Mercurial > pidgin
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 |
rev | line source |
---|---|
11181 | 1 /** |
2 * @file simple.c | |
3 * | |
4 * gaim | |
5 * | |
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 | 8 * *** |
9 * Thanks to Google's Summer of Code Program and the helpful mentors | |
10 * *** | |
11181 | 11 * |
12 * This program is free software; you can redistribute it and/or modify | |
13 * it under the terms of the GNU General Public License as published by | |
14 * the Free Software Foundation; either version 2 of the License, or | |
15 * (at your option) any later version. | |
16 * | |
17 * This program is distributed in the hope that it will be useful, | |
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 * GNU General Public License for more details. | |
21 * | |
22 * You should have received a copy of the GNU General Public License | |
23 * along with this program; if not, write to the Free Software | |
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
25 */ | |
26 | |
27 #include "internal.h" | |
28 | |
29 #include "accountopt.h" | |
30 #include "blist.h" | |
31 #include "conversation.h" | |
32 #include "debug.h" | |
33 #include "notify.h" | |
11345 | 34 #include "privacy.h" |
11181 | 35 #include "prpl.h" |
36 #include "plugin.h" | |
37 #include "util.h" | |
38 #include "version.h" | |
39 #include "network.h" | |
40 #include "xmlnode.h" | |
41 | |
42 #include "simple.h" | |
43 #include "sipmsg.h" | |
11383 | 44 #include "dnssrv.h" |
11409 | 45 #include "ntlm.h" |
11181 | 46 |
47 static char *gentag() { | |
48 return g_strdup_printf("%04d%04d", rand() & 0xFFFF, rand() & 0xFFFF); | |
49 } | |
50 | |
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 | 55 } |
56 | |
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 | 62 } |
63 | |
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 | 66 } |
67 | |
68 static void simple_keep_alive(GaimConnection *gc) { | |
11194 | 69 struct simple_account_data *sip = gc->proto_data; |
11341 | 70 if(sip->udp) { /* in case of UDP send a packet only with a 0 byte to |
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 | 73 gaim_debug_info("simple", "sending keep alive\n"); |
74 sendto(sip->fd, buf, 1, 0, (struct sockaddr*)&sip->serveraddr, sizeof(struct sockaddr_in)); | |
75 } | |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
76 return; |
11181 | 77 } |
78 | |
79 static gboolean process_register_response(struct simple_account_data *sip, struct sipmsg *msg, struct transaction *tc); | |
80 static void send_notify(struct simple_account_data *sip, struct simple_watcher *); | |
81 | |
82 static void send_publish(struct simple_account_data *sip); | |
83 | |
84 static void do_notifies(struct simple_account_data *sip) { | |
85 GSList *tmp = sip->watcher; | |
86 gaim_debug_info("simple", "do_notifies()\n"); | |
11345 | 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 | 89 send_publish(sip); |
90 } | |
91 } | |
11181 | 92 |
93 while(tmp) { | |
94 gaim_debug_info("simple", "notifying %s\n", ((struct simple_watcher*)tmp->data)->name); | |
95 send_notify(sip, tmp->data); | |
96 tmp = tmp->next; | |
97 } | |
98 } | |
99 | |
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 | 102 struct simple_account_data *sip = NULL; |
11718 | 103 |
11181 | 104 if (!gaim_status_is_active(status)) |
105 return; | |
106 | |
11718 | 107 if (account->gc) |
108 sip = account->gc->proto_data; | |
109 | |
110 if (sip) | |
111 { | |
11650 | 112 g_free(sip->status); |
11718 | 113 if (primitive == GAIM_STATUS_AVAILABLE) |
114 sip->status = g_strdup("available"); | |
115 else | |
116 sip->status = g_strdup("busy"); | |
11181 | 117 |
118 do_notifies(sip); | |
119 } | |
120 } | |
121 | |
122 static struct sip_connection *connection_find(struct simple_account_data *sip, int fd) { | |
123 struct sip_connection *ret = NULL; | |
124 GSList *entry = sip->openconns; | |
125 while(entry) { | |
126 ret = entry->data; | |
127 if(ret->fd == fd) return ret; | |
128 entry = entry->next; | |
129 } | |
130 return NULL; | |
131 } | |
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 | 135 struct simple_watcher *watcher; |
136 GSList *entry = sip->watcher; | |
137 while(entry) { | |
138 watcher = entry->data; | |
139 if(!strcmp(name, watcher->name)) return watcher; | |
140 entry = entry->next; | |
141 } | |
142 return NULL; | |
143 } | |
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 | 149 watcher->name = g_strdup(name); |
150 watcher->dialog.callid = g_strdup(callid); | |
151 watcher->dialog.ourtag = g_strdup(ourtag); | |
152 watcher->dialog.theirtag = g_strdup(theirtag); | |
13177 | 153 watcher->needsxpidf = needsxpidf; |
11181 | 154 sip->watcher = g_slist_append(sip->watcher, watcher); |
155 return watcher; | |
156 } | |
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 | 159 struct simple_watcher *watcher = watcher_find(sip, name); |
160 sip->watcher = g_slist_remove(sip->watcher, watcher); | |
161 g_free(watcher->name); | |
162 g_free(watcher->dialog.callid); | |
163 g_free(watcher->dialog.ourtag); | |
164 g_free(watcher->dialog.theirtag); | |
165 g_free(watcher); | |
166 } | |
167 | |
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 | 170 ret->fd = fd; |
171 sip->openconns = g_slist_append(sip->openconns, ret); | |
172 return ret; | |
173 } | |
174 | |
175 static void connection_remove(struct simple_account_data *sip, int fd) { | |
176 struct sip_connection *conn = connection_find(sip, fd); | |
177 sip->openconns = g_slist_remove(sip->openconns, conn); | |
178 if(conn->inputhandler) gaim_input_remove(conn->inputhandler); | |
11650 | 179 g_free(conn->inbuf); |
11181 | 180 g_free(conn); |
181 } | |
182 | |
11346 | 183 static void connection_free_all(struct simple_account_data *sip) { |
184 struct sip_connection *ret = NULL; | |
185 GSList *entry = sip->openconns; | |
186 while(entry) { | |
187 ret = entry->data; | |
188 connection_remove(sip, ret->fd); | |
189 entry = sip->openconns; | |
190 } | |
191 } | |
192 | |
11181 | 193 static void simple_add_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group) |
194 { | |
195 struct simple_account_data *sip = (struct simple_account_data *)gc->proto_data; | |
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 | 199 gaim_blist_rename_buddy(buddy, buf); |
11181 | 200 g_free(buf); |
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 | 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 | 205 b->name = g_strdup(buddy->name); |
206 g_hash_table_insert(sip->buddies, b->name, b); | |
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 | 209 } |
210 } | |
211 | |
212 static void simple_get_buddies(GaimConnection *gc) { | |
213 GaimBlistNode *gnode, *cnode, *bnode; | |
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 | 217 for(gnode = gaim_get_blist()->root; gnode; gnode = gnode->next) { |
218 if(!GAIM_BLIST_NODE_IS_GROUP(gnode)) continue; | |
219 for(cnode = gnode->child; cnode; cnode = cnode->next) { | |
220 if(!GAIM_BLIST_NODE_IS_CONTACT(cnode)) continue; | |
221 for(bnode = cnode->child; bnode; bnode = bnode->next) { | |
222 if(!GAIM_BLIST_NODE_IS_BUDDY(bnode)) continue; | |
11192 | 223 if(((GaimBuddy*)bnode)->account == gc->account) |
224 simple_add_buddy(gc, (GaimBuddy*)bnode, (GaimGroup *)gnode); | |
11181 | 225 } |
226 } | |
227 } | |
228 } | |
229 | |
230 static void simple_remove_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group) | |
231 { | |
232 struct simple_account_data *sip = (struct simple_account_data *)gc->proto_data; | |
233 struct simple_buddy *b = g_hash_table_lookup(sip->buddies, buddy->name); | |
234 g_hash_table_remove(sip->buddies, buddy->name); | |
235 g_free(b->name); | |
236 g_free(b); | |
237 } | |
238 | |
239 static GList *simple_status_types(GaimAccount *acc) { | |
240 GaimStatusType *type; | |
241 GList *types = NULL; | |
12456 | 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 | 249 type = gaim_status_type_new_full( |
250 GAIM_STATUS_OFFLINE, NULL, NULL, TRUE, TRUE, FALSE); | |
251 types = g_list_append(types, type); | |
252 | |
11181 | 253 return types; |
254 } | |
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 | 258 gchar noncecount[9]; |
12382
cfc808463763
[gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents:
12216
diff
changeset
|
259 gchar *response; |
11346 | 260 gchar *ret; |
11409 | 261 gchar *tmp; |
13088 | 262 const char *authdomain; |
263 const char *authuser; | |
264 | |
265 authdomain = gaim_account_get_string(sip->account, "authdomain", ""); | |
266 authuser = gaim_account_get_string(sip->account, "authuser", sip->username); | |
267 | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
268 if(!authuser || strlen(authuser) < 1) { |
13084 | 269 authuser = sip->username; |
270 } | |
11409 | 271 |
272 if(auth->type == 1) { /* Digest */ | |
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 | 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 | 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 | 281 return ret; |
282 } else if(auth->type == 2) { /* NTLM */ | |
13084 | 283 if(auth->nc == 3 && auth->nonce) { |
13698 | 284 /* TODO: Don't hardcode "gaim" as the hostname */ |
285 ret = gaim_ntlm_gen_type3(authuser, sip->password, "gaim", authdomain, (const guint8 *)auth->nonce, &auth->flags); | |
13084 | 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 | 287 g_free(ret); |
288 return tmp; | |
289 } | |
13084 | 290 tmp = g_strdup_printf("NTLM qop=\"auth\", realm=\"%s\", targetname=\"%s\", gssapi-data=\"\"\r\n", auth->realm, auth->target); |
11409 | 291 return tmp; |
292 } | |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
293 |
11346 | 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 | 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 | 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 | 302 return ret; |
303 } | |
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 | 315 else |
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 | 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 | 324 const char *authuser; |
11424 | 325 char *tmp; |
11439
617e67e1c985
[gaim-migrate @ 13676]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11424
diff
changeset
|
326 gchar **parts; |
13084 | 327 |
13088 | 328 authuser = gaim_account_get_string(sip->account, "authuser", sip->username); |
329 | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
330 if(!authuser || strlen(authuser) < 1) { |
13084 | 331 authuser = sip->username; |
332 } | |
13088 | 333 |
11346 | 334 if(!hdr) { |
11409 | 335 gaim_debug_error("simple", "fill_auth: hdr==NULL\n"); |
11346 | 336 return; |
337 } | |
11409 | 338 |
339 if(!g_strncasecmp(hdr, "NTLM", 4)) { | |
340 gaim_debug_info("simple", "found NTLM\n"); | |
341 auth->type = 2; | |
13347 | 342 parts = g_strsplit(hdr+5, "\", ", 0); |
343 i = 0; | |
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 | 346 if((tmp = parse_attribute("gssapi-data=\"", parts[i]))) { |
13698 | 347 auth->nonce = g_memdup(gaim_ntlm_parse_type2(tmp, &auth->flags), 8); |
13347 | 348 g_free(tmp); |
349 } | |
350 if((tmp = parse_attribute("targetname=\"", | |
351 parts[i]))) { | |
352 auth->target = tmp; | |
11424 | 353 } |
13347 | 354 else if((tmp = parse_attribute("realm=\"", |
355 parts[i]))) { | |
356 auth->realm = tmp; | |
357 } | |
358 else if((tmp = parse_attribute("opaque=\"", parts[i]))) { | |
359 auth->opaque = tmp; | |
360 } | |
361 i++; | |
362 } | |
363 g_strfreev(parts); | |
364 auth->nc = 1; | |
365 if(!strstr(hdr, "gssapi-data")) { | |
11409 | 366 auth->nc = 1; |
13084 | 367 } else { |
11409 | 368 auth->nc = 3; |
13347 | 369 } |
11409 | 370 return; |
371 } | |
372 | |
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 | 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 | 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 | 381 } |
382 i++; | |
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 | 386 gaim_debug(GAIM_DEBUG_MISC, "simple", "nonce: %s realm: %s\n", auth->nonce ? auth->nonce : "(null)", auth->realm ? auth->realm : "(null)"); |
13656 | 387 if(auth->realm) { |
388 auth->digest_session_key = gaim_cipher_http_digest_calculate_session_key( | |
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 | 391 auth->nc = 1; |
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 | 420 } |
421 | |
11181 | 422 static void simple_input_cb(gpointer data, gint source, GaimInputCondition cond); |
423 | |
14118 | 424 static void send_later_cb(gpointer data, gint source, const gchar *error) { |
11181 | 425 GaimConnection *gc = data; |
14118 | 426 struct simple_account_data *sip; |
11181 | 427 struct sip_connection *conn; |
428 | |
14118 | 429 if (!GAIM_CONNECTION_IS_VALID(gc)) |
430 { | |
431 if (source >= 0) | |
432 close(source); | |
433 return; | |
434 } | |
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 | 438 return; |
439 } | |
440 | |
14118 | 441 sip = gc->proto_data; |
11181 | 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 | 452 conn = connection_create(sip, source); |
453 conn->inputhandler = gaim_input_add(sip->fd, GAIM_INPUT_READ, simple_input_cb, gc); | |
454 } | |
455 | |
456 | |
457 static void sendlater(GaimConnection *gc, const char *buf) { | |
458 struct simple_account_data *sip = gc->proto_data; | |
14089 | 459 GaimProxyConnectInfo *connect_info; |
460 | |
11181 | 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 | 463 connect_info = gaim_proxy_connect(sip->account, sip->realhostname, sip->realport, send_later_cb, gc); |
14089 | 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 | 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 | 474 } |
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 | 477 struct simple_account_data *sip = gc->proto_data; |
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 | 481 gaim_debug(GAIM_DEBUG_MISC, "simple", "\n\nsending - %s\n######\n%s\n######\n\n", ctime(&currtime), buf); |
11189 | 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 | 484 gaim_debug_info("simple", "could not send packet\n"); |
485 } | |
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 | 489 sendlater(gc, buf); |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
490 return; |
11189 | 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 | 519 } |
11181 | 520 } |
521 } | |
522 | |
11194 | 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 | 525 gchar *name; |
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 | 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 | 533 tmp = g_slist_next(tmp); |
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 | 538 } |
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 | 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 | 547 /* When sending the acknowlegements and errors, the content length from the original |
548 message is still here, but there is no body; we need to make sure we're sending the | |
549 correct content length */ | |
550 sipmsg_remove_header(msg, "Content-Length"); | |
551 if(body) { | |
552 gchar len[12]; | |
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 | 555 } |
556 else | |
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 | 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 | 564 tmp = g_slist_next(tmp); |
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 | 569 } |
570 | |
11194 | 571 static void transactions_remove(struct simple_account_data *sip, struct transaction *trans) { |
572 if(trans->msg) sipmsg_free(trans->msg); | |
573 sip->transactions = g_slist_remove(sip->transactions, trans); | |
574 g_free(trans); | |
575 } | |
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 | 578 struct transaction *trans = g_new0(struct transaction, 1); |
579 trans->time = time(NULL); | |
580 trans->msg = sipmsg_parse_msg(buf); | |
581 trans->cseq = sipmsg_find_header(trans->msg, "CSeq"); | |
582 trans->callback = callback; | |
583 sip->transactions = g_slist_append(sip->transactions, trans); | |
584 } | |
585 | |
586 static struct transaction *transactions_find(struct simple_account_data *sip, struct sipmsg *msg) { | |
587 struct transaction *trans; | |
588 GSList *transactions = sip->transactions; | |
589 gchar *cseq = sipmsg_find_header(msg, "CSeq"); | |
590 | |
591 while(transactions) { | |
592 trans = transactions->data; | |
593 if(!strcmp(trans->cseq, cseq)) { | |
594 return trans; | |
595 } | |
596 transactions = transactions->next; | |
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 | 600 } |
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 | 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 | 609 gchar *branch = genbranch(); |
14069
d594f0466585
[gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13981
diff
changeset
|
610 gchar *tag = NULL; |
12216 | 611 char *buf; |
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 | 618 else sip->regcallid = g_strdup(callid); |
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 | 625 g_free(buf); |
11181 | 626 gaim_debug(GAIM_DEBUG_MISC, "simple", "header %s", auth); |
627 } | |
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 | 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 | 632 g_free(buf); |
11181 | 633 gaim_debug(GAIM_DEBUG_MISC, "simple", "header %s", auth); |
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 | 639 buf = g_strdup_printf("%s %s SIP/2.0\r\n" |
11190 | 640 "Via: SIP/2.0/%s %s:%d;branch=%s\r\n" |
13084 | 641 /* Don't know what epid is, but LCS wants it */ |
642 "From: <sip:%s@%s>;tag=%s;epid=1234567890\r\n" | |
11181 | 643 "To: <%s>%s%s\r\n" |
644 "Max-Forwards: 10\r\n" | |
645 "CSeq: %d %s\r\n" | |
13678 | 646 "User-Agent: Gaim/" VERSION "\r\n" |
11181 | 647 "Call-ID: %s\r\n" |
648 "%s%s" | |
11658 | 649 "Content-Length: %" G_GSIZE_FORMAT "\r\n\r\n%s", |
11181 | 650 method, |
651 url, | |
11190 | 652 sip->udp ? "UDP" : "TCP", |
13129 | 653 gaim_network_get_my_ip(-1), |
11181 | 654 sip->listenport, |
655 branch, | |
656 sip->username, | |
657 sip->servername, | |
14069
d594f0466585
[gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13981
diff
changeset
|
658 dialog ? dialog->ourtag : tag, |
11181 | 659 to, |
660 dialog ? ";tag=" : "", | |
661 dialog ? dialog->theirtag : "", | |
662 ++sip->cseq, | |
663 method, | |
664 callid, | |
665 auth, | |
666 addh, | |
667 strlen(body), | |
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 | 672 g_free(branch); |
673 g_free(callid); | |
674 | |
11341 | 675 /* add to ongoing transactions */ |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
676 |
11181 | 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 | 681 g_free(buf); |
682 } | |
683 | |
13177 | 684 static char *get_contact(struct simple_account_data *sip) { |
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"); | |
686 } | |
687 | |
11194 | 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 | 691 char *contact = get_contact(sip); |
692 char *hdr = g_strdup_printf("Contact: %s\r\nExpires: %d\r\n", contact, expire); | |
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 | 697 if(expire) { |
698 sip->reregister = time(NULL) + expire - 50; | |
699 } else { | |
700 sip->reregister = time(NULL) + 600; | |
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 | 706 g_free(hdr); |
11181 | 707 g_free(uri); |
708 g_free(to); | |
709 } | |
710 | |
11194 | 711 static void do_register(struct simple_account_data *sip) { |
712 do_register_exp(sip, sip->registerexpire); | |
713 } | |
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 | 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 | 722 |
11341 | 723 /* i hate the different SIP UA behaviours... */ |
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 | 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 | 729 } else { |
730 gaim_debug_info("simple", "found < without > in From\n"); | |
731 return NULL; | |
732 } | |
733 } else { | |
14069
d594f0466585
[gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13981
diff
changeset
|
734 tmp = strchr(tmp2, ';'); |
11181 | 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 | 737 } else { |
14069
d594f0466585
[gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13981
diff
changeset
|
738 from = g_strdup(tmp2); |
11181 | 739 } |
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 | 742 return from; |
743 } | |
744 | |
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 | 749 return TRUE; |
750 } | |
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 | 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 | 756 gaim_prpl_got_user_status(sip->account, to, "offline", NULL); |
757 g_free(to); | |
758 return TRUE; | |
759 } | |
760 | |
761 static void simple_subscribe(struct simple_account_data *sip, struct simple_buddy *buddy) { | |
13347 | 762 gchar *contact = "Expires: 1200\r\nAccept: application/pidf+xml, application/xpidf+xml\r\nEvent: presence\r\n"; |
11181 | 763 gchar *to; |
13177 | 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 | 771 tmp = get_contact(sip); |
772 contact = g_strdup_printf("%sContact: %s\r\n", contact, tmp); | |
773 g_free(tmp); | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
774 |
11341 | 775 /* subscribe to buddy presence |
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 | 781 g_free(to); |
11341 | 782 g_free(contact); |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
783 |
11341 | 784 /* resubscribe before subscription expires */ |
785 /* add some jitter */ | |
13347 | 786 buddy->resubscribe = time(NULL)+1140+(rand()%50); |
11181 | 787 } |
788 | |
13347 | 789 static gboolean simple_add_lcs_contacts(struct simple_account_data *sip, struct sipmsg *msg, struct transaction *tc) { |
790 gchar *tmp; | |
791 xmlnode *item, *group, *isc; | |
792 const char *name_group; | |
793 GaimBuddy *b; | |
14069
d594f0466585
[gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13981
diff
changeset
|
794 GaimGroup *g = NULL; |
13347 | 795 struct simple_buddy *bs; |
796 int len = msg->bodylen; | |
797 | |
798 | |
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 | 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 | 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 | 805 |
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 | 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 | 818 g = gaim_group_new("Buddies"); |
819 } | |
820 | |
821 for(item = xmlnode_get_child(isc, "contact"); item; item = xmlnode_get_next_twin(item)) | |
822 { | |
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 | 825 uri = xmlnode_get_attrib(item, "uri"); |
826 name = xmlnode_get_attrib(item, "name"); | |
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 | 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 | 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 | 838 gaim_blist_add_buddy(b, NULL, g, NULL); |
839 gaim_blist_alias_buddy(b, uri); | |
840 bs = g_new0(struct simple_buddy, 1); | |
841 bs->name = g_strdup(b->name); | |
842 g_hash_table_insert(sip->buddies, bs->name, bs); | |
843 } | |
844 xmlnode_free(isc); | |
845 } | |
846 return 0; | |
847 } | |
848 | |
849 static void simple_subscribe_buddylist(struct simple_account_data *sip) { | |
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"; | |
851 gchar *to; | |
852 gchar *tmp; | |
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 | 855 tmp = get_contact(sip); |
14069
d594f0466585
[gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13981
diff
changeset
|
856 |
13347 | 857 contact = g_strdup_printf("%sContact: %s\r\n", contact, tmp); |
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 | 861 |
862 g_free(to); | |
863 g_free(contact); | |
864 } | |
865 | |
866 | |
11181 | 867 static void simple_buddy_resub(char *name, struct simple_buddy *buddy, struct simple_account_data *sip) { |
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 | 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 | 872 simple_subscribe(sip, buddy); |
873 } | |
874 } | |
875 | |
11194 | 876 static gboolean resend_timeout(struct simple_account_data *sip) { |
877 GSList *tmp = sip->transactions; | |
878 time_t currtime = time(NULL); | |
879 while(tmp) { | |
880 struct transaction *trans = tmp->data; | |
881 tmp = tmp->next; | |
882 gaim_debug_info("simple", "have open transaction age: %d\n", currtime- trans->time); | |
883 if((currtime - trans->time > 5) && trans->retries >= 1) { | |
11341 | 884 /* TODO 408 */ |
11194 | 885 } else { |
886 if((currtime - trans->time > 2) && trans->retries == 0) { | |
887 trans->retries++; | |
888 sendout_sipmsg(sip, trans->msg); | |
889 } | |
890 } | |
891 } | |
892 return TRUE; | |
893 } | |
894 | |
12768 | 895 static gboolean subscribe_timeout(struct simple_account_data *sip) { |
11181 | 896 GSList *tmp; |
897 time_t curtime = time(NULL); | |
11341 | 898 /* register again if first registration expires */ |
11181 | 899 if(sip->reregister < curtime) { |
11194 | 900 do_register(sip); |
11181 | 901 } |
11341 | 902 /* check for every subscription if we need to resubscribe */ |
11181 | 903 g_hash_table_foreach(sip->buddies, (GHFunc)simple_buddy_resub, (gpointer)sip); |
904 | |
11341 | 905 /* remove a timed out suscriber */ |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
906 |
11181 | 907 tmp = sip->watcher; |
908 while(tmp) { | |
909 struct simple_watcher *watcher = tmp->data; | |
910 if(watcher->expire < curtime) { | |
911 watcher_remove(sip, watcher->name); | |
912 tmp = sip->watcher; | |
913 } | |
914 if(tmp) tmp = tmp->next; | |
915 } | |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
916 |
11181 | 917 return TRUE; |
918 } | |
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 | 921 gchar *hdr; |
13184 | 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 | 925 } else { |
926 fullto = g_strdup(to); | |
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 | 930 } else { |
931 hdr = g_strdup("Content-Type: text/plain\r\n"); | |
932 } | |
13184 | 933 send_sip_request(sip->gc, "MESSAGE", fullto, fullto, hdr, msg, NULL, NULL); |
11181 | 934 g_free(hdr); |
13184 | 935 g_free(fullto); |
11181 | 936 } |
937 | |
12216 | 938 static int simple_im_send(GaimConnection *gc, const char *who, const char *what, GaimMessageFlags flags) { |
11181 | 939 struct simple_account_data *sip = gc->proto_data; |
940 char *to = g_strdup(who); | |
12216 | 941 char *text = gaim_unescape_html(what); |
11181 | 942 simple_send_message(sip, to, text, NULL); |
943 g_free(to); | |
944 g_free(text); | |
945 return 1; | |
946 } | |
947 | |
948 static void process_incoming_message(struct simple_account_data *sip, struct sipmsg *msg) { | |
949 gchar *from; | |
950 gchar *contenttype; | |
951 gboolean found = FALSE; | |
952 | |
953 from = parse_from(sipmsg_find_header(msg, "From")); | |
954 | |
955 if(!from) return; | |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
956 |
11181 | 957 gaim_debug(GAIM_DEBUG_MISC, "simple", "got message from %s: %s\n", from, msg->body); |
958 | |
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 | 961 serv_got_im(sip->gc, from, msg->body, 0, time(NULL)); |
962 send_sip_response(sip->gc, msg, 200, "OK", NULL); | |
963 found = TRUE; | |
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 | 967 xmlnode *state; |
968 gchar *statedata; | |
969 | |
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 | 974 |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
975 state = xmlnode_get_child(isc, "state"); |
11181 | 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 | 982 |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
983 statedata = xmlnode_get_data(state); |
11181 | 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 | 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 | 989 } |
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 | 992 found = TRUE; |
993 } | |
994 if(!found) { | |
995 gaim_debug_info("simple", "got unknown mime-type"); | |
996 send_sip_response(sip->gc, msg, 415, "Unsupported media type", NULL); | |
997 } | |
998 g_free(from); | |
999 } | |
1000 | |
1001 | |
1002 gboolean process_register_response(struct simple_account_data *sip, struct sipmsg *msg, struct transaction *tc) { | |
1003 gchar *tmp; | |
1004 gaim_debug(GAIM_DEBUG_MISC, "simple", "in process register response response: %d\n", msg->response); | |
1005 switch (msg->response) { | |
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 | 1009 send_publish(sip); |
1010 } | |
11181 | 1011 } |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
1012 sip->registerstatus = 3; |
11181 | 1013 gaim_connection_set_state(sip->gc, GAIM_CONNECTED); |
11341 | 1014 |
1015 /* get buddies from blist */ | |
1016 simple_get_buddies(sip->gc); | |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
1017 |
12768 | 1018 subscribe_timeout(sip); |
13347 | 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 | 1021 simple_subscribe_buddylist(sip); |
1022 } | |
1023 | |
11181 | 1024 break; |
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 | 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 | 1031 return TRUE; |
1032 } | |
11181 | 1033 tmp = sipmsg_find_header(msg, "WWW-Authenticate"); |
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 | 1036 do_register(sip); |
11181 | 1037 } |
1038 break; | |
1039 } | |
1040 return TRUE; | |
1041 } | |
1042 | |
1043 static void process_incoming_notify(struct simple_account_data *sip, struct sipmsg *msg) { | |
1044 gchar *from; | |
1045 gchar *fromhdr; | |
1046 gchar *tmp2; | |
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 | 1049 gboolean isonline = FALSE; |
1050 | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
1051 fromhdr = sipmsg_find_header(msg, "From"); |
11181 | 1052 from = parse_from(fromhdr); |
1053 if(!from) return; | |
1054 | |
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 | 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 | 1059 return; |
1060 } | |
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 | 1065 |
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 | 1069 return; |
1070 } | |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
1071 |
11181 | 1072 tmp2 = xmlnode_get_data(basicstatus); |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
1073 |
11181 | 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 | 1077 return; |
1078 } | |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
1079 |
11181 | 1080 if(strstr(tmp2, "open")) { |
1081 isonline = TRUE; | |
1082 } | |
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 | 1086 if(isonline) gaim_prpl_got_user_status(sip->account, from, "available", NULL); |
1087 else gaim_prpl_got_user_status(sip->account, from, "offline", NULL); | |
1088 | |
1089 xmlnode_free(pidf); | |
1090 | |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
1091 g_free(from); |
11181 | 1092 send_sip_response(sip->gc, msg, 200, "OK", NULL); |
1093 } | |
1094 | |
13842 | 1095 static unsigned int simple_typing(GaimConnection *gc, const char *name, GaimTypingState state) { |
11181 | 1096 struct simple_account_data *sip = gc->proto_data; |
1097 | |
1098 gchar *xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" | |
1099 "<isComposing xmlns=\"urn:ietf:params:xml:ns:im-iscomposing\"\n" | |
1100 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" | |
1101 "xsi:schemaLocation=\"urn:ietf:params:xml:ns:im-composing iscomposing.xsd\">\n" | |
1102 "<state>%s</state>\n" | |
1103 "<contenttype>text/plain</contenttype>\n" | |
1104 "<refresh>60</refresh>\n" | |
1105 "</isComposing>"; | |
1106 gchar *recv = g_strdup(name); | |
13842 | 1107 if(state == GAIM_TYPING) { |
11181 | 1108 gchar *msg = g_strdup_printf(xml, "active"); |
1109 simple_send_message(sip, recv, msg, "application/im-iscomposing+xml"); | |
1110 g_free(msg); | |
13842 | 1111 } else /* TODO: Only if (state == GAIM_TYPED) ? */ { |
11181 | 1112 gchar *msg = g_strdup_printf(xml, "idle"); |
1113 simple_send_message(sip, recv, msg, "application/im-iscomposing+xml"); | |
1114 g_free(msg); | |
1115 } | |
1116 g_free(recv); | |
13842 | 1117 /* |
1118 * TODO: Is this right? It will cause the core to call | |
1119 * serv_send_typing(gc, who, GAIM_TYPING) once every second | |
1120 * until the user stops typing. If that's not desired, | |
1121 * then return 0 instead. | |
1122 */ | |
11181 | 1123 return 1; |
1124 } | |
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 | 1129 if(!tmp) return NULL; |
1130 tmp += 5; | |
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 | 1133 } |
1134 return g_strdup(tmp); | |
1135 } | |
1136 | |
13177 | 1137 static gchar* gen_xpidf(struct simple_account_data *sip) { |
1138 gchar *doc = g_strdup_printf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" | |
1139 "<presence>\n" | |
1140 "<presentity uri=\"sip:%s@%s;method=SUBSCRIBE\"/>\n" | |
1141 "<display name=\"sip:%s@%s\"/>\n" | |
1142 "<atom id=\"1234\">\n" | |
1143 "<address uri=\"sip:%s@%s\">\n" | |
1144 "<status status=\"%s\"/>\n" | |
1145 "</address>\n" | |
1146 "</atom>\n" | |
1147 "</presence>\n", | |
1148 sip->username, | |
1149 sip->servername, | |
1150 sip->username, | |
1151 sip->servername, | |
1152 sip->username, | |
1153 sip->servername, | |
1154 sip->status); | |
1155 return doc; | |
1156 } | |
1157 | |
1158 | |
1159 | |
11181 | 1160 static gchar* gen_pidf(struct simple_account_data *sip) { |
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 | 1166 "<status>\n" |
1167 "<basic>open</basic>\n" | |
1168 "</status>\n" | |
13655 | 1169 "<note>%s</note>\n" |
11181 | 1170 "</tuple>\n" |
1171 "</presence>", | |
1172 sip->username, | |
1173 sip->servername, | |
1174 sip->status); | |
1175 return doc; | |
1176 } | |
1177 | |
1178 static void send_notify(struct simple_account_data *sip, struct simple_watcher *watcher) { | |
13177 | 1179 gchar *doc = watcher->needsxpidf ? gen_xpidf(sip) : gen_pidf(sip); |
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"; | |
1181 send_sip_request(sip->gc, "NOTIFY", watcher->name, watcher->name, hdr, doc, &watcher->dialog, NULL); | |
11181 | 1182 g_free(doc); |
1183 } | |
1184 | |
1185 static gboolean process_publish_response(struct simple_account_data *sip, struct sipmsg *msg, struct transaction *tc) { | |
11345 | 1186 if(msg->response != 200 && msg->response != 408) { |
11341 | 1187 /* never send again */ |
11181 | 1188 sip->republish = -1; |
1189 } | |
1190 return TRUE; | |
1191 } | |
1192 | |
1193 static void send_publish(struct simple_account_data *sip) { | |
1194 gchar *uri = g_strdup_printf("sip:%s@%s", sip->username, sip->servername); | |
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 | 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 | 1202 g_free(doc); |
1203 } | |
1204 | |
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 | 1209 gchar *ourtag = find_tag(sipmsg_find_header(msg, "To")); |
1210 gboolean tagadded = FALSE; | |
1211 gchar *callid = sipmsg_find_header(msg, "Call-ID"); | |
1212 gchar *expire = sipmsg_find_header(msg, "Expire"); | |
1213 gchar *tmp; | |
1214 struct simple_watcher *watcher = watcher_find(sip, from); | |
1215 if(!ourtag) { | |
1216 tagadded = TRUE; | |
1217 ourtag = gentag(); | |
1218 } | |
11341 | 1219 if(!watcher) { /* new subscription */ |
13177 | 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 | 1222 if(!gaim_privacy_check(sip->account, from)) { |
1223 send_sip_response(sip->gc, msg, 202, "Ok", NULL); | |
1224 goto privend; | |
1225 } | |
13177 | 1226 if(acceptheader) { |
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 | 1230 while(tmp && tmp < acceptheader + strlen(acceptheader)) { |
1231 gchar *tmp2 = strchr(tmp, ','); | |
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 | 1237 if(tmp2) { |
1238 *tmp2 = ','; | |
1239 tmp = tmp2; | |
1240 while(*tmp == ' ') tmp++; | |
1241 } else | |
1242 tmp = 0; | |
1243 } | |
14069
d594f0466585
[gaim-migrate @ 16690]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13981
diff
changeset
|
1244 if(!foundpidf && foundxpidf) needsxpidf = TRUE; |
13177 | 1245 g_free(acceptheader); |
1246 } | |
1247 watcher = watcher_create(sip, from, callid, ourtag, theirtag, needsxpidf); | |
11181 | 1248 } |
1249 if(tagadded) { | |
1250 gchar *to = g_strdup_printf("%s;tag=%s", sipmsg_find_header(msg, "To"), ourtag); | |
1251 sipmsg_remove_header(msg, "To"); | |
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 | 1254 } |
1255 if(expire) | |
1256 watcher->expire = time(NULL) + strtol(expire, NULL, 10); | |
1257 else | |
1258 watcher->expire = time(NULL) + 600; | |
1259 sipmsg_remove_header(msg, "Contact"); | |
13177 | 1260 tmp = get_contact(sip); |
11181 | 1261 sipmsg_add_header(msg, "Contact", tmp); |
13177 | 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 | 1264 send_sip_response(sip->gc, msg, 200, "Ok", NULL); |
1265 send_notify(sip, watcher); | |
11345 | 1266 privend: |
1267 g_free(from); | |
1268 g_free(theirtag); | |
1269 g_free(ourtag); | |
1270 g_free(callid); | |
1271 g_free(expire); | |
11181 | 1272 } |
1273 | |
11189 | 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 | 1277 if(!strcmp(msg->method, "MESSAGE")) { |
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 | 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 | 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 | 1288 } |
11341 | 1289 } else { /* response */ |
11189 | 1290 struct transaction *trans = transactions_find(sip, msg); |
1291 if(trans) { | |
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 | 1296 sip->proxy.retries++; |
11341 | 1297 /* do proxy authentication */ |
11189 | 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 | 1301 fill_auth(sip, ptmp, &sip->proxy); |
11346 | 1302 auth = auth_header(sip, &sip->proxy, trans->msg->method, trans->msg->target); |
13272 | 1303 sipmsg_remove_header(trans->msg, "Proxy-Authorization"); |
11189 | 1304 sipmsg_add_header(trans->msg, "Proxy-Authorization", auth); |
1305 g_free(auth); | |
1306 resend = sipmsg_to_string(trans->msg); | |
11341 | 1307 /* resend request */ |
11189 | 1308 sendout_pkt(sip->gc, resend); |
1309 g_free(resend); | |
1310 } else { | |
11517 | 1311 if(msg->response == 100) { |
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 | 1314 } else { |
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 | 1317 if(msg->response == 401) sip->registrar.retries++; |
1318 else sip->registrar.retries = 0; | |
1319 } else { | |
1320 if(msg->response == 401) { | |
1321 gchar *resend, *auth, *ptmp; | |
1322 | |
1323 if(sip->registrar.retries > 4) return; | |
1324 sip->registrar.retries++; | |
1325 | |
1326 ptmp = sipmsg_find_header(msg, "WWW-Authenticate"); | |
1327 | |
1328 fill_auth(sip, ptmp, &sip->registrar); | |
1329 auth = auth_header(sip, &sip->registrar, trans->msg->method, trans->msg->target); | |
1330 sipmsg_remove_header(trans->msg, "Authorization"); | |
1331 sipmsg_add_header(trans->msg, "Authorization", auth); | |
1332 g_free(auth); | |
1333 resend = sipmsg_to_string(trans->msg); | |
1334 /* resend request */ | |
1335 sendout_pkt(sip->gc, resend); | |
1336 g_free(resend); | |
1337 } | |
1338 } | |
11517 | 1339 if(trans->callback) { |
1340 /* call the callback to process response*/ | |
1341 (trans->callback)(sip, msg, trans); | |
1342 } | |
1343 transactions_remove(sip, trans); | |
11189 | 1344 } |
1345 } | |
12745
e788741f4840
[gaim-migrate @ 15092]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12741
diff
changeset
|
1346 found = TRUE; |
11189 | 1347 } else { |
1348 gaim_debug(GAIM_DEBUG_MISC, "simple", "received response to unknown transaction"); | |
1349 } | |
1350 } | |
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 | 1353 } |
1354 } | |
1355 | |
11181 | 1356 static void process_input(struct simple_account_data *sip, struct sip_connection *conn) |
1357 { | |
1358 char *cur; | |
1359 char *dummy; | |
1360 struct sipmsg *msg; | |
1361 int restlen; | |
1362 cur = conn->inbuf; | |
1363 | |
11341 | 1364 /* according to the RFC remove CRLF at the beginning */ |
11181 | 1365 while(*cur == '\r' || *cur == '\n') { |
1366 cur++; | |
1367 } | |
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 | 1371 } |
1372 | |
11341 | 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 | 1375 time_t currtime = time(NULL); |
1376 cur += 2; | |
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 | 1379 msg = sipmsg_parse_header(conn->inbuf); |
1380 cur[0] = '\r'; | |
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 | 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 | 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 | 1391 } else { |
1392 sipmsg_free(msg); | |
1393 return; | |
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 | 1397 } else { |
1398 gaim_debug(GAIM_DEBUG_MISC, "simple", "received a incomplete sip msg: %s\n", conn->inbuf); | |
1399 } | |
1400 } | |
1401 | |
11189 | 1402 static void simple_udp_process(gpointer data, gint source, GaimInputCondition con) { |
1403 GaimConnection *gc = data; | |
1404 struct simple_account_data *sip = gc->proto_data; | |
1405 struct sipmsg *msg; | |
1406 int len; | |
1407 time_t currtime; | |
1408 | |
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 | 1416 } |
1417 | |
11181 | 1418 static void simple_input_cb(gpointer data, gint source, GaimInputCondition cond) |
1419 { | |
1420 GaimConnection *gc = data; | |
1421 struct simple_account_data *sip = gc->proto_data; | |
1422 int len; | |
1423 struct sip_connection *conn = connection_find(sip, source); | |
1424 if(!conn) { | |
1425 gaim_debug_error("simple", "Connection not found!\n"); | |
1426 return; | |
1427 } | |
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 | 1430 conn->inbuflen += SIMPLE_BUF_INC; |
1431 conn->inbuf = g_realloc(conn->inbuf, conn->inbuflen); | |
1432 } | |
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 | 1440 connection_remove(sip, source); |
1441 if(sip->fd == source) sip->fd = -1; | |
1442 return; | |
1443 } | |
1444 | |
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 | 1448 process_input(sip, conn); |
1449 } | |
1450 | |
1451 /* Callback for new connections on incoming TCP port */ | |
1452 static void simple_newconn_cb(gpointer data, gint source, GaimInputCondition cond) { | |
1453 GaimConnection *gc = data; | |
1454 struct simple_account_data *sip = gc->proto_data; | |
1455 struct sip_connection *conn; | |
1456 | |
1457 int newfd = accept(source, NULL, NULL); | |
1458 | |
1459 conn = connection_create(sip, newfd); | |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
1460 |
11181 | 1461 conn->inputhandler = gaim_input_add(newfd, GAIM_INPUT_READ, simple_input_cb, gc); |
1462 } | |
1463 | |
14118 | 1464 static void login_cb(gpointer data, gint source, const gchar *error_message) { |
11181 | 1465 GaimConnection *gc = data; |
14118 | 1466 struct simple_account_data *sip; |
11181 | 1467 struct sip_connection *conn; |
1468 | |
14118 | 1469 if (!GAIM_CONNECTION_IS_VALID(gc)) |
1470 { | |
1471 if (source >= 0) | |
1472 close(source); | |
1473 return; | |
1474 } | |
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 | 1478 return; |
1479 } | |
1480 | |
14118 | 1481 sip = gc->proto_data; |
11181 | 1482 sip->fd = source; |
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 | 1486 sip->registertimeout = gaim_timeout_add((rand()%100)+10*1000, (GSourceFunc)subscribe_timeout, sip); |
11181 | 1487 |
11194 | 1488 do_register(sip); |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
1489 |
11181 | 1490 conn->inputhandler = gaim_input_add(sip->fd, GAIM_INPUT_READ, simple_input_cb, gc); |
1491 } | |
1492 | |
1493 static guint simple_ht_hash_nick(const char *nick) { | |
1494 char *lc = g_utf8_strdown(nick, -1); | |
1495 guint bucket = g_str_hash(lc); | |
1496 g_free(lc); | |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
1497 |
11181 | 1498 return bucket; |
1499 } | |
1500 | |
1501 static gboolean simple_ht_equals_nick(const char *nick1, const char *nick2) { | |
1502 return (gaim_utf8_strcasecmp(nick1, nick2) == 0); | |
1503 } | |
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 | 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 | 1571 connect_info = gaim_proxy_connect(sip->account, sip->realhostname, |
14108 | 1572 sip->realport, login_cb, sip->gc); |
14089 | 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 | 1579 GaimConnection *gc; |
1580 struct simple_account_data *sip; | |
1581 gchar *hostname; | |
1582 int port; | |
11383 | 1583 |
13580 | 1584 gc = data; |
13981 | 1585 if (!GAIM_CONNECTION_IS_VALID(gc)) |
13580 | 1586 { |
1587 /* This connection has been closed */ | |
1588 g_free(resp); | |
1589 return; | |
1590 } | |
1591 | |
1592 sip = gc->proto_data; | |
1593 port = gaim_account_get_int(sip->account, "port", 0); | |
11383 | 1594 |
1595 /* find the host to connect to */ | |
1596 if(results) { | |
1597 hostname = g_strdup(resp->hostname); | |
12769 | 1598 if(!port) |
1599 port = resp->port; | |
11383 | 1600 g_free(resp); |
1601 } else { | |
1602 if(!gaim_account_get_bool(sip->account, "useproxy", FALSE)) { | |
1603 hostname = g_strdup(sip->servername); | |
1604 } else { | |
1605 hostname = g_strdup(gaim_account_get_string(sip->account, "proxy", sip->servername)); | |
1606 } | |
1607 } | |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
1608 |
11383 | 1609 sip->realhostname = hostname; |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
1610 sip->realport = port; |
12769 | 1611 if(!sip->realport) sip->realport = 5060; |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
1612 |
11383 | 1613 /* TCP case */ |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
1614 if(!sip->udp) { |
11409 | 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 | 1618 gaim_connection_error(sip->gc, _("Could not create listen socket")); |
1619 return; | |
1620 } | |
11383 | 1621 } else { /* UDP */ |
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 | 1625 } |
1626 } | |
1627 | |
11837 | 1628 static void simple_login(GaimAccount *account) |
11181 | 1629 { |
1630 GaimConnection *gc; | |
1631 struct simple_account_data *sip; | |
1632 gchar **userserver; | |
11210 | 1633 gchar *hosttoconnect; |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
1634 |
11181 | 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 | 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 | 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 | 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 | 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 | 1655 sip->username = g_strdup(userserver[0]); |
1656 sip->servername = g_strdup(userserver[1]); | |
1657 sip->password = g_strdup(gaim_connection_get_password(gc)); | |
1658 g_strfreev(userserver); | |
1659 | |
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 | 1663 |
11837 | 1664 /* TODO: Set the status correctly. */ |
11181 | 1665 sip->status = g_strdup("available"); |
11189 | 1666 |
11210 | 1667 if(!gaim_account_get_bool(account, "useproxy", FALSE)) { |
1668 hosttoconnect = g_strdup(sip->servername); | |
1669 } else { | |
1670 hosttoconnect = g_strdup(gaim_account_get_string(account, "proxy", sip->servername)); | |
1671 } | |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
1672 |
11341 | 1673 /* TCP case */ |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
1674 if(!sip->udp) { |
13580 | 1675 gaim_srv_resolve("sip", "tcp", hosttoconnect, srvresolved, gc); |
11341 | 1676 } else { /* UDP */ |
13580 | 1677 gaim_srv_resolve("sip", "udp", hosttoconnect, srvresolved, gc); |
11181 | 1678 } |
11210 | 1679 g_free(hosttoconnect); |
11181 | 1680 } |
1681 | |
1682 static void simple_close(GaimConnection *gc) | |
1683 { | |
1684 struct simple_account_data *sip = gc->proto_data; | |
11194 | 1685 |
11341 | 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 | 1691 g_free(sip->servername); |
1692 g_free(sip->username); | |
1693 g_free(sip->password); | |
1694 g_free(sip->registrar.nonce); | |
13084 | 1695 g_free(sip->registrar.opaque); |
1696 g_free(sip->registrar.target); | |
11650 | 1697 g_free(sip->registrar.realm); |
13084 | 1698 g_free(sip->registrar.digest_session_key); |
11650 | 1699 g_free(sip->proxy.nonce); |
13084 | 1700 g_free(sip->proxy.opaque); |
1701 g_free(sip->proxy.target); | |
11650 | 1702 g_free(sip->proxy.realm); |
13084 | 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 | 1706 g_free(sip->realhostname); |
11409 | 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 | 1710 if(sip->registertimeout) gaim_timeout_remove(sip->registertimeout); |
11181 | 1711 } |
11650 | 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 | 1714 } |
1715 | |
11345 | 1716 /* not needed since privacy is checked for every subscribe */ |
1717 static void dummy_add_deny(GaimConnection *gc, const char *name) { | |
1718 } | |
1719 | |
1720 static void dummy_permit_deny(GaimConnection *gc) { | |
1721 } | |
1722 | |
11181 | 1723 static GaimPluginProtocolInfo prpl_info = |
1724 { | |
1725 0, | |
1726 NULL, /* user_splits */ | |
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 | 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 | 1731 NULL, /* status_text */ |
1732 NULL, /* tooltip_text */ | |
1733 simple_status_types, /* away_states */ | |
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 | 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 | 1743 simple_set_status, /* set_status */ |
1744 NULL, /* set_idle */ | |
1745 NULL, /* change_passwd */ | |
1746 simple_add_buddy, /* add_buddy */ | |
1747 NULL, /* add_buddies */ | |
1748 simple_remove_buddy, /* remove_buddy */ | |
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 | 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 | 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 | 1763 NULL, /* register_user */ |
1764 NULL, /* get_cb_info */ | |
1765 NULL, /* get_cb_away */ | |
1766 NULL, /* alias_buddy */ | |
1767 NULL, /* group_buddy */ | |
1768 NULL, /* rename_group */ | |
1769 NULL, /* buddy_free */ | |
1770 NULL, /* convo_closed */ | |
1771 NULL, /* normalize */ | |
1772 NULL, /* set_buddy_icon */ | |
1773 NULL, /* remove_group */ | |
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 | 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 | 1779 NULL, /* roomlist_expand_category */ |
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 | 1785 }; |
1786 | |
1787 | |
1788 static GaimPluginInfo info = | |
1789 { | |
1790 GAIM_PLUGIN_MAGIC, | |
1791 GAIM_MAJOR_VERSION, | |
1792 GAIM_MINOR_VERSION, | |
1793 GAIM_PLUGIN_PROTOCOL, /**< type */ | |
1794 NULL, /**< ui_requirement */ | |
1795 0, /**< flags */ | |
1796 NULL, /**< dependencies */ | |
1797 GAIM_PRIORITY_DEFAULT, /**< priority */ | |
1798 | |
12489 | 1799 "prpl-simple", /**< id */ |
1800 "SIMPLE", /**< name */ | |
11181 | 1801 VERSION, /**< version */ |
12489 | 1802 N_("SIP/SIMPLE Protocol Plugin"), /** summary */ |
1803 N_("The SIP/SIMPLE Protocol Plugin"), /** description */ | |
1804 "Thomas Butter <butter@uni-mannheim.de>", /**< author */ | |
11181 | 1805 GAIM_WEBSITE, /**< homepage */ |
1806 | |
1807 NULL, /**< load */ | |
1808 NULL, /**< unload */ | |
1809 NULL, /**< destroy */ | |
1810 | |
1811 NULL, /**< ui_info */ | |
1812 &prpl_info, /**< extra_info */ | |
1813 NULL, | |
1814 NULL | |
1815 }; | |
1816 | |
1817 static void _init_plugin(GaimPlugin *plugin) | |
1818 { | |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
1819 GaimAccountUserSplit *split; |
11189 | 1820 GaimAccountOption *option; |
11181 | 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 | 1824 |
12489 | 1825 option = gaim_account_option_bool_new(_("Publish status (note: everyone may watch you)"), "dopublish", TRUE); |
11345 | 1826 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); |
1827 | |
12769 | 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 | 1831 option = gaim_account_option_bool_new(_("Use UDP"), "udp", FALSE); |
1832 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
12489 | 1833 option = gaim_account_option_bool_new(_("Use proxy"), "useproxy", FALSE); |
11210 | 1834 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); |
1835 option = gaim_account_option_string_new(_("Proxy"), "proxy", ""); | |
1836 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
13084 | 1837 option = gaim_account_option_string_new(_("Auth User"), "authuser", ""); |
1838 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
1839 option = gaim_account_option_string_new(_("Auth Domain"), "authdomain", ""); | |
1840 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
11181 | 1841 } |
1842 | |
1843 GAIM_INIT_PLUGIN(simple, _init_plugin, info); |