Mercurial > pidgin
annotate src/protocols/bonjour/bonjour.c @ 12645:fc28451f5d96
[gaim-migrate @ 14983]
SF Patch #1314512 from Sadrul (who has a patch for everything)
"This patch introduces a flag for protocol plugins that
support offline messages (like Y!M and ICQ). This was
encouraged by the following conversation:
<sadrul> should offline buddies be listed/enabled in
the send-to menu?
<rekkanoryo> i would think only for protocols that
support offline messaging, if it's indicated that the
buddy is offline
-- <snip> --
<Bleeter> sadrul: personally, I'd like to see a
'supports offline' flag of some description
<Bleeter> one could then redirect (via plugins) through
email or alternative methods
<Bleeter> just a thought
<Paco-Paco> yeah, that sounds like a reasonble thing to have
This patch uses this flag to disable the buddies in the
send-to menu who are offline and the protocol doesn't
support offline messages."
I made this make the label insensitive instead of the whole menuitem. This
should address SimGuy's concerns about inconsistency (i.e. you could create a
conversation with someone via the buddy list that you couldn't create via the
Send To menu). I also hacked up some voodoo to show the label as sensitive when
moused-over, as that looks better (given the label-insensitive thing is itself a
hack). I think this works quite well.
BUG NOTE:
This makes more obvious an existing bug. The Send To menu isn't updated when
buddies sign on or off or change status (at least under some circumstances).
We need to fix that anyway, so I'm not going to let it hold up this commit.
Switching tabs will clear it up. I'm thinking we just might want to build the
contents of that menu when it is selected. That would save us a mess of
inefficient signal callbacks that update the Send To menus in open windows all
the time.
AIM NOTE:
This assumes that AIM can't offline message. That's not strictly true. You can
message invisible users on AIM. However, by design, we can't tell when a user
is invisible without resorting to dirty hackery. In practice, this isn't a
problem, as you can still select the AIM user from the menu. And really, how
often will you be choosing the Invisible contact, rather than the user going
Invisible in the middle of a conversation or IMing you while they're Invisible?
JABBER NOTE:
This assumes that Jabber can always offline message. This isn't strictly true.
Sadrul said:
I have updated Jabber according to this link which seems to
talk about how to determine the existence offline-message
support in a server:
http://www.jabber.org/jeps/jep-0013.html#discover
However, jabber.org doesn't seem to send the required
info. So I am not sure about it.
He later said:
I talked to Nathan and he said offline message support is
mostly assumed for most jabber servers. GTalk doesn't yet
support it, but they are working on it. So I have made
jabber to always return TRUE.
If there is truly no way to detect offline messaging capability, then this is
an acceptable solution. We could special case Google Talk because of its
popularity, and remove that later. It's probably not worth it though.
MSN NOTE:
This assumes that MSN can never offline message. That's effectively true, but
to be technically correct, MSN can offline message if there's already a
switchboard conversation open with a user. We could write an offline_message
function in the MSN prpl to detect that, but it'd be of limited usefulness,
especially given that under most circumstances (where this might matter), the
switchboard connection will be closed almost immediately.
CVS NOTE:
I'm writing to share a tragic little story.
I have a PC that I use for Gaim development. One day, I was writing a commit
message on it, when all of a suddent it went berserk. The screen started
flashing, and the whole commit message just disappeared. All of it. And it was
a good commit message! I had to cram and rewrite it really quickly. Needless to
say, my rushed commit message wasn't nearly as good, and I blame the PC for that.
Seriously, though, what kind of version control system loses your commit
message on a broken connection to the server? Stupid!
committer: Tailor Script <tailor@pidgin.im>
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Fri, 23 Dec 2005 19:26:04 +0000 |
parents | 78048f8af66f |
children | 2926e3c3185e |
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 | |
12443 | 87 static 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 | |
12443 | 154 static void |
11539 | 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 | |
12443 | 182 static const char * |
11539 | 183 bonjour_list_icon(GaimAccount *account, GaimBuddy *buddy) |
11477 | 184 { |
185 return BONJOUR_ICON_NAME; | |
186 } | |
187 | |
12443 | 188 static 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 | |
12443 | 197 static void |
11539 | 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, | |
12595
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12489
diff
changeset
|
246 NULL, TRUE, TRUE, FALSE); |
11496 | 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, | |
12595
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12489
diff
changeset
|
251 NULL, TRUE, TRUE, FALSE, |
11496 | 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, | |
12595
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12489
diff
changeset
|
258 NULL, TRUE, TRUE, FALSE, |
11496 | 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) |
12595
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12489
diff
changeset
|
272 { |
11966 | 273 /* |
274 * This buddy is not in our buddy list, and therefore does not really | |
275 * exist, so we won't have any data about them. | |
276 */ | |
277 return; | |
12595
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12489
diff
changeset
|
278 } |
11966 | 279 |
11477 | 280 bonjour_jabber_close_conversation(((BonjourData*)(connection->proto_data))->jabber_data, buddy); |
281 } | |
282 | |
11539 | 283 static void |
284 bonjour_list_emblems(GaimBuddy *buddy, | |
11496 | 285 const char **se, const char **sw, |
12595
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12489
diff
changeset
|
286 const char **nw, const char **ne) |
11477 | 287 { |
11496 | 288 GaimPresence *presence; |
289 | |
290 presence = gaim_buddy_get_presence(buddy); | |
291 | |
12339 | 292 if (gaim_presence_is_online(presence) && !gaim_presence_is_available(presence)) |
11496 | 293 *se = "away"; |
294 } | |
295 | |
11539 | 296 static char * |
297 bonjour_status_text(GaimBuddy *buddy) | |
11496 | 298 { |
299 GaimPresence *presence; | |
300 | |
301 presence = gaim_buddy_get_presence(buddy); | |
302 | |
12339 | 303 if (gaim_presence_is_online(presence) && !gaim_presence_is_available(presence)) |
11496 | 304 return g_strdup("Away"); |
12339 | 305 |
306 return NULL; | |
11477 | 307 } |
308 | |
11539 | 309 static char * |
310 bonjour_tooltip_text(GaimBuddy *buddy) | |
11477 | 311 { |
11496 | 312 GString *ret; |
313 GaimPresence *presence; | |
314 GaimStatus *status; | |
315 const char *status_description; | |
316 const char *message; | |
317 | |
318 presence = gaim_buddy_get_presence(buddy); | |
319 status = gaim_presence_get_active_status(presence); | |
320 message = gaim_status_get_attr_string(status, "message"); | |
321 | |
322 if (gaim_presence_is_available(presence)) | |
323 status_description = gaim_status_get_name(status); | |
324 else if (gaim_presence_is_idle(presence)) | |
325 status_description = _("Idle"); | |
326 else | |
327 status_description = gaim_status_get_name(status); | |
328 | |
329 ret = g_string_new(""); | |
11519 | 330 g_string_append_printf(ret, _("\n<b>Status:</b> %s"), status_description); |
331 if (message != NULL) | |
332 g_string_append_printf(ret, _("\n<b>Message:</b> %s"), message); | |
11496 | 333 |
334 return g_string_free(ret, FALSE); | |
11477 | 335 } |
336 | |
11984 | 337 static gboolean |
338 plugin_unload(GaimPlugin *plugin) | |
339 { | |
340 g_free(default_firstname); | |
341 g_free(default_lastname); | |
342 g_free(default_hostname); | |
343 | |
344 return TRUE; | |
345 } | |
346 | |
11477 | 347 static GaimPlugin *my_protocol = NULL; |
348 | |
349 static GaimPluginProtocolInfo prpl_info = | |
350 { | |
351 OPT_PROTO_NO_PASSWORD, | |
352 NULL, /* user_splits */ | |
353 NULL, /* protocol_options */ | |
354 {"png", 0, 0, 96, 96, GAIM_ICON_SCALE_DISPLAY}, /* icon_spec */ | |
355 bonjour_list_icon, /* list_icon */ | |
356 bonjour_list_emblems, /* list_emblems */ | |
357 bonjour_status_text, /* status_text */ | |
358 bonjour_tooltip_text, /* tooltip_text */ | |
359 bonjour_status_types, /* status_types */ | |
360 NULL, /* blist_node_menu */ | |
361 NULL, /* chat_info */ | |
362 NULL, /* chat_info_defaults */ | |
363 bonjour_login, /* login */ | |
364 bonjour_close, /* close */ | |
365 bonjour_send_im, /* send_im */ | |
366 NULL, /* set_info */ | |
367 NULL, /* send_typing */ | |
368 NULL, /* get_info */ | |
369 bonjour_set_status, /* set_status */ | |
370 NULL, /* set_idle */ | |
371 NULL, /* change_passwd */ | |
372 NULL, /* add_buddy */ | |
373 NULL, /* add_buddies */ | |
374 NULL, /* remove_buddy */ | |
375 NULL, /* remove_buddies */ | |
376 NULL, /* add_permit */ | |
377 NULL, /* add_deny */ | |
378 NULL, /* rem_permit */ | |
379 NULL, /* rem_deny */ | |
380 NULL, /* set_permit_deny */ | |
381 NULL, /* join_chat */ | |
382 NULL, /* reject_chat */ | |
383 NULL, /* get_chat_name */ | |
384 NULL, /* chat_invite */ | |
385 NULL, /* chat_leave */ | |
386 NULL, /* chat_whisper */ | |
387 NULL, /* chat_send */ | |
388 NULL, /* keepalive */ | |
389 NULL, /* register_user */ | |
390 NULL, /* get_cb_info */ | |
391 NULL, /* get_cb_away */ | |
392 NULL, /* alias_buddy */ | |
393 NULL, /* group_buddy */ | |
394 NULL, /* rename_group */ | |
395 NULL, /* buddy_free */ | |
396 bonjour_convo_closed, /* convo_closed */ | |
397 NULL, /* normalize */ | |
398 NULL, /* set_buddy_icon */ | |
399 NULL, /* remove_group */ | |
400 NULL, /* get_cb_real_name */ | |
401 NULL, /* set_chat_topic */ | |
402 NULL, /* find_blist_chat */ | |
403 NULL, /* roomlist_get_list */ | |
404 NULL, /* roomlist_cancel */ | |
405 NULL, /* roomlist_expand_category */ | |
406 NULL, /* can_receive_file */ | |
12143
cbebda5f019c
[gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents:
12003
diff
changeset
|
407 NULL, /* send_file */ |
12607 | 408 NULL, /* new_xfer */ |
409 NULL, /* whiteboard_prpl_ops */ | |
410 NULL, /* media_prpl_ops */ | |
11477 | 411 }; |
412 | |
413 static GaimPluginInfo info = | |
414 { | |
415 GAIM_PLUGIN_MAGIC, | |
416 GAIM_MAJOR_VERSION, | |
417 GAIM_MINOR_VERSION, | |
418 GAIM_PLUGIN_PROTOCOL, /**< type */ | |
419 NULL, /**< ui_requirement */ | |
420 0, /**< flags */ | |
421 NULL, /**< dependencies */ | |
422 GAIM_PRIORITY_DEFAULT, /**< priority */ | |
423 | |
424 "prpl-bonjour", /**< id */ | |
425 "Bonjour", /**< name */ | |
426 VERSION, /**< version */ | |
427 /** summary */ | |
428 N_("Bonjour Protocol Plugin"), | |
429 /** description */ | |
430 N_("Bonjour Protocol Plugin"), | |
431 NULL, /**< author */ | |
432 GAIM_WEBSITE, /**< homepage */ | |
433 | |
434 NULL, /**< load */ | |
11984 | 435 plugin_unload, /**< unload */ |
11477 | 436 NULL, /**< destroy */ |
437 | |
438 NULL, /**< ui_info */ | |
439 &prpl_info, /**< extra_info */ | |
440 NULL, /**< prefs_info */ | |
441 NULL | |
442 }; | |
443 | |
444 static void | |
11984 | 445 initialize_default_account_values() |
446 { | |
447 char *fullname = NULL; | |
448 char *splitpoint = NULL; | |
449 char hostname[255]; | |
12003
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
450 #ifndef _WIN32 |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
451 struct passwd *info; |
11984 | 452 |
453 /* Try to figure out the user's real name */ | |
454 info = getpwuid(getuid()); | |
455 if ((info != NULL) && (info->pw_gecos != NULL) && (info->pw_gecos[0] != '\0')) | |
456 fullname = info->pw_gecos; | |
457 else if ((info != NULL) && (info->pw_name != NULL) && (info->pw_name[0] != '\0')) | |
458 fullname = info->pw_name; | |
459 else if (((fullname = getlogin()) != NULL) && (fullname[0] != '\0')) | |
460 ; | |
461 else | |
462 fullname = _("Gaim User"); | |
463 | |
12003
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
464 #else |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
465 FARPROC myNetUserGetInfo = wgaim_find_and_loadproc("Netapi32.dll", |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
466 "NetUserGetInfo"); |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
467 |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
468 if (myNetUserGetInfo) { |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
469 LPUSER_INFO_10 user_info = NULL; |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
470 LPSERVER_INFO_100 server_info = NULL; |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
471 wchar_t *servername = NULL; |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
472 wchar_t username[UNLEN + 1] = {'\0'}; |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
473 DWORD dwLenUsername = sizeof(username); |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
474 FARPROC myNetServerEnum = wgaim_find_and_loadproc( |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
475 "Netapi32.dll", "NetServerEnum"); |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
476 FARPROC myNetApiBufferFree = wgaim_find_and_loadproc( |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
477 "Netapi32.dll", "NetApiBufferFree"); |
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 (myNetServerEnum && myNetApiBufferFree) { |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
480 DWORD dwEntriesRead = 0; |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
481 DWORD dwTotalEntries = 0; |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
482 DWORD dwResumeHandle = 0; |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
483 |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
484 NET_API_STATUS nStatus = (myNetServerEnum)(NULL, 100, |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
485 &server_info, MAX_PREFERRED_LENGTH, |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
486 &dwEntriesRead, &dwTotalEntries, |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
487 SV_TYPE_DOMAIN_CTRL, NULL, &dwResumeHandle); |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
488 |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
489 if ((nStatus == NERR_Success |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
490 || nStatus == ERROR_MORE_DATA) |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
491 && dwEntriesRead > 0) { |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
492 servername = server_info->sv100_name; |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
493 } else { |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
494 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
|
495 } |
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 |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
498 if (!GetUserNameW(&username, &dwLenUsername)) { |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
499 gaim_debug_warning("bonjour", |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
500 "Unable to look up username\n"); |
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 |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
503 if (username != NULL && *username != '\0' |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
504 && (myNetUserGetInfo)(servername, username, 10, |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
505 &user_info) == NERR_Success) { |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
506 if (user_info != NULL) { |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
507 fullname = g_utf16_to_utf8( |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
508 user_info->usri10_full_name, |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
509 -1, NULL, NULL, NULL); |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
510 } |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
511 } |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
512 if (user_info != NULL) |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
513 (myNetApiBufferFree)(user_info); |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
514 if (server_info != NULL) |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
515 (myNetApiBufferFree)(server_info); |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
516 } |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
517 |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
518 if (!fullname) |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
519 fullname = g_strdup(_("Gaim User")); |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
520 #endif |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
521 |
11984 | 522 /* Split the real name into a first and last name */ |
523 splitpoint = strchr(fullname, ' '); | |
524 if (splitpoint != NULL) | |
525 { | |
526 default_firstname = g_strndup(fullname, splitpoint - fullname); | |
527 default_lastname = g_strdup(&splitpoint[1]); | |
528 } | |
529 else | |
530 { | |
531 default_firstname = g_strdup(fullname); | |
532 default_lastname = g_strdup(""); | |
533 } | |
534 | |
12003
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
535 #ifdef _WIN32 |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
536 g_free(fullname); |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
537 #endif |
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
538 |
11984 | 539 /* Try to figure out a good host name to use */ |
540 /* TODO: Avoiding 'localhost,' if possible */ | |
541 if (gethostname(hostname, 255) != 0) { | |
12003
13da3f228bbb
[gaim-migrate @ 14296]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11984
diff
changeset
|
542 gaim_debug_warning("bonjour", "Error %d when getting host name. Using \"localhost.\"\n", errno); |
11984 | 543 strcpy(hostname, "localhost"); |
544 } | |
545 default_hostname = g_strdup(hostname); | |
546 } | |
547 | |
548 static void | |
11477 | 549 init_plugin(GaimPlugin *plugin) |
550 { | |
551 GaimAccountUserSplit *split; | |
552 GaimAccountOption *option; | |
553 | |
11984 | 554 initialize_default_account_values(); |
11477 | 555 |
11829
4669e7461968
[gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents:
11718
diff
changeset
|
556 /* Creating the user splits */ |
12489 | 557 split = gaim_account_user_split_new(_("Hostname"), default_hostname, '@'); |
11477 | 558 prpl_info.user_splits = g_list_append(prpl_info.user_splits, split); |
11539 | 559 |
11829
4669e7461968
[gaim-migrate @ 14120]
Richard Laager <rlaager@wiktel.com>
parents:
11718
diff
changeset
|
560 /* Creating the options for the protocol */ |
11477 | 561 option = gaim_account_option_int_new(_("Port"), "port", 5298); |
562 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
563 | |
11984 | 564 option = gaim_account_option_string_new(_("First name"), "first", default_firstname); |
11477 | 565 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); |
566 | |
11984 | 567 option = gaim_account_option_string_new(_("Last name"), "last", default_lastname); |
11477 | 568 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); |
569 | |
570 option = gaim_account_option_string_new(_("Email"), "email", ""); | |
571 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
11539 | 572 |
11477 | 573 my_protocol = plugin; |
574 } | |
575 | |
576 GAIM_INIT_PLUGIN(bonjour, init_plugin, info); |