libpurple/protocols/simple/simple.c

Sun, 15 Sep 2019 17:11:46 -0400

author
Elliott Sales de Andrade <qulogic@pidgin.im>
date
Sun, 15 Sep 2019 17:11:46 -0400
changeset 39894
7eab91ea30a1
parent 39760
217330c81a30
child 39896
e94146df6f96
permissions
-rw-r--r--

Replace Purple type macros by GObject macros.

These were necessary to support both static and dynamic plugins, but
we're just leaving the to GPlugin now.

11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1 /**
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
2 * @file simple.c
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
3 *
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
4 * purple
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
5 *
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
6 * Copyright (C) 2005 Thomas Butter <butter@uni-mannheim.de>
11396
468e60b682cd [gaim-migrate @ 13627]
Daniel Atallah <datallah@pidgin.im>
parents: 11383
diff changeset
7 *
11345
48a2f93e47b6 [gaim-migrate @ 13562]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11341
diff changeset
8 * ***
48a2f93e47b6 [gaim-migrate @ 13562]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11341
diff changeset
9 * Thanks to Google's Summer of Code Program and the helpful mentors
48a2f93e47b6 [gaim-migrate @ 13562]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11341
diff changeset
10 * ***
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
11 *
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
12 * This program is free software; you can redistribute it and/or modify
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
13 * it under the terms of the GNU General Public License as published by
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
14 * the Free Software Foundation; either version 2 of the License, or
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
15 * (at your option) any later version.
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
16 *
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
17 * This program is distributed in the hope that it will be useful,
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
20 * GNU General Public License for more details.
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
21 *
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
22 * You should have received a copy of the GNU General Public License
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
23 * along with this program; if not, write to the Free Software
19859
71d37b57eff2 The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 19848
diff changeset
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
25 */
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
26
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
27 #include "internal.h"
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
28
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
29 #include "accountopt.h"
34706
02cb08146888 Renamed blist.[ch] to buddylist.[ch]
Ankit Vani <a@nevitus.org>
parents: 34670
diff changeset
30 #include "buddylist.h"
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
31 #include "conversation.h"
39330
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
32 #include "core.h"
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
33 #include "debug.h"
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
34 #include "notify.h"
36543
a8c3fecee2d3 Renamed prpl.[ch] to protocol.[ch]
Ankit Vani <a@nevitus.org>
parents: 36536
diff changeset
35 #include "protocol.h"
36367
891eea799578 Renamed plugin.[ch] to plugins.[ch], since we (will) no longer have a PurplePlugin structure.
Ankit Vani <a@nevitus.org>
parents: 34855
diff changeset
36 #include "plugins.h"
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
37 #include "util.h"
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
38 #include "version.h"
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
39 #include "network.h"
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
40 #include "xmlnode.h"
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
41
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
42 #include "simple.h"
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
43 #include "sipmsg.h"
11409
2a3466f4a32c [gaim-migrate @ 13646]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11396
diff changeset
44 #include "ntlm.h"
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
45
36597
5392a32c7a4d Refactored simple to use the new protocol API
Ankit Vani <a@nevitus.org>
parents: 36583
diff changeset
46 static PurpleProtocol *my_protocol = NULL;
5392a32c7a4d Refactored simple to use the new protocol API
Ankit Vani <a@nevitus.org>
parents: 36583
diff changeset
47
38194
5a226afe38c9 Fix coverity 1255960
Gary Kramlich <grim@reaperworld.com>
parents: 38191
diff changeset
48 static gchar *gentag(void) {
5a226afe38c9 Fix coverity 1255960
Gary Kramlich <grim@reaperworld.com>
parents: 38191
diff changeset
49 return g_strdup_printf("%04d%04d", g_random_int(), g_random_int());
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
50 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
51
22104
56970903b8e9 Probe for -Wstrict-prototypes to get some more warnings. I then cleaned up
Richard Laager <rlaager@pidgin.im>
parents: 21503
diff changeset
52 static char *genbranch(void) {
11396
468e60b682cd [gaim-migrate @ 13627]
Daniel Atallah <datallah@pidgin.im>
parents: 11383
diff changeset
53 return g_strdup_printf("z9hG4bK%04X%04X%04X%04X%04X",
38194
5a226afe38c9 Fix coverity 1255960
Gary Kramlich <grim@reaperworld.com>
parents: 38191
diff changeset
54 g_random_int(), g_random_int(), g_random_int(),
5a226afe38c9 Fix coverity 1255960
Gary Kramlich <grim@reaperworld.com>
parents: 38191
diff changeset
55 g_random_int(), g_random_int());
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
56 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
57
22104
56970903b8e9 Probe for -Wstrict-prototypes to get some more warnings. I then cleaned up
Richard Laager <rlaager@pidgin.im>
parents: 21503
diff changeset
58 static char *gencallid(void) {
11396
468e60b682cd [gaim-migrate @ 13627]
Daniel Atallah <datallah@pidgin.im>
parents: 11383
diff changeset
59 return g_strdup_printf("%04Xg%04Xa%04Xi%04Xm%04Xt%04Xb%04Xx%04Xx",
38194
5a226afe38c9 Fix coverity 1255960
Gary Kramlich <grim@reaperworld.com>
parents: 38191
diff changeset
60 g_random_int(), g_random_int(), g_random_int(),
5a226afe38c9 Fix coverity 1255960
Gary Kramlich <grim@reaperworld.com>
parents: 38191
diff changeset
61 g_random_int(), g_random_int(), g_random_int(),
5a226afe38c9 Fix coverity 1255960
Gary Kramlich <grim@reaperworld.com>
parents: 38191
diff changeset
62 g_random_int(), g_random_int());
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
63 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
64
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
65 static const char *simple_list_icon(PurpleAccount *a, PurpleBuddy *b) {
11396
468e60b682cd [gaim-migrate @ 13627]
Daniel Atallah <datallah@pidgin.im>
parents: 11383
diff changeset
66 return "simple";
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
67 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
68
39330
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
69 static gint
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
70 simple_uri_handler_find_account(gconstpointer a, gconstpointer b)
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
71 {
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
72 PurpleAccount *account = PURPLE_ACCOUNT(a);
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
73 const gchar *protocol_id;
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
74
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
75 protocol_id = purple_account_get_protocol_id(account);
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
76
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
77 if (purple_strequal(protocol_id, "prpl-simple") &&
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
78 purple_account_is_connected(account)) {
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
79 return 0;
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
80 } else {
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
81 return -1;
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
82 }
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
83 }
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
84
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
85 static gboolean
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
86 simple_uri_handler(const gchar *scheme, const gchar *screenname,
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
87 GHashTable *params)
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
88 {
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
89 GList *accounts;
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
90 GList *account_node;
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
91 PurpleIMConversation *im;
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
92
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
93 g_return_val_if_fail(screenname != NULL, FALSE);
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
94
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
95 if (!purple_strequal(scheme, "sip")) {
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
96 return FALSE;
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
97 }
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
98
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
99 if (screenname[0] == '\0') {
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
100 purple_debug_warning("simple",
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
101 "Invalid empty screenname in URI");
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
102 return FALSE;
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
103 }
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
104
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
105 /* Find online SIMPLE account */
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
106 accounts = purple_accounts_get_all();
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
107 account_node = g_list_find_custom(accounts, NULL,
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
108 simple_uri_handler_find_account);
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
109
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
110 if (account_node == NULL) {
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
111 return FALSE;
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
112 }
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
113
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
114 im = purple_im_conversation_new(account_node->data, screenname);
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
115 purple_conversation_present(PURPLE_CONVERSATION(im));
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
116
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
117 return TRUE;
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
118 }
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
119
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
120 static void simple_keep_alive(PurpleConnection *gc) {
32266
af94a3153685 Convert simple prpl to use accessor functions purple_connection_get_protocol_data() and purple_connection_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents: 32157
diff changeset
121 struct simple_account_data *sip = purple_connection_get_protocol_data(gc);
11341
5511bbeeb3b4 [gaim-migrate @ 13555]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11327
diff changeset
122 if(sip->udp) { /* in case of UDP send a packet only with a 0 byte to
5511bbeeb3b4 [gaim-migrate @ 13555]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11327
diff changeset
123 remain in the NAT table */
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
124 gchar buf[2] = {0, 0};
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
125 purple_debug_info("simple", "sending keep alive\n");
35991
e6937e52930b Fix some CWE-252 coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35221
diff changeset
126 if (sendto(sip->fd, buf, 1, 0,
e6937e52930b Fix some CWE-252 coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35221
diff changeset
127 (struct sockaddr*)&sip->serveraddr,
e6937e52930b Fix some CWE-252 coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35221
diff changeset
128 sizeof(struct sockaddr_in)) != 1)
e6937e52930b Fix some CWE-252 coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35221
diff changeset
129 {
e6937e52930b Fix some CWE-252 coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35221
diff changeset
130 purple_debug_error("simple", "failed sending keep alive\n");
e6937e52930b Fix some CWE-252 coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35221
diff changeset
131 }
11194
47dc0e9a757a [gaim-migrate @ 13317]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11192
diff changeset
132 }
11396
468e60b682cd [gaim-migrate @ 13627]
Daniel Atallah <datallah@pidgin.im>
parents: 11383
diff changeset
133 return;
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
134 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
135
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
136 static gboolean process_register_response(struct simple_account_data *sip, struct sipmsg *msg, struct transaction *tc);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
137 static void send_notify(struct simple_account_data *sip, struct simple_watcher *);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
138
20988
75eab0f2aa19 Patch from Will Hawkins to publish a status of closed when signing out of a SIMPLE account. Fixes #1914.
Daniel Atallah <datallah@pidgin.im>
parents: 20658
diff changeset
139 static void send_open_publish(struct simple_account_data *sip);
75eab0f2aa19 Patch from Will Hawkins to publish a status of closed when signing out of a SIMPLE account. Fixes #1914.
Daniel Atallah <datallah@pidgin.im>
parents: 20658
diff changeset
140 static void send_closed_publish(struct simple_account_data *sip);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
141
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
142 static void do_notifies(struct simple_account_data *sip) {
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
143 GSList *tmp = sip->watcher;
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
144 purple_debug_info("simple", "do_notifies()\n");
11345
48a2f93e47b6 [gaim-migrate @ 13562]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11341
diff changeset
145 if((sip->republish != -1) || sip->republish < time(NULL)) {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
146 if(purple_account_get_bool(sip->account, "dopublish", TRUE)) {
20988
75eab0f2aa19 Patch from Will Hawkins to publish a status of closed when signing out of a SIMPLE account. Fixes #1914.
Daniel Atallah <datallah@pidgin.im>
parents: 20658
diff changeset
147 send_open_publish(sip);
11345
48a2f93e47b6 [gaim-migrate @ 13562]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11341
diff changeset
148 }
48a2f93e47b6 [gaim-migrate @ 13562]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11341
diff changeset
149 }
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
150
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
151 while(tmp) {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
152 purple_debug_info("simple", "notifying %s\n", ((struct simple_watcher*)tmp->data)->name);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
153 send_notify(sip, tmp->data);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
154 tmp = tmp->next;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
155 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
156 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
157
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
158 static void simple_set_status(PurpleAccount *account, PurpleStatus *status) {
32266
af94a3153685 Convert simple prpl to use accessor functions purple_connection_get_protocol_data() and purple_connection_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents: 32157
diff changeset
159 PurpleConnection *gc = purple_account_get_connection(account);
34855
9c289149eed4 Global replaces according to GObject status API
Ankit Vani <a@nevitus.org>
parents: 34811
diff changeset
160 PurpleStatusPrimitive primitive = purple_status_type_get_primitive(purple_status_get_status_type(status));
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
161 struct simple_account_data *sip = NULL;
11718
90804d019837 [gaim-migrate @ 14009]
Mark Doliner <markdoliner@pidgin.im>
parents: 11658
diff changeset
162
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
163 if (!purple_status_is_active(status))
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
164 return;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
165
32266
af94a3153685 Convert simple prpl to use accessor functions purple_connection_get_protocol_data() and purple_connection_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents: 32157
diff changeset
166 if (gc)
af94a3153685 Convert simple prpl to use accessor functions purple_connection_get_protocol_data() and purple_connection_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents: 32157
diff changeset
167 sip = purple_connection_get_protocol_data(gc);
11718
90804d019837 [gaim-migrate @ 14009]
Mark Doliner <markdoliner@pidgin.im>
parents: 11658
diff changeset
168
90804d019837 [gaim-migrate @ 14009]
Mark Doliner <markdoliner@pidgin.im>
parents: 11658
diff changeset
169 if (sip)
90804d019837 [gaim-migrate @ 14009]
Mark Doliner <markdoliner@pidgin.im>
parents: 11658
diff changeset
170 {
11650
757d7fbd4ca9 [gaim-migrate @ 13931]
Mark Doliner <markdoliner@pidgin.im>
parents: 11522
diff changeset
171 g_free(sip->status);
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
172 if (primitive == PURPLE_STATUS_AVAILABLE)
11718
90804d019837 [gaim-migrate @ 14009]
Mark Doliner <markdoliner@pidgin.im>
parents: 11658
diff changeset
173 sip->status = g_strdup("available");
90804d019837 [gaim-migrate @ 14009]
Mark Doliner <markdoliner@pidgin.im>
parents: 11658
diff changeset
174 else
90804d019837 [gaim-migrate @ 14009]
Mark Doliner <markdoliner@pidgin.im>
parents: 11658
diff changeset
175 sip->status = g_strdup("busy");
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
176
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
177 do_notifies(sip);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
178 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
179 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
180
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
181 static struct sip_connection *connection_find(struct simple_account_data *sip, int fd) {
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
182 struct sip_connection *ret = NULL;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
183 GSList *entry = sip->openconns;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
184 while(entry) {
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
185 ret = entry->data;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
186 if(ret->fd == fd) return ret;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
187 entry = entry->next;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
188 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
189 return NULL;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
190 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
191
14131
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
192 static struct simple_watcher *watcher_find(struct simple_account_data *sip,
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
193 const gchar *name) {
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
194 struct simple_watcher *watcher;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
195 GSList *entry = sip->watcher;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
196 while(entry) {
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
197 watcher = entry->data;
38258
9a6551eba09c Replace !strcmp() with purple_strequal()
qarkai <qarkai@gmail.com>
parents: 36041
diff changeset
198 if(purple_strequal(name, watcher->name)) return watcher;
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
199 entry = entry->next;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
200 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
201 return NULL;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
202 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
203
14131
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
204 static struct simple_watcher *watcher_create(struct simple_account_data *sip,
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
205 const gchar *name, const gchar *callid, const gchar *ourtag,
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
206 const gchar *theirtag, gboolean needsxpidf) {
13093
e27434c31f00 [gaim-migrate @ 15454]
Daniel Atallah <datallah@pidgin.im>
parents: 13089
diff changeset
207 struct simple_watcher *watcher = g_new0(struct simple_watcher, 1);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
208 watcher->name = g_strdup(name);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
209 watcher->dialog.callid = g_strdup(callid);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
210 watcher->dialog.ourtag = g_strdup(ourtag);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
211 watcher->dialog.theirtag = g_strdup(theirtag);
13178
824d50326672 [gaim-migrate @ 15540]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13130
diff changeset
212 watcher->needsxpidf = needsxpidf;
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
213 sip->watcher = g_slist_append(sip->watcher, watcher);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
214 return watcher;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
215 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
216
14131
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
217 static void watcher_remove(struct simple_account_data *sip, const gchar *name) {
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
218 struct simple_watcher *watcher = watcher_find(sip, name);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
219 sip->watcher = g_slist_remove(sip->watcher, watcher);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
220 g_free(watcher->name);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
221 g_free(watcher->dialog.callid);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
222 g_free(watcher->dialog.ourtag);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
223 g_free(watcher->dialog.theirtag);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
224 g_free(watcher);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
225 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
226
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
227 static struct sip_connection *connection_create(struct simple_account_data *sip, int fd) {
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
228 struct sip_connection *ret = g_new0(struct sip_connection, 1);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
229 ret->fd = fd;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
230 sip->openconns = g_slist_append(sip->openconns, ret);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
231 return ret;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
232 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
233
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
234 static void connection_remove(struct simple_account_data *sip, int fd) {
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
235 struct sip_connection *conn = connection_find(sip, fd);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
236 sip->openconns = g_slist_remove(sip->openconns, conn);
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
237 if(conn->inputhandler) purple_input_remove(conn->inputhandler);
11650
757d7fbd4ca9 [gaim-migrate @ 13931]
Mark Doliner <markdoliner@pidgin.im>
parents: 11522
diff changeset
238 g_free(conn->inbuf);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
239 g_free(conn);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
240 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
241
11346
4af1dc4b2c44 [gaim-migrate @ 13563]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11345
diff changeset
242 static void connection_free_all(struct simple_account_data *sip) {
4af1dc4b2c44 [gaim-migrate @ 13563]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11345
diff changeset
243 struct sip_connection *ret = NULL;
4af1dc4b2c44 [gaim-migrate @ 13563]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11345
diff changeset
244 GSList *entry = sip->openconns;
4af1dc4b2c44 [gaim-migrate @ 13563]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11345
diff changeset
245 while(entry) {
4af1dc4b2c44 [gaim-migrate @ 13563]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11345
diff changeset
246 ret = entry->data;
4af1dc4b2c44 [gaim-migrate @ 13563]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11345
diff changeset
247 connection_remove(sip, ret->fd);
4af1dc4b2c44 [gaim-migrate @ 13563]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11345
diff changeset
248 entry = sip->openconns;
4af1dc4b2c44 [gaim-migrate @ 13563]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11345
diff changeset
249 }
4af1dc4b2c44 [gaim-migrate @ 13563]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11345
diff changeset
250 }
4af1dc4b2c44 [gaim-migrate @ 13563]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11345
diff changeset
251
32315
2550a39e0285 Rename the _with_invite functions to their counterparts.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32300
diff changeset
252 static void simple_add_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group, const char *message)
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
253 {
32266
af94a3153685 Convert simple prpl to use accessor functions purple_connection_get_protocol_data() and purple_connection_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents: 32157
diff changeset
254 struct simple_account_data *sip = purple_connection_get_protocol_data(gc);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
255 struct simple_buddy *b;
24398
4865c2ee6ea8 Start hiding blist.h internals in prpls.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24040
diff changeset
256 const char *name = purple_buddy_get_name(buddy);
25911
f22097dc8413 propagate from branch 'im.pidgin.pidgin.next.minor' (head d24c4a9d28f21eaa47bd76e50ed31053733edcb1)
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 25865 25603
diff changeset
257 if(strncmp(name, "sip:", 4)) {
24398
4865c2ee6ea8 Start hiding blist.h internals in prpls.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24040
diff changeset
258 gchar *buf = g_strdup_printf("sip:%s", name);
34728
8efd73063ecf Renamed buddy list functions to more appropriate/simler names.
Ankit Vani <a@nevitus.org>
parents: 34706
diff changeset
259 purple_buddy_set_name(buddy, buf);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
260 g_free(buf);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
261 }
24398
4865c2ee6ea8 Start hiding blist.h internals in prpls.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24040
diff changeset
262 if(!g_hash_table_lookup(sip->buddies, name)) {
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
263 b = g_new0(struct simple_buddy, 1);
24398
4865c2ee6ea8 Start hiding blist.h internals in prpls.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24040
diff changeset
264 purple_debug_info("simple", "simple_add_buddy %s\n", name);
4865c2ee6ea8 Start hiding blist.h internals in prpls.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24040
diff changeset
265 b->name = g_strdup(name);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
266 g_hash_table_insert(sip->buddies, b->name, b);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
267 } else {
24398
4865c2ee6ea8 Start hiding blist.h internals in prpls.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24040
diff changeset
268 purple_debug_info("simple", "buddy %s already in internal list\n", name);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
269 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
270 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
271
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
272 static void simple_get_buddies(PurpleConnection *gc) {
27199
ab2af9d15cba Use purple_find_buddies() instead of iterating the buddy list.
Paul Aurich <darkrain42@pidgin.im>
parents: 26482
diff changeset
273 GSList *buddies;
24398
4865c2ee6ea8 Start hiding blist.h internals in prpls.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24040
diff changeset
274 PurpleAccount *account;
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
275
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
276 purple_debug_info("simple", "simple_get_buddies\n");
11396
468e60b682cd [gaim-migrate @ 13627]
Daniel Atallah <datallah@pidgin.im>
parents: 11383
diff changeset
277
24398
4865c2ee6ea8 Start hiding blist.h internals in prpls.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24040
diff changeset
278 account = purple_connection_get_account(gc);
34728
8efd73063ecf Renamed buddy list functions to more appropriate/simler names.
Ankit Vani <a@nevitus.org>
parents: 34706
diff changeset
279 buddies = purple_blist_find_buddies(account, NULL);
27199
ab2af9d15cba Use purple_find_buddies() instead of iterating the buddy list.
Paul Aurich <darkrain42@pidgin.im>
parents: 26482
diff changeset
280 while (buddies) {
ab2af9d15cba Use purple_find_buddies() instead of iterating the buddy list.
Paul Aurich <darkrain42@pidgin.im>
parents: 26482
diff changeset
281 PurpleBuddy *buddy = buddies->data;
32315
2550a39e0285 Rename the _with_invite functions to their counterparts.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32300
diff changeset
282 simple_add_buddy(gc, buddy, purple_buddy_get_group(buddy), NULL);
27199
ab2af9d15cba Use purple_find_buddies() instead of iterating the buddy list.
Paul Aurich <darkrain42@pidgin.im>
parents: 26482
diff changeset
283
ab2af9d15cba Use purple_find_buddies() instead of iterating the buddy list.
Paul Aurich <darkrain42@pidgin.im>
parents: 26482
diff changeset
284 buddies = g_slist_delete_link(buddies, buddies);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
285 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
286 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
287
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
288 static void simple_remove_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group)
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
289 {
24398
4865c2ee6ea8 Start hiding blist.h internals in prpls.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24040
diff changeset
290 const char *name = purple_buddy_get_name(buddy);
32266
af94a3153685 Convert simple prpl to use accessor functions purple_connection_get_protocol_data() and purple_connection_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents: 32157
diff changeset
291 struct simple_account_data *sip = purple_connection_get_protocol_data(gc);
24398
4865c2ee6ea8 Start hiding blist.h internals in prpls.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24040
diff changeset
292 struct simple_buddy *b = g_hash_table_lookup(sip->buddies, name);
4865c2ee6ea8 Start hiding blist.h internals in prpls.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24040
diff changeset
293 g_hash_table_remove(sip->buddies, name);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
294 g_free(b->name);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
295 g_free(b);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
296 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
297
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
298 static GList *simple_status_types(PurpleAccount *acc) {
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
299 PurpleStatusType *type;
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
300 GList *types = NULL;
12456
94b229fc8203 [gaim-migrate @ 14765]
Mark Doliner <markdoliner@pidgin.im>
parents: 12389
diff changeset
301
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
302 type = purple_status_type_new_with_attrs(
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
303 PURPLE_STATUS_AVAILABLE, NULL, NULL, TRUE, TRUE, FALSE,
35005
bff56dfca65d Renamed purple_g_value_* to purple_value_*
Ankit Vani <a@nevitus.org>
parents: 34935
diff changeset
304 "message", _("Message"), purple_value_new(G_TYPE_STRING),
12595
8108c22aa723 [gaim-migrate @ 14925]
Richard Laager <rlaager@pidgin.im>
parents: 12571
diff changeset
305 NULL);
11396
468e60b682cd [gaim-migrate @ 13627]
Daniel Atallah <datallah@pidgin.im>
parents: 11383
diff changeset
306 types = g_list_append(types, type);
468e60b682cd [gaim-migrate @ 13627]
Daniel Atallah <datallah@pidgin.im>
parents: 11383
diff changeset
307
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
308 type = purple_status_type_new_full(
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
309 PURPLE_STATUS_OFFLINE, NULL, NULL, TRUE, TRUE, FALSE);
12657
fd16423a0383 [gaim-migrate @ 15000]
Mark Doliner <markdoliner@pidgin.im>
parents: 12645
diff changeset
310 types = g_list_append(types, type);
fd16423a0383 [gaim-migrate @ 15000]
Mark Doliner <markdoliner@pidgin.im>
parents: 12645
diff changeset
311
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
312 return types;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
313 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
314
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
315 static gchar *auth_header(struct simple_account_data *sip,
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
316 struct sip_auth *auth, const gchar *method, const gchar *target) {
11346
4af1dc4b2c44 [gaim-migrate @ 13563]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11345
diff changeset
317 gchar noncecount[9];
12382
5ef67596b420 [gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents: 12216
diff changeset
318 gchar *response;
11346
4af1dc4b2c44 [gaim-migrate @ 13563]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11345
diff changeset
319 gchar *ret;
13089
e1ab8bfba211 [gaim-migrate @ 15450]
Mark Doliner <markdoliner@pidgin.im>
parents: 13086
diff changeset
320 const char *authuser;
e1ab8bfba211 [gaim-migrate @ 15450]
Mark Doliner <markdoliner@pidgin.im>
parents: 13086
diff changeset
321
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
322 authuser = purple_account_get_string(sip->account, "authuser", sip->username);
13089
e1ab8bfba211 [gaim-migrate @ 15450]
Mark Doliner <markdoliner@pidgin.im>
parents: 13086
diff changeset
323
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
324 if(!authuser || strlen(authuser) < 1) {
13085
c80913901342 [gaim-migrate @ 15446]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13084
diff changeset
325 authuser = sip->username;
c80913901342 [gaim-migrate @ 15446]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13084
diff changeset
326 }
11409
2a3466f4a32c [gaim-migrate @ 13646]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11396
diff changeset
327
2a3466f4a32c [gaim-migrate @ 13646]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11396
diff changeset
328 if(auth->type == 1) { /* Digest */
2a3466f4a32c [gaim-migrate @ 13646]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11396
diff changeset
329 sprintf(noncecount, "%08d", auth->nc++);
34557
295cd5bf4c41 Refactored protocols msn, myspace, oscar, simple, yahoo to use GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents: 34529
diff changeset
330 response = purple_http_digest_calculate_response(
12389
7196ba664097 [gaim-migrate @ 14695]
Richard Laager <rlaager@pidgin.im>
parents: 12382
diff changeset
331 "md5", method, target, NULL, NULL,
12382
5ef67596b420 [gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents: 12216
diff changeset
332 auth->nonce, noncecount, NULL, auth->digest_session_key);
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
333 purple_debug(PURPLE_DEBUG_MISC, "simple", "response %s\n", response);
12382
5ef67596b420 [gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents: 12216
diff changeset
334
17187
78b7ae95ad45 Fix an extra \r\n in the Authorization header. Fixes #965.
Daniel Atallah <datallah@pidgin.im>
parents: 17185
diff changeset
335 ret = g_strdup_printf("Digest username=\"%s\", realm=\"%s\", nonce=\"%s\", uri=\"%s\", nc=\"%s\", response=\"%s\"", authuser, auth->realm, auth->nonce, target, noncecount, response);
12382
5ef67596b420 [gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents: 12216
diff changeset
336 g_free(response);
11409
2a3466f4a32c [gaim-migrate @ 13646]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11396
diff changeset
337 return ret;
2a3466f4a32c [gaim-migrate @ 13646]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11396
diff changeset
338 } else if(auth->type == 2) { /* NTLM */
38409
751fa9e1fc8e simple: Port NTLM to Nettle
Mike Ruprecht <cmaiku@gmail.com>
parents: 38358
diff changeset
339 #ifdef HAVE_NETTLE
751fa9e1fc8e simple: Port NTLM to Nettle
Mike Ruprecht <cmaiku@gmail.com>
parents: 38358
diff changeset
340 const gchar *authdomain;
751fa9e1fc8e simple: Port NTLM to Nettle
Mike Ruprecht <cmaiku@gmail.com>
parents: 38358
diff changeset
341 gchar *tmp;
751fa9e1fc8e simple: Port NTLM to Nettle
Mike Ruprecht <cmaiku@gmail.com>
parents: 38358
diff changeset
342
751fa9e1fc8e simple: Port NTLM to Nettle
Mike Ruprecht <cmaiku@gmail.com>
parents: 38358
diff changeset
343 authdomain = purple_account_get_string(sip->account,
751fa9e1fc8e simple: Port NTLM to Nettle
Mike Ruprecht <cmaiku@gmail.com>
parents: 38358
diff changeset
344 "authdomain", "");
751fa9e1fc8e simple: Port NTLM to Nettle
Mike Ruprecht <cmaiku@gmail.com>
parents: 38358
diff changeset
345
13085
c80913901342 [gaim-migrate @ 15446]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13084
diff changeset
346 if(auth->nc == 3 && auth->nonce) {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
347 /* TODO: Don't hardcode "purple" as the hostname */
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
348 ret = purple_ntlm_gen_type3(authuser, sip->password, "purple", authdomain, (const guint8 *)auth->nonce, &auth->flags);
17187
78b7ae95ad45 Fix an extra \r\n in the Authorization header. Fixes #965.
Daniel Atallah <datallah@pidgin.im>
parents: 17185
diff changeset
349 tmp = g_strdup_printf("NTLM qop=\"auth\", opaque=\"%s\", realm=\"%s\", targetname=\"%s\", gssapi-data=\"%s\"", auth->opaque, auth->realm, auth->target, ret);
11409
2a3466f4a32c [gaim-migrate @ 13646]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11396
diff changeset
350 g_free(ret);
2a3466f4a32c [gaim-migrate @ 13646]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11396
diff changeset
351 return tmp;
2a3466f4a32c [gaim-migrate @ 13646]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11396
diff changeset
352 }
17187
78b7ae95ad45 Fix an extra \r\n in the Authorization header. Fixes #965.
Daniel Atallah <datallah@pidgin.im>
parents: 17185
diff changeset
353 tmp = g_strdup_printf("NTLM qop=\"auth\", realm=\"%s\", targetname=\"%s\", gssapi-data=\"\"", auth->realm, auth->target);
11409
2a3466f4a32c [gaim-migrate @ 13646]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11396
diff changeset
354 return tmp;
38409
751fa9e1fc8e simple: Port NTLM to Nettle
Mike Ruprecht <cmaiku@gmail.com>
parents: 38358
diff changeset
355 #else
751fa9e1fc8e simple: Port NTLM to Nettle
Mike Ruprecht <cmaiku@gmail.com>
parents: 38358
diff changeset
356 /* Used without support enabled */
751fa9e1fc8e simple: Port NTLM to Nettle
Mike Ruprecht <cmaiku@gmail.com>
parents: 38358
diff changeset
357 g_return_val_if_reached(NULL);
751fa9e1fc8e simple: Port NTLM to Nettle
Mike Ruprecht <cmaiku@gmail.com>
parents: 38358
diff changeset
358 #endif /* HAVE_NETTLE */
11409
2a3466f4a32c [gaim-migrate @ 13646]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11396
diff changeset
359 }
11396
468e60b682cd [gaim-migrate @ 13627]
Daniel Atallah <datallah@pidgin.im>
parents: 11383
diff changeset
360
11346
4af1dc4b2c44 [gaim-migrate @ 13563]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11345
diff changeset
361 sprintf(noncecount, "%08d", auth->nc++);
34557
295cd5bf4c41 Refactored protocols msn, myspace, oscar, simple, yahoo to use GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents: 34529
diff changeset
362 response = purple_http_digest_calculate_response(
12389
7196ba664097 [gaim-migrate @ 14695]
Richard Laager <rlaager@pidgin.im>
parents: 12382
diff changeset
363 "md5", method, target, NULL, NULL,
12382
5ef67596b420 [gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents: 12216
diff changeset
364 auth->nonce, noncecount, NULL, auth->digest_session_key);
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
365 purple_debug(PURPLE_DEBUG_MISC, "simple", "response %s\n", response);
12382
5ef67596b420 [gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents: 12216
diff changeset
366
17187
78b7ae95ad45 Fix an extra \r\n in the Authorization header. Fixes #965.
Daniel Atallah <datallah@pidgin.im>
parents: 17185
diff changeset
367 ret = g_strdup_printf("Digest username=\"%s\", realm=\"%s\", nonce=\"%s\", uri=\"%s\", nc=\"%s\", response=\"%s\"", authuser, auth->realm, auth->nonce, target, noncecount, response);
12382
5ef67596b420 [gaim-migrate @ 14688]
Richard Laager <rlaager@pidgin.im>
parents: 12216
diff changeset
368 g_free(response);
11346
4af1dc4b2c44 [gaim-migrate @ 13563]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11345
diff changeset
369 return ret;
4af1dc4b2c44 [gaim-migrate @ 13563]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11345
diff changeset
370 }
4af1dc4b2c44 [gaim-migrate @ 13563]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11345
diff changeset
371
14131
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
372 static char *parse_attribute(const char *attrname, const char *source) {
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
373 const char *tmp, *tmp2;
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
374 char *retval = NULL;
12746
7ee4a8a55435 [gaim-migrate @ 15093]
Daniel Atallah <datallah@pidgin.im>
parents: 12745
diff changeset
375 int len = strlen(attrname);
7ee4a8a55435 [gaim-migrate @ 15093]
Daniel Atallah <datallah@pidgin.im>
parents: 12745
diff changeset
376
23086
413ccc075f8b Patch from Will Hawkins to fix SIMPLE authentication on some servers.
Daniel Atallah <datallah@pidgin.im>
parents: 22942
diff changeset
377 /* we know that source is NULL-terminated.
413ccc075f8b Patch from Will Hawkins to fix SIMPLE authentication on some servers.
Daniel Atallah <datallah@pidgin.im>
parents: 22942
diff changeset
378 * Therefore this loop won't be infinite.
413ccc075f8b Patch from Will Hawkins to fix SIMPLE authentication on some servers.
Daniel Atallah <datallah@pidgin.im>
parents: 22942
diff changeset
379 */
413ccc075f8b Patch from Will Hawkins to fix SIMPLE authentication on some servers.
Daniel Atallah <datallah@pidgin.im>
parents: 22942
diff changeset
380 while (source[0] == ' ')
413ccc075f8b Patch from Will Hawkins to fix SIMPLE authentication on some servers.
Daniel Atallah <datallah@pidgin.im>
parents: 22942
diff changeset
381 source++;
413ccc075f8b Patch from Will Hawkins to fix SIMPLE authentication on some servers.
Daniel Atallah <datallah@pidgin.im>
parents: 22942
diff changeset
382
12746
7ee4a8a55435 [gaim-migrate @ 15093]
Daniel Atallah <datallah@pidgin.im>
parents: 12745
diff changeset
383 if(!strncmp(source, attrname, len)) {
7ee4a8a55435 [gaim-migrate @ 15093]
Daniel Atallah <datallah@pidgin.im>
parents: 12745
diff changeset
384 tmp = source + len;
7ee4a8a55435 [gaim-migrate @ 15093]
Daniel Atallah <datallah@pidgin.im>
parents: 12745
diff changeset
385 tmp2 = g_strstr_len(tmp, strlen(tmp), "\"");
7ee4a8a55435 [gaim-migrate @ 15093]
Daniel Atallah <datallah@pidgin.im>
parents: 12745
diff changeset
386 if(tmp2)
7ee4a8a55435 [gaim-migrate @ 15093]
Daniel Atallah <datallah@pidgin.im>
parents: 12745
diff changeset
387 retval = g_strndup(tmp, tmp2 - tmp);
13086
0e5a0a33475b [gaim-migrate @ 15447]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13085
diff changeset
388 else
0e5a0a33475b [gaim-migrate @ 15447]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13085
diff changeset
389 retval = g_strdup(tmp);
12746
7ee4a8a55435 [gaim-migrate @ 15093]
Daniel Atallah <datallah@pidgin.im>
parents: 12745
diff changeset
390 }
7ee4a8a55435 [gaim-migrate @ 15093]
Daniel Atallah <datallah@pidgin.im>
parents: 12745
diff changeset
391
7ee4a8a55435 [gaim-migrate @ 15093]
Daniel Atallah <datallah@pidgin.im>
parents: 12745
diff changeset
392 return retval;
7ee4a8a55435 [gaim-migrate @ 15093]
Daniel Atallah <datallah@pidgin.im>
parents: 12745
diff changeset
393 }
7ee4a8a55435 [gaim-migrate @ 15093]
Daniel Atallah <datallah@pidgin.im>
parents: 12745
diff changeset
394
21100
814637ced463 Some constification, which also found and fixed some potential double-free
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 21076
diff changeset
395 static void fill_auth(struct simple_account_data *sip, const gchar *hdr, struct sip_auth *auth) {
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
396 int i = 0;
13089
e1ab8bfba211 [gaim-migrate @ 15450]
Mark Doliner <markdoliner@pidgin.im>
parents: 13086
diff changeset
397 const char *authuser;
11424
b0f8535daa74 [gaim-migrate @ 13661]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11409
diff changeset
398 char *tmp;
11439
e76bc2f9deb0 [gaim-migrate @ 13676]
Daniel Atallah <datallah@pidgin.im>
parents: 11424
diff changeset
399 gchar **parts;
13085
c80913901342 [gaim-migrate @ 15446]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13084
diff changeset
400
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
401 authuser = purple_account_get_string(sip->account, "authuser", sip->username);
13089
e1ab8bfba211 [gaim-migrate @ 15450]
Mark Doliner <markdoliner@pidgin.im>
parents: 13086
diff changeset
402
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
403 if(!authuser || strlen(authuser) < 1) {
13085
c80913901342 [gaim-migrate @ 15446]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13084
diff changeset
404 authuser = sip->username;
c80913901342 [gaim-migrate @ 15446]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13084
diff changeset
405 }
13089
e1ab8bfba211 [gaim-migrate @ 15450]
Mark Doliner <markdoliner@pidgin.im>
parents: 13086
diff changeset
406
11346
4af1dc4b2c44 [gaim-migrate @ 13563]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11345
diff changeset
407 if(!hdr) {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
408 purple_debug_error("simple", "fill_auth: hdr==NULL\n");
11346
4af1dc4b2c44 [gaim-migrate @ 13563]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11345
diff changeset
409 return;
4af1dc4b2c44 [gaim-migrate @ 13563]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11345
diff changeset
410 }
11409
2a3466f4a32c [gaim-migrate @ 13646]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11396
diff changeset
411
18552
810a338ef085 Use the glib strcasecmp functions everywhere, as we've had reports of
Richard Laager <rlaager@pidgin.im>
parents: 17653
diff changeset
412 if(!g_ascii_strncasecmp(hdr, "NTLM", 4)) {
38409
751fa9e1fc8e simple: Port NTLM to Nettle
Mike Ruprecht <cmaiku@gmail.com>
parents: 38358
diff changeset
413 #ifdef HAVE_NETTLE
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
414 purple_debug_info("simple", "found NTLM\n");
11409
2a3466f4a32c [gaim-migrate @ 13646]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11396
diff changeset
415 auth->type = 2;
23086
413ccc075f8b Patch from Will Hawkins to fix SIMPLE authentication on some servers.
Daniel Atallah <datallah@pidgin.im>
parents: 22942
diff changeset
416 parts = g_strsplit(hdr+5, "\",", 0);
13348
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
417 i = 0;
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
418 while(parts[i]) {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
419 purple_debug_info("simple", "parts[i] %s\n", parts[i]);
13348
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
420 if((tmp = parse_attribute("gssapi-data=\"", parts[i]))) {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
421 auth->nonce = g_memdup(purple_ntlm_parse_type2(tmp, &auth->flags), 8);
13348
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
422 g_free(tmp);
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
423 }
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
424 if((tmp = parse_attribute("targetname=\"",
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
425 parts[i]))) {
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
426 auth->target = tmp;
11424
b0f8535daa74 [gaim-migrate @ 13661]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11409
diff changeset
427 }
13348
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
428 else if((tmp = parse_attribute("realm=\"",
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
429 parts[i]))) {
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
430 auth->realm = tmp;
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
431 }
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
432 else if((tmp = parse_attribute("opaque=\"", parts[i]))) {
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
433 auth->opaque = tmp;
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
434 }
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
435 i++;
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
436 }
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
437 g_strfreev(parts);
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
438 auth->nc = 1;
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
439 if(!strstr(hdr, "gssapi-data")) {
11409
2a3466f4a32c [gaim-migrate @ 13646]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11396
diff changeset
440 auth->nc = 1;
13085
c80913901342 [gaim-migrate @ 15446]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13084
diff changeset
441 } else {
11409
2a3466f4a32c [gaim-migrate @ 13646]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11396
diff changeset
442 auth->nc = 3;
23086
413ccc075f8b Patch from Will Hawkins to fix SIMPLE authentication on some servers.
Daniel Atallah <datallah@pidgin.im>
parents: 22942
diff changeset
443 }
413ccc075f8b Patch from Will Hawkins to fix SIMPLE authentication on some servers.
Daniel Atallah <datallah@pidgin.im>
parents: 22942
diff changeset
444
11409
2a3466f4a32c [gaim-migrate @ 13646]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11396
diff changeset
445 return;
38409
751fa9e1fc8e simple: Port NTLM to Nettle
Mike Ruprecht <cmaiku@gmail.com>
parents: 38358
diff changeset
446 #else
751fa9e1fc8e simple: Port NTLM to Nettle
Mike Ruprecht <cmaiku@gmail.com>
parents: 38358
diff changeset
447 purple_debug_error("simple", "NTLM auth unsupported without "
751fa9e1fc8e simple: Port NTLM to Nettle
Mike Ruprecht <cmaiku@gmail.com>
parents: 38358
diff changeset
448 "libnettle support. Please rebuild with "
751fa9e1fc8e simple: Port NTLM to Nettle
Mike Ruprecht <cmaiku@gmail.com>
parents: 38358
diff changeset
449 "libnettle support for this feature.\n");
751fa9e1fc8e simple: Port NTLM to Nettle
Mike Ruprecht <cmaiku@gmail.com>
parents: 38358
diff changeset
450 #endif /* HAVE_NETTLE */
23086
413ccc075f8b Patch from Will Hawkins to fix SIMPLE authentication on some servers.
Daniel Atallah <datallah@pidgin.im>
parents: 22942
diff changeset
451 } else if(!g_ascii_strncasecmp(hdr, "DIGEST", 6)) {
413ccc075f8b Patch from Will Hawkins to fix SIMPLE authentication on some servers.
Daniel Atallah <datallah@pidgin.im>
parents: 22942
diff changeset
452
413ccc075f8b Patch from Will Hawkins to fix SIMPLE authentication on some servers.
Daniel Atallah <datallah@pidgin.im>
parents: 22942
diff changeset
453 purple_debug_info("simple", "found DIGEST\n");
413ccc075f8b Patch from Will Hawkins to fix SIMPLE authentication on some servers.
Daniel Atallah <datallah@pidgin.im>
parents: 22942
diff changeset
454
413ccc075f8b Patch from Will Hawkins to fix SIMPLE authentication on some servers.
Daniel Atallah <datallah@pidgin.im>
parents: 22942
diff changeset
455 auth->type = 1;
413ccc075f8b Patch from Will Hawkins to fix SIMPLE authentication on some servers.
Daniel Atallah <datallah@pidgin.im>
parents: 22942
diff changeset
456 parts = g_strsplit(hdr+7, ",", 0);
413ccc075f8b Patch from Will Hawkins to fix SIMPLE authentication on some servers.
Daniel Atallah <datallah@pidgin.im>
parents: 22942
diff changeset
457 while(parts[i]) {
413ccc075f8b Patch from Will Hawkins to fix SIMPLE authentication on some servers.
Daniel Atallah <datallah@pidgin.im>
parents: 22942
diff changeset
458 if((tmp = parse_attribute("nonce=\"", parts[i]))) {
413ccc075f8b Patch from Will Hawkins to fix SIMPLE authentication on some servers.
Daniel Atallah <datallah@pidgin.im>
parents: 22942
diff changeset
459 auth->nonce = tmp;
413ccc075f8b Patch from Will Hawkins to fix SIMPLE authentication on some servers.
Daniel Atallah <datallah@pidgin.im>
parents: 22942
diff changeset
460 }
413ccc075f8b Patch from Will Hawkins to fix SIMPLE authentication on some servers.
Daniel Atallah <datallah@pidgin.im>
parents: 22942
diff changeset
461 else if((tmp = parse_attribute("realm=\"", parts[i]))) {
413ccc075f8b Patch from Will Hawkins to fix SIMPLE authentication on some servers.
Daniel Atallah <datallah@pidgin.im>
parents: 22942
diff changeset
462 auth->realm = tmp;
413ccc075f8b Patch from Will Hawkins to fix SIMPLE authentication on some servers.
Daniel Atallah <datallah@pidgin.im>
parents: 22942
diff changeset
463 }
413ccc075f8b Patch from Will Hawkins to fix SIMPLE authentication on some servers.
Daniel Atallah <datallah@pidgin.im>
parents: 22942
diff changeset
464 i++;
413ccc075f8b Patch from Will Hawkins to fix SIMPLE authentication on some servers.
Daniel Atallah <datallah@pidgin.im>
parents: 22942
diff changeset
465 }
413ccc075f8b Patch from Will Hawkins to fix SIMPLE authentication on some servers.
Daniel Atallah <datallah@pidgin.im>
parents: 22942
diff changeset
466 g_strfreev(parts);
413ccc075f8b Patch from Will Hawkins to fix SIMPLE authentication on some servers.
Daniel Atallah <datallah@pidgin.im>
parents: 22942
diff changeset
467 purple_debug(PURPLE_DEBUG_MISC, "simple", "nonce: %s realm: %s\n",
413ccc075f8b Patch from Will Hawkins to fix SIMPLE authentication on some servers.
Daniel Atallah <datallah@pidgin.im>
parents: 22942
diff changeset
468 auth->nonce ? auth->nonce : "(null)",
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 30138
diff changeset
469 auth->realm ? auth->realm : "(null)");
23086
413ccc075f8b Patch from Will Hawkins to fix SIMPLE authentication on some servers.
Daniel Atallah <datallah@pidgin.im>
parents: 22942
diff changeset
470
413ccc075f8b Patch from Will Hawkins to fix SIMPLE authentication on some servers.
Daniel Atallah <datallah@pidgin.im>
parents: 22942
diff changeset
471 if(auth->realm) {
34557
295cd5bf4c41 Refactored protocols msn, myspace, oscar, simple, yahoo to use GObject-based PurpleCipher
Ankit Vani <a@nevitus.org>
parents: 34529
diff changeset
472 auth->digest_session_key = purple_http_digest_calculate_session_key(
23086
413ccc075f8b Patch from Will Hawkins to fix SIMPLE authentication on some servers.
Daniel Atallah <datallah@pidgin.im>
parents: 22942
diff changeset
473 "md5", authuser, auth->realm, sip->password, auth->nonce, NULL);
413ccc075f8b Patch from Will Hawkins to fix SIMPLE authentication on some servers.
Daniel Atallah <datallah@pidgin.im>
parents: 22942
diff changeset
474
413ccc075f8b Patch from Will Hawkins to fix SIMPLE authentication on some servers.
Daniel Atallah <datallah@pidgin.im>
parents: 22942
diff changeset
475 auth->nc = 1;
413ccc075f8b Patch from Will Hawkins to fix SIMPLE authentication on some servers.
Daniel Atallah <datallah@pidgin.im>
parents: 22942
diff changeset
476 }
413ccc075f8b Patch from Will Hawkins to fix SIMPLE authentication on some servers.
Daniel Atallah <datallah@pidgin.im>
parents: 22942
diff changeset
477
413ccc075f8b Patch from Will Hawkins to fix SIMPLE authentication on some servers.
Daniel Atallah <datallah@pidgin.im>
parents: 22942
diff changeset
478 } else {
413ccc075f8b Patch from Will Hawkins to fix SIMPLE authentication on some servers.
Daniel Atallah <datallah@pidgin.im>
parents: 22942
diff changeset
479 purple_debug_error("simple", "Unsupported or bad WWW-Authenticate header (%s).\n", hdr);
11409
2a3466f4a32c [gaim-migrate @ 13646]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11396
diff changeset
480 }
2a3466f4a32c [gaim-migrate @ 13646]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11396
diff changeset
481
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
482 }
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
483
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
484 static void simple_canwrite_cb(gpointer data, gint source, PurpleInputCondition cond) {
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
485 PurpleConnection *gc = data;
32266
af94a3153685 Convert simple prpl to use accessor functions purple_connection_get_protocol_data() and purple_connection_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents: 32157
diff changeset
486 struct simple_account_data *sip = purple_connection_get_protocol_data(gc);
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
487 gsize max_write;
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
488 gssize written;
34529
68cf25486001 GObjectify PurpleCircBuffer as PurpleCircularBuffer (from gobjectification branch)
Ankit Vani <a@nevitus.org>
parents: 34111
diff changeset
489 const gchar *output = NULL;
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
490
34529
68cf25486001 GObjectify PurpleCircBuffer as PurpleCircularBuffer (from gobjectification branch)
Ankit Vani <a@nevitus.org>
parents: 34111
diff changeset
491 max_write = purple_circular_buffer_get_max_read(sip->txbuf);
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
492
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
493 if(max_write == 0) {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
494 purple_input_remove(sip->tx_handler);
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
495 sip->tx_handler = 0;
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
496 return;
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
497 }
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
498
34529
68cf25486001 GObjectify PurpleCircBuffer as PurpleCircularBuffer (from gobjectification branch)
Ankit Vani <a@nevitus.org>
parents: 34111
diff changeset
499 output = purple_circular_buffer_get_output(sip->txbuf);
68cf25486001 GObjectify PurpleCircBuffer as PurpleCircularBuffer (from gobjectification branch)
Ankit Vani <a@nevitus.org>
parents: 34111
diff changeset
500
68cf25486001 GObjectify PurpleCircBuffer as PurpleCircularBuffer (from gobjectification branch)
Ankit Vani <a@nevitus.org>
parents: 34111
diff changeset
501 written = write(sip->fd, output, max_write);
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
502
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
503 if(written < 0 && errno == EAGAIN)
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
504 written = 0;
27635
0cd19038c417 More uniformity among disconnect error messages
Mark Doliner <markdoliner@pidgin.im>
parents: 27350
diff changeset
505 else if (written <= 0) {
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
506 /*TODO: do we really want to disconnect on a failure to write?*/
27635
0cd19038c417 More uniformity among disconnect error messages
Mark Doliner <markdoliner@pidgin.im>
parents: 27350
diff changeset
507 gchar *tmp = g_strdup_printf(_("Lost connection with server: %s"),
0cd19038c417 More uniformity among disconnect error messages
Mark Doliner <markdoliner@pidgin.im>
parents: 27350
diff changeset
508 g_strerror(errno));
32157
39ba2e2492ee Rename purple_connection_error_reason to purple_connection_error
Mark Doliner <markdoliner@pidgin.im>
parents: 31949
diff changeset
509 purple_connection_error(gc,
27635
0cd19038c417 More uniformity among disconnect error messages
Mark Doliner <markdoliner@pidgin.im>
parents: 27350
diff changeset
510 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp);
0cd19038c417 More uniformity among disconnect error messages
Mark Doliner <markdoliner@pidgin.im>
parents: 27350
diff changeset
511 g_free(tmp);
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
512 return;
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
513 }
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
514
34529
68cf25486001 GObjectify PurpleCircBuffer as PurpleCircularBuffer (from gobjectification branch)
Ankit Vani <a@nevitus.org>
parents: 34111
diff changeset
515 purple_circular_buffer_mark_read(sip->txbuf, written);
11346
4af1dc4b2c44 [gaim-migrate @ 13563]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11345
diff changeset
516 }
4af1dc4b2c44 [gaim-migrate @ 13563]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11345
diff changeset
517
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
518 static void simple_input_cb(gpointer data, gint source, PurpleInputCondition cond);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
519
27635
0cd19038c417 More uniformity among disconnect error messages
Mark Doliner <markdoliner@pidgin.im>
parents: 27350
diff changeset
520 static void send_later_cb(gpointer data, gint source, const gchar *error_message) {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
521 PurpleConnection *gc = data;
14180
77010795da2c [gaim-migrate @ 16752]
Mark Doliner <markdoliner@pidgin.im>
parents: 14170
diff changeset
522 struct simple_account_data *sip;
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
523 struct sip_connection *conn;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
524
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
525 if(source < 0) {
27635
0cd19038c417 More uniformity among disconnect error messages
Mark Doliner <markdoliner@pidgin.im>
parents: 27350
diff changeset
526 gchar *tmp = g_strdup_printf(_("Unable to connect: %s"),
0cd19038c417 More uniformity among disconnect error messages
Mark Doliner <markdoliner@pidgin.im>
parents: 27350
diff changeset
527 error_message);
32157
39ba2e2492ee Rename purple_connection_error_reason to purple_connection_error
Mark Doliner <markdoliner@pidgin.im>
parents: 31949
diff changeset
528 purple_connection_error(gc,
27635
0cd19038c417 More uniformity among disconnect error messages
Mark Doliner <markdoliner@pidgin.im>
parents: 27350
diff changeset
529 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp);
0cd19038c417 More uniformity among disconnect error messages
Mark Doliner <markdoliner@pidgin.im>
parents: 27350
diff changeset
530 g_free(tmp);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
531 return;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
532 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
533
32266
af94a3153685 Convert simple prpl to use accessor functions purple_connection_get_protocol_data() and purple_connection_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents: 32157
diff changeset
534 sip = purple_connection_get_protocol_data(gc);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
535 sip->fd = source;
13058
2bf79aa07199 [gaim-migrate @ 15420]
Daniel Atallah <datallah@pidgin.im>
parents: 12909
diff changeset
536 sip->connecting = FALSE;
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
537
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
538 simple_canwrite_cb(gc, sip->fd, PURPLE_INPUT_WRITE);
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
539
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
540 /* If there is more to write now, we need to register a handler */
34529
68cf25486001 GObjectify PurpleCircBuffer as PurpleCircularBuffer (from gobjectification branch)
Ankit Vani <a@nevitus.org>
parents: 34111
diff changeset
541 if(purple_circular_buffer_get_used(sip->txbuf) > 0)
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
542 sip->tx_handler = purple_input_add(sip->fd, PURPLE_INPUT_WRITE,
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
543 simple_canwrite_cb, gc);
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
544
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
545 conn = connection_create(sip, source);
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
546 conn->inputhandler = purple_input_add(sip->fd, PURPLE_INPUT_READ, simple_input_cb, gc);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
547 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
548
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
549
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
550 static void sendlater(PurpleConnection *gc, const char *buf) {
32266
af94a3153685 Convert simple prpl to use accessor functions purple_connection_get_protocol_data() and purple_connection_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents: 32157
diff changeset
551 struct simple_account_data *sip = purple_connection_get_protocol_data(gc);
14151
34427f138b1f [gaim-migrate @ 16712]
Mark Doliner <markdoliner@pidgin.im>
parents: 14132
diff changeset
552
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
553 if(!sip->connecting) {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
554 purple_debug_info("simple", "connecting to %s port %d\n", sip->realhostname ? sip->realhostname : "{NULL}", sip->realport);
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
555 if (purple_proxy_connect(gc, sip->account, sip->realhostname, sip->realport, send_later_cb, gc) == NULL) {
32157
39ba2e2492ee Rename purple_connection_error_reason to purple_connection_error
Mark Doliner <markdoliner@pidgin.im>
parents: 31949
diff changeset
556 purple_connection_error(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, _("Unable to connect"));
11396
468e60b682cd [gaim-migrate @ 13627]
Daniel Atallah <datallah@pidgin.im>
parents: 11383
diff changeset
557 }
13058
2bf79aa07199 [gaim-migrate @ 15420]
Daniel Atallah <datallah@pidgin.im>
parents: 12909
diff changeset
558 sip->connecting = TRUE;
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
559 }
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
560
34529
68cf25486001 GObjectify PurpleCircBuffer as PurpleCircularBuffer (from gobjectification branch)
Ankit Vani <a@nevitus.org>
parents: 34111
diff changeset
561 if(purple_circular_buffer_get_max_read(sip->txbuf) > 0)
68cf25486001 GObjectify PurpleCircBuffer as PurpleCircularBuffer (from gobjectification branch)
Ankit Vani <a@nevitus.org>
parents: 34111
diff changeset
562 purple_circular_buffer_append(sip->txbuf, "\r\n", 2);
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
563
34529
68cf25486001 GObjectify PurpleCircBuffer as PurpleCircularBuffer (from gobjectification branch)
Ankit Vani <a@nevitus.org>
parents: 34111
diff changeset
564 purple_circular_buffer_append(sip->txbuf, buf, strlen(buf));
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
565 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
566
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
567 static void sendout_pkt(PurpleConnection *gc, const char *buf) {
32266
af94a3153685 Convert simple prpl to use accessor functions purple_connection_get_protocol_data() and purple_connection_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents: 32157
diff changeset
568 struct simple_account_data *sip = purple_connection_get_protocol_data(gc);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
569 time_t currtime = time(NULL);
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
570 int writelen = strlen(buf);
11396
468e60b682cd [gaim-migrate @ 13627]
Daniel Atallah <datallah@pidgin.im>
parents: 11383
diff changeset
571
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
572 purple_debug(PURPLE_DEBUG_MISC, "simple", "\n\nsending - %s\n######\n%s\n######\n\n", ctime(&currtime), buf);
11189
5ac07336091e [gaim-migrate @ 13307]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11181
diff changeset
573 if(sip->udp) {
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
574 if(sendto(sip->fd, buf, writelen, 0, (struct sockaddr*)&sip->serveraddr, sizeof(struct sockaddr_in)) < writelen) {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
575 purple_debug_info("simple", "could not send packet\n");
11189
5ac07336091e [gaim-migrate @ 13307]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11181
diff changeset
576 }
5ac07336091e [gaim-migrate @ 13307]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11181
diff changeset
577 } else {
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
578 int ret;
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
579 if(sip->fd < 0) {
11189
5ac07336091e [gaim-migrate @ 13307]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11181
diff changeset
580 sendlater(gc, buf);
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
581 return;
11189
5ac07336091e [gaim-migrate @ 13307]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11181
diff changeset
582 }
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
583
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
584 if(sip->tx_handler) {
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
585 ret = -1;
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
586 errno = EAGAIN;
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
587 } else
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
588 ret = write(sip->fd, buf, writelen);
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
589
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
590 if (ret < 0 && errno == EAGAIN)
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
591 ret = 0;
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
592 else if(ret <= 0) { /* XXX: When does this happen legitimately? */
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
593 sendlater(gc, buf);
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
594 return;
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
595 }
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
596
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
597 if (ret < writelen) {
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
598 if(!sip->tx_handler)
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
599 sip->tx_handler = purple_input_add(sip->fd,
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
600 PURPLE_INPUT_WRITE, simple_canwrite_cb,
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
601 gc);
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
602
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
603 /* XXX: is it OK to do this? You might get part of a request sent
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
604 with part of another. */
34529
68cf25486001 GObjectify PurpleCircBuffer as PurpleCircularBuffer (from gobjectification branch)
Ankit Vani <a@nevitus.org>
parents: 34111
diff changeset
605 if(purple_circular_buffer_get_used(sip->txbuf) > 0)
68cf25486001 GObjectify PurpleCircBuffer as PurpleCircularBuffer (from gobjectification branch)
Ankit Vani <a@nevitus.org>
parents: 34111
diff changeset
606 purple_circular_buffer_append(sip->txbuf, "\r\n", 2);
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
607
34529
68cf25486001 GObjectify PurpleCircBuffer as PurpleCircularBuffer (from gobjectification branch)
Ankit Vani <a@nevitus.org>
parents: 34111
diff changeset
608 purple_circular_buffer_append(sip->txbuf, buf + ret,
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
609 writelen - ret);
11189
5ac07336091e [gaim-migrate @ 13307]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11181
diff changeset
610 }
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
611 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
612 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
613
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
614 static int simple_send_raw(PurpleConnection *gc, const char *buf, int len)
14604
67a7c42a8654 [gaim-migrate @ 17263]
Sean Egan <seanegan@pidgin.im>
parents: 14370
diff changeset
615 {
67a7c42a8654 [gaim-migrate @ 17263]
Sean Egan <seanegan@pidgin.im>
parents: 14370
diff changeset
616 sendout_pkt(gc, buf);
67a7c42a8654 [gaim-migrate @ 17263]
Sean Egan <seanegan@pidgin.im>
parents: 14370
diff changeset
617 return len;
67a7c42a8654 [gaim-migrate @ 17263]
Sean Egan <seanegan@pidgin.im>
parents: 14370
diff changeset
618 }
67a7c42a8654 [gaim-migrate @ 17263]
Sean Egan <seanegan@pidgin.im>
parents: 14370
diff changeset
619
11194
47dc0e9a757a [gaim-migrate @ 13317]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11192
diff changeset
620 static void sendout_sipmsg(struct simple_account_data *sip, struct sipmsg *msg) {
12741
14cd04e157b1 [gaim-migrate @ 15088]
Daniel Atallah <datallah@pidgin.im>
parents: 12730
diff changeset
621 GSList *tmp = msg->headers;
11194
47dc0e9a757a [gaim-migrate @ 13317]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11192
diff changeset
622 gchar *name;
47dc0e9a757a [gaim-migrate @ 13317]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11192
diff changeset
623 gchar *value;
12741
14cd04e157b1 [gaim-migrate @ 15088]
Daniel Atallah <datallah@pidgin.im>
parents: 12730
diff changeset
624 GString *outstr = g_string_new("");
14cd04e157b1 [gaim-migrate @ 15088]
Daniel Atallah <datallah@pidgin.im>
parents: 12730
diff changeset
625 g_string_append_printf(outstr, "%s %s SIP/2.0\r\n", msg->method, msg->target);
11194
47dc0e9a757a [gaim-migrate @ 13317]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11192
diff changeset
626 while(tmp) {
12741
14cd04e157b1 [gaim-migrate @ 15088]
Daniel Atallah <datallah@pidgin.im>
parents: 12730
diff changeset
627 name = ((struct siphdrelement*) (tmp->data))->name;
14cd04e157b1 [gaim-migrate @ 15088]
Daniel Atallah <datallah@pidgin.im>
parents: 12730
diff changeset
628 value = ((struct siphdrelement*) (tmp->data))->value;
14cd04e157b1 [gaim-migrate @ 15088]
Daniel Atallah <datallah@pidgin.im>
parents: 12730
diff changeset
629 g_string_append_printf(outstr, "%s: %s\r\n", name, value);
11194
47dc0e9a757a [gaim-migrate @ 13317]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11192
diff changeset
630 tmp = g_slist_next(tmp);
47dc0e9a757a [gaim-migrate @ 13317]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11192
diff changeset
631 }
12741
14cd04e157b1 [gaim-migrate @ 15088]
Daniel Atallah <datallah@pidgin.im>
parents: 12730
diff changeset
632 g_string_append_printf(outstr, "\r\n%s", msg->body ? msg->body : "");
14cd04e157b1 [gaim-migrate @ 15088]
Daniel Atallah <datallah@pidgin.im>
parents: 12730
diff changeset
633 sendout_pkt(sip->gc, outstr->str);
14cd04e157b1 [gaim-migrate @ 15088]
Daniel Atallah <datallah@pidgin.im>
parents: 12730
diff changeset
634 g_string_free(outstr, TRUE);
11194
47dc0e9a757a [gaim-migrate @ 13317]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11192
diff changeset
635 }
47dc0e9a757a [gaim-migrate @ 13317]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11192
diff changeset
636
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
637 static void send_sip_response(PurpleConnection *gc, struct sipmsg *msg, int code,
14131
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
638 const char *text, const char *body) {
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
639 GSList *tmp = msg->headers;
12741
14cd04e157b1 [gaim-migrate @ 15088]
Daniel Atallah <datallah@pidgin.im>
parents: 12730
diff changeset
640 gchar *name;
14cd04e157b1 [gaim-migrate @ 15088]
Daniel Atallah <datallah@pidgin.im>
parents: 12730
diff changeset
641 gchar *value;
14cd04e157b1 [gaim-migrate @ 15088]
Daniel Atallah <datallah@pidgin.im>
parents: 12730
diff changeset
642 GString *outstr = g_string_new("");
13093
e27434c31f00 [gaim-migrate @ 15454]
Daniel Atallah <datallah@pidgin.im>
parents: 13089
diff changeset
643
12754
539bcb15199f [gaim-migrate @ 15101]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 12753
diff changeset
644 /* When sending the acknowlegements and errors, the content length from the original
539bcb15199f [gaim-migrate @ 15101]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 12753
diff changeset
645 message is still here, but there is no body; we need to make sure we're sending the
539bcb15199f [gaim-migrate @ 15101]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 12753
diff changeset
646 correct content length */
539bcb15199f [gaim-migrate @ 15101]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 12753
diff changeset
647 sipmsg_remove_header(msg, "Content-Length");
539bcb15199f [gaim-migrate @ 15101]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 12753
diff changeset
648 if(body) {
539bcb15199f [gaim-migrate @ 15101]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 12753
diff changeset
649 gchar len[12];
539bcb15199f [gaim-migrate @ 15101]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 12753
diff changeset
650 sprintf(len, "%" G_GSIZE_FORMAT , strlen(body));
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
651 sipmsg_add_header(msg, "Content-Length", len);
12754
539bcb15199f [gaim-migrate @ 15101]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 12753
diff changeset
652 }
539bcb15199f [gaim-migrate @ 15101]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 12753
diff changeset
653 else
539bcb15199f [gaim-migrate @ 15101]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 12753
diff changeset
654 sipmsg_add_header(msg, "Content-Length", "0");
12741
14cd04e157b1 [gaim-migrate @ 15088]
Daniel Atallah <datallah@pidgin.im>
parents: 12730
diff changeset
655 g_string_append_printf(outstr, "SIP/2.0 %d %s\r\n", code, text);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
656 while(tmp) {
12741
14cd04e157b1 [gaim-migrate @ 15088]
Daniel Atallah <datallah@pidgin.im>
parents: 12730
diff changeset
657 name = ((struct siphdrelement*) (tmp->data))->name;
14cd04e157b1 [gaim-migrate @ 15088]
Daniel Atallah <datallah@pidgin.im>
parents: 12730
diff changeset
658 value = ((struct siphdrelement*) (tmp->data))->value;
12745
1dc3525647c2 [gaim-migrate @ 15092]
Daniel Atallah <datallah@pidgin.im>
parents: 12741
diff changeset
659
12741
14cd04e157b1 [gaim-migrate @ 15088]
Daniel Atallah <datallah@pidgin.im>
parents: 12730
diff changeset
660 g_string_append_printf(outstr, "%s: %s\r\n", name, value);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
661 tmp = g_slist_next(tmp);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
662 }
12741
14cd04e157b1 [gaim-migrate @ 15088]
Daniel Atallah <datallah@pidgin.im>
parents: 12730
diff changeset
663 g_string_append_printf(outstr, "\r\n%s", body ? body : "");
14cd04e157b1 [gaim-migrate @ 15088]
Daniel Atallah <datallah@pidgin.im>
parents: 12730
diff changeset
664 sendout_pkt(gc, outstr->str);
14cd04e157b1 [gaim-migrate @ 15088]
Daniel Atallah <datallah@pidgin.im>
parents: 12730
diff changeset
665 g_string_free(outstr, TRUE);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
666 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
667
11194
47dc0e9a757a [gaim-migrate @ 13317]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11192
diff changeset
668 static void transactions_remove(struct simple_account_data *sip, struct transaction *trans) {
47dc0e9a757a [gaim-migrate @ 13317]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11192
diff changeset
669 if(trans->msg) sipmsg_free(trans->msg);
47dc0e9a757a [gaim-migrate @ 13317]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11192
diff changeset
670 sip->transactions = g_slist_remove(sip->transactions, trans);
47dc0e9a757a [gaim-migrate @ 13317]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11192
diff changeset
671 g_free(trans);
47dc0e9a757a [gaim-migrate @ 13317]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11192
diff changeset
672 }
47dc0e9a757a [gaim-migrate @ 13317]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11192
diff changeset
673
14131
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
674 static void transactions_add_buf(struct simple_account_data *sip, const gchar *buf, void *callback) {
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
675 struct transaction *trans = g_new0(struct transaction, 1);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
676 trans->time = time(NULL);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
677 trans->msg = sipmsg_parse_msg(buf);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
678 trans->cseq = sipmsg_find_header(trans->msg, "CSeq");
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
679 trans->callback = callback;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
680 sip->transactions = g_slist_append(sip->transactions, trans);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
681 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
682
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
683 static struct transaction *transactions_find(struct simple_account_data *sip, struct sipmsg *msg) {
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
684 struct transaction *trans;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
685 GSList *transactions = sip->transactions;
21100
814637ced463 Some constification, which also found and fixed some potential double-free
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 21076
diff changeset
686 const gchar *cseq = sipmsg_find_header(msg, "CSeq");
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
687
16232
b5838c6cb3ed simple-crashfix.diff from achris in ticket #98. This is a fix for the crasher,
Richard Laager <rlaager@pidgin.im>
parents: 16209
diff changeset
688 if (cseq) {
b5838c6cb3ed simple-crashfix.diff from achris in ticket #98. This is a fix for the crasher,
Richard Laager <rlaager@pidgin.im>
parents: 16209
diff changeset
689 while(transactions) {
b5838c6cb3ed simple-crashfix.diff from achris in ticket #98. This is a fix for the crasher,
Richard Laager <rlaager@pidgin.im>
parents: 16209
diff changeset
690 trans = transactions->data;
38258
9a6551eba09c Replace !strcmp() with purple_strequal()
qarkai <qarkai@gmail.com>
parents: 36041
diff changeset
691 if(purple_strequal(trans->cseq, cseq)) {
16232
b5838c6cb3ed simple-crashfix.diff from achris in ticket #98. This is a fix for the crasher,
Richard Laager <rlaager@pidgin.im>
parents: 16209
diff changeset
692 return trans;
b5838c6cb3ed simple-crashfix.diff from achris in ticket #98. This is a fix for the crasher,
Richard Laager <rlaager@pidgin.im>
parents: 16209
diff changeset
693 }
b5838c6cb3ed simple-crashfix.diff from achris in ticket #98. This is a fix for the crasher,
Richard Laager <rlaager@pidgin.im>
parents: 16209
diff changeset
694 transactions = transactions->next;
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
695 }
16232
b5838c6cb3ed simple-crashfix.diff from achris in ticket #98. This is a fix for the crasher,
Richard Laager <rlaager@pidgin.im>
parents: 16209
diff changeset
696 } else {
b5838c6cb3ed simple-crashfix.diff from achris in ticket #98. This is a fix for the crasher,
Richard Laager <rlaager@pidgin.im>
parents: 16209
diff changeset
697 purple_debug(PURPLE_DEBUG_MISC, "simple", "Received message contains no CSeq header.\n");
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
698 }
11396
468e60b682cd [gaim-migrate @ 13627]
Daniel Atallah <datallah@pidgin.im>
parents: 11383
diff changeset
699
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
700 return NULL;
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
701 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
702
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
703 static void send_sip_request(PurpleConnection *gc, const gchar *method,
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
704 const gchar *url, const gchar *to, const gchar *addheaders,
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
705 const gchar *body, struct sip_dialog *dialog, TransCallback tc) {
32266
af94a3153685 Convert simple prpl to use accessor functions purple_connection_get_protocol_data() and purple_connection_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents: 32157
diff changeset
706 struct simple_account_data *sip = purple_connection_get_protocol_data(gc);
13093
e27434c31f00 [gaim-migrate @ 15454]
Daniel Atallah <datallah@pidgin.im>
parents: 13089
diff changeset
707 char *callid = dialog ? g_strdup(dialog->callid) : gencallid();
14213
1d35fd2c5713 [gaim-migrate @ 16796]
Daniel Atallah <datallah@pidgin.im>
parents: 14180
diff changeset
708 char *auth = NULL;
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
709 const char *addh = "";
12216
d80739091a63 [gaim-migrate @ 14518]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 12196
diff changeset
710 gchar *branch = genbranch();
14131
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
711 gchar *tag = NULL;
12216
d80739091a63 [gaim-migrate @ 14518]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 12196
diff changeset
712 char *buf;
d80739091a63 [gaim-migrate @ 14518]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 12196
diff changeset
713
38258
9a6551eba09c Replace !strcmp() with purple_strequal()
qarkai <qarkai@gmail.com>
parents: 36041
diff changeset
714 if(purple_strequal(method, "REGISTER")) {
13093
e27434c31f00 [gaim-migrate @ 15454]
Daniel Atallah <datallah@pidgin.im>
parents: 13089
diff changeset
715 if(sip->regcallid) {
e27434c31f00 [gaim-migrate @ 15454]
Daniel Atallah <datallah@pidgin.im>
parents: 13089
diff changeset
716 g_free(callid);
e27434c31f00 [gaim-migrate @ 15454]
Daniel Atallah <datallah@pidgin.im>
parents: 13089
diff changeset
717 callid = g_strdup(sip->regcallid);
e27434c31f00 [gaim-migrate @ 15454]
Daniel Atallah <datallah@pidgin.im>
parents: 13089
diff changeset
718 }
12196
92a07bdbe0df [gaim-migrate @ 14498]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 12143
diff changeset
719 else sip->regcallid = g_strdup(callid);
92a07bdbe0df [gaim-migrate @ 14498]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 12143
diff changeset
720 }
11396
468e60b682cd [gaim-migrate @ 13627]
Daniel Atallah <datallah@pidgin.im>
parents: 11383
diff changeset
721
13093
e27434c31f00 [gaim-migrate @ 15454]
Daniel Atallah <datallah@pidgin.im>
parents: 13089
diff changeset
722 if(addheaders) addh = addheaders;
38258
9a6551eba09c Replace !strcmp() with purple_strequal()
qarkai <qarkai@gmail.com>
parents: 36041
diff changeset
723 if(sip->registrar.type && purple_strequal(method, "REGISTER")) {
11396
468e60b682cd [gaim-migrate @ 13627]
Daniel Atallah <datallah@pidgin.im>
parents: 11383
diff changeset
724 buf = auth_header(sip, &sip->registrar, method, url);
17187
78b7ae95ad45 Fix an extra \r\n in the Authorization header. Fixes #965.
Daniel Atallah <datallah@pidgin.im>
parents: 17185
diff changeset
725 auth = g_strdup_printf("Authorization: %s\r\n", buf);
11346
4af1dc4b2c44 [gaim-migrate @ 13563]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11345
diff changeset
726 g_free(buf);
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
727 purple_debug(PURPLE_DEBUG_MISC, "simple", "header %s", auth);
38259
c593fc9f5438 Replace strcmp() with purple_strequal()
qarkai <qarkai@gmail.com>
parents: 38258
diff changeset
728 } else if(sip->proxy.type && !purple_strequal(method, "REGISTER")) {
11346
4af1dc4b2c44 [gaim-migrate @ 13563]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11345
diff changeset
729 buf = auth_header(sip, &sip->proxy, method, url);
17187
78b7ae95ad45 Fix an extra \r\n in the Authorization header. Fixes #965.
Daniel Atallah <datallah@pidgin.im>
parents: 17185
diff changeset
730 auth = g_strdup_printf("Proxy-Authorization: %s\r\n", buf);
11346
4af1dc4b2c44 [gaim-migrate @ 13563]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11345
diff changeset
731 g_free(buf);
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
732 purple_debug(PURPLE_DEBUG_MISC, "simple", "header %s", auth);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
733 }
12767
4870d7755883 [gaim-migrate @ 15114]
Daniel Atallah <datallah@pidgin.im>
parents: 12760
diff changeset
734
14131
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
735 if (!dialog)
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
736 tag = gentag();
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
737
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
738 buf = g_strdup_printf("%s %s SIP/2.0\r\n"
11190
16f02ac58a38 [gaim-migrate @ 13308]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11189
diff changeset
739 "Via: SIP/2.0/%s %s:%d;branch=%s\r\n"
13085
c80913901342 [gaim-migrate @ 15446]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13084
diff changeset
740 /* Don't know what epid is, but LCS wants it */
c80913901342 [gaim-migrate @ 15446]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13084
diff changeset
741 "From: <sip:%s@%s>;tag=%s;epid=1234567890\r\n"
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
742 "To: <%s>%s%s\r\n"
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
743 "Max-Forwards: 10\r\n"
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
744 "CSeq: %d %s\r\n"
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
745 "User-Agent: Purple/" VERSION "\r\n"
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
746 "Call-ID: %s\r\n"
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
747 "%s%s"
11658
5d1ee2125070 [gaim-migrate @ 13943]
Nathan Walp <nwalp@pidgin.im>
parents: 11650
diff changeset
748 "Content-Length: %" G_GSIZE_FORMAT "\r\n\r\n%s",
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
749 method,
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
750 url,
11190
16f02ac58a38 [gaim-migrate @ 13308]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11189
diff changeset
751 sip->udp ? "UDP" : "TCP",
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
752 purple_network_get_my_ip(-1),
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
753 sip->listenport,
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
754 branch,
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
755 sip->username,
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
756 sip->servername,
14131
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
757 dialog ? dialog->ourtag : tag,
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
758 to,
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
759 dialog ? ";tag=" : "",
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
760 dialog ? dialog->theirtag : "",
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
761 ++sip->cseq,
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
762 method,
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
763 callid,
14213
1d35fd2c5713 [gaim-migrate @ 16796]
Daniel Atallah <datallah@pidgin.im>
parents: 14180
diff changeset
764 auth ? auth : "",
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
765 addh,
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
766 strlen(body),
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
767 body);
14131
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
768
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
769 g_free(tag);
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
770 g_free(auth);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
771 g_free(branch);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
772 g_free(callid);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
773
11341
5511bbeeb3b4 [gaim-migrate @ 13555]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11327
diff changeset
774 /* add to ongoing transactions */
11396
468e60b682cd [gaim-migrate @ 13627]
Daniel Atallah <datallah@pidgin.im>
parents: 11383
diff changeset
775
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
776 transactions_add_buf(sip, buf, tc);
11396
468e60b682cd [gaim-migrate @ 13627]
Daniel Atallah <datallah@pidgin.im>
parents: 11383
diff changeset
777
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
778 sendout_pkt(gc, buf);
11396
468e60b682cd [gaim-migrate @ 13627]
Daniel Atallah <datallah@pidgin.im>
parents: 11383
diff changeset
779
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
780 g_free(buf);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
781 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
782
13178
824d50326672 [gaim-migrate @ 15540]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13130
diff changeset
783 static char *get_contact(struct simple_account_data *sip) {
21417
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
784 return g_strdup_printf("<sip:%s@%s:%d;transport=%s>;methods=\"MESSAGE, SUBSCRIBE, NOTIFY\"",
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
785 sip->username, purple_network_get_my_ip(-1),
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
786 sip->listenport,
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
787 sip->udp ? "udp" : "tcp");
13178
824d50326672 [gaim-migrate @ 15540]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13130
diff changeset
788 }
824d50326672 [gaim-migrate @ 15540]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13130
diff changeset
789
11194
47dc0e9a757a [gaim-migrate @ 13317]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11192
diff changeset
790 static void do_register_exp(struct simple_account_data *sip, int expire) {
19991
603d11d2afa7 Fixes #3051 Patch from Will Hawkins to clean up SIMPLE login and registration
Sean Egan <seanegan@pidgin.im>
parents: 19859
diff changeset
791 char *uri, *to, *contact, *hdr;
603d11d2afa7 Fixes #3051 Patch from Will Hawkins to clean up SIMPLE login and registration
Sean Egan <seanegan@pidgin.im>
parents: 19859
diff changeset
792
603d11d2afa7 Fixes #3051 Patch from Will Hawkins to clean up SIMPLE login and registration
Sean Egan <seanegan@pidgin.im>
parents: 19859
diff changeset
793 sip->reregister = time(NULL) + expire - 50;
603d11d2afa7 Fixes #3051 Patch from Will Hawkins to clean up SIMPLE login and registration
Sean Egan <seanegan@pidgin.im>
parents: 19859
diff changeset
794
603d11d2afa7 Fixes #3051 Patch from Will Hawkins to clean up SIMPLE login and registration
Sean Egan <seanegan@pidgin.im>
parents: 19859
diff changeset
795 uri = g_strdup_printf("sip:%s", sip->servername);
603d11d2afa7 Fixes #3051 Patch from Will Hawkins to clean up SIMPLE login and registration
Sean Egan <seanegan@pidgin.im>
parents: 19859
diff changeset
796 to = g_strdup_printf("sip:%s@%s", sip->username, sip->servername);
603d11d2afa7 Fixes #3051 Patch from Will Hawkins to clean up SIMPLE login and registration
Sean Egan <seanegan@pidgin.im>
parents: 19859
diff changeset
797 contact = get_contact(sip);
603d11d2afa7 Fixes #3051 Patch from Will Hawkins to clean up SIMPLE login and registration
Sean Egan <seanegan@pidgin.im>
parents: 19859
diff changeset
798 hdr = g_strdup_printf("Contact: %s\r\nExpires: %d\r\n", contact, expire);
13178
824d50326672 [gaim-migrate @ 15540]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13130
diff changeset
799 g_free(contact);
11396
468e60b682cd [gaim-migrate @ 13627]
Daniel Atallah <datallah@pidgin.im>
parents: 11383
diff changeset
800
19991
603d11d2afa7 Fixes #3051 Patch from Will Hawkins to clean up SIMPLE login and registration
Sean Egan <seanegan@pidgin.im>
parents: 19859
diff changeset
801 sip->registerstatus = SIMPLE_REGISTER_SENT;
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
802
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
803 send_sip_request(sip->gc, "REGISTER", uri, to, hdr, "", NULL,
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
804 process_register_response);
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
805
13178
824d50326672 [gaim-migrate @ 15540]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13130
diff changeset
806 g_free(hdr);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
807 g_free(uri);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
808 g_free(to);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
809 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
810
11194
47dc0e9a757a [gaim-migrate @ 13317]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11192
diff changeset
811 static void do_register(struct simple_account_data *sip) {
47dc0e9a757a [gaim-migrate @ 13317]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11192
diff changeset
812 do_register_exp(sip, sip->registerexpire);
47dc0e9a757a [gaim-migrate @ 13317]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11192
diff changeset
813 }
47dc0e9a757a [gaim-migrate @ 13317]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11192
diff changeset
814
14131
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
815 static gchar *parse_from(const gchar *hdr) {
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
816 gchar *from;
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
817 const gchar *tmp, *tmp2 = hdr;
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
818
14131
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
819 if(!hdr) return NULL;
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
820 purple_debug_info("simple", "parsing address out of %s\n", hdr);
14131
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
821 tmp = strchr(hdr, '<');
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
822
11341
5511bbeeb3b4 [gaim-migrate @ 13555]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11327
diff changeset
823 /* i hate the different SIP UA behaviours... */
5511bbeeb3b4 [gaim-migrate @ 13555]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11327
diff changeset
824 if(tmp) { /* sip address in <...> */
14131
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
825 tmp2 = tmp + 1;
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
826 tmp = strchr(tmp2, '>');
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
827 if(tmp) {
14131
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
828 from = g_strndup(tmp2, tmp - tmp2);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
829 } else {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
830 purple_debug_info("simple", "found < without > in From\n");
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
831 return NULL;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
832 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
833 } else {
14131
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
834 tmp = strchr(tmp2, ';');
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
835 if(tmp) {
14131
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
836 from = g_strndup(tmp2, tmp - tmp2);
11483
098043515257 [gaim-migrate @ 13725]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11439
diff changeset
837 } else {
14131
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
838 from = g_strdup(tmp2);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
839 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
840 }
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
841 purple_debug_info("simple", "got %s\n", from);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
842 return from;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
843 }
21417
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
844 static gchar *find_tag(const gchar *);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
845
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
846 static gboolean process_subscribe_response(struct simple_account_data *sip, struct sipmsg *msg, struct transaction *tc) {
21417
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
847 gchar *to = NULL;
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
848 struct simple_buddy *b = NULL;
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
849 gchar *theirtag = NULL, *ourtag = NULL;
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
850 const gchar *callid = NULL;
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
851
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
852 purple_debug_info("simple", "process subscribe response\n");
11396
468e60b682cd [gaim-migrate @ 13627]
Daniel Atallah <datallah@pidgin.im>
parents: 11383
diff changeset
853
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
854 if(msg->response == 200 || msg->response == 202) {
21417
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
855 if ( (to = parse_from(sipmsg_find_header(msg, "To"))) &&
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
856 (b = g_hash_table_lookup(sip->buddies, to)) &&
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
857 !(b->dialog))
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
858 {
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
859 purple_debug_info("simple", "creating dialog"
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
860 " information for a subscription.\n");
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
861
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
862 theirtag = find_tag(sipmsg_find_header(msg, "To"));
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
863 ourtag = find_tag(sipmsg_find_header(msg, "From"));
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
864 callid = sipmsg_find_header(msg, "Call-ID");
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
865
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
866 if (theirtag && ourtag && callid)
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
867 {
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
868 b->dialog = g_new0(struct sip_dialog, 1);
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
869 b->dialog->ourtag = g_strdup(ourtag);
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
870 b->dialog->theirtag = g_strdup(theirtag);
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
871 b->dialog->callid = g_strdup(callid);
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
872
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 30138
diff changeset
873 purple_debug_info("simple", "ourtag: %s\n",
21417
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
874 ourtag);
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 30138
diff changeset
875 purple_debug_info("simple", "theirtag: %s\n",
21417
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
876 theirtag);
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 30138
diff changeset
877 purple_debug_info("simple", "callid: %s\n",
21417
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
878 callid);
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
879 g_free(theirtag);
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
880 g_free(ourtag);
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
881 }
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
882 }
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
883 else
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
884 {
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
885 purple_debug_info("simple", "cannot create dialog!\n");
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
886 }
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
887 return TRUE;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
888 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
889
14131
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
890 to = parse_from(sipmsg_find_header(tc->msg, "To")); /* cant be NULL since it is our own msg */
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
891
11341
5511bbeeb3b4 [gaim-migrate @ 13555]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11327
diff changeset
892 /* we can not subscribe -> user is offline (TODO unknown status?) */
11396
468e60b682cd [gaim-migrate @ 13627]
Daniel Atallah <datallah@pidgin.im>
parents: 11383
diff changeset
893
36545
23b59a16c808 Replaced some _prpl_ stuff with _protocol_
Ankit Vani <a@nevitus.org>
parents: 36544
diff changeset
894 purple_protocol_got_user_status(sip->account, to, "offline", NULL);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
895 g_free(to);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
896 return TRUE;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
897 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
898
21417
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
899 static void simple_subscribe_exp(struct simple_account_data *sip, struct simple_buddy *buddy, int expiration) {
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
900 gchar *contact, *to, *tmp, *tmp2;
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
901
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
902 tmp2 = g_strdup_printf(
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
903 "Expires: %d\r\n"
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
904 "Accept: application/pidf+xml, application/xpidf+xml\r\n"
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
905 "Event: presence\r\n",
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
906 expiration);
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
907
25603
d9748fa08309 This is a combination of patches from darkrain42 and Marcus Sundberg to fix
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 25206
diff changeset
908 if(strncmp(buddy->name, "sip:", 4))
d9748fa08309 This is a combination of patches from darkrain42 and Marcus Sundberg to fix
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 25206
diff changeset
909 to = g_strdup_printf("sip:%s", buddy->name);
d9748fa08309 This is a combination of patches from darkrain42 and Marcus Sundberg to fix
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 25206
diff changeset
910 else
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
911 to = g_strdup(buddy->name);
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
912
13178
824d50326672 [gaim-migrate @ 15540]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13130
diff changeset
913 tmp = get_contact(sip);
21417
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
914 contact = g_strdup_printf("%sContact: %s\r\n", tmp2, tmp);
13178
824d50326672 [gaim-migrate @ 15540]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13130
diff changeset
915 g_free(tmp);
21417
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
916 g_free(tmp2);
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
917
21417
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
918 send_sip_request(sip->gc, "SUBSCRIBE", to, to, contact,"",buddy->dialog,
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
919 (expiration > 0) ? process_subscribe_response : NULL);
11396
468e60b682cd [gaim-migrate @ 13627]
Daniel Atallah <datallah@pidgin.im>
parents: 11383
diff changeset
920
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
921 g_free(to);
11341
5511bbeeb3b4 [gaim-migrate @ 13555]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11327
diff changeset
922 g_free(contact);
11396
468e60b682cd [gaim-migrate @ 13627]
Daniel Atallah <datallah@pidgin.im>
parents: 11383
diff changeset
923
11341
5511bbeeb3b4 [gaim-migrate @ 13555]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11327
diff changeset
924 /* resubscribe before subscription expires */
5511bbeeb3b4 [gaim-migrate @ 13555]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11327
diff changeset
925 /* add some jitter */
21417
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
926 if (expiration > 60)
38191
20f33f108f99 Fix coverity 1255966 and 1255964
Gary Kramlich <grim@reaperworld.com>
parents: 37518
diff changeset
927 buddy->resubscribe = time(NULL) + (expiration - 60) + (g_random_int_range(0, 50));
21417
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
928 else if (expiration > 0)
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
929 buddy->resubscribe = time(NULL) + ((int) (expiration / 2));
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
930 }
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
931
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
932 static void simple_subscribe(struct simple_account_data *sip, struct simple_buddy *buddy) {
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
933 simple_subscribe_exp(sip, buddy, SUBSCRIBE_EXPIRATION);
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
934 }
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
935
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
936 static void simple_unsubscribe(char *name, struct simple_buddy *buddy, struct simple_account_data *sip) {
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
937 if (buddy->dialog)
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
938 {
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
939 purple_debug_info("simple", "Unsubscribing from %s\n", name);
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
940 simple_subscribe_exp(sip, buddy, 0);
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
941 }
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
942 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
943
13348
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
944 static gboolean simple_add_lcs_contacts(struct simple_account_data *sip, struct sipmsg *msg, struct transaction *tc) {
21100
814637ced463 Some constification, which also found and fixed some potential double-free
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 21076
diff changeset
945 const gchar *tmp;
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34894
diff changeset
946 PurpleXmlNode *item, *group, *isc;
13348
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
947 const char *name_group;
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
948 PurpleBuddy *b;
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
949 PurpleGroup *g = NULL;
13348
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
950 struct simple_buddy *bs;
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
951 int len = msg->bodylen;
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
952
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
953
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
954 tmp = sipmsg_find_header(msg, "Event");
25603
d9748fa08309 This is a combination of patches from darkrain42 and Marcus Sundberg to fix
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 25206
diff changeset
955 if(tmp && !strncmp(tmp, "vnd-microsoft-roaming-contacts", 30)){
13348
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
956
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
957 purple_debug_info("simple", "simple_add_lcs_contacts->%s-%d\n", msg->body, len);
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
958 /*Convert the contact from XML to Purple Buddies*/
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34894
diff changeset
959 isc = purple_xmlnode_from_str(msg->body, len);
13348
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
960
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
961 /* ToDo. Find for all groups */
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34894
diff changeset
962 if ((group = purple_xmlnode_get_child(isc, "group"))) {
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34894
diff changeset
963 name_group = purple_xmlnode_get_attrib(group, "name");
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
964 purple_debug_info("simple", "name_group->%s\n", name_group);
34728
8efd73063ecf Renamed buddy list functions to more appropriate/simler names.
Ankit Vani <a@nevitus.org>
parents: 34706
diff changeset
965 g = purple_blist_find_group(name_group);
14131
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
966 if(!g)
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
967 g = purple_group_new(name_group);
14131
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
968 }
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
969
35958
1d8446f396b6 blist: define default group better
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35501
diff changeset
970 if (!g)
1d8446f396b6 blist: define default group better
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35501
diff changeset
971 g = purple_blist_get_default_group();
13348
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
972
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34894
diff changeset
973 for(item = purple_xmlnode_get_child(isc, "contact"); item; item = purple_xmlnode_get_next_twin(item))
13348
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
974 {
33782
1690e0b2c508 Fix a bunch of unused variables
Daniel Atallah <datallah@pidgin.im>
parents: 31949
diff changeset
975 const char *uri;
14131
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
976 char *buddy_name;
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34894
diff changeset
977 uri = purple_xmlnode_get_attrib(item, "uri");
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34894
diff changeset
978 /*name = purple_xmlnode_get_attrib(item, "name");
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34894
diff changeset
979 groups = purple_xmlnode_get_attrib(item, "groups");*/
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
980 purple_debug_info("simple", "URI->%s\n", uri);
14131
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
981
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
982 buddy_name = g_strdup_printf("sip:%s", uri);
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
983
34728
8efd73063ecf Renamed buddy list functions to more appropriate/simler names.
Ankit Vani <a@nevitus.org>
parents: 34706
diff changeset
984 b = purple_blist_find_buddy(sip->account, buddy_name);
13348
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
985 if(!b){
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
986 b = purple_buddy_new(sip->account, buddy_name, uri);
13348
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
987 }
14131
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
988 g_free(buddy_name);
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
989
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
990 purple_blist_add_buddy(b, NULL, g, NULL);
34728
8efd73063ecf Renamed buddy list functions to more appropriate/simler names.
Ankit Vani <a@nevitus.org>
parents: 34706
diff changeset
991 purple_buddy_set_local_alias(b, uri);
13348
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
992 bs = g_new0(struct simple_buddy, 1);
24398
4865c2ee6ea8 Start hiding blist.h internals in prpls.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 24040
diff changeset
993 bs->name = g_strdup(purple_buddy_get_name(b));
13348
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
994 g_hash_table_insert(sip->buddies, bs->name, bs);
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
995 }
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34894
diff changeset
996 purple_xmlnode_free(isc);
13348
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
997 }
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
998 return 0;
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
999 }
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
1000
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
1001 static void simple_subscribe_buddylist(struct simple_account_data *sip) {
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
1002 gchar *contact = "Event: vnd-microsoft-roaming-contacts\r\nAccept: application/vnd-microsoft-roaming-contacts+xml\r\nSupported: com.microsoft.autoextend\r\nSupported: ms-benotify\r\nProxy-Require: ms-benotify\r\nSupported: ms-piggyback-first-notify\r\n";
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
1003 gchar *to;
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
1004 gchar *tmp;
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
1005 to = g_strdup_printf("sip:%s@%s", sip->username, sip->servername);
14131
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
1006
13348
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
1007 tmp = get_contact(sip);
14131
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
1008
13348
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
1009 contact = g_strdup_printf("%sContact: %s\r\n", contact, tmp);
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
1010 g_free(tmp);
14131
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
1011
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
1012 send_sip_request(sip->gc, "SUBSCRIBE", to, to, contact, "", NULL, simple_add_lcs_contacts);
13348
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
1013
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
1014 g_free(to);
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
1015 g_free(contact);
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
1016 }
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
1017
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
1018
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1019 static void simple_buddy_resub(char *name, struct simple_buddy *buddy, struct simple_account_data *sip) {
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1020 time_t curtime = time(NULL);
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
1021 purple_debug_info("simple", "buddy resub\n");
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1022 if(buddy->resubscribe < curtime) {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
1023 purple_debug(PURPLE_DEBUG_MISC, "simple", "simple_buddy_resub %s\n", name);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1024 simple_subscribe(sip, buddy);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1025 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1026 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1027
11194
47dc0e9a757a [gaim-migrate @ 13317]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11192
diff changeset
1028 static gboolean resend_timeout(struct simple_account_data *sip) {
47dc0e9a757a [gaim-migrate @ 13317]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11192
diff changeset
1029 GSList *tmp = sip->transactions;
47dc0e9a757a [gaim-migrate @ 13317]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11192
diff changeset
1030 time_t currtime = time(NULL);
47dc0e9a757a [gaim-migrate @ 13317]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11192
diff changeset
1031 while(tmp) {
47dc0e9a757a [gaim-migrate @ 13317]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11192
diff changeset
1032 struct transaction *trans = tmp->data;
47dc0e9a757a [gaim-migrate @ 13317]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11192
diff changeset
1033 tmp = tmp->next;
22709
6bd336964410 Printf warning fixes.
Daniel Atallah <datallah@pidgin.im>
parents: 22634
diff changeset
1034 purple_debug_info("simple", "have open transaction age: %lu\n", currtime- trans->time);
11194
47dc0e9a757a [gaim-migrate @ 13317]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11192
diff changeset
1035 if((currtime - trans->time > 5) && trans->retries >= 1) {
11341
5511bbeeb3b4 [gaim-migrate @ 13555]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11327
diff changeset
1036 /* TODO 408 */
11194
47dc0e9a757a [gaim-migrate @ 13317]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11192
diff changeset
1037 } else {
47dc0e9a757a [gaim-migrate @ 13317]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11192
diff changeset
1038 if((currtime - trans->time > 2) && trans->retries == 0) {
47dc0e9a757a [gaim-migrate @ 13317]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11192
diff changeset
1039 trans->retries++;
47dc0e9a757a [gaim-migrate @ 13317]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11192
diff changeset
1040 sendout_sipmsg(sip, trans->msg);
47dc0e9a757a [gaim-migrate @ 13317]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11192
diff changeset
1041 }
47dc0e9a757a [gaim-migrate @ 13317]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11192
diff changeset
1042 }
47dc0e9a757a [gaim-migrate @ 13317]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11192
diff changeset
1043 }
47dc0e9a757a [gaim-migrate @ 13317]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11192
diff changeset
1044 return TRUE;
47dc0e9a757a [gaim-migrate @ 13317]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11192
diff changeset
1045 }
47dc0e9a757a [gaim-migrate @ 13317]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11192
diff changeset
1046
12768
0783fffbd552 [gaim-migrate @ 15115]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 12767
diff changeset
1047 static gboolean subscribe_timeout(struct simple_account_data *sip) {
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1048 GSList *tmp;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1049 time_t curtime = time(NULL);
11341
5511bbeeb3b4 [gaim-migrate @ 13555]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11327
diff changeset
1050 /* register again if first registration expires */
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1051 if(sip->reregister < curtime) {
11194
47dc0e9a757a [gaim-migrate @ 13317]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11192
diff changeset
1052 do_register(sip);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1053 }
21417
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1054
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1055 /* publish status again if our last update is about to expire. */
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 30138
diff changeset
1056 if (sip->republish != -1 &&
21417
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1057 sip->republish < curtime &&
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1058 purple_account_get_bool(sip->account, "dopublish", TRUE))
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1059 {
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1060 purple_debug_info("simple", "subscribe_timeout: republishing status.\n");
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1061 send_open_publish(sip);
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1062 }
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1063
11341
5511bbeeb3b4 [gaim-migrate @ 13555]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11327
diff changeset
1064 /* check for every subscription if we need to resubscribe */
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1065 g_hash_table_foreach(sip->buddies, (GHFunc)simple_buddy_resub, (gpointer)sip);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1066
11341
5511bbeeb3b4 [gaim-migrate @ 13555]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11327
diff changeset
1067 /* remove a timed out suscriber */
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1068 tmp = sip->watcher;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1069 while(tmp) {
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1070 struct simple_watcher *watcher = tmp->data;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1071 if(watcher->expire < curtime) {
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1072 watcher_remove(sip, watcher->name);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1073 tmp = sip->watcher;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1074 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1075 if(tmp) tmp = tmp->next;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1076 }
11396
468e60b682cd [gaim-migrate @ 13627]
Daniel Atallah <datallah@pidgin.im>
parents: 11383
diff changeset
1077
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1078 return TRUE;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1079 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1080
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
1081 static void simple_send_message(struct simple_account_data *sip, const char *to, const char *msg, const char *type) {
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1082 gchar *hdr;
13185
ee7ac8a41ec4 [gaim-migrate @ 15547]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13178
diff changeset
1083 gchar *fullto;
25603
d9748fa08309 This is a combination of patches from darkrain42 and Marcus Sundberg to fix
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 25206
diff changeset
1084 if(strncmp(to, "sip:", 4))
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
1085 fullto = g_strdup_printf("sip:%s", to);
25603
d9748fa08309 This is a combination of patches from darkrain42 and Marcus Sundberg to fix
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 25206
diff changeset
1086 else
13185
ee7ac8a41ec4 [gaim-migrate @ 15547]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13178
diff changeset
1087 fullto = g_strdup(to);
25603
d9748fa08309 This is a combination of patches from darkrain42 and Marcus Sundberg to fix
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 25206
diff changeset
1088
11396
468e60b682cd [gaim-migrate @ 13627]
Daniel Atallah <datallah@pidgin.im>
parents: 11383
diff changeset
1089 if(type) {
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
1090 hdr = g_strdup_printf("Content-Type: %s\r\n", type);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1091 } else {
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1092 hdr = g_strdup("Content-Type: text/plain\r\n");
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1093 }
13185
ee7ac8a41ec4 [gaim-migrate @ 15547]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13178
diff changeset
1094 send_sip_request(sip->gc, "MESSAGE", fullto, fullto, hdr, msg, NULL, NULL);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1095 g_free(hdr);
13185
ee7ac8a41ec4 [gaim-migrate @ 15547]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13178
diff changeset
1096 g_free(fullto);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1097 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1098
36076
a0e5b68ff4ef Switch purple_serv_send_im to PurpleMessage
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 36055
diff changeset
1099 static int simple_im_send(PurpleConnection *gc, PurpleMessage *msg) {
32266
af94a3153685 Convert simple prpl to use accessor functions purple_connection_get_protocol_data() and purple_connection_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents: 32157
diff changeset
1100 struct simple_account_data *sip = purple_connection_get_protocol_data(gc);
36098
4951752ad038 Split PurpleMessage into incoming, outgoing and system
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 36078
diff changeset
1101 char *to = g_strdup(purple_message_get_recipient(msg));
36076
a0e5b68ff4ef Switch purple_serv_send_im to PurpleMessage
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 36055
diff changeset
1102 char *text = purple_unescape_html(purple_message_get_contents(msg));
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1103 simple_send_message(sip, to, text, NULL);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1104 g_free(to);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1105 g_free(text);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1106 return 1;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1107 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1108
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1109 static void process_incoming_message(struct simple_account_data *sip, struct sipmsg *msg) {
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1110 gchar *from;
21100
814637ced463 Some constification, which also found and fixed some potential double-free
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 21076
diff changeset
1111 const gchar *contenttype;
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1112 gboolean found = FALSE;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1113
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1114 from = parse_from(sipmsg_find_header(msg, "From"));
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1115
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1116 if(!from) return;
11396
468e60b682cd [gaim-migrate @ 13627]
Daniel Atallah <datallah@pidgin.im>
parents: 11383
diff changeset
1117
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
1118 purple_debug(PURPLE_DEBUG_MISC, "simple", "got message from %s: %s\n", from, msg->body);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1119
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1120 contenttype = sipmsg_find_header(msg, "Content-Type");
25603
d9748fa08309 This is a combination of patches from darkrain42 and Marcus Sundberg to fix
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 25206
diff changeset
1121 if(!contenttype || !strncmp(contenttype, "text/plain", 10) || !strncmp(contenttype, "text/html", 9)) {
35499
c4c5e0a670b1 Fix namespaces issues in libpurple.
Ankit Vani <a@nevitus.org>
parents: 35265
diff changeset
1122 purple_serv_got_im(sip->gc, from, msg->body, 0, time(NULL));
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1123 send_sip_response(sip->gc, msg, 200, "OK", NULL);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1124 found = TRUE;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1125 }
25603
d9748fa08309 This is a combination of patches from darkrain42 and Marcus Sundberg to fix
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 25206
diff changeset
1126 else if(!strncmp(contenttype, "application/im-iscomposing+xml", 30)) {
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34894
diff changeset
1127 PurpleXmlNode *isc = purple_xmlnode_from_str(msg->body, msg->bodylen);
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34894
diff changeset
1128 PurpleXmlNode *state;
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1129 gchar *statedata;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1130
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1131 if(!isc) {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
1132 purple_debug_info("simple", "process_incoming_message: can not parse iscomposing\n");
18840
05aeff1821c4 Fix from Will Hawkins to plug some leaks in error cases for the SIMPLE prpl. References #2181.
Daniel Atallah <datallah@pidgin.im>
parents: 18552
diff changeset
1133 g_free(from);
11396
468e60b682cd [gaim-migrate @ 13627]
Daniel Atallah <datallah@pidgin.im>
parents: 11383
diff changeset
1134 return;
468e60b682cd [gaim-migrate @ 13627]
Daniel Atallah <datallah@pidgin.im>
parents: 11383
diff changeset
1135 }
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1136
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34894
diff changeset
1137 state = purple_xmlnode_get_child(isc, "state");
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1138
11396
468e60b682cd [gaim-migrate @ 13627]
Daniel Atallah <datallah@pidgin.im>
parents: 11383
diff changeset
1139 if(!state) {
18840
05aeff1821c4 Fix from Will Hawkins to plug some leaks in error cases for the SIMPLE prpl. References #2181.
Daniel Atallah <datallah@pidgin.im>
parents: 18552
diff changeset
1140 purple_debug_info("simple", "process_incoming_message: no state found\n");
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34894
diff changeset
1141 purple_xmlnode_free(isc);
18840
05aeff1821c4 Fix from Will Hawkins to plug some leaks in error cases for the SIMPLE prpl. References #2181.
Daniel Atallah <datallah@pidgin.im>
parents: 18552
diff changeset
1142 g_free(from);
11396
468e60b682cd [gaim-migrate @ 13627]
Daniel Atallah <datallah@pidgin.im>
parents: 11383
diff changeset
1143 return;
468e60b682cd [gaim-migrate @ 13627]
Daniel Atallah <datallah@pidgin.im>
parents: 11383
diff changeset
1144 }
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1145
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34894
diff changeset
1146 statedata = purple_xmlnode_get_data(state);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1147 if(statedata) {
24845
6418fb8799b8 Some cleanup. The headers are all NUL delimited, so we don't need to mess with
Daniel Atallah <datallah@pidgin.im>
parents: 24844
diff changeset
1148 if(strstr(statedata, "active"))
35499
c4c5e0a670b1 Fix namespaces issues in libpurple.
Ankit Vani <a@nevitus.org>
parents: 35265
diff changeset
1149 purple_serv_got_typing(sip->gc, from, 0, PURPLE_IM_TYPING);
24845
6418fb8799b8 Some cleanup. The headers are all NUL delimited, so we don't need to mess with
Daniel Atallah <datallah@pidgin.im>
parents: 24844
diff changeset
1150 else
35501
602747bb4af9 Fix duplicate prefixes
Ankit Vani <a@nevitus.org>
parents: 35499
diff changeset
1151 purple_serv_got_typing_stopped(sip->gc, from);
14131
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
1152
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
1153 g_free(statedata);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1154 }
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34894
diff changeset
1155 purple_xmlnode_free(isc);
11396
468e60b682cd [gaim-migrate @ 13627]
Daniel Atallah <datallah@pidgin.im>
parents: 11383
diff changeset
1156 send_sip_response(sip->gc, msg, 200, "OK", NULL);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1157 found = TRUE;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1158 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1159 if(!found) {
19832
84b69b21672b Patch from QuLogic. Fixes #2903 ('Missing newlines in debug messages.')
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 18840
diff changeset
1160 purple_debug_info("simple", "got unknown mime-type\n");
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1161 send_sip_response(sip->gc, msg, 415, "Unsupported media type", NULL);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1162 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1163 g_free(from);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1164 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1165
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1166
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1167 gboolean process_register_response(struct simple_account_data *sip, struct sipmsg *msg, struct transaction *tc) {
21100
814637ced463 Some constification, which also found and fixed some potential double-free
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 21076
diff changeset
1168 const gchar *tmp;
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
1169 purple_debug(PURPLE_DEBUG_MISC, "simple", "in process register response response: %d\n", msg->response);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1170 switch (msg->response) {
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1171 case 200:
19991
603d11d2afa7 Fixes #3051 Patch from Will Hawkins to clean up SIMPLE login and registration
Sean Egan <seanegan@pidgin.im>
parents: 19859
diff changeset
1172 if(sip->registerstatus < SIMPLE_REGISTER_COMPLETE) { /* registered */
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
1173 if(purple_account_get_bool(sip->account, "dopublish", TRUE)) {
20988
75eab0f2aa19 Patch from Will Hawkins to publish a status of closed when signing out of a SIMPLE account. Fixes #1914.
Daniel Atallah <datallah@pidgin.im>
parents: 20658
diff changeset
1174 send_open_publish(sip);
11345
48a2f93e47b6 [gaim-migrate @ 13562]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11341
diff changeset
1175 }
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1176 }
19991
603d11d2afa7 Fixes #3051 Patch from Will Hawkins to clean up SIMPLE login and registration
Sean Egan <seanegan@pidgin.im>
parents: 19859
diff changeset
1177 sip->registerstatus = SIMPLE_REGISTER_COMPLETE;
34746
dc9c911dbd35 Started GObjectification of PurpleConnection.
Ankit Vani <a@nevitus.org>
parents: 34728
diff changeset
1178 purple_connection_set_state(sip->gc, PURPLE_CONNECTION_CONNECTED);
11341
5511bbeeb3b4 [gaim-migrate @ 13555]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11327
diff changeset
1179
5511bbeeb3b4 [gaim-migrate @ 13555]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11327
diff changeset
1180 /* get buddies from blist */
5511bbeeb3b4 [gaim-migrate @ 13555]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11327
diff changeset
1181 simple_get_buddies(sip->gc);
11396
468e60b682cd [gaim-migrate @ 13627]
Daniel Atallah <datallah@pidgin.im>
parents: 11383
diff changeset
1182
12768
0783fffbd552 [gaim-migrate @ 15115]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 12767
diff changeset
1183 subscribe_timeout(sip);
13348
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
1184 tmp = sipmsg_find_header(msg, "Allow-Events");
14131
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
1185 if(tmp && strstr(tmp, "vnd-microsoft-provisioning")){
13348
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
1186 simple_subscribe_buddylist(sip);
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
1187 }
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
1188
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1189 break;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1190 case 401:
19991
603d11d2afa7 Fixes #3051 Patch from Will Hawkins to clean up SIMPLE login and registration
Sean Egan <seanegan@pidgin.im>
parents: 19859
diff changeset
1191 if(sip->registerstatus != SIMPLE_REGISTER_RETRY) {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
1192 purple_debug_info("simple", "REGISTER retries %d\n", sip->registrar.retries);
19991
603d11d2afa7 Fixes #3051 Patch from Will Hawkins to clean up SIMPLE login and registration
Sean Egan <seanegan@pidgin.im>
parents: 19859
diff changeset
1193 if(sip->registrar.retries > SIMPLE_REGISTER_RETRY_MAX) {
32678
01f6312a4a7b On the way to hiding the PurpleConnection struct.
Andrew Victor <andrew.victor@mxit.com>
parents: 32594
diff changeset
1194 if (!purple_account_get_remember_password(purple_connection_get_account(sip->gc)))
34029
059c1270db1f Remove the silly destroy argument from purple_account_set_password and
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 34028
diff changeset
1195 purple_account_set_password(purple_connection_get_account(sip->gc), NULL, NULL, NULL);
32157
39ba2e2492ee Rename purple_connection_error_reason to purple_connection_error
Mark Doliner <markdoliner@pidgin.im>
parents: 31949
diff changeset
1196 purple_connection_error(sip->gc,
21279
40685e1f50ca Rename:
Will Thompson <resiak@pidgin.im>
parents: 21152
diff changeset
1197 PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED,
27635
0cd19038c417 More uniformity among disconnect error messages
Mark Doliner <markdoliner@pidgin.im>
parents: 27350
diff changeset
1198 _("Incorrect password"));
11346
4af1dc4b2c44 [gaim-migrate @ 13563]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11345
diff changeset
1199 return TRUE;
4af1dc4b2c44 [gaim-migrate @ 13563]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11345
diff changeset
1200 }
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1201 tmp = sipmsg_find_header(msg, "WWW-Authenticate");
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1202 fill_auth(sip, tmp, &sip->registrar);
19991
603d11d2afa7 Fixes #3051 Patch from Will Hawkins to clean up SIMPLE login and registration
Sean Egan <seanegan@pidgin.im>
parents: 19859
diff changeset
1203 sip->registerstatus = SIMPLE_REGISTER_RETRY;
603d11d2afa7 Fixes #3051 Patch from Will Hawkins to clean up SIMPLE login and registration
Sean Egan <seanegan@pidgin.im>
parents: 19859
diff changeset
1204 do_register(sip);
603d11d2afa7 Fixes #3051 Patch from Will Hawkins to clean up SIMPLE login and registration
Sean Egan <seanegan@pidgin.im>
parents: 19859
diff changeset
1205 }
603d11d2afa7 Fixes #3051 Patch from Will Hawkins to clean up SIMPLE login and registration
Sean Egan <seanegan@pidgin.im>
parents: 19859
diff changeset
1206 break;
603d11d2afa7 Fixes #3051 Patch from Will Hawkins to clean up SIMPLE login and registration
Sean Egan <seanegan@pidgin.im>
parents: 19859
diff changeset
1207 default:
603d11d2afa7 Fixes #3051 Patch from Will Hawkins to clean up SIMPLE login and registration
Sean Egan <seanegan@pidgin.im>
parents: 19859
diff changeset
1208 if (sip->registerstatus != SIMPLE_REGISTER_RETRY) {
603d11d2afa7 Fixes #3051 Patch from Will Hawkins to clean up SIMPLE login and registration
Sean Egan <seanegan@pidgin.im>
parents: 19859
diff changeset
1209 purple_debug_info("simple", "Unrecognized return code for REGISTER.\n");
603d11d2afa7 Fixes #3051 Patch from Will Hawkins to clean up SIMPLE login and registration
Sean Egan <seanegan@pidgin.im>
parents: 19859
diff changeset
1210 if (sip->registrar.retries > SIMPLE_REGISTER_RETRY_MAX) {
32157
39ba2e2492ee Rename purple_connection_error_reason to purple_connection_error
Mark Doliner <markdoliner@pidgin.im>
parents: 31949
diff changeset
1211 purple_connection_error(sip->gc,
21279
40685e1f50ca Rename:
Will Thompson <resiak@pidgin.im>
parents: 21152
diff changeset
1212 PURPLE_CONNECTION_ERROR_OTHER_ERROR,
27635
0cd19038c417 More uniformity among disconnect error messages
Mark Doliner <markdoliner@pidgin.im>
parents: 27350
diff changeset
1213 _("Unknown server response"));
19991
603d11d2afa7 Fixes #3051 Patch from Will Hawkins to clean up SIMPLE login and registration
Sean Egan <seanegan@pidgin.im>
parents: 19859
diff changeset
1214 return TRUE;
603d11d2afa7 Fixes #3051 Patch from Will Hawkins to clean up SIMPLE login and registration
Sean Egan <seanegan@pidgin.im>
parents: 19859
diff changeset
1215 }
603d11d2afa7 Fixes #3051 Patch from Will Hawkins to clean up SIMPLE login and registration
Sean Egan <seanegan@pidgin.im>
parents: 19859
diff changeset
1216 sip->registerstatus = SIMPLE_REGISTER_RETRY;
11194
47dc0e9a757a [gaim-migrate @ 13317]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11192
diff changeset
1217 do_register(sip);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1218 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1219 break;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1220 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1221 return TRUE;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1222 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1223
21417
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1224 static gboolean dialog_match(struct sip_dialog *dialog, struct sipmsg *msg)
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1225 {
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1226 const gchar *fromhdr;
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1227 const gchar *tohdr;
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1228 const gchar *callid;
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1229 gchar *ourtag, *theirtag;
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1230 gboolean match = FALSE;
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1231
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1232 fromhdr = sipmsg_find_header(msg, "From");
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1233 tohdr = sipmsg_find_header(msg, "To");
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1234 callid = sipmsg_find_header(msg, "Call-ID");
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1235
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1236 if (!fromhdr || !tohdr || !callid)
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1237 return FALSE;
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1238
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1239 ourtag = find_tag(tohdr);
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1240 theirtag = find_tag(fromhdr);
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1241
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1242 if (ourtag && theirtag &&
38258
9a6551eba09c Replace !strcmp() with purple_strequal()
qarkai <qarkai@gmail.com>
parents: 36041
diff changeset
1243 purple_strequal(dialog->callid, callid) &&
9a6551eba09c Replace !strcmp() with purple_strequal()
qarkai <qarkai@gmail.com>
parents: 36041
diff changeset
1244 purple_strequal(dialog->ourtag, ourtag) &&
9a6551eba09c Replace !strcmp() with purple_strequal()
qarkai <qarkai@gmail.com>
parents: 36041
diff changeset
1245 purple_strequal(dialog->theirtag, theirtag))
21417
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1246 match = TRUE;
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1247
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1248 g_free(ourtag);
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1249 g_free(theirtag);
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1250
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1251 return match;
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1252 }
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1253
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1254 static void process_incoming_notify(struct simple_account_data *sip, struct sipmsg *msg) {
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1255 gchar *from;
21100
814637ced463 Some constification, which also found and fixed some potential double-free
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 21076
diff changeset
1256 const gchar *fromhdr;
20989
5707d9d29718 Patch from Will Hawkins for some cleanup of the SIMPLE notify message processing. This should hopefully fix some cases when a user signs off but we don't notice. Fixes #3507.
Daniel Atallah <datallah@pidgin.im>
parents: 20988
diff changeset
1257 gchar *basicstatus_data;
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34894
diff changeset
1258 PurpleXmlNode *pidf;
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34894
diff changeset
1259 PurpleXmlNode *basicstatus = NULL, *tuple, *status;
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1260 gboolean isonline = FALSE;
21417
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1261 struct simple_buddy *b = NULL;
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1262 const gchar *sshdr = NULL;
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1263
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
1264 fromhdr = sipmsg_find_header(msg, "From");
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1265 from = parse_from(fromhdr);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1266 if(!from) return;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1267
21417
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1268 b = g_hash_table_lookup(sip->buddies, from);
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1269 if (!b)
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1270 {
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1271 g_free(from);
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1272 purple_debug_info("simple", "Could not find the buddy.\n");
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1273 return;
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1274 }
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1275
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1276 if (b->dialog && !dialog_match(b->dialog, msg))
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1277 {
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1278 /* We only accept notifies from people that
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1279 * we already have a dialog with.
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1280 */
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1281 purple_debug_info("simple","No corresponding dialog for notify--discard\n");
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1282 g_free(from);
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1283 return;
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1284 }
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1285
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34894
diff changeset
1286 pidf = purple_xmlnode_from_str(msg->body, msg->bodylen);
11396
468e60b682cd [gaim-migrate @ 13627]
Daniel Atallah <datallah@pidgin.im>
parents: 11383
diff changeset
1287
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1288 if(!pidf) {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
1289 purple_debug_info("simple", "process_incoming_notify: no parseable pidf\n");
21417
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1290 sshdr = sipmsg_find_header(msg, "Subscription-State");
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1291 if (sshdr)
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1292 {
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1293 int i = 0;
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1294 gchar **ssparts = g_strsplit(sshdr, ":", 0);
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1295 while (ssparts[i])
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1296 {
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1297 g_strchug(ssparts[i]);
22634
faaadc2d74bb Use purple_str_has_prefix which provides backwards compatibility with older
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 22388
diff changeset
1298 if (purple_str_has_prefix(ssparts[i], "terminated"))
21417
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1299 {
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1300 purple_debug_info("simple", "Subscription expired!");
24638
b272153e8de5 Fix CID #370
Richard Laager <rlaager@pidgin.im>
parents: 24040
diff changeset
1301 if (b->dialog)
b272153e8de5 Fix CID #370
Richard Laager <rlaager@pidgin.im>
parents: 24040
diff changeset
1302 {
b272153e8de5 Fix CID #370
Richard Laager <rlaager@pidgin.im>
parents: 24040
diff changeset
1303 g_free(b->dialog->ourtag);
b272153e8de5 Fix CID #370
Richard Laager <rlaager@pidgin.im>
parents: 24040
diff changeset
1304 g_free(b->dialog->theirtag);
b272153e8de5 Fix CID #370
Richard Laager <rlaager@pidgin.im>
parents: 24040
diff changeset
1305 g_free(b->dialog->callid);
b272153e8de5 Fix CID #370
Richard Laager <rlaager@pidgin.im>
parents: 24040
diff changeset
1306 g_free(b->dialog);
b272153e8de5 Fix CID #370
Richard Laager <rlaager@pidgin.im>
parents: 24040
diff changeset
1307 b->dialog = NULL;
b272153e8de5 Fix CID #370
Richard Laager <rlaager@pidgin.im>
parents: 24040
diff changeset
1308 }
21417
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1309
36545
23b59a16c808 Replaced some _prpl_ stuff with _protocol_
Ankit Vani <a@nevitus.org>
parents: 36544
diff changeset
1310 purple_protocol_got_user_status(sip->account, from, "offline", NULL);
21417
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1311 break;
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1312 }
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1313 i++;
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1314 }
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1315 g_strfreev(ssparts);
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1316 }
20989
5707d9d29718 Patch from Will Hawkins for some cleanup of the SIMPLE notify message processing. This should hopefully fix some cases when a user signs off but we don't notice. Fixes #3507.
Daniel Atallah <datallah@pidgin.im>
parents: 20988
diff changeset
1317 send_sip_response(sip->gc, msg, 200, "OK", NULL);
18840
05aeff1821c4 Fix from Will Hawkins to plug some leaks in error cases for the SIMPLE prpl. References #2181.
Daniel Atallah <datallah@pidgin.im>
parents: 18552
diff changeset
1318 g_free(from);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1319 return;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1320 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1321
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34894
diff changeset
1322 if ((tuple = purple_xmlnode_get_child(pidf, "tuple")))
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34894
diff changeset
1323 if ((status = purple_xmlnode_get_child(tuple, "status")))
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34894
diff changeset
1324 basicstatus = purple_xmlnode_get_child(status, "basic");
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1325
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1326 if(!basicstatus) {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
1327 purple_debug_info("simple", "process_incoming_notify: no basic found\n");
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34894
diff changeset
1328 purple_xmlnode_free(pidf);
18840
05aeff1821c4 Fix from Will Hawkins to plug some leaks in error cases for the SIMPLE prpl. References #2181.
Daniel Atallah <datallah@pidgin.im>
parents: 18552
diff changeset
1329 g_free(from);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1330 return;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1331 }
11396
468e60b682cd [gaim-migrate @ 13627]
Daniel Atallah <datallah@pidgin.im>
parents: 11383
diff changeset
1332
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34894
diff changeset
1333 basicstatus_data = purple_xmlnode_get_data(basicstatus);
11396
468e60b682cd [gaim-migrate @ 13627]
Daniel Atallah <datallah@pidgin.im>
parents: 11383
diff changeset
1334
20989
5707d9d29718 Patch from Will Hawkins for some cleanup of the SIMPLE notify message processing. This should hopefully fix some cases when a user signs off but we don't notice. Fixes #3507.
Daniel Atallah <datallah@pidgin.im>
parents: 20988
diff changeset
1335 if(!basicstatus_data) {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
1336 purple_debug_info("simple", "process_incoming_notify: no basic data found\n");
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34894
diff changeset
1337 purple_xmlnode_free(pidf);
18840
05aeff1821c4 Fix from Will Hawkins to plug some leaks in error cases for the SIMPLE prpl. References #2181.
Daniel Atallah <datallah@pidgin.im>
parents: 18552
diff changeset
1338 g_free(from);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1339 return;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1340 }
11396
468e60b682cd [gaim-migrate @ 13627]
Daniel Atallah <datallah@pidgin.im>
parents: 11383
diff changeset
1341
20989
5707d9d29718 Patch from Will Hawkins for some cleanup of the SIMPLE notify message processing. This should hopefully fix some cases when a user signs off but we don't notice. Fixes #3507.
Daniel Atallah <datallah@pidgin.im>
parents: 20988
diff changeset
1342 if(strstr(basicstatus_data, "open"))
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1343 isonline = TRUE;
20989
5707d9d29718 Patch from Will Hawkins for some cleanup of the SIMPLE notify message processing. This should hopefully fix some cases when a user signs off but we don't notice. Fixes #3507.
Daniel Atallah <datallah@pidgin.im>
parents: 20988
diff changeset
1344
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1345
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 30138
diff changeset
1346 if(isonline)
36545
23b59a16c808 Replaced some _prpl_ stuff with _protocol_
Ankit Vani <a@nevitus.org>
parents: 36544
diff changeset
1347 purple_protocol_got_user_status(sip->account, from, "available", NULL);
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 30138
diff changeset
1348 else
36545
23b59a16c808 Replaced some _prpl_ stuff with _protocol_
Ankit Vani <a@nevitus.org>
parents: 36544
diff changeset
1349 purple_protocol_got_user_status(sip->account, from, "offline", NULL);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1350
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34894
diff changeset
1351 purple_xmlnode_free(pidf);
20989
5707d9d29718 Patch from Will Hawkins for some cleanup of the SIMPLE notify message processing. This should hopefully fix some cases when a user signs off but we don't notice. Fixes #3507.
Daniel Atallah <datallah@pidgin.im>
parents: 20988
diff changeset
1352 g_free(from);
5707d9d29718 Patch from Will Hawkins for some cleanup of the SIMPLE notify message processing. This should hopefully fix some cases when a user signs off but we don't notice. Fixes #3507.
Daniel Atallah <datallah@pidgin.im>
parents: 20988
diff changeset
1353 g_free(basicstatus_data);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1354
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1355 send_sip_response(sip->gc, msg, 200, "OK", NULL);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1356 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1357
34670
9bd5bd903dc7 Renamed chat buddies to chat users, and IM conversation typing state to IM typing state.
Ankit Vani <a@nevitus.org>
parents: 34622
diff changeset
1358 static unsigned int simple_typing(PurpleConnection *gc, const char *name, PurpleIMTypingState state) {
32266
af94a3153685 Convert simple prpl to use accessor functions purple_connection_get_protocol_data() and purple_connection_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents: 32157
diff changeset
1359 struct simple_account_data *sip = purple_connection_get_protocol_data(gc);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1360
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1361 gchar *xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1362 "<isComposing xmlns=\"urn:ietf:params:xml:ns:im-iscomposing\"\n"
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1363 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1364 "xsi:schemaLocation=\"urn:ietf:params:xml:ns:im-composing iscomposing.xsd\">\n"
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1365 "<state>%s</state>\n"
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1366 "<contenttype>text/plain</contenttype>\n"
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1367 "<refresh>60</refresh>\n"
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1368 "</isComposing>";
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1369 gchar *recv = g_strdup(name);
34670
9bd5bd903dc7 Renamed chat buddies to chat users, and IM conversation typing state to IM typing state.
Ankit Vani <a@nevitus.org>
parents: 34622
diff changeset
1370 if(state == PURPLE_IM_TYPING) {
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1371 gchar *msg = g_strdup_printf(xml, "active");
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1372 simple_send_message(sip, recv, msg, "application/im-iscomposing+xml");
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1373 g_free(msg);
34670
9bd5bd903dc7 Renamed chat buddies to chat users, and IM conversation typing state to IM typing state.
Ankit Vani <a@nevitus.org>
parents: 34622
diff changeset
1374 } else /* TODO: Only if (state == PURPLE_IM_TYPED) ? */ {
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1375 gchar *msg = g_strdup_printf(xml, "idle");
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1376 simple_send_message(sip, recv, msg, "application/im-iscomposing+xml");
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1377 g_free(msg);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1378 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1379 g_free(recv);
13844
835b8f7b3d1d [gaim-migrate @ 16295]
Mark Doliner <markdoliner@pidgin.im>
parents: 13751
diff changeset
1380 /*
835b8f7b3d1d [gaim-migrate @ 16295]
Mark Doliner <markdoliner@pidgin.im>
parents: 13751
diff changeset
1381 * TODO: Is this right? It will cause the core to call
35499
c4c5e0a670b1 Fix namespaces issues in libpurple.
Ankit Vani <a@nevitus.org>
parents: 35265
diff changeset
1382 * purple_serv_send_typing(gc, who, PURPLE_IM_TYPING) once every second
13844
835b8f7b3d1d [gaim-migrate @ 16295]
Mark Doliner <markdoliner@pidgin.im>
parents: 13751
diff changeset
1383 * until the user stops typing. If that's not desired,
835b8f7b3d1d [gaim-migrate @ 16295]
Mark Doliner <markdoliner@pidgin.im>
parents: 13751
diff changeset
1384 * then return 0 instead.
835b8f7b3d1d [gaim-migrate @ 16295]
Mark Doliner <markdoliner@pidgin.im>
parents: 13751
diff changeset
1385 */
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1386 return 1;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1387 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1388
14131
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
1389 static gchar *find_tag(const gchar *hdr) {
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
1390 const gchar *tmp = strstr(hdr, ";tag="), *tmp2;
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
1391
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1392 if(!tmp) return NULL;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1393 tmp += 5;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1394 if((tmp2 = strchr(tmp, ';'))) {
14131
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
1395 return g_strndup(tmp, tmp2 - tmp);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1396 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1397 return g_strdup(tmp);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1398 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1399
13178
824d50326672 [gaim-migrate @ 15540]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13130
diff changeset
1400 static gchar* gen_xpidf(struct simple_account_data *sip) {
824d50326672 [gaim-migrate @ 15540]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13130
diff changeset
1401 gchar *doc = g_strdup_printf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
824d50326672 [gaim-migrate @ 15540]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13130
diff changeset
1402 "<presence>\n"
824d50326672 [gaim-migrate @ 15540]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13130
diff changeset
1403 "<presentity uri=\"sip:%s@%s;method=SUBSCRIBE\"/>\n"
824d50326672 [gaim-migrate @ 15540]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13130
diff changeset
1404 "<display name=\"sip:%s@%s\"/>\n"
824d50326672 [gaim-migrate @ 15540]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13130
diff changeset
1405 "<atom id=\"1234\">\n"
824d50326672 [gaim-migrate @ 15540]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13130
diff changeset
1406 "<address uri=\"sip:%s@%s\">\n"
824d50326672 [gaim-migrate @ 15540]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13130
diff changeset
1407 "<status status=\"%s\"/>\n"
824d50326672 [gaim-migrate @ 15540]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13130
diff changeset
1408 "</address>\n"
824d50326672 [gaim-migrate @ 15540]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13130
diff changeset
1409 "</atom>\n"
824d50326672 [gaim-migrate @ 15540]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13130
diff changeset
1410 "</presence>\n",
824d50326672 [gaim-migrate @ 15540]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13130
diff changeset
1411 sip->username,
824d50326672 [gaim-migrate @ 15540]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13130
diff changeset
1412 sip->servername,
824d50326672 [gaim-migrate @ 15540]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13130
diff changeset
1413 sip->username,
824d50326672 [gaim-migrate @ 15540]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13130
diff changeset
1414 sip->servername,
824d50326672 [gaim-migrate @ 15540]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13130
diff changeset
1415 sip->username,
824d50326672 [gaim-migrate @ 15540]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13130
diff changeset
1416 sip->servername,
824d50326672 [gaim-migrate @ 15540]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13130
diff changeset
1417 sip->status);
824d50326672 [gaim-migrate @ 15540]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13130
diff changeset
1418 return doc;
824d50326672 [gaim-migrate @ 15540]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13130
diff changeset
1419 }
824d50326672 [gaim-migrate @ 15540]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13130
diff changeset
1420
20988
75eab0f2aa19 Patch from Will Hawkins to publish a status of closed when signing out of a SIMPLE account. Fixes #1914.
Daniel Atallah <datallah@pidgin.im>
parents: 20658
diff changeset
1421 static gchar* gen_pidf(struct simple_account_data *sip, gboolean open) {
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1422 gchar *doc = g_strdup_printf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
11396
468e60b682cd [gaim-migrate @ 13627]
Daniel Atallah <datallah@pidgin.im>
parents: 11383
diff changeset
1423 "<presence xmlns=\"urn:ietf:params:xml:ns:pidf\"\n"
468e60b682cd [gaim-migrate @ 13627]
Daniel Atallah <datallah@pidgin.im>
parents: 11383
diff changeset
1424 "xmlns:im=\"urn:ietf:params:xml:ns:pidf:im\"\n"
468e60b682cd [gaim-migrate @ 13627]
Daniel Atallah <datallah@pidgin.im>
parents: 11383
diff changeset
1425 "entity=\"sip:%s@%s\">\n"
468e60b682cd [gaim-migrate @ 13627]
Daniel Atallah <datallah@pidgin.im>
parents: 11383
diff changeset
1426 "<tuple id=\"bs35r9f\">\n"
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1427 "<status>\n"
20988
75eab0f2aa19 Patch from Will Hawkins to publish a status of closed when signing out of a SIMPLE account. Fixes #1914.
Daniel Atallah <datallah@pidgin.im>
parents: 20658
diff changeset
1428 "<basic>%s</basic>\n"
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1429 "</status>\n"
13656
32db312f1b9c [gaim-migrate @ 16057]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13581
diff changeset
1430 "<note>%s</note>\n"
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1431 "</tuple>\n"
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1432 "</presence>",
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1433 sip->username,
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1434 sip->servername,
20988
75eab0f2aa19 Patch from Will Hawkins to publish a status of closed when signing out of a SIMPLE account. Fixes #1914.
Daniel Atallah <datallah@pidgin.im>
parents: 20658
diff changeset
1435 (open == TRUE) ? "open" : "closed",
75eab0f2aa19 Patch from Will Hawkins to publish a status of closed when signing out of a SIMPLE account. Fixes #1914.
Daniel Atallah <datallah@pidgin.im>
parents: 20658
diff changeset
1436 (open == TRUE) ? sip->status : "");
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1437 return doc;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1438 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1439
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1440 static void send_notify(struct simple_account_data *sip, struct simple_watcher *watcher) {
20988
75eab0f2aa19 Patch from Will Hawkins to publish a status of closed when signing out of a SIMPLE account. Fixes #1914.
Daniel Atallah <datallah@pidgin.im>
parents: 20658
diff changeset
1441 gchar *doc = watcher->needsxpidf ? gen_xpidf(sip) : gen_pidf(sip, TRUE);
13178
824d50326672 [gaim-migrate @ 15540]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13130
diff changeset
1442 gchar *hdr = watcher->needsxpidf ? "Event: presence\r\nContent-Type: application/xpidf+xml\r\n" : "Event: presence\r\nContent-Type: application/pidf+xml\r\n";
824d50326672 [gaim-migrate @ 15540]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13130
diff changeset
1443 send_sip_request(sip->gc, "NOTIFY", watcher->name, watcher->name, hdr, doc, &watcher->dialog, NULL);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1444 g_free(doc);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1445 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1446
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1447 static gboolean process_publish_response(struct simple_account_data *sip, struct sipmsg *msg, struct transaction *tc) {
22182
0a0d7e312397 Patch from Will Hawkins to implement sending a SIP-If-Match header on subsequent PUBLISHes after receiving a SIP-Etag header. I made some minor tweaks to this, hopefully I didn't break anything. Fixes #4422.
Daniel Atallah <datallah@pidgin.im>
parents: 22104
diff changeset
1448
0a0d7e312397 Patch from Will Hawkins to implement sending a SIP-If-Match header on subsequent PUBLISHes after receiving a SIP-Etag header. I made some minor tweaks to this, hopefully I didn't break anything. Fixes #4422.
Daniel Atallah <datallah@pidgin.im>
parents: 22104
diff changeset
1449 const gchar *etag = NULL;
0a0d7e312397 Patch from Will Hawkins to implement sending a SIP-If-Match header on subsequent PUBLISHes after receiving a SIP-Etag header. I made some minor tweaks to this, hopefully I didn't break anything. Fixes #4422.
Daniel Atallah <datallah@pidgin.im>
parents: 22104
diff changeset
1450
11345
48a2f93e47b6 [gaim-migrate @ 13562]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11341
diff changeset
1451 if(msg->response != 200 && msg->response != 408) {
11341
5511bbeeb3b4 [gaim-migrate @ 13555]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11327
diff changeset
1452 /* never send again */
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1453 sip->republish = -1;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1454 }
22182
0a0d7e312397 Patch from Will Hawkins to implement sending a SIP-If-Match header on subsequent PUBLISHes after receiving a SIP-Etag header. I made some minor tweaks to this, hopefully I didn't break anything. Fixes #4422.
Daniel Atallah <datallah@pidgin.im>
parents: 22104
diff changeset
1455
0a0d7e312397 Patch from Will Hawkins to implement sending a SIP-If-Match header on subsequent PUBLISHes after receiving a SIP-Etag header. I made some minor tweaks to this, hopefully I didn't break anything. Fixes #4422.
Daniel Atallah <datallah@pidgin.im>
parents: 22104
diff changeset
1456 etag = sipmsg_find_header(msg, "SIP-Etag");
0a0d7e312397 Patch from Will Hawkins to implement sending a SIP-If-Match header on subsequent PUBLISHes after receiving a SIP-Etag header. I made some minor tweaks to this, hopefully I didn't break anything. Fixes #4422.
Daniel Atallah <datallah@pidgin.im>
parents: 22104
diff changeset
1457 if (etag) {
0a0d7e312397 Patch from Will Hawkins to implement sending a SIP-If-Match header on subsequent PUBLISHes after receiving a SIP-Etag header. I made some minor tweaks to this, hopefully I didn't break anything. Fixes #4422.
Daniel Atallah <datallah@pidgin.im>
parents: 22104
diff changeset
1458 /* we must store the etag somewhere. */
0a0d7e312397 Patch from Will Hawkins to implement sending a SIP-If-Match header on subsequent PUBLISHes after receiving a SIP-Etag header. I made some minor tweaks to this, hopefully I didn't break anything. Fixes #4422.
Daniel Atallah <datallah@pidgin.im>
parents: 22104
diff changeset
1459 g_free(sip->publish_etag);
0a0d7e312397 Patch from Will Hawkins to implement sending a SIP-If-Match header on subsequent PUBLISHes after receiving a SIP-Etag header. I made some minor tweaks to this, hopefully I didn't break anything. Fixes #4422.
Daniel Atallah <datallah@pidgin.im>
parents: 22104
diff changeset
1460 sip->publish_etag = g_strdup(etag);
0a0d7e312397 Patch from Will Hawkins to implement sending a SIP-If-Match header on subsequent PUBLISHes after receiving a SIP-Etag header. I made some minor tweaks to this, hopefully I didn't break anything. Fixes #4422.
Daniel Atallah <datallah@pidgin.im>
parents: 22104
diff changeset
1461 }
0a0d7e312397 Patch from Will Hawkins to implement sending a SIP-If-Match header on subsequent PUBLISHes after receiving a SIP-Etag header. I made some minor tweaks to this, hopefully I didn't break anything. Fixes #4422.
Daniel Atallah <datallah@pidgin.im>
parents: 22104
diff changeset
1462
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1463 return TRUE;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1464 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1465
20988
75eab0f2aa19 Patch from Will Hawkins to publish a status of closed when signing out of a SIMPLE account. Fixes #1914.
Daniel Atallah <datallah@pidgin.im>
parents: 20658
diff changeset
1466 static void send_open_publish(struct simple_account_data *sip) {
21417
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1467 gchar *add_headers = NULL;
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1468 gchar *uri = g_strdup_printf("sip:%s@%s", sip->username, sip->servername);
20988
75eab0f2aa19 Patch from Will Hawkins to publish a status of closed when signing out of a SIMPLE account. Fixes #1914.
Daniel Atallah <datallah@pidgin.im>
parents: 20658
diff changeset
1469 gchar *doc = gen_pidf(sip, TRUE);
21417
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1470
22182
0a0d7e312397 Patch from Will Hawkins to implement sending a SIP-If-Match header on subsequent PUBLISHes after receiving a SIP-Etag header. I made some minor tweaks to this, hopefully I didn't break anything. Fixes #4422.
Daniel Atallah <datallah@pidgin.im>
parents: 22104
diff changeset
1471 add_headers = g_strdup_printf("%s%s%s%s%d\r\n%s",
0a0d7e312397 Patch from Will Hawkins to implement sending a SIP-If-Match header on subsequent PUBLISHes after receiving a SIP-Etag header. I made some minor tweaks to this, hopefully I didn't break anything. Fixes #4422.
Daniel Atallah <datallah@pidgin.im>
parents: 22104
diff changeset
1472 sip->publish_etag ? "SIP-If-Match: " : "",
0a0d7e312397 Patch from Will Hawkins to implement sending a SIP-If-Match header on subsequent PUBLISHes after receiving a SIP-Etag header. I made some minor tweaks to this, hopefully I didn't break anything. Fixes #4422.
Daniel Atallah <datallah@pidgin.im>
parents: 22104
diff changeset
1473 sip->publish_etag ? sip->publish_etag : "",
0a0d7e312397 Patch from Will Hawkins to implement sending a SIP-If-Match header on subsequent PUBLISHes after receiving a SIP-Etag header. I made some minor tweaks to this, hopefully I didn't break anything. Fixes #4422.
Daniel Atallah <datallah@pidgin.im>
parents: 22104
diff changeset
1474 sip->publish_etag ? "\r\n" : "",
0a0d7e312397 Patch from Will Hawkins to implement sending a SIP-If-Match header on subsequent PUBLISHes after receiving a SIP-Etag header. I made some minor tweaks to this, hopefully I didn't break anything. Fixes #4422.
Daniel Atallah <datallah@pidgin.im>
parents: 22104
diff changeset
1475 "Expires: ", PUBLISH_EXPIRATION,
0a0d7e312397 Patch from Will Hawkins to implement sending a SIP-If-Match header on subsequent PUBLISHes after receiving a SIP-Etag header. I made some minor tweaks to this, hopefully I didn't break anything. Fixes #4422.
Daniel Atallah <datallah@pidgin.im>
parents: 22104
diff changeset
1476 "Event: presence\r\n"
21417
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1477 "Content-Type: application/pidf+xml\r\n");
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1478
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
1479 send_sip_request(sip->gc, "PUBLISH", uri, uri,
21417
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1480 add_headers, doc, NULL, process_publish_response);
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1481 sip->republish = time(NULL) + PUBLISH_EXPIRATION - 50;
14131
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
1482 g_free(uri);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1483 g_free(doc);
21417
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
1484 g_free(add_headers);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1485 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1486
20988
75eab0f2aa19 Patch from Will Hawkins to publish a status of closed when signing out of a SIMPLE account. Fixes #1914.
Daniel Atallah <datallah@pidgin.im>
parents: 20658
diff changeset
1487 static void send_closed_publish(struct simple_account_data *sip) {
75eab0f2aa19 Patch from Will Hawkins to publish a status of closed when signing out of a SIMPLE account. Fixes #1914.
Daniel Atallah <datallah@pidgin.im>
parents: 20658
diff changeset
1488 gchar *uri = g_strdup_printf("sip:%s@%s", sip->username, sip->servername);
22182
0a0d7e312397 Patch from Will Hawkins to implement sending a SIP-If-Match header on subsequent PUBLISHes after receiving a SIP-Etag header. I made some minor tweaks to this, hopefully I didn't break anything. Fixes #4422.
Daniel Atallah <datallah@pidgin.im>
parents: 22104
diff changeset
1489 gchar *add_headers, *doc;
0a0d7e312397 Patch from Will Hawkins to implement sending a SIP-If-Match header on subsequent PUBLISHes after receiving a SIP-Etag header. I made some minor tweaks to this, hopefully I didn't break anything. Fixes #4422.
Daniel Atallah <datallah@pidgin.im>
parents: 22104
diff changeset
1490
0a0d7e312397 Patch from Will Hawkins to implement sending a SIP-If-Match header on subsequent PUBLISHes after receiving a SIP-Etag header. I made some minor tweaks to this, hopefully I didn't break anything. Fixes #4422.
Daniel Atallah <datallah@pidgin.im>
parents: 22104
diff changeset
1491 add_headers = g_strdup_printf("%s%s%s%s",
0a0d7e312397 Patch from Will Hawkins to implement sending a SIP-If-Match header on subsequent PUBLISHes after receiving a SIP-Etag header. I made some minor tweaks to this, hopefully I didn't break anything. Fixes #4422.
Daniel Atallah <datallah@pidgin.im>
parents: 22104
diff changeset
1492 sip->publish_etag ? "SIP-If-Match: " : "",
0a0d7e312397 Patch from Will Hawkins to implement sending a SIP-If-Match header on subsequent PUBLISHes after receiving a SIP-Etag header. I made some minor tweaks to this, hopefully I didn't break anything. Fixes #4422.
Daniel Atallah <datallah@pidgin.im>
parents: 22104
diff changeset
1493 sip->publish_etag ? sip->publish_etag : "",
0a0d7e312397 Patch from Will Hawkins to implement sending a SIP-If-Match header on subsequent PUBLISHes after receiving a SIP-Etag header. I made some minor tweaks to this, hopefully I didn't break anything. Fixes #4422.
Daniel Atallah <datallah@pidgin.im>
parents: 22104
diff changeset
1494 sip->publish_etag ? "\r\n" : "",
0a0d7e312397 Patch from Will Hawkins to implement sending a SIP-If-Match header on subsequent PUBLISHes after receiving a SIP-Etag header. I made some minor tweaks to this, hopefully I didn't break anything. Fixes #4422.
Daniel Atallah <datallah@pidgin.im>
parents: 22104
diff changeset
1495 "Expires: 600\r\n"
0a0d7e312397 Patch from Will Hawkins to implement sending a SIP-If-Match header on subsequent PUBLISHes after receiving a SIP-Etag header. I made some minor tweaks to this, hopefully I didn't break anything. Fixes #4422.
Daniel Atallah <datallah@pidgin.im>
parents: 22104
diff changeset
1496 "Event: presence\r\n"
0a0d7e312397 Patch from Will Hawkins to implement sending a SIP-If-Match header on subsequent PUBLISHes after receiving a SIP-Etag header. I made some minor tweaks to this, hopefully I didn't break anything. Fixes #4422.
Daniel Atallah <datallah@pidgin.im>
parents: 22104
diff changeset
1497 "Content-Type: application/pidf+xml\r\n");
0a0d7e312397 Patch from Will Hawkins to implement sending a SIP-If-Match header on subsequent PUBLISHes after receiving a SIP-Etag header. I made some minor tweaks to this, hopefully I didn't break anything. Fixes #4422.
Daniel Atallah <datallah@pidgin.im>
parents: 22104
diff changeset
1498
0a0d7e312397 Patch from Will Hawkins to implement sending a SIP-If-Match header on subsequent PUBLISHes after receiving a SIP-Etag header. I made some minor tweaks to this, hopefully I didn't break anything. Fixes #4422.
Daniel Atallah <datallah@pidgin.im>
parents: 22104
diff changeset
1499 doc = gen_pidf(sip, FALSE);
0a0d7e312397 Patch from Will Hawkins to implement sending a SIP-If-Match header on subsequent PUBLISHes after receiving a SIP-Etag header. I made some minor tweaks to this, hopefully I didn't break anything. Fixes #4422.
Daniel Atallah <datallah@pidgin.im>
parents: 22104
diff changeset
1500 send_sip_request(sip->gc, "PUBLISH", uri, uri, add_headers,
20988
75eab0f2aa19 Patch from Will Hawkins to publish a status of closed when signing out of a SIMPLE account. Fixes #1914.
Daniel Atallah <datallah@pidgin.im>
parents: 20658
diff changeset
1501 doc, NULL, process_publish_response);
75eab0f2aa19 Patch from Will Hawkins to publish a status of closed when signing out of a SIMPLE account. Fixes #1914.
Daniel Atallah <datallah@pidgin.im>
parents: 20658
diff changeset
1502 /*sip->republish = time(NULL) + 500;*/
75eab0f2aa19 Patch from Will Hawkins to publish a status of closed when signing out of a SIMPLE account. Fixes #1914.
Daniel Atallah <datallah@pidgin.im>
parents: 20658
diff changeset
1503 g_free(uri);
75eab0f2aa19 Patch from Will Hawkins to publish a status of closed when signing out of a SIMPLE account. Fixes #1914.
Daniel Atallah <datallah@pidgin.im>
parents: 20658
diff changeset
1504 g_free(doc);
22182
0a0d7e312397 Patch from Will Hawkins to implement sending a SIP-If-Match header on subsequent PUBLISHes after receiving a SIP-Etag header. I made some minor tweaks to this, hopefully I didn't break anything. Fixes #4422.
Daniel Atallah <datallah@pidgin.im>
parents: 22104
diff changeset
1505 g_free(add_headers);
20988
75eab0f2aa19 Patch from Will Hawkins to publish a status of closed when signing out of a SIMPLE account. Fixes #1914.
Daniel Atallah <datallah@pidgin.im>
parents: 20658
diff changeset
1506 }
75eab0f2aa19 Patch from Will Hawkins to publish a status of closed when signing out of a SIMPLE account. Fixes #1914.
Daniel Atallah <datallah@pidgin.im>
parents: 20658
diff changeset
1507
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1508 static void process_incoming_subscribe(struct simple_account_data *sip, struct sipmsg *msg) {
14131
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
1509 const char *from_hdr = sipmsg_find_header(msg, "From");
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
1510 gchar *from = parse_from(from_hdr);
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
1511 gchar *theirtag = find_tag(from_hdr);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1512 gchar *ourtag = find_tag(sipmsg_find_header(msg, "To"));
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1513 gboolean tagadded = FALSE;
21100
814637ced463 Some constification, which also found and fixed some potential double-free
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 21076
diff changeset
1514 const gchar *callid = sipmsg_find_header(msg, "Call-ID");
814637ced463 Some constification, which also found and fixed some potential double-free
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 21076
diff changeset
1515 const gchar *expire = sipmsg_find_header(msg, "Expire");
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1516 gchar *tmp;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1517 struct simple_watcher *watcher = watcher_find(sip, from);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1518 if(!ourtag) {
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1519 tagadded = TRUE;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1520 ourtag = gentag();
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1521 }
11341
5511bbeeb3b4 [gaim-migrate @ 13555]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11327
diff changeset
1522 if(!watcher) { /* new subscription */
21100
814637ced463 Some constification, which also found and fixed some potential double-free
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 21076
diff changeset
1523 const gchar *acceptheader = sipmsg_find_header(msg, "Accept");
14131
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
1524 gboolean needsxpidf = FALSE;
34578
cfb2f856a5d0 Refactored prpls according to the changed PurpleAccount API
Ankit Vani <a@nevitus.org>
parents: 34557
diff changeset
1525 if(!purple_account_privacy_check(sip->account, from)) {
11345
48a2f93e47b6 [gaim-migrate @ 13562]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11341
diff changeset
1526 send_sip_response(sip->gc, msg, 202, "Ok", NULL);
48a2f93e47b6 [gaim-migrate @ 13562]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11341
diff changeset
1527 goto privend;
48a2f93e47b6 [gaim-migrate @ 13562]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11341
diff changeset
1528 }
13178
824d50326672 [gaim-migrate @ 15540]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13130
diff changeset
1529 if(acceptheader) {
21100
814637ced463 Some constification, which also found and fixed some potential double-free
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 21076
diff changeset
1530 const gchar *tmp = acceptheader;
14132
2325b60d8b77 [gaim-migrate @ 16691]
Daniel Atallah <datallah@pidgin.im>
parents: 14131
diff changeset
1531 gboolean foundpidf = FALSE;
2325b60d8b77 [gaim-migrate @ 16691]
Daniel Atallah <datallah@pidgin.im>
parents: 14131
diff changeset
1532 gboolean foundxpidf = FALSE;
13178
824d50326672 [gaim-migrate @ 15540]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13130
diff changeset
1533 while(tmp && tmp < acceptheader + strlen(acceptheader)) {
824d50326672 [gaim-migrate @ 15540]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13130
diff changeset
1534 gchar *tmp2 = strchr(tmp, ',');
824d50326672 [gaim-migrate @ 15540]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13130
diff changeset
1535 if(tmp2) *tmp2 = '\0';
17155
143ff2796376 Replace strcasecmp() calls with glib equivalents.
Richard Laager <rlaager@pidgin.im>
parents: 16746
diff changeset
1536 if(!g_ascii_strcasecmp("application/pidf+xml", tmp))
14132
2325b60d8b77 [gaim-migrate @ 16691]
Daniel Atallah <datallah@pidgin.im>
parents: 14131
diff changeset
1537 foundpidf = TRUE;
17155
143ff2796376 Replace strcasecmp() calls with glib equivalents.
Richard Laager <rlaager@pidgin.im>
parents: 16746
diff changeset
1538 if(!g_ascii_strcasecmp("application/xpidf+xml", tmp))
14132
2325b60d8b77 [gaim-migrate @ 16691]
Daniel Atallah <datallah@pidgin.im>
parents: 14131
diff changeset
1539 foundxpidf = TRUE;
13178
824d50326672 [gaim-migrate @ 15540]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13130
diff changeset
1540 if(tmp2) {
824d50326672 [gaim-migrate @ 15540]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13130
diff changeset
1541 *tmp2 = ',';
17653
a71ca6b486a0 Fix a freeze caused by improper SIMPLE message parsing. Thanks, Michal Matyska! Fixes #1037
Sean Egan <seanegan@pidgin.im>
parents: 17226
diff changeset
1542 tmp = tmp2 + 1;
13178
824d50326672 [gaim-migrate @ 15540]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13130
diff changeset
1543 while(*tmp == ' ') tmp++;
824d50326672 [gaim-migrate @ 15540]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13130
diff changeset
1544 } else
37390
209a1350d87f Assign pointers to NULL rather than 0.
Michael McConville <mmcconville@mykolab.com>
parents: 37163
diff changeset
1545 tmp = NULL;
13178
824d50326672 [gaim-migrate @ 15540]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13130
diff changeset
1546 }
14131
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
1547 if(!foundpidf && foundxpidf) needsxpidf = TRUE;
13178
824d50326672 [gaim-migrate @ 15540]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13130
diff changeset
1548 }
824d50326672 [gaim-migrate @ 15540]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13130
diff changeset
1549 watcher = watcher_create(sip, from, callid, ourtag, theirtag, needsxpidf);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1550 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1551 if(tagadded) {
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1552 gchar *to = g_strdup_printf("%s;tag=%s", sipmsg_find_header(msg, "To"), ourtag);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1553 sipmsg_remove_header(msg, "To");
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1554 sipmsg_add_header(msg, "To", to);
14131
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
1555 g_free(to);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1556 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1557 if(expire)
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1558 watcher->expire = time(NULL) + strtol(expire, NULL, 10);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1559 else
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1560 watcher->expire = time(NULL) + 600;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1561 sipmsg_remove_header(msg, "Contact");
13178
824d50326672 [gaim-migrate @ 15540]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13130
diff changeset
1562 tmp = get_contact(sip);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1563 sipmsg_add_header(msg, "Contact", tmp);
13178
824d50326672 [gaim-migrate @ 15540]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13130
diff changeset
1564 g_free(tmp);
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
1565 purple_debug_info("simple", "got subscribe: name %s ourtag %s theirtag %s callid %s\n", watcher->name, watcher->dialog.ourtag, watcher->dialog.theirtag, watcher->dialog.callid);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1566 send_sip_response(sip->gc, msg, 200, "Ok", NULL);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1567 send_notify(sip, watcher);
11345
48a2f93e47b6 [gaim-migrate @ 13562]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11341
diff changeset
1568 privend:
48a2f93e47b6 [gaim-migrate @ 13562]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11341
diff changeset
1569 g_free(from);
48a2f93e47b6 [gaim-migrate @ 13562]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11341
diff changeset
1570 g_free(theirtag);
48a2f93e47b6 [gaim-migrate @ 13562]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11341
diff changeset
1571 g_free(ourtag);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1572 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1573
11189
5ac07336091e [gaim-migrate @ 13307]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11181
diff changeset
1574 static void process_input_message(struct simple_account_data *sip, struct sipmsg *msg) {
12745
1dc3525647c2 [gaim-migrate @ 15092]
Daniel Atallah <datallah@pidgin.im>
parents: 12741
diff changeset
1575 gboolean found = FALSE;
1dc3525647c2 [gaim-migrate @ 15092]
Daniel Atallah <datallah@pidgin.im>
parents: 12741
diff changeset
1576 if(msg->response == 0) { /* request */
38258
9a6551eba09c Replace !strcmp() with purple_strequal()
qarkai <qarkai@gmail.com>
parents: 36041
diff changeset
1577 if(purple_strequal(msg->method, "MESSAGE")) {
11189
5ac07336091e [gaim-migrate @ 13307]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11181
diff changeset
1578 process_incoming_message(sip, msg);
12745
1dc3525647c2 [gaim-migrate @ 15092]
Daniel Atallah <datallah@pidgin.im>
parents: 12741
diff changeset
1579 found = TRUE;
38258
9a6551eba09c Replace !strcmp() with purple_strequal()
qarkai <qarkai@gmail.com>
parents: 36041
diff changeset
1580 } else if(purple_strequal(msg->method, "NOTIFY")) {
11189
5ac07336091e [gaim-migrate @ 13307]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11181
diff changeset
1581 process_incoming_notify(sip, msg);
12745
1dc3525647c2 [gaim-migrate @ 15092]
Daniel Atallah <datallah@pidgin.im>
parents: 12741
diff changeset
1582 found = TRUE;
38258
9a6551eba09c Replace !strcmp() with purple_strequal()
qarkai <qarkai@gmail.com>
parents: 36041
diff changeset
1583 } else if(purple_strequal(msg->method, "SUBSCRIBE")) {
11189
5ac07336091e [gaim-migrate @ 13307]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11181
diff changeset
1584 process_incoming_subscribe(sip, msg);
12745
1dc3525647c2 [gaim-migrate @ 15092]
Daniel Atallah <datallah@pidgin.im>
parents: 12741
diff changeset
1585 found = TRUE;
1dc3525647c2 [gaim-migrate @ 15092]
Daniel Atallah <datallah@pidgin.im>
parents: 12741
diff changeset
1586 } else {
11396
468e60b682cd [gaim-migrate @ 13627]
Daniel Atallah <datallah@pidgin.im>
parents: 11383
diff changeset
1587 send_sip_response(sip->gc, msg, 501, "Not implemented", NULL);
11190
16f02ac58a38 [gaim-migrate @ 13308]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11189
diff changeset
1588 }
11341
5511bbeeb3b4 [gaim-migrate @ 13555]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11327
diff changeset
1589 } else { /* response */
11189
5ac07336091e [gaim-migrate @ 13307]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11181
diff changeset
1590 struct transaction *trans = transactions_find(sip, msg);
5ac07336091e [gaim-migrate @ 13307]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11181
diff changeset
1591 if(trans) {
5ac07336091e [gaim-migrate @ 13307]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11181
diff changeset
1592 if(msg->response == 407) {
21100
814637ced463 Some constification, which also found and fixed some potential double-free
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 21076
diff changeset
1593 gchar *resend, *auth;
814637ced463 Some constification, which also found and fixed some potential double-free
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 21076
diff changeset
1594 const gchar *ptmp;
11439
e76bc2f9deb0 [gaim-migrate @ 13676]
Daniel Atallah <datallah@pidgin.im>
parents: 11424
diff changeset
1595
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
1596 if(sip->proxy.retries > 3) return;
11346
4af1dc4b2c44 [gaim-migrate @ 13563]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11345
diff changeset
1597 sip->proxy.retries++;
11341
5511bbeeb3b4 [gaim-migrate @ 13555]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11327
diff changeset
1598 /* do proxy authentication */
11189
5ac07336091e [gaim-migrate @ 13307]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11181
diff changeset
1599
11439
e76bc2f9deb0 [gaim-migrate @ 13676]
Daniel Atallah <datallah@pidgin.im>
parents: 11424
diff changeset
1600 ptmp = sipmsg_find_header(msg, "Proxy-Authenticate");
11396
468e60b682cd [gaim-migrate @ 13627]
Daniel Atallah <datallah@pidgin.im>
parents: 11383
diff changeset
1601
11189
5ac07336091e [gaim-migrate @ 13307]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11181
diff changeset
1602 fill_auth(sip, ptmp, &sip->proxy);
11346
4af1dc4b2c44 [gaim-migrate @ 13563]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11345
diff changeset
1603 auth = auth_header(sip, &sip->proxy, trans->msg->method, trans->msg->target);
13273
68a4ff81c348 [gaim-migrate @ 15638]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13201
diff changeset
1604 sipmsg_remove_header(trans->msg, "Proxy-Authorization");
11189
5ac07336091e [gaim-migrate @ 13307]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11181
diff changeset
1605 sipmsg_add_header(trans->msg, "Proxy-Authorization", auth);
5ac07336091e [gaim-migrate @ 13307]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11181
diff changeset
1606 g_free(auth);
5ac07336091e [gaim-migrate @ 13307]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11181
diff changeset
1607 resend = sipmsg_to_string(trans->msg);
11341
5511bbeeb3b4 [gaim-migrate @ 13555]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11327
diff changeset
1608 /* resend request */
11189
5ac07336091e [gaim-migrate @ 13307]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11181
diff changeset
1609 sendout_pkt(sip->gc, resend);
5ac07336091e [gaim-migrate @ 13307]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11181
diff changeset
1610 g_free(resend);
5ac07336091e [gaim-migrate @ 13307]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11181
diff changeset
1611 } else {
11517
a3d6d136b7dd [gaim-migrate @ 13762]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11483
diff changeset
1612 if(msg->response == 100) {
a3d6d136b7dd [gaim-migrate @ 13762]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11483
diff changeset
1613 /* ignore provisional response */
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
1614 purple_debug_info("simple", "got trying response\n");
11517
a3d6d136b7dd [gaim-migrate @ 13762]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11483
diff changeset
1615 } else {
a3d6d136b7dd [gaim-migrate @ 13762]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11483
diff changeset
1616 sip->proxy.retries = 0;
38258
9a6551eba09c Replace !strcmp() with purple_strequal()
qarkai <qarkai@gmail.com>
parents: 36041
diff changeset
1617 if(purple_strequal(trans->msg->method, "REGISTER")) {
19991
603d11d2afa7 Fixes #3051 Patch from Will Hawkins to clean up SIMPLE login and registration
Sean Egan <seanegan@pidgin.im>
parents: 19859
diff changeset
1618
603d11d2afa7 Fixes #3051 Patch from Will Hawkins to clean up SIMPLE login and registration
Sean Egan <seanegan@pidgin.im>
parents: 19859
diff changeset
1619 /* This is encountered when a REGISTER request was ...
603d11d2afa7 Fixes #3051 Patch from Will Hawkins to clean up SIMPLE login and registration
Sean Egan <seanegan@pidgin.im>
parents: 19859
diff changeset
1620 */
603d11d2afa7 Fixes #3051 Patch from Will Hawkins to clean up SIMPLE login and registration
Sean Egan <seanegan@pidgin.im>
parents: 19859
diff changeset
1621 if(msg->response == 401) {
603d11d2afa7 Fixes #3051 Patch from Will Hawkins to clean up SIMPLE login and registration
Sean Egan <seanegan@pidgin.im>
parents: 19859
diff changeset
1622 /* denied until further authentication was provided. */
603d11d2afa7 Fixes #3051 Patch from Will Hawkins to clean up SIMPLE login and registration
Sean Egan <seanegan@pidgin.im>
parents: 19859
diff changeset
1623 sip->registrar.retries++;
603d11d2afa7 Fixes #3051 Patch from Will Hawkins to clean up SIMPLE login and registration
Sean Egan <seanegan@pidgin.im>
parents: 19859
diff changeset
1624 }
603d11d2afa7 Fixes #3051 Patch from Will Hawkins to clean up SIMPLE login and registration
Sean Egan <seanegan@pidgin.im>
parents: 19859
diff changeset
1625 else if (msg->response != 200) {
603d11d2afa7 Fixes #3051 Patch from Will Hawkins to clean up SIMPLE login and registration
Sean Egan <seanegan@pidgin.im>
parents: 19859
diff changeset
1626 /* denied for some other reason! */
603d11d2afa7 Fixes #3051 Patch from Will Hawkins to clean up SIMPLE login and registration
Sean Egan <seanegan@pidgin.im>
parents: 19859
diff changeset
1627 sip->registrar.retries++;
603d11d2afa7 Fixes #3051 Patch from Will Hawkins to clean up SIMPLE login and registration
Sean Egan <seanegan@pidgin.im>
parents: 19859
diff changeset
1628 }
603d11d2afa7 Fixes #3051 Patch from Will Hawkins to clean up SIMPLE login and registration
Sean Egan <seanegan@pidgin.im>
parents: 19859
diff changeset
1629 else {
603d11d2afa7 Fixes #3051 Patch from Will Hawkins to clean up SIMPLE login and registration
Sean Egan <seanegan@pidgin.im>
parents: 19859
diff changeset
1630 /* accepted! */
603d11d2afa7 Fixes #3051 Patch from Will Hawkins to clean up SIMPLE login and registration
Sean Egan <seanegan@pidgin.im>
parents: 19859
diff changeset
1631 sip->registrar.retries = 0;
603d11d2afa7 Fixes #3051 Patch from Will Hawkins to clean up SIMPLE login and registration
Sean Egan <seanegan@pidgin.im>
parents: 19859
diff changeset
1632 }
13348
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
1633 } else {
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
1634 if(msg->response == 401) {
19991
603d11d2afa7 Fixes #3051 Patch from Will Hawkins to clean up SIMPLE login and registration
Sean Egan <seanegan@pidgin.im>
parents: 19859
diff changeset
1635 /* This is encountered when a generic (MESSAGE, NOTIFY, etc)
603d11d2afa7 Fixes #3051 Patch from Will Hawkins to clean up SIMPLE login and registration
Sean Egan <seanegan@pidgin.im>
parents: 19859
diff changeset
1636 * was denied until further authorization is provided.
603d11d2afa7 Fixes #3051 Patch from Will Hawkins to clean up SIMPLE login and registration
Sean Egan <seanegan@pidgin.im>
parents: 19859
diff changeset
1637 */
21100
814637ced463 Some constification, which also found and fixed some potential double-free
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 21076
diff changeset
1638 gchar *resend, *auth;
814637ced463 Some constification, which also found and fixed some potential double-free
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 21076
diff changeset
1639 const gchar *ptmp;
13348
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
1640
19991
603d11d2afa7 Fixes #3051 Patch from Will Hawkins to clean up SIMPLE login and registration
Sean Egan <seanegan@pidgin.im>
parents: 19859
diff changeset
1641 if(sip->registrar.retries > SIMPLE_REGISTER_RETRY_MAX) return;
13348
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
1642 sip->registrar.retries++;
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
1643
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
1644 ptmp = sipmsg_find_header(msg, "WWW-Authenticate");
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
1645
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
1646 fill_auth(sip, ptmp, &sip->registrar);
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
1647 auth = auth_header(sip, &sip->registrar, trans->msg->method, trans->msg->target);
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
1648 sipmsg_remove_header(trans->msg, "Authorization");
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
1649 sipmsg_add_header(trans->msg, "Authorization", auth);
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
1650 g_free(auth);
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
1651 resend = sipmsg_to_string(trans->msg);
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
1652 /* resend request */
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
1653 sendout_pkt(sip->gc, resend);
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
1654 g_free(resend);
19991
603d11d2afa7 Fixes #3051 Patch from Will Hawkins to clean up SIMPLE login and registration
Sean Egan <seanegan@pidgin.im>
parents: 19859
diff changeset
1655 } else {
603d11d2afa7 Fixes #3051 Patch from Will Hawkins to clean up SIMPLE login and registration
Sean Egan <seanegan@pidgin.im>
parents: 19859
diff changeset
1656 /* Reset any count of retries that may have
603d11d2afa7 Fixes #3051 Patch from Will Hawkins to clean up SIMPLE login and registration
Sean Egan <seanegan@pidgin.im>
parents: 19859
diff changeset
1657 * accumulated in the above branch.
603d11d2afa7 Fixes #3051 Patch from Will Hawkins to clean up SIMPLE login and registration
Sean Egan <seanegan@pidgin.im>
parents: 19859
diff changeset
1658 */
603d11d2afa7 Fixes #3051 Patch from Will Hawkins to clean up SIMPLE login and registration
Sean Egan <seanegan@pidgin.im>
parents: 19859
diff changeset
1659 sip->registrar.retries = 0;
13348
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
1660 }
1fe9d587d705 [gaim-migrate @ 15717]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 13297
diff changeset
1661 }
11517
a3d6d136b7dd [gaim-migrate @ 13762]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11483
diff changeset
1662 if(trans->callback) {
a3d6d136b7dd [gaim-migrate @ 13762]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11483
diff changeset
1663 /* call the callback to process response*/
a3d6d136b7dd [gaim-migrate @ 13762]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11483
diff changeset
1664 (trans->callback)(sip, msg, trans);
a3d6d136b7dd [gaim-migrate @ 13762]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11483
diff changeset
1665 }
a3d6d136b7dd [gaim-migrate @ 13762]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11483
diff changeset
1666 transactions_remove(sip, trans);
11189
5ac07336091e [gaim-migrate @ 13307]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11181
diff changeset
1667 }
5ac07336091e [gaim-migrate @ 13307]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11181
diff changeset
1668 }
12745
1dc3525647c2 [gaim-migrate @ 15092]
Daniel Atallah <datallah@pidgin.im>
parents: 12741
diff changeset
1669 found = TRUE;
11189
5ac07336091e [gaim-migrate @ 13307]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11181
diff changeset
1670 } else {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
1671 purple_debug(PURPLE_DEBUG_MISC, "simple", "received response to unknown transaction");
11189
5ac07336091e [gaim-migrate @ 13307]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11181
diff changeset
1672 }
5ac07336091e [gaim-migrate @ 13307]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11181
diff changeset
1673 }
5ac07336091e [gaim-migrate @ 13307]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11181
diff changeset
1674 if(!found) {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
1675 purple_debug(PURPLE_DEBUG_MISC, "simple", "received a unknown sip message with method %s and response %d\n", msg->method, msg->response);
11189
5ac07336091e [gaim-migrate @ 13307]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11181
diff changeset
1676 }
5ac07336091e [gaim-migrate @ 13307]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11181
diff changeset
1677 }
5ac07336091e [gaim-migrate @ 13307]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11181
diff changeset
1678
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1679 static void process_input(struct simple_account_data *sip, struct sip_connection *conn)
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1680 {
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1681 char *cur;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1682 char *dummy;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1683 struct sipmsg *msg;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1684 int restlen;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1685 cur = conn->inbuf;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1686
11341
5511bbeeb3b4 [gaim-migrate @ 13555]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11327
diff changeset
1687 /* according to the RFC remove CRLF at the beginning */
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1688 while(*cur == '\r' || *cur == '\n') {
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1689 cur++;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1690 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1691 if(cur != conn->inbuf) {
14131
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
1692 memmove(conn->inbuf, cur, conn->inbufused - (cur - conn->inbuf));
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
1693 conn->inbufused = strlen(conn->inbuf);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1694 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1695
11341
5511bbeeb3b4 [gaim-migrate @ 13555]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11327
diff changeset
1696 /* Received a full Header? */
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
1697 if((cur = strstr(conn->inbuf, "\r\n\r\n")) != NULL) {
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1698 time_t currtime = time(NULL);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1699 cur += 2;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1700 cur[0] = '\0';
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
1701 purple_debug_info("simple", "\n\nreceived - %s\n######\n%s\n#######\n\n", ctime(&currtime), conn->inbuf);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1702 msg = sipmsg_parse_header(conn->inbuf);
24758
26c1c4bc47c0 Add a NULL check to fix a crash. Fixes #4516.
Richard Laager <rlaager@pidgin.im>
parents: 24638
diff changeset
1703
26c1c4bc47c0 Add a NULL check to fix a crash. Fixes #4516.
Richard Laager <rlaager@pidgin.im>
parents: 24638
diff changeset
1704 if(!msg) {
26c1c4bc47c0 Add a NULL check to fix a crash. Fixes #4516.
Richard Laager <rlaager@pidgin.im>
parents: 24638
diff changeset
1705 /* Should we re-use this error message (from lower in the function)? */
26c1c4bc47c0 Add a NULL check to fix a crash. Fixes #4516.
Richard Laager <rlaager@pidgin.im>
parents: 24638
diff changeset
1706 purple_debug_misc("simple", "received a incomplete sip msg: %s\n", conn->inbuf);
26c1c4bc47c0 Add a NULL check to fix a crash. Fixes #4516.
Richard Laager <rlaager@pidgin.im>
parents: 24638
diff changeset
1707 return;
26c1c4bc47c0 Add a NULL check to fix a crash. Fixes #4516.
Richard Laager <rlaager@pidgin.im>
parents: 24638
diff changeset
1708 }
26c1c4bc47c0 Add a NULL check to fix a crash. Fixes #4516.
Richard Laager <rlaager@pidgin.im>
parents: 24638
diff changeset
1709
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1710 cur[0] = '\r';
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1711 cur += 2;
14131
2cd4ddea2f52 [gaim-migrate @ 16690]
Daniel Atallah <datallah@pidgin.im>
parents: 14043
diff changeset
1712 restlen = conn->inbufused - (cur - conn->inbuf);
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
1713 if(restlen >= msg->bodylen) {
35221
6bd2dd10e5da Simple: fix a possible NULL-pointer dereference and add some input filtering. Fixes VRT-2013-1004
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33782
diff changeset
1714 dummy = g_new(char, msg->bodylen + 1);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1715 memcpy(dummy, cur, msg->bodylen);
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
1716 dummy[msg->bodylen] = '\0';
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1717 msg->body = dummy;
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
1718 cur += msg->bodylen;
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
1719 memmove(conn->inbuf, cur, conn->inbuflen - (cur - conn->inbuf));
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
1720 conn->inbufused = strlen(conn->inbuf);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1721 } else {
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1722 sipmsg_free(msg);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1723 return;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1724 }
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
1725 purple_debug(PURPLE_DEBUG_MISC, "simple", "in process response response: %d\n", msg->response);
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
1726 process_input_message(sip, msg);
29997
9a9b586ac254 Lots of little memleak fixes
Mark Doliner <markdoliner@pidgin.im>
parents: 29996
diff changeset
1727 sipmsg_free(msg);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1728 } else {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
1729 purple_debug(PURPLE_DEBUG_MISC, "simple", "received a incomplete sip msg: %s\n", conn->inbuf);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1730 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1731 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1732
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
1733 static void simple_udp_process(gpointer data, gint source, PurpleInputCondition con) {
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
1734 PurpleConnection *gc = data;
32266
af94a3153685 Convert simple prpl to use accessor functions purple_connection_get_protocol_data() and purple_connection_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents: 32157
diff changeset
1735 struct simple_account_data *sip = purple_connection_get_protocol_data(gc);
11189
5ac07336091e [gaim-migrate @ 13307]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11181
diff changeset
1736 struct sipmsg *msg;
5ac07336091e [gaim-migrate @ 13307]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11181
diff changeset
1737 int len;
29996
bcc1ae2c2550 Two SIMPLE changes:
Mark Doliner <markdoliner@pidgin.im>
parents: 29989
diff changeset
1738 time_t currtime = time(NULL);
11189
5ac07336091e [gaim-migrate @ 13307]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11181
diff changeset
1739
5ac07336091e [gaim-migrate @ 13307]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11181
diff changeset
1740 static char buffer[65536];
12770
f9bbe68a0c88 [gaim-migrate @ 15117]
Daniel Atallah <datallah@pidgin.im>
parents: 12769
diff changeset
1741 if((len = recv(source, buffer, sizeof(buffer) - 1, 0)) > 0) {
12748
f2cbf850b529 [gaim-migrate @ 15095]
Daniel Atallah <datallah@pidgin.im>
parents: 12746
diff changeset
1742 buffer[len] = '\0';
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
1743 purple_debug_info("simple", "\n\nreceived - %s\n######\n%s\n#######\n\n", ctime(&currtime), buffer);
12748
f2cbf850b529 [gaim-migrate @ 15095]
Daniel Atallah <datallah@pidgin.im>
parents: 12746
diff changeset
1744 msg = sipmsg_parse_msg(buffer);
30007
09362ce17f6f simple: sipmsg_free() can't handle NULL. Reported by Jochen
Paul Aurich <darkrain42@pidgin.im>
parents: 29998
diff changeset
1745 if (msg) {
09362ce17f6f simple: sipmsg_free() can't handle NULL. Reported by Jochen
Paul Aurich <darkrain42@pidgin.im>
parents: 29998
diff changeset
1746 process_input_message(sip, msg);
09362ce17f6f simple: sipmsg_free() can't handle NULL. Reported by Jochen
Paul Aurich <darkrain42@pidgin.im>
parents: 29998
diff changeset
1747 sipmsg_free(msg);
09362ce17f6f simple: sipmsg_free() can't handle NULL. Reported by Jochen
Paul Aurich <darkrain42@pidgin.im>
parents: 29998
diff changeset
1748 }
12748
f2cbf850b529 [gaim-migrate @ 15095]
Daniel Atallah <datallah@pidgin.im>
parents: 12746
diff changeset
1749 }
11189
5ac07336091e [gaim-migrate @ 13307]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11181
diff changeset
1750 }
5ac07336091e [gaim-migrate @ 13307]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11181
diff changeset
1751
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
1752 static void simple_input_cb(gpointer data, gint source, PurpleInputCondition cond)
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1753 {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
1754 PurpleConnection *gc = data;
32266
af94a3153685 Convert simple prpl to use accessor functions purple_connection_get_protocol_data() and purple_connection_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents: 32157
diff changeset
1755 struct simple_account_data *sip = purple_connection_get_protocol_data(gc);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1756 int len;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1757 struct sip_connection *conn = connection_find(sip, source);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1758 if(!conn) {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
1759 purple_debug_error("simple", "Connection not found!\n");
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1760 return;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1761 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1762
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
1763 if(conn->inbuflen < conn->inbufused + SIMPLE_BUF_INC) {
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1764 conn->inbuflen += SIMPLE_BUF_INC;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1765 conn->inbuf = g_realloc(conn->inbuf, conn->inbuflen);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1766 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1767
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
1768 len = read(source, conn->inbuf + conn->inbufused, SIMPLE_BUF_INC - 1);
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
1769
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
1770 if(len < 0 && errno == EAGAIN)
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
1771 return;
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
1772 else if(len <= 0) {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
1773 purple_debug_info("simple", "simple_input_cb: read error\n");
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1774 connection_remove(sip, source);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1775 if(sip->fd == source) sip->fd = -1;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1776 return;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1777 }
32679
fd936a0b84f7 Add a purple_connection_update_last_received() function to update the
Andrew Victor <andrew.victor@mxit.com>
parents: 32678
diff changeset
1778 purple_connection_update_last_received(gc);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1779 conn->inbufused += len;
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
1780 conn->inbuf[conn->inbufused] = '\0';
11396
468e60b682cd [gaim-migrate @ 13627]
Daniel Atallah <datallah@pidgin.im>
parents: 11383
diff changeset
1781
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1782 process_input(sip, conn);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1783 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1784
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1785 /* Callback for new connections on incoming TCP port */
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
1786 static void simple_newconn_cb(gpointer data, gint source, PurpleInputCondition cond) {
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
1787 PurpleConnection *gc = data;
32266
af94a3153685 Convert simple prpl to use accessor functions purple_connection_get_protocol_data() and purple_connection_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents: 32157
diff changeset
1788 struct simple_account_data *sip = purple_connection_get_protocol_data(gc);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1789 struct sip_connection *conn;
36028
fc5300cb3617 Get rid of fair amount of copy-pasta and coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35991
diff changeset
1790 int newfd;
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1791
24040
24ff94bfd09d Use non-blocking io for inbound TCP connections for SIMPLE.
Daniel Atallah <datallah@pidgin.im>
parents: 23495
diff changeset
1792 newfd = accept(source, NULL, NULL);
36041
7f35f441b939 Fix a coverity typo
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 36037
diff changeset
1793 g_return_if_fail(newfd >= 0);
36037
e2ef692ff10a Fix outstaning Coverity bugs
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 36028
diff changeset
1794
36028
fc5300cb3617 Get rid of fair amount of copy-pasta and coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35991
diff changeset
1795 _purple_network_set_common_socket_flags(newfd);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1796
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1797 conn = connection_create(sip, newfd);
11396
468e60b682cd [gaim-migrate @ 13627]
Daniel Atallah <datallah@pidgin.im>
parents: 11383
diff changeset
1798
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
1799 conn->inputhandler = purple_input_add(newfd, PURPLE_INPUT_READ, simple_input_cb, gc);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1800 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1801
14180
77010795da2c [gaim-migrate @ 16752]
Mark Doliner <markdoliner@pidgin.im>
parents: 14170
diff changeset
1802 static void login_cb(gpointer data, gint source, const gchar *error_message) {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
1803 PurpleConnection *gc = data;
14180
77010795da2c [gaim-migrate @ 16752]
Mark Doliner <markdoliner@pidgin.im>
parents: 14170
diff changeset
1804 struct simple_account_data *sip;
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1805 struct sip_connection *conn;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1806
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
1807 if(source < 0) {
27635
0cd19038c417 More uniformity among disconnect error messages
Mark Doliner <markdoliner@pidgin.im>
parents: 27350
diff changeset
1808 gchar *tmp = g_strdup_printf(_("Unable to connect: %s"),
0cd19038c417 More uniformity among disconnect error messages
Mark Doliner <markdoliner@pidgin.im>
parents: 27350
diff changeset
1809 error_message);
32157
39ba2e2492ee Rename purple_connection_error_reason to purple_connection_error
Mark Doliner <markdoliner@pidgin.im>
parents: 31949
diff changeset
1810 purple_connection_error(gc,
27635
0cd19038c417 More uniformity among disconnect error messages
Mark Doliner <markdoliner@pidgin.im>
parents: 27350
diff changeset
1811 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp);
0cd19038c417 More uniformity among disconnect error messages
Mark Doliner <markdoliner@pidgin.im>
parents: 27350
diff changeset
1812 g_free(tmp);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1813 return;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1814 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1815
32266
af94a3153685 Convert simple prpl to use accessor functions purple_connection_get_protocol_data() and purple_connection_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents: 32157
diff changeset
1816 sip = purple_connection_get_protocol_data(gc);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1817 sip->fd = source;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1818
11396
468e60b682cd [gaim-migrate @ 13627]
Daniel Atallah <datallah@pidgin.im>
parents: 11383
diff changeset
1819 conn = connection_create(sip, source);
13093
e27434c31f00 [gaim-migrate @ 15454]
Daniel Atallah <datallah@pidgin.im>
parents: 13089
diff changeset
1820
38433
361c801c4536 Remove purple_timeout_* function usage
Mike Ruprecht <cmaiku@gmail.com>
parents: 38409
diff changeset
1821 sip->registertimeout = g_timeout_add(g_random_int_range(10000, 100000), (GSourceFunc)subscribe_timeout, sip);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1822
11194
47dc0e9a757a [gaim-migrate @ 13317]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11192
diff changeset
1823 do_register(sip);
11396
468e60b682cd [gaim-migrate @ 13627]
Daniel Atallah <datallah@pidgin.im>
parents: 11383
diff changeset
1824
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
1825 conn->inputhandler = purple_input_add(sip->fd, PURPLE_INPUT_READ, simple_input_cb, gc);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1826 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1827
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1828 static guint simple_ht_hash_nick(const char *nick) {
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1829 char *lc = g_utf8_strdown(nick, -1);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1830 guint bucket = g_str_hash(lc);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1831 g_free(lc);
11396
468e60b682cd [gaim-migrate @ 13627]
Daniel Atallah <datallah@pidgin.im>
parents: 11383
diff changeset
1832
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1833 return bucket;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1834 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1835
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1836 static gboolean simple_ht_equals_nick(const char *nick1, const char *nick2) {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
1837 return (purple_utf8_strcasecmp(nick1, nick2) == 0);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1838 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
1839
12909
dfcf4df1dcd7 [gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents: 12770
diff changeset
1840 static void simple_udp_host_resolved_listen_cb(int listenfd, gpointer data) {
dfcf4df1dcd7 [gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents: 12770
diff changeset
1841 struct simple_account_data *sip = (struct simple_account_data*) data;
dfcf4df1dcd7 [gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents: 12770
diff changeset
1842
14329
05c3cc0c1f79 [gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents: 14324
diff changeset
1843 sip->listen_data = NULL;
05c3cc0c1f79 [gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents: 14324
diff changeset
1844
12909
dfcf4df1dcd7 [gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents: 12770
diff changeset
1845 if(listenfd == -1) {
32157
39ba2e2492ee Rename purple_connection_error_reason to purple_connection_error
Mark Doliner <markdoliner@pidgin.im>
parents: 31949
diff changeset
1846 purple_connection_error(sip->gc,
21279
40685e1f50ca Rename:
Will Thompson <resiak@pidgin.im>
parents: 21152
diff changeset
1847 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
27635
0cd19038c417 More uniformity among disconnect error messages
Mark Doliner <markdoliner@pidgin.im>
parents: 27350
diff changeset
1848 _("Unable to create listen socket"));
12909
dfcf4df1dcd7 [gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents: 12770
diff changeset
1849 return;
dfcf4df1dcd7 [gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents: 12770
diff changeset
1850 }
dfcf4df1dcd7 [gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents: 12770
diff changeset
1851
29996
bcc1ae2c2550 Two SIMPLE changes:
Mark Doliner <markdoliner@pidgin.im>
parents: 29989
diff changeset
1852 /*
bcc1ae2c2550 Two SIMPLE changes:
Mark Doliner <markdoliner@pidgin.im>
parents: 29989
diff changeset
1853 * TODO: Is it correct to set sip->fd to the listenfd? For the TCP
bcc1ae2c2550 Two SIMPLE changes:
Mark Doliner <markdoliner@pidgin.im>
parents: 29989
diff changeset
1854 * listener we set sip->listenfd, but maybe UDP is different?
bcc1ae2c2550 Two SIMPLE changes:
Mark Doliner <markdoliner@pidgin.im>
parents: 29989
diff changeset
1855 * Maybe we use the same fd for outgoing data or something?
bcc1ae2c2550 Two SIMPLE changes:
Mark Doliner <markdoliner@pidgin.im>
parents: 29989
diff changeset
1856 */
12909
dfcf4df1dcd7 [gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents: 12770
diff changeset
1857 sip->fd = listenfd;
dfcf4df1dcd7 [gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents: 12770
diff changeset
1858
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
1859 sip->listenport = purple_network_get_port_from_fd(sip->fd);
12909
dfcf4df1dcd7 [gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents: 12770
diff changeset
1860
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
1861 sip->listenpa = purple_input_add(sip->fd, PURPLE_INPUT_READ, simple_udp_process, sip->gc);
12909
dfcf4df1dcd7 [gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents: 12770
diff changeset
1862
38433
361c801c4536 Remove purple_timeout_* function usage
Mike Ruprecht <cmaiku@gmail.com>
parents: 38409
diff changeset
1863 sip->resendtimeout = g_timeout_add(2500, (GSourceFunc) resend_timeout, sip);
361c801c4536 Remove purple_timeout_* function usage
Mike Ruprecht <cmaiku@gmail.com>
parents: 38409
diff changeset
1864 sip->registertimeout = g_timeout_add(g_random_int_range(10000, 100000), (GSourceFunc)subscribe_timeout, sip);
12909
dfcf4df1dcd7 [gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents: 12770
diff changeset
1865 do_register(sip);
dfcf4df1dcd7 [gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents: 12770
diff changeset
1866 }
dfcf4df1dcd7 [gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents: 12770
diff changeset
1867
37458
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
1868 static void
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
1869 simple_udp_host_resolved(GObject *sender, GAsyncResult *result, gpointer data) {
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
1870 GError *error = NULL;
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
1871 GList *addresses = NULL;
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
1872 GInetAddress *inet_address = NULL;
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
1873 GSocketAddress *socket_address = NULL;
12767
4870d7755883 [gaim-migrate @ 15114]
Daniel Atallah <datallah@pidgin.im>
parents: 12760
diff changeset
1874 struct simple_account_data *sip = (struct simple_account_data*) data;
4870d7755883 [gaim-migrate @ 15114]
Daniel Atallah <datallah@pidgin.im>
parents: 12760
diff changeset
1875
37517
a67be31f9c7e Use the GResolver which was passed to g_resolver_lookup_*_async()
Mike Ruprecht <cmaiku@gmail.com>
parents: 37458
diff changeset
1876 addresses = g_resolver_lookup_by_name_finish(G_RESOLVER(sender),
a67be31f9c7e Use the GResolver which was passed to g_resolver_lookup_*_async()
Mike Ruprecht <cmaiku@gmail.com>
parents: 37458
diff changeset
1877 result, &error);
37458
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
1878 if(error) {
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
1879 gchar *msg = g_strdup_printf(_("Unable to resolve hostname : %s"),
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
1880 error->message);
14300
68a0aa63f3b8 [gaim-migrate @ 16920]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
1881
32157
39ba2e2492ee Rename purple_connection_error_reason to purple_connection_error
Mark Doliner <markdoliner@pidgin.im>
parents: 31949
diff changeset
1882 purple_connection_error(sip->gc,
21279
40685e1f50ca Rename:
Will Thompson <resiak@pidgin.im>
parents: 21152
diff changeset
1883 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
37458
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
1884 msg
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
1885 );
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
1886
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
1887 g_error_free(error);
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
1888
12767
4870d7755883 [gaim-migrate @ 15114]
Daniel Atallah <datallah@pidgin.im>
parents: 12760
diff changeset
1889 return;
4870d7755883 [gaim-migrate @ 15114]
Daniel Atallah <datallah@pidgin.im>
parents: 12760
diff changeset
1890 }
4870d7755883 [gaim-migrate @ 15114]
Daniel Atallah <datallah@pidgin.im>
parents: 12760
diff changeset
1891
37458
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
1892 inet_address = G_INET_ADDRESS(addresses->data);
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
1893 socket_address = g_inet_socket_address_new(inet_address, sip->realport);
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
1894 g_object_unref(G_OBJECT(inet_address));
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
1895
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
1896 g_socket_address_to_native(socket_address,
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
1897 &(sip->serveraddr),
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
1898 g_socket_address_get_native_size(socket_address),
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
1899 NULL);
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
1900
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
1901 g_object_unref(G_OBJECT(socket_address));
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
1902
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
1903 g_resolver_free_addresses(addresses);
12767
4870d7755883 [gaim-migrate @ 15114]
Daniel Atallah <datallah@pidgin.im>
parents: 12760
diff changeset
1904
4870d7755883 [gaim-migrate @ 15114]
Daniel Atallah <datallah@pidgin.im>
parents: 12760
diff changeset
1905 /* create socket for incoming connections */
32594
f2feea134fdb Remove deprecated purple_network_listen_map_external().
Andrew Victor <andrew.victor@mxit.com>
parents: 32593
diff changeset
1906 sip->listen_data = purple_network_listen_range(5060, 5160, AF_UNSPEC, SOCK_DGRAM, TRUE,
14329
05c3cc0c1f79 [gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents: 14324
diff changeset
1907 simple_udp_host_resolved_listen_cb, sip);
05c3cc0c1f79 [gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents: 14324
diff changeset
1908 if (sip->listen_data == NULL) {
32157
39ba2e2492ee Rename purple_connection_error_reason to purple_connection_error
Mark Doliner <markdoliner@pidgin.im>
parents: 31949
diff changeset
1909 purple_connection_error(sip->gc,
21279
40685e1f50ca Rename:
Will Thompson <resiak@pidgin.im>
parents: 21152
diff changeset
1910 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
27635
0cd19038c417 More uniformity among disconnect error messages
Mark Doliner <markdoliner@pidgin.im>
parents: 27350
diff changeset
1911 _("Unable to create listen socket"));
12909
dfcf4df1dcd7 [gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents: 12770
diff changeset
1912 return;
dfcf4df1dcd7 [gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents: 12770
diff changeset
1913 }
dfcf4df1dcd7 [gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents: 12770
diff changeset
1914 }
12767
4870d7755883 [gaim-migrate @ 15114]
Daniel Atallah <datallah@pidgin.im>
parents: 12760
diff changeset
1915
12909
dfcf4df1dcd7 [gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents: 12770
diff changeset
1916 static void
dfcf4df1dcd7 [gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents: 12770
diff changeset
1917 simple_tcp_connect_listen_cb(int listenfd, gpointer data) {
dfcf4df1dcd7 [gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents: 12770
diff changeset
1918 struct simple_account_data *sip = (struct simple_account_data*) data;
dfcf4df1dcd7 [gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents: 12770
diff changeset
1919
14329
05c3cc0c1f79 [gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents: 14324
diff changeset
1920 sip->listen_data = NULL;
05c3cc0c1f79 [gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents: 14324
diff changeset
1921
12909
dfcf4df1dcd7 [gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents: 12770
diff changeset
1922 sip->listenfd = listenfd;
dfcf4df1dcd7 [gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents: 12770
diff changeset
1923 if(sip->listenfd == -1) {
32157
39ba2e2492ee Rename purple_connection_error_reason to purple_connection_error
Mark Doliner <markdoliner@pidgin.im>
parents: 31949
diff changeset
1924 purple_connection_error(sip->gc,
21279
40685e1f50ca Rename:
Will Thompson <resiak@pidgin.im>
parents: 21152
diff changeset
1925 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
27635
0cd19038c417 More uniformity among disconnect error messages
Mark Doliner <markdoliner@pidgin.im>
parents: 27350
diff changeset
1926 _("Unable to create listen socket"));
12767
4870d7755883 [gaim-migrate @ 15114]
Daniel Atallah <datallah@pidgin.im>
parents: 12760
diff changeset
1927 return;
4870d7755883 [gaim-migrate @ 15114]
Daniel Atallah <datallah@pidgin.im>
parents: 12760
diff changeset
1928 }
4870d7755883 [gaim-migrate @ 15114]
Daniel Atallah <datallah@pidgin.im>
parents: 12760
diff changeset
1929
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
1930 purple_debug_info("simple", "listenfd: %d\n", sip->listenfd);
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
1931 sip->listenport = purple_network_get_port_from_fd(sip->listenfd);
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
1932 sip->listenpa = purple_input_add(sip->listenfd, PURPLE_INPUT_READ,
12909
dfcf4df1dcd7 [gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents: 12770
diff changeset
1933 simple_newconn_cb, sip->gc);
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
1934 purple_debug_info("simple", "connecting to %s port %d\n",
12909
dfcf4df1dcd7 [gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents: 12770
diff changeset
1935 sip->realhostname, sip->realport);
dfcf4df1dcd7 [gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents: 12770
diff changeset
1936 /* open tcp connection to the server */
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
1937 if (purple_proxy_connect(sip->gc, sip->account, sip->realhostname,
14899
c65f0b4fb351 [gaim-migrate @ 17606]
Mark Doliner <markdoliner@pidgin.im>
parents: 14696
diff changeset
1938 sip->realport, login_cb, sip->gc) == NULL) {
32157
39ba2e2492ee Rename purple_connection_error_reason to purple_connection_error
Mark Doliner <markdoliner@pidgin.im>
parents: 31949
diff changeset
1939 purple_connection_error(sip->gc,
21279
40685e1f50ca Rename:
Will Thompson <resiak@pidgin.im>
parents: 21152
diff changeset
1940 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
27635
0cd19038c417 More uniformity among disconnect error messages
Mark Doliner <markdoliner@pidgin.im>
parents: 27350
diff changeset
1941 _("Unable to connect"));
12909
dfcf4df1dcd7 [gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents: 12770
diff changeset
1942 }
12767
4870d7755883 [gaim-migrate @ 15114]
Daniel Atallah <datallah@pidgin.im>
parents: 12760
diff changeset
1943 }
4870d7755883 [gaim-migrate @ 15114]
Daniel Atallah <datallah@pidgin.im>
parents: 12760
diff changeset
1944
37458
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
1945 static void
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
1946 srvresolved(GObject *sender, GAsyncResult *result, gpointer data) {
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
1947 GError *error = NULL;
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
1948 GList *targets = NULL;
13581
d0f0e28aa864 [gaim-migrate @ 15962]
Mark Doliner <markdoliner@pidgin.im>
parents: 13399
diff changeset
1949 struct simple_account_data *sip;
d0f0e28aa864 [gaim-migrate @ 15962]
Mark Doliner <markdoliner@pidgin.im>
parents: 13399
diff changeset
1950 gchar *hostname;
d0f0e28aa864 [gaim-migrate @ 15962]
Mark Doliner <markdoliner@pidgin.im>
parents: 13399
diff changeset
1951 int port;
11383
2c5a70e62389 [gaim-migrate @ 13610]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11346
diff changeset
1952
14370
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14329
diff changeset
1953 sip = data;
11383
2c5a70e62389 [gaim-migrate @ 13610]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11346
diff changeset
1954
37517
a67be31f9c7e Use the GResolver which was passed to g_resolver_lookup_*_async()
Mike Ruprecht <cmaiku@gmail.com>
parents: 37458
diff changeset
1955 targets = g_resolver_lookup_service_finish(G_RESOLVER(sender),
a67be31f9c7e Use the GResolver which was passed to g_resolver_lookup_*_async()
Mike Ruprecht <cmaiku@gmail.com>
parents: 37458
diff changeset
1956 result, &error);
37458
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
1957 if(error) {
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
1958 purple_debug_info("simple",
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
1959 "srv lookup failed, continuing with configured settings : %s",
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
1960 error->message);
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
1961
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
1962 g_error_free(error);
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
1963
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
1964 if(!purple_account_get_bool(sip->account, "useproxy", FALSE)) {
11383
2c5a70e62389 [gaim-migrate @ 13610]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11346
diff changeset
1965 hostname = g_strdup(sip->servername);
2c5a70e62389 [gaim-migrate @ 13610]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11346
diff changeset
1966 } else {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
1967 hostname = g_strdup(purple_account_get_string(sip->account, "proxy", sip->servername));
37458
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
1968 }
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
1969 port = purple_account_get_int(sip->account, "port", 0);
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
1970 } else {
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
1971 GSrvTarget *target = (GSrvTarget *)targets->data;
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
1972
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
1973 hostname = g_strdup(g_srv_target_get_hostname(target));
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
1974 port = g_srv_target_get_port(target);
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
1975
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
1976 g_resolver_free_targets(targets);
11383
2c5a70e62389 [gaim-migrate @ 13610]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11346
diff changeset
1977 }
11396
468e60b682cd [gaim-migrate @ 13627]
Daniel Atallah <datallah@pidgin.im>
parents: 11383
diff changeset
1978
11383
2c5a70e62389 [gaim-migrate @ 13610]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11346
diff changeset
1979 sip->realhostname = hostname;
11396
468e60b682cd [gaim-migrate @ 13627]
Daniel Atallah <datallah@pidgin.im>
parents: 11383
diff changeset
1980 sip->realport = port;
37458
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
1981
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
1982 if(!sip->realport)
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
1983 sip->realport = 5060;
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
1984
11383
2c5a70e62389 [gaim-migrate @ 13610]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11346
diff changeset
1985 /* TCP case */
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
1986 if(!sip->udp) {
11409
2a3466f4a32c [gaim-migrate @ 13646]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11396
diff changeset
1987 /* create socket for incoming connections */
32594
f2feea134fdb Remove deprecated purple_network_listen_map_external().
Andrew Victor <andrew.victor@mxit.com>
parents: 32593
diff changeset
1988 sip->listen_data = purple_network_listen_range(5060, 5160, AF_UNSPEC, SOCK_STREAM, TRUE,
14329
05c3cc0c1f79 [gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents: 14324
diff changeset
1989 simple_tcp_connect_listen_cb, sip);
05c3cc0c1f79 [gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents: 14324
diff changeset
1990 if (sip->listen_data == NULL) {
32157
39ba2e2492ee Rename purple_connection_error_reason to purple_connection_error
Mark Doliner <markdoliner@pidgin.im>
parents: 31949
diff changeset
1991 purple_connection_error(sip->gc,
21279
40685e1f50ca Rename:
Will Thompson <resiak@pidgin.im>
parents: 21152
diff changeset
1992 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
27635
0cd19038c417 More uniformity among disconnect error messages
Mark Doliner <markdoliner@pidgin.im>
parents: 27350
diff changeset
1993 _("Unable to create listen socket"));
11409
2a3466f4a32c [gaim-migrate @ 13646]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11396
diff changeset
1994 return;
2a3466f4a32c [gaim-migrate @ 13646]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11396
diff changeset
1995 }
11383
2c5a70e62389 [gaim-migrate @ 13610]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11346
diff changeset
1996 } else { /* UDP */
37518
53c9ebedf2b7 Plug g_resolver_get_default() leaks
Mike Ruprecht <cmaiku@gmail.com>
parents: 37517
diff changeset
1997 GResolver *resolver = g_resolver_get_default();
53c9ebedf2b7 Plug g_resolver_get_default() leaks
Mike Ruprecht <cmaiku@gmail.com>
parents: 37517
diff changeset
1998
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
1999 purple_debug_info("simple", "using udp with server %s and port %d\n", hostname, port);
12565
8601c9c26f93 [gaim-migrate @ 14884]
Daniel Atallah <datallah@pidgin.im>
parents: 12563
diff changeset
2000
37518
53c9ebedf2b7 Plug g_resolver_get_default() leaks
Mike Ruprecht <cmaiku@gmail.com>
parents: 37517
diff changeset
2001 g_resolver_lookup_by_name_async(resolver,
37458
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
2002 sip->realhostname,
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
2003 sip->cancellable,
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
2004 simple_udp_host_resolved,
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
2005 sip);
37518
53c9ebedf2b7 Plug g_resolver_get_default() leaks
Mike Ruprecht <cmaiku@gmail.com>
parents: 37517
diff changeset
2006 g_object_unref(resolver);
11383
2c5a70e62389 [gaim-migrate @ 13610]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11346
diff changeset
2007 }
2c5a70e62389 [gaim-migrate @ 13610]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11346
diff changeset
2008 }
2c5a70e62389 [gaim-migrate @ 13610]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11346
diff changeset
2009
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
2010 static void simple_login(PurpleAccount *account)
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
2011 {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
2012 PurpleConnection *gc;
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
2013 struct simple_account_data *sip;
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
2014 gchar **userserver;
23495
cc9ee7e6a09f There's no need to dup this
Mark Doliner <markdoliner@pidgin.im>
parents: 23302
diff changeset
2015 const gchar *hosttoconnect;
37518
53c9ebedf2b7 Plug g_resolver_get_default() leaks
Mike Ruprecht <cmaiku@gmail.com>
parents: 37517
diff changeset
2016 const char *username = purple_account_get_username(account);
53c9ebedf2b7 Plug g_resolver_get_default() leaks
Mike Ruprecht <cmaiku@gmail.com>
parents: 37517
diff changeset
2017 GResolver *resolver;
11396
468e60b682cd [gaim-migrate @ 13627]
Daniel Atallah <datallah@pidgin.im>
parents: 11383
diff changeset
2018
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
2019 gc = purple_account_get_connection(account);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
2020
36055
33978dc8ef6f Remove redundant OPT_PROTO_IM_IMAGE (use \!PURPLE_CONNECTION_FLAG_NO_IMAGES instead)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 36042
diff changeset
2021 purple_connection_set_flags(gc, PURPLE_CONNECTION_FLAG_NO_IMAGES);
33978dc8ef6f Remove redundant OPT_PROTO_IM_IMAGE (use \!PURPLE_CONNECTION_FLAG_NO_IMAGES instead)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 36042
diff changeset
2022
11396
468e60b682cd [gaim-migrate @ 13627]
Daniel Atallah <datallah@pidgin.im>
parents: 11383
diff changeset
2023 if (strpbrk(username, " \t\v\r\n") != NULL) {
32157
39ba2e2492ee Rename purple_connection_error_reason to purple_connection_error
Mark Doliner <markdoliner@pidgin.im>
parents: 31949
diff changeset
2024 purple_connection_error(gc,
21279
40685e1f50ca Rename:
Will Thompson <resiak@pidgin.im>
parents: 21152
diff changeset
2025 PURPLE_CONNECTION_ERROR_INVALID_SETTINGS,
22942
2bf494f8e2a4 Change the string "screen name" to "username" everywhere. I think most
Mark Doliner <markdoliner@pidgin.im>
parents: 22709
diff changeset
2026 _("SIP usernames may not contain whitespaces or @ symbols"));
11396
468e60b682cd [gaim-migrate @ 13627]
Daniel Atallah <datallah@pidgin.im>
parents: 11383
diff changeset
2027 return;
468e60b682cd [gaim-migrate @ 13627]
Daniel Atallah <datallah@pidgin.im>
parents: 11383
diff changeset
2028 }
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
2029
32266
af94a3153685 Convert simple prpl to use accessor functions purple_connection_get_protocol_data() and purple_connection_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents: 32157
diff changeset
2030 sip = g_new0(struct simple_account_data, 1);
af94a3153685 Convert simple prpl to use accessor functions purple_connection_get_protocol_data() and purple_connection_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents: 32157
diff changeset
2031 purple_connection_set_protocol_data(gc, sip);
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
2032 sip->gc = gc;
31949
f141aee90086 Fix some closes on invalid fds, which can crash on Windows.
Florian Quèze <florian@instantbird.org>
parents: 31680
diff changeset
2033 sip->fd = -1;
f141aee90086 Fix some closes on invalid fds, which can crash on Windows.
Florian Quèze <florian@instantbird.org>
parents: 31680
diff changeset
2034 sip->listenfd = -1;
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
2035 sip->account = account;
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
2036 sip->registerexpire = 900;
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
2037 sip->udp = purple_account_get_bool(account, "udp", FALSE);
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
2038 /* TODO: is there a good default grow size? */
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
2039 if(!sip->udp)
34529
68cf25486001 GObjectify PurpleCircBuffer as PurpleCircularBuffer (from gobjectification branch)
Ankit Vani <a@nevitus.org>
parents: 34111
diff changeset
2040 sip->txbuf = purple_circular_buffer_new(0);
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 13185
diff changeset
2041
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
2042 userserver = g_strsplit(username, "@", 2);
25179
0dbf2eb5f168 Don't allow connecting a SIMPLE account if no server is configured. Fixes #7767.
Florian Quèze <florian@instantbird.org>
parents: 24845
diff changeset
2043 if (userserver[1] == NULL || userserver[1][0] == '\0') {
32157
39ba2e2492ee Rename purple_connection_error_reason to purple_connection_error
Mark Doliner <markdoliner@pidgin.im>
parents: 31949
diff changeset
2044 purple_connection_error(gc,
25179
0dbf2eb5f168 Don't allow connecting a SIMPLE account if no server is configured. Fixes #7767.
Florian Quèze <florian@instantbird.org>
parents: 24845
diff changeset
2045 PURPLE_CONNECTION_ERROR_INVALID_SETTINGS,
25206
4758bccd444c disapproval of revision '99fcf96872a999874e2f1e5f46bd44f4a487119c'
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 25201
diff changeset
2046 _("SIP connect server not specified"));
25179
0dbf2eb5f168 Don't allow connecting a SIMPLE account if no server is configured. Fixes #7767.
Florian Quèze <florian@instantbird.org>
parents: 24845
diff changeset
2047 return;
0dbf2eb5f168 Don't allow connecting a SIMPLE account if no server is configured. Fixes #7767.
Florian Quèze <florian@instantbird.org>
parents: 24845
diff changeset
2048 }
0dbf2eb5f168 Don't allow connecting a SIMPLE account if no server is configured. Fixes #7767.
Florian Quèze <florian@instantbird.org>
parents: 24845
diff changeset
2049
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
2050 purple_connection_set_display_name(gc, userserver[0]);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
2051 sip->username = g_strdup(userserver[0]);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
2052 sip->servername = g_strdup(userserver[1]);
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
2053 sip->password = g_strdup(purple_connection_get_password(gc));
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
2054 g_strfreev(userserver);
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
2055
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
2056 sip->buddies = g_hash_table_new((GHashFunc)simple_ht_hash_nick, (GEqualFunc)simple_ht_equals_nick);
11396
468e60b682cd [gaim-migrate @ 13627]
Daniel Atallah <datallah@pidgin.im>
parents: 11383
diff changeset
2057
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
2058 purple_connection_update_progress(gc, _("Connecting"), 1, 2);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
2059
11837
2f1206084fef [gaim-migrate @ 14128]
Mark Doliner <markdoliner@pidgin.im>
parents: 11718
diff changeset
2060 /* TODO: Set the status correctly. */
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
2061 sip->status = g_strdup("available");
11189
5ac07336091e [gaim-migrate @ 13307]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11181
diff changeset
2062
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
2063 if(!purple_account_get_bool(account, "useproxy", FALSE)) {
23495
cc9ee7e6a09f There's no need to dup this
Mark Doliner <markdoliner@pidgin.im>
parents: 23302
diff changeset
2064 hosttoconnect = sip->servername;
11210
95ba2527d7d1 [gaim-migrate @ 13341]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11194
diff changeset
2065 } else {
23495
cc9ee7e6a09f There's no need to dup this
Mark Doliner <markdoliner@pidgin.im>
parents: 23302
diff changeset
2066 hosttoconnect = purple_account_get_string(account, "proxy", sip->servername);
11210
95ba2527d7d1 [gaim-migrate @ 13341]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11194
diff changeset
2067 }
11396
468e60b682cd [gaim-migrate @ 13627]
Daniel Atallah <datallah@pidgin.im>
parents: 11383
diff changeset
2068
37518
53c9ebedf2b7 Plug g_resolver_get_default() leaks
Mike Ruprecht <cmaiku@gmail.com>
parents: 37517
diff changeset
2069 resolver = g_resolver_get_default();
53c9ebedf2b7 Plug g_resolver_get_default() leaks
Mike Ruprecht <cmaiku@gmail.com>
parents: 37517
diff changeset
2070 g_resolver_lookup_service_async(resolver,
37458
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
2071 "sip",
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
2072 sip->udp ? "udp" : "tcp",
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
2073 hosttoconnect,
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
2074 sip->cancellable,
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
2075 srvresolved,
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
2076 sip);
37518
53c9ebedf2b7 Plug g_resolver_get_default() leaks
Mike Ruprecht <cmaiku@gmail.com>
parents: 37517
diff changeset
2077 g_object_unref(resolver);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
2078 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
2079
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
2080 static void simple_close(PurpleConnection *gc)
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
2081 {
32266
af94a3153685 Convert simple prpl to use accessor functions purple_connection_get_protocol_data() and purple_connection_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents: 32157
diff changeset
2082 struct simple_account_data *sip = purple_connection_get_protocol_data(gc);
11194
47dc0e9a757a [gaim-migrate @ 13317]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11192
diff changeset
2083
29989
18bc65ced65a Exit early if sip is null, instead of putting the whole body of this
Mark Doliner <markdoliner@pidgin.im>
parents: 29757
diff changeset
2084 if (!sip)
18bc65ced65a Exit early if sip is null, instead of putting the whole body of this
Mark Doliner <markdoliner@pidgin.im>
parents: 29757
diff changeset
2085 return;
18bc65ced65a Exit early if sip is null, instead of putting the whole body of this
Mark Doliner <markdoliner@pidgin.im>
parents: 29757
diff changeset
2086
18bc65ced65a Exit early if sip is null, instead of putting the whole body of this
Mark Doliner <markdoliner@pidgin.im>
parents: 29757
diff changeset
2087 /* unregister */
18bc65ced65a Exit early if sip is null, instead of putting the whole body of this
Mark Doliner <markdoliner@pidgin.im>
parents: 29757
diff changeset
2088 if (sip->registerstatus == SIMPLE_REGISTER_COMPLETE)
18bc65ced65a Exit early if sip is null, instead of putting the whole body of this
Mark Doliner <markdoliner@pidgin.im>
parents: 29757
diff changeset
2089 {
18bc65ced65a Exit early if sip is null, instead of putting the whole body of this
Mark Doliner <markdoliner@pidgin.im>
parents: 29757
diff changeset
2090 g_hash_table_foreach(sip->buddies,
18bc65ced65a Exit early if sip is null, instead of putting the whole body of this
Mark Doliner <markdoliner@pidgin.im>
parents: 29757
diff changeset
2091 (GHFunc)simple_unsubscribe,
18bc65ced65a Exit early if sip is null, instead of putting the whole body of this
Mark Doliner <markdoliner@pidgin.im>
parents: 29757
diff changeset
2092 (gpointer)sip);
18bc65ced65a Exit early if sip is null, instead of putting the whole body of this
Mark Doliner <markdoliner@pidgin.im>
parents: 29757
diff changeset
2093
18bc65ced65a Exit early if sip is null, instead of putting the whole body of this
Mark Doliner <markdoliner@pidgin.im>
parents: 29757
diff changeset
2094 if (purple_account_get_bool(sip->account, "dopublish", TRUE))
18bc65ced65a Exit early if sip is null, instead of putting the whole body of this
Mark Doliner <markdoliner@pidgin.im>
parents: 29757
diff changeset
2095 send_closed_publish(sip);
21417
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
2096
29989
18bc65ced65a Exit early if sip is null, instead of putting the whole body of this
Mark Doliner <markdoliner@pidgin.im>
parents: 29757
diff changeset
2097 do_register_exp(sip, 0);
18bc65ced65a Exit early if sip is null, instead of putting the whole body of this
Mark Doliner <markdoliner@pidgin.im>
parents: 29757
diff changeset
2098 }
18bc65ced65a Exit early if sip is null, instead of putting the whole body of this
Mark Doliner <markdoliner@pidgin.im>
parents: 29757
diff changeset
2099 connection_free_all(sip);
21417
48f4f6c2fe47 Patch from Will Hawkins to make the SIMPLE prpl more standards compliant by keeping all subscribe/notify messaging within a dialog. This didn't apply cleanly, so I had to manually apply it - hopefully I didn't break anything during the process. Fixes #3778.
Daniel Atallah <datallah@pidgin.im>
parents: 21106
diff changeset
2100
29996
bcc1ae2c2550 Two SIMPLE changes:
Mark Doliner <markdoliner@pidgin.im>
parents: 29989
diff changeset
2101 if (sip->listenpa)
bcc1ae2c2550 Two SIMPLE changes:
Mark Doliner <markdoliner@pidgin.im>
parents: 29989
diff changeset
2102 purple_input_remove(sip->listenpa);
bcc1ae2c2550 Two SIMPLE changes:
Mark Doliner <markdoliner@pidgin.im>
parents: 29989
diff changeset
2103 if (sip->tx_handler)
bcc1ae2c2550 Two SIMPLE changes:
Mark Doliner <markdoliner@pidgin.im>
parents: 29989
diff changeset
2104 purple_input_remove(sip->tx_handler);
bcc1ae2c2550 Two SIMPLE changes:
Mark Doliner <markdoliner@pidgin.im>
parents: 29989
diff changeset
2105 if (sip->resendtimeout)
38433
361c801c4536 Remove purple_timeout_* function usage
Mike Ruprecht <cmaiku@gmail.com>
parents: 38409
diff changeset
2106 g_source_remove(sip->resendtimeout);
29996
bcc1ae2c2550 Two SIMPLE changes:
Mark Doliner <markdoliner@pidgin.im>
parents: 29989
diff changeset
2107 if (sip->registertimeout)
38433
361c801c4536 Remove purple_timeout_* function usage
Mike Ruprecht <cmaiku@gmail.com>
parents: 38409
diff changeset
2108 g_source_remove(sip->registertimeout);
13399
e877a5672fe8 [gaim-migrate @ 15772]
Richard Laager <rlaager@pidgin.im>
parents: 13348
diff changeset
2109
37458
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
2110 g_cancellable_cancel(sip->cancellable);
2539f27ecd73 This should do it for simple
Gary Kramlich <grim@reaperworld.com>
parents: 37390
diff changeset
2111 g_object_unref(G_OBJECT(sip->cancellable));
14300
68a0aa63f3b8 [gaim-migrate @ 16920]
Mark Doliner <markdoliner@pidgin.im>
parents: 14254
diff changeset
2112
29989
18bc65ced65a Exit early if sip is null, instead of putting the whole body of this
Mark Doliner <markdoliner@pidgin.im>
parents: 29757
diff changeset
2113 if (sip->listen_data != NULL)
18bc65ced65a Exit early if sip is null, instead of putting the whole body of this
Mark Doliner <markdoliner@pidgin.im>
parents: 29757
diff changeset
2114 purple_network_listen_cancel(sip->listen_data);
14370
12ef3d4096ee [gaim-migrate @ 16998]
Mark Doliner <markdoliner@pidgin.im>
parents: 14329
diff changeset
2115
29996
bcc1ae2c2550 Two SIMPLE changes:
Mark Doliner <markdoliner@pidgin.im>
parents: 29989
diff changeset
2116 if (sip->fd >= 0)
bcc1ae2c2550 Two SIMPLE changes:
Mark Doliner <markdoliner@pidgin.im>
parents: 29989
diff changeset
2117 close(sip->fd);
bcc1ae2c2550 Two SIMPLE changes:
Mark Doliner <markdoliner@pidgin.im>
parents: 29989
diff changeset
2118 if (sip->listenfd >= 0)
bcc1ae2c2550 Two SIMPLE changes:
Mark Doliner <markdoliner@pidgin.im>
parents: 29989
diff changeset
2119 close(sip->listenfd);
bcc1ae2c2550 Two SIMPLE changes:
Mark Doliner <markdoliner@pidgin.im>
parents: 29989
diff changeset
2120
29989
18bc65ced65a Exit early if sip is null, instead of putting the whole body of this
Mark Doliner <markdoliner@pidgin.im>
parents: 29757
diff changeset
2121 g_free(sip->servername);
18bc65ced65a Exit early if sip is null, instead of putting the whole body of this
Mark Doliner <markdoliner@pidgin.im>
parents: 29757
diff changeset
2122 g_free(sip->username);
18bc65ced65a Exit early if sip is null, instead of putting the whole body of this
Mark Doliner <markdoliner@pidgin.im>
parents: 29757
diff changeset
2123 g_free(sip->password);
18bc65ced65a Exit early if sip is null, instead of putting the whole body of this
Mark Doliner <markdoliner@pidgin.im>
parents: 29757
diff changeset
2124 g_free(sip->registrar.nonce);
18bc65ced65a Exit early if sip is null, instead of putting the whole body of this
Mark Doliner <markdoliner@pidgin.im>
parents: 29757
diff changeset
2125 g_free(sip->registrar.opaque);
18bc65ced65a Exit early if sip is null, instead of putting the whole body of this
Mark Doliner <markdoliner@pidgin.im>
parents: 29757
diff changeset
2126 g_free(sip->registrar.target);
18bc65ced65a Exit early if sip is null, instead of putting the whole body of this
Mark Doliner <markdoliner@pidgin.im>
parents: 29757
diff changeset
2127 g_free(sip->registrar.realm);
18bc65ced65a Exit early if sip is null, instead of putting the whole body of this
Mark Doliner <markdoliner@pidgin.im>
parents: 29757
diff changeset
2128 g_free(sip->registrar.digest_session_key);
18bc65ced65a Exit early if sip is null, instead of putting the whole body of this
Mark Doliner <markdoliner@pidgin.im>
parents: 29757
diff changeset
2129 g_free(sip->proxy.nonce);
18bc65ced65a Exit early if sip is null, instead of putting the whole body of this
Mark Doliner <markdoliner@pidgin.im>
parents: 29757
diff changeset
2130 g_free(sip->proxy.opaque);
18bc65ced65a Exit early if sip is null, instead of putting the whole body of this
Mark Doliner <markdoliner@pidgin.im>
parents: 29757
diff changeset
2131 g_free(sip->proxy.target);
18bc65ced65a Exit early if sip is null, instead of putting the whole body of this
Mark Doliner <markdoliner@pidgin.im>
parents: 29757
diff changeset
2132 g_free(sip->proxy.realm);
18bc65ced65a Exit early if sip is null, instead of putting the whole body of this
Mark Doliner <markdoliner@pidgin.im>
parents: 29757
diff changeset
2133 g_free(sip->proxy.digest_session_key);
29997
9a9b586ac254 Lots of little memleak fixes
Mark Doliner <markdoliner@pidgin.im>
parents: 29996
diff changeset
2134 g_free(sip->status);
9a9b586ac254 Lots of little memleak fixes
Mark Doliner <markdoliner@pidgin.im>
parents: 29996
diff changeset
2135 g_hash_table_destroy(sip->buddies);
9a9b586ac254 Lots of little memleak fixes
Mark Doliner <markdoliner@pidgin.im>
parents: 29996
diff changeset
2136 g_free(sip->regcallid);
29998
fcacdafd0f2d Fix one more small memleak by freeing any lingering transactions at shutdown
Mark Doliner <markdoliner@pidgin.im>
parents: 29997
diff changeset
2137 while (sip->transactions)
fcacdafd0f2d Fix one more small memleak by freeing any lingering transactions at shutdown
Mark Doliner <markdoliner@pidgin.im>
parents: 29997
diff changeset
2138 transactions_remove(sip, sip->transactions->data);
29989
18bc65ced65a Exit early if sip is null, instead of putting the whole body of this
Mark Doliner <markdoliner@pidgin.im>
parents: 29757
diff changeset
2139 g_free(sip->publish_etag);
18bc65ced65a Exit early if sip is null, instead of putting the whole body of this
Mark Doliner <markdoliner@pidgin.im>
parents: 29757
diff changeset
2140 if (sip->txbuf)
34529
68cf25486001 GObjectify PurpleCircBuffer as PurpleCircularBuffer (from gobjectification branch)
Ankit Vani <a@nevitus.org>
parents: 34111
diff changeset
2141 g_object_unref(G_OBJECT(sip->txbuf));
29989
18bc65ced65a Exit early if sip is null, instead of putting the whole body of this
Mark Doliner <markdoliner@pidgin.im>
parents: 29757
diff changeset
2142 g_free(sip->realhostname);
14329
05c3cc0c1f79 [gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents: 14324
diff changeset
2143
29989
18bc65ced65a Exit early if sip is null, instead of putting the whole body of this
Mark Doliner <markdoliner@pidgin.im>
parents: 29757
diff changeset
2144 g_free(sip);
32266
af94a3153685 Convert simple prpl to use accessor functions purple_connection_get_protocol_data() and purple_connection_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents: 32157
diff changeset
2145 purple_connection_set_protocol_data(gc, NULL);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
2146 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
2147
36597
5392a32c7a4d Refactored simple to use the new protocol API
Ankit Vani <a@nevitus.org>
parents: 36583
diff changeset
2148 static void
39894
7eab91ea30a1 Replace Purple type macros by GObject macros.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39760
diff changeset
2149 simple_protocol_init(SIMPLEProtocol *self)
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
2150 {
39894
7eab91ea30a1 Replace Purple type macros by GObject macros.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39760
diff changeset
2151 PurpleProtocol *protocol = PURPLE_PROTOCOL(self);
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
2152 PurpleAccountUserSplit *split;
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
2153 PurpleAccountOption *option;
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
2154
37004
c8dce7bef0e6 Change protocol IDs to prpl-*
Ankit Vani <a@nevitus.org>
parents: 36985
diff changeset
2155 protocol->id = "prpl-simple";
36684
ecc74498e088 Refactored other protocols to use instance init
Ankit Vani <a@nevitus.org>
parents: 36678
diff changeset
2156 protocol->name = "SIMPLE";
36597
5392a32c7a4d Refactored simple to use the new protocol API
Ankit Vani <a@nevitus.org>
parents: 36583
diff changeset
2157
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
2158 split = purple_account_user_split_new(_("Server"), "", '@');
36684
ecc74498e088 Refactored other protocols to use instance init
Ankit Vani <a@nevitus.org>
parents: 36678
diff changeset
2159 protocol->user_splits = g_list_append(protocol->user_splits, split);
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
2160
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
2161 option = purple_account_option_bool_new(_("Publish status (note: everyone may watch you)"), "dopublish", TRUE);
37038
8832d14d7d0c Rename 'protocol_options' field of PurpleProtocol to more appropriate 'account_options'
Ankit Vani <a@nevitus.org>
parents: 37016
diff changeset
2162 protocol->account_options = g_list_append(protocol->account_options, option);
11345
48a2f93e47b6 [gaim-migrate @ 13562]
Thomas Butter <tbutter@users.sourceforge.net>
parents: 11341
diff changeset
2163
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
2164 option = purple_account_option_int_new(_("Connect port"), "port", 0);
37038
8832d14d7d0c Rename 'protocol_options' field of PurpleProtocol to more appropriate 'account_options'
Ankit Vani <a@nevitus.org>
parents: 37016
diff changeset
2165 protocol->account_options = g_list_append(protocol->account_options, option);
12730
f64fdbc34677 [gaim-migrate @ 15074]
Daniel Atallah <datallah@pidgin.im>
parents: 12689
diff changeset
2166
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
2167 option = purple_account_option_bool_new(_("Use UDP"), "udp", FALSE);
37038
8832d14d7d0c Rename 'protocol_options' field of PurpleProtocol to more appropriate 'account_options'
Ankit Vani <a@nevitus.org>
parents: 37016
diff changeset
2168 protocol->account_options = g_list_append(protocol->account_options, option);
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
2169 option = purple_account_option_bool_new(_("Use proxy"), "useproxy", FALSE);
37038
8832d14d7d0c Rename 'protocol_options' field of PurpleProtocol to more appropriate 'account_options'
Ankit Vani <a@nevitus.org>
parents: 37016
diff changeset
2170 protocol->account_options = g_list_append(protocol->account_options, option);
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
2171 option = purple_account_option_string_new(_("Proxy"), "proxy", "");
37038
8832d14d7d0c Rename 'protocol_options' field of PurpleProtocol to more appropriate 'account_options'
Ankit Vani <a@nevitus.org>
parents: 37016
diff changeset
2172 protocol->account_options = g_list_append(protocol->account_options, option);
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
2173 option = purple_account_option_string_new(_("Auth User"), "authuser", "");
37038
8832d14d7d0c Rename 'protocol_options' field of PurpleProtocol to more appropriate 'account_options'
Ankit Vani <a@nevitus.org>
parents: 37016
diff changeset
2174 protocol->account_options = g_list_append(protocol->account_options, option);
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
2175 option = purple_account_option_string_new(_("Auth Domain"), "authdomain", "");
37038
8832d14d7d0c Rename 'protocol_options' field of PurpleProtocol to more appropriate 'account_options'
Ankit Vani <a@nevitus.org>
parents: 37016
diff changeset
2176 protocol->account_options = g_list_append(protocol->account_options, option);
36684
ecc74498e088 Refactored other protocols to use instance init
Ankit Vani <a@nevitus.org>
parents: 36678
diff changeset
2177 }
ecc74498e088 Refactored other protocols to use instance init
Ankit Vani <a@nevitus.org>
parents: 36678
diff changeset
2178
ecc74498e088 Refactored other protocols to use instance init
Ankit Vani <a@nevitus.org>
parents: 36678
diff changeset
2179 static void
39894
7eab91ea30a1 Replace Purple type macros by GObject macros.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39760
diff changeset
2180 simple_protocol_class_init(SIMPLEProtocolClass *klass)
36684
ecc74498e088 Refactored other protocols to use instance init
Ankit Vani <a@nevitus.org>
parents: 36678
diff changeset
2181 {
39894
7eab91ea30a1 Replace Purple type macros by GObject macros.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39760
diff changeset
2182 PurpleProtocolClass *protocol_class = PURPLE_PROTOCOL_CLASS(klass);
7eab91ea30a1 Replace Purple type macros by GObject macros.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39760
diff changeset
2183
7eab91ea30a1 Replace Purple type macros by GObject macros.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39760
diff changeset
2184 protocol_class->login = simple_login;
7eab91ea30a1 Replace Purple type macros by GObject macros.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39760
diff changeset
2185 protocol_class->close = simple_close;
7eab91ea30a1 Replace Purple type macros by GObject macros.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39760
diff changeset
2186 protocol_class->status_types = simple_status_types;
7eab91ea30a1 Replace Purple type macros by GObject macros.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39760
diff changeset
2187 protocol_class->list_icon = simple_list_icon;
7eab91ea30a1 Replace Purple type macros by GObject macros.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39760
diff changeset
2188 }
7eab91ea30a1 Replace Purple type macros by GObject macros.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39760
diff changeset
2189
7eab91ea30a1 Replace Purple type macros by GObject macros.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39760
diff changeset
2190 static void
7eab91ea30a1 Replace Purple type macros by GObject macros.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39760
diff changeset
2191 simple_protocol_class_finalize(G_GNUC_UNUSED SIMPLEProtocolClass *klass)
7eab91ea30a1 Replace Purple type macros by GObject macros.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39760
diff changeset
2192 {
36597
5392a32c7a4d Refactored simple to use the new protocol API
Ankit Vani <a@nevitus.org>
parents: 36583
diff changeset
2193 }
5392a32c7a4d Refactored simple to use the new protocol API
Ankit Vani <a@nevitus.org>
parents: 36583
diff changeset
2194
5392a32c7a4d Refactored simple to use the new protocol API
Ankit Vani <a@nevitus.org>
parents: 36583
diff changeset
2195 static void
39757
4a5ba806d8c9 Rename *Iface to more standard names.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39330
diff changeset
2196 simple_protocol_server_iface_init(PurpleProtocolServerInterface *server_iface)
36597
5392a32c7a4d Refactored simple to use the new protocol API
Ankit Vani <a@nevitus.org>
parents: 36583
diff changeset
2197 {
36736
164cbd1113d4 Refactored sametime, silc, simple to use the new protocol interfaces
Ankit Vani <a@nevitus.org>
parents: 36729
diff changeset
2198 server_iface->set_status = simple_set_status;
164cbd1113d4 Refactored sametime, silc, simple to use the new protocol interfaces
Ankit Vani <a@nevitus.org>
parents: 36729
diff changeset
2199 server_iface->add_buddy = simple_add_buddy;
164cbd1113d4 Refactored sametime, silc, simple to use the new protocol interfaces
Ankit Vani <a@nevitus.org>
parents: 36729
diff changeset
2200 server_iface->remove_buddy = simple_remove_buddy;
164cbd1113d4 Refactored sametime, silc, simple to use the new protocol interfaces
Ankit Vani <a@nevitus.org>
parents: 36729
diff changeset
2201 server_iface->keepalive = simple_keep_alive;
164cbd1113d4 Refactored sametime, silc, simple to use the new protocol interfaces
Ankit Vani <a@nevitus.org>
parents: 36729
diff changeset
2202 server_iface->send_raw = simple_send_raw;
164cbd1113d4 Refactored sametime, silc, simple to use the new protocol interfaces
Ankit Vani <a@nevitus.org>
parents: 36729
diff changeset
2203 }
164cbd1113d4 Refactored sametime, silc, simple to use the new protocol interfaces
Ankit Vani <a@nevitus.org>
parents: 36729
diff changeset
2204
164cbd1113d4 Refactored sametime, silc, simple to use the new protocol interfaces
Ankit Vani <a@nevitus.org>
parents: 36729
diff changeset
2205 static void
39757
4a5ba806d8c9 Rename *Iface to more standard names.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39330
diff changeset
2206 simple_protocol_im_iface_init(PurpleProtocolIMInterface *im_iface)
36736
164cbd1113d4 Refactored sametime, silc, simple to use the new protocol interfaces
Ankit Vani <a@nevitus.org>
parents: 36729
diff changeset
2207 {
164cbd1113d4 Refactored sametime, silc, simple to use the new protocol interfaces
Ankit Vani <a@nevitus.org>
parents: 36729
diff changeset
2208 im_iface->send = simple_im_send;
164cbd1113d4 Refactored sametime, silc, simple to use the new protocol interfaces
Ankit Vani <a@nevitus.org>
parents: 36729
diff changeset
2209 im_iface->send_typing = simple_typing;
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
2210 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
2211
39894
7eab91ea30a1 Replace Purple type macros by GObject macros.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39760
diff changeset
2212 G_DEFINE_DYNAMIC_TYPE_EXTENDED(
7eab91ea30a1 Replace Purple type macros by GObject macros.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39760
diff changeset
2213 SIMPLEProtocol, simple_protocol, PURPLE_TYPE_PROTOCOL, 0,
36736
164cbd1113d4 Refactored sametime, silc, simple to use the new protocol interfaces
Ankit Vani <a@nevitus.org>
parents: 36729
diff changeset
2214
39894
7eab91ea30a1 Replace Purple type macros by GObject macros.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39760
diff changeset
2215 G_IMPLEMENT_INTERFACE_DYNAMIC(PURPLE_TYPE_PROTOCOL_SERVER,
7eab91ea30a1 Replace Purple type macros by GObject macros.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39760
diff changeset
2216 simple_protocol_server_iface_init)
36736
164cbd1113d4 Refactored sametime, silc, simple to use the new protocol interfaces
Ankit Vani <a@nevitus.org>
parents: 36729
diff changeset
2217
39894
7eab91ea30a1 Replace Purple type macros by GObject macros.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39760
diff changeset
2218 G_IMPLEMENT_INTERFACE_DYNAMIC(PURPLE_TYPE_PROTOCOL_IM,
7eab91ea30a1 Replace Purple type macros by GObject macros.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39760
diff changeset
2219 simple_protocol_im_iface_init));
36714
ec178f7d66da Refactored protocols to use the new type definition macros
Ankit Vani <a@nevitus.org>
parents: 36692
diff changeset
2220
36532
eaa5f2f9c1d5 Refactored simple to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
2221 static PurplePluginInfo *
eaa5f2f9c1d5 Refactored simple to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
2222 plugin_query(GError **error)
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
2223 {
36642
b8ba53daa445 Updated libpurple to use current GPlugin
Ankit Vani <a@nevitus.org>
parents: 36638
diff changeset
2224 const gchar * const authors[] = {
b8ba53daa445 Updated libpurple to use current GPlugin
Ankit Vani <a@nevitus.org>
parents: 36638
diff changeset
2225 "Thomas Butter <butter@uni-mannheim.de>",
b8ba53daa445 Updated libpurple to use current GPlugin
Ankit Vani <a@nevitus.org>
parents: 36638
diff changeset
2226 NULL
b8ba53daa445 Updated libpurple to use current GPlugin
Ankit Vani <a@nevitus.org>
parents: 36638
diff changeset
2227 };
b8ba53daa445 Updated libpurple to use current GPlugin
Ankit Vani <a@nevitus.org>
parents: 36638
diff changeset
2228
36532
eaa5f2f9c1d5 Refactored simple to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
2229 return purple_plugin_info_new(
36985
9faafe43603e Rename protocol plugin IDs to prpl-*
Ankit Vani <a@nevitus.org>
parents: 36862
diff changeset
2230 "id", "prpl-simple",
36638
5f6dcd83e8c1 Seperate plugin and protocol IDs. Protocol ID example: "msn". Plugin ID example: "protocol-msn".
Ankit Vani <a@nevitus.org>
parents: 36628
diff changeset
2231 "name", "SIMPLE Protocol",
36532
eaa5f2f9c1d5 Refactored simple to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
2232 "version", DISPLAY_VERSION,
eaa5f2f9c1d5 Refactored simple to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
2233 "category", N_("Protocol"),
eaa5f2f9c1d5 Refactored simple to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
2234 "summary", N_("SIP/SIMPLE Protocol Plugin"),
eaa5f2f9c1d5 Refactored simple to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
2235 "description", N_("The SIP/SIMPLE Protocol Plugin"),
36642
b8ba53daa445 Updated libpurple to use current GPlugin
Ankit Vani <a@nevitus.org>
parents: 36638
diff changeset
2236 "authors", authors,
36532
eaa5f2f9c1d5 Refactored simple to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
2237 "website", PURPLE_WEBSITE,
eaa5f2f9c1d5 Refactored simple to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
2238 "abi-version", PURPLE_ABI_VERSION,
36653
4084c34c051d Override gplugin info's "flags" property. Added PURPLE_PLUGIN_INFO_FLAGS_INTERNAL and PURPLE_PLUGIN_INFO_FLAGS_AUTO_LOAD.
Ankit Vani <a@nevitus.org>
parents: 36642
diff changeset
2239 "flags", PURPLE_PLUGIN_INFO_FLAGS_INTERNAL |
4084c34c051d Override gplugin info's "flags" property. Added PURPLE_PLUGIN_INFO_FLAGS_INTERNAL and PURPLE_PLUGIN_INFO_FLAGS_AUTO_LOAD.
Ankit Vani <a@nevitus.org>
parents: 36642
diff changeset
2240 PURPLE_PLUGIN_INFO_FLAGS_AUTO_LOAD,
36532
eaa5f2f9c1d5 Refactored simple to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
2241 NULL
eaa5f2f9c1d5 Refactored simple to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
2242 );
eaa5f2f9c1d5 Refactored simple to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
2243 }
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
2244
36597
5392a32c7a4d Refactored simple to use the new protocol API
Ankit Vani <a@nevitus.org>
parents: 36583
diff changeset
2245 static gboolean
5392a32c7a4d Refactored simple to use the new protocol API
Ankit Vani <a@nevitus.org>
parents: 36583
diff changeset
2246 plugin_load(PurplePlugin *plugin, GError **error)
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
2247 {
39894
7eab91ea30a1 Replace Purple type macros by GObject macros.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39760
diff changeset
2248 simple_protocol_register_type(G_TYPE_MODULE(plugin));
36714
ec178f7d66da Refactored protocols to use the new type definition macros
Ankit Vani <a@nevitus.org>
parents: 36692
diff changeset
2249
36628
3d43ca8d69ee Refactored the protocols to use the error argument of purple_protocols_{add/remove}
Ankit Vani <a@nevitus.org>
parents: 36613
diff changeset
2250 my_protocol = purple_protocols_add(SIMPLE_TYPE_PROTOCOL, error);
3d43ca8d69ee Refactored the protocols to use the error argument of purple_protocols_{add/remove}
Ankit Vani <a@nevitus.org>
parents: 36613
diff changeset
2251 if (!my_protocol)
36597
5392a32c7a4d Refactored simple to use the new protocol API
Ankit Vani <a@nevitus.org>
parents: 36583
diff changeset
2252 return FALSE;
12730
f64fdbc34677 [gaim-migrate @ 15074]
Daniel Atallah <datallah@pidgin.im>
parents: 12689
diff changeset
2253
39330
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
2254 purple_signal_connect(purple_get_core(), "uri-handler", plugin,
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
2255 PURPLE_CALLBACK(simple_uri_handler), NULL);
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
2256
36532
eaa5f2f9c1d5 Refactored simple to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
2257 return TRUE;
11181
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
2258 }
e872a55b9524 [gaim-migrate @ 13292]
Thomas Butter <tbutter@users.sourceforge.net>
parents:
diff changeset
2259
36597
5392a32c7a4d Refactored simple to use the new protocol API
Ankit Vani <a@nevitus.org>
parents: 36583
diff changeset
2260 static gboolean
5392a32c7a4d Refactored simple to use the new protocol API
Ankit Vani <a@nevitus.org>
parents: 36583
diff changeset
2261 plugin_unload(PurplePlugin *plugin, GError **error)
36532
eaa5f2f9c1d5 Refactored simple to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
2262 {
39330
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
2263 purple_signal_disconnect(purple_get_core(), "uri-handler", plugin,
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
2264 PURPLE_CALLBACK(simple_uri_handler));
650003822919 simple: Implement SIP/SIMPLE URI handler
Mike Ruprecht <cmaiku@gmail.com>
parents: 38433
diff changeset
2265
36628
3d43ca8d69ee Refactored the protocols to use the error argument of purple_protocols_{add/remove}
Ankit Vani <a@nevitus.org>
parents: 36613
diff changeset
2266 if (!purple_protocols_remove(my_protocol, error))
36597
5392a32c7a4d Refactored simple to use the new protocol API
Ankit Vani <a@nevitus.org>
parents: 36583
diff changeset
2267 return FALSE;
5392a32c7a4d Refactored simple to use the new protocol API
Ankit Vani <a@nevitus.org>
parents: 36583
diff changeset
2268
36532
eaa5f2f9c1d5 Refactored simple to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
2269 return TRUE;
eaa5f2f9c1d5 Refactored simple to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
2270 }
eaa5f2f9c1d5 Refactored simple to use the new plugin API
Ankit Vani <a@nevitus.org>
parents: 36367
diff changeset
2271
36714
ec178f7d66da Refactored protocols to use the new type definition macros
Ankit Vani <a@nevitus.org>
parents: 36692
diff changeset
2272 PURPLE_PLUGIN_INIT(simple, plugin_query, plugin_load, plugin_unload);

mercurial