From af4c95e5d392338d8b10d866e75ffd6c744531fa Mon Sep 17 00:00:00 2001 From: Dwi Sasongko S Date: Sat, 13 Nov 2010 10:54:56 +0700 Subject: [PATCH] Support proper 'reply_to' and 'retweet' Signed-off-by: Dwi Sasongko S Signed-off-by: Greg Kroah-Hartman --- bti.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 55 insertions(+), 4 deletions(-) diff --git a/bti.c b/bti.c index da49f93..0229a9a 100644 --- a/bti.c +++ b/bti.c @@ -68,7 +68,8 @@ enum action { ACTION_REPLIES = 4, ACTION_PUBLIC = 8, ACTION_GROUP = 16, - ACTION_UNKNOWN = 32 + ACTION_RETWEET = 32, + ACTION_UNKNOWN = 64 }; struct session { @@ -89,6 +90,7 @@ struct session { char *hostname; char *configfile; char *replyto; + char *retweet; int bash; int background; int interactive; @@ -126,6 +128,7 @@ static void display_help(void) " --logfile logfile\n" " --config configfile\n" " --replyto ID\n" + " --retweet ID\n" " --shrink-urls\n" " --page PAGENUMBER\n" " --bash\n" @@ -252,6 +255,7 @@ static void session_free(struct session *session) { if (!session) return; + free(session->retweet); free(session->replyto); free(session->password); free(session->account); @@ -317,6 +321,7 @@ static const char public_uri[] = "/public_timeline.xml"; static const char friends_uri[] = "/friends_timeline.xml"; static const char mentions_uri[] = "/mentions.xml"; static const char replies_uri[] = "/replies.xml"; +static const char retweet_uri[] = "/retweet/"; static const char group_uri[] = "/../statusnet/groups/timeline/"; static CURL *curl_init(void) @@ -700,8 +705,17 @@ static int send_request(struct session *session) 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); + 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: @@ -726,6 +740,11 @@ static int send_request(struct session *session) 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; } @@ -751,7 +770,8 @@ static int send_request(struct session *session) if (req_url) free(req_url); - if (session->action != ACTION_UPDATE) + if ((session->action != ACTION_UPDATE) && + (session->action != ACTION_RETWEET)) parse_timeline(reply); } return 0; @@ -774,6 +794,7 @@ static void parse_configfile(struct session *session) char *action = NULL; char *user = NULL; char *replyto = NULL; + char *retweet = NULL; int shrink_urls = 0; config_file = fopen(session->configfile, "r"); @@ -872,6 +893,11 @@ static void parse_configfile(struct session *session) if (!strncasecmp(c, "true", 4) || !strncasecmp(c, "yes", 3)) verbose = 1; + } else if (!strncasecmp(c,"retweet", 7) && + (c[7] == '=')) { + c += 8; + if (c[0] != '\0') + retweet = strdup(c); } } while (!feof(config_file)); @@ -912,6 +938,8 @@ static void parse_configfile(struct session *session) session->logfile = logfile; if (replyto) session->replyto = replyto; + if (retweet) + session->retweet = retweet; if (action) { if (strcasecmp(action, "update") == 0) session->action = ACTION_UPDATE; @@ -1320,11 +1348,13 @@ int main(int argc, char *argv[], char *envp[]) { "version", 0, NULL, 'v' }, { "config", 1, NULL, 'c' }, { "replyto", 1, NULL, 'r' }, + { "retweet", 1, NULL, 'w' }, { } }; struct session *session; pid_t child; char *tweet; + char *retweet; static char password[80]; int retval = 0; int option; @@ -1393,6 +1423,10 @@ int main(int argc, char *argv[], char *envp[]) session->replyto = strdup(optarg); dbg("in_reply_to_status_id = %s\n", session->replyto); break; + case 'w': + session->retweet = strdup(optarg); + dbg("Retweet ID = %s\n", session->retweet); + break; case 'p': if (session->password) free(session->password); @@ -1418,6 +1452,8 @@ int main(int argc, char *argv[], char *envp[]) session->action = ACTION_PUBLIC; else if (strcasecmp(optarg, "group") == 0) session->action = ACTION_GROUP; + else if (strcasecmp(optarg,"retweet") == 0) + session->action = ACTION_RETWEET; else session->action = ACTION_UNKNOWN; dbg("action = %d\n", session->action); @@ -1553,6 +1589,21 @@ int main(int argc, char *argv[], char *envp[]) session->group = session->readline(NULL); } + if (session->action == ACTION_RETWEET) { + fprintf(stdout, "Status ID to retweet: "); + retweet = get_string_from_stdin(); + + if (!retweet || strlen(retweet) == 0) { + dbg("no retweet?\n"); + return -1; + } + + session->retweet = zalloc(strlen(retweet) + 10); + sprintf(session->retweet,"%s", retweet); + free(retweet); + dbg("retweet ID = %s\n", session->retweet); + } + if (session->action == ACTION_UPDATE) { if (session->background || !session->interactive) tweet = get_string_from_stdin(); -- 2.39.5