Mercurial > pidgin-twitter
comparison pidgin-twitter.c @ 39:2ac81c0afb53
- new debug macro. it includes function name and line number.
- aggregate some debug messages.
author | Yoshiki Yazawa <yaz@cc.rim.or.jp> |
---|---|
date | Mon, 12 May 2008 22:22:19 +0900 |
parents | 625e385036c3 |
children | e60e6cbdc4c4 |
comparison
equal
deleted
inserted
replaced
38:625e385036c3 | 39:2ac81c0afb53 |
---|---|
56 #define RECIPIENT_FORMAT "@<a href='http://twitter.com/%s'>%s</a>" | 56 #define RECIPIENT_FORMAT "@<a href='http://twitter.com/%s'>%s</a>" |
57 #define SENDER_FORMAT "<a href='http://twitter.com/%s'>%s</a>: " | 57 #define SENDER_FORMAT "<a href='http://twitter.com/%s'>%s</a>: " |
58 #define DEFAULT_LIST "(list of users: separated with ' ,:;')" | 58 #define DEFAULT_LIST "(list of users: separated with ' ,:;')" |
59 #define OOPS_MESSAGE "<body>Oops! Your update was over 140 characters. We sent the short version to your friends (they can view the entire update on the web).<BR></body>" | 59 #define OOPS_MESSAGE "<body>Oops! Your update was over 140 characters. We sent the short version to your friends (they can view the entire update on the web).<BR></body>" |
60 | 60 |
61 #define twitter_debug(fmt, ...) purple_debug(PURPLE_DEBUG_INFO, PLUGIN_NAME, fmt, ## __VA_ARGS__); | 61 #define twitter_debug(fmt, ...) purple_debug(PURPLE_DEBUG_INFO, PLUGIN_NAME, "%s():%4d: " fmt, __FUNCTION__, (int)__LINE__, ## __VA_ARGS__); |
62 #define twitter_error(fmt, ...) purple_debug(PURPLE_DEBUG_ERROR, PLUGIN_NAME, fmt, ## __VA_ARGS__); | 62 #define twitter_error(fmt, ...) purple_debug(PURPLE_DEBUG_ERROR, PLUGIN_NAME, "%s():%4d: " fmt, __FUCTION__, (int)__LINE__, ## __VA_ARGS__); |
63 | 63 |
64 /* globals */ | 64 /* globals */ |
65 static GRegex *regp[5]; | 65 static GRegex *regp[5]; |
66 static gboolean suppress_oops = FALSE; | 66 static gboolean suppress_oops = FALSE; |
67 | 67 |
77 gchar *newstr = NULL; | 77 gchar *newstr = NULL; |
78 | 78 |
79 /* replace senders with link */ | 79 /* replace senders with link */ |
80 newstr = | 80 newstr = |
81 g_regex_replace(regp[SENDER_WITH_LINK], *str, -1, 0, "@\\1", 0, NULL); | 81 g_regex_replace(regp[SENDER_WITH_LINK], *str, -1, 0, "@\\1", 0, NULL); |
82 twitter_debug("*str = %s\n", *str); | 82 |
83 twitter_debug("rnewstr = %s\n", newstr); | 83 twitter_debug("*str = %s newstr = %s\n", *str, newstr); |
84 | 84 |
85 g_free(*str); | 85 g_free(*str); |
86 *str = newstr; | 86 *str = newstr; |
87 } | 87 } |
88 | 88 |
123 | 123 |
124 /* if there is pseudo one, escape it */ | 124 /* if there is pseudo one, escape it */ |
125 if(flag) { | 125 if(flag) { |
126 /* put ". " to the beginning of buffer */ | 126 /* put ". " to the beginning of buffer */ |
127 newstr = g_strdup_printf(". %s", *str); | 127 newstr = g_strdup_printf(". %s", *str); |
128 twitter_debug("*str = %s\n", *str); | 128 twitter_debug("*str = %s newstr = %s\n", *str, newstr); |
129 twitter_debug("newstr = %s\n", newstr); | |
130 g_free(*str); | 129 g_free(*str); |
131 *str = newstr; | 130 *str = newstr; |
132 } | 131 } |
133 } | 132 } |
134 | 133 |
138 { | 137 { |
139 const gchar *proto; | 138 const gchar *proto; |
140 | 139 |
141 /* check if the message is from twitter */ | 140 /* check if the message is from twitter */ |
142 proto = purple_account_get_protocol_id(account); | 141 proto = purple_account_get_protocol_id(account); |
143 twitter_debug("sending_im_cb\n"); | 142 twitter_debug("proto = %s recipient = %s\n", |
144 twitter_debug("proto = %s\n", proto); | 143 proto, recipient); |
145 twitter_debug("recipient = %s\n", recipient); | |
146 | 144 |
147 if(!strcmp(proto, "prpl-jabber") && | 145 if(!strcmp(proto, "prpl-jabber") && |
148 !strcmp(recipient, "twitter@twitter.com")) { | 146 !strcmp(recipient, "twitter@twitter.com")) { |
149 /* escape */ | 147 /* escape */ |
150 if(purple_prefs_get_bool(OPT_ESCAPE_PSEUDO)) { | 148 if(purple_prefs_get_bool(OPT_ESCAPE_PSEUDO)) { |
169 gchar sub[128]; | 167 gchar sub[128]; |
170 gchar *match = g_match_info_fetch(match_info, 1); | 168 gchar *match = g_match_info_fetch(match_info, 1); |
171 | 169 |
172 int which = *(int *)user_data; | 170 int which = *(int *)user_data; |
173 | 171 |
174 snprintf(sub, 128, which ? SENDER_FORMAT : RECIPIENT_FORMAT, match, match); | 172 snprintf(sub, 128, which ? SENDER_FORMAT : RECIPIENT_FORMAT, |
173 match, match); | |
175 twitter_debug("sub = %s\n", sub); | 174 twitter_debug("sub = %s\n", sub); |
176 g_string_append(result, sub); | 175 g_string_append(result, sub); |
177 g_free(match); | 176 g_free(match); |
178 | 177 |
179 return FALSE; | 178 return FALSE; |
181 | 180 |
182 static void | 181 static void |
183 translate(gchar **str, int which) | 182 translate(gchar **str, int which) |
184 { | 183 { |
185 gchar *newstr; | 184 gchar *newstr; |
186 | |
187 twitter_debug("*str = %s\n", *str); | |
188 | 185 |
189 newstr = g_regex_replace_eval(regp[which], // compiled regex | 186 newstr = g_regex_replace_eval(regp[which], // compiled regex |
190 *str, // subject string | 187 *str, // subject string |
191 -1, // length of the subject string | 188 -1, // length of the subject string |
192 0, // start position | 189 0, // start position |
193 0, // match options | 190 0, // match options |
194 eval, // function to be called for each match | 191 eval, // function to be called for each match |
195 &which, // user data | 192 &which, // user data |
196 NULL); // error handler | 193 NULL); // error handler |
197 | 194 |
198 twitter_debug("newstr = %s\n", newstr); | 195 twitter_debug("*str = %s newstr = %s\n", *str, newstr); |
199 | 196 |
200 g_free(*str); | 197 g_free(*str); |
201 *str = newstr; | 198 *str = newstr; |
202 } | 199 } |
203 | 200 |
247 { | 244 { |
248 const gchar *proto; | 245 const gchar *proto; |
249 | 246 |
250 /* check if the message is from twitter */ | 247 /* check if the message is from twitter */ |
251 proto = purple_account_get_protocol_id(account); | 248 proto = purple_account_get_protocol_id(account); |
252 twitter_debug("writing_im_cb\n"); | 249 twitter_debug("proto = %s sender = %s\n", proto, sender); |
253 twitter_debug("proto = %s\n", proto); | 250 |
254 twitter_debug("sender = %s\n", sender); | 251 if(!strcmp(sender, "twitter@twitter.com") && |
255 | 252 !strcmp(proto, "prpl-jabber")) { |
256 if(!strcmp(sender, "twitter@twitter.com") && !strcmp(proto, "prpl-jabber")) { | |
257 /* playsound */ | 253 /* playsound */ |
258 if(purple_prefs_get_bool(OPT_PLAYSOUND_SENDER)) { | 254 if(purple_prefs_get_bool(OPT_PLAYSOUND_SENDER)) { |
259 playsound(buffer, SENDER); | 255 playsound(buffer, SENDER); |
260 } | 256 } |
261 if(purple_prefs_get_bool(OPT_PLAYSOUND_RECIPIENT)) { | 257 if(purple_prefs_get_bool(OPT_PLAYSOUND_RECIPIENT)) { |
428 { | 424 { |
429 const char *name = purple_conversation_get_name(conv); | 425 const char *name = purple_conversation_get_name(conv); |
430 PurpleAccount *account = purple_conversation_get_account(conv); | 426 PurpleAccount *account = purple_conversation_get_account(conv); |
431 const gchar *proto = purple_account_get_protocol_id(account); | 427 const gchar *proto = purple_account_get_protocol_id(account); |
432 | 428 |
433 twitter_debug("is_twitter_conv\n"); | 429 twitter_debug("name = %s proto = %s\n", name, proto); |
434 twitter_debug("name = %s\n", name); | |
435 twitter_debug("proto = %s\n", proto); | |
436 | 430 |
437 if(!strcmp(name, "twitter@twitter.com") && !strcmp(proto, "prpl-jabber")) { | 431 if(!strcmp(name, "twitter@twitter.com") && !strcmp(proto, "prpl-jabber")) { |
438 return TRUE; | 432 return TRUE; |
439 } | 433 } |
440 | 434 |
458 | 452 |
459 static gboolean | 453 static gboolean |
460 receiving_im_cb(PurpleAccount *account, char **sender, char **buffer, | 454 receiving_im_cb(PurpleAccount *account, char **sender, char **buffer, |
461 PurpleConversation *conv, PurpleMessageFlags *flags, void *data) | 455 PurpleConversation *conv, PurpleMessageFlags *flags, void *data) |
462 { | 456 { |
463 twitter_debug("receiving_im_cb: buffer = %s\n", *buffer); | 457 twitter_debug("buffer = %s suppress_oops = %d\n", *buffer, suppress_oops); |
464 twitter_debug("receiving_im_cb: suppress_oops = %d\n", suppress_oops); | |
465 | 458 |
466 if(!suppress_oops || !purple_prefs_get_bool(OPT_SUPPRESS_OOPS)) | 459 if(!suppress_oops || !purple_prefs_get_bool(OPT_SUPPRESS_OOPS)) |
467 return FALSE; | 460 return FALSE; |
468 | 461 |
469 if(strstr(*buffer, OOPS_MESSAGE)) { | 462 if(strstr(*buffer, OOPS_MESSAGE)) { |
470 twitter_debug("receiving_im_cb: clearing sender and buffer\n"); | 463 twitter_debug("clearing sender and buffer\n"); |
471 g_free(*sender); | 464 g_free(*sender); |
472 *sender = NULL; | 465 *sender = NULL; |
473 g_free(*buffer); | 466 g_free(*buffer); |
474 *buffer = NULL; | 467 *buffer = NULL; |
475 suppress_oops = FALSE; | 468 suppress_oops = FALSE; |
516 } | 509 } |
517 | 510 |
518 static gboolean | 511 static gboolean |
519 unload_plugin(PurplePlugin *plugin) | 512 unload_plugin(PurplePlugin *plugin) |
520 { | 513 { |
521 twitter_debug("pidgin-twitter unload called\n"); | 514 twitter_debug("called\n"); |
522 | 515 |
523 /* disconnect from signal */ | 516 /* disconnect from signal */ |
524 purple_signal_disconnect(purple_conversations_get_handle(), | 517 purple_signal_disconnect(purple_conversations_get_handle(), |
525 "writing-im-msg", | 518 "writing-im-msg", |
526 plugin, PURPLE_CALLBACK(writing_im_cb)); | 519 plugin, PURPLE_CALLBACK(writing_im_cb)); |