Example #1
0
   void testGetUnexpiredContacts()
      {
         Url uri;
         ResultSet results;
         UtlHashMap record1;
         UtlHashMap record2;
         int timeNow = (int)OsDateTime::getSecsSinceEpoch();

         RegistrationDbTestContext testDbContext(TEST_DATA_DIR "/regdbdata",
                                                 TEST_WORK_DIR "/regdbdata"
                                                 );

         testDbContext.inputFile("getUnexpiredContacts.xml");

         RegistrationDB* regDb = RegistrationDB::getInstance();

         uri.setUserId("900");
         uri.setHostAddress("testdomain.example.com");


         regDb->getUnexpiredContactsUser(uri, timeNow, results);
         int numResults = results.getSize();
         CPPUNIT_ASSERT_EQUAL(2, numResults);


         if (numResults == 2)
         {
             // Get first record
             results.getIndex(0, record1);
             UtlString* value = (UtlString*)record1.findValue(&RegistrationDB::gContactKey);
             CPPUNIT_ASSERT_EQUAL(value->compareTo("sip:[email protected]"), 0);

             value = (UtlString*)record1.findValue(&RegistrationDB::gUriKey);
             CPPUNIT_ASSERT_EQUAL(value->compareTo("sip:[email protected]"), 0);

             // Get second record
             results.getIndex(1, record2);
             value = (UtlString*)record2.findValue(&RegistrationDB::gContactKey);
             CPPUNIT_ASSERT_EQUAL(value->compareTo("sip:[email protected]"), 0);

             value = (UtlString*)record2.findValue(&RegistrationDB::gUriKey);
             CPPUNIT_ASSERT_EQUAL(value->compareTo("sip:[email protected]"), 0);
         }
      }
 void getResult( ResultSet& resultSet
                ,int         index
                ,const char* key
                ,UtlString&  result
                )
 {
    UtlHashMap hash;
    resultSet.getIndex( index, hash );
    UtlString theKey(key);
    result = *((UtlString*)hash.findValue(&theKey));
 }
UtlBoolean
SubscribeServerThread::isAuthorized (
    const SipMessage* message,
    SipMessage *responseMessage,
    StatusPluginReference* pluginContainer)
{
    UtlBoolean isAuthorized = FALSE;
    UtlString  requestUser;
    Url       identityUrl;
    message->getUri(NULL, NULL, NULL, &requestUser);
    identityUrl.setUserId(requestUser);
    identityUrl.setHostAddress(mDefaultDomain);

    if( pluginContainer )
    {
        // if the plugin has permissions, we must match all these against the IMDB
        if( pluginContainer->hasPermissions() )
        {
            // permission required. Check for required permission in permission IMDB
            // All required permissions should match
            ResultSet dbPermissions;

            PermissionDB::getInstance()->getPermissions( identityUrl, dbPermissions );

            int numDBPermissions = dbPermissions.getSize();

            if( numDBPermissions > 0 )
            {
                UtlBoolean nextPermissionMatched = TRUE;

                UtlSListIterator* pluginPermissionIterator = pluginContainer->permissionsIterator();
                UtlString* pluginPermission;
                // Iterated through the plugin permissions matching
                // them one by one against the IMDB
                while(   (pluginPermission = (UtlString*)(*pluginPermissionIterator)())
                      && nextPermissionMatched
                      )
                {
                    //check againt all permissions in IMDB
                    nextPermissionMatched = FALSE;
                    UtlString identity, permission;
                    for ( int dbIndex = 0; dbIndex < numDBPermissions; dbIndex++ )
                    {

                        UtlHashMap record;
                        dbPermissions.getIndex( dbIndex, record );
                        // note not interested in identity here
                        UtlString permissionKey ("permission");
                        UtlString permission = *((UtlString*)record.findValue(&permissionKey));
                        if( permission.compareTo( *pluginPermission, UtlString::ignoreCase ) == 0)
                        {
                            nextPermissionMatched = TRUE;
                            break;
                        }
                    }
                }
                delete pluginPermissionIterator;

                // after going thru all permissions find out if all matched or not
                if( nextPermissionMatched )
                {
                   OsSysLog::add(FAC_AUTH, PRI_DEBUG, "SubscribeServerThread::isAuthorized() -"
                        " All permissions matched - request is AUTHORIZED");
                    isAuthorized = TRUE;
                }
                else
                {
                    OsSysLog::add(FAC_AUTH, PRI_DEBUG, "SubscribeServerThread::isAuthorized() -"
                        " One or more Permissions did not match - request is UNAUTHORIZED");
                    isAuthorized = FALSE;
                }
            }
            else
            {
                // one or more permissions needed by plugin and none in IMDB => UNAUTHORIZED
                OsSysLog::add(FAC_AUTH, PRI_DEBUG, "SubscribeServerThread::isAuthorized() -"
                    " No Permissions in IMDB - request is UNAUTHORIZED");
                isAuthorized = FALSE;
            }
        }
        else
        {
            OsSysLog::add(FAC_AUTH, PRI_DEBUG, "SubscribeServerThread::isAuthorized() -"
                " No Permissions required - request is always AUTHORIZED");
            isAuthorized = TRUE;
        }
    }
    //set the error response message id unauthorized
    if(!isAuthorized)
    {
        responseMessage->setResponseData(message,SIP_FORBIDDEN_CODE, SIP_FORBIDDEN_TEXT);
    }
    return isAuthorized;
}
Example #4
0
OsStatus
DialByNameDB::load() const
{
    // 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 ();

        // Query all Identities with 'AutoAttendant' permission set
        PermissionDB * pPermissionDB = PermissionDB::getInstance();
        ResultSet permissionsResultSet;
        pPermissionDB->getIdentities ( "AutoAttendant", permissionsResultSet );

        CredentialDB * pCredentialDB = CredentialDB::getInstance();
        ResultSet credentialsResultSet;

        UtlString identity, permission;
        int numAutoAttendees = permissionsResultSet.getSize();
        for (int index = 0; index < numAutoAttendees; index++)
        {
            // get the next identity
            UtlString identityKey("identity");
            UtlHashMap record;
            permissionsResultSet.getIndex( index, record );
            UtlString identity = *((UtlString*)record.findValue(&identityKey));

            Url identityUrl (identity);
            pCredentialDB->
                getAllCredentials (
                    identityUrl,
                    credentialsResultSet );

            // we should only have one credential! we're 
            // only interested in the uri column's display name
            if ( credentialsResultSet.getSize() == 1)
            {
                UtlString uriKey("uri");
                UtlHashMap record;
                credentialsResultSet.getIndex( 0, record );
                UtlString uri = *((UtlString*)record.findValue(&uriKey));

                // must have a display name present before inserting a row
                // @TODO convert to url and get display name
                UtlHashMap nvPairs;
                if (!uri.isNull())
                {
                    // Null Element value create a special 
                    // char string we have key and value so insert
                    UtlString* contactValue = 
                        new UtlString( uri ); 

                    // Memory Leak fixes, make shallow copies of static keys
                    UtlString* contactKey = 
                        new UtlString( gNp_contactKey );

                    nvPairs.insertKeyAndValue ( 
                        contactKey, contactValue );
                }
                // Insert the item row into the IMDB
                insertRow ( nvPairs );
            }
        }

        // Reset the changed flags after a successful load
        SIPDBManager::getInstance()->
            setDatabaseChangedFlag("credential", FALSE);
        SIPDBManager::getInstance()->
            setDatabaseChangedFlag("permission", FALSE);
    } else
    {
        result = OS_FAILED;
    }
    return result;
}
Example #5
0
RedirectPlugin::LookUpStatus
SipRedirectorMapping::lookUp(
   const SipMessage& message,
   const UtlString& requestString,
   const Url& requestUri,
   const UtlString& method,
   ContactList& contactList,
   RequestSeqNo requestSeqNo,
   int redirectorNo,
   SipRedirectorPrivateStorage*& privateStorage,
   ErrorDescriptor& errorDescriptor)
{
   UtlString callTag = "UNK";
   UtlString permissionName;
   ResultSet urlMappingRegistrations;
   ResultSet urlMappingPermissions;

   // @JC This variable is strangely overloaded
   // If we have no permissions then add any encountered
   // contacts. If we do have permissions then the
   // permission must match
   UtlBoolean permissionFound = TRUE;

   if (mMappingRulesLoaded == OS_SUCCESS)
   {
      mMap.getContactList(
         requestUri,
         urlMappingRegistrations,
         urlMappingPermissions,
         callTag);
   }

   int numUrlMappingPermissions = urlMappingPermissions.getSize();

   Os::Logger::instance().log(FAC_SIP, PRI_DEBUG, "%s::lookUp "
                 "got %d UrlMapping Permission requirements for %d contacts",
                 mLogName.data(), numUrlMappingPermissions,
                 urlMappingRegistrations.getSize());

   if (numUrlMappingPermissions > 0)
   {
      // check if we have field parameter that indicates that some permissions should be ignored
      UtlString ignorePermissionStr;
      // :KLUDGE: remove const_cast and uri declaration after XSL-88 gets fixed
      Url& uri = const_cast<Url&>(requestUri);
      uri.getUrlParameter("sipx-noroute", ignorePermissionStr);

      EntityRecord entity;
     std::set<std::string> permissions;
     if (_dataStore.entityDB().findByIdentityOrAlias(requestUri, entity))
        permissions = entity.permissions();
     size_t numDBPermissions = permissions.size();

      for (int i = 0; i<numUrlMappingPermissions; i++)
      {
         UtlHashMap record;
         urlMappingPermissions.getIndex(i, record);
         UtlString permissionKey("permission");
         UtlString urlMappingPermissionStr =
            *((UtlString*) record.findValue(&permissionKey));
         Os::Logger::instance().log(FAC_SIP, PRI_DEBUG,
                       "%s::lookUp checking permissions DB for "
                       "urlMappingPermissions[%d] = '%s'",
                       mLogName.data(), i,
                       urlMappingPermissionStr.data());

         // Try to match the permission
         // so assume it cannot be found unless we
         // see a match in the IMDB
         permissionFound = FALSE;

         // if the permission we are looking for is the one the we are supposed to ignore,
         // than assume that permission is not found
         if (urlMappingPermissionStr.compareTo(ignorePermissionStr, UtlString::ignoreCase) == 0)
         {
             Os::Logger::instance().log(FAC_SIP, PRI_DEBUG,
                           "%s::lookUp ignoring permission '%s'",
                           mLogName.data(),
                           ignorePermissionStr.data());
             continue;
         }



         
         
         UtlString permissionsFound;
         for (std::set<std::string>::const_iterator iter = permissions.begin();
             iter != permissions.end(); iter++)
         {
            UtlString dbPermissionStr = iter->c_str();

            bool equal = dbPermissionStr.compareTo(urlMappingPermissionStr, UtlString::ignoreCase) == 0;
 
            if (Os::Logger::instance().willLog(FAC_SIP, PRI_DEBUG))
            {
               permissionsFound.append(" ");
               permissionsFound.append(dbPermissionStr);
               if (equal)
               {
                  permissionsFound.append("[matches]");
               }
            }
            if (equal)
            {
               // matching permission found in IMDB
               permissionFound = TRUE;
               break;
            }
            dbPermissionStr.remove(0);
         }
         Os::Logger::instance().log(FAC_SIP, PRI_DEBUG,
                       "%s::lookUp %d permissions configured for request URI '%s'.  Checking: %s",
                       mLogName.data(), numDBPermissions,
                       requestUri.toString().data(),
                       permissionsFound.data());

         if (permissionFound)
         {
            break;
         }
         urlMappingPermissionStr.remove(0);
      }
   }

   // either there were no requirements to match against voicemail
   // or there were and we found a match in the IMDB for the URI
   // so now add the contacts to the SIP message
   if (permissionFound)
   {
      int numUrlMappingRegistrations = urlMappingRegistrations.getSize();

      Os::Logger::instance().log(FAC_SIP, PRI_DEBUG,
                    "%s::lookUp got %d UrlMapping Contacts",
                    mLogName.data(), numUrlMappingRegistrations);

      if (numUrlMappingRegistrations > 0)
      {
         for (int i = 0; i < numUrlMappingRegistrations; i++)
         {
            UtlHashMap record;
            urlMappingRegistrations.getIndex(i, record);
            UtlString contactKey("contact");
            UtlString contact= *(dynamic_cast <UtlString*> (record.findValue(&contactKey)));

            Os::Logger::instance().log(FAC_SIP, PRI_DEBUG,
                          "%s::lookUp contact = '%s'",
                          mLogName.data(), contact.data());
            Url contactUri(contact);
            Os::Logger::instance().log(FAC_SIP, PRI_DEBUG,
                          "%s::lookUp contactUri = '%s'",
                          mLogName.data(), contactUri.toString().data());
            // We no longer check for recursive loops here because we
            // have comprehensive loop detection in the proxy.
            UtlString recordRoute;
            UtlString curCallDest;
            if (message.getRecordRouteField(0,&recordRoute)) {
               Os::Logger::instance().log(FAC_SIP, PRI_DEBUG,
                          "%s::lookUp RecordRouteField = '%s'",
                          mLogName.data(), recordRoute.data());
            }
            contactUri.setUrlParameter(SIP_SIPX_CALL_DEST_FIELD, callTag.data());

            // Add the contact.
            contactList.add( contactUri, *this );
         }
      }
   }

   return RedirectPlugin::SUCCESS;
}
RedirectPlugin::LookUpStatus
SipRedirectorFallback::lookUp(
   const SipMessage& message,
   UtlString& requestString,
   Url& requestUri,
   const UtlString& method,
   ContactList& contactList,
   RequestSeqNo requestSeqNo,
   int redirectorNo,
   SipRedirectorPrivateStorage*& privateStorage,
   ErrorDescriptor& errorDescriptor)
{
   ResultSet urlMappingRegistrations;

   UtlString callTag = "UNK";

   if (mMappingRulesLoaded == OS_SUCCESS)
   {      
      UtlString callerLocation;
      determineCallerLocation( message, callerLocation );
    
#ifndef __USE_OLD_FALLBACKRULES_SCHEMA__      
      mMap.getContactList(
         requestUri,
         callerLocation,
         urlMappingRegistrations,
         callTag );
#else
      ResultSet dummyMappingPermissions;
      mMap.getContactList(
         requestUri,
         urlMappingRegistrations, 
         dummyMappingPermissions );
#endif      
      
      int numUrlMappingRegistrations = urlMappingRegistrations.getSize();
      Os::Logger::instance().log(FAC_SIP, PRI_DEBUG,
                    "%s::lookUp got %d UrlMapping Contacts for %s @ location '%s'",
                    mLogName.data(), numUrlMappingRegistrations, requestString.data(), callerLocation.data() );

      if (numUrlMappingRegistrations > 0)
      {
         for (int i = 0; i < numUrlMappingRegistrations; i++)
         {
            UtlHashMap record;
            urlMappingRegistrations.getIndex(i, record);
            UtlString contactKey("contact");
            UtlString contact= *(dynamic_cast <UtlString*> (record.findValue(&contactKey)));
            UtlString callTagKey("callTag");
            Os::Logger::instance().log(FAC_SIP, PRI_DEBUG,
                          "%s::lookUp contact = '%s'",
                          mLogName.data(), contact.data());
            Url contactUri(contact);
            Os::Logger::instance().log(FAC_SIP, PRI_DEBUG,
                          "%s::lookUp contactUri = '%s'",
                          mLogName.data(), contactUri.toString().data());

            contactUri.setUrlParameter(SIP_SIPX_CALL_DEST_FIELD, callTag.data());

            // Add the contact.
            contactList.add( contactUri, *this );
         }
      }
   }
   return RedirectPlugin::SUCCESS;
}
Example #7
0
RedirectPlugin::LookUpStatus
SipRedirectorAliasDB::lookUp(
    const SipMessage& message,
    const UtlString& requestString,
    const Url& requestUri,
    const UtlString& method,
    ContactList& contactList,
    RequestSeqNo requestSeqNo,
    int redirectorNo,
    SipRedirectorPrivateStorage*& privateStorage,
    ErrorDescriptor& errorDescriptor)
{
    // If url param sipx-userforward = false, do not redirect to its aliases
    UtlString disableForwarding;
    requestUri.getUrlParameter("sipx-userforward", disableForwarding);
    if (disableForwarding.compareTo("false", UtlString::ignoreCase) == 0)
    {
        OsSysLog::add(FAC_SIP, PRI_DEBUG, "%s::lookUp user forwarding disabled by parameter",
                      mLogName.data());
    }
    else
    {
        UtlString requestIdentity;
        requestUri.getIdentity(requestIdentity);

        OsSysLog::add(FAC_SIP, PRI_DEBUG, "%s::lookUp identity '%s'",
                      mLogName.data(), requestIdentity.data());

        ResultSet aliases;
        AliasDB::getInstance()->getContacts(requestUri, aliases);
        int numAliasContacts = aliases.getSize();
        if (numAliasContacts > 0)
        {
            OsSysLog::add(FAC_SIP, PRI_DEBUG, "%s::lookUp "
                          "got %d AliasDB contacts", mLogName.data(),
                          numAliasContacts);

            // Check if the request identity is a real user/extension
            UtlString realm;
            UtlString authType;
            bool isUserIdentity =
                CredentialDB::getInstance()->isUriDefined(requestUri, realm, authType);
            SipXauthIdentity authIdentity;
            authIdentity.setIdentity(requestIdentity);

            for (int i = 0; i < numAliasContacts; i++)
            {
                static UtlString contactKey("contact");

                UtlHashMap record;
                if (aliases.getIndex(i, record))
                {
                    UtlString contact = *((UtlString*)record.findValue(&contactKey));
                    Url contactUri(contact);

                    // if the request identity is a real user
                    if (isUserIdentity)
                    {
                        // Encode AuthIdentity into the URI
                        authIdentity.encodeUri(contactUri, message);
                    }

                    contactUri.setUrlParameter(SIP_SIPX_CALL_DEST_FIELD, "AL");
                    // Add the contact.
                    contactList.add( contactUri, *this );
                }
            }
        }
    }

    return RedirectPlugin::SUCCESS;
}
Example #8
0
   void getRowsTest()
   {
      SipDbTestContext sipDbTestContext(TEST_DATA_DIR "/locationdata",
                                        TEST_WORK_DIR "/locationdata"
                                                 );
      sipDbTestContext.inputFile("dummy_loc_db.xml" );
      
      LocationDB* pLocDb = LocationDB::getInstance("dummy_loc_db");
      ResultSet resultSet;
      UtlHashMap hashmap1;
      UtlHashMap hashmap2;
      UtlHashMap hashmap3;
      UtlHashMap hashmap4;
      UtlString* pTempString;
      UtlString key;

      pLocDb->getAllRows( resultSet );
      CPPUNIT_ASSERT( resultSet.getSize() == 4 );

      CPPUNIT_ASSERT( resultSet.getIndex( 0, hashmap1 ) == OS_SUCCESS );
      key = "name";
      pTempString = dynamic_cast<UtlString*>(hashmap1.findValue( &key ) );
      CPPUNIT_ASSERT( pTempString );
      ASSERT_STR_EQUAL( "Ottawa", pTempString->data() );
      
      key = "description";
      pTempString = dynamic_cast<UtlString*>(hashmap1.findValue( &key ) );
      CPPUNIT_ASSERT( pTempString );
      ASSERT_STR_EQUAL( "One crazy location", pTempString->data() );
      
      key = "locationcode";
      pTempString = dynamic_cast<UtlString*>(hashmap1.findValue( &key ) );
      CPPUNIT_ASSERT( pTempString );
      ASSERT_STR_EQUAL( "613", pTempString->data() );

      key = "subnets";
      pTempString = dynamic_cast<UtlString*>(hashmap1.findValue( &key ) );
      CPPUNIT_ASSERT( pTempString );
      ASSERT_STR_EQUAL( "172.30.0.0/16,22.22.22.22/32", pTempString->data() );

      CPPUNIT_ASSERT( resultSet.getIndex( 1, hashmap2 ) == OS_SUCCESS );
      key = "name";
      pTempString = dynamic_cast<UtlString*>(hashmap2.findValue( &key ) );
      CPPUNIT_ASSERT( pTempString );
      ASSERT_STR_EQUAL( "Quebec", pTempString->data() );
      
      key = "description";
      pTempString = dynamic_cast<UtlString*>(hashmap2.findValue( &key ) );
      CPPUNIT_ASSERT( pTempString );
      ASSERT_STR_EQUAL( "Happy 400th anniversary", pTempString->data() );
      
      key = "locationcode";
      pTempString = dynamic_cast<UtlString*>(hashmap2.findValue( &key ) );
      CPPUNIT_ASSERT( pTempString );
      ASSERT_STR_EQUAL( "418", pTempString->data() );

      key = "subnets";
      pTempString = dynamic_cast<UtlString*>(hashmap2.findValue( &key ) );
      CPPUNIT_ASSERT( pTempString );
      ASSERT_STR_EQUAL( SPECIAL_IMDB_NULL_VALUE, pTempString->data() );

      CPPUNIT_ASSERT( resultSet.getIndex( 2, hashmap3 ) == OS_SUCCESS );
      key = "name";
      pTempString = dynamic_cast<UtlString*>(hashmap3.findValue( &key ) );
      CPPUNIT_ASSERT( pTempString );
      ASSERT_STR_EQUAL( "Montreal", pTempString->data() );
      
      key = "description";
      pTempString = dynamic_cast<UtlString*>(hashmap3.findValue( &key ) );
      CPPUNIT_ASSERT( pTempString );
      ASSERT_STR_EQUAL( "Go Habs Go!", pTempString->data() );
      
      key = "locationcode";
      pTempString = dynamic_cast<UtlString*>(hashmap3.findValue( &key ) );
      CPPUNIT_ASSERT( pTempString );
      ASSERT_STR_EQUAL( "514", pTempString->data() );

      key = "subnets";
      pTempString = dynamic_cast<UtlString*>(hashmap3.findValue( &key ) );
      CPPUNIT_ASSERT( pTempString );
      ASSERT_STR_EQUAL( "10.10.10.0/24,11.11.11.0/24,12.12.12.0/24", pTempString->data() );

      CPPUNIT_ASSERT( resultSet.getIndex( 3, hashmap4 ) == OS_SUCCESS );
      key = "name";
      pTempString = dynamic_cast<UtlString*>(hashmap4.findValue( &key ) );
      CPPUNIT_ASSERT( pTempString );
      ASSERT_STR_EQUAL( "Springfield", pTempString->data() );
      
      key = "description";
      pTempString = dynamic_cast<UtlString*>(hashmap4.findValue( &key ) );
      CPPUNIT_ASSERT( pTempString );
      ASSERT_STR_EQUAL( "It's a hell of a town", pTempString->data() );
      
      key = "locationcode";
      pTempString = dynamic_cast<UtlString*>(hashmap4.findValue( &key ) );
      CPPUNIT_ASSERT( pTempString );
      ASSERT_STR_EQUAL( "KL5", pTempString->data() );

      key = "subnets";
      pTempString = dynamic_cast<UtlString*>(hashmap4.findValue( &key ) );
      CPPUNIT_ASSERT( pTempString );
      ASSERT_STR_EQUAL( "47.0.0.0/8", pTempString->data() );
   }