Mercurial > pidgin.yaz
annotate src/protocols/bonjour/bonjour.c @ 13296:263c2db78f77
[gaim-migrate @ 15662]
Kill the other media_prpl_ops.
committer: Tailor Script <tailor@pidgin.im>
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Thu, 16 Feb 2006 02:00:25 +0000 |
parents | a0dfbd5c3b03 |
children | cfc2f7fcb3dd |
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); |
106 bd->jabber_data->port = gaim_account_get_int(account, "port", BONJOUR_DEFAULT_PORT_INT); | |
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)); | |
11477 | 126 bd->dns_sd_data->port_p2pj = gaim_account_get_int(account, "port", BONJOUR_DEFAULT_PORT_INT); |
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(""); |
130 bd->dns_sd_data->jid = g_strdup(""); | |
131 bd->dns_sd_data->AIM = g_strdup(""); | |
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 */ | |
359 {"png", 0, 0, 96, 96, GAIM_ICON_SCALE_DISPLAY}, /* icon_spec */ | |
360 bonjour_list_icon, /* list_icon */ | |
361 bonjour_list_emblems, /* list_emblems */ | |
362 bonjour_status_text, /* status_text */ | |
363 bonjour_tooltip_text, /* tooltip_text */ | |
364 bonjour_status_types, /* status_types */ | |
365 NULL, /* blist_node_menu */ | |
366 NULL, /* chat_info */ | |
367 NULL, /* chat_info_defaults */ | |
368 bonjour_login, /* login */ | |
369 bonjour_close, /* close */ | |
370 bonjour_send_im, /* send_im */ | |
371 NULL, /* set_info */ | |
372 NULL, /* send_typing */ | |
373 NULL, /* get_info */ | |
374 bonjour_set_status, /* set_status */ | |
375 NULL, /* set_idle */ | |
376 NULL, /* change_passwd */ | |
377 NULL, /* add_buddy */ | |
378 NULL, /* add_buddies */ | |
379 NULL, /* remove_buddy */ | |
380 NULL, /* remove_buddies */ | |
381 NULL, /* add_permit */ | |
382 NULL, /* add_deny */ | |
383 NULL, /* rem_permit */ | |
384 NULL, /* rem_deny */ | |
385 NULL, /* set_permit_deny */ | |
386 NULL, /* join_chat */ | |
387 NULL, /* reject_chat */ | |
388 NULL, /* get_chat_name */ | |
389 NULL, /* chat_invite */ | |
390 NULL, /* chat_leave */ | |
391 NULL, /* chat_whisper */ | |
392 NULL, /* chat_send */ | |
393 NULL, /* keepalive */ | |
394 NULL, /* register_user */ | |
395 NULL, /* get_cb_info */ | |
396 NULL, /* get_cb_away */ | |
397 NULL, /* alias_buddy */ | |
398 NULL, /* group_buddy */ | |
399 NULL, /* rename_group */ | |
400 NULL, /* buddy_free */ | |
401 bonjour_convo_closed, /* convo_closed */ | |
402 NULL, /* normalize */ | |
403 NULL, /* set_buddy_icon */ | |
404 NULL, /* remove_group */ | |
405 NULL, /* get_cb_real_name */ | |
406 NULL, /* set_chat_topic */ | |
407 NULL, /* find_blist_chat */ | |
408 NULL, /* roomlist_get_list */ | |
409 NULL, /* roomlist_cancel */ | |
410 NULL, /* roomlist_expand_category */ | |
411 NULL, /* can_receive_file */ | |
12143
cbebda5f019c
[gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents:
12003
diff
changeset
|
412 NULL, /* send_file */ |
12607 | 413 NULL, /* new_xfer */ |
12650 | 414 NULL, /* offline_message */ |
12607 | 415 NULL, /* whiteboard_prpl_ops */ |
11477 | 416 }; |
417 | |
418 static GaimPluginInfo info = | |
419 { | |
420 GAIM_PLUGIN_MAGIC, | |
421 GAIM_MAJOR_VERSION, | |
422 GAIM_MINOR_VERSION, | |
423 GAIM_PLUGIN_PROTOCOL, /**< type */ | |
424 NULL, /**< ui_requirement */ | |
425 0, /**< flags */ | |
426 NULL, /**< dependencies */ | |
427 GAIM_PRIORITY_DEFAULT, /**< priority */ | |
428 | |
429 "prpl-bonjour", /**< id */ | |
430 "Bonjour", /**< name */ | |
431 VERSION, /**< version */ | |
432 /** summary */ | |
433 N_("Bonjour Protocol Plugin"), | |
434 /** description */ | |
435 N_("Bonjour Protocol Plugin"), | |
436 NULL, /**< author */ | |
437 GAIM_WEBSITE, /**< homepage */ | |
438 | |
439 NULL, /**< load */ | |
11984 | 440 plugin_unload, /**< unload */ |
11477 | 441 NULL, /**< destroy */ |
442 | |
443 NULL, /**< ui_info */ | |
444 &prpl_info, /**< extra_info */ | |
445 NULL, /**< prefs_info */ | |
446 NULL | |
447 }; | |
448 | |
449 static void | |
11984 | 450 initialize_default_account_values() |
451 { | |
13191 | 452 #ifdef _WIN32 |
11984 | 453 char *fullname = NULL; |
13191 | 454 #else |
455 struct passwd *info; | |
456 const char *fullname = NULL; | |
457 #endif | |
11984 | 458 char *splitpoint = NULL; |
459 char hostname[255]; | |
13191 | 460 |
12003
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
461 #ifndef _WIN32 |
11984 | 462 /* Try to figure out the user's real name */ |
463 info = getpwuid(getuid()); | |
464 if ((info != NULL) && (info->pw_gecos != NULL) && (info->pw_gecos[0] != '\0')) | |
465 fullname = info->pw_gecos; | |
466 else if ((info != NULL) && (info->pw_name != NULL) && (info->pw_name[0] != '\0')) | |
467 fullname = info->pw_name; | |
468 else if (((fullname = getlogin()) != NULL) && (fullname[0] != '\0')) | |
469 ; | |
470 else | |
471 fullname = _("Gaim User"); | |
472 | |
13075 | 473 /* Make sure fullname is valid UTF-8. If not, try to convert it. */ |
474 if (!g_utf8_validate(fullname, -1, NULL)) | |
475 { | |
476 gchar *tmp; | |
477 tmp = g_locale_to_utf8(fullname, -1, NULL, NULL, NULL); | |
478 if ((tmp == NULL) || (*tmp == '\0')) | |
479 fullname = _("Gaim User"); | |
480 } | |
481 | |
12003
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
482 #else |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
483 FARPROC myNetUserGetInfo = wgaim_find_and_loadproc("Netapi32.dll", |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
484 "NetUserGetInfo"); |
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 if (myNetUserGetInfo) { |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
487 LPUSER_INFO_10 user_info = NULL; |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
488 LPSERVER_INFO_100 server_info = NULL; |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
489 wchar_t *servername = NULL; |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
490 wchar_t username[UNLEN + 1] = {'\0'}; |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
491 DWORD dwLenUsername = sizeof(username); |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
492 FARPROC myNetServerEnum = wgaim_find_and_loadproc( |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
493 "Netapi32.dll", "NetServerEnum"); |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
494 FARPROC myNetApiBufferFree = wgaim_find_and_loadproc( |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
495 "Netapi32.dll", "NetApiBufferFree"); |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
496 |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
497 if (myNetServerEnum && myNetApiBufferFree) { |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
498 DWORD dwEntriesRead = 0; |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
499 DWORD dwTotalEntries = 0; |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
500 DWORD dwResumeHandle = 0; |
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 NET_API_STATUS nStatus = (myNetServerEnum)(NULL, 100, |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
503 &server_info, MAX_PREFERRED_LENGTH, |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
504 &dwEntriesRead, &dwTotalEntries, |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
505 SV_TYPE_DOMAIN_CTRL, NULL, &dwResumeHandle); |
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 if ((nStatus == NERR_Success |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
508 || nStatus == ERROR_MORE_DATA) |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
509 && dwEntriesRead > 0) { |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
510 servername = server_info->sv100_name; |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
511 } else { |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
512 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
|
513 } |
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 if (!GetUserNameW(&username, &dwLenUsername)) { |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
517 gaim_debug_warning("bonjour", |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
518 "Unable to look up username\n"); |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
519 } |
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 if (username != NULL && *username != '\0' |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
522 && (myNetUserGetInfo)(servername, username, 10, |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
523 &user_info) == NERR_Success) { |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
524 if (user_info != NULL) { |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
525 fullname = g_utf16_to_utf8( |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
526 user_info->usri10_full_name, |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
527 -1, NULL, NULL, NULL); |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
528 } |
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 if (user_info != NULL) |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
531 (myNetApiBufferFree)(user_info); |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
532 if (server_info != NULL) |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
533 (myNetApiBufferFree)(server_info); |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
534 } |
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 if (!fullname) |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
537 fullname = g_strdup(_("Gaim User")); |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
538 #endif |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
539 |
11984 | 540 /* Split the real name into a first and last name */ |
541 splitpoint = strchr(fullname, ' '); | |
542 if (splitpoint != NULL) | |
543 { | |
544 default_firstname = g_strndup(fullname, splitpoint - fullname); | |
545 default_lastname = g_strdup(&splitpoint[1]); | |
546 } | |
547 else | |
548 { | |
549 default_firstname = g_strdup(fullname); | |
550 default_lastname = g_strdup(""); | |
551 } | |
552 | |
12003
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
553 #ifdef _WIN32 |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
554 g_free(fullname); |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
555 #endif |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
556 |
11984 | 557 /* Try to figure out a good host name to use */ |
558 /* TODO: Avoiding 'localhost,' if possible */ | |
559 if (gethostname(hostname, 255) != 0) { | |
12003
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
560 gaim_debug_warning("bonjour", "Error %d when getting host name. Using \"localhost.\"\n", errno); |
11984 | 561 strcpy(hostname, "localhost"); |
562 } | |
563 default_hostname = g_strdup(hostname); | |
564 } | |
565 | |
566 static void | |
11477 | 567 init_plugin(GaimPlugin *plugin) |
568 { | |
569 GaimAccountUserSplit *split; | |
570 GaimAccountOption *option; | |
571 | |
11984 | 572 initialize_default_account_values(); |
11477 | 573 |
11829
4669e7461968
[gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents:
11718
diff
changeset
|
574 /* Creating the user splits */ |
12489 | 575 split = gaim_account_user_split_new(_("Hostname"), default_hostname, '@'); |
11477 | 576 prpl_info.user_splits = g_list_append(prpl_info.user_splits, split); |
11539 | 577 |
11829
4669e7461968
[gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents:
11718
diff
changeset
|
578 /* Creating the options for the protocol */ |
11477 | 579 option = gaim_account_option_int_new(_("Port"), "port", 5298); |
580 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
581 | |
11984 | 582 option = gaim_account_option_string_new(_("First name"), "first", default_firstname); |
11477 | 583 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); |
584 | |
11984 | 585 option = gaim_account_option_string_new(_("Last name"), "last", default_lastname); |
11477 | 586 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); |
587 | |
588 option = gaim_account_option_string_new(_("Email"), "email", ""); | |
589 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
11539 | 590 |
11477 | 591 my_protocol = plugin; |
592 } | |
593 | |
594 GAIM_INIT_PLUGIN(bonjour, init_plugin, info); |