Merge branch 'master' into oath-test
authorGreg Kroah-Hartman <gregkh@suse.de>
Wed, 28 Jul 2010 00:31:13 +0000 (17:31 -0700)
committerGreg Kroah-Hartman <gregkh@suse.de>
Wed, 28 Jul 2010 00:31:13 +0000 (17:31 -0700)
Conflicts:
bti.c

Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
1  2 
bti.c

diff --cc bti.c
--- 1/bti.c
--- 2/bti.c
+++ b/bti.c
@@@ -249,12 -245,9 +251,13 @@@ static void session_free(struct sessio
  {
        if (!session)
                return;
+       free(session->replyto);
        free(session->password);
        free(session->account);
 +      free(session->consumer_key);
 +      free(session->consumer_secret);
 +      free(session->access_token_key);
 +      free(session->access_token_secret);
        free(session->tweet);
        free(session->proxy);
        free(session->time);
@@@ -570,165 -447,109 +578,170 @@@ static int send_request(struct session 
        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);
 +      if (session->no_oauth) {
 +              curl_buf = bti_curl_buffer_alloc(session->action);
 +              if (!curl_buf)
 +                      return -ENOMEM;
  
 -              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);
 +              curl = curl_init();
 +              if (!curl)
 +                      return -EINVAL;
  
 -              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);
 +              if (!session->hosturl)
 +                      session->hosturl = strdup(twitter_host);
  
 -              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);
 +              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;
 +              }
  
 -              break;
 -      case ACTION_PUBLIC:
 -              sprintf(endpoint, "%s%s?page=%d", session->hosturl, public_uri,
 -                      session->page);
 -              curl_easy_setopt(curl, CURLOPT_URL, endpoint);
 +              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->bash) {
 +                              fprintf(stderr, "error(%d) trying to perform "
 +                                              "operation\n", res);
 +                              return -EINVAL;
 +                      }
 +              }
  
 -              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);
 +              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:
 +                              sprintf(endpoint,
 +                                              "%s%s?status=%s",
 +                                              session->hosturl, update_uri, session->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;
 +              }
  
 -              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);
 +              }
  
 -      if (session->proxy)
 -              curl_easy_setopt(curl, CURLOPT_PROXY, session->proxy);
 +              dbg("%s\n", req_url);
 +              dbg("%s\n", reply);
 +              if (req_url)
 +                      free(req_url);
  
 -      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->bash) {
 -                      fprintf(stderr, "error(%d) trying to perform "
 -                              "operation\n", res);
 -                      return -EINVAL;
 -              }
 +              if (session->action != ACTION_UPDATE)
 +                      parse_timeline(reply);
        }
 -
 -      curl_easy_cleanup(curl);
 -      if (session->action == ACTION_UPDATE)
 -              curl_formfree(formpost);
 -      bti_curl_buffer_free(curl_buf);
        return 0;
  }