Example #1
0
/*----------------------------------------------------------------------
|   NPT_Url::SetPath
+---------------------------------------------------------------------*/
NPT_Result 
NPT_Url::SetPath(const char* path, bool encoded)
{
    if (encoded) {
        m_Path = path;
    } else {
        m_Path = PercentEncode(path, PathCharsToEncode);    
    }
    
    return NPT_SUCCESS;
}
Example #2
0
/*----------------------------------------------------------------------
|   NPT_Url::SetFragment
+---------------------------------------------------------------------*/
NPT_Result 
NPT_Url::SetFragment(const char* fragment, bool encoded)
{
    if (encoded) {
        m_Fragment = fragment;
    } else {
        m_Fragment = PercentEncode(fragment, FragmentCharsToEncode);
    }
    m_HasFragment = fragment!=NULL;

    return NPT_SUCCESS;
}
Example #3
0
/*----------------------------------------------------------------------
|   NPT_Url::SetQuery
+---------------------------------------------------------------------*/
NPT_Result 
NPT_Url::SetQuery(const char* query, bool encoded)
{
    if (encoded) {
        m_Query = query;
    } else {
        m_Query = PercentEncode(query, QueryCharsToEncode);
    }
    m_HasQuery = query!=NULL && NPT_StringLength(query)>0;

    return NPT_SUCCESS;
}
std::string URLEncode(const std::string& decoded) {
    return PercentEncode(decoded);
}
/*++
* @method: Client::getSignature
*
* @description: this method calculates HMAC-SHA1 signature of OAuth header
*
* @input: eType - HTTP request type
*         rawUrl - raw url of the HTTP request
*         rawKeyValuePairs - key-value pairs containing OAuth headers and HTTP data
*
* @output: oAuthSignature - base64 and url encoded signature
*
* @remarks: internal method
*
*--*/
bool Client::getSignature( const Http::RequestType eType,
                           const std::string& rawUrl,
                           const KeyValuePairs& rawKeyValuePairs,
                           std::string& oAuthSignature )
{
    std::string rawParams;
    std::string paramsSeperator;
    std::string sigBase;

    /* Initially empty signature */
    oAuthSignature.assign( "" );

    /* Build a string using key-value pairs */
    paramsSeperator = "&";
    getStringFromOAuthKeyValuePairs( rawKeyValuePairs, rawParams, paramsSeperator );

    /* Start constructing base signature string. Refer http://dev.twitter.com/auth#intro */
    switch( eType )
    {
    case Http::Head:
    {
        sigBase.assign( "HEAD&" );
    }
    break;

    case Http::Get:
    {
        sigBase.assign( "GET&" );
    }
    break;

    case Http::Post:
    {
        sigBase.assign( "POST&" );
    }
    break;

    case Http::Delete:
    {
        sigBase.assign( "DELETE&" );
    }
    break;

    case Http::Put:
    {
        sigBase.assign( "PUT&" );
    }
    break;

    default:
    {
        return false;
    }
    break;
    }
    sigBase.append( PercentEncode( rawUrl ) );
    sigBase.append( "&" );
    sigBase.append( PercentEncode( rawParams ) );

    /* Now, hash the signature base string using HMAC_SHA1 class */
    CHMAC_SHA1 objHMACSHA1;
    std::string secretSigningKey;
    unsigned char strDigest[Defaults::BUFFSIZE_LARGE];

    memset( strDigest, 0, Defaults::BUFFSIZE_LARGE );

    /* Signing key is composed of consumer_secret&token_secret */
    secretSigningKey.assign( PercentEncode(mConsumer->secret()) );
    secretSigningKey.append( "&" );
    if( mToken && mToken->secret().length() )
    {
        secretSigningKey.append( PercentEncode(mToken->secret()) );
    }

    objHMACSHA1.HMAC_SHA1( (unsigned char*)sigBase.c_str(),
                           sigBase.length(),
                           (unsigned char*)secretSigningKey.c_str(),
                           secretSigningKey.length(),
                           strDigest );

    /* Do a base64 encode of signature */
    std::string base64Str = base64_encode( strDigest, 20 /* SHA 1 digest is 160 bits */ );

    /* Do an url encode */
    oAuthSignature = PercentEncode( base64Str );

    return ( oAuthSignature.length() ) ? true : false;
}