Mercurial > pidgin
annotate src/protocols/bonjour/bonjour.c @ 12339:fdac1c5e6c68
[gaim-migrate @ 14643]
Don't show offline bonjour uses as away. Of course, the only time you
would ever have an offline bonjour user is if you add some random person
to your buddy list
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Mon, 05 Dec 2005 03:42:48 +0000 |
parents | 4d3119205a33 |
children | 488a305f9aff |
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" | |
32 #include "account.h" | |
33 #include "accountopt.h" | |
34 #include "version.h" | |
35 #include "debug.h" | |
36 | |
37 #include "bonjour.h" | |
38 #include "dns_sd.h" | |
39 #include "jabber.h" | |
40 #include "buddy.h" | |
41 | |
12339 | 42 /* |
43 * TODO: Should implement an add_buddy callback that removes the buddy | |
44 * from the local list. Bonjour manages buddies for you, and | |
45 * adding someone locally by hand is stupid. | |
46 */ | |
47 | |
11984 | 48 static char *default_firstname; |
49 static char *default_lastname; | |
50 static char *default_hostname; | |
51 | |
11691 | 52 static void |
53 bonjour_removeallfromlocal(GaimConnection *gc) | |
54 { | |
55 GaimAccount *account = gaim_connection_get_account(gc); | |
56 GaimBuddyList *blist; | |
57 GaimBlistNode *gnode, *cnode, *bnode; | |
58 GaimBuddy *buddy; | |
59 | |
60 blist = gaim_get_blist(); | |
61 if (blist == NULL) | |
62 return; | |
63 | |
64 /* Go through and remove all buddies that belong to this account */ | |
65 for (gnode = blist->root; gnode; gnode = gnode->next) | |
66 { | |
67 if (!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
68 continue; | |
69 for (cnode = gnode->child; cnode; cnode = cnode->next) | |
70 { | |
71 if (!GAIM_BLIST_NODE_IS_CONTACT(cnode)) | |
72 continue; | |
73 for (bnode = cnode->child; bnode; bnode = bnode->next) | |
74 { | |
75 if (!GAIM_BLIST_NODE_IS_BUDDY(bnode)) | |
76 continue; | |
77 buddy = (GaimBuddy *)bnode; | |
78 if (buddy->account != account) | |
79 continue; | |
80 gaim_prpl_got_user_status(account, buddy->name, "offline", NULL); | |
81 gaim_blist_remove_buddy(buddy); | |
82 } | |
83 } | |
84 } | |
85 } | |
86 | |
11539 | 87 void |
11837 | 88 bonjour_login(GaimAccount *account) |
11477 | 89 { |
90 GaimConnection *gc = gaim_account_get_connection(account); | |
11539 | 91 GaimGroup *bonjour_group = NULL; |
92 BonjourData *bd = NULL; | |
11837 | 93 GaimStatus *status; |
11834 | 94 GaimPresence *presence; |
11539 | 95 |
11477 | 96 gc->flags |= GAIM_CONNECTION_HTML; |
11984 | 97 gc->proto_data = g_new0(BonjourData, 1); |
11477 | 98 bd = gc->proto_data; |
11539 | 99 |
11829
4669e7461968
[gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents:
11718
diff
changeset
|
100 /* Start waiting for jabber connections (iChat style) */ |
11477 | 101 bd->jabber_data = g_new(BonjourJabber, 1); |
102 bd->jabber_data->port = gaim_account_get_int(account, "port", BONJOUR_DEFAULT_PORT_INT); | |
103 bd->jabber_data->account = account; | |
11539 | 104 |
11477 | 105 if (bonjour_jabber_start(bd->jabber_data) == -1) { |
11829
4669e7461968
[gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents:
11718
diff
changeset
|
106 /* Send a message about the connection error */ |
11984 | 107 gaim_connection_error(gc, _("Unable to listen for incoming IM connections\n")); |
11539 | 108 |
11829
4669e7461968
[gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents:
11718
diff
changeset
|
109 /* Free the data */ |
11477 | 110 g_free(bd->jabber_data); |
11984 | 111 bd->jabber_data = NULL; |
11477 | 112 return; |
113 } | |
11539 | 114 |
11829
4669e7461968
[gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents:
11718
diff
changeset
|
115 /* Connect to the mDNS daemon looking for buddies in the LAN */ |
11477 | 116 bd->dns_sd_data = bonjour_dns_sd_new(); |
117 bd->dns_sd_data->name = (sw_string)gaim_account_get_username(account); | |
118 bd->dns_sd_data->txtvers = g_strdup("1"); | |
119 bd->dns_sd_data->version = g_strdup("1"); | |
11984 | 120 bd->dns_sd_data->first = g_strdup(gaim_account_get_string(account, "first", default_firstname)); |
121 bd->dns_sd_data->last = g_strdup(gaim_account_get_string(account, "last", default_lastname)); | |
11477 | 122 bd->dns_sd_data->port_p2pj = gaim_account_get_int(account, "port", BONJOUR_DEFAULT_PORT_INT); |
123 bd->dns_sd_data->phsh = g_strdup(""); | |
11496 | 124 bd->dns_sd_data->email = g_strdup(gaim_account_get_string(account, "email", "")); |
11477 | 125 bd->dns_sd_data->vc = g_strdup(""); |
126 bd->dns_sd_data->jid = g_strdup(""); | |
127 bd->dns_sd_data->AIM = g_strdup(""); | |
11834 | 128 |
129 status = gaim_account_get_active_status(account); | |
130 presence = gaim_account_get_presence(account); | |
131 if (gaim_presence_is_available(presence)) | |
132 bd->dns_sd_data->status = g_strdup("avail"); | |
133 else if (gaim_presence_is_idle(presence)) | |
134 bd->dns_sd_data->status = g_strdup("away"); | |
135 else | |
136 bd->dns_sd_data->status = g_strdup("dnd"); | |
137 bd->dns_sd_data->msg = g_strdup(gaim_status_get_attr_string(status, "message")); | |
11539 | 138 |
11477 | 139 bd->dns_sd_data->account = account; |
11927 | 140 if (!bonjour_dns_sd_start(bd->dns_sd_data)) |
141 { | |
142 gaim_connection_error(gc, _("Unable to establish connection with the local mDNS server. Is it running?")); | |
143 return; | |
144 } | |
11539 | 145 |
11829
4669e7461968
[gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents:
11718
diff
changeset
|
146 /* Create a group for bonjour buddies */ |
11477 | 147 bonjour_group = gaim_group_new(BONJOUR_GROUP_NAME); |
148 gaim_blist_add_group(bonjour_group, NULL); | |
11539 | 149 |
11829
4669e7461968
[gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents:
11718
diff
changeset
|
150 /* Show the buddy list by telling Gaim we have already connected */ |
11477 | 151 gaim_connection_set_state(gc, GAIM_CONNECTED); |
152 } | |
153 | |
11539 | 154 void |
155 bonjour_close(GaimConnection *connection) | |
11477 | 156 { |
11539 | 157 GaimGroup *bonjour_group = gaim_find_group(BONJOUR_GROUP_NAME); |
158 BonjourData *bd = (BonjourData*)connection->proto_data; | |
159 | |
11829
4669e7461968
[gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents:
11718
diff
changeset
|
160 /* Stop looking for buddies in the LAN */ |
11984 | 161 if (bd->dns_sd_data != NULL) |
162 { | |
11477 | 163 bonjour_dns_sd_stop(bd->dns_sd_data); |
11984 | 164 bonjour_dns_sd_free(bd->dns_sd_data); |
11477 | 165 } |
11539 | 166 |
11984 | 167 if (bd->jabber_data != NULL) |
168 { | |
169 /* Stop waiting for conversations */ | |
170 bonjour_jabber_stop(bd->jabber_data); | |
171 g_free(bd->jabber_data); | |
172 } | |
11539 | 173 |
11829
4669e7461968
[gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents:
11718
diff
changeset
|
174 /* Remove all the bonjour buddies */ |
11691 | 175 bonjour_removeallfromlocal(connection); |
11539 | 176 |
11829
4669e7461968
[gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents:
11718
diff
changeset
|
177 /* Delete the bonjour group */ |
11477 | 178 gaim_blist_remove_group(bonjour_group); |
11539 | 179 |
11477 | 180 } |
181 | |
11539 | 182 const char * |
183 bonjour_list_icon(GaimAccount *account, GaimBuddy *buddy) | |
11477 | 184 { |
185 return BONJOUR_ICON_NAME; | |
186 } | |
187 | |
11539 | 188 int |
12216 | 189 bonjour_send_im(GaimConnection *connection, const char *to, const char *msg, GaimMessageFlags flags) |
11477 | 190 { |
191 if(!to || !msg) | |
192 return 0; | |
11539 | 193 |
11693 | 194 return bonjour_jabber_send_message(((BonjourData*)(connection->proto_data))->jabber_data, to, msg); |
11477 | 195 } |
196 | |
11539 | 197 void |
198 bonjour_set_status(GaimAccount *account, GaimStatus *status) | |
11477 | 199 { |
11496 | 200 GaimConnection *gc; |
201 BonjourData *bd; | |
202 gboolean disconnected; | |
203 GaimStatusType *type; | |
204 int primitive; | |
205 GaimPresence *presence; | |
11841 | 206 const char *message, *bonjour_status; |
11477 | 207 |
11839 | 208 gc = gaim_account_get_connection(account); |
209 bd = gc->proto_data; | |
11496 | 210 disconnected = gaim_account_is_disconnected(account); |
211 type = gaim_status_get_type(status); | |
212 primitive = gaim_status_type_get_primitive(type); | |
213 presence = gaim_account_get_presence(account); | |
214 | |
215 message = gaim_status_get_attr_string(status, "message"); | |
216 if (message == NULL) | |
217 message = ""; | |
218 | |
219 /* | |
220 * The three possible status for Bonjour are | |
221 * -available ("avail") | |
222 * -idle ("away") | |
223 * -away ("dnd") | |
224 * Each of them can have an optional message. | |
225 */ | |
11835 | 226 if (gaim_presence_is_available(presence)) |
11841 | 227 bonjour_status = "avail"; |
11835 | 228 else if (gaim_presence_is_idle(presence)) |
11841 | 229 bonjour_status = "away"; |
11835 | 230 else |
11841 | 231 bonjour_status = "dnd"; |
11477 | 232 |
11841 | 233 bonjour_dns_sd_send_status(bd->dns_sd_data, bonjour_status, message); |
11477 | 234 } |
235 | |
11496 | 236 static GList * |
237 bonjour_status_types(GaimAccount *account) | |
11477 | 238 { |
11496 | 239 GList *status_types = NULL; |
240 GaimStatusType *type; | |
241 | |
242 g_return_val_if_fail(account != NULL, NULL); | |
243 | |
244 type = gaim_status_type_new_full(GAIM_STATUS_OFFLINE, | |
245 BONJOUR_STATUS_ID_OFFLINE, | |
246 _("Offline"), TRUE, TRUE, FALSE); | |
247 status_types = g_list_append(status_types, type); | |
11477 | 248 |
11496 | 249 type = gaim_status_type_new_with_attrs(GAIM_STATUS_AVAILABLE, |
250 BONJOUR_STATUS_ID_AVAILABLE, | |
251 _("Available"), TRUE, TRUE, FALSE, | |
252 "message", _("Message"), | |
253 gaim_value_new(GAIM_TYPE_STRING), NULL); | |
254 status_types = g_list_append(status_types, type); | |
11477 | 255 |
11496 | 256 type = gaim_status_type_new_with_attrs(GAIM_STATUS_AWAY, |
257 BONJOUR_STATUS_ID_AWAY, | |
258 _("Away"), TRUE, TRUE, FALSE, | |
259 "message", _("Message"), | |
260 gaim_value_new(GAIM_TYPE_STRING), NULL); | |
261 status_types = g_list_append(status_types, type); | |
262 | |
263 return status_types; | |
11477 | 264 } |
265 | |
11539 | 266 static void |
267 bonjour_convo_closed(GaimConnection *connection, const char *who) | |
11477 | 268 { |
11539 | 269 GaimBuddy *buddy = gaim_find_buddy(connection->account, who); |
270 | |
11966 | 271 if (buddy == NULL) |
272 /* | |
273 * This buddy is not in our buddy list, and therefore does not really | |
274 * exist, so we won't have any data about them. | |
275 */ | |
276 return; | |
277 | |
11477 | 278 bonjour_jabber_close_conversation(((BonjourData*)(connection->proto_data))->jabber_data, buddy); |
279 } | |
280 | |
11539 | 281 static void |
282 bonjour_list_emblems(GaimBuddy *buddy, | |
11496 | 283 const char **se, const char **sw, |
284 const char **nw,const char **ne) | |
11477 | 285 { |
11496 | 286 GaimPresence *presence; |
287 | |
288 presence = gaim_buddy_get_presence(buddy); | |
289 | |
12339 | 290 if (gaim_presence_is_online(presence) && !gaim_presence_is_available(presence)) |
11496 | 291 *se = "away"; |
292 } | |
293 | |
11539 | 294 static char * |
295 bonjour_status_text(GaimBuddy *buddy) | |
11496 | 296 { |
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 return g_strdup("Away"); |
12339 | 303 |
304 return NULL; | |
11477 | 305 } |
306 | |
11539 | 307 static char * |
308 bonjour_tooltip_text(GaimBuddy *buddy) | |
11477 | 309 { |
11496 | 310 GString *ret; |
311 GaimPresence *presence; | |
312 GaimStatus *status; | |
313 const char *status_description; | |
314 const char *message; | |
315 | |
316 presence = gaim_buddy_get_presence(buddy); | |
317 status = gaim_presence_get_active_status(presence); | |
318 message = gaim_status_get_attr_string(status, "message"); | |
319 | |
320 if (gaim_presence_is_available(presence)) | |
321 status_description = gaim_status_get_name(status); | |
322 else if (gaim_presence_is_idle(presence)) | |
323 status_description = _("Idle"); | |
324 else | |
325 status_description = gaim_status_get_name(status); | |
326 | |
327 ret = g_string_new(""); | |
11519 | 328 g_string_append_printf(ret, _("\n<b>Status:</b> %s"), status_description); |
329 if (message != NULL) | |
330 g_string_append_printf(ret, _("\n<b>Message:</b> %s"), message); | |
11496 | 331 |
332 return g_string_free(ret, FALSE); | |
11477 | 333 } |
334 | |
11984 | 335 static gboolean |
336 plugin_unload(GaimPlugin *plugin) | |
337 { | |
338 g_free(default_firstname); | |
339 g_free(default_lastname); | |
340 g_free(default_hostname); | |
341 | |
342 return TRUE; | |
343 } | |
344 | |
11477 | 345 static GaimPlugin *my_protocol = NULL; |
346 | |
347 static GaimPluginProtocolInfo prpl_info = | |
348 { | |
349 OPT_PROTO_NO_PASSWORD, | |
350 NULL, /* user_splits */ | |
351 NULL, /* protocol_options */ | |
352 {"png", 0, 0, 96, 96, GAIM_ICON_SCALE_DISPLAY}, /* icon_spec */ | |
353 bonjour_list_icon, /* list_icon */ | |
354 bonjour_list_emblems, /* list_emblems */ | |
355 bonjour_status_text, /* status_text */ | |
356 bonjour_tooltip_text, /* tooltip_text */ | |
357 bonjour_status_types, /* status_types */ | |
358 NULL, /* blist_node_menu */ | |
359 NULL, /* chat_info */ | |
360 NULL, /* chat_info_defaults */ | |
361 bonjour_login, /* login */ | |
362 bonjour_close, /* close */ | |
363 bonjour_send_im, /* send_im */ | |
364 NULL, /* set_info */ | |
365 NULL, /* send_typing */ | |
366 NULL, /* get_info */ | |
367 bonjour_set_status, /* set_status */ | |
368 NULL, /* set_idle */ | |
369 NULL, /* change_passwd */ | |
370 NULL, /* add_buddy */ | |
371 NULL, /* add_buddies */ | |
372 NULL, /* remove_buddy */ | |
373 NULL, /* remove_buddies */ | |
374 NULL, /* add_permit */ | |
375 NULL, /* add_deny */ | |
376 NULL, /* rem_permit */ | |
377 NULL, /* rem_deny */ | |
378 NULL, /* set_permit_deny */ | |
379 NULL, /* join_chat */ | |
380 NULL, /* reject_chat */ | |
381 NULL, /* get_chat_name */ | |
382 NULL, /* chat_invite */ | |
383 NULL, /* chat_leave */ | |
384 NULL, /* chat_whisper */ | |
385 NULL, /* chat_send */ | |
386 NULL, /* keepalive */ | |
387 NULL, /* register_user */ | |
388 NULL, /* get_cb_info */ | |
389 NULL, /* get_cb_away */ | |
390 NULL, /* alias_buddy */ | |
391 NULL, /* group_buddy */ | |
392 NULL, /* rename_group */ | |
393 NULL, /* buddy_free */ | |
394 bonjour_convo_closed, /* convo_closed */ | |
395 NULL, /* normalize */ | |
396 NULL, /* set_buddy_icon */ | |
397 NULL, /* remove_group */ | |
398 NULL, /* get_cb_real_name */ | |
399 NULL, /* set_chat_topic */ | |
400 NULL, /* find_blist_chat */ | |
401 NULL, /* roomlist_get_list */ | |
402 NULL, /* roomlist_cancel */ | |
403 NULL, /* roomlist_expand_category */ | |
404 NULL, /* can_receive_file */ | |
12143
cbebda5f019c
[gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents:
12003
diff
changeset
|
405 NULL, /* send_file */ |
cbebda5f019c
[gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents:
12003
diff
changeset
|
406 NULL /* new_xfer */ |
11477 | 407 }; |
408 | |
409 static GaimPluginInfo info = | |
410 { | |
411 GAIM_PLUGIN_MAGIC, | |
412 GAIM_MAJOR_VERSION, | |
413 GAIM_MINOR_VERSION, | |
414 GAIM_PLUGIN_PROTOCOL, /**< type */ | |
415 NULL, /**< ui_requirement */ | |
416 0, /**< flags */ | |
417 NULL, /**< dependencies */ | |
418 GAIM_PRIORITY_DEFAULT, /**< priority */ | |
419 | |
420 "prpl-bonjour", /**< id */ | |
421 "Bonjour", /**< name */ | |
422 VERSION, /**< version */ | |
423 /** summary */ | |
424 N_("Bonjour Protocol Plugin"), | |
425 /** description */ | |
426 N_("Bonjour Protocol Plugin"), | |
427 NULL, /**< author */ | |
428 GAIM_WEBSITE, /**< homepage */ | |
429 | |
430 NULL, /**< load */ | |
11984 | 431 plugin_unload, /**< unload */ |
11477 | 432 NULL, /**< destroy */ |
433 | |
434 NULL, /**< ui_info */ | |
435 &prpl_info, /**< extra_info */ | |
436 NULL, /**< prefs_info */ | |
437 NULL | |
438 }; | |
439 | |
440 static void | |
11984 | 441 initialize_default_account_values() |
442 { | |
443 char *fullname = NULL; | |
444 char *splitpoint = NULL; | |
445 char hostname[255]; | |
12003
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
446 #ifndef _WIN32 |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
447 struct passwd *info; |
11984 | 448 |
449 /* Try to figure out the user's real name */ | |
450 info = getpwuid(getuid()); | |
451 if ((info != NULL) && (info->pw_gecos != NULL) && (info->pw_gecos[0] != '\0')) | |
452 fullname = info->pw_gecos; | |
453 else if ((info != NULL) && (info->pw_name != NULL) && (info->pw_name[0] != '\0')) | |
454 fullname = info->pw_name; | |
455 else if (((fullname = getlogin()) != NULL) && (fullname[0] != '\0')) | |
456 ; | |
457 else | |
458 fullname = _("Gaim User"); | |
459 | |
12003
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
460 #else |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
461 FARPROC myNetUserGetInfo = wgaim_find_and_loadproc("Netapi32.dll", |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
462 "NetUserGetInfo"); |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
463 |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
464 if (myNetUserGetInfo) { |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
465 LPUSER_INFO_10 user_info = NULL; |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
466 LPSERVER_INFO_100 server_info = NULL; |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
467 wchar_t *servername = NULL; |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
468 wchar_t username[UNLEN + 1] = {'\0'}; |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
469 DWORD dwLenUsername = sizeof(username); |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
470 FARPROC myNetServerEnum = wgaim_find_and_loadproc( |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
471 "Netapi32.dll", "NetServerEnum"); |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
472 FARPROC myNetApiBufferFree = wgaim_find_and_loadproc( |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
473 "Netapi32.dll", "NetApiBufferFree"); |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
474 |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
475 if (myNetServerEnum && myNetApiBufferFree) { |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
476 DWORD dwEntriesRead = 0; |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
477 DWORD dwTotalEntries = 0; |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
478 DWORD dwResumeHandle = 0; |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
479 |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
480 NET_API_STATUS nStatus = (myNetServerEnum)(NULL, 100, |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
481 &server_info, MAX_PREFERRED_LENGTH, |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
482 &dwEntriesRead, &dwTotalEntries, |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
483 SV_TYPE_DOMAIN_CTRL, NULL, &dwResumeHandle); |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
484 |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
485 if ((nStatus == NERR_Success |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
486 || nStatus == ERROR_MORE_DATA) |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
487 && dwEntriesRead > 0) { |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
488 servername = server_info->sv100_name; |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
489 } else { |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
490 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
|
491 } |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
492 } |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
493 |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
494 if (!GetUserNameW(&username, &dwLenUsername)) { |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
495 gaim_debug_warning("bonjour", |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
496 "Unable to look up username\n"); |
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 |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
499 if (username != NULL && *username != '\0' |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
500 && (myNetUserGetInfo)(servername, username, 10, |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
501 &user_info) == NERR_Success) { |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
502 if (user_info != NULL) { |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
503 fullname = g_utf16_to_utf8( |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
504 user_info->usri10_full_name, |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
505 -1, NULL, NULL, NULL); |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
506 } |
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 (user_info != NULL) |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
509 (myNetApiBufferFree)(user_info); |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
510 if (server_info != NULL) |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
511 (myNetApiBufferFree)(server_info); |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
512 } |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
513 |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
514 if (!fullname) |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
515 fullname = g_strdup(_("Gaim User")); |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
516 #endif |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
517 |
11984 | 518 /* Split the real name into a first and last name */ |
519 splitpoint = strchr(fullname, ' '); | |
520 if (splitpoint != NULL) | |
521 { | |
522 default_firstname = g_strndup(fullname, splitpoint - fullname); | |
523 default_lastname = g_strdup(&splitpoint[1]); | |
524 } | |
525 else | |
526 { | |
527 default_firstname = g_strdup(fullname); | |
528 default_lastname = g_strdup(""); | |
529 } | |
530 | |
12003
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
531 #ifdef _WIN32 |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
532 g_free(fullname); |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
533 #endif |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
534 |
11984 | 535 /* Try to figure out a good host name to use */ |
536 /* TODO: Avoiding 'localhost,' if possible */ | |
537 if (gethostname(hostname, 255) != 0) { | |
12003
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
538 gaim_debug_warning("bonjour", "Error %d when getting host name. Using \"localhost.\"\n", errno); |
11984 | 539 strcpy(hostname, "localhost"); |
540 } | |
541 default_hostname = g_strdup(hostname); | |
542 } | |
543 | |
544 static void | |
11477 | 545 init_plugin(GaimPlugin *plugin) |
546 { | |
547 GaimAccountUserSplit *split; | |
548 GaimAccountOption *option; | |
549 | |
11984 | 550 initialize_default_account_values(); |
11477 | 551 |
11829
4669e7461968
[gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents:
11718
diff
changeset
|
552 /* Creating the user splits */ |
11984 | 553 split = gaim_account_user_split_new(_("Host name"), default_hostname, '@'); |
11477 | 554 prpl_info.user_splits = g_list_append(prpl_info.user_splits, split); |
11539 | 555 |
11829
4669e7461968
[gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents:
11718
diff
changeset
|
556 /* Creating the options for the protocol */ |
11477 | 557 option = gaim_account_option_int_new(_("Port"), "port", 5298); |
558 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
559 | |
11984 | 560 option = gaim_account_option_string_new(_("First name"), "first", default_firstname); |
11477 | 561 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); |
562 | |
11984 | 563 option = gaim_account_option_string_new(_("Last name"), "last", default_lastname); |
11477 | 564 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); |
565 | |
566 option = gaim_account_option_string_new(_("Email"), "email", ""); | |
567 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
11539 | 568 |
11477 | 569 my_protocol = plugin; |
570 } | |
571 | |
572 GAIM_INIT_PLUGIN(bonjour, init_plugin, info); |