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>
|
|
23
|
|
24 #include "internal.h"
|
|
25 #include "account.h"
|
|
26 #include "accountopt.h"
|
|
27 #include "version.h"
|
|
28 #include "debug.h"
|
|
29
|
|
30 #include "bonjour.h"
|
|
31 #include "dns_sd.h"
|
|
32 #include "jabber.h"
|
|
33 #include "buddy.h"
|
|
34
|
11496
|
35 void bonjour_login(GaimAccount *account, GaimStatus *status)
|
11477
|
36 {
|
|
37 GaimConnection *gc = gaim_account_get_connection(account);
|
|
38 GaimGroup* bonjour_group = NULL;
|
|
39 BonjourData* bd = NULL;
|
|
40
|
|
41 gc->flags |= GAIM_CONNECTION_HTML;
|
|
42 gc->proto_data = g_new(BonjourData, 1);
|
|
43 bd = gc->proto_data;
|
|
44
|
|
45 // Start waiting for jabber connections (iChat style)
|
|
46 bd->jabber_data = g_new(BonjourJabber, 1);
|
|
47 bd->jabber_data->name = gc->account->username;
|
|
48 bd->jabber_data->port = gaim_account_get_int(account, "port", BONJOUR_DEFAULT_PORT_INT);
|
|
49 bd->jabber_data->account = account;
|
|
50
|
|
51 if (bonjour_jabber_start(bd->jabber_data) == -1) {
|
|
52 // Send a message about the connection error
|
|
53 gaim_debug_error("bonjour", "Unable to listen to ichat connections");
|
|
54
|
|
55 // Free the data
|
|
56 g_free(bd->jabber_data);
|
|
57 g_free(bd);
|
|
58 return;
|
|
59 }
|
|
60
|
|
61 // Connect to the mDNS daemon looking for buddies in the LAN
|
|
62 bd->dns_sd_data = bonjour_dns_sd_new();
|
|
63 bd->dns_sd_data->name = (sw_string)gaim_account_get_username(account);
|
|
64 bd->dns_sd_data->txtvers = g_strdup("1");
|
|
65 bd->dns_sd_data->version = g_strdup("1");
|
11496
|
66 bd->dns_sd_data->first = g_strdup(gaim_account_get_string(account, "first", "TODO"));
|
|
67 bd->dns_sd_data->last = g_strdup(gaim_account_get_string(account, "last", ""));
|
11477
|
68 bd->dns_sd_data->port_p2pj = gaim_account_get_int(account, "port", BONJOUR_DEFAULT_PORT_INT);
|
|
69 bd->dns_sd_data->phsh = g_strdup("");
|
|
70 bd->dns_sd_data->status = g_strdup("avail"); //<-- Check the real status if different from avail
|
11496
|
71 bd->dns_sd_data->email = g_strdup(gaim_account_get_string(account, "email", ""));
|
11477
|
72 bd->dns_sd_data->vc = g_strdup("");
|
|
73 bd->dns_sd_data->jid = g_strdup("");
|
|
74 bd->dns_sd_data->AIM = g_strdup("");
|
11496
|
75 bd->dns_sd_data->msg = NULL; /* TODO */
|
11477
|
76
|
|
77 bd->dns_sd_data->account = account;
|
|
78 bonjour_dns_sd_start(bd->dns_sd_data);
|
|
79
|
|
80 // Create a group for bonjour buddies
|
|
81 bonjour_group = gaim_group_new(BONJOUR_GROUP_NAME);
|
|
82 gaim_blist_add_group(bonjour_group, NULL);
|
|
83
|
|
84 // Show the buddy list by telling Gaim we have already connected
|
|
85 gaim_connection_set_state(gc, GAIM_CONNECTED);
|
|
86 }
|
|
87
|
|
88 void bonjour_close(GaimConnection* connection)
|
|
89 {
|
|
90 GaimGroup* bonjour_group = gaim_find_group(BONJOUR_GROUP_NAME);
|
|
91 GSList* buddies;
|
|
92 GSList* l;
|
|
93 BonjourData* bd = (BonjourData*)connection->proto_data;
|
|
94
|
|
95 // Stop looking for buddies in the LAN
|
|
96 if (connection != NULL) {
|
|
97 bonjour_dns_sd_stop(bd->dns_sd_data);
|
|
98 if (bd != NULL) {
|
|
99 bonjour_dns_sd_free(bd->dns_sd_data);
|
|
100 }
|
|
101 }
|
|
102
|
|
103 // Stop waiting for conversations
|
|
104 bonjour_jabber_stop(bd->jabber_data);
|
|
105 g_free(bd->jabber_data);
|
|
106
|
|
107 // Remove all the bonjour buddies
|
|
108 if(connection != NULL){
|
|
109 buddies = gaim_find_buddies(connection->account, connection->account->username);
|
|
110 for(l = buddies; l; l = l->next){
|
|
111 bonjour_buddy_delete(((GaimBuddy*)(l->data))->proto_data);
|
|
112 gaim_blist_remove_buddy(l->data);
|
|
113 }
|
|
114 g_slist_free(buddies);
|
|
115 }
|
|
116
|
|
117 // Delete the bonjour group
|
|
118 gaim_blist_remove_group(bonjour_group);
|
|
119
|
|
120 }
|
|
121
|
|
122 const char* bonjour_list_icon(GaimAccount* account, GaimBuddy* buddy)
|
|
123 {
|
|
124 return BONJOUR_ICON_NAME;
|
|
125 }
|
|
126
|
|
127 int bonjour_send_im(GaimConnection* connection, const char* to, const char* msg, GaimConvImFlags flags)
|
|
128 {
|
|
129 if(!to || !msg)
|
|
130 return 0;
|
|
131
|
|
132 bonjour_jabber_send_message(((BonjourData*)(connection->proto_data))->jabber_data, to, msg);
|
|
133
|
|
134 return 1;
|
|
135 }
|
|
136
|
11496
|
137 void bonjour_set_status(GaimAccount *account, GaimStatus *status)
|
11477
|
138 {
|
11496
|
139 GaimConnection *gc;
|
|
140 BonjourData *bd;
|
|
141 gboolean disconnected;
|
|
142 GaimStatusType *type;
|
|
143 int primitive;
|
|
144 GaimPresence *presence;
|
|
145 const char *message, *bonjour_status;
|
11477
|
146
|
11496
|
147 disconnected = gaim_account_is_disconnected(account);
|
|
148 type = gaim_status_get_type(status);
|
|
149 primitive = gaim_status_type_get_primitive(type);
|
|
150 presence = gaim_account_get_presence(account);
|
|
151
|
|
152 if (primitive != GAIM_STATUS_OFFLINE && disconnected)
|
|
153 {
|
|
154 gaim_account_connect(account);
|
|
155 return;
|
|
156 }
|
|
157 if (primitive == GAIM_STATUS_OFFLINE && !disconnected)
|
|
158 {
|
|
159 gaim_account_disconnect(account);
|
|
160 return;
|
11477
|
161 }
|
|
162
|
11496
|
163 if (!gaim_account_is_connected(account))
|
|
164 /* TODO: Does this mean we're connecting? */
|
|
165 return;
|
|
166
|
|
167 message = gaim_status_get_attr_string(status, "message");
|
|
168 if (message == NULL)
|
|
169 message = "";
|
|
170
|
|
171 /*
|
|
172 * The three possible status for Bonjour are
|
|
173 * -available ("avail")
|
|
174 * -idle ("away")
|
|
175 * -away ("dnd")
|
|
176 * Each of them can have an optional message.
|
|
177 */
|
|
178 if (primitive == GAIM_STATUS_AVAILABLE) {
|
|
179 bonjour_status = "avail";
|
|
180 } else if (gaim_presence_is_idle(presence)) {
|
|
181 bonjour_status = "away";
|
|
182 } else {
|
|
183 bonjour_status = "dnd";
|
11477
|
184 }
|
|
185
|
11496
|
186 gc = gaim_account_get_connection(account);
|
|
187 bd = gc->proto_data;
|
|
188 bonjour_dns_sd_send_status(bd->dns_sd_data, bonjour_status, message);
|
11477
|
189 }
|
|
190
|
11496
|
191 static GList *
|
|
192 bonjour_status_types(GaimAccount *account)
|
11477
|
193 {
|
11496
|
194 GList *status_types = NULL;
|
|
195 GaimStatusType *type;
|
|
196
|
|
197 g_return_val_if_fail(account != NULL, NULL);
|
|
198
|
|
199 type = gaim_status_type_new_full(GAIM_STATUS_OFFLINE,
|
|
200 BONJOUR_STATUS_ID_OFFLINE,
|
|
201 _("Offline"), TRUE, TRUE, FALSE);
|
|
202 status_types = g_list_append(status_types, type);
|
11477
|
203
|
11496
|
204 type = gaim_status_type_new_with_attrs(GAIM_STATUS_AVAILABLE,
|
|
205 BONJOUR_STATUS_ID_AVAILABLE,
|
|
206 _("Available"), TRUE, TRUE, FALSE,
|
|
207 "message", _("Message"),
|
|
208 gaim_value_new(GAIM_TYPE_STRING), NULL);
|
|
209 status_types = g_list_append(status_types, type);
|
11477
|
210
|
11496
|
211 type = gaim_status_type_new_with_attrs(GAIM_STATUS_AWAY,
|
|
212 BONJOUR_STATUS_ID_AWAY,
|
|
213 _("Away"), TRUE, TRUE, FALSE,
|
|
214 "message", _("Message"),
|
|
215 gaim_value_new(GAIM_TYPE_STRING), NULL);
|
|
216 status_types = g_list_append(status_types, type);
|
|
217
|
|
218 return status_types;
|
11477
|
219 }
|
|
220
|
11496
|
221 static void bonjour_convo_closed(GaimConnection *connection, const char *who)
|
11477
|
222 {
|
|
223 GaimBuddy* buddy = gaim_find_buddy(connection->account, who);
|
|
224
|
|
225 bonjour_jabber_close_conversation(((BonjourData*)(connection->proto_data))->jabber_data, buddy);
|
|
226 }
|
|
227
|
11496
|
228 static void bonjour_list_emblems(GaimBuddy *buddy,
|
|
229 const char **se, const char **sw,
|
|
230 const char **nw,const char **ne)
|
11477
|
231 {
|
11496
|
232 GaimPresence *presence;
|
|
233
|
|
234 presence = gaim_buddy_get_presence(buddy);
|
|
235
|
|
236 if (!gaim_presence_is_available(presence))
|
|
237 *se = "away";
|
|
238 }
|
|
239
|
|
240 static char *bonjour_status_text(GaimBuddy *buddy)
|
|
241 {
|
|
242 GaimPresence *presence;
|
|
243
|
|
244 presence = gaim_buddy_get_presence(buddy);
|
|
245
|
|
246 if (gaim_presence_is_available(presence))
|
|
247 return g_strdup("");
|
|
248 else
|
|
249 return g_strdup("Away");
|
11477
|
250 }
|
|
251
|
11496
|
252 static char *bonjour_tooltip_text(GaimBuddy *buddy)
|
11477
|
253 {
|
11496
|
254 GString *ret;
|
|
255 GaimPresence *presence;
|
|
256 GaimStatus *status;
|
|
257 const char *status_description;
|
|
258 const char *message;
|
|
259
|
|
260 presence = gaim_buddy_get_presence(buddy);
|
|
261 status = gaim_presence_get_active_status(presence);
|
|
262 message = gaim_status_get_attr_string(status, "message");
|
|
263
|
|
264 if (gaim_presence_is_available(presence))
|
|
265 status_description = gaim_status_get_name(status);
|
|
266 else if (gaim_presence_is_idle(presence))
|
|
267 status_description = _("Idle");
|
|
268 else
|
|
269 status_description = gaim_status_get_name(status);
|
|
270
|
|
271 ret = g_string_new("");
|
|
272 g_string_append_printf(ret, _("<b>Status:</b> %s"), status_description);
|
|
273 g_string_append_printf(ret, _("<b>Message:</b> %s"), message);
|
|
274
|
|
275 return g_string_free(ret, FALSE);
|
11477
|
276 }
|
|
277
|
|
278 static GaimPlugin *my_protocol = NULL;
|
|
279
|
|
280 static GaimPluginProtocolInfo prpl_info =
|
|
281 {
|
|
282 OPT_PROTO_NO_PASSWORD,
|
|
283 NULL, /* user_splits */
|
|
284 NULL, /* protocol_options */
|
|
285 {"png", 0, 0, 96, 96, GAIM_ICON_SCALE_DISPLAY}, /* icon_spec */
|
|
286 bonjour_list_icon, /* list_icon */
|
|
287 bonjour_list_emblems, /* list_emblems */
|
|
288 bonjour_status_text, /* status_text */
|
|
289 bonjour_tooltip_text, /* tooltip_text */
|
|
290 bonjour_status_types, /* status_types */
|
|
291 NULL, /* blist_node_menu */
|
|
292 NULL, /* chat_info */
|
|
293 NULL, /* chat_info_defaults */
|
|
294 bonjour_login, /* login */
|
|
295 bonjour_close, /* close */
|
|
296 bonjour_send_im, /* send_im */
|
|
297 NULL, /* set_info */
|
|
298 NULL, /* send_typing */
|
|
299 NULL, /* get_info */
|
|
300 bonjour_set_status, /* set_status */
|
|
301 NULL, /* set_idle */
|
|
302 NULL, /* change_passwd */
|
|
303 NULL, /* add_buddy */
|
|
304 NULL, /* add_buddies */
|
|
305 NULL, /* remove_buddy */
|
|
306 NULL, /* remove_buddies */
|
|
307 NULL, /* add_permit */
|
|
308 NULL, /* add_deny */
|
|
309 NULL, /* rem_permit */
|
|
310 NULL, /* rem_deny */
|
|
311 NULL, /* set_permit_deny */
|
|
312 NULL, /* join_chat */
|
|
313 NULL, /* reject_chat */
|
|
314 NULL, /* get_chat_name */
|
|
315 NULL, /* chat_invite */
|
|
316 NULL, /* chat_leave */
|
|
317 NULL, /* chat_whisper */
|
|
318 NULL, /* chat_send */
|
|
319 NULL, /* keepalive */
|
|
320 NULL, /* register_user */
|
|
321 NULL, /* get_cb_info */
|
|
322 NULL, /* get_cb_away */
|
|
323 NULL, /* alias_buddy */
|
|
324 NULL, /* group_buddy */
|
|
325 NULL, /* rename_group */
|
|
326 NULL, /* buddy_free */
|
|
327 bonjour_convo_closed, /* convo_closed */
|
|
328 NULL, /* normalize */
|
|
329 NULL, /* set_buddy_icon */
|
|
330 NULL, /* remove_group */
|
|
331 NULL, /* get_cb_real_name */
|
|
332 NULL, /* set_chat_topic */
|
|
333 NULL, /* find_blist_chat */
|
|
334 NULL, /* roomlist_get_list */
|
|
335 NULL, /* roomlist_cancel */
|
|
336 NULL, /* roomlist_expand_category */
|
|
337 NULL, /* can_receive_file */
|
|
338 NULL /* send_file */
|
|
339 };
|
|
340
|
|
341 static GaimPluginInfo info =
|
|
342 {
|
|
343 GAIM_PLUGIN_MAGIC,
|
|
344 GAIM_MAJOR_VERSION,
|
|
345 GAIM_MINOR_VERSION,
|
|
346 GAIM_PLUGIN_PROTOCOL, /**< type */
|
|
347 NULL, /**< ui_requirement */
|
|
348 0, /**< flags */
|
|
349 NULL, /**< dependencies */
|
|
350 GAIM_PRIORITY_DEFAULT, /**< priority */
|
|
351
|
|
352 "prpl-bonjour", /**< id */
|
|
353 "Bonjour", /**< name */
|
|
354 VERSION, /**< version */
|
|
355 /** summary */
|
|
356 N_("Bonjour Protocol Plugin"),
|
|
357 /** description */
|
|
358 N_("Bonjour Protocol Plugin"),
|
|
359 NULL, /**< author */
|
|
360 GAIM_WEBSITE, /**< homepage */
|
|
361
|
|
362 NULL, /**< load */
|
|
363 NULL, /**< unload */
|
|
364 NULL, /**< destroy */
|
|
365
|
|
366 NULL, /**< ui_info */
|
|
367 &prpl_info, /**< extra_info */
|
|
368 NULL, /**< prefs_info */
|
|
369 NULL
|
|
370 };
|
|
371
|
|
372 static void
|
|
373 init_plugin(GaimPlugin *plugin)
|
|
374 {
|
|
375 GaimAccountUserSplit *split;
|
|
376 GaimAccountOption *option;
|
|
377 char hostname[255];
|
|
378
|
|
379 if (gethostname(hostname, 255) != 0) {
|
|
380 gaim_debug_warning("rendezvous", "Error %d when getting host name. Using \"localhost.\"\n", errno);
|
|
381 strcpy(hostname, "localhost");
|
|
382 }
|
|
383
|
|
384 // Creating the user splits
|
|
385 split = gaim_account_user_split_new(_("Host name"), hostname, '@');
|
|
386 prpl_info.user_splits = g_list_append(prpl_info.user_splits, split);
|
|
387
|
|
388 // Creating the options for the protocol
|
|
389 option = gaim_account_option_int_new(_("Port"), "port", 5298);
|
|
390 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
|
|
391
|
|
392 option = gaim_account_option_string_new(_("First name"), "first", "Gaim");
|
|
393 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
|
|
394
|
|
395 option = gaim_account_option_string_new(_("Last name"), "last", "User");
|
|
396 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
|
|
397
|
|
398 option = gaim_account_option_string_new(_("Email"), "email", "");
|
|
399 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
|
|
400
|
|
401 /*
|
|
402 option = gaim_account_option_string_new(_("Status Message"), "message", "Available");
|
|
403 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
|
|
404 */
|
|
405
|
|
406 my_protocol = plugin;
|
|
407 }
|
|
408
|
|
409 GAIM_INIT_PLUGIN(bonjour, init_plugin, info);
|