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