Пример #1
0
UtlString* SipRedirectorMPT::addMapping(const char* contacts,
                                        int length)
{
   // Make the contact UtlString.
   UtlString* contactString = new UtlString(contacts, length);
   OsSysLog::add(FAC_SIP, PRI_DEBUG,
                 "%s::addMapping inserting '%s'", mLogName.data(),
                 contactString->data());
   // Get its hash.
   unsigned hash = contactString->hash();
   // Keys are 24 bits, and the starting key is the lower 24 bits of the hash.
   unsigned key = hash & 0xFFFFFF;
   // The increment is the upper 24 bits of the hash, forced to be odd so all
   // possible keys will be hit.
   unsigned increment = ((hash >> 8) & 0xFFFFFF) | 1;
   UtlString* userString;

   mMapLock.acquire();

   // First, check if it's already mapped.
   UtlContainable* v = mMapContactsToUser.findValue(contactString);
   if (v)
   {
      userString = dynamic_cast<UtlString*> (v);
   }
   else
   {
      // Find an unused key value.
      while (1)
      {
         char buffer[20];
         sprintf(buffer, "=MPT=%03x-%03x", (hash >> 12) & 0xFFF, hash & 0xFFF);
         userString = new UtlString(buffer);
         OsSysLog::add(FAC_SIP, PRI_DEBUG,
                       "%s::addMapping trying '%s'", mLogName.data(),
                       buffer);
         if (mMapUserToContacts.findValue(userString) == NULL)
         {
            break;
         }
         delete userString;
         key += increment;
         key &= 0xFFFFFF;
      }
      // Insert the mapping.
      mMapUserToContacts.insertKeyAndValue(userString, contactString);
      mMapContactsToUser.insertKeyAndValue(contactString, userString);

      mMapsModified = TRUE;
   }

   mMapLock.release();

   OsSysLog::add(FAC_SIP, PRI_DEBUG,
                 "%s::addMapping using '%s'", mLogName.data(),
                 userString->data());

   return userString;
}
Пример #2
0
OsStatus
ExtensionDB::load()
{
    // Critical Section here
    OsLock lock( sLockMutex );
    OsStatus result = OS_SUCCESS;

    if ( m_pFastDB != NULL ) 
    {
        // Clean out the existing DB rows before loading
        // a new set from persistent storage
        removeAllRows ();

        UtlString fileName = OsPath::separator + mDatabaseName + ".xml";
        UtlString pathName = SipXecsService::Path(SipXecsService::DatabaseDirType,
                                                  fileName.data());

        OsSysLog::add(FAC_DB, PRI_DEBUG, "ExtensionDB::load loading \"%s\"",
                    pathName.data());

        TiXmlDocument doc ( pathName );

        // Verify that we can load the file (i.e it must exist)
        if( doc.LoadFile() )
        {
            // the checksum is used to determine if the db changed between reloads
            int loadChecksum = 0;
            TiXmlNode * rootNode = doc.FirstChild ("items");
            if (rootNode != NULL)
            {
                // the folder node contains at least the name/displayname/
                // and autodelete elements, it may contain others
                for( TiXmlNode *itemNode = rootNode->FirstChild( "item" );
                     itemNode; 
                     itemNode = itemNode->NextSibling( "item" ) )
                {
                    // Create a hash dictionary for element attributes
                    UtlHashMap nvPairs;

                    for( TiXmlNode *elementNode = itemNode->FirstChild();
                         elementNode; 
                         elementNode = elementNode->NextSibling() )
                    {
                        // Bypass comments and other element types only interested
                        // in parsing element attributes
                        if ( elementNode->Type() == TiXmlNode::ELEMENT )
                        {
                            UtlString elementName = elementNode->Value();
                            UtlString elementValue;

                            result = SIPDBManager::getAttributeValue (
                                *itemNode, elementName, elementValue);

                            // update the load checksum
                            loadChecksum += ( elementName.hash() + elementValue.hash() );
                            if (result == OS_SUCCESS)
                            {
                                UtlString* collectableKey = 
                                    new UtlString( elementName ); 
                                UtlString* collectableValue = 
                                    new UtlString( elementValue ); 
                                nvPairs.insertKeyAndValue ( 
                                    collectableKey, collectableValue );
                            } else if ( elementNode->FirstChild() == NULL )
                            {
                                // NULL Element value create a special 
                                // char string we have key and value so insert
                                UtlString* collectableKey = 
                                    new UtlString( elementName ); 
                                UtlString* collectableValue = 
                                    new UtlString( SPECIAL_IMDB_NULL_VALUE ); 
                                nvPairs.insertKeyAndValue ( 
                                    collectableKey, collectableValue );
                            }
                        }
                    }
                    // Insert the item row into the IMDB
                    insertRow ( nvPairs );
                }
            }
        } else 
        {
            OsSysLog::add(FAC_SIP, PRI_WARNING, "ExtensionDB::load failed to load \"%s\"",
                    pathName.data());
            result = OS_FAILED;
        }
    } else
    {
        result = OS_FAILED;
    }
    return result;
}