annotate twitter_api.c @ 364:cbdf0b35d31b default tip

Added tag 0.9.2.1 for changeset 85e109dee063
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Fri, 13 May 2011 00:02:49 +0900
parents c6392a86839b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
254
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1 #include "pidgin-twitter.h"
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
2
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
3 static GList *postedlist = NULL;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
4 static GList *statuseslist = NULL;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
5
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
6 /* prototypes */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
7 static void parse_user(xmlNode *user, status_t *st);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
8 static void read_timestamp(const char *str, struct tm *res);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
9 static void parse_status(xmlNode *status, status_t *st);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
10
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
11 static void free_status(status_t *st);
305
227e59f017f2 status id now exceeds int32 limit.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 304
diff changeset
12 static gboolean is_posted_message(status_t *status, guint64 lastid);
254
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
13 static void get_status_with_api_cb(PurpleUtilFetchUrlData *url_data, gpointer user_data, const gchar *url_text, size_t len, const gchar *error_message);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
14 static void post_status_with_api_cb(PurpleUtilFetchUrlData *url_data, gpointer user_data, const gchar *url_text, size_t len, const gchar *error_message);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
15
355
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
16 /* oauth */
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
17 #define TYPE_GET 0
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
18 #define TYPE_POST 1
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
19
357
732de90812d8 - fixed memory leaks
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 355
diff changeset
20 char *c_key = "wrD3WGIh2P31d3fIjRkfcw";
732de90812d8 - fixed memory leaks
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 355
diff changeset
21 char *c_sec = "ZEhViGY8P5IPjwgV8EVOkdjHhShRAZ9yhlYw0ZDXU";
732de90812d8 - fixed memory leaks
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 355
diff changeset
22 char *SAMPLE_NONCE = "0123456789abcdefghijk";
732de90812d8 - fixed memory leaks
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 355
diff changeset
23
355
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
24 typedef struct oauth_request {
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
25 char *url;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
26 char *c_key;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
27 char *c_sec;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
28 char *a_key;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
29 char *a_sec;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
30 char *verifier;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
31 char *status;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
32 PurpleConversation *conv;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
33 guint64 msgid;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
34 int count;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
35 int type;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
36 gboolean notoken;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
37 } oauth_request_t;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
38
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
39 char *make_oauth_get(oauth_request_t *oauth_req);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
40 char *make_oauth_post(oauth_request_t *auth_req);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
41 static void oauth_setup_cb(PurpleUtilFetchUrlData *url_data, gpointer user_data, const gchar *url_text, size_t len, const gchar *error_message);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
42
260
d973f9debe86 Fix Win32 compile error
Konosuke Watanabe <sasugaanija@gmail.com>
parents: 254
diff changeset
43 #ifdef _WIN32
d973f9debe86 Fix Win32 compile error
Konosuke Watanabe <sasugaanija@gmail.com>
parents: 254
diff changeset
44 extern gboolean blink_state;
d973f9debe86 Fix Win32 compile error
Konosuke Watanabe <sasugaanija@gmail.com>
parents: 254
diff changeset
45 extern gboolean blink_modified;
d973f9debe86 Fix Win32 compile error
Konosuke Watanabe <sasugaanija@gmail.com>
parents: 254
diff changeset
46 #endif
254
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
47
330
cc41ee1f5d3a implemented reply, favorite, retweet functionalities. these are quite raw, be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 315
diff changeset
48 extern guint64 reply_to_msgid;
cc41ee1f5d3a implemented reply, favorite, retweet functionalities. these are quite raw, be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 315
diff changeset
49 extern PurpleAccount *account_for_twitter;
cc41ee1f5d3a implemented reply, favorite, retweet functionalities. these are quite raw, be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 315
diff changeset
50
355
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
51
357
732de90812d8 - fixed memory leaks
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 355
diff changeset
52 /* oauth functions */
355
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
53 void
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
54 oauth_access_cb(PurpleUtilFetchUrlData *url_data, gpointer user_data,
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
55 const gchar *url_text, size_t len,
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
56 const gchar *error_message)
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
57 {
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
58 char *f = NULL, *e = NULL;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
59 oauth_request_t *oauth_req = (oauth_request_t *)user_data;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
60
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
61 /* separate key and secret */
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
62 f = strstr(url_text, "oauth_token=");
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
63 if(!f)
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
64 return;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
65 e = strstr(f, "&");
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
66 if(!e)
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
67 return;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
68 g_free(oauth_req->a_key);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
69 oauth_req->a_key = g_strndup(f+12, e-f-12);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
70
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
71 f = strstr(e+1, "oauth_token_secret=");
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
72 if(!f)
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
73 return;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
74 e = strstr(f, "&");
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
75 if(!e)
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
76 return;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
77 g_free(oauth_req->a_sec);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
78 oauth_req->a_sec = g_strndup(f+19, e-f-19);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
79
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
80 /* write a_key and a_sec to prefs */
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
81 purple_prefs_set_string(OPT_AKEY_TWITTER, oauth_req->a_key);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
82 purple_prefs_set_string(OPT_ASEC_TWITTER, oauth_req->a_sec);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
83
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
84 /* invoke fetch xxx */
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
85 g_usleep(3*1000000); /* wait for server configuration */
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
86 get_status_with_api((gpointer)oauth_req->conv);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
87
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
88 /* all done */
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
89 g_free(oauth_req->url);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
90 g_free(oauth_req->c_key);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
91 g_free(oauth_req->c_sec);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
92 g_free(oauth_req->a_key);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
93 g_free(oauth_req->a_sec);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
94 g_free(oauth_req);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
95 }
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
96
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
97
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
98 void
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
99 pin_dialog_ok_cb(gpointer data, char *pin)
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
100 {
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
101 char *oauth = NULL;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
102 char *request = NULL;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
103 oauth_request_t *oauth_req = (oauth_request_t *)data;
357
732de90812d8 - fixed memory leaks
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 355
diff changeset
104
355
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
105 /*
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
106 request URL:http://twitter.com/oauth/access_token?
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
107 oauth_consumer_key=wrD3WGIh2P31d3fIjRkfcw&
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
108 oauth_nonce=QUzhkt0AO3tjNrR&
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
109 oauth_signature_method=HMAC-SHA1&
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
110 oauth_timestamp=1282450223&
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
111 oauth_token=VL126k8KRNXid7Q7ZHYHh05PuASunVaPzyzrozf14&
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
112 oauth_verifier=9772286&
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
113 oauth_version=1.0&
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
114 oauth_signature=OyBsxqWdsvLkV4LBnN8tMBnImVY%3D
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
115 */
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
116
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
117 /* access token*/
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
118 g_free(oauth_req->url);
357
732de90812d8 - fixed memory leaks
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 355
diff changeset
119 oauth_req->url = g_strdup(ACCESS_TOKEN_URL);
355
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
120 oauth_req->verifier = g_strdup(pin);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
121 oauth_req->type = TYPE_GET;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
122 oauth_req->notoken = FALSE;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
123
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
124 twitter_debug("a_key=%s\n", oauth_req->a_key);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
125
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
126 oauth = make_oauth_get(oauth_req);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
127
357
732de90812d8 - fixed memory leaks
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 355
diff changeset
128 request = g_strdup_printf("%s?%s", ACCESS_TOKEN_URL, oauth);
355
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
129 twitter_debug("request=%s\n", request);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
130
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
131 purple_util_fetch_url_request(request, TRUE,
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
132 NULL, TRUE, NULL, TRUE,
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
133 oauth_access_cb, data);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
134 g_free(oauth);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
135 g_free(request);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
136 }
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
137
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
138
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
139 static void
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
140 oauth_setup_cb(PurpleUtilFetchUrlData *url_data, gpointer user_data,
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
141 const gchar *url_text, size_t len,
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
142 const gchar *error_message)
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
143 {
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
144 char *f = NULL, *e = NULL;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
145 oauth_request_t *oauth_req = (oauth_request_t *)user_data;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
146 PurpleConversation *conv = oauth_req->conv;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
147 PurpleAccount *account = purple_conversation_get_account(conv);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
148 PurpleConnection *conn = purple_conversation_get_gc(conv);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
149
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
150 g_return_if_fail(url_text != NULL);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
151 twitter_debug("len=%d\n", (int)len);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
152 twitter_debug("url_text=%s\n", url_text);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
153
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
154 /*
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
155 HTTP-reply:
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
156 oauth_token=zKILrNcVPGRtUE6Rlh1KU6upYNJWW51mzt7btZx5Ac&
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
157 oauth_token_secret=EMD3u1piAKPsQnq44Its9f8WmIReYnUFcJIgd3niu4&
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
158 oauth_callback_confirmed=true
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
159 */
357
732de90812d8 - fixed memory leaks
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 355
diff changeset
160
355
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
161 /* separate key and secret */
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
162 f = strstr(url_text, "oauth_token=");
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
163 if(!f)
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
164 return;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
165 e = strstr(f, "&");
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
166 if(!e)
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
167 return;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
168 g_free(oauth_req->a_key);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
169 oauth_req->a_key = g_strndup(f+12, e-f-12);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
170
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
171 f = strstr(e+1, "oauth_token_secret=");
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
172 if(!f)
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
173 return;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
174 e = strstr(f, "&");
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
175 if(!e)
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
176 return;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
177 g_free(oauth_req->a_sec);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
178 oauth_req->a_sec = g_strndup(f+19, e-f-19);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
179
357
732de90812d8 - fixed memory leaks
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 355
diff changeset
180 /* redirect to twitter's authorization url */
732de90812d8 - fixed memory leaks
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 355
diff changeset
181 char *uri = g_strdup_printf("%s?oauth_token=%s", AUTHORIZE_URL, oauth_req->a_key);
355
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
182 twitter_debug("auth uri=%s\n", uri);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
183 purple_notify_uri(conn, uri);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
184
357
732de90812d8 - fixed memory leaks
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 355
diff changeset
185 /* show dialog to wait PIN */
355
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
186 purple_request_input(conn,
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
187 "PIN",
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
188 "Enter PIN",
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
189 "Press allow button in the browser, then enter the PIN to complete process.",
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
190 "",
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
191 FALSE,
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
192 FALSE,
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
193 NULL,
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
194 "OK", G_CALLBACK(pin_dialog_ok_cb),
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
195 "Cancel", NULL,
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
196 account,
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
197 NULL,
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
198 NULL,
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
199 user_data);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
200
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
201 g_free(uri);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
202 }
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
203
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
204 void
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
205 oauth_setup(gpointer data)
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
206 {
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
207 char *oauth = NULL;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
208 char *request = NULL;
357
732de90812d8 - fixed memory leaks
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 355
diff changeset
209 oauth_request_t *oauth_req = g_new0(oauth_request_t, 1); /* persistent */
732de90812d8 - fixed memory leaks
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 355
diff changeset
210
355
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
211 /*
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
212 http://twitter.com/oauth/request_token?
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
213 oauth_consumer_key=wrD3WGIh2P31d3fIjRkfcw&
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
214 oauth_nonce=HCUxu1D3qN4Nklr9QVAymve40PtJyU&
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
215 oauth_signature_method=HMAC-SHA1&
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
216 oauth_timestamp=1282446611&oauth_version=1.0&
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
217 oauth_signature=A%2BZIiUVsQv5ZR8u%2F2oLmUFX1eHE%3D
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
218 */
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
219
357
732de90812d8 - fixed memory leaks
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 355
diff changeset
220 oauth_req->url = strdup(REQUEST_TOKEN_URL);
355
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
221 oauth_req->c_key = strdup(c_key);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
222 oauth_req->c_sec = strdup(c_sec);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
223 oauth_req->a_key = NULL;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
224 oauth_req->a_sec = NULL;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
225 oauth_req->type = TYPE_GET;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
226 oauth_req->notoken = TRUE;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
227 oauth_req->conv = (PurpleConversation *)data;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
228
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
229 /* request token*/
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
230 oauth = make_oauth_get(oauth_req);
357
732de90812d8 - fixed memory leaks
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 355
diff changeset
231 request = g_strdup_printf("%s?%s", REQUEST_TOKEN_URL, oauth);
355
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
232
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
233 twitter_debug("request=%s\n", request);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
234
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
235 purple_util_fetch_url_request(request, TRUE,
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
236 NULL, TRUE, NULL, TRUE,
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
237 oauth_setup_cb, oauth_req);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
238 }
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
239
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
240
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
241 char *
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
242 hmac_sha1(char *text, char *key) {
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
243 PurpleCipherContext *context = NULL;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
244 size_t len;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
245 guchar digest[255];
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
246 char *signature = NULL;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
247
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
248 twitter_debug("text=%s\n", text);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
249 twitter_debug("key=%s\n", key);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
250
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
251 context = purple_cipher_context_new_by_name("hmac", NULL);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
252 if(!context)
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
253 return NULL;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
254
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
255 purple_cipher_context_set_option(context, "hash", "sha1");
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
256 purple_cipher_context_set_key(context, (guchar *)key);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
257 purple_cipher_context_append(context, (guchar *)text, strlen(text));
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
258
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
259 if(purple_cipher_context_digest(context, sizeof(digest), digest, &len)) {
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
260 signature = purple_base64_encode(digest, len);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
261 twitter_debug("hmac1 signature=%s\n", signature);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
262 }
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
263 else {
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
264 twitter_debug("digest signature failed\n");
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
265 }
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
266
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
267 purple_cipher_context_destroy(context);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
268
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
269 return signature;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
270 }
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
271
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
272 char *
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
273 make_oauth_get(oauth_request_t *req)
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
274 {
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
275 gchar *tmp = NULL;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
276 char *signature = NULL;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
277 time_t current_time = time(NULL);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
278 char *params = NULL;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
279 char *oauth;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
280 char *count_str = NULL;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
281 char *token_str = NULL;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
282 char *verifier_str = NULL;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
283
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
284 if(req->count)
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
285 count_str = g_strdup_printf("count=%d&", req->count);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
286 else
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
287 count_str = g_strdup("");
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
288
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
289 if(req->notoken) {
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
290 twitter_debug("notoken\n");
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
291 token_str = g_strdup("");
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
292 }
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
293 else
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
294 token_str = g_strdup_printf("oauth_token=%s&", req->a_key?req->a_key:req->c_key);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
295
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
296 if(req->verifier)
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
297 verifier_str = g_strdup_printf("oauth_verifier=%s&", req->verifier);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
298 else
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
299 verifier_str = g_strdup("");
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
300
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
301 params = g_strdup_printf("%soauth_consumer_key=%s&oauth_nonce=%s&oauth_signature_method=HMAC-SHA1&oauth_timestamp=%d&%s%soauth_version=1.0",
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
302 count_str,
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
303 req->c_key,
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
304 SAMPLE_NONCE,
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
305 (int)current_time,
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
306 token_str,
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
307 verifier_str);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
308
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
309 g_free(count_str);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
310 g_free(token_str);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
311 g_free(verifier_str);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
312
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
313 const char *url_encoded = g_uri_escape_string(req->url, "", FALSE);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
314 const char *params_encoded = g_uri_escape_string(params, "", FALSE);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
315
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
316 tmp = g_strdup_printf("GET&%s&%s", url_encoded, params_encoded);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
317 char *key = g_strdup_printf("%s&%s", req->c_sec, req->a_sec?req->a_sec:"");
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
318 signature = hmac_sha1(tmp, key);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
319 g_free(key);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
320
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
321 const char *signature_encoded = g_uri_escape_string(signature, "", FALSE);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
322
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
323 oauth = g_strdup_printf("%s&oauth_signature=%s", params, signature_encoded);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
324
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
325 g_free(tmp);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
326 g_free(signature);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
327 g_free(params);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
328
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
329 twitter_debug("oauth_block=%s\n", oauth);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
330 return oauth;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
331 }
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
332
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
333 char *
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
334 make_oauth_post(oauth_request_t *req)
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
335 {
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
336 gchar *tmp = NULL;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
337 char *signature = NULL;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
338 time_t current_time = time(NULL);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
339 char *params = NULL;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
340 char *oauth;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
341 char *status_str = NULL;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
342 char *msgid_str = NULL;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
343
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
344 if(req->status)
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
345 status_str = g_strdup_printf("&status=%s", req->status);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
346 else
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
347 status_str = g_strdup("");
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
348
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
349 if(req->msgid)
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
350 msgid_str = g_strdup_printf("in_reply_to_status_id=%llu&",
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
351 (long long unsigned int)req->msgid);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
352 else
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
353 msgid_str = g_strdup("");
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
354
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
355 params = g_strdup_printf("%soauth_consumer_key=%s&oauth_nonce=%s&oauth_signature_method=HMAC-SHA1&oauth_timestamp=%d&oauth_token=%s&oauth_version=1.0%s",
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
356 msgid_str,
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
357 req->c_key,
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
358 SAMPLE_NONCE,
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
359 (int)current_time,
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
360 req->a_key,
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
361 status_str);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
362
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
363 g_free(status_str);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
364 g_free(msgid_str);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
365
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
366 const char *url_encoded = g_uri_escape_string(req->url, "", FALSE);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
367 const char *params_encoded = g_uri_escape_string(params, "", FALSE);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
368
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
369 tmp = g_strdup_printf("POST&%s&%s", url_encoded, params_encoded);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
370 char *key = g_strdup_printf("%s&%s", req->c_sec, req->a_sec);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
371 signature = hmac_sha1(tmp, key);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
372 g_free(key);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
373
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
374 const char *signature_encoded = g_uri_escape_string(signature, "", FALSE);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
375
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
376 oauth = g_strdup_printf("%s&oauth_signature=%s", params, signature_encoded);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
377
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
378 g_free(tmp);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
379 g_free(signature);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
380 g_free(params);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
381
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
382 twitter_debug("oauth_block=%s\n", oauth);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
383 return oauth;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
384 }
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
385
254
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
386 /**************************/
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
387 /* API base get functions */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
388 /**************************/
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
389 /* xml parser */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
390 static void
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
391 parse_user(xmlNode *user, status_t *st)
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
392 {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
393 xmlNode *nptr;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
394
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
395 for(nptr = user->children; nptr != NULL; nptr = nptr->next) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
396 if(nptr->type == XML_ELEMENT_NODE) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
397 if(!xmlStrcmp(nptr->name, (xmlChar *)"screen_name")) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
398 gchar *str = (gchar *)xmlNodeGetContent(nptr);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
399 st->screen_name = g_strdup(str);
305
227e59f017f2 status id now exceeds int32 limit.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 304
diff changeset
400 twitter_debug("screen_name=%s\n", st->screen_name);
254
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
401 xmlFree(str);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
402 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
403 else if(!xmlStrcmp(nptr->name, (xmlChar *)"profile_image_url")) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
404 gchar *str = (gchar *)xmlNodeGetContent(nptr);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
405 st->profile_image_url = g_strdup(str);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
406 xmlFree(str);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
407 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
408 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
409 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
410 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
411
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
412 static gchar *day_of_week_name[] = {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
413 "Sun",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
414 "Mon",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
415 "Tue",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
416 "Wed",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
417 "Thu",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
418 "Fri",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
419 "Sat",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
420 NULL
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
421 };
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
422
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
423 static gchar *month_name[] = {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
424 "Jan",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
425 "Feb",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
426 "Mar",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
427 "Apr",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
428 "May",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
429 "Jun",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
430 "Jul",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
431 "Aug",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
432 "Sep",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
433 "Oct",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
434 "Nov",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
435 "Dec",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
436 NULL
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
437 };
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
438
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
439 static void
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
440 read_timestamp(const char *str, struct tm *res)
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
441 {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
442 char day_of_week[4];
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
443 char month[4];
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
444 char time_offset[6];
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
445 int day, hour, minute, second, year;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
446 int i;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
447
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
448 if(str == NULL || res == NULL)
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
449 return;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
450
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
451 sscanf(str, "%s %s %d %d:%d:%d %s %d",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
452 day_of_week, month, &day,
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
453 &hour, &minute, &second,
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
454 time_offset, &year);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
455
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
456 for(i=0; i<7; i++) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
457 if(!strcmp(day_of_week_name[i], day_of_week)) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
458 res->tm_wday = i;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
459 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
460 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
461 for(i=0; i<12; i++) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
462 if(!strcmp(month_name[i], month)) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
463 res->tm_mon = i;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
464 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
465 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
466
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
467 res->tm_mday = day;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
468 res->tm_hour = hour;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
469 res->tm_min = minute;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
470 res->tm_sec = second;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
471 res->tm_year = year - 1900;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
472 #ifndef _WIN32
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
473 int offset = atoi(time_offset);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
474 res->tm_gmtoff = -1 * (60 * 60 * offset / 100);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
475 #endif
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
476
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
477 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
478
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
479 static void
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
480 parse_status(xmlNode *status, status_t *st)
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
481 {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
482 xmlNode *nptr;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
483
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
484 for(nptr = status->children; nptr != NULL; nptr = nptr->next) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
485 if(nptr->type == XML_ELEMENT_NODE) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
486 if(!xmlStrcmp(nptr->name, (xmlChar *)"created_at")) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
487 gchar *str = (gchar *)xmlNodeGetContent(nptr);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
488 st->created_at = g_strdup(str);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
489
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
490 /* read time stamp */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
491 struct tm res;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
492 memset(&res, 0x00, sizeof(struct tm));
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
493 read_timestamp(str, &res);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
494 tzset();
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
495 #ifdef _WIN32
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
496 st->time = mktime(&res) - timezone;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
497 #else
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
498 st->time = mktime(&res) + res.tm_gmtoff;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
499 #endif
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
500
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
501 xmlFree(str);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
502 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
503 else if(!xmlStrcmp(nptr->name, (xmlChar *)"id")) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
504 gchar *str = (gchar *)xmlNodeGetContent(nptr);
305
227e59f017f2 status id now exceeds int32 limit.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 304
diff changeset
505 st->id = atoll(str);
335
34ecd09ce4f8 properly set msgid to the posted message.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 333
diff changeset
506 twitter_debug("id=%llu\n", (long long unsigned int)st->id);
254
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
507 xmlFree(str);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
508 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
509 else if(!xmlStrcmp(nptr->name, (xmlChar *)"text")) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
510 gchar *str = (gchar *)xmlNodeGetContent(nptr);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
511 st->text = g_strdup(str);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
512 xmlFree(str);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
513 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
514 else if(!xmlStrcmp(nptr->name, (xmlChar *)"user")) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
515 parse_user(nptr, st);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
516 }
347
33d2551727ba embed "in reply to foo" link to each reply message
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 345
diff changeset
517 else if(!xmlStrcmp(nptr->name, (xmlChar *)"in_reply_to_status_id")) {
33d2551727ba embed "in reply to foo" link to each reply message
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 345
diff changeset
518 gchar *str = (gchar *)xmlNodeGetContent(nptr);
33d2551727ba embed "in reply to foo" link to each reply message
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 345
diff changeset
519 st->in_reply_to_status_id = atoll(str);
33d2551727ba embed "in reply to foo" link to each reply message
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 345
diff changeset
520 twitter_debug("in_reply_to_status_id=%llu\n", (long long unsigned int)st->in_reply_to_status_id);
33d2551727ba embed "in reply to foo" link to each reply message
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 345
diff changeset
521 xmlFree(str);
33d2551727ba embed "in reply to foo" link to each reply message
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 345
diff changeset
522 }
33d2551727ba embed "in reply to foo" link to each reply message
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 345
diff changeset
523 else if(!xmlStrcmp(nptr->name, (xmlChar *)"in_reply_to_screen_name")) {
33d2551727ba embed "in reply to foo" link to each reply message
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 345
diff changeset
524 gchar *str = (gchar *)xmlNodeGetContent(nptr);
33d2551727ba embed "in reply to foo" link to each reply message
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 345
diff changeset
525 st->in_reply_to_screen_name = g_strdup(str);
33d2551727ba embed "in reply to foo" link to each reply message
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 345
diff changeset
526 twitter_debug("in_reply_to_screen_name=%s\n", st->in_reply_to_screen_name);
33d2551727ba embed "in reply to foo" link to each reply message
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 345
diff changeset
527 xmlFree(str);
33d2551727ba embed "in reply to foo" link to each reply message
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 345
diff changeset
528 }
254
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
529 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
530 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
531 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
532
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
533 static void
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
534 free_status(status_t *st)
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
535 {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
536 g_free(st->created_at);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
537 g_free(st->text);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
538 g_free(st->screen_name);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
539 g_free(st->profile_image_url);
347
33d2551727ba embed "in reply to foo" link to each reply message
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 345
diff changeset
540 g_free(st->in_reply_to_screen_name);
254
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
541 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
542
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
543 static gboolean
305
227e59f017f2 status id now exceeds int32 limit.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 304
diff changeset
544 is_posted_message(status_t *status, guint64 lastid)
254
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
545 {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
546 GList *pp = g_list_first(postedlist);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
547 gboolean rv = FALSE;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
548
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
549 while(pp) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
550 GList *next;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
551 status_t *posted = (status_t *)pp->data;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
552
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
553 next = g_list_next(pp);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
554
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
555 if(posted->id == status->id) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
556 rv = TRUE;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
557 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
558
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
559 if(posted->id <= lastid) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
560 free_status(posted);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
561 g_free(pp->data);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
562 postedlist = g_list_delete_link(postedlist, pp);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
563 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
564
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
565 pp = next;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
566 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
567
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
568 return rv;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
569 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
570
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
571 static void
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
572 get_status_with_api_cb(PurpleUtilFetchUrlData *url_data, gpointer user_data,
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
573 const gchar *url_text, size_t len,
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
574 const gchar *error_message)
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
575
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
576 {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
577 xmlDocPtr doc;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
578 xmlNode *nptr, *nptr2;
305
227e59f017f2 status id now exceeds int32 limit.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 304
diff changeset
579 static guint64 lastid = 0;
254
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
580 PurpleConversation *conv;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
581 GList *stp;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
582 const gchar *start;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
583
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
584 g_return_if_fail(url_text != NULL);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
585
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
586 conv = (PurpleConversation *)user_data;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
587 if(!conv)
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
588 return;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
589
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
590 /* skip to the beginning of xml */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
591 start = strstr(url_text, "<?xml");
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
592
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
593 doc = xmlRecoverMemory(start, len - (start - url_text));
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
594 if(doc == NULL)
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
595 return;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
596
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
597 #ifdef _WIN32
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
598 /* suppress notification of incoming messages. */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
599 if(purple_prefs_get_bool(OPT_PREVENT_NOTIFICATION)) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
600 if(!blink_modified) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
601 blink_modified = TRUE;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
602 blink_state = purple_prefs_get_bool(OPT_PIDGIN_BLINK_IM);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
603 purple_prefs_set_bool(OPT_PIDGIN_BLINK_IM, FALSE);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
604 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
605 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
606 #endif
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
607
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
608 for(nptr = doc->children; nptr != NULL; nptr = nptr->next) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
609 if(nptr->type == XML_ELEMENT_NODE &&
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
610 !xmlStrcmp(nptr->name, (xmlChar *)"statuses")) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
611
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
612 for(nptr2 = nptr->children; nptr2 != NULL; nptr2 = nptr2->next) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
613 if(nptr2->type == XML_ELEMENT_NODE &&
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
614 !xmlStrcmp(nptr2->name, (xmlChar *)"status")) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
615 status_t *st = g_new0(status_t, 1);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
616 statuseslist = g_list_prepend(statuseslist, st);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
617 parse_status(nptr2, st);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
618 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
619 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
620 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
621 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
622
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
623 xmlFreeDoc(doc);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
624 xmlCleanupParser();
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
625
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
626 /* process statuseslist */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
627 stp = g_list_first(statuseslist);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
628 while(stp) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
629 GList *next;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
630 status_t *st = (status_t *)stp->data;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
631
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
632 next = g_list_next(stp);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
633
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
634 if(st->id > lastid && !is_posted_message(st, lastid)) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
635 gchar *msg = NULL;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
636 gchar *sender = NULL;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
637
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
638 sender = g_strdup("twitter@twitter.com");
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
639
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
640 PurpleMessageFlags flag = PURPLE_MESSAGE_RECV;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
641
347
33d2551727ba embed "in reply to foo" link to each reply message
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 345
diff changeset
642 msg = g_strdup_printf("%s: %s pttag=%llu:%llu:%s",
354
ff078879e68e include in_reply_to information to the internal tag even in posting message
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 347
diff changeset
643 st->screen_name,
ff078879e68e include in_reply_to information to the internal tag even in posting message
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 347
diff changeset
644 st->text,
347
33d2551727ba embed "in reply to foo" link to each reply message
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 345
diff changeset
645 (long long unsigned int)st->id,
33d2551727ba embed "in reply to foo" link to each reply message
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 345
diff changeset
646 (long long unsigned int)st->in_reply_to_status_id,
33d2551727ba embed "in reply to foo" link to each reply message
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 345
diff changeset
647 st->in_reply_to_screen_name ? st->in_reply_to_screen_name : "");
254
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
648
305
227e59f017f2 status id now exceeds int32 limit.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 304
diff changeset
649 /* apply filter */
254
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
650 if(purple_prefs_get_bool(OPT_FILTER)) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
651 apply_filter(&sender, &msg, &flag, twitter_service);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
652 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
653 if(sender && msg) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
654 purple_conv_im_write(conv->u.im,
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
655 sender,
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
656 msg,
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
657 flag,
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
658 st->time);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
659 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
660 lastid = st->id;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
661
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
662 g_free(sender);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
663 g_free(msg);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
664 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
665
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
666 free_status(st);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
667 g_free(stp->data);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
668 statuseslist = g_list_delete_link(statuseslist, stp);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
669
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
670 stp = next;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
671 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
672 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
673
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
674 /* status fetching function. it will be called periodically. */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
675 gboolean
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
676 get_status_with_api(gpointer data)
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
677 {
284
2d559555875f now message count can be specified in twitter API access.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 260
diff changeset
678 twitter_debug("called\n");
2d559555875f now message count can be specified in twitter API access.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 260
diff changeset
679
254
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
680 /* fetch friends time line */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
681 char *request, *header;
284
2d559555875f now message count can be specified in twitter API access.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 260
diff changeset
682 gint count = purple_prefs_get_int(OPT_RETRIEVE_COUNT);
355
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
683 char *oauth;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
684 const char *a_key = NULL;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
685 const char *a_sec = NULL;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
686 static gboolean setup = FALSE;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
687 oauth_request_t oauth_req;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
688
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
689 a_key = purple_prefs_get_string(OPT_AKEY_TWITTER);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
690 a_sec = purple_prefs_get_string(OPT_ASEC_TWITTER);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
691
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
692 if(!a_key || !a_sec) {
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
693 if(!setup) {
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
694 oauth_setup(data);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
695 setup = TRUE;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
696 }
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
697 return TRUE;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
698 }
254
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
699
284
2d559555875f now message count can be specified in twitter API access.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 260
diff changeset
700 if(count < TWITTER_DEFAULT_RETRIEVE_COUNT)
2d559555875f now message count can be specified in twitter API access.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 260
diff changeset
701 count = TWITTER_DEFAULT_RETRIEVE_COUNT;
254
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
702
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
703 /* if disabled, just return */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
704 if(!purple_prefs_get_bool(OPT_API_BASE_POST))
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
705 return TRUE;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
706
355
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
707 /* oauth */
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
708 char *url0 = g_strdup_printf(TWITTER_API_BASE_URL "/1/statuses/home_timeline.xml");
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
709 oauth_req.url = url0;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
710 oauth_req.c_key = c_key;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
711 oauth_req.c_sec = c_sec;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
712 oauth_req.a_key = (char *)a_key;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
713 oauth_req.a_sec = (char *)a_sec;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
714 oauth_req.verifier = NULL;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
715 oauth_req.status = NULL;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
716 oauth_req.type = TYPE_GET;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
717 oauth_req.count = count;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
718 oauth_req.msgid = 0;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
719 oauth_req.notoken = FALSE;
254
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
720
355
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
721 oauth = make_oauth_get(&oauth_req);
357
732de90812d8 - fixed memory leaks
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 355
diff changeset
722 g_free(url0);
254
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
723
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
724 /* header */
355
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
725 header = g_strdup_printf(TWITTER_STATUS_GET, oauth);
254
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
726 request = g_strconcat(header, "\r\n", NULL);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
727
355
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
728 twitter_debug("request=%s\n", request);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
729
254
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
730 /* invoke fetch */
345
2e37e715e4a6 add preliminary support for quotetweet and official retweet.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 335
diff changeset
731 purple_util_fetch_url_request(TWITTER_API_BASE_URL, FALSE,
254
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
732 NULL, TRUE, request, TRUE,
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
733 get_status_with_api_cb, data);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
734
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
735 g_free(header);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
736 g_free(request);
355
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
737 g_free(oauth);
357
732de90812d8 - fixed memory leaks
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 355
diff changeset
738
254
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
739 return TRUE;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
740 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
741
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
742 /****************************/
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
743 /* API based post functions */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
744 /****************************/
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
745 static void
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
746 post_status_with_api_cb(PurpleUtilFetchUrlData *url_data, gpointer user_data,
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
747 const gchar *url_text, size_t len,
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
748 const gchar *error_message)
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
749 {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
750 twitter_message_t *tm = (twitter_message_t *)user_data;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
751 gchar *msg = NULL;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
752 char *p1 = NULL, *p2 = NULL;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
753 int error = 1;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
754 PurpleConversation *conv;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
755
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
756 conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_ANY,
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
757 "twitter@twitter.com",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
758 tm->account);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
759 if (!conv) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
760 twitter_debug("failed to get conversation\n");
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
761 goto fin;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
762 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
763
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
764 if (error_message) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
765 /* connection failed or something */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
766 msg = g_strdup_printf("Local error: %s", error_message);
335
34ecd09ce4f8 properly set msgid to the posted message.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 333
diff changeset
767 }
34ecd09ce4f8 properly set msgid to the posted message.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 333
diff changeset
768 else {
254
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
769 int code = -1;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
770
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
771 if ((strncmp(url_text, "HTTP/1.0", strlen("HTTP/1.0")) == 0
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
772 || strncmp(url_text, "HTTP/1.1", strlen("HTTP/1.1")) == 0)) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
773
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
774 p1 = strchr(url_text, ' ');
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
775
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
776 if (p1) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
777 p1++;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
778 p2 = strchr(p1, ' ');
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
779 if (p2)
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
780 p2++;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
781 else
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
782 p2 = NULL;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
783 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
784 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
785
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
786 code = atoi(p1);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
787
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
788 if (code == 200) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
789 error = 0;
335
34ecd09ce4f8 properly set msgid to the posted message.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 333
diff changeset
790 }
34ecd09ce4f8 properly set msgid to the posted message.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 333
diff changeset
791 else {
254
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
792 switch (code) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
793 case 400:
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
794 msg = g_strdup("Invalid request. Too many updates?");
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
795 break;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
796 case 401:
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
797 msg = g_strdup("Authorization failed.");
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
798 break;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
799 case 403:
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
800 msg = g_strdup("Your update has been refused by Twitter server "
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
801 "for some reason.");
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
802 break;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
803 case 404:
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
804 msg = g_strdup("Requested URI is not found.");
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
805 break;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
806 case 500:
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
807 msg = g_strdup("Server error.");
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
808 break;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
809 case 502:
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
810 msg = g_strdup("Twitter is down or under maintenance.");
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
811 break;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
812 case 503:
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
813 msg = g_strdup("Twitter is extremely crowded. "
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
814 "Try again later.");
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
815 break;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
816 default:
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
817 msg = g_strdup_printf("Unknown error. (%d %s)",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
818 code, p2 ? p2 : "");
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
819 break;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
820 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
821 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
822 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
823
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
824 if (!error) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
825 /* cache message ID that posted via API */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
826 gchar *start = NULL;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
827 xmlDocPtr doc;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
828 xmlNode *nptr;
335
34ecd09ce4f8 properly set msgid to the posted message.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 333
diff changeset
829 status_t *st;
34ecd09ce4f8 properly set msgid to the posted message.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 333
diff changeset
830 gchar *m;
254
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
831
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
832 start = strstr(url_text, "<?xml");
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
833
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
834 if(!start)
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
835 goto fin;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
836
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
837 doc = xmlRecoverMemory(start, len - (start - url_text));
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
838 if(doc == NULL)
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
839 return;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
840
335
34ecd09ce4f8 properly set msgid to the posted message.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 333
diff changeset
841
254
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
842 /* enqueue posted message to postedlist */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
843 for(nptr = doc->children; nptr != NULL; nptr = nptr->next) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
844 if(nptr->type == XML_ELEMENT_NODE &&
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
845 !xmlStrcmp(nptr->name, (xmlChar *)"status")) {
335
34ecd09ce4f8 properly set msgid to the posted message.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 333
diff changeset
846 st = g_new0(status_t, 1);
254
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
847 postedlist = g_list_prepend(postedlist, st);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
848 parse_status(nptr, st);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
849 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
850 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
851
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
852 xmlFreeDoc(doc);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
853 xmlCleanupParser();
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
854
354
ff078879e68e include in_reply_to information to the internal tag even in posting message
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 347
diff changeset
855 m = g_strdup_printf("%s pttag=%llu:%llu:%s",
335
34ecd09ce4f8 properly set msgid to the posted message.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 333
diff changeset
856 tm->status,
354
ff078879e68e include in_reply_to information to the internal tag even in posting message
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 347
diff changeset
857 (long long unsigned int)st->id,
ff078879e68e include in_reply_to information to the internal tag even in posting message
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 347
diff changeset
858 (long long unsigned int)st->in_reply_to_status_id,
ff078879e68e include in_reply_to information to the internal tag even in posting message
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 347
diff changeset
859 st->in_reply_to_screen_name ? st->in_reply_to_screen_name : "");
335
34ecd09ce4f8 properly set msgid to the posted message.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 333
diff changeset
860
34ecd09ce4f8 properly set msgid to the posted message.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 333
diff changeset
861 purple_conv_im_write(conv->u.im,
34ecd09ce4f8 properly set msgid to the posted message.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 333
diff changeset
862 purple_account_get_username(tm->account),
34ecd09ce4f8 properly set msgid to the posted message.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 333
diff changeset
863 m,
34ecd09ce4f8 properly set msgid to the posted message.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 333
diff changeset
864 PURPLE_MESSAGE_SEND,
34ecd09ce4f8 properly set msgid to the posted message.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 333
diff changeset
865 tm->time);
34ecd09ce4f8 properly set msgid to the posted message.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 333
diff changeset
866 g_free(m);
34ecd09ce4f8 properly set msgid to the posted message.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 333
diff changeset
867
34ecd09ce4f8 properly set msgid to the posted message.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 333
diff changeset
868 }
34ecd09ce4f8 properly set msgid to the posted message.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 333
diff changeset
869 else {
254
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
870 gchar *m;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
871 m = g_strdup_printf("%s<BR>%s",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
872 msg, tm->status);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
873 /* FIXME: too strong. it should be more smart */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
874 purple_conv_im_write(conv->u.im,
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
875 purple_account_get_username(tm->account),
335
34ecd09ce4f8 properly set msgid to the posted message.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 333
diff changeset
876 m,
34ecd09ce4f8 properly set msgid to the posted message.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 333
diff changeset
877 PURPLE_MESSAGE_ERROR,
34ecd09ce4f8 properly set msgid to the posted message.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 333
diff changeset
878 time(NULL));
254
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
879 g_free(m);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
880 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
881
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
882 fin:
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
883 if (msg)
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
884 g_free(msg);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
885
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
886 if (tm) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
887 if (tm->status)
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
888 g_free(tm->status);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
889 g_free(tm);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
890 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
891
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
892 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
893
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
894 void
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
895 post_status_with_api(PurpleAccount *account, char **buffer)
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
896 {
355
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
897 char *request, *header;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
898 const char *url_encoded = g_uri_escape_string(*buffer, "", FALSE);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
899 char *oauth;
254
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
900 twitter_message_t *tm;
355
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
901 const char *a_key = NULL;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
902 const char *a_sec = NULL;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
903 oauth_request_t oauth_req;
254
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
904
355
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
905 a_key = purple_prefs_get_string(OPT_AKEY_TWITTER);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
906 a_sec = purple_prefs_get_string(OPT_ASEC_TWITTER);
254
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
907
355
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
908 if(!a_key || !a_sec) {
254
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
909 return;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
910 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
911
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
912 tm = g_new(twitter_message_t, 1);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
913 tm->account = account;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
914 tm->status = g_strdup(*buffer);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
915 tm->time = time(NULL);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
916
355
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
917 /* oauth */
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
918 char *url0 = g_strdup_printf(TWITTER_API_BASE_URL "/1/statuses/update.xml");
254
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
919
355
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
920 oauth_req.url = url0;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
921 oauth_req.c_key = c_key;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
922 oauth_req.c_sec = c_sec;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
923 oauth_req.a_key = (char *)purple_prefs_get_string(OPT_AKEY_TWITTER);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
924 oauth_req.a_sec = (char *)purple_prefs_get_string(OPT_ASEC_TWITTER);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
925 oauth_req.verifier = NULL;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
926 oauth_req.status = (char *)url_encoded;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
927 oauth_req.type = TYPE_POST;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
928 oauth_req.count = 0;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
929 oauth_req.msgid = reply_to_msgid;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
930 oauth_req.notoken = FALSE;
254
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
931
355
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
932 oauth = make_oauth_post(&oauth_req);
357
732de90812d8 - fixed memory leaks
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 355
diff changeset
933 g_free(url0);
355
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
934
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
935 reply_to_msgid = 0;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
936
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
937 header = g_strdup_printf(TWITTER_STATUS_POST,
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
938 (int)strlen(oauth));
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
939
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
940 request = g_strconcat(header, "\r\n", oauth, "\r\n", NULL);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
941 twitter_debug("request=%s\n", request);
254
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
942 purple_util_fetch_url_request(TWITTER_BASE_URL, FALSE,
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
943 NULL, TRUE, request, TRUE,
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
944 post_status_with_api_cb, tm);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
945
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
946 g_free(header);
355
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
947 g_free(oauth);
254
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
948 g_free(request);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
949
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
950 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
951
330
cc41ee1f5d3a implemented reply, favorite, retweet functionalities. these are quite raw, be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 315
diff changeset
952 static void
cc41ee1f5d3a implemented reply, favorite, retweet functionalities. these are quite raw, be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 315
diff changeset
953 fav_with_api_cb(PurpleUtilFetchUrlData *url_data, gpointer user_data,
cc41ee1f5d3a implemented reply, favorite, retweet functionalities. these are quite raw, be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 315
diff changeset
954 const gchar *url_text, size_t len,
cc41ee1f5d3a implemented reply, favorite, retweet functionalities. these are quite raw, be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 315
diff changeset
955 const gchar *error_message)
cc41ee1f5d3a implemented reply, favorite, retweet functionalities. these are quite raw, be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 315
diff changeset
956 {
cc41ee1f5d3a implemented reply, favorite, retweet functionalities. these are quite raw, be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 315
diff changeset
957 /* dummy */
cc41ee1f5d3a implemented reply, favorite, retweet functionalities. these are quite raw, be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 315
diff changeset
958 }
cc41ee1f5d3a implemented reply, favorite, retweet functionalities. these are quite raw, be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 315
diff changeset
959
cc41ee1f5d3a implemented reply, favorite, retweet functionalities. these are quite raw, be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 315
diff changeset
960 void
cc41ee1f5d3a implemented reply, favorite, retweet functionalities. these are quite raw, be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 315
diff changeset
961 fav_with_api(guint64 id)
cc41ee1f5d3a implemented reply, favorite, retweet functionalities. these are quite raw, be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 315
diff changeset
962 {
cc41ee1f5d3a implemented reply, favorite, retweet functionalities. these are quite raw, be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 315
diff changeset
963 char *header, *request;
355
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
964 char *oauth;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
965 const char *a_key = NULL;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
966 const char *a_sec = NULL;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
967 oauth_request_t oauth_req;
330
cc41ee1f5d3a implemented reply, favorite, retweet functionalities. these are quite raw, be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 315
diff changeset
968
355
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
969 a_key = purple_prefs_get_string(OPT_AKEY_TWITTER);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
970 a_sec = purple_prefs_get_string(OPT_ASEC_TWITTER);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
971
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
972 if(!a_key || !a_sec) {
332
227852ee649c do not append "in_reply_to_status_id" when msdid is 0.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 330
diff changeset
973 return;
227852ee649c do not append "in_reply_to_status_id" when msdid is 0.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 330
diff changeset
974 }
227852ee649c do not append "in_reply_to_status_id" when msdid is 0.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 330
diff changeset
975
355
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
976 /* oauth */
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
977 char *url0 = g_strdup_printf(TWITTER_API_BASE_URL "/1/favorites/create/%llu.xml", (long long unsigned int)id);
330
cc41ee1f5d3a implemented reply, favorite, retweet functionalities. these are quite raw, be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 315
diff changeset
978
355
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
979 oauth_req.url = url0;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
980 oauth_req.c_key = c_key;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
981 oauth_req.c_sec = c_sec;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
982 oauth_req.a_key = (char *)a_key;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
983 oauth_req.a_sec = (char *)a_sec;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
984 oauth_req.verifier = NULL;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
985 oauth_req.status = NULL;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
986 oauth_req.type = TYPE_POST;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
987 oauth_req.count = 0;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
988 oauth_req.msgid = 0;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
989 oauth_req.notoken = FALSE;
330
cc41ee1f5d3a implemented reply, favorite, retweet functionalities. these are quite raw, be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 315
diff changeset
990
355
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
991 oauth = make_oauth_post(&oauth_req);
357
732de90812d8 - fixed memory leaks
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 355
diff changeset
992 g_free(url0);
330
cc41ee1f5d3a implemented reply, favorite, retweet functionalities. these are quite raw, be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 315
diff changeset
993
cc41ee1f5d3a implemented reply, favorite, retweet functionalities. these are quite raw, be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 315
diff changeset
994 header = g_strdup_printf(TWITTER_FAV_POST,
cc41ee1f5d3a implemented reply, favorite, retweet functionalities. these are quite raw, be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 315
diff changeset
995 (long long unsigned int)id,
355
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
996 (int)strlen(oauth));
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
997
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
998 request = g_strconcat(header, "\r\n", oauth, NULL);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
999 twitter_debug("request=%s\n", request);
330
cc41ee1f5d3a implemented reply, favorite, retweet functionalities. these are quite raw, be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 315
diff changeset
1000
cc41ee1f5d3a implemented reply, favorite, retweet functionalities. these are quite raw, be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 315
diff changeset
1001 purple_util_fetch_url_request(TWITTER_BASE_URL, FALSE,
cc41ee1f5d3a implemented reply, favorite, retweet functionalities. these are quite raw, be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 315
diff changeset
1002 NULL, TRUE, request, TRUE,
cc41ee1f5d3a implemented reply, favorite, retweet functionalities. these are quite raw, be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 315
diff changeset
1003 fav_with_api_cb, NULL);
cc41ee1f5d3a implemented reply, favorite, retweet functionalities. these are quite raw, be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 315
diff changeset
1004
cc41ee1f5d3a implemented reply, favorite, retweet functionalities. these are quite raw, be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 315
diff changeset
1005 g_free(header);
355
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
1006 g_free(oauth);
330
cc41ee1f5d3a implemented reply, favorite, retweet functionalities. these are quite raw, be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 315
diff changeset
1007 g_free(request);
cc41ee1f5d3a implemented reply, favorite, retweet functionalities. these are quite raw, be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 315
diff changeset
1008 }
cc41ee1f5d3a implemented reply, favorite, retweet functionalities. these are quite raw, be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 315
diff changeset
1009
345
2e37e715e4a6 add preliminary support for quotetweet and official retweet.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 335
diff changeset
1010 static void
2e37e715e4a6 add preliminary support for quotetweet and official retweet.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 335
diff changeset
1011 retweet_with_api_cb(PurpleUtilFetchUrlData *url_data, gpointer user_data,
2e37e715e4a6 add preliminary support for quotetweet and official retweet.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 335
diff changeset
1012 const gchar *url_text, size_t len,
2e37e715e4a6 add preliminary support for quotetweet and official retweet.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 335
diff changeset
1013 const gchar *error_message)
2e37e715e4a6 add preliminary support for quotetweet and official retweet.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 335
diff changeset
1014 {
2e37e715e4a6 add preliminary support for quotetweet and official retweet.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 335
diff changeset
1015 /* dummy */
2e37e715e4a6 add preliminary support for quotetweet and official retweet.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 335
diff changeset
1016 }
2e37e715e4a6 add preliminary support for quotetweet and official retweet.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 335
diff changeset
1017
2e37e715e4a6 add preliminary support for quotetweet and official retweet.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 335
diff changeset
1018 void
2e37e715e4a6 add preliminary support for quotetweet and official retweet.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 335
diff changeset
1019 retweet_with_api(guint64 id)
2e37e715e4a6 add preliminary support for quotetweet and official retweet.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 335
diff changeset
1020 {
2e37e715e4a6 add preliminary support for quotetweet and official retweet.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 335
diff changeset
1021 char *header, *request;
355
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
1022 char *oauth;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
1023 const char *a_key = NULL;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
1024 const char *a_sec = NULL;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
1025 oauth_request_t oauth_req;
345
2e37e715e4a6 add preliminary support for quotetweet and official retweet.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 335
diff changeset
1026
355
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
1027 a_key = purple_prefs_get_string(OPT_AKEY_TWITTER);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
1028 a_sec = purple_prefs_get_string(OPT_ASEC_TWITTER);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
1029
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
1030 if(!a_key || !a_sec) {
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
1031 return;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
1032 }
345
2e37e715e4a6 add preliminary support for quotetweet and official retweet.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 335
diff changeset
1033
2e37e715e4a6 add preliminary support for quotetweet and official retweet.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 335
diff changeset
1034 if(id == 0) {
2e37e715e4a6 add preliminary support for quotetweet and official retweet.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 335
diff changeset
1035 twitter_debug("invalid message id\n");
2e37e715e4a6 add preliminary support for quotetweet and official retweet.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 335
diff changeset
1036 return;
2e37e715e4a6 add preliminary support for quotetweet and official retweet.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 335
diff changeset
1037 }
2e37e715e4a6 add preliminary support for quotetweet and official retweet.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 335
diff changeset
1038
355
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
1039 /* oauth */
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
1040 char *url0 = g_strdup_printf(TWITTER_API_BASE_URL "/1/statuses/retweet%llu.xml", (long long unsigned int)id);
345
2e37e715e4a6 add preliminary support for quotetweet and official retweet.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 335
diff changeset
1041
355
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
1042 oauth_req.url = url0;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
1043 oauth_req.c_key = c_key;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
1044 oauth_req.c_sec = c_sec;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
1045 oauth_req.a_key = (char *)a_key;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
1046 oauth_req.a_sec = (char *)a_sec;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
1047 oauth_req.verifier = NULL;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
1048 oauth_req.status = NULL;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
1049 oauth_req.type = TYPE_POST;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
1050 oauth_req.count = 0;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
1051 oauth_req.msgid = 0;
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
1052 oauth_req.notoken = FALSE;
345
2e37e715e4a6 add preliminary support for quotetweet and official retweet.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 335
diff changeset
1053
355
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
1054 oauth = make_oauth_post(&oauth_req);
357
732de90812d8 - fixed memory leaks
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 355
diff changeset
1055 g_free(url0);
345
2e37e715e4a6 add preliminary support for quotetweet and official retweet.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 335
diff changeset
1056
2e37e715e4a6 add preliminary support for quotetweet and official retweet.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 335
diff changeset
1057 header = g_strdup_printf(TWITTER_RETWEET_POST,
2e37e715e4a6 add preliminary support for quotetweet and official retweet.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 335
diff changeset
1058 (long long unsigned int)id,
355
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
1059 (int)strlen(oauth));
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
1060
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
1061 request = g_strconcat(header, "\r\n", oauth, NULL);
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
1062 twitter_debug("request=%s\n", request);
345
2e37e715e4a6 add preliminary support for quotetweet and official retweet.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 335
diff changeset
1063
2e37e715e4a6 add preliminary support for quotetweet and official retweet.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 335
diff changeset
1064 purple_util_fetch_url_request(TWITTER_API_BASE_URL, FALSE,
2e37e715e4a6 add preliminary support for quotetweet and official retweet.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 335
diff changeset
1065 NULL, TRUE, request, TRUE,
2e37e715e4a6 add preliminary support for quotetweet and official retweet.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 335
diff changeset
1066 retweet_with_api_cb, NULL);
2e37e715e4a6 add preliminary support for quotetweet and official retweet.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 335
diff changeset
1067
2e37e715e4a6 add preliminary support for quotetweet and official retweet.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 335
diff changeset
1068 g_free(header);
355
0fe895195132 implement OAuth authentication.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 354
diff changeset
1069 g_free(oauth);
345
2e37e715e4a6 add preliminary support for quotetweet and official retweet.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 335
diff changeset
1070 g_free(request);
2e37e715e4a6 add preliminary support for quotetweet and official retweet.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 335
diff changeset
1071 }
2e37e715e4a6 add preliminary support for quotetweet and official retweet.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 335
diff changeset
1072
254
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1073 void
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1074 signed_on_cb(PurpleConnection *gc)
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1075 {
287
4a7f4ba199cc - version bump to 0.8.3
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 284
diff changeset
1076 PurpleAccount *account;
4a7f4ba199cc - version bump to 0.8.3
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 284
diff changeset
1077 PurpleBuddy *buddy;
4a7f4ba199cc - version bump to 0.8.3
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 284
diff changeset
1078 PurpleConversation *gconv;
4a7f4ba199cc - version bump to 0.8.3
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 284
diff changeset
1079 const char name[] = "twitter@twitter.com";
254
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1080
287
4a7f4ba199cc - version bump to 0.8.3
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 284
diff changeset
1081 if(!purple_prefs_get_bool(OPT_API_BASE_POST)) {
304
6c8942296a47 tweak debug messages
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 290
diff changeset
1082 twitter_debug("per prefs\n");
254
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1083 return;
287
4a7f4ba199cc - version bump to 0.8.3
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 284
diff changeset
1084 }
254
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1085
287
4a7f4ba199cc - version bump to 0.8.3
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 284
diff changeset
1086 account = purple_connection_get_account(gc);
4a7f4ba199cc - version bump to 0.8.3
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 284
diff changeset
1087 if(!account) {
304
6c8942296a47 tweak debug messages
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 290
diff changeset
1088 twitter_debug("no account\n");
287
4a7f4ba199cc - version bump to 0.8.3
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 284
diff changeset
1089 return;
4a7f4ba199cc - version bump to 0.8.3
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 284
diff changeset
1090 }
254
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1091
287
4a7f4ba199cc - version bump to 0.8.3
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 284
diff changeset
1092 buddy = purple_find_buddy(account, name);
4a7f4ba199cc - version bump to 0.8.3
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 284
diff changeset
1093 if(!buddy) {
304
6c8942296a47 tweak debug messages
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 290
diff changeset
1094 twitter_debug("no buddy\n");
287
4a7f4ba199cc - version bump to 0.8.3
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 284
diff changeset
1095 return;
4a7f4ba199cc - version bump to 0.8.3
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 284
diff changeset
1096 }
4a7f4ba199cc - version bump to 0.8.3
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 284
diff changeset
1097
330
cc41ee1f5d3a implemented reply, favorite, retweet functionalities. these are quite raw, be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 315
diff changeset
1098 account_for_twitter = account;
cc41ee1f5d3a implemented reply, favorite, retweet functionalities. these are quite raw, be careful!
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 315
diff changeset
1099
287
4a7f4ba199cc - version bump to 0.8.3
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 284
diff changeset
1100 gconv = purple_find_conversation_with_account(
4a7f4ba199cc - version bump to 0.8.3
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 284
diff changeset
1101 PURPLE_CONV_TYPE_IM, name, account);
4a7f4ba199cc - version bump to 0.8.3
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 284
diff changeset
1102 if(!gconv) {
4a7f4ba199cc - version bump to 0.8.3
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 284
diff changeset
1103 gconv = purple_conversation_new(
4a7f4ba199cc - version bump to 0.8.3
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 284
diff changeset
1104 PURPLE_CONV_TYPE_IM, account, name);
304
6c8942296a47 tweak debug messages
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 290
diff changeset
1105 twitter_debug("new conv\n");
287
4a7f4ba199cc - version bump to 0.8.3
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 284
diff changeset
1106 }
254
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1107 }