/************************************move******************************************/ void kp_api::move(string from_path,string to_path) { char* from_path_encode = oauth_url_escape(from_path.c_str()); char* to_path_encode = oauth_url_escape(to_path.c_str()); string url = kp_api::m_move_url+"?root="+kp_api::m_root+"?&from_path="+from_path_encode+"?&to_path="+to_path_encode; string req_url = oauth_sign_url2(url.c_str(),NULL,OA_HMAC, NULL, m_kpoauth.consumer_key.c_str(),m_kpoauth.consumer_secret.c_str(), m_kpoauth.oauth_token.c_str (),m_kpoauth.oauth_token_secret.c_str()); //cout<<req_url<<endl; string reply = oauth_http_get(req_url.c_str(),NULL); cout<<reply<<endl; }
void add_escaped_kv_to_array(int *argcp, char ***argvp, const char *key, const char *value) { const char *val=value; if (!key) return; if (!val) val=""; char *t1 = oauth_url_escape(key); char *t2 = oauth_url_escape(val); char *param = (char*) xmalloc(sizeof(char)*(strlen(t1)+strlen(t1)+2)); param[0]='\0'; strcat(param,t1); strcat(param,"="); strcat(param,t2); add_param_to_array(argcp, argvp, param); free(t1); free(t2); free(param); }
static void gsocial_send_request(Session *request) { request->exit_code = 0; char *escaped_tweet = NULL; int is_post = 0; char endpoint[500]; char *req_url; char *reply; char *postarg = NULL; switch(request->action) { case ACTION_HOME_TIMELINE: if(request->since_id != NULL) { sprintf(endpoint, "%s%s?%s%s", twitter_statuses, "/home_timeline.xml", "since_id=", request->since_id); printf ( "%s\n", request->since_id ); } else { sprintf(endpoint, "%s%s", twitter_statuses, "/home_timeline.xml"); } break; case ACTION_UPDATE: escaped_tweet = oauth_url_escape(request->tweet); sprintf(endpoint, "%s%s?status=%s","http://api.twitter.com/1/statuses", "/update.xml", escaped_tweet); is_post = 1; break; case ACTION_MESSAGES: if(request->since_id != NULL) { sprintf(endpoint, "%s?%s%s", twitter_dm_uri, "since_id=", request->since_id); } else { sprintf(endpoint, "%s", twitter_dm_uri); } break; } if(is_post){ req_url = oauth_sign_url2(endpoint, &postarg, OA_HMAC, NULL, consumer_key, consumer_secret, access_key, access_secret); reply = oauth_http_post(req_url, postarg); } else{ req_url = oauth_sign_url2(endpoint, NULL, OA_HMAC, NULL, consumer_key, consumer_secret, access_key, access_secret); reply = oauth_http_get(req_url, postarg); } if (request->action != ACTION_UPDATE) gsocial_parse(reply, request, request->action); if(reply) request->exit_code = 1; free(postarg); free(req_url); free(reply); }
int API::login(const std::string& email, const std::string& password) { int res = 0; std::string url; std::string token, secret; // Get temporary request token url = oauth_sign_url2(this->config.oauth_get_temp_token.c_str(), NULL, OA_HMAC, NULL, CONSUMER_KEY.c_str(), CONSUMER_SECRET.c_str(), NULL /* token */, NULL /* secret */); std::string request_token_resp = this->getResponse(url); char **rv = NULL; int rc = oauth_split_url_parameters(request_token_resp.c_str(), &rv); qsort(rv, rc, sizeof(char *), oauth_cmpstringp); if (rc == 3 && !strncmp(rv[1], "oauth_token=", OAUTH_TOKEN_LENGTH) && !strncmp(rv[2], "oauth_token_secret=", OAUTH_SECRET_LENGTH)) { token = rv[1]+OAUTH_TOKEN_LENGTH+1; secret = rv[2]+OAUTH_SECRET_LENGTH+1; rv = NULL; } else { return res; } // Authorize temporary token and get verifier url = this->config.oauth_authorize_temp_token + "?username="******"&password="******"oauth_verifier=", OAUTH_VERIFIER_LENGTH)) { verifier = rv[1]+OAUTH_VERIFIER_LENGTH+1; rv = NULL; } else { return res; } // Get final token and secret url = this->config.oauth_get_token + "?oauth_verifier=" + verifier; url = oauth_sign_url2(url.c_str(), NULL, OA_HMAC, NULL, CONSUMER_KEY.c_str(), CONSUMER_SECRET.c_str(), token.c_str(), secret.c_str()); std::string token_resp = this->getResponse(url); rc = oauth_split_url_parameters(token_resp.c_str(), &rv); qsort(rv, rc, sizeof(char *), oauth_cmpstringp); if (rc == 2 && !strncmp(rv[0], "oauth_token=", OAUTH_TOKEN_LENGTH) && !strncmp(rv[1], "oauth_token_secret=", OAUTH_SECRET_LENGTH)) { this->config.oauth_token = rv[0]+OAUTH_TOKEN_LENGTH+1; this->config.oauth_secret = rv[1]+OAUTH_SECRET_LENGTH+1; free(rv); res = 1; } return res; }
// 取得したキーでつぶやく int post_tweet(_TCHAR *consumer_key, _TCHAR *consumer_secret, _TCHAR *access_key, _TCHAR *access_secret, _TCHAR *tweet) { std::string c_key; //< consumer key std::string c_secret; //< consumer secret std::string t_key; //< access key std::string t_secret; //< access secret std::string message; //< tweetする内容 std::string req_url; std::string postarg; std::string reply; // アプリケーションのキーを代入 c_key = consumer_key; c_secret = consumer_secret; t_key = access_key; t_secret = access_secret; message = tweet; printf("Tweet Message..\n"); printf("consumer_key: %s\n", c_key.c_str()); printf("consumer_secret: %s\n", c_secret.c_str()); printf("access_key: %s\n", t_key.c_str()); printf("access_secret: %s\n", t_secret.c_str()); printf("message: %s\n", message.c_str()); if (!message.empty()) { { int n; wchar_t ucs2[1000]; char utf8[1000]; n = MultiByteToWideChar(CP_ACP, 0, message.c_str(), message.size(), ucs2, 1000); n = WideCharToMultiByte(CP_UTF8, 0, ucs2, n, utf8, 1000, 0, 0); message.assign(utf8, n); } std::string uri = "http://api.twitter.com/statuses/update.json"; uri += "?status="; uri += oauth_url_escape(message.c_str()); req_url = oauth_sign_url2(uri.c_str(), &postarg, OA_HMAC, 0, c_key.c_str(), c_secret.c_str(), t_key.c_str(), t_secret.c_str()); reply = oauth_http_post(req_url.c_str(), postarg.c_str()); /* 取得したjsonをファイルに書き出す */ FILE *fp; fp = fopen("post_message.json","w"); fputs( reply.c_str() , fp ); fclose( fp ); } return TRUE; }
/************************************Get file(folder) information*****************************************/ string kp_api::GetMetadata(string path) { path = oauth_url_escape(path.c_str()); string url = kp_api::m_metadata_url+"/"+kp_api::m_root+path; string req_url; req_url = oauth_sign_url2(url.c_str(), NULL, OA_HMAC, NULL, m_kpoauth.consumer_key.c_str(),m_kpoauth.consumer_secret.c_str(), m_kpoauth.oauth_token.c_str(),m_kpoauth.oauth_token_secret.c_str()); string reply = oauth_http_get(req_url.c_str(),NULL); return reply; }
/************************************delete function:*****************************************/ string kp_api::Delete(string path) { string path_encode = oauth_url_escape(path.c_str()); string url = kp_api::m_delete_url+"?root="+kp_api::m_root+"?&path="+path_encode; string req_url = oauth_sign_url2(url.c_str(), NULL, OA_HMAC, NULL, m_kpoauth.consumer_key.c_str(),m_kpoauth.consumer_secret.c_str(), m_kpoauth.oauth_token.c_str (),m_kpoauth.oauth_token_secret.c_str()); //cout<<req_url<<endl; string reply = oauth_http_get(req_url.c_str(),NULL); return reply; }
/* * test parameter encoding */ int test_encoding(char *param, char *expected) { int rv=0; char *testcase=NULL; testcase = oauth_url_escape(param); if (strcmp(testcase,expected)) { rv=1; printf("parameter encoding test for '%s' failed.\n" " got: '%s' expected: '%s'\n", param, testcase, expected); } else if (loglevel) printf("parameter encoding ok. ('%s')\n", testcase); if (testcase) free(testcase); return (rv); }
bool kp_api::Upload(string upload_path,string local_path) { char *postarg = NULL; string path = oauth_url_escape(upload_path.c_str()); string upload_url = kp_api::GetUploadUrl()+"1/fileops/upload_file?overwrite=true?&root="+kp_api::m_root+"?&path="+path; string req_url = oauth_sign_url2(upload_url.c_str(),&postarg,OA_HMAC,NULL,m_kpoauth.consumer_key.c_str(),m_kpoauth.consumer_secret.c_str(),m_kpoauth.oauth_token.c_str(),m_kpoauth.oauth_token_secret.c_str()); /*Parameters: url The request URL to be signed. append all GET or POST query-parameters separated by either '?' or '&' to this parameter. postargs This parameter points to an area where the return value is stored. If 'postargs' is NULL, no value is stored. method specify the signature method to use. It is of type OAuthMethod and most likely OA_HMAC. http_method The HTTP request method to use (ie "GET", "PUT",..) If NULL is given as 'http_method' this defaults to "GET" when 'postargs' is also NULL and when postargs is not NULL "POST" is used. */ //回来在这里写liburl上传文件的程序... //cout<<req_url<<endl; req_url = req_url+"?"+postarg; //cout<<req_url<<endl; //upload file using the http post way of curl CURL *curl; CURLcode res; struct curl_httppost *formpost=NULL; struct curl_httppost *lastptr=NULL; struct curl_slist *headerlist=NULL; static const char buf[]="Expect:"; curl_global_init(CURL_GLOBAL_ALL); curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME,"file", CURLFORM_FILE,local_path.c_str(), CURLFORM_END); curl = curl_easy_init(); headerlist = curl_slist_append(headerlist,buf); curl_easy_setopt(curl,CURLOPT_URL,req_url.c_str()); curl_easy_setopt(curl,CURLOPT_HTTPHEADER,headerlist); curl_easy_setopt(curl,CURLOPT_HTTPPOST,formpost); //curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data); //curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp); res = curl_easy_perform(curl); int infocode; curl_easy_getinfo(curl,CURLINFO_RESPONSE_CODE,&infocode); curl_easy_cleanup(curl); curl_formfree(formpost); curl_slist_free_all(headerlist); return infocode==200 ? true:false; }
string CSnsSigCheck:: url_encode(const string& src) { char* p_dest = oauth_url_escape(src.c_str()); if (p_dest == NULL) { return ""; } string str_dest = p_dest; delete [] p_dest; p_dest = NULL; str_dest = replace_str(str_dest, "~", "%7E"); return str_dest; }
get_pJWTAssertion(){ int rc=0; char * signature = 0; // Before getting here, example: lr_save_string("*****@*****.**","GoogleAPIServiceEmail"); // Each vuser gets its own tokens. // Google will return "Invalid Request' if the current time sent is off more than a just a few seconds from Google's server, so: // TODO: 14. Wherever machine this runs on needs to be synced to NTP or time.gov for UTC (GMT) timezone. // Google returns "invalid_grant" 400 error response if the previous token has not expired yet. // So loop is needed to re-use tokens until its expiration: lr_param_sprintf("pTimeNow","%d",time(0)); // where time(0) generates 10-digits. if( strcmp( lr_eval_string("{pTimeNow}"), lr_eval_string("{pTimeExpire}")) < 0 ){ wi_startPrintingTrace(); // Re-use assertion saved for use instead of running get_pJWTAssertion() again now. lr_output_message(">> JWT assertion token reuse: pTimeNow=%s, pTimeExpire=%s" ,lr_eval_string("{pTimeNow}") ,lr_eval_string("{pTimeExpire}") ); wi_stopPrinting(); } else { // First iteration or generated one expired: lr_param_sprintf("pTimeExpire","%d",time(0)+1800); // Google allows up to 3600 (one hour). } // The spec this should follow is http://tools.ietf.org/id/draft-jones-json-web-token-08.html#rfc.section.3.1 lr_param_sprintf("JWTBody", "{\"iss\":\"%s\"," "\"scope\":\"%s\"," "\"aud\":\"https://accounts.google.com/o/oauth2/token\"," "\"exp\":%s,\"iat\":%s}", lr_eval_string("{GoogleAPIServiceEmail}"), lr_eval_string("{pServiceScope}"), lr_eval_string("{pTimeExpire}"), lr_eval_string("{pTimeNow}")); // "aud" (audit) without back-slashes is: https://accounts.google.com/o/oauth2/token // "prn" (principal) is not set because it's not applicable for Gmail accounts, only Google Apps accounts granted domain-wide delegation access by an administrator. // Encode Header dot Claim set: lr_param_sprintf("pEncoded","%s.%s", oauth_url_escape(oauth_encode_base64(0,"{\"alg\":\"RS256\",\"typ\":\"JWT\"}")), oauth_url_escape(oauth_encode_base64(0,lr_eval_string("{JWTBody}")))); // "alg:RS256" = algorithm RSA P-256 SHA-256 used by Google APIs // "alg:HS256" = used by Google Wallet and OpenID // "alg:ES256" = algorithm ECDSA P-256 SHA-256 used by Salesforce // Microsoft Live Connect API signature = (char*)oauth_sign_rsa_sha256( lr_eval_string("{pEncoded}") ); lr_param_sprintf("pJWTAssertion","%s.%s", lr_eval_string("{pEncoded}"), oauth_url_escape(signature)); // Verify assertion output on-line using https://developers.google.com/commerce/wallet/digital/docs/jwtdecoder // https://developers.google.com/wallet/digital/docs/jwtdecoder wi_startPrintingTrace(); lr_output_message(">> JWTBody=%s." ,lr_eval_string("{JWTBody}") ); lr_output_message(">> pEncoded=%s." ,lr_eval_string("{pEncoded}") ); lr_output_message(">> pJWTAssertion=%s." ,lr_eval_string("{pJWTAssertion}") ); lr_output_message(">> signature=%s." ,signature ); wi_stopPrinting(); return rc; } // get_pJWTAssertion()
static int send_request(struct session *session) { char endpoint[500]; char user_password[500]; char data[500]; struct bti_curl_buffer *curl_buf; CURL *curl = NULL; CURLcode res; struct curl_httppost *formpost = NULL; struct curl_httppost *lastptr = NULL; struct curl_slist *slist = NULL; char *req_url = NULL; char *reply = NULL; char *postarg = NULL; char *escaped_tweet = NULL; int is_post = 0; if (!session) return -EINVAL; if (!session->hosturl) session->hosturl = strdup(twitter_host); if (session->no_oauth || session->guest) { curl_buf = bti_curl_buffer_alloc(session->action); if (!curl_buf) return -ENOMEM; curl_buf->session = session; curl = curl_init(); if (!curl) return -EINVAL; if (!session->hosturl) session->hosturl = strdup(twitter_host); switch (session->action) { case ACTION_UPDATE: snprintf(user_password, sizeof(user_password), "%s:%s", session->account, session->password); snprintf(data, sizeof(data), "status=\"%s\"", session->tweet); curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "status", CURLFORM_COPYCONTENTS, session->tweet, CURLFORM_END); curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "source", CURLFORM_COPYCONTENTS, "bti", CURLFORM_END); if (session->replyto) curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "in_reply_to_status_id", CURLFORM_COPYCONTENTS, session->replyto, CURLFORM_END); curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost); slist = curl_slist_append(slist, "Expect:"); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist); sprintf(endpoint, "%s%s", session->hosturl, update_uri); curl_easy_setopt(curl, CURLOPT_URL, endpoint); curl_easy_setopt(curl, CURLOPT_USERPWD, user_password); break; case ACTION_FRIENDS: snprintf(user_password, sizeof(user_password), "%s:%s", session->account, session->password); sprintf(endpoint, "%s%s?page=%d", session->hosturl, friends_uri, session->page); curl_easy_setopt(curl, CURLOPT_URL, endpoint); curl_easy_setopt(curl, CURLOPT_USERPWD, user_password); break; case ACTION_USER: sprintf(endpoint, "%s%s%s.xml?page=%d", session->hosturl, user_uri, session->user, session->page); curl_easy_setopt(curl, CURLOPT_URL, endpoint); break; case ACTION_REPLIES: snprintf(user_password, sizeof(user_password), "%s:%s", session->account, session->password); sprintf(endpoint, "%s%s?page=%d", session->hosturl, replies_uri, session->page); curl_easy_setopt(curl, CURLOPT_URL, endpoint); curl_easy_setopt(curl, CURLOPT_USERPWD, user_password); break; case ACTION_PUBLIC: sprintf(endpoint, "%s%s?page=%d", session->hosturl, public_uri, session->page); curl_easy_setopt(curl, CURLOPT_URL, endpoint); break; case ACTION_GROUP: sprintf(endpoint, "%s%s%s.xml?page=%d", session->hosturl, group_uri, session->group, session->page); curl_easy_setopt(curl, CURLOPT_URL, endpoint); break; default: break; } if (session->proxy) curl_easy_setopt(curl, CURLOPT_PROXY, session->proxy); if (debug) curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); dbg("user_password = %s\n", user_password); dbg("data = %s\n", data); dbg("proxy = %s\n", session->proxy); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_callback); curl_easy_setopt(curl, CURLOPT_WRITEDATA, curl_buf); if (!session->dry_run) { res = curl_easy_perform(curl); if (!session->background) { xmlDocPtr doc; xmlNodePtr current; if (res) { fprintf(stderr, "error(%d) trying to " "perform operation\n", res); return -EINVAL; } doc = xmlReadMemory(curl_buf->data, curl_buf->length, "response.xml", NULL, XML_PARSE_NOERROR); if (doc == NULL) return -EINVAL; current = xmlDocGetRootElement(doc); if (current == NULL) { fprintf(stderr, "empty document\n"); xmlFreeDoc(doc); return -EINVAL; } if (xmlStrcmp(current->name, (const xmlChar *)"status")) { fprintf(stderr, "unexpected document type\n"); xmlFreeDoc(doc); return -EINVAL; } xmlFreeDoc(doc); } } curl_easy_cleanup(curl); if (session->action == ACTION_UPDATE) curl_formfree(formpost); bti_curl_buffer_free(curl_buf); } else { switch (session->action) { case ACTION_UPDATE: escaped_tweet = oauth_url_escape(session->tweet); if (session->replyto) { sprintf(endpoint, "%s%s?status=%s&in_reply_to_status_id=%s", session->hosturl, update_uri, escaped_tweet, session->replyto); } else { sprintf(endpoint, "%s%s?status=%s", session->hosturl, update_uri, escaped_tweet); } is_post = 1; break; case ACTION_USER: sprintf(endpoint, "%s%s%s.xml?page=%d", session->hosturl, user_uri, session->user, session->page); break; case ACTION_REPLIES: sprintf(endpoint, "%s%s?page=%d", session->hosturl, mentions_uri, session->page); break; case ACTION_PUBLIC: sprintf(endpoint, "%s%s?page=%d", session->hosturl, public_uri, session->page); break; case ACTION_GROUP: sprintf(endpoint, "%s%s%s.xml?page=%d", session->hosturl, group_uri, session->group, session->page); break; case ACTION_FRIENDS: sprintf(endpoint, "%s%s?page=%d", session->hosturl, friends_uri, session->page); break; case ACTION_RETWEET: sprintf(endpoint, "%s%s%s.xml", session->hosturl, retweet_uri, session->retweet); is_post = 1; break; default: break; } dbg("%s\n", endpoint); if (!session->dry_run) { if (is_post) { req_url = oauth_sign_url2(endpoint, &postarg, OA_HMAC, NULL, session->consumer_key, session->consumer_secret, session->access_token_key, session->access_token_secret); reply = oauth_http_post(req_url, postarg); } else { req_url = oauth_sign_url2(endpoint, NULL, OA_HMAC, NULL, session->consumer_key, session->consumer_secret, session->access_token_key, session->access_token_secret); reply = oauth_http_get(req_url, postarg); } dbg("%s\n", req_url); dbg("%s\n", reply); if (req_url) free(req_url); } if (!reply) { fprintf(stderr, "Error retrieving from URL (%s)\n", endpoint); return -EIO; } if ((session->action != ACTION_UPDATE) && (session->action != ACTION_RETWEET)) parse_timeline(reply, session); } return 0; }
bool kp_api::Download(string download_path,string local_path) { string path_encode = oauth_url_escape(download_path.c_str()); string url = kp_api::m_download_url+"?root="+kp_api::m_root+"?&path="+path_encode; string req_url = oauth_sign_url2(url.c_str(), NULL, OA_HMAC, NULL, m_kpoauth.consumer_key.c_str(),m_kpoauth.consumer_secret.c_str(), m_kpoauth.oauth_token.c_str (),m_kpoauth.oauth_token_secret.c_str()); //cout<<req_url<<endl; //req_url is download url , tomorrow try to solute the download problem! CURL *curl; FILE *fp; CURLcode res; //char outfilename[FILENAME_MAX] = "x.txt"; struct MemoryStruct chunk; chunk.memory = (char *)malloc(1); /* will be grown as needed by the realloc above */ chunk.size = 0; /* no data at this point */ string cookie(""); fp = fopen(local_path.c_str(),"wb"); bool isJump = true; int infocode = 0; while(isJump) { curl = curl_easy_init(); curl_easy_setopt(curl, CURLOPT_URL,req_url.c_str()); curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1L); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data); curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp); curl_easy_setopt(curl, CURLOPT_HEADER, 0L); curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, WriteMemoryCallback); curl_easy_setopt(curl, CURLOPT_WRITEHEADER, (void *)&chunk); curl_easy_setopt(curl,CURLOPT_COOKIE,cookie.c_str()); res = curl_easy_perform(curl); //cout<<"***"<<chunk.memory<<endl; curl_easy_getinfo(curl,CURLINFO_RESPONSE_CODE,&infocode);//get the return http info code,if it is 302,it means that the url will jump another url. //cout<<infocode<<endl; if(infocode==302) {//if it is 302,we need get the jump url and cookie! string str = chunk.memory; int k = str.find("Set-Cookie: ",0); int i = str.find("Location: ",0); int j = str.find("Content-Length:",0); k+=12; int len1 = i-k-2; cookie = str.substr(k,len1); i+=10; //cout<<"***"<<cookie<<endl; int len2 = j-i-2; req_url = str.substr(i,len2); //cout<<"***"<<req_url<<endl; continue; } else if(infocode==200) { cout<<local_path+"\t\tdownload success!"<<endl;//2012-06-14 } isJump = false; } curl_easy_cleanup(curl); fclose(fp); return infocode==200 ? true:false; }
static int send_request(struct session *session) { char endpoint[500]; char user_password[500]; char data[500]; struct bti_curl_buffer *curl_buf; CURL *curl = NULL; CURLcode res; struct curl_httppost *formpost = NULL; struct curl_httppost *lastptr = NULL; struct curl_slist *slist = NULL; char *req_url = NULL; char *reply = NULL; char *postarg = NULL; char *escaped_tweet = NULL; int is_post = 0; if (!session) return -EINVAL; if (!session->hosturl) session->hosturl = strdup(twitter_host); if (session->no_oauth) { curl_buf = bti_curl_buffer_alloc(session->action); if (!curl_buf) return -ENOMEM; curl = curl_init(); if (!curl) return -EINVAL; if (!session->hosturl) session->hosturl = strdup(twitter_host); switch (session->action) { case ACTION_UPDATE: snprintf(user_password, sizeof(user_password), "%s:%s", session->account, session->password); snprintf(data, sizeof(data), "status=\"%s\"", session->tweet); curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "status", CURLFORM_COPYCONTENTS, session->tweet, CURLFORM_END); curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "source", CURLFORM_COPYCONTENTS, "bti", CURLFORM_END); if (session->replyto) curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "in_reply_to_status_id", CURLFORM_COPYCONTENTS, session->replyto, CURLFORM_END); curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost); slist = curl_slist_append(slist, "Expect:"); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist); sprintf(endpoint, "%s%s", session->hosturl, update_uri); curl_easy_setopt(curl, CURLOPT_URL, endpoint); curl_easy_setopt(curl, CURLOPT_USERPWD, user_password); break; case ACTION_FRIENDS: snprintf(user_password, sizeof(user_password), "%s:%s", session->account, session->password); sprintf(endpoint, "%s%s?page=%d", session->hosturl, friends_uri, session->page); curl_easy_setopt(curl, CURLOPT_URL, endpoint); curl_easy_setopt(curl, CURLOPT_USERPWD, user_password); break; case ACTION_USER: snprintf(user_password, sizeof(user_password), "%s:%s", session->account, session->password); sprintf(endpoint, "%s%s?screen_name=%s&page=%d", session->hosturl, user_uri, session->user, session->page); curl_easy_setopt(curl, CURLOPT_URL, endpoint); curl_easy_setopt(curl, CURLOPT_USERPWD, user_password); break; case ACTION_REPLIES: snprintf(user_password, sizeof(user_password), "%s:%s", session->account, session->password); sprintf(endpoint, "%s%s?page=%d", session->hosturl, replies_uri, session->page); curl_easy_setopt(curl, CURLOPT_URL, endpoint); curl_easy_setopt(curl, CURLOPT_USERPWD, user_password); break; case ACTION_PUBLIC: snprintf(user_password, sizeof(user_password), "%s:%s", session->account, session->password); sprintf(endpoint, "%s%s?page=%d", session->hosturl, public_uri, session->page); curl_easy_setopt(curl, CURLOPT_URL, endpoint); curl_easy_setopt(curl, CURLOPT_USERPWD, user_password); break; case ACTION_GROUP: snprintf(user_password, sizeof(user_password), "%s:%s", session->account, session->password); sprintf(endpoint, "%s%s%s.xml?page=%d", session->hosturl, group_uri, session->group, session->page); curl_easy_setopt(curl, CURLOPT_URL, endpoint); curl_easy_setopt(curl, CURLOPT_USERPWD, user_password); break; default: break; } if (session->proxy) curl_easy_setopt(curl, CURLOPT_PROXY, session->proxy); if (debug) curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); dbg("user_password = %s\n", user_password); dbg("data = %s\n", data); dbg("proxy = %s\n", session->proxy); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_callback); curl_easy_setopt(curl, CURLOPT_WRITEDATA, curl_buf); if (!session->dry_run) { res = curl_easy_perform(curl); if (res && !session->background) { fprintf(stderr, "error(%d) trying to perform " "operation\n", res); return -EINVAL; } } curl_easy_cleanup(curl); if (session->action == ACTION_UPDATE) curl_formfree(formpost); bti_curl_buffer_free(curl_buf); } else { switch (session->action) { case ACTION_UPDATE: escaped_tweet = oauth_url_escape(session->tweet); sprintf(endpoint, "%s%s?status=%s", session->hosturl, update_uri, escaped_tweet); is_post = 1; break; case ACTION_USER: sprintf(endpoint, "%s%s%s.xml?page=%d", session->hosturl, user_uri, session->user, session->page); break; case ACTION_REPLIES: sprintf(endpoint, "%s%s?page=%d", session->hosturl, mentions_uri, session->page); break; case ACTION_PUBLIC: sprintf(endpoint, "%s%s?page=%d", session->hosturl, public_uri, session->page); break; case ACTION_GROUP: sprintf(endpoint, "%s%s%s.xml?page=%d", session->hosturl, group_uri, session->group, session->page); break; case ACTION_FRIENDS: sprintf(endpoint, "%s%s?page=%d", session->hosturl, friends_uri, session->page); break; default: break; } if (is_post) { req_url = oauth_sign_url2(endpoint, &postarg, OA_HMAC, NULL, session->consumer_key, session->consumer_secret, session->access_token_key, session->access_token_secret); reply = oauth_http_post(req_url, postarg); } else { req_url = oauth_sign_url2(endpoint, NULL, OA_HMAC, NULL, session->consumer_key, session->consumer_secret, session->access_token_key, session->access_token_secret); reply = oauth_http_get(req_url, postarg); } dbg("%s\n", req_url); dbg("%s\n", reply); if (req_url) free(req_url); if (session->action != ACTION_UPDATE) parse_timeline(reply); } return 0; }