Mercurial > pidgin-audacious
comparison pidgin-audacious.c @ 12:79f081cdfb19
- fixed potential memory leaks.
- fixed indentation.
author | Yoshiki Yazawa <yaz@cc.rim.or.jp> |
---|---|
date | Sat, 27 Sep 2008 00:50:45 +0900 |
parents | 43cb653de212 |
children | 44568f7ef51d |
comparison
equal
deleted
inserted
replaced
11:43cb653de212 | 12:79f081cdfb19 |
---|---|
1 /* | 1 /* -*- indent-tabs-mode:t; tab-width:8; -*- |
2 * | |
2 * Pidgin-Audacious plugin. | 3 * Pidgin-Audacious plugin. |
3 * | 4 * |
4 * This program is free software; you can redistribute it and/or | 5 * This program is free software; you can redistribute it and/or |
5 * modify it under the terms of the GNU General Public License as | 6 * modify it under the terms of the GNU General Public License as |
6 * published by the Free Software Foundation; either version 2 of the | 7 * published by the Free Software Foundation; either version 2 of the |
66 | 67 |
67 static PurpleCmdId cmdid_paste_current_song; | 68 static PurpleCmdId cmdid_paste_current_song; |
68 | 69 |
69 static void aud_process(gchar *aud_info); | 70 static void aud_process(gchar *aud_info); |
70 | 71 |
71 static DBusGProxy *get_dbus_proxy(void) | 72 static DBusGProxy * |
73 get_dbus_proxy(void) | |
72 { | 74 { |
73 DBusGConnection *connection = NULL; | 75 DBusGConnection *connection = NULL; |
74 DBusGProxy *session = NULL; | 76 DBusGProxy *session = NULL; |
75 GError *error = NULL; | 77 GError *error = NULL; |
76 connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error); | 78 connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error); |
146 /* generate key for hash table */ | 148 /* generate key for hash table */ |
147 key = g_strdup_printf("%s %s", account->username, account->protocol_id); | 149 key = g_strdup_printf("%s %s", account->username, account->protocol_id); |
148 | 150 |
149 /* retrieve current user status */ | 151 /* retrieve current user status */ |
150 current = purple_status_get_attr_string(status, "message"); | 152 current = purple_status_get_attr_string(status, "message"); |
151 aud_debug("status current = %s\n", current); | 153 aud_debug("status current = %s\n", current); |
152 | 154 |
153 /* invalidate pushded status on auto away etc. */ | 155 /* invalidate pushded status on auto away etc. */ |
154 if(current == NULL || strlen(current) == 0) { | 156 if(current == NULL || strlen(current) == 0) { |
155 g_hash_table_replace(pushed_status, g_strdup(key), g_strdup("")); | 157 g_hash_table_replace(pushed_status, g_strdup(key), g_strdup("")); |
156 g_free(key); | 158 g_free(key); |
157 return; | 159 return; |
158 } | 160 } |
159 | 161 |
160 /* pop pushed_status */ | 162 /* pop pushed_status */ |
161 pushed = (gchar *)g_hash_table_lookup(pushed_status, key); | 163 pushed = (gchar *)g_hash_table_lookup(pushed_status, key); |
166 g_hash_table_replace(pushed_status, g_strdup(key), g_strdup(current)); | 168 g_hash_table_replace(pushed_status, g_strdup(key), g_strdup(current)); |
167 } | 169 } |
168 | 170 |
169 /* construct new status message */ | 171 /* construct new status message */ |
170 seed = (gchar *)g_hash_table_lookup(seed_status, key); | 172 seed = (gchar *)g_hash_table_lookup(seed_status, key); |
171 g_return_if_fail(seed != NULL); | 173 if(!seed) { |
174 g_free(key); | |
175 return; | |
176 } | |
172 aud_debug("status seed = %s\n", seed); | 177 aud_debug("status seed = %s\n", seed); |
173 | 178 |
174 if(strstr(seed, SONG_TOKEN)) { | 179 if(strstr(seed, SONG_TOKEN)) { |
175 if(aud_info){ | 180 if(aud_info){ |
176 new = purple_strreplace(seed, SONG_TOKEN, aud_info); | 181 new = purple_strreplace(seed, SONG_TOKEN, aud_info); |
177 } | 182 } |
178 else { | 183 else { |
179 new = g_strdup(NO_SONG_MESSAGE); | 184 new = g_strdup(NO_SONG_MESSAGE); |
180 } | 185 } |
181 } | 186 } |
182 g_return_if_fail(new != NULL); | 187 |
188 if(!new) { | |
189 g_free(key); | |
190 return; | |
191 } | |
183 | 192 |
184 /* set status message only if text has been changed */ | 193 /* set status message only if text has been changed */ |
185 pushed = (gchar *)g_hash_table_lookup(pushed_status, key); | 194 pushed = (gchar *)g_hash_table_lookup(pushed_status, key); |
186 aud_debug("status pushed = %s\n", pushed); | 195 aud_debug("status pushed = %s\n", pushed); |
187 | 196 |
216 /* generate key for hash table*/ | 225 /* generate key for hash table*/ |
217 key = g_strdup_printf("%s %s", account->username, account->protocol_id); | 226 key = g_strdup_printf("%s %s", account->username, account->protocol_id); |
218 | 227 |
219 /* retrieve current user info */ | 228 /* retrieve current user info */ |
220 current = purple_account_get_user_info(account); /* it's always from account.xml! */ | 229 current = purple_account_get_user_info(account); /* it's always from account.xml! */ |
221 aud_debug("userinfo current = %s\n", current); | 230 aud_debug("userinfo current = %s\n", current); |
222 | 231 |
223 /* invalidate pushded status on auto away etc. */ | 232 /* invalidate pushded status on auto away etc. */ |
224 if(current == NULL || strlen(current) == 0) { | 233 if(current == NULL || strlen(current) == 0) { |
225 g_hash_table_replace(pushed_userinfo, g_strdup(key), g_strdup("")); | 234 g_hash_table_replace(pushed_userinfo, g_strdup(key), g_strdup("")); |
226 g_free(key); | 235 g_free(key); |
227 return; | 236 return; |
228 } | 237 } |
229 | 238 |
230 /* pop pushed_userinfo */ | 239 /* pop pushed_userinfo */ |
231 pushed = g_hash_table_lookup(pushed_userinfo, key); | 240 pushed = g_hash_table_lookup(pushed_userinfo, key); |
232 | 241 |
233 /* if current alias differs from pushed_alias or contains token, replace seed with this. */ | 242 /* if current alias differs from pushed_alias or contains token, replace seed with this. */ |
234 if( (pushed && g_ascii_strcasecmp(current, pushed)) || strstr(current, SONG_TOKEN) ) { | 243 if( (pushed && g_ascii_strcasecmp(current, pushed)) || strstr(current, SONG_TOKEN) ) { |
235 g_hash_table_replace(seed_userinfo, g_strdup(key), g_strdup(current)); | 244 g_hash_table_replace(seed_userinfo, g_strdup(key), g_strdup(current)); |
236 g_hash_table_replace(pushed_userinfo, g_strdup(key), g_strdup(current)); | 245 g_hash_table_replace(pushed_userinfo, g_strdup(key), g_strdup(current)); |
237 } | 246 } |
238 | 247 |
239 /* construct new status message */ | 248 /* construct new status message */ |
240 seed = (gchar *)g_hash_table_lookup(seed_userinfo, key); | 249 seed = (gchar *)g_hash_table_lookup(seed_userinfo, key); |
241 g_return_if_fail(seed != NULL); | 250 if(!seed) { |
251 g_free(key); | |
252 return; | |
253 } | |
242 aud_debug("userinfo seed = %s\n", seed); | 254 aud_debug("userinfo seed = %s\n", seed); |
243 | 255 |
244 if(strstr(seed, SONG_TOKEN)) { | 256 if(strstr(seed, SONG_TOKEN)) { |
245 if(aud_info){ | 257 if(aud_info){ |
246 new = purple_strreplace(seed, SONG_TOKEN, aud_info); | 258 new = purple_strreplace(seed, SONG_TOKEN, aud_info); |
247 } | 259 } |
248 else { | 260 else { |
249 new = g_strdup(NO_SONG_MESSAGE); | 261 new = g_strdup(NO_SONG_MESSAGE); |
250 } | 262 } |
251 } | 263 } |
252 g_return_if_fail(new != NULL); | 264 |
265 if(!new) { | |
266 g_free(key); | |
267 return; | |
268 } | |
253 | 269 |
254 /* set user info only if text has been changed */ | 270 /* set user info only if text has been changed */ |
255 pushed = (gchar *)g_hash_table_lookup(pushed_userinfo, key); | 271 pushed = (gchar *)g_hash_table_lookup(pushed_userinfo, key); |
256 aud_debug("userinfo pushed = %s\n", pushed); | 272 aud_debug("userinfo pushed = %s\n", pushed); |
257 | 273 |
288 | 304 |
289 /* retrieve current alias */ | 305 /* retrieve current alias */ |
290 current = purple_account_get_alias(account); | 306 current = purple_account_get_alias(account); |
291 if(current == NULL || strlen(current) == 0) { | 307 if(current == NULL || strlen(current) == 0) { |
292 aud_error("couldn't get current alias\n"); | 308 aud_error("couldn't get current alias\n"); |
293 g_free(key); | 309 g_free(key); |
294 return; | 310 return; |
295 } | 311 } |
296 aud_debug("current alias = %s\n", current); | 312 aud_debug("current alias = %s\n", current); |
297 | 313 |
298 /* pop pushed_alias */ | 314 /* pop pushed_alias */ |
299 pushed = g_hash_table_lookup(pushed_alias, key); | 315 pushed = g_hash_table_lookup(pushed_alias, key); |
300 | 316 |
301 /* if current alias differs from pushed_alias or contains token, replace seed with current. */ | 317 /* if current alias differs from pushed_alias or contains token, replace seed with current. */ |
302 if( (pushed && g_ascii_strcasecmp(current, pushed)) || strstr(current, SONG_TOKEN) ) { | 318 if( (pushed && g_ascii_strcasecmp(current, pushed)) || strstr(current, SONG_TOKEN) ) { |
303 g_hash_table_replace(seed_alias, g_strdup(key), g_strdup(current)); | 319 g_hash_table_replace(seed_alias, g_strdup(key), g_strdup(current)); |
304 } | 320 } |
305 | 321 |
306 /* construct new status message */ | 322 /* construct new status message */ |
307 seed = g_hash_table_lookup(seed_alias, key); | 323 seed = g_hash_table_lookup(seed_alias, key); |
308 g_return_if_fail(seed != NULL); | 324 if(!seed) { |
325 g_free(key); | |
326 return; | |
327 } | |
309 aud_debug("alias: seed = %s\n", (gchar *)seed); | 328 aud_debug("alias: seed = %s\n", (gchar *)seed); |
310 | 329 |
311 bytes = strlen(seed); | 330 bytes = strlen(seed); |
312 bytes -= strlen(SONG_TOKEN); | 331 bytes -= strlen(SONG_TOKEN); |
313 aud_debug("alias: bytes = %ld", bytes); | 332 aud_debug("alias: bytes = %ld", bytes); |
314 | 333 |
315 if(aud_info){ | 334 if(aud_info){ |
316 gchar *tmp = g_malloc0(BUDDY_ALIAS_MAXLEN); | 335 gchar *tmp = g_malloc0(BUDDY_ALIAS_MAXLEN); |
317 glong utflen = g_utf8_strlen(aud_info, BUDDY_ALIAS_MAXLEN/3 - bytes - 1); | 336 glong utflen = g_utf8_strlen(aud_info, BUDDY_ALIAS_MAXLEN/3 - bytes - 1); |
318 g_utf8_strncpy(tmp, aud_info, utflen); | 337 g_utf8_strncpy(tmp, aud_info, utflen); |
320 g_free(tmp); | 339 g_free(tmp); |
321 } | 340 } |
322 else { | 341 else { |
323 new = purple_strreplace(seed, SONG_TOKEN, NO_SONG_MESSAGE); | 342 new = purple_strreplace(seed, SONG_TOKEN, NO_SONG_MESSAGE); |
324 } | 343 } |
325 g_return_if_fail(new != NULL); | 344 if(!new) { |
345 g_free(key); | |
346 return; | |
347 } | |
326 | 348 |
327 /* set user info only if text has been changed */ | 349 /* set user info only if text has been changed */ |
328 pushed = g_hash_table_lookup(pushed_alias, key); | 350 pushed = g_hash_table_lookup(pushed_alias, key); |
329 aud_debug("alias pushed = %s\n", (gchar *)pushed); | 351 aud_debug("alias pushed = %s\n", (gchar *)pushed); |
330 | 352 |
392 aud_debug("********** restore_alias called **********\n"); | 414 aud_debug("********** restore_alias called **********\n"); |
393 account = purple_connection_get_account(gc); | 415 account = purple_connection_get_account(gc); |
394 | 416 |
395 key = g_strdup_printf("%s %s", account->username, account->protocol_id); | 417 key = g_strdup_printf("%s %s", account->username, account->protocol_id); |
396 val = g_hash_table_lookup(seed_alias, key); | 418 val = g_hash_table_lookup(seed_alias, key); |
397 g_return_val_if_fail(val != NULL, FALSE); | 419 if(!val) { |
420 g_free(key); | |
421 return FALSE; | |
422 } | |
398 | 423 |
399 aud_debug("write back alias %s\n", (char *)val); | 424 aud_debug("write back alias %s\n", (char *)val); |
400 purple_account_set_alias(account, val); //oct16 | 425 purple_account_set_alias(account, val); //oct16 |
401 | 426 |
402 g_free(key); | 427 g_free(key); |