Changeset - a25edefbb83f
README.win32
Show inline comments
 
Prerequisites
 
=============
 
 
1. Microsoft Visual C++ 2010 Express or higher edition (http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-cpp-express)
 
2. Git for Windows (http://code.google.com/p/msysgit/downloads/list)
 
3. CMake 2.8 or newer (http://www.cmake.org/cmake/resources/software.html)
 
4. Python 2.x for Swiften build scripts (scons) (http://www.python.org)
 
 
Libraries
 
=========
 
3. Swiften library (http://swift.im/git/swift)
 
4. Boost 1.48 or newer (http://sourceforge.net/projects/boost/files/boost/1.49.0/)
 
5. Google ProtoBuf library (http://code.google.com/p/protobuf/downloads/list)
 
 
 
Environment
 
===========
 
 
To create spectrum build environment do:
 
 
0. Create directory where we'll install all dependencies, e.g. C:\env-msvc-x64.
 
Create C:\env-msvc-x64\bin and add it to %PATH%.
 
Assuming you have git, python and cmake in %PATH%, 
 
launch "Visual Studio 2010 command prompt" or
 
"Visual Studio 2010(x64) command prompt", depends on your target (Windows x86 or Windows x86_64).
 
1. unpack and build boost libraries:
 
 
	bootstrap.bat
 
	b2.exe --without-mpi --without-python
 
	b2.exe --without-mpi --without-python install --prefix=C:\env-msvc-x64 release
 
 
2. clone swift repository and build it. Don't forget to point it to our env directory:
 
 
	git clone git://swift.im/swift
 
	cd swift
 
	echo boost_includedir="c:/env-msvc-x64/include/boost-1_49" > config.py
 
	echo boost_libdir="c:/env-msvc-x64/lib" >> config.py 
 
	scons.bat debug=no SWIFTEN_INSTALLDIR=C:\env-msvc-x64 force_configure=1
 
	scons.bat debug=no SWIFTEN_INSTALLDIR=C:\env-msvc-x64 C:\env-msvc-x64
 
 
3. unpack and compile protobuf as described in its documentation. 
 
 
Run extract_includes.bat in vsprojects/ directory and move resulting vsprojects/include/google/ directory to our C:\env-msvc-x64\include
 
 
Move protoc.exe to C:\env-msvc-x64\bin\ and libprotobuf.lib to C:\env-msvc-x64\lib
 
 
4. Install gtkmm
 
 
Download installer from https://live.gnome.org/gtkmm/MSWindows and install gtkmm into C:\env-msvc-x64\
 
 
5. Install libpurple headers
 
 
Download http://www.pidgin.im/download/source/ , extract it and copy libpurple directory in C:\env-msvc-x64\include
 
 
6. You're ready! :) Clone libtransport into C:\env-msvc-x64\libtransport (You *must* clone it into this directory, because libtransport will try to find the dependencies in ../lib and ../include)
 
 
Compile it as:
 
 
	set CMAKE_INCLUDE_PATH=C:\env-msvc-x64\include
 
	cmake . -G "NMake Makefiles" -DBOOST_INCLUDEDIR=../include/boost-1_49 -DBOOST_LIBRARYDIR=../lib -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=C:\env-msvc-x64 -DGIT_EXECUTABLE="c:\Program Files (x86)\git\bin\git.exe"
 
	nmake
 
Prerequisites
 
=============
 

	
 
1. Microsoft Visual C++ 2010 Express or higher edition (http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-cpp-express)
 
2. Git for Windows (http://code.google.com/p/msysgit/downloads/list)
 
3. CMake 2.8 or newer (http://www.cmake.org/cmake/resources/software.html)
 
4. Python 2.x for Swiften build scripts (scons) (http://www.python.org)
 

	
 
Libraries
 
=========
 
3. Swiften library (http://swift.im/git/swift)
 
4. Boost 1.48 or newer (http://sourceforge.net/projects/boost/files/boost/1.49.0/)
 
5. Google ProtoBuf library (http://code.google.com/p/protobuf/downloads/list)
 

	
 

	
 
Environment
 
===========
 

	
 
To create spectrum build environment do:
 

	
 
0. Create directory where we'll install all dependencies, e.g. C:\env-msvc-x64.
 
Create C:\env-msvc-x64\bin and add it to %PATH%.
 
Assuming you have git, python and cmake in %PATH%, 
 
launch "Visual Studio 2010 command prompt" or
 
"Visual Studio 2010(x64) command prompt", depends on your target (Windows x86 or Windows x86_64).
 
1. unpack and build boost libraries:
 

	
 
	bootstrap.bat
 
	b2.exe --without-mpi --without-python
 
	b2.exe --without-mpi --without-python install --prefix=C:\env-msvc-x64 release
 

	
 
2. clone swift repository and build it. Don't forget to point it to our env directory:
 

	
 
	git clone git://swift.im/swift
 
	cd swift
 
	echo boost_includedir="c:/env-msvc-x64/include/boost-1_49" > config.py
 
	echo boost_libdir="c:/env-msvc-x64/lib" >> config.py 
 
	scons.bat debug=no SWIFTEN_INSTALLDIR=C:\env-msvc-x64 force_configure=1
 
	scons.bat debug=no SWIFTEN_INSTALLDIR=C:\env-msvc-x64 C:\env-msvc-x64
 

	
 
3. unpack and compile protobuf as described in its documentation. 
 

	
 
Run extract_includes.bat in vsprojects/ directory and move resulting vsprojects/include/google/ directory to our C:\env-msvc-x64\include
 

	
 
Move protoc.exe to C:\env-msvc-x64\bin\ and libprotobuf.lib to C:\env-msvc-x64\lib
 

	
 
4. Install gtkmm
 

	
 
Download installer from https://live.gnome.org/gtkmm/MSWindows and install gtkmm into C:\env-msvc-x64\
 

	
 
5. Install libpurple headers
 

	
 
Download http://www.pidgin.im/download/source/ , extract it and copy libpurple directory in C:\env-msvc-x64\include
 

	
 
6. You're ready! :) Clone libtransport into C:\env-msvc-x64\libtransport (You *must* clone it into this directory, because libtransport will try to find the dependencies in ../lib and ../include)
 

	
 
Compile it as:
 

	
 
	set CMAKE_INCLUDE_PATH=C:\env-msvc-x64\include
 
	cmake . -G "NMake Makefiles" -DBOOST_INCLUDEDIR=../include/boost-1_49 -DBOOST_LIBRARYDIR=../lib -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=C:\env-msvc-x64 -DGIT_EXECUTABLE="c:\Program Files (x86)\git\bin\git.exe"
 
	nmake
backends/frotz/CMakeLists.txt
Show inline comments
 
cmake_minimum_required(VERSION 2.6)
 
 
ADD_SUBDIRECTORY(dfrotz)
 
 
FILE(GLOB SRC *.c *.cpp)
 
 
ADD_EXECUTABLE(spectrum2_frotz_backend ${SRC})
 
 
target_link_libraries(spectrum2_frotz_backend transport pthread ${Boost_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES})
 
 
INSTALL(TARGETS spectrum2_frotz_backend RUNTIME DESTINATION bin)
 
 
cmake_minimum_required(VERSION 2.6)
 

	
 
ADD_SUBDIRECTORY(dfrotz)
 

	
 
FILE(GLOB SRC *.c *.cpp)
 

	
 
ADD_EXECUTABLE(spectrum2_frotz_backend ${SRC})
 

	
 
target_link_libraries(spectrum2_frotz_backend transport pthread ${Boost_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES})
 

	
 
INSTALL(TARGETS spectrum2_frotz_backend RUNTIME DESTINATION bin)
 

	
backends/frotz/dfrotz/CMakeLists.txt
Show inline comments
 
cmake_minimum_required(VERSION 2.6)
 
FILE(GLOB SRC common/*.c dumb/*.c)
 
 
ADD_EXECUTABLE(dfrotz ${SRC})
 
 
# target_link_libraries(dfrotz)
 
 
INSTALL(TARGETS dfrotz RUNTIME DESTINATION bin)
 
 
cmake_minimum_required(VERSION 2.6)
 
FILE(GLOB SRC common/*.c dumb/*.c)
 

	
 
ADD_EXECUTABLE(dfrotz ${SRC})
 

	
 
# target_link_libraries(dfrotz)
 

	
 
INSTALL(TARGETS dfrotz RUNTIME DESTINATION bin)
 

	
backends/libcommuni/CMakeLists.txt
Show inline comments
 
cmake_minimum_required(VERSION 2.6)
 
FILE(GLOB SRC *.cpp)
 
FILE(GLOB HEADERS *.h)
 
QT4_WRAP_CPP(SRC ${HEADERS} OPTIONS -DBOOST_TT_HAS_OPERATOR_HPP_INCLUDED)
 
ADD_EXECUTABLE(spectrum2_libcommuni_backend ${SRC})
 
 
if (NOT WIN32)
 
	target_link_libraries(spectrum2_libcommuni_backend ${IRC_LIBRARY} ${QT_LIBRARIES} transport pthread)
 
else ()
 
	target_link_libraries(spectrum2_libcommuni_backend ${IRC_LIBRARY} ${QT_LIBRARIES} transport)
 
endif()
 
INSTALL(TARGETS spectrum2_libcommuni_backend RUNTIME DESTINATION bin)
 
 
cmake_minimum_required(VERSION 2.6)
 
FILE(GLOB SRC *.cpp)
 
FILE(GLOB HEADERS *.h)
 
QT4_WRAP_CPP(SRC ${HEADERS} OPTIONS -DBOOST_TT_HAS_OPERATOR_HPP_INCLUDED)
 
ADD_EXECUTABLE(spectrum2_libcommuni_backend ${SRC})
 

	
 
if (NOT WIN32)
 
	target_link_libraries(spectrum2_libcommuni_backend ${IRC_LIBRARY} ${QT_LIBRARIES} transport pthread)
 
else ()
 
	target_link_libraries(spectrum2_libcommuni_backend ${IRC_LIBRARY} ${QT_LIBRARIES} transport)
 
endif()
 
INSTALL(TARGETS spectrum2_libcommuni_backend RUNTIME DESTINATION bin)
 

	
backends/libpurple/CMakeLists.txt
Show inline comments
 
cmake_minimum_required(VERSION 2.6)
 
FILE(GLOB SRC *.cpp)
 
 
ADD_EXECUTABLE(spectrum2_libpurple_backend ${SRC})
 
 
if(CMAKE_COMPILER_IS_GNUCXX)
 
	if (NOT WIN32)
 
	target_link_libraries(spectrum2_libpurple_backend ${PURPLE_LIBRARY} ${GLIB2_LIBRARIES} ${EVENT_LIBRARIES} transport-plugin pthread)
 
	else()
 
	target_link_libraries(spectrum2_libpurple_backend ${PURPLE_LIBRARY} ${GLIB2_LIBRARIES} ${EVENT_LIBRARIES} transport-plugin)
 
	endif()
 
else()
 
target_link_libraries(spectrum2_libpurple_backend sqlite3 ${PURPLE_LIBRARY} ${GLIB2_LIBRARIES} ${LIBXML2_LIBRARIES} ${EVENT_LIBRARIES} transport-plugin ${PROTOBUF_LIBRARY})
 
endif()
 
 
INSTALL(TARGETS spectrum2_libpurple_backend RUNTIME DESTINATION bin)
 
 
cmake_minimum_required(VERSION 2.6)
 
FILE(GLOB SRC *.cpp)
 

	
 
ADD_EXECUTABLE(spectrum2_libpurple_backend ${SRC})
 

	
 
if(CMAKE_COMPILER_IS_GNUCXX)
 
	if (NOT WIN32)
 
	target_link_libraries(spectrum2_libpurple_backend ${PURPLE_LIBRARY} ${GLIB2_LIBRARIES} ${EVENT_LIBRARIES} transport-plugin pthread)
 
	else()
 
	target_link_libraries(spectrum2_libpurple_backend ${PURPLE_LIBRARY} ${GLIB2_LIBRARIES} ${EVENT_LIBRARIES} transport-plugin)
 
	endif()
 
else()
 
target_link_libraries(spectrum2_libpurple_backend sqlite3 ${PURPLE_LIBRARY} ${GLIB2_LIBRARIES} ${LIBXML2_LIBRARIES} ${EVENT_LIBRARIES} transport-plugin ${PROTOBUF_LIBRARY})
 
endif()
 

	
 
INSTALL(TARGETS spectrum2_libpurple_backend RUNTIME DESTINATION bin)
 

	
backends/libyahoo2/CMakeLists.txt
Show inline comments
 
cmake_minimum_required(VERSION 2.6)
 
 
FILE(GLOB_RECURSE SRC *.c *.cpp)
 
 
ADD_DEFINITIONS(-DHAVE_STDINT_H=1)
 
 
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/yahoo)
 
 
ADD_EXECUTABLE(spectrum2_libyahoo2_backend ${SRC})
 
 
target_link_libraries(spectrum2_libyahoo2_backend transport pthread ${Boost_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES})
 
 
INSTALL(TARGETS spectrum2_libyahoo2_backend RUNTIME DESTINATION bin)
 
 
cmake_minimum_required(VERSION 2.6)
 

	
 
FILE(GLOB_RECURSE SRC *.c *.cpp)
 

	
 
ADD_DEFINITIONS(-DHAVE_STDINT_H=1)
 

	
 
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/yahoo)
 

	
 
ADD_EXECUTABLE(spectrum2_libyahoo2_backend ${SRC})
 

	
 
target_link_libraries(spectrum2_libyahoo2_backend transport pthread ${Boost_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES})
 

	
 
INSTALL(TARGETS spectrum2_libyahoo2_backend RUNTIME DESTINATION bin)
 

	
backends/skype/CMakeLists.txt
Show inline comments
 
cmake_minimum_required(VERSION 2.6)
 
FILE(GLOB SRC *.cpp)
 
 
ADD_EXECUTABLE(spectrum2_skype_backend ${SRC})
 
 
target_link_libraries(spectrum2_skype_backend ${GLIB2_LIBRARIES} ${EVENT_LIBRARIES} transport pthread ${LIBDBUSGLIB_LIBRARIES})
 
 
INSTALL(TARGETS spectrum2_skype_backend RUNTIME DESTINATION bin)
 
 
cmake_minimum_required(VERSION 2.6)
 
FILE(GLOB SRC *.cpp)
 

	
 
ADD_EXECUTABLE(spectrum2_skype_backend ${SRC})
 

	
 
target_link_libraries(spectrum2_skype_backend ${GLIB2_LIBRARIES} ${EVENT_LIBRARIES} transport pthread ${LIBDBUSGLIB_LIBRARIES})
 

	
 
INSTALL(TARGETS spectrum2_skype_backend RUNTIME DESTINATION bin)
 

	
backends/smstools3/CMakeLists.txt
Show inline comments
 
cmake_minimum_required(VERSION 2.6)
 
 
FILE(GLOB SRC *.c *.cpp)
 
 
ADD_EXECUTABLE(spectrum2_smstools3_backend ${SRC})
 
 
target_link_libraries(spectrum2_smstools3_backend transport pthread ${Boost_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES})
 
 
INSTALL(TARGETS spectrum2_smstools3_backend RUNTIME DESTINATION bin)
 
 
cmake_minimum_required(VERSION 2.6)
 

	
 
FILE(GLOB SRC *.c *.cpp)
 

	
 
ADD_EXECUTABLE(spectrum2_smstools3_backend ${SRC})
 

	
 
target_link_libraries(spectrum2_smstools3_backend transport pthread ${Boost_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES})
 

	
 
INSTALL(TARGETS spectrum2_smstools3_backend RUNTIME DESTINATION bin)
 

	
backends/swiften/CMakeLists.txt
Show inline comments
 
cmake_minimum_required(VERSION 2.6)
 
 
FILE(GLOB SRC *.cpp)
 
 
ADD_EXECUTABLE(spectrum2_swiften_backend ${SRC})
 
 
IF (NOT WIN32)
 
target_link_libraries(spectrum2_swiften_backend transport pthread ${Boost_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES})
 
else()
 
target_link_libraries(spectrum2_swiften_backend transport ${Boost_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES})
 
endif()
 
 
INSTALL(TARGETS spectrum2_swiften_backend RUNTIME DESTINATION bin)
 
 
cmake_minimum_required(VERSION 2.6)
 

	
 
FILE(GLOB SRC *.cpp)
 

	
 
ADD_EXECUTABLE(spectrum2_swiften_backend ${SRC})
 

	
 
IF (NOT WIN32)
 
target_link_libraries(spectrum2_swiften_backend transport pthread ${Boost_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES})
 
else()
 
target_link_libraries(spectrum2_swiften_backend transport ${Boost_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES})
 
endif()
 

	
 
INSTALL(TARGETS spectrum2_swiften_backend RUNTIME DESTINATION bin)
 

	
backends/template/CMakeLists.txt
Show inline comments
 
cmake_minimum_required(VERSION 2.6)
 
 
FILE(GLOB SRC *.c *.cpp)
 
 
ADD_EXECUTABLE(spectrum2_template_backend ${SRC})
 
 
if (CMAKE_COMPILER_IS_GNUCXX)
 
if (NOT WIN32)
 
target_link_libraries(spectrum2_template_backend transport pthread ${Boost_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES})
 
else()
 
target_link_libraries(spectrum2_template_backend transport ${Boost_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES})
 
endif()
 
else()
 
target_link_libraries(spectrum2_template_backend transport ${PROTOBUF_LIBRARY} ${Boost_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES})
 
endif()
 
 
#INSTALL(TARGETS spectrum2_template_backend RUNTIME DESTINATION bin)
 
 
cmake_minimum_required(VERSION 2.6)
 

	
 
FILE(GLOB SRC *.c *.cpp)
 

	
 
ADD_EXECUTABLE(spectrum2_template_backend ${SRC})
 

	
 
if (CMAKE_COMPILER_IS_GNUCXX)
 
if (NOT WIN32)
 
target_link_libraries(spectrum2_template_backend transport pthread ${Boost_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES})
 
else()
 
target_link_libraries(spectrum2_template_backend transport ${Boost_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES})
 
endif()
 
else()
 
target_link_libraries(spectrum2_template_backend transport ${PROTOBUF_LIBRARY} ${Boost_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES})
 
endif()
 

	
 
#INSTALL(TARGETS spectrum2_template_backend RUNTIME DESTINATION bin)
 

	
backends/twitter/libtwitcurl/HMAC_SHA1.cpp
Show inline comments
 
//******************************************************************************
 
//* HMAC_SHA1.cpp : Implementation of HMAC SHA1 algorithm
 
//*                 Comfort to RFC 2104
 
//*
 
//******************************************************************************
 
#include "HMAC_SHA1.h"
 
#include <iostream>
 
#include <memory>
 
 
 
void CHMAC_SHA1::HMAC_SHA1(BYTE *text, int text_len, BYTE *key, int key_len, BYTE *digest)
 
{
 
	memset(SHA1_Key, 0, SHA1_BLOCK_SIZE);
 
 
	/* repeated 64 times for values in ipad and opad */
 
	memset(m_ipad, 0x36, sizeof(m_ipad));
 
	memset(m_opad, 0x5c, sizeof(m_opad));
 
 
	/* STEP 1 */
 
	if (key_len > SHA1_BLOCK_SIZE)
 
	{
 
		CSHA1::Reset();
 
		CSHA1::Update((UINT_8 *)key, key_len);
 
		CSHA1::Final();
 
 
		CSHA1::GetHash((UINT_8 *)SHA1_Key);
 
	}
 
	else
 
		memcpy(SHA1_Key, key, key_len);
 
 
	/* STEP 2 */
 
	for (size_t i=0; i<sizeof(m_ipad); i++)
 
	{
 
		m_ipad[i] ^= SHA1_Key[i];		
 
	}
 
 
	/* STEP 3 */
 
	memcpy(AppendBuf1, m_ipad, sizeof(m_ipad));
 
	memcpy(AppendBuf1 + sizeof(m_ipad), text, text_len);
 
 
	/* STEP 4 */
 
	CSHA1::Reset();
 
	CSHA1::Update((UINT_8 *)AppendBuf1, sizeof(m_ipad) + text_len);
 
	CSHA1::Final();
 
 
	CSHA1::GetHash((UINT_8 *)szReport);
 
 
	/* STEP 5 */
 
	for (size_t j=0; j<sizeof(m_opad); j++)
 
	{
 
		m_opad[j] ^= SHA1_Key[j];
 
	}
 
 
	/* STEP 6 */
 
	memcpy(AppendBuf2, m_opad, sizeof(m_opad));
 
	memcpy(AppendBuf2 + sizeof(m_opad), szReport, SHA1_DIGEST_LENGTH);
 
 
	/*STEP 7 */
 
	CSHA1::Reset();
 
	CSHA1::Update((UINT_8 *)AppendBuf2, sizeof(m_opad) + SHA1_DIGEST_LENGTH);
 
	CSHA1::Final();
 
 
	CSHA1::GetHash((UINT_8 *)digest);
 
}
 
//******************************************************************************
 
//* HMAC_SHA1.cpp : Implementation of HMAC SHA1 algorithm
 
//*                 Comfort to RFC 2104
 
//*
 
//******************************************************************************
 
#include "HMAC_SHA1.h"
 
#include <iostream>
 
#include <memory>
 

	
 

	
 
void CHMAC_SHA1::HMAC_SHA1(BYTE *text, int text_len, BYTE *key, int key_len, BYTE *digest)
 
{
 
	memset(SHA1_Key, 0, SHA1_BLOCK_SIZE);
 

	
 
	/* repeated 64 times for values in ipad and opad */
 
	memset(m_ipad, 0x36, sizeof(m_ipad));
 
	memset(m_opad, 0x5c, sizeof(m_opad));
 

	
 
	/* STEP 1 */
 
	if (key_len > SHA1_BLOCK_SIZE)
 
	{
 
		CSHA1::Reset();
 
		CSHA1::Update((UINT_8 *)key, key_len);
 
		CSHA1::Final();
 

	
 
		CSHA1::GetHash((UINT_8 *)SHA1_Key);
 
	}
 
	else
 
		memcpy(SHA1_Key, key, key_len);
 

	
 
	/* STEP 2 */
 
	for (size_t i=0; i<sizeof(m_ipad); i++)
 
	{
 
		m_ipad[i] ^= SHA1_Key[i];		
 
	}
 

	
 
	/* STEP 3 */
 
	memcpy(AppendBuf1, m_ipad, sizeof(m_ipad));
 
	memcpy(AppendBuf1 + sizeof(m_ipad), text, text_len);
 

	
 
	/* STEP 4 */
 
	CSHA1::Reset();
 
	CSHA1::Update((UINT_8 *)AppendBuf1, sizeof(m_ipad) + text_len);
 
	CSHA1::Final();
 

	
 
	CSHA1::GetHash((UINT_8 *)szReport);
 

	
 
	/* STEP 5 */
 
	for (size_t j=0; j<sizeof(m_opad); j++)
 
	{
 
		m_opad[j] ^= SHA1_Key[j];
 
	}
 

	
 
	/* STEP 6 */
 
	memcpy(AppendBuf2, m_opad, sizeof(m_opad));
 
	memcpy(AppendBuf2 + sizeof(m_opad), szReport, SHA1_DIGEST_LENGTH);
 

	
 
	/*STEP 7 */
 
	CSHA1::Reset();
 
	CSHA1::Update((UINT_8 *)AppendBuf2, sizeof(m_opad) + SHA1_DIGEST_LENGTH);
 
	CSHA1::Final();
 

	
 
	CSHA1::GetHash((UINT_8 *)digest);
 
}
backends/twitter/libtwitcurl/HMAC_SHA1.h
Show inline comments
 
/*
 
	100% free public domain implementation of the HMAC-SHA1 algorithm
 
	by Chien-Chung, Chung (Jim Chung) <jimchung1221@gmail.com>
 
*/
 
 
 
#ifndef __HMAC_SHA1_H__
 
#define __HMAC_SHA1_H__
 
 
#include "SHA1.h"
 
 
typedef unsigned char BYTE ;
 
 
class CHMAC_SHA1 : public CSHA1
 
{
 
    private:
 
		BYTE m_ipad[64];
 
        BYTE m_opad[64];
 
 
		char * szReport ;
 
		char * SHA1_Key ;
 
		char * AppendBuf1 ;
 
		char * AppendBuf2 ;
 
 
 
	public:
 
		
 
		enum {
 
			SHA1_DIGEST_LENGTH	= 20,
 
			SHA1_BLOCK_SIZE		= 64,
 
			HMAC_BUF_LEN		= 4096
 
		} ;
 
 
		CHMAC_SHA1()
 
			:szReport(new char[HMAC_BUF_LEN]),
 
             SHA1_Key(new char[HMAC_BUF_LEN]),
 
             AppendBuf1(new char[HMAC_BUF_LEN]),
 
             AppendBuf2(new char[HMAC_BUF_LEN])
 
		{}
 
 
        ~CHMAC_SHA1()
 
        {
 
            delete[] szReport ;
 
            delete[] AppendBuf1 ;
 
            delete[] AppendBuf2 ;
 
            delete[] SHA1_Key ;
 
        }
 
 
        void HMAC_SHA1(BYTE *text, int text_len, BYTE *key, int key_len, BYTE *digest);
 
};
 
 
 
#endif /* __HMAC_SHA1_H__ */
 
/*
 
	100% free public domain implementation of the HMAC-SHA1 algorithm
 
	by Chien-Chung, Chung (Jim Chung) <jimchung1221@gmail.com>
 
*/
 

	
 

	
 
#ifndef __HMAC_SHA1_H__
 
#define __HMAC_SHA1_H__
 

	
 
#include "SHA1.h"
 

	
 
typedef unsigned char BYTE ;
 

	
 
class CHMAC_SHA1 : public CSHA1
 
{
 
    private:
 
		BYTE m_ipad[64];
 
        BYTE m_opad[64];
 

	
 
		char * szReport ;
 
		char * SHA1_Key ;
 
		char * AppendBuf1 ;
 
		char * AppendBuf2 ;
 

	
 

	
 
	public:
 
		
 
		enum {
 
			SHA1_DIGEST_LENGTH	= 20,
 
			SHA1_BLOCK_SIZE		= 64,
 
			HMAC_BUF_LEN		= 4096
 
		} ;
 

	
 
		CHMAC_SHA1()
 
			:szReport(new char[HMAC_BUF_LEN]),
 
             SHA1_Key(new char[HMAC_BUF_LEN]),
 
             AppendBuf1(new char[HMAC_BUF_LEN]),
 
             AppendBuf2(new char[HMAC_BUF_LEN])
 
		{}
 

	
 
        ~CHMAC_SHA1()
 
        {
 
            delete[] szReport ;
 
            delete[] AppendBuf1 ;
 
            delete[] AppendBuf2 ;
 
            delete[] SHA1_Key ;
 
        }
 

	
 
        void HMAC_SHA1(BYTE *text, int text_len, BYTE *key, int key_len, BYTE *digest);
 
};
 

	
 

	
 
#endif /* __HMAC_SHA1_H__ */
backends/twitter/libtwitcurl/SHA1.cpp
Show inline comments
 
/*
 
	100% free public domain implementation of the SHA-1 algorithm
 
	by Dominik Reichl <dominik.reichl@t-online.de>
 
	Web: http://www.dominik-reichl.de/
 
 
	Version 1.6 - 2005-02-07 (thanks to Howard Kapustein for patches)
 
	- You can set the endianness in your files, no need to modify the
 
	  header file of the CSHA1 class any more
 
	- Aligned data support
 
	- Made support/compilation of the utility functions (ReportHash
 
	  and HashFile) optional (useful, if bytes count, for example in
 
	  embedded environments)
 
 
	Version 1.5 - 2005-01-01
 
	- 64-bit compiler compatibility added
 
	- Made variable wiping optional (define SHA1_WIPE_VARIABLES)
 
	- Removed unnecessary variable initializations
 
	- ROL32 improvement for the Microsoft compiler (using _rotl)
 
 
	======== Test Vectors (from FIPS PUB 180-1) ========
 
 
	SHA1("abc") =
 
		A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D
 
 
	SHA1("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq") =
 
		84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1
 
 
	SHA1(A million repetitions of "a") =
 
		34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F
 
*/
 
 
#include "SHA1.h"
 
 
#ifdef SHA1_UTILITY_FUNCTIONS
 
#define SHA1_MAX_FILE_BUFFER 8000
 
#endif
 
 
// Rotate x bits to the left
 
#ifndef ROL32
 
#ifdef _MSC_VER
 
#define ROL32(_val32, _nBits) _rotl(_val32, _nBits)
 
#else
 
#define ROL32(_val32, _nBits) (((_val32)<<(_nBits))|((_val32)>>(32-(_nBits))))
 
#endif
 
#endif
 
 
#ifdef SHA1_LITTLE_ENDIAN
 
#define SHABLK0(i) (m_block->l[i] = \
 
	(ROL32(m_block->l[i],24) & 0xFF00FF00) | (ROL32(m_block->l[i],8) & 0x00FF00FF))
 
#else
 
#define SHABLK0(i) (m_block->l[i])
 
#endif
 
 
#define SHABLK(i) (m_block->l[i&15] = ROL32(m_block->l[(i+13)&15] ^ m_block->l[(i+8)&15] \
 
	^ m_block->l[(i+2)&15] ^ m_block->l[i&15],1))
 
 
// SHA-1 rounds
 
#define _R0(v,w,x,y,z,i) { z+=((w&(x^y))^y)+SHABLK0(i)+0x5A827999+ROL32(v,5); w=ROL32(w,30); }
 
#define _R1(v,w,x,y,z,i) { z+=((w&(x^y))^y)+SHABLK(i)+0x5A827999+ROL32(v,5); w=ROL32(w,30); }
 
#define _R2(v,w,x,y,z,i) { z+=(w^x^y)+SHABLK(i)+0x6ED9EBA1+ROL32(v,5); w=ROL32(w,30); }
 
#define _R3(v,w,x,y,z,i) { z+=(((w|x)&y)|(w&x))+SHABLK(i)+0x8F1BBCDC+ROL32(v,5); w=ROL32(w,30); }
 
#define _R4(v,w,x,y,z,i) { z+=(w^x^y)+SHABLK(i)+0xCA62C1D6+ROL32(v,5); w=ROL32(w,30); }
 
 
CSHA1::CSHA1()
 
{
 
	m_block = (SHA1_WORKSPACE_BLOCK *)m_workspace;
 
 
	Reset();
 
}
 
 
CSHA1::~CSHA1()
 
{
 
	Reset();
 
}
 
 
void CSHA1::Reset()
 
{
 
	// SHA1 initialization constants
 
	m_state[0] = 0x67452301;
 
	m_state[1] = 0xEFCDAB89;
 
	m_state[2] = 0x98BADCFE;
 
	m_state[3] = 0x10325476;
 
	m_state[4] = 0xC3D2E1F0;
 
 
	m_count[0] = 0;
 
	m_count[1] = 0;
 
}
 
 
void CSHA1::Transform(UINT_32 *state, UINT_8 *buffer)
 
{
 
	// Copy state[] to working vars
 
	UINT_32 a = state[0], b = state[1], c = state[2], d = state[3], e = state[4];
 
 
	memcpy(m_block, buffer, 64);
 
 
	// 4 rounds of 20 operations each. Loop unrolled.
 
	_R0(a,b,c,d,e, 0); _R0(e,a,b,c,d, 1); _R0(d,e,a,b,c, 2); _R0(c,d,e,a,b, 3);
 
	_R0(b,c,d,e,a, 4); _R0(a,b,c,d,e, 5); _R0(e,a,b,c,d, 6); _R0(d,e,a,b,c, 7);
 
	_R0(c,d,e,a,b, 8); _R0(b,c,d,e,a, 9); _R0(a,b,c,d,e,10); _R0(e,a,b,c,d,11);
 
	_R0(d,e,a,b,c,12); _R0(c,d,e,a,b,13); _R0(b,c,d,e,a,14); _R0(a,b,c,d,e,15);
 
	_R1(e,a,b,c,d,16); _R1(d,e,a,b,c,17); _R1(c,d,e,a,b,18); _R1(b,c,d,e,a,19);
 
	_R2(a,b,c,d,e,20); _R2(e,a,b,c,d,21); _R2(d,e,a,b,c,22); _R2(c,d,e,a,b,23);
 
	_R2(b,c,d,e,a,24); _R2(a,b,c,d,e,25); _R2(e,a,b,c,d,26); _R2(d,e,a,b,c,27);
 
	_R2(c,d,e,a,b,28); _R2(b,c,d,e,a,29); _R2(a,b,c,d,e,30); _R2(e,a,b,c,d,31);
 
	_R2(d,e,a,b,c,32); _R2(c,d,e,a,b,33); _R2(b,c,d,e,a,34); _R2(a,b,c,d,e,35);
 
	_R2(e,a,b,c,d,36); _R2(d,e,a,b,c,37); _R2(c,d,e,a,b,38); _R2(b,c,d,e,a,39);
 
	_R3(a,b,c,d,e,40); _R3(e,a,b,c,d,41); _R3(d,e,a,b,c,42); _R3(c,d,e,a,b,43);
 
	_R3(b,c,d,e,a,44); _R3(a,b,c,d,e,45); _R3(e,a,b,c,d,46); _R3(d,e,a,b,c,47);
 
	_R3(c,d,e,a,b,48); _R3(b,c,d,e,a,49); _R3(a,b,c,d,e,50); _R3(e,a,b,c,d,51);
 
	_R3(d,e,a,b,c,52); _R3(c,d,e,a,b,53); _R3(b,c,d,e,a,54); _R3(a,b,c,d,e,55);
 
	_R3(e,a,b,c,d,56); _R3(d,e,a,b,c,57); _R3(c,d,e,a,b,58); _R3(b,c,d,e,a,59);
 
	_R4(a,b,c,d,e,60); _R4(e,a,b,c,d,61); _R4(d,e,a,b,c,62); _R4(c,d,e,a,b,63);
 
	_R4(b,c,d,e,a,64); _R4(a,b,c,d,e,65); _R4(e,a,b,c,d,66); _R4(d,e,a,b,c,67);
 
	_R4(c,d,e,a,b,68); _R4(b,c,d,e,a,69); _R4(a,b,c,d,e,70); _R4(e,a,b,c,d,71);
 
	_R4(d,e,a,b,c,72); _R4(c,d,e,a,b,73); _R4(b,c,d,e,a,74); _R4(a,b,c,d,e,75);
 
	_R4(e,a,b,c,d,76); _R4(d,e,a,b,c,77); _R4(c,d,e,a,b,78); _R4(b,c,d,e,a,79);
 
 
	// Add the working vars back into state
 
	state[0] += a;
 
	state[1] += b;
 
	state[2] += c;
 
	state[3] += d;
 
	state[4] += e;
 
 
	// Wipe variables
 
#ifdef SHA1_WIPE_VARIABLES
 
	a = b = c = d = e = 0;
 
#endif
 
}
 
 
// Use this function to hash in binary data and strings
 
void CSHA1::Update(UINT_8 *data, UINT_32 len)
 
{
 
	UINT_32 i, j;
 
 
	j = (m_count[0] >> 3) & 63;
 
 
	if((m_count[0] += len << 3) < (len << 3)) m_count[1]++;
 
 
	m_count[1] += (len >> 29);
 
 
	if((j + len) > 63)
 
	{
 
		i = 64 - j;
 
		memcpy(&m_buffer[j], data, i);
 
		Transform(m_state, m_buffer);
 
 
		for(; i + 63 < len; i += 64) Transform(m_state, &data[i]);
 
 
		j = 0;
 
	}
 
	else i = 0;
 
 
	memcpy(&m_buffer[j], &data[i], len - i);
 
}
 
 
#ifdef SHA1_UTILITY_FUNCTIONS
 
// Hash in file contents
 
bool CSHA1::HashFile(char *szFileName)
 
{
 
	unsigned long ulFileSize, ulRest, ulBlocks;
 
	unsigned long i;
 
	UINT_8 uData[SHA1_MAX_FILE_BUFFER];
 
	FILE *fIn;
 
 
	if(szFileName == NULL) return false;
 
 
	fIn = fopen(szFileName, "rb");
 
	if(fIn == NULL) return false;
 
 
	fseek(fIn, 0, SEEK_END);
 
	ulFileSize = (unsigned long)ftell(fIn);
 
	fseek(fIn, 0, SEEK_SET);
 
 
	if(ulFileSize != 0)
 
	{
 
		ulBlocks = ulFileSize / SHA1_MAX_FILE_BUFFER;
 
		ulRest = ulFileSize % SHA1_MAX_FILE_BUFFER;
 
	}
 
	else
 
	{
 
		ulBlocks = 0;
 
		ulRest = 0;
 
	}
 
 
	for(i = 0; i < ulBlocks; i++)
 
	{
 
		fread(uData, 1, SHA1_MAX_FILE_BUFFER, fIn);
 
		Update((UINT_8 *)uData, SHA1_MAX_FILE_BUFFER);
 
	}
 
 
	if(ulRest != 0)
 
	{
 
		fread(uData, 1, ulRest, fIn);
 
		Update((UINT_8 *)uData, ulRest);
 
	}
 
 
	fclose(fIn); fIn = NULL;
 
	return true;
 
}
 
#endif
 
 
void CSHA1::Final()
 
{
 
	UINT_32 i;
 
	UINT_8 finalcount[8];
 
 
	for(i = 0; i < 8; i++)
 
		finalcount[i] = (UINT_8)((m_count[((i >= 4) ? 0 : 1)]
 
			>> ((3 - (i & 3)) * 8) ) & 255); // Endian independent
 
 
	Update((UINT_8 *)"\200", 1);
 
 
	while ((m_count[0] & 504) != 448)
 
		Update((UINT_8 *)"\0", 1);
 
 
	Update(finalcount, 8); // Cause a SHA1Transform()
 
 
	for(i = 0; i < 20; i++)
 
	{
 
		m_digest[i] = (UINT_8)((m_state[i >> 2] >> ((3 - (i & 3)) * 8) ) & 255);
 
	}
 
 
	// Wipe variables for security reasons
 
#ifdef SHA1_WIPE_VARIABLES
 
	i = 0;
 
	memset(m_buffer, 0, 64);
 
	memset(m_state, 0, 20);
 
	memset(m_count, 0, 8);
 
	memset(finalcount, 0, 8);
 
	Transform(m_state, m_buffer);
 
#endif
 
}
 
 
#ifdef SHA1_UTILITY_FUNCTIONS
 
// Get the final hash as a pre-formatted string
 
void CSHA1::ReportHash(char *szReport, unsigned char uReportType)
 
{
 
	unsigned char i;
 
	char szTemp[16];
 
 
	if(szReport == NULL) return;
 
 
	if(uReportType == REPORT_HEX)
 
	{
 
		sprintf(szTemp, "%02X", m_digest[0]);
 
		strcat(szReport, szTemp);
 
 
		for(i = 1; i < 20; i++)
 
		{
 
			sprintf(szTemp, " %02X", m_digest[i]);
 
			strcat(szReport, szTemp);
 
		}
 
	}
 
	else if(uReportType == REPORT_DIGIT)
 
	{
 
		sprintf(szTemp, "%u", m_digest[0]);
 
		strcat(szReport, szTemp);
 
 
		for(i = 1; i < 20; i++)
 
		{
 
			sprintf(szTemp, " %u", m_digest[i]);
 
			strcat(szReport, szTemp);
 
		}
 
	}
 
	else strcpy(szReport, "Error: Unknown report type!");
 
}
 
#endif
 
 
// Get the raw message digest
 
void CSHA1::GetHash(UINT_8 *puDest)
 
{
 
	memcpy(puDest, m_digest, 20);
 
}
 
/*
 
	100% free public domain implementation of the SHA-1 algorithm
 
	by Dominik Reichl <dominik.reichl@t-online.de>
 
	Web: http://www.dominik-reichl.de/
 

	
 
	Version 1.6 - 2005-02-07 (thanks to Howard Kapustein for patches)
 
	- You can set the endianness in your files, no need to modify the
 
	  header file of the CSHA1 class any more
 
	- Aligned data support
 
	- Made support/compilation of the utility functions (ReportHash
 
	  and HashFile) optional (useful, if bytes count, for example in
 
	  embedded environments)
 

	
 
	Version 1.5 - 2005-01-01
 
	- 64-bit compiler compatibility added
 
	- Made variable wiping optional (define SHA1_WIPE_VARIABLES)
 
	- Removed unnecessary variable initializations
 
	- ROL32 improvement for the Microsoft compiler (using _rotl)
 

	
 
	======== Test Vectors (from FIPS PUB 180-1) ========
 

	
 
	SHA1("abc") =
 
		A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D
 

	
 
	SHA1("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq") =
 
		84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1
 

	
 
	SHA1(A million repetitions of "a") =
 
		34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F
 
*/
 

	
 
#include "SHA1.h"
 

	
 
#ifdef SHA1_UTILITY_FUNCTIONS
 
#define SHA1_MAX_FILE_BUFFER 8000
 
#endif
 

	
 
// Rotate x bits to the left
 
#ifndef ROL32
 
#ifdef _MSC_VER
 
#define ROL32(_val32, _nBits) _rotl(_val32, _nBits)
 
#else
 
#define ROL32(_val32, _nBits) (((_val32)<<(_nBits))|((_val32)>>(32-(_nBits))))
 
#endif
 
#endif
 

	
 
#ifdef SHA1_LITTLE_ENDIAN
 
#define SHABLK0(i) (m_block->l[i] = \
 
	(ROL32(m_block->l[i],24) & 0xFF00FF00) | (ROL32(m_block->l[i],8) & 0x00FF00FF))
 
#else
 
#define SHABLK0(i) (m_block->l[i])
 
#endif
 

	
 
#define SHABLK(i) (m_block->l[i&15] = ROL32(m_block->l[(i+13)&15] ^ m_block->l[(i+8)&15] \
 
	^ m_block->l[(i+2)&15] ^ m_block->l[i&15],1))
 

	
 
// SHA-1 rounds
 
#define _R0(v,w,x,y,z,i) { z+=((w&(x^y))^y)+SHABLK0(i)+0x5A827999+ROL32(v,5); w=ROL32(w,30); }
 
#define _R1(v,w,x,y,z,i) { z+=((w&(x^y))^y)+SHABLK(i)+0x5A827999+ROL32(v,5); w=ROL32(w,30); }
 
#define _R2(v,w,x,y,z,i) { z+=(w^x^y)+SHABLK(i)+0x6ED9EBA1+ROL32(v,5); w=ROL32(w,30); }
 
#define _R3(v,w,x,y,z,i) { z+=(((w|x)&y)|(w&x))+SHABLK(i)+0x8F1BBCDC+ROL32(v,5); w=ROL32(w,30); }
 
#define _R4(v,w,x,y,z,i) { z+=(w^x^y)+SHABLK(i)+0xCA62C1D6+ROL32(v,5); w=ROL32(w,30); }
 

	
 
CSHA1::CSHA1()
 
{
 
	m_block = (SHA1_WORKSPACE_BLOCK *)m_workspace;
 

	
 
	Reset();
 
}
 

	
 
CSHA1::~CSHA1()
 
{
 
	Reset();
 
}
 

	
 
void CSHA1::Reset()
 
{
 
	// SHA1 initialization constants
 
	m_state[0] = 0x67452301;
 
	m_state[1] = 0xEFCDAB89;
 
	m_state[2] = 0x98BADCFE;
 
	m_state[3] = 0x10325476;
 
	m_state[4] = 0xC3D2E1F0;
 

	
 
	m_count[0] = 0;
 
	m_count[1] = 0;
 
}
 

	
 
void CSHA1::Transform(UINT_32 *state, UINT_8 *buffer)
 
{
 
	// Copy state[] to working vars
 
	UINT_32 a = state[0], b = state[1], c = state[2], d = state[3], e = state[4];
 

	
 
	memcpy(m_block, buffer, 64);
 

	
 
	// 4 rounds of 20 operations each. Loop unrolled.
 
	_R0(a,b,c,d,e, 0); _R0(e,a,b,c,d, 1); _R0(d,e,a,b,c, 2); _R0(c,d,e,a,b, 3);
 
	_R0(b,c,d,e,a, 4); _R0(a,b,c,d,e, 5); _R0(e,a,b,c,d, 6); _R0(d,e,a,b,c, 7);
 
	_R0(c,d,e,a,b, 8); _R0(b,c,d,e,a, 9); _R0(a,b,c,d,e,10); _R0(e,a,b,c,d,11);
 
	_R0(d,e,a,b,c,12); _R0(c,d,e,a,b,13); _R0(b,c,d,e,a,14); _R0(a,b,c,d,e,15);
 
	_R1(e,a,b,c,d,16); _R1(d,e,a,b,c,17); _R1(c,d,e,a,b,18); _R1(b,c,d,e,a,19);
 
	_R2(a,b,c,d,e,20); _R2(e,a,b,c,d,21); _R2(d,e,a,b,c,22); _R2(c,d,e,a,b,23);
 
	_R2(b,c,d,e,a,24); _R2(a,b,c,d,e,25); _R2(e,a,b,c,d,26); _R2(d,e,a,b,c,27);
 
	_R2(c,d,e,a,b,28); _R2(b,c,d,e,a,29); _R2(a,b,c,d,e,30); _R2(e,a,b,c,d,31);
 
	_R2(d,e,a,b,c,32); _R2(c,d,e,a,b,33); _R2(b,c,d,e,a,34); _R2(a,b,c,d,e,35);
 
	_R2(e,a,b,c,d,36); _R2(d,e,a,b,c,37); _R2(c,d,e,a,b,38); _R2(b,c,d,e,a,39);
 
	_R3(a,b,c,d,e,40); _R3(e,a,b,c,d,41); _R3(d,e,a,b,c,42); _R3(c,d,e,a,b,43);
 
	_R3(b,c,d,e,a,44); _R3(a,b,c,d,e,45); _R3(e,a,b,c,d,46); _R3(d,e,a,b,c,47);
 
	_R3(c,d,e,a,b,48); _R3(b,c,d,e,a,49); _R3(a,b,c,d,e,50); _R3(e,a,b,c,d,51);
 
	_R3(d,e,a,b,c,52); _R3(c,d,e,a,b,53); _R3(b,c,d,e,a,54); _R3(a,b,c,d,e,55);
 
	_R3(e,a,b,c,d,56); _R3(d,e,a,b,c,57); _R3(c,d,e,a,b,58); _R3(b,c,d,e,a,59);
 
	_R4(a,b,c,d,e,60); _R4(e,a,b,c,d,61); _R4(d,e,a,b,c,62); _R4(c,d,e,a,b,63);
 
	_R4(b,c,d,e,a,64); _R4(a,b,c,d,e,65); _R4(e,a,b,c,d,66); _R4(d,e,a,b,c,67);
 
	_R4(c,d,e,a,b,68); _R4(b,c,d,e,a,69); _R4(a,b,c,d,e,70); _R4(e,a,b,c,d,71);
 
	_R4(d,e,a,b,c,72); _R4(c,d,e,a,b,73); _R4(b,c,d,e,a,74); _R4(a,b,c,d,e,75);
 
	_R4(e,a,b,c,d,76); _R4(d,e,a,b,c,77); _R4(c,d,e,a,b,78); _R4(b,c,d,e,a,79);
 

	
 
	// Add the working vars back into state
 
	state[0] += a;
 
	state[1] += b;
 
	state[2] += c;
 
	state[3] += d;
 
	state[4] += e;
 

	
 
	// Wipe variables
 
#ifdef SHA1_WIPE_VARIABLES
 
	a = b = c = d = e = 0;
 
#endif
 
}
 

	
 
// Use this function to hash in binary data and strings
 
void CSHA1::Update(UINT_8 *data, UINT_32 len)
 
{
 
	UINT_32 i, j;
 

	
 
	j = (m_count[0] >> 3) & 63;
 

	
 
	if((m_count[0] += len << 3) < (len << 3)) m_count[1]++;
 

	
 
	m_count[1] += (len >> 29);
 

	
 
	if((j + len) > 63)
 
	{
 
		i = 64 - j;
 
		memcpy(&m_buffer[j], data, i);
 
		Transform(m_state, m_buffer);
 

	
 
		for(; i + 63 < len; i += 64) Transform(m_state, &data[i]);
 

	
 
		j = 0;
 
	}
 
	else i = 0;
 

	
 
	memcpy(&m_buffer[j], &data[i], len - i);
 
}
 

	
 
#ifdef SHA1_UTILITY_FUNCTIONS
 
// Hash in file contents
 
bool CSHA1::HashFile(char *szFileName)
 
{
 
	unsigned long ulFileSize, ulRest, ulBlocks;
 
	unsigned long i;
 
	UINT_8 uData[SHA1_MAX_FILE_BUFFER];
 
	FILE *fIn;
 

	
 
	if(szFileName == NULL) return false;
 

	
 
	fIn = fopen(szFileName, "rb");
 
	if(fIn == NULL) return false;
 

	
 
	fseek(fIn, 0, SEEK_END);
 
	ulFileSize = (unsigned long)ftell(fIn);
 
	fseek(fIn, 0, SEEK_SET);
 

	
 
	if(ulFileSize != 0)
 
	{
 
		ulBlocks = ulFileSize / SHA1_MAX_FILE_BUFFER;
 
		ulRest = ulFileSize % SHA1_MAX_FILE_BUFFER;
 
	}
 
	else
 
	{
 
		ulBlocks = 0;
 
		ulRest = 0;
 
	}
 

	
 
	for(i = 0; i < ulBlocks; i++)
 
	{
 
		fread(uData, 1, SHA1_MAX_FILE_BUFFER, fIn);
 
		Update((UINT_8 *)uData, SHA1_MAX_FILE_BUFFER);
 
	}
 

	
 
	if(ulRest != 0)
 
	{
 
		fread(uData, 1, ulRest, fIn);
 
		Update((UINT_8 *)uData, ulRest);
 
	}
 

	
 
	fclose(fIn); fIn = NULL;
 
	return true;
 
}
 
#endif
 

	
 
void CSHA1::Final()
 
{
 
	UINT_32 i;
 
	UINT_8 finalcount[8];
 

	
 
	for(i = 0; i < 8; i++)
 
		finalcount[i] = (UINT_8)((m_count[((i >= 4) ? 0 : 1)]
 
			>> ((3 - (i & 3)) * 8) ) & 255); // Endian independent
 

	
 
	Update((UINT_8 *)"\200", 1);
 

	
 
	while ((m_count[0] & 504) != 448)
 
		Update((UINT_8 *)"\0", 1);
 

	
 
	Update(finalcount, 8); // Cause a SHA1Transform()
 

	
 
	for(i = 0; i < 20; i++)
 
	{
 
		m_digest[i] = (UINT_8)((m_state[i >> 2] >> ((3 - (i & 3)) * 8) ) & 255);
 
	}
 

	
 
	// Wipe variables for security reasons
 
#ifdef SHA1_WIPE_VARIABLES
 
	i = 0;
 
	memset(m_buffer, 0, 64);
 
	memset(m_state, 0, 20);
 
	memset(m_count, 0, 8);
 
	memset(finalcount, 0, 8);
 
	Transform(m_state, m_buffer);
 
#endif
 
}
 

	
 
#ifdef SHA1_UTILITY_FUNCTIONS
 
// Get the final hash as a pre-formatted string
 
void CSHA1::ReportHash(char *szReport, unsigned char uReportType)
 
{
 
	unsigned char i;
 
	char szTemp[16];
 

	
 
	if(szReport == NULL) return;
 

	
 
	if(uReportType == REPORT_HEX)
 
	{
 
		sprintf(szTemp, "%02X", m_digest[0]);
 
		strcat(szReport, szTemp);
 

	
 
		for(i = 1; i < 20; i++)
 
		{
 
			sprintf(szTemp, " %02X", m_digest[i]);
 
			strcat(szReport, szTemp);
 
		}
 
	}
 
	else if(uReportType == REPORT_DIGIT)
 
	{
 
		sprintf(szTemp, "%u", m_digest[0]);
 
		strcat(szReport, szTemp);
 

	
 
		for(i = 1; i < 20; i++)
 
		{
 
			sprintf(szTemp, " %u", m_digest[i]);
 
			strcat(szReport, szTemp);
 
		}
 
	}
 
	else strcpy(szReport, "Error: Unknown report type!");
 
}
 
#endif
 

	
 
// Get the raw message digest
 
void CSHA1::GetHash(UINT_8 *puDest)
 
{
 
	memcpy(puDest, m_digest, 20);
 
}
backends/twitter/libtwitcurl/SHA1.h
Show inline comments
 
/*
 
	100% free public domain implementation of the SHA-1 algorithm
 
	by Dominik Reichl <dominik.reichl@t-online.de>
 
	Web: http://www.dominik-reichl.de/
 
 
	Version 1.6 - 2005-02-07 (thanks to Howard Kapustein for patches)
 
	- You can set the endianness in your files, no need to modify the
 
	  header file of the CSHA1 class any more
 
	- Aligned data support
 
	- Made support/compilation of the utility functions (ReportHash
 
	  and HashFile) optional (useful, if bytes count, for example in
 
	  embedded environments)
 
 
	Version 1.5 - 2005-01-01
 
	- 64-bit compiler compatibility added
 
	- Made variable wiping optional (define SHA1_WIPE_VARIABLES)
 
	- Removed unnecessary variable initializations
 
	- ROL32 improvement for the Microsoft compiler (using _rotl)
 
 
	======== Test Vectors (from FIPS PUB 180-1) ========
 
 
	SHA1("abc") =
 
		A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D
 
 
	SHA1("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq") =
 
		84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1
 
 
	SHA1(A million repetitions of "a") =
 
		34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F
 
*/
 
 
#ifndef ___SHA1_HDR___
 
#define ___SHA1_HDR___
 
 
#if !defined(SHA1_UTILITY_FUNCTIONS) && !defined(SHA1_NO_UTILITY_FUNCTIONS)
 
#define SHA1_UTILITY_FUNCTIONS
 
#endif
 
 
#include <memory.h> // Needed for memset and memcpy
 
 
#ifdef SHA1_UTILITY_FUNCTIONS
 
#include <stdio.h>  // Needed for file access and sprintf
 
#include <string.h> // Needed for strcat and strcpy
 
#endif
 
 
#ifdef _MSC_VER
 
#include <stdlib.h>
 
#endif
 
 
// You can define the endian mode in your files, without modifying the SHA1
 
// source files. Just #define SHA1_LITTLE_ENDIAN or #define SHA1_BIG_ENDIAN
 
// in your files, before including the SHA1.h header file. If you don't
 
// define anything, the class defaults to little endian.
 
 
#if !defined(SHA1_LITTLE_ENDIAN) && !defined(SHA1_BIG_ENDIAN)
 
#define SHA1_LITTLE_ENDIAN
 
#endif
 
 
// Same here. If you want variable wiping, #define SHA1_WIPE_VARIABLES, if
 
// not, #define SHA1_NO_WIPE_VARIABLES. If you don't define anything, it
 
// defaults to wiping.
 
 
#if !defined(SHA1_WIPE_VARIABLES) && !defined(SHA1_NO_WIPE_VARIABLES)
 
#define SHA1_WIPE_VARIABLES
 
#endif
 
 
/////////////////////////////////////////////////////////////////////////////
 
// Define 8- and 32-bit variables
 
 
#ifndef UINT_32
 
 
#ifdef _MSC_VER
 
 
#define UINT_8  unsigned __int8
 
#define UINT_32 unsigned __int32
 
 
#else
 
 
#define UINT_8 unsigned char
 
 
#if (ULONG_MAX == 0xFFFFFFFF)
 
#define UINT_32 unsigned long
 
#else
 
#define UINT_32 unsigned int
 
#endif
 
 
#endif
 
#endif
 
 
/////////////////////////////////////////////////////////////////////////////
 
// Declare SHA1 workspace
 
 
typedef union
 
{
 
	UINT_8  c[64];
 
	UINT_32 l[16];
 
} SHA1_WORKSPACE_BLOCK;
 
 
class CSHA1
 
{
 
public:
 
#ifdef SHA1_UTILITY_FUNCTIONS
 
	// Two different formats for ReportHash(...)
 
	enum
 
	{
 
		REPORT_HEX = 0,
 
		REPORT_DIGIT = 1
 
	};
 
#endif
 
 
	// Constructor and Destructor
 
	CSHA1();
 
	~CSHA1();
 
 
	UINT_32 m_state[5];
 
	UINT_32 m_count[2];
 
	UINT_32 __reserved1[1];
 
	UINT_8  m_buffer[64];
 
	UINT_8  m_digest[20];
 
	UINT_32 __reserved2[3];
 
 
	void Reset();
 
 
	// Update the hash value
 
	void Update(UINT_8 *data, UINT_32 len);
 
#ifdef SHA1_UTILITY_FUNCTIONS
 
	bool HashFile(char *szFileName);
 
#endif
 
 
	// Finalize hash and report
 
	void Final();
 
 
	// Report functions: as pre-formatted and raw data
 
#ifdef SHA1_UTILITY_FUNCTIONS
 
	void ReportHash(char *szReport, unsigned char uReportType = REPORT_HEX);
 
#endif
 
	void GetHash(UINT_8 *puDest);
 
 
private:
 
	// Private SHA-1 transformation
 
	void Transform(UINT_32 *state, UINT_8 *buffer);
 
 
	// Member variables
 
	UINT_8 m_workspace[64];
 
	SHA1_WORKSPACE_BLOCK *m_block; // SHA1 pointer to the byte array above
 
};
 
 
#endif
 
/*
 
	100% free public domain implementation of the SHA-1 algorithm
 
	by Dominik Reichl <dominik.reichl@t-online.de>
 
	Web: http://www.dominik-reichl.de/
 

	
 
	Version 1.6 - 2005-02-07 (thanks to Howard Kapustein for patches)
 
	- You can set the endianness in your files, no need to modify the
 
	  header file of the CSHA1 class any more
 
	- Aligned data support
 
	- Made support/compilation of the utility functions (ReportHash
 
	  and HashFile) optional (useful, if bytes count, for example in
 
	  embedded environments)
 

	
 
	Version 1.5 - 2005-01-01
 
	- 64-bit compiler compatibility added
 
	- Made variable wiping optional (define SHA1_WIPE_VARIABLES)
 
	- Removed unnecessary variable initializations
 
	- ROL32 improvement for the Microsoft compiler (using _rotl)
 

	
 
	======== Test Vectors (from FIPS PUB 180-1) ========
 

	
 
	SHA1("abc") =
 
		A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D
 

	
 
	SHA1("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq") =
 
		84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1
 

	
 
	SHA1(A million repetitions of "a") =
 
		34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F
 
*/
 

	
 
#ifndef ___SHA1_HDR___
 
#define ___SHA1_HDR___
 

	
 
#if !defined(SHA1_UTILITY_FUNCTIONS) && !defined(SHA1_NO_UTILITY_FUNCTIONS)
 
#define SHA1_UTILITY_FUNCTIONS
 
#endif
 

	
 
#include <memory.h> // Needed for memset and memcpy
 

	
 
#ifdef SHA1_UTILITY_FUNCTIONS
 
#include <stdio.h>  // Needed for file access and sprintf
 
#include <string.h> // Needed for strcat and strcpy
 
#endif
 

	
 
#ifdef _MSC_VER
 
#include <stdlib.h>
 
#endif
 

	
 
// You can define the endian mode in your files, without modifying the SHA1
 
// source files. Just #define SHA1_LITTLE_ENDIAN or #define SHA1_BIG_ENDIAN
 
// in your files, before including the SHA1.h header file. If you don't
 
// define anything, the class defaults to little endian.
 

	
 
#if !defined(SHA1_LITTLE_ENDIAN) && !defined(SHA1_BIG_ENDIAN)
 
#define SHA1_LITTLE_ENDIAN
 
#endif
 

	
 
// Same here. If you want variable wiping, #define SHA1_WIPE_VARIABLES, if
 
// not, #define SHA1_NO_WIPE_VARIABLES. If you don't define anything, it
 
// defaults to wiping.
 

	
 
#if !defined(SHA1_WIPE_VARIABLES) && !defined(SHA1_NO_WIPE_VARIABLES)
 
#define SHA1_WIPE_VARIABLES
 
#endif
 

	
 
/////////////////////////////////////////////////////////////////////////////
 
// Define 8- and 32-bit variables
 

	
 
#ifndef UINT_32
 

	
 
#ifdef _MSC_VER
 

	
 
#define UINT_8  unsigned __int8
 
#define UINT_32 unsigned __int32
 

	
 
#else
 

	
 
#define UINT_8 unsigned char
 

	
 
#if (ULONG_MAX == 0xFFFFFFFF)
 
#define UINT_32 unsigned long
 
#else
 
#define UINT_32 unsigned int
 
#endif
 

	
 
#endif
 
#endif
 

	
 
/////////////////////////////////////////////////////////////////////////////
 
// Declare SHA1 workspace
 

	
 
typedef union
 
{
 
	UINT_8  c[64];
 
	UINT_32 l[16];
 
} SHA1_WORKSPACE_BLOCK;
 

	
 
class CSHA1
 
{
 
public:
 
#ifdef SHA1_UTILITY_FUNCTIONS
 
	// Two different formats for ReportHash(...)
 
	enum
 
	{
 
		REPORT_HEX = 0,
 
		REPORT_DIGIT = 1
 
	};
 
#endif
 

	
 
	// Constructor and Destructor
 
	CSHA1();
 
	~CSHA1();
 

	
 
	UINT_32 m_state[5];
 
	UINT_32 m_count[2];
 
	UINT_32 __reserved1[1];
 
	UINT_8  m_buffer[64];
 
	UINT_8  m_digest[20];
 
	UINT_32 __reserved2[3];
 

	
 
	void Reset();
 

	
 
	// Update the hash value
 
	void Update(UINT_8 *data, UINT_32 len);
 
#ifdef SHA1_UTILITY_FUNCTIONS
 
	bool HashFile(char *szFileName);
 
#endif
 

	
 
	// Finalize hash and report
 
	void Final();
 

	
 
	// Report functions: as pre-formatted and raw data
 
#ifdef SHA1_UTILITY_FUNCTIONS
 
	void ReportHash(char *szReport, unsigned char uReportType = REPORT_HEX);
 
#endif
 
	void GetHash(UINT_8 *puDest);
 

	
 
private:
 
	// Private SHA-1 transformation
 
	void Transform(UINT_32 *state, UINT_8 *buffer);
 

	
 
	// Member variables
 
	UINT_8 m_workspace[64];
 
	SHA1_WORKSPACE_BLOCK *m_block; // SHA1 pointer to the byte array above
 
};
 

	
 
#endif
backends/twitter/libtwitcurl/base64.cpp
Show inline comments
 
/* 
 
   base64.cpp and base64.h
 
 
   Copyright (C) 2004-2008 René Nyffenegger
 
 
   This source code is provided 'as-is', without any express or implied
 
   warranty. In no event will the author be held liable for any damages
 
   arising from the use of this software.
 
 
   Permission is granted to anyone to use this software for any purpose,
 
   including commercial applications, and to alter it and redistribute it
 
   freely, subject to the following restrictions:
 
 
   1. The origin of this source code must not be misrepresented; you must not
 
      claim that you wrote the original source code. If you use this source code
 
      in a product, an acknowledgment in the product documentation would be
 
      appreciated but is not required.
 
 
   2. Altered source versions must be plainly marked as such, and must not be
 
      misrepresented as being the original source code.
 
 
   3. This notice may not be removed or altered from any source distribution.
 
 
   René Nyffenegger rene.nyffenegger@adp-gmbh.ch
 
 
*/
 
 
#include "base64.h"
 
#include <iostream>
 
 
static const std::string base64_chars = 
 
             "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
 
             "abcdefghijklmnopqrstuvwxyz"
 
             "0123456789+/";
 
 
 
static inline bool is_base64(unsigned char c) {
 
  return (isalnum(c) || (c == '+') || (c == '/'));
 
}
 
 
std::string base64_encode(unsigned char const* bytes_to_encode, unsigned int in_len) {
 
  std::string ret;
 
  int i = 0;
 
  int j = 0;
 
  unsigned char char_array_3[3];
 
  unsigned char char_array_4[4];
 
 
  while (in_len--) {
 
    char_array_3[i++] = *(bytes_to_encode++);
 
    if (i == 3) {
 
      char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
 
      char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
 
      char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
 
      char_array_4[3] = char_array_3[2] & 0x3f;
 
 
      for(i = 0; (i <4) ; i++)
 
        ret += base64_chars[char_array_4[i]];
 
      i = 0;
 
    }
 
  }
 
 
  if (i)
 
  {
 
    for(j = i; j < 3; j++)
 
      char_array_3[j] = '\0';
 
 
    char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
 
    char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
 
    char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
 
    char_array_4[3] = char_array_3[2] & 0x3f;
 
 
    for (j = 0; (j < i + 1); j++)
 
      ret += base64_chars[char_array_4[j]];
 
 
    while((i++ < 3))
 
      ret += '=';
 
 
  }
 
 
  return ret;
 
 
}
 
 
std::string base64_decode(std::string const& encoded_string) {
 
  int in_len = encoded_string.size();
 
  int i = 0;
 
  int j = 0;
 
  int in_ = 0;
 
  unsigned char char_array_4[4], char_array_3[3];
 
  std::string ret;
 
 
  while (in_len-- && ( encoded_string[in_] != '=') && is_base64(encoded_string[in_])) {
 
    char_array_4[i++] = encoded_string[in_]; in_++;
 
    if (i ==4) {
 
      for (i = 0; i <4; i++)
 
        char_array_4[i] = base64_chars.find(char_array_4[i]);
 
 
      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 (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;
 
/* 
 
   base64.cpp and base64.h
 

	
 
   Copyright (C) 2004-2008 René Nyffenegger
 

	
 
   This source code is provided 'as-is', without any express or implied
 
   warranty. In no event will the author be held liable for any damages
 
   arising from the use of this software.
 

	
 
   Permission is granted to anyone to use this software for any purpose,
 
   including commercial applications, and to alter it and redistribute it
 
   freely, subject to the following restrictions:
 

	
 
   1. The origin of this source code must not be misrepresented; you must not
 
      claim that you wrote the original source code. If you use this source code
 
      in a product, an acknowledgment in the product documentation would be
 
      appreciated but is not required.
 

	
 
   2. Altered source versions must be plainly marked as such, and must not be
 
      misrepresented as being the original source code.
 

	
 
   3. This notice may not be removed or altered from any source distribution.
 

	
 
   René Nyffenegger rene.nyffenegger@adp-gmbh.ch
 

	
 
*/
 

	
 
#include "base64.h"
 
#include <iostream>
 

	
 
static const std::string base64_chars = 
 
             "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
 
             "abcdefghijklmnopqrstuvwxyz"
 
             "0123456789+/";
 

	
 

	
 
static inline bool is_base64(unsigned char c) {
 
  return (isalnum(c) || (c == '+') || (c == '/'));
 
}
 

	
 
std::string base64_encode(unsigned char const* bytes_to_encode, unsigned int in_len) {
 
  std::string ret;
 
  int i = 0;
 
  int j = 0;
 
  unsigned char char_array_3[3];
 
  unsigned char char_array_4[4];
 

	
 
  while (in_len--) {
 
    char_array_3[i++] = *(bytes_to_encode++);
 
    if (i == 3) {
 
      char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
 
      char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
 
      char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
 
      char_array_4[3] = char_array_3[2] & 0x3f;
 

	
 
      for(i = 0; (i <4) ; i++)
 
        ret += base64_chars[char_array_4[i]];
 
      i = 0;
 
    }
 
  }
 

	
 
  if (i)
 
  {
 
    for(j = i; j < 3; j++)
 
      char_array_3[j] = '\0';
 

	
 
    char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
 
    char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
 
    char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
 
    char_array_4[3] = char_array_3[2] & 0x3f;
 

	
 
    for (j = 0; (j < i + 1); j++)
 
      ret += base64_chars[char_array_4[j]];
 

	
 
    while((i++ < 3))
 
      ret += '=';
 

	
 
  }
 

	
 
  return ret;
 

	
 
}
 

	
 
std::string base64_decode(std::string const& encoded_string) {
 
  int in_len = encoded_string.size();
 
  int i = 0;
 
  int j = 0;
 
  int in_ = 0;
 
  unsigned char char_array_4[4], char_array_3[3];
 
  std::string ret;
 

	
 
  while (in_len-- && ( encoded_string[in_] != '=') && is_base64(encoded_string[in_])) {
 
    char_array_4[i++] = encoded_string[in_]; in_++;
 
    if (i ==4) {
 
      for (i = 0; i <4; i++)
 
        char_array_4[i] = base64_chars.find(char_array_4[i]);
 

	
 
      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 (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);
 
#include <string>
 

	
 
std::string base64_encode(unsigned char const* , unsigned int len);
 
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;
 
}
 
 
 
/*++
 
* @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
 
*
 
* @output: none
 
*
 
*--*/
 
void oAuth::setConsumerKey( const std::string& consumerKey )
 
{
 
    m_consumerKey.assign( consumerKey );
 
}
 
 
/*++
 
* @method: oAuth::getConsumerSecret
 
*
 
* @description: this method gives consumer secret that is being used currently
 
*
 
* @input: none
 
*
 
* @output: consumer secret
 
*
 
*--*/
 
void oAuth::getConsumerSecret( std::string& consumerSecret )
 
{
 
    consumerSecret = m_consumerSecret;
 
}
 
 
/*++
 
* @method: oAuth::setConsumerSecret
 
*
 
* @description: this method saves consumer secret that should be used
 
*
 
* @input: consumer secret
 
*
 
* @output: none
 
*
 
*--*/
 
void oAuth::setConsumerSecret( const std::string& consumerSecret )
 
{
 
    m_consumerSecret = consumerSecret;
 
}
 
 
/*++
 
* @method: oAuth::getOAuthTokenKey
 
*
 
* @description: this method gives OAuth token (also called access token) that is being used currently
 
*
 
* @input: none
 
*
 
* @output: OAuth token
 
*
 
*--*/
 
void oAuth::getOAuthTokenKey( std::string& oAuthTokenKey )
 
{
 
    oAuthTokenKey = m_oAuthTokenKey;
 
}
 
 
/*++
 
* @method: oAuth::setOAuthTokenKey
 
*
 
* @description: this method saves OAuth token that should be used
 
*
 
* @input: OAuth token
 
*
 
* @output: none
 
*
 
*--*/
 
void oAuth::setOAuthTokenKey( const std::string& oAuthTokenKey )
 
{
 
    m_oAuthTokenKey = oAuthTokenKey;
 
}
 
 
/*++
 
* @method: oAuth::getOAuthTokenSecret
 
*
 
* @description: this method gives OAuth token secret that is being used currently
 
*
 
* @input: none
 
*
 
* @output: OAuth token secret
 
*
 
*--*/
 
void oAuth::getOAuthTokenSecret( std::string& oAuthTokenSecret )
 
{
 
    oAuthTokenSecret = m_oAuthTokenSecret;
 
}
 
 
/*++
 
* @method: oAuth::setOAuthTokenSecret
 
*
 
* @description: this method saves OAuth token that should be used
 
*
 
* @input: OAuth token secret
 
*
 
* @output: none
 
*
 
*--*/
 
void oAuth::setOAuthTokenSecret( const std::string& oAuthTokenSecret )
 
{
 
    m_oAuthTokenSecret = oAuthTokenSecret;
 
}
 
 
/*++
 
* @method: oAuth::getOAuthScreenName
 
*
 
* @description: this method gives authorized user's screenname
 
*
 
* @input: none
 
*
 
* @output: screen name
 
*
 
*--*/
 
void oAuth::getOAuthScreenName( std::string& oAuthScreenName )
 
{
 
    oAuthScreenName = m_oAuthScreenName;
 
}
 
 
/*++
 
* @method: oAuth::setOAuthScreenName
 
*
 
* @description: this method sets authorized user's screenname
 
*
 
* @input: screen name
 
*
 
* @output: none
 
*
 
*--*/
 
void oAuth::setOAuthScreenName( const std::string& oAuthScreenName )
 
{
 
    m_oAuthScreenName = oAuthScreenName;
 
}
 
 
/*++
 
* @method: oAuth::getOAuthPin
 
*
 
* @description: this method gives OAuth verifier PIN
 
*
 
* @input: none
 
*
 
* @output: OAuth verifier PIN
 
*
 
*--*/
 
void oAuth::getOAuthPin( std::string& oAuthPin )
 
{
 
    oAuthPin = m_oAuthPin;
 
}
 
 
/*++
 
* @method: oAuth::setOAuthPin
 
*
 
* @description: this method sets OAuth verifier PIN
 
*
 
* @input: OAuth verifier PIN
 
*
 
* @output: none
 
*
 
*--*/
 
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( (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.empty() )
 
    {
 
        return;
 
    }
 
 
    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 )
 
{
 
    /* Generate nonce and timestamp if required */
 
    if( generateTimestamp )
 
    {
 
        generateNonceTimeStamp();
 
    }
 
 
    /* Consumer key and its value */
 
    keyValueMap[oAuthLibDefaults::OAUTHLIB_CONSUMERKEY_KEY] = m_consumerKey;
 
 
    /* Nonce key and its value */
 
    keyValueMap[oAuthLibDefaults::OAUTHLIB_NONCE_KEY] = m_nonce;
 
 
    /* Signature if supplied */
 
    if( oauthSignature.length() )
 
    {
 
        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.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 = "";
 
 
    /* 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&" );
 
        }
 
        break;
 
 
    default:
 
        {
 
            return false;
 
        }
 
        break;
 
    }
 
    sigBase.append( urlencode( rawUrl ) );
 
    sigBase.append( "&" );
 
    sigBase.append( urlencode( rawParams ) );
 
 
    /* Now, hash the signature base string using HMAC_SHA1 class */
 
    CHMAC_SHA1 objHMACSHA1;
 
    std::string secretSigningKey;
 
    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.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 = "";
 
    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.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 = "";
 
    if( rawParamMap.empty() )
 
    {
 
        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++ )
 
    {
 
        dummyStr.assign( itMap->first );
 
        dummyStr.append( "=" );
 
        if( paramsSeperator == "," )
 
        {
 
            dummyStr.append( "\"" );
 
        }
 
        dummyStr.append( itMap->second );
 
        if( paramsSeperator == "," )
 
        {
 
            dummyStr.append( "\"" );
 
        }
 
        keyValueList.push_back( dummyStr );
 
    }
 
 
    /* Sort key-value pairs based on key name */
 
    keyValueList.sort();
 
 
    /* Now, form a string */
 
    dummyStr = "";
 
    oAuthKeyValueList::iterator itKeyValue = keyValueList.begin();
 
    for( ; itKeyValue != keyValueList.end(); itKeyValue++ )
 
    {
 
        if( dummyStr.length() )
 
        {
 
            dummyStr.append( paramsSeperator );
 
         }
 
         dummyStr.append( itKeyValue->c_str() );
 
    }
 
    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.empty() )
 
    {
 
        return false;
 
    }
 
 
    size_t nPos = std::string::npos;
 
    std::string strDummy;
 
 
    /* 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 );
 
        }
 
    }
 
 
    /* 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 )
 
        {
 
            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;
 
}
 
 
#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;
 
}
 

	
 

	
 
/*++
 
* @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
 
*
 
* @output: none
 
*
 
*--*/
 
void oAuth::setConsumerKey( const std::string& consumerKey )
 
{
 
    m_consumerKey.assign( consumerKey );
 
}
 

	
 
/*++
 
* @method: oAuth::getConsumerSecret
 
*
 
* @description: this method gives consumer secret that is being used currently
 
*
 
* @input: none
 
*
 
* @output: consumer secret
 
*
 
*--*/
 
void oAuth::getConsumerSecret( std::string& consumerSecret )
 
{
 
    consumerSecret = m_consumerSecret;
 
}
 

	
 
/*++
 
* @method: oAuth::setConsumerSecret
 
*
 
* @description: this method saves consumer secret that should be used
 
*
 
* @input: consumer secret
 
*
 
* @output: none
 
*
 
*--*/
 
void oAuth::setConsumerSecret( const std::string& consumerSecret )
 
{
 
    m_consumerSecret = consumerSecret;
 
}
 

	
 
/*++
 
* @method: oAuth::getOAuthTokenKey
 
*
 
* @description: this method gives OAuth token (also called access token) that is being used currently
 
*
 
* @input: none
 
*
 
* @output: OAuth token
 
*
 
*--*/
 
void oAuth::getOAuthTokenKey( std::string& oAuthTokenKey )
 
{
 
    oAuthTokenKey = m_oAuthTokenKey;
 
}
 

	
 
/*++
 
* @method: oAuth::setOAuthTokenKey
 
*
 
* @description: this method saves OAuth token that should be used
 
*
 
* @input: OAuth token
 
*
 
* @output: none
 
*
 
*--*/
 
void oAuth::setOAuthTokenKey( const std::string& oAuthTokenKey )
 
{
 
    m_oAuthTokenKey = oAuthTokenKey;
 
}
 

	
 
/*++
 
* @method: oAuth::getOAuthTokenSecret
 
*
 
* @description: this method gives OAuth token secret that is being used currently
 
*
 
* @input: none
 
*
 
* @output: OAuth token secret
 
*
 
*--*/
 
void oAuth::getOAuthTokenSecret( std::string& oAuthTokenSecret )
 
{
 
    oAuthTokenSecret = m_oAuthTokenSecret;
 
}
 

	
 
/*++
 
* @method: oAuth::setOAuthTokenSecret
 
*
 
* @description: this method saves OAuth token that should be used
 
*
 
* @input: OAuth token secret
 
*
 
* @output: none
 
*
 
*--*/
 
void oAuth::setOAuthTokenSecret( const std::string& oAuthTokenSecret )
 
{
 
    m_oAuthTokenSecret = oAuthTokenSecret;
 
}
 

	
 
/*++
 
* @method: oAuth::getOAuthScreenName
 
*
 
* @description: this method gives authorized user's screenname
 
*
 
* @input: none
 
*
 
* @output: screen name
 
*
 
*--*/
 
void oAuth::getOAuthScreenName( std::string& oAuthScreenName )
 
{
 
    oAuthScreenName = m_oAuthScreenName;
 
}
 

	
 
/*++
 
* @method: oAuth::setOAuthScreenName
 
*
 
* @description: this method sets authorized user's screenname
 
*
 
* @input: screen name
 
*
 
* @output: none
 
*
 
*--*/
 
void oAuth::setOAuthScreenName( const std::string& oAuthScreenName )
 
{
 
    m_oAuthScreenName = oAuthScreenName;
 
}
 

	
 
/*++
 
* @method: oAuth::getOAuthPin
 
*
 
* @description: this method gives OAuth verifier PIN
 
*
 
* @input: none
 
*
 
* @output: OAuth verifier PIN
 
*
 
*--*/
 
void oAuth::getOAuthPin( std::string& oAuthPin )
 
{
 
    oAuthPin = m_oAuthPin;
 
}
 

	
 
/*++
 
* @method: oAuth::setOAuthPin
 
*
 
* @description: this method sets OAuth verifier PIN
 
*
 
* @input: OAuth verifier PIN
 
*
 
* @output: none
 
*
 
*--*/
 
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( (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.empty() )
 
    {
 
        return;
 
    }
 

	
 
    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 )
 
{
 
    /* Generate nonce and timestamp if required */
 
    if( generateTimestamp )
 
    {
 
        generateNonceTimeStamp();
 
    }
 

	
 
    /* Consumer key and its value */
 
    keyValueMap[oAuthLibDefaults::OAUTHLIB_CONSUMERKEY_KEY] = m_consumerKey;
 

	
 
    /* Nonce key and its value */
 
    keyValueMap[oAuthLibDefaults::OAUTHLIB_NONCE_KEY] = m_nonce;
 

	
 
    /* Signature if supplied */
 
    if( oauthSignature.length() )
 
    {
 
        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.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 = "";
 

	
 
    /* 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&" );
 
        }
 
        break;
 

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

	
 
    /* Now, hash the signature base string using HMAC_SHA1 class */
 
    CHMAC_SHA1 objHMACSHA1;
 
    std::string secretSigningKey;
 
    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.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 = "";
 
    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.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 = "";
 
    if( rawParamMap.empty() )
 
    {
 
        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++ )
 
    {
 
        dummyStr.assign( itMap->first );
 
        dummyStr.append( "=" );
 
        if( paramsSeperator == "," )
 
        {
 
            dummyStr.append( "\"" );
 
        }
 
        dummyStr.append( itMap->second );
 
        if( paramsSeperator == "," )
 
        {
 
            dummyStr.append( "\"" );
 
        }
 
        keyValueList.push_back( dummyStr );
 
    }
 

	
 
    /* Sort key-value pairs based on key name */
 
    keyValueList.sort();
 

	
 
    /* Now, form a string */
 
    dummyStr = "";
 
    oAuthKeyValueList::iterator itKeyValue = keyValueList.begin();
 
    for( ; itKeyValue != keyValueList.end(); itKeyValue++ )
 
    {
 
        if( dummyStr.length() )
 
        {
 
            dummyStr.append( paramsSeperator );
 
         }
 
         dummyStr.append( itKeyValue->c_str() );
 
    }
 
    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.empty() )
 
    {
 
        return false;
 
    }
 

	
 
    size_t nPos = std::string::npos;
 
    std::string strDummy;
 

	
 
    /* 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 );
 
        }
 
    }
 

	
 
    /* 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 )
 
        {
 
            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>
 
 
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 */ );
 
 
    void getOAuthTokenKey( std::string& oAuthTokenKey /* out */ );
 
    void setOAuthTokenKey( const std::string& oAuthTokenKey /* in */ );
 
 
    void getOAuthTokenSecret( std::string& oAuthTokenSecret /* out */ );
 
    void setOAuthTokenSecret( const std::string& oAuthTokenSecret /* in */ );
 
 
    void getOAuthScreenName( std::string& oAuthScreenName /* out */ );
 
    void setOAuthScreenName( const std::string& oAuthScreenName /* in */ );
 
 
    void getOAuthPin( std::string& oAuthPin /* out */ );
 
    void setOAuthPin( const std::string& oAuthPin /* in */ );
 
 
    bool getOAuthHeader( const eOAuthHttpRequestType eType, /* in */
 
                         const std::string& rawUrl, /* in */
 
                         const std::string& rawData, /* in */
 
                         std::string& oAuthHttpHeader, /* out */
 
                         const bool includeOAuthVerifierPin = false /* in */ );
 
 
    bool extractOAuthTokenKeySecret( const std::string& requestTokenResponse /* in */ );
 
 
    oAuth clone();
 
 
private:
 
 
    /* OAuth data */
 
    std::string m_consumerKey;
 
    std::string m_consumerSecret;
 
    std::string m_oAuthTokenKey;
 
    std::string m_oAuthTokenSecret;
 
    std::string m_oAuthPin;
 
    std::string m_nonce;
 
    std::string m_timeStamp;
 
    std::string m_oAuthScreenName;
 
 
    /* OAuth twitter related utility methods */
 
    void buildOAuthRawDataKeyValPairs( const std::string& rawData, /* in */
 
                                       bool urlencodeData, /* in */
 
                                       oAuthKeyValuePairs& rawDataKeyValuePairs /* out */ );
 
 
    bool buildOAuthTokenKeyValuePairs( const bool includeOAuthVerifierPin, /* in */
 
                                       const std::string& oauthSignature, /* in */
 
                                       oAuthKeyValuePairs& keyValueMap /* out */,
 
                                       const bool generateTimestamp /* in */ );
 
 
    bool getStringFromOAuthKeyValuePairs( const oAuthKeyValuePairs& rawParamMap, /* in */
 
                                          std::string& rawParams, /* out */
 
                                          const std::string& paramsSeperator /* in */ );
 
 
    bool getSignature( const eOAuthHttpRequestType eType, /* in */
 
                       const std::string& rawUrl, /* in */
 
                       const oAuthKeyValuePairs& rawKeyValuePairs, /* in */
 
                       std::string& oAuthSignature /* out */ );
 
 
    void generateNonceTimeStamp();
 
};
 
 
#endif // __OAUTHLIB_H__
 
#ifndef __OAUTHLIB_H__
 
#define __OAUTHLIB_H__
 

	
 
#include "time.h"
 
#include <cstdlib>
 
#include <sstream>
 
#include <iostream>
 
#include <fstream>
 
#include <string>
 
#include <list>
 
#include <map>
 

	
 
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 */ );
 

	
 
    void getOAuthTokenKey( std::string& oAuthTokenKey /* out */ );
 
    void setOAuthTokenKey( const std::string& oAuthTokenKey /* in */ );
 

	
 
    void getOAuthTokenSecret( std::string& oAuthTokenSecret /* out */ );
 
    void setOAuthTokenSecret( const std::string& oAuthTokenSecret /* in */ );
 

	
 
    void getOAuthScreenName( std::string& oAuthScreenName /* out */ );
 
    void setOAuthScreenName( const std::string& oAuthScreenName /* in */ );
 

	
 
    void getOAuthPin( std::string& oAuthPin /* out */ );
 
    void setOAuthPin( const std::string& oAuthPin /* in */ );
 

	
 
    bool getOAuthHeader( const eOAuthHttpRequestType eType, /* in */
 
                         const std::string& rawUrl, /* in */
 
                         const std::string& rawData, /* in */
 
                         std::string& oAuthHttpHeader, /* out */
 
                         const bool includeOAuthVerifierPin = false /* in */ );
 

	
 
    bool extractOAuthTokenKeySecret( const std::string& requestTokenResponse /* in */ );
 

	
 
    oAuth clone();
 

	
 
private:
 

	
 
    /* OAuth data */
 
    std::string m_consumerKey;
 
    std::string m_consumerSecret;
 
    std::string m_oAuthTokenKey;
 
    std::string m_oAuthTokenSecret;
 
    std::string m_oAuthPin;
 
    std::string m_nonce;
 
    std::string m_timeStamp;
 
    std::string m_oAuthScreenName;
 

	
 
    /* OAuth twitter related utility methods */
 
    void buildOAuthRawDataKeyValPairs( const std::string& rawData, /* in */
 
                                       bool urlencodeData, /* in */
 
                                       oAuthKeyValuePairs& rawDataKeyValuePairs /* out */ );
 

	
 
    bool buildOAuthTokenKeyValuePairs( const bool includeOAuthVerifierPin, /* in */
 
                                       const std::string& oauthSignature, /* in */
 
                                       oAuthKeyValuePairs& keyValueMap /* out */,
 
                                       const bool generateTimestamp /* in */ );
 

	
 
    bool getStringFromOAuthKeyValuePairs( const oAuthKeyValuePairs& rawParamMap, /* in */
 
                                          std::string& rawParams, /* out */
 
                                          const std::string& paramsSeperator /* in */ );
 

	
 
    bool getSignature( const eOAuthHttpRequestType eType, /* in */
 
                       const std::string& rawUrl, /* in */
 
                       const oAuthKeyValuePairs& rawKeyValuePairs, /* in */
 
                       std::string& oAuthSignature /* out */ );
 

	
 
    void generateNonceTimeStamp();
 
};
 

	
 
#endif // __OAUTHLIB_H__
backends/twitter/libtwitcurl/twitcurl.cpp
Show inline comments
 
#define NOMINMAX
 
#include <memory.h>
 
#include "twitcurlurls.h"
 
#include "twitcurl.h"
 
#include "urlencode.h"
 
 
/*++
 
* @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::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_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);
 
 
    /* Twitter data */
 
    cloneObj->setTwitterUsername(m_twitterUsername);
 
    cloneObj->setTwitterPassword(m_twitterPassword);
 
 
    /* OAuth data */
 
    cloneObj->m_oAuth = m_oAuth.clone();
 
 
    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
 
*
 
* @output: twitter username
 
*
 
*--*/
 
std::string& twitCurl::getTwitterUsername()
 
{
 
    return m_twitterUsername;
 
}
 
 
/*++
 
* @method: twitCurl::getTwitterPassword
 
*
 
* @description: method to get stored Twitter password
 
*
 
* @input: none
 
*
 
* @output: twitter password
 
*
 
*--*/
 
std::string& twitCurl::getTwitterPassword()
 
{
 
    return m_twitterPassword;
 
}
 
 
/*++
 
* @method: twitCurl::setTwitterUsername
 
*
 
* @description: method to set username
 
*
 
* @input: userName
 
*
 
* @output: none
 
*
 
*--*/
 
void twitCurl::setTwitterUsername( std::string& userName )
 
{
 
    if( userName.length() )
 
    {
 
        m_twitterUsername = userName;
 
        m_curlLoginParamsSet = false;
 
    }
 
}
 
 
/*++
 
* @method: twitCurl::setTwitterPassword
 
*
 
* @description: method to set password
 
*
 
* @input: passWord
 
*
 
* @output: none
 
*
 
*--*/
 
void twitCurl::setTwitterPassword( std::string& passWord )
 
{
 
    if( passWord.length() )
 
    {
 
        m_twitterPassword = passWord;
 
        m_curlLoginParamsSet = false;
 
    }
 
}
 
 
/*++
 
* @method: twitCurl::getProxyServerIp
 
*
 
* @description: method to get proxy server IP address
 
*
 
* @input: none
 
*
 
* @output: proxy server IP address
 
*
 
*--*/
 
std::string& twitCurl::getProxyServerIp()
 
{
 
    return m_proxyServerIp;
 
}
 
 
/*++
 
* @method: twitCurl::getProxyServerPort
 
*
 
* @description: method to get proxy server port
 
*
 
* @input: none
 
*
 
* @output: proxy server port
 
*
 
*--*/
 
std::string& twitCurl::getProxyServerPort()
 
{
 
    return m_proxyServerPort;
 
}
 
 
/*++
 
* @method: twitCurl::getProxyUserName
 
*
 
* @description: method to get proxy user name
 
*
 
* @input: none
 
*
 
* @output: proxy server user name
 
*
 
*--*/
 
std::string& twitCurl::getProxyUserName()
 
{
 
    return m_proxyUserName;
 
}
 
 
/*++
 
* @method: twitCurl::getProxyPassword
 
*
 
* @description: method to get proxy server password
 
*
 
* @input: none
 
*
 
* @output: proxy server password
 
*
 
*--*/
 
std::string& twitCurl::getProxyPassword()
 
{
 
    return m_proxyPassword;
 
}
 
 
/*++
 
* @method: twitCurl::setProxyServerIp
 
*
 
* @description: method to set proxy server IP address
 
*
 
* @input: proxyServerIp
 
*
 
* @output: none
 
*
 
*--*/
 
void twitCurl::setProxyServerIp( std::string& proxyServerIp )
 
{
 
    if( proxyServerIp.length() )
 
    {
 
        m_proxyServerIp = proxyServerIp;
 
        /*
 
         * Reset the flag so that next cURL http request
 
         * would set proxy details again into cURL.
 
         */
 
        m_curlProxyParamsSet = false;
 
    }
 
}
 
 
/*++
 
* @method: twitCurl::setProxyServerPort
 
*
 
* @description: method to set proxy server port
 
*
 
* @input: proxyServerPort
 
*
 
* @output: none
 
*
 
*--*/
 
void twitCurl::setProxyServerPort( std::string& proxyServerPort )
 
{
 
    if( proxyServerPort.length() )
 
    {
 
        m_proxyServerPort = proxyServerPort;
 
        /*
 
         * Reset the flag so that next cURL http request
 
         * would set proxy details again into cURL.
 
         */
 
        m_curlProxyParamsSet = false;
 
    }
 
}
 
 
/*++
 
* @method: twitCurl::setProxyUserName
 
*
 
* @description: method to set proxy server username
 
*
 
* @input: proxyUserName
 
*
 
* @output: none
 
*
 
*--*/
 
void twitCurl::setProxyUserName( std::string& proxyUserName )
 
{
 
    if( proxyUserName.length() )
 
    {
 
        m_proxyUserName = proxyUserName;
 
        /*
 
         * Reset the flag so that next cURL http request
 
         * would set proxy details again into cURL.
 
         */
 
        m_curlProxyParamsSet = false;
 
    }
 
}
 
 
/*++
 
* @method: twitCurl::setProxyPassword
 
*
 
* @description: method to set proxy server password
 
*
 
* @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, std::string resultCount )
 
{
 
    /* Prepare URL */
 
    std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                           twitterDefaults::TWITCURL_SEARCH_URL +
 
                           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 - 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, std::string inReplyToStatusId )
 
{
 
    if( newStatus.empty() )
 
    {
 
        return false;
 
    }
 
 
    /* 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 );
 
    }
 
 
    /* 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 )
 
{
 
    if( statusId.empty() )
 
    {
 
        return false;
 
    }
 
 
    /* 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 )
 
{
 
    if( statusId.empty() )
 
    {
 
        return false;
 
    }
 
 
    /* 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 )
 
{
 
    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" ) );
 
 
    /* 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];
 
    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] );
 
}
 
 
/*++
 
* @method: twitCurl::featuredUsersGet
 
*
 
* @description: method to get featured users
 
*
 
* @input: none
 
*
 
* @output: true if GET is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
*--*/
 
bool twitCurl::featuredUsersGet()
 
{
 
    /* Perform GET */
 
    return performGet( twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                       twitterDefaults::TWITCURL_FEATURED_USERS_URL +
 
                       twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType] );
 
}
 
 
/*++
 
* @method: twitCurl::timelineFriendsGet
 
*
 
* @description: method to get friends 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::timelineFriendsGet()
 
{
 
    /* Perform GET */
 
    return performGet( twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                       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 )
 
{
 
    /* 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.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 )
 
{
 
    if( userInfo.empty() )
 
    {
 
        return false;
 
    }
 
 
    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];
 
    }
 
 
    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 )
 
{
 
    if( userInfo.empty() )
 
    {
 
        return false;
 
    }
 
 
    /* 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 */
 
    return performGet( buildUrl );
 
}
 
 
/*++
 
* @method: twitCurl::followersGet
 
*
 
* @description: method to get a user's followers
 
*
 
* @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::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;
 
    }
 
 
    /* 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 )
 
{
 
    if( userInfo.empty() || dMsg.empty() )
 
    {
 
        return false;
 
    }
 
 
    /* Prepare new direct message */
 
    std::string newDm = twitCurlDefaults::TWITCURL_TEXTSTRING + urlencode( dMsg );
 
 
    /* 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 )
 
{
 
    if( dMsgId.empty() )
 
    {
 
        return false;
 
    }
 
 
    /* 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 )
 
{
 
    if( userInfo.empty() )
 
    {
 
        return false;
 
    }
 
 
    /* Prepare URL */
 
    std::string buildUrl;
 
    utilMakeUrlForUser( buildUrl, twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                        twitterDefaults::TWITCURL_FRIENDSHIPSCREATE_URL +
 
                        twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType],
 
                        userInfo, isUserId );
 
 
    /* 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 )
 
{
 
    if( userInfo.empty() )
 
    {
 
        return false;
 
    }
 
 
    /* 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& 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& 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] );
 
}
 
 
/*++
 
* @method: twitCurl::accountVerifyCredGet
 
*
 
* @description: method to get information on user identified by given credentials
 
*
 
* @input: none
 
*
 
* @output: true if GET is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
*--*/
 
bool twitCurl::accountVerifyCredGet()
 
{
 
    /* Perform GET */
 
    return performGet( twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                       twitterDefaults::TWITCURL_ACCOUNTVERIFYCRED_URL +
 
                       twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType] );
 
}
 
 
/*++
 
* @method: twitCurl::favoriteGet
 
*
 
* @description: method to get favorite users' statuses
 
*
 
* @input: none
 
*
 
* @output: true if GET is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
*--*/
 
bool twitCurl::favoriteGet()
 
{
 
    /* Perform GET */
 
    return performGet( twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                       twitterDefaults::TWITCURL_FAVORITESGET_URL +
 
                       twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType] );
 
}
 
 
/*++
 
* @method: twitCurl::favoriteCreate
 
*
 
* @description: method to favorite a status message
 
*
 
* @input: statusId - id in string format of the status to be favorited
 
*
 
* @output: true if POST is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
*--*/
 
bool twitCurl::favoriteCreate( std::string& statusId )
 
{
 
    /* Prepare URL */
 
    std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                           twitterDefaults::TWITCURL_FAVORITECREATE_URL + statusId +
 
                           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::favoriteDestroy
 
*
 
* @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 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 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.
 
*
 
* @input: searchId - id in string format of the search to be displayed
 
*
 
* @output: true if GET is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
*--*/
 
bool twitCurl::savedSearchShow( std::string& searchId )
 
{
 
    /* Prepare URL */
 
    std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                           twitterDefaults::TWITCURL_SAVEDSEARCHSHOW_URL + searchId +
 
                           twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];
 
 
    /* Perform GET */
 
    return performGet( buildUrl );
 
}
 
 
/*++
 
* @method: twitCurl::savedSearchCreate
 
*
 
* @description: creates a saved search for the authenticated user
 
*
 
* @input: query - the query of the search the user would like to save
 
*
 
* @output: true if POST is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
*--*/
 
bool twitCurl::savedSearchCreate( std::string& query )
 
{
 
    /* Prepare URL */
 
    std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                           twitterDefaults::TWITCURL_SAVEDSEARCHCREATE_URL +
 
                           twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];
 
 
    /* Send some dummy data in POST */
 
    std::string queryStr = twitCurlDefaults::TWITCURL_QUERYSTRING + urlencode( query );
 
 
    /* Perform POST */
 
    return performPost( buildUrl, queryStr );
 
}
 
 
 
/*++
 
* @method: twitCurl::savedSearchDestroy
 
*
 
* @description: method to destroy a saved search for the authenticated user. The search specified
 
*               by id must be owned by the authenticating user.
 
*
 
* @input: searchId - search id of item 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::savedSearchDestroy( std::string& searchId )
 
{
 
    /* Prepare URL */
 
    std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                           twitterDefaults::TWITCURL_SAVEDSEARCHDESTROY_URL + searchId +
 
                           twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];
 
 
    /* Perform DELETE */
 
    return performDelete( buildUrl );
 
}
 
 
 
/*++
 
* @method: twitCurl::trendsGet()
 
*
 
* @description: gets trends.
 
*
 
* @input: none
 
*
 
* @output: true if GET is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
*--*/
 
bool twitCurl::trendsGet()
 
{
 
    /* Perform GET */
 
    return performGet( twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                       twitterDefaults::TWITCURL_TRENDS_URL +
 
                       twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType] );
 
}
 
 
 
/*++
 
* @method: twitCurl::trendsDailyGet()
 
*
 
* @description: gets daily trends.
 
*
 
* @input: none
 
*
 
* @output: true if GET is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
*--*/
 
bool twitCurl::trendsDailyGet()
 
{
 
    /* Perform GET */
 
    return performGet( twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                       twitterDefaults::TWITCURL_TRENDSDAILY_URL +
 
                       twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType] );
 
}
 
 
/*++
 
* @method: twitCurl::trendsWeeklyGet()
 
*
 
* @description: gets weekly trends.
 
*
 
* @input: none
 
*
 
* @output: true if GET is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
*--*/
 
bool twitCurl::trendsWeeklyGet()
 
{
 
    /* Perform GET */
 
    return performGet( twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                       twitterDefaults::TWITCURL_TRENDSWEEKLY_URL +
 
                       twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType] );
 
}
 
 
/*++
 
* @method: twitCurl::trendsCurrentGet()
 
*
 
* @description: gets current trends.
 
*
 
* @input: none
 
*
 
* @output: true if GET is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
*--*/
 
bool twitCurl::trendsCurrentGet()
 
{
 
    /* Perform GET */
 
    return performGet( twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                       twitterDefaults::TWITCURL_TRENDSCURRENT_URL +
 
                       twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType] );
 
}
 
 
/*++
 
* @method: twitCurl::trendsAvailableGet()
 
*
 
* @description: gets available trends.
 
*
 
* @input: none
 
*
 
* @output: true if GET is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
*--*/
 
bool twitCurl::trendsAvailableGet()
 
{
 
    /* Perform GET */
 
    return performGet( twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                       twitterDefaults::TWITCURL_TRENDSAVAILABLE_URL +
 
                       twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType] );
 
}
 
 
/*++
 
* @method: twitCurl::getLastWebResponse
 
*
 
* @description: method to get http response for the most recent request sent.
 
*               twitcurl users need to call this method and parse the XML
 
*               data returned by twitter to see what has happened.
 
*
 
* @input: outWebResp - string in which twitter's response is supplied back to caller
 
*
 
* @output: none
 
*
 
*--*/
 
void twitCurl::getLastWebResponse( std::string& outWebResp )
 
{
 
    outWebResp = "";
 
    if( m_callbackData.length() )
 
    {
 
        outWebResp = m_callbackData;
 
    }
 
}
 
 
/*++
 
* @method: twitCurl::getLastCurlError
 
*
 
* @description: method to get cURL error response for most recent http request.
 
*               twitcurl users can call this method if any of the APIs return
 
*               false.
 
*
 
* @input: none
 
*
 
* @output: none
 
*
 
*--*/
 
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 )
 
{
 
    if( pTwitCurlObj && data )
 
    {
 
        /* Save http response in twitcurl object's buffer */
 
        return pTwitCurlObj->saveLastWebResponse( data, ( size*nmemb ) );
 
    }
 
    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 )
 
{
 
    if( data && size )
 
    {
 
        /* Append data in our internal buffer */
 
        m_callbackData.append( data, size );
 
        return (int)size;
 
    }
 
    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 )
 
    {
 
        return;
 
    }
 
 
    /* 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 );
 
 
    /* 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() );
 
 
    /* 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 )
 
    {
 
        return;
 
    }
 
 
    /* Set buffer to get error */
 
    curl_easy_setopt( m_curlHandle, CURLOPT_ERRORBUFFER, m_errorBuffer );
 
 
    /* 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 )
 
    {
 
        return;
 
    }
 
 
    /* Reset existing username and password stored in cURL */
 
    curl_easy_setopt( m_curlHandle, CURLOPT_USERPWD, "" );
 
 
    if( getTwitterUsername().size() )
 
    {
 
        /* Prepare username:password */
 
        std::string userNamePassword;
 
        utilMakeCurlParams( userNamePassword, getTwitterUsername(), getTwitterPassword() );
 
 
        /* 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, "" );
 
 
    /* 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
 
*
 
* @remarks: internal method
 
*
 
*--*/
 
bool twitCurl::performGet( const std::string& getUrl )
 
{
 
    /* Return if cURL is not initialized */
 
    if( !isCurlInit() )
 
    {
 
        return false;
 
    }
 
 
    std::string dataStrDummy;
 
    std::string oAuthHttpHeader;
 
    struct curl_slist* pOAuthHeaderList = NULL;
 
 
    /* Prepare standard params */
 
    prepareStandardParams();
 
 
    /* Set OAuth header */
 
    m_oAuth.getOAuthHeader( eOAuthHttpGet, getUrl, dataStrDummy, oAuthHttpHeader );
 
    if( oAuthHttpHeader.length() )
 
    {
 
        pOAuthHeaderList = curl_slist_append( pOAuthHeaderList, oAuthHttpHeader.c_str() );
 
        if( pOAuthHeaderList )
 
        {
 
            curl_easy_setopt( m_curlHandle, CURLOPT_HTTPHEADER, pOAuthHeaderList );
 
        }
 
    }
 
 
    /* 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::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::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 );
 
        }
 
    }
 
 
    /* 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::performDelete
 
*
 
* @description: method to send http DELETE request. this is an internal method.
 
*               twitcurl users should not use this method.
 
*
 
* @input: deleteUrl - url
 
*
 
* @output: none
 
*
 
* @remarks: internal method
 
*
 
*--*/
 
bool twitCurl::performDelete( const std::string& deleteUrl )
 
{
 
    /* Return if cURL is not initialized */
 
    if( !isCurlInit() )
 
    {
 
        return false;
 
    }
 
 
    std::string dataStrDummy;
 
    std::string oAuthHttpHeader;
 
    struct curl_slist* pOAuthHeaderList = NULL;
 
 
    /* Prepare standard params */
 
    prepareStandardParams();
 
 
    /* Set OAuth header */
 
    m_oAuth.getOAuthHeader( eOAuthHttpDelete, deleteUrl, dataStrDummy, oAuthHttpHeader );
 
    if( oAuthHttpHeader.length() )
 
    {
 
        pOAuthHeaderList = curl_slist_append( pOAuthHeaderList, oAuthHttpHeader.c_str() );
 
        if( pOAuthHeaderList )
 
        {
 
            curl_easy_setopt( m_curlHandle, CURLOPT_HTTPHEADER, pOAuthHeaderList );
 
        }
 
    }
 
 
    /* Set http request and url */
 
    curl_easy_setopt( m_curlHandle, CURLOPT_CUSTOMREQUEST, "DELETE" );
 
    curl_easy_setopt( m_curlHandle, CURLOPT_URL, deleteUrl.c_str() );
 
    curl_easy_setopt( m_curlHandle, CURLOPT_COPYPOSTFIELDS, dataStrDummy.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::performPost
 
*
 
* @description: method to send http POST request. this is an internal method.
 
*               twitcurl users should not use this method.
 
*
 
* @input: postUrl - url,
 
*         dataStr - url encoded data to be posted
 
*
 
* @output: none
 
*
 
* @remarks: internal method
 
*           data value in dataStr must already be url encoded.
 
*           ex: dataStr = "key=urlencode(value)"
 
*
 
*--*/
 
bool twitCurl::performPost( const std::string& postUrl, std::string dataStr )
 
{
 
    /* Return if cURL is not initialized */
 
    if( !isCurlInit() )
 
    {
 
        return false;
 
    }
 
 
    std::string oAuthHttpHeader;
 
    struct curl_slist* pOAuthHeaderList = NULL;
 
 
    /* Prepare standard params */
 
    prepareStandardParams();
 
 
    /* Set OAuth header */
 
    m_oAuth.getOAuthHeader( eOAuthHttpPost, postUrl, dataStr, oAuthHttpHeader );
 
    if( oAuthHttpHeader.length() )
 
    {
 
        pOAuthHeaderList = curl_slist_append( pOAuthHeaderList, oAuthHttpHeader.c_str() );
 
        if( pOAuthHeaderList )
 
        {
 
            curl_easy_setopt( m_curlHandle, CURLOPT_HTTPHEADER, pOAuthHeaderList );
 
        }
 
    }
 
 
    /* Set http request, url and data */
 
    curl_easy_setopt( m_curlHandle, CURLOPT_POST, 1 );
 
    curl_easy_setopt( m_curlHandle, CURLOPT_URL, postUrl.c_str() );
 
    if( dataStr.length() )
 
    {
 
        curl_easy_setopt( m_curlHandle, CURLOPT_COPYPOSTFIELDS, dataStr.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: utilMakeCurlParams
 
*
 
* @description: utility function to build parameter strings in the format
 
*               required by cURL ("param1:param2"). twitcurl users should
 
*               not use this function.
 
*
 
* @input: inParam1 - first parameter,
 
*         inParam2 - second parameter
 
*
 
* @output: outStr - built parameter
 
*
 
* @remarks: internal method
 
*
 
*--*/
 
void utilMakeCurlParams( std::string& outStr, std::string& inParam1, std::string& inParam2 )
 
{
 
    outStr = inParam1;
 
    outStr += twitCurlDefaults::TWITCURL_COLON + inParam2;
 
}
 
 
/*++
 
* @method: utilMakeUrlForUser
 
*
 
* @description: utility function to build url compatible to twitter. twitcurl
 
*               users should not use this function.
 
*
 
* @input: baseUrl - base twitter url,
 
*         userInfo - user name,
 
*         isUserId - indicates if userInfo contains a user id or scree name
 
*
 
* @output: outUrl - built url
 
*
 
* @remarks: internal method
 
*
 
*--*/
 
void utilMakeUrlForUser( std::string& outUrl, const std::string& baseUrl, std::string& userInfo, bool isUserId )
 
{
 
    /* Copy base URL */
 
    outUrl = baseUrl;
 
 
    if( userInfo.length() )
 
    {
 
        /* Append username to the URL */
 
        outUrl += twitCurlDefaults::TWITCURL_URL_SEP_QUES;
 
        if( isUserId )
 
        {
 
            outUrl += twitCurlDefaults::TWITCURL_USERID;
 
        }
 
        else
 
        {
 
            outUrl += twitCurlDefaults::TWITCURL_SCREENNAME;
 
        }
 
        outUrl += userInfo;
 
    }
 
}
 
 
/*++
 
* @method: twitCurl::getOAuth
 
*
 
* @description: method to get a reference to oAuth object.
 
*
 
* @input: none
 
*
 
* @output: reference to oAuth object
 
*
 
*--*/
 
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 */
 
    std::string oAuthHeader;
 
    authorizeUrl = "";
 
    if( m_oAuth.getOAuthHeader( eOAuthHttpGet,
 
                                twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                                oAuthTwitterApiUrls::OAUTHLIB_TWITTER_REQUEST_TOKEN_URL,
 
                                std::string( "" ),
 
                                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() );
 
 
            return true;
 
        }
 
    }
 
    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 */
 
    std::string oAuthHeader;
 
    if( m_oAuth.getOAuthHeader( eOAuthHttpGet,
 
                                twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                                oAuthTwitterApiUrls::OAUTHLIB_TWITTER_ACCESS_TOKEN_URL,
 
                                std::string( "" ),
 
                                oAuthHeader, true ) )
 
    {
 
        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 );
 
 
            return true;
 
        }
 
    }
 
    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;
 
    std::string authenticityTokenVal;
 
    std::string oauthTokenVal;
 
    std::string pinCodeVal;
 
    unsigned long httpStatusCode = 0;
 
    size_t nPosStart, nPosEnd;
 
    struct curl_slist* pOAuthHeaderList = NULL;
 
 
    /* Prepare standard params */
 
    prepareStandardParams();
 
 
    /* Set OAuth header */
 
    m_oAuth.getOAuthHeader( eOAuthHttpGet, authorizeUrl, dataStr, oAuthHttpHeader );
 
    if( oAuthHttpHeader.length() )
 
    {
 
        pOAuthHeaderList = curl_slist_append( pOAuthHeaderList, oAuthHttpHeader.c_str() );
 
        if( pOAuthHeaderList )
 
        {
 
            curl_easy_setopt( m_curlHandle, CURLOPT_HTTPHEADER, pOAuthHeaderList );
 
        }
 
    }
 
 
    /* Set http request and url */
 
    curl_easy_setopt( m_curlHandle, CURLOPT_HTTPGET, 1 );
 
    curl_easy_setopt( m_curlHandle, CURLOPT_URL, authorizeUrl.c_str() );
 
 
    /* Send http request */
 
    if( CURLE_OK == curl_easy_perform( m_curlHandle ) )
 
    {
 
        if( pOAuthHeaderList )
 
        {
 
            curl_easy_getinfo( m_curlHandle, CURLINFO_HTTP_CODE, &httpStatusCode );
 
            curl_slist_free_all( pOAuthHeaderList );
 
 
            // Now, let's find the authenticity token and oauth token
 
            nPosStart = m_callbackData.find( oAuthLibDefaults::OAUTHLIB_AUTHENTICITY_TOKEN_TWITTER_RESP_KEY );
 
            if( std::string::npos == nPosStart )
 
            {
 
                return false;
 
            }
 
            nPosStart += oAuthLibDefaults::OAUTHLIB_AUTHENTICITY_TOKEN_TWITTER_RESP_KEY.length();
 
            nPosEnd = m_callbackData.substr( nPosStart ).find( oAuthLibDefaults::OAUTHLIB_TOKEN_END_TAG_TWITTER_RESP );
 
            if( std::string::npos == nPosEnd )
 
            {
 
                return false;
 
            }
 
            authenticityTokenVal = m_callbackData.substr( nPosStart, nPosEnd );
 
 
            nPosStart = m_callbackData.find( oAuthLibDefaults::OAUTHLIB_TOKEN_TWITTER_RESP_KEY );
 
            if( std::string::npos == nPosStart )
 
            {
 
                return false;
 
            }
 
            nPosStart += oAuthLibDefaults::OAUTHLIB_TOKEN_TWITTER_RESP_KEY.length();
 
            nPosEnd = m_callbackData.substr( nPosStart ).find( oAuthLibDefaults::OAUTHLIB_TOKEN_END_TAG_TWITTER_RESP );
 
            if( std::string::npos == nPosEnd )
 
            {
 
                return false;
 
            }
 
            oauthTokenVal = m_callbackData.substr( nPosStart, nPosEnd );
 
        }
 
    }
 
    else if( pOAuthHeaderList )
 
    {
 
        curl_slist_free_all( pOAuthHeaderList );
 
        return false;
 
    }
 
 
    // Second phase for the authorization
 
    pOAuthHeaderList = NULL;
 
    oAuthHttpHeader.clear();
 
 
    /* Prepare standard params */
 
    prepareStandardParams();
 
 
    /*
 
    Now, we need to make a data string for POST operation
 
    which includes oauth token, authenticity token, username, password.
 
    */
 
    dataStr = oAuthLibDefaults::OAUTHLIB_TOKEN_KEY + "=" + oauthTokenVal + "&" +                      \
 
              oAuthLibDefaults::OAUTHLIB_AUTHENTICITY_TOKEN_KEY + "=" + authenticityTokenVal + "&" +  \
 
              oAuthLibDefaults::OAUTHLIB_SESSIONUSERNAME_KEY + "=" + getTwitterUsername() + "&" +     \
 
              oAuthLibDefaults::OAUTHLIB_SESSIONPASSWORD_KEY + "=" + getTwitterPassword();
 
 
    /* Set OAuth header */
 
    m_oAuth.getOAuthHeader( eOAuthHttpPost, authorizeUrl, dataStr, oAuthHttpHeader );
 
    if( oAuthHttpHeader.length() )
 
    {
 
        pOAuthHeaderList = curl_slist_append( pOAuthHeaderList, oAuthHttpHeader.c_str() );
 
        if( pOAuthHeaderList )
 
        {
 
            curl_easy_setopt( m_curlHandle, CURLOPT_HTTPHEADER, pOAuthHeaderList );
 
        }
 
    }
 
 
    /* Set http request and url */
 
    curl_easy_setopt( m_curlHandle, CURLOPT_POST, 1 );
 
    curl_easy_setopt( m_curlHandle, CURLOPT_URL, authorizeUrl.c_str() );
 
    curl_easy_setopt( m_curlHandle, CURLOPT_COPYPOSTFIELDS, dataStr.c_str() );
 
 
    /* Send http request */
 
    if( CURLE_OK == curl_easy_perform( m_curlHandle ) )
 
    {
 
        if( pOAuthHeaderList )
 
        {
 
            curl_easy_getinfo( m_curlHandle, CURLINFO_HTTP_CODE, &httpStatusCode );
 
            curl_slist_free_all( pOAuthHeaderList );
 
 
            // 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;
 
}
 
 
#define NOMINMAX
 
#include <memory.h>
 
#include "twitcurlurls.h"
 
#include "twitcurl.h"
 
#include "urlencode.h"
 

	
 
/*++
 
* @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::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_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);
 

	
 
    /* Twitter data */
 
    cloneObj->setTwitterUsername(m_twitterUsername);
 
    cloneObj->setTwitterPassword(m_twitterPassword);
 

	
 
    /* OAuth data */
 
    cloneObj->m_oAuth = m_oAuth.clone();
 

	
 
    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
 
*
 
* @output: twitter username
 
*
 
*--*/
 
std::string& twitCurl::getTwitterUsername()
 
{
 
    return m_twitterUsername;
 
}
 

	
 
/*++
 
* @method: twitCurl::getTwitterPassword
 
*
 
* @description: method to get stored Twitter password
 
*
 
* @input: none
 
*
 
* @output: twitter password
 
*
 
*--*/
 
std::string& twitCurl::getTwitterPassword()
 
{
 
    return m_twitterPassword;
 
}
 

	
 
/*++
 
* @method: twitCurl::setTwitterUsername
 
*
 
* @description: method to set username
 
*
 
* @input: userName
 
*
 
* @output: none
 
*
 
*--*/
 
void twitCurl::setTwitterUsername( std::string& userName )
 
{
 
    if( userName.length() )
 
    {
 
        m_twitterUsername = userName;
 
        m_curlLoginParamsSet = false;
 
    }
 
}
 

	
 
/*++
 
* @method: twitCurl::setTwitterPassword
 
*
 
* @description: method to set password
 
*
 
* @input: passWord
 
*
 
* @output: none
 
*
 
*--*/
 
void twitCurl::setTwitterPassword( std::string& passWord )
 
{
 
    if( passWord.length() )
 
    {
 
        m_twitterPassword = passWord;
 
        m_curlLoginParamsSet = false;
 
    }
 
}
 

	
 
/*++
 
* @method: twitCurl::getProxyServerIp
 
*
 
* @description: method to get proxy server IP address
 
*
 
* @input: none
 
*
 
* @output: proxy server IP address
 
*
 
*--*/
 
std::string& twitCurl::getProxyServerIp()
 
{
 
    return m_proxyServerIp;
 
}
 

	
 
/*++
 
* @method: twitCurl::getProxyServerPort
 
*
 
* @description: method to get proxy server port
 
*
 
* @input: none
 
*
 
* @output: proxy server port
 
*
 
*--*/
 
std::string& twitCurl::getProxyServerPort()
 
{
 
    return m_proxyServerPort;
 
}
 

	
 
/*++
 
* @method: twitCurl::getProxyUserName
 
*
 
* @description: method to get proxy user name
 
*
 
* @input: none
 
*
 
* @output: proxy server user name
 
*
 
*--*/
 
std::string& twitCurl::getProxyUserName()
 
{
 
    return m_proxyUserName;
 
}
 

	
 
/*++
 
* @method: twitCurl::getProxyPassword
 
*
 
* @description: method to get proxy server password
 
*
 
* @input: none
 
*
 
* @output: proxy server password
 
*
 
*--*/
 
std::string& twitCurl::getProxyPassword()
 
{
 
    return m_proxyPassword;
 
}
 

	
 
/*++
 
* @method: twitCurl::setProxyServerIp
 
*
 
* @description: method to set proxy server IP address
 
*
 
* @input: proxyServerIp
 
*
 
* @output: none
 
*
 
*--*/
 
void twitCurl::setProxyServerIp( std::string& proxyServerIp )
 
{
 
    if( proxyServerIp.length() )
 
    {
 
        m_proxyServerIp = proxyServerIp;
 
        /*
 
         * Reset the flag so that next cURL http request
 
         * would set proxy details again into cURL.
 
         */
 
        m_curlProxyParamsSet = false;
 
    }
 
}
 

	
 
/*++
 
* @method: twitCurl::setProxyServerPort
 
*
 
* @description: method to set proxy server port
 
*
 
* @input: proxyServerPort
 
*
 
* @output: none
 
*
 
*--*/
 
void twitCurl::setProxyServerPort( std::string& proxyServerPort )
 
{
 
    if( proxyServerPort.length() )
 
    {
 
        m_proxyServerPort = proxyServerPort;
 
        /*
 
         * Reset the flag so that next cURL http request
 
         * would set proxy details again into cURL.
 
         */
 
        m_curlProxyParamsSet = false;
 
    }
 
}
 

	
 
/*++
 
* @method: twitCurl::setProxyUserName
 
*
 
* @description: method to set proxy server username
 
*
 
* @input: proxyUserName
 
*
 
* @output: none
 
*
 
*--*/
 
void twitCurl::setProxyUserName( std::string& proxyUserName )
 
{
 
    if( proxyUserName.length() )
 
    {
 
        m_proxyUserName = proxyUserName;
 
        /*
 
         * Reset the flag so that next cURL http request
 
         * would set proxy details again into cURL.
 
         */
 
        m_curlProxyParamsSet = false;
 
    }
 
}
 

	
 
/*++
 
* @method: twitCurl::setProxyPassword
 
*
 
* @description: method to set proxy server password
 
*
 
* @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, std::string resultCount )
 
{
 
    /* Prepare URL */
 
    std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                           twitterDefaults::TWITCURL_SEARCH_URL +
 
                           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 - 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, std::string inReplyToStatusId )
 
{
 
    if( newStatus.empty() )
 
    {
 
        return false;
 
    }
 

	
 
    /* 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 );
 
    }
 

	
 
    /* 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 )
 
{
 
    if( statusId.empty() )
 
    {
 
        return false;
 
    }
 

	
 
    /* 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 )
 
{
 
    if( statusId.empty() )
 
    {
 
        return false;
 
    }
 

	
 
    /* 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 )
 
{
 
    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" ) );
 

	
 
    /* 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];
 
    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] );
 
}
 

	
 
/*++
 
* @method: twitCurl::featuredUsersGet
 
*
 
* @description: method to get featured users
 
*
 
* @input: none
 
*
 
* @output: true if GET is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
*--*/
 
bool twitCurl::featuredUsersGet()
 
{
 
    /* Perform GET */
 
    return performGet( twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                       twitterDefaults::TWITCURL_FEATURED_USERS_URL +
 
                       twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType] );
 
}
 

	
 
/*++
 
* @method: twitCurl::timelineFriendsGet
 
*
 
* @description: method to get friends 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::timelineFriendsGet()
 
{
 
    /* Perform GET */
 
    return performGet( twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                       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 )
 
{
 
    /* 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.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 )
 
{
 
    if( userInfo.empty() )
 
    {
 
        return false;
 
    }
 

	
 
    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];
 
    }
 

	
 
    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 )
 
{
 
    if( userInfo.empty() )
 
    {
 
        return false;
 
    }
 

	
 
    /* 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 */
 
    return performGet( buildUrl );
 
}
 

	
 
/*++
 
* @method: twitCurl::followersGet
 
*
 
* @description: method to get a user's followers
 
*
 
* @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::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;
 
    }
 

	
 
    /* 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 )
 
{
 
    if( userInfo.empty() || dMsg.empty() )
 
    {
 
        return false;
 
    }
 

	
 
    /* Prepare new direct message */
 
    std::string newDm = twitCurlDefaults::TWITCURL_TEXTSTRING + urlencode( dMsg );
 

	
 
    /* 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 )
 
{
 
    if( dMsgId.empty() )
 
    {
 
        return false;
 
    }
 

	
 
    /* 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 )
 
{
 
    if( userInfo.empty() )
 
    {
 
        return false;
 
    }
 

	
 
    /* Prepare URL */
 
    std::string buildUrl;
 
    utilMakeUrlForUser( buildUrl, twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                        twitterDefaults::TWITCURL_FRIENDSHIPSCREATE_URL +
 
                        twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType],
 
                        userInfo, isUserId );
 

	
 
    /* 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 )
 
{
 
    if( userInfo.empty() )
 
    {
 
        return false;
 
    }
 

	
 
    /* 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& 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& 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] );
 
}
 

	
 
/*++
 
* @method: twitCurl::accountVerifyCredGet
 
*
 
* @description: method to get information on user identified by given credentials
 
*
 
* @input: none
 
*
 
* @output: true if GET is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
*--*/
 
bool twitCurl::accountVerifyCredGet()
 
{
 
    /* Perform GET */
 
    return performGet( twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                       twitterDefaults::TWITCURL_ACCOUNTVERIFYCRED_URL +
 
                       twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType] );
 
}
 

	
 
/*++
 
* @method: twitCurl::favoriteGet
 
*
 
* @description: method to get favorite users' statuses
 
*
 
* @input: none
 
*
 
* @output: true if GET is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
*--*/
 
bool twitCurl::favoriteGet()
 
{
 
    /* Perform GET */
 
    return performGet( twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                       twitterDefaults::TWITCURL_FAVORITESGET_URL +
 
                       twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType] );
 
}
 

	
 
/*++
 
* @method: twitCurl::favoriteCreate
 
*
 
* @description: method to favorite a status message
 
*
 
* @input: statusId - id in string format of the status to be favorited
 
*
 
* @output: true if POST is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
*--*/
 
bool twitCurl::favoriteCreate( std::string& statusId )
 
{
 
    /* Prepare URL */
 
    std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                           twitterDefaults::TWITCURL_FAVORITECREATE_URL + statusId +
 
                           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::favoriteDestroy
 
*
 
* @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 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 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.
 
*
 
* @input: searchId - id in string format of the search to be displayed
 
*
 
* @output: true if GET is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
*--*/
 
bool twitCurl::savedSearchShow( std::string& searchId )
 
{
 
    /* Prepare URL */
 
    std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                           twitterDefaults::TWITCURL_SAVEDSEARCHSHOW_URL + searchId +
 
                           twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];
 

	
 
    /* Perform GET */
 
    return performGet( buildUrl );
 
}
 

	
 
/*++
 
* @method: twitCurl::savedSearchCreate
 
*
 
* @description: creates a saved search for the authenticated user
 
*
 
* @input: query - the query of the search the user would like to save
 
*
 
* @output: true if POST is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
*--*/
 
bool twitCurl::savedSearchCreate( std::string& query )
 
{
 
    /* Prepare URL */
 
    std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                           twitterDefaults::TWITCURL_SAVEDSEARCHCREATE_URL +
 
                           twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];
 

	
 
    /* Send some dummy data in POST */
 
    std::string queryStr = twitCurlDefaults::TWITCURL_QUERYSTRING + urlencode( query );
 

	
 
    /* Perform POST */
 
    return performPost( buildUrl, queryStr );
 
}
 

	
 

	
 
/*++
 
* @method: twitCurl::savedSearchDestroy
 
*
 
* @description: method to destroy a saved search for the authenticated user. The search specified
 
*               by id must be owned by the authenticating user.
 
*
 
* @input: searchId - search id of item 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::savedSearchDestroy( std::string& searchId )
 
{
 
    /* Prepare URL */
 
    std::string buildUrl = twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                           twitterDefaults::TWITCURL_SAVEDSEARCHDESTROY_URL + searchId +
 
                           twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType];
 

	
 
    /* Perform DELETE */
 
    return performDelete( buildUrl );
 
}
 

	
 

	
 
/*++
 
* @method: twitCurl::trendsGet()
 
*
 
* @description: gets trends.
 
*
 
* @input: none
 
*
 
* @output: true if GET is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
*--*/
 
bool twitCurl::trendsGet()
 
{
 
    /* Perform GET */
 
    return performGet( twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                       twitterDefaults::TWITCURL_TRENDS_URL +
 
                       twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType] );
 
}
 

	
 

	
 
/*++
 
* @method: twitCurl::trendsDailyGet()
 
*
 
* @description: gets daily trends.
 
*
 
* @input: none
 
*
 
* @output: true if GET is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
*--*/
 
bool twitCurl::trendsDailyGet()
 
{
 
    /* Perform GET */
 
    return performGet( twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                       twitterDefaults::TWITCURL_TRENDSDAILY_URL +
 
                       twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType] );
 
}
 

	
 
/*++
 
* @method: twitCurl::trendsWeeklyGet()
 
*
 
* @description: gets weekly trends.
 
*
 
* @input: none
 
*
 
* @output: true if GET is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
*--*/
 
bool twitCurl::trendsWeeklyGet()
 
{
 
    /* Perform GET */
 
    return performGet( twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                       twitterDefaults::TWITCURL_TRENDSWEEKLY_URL +
 
                       twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType] );
 
}
 

	
 
/*++
 
* @method: twitCurl::trendsCurrentGet()
 
*
 
* @description: gets current trends.
 
*
 
* @input: none
 
*
 
* @output: true if GET is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
*--*/
 
bool twitCurl::trendsCurrentGet()
 
{
 
    /* Perform GET */
 
    return performGet( twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                       twitterDefaults::TWITCURL_TRENDSCURRENT_URL +
 
                       twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType] );
 
}
 

	
 
/*++
 
* @method: twitCurl::trendsAvailableGet()
 
*
 
* @description: gets available trends.
 
*
 
* @input: none
 
*
 
* @output: true if GET is success, otherwise false. This does not check http
 
*          response by twitter. Use getLastWebResponse() for that.
 
*
 
*--*/
 
bool twitCurl::trendsAvailableGet()
 
{
 
    /* Perform GET */
 
    return performGet( twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                       twitterDefaults::TWITCURL_TRENDSAVAILABLE_URL +
 
                       twitCurlDefaults::TWITCURL_EXTENSIONFORMATS[m_eApiFormatType] );
 
}
 

	
 
/*++
 
* @method: twitCurl::getLastWebResponse
 
*
 
* @description: method to get http response for the most recent request sent.
 
*               twitcurl users need to call this method and parse the XML
 
*               data returned by twitter to see what has happened.
 
*
 
* @input: outWebResp - string in which twitter's response is supplied back to caller
 
*
 
* @output: none
 
*
 
*--*/
 
void twitCurl::getLastWebResponse( std::string& outWebResp )
 
{
 
    outWebResp = "";
 
    if( m_callbackData.length() )
 
    {
 
        outWebResp = m_callbackData;
 
    }
 
}
 

	
 
/*++
 
* @method: twitCurl::getLastCurlError
 
*
 
* @description: method to get cURL error response for most recent http request.
 
*               twitcurl users can call this method if any of the APIs return
 
*               false.
 
*
 
* @input: none
 
*
 
* @output: none
 
*
 
*--*/
 
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 )
 
{
 
    if( pTwitCurlObj && data )
 
    {
 
        /* Save http response in twitcurl object's buffer */
 
        return pTwitCurlObj->saveLastWebResponse( data, ( size*nmemb ) );
 
    }
 
    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 )
 
{
 
    if( data && size )
 
    {
 
        /* Append data in our internal buffer */
 
        m_callbackData.append( data, size );
 
        return (int)size;
 
    }
 
    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 )
 
    {
 
        return;
 
    }
 

	
 
    /* 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 );
 

	
 
    /* 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() );
 

	
 
    /* 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 )
 
    {
 
        return;
 
    }
 

	
 
    /* Set buffer to get error */
 
    curl_easy_setopt( m_curlHandle, CURLOPT_ERRORBUFFER, m_errorBuffer );
 

	
 
    /* 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 )
 
    {
 
        return;
 
    }
 

	
 
    /* Reset existing username and password stored in cURL */
 
    curl_easy_setopt( m_curlHandle, CURLOPT_USERPWD, "" );
 

	
 
    if( getTwitterUsername().size() )
 
    {
 
        /* Prepare username:password */
 
        std::string userNamePassword;
 
        utilMakeCurlParams( userNamePassword, getTwitterUsername(), getTwitterPassword() );
 

	
 
        /* 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, "" );
 

	
 
    /* 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
 
*
 
* @remarks: internal method
 
*
 
*--*/
 
bool twitCurl::performGet( const std::string& getUrl )
 
{
 
    /* Return if cURL is not initialized */
 
    if( !isCurlInit() )
 
    {
 
        return false;
 
    }
 

	
 
    std::string dataStrDummy;
 
    std::string oAuthHttpHeader;
 
    struct curl_slist* pOAuthHeaderList = NULL;
 

	
 
    /* Prepare standard params */
 
    prepareStandardParams();
 

	
 
    /* Set OAuth header */
 
    m_oAuth.getOAuthHeader( eOAuthHttpGet, getUrl, dataStrDummy, oAuthHttpHeader );
 
    if( oAuthHttpHeader.length() )
 
    {
 
        pOAuthHeaderList = curl_slist_append( pOAuthHeaderList, oAuthHttpHeader.c_str() );
 
        if( pOAuthHeaderList )
 
        {
 
            curl_easy_setopt( m_curlHandle, CURLOPT_HTTPHEADER, pOAuthHeaderList );
 
        }
 
    }
 

	
 
    /* 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::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::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 );
 
        }
 
    }
 

	
 
    /* 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::performDelete
 
*
 
* @description: method to send http DELETE request. this is an internal method.
 
*               twitcurl users should not use this method.
 
*
 
* @input: deleteUrl - url
 
*
 
* @output: none
 
*
 
* @remarks: internal method
 
*
 
*--*/
 
bool twitCurl::performDelete( const std::string& deleteUrl )
 
{
 
    /* Return if cURL is not initialized */
 
    if( !isCurlInit() )
 
    {
 
        return false;
 
    }
 

	
 
    std::string dataStrDummy;
 
    std::string oAuthHttpHeader;
 
    struct curl_slist* pOAuthHeaderList = NULL;
 

	
 
    /* Prepare standard params */
 
    prepareStandardParams();
 

	
 
    /* Set OAuth header */
 
    m_oAuth.getOAuthHeader( eOAuthHttpDelete, deleteUrl, dataStrDummy, oAuthHttpHeader );
 
    if( oAuthHttpHeader.length() )
 
    {
 
        pOAuthHeaderList = curl_slist_append( pOAuthHeaderList, oAuthHttpHeader.c_str() );
 
        if( pOAuthHeaderList )
 
        {
 
            curl_easy_setopt( m_curlHandle, CURLOPT_HTTPHEADER, pOAuthHeaderList );
 
        }
 
    }
 

	
 
    /* Set http request and url */
 
    curl_easy_setopt( m_curlHandle, CURLOPT_CUSTOMREQUEST, "DELETE" );
 
    curl_easy_setopt( m_curlHandle, CURLOPT_URL, deleteUrl.c_str() );
 
    curl_easy_setopt( m_curlHandle, CURLOPT_COPYPOSTFIELDS, dataStrDummy.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::performPost
 
*
 
* @description: method to send http POST request. this is an internal method.
 
*               twitcurl users should not use this method.
 
*
 
* @input: postUrl - url,
 
*         dataStr - url encoded data to be posted
 
*
 
* @output: none
 
*
 
* @remarks: internal method
 
*           data value in dataStr must already be url encoded.
 
*           ex: dataStr = "key=urlencode(value)"
 
*
 
*--*/
 
bool twitCurl::performPost( const std::string& postUrl, std::string dataStr )
 
{
 
    /* Return if cURL is not initialized */
 
    if( !isCurlInit() )
 
    {
 
        return false;
 
    }
 

	
 
    std::string oAuthHttpHeader;
 
    struct curl_slist* pOAuthHeaderList = NULL;
 

	
 
    /* Prepare standard params */
 
    prepareStandardParams();
 

	
 
    /* Set OAuth header */
 
    m_oAuth.getOAuthHeader( eOAuthHttpPost, postUrl, dataStr, oAuthHttpHeader );
 
    if( oAuthHttpHeader.length() )
 
    {
 
        pOAuthHeaderList = curl_slist_append( pOAuthHeaderList, oAuthHttpHeader.c_str() );
 
        if( pOAuthHeaderList )
 
        {
 
            curl_easy_setopt( m_curlHandle, CURLOPT_HTTPHEADER, pOAuthHeaderList );
 
        }
 
    }
 

	
 
    /* Set http request, url and data */
 
    curl_easy_setopt( m_curlHandle, CURLOPT_POST, 1 );
 
    curl_easy_setopt( m_curlHandle, CURLOPT_URL, postUrl.c_str() );
 
    if( dataStr.length() )
 
    {
 
        curl_easy_setopt( m_curlHandle, CURLOPT_COPYPOSTFIELDS, dataStr.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: utilMakeCurlParams
 
*
 
* @description: utility function to build parameter strings in the format
 
*               required by cURL ("param1:param2"). twitcurl users should
 
*               not use this function.
 
*
 
* @input: inParam1 - first parameter,
 
*         inParam2 - second parameter
 
*
 
* @output: outStr - built parameter
 
*
 
* @remarks: internal method
 
*
 
*--*/
 
void utilMakeCurlParams( std::string& outStr, std::string& inParam1, std::string& inParam2 )
 
{
 
    outStr = inParam1;
 
    outStr += twitCurlDefaults::TWITCURL_COLON + inParam2;
 
}
 

	
 
/*++
 
* @method: utilMakeUrlForUser
 
*
 
* @description: utility function to build url compatible to twitter. twitcurl
 
*               users should not use this function.
 
*
 
* @input: baseUrl - base twitter url,
 
*         userInfo - user name,
 
*         isUserId - indicates if userInfo contains a user id or scree name
 
*
 
* @output: outUrl - built url
 
*
 
* @remarks: internal method
 
*
 
*--*/
 
void utilMakeUrlForUser( std::string& outUrl, const std::string& baseUrl, std::string& userInfo, bool isUserId )
 
{
 
    /* Copy base URL */
 
    outUrl = baseUrl;
 

	
 
    if( userInfo.length() )
 
    {
 
        /* Append username to the URL */
 
        outUrl += twitCurlDefaults::TWITCURL_URL_SEP_QUES;
 
        if( isUserId )
 
        {
 
            outUrl += twitCurlDefaults::TWITCURL_USERID;
 
        }
 
        else
 
        {
 
            outUrl += twitCurlDefaults::TWITCURL_SCREENNAME;
 
        }
 
        outUrl += userInfo;
 
    }
 
}
 

	
 
/*++
 
* @method: twitCurl::getOAuth
 
*
 
* @description: method to get a reference to oAuth object.
 
*
 
* @input: none
 
*
 
* @output: reference to oAuth object
 
*
 
*--*/
 
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 */
 
    std::string oAuthHeader;
 
    authorizeUrl = "";
 
    if( m_oAuth.getOAuthHeader( eOAuthHttpGet,
 
                                twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                                oAuthTwitterApiUrls::OAUTHLIB_TWITTER_REQUEST_TOKEN_URL,
 
                                std::string( "" ),
 
                                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() );
 

	
 
            return true;
 
        }
 
    }
 
    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 */
 
    std::string oAuthHeader;
 
    if( m_oAuth.getOAuthHeader( eOAuthHttpGet,
 
                                twitCurlDefaults::TWITCURL_PROTOCOLS[m_eProtocolType] +
 
                                oAuthTwitterApiUrls::OAUTHLIB_TWITTER_ACCESS_TOKEN_URL,
 
                                std::string( "" ),
 
                                oAuthHeader, true ) )
 
    {
 
        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 );
 

	
 
            return true;
 
        }
 
    }
 
    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;
 
    std::string authenticityTokenVal;
 
    std::string oauthTokenVal;
 
    std::string pinCodeVal;
 
    unsigned long httpStatusCode = 0;
 
    size_t nPosStart, nPosEnd;
 
    struct curl_slist* pOAuthHeaderList = NULL;
 

	
 
    /* Prepare standard params */
 
    prepareStandardParams();
 

	
 
    /* Set OAuth header */
 
    m_oAuth.getOAuthHeader( eOAuthHttpGet, authorizeUrl, dataStr, oAuthHttpHeader );
 
    if( oAuthHttpHeader.length() )
 
    {
 
        pOAuthHeaderList = curl_slist_append( pOAuthHeaderList, oAuthHttpHeader.c_str() );
 
        if( pOAuthHeaderList )
 
        {
 
            curl_easy_setopt( m_curlHandle, CURLOPT_HTTPHEADER, pOAuthHeaderList );
 
        }
 
    }
 

	
 
    /* Set http request and url */
 
    curl_easy_setopt( m_curlHandle, CURLOPT_HTTPGET, 1 );
 
    curl_easy_setopt( m_curlHandle, CURLOPT_URL, authorizeUrl.c_str() );
 

	
 
    /* Send http request */
 
    if( CURLE_OK == curl_easy_perform( m_curlHandle ) )
 
    {
 
        if( pOAuthHeaderList )
 
        {
 
            curl_easy_getinfo( m_curlHandle, CURLINFO_HTTP_CODE, &httpStatusCode );
 
            curl_slist_free_all( pOAuthHeaderList );
 

	
 
            // Now, let's find the authenticity token and oauth token
 
            nPosStart = m_callbackData.find( oAuthLibDefaults::OAUTHLIB_AUTHENTICITY_TOKEN_TWITTER_RESP_KEY );
 
            if( std::string::npos == nPosStart )
 
            {
 
                return false;
 
            }
 
            nPosStart += oAuthLibDefaults::OAUTHLIB_AUTHENTICITY_TOKEN_TWITTER_RESP_KEY.length();
 
            nPosEnd = m_callbackData.substr( nPosStart ).find( oAuthLibDefaults::OAUTHLIB_TOKEN_END_TAG_TWITTER_RESP );
 
            if( std::string::npos == nPosEnd )
 
            {
 
                return false;
 
            }
 
            authenticityTokenVal = m_callbackData.substr( nPosStart, nPosEnd );
 

	
 
            nPosStart = m_callbackData.find( oAuthLibDefaults::OAUTHLIB_TOKEN_TWITTER_RESP_KEY );
 
            if( std::string::npos == nPosStart )
 
            {
 
                return false;
 
            }
 
            nPosStart += oAuthLibDefaults::OAUTHLIB_TOKEN_TWITTER_RESP_KEY.length();
 
            nPosEnd = m_callbackData.substr( nPosStart ).find( oAuthLibDefaults::OAUTHLIB_TOKEN_END_TAG_TWITTER_RESP );
 
            if( std::string::npos == nPosEnd )
 
            {
 
                return false;
 
            }
 
            oauthTokenVal = m_callbackData.substr( nPosStart, nPosEnd );
 
        }
 
    }
 
    else if( pOAuthHeaderList )
 
    {
 
        curl_slist_free_all( pOAuthHeaderList );
 
        return false;
 
    }
 

	
 
    // Second phase for the authorization
 
    pOAuthHeaderList = NULL;
 
    oAuthHttpHeader.clear();
 

	
 
    /* Prepare standard params */
 
    prepareStandardParams();
 

	
 
    /*
 
    Now, we need to make a data string for POST operation
 
    which includes oauth token, authenticity token, username, password.
 
    */
 
    dataStr = oAuthLibDefaults::OAUTHLIB_TOKEN_KEY + "=" + oauthTokenVal + "&" +                      \
 
              oAuthLibDefaults::OAUTHLIB_AUTHENTICITY_TOKEN_KEY + "=" + authenticityTokenVal + "&" +  \
 
              oAuthLibDefaults::OAUTHLIB_SESSIONUSERNAME_KEY + "=" + getTwitterUsername() + "&" +     \
 
              oAuthLibDefaults::OAUTHLIB_SESSIONPASSWORD_KEY + "=" + getTwitterPassword();
 

	
 
    /* Set OAuth header */
 
    m_oAuth.getOAuthHeader( eOAuthHttpPost, authorizeUrl, dataStr, oAuthHttpHeader );
 
    if( oAuthHttpHeader.length() )
 
    {
 
        pOAuthHeaderList = curl_slist_append( pOAuthHeaderList, oAuthHttpHeader.c_str() );
 
        if( pOAuthHeaderList )
 
        {
 
            curl_easy_setopt( m_curlHandle, CURLOPT_HTTPHEADER, pOAuthHeaderList );
 
        }
 
    }
 

	
 
    /* Set http request and url */
 
    curl_easy_setopt( m_curlHandle, CURLOPT_POST, 1 );
 
    curl_easy_setopt( m_curlHandle, CURLOPT_URL, authorizeUrl.c_str() );
 
    curl_easy_setopt( m_curlHandle, CURLOPT_COPYPOSTFIELDS, dataStr.c_str() );
 

	
 
    /* Send http request */
 
    if( CURLE_OK == curl_easy_perform( m_curlHandle ) )
 
    {
 
        if( pOAuthHeaderList )
 
        {
 
            curl_easy_getinfo( m_curlHandle, CURLINFO_HTTP_CODE, &httpStatusCode );
 
            curl_slist_free_all( pOAuthHeaderList );
 

	
 
            // 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.dsp
Show inline comments
 
# Microsoft Developer Studio Project File - Name="twitcurl" - Package Owner=<4>
 
# Microsoft Developer Studio Generated Build File, Format Version 6.00
 
# ** DO NOT EDIT **
 
 
# TARGTYPE "Win32 (x86) Static Library" 0x0104
 
 
CFG=twitcurl - Win32 Debug
 
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
 
!MESSAGE use the Export Makefile command and run
 
!MESSAGE 
 
!MESSAGE NMAKE /f "twitcurl.mak".
 
!MESSAGE 
 
!MESSAGE You can specify a configuration when running NMAKE
 
!MESSAGE by defining the macro CFG on the command line. For example:
 
!MESSAGE 
 
!MESSAGE NMAKE /f "twitcurl.mak" CFG="twitcurl - Win32 Debug"
 
!MESSAGE 
 
!MESSAGE Possible choices for configuration are:
 
!MESSAGE 
 
!MESSAGE "twitcurl - Win32 Release" (based on "Win32 (x86) Static Library")
 
!MESSAGE "twitcurl - Win32 Debug" (based on "Win32 (x86) Static Library")
 
!MESSAGE 
 
 
# Begin Project
 
# PROP AllowPerConfigDependencies 0
 
# PROP Scc_ProjName ""
 
# PROP Scc_LocalPath ""
 
CPP=cl.exe
 
RSC=rc.exe
 
 
!IF  "$(CFG)" == "twitcurl - Win32 Release"
 
 
# PROP BASE Use_MFC 0
 
# PROP BASE Use_Debug_Libraries 0
 
# PROP BASE Output_Dir "Release"
 
# PROP BASE Intermediate_Dir "Release"
 
# PROP BASE Target_Dir ""
 
# PROP Use_MFC 0
 
# PROP Use_Debug_Libraries 0
 
# PROP Output_Dir "Release"
 
# PROP Intermediate_Dir "Release"
 
# PROP Target_Dir ""
 
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
 
# ADD CPP /nologo /W3 /GX /O2 /I "./curl" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
 
# ADD BASE RSC /l 0x409 /d "NDEBUG"
 
# ADD RSC /l 0x409 /d "NDEBUG"
 
BSC32=bscmake.exe
 
# ADD BASE BSC32 /nologo
 
# ADD BSC32 /nologo
 
LIB32=link.exe -lib
 
# ADD BASE LIB32 /nologo
 
# ADD LIB32 /nologo
 
 
!ELSEIF  "$(CFG)" == "twitcurl - Win32 Debug"
 
 
# PROP BASE Use_MFC 0
 
# PROP BASE Use_Debug_Libraries 1
 
# PROP BASE Output_Dir "Debug"
 
# PROP BASE Intermediate_Dir "Debug"
 
# PROP BASE Target_Dir ""
 
# PROP Use_MFC 0
 
# PROP Use_Debug_Libraries 1
 
# PROP Output_Dir "Debug"
 
# PROP Intermediate_Dir "Debug"
 
# PROP Target_Dir ""
 
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
 
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "./curl" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
 
# ADD BASE RSC /l 0x409 /d "_DEBUG"
 
# ADD RSC /l 0x409 /d "_DEBUG"
 
BSC32=bscmake.exe
 
# ADD BASE BSC32 /nologo
 
# ADD BSC32 /nologo
 
LIB32=link.exe -lib
 
# ADD BASE LIB32 /nologo
 
# ADD LIB32 /nologo
 
 
!ENDIF 
 
 
# Begin Target
 
 
# Name "twitcurl - Win32 Release"
 
# Name "twitcurl - Win32 Debug"
 
# Begin Group "Source Files"
 
 
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
 
# Begin Source File
 
 
SOURCE=.\base64.cpp
 
# End Source File
 
# Begin Source File
 
 
SOURCE=.\HMAC_SHA1.cpp
 
# End Source File
 
# Begin Source File
 
 
SOURCE=.\oauthlib.cpp
 
# End Source File
 
# Begin Source File
 
 
SOURCE=.\SHA1.cpp
 
# End Source File
 
# Begin Source File
 
 
SOURCE=.\twitcurl.cpp
 
# End Source File
 
# Begin Source File
 
 
SOURCE=.\urlencode.cpp
 
# End Source File
 
# End Group
 
# Begin Group "Header Files"
 
 
# PROP Default_Filter "h;hpp;hxx;hm;inl"
 
# Begin Source File
 
 
SOURCE=.\base64.h
 
# End Source File
 
# Begin Source File
 
 
SOURCE=.\HMAC_SHA1.h
 
# End Source File
 
# Begin Source File
 
 
SOURCE=.\oauthlib.h
 
# End Source File
 
# Begin Source File
 
 
SOURCE=.\SHA1.h
 
# End Source File
 
# Begin Source File
 
 
SOURCE=.\twitcurl.h
 
# End Source File
 
# Begin Source File
 
 
SOURCE=.\urlencode.h
 
# End Source File
 
# End Group
 
# End Target
 
# End Project
 
# Microsoft Developer Studio Project File - Name="twitcurl" - Package Owner=<4>
 
# Microsoft Developer Studio Generated Build File, Format Version 6.00
 
# ** DO NOT EDIT **
 

	
 
# TARGTYPE "Win32 (x86) Static Library" 0x0104
 

	
 
CFG=twitcurl - Win32 Debug
 
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
 
!MESSAGE use the Export Makefile command and run
 
!MESSAGE 
 
!MESSAGE NMAKE /f "twitcurl.mak".
 
!MESSAGE 
 
!MESSAGE You can specify a configuration when running NMAKE
 
!MESSAGE by defining the macro CFG on the command line. For example:
 
!MESSAGE 
 
!MESSAGE NMAKE /f "twitcurl.mak" CFG="twitcurl - Win32 Debug"
 
!MESSAGE 
 
!MESSAGE Possible choices for configuration are:
 
!MESSAGE 
 
!MESSAGE "twitcurl - Win32 Release" (based on "Win32 (x86) Static Library")
 
!MESSAGE "twitcurl - Win32 Debug" (based on "Win32 (x86) Static Library")
 
!MESSAGE 
 

	
 
# Begin Project
 
# PROP AllowPerConfigDependencies 0
 
# PROP Scc_ProjName ""
 
# PROP Scc_LocalPath ""
 
CPP=cl.exe
 
RSC=rc.exe
 

	
 
!IF  "$(CFG)" == "twitcurl - Win32 Release"
 

	
 
# PROP BASE Use_MFC 0
 
# PROP BASE Use_Debug_Libraries 0
 
# PROP BASE Output_Dir "Release"
 
# PROP BASE Intermediate_Dir "Release"
 
# PROP BASE Target_Dir ""
 
# PROP Use_MFC 0
 
# PROP Use_Debug_Libraries 0
 
# PROP Output_Dir "Release"
 
# PROP Intermediate_Dir "Release"
 
# PROP Target_Dir ""
 
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
 
# ADD CPP /nologo /W3 /GX /O2 /I "./curl" /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
 
# ADD BASE RSC /l 0x409 /d "NDEBUG"
 
# ADD RSC /l 0x409 /d "NDEBUG"
 
BSC32=bscmake.exe
 
# ADD BASE BSC32 /nologo
 
# ADD BSC32 /nologo
 
LIB32=link.exe -lib
 
# ADD BASE LIB32 /nologo
 
# ADD LIB32 /nologo
 

	
 
!ELSEIF  "$(CFG)" == "twitcurl - Win32 Debug"
 

	
 
# PROP BASE Use_MFC 0
 
# PROP BASE Use_Debug_Libraries 1
 
# PROP BASE Output_Dir "Debug"
 
# PROP BASE Intermediate_Dir "Debug"
 
# PROP BASE Target_Dir ""
 
# PROP Use_MFC 0
 
# PROP Use_Debug_Libraries 1
 
# PROP Output_Dir "Debug"
 
# PROP Intermediate_Dir "Debug"
 
# PROP Target_Dir ""
 
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
 
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "./curl" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
 
# ADD BASE RSC /l 0x409 /d "_DEBUG"
 
# ADD RSC /l 0x409 /d "_DEBUG"
 
BSC32=bscmake.exe
 
# ADD BASE BSC32 /nologo
 
# ADD BSC32 /nologo
 
LIB32=link.exe -lib
 
# ADD BASE LIB32 /nologo
 
# ADD LIB32 /nologo
 

	
 
!ENDIF 
 

	
 
# Begin Target
 

	
 
# Name "twitcurl - Win32 Release"
 
# Name "twitcurl - Win32 Debug"
 
# Begin Group "Source Files"
 

	
 
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
 
# Begin Source File
 

	
 
SOURCE=.\base64.cpp
 
# End Source File
 
# Begin Source File
 

	
 
SOURCE=.\HMAC_SHA1.cpp
 
# End Source File
 
# Begin Source File
 

	
 
SOURCE=.\oauthlib.cpp
 
# End Source File
 
# Begin Source File
 

	
 
SOURCE=.\SHA1.cpp
 
# End Source File
 
# Begin Source File
 

	
 
SOURCE=.\twitcurl.cpp
 
# End Source File
 
# Begin Source File
 

	
 
SOURCE=.\urlencode.cpp
 
# End Source File
 
# End Group
 
# Begin Group "Header Files"
 

	
 
# PROP Default_Filter "h;hpp;hxx;hm;inl"
 
# Begin Source File
 

	
 
SOURCE=.\base64.h
 
# End Source File
 
# Begin Source File
 

	
 
SOURCE=.\HMAC_SHA1.h
 
# End Source File
 
# Begin Source File
 

	
 
SOURCE=.\oauthlib.h
 
# End Source File
 
# Begin Source File
 

	
 
SOURCE=.\SHA1.h
 
# End Source File
 
# Begin Source File
 

	
 
SOURCE=.\twitcurl.h
 
# End Source File
 
# Begin Source File
 

	
 
SOURCE=.\urlencode.h
 
# End Source File
 
# End Group
 
# End Target
 
# End Project
backends/twitter/libtwitcurl/twitcurl.dsw
Show inline comments
 
Microsoft Developer Studio Workspace File, Format Version 6.00
 
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
 
 
###############################################################################
 
 
Project: "twitcurl"=.\twitcurl.dsp - Package Owner=<4>
 
 
Package=<5>
 
{{{
 
}}}
 
 
Package=<4>
 
{{{
 
}}}
 
 
###############################################################################
 
 
Global:
 
 
Package=<5>
 
{{{
 
}}}
 
 
Package=<3>
 
{{{
 
}}}
 
 
###############################################################################
 
 
Microsoft Developer Studio Workspace File, Format Version 6.00
 
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
 

	
 
###############################################################################
 

	
 
Project: "twitcurl"=.\twitcurl.dsp - Package Owner=<4>
 

	
 
Package=<5>
 
{{{
 
}}}
 

	
 
Package=<4>
 
{{{
 
}}}
 

	
 
###############################################################################
 

	
 
Global:
 

	
 
Package=<5>
 
{{{
 
}}}
 

	
 
Package=<3>
 
{{{
 
}}}
 

	
 
###############################################################################
 

	

Changeset was too big and was cut off... Show full diff anyway

0 comments (0 inline, 0 general)