From 137727e70ef91cc4f0d444e6445a43094653e9bb Mon Sep 17 00:00:00 2001 From: Sarang Bharadwaj Date: Thu, 24 May 2012 01:40:17 +0530 Subject: [PATCH] Added twitter to user's roster --- backends/twitter/.main.cpp.swp | Bin 20480 -> 36864 bytes backends/twitter/CMakeLists.txt | 2 +- backends/twitter/main.cpp | 840 ++++++++++++++++---------------- spectrum/src/sample.cfg | 2 +- 4 files changed, 431 insertions(+), 413 deletions(-) diff --git a/backends/twitter/.main.cpp.swp b/backends/twitter/.main.cpp.swp index 841a1e3c21a429480d4eb619803a64c46578005c..5bb6fba50690853090057c8b08094881f1d71cbe 100644 GIT binary patch literal 36864 zcmeI53y>T~d4QLvIj}H~q5=ey=3JKdELbTV@6@Q5E^g267rJ1HOq1QG{3aY4lisd9oTLb-@j1&KpQ5e(r`s)1AksRmLFq#8&ykZK^+K&pXM z1E~gnK^m}1nGB}>%=cvy&xBsq0KUyc{Xw`FJ_a9!+u&Bn!#M1L^WkOikq8$V}b9Fzy^-_DSkxZ z3W3h|V0a?zH3@FdwNc<2@sHcfiO7-Gg0Pg!ISWDP+g2@69C3nT?XDJ1U$rd|q8zup zYPn^5d$qPD@mlDr;Srq-JhVy8gmzsG=hRrmE*@9Tf?BebRrT%CvZ`2%w$e34S-Pqy ztu(dZdo^XLx^FK!UL#O`!&RH4Zt>65n@H7@^H&d+?NE!z_6<@^#ymG@)NJ3VBAZMt zC3MNs)?(g2u$;dn|GK%uhqg^_sn?79uBrv2V|%UfiIe+E2lH3d#^-iyrL;_Wt@C=4 z?~aQtR>!u@3{Q+*dEh{KM{VzLxiU3?CuMiqi*?DyH76Ek#;)3aXkz=!;p+BMP`PIR z;Z`n0YFx;hb83b*ZVJ@5t5#^2R2?6%S}>?)D|SG^`?e~3p_*S-zFl?#e6^(BEqe`L zS@pWI!Z?kCMe2Yq^ym^s>_XLBQu9Q0gJzYG0H-2#%J)PrsS#7YcVc)n zCiGivQAeoN<=Ad&Tq11TKvoes7uf!URkPP4Qo_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|MJGT-;vcMVK;d;elp!u!^S-wv#zk>Dmtw%D@1!&3!VA_ET_p_*=;_hr^ft~iI5GRn59Sx3~{Rk9ilsXEPw}t2zyvU^}b}F7EO-i^~ zqhlG#f|UDZVo%0tUkDM)SfiL$FQP>8L~n*zvT%j&nh$v+grxlRFNcsMtxJD#>%1hV zz1T$hX`6bqQA2ldt2DTT`r?A_*7a^NS8eYOI{Kt$dy9)G(aw@>EYT-)X zj(#Cl>ux984(Nq>7>8@~JO*lBnLe??^C8L=(@$Du-YwAT_~L?)cG5kiYi-bqk{SgO RKgvi;x+hPRQ}Uf}{|jKSMgRZ+ delta 980 zcmX}qYe4N&;jMgU=#g>q!sAy4SVKS+aXpm);#cXWLiBg-;MTlaT zg8Cwg6k$Q-lb1}1Na{n<%?Pv$<)?x!WCay=`M)8(@Z&k}^Sqq*;hYohP6&5v={ue7 z$|^@;UcT_8iA)DatK)e_Nw!`~f18?bkU#7vpc2|VBWor$&c7R2mm!GwG-fvWC#lVaN?bb#5j*0bYVY!CX2kr3ryh- znz0W}*o(;|kv6m>g+vY#Of3+Jp#r5S!3b5kfdO1cAI?IrRy(S&31!H~O60(Z=TvnX z7ZJr~l%NQD#S5?sHvQl?{rQ4f4B!ZY2*3})dwM*I(}>^%I#G`w^nDVKG*OY7u)$$6 zc^bSW{y<}Ku|MEzYTlFU@HRC0{_m)Ax7`r$t9HjHYBSW+x?H0wI($!4!@F!+sG*VU zG{{a9^`X!Q=M7DNh1(c}!Ugo=7~0W_AX=~+`p~$s73+|R8FD_uB%a_B`k)Vw538+W zm2846EQMXUoF^^XA$7N`Sc`2~5}$LO`FFz}rozS4=r`0y{TJEi@BkCI1^t%&xQwHy zM;)@U2oL$e7)CIRAq*mh5CZU{0EzfcRlZqdg?uIGfCr^m3>(Za;UyPq!xp&AN;CGR JsA$a -#include -#include - -void printUsage() -{ - printf( "\nUsage:\ntwitterClient -u username -p password\n" ); -} - -int main( int argc, char* argv[] ) -{ - std::string userName( "" ); - std::string passWord( "" ); - if( argc > 4 ) - { - for( int i = 1; i < argc; i += 2 ) - { - if( 0 == strncmp( argv[i], "-u", strlen("-u") ) ) - { - userName = argv[i+1]; - } - else if( 0 == strncmp( argv[i], "-p", strlen("-p") ) ) - { - passWord = argv[i+1]; - } - } - if( ( 0 == userName.length() ) || ( 0 == passWord.length() ) ) - { - printUsage(); - return 0; - } - } - else - { - printUsage(); - return 0; - } - - twitCurl twitterObj; - std::string tmpStr; - std::string replyMsg; - char tmpBuf[1024]; - - /* Set twitter username and password */ - twitterObj.setTwitterUsername( userName ); - twitterObj.setTwitterPassword( passWord ); - - /* Set proxy server usename, password, IP and port (if present) */ - memset( tmpBuf, 0, 1024 ); - printf( "\nDo you have a proxy server configured (0 for no; 1 for yes): " ); - gets( tmpBuf ); - tmpStr = tmpBuf; - - if( std::string::npos != tmpStr.find( "1" ) ) - { - char proxyIp[1024]; - char proxyPort[1024]; - char proxyUsername[1024]; - char proxyPassword[1024]; - - memset( proxyIp, 0, 1024 ); - memset( proxyPort, 0, 1024 ); - memset( proxyUsername, 0, 1024 ); - memset( proxyPassword, 0, 1024 ); - - printf( "\nEnter proxy server IP: " ); - gets( proxyIp ); - printf( "\nEnter proxy server port: " ); - gets( proxyPort ); - printf( "\nEnter proxy server username: " ); - gets( proxyUsername ); - printf( "\nEnter proxy server password: " ); - gets( proxyPassword ); - - tmpStr = proxyIp; - twitterObj.setProxyServerIp( tmpStr ); - tmpStr = proxyPort; - twitterObj.setProxyServerPort( tmpStr ); - tmpStr = proxyUsername; - twitterObj.setProxyUserName( tmpStr ); - tmpStr = proxyPassword; - twitterObj.setProxyPassword( tmpStr ); - } - - /* OAuth flow begins */ - /* Step 0: Set OAuth related params. These are got by registering your app at twitter.com */ - twitterObj.getOAuth().setConsumerKey( std::string( "qxfSCX7WN7SZl7dshqGZA" ) ); - twitterObj.getOAuth().setConsumerSecret( std::string( "ypWapSj87lswvnksZ46hMAoAZvST4ePGPxAQw6S2o" ) ); - -// twitterObj.getOAuth().setConsumerKey( std::string( "vlC5S1NCMHHg8mD1ghPRkA" ) ); -// twitterObj.getOAuth().setConsumerSecret( std::string( "3w4cIrHyI3IYUZW5O2ppcFXmsACDaENzFdLIKmEU84" ) ); - - /* Step 1: Check if we alredy have OAuth access token from a previous run */ - std::string myOAuthAccessTokenKey(""); - std::string myOAuthAccessTokenSecret(""); - std::ifstream oAuthTokenKeyIn; - std::ifstream oAuthTokenSecretIn; - - oAuthTokenKeyIn.open( "twitterClient_token_key.txt" ); - oAuthTokenSecretIn.open( "twitterClient_token_secret.txt" ); - - memset( tmpBuf, 0, 1024 ); - oAuthTokenKeyIn >> tmpBuf; - myOAuthAccessTokenKey = tmpBuf; - - memset( tmpBuf, 0, 1024 ); - oAuthTokenSecretIn >> tmpBuf; - myOAuthAccessTokenSecret = tmpBuf; - - oAuthTokenKeyIn.close(); - oAuthTokenSecretIn.close(); - - if( myOAuthAccessTokenKey.size() && myOAuthAccessTokenSecret.size() ) - { - /* If we already have these keys, then no need to go through auth again */ - printf( "\nUsing:\nKey: %s\nSecret: %s\n\n", myOAuthAccessTokenKey.c_str(), myOAuthAccessTokenSecret.c_str() ); - - twitterObj.getOAuth().setOAuthTokenKey( myOAuthAccessTokenKey ); - twitterObj.getOAuth().setOAuthTokenSecret( myOAuthAccessTokenSecret ); - } - else - { - /* Step 2: Get request token key and secret */ - std::string authUrl; - twitterObj.oAuthRequestToken( authUrl ); - - /* Step 3: Get PIN */ - memset( tmpBuf, 0, 1024 ); - printf( "\nDo you want to visit twitter.com for PIN (0 for no; 1 for yes): " ); - gets( tmpBuf ); - tmpStr = tmpBuf; - if( std::string::npos != tmpStr.find( "1" ) ) - { - /* Ask user to visit twitter.com auth page and get PIN */ - memset( tmpBuf, 0, 1024 ); - printf( "\nPlease visit this link in web browser and authorize this application:\n%s", authUrl.c_str() ); - printf( "\nEnter the PIN provided by twitter: " ); - gets( tmpBuf ); - tmpStr = tmpBuf; - twitterObj.getOAuth().setOAuthPin( tmpStr ); - } - else - { - /* Else, pass auth url to twitCurl and get it via twitCurl PIN handling */ - twitterObj.oAuthHandlePIN( authUrl ); - } - - /* Step 4: Exchange request token with access token */ - twitterObj.oAuthAccessToken(); - - /* Step 5: Now, save this access token key and secret for future use without PIN */ - twitterObj.getOAuth().getOAuthTokenKey( myOAuthAccessTokenKey ); - twitterObj.getOAuth().getOAuthTokenSecret( myOAuthAccessTokenSecret ); - - /* Step 6: Save these keys in a file or wherever */ - std::ofstream oAuthTokenKeyOut; - std::ofstream oAuthTokenSecretOut; - - oAuthTokenKeyOut.open( "twitterClient_token_key.txt" ); - oAuthTokenSecretOut.open( "twitterClient_token_secret.txt" ); - - oAuthTokenKeyOut.clear(); - oAuthTokenSecretOut.clear(); - - oAuthTokenKeyOut << myOAuthAccessTokenKey.c_str(); - oAuthTokenSecretOut << myOAuthAccessTokenSecret.c_str(); - - oAuthTokenKeyOut.close(); - oAuthTokenSecretOut.close(); - } - /* OAuth flow ends */ - - /* Post a new status message */ - memset( tmpBuf, 0, 1024 ); - printf( "\nEnter a new status message: " ); - gets( tmpBuf ); - tmpStr = tmpBuf; - replyMsg = ""; - if( twitterObj.statusUpdate( tmpStr ) ) - { - twitterObj.getLastWebResponse( replyMsg ); - printf( "\ntwitterClient:: twitCurl::statusUpdate web response:\n%s\n", replyMsg.c_str() ); - } - else - { - twitterObj.getLastCurlError( replyMsg ); - printf( "\ntwitterClient:: twitCurl::statusUpdate error:\n%s\n", replyMsg.c_str() ); - } - -// /* Search a string */ -// twitterObj.setTwitterApiType( twitCurlTypes::eTwitCurlApiFormatJson ); -// printf( "\nEnter string to search: " ); +//#include "twitcurl.h" +//#include +//#include +//#include +// +//void printUsage() +//{ +// printf( "\nUsage:\ntwitterClient -u username -p password\n" ); +//} +// +//int main( int argc, char* argv[] ) +//{ +// std::string userName( "" ); +// std::string passWord( "" ); +// if( argc > 4 ) +// { +// for( int i = 1; i < argc; i += 2 ) +// { +// if( 0 == strncmp( argv[i], "-u", strlen("-u") ) ) +// { +// userName = argv[i+1]; +// } +// else if( 0 == strncmp( argv[i], "-p", strlen("-p") ) ) +// { +// passWord = argv[i+1]; +// } +// } +// if( ( 0 == userName.length() ) || ( 0 == passWord.length() ) ) +// { +// printUsage(); +// return 0; +// } +// } +// else +// { +// printUsage(); +// return 0; +// } +// +// twitCurl twitterObj; +// std::string tmpStr; +// std::string replyMsg; +// char tmpBuf[1024]; +// +// /* Set twitter username and password */ +// twitterObj.setTwitterUsername( userName ); +// twitterObj.setTwitterPassword( passWord ); +// +// /* Set proxy server usename, password, IP and port (if present) */ // memset( tmpBuf, 0, 1024 ); +// printf( "\nDo you have a proxy server configured (0 for no; 1 for yes): " ); +// gets( tmpBuf ); +// tmpStr = tmpBuf; +// +// if( std::string::npos != tmpStr.find( "1" ) ) +// { +// char proxyIp[1024]; +// char proxyPort[1024]; +// char proxyUsername[1024]; +// char proxyPassword[1024]; +// +// memset( proxyIp, 0, 1024 ); +// memset( proxyPort, 0, 1024 ); +// memset( proxyUsername, 0, 1024 ); +// memset( proxyPassword, 0, 1024 ); +// +// printf( "\nEnter proxy server IP: " ); +// gets( proxyIp ); +// printf( "\nEnter proxy server port: " ); +// gets( proxyPort ); +// printf( "\nEnter proxy server username: " ); +// gets( proxyUsername ); +// printf( "\nEnter proxy server password: " ); +// gets( proxyPassword ); +// +// tmpStr = proxyIp; +// twitterObj.setProxyServerIp( tmpStr ); +// tmpStr = proxyPort; +// twitterObj.setProxyServerPort( tmpStr ); +// tmpStr = proxyUsername; +// twitterObj.setProxyUserName( tmpStr ); +// tmpStr = proxyPassword; +// twitterObj.setProxyPassword( tmpStr ); +// } +// +// /* OAuth flow begins */ +// /* Step 0: Set OAuth related params. These are got by registering your app at twitter.com */ +// twitterObj.getOAuth().setConsumerKey( std::string( "qxfSCX7WN7SZl7dshqGZA" ) ); +// twitterObj.getOAuth().setConsumerSecret( std::string( "ypWapSj87lswvnksZ46hMAoAZvST4ePGPxAQw6S2o" ) ); +// +//// twitterObj.getOAuth().setConsumerKey( std::string( "vlC5S1NCMHHg8mD1ghPRkA" ) ); +//// twitterObj.getOAuth().setConsumerSecret( std::string( "3w4cIrHyI3IYUZW5O2ppcFXmsACDaENzFdLIKmEU84" ) ); +// +// /* Step 1: Check if we alredy have OAuth access token from a previous run */ +// std::string myOAuthAccessTokenKey(""); +// std::string myOAuthAccessTokenSecret(""); +// std::ifstream oAuthTokenKeyIn; +// std::ifstream oAuthTokenSecretIn; +// +// oAuthTokenKeyIn.open( "twitterClient_token_key.txt" ); +// oAuthTokenSecretIn.open( "twitterClient_token_secret.txt" ); +// +// memset( tmpBuf, 0, 1024 ); +// oAuthTokenKeyIn >> tmpBuf; +// myOAuthAccessTokenKey = tmpBuf; +// +// memset( tmpBuf, 0, 1024 ); +// oAuthTokenSecretIn >> tmpBuf; +// myOAuthAccessTokenSecret = tmpBuf; +// +// oAuthTokenKeyIn.close(); +// oAuthTokenSecretIn.close(); +// +// if( myOAuthAccessTokenKey.size() && myOAuthAccessTokenSecret.size() ) +// { +// /* If we already have these keys, then no need to go through auth again */ +// printf( "\nUsing:\nKey: %s\nSecret: %s\n\n", myOAuthAccessTokenKey.c_str(), myOAuthAccessTokenSecret.c_str() ); +// +// twitterObj.getOAuth().setOAuthTokenKey( myOAuthAccessTokenKey ); +// twitterObj.getOAuth().setOAuthTokenSecret( myOAuthAccessTokenSecret ); +// } +// else +// { +// /* Step 2: Get request token key and secret */ +// std::string authUrl; +// twitterObj.oAuthRequestToken( authUrl ); +// +// /* Step 3: Get PIN */ +// memset( tmpBuf, 0, 1024 ); +// printf( "\nDo you want to visit twitter.com for PIN (0 for no; 1 for yes): " ); +// gets( tmpBuf ); +// tmpStr = tmpBuf; +// if( std::string::npos != tmpStr.find( "1" ) ) +// { +// /* Ask user to visit twitter.com auth page and get PIN */ +// memset( tmpBuf, 0, 1024 ); +// printf( "\nPlease visit this link in web browser and authorize this application:\n%s", authUrl.c_str() ); +// printf( "\nEnter the PIN provided by twitter: " ); +// gets( tmpBuf ); +// tmpStr = tmpBuf; +// twitterObj.getOAuth().setOAuthPin( tmpStr ); +// } +// else +// { +// /* Else, pass auth url to twitCurl and get it via twitCurl PIN handling */ +// twitterObj.oAuthHandlePIN( authUrl ); +// } +// +// /* Step 4: Exchange request token with access token */ +// twitterObj.oAuthAccessToken(); +// +// /* Step 5: Now, save this access token key and secret for future use without PIN */ +// twitterObj.getOAuth().getOAuthTokenKey( myOAuthAccessTokenKey ); +// twitterObj.getOAuth().getOAuthTokenSecret( myOAuthAccessTokenSecret ); +// +// /* Step 6: Save these keys in a file or wherever */ +// std::ofstream oAuthTokenKeyOut; +// std::ofstream oAuthTokenSecretOut; +// +// oAuthTokenKeyOut.open( "twitterClient_token_key.txt" ); +// oAuthTokenSecretOut.open( "twitterClient_token_secret.txt" ); +// +// oAuthTokenKeyOut.clear(); +// oAuthTokenSecretOut.clear(); +// +// oAuthTokenKeyOut << myOAuthAccessTokenKey.c_str(); +// oAuthTokenSecretOut << myOAuthAccessTokenSecret.c_str(); +// +// oAuthTokenKeyOut.close(); +// oAuthTokenSecretOut.close(); +// } +// /* OAuth flow ends */ +// +// /* Post a new status message */ +// memset( tmpBuf, 0, 1024 ); +// printf( "\nEnter a new status message: " ); // gets( tmpBuf ); // tmpStr = tmpBuf; // replyMsg = ""; -// if( twitterObj.search( tmpStr ) ) +// if( twitterObj.statusUpdate( tmpStr ) ) // { // twitterObj.getLastWebResponse( replyMsg ); -// printf( "\ntwitterClient:: twitCurl::search web response:\n%s\n", replyMsg.c_str() ); +// printf( "\ntwitterClient:: twitCurl::statusUpdate web response:\n%s\n", replyMsg.c_str() ); // } // else // { // twitterObj.getLastCurlError( replyMsg ); -// printf( "\ntwitterClient:: twitCurl::search error:\n%s\n", replyMsg.c_str() ); +// printf( "\ntwitterClient:: twitCurl::statusUpdate error:\n%s\n", replyMsg.c_str() ); // } // -// /* Get user timeline */ -// replyMsg = ""; -// printf( "\nGetting user timeline\n" ); -// if( twitterObj.timelineUserGet( false, false, 0 ) ) -// { -// twitterObj.getLastWebResponse( replyMsg ); -// printf( "\ntwitterClient:: twitCurl::timelineUserGet web response:\n%s\n", replyMsg.c_str() ); -// } -// else -// { -// twitterObj.getLastCurlError( replyMsg ); -// printf( "\ntwitterClient:: twitCurl::timelineUserGet error:\n%s\n", replyMsg.c_str() ); +//// /* Search a string */ +//// twitterObj.setTwitterApiType( twitCurlTypes::eTwitCurlApiFormatJson ); +//// printf( "\nEnter string to search: " ); +//// memset( tmpBuf, 0, 1024 ); +//// gets( tmpBuf ); +//// tmpStr = tmpBuf; +//// replyMsg = ""; +//// if( twitterObj.search( tmpStr ) ) +//// { +//// twitterObj.getLastWebResponse( replyMsg ); +//// printf( "\ntwitterClient:: twitCurl::search web response:\n%s\n", replyMsg.c_str() ); +//// } +//// else +//// { +//// twitterObj.getLastCurlError( replyMsg ); +//// printf( "\ntwitterClient:: twitCurl::search error:\n%s\n", replyMsg.c_str() ); +//// } +//// +//// /* Get user timeline */ +//// replyMsg = ""; +//// printf( "\nGetting user timeline\n" ); +//// if( twitterObj.timelineUserGet( false, false, 0 ) ) +//// { +//// twitterObj.getLastWebResponse( replyMsg ); +//// printf( "\ntwitterClient:: twitCurl::timelineUserGet web response:\n%s\n", replyMsg.c_str() ); +//// } +//// else +//// { +//// twitterObj.getLastCurlError( replyMsg ); +//// printf( "\ntwitterClient:: twitCurl::timelineUserGet error:\n%s\n", replyMsg.c_str() ); +//// } +// +//#ifdef _TWITCURL_TEST_ +//// /* Destroy a status message */ +//// memset( statusMsg, 0, 1024 ); +//// printf( "\nEnter status message id to delete: " ); +//// gets( statusMsg ); +//// tmpStr = statusMsg; +//// replyMsg = ""; +//// if( twitterObj.statusDestroyById( tmpStr ) ) +//// { +//// twitterObj.getLastWebResponse( replyMsg ); +//// printf( "\ntwitterClient:: twitCurl::statusDestroyById web response:\n%s\n", replyMsg.c_str() ); +//// } +//// else +//// { +//// twitterObj.getLastCurlError( replyMsg ); +//// printf( "\ntwitterClient:: twitCurl::statusDestroyById error:\n%s\n", replyMsg.c_str() ); +//// } +//// +//// /* Get public timeline */ +//// replyMsg = ""; +//// printf( "\nGetting public timeline\n" ); +//// if( twitterObj.timelinePublicGet() ) +//// { +//// twitterObj.getLastWebResponse( replyMsg ); +//// printf( "\ntwitterClient:: twitCurl::timelinePublicGet web response:\n%s\n", replyMsg.c_str() ); +//// } +//// else +//// { +//// twitterObj.getLastCurlError( replyMsg ); +//// printf( "\ntwitterClient:: twitCurl::timelinePublicGet error:\n%s\n", replyMsg.c_str() ); +//// } +//// +//// /* Get friend ids */ +//// replyMsg = ""; +//// printf( "\nGetting friend ids\n" ); +//// tmpStr = "techcrunch"; +//// if( twitterObj.friendsIdsGet( tmpStr, false ) ) +//// { +//// twitterObj.getLastWebResponse( replyMsg ); +//// printf( "\ntwitterClient:: twitCurl::friendsIdsGet web response:\n%s\n", replyMsg.c_str() ); +//// } +//// else +//// { +//// twitterObj.getLastCurlError( replyMsg ); +//// printf( "\ntwitterClient:: twitCurl::friendsIdsGet error:\n%s\n", replyMsg.c_str() ); +//// } +//// +//// /* Get trends */ +//// if( twitterObj.trendsDailyGet() ) +//// { +//// twitterObj.getLastWebResponse( replyMsg ); +//// printf( "\ntwitterClient:: twitCurl::trendsDailyGet web response:\n%s\n", replyMsg.c_str() ); +//// } +//// else +//// { +//// twitterObj.getLastCurlError( replyMsg ); +//// printf( "\ntwitterClient:: twitCurl::trendsDailyGet error:\n%s\n", replyMsg.c_str() ); // } +//#endif // _TWITCURL_TEST_ +// +// return 0; +//} -#ifdef _TWITCURL_TEST_ -// /* Destroy a status message */ -// memset( statusMsg, 0, 1024 ); -// printf( "\nEnter status message id to delete: " ); -// gets( statusMsg ); -// tmpStr = statusMsg; -// replyMsg = ""; -// if( twitterObj.statusDestroyById( tmpStr ) ) -// { -// twitterObj.getLastWebResponse( replyMsg ); -// printf( "\ntwitterClient:: twitCurl::statusDestroyById web response:\n%s\n", replyMsg.c_str() ); -// } -// else -// { -// twitterObj.getLastCurlError( replyMsg ); -// printf( "\ntwitterClient:: twitCurl::statusDestroyById error:\n%s\n", replyMsg.c_str() ); -// } -// -// /* Get public timeline */ -// replyMsg = ""; -// printf( "\nGetting public timeline\n" ); -// if( twitterObj.timelinePublicGet() ) -// { -// twitterObj.getLastWebResponse( replyMsg ); -// printf( "\ntwitterClient:: twitCurl::timelinePublicGet web response:\n%s\n", replyMsg.c_str() ); -// } -// else -// { -// twitterObj.getLastCurlError( replyMsg ); -// printf( "\ntwitterClient:: twitCurl::timelinePublicGet error:\n%s\n", replyMsg.c_str() ); -// } -// -// /* Get friend ids */ -// replyMsg = ""; -// printf( "\nGetting friend ids\n" ); -// tmpStr = "techcrunch"; -// if( twitterObj.friendsIdsGet( tmpStr, false ) ) -// { -// twitterObj.getLastWebResponse( replyMsg ); -// printf( "\ntwitterClient:: twitCurl::friendsIdsGet web response:\n%s\n", replyMsg.c_str() ); -// } -// else -// { -// twitterObj.getLastCurlError( replyMsg ); -// printf( "\ntwitterClient:: twitCurl::friendsIdsGet error:\n%s\n", replyMsg.c_str() ); -// } -// -// /* Get trends */ -// if( twitterObj.trendsDailyGet() ) -// { -// twitterObj.getLastWebResponse( replyMsg ); -// printf( "\ntwitterClient:: twitCurl::trendsDailyGet web response:\n%s\n", replyMsg.c_str() ); -// } -// else -// { -// twitterObj.getLastCurlError( replyMsg ); -// printf( "\ntwitterClient:: twitCurl::trendsDailyGet error:\n%s\n", replyMsg.c_str() ); - } -#endif // _TWITCURL_TEST_ +#include "transport/config.h" +#include "transport/networkplugin.h" +#include "transport/logging.h" +#include "Swiften/Swiften.h" +#include "unistd.h" +#include "signal.h" +#include "sys/wait.h" +#include "sys/signal.h" +#include +#include "twitcurl.h" +#include +#include +#include +#include - return 0; +using namespace boost::filesystem; +using namespace boost::program_options; +using namespace Transport; + +DEFINE_LOGGER(logger, "Twitter Backend"); +Swift::SimpleEventLoop *loop_; // Event Loop +class TwitterPlugin; // The plugin +TwitterPlugin * np = NULL; + +class TwitterPlugin : public NetworkPlugin { + public: + Swift::BoostNetworkFactories *m_factories; + Swift::BoostIOServiceThread m_boostIOServiceThread; + boost::shared_ptr m_conn; + + TwitterPlugin(Config *config, Swift::SimpleEventLoop *loop, const std::string &host, int port) : NetworkPlugin() { + this->config = config; + m_factories = new Swift::BoostNetworkFactories(loop); + m_conn = m_factories->getConnectionFactory()->createConnection(); + m_conn->onDataRead.connect(boost::bind(&TwitterPlugin::_handleDataRead, this, _1)); + m_conn->connect(Swift::HostAddressPort(Swift::HostAddress(host), port)); + + LOG4CXX_INFO(logger, "Starting the plugin."); + } + + // Send data to NetworkPlugin server + void sendData(const std::string &string) { + m_conn->write(Swift::createSafeByteArray(string)); + } + + // Receive date from the NetworkPlugin server and invoke the appropirate payload handler (implement in the NetworkPlugin class) + void _handleDataRead(boost::shared_ptr data) { + std::string d(data->begin(), data->end()); + handleDataRead(d); + } + + // User trying to login into his twitter account + void handleLoginRequest(const std::string &user, const std::string &legacyName, const std::string &password) { + if(sessions.count(user)) { + LOG4CXX_INFO(logger, "A session corresponding to " + user + " is already active\n") + return; + } + + //twitCurl &twitterObj = sessions[user]; + //std::string myOAuthAccessTokenSecret, myOAuthAccessTokenKey; + //twitterObj.getOAuth().getOAuthTokenKey( myOAuthAccessTokenKey ); + //twitterObj.getOAuth().getOAuthTokenSecret( myOAuthAccessTokenSecret ); + + //if(myOAuthAccessTokenSecret.size() && myOAuthAccessTokenKey.size()) { + //} + handleConnected(user); + handleBuddyChanged(user, "twitter-account", "twitter", std::vector(), pbnetwork::STATUS_ONLINE); + } + + // User logging out + void handleLogoutRequest(const std::string &user, const std::string &legacyName) { + } + + + void handleMessageSendRequest(const std::string &user, const std::string &legacyName, const std::string &message, const std::string &xhtml = "") { + LOG4CXX_INFO(logger, "Sending message from " << user << " to " << legacyName << "."); + } + + void handleBuddyUpdatedRequest(const std::string &user, const std::string &buddyName, const std::string &alias, const std::vector &groups) { + LOG4CXX_INFO(logger, user << ": Added buddy " << buddyName << "."); + handleBuddyChanged(user, buddyName, alias, groups, pbnetwork::STATUS_ONLINE); + } + + void handleBuddyRemovedRequest(const std::string &user, const std::string &buddyName, const std::vector &groups) { + + } + + private: + Config *config; + std::map sessions; +}; + +static void spectrum_sigchld_handler(int sig) +{ + int status; + pid_t pid; + + do { + pid = waitpid(-1, &status, WNOHANG); + } while (pid != 0 && pid != (pid_t)-1); + + if ((pid == (pid_t) - 1) && (errno != ECHILD)) { + char errmsg[BUFSIZ]; + snprintf(errmsg, BUFSIZ, "Warning: waitpid() returned %d", pid); + perror(errmsg); + } +} + + +int main (int argc, char* argv[]) { + std::string host; + int port; + + if (signal(SIGCHLD, spectrum_sigchld_handler) == SIG_ERR) { + std::cout << "SIGCHLD handler can't be set\n"; + return -1; + } + + boost::program_options::options_description desc("Usage: spectrum [OPTIONS] \nAllowed options"); + desc.add_options() + ("host,h", value(&host), "host") + ("port,p", value(&port), "port") + ; + try + { + boost::program_options::variables_map vm; + boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm); + boost::program_options::notify(vm); + } + catch (std::runtime_error& e) + { + std::cout << desc << "\n"; + exit(1); + } + catch (...) + { + std::cout << desc << "\n"; + exit(1); + } + + + if (argc < 5) { + return 1; + } + + Config config; + if (!config.load(argv[5])) { + std::cerr << "Can't open " << argv[1] << " configuration file.\n"; + return 1; + } + + Logging::initBackendLogging(&config); + + Swift::SimpleEventLoop eventLoop; + loop_ = &eventLoop; + np = new TwitterPlugin(&config, &eventLoop, host, port); + loop_->run(); + + return 0; } -//#include "transport/config.h" -//#include "transport/networkplugin.h" -//#include "transport/logging.h" -//#include "Swiften/Swiften.h" -//#include "unistd.h" -//#include "signal.h" -//#include "sys/wait.h" -//#include "sys/signal.h" -//#include -//#include "twitcurl.h" -// -//using namespace boost::filesystem; -//using namespace boost::program_options; -//using namespace Transport; -// -//DEFINE_LOGGER(logger, "Twitter Backend"); -//Swift::SimpleEventLoop *loop_; // Event Loop -//class TwitterPlugin; // The plugin -//TwitterPlugin * np = NULL; -// -//class TwitterPlugin : public NetworkPlugin { -// public: -// Swift::BoostNetworkFactories *m_factories; -// Swift::BoostIOServiceThread m_boostIOServiceThread; -// boost::shared_ptr m_conn; -// -// TwitterPlugin(Config *config, Swift::SimpleEventLoop *loop, const std::string &host, int port) : NetworkPlugin() { -// this->config = config; -// m_factories = new Swift::BoostNetworkFactories(loop); -// m_conn = m_factories->getConnectionFactory()->createConnection(); -// m_conn->onDataRead.connect(boost::bind(&TwitterPlugin::_handleDataRead, this, _1)); -// m_conn->connect(Swift::HostAddressPort(Swift::HostAddress(host), port)); -// -// LOG4CXX_INFO(logger, "Starting the plugin."); -// } -// -// // Send data to NetworkPlugin server -// void sendData(const std::string &string) { -// m_conn->write(Swift::createSafeByteArray(string)); -// } -// -// // Receive date from the NetworkPlugin server and invoke the appropirate payload handler (implement in the NetworkPlugin class) -// void _handleDataRead(boost::shared_ptr data) { -// std::string d(data->begin(), data->end()); -// handleDataRead(d); -// } -// -// // User trying to login into his twitter account -// void handleLoginRequest(const std::string &user, const std::string &legacyName, const std::string &password) { -// handleConnected(user); -// } -// -// // User logging out -// void handleLogoutRequest(const std::string &user, const std::string &legacyName) { -// } -// -// -// void handleMessageSendRequest(const std::string &user, const std::string &legacyName, const std::string &message, const std::string &xhtml = "") { -// LOG4CXX_INFO(logger, "Sending message from " << user << " to " << legacyName << "."); -// } -// -// void handleBuddyUpdatedRequest(const std::string &user, const std::string &buddyName, const std::string &alias, const std::vector &groups) { -// LOG4CXX_INFO(logger, user << ": Added buddy " << buddyName << "."); -// handleBuddyChanged(user, buddyName, alias, groups, pbnetwork::STATUS_ONLINE); -// } -// -// void handleBuddyRemovedRequest(const std::string &user, const std::string &buddyName, const std::vector &groups) { -// -// } -// -// private: -// Config *config; -// map< std::string, twitCurl > sessions; -//}; -// -//static void spectrum_sigchld_handler(int sig) -//{ -// int status; -// pid_t pid; -// -// do { -// pid = waitpid(-1, &status, WNOHANG); -// } while (pid != 0 && pid != (pid_t)-1); -// -// if ((pid == (pid_t) - 1) && (errno != ECHILD)) { -// char errmsg[BUFSIZ]; -// snprintf(errmsg, BUFSIZ, "Warning: waitpid() returned %d", pid); -// perror(errmsg); -// } -//} -// -// -//int main (int argc, char* argv[]) { -// std::string host; -// int port; -// -// if (signal(SIGCHLD, spectrum_sigchld_handler) == SIG_ERR) { -// std::cout << "SIGCHLD handler can't be set\n"; -// return -1; -// } -// -// boost::program_options::options_description desc("Usage: spectrum [OPTIONS] \nAllowed options"); -// desc.add_options() -// ("host,h", value(&host), "host") -// ("port,p", value(&port), "port") -// ; -// try -// { -// boost::program_options::variables_map vm; -// boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm); -// boost::program_options::notify(vm); -// } -// catch (std::runtime_error& e) -// { -// std::cout << desc << "\n"; -// exit(1); -// } -// catch (...) -// { -// std::cout << desc << "\n"; -// exit(1); -// } -// -// -// if (argc < 5) { -// return 1; -// } -// -// Config config; -// if (!config.load(argv[5])) { -// std::cerr << "Can't open " << argv[1] << " configuration file.\n"; -// return 1; -// } -// -// Logging::initBackendLogging(&config); -// -// Swift::SimpleEventLoop eventLoop; -// loop_ = &eventLoop; -// np = new TwitterPlugin(&config, &eventLoop, host, port); -// loop_->run(); -// -// return 0; -//} diff --git a/spectrum/src/sample.cfg b/spectrum/src/sample.cfg index 5018ae8b..ccb8c867 100644 --- a/spectrum/src/sample.cfg +++ b/spectrum/src/sample.cfg @@ -14,7 +14,7 @@ admin_password=test #cert_password=test #password to that certificate if any users_per_backend=10 #backend=../..//backends/libpurple/spectrum2_libpurple_backend -backend=../../backends/template/template_backend.py +backend=../../backends/twitter/spectrum_twitter_backend protocol=prpl-jabber #protocol=prpl-msn #protocol=any