- free(session->proxy);
- session->proxy = proxy;
- }
- if (logfile)
- session->logfile = logfile;
- if (action) {
- if (strcasecmp(action, "update") == 0)
- session->action = ACTION_UPDATE;
- else if (strcasecmp(action, "friends") == 0)
- session->action = ACTION_FRIENDS;
- else if (strcasecmp(action, "user") == 0)
- session->action = ACTION_USER;
- else if (strcasecmp(action, "replies") == 0)
- session->action = ACTION_REPLIES;
- else if (strcasecmp(action, "public") == 0)
- session->action = ACTION_PUBLIC;
- else if (strcasecmp(action, "group") == 0)
- session->action = ACTION_GROUP;
- else
- session->action = ACTION_UNKNOWN;
- free(action);
- }
- if (user)
- session->user = user;
- session->shrink_urls = shrink_urls;
+ 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);
+ }