~vish/ubuntu/maverick/pidgin/bug25979

« back to all changes in this revision

Viewing changes to libpurple/protocols/jabber/libxmpp.c

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2009-10-09 19:40:26 UTC
  • mfrom: (1.4.1 upstream) (46.1.10 karmic)
  • Revision ID: james.westby@ubuntu.com-20091009194026-wbqqh0bsbz19nx5q
Tags: 1:2.6.2-1ubuntu7
* Don't stick the buddy list window to all desktops as some
  window managers have trouble to properly unstick it (LP: #346840)
  - debian/patches/11_buddy_list_really_show.patch
* Always use default tray icon size on KDE (LP: #209440)
  - debian/patches/62_tray_icon_size_kde.patch
* Use scrollbars in the preferences dialog if the screen height is
  below 700 px instead of 600 px
  - debian/patches/60_1024x600_gtkprefs.c.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
#include "internal.h"
29
29
 
30
30
#include "accountopt.h"
 
31
#include "core.h"
31
32
#include "debug.h"
32
33
#include "version.h"
33
34
 
34
35
#include "iq.h"
35
36
#include "jabber.h"
36
37
#include "chat.h"
 
38
#include "disco.h"
37
39
#include "message.h"
38
40
#include "roster.h"
39
41
#include "si.h"
44
46
#include "usertune.h"
45
47
#include "caps.h"
46
48
#include "data.h"
 
49
#include "ibb.h"
 
50
 
 
51
static PurplePlugin *my_protocol = NULL;
47
52
 
48
53
static PurplePluginProtocolInfo prpl_info =
49
54
{
69
74
        jabber_set_info,                                /* set_info */
70
75
        jabber_send_typing,                             /* send_typing */
71
76
        jabber_buddy_get_info,                  /* get_info */
72
 
        jabber_presence_send,                   /* set_status */
 
77
        jabber_set_status,                              /* set_status */
73
78
        jabber_idle_set,                                /* set_idle */
74
79
        NULL,                                                   /* change_passwd */
75
80
        jabber_roster_add_buddy,                /* add_buddy */
118
123
        jabber_attention_types,                 /* attention_types */
119
124
 
120
125
        sizeof(PurplePluginProtocolInfo),       /* struct_size */
121
 
        NULL
 
126
        NULL, /* get_account_text_table */
 
127
        jabber_initiate_media,          /* initiate_media */
 
128
        jabber_get_media_caps,                  /* get_media_caps */
122
129
};
123
130
 
124
131
static gboolean load_plugin(PurplePlugin *plugin)
133
140
                        purple_value_new(PURPLE_TYPE_SUBTYPE, PURPLE_SUBTYPE_CONNECTION),
134
141
                        purple_value_new_outgoing(PURPLE_TYPE_SUBTYPE, PURPLE_SUBTYPE_XMLNODE));
135
142
 
 
143
        /*
 
144
         * Do not remove this or the plugin will fail. Completely. You have been
 
145
         * warned!
 
146
         */
 
147
        purple_signal_connect_priority(plugin, "jabber-sending-xmlnode",
 
148
                        plugin, PURPLE_CALLBACK(jabber_send_signal_cb),
 
149
                        NULL, PURPLE_SIGNAL_PRIORITY_HIGHEST);
 
150
 
136
151
        purple_signal_register(plugin, "jabber-sending-text",
137
152
                             purple_marshal_VOID__POINTER_POINTER, NULL, 2,
138
153
                             purple_value_new(PURPLE_TYPE_SUBTYPE, PURPLE_SUBTYPE_CONNECTION),
139
154
                             purple_value_new_outgoing(PURPLE_TYPE_STRING));
140
 
        
 
155
 
 
156
        purple_signal_register(plugin, "jabber-receiving-message",
 
157
                        purple_marshal_BOOLEAN__POINTER_POINTER_POINTER_POINTER_POINTER_POINTER,
 
158
                        purple_value_new(PURPLE_TYPE_BOOLEAN), 6,
 
159
                        purple_value_new(PURPLE_TYPE_SUBTYPE, PURPLE_SUBTYPE_CONNECTION),
 
160
                        purple_value_new(PURPLE_TYPE_STRING), /* type */
 
161
                        purple_value_new(PURPLE_TYPE_STRING), /* id */
 
162
                        purple_value_new(PURPLE_TYPE_STRING), /* from */
 
163
                        purple_value_new(PURPLE_TYPE_STRING), /* to */
 
164
                        purple_value_new(PURPLE_TYPE_SUBTYPE, PURPLE_SUBTYPE_XMLNODE));
 
165
 
 
166
        purple_signal_register(plugin, "jabber-receiving-iq",
 
167
                        purple_marshal_BOOLEAN__POINTER_POINTER_POINTER_POINTER_POINTER,
 
168
                        purple_value_new(PURPLE_TYPE_BOOLEAN), 5,
 
169
                        purple_value_new(PURPLE_TYPE_SUBTYPE, PURPLE_SUBTYPE_CONNECTION),
 
170
                        purple_value_new(PURPLE_TYPE_STRING), /* type */
 
171
                        purple_value_new(PURPLE_TYPE_STRING), /* id */
 
172
                        purple_value_new(PURPLE_TYPE_STRING), /* from */
 
173
                        purple_value_new(PURPLE_TYPE_SUBTYPE, PURPLE_SUBTYPE_XMLNODE));
 
174
 
 
175
        purple_signal_register(plugin, "jabber-watched-iq",
 
176
                        purple_marshal_BOOLEAN__POINTER_POINTER_POINTER_POINTER_POINTER,
 
177
                        purple_value_new(PURPLE_TYPE_BOOLEAN), 5,
 
178
                        purple_value_new(PURPLE_TYPE_SUBTYPE, PURPLE_SUBTYPE_CONNECTION),
 
179
                        purple_value_new(PURPLE_TYPE_STRING), /* type */
 
180
                        purple_value_new(PURPLE_TYPE_STRING), /* id */
 
181
                        purple_value_new(PURPLE_TYPE_STRING), /* from */
 
182
                        purple_value_new(PURPLE_TYPE_SUBTYPE, PURPLE_SUBTYPE_XMLNODE)); /* child */
 
183
 
 
184
        /* Modifying these? Look at jabber_init_plugin for the ipc versions */
 
185
        purple_signal_register(plugin, "jabber-register-namespace-watcher",
 
186
                        purple_marshal_VOID__POINTER_POINTER,
 
187
                        NULL, 2,
 
188
                        purple_value_new(PURPLE_TYPE_STRING),  /* node */
 
189
                        purple_value_new(PURPLE_TYPE_STRING)); /* namespace */
 
190
 
 
191
        purple_signal_register(plugin, "jabber-unregister-namespace-watcher",
 
192
                        purple_marshal_VOID__POINTER_POINTER,
 
193
                        NULL, 2,
 
194
                        purple_value_new(PURPLE_TYPE_STRING),  /* node */
 
195
                        purple_value_new(PURPLE_TYPE_STRING)); /* namespace */
 
196
 
 
197
        purple_signal_connect(plugin, "jabber-register-namespace-watcher",
 
198
                        plugin, PURPLE_CALLBACK(jabber_iq_signal_register), NULL);
 
199
        purple_signal_connect(plugin, "jabber-unregister-namespace-watcher",
 
200
                        plugin, PURPLE_CALLBACK(jabber_iq_signal_unregister), NULL);
 
201
 
 
202
        purple_signal_register(plugin, "jabber-receiving-presence",
 
203
                        purple_marshal_BOOLEAN__POINTER_POINTER_POINTER_POINTER,
 
204
                        purple_value_new(PURPLE_TYPE_BOOLEAN), 4,
 
205
                        purple_value_new(PURPLE_TYPE_SUBTYPE, PURPLE_SUBTYPE_CONNECTION),
 
206
                        purple_value_new(PURPLE_TYPE_STRING), /* type */
 
207
                        purple_value_new(PURPLE_TYPE_STRING), /* from */
 
208
                        purple_value_new(PURPLE_TYPE_SUBTYPE, PURPLE_SUBTYPE_XMLNODE));
 
209
 
141
210
        return TRUE;
142
211
}
143
212
 
144
213
static gboolean unload_plugin(PurplePlugin *plugin)
145
214
{
146
 
        purple_signal_unregister(plugin, "jabber-receiving-xmlnode");
 
215
        purple_signals_unregister_by_instance(plugin);
147
216
 
148
 
        purple_signal_unregister(plugin, "jabber-sending-xmlnode");
149
 
        
150
 
        purple_signal_unregister(plugin, "jabber-sending-text");
151
 
        
 
217
        /* reverse order of init_plugin */
 
218
        jabber_bosh_uninit();
152
219
        jabber_data_uninit();
153
 
        
 
220
        jabber_si_uninit();
 
221
        jabber_ibb_uninit();
 
222
        /* PEP things should be uninit via jabber_pep_uninit, not here */
 
223
        jabber_pep_uninit();
 
224
        jabber_caps_uninit();
 
225
        jabber_iq_uninit();
 
226
 
 
227
        jabber_unregister_commands();
 
228
 
 
229
        /* Stay on target...stay on target... Almost there... */
 
230
        jabber_uninit_plugin();
 
231
 
154
232
        return TRUE;
155
233
}
156
234
 
191
269
        NULL
192
270
};
193
271
 
 
272
static PurpleAccount *find_acct(const char *prpl, const char *acct_id)
 
273
{
 
274
        PurpleAccount *acct = NULL;
 
275
 
 
276
        /* If we have a specific acct, use it */
 
277
        if (acct_id) {
 
278
                acct = purple_accounts_find(acct_id, prpl);
 
279
                if (acct && !purple_account_is_connected(acct))
 
280
                        acct = NULL;
 
281
        } else { /* Otherwise find an active account for the protocol */
 
282
                GList *l = purple_accounts_get_all();
 
283
                while (l) {
 
284
                        if (!strcmp(prpl, purple_account_get_protocol_id(l->data))
 
285
                                        && purple_account_is_connected(l->data)) {
 
286
                                acct = l->data;
 
287
                                break;
 
288
                        }
 
289
                        l = l->next;
 
290
                }
 
291
        }
 
292
 
 
293
        return acct;
 
294
}
 
295
 
 
296
static gboolean xmpp_uri_handler(const char *proto, const char *user, GHashTable *params)
 
297
{
 
298
        char *acct_id = g_hash_table_lookup(params, "account");
 
299
        PurpleAccount *acct;
 
300
 
 
301
        if (g_ascii_strcasecmp(proto, "xmpp"))
 
302
                return FALSE;
 
303
 
 
304
        acct = find_acct(purple_plugin_get_id(my_protocol), acct_id);
 
305
 
 
306
        if (!acct)
 
307
                return FALSE;
 
308
 
 
309
        /* xmpp:romeo@montague.net?message;subject=Test%20Message;body=Here%27s%20a%20test%20message */
 
310
        if (g_hash_table_lookup_extended(params, "message", NULL, NULL)) {
 
311
                char *body = g_hash_table_lookup(params, "body");
 
312
                if (user && *user) {
 
313
                        PurpleConversation *conv =
 
314
                                        purple_conversation_new(PURPLE_CONV_TYPE_IM, acct, user);
 
315
                        purple_conversation_present(conv);
 
316
                        if (body && *body)
 
317
                                purple_conv_send_confirm(conv, body);
 
318
                }
 
319
        } else if (g_hash_table_lookup_extended(params, "roster", NULL, NULL)) {
 
320
                char *name = g_hash_table_lookup(params, "name");
 
321
                if (user && *user)
 
322
                        purple_blist_request_add_buddy(acct, user, NULL, name);
 
323
        } else if (g_hash_table_lookup_extended(params, "join", NULL, NULL)) {
 
324
                PurpleConnection *gc = purple_account_get_connection(acct);
 
325
                if (user && *user) {
 
326
                        GHashTable *params = jabber_chat_info_defaults(gc, user);
 
327
                        jabber_chat_join(gc, params);
 
328
                }
 
329
                return TRUE;
 
330
        }
 
331
 
 
332
        return FALSE;
 
333
}
 
334
 
 
335
 
194
336
static void
195
337
init_plugin(PurplePlugin *plugin)
196
338
{
203
345
#endif
204
346
        PurpleAccountUserSplit *split;
205
347
        PurpleAccountOption *option;
206
 
        
 
348
 
207
349
        /* Translators: 'domain' is used here in the context of Internet domains, e.g. pidgin.im */
208
350
        split = purple_account_user_split_new(_("Domain"), NULL, '@');
209
351
        purple_account_user_split_set_reverse(split, FALSE);
210
352
        prpl_info.user_splits = g_list_append(prpl_info.user_splits, split);
211
 
        
 
353
 
212
354
        split = purple_account_user_split_new(_("Resource"), NULL, '/');
213
355
        purple_account_user_split_set_reverse(split, FALSE);
214
356
        prpl_info.user_splits = g_list_append(prpl_info.user_splits, split);
215
 
        
216
 
        option = purple_account_option_bool_new(_("Require SSL/TLS"), "require_tls", FALSE);
 
357
 
 
358
        option = purple_account_option_bool_new(_("Require SSL/TLS"), "require_tls", TRUE);
217
359
        prpl_info.protocol_options = g_list_append(prpl_info.protocol_options,
218
360
                                                                                           option);
219
 
        
 
361
 
220
362
        option = purple_account_option_bool_new(_("Force old (port 5223) SSL"), "old_ssl", FALSE);
221
363
        prpl_info.protocol_options = g_list_append(prpl_info.protocol_options,
222
364
                                                                                           option);
223
 
        
 
365
 
224
366
        option = purple_account_option_bool_new(
225
367
                                                _("Allow plaintext auth over unencrypted streams"),
226
368
                                                "auth_plain_in_clear", FALSE);
227
369
        prpl_info.protocol_options = g_list_append(prpl_info.protocol_options,
228
370
                                                   option);
229
 
        
 
371
 
230
372
        option = purple_account_option_int_new(_("Connect port"), "port", 5222);
231
373
        prpl_info.protocol_options = g_list_append(prpl_info.protocol_options,
232
374
                                                   option);
238
380
 
239
381
        option = purple_account_option_string_new(_("File transfer proxies"),
240
382
                                                  "ft_proxies",
241
 
                                                /* TODO: Is this an acceptable default? */
242
 
                                                  "proxy.jabber.org");
 
383
                                                /* TODO: Is this an acceptable default?
 
384
                                                 * Also, keep this in sync as they add more servers */
 
385
                                                  "proxy.eu.jabber.org");
 
386
        prpl_info.protocol_options = g_list_append(prpl_info.protocol_options,
 
387
                                                  option);
 
388
 
 
389
        option = purple_account_option_string_new(_("BOSH URL"),
 
390
                                                  "bosh_url", NULL);
243
391
        prpl_info.protocol_options = g_list_append(prpl_info.protocol_options,
244
392
                                                  option);
245
393
 
250
398
        prpl_info.protocol_options = g_list_append(prpl_info.protocol_options,
251
399
                option);
252
400
 
 
401
        my_protocol = plugin;
253
402
        jabber_init_plugin(plugin);
254
403
 
255
404
        purple_prefs_remove("/plugins/prpl/jabber");
272
421
#endif
273
422
#endif
274
423
        jabber_register_commands();
275
 
        
 
424
 
 
425
        /* reverse order of unload_plugin */
276
426
        jabber_iq_init();
 
427
        jabber_caps_init();
 
428
        /* PEP things should be init via jabber_pep_init, not here */
277
429
        jabber_pep_init();
278
 
        
279
 
        jabber_tune_init();
280
 
        jabber_caps_init();
281
 
        
282
430
        jabber_data_init();
283
 
        
284
 
        jabber_add_feature("avatarmeta", AVATARNAMESPACEMETA, jabber_pep_namespace_only_when_pep_enabled_cb);
285
 
        jabber_add_feature("avatardata", AVATARNAMESPACEDATA, jabber_pep_namespace_only_when_pep_enabled_cb);
286
 
        jabber_add_feature("buzz", "http://www.xmpp.org/extensions/xep-0224.html#ns",
287
 
                                           jabber_buzz_isenabled);
288
 
        jabber_add_feature("bob", XEP_0231_NAMESPACE,
289
 
                                           jabber_custom_smileys_isenabled);
290
 
 
291
 
        jabber_pep_register_handler("avatar", AVATARNAMESPACEMETA, jabber_buddy_avatar_update_metadata);
 
431
        jabber_bosh_init();
 
432
 
 
433
        #warning implement adding and retrieving own features via IPC API
 
434
 
 
435
        jabber_ibb_init();
 
436
        jabber_si_init();
 
437
 
 
438
        purple_signal_connect(purple_get_core(), "uri-handler", plugin,
 
439
                PURPLE_CALLBACK(xmpp_uri_handler), NULL);
292
440
}
293
441
 
294
442