librnr/uri.c
char *UriStrNew(const Uri_T *pUri)
{
  char   *sUri;   // uri string
  Uri_T   uri = {"", "", "", 0, "", ""};
  Uri_T   sep = {"", "", "", 0, "", ""};
  char    bufPort[URI_SEP_PORT_LEN+URI_PORT_MAX_LEN+1] = {0, };
  size_t  n = 0;

  if( pUri == NULL )
  {
    return NULL;
  }

  if( pUri->m_sScheme != NULL )
  {
    n += strlen(pUri->m_sScheme) + (size_t)URI_SEP_SCHEME_LEN;
    uri.m_sScheme = pUri->m_sScheme;
    sep.m_sScheme = URI_SEP_SCHEME;
  }

  if( pUri->m_sUserInfo != NULL )
  {
    n += strlen(pUri->m_sUserInfo) + (size_t)URI_SEP_USER_INFO_LEN;
    uri.m_sUserInfo = pUri->m_sUserInfo;
    sep.m_sUserInfo = URI_SEP_USER_INFO;
  }

  if( pUri->m_sHostName != NULL )
  {
    n += strlen(pUri->m_sHostName);
    uri.m_sHostName = pUri->m_sHostName;

    if( pUri->m_nPortNum != URI_PORT_NONE )
    {
      n += (size_t)URI_SEP_PORT_LEN + (size_t)URI_PORT_MAX_LEN;
      snprintf(bufPort, sizeof(bufPort), "%s%d",
          URI_SEP_PORT, pUri->m_nPortNum);
      bufPort[sizeof(bufPort)-1] = 0;
    }
  }

  if( pUri->m_sPath != NULL )
  {
    n += strlen(pUri->m_sPath);
    uri.m_sPath = pUri->m_sPath;
    if( strncmp(uri.m_sPath, URI_SEP_PATH, URI_SEP_PATH_LEN) )
    {
      n++;
      sep.m_sPath = URI_SEP_PATH;
    }
  }

  if( pUri->m_sQuery != NULL )
  {
    n += URI_SEP_QUERY_LEN + strlen(pUri->m_sQuery);
    uri.m_sQuery = pUri->m_sQuery;
    sep.m_sQuery = URI_SEP_QUERY;
  }

  sUri = NEWSTR(n);

  sprintf(sUri, "%s%s%s%s%s%s%s%s%s%s",
      uri.m_sScheme, sep.m_sScheme,
      uri.m_sUserInfo, sep.m_sUserInfo,
      uri.m_sHostName, bufPort,
      sep.m_sPath, uri.m_sPath,
      sep.m_sQuery, uri.m_sQuery);

  return sUri;
}
/*!
 * \brief Construct a new URI string from the given URI components.
 *
 * \param pUri  Pointer to URI structure.
 *
 * \return Allocated string.
 */
\brief Construct a new URI string from the given URI components.
\param pUri  Pointer to URI structure.

\return Allocated string.
\ brief Construct a new URI string from the given URI components . \ param pUri Pointer to URI structure . \ return Allocated string .
char *UriStrNew(const Uri_T *pUri)
{
  char   *sUri;   
  Uri_T   uri = {"", "", "", 0, "", ""};
  Uri_T   sep = {"", "", "", 0, "", ""};
  char    bufPort[URI_SEP_PORT_LEN+URI_PORT_MAX_LEN+1] = {0, };
  size_t  n = 0;
  if( pUri == NULL )
  {
    return NULL;
  }
  if( pUri->m_sScheme != NULL )
  {
    n += strlen(pUri->m_sScheme) + (size_t)URI_SEP_SCHEME_LEN;
    uri.m_sScheme = pUri->m_sScheme;
    sep.m_sScheme = URI_SEP_SCHEME;
  }
  if( pUri->m_sUserInfo != NULL )
  {
    n += strlen(pUri->m_sUserInfo) + (size_t)URI_SEP_USER_INFO_LEN;
    uri.m_sUserInfo = pUri->m_sUserInfo;
    sep.m_sUserInfo = URI_SEP_USER_INFO;
  }
  if( pUri->m_sHostName != NULL )
  {
    n += strlen(pUri->m_sHostName);
    uri.m_sHostName = pUri->m_sHostName;
    if( pUri->m_nPortNum != URI_PORT_NONE )
    {
      n += (size_t)URI_SEP_PORT_LEN + (size_t)URI_PORT_MAX_LEN;
      snprintf(bufPort, sizeof(bufPort), "%s%d",
          URI_SEP_PORT, pUri->m_nPortNum);
      bufPort[sizeof(bufPort)-1] = 0;
    }
  }
  if( pUri->m_sPath != NULL )
  {
    n += strlen(pUri->m_sPath);
    uri.m_sPath = pUri->m_sPath;
    if( strncmp(uri.m_sPath, URI_SEP_PATH, URI_SEP_PATH_LEN) )
    {
      n++;
      sep.m_sPath = URI_SEP_PATH;
    }
  }
  if( pUri->m_sQuery != NULL )
  {
    n += URI_SEP_QUERY_LEN + strlen(pUri->m_sQuery);
    uri.m_sQuery = pUri->m_sQuery;
    sep.m_sQuery = URI_SEP_QUERY;
  }
  sUri = NEWSTR(n);
  sprintf(sUri, "%s%s%s%s%s%s%s%s%s%s",
      uri.m_sScheme, sep.m_sScheme,
      uri.m_sUserInfo, sep.m_sUserInfo,
      uri.m_sHostName, bufPort,
      sep.m_sPath, uri.m_sPath,
      sep.m_sQuery, uri.m_sQuery);
  return sUri;
}
char * UriStrNew ( const Uri_T * pUri ) { char * sUri ; Uri_T uri = { " " , " " , " " , 0 , " " , " " } ; Uri_T sep = { " " , " " , " " , 0 , " " , " " } ; char bufPort [ URI_SEP_PORT_LEN + URI_PORT_MAX_LEN + 1 ] = { 0 , } ; size_t n = 0 ; if ( pUri == NULL ) { return NULL ; } if ( pUri -> m_sScheme != NULL ) { n += strlen ( pUri -> m_sScheme ) + ( size_t ) URI_SEP_SCHEME_LEN ; uri . m_sScheme = pUri -> m_sScheme ; sep . m_sScheme = URI_SEP_SCHEME ; } if ( pUri -> m_sUserInfo != NULL ) { n += strlen ( pUri -> m_sUserInfo ) + ( size_t ) URI_SEP_USER_INFO_LEN ; uri . m_sUserInfo = pUri -> m_sUserInfo ; sep . m_sUserInfo = URI_SEP_USER_INFO ; } if ( pUri -> m_sHostName != NULL ) { n += strlen ( pUri -> m_sHostName ) ; uri . m_sHostName = pUri -> m_sHostName ; if ( pUri -> m_nPortNum != URI_PORT_NONE ) { n += ( size_t ) URI_SEP_PORT_LEN + ( size_t ) URI_PORT_MAX_LEN ; snprintf ( bufPort , sizeof ( bufPort ) , " " , URI_SEP_PORT , pUri -> m_nPortNum ) ; bufPort [ sizeof ( bufPort ) - 1 ] = 0 ; } } if ( pUri -> m_sPath != NULL ) { n += strlen ( pUri -> m_sPath ) ; uri . m_sPath = pUri -> m_sPath ; if ( strncmp ( uri . m_sPath , URI_SEP_PATH , URI_SEP_PATH_LEN ) ) { n ++ ; sep . m_sPath = URI_SEP_PATH ; } } if ( pUri -> m_sQuery != NULL ) { n += URI_SEP_QUERY_LEN + strlen ( pUri -> m_sQuery ) ; uri . m_sQuery = pUri -> m_sQuery ; sep . m_sQuery = URI_SEP_QUERY ; } sUri = NEWSTR ( n ) ; sprintf ( sUri , " " , uri . m_sScheme , sep . m_sScheme , uri . m_sUserInfo , sep . m_sUserInfo , uri . m_sHostName , bufPort , sep . m_sPath , uri . m_sPath , sep . m_sQuery , uri . m_sQuery ) ; return sUri ; }
\brief Construct a new URI string from the given URI components.
\ brief Construct a new URI string from the given URI components .
// uri string