void SipImpliedSubscriptions::readConfig( OsConfigDb& configDb )
{
  OsConfigDb impliedSubscriptionConfig;
  OsStatus   found;
  UtlString   key;
  UtlString   name;
  UtlString   recognizer;

  configuredUserAgents.reset();

  // extract the database of implied message waiting subscriptions
  configDb.getSubHash( ConfigPrefix
                      ,impliedSubscriptionConfig
                      );
  for ( key = "", found = impliedSubscriptionConfig.getNext( key
                                                            ,name
                                                            ,recognizer
                                                            );
        found == OS_SUCCESS;
        key = name, found = impliedSubscriptionConfig.getNext( key
                                                              ,name
                                                              ,recognizer
                                                              )
       )
    {
      OsSysLog::add( FAC_SIP, PRI_INFO
                    ,"%s::readConfig name=\"%s\" recognizer=\"%s\""
                    ,mLogName.data(), name.data(), recognizer.data()
                    );
      configuredUserAgents.add( name, recognizer, mLogName );
    }
}
Example #2
0
/// Read (or re-read) whatever configuration the hook requires.
void TestPlugin::readConfig( OsConfigDb& configDb )
{
   UtlString key;
   UtlString value;

   if (mConfigured)
   {
      mConfiguration.destroyAll();
   }

   UtlString place;
   for (; configDb.getNext(place, key, value) == OS_SUCCESS; place = key)
   {
      mConfiguration.insertKeyAndValue(new UtlString(key), new UtlString(value));
   }

   mConfigured = true;
}
Example #3
0
   virtual bool execute(const HttpRequestContext& requestContext, ///< request context
                        UtlSList& params,                         ///< request param list
                        void* userData,                           ///< user data
                        XmlRpcResponse& response,                 ///< request response
                        ExecutionStatus& status
                        )
      {
         UtlString* dbName = dynamic_cast<UtlString*>(params.at(0));

         if (dbName && !dbName->isNull())
         {
            OsReadLock lock(*ConfigRPC::spDatabaseLock);

            // find the dataset registered with this name
            ConfigRPC* db = ConfigRPC::find(*dbName);
            if (db)
            {
               // check with the application to see if this request is authorized on this dataset
               status = db->mCallback->accessAllowed(requestContext, ConfigRPC_Callback::Get);
               if ( XmlRpcMethod::OK == status )
               {
                  // read in the dataset
                  OsConfigDb dataset;
                  OsStatus datasetStatus = db->load(dataset);
                  if ( OS_SUCCESS == datasetStatus )
                  {
                     // get the list of names that the request is asking for
                     UtlContainable* secondParam = params.at(1);
                     if ( secondParam )
                     {
                        UtlSList* nameList = dynamic_cast<UtlSList*>(secondParam);
                        if (nameList)
                        {
                           /*
                            * Iterate over the requested names
                            * - All must be present or the request is an error
                            * - For each name found, add the name and value to the
                            *   selectedParams hash to be returned in a success response.
                            */
                           UtlHashMap selectedParams;
                           UtlSListIterator requestedNames(*nameList);
                           UtlString* requestedName = NULL;
                           bool allNamesFound = true;

                           while (   allNamesFound
                                  && (requestedName = dynamic_cast<UtlString*>(requestedNames()))
                                  )
                           {
                              UtlString* paramValue = new UtlString();
                              if ( OS_SUCCESS == dataset.get(*requestedName, *paramValue) )
                              {
                                 UtlString* paramName  = new UtlString(*requestedName);
                                 // put it into the results
                                 selectedParams.insertKeyAndValue(paramName, paramValue);
                              }
                              else
                              {
                                 allNamesFound = false;
                                 delete paramValue;
                              }
                           }

                           if (allNamesFound)
                           {
                              // all were found - return the name/value pairs
                              response.setResponse(&selectedParams);
                           }
                           else
                           {
                              // at least one name was not found - return an error.
                              UtlString faultMsg;
                              faultMsg.append("parameter name '");
                              faultMsg.append(*requestedName);
                              faultMsg.append("' not found");
                              response.setFault(ConfigRPC::nameNotFound, faultMsg.data());
                              status = XmlRpcMethod::FAILED;
                           }

                           selectedParams.destroyAll();
                        }
                        else
                        {
                           // The second parameter was not a list
                           response.setFault( ConfigRPC::invalidType
                                             ,"namelist parameter is not an array"
                                             );
                           status = XmlRpcMethod::FAILED;
                        }
                     }
                     else // no parameter names specified
                     {
                        // return all names
                        UtlHashMap allParams;
                        UtlString  lastKey;
                        OsStatus   iterateStatus;
                        UtlString* paramName;
                        UtlString* paramValue;
                        bool       notEmpty = false;

                        for ( ( paramName  = new UtlString()
                               ,paramValue = new UtlString()
                               ,iterateStatus = dataset.getNext(lastKey, *paramName, *paramValue)
                               );
                              OS_SUCCESS == iterateStatus;
                              ( lastKey       = *paramName
                               ,paramName     = new UtlString()
                               ,paramValue    = new UtlString()
                               ,iterateStatus = dataset.getNext(lastKey, *paramName, *paramValue)
                               )
                             )
                        {
                           notEmpty = true; // got at least one parameter
                           // put it into the result array
                           allParams.insertKeyAndValue(paramName, paramValue);
                        }
                        // on the final iteration these were not used
                        delete paramName;
                        delete paramValue;

                        if (notEmpty)
                        {
                           response.setResponse(&allParams);
                           allParams.destroyAll();
                        }
                        else
                        {
                           // there is no way to send a well-formed but empty response,
                           // so a 'get all' on an empty dataset returns a fault.
                           UtlString faultMsg;
                           faultMsg.append("dataset '");
                           faultMsg.append(*dbName);
                           faultMsg.append("' has no parameters");
                           response.setFault(ConfigRPC::emptyDataset, faultMsg);
                           status = XmlRpcMethod::FAILED;
                        }
                     }
                  }
                  else
                  {
                     UtlString faultMsg("dataset load failed");
                     response.setFault(ConfigRPC::loadFailed, faultMsg);
                     status = XmlRpcMethod::FAILED;
                  }
               }
               else
               {
                  UtlString faultMsg("Access Denied");
                  response.setFault(XmlRpcMethod::FAILED, faultMsg.data());
               }
            }
            else
            {
               UtlString faultMsg;
               faultMsg.append("db lookup failed for '");
               faultMsg.append(*dbName);
               faultMsg.append("'");
               response.setFault( XmlRpcResponse::UnregisteredMethod, faultMsg.data());
               status = XmlRpcMethod::FAILED;
            }
         }
         else
         {
            response.setFault( XmlRpcResponse::EmptyParameterValue
                              ,"'dbname' parameter is missing or invalid type"
                              );
            status = XmlRpcMethod::FAILED;
         }

         return true;
      }
Example #4
0
void PluginHooks::readConfig(OsConfigDb& configDb)
{
   OsSysLog::add(FAC_KERNEL, PRI_DEBUG, "PluginHooks::readConfig" );

   // Move any existing hooks from the current configured list to
   // a temporary holding list.
   UtlSList existingHooks;
   UtlContainable* existingHook;
   
   UtlSortedListIterator nextHook(mConfiguredHooks);
   while (existingHook = nextHook())
   {
      existingHooks.append(mConfiguredHooks.removeReference(existingHook));
   }
   // the mConfiguredHooks list is now empty
   
   // Walk the current configuration,
   //   any existing hook is moved back to the mConfiguredHooks list,
   //   newly configured hooks are added,
   //   each configured hook is called to read its own configuration.
   UtlString  hookPrefix(mPrefix);
   hookPrefix.append(HOOK_LIB_PREFIX);
   
   OsConfigDb allHooks;
   
   OsSysLog::add(FAC_KERNEL, PRI_DEBUG,
                 "PluginHooks::readConfig looking up hooks '%s'",
                 hookPrefix.data()
                 );
   if (OS_SUCCESS == configDb.getSubHash(hookPrefix, allHooks)) // any hooks configured for prefix?
   {
      UtlString lastHook;
      UtlString hookName;
      UtlString hookLibrary;

      // walk each hook and attempt to load and configure it 
      for ( lastHook = "";
            OS_SUCCESS == allHooks.getNext(lastHook, hookName, hookLibrary);
            lastHook = hookName
           )
      {
         ConfiguredHook* thisHook;
         
         if (NULL == (thisHook = dynamic_cast<ConfiguredHook*>(existingHooks.remove(&hookName))))
         {
            // not an existing hook, so create a new one
            OsSysLog::add(FAC_KERNEL, PRI_DEBUG,
                          "PluginHooks: loading '%s'", hookName.data()
                          );
            thisHook = new ConfiguredHook(hookName, mFactory, hookLibrary);
         }

         // put the hook onto the list of active hooks
         mConfiguredHooks.insert(thisHook);

         // (re)configure the hook
         thisHook->readConfig(mPrefix, configDb);
      }
   }
   else
   {
      OsSysLog::add(FAC_KERNEL, PRI_INFO,
                    "PluginHooks: no '%s' hooks configured", mPrefix.data()
                    );
   }

   // discard any hooks that are no longer in the configuration
   existingHooks.destroyAll();
}
Example #5
0
 void testAccessors()
 {
     OsConfigDb *pDb = new OsConfigDb();
                                                                             
     // the get() method is tested by testManipulators()
                                                                             
     // test the getNext() method
     //
     // We put the following block in its own scope so that the UtlString
     // references (stored in "name" and "value") are released as a side effect
     // of going out of scope.  Otherwise, it will look like a memory leak.
     {
         UtlString  name;
         UtlString  value;
                                                                             
         pDb->set("Key3", "Value3");   // add several entries (not in
         pDb->set("Key2", "Value2");   //  alphabetical or reverse alphabetical
         pDb->set("Key4", "Value4");   //  order
         pDb->set("Key1", "Value1");
         CPPUNIT_ASSERT_MESSAGE("verify that the database is not empty",
                                !pDb->isEmpty());
         CPPUNIT_ASSERT_MESSAGE("has four entries", pDb->numEntries()==4);
                                                                             
         OsStatus res = pDb->getNext("", name, value);      // call getNext("", ...)
         CPPUNIT_ASSERT_MESSAGE("verify that Key1/Value1", 
             res == OS_SUCCESS &&
             name.compareTo("Key1") == 0 &&     //  is returned
             value.compareTo("Value1") == 0);
                                                                             
         res = pDb->getNext("Key1", name, value);
         CPPUNIT_ASSERT_MESSAGE("call getNext(\"Key1\", ...)",
             res == OS_SUCCESS &&               //  verify that Key2/Value2
             name.compareTo("Key2") == 0 &&     //  is returned
             value.compareTo("Value2") == 0);
                                                                             
         res = pDb->getNext("Key2", name, value);
         CPPUNIT_ASSERT_MESSAGE("call getNext(\"Key2\", ...)", 
             res == OS_SUCCESS &&               //  verify that Key3/Value3
             name.compareTo("Key3") == 0 &&     //  is returned
             value.compareTo("Value3") == 0);
                                                                             
         res = pDb->getNext("Key3", name, value);
         CPPUNIT_ASSERT_MESSAGE("call getNext(\"Key3\", ...)", 
             res == OS_SUCCESS &&
             name.compareTo("Key4") == 0 &&
             value.compareTo("Value4") == 0);
     
         res = pDb->getNext("Key4", name, value);
         CPPUNIT_ASSERT_MESSAGE("call getNext(\"Key4\", ...)", 
              res == OS_NO_MORE_DATA &&
              name.compareTo("") == 0 &&
              value.compareTo("") == 0);
                                                                             
         res = pDb->getNext("XXX", name, value);
         CPPUNIT_ASSERT_MESSAGE("call getNext with a key not in the database and verify",
             res == OS_NOT_FOUND &&         
             name.compareTo("") == 0 &&      //  that empty strings are
            value.compareTo("") == 0);       //  returned for the next name
                                             //  and value pair.
                                                                             
         delete pDb;                               // delete the database
         name.remove(0);
         value.remove(0);
     }
 }