Changeset 79524 in vbox for trunk/src/VBox/NetworkServices/Dhcpd/ClientId.cpp
- Timestamp:
- Jul 4, 2019 10:14:02 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/NetworkServices/Dhcpd/ClientId.cpp
r76553 r79524 16 16 */ 17 17 18 19 /********************************************************************************************************************************* 20 * Header Files * 21 *********************************************************************************************************************************/ 18 22 #include <algorithm> 19 20 23 #include "ClientId.h" 21 24 22 25 26 /********************************************************************************************************************************* 27 * Global Variables * 28 *********************************************************************************************************************************/ 29 /** Indiciates wherther ClientId::rtStrFormat was already registered. */ 23 30 bool ClientId::g_fFormatRegistered = false; 24 31 25 32 33 /** 34 * Registers the ClientId format type callback ("%R[id]"). 35 */ 26 36 void ClientId::registerFormat() 27 37 { 28 if (g_fFormatRegistered) 29 return; 30 31 int rc = RTStrFormatTypeRegister("id", rtStrFormat, NULL); 32 AssertRC(rc); 33 34 g_fFormatRegistered = true; 38 if (!g_fFormatRegistered) 39 { 40 int rc = RTStrFormatTypeRegister("id", rtStrFormat, NULL); 41 AssertRC(rc); 42 g_fFormatRegistered = RT_SUCCESS(rc); 43 } 35 44 } 36 45 37 46 47 /** 48 * @callback_method_impl{FNRTSTRFORMATTYPE, Formats ClientId via "%R[id]". } 49 */ 38 50 DECLCALLBACK(size_t) 39 51 ClientId::rtStrFormat(PFNRTSTROUTPUT pfnOutput, void *pvArgOutput, 40 const char *pszType, void const *pvValue,41 int cchWidth, int cchPrecision, unsigned fFlags,42 void *pvUser)52 const char *pszType, void const *pvValue, 53 int cchWidth, int cchPrecision, unsigned fFlags, 54 void *pvUser) 43 55 { 44 const ClientId *id = static_cast<const ClientId *>(pvValue); 56 RT_NOREF(pszType, cchWidth, cchPrecision, fFlags, pvUser); 57 Assert(strcmp(pszType, "id") == 0); 58 59 const ClientId *pThis = static_cast<const ClientId *>(pvValue); 60 if (pThis == NULL) 61 return pfnOutput(pvArgOutput, RT_STR_TUPLE("<NULL>")); 62 45 63 size_t cb = 0; 64 if (pThis->m_id.present()) 65 { 66 cb += pfnOutput(pvArgOutput, RT_STR_TUPLE("[")); 46 67 47 AssertReturn(strcmp(pszType, "id") == 0, 0); 48 RT_NOREF(pszType); 68 const OptClientId::value_t &idopt = pThis->m_id.value(); 69 for (size_t i = 0; i < idopt.size(); ++i) 70 cb += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, "%s%02x", (i == 0 ? "" : ":"), idopt[i]); 49 71 50 RT_NOREF(cchWidth, cchPrecision, fFlags); 51 RT_NOREF(pvUser); 52 53 if (id == NULL) 54 { 55 return RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, 56 "<NULL>"); 72 cb += pfnOutput(pvArgOutput, RT_STR_TUPLE("] (")); 57 73 } 58 74 59 if (id->m_id.present()) 60 { 61 const OptClientId::value_t &idopt = id->m_id.value(); 75 cb += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, "%RTmac", &pThis->m_mac); 62 76 63 cb += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0,64 "[");77 if (pThis->m_id.present()) 78 cb += pfnOutput(pvArgOutput, RT_STR_TUPLE(")")); 65 79 66 for (size_t i = 0; i < idopt.size(); ++i) 67 { 68 cb += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, 69 "%s%02x", (i == 0 ? "" : ":"), idopt[i]); 70 } 71 72 cb += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, 73 "] ("); 74 } 75 76 cb += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, 77 "%RTmac", &id->m_mac); 78 79 if (id->m_id.present()) 80 { 81 cb += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0, 82 ")"); 83 } 84 85 return 0; 80 return cb; 86 81 } 87 82 … … 110 105 if (r.m_id.present()) 111 106 return l.m_id.value() < r.m_id.value(); 112 else 113 return false; /* the one with id comes last */ 107 return false; /* the one with id comes last */ 114 108 } 115 109 else … … 117 111 if (r.m_id.present()) 118 112 return true; /* the one with id comes last */ 119 else 120 return l.m_mac < r.m_mac; 113 return l.m_mac < r.m_mac; 121 114 } 122 115 } 116
Note:
See TracChangeset
for help on using the changeset viewer.