annotate src/protocols/simple/simple.c @ 14118:87ff682bdf5f

[gaim-migrate @ 16752] I don't feel like fixing simple right now, so I'm adding some GAIM_CONNECTION_IS_VALID's to tide us over committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Mon, 14 Aug 2006 08:23:26 +0000
parents 7a205b430d19
children 8856312371cb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1 /**
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
2 * @file simple.c
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
3 *
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
4 * gaim
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
5 *
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
6 * Copyright (C) 2005 Thomas Butter <butter@uni-mannheim.de>
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
7 *
11345
03d9507f05a9 [gaim-migrate @ 13562]
Thomas Butter <tbutter>
parents: 11341
diff changeset
8 * ***
03d9507f05a9 [gaim-migrate @ 13562]
Thomas Butter <tbutter>
parents: 11341
diff changeset
9 * Thanks to Google's Summer of Code Program and the helpful mentors
03d9507f05a9 [gaim-migrate @ 13562]
Thomas Butter <tbutter>
parents: 11341
diff changeset
10 * ***
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
11 *
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
12 * This program is free software; you can redistribute it and/or modify
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
13 * it under the terms of the GNU General Public License as published by
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
14 * the Free Software Foundation; either version 2 of the License, or
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
15 * (at your option) any later version.
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
16 *
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
17 * This program is distributed in the hope that it will be useful,
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
20 * GNU General Public License for more details.
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
21 *
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
22 * You should have received a copy of the GNU General Public License
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
23 * along with this program; if not, write to the Free Software
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
25 */
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
26
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
27 #include "internal.h"
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
28
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
29 #include "accountopt.h"
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
30 #include "blist.h"
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
31 #include "conversation.h"
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
32 #include "debug.h"
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
33 #include "notify.h"
11345
03d9507f05a9 [gaim-migrate @ 13562]
Thomas Butter <tbutter>
parents: 11341
diff changeset
34 #include "privacy.h"
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
35 #include "prpl.h"
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
36 #include "plugin.h"
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
37 #include "util.h"
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
38 #include "version.h"
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
39 #include "network.h"
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
40 #include "xmlnode.h"
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
41
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
42 #include "simple.h"
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
43 #include "sipmsg.h"
11383
b4cf724b64f8 [gaim-migrate @ 13610]
Thomas Butter <tbutter>
parents: 11346
diff changeset
44 #include "dnssrv.h"
11409
1e495a5fcbbc [gaim-migrate @ 13646]
Thomas Butter <tbutter>
parents: 11396
diff changeset
45 #include "ntlm.h"
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
46
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
47 static char *gentag() {
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
48 return g_strdup_printf("%04d%04d", rand() & 0xFFFF, rand() & 0xFFFF);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
49 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
50
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
51 static char *genbranch() {
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
52 return g_strdup_printf("z9hG4bK%04X%04X%04X%04X%04X",
12767
53218d758ba9 [gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12760
diff changeset
53 rand() & 0xFFFF, rand() & 0xFFFF, rand() & 0xFFFF,
53218d758ba9 [gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12760
diff changeset
54 rand() & 0xFFFF, rand() & 0xFFFF);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
55 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
56
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
57 static char *gencallid() {
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
58 return g_strdup_printf("%04Xg%04Xa%04Xi%04Xm%04Xt%04Xb%04Xx%04Xx",
12767
53218d758ba9 [gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12760
diff changeset
59 rand() & 0xFFFF, rand() & 0xFFFF, rand() & 0xFFFF,
53218d758ba9 [gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12760
diff changeset
60 rand() & 0xFFFF, rand() & 0xFFFF, rand() & 0xFFFF,
53218d758ba9 [gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12760
diff changeset
61 rand() & 0xFFFF, rand() & 0xFFFF);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
62 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
63
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
64 static const char *simple_list_icon(GaimAccount *a, GaimBuddy *b) {
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
65 return "simple";
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
66 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
67
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
68 static void simple_keep_alive(GaimConnection *gc) {
11194
4c1f45ac00e9 [gaim-migrate @ 13317]
Thomas Butter <tbutter>
parents: 11192
diff changeset
69 struct simple_account_data *sip = gc->proto_data;
11341
3f0fda678686 [gaim-migrate @ 13555]
Thomas Butter <tbutter>
parents: 11327
diff changeset
70 if(sip->udp) { /* in case of UDP send a packet only with a 0 byte to
3f0fda678686 [gaim-migrate @ 13555]
Thomas Butter <tbutter>
parents: 11327
diff changeset
71 remain in the NAT table */
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
72 gchar buf[2] = {0, 0};
11194
4c1f45ac00e9 [gaim-migrate @ 13317]
Thomas Butter <tbutter>
parents: 11192
diff changeset
73 gaim_debug_info("simple", "sending keep alive\n");
4c1f45ac00e9 [gaim-migrate @ 13317]
Thomas Butter <tbutter>
parents: 11192
diff changeset
74 sendto(sip->fd, buf, 1, 0, (struct sockaddr*)&sip->serveraddr, sizeof(struct sockaddr_in));
4c1f45ac00e9 [gaim-migrate @ 13317]
Thomas Butter <tbutter>
parents: 11192
diff changeset
75 }
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
76 return;
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
77 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
78
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
79 static gboolean process_register_response(struct simple_account_data *sip, struct sipmsg *msg, struct transaction *tc);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
80 static void send_notify(struct simple_account_data *sip, struct simple_watcher *);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
81
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
82 static void send_publish(struct simple_account_data *sip);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
83
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
84 static void do_notifies(struct simple_account_data *sip) {
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
85 GSList *tmp = sip->watcher;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
86 gaim_debug_info("simple", "do_notifies()\n");
11345
03d9507f05a9 [gaim-migrate @ 13562]
Thomas Butter <tbutter>
parents: 11341
diff changeset
87 if((sip->republish != -1) || sip->republish < time(NULL)) {
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
88 if(gaim_account_get_bool(sip->account, "dopublish", TRUE)) {
11345
03d9507f05a9 [gaim-migrate @ 13562]
Thomas Butter <tbutter>
parents: 11341
diff changeset
89 send_publish(sip);
03d9507f05a9 [gaim-migrate @ 13562]
Thomas Butter <tbutter>
parents: 11341
diff changeset
90 }
03d9507f05a9 [gaim-migrate @ 13562]
Thomas Butter <tbutter>
parents: 11341
diff changeset
91 }
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
92
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
93 while(tmp) {
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
94 gaim_debug_info("simple", "notifying %s\n", ((struct simple_watcher*)tmp->data)->name);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
95 send_notify(sip, tmp->data);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
96 tmp = tmp->next;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
97 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
98 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
99
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
100 static void simple_set_status(GaimAccount *account, GaimStatus *status) {
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
101 GaimStatusPrimitive primitive = gaim_status_type_get_primitive(gaim_status_get_type(status));
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
102 struct simple_account_data *sip = NULL;
11718
11e95968c9ff [gaim-migrate @ 14009]
Mark Doliner <mark@kingant.net>
parents: 11658
diff changeset
103
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
104 if (!gaim_status_is_active(status))
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
105 return;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
106
11718
11e95968c9ff [gaim-migrate @ 14009]
Mark Doliner <mark@kingant.net>
parents: 11658
diff changeset
107 if (account->gc)
11e95968c9ff [gaim-migrate @ 14009]
Mark Doliner <mark@kingant.net>
parents: 11658
diff changeset
108 sip = account->gc->proto_data;
11e95968c9ff [gaim-migrate @ 14009]
Mark Doliner <mark@kingant.net>
parents: 11658
diff changeset
109
11e95968c9ff [gaim-migrate @ 14009]
Mark Doliner <mark@kingant.net>
parents: 11658
diff changeset
110 if (sip)
11e95968c9ff [gaim-migrate @ 14009]
Mark Doliner <mark@kingant.net>
parents: 11658
diff changeset
111 {
11650
1f95b6308195 [gaim-migrate @ 13931]
Mark Doliner <mark@kingant.net>
parents: 11522
diff changeset
112 g_free(sip->status);
11718
11e95968c9ff [gaim-migrate @ 14009]
Mark Doliner <mark@kingant.net>
parents: 11658
diff changeset
113 if (primitive == GAIM_STATUS_AVAILABLE)
11e95968c9ff [gaim-migrate @ 14009]
Mark Doliner <mark@kingant.net>
parents: 11658
diff changeset
114 sip->status = g_strdup("available");
11e95968c9ff [gaim-migrate @ 14009]
Mark Doliner <mark@kingant.net>
parents: 11658
diff changeset
115 else
11e95968c9ff [gaim-migrate @ 14009]
Mark Doliner <mark@kingant.net>
parents: 11658
diff changeset
116 sip->status = g_strdup("busy");
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
117
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
118 do_notifies(sip);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
119 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
120 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
121
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
122 static struct sip_connection *connection_find(struct simple_account_data *sip, int fd) {
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
123 struct sip_connection *ret = NULL;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
124 GSList *entry = sip->openconns;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
125 while(entry) {
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
126 ret = entry->data;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
127 if(ret->fd == fd) return ret;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
128 entry = entry->next;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
129 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
130 return NULL;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
131 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
132
14069
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
133 static struct simple_watcher *watcher_find(struct simple_account_data *sip,
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
134 const gchar *name) {
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
135 struct simple_watcher *watcher;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
136 GSList *entry = sip->watcher;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
137 while(entry) {
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
138 watcher = entry->data;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
139 if(!strcmp(name, watcher->name)) return watcher;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
140 entry = entry->next;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
141 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
142 return NULL;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
143 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
144
14069
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
145 static struct simple_watcher *watcher_create(struct simple_account_data *sip,
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
146 const gchar *name, const gchar *callid, const gchar *ourtag,
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
147 const gchar *theirtag, gboolean needsxpidf) {
13092
edef744647ff [gaim-migrate @ 15454]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13088
diff changeset
148 struct simple_watcher *watcher = g_new0(struct simple_watcher, 1);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
149 watcher->name = g_strdup(name);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
150 watcher->dialog.callid = g_strdup(callid);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
151 watcher->dialog.ourtag = g_strdup(ourtag);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
152 watcher->dialog.theirtag = g_strdup(theirtag);
13177
891be2f09b5c [gaim-migrate @ 15540]
Thomas Butter <tbutter>
parents: 13129
diff changeset
153 watcher->needsxpidf = needsxpidf;
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
154 sip->watcher = g_slist_append(sip->watcher, watcher);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
155 return watcher;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
156 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
157
14069
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
158 static void watcher_remove(struct simple_account_data *sip, const gchar *name) {
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
159 struct simple_watcher *watcher = watcher_find(sip, name);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
160 sip->watcher = g_slist_remove(sip->watcher, watcher);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
161 g_free(watcher->name);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
162 g_free(watcher->dialog.callid);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
163 g_free(watcher->dialog.ourtag);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
164 g_free(watcher->dialog.theirtag);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
165 g_free(watcher);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
166 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
167
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
168 static struct sip_connection *connection_create(struct simple_account_data *sip, int fd) {
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
169 struct sip_connection *ret = g_new0(struct sip_connection, 1);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
170 ret->fd = fd;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
171 sip->openconns = g_slist_append(sip->openconns, ret);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
172 return ret;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
173 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
174
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
175 static void connection_remove(struct simple_account_data *sip, int fd) {
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
176 struct sip_connection *conn = connection_find(sip, fd);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
177 sip->openconns = g_slist_remove(sip->openconns, conn);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
178 if(conn->inputhandler) gaim_input_remove(conn->inputhandler);
11650
1f95b6308195 [gaim-migrate @ 13931]
Mark Doliner <mark@kingant.net>
parents: 11522
diff changeset
179 g_free(conn->inbuf);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
180 g_free(conn);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
181 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
182
11346
e40318d2bcd8 [gaim-migrate @ 13563]
Thomas Butter <tbutter>
parents: 11345
diff changeset
183 static void connection_free_all(struct simple_account_data *sip) {
e40318d2bcd8 [gaim-migrate @ 13563]
Thomas Butter <tbutter>
parents: 11345
diff changeset
184 struct sip_connection *ret = NULL;
e40318d2bcd8 [gaim-migrate @ 13563]
Thomas Butter <tbutter>
parents: 11345
diff changeset
185 GSList *entry = sip->openconns;
e40318d2bcd8 [gaim-migrate @ 13563]
Thomas Butter <tbutter>
parents: 11345
diff changeset
186 while(entry) {
e40318d2bcd8 [gaim-migrate @ 13563]
Thomas Butter <tbutter>
parents: 11345
diff changeset
187 ret = entry->data;
e40318d2bcd8 [gaim-migrate @ 13563]
Thomas Butter <tbutter>
parents: 11345
diff changeset
188 connection_remove(sip, ret->fd);
e40318d2bcd8 [gaim-migrate @ 13563]
Thomas Butter <tbutter>
parents: 11345
diff changeset
189 entry = sip->openconns;
e40318d2bcd8 [gaim-migrate @ 13563]
Thomas Butter <tbutter>
parents: 11345
diff changeset
190 }
e40318d2bcd8 [gaim-migrate @ 13563]
Thomas Butter <tbutter>
parents: 11345
diff changeset
191 }
e40318d2bcd8 [gaim-migrate @ 13563]
Thomas Butter <tbutter>
parents: 11345
diff changeset
192
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
193 static void simple_add_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group)
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
194 {
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
195 struct simple_account_data *sip = (struct simple_account_data *)gc->proto_data;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
196 struct simple_buddy *b;
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
197 if(strncmp("sip:", buddy->name, 4)) {
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
198 gchar *buf = g_strdup_printf("sip:%s", buddy->name);
12755
505bc707b641 [gaim-migrate @ 15102]
Thomas Butter <tbutter>
parents: 12754
diff changeset
199 gaim_blist_rename_buddy(buddy, buf);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
200 g_free(buf);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
201 }
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
202 if(!g_hash_table_lookup(sip->buddies, buddy->name)) {
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
203 b = g_new0(struct simple_buddy, 1);
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
204 gaim_debug_info("simple", "simple_add_buddy %s\n", buddy->name);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
205 b->name = g_strdup(buddy->name);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
206 g_hash_table_insert(sip->buddies, b->name, b);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
207 } else {
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
208 gaim_debug_info("simple", "buddy %s already in internal list\n", buddy->name);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
209 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
210 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
211
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
212 static void simple_get_buddies(GaimConnection *gc) {
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
213 GaimBlistNode *gnode, *cnode, *bnode;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
214
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
215 gaim_debug_info("simple", "simple_get_buddies\n");
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
216
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
217 for(gnode = gaim_get_blist()->root; gnode; gnode = gnode->next) {
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
218 if(!GAIM_BLIST_NODE_IS_GROUP(gnode)) continue;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
219 for(cnode = gnode->child; cnode; cnode = cnode->next) {
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
220 if(!GAIM_BLIST_NODE_IS_CONTACT(cnode)) continue;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
221 for(bnode = cnode->child; bnode; bnode = bnode->next) {
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
222 if(!GAIM_BLIST_NODE_IS_BUDDY(bnode)) continue;
11192
fd6232f9a418 [gaim-migrate @ 13310]
Thomas Butter <tbutter>
parents: 11191
diff changeset
223 if(((GaimBuddy*)bnode)->account == gc->account)
fd6232f9a418 [gaim-migrate @ 13310]
Thomas Butter <tbutter>
parents: 11191
diff changeset
224 simple_add_buddy(gc, (GaimBuddy*)bnode, (GaimGroup *)gnode);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
225 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
226 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
227 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
228 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
229
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
230 static void simple_remove_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group)
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
231 {
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
232 struct simple_account_data *sip = (struct simple_account_data *)gc->proto_data;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
233 struct simple_buddy *b = g_hash_table_lookup(sip->buddies, buddy->name);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
234 g_hash_table_remove(sip->buddies, buddy->name);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
235 g_free(b->name);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
236 g_free(b);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
237 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
238
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
239 static GList *simple_status_types(GaimAccount *acc) {
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
240 GaimStatusType *type;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
241 GList *types = NULL;
12456
ca4021fe9a1c [gaim-migrate @ 14765]
Mark Doliner <mark@kingant.net>
parents: 12389
diff changeset
242
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
243 type = gaim_status_type_new_with_attrs(
12595
3169cd6727ad [gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents: 12571
diff changeset
244 GAIM_STATUS_AVAILABLE, NULL, NULL, TRUE, TRUE, FALSE,
3169cd6727ad [gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents: 12571
diff changeset
245 "message", _("Message"), gaim_value_new(GAIM_TYPE_STRING),
3169cd6727ad [gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents: 12571
diff changeset
246 NULL);
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
247 types = g_list_append(types, type);
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
248
12657
7b816173e2c6 [gaim-migrate @ 15000]
Mark Doliner <mark@kingant.net>
parents: 12645
diff changeset
249 type = gaim_status_type_new_full(
7b816173e2c6 [gaim-migrate @ 15000]
Mark Doliner <mark@kingant.net>
parents: 12645
diff changeset
250 GAIM_STATUS_OFFLINE, NULL, NULL, TRUE, TRUE, FALSE);
7b816173e2c6 [gaim-migrate @ 15000]
Mark Doliner <mark@kingant.net>
parents: 12645
diff changeset
251 types = g_list_append(types, type);
7b816173e2c6 [gaim-migrate @ 15000]
Mark Doliner <mark@kingant.net>
parents: 12645
diff changeset
252
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
253 return types;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
254 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
255
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
256 static gchar *auth_header(struct simple_account_data *sip,
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
257 struct sip_auth *auth, const gchar *method, const gchar *target) {
11346
e40318d2bcd8 [gaim-migrate @ 13563]
Thomas Butter <tbutter>
parents: 11345
diff changeset
258 gchar noncecount[9];
12382
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 12216
diff changeset
259 gchar *response;
11346
e40318d2bcd8 [gaim-migrate @ 13563]
Thomas Butter <tbutter>
parents: 11345
diff changeset
260 gchar *ret;
11409
1e495a5fcbbc [gaim-migrate @ 13646]
Thomas Butter <tbutter>
parents: 11396
diff changeset
261 gchar *tmp;
13088
a91a8a28f61f [gaim-migrate @ 15450]
Mark Doliner <mark@kingant.net>
parents: 13085
diff changeset
262 const char *authdomain;
a91a8a28f61f [gaim-migrate @ 15450]
Mark Doliner <mark@kingant.net>
parents: 13085
diff changeset
263 const char *authuser;
a91a8a28f61f [gaim-migrate @ 15450]
Mark Doliner <mark@kingant.net>
parents: 13085
diff changeset
264
a91a8a28f61f [gaim-migrate @ 15450]
Mark Doliner <mark@kingant.net>
parents: 13085
diff changeset
265 authdomain = gaim_account_get_string(sip->account, "authdomain", "");
a91a8a28f61f [gaim-migrate @ 15450]
Mark Doliner <mark@kingant.net>
parents: 13085
diff changeset
266 authuser = gaim_account_get_string(sip->account, "authuser", sip->username);
a91a8a28f61f [gaim-migrate @ 15450]
Mark Doliner <mark@kingant.net>
parents: 13085
diff changeset
267
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
268 if(!authuser || strlen(authuser) < 1) {
13084
31a3a9af1494 [gaim-migrate @ 15446]
Thomas Butter <tbutter>
parents: 13083
diff changeset
269 authuser = sip->username;
31a3a9af1494 [gaim-migrate @ 15446]
Thomas Butter <tbutter>
parents: 13083
diff changeset
270 }
11409
1e495a5fcbbc [gaim-migrate @ 13646]
Thomas Butter <tbutter>
parents: 11396
diff changeset
271
1e495a5fcbbc [gaim-migrate @ 13646]
Thomas Butter <tbutter>
parents: 11396
diff changeset
272 if(auth->type == 1) { /* Digest */
1e495a5fcbbc [gaim-migrate @ 13646]
Thomas Butter <tbutter>
parents: 11396
diff changeset
273 sprintf(noncecount, "%08d", auth->nc++);
12382
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 12216
diff changeset
274 response = gaim_cipher_http_digest_calculate_response(
12389
e024601d45c7 [gaim-migrate @ 14695]
Richard Laager <rlaager@wiktel.com>
parents: 12382
diff changeset
275 "md5", method, target, NULL, NULL,
12382
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 12216
diff changeset
276 auth->nonce, noncecount, NULL, auth->digest_session_key);
11409
1e495a5fcbbc [gaim-migrate @ 13646]
Thomas Butter <tbutter>
parents: 11396
diff changeset
277 gaim_debug(GAIM_DEBUG_MISC, "simple", "response %s\n", response);
12382
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 12216
diff changeset
278
13084
31a3a9af1494 [gaim-migrate @ 15446]
Thomas Butter <tbutter>
parents: 13083
diff changeset
279 ret = g_strdup_printf("Digest username=\"%s\", realm=\"%s\", nonce=\"%s\", uri=\"%s\", nc=\"%s\", response=\"%s\"\r\n", authuser, auth->realm, auth->nonce, target, noncecount, response);
12382
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 12216
diff changeset
280 g_free(response);
11409
1e495a5fcbbc [gaim-migrate @ 13646]
Thomas Butter <tbutter>
parents: 11396
diff changeset
281 return ret;
1e495a5fcbbc [gaim-migrate @ 13646]
Thomas Butter <tbutter>
parents: 11396
diff changeset
282 } else if(auth->type == 2) { /* NTLM */
13084
31a3a9af1494 [gaim-migrate @ 15446]
Thomas Butter <tbutter>
parents: 13083
diff changeset
283 if(auth->nc == 3 && auth->nonce) {
13698
6bee2e80e42c [gaim-migrate @ 16101]
Mark Doliner <mark@kingant.net>
parents: 13678
diff changeset
284 /* TODO: Don't hardcode "gaim" as the hostname */
6bee2e80e42c [gaim-migrate @ 16101]
Mark Doliner <mark@kingant.net>
parents: 13678
diff changeset
285 ret = gaim_ntlm_gen_type3(authuser, sip->password, "gaim", authdomain, (const guint8 *)auth->nonce, &auth->flags);
13084
31a3a9af1494 [gaim-migrate @ 15446]
Thomas Butter <tbutter>
parents: 13083
diff changeset
286 tmp = g_strdup_printf("NTLM qop=\"auth\", opaque=\"%s\", realm=\"%s\", targetname=\"%s\", gssapi-data=\"%s\"\r\n", auth->opaque, auth->realm, auth->target, ret);
11409
1e495a5fcbbc [gaim-migrate @ 13646]
Thomas Butter <tbutter>
parents: 11396
diff changeset
287 g_free(ret);
1e495a5fcbbc [gaim-migrate @ 13646]
Thomas Butter <tbutter>
parents: 11396
diff changeset
288 return tmp;
1e495a5fcbbc [gaim-migrate @ 13646]
Thomas Butter <tbutter>
parents: 11396
diff changeset
289 }
13084
31a3a9af1494 [gaim-migrate @ 15446]
Thomas Butter <tbutter>
parents: 13083
diff changeset
290 tmp = g_strdup_printf("NTLM qop=\"auth\", realm=\"%s\", targetname=\"%s\", gssapi-data=\"\"\r\n", auth->realm, auth->target);
11409
1e495a5fcbbc [gaim-migrate @ 13646]
Thomas Butter <tbutter>
parents: 11396
diff changeset
291 return tmp;
1e495a5fcbbc [gaim-migrate @ 13646]
Thomas Butter <tbutter>
parents: 11396
diff changeset
292 }
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
293
11346
e40318d2bcd8 [gaim-migrate @ 13563]
Thomas Butter <tbutter>
parents: 11345
diff changeset
294 sprintf(noncecount, "%08d", auth->nc++);
12382
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 12216
diff changeset
295 response = gaim_cipher_http_digest_calculate_response(
12389
e024601d45c7 [gaim-migrate @ 14695]
Richard Laager <rlaager@wiktel.com>
parents: 12382
diff changeset
296 "md5", method, target, NULL, NULL,
12382
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 12216
diff changeset
297 auth->nonce, noncecount, NULL, auth->digest_session_key);
11346
e40318d2bcd8 [gaim-migrate @ 13563]
Thomas Butter <tbutter>
parents: 11345
diff changeset
298 gaim_debug(GAIM_DEBUG_MISC, "simple", "response %s\n", response);
12382
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 12216
diff changeset
299
13084
31a3a9af1494 [gaim-migrate @ 15446]
Thomas Butter <tbutter>
parents: 13083
diff changeset
300 ret = g_strdup_printf("Digest username=\"%s\", realm=\"%s\", nonce=\"%s\", uri=\"%s\", nc=\"%s\", response=\"%s\"\r\n", authuser, auth->realm, auth->nonce, target, noncecount, response);
12382
cfc808463763 [gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents: 12216
diff changeset
301 g_free(response);
11346
e40318d2bcd8 [gaim-migrate @ 13563]
Thomas Butter <tbutter>
parents: 11345
diff changeset
302 return ret;
e40318d2bcd8 [gaim-migrate @ 13563]
Thomas Butter <tbutter>
parents: 11345
diff changeset
303 }
e40318d2bcd8 [gaim-migrate @ 13563]
Thomas Butter <tbutter>
parents: 11345
diff changeset
304
14069
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
305 static char *parse_attribute(const char *attrname, const char *source) {
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
306 const char *tmp, *tmp2;
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
307 char *retval = NULL;
12746
4f7dab030b1a [gaim-migrate @ 15093]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12745
diff changeset
308 int len = strlen(attrname);
4f7dab030b1a [gaim-migrate @ 15093]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12745
diff changeset
309
4f7dab030b1a [gaim-migrate @ 15093]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12745
diff changeset
310 if(!strncmp(source, attrname, len)) {
4f7dab030b1a [gaim-migrate @ 15093]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12745
diff changeset
311 tmp = source + len;
4f7dab030b1a [gaim-migrate @ 15093]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12745
diff changeset
312 tmp2 = g_strstr_len(tmp, strlen(tmp), "\"");
4f7dab030b1a [gaim-migrate @ 15093]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12745
diff changeset
313 if(tmp2)
4f7dab030b1a [gaim-migrate @ 15093]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12745
diff changeset
314 retval = g_strndup(tmp, tmp2 - tmp);
13085
3382d7aa9ca3 [gaim-migrate @ 15447]
Thomas Butter <tbutter>
parents: 13084
diff changeset
315 else
3382d7aa9ca3 [gaim-migrate @ 15447]
Thomas Butter <tbutter>
parents: 13084
diff changeset
316 retval = g_strdup(tmp);
12746
4f7dab030b1a [gaim-migrate @ 15093]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12745
diff changeset
317 }
4f7dab030b1a [gaim-migrate @ 15093]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12745
diff changeset
318
4f7dab030b1a [gaim-migrate @ 15093]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12745
diff changeset
319 return retval;
4f7dab030b1a [gaim-migrate @ 15093]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12745
diff changeset
320 }
4f7dab030b1a [gaim-migrate @ 15093]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12745
diff changeset
321
11346
e40318d2bcd8 [gaim-migrate @ 13563]
Thomas Butter <tbutter>
parents: 11345
diff changeset
322 static void fill_auth(struct simple_account_data *sip, gchar *hdr, struct sip_auth *auth) {
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
323 int i = 0;
13088
a91a8a28f61f [gaim-migrate @ 15450]
Mark Doliner <mark@kingant.net>
parents: 13085
diff changeset
324 const char *authuser;
11424
e1ab173ef3b5 [gaim-migrate @ 13661]
Thomas Butter <tbutter>
parents: 11409
diff changeset
325 char *tmp;
11439
617e67e1c985 [gaim-migrate @ 13676]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11424
diff changeset
326 gchar **parts;
13084
31a3a9af1494 [gaim-migrate @ 15446]
Thomas Butter <tbutter>
parents: 13083
diff changeset
327
13088
a91a8a28f61f [gaim-migrate @ 15450]
Mark Doliner <mark@kingant.net>
parents: 13085
diff changeset
328 authuser = gaim_account_get_string(sip->account, "authuser", sip->username);
a91a8a28f61f [gaim-migrate @ 15450]
Mark Doliner <mark@kingant.net>
parents: 13085
diff changeset
329
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
330 if(!authuser || strlen(authuser) < 1) {
13084
31a3a9af1494 [gaim-migrate @ 15446]
Thomas Butter <tbutter>
parents: 13083
diff changeset
331 authuser = sip->username;
31a3a9af1494 [gaim-migrate @ 15446]
Thomas Butter <tbutter>
parents: 13083
diff changeset
332 }
13088
a91a8a28f61f [gaim-migrate @ 15450]
Mark Doliner <mark@kingant.net>
parents: 13085
diff changeset
333
11346
e40318d2bcd8 [gaim-migrate @ 13563]
Thomas Butter <tbutter>
parents: 11345
diff changeset
334 if(!hdr) {
11409
1e495a5fcbbc [gaim-migrate @ 13646]
Thomas Butter <tbutter>
parents: 11396
diff changeset
335 gaim_debug_error("simple", "fill_auth: hdr==NULL\n");
11346
e40318d2bcd8 [gaim-migrate @ 13563]
Thomas Butter <tbutter>
parents: 11345
diff changeset
336 return;
e40318d2bcd8 [gaim-migrate @ 13563]
Thomas Butter <tbutter>
parents: 11345
diff changeset
337 }
11409
1e495a5fcbbc [gaim-migrate @ 13646]
Thomas Butter <tbutter>
parents: 11396
diff changeset
338
1e495a5fcbbc [gaim-migrate @ 13646]
Thomas Butter <tbutter>
parents: 11396
diff changeset
339 if(!g_strncasecmp(hdr, "NTLM", 4)) {
1e495a5fcbbc [gaim-migrate @ 13646]
Thomas Butter <tbutter>
parents: 11396
diff changeset
340 gaim_debug_info("simple", "found NTLM\n");
1e495a5fcbbc [gaim-migrate @ 13646]
Thomas Butter <tbutter>
parents: 11396
diff changeset
341 auth->type = 2;
13347
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
342 parts = g_strsplit(hdr+5, "\", ", 0);
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
343 i = 0;
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
344 while(parts[i]) {
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
345 gaim_debug_info("simple", "parts[i] %s\n", parts[i]);
13347
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
346 if((tmp = parse_attribute("gssapi-data=\"", parts[i]))) {
13698
6bee2e80e42c [gaim-migrate @ 16101]
Mark Doliner <mark@kingant.net>
parents: 13678
diff changeset
347 auth->nonce = g_memdup(gaim_ntlm_parse_type2(tmp, &auth->flags), 8);
13347
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
348 g_free(tmp);
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
349 }
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
350 if((tmp = parse_attribute("targetname=\"",
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
351 parts[i]))) {
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
352 auth->target = tmp;
11424
e1ab173ef3b5 [gaim-migrate @ 13661]
Thomas Butter <tbutter>
parents: 11409
diff changeset
353 }
13347
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
354 else if((tmp = parse_attribute("realm=\"",
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
355 parts[i]))) {
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
356 auth->realm = tmp;
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
357 }
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
358 else if((tmp = parse_attribute("opaque=\"", parts[i]))) {
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
359 auth->opaque = tmp;
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
360 }
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
361 i++;
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
362 }
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
363 g_strfreev(parts);
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
364 auth->nc = 1;
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
365 if(!strstr(hdr, "gssapi-data")) {
11409
1e495a5fcbbc [gaim-migrate @ 13646]
Thomas Butter <tbutter>
parents: 11396
diff changeset
366 auth->nc = 1;
13084
31a3a9af1494 [gaim-migrate @ 15446]
Thomas Butter <tbutter>
parents: 13083
diff changeset
367 } else {
11409
1e495a5fcbbc [gaim-migrate @ 13646]
Thomas Butter <tbutter>
parents: 11396
diff changeset
368 auth->nc = 3;
13347
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
369 }
11409
1e495a5fcbbc [gaim-migrate @ 13646]
Thomas Butter <tbutter>
parents: 11396
diff changeset
370 return;
1e495a5fcbbc [gaim-migrate @ 13646]
Thomas Butter <tbutter>
parents: 11396
diff changeset
371 }
1e495a5fcbbc [gaim-migrate @ 13646]
Thomas Butter <tbutter>
parents: 11396
diff changeset
372
1e495a5fcbbc [gaim-migrate @ 13646]
Thomas Butter <tbutter>
parents: 11396
diff changeset
373 auth->type = 1;
11439
617e67e1c985 [gaim-migrate @ 13676]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11424
diff changeset
374 parts = g_strsplit(hdr, " ", 0);
11346
e40318d2bcd8 [gaim-migrate @ 13563]
Thomas Butter <tbutter>
parents: 11345
diff changeset
375 while(parts[i]) {
12746
4f7dab030b1a [gaim-migrate @ 15093]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12745
diff changeset
376 if((tmp = parse_attribute("nonce=\"", parts[i]))) {
4f7dab030b1a [gaim-migrate @ 15093]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12745
diff changeset
377 auth->nonce = tmp;
11346
e40318d2bcd8 [gaim-migrate @ 13563]
Thomas Butter <tbutter>
parents: 11345
diff changeset
378 }
12746
4f7dab030b1a [gaim-migrate @ 15093]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12745
diff changeset
379 else if((tmp = parse_attribute("realm=\"", parts[i]))) {
4f7dab030b1a [gaim-migrate @ 15093]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12745
diff changeset
380 auth->realm = tmp;
11346
e40318d2bcd8 [gaim-migrate @ 13563]
Thomas Butter <tbutter>
parents: 11345
diff changeset
381 }
e40318d2bcd8 [gaim-migrate @ 13563]
Thomas Butter <tbutter>
parents: 11345
diff changeset
382 i++;
e40318d2bcd8 [gaim-migrate @ 13563]
Thomas Butter <tbutter>
parents: 11345
diff changeset
383 }
11439
617e67e1c985 [gaim-migrate @ 13676]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11424
diff changeset
384 g_strfreev(parts);
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
385
13749
e4a4983752a9 [gaim-migrate @ 16160]
Mark Doliner <mark@kingant.net>
parents: 13698
diff changeset
386 gaim_debug(GAIM_DEBUG_MISC, "simple", "nonce: %s realm: %s\n", auth->nonce ? auth->nonce : "(null)", auth->realm ? auth->realm : "(null)");
13656
d0fc90e56b5e [gaim-migrate @ 16058]
Thomas Butter <tbutter>
parents: 13655
diff changeset
387 if(auth->realm) {
d0fc90e56b5e [gaim-migrate @ 16058]
Thomas Butter <tbutter>
parents: 13655
diff changeset
388 auth->digest_session_key = gaim_cipher_http_digest_calculate_session_key(
d0fc90e56b5e [gaim-migrate @ 16058]
Thomas Butter <tbutter>
parents: 13655
diff changeset
389 "md5", authuser, auth->realm, sip->password, auth->nonce, NULL);
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
390
13656
d0fc90e56b5e [gaim-migrate @ 16058]
Thomas Butter <tbutter>
parents: 13655
diff changeset
391 auth->nc = 1;
d0fc90e56b5e [gaim-migrate @ 16058]
Thomas Butter <tbutter>
parents: 13655
diff changeset
392 }
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
393 }
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
394
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
395 static void simple_canwrite_cb(gpointer data, gint source, GaimInputCondition cond) {
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
396 GaimConnection *gc = data;
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
397 struct simple_account_data *sip = gc->proto_data;
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
398 gsize max_write;
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
399 gssize written;
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
400
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
401 max_write = gaim_circ_buffer_get_max_read(sip->txbuf);
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
402
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
403 if(max_write == 0) {
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
404 gaim_input_remove(sip->tx_handler);
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
405 sip->tx_handler = 0;
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
406 return;
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
407 }
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
408
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
409 written = write(sip->fd, sip->txbuf->outptr, max_write);
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
410
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
411 if(written < 0 && errno == EAGAIN)
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
412 written = 0;
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
413 else if(written <= 0) {
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
414 /*TODO: do we really want to disconnect on a failure to write?*/
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
415 gaim_connection_error(gc, _("Could not write"));
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
416 return;
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
417 }
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
418
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
419 gaim_circ_buffer_mark_read(sip->txbuf, written);
11346
e40318d2bcd8 [gaim-migrate @ 13563]
Thomas Butter <tbutter>
parents: 11345
diff changeset
420 }
e40318d2bcd8 [gaim-migrate @ 13563]
Thomas Butter <tbutter>
parents: 11345
diff changeset
421
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
422 static void simple_input_cb(gpointer data, gint source, GaimInputCondition cond);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
423
14118
87ff682bdf5f [gaim-migrate @ 16752]
Mark Doliner <mark@kingant.net>
parents: 14108
diff changeset
424 static void send_later_cb(gpointer data, gint source, const gchar *error) {
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
425 GaimConnection *gc = data;
14118
87ff682bdf5f [gaim-migrate @ 16752]
Mark Doliner <mark@kingant.net>
parents: 14108
diff changeset
426 struct simple_account_data *sip;
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
427 struct sip_connection *conn;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
428
14118
87ff682bdf5f [gaim-migrate @ 16752]
Mark Doliner <mark@kingant.net>
parents: 14108
diff changeset
429 if (!GAIM_CONNECTION_IS_VALID(gc))
87ff682bdf5f [gaim-migrate @ 16752]
Mark Doliner <mark@kingant.net>
parents: 14108
diff changeset
430 {
87ff682bdf5f [gaim-migrate @ 16752]
Mark Doliner <mark@kingant.net>
parents: 14108
diff changeset
431 if (source >= 0)
87ff682bdf5f [gaim-migrate @ 16752]
Mark Doliner <mark@kingant.net>
parents: 14108
diff changeset
432 close(source);
87ff682bdf5f [gaim-migrate @ 16752]
Mark Doliner <mark@kingant.net>
parents: 14108
diff changeset
433 return;
87ff682bdf5f [gaim-migrate @ 16752]
Mark Doliner <mark@kingant.net>
parents: 14108
diff changeset
434 }
87ff682bdf5f [gaim-migrate @ 16752]
Mark Doliner <mark@kingant.net>
parents: 14108
diff changeset
435
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
436 if(source < 0) {
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
437 gaim_connection_error(gc, _("Could not connect"));
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
438 return;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
439 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
440
14118
87ff682bdf5f [gaim-migrate @ 16752]
Mark Doliner <mark@kingant.net>
parents: 14108
diff changeset
441 sip = gc->proto_data;
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
442 sip->fd = source;
13058
256abf4dd912 [gaim-migrate @ 15420]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12909
diff changeset
443 sip->connecting = FALSE;
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
444
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
445 simple_canwrite_cb(gc, sip->fd, GAIM_INPUT_WRITE);
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
446
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
447 /* If there is more to write now, we need to register a handler */
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
448 if(sip->txbuf->bufused > 0)
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
449 sip->tx_handler = gaim_input_add(sip->fd, GAIM_INPUT_WRITE,
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
450 simple_canwrite_cb, gc);
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
451
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
452 conn = connection_create(sip, source);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
453 conn->inputhandler = gaim_input_add(sip->fd, GAIM_INPUT_READ, simple_input_cb, gc);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
454 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
455
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
456
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
457 static void sendlater(GaimConnection *gc, const char *buf) {
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
458 struct simple_account_data *sip = gc->proto_data;
14089
10e8eb6a4910 [gaim-migrate @ 16712]
Mark Doliner <mark@kingant.net>
parents: 14070
diff changeset
459 GaimProxyConnectInfo *connect_info;
10e8eb6a4910 [gaim-migrate @ 16712]
Mark Doliner <mark@kingant.net>
parents: 14070
diff changeset
460
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
461 if(!sip->connecting) {
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
462 gaim_debug_info("simple", "connecting to %s port %d\n", sip->realhostname ? sip->realhostname : "{NULL}", sip->realport);
14108
7a205b430d19 [gaim-migrate @ 16742]
Mark Doliner <mark@kingant.net>
parents: 14089
diff changeset
463 connect_info = gaim_proxy_connect(sip->account, sip->realhostname, sip->realport, send_later_cb, gc);
14089
10e8eb6a4910 [gaim-migrate @ 16712]
Mark Doliner <mark@kingant.net>
parents: 14070
diff changeset
464 if(connect_info == NULL) {
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
465 gaim_connection_error(gc, _("Couldn't create socket"));
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
466 }
13058
256abf4dd912 [gaim-migrate @ 15420]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12909
diff changeset
467 sip->connecting = TRUE;
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
468 }
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
469
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
470 if(gaim_circ_buffer_get_max_read(sip->txbuf) > 0)
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
471 gaim_circ_buffer_append(sip->txbuf, "\r\n", 2);
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
472
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
473 gaim_circ_buffer_append(sip->txbuf, buf, strlen(buf));
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
474 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
475
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
476 static void sendout_pkt(GaimConnection *gc, const char *buf) {
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
477 struct simple_account_data *sip = gc->proto_data;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
478 time_t currtime = time(NULL);
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
479 int writelen = strlen(buf);
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
480
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
481 gaim_debug(GAIM_DEBUG_MISC, "simple", "\n\nsending - %s\n######\n%s\n######\n\n", ctime(&currtime), buf);
11189
5f79dfde334c [gaim-migrate @ 13307]
Thomas Butter <tbutter>
parents: 11181
diff changeset
482 if(sip->udp) {
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
483 if(sendto(sip->fd, buf, writelen, 0, (struct sockaddr*)&sip->serveraddr, sizeof(struct sockaddr_in)) < writelen) {
11189
5f79dfde334c [gaim-migrate @ 13307]
Thomas Butter <tbutter>
parents: 11181
diff changeset
484 gaim_debug_info("simple", "could not send packet\n");
5f79dfde334c [gaim-migrate @ 13307]
Thomas Butter <tbutter>
parents: 11181
diff changeset
485 }
5f79dfde334c [gaim-migrate @ 13307]
Thomas Butter <tbutter>
parents: 11181
diff changeset
486 } else {
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
487 int ret;
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
488 if(sip->fd < 0) {
11189
5f79dfde334c [gaim-migrate @ 13307]
Thomas Butter <tbutter>
parents: 11181
diff changeset
489 sendlater(gc, buf);
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
490 return;
11189
5f79dfde334c [gaim-migrate @ 13307]
Thomas Butter <tbutter>
parents: 11181
diff changeset
491 }
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
492
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
493 if(sip->tx_handler) {
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
494 ret = -1;
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
495 errno = EAGAIN;
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
496 } else
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
497 ret = write(sip->fd, buf, writelen);
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
498
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
499 if (ret < 0 && errno == EAGAIN)
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
500 ret = 0;
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
501 else if(ret <= 0) { /* XXX: When does this happen legitimately? */
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
502 sendlater(gc, buf);
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
503 return;
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
504 }
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
505
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
506 if (ret < writelen) {
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
507 if(!sip->tx_handler)
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
508 sip->tx_handler = gaim_input_add(sip->fd,
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
509 GAIM_INPUT_WRITE, simple_canwrite_cb,
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
510 gc);
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
511
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
512 /* XXX: is it OK to do this? You might get part of a request sent
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
513 with part of another. */
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
514 if(sip->txbuf->bufused > 0)
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
515 gaim_circ_buffer_append(sip->txbuf, "\r\n", 2);
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
516
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
517 gaim_circ_buffer_append(sip->txbuf, buf + ret,
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
518 writelen - ret);
11189
5f79dfde334c [gaim-migrate @ 13307]
Thomas Butter <tbutter>
parents: 11181
diff changeset
519 }
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
520 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
521 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
522
11194
4c1f45ac00e9 [gaim-migrate @ 13317]
Thomas Butter <tbutter>
parents: 11192
diff changeset
523 static void sendout_sipmsg(struct simple_account_data *sip, struct sipmsg *msg) {
12741
2b61e6ed85c3 [gaim-migrate @ 15088]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
524 GSList *tmp = msg->headers;
11194
4c1f45ac00e9 [gaim-migrate @ 13317]
Thomas Butter <tbutter>
parents: 11192
diff changeset
525 gchar *name;
4c1f45ac00e9 [gaim-migrate @ 13317]
Thomas Butter <tbutter>
parents: 11192
diff changeset
526 gchar *value;
12741
2b61e6ed85c3 [gaim-migrate @ 15088]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
527 GString *outstr = g_string_new("");
2b61e6ed85c3 [gaim-migrate @ 15088]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
528 g_string_append_printf(outstr, "%s %s SIP/2.0\r\n", msg->method, msg->target);
11194
4c1f45ac00e9 [gaim-migrate @ 13317]
Thomas Butter <tbutter>
parents: 11192
diff changeset
529 while(tmp) {
12741
2b61e6ed85c3 [gaim-migrate @ 15088]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
530 name = ((struct siphdrelement*) (tmp->data))->name;
2b61e6ed85c3 [gaim-migrate @ 15088]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
531 value = ((struct siphdrelement*) (tmp->data))->value;
2b61e6ed85c3 [gaim-migrate @ 15088]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
532 g_string_append_printf(outstr, "%s: %s\r\n", name, value);
11194
4c1f45ac00e9 [gaim-migrate @ 13317]
Thomas Butter <tbutter>
parents: 11192
diff changeset
533 tmp = g_slist_next(tmp);
4c1f45ac00e9 [gaim-migrate @ 13317]
Thomas Butter <tbutter>
parents: 11192
diff changeset
534 }
12741
2b61e6ed85c3 [gaim-migrate @ 15088]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
535 g_string_append_printf(outstr, "\r\n%s", msg->body ? msg->body : "");
2b61e6ed85c3 [gaim-migrate @ 15088]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
536 sendout_pkt(sip->gc, outstr->str);
2b61e6ed85c3 [gaim-migrate @ 15088]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
537 g_string_free(outstr, TRUE);
11194
4c1f45ac00e9 [gaim-migrate @ 13317]
Thomas Butter <tbutter>
parents: 11192
diff changeset
538 }
4c1f45ac00e9 [gaim-migrate @ 13317]
Thomas Butter <tbutter>
parents: 11192
diff changeset
539
14069
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
540 static void send_sip_response(GaimConnection *gc, struct sipmsg *msg, int code,
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
541 const char *text, const char *body) {
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
542 GSList *tmp = msg->headers;
12741
2b61e6ed85c3 [gaim-migrate @ 15088]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
543 gchar *name;
2b61e6ed85c3 [gaim-migrate @ 15088]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
544 gchar *value;
2b61e6ed85c3 [gaim-migrate @ 15088]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
545 GString *outstr = g_string_new("");
13092
edef744647ff [gaim-migrate @ 15454]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13088
diff changeset
546
12754
d37adb7af391 [gaim-migrate @ 15101]
Thomas Butter <tbutter>
parents: 12753
diff changeset
547 /* When sending the acknowlegements and errors, the content length from the original
d37adb7af391 [gaim-migrate @ 15101]
Thomas Butter <tbutter>
parents: 12753
diff changeset
548 message is still here, but there is no body; we need to make sure we're sending the
d37adb7af391 [gaim-migrate @ 15101]
Thomas Butter <tbutter>
parents: 12753
diff changeset
549 correct content length */
d37adb7af391 [gaim-migrate @ 15101]
Thomas Butter <tbutter>
parents: 12753
diff changeset
550 sipmsg_remove_header(msg, "Content-Length");
d37adb7af391 [gaim-migrate @ 15101]
Thomas Butter <tbutter>
parents: 12753
diff changeset
551 if(body) {
d37adb7af391 [gaim-migrate @ 15101]
Thomas Butter <tbutter>
parents: 12753
diff changeset
552 gchar len[12];
d37adb7af391 [gaim-migrate @ 15101]
Thomas Butter <tbutter>
parents: 12753
diff changeset
553 sprintf(len, "%" G_GSIZE_FORMAT , strlen(body));
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
554 sipmsg_add_header(msg, "Content-Length", len);
12754
d37adb7af391 [gaim-migrate @ 15101]
Thomas Butter <tbutter>
parents: 12753
diff changeset
555 }
d37adb7af391 [gaim-migrate @ 15101]
Thomas Butter <tbutter>
parents: 12753
diff changeset
556 else
d37adb7af391 [gaim-migrate @ 15101]
Thomas Butter <tbutter>
parents: 12753
diff changeset
557 sipmsg_add_header(msg, "Content-Length", "0");
12741
2b61e6ed85c3 [gaim-migrate @ 15088]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
558 g_string_append_printf(outstr, "SIP/2.0 %d %s\r\n", code, text);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
559 while(tmp) {
12741
2b61e6ed85c3 [gaim-migrate @ 15088]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
560 name = ((struct siphdrelement*) (tmp->data))->name;
2b61e6ed85c3 [gaim-migrate @ 15088]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
561 value = ((struct siphdrelement*) (tmp->data))->value;
12745
e788741f4840 [gaim-migrate @ 15092]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12741
diff changeset
562
12741
2b61e6ed85c3 [gaim-migrate @ 15088]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
563 g_string_append_printf(outstr, "%s: %s\r\n", name, value);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
564 tmp = g_slist_next(tmp);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
565 }
12741
2b61e6ed85c3 [gaim-migrate @ 15088]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
566 g_string_append_printf(outstr, "\r\n%s", body ? body : "");
2b61e6ed85c3 [gaim-migrate @ 15088]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
567 sendout_pkt(gc, outstr->str);
2b61e6ed85c3 [gaim-migrate @ 15088]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
568 g_string_free(outstr, TRUE);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
569 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
570
11194
4c1f45ac00e9 [gaim-migrate @ 13317]
Thomas Butter <tbutter>
parents: 11192
diff changeset
571 static void transactions_remove(struct simple_account_data *sip, struct transaction *trans) {
4c1f45ac00e9 [gaim-migrate @ 13317]
Thomas Butter <tbutter>
parents: 11192
diff changeset
572 if(trans->msg) sipmsg_free(trans->msg);
4c1f45ac00e9 [gaim-migrate @ 13317]
Thomas Butter <tbutter>
parents: 11192
diff changeset
573 sip->transactions = g_slist_remove(sip->transactions, trans);
4c1f45ac00e9 [gaim-migrate @ 13317]
Thomas Butter <tbutter>
parents: 11192
diff changeset
574 g_free(trans);
4c1f45ac00e9 [gaim-migrate @ 13317]
Thomas Butter <tbutter>
parents: 11192
diff changeset
575 }
4c1f45ac00e9 [gaim-migrate @ 13317]
Thomas Butter <tbutter>
parents: 11192
diff changeset
576
14069
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
577 static void transactions_add_buf(struct simple_account_data *sip, const gchar *buf, void *callback) {
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
578 struct transaction *trans = g_new0(struct transaction, 1);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
579 trans->time = time(NULL);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
580 trans->msg = sipmsg_parse_msg(buf);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
581 trans->cseq = sipmsg_find_header(trans->msg, "CSeq");
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
582 trans->callback = callback;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
583 sip->transactions = g_slist_append(sip->transactions, trans);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
584 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
585
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
586 static struct transaction *transactions_find(struct simple_account_data *sip, struct sipmsg *msg) {
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
587 struct transaction *trans;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
588 GSList *transactions = sip->transactions;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
589 gchar *cseq = sipmsg_find_header(msg, "CSeq");
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
590
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
591 while(transactions) {
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
592 trans = transactions->data;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
593 if(!strcmp(trans->cseq, cseq)) {
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
594 return trans;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
595 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
596 transactions = transactions->next;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
597 }
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
598
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
599 return NULL;
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
600 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
601
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
602 static void send_sip_request(GaimConnection *gc, const gchar *method,
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
603 const gchar *url, const gchar *to, const gchar *addheaders,
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
604 const gchar *body, struct sip_dialog *dialog, TransCallback tc) {
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
605 struct simple_account_data *sip = gc->proto_data;
13092
edef744647ff [gaim-migrate @ 15454]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13088
diff changeset
606 char *callid = dialog ? g_strdup(dialog->callid) : gencallid();
edef744647ff [gaim-migrate @ 15454]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13088
diff changeset
607 char *auth = "";
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
608 const char *addh = "";
12216
4d3119205a33 [gaim-migrate @ 14518]
Stu Tomlinson <stu@nosnilmot.com>
parents: 12196
diff changeset
609 gchar *branch = genbranch();
14069
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
610 gchar *tag = NULL;
12216
4d3119205a33 [gaim-migrate @ 14518]
Stu Tomlinson <stu@nosnilmot.com>
parents: 12196
diff changeset
611 char *buf;
4d3119205a33 [gaim-migrate @ 14518]
Stu Tomlinson <stu@nosnilmot.com>
parents: 12196
diff changeset
612
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
613 if(!strcmp(method, "REGISTER")) {
13092
edef744647ff [gaim-migrate @ 15454]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13088
diff changeset
614 if(sip->regcallid) {
edef744647ff [gaim-migrate @ 15454]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13088
diff changeset
615 g_free(callid);
edef744647ff [gaim-migrate @ 15454]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13088
diff changeset
616 callid = g_strdup(sip->regcallid);
edef744647ff [gaim-migrate @ 15454]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13088
diff changeset
617 }
12196
2f379ed0c26b [gaim-migrate @ 14498]
Ethan Blanton <elb@pidgin.im>
parents: 12143
diff changeset
618 else sip->regcallid = g_strdup(callid);
2f379ed0c26b [gaim-migrate @ 14498]
Ethan Blanton <elb@pidgin.im>
parents: 12143
diff changeset
619 }
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
620
13092
edef744647ff [gaim-migrate @ 15454]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13088
diff changeset
621 if(addheaders) addh = addheaders;
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
622 if(sip->registrar.type && !strcmp(method, "REGISTER")) {
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
623 buf = auth_header(sip, &sip->registrar, method, url);
12563
b7f7f3a685ea [gaim-migrate @ 14882]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12492
diff changeset
624 auth = g_strdup_printf("Authorization: %s", buf);
11346
e40318d2bcd8 [gaim-migrate @ 13563]
Thomas Butter <tbutter>
parents: 11345
diff changeset
625 g_free(buf);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
626 gaim_debug(GAIM_DEBUG_MISC, "simple", "header %s", auth);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
627 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
628
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
629 if(sip->proxy.type && strcmp(method, "REGISTER")) {
11346
e40318d2bcd8 [gaim-migrate @ 13563]
Thomas Butter <tbutter>
parents: 11345
diff changeset
630 buf = auth_header(sip, &sip->proxy, method, url);
12563
b7f7f3a685ea [gaim-migrate @ 14882]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12492
diff changeset
631 auth = g_strdup_printf("Proxy-Authorization: %s", buf);
11346
e40318d2bcd8 [gaim-migrate @ 13563]
Thomas Butter <tbutter>
parents: 11345
diff changeset
632 g_free(buf);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
633 gaim_debug(GAIM_DEBUG_MISC, "simple", "header %s", auth);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
634 }
12767
53218d758ba9 [gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12760
diff changeset
635
14069
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
636 if (!dialog)
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
637 tag = gentag();
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
638
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
639 buf = g_strdup_printf("%s %s SIP/2.0\r\n"
11190
fde0f4c1348d [gaim-migrate @ 13308]
Thomas Butter <tbutter>
parents: 11189
diff changeset
640 "Via: SIP/2.0/%s %s:%d;branch=%s\r\n"
13084
31a3a9af1494 [gaim-migrate @ 15446]
Thomas Butter <tbutter>
parents: 13083
diff changeset
641 /* Don't know what epid is, but LCS wants it */
31a3a9af1494 [gaim-migrate @ 15446]
Thomas Butter <tbutter>
parents: 13083
diff changeset
642 "From: <sip:%s@%s>;tag=%s;epid=1234567890\r\n"
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
643 "To: <%s>%s%s\r\n"
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
644 "Max-Forwards: 10\r\n"
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
645 "CSeq: %d %s\r\n"
13678
299536c4caf1 [gaim-migrate @ 16080]
Mark Doliner <mark@kingant.net>
parents: 13656
diff changeset
646 "User-Agent: Gaim/" VERSION "\r\n"
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
647 "Call-ID: %s\r\n"
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
648 "%s%s"
11658
20edc3a05317 [gaim-migrate @ 13943]
Nathan Walp <nwalp@pidgin.im>
parents: 11650
diff changeset
649 "Content-Length: %" G_GSIZE_FORMAT "\r\n\r\n%s",
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
650 method,
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
651 url,
11190
fde0f4c1348d [gaim-migrate @ 13308]
Thomas Butter <tbutter>
parents: 11189
diff changeset
652 sip->udp ? "UDP" : "TCP",
13129
d0ae6489a0fb [gaim-migrate @ 15491]
Mark Doliner <mark@kingant.net>
parents: 13092
diff changeset
653 gaim_network_get_my_ip(-1),
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
654 sip->listenport,
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
655 branch,
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
656 sip->username,
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
657 sip->servername,
14069
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
658 dialog ? dialog->ourtag : tag,
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
659 to,
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
660 dialog ? ";tag=" : "",
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
661 dialog ? dialog->theirtag : "",
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
662 ++sip->cseq,
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
663 method,
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
664 callid,
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
665 auth,
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
666 addh,
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
667 strlen(body),
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
668 body);
14069
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
669
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
670 g_free(tag);
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
671 g_free(auth);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
672 g_free(branch);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
673 g_free(callid);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
674
11341
3f0fda678686 [gaim-migrate @ 13555]
Thomas Butter <tbutter>
parents: 11327
diff changeset
675 /* add to ongoing transactions */
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
676
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
677 transactions_add_buf(sip, buf, tc);
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
678
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
679 sendout_pkt(gc, buf);
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
680
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
681 g_free(buf);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
682 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
683
13177
891be2f09b5c [gaim-migrate @ 15540]
Thomas Butter <tbutter>
parents: 13129
diff changeset
684 static char *get_contact(struct simple_account_data *sip) {
891be2f09b5c [gaim-migrate @ 15540]
Thomas Butter <tbutter>
parents: 13129
diff changeset
685 return g_strdup_printf("<sip:%s@%s:%d;transport=%s>;methods=\"MESSAGE, SUBSCRIBE, NOTIFY\"", sip->username, gaim_network_get_my_ip(-1), sip->listenport, sip->udp ? "udp" : "tcp");
891be2f09b5c [gaim-migrate @ 15540]
Thomas Butter <tbutter>
parents: 13129
diff changeset
686 }
891be2f09b5c [gaim-migrate @ 15540]
Thomas Butter <tbutter>
parents: 13129
diff changeset
687
11194
4c1f45ac00e9 [gaim-migrate @ 13317]
Thomas Butter <tbutter>
parents: 11192
diff changeset
688 static void do_register_exp(struct simple_account_data *sip, int expire) {
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
689 char *uri = g_strdup_printf("sip:%s", sip->servername);
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
690 char *to = g_strdup_printf("sip:%s@%s", sip->username, sip->servername);
13177
891be2f09b5c [gaim-migrate @ 15540]
Thomas Butter <tbutter>
parents: 13129
diff changeset
691 char *contact = get_contact(sip);
891be2f09b5c [gaim-migrate @ 15540]
Thomas Butter <tbutter>
parents: 13129
diff changeset
692 char *hdr = g_strdup_printf("Contact: %s\r\nExpires: %d\r\n", contact, expire);
891be2f09b5c [gaim-migrate @ 15540]
Thomas Butter <tbutter>
parents: 13129
diff changeset
693 g_free(contact);
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
694
11439
617e67e1c985 [gaim-migrate @ 13676]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11424
diff changeset
695 sip->registerstatus = 1;
617e67e1c985 [gaim-migrate @ 13676]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11424
diff changeset
696
11194
4c1f45ac00e9 [gaim-migrate @ 13317]
Thomas Butter <tbutter>
parents: 11192
diff changeset
697 if(expire) {
4c1f45ac00e9 [gaim-migrate @ 13317]
Thomas Butter <tbutter>
parents: 11192
diff changeset
698 sip->reregister = time(NULL) + expire - 50;
4c1f45ac00e9 [gaim-migrate @ 13317]
Thomas Butter <tbutter>
parents: 11192
diff changeset
699 } else {
4c1f45ac00e9 [gaim-migrate @ 13317]
Thomas Butter <tbutter>
parents: 11192
diff changeset
700 sip->reregister = time(NULL) + 600;
4c1f45ac00e9 [gaim-migrate @ 13317]
Thomas Butter <tbutter>
parents: 11192
diff changeset
701 }
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
702
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
703 send_sip_request(sip->gc, "REGISTER", uri, to, hdr, "", NULL,
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
704 process_register_response);
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
705
13177
891be2f09b5c [gaim-migrate @ 15540]
Thomas Butter <tbutter>
parents: 13129
diff changeset
706 g_free(hdr);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
707 g_free(uri);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
708 g_free(to);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
709 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
710
11194
4c1f45ac00e9 [gaim-migrate @ 13317]
Thomas Butter <tbutter>
parents: 11192
diff changeset
711 static void do_register(struct simple_account_data *sip) {
4c1f45ac00e9 [gaim-migrate @ 13317]
Thomas Butter <tbutter>
parents: 11192
diff changeset
712 do_register_exp(sip, sip->registerexpire);
4c1f45ac00e9 [gaim-migrate @ 13317]
Thomas Butter <tbutter>
parents: 11192
diff changeset
713 }
4c1f45ac00e9 [gaim-migrate @ 13317]
Thomas Butter <tbutter>
parents: 11192
diff changeset
714
14069
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
715 static gchar *parse_from(const gchar *hdr) {
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
716 gchar *from;
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
717 const gchar *tmp, *tmp2 = hdr;
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
718
14069
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
719 if(!hdr) return NULL;
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
720 gaim_debug_info("simple", "parsing address out of %s\n", hdr);
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
721 tmp = strchr(hdr, '<');
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
722
11341
3f0fda678686 [gaim-migrate @ 13555]
Thomas Butter <tbutter>
parents: 11327
diff changeset
723 /* i hate the different SIP UA behaviours... */
3f0fda678686 [gaim-migrate @ 13555]
Thomas Butter <tbutter>
parents: 11327
diff changeset
724 if(tmp) { /* sip address in <...> */
14069
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
725 tmp2 = tmp + 1;
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
726 tmp = strchr(tmp2, '>');
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
727 if(tmp) {
14069
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
728 from = g_strndup(tmp2, tmp - tmp2);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
729 } else {
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
730 gaim_debug_info("simple", "found < without > in From\n");
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
731 return NULL;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
732 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
733 } else {
14069
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
734 tmp = strchr(tmp2, ';');
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
735 if(tmp) {
14069
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
736 from = g_strndup(tmp2, tmp - tmp2);
11483
0d18fa6c3b41 [gaim-migrate @ 13725]
Thomas Butter <tbutter>
parents: 11439
diff changeset
737 } else {
14069
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
738 from = g_strdup(tmp2);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
739 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
740 }
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
741 gaim_debug_info("simple", "got %s\n", from);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
742 return from;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
743 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
744
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
745 static gboolean process_subscribe_response(struct simple_account_data *sip, struct sipmsg *msg, struct transaction *tc) {
14069
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
746 gchar *to;
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
747
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
748 if(msg->response == 200 || msg->response == 202) {
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
749 return TRUE;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
750 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
751
14069
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
752 to = parse_from(sipmsg_find_header(tc->msg, "To")); /* cant be NULL since it is our own msg */
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
753
11341
3f0fda678686 [gaim-migrate @ 13555]
Thomas Butter <tbutter>
parents: 11327
diff changeset
754 /* we can not subscribe -> user is offline (TODO unknown status?) */
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
755
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
756 gaim_prpl_got_user_status(sip->account, to, "offline", NULL);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
757 g_free(to);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
758 return TRUE;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
759 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
760
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
761 static void simple_subscribe(struct simple_account_data *sip, struct simple_buddy *buddy) {
13347
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
762 gchar *contact = "Expires: 1200\r\nAccept: application/pidf+xml, application/xpidf+xml\r\nEvent: presence\r\n";
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
763 gchar *to;
13177
891be2f09b5c [gaim-migrate @ 15540]
Thomas Butter <tbutter>
parents: 13129
diff changeset
764 gchar *tmp;
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
765
14069
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
766 if(strstr(buddy->name, "sip:"))
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
767 to = g_strdup(buddy->name);
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
768 else
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
769 to = g_strdup_printf("sip:%s", buddy->name);
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
770
13177
891be2f09b5c [gaim-migrate @ 15540]
Thomas Butter <tbutter>
parents: 13129
diff changeset
771 tmp = get_contact(sip);
891be2f09b5c [gaim-migrate @ 15540]
Thomas Butter <tbutter>
parents: 13129
diff changeset
772 contact = g_strdup_printf("%sContact: %s\r\n", contact, tmp);
891be2f09b5c [gaim-migrate @ 15540]
Thomas Butter <tbutter>
parents: 13129
diff changeset
773 g_free(tmp);
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
774
11341
3f0fda678686 [gaim-migrate @ 13555]
Thomas Butter <tbutter>
parents: 11327
diff changeset
775 /* subscribe to buddy presence
3f0fda678686 [gaim-migrate @ 13555]
Thomas Butter <tbutter>
parents: 11327
diff changeset
776 * we dont need to know the status so we do not need a callback */
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
777
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
778 send_sip_request(sip->gc, "SUBSCRIBE", to, to, contact, "", NULL,
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
779 process_subscribe_response);
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
780
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
781 g_free(to);
11341
3f0fda678686 [gaim-migrate @ 13555]
Thomas Butter <tbutter>
parents: 11327
diff changeset
782 g_free(contact);
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
783
11341
3f0fda678686 [gaim-migrate @ 13555]
Thomas Butter <tbutter>
parents: 11327
diff changeset
784 /* resubscribe before subscription expires */
3f0fda678686 [gaim-migrate @ 13555]
Thomas Butter <tbutter>
parents: 11327
diff changeset
785 /* add some jitter */
13347
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
786 buddy->resubscribe = time(NULL)+1140+(rand()%50);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
787 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
788
13347
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
789 static gboolean simple_add_lcs_contacts(struct simple_account_data *sip, struct sipmsg *msg, struct transaction *tc) {
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
790 gchar *tmp;
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
791 xmlnode *item, *group, *isc;
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
792 const char *name_group;
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
793 GaimBuddy *b;
14069
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
794 GaimGroup *g = NULL;
13347
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
795 struct simple_buddy *bs;
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
796 int len = msg->bodylen;
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
797
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
798
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
799 tmp = sipmsg_find_header(msg, "Event");
14069
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
800 if(tmp && !strncmp(tmp, "vnd-microsoft-roaming-contacts", 30)){
13347
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
801
14069
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
802 gaim_debug_info("simple", "simple_add_lcs_contacts->%s-%d\n", msg->body, len);
13347
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
803 /*Convert the contact from XML to Gaim Buddies*/
14069
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
804 isc = xmlnode_from_str(msg->body, len);
13347
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
805
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
806 /* ToDo. Find for all groups */
14069
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
807 if ((group = xmlnode_get_child(isc, "group"))) {
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
808 name_group = xmlnode_get_attrib(group, "name");
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
809 gaim_debug_info("simple", "name_group->%s\n", name_group);
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
810 g = gaim_find_group(name_group);
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
811 if(!g)
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
812 g = gaim_group_new(name_group);
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
813 }
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
814
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
815 if (!g) {
13347
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
816 g = gaim_find_group("Buddies");
14069
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
817 if(!g)
13347
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
818 g = gaim_group_new("Buddies");
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
819 }
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
820
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
821 for(item = xmlnode_get_child(isc, "contact"); item; item = xmlnode_get_next_twin(item))
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
822 {
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
823 const char *uri, *name, *groups;
14069
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
824 char *buddy_name;
13347
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
825 uri = xmlnode_get_attrib(item, "uri");
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
826 name = xmlnode_get_attrib(item, "name");
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
827 groups = xmlnode_get_attrib(item, "groups");
14069
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
828 gaim_debug_info("simple", "URI->%s\n", uri);
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
829
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
830 buddy_name = g_strdup_printf("sip:%s", uri);
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
831
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
832 b = gaim_find_buddy(sip->account, buddy_name);
13347
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
833 if(!b){
14069
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
834 b = gaim_buddy_new(sip->account, buddy_name, uri);
13347
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
835 }
14069
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
836 g_free(buddy_name);
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
837
13347
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
838 gaim_blist_add_buddy(b, NULL, g, NULL);
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
839 gaim_blist_alias_buddy(b, uri);
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
840 bs = g_new0(struct simple_buddy, 1);
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
841 bs->name = g_strdup(b->name);
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
842 g_hash_table_insert(sip->buddies, bs->name, bs);
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
843 }
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
844 xmlnode_free(isc);
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
845 }
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
846 return 0;
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
847 }
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
848
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
849 static void simple_subscribe_buddylist(struct simple_account_data *sip) {
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
850 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";
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
851 gchar *to;
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
852 gchar *tmp;
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
853 to = g_strdup_printf("sip:%s@%s", sip->username, sip->servername);
14069
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
854
13347
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
855 tmp = get_contact(sip);
14069
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
856
13347
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
857 contact = g_strdup_printf("%sContact: %s\r\n", contact, tmp);
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
858 g_free(tmp);
14069
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
859
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
860 send_sip_request(sip->gc, "SUBSCRIBE", to, to, contact, "", NULL, simple_add_lcs_contacts);
13347
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
861
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
862 g_free(to);
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
863 g_free(contact);
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
864 }
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
865
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
866
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
867 static void simple_buddy_resub(char *name, struct simple_buddy *buddy, struct simple_account_data *sip) {
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
868 time_t curtime = time(NULL);
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
869 gaim_debug_info("simple", "buddy resub\n");
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
870 if(buddy->resubscribe < curtime) {
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
871 gaim_debug(GAIM_DEBUG_MISC, "simple", "simple_buddy_resub %s\n", name);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
872 simple_subscribe(sip, buddy);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
873 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
874 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
875
11194
4c1f45ac00e9 [gaim-migrate @ 13317]
Thomas Butter <tbutter>
parents: 11192
diff changeset
876 static gboolean resend_timeout(struct simple_account_data *sip) {
4c1f45ac00e9 [gaim-migrate @ 13317]
Thomas Butter <tbutter>
parents: 11192
diff changeset
877 GSList *tmp = sip->transactions;
4c1f45ac00e9 [gaim-migrate @ 13317]
Thomas Butter <tbutter>
parents: 11192
diff changeset
878 time_t currtime = time(NULL);
4c1f45ac00e9 [gaim-migrate @ 13317]
Thomas Butter <tbutter>
parents: 11192
diff changeset
879 while(tmp) {
4c1f45ac00e9 [gaim-migrate @ 13317]
Thomas Butter <tbutter>
parents: 11192
diff changeset
880 struct transaction *trans = tmp->data;
4c1f45ac00e9 [gaim-migrate @ 13317]
Thomas Butter <tbutter>
parents: 11192
diff changeset
881 tmp = tmp->next;
4c1f45ac00e9 [gaim-migrate @ 13317]
Thomas Butter <tbutter>
parents: 11192
diff changeset
882 gaim_debug_info("simple", "have open transaction age: %d\n", currtime- trans->time);
4c1f45ac00e9 [gaim-migrate @ 13317]
Thomas Butter <tbutter>
parents: 11192
diff changeset
883 if((currtime - trans->time > 5) && trans->retries >= 1) {
11341
3f0fda678686 [gaim-migrate @ 13555]
Thomas Butter <tbutter>
parents: 11327
diff changeset
884 /* TODO 408 */
11194
4c1f45ac00e9 [gaim-migrate @ 13317]
Thomas Butter <tbutter>
parents: 11192
diff changeset
885 } else {
4c1f45ac00e9 [gaim-migrate @ 13317]
Thomas Butter <tbutter>
parents: 11192
diff changeset
886 if((currtime - trans->time > 2) && trans->retries == 0) {
4c1f45ac00e9 [gaim-migrate @ 13317]
Thomas Butter <tbutter>
parents: 11192
diff changeset
887 trans->retries++;
4c1f45ac00e9 [gaim-migrate @ 13317]
Thomas Butter <tbutter>
parents: 11192
diff changeset
888 sendout_sipmsg(sip, trans->msg);
4c1f45ac00e9 [gaim-migrate @ 13317]
Thomas Butter <tbutter>
parents: 11192
diff changeset
889 }
4c1f45ac00e9 [gaim-migrate @ 13317]
Thomas Butter <tbutter>
parents: 11192
diff changeset
890 }
4c1f45ac00e9 [gaim-migrate @ 13317]
Thomas Butter <tbutter>
parents: 11192
diff changeset
891 }
4c1f45ac00e9 [gaim-migrate @ 13317]
Thomas Butter <tbutter>
parents: 11192
diff changeset
892 return TRUE;
4c1f45ac00e9 [gaim-migrate @ 13317]
Thomas Butter <tbutter>
parents: 11192
diff changeset
893 }
4c1f45ac00e9 [gaim-migrate @ 13317]
Thomas Butter <tbutter>
parents: 11192
diff changeset
894
12768
3f6f2d59bcb4 [gaim-migrate @ 15115]
Thomas Butter <tbutter>
parents: 12767
diff changeset
895 static gboolean subscribe_timeout(struct simple_account_data *sip) {
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
896 GSList *tmp;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
897 time_t curtime = time(NULL);
11341
3f0fda678686 [gaim-migrate @ 13555]
Thomas Butter <tbutter>
parents: 11327
diff changeset
898 /* register again if first registration expires */
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
899 if(sip->reregister < curtime) {
11194
4c1f45ac00e9 [gaim-migrate @ 13317]
Thomas Butter <tbutter>
parents: 11192
diff changeset
900 do_register(sip);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
901 }
11341
3f0fda678686 [gaim-migrate @ 13555]
Thomas Butter <tbutter>
parents: 11327
diff changeset
902 /* check for every subscription if we need to resubscribe */
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
903 g_hash_table_foreach(sip->buddies, (GHFunc)simple_buddy_resub, (gpointer)sip);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
904
11341
3f0fda678686 [gaim-migrate @ 13555]
Thomas Butter <tbutter>
parents: 11327
diff changeset
905 /* remove a timed out suscriber */
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
906
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
907 tmp = sip->watcher;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
908 while(tmp) {
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
909 struct simple_watcher *watcher = tmp->data;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
910 if(watcher->expire < curtime) {
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
911 watcher_remove(sip, watcher->name);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
912 tmp = sip->watcher;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
913 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
914 if(tmp) tmp = tmp->next;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
915 }
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
916
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
917 return TRUE;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
918 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
919
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
920 static void simple_send_message(struct simple_account_data *sip, const char *to, const char *msg, const char *type) {
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
921 gchar *hdr;
13184
2d68ea9616b3 [gaim-migrate @ 15547]
Thomas Butter <tbutter>
parents: 13177
diff changeset
922 gchar *fullto;
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
923 if(strncmp("sip:", to, 4)) {
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
924 fullto = g_strdup_printf("sip:%s", to);
13184
2d68ea9616b3 [gaim-migrate @ 15547]
Thomas Butter <tbutter>
parents: 13177
diff changeset
925 } else {
2d68ea9616b3 [gaim-migrate @ 15547]
Thomas Butter <tbutter>
parents: 13177
diff changeset
926 fullto = g_strdup(to);
2d68ea9616b3 [gaim-migrate @ 15547]
Thomas Butter <tbutter>
parents: 13177
diff changeset
927 }
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
928 if(type) {
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
929 hdr = g_strdup_printf("Content-Type: %s\r\n", type);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
930 } else {
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
931 hdr = g_strdup("Content-Type: text/plain\r\n");
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
932 }
13184
2d68ea9616b3 [gaim-migrate @ 15547]
Thomas Butter <tbutter>
parents: 13177
diff changeset
933 send_sip_request(sip->gc, "MESSAGE", fullto, fullto, hdr, msg, NULL, NULL);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
934 g_free(hdr);
13184
2d68ea9616b3 [gaim-migrate @ 15547]
Thomas Butter <tbutter>
parents: 13177
diff changeset
935 g_free(fullto);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
936 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
937
12216
4d3119205a33 [gaim-migrate @ 14518]
Stu Tomlinson <stu@nosnilmot.com>
parents: 12196
diff changeset
938 static int simple_im_send(GaimConnection *gc, const char *who, const char *what, GaimMessageFlags flags) {
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
939 struct simple_account_data *sip = gc->proto_data;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
940 char *to = g_strdup(who);
12216
4d3119205a33 [gaim-migrate @ 14518]
Stu Tomlinson <stu@nosnilmot.com>
parents: 12196
diff changeset
941 char *text = gaim_unescape_html(what);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
942 simple_send_message(sip, to, text, NULL);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
943 g_free(to);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
944 g_free(text);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
945 return 1;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
946 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
947
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
948 static void process_incoming_message(struct simple_account_data *sip, struct sipmsg *msg) {
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
949 gchar *from;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
950 gchar *contenttype;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
951 gboolean found = FALSE;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
952
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
953 from = parse_from(sipmsg_find_header(msg, "From"));
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
954
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
955 if(!from) return;
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
956
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
957 gaim_debug(GAIM_DEBUG_MISC, "simple", "got message from %s: %s\n", from, msg->body);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
958
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
959 contenttype = sipmsg_find_header(msg, "Content-Type");
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
960 if(!contenttype || !strncmp(contenttype, "text/plain", 10) || !strncmp(contenttype, "text/html", 9)) {
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
961 serv_got_im(sip->gc, from, msg->body, 0, time(NULL));
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
962 send_sip_response(sip->gc, msg, 200, "OK", NULL);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
963 found = TRUE;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
964 }
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
965 if(!strncmp(contenttype, "application/im-iscomposing+xml", 30)) {
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
966 xmlnode *isc = xmlnode_from_str(msg->body, msg->bodylen);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
967 xmlnode *state;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
968 gchar *statedata;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
969
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
970 if(!isc) {
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
971 gaim_debug_info("simple", "process_incoming_message: can not parse iscomposing\n");
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
972 return;
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
973 }
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
974
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
975 state = xmlnode_get_child(isc, "state");
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
976
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
977 if(!state) {
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
978 gaim_debug_info("simple", "process_incoming_message: no state found\n");
14070
72660065eb3e [gaim-migrate @ 16691]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14069
diff changeset
979 xmlnode_free(isc);
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
980 return;
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
981 }
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
982
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
983 statedata = xmlnode_get_data(state);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
984 if(statedata) {
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
985 if(strstr(statedata, "active")) serv_got_typing(sip->gc, from, 0, GAIM_TYPING);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
986 else serv_got_typing_stopped(sip->gc, from);
14069
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
987
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
988 g_free(statedata);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
989 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
990 xmlnode_free(isc);
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
991 send_sip_response(sip->gc, msg, 200, "OK", NULL);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
992 found = TRUE;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
993 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
994 if(!found) {
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
995 gaim_debug_info("simple", "got unknown mime-type");
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
996 send_sip_response(sip->gc, msg, 415, "Unsupported media type", NULL);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
997 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
998 g_free(from);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
999 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1000
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1001
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1002 gboolean process_register_response(struct simple_account_data *sip, struct sipmsg *msg, struct transaction *tc) {
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1003 gchar *tmp;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1004 gaim_debug(GAIM_DEBUG_MISC, "simple", "in process register response response: %d\n", msg->response);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1005 switch (msg->response) {
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1006 case 200:
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
1007 if(sip->registerstatus < 3) { /* registered */
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
1008 if(gaim_account_get_bool(sip->account, "dopublish", TRUE)) {
11345
03d9507f05a9 [gaim-migrate @ 13562]
Thomas Butter <tbutter>
parents: 11341
diff changeset
1009 send_publish(sip);
03d9507f05a9 [gaim-migrate @ 13562]
Thomas Butter <tbutter>
parents: 11341
diff changeset
1010 }
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1011 }
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
1012 sip->registerstatus = 3;
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1013 gaim_connection_set_state(sip->gc, GAIM_CONNECTED);
11341
3f0fda678686 [gaim-migrate @ 13555]
Thomas Butter <tbutter>
parents: 11327
diff changeset
1014
3f0fda678686 [gaim-migrate @ 13555]
Thomas Butter <tbutter>
parents: 11327
diff changeset
1015 /* get buddies from blist */
3f0fda678686 [gaim-migrate @ 13555]
Thomas Butter <tbutter>
parents: 11327
diff changeset
1016 simple_get_buddies(sip->gc);
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
1017
12768
3f6f2d59bcb4 [gaim-migrate @ 15115]
Thomas Butter <tbutter>
parents: 12767
diff changeset
1018 subscribe_timeout(sip);
13347
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
1019 tmp = sipmsg_find_header(msg, "Allow-Events");
14069
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
1020 if(tmp && strstr(tmp, "vnd-microsoft-provisioning")){
13347
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
1021 simple_subscribe_buddylist(sip);
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
1022 }
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
1023
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1024 break;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1025 case 401:
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
1026 if(sip->registerstatus != 2) {
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
1027 gaim_debug_info("simple", "REGISTER retries %d\n", sip->registrar.retries);
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
1028 if(sip->registrar.retries > 3) {
13678
299536c4caf1 [gaim-migrate @ 16080]
Mark Doliner <mark@kingant.net>
parents: 13656
diff changeset
1029 sip->gc->wants_to_die = TRUE;
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
1030 gaim_connection_error(sip->gc, _("Wrong Password"));
11346
e40318d2bcd8 [gaim-migrate @ 13563]
Thomas Butter <tbutter>
parents: 11345
diff changeset
1031 return TRUE;
e40318d2bcd8 [gaim-migrate @ 13563]
Thomas Butter <tbutter>
parents: 11345
diff changeset
1032 }
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1033 tmp = sipmsg_find_header(msg, "WWW-Authenticate");
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1034 fill_auth(sip, tmp, &sip->registrar);
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
1035 sip->registerstatus = 2;
11194
4c1f45ac00e9 [gaim-migrate @ 13317]
Thomas Butter <tbutter>
parents: 11192
diff changeset
1036 do_register(sip);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1037 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1038 break;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1039 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1040 return TRUE;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1041 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1042
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1043 static void process_incoming_notify(struct simple_account_data *sip, struct sipmsg *msg) {
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1044 gchar *from;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1045 gchar *fromhdr;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1046 gchar *tmp2;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1047 xmlnode *pidf;
14070
72660065eb3e [gaim-migrate @ 16691]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14069
diff changeset
1048 xmlnode *basicstatus = NULL, *tuple, *status;
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1049 gboolean isonline = FALSE;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1050
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
1051 fromhdr = sipmsg_find_header(msg, "From");
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1052 from = parse_from(fromhdr);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1053 if(!from) return;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1054
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1055 pidf = xmlnode_from_str(msg->body, msg->bodylen);
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
1056
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1057 if(!pidf) {
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
1058 gaim_debug_info("simple", "process_incoming_notify: no parseable pidf\n");
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1059 return;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1060 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1061
14070
72660065eb3e [gaim-migrate @ 16691]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14069
diff changeset
1062 if ((tuple = xmlnode_get_child(pidf, "tuple")))
72660065eb3e [gaim-migrate @ 16691]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14069
diff changeset
1063 if ((status = xmlnode_get_child(tuple, "status")))
72660065eb3e [gaim-migrate @ 16691]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14069
diff changeset
1064 basicstatus = xmlnode_get_child(status, "basic");
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1065
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1066 if(!basicstatus) {
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
1067 gaim_debug_info("simple", "process_incoming_notify: no basic found\n");
14070
72660065eb3e [gaim-migrate @ 16691]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14069
diff changeset
1068 xmlnode_free(pidf);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1069 return;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1070 }
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
1071
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1072 tmp2 = xmlnode_get_data(basicstatus);
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
1073
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1074 if(!tmp2) {
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
1075 gaim_debug_info("simple", "process_incoming_notify: no basic data found\n");
14070
72660065eb3e [gaim-migrate @ 16691]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14069
diff changeset
1076 xmlnode_free(pidf);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1077 return;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1078 }
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
1079
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1080 if(strstr(tmp2, "open")) {
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1081 isonline = TRUE;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1082 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1083
14069
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
1084 g_free(tmp2);
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
1085
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1086 if(isonline) gaim_prpl_got_user_status(sip->account, from, "available", NULL);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1087 else gaim_prpl_got_user_status(sip->account, from, "offline", NULL);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1088
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1089 xmlnode_free(pidf);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1090
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
1091 g_free(from);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1092 send_sip_response(sip->gc, msg, 200, "OK", NULL);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1093 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1094
13842
a9ff4499d9ce [gaim-migrate @ 16295]
Mark Doliner <mark@kingant.net>
parents: 13749
diff changeset
1095 static unsigned int simple_typing(GaimConnection *gc, const char *name, GaimTypingState state) {
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1096 struct simple_account_data *sip = gc->proto_data;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1097
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1098 gchar *xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1099 "<isComposing xmlns=\"urn:ietf:params:xml:ns:im-iscomposing\"\n"
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1100 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1101 "xsi:schemaLocation=\"urn:ietf:params:xml:ns:im-composing iscomposing.xsd\">\n"
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1102 "<state>%s</state>\n"
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1103 "<contenttype>text/plain</contenttype>\n"
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1104 "<refresh>60</refresh>\n"
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1105 "</isComposing>";
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1106 gchar *recv = g_strdup(name);
13842
a9ff4499d9ce [gaim-migrate @ 16295]
Mark Doliner <mark@kingant.net>
parents: 13749
diff changeset
1107 if(state == GAIM_TYPING) {
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1108 gchar *msg = g_strdup_printf(xml, "active");
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1109 simple_send_message(sip, recv, msg, "application/im-iscomposing+xml");
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1110 g_free(msg);
13842
a9ff4499d9ce [gaim-migrate @ 16295]
Mark Doliner <mark@kingant.net>
parents: 13749
diff changeset
1111 } else /* TODO: Only if (state == GAIM_TYPED) ? */ {
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1112 gchar *msg = g_strdup_printf(xml, "idle");
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1113 simple_send_message(sip, recv, msg, "application/im-iscomposing+xml");
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1114 g_free(msg);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1115 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1116 g_free(recv);
13842
a9ff4499d9ce [gaim-migrate @ 16295]
Mark Doliner <mark@kingant.net>
parents: 13749
diff changeset
1117 /*
a9ff4499d9ce [gaim-migrate @ 16295]
Mark Doliner <mark@kingant.net>
parents: 13749
diff changeset
1118 * TODO: Is this right? It will cause the core to call
a9ff4499d9ce [gaim-migrate @ 16295]
Mark Doliner <mark@kingant.net>
parents: 13749
diff changeset
1119 * serv_send_typing(gc, who, GAIM_TYPING) once every second
a9ff4499d9ce [gaim-migrate @ 16295]
Mark Doliner <mark@kingant.net>
parents: 13749
diff changeset
1120 * until the user stops typing. If that's not desired,
a9ff4499d9ce [gaim-migrate @ 16295]
Mark Doliner <mark@kingant.net>
parents: 13749
diff changeset
1121 * then return 0 instead.
a9ff4499d9ce [gaim-migrate @ 16295]
Mark Doliner <mark@kingant.net>
parents: 13749
diff changeset
1122 */
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1123 return 1;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1124 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1125
14069
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
1126 static gchar *find_tag(const gchar *hdr) {
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
1127 const gchar *tmp = strstr(hdr, ";tag="), *tmp2;
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
1128
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1129 if(!tmp) return NULL;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1130 tmp += 5;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1131 if((tmp2 = strchr(tmp, ';'))) {
14069
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
1132 return g_strndup(tmp, tmp2 - tmp);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1133 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1134 return g_strdup(tmp);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1135 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1136
13177
891be2f09b5c [gaim-migrate @ 15540]
Thomas Butter <tbutter>
parents: 13129
diff changeset
1137 static gchar* gen_xpidf(struct simple_account_data *sip) {
891be2f09b5c [gaim-migrate @ 15540]
Thomas Butter <tbutter>
parents: 13129
diff changeset
1138 gchar *doc = g_strdup_printf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
891be2f09b5c [gaim-migrate @ 15540]
Thomas Butter <tbutter>
parents: 13129
diff changeset
1139 "<presence>\n"
891be2f09b5c [gaim-migrate @ 15540]
Thomas Butter <tbutter>
parents: 13129
diff changeset
1140 "<presentity uri=\"sip:%s@%s;method=SUBSCRIBE\"/>\n"
891be2f09b5c [gaim-migrate @ 15540]
Thomas Butter <tbutter>
parents: 13129
diff changeset
1141 "<display name=\"sip:%s@%s\"/>\n"
891be2f09b5c [gaim-migrate @ 15540]
Thomas Butter <tbutter>
parents: 13129
diff changeset
1142 "<atom id=\"1234\">\n"
891be2f09b5c [gaim-migrate @ 15540]
Thomas Butter <tbutter>
parents: 13129
diff changeset
1143 "<address uri=\"sip:%s@%s\">\n"
891be2f09b5c [gaim-migrate @ 15540]
Thomas Butter <tbutter>
parents: 13129
diff changeset
1144 "<status status=\"%s\"/>\n"
891be2f09b5c [gaim-migrate @ 15540]
Thomas Butter <tbutter>
parents: 13129
diff changeset
1145 "</address>\n"
891be2f09b5c [gaim-migrate @ 15540]
Thomas Butter <tbutter>
parents: 13129
diff changeset
1146 "</atom>\n"
891be2f09b5c [gaim-migrate @ 15540]
Thomas Butter <tbutter>
parents: 13129
diff changeset
1147 "</presence>\n",
891be2f09b5c [gaim-migrate @ 15540]
Thomas Butter <tbutter>
parents: 13129
diff changeset
1148 sip->username,
891be2f09b5c [gaim-migrate @ 15540]
Thomas Butter <tbutter>
parents: 13129
diff changeset
1149 sip->servername,
891be2f09b5c [gaim-migrate @ 15540]
Thomas Butter <tbutter>
parents: 13129
diff changeset
1150 sip->username,
891be2f09b5c [gaim-migrate @ 15540]
Thomas Butter <tbutter>
parents: 13129
diff changeset
1151 sip->servername,
891be2f09b5c [gaim-migrate @ 15540]
Thomas Butter <tbutter>
parents: 13129
diff changeset
1152 sip->username,
891be2f09b5c [gaim-migrate @ 15540]
Thomas Butter <tbutter>
parents: 13129
diff changeset
1153 sip->servername,
891be2f09b5c [gaim-migrate @ 15540]
Thomas Butter <tbutter>
parents: 13129
diff changeset
1154 sip->status);
891be2f09b5c [gaim-migrate @ 15540]
Thomas Butter <tbutter>
parents: 13129
diff changeset
1155 return doc;
891be2f09b5c [gaim-migrate @ 15540]
Thomas Butter <tbutter>
parents: 13129
diff changeset
1156 }
891be2f09b5c [gaim-migrate @ 15540]
Thomas Butter <tbutter>
parents: 13129
diff changeset
1157
891be2f09b5c [gaim-migrate @ 15540]
Thomas Butter <tbutter>
parents: 13129
diff changeset
1158
891be2f09b5c [gaim-migrate @ 15540]
Thomas Butter <tbutter>
parents: 13129
diff changeset
1159
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1160 static gchar* gen_pidf(struct simple_account_data *sip) {
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1161 gchar *doc = g_strdup_printf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
1162 "<presence xmlns=\"urn:ietf:params:xml:ns:pidf\"\n"
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
1163 "xmlns:im=\"urn:ietf:params:xml:ns:pidf:im\"\n"
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
1164 "entity=\"sip:%s@%s\">\n"
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
1165 "<tuple id=\"bs35r9f\">\n"
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1166 "<status>\n"
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1167 "<basic>open</basic>\n"
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1168 "</status>\n"
13655
bbab6b311195 [gaim-migrate @ 16057]
Thomas Butter <tbutter>
parents: 13580
diff changeset
1169 "<note>%s</note>\n"
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1170 "</tuple>\n"
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1171 "</presence>",
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1172 sip->username,
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1173 sip->servername,
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1174 sip->status);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1175 return doc;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1176 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1177
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1178 static void send_notify(struct simple_account_data *sip, struct simple_watcher *watcher) {
13177
891be2f09b5c [gaim-migrate @ 15540]
Thomas Butter <tbutter>
parents: 13129
diff changeset
1179 gchar *doc = watcher->needsxpidf ? gen_xpidf(sip) : gen_pidf(sip);
891be2f09b5c [gaim-migrate @ 15540]
Thomas Butter <tbutter>
parents: 13129
diff changeset
1180 gchar *hdr = watcher->needsxpidf ? "Event: presence\r\nContent-Type: application/xpidf+xml\r\n" : "Event: presence\r\nContent-Type: application/pidf+xml\r\n";
891be2f09b5c [gaim-migrate @ 15540]
Thomas Butter <tbutter>
parents: 13129
diff changeset
1181 send_sip_request(sip->gc, "NOTIFY", watcher->name, watcher->name, hdr, doc, &watcher->dialog, NULL);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1182 g_free(doc);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1183 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1184
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1185 static gboolean process_publish_response(struct simple_account_data *sip, struct sipmsg *msg, struct transaction *tc) {
11345
03d9507f05a9 [gaim-migrate @ 13562]
Thomas Butter <tbutter>
parents: 11341
diff changeset
1186 if(msg->response != 200 && msg->response != 408) {
11341
3f0fda678686 [gaim-migrate @ 13555]
Thomas Butter <tbutter>
parents: 11327
diff changeset
1187 /* never send again */
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1188 sip->republish = -1;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1189 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1190 return TRUE;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1191 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1192
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1193 static void send_publish(struct simple_account_data *sip) {
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1194 gchar *uri = g_strdup_printf("sip:%s@%s", sip->username, sip->servername);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1195 gchar *doc = gen_pidf(sip);
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
1196 send_sip_request(sip->gc, "PUBLISH", uri, uri,
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
1197 "Expires: 600\r\nEvent: presence\r\n"
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
1198 "Content-Type: application/pidf+xml\r\n",
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
1199 doc, NULL, process_publish_response);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1200 sip->republish = time(NULL) + 500;
14069
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
1201 g_free(uri);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1202 g_free(doc);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1203 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1204
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1205 static void process_incoming_subscribe(struct simple_account_data *sip, struct sipmsg *msg) {
14069
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
1206 const char *from_hdr = sipmsg_find_header(msg, "From");
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
1207 gchar *from = parse_from(from_hdr);
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
1208 gchar *theirtag = find_tag(from_hdr);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1209 gchar *ourtag = find_tag(sipmsg_find_header(msg, "To"));
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1210 gboolean tagadded = FALSE;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1211 gchar *callid = sipmsg_find_header(msg, "Call-ID");
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1212 gchar *expire = sipmsg_find_header(msg, "Expire");
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1213 gchar *tmp;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1214 struct simple_watcher *watcher = watcher_find(sip, from);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1215 if(!ourtag) {
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1216 tagadded = TRUE;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1217 ourtag = gentag();
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1218 }
11341
3f0fda678686 [gaim-migrate @ 13555]
Thomas Butter <tbutter>
parents: 11327
diff changeset
1219 if(!watcher) { /* new subscription */
13177
891be2f09b5c [gaim-migrate @ 15540]
Thomas Butter <tbutter>
parents: 13129
diff changeset
1220 gchar *acceptheader = sipmsg_find_header(msg, "Accept");
14069
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
1221 gboolean needsxpidf = FALSE;
11345
03d9507f05a9 [gaim-migrate @ 13562]
Thomas Butter <tbutter>
parents: 11341
diff changeset
1222 if(!gaim_privacy_check(sip->account, from)) {
03d9507f05a9 [gaim-migrate @ 13562]
Thomas Butter <tbutter>
parents: 11341
diff changeset
1223 send_sip_response(sip->gc, msg, 202, "Ok", NULL);
03d9507f05a9 [gaim-migrate @ 13562]
Thomas Butter <tbutter>
parents: 11341
diff changeset
1224 goto privend;
03d9507f05a9 [gaim-migrate @ 13562]
Thomas Butter <tbutter>
parents: 11341
diff changeset
1225 }
13177
891be2f09b5c [gaim-migrate @ 15540]
Thomas Butter <tbutter>
parents: 13129
diff changeset
1226 if(acceptheader) {
891be2f09b5c [gaim-migrate @ 15540]
Thomas Butter <tbutter>
parents: 13129
diff changeset
1227 gchar *tmp = acceptheader;
14070
72660065eb3e [gaim-migrate @ 16691]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14069
diff changeset
1228 gboolean foundpidf = FALSE;
72660065eb3e [gaim-migrate @ 16691]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14069
diff changeset
1229 gboolean foundxpidf = FALSE;
13177
891be2f09b5c [gaim-migrate @ 15540]
Thomas Butter <tbutter>
parents: 13129
diff changeset
1230 while(tmp && tmp < acceptheader + strlen(acceptheader)) {
891be2f09b5c [gaim-migrate @ 15540]
Thomas Butter <tbutter>
parents: 13129
diff changeset
1231 gchar *tmp2 = strchr(tmp, ',');
891be2f09b5c [gaim-migrate @ 15540]
Thomas Butter <tbutter>
parents: 13129
diff changeset
1232 if(tmp2) *tmp2 = '\0';
14069
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
1233 if(!strcmp("application/pidf+xml", tmp))
14070
72660065eb3e [gaim-migrate @ 16691]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14069
diff changeset
1234 foundpidf = TRUE;
14069
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
1235 if(!strcmp("application/xpidf+xml", tmp))
14070
72660065eb3e [gaim-migrate @ 16691]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 14069
diff changeset
1236 foundxpidf = TRUE;
13177
891be2f09b5c [gaim-migrate @ 15540]
Thomas Butter <tbutter>
parents: 13129
diff changeset
1237 if(tmp2) {
891be2f09b5c [gaim-migrate @ 15540]
Thomas Butter <tbutter>
parents: 13129
diff changeset
1238 *tmp2 = ',';
891be2f09b5c [gaim-migrate @ 15540]
Thomas Butter <tbutter>
parents: 13129
diff changeset
1239 tmp = tmp2;
891be2f09b5c [gaim-migrate @ 15540]
Thomas Butter <tbutter>
parents: 13129
diff changeset
1240 while(*tmp == ' ') tmp++;
891be2f09b5c [gaim-migrate @ 15540]
Thomas Butter <tbutter>
parents: 13129
diff changeset
1241 } else
891be2f09b5c [gaim-migrate @ 15540]
Thomas Butter <tbutter>
parents: 13129
diff changeset
1242 tmp = 0;
891be2f09b5c [gaim-migrate @ 15540]
Thomas Butter <tbutter>
parents: 13129
diff changeset
1243 }
14069
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
1244 if(!foundpidf && foundxpidf) needsxpidf = TRUE;
13177
891be2f09b5c [gaim-migrate @ 15540]
Thomas Butter <tbutter>
parents: 13129
diff changeset
1245 g_free(acceptheader);
891be2f09b5c [gaim-migrate @ 15540]
Thomas Butter <tbutter>
parents: 13129
diff changeset
1246 }
891be2f09b5c [gaim-migrate @ 15540]
Thomas Butter <tbutter>
parents: 13129
diff changeset
1247 watcher = watcher_create(sip, from, callid, ourtag, theirtag, needsxpidf);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1248 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1249 if(tagadded) {
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1250 gchar *to = g_strdup_printf("%s;tag=%s", sipmsg_find_header(msg, "To"), ourtag);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1251 sipmsg_remove_header(msg, "To");
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1252 sipmsg_add_header(msg, "To", to);
14069
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
1253 g_free(to);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1254 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1255 if(expire)
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1256 watcher->expire = time(NULL) + strtol(expire, NULL, 10);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1257 else
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1258 watcher->expire = time(NULL) + 600;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1259 sipmsg_remove_header(msg, "Contact");
13177
891be2f09b5c [gaim-migrate @ 15540]
Thomas Butter <tbutter>
parents: 13129
diff changeset
1260 tmp = get_contact(sip);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1261 sipmsg_add_header(msg, "Contact", tmp);
13177
891be2f09b5c [gaim-migrate @ 15540]
Thomas Butter <tbutter>
parents: 13129
diff changeset
1262 g_free(tmp);
14069
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
1263 gaim_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
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1264 send_sip_response(sip->gc, msg, 200, "Ok", NULL);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1265 send_notify(sip, watcher);
11345
03d9507f05a9 [gaim-migrate @ 13562]
Thomas Butter <tbutter>
parents: 11341
diff changeset
1266 privend:
03d9507f05a9 [gaim-migrate @ 13562]
Thomas Butter <tbutter>
parents: 11341
diff changeset
1267 g_free(from);
03d9507f05a9 [gaim-migrate @ 13562]
Thomas Butter <tbutter>
parents: 11341
diff changeset
1268 g_free(theirtag);
03d9507f05a9 [gaim-migrate @ 13562]
Thomas Butter <tbutter>
parents: 11341
diff changeset
1269 g_free(ourtag);
03d9507f05a9 [gaim-migrate @ 13562]
Thomas Butter <tbutter>
parents: 11341
diff changeset
1270 g_free(callid);
03d9507f05a9 [gaim-migrate @ 13562]
Thomas Butter <tbutter>
parents: 11341
diff changeset
1271 g_free(expire);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1272 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1273
11189
5f79dfde334c [gaim-migrate @ 13307]
Thomas Butter <tbutter>
parents: 11181
diff changeset
1274 static void process_input_message(struct simple_account_data *sip, struct sipmsg *msg) {
12745
e788741f4840 [gaim-migrate @ 15092]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12741
diff changeset
1275 gboolean found = FALSE;
e788741f4840 [gaim-migrate @ 15092]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12741
diff changeset
1276 if(msg->response == 0) { /* request */
11189
5f79dfde334c [gaim-migrate @ 13307]
Thomas Butter <tbutter>
parents: 11181
diff changeset
1277 if(!strcmp(msg->method, "MESSAGE")) {
5f79dfde334c [gaim-migrate @ 13307]
Thomas Butter <tbutter>
parents: 11181
diff changeset
1278 process_incoming_message(sip, msg);
12745
e788741f4840 [gaim-migrate @ 15092]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12741
diff changeset
1279 found = TRUE;
e788741f4840 [gaim-migrate @ 15092]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12741
diff changeset
1280 } else if(!strcmp(msg->method, "NOTIFY")) {
11189
5f79dfde334c [gaim-migrate @ 13307]
Thomas Butter <tbutter>
parents: 11181
diff changeset
1281 process_incoming_notify(sip, msg);
12745
e788741f4840 [gaim-migrate @ 15092]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12741
diff changeset
1282 found = TRUE;
e788741f4840 [gaim-migrate @ 15092]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12741
diff changeset
1283 } else if(!strcmp(msg->method, "SUBSCRIBE")) {
11189
5f79dfde334c [gaim-migrate @ 13307]
Thomas Butter <tbutter>
parents: 11181
diff changeset
1284 process_incoming_subscribe(sip, msg);
12745
e788741f4840 [gaim-migrate @ 15092]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12741
diff changeset
1285 found = TRUE;
e788741f4840 [gaim-migrate @ 15092]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12741
diff changeset
1286 } else {
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
1287 send_sip_response(sip->gc, msg, 501, "Not implemented", NULL);
11190
fde0f4c1348d [gaim-migrate @ 13308]
Thomas Butter <tbutter>
parents: 11189
diff changeset
1288 }
11341
3f0fda678686 [gaim-migrate @ 13555]
Thomas Butter <tbutter>
parents: 11327
diff changeset
1289 } else { /* response */
11189
5f79dfde334c [gaim-migrate @ 13307]
Thomas Butter <tbutter>
parents: 11181
diff changeset
1290 struct transaction *trans = transactions_find(sip, msg);
5f79dfde334c [gaim-migrate @ 13307]
Thomas Butter <tbutter>
parents: 11181
diff changeset
1291 if(trans) {
5f79dfde334c [gaim-migrate @ 13307]
Thomas Butter <tbutter>
parents: 11181
diff changeset
1292 if(msg->response == 407) {
11439
617e67e1c985 [gaim-migrate @ 13676]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11424
diff changeset
1293 gchar *resend, *auth, *ptmp;
617e67e1c985 [gaim-migrate @ 13676]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11424
diff changeset
1294
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
1295 if(sip->proxy.retries > 3) return;
11346
e40318d2bcd8 [gaim-migrate @ 13563]
Thomas Butter <tbutter>
parents: 11345
diff changeset
1296 sip->proxy.retries++;
11341
3f0fda678686 [gaim-migrate @ 13555]
Thomas Butter <tbutter>
parents: 11327
diff changeset
1297 /* do proxy authentication */
11189
5f79dfde334c [gaim-migrate @ 13307]
Thomas Butter <tbutter>
parents: 11181
diff changeset
1298
11439
617e67e1c985 [gaim-migrate @ 13676]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11424
diff changeset
1299 ptmp = sipmsg_find_header(msg, "Proxy-Authenticate");
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
1300
11189
5f79dfde334c [gaim-migrate @ 13307]
Thomas Butter <tbutter>
parents: 11181
diff changeset
1301 fill_auth(sip, ptmp, &sip->proxy);
11346
e40318d2bcd8 [gaim-migrate @ 13563]
Thomas Butter <tbutter>
parents: 11345
diff changeset
1302 auth = auth_header(sip, &sip->proxy, trans->msg->method, trans->msg->target);
13272
0bfc9b72b9ce [gaim-migrate @ 15638]
Thomas Butter <tbutter>
parents: 13200
diff changeset
1303 sipmsg_remove_header(trans->msg, "Proxy-Authorization");
11189
5f79dfde334c [gaim-migrate @ 13307]
Thomas Butter <tbutter>
parents: 11181
diff changeset
1304 sipmsg_add_header(trans->msg, "Proxy-Authorization", auth);
5f79dfde334c [gaim-migrate @ 13307]
Thomas Butter <tbutter>
parents: 11181
diff changeset
1305 g_free(auth);
5f79dfde334c [gaim-migrate @ 13307]
Thomas Butter <tbutter>
parents: 11181
diff changeset
1306 resend = sipmsg_to_string(trans->msg);
11341
3f0fda678686 [gaim-migrate @ 13555]
Thomas Butter <tbutter>
parents: 11327
diff changeset
1307 /* resend request */
11189
5f79dfde334c [gaim-migrate @ 13307]
Thomas Butter <tbutter>
parents: 11181
diff changeset
1308 sendout_pkt(sip->gc, resend);
5f79dfde334c [gaim-migrate @ 13307]
Thomas Butter <tbutter>
parents: 11181
diff changeset
1309 g_free(resend);
5f79dfde334c [gaim-migrate @ 13307]
Thomas Butter <tbutter>
parents: 11181
diff changeset
1310 } else {
11517
d37a45a53106 [gaim-migrate @ 13762]
Thomas Butter <tbutter>
parents: 11483
diff changeset
1311 if(msg->response == 100) {
d37a45a53106 [gaim-migrate @ 13762]
Thomas Butter <tbutter>
parents: 11483
diff changeset
1312 /* ignore provisional response */
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
1313 gaim_debug_info("simple", "got trying response\n");
11517
d37a45a53106 [gaim-migrate @ 13762]
Thomas Butter <tbutter>
parents: 11483
diff changeset
1314 } else {
d37a45a53106 [gaim-migrate @ 13762]
Thomas Butter <tbutter>
parents: 11483
diff changeset
1315 sip->proxy.retries = 0;
14069
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
1316 if(!strcmp(trans->msg->method, "REGISTER")) {
13347
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
1317 if(msg->response == 401) sip->registrar.retries++;
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
1318 else sip->registrar.retries = 0;
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
1319 } else {
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
1320 if(msg->response == 401) {
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
1321 gchar *resend, *auth, *ptmp;
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
1322
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
1323 if(sip->registrar.retries > 4) return;
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
1324 sip->registrar.retries++;
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
1325
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
1326 ptmp = sipmsg_find_header(msg, "WWW-Authenticate");
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
1327
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
1328 fill_auth(sip, ptmp, &sip->registrar);
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
1329 auth = auth_header(sip, &sip->registrar, trans->msg->method, trans->msg->target);
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
1330 sipmsg_remove_header(trans->msg, "Authorization");
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
1331 sipmsg_add_header(trans->msg, "Authorization", auth);
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
1332 g_free(auth);
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
1333 resend = sipmsg_to_string(trans->msg);
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
1334 /* resend request */
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
1335 sendout_pkt(sip->gc, resend);
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
1336 g_free(resend);
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
1337 }
955a24d87729 [gaim-migrate @ 15717]
Thomas Butter <tbutter>
parents: 13296
diff changeset
1338 }
11517
d37a45a53106 [gaim-migrate @ 13762]
Thomas Butter <tbutter>
parents: 11483
diff changeset
1339 if(trans->callback) {
d37a45a53106 [gaim-migrate @ 13762]
Thomas Butter <tbutter>
parents: 11483
diff changeset
1340 /* call the callback to process response*/
d37a45a53106 [gaim-migrate @ 13762]
Thomas Butter <tbutter>
parents: 11483
diff changeset
1341 (trans->callback)(sip, msg, trans);
d37a45a53106 [gaim-migrate @ 13762]
Thomas Butter <tbutter>
parents: 11483
diff changeset
1342 }
d37a45a53106 [gaim-migrate @ 13762]
Thomas Butter <tbutter>
parents: 11483
diff changeset
1343 transactions_remove(sip, trans);
11189
5f79dfde334c [gaim-migrate @ 13307]
Thomas Butter <tbutter>
parents: 11181
diff changeset
1344 }
5f79dfde334c [gaim-migrate @ 13307]
Thomas Butter <tbutter>
parents: 11181
diff changeset
1345 }
12745
e788741f4840 [gaim-migrate @ 15092]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12741
diff changeset
1346 found = TRUE;
11189
5f79dfde334c [gaim-migrate @ 13307]
Thomas Butter <tbutter>
parents: 11181
diff changeset
1347 } else {
5f79dfde334c [gaim-migrate @ 13307]
Thomas Butter <tbutter>
parents: 11181
diff changeset
1348 gaim_debug(GAIM_DEBUG_MISC, "simple", "received response to unknown transaction");
5f79dfde334c [gaim-migrate @ 13307]
Thomas Butter <tbutter>
parents: 11181
diff changeset
1349 }
5f79dfde334c [gaim-migrate @ 13307]
Thomas Butter <tbutter>
parents: 11181
diff changeset
1350 }
5f79dfde334c [gaim-migrate @ 13307]
Thomas Butter <tbutter>
parents: 11181
diff changeset
1351 if(!found) {
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
1352 gaim_debug(GAIM_DEBUG_MISC, "simple", "received a unknown sip message with method %s and response %d\n", msg->method, msg->response);
11189
5f79dfde334c [gaim-migrate @ 13307]
Thomas Butter <tbutter>
parents: 11181
diff changeset
1353 }
5f79dfde334c [gaim-migrate @ 13307]
Thomas Butter <tbutter>
parents: 11181
diff changeset
1354 }
5f79dfde334c [gaim-migrate @ 13307]
Thomas Butter <tbutter>
parents: 11181
diff changeset
1355
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1356 static void process_input(struct simple_account_data *sip, struct sip_connection *conn)
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1357 {
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1358 char *cur;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1359 char *dummy;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1360 struct sipmsg *msg;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1361 int restlen;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1362 cur = conn->inbuf;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1363
11341
3f0fda678686 [gaim-migrate @ 13555]
Thomas Butter <tbutter>
parents: 11327
diff changeset
1364 /* according to the RFC remove CRLF at the beginning */
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1365 while(*cur == '\r' || *cur == '\n') {
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1366 cur++;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1367 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1368 if(cur != conn->inbuf) {
14069
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
1369 memmove(conn->inbuf, cur, conn->inbufused - (cur - conn->inbuf));
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
1370 conn->inbufused = strlen(conn->inbuf);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1371 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1372
11341
3f0fda678686 [gaim-migrate @ 13555]
Thomas Butter <tbutter>
parents: 11327
diff changeset
1373 /* Received a full Header? */
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
1374 if((cur = strstr(conn->inbuf, "\r\n\r\n")) != NULL) {
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1375 time_t currtime = time(NULL);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1376 cur += 2;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1377 cur[0] = '\0';
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
1378 gaim_debug_info("simple", "\n\nreceived - %s\n######\n%s\n#######\n\n", ctime(&currtime), conn->inbuf);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1379 msg = sipmsg_parse_header(conn->inbuf);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1380 cur[0] = '\r';
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1381 cur += 2;
14069
d594f0466585 [gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13981
diff changeset
1382 restlen = conn->inbufused - (cur - conn->inbuf);
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
1383 if(restlen >= msg->bodylen) {
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
1384 dummy = g_malloc(msg->bodylen + 1);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1385 memcpy(dummy, cur, msg->bodylen);
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
1386 dummy[msg->bodylen] = '\0';
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1387 msg->body = dummy;
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
1388 cur += msg->bodylen;
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
1389 memmove(conn->inbuf, cur, conn->inbuflen - (cur - conn->inbuf));
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
1390 conn->inbufused = strlen(conn->inbuf);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1391 } else {
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1392 sipmsg_free(msg);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1393 return;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1394 }
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
1395 gaim_debug(GAIM_DEBUG_MISC, "simple", "in process response response: %d\n", msg->response);
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
1396 process_input_message(sip, msg);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1397 } else {
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1398 gaim_debug(GAIM_DEBUG_MISC, "simple", "received a incomplete sip msg: %s\n", conn->inbuf);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1399 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1400 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1401
11189
5f79dfde334c [gaim-migrate @ 13307]
Thomas Butter <tbutter>
parents: 11181
diff changeset
1402 static void simple_udp_process(gpointer data, gint source, GaimInputCondition con) {
5f79dfde334c [gaim-migrate @ 13307]
Thomas Butter <tbutter>
parents: 11181
diff changeset
1403 GaimConnection *gc = data;
5f79dfde334c [gaim-migrate @ 13307]
Thomas Butter <tbutter>
parents: 11181
diff changeset
1404 struct simple_account_data *sip = gc->proto_data;
5f79dfde334c [gaim-migrate @ 13307]
Thomas Butter <tbutter>
parents: 11181
diff changeset
1405 struct sipmsg *msg;
5f79dfde334c [gaim-migrate @ 13307]
Thomas Butter <tbutter>
parents: 11181
diff changeset
1406 int len;
5f79dfde334c [gaim-migrate @ 13307]
Thomas Butter <tbutter>
parents: 11181
diff changeset
1407 time_t currtime;
5f79dfde334c [gaim-migrate @ 13307]
Thomas Butter <tbutter>
parents: 11181
diff changeset
1408
5f79dfde334c [gaim-migrate @ 13307]
Thomas Butter <tbutter>
parents: 11181
diff changeset
1409 static char buffer[65536];
12770
ab00cea25ef2 [gaim-migrate @ 15117]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12769
diff changeset
1410 if((len = recv(source, buffer, sizeof(buffer) - 1, 0)) > 0) {
12748
dd271caf25b0 [gaim-migrate @ 15095]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12746
diff changeset
1411 buffer[len] = '\0';
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
1412 gaim_debug_info("simple", "\n\nreceived - %s\n######\n%s\n#######\n\n", ctime(&currtime), buffer);
12748
dd271caf25b0 [gaim-migrate @ 15095]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12746
diff changeset
1413 msg = sipmsg_parse_msg(buffer);
dd271caf25b0 [gaim-migrate @ 15095]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12746
diff changeset
1414 if(msg) process_input_message(sip, msg);
dd271caf25b0 [gaim-migrate @ 15095]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12746
diff changeset
1415 }
11189
5f79dfde334c [gaim-migrate @ 13307]
Thomas Butter <tbutter>
parents: 11181
diff changeset
1416 }
5f79dfde334c [gaim-migrate @ 13307]
Thomas Butter <tbutter>
parents: 11181
diff changeset
1417
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1418 static void simple_input_cb(gpointer data, gint source, GaimInputCondition cond)
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1419 {
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1420 GaimConnection *gc = data;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1421 struct simple_account_data *sip = gc->proto_data;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1422 int len;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1423 struct sip_connection *conn = connection_find(sip, source);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1424 if(!conn) {
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1425 gaim_debug_error("simple", "Connection not found!\n");
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1426 return;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1427 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1428
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
1429 if(conn->inbuflen < conn->inbufused + SIMPLE_BUF_INC) {
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1430 conn->inbuflen += SIMPLE_BUF_INC;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1431 conn->inbuf = g_realloc(conn->inbuf, conn->inbuflen);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1432 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1433
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
1434 len = read(source, conn->inbuf + conn->inbufused, SIMPLE_BUF_INC - 1);
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
1435
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
1436 if(len < 0 && errno == EAGAIN)
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
1437 return;
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
1438 else if(len <= 0) {
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
1439 gaim_debug_info("simple", "simple_input_cb: read error\n");
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1440 connection_remove(sip, source);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1441 if(sip->fd == source) sip->fd = -1;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1442 return;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1443 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1444
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1445 conn->inbufused += len;
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
1446 conn->inbuf[conn->inbufused] = '\0';
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
1447
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1448 process_input(sip, conn);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1449 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1450
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1451 /* Callback for new connections on incoming TCP port */
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1452 static void simple_newconn_cb(gpointer data, gint source, GaimInputCondition cond) {
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1453 GaimConnection *gc = data;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1454 struct simple_account_data *sip = gc->proto_data;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1455 struct sip_connection *conn;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1456
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1457 int newfd = accept(source, NULL, NULL);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1458
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1459 conn = connection_create(sip, newfd);
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
1460
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1461 conn->inputhandler = gaim_input_add(newfd, GAIM_INPUT_READ, simple_input_cb, gc);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1462 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1463
14118
87ff682bdf5f [gaim-migrate @ 16752]
Mark Doliner <mark@kingant.net>
parents: 14108
diff changeset
1464 static void login_cb(gpointer data, gint source, const gchar *error_message) {
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1465 GaimConnection *gc = data;
14118
87ff682bdf5f [gaim-migrate @ 16752]
Mark Doliner <mark@kingant.net>
parents: 14108
diff changeset
1466 struct simple_account_data *sip;
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1467 struct sip_connection *conn;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1468
14118
87ff682bdf5f [gaim-migrate @ 16752]
Mark Doliner <mark@kingant.net>
parents: 14108
diff changeset
1469 if (!GAIM_CONNECTION_IS_VALID(gc))
87ff682bdf5f [gaim-migrate @ 16752]
Mark Doliner <mark@kingant.net>
parents: 14108
diff changeset
1470 {
87ff682bdf5f [gaim-migrate @ 16752]
Mark Doliner <mark@kingant.net>
parents: 14108
diff changeset
1471 if (source >= 0)
87ff682bdf5f [gaim-migrate @ 16752]
Mark Doliner <mark@kingant.net>
parents: 14108
diff changeset
1472 close(source);
87ff682bdf5f [gaim-migrate @ 16752]
Mark Doliner <mark@kingant.net>
parents: 14108
diff changeset
1473 return;
87ff682bdf5f [gaim-migrate @ 16752]
Mark Doliner <mark@kingant.net>
parents: 14108
diff changeset
1474 }
87ff682bdf5f [gaim-migrate @ 16752]
Mark Doliner <mark@kingant.net>
parents: 14108
diff changeset
1475
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
1476 if(source < 0) {
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
1477 gaim_connection_error(gc, _("Could not connect"));
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1478 return;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1479 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1480
14118
87ff682bdf5f [gaim-migrate @ 16752]
Mark Doliner <mark@kingant.net>
parents: 14108
diff changeset
1481 sip = gc->proto_data;
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1482 sip->fd = source;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1483
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
1484 conn = connection_create(sip, source);
13092
edef744647ff [gaim-migrate @ 15454]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13088
diff changeset
1485
12768
3f6f2d59bcb4 [gaim-migrate @ 15115]
Thomas Butter <tbutter>
parents: 12767
diff changeset
1486 sip->registertimeout = gaim_timeout_add((rand()%100)+10*1000, (GSourceFunc)subscribe_timeout, sip);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1487
11194
4c1f45ac00e9 [gaim-migrate @ 13317]
Thomas Butter <tbutter>
parents: 11192
diff changeset
1488 do_register(sip);
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
1489
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1490 conn->inputhandler = gaim_input_add(sip->fd, GAIM_INPUT_READ, simple_input_cb, gc);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1491 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1492
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1493 static guint simple_ht_hash_nick(const char *nick) {
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1494 char *lc = g_utf8_strdown(nick, -1);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1495 guint bucket = g_str_hash(lc);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1496 g_free(lc);
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
1497
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1498 return bucket;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1499 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1500
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1501 static gboolean simple_ht_equals_nick(const char *nick1, const char *nick2) {
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1502 return (gaim_utf8_strcasecmp(nick1, nick2) == 0);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1503 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1504
12909
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12770
diff changeset
1505 static void simple_udp_host_resolved_listen_cb(int listenfd, gpointer data) {
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12770
diff changeset
1506 struct simple_account_data *sip = (struct simple_account_data*) data;
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12770
diff changeset
1507
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12770
diff changeset
1508 if(listenfd == -1) {
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12770
diff changeset
1509 gaim_connection_error(sip->gc, _("Could not create listen socket"));
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12770
diff changeset
1510 return;
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12770
diff changeset
1511 }
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12770
diff changeset
1512
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12770
diff changeset
1513 sip->fd = listenfd;
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12770
diff changeset
1514
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12770
diff changeset
1515 sip->listenport = gaim_network_get_port_from_fd(sip->fd);
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12770
diff changeset
1516 sip->listenfd = sip->fd;
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12770
diff changeset
1517
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12770
diff changeset
1518 sip->listenpa = gaim_input_add(sip->fd, GAIM_INPUT_READ, simple_udp_process, sip->gc);
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12770
diff changeset
1519
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12770
diff changeset
1520 sip->resendtimeout = gaim_timeout_add(2500, (GSourceFunc) resend_timeout, sip);
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12770
diff changeset
1521 sip->registertimeout = gaim_timeout_add((rand()%100)+10*1000, (GSourceFunc)subscribe_timeout, sip);
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12770
diff changeset
1522 do_register(sip);
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12770
diff changeset
1523 }
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12770
diff changeset
1524
12767
53218d758ba9 [gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12760
diff changeset
1525 static void simple_udp_host_resolved(GSList *hosts, gpointer data, const char *error_message) {
53218d758ba9 [gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12760
diff changeset
1526 struct simple_account_data *sip = (struct simple_account_data*) data;
53218d758ba9 [gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12760
diff changeset
1527 int addr_size;
53218d758ba9 [gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12760
diff changeset
1528
53218d758ba9 [gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12760
diff changeset
1529 if (!hosts || !hosts->data) {
53218d758ba9 [gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12760
diff changeset
1530 gaim_connection_error(sip->gc, _("Couldn't resolve host"));
53218d758ba9 [gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12760
diff changeset
1531 return;
53218d758ba9 [gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12760
diff changeset
1532 }
53218d758ba9 [gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12760
diff changeset
1533
53218d758ba9 [gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12760
diff changeset
1534 addr_size = GPOINTER_TO_INT(hosts->data);
53218d758ba9 [gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12760
diff changeset
1535 hosts = g_slist_remove(hosts, hosts->data);
53218d758ba9 [gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12760
diff changeset
1536 memcpy(&(sip->serveraddr), hosts->data, addr_size);
53218d758ba9 [gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12760
diff changeset
1537 g_free(hosts->data);
53218d758ba9 [gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12760
diff changeset
1538 hosts = g_slist_remove(hosts, hosts->data);
53218d758ba9 [gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12760
diff changeset
1539 while(hosts) {
53218d758ba9 [gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12760
diff changeset
1540 hosts = g_slist_remove(hosts, hosts->data);
53218d758ba9 [gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12760
diff changeset
1541 g_free(hosts->data);
53218d758ba9 [gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12760
diff changeset
1542 hosts = g_slist_remove(hosts, hosts->data);
53218d758ba9 [gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12760
diff changeset
1543 }
53218d758ba9 [gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12760
diff changeset
1544
53218d758ba9 [gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12760
diff changeset
1545 /* create socket for incoming connections */
12909
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12770
diff changeset
1546 if(!gaim_network_listen_range(5060, 5160, SOCK_DGRAM,
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12770
diff changeset
1547 simple_udp_host_resolved_listen_cb, sip)) {
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12770
diff changeset
1548 gaim_connection_error(sip->gc, _("Could not create listen socket"));
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12770
diff changeset
1549 return;
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12770
diff changeset
1550 }
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12770
diff changeset
1551 }
12767
53218d758ba9 [gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12760
diff changeset
1552
12909
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12770
diff changeset
1553 static void
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12770
diff changeset
1554 simple_tcp_connect_listen_cb(int listenfd, gpointer data) {
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12770
diff changeset
1555 struct simple_account_data *sip = (struct simple_account_data*) data;
14089
10e8eb6a4910 [gaim-migrate @ 16712]
Mark Doliner <mark@kingant.net>
parents: 14070
diff changeset
1556 GaimProxyConnectInfo *connect_info;
12909
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12770
diff changeset
1557
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12770
diff changeset
1558 sip->listenfd = listenfd;
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12770
diff changeset
1559 if(sip->listenfd == -1) {
12767
53218d758ba9 [gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12760
diff changeset
1560 gaim_connection_error(sip->gc, _("Could not create listen socket"));
53218d758ba9 [gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12760
diff changeset
1561 return;
53218d758ba9 [gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12760
diff changeset
1562 }
53218d758ba9 [gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12760
diff changeset
1563
12909
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12770
diff changeset
1564 gaim_debug_info("simple", "listenfd: %d\n", sip->listenfd);
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12770
diff changeset
1565 sip->listenport = gaim_network_get_port_from_fd(sip->listenfd);
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12770
diff changeset
1566 sip->listenpa = gaim_input_add(sip->listenfd, GAIM_INPUT_READ,
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12770
diff changeset
1567 simple_newconn_cb, sip->gc);
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
1568 gaim_debug_info("simple", "connecting to %s port %d\n",
12909
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12770
diff changeset
1569 sip->realhostname, sip->realport);
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12770
diff changeset
1570 /* open tcp connection to the server */
14089
10e8eb6a4910 [gaim-migrate @ 16712]
Mark Doliner <mark@kingant.net>
parents: 14070
diff changeset
1571 connect_info = gaim_proxy_connect(sip->account, sip->realhostname,
14108
7a205b430d19 [gaim-migrate @ 16742]
Mark Doliner <mark@kingant.net>
parents: 14089
diff changeset
1572 sip->realport, login_cb, sip->gc);
14089
10e8eb6a4910 [gaim-migrate @ 16712]
Mark Doliner <mark@kingant.net>
parents: 14070
diff changeset
1573 if(connect_info == NULL) {
12909
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12770
diff changeset
1574 gaim_connection_error(sip->gc, _("Couldn't create socket"));
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12770
diff changeset
1575 }
12767
53218d758ba9 [gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12760
diff changeset
1576 }
53218d758ba9 [gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12760
diff changeset
1577
12686
5f65a0cca87c [gaim-migrate @ 15029]
Richard Laager <rlaager@wiktel.com>
parents: 12657
diff changeset
1578 static void srvresolved(GaimSrvResponse *resp, int results, gpointer data) {
13580
dc28bca6a7b5 [gaim-migrate @ 15962]
Mark Doliner <mark@kingant.net>
parents: 13398
diff changeset
1579 GaimConnection *gc;
dc28bca6a7b5 [gaim-migrate @ 15962]
Mark Doliner <mark@kingant.net>
parents: 13398
diff changeset
1580 struct simple_account_data *sip;
dc28bca6a7b5 [gaim-migrate @ 15962]
Mark Doliner <mark@kingant.net>
parents: 13398
diff changeset
1581 gchar *hostname;
dc28bca6a7b5 [gaim-migrate @ 15962]
Mark Doliner <mark@kingant.net>
parents: 13398
diff changeset
1582 int port;
11383
b4cf724b64f8 [gaim-migrate @ 13610]
Thomas Butter <tbutter>
parents: 11346
diff changeset
1583
13580
dc28bca6a7b5 [gaim-migrate @ 15962]
Mark Doliner <mark@kingant.net>
parents: 13398
diff changeset
1584 gc = data;
13981
91a4cc3ee221 [gaim-migrate @ 16548]
Mark Doliner <mark@kingant.net>
parents: 13842
diff changeset
1585 if (!GAIM_CONNECTION_IS_VALID(gc))
13580
dc28bca6a7b5 [gaim-migrate @ 15962]
Mark Doliner <mark@kingant.net>
parents: 13398
diff changeset
1586 {
dc28bca6a7b5 [gaim-migrate @ 15962]
Mark Doliner <mark@kingant.net>
parents: 13398
diff changeset
1587 /* This connection has been closed */
dc28bca6a7b5 [gaim-migrate @ 15962]
Mark Doliner <mark@kingant.net>
parents: 13398
diff changeset
1588 g_free(resp);
dc28bca6a7b5 [gaim-migrate @ 15962]
Mark Doliner <mark@kingant.net>
parents: 13398
diff changeset
1589 return;
dc28bca6a7b5 [gaim-migrate @ 15962]
Mark Doliner <mark@kingant.net>
parents: 13398
diff changeset
1590 }
dc28bca6a7b5 [gaim-migrate @ 15962]
Mark Doliner <mark@kingant.net>
parents: 13398
diff changeset
1591
dc28bca6a7b5 [gaim-migrate @ 15962]
Mark Doliner <mark@kingant.net>
parents: 13398
diff changeset
1592 sip = gc->proto_data;
dc28bca6a7b5 [gaim-migrate @ 15962]
Mark Doliner <mark@kingant.net>
parents: 13398
diff changeset
1593 port = gaim_account_get_int(sip->account, "port", 0);
11383
b4cf724b64f8 [gaim-migrate @ 13610]
Thomas Butter <tbutter>
parents: 11346
diff changeset
1594
b4cf724b64f8 [gaim-migrate @ 13610]
Thomas Butter <tbutter>
parents: 11346
diff changeset
1595 /* find the host to connect to */
b4cf724b64f8 [gaim-migrate @ 13610]
Thomas Butter <tbutter>
parents: 11346
diff changeset
1596 if(results) {
b4cf724b64f8 [gaim-migrate @ 13610]
Thomas Butter <tbutter>
parents: 11346
diff changeset
1597 hostname = g_strdup(resp->hostname);
12769
a90255f67652 [gaim-migrate @ 15116]
Thomas Butter <tbutter>
parents: 12768
diff changeset
1598 if(!port)
a90255f67652 [gaim-migrate @ 15116]
Thomas Butter <tbutter>
parents: 12768
diff changeset
1599 port = resp->port;
11383
b4cf724b64f8 [gaim-migrate @ 13610]
Thomas Butter <tbutter>
parents: 11346
diff changeset
1600 g_free(resp);
b4cf724b64f8 [gaim-migrate @ 13610]
Thomas Butter <tbutter>
parents: 11346
diff changeset
1601 } else {
b4cf724b64f8 [gaim-migrate @ 13610]
Thomas Butter <tbutter>
parents: 11346
diff changeset
1602 if(!gaim_account_get_bool(sip->account, "useproxy", FALSE)) {
b4cf724b64f8 [gaim-migrate @ 13610]
Thomas Butter <tbutter>
parents: 11346
diff changeset
1603 hostname = g_strdup(sip->servername);
b4cf724b64f8 [gaim-migrate @ 13610]
Thomas Butter <tbutter>
parents: 11346
diff changeset
1604 } else {
b4cf724b64f8 [gaim-migrate @ 13610]
Thomas Butter <tbutter>
parents: 11346
diff changeset
1605 hostname = g_strdup(gaim_account_get_string(sip->account, "proxy", sip->servername));
b4cf724b64f8 [gaim-migrate @ 13610]
Thomas Butter <tbutter>
parents: 11346
diff changeset
1606 }
b4cf724b64f8 [gaim-migrate @ 13610]
Thomas Butter <tbutter>
parents: 11346
diff changeset
1607 }
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
1608
11383
b4cf724b64f8 [gaim-migrate @ 13610]
Thomas Butter <tbutter>
parents: 11346
diff changeset
1609 sip->realhostname = hostname;
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
1610 sip->realport = port;
12769
a90255f67652 [gaim-migrate @ 15116]
Thomas Butter <tbutter>
parents: 12768
diff changeset
1611 if(!sip->realport) sip->realport = 5060;
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
1612
11383
b4cf724b64f8 [gaim-migrate @ 13610]
Thomas Butter <tbutter>
parents: 11346
diff changeset
1613 /* TCP case */
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
1614 if(!sip->udp) {
11409
1e495a5fcbbc [gaim-migrate @ 13646]
Thomas Butter <tbutter>
parents: 11396
diff changeset
1615 /* create socket for incoming connections */
12909
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12770
diff changeset
1616 if(!gaim_network_listen_range(5060, 5160, SOCK_STREAM,
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12770
diff changeset
1617 simple_tcp_connect_listen_cb, sip)) {
11409
1e495a5fcbbc [gaim-migrate @ 13646]
Thomas Butter <tbutter>
parents: 11396
diff changeset
1618 gaim_connection_error(sip->gc, _("Could not create listen socket"));
1e495a5fcbbc [gaim-migrate @ 13646]
Thomas Butter <tbutter>
parents: 11396
diff changeset
1619 return;
1e495a5fcbbc [gaim-migrate @ 13646]
Thomas Butter <tbutter>
parents: 11396
diff changeset
1620 }
11383
b4cf724b64f8 [gaim-migrate @ 13610]
Thomas Butter <tbutter>
parents: 11346
diff changeset
1621 } else { /* UDP */
b4cf724b64f8 [gaim-migrate @ 13610]
Thomas Butter <tbutter>
parents: 11346
diff changeset
1622 gaim_debug_info("simple", "using udp with server %s and port %d\n", hostname, port);
12565
3f895385e841 [gaim-migrate @ 14884]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12563
diff changeset
1623
12767
53218d758ba9 [gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12760
diff changeset
1624 gaim_gethostbyname_async(hostname, port, simple_udp_host_resolved, sip);
11383
b4cf724b64f8 [gaim-migrate @ 13610]
Thomas Butter <tbutter>
parents: 11346
diff changeset
1625 }
b4cf724b64f8 [gaim-migrate @ 13610]
Thomas Butter <tbutter>
parents: 11346
diff changeset
1626 }
b4cf724b64f8 [gaim-migrate @ 13610]
Thomas Butter <tbutter>
parents: 11346
diff changeset
1627
11837
fa742ad8068c [gaim-migrate @ 14128]
Mark Doliner <mark@kingant.net>
parents: 11718
diff changeset
1628 static void simple_login(GaimAccount *account)
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1629 {
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1630 GaimConnection *gc;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1631 struct simple_account_data *sip;
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1632 gchar **userserver;
11210
5ba038e1b21f [gaim-migrate @ 13341]
Thomas Butter <tbutter>
parents: 11194
diff changeset
1633 gchar *hosttoconnect;
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
1634
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1635 const char *username = gaim_account_get_username(account);
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
1636 gc = gaim_account_get_connection(account);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1637
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
1638 if (strpbrk(username, " \t\v\r\n") != NULL) {
13678
299536c4caf1 [gaim-migrate @ 16080]
Mark Doliner <mark@kingant.net>
parents: 13656
diff changeset
1639 gc->wants_to_die = TRUE;
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
1640 gaim_connection_error(gc, _("SIP usernames may not contain whitespaces or @ symbols"));
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
1641 return;
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
1642 }
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1643
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
1644 gc->proto_data = sip = g_new0(struct simple_account_data, 1);
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
1645 sip->gc = gc;
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
1646 sip->account = account;
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
1647 sip->registerexpire = 900;
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
1648 sip->udp = gaim_account_get_bool(account, "udp", FALSE);
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
1649 /* TODO: is there a good default grow size? */
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
1650 if(!sip->udp)
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
1651 sip->txbuf = gaim_circ_buffer_new(0);
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
1652
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1653 userserver = g_strsplit(username, "@", 2);
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
1654 gaim_connection_set_display_name(gc, userserver[0]);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1655 sip->username = g_strdup(userserver[0]);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1656 sip->servername = g_strdup(userserver[1]);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1657 sip->password = g_strdup(gaim_connection_get_password(gc));
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1658 g_strfreev(userserver);
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1659
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1660 sip->buddies = g_hash_table_new((GHashFunc)simple_ht_hash_nick, (GEqualFunc)simple_ht_equals_nick);
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
1661
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
1662 gaim_connection_update_progress(gc, _("Connecting"), 1, 2);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1663
11837
fa742ad8068c [gaim-migrate @ 14128]
Mark Doliner <mark@kingant.net>
parents: 11718
diff changeset
1664 /* TODO: Set the status correctly. */
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1665 sip->status = g_strdup("available");
11189
5f79dfde334c [gaim-migrate @ 13307]
Thomas Butter <tbutter>
parents: 11181
diff changeset
1666
11210
5ba038e1b21f [gaim-migrate @ 13341]
Thomas Butter <tbutter>
parents: 11194
diff changeset
1667 if(!gaim_account_get_bool(account, "useproxy", FALSE)) {
5ba038e1b21f [gaim-migrate @ 13341]
Thomas Butter <tbutter>
parents: 11194
diff changeset
1668 hosttoconnect = g_strdup(sip->servername);
5ba038e1b21f [gaim-migrate @ 13341]
Thomas Butter <tbutter>
parents: 11194
diff changeset
1669 } else {
5ba038e1b21f [gaim-migrate @ 13341]
Thomas Butter <tbutter>
parents: 11194
diff changeset
1670 hosttoconnect = g_strdup(gaim_account_get_string(account, "proxy", sip->servername));
5ba038e1b21f [gaim-migrate @ 13341]
Thomas Butter <tbutter>
parents: 11194
diff changeset
1671 }
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
1672
11341
3f0fda678686 [gaim-migrate @ 13555]
Thomas Butter <tbutter>
parents: 11327
diff changeset
1673 /* TCP case */
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
1674 if(!sip->udp) {
13580
dc28bca6a7b5 [gaim-migrate @ 15962]
Mark Doliner <mark@kingant.net>
parents: 13398
diff changeset
1675 gaim_srv_resolve("sip", "tcp", hosttoconnect, srvresolved, gc);
11341
3f0fda678686 [gaim-migrate @ 13555]
Thomas Butter <tbutter>
parents: 11327
diff changeset
1676 } else { /* UDP */
13580
dc28bca6a7b5 [gaim-migrate @ 15962]
Mark Doliner <mark@kingant.net>
parents: 13398
diff changeset
1677 gaim_srv_resolve("sip", "udp", hosttoconnect, srvresolved, gc);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1678 }
11210
5ba038e1b21f [gaim-migrate @ 13341]
Thomas Butter <tbutter>
parents: 11194
diff changeset
1679 g_free(hosttoconnect);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1680 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1681
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1682 static void simple_close(GaimConnection *gc)
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1683 {
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1684 struct simple_account_data *sip = gc->proto_data;
11194
4c1f45ac00e9 [gaim-migrate @ 13317]
Thomas Butter <tbutter>
parents: 11192
diff changeset
1685
11341
3f0fda678686 [gaim-migrate @ 13555]
Thomas Butter <tbutter>
parents: 11327
diff changeset
1686 if(sip) {
13398
bddf037063bd [gaim-migrate @ 15772]
Richard Laager <rlaager@wiktel.com>
parents: 13347
diff changeset
1687 /* unregister */
bddf037063bd [gaim-migrate @ 15772]
Richard Laager <rlaager@wiktel.com>
parents: 13347
diff changeset
1688 do_register_exp(sip, 0);
bddf037063bd [gaim-migrate @ 15772]
Richard Laager <rlaager@wiktel.com>
parents: 13347
diff changeset
1689 connection_free_all(sip);
bddf037063bd [gaim-migrate @ 15772]
Richard Laager <rlaager@wiktel.com>
parents: 13347
diff changeset
1690
11650
1f95b6308195 [gaim-migrate @ 13931]
Mark Doliner <mark@kingant.net>
parents: 11522
diff changeset
1691 g_free(sip->servername);
1f95b6308195 [gaim-migrate @ 13931]
Mark Doliner <mark@kingant.net>
parents: 11522
diff changeset
1692 g_free(sip->username);
1f95b6308195 [gaim-migrate @ 13931]
Mark Doliner <mark@kingant.net>
parents: 11522
diff changeset
1693 g_free(sip->password);
1f95b6308195 [gaim-migrate @ 13931]
Mark Doliner <mark@kingant.net>
parents: 11522
diff changeset
1694 g_free(sip->registrar.nonce);
13084
31a3a9af1494 [gaim-migrate @ 15446]
Thomas Butter <tbutter>
parents: 13083
diff changeset
1695 g_free(sip->registrar.opaque);
31a3a9af1494 [gaim-migrate @ 15446]
Thomas Butter <tbutter>
parents: 13083
diff changeset
1696 g_free(sip->registrar.target);
11650
1f95b6308195 [gaim-migrate @ 13931]
Mark Doliner <mark@kingant.net>
parents: 11522
diff changeset
1697 g_free(sip->registrar.realm);
13084
31a3a9af1494 [gaim-migrate @ 15446]
Thomas Butter <tbutter>
parents: 13083
diff changeset
1698 g_free(sip->registrar.digest_session_key);
11650
1f95b6308195 [gaim-migrate @ 13931]
Mark Doliner <mark@kingant.net>
parents: 11522
diff changeset
1699 g_free(sip->proxy.nonce);
13084
31a3a9af1494 [gaim-migrate @ 15446]
Thomas Butter <tbutter>
parents: 13083
diff changeset
1700 g_free(sip->proxy.opaque);
31a3a9af1494 [gaim-migrate @ 15446]
Thomas Butter <tbutter>
parents: 13083
diff changeset
1701 g_free(sip->proxy.target);
11650
1f95b6308195 [gaim-migrate @ 13931]
Mark Doliner <mark@kingant.net>
parents: 11522
diff changeset
1702 g_free(sip->proxy.realm);
13084
31a3a9af1494 [gaim-migrate @ 15446]
Thomas Butter <tbutter>
parents: 13083
diff changeset
1703 g_free(sip->proxy.digest_session_key);
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
1704 if(sip->txbuf)
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
1705 gaim_circ_buffer_destroy(sip->txbuf);
11650
1f95b6308195 [gaim-migrate @ 13931]
Mark Doliner <mark@kingant.net>
parents: 11522
diff changeset
1706 g_free(sip->realhostname);
11409
1e495a5fcbbc [gaim-migrate @ 13646]
Thomas Butter <tbutter>
parents: 11396
diff changeset
1707 if(sip->listenpa) gaim_input_remove(sip->listenpa);
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13184
diff changeset
1708 if(sip->tx_handler) gaim_input_remove(sip->tx_handler);
12571
2c73e08032a1 [gaim-migrate @ 14890]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12570
diff changeset
1709 if(sip->resendtimeout) gaim_timeout_remove(sip->resendtimeout);
11346
e40318d2bcd8 [gaim-migrate @ 13563]
Thomas Butter <tbutter>
parents: 11345
diff changeset
1710 if(sip->registertimeout) gaim_timeout_remove(sip->registertimeout);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1711 }
11650
1f95b6308195 [gaim-migrate @ 13931]
Mark Doliner <mark@kingant.net>
parents: 11522
diff changeset
1712 g_free(gc->proto_data);
12571
2c73e08032a1 [gaim-migrate @ 14890]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12570
diff changeset
1713 gc->proto_data = NULL;
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1714 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1715
11345
03d9507f05a9 [gaim-migrate @ 13562]
Thomas Butter <tbutter>
parents: 11341
diff changeset
1716 /* not needed since privacy is checked for every subscribe */
03d9507f05a9 [gaim-migrate @ 13562]
Thomas Butter <tbutter>
parents: 11341
diff changeset
1717 static void dummy_add_deny(GaimConnection *gc, const char *name) {
03d9507f05a9 [gaim-migrate @ 13562]
Thomas Butter <tbutter>
parents: 11341
diff changeset
1718 }
03d9507f05a9 [gaim-migrate @ 13562]
Thomas Butter <tbutter>
parents: 11341
diff changeset
1719
03d9507f05a9 [gaim-migrate @ 13562]
Thomas Butter <tbutter>
parents: 11341
diff changeset
1720 static void dummy_permit_deny(GaimConnection *gc) {
03d9507f05a9 [gaim-migrate @ 13562]
Thomas Butter <tbutter>
parents: 11341
diff changeset
1721 }
03d9507f05a9 [gaim-migrate @ 13562]
Thomas Butter <tbutter>
parents: 11341
diff changeset
1722
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1723 static GaimPluginProtocolInfo prpl_info =
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1724 {
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1725 0,
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1726 NULL, /* user_splits */
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1727 NULL, /* protocol_options */
12143
cbebda5f019c [gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents: 11837
diff changeset
1728 NO_BUDDY_ICONS, /* icon_spec */
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1729 simple_list_icon, /* list_icon */
12143
cbebda5f019c [gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents: 11837
diff changeset
1730 NULL, /* list_emblems */
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1731 NULL, /* status_text */
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1732 NULL, /* tooltip_text */
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1733 simple_status_types, /* away_states */
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1734 NULL, /* blist_node_menu */
12143
cbebda5f019c [gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents: 11837
diff changeset
1735 NULL, /* chat_info */
cbebda5f019c [gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents: 11837
diff changeset
1736 NULL, /* chat_info_defaults */
cbebda5f019c [gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents: 11837
diff changeset
1737 simple_login, /* login */
cbebda5f019c [gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents: 11837
diff changeset
1738 simple_close, /* close */
cbebda5f019c [gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents: 11837
diff changeset
1739 simple_im_send, /* send_im */
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1740 NULL, /* set_info */
12143
cbebda5f019c [gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents: 11837
diff changeset
1741 simple_typing, /* send_typing */
cbebda5f019c [gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents: 11837
diff changeset
1742 NULL, /* get_info */
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1743 simple_set_status, /* set_status */
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1744 NULL, /* set_idle */
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1745 NULL, /* change_passwd */
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1746 simple_add_buddy, /* add_buddy */
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1747 NULL, /* add_buddies */
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1748 simple_remove_buddy, /* remove_buddy */
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1749 NULL, /* remove_buddies */
12143
cbebda5f019c [gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents: 11837
diff changeset
1750 dummy_add_deny, /* add_permit */
cbebda5f019c [gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents: 11837
diff changeset
1751 dummy_add_deny, /* add_deny */
cbebda5f019c [gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents: 11837
diff changeset
1752 dummy_add_deny, /* rem_permit */
cbebda5f019c [gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents: 11837
diff changeset
1753 dummy_add_deny, /* rem_deny */
cbebda5f019c [gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents: 11837
diff changeset
1754 dummy_permit_deny, /* set_permit_deny */
cbebda5f019c [gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents: 11837
diff changeset
1755 NULL, /* join_chat */
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1756 NULL, /* reject_chat */
12143
cbebda5f019c [gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents: 11837
diff changeset
1757 NULL, /* get_chat_name */
cbebda5f019c [gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents: 11837
diff changeset
1758 NULL, /* chat_invite */
cbebda5f019c [gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents: 11837
diff changeset
1759 NULL, /* chat_leave */
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1760 NULL, /* chat_whisper */
12143
cbebda5f019c [gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents: 11837
diff changeset
1761 NULL, /* chat_send */
cbebda5f019c [gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents: 11837
diff changeset
1762 simple_keep_alive, /* keepalive */
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1763 NULL, /* register_user */
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1764 NULL, /* get_cb_info */
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1765 NULL, /* get_cb_away */
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1766 NULL, /* alias_buddy */
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1767 NULL, /* group_buddy */
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1768 NULL, /* rename_group */
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1769 NULL, /* buddy_free */
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1770 NULL, /* convo_closed */
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1771 NULL, /* normalize */
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1772 NULL, /* set_buddy_icon */
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1773 NULL, /* remove_group */
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1774 NULL, /* get_cb_real_name */
12143
cbebda5f019c [gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents: 11837
diff changeset
1775 NULL, /* set_chat_topic */
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1776 NULL, /* find_blist_chat */
12143
cbebda5f019c [gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents: 11837
diff changeset
1777 NULL, /* roomlist_get_list */
cbebda5f019c [gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents: 11837
diff changeset
1778 NULL, /* roomlist_cancel */
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1779 NULL, /* roomlist_expand_category */
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1780 NULL, /* can_receive_file */
12143
cbebda5f019c [gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents: 11837
diff changeset
1781 NULL, /* send_file */
12600
e856f985a0b9 [gaim-migrate @ 14934]
Richard Laager <rlaager@wiktel.com>
parents: 12595
diff changeset
1782 NULL, /* new_xfer */
12645
fc28451f5d96 [gaim-migrate @ 14983]
Richard Laager <rlaager@wiktel.com>
parents: 12600
diff changeset
1783 NULL, /* offline_message */
12600
e856f985a0b9 [gaim-migrate @ 14934]
Richard Laager <rlaager@wiktel.com>
parents: 12595
diff changeset
1784 NULL, /* whiteboard_prpl_ops */
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1785 };
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1786
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1787
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1788 static GaimPluginInfo info =
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1789 {
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1790 GAIM_PLUGIN_MAGIC,
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1791 GAIM_MAJOR_VERSION,
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1792 GAIM_MINOR_VERSION,
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1793 GAIM_PLUGIN_PROTOCOL, /**< type */
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1794 NULL, /**< ui_requirement */
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1795 0, /**< flags */
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1796 NULL, /**< dependencies */
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1797 GAIM_PRIORITY_DEFAULT, /**< priority */
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1798
12489
12db50600de5 [gaim-migrate @ 14801]
Mark Doliner <mark@kingant.net>
parents: 12456
diff changeset
1799 "prpl-simple", /**< id */
12db50600de5 [gaim-migrate @ 14801]
Mark Doliner <mark@kingant.net>
parents: 12456
diff changeset
1800 "SIMPLE", /**< name */
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1801 VERSION, /**< version */
12489
12db50600de5 [gaim-migrate @ 14801]
Mark Doliner <mark@kingant.net>
parents: 12456
diff changeset
1802 N_("SIP/SIMPLE Protocol Plugin"), /** summary */
12db50600de5 [gaim-migrate @ 14801]
Mark Doliner <mark@kingant.net>
parents: 12456
diff changeset
1803 N_("The SIP/SIMPLE Protocol Plugin"), /** description */
12db50600de5 [gaim-migrate @ 14801]
Mark Doliner <mark@kingant.net>
parents: 12456
diff changeset
1804 "Thomas Butter <butter@uni-mannheim.de>", /**< author */
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1805 GAIM_WEBSITE, /**< homepage */
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1806
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1807 NULL, /**< load */
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1808 NULL, /**< unload */
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1809 NULL, /**< destroy */
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1810
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1811 NULL, /**< ui_info */
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1812 &prpl_info, /**< extra_info */
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1813 NULL,
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1814 NULL
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1815 };
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1816
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1817 static void _init_plugin(GaimPlugin *plugin)
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1818 {
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
1819 GaimAccountUserSplit *split;
11189
5f79dfde334c [gaim-migrate @ 13307]
Thomas Butter <tbutter>
parents: 11181
diff changeset
1820 GaimAccountOption *option;
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1821
11396
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
1822 split = gaim_account_user_split_new(_("Server"), "", '@');
be776f9b1818 [gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11383
diff changeset
1823 prpl_info.user_splits = g_list_append(prpl_info.user_splits, split);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1824
12489
12db50600de5 [gaim-migrate @ 14801]
Mark Doliner <mark@kingant.net>
parents: 12456
diff changeset
1825 option = gaim_account_option_bool_new(_("Publish status (note: everyone may watch you)"), "dopublish", TRUE);
11345
03d9507f05a9 [gaim-migrate @ 13562]
Thomas Butter <tbutter>
parents: 11341
diff changeset
1826 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
03d9507f05a9 [gaim-migrate @ 13562]
Thomas Butter <tbutter>
parents: 11341
diff changeset
1827
12769
a90255f67652 [gaim-migrate @ 15116]
Thomas Butter <tbutter>
parents: 12768
diff changeset
1828 option = gaim_account_option_int_new(_("Connect port"), "port", 0);
12730
d5b8f4dc1622 [gaim-migrate @ 15074]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12689
diff changeset
1829 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
d5b8f4dc1622 [gaim-migrate @ 15074]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12689
diff changeset
1830
11189
5f79dfde334c [gaim-migrate @ 13307]
Thomas Butter <tbutter>
parents: 11181
diff changeset
1831 option = gaim_account_option_bool_new(_("Use UDP"), "udp", FALSE);
5f79dfde334c [gaim-migrate @ 13307]
Thomas Butter <tbutter>
parents: 11181
diff changeset
1832 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
12489
12db50600de5 [gaim-migrate @ 14801]
Mark Doliner <mark@kingant.net>
parents: 12456
diff changeset
1833 option = gaim_account_option_bool_new(_("Use proxy"), "useproxy", FALSE);
11210
5ba038e1b21f [gaim-migrate @ 13341]
Thomas Butter <tbutter>
parents: 11194
diff changeset
1834 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
5ba038e1b21f [gaim-migrate @ 13341]
Thomas Butter <tbutter>
parents: 11194
diff changeset
1835 option = gaim_account_option_string_new(_("Proxy"), "proxy", "");
5ba038e1b21f [gaim-migrate @ 13341]
Thomas Butter <tbutter>
parents: 11194
diff changeset
1836 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
13084
31a3a9af1494 [gaim-migrate @ 15446]
Thomas Butter <tbutter>
parents: 13083
diff changeset
1837 option = gaim_account_option_string_new(_("Auth User"), "authuser", "");
31a3a9af1494 [gaim-migrate @ 15446]
Thomas Butter <tbutter>
parents: 13083
diff changeset
1838 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
31a3a9af1494 [gaim-migrate @ 15446]
Thomas Butter <tbutter>
parents: 13083
diff changeset
1839 option = gaim_account_option_string_new(_("Auth Domain"), "authdomain", "");
31a3a9af1494 [gaim-migrate @ 15446]
Thomas Butter <tbutter>
parents: 13083
diff changeset
1840 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
11181
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1841 }
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1842
e5bbe5070e04 [gaim-migrate @ 13292]
Thomas Butter <tbutter>
parents:
diff changeset
1843 GAIM_INIT_PLUGIN(simple, _init_plugin, info);