Changeset - 40fb5c2d3f4b
[Not reviewed]
backends/twitter/libtwitcurl/base64.cpp
Show inline comments
 
@@ -99,25 +99,25 @@ std::string base64_decode(std::string const& encoded_string) {
 
      char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
 
      char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
 
 
      for (i = 0; (i < 3); i++)
 
        ret += char_array_3[i];
 
      i = 0;
 
    }
 
  }
 
 
  if (i) {
 
    for (j = i; j <4; j++)
 
      char_array_4[j] = 0;
 
 
    for (j = 0; j <4; j++)
 
      char_array_4[j] = base64_chars.find(char_array_4[j]);
 
 
    char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4);
 
    char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2);
 
    char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3];
 
 
    for (j = 0; (j < i - 1); j++) ret += char_array_3[j];
 
  }
 
 
  return ret;
 
}
 
}
 
\ No newline at end of file
backends/twitter/libtwitcurl/base64.h
Show inline comments
 
#include <string>
 
 
std::string base64_encode(unsigned char const* , unsigned int len);
 
std::string base64_decode(std::string const& s);
 
std::string base64_decode(std::string const& s);
 
\ No newline at end of file
backends/twitter/libtwitcurl/oauthlib.cpp
Show inline comments
 
#include "twitcurlurls.h"
 
#include "oauthlib.h"
 
#include "HMAC_SHA1.h"
 
#include "base64.h"
 
#include "urlencode.h"
 
 
/*++
 
* @method: oAuth::oAuth
 
*
 
* @description: constructor
 
*
 
* @input: none
 
*
 
* @output: none
 
*
 
*--*/
 
oAuth::oAuth()
 
{
 
}
 
 
/*++
 
* @method: oAuth::~oAuth
 
*
 
* @description: destructor
 
*
 
* @input: none
 
*
 
* @output: none
 
*
 
*--*/
 
oAuth::~oAuth()
 
{
 
}
 
 
/*++
 
* @method: oAuth::clone
 
*
 
* @description: creates a clone of oAuth object
 
*
 
* @input: none
 
*
 
* @output: cloned oAuth object
 
*
 
*--*/
 
oAuth oAuth::clone()
 
{
 
	oAuth cloneObj;
 
	cloneObj.m_consumerKey = m_consumerKey;
 
	cloneObj.m_consumerSecret = m_consumerSecret;
 
	cloneObj.m_oAuthTokenKey = m_oAuthTokenKey;
 
	cloneObj.m_oAuthTokenSecret = m_oAuthTokenSecret;
 
	cloneObj.m_oAuthPin = m_oAuthPin;
 
	cloneObj.m_nonce = m_nonce;
 
	cloneObj.m_timeStamp = m_timeStamp;
 
	cloneObj.m_oAuthScreenName =  m_oAuthScreenName;
 
	return cloneObj;
 
    oAuth cloneObj;
 
    cloneObj.m_consumerKey = m_consumerKey;
 
    cloneObj.m_consumerSecret = m_consumerSecret;
 
    cloneObj.m_oAuthTokenKey = m_oAuthTokenKey;
 
    cloneObj.m_oAuthTokenSecret = m_oAuthTokenSecret;
 
    cloneObj.m_oAuthPin = m_oAuthPin;
 
    cloneObj.m_nonce = m_nonce;
 
    cloneObj.m_timeStamp = m_timeStamp;
 
    cloneObj.m_oAuthScreenName =  m_oAuthScreenName;
 
    return cloneObj;
 
}
 
 
 
/*++
 
* @method: oAuth::getConsumerKey
 
*
 
* @description: this method gives consumer key that is being used currently
 
*
 
* @input: none
 
*
 
* @output: consumer key
 
*
 
*--*/
 
void oAuth::getConsumerKey( std::string& consumerKey )
 
{
 
    consumerKey = m_consumerKey;
 
}
 
 
/*++
 
* @method: oAuth::setConsumerKey
 
*
 
* @description: this method saves consumer key that should be used
 
*
 
* @input: consumer key
 
@@ -233,120 +234,122 @@ void oAuth::getOAuthPin( std::string& oAuthPin )
 
*--*/
 
void oAuth::setOAuthPin( const std::string& oAuthPin )
 
{
 
    m_oAuthPin = oAuthPin;
 
}
 
 
/*++
 
* @method: oAuth::generateNonceTimeStamp
 
*
 
* @description: this method generates nonce and timestamp for OAuth header
 
*
 
* @input: none
 
*
 
* @output: none
 
*
 
* @remarks: internal method
 
*
 
*--*/
 
void oAuth::generateNonceTimeStamp()
 
{
 
    char szTime[oAuthLibDefaults::OAUTHLIB_BUFFSIZE];
 
    char szRand[oAuthLibDefaults::OAUTHLIB_BUFFSIZE];
 
    memset( szTime, 0, oAuthLibDefaults::OAUTHLIB_BUFFSIZE );
 
    memset( szRand, 0, oAuthLibDefaults::OAUTHLIB_BUFFSIZE );
 
    srand( time( NULL ) );
 
    srand( (unsigned int)time( NULL ) );
 
    sprintf( szRand, "%x", rand()%1000 );
 
    sprintf( szTime, "%ld", time( NULL ) );
 
 
    m_nonce.assign( szTime );
 
    m_nonce.append( szRand );
 
    m_timeStamp.assign( szTime );
 
}
 
 
/*++
 
* @method: oAuth::buildOAuthRawDataKeyValPairs
 
*
 
* @description: this method prepares key-value pairs from the data part of the URL
 
*               or from the URL post fields data, as required by OAuth header
 
*               and signature generation.
 
*
 
* @input: rawData - Raw data either from the URL itself or from post fields.
 
*                   Should already be url encoded.
 
*         urlencodeData - If true, string will be urlencoded before converting
 
*                         to key value pairs.
 
*
 
* @output: rawDataKeyValuePairs - Map in which key-value pairs are populated
 
*
 
* @remarks: internal method
 
*
 
*--*/
 
void oAuth::buildOAuthRawDataKeyValPairs( const std::string& rawData,
 
                                          bool urlencodeData,
 
                                          oAuthKeyValuePairs& rawDataKeyValuePairs )
 
{
 
    /* Raw data if it's present. Data should already be urlencoded once */
 
    if( rawData.length() )
 
    if( rawData.empty() )
 
    {
 
        size_t nSep = std::string::npos;
 
        size_t nPos = std::string::npos;
 
        std::string dataKeyVal;
 
        std::string dataKey;
 
        std::string dataVal;
 
 
        /* This raw data part can contain many key value pairs: key1=value1&key2=value2&key3=value3 */
 
        std::string dataPart = rawData;
 
        while( std::string::npos != ( nSep = dataPart.find_first_of("&") ) )
 
        {
 
            /* Extract first key=value pair */
 
            dataKeyVal = dataPart.substr( 0, nSep );
 
 
            /* Split them */
 
            nPos = dataKeyVal.find_first_of( "=" );
 
            if( std::string::npos != nPos )
 
            {
 
                dataKey = dataKeyVal.substr( 0, nPos );
 
                dataVal = dataKeyVal.substr( nPos + 1 );
 
 
                /* Put this key=value pair in map */
 
                rawDataKeyValuePairs[dataKey] = urlencodeData ? urlencode( dataVal ) : dataVal;
 
            }
 
            dataPart = dataPart.substr( nSep + 1 );
 
        }
 
        return;
 
    }
 
 
        /* For the last key=value */
 
    size_t nSep = std::string::npos;
 
    size_t nPos = std::string::npos;
 
    std::string dataKeyVal;
 
    std::string dataKey;
 
    std::string dataVal;
 
 
    /* This raw data part can contain many key value pairs: key1=value1&key2=value2&key3=value3 */
 
    std::string dataPart = rawData;
 
    while( std::string::npos != ( nSep = dataPart.find_first_of("&") ) )
 
    {
 
        /* Extract first key=value pair */
 
        dataKeyVal = dataPart.substr( 0, nSep );
 
 
        /* Split them */
 
        nPos = dataKeyVal.find_first_of( "=" );
 
        if( std::string::npos != nPos )
 
        {
 
            dataKey = dataKeyVal.substr( 0, nPos );
 
            dataVal = dataKeyVal.substr( nPos + 1 );
 
 
            /* Put this key=value pair in map */
 
            rawDataKeyValuePairs[dataKey] = urlencodeData ? urlencode( dataVal ) : dataVal;
 
        }
 
        dataPart = dataPart.substr( nSep + 1 );
 
    }
 
 
    /* For the last key=value */
 
    dataKeyVal = dataPart.substr( 0, nSep );
 
 
    /* Split them */
 
    nPos = dataKeyVal.find_first_of( "=" );
 
    if( std::string::npos != nPos )
 
    {
 
        dataKey = dataKeyVal.substr( 0, nPos );
 
        dataVal = dataKeyVal.substr( nPos + 1 );
 
 
        /* Put this key=value pair in map */
 
        rawDataKeyValuePairs[dataKey] = urlencodeData ? urlencode( dataVal ) : dataVal;
 
    }
 
}
 
 
/*++
 
* @method: oAuth::buildOAuthTokenKeyValuePairs
 
*
 
* @description: this method prepares key-value pairs required for OAuth header
 
*               and signature generation.
 
*
 
* @input: includeOAuthVerifierPin - flag to indicate whether oauth_verifer key-value
 
*                                   pair needs to be included. oauth_verifer is only
 
*                                   used during exchanging request token with access token.
 
*         oauthSignature - base64 and url encoded OAuth signature.
 
*         generateTimestamp - If true, then generate new timestamp for nonce.
 
*
 
* @output: keyValueMap - map in which key-value pairs are populated
 
*
 
* @remarks: internal method
 
*
 
*--*/
 
bool oAuth::buildOAuthTokenKeyValuePairs( const bool includeOAuthVerifierPin,
 
                                          const std::string& oauthSignature,
 
                                          oAuthKeyValuePairs& keyValueMap,
 
                                          const bool generateTimestamp )
 
@@ -369,76 +372,76 @@ bool oAuth::buildOAuthTokenKeyValuePairs( const bool includeOAuthVerifierPin,
 
        keyValueMap[oAuthLibDefaults::OAUTHLIB_SIGNATURE_KEY] = oauthSignature;
 
    }
 
 
    /* Signature method, only HMAC-SHA1 as of now */
 
    keyValueMap[oAuthLibDefaults::OAUTHLIB_SIGNATUREMETHOD_KEY] = std::string( "HMAC-SHA1" );
 
 
    /* Timestamp */
 
    keyValueMap[oAuthLibDefaults::OAUTHLIB_TIMESTAMP_KEY] = m_timeStamp;
 
 
    /* Token */
 
    if( m_oAuthTokenKey.length() )
 
    {
 
        keyValueMap[oAuthLibDefaults::OAUTHLIB_TOKEN_KEY] = m_oAuthTokenKey;
 
    }
 
 
    /* Verifier */
 
    if( includeOAuthVerifierPin && m_oAuthPin.length() )
 
    {
 
        keyValueMap[oAuthLibDefaults::OAUTHLIB_VERIFIER_KEY] = m_oAuthPin;
 
    }
 
 
    /* Version */
 
    keyValueMap[oAuthLibDefaults::OAUTHLIB_VERSION_KEY] = std::string( "1.0" );
 
 
    return ( keyValueMap.size() ) ? true : false;
 
    return !keyValueMap.empty();
 
}
 
 
/*++
 
* @method: oAuth::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 oAuth::getSignature( const eOAuthHttpRequestType eType,
 
                          const std::string& rawUrl,
 
                          const oAuthKeyValuePairs& rawKeyValuePairs,
 
                          std::string& oAuthSignature )
 
{
 
    std::string rawParams;
 
    std::string paramsSeperator;
 
    std::string sigBase;
 
 
    /* Initially empty signature */
 
    oAuthSignature.assign( "" );
 
    oAuthSignature = "";
 
 
    /* 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 eOAuthHttpGet:
 
        {
 
            sigBase.assign( "GET&" );
 
        }
 
        break;
 
 
    case eOAuthHttpPost:
 
        {
 
            sigBase.assign( "POST&" );
 
        }
 
        break;
 
 
    case eOAuthHttpDelete:
 
        {
 
            sigBase.assign( "DELETE&" );
 
        }
 
@@ -460,213 +463,219 @@ bool oAuth::getSignature( const eOAuthHttpRequestType eType,
 
    unsigned char strDigest[oAuthLibDefaults::OAUTHLIB_BUFFSIZE_LARGE];
 
 
    memset( strDigest, 0, oAuthLibDefaults::OAUTHLIB_BUFFSIZE_LARGE );
 
 
    /* Signing key is composed of consumer_secret&token_secret */
 
    secretSigningKey.assign( m_consumerSecret );
 
    secretSigningKey.append( "&" );
 
    if( m_oAuthTokenSecret.length() )
 
    {
 
        secretSigningKey.append( m_oAuthTokenSecret );
 
    }
 
  
 
    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 = urlencode( base64Str );
 
 
    return ( oAuthSignature.length() ) ? true : false;
 
    return !oAuthSignature.empty();
 
}
 
 
/*++
 
* @method: oAuth::getOAuthHeader
 
*
 
* @description: this method builds OAuth header that should be used in HTTP requests to twitter
 
*
 
* @input: eType - HTTP request type
 
*         rawUrl - raw url of the HTTP request
 
*         rawData - HTTP data (post fields)
 
*         includeOAuthVerifierPin - flag to indicate whether or not oauth_verifier needs to included
 
*                                   in OAuth header
 
*
 
* @output: oAuthHttpHeader - OAuth header
 
*
 
*--*/
 
bool oAuth::getOAuthHeader( const eOAuthHttpRequestType eType,
 
                            const std::string& rawUrl,
 
                            const std::string& rawData,
 
                            std::string& oAuthHttpHeader,
 
                            const bool includeOAuthVerifierPin )
 
{
 
    oAuthKeyValuePairs rawKeyValuePairs;
 
    std::string rawParams;
 
    std::string oauthSignature;
 
    std::string paramsSeperator;
 
    std::string pureUrl( rawUrl );
 
 
    /* Clear header string initially */
 
    oAuthHttpHeader.assign( "" );
 
    oAuthHttpHeader = "";
 
    rawKeyValuePairs.clear();
 
 
    /* If URL itself contains ?key=value, then extract and put them in map */
 
    size_t nPos = rawUrl.find_first_of( "?" );
 
    if( std::string::npos != nPos )
 
    {
 
        /* Get only URL */
 
        pureUrl = rawUrl.substr( 0, nPos );
 
 
        /* Get only key=value data part */
 
        std::string dataPart = rawUrl.substr( nPos + 1 );
 
 
        /* Split the data in URL as key=value pairs */
 
        buildOAuthRawDataKeyValPairs( dataPart, true, rawKeyValuePairs );
 
    }
 
 
    /* Split the raw data if it's present, as key=value pairs. Data should already be urlencoded once */
 
    buildOAuthRawDataKeyValPairs( rawData, false, rawKeyValuePairs );
 
 
    /* Build key-value pairs needed for OAuth request token, without signature */
 
    buildOAuthTokenKeyValuePairs( includeOAuthVerifierPin, std::string( "" ), rawKeyValuePairs, true );
 
 
    /* Get url encoded base64 signature using request type, url and parameters */
 
    getSignature( eType, pureUrl, rawKeyValuePairs, oauthSignature );
 
 
    /* Clear map so that the parameters themselves are not sent along with the OAuth values */
 
    rawKeyValuePairs.clear();
 
 
    /* Now, again build key-value pairs with signature this time */
 
    buildOAuthTokenKeyValuePairs( includeOAuthVerifierPin, oauthSignature, rawKeyValuePairs, false );
 
 
    /* Get OAuth header in string format */
 
    paramsSeperator = ",";
 
    getStringFromOAuthKeyValuePairs( rawKeyValuePairs, rawParams, paramsSeperator );
 
 
    /* Build authorization header */
 
    oAuthHttpHeader.assign( oAuthLibDefaults::OAUTHLIB_AUTHHEADER_STRING );
 
    oAuthHttpHeader.append( rawParams );
 
 
    return ( oAuthHttpHeader.length() ) ? true : false;
 
    return !oAuthHttpHeader.empty();
 
}
 
 
/*++
 
* @method: oAuth::getStringFromOAuthKeyValuePairs
 
*
 
* @description: this method builds a sorted string from key-value pairs
 
*
 
* @input: rawParamMap - key-value pairs map
 
*         paramsSeperator - sepearator, either & or ,
 
*
 
* @output: rawParams - sorted string of OAuth parameters
 
*
 
* @remarks: internal method
 
*
 
*--*/
 
bool oAuth::getStringFromOAuthKeyValuePairs( const oAuthKeyValuePairs& rawParamMap,
 
                                             std::string& rawParams,
 
                                             const std::string& paramsSeperator )
 
{
 
    rawParams.assign( "" );
 
    if( rawParamMap.size() )
 
    rawParams = "";
 
    if( rawParamMap.empty() )
 
    {
 
        oAuthKeyValueList keyValueList;
 
        std::string dummyStr;
 
        return false;
 
    }
 
 
    oAuthKeyValueList keyValueList;
 
    std::string dummyStr;
 
 
        /* Push key-value pairs to a list of strings */
 
        keyValueList.clear();
 
        oAuthKeyValuePairs::const_iterator itMap = rawParamMap.begin();
 
        for( ; itMap != rawParamMap.end(); itMap++ )
 
    /* Push key-value pairs to a list of strings */
 
    keyValueList.clear();
 
    oAuthKeyValuePairs::const_iterator itMap = rawParamMap.begin();
 
    for( ; itMap != rawParamMap.end(); itMap++ )
 
    {
 
        dummyStr.assign( itMap->first );
 
        dummyStr.append( "=" );
 
        if( paramsSeperator == "," )
 
        {
 
            dummyStr.append( "\"" );
 
        }
 
        dummyStr.append( itMap->second );
 
        if( paramsSeperator == "," )
 
        {
 
            dummyStr.assign( itMap->first );
 
            dummyStr.append( "=" );
 
            if( paramsSeperator == "," )
 
            {
 
                dummyStr.append( "\"" );
 
            }
 
            dummyStr.append( itMap->second );
 
            if( paramsSeperator == "," )
 
            {
 
                dummyStr.append( "\"" );
 
            }
 
            keyValueList.push_back( dummyStr );
 
            dummyStr.append( "\"" );
 
        }
 
        keyValueList.push_back( dummyStr );
 
    }
 
 
        /* Sort key-value pairs based on key name */
 
        keyValueList.sort();
 
    /* Sort key-value pairs based on key name */
 
    keyValueList.sort();
 
 
        /* Now, form a string */
 
        dummyStr.assign( "" );
 
        oAuthKeyValueList::iterator itKeyValue = keyValueList.begin();
 
        for( ; itKeyValue != keyValueList.end(); itKeyValue++ )
 
    /* Now, form a string */
 
    dummyStr = "";
 
    oAuthKeyValueList::iterator itKeyValue = keyValueList.begin();
 
    for( ; itKeyValue != keyValueList.end(); itKeyValue++ )
 
    {
 
        if( dummyStr.length() )
 
        {
 
            if( dummyStr.length() )
 
            {
 
                dummyStr.append( paramsSeperator );
 
            }
 
            dummyStr.append( itKeyValue->c_str() );
 
        }
 
        rawParams.assign( dummyStr );
 
            dummyStr.append( paramsSeperator );
 
         }
 
         dummyStr.append( itKeyValue->c_str() );
 
    }
 
    return ( rawParams.length() ) ? true : false;
 
    rawParams = dummyStr;
 
    return !rawParams.empty();
 
}
 
 
/*++
 
* @method: oAuth::extractOAuthTokenKeySecret
 
*
 
* @description: this method extracts oauth token key and secret from
 
*               twitter's HTTP response
 
*
 
* @input: requestTokenResponse - response from twitter
 
*
 
* @output: none
 
*
 
*--*/
 
bool oAuth::extractOAuthTokenKeySecret( const std::string& requestTokenResponse )
 
{
 
    if( requestTokenResponse.length() )
 
    if( requestTokenResponse.empty() )
 
    {
 
        size_t nPos = std::string::npos;
 
        std::string strDummy;
 
        return false;
 
    }
 
 
        /* Get oauth_token key */
 
        nPos = requestTokenResponse.find( oAuthLibDefaults::OAUTHLIB_TOKEN_KEY );
 
        if( std::string::npos != nPos )
 
        {
 
            nPos = nPos + oAuthLibDefaults::OAUTHLIB_TOKEN_KEY.length() + strlen( "=" );
 
            strDummy = requestTokenResponse.substr( nPos );
 
            nPos = strDummy.find( "&" );
 
            if( std::string::npos != nPos )
 
            {
 
                m_oAuthTokenKey = strDummy.substr( 0, nPos );
 
            }
 
        }
 
    size_t nPos = std::string::npos;
 
    std::string strDummy;
 
 
        /* Get oauth_token_secret */
 
        nPos = requestTokenResponse.find( oAuthLibDefaults::OAUTHLIB_TOKENSECRET_KEY );
 
    /* Get oauth_token key */
 
    nPos = requestTokenResponse.find( oAuthLibDefaults::OAUTHLIB_TOKEN_KEY );
 
    if( std::string::npos != nPos )
 
    {
 
        nPos = nPos + oAuthLibDefaults::OAUTHLIB_TOKEN_KEY.length() + strlen( "=" );
 
        strDummy = requestTokenResponse.substr( nPos );
 
        nPos = strDummy.find( "&" );
 
        if( std::string::npos != nPos )
 
        {
 
            nPos = nPos + oAuthLibDefaults::OAUTHLIB_TOKENSECRET_KEY.length() + strlen( "=" );
 
            strDummy = requestTokenResponse.substr( nPos );
 
            nPos = strDummy.find( "&" );
 
            if( std::string::npos != nPos )
 
            {
 
                m_oAuthTokenSecret = strDummy.substr( 0, nPos );
 
            }
 
            m_oAuthTokenKey = strDummy.substr( 0, nPos );
 
        }
 
    }
 
 
        /* Get screen_name */
 
        nPos = requestTokenResponse.find( oAuthLibDefaults::OAUTHLIB_SCREENNAME_KEY );
 
    /* Get oauth_token_secret */
 
    nPos = requestTokenResponse.find( oAuthLibDefaults::OAUTHLIB_TOKENSECRET_KEY );
 
    if( std::string::npos != nPos )
 
    {
 
        nPos = nPos + oAuthLibDefaults::OAUTHLIB_TOKENSECRET_KEY.length() + strlen( "=" );
 
        strDummy = requestTokenResponse.substr( nPos );
 
        nPos = strDummy.find( "&" );
 
        if( std::string::npos != nPos )
 
        {
 
            nPos = nPos + oAuthLibDefaults::OAUTHLIB_SCREENNAME_KEY.length() + strlen( "=" );
 
            strDummy = requestTokenResponse.substr( nPos );
 
            m_oAuthScreenName = strDummy;
 
            m_oAuthTokenSecret = strDummy.substr( 0, nPos );
 
        }
 
    }
 
 
    /* Get screen_name */
 
    nPos = requestTokenResponse.find( oAuthLibDefaults::OAUTHLIB_SCREENNAME_KEY );
 
    if( std::string::npos != nPos )
 
    {
 
        nPos = nPos + oAuthLibDefaults::OAUTHLIB_SCREENNAME_KEY.length() + strlen( "=" );
 
        strDummy = requestTokenResponse.substr( nPos );
 
        m_oAuthScreenName = strDummy;
 
    }
 
 
    return true;
 
}
 
backends/twitter/libtwitcurl/oauthlib.h
Show inline comments
 
#ifndef __OAUTHLIB_H__
 
#define __OAUTHLIB_H__
 
 
#include "time.h"
 
#include <cstdlib>
 
#include <sstream>
 
#include <iostream>
 
#include <fstream>
 
#include <string>
 
#include <list>
 
#include <map>
 
 
namespace oAuthLibDefaults
 
{
 
    /* Constants */
 
    const int OAUTHLIB_BUFFSIZE = 1024;
 
    const int OAUTHLIB_BUFFSIZE_LARGE = 1024;
 
    const std::string OAUTHLIB_CONSUMERKEY_KEY = "oauth_consumer_key";
 
    const std::string OAUTHLIB_CALLBACK_KEY = "oauth_callback";
 
    const std::string OAUTHLIB_VERSION_KEY = "oauth_version";
 
    const std::string OAUTHLIB_SIGNATUREMETHOD_KEY = "oauth_signature_method";
 
    const std::string OAUTHLIB_SIGNATURE_KEY = "oauth_signature";
 
    const std::string OAUTHLIB_TIMESTAMP_KEY = "oauth_timestamp";
 
    const std::string OAUTHLIB_NONCE_KEY = "oauth_nonce";
 
    const std::string OAUTHLIB_TOKEN_KEY = "oauth_token";
 
    const std::string OAUTHLIB_TOKENSECRET_KEY = "oauth_token_secret";
 
    const std::string OAUTHLIB_VERIFIER_KEY = "oauth_verifier";
 
    const std::string OAUTHLIB_SCREENNAME_KEY = "screen_name";
 
    const std::string OAUTHLIB_AUTHENTICITY_TOKEN_KEY = "authenticity_token";
 
    const std::string OAUTHLIB_SESSIONUSERNAME_KEY = "session[username_or_email]";
 
    const std::string OAUTHLIB_SESSIONPASSWORD_KEY = "session[password]";
 
    const std::string OAUTHLIB_AUTHENTICITY_TOKEN_TWITTER_RESP_KEY = "authenticity_token\" type=\"hidden\" value=\"";
 
    const std::string OAUTHLIB_TOKEN_TWITTER_RESP_KEY = "oauth_token\" type=\"hidden\" value=\"";
 
    const std::string OAUTHLIB_PIN_TWITTER_RESP_KEY = "code-desc\"><code>";
 
    const std::string OAUTHLIB_TOKEN_END_TAG_TWITTER_RESP = "\" />";
 
    const std::string OAUTHLIB_PIN_END_TAG_TWITTER_RESP = "</code>";
 
 
    const std::string OAUTHLIB_AUTHHEADER_STRING = "Authorization: OAuth ";
 
};
 
 
namespace oAuthTwitterApiUrls
 
{
 
    /* Twitter OAuth API URLs */
 
    const std::string OAUTHLIB_TWITTER_REQUEST_TOKEN_URL = "api.twitter.com/oauth/request_token";
 
    const std::string OAUTHLIB_TWITTER_AUTHORIZE_URL = "api.twitter.com/oauth/authorize?oauth_token=";
 
    const std::string OAUTHLIB_TWITTER_ACCESS_TOKEN_URL = "api.twitter.com/oauth/access_token";
 
};
 
 
typedef enum _eOAuthHttpRequestType
 
{
 
    eOAuthHttpInvalid = 0,
 
    eOAuthHttpGet,
 
    eOAuthHttpPost,
 
    eOAuthHttpDelete
 
} eOAuthHttpRequestType;
 
 
typedef std::list<std::string> oAuthKeyValueList;
 
typedef std::map<std::string, std::string> oAuthKeyValuePairs;
 
 
class oAuth
 
{
 
public:
 
    oAuth();
 
    ~oAuth();
 
 
    /* OAuth public methods used by twitCurl */
 
    void getConsumerKey( std::string& consumerKey /* out */ );
 
    void setConsumerKey( const std::string& consumerKey /* in */ );
 
 
    void getConsumerSecret( std::string& consumerSecret /* out */ );
 
    void setConsumerSecret( const std::string& consumerSecret /* in */ );
 
backends/twitter/libtwitcurl/twitcurl.cpp
Show inline comments
 
#define NOMINMAX
 
#include <memory.h>
 
#include "twitcurlurls.h"
 
#include "twitcurl.h"
 
#include "urlencode.h"
 
 
static int myDebugCallback(CURL *,
 
                    curl_infotype type,
 
                    char *data,
 
                    size_t size,
 
                    void *handle)
 
{
 
	std::cerr << std::string(data, size);
 
  return 0;
 
};
 
 
/*++
 
* @method: twitCurl::twitCurl
 
*
 
* @description: constructor
 
*
 
* @input: none
 
*
 
* @output: none
 
*
 
*--*/
 
twitCurl::twitCurl():
 
m_curlHandle( NULL ),
 
m_curlProxyParamsSet( false ),
 
m_curlLoginParamsSet( false ),
 
m_curlCallbackParamsSet( false ),
 
m_eApiFormatType( twitCurlTypes::eTwitCurlApiFormatXml ),
 
m_eApiFormatType( twitCurlTypes::eTwitCurlApiFormatJson ),
 
m_eProtocolType( twitCurlTypes::eTwitCurlProtocolHttps )
 
{
 
    /* Alloc memory for cURL error responses */
 
    m_errorBuffer = (char*)malloc( twitCurlDefaults::TWITCURL_DEFAULT_BUFFSIZE );
 
 
    /* Clear callback buffers */
 
    clearCurlCallbackBuffers();
 
 
    /* Initialize cURL */
 
    m_curlHandle = curl_easy_init();
 
    if( NULL == m_curlHandle )
 
    {
 
        std::string dummyStr;
 
        getLastCurlError( dummyStr );
 
    }
 
    curl_easy_setopt(m_curlHandle, CURLOPT_VERBOSE, 1);
 
    curl_easy_setopt(m_curlHandle, CURLOPT_FOLLOWLOCATION, 1);
 
	curl_easy_setopt(m_curlHandle, CURLOPT_DEBUGFUNCTION, myDebugCallback);
 
    curl_easy_setopt(m_curlHandle, CURLOPT_SSL_VERIFYPEER, 0);
 
}
 
 
/*++
 
* @method: twitCurl::~twitCurl
 
*
 
* @description: destructor
 
*
 
* @input: none
 
*
 
* @output: none
 
*
 
*--*/
 
twitCurl::~twitCurl()
 
{
 
    /* Cleanup cURL */
 
    if( m_curlHandle )
 
    {
 
        curl_easy_cleanup( m_curlHandle );
 
        m_curlHandle = NULL;
 
    }
 
    if( m_errorBuffer )
 
    {
 
        free( m_errorBuffer );
 
        m_errorBuffer = NULL;
 
    }
 
}
 
 
/*++
 
* @method: twitCurl::clone
 
*
 
* @description: creates a clone of twitcurl object
 
*
 
* @input: none
 
*
 
* @output: cloned object
 
*
 
*--*/
 
twitCurl* twitCurl::clone()
 
{
 
	twitCurl *cloneObj = new twitCurl();
 
 
	/* cURL proxy data */
 
	cloneObj->setProxyServerIp(m_proxyServerIp);
 
	cloneObj->setProxyServerPort(m_proxyServerPort);
 
	cloneObj->setProxyUserName(m_proxyUserName);
 
	cloneObj->setProxyPassword(m_proxyPassword);
 
    twitCurl *cloneObj = new twitCurl();
 
 
	/* Twitter data */
 
	cloneObj->setTwitterUsername(m_twitterUsername);
 
	cloneObj->setTwitterPassword(m_twitterPassword);
 
    /* cURL proxy data */
 
    cloneObj->setProxyServerIp(m_proxyServerIp);
 
    cloneObj->setProxyServerPort(m_proxyServerPort);
 
    cloneObj->setProxyUserName(m_proxyUserName);
 
    cloneObj->setProxyPassword(m_proxyPassword);
 
 
	/* Twitter API type */
 
	cloneObj->setTwitterApiType(m_eApiFormatType);
 
    /* Twitter data */
 
    cloneObj->setTwitterUsername(m_twitterUsername);
 
    cloneObj->setTwitterPassword(m_twitterPassword);
 
 
	/* OAuth data */
 
	cloneObj->m_oAuth = m_oAuth.clone();
 
    /* OAuth data */
 
    cloneObj->m_oAuth = m_oAuth.clone();
 
 
	return cloneObj;
 
}
 
 
/*++
 
* @method: twitCurl::setTwitterApiType
 
*
 
* @description: method to set API type
 
*
 
* @input: none
 
*
 
* @output: none
 
*
 
*--*/
 
void twitCurl::setTwitterApiType( twitCurlTypes::eTwitCurlApiFormatType eType )
 
{
 
    m_eApiFormatType = ( eType < twitCurlTypes::eTwitCurlApiFormatMax ) ?
 
                        eType : twitCurlTypes::eTwitCurlApiFormatXml;
 
}
 
 
/*++
 
* @method: twitCurl::setTwitterProcotolType
 
*
 
* @description: method to set protocol
 
*
 
* @input: none
 
*
 
* @output: none
 
*
 
*--*/
 
void twitCurl::setTwitterProcotolType( twitCurlTypes::eTwitCurlProtocolType eType )
 
{
 
    m_eProtocolType = ( eType < twitCurlTypes::eTwitCurlProtocolMax ) ?
 
                        eType : twitCurlTypes::eTwitCurlProtocolHttp;
 
    return cloneObj;
 
}
 
 
/*++
 
* @method: twitCurl::isCurlInit
 
*
 
* @description: method to check if cURL is initialized properly
 
*
 
* @input: none
 
*
 
* @output: true if cURL is intialized, otherwise false
 
*
 
*--*/
 
bool twitCurl::isCurlInit()
 
{
 
    return ( NULL != m_curlHandle ) ? true : false;
 
}
 
 
/*++
 
* @method: twitCurl::getTwitterUsername
 
*
 
* @description: method to get stored Twitter username
 
*
 
* @input: none
 
*
 
@@ -350,201 +313,219 @@ void twitCurl::setProxyUserName( std::string& proxyUserName )
 
* @input: proxyPassword
 
*
 
* @output: none
 
*
 
*--*/
 
void twitCurl::setProxyPassword( std::string& proxyPassword )
 
{
 
    if( proxyPassword.length() )
 
    {
 
        m_proxyPassword = proxyPassword;
 
        /*
 
         * Reset the flag so that next cURL http request
 
         * would set proxy details again into cURL.
 
         */
 
        m_curlProxyParamsSet = false;
 
    }
 
}
 
 
/*++
 
* @method: twitCurl::search
 
*
 
* @description: method to return tweets that match a specified query.
 
*
 
* @input: searchQuery - search query in string format
 
*         resultCount - optional search result count
 
*
 
* @output: true if GET is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
* @note: Only ATOM and JSON format supported.
 
*
 
*--*/
 
bool twitCurl::search( std::string& searchQuery )
 
bool twitCurl::search( std::string& searchQuery, std::string resultCount )
 
{
 
    /* Prepare URL */
 
    std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                           twitterDefaults::TWITCURL_SEARCH_URL +
 
                           twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[twitCurlTypes::eTwitCurlApiFormatJson] +
 
                           twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType] +
 
                           twitCurlDefaults::TWITCURL_URL_SEP_QUES + twitCurlDefaults::TWITCURL_SEARCHQUERYSTRING +
 
                           searchQuery;
 
 
    /* Add number of results count if provided */
 
    if( resultCount.size() )
 
    {
 
        buildUrl += twitCurlDefaults::TWITCURL_URL_SEP_AMP +
 
                    twitCurlDefaults::TWITCURL_COUNT + urlencode( resultCount );
 
    }
 
 
    /* Perform GET */
 
    return performGet( buildUrl );
 
}
 
 
/*++
 
* @method: twitCurl::statusUpdate
 
*
 
* @description: method to update new status message in twitter profile
 
*
 
* @input: newStatus
 
* @input: newStatus - status message text
 
*         inReplyToStatusId - optional status id to we're replying to
 
*
 
* @output: true if POST is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
*--*/
 
bool twitCurl::statusUpdate( std::string& newStatus )
 
bool twitCurl::statusUpdate( std::string& newStatus, std::string inReplyToStatusId )
 
{
 
    bool retVal = false;
 
    if( newStatus.length() )
 
    if( newStatus.empty() )
 
    {
 
        /* Prepare new status message */
 
        std::string newStatusMsg = twitCurlDefaults::TWITCURL_STATUSSTRING + urlencode( newStatus );
 
        return false;
 
    }
 
 
        /* Perform POST */
 
        retVal = performPost( twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                              twitterDefaults::TWITCURL_STATUSUPDATE_URL +
 
                              twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType],
 
                              newStatusMsg );
 
    /* Prepare new status message */
 
    std::string newStatusMsg = twitCurlDefaults::TWITCURL_STATUSSTRING + urlencode( newStatus );
 
 
    /* Append status id to which we're replying to */
 
    if( inReplyToStatusId.size() )
 
    {
 
        newStatusMsg += twitCurlDefaults::TWITCURL_URL_SEP_AMP +
 
                        twitCurlDefaults::TWITCURL_INREPLYTOSTATUSID +
 
                        urlencode( inReplyToStatusId );
 
    }
 
    return retVal;
 
 
    /* Perform POST */
 
    return  performPost( twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                         twitterDefaults::TWITCURL_STATUSUPDATE_URL +
 
                         twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType],
 
                         newStatusMsg );
 
}
 
 
/*++
 
* @method: twitCurl::statusShowById
 
*
 
* @description: method to get a status message by its id
 
*
 
* @input: statusId - a number in std::string format
 
*
 
* @output: true if GET is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
*--*/
 
bool twitCurl::statusShowById( std::string& statusId )
 
{
 
    bool retVal = false;
 
    if( statusId.length() )
 
    if( statusId.empty() )
 
    {
 
        /* Prepare URL */
 
        std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                               twitterDefaults::TWITCURL_STATUSSHOW_URL + statusId +
 
                               twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];
 
 
        /* Perform GET */
 
        retVal = performGet( buildUrl );
 
        return false;
 
    }
 
    return retVal;
 
 
    /* Prepare URL */
 
    std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                           twitterDefaults::TWITCURL_STATUSSHOW_URL + statusId +
 
                           twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];
 
 
    /* Perform GET */
 
    return performGet( buildUrl );
 
}
 
 
/*++
 
* @method: twitCurl::statusDestroyById
 
*
 
* @description: method to delete a status message by its id
 
*
 
* @input: statusId - a number in std::string format
 
*
 
* @output: true if DELETE is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
*--*/
 
bool twitCurl::statusDestroyById( std::string& statusId )
 
{
 
    bool retVal = false;
 
    if( statusId.length() )
 
    if( statusId.empty() )
 
    {
 
        /* Prepare URL */
 
        std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                               twitterDefaults::TWITCURL_STATUDESTROY_URL + statusId +
 
                               twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];
 
 
        /* Perform DELETE */
 
        retVal = performDelete( buildUrl );
 
        return false;
 
    }
 
    return retVal;
 
 
    /* Prepare URL */
 
    std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                           twitterDefaults::TWITCURL_STATUDESTROY_URL + statusId +
 
                           twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];
 
 
    /* Perform DELETE */
 
    return performDelete( buildUrl );
 
}
 
 
/*++
 
* @method: twitCurl::retweetById
 
*
 
* @description: method to RETWEET a status message by its id
 
*
 
* @input: statusId - a number in std::string format
 
*
 
* @output: true if RETWEET is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
*--*/
 
bool twitCurl::retweetById( std::string& statusId )
 
{
 
	bool retVal = false;
 
	if( statusId.length() )
 
	{
 
		/* Prepare URL */
 
		std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
								twitterDefaults::TWITCURL_RETWEET_URL + statusId +
 
								twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];
 
    if( statusId.empty() )
 
    {
 
        return false;
 
    }
 
 
    /* Prepare URL */
 
    std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                           twitterDefaults::TWITCURL_RETWEET_URL + statusId +
 
                           twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];
 
 
		/* Send some dummy data in POST */
 
		std::string dummyData = twitCurlDefaults::TWITCURL_TEXTSTRING +
 
				                urlencode( std::string( "dummy" ) );
 
    /* Send some dummy data in POST */
 
    std::string dummyData = twitCurlDefaults::TWITCURL_TEXTSTRING +
 
                            urlencode( std::string( "dummy" ) );
 
 
		/* Perform Retweet */
 
		retVal = performPost( buildUrl, dummyData );
 
	}
 
	return retVal;
 
    /* Perform Retweet */
 
    return performPost( buildUrl, dummyData );
 
}
 
 
/*++
 
* @method: twitCurl::timelineHomeGet
 
*
 
* @description: method to get home timeline
 
*
 
* @input: none
 
*
 
* @output: true if GET is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
*--*/
 
bool twitCurl::timelineHomeGet( std::string sinceId )
 
{
 
    std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
							twitterDefaults::TWITCURL_HOME_TIMELINE_URL +
 
							twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];
 
                           twitterDefaults::TWITCURL_HOME_TIMELINE_URL +
 
                           twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];
 
    if( sinceId.length() )
 
    {
 
        buildUrl += twitCurlDefaults::TWITCURL_URL_SEP_QUES + twitCurlDefaults::TWITCURL_SINCEID + sinceId;
 
    }
 
 
    /* Perform GET */
 
    return performGet( buildUrl );
 
}
 
 
/*++
 
* @method: twitCurl::timelinePublicGet
 
*
 
* @description: method to get public timeline
 
*
 
* @input: none
 
*
 
* @output: true if GET is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
*--*/
 
bool twitCurl::timelinePublicGet()
 
{
 
    /* Perform GET */
 
    return performGet( twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                       twitterDefaults::TWITCURL_PUBLIC_TIMELINE_URL +
 
                       twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType] );
 
}
 
 
/*++
 
@@ -584,171 +565,174 @@ bool twitCurl::timelineFriendsGet()
 
                       twitterDefaults::TWITCURL_FRIENDS_TIMELINE_URL +
 
                       twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType] );
 
}
 
 
/*++
 
* @method: twitCurl::mentionsGet
 
*
 
* @description: method to get mentions
 
*
 
* @input: sinceId - String specifying since id parameter
 
*
 
* @output: true if GET is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
*--*/
 
bool twitCurl::mentionsGet( std::string sinceId )
 
{
 
    std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                           twitterDefaults::TWITCURL_MENTIONS_URL +
 
                           twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];
 
    if( sinceId.length() )
 
    {
 
        buildUrl += twitCurlDefaults::TWITCURL_URL_SEP_QUES + twitCurlDefaults::TWITCURL_SINCEID + sinceId;
 
    }
 
 
    /* Perform GET */
 
    return performGet( buildUrl );
 
}
 
 
/*++
 
* @method: twitCurl::timelineUserGet
 
*
 
* @description: method to get mentions
 
*
 
* @input: trimUser - Trim user name if true
 
*         tweetCount - Number of tweets to get. Max 200.
 
*         userInfo - screen name or user id in string format,
 
*         isUserId - true if userInfo contains an id
 
*
 
* @output: true if GET is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
*--*/
 
bool twitCurl::timelineUserGet( bool trimUser, bool includeRetweets, unsigned int tweetCount, std::string userInfo, bool isUserId )
 
bool twitCurl::timelineUserGet( bool trimUser, bool includeRetweets, unsigned int tweetCount,
 
                                std::string userInfo, bool isUserId )
 
{
 
    /* Prepare URL */
 
    std::string buildUrl;
 
 
    utilMakeUrlForUser( buildUrl, twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                        twitterDefaults::TWITCURL_USERTIMELINE_URL +
 
                        twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType],
 
                        userInfo, isUserId );
 
 
    if( !userInfo.length() )
 
    if( userInfo.empty() )
 
    {
 
        buildUrl += twitCurlDefaults::TWITCURL_URL_SEP_QUES;
 
    }
 
 
    if( tweetCount )
 
    {
 
        if( tweetCount > twitCurlDefaults::MAX_TIMELINE_TWEET_COUNT )
 
        {
 
            tweetCount = twitCurlDefaults::MAX_TIMELINE_TWEET_COUNT;
 
        }
 
        std::stringstream tmpStrm;
 
        tmpStrm << twitCurlDefaults::TWITCURL_URL_SEP_AMP + twitCurlDefaults::TWITCURL_COUNT << tweetCount;
 
        buildUrl += tmpStrm.str();
 
        tmpStrm.str().clear();
 
    }
 
 
    if( includeRetweets )
 
    {
 
        buildUrl += twitCurlDefaults::TWITCURL_URL_SEP_AMP + twitCurlDefaults::TWITCURL_INCRETWEETS;
 
    }
 
 
    if( trimUser )
 
    {
 
        buildUrl += twitCurlDefaults::TWITCURL_URL_SEP_AMP + twitCurlDefaults::TWITCURL_TRIMUSER;
 
    }
 
 
    /* Perform GET */
 
    return performGet( buildUrl );
 
}
 
 
/*++
 
* @method: twitCurl::userLookup
 
*
 
* @description: method to get a number of user's profiles
 
*
 
* @input: userInfo - vector of screen names or user ids
 
*         isUserId - true if userInfo contains an id
 
*
 
* @output: true if POST is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
*--*/
 
bool twitCurl::userLookup( std::vector<std::string> &userInfo, bool isUserId )
 
{
 
    bool retVal = false;
 
    
 
    if( userInfo.size() )
 
    if( userInfo.empty() )
 
    {
 
		std::string userIds = "";
 
		std::string sep = "";
 
		for(int i=0 ; i<std::min(100U,(unsigned int) userInfo.size()) ; i++, sep = ",")
 
			userIds += sep + userInfo[i];
 
        return false;
 
    }
 
 
		userIds = (isUserId?twitCurlDefaults::TWITCURL_USERID : twitCurlDefaults::TWITCURL_SCREENNAME) + urlencode(userIds);
 
		
 
		std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] + 
 
								twitterDefaults::TWITCURL_LOOKUPUSERS_URL + 
 
								twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];
 
        
 
		/* Perform POST */
 
        retVal = performPost( buildUrl, userIds);
 
    std::string userIds = "";
 
    std::string sep = "";
 
    for( unsigned int i = 0 ; i < std::min((size_t)100, userInfo.size()); i++, sep = "," )
 
    {
 
        userIds += sep + userInfo[i];
 
    }
 
    
 
    return retVal;
 
 
    userIds = ( isUserId ? twitCurlDefaults::TWITCURL_USERID : twitCurlDefaults::TWITCURL_SCREENNAME ) +
 
              urlencode( userIds );
 
 
    std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] + 
 
                           twitterDefaults::TWITCURL_LOOKUPUSERS_URL + 
 
                           twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];
 
 
    /* Perform POST */
 
    return performPost( buildUrl, userIds);
 
}
 
 
/*++
 
* @method: twitCurl::userGet
 
*
 
* @description: method to get a user's profile
 
*
 
* @input: userInfo - screen name or user id in string format,
 
*         isUserId - true if userInfo contains an id
 
*
 
* @output: true if GET is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
*--*/
 
bool twitCurl::userGet( std::string& userInfo, bool isUserId )
 
{
 
    bool retVal = false;
 
    if( userInfo.length() )
 
    if( userInfo.empty() )
 
    {
 
        /* Set URL */
 
        std::string buildUrl;
 
        utilMakeUrlForUser( buildUrl, twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                            twitterDefaults::TWITCURL_SHOWUSERS_URL +
 
                            twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType],
 
                            userInfo, isUserId );
 
 
        /* Perform GET */
 
        retVal = performGet( buildUrl );
 
        return false;
 
    }
 
    return retVal;
 
 
    /* Set URL */
 
    std::string buildUrl;
 
    utilMakeUrlForUser( buildUrl, twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                        twitterDefaults::TWITCURL_SHOWUSERS_URL +
 
                        twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType],
 
                        userInfo, isUserId );
 
 
    /* Perform GET */
 
    return performGet( buildUrl );
 
}
 
 
/*++
 
* @method: twitCurl::friendsGet
 
*
 
* @description: method to get a user's friends
 
*
 
* @input: userInfo - screen name or user id in string format,
 
*         isUserId - true if userInfo contains an id
 
*
 
* @output: true if GET is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
*--*/
 
bool twitCurl::friendsGet( std::string userInfo, bool isUserId )
 
{
 
    /* Set URL */
 
    std::string buildUrl;
 
    utilMakeUrlForUser( buildUrl, twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                        twitterDefaults::TWITCURL_SHOWFRIENDS_URL +
 
                        twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType],
 
                        userInfo, isUserId );
 
 
    /* Perform GET */
 
@@ -772,288 +756,306 @@ bool twitCurl::followersGet( std::string userInfo, bool isUserId )
 
    /* Prepare URL */
 
    std::string buildUrl;
 
    utilMakeUrlForUser( buildUrl, twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                        twitterDefaults::TWITCURL_SHOWFOLLOWERS_URL +
 
                        twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType],
 
                        userInfo, isUserId );
 
 
    /* Perform GET */
 
    return performGet( buildUrl );
 
}
 
 
/*++
 
* @method: twitCurl::directMessageGet
 
*
 
* @description: method to get direct messages
 
*
 
* @input: since id
 
*
 
* @output: true if GET is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
*--*/
 
bool twitCurl::directMessageGet( std::string sinceId )
 
{
 
	std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] + 
 
							twitterDefaults::TWITCURL_DIRECTMESSAGES_URL + 
 
							twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];
 
	
 
	if(sinceId.length())
 
	{
 
      	buildUrl += twitCurlDefaults::TWITCURL_URL_SEP_QUES + twitCurlDefaults::TWITCURL_SINCEID + sinceId;
 
	}
 
    std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                           twitterDefaults::TWITCURL_DIRECTMESSAGES_URL +
 
                           twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];
 
 
    if( sinceId.length() )
 
    {
 
        buildUrl += twitCurlDefaults::TWITCURL_URL_SEP_QUES + twitCurlDefaults::TWITCURL_SINCEID + sinceId;
 
    }
 
 
    /* Perform GET */
 
    return performGet( buildUrl );
 
}
 
 
/*++
 
* @method: twitCurl::directMessageSend
 
*
 
* @description: method to send direct message to a user
 
*
 
* @input: userInfo - screen name or user id of a user to whom message needs to be sent,
 
*         dMsg - message
 
*         isUserId - true if userInfo contains target user's id
 
*
 
* @output: true if POST is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
*--*/
 
bool twitCurl::directMessageSend( std::string& userInfo, std::string& dMsg, bool isUserId )
 
{
 
    bool retVal = false;
 
    if( userInfo.length() && dMsg.length() )
 
    if( userInfo.empty() || dMsg.empty() )
 
    {
 
        /* Prepare new direct message */
 
        std::string newDm = twitCurlDefaults::TWITCURL_TEXTSTRING + urlencode( dMsg );
 
        return false;
 
    }
 
 
        /* Prepare URL */
 
        std::string buildUrl;
 
        utilMakeUrlForUser( buildUrl, twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                            twitterDefaults::TWITCURL_DIRECTMESSAGENEW_URL +
 
                            twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType],
 
                            userInfo, isUserId );
 
    /* Prepare new direct message */
 
    std::string newDm = twitCurlDefaults::TWITCURL_TEXTSTRING + urlencode( dMsg );
 
 
        /* Perform POST */
 
        retVal = performPost( buildUrl, newDm );
 
    }
 
    return retVal;
 
    /* Prepare URL */
 
    std::string buildUrl;
 
    utilMakeUrlForUser( buildUrl, twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                        twitterDefaults::TWITCURL_DIRECTMESSAGENEW_URL +
 
                        twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType],
 
                        userInfo, isUserId );
 
 
    /* Perform POST */
 
    return performPost( buildUrl, newDm );
 
}
 
 
/*++
 
* @method: twitCurl::directMessageGetSent
 
*
 
* @description: method to get sent direct messages
 
*
 
* @input: none
 
*
 
* @output: true if GET is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
*--*/
 
bool twitCurl::directMessageGetSent()
 
{
 
    /* Perform GET */
 
    return performGet( twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                       twitterDefaults::TWITCURL_DIRECTMESSAGESSENT_URL +
 
                       twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType] );
 
}
 
 
/*++
 
* @method: twitCurl::directMessageDestroyById
 
*
 
* @description: method to delete direct messages by its id
 
*
 
* @input: dMsgId - id of direct message in string format
 
*
 
* @output: true if DELETE is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
*--*/
 
bool twitCurl::directMessageDestroyById( std::string& dMsgId )
 
{
 
    bool retVal = false;
 
    if( dMsgId.length() )
 
    if( dMsgId.empty() )
 
    {
 
        /* Prepare URL */
 
        std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                               twitterDefaults::TWITCURL_DIRECTMESSAGEDESTROY_URL + dMsgId +
 
                               twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];
 
 
        /* Perform DELETE */
 
        retVal = performDelete( buildUrl );
 
        return false;
 
    }
 
    return retVal;
 
 
    /* Prepare URL */
 
    std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                           twitterDefaults::TWITCURL_DIRECTMESSAGEDESTROY_URL + dMsgId +
 
                           twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];
 
 
    /* Perform DELETE */
 
    return performDelete( buildUrl );
 
}
 
 
/*++
 
* @method: twitCurl::friendshipCreate
 
*
 
* @description: method to add a twitter user as friend (follow a user)
 
*
 
* @input: userInfo - user id or screen name of a user
 
*         isUserId - true if userInfo contains a user id instead of screen name
 
*
 
* @output: true if POST is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
*--*/
 
bool twitCurl::friendshipCreate( std::string& userInfo, bool isUserId )
 
{
 
    bool retVal = false;
 
    if( userInfo.length() )
 
    if( userInfo.empty() )
 
    {
 
        /* Prepare URL */
 
        std::string buildUrl;
 
        utilMakeUrlForUser( buildUrl, twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                            twitterDefaults::TWITCURL_FRIENDSHIPSCREATE_URL +
 
                            twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType],
 
                            userInfo, isUserId );
 
        return false;
 
    }
 
 
        /* Send some dummy data in POST */
 
        std::string dummyData = twitCurlDefaults::TWITCURL_TEXTSTRING +
 
                                urlencode( std::string( "dummy" ) );
 
    /* Prepare URL */
 
    std::string buildUrl;
 
    utilMakeUrlForUser( buildUrl, twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                        twitterDefaults::TWITCURL_FRIENDSHIPSCREATE_URL +
 
                        twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType],
 
                        userInfo, isUserId );
 
 
        /* Perform POST */
 
        retVal = performPost( buildUrl, dummyData );
 
    }
 
    return retVal;
 
    /* Send some dummy data in POST */
 
    std::string dummyData = twitCurlDefaults::TWITCURL_TEXTSTRING +
 
                            urlencode( std::string( "dummy" ) );
 
 
    /* Perform POST */
 
    return performPost( buildUrl, dummyData );
 
}
 
 
/*++
 
* @method: twitCurl::friendshipDestroy
 
*
 
* @description: method to delete a twitter user from friend list (unfollow a user)
 
*
 
* @input: userInfo - user id or screen name of a user
 
*         isUserId - true if userInfo contains a user id instead of screen name
 
*
 
* @output: true if DELETE is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
*--*/
 
bool twitCurl::friendshipDestroy( std::string& userInfo, bool isUserId )
 
{
 
    bool retVal = false;
 
    if( userInfo.length() )
 
    if( userInfo.empty() )
 
    {
 
        /* Prepare URL */
 
        std::string buildUrl;
 
        utilMakeUrlForUser( buildUrl, twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                            twitterDefaults::TWITCURL_FRIENDSHIPSDESTROY_URL +
 
                            twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType],
 
                            userInfo, isUserId );
 
 
        /* Perform DELETE */
 
        retVal = performDelete( buildUrl );
 
        return false;
 
    }
 
    return retVal;
 
 
    /* Prepare URL */
 
    std::string buildUrl;
 
    utilMakeUrlForUser( buildUrl, twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                        twitterDefaults::TWITCURL_FRIENDSHIPSDESTROY_URL +
 
                        twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType],
 
                        userInfo, isUserId );
 
 
    /* Perform DELETE */
 
    return performDelete( buildUrl );
 
}
 
 
/*++
 
* @method: twitCurl::friendshipShow
 
*
 
* @description: method to show all friends
 
*
 
* @input: userInfo - user id or screen name of a user of whom friends need to be shown
 
*         isUserId - true if userInfo contains a user id instead of screen name
 
*
 
* @output: true if GET is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
*--*/
 
bool twitCurl::friendshipShow( std::string& userInfo, bool isUserId )
 
{
 
    /* Prepare URL */
 
    std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                           twitterDefaults::TWITCURL_FRIENDSHIPSSHOW_URL +
 
                           twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];
 
    if( userInfo.length() )
 
    {
 
        /* Append username to the URL */
 
        buildUrl += twitCurlDefaults::TWITCURL_URL_SEP_QUES;
 
        if( isUserId )
 
        {
 
            buildUrl += twitCurlDefaults::TWITCURL_TARGETUSERID;
 
        }
 
        else
 
        {
 
            buildUrl += twitCurlDefaults::TWITCURL_TARGETSCREENNAME;
 
        }
 
        buildUrl += userInfo;
 
    }
 
 
    /* Perform GET */
 
    return performGet( buildUrl );
 
}
 
 
/*++
 
* @method: twitCurl::friendsIdsGet
 
*
 
* @description: method to show IDs of all friends of a twitter user
 
*
 
* @input: userInfo - user id or screen name of a user
 
*         isUserId - true if userInfo contains a user id instead of screen name
 
*         nextCursor - next cursor string returned from a previous call
 
*                      to this API, otherwise an empty string
 
*
 
* @output: true if GET is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
*--*/
 
bool twitCurl::friendsIdsGet( std::string& userInfo, bool isUserId )
 
bool twitCurl::friendsIdsGet( std::string& nextCursor, std::string& userInfo, bool isUserId )
 
{
 
    /* Prepare URL */
 
    std::string buildUrl;
 
    utilMakeUrlForUser( buildUrl, twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                        twitterDefaults::TWITCURL_FRIENDSIDS_URL +
 
                        twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType],
 
                        userInfo, isUserId );
 
 
    if( buildUrl.length() && nextCursor.length() )
 
    {
 
        buildUrl += twitCurlDefaults::TWITCURL_URL_SEP_AMP +
 
                    twitCurlDefaults::TWITCURL_NEXT_CURSOR +
 
                    nextCursor;
 
    }
 
 
    /* Perform GET */
 
    return performGet( buildUrl );
 
}
 
 
/*++
 
* @method: twitCurl::followersIdsGet
 
*
 
* @description: method to show IDs of all followers of a twitter user
 
*
 
* @input: userInfo - user id or screen name of a user
 
*         isUserId - true if userInfo contains a user id instead of screen name
 
*         nextCursor - next cursor string returned from a previous call
 
*                      to this API, otherwise an empty string
 
*
 
* @output: true if GET is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
*--*/
 
bool twitCurl::followersIdsGet( std::string& userInfo, bool isUserId )
 
bool twitCurl::followersIdsGet( std::string& nextCursor, std::string& userInfo, bool isUserId )
 
{
 
    /* Prepare URL */
 
    std::string buildUrl;
 
    utilMakeUrlForUser( buildUrl, twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                        twitterDefaults::TWITCURL_FOLLOWERSIDS_URL +
 
                        twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType],
 
                        userInfo, isUserId );
 
 
    if( buildUrl.length() && nextCursor.length() )
 
    {
 
        buildUrl += twitCurlDefaults::TWITCURL_URL_SEP_AMP +
 
                    twitCurlDefaults::TWITCURL_NEXT_CURSOR +
 
                    nextCursor;
 
    }
 
 
    /* Perform GET */
 
    return performGet( buildUrl );
 
}
 
 
/*++
 
* @method: twitCurl::accountRateLimitGet
 
*
 
* @description: method to get API rate limit of current user
 
*
 
* @input: none
 
*
 
* @output: true if GET is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
*--*/
 
bool twitCurl::accountRateLimitGet()
 
{
 
    /* Perform GET */
 
    return performGet( twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                       twitterDefaults::TWITCURL_ACCOUNTRATELIMIT_URL +
 
                       twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType] );
 
}
 
 
/*++
 
@@ -1126,91 +1128,185 @@ bool twitCurl::favoriteCreate( std::string& statusId )
 
* @description: method to delete a favorited the status
 
*
 
* @input: statusId - id in string format of the favorite status to be deleted
 
*
 
* @output: true if DELETE is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
*--*/
 
bool twitCurl::favoriteDestroy( std::string& statusId )
 
{
 
    /* Prepare URL */
 
    std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                           twitterDefaults::TWITCURL_FAVORITEDESTROY_URL + statusId +
 
                           twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];
 
 
    /* Perform DELETE */
 
    return performDelete( buildUrl );
 
}
 
 
/*++
 
* @method: twitCurl::blockCreate
 
*
 
* @description: method to block a user
 
*
 
* @input: userInfo - user id or screen name
 
* @input: userInfo - user id or screen name who needs to be blocked
 
*
 
* @output: true if POST is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
*--*/
 
bool twitCurl::blockCreate( std::string& userInfo )
 
{
 
        /* Prepare URL */
 
        std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                               twitterDefaults::TWITCURL_BLOCKSCREATE_URL + userInfo +
 
                               twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];
 
 
        /* Send some dummy data in POST */
 
        std::string dummyData = twitCurlDefaults::TWITCURL_TEXTSTRING +
 
                                urlencode( std::string( "dummy" ) );
 
 
        /* Perform POST */
 
        return performPost( buildUrl, dummyData );
 
}
 
 
/*++
 
* @method: twitCurl::blockDestroy
 
*
 
* @description: method to unblock a user
 
*
 
* @input: userInfo - user id or screen name
 
* @input: userInfo - user id or screen name who need to unblocked
 
*
 
* @output: true if DELETE is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
*--*/
 
bool twitCurl::blockDestroy( std::string& userInfo )
 
{
 
    /* Prepare URL */
 
    std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                           twitterDefaults::TWITCURL_BLOCKSDESTROY_URL + userInfo +
 
                           twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];
 
 
    /* Perform DELETE */
 
    return performDelete( buildUrl );
 
}
 
 
/*++
 
* @method: twitCurl::blockListGet
 
*
 
* @description: method to get list of users blocked by authenticated user
 
*
 
* @input: includeEntities - indicates whether or not to include 'entities' node
 
*         skipStatus - indicates whether or not to include status for returned users
 
*         nextCursor - next cursor string returned from a previous call
 
*                      to this API, otherwise an empty string
 
*
 
* @output: true if GET is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
*--*/
 
bool twitCurl::blockListGet( std::string& nextCursor, bool includeEntities, bool skipStatus )
 
{
 
    /* Prepare URL */
 
    std::string buildUrl, urlParams;
 
 
    buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
               twitterDefaults::TWITCURL_BLOCKSLIST_URL +
 
               twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];
 
    if( includeEntities )
 
    {
 
        urlParams += twitCurlDefaults::TWITCURL_INCLUDE_ENTITIES + std::string("true");
 
    }
 
    if( skipStatus )
 
    {
 
        if( urlParams.length() )
 
        {
 
            urlParams += twitCurlDefaults::TWITCURL_URL_SEP_AMP;
 
        }
 
        urlParams += twitCurlDefaults::TWITCURL_SKIP_STATUS + std::string("true");
 
    }
 
    if( nextCursor.length() )
 
    {
 
        if( urlParams.length() )
 
        {
 
            urlParams += twitCurlDefaults::TWITCURL_URL_SEP_AMP;
 
        }
 
        urlParams += twitCurlDefaults::TWITCURL_NEXT_CURSOR + nextCursor;
 
    }
 
    if( urlParams.length() )
 
    {
 
        buildUrl += twitCurlDefaults::TWITCURL_URL_SEP_QUES + urlParams;
 
    }
 
 
    /* Perform GET */
 
    return performGet( buildUrl );
 
}
 
 
/*++
 
* @method: twitCurl::blockIdsGet
 
*
 
* @description: method to get list of IDs blocked by authenticated user
 
*
 
* @input: stringifyIds - indicates whether or not returned ids should
 
*                        be in string format
 
*         nextCursor - next cursor string returned from a previous call
 
*                      to this API, otherwise an empty string
 
*
 
* @output: true if GET is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
*--*/
 
bool twitCurl::blockIdsGet( std::string& nextCursor, bool stringifyIds )
 
{
 
    /* Prepare URL */
 
    std::string buildUrl, urlParams;
 
 
    buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
               twitterDefaults::TWITCURL_BLOCKSIDS_URL +
 
               twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];
 
    if( stringifyIds )
 
    {
 
        urlParams += twitCurlDefaults::TWITCURL_STRINGIFY_IDS + std::string("true");
 
    }
 
    if( nextCursor.length() )
 
    {
 
        if( urlParams.length() )
 
        {
 
            urlParams += twitCurlDefaults::TWITCURL_URL_SEP_AMP;
 
        }
 
        urlParams += twitCurlDefaults::TWITCURL_NEXT_CURSOR + nextCursor;
 
    }
 
    if( urlParams.length() )
 
    {
 
        buildUrl += twitCurlDefaults::TWITCURL_URL_SEP_QUES + urlParams;
 
    }
 
 
    /* Perform GET */
 
    return performGet( buildUrl );
 
}
 
 
/*++
 
* @method: twitCurl::savedSearchGet
 
*
 
* @description: gets authenticated user's saved search queries.
 
*
 
* @input: none
 
*
 
* @output: true if GET is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
*--*/
 
bool twitCurl::savedSearchGet( )
 
{
 
    /* Perform GET */
 
    return performGet( twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                       twitterDefaults::TWITCURL_SAVEDSEARCHGET_URL +
 
                       twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType] );
 
}
 
 
/*++
 
* @method: twitCurl::savedSearchShow
 
*
 
* @description: method to retrieve the data for a saved search owned by the authenticating user
 
*               specified by the given id.
 
@@ -1412,231 +1508,235 @@ void twitCurl::getLastWebResponse( std::string& outWebResp )
 
*
 
*--*/
 
void twitCurl::getLastCurlError( std::string& outErrResp )
 
{
 
    m_errorBuffer[twitCurlDefaults::TWITCURL_DEFAULT_BUFFSIZE-1] = twitCurlDefaults::TWITCURL_EOS;
 
    outErrResp.assign( m_errorBuffer );
 
}
 
 
/*++
 
* @method: twitCurl::curlCallback
 
*
 
* @description: static method to get http response back from cURL.
 
*               this is an internal method, users of twitcurl need not
 
*               use this.
 
*
 
* @input: as per cURL convention.
 
*
 
* @output: size of data stored in our buffer
 
*
 
* @remarks: internal method
 
*
 
*--*/
 
int twitCurl::curlCallback( char* data, size_t size, size_t nmemb, twitCurl* pTwitCurlObj )
 
{
 
    int writtenSize = 0;
 
    if( ( NULL != pTwitCurlObj ) && ( NULL != data ) )
 
    if( pTwitCurlObj && data )
 
    {
 
        /* Save http response in twitcurl object's buffer */
 
        writtenSize = pTwitCurlObj->saveLastWebResponse( data, ( size*nmemb ) );
 
        return pTwitCurlObj->saveLastWebResponse( data, ( size*nmemb ) );
 
    }
 
    return writtenSize;
 
    return 0;
 
}
 
 
/*++
 
* @method: twitCurl::saveLastWebResponse
 
*
 
* @description: method to save http responses. this is an internal method
 
*               and twitcurl users need not use this.
 
*
 
* @input: data - character buffer from cURL,
 
*         size - size of character buffer
 
*
 
* @output: size of data stored in our buffer
 
*
 
* @remarks: internal method
 
*
 
*--*/
 
int twitCurl::saveLastWebResponse(  char*& data, size_t size )
 
{
 
    int bytesWritten = 0;
 
    if( data && size )
 
    {
 
        /* Append data in our internal buffer */
 
        m_callbackData.append( data, size );
 
        bytesWritten = (int)size;
 
        return (int)size;
 
    }
 
    return bytesWritten;
 
    return 0;
 
}
 
 
/*++
 
* @method: twitCurl::clearCurlCallbackBuffers
 
*
 
* @description: method to clear callback buffers used by cURL. this is an
 
*               internal method and twitcurl users need not use this.
 
*
 
* @input: none
 
*
 
* @output: none
 
*
 
* @remarks: internal method
 
*
 
*--*/
 
void twitCurl::clearCurlCallbackBuffers()
 
{
 
    m_callbackData = "";
 
    memset( m_errorBuffer, 0, twitCurlDefaults::TWITCURL_DEFAULT_BUFFSIZE );
 
}
 
 
/*++
 
* @method: twitCurl::prepareCurlProxy
 
*
 
* @description: method to set proxy details into cURL. this is an internal method.
 
*               twitcurl users should not use this method, instead use setProxyXxx
 
*               methods to set proxy server information.
 
*
 
* @input: none
 
*
 
* @output: none
 
*
 
* @remarks: internal method
 
*
 
*--*/
 
void twitCurl::prepareCurlProxy()
 
{
 
    if( !m_curlProxyParamsSet )
 
    if( m_curlProxyParamsSet )
 
    {
 
        /* Reset existing proxy details in cURL */
 
        curl_easy_setopt( m_curlHandle, CURLOPT_PROXY, NULL );
 
        curl_easy_setopt( m_curlHandle, CURLOPT_PROXYUSERPWD, NULL );
 
        curl_easy_setopt( m_curlHandle, CURLOPT_PROXYAUTH, (long)CURLAUTH_ANY );
 
        return;
 
    }
 
 
        /* Set proxy details in cURL */
 
        std::string proxyIpPort("");
 
        if( getProxyServerIp().size() )
 
        {
 
            utilMakeCurlParams( proxyIpPort, getProxyServerIp(), getProxyServerPort() );
 
        }
 
        curl_easy_setopt( m_curlHandle, CURLOPT_PROXY, proxyIpPort.c_str() );
 
    /* Reset existing proxy details in cURL */
 
    curl_easy_setopt( m_curlHandle, CURLOPT_PROXY, NULL );
 
    curl_easy_setopt( m_curlHandle, CURLOPT_PROXYUSERPWD, NULL );
 
    curl_easy_setopt( m_curlHandle, CURLOPT_PROXYAUTH, (long)CURLAUTH_ANY );
 
 
        /* Prepare username and password for proxy server */
 
        if( m_proxyUserName.length() && m_proxyPassword.length() )
 
        {
 
            std::string proxyUserPass;
 
            utilMakeCurlParams( proxyUserPass, getProxyUserName(), getProxyPassword() );
 
            curl_easy_setopt( m_curlHandle, CURLOPT_PROXYUSERPWD, proxyUserPass.c_str() );
 
        }
 
    /* Set proxy details in cURL */
 
    std::string proxyIpPort("");
 
    if( getProxyServerIp().size() )
 
    {
 
        utilMakeCurlParams( proxyIpPort, getProxyServerIp(), getProxyServerPort() );
 
    }
 
    curl_easy_setopt( m_curlHandle, CURLOPT_PROXY, proxyIpPort.c_str() );
 
 
        /* Set the flag to true indicating that proxy info is set in cURL */
 
        m_curlProxyParamsSet = true;
 
    /* Prepare username and password for proxy server */
 
    if( m_proxyUserName.length() && m_proxyPassword.length() )
 
    {
 
        std::string proxyUserPass;
 
        utilMakeCurlParams( proxyUserPass, getProxyUserName(), getProxyPassword() );
 
        curl_easy_setopt( m_curlHandle, CURLOPT_PROXYUSERPWD, proxyUserPass.c_str() );
 
    }
 
 
    /* Set the flag to true indicating that proxy info is set in cURL */
 
    m_curlProxyParamsSet = true;
 
}
 
 
/*++
 
* @method: twitCurl::prepareCurlCallback
 
*
 
* @description: method to set callback details into cURL. this is an internal method.
 
*               twitcurl users should not use this method.
 
*
 
* @input: none
 
*
 
* @output: none
 
*
 
* @remarks: internal method
 
*
 
*--*/
 
void twitCurl::prepareCurlCallback()
 
{
 
    if( !m_curlCallbackParamsSet )
 
    if( m_curlCallbackParamsSet )
 
    {
 
        /* Set buffer to get error */
 
        curl_easy_setopt( m_curlHandle, CURLOPT_ERRORBUFFER, m_errorBuffer );
 
        return;
 
    }
 
 
        /* Set callback function to get response */
 
        curl_easy_setopt( m_curlHandle, CURLOPT_WRITEFUNCTION, curlCallback );
 
        curl_easy_setopt( m_curlHandle, CURLOPT_WRITEDATA, this );
 
    /* Set buffer to get error */
 
    curl_easy_setopt( m_curlHandle, CURLOPT_ERRORBUFFER, m_errorBuffer );
 
 
        /* Set the flag to true indicating that callback info is set in cURL */
 
        m_curlCallbackParamsSet = true;
 
    }
 
    /* Set callback function to get response */
 
    curl_easy_setopt( m_curlHandle, CURLOPT_WRITEFUNCTION, curlCallback );
 
    curl_easy_setopt( m_curlHandle, CURLOPT_WRITEDATA, this );
 
 
    /* Set the flag to true indicating that callback info is set in cURL */
 
    m_curlCallbackParamsSet = true;
 
}
 
 
/*++
 
* @method: twitCurl::prepareCurlUserPass
 
*
 
* @description: method to set twitter credentials into cURL. this is an internal method.
 
*               twitcurl users should not use this method, instead use setTwitterXxx
 
*               methods to set twitter username and password.
 
*
 
* @input: none
 
*
 
* @output: none
 
*
 
* @remarks: internal method
 
*
 
*--*/
 
void twitCurl::prepareCurlUserPass()
 
{
 
    if( !m_curlLoginParamsSet )
 
    if( m_curlLoginParamsSet )
 
    {
 
        /* Reset existing username and password stored in cURL */
 
        curl_easy_setopt( m_curlHandle, CURLOPT_USERPWD, "" );
 
        return;
 
    }
 
 
        if( getTwitterUsername().size() )
 
        {
 
            /* Prepare username:password */
 
            std::string userNamePassword;
 
            utilMakeCurlParams( userNamePassword, getTwitterUsername(), getTwitterPassword() );
 
    /* Reset existing username and password stored in cURL */
 
    curl_easy_setopt( m_curlHandle, CURLOPT_USERPWD, "" );
 
 
            /* Set username and password */
 
            curl_easy_setopt( m_curlHandle, CURLOPT_USERPWD, userNamePassword.c_str() );
 
        }
 
    if( getTwitterUsername().size() )
 
    {
 
        /* Prepare username:password */
 
        std::string userNamePassword;
 
        utilMakeCurlParams( userNamePassword, getTwitterUsername(), getTwitterPassword() );
 
 
        /* Set the flag to true indicating that twitter credentials are set in cURL */
 
        m_curlLoginParamsSet = true;
 
        /* Set username and password */
 
        curl_easy_setopt( m_curlHandle, CURLOPT_USERPWD, userNamePassword.c_str() );
 
    }
 
 
    /* Set the flag to true indicating that twitter credentials are set in cURL */
 
    m_curlLoginParamsSet = true;
 
}
 
 
/*++
 
* @method: twitCurl::prepareStandardParams
 
*
 
* @description: method to set standard params into cURL. this is an internal method.
 
*               twitcurl users should not use this method.
 
*
 
* @input: none
 
*
 
* @output: none
 
*
 
* @remarks: internal method
 
*
 
*--*/
 
void twitCurl::prepareStandardParams()
 
{
 
    /* Restore any custom request we may have */
 
    curl_easy_setopt( m_curlHandle, CURLOPT_CUSTOMREQUEST, NULL );
 
 
	/* All supported encodings */
 
	curl_easy_setopt( m_curlHandle, CURLOPT_ENCODING, "" );
 
    /* All supported encodings */
 
    curl_easy_setopt( m_curlHandle, CURLOPT_ENCODING, "" );
 
 
    /* Clear callback and error buffers */
 
    clearCurlCallbackBuffers();
 
 
    /* Prepare proxy */
 
    prepareCurlProxy();
 
 
    /* Prepare cURL callback data and error buffer */
 
    prepareCurlCallback();
 
 
    /* Prepare username and password for twitter */
 
    prepareCurlUserPass();
 
}
 
 
/*++
 
* @method: twitCurl::performGet
 
*
 
* @description: method to send http GET request. this is an internal method.
 
*               twitcurl users should not use this method.
 
*
 
* @input: getUrl - url
 
*
 
* @output: none
 
*
 
@@ -1669,61 +1769,62 @@ bool twitCurl::performGet( const std::string& getUrl )
 
        }
 
    }
 
 
    /* Set http request and url */
 
    curl_easy_setopt( m_curlHandle, CURLOPT_HTTPGET, 1 );
 
    curl_easy_setopt( m_curlHandle, CURLOPT_URL, getUrl.c_str() );
 
 
    /* Send http request */
 
    if( CURLE_OK == curl_easy_perform( m_curlHandle ) )
 
    {
 
        if( pOAuthHeaderList )
 
        {
 
            curl_slist_free_all( pOAuthHeaderList );
 
        }
 
        return true;
 
    }
 
    if( pOAuthHeaderList )
 
    {
 
        curl_slist_free_all( pOAuthHeaderList );
 
    }
 
    return false;
 
}
 
 
/*++
 
* @method: twitCurl::performGet
 
* @method: twitCurl::performGetInternal
 
*
 
* @description: method to send http GET request. this is an internal method.
 
*               twitcurl users should not use this method.
 
*
 
* @input: const std::string& getUrl, const std::string& oAuthHttpHeader
 
*
 
* @output: none
 
*
 
* @remarks: internal method
 
*
 
*--*/
 
bool twitCurl::performGet( const std::string& getUrl, const std::string& oAuthHttpHeader )
 
bool twitCurl::performGetInternal( const std::string& getUrl,
 
                                   const std::string& oAuthHttpHeader )
 
{
 
    /* Return if cURL is not initialized */
 
    if( !isCurlInit() )
 
    {
 
        return false;
 
    }
 
 
    struct curl_slist* pOAuthHeaderList = NULL;
 
 
    /* Prepare standard params */
 
    prepareStandardParams();
 
 
    /* Set http request and url */
 
    curl_easy_setopt( m_curlHandle, CURLOPT_HTTPGET, 1 );
 
    curl_easy_setopt( m_curlHandle, CURLOPT_URL, getUrl.c_str() );
 
 
    /* Set header */
 
    if( oAuthHttpHeader.length() )
 
    {
 
        pOAuthHeaderList = curl_slist_append( pOAuthHeaderList, oAuthHttpHeader.c_str() );
 
        if( pOAuthHeaderList )
 
        {
 
            curl_easy_setopt( m_curlHandle, CURLOPT_HTTPHEADER, pOAuthHeaderList );
 
        }
 
@@ -1942,118 +2043,118 @@ oAuth& twitCurl::getOAuth()
 
    return m_oAuth;
 
}
 
 
/*++
 
* @method: twitCurl::oAuthRequestToken
 
*
 
* @description: method to get a request token key and secret. this token
 
*               will be used to get authorize user and get PIN from twitter
 
*
 
* @input: authorizeUrl is an output parameter. this method will set the url
 
*         in this string. user should visit this link and get PIN from that page.
 
*
 
* @output: true if everything went sucessfully, otherwise false
 
*
 
*--*/
 
bool twitCurl::oAuthRequestToken( std::string& authorizeUrl /* out */ )
 
{
 
    /* Return if cURL is not initialized */
 
    if( !isCurlInit() )
 
    {
 
        return false;
 
    }
 
 
    /* Get OAuth header for request token */
 
    bool retVal = false;
 
    std::string oAuthHeader;
 
    authorizeUrl = "";
 
    if( m_oAuth.getOAuthHeader( eOAuthHttpGet,
 
                                twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                                oAuthTwitterApiUrls::OAUTHLIB_TWITTER_REQUEST_TOKEN_URL,
 
                                std::string( "" ),
 
                                oAuthHeader ) )
 
    {
 
        if( performGet( twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                        oAuthTwitterApiUrls::OAUTHLIB_TWITTER_REQUEST_TOKEN_URL, oAuthHeader ) )
 
        if( performGetInternal( twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                                oAuthTwitterApiUrls::OAUTHLIB_TWITTER_REQUEST_TOKEN_URL,
 
                                oAuthHeader ) )
 
        {
 
            /* Tell OAuth object to save access token and secret from web response */
 
            std::string twitterResp;
 
            getLastWebResponse( twitterResp );
 
            m_oAuth.extractOAuthTokenKeySecret( twitterResp );
 
 
            /* Get access token and secret from OAuth object */
 
            std::string oAuthTokenKey;
 
            m_oAuth.getOAuthTokenKey( oAuthTokenKey );
 
 
            /* Build authorize url so that user can visit in browser and get PIN */
 
            authorizeUrl.assign(twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                                oAuthTwitterApiUrls::OAUTHLIB_TWITTER_AUTHORIZE_URL );
 
            authorizeUrl.append( oAuthTokenKey.c_str() );
 
 
            retVal = true;
 
            return true;
 
        }
 
    }
 
    return retVal;
 
    return false;
 
}
 
 
/*++
 
* @method: twitCurl::oAuthAccessToken
 
*
 
* @description: method to exchange request token with access token
 
*
 
* @input: none
 
*
 
* @output: true if everything went sucessfully, otherwise false
 
*
 
*--*/
 
bool twitCurl::oAuthAccessToken()
 
{
 
    /* Return if cURL is not initialized */
 
    if( !isCurlInit() )
 
    {
 
        return false;
 
    }
 
    /* Get OAuth header for access token */
 
    bool retVal = false;
 
    std::string oAuthHeader;
 
    if( m_oAuth.getOAuthHeader( eOAuthHttpGet,
 
                                twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                                oAuthTwitterApiUrls::OAUTHLIB_TWITTER_ACCESS_TOKEN_URL,
 
                                std::string( "" ),
 
                                oAuthHeader, true ) )
 
    {
 
        if( performGet( twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                        oAuthTwitterApiUrls::OAUTHLIB_TWITTER_ACCESS_TOKEN_URL, oAuthHeader ) )
 
        if( performGetInternal( twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                                oAuthTwitterApiUrls::OAUTHLIB_TWITTER_ACCESS_TOKEN_URL,
 
                                oAuthHeader ) )
 
        {
 
            /* Tell OAuth object to save access token and secret from web response */
 
            std::string twitterResp;
 
            getLastWebResponse( twitterResp );
 
            m_oAuth.extractOAuthTokenKeySecret( twitterResp );
 
 
            retVal = true;
 
            return true;
 
        }
 
    }
 
    return retVal;
 
    return false;
 
}
 
 
/*++
 
* ADDED BY ANTIROOT
 
*
 
* @method: twitCurl::oAuthHandlePIN
 
*
 
* @description: method to handle user's PIN code from the authentiation URLs
 
*
 
* @input: none
 
*
 
* @output: true if everything went sucessfully, otherwise false
 
*
 
*--*/
 
bool twitCurl::oAuthHandlePIN( const std::string& authorizeUrl /* in */ )
 
{
 
    /* Return if cURL is not initialized */
 
    if( !isCurlInit() )
 
    {
 
        return false;
 
    }
 
 
    std::string dataStr;
 
    std::string oAuthHttpHeader;
 
@@ -2166,24 +2267,25 @@ bool twitCurl::oAuthHandlePIN( const std::string& authorizeUrl /* in */ )
 
 
            // Now, let's find the PIN CODE
 
            nPosStart = m_callbackData.find( oAuthLibDefaults::OAUTHLIB_PIN_TWITTER_RESP_KEY );
 
            if( std::string::npos == nPosStart )
 
            {
 
                return false;
 
            }
 
            nPosStart += oAuthLibDefaults::OAUTHLIB_PIN_TWITTER_RESP_KEY.length();
 
            nPosEnd = m_callbackData.substr( nPosStart ).find( oAuthLibDefaults::OAUTHLIB_PIN_END_TAG_TWITTER_RESP );
 
            if( std::string::npos == nPosEnd )
 
            {
 
                return false;
 
            }
 
            pinCodeVal = m_callbackData.substr( nPosStart, nPosEnd );
 
            getOAuth().setOAuthPin( pinCodeVal );
 
            return true;
 
        }
 
    }
 
    else if( pOAuthHeaderList )
 
    {
 
        curl_slist_free_all( pOAuthHeaderList );
 
    }
 
    return false;
 
}
 
backends/twitter/libtwitcurl/twitcurl.h
Show inline comments
 
#ifndef _TWITCURL_H_
 
#define _TWITCURL_H_
 
#ifdef _WIN32
 
#define NOMINMAX 1
 
#endif
 
 
#include <string>
 
#include <sstream>
 
#include <cstring>
 
#include <vector>
 
#include "oauthlib.h"
 
#include "curl/curl.h"
 
 
/* Few common types used by twitCurl */
 
namespace twitCurlTypes
 
{
 
    typedef enum _eTwitCurlApiFormatType
 
    {
 
        eTwitCurlApiFormatXml = 0,
 
        eTwitCurlApiFormatJson,
 
        eTwitCurlApiFormatJson = 0,
 
        eTwitCurlApiFormatXml,
 
        eTwitCurlApiFormatMax
 
    } eTwitCurlApiFormatType;
 
 
    typedef enum _eTwitCurlProtocolType
 
    {
 
        eTwitCurlProtocolHttp = 0,
 
        eTwitCurlProtocolHttps,
 
        eTwitCurlProtocolHttps = 0,
 
        eTwitCurlProtocolHttp,
 
        eTwitCurlProtocolMax
 
    } eTwitCurlProtocolType;
 
};
 
 
/* Default values used in twitcurl */
 
namespace twitCurlDefaults
 
{
 
    /* Constants */
 
    const int TWITCURL_DEFAULT_BUFFSIZE = 1024;
 
    const std::string TWITCURL_COLON = ":";
 
    const char TWITCURL_EOS = '\0';
 
    const unsigned int MAX_TIMELINE_TWEET_COUNT = 200;
 
 
    /* Miscellaneous data used to build twitter URLs*/
 
    const std::string TWITCURL_STATUSSTRING = "status=";
 
    const std::string TWITCURL_TEXTSTRING = "text=";
 
    const std::string TWITCURL_QUERYSTRING = "query=";
 
    const std::string TWITCURL_SEARCHQUERYSTRING = "q=";
 
    const std::string TWITCURL_SCREENNAME = "screen_name=";
 
    const std::string TWITCURL_USERID = "user_id=";
 
    const std::string TWITCURL_EXTENSIONFORMATS[2] = { ".xml",
 
                                                       ".json"
 
                                                     };
 
    const std::string TWITCURL_PROTOCOLS[2] =        { "http://",
 
                                                       "https://"
 
                                                     };
 
    const std::string TWITCURL_TARGETSCREENNAME = "target_screen_name=";
 
    const std::string TWITCURL_TARGETUSERID = "target_id=";
 
    const std::string TWITCURL_SINCEID = "since_id=";
 
    const std::string TWITCURL_TRIMUSER = "trim_user=true";
 
    const std::string TWITCURL_INCRETWEETS = "include_rts=true";
 
    const std::string TWITCURL_COUNT = "count=";
 
 
    /* URL separators */
 
    const std::string TWITCURL_URL_SEP_AMP = "&";
 
    const std::string TWITCURL_URL_SEP_QUES = "?";
 
};
 
 
/* Default twitter URLs */
 
namespace twitterDefaults
 
{
 
 
    /* Search URLs */
 
    const std::string TWITCURL_SEARCH_URL = "search.twitter.com/search";
 
 
    /* Status URLs */
 
    const std::string TWITCURL_STATUSUPDATE_URL = "api.twitter.com/1.1/statuses/update";
 
    const std::string TWITCURL_STATUSSHOW_URL = "api.twitter.com/1.1/statuses/show/";
 
    const std::string TWITCURL_STATUDESTROY_URL = "api.twitter.com/1.1/statuses/destroy/";
 
	const std::string TWITCURL_RETWEET_URL = "api.twitter.com/1.1/statuses/retweet/";
 
 
    /* Timeline URLs */
 
    const std::string TWITCURL_HOME_TIMELINE_URL = "api.twitter.com/1.1/statuses/home_timeline";
 
    const std::string TWITCURL_PUBLIC_TIMELINE_URL = "api.twitter.com/1.1/statuses/public_timeline";
 
    const std::string TWITCURL_FEATURED_USERS_URL = "api.twitter.com/1.1/statuses/featured";
 
    const std::string TWITCURL_FRIENDS_TIMELINE_URL = "api.twitter.com/1.1/statuses/friends_timeline";
 
    const std::string TWITCURL_MENTIONS_URL = "api.twitter.com/1.1/statuses/mentions";
 
    const std::string TWITCURL_USERTIMELINE_URL = "api.twitter.com/1.1/statuses/user_timeline";
 
 
    /* Users URLs */
 
	const std::string TWITCURL_LOOKUPUSERS_URL = "api.twitter.com/1.1/users/lookup";
 
    const std::string TWITCURL_SHOWUSERS_URL = "api.twitter.com/1.1/users/show";
 
    const std::string TWITCURL_SHOWFRIENDS_URL = "api.twitter.com/1.1/statuses/friends";
 
    const std::string TWITCURL_SHOWFOLLOWERS_URL = "api.twitter.com/1.1/statuses/followers";
 
 
    /* Direct messages URLs */
 
    const std::string TWITCURL_DIRECTMESSAGES_URL = "api.twitter.com/1.1/direct_messages";
 
    const std::string TWITCURL_DIRECTMESSAGENEW_URL = "api.twitter.com/1.1/direct_messages/new";
 
    const std::string TWITCURL_DIRECTMESSAGESSENT_URL = "api.twitter.com/1.1/direct_messages/sent";
 
    const std::string TWITCURL_DIRECTMESSAGEDESTROY_URL = "api.twitter.com/1.1/direct_messages/destroy/";
 
 
    /* Friendships URLs */
 
    const std::string TWITCURL_FRIENDSHIPSCREATE_URL = "api.twitter.com/1.1/friendships/create";
 
    const std::string TWITCURL_FRIENDSHIPSDESTROY_URL = "api.twitter.com/1.1/friendships/destroy";
 
    const std::string TWITCURL_FRIENDSHIPSSHOW_URL = "api.twitter.com/1.1/friendships/show";
 
 
    /* Social graphs URLs */
 
    const std::string TWITCURL_FRIENDSIDS_URL = "api.twitter.com/1.1/friends/ids";
 
    const std::string TWITCURL_FOLLOWERSIDS_URL = "api.twitter.com/1.1/followers/ids";
 
 
    /* Account URLs */
 
    const std::string TWITCURL_ACCOUNTRATELIMIT_URL = "api.twitter.com/1.1/account/rate_limit_status";
 
    const std::string TWITCURL_ACCOUNTVERIFYCRED_URL = "api.twitter.com/1.1/account/verify_credentials";
 
 
    /* Favorites URLs */
 
    const std::string TWITCURL_FAVORITESGET_URL = "api.twitter.com/1.1/favorites";
 
    const std::string TWITCURL_FAVORITECREATE_URL = "api.twitter.com/1.1/favorites/create/";
 
    const std::string TWITCURL_FAVORITEDESTROY_URL = "api.twitter.com/1.1/favorites/destroy/";
 
 
    /* Block URLs */
 
    const std::string TWITCURL_BLOCKSCREATE_URL = "api.twitter.com/1.1/blocks/create/";
 
    const std::string TWITCURL_BLOCKSDESTROY_URL = "api.twitter.com/1.1/blocks/destroy/";
 
 
    /* Saved Search URLs */
 
    const std::string TWITCURL_SAVEDSEARCHGET_URL = "api.twitter.com/1.1/saved_searches";
 
    const std::string TWITCURL_SAVEDSEARCHSHOW_URL = "api.twitter.com/1.1/saved_searches/show/";
 
    const std::string TWITCURL_SAVEDSEARCHCREATE_URL = "api.twitter.com/1.1/saved_searches/create";
 
    const std::string TWITCURL_SAVEDSEARCHDESTROY_URL = "api.twitter.com/1.1/saved_searches/destroy/";
 
 
    /* Trends URLs */
 
    const std::string TWITCURL_TRENDS_URL = "api.twitter.com/1.1/trends";
 
    const std::string TWITCURL_TRENDSDAILY_URL = "api.twitter.com/1.1/trends/daily";
 
    const std::string TWITCURL_TRENDSCURRENT_URL = "api.twitter.com/1.1/trends/current";
 
    const std::string TWITCURL_TRENDSWEEKLY_URL = "api.twitter.com/1.1/trends/weekly";
 
    const std::string TWITCURL_TRENDSAVAILABLE_URL = "api.twitter.com/1.1/trends/available";
 
 
};
 
 
/* twitCurl class */
 
class twitCurl
 
{
 
public:
 
    twitCurl();
 
    ~twitCurl();
 
 
    /* Twitter OAuth authorization methods */
 
    oAuth& getOAuth();
 
    bool oAuthRequestToken( std::string& authorizeUrl /* out */ );
 
    bool oAuthAccessToken();
 
    bool oAuthHandlePIN( const std::string& authorizeUrl /* in */ );
 
 
    /* Twitter login APIs, set once and forget */
 
    std::string& getTwitterUsername();
 
    std::string& getTwitterPassword();
 
    void setTwitterUsername( std::string& userName /* in */ );
 
    void setTwitterPassword( std::string& passWord /* in */ );
 
 
    /* Twitter API type */
 
    void setTwitterApiType( twitCurlTypes::eTwitCurlApiFormatType eType );
 
    void setTwitterProcotolType( twitCurlTypes::eTwitCurlProtocolType eType );
 
 
    /* Twitter search APIs */
 
    bool search( std::string& searchQuery /* in */ );
 
    bool search( std::string& searchQuery /* in */, std::string resultCount = "" /* in */ );
 
 
    /* Twitter status APIs */
 
    bool statusUpdate( std::string& newStatus /* in */ );
 
    bool statusUpdate( std::string& newStatus /* in */, std::string inReplyToStatusId = "" /* in */ );
 
    bool statusShowById( std::string& statusId /* in */ );
 
    bool statusDestroyById( std::string& statusId /* in */ );
 
    bool retweetById( std::string& statusId /* in */ );
 
 
    /* Twitter timeline APIs */
 
    bool timelineHomeGet( std::string sinceId = ""  /* in */ );
 
    bool timelinePublicGet();
 
    bool timelineFriendsGet();
 
    bool timelineUserGet( bool trimUser /* in */, bool includeRetweets /* in */, unsigned int tweetCount /* in */, std::string userInfo = "" /* in */, bool isUserId = false /* in */ );
 
    bool timelineUserGet( bool trimUser /* in */, bool includeRetweets /* in */,
 
                          unsigned int tweetCount /* in */,
 
                          std::string userInfo = "" /* in */,
 
                          bool isUserId = false /* in */ );
 
    bool featuredUsersGet();
 
    bool mentionsGet( std::string sinceId = "" /* in */ );
 
 
    /* Twitter user APIs */
 
	bool userLookup( std::vector<std::string> &userInfo /* in */,  bool isUserId = false /* in */ );
 
    bool userLookup( std::vector<std::string> &userInfo /* in */,  bool isUserId = false /* in */ );
 
    bool userGet( std::string& userInfo /* in */, bool isUserId = false /* in */ );
 
    bool friendsGet( std::string userInfo = "" /* in */, bool isUserId = false /* in */ );
 
    bool followersGet( std::string userInfo = "" /* in */, bool isUserId = false /* in */ );
 
 
    /* Twitter direct message APIs */
 
    bool directMessageGet( std::string sinceId /* in */ );
 
    bool directMessageGet( std::string sinceId = "" /* in */ );
 
    bool directMessageSend( std::string& userInfo /* in */, std::string& dMsg /* in */, bool isUserId = false /* in */ );
 
    bool directMessageGetSent();
 
    bool directMessageDestroyById( std::string& dMsgId /* in */ );
 
 
    /* Twitter friendships APIs */
 
    bool friendshipCreate( std::string& userInfo /* in */, bool isUserId = false /* in */ );
 
    bool friendshipDestroy( std::string& userInfo /* in */, bool isUserId = false /* in */ );
 
    bool friendshipShow( std::string& userInfo /* in */, bool isUserId = false /* in */ );
 
 
    /* Twitter social graphs APIs */
 
    bool friendsIdsGet( std::string& userInfo /* in */, bool isUserId = false /* in */ );
 
    bool followersIdsGet( std::string& userInfo /* in */, bool isUserId = false /* in */ );
 
    bool friendsIdsGet( std::string& nextCursor /* in */,
 
                        std::string& userInfo /* in */, bool isUserId = false /* in */ );
 
    bool followersIdsGet( std::string& nextCursor /* in */,
 
                          std::string& userInfo /* in */, bool isUserId = false /* in */ );
 
 
    /* Twitter account APIs */
 
    bool accountRateLimitGet();
 
    bool accountVerifyCredGet();
 
 
    /* Twitter favorites APIs */
 
    bool favoriteGet();
 
    bool favoriteCreate( std::string& statusId /* in */ );
 
    bool favoriteDestroy( std::string& statusId /* in */ );
 
 
    /* Twitter block APIs */
 
    bool blockCreate( std::string& userInfo /* in */ );
 
    bool blockDestroy( std::string& userInfo /* in */ );
 
    bool blockListGet( std::string& nextCursor /* in */,
 
                        bool includeEntities /* in */, bool skipStatus /* in */ );
 
    bool blockIdsGet( std::string& nextCursor /* in */, bool stringifyIds /* in */ );
 
 
    /* Twitter search APIs */
 
    bool savedSearchGet();
 
    bool savedSearchCreate( std::string& query /* in */ );
 
    bool savedSearchShow( std::string& searchId /* in */ );
 
    bool savedSearchDestroy( std::string& searchId /* in */ );
 
 
    /* Twitter trends APIs (JSON) */
 
    bool trendsGet();
 
    bool trendsDailyGet();
 
    bool trendsWeeklyGet();
 
    bool trendsCurrentGet();
 
    bool trendsAvailableGet();
 
 
    /* cURL APIs */
 
    bool isCurlInit();
 
    void getLastWebResponse( std::string& outWebResp /* out */ );
 
    void getLastCurlError( std::string& outErrResp /* out */);
 
 
    /* Internal cURL related methods */
 
    int saveLastWebResponse( char*& data, size_t size );
 
 
    /* cURL proxy APIs */
 
    std::string& getProxyServerIp();
 
    std::string& getProxyServerPort();
 
    std::string& getProxyUserName();
 
    std::string& getProxyPassword();
 
    void setProxyServerIp( std::string& proxyServerIp /* in */ );
 
    void setProxyServerPort( std::string& proxyServerPort /* in */ );
 
    void setProxyUserName( std::string& proxyUserName /* in */ );
 
    void setProxyPassword( std::string& proxyPassword /* in */ );
 
 
	twitCurl* clone();
 
    
 
    /* Clones this object */
 
    twitCurl* clone();
 
 
private:
 
    /* cURL data */
 
    CURL* m_curlHandle;
 
    char m_errorBuffer[twitCurlDefaults::TWITCURL_DEFAULT_BUFFSIZE];
 
    char* m_errorBuffer;
 
    std::string m_callbackData;
 
 
    /* cURL flags */
 
    bool m_curlProxyParamsSet;
 
    bool m_curlLoginParamsSet;
 
    bool m_curlCallbackParamsSet;
 
 
    /* cURL proxy data */
 
    std::string m_proxyServerIp;
 
    std::string m_proxyServerPort;
 
    std::string m_proxyUserName;
 
    std::string m_proxyPassword;
 
 
    /* Twitter data */
 
    std::string m_twitterUsername;
 
    std::string m_twitterPassword;
 
 
    /* Twitter API type */
 
    twitCurlTypes::eTwitCurlApiFormatType m_eApiFormatType;
 
    twitCurlTypes::eTwitCurlProtocolType m_eProtocolType;
 
 
    /* OAuth data */
 
    oAuth m_oAuth;
 
 
    /* Private methods */
 
    void clearCurlCallbackBuffers();
 
    void prepareCurlProxy();
 
    void prepareCurlCallback();
 
    void prepareCurlUserPass();
 
    void prepareStandardParams();
 
    bool performGet( const std::string& getUrl );
 
    bool performGet( const std::string& getUrl, const std::string& oAuthHttpHeader );
 
    bool performGetInternal( const std::string& getUrl,
 
                             const std::string& oAuthHttpHeader );
 
    bool performDelete( const std::string& deleteUrl );
 
    bool performPost( const std::string& postUrl, std::string dataStr = "" );
 
 
    /* Internal cURL related methods */
 
    static int curlCallback( char* data, size_t size, size_t nmemb, twitCurl* pTwitCurlObj );
 
};
 
 
 
/* Private functions */
 
void utilMakeCurlParams( std::string& outStr, std::string& inParam1, std::string& inParam2 );
 
void utilMakeUrlForUser( std::string& outUrl, const std::string& baseUrl, std::string& userInfo, bool isUserId );
 
 
#endif // _TWITCURL_H_
backends/twitter/libtwitcurl/twitcurl.vcproj
Show inline comments
 
@@ -97,75 +97,75 @@
 
			InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
 
			UseOfMFC="0"
 
			ATLMinimizesCRunTimeLibraryUsage="false"
 
			CharacterSet="2"
 
			>
 
			<Tool
 
				Name="VCPreBuildEventTool"
 
			/>
 
			<Tool
 
				Name="VCCustomBuildTool"
 
			/>
 
			<Tool
 
				Name="VCXMLDataGeneratorTool"
 
			/>
 
			<Tool
 
				Name="VCWebServiceProxyGeneratorTool"
 
			/>
 
			<Tool
 
				Name="VCMIDLTool"
 
			/>
 
			<Tool
 
				Name="VCCLCompilerTool"
 
				Optimization="2"
 
				InlineFunctionExpansion="1"
 
				AdditionalIncludeDirectories="./curl"
 
				AdditionalIncludeDirectories="./include"
 
				PreprocessorDefinitions="WIN32;NDEBUG;_LIB;CURL_STATICLIB"
 
				StringPooling="true"
 
				RuntimeLibrary="2"
 
				EnableFunctionLevelLinking="true"
 
				PrecompiledHeaderFile=".\Release/twitcurl.pch"
 
				AssemblerListingLocation=".\Release/"
 
				ObjectFile=".\Release/"
 
				ProgramDataBaseFileName=".\Release/"
 
				WarningLevel="3"
 
				SuppressStartupBanner="true"
 
			/>
 
			<Tool
 
				Name="VCManagedResourceCompilerTool"
 
			/>
 
			<Tool
 
				Name="VCResourceCompilerTool"
 
				PreprocessorDefinitions="NDEBUG"
 
				Culture="1033"
 
			/>
 
			<Tool
 
				Name="VCPreLinkEventTool"
 
			/>
 
			<Tool
 
				Name="VCLibrarianTool"
 
				LinkLibraryDependencies="true"
 
				AdditionalDependencies="libcurl.lib ws2_32.lib wldap32.lib"
 
				AdditionalDependencies="libcurl.lib"
 
				OutputFile=".\Release\twitcurl.lib"
 
				AdditionalLibraryDirectories="./lib"
 
				SuppressStartupBanner="true"
 
			/>
 
			<Tool
 
				Name="VCALinkTool"
 
			/>
 
			<Tool
 
				Name="VCXDCMakeTool"
 
			/>
 
			<Tool
 
				Name="VCBscMakeTool"
 
				SuppressStartupBanner="true"
 
				OutputFile=".\Release/twitcurl.bsc"
 
			/>
 
			<Tool
 
				Name="VCFxCopTool"
 
			/>
 
			<Tool
 
				Name="VCPostBuildEventTool"
 
			/>
 
		</Configuration>
 
	</Configurations>
 
	<References>
 
@@ -311,33 +311,37 @@
 
		<Filter
 
			Name="Header Files"
 
			Filter="h;hpp;hxx;hm;inl"
 
			>
 
			<File
 
				RelativePath="base64.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath="HMAC_SHA1.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath="oauthlib.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath="SHA1.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath="twitcurl.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath=".\twitcurlurls.h"
 
				>
 
			</File>
 
			<File
 
				RelativePath="urlencode.h"
 
				>
 
			</File>
 
		</Filter>
 
	</Files>
 
	<Globals>
 
	</Globals>
 
</VisualStudioProject>
backends/twitter/libtwitcurl/twitcurlurls.h
Show inline comments
 
new file 100644
 
#ifndef _TWITCURLURLS_H_
 
#define _TWITCURLURLS_H_
 
 
#include <string>
 
#include <cstring>
 
 
/* Default values used in twitcurl */
 
namespace twitCurlDefaults
 
{
 
    /* Constants */
 
    const int TWITCURL_DEFAULT_BUFFSIZE = 1024;
 
    const std::string TWITCURL_COLON = ":";
 
    const char TWITCURL_EOS = '\0';
 
    const unsigned int MAX_TIMELINE_TWEET_COUNT = 200;
 
 
    /* Miscellaneous data used to build twitter URLs*/
 
    const std::string TWITCURL_STATUSSTRING = "status=";
 
    const std::string TWITCURL_TEXTSTRING = "text=";
 
    const std::string TWITCURL_QUERYSTRING = "query=";
 
    const std::string TWITCURL_SEARCHQUERYSTRING = "q=";
 
    const std::string TWITCURL_SCREENNAME = "screen_name=";
 
    const std::string TWITCURL_USERID = "user_id=";
 
    const std::string TWITCURL_EXTENSIONFORMATS[2] = { ".json",
 
                                                       ".xml"
 
                                                     };
 
    const std::string TWITCURL_PROTOCOLS[2] =        { "https://",
 
                                                       "http://"
 
                                                     };
 
    const std::string TWITCURL_TARGETSCREENNAME = "target_screen_name=";
 
    const std::string TWITCURL_TARGETUSERID = "target_id=";
 
    const std::string TWITCURL_SINCEID = "since_id=";
 
    const std::string TWITCURL_TRIMUSER = "trim_user=true";
 
    const std::string TWITCURL_INCRETWEETS = "include_rts=true";
 
    const std::string TWITCURL_COUNT = "count=";
 
    const std::string TWITCURL_NEXT_CURSOR = "cursor=";
 
    const std::string TWITCURL_SKIP_STATUS = "skip_status=";
 
    const std::string TWITCURL_INCLUDE_ENTITIES = "include_entities=";
 
    const std::string TWITCURL_STRINGIFY_IDS = "stringify_ids=";
 
    const std::string TWITCURL_INREPLYTOSTATUSID = "in_reply_to_status_id=";
 
 
    /* URL separators */
 
    const std::string TWITCURL_URL_SEP_AMP = "&";
 
    const std::string TWITCURL_URL_SEP_QUES = "?";
 
};
 
 
/* Default twitter URLs */
 
namespace twitterDefaults
 
{
 
    /* Base URL */
 
    const std::string TWITCURL_BASE_URL = "api.twitter.com/1.1/";
 
 
    /* Search URLs */
 
    const std::string TWITCURL_SEARCH_URL = TWITCURL_BASE_URL + "search/tweets";
 
 
    /* Status URLs */
 
    const std::string TWITCURL_STATUSUPDATE_URL = TWITCURL_BASE_URL + "statuses/update";
 
    const std::string TWITCURL_STATUSSHOW_URL = TWITCURL_BASE_URL + "statuses/show/";
 
    const std::string TWITCURL_STATUDESTROY_URL = TWITCURL_BASE_URL + "statuses/destroy/";
 
    const std::string TWITCURL_RETWEET_URL = TWITCURL_BASE_URL + "statuses/retweet/";
 
 
    /* Timeline URLs */
 
    const std::string TWITCURL_HOME_TIMELINE_URL = TWITCURL_BASE_URL + "statuses/home_timeline";
 
    const std::string TWITCURL_PUBLIC_TIMELINE_URL = TWITCURL_BASE_URL + "statuses/public_timeline";
 
    const std::string TWITCURL_FEATURED_USERS_URL = TWITCURL_BASE_URL + "statuses/featured";
 
    const std::string TWITCURL_FRIENDS_TIMELINE_URL = TWITCURL_BASE_URL + "statuses/friends_timeline";
 
    const std::string TWITCURL_MENTIONS_URL = TWITCURL_BASE_URL + "statuses/mentions";
 
    const std::string TWITCURL_USERTIMELINE_URL = TWITCURL_BASE_URL + "statuses/user_timeline";
 
 
    /* Users URLs */
 
    const std::string TWITCURL_LOOKUPUSERS_URL = TWITCURL_BASE_URL + "users/lookup";
 
    const std::string TWITCURL_SHOWUSERS_URL = TWITCURL_BASE_URL + "users/show";
 
    const std::string TWITCURL_SHOWFRIENDS_URL = TWITCURL_BASE_URL + "statuses/friends";
 
    const std::string TWITCURL_SHOWFOLLOWERS_URL = TWITCURL_BASE_URL + "statuses/followers";
 
 
    /* Direct messages URLs */
 
    const std::string TWITCURL_DIRECTMESSAGES_URL = TWITCURL_BASE_URL + "direct_messages";
 
    const std::string TWITCURL_DIRECTMESSAGENEW_URL = TWITCURL_BASE_URL + "direct_messages/new";
 
    const std::string TWITCURL_DIRECTMESSAGESSENT_URL = TWITCURL_BASE_URL + "direct_messages/sent";
 
    const std::string TWITCURL_DIRECTMESSAGEDESTROY_URL = TWITCURL_BASE_URL + "direct_messages/destroy/";
 
 
    /* Friendships URLs */
 
    const std::string TWITCURL_FRIENDSHIPSCREATE_URL = TWITCURL_BASE_URL + "friendships/create";
 
    const std::string TWITCURL_FRIENDSHIPSDESTROY_URL = TWITCURL_BASE_URL + "friendships/destroy";
 
    const std::string TWITCURL_FRIENDSHIPSSHOW_URL = TWITCURL_BASE_URL + "friendships/show";
 
 
    /* Social graphs URLs */
 
    const std::string TWITCURL_FRIENDSIDS_URL = TWITCURL_BASE_URL + "friends/ids";
 
    const std::string TWITCURL_FOLLOWERSIDS_URL = TWITCURL_BASE_URL + "followers/ids";
 
 
    /* Account URLs */
 
    const std::string TWITCURL_ACCOUNTRATELIMIT_URL = TWITCURL_BASE_URL + "account/rate_limit_status";
 
    const std::string TWITCURL_ACCOUNTVERIFYCRED_URL = TWITCURL_BASE_URL + "account/verify_credentials";
 
 
    /* Favorites URLs */
 
    const std::string TWITCURL_FAVORITESGET_URL = TWITCURL_BASE_URL + "favorites";
 
    const std::string TWITCURL_FAVORITECREATE_URL = TWITCURL_BASE_URL + "favorites/create/";
 
    const std::string TWITCURL_FAVORITEDESTROY_URL = TWITCURL_BASE_URL + "favorites/destroy/";
 
 
    /* Block URLs */
 
    const std::string TWITCURL_BLOCKSCREATE_URL = TWITCURL_BASE_URL + "blocks/create/";
 
    const std::string TWITCURL_BLOCKSDESTROY_URL = TWITCURL_BASE_URL + "blocks/destroy/";
 
    const std::string TWITCURL_BLOCKSLIST_URL = TWITCURL_BASE_URL + "blocks/list";
 
    const std::string TWITCURL_BLOCKSIDS_URL = TWITCURL_BASE_URL + "blocks/ids";
 
 
    /* Saved Search URLs */
 
    const std::string TWITCURL_SAVEDSEARCHGET_URL = TWITCURL_BASE_URL + "saved_searches";
 
    const std::string TWITCURL_SAVEDSEARCHSHOW_URL = TWITCURL_BASE_URL + "saved_searches/show/";
 
    const std::string TWITCURL_SAVEDSEARCHCREATE_URL = TWITCURL_BASE_URL + "saved_searches/create";
 
    const std::string TWITCURL_SAVEDSEARCHDESTROY_URL = TWITCURL_BASE_URL + "saved_searches/destroy/";
 
 
    /* Trends URLs */
 
    const std::string TWITCURL_TRENDS_URL = TWITCURL_BASE_URL + "trends";
 
    const std::string TWITCURL_TRENDSDAILY_URL = TWITCURL_BASE_URL + "trends/daily";
 
    const std::string TWITCURL_TRENDSCURRENT_URL = TWITCURL_BASE_URL + "trends/current";
 
    const std::string TWITCURL_TRENDSWEEKLY_URL = TWITCURL_BASE_URL + "trends/weekly";
 
    const std::string TWITCURL_TRENDSAVAILABLE_URL = TWITCURL_BASE_URL + "trends/available";
 
 
};
 
 
namespace oAuthLibDefaults
 
{
 
    /* Constants */
 
    const int OAUTHLIB_BUFFSIZE = 1024;
 
    const int OAUTHLIB_BUFFSIZE_LARGE = 1024;
 
    const std::string OAUTHLIB_CONSUMERKEY_KEY = "oauth_consumer_key";
 
    const std::string OAUTHLIB_CALLBACK_KEY = "oauth_callback";
 
    const std::string OAUTHLIB_VERSION_KEY = "oauth_version";
 
    const std::string OAUTHLIB_SIGNATUREMETHOD_KEY = "oauth_signature_method";
 
    const std::string OAUTHLIB_SIGNATURE_KEY = "oauth_signature";
 
    const std::string OAUTHLIB_TIMESTAMP_KEY = "oauth_timestamp";
 
    const std::string OAUTHLIB_NONCE_KEY = "oauth_nonce";
 
    const std::string OAUTHLIB_TOKEN_KEY = "oauth_token";
 
    const std::string OAUTHLIB_TOKENSECRET_KEY = "oauth_token_secret";
 
    const std::string OAUTHLIB_VERIFIER_KEY = "oauth_verifier";
 
    const std::string OAUTHLIB_SCREENNAME_KEY = "screen_name";
 
    const std::string OAUTHLIB_AUTHENTICITY_TOKEN_KEY = "authenticity_token";
 
    const std::string OAUTHLIB_SESSIONUSERNAME_KEY = "session[username_or_email]";
 
    const std::string OAUTHLIB_SESSIONPASSWORD_KEY = "session[password]";
 
    const std::string OAUTHLIB_AUTHENTICITY_TOKEN_TWITTER_RESP_KEY = "authenticity_token\" type=\"hidden\" value=\"";
 
    const std::string OAUTHLIB_TOKEN_TWITTER_RESP_KEY = "oauth_token\" type=\"hidden\" value=\"";
 
    const std::string OAUTHLIB_PIN_TWITTER_RESP_KEY = "code-desc\"><code>";
 
    const std::string OAUTHLIB_TOKEN_END_TAG_TWITTER_RESP = "\" />";
 
    const std::string OAUTHLIB_PIN_END_TAG_TWITTER_RESP = "</code>";
 
 
    const std::string OAUTHLIB_AUTHHEADER_STRING = "Authorization: OAuth ";
 
};
 
 
namespace oAuthTwitterApiUrls
 
{
 
    /* Twitter OAuth API URLs */
 
    const std::string OAUTHLIB_TWITTER_REQUEST_TOKEN_URL = "api.twitter.com/oauth/request_token";
 
    const std::string OAUTHLIB_TWITTER_AUTHORIZE_URL = "api.twitter.com/oauth/authorize?oauth_token=";
 
    const std::string OAUTHLIB_TWITTER_ACCESS_TOKEN_URL = "api.twitter.com/oauth/access_token";
 
};
 
 
#endif // _TWITCURLURLS_H_
backends/twitter/libtwitcurl/urlencode.cpp
Show inline comments
 
@@ -16,25 +16,25 @@ std::string char2hex( char dec )
 
}
 
 
std::string urlencode( const std::string &c )
 
{
 
 
    std::string escaped;
 
	int max = c.length();
 
	for(int i=0; i<max; i++)
 
	{
 
		if ( (48 <= c[i] && c[i] <= 57) ||//0-9
 
			(65 <= c[i] && c[i] <= 90) ||//ABC...XYZ
 
			(97 <= c[i] && c[i] <= 122) || //abc...xyz
 
			(c[i]=='~' || c[i]=='-' || c[i]=='_' || c[i]=='.')
 
			)
 
		{
 
			escaped.append( &c[i], 1);
 
		}
 
		else
 
		{
 
			escaped.append("%");
 
			escaped.append( char2hex(c[i]) );//converts char 255 to string "FF"
 
		}
 
	}
 
	return escaped;
 
}
 
}
 
\ No newline at end of file
backends/twitter/libtwitcurl/urlencode.h
Show inline comments
 
#ifndef __URLENCODE_H__
 
#define __URLENCODE_H__
 
 
#include <iostream>
 
#include <string>
 
 
std::string char2hex( char dec );
 
std::string urlencode( const std::string &c );
 
 
#endif // __URLENCODE_H__
 
#endif // __URLENCODE_H__
 
\ No newline at end of file
0 comments (0 inline, 0 general)