/**
 *
 * @brief Get Proxyserver info
 *
 * @param[out] ProxyServer
 * @param[in] ProxyServerLen
 * @param[out] ProxyServerLenReq
 *
 * @return HTTPReturnCode
 */
HTTPReturnCode HTTPStackHelper::GetProxyServer
(
 char* ProxyServer,
 size_t ProxyServerLen,
 size_t &ProxyServerLenReq
)
{
  HTTPReturnCode rsltCode = HTTP_FAILURE;
  ProxyServerLenReq = 0;

  if (m_ProxyServerName)
  {
    size_t servLen = std_strlen(m_ProxyServerName);
    if (servLen > 0)
    {
      size_t reqProxyStrLen = servLen + 7; //(7 characters assuming max port 65535,":","\0" )

      char *localProxyStr = (char *)QTV_Malloc((reqProxyStrLen) * sizeof(char));
      if (localProxyStr)
      {
        size_t offset = 0;
        offset += std_strlprintf(localProxyStr+offset,reqProxyStrLen-offset, "%s:%d",
                                 m_ProxyServerName,m_ProxyServerPort);

        size_t actualProxyStrLen = std_strlen(localProxyStr);
        if (actualProxyStrLen > 0)
        {
          if (ProxyServer != NULL && ProxyServerLen > 0 )
          {
            if (ProxyServerLen > actualProxyStrLen)
            {
              std_strlcpy(ProxyServer,localProxyStr,ProxyServerLen);
              ProxyServerLenReq = actualProxyStrLen ;
              rsltCode = HTTP_SUCCESS;
            }
            else if (ProxyServerLen <= actualProxyStrLen )
            {
              ProxyServerLenReq = actualProxyStrLen+1 ;
              rsltCode = HTTP_BADPARAM;
            }
          }
          else if(ProxyServer == NULL && ProxyServerLen == 0)
          {
            ProxyServerLenReq = actualProxyStrLen ;
            rsltCode = HTTP_SUCCESS;
          }
        }
        QTV_Free(localProxyStr);
        localProxyStr = NULL;
      }
    }
  }
  return rsltCode;
}
HTTPReturnCode
HTTPStackHelper::GetContentType(uint32 requestId,
                                char *contentType,
                                size_t contentTypeLen,
                                size_t *contentTypeLenReq)
{
  HTTPReturnCode result = HTTP_FAILURE;

  if (NULL == m_HTTPState)
  {
    QTV_MSG_PRIO(QTVDIAG_HTTP_STACK, QTVDIAG_PRIO_ERROR,
      "HTTPStackHelper::GetContentType : m_HTTPState is NULL");
  }
  else
  {
    GetContentTypeArgument arg(contentType, contentTypeLen, contentTypeLenReq);

    const char *respContentType = m_HTTPStateInfo.GetContentType(requestId);
    if (NULL == contentType)
    {
      if(NULL != respContentType)
      {
        *contentTypeLenReq = std_strlen(respContentType) + 1;
        result = HTTP_SUCCESS;
      }
    }
    else
    {
      if (NULL != respContentType)
      {
        std_strlcpy(contentType, respContentType, contentTypeLen);
        result = HTTP_SUCCESS;
      }
    }
  }

  return result;
}
예제 #3
0
/**
 * Initializes the Diag Interface
 *
 * @return 0 value on success else failure
 */
int MM_Debug_Initialize()
{
  int index;
  int res=1;
  //! Lock the function using static Mutex
  res = pthread_mutex_lock(&mOSALMutex);
  if (0 != res)
  {
    LOGE("Mutex Lock failed in Init, %d", res);
  }

  /* Below counter will help to check whether mask is already updated or not.
     It is not required to execute same config file multiple times. */
  if (nMMOSALDebugRefCnt == 0)
  {
    char MMOSALDebugConfig[MMOSAL_CONFIG_BUFFER_SIZE];
    MM_HANDLE nMMOSALDebugConfigFile = NULL;
    size_t pnBytesRead = 0;

    /*  Default bit mask. Error and Fatal are enabled.
    0 0 1 1 1 1 1 1 <- bit mask
        D F E H M L (Debug, Fatal, Error, High, Medium, Low)
    0 0 0 1 1 1 0 0 default priority*/

    for(index=0;index<MAP_SIZE;index++)
    {
      ssidMaskMap[index]=24;
    }

    MMOSALDebugConfig[0] = '\0';

    /*
     * To keep the config file path location backward compatible with other domains like
     * WFD, first attempt is to read from MMOSAL_LOGMASK_CONFIG_FILE (path loc is /data/)
     * If file open or read permission issues in above location then read from
     * MMOSAL_LOGMASK_CONFIG_FILE_MEDIASERVER (path loc is /data/misc/media) which is
     * the partition location that media server process should use.
     */

    res = MM_File_Create(MMOSAL_LOGMASK_CONFIG_FILE, MM_FILE_CREATE_R, &nMMOSALDebugConfigFile);
    if (res == 0)
    {
      res = MM_File_Read(nMMOSALDebugConfigFile, MMOSALDebugConfig, (size_t)MMOSAL_CONFIG_BUFFER_SIZE,(ssize_t *) &pnBytesRead);
      MM_File_Release(nMMOSALDebugConfigFile);
    }

    if(res != 0)
    {
      LOGE("Open or read fail on /data/mmosal_logmask.cfg. Possible permission denied issue. Looking for /data/misc/media/mmosal_logmask.cfg");
      res = MM_File_Create(MMOSAL_LOGMASK_CONFIG_FILE_MEDIASERVER, MM_FILE_CREATE_R, &nMMOSALDebugConfigFile);
      if (res == 0)
      {
        res = MM_File_Read(nMMOSALDebugConfigFile, MMOSALDebugConfig, (size_t)MMOSAL_CONFIG_BUFFER_SIZE,(ssize_t *) &pnBytesRead);
        MM_File_Release(nMMOSALDebugConfigFile);
      }
    }

    if (res == 0 && pnBytesRead > 0)
    {
      MMOSALDebugConfig[pnBytesRead] = '\0';
    }

    if (std_strlen(MMOSALDebugConfig) > 0)
    {
      char sPattern[32];
      int nLogMask = 0;
      char* pLogMask = NULL;

      (void)std_strlprintf(sPattern, sizeof(sPattern), "LOGMASK = %d", MSG_SSID_APPS_ALL);
      pLogMask = std_strstr(MMOSALDebugConfig, sPattern);
      if (pLogMask)
      {
        int index;
        nLogMask = atoi(pLogMask + std_strlen(sPattern)+1);
        for(index=0;index<MAP_SIZE;index++)
        {
          ssidMaskMap[index]=nLogMask;
        }
      }

      (void)std_strlprintf(sPattern, sizeof(sPattern), "LOGMASK = ");
      pLogMask = std_strstr(MMOSALDebugConfig, sPattern);

      if (pLogMask)
      {
        int nSysID=0;
        do
        {
          pLogMask = pLogMask + std_strlen(sPattern);
          nSysID=atoi(pLogMask)-MSG_SSID_APPS;
          nLogMask = atoi(pLogMask+5);
          if (nSysID < MAP_SIZE)
          {
           ssidMaskMap[nSysID]=nLogMask;
           pLogMask = std_strstr(pLogMask, sPattern);
          }
        } while (pLogMask!='\0');
      }
    }
  }
  nMMOSALDebugRefCnt++;
  res = pthread_mutex_unlock(&mOSALMutex);
  if (0 != res)
  {
    LOGE("Mutex UnLock failed in Init, %d", res);
  }
  return 0;
}
/**
 * @brief
 *  Update data structures related to event id passed.for QOE data.
 *
 * @param pHTTPSourceMMIHelper
 * @param eventID
 *
 * @return None
 */
void HTTPSourceMMIExtensionEventHandler::HTTPQOEEventManager::
     UpdateQOEData(HTTPSourceMMIHelper *pHTTPSourceMMIHelper,
                   const uint32 eventID)
{
  if(m_bQOENotify)
  {
    QTV_MSG_PRIO1(QTVDIAG_HTTP_STREAMING, QTVDIAG_PRIO_LOW,
      "HTTPSourceMMIExtensionEventHandler::HTTPQOEEventManager::UpdateQOEData eventID = %u",eventID);
    char* pVideoURL = NULL;
    uint32 nBandwidth = 0;
    uint32 nBufCount = 0;
    size_t nURLSize = 0;
    size_t nIPAddrSize = 0;
    size_t    nStopPhraseSize = 0;
    bool   bUpdateRequired = false;
    uint64 currMSeconds = 0;
    (void)MM_Time_GetCurrentTimeInMilliSecsFromEpoch(&currMSeconds);
    switch(eventID)
    {
      case QOMX_HTTP_IndexParamQOEPlay:
        if(!dataPlay)
        {
          dataPlay = (QOMX_QOE_DATA_PLAY *)QTV_Malloc(sizeof(QOMX_QOE_DATA_PLAY));
        }
        if(dataPlay)
        {
          memset(dataPlay,0,sizeof(QOMX_QOE_DATA_PLAY));
          dataPlay->size = (OMX_U32)sizeof(QOMX_QOE_DATA_PLAY);
          dataPlay->timeOfDay = currMSeconds;
        }
        break;
      case QOMX_HTTP_IndexParamQOESwitch:
        {
          if(pHTTPSourceMMIHelper)
          {
            pHTTPSourceMMIHelper->GetQOEData(nBandwidth,nBufCount,NULL,nURLSize,NULL,nIPAddrSize,NULL,nStopPhraseSize);
          }
          if(!dataSwitch)
          {
            dataSwitch = (QOMX_QOE_DATA_SWITCH *)QTV_Malloc(sizeof(QOMX_QOE_DATA_SWITCH));
          }
          if(dataSwitch)
          {
            memset(dataSwitch,0,sizeof(QOMX_QOE_DATA_SWITCH));
            dataSwitch->bandwidth  = nBandwidth;
            dataSwitch->reBufCount = nBufCount;
            dataSwitch->timeOfDay  = currMSeconds;
          }
        }
        break;
      case QOMX_HTTP_IndexParamQOEPeriodic:
        {
          char* pIPAddress = NULL;
          if(pHTTPSourceMMIHelper)
          {
            pHTTPSourceMMIHelper->GetQOEData(nBandwidth,nBufCount,pVideoURL,nURLSize,pIPAddress,nIPAddrSize,NULL,nStopPhraseSize);
            if(pVideoURL == NULL && nURLSize)
            {
              pVideoURL = (char*)QTV_Malloc(nURLSize+1);
              if(pVideoURL)
              {
                bUpdateRequired = true;
              }
            }
            if(pIPAddress == NULL && nIPAddrSize)
            {
              pIPAddress = (char*)QTV_Malloc(nIPAddrSize+1);
              if(pIPAddress)
              {
                bUpdateRequired = true;
              }
            }
            if(bUpdateRequired)
            {
              pHTTPSourceMMIHelper->GetQOEData(nBandwidth,nBufCount,pVideoURL,nURLSize,pIPAddress,nIPAddrSize,NULL,nStopPhraseSize);
              bUpdateRequired = false;
            }
          }
          size_t nSize = sizeof(QOMX_QOE_DATA_PERIODIC)+nURLSize+1+nIPAddrSize+1;
          if(dataPeriodic)
          {
            QTV_Free(dataPeriodic);
          }
          dataPeriodic = (QOMX_QOE_DATA_PERIODIC *)QTV_Malloc(nSize);
          if(dataPeriodic)
          {
            memset(dataPeriodic,0,nSize);
            dataPeriodic->size = (uint32)nSize;
            dataPeriodic->bandwidth = nBandwidth;
            dataPeriodic->timeOfDay = currMSeconds;
            dataPeriodic->nInfoPeriodicLen = (OMX_U32)(nURLSize+1+nIPAddrSize+1);
            if(pIPAddress)
            {
              std_memmove(dataPeriodic->infoPeriodic,pIPAddress,std_strlen(pIPAddress)+1);
              dataPeriodic->nIpAddressLen = (OMX_U32)std_strlen(pIPAddress)+1;
            }
            if(pVideoURL)
            {
              std_memmove(dataPeriodic->infoPeriodic+dataPeriodic->nIpAddressLen,pVideoURL,std_strlen(pVideoURL)+1);
              dataPeriodic->nVideoURLLen =  (OMX_U32)std_strlen(pVideoURL)+1;
            }
          }
          if(pIPAddress)
          {
            QTV_Free(pIPAddress);
            pIPAddress = NULL;
          }
        }
        break;
      case QOMX_HTTP_IndexParamQOEStop:
        {
          char* pStopPhrase = NULL;
          if(pHTTPSourceMMIHelper)
          {
            pHTTPSourceMMIHelper->GetQOEData(nBandwidth,nBufCount,pVideoURL,nURLSize,NULL,nIPAddrSize,pStopPhrase,nStopPhraseSize);
            if(pVideoURL == NULL && nURLSize)
            {
              pVideoURL = (char*)QTV_Malloc(nURLSize+1);
              if(pVideoURL)
              {
                bUpdateRequired = true;
              }
            }
            if(pStopPhrase == NULL && nStopPhraseSize)
            {
              pStopPhrase = (char*)QTV_Malloc(nStopPhraseSize+1);
              if(pStopPhrase)
              {
                bUpdateRequired = true;
              }
            }
            if(bUpdateRequired)
            {
              pHTTPSourceMMIHelper->GetQOEData(nBandwidth,nBufCount,pVideoURL,nURLSize,NULL,nIPAddrSize,pStopPhrase,nStopPhraseSize);
              bUpdateRequired = false;
            }
          }
          size_t nSize = sizeof(QOMX_QOE_DATA_STOP)+nURLSize+1+nStopPhraseSize+1;
          if(dataStop)
          {
            QTV_Free(dataStop);
          }
          dataStop = (QOMX_QOE_DATA_STOP *)QTV_Malloc(nSize);
          if(dataStop)
          {
            memset(dataStop,0,nSize);
            dataStop->size = (OMX_U32)nSize;
            dataStop->bandwidth = (OMX_U32)nBandwidth;
            dataStop->reBufCount = nBufCount;
            dataStop->timeOfDay = currMSeconds;
            dataStop->nInfoStopLen = (OMX_U32)(nURLSize+1+nStopPhraseSize+1);
            if(pStopPhrase)
            {
              std_memmove(dataStop->infoStop,pStopPhrase,std_strlen(pStopPhrase)+1);
              dataStop->nStopPhraseLen = (OMX_U32)(std_strlen(pStopPhrase)+1);
            }

            if(pVideoURL)
            {
              std_memmove(dataStop->infoStop+dataStop->nStopPhraseLen,pVideoURL,std_strlen(pVideoURL)+1);
              dataStop->nVideoURLLen = (OMX_U32)(std_strlen(pVideoURL)+1);
            }
          }
          if(pStopPhrase)
          {
            QTV_Free(pStopPhrase);
            pStopPhrase = NULL;
          }
        }
        break;
      default:
        break;
    }
    if(pVideoURL)
    {
      QTV_Free(pVideoURL);
      pVideoURL = NULL;
    }
  }
}
/** @brief IDLE state handler.
  *
  * @param[in] pHttpResolver - Reference to HTTPResolver
  * @return
  * HTTPDL_WAITING - Successfully posted GET request to the HTTP stack
  * HTTPDL_ERROR_ABORT - Error
  */
HTTPDownloadStatus HTTPResolver::IdleStateHandler::Execute
(
 HTTPResolver* pHttpResolver
)
{
  QTV_MSG_PRIO( QTVDIAG_HTTP_STREAMING, QTVDIAG_PRIO_LOW,
                "HTTPResolver::IdleStateHandler::Execute()" );
  HTTPDownloadStatus status = HTTPCommon::HTTPDL_ERROR_ABORT;
  HTTPResolver* pSelf = static_cast<HTTPResolver *> (pHttpResolver);

  //Validity check
  if (pSelf)
  {
    HTTPSessionInfo& sessionInfo = pSelf->m_sessionInfo;
    URL url = sessionInfo.GetURL();
    char* pLaunchURL = pSelf->m_pLaunchURL;
    HTTPMethodType methodType = HTTP_GET;

    //Prepare launch URL
    if (HTTPCommon::ParseURL(url, HTTP_DEFAULT_PORT, pLaunchURL) && pLaunchURL)
    {
      pSelf->m_pLaunchURL = pLaunchURL;
      HTTPStackInterface& HTTPStack = pSelf->m_pHTTPStack;

      if(HTTPStack.CreateRequest(pSelf->m_nRequestID) == HTTP_SUCCESS )
      {
        //Add HTTP headers
        char hostName[HTTP_MAX_HOSTNAME_LEN] = {0};
        if (url.GetHost(hostName, sizeof(hostName)) == URL::URL_OK)
        {
            (void)HTTPStack.SetHeader(pSelf->m_nRequestID, "Host", (int)std_strlen("Host"),
                                    hostName, (int)std_strlen(hostName));
        }

        char range[HTTP_MAX_RANGE_LEN] = {0};
        if (pSelf->m_nMaxRequestSize >= 0)
        {
          (void)std_strlprintf(range, sizeof(range), "bytes=%d-%d", 0, (int)pSelf->m_nMaxRequestSize);
        }
        else
        {
        (void)std_strlprintf(range, sizeof(range), "bytes=%d-", 0);
        }

          (void)HTTPStack.SetHeader(pSelf->m_nRequestID, "Range", (int)std_strlen("Range"),
                                  range, (int)std_strlen(range));

        const char* pUserAgent = sessionInfo.GetUserAgent();
        if (pUserAgent)
        {
            (void)HTTPStack.SetHeader(pSelf->m_nRequestID, "User-Agent",
                                    (int)std_strlen("User-Agent"),
                                    pUserAgent, (int)std_strlen(pUserAgent));
        }

        //Add any OEM headers
        HTTPCommon::AddIPStreamProtocolHeaders(sessionInfo, HTTPStack, methodType, pSelf->m_nRequestID);

        //Send HTTP GET request
        QTV_MSG_SPRINTF_PRIO_2( QTVDIAG_HTTP_STREAMING, QTVDIAG_PRIO_HIGH,
                                "HTTPResolver::IdleStateHandler: Posting GET %s for %s", range, pLaunchURL );
          HTTPReturnCode result = HTTPStack.SendRequest(pSelf->m_nRequestID, methodType,
                                                      pLaunchURL,
                                                      (int)std_strlen(pLaunchURL));
        if (result == HTTP_SUCCESS)
        {
          //HTTP GET request successfully composed and posted to the HTTP stack,
          //move to WAIT_FOR_DATA
          status = HTTPCommon::HTTPDL_WAITING;
          pSelf->SetStateHandler(&pSelf->m_WaitForDataStateHandler);
          QTV_MSG_PRIO( QTVDIAG_HTTP_STREAMING, QTVDIAG_PRIO_MEDIUM,
                        "HTTPResolver::IdleStateHandler: HTTP GET request successfully "
                        "composed and posted to HTTP stack - moving to WAIT_FOR_DATA" );
        }
        else
        {
          QTV_MSG_PRIO1( QTVDIAG_HTTP_STREAMING, QTVDIAG_PRIO_ERROR,
                         "HTTPResolver::IdleStateHandler: Posting HTTP GET failed %d",
                         result );
        }
      }
      else
      {
        QTV_MSG_PRIO( QTVDIAG_HTTP_STREAMING, QTVDIAG_PRIO_ERROR,
                      "Error Creating Request");
      }
    }// if (HTTPCommon::ParseURL())
  }// if (pSelf)

  return status;
}
HTTPReturnCode
HTTPStackHelper::NotifyEvent(uint32 requestId, HTTPStackNotifyCode notifyCode)
{
  HTTPReturnCode rsltCode = HTTP_FAILURE;

  HTTPStackNotificationCbData cbData = {0,NULL,NULL,false,NULL,NULL,NULL};
  cbData.m_serverCode = m_HTTPStateInfo.GetHTTPResponseCode(requestId);
  cbData.m_serverMessage = (char*)m_HTTPStateInfo.GetReasonPhraseStr(requestId);
  cbData.m_entityBody = (char*)m_HTTPStateInfo.GetEntityBody(requestId);
  cbData.m_method = (char *)HTTPStackCommon::GetStringForMethod(m_HTTPStateInfo.GetRequestMethod(requestId));
  cbData.m_protocolHeaders = NULL;
  cbData.m_pHTTPStack = m_pHTTPStack;

  int reqLen = 0;

  /**
  * This commented code is in line with what is specified for
  * protocol header events. However, current decision is to send
  * protocol header event for authorization or porxy-authoirzation
  * only. If this changes then this can be uncommented and th the
  * code following this can be
  * removed.
  *
  * httpResponse.GetHeaders(NULL, 0, reqLen);
  *
  * if (reqLen > 0)
  *{
  * int bufSize = reqLen; cbData.m_protocolHeaders = (char
  *
  *  *)QTV_Malloc(bufSize * sizeof(char));
  *
  * if (cbData.m_protocolHeaders)
  * {
  *   httpResponse.GetHeaders(cbData.m_protocolHeaders,bufSize,
  *reqLen);
  *  }
  *  }
  *  else {
  *  QTV_MSG_PRIO1(QTVDIAG_HTTP_STREAMING, QTVDIAG_PRIO_ERROR,
  *
  *   "HTTPStackHelper::NotifyEvent Did not find headers for
  *   response. ServerCode %d", cbData.m_serverCode);
  *   }
  */

  static const int AUTHENTICATE_KEY_LEN = (int)std_strlen(HTTPStackCommon::AUTHENTICATE_KEY);
  static const int PROXY_AUTHENTICATE_KEY_LEN = (int)std_strlen(HTTPStackCommon::PROXY_AUTHENTICATE_KEY);
  static const char *DELIM = ": ";
  static const int DELIM_LEN = (int)std_strlen(DELIM);
  static const char *TERMINATE = "\r\n\r\n";
  static const int TERMINATE_LEN = (int)std_strlen(TERMINATE);

    m_HTTPStateInfo.GetHeaderValue(requestId,
    HTTPStackCommon::AUTHENTICATE_KEY, AUTHENTICATE_KEY_LEN,
    NULL, 0, &reqLen);

  if (reqLen > 0)
  {
    // response header contains "WWW-Authenticate"
    int reqdBufSize = AUTHENTICATE_KEY_LEN + DELIM_LEN + reqLen + TERMINATE_LEN + 1;
    cbData.m_protocolHeaders = (char *)QTV_Malloc(reqdBufSize * sizeof(char));
    if (cbData.m_protocolHeaders)
    {
      std_strlcpy(cbData.m_protocolHeaders, HTTPStackCommon::AUTHENTICATE_KEY, reqdBufSize);
      std_strlcat(cbData.m_protocolHeaders, DELIM, reqdBufSize);
      int tmpLen = reqLen;
      m_HTTPStateInfo.GetHeaderValue(requestId,
        HTTPStackCommon::AUTHENTICATE_KEY, AUTHENTICATE_KEY_LEN,
        cbData.m_protocolHeaders + AUTHENTICATE_KEY_LEN + DELIM_LEN, reqLen, &tmpLen);
      std_strlcat(cbData.m_protocolHeaders, TERMINATE, reqdBufSize);
    }
    else
    {
      QTV_MSG_PRIO(QTVDIAG_HTTP_STREAMING, QTVDIAG_PRIO_ERROR,
        "cbData.m_protocolHeaders for authentication is NULL");
    }
  }
  else
  {
      m_HTTPStateInfo.GetHeaderValue(requestId,
      HTTPStackCommon::PROXY_AUTHENTICATE_KEY, PROXY_AUTHENTICATE_KEY_LEN,
      NULL, 0, &reqLen);

    if (reqLen > 0)
    {
      int reqdBufSize = PROXY_AUTHENTICATE_KEY_LEN + DELIM_LEN + reqLen + TERMINATE_LEN + 1;
      cbData.m_protocolHeaders = (char *)QTV_Malloc(reqdBufSize * sizeof(char));

      if (cbData.m_protocolHeaders)
      {
        std_strlcpy(cbData.m_protocolHeaders, HTTPStackCommon::PROXY_AUTHENTICATE_KEY, reqdBufSize);
        std_strlcat(cbData.m_protocolHeaders, DELIM, reqdBufSize);
        int tmpLen = reqLen;
        m_HTTPStateInfo.GetHeaderValue(requestId,
          HTTPStackCommon::PROXY_AUTHENTICATE_KEY, PROXY_AUTHENTICATE_KEY_LEN,
          cbData.m_protocolHeaders + PROXY_AUTHENTICATE_KEY_LEN + DELIM_LEN, reqLen, &tmpLen);
        std_strlcat(cbData.m_protocolHeaders, TERMINATE, reqdBufSize);
      }
      else
      {
        QTV_MSG_PRIO(QTVDIAG_HTTP_STREAMING, QTVDIAG_PRIO_ERROR,
          "cbData.m_protocolHeaders for proxy-authentication is NULL");
      }
    }
  }

  rsltCode =  m_fNotifyCallback(requestId, notifyCode,&cbData, m_pOwner);

  return rsltCode;
}
/** @brief IDLE state handler.
*
* @param[in] pDownloadHelper - Reference to PlaylistDownloadHelper
* @return
* HTTPDL_WAITING - Successfully initiated connection and GET request posted
*                  to the HTTP stack
* HTTPDL_ERROR_ABORT - Otherwise
*/
HTTPDownloadStatus PlaylistDownloadHelper::IdleStateHandler::Execute
(
 PlaylistDownloadHelper* pDownloadHelper
 )
{
  QTV_MSG_PRIO( QTVDIAG_HTTP_STREAMING, QTVDIAG_PRIO_LOW,
    "PlaylistDownloadHelper::IdleStateHandler::Execute()" );
  HTTPDownloadStatus status = HTTPCommon::HTTPDL_ERROR_ABORT;
  PlaylistDownloadHelper* pSelf = pDownloadHelper;

  //Validity check
  if (pSelf)
  {
    char* pLaunchURL = pSelf->m_pLaunchURL;

    //Fill in default port if port already not present in URL
    if (pSelf->ParseURL(HTTP_DEFAULT_PORT, pLaunchURL) && pLaunchURL)
    {
      HTTPMethodType methodType = HTTP_GET;
      status = HTTPCommon::HTTPDL_SUCCESS;
      pSelf->m_pLaunchURL = pLaunchURL;
      HTTPStackInterface& HTTPStack = *(pSelf->m_pHTTPStack);

      if(HTTPStack.CreateRequest(pSelf->m_nRequestID) == HTTP_SUCCESS)
      {
        URL url = pSelf->GetURL();
        char hostName[HTTP_MAX_HOSTNAME_LEN] = {0};
        if (url.GetHost(hostName, sizeof(hostName)) == URL::URL_OK)
        {
            (void)HTTPStack.SetHeader(pSelf->m_nRequestID, "Host", (int)std_strlen("Host"),
            hostName, (int)std_strlen(hostName));
        }
        const char* pUserAgent = (pSelf->m_sessionInfo).GetUserAgent();
        if (pUserAgent)
        {
          (void)HTTPStack.SetHeader(pSelf->m_nRequestID, "User-Agent",
          (int)std_strlen("User-Agent"),
                                     pUserAgent, (int)std_strlen(pUserAgent));
        }
        HTTPCommon::AddIPStreamProtocolHeaders(pSelf->m_sessionInfo,HTTPStack,methodType, pSelf->m_nRequestID);
        //Send GET to get the playlist

          HTTPReturnCode result = HTTPStack.SendRequest(pSelf->m_nRequestID, methodType,
          pLaunchURL,
          (int)std_strlen(pLaunchURL));
        if (result == HTTP_SUCCESS)
        {
          //HTTP GET request successfully composed and posted to the HTTP stack.
          //So change state to WAITING_FOR_PLAYLIST and check back later
          status = HTTPCommon::HTTPDL_WAITING;
          pSelf->SetStateHandler(&pSelf->m_WaitingForPlaylistStateHandler);
          QTV_MSG_PRIO( QTVDIAG_HTTP_STREAMING, QTVDIAG_PRIO_HIGH,
            "HTTP GET request to get playlist successfully composed and posted "
            "to HTTP stack - proceeding to WAITING_FOR_PLAYLIST" );
        }
        else
        {
          QTV_MSG_PRIO1( QTVDIAG_HTTP_STREAMING, QTVDIAG_PRIO_ERROR,
            "Error: HTTP GET request send failed %d",
            result );
          status = HTTPCommon::HTTPDL_ERROR_ABORT;
        }
      }
      else
      {
        QTV_MSG_PRIO( QTVDIAG_HTTP_STREAMING, QTVDIAG_PRIO_ERROR,
                      "Error Creating Request");
      }
    }
    else
    {
      QTV_MSG_PRIO( QTVDIAG_HTTP_STREAMING, QTVDIAG_PRIO_ERROR,
        "Error: ParseURL failed" );
    }// if (pSelf->ParseURL(HTTP_DEFAULT_PORT, pLaunchURL) && pLaunchURL)
  }// if (pSelf && pSelf->GetState() == IDLE)

  return status;
}
/** @brief Parses the input URL and fills in the default port if port already
  * not present.
  *
  * @param[in] pDefaultPort - Default HTTP port to use if port not present in URL
  * @param[out] pLaunchURL - Launch URL used to connect to server
  * @return
  * TRUE - Launch URL ready
  * FALSE - Otherwise
  */
bool PlaylistDownloadHelper::ParseURL
(
 const char* pDefaultPort,
 char*& pLaunchURL
 )
{
  bool bOk = false;

  URL url(GetURL());
  size_t launchURLLen = url.GetUrlLength() + 1;
  uint32 port = 0;

  if (pLaunchURL)
  {
    QTV_Free(pLaunchURL);
    pLaunchURL = NULL;
  }

  if (url.GetPort(&port) == URL::URL_OK)
  {
    if (port)
    {
      pLaunchURL = (char*)QTV_Malloc(launchURLLen);
      if (pLaunchURL && url.GetUrlBuffer())
      {
        bOk = true;
        (void)std_strlcpy(pLaunchURL, url.GetUrlBuffer(), launchURLLen);
      }
    }
    else if (pDefaultPort)
    {
      char hostName[HTTP_MAX_HOSTNAME_LEN] = {0};

      //Extra space for ":9300"
      launchURLLen += std_strlen(pDefaultPort) + 1;
      pLaunchURL = (char*)QTV_Malloc(launchURLLen);
      if (pLaunchURL &&
        url.GetHost(hostName, sizeof(hostName)) == URL::URL_OK)
      {
        //Write http://
        size_t arg2 = std_strlen("http://") + 1;
        size_t dstBufLen = STD_MIN(launchURLLen, arg2);
        size_t numURLBytes = std_strlcpy(pLaunchURL,
          "http://", dstBufLen);

        //Write hostname
        arg2 = std_strlen(hostName) + 1;
        dstBufLen = STD_MIN(launchURLLen - numURLBytes, arg2);
        numURLBytes += std_strlcpy(pLaunchURL + numURLBytes,
          hostName, dstBufLen);

        //Write :
        arg2 = std_strlen(":") + 1;
        dstBufLen = STD_MIN(launchURLLen - numURLBytes, arg2);
        numURLBytes += std_strlcpy(pLaunchURL + numURLBytes,
          ":", dstBufLen);

        //Write default port
        arg2 = std_strlen(pDefaultPort) + 1;
        dstBufLen = STD_MIN(launchURLLen - numURLBytes, arg2);
        numURLBytes += std_strlcpy(pLaunchURL + numURLBytes,
          pDefaultPort, dstBufLen);

        //Write /
        arg2 = std_strlen("/") + 1;
        dstBufLen = STD_MIN(launchURLLen - numURLBytes, arg2);
        numURLBytes += std_strlcpy(pLaunchURL + numURLBytes,
          "/", dstBufLen);

        //Write clipname
        dstBufLen = launchURLLen - numURLBytes;
        char* pClipName = NULL;
        pClipName = (char*)QTV_Malloc(dstBufLen);
        if (pClipName)
        {
          if (url.GetClipName(pClipName, dstBufLen) == URL::URL_OK)
          {
            bOk = true;
            (void)std_strlcpy(pLaunchURL + numURLBytes,
              pClipName, dstBufLen);
          }
          QTV_Free(pClipName);
        }
      }
    }
    else
    {
      QTV_MSG_PRIO( QTVDIAG_HTTP_STREAMING, QTVDIAG_PRIO_ERROR,
        "Error: Invalid port" );
    }
  }
  if(!bOk)
  {
    if(pLaunchURL)
    {
      QTV_Free(pLaunchURL);
    }
  }
  return bOk;
}
예제 #9
0
파일: settings.c 프로젝트: eerimoq/simba
static int cmd_list_cb(int argc,
                       const char *argv[],
                       void *chout_p,
                       void *chin_p,
                       void *arg_p,
                       void *call_arg_p)
{
    const FAR struct setting_t *setting_p;
    int i;
    int8_t int8;
    int16_t int16;
    int32_t int32;
    char buf[32];
    size_t size;

    /* Print the header. */
    std_fprintf(chout_p,
                FSTR("NAME                  TYPE     SIZE  VALUE\r\n"));

    /* Print all settings. */
    setting_p = &settings[0];

    while (setting_p->name_p != NULL) {
        /* Print the name. */
        if (std_strlen(setting_p->name_p) >= sizeof(buf)) {
            continue;
        }

        std_strcpy(buf, setting_p->name_p);
        std_fprintf(chout_p, FSTR("%-20s  "), buf);
        size = setting_p->size;

        switch (setting_p->type) {

        case setting_type_int8_t:
            int8 = 0;
            settings_read(&int8, setting_p->address, size);
            std_fprintf(chout_p,
                        FSTR("int8_t      1  %d\r\n"),
                        (int)int8);
            break;

        case setting_type_int16_t:
            int16 = 0;
            settings_read(&int16, setting_p->address, size);
            std_fprintf(chout_p,
                        FSTR("int16_t     2  %d\r\n"),
                        (int)int16);
            break;

        case setting_type_int32_t:
            int32 = 0;
            settings_read(&int32, setting_p->address, size);
            std_fprintf(chout_p,
                        FSTR("int32_t     4  %ld\r\n"),
                        (long)int32);
            break;

        case setting_type_string_t:
            std_fprintf(chout_p, FSTR("string   %4u  "), (int)size);

            for (i = 0; i < size; i++) {
                settings_read(&buf[0], setting_p->address + i, 1);

                if (buf[0] == '\0') {
                    break;
                }

                std_fprintf(chout_p, FSTR("%c"), buf[0]);
            }

            std_fprintf(chout_p, FSTR("\r\n"));
            break;

        default:
            std_fprintf(chout_p,
                        FSTR("bad setting type %d\r\n"),
                        setting_p->type);
        }

        setting_p++;
    }

    return (0);
}