Exemplo n.º 1
0
// Get all bindings expiring before newerThanTime.
void
RegistrationDB::getAllOldBindings(int newerThanTime,
                                  UtlHashBag& rAors) const
{
   // Empty the return value.
   rAors.destroyAll();

   if ( m_pFastDB != NULL )
   {
      SMART_DB_ACCESS;

      // Note: callid set to null indicates provisioned entries and
      //        these should not be removed
      dbQuery query;
      query = "expires <", static_cast<const int&>(newerThanTime), " and (callid != '#')";
      dbCursor< RegistrationRow > cursor;
      int rows = cursor.select( query );
      if (rows > 0)
      {
         // Create UtlString containing the AOR from the "uri" column.
         UtlString* uri = new UtlString(cursor->uri);
         // Add it to the result set.
         rAors.insert(uri);
      } while ( cursor.next() );
   }
   else
   {
      OsSysLog::add(FAC_DB, PRI_CRIT, "RegistrationDB::getAllOldBindings failed - no DB");
   }

   return;
}
Exemplo n.º 2
0
    /*!a Test case to test the DestroyAll()
    *    method.
    */
    void testClearAndDestroy()
    {
        const int testCount = 3 ;
        int cCountBefore = UtlContainableTestStub :: getCount() ;
        const char* prefix  = "test the destroyAll() method " ;
        const char* suffix1  = " :- sanity check to double check that the counter was incremented for every new() call" ;
        const char* suffix2 = " :- Verify that all entries are removed and the objects are deleted" ;

        UtlContainableTestStub* uStub ;
        UtlContainableTestStub* uStubPtr ;
        UtlContainableTestStub* uStubPtr2 ;
        uStub = new UtlContainableTestStub(0) ;
        uStubPtr = new UtlContainableTestStub(201) ;
        uStubPtr2 = new UtlContainableTestStub(201) ;
        emptyList.insert(uStub) ;
        emptyList.insert(uStubPtr) ;
        emptyList.insert(uStubPtr2) ;

        cCountBefore = UtlContainableTestStub :: getCount() - cCountBefore ;
        emptyList.destroyAll() ;
        int cCountAfter = UtlContainableTestStub :: getCount() ;

        string msg ;
        // Make sure that static count was incremented for every instance
        // of the TestStub that was created.
        TestUtilities::createMessage(2, &msg, prefix, suffix1) ;
        CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(),  testCount, cCountBefore) ;

        // Verify that the list has no entries left after destroyAll()
        // and also ensure that all the TestStub instances were deleted.
        TestUtilities::createMessage(2, &msg, prefix, suffix2) ;
        CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), 0, cCountAfter) ;
        CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), 0, (int)emptyList.entries()) ;
    } //testClearAndDestroy
Exemplo n.º 3
0
OsStatus OsConfigDb::updateFile(const char* filename) const
{
   UtlString originalFileContents;
   long fileLength = OsFile::openAndRead(filename, originalFileContents);
   const char* unparsedBits = originalFileContents;
   int unparsedLength = originalFileContents.length();

   // Loop through and try to preserve comments, space and order
   int lineStart = 0;
   int lineEnd = 0;
   UtlHashBag writtenNames;
   UtlString newFileContents;
   UtlString name;
   UtlString value;
   UtlString newValue;

   while(lineStart < unparsedLength)
   {
      lineEnd = UtlTokenizer::nextDelim(unparsedBits, lineStart, unparsedLength, "\n\r");

      //printf("start: %d end: %d length: %d\n", lineStart, lineEnd, unparsedLength);

      UtlString oneLine(&unparsedBits[lineStart], lineEnd - lineStart);

      //printf("Line: <%s>\n", oneLine.data());

      // If line contains a parameter
      if(parseLine(oneLine, mCapitalizeName, filename, name, value))
      {
         //printf("name<%s> value<%s>\n", name.data(), value.data());
         if(get(name, newValue) == OS_SUCCESS &&
            !writtenNames.contains(&name))
         {
            //printf("Wrote name<%s>\n", name.data());
            // The parameter still exists in the configDb and we have not yet
            // written it out, write the potentially changed value
            newFileContents.appendFormat("%s : %s\n", name.data(), newValue.data());

            // Save names/parameters written so that we can figure out what has not
            // been written out
            writtenNames.insert(new UtlString(name));
         }
         // else the parameter was removed, do nothing
      }
   
      // The line was a comment or blank line, write it back out the same
      else
      {
         newFileContents.appendFormat("%s\n", oneLine.data());
      }

      lineStart = lineEnd + 1;
   }

   int paramIndex;
   int paramCount = numEntries();
   DbEntry* paramEntry;

   for (paramIndex = 0; paramIndex < paramCount; paramIndex++)
   {
      paramEntry = (DbEntry*) mDb.at(paramIndex);

      removeNewlineReturns(paramEntry->key);
      removeNewlineReturns(paramEntry->value);

      // We have not written the value yet
      if(!writtenNames.contains(&(paramEntry->key)))
      {
          newFileContents.appendFormat("%s : %s\n", paramEntry->key.data(), paramEntry->value.data());
          writtenNames.insert(new UtlString(paramEntry->key));
      }
   }

   fileLength = OsFile::openAndWrite(filename, newFileContents);
 
   writtenNames.destroyAll();

   return(fileLength > 0 ? OS_SUCCESS : OS_INVALID_ARGUMENT);
}
Exemplo n.º 4
0
UtlBoolean SipPublishContentMgr::getContent(const char* resourceId,
        const char* eventTypeKey,
        const char* eventType,
        const char* acceptHeaderValue,
        HttpBody*& content,
        int& version,
        UtlBoolean& isDefaultContent,
        UtlBoolean fullState)
{
    UtlBoolean foundContent = FALSE;
    UtlString key(resourceId);

    key.append(eventTypeKey);
    PublishContentContainer* container = NULL;
    isDefaultContent = FALSE;

    // Turn acceptHeaderValue into a HashBag of its components.
    // acceptedTypesGiven = FALSE if there are no components.
    UtlHashBag contentTypes;
    UtlBoolean acceptedTypesGiven =
        buildContentTypesContainer(acceptHeaderValue, contentTypes);

    lock();

    UtlHashBag* pContent;
    if (fullState)
    {
        // Full content (this is the usual case)
        pContent = &mContentEntries;
    }
    else
    {
        // Partial content (used for partial dialog events)
        pContent = &mPartialContentEntries;
    }

    // See if resource-specific content exists
    container =
        dynamic_cast <PublishContentContainer*> (pContent->find(&key));

    // There is no resource-specific content.  Check if the default
    // constructor exists.
    if (container == NULL)
    {
        // Construct the key for the default data.
        UtlString default_key(eventTypeKey);

        // Look up the constructor.

        SipPublishContentMgrDefaultConstructor* constructor =
            dynamic_cast <SipPublishContentMgrDefaultConstructor*>
            (mDefaultContentConstructors.findValue(&default_key));
        // If it exists, call it to publish content for this resource/event.
        if (constructor)
        {
            constructor->generateDefaultContent(this, resourceId,
                                                eventTypeKey, eventType);
        }

        // See if resource specific content exists now.
        container =
            dynamic_cast <PublishContentContainer*> (pContent->find(&key));

        // If content was found, still mark it as default content.
        if (container)
        {
            isDefaultContent = TRUE;
        }
        // If still no content was found, check if the default exists.
        else
        {
            container =
                dynamic_cast <PublishContentContainer*>
                (mDefaultContentEntries.find(&default_key));
            if(container)
            {
                isDefaultContent = TRUE;
            }
        }
    }

    // Within the container, find the content of the right MIME type.
    if (container)
    {
        if (acceptedTypesGiven)
        {
            UtlString base_mime_type;

            // Search for the first content in the container whose
            // MIME type is in the acceptable list.
            UtlSListIterator contentIterator(container->mEventContent);
            HttpBody* bodyPtr;
            UtlSListIterator versionIterator(container->mEventVersion);
            UtlInt* versionPtr;
            while (!foundContent &&
                    (bodyPtr = dynamic_cast <HttpBody*> (contentIterator())) &&
                    (versionPtr = dynamic_cast <UtlInt*> (versionIterator())))
            {
                // Test if ';' is present in *bodyPtr's MIME type.
                // (Remember that an HttpBody considered as a UtlString has
                // the value of its content type.)
                ssize_t i = bodyPtr->index(';');

                // The 'if expression' is TRUE if the MIME type of *bodyPtr
                // is found in in contentTypes.  This is messy, because
                // *bodyPtr's MIME type may have parameters, which have
                // to be removed before searching contentTypes.
                if (contentTypes.find(i == UTL_NOT_FOUND ?
                                      bodyPtr :
                                      ( base_mime_type.remove(0),
                                        base_mime_type.append(*bodyPtr, 0, i),
                                        &base_mime_type)))
                {
                    content = bodyPtr->copy();
                    version = versionPtr->getValue();
                    foundContent = TRUE;
                }
            }
            if (!foundContent)
            {
                // No content was found that matched the required MIME types.
                OsSysLog::add(FAC_SIP, PRI_WARNING,
                              "SipPublishContentMgr::getContent no content found for key '%s', acceptHeaderValue '%s', resourceId '%s', eventTypeKey ='%s', eventType '%s'",
                              key.data(),
                              acceptHeaderValue ? acceptHeaderValue : "[none]",
                              resourceId ? resourceId : "[none]",
                              eventTypeKey, eventType);
            }
        }
        else
        {
            // No MIME types were specified, take the first content in the list.
            HttpBody* bodyPtr =
                dynamic_cast <HttpBody*> (container->mEventContent.first());
            UtlInt* versionPtr =
                dynamic_cast <UtlInt*> (container->mEventVersion.first());
            if (bodyPtr)
            {
                content = bodyPtr->copy();
                version = versionPtr->getValue();
                foundContent = TRUE;
            }
            else
            {
                // No content was found (at all).
                OsSysLog::add(FAC_SIP, PRI_WARNING,
                              "SipPublishContentMgr::getContent no content found for key '%s', acceptHeaderValue '%s', resourceId '%s', eventTypeKey ='%s', eventType '%s'",
                              key.data(),
                              acceptHeaderValue ? acceptHeaderValue : "[none]",
                              resourceId ? resourceId : "[none]",
                              eventTypeKey, eventType);
            }
        }
    }
    else
    {
        // No container found for this resource and event.
        OsSysLog::add(FAC_SIP, PRI_WARNING,
                      "SipPublishContentMgr::getContent no container found for key '%s', acceptHeaderValue '%s', resourceId '%s', eventTypeKey ='%s', eventType '%s', fullState = %d",
                      key.data(),
                      acceptHeaderValue ? acceptHeaderValue : "[none]",
                      resourceId ? resourceId : "[none]",
                      eventTypeKey, eventType,
                      fullState);
    }

    unlock();

    contentTypes.destroyAll();
    return (foundContent);
}