示例#1
0
// Constructor
sipXmediaFactoryImpl::sipXmediaFactoryImpl(OsConfigDb* pConfigDb)
{    
    int maxFlowGraph = -1 ; 
    UtlString strInBandDTMF ;
    
    if (pConfigDb)
    {
        pConfigDb->get("PHONESET_MAX_ACTIVE_CALLS_ALLOWED", maxFlowGraph) ;
        pConfigDb->get(CONFIG_PHONESET_SEND_INBAND_DTMF, strInBandDTMF) ;
        strInBandDTMF.toUpper() ;

        OsSysLog::add(FAC_MP, PRI_DEBUG, 
                      "sipXmediaFactoryImpl::sipXmediaFactoryImpl maxFlowGraph = %d",
                      maxFlowGraph);
    }

    // Max Flow graphs
    if (maxFlowGraph <=0 ) 
    {
        maxFlowGraph = MAX_MANAGED_FLOW_GRAPHS;
    }
    if (miInstanceCount == 0)
    {
        mpStartUp(8000, 80, 16*maxFlowGraph, pConfigDb);
    }

    // Should we send inband DTMF by default?    
    if (strInBandDTMF.compareTo("DISABLE") == 0)
    {
        MpCallFlowGraph::setInbandDTMF(false) ;
    }
    else
    {
        MpCallFlowGraph::setInbandDTMF(true) ;
    }

    // init the media processing task
    mpMediaTask = MpMediaTask::getMediaTask(maxFlowGraph); 

#ifdef INCLUDE_RTCP /* [ */
    mpiRTCPControl = CRTCManager::getRTCPControl();
#endif /* INCLUDE_RTCP ] */

    if (miInstanceCount == 0)
    {
        mpStartTasks();  
    }

    miGain = 7 ;
    ++miInstanceCount;
}
示例#2
0
   void testSupportedAndRequiredFields()
   {
      SipUserAgent sipUA( 5090, 5090, 5091, 
                          NULL, NULL,   // default publicAddress and defaultUser
                         "127.0.0.1" ); 

      // Supported
      CPPUNIT_ASSERT( ! sipUA.isExtensionAllowed( "nope" ) );

      UtlString supported( "supported-1" );
      sipUA.allowExtension( supported );

      UtlString tmp;
      sipUA.getSupportedExtensions( tmp );
      CPPUNIT_ASSERT( supported == tmp );
      supported.toUpper();
      CPPUNIT_ASSERT( sipUA.isExtensionAllowed( supported ) );
      CPPUNIT_ASSERT( ! sipUA.isExtensionAllowed( "nope" ) );


      // Required
      CPPUNIT_ASSERT( ! sipUA.isExtensionRequired( "nope" ) );

      UtlString required( "required-1, required-2, required-3" );
      UtlString copy_required( required );
      copy_required += ',';
      ssize_t prev = 0;
      ssize_t index = copy_required.index( ',', prev );
      while( UTL_NOT_FOUND != index )
      {
         UtlString field = copy_required( prev, index - prev );
         field.strip( UtlString::both );
         sipUA.requireExtension( field );
         prev = index + 1;
         index = copy_required.index( ',', prev );
      }

      sipUA.getRequiredExtensions( tmp );
      CPPUNIT_ASSERT( required == tmp );
      index = copy_required.index( ',', prev );
      while( UTL_NOT_FOUND != index )
      {
         UtlString field = copy_required( prev, index - prev );
         field.strip( UtlString::both );
         field.toUpper();
         CPPUNIT_ASSERT( sipUA.isExtensionRequired( field ) );
         prev = index + 1;
         index = copy_required.index( ',', prev );
      }
      CPPUNIT_ASSERT( ! sipUA.isExtensionRequired( "nope" ) );
   }
示例#3
0
UtlBoolean SipRequestContext::getVariable(const char* name, 
                                             UtlString& value, 
                                             int occurance) const
{
    UtlDListIterator iterator((UtlDList&)mVariableList);
    NameValuePair* nameValuePair = NULL;
    int fieldIndex = 0;
    UtlString upperCaseName;
    UtlBoolean foundName = FALSE;

    value.remove(0);

    if(name)
    {
        upperCaseName.append(name);
        upperCaseName.toUpper();
    }
    NameValuePair matchName(upperCaseName);

    // For each name value:
    while(fieldIndex <= occurance)
    {
        // Go to the next header field
        nameValuePair = (NameValuePair*) iterator.findNext(&matchName);

        if(!nameValuePair || fieldIndex == occurance)
        {
            break;
        }
        fieldIndex++;
    }

    if(fieldIndex == occurance && nameValuePair)
    {
        value.append(nameValuePair->getValue());
        foundName = TRUE;
    }

    upperCaseName.remove(0);
    return(foundName);
}
示例#4
0
文件: main.cpp 项目: astubbs/sipxecs
// Initialize the OsSysLog
void initSysLog(OsConfigDb* pConfig)
{
   UtlString logLevel;               // Controls Log Verbosity
   UtlString consoleLogging;         // Enable console logging by default?
   UtlString fileTarget;             // Path to store log file.
   UtlBoolean bSpecifiedDirError ;   // Set if the specified log dir does not
                                    // exist

   OsSysLog::initialize(0, "sipxpark");
   OsSysLog::add(FAC_SIP, PRI_INFO, ">>>>>>>>>>>>>>>> Starting - version %s build %s",
                 SIPX_VERSION, SIPX_BUILD
                 );

   //
   // Get/Apply Log Filename
   //
   fileTarget.remove(0);
   if ((pConfig->get(CONFIG_SETTING_LOG_DIR, fileTarget) != OS_SUCCESS) ||
      fileTarget.isNull() || !OsFileSystem::exists(fileTarget))
   {
      bSpecifiedDirError = !fileTarget.isNull();

      // If the log file directory exists use that, otherwise place the log
      // in the current directory
      OsPath workingDirectory;
      if (OsFileSystem::exists(CONFIG_LOG_DIR))
      {
         fileTarget = CONFIG_LOG_DIR;
         OsPath path(fileTarget);
         path.getNativePath(workingDirectory);

         osPrintf("%s : %s\n", CONFIG_SETTING_LOG_DIR, workingDirectory.data());
         OsSysLog::add(LOG_FACILITY, PRI_INFO, "%s : %s", CONFIG_SETTING_LOG_DIR, workingDirectory.data());
      }
      else
      {
         OsPath path;
         OsFileSystem::getWorkingDirectory(path);
         path.getNativePath(workingDirectory);

         osPrintf("%s : %s\n", CONFIG_SETTING_LOG_DIR, workingDirectory.data());
         OsSysLog::add(LOG_FACILITY, PRI_INFO, "%s : %s", CONFIG_SETTING_LOG_DIR, workingDirectory.data());
      }

      fileTarget = workingDirectory +
         OsPathBase::separator +
         CONFIG_LOG_FILE;
   }
   else
   {
      bSpecifiedDirError = false;
      osPrintf("%s : %s\n", CONFIG_SETTING_LOG_DIR, fileTarget.data());
      OsSysLog::add(LOG_FACILITY, PRI_INFO, "%s : %s", CONFIG_SETTING_LOG_DIR, fileTarget.data());

      fileTarget = fileTarget +
         OsPathBase::separator +
         CONFIG_LOG_FILE;
   }
   OsSysLog::setOutputFile(0, fileTarget);


   //
   // Get/Apply Log Level
   //
   SipXecsService::setLogPriority(*pConfig, CONFIG_SETTING_PREFIX, PRI_ERR);
   OsSysLog::setLoggingPriorityForFacility(FAC_SIP_INCOMING_PARSED, PRI_ERR);

   //
   // Get/Apply console logging
   //
   UtlBoolean bConsoleLoggingEnabled = false;
   if ((pConfig->get(CONFIG_SETTING_LOG_CONSOLE, consoleLogging) == OS_SUCCESS))
   {
      consoleLogging.toUpper();
      if (consoleLogging == "ENABLE")
      {
         OsSysLog::enableConsoleOutput(true);
         bConsoleLoggingEnabled = true;
      }
   }

   osPrintf("%s : %s\n", CONFIG_SETTING_LOG_CONSOLE, bConsoleLoggingEnabled ? "ENABLE" : "DISABLE") ;
   OsSysLog::add(LOG_FACILITY, PRI_INFO, "%s : %s", CONFIG_SETTING_LOG_CONSOLE, bConsoleLoggingEnabled ? "ENABLE" : "DISABLE") ;

   if (bSpecifiedDirError)
   {
      OsSysLog::add(FAC_LOG, PRI_CRIT, "Cannot access %s directory; please check configuration.", CONFIG_SETTING_LOG_DIR);
   }
}
/**
 * Description:
 * closes any open connections to the IMDB safely using a mutex lock
 */
void initSysLog(OsConfigDb* pConfig)
{
   UtlString consoleLogging;         // Enable console logging by default?
   UtlString fileTarget;             // Path to store log file.
   UtlBoolean bSpecifiedDirError ;   // Set if the specified log dir does not
                                    // exist

   Os::LoggerHelper::instance().processName = "SipXProxy";

   //
   // Get/Apply Log Filename
   //
   if ((pConfig->get(CONFIG_SETTING_LOG_DIR, fileTarget) != OS_SUCCESS) ||
      fileTarget.isNull() || !OsFileSystem::exists(fileTarget))
   {
      bSpecifiedDirError = !fileTarget.isNull() ;

      // If the log file directory exists use that, otherwise place the log
      // in the current directory
      OsPath workingDirectory;
      if (OsFileSystem::exists(CONFIG_LOG_DIR))
      {
         fileTarget = CONFIG_LOG_DIR;
         OsPath path(fileTarget);
         path.getNativePath(workingDirectory);

         osPrintf("%s : %s\n", CONFIG_SETTING_LOG_DIR, workingDirectory.data()) ;
         Os::Logger::instance().log(FAC_SIP, PRI_INFO, "%s : %s", CONFIG_SETTING_LOG_DIR, workingDirectory.data()) ;
      }
      else
      {
         OsPath path;
         OsFileSystem::getWorkingDirectory(path);
         path.getNativePath(workingDirectory);

         osPrintf("%s : %s\n", CONFIG_SETTING_LOG_DIR, workingDirectory.data()) ;
         Os::Logger::instance().log(FAC_SIP, PRI_INFO, "%s : %s", CONFIG_SETTING_LOG_DIR, workingDirectory.data()) ;
      }

      fileTarget = workingDirectory + OsPathBase::separator + SIPX_PROXY_LOG_FILE;
   }
   else
   {
      bSpecifiedDirError = false ;
      osPrintf("%s : %s\n", CONFIG_SETTING_LOG_DIR, fileTarget.data()) ;
      Os::Logger::instance().log(FAC_SIP, PRI_INFO, "%s : %s", CONFIG_SETTING_LOG_DIR, fileTarget.data()) ;

      fileTarget = fileTarget +
         OsPathBase::separator +
         SIPX_PROXY_LOG_FILE;
   }

   

   //
   // Get/Apply Log Level
   //
   SipXecsService::setLogPriority( CONFIG_SETTINGS_FILE, PROXY_CONFIG_PREFIX );
   Os::Logger::instance().setLoggingPriorityForFacility(FAC_SIP_INCOMING_PARSED, PRI_ERR);
   Os::LoggerHelper::instance().initialize(fileTarget.data());
   //
   // Get/Apply console logging
   //
   UtlBoolean bConsoleLoggingEnabled = false ;
   if ((pConfig->get(CONFIG_SETTING_LOG_CONSOLE, consoleLogging) ==
         OS_SUCCESS))
   {
      consoleLogging.toUpper();
      if (consoleLogging == "ENABLE")
      {
         Os::Logger::instance().enableConsoleOutput(true);
         bConsoleLoggingEnabled = true ;
      }
   }

   osPrintf("%s : %s\n", CONFIG_SETTING_LOG_CONSOLE, bConsoleLoggingEnabled ? "ENABLE" : "DISABLE") ;
   Os::Logger::instance().log(FAC_SIP, PRI_INFO, "%s : %s",
                 CONFIG_SETTING_LOG_CONSOLE, bConsoleLoggingEnabled ? "ENABLE" : "DISABLE") ;

   if (bSpecifiedDirError)
   {
      Os::Logger::instance().log(FAC_LOG, PRI_CRIT,
                    "Cannot access %s directory; please check configuration.",
                    CONFIG_SETTING_LOG_DIR);
   }
}
示例#6
0
UtlBoolean HttpRequestContext::getCgiVariable(const char* name,
                                             UtlString& value,
                                             int occurance) const
{
   UtlSListIterator iterator((UtlSList&)mCgiVariableList);
   NameValuePair* nameValuePair = NULL;
   int fieldIndex = 0;
   UtlString upperCaseName;
   UtlBoolean foundName = FALSE;
   
   value.remove(0);
 
#  ifdef TEST_DEBUG
   OsSysLog::add(FAC_SIP, PRI_DEBUG,
                 "HttpRequestContext::getCgiVariable %p (\"%s\",<val>,%d)",
                 &mCgiVariableList, name, occurance
                 );
#  endif

   if(name)
   {
      upperCaseName.append(name);
      upperCaseName.toUpper();
   }
   NameValuePair *matchName = ( mUsingInsensitive
                               ? new NameValuePair(upperCaseName)
                               : new NameValuePairInsensitive(upperCaseName)
                               );

   // For each name value:
   for (fieldIndex = 0, nameValuePair = (NameValuePair*) iterator.findNext(matchName);
        fieldIndex < occurance;
        fieldIndex++
        )
   {
      nameValuePair = (NameValuePair*) iterator.findNext(matchName);

#     ifdef TEST_DEBUG
      OsSysLog::add(FAC_SIP, PRI_DEBUG,
                    "HttpRequestContext::getCgiVariable(name,val,occ) %p skipping %d '%s' -> '%s'",
                    &mCgiVariableList,
                    fieldIndex,
                    nameValuePair ? nameValuePair->data() : "UNFOUND",
                    nameValuePair ? nameValuePair->getValue() : "UNFOUND"
                    );
#     endif
   }
   delete matchName;

#  ifdef TEST_DEBUG
   OsSysLog::add(FAC_SIP, PRI_DEBUG,
                 "HttpRequestContext::getCgiVariable(name,val,occ) %p stopped at %d '%s' -> '%s'",
                 &mCgiVariableList, fieldIndex,
                 nameValuePair ? nameValuePair->data() : "UNFOUND",
                 nameValuePair ? nameValuePair->getValue() : "UNFOUND"
                 );
#  endif

   if(fieldIndex == occurance && nameValuePair)
   {
      value.append(nameValuePair->getValue());
      foundName = TRUE;
   }

   return(foundName);
}
示例#7
0
文件: main.cpp 项目: mranga/sipxecs
// Initialize the OsSysLog
void initSysLog(OsConfigDb* pConfig)
{
   UtlString logLevel;               // Controls Log Verbosity
   UtlString consoleLogging;         // Enable console logging by default?
   UtlString fileTarget;             // Path to store log file.
   UtlBoolean bSpecifiedDirError ;   // Set if the specified log dir does not
                                    // exist
   struct tagPrioriotyLookupTable
   {
      const char*      pIdentity;
      OsSysLogPriority ePriority;
   };

   struct tagPrioriotyLookupTable lkupTable[] =
   {
      { "DEBUG",   PRI_DEBUG},
      { "INFO",    PRI_INFO},
      { "NOTICE",  PRI_NOTICE},
      { "WARNING", PRI_WARNING},
      { "ERR",     PRI_ERR},
      { "CRIT",    PRI_CRIT},
      { "ALERT",   PRI_ALERT},
      { "EMERG",   PRI_EMERG},
   };

   OsSysLog::initialize(0, "sipxdialog");


   //
   // Get/Apply Log Filename
   //
   fileTarget.remove(0);
   if ((pConfig->get(CONFIG_SETTING_LOG_DIR, fileTarget) != OS_SUCCESS) ||
      fileTarget.isNull() || !OsFileSystem::exists(fileTarget))
   {
      bSpecifiedDirError = !fileTarget.isNull();

      // If the log file directory exists use that, otherwise place the log
      // in the current directory
      OsPath workingDirectory;
      if (OsFileSystem::exists(CONFIG_LOG_DIR))
      {
         fileTarget = CONFIG_LOG_DIR;
         OsPath path(fileTarget);
         path.getNativePath(workingDirectory);

         osPrintf("%s : %s\n", CONFIG_SETTING_LOG_DIR, workingDirectory.data());
         OsSysLog::add(LOG_FACILITY, PRI_INFO, "%s : %s", CONFIG_SETTING_LOG_DIR, workingDirectory.data());
      }
      else
      {
         OsPath path;
         OsFileSystem::getWorkingDirectory(path);
         path.getNativePath(workingDirectory);

         osPrintf("%s : %s\n", CONFIG_SETTING_LOG_DIR, workingDirectory.data());
         OsSysLog::add(LOG_FACILITY, PRI_INFO, "%s : %s", CONFIG_SETTING_LOG_DIR, workingDirectory.data());
      }

      fileTarget = workingDirectory +
         OsPathBase::separator +
         CONFIG_LOG_FILE;
   }
   else
   {
      bSpecifiedDirError = false;
      osPrintf("%s : %s\n", CONFIG_SETTING_LOG_DIR, fileTarget.data());
      OsSysLog::add(LOG_FACILITY, PRI_INFO, "%s : %s", CONFIG_SETTING_LOG_DIR, fileTarget.data());

      fileTarget = fileTarget +
         OsPathBase::separator +
         CONFIG_LOG_FILE;
   }
   OsSysLog::setOutputFile(0, fileTarget);


   //
   // Get/Apply Log Level
   //
   if ((pConfig->get(CONFIG_SETTING_LOG_LEVEL, logLevel) != OS_SUCCESS) ||
         logLevel.isNull())
   {
      logLevel = "ERR";
   }
   logLevel.toUpper();
   OsSysLogPriority priority = PRI_ERR;
   int iEntries = sizeof(lkupTable) / sizeof(struct tagPrioriotyLookupTable);
   for (int i = 0; i < iEntries; i++)
   {
      if (logLevel == lkupTable[i].pIdentity)
      {
         priority = lkupTable[i].ePriority;
         osPrintf("%s : %s\n", CONFIG_SETTING_LOG_LEVEL, lkupTable[i].pIdentity);
         OsSysLog::add(LOG_FACILITY, PRI_INFO, "%s : %s", CONFIG_SETTING_LOG_LEVEL, lkupTable[i].pIdentity);
         break;
      }
   }
   OsSysLog::setLoggingPriority(priority);
   OsSysLog::setLoggingPriorityForFacility(FAC_SIP_INCOMING_PARSED, PRI_ERR);

   //
   // Get/Apply console logging
   //
   UtlBoolean bConsoleLoggingEnabled = false;
   if ((pConfig->get(CONFIG_SETTING_LOG_CONSOLE, consoleLogging) == OS_SUCCESS))
   {
      consoleLogging.toUpper();
      if (consoleLogging == "ENABLE")
      {
         OsSysLog::enableConsoleOutput(true);
         bConsoleLoggingEnabled = true;
      }
   }

   osPrintf("%s : %s\n", CONFIG_SETTING_LOG_CONSOLE, bConsoleLoggingEnabled ? "ENABLE" : "DISABLE") ;
   OsSysLog::add(LOG_FACILITY, PRI_INFO, "%s : %s", CONFIG_SETTING_LOG_CONSOLE, bConsoleLoggingEnabled ? "ENABLE" : "DISABLE") ;

   if (bSpecifiedDirError)
   {
      OsSysLog::add(FAC_LOG, PRI_CRIT, "Cannot access %s directory; please check configuration.", CONFIG_SETTING_LOG_DIR);
   }
}
示例#8
0
// Constructor
HttpBody::HttpBody(const char* bytes, ssize_t length, const char* contentType) :
   bodyLength(0),
   mBodyPartCount(0)
{
   if (contentType)
   {
      append(contentType);
      NameValueTokenizer::frontBackTrim(this, " \t");
      //osPrintf("Content type: \"%s\"\n", mBodyContentType.data());
      ssize_t boundaryIndex = index(MULTIPART_BOUNDARY_PARAMETER,
                                0, UtlString::ignoreCase);

      if(boundaryIndex >=0 &&
         index(CONTENT_TYPE_MULTIPART,
               0, UtlString::ignoreCase) == 0)
      {
         boundaryIndex += strlen(MULTIPART_BOUNDARY_PARAMETER);
         //osPrintf("Boundary start:=>%s\n",
         //    (mBodyContentType.data())[boundaryIndex]);

         // Allow white space before =
         ssize_t fieldLength = this->length();
         while(boundaryIndex < fieldLength &&
               (data()[boundaryIndex] == ' ' ||
                data()[boundaryIndex] == '\t'))
            boundaryIndex++;

         if(data()[boundaryIndex] == '=')
         {
            mMultipartBoundary.append(&data()[boundaryIndex + 1]);
            NameValueTokenizer::frontTrim(&mMultipartBoundary, " \t");
            ssize_t whiteSpaceIndex = mMultipartBoundary.first(' ');
            if(whiteSpaceIndex > 0) mMultipartBoundary.remove(whiteSpaceIndex);
            whiteSpaceIndex = mMultipartBoundary.first('\t');
            if(whiteSpaceIndex > 0) mMultipartBoundary.remove(whiteSpaceIndex);
            //osPrintf("HttpBody: boundary=\"%s\"\n", mMultipartBoundary.data());
	    mMultipartBoundary.strip(both, '"');
         }
      }
   }

   if(bytes && length < 0) length = strlen(bytes);
   if(bytes && length > 0)
   {
      if (mBody.append(bytes, length).length() > 0) //append was successful
      {
         bodyLength = length;

         if(isMultipart())
         {
            for(unsigned int partIndex = 0;; partIndex++)
            {
               UtlString contentType;
               UtlString name;
               UtlString value;
               const char* partBytes;
               const char* parentBodyBytes;
               ssize_t partLength;
               ssize_t parentBodyLength;
               getBytes(&parentBodyBytes, &parentBodyLength);
               getMultipartBytes(partIndex, &partBytes, &partLength);
               //osPrintf("Body part 1 length: %d\n", firstPart.length());
               //osPrintf("++++ Multipart Body #1 ++++\n%s\n++++ End Multipart #1 ++++\n",
               //    firstPart.data());
               if(partLength <= 0) break;

               // Parse throught the header to the MIME part
               // The first blank line is the begining of the part body
               NameValueTokenizer parser(partBytes, partLength);
                 do
                 {
                     parser.getNextPair(HTTP_NAME_VALUE_DELIMITER,
                     &name, & value);
                     name.toUpper();
                     if(name.compareTo(HTTP_CONTENT_TYPE_FIELD) == 0)
                     {
                         contentType = value;
                     }
                 }
                 while(!name.isNull());

               // This is a bit of a temporary kludge
               //Prepend a HTTP header to make it look like a HTTP message
               //partBytes.insert(0, "GET / HTTP/1.0\n");
               //HttpMessage firstPartMessage(partBytes.data(), partBytes.length());
               //const HttpBody* partFileBody = firstPartMessage.getBody();
               //ssize_t bytesLeft = parser.getProcessedIndex() - partLength;

               if (partLength > 0)
               {
                  mBodyParts.append(new MimeBodyPart(this, partBytes, partBytes - parentBodyBytes,
                                                            partLength,contentType.data()));
                  // Save the number of body parts.
                  mBodyPartCount = partIndex + 1;
               }
            }
         }
      }
   }
}
示例#9
0
void HttpServer::processRequest(const HttpMessage& request,
                                HttpMessage*& response,
                                OsConnectionSocket* connection
                                )
{
    UtlString method;
    response = NULL;

    if(true) // used to be authorization check, but I don't want to change all indenting
    {
        request.getRequestMethod(&method);
        method.toUpper();
        UtlString uri;
        request.getRequestUri(&uri);

        UtlString uriFileName(uri);
        ssize_t fileNameEnd = -1;
        if(method.compareTo(HTTP_GET_METHOD) == 0)
        {
            fileNameEnd = uriFileName.first('?');
            if(fileNameEnd > 0)
            {
               uriFileName.remove(fileNameEnd);
            }
        }

        UtlString mappedUriFileName;
        if (uriFileName.contains(".."))
        {
            OsSysLog::add(FAC_SIP, PRI_ERR, "HttpServer::processRequest "
                          "Disallowing URI: '%s' because it contains '..'",
                          uriFileName.data());

            // Disallow relative path names going up for security reasons
            mappedUriFileName.append("/");
        }
        else
        {
            OsSysLog::add(FAC_SIP, PRI_INFO, "HttpServer::processRequest "
                          "%s '%s'", method.data(), uriFileName.data());

            // Map the file name
            mapUri(mUriMaps, uriFileName.data(), mappedUriFileName);
        }

        // Build the request context
        HttpRequestContext requestContext(method.data(),
                                          uri.data(),
                                          mappedUriFileName.data(),
                                          NULL,
                                          NULL, // was userid
                                          connection
                                          );

        if(requestContext.methodIs(HTTP_POST_METHOD))
        {
            //Need to get the CGI/form variables from the body.
            const HttpBody* body = request.getBody();
            if(body  && !body->isMultipart())
            {
                requestContext.extractPostCgiVariables(*body);
            }
        }

        RequestProcessor* requestProcessorPtr = NULL;
        HttpService* pService = NULL;

        if(   (   requestContext.methodIs(HTTP_GET_METHOD)
               || requestContext.methodIs(HTTP_POST_METHOD)
               )
           && findRequestProcessor(uriFileName.data(), requestProcessorPtr))
        {
            // There is a request processor for this URI
           requestProcessorPtr(requestContext, request, response);
        }
        else if (   (   requestContext.methodIs(HTTP_GET_METHOD)
                     || requestContext.methodIs(HTTP_POST_METHOD)
                     || requestContext.methodIs(HTTP_PUT_METHOD)
                     || requestContext.methodIs(HTTP_DELETE_METHOD)
                     )
                 && findHttpService(uriFileName.data(), pService))
        {
           pService->processRequest(requestContext, request, response);
        }
        else
        {
           processNotSupportedRequest(requestContext, request, response);
        }
    }
}
示例#10
0
UtlBoolean SipPimClient::handleMessage(OsMsg& eventMessage)
{
    int msgType = eventMessage.getMsgType();
    int msgSubType = eventMessage.getMsgSubType();

    // SIP message
    if(msgType == OsMsg::PHONE_APP &&
       msgSubType == SipMessage::NET_SIP_MESSAGE)
    {
        const SipMessage* sipMessage = ((SipMessageEvent&)eventMessage).getMessage();

        // If this is a MESSAGE request
        UtlString method;
        if(sipMessage) sipMessage->getRequestMethod(&method);
        method.toUpper();
        UtlBoolean responseSent = FALSE;
        if(sipMessage &&
            method.compareTo(SIP_MESSAGE_METHOD) == 0 &&
            !sipMessage->isResponse())
        {
            const HttpBody* messageBody = sipMessage->getBody();
            UtlString contentType = messageBody->getContentType();
            // Trim off the MIME parameters if present
            contentType.remove(strlen(CONTENT_TYPE_TEXT_PLAIN));


            // We have a text body and a callback handler function
            if(messageBody &&
               mpTextHandlerFunction &&
               contentType.compareTo(CONTENT_TYPE_TEXT_PLAIN, UtlString::ignoreCase) == 0)
            {
                const char* bodyBytes;
                ssize_t bodyLength;
                messageBody->getBytes(&bodyBytes, &bodyLength);
                UtlString fromField;
                sipMessage->getFromField(&fromField);

                // Send back a 200 response
                SipMessage response;
                response.setResponseData(sipMessage, SIP_OK_CODE, SIP_OK_TEXT);
                mpUserAgent->send(response);
                responseSent = TRUE;

                // Invoke the call back with the info
                mpTextHandlerFunction(fromField, bodyBytes, bodyLength,
                    *sipMessage);

            }

            if(!responseSent)
            {
                // Send an error as we do not accept the content type
                SipMessage badContentResponse;
                badContentResponse.setResponseData(sipMessage,
                                                    SIP_BAD_MEDIA_CODE,
                                                    SIP_BAD_MEDIA_TEXT);
                mpUserAgent->send(badContentResponse);
            }

        }
    }
    return(TRUE);
}
示例#11
0
// Constructor
sipXmediaFactoryImpl::sipXmediaFactoryImpl(OsConfigDb* pConfigDb, 
                                           uint32_t frameSizeMs, 
                                           uint32_t maxSamplesPerSec,
                                           uint32_t defaultSamplesPerSec,
                                           UtlBoolean enableLocalAudio,
                                           const UtlString &inputDeviceName,
                                           const UtlString &outputDeviceName)
{
   // See Doxygen comments for this constructor for information on the impact 
   // of the values of maxSamplesPerFrame and maxSamplesPerSec.
   mFrameSizeMs = (frameSizeMs == 0) ? 10 : frameSizeMs;
   mMaxSamplesPerSec = (maxSamplesPerSec == 0) ? 8000 : maxSamplesPerSec;

   // Default the default sample rate to 8kHz, so NB users will be happy.
   mDefaultSamplesPerSec = (defaultSamplesPerSec == 0) ? 8000 : defaultSamplesPerSec;
   assert(mDefaultSamplesPerSec <= mMaxSamplesPerSec);
   if(mDefaultSamplesPerSec > mMaxSamplesPerSec)
   {
      OsSysLog::add(FAC_MP, PRI_CRIT, 
         "sipXmediaFactoryImpl constructor - %d > %d: "
         "default sample rate is higher than max sample rate!", 
         mDefaultSamplesPerSec, mMaxSamplesPerSec);
   }

   int maxFlowGraph = -1; 
   UtlString strInBandDTMF;
   if (pConfigDb)
   {
      pConfigDb->get("PHONESET_MAX_ACTIVE_CALLS_ALLOWED", maxFlowGraph);
      pConfigDb->get("PHONESET_SEND_INBAND_DTMF", strInBandDTMF);
      strInBandDTMF.toUpper();

      OsSysLog::add(FAC_MP, PRI_DEBUG, 
                    "sipXmediaFactoryImpl::sipXmediaFactoryImpl"
                    " maxFlowGraph = %d",
                    maxFlowGraph);
   }

   // Max Flow graphs
   if (maxFlowGraph <=0 ) 
   {
      maxFlowGraph = MAX_MANAGED_FLOW_GRAPHS;
   }

   // Start audio subsystem if still not started.
   if (miInstanceCount == 0)
   {
      mpStartUp(mMaxSamplesPerSec, (mFrameSizeMs*mMaxSamplesPerSec)/1000, 
                16*maxFlowGraph, pConfigDb, mnCodecPaths, mpCodecPaths);
   }

   // Should we send inband DTMF by default?    
   if (strInBandDTMF.compareTo("DISABLE") == 0)
   {
      MpCallFlowGraph::setInbandDTMF(false);
   }
   else
   {
      MpCallFlowGraph::setInbandDTMF(true);
   }

   // init the media processing task
   mpMediaTask = MpMediaTask::createMediaTask(maxFlowGraph, enableLocalAudio); 

#ifdef INCLUDE_RTCP /* [ */
   mpiRTCPControl = CRTCManager::getRTCPControl();
#endif /* INCLUDE_RTCP ] */

   if (miInstanceCount == 0)
   {
#ifndef ENABLE_TOPOLOGY_FLOWGRAPH_INTERFACE_FACTORY
      mpStartTasks();  
#else
      NetInTask *pTask = NetInTask::getNetInTask();
      if (NULL == pTask) 
      {
         OsSysLog::add(FAC_MP, PRI_ERR, "Could not start NetInTask!!");
      }
#endif
   }

   miGain = 7;
   ++miInstanceCount;

   // We are missing synchronization -- give the tasks time to start
   OsTask::delay(100);
}