Mercurial > pidgin
annotate src/protocols/bonjour/bonjour.c @ 13909:8264f52a1142
[gaim-migrate @ 16406]
More of sf patch #1490646, from Jonty Wareing & Jono Cole
"The screen name + hostname of the sending user is sent
in the outgoing jabber message, fixing a sporadic
problem with iChat.
The port in use has been fixed to the one described in
the Bonjour specification and can no longer be changed
in the prpl preferences - modifiying this just stops
the client from being able to start a chat.
The option for a buddy icon has been removed for now as
no code actually uses it yet - we plan to change this
in the future.
This update also introduces automatic local port retry
for up to ten attempts if the port is in
use (e.g. if multiple instances of gaim are running)."
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Mon, 03 Jul 2006 00:37:41 +0000 |
parents | b986b6e2441b |
children | 6c907830a45f |
rev | line source |
---|---|
11477 | 1 /* |
2 * gaim - Bonjour Protocol Plugin | |
3 * | |
4 * Gaim is the legal property of its developers, whose names are too numerous | |
5 * to list here. Please refer to the COPYRIGHT file distributed with this | |
6 * source distribution. | |
7 * | |
8 * This program is free software; you can redistribute it and/or modify | |
9 * it under the terms of the GNU General Public License as published by | |
10 * the Free Software Foundation; either version 2 of the License, or | |
11 * (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, | |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 * GNU General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License | |
19 * along with this program; if not, write to the Free Software | |
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 */ | |
22 #include <glib.h> | |
12003
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
23 #ifndef _WIN32 |
11984 | 24 #include <pwd.h> |
12003
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
25 #else |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
26 #define UNICODE |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
27 #include <windows.h> |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
28 #include <lm.h> |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
29 #endif |
11477 | 30 |
31 #include "internal.h" | |
13061 | 32 |
11477 | 33 #include "account.h" |
34 #include "accountopt.h" | |
13061 | 35 #include "debug.h" |
36 #include "util.h" | |
11477 | 37 #include "version.h" |
38 | |
39 #include "bonjour.h" | |
40 #include "dns_sd.h" | |
41 #include "jabber.h" | |
42 #include "buddy.h" | |
43 | |
12339 | 44 /* |
45 * TODO: Should implement an add_buddy callback that removes the buddy | |
46 * from the local list. Bonjour manages buddies for you, and | |
13061 | 47 * adding someone locally by hand is stupid. Or, maybe even better, |
48 * if a PRPL does not have an add_buddy callback then do not allow | |
49 * users to add buddies. | |
12339 | 50 */ |
51 | |
11984 | 52 static char *default_firstname; |
53 static char *default_lastname; | |
54 static char *default_hostname; | |
55 | |
11691 | 56 static void |
57 bonjour_removeallfromlocal(GaimConnection *gc) | |
58 { | |
59 GaimAccount *account = gaim_connection_get_account(gc); | |
60 GaimBuddyList *blist; | |
61 GaimBlistNode *gnode, *cnode, *bnode; | |
62 GaimBuddy *buddy; | |
63 | |
64 blist = gaim_get_blist(); | |
65 if (blist == NULL) | |
66 return; | |
67 | |
68 /* Go through and remove all buddies that belong to this account */ | |
69 for (gnode = blist->root; gnode; gnode = gnode->next) | |
70 { | |
71 if (!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
72 continue; | |
73 for (cnode = gnode->child; cnode; cnode = cnode->next) | |
74 { | |
75 if (!GAIM_BLIST_NODE_IS_CONTACT(cnode)) | |
76 continue; | |
77 for (bnode = cnode->child; bnode; bnode = bnode->next) | |
78 { | |
79 if (!GAIM_BLIST_NODE_IS_BUDDY(bnode)) | |
80 continue; | |
81 buddy = (GaimBuddy *)bnode; | |
82 if (buddy->account != account) | |
83 continue; | |
84 gaim_prpl_got_user_status(account, buddy->name, "offline", NULL); | |
85 gaim_blist_remove_buddy(buddy); | |
86 } | |
87 } | |
88 } | |
89 } | |
90 | |
12443 | 91 static void |
11837 | 92 bonjour_login(GaimAccount *account) |
11477 | 93 { |
94 GaimConnection *gc = gaim_account_get_connection(account); | |
11539 | 95 GaimGroup *bonjour_group = NULL; |
96 BonjourData *bd = NULL; | |
11837 | 97 GaimStatus *status; |
11834 | 98 GaimPresence *presence; |
11539 | 99 |
11477 | 100 gc->flags |= GAIM_CONNECTION_HTML; |
11984 | 101 gc->proto_data = g_new0(BonjourData, 1); |
11477 | 102 bd = gc->proto_data; |
11539 | 103 |
11829
4669e7461968
[gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents:
11718
diff
changeset
|
104 /* Start waiting for jabber connections (iChat style) */ |
11477 | 105 bd->jabber_data = g_new(BonjourJabber, 1); |
13909 | 106 bd->jabber_data->port = BONJOUR_DEFAULT_PORT_INT; |
11477 | 107 bd->jabber_data->account = account; |
11539 | 108 |
11477 | 109 if (bonjour_jabber_start(bd->jabber_data) == -1) { |
11829
4669e7461968
[gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents:
11718
diff
changeset
|
110 /* Send a message about the connection error */ |
11984 | 111 gaim_connection_error(gc, _("Unable to listen for incoming IM connections\n")); |
11539 | 112 |
11829
4669e7461968
[gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents:
11718
diff
changeset
|
113 /* Free the data */ |
11477 | 114 g_free(bd->jabber_data); |
11984 | 115 bd->jabber_data = NULL; |
11477 | 116 return; |
117 } | |
11539 | 118 |
11829
4669e7461968
[gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents:
11718
diff
changeset
|
119 /* Connect to the mDNS daemon looking for buddies in the LAN */ |
11477 | 120 bd->dns_sd_data = bonjour_dns_sd_new(); |
121 bd->dns_sd_data->name = (sw_string)gaim_account_get_username(account); | |
122 bd->dns_sd_data->txtvers = g_strdup("1"); | |
123 bd->dns_sd_data->version = g_strdup("1"); | |
11984 | 124 bd->dns_sd_data->first = g_strdup(gaim_account_get_string(account, "first", default_firstname)); |
125 bd->dns_sd_data->last = g_strdup(gaim_account_get_string(account, "last", default_lastname)); | |
13909 | 126 bd->dns_sd_data->port_p2pj = bd->jabber_data->port; |
11477 | 127 bd->dns_sd_data->phsh = g_strdup(""); |
11496 | 128 bd->dns_sd_data->email = g_strdup(gaim_account_get_string(account, "email", "")); |
11477 | 129 bd->dns_sd_data->vc = g_strdup(""); |
13906 | 130 bd->dns_sd_data->jid = g_strdup(gaim_account_get_string(account, "jid", "")); |
131 bd->dns_sd_data->AIM = g_strdup(gaim_account_get_string(account, "AIM", "")); | |
11834 | 132 |
133 status = gaim_account_get_active_status(account); | |
134 presence = gaim_account_get_presence(account); | |
135 if (gaim_presence_is_available(presence)) | |
136 bd->dns_sd_data->status = g_strdup("avail"); | |
137 else if (gaim_presence_is_idle(presence)) | |
138 bd->dns_sd_data->status = g_strdup("away"); | |
139 else | |
140 bd->dns_sd_data->status = g_strdup("dnd"); | |
141 bd->dns_sd_data->msg = g_strdup(gaim_status_get_attr_string(status, "message")); | |
11539 | 142 |
11477 | 143 bd->dns_sd_data->account = account; |
11927 | 144 if (!bonjour_dns_sd_start(bd->dns_sd_data)) |
145 { | |
146 gaim_connection_error(gc, _("Unable to establish connection with the local mDNS server. Is it running?")); | |
147 return; | |
148 } | |
11539 | 149 |
11829
4669e7461968
[gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents:
11718
diff
changeset
|
150 /* Create a group for bonjour buddies */ |
11477 | 151 bonjour_group = gaim_group_new(BONJOUR_GROUP_NAME); |
152 gaim_blist_add_group(bonjour_group, NULL); | |
11539 | 153 |
11829
4669e7461968
[gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents:
11718
diff
changeset
|
154 /* Show the buddy list by telling Gaim we have already connected */ |
11477 | 155 gaim_connection_set_state(gc, GAIM_CONNECTED); |
156 } | |
157 | |
12443 | 158 static void |
11539 | 159 bonjour_close(GaimConnection *connection) |
11477 | 160 { |
13063 | 161 GaimGroup *bonjour_group; |
11539 | 162 BonjourData *bd = (BonjourData*)connection->proto_data; |
163 | |
11829
4669e7461968
[gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents:
11718
diff
changeset
|
164 /* Stop looking for buddies in the LAN */ |
11984 | 165 if (bd->dns_sd_data != NULL) |
166 { | |
11477 | 167 bonjour_dns_sd_stop(bd->dns_sd_data); |
11984 | 168 bonjour_dns_sd_free(bd->dns_sd_data); |
11477 | 169 } |
11539 | 170 |
11984 | 171 if (bd->jabber_data != NULL) |
172 { | |
173 /* Stop waiting for conversations */ | |
174 bonjour_jabber_stop(bd->jabber_data); | |
175 g_free(bd->jabber_data); | |
176 } | |
11539 | 177 |
11829
4669e7461968
[gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents:
11718
diff
changeset
|
178 /* Remove all the bonjour buddies */ |
11691 | 179 bonjour_removeallfromlocal(connection); |
11539 | 180 |
11829
4669e7461968
[gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents:
11718
diff
changeset
|
181 /* Delete the bonjour group */ |
13063 | 182 bonjour_group = gaim_find_group(BONJOUR_GROUP_NAME); |
183 if (bonjour_group != NULL) | |
184 gaim_blist_remove_group(bonjour_group); | |
11539 | 185 |
11477 | 186 } |
187 | |
12443 | 188 static const char * |
11539 | 189 bonjour_list_icon(GaimAccount *account, GaimBuddy *buddy) |
11477 | 190 { |
191 return BONJOUR_ICON_NAME; | |
192 } | |
193 | |
12443 | 194 static int |
12216 | 195 bonjour_send_im(GaimConnection *connection, const char *to, const char *msg, GaimMessageFlags flags) |
11477 | 196 { |
197 if(!to || !msg) | |
198 return 0; | |
11539 | 199 |
11693 | 200 return bonjour_jabber_send_message(((BonjourData*)(connection->proto_data))->jabber_data, to, msg); |
11477 | 201 } |
202 | |
12443 | 203 static void |
11539 | 204 bonjour_set_status(GaimAccount *account, GaimStatus *status) |
11477 | 205 { |
11496 | 206 GaimConnection *gc; |
207 BonjourData *bd; | |
208 gboolean disconnected; | |
209 GaimStatusType *type; | |
210 int primitive; | |
211 GaimPresence *presence; | |
11841 | 212 const char *message, *bonjour_status; |
13061 | 213 gchar *stripped; |
11477 | 214 |
11839 | 215 gc = gaim_account_get_connection(account); |
216 bd = gc->proto_data; | |
11496 | 217 disconnected = gaim_account_is_disconnected(account); |
218 type = gaim_status_get_type(status); | |
219 primitive = gaim_status_type_get_primitive(type); | |
220 presence = gaim_account_get_presence(account); | |
221 | |
222 message = gaim_status_get_attr_string(status, "message"); | |
223 if (message == NULL) | |
224 message = ""; | |
13061 | 225 stripped = gaim_markup_strip_html(message); |
11496 | 226 |
227 /* | |
228 * The three possible status for Bonjour are | |
229 * -available ("avail") | |
230 * -idle ("away") | |
231 * -away ("dnd") | |
232 * Each of them can have an optional message. | |
233 */ | |
11835 | 234 if (gaim_presence_is_available(presence)) |
11841 | 235 bonjour_status = "avail"; |
11835 | 236 else if (gaim_presence_is_idle(presence)) |
11841 | 237 bonjour_status = "away"; |
11835 | 238 else |
11841 | 239 bonjour_status = "dnd"; |
11477 | 240 |
13061 | 241 bonjour_dns_sd_send_status(bd->dns_sd_data, bonjour_status, stripped); |
242 g_free(stripped); | |
11477 | 243 } |
244 | |
11496 | 245 static GList * |
246 bonjour_status_types(GaimAccount *account) | |
11477 | 247 { |
11496 | 248 GList *status_types = NULL; |
249 GaimStatusType *type; | |
250 | |
251 g_return_val_if_fail(account != NULL, NULL); | |
252 | |
253 type = gaim_status_type_new_with_attrs(GAIM_STATUS_AVAILABLE, | |
254 BONJOUR_STATUS_ID_AVAILABLE, | |
12595
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12489
diff
changeset
|
255 NULL, TRUE, TRUE, FALSE, |
11496 | 256 "message", _("Message"), |
257 gaim_value_new(GAIM_TYPE_STRING), NULL); | |
258 status_types = g_list_append(status_types, type); | |
11477 | 259 |
11496 | 260 type = gaim_status_type_new_with_attrs(GAIM_STATUS_AWAY, |
261 BONJOUR_STATUS_ID_AWAY, | |
12595
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12489
diff
changeset
|
262 NULL, TRUE, TRUE, FALSE, |
11496 | 263 "message", _("Message"), |
264 gaim_value_new(GAIM_TYPE_STRING), NULL); | |
265 status_types = g_list_append(status_types, type); | |
266 | |
12658 | 267 type = gaim_status_type_new_full(GAIM_STATUS_OFFLINE, |
268 BONJOUR_STATUS_ID_OFFLINE, | |
269 NULL, TRUE, TRUE, FALSE); | |
270 status_types = g_list_append(status_types, type); | |
271 | |
11496 | 272 return status_types; |
11477 | 273 } |
274 | |
11539 | 275 static void |
276 bonjour_convo_closed(GaimConnection *connection, const char *who) | |
11477 | 277 { |
11539 | 278 GaimBuddy *buddy = gaim_find_buddy(connection->account, who); |
279 | |
11966 | 280 if (buddy == NULL) |
12595
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12489
diff
changeset
|
281 { |
11966 | 282 /* |
283 * This buddy is not in our buddy list, and therefore does not really | |
284 * exist, so we won't have any data about them. | |
285 */ | |
286 return; | |
12595
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12489
diff
changeset
|
287 } |
11966 | 288 |
11477 | 289 bonjour_jabber_close_conversation(((BonjourData*)(connection->proto_data))->jabber_data, buddy); |
290 } | |
291 | |
11539 | 292 static void |
293 bonjour_list_emblems(GaimBuddy *buddy, | |
11496 | 294 const char **se, const char **sw, |
12595
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12489
diff
changeset
|
295 const char **nw, const char **ne) |
11477 | 296 { |
11496 | 297 GaimPresence *presence; |
298 | |
299 presence = gaim_buddy_get_presence(buddy); | |
300 | |
12339 | 301 if (gaim_presence_is_online(presence) && !gaim_presence_is_available(presence)) |
11496 | 302 *se = "away"; |
303 } | |
304 | |
11539 | 305 static char * |
306 bonjour_status_text(GaimBuddy *buddy) | |
11496 | 307 { |
308 GaimPresence *presence; | |
309 | |
310 presence = gaim_buddy_get_presence(buddy); | |
311 | |
12339 | 312 if (gaim_presence_is_online(presence) && !gaim_presence_is_available(presence)) |
11496 | 313 return g_strdup("Away"); |
12339 | 314 |
315 return NULL; | |
11477 | 316 } |
317 | |
12970
ec9b92104904
[gaim-migrate @ 15323]
Richard Laager <rlaager@wiktel.com>
parents:
12943
diff
changeset
|
318 static void |
ec9b92104904
[gaim-migrate @ 15323]
Richard Laager <rlaager@wiktel.com>
parents:
12943
diff
changeset
|
319 bonjour_tooltip_text(GaimBuddy *buddy, GString *str, gboolean full) |
11477 | 320 { |
11496 | 321 GaimPresence *presence; |
322 GaimStatus *status; | |
323 const char *status_description; | |
324 const char *message; | |
325 | |
326 presence = gaim_buddy_get_presence(buddy); | |
327 status = gaim_presence_get_active_status(presence); | |
328 message = gaim_status_get_attr_string(status, "message"); | |
329 | |
330 if (gaim_presence_is_available(presence)) | |
331 status_description = gaim_status_get_name(status); | |
332 else if (gaim_presence_is_idle(presence)) | |
333 status_description = _("Idle"); | |
334 else | |
335 status_description = gaim_status_get_name(status); | |
336 | |
12970
ec9b92104904
[gaim-migrate @ 15323]
Richard Laager <rlaager@wiktel.com>
parents:
12943
diff
changeset
|
337 g_string_append_printf(str, _("\n<b>Status:</b> %s"), status_description); |
11519 | 338 if (message != NULL) |
12970
ec9b92104904
[gaim-migrate @ 15323]
Richard Laager <rlaager@wiktel.com>
parents:
12943
diff
changeset
|
339 g_string_append_printf(str, _("\n<b>Message:</b> %s"), message); |
11477 | 340 } |
341 | |
11984 | 342 static gboolean |
343 plugin_unload(GaimPlugin *plugin) | |
344 { | |
345 g_free(default_firstname); | |
346 g_free(default_lastname); | |
347 g_free(default_hostname); | |
348 | |
349 return TRUE; | |
350 } | |
351 | |
11477 | 352 static GaimPlugin *my_protocol = NULL; |
353 | |
354 static GaimPluginProtocolInfo prpl_info = | |
355 { | |
356 OPT_PROTO_NO_PASSWORD, | |
357 NULL, /* user_splits */ | |
358 NULL, /* protocol_options */ | |
13909 | 359 /* {"png", 0, 0, 96, 96, GAIM_ICON_SCALE_DISPLAY}, */ /* icon_spec */ |
360 NO_BUDDY_ICONS, /* not yet */ /* icon_spec */ | |
11477 | 361 bonjour_list_icon, /* list_icon */ |
362 bonjour_list_emblems, /* list_emblems */ | |
363 bonjour_status_text, /* status_text */ | |
364 bonjour_tooltip_text, /* tooltip_text */ | |
365 bonjour_status_types, /* status_types */ | |
366 NULL, /* blist_node_menu */ | |
367 NULL, /* chat_info */ | |
368 NULL, /* chat_info_defaults */ | |
369 bonjour_login, /* login */ | |
370 bonjour_close, /* close */ | |
371 bonjour_send_im, /* send_im */ | |
372 NULL, /* set_info */ | |
373 NULL, /* send_typing */ | |
374 NULL, /* get_info */ | |
375 bonjour_set_status, /* set_status */ | |
376 NULL, /* set_idle */ | |
377 NULL, /* change_passwd */ | |
378 NULL, /* add_buddy */ | |
379 NULL, /* add_buddies */ | |
380 NULL, /* remove_buddy */ | |
381 NULL, /* remove_buddies */ | |
382 NULL, /* add_permit */ | |
383 NULL, /* add_deny */ | |
384 NULL, /* rem_permit */ | |
385 NULL, /* rem_deny */ | |
386 NULL, /* set_permit_deny */ | |
387 NULL, /* join_chat */ | |
388 NULL, /* reject_chat */ | |
389 NULL, /* get_chat_name */ | |
390 NULL, /* chat_invite */ | |
391 NULL, /* chat_leave */ | |
392 NULL, /* chat_whisper */ | |
393 NULL, /* chat_send */ | |
394 NULL, /* keepalive */ | |
395 NULL, /* register_user */ | |
396 NULL, /* get_cb_info */ | |
397 NULL, /* get_cb_away */ | |
398 NULL, /* alias_buddy */ | |
399 NULL, /* group_buddy */ | |
400 NULL, /* rename_group */ | |
401 NULL, /* buddy_free */ | |
402 bonjour_convo_closed, /* convo_closed */ | |
403 NULL, /* normalize */ | |
404 NULL, /* set_buddy_icon */ | |
405 NULL, /* remove_group */ | |
406 NULL, /* get_cb_real_name */ | |
407 NULL, /* set_chat_topic */ | |
408 NULL, /* find_blist_chat */ | |
409 NULL, /* roomlist_get_list */ | |
410 NULL, /* roomlist_cancel */ | |
411 NULL, /* roomlist_expand_category */ | |
412 NULL, /* can_receive_file */ | |
12143
cbebda5f019c
[gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents:
12003
diff
changeset
|
413 NULL, /* send_file */ |
12607 | 414 NULL, /* new_xfer */ |
12650 | 415 NULL, /* offline_message */ |
12607 | 416 NULL, /* whiteboard_prpl_ops */ |
11477 | 417 }; |
418 | |
419 static GaimPluginInfo info = | |
420 { | |
421 GAIM_PLUGIN_MAGIC, | |
422 GAIM_MAJOR_VERSION, | |
423 GAIM_MINOR_VERSION, | |
424 GAIM_PLUGIN_PROTOCOL, /**< type */ | |
425 NULL, /**< ui_requirement */ | |
426 0, /**< flags */ | |
427 NULL, /**< dependencies */ | |
428 GAIM_PRIORITY_DEFAULT, /**< priority */ | |
429 | |
430 "prpl-bonjour", /**< id */ | |
431 "Bonjour", /**< name */ | |
432 VERSION, /**< version */ | |
433 /** summary */ | |
434 N_("Bonjour Protocol Plugin"), | |
435 /** description */ | |
436 N_("Bonjour Protocol Plugin"), | |
437 NULL, /**< author */ | |
438 GAIM_WEBSITE, /**< homepage */ | |
439 | |
440 NULL, /**< load */ | |
11984 | 441 plugin_unload, /**< unload */ |
11477 | 442 NULL, /**< destroy */ |
443 | |
444 NULL, /**< ui_info */ | |
445 &prpl_info, /**< extra_info */ | |
446 NULL, /**< prefs_info */ | |
447 NULL | |
448 }; | |
449 | |
450 static void | |
11984 | 451 initialize_default_account_values() |
452 { | |
13191 | 453 #ifdef _WIN32 |
11984 | 454 char *fullname = NULL; |
13191 | 455 #else |
456 struct passwd *info; | |
457 const char *fullname = NULL; | |
458 #endif | |
11984 | 459 char *splitpoint = NULL; |
460 char hostname[255]; | |
13191 | 461 |
12003
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
462 #ifndef _WIN32 |
11984 | 463 /* Try to figure out the user's real name */ |
464 info = getpwuid(getuid()); | |
465 if ((info != NULL) && (info->pw_gecos != NULL) && (info->pw_gecos[0] != '\0')) | |
466 fullname = info->pw_gecos; | |
467 else if ((info != NULL) && (info->pw_name != NULL) && (info->pw_name[0] != '\0')) | |
468 fullname = info->pw_name; | |
469 else if (((fullname = getlogin()) != NULL) && (fullname[0] != '\0')) | |
470 ; | |
471 else | |
472 fullname = _("Gaim User"); | |
473 | |
13075 | 474 /* Make sure fullname is valid UTF-8. If not, try to convert it. */ |
475 if (!g_utf8_validate(fullname, -1, NULL)) | |
476 { | |
477 gchar *tmp; | |
478 tmp = g_locale_to_utf8(fullname, -1, NULL, NULL, NULL); | |
479 if ((tmp == NULL) || (*tmp == '\0')) | |
480 fullname = _("Gaim User"); | |
481 } | |
482 | |
12003
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
483 #else |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
484 FARPROC myNetUserGetInfo = wgaim_find_and_loadproc("Netapi32.dll", |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
485 "NetUserGetInfo"); |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
486 |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
487 if (myNetUserGetInfo) { |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
488 LPUSER_INFO_10 user_info = NULL; |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
489 LPSERVER_INFO_100 server_info = NULL; |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
490 wchar_t *servername = NULL; |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
491 wchar_t username[UNLEN + 1] = {'\0'}; |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
492 DWORD dwLenUsername = sizeof(username); |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
493 FARPROC myNetServerEnum = wgaim_find_and_loadproc( |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
494 "Netapi32.dll", "NetServerEnum"); |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
495 FARPROC myNetApiBufferFree = wgaim_find_and_loadproc( |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
496 "Netapi32.dll", "NetApiBufferFree"); |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
497 |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
498 if (myNetServerEnum && myNetApiBufferFree) { |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
499 DWORD dwEntriesRead = 0; |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
500 DWORD dwTotalEntries = 0; |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
501 DWORD dwResumeHandle = 0; |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
502 |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
503 NET_API_STATUS nStatus = (myNetServerEnum)(NULL, 100, |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
504 &server_info, MAX_PREFERRED_LENGTH, |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
505 &dwEntriesRead, &dwTotalEntries, |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
506 SV_TYPE_DOMAIN_CTRL, NULL, &dwResumeHandle); |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
507 |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
508 if ((nStatus == NERR_Success |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
509 || nStatus == ERROR_MORE_DATA) |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
510 && dwEntriesRead > 0) { |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
511 servername = server_info->sv100_name; |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
512 } else { |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
513 gaim_debug_warning("bonjour", "Unable to look up domain controller. NET_API_STATUS = %d, Entries Read = %d, Total Entries = %d\n", nStatus, dwEntriesRead, dwTotalEntries); |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
514 } |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
515 } |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
516 |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
517 if (!GetUserNameW(&username, &dwLenUsername)) { |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
518 gaim_debug_warning("bonjour", |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
519 "Unable to look up username\n"); |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
520 } |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
521 |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
522 if (username != NULL && *username != '\0' |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
523 && (myNetUserGetInfo)(servername, username, 10, |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
524 &user_info) == NERR_Success) { |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
525 if (user_info != NULL) { |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
526 fullname = g_utf16_to_utf8( |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
527 user_info->usri10_full_name, |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
528 -1, NULL, NULL, NULL); |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
529 } |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
530 } |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
531 if (user_info != NULL) |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
532 (myNetApiBufferFree)(user_info); |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
533 if (server_info != NULL) |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
534 (myNetApiBufferFree)(server_info); |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
535 } |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
536 |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
537 if (!fullname) |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
538 fullname = g_strdup(_("Gaim User")); |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
539 #endif |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
540 |
11984 | 541 /* Split the real name into a first and last name */ |
542 splitpoint = strchr(fullname, ' '); | |
543 if (splitpoint != NULL) | |
544 { | |
545 default_firstname = g_strndup(fullname, splitpoint - fullname); | |
546 default_lastname = g_strdup(&splitpoint[1]); | |
547 } | |
548 else | |
549 { | |
550 default_firstname = g_strdup(fullname); | |
551 default_lastname = g_strdup(""); | |
552 } | |
553 | |
12003
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
554 #ifdef _WIN32 |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
555 g_free(fullname); |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
556 #endif |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
557 |
11984 | 558 /* Try to figure out a good host name to use */ |
559 /* TODO: Avoiding 'localhost,' if possible */ | |
560 if (gethostname(hostname, 255) != 0) { | |
12003
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
561 gaim_debug_warning("bonjour", "Error %d when getting host name. Using \"localhost.\"\n", errno); |
11984 | 562 strcpy(hostname, "localhost"); |
563 } | |
564 default_hostname = g_strdup(hostname); | |
565 } | |
566 | |
567 static void | |
11477 | 568 init_plugin(GaimPlugin *plugin) |
569 { | |
570 GaimAccountUserSplit *split; | |
571 GaimAccountOption *option; | |
572 | |
11984 | 573 initialize_default_account_values(); |
11477 | 574 |
11829
4669e7461968
[gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents:
11718
diff
changeset
|
575 /* Creating the user splits */ |
12489 | 576 split = gaim_account_user_split_new(_("Hostname"), default_hostname, '@'); |
11477 | 577 prpl_info.user_splits = g_list_append(prpl_info.user_splits, split); |
11539 | 578 |
11829
4669e7461968
[gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents:
11718
diff
changeset
|
579 /* Creating the options for the protocol */ |
11984 | 580 option = gaim_account_option_string_new(_("First name"), "first", default_firstname); |
11477 | 581 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); |
582 | |
11984 | 583 option = gaim_account_option_string_new(_("Last name"), "last", default_lastname); |
11477 | 584 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); |
585 | |
13545
cfc2f7fcb3dd
[gaim-migrate @ 15922]
Richard Laager <rlaager@wiktel.com>
parents:
13296
diff
changeset
|
586 option = gaim_account_option_string_new(_("E-mail"), "email", ""); |
11477 | 587 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); |
11539 | 588 |
13906 | 589 option = gaim_account_option_string_new(_("AIM Account"), "AIM", ""); |
590 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
591 | |
592 option = gaim_account_option_string_new(_("Jabber Account"), "jid", ""); | |
593 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
594 | |
11477 | 595 my_protocol = plugin; |
596 } | |
597 | |
598 GAIM_INIT_PLUGIN(bonjour, init_plugin, info); |