Mercurial > pidgin
comparison libpurple/protocols/bonjour/bonjour.c @ 32819:2c6510167895 default tip
propagate from branch 'im.pidgin.pidgin.2.x.y' (head 3315c5dfbd0ad16511bdcf865e5b07c02d07df24)
to branch 'im.pidgin.pidgin' (head cbd1eda6bcbf0565ae7766396bb8f6f419cb6a9a)
author | Elliott Sales de Andrade <qulogic@pidgin.im> |
---|---|
date | Sat, 02 Jun 2012 02:30:49 +0000 |
parents | 2ec94166be43 |
children |
comparison
equal
deleted
inserted
replaced
32818:01ff09d4a463 | 32819:2c6510167895 |
---|---|
49 | 49 |
50 const char * | 50 const char * |
51 bonjour_get_jid(PurpleAccount *account) | 51 bonjour_get_jid(PurpleAccount *account) |
52 { | 52 { |
53 PurpleConnection *conn = purple_account_get_connection(account); | 53 PurpleConnection *conn = purple_account_get_connection(account); |
54 BonjourData *bd = conn->proto_data; | 54 BonjourData *bd = purple_connection_get_protocol_data(conn); |
55 return bd->jid; | 55 return bd->jid; |
56 } | 56 } |
57 | 57 |
58 static void | 58 static void |
59 bonjour_removeallfromlocal(PurpleConnection *conn, PurpleGroup *bonjour_group) | 59 bonjour_removeallfromlocal(PurpleConnection *conn, PurpleGroup *bonjour_group) |
92 PurpleStatus *status; | 92 PurpleStatus *status; |
93 PurplePresence *presence; | 93 PurplePresence *presence; |
94 | 94 |
95 #ifdef _WIN32 | 95 #ifdef _WIN32 |
96 if (!dns_sd_available()) { | 96 if (!dns_sd_available()) { |
97 purple_connection_error_reason(gc, | 97 purple_connection_error(gc, |
98 PURPLE_CONNECTION_ERROR_OTHER_ERROR, | 98 PURPLE_CONNECTION_ERROR_OTHER_ERROR, |
99 _("Unable to find Apple's \"Bonjour for Windows\" toolkit, see " | 99 _("Unable to find Apple's \"Bonjour for Windows\" toolkit, see " |
100 "http://d.pidgin.im/BonjourWindows for more information.")); | 100 "http://d.pidgin.im/BonjourWindows for more information.")); |
101 return; | 101 return; |
102 } | 102 } |
103 #endif /* _WIN32 */ | 103 #endif /* _WIN32 */ |
104 | 104 |
105 gc->flags |= PURPLE_CONNECTION_HTML; | 105 purple_connection_set_flags(gc, PURPLE_CONNECTION_HTML); |
106 gc->proto_data = bd = g_new0(BonjourData, 1); | 106 bd = g_new0(BonjourData, 1); |
107 purple_connection_set_protocol_data(gc, bd); | |
107 | 108 |
108 /* Start waiting for jabber connections (iChat style) */ | 109 /* Start waiting for jabber connections (iChat style) */ |
109 bd->jabber_data = g_new0(BonjourJabber, 1); | 110 bd->jabber_data = g_new0(BonjourJabber, 1); |
110 bd->jabber_data->socket = -1; | 111 bd->jabber_data->socket = -1; |
111 bd->jabber_data->socket6 = -1; | 112 bd->jabber_data->socket6 = -1; |
112 bd->jabber_data->port = purple_account_get_int(account, "port", BONJOUR_DEFAULT_PORT); | 113 bd->jabber_data->port = purple_account_get_int(account, "port", BONJOUR_DEFAULT_PORT); |
113 bd->jabber_data->account = account; | 114 bd->jabber_data->account = account; |
114 | 115 |
115 if (bonjour_jabber_start(bd->jabber_data) == -1) { | 116 if (bonjour_jabber_start(bd->jabber_data) == -1) { |
116 /* Send a message about the connection error */ | 117 /* Send a message about the connection error */ |
117 purple_connection_error_reason (gc, | 118 purple_connection_error (gc, |
118 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, | 119 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, |
119 _("Unable to listen for incoming IM connections")); | 120 _("Unable to listen for incoming IM connections")); |
120 return; | 121 return; |
121 } | 122 } |
122 | 123 |
139 bd->dns_sd_data->msg = g_strdup(purple_status_get_attr_string(status, "message")); | 140 bd->dns_sd_data->msg = g_strdup(purple_status_get_attr_string(status, "message")); |
140 | 141 |
141 bd->dns_sd_data->account = account; | 142 bd->dns_sd_data->account = account; |
142 if (!bonjour_dns_sd_start(bd->dns_sd_data)) | 143 if (!bonjour_dns_sd_start(bd->dns_sd_data)) |
143 { | 144 { |
144 purple_connection_error_reason (gc, | 145 purple_connection_error (gc, |
145 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, | 146 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, |
146 _("Unable to establish connection with the local mDNS server. Is it running?")); | 147 _("Unable to establish connection with the local mDNS server. Is it running?")); |
147 return; | 148 return; |
148 } | 149 } |
149 | 150 |
155 | 156 |
156 static void | 157 static void |
157 bonjour_close(PurpleConnection *connection) | 158 bonjour_close(PurpleConnection *connection) |
158 { | 159 { |
159 PurpleGroup *bonjour_group; | 160 PurpleGroup *bonjour_group; |
160 BonjourData *bd = connection->proto_data; | 161 BonjourData *bd = purple_connection_get_protocol_data(connection); |
161 | 162 |
162 bonjour_group = purple_find_group(BONJOUR_GROUP_NAME); | 163 bonjour_group = purple_find_group(BONJOUR_GROUP_NAME); |
163 | 164 |
164 /* Remove all the bonjour buddies */ | 165 /* Remove all the bonjour buddies */ |
165 bonjour_removeallfromlocal(connection, bonjour_group); | 166 bonjour_removeallfromlocal(connection, bonjour_group); |
190 } | 191 } |
191 | 192 |
192 if (bd != NULL) | 193 if (bd != NULL) |
193 g_free(bd->jid); | 194 g_free(bd->jid); |
194 g_free(bd); | 195 g_free(bd); |
195 connection->proto_data = NULL; | 196 purple_connection_set_protocol_data(connection, NULL); |
196 } | 197 } |
197 | 198 |
198 static const char * | 199 static const char * |
199 bonjour_list_icon(PurpleAccount *account, PurpleBuddy *buddy) | 200 bonjour_list_icon(PurpleAccount *account, PurpleBuddy *buddy) |
200 { | 201 { |
202 } | 203 } |
203 | 204 |
204 static int | 205 static int |
205 bonjour_send_im(PurpleConnection *connection, const char *to, const char *msg, PurpleMessageFlags flags) | 206 bonjour_send_im(PurpleConnection *connection, const char *to, const char *msg, PurpleMessageFlags flags) |
206 { | 207 { |
208 BonjourData *bd = purple_connection_get_protocol_data(connection); | |
209 | |
207 if(!to || !msg) | 210 if(!to || !msg) |
208 return 0; | 211 return 0; |
209 | 212 |
210 return bonjour_jabber_send_message(((BonjourData*)(connection->proto_data))->jabber_data, to, msg); | 213 return bonjour_jabber_send_message(bd->jabber_data, to, msg); |
211 } | 214 } |
212 | 215 |
213 static void | 216 static void |
214 bonjour_set_status(PurpleAccount *account, PurpleStatus *status) | 217 bonjour_set_status(PurpleAccount *account, PurpleStatus *status) |
215 { | 218 { |
218 PurplePresence *presence; | 221 PurplePresence *presence; |
219 const char *message, *bonjour_status; | 222 const char *message, *bonjour_status; |
220 gchar *stripped; | 223 gchar *stripped; |
221 | 224 |
222 gc = purple_account_get_connection(account); | 225 gc = purple_account_get_connection(account); |
223 bd = gc->proto_data; | 226 bd = purple_connection_get_protocol_data(gc); |
224 presence = purple_account_get_presence(account); | 227 presence = purple_account_get_presence(account); |
225 | 228 |
226 message = purple_status_get_attr_string(status, "message"); | 229 message = purple_status_get_attr_string(status, "message"); |
227 if (message == NULL) | 230 if (message == NULL) |
228 message = ""; | 231 message = ""; |
251 * Bonjour manages buddies for you, and adding someone locally by | 254 * Bonjour manages buddies for you, and adding someone locally by |
252 * hand is stupid. Perhaps we should change libpurple not to allow adding | 255 * hand is stupid. Perhaps we should change libpurple not to allow adding |
253 * if there is no add_buddy callback. | 256 * if there is no add_buddy callback. |
254 */ | 257 */ |
255 static void | 258 static void |
256 bonjour_fake_add_buddy(PurpleConnection *pc, PurpleBuddy *buddy, PurpleGroup *group) { | 259 bonjour_fake_add_buddy(PurpleConnection *pc, PurpleBuddy *buddy, PurpleGroup *group, const char *message) { |
257 purple_debug_error("bonjour", "Buddy '%s' manually added; removing. " | 260 purple_debug_error("bonjour", "Buddy '%s' manually added; removing. " |
258 "Bonjour buddies must be discovered and not manually added.\n", | 261 "Bonjour buddies must be discovered and not manually added.\n", |
259 purple_buddy_get_name(buddy)); | 262 purple_buddy_get_name(buddy)); |
260 | 263 |
261 /* I suppose we could alert the user here, but it seems unnecessary. */ | 264 /* I suppose we could alert the user here, but it seems unnecessary. */ |
304 } | 307 } |
305 | 308 |
306 static void | 309 static void |
307 bonjour_convo_closed(PurpleConnection *connection, const char *who) | 310 bonjour_convo_closed(PurpleConnection *connection, const char *who) |
308 { | 311 { |
309 PurpleBuddy *buddy = purple_find_buddy(connection->account, who); | 312 PurpleBuddy *buddy = purple_find_buddy(purple_connection_get_account(connection), who); |
310 BonjourBuddy *bb; | 313 BonjourBuddy *bb; |
311 | 314 |
312 if (buddy == NULL || (bb = purple_buddy_get_protocol_data(buddy)) == NULL) | 315 if (buddy == NULL || (bb = purple_buddy_get_protocol_data(buddy)) == NULL) |
313 { | 316 { |
314 /* | 317 /* |
323 } | 326 } |
324 | 327 |
325 static | 328 static |
326 void bonjour_set_buddy_icon(PurpleConnection *conn, PurpleStoredImage *img) | 329 void bonjour_set_buddy_icon(PurpleConnection *conn, PurpleStoredImage *img) |
327 { | 330 { |
328 BonjourData *bd = conn->proto_data; | 331 BonjourData *bd = purple_connection_get_protocol_data(conn); |
329 bonjour_dns_sd_update_buddy_icon(bd->dns_sd_data); | 332 bonjour_dns_sd_update_buddy_icon(bd->dns_sd_data); |
330 } | 333 } |
331 | 334 |
332 | 335 |
333 static char * | 336 static char * |
369 else if (purple_presence_is_idle(presence)) | 372 else if (purple_presence_is_idle(presence)) |
370 status_description = _("Idle"); | 373 status_description = _("Idle"); |
371 else | 374 else |
372 status_description = purple_status_get_name(status); | 375 status_description = purple_status_get_name(status); |
373 | 376 |
374 purple_notify_user_info_add_pair(user_info, _("Status"), status_description); | 377 purple_notify_user_info_add_pair_plaintext(user_info, _("Status"), status_description); |
375 if (message != NULL) | 378 if (message != NULL) { |
376 purple_notify_user_info_add_pair(user_info, _("Message"), message); | 379 /* TODO: Check whether it's correct to call add_pair_html, |
380 or if we should be using add_pair_plaintext */ | |
381 purple_notify_user_info_add_pair_html(user_info, _("Message"), message); | |
382 } | |
377 | 383 |
378 if (bb == NULL) { | 384 if (bb == NULL) { |
379 purple_debug_error("bonjour", "Got tooltip request for a buddy without protocol data.\n"); | 385 purple_debug_error("bonjour", "Got tooltip request for a buddy without protocol data.\n"); |
380 return; | 386 return; |
381 } | 387 } |
382 | 388 |
383 /* Only show first/last name if there is a nickname set (to avoid duplication) */ | 389 /* Only show first/last name if there is a nickname set (to avoid duplication) */ |
384 if (bb->nick != NULL && *bb->nick != '\0') { | 390 if (bb->nick != NULL && *bb->nick != '\0') { |
385 if (bb->first != NULL && *bb->first != '\0') | 391 if (bb->first != NULL && *bb->first != '\0') { |
386 purple_notify_user_info_add_pair(user_info, _("First name"), bb->first); | 392 /* TODO: Check whether it's correct to call add_pair_html, |
387 if (bb->last != NULL && *bb->last != '\0') | 393 or if we should be using add_pair_plaintext */ |
388 purple_notify_user_info_add_pair(user_info, _("Last name"), bb->last); | 394 purple_notify_user_info_add_pair_html(user_info, _("First name"), bb->first); |
389 } | 395 } |
390 | 396 if (bb->last != NULL && *bb->last != '\0') { |
391 if (bb->email != NULL && *bb->email != '\0') | 397 /* TODO: Check whether it's correct to call add_pair_html, |
392 purple_notify_user_info_add_pair(user_info, _("Email"), bb->email); | 398 or if we should be using add_pair_plaintext */ |
393 | 399 purple_notify_user_info_add_pair_html(user_info, _("Last name"), bb->last); |
394 if (bb->AIM != NULL && *bb->AIM != '\0') | 400 } |
395 purple_notify_user_info_add_pair(user_info, _("AIM Account"), bb->AIM); | 401 } |
396 | 402 |
397 if (bb->jid != NULL && *bb->jid != '\0') | 403 if (bb->email != NULL && *bb->email != '\0') { |
398 purple_notify_user_info_add_pair(user_info, _("XMPP Account"), bb->jid); | 404 /* TODO: Check whether it's correct to call add_pair_html, |
405 or if we should be using add_pair_plaintext */ | |
406 purple_notify_user_info_add_pair_html(user_info, _("Email"), bb->email); | |
407 } | |
408 | |
409 if (bb->AIM != NULL && *bb->AIM != '\0') { | |
410 /* TODO: Check whether it's correct to call add_pair_html, | |
411 or if we should be using add_pair_plaintext */ | |
412 purple_notify_user_info_add_pair_html(user_info, _("AIM Account"), bb->AIM); | |
413 } | |
414 | |
415 if (bb->jid != NULL && *bb->jid != '\0') { | |
416 /* TODO: Check whether it's correct to call add_pair_html, | |
417 or if we should be using add_pair_plaintext */ | |
418 purple_notify_user_info_add_pair_html(user_info, _("XMPP Account"), bb->jid); | |
419 } | |
399 } | 420 } |
400 | 421 |
401 static void | 422 static void |
402 bonjour_do_group_change(PurpleBuddy *buddy, const char *new_group) { | 423 bonjour_do_group_change(PurpleBuddy *buddy, const char *new_group) { |
403 PurpleBlistNodeFlags oldflags; | 424 PurpleBlistNodeFlags oldflags; |
416 } | 437 } |
417 | 438 |
418 static void | 439 static void |
419 bonjour_group_buddy(PurpleConnection *connection, const char *who, const char *old_group, const char *new_group) | 440 bonjour_group_buddy(PurpleConnection *connection, const char *who, const char *old_group, const char *new_group) |
420 { | 441 { |
421 PurpleBuddy *buddy = purple_find_buddy(connection->account, who); | 442 PurpleBuddy *buddy = purple_find_buddy(purple_connection_get_account(connection), who); |
422 | 443 |
423 bonjour_do_group_change(buddy, new_group); | 444 bonjour_do_group_change(buddy, new_group); |
424 | 445 |
425 } | 446 } |
426 | 447 |
441 } | 462 } |
442 | 463 |
443 static gboolean | 464 static gboolean |
444 bonjour_can_receive_file(PurpleConnection *connection, const char *who) | 465 bonjour_can_receive_file(PurpleConnection *connection, const char *who) |
445 { | 466 { |
446 PurpleBuddy *buddy = purple_find_buddy(connection->account, who); | 467 PurpleBuddy *buddy = purple_find_buddy(purple_connection_get_account(connection), who); |
447 | 468 |
448 return (buddy != NULL && purple_buddy_get_protocol_data(buddy) != NULL); | 469 return (buddy != NULL && purple_buddy_get_protocol_data(buddy) != NULL); |
449 } | 470 } |
450 | 471 |
451 static gboolean | 472 static gboolean |
461 | 482 |
462 static PurplePlugin *my_protocol = NULL; | 483 static PurplePlugin *my_protocol = NULL; |
463 | 484 |
464 static PurplePluginProtocolInfo prpl_info = | 485 static PurplePluginProtocolInfo prpl_info = |
465 { | 486 { |
487 sizeof(PurplePluginProtocolInfo), /* struct_size */ | |
466 OPT_PROTO_NO_PASSWORD, | 488 OPT_PROTO_NO_PASSWORD, |
467 NULL, /* user_splits */ | 489 NULL, /* user_splits */ |
468 NULL, /* protocol_options */ | 490 NULL, /* protocol_options */ |
469 {"png,gif,jpeg", 0, 0, 96, 96, 65535, PURPLE_ICON_SCALE_DISPLAY}, /* icon_spec */ | 491 {"png,gif,jpeg", 0, 0, 96, 96, 65535, PURPLE_ICON_SCALE_DISPLAY}, /* icon_spec */ |
470 bonjour_list_icon, /* list_icon */ | 492 bonjour_list_icon, /* list_icon */ |
501 NULL, /* chat_whisper */ | 523 NULL, /* chat_whisper */ |
502 NULL, /* chat_send */ | 524 NULL, /* chat_send */ |
503 NULL, /* keepalive */ | 525 NULL, /* keepalive */ |
504 NULL, /* register_user */ | 526 NULL, /* register_user */ |
505 NULL, /* get_cb_info */ | 527 NULL, /* get_cb_info */ |
506 NULL, /* get_cb_away */ | |
507 NULL, /* alias_buddy */ | 528 NULL, /* alias_buddy */ |
508 bonjour_group_buddy, /* group_buddy */ | 529 bonjour_group_buddy, /* group_buddy */ |
509 bonjour_rename_group, /* rename_group */ | 530 bonjour_rename_group, /* rename_group */ |
510 NULL, /* buddy_free */ | 531 NULL, /* buddy_free */ |
511 bonjour_convo_closed, /* convo_closed */ | 532 bonjour_convo_closed, /* convo_closed */ |
526 NULL, /* send_raw */ | 547 NULL, /* send_raw */ |
527 NULL, /* roomlist_room_serialize */ | 548 NULL, /* roomlist_room_serialize */ |
528 NULL, /* unregister_user */ | 549 NULL, /* unregister_user */ |
529 NULL, /* send_attention */ | 550 NULL, /* send_attention */ |
530 NULL, /* get_attention_types */ | 551 NULL, /* get_attention_types */ |
531 sizeof(PurplePluginProtocolInfo), /* struct_size */ | |
532 NULL, /* get_account_text_table */ | 552 NULL, /* get_account_text_table */ |
533 NULL, /* initiate_media */ | 553 NULL, /* initiate_media */ |
534 NULL, /* get_media_caps */ | 554 NULL, /* get_media_caps */ |
535 NULL, /* get_moods */ | 555 NULL, /* get_moods */ |
536 NULL, /* set_public_alias */ | 556 NULL, /* set_public_alias */ |
537 NULL, /* get_public_alias */ | 557 NULL /* get_public_alias */ |
538 NULL, /* add_buddy_with_invite */ | |
539 NULL /* add_buddies_with_invite */ | |
540 }; | 558 }; |
541 | 559 |
542 static PurplePluginInfo info = | 560 static PurplePluginInfo info = |
543 { | 561 { |
544 PURPLE_PLUGIN_MAGIC, | 562 PURPLE_PLUGIN_MAGIC, |