annotate twitter_api.c @ 264:b7ac562d758c

- changed the pattern for twitter icons so that it may match to protected user's icon link too. - when pixbuf is null, pidgin-twitter will renew icon even if new and old URLs are same. - will fall back to default icon if pixbuf couldn't be made from retrieved data. - code cleanup.
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Thu, 04 Dec 2008 18:24:06 +0900
parents d973f9debe86
children 2d559555875f
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);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
12 static gboolean is_posted_message(status_t *status, guint lastid);
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
260
d973f9debe86 Fix Win32 compile error
Konosuke Watanabe <sasugaanija@gmail.com>
parents: 254
diff changeset
16 #ifdef _WIN32
d973f9debe86 Fix Win32 compile error
Konosuke Watanabe <sasugaanija@gmail.com>
parents: 254
diff changeset
17 extern gboolean blink_state;
d973f9debe86 Fix Win32 compile error
Konosuke Watanabe <sasugaanija@gmail.com>
parents: 254
diff changeset
18 extern gboolean blink_modified;
d973f9debe86 Fix Win32 compile error
Konosuke Watanabe <sasugaanija@gmail.com>
parents: 254
diff changeset
19 #endif
254
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
20
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
21 /**************************/
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
22 /* API base get functions */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
23 /**************************/
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
24 /* xml parser */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
25 static void
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
26 parse_user(xmlNode *user, status_t *st)
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
27 {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
28 xmlNode *nptr;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
29
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
30 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
31 if(nptr->type == XML_ELEMENT_NODE) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
32 if(!xmlStrcmp(nptr->name, (xmlChar *)"screen_name")) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
33 gchar *str = (gchar *)xmlNodeGetContent(nptr);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
34 st->screen_name = g_strdup(str);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
35 xmlFree(str);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
36 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
37 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
38 gchar *str = (gchar *)xmlNodeGetContent(nptr);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
39 st->profile_image_url = g_strdup(str);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
40 xmlFree(str);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
41 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
42 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
43 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
44 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
45
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
46 static gchar *day_of_week_name[] = {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
47 "Sun",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
48 "Mon",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
49 "Tue",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
50 "Wed",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
51 "Thu",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
52 "Fri",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
53 "Sat",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
54 NULL
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
55 };
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
56
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
57 static gchar *month_name[] = {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
58 "Jan",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
59 "Feb",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
60 "Mar",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
61 "Apr",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
62 "May",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
63 "Jun",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
64 "Jul",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
65 "Aug",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
66 "Sep",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
67 "Oct",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
68 "Nov",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
69 "Dec",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
70 NULL
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
71 };
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
72
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
73 static void
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
74 read_timestamp(const char *str, struct tm *res)
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
75 {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
76 char day_of_week[4];
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
77 char month[4];
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
78 char time_offset[6];
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
79 int day, hour, minute, second, year;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
80 int i;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
81
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
82 if(str == NULL || res == NULL)
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
83 return;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
84
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
85 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
86 day_of_week, month, &day,
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
87 &hour, &minute, &second,
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
88 time_offset, &year);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
89
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
90 for(i=0; i<7; i++) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
91 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
92 res->tm_wday = i;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
93 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
94 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
95 for(i=0; i<12; i++) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
96 if(!strcmp(month_name[i], month)) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
97 res->tm_mon = i;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
98 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
99 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
100
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
101 res->tm_mday = day;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
102 res->tm_hour = hour;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
103 res->tm_min = minute;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
104 res->tm_sec = second;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
105 res->tm_year = year - 1900;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
106 #ifndef _WIN32
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
107 int offset = atoi(time_offset);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
108 res->tm_gmtoff = -1 * (60 * 60 * offset / 100);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
109 #endif
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
110
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
111 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
112
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
113 static void
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
114 parse_status(xmlNode *status, status_t *st)
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
115 {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
116 xmlNode *nptr;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
117
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
118 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
119 if(nptr->type == XML_ELEMENT_NODE) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
120 if(!xmlStrcmp(nptr->name, (xmlChar *)"created_at")) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
121 gchar *str = (gchar *)xmlNodeGetContent(nptr);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
122 st->created_at = g_strdup(str);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
123
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
124 /* read time stamp */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
125 struct tm res;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
126 memset(&res, 0x00, sizeof(struct tm));
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
127 read_timestamp(str, &res);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
128 tzset();
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
129 #ifdef _WIN32
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
130 st->time = mktime(&res) - timezone;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
131 #else
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
132 st->time = mktime(&res) + res.tm_gmtoff;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
133 #endif
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
134
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
135 xmlFree(str);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
136 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
137 else if(!xmlStrcmp(nptr->name, (xmlChar *)"id")) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
138 gchar *str = (gchar *)xmlNodeGetContent(nptr);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
139 st->id = atoi(str);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
140 xmlFree(str);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
141 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
142 else if(!xmlStrcmp(nptr->name, (xmlChar *)"text")) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
143 gchar *str = (gchar *)xmlNodeGetContent(nptr);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
144 st->text = g_strdup(str);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
145 xmlFree(str);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
146 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
147 else if(!xmlStrcmp(nptr->name, (xmlChar *)"user")) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
148 parse_user(nptr, st);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
149 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
150 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
151 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
152 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
153
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
154 static void
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
155 free_status(status_t *st)
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
156 {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
157 g_free(st->created_at);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
158 g_free(st->text);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
159 g_free(st->screen_name);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
160 g_free(st->profile_image_url);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
161 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
162
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
163 static gboolean
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
164 is_posted_message(status_t *status, guint lastid)
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
165 {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
166 GList *pp = g_list_first(postedlist);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
167 gboolean rv = FALSE;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
168
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
169 while(pp) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
170 GList *next;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
171 status_t *posted = (status_t *)pp->data;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
172
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
173 next = g_list_next(pp);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
174
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
175 if(posted->id == status->id) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
176 rv = TRUE;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
177 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
178
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
179 if(posted->id <= lastid) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
180 free_status(posted);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
181 g_free(pp->data);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
182 postedlist = g_list_delete_link(postedlist, pp);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
183 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
184
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
185 pp = next;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
186 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
187
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
188 return rv;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
189 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
190
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
191 static void
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
192 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
193 const gchar *url_text, size_t len,
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
194 const gchar *error_message)
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
195
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
196 {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
197 xmlDocPtr doc;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
198 xmlNode *nptr, *nptr2;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
199 static guint lastid = 0;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
200 PurpleConversation *conv;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
201 GList *stp;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
202 const gchar *start;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
203
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
204 g_return_if_fail(url_text != NULL);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
205
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
206 conv = (PurpleConversation *)user_data;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
207 if(!conv)
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
208 return;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
209
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
210 /* skip to the beginning of xml */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
211 start = strstr(url_text, "<?xml");
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
212
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
213 doc = xmlRecoverMemory(start, len - (start - url_text));
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
214 if(doc == NULL)
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
215 return;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
216
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
217 #ifdef _WIN32
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
218 /* suppress notification of incoming messages. */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
219 if(purple_prefs_get_bool(OPT_PREVENT_NOTIFICATION)) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
220 if(!blink_modified) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
221 blink_modified = TRUE;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
222 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
223 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
224 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
225 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
226 #endif
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
227
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
228 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
229 if(nptr->type == XML_ELEMENT_NODE &&
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
230 !xmlStrcmp(nptr->name, (xmlChar *)"statuses")) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
231
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
232 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
233 if(nptr2->type == XML_ELEMENT_NODE &&
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
234 !xmlStrcmp(nptr2->name, (xmlChar *)"status")) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
235 status_t *st = g_new0(status_t, 1);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
236 statuseslist = g_list_prepend(statuseslist, st);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
237 parse_status(nptr2, st);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
238 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
239 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
240 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
241 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
242
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
243 xmlFreeDoc(doc);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
244 xmlCleanupParser();
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
245
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
246 /* process statuseslist */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
247 stp = g_list_first(statuseslist);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
248 while(stp) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
249 GList *next;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
250 status_t *st = (status_t *)stp->data;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
251
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
252 next = g_list_next(stp);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
253
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
254 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
255 gchar *msg = NULL;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
256 gchar *sender = NULL;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
257
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
258 sender = g_strdup("twitter@twitter.com");
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
259
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
260 PurpleMessageFlags flag = PURPLE_MESSAGE_RECV;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
261
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
262 msg = g_strdup_printf("%s: %s", st->screen_name, st->text);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
263
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
264 /* apply filter*/
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
265 if(purple_prefs_get_bool(OPT_FILTER)) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
266 apply_filter(&sender, &msg, &flag, twitter_service);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
267 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
268 if(sender && msg) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
269 purple_conv_im_write(conv->u.im,
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
270 sender,
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
271 msg,
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
272 flag,
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
273 st->time);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
274 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
275 lastid = st->id;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
276
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
277 g_free(sender);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
278 g_free(msg);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
279 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
280
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
281 free_status(st);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
282 g_free(stp->data);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
283 statuseslist = g_list_delete_link(statuseslist, stp);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
284
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
285 stp = next;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
286 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
287 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
288
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
289 /* status fetching function. it will be called periodically. */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
290 gboolean
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
291 get_status_with_api(gpointer data)
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
292 {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
293 /* fetch friends time line */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
294 char *request, *header;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
295 char *basic_auth, *basic_auth_encoded;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
296
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
297 twitter_debug("called\n");
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
298
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
299 /* if disabled, just return */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
300 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
301 return TRUE;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
302
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
303 const char *screen_name =
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
304 purple_prefs_get_string(OPT_SCREEN_NAME_TWITTER);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
305 const char *password =
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
306 purple_prefs_get_string(OPT_PASSWORD_TWITTER);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
307
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
308 if (!screen_name || !password || !screen_name[0] || !password[0]) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
309 twitter_debug("screen_name or password is empty\n");
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
310 return TRUE;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
311 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
312
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
313 /* auth */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
314 basic_auth = g_strdup_printf("%s:%s", screen_name, password);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
315 basic_auth_encoded = purple_base64_encode((unsigned char *)basic_auth,
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
316 strlen(basic_auth));
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
317 g_free(basic_auth);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
318
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
319 /* header */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
320 header = g_strdup_printf(TWITTER_STATUS_GET, basic_auth_encoded);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
321 request = g_strconcat(header, "\r\n", NULL);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
322
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
323 /* invoke fetch */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
324 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
325 NULL, TRUE, request, TRUE,
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
326 get_status_with_api_cb, data);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
327
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
328 g_free(header);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
329 g_free(basic_auth_encoded);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
330 g_free(request);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
331
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
332 return TRUE;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
333 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
334
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
335 /****************************/
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
336 /* API based post functions */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
337 /****************************/
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
338 static void
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
339 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
340 const gchar *url_text, size_t len,
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
341 const gchar *error_message)
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
342 {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
343 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
344 gchar *msg = NULL;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
345 char *p1 = NULL, *p2 = NULL;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
346 int error = 1;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
347 PurpleConversation *conv;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
348
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
349 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
350 "twitter@twitter.com",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
351 tm->account);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
352 if (!conv) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
353 twitter_debug("failed to get conversation\n");
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
354 goto fin;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
355 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
356
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
357 if (error_message) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
358 /* connection failed or something */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
359 msg = g_strdup_printf("Local error: %s", error_message);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
360 } else {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
361 int code = -1;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
362
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
363 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
364 || 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
365
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
366 p1 = strchr(url_text, ' ');
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
367
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
368 if (p1) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
369 p1++;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
370 p2 = strchr(p1, ' ');
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
371 if (p2)
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
372 p2++;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
373 else
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
374 p2 = NULL;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
375 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
376 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
377
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
378 code = atoi(p1);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
379
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
380 if (code == 200) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
381 error = 0;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
382 } else {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
383 switch (code) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
384 case 400:
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
385 msg = g_strdup("Invalid request. Too many updates?");
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
386 break;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
387 case 401:
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
388 msg = g_strdup("Authorization failed.");
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
389 break;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
390 case 403:
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
391 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
392 "for some reason.");
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
393 break;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
394 case 404:
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
395 msg = g_strdup("Requested URI is not found.");
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
396 break;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
397 case 500:
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
398 msg = g_strdup("Server error.");
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
399 break;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
400 case 502:
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
401 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
402 break;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
403 case 503:
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
404 msg = g_strdup("Twitter is extremely crowded. "
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
405 "Try again later.");
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
406 break;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
407 default:
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
408 msg = g_strdup_printf("Unknown error. (%d %s)",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
409 code, p2 ? p2 : "");
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
410 break;
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 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
413 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
414
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
415 if (!error) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
416 purple_conv_im_write(conv->u.im,
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
417 purple_account_get_username(tm->account),
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
418 tm->status, PURPLE_MESSAGE_SEND, tm->time);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
419
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
420 /* cache message ID that posted via API */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
421 gchar *start = NULL;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
422 xmlDocPtr doc;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
423 xmlNode *nptr;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
424
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
425 start = strstr(url_text, "<?xml");
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
426
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
427 if(!start)
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
428 goto fin;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
429
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
430 doc = xmlRecoverMemory(start, len - (start - url_text));
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
431 if(doc == NULL)
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
432 return;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
433
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
434 /* enqueue posted message to postedlist */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
435 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
436 if(nptr->type == XML_ELEMENT_NODE &&
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
437 !xmlStrcmp(nptr->name, (xmlChar *)"status")) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
438 status_t *st = g_new0(status_t, 1);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
439 postedlist = g_list_prepend(postedlist, st);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
440 parse_status(nptr, st);
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 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
443
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
444 xmlFreeDoc(doc);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
445 xmlCleanupParser();
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
446
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
447 } else {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
448 gchar *m;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
449 m = g_strdup_printf("%s<BR>%s",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
450 msg, tm->status);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
451 /* FIXME: too strong. it should be more smart */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
452 purple_conv_im_write(conv->u.im,
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
453 purple_account_get_username(tm->account),
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
454 m, PURPLE_MESSAGE_ERROR, time(NULL));
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
455 g_free(m);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
456 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
457
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
458 fin:
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
459 if (msg)
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
460 g_free(msg);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
461
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
462 if (tm) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
463 if (tm->status)
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
464 g_free(tm->status);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
465 g_free(tm);
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
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
468 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
469
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
470 void
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
471 post_status_with_api(PurpleAccount *account, char **buffer)
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
472 {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
473 char *request, *status, *header;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
474 const char *url_encoded = purple_url_encode(*buffer);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
475 char *basic_auth, *basic_auth_encoded;
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 twitter_message_t *tm;
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 const char *screen_name =
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
480 purple_prefs_get_string(OPT_SCREEN_NAME_TWITTER);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
481 const char *password = purple_prefs_get_string(OPT_PASSWORD_TWITTER);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
482
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
483 twitter_debug("tm.account: %s\n",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
484 purple_account_get_username(account));
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
485
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
486 if (!screen_name || !password || !screen_name[0] || !password[0]) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
487 twitter_debug("screen_name or password is empty\n");
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
488 return;
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
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
491 tm = g_new(twitter_message_t, 1);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
492 tm->account = account;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
493 tm->status = g_strdup(*buffer);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
494 tm->time = time(NULL);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
495
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
496 basic_auth = g_strdup_printf("%s:%s", screen_name, password);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
497 basic_auth_encoded = purple_base64_encode((unsigned char *)basic_auth,
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
498 strlen(basic_auth));
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
499 g_free(basic_auth);
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 status = g_strdup_printf(TWITTER_STATUS_FORMAT, url_encoded);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
502 header = g_strdup_printf(TWITTER_STATUS_POST, basic_auth_encoded,
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
503 (int)strlen(status));
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
504
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
505 request = g_strconcat(header, "\r\n", status, "\r\n", NULL);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
506
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
507 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
508 NULL, TRUE, request, TRUE,
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
509 post_status_with_api_cb, tm);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
510
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
511 g_free(header);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
512 g_free(basic_auth_encoded);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
513 g_free(status);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
514 g_free(request);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
515
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
516 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
517
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
518 void
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
519 signed_on_cb(PurpleConnection *gc)
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
520 {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
521 PurpleBuddyList *list = purple_get_blist();
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
522 PurpleBlistNode *gnode, *cnode, *bnode;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
523 PurpleBuddy *b;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
524
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
525 twitter_debug("called\n");
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
526
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
527 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
528 return;
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 if (!list)
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
531 return;
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 twitter_debug("scan list\n");
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
534
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
535 for (gnode = list->root; gnode; gnode = gnode->next) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
536 if(!PURPLE_BLIST_NODE_IS_GROUP(gnode))
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
537 continue;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
538
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
539 for(cnode = gnode->child; cnode; cnode = cnode->next) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
540
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
541 if(!PURPLE_BLIST_NODE_IS_CONTACT(cnode))
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
542 continue;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
543
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
544 for(bnode = cnode->child; bnode; bnode = bnode->next) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
545 if(!PURPLE_BLIST_NODE_IS_BUDDY(bnode))
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
546 continue;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
547
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
548 b = (PurpleBuddy *)bnode;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
549
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
550 if(!PURPLE_BUDDY_IS_ONLINE(b)) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
551 const char *name;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
552 PurpleAccount *account;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
553 name = purple_buddy_get_name(b);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
554 account = purple_buddy_get_account(b);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
555 if (is_twitter_account(account, name)) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
556 PurpleConversation *gconv;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
557 gconv = purple_find_conversation_with_account(
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
558 PURPLE_CONV_TYPE_IM, name, account);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
559 if (!gconv) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
560 gconv = purple_conversation_new(
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
561 PURPLE_CONV_TYPE_IM, account, name);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
562 }
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 }
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 }