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("");
|
11519
|
272 g_string_append_printf(ret, _("\n<b>Status:</b> %s"), status_description);
|
|
273 if (message != NULL)
|
|
274 g_string_append_printf(ret, _("\n<b>Message:</b> %s"), message);
|
11496
|
275
|
|
276 return g_string_free(ret, FALSE);
|
11477
|
277 }
|
|
278
|
|
279 static GaimPlugin *my_protocol = NULL;
|
|
280
|
|
281 static GaimPluginProtocolInfo prpl_info =
|
|
282 {
|
|
283 OPT_PROTO_NO_PASSWORD,
|
|
284 NULL, /* user_splits */
|
|
285 NULL, /* protocol_options */
|
|
286 {"png", 0, 0, 96, 96, GAIM_ICON_SCALE_DISPLAY}, /* icon_spec */
|
|
287 bonjour_list_icon, /* list_icon */
|
|
288 bonjour_list_emblems, /* list_emblems */
|
|
289 bonjour_status_text, /* status_text */
|
|
290 bonjour_tooltip_text, /* tooltip_text */
|
|
291 bonjour_status_types, /* status_types */
|
|
292 NULL, /* blist_node_menu */
|
|
293 NULL, /* chat_info */
|
|
294 NULL, /* chat_info_defaults */
|
|
295 bonjour_login, /* login */
|
|
296 bonjour_close, /* close */
|
|
297 bonjour_send_im, /* send_im */
|
|
298 NULL, /* set_info */
|
|
299 NULL, /* send_typing */
|
|
300 NULL, /* get_info */
|
|
301 bonjour_set_status, /* set_status */
|
|
302 NULL, /* set_idle */
|
|
303 NULL, /* change_passwd */
|
|
304 NULL, /* add_buddy */
|
|
305 NULL, /* add_buddies */
|
|
306 NULL, /* remove_buddy */
|
|
307 NULL, /* remove_buddies */
|
|
308 NULL, /* add_permit */
|
|
309 NULL, /* add_deny */
|
|
310 NULL, /* rem_permit */
|
|
311 NULL, /* rem_deny */
|
|
312 NULL, /* set_permit_deny */
|
|
313 NULL, /* join_chat */
|
|
314 NULL, /* reject_chat */
|
|
315 NULL, /* get_chat_name */
|
|
316 NULL, /* chat_invite */
|
|
317 NULL, /* chat_leave */
|
|
318 NULL, /* chat_whisper */
|
|
319 NULL, /* chat_send */
|
|
320 NULL, /* keepalive */
|
|
321 NULL, /* register_user */
|
|
322 NULL, /* get_cb_info */
|
|
323 NULL, /* get_cb_away */
|
|
324 NULL, /* alias_buddy */
|
|
325 NULL, /* group_buddy */
|
|
326 NULL, /* rename_group */
|
|
327 NULL, /* buddy_free */
|
|
328 bonjour_convo_closed, /* convo_closed */
|
|
329 NULL, /* normalize */
|
|
330 NULL, /* set_buddy_icon */
|
|
331 NULL, /* remove_group */
|
|
332 NULL, /* get_cb_real_name */
|
|
333 NULL, /* set_chat_topic */
|
|
334 NULL, /* find_blist_chat */
|
|
335 NULL, /* roomlist_get_list */
|
|
336 NULL, /* roomlist_cancel */
|
|
337 NULL, /* roomlist_expand_category */
|
|
338 NULL, /* can_receive_file */
|
|
339 NULL /* send_file */
|
|
340 };
|
|
341
|
|
342 static GaimPluginInfo info =
|
|
343 {
|
|
344 GAIM_PLUGIN_MAGIC,
|
|
345 GAIM_MAJOR_VERSION,
|
|
346 GAIM_MINOR_VERSION,
|
|
347 GAIM_PLUGIN_PROTOCOL, /**< type */
|
|
348 NULL, /**< ui_requirement */
|
|
349 0, /**< flags */
|
|
350 NULL, /**< dependencies */
|
|
351 GAIM_PRIORITY_DEFAULT, /**< priority */
|
|
352
|
|
353 "prpl-bonjour", /**< id */
|
|
354 "Bonjour", /**< name */
|
|
355 VERSION, /**< version */
|
|
356 /** summary */
|
|
357 N_("Bonjour Protocol Plugin"),
|
|
358 /** description */
|
|
359 N_("Bonjour Protocol Plugin"),
|
|
360 NULL, /**< author */
|
|
361 GAIM_WEBSITE, /**< homepage */
|
|
362
|
|
363 NULL, /**< load */
|
|
364 NULL, /**< unload */
|
|
365 NULL, /**< destroy */
|
|
366
|
|
367 NULL, /**< ui_info */
|
|
368 &prpl_info, /**< extra_info */
|
|
369 NULL, /**< prefs_info */
|
|
370 NULL
|
|
371 };
|
|
372
|
|
373 static void
|
|
374 init_plugin(GaimPlugin *plugin)
|
|
375 {
|
|
376 GaimAccountUserSplit *split;
|
|
377 GaimAccountOption *option;
|
|
378 char hostname[255];
|
|
379
|
|
380 if (gethostname(hostname, 255) != 0) {
|
|
381 gaim_debug_warning("rendezvous", "Error %d when getting host name. Using \"localhost.\"\n", errno);
|
|
382 strcpy(hostname, "localhost");
|
|
383 }
|
|
384
|
|
385 // Creating the user splits
|
|
386 split = gaim_account_user_split_new(_("Host name"), hostname, '@');
|
|
387 prpl_info.user_splits = g_list_append(prpl_info.user_splits, split);
|
|
388
|
|
389 // Creating the options for the protocol
|
|
390 option = gaim_account_option_int_new(_("Port"), "port", 5298);
|
|
391 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
|
|
392
|
|
393 option = gaim_account_option_string_new(_("First name"), "first", "Gaim");
|
|
394 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
|
|
395
|
|
396 option = gaim_account_option_string_new(_("Last name"), "last", "User");
|
|
397 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
|
|
398
|
|
399 option = gaim_account_option_string_new(_("Email"), "email", "");
|
|
400 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
|
|
401
|
|
402 my_protocol = plugin;
|
|
403 }
|
|
404
|
|
405 GAIM_INIT_PLUGIN(bonjour, init_plugin, info);
|