# HG changeset patch # User Yoshiki Yazawa # Date 1260544707 -32400 # Node ID 2e37e715e4a6d0f3db818a7ebf4b7e0a4a48483a # Parent 3d2657ce4dba1e9aa4e3ee479aea4614e65769c7 add preliminary support for quotetweet and official retweet. diff -r 3d2657ce4dba -r 2e37e715e4a6 Makefile.in --- a/Makefile.in Mon Oct 19 00:48:25 2009 +0900 +++ b/Makefile.in Sat Dec 12 00:18:27 2009 +0900 @@ -9,7 +9,7 @@ PIDGIN_CFLAGS = @PIDGIN_CFLAGS@ GLIB_CFLAGS = @GLIB_CFLAGS@ XML_CFLAGS = @XML_CFLAGS@ -CFLAGS = -fPIC -shared -Wall -g $(PIDGIN_CFLAGS) $(GLIB_CFLAGS) $(XML_CFLAGS) -DDATADIR=\"$(PIDGIN_DATA_DIR)\" +CFLAGS = -fPIC -shared -Wall -Werror -g $(PIDGIN_CFLAGS) $(GLIB_CFLAGS) $(XML_CFLAGS) -DDATADIR=\"$(PIDGIN_DATA_DIR)\" GLIB_LIBS = @GLIB_LIBS@ XML_LIBS = @XML_LIBS@ diff -r 3d2657ce4dba -r 2e37e715e4a6 configure.ac --- a/configure.ac Mon Oct 19 00:48:25 2009 +0900 +++ b/configure.ac Sat Dec 12 00:18:27 2009 +0900 @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.59) -AC_INIT(pidgin-twitter, 0.9.0, yaz@honeyplanet.jp) +AC_INIT(pidgin-twitter, 0.9.1, yaz@honeyplanet.jp) AC_CONFIG_SRCDIR([main.c]) # Checks for programs. diff -r 3d2657ce4dba -r 2e37e715e4a6 main.c --- a/main.c Mon Oct 19 00:48:25 2009 +0900 +++ b/main.c Sat Dec 12 00:18:27 2009 +0900 @@ -1420,7 +1420,7 @@ PURPLE_PRIORITY_DEFAULT, /**< priority */ PLUGIN_ID, /**< id */ "Pidgin-Twitter", /**< name */ - "0.9.0", /**< version */ + "0.9.1", /**< version */ "provides useful features for twitter", /** summary */ "provides useful features for twitter", /** desc */ "Yoshiki Yazawa, mikanbako, \nKonosuke Watanabe, IWATA Ray, \nmojin, umq, \nthe pidging-twitter team", /**< author */ diff -r 3d2657ce4dba -r 2e37e715e4a6 pidgin-twitter.h --- a/pidgin-twitter.h Mon Oct 19 00:48:25 2009 +0900 +++ b/pidgin-twitter.h Sat Dec 12 00:18:27 2009 +0900 @@ -172,7 +172,7 @@ #define TAG_FORMAT_TWITTER "%s#%s" #define TAG_FORMAT_IDENTICA "#%s" #define GROUP_FORMAT_IDENTICA "!%s" -#define LINK_FORMAT_TWITTER " R F RT" +#define LINK_FORMAT_TWITTER " RE FV RT QT" #define DEFAULT_LIST "(list of users: separated with ' ,:;')" #define OOPS_MESSAGE "Oops! Your update was over 140 characters. We sent the short version to your friends (they can view the entire update on the web).
" @@ -201,10 +201,17 @@ /* twitter API specific macros */ #define TWITTER_BASE_URL "http://twitter.com" +#define TWITTER_API_BASE_URL "http://api.twitter.com" +#if 0 #define TWITTER_STATUS_GET "GET /statuses/friends_timeline.xml?count=%d HTTP/1.1\r\n" \ "Host: twitter.com\r\n" \ "User-Agent: pidgin-twitter\r\n" \ "Authorization: Basic %s\r\n" +#endif +#define TWITTER_STATUS_GET "GET /1/statuses/home_timeline.xml?count=%d HTTP/1.1\r\n" \ + "Host: api.twitter.com\r\n" \ + "User-Agent: pidgin-twitter\r\n" \ + "Authorization: Basic %s\r\n" #define TWITTER_STATUS_POST "POST /statuses/update.xml HTTP/1.1\r\n" \ "Host: twitter.com\r\n" \ "User-Agent: pidgin-twitter\r\n" \ @@ -214,6 +221,10 @@ "Host: twitter.com\r\n" \ "User-Agent: pidgin-twitter\r\n" \ "Authorization: Basic %s\r\n" +#define TWITTER_RETWEET_POST "POST /1/statuses/retweet/%llu.xml HTTP/1.1\r\n" \ + "Host: api.twitter.com\r\n" \ + "User-Agent: pidgin-twitter\r\n" \ + "Authorization: Basic %s\r\n" #define TWITTER_STATUS_FORMAT "status=%s&source=pidgintwitter" #define TWITTER_REPLY_FORMAT "status=%s&in_reply_to_status_id=%llu&source=pidgintwitter" diff -r 3d2657ce4dba -r 2e37e715e4a6 twitter_api.c --- a/twitter_api.c Mon Oct 19 00:48:25 2009 +0900 +++ b/twitter_api.c Sat Dec 12 00:18:27 2009 +0900 @@ -332,7 +332,7 @@ request = g_strconcat(header, "\r\n", NULL); /* invoke fetch */ - purple_util_fetch_url_request(TWITTER_BASE_URL, FALSE, + purple_util_fetch_url_request(TWITTER_API_BASE_URL, FALSE, NULL, TRUE, request, TRUE, get_status_with_api_cb, data); @@ -598,6 +598,55 @@ g_free(request); } +static void +retweet_with_api_cb(PurpleUtilFetchUrlData *url_data, gpointer user_data, + const gchar *url_text, size_t len, + const gchar *error_message) +{ + /* dummy */ +} + +void +retweet_with_api(guint64 id) +{ + char *header, *request; + char *basic_auth, *basic_auth_encoded; + + const char *screen_name = + purple_prefs_get_string(OPT_SCREEN_NAME_TWITTER); + const char *password = purple_prefs_get_string(OPT_PASSWORD_TWITTER); + + if(id == 0) { + twitter_debug("invalid message id\n"); + return; + } + + if (!screen_name || !password || !screen_name[0] || !password[0]) { + twitter_debug("screen_name or password is empty\n"); + return; + } + + basic_auth = g_strdup_printf("%s:%s", screen_name, password); + basic_auth_encoded = purple_base64_encode((unsigned char *)basic_auth, + strlen(basic_auth)); + g_free(basic_auth); + + + header = g_strdup_printf(TWITTER_RETWEET_POST, + (long long unsigned int)id, + basic_auth_encoded); + request = g_strconcat(header, "\r\n", NULL); + + purple_util_fetch_url_request(TWITTER_API_BASE_URL, FALSE, + NULL, TRUE, request, TRUE, + retweet_with_api_cb, NULL); + twitter_debug("request = %s\n", request); + + g_free(header); + g_free(basic_auth_encoded); + g_free(request); +} + void signed_on_cb(PurpleConnection *gc) { diff -r 3d2657ce4dba -r 2e37e715e4a6 twitter_api.h --- a/twitter_api.h Mon Oct 19 00:48:25 2009 +0900 +++ b/twitter_api.h Sat Dec 12 00:18:27 2009 +0900 @@ -3,6 +3,8 @@ void post_status_with_api(PurpleAccount *account, char **buffer); gboolean get_status_with_api(gpointer data); +void fav_with_api(guint64 id); +void retweet_with_api(guint64 id); void signed_on_cb(PurpleConnection *gc); #endif diff -r 3d2657ce4dba -r 2e37e715e4a6 util.c --- a/util.c Mon Oct 19 00:48:25 2009 +0900 +++ b/util.c Sat Dec 12 00:18:27 2009 +0900 @@ -6,7 +6,6 @@ /* prototypes */ static gchar *twitter_memrchr(const gchar *s, int c, size_t n); -void fav_with_api(guint64 id); /* functions */ @@ -485,6 +484,11 @@ return TRUE; } else if(strstr(cmd, "retweet-twitter")) { + idstr = g_hash_table_lookup(params, "id"); + retweet_with_api(strtoull(idstr, NULL, 10)); + return TRUE; + } + else if(strstr(cmd, "quotetweet-twitter")) { gchar *msg0; sender = g_hash_table_lookup(params, "user"); idstr = g_hash_table_lookup(params, "id"); @@ -503,7 +507,7 @@ twitter_debug("sender = %s, id = %llu\n", sender, (unsigned long long)msgid); - recipient = g_strdup_printf("RT @%s: %s", sender, msg); + recipient = g_strdup_printf("QT @%s: %s", sender, msg); g_free(msg); gtk_text_buffer_insert_at_cursor(gtkconv->entry_buffer, recipient, -1); @@ -559,7 +563,8 @@ linkstr = g_strdup_printf(LINK_FORMAT_TWITTER, idstr, user, /* Reply */ idstr, /* Favorite */ - idstr, user, boddy); /* Retweet */ + idstr, /* Retweet */ + idstr, user, boddy); /* Quotetweet */ twitter_debug("linkstr = %s\n", linkstr);