14192
|
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>
|
|
23 #ifndef _WIN32
|
|
24 #include <pwd.h>
|
|
25 #else
|
|
26 #define UNICODE
|
|
27 #include <windows.h>
|
|
28 #include <lm.h>
|
|
29 #endif
|
|
30
|
|
31 #include "internal.h"
|
|
32
|
|
33 #include "account.h"
|
|
34 #include "accountopt.h"
|
|
35 #include "debug.h"
|
|
36 #include "util.h"
|
|
37 #include "version.h"
|
|
38
|
|
39 #include "bonjour.h"
|
|
40 #include "dns_sd.h"
|
|
41 #include "jabber.h"
|
|
42 #include "buddy.h"
|
|
43
|
|
44 /*
|
|
45 * TODO: Should implement an add_buddy callback that removes the buddy
|
|
46 * from the local list. Bonjour manages buddies for you, and
|
|
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.
|
|
50 */
|
|
51
|
|
52 static char *default_firstname;
|
|
53 static char *default_lastname;
|
|
54 static char *default_hostname;
|
|
55
|
|
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
|
|
91 static void
|
|
92 bonjour_login(GaimAccount *account)
|
|
93 {
|
|
94 GaimConnection *gc = gaim_account_get_connection(account);
|
|
95 GaimGroup *bonjour_group = NULL;
|
|
96 BonjourData *bd = NULL;
|
|
97 GaimStatus *status;
|
|
98 GaimPresence *presence;
|
|
99
|
|
100 gc->flags |= GAIM_CONNECTION_HTML;
|
|
101 gc->proto_data = g_new0(BonjourData, 1);
|
|
102 bd = gc->proto_data;
|
|
103
|
|
104 /* Start waiting for jabber connections (iChat style) */
|
|
105 bd->jabber_data = g_new(BonjourJabber, 1);
|
|
106 bd->jabber_data->port = BONJOUR_DEFAULT_PORT_INT;
|
|
107 bd->jabber_data->account = account;
|
|
108
|
|
109 if (bonjour_jabber_start(bd->jabber_data) == -1) {
|
|
110 /* Send a message about the connection error */
|
|
111 gaim_connection_error(gc, _("Unable to listen for incoming IM connections\n"));
|
|
112
|
|
113 /* Free the data */
|
|
114 g_free(bd->jabber_data);
|
|
115 bd->jabber_data = NULL;
|
|
116 return;
|
|
117 }
|
|
118
|
|
119 /* Connect to the mDNS daemon looking for buddies in the LAN */
|
|
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");
|
|
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));
|
|
126 bd->dns_sd_data->port_p2pj = bd->jabber_data->port;
|
|
127 bd->dns_sd_data->phsh = g_strdup("");
|
|
128 bd->dns_sd_data->email = g_strdup(gaim_account_get_string(account, "email", ""));
|
|
129 bd->dns_sd_data->vc = g_strdup("");
|
|
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", ""));
|
|
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"));
|
|
142
|
|
143 bd->dns_sd_data->account = account;
|
|
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 }
|
|
149
|
|
150 /* Create a group for bonjour buddies */
|
|
151 bonjour_group = gaim_group_new(BONJOUR_GROUP_NAME);
|
|
152 gaim_blist_add_group(bonjour_group, NULL);
|
|
153
|
|
154 /* Show the buddy list by telling Gaim we have already connected */
|
|
155 gaim_connection_set_state(gc, GAIM_CONNECTED);
|
|
156 }
|
|
157
|
|
158 static void
|
|
159 bonjour_close(GaimConnection *connection)
|
|
160 {
|
|
161 GaimGroup *bonjour_group;
|
|
162 BonjourData *bd = (BonjourData*)connection->proto_data;
|
|
163
|
|
164 /* Stop looking for buddies in the LAN */
|
|
165 if (bd->dns_sd_data != NULL)
|
|
166 {
|
|
167 bonjour_dns_sd_stop(bd->dns_sd_data);
|
|
168 bonjour_dns_sd_free(bd->dns_sd_data);
|
|
169 }
|
|
170
|
|
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 }
|
|
177
|
|
178 /* Remove all the bonjour buddies */
|
|
179 bonjour_removeallfromlocal(connection);
|
|
180
|
|
181 /* Delete the bonjour group */
|
|
182 bonjour_group = gaim_find_group(BONJOUR_GROUP_NAME);
|
|
183 if (bonjour_group != NULL)
|
|
184 gaim_blist_remove_group(bonjour_group);
|
|
185
|
|
186 }
|
|
187
|
|
188 static const char *
|
|
189 bonjour_list_icon(GaimAccount *account, GaimBuddy *buddy)
|
|
190 {
|
|
191 return BONJOUR_ICON_NAME;
|
|
192 }
|
|
193
|
|
194 static int
|
|
195 bonjour_send_im(GaimConnection *connection, const char *to, const char *msg, GaimMessageFlags flags)
|
|
196 {
|
|
197 if(!to || !msg)
|
|
198 return 0;
|
|
199
|
|
200 return bonjour_jabber_send_message(((BonjourData*)(connection->proto_data))->jabber_data, to, msg);
|
|
201 }
|
|
202
|
|
203 static void
|
|
204 bonjour_set_status(GaimAccount *account, GaimStatus *status)
|
|
205 {
|
|
206 GaimConnection *gc;
|
|
207 BonjourData *bd;
|
|
208 gboolean disconnected;
|
|
209 GaimStatusType *type;
|
|
210 int primitive;
|
|
211 GaimPresence *presence;
|
|
212 const char *message, *bonjour_status;
|
|
213 gchar *stripped;
|
|
214
|
|
215 gc = gaim_account_get_connection(account);
|
|
216 bd = gc->proto_data;
|
|
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 = "";
|
|
225 stripped = gaim_markup_strip_html(message);
|
|
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 */
|
|
234 if (gaim_presence_is_available(presence))
|
|
235 bonjour_status = "avail";
|
|
236 else if (gaim_presence_is_idle(presence))
|
|
237 bonjour_status = "away";
|
|
238 else
|
|
239 bonjour_status = "dnd";
|
|
240
|
|
241 bonjour_dns_sd_send_status(bd->dns_sd_data, bonjour_status, stripped);
|
|
242 g_free(stripped);
|
|
243 }
|
|
244
|
|
245 static GList *
|
|
246 bonjour_status_types(GaimAccount *account)
|
|
247 {
|
|
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,
|
|
255 NULL, TRUE, TRUE, FALSE,
|
|
256 "message", _("Message"),
|
|
257 gaim_value_new(GAIM_TYPE_STRING), NULL);
|
|
258 status_types = g_list_append(status_types, type);
|
|
259
|
|
260 type = gaim_status_type_new_with_attrs(GAIM_STATUS_AWAY,
|
|
261 BONJOUR_STATUS_ID_AWAY,
|
|
262 NULL, TRUE, TRUE, FALSE,
|
|
263 "message", _("Message"),
|
|
264 gaim_value_new(GAIM_TYPE_STRING), NULL);
|
|
265 status_types = g_list_append(status_types, type);
|
|
266
|
|
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
|
|
272 return status_types;
|
|
273 }
|
|
274
|
|
275 static void
|
|
276 bonjour_convo_closed(GaimConnection *connection, const char *who)
|
|
277 {
|
|
278 GaimBuddy *buddy = gaim_find_buddy(connection->account, who);
|
|
279
|
|
280 if (buddy == NULL)
|
|
281 {
|
|
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;
|
|
287 }
|
|
288
|
|
289 bonjour_jabber_close_conversation(((BonjourData*)(connection->proto_data))->jabber_data, buddy);
|
|
290 }
|
|
291
|
|
292 static void
|
|
293 bonjour_list_emblems(GaimBuddy *buddy,
|
|
294 const char **se, const char **sw,
|
|
295 const char **nw, const char **ne)
|
|
296 {
|
|
297 GaimPresence *presence;
|
|
298
|
|
299 presence = gaim_buddy_get_presence(buddy);
|
|
300
|
|
301 if (gaim_presence_is_online(presence) && !gaim_presence_is_available(presence))
|
|
302 *se = "away";
|
|
303 }
|
|
304
|
|
305 static char *
|
|
306 bonjour_status_text(GaimBuddy *buddy)
|
|
307 {
|
|
308 GaimPresence *presence;
|
|
309
|
|
310 presence = gaim_buddy_get_presence(buddy);
|
|
311
|
|
312 if (gaim_presence_is_online(presence) && !gaim_presence_is_available(presence))
|
|
313 return g_strdup("Away");
|
|
314
|
|
315 return NULL;
|
|
316 }
|
|
317
|
|
318 static void
|
|
319 bonjour_tooltip_text(GaimBuddy *buddy, GString *str, gboolean full)
|
|
320 {
|
|
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
|
|
337 g_string_append_printf(str, _("\n<b>Status:</b> %s"), status_description);
|
|
338 if (message != NULL)
|
|
339 g_string_append_printf(str, _("\n<b>Message:</b> %s"), message);
|
|
340 }
|
|
341
|
|
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
|
|
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 NO_BUDDY_ICONS, /* not yet */ /* icon_spec */
|
|
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 */
|
|
413 NULL, /* send_file */
|
|
414 NULL, /* new_xfer */
|
|
415 NULL, /* offline_message */
|
|
416 NULL, /* whiteboard_prpl_ops */
|
14542
|
417 NULL, /* send_raw */
|
14192
|
418 };
|
|
419
|
|
420 static GaimPluginInfo info =
|
|
421 {
|
|
422 GAIM_PLUGIN_MAGIC,
|
|
423 GAIM_MAJOR_VERSION,
|
|
424 GAIM_MINOR_VERSION,
|
|
425 GAIM_PLUGIN_PROTOCOL, /**< type */
|
|
426 NULL, /**< ui_requirement */
|
|
427 0, /**< flags */
|
|
428 NULL, /**< dependencies */
|
|
429 GAIM_PRIORITY_DEFAULT, /**< priority */
|
|
430
|
|
431 "prpl-bonjour", /**< id */
|
|
432 "Bonjour", /**< name */
|
|
433 VERSION, /**< version */
|
|
434 /** summary */
|
|
435 N_("Bonjour Protocol Plugin"),
|
|
436 /** description */
|
|
437 N_("Bonjour Protocol Plugin"),
|
|
438 NULL, /**< author */
|
|
439 GAIM_WEBSITE, /**< homepage */
|
|
440
|
|
441 NULL, /**< load */
|
|
442 plugin_unload, /**< unload */
|
|
443 NULL, /**< destroy */
|
|
444
|
|
445 NULL, /**< ui_info */
|
|
446 &prpl_info, /**< extra_info */
|
|
447 NULL, /**< prefs_info */
|
|
448 NULL
|
|
449 };
|
|
450
|
|
451 static void
|
|
452 initialize_default_account_values()
|
|
453 {
|
|
454 #ifdef _WIN32
|
|
455 char *fullname = NULL;
|
|
456 #else
|
|
457 struct passwd *info;
|
|
458 const char *fullname = NULL;
|
|
459 #endif
|
|
460 char *splitpoint = NULL;
|
|
461 char hostname[255];
|
|
462
|
|
463 #ifndef _WIN32
|
|
464 /* Try to figure out the user's real name */
|
|
465 info = getpwuid(getuid());
|
|
466 if ((info != NULL) && (info->pw_gecos != NULL) && (info->pw_gecos[0] != '\0'))
|
|
467 fullname = info->pw_gecos;
|
|
468 else if ((info != NULL) && (info->pw_name != NULL) && (info->pw_name[0] != '\0'))
|
|
469 fullname = info->pw_name;
|
|
470 else if (((fullname = getlogin()) != NULL) && (fullname[0] != '\0'))
|
|
471 ;
|
|
472 else
|
|
473 fullname = _("Gaim User");
|
|
474
|
|
475 /* Make sure fullname is valid UTF-8. If not, try to convert it. */
|
|
476 if (!g_utf8_validate(fullname, -1, NULL))
|
|
477 {
|
|
478 gchar *tmp;
|
|
479 tmp = g_locale_to_utf8(fullname, -1, NULL, NULL, NULL);
|
|
480 if ((tmp == NULL) || (*tmp == '\0'))
|
|
481 fullname = _("Gaim User");
|
|
482 }
|
|
483
|
|
484 #else
|
|
485 FARPROC myNetUserGetInfo = wgaim_find_and_loadproc("Netapi32.dll",
|
|
486 "NetUserGetInfo");
|
|
487
|
|
488 if (myNetUserGetInfo) {
|
|
489 LPUSER_INFO_10 user_info = NULL;
|
|
490 LPSERVER_INFO_100 server_info = NULL;
|
|
491 wchar_t *servername = NULL;
|
|
492 wchar_t username[UNLEN + 1] = {'\0'};
|
|
493 DWORD dwLenUsername = sizeof(username);
|
|
494 FARPROC myNetServerEnum = wgaim_find_and_loadproc(
|
|
495 "Netapi32.dll", "NetServerEnum");
|
|
496 FARPROC myNetApiBufferFree = wgaim_find_and_loadproc(
|
|
497 "Netapi32.dll", "NetApiBufferFree");
|
|
498
|
|
499 if (myNetServerEnum && myNetApiBufferFree) {
|
|
500 DWORD dwEntriesRead = 0;
|
|
501 DWORD dwTotalEntries = 0;
|
|
502 DWORD dwResumeHandle = 0;
|
|
503
|
|
504 NET_API_STATUS nStatus = (myNetServerEnum)(NULL, 100,
|
|
505 &server_info, MAX_PREFERRED_LENGTH,
|
|
506 &dwEntriesRead, &dwTotalEntries,
|
|
507 SV_TYPE_DOMAIN_CTRL, NULL, &dwResumeHandle);
|
|
508
|
|
509 if ((nStatus == NERR_Success
|
|
510 || nStatus == ERROR_MORE_DATA)
|
|
511 && dwEntriesRead > 0) {
|
|
512 servername = server_info->sv100_name;
|
|
513 } else {
|
|
514 gaim_debug_warning("bonjour", "Unable to look up domain controller. NET_API_STATUS = %d, Entries Read = %d, Total Entries = %d\n", nStatus, dwEntriesRead, dwTotalEntries);
|
|
515 }
|
|
516 }
|
|
517
|
|
518 if (!GetUserNameW(&username, &dwLenUsername)) {
|
|
519 gaim_debug_warning("bonjour",
|
|
520 "Unable to look up username\n");
|
|
521 }
|
|
522
|
|
523 if (username != NULL && *username != '\0'
|
|
524 && (myNetUserGetInfo)(servername, username, 10,
|
|
525 &user_info) == NERR_Success) {
|
|
526 if (user_info != NULL) {
|
|
527 fullname = g_utf16_to_utf8(
|
|
528 user_info->usri10_full_name,
|
|
529 -1, NULL, NULL, NULL);
|
|
530 }
|
|
531 }
|
|
532 if (user_info != NULL)
|
|
533 (myNetApiBufferFree)(user_info);
|
|
534 if (server_info != NULL)
|
|
535 (myNetApiBufferFree)(server_info);
|
|
536 }
|
|
537
|
|
538 if (!fullname)
|
|
539 fullname = g_strdup(_("Gaim User"));
|
|
540 #endif
|
|
541
|
|
542 /* Split the real name into a first and last name */
|
|
543 splitpoint = strchr(fullname, ' ');
|
|
544 if (splitpoint != NULL)
|
|
545 {
|
|
546 default_firstname = g_strndup(fullname, splitpoint - fullname);
|
|
547 default_lastname = g_strdup(&splitpoint[1]);
|
|
548 }
|
|
549 else
|
|
550 {
|
|
551 default_firstname = g_strdup(fullname);
|
|
552 default_lastname = g_strdup("");
|
|
553 }
|
|
554
|
|
555 #ifdef _WIN32
|
|
556 g_free(fullname);
|
|
557 #endif
|
|
558
|
|
559 /* Try to figure out a good host name to use */
|
|
560 /* TODO: Avoid 'localhost,' if possible */
|
|
561 if (gethostname(hostname, 255) != 0) {
|
|
562 gaim_debug_warning("bonjour", "Error %d when getting host name. Using \"localhost.\"\n", errno);
|
|
563 strcpy(hostname, "localhost");
|
|
564 }
|
|
565 default_hostname = g_strdup(hostname);
|
|
566 }
|
|
567
|
|
568 static void
|
|
569 init_plugin(GaimPlugin *plugin)
|
|
570 {
|
|
571 GaimAccountUserSplit *split;
|
|
572 GaimAccountOption *option;
|
|
573
|
|
574 initialize_default_account_values();
|
|
575
|
|
576 /* Creating the user splits */
|
|
577 split = gaim_account_user_split_new(_("Hostname"), default_hostname, '@');
|
|
578 prpl_info.user_splits = g_list_append(prpl_info.user_splits, split);
|
|
579
|
|
580 /* Creating the options for the protocol */
|
|
581 option = gaim_account_option_string_new(_("First name"), "first", default_firstname);
|
|
582 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
|
|
583
|
|
584 option = gaim_account_option_string_new(_("Last name"), "last", default_lastname);
|
|
585 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
|
|
586
|
|
587 option = gaim_account_option_string_new(_("E-mail"), "email", "");
|
|
588 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
|
|
589
|
|
590 option = gaim_account_option_string_new(_("AIM Account"), "AIM", "");
|
|
591 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
|
|
592
|
|
593 option = gaim_account_option_string_new(_("Jabber Account"), "jid", "");
|
|
594 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
|
|
595
|
|
596 my_protocol = plugin;
|
|
597 }
|
|
598
|
|
599 GAIM_INIT_PLUGIN(bonjour, init_plugin, info);
|