VirtualBox

Ignore:
Timestamp:
Jul 6, 2019 1:22:56 AM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
131853
Message:

Dhcpd: Went over the Dhcpd and related code adding comments and doing some exception vetting. bugref:9288

File:
1 edited

Legend:

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

    r79530 r79563  
    3636 * Registers the ClientId format type callback ("%R[binding]").
    3737 */
    38 void Binding::registerFormat()
     38void Binding::registerFormat() RT_NOEXCEPT
    3939{
    4040    if (!g_fFormatRegistered)
     
    8787}
    8888
    89 const char *Binding::stateName() const
     89const char *Binding::stateName() const RT_NOEXCEPT
    9090{
    9191    switch (m_state)
     
    108108
    109109
    110 Binding &Binding::setState(const char *pszStateName)
     110Binding &Binding::setState(const char *pszStateName) RT_NOEXCEPT
    111111{
    112112    if (strcmp(pszStateName, "free") == 0)
     
    137137 * @param   tsDeadline          The expiry deadline to use.
    138138 */
    139 bool Binding::expire(Timestamp tsDeadline)
     139bool Binding::expire(Timestamp tsDeadline) RT_NOEXCEPT
    140140{
    141141    if (m_state <= Binding::EXPIRED)
     
    232232        /*
    233233         * Decode from "de:ad:be:ef".
    234          * XXX: RTStrConvertHexBytes() doesn't grok colons
    235234         */
    236         size_t cbBytes = strId.length() / 2;
    237         uint8_t *pBytes = new uint8_t[cbBytes];
    238         rc = RTStrConvertHexBytes(strId.c_str(), pBytes, cbBytes, 0);
     235        /** @todo RTStrConvertHexBytes() doesn't grok colons */
     236        size_t   cbBytes = strId.length() / 2;
     237        uint8_t *pbBytes = new uint8_t[cbBytes];
     238        rc = RTStrConvertHexBytes(strId.c_str(), pbBytes, cbBytes, 0);
    239239        if (RT_SUCCESS(rc))
    240240        {
    241             std::vector<uint8_t> rawopt(pBytes, pBytes + cbBytes);
    242             id = OptClientId(rawopt);
    243         }
    244         delete[] pBytes;
     241            try
     242            {
     243                std::vector<uint8_t> rawopt(pbBytes, pbBytes + cbBytes);
     244                id = OptClientId(rawopt);
     245            }
     246            catch (std::bad_alloc &)
     247            {
     248                delete[] pbBytes;
     249                throw;
     250            }
     251        }
     252        delete[] pbBytes;
    245253    }
    246254
     
    305313    }
    306314    else
    307     {   /* XXX: old code wrote timestamps instead of absolute time. */
     315    {   /** @todo XXX: old code wrote timestamps instead of absolute time. */
    308316        /* pretend that lease has just ended */
    309317        Timestamp fakeIssued = Timestamp::now();
     
    341349    m_pConfig = pConfig;
    342350
    343     m_pool.init(pConfig->getIPv4PoolFirst(),
    344                 pConfig->getIPv4PoolLast());
    345 
    346     return VINF_SUCCESS;
     351    return m_pool.init(pConfig->getIPv4PoolFirst(), pConfig->getIPv4PoolLast());
    347352}
    348353
     
    351356 * Expire old binding (leases).
    352357 */
    353 void Db::expire()
     358void Db::expire() RT_NOEXCEPT
    354359{
    355360    const Timestamp now = Timestamp::now();
     
    609614 * @param   pNewBinding     The new binding to add.
    610615 */
    611 int Db::i_addBinding(Binding *pNewBinding)
     616int Db::i_addBinding(Binding *pNewBinding) RT_NOEXCEPT
    612617{
    613618    /*
     
    662667 * @param   req                 The DHCP request.
    663668 */
    664 void Db::cancelOffer(const DhcpClientMessage &req)
     669void Db::cancelOffer(const DhcpClientMessage &req) RT_NOEXCEPT
    665670{
    666671    const OptRequestedAddress reqAddr(req);
     
    697702 * @param   req                 The DHCP request.
    698703 * @returns true if found and released, otherwise false.
    699  */
    700 bool Db::releaseBinding(const DhcpClientMessage &req)
     704 * @throws  nothing
     705 */
     706bool Db::releaseBinding(const DhcpClientMessage &req) RT_NOEXCEPT
    701707{
    702708    const RTNETADDRIPV4 addr = req.ciaddr();
     
    726732 * @param   strFilename         The file to write it to.
    727733 */
    728 int Db::writeLeases(const RTCString &strFilename) const
     734int Db::writeLeases(const RTCString &strFilename) const RT_NOEXCEPT
    729735{
    730736    LogDHCP(("writing leases to %s\n", strFilename.c_str()));
     737
     738    /** @todo This could easily be written directly to the file w/o going thru
     739     *        a xml::Document, xml::XmlFileWriter, hammering the heap and being
     740     *        required to catch a lot of different exceptions at various points.
     741     *        (RTStrmOpen, bunch of RTStrmPrintf using \%RMas and \%RMes.,
     742     *        RTStrmClose closely followed by a couple of renames.)
     743     */
    731744
    732745    /*
     
    789802 * @returns IPRT status code.
    790803 * @param   strFilename         The file to load it from.
    791  */
    792 int Db::loadLeases(const RTCString &strFilename)
     804 * @throws  nothing
     805 */
     806int Db::loadLeases(const RTCString &strFilename) RT_NOEXCEPT
    793807{
    794808    LogDHCP(("loading leases from %s\n", strFilename.c_str()));
     
    863877 * @return  IPRT status code.
    864878 */
    865 int Db::i_loadLease(const xml::ElementNode *pElmLease)
     879int Db::i_loadLease(const xml::ElementNode *pElmLease) RT_NOEXCEPT
    866880{
    867881    Binding *pBinding = NULL;
     
    878892        bool fExpired = pBinding->expire();
    879893        if (!fExpired)
    880             LogDHCP(("> LOAD: lease %R[binding]\n", pBinding));
     894            LogDHCP(("> LOAD:         lease %R[binding]\n", pBinding));
    881895        else
    882896            LogDHCP(("> LOAD: EXPIRED lease %R[binding]\n", pBinding));
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