VirtualBox

Ignore:
Timestamp:
Jul 4, 2019 10:14:02 AM (5 years ago)
Author:
vboxsync
Message:

Dhcpd: s/Defs.h/DhcpdInternal.h/, s/TimeStamp/Timestamp/g, started adding comments and stuff. bugref:9288

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/NetworkServices/Dhcpd/ClientId.cpp

    r76553 r79524  
    1616 */
    1717
     18
     19/*********************************************************************************************************************************
     20*   Header Files                                                                                                                 *
     21*********************************************************************************************************************************/
    1822#include <algorithm>
    19 
    2023#include "ClientId.h"
    2124
    2225
     26/*********************************************************************************************************************************
     27*   Global Variables                                                                                                             *
     28*********************************************************************************************************************************/
     29/** Indiciates wherther ClientId::rtStrFormat was already registered. */
    2330bool ClientId::g_fFormatRegistered = false;
    2431
    2532
     33/**
     34 * Registers the ClientId format type callback ("%R[id]").
     35 */
    2636void ClientId::registerFormat()
    2737{
    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    }
    3544}
    3645
    3746
     47/**
     48 * @callback_method_impl{FNRTSTRFORMATTYPE, Formats ClientId via "%R[id]". }
     49 */
    3850DECLCALLBACK(size_t)
    3951ClientId::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)
    4355{
    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
    4563    size_t cb = 0;
     64    if (pThis->m_id.present())
     65    {
     66        cb += pfnOutput(pvArgOutput, RT_STR_TUPLE("["));
    4667
    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]);
    4971
    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("] ("));
    5773    }
    5874
    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);
    6276
    63         cb += RTStrFormat(pfnOutput, pvArgOutput, NULL, 0,
    64                           "[");
     77    if (pThis->m_id.present())
     78        cb += pfnOutput(pvArgOutput, RT_STR_TUPLE(")"));
    6579
    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;
    8681}
    8782
     
    110105        if (r.m_id.present())
    111106            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 */
    114108    }
    115109    else
     
    117111        if (r.m_id.present())
    118112            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;
    121114    }
    122115}
     116
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette