Mercurial > pidgin
annotate src/protocols/simple/simple.c @ 13329:1d569233f257
[gaim-migrate @ 15699]
fix a stupid bug (SF 1432924)
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Sun, 26 Feb 2006 19:35:31 +0000 |
parents | 263c2db78f77 |
children | 955a24d87729 |
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 | |
133 static struct simple_watcher *watcher_find(struct simple_account_data *sip, gchar *name) { | |
134 struct simple_watcher *watcher; | |
135 GSList *entry = sip->watcher; | |
136 while(entry) { | |
137 watcher = entry->data; | |
138 if(!strcmp(name, watcher->name)) return watcher; | |
139 entry = entry->next; | |
140 } | |
141 return NULL; | |
142 } | |
143 | |
13177 | 144 static struct simple_watcher *watcher_create(struct simple_account_data *sip, gchar *name, gchar *callid, gchar *ourtag, gchar *theirtag, int needsxpidf) { |
13092
edef744647ff
[gaim-migrate @ 15454]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13088
diff
changeset
|
145 struct simple_watcher *watcher = g_new0(struct simple_watcher, 1); |
11181 | 146 watcher->name = g_strdup(name); |
147 watcher->dialog.callid = g_strdup(callid); | |
148 watcher->dialog.ourtag = g_strdup(ourtag); | |
149 watcher->dialog.theirtag = g_strdup(theirtag); | |
13177 | 150 watcher->needsxpidf = needsxpidf; |
11181 | 151 sip->watcher = g_slist_append(sip->watcher, watcher); |
152 return watcher; | |
153 } | |
154 | |
155 static void watcher_remove(struct simple_account_data *sip, gchar *name) { | |
156 struct simple_watcher *watcher = watcher_find(sip, name); | |
157 sip->watcher = g_slist_remove(sip->watcher, watcher); | |
158 g_free(watcher->name); | |
159 g_free(watcher->dialog.callid); | |
160 g_free(watcher->dialog.ourtag); | |
161 g_free(watcher->dialog.theirtag); | |
162 g_free(watcher); | |
163 } | |
164 | |
165 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
|
166 struct sip_connection *ret = g_new0(struct sip_connection, 1); |
11181 | 167 ret->fd = fd; |
168 sip->openconns = g_slist_append(sip->openconns, ret); | |
169 return ret; | |
170 } | |
171 | |
172 static void connection_remove(struct simple_account_data *sip, int fd) { | |
173 struct sip_connection *conn = connection_find(sip, fd); | |
174 sip->openconns = g_slist_remove(sip->openconns, conn); | |
175 if(conn->inputhandler) gaim_input_remove(conn->inputhandler); | |
11650 | 176 g_free(conn->inbuf); |
11181 | 177 g_free(conn); |
178 } | |
179 | |
11346 | 180 static void connection_free_all(struct simple_account_data *sip) { |
181 struct sip_connection *ret = NULL; | |
182 GSList *entry = sip->openconns; | |
183 while(entry) { | |
184 ret = entry->data; | |
185 connection_remove(sip, ret->fd); | |
186 entry = sip->openconns; | |
187 } | |
188 } | |
189 | |
11181 | 190 static void simple_add_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group) |
191 { | |
192 struct simple_account_data *sip = (struct simple_account_data *)gc->proto_data; | |
193 struct simple_buddy *b; | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
194 if(strncmp("sip:", buddy->name, 4)) { |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
195 gchar *buf = g_strdup_printf("sip:%s", buddy->name); |
12755 | 196 gaim_blist_rename_buddy(buddy, buf); |
11181 | 197 g_free(buf); |
198 } | |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
199 if(!g_hash_table_lookup(sip->buddies, buddy->name)) { |
11181 | 200 b = g_new0(struct simple_buddy, 1); |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
201 gaim_debug_info("simple", "simple_add_buddy %s\n", buddy->name); |
11181 | 202 b->name = g_strdup(buddy->name); |
203 g_hash_table_insert(sip->buddies, b->name, b); | |
204 } else { | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
205 gaim_debug_info("simple", "buddy %s already in internal list\n", buddy->name); |
11181 | 206 } |
207 } | |
208 | |
209 static void simple_get_buddies(GaimConnection *gc) { | |
210 GaimBlistNode *gnode, *cnode, *bnode; | |
211 | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
212 gaim_debug_info("simple", "simple_get_buddies\n"); |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
213 |
11181 | 214 for(gnode = gaim_get_blist()->root; gnode; gnode = gnode->next) { |
215 if(!GAIM_BLIST_NODE_IS_GROUP(gnode)) continue; | |
216 for(cnode = gnode->child; cnode; cnode = cnode->next) { | |
217 if(!GAIM_BLIST_NODE_IS_CONTACT(cnode)) continue; | |
218 for(bnode = cnode->child; bnode; bnode = bnode->next) { | |
219 if(!GAIM_BLIST_NODE_IS_BUDDY(bnode)) continue; | |
11192 | 220 if(((GaimBuddy*)bnode)->account == gc->account) |
221 simple_add_buddy(gc, (GaimBuddy*)bnode, (GaimGroup *)gnode); | |
11181 | 222 } |
223 } | |
224 } | |
225 } | |
226 | |
227 static void simple_remove_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group) | |
228 { | |
229 struct simple_account_data *sip = (struct simple_account_data *)gc->proto_data; | |
230 struct simple_buddy *b = g_hash_table_lookup(sip->buddies, buddy->name); | |
231 g_hash_table_remove(sip->buddies, buddy->name); | |
232 g_free(b->name); | |
233 g_free(b); | |
234 } | |
235 | |
236 static GList *simple_status_types(GaimAccount *acc) { | |
237 GaimStatusType *type; | |
238 GList *types = NULL; | |
12456 | 239 |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
240 type = gaim_status_type_new_with_attrs( |
12595
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12571
diff
changeset
|
241 GAIM_STATUS_AVAILABLE, NULL, NULL, TRUE, TRUE, FALSE, |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12571
diff
changeset
|
242 "message", _("Message"), gaim_value_new(GAIM_TYPE_STRING), |
3169cd6727ad
[gaim-migrate @ 14925]
Richard Laager <rlaager@wiktel.com>
parents:
12571
diff
changeset
|
243 NULL); |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
244 types = g_list_append(types, type); |
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
245 |
12657 | 246 type = gaim_status_type_new_full( |
247 GAIM_STATUS_OFFLINE, NULL, NULL, TRUE, TRUE, FALSE); | |
248 types = g_list_append(types, type); | |
249 | |
11181 | 250 return types; |
251 } | |
252 | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
253 static gchar *auth_header(struct simple_account_data *sip, |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
254 struct sip_auth *auth, const gchar *method, const gchar *target) { |
11346 | 255 gchar noncecount[9]; |
12382
cfc808463763
[gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents:
12216
diff
changeset
|
256 gchar *response; |
11346 | 257 gchar *ret; |
11409 | 258 gchar *tmp; |
13088 | 259 const char *authdomain; |
260 const char *authuser; | |
261 | |
262 authdomain = gaim_account_get_string(sip->account, "authdomain", ""); | |
263 authuser = gaim_account_get_string(sip->account, "authuser", sip->username); | |
264 | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
265 if(!authuser || strlen(authuser) < 1) { |
13084 | 266 authuser = sip->username; |
267 } | |
11409 | 268 |
269 if(auth->type == 1) { /* Digest */ | |
270 sprintf(noncecount, "%08d", auth->nc++); | |
12382
cfc808463763
[gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents:
12216
diff
changeset
|
271 response = gaim_cipher_http_digest_calculate_response( |
12389
e024601d45c7
[gaim-migrate @ 14695]
Richard Laager <rlaager@wiktel.com>
parents:
12382
diff
changeset
|
272 "md5", method, target, NULL, NULL, |
12382
cfc808463763
[gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents:
12216
diff
changeset
|
273 auth->nonce, noncecount, NULL, auth->digest_session_key); |
11409 | 274 gaim_debug(GAIM_DEBUG_MISC, "simple", "response %s\n", response); |
12382
cfc808463763
[gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents:
12216
diff
changeset
|
275 |
13084 | 276 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
|
277 g_free(response); |
11409 | 278 return ret; |
279 } else if(auth->type == 2) { /* NTLM */ | |
13084 | 280 if(auth->nc == 3 && auth->nonce) { |
281 ret = gaim_ntlm_gen_type3(authuser, sip->password, "gaim", authdomain, auth->nonce, &auth->flags); | |
282 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 | 283 g_free(ret); |
284 return tmp; | |
285 } | |
13084 | 286 tmp = g_strdup_printf("NTLM qop=\"auth\", realm=\"%s\", targetname=\"%s\", gssapi-data=\"\"\r\n", auth->realm, auth->target); |
11409 | 287 return tmp; |
288 } | |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
289 |
11346 | 290 sprintf(noncecount, "%08d", auth->nc++); |
12382
cfc808463763
[gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents:
12216
diff
changeset
|
291 response = gaim_cipher_http_digest_calculate_response( |
12389
e024601d45c7
[gaim-migrate @ 14695]
Richard Laager <rlaager@wiktel.com>
parents:
12382
diff
changeset
|
292 "md5", method, target, NULL, NULL, |
12382
cfc808463763
[gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents:
12216
diff
changeset
|
293 auth->nonce, noncecount, NULL, auth->digest_session_key); |
11346 | 294 gaim_debug(GAIM_DEBUG_MISC, "simple", "response %s\n", response); |
12382
cfc808463763
[gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents:
12216
diff
changeset
|
295 |
13084 | 296 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
|
297 g_free(response); |
11346 | 298 return ret; |
299 } | |
300 | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
301 static char *parse_attribute(const char *attrname, char *source) { |
12746
4f7dab030b1a
[gaim-migrate @ 15093]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12745
diff
changeset
|
302 char *tmp, *tmp2, *retval = NULL; |
4f7dab030b1a
[gaim-migrate @ 15093]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12745
diff
changeset
|
303 int len = strlen(attrname); |
4f7dab030b1a
[gaim-migrate @ 15093]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12745
diff
changeset
|
304 |
4f7dab030b1a
[gaim-migrate @ 15093]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12745
diff
changeset
|
305 if(!strncmp(source, attrname, len)) { |
4f7dab030b1a
[gaim-migrate @ 15093]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12745
diff
changeset
|
306 tmp = source + len; |
4f7dab030b1a
[gaim-migrate @ 15093]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12745
diff
changeset
|
307 tmp2 = g_strstr_len(tmp, strlen(tmp), "\""); |
4f7dab030b1a
[gaim-migrate @ 15093]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12745
diff
changeset
|
308 if(tmp2) |
4f7dab030b1a
[gaim-migrate @ 15093]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12745
diff
changeset
|
309 retval = g_strndup(tmp, tmp2 - tmp); |
13085 | 310 else |
311 retval = g_strdup(tmp); | |
12746
4f7dab030b1a
[gaim-migrate @ 15093]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12745
diff
changeset
|
312 } |
4f7dab030b1a
[gaim-migrate @ 15093]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12745
diff
changeset
|
313 |
4f7dab030b1a
[gaim-migrate @ 15093]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12745
diff
changeset
|
314 return retval; |
4f7dab030b1a
[gaim-migrate @ 15093]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12745
diff
changeset
|
315 } |
4f7dab030b1a
[gaim-migrate @ 15093]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12745
diff
changeset
|
316 |
11346 | 317 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
|
318 int i = 0; |
13088 | 319 const char *authuser; |
11424 | 320 char *tmp; |
11439
617e67e1c985
[gaim-migrate @ 13676]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11424
diff
changeset
|
321 gchar **parts; |
13084 | 322 |
13088 | 323 authuser = gaim_account_get_string(sip->account, "authuser", sip->username); |
324 | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
325 if(!authuser || strlen(authuser) < 1) { |
13084 | 326 authuser = sip->username; |
327 } | |
13088 | 328 |
11346 | 329 if(!hdr) { |
11409 | 330 gaim_debug_error("simple", "fill_auth: hdr==NULL\n"); |
11346 | 331 return; |
332 } | |
11409 | 333 |
334 if(!g_strncasecmp(hdr, "NTLM", 4)) { | |
335 gaim_debug_info("simple", "found NTLM\n"); | |
336 auth->type = 2; | |
13084 | 337 if(!strstr(hdr, "gssapi-data")) { |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
338 gaim_debug_info("simple", "here"); |
13085 | 339 parts = g_strsplit(hdr+5, "\", ", 0); |
13084 | 340 i = 0; |
11424 | 341 while(parts[i]) { |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
342 gaim_debug_info("simple", "parts[i] %s\n", parts[i]); |
12746
4f7dab030b1a
[gaim-migrate @ 15093]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12745
diff
changeset
|
343 if((tmp = parse_attribute("targetname=\"", |
4f7dab030b1a
[gaim-migrate @ 15093]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12745
diff
changeset
|
344 parts[i]))) { |
4f7dab030b1a
[gaim-migrate @ 15093]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12745
diff
changeset
|
345 auth->target = tmp; |
11424 | 346 } |
12746
4f7dab030b1a
[gaim-migrate @ 15093]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12745
diff
changeset
|
347 else if((tmp = parse_attribute("realm=\"", |
4f7dab030b1a
[gaim-migrate @ 15093]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12745
diff
changeset
|
348 parts[i]))) { |
4f7dab030b1a
[gaim-migrate @ 15093]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12745
diff
changeset
|
349 auth->realm = tmp; |
11424 | 350 } |
351 i++; | |
352 } | |
11439
617e67e1c985
[gaim-migrate @ 13676]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11424
diff
changeset
|
353 g_strfreev(parts); |
11409 | 354 auth->nc = 1; |
13084 | 355 } else { |
11409 | 356 auth->nc = 3; |
13084 | 357 i = 0; |
358 parts = g_strsplit(hdr, " ", 0); | |
359 while(parts[i]) { | |
360 if((tmp = parse_attribute("gssapi-data=\"", parts[i]))) { | |
361 auth->nonce = g_strdup(gaim_ntlm_parse_type2(tmp, &auth->flags)); | |
362 g_free(tmp); | |
363 } | |
364 if((tmp = parse_attribute("opaque=\"", parts[i]))) { | |
365 auth->opaque = tmp; | |
366 } | |
367 i++; | |
368 } | |
369 g_strfreev(parts); | |
11409 | 370 } |
371 return; | |
372 } | |
373 | |
374 auth->type = 1; | |
11439
617e67e1c985
[gaim-migrate @ 13676]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11424
diff
changeset
|
375 parts = g_strsplit(hdr, " ", 0); |
11346 | 376 while(parts[i]) { |
12746
4f7dab030b1a
[gaim-migrate @ 15093]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12745
diff
changeset
|
377 if((tmp = parse_attribute("nonce=\"", parts[i]))) { |
4f7dab030b1a
[gaim-migrate @ 15093]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12745
diff
changeset
|
378 auth->nonce = tmp; |
11346 | 379 } |
12746
4f7dab030b1a
[gaim-migrate @ 15093]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12745
diff
changeset
|
380 else if((tmp = parse_attribute("realm=\"", parts[i]))) { |
4f7dab030b1a
[gaim-migrate @ 15093]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12745
diff
changeset
|
381 auth->realm = tmp; |
11346 | 382 } |
383 i++; | |
384 } | |
11439
617e67e1c985
[gaim-migrate @ 13676]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11424
diff
changeset
|
385 g_strfreev(parts); |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
386 |
12745
e788741f4840
[gaim-migrate @ 15092]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12741
diff
changeset
|
387 gaim_debug(GAIM_DEBUG_MISC, "simple", "nonce: %s realm: %s ", auth->nonce ? auth->nonce : "(null)", auth->realm ? auth->realm : "(null)"); |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
388 |
12382
cfc808463763
[gaim-migrate @ 14688]
Richard Laager <rlaager@wiktel.com>
parents:
12216
diff
changeset
|
389 auth->digest_session_key = gaim_cipher_http_digest_calculate_session_key( |
13084 | 390 "md5", authuser, auth->realm, sip->password, auth->nonce, NULL); |
11346 | 391 |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
392 auth->nc = 1; |
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 | |
424 static void send_later_cb(gpointer data, gint source, GaimInputCondition cond) { | |
425 GaimConnection *gc = data; | |
426 struct simple_account_data *sip = gc->proto_data; | |
427 struct sip_connection *conn; | |
428 | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
429 if(source < 0) { |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
430 gaim_connection_error(gc, _("Could not connect")); |
11181 | 431 return; |
432 } | |
433 | |
434 sip->fd = source; | |
13058
256abf4dd912
[gaim-migrate @ 15420]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12909
diff
changeset
|
435 sip->connecting = FALSE; |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
436 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
437 simple_canwrite_cb(gc, sip->fd, GAIM_INPUT_WRITE); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
438 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
439 /* 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
|
440 if(sip->txbuf->bufused > 0) |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
441 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
|
442 simple_canwrite_cb, gc); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
443 |
11181 | 444 conn = connection_create(sip, source); |
445 conn->inputhandler = gaim_input_add(sip->fd, GAIM_INPUT_READ, simple_input_cb, gc); | |
446 } | |
447 | |
448 | |
449 static void sendlater(GaimConnection *gc, const char *buf) { | |
450 struct simple_account_data *sip = gc->proto_data; | |
451 int error = 0; | |
452 if(!sip->connecting) { | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
453 gaim_debug_info("simple", "connecting to %s port %d\n", sip->realhostname ? sip->realhostname : "{NULL}", sip->realport); |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
454 error = gaim_proxy_connect(sip->account, sip->realhostname, sip->realport, send_later_cb, gc); |
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
455 if(error) { |
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
456 gaim_connection_error(gc, _("Couldn't create socket")); |
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
457 } |
13058
256abf4dd912
[gaim-migrate @ 15420]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12909
diff
changeset
|
458 sip->connecting = TRUE; |
11181 | 459 } |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
460 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
461 if(gaim_circ_buffer_get_max_read(sip->txbuf) > 0) |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
462 gaim_circ_buffer_append(sip->txbuf, "\r\n", 2); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
463 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
464 gaim_circ_buffer_append(sip->txbuf, buf, strlen(buf)); |
11181 | 465 } |
466 | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
467 static void sendout_pkt(GaimConnection *gc, const char *buf) { |
11181 | 468 struct simple_account_data *sip = gc->proto_data; |
469 time_t currtime = time(NULL); | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
470 int writelen = strlen(buf); |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
471 |
11181 | 472 gaim_debug(GAIM_DEBUG_MISC, "simple", "\n\nsending - %s\n######\n%s\n######\n\n", ctime(&currtime), buf); |
11189 | 473 if(sip->udp) { |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
474 if(sendto(sip->fd, buf, writelen, 0, (struct sockaddr*)&sip->serveraddr, sizeof(struct sockaddr_in)) < writelen) { |
11189 | 475 gaim_debug_info("simple", "could not send packet\n"); |
476 } | |
477 } else { | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
478 int ret; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
479 if(sip->fd < 0) { |
11189 | 480 sendlater(gc, buf); |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
481 return; |
11189 | 482 } |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
483 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
484 if(sip->tx_handler) { |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
485 ret = -1; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
486 errno = EAGAIN; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
487 } else |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
488 ret = write(sip->fd, buf, writelen); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
489 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
490 if (ret < 0 && errno == EAGAIN) |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
491 ret = 0; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
492 else if(ret <= 0) { /* XXX: When does this happen legitimately? */ |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
493 sendlater(gc, buf); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
494 return; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
495 } |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
496 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
497 if (ret < writelen) { |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
498 if(!sip->tx_handler) |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
499 sip->tx_handler = gaim_input_add(sip->fd, |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
500 GAIM_INPUT_WRITE, simple_canwrite_cb, |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
501 gc); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
502 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
503 /* 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
|
504 with part of another. */ |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
505 if(sip->txbuf->bufused > 0) |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
506 gaim_circ_buffer_append(sip->txbuf, "\r\n", 2); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
507 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
508 gaim_circ_buffer_append(sip->txbuf, buf + ret, |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
509 writelen - ret); |
11189 | 510 } |
11181 | 511 } |
512 } | |
513 | |
11194 | 514 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
|
515 GSList *tmp = msg->headers; |
11194 | 516 gchar *name; |
517 gchar *value; | |
12741
2b61e6ed85c3
[gaim-migrate @ 15088]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12730
diff
changeset
|
518 GString *outstr = g_string_new(""); |
2b61e6ed85c3
[gaim-migrate @ 15088]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12730
diff
changeset
|
519 g_string_append_printf(outstr, "%s %s SIP/2.0\r\n", msg->method, msg->target); |
11194 | 520 while(tmp) { |
12741
2b61e6ed85c3
[gaim-migrate @ 15088]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12730
diff
changeset
|
521 name = ((struct siphdrelement*) (tmp->data))->name; |
2b61e6ed85c3
[gaim-migrate @ 15088]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12730
diff
changeset
|
522 value = ((struct siphdrelement*) (tmp->data))->value; |
2b61e6ed85c3
[gaim-migrate @ 15088]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12730
diff
changeset
|
523 g_string_append_printf(outstr, "%s: %s\r\n", name, value); |
11194 | 524 tmp = g_slist_next(tmp); |
525 } | |
12741
2b61e6ed85c3
[gaim-migrate @ 15088]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12730
diff
changeset
|
526 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
|
527 sendout_pkt(sip->gc, outstr->str); |
2b61e6ed85c3
[gaim-migrate @ 15088]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12730
diff
changeset
|
528 g_string_free(outstr, TRUE); |
11194 | 529 } |
530 | |
11181 | 531 static void send_sip_response(GaimConnection *gc, struct sipmsg *msg, int code, char *text, char *body) { |
532 GSList *tmp = msg->headers; | |
12741
2b61e6ed85c3
[gaim-migrate @ 15088]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12730
diff
changeset
|
533 gchar *name; |
2b61e6ed85c3
[gaim-migrate @ 15088]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12730
diff
changeset
|
534 gchar *value; |
2b61e6ed85c3
[gaim-migrate @ 15088]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12730
diff
changeset
|
535 GString *outstr = g_string_new(""); |
13092
edef744647ff
[gaim-migrate @ 15454]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13088
diff
changeset
|
536 |
12754 | 537 /* When sending the acknowlegements and errors, the content length from the original |
538 message is still here, but there is no body; we need to make sure we're sending the | |
539 correct content length */ | |
540 sipmsg_remove_header(msg, "Content-Length"); | |
541 if(body) { | |
542 gchar len[12]; | |
543 sprintf(len, "%" G_GSIZE_FORMAT , strlen(body)); | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
544 sipmsg_add_header(msg, "Content-Length", len); |
12754 | 545 } |
546 else | |
547 sipmsg_add_header(msg, "Content-Length", "0"); | |
12741
2b61e6ed85c3
[gaim-migrate @ 15088]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12730
diff
changeset
|
548 g_string_append_printf(outstr, "SIP/2.0 %d %s\r\n", code, text); |
11181 | 549 while(tmp) { |
12741
2b61e6ed85c3
[gaim-migrate @ 15088]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12730
diff
changeset
|
550 name = ((struct siphdrelement*) (tmp->data))->name; |
2b61e6ed85c3
[gaim-migrate @ 15088]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12730
diff
changeset
|
551 value = ((struct siphdrelement*) (tmp->data))->value; |
12745
e788741f4840
[gaim-migrate @ 15092]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12741
diff
changeset
|
552 |
12741
2b61e6ed85c3
[gaim-migrate @ 15088]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12730
diff
changeset
|
553 g_string_append_printf(outstr, "%s: %s\r\n", name, value); |
11181 | 554 tmp = g_slist_next(tmp); |
555 } | |
12741
2b61e6ed85c3
[gaim-migrate @ 15088]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12730
diff
changeset
|
556 g_string_append_printf(outstr, "\r\n%s", body ? body : ""); |
2b61e6ed85c3
[gaim-migrate @ 15088]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12730
diff
changeset
|
557 sendout_pkt(gc, outstr->str); |
2b61e6ed85c3
[gaim-migrate @ 15088]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12730
diff
changeset
|
558 g_string_free(outstr, TRUE); |
11181 | 559 } |
560 | |
11194 | 561 static void transactions_remove(struct simple_account_data *sip, struct transaction *trans) { |
562 if(trans->msg) sipmsg_free(trans->msg); | |
563 sip->transactions = g_slist_remove(sip->transactions, trans); | |
564 g_free(trans); | |
565 } | |
566 | |
11181 | 567 static void transactions_add_buf(struct simple_account_data *sip, gchar *buf, void *callback) { |
568 struct transaction *trans = g_new0(struct transaction, 1); | |
569 trans->time = time(NULL); | |
570 trans->msg = sipmsg_parse_msg(buf); | |
571 trans->cseq = sipmsg_find_header(trans->msg, "CSeq"); | |
572 trans->callback = callback; | |
573 sip->transactions = g_slist_append(sip->transactions, trans); | |
574 } | |
575 | |
576 static struct transaction *transactions_find(struct simple_account_data *sip, struct sipmsg *msg) { | |
577 struct transaction *trans; | |
578 GSList *transactions = sip->transactions; | |
579 gchar *cseq = sipmsg_find_header(msg, "CSeq"); | |
580 | |
581 while(transactions) { | |
582 trans = transactions->data; | |
583 if(!strcmp(trans->cseq, cseq)) { | |
584 return trans; | |
585 } | |
586 transactions = transactions->next; | |
587 } | |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
588 |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
589 return NULL; |
11181 | 590 } |
591 | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
592 static void send_sip_request(GaimConnection *gc, const gchar *method, |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
593 const gchar *url, const gchar *to, const gchar *addheaders, |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
594 const gchar *body, struct sip_dialog *dialog, TransCallback tc) { |
11181 | 595 struct simple_account_data *sip = gc->proto_data; |
13092
edef744647ff
[gaim-migrate @ 15454]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13088
diff
changeset
|
596 char *callid = dialog ? g_strdup(dialog->callid) : gencallid(); |
edef744647ff
[gaim-migrate @ 15454]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13088
diff
changeset
|
597 char *auth = ""; |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
598 const char *addh = ""; |
12216 | 599 gchar *branch = genbranch(); |
600 char *buf; | |
601 | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
602 if(!strcmp(method, "REGISTER")) { |
13092
edef744647ff
[gaim-migrate @ 15454]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13088
diff
changeset
|
603 if(sip->regcallid) { |
edef744647ff
[gaim-migrate @ 15454]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13088
diff
changeset
|
604 g_free(callid); |
edef744647ff
[gaim-migrate @ 15454]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13088
diff
changeset
|
605 callid = g_strdup(sip->regcallid); |
edef744647ff
[gaim-migrate @ 15454]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13088
diff
changeset
|
606 } |
12196 | 607 else sip->regcallid = g_strdup(callid); |
608 } | |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
609 |
13092
edef744647ff
[gaim-migrate @ 15454]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13088
diff
changeset
|
610 if(addheaders) addh = addheaders; |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
611 if(sip->registrar.type && !strcmp(method, "REGISTER")) { |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
612 buf = auth_header(sip, &sip->registrar, method, url); |
12563
b7f7f3a685ea
[gaim-migrate @ 14882]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12492
diff
changeset
|
613 auth = g_strdup_printf("Authorization: %s", buf); |
11346 | 614 g_free(buf); |
11181 | 615 gaim_debug(GAIM_DEBUG_MISC, "simple", "header %s", auth); |
616 } | |
617 | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
618 if(sip->proxy.type && strcmp(method, "REGISTER")) { |
11346 | 619 buf = auth_header(sip, &sip->proxy, method, url); |
12563
b7f7f3a685ea
[gaim-migrate @ 14882]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12492
diff
changeset
|
620 auth = g_strdup_printf("Proxy-Authorization: %s", buf); |
11346 | 621 g_free(buf); |
11181 | 622 gaim_debug(GAIM_DEBUG_MISC, "simple", "header %s", auth); |
623 } | |
12767
53218d758ba9
[gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12760
diff
changeset
|
624 |
11181 | 625 buf = g_strdup_printf("%s %s SIP/2.0\r\n" |
11190 | 626 "Via: SIP/2.0/%s %s:%d;branch=%s\r\n" |
13084 | 627 /* Don't know what epid is, but LCS wants it */ |
628 "From: <sip:%s@%s>;tag=%s;epid=1234567890\r\n" | |
11181 | 629 "To: <%s>%s%s\r\n" |
630 "Max-Forwards: 10\r\n" | |
631 "CSeq: %d %s\r\n" | |
632 "User-Agent: Gaim SIP/SIMPLE Plugin\r\n" | |
633 "Call-ID: %s\r\n" | |
634 "%s%s" | |
11658 | 635 "Content-Length: %" G_GSIZE_FORMAT "\r\n\r\n%s", |
11181 | 636 method, |
637 url, | |
11190 | 638 sip->udp ? "UDP" : "TCP", |
13129 | 639 gaim_network_get_my_ip(-1), |
11181 | 640 sip->listenport, |
641 branch, | |
642 sip->username, | |
643 sip->servername, | |
644 dialog ? dialog->ourtag : gentag(), | |
645 to, | |
646 dialog ? ";tag=" : "", | |
647 dialog ? dialog->theirtag : "", | |
648 ++sip->cseq, | |
649 method, | |
650 callid, | |
651 auth, | |
652 addh, | |
653 strlen(body), | |
654 body); | |
655 g_free(branch); | |
656 g_free(callid); | |
657 | |
11341 | 658 /* add to ongoing transactions */ |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
659 |
11181 | 660 transactions_add_buf(sip, buf, tc); |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
661 |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
662 sendout_pkt(gc, buf); |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
663 |
11181 | 664 g_free(buf); |
665 } | |
666 | |
13177 | 667 static char *get_contact(struct simple_account_data *sip) { |
668 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"); | |
669 } | |
670 | |
11194 | 671 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
|
672 char *uri = g_strdup_printf("sip:%s", sip->servername); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
673 char *to = g_strdup_printf("sip:%s@%s", sip->username, sip->servername); |
13177 | 674 char *contact = get_contact(sip); |
675 char *hdr = g_strdup_printf("Contact: %s\r\nExpires: %d\r\n", contact, expire); | |
676 g_free(contact); | |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
677 |
11439
617e67e1c985
[gaim-migrate @ 13676]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11424
diff
changeset
|
678 sip->registerstatus = 1; |
617e67e1c985
[gaim-migrate @ 13676]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11424
diff
changeset
|
679 |
11194 | 680 if(expire) { |
681 sip->reregister = time(NULL) + expire - 50; | |
682 } else { | |
683 sip->reregister = time(NULL) + 600; | |
684 } | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
685 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
686 send_sip_request(sip->gc, "REGISTER", uri, to, hdr, "", NULL, |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
687 process_register_response); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
688 |
13177 | 689 g_free(hdr); |
11181 | 690 g_free(uri); |
691 g_free(to); | |
692 } | |
693 | |
11194 | 694 static void do_register(struct simple_account_data *sip) { |
695 do_register_exp(sip, sip->registerexpire); | |
696 } | |
697 | |
11181 | 698 static gchar *parse_from(gchar *hdr) { |
699 gchar *from = hdr; | |
700 gchar *tmp; | |
701 | |
702 if(!from) return NULL; | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
703 gaim_debug_info("simple", "parsing address out of %s\n", from); |
11181 | 704 tmp = strchr(from, '<'); |
705 | |
11341 | 706 /* i hate the different SIP UA behaviours... */ |
707 if(tmp) { /* sip address in <...> */ | |
11181 | 708 from = tmp+1; |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
709 tmp = strchr(from, '>'); |
11181 | 710 if(tmp) { |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
711 from = g_strndup(from, tmp-from); |
11181 | 712 } else { |
713 gaim_debug_info("simple", "found < without > in From\n"); | |
714 return NULL; | |
715 } | |
716 } else { | |
717 tmp = strchr(from, ';'); | |
718 if(tmp) { | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
719 from = g_strndup(from, tmp-from); |
11483 | 720 } else { |
721 from = g_strdup(from); | |
11181 | 722 } |
723 } | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
724 gaim_debug_info("simple", "got %s\n", from); |
11181 | 725 return from; |
726 } | |
727 | |
728 static gboolean process_subscribe_response(struct simple_account_data *sip, struct sipmsg *msg, struct transaction *tc) { | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
729 gchar *to = parse_from(sipmsg_find_header(tc->msg, "To")); /* cant be NULL since it is our own msg */ |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
730 |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
731 if(msg->response == 200 || msg->response == 202) { |
11181 | 732 return TRUE; |
733 } | |
734 | |
11341 | 735 /* 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
|
736 |
11181 | 737 gaim_prpl_got_user_status(sip->account, to, "offline", NULL); |
738 g_free(to); | |
739 return TRUE; | |
740 } | |
741 | |
742 static void simple_subscribe(struct simple_account_data *sip, struct simple_buddy *buddy) { | |
13177 | 743 gchar *contact = "Expires: 300\r\nAccept: application/pidf+xml, application/xpidf+xml\r\nEvent: presence\r\n"; |
11181 | 744 gchar *to; |
13177 | 745 gchar *tmp; |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
746 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
747 if(strstr(buddy->name,"sip:")) |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
748 to = g_strdup(buddy->name); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
749 else |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
750 to = g_strdup_printf("sip:%s", buddy->name); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
751 |
13177 | 752 tmp = get_contact(sip); |
753 contact = g_strdup_printf("%sContact: %s\r\n", contact, tmp); | |
754 g_free(tmp); | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
755 |
11341 | 756 /* subscribe to buddy presence |
757 * 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
|
758 |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
759 send_sip_request(sip->gc, "SUBSCRIBE", to, to, contact, "", NULL, |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
760 process_subscribe_response); |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
761 |
11181 | 762 g_free(to); |
11341 | 763 g_free(contact); |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
764 |
11341 | 765 /* resubscribe before subscription expires */ |
766 /* add some jitter */ | |
767 buddy->resubscribe = time(NULL)+250+(rand()%50); | |
11181 | 768 } |
769 | |
770 static void simple_buddy_resub(char *name, struct simple_buddy *buddy, struct simple_account_data *sip) { | |
771 time_t curtime = time(NULL); | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
772 gaim_debug_info("simple", "buddy resub\n"); |
11181 | 773 if(buddy->resubscribe < curtime) { |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
774 gaim_debug(GAIM_DEBUG_MISC, "simple", "simple_buddy_resub %s\n", name); |
11181 | 775 simple_subscribe(sip, buddy); |
776 } | |
777 } | |
778 | |
11194 | 779 static gboolean resend_timeout(struct simple_account_data *sip) { |
780 GSList *tmp = sip->transactions; | |
781 time_t currtime = time(NULL); | |
782 while(tmp) { | |
783 struct transaction *trans = tmp->data; | |
784 tmp = tmp->next; | |
785 gaim_debug_info("simple", "have open transaction age: %d\n", currtime- trans->time); | |
786 if((currtime - trans->time > 5) && trans->retries >= 1) { | |
11341 | 787 /* TODO 408 */ |
11194 | 788 } else { |
789 if((currtime - trans->time > 2) && trans->retries == 0) { | |
790 trans->retries++; | |
791 sendout_sipmsg(sip, trans->msg); | |
792 } | |
793 } | |
794 } | |
795 return TRUE; | |
796 } | |
797 | |
12768 | 798 static gboolean subscribe_timeout(struct simple_account_data *sip) { |
11181 | 799 GSList *tmp; |
800 time_t curtime = time(NULL); | |
11341 | 801 /* register again if first registration expires */ |
11181 | 802 if(sip->reregister < curtime) { |
11194 | 803 do_register(sip); |
11181 | 804 } |
11341 | 805 /* check for every subscription if we need to resubscribe */ |
11181 | 806 g_hash_table_foreach(sip->buddies, (GHFunc)simple_buddy_resub, (gpointer)sip); |
807 | |
11341 | 808 /* remove a timed out suscriber */ |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
809 |
11181 | 810 tmp = sip->watcher; |
811 while(tmp) { | |
812 struct simple_watcher *watcher = tmp->data; | |
813 if(watcher->expire < curtime) { | |
814 watcher_remove(sip, watcher->name); | |
815 tmp = sip->watcher; | |
816 } | |
817 if(tmp) tmp = tmp->next; | |
818 } | |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
819 |
11181 | 820 return TRUE; |
821 } | |
822 | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
823 static void simple_send_message(struct simple_account_data *sip, const char *to, const char *msg, const char *type) { |
11181 | 824 gchar *hdr; |
13184 | 825 gchar *fullto; |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
826 if(strncmp("sip:", to, 4)) { |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
827 fullto = g_strdup_printf("sip:%s", to); |
13184 | 828 } else { |
829 fullto = g_strdup(to); | |
830 } | |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
831 if(type) { |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
832 hdr = g_strdup_printf("Content-Type: %s\r\n", type); |
11181 | 833 } else { |
834 hdr = g_strdup("Content-Type: text/plain\r\n"); | |
835 } | |
13184 | 836 send_sip_request(sip->gc, "MESSAGE", fullto, fullto, hdr, msg, NULL, NULL); |
11181 | 837 g_free(hdr); |
13184 | 838 g_free(fullto); |
11181 | 839 } |
840 | |
12216 | 841 static int simple_im_send(GaimConnection *gc, const char *who, const char *what, GaimMessageFlags flags) { |
11181 | 842 struct simple_account_data *sip = gc->proto_data; |
843 char *to = g_strdup(who); | |
12216 | 844 char *text = gaim_unescape_html(what); |
11181 | 845 simple_send_message(sip, to, text, NULL); |
846 g_free(to); | |
847 g_free(text); | |
848 return 1; | |
849 } | |
850 | |
851 static void process_incoming_message(struct simple_account_data *sip, struct sipmsg *msg) { | |
852 gchar *from; | |
853 gchar *contenttype; | |
854 gboolean found = FALSE; | |
855 | |
856 from = parse_from(sipmsg_find_header(msg, "From")); | |
857 | |
858 if(!from) return; | |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
859 |
11181 | 860 gaim_debug(GAIM_DEBUG_MISC, "simple", "got message from %s: %s\n", from, msg->body); |
861 | |
862 contenttype = sipmsg_find_header(msg, "Content-Type"); | |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
863 if(!contenttype || !strncmp(contenttype, "text/plain", 10) || !strncmp(contenttype, "text/html", 9)) { |
11181 | 864 serv_got_im(sip->gc, from, msg->body, 0, time(NULL)); |
865 send_sip_response(sip->gc, msg, 200, "OK", NULL); | |
866 found = TRUE; | |
867 } | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
868 if(!strncmp(contenttype, "application/im-iscomposing+xml", 30)) { |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
869 xmlnode *isc = xmlnode_from_str(msg->body, msg->bodylen); |
11181 | 870 xmlnode *state; |
871 gchar *statedata; | |
872 | |
873 if(!isc) { | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
874 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
|
875 return; |
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
876 } |
11181 | 877 |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
878 state = xmlnode_get_child(isc, "state"); |
11181 | 879 |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
880 if(!state) { |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
881 gaim_debug_info("simple", "process_incoming_message: no state found\n"); |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
882 return; |
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
883 } |
11181 | 884 |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
885 statedata = xmlnode_get_data(state); |
11181 | 886 if(statedata) { |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
887 if(strstr(statedata, "active")) serv_got_typing(sip->gc, from, 0, GAIM_TYPING); |
11181 | 888 else serv_got_typing_stopped(sip->gc, from); |
889 } | |
890 xmlnode_free(isc); | |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
891 send_sip_response(sip->gc, msg, 200, "OK", NULL); |
11181 | 892 found = TRUE; |
893 } | |
894 if(!found) { | |
895 gaim_debug_info("simple", "got unknown mime-type"); | |
896 send_sip_response(sip->gc, msg, 415, "Unsupported media type", NULL); | |
897 } | |
898 g_free(from); | |
899 } | |
900 | |
901 | |
902 gboolean process_register_response(struct simple_account_data *sip, struct sipmsg *msg, struct transaction *tc) { | |
903 gchar *tmp; | |
904 gaim_debug(GAIM_DEBUG_MISC, "simple", "in process register response response: %d\n", msg->response); | |
905 switch (msg->response) { | |
906 case 200: | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
907 if(sip->registerstatus < 3) { /* registered */ |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
908 if(gaim_account_get_bool(sip->account, "dopublish", TRUE)) { |
11345 | 909 send_publish(sip); |
910 } | |
11181 | 911 } |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
912 sip->registerstatus = 3; |
11181 | 913 gaim_connection_set_state(sip->gc, GAIM_CONNECTED); |
11341 | 914 |
915 /* get buddies from blist */ | |
916 simple_get_buddies(sip->gc); | |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
917 |
12768 | 918 subscribe_timeout(sip); |
11181 | 919 break; |
920 case 401: | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
921 if(sip->registerstatus != 2) { |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
922 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
|
923 if(sip->registrar.retries > 3) { |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
924 gaim_connection_error(sip->gc, _("Wrong Password")); |
11346 | 925 return TRUE; |
926 } | |
11181 | 927 tmp = sipmsg_find_header(msg, "WWW-Authenticate"); |
928 fill_auth(sip, tmp, &sip->registrar); | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
929 sip->registerstatus = 2; |
11194 | 930 do_register(sip); |
11181 | 931 } |
932 break; | |
933 } | |
934 return TRUE; | |
935 } | |
936 | |
937 static void process_incoming_notify(struct simple_account_data *sip, struct sipmsg *msg) { | |
938 gchar *from; | |
939 gchar *fromhdr; | |
940 gchar *tmp2; | |
941 xmlnode *pidf; | |
942 xmlnode *basicstatus; | |
943 gboolean isonline = FALSE; | |
944 | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
945 fromhdr = sipmsg_find_header(msg, "From"); |
11181 | 946 from = parse_from(fromhdr); |
947 if(!from) return; | |
948 | |
949 pidf = xmlnode_from_str(msg->body, msg->bodylen); | |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
950 |
11181 | 951 if(!pidf) { |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
952 gaim_debug_info("simple", "process_incoming_notify: no parseable pidf\n"); |
11181 | 953 return; |
954 } | |
955 | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
956 basicstatus = xmlnode_get_child(xmlnode_get_child(xmlnode_get_child(pidf, "tuple"), "status"), "basic"); |
11181 | 957 |
958 if(!basicstatus) { | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
959 gaim_debug_info("simple", "process_incoming_notify: no basic found\n"); |
11181 | 960 return; |
961 } | |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
962 |
11181 | 963 tmp2 = xmlnode_get_data(basicstatus); |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
964 |
11181 | 965 if(!tmp2) { |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
966 gaim_debug_info("simple", "process_incoming_notify: no basic data found\n"); |
11181 | 967 return; |
968 } | |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
969 |
11181 | 970 if(strstr(tmp2, "open")) { |
971 isonline = TRUE; | |
972 } | |
973 | |
974 if(isonline) gaim_prpl_got_user_status(sip->account, from, "available", NULL); | |
975 else gaim_prpl_got_user_status(sip->account, from, "offline", NULL); | |
976 | |
977 xmlnode_free(pidf); | |
978 | |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
979 g_free(from); |
11181 | 980 send_sip_response(sip->gc, msg, 200, "OK", NULL); |
981 } | |
982 | |
983 static int simple_typing(GaimConnection *gc, const char *name, int typing) { | |
984 struct simple_account_data *sip = gc->proto_data; | |
985 | |
986 gchar *xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" | |
987 "<isComposing xmlns=\"urn:ietf:params:xml:ns:im-iscomposing\"\n" | |
988 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" | |
989 "xsi:schemaLocation=\"urn:ietf:params:xml:ns:im-composing iscomposing.xsd\">\n" | |
990 "<state>%s</state>\n" | |
991 "<contenttype>text/plain</contenttype>\n" | |
992 "<refresh>60</refresh>\n" | |
993 "</isComposing>"; | |
994 gchar *recv = g_strdup(name); | |
995 if(typing == GAIM_TYPING) { | |
996 gchar *msg = g_strdup_printf(xml, "active"); | |
997 simple_send_message(sip, recv, msg, "application/im-iscomposing+xml"); | |
998 g_free(msg); | |
999 } else { | |
1000 gchar *msg = g_strdup_printf(xml, "idle"); | |
1001 simple_send_message(sip, recv, msg, "application/im-iscomposing+xml"); | |
1002 g_free(msg); | |
1003 } | |
1004 g_free(recv); | |
1005 return 1; | |
1006 } | |
1007 | |
1008 static gchar *find_tag(gchar *hdr) { | |
1009 gchar *tmp = strstr(hdr, ";tag="); | |
1010 gchar *tmp2; | |
1011 if(!tmp) return NULL; | |
1012 tmp += 5; | |
1013 if((tmp2 = strchr(tmp, ';'))) { | |
1014 tmp2[0] = '\0'; | |
1015 tmp = g_strdup(tmp); | |
1016 tmp2[0] = ';'; | |
1017 return tmp; | |
1018 } | |
1019 return g_strdup(tmp); | |
1020 } | |
1021 | |
13177 | 1022 static gchar* gen_xpidf(struct simple_account_data *sip) { |
1023 gchar *doc = g_strdup_printf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" | |
1024 "<presence>\n" | |
1025 "<presentity uri=\"sip:%s@%s;method=SUBSCRIBE\"/>\n" | |
1026 "<display name=\"sip:%s@%s\"/>\n" | |
1027 "<atom id=\"1234\">\n" | |
1028 "<address uri=\"sip:%s@%s\">\n" | |
1029 "<status status=\"%s\"/>\n" | |
1030 "</address>\n" | |
1031 "</atom>\n" | |
1032 "</presence>\n", | |
1033 sip->username, | |
1034 sip->servername, | |
1035 sip->username, | |
1036 sip->servername, | |
1037 sip->username, | |
1038 sip->servername, | |
1039 sip->status); | |
1040 return doc; | |
1041 } | |
1042 | |
1043 | |
1044 | |
11181 | 1045 static gchar* gen_pidf(struct simple_account_data *sip) { |
1046 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
|
1047 "<presence xmlns=\"urn:ietf:params:xml:ns:pidf\"\n" |
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
1048 "xmlns:im=\"urn:ietf:params:xml:ns:pidf:im\"\n" |
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
1049 "entity=\"sip:%s@%s\">\n" |
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
1050 "<tuple id=\"bs35r9f\">\n" |
11181 | 1051 "<status>\n" |
1052 "<basic>open</basic>\n" | |
1053 "<im:im>%s</im:im>\n" | |
1054 "</status>\n" | |
1055 "</tuple>\n" | |
1056 "</presence>", | |
1057 sip->username, | |
1058 sip->servername, | |
1059 sip->status); | |
1060 return doc; | |
1061 } | |
1062 | |
1063 static void send_notify(struct simple_account_data *sip, struct simple_watcher *watcher) { | |
13177 | 1064 gchar *doc = watcher->needsxpidf ? gen_xpidf(sip) : gen_pidf(sip); |
1065 gchar *hdr = watcher->needsxpidf ? "Event: presence\r\nContent-Type: application/xpidf+xml\r\n" : "Event: presence\r\nContent-Type: application/pidf+xml\r\n"; | |
1066 send_sip_request(sip->gc, "NOTIFY", watcher->name, watcher->name, hdr, doc, &watcher->dialog, NULL); | |
11181 | 1067 g_free(doc); |
1068 } | |
1069 | |
1070 static gboolean process_publish_response(struct simple_account_data *sip, struct sipmsg *msg, struct transaction *tc) { | |
11345 | 1071 if(msg->response != 200 && msg->response != 408) { |
11341 | 1072 /* never send again */ |
11181 | 1073 sip->republish = -1; |
1074 } | |
1075 return TRUE; | |
1076 } | |
1077 | |
1078 static void send_publish(struct simple_account_data *sip) { | |
1079 gchar *uri = g_strdup_printf("sip:%s@%s", sip->username, sip->servername); | |
1080 gchar *doc = gen_pidf(sip); | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
1081 send_sip_request(sip->gc, "PUBLISH", uri, uri, |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
1082 "Expires: 600\r\nEvent: presence\r\n" |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
1083 "Content-Type: application/pidf+xml\r\n", |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
1084 doc, NULL, process_publish_response); |
11181 | 1085 sip->republish = time(NULL) + 500; |
1086 g_free(doc); | |
1087 } | |
1088 | |
1089 static void process_incoming_subscribe(struct simple_account_data *sip, struct sipmsg *msg) { | |
1090 gchar *from = parse_from(sipmsg_find_header(msg, "From")); | |
1091 gchar *theirtag = find_tag(sipmsg_find_header(msg, "From")); | |
1092 gchar *ourtag = find_tag(sipmsg_find_header(msg, "To")); | |
1093 gboolean tagadded = FALSE; | |
1094 gchar *callid = sipmsg_find_header(msg, "Call-ID"); | |
1095 gchar *expire = sipmsg_find_header(msg, "Expire"); | |
1096 gchar *tmp; | |
1097 struct simple_watcher *watcher = watcher_find(sip, from); | |
1098 if(!ourtag) { | |
1099 tagadded = TRUE; | |
1100 ourtag = gentag(); | |
1101 } | |
11341 | 1102 if(!watcher) { /* new subscription */ |
13177 | 1103 gchar *acceptheader = sipmsg_find_header(msg, "Accept"); |
1104 int needsxpidf = 0; | |
11345 | 1105 if(!gaim_privacy_check(sip->account, from)) { |
1106 send_sip_response(sip->gc, msg, 202, "Ok", NULL); | |
1107 goto privend; | |
1108 } | |
13177 | 1109 if(acceptheader) { |
1110 gchar *tmp = acceptheader; | |
1111 int foundpidf = 0; | |
1112 int foundxpidf = 0; | |
1113 while(tmp && tmp < acceptheader + strlen(acceptheader)) { | |
1114 gchar *tmp2 = strchr(tmp, ','); | |
1115 if(tmp2) *tmp2 = '\0'; | |
1116 if(!strcmp("application/pidf+xml",tmp)) | |
1117 foundpidf = 1; | |
1118 if(!strcmp("application/xpidf+xml",tmp)) | |
1119 foundxpidf = 1; | |
1120 if(tmp2) { | |
1121 *tmp2 = ','; | |
1122 tmp = tmp2; | |
1123 while(*tmp == ' ') tmp++; | |
1124 } else | |
1125 tmp = 0; | |
1126 } | |
1127 if(!foundpidf && foundxpidf) needsxpidf = 1; | |
1128 g_free(acceptheader); | |
1129 } | |
1130 watcher = watcher_create(sip, from, callid, ourtag, theirtag, needsxpidf); | |
11181 | 1131 } |
1132 if(tagadded) { | |
1133 gchar *to = g_strdup_printf("%s;tag=%s", sipmsg_find_header(msg, "To"), ourtag); | |
1134 sipmsg_remove_header(msg, "To"); | |
1135 sipmsg_add_header(msg, "To", to); | |
1136 } | |
1137 if(expire) | |
1138 watcher->expire = time(NULL) + strtol(expire, NULL, 10); | |
1139 else | |
1140 watcher->expire = time(NULL) + 600; | |
1141 sipmsg_remove_header(msg, "Contact"); | |
13177 | 1142 tmp = get_contact(sip); |
11181 | 1143 sipmsg_add_header(msg, "Contact", tmp); |
13177 | 1144 g_free(tmp); |
11181 | 1145 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); |
1146 send_sip_response(sip->gc, msg, 200, "Ok", NULL); | |
1147 send_notify(sip, watcher); | |
11345 | 1148 privend: |
1149 g_free(from); | |
1150 g_free(theirtag); | |
1151 g_free(ourtag); | |
1152 g_free(callid); | |
1153 g_free(expire); | |
11181 | 1154 } |
1155 | |
11189 | 1156 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
|
1157 gboolean found = FALSE; |
e788741f4840
[gaim-migrate @ 15092]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12741
diff
changeset
|
1158 if(msg->response == 0) { /* request */ |
11189 | 1159 if(!strcmp(msg->method, "MESSAGE")) { |
1160 process_incoming_message(sip, msg); | |
12745
e788741f4840
[gaim-migrate @ 15092]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12741
diff
changeset
|
1161 found = TRUE; |
e788741f4840
[gaim-migrate @ 15092]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12741
diff
changeset
|
1162 } else if(!strcmp(msg->method, "NOTIFY")) { |
11189 | 1163 process_incoming_notify(sip, msg); |
12745
e788741f4840
[gaim-migrate @ 15092]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12741
diff
changeset
|
1164 found = TRUE; |
e788741f4840
[gaim-migrate @ 15092]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12741
diff
changeset
|
1165 } else if(!strcmp(msg->method, "SUBSCRIBE")) { |
11189 | 1166 process_incoming_subscribe(sip, msg); |
12745
e788741f4840
[gaim-migrate @ 15092]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12741
diff
changeset
|
1167 found = TRUE; |
e788741f4840
[gaim-migrate @ 15092]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12741
diff
changeset
|
1168 } else { |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
1169 send_sip_response(sip->gc, msg, 501, "Not implemented", NULL); |
11190 | 1170 } |
11341 | 1171 } else { /* response */ |
11189 | 1172 struct transaction *trans = transactions_find(sip, msg); |
1173 if(trans) { | |
1174 if(msg->response == 407) { | |
11439
617e67e1c985
[gaim-migrate @ 13676]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11424
diff
changeset
|
1175 gchar *resend, *auth, *ptmp; |
617e67e1c985
[gaim-migrate @ 13676]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11424
diff
changeset
|
1176 |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
1177 if(sip->proxy.retries > 3) return; |
11346 | 1178 sip->proxy.retries++; |
11341 | 1179 /* do proxy authentication */ |
11189 | 1180 |
11439
617e67e1c985
[gaim-migrate @ 13676]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11424
diff
changeset
|
1181 ptmp = sipmsg_find_header(msg, "Proxy-Authenticate"); |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
1182 |
11189 | 1183 fill_auth(sip, ptmp, &sip->proxy); |
11346 | 1184 auth = auth_header(sip, &sip->proxy, trans->msg->method, trans->msg->target); |
13272 | 1185 sipmsg_remove_header(trans->msg, "Proxy-Authorization"); |
11189 | 1186 sipmsg_add_header(trans->msg, "Proxy-Authorization", auth); |
1187 g_free(auth); | |
1188 resend = sipmsg_to_string(trans->msg); | |
11341 | 1189 /* resend request */ |
11189 | 1190 sendout_pkt(sip->gc, resend); |
1191 g_free(resend); | |
1192 } else { | |
11517 | 1193 if(msg->response == 100) { |
1194 /* ignore provisional response */ | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
1195 gaim_debug_info("simple", "got trying response\n"); |
11517 | 1196 } else { |
1197 sip->proxy.retries = 0; | |
1198 if(msg->response == 401) sip->registrar.retries++; | |
1199 else sip->registrar.retries = 0; | |
1200 if(trans->callback) { | |
1201 /* call the callback to process response*/ | |
1202 (trans->callback)(sip, msg, trans); | |
1203 } | |
1204 transactions_remove(sip, trans); | |
11189 | 1205 } |
1206 } | |
12745
e788741f4840
[gaim-migrate @ 15092]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12741
diff
changeset
|
1207 found = TRUE; |
11189 | 1208 } else { |
1209 gaim_debug(GAIM_DEBUG_MISC, "simple", "received response to unknown transaction"); | |
1210 } | |
1211 } | |
1212 if(!found) { | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
1213 gaim_debug(GAIM_DEBUG_MISC, "simple", "received a unknown sip message with method %s and response %d\n", msg->method, msg->response); |
11189 | 1214 } |
1215 } | |
1216 | |
11181 | 1217 static void process_input(struct simple_account_data *sip, struct sip_connection *conn) |
1218 { | |
1219 char *cur; | |
1220 char *dummy; | |
1221 struct sipmsg *msg; | |
1222 int restlen; | |
1223 cur = conn->inbuf; | |
1224 | |
11341 | 1225 /* according to the RFC remove CRLF at the beginning */ |
11181 | 1226 while(*cur == '\r' || *cur == '\n') { |
1227 cur++; | |
1228 } | |
1229 if(cur != conn->inbuf) { | |
1230 memmove(conn->inbuf, cur, conn->inbufused-(cur-conn->inbuf)); | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
1231 conn->inbufused = strlen(conn->inbuf); |
11181 | 1232 } |
1233 | |
11341 | 1234 /* Received a full Header? */ |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
1235 if((cur = strstr(conn->inbuf, "\r\n\r\n")) != NULL) { |
11181 | 1236 time_t currtime = time(NULL); |
1237 cur += 2; | |
1238 cur[0] = '\0'; | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
1239 gaim_debug_info("simple", "\n\nreceived - %s\n######\n%s\n#######\n\n", ctime(&currtime), conn->inbuf); |
11181 | 1240 msg = sipmsg_parse_header(conn->inbuf); |
1241 cur[0] = '\r'; | |
1242 cur += 2; | |
1243 restlen = conn->inbufused - (cur-conn->inbuf); | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
1244 if(restlen >= msg->bodylen) { |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
1245 dummy = g_malloc(msg->bodylen + 1); |
11181 | 1246 memcpy(dummy, cur, msg->bodylen); |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
1247 dummy[msg->bodylen] = '\0'; |
11181 | 1248 msg->body = dummy; |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
1249 cur += msg->bodylen; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
1250 memmove(conn->inbuf, cur, conn->inbuflen - (cur - conn->inbuf)); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
1251 conn->inbufused = strlen(conn->inbuf); |
11181 | 1252 } else { |
1253 sipmsg_free(msg); | |
1254 return; | |
1255 } | |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
1256 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
|
1257 process_input_message(sip, msg); |
11181 | 1258 } else { |
1259 gaim_debug(GAIM_DEBUG_MISC, "simple", "received a incomplete sip msg: %s\n", conn->inbuf); | |
1260 } | |
1261 } | |
1262 | |
11189 | 1263 static void simple_udp_process(gpointer data, gint source, GaimInputCondition con) { |
1264 GaimConnection *gc = data; | |
1265 struct simple_account_data *sip = gc->proto_data; | |
1266 struct sipmsg *msg; | |
1267 int len; | |
1268 time_t currtime; | |
1269 | |
1270 static char buffer[65536]; | |
12770
ab00cea25ef2
[gaim-migrate @ 15117]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12769
diff
changeset
|
1271 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
|
1272 buffer[len] = '\0'; |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
1273 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
|
1274 msg = sipmsg_parse_msg(buffer); |
dd271caf25b0
[gaim-migrate @ 15095]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12746
diff
changeset
|
1275 if(msg) process_input_message(sip, msg); |
dd271caf25b0
[gaim-migrate @ 15095]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12746
diff
changeset
|
1276 } |
11189 | 1277 } |
1278 | |
11181 | 1279 static void simple_input_cb(gpointer data, gint source, GaimInputCondition cond) |
1280 { | |
1281 GaimConnection *gc = data; | |
1282 struct simple_account_data *sip = gc->proto_data; | |
1283 int len; | |
1284 struct sip_connection *conn = connection_find(sip, source); | |
1285 if(!conn) { | |
1286 gaim_debug_error("simple", "Connection not found!\n"); | |
1287 return; | |
1288 } | |
1289 | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
1290 if(conn->inbuflen < conn->inbufused + SIMPLE_BUF_INC) { |
11181 | 1291 conn->inbuflen += SIMPLE_BUF_INC; |
1292 conn->inbuf = g_realloc(conn->inbuf, conn->inbuflen); | |
1293 } | |
1294 | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
1295 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
|
1296 |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
1297 if(len < 0 && errno == EAGAIN) |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
1298 return; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
1299 else if(len <= 0) { |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
1300 gaim_debug_info("simple", "simple_input_cb: read error\n"); |
11181 | 1301 connection_remove(sip, source); |
1302 if(sip->fd == source) sip->fd = -1; | |
1303 return; | |
1304 } | |
1305 | |
1306 conn->inbufused += len; | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
1307 conn->inbuf[conn->inbufused] = '\0'; |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
1308 |
11181 | 1309 process_input(sip, conn); |
1310 } | |
1311 | |
1312 /* Callback for new connections on incoming TCP port */ | |
1313 static void simple_newconn_cb(gpointer data, gint source, GaimInputCondition cond) { | |
1314 GaimConnection *gc = data; | |
1315 struct simple_account_data *sip = gc->proto_data; | |
1316 struct sip_connection *conn; | |
1317 | |
1318 int newfd = accept(source, NULL, NULL); | |
1319 | |
1320 conn = connection_create(sip, newfd); | |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
1321 |
11181 | 1322 conn->inputhandler = gaim_input_add(newfd, GAIM_INPUT_READ, simple_input_cb, gc); |
1323 } | |
1324 | |
1325 static void login_cb(gpointer data, gint source, GaimInputCondition cond) { | |
1326 GaimConnection *gc = data; | |
1327 struct simple_account_data *sip = gc->proto_data; | |
1328 struct sip_connection *conn; | |
1329 | |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
1330 if(source < 0) { |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
1331 gaim_connection_error(gc, _("Could not connect")); |
11181 | 1332 return; |
1333 } | |
1334 | |
1335 sip->fd = source; | |
1336 | |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
1337 conn = connection_create(sip, source); |
13092
edef744647ff
[gaim-migrate @ 15454]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13088
diff
changeset
|
1338 |
12768 | 1339 sip->registertimeout = gaim_timeout_add((rand()%100)+10*1000, (GSourceFunc)subscribe_timeout, sip); |
11181 | 1340 |
11194 | 1341 do_register(sip); |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
1342 |
11181 | 1343 conn->inputhandler = gaim_input_add(sip->fd, GAIM_INPUT_READ, simple_input_cb, gc); |
1344 } | |
1345 | |
1346 static guint simple_ht_hash_nick(const char *nick) { | |
1347 char *lc = g_utf8_strdown(nick, -1); | |
1348 guint bucket = g_str_hash(lc); | |
1349 g_free(lc); | |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
1350 |
11181 | 1351 return bucket; |
1352 } | |
1353 | |
1354 static gboolean simple_ht_equals_nick(const char *nick1, const char *nick2) { | |
1355 return (gaim_utf8_strcasecmp(nick1, nick2) == 0); | |
1356 } | |
1357 | |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12770
diff
changeset
|
1358 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
|
1359 struct simple_account_data *sip = (struct simple_account_data*) data; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12770
diff
changeset
|
1360 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12770
diff
changeset
|
1361 if(listenfd == -1) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12770
diff
changeset
|
1362 gaim_connection_error(sip->gc, _("Could not create listen socket")); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12770
diff
changeset
|
1363 return; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12770
diff
changeset
|
1364 } |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12770
diff
changeset
|
1365 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12770
diff
changeset
|
1366 sip->fd = listenfd; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12770
diff
changeset
|
1367 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12770
diff
changeset
|
1368 sip->listenport = gaim_network_get_port_from_fd(sip->fd); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12770
diff
changeset
|
1369 sip->listenfd = sip->fd; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12770
diff
changeset
|
1370 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12770
diff
changeset
|
1371 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
|
1372 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12770
diff
changeset
|
1373 sip->resendtimeout = gaim_timeout_add(2500, (GSourceFunc) resend_timeout, sip); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12770
diff
changeset
|
1374 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
|
1375 do_register(sip); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12770
diff
changeset
|
1376 } |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12770
diff
changeset
|
1377 |
12767
53218d758ba9
[gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12760
diff
changeset
|
1378 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
|
1379 struct simple_account_data *sip = (struct simple_account_data*) data; |
53218d758ba9
[gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12760
diff
changeset
|
1380 int addr_size; |
53218d758ba9
[gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12760
diff
changeset
|
1381 |
53218d758ba9
[gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12760
diff
changeset
|
1382 if (!hosts || !hosts->data) { |
53218d758ba9
[gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12760
diff
changeset
|
1383 gaim_connection_error(sip->gc, _("Couldn't resolve host")); |
53218d758ba9
[gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12760
diff
changeset
|
1384 return; |
53218d758ba9
[gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12760
diff
changeset
|
1385 } |
53218d758ba9
[gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12760
diff
changeset
|
1386 |
53218d758ba9
[gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12760
diff
changeset
|
1387 addr_size = GPOINTER_TO_INT(hosts->data); |
53218d758ba9
[gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12760
diff
changeset
|
1388 hosts = g_slist_remove(hosts, hosts->data); |
53218d758ba9
[gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12760
diff
changeset
|
1389 memcpy(&(sip->serveraddr), hosts->data, addr_size); |
53218d758ba9
[gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12760
diff
changeset
|
1390 g_free(hosts->data); |
53218d758ba9
[gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12760
diff
changeset
|
1391 hosts = g_slist_remove(hosts, hosts->data); |
53218d758ba9
[gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12760
diff
changeset
|
1392 while(hosts) { |
53218d758ba9
[gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12760
diff
changeset
|
1393 hosts = g_slist_remove(hosts, hosts->data); |
53218d758ba9
[gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12760
diff
changeset
|
1394 g_free(hosts->data); |
53218d758ba9
[gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12760
diff
changeset
|
1395 hosts = g_slist_remove(hosts, hosts->data); |
53218d758ba9
[gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12760
diff
changeset
|
1396 } |
53218d758ba9
[gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12760
diff
changeset
|
1397 |
53218d758ba9
[gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12760
diff
changeset
|
1398 /* create socket for incoming connections */ |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12770
diff
changeset
|
1399 if(!gaim_network_listen_range(5060, 5160, SOCK_DGRAM, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12770
diff
changeset
|
1400 simple_udp_host_resolved_listen_cb, sip)) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12770
diff
changeset
|
1401 gaim_connection_error(sip->gc, _("Could not create listen socket")); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12770
diff
changeset
|
1402 return; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12770
diff
changeset
|
1403 } |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12770
diff
changeset
|
1404 } |
12767
53218d758ba9
[gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12760
diff
changeset
|
1405 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12770
diff
changeset
|
1406 static void |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12770
diff
changeset
|
1407 simple_tcp_connect_listen_cb(int listenfd, gpointer data) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12770
diff
changeset
|
1408 struct simple_account_data *sip = (struct simple_account_data*) data; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12770
diff
changeset
|
1409 int error = 0; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12770
diff
changeset
|
1410 |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12770
diff
changeset
|
1411 sip->listenfd = listenfd; |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12770
diff
changeset
|
1412 if(sip->listenfd == -1) { |
12767
53218d758ba9
[gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12760
diff
changeset
|
1413 gaim_connection_error(sip->gc, _("Could not create listen socket")); |
53218d758ba9
[gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12760
diff
changeset
|
1414 return; |
53218d758ba9
[gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12760
diff
changeset
|
1415 } |
53218d758ba9
[gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12760
diff
changeset
|
1416 |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12770
diff
changeset
|
1417 gaim_debug_info("simple", "listenfd: %d\n", sip->listenfd); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12770
diff
changeset
|
1418 sip->listenport = gaim_network_get_port_from_fd(sip->listenfd); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12770
diff
changeset
|
1419 sip->listenpa = gaim_input_add(sip->listenfd, GAIM_INPUT_READ, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12770
diff
changeset
|
1420 simple_newconn_cb, sip->gc); |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
1421 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
|
1422 sip->realhostname, sip->realport); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12770
diff
changeset
|
1423 /* open tcp connection to the server */ |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12770
diff
changeset
|
1424 error = gaim_proxy_connect(sip->account, sip->realhostname, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12770
diff
changeset
|
1425 sip->realport, login_cb, sip->gc); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12770
diff
changeset
|
1426 if(error) { |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12770
diff
changeset
|
1427 gaim_connection_error(sip->gc, _("Couldn't create socket")); |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12770
diff
changeset
|
1428 } |
12767
53218d758ba9
[gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12760
diff
changeset
|
1429 } |
53218d758ba9
[gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12760
diff
changeset
|
1430 |
12686
5f65a0cca87c
[gaim-migrate @ 15029]
Richard Laager <rlaager@wiktel.com>
parents:
12657
diff
changeset
|
1431 static void srvresolved(GaimSrvResponse *resp, int results, gpointer data) { |
11383 | 1432 struct simple_account_data *sip = (struct simple_account_data*) data; |
1433 | |
1434 gchar *hostname; | |
12730
d5b8f4dc1622
[gaim-migrate @ 15074]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12689
diff
changeset
|
1435 int port = gaim_account_get_int(sip->account, "port", 0); |
11383 | 1436 |
1437 /* find the host to connect to */ | |
1438 if(results) { | |
1439 hostname = g_strdup(resp->hostname); | |
12769 | 1440 if(!port) |
1441 port = resp->port; | |
11383 | 1442 g_free(resp); |
1443 } else { | |
1444 if(!gaim_account_get_bool(sip->account, "useproxy", FALSE)) { | |
1445 hostname = g_strdup(sip->servername); | |
1446 } else { | |
1447 hostname = g_strdup(gaim_account_get_string(sip->account, "proxy", sip->servername)); | |
1448 } | |
1449 } | |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
1450 |
11383 | 1451 sip->realhostname = hostname; |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
1452 sip->realport = port; |
12769 | 1453 if(!sip->realport) sip->realport = 5060; |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
1454 |
11383 | 1455 /* TCP case */ |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
1456 if(!sip->udp) { |
11409 | 1457 /* create socket for incoming connections */ |
12909
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12770
diff
changeset
|
1458 if(!gaim_network_listen_range(5060, 5160, SOCK_STREAM, |
8e3b85fe4a55
[gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12770
diff
changeset
|
1459 simple_tcp_connect_listen_cb, sip)) { |
11409 | 1460 gaim_connection_error(sip->gc, _("Could not create listen socket")); |
1461 return; | |
1462 } | |
11383 | 1463 } else { /* UDP */ |
1464 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
|
1465 |
12767
53218d758ba9
[gaim-migrate @ 15114]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12760
diff
changeset
|
1466 gaim_gethostbyname_async(hostname, port, simple_udp_host_resolved, sip); |
11383 | 1467 } |
1468 } | |
1469 | |
11837 | 1470 static void simple_login(GaimAccount *account) |
11181 | 1471 { |
1472 GaimConnection *gc; | |
1473 struct simple_account_data *sip; | |
1474 gchar **userserver; | |
11210 | 1475 gchar *hosttoconnect; |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
1476 |
11181 | 1477 const char *username = gaim_account_get_username(account); |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
1478 gc = gaim_account_get_connection(account); |
11181 | 1479 |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
1480 if (strpbrk(username, " \t\v\r\n") != NULL) { |
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
1481 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
|
1482 return; |
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
1483 } |
11181 | 1484 |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
1485 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
|
1486 sip->gc = gc; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
1487 sip->account = account; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
1488 sip->registerexpire = 900; |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
1489 sip->udp = gaim_account_get_bool(account, "udp", FALSE); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
1490 /* TODO: is there a good default grow size? */ |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
1491 if(!sip->udp) |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
1492 sip->txbuf = gaim_circ_buffer_new(0); |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
1493 |
11181 | 1494 userserver = g_strsplit(username, "@", 2); |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
1495 gaim_connection_set_display_name(gc, userserver[0]); |
11181 | 1496 sip->username = g_strdup(userserver[0]); |
1497 sip->servername = g_strdup(userserver[1]); | |
1498 sip->password = g_strdup(gaim_connection_get_password(gc)); | |
1499 g_strfreev(userserver); | |
1500 | |
1501 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
|
1502 |
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
1503 gaim_connection_update_progress(gc, _("Connecting"), 1, 2); |
11181 | 1504 |
11837 | 1505 /* TODO: Set the status correctly. */ |
11181 | 1506 sip->status = g_strdup("available"); |
11189 | 1507 |
11210 | 1508 if(!gaim_account_get_bool(account, "useproxy", FALSE)) { |
1509 hosttoconnect = g_strdup(sip->servername); | |
1510 } else { | |
1511 hosttoconnect = g_strdup(gaim_account_get_string(account, "proxy", sip->servername)); | |
1512 } | |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
1513 |
11341 | 1514 /* TCP case */ |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
1515 if(!sip->udp) { |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
1516 gaim_srv_resolve("sip", "tcp", hosttoconnect, srvresolved, sip); |
11341 | 1517 } else { /* UDP */ |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
1518 gaim_srv_resolve("sip", "udp", hosttoconnect, srvresolved, sip); |
11181 | 1519 } |
11210 | 1520 g_free(hosttoconnect); |
11181 | 1521 } |
1522 | |
1523 static void simple_close(GaimConnection *gc) | |
1524 { | |
1525 struct simple_account_data *sip = gc->proto_data; | |
11194 | 1526 |
11341 | 1527 /* unregister */ |
11194 | 1528 do_register_exp(sip, 0); |
11346 | 1529 connection_free_all(sip); |
11341 | 1530 if(sip) { |
11650 | 1531 g_free(sip->servername); |
1532 g_free(sip->username); | |
1533 g_free(sip->password); | |
1534 g_free(sip->registrar.nonce); | |
13084 | 1535 g_free(sip->registrar.opaque); |
1536 g_free(sip->registrar.target); | |
11650 | 1537 g_free(sip->registrar.realm); |
13084 | 1538 g_free(sip->registrar.digest_session_key); |
11650 | 1539 g_free(sip->proxy.nonce); |
13084 | 1540 g_free(sip->proxy.opaque); |
1541 g_free(sip->proxy.target); | |
11650 | 1542 g_free(sip->proxy.realm); |
13084 | 1543 g_free(sip->proxy.digest_session_key); |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
1544 if(sip->txbuf) |
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
1545 gaim_circ_buffer_destroy(sip->txbuf); |
11650 | 1546 g_free(sip->realhostname); |
11409 | 1547 if(sip->listenpa) gaim_input_remove(sip->listenpa); |
13200
33bef17125c2
[gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13184
diff
changeset
|
1548 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
|
1549 if(sip->resendtimeout) gaim_timeout_remove(sip->resendtimeout); |
11346 | 1550 if(sip->registertimeout) gaim_timeout_remove(sip->registertimeout); |
11181 | 1551 } |
11650 | 1552 g_free(gc->proto_data); |
12571
2c73e08032a1
[gaim-migrate @ 14890]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12570
diff
changeset
|
1553 gc->proto_data = NULL; |
11181 | 1554 } |
1555 | |
11345 | 1556 /* not needed since privacy is checked for every subscribe */ |
1557 static void dummy_add_deny(GaimConnection *gc, const char *name) { | |
1558 } | |
1559 | |
1560 static void dummy_permit_deny(GaimConnection *gc) { | |
1561 } | |
1562 | |
11181 | 1563 static GaimPluginProtocolInfo prpl_info = |
1564 { | |
1565 0, | |
1566 NULL, /* user_splits */ | |
1567 NULL, /* protocol_options */ | |
12143
cbebda5f019c
[gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents:
11837
diff
changeset
|
1568 NO_BUDDY_ICONS, /* icon_spec */ |
11181 | 1569 simple_list_icon, /* list_icon */ |
12143
cbebda5f019c
[gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents:
11837
diff
changeset
|
1570 NULL, /* list_emblems */ |
11181 | 1571 NULL, /* status_text */ |
1572 NULL, /* tooltip_text */ | |
1573 simple_status_types, /* away_states */ | |
1574 NULL, /* blist_node_menu */ | |
12143
cbebda5f019c
[gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents:
11837
diff
changeset
|
1575 NULL, /* chat_info */ |
cbebda5f019c
[gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents:
11837
diff
changeset
|
1576 NULL, /* chat_info_defaults */ |
cbebda5f019c
[gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents:
11837
diff
changeset
|
1577 simple_login, /* login */ |
cbebda5f019c
[gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents:
11837
diff
changeset
|
1578 simple_close, /* close */ |
cbebda5f019c
[gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents:
11837
diff
changeset
|
1579 simple_im_send, /* send_im */ |
11181 | 1580 NULL, /* set_info */ |
12143
cbebda5f019c
[gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents:
11837
diff
changeset
|
1581 simple_typing, /* send_typing */ |
cbebda5f019c
[gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents:
11837
diff
changeset
|
1582 NULL, /* get_info */ |
11181 | 1583 simple_set_status, /* set_status */ |
1584 NULL, /* set_idle */ | |
1585 NULL, /* change_passwd */ | |
1586 simple_add_buddy, /* add_buddy */ | |
1587 NULL, /* add_buddies */ | |
1588 simple_remove_buddy, /* remove_buddy */ | |
1589 NULL, /* remove_buddies */ | |
12143
cbebda5f019c
[gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents:
11837
diff
changeset
|
1590 dummy_add_deny, /* add_permit */ |
cbebda5f019c
[gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents:
11837
diff
changeset
|
1591 dummy_add_deny, /* add_deny */ |
cbebda5f019c
[gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents:
11837
diff
changeset
|
1592 dummy_add_deny, /* rem_permit */ |
cbebda5f019c
[gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents:
11837
diff
changeset
|
1593 dummy_add_deny, /* rem_deny */ |
cbebda5f019c
[gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents:
11837
diff
changeset
|
1594 dummy_permit_deny, /* set_permit_deny */ |
cbebda5f019c
[gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents:
11837
diff
changeset
|
1595 NULL, /* join_chat */ |
11181 | 1596 NULL, /* reject_chat */ |
12143
cbebda5f019c
[gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents:
11837
diff
changeset
|
1597 NULL, /* get_chat_name */ |
cbebda5f019c
[gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents:
11837
diff
changeset
|
1598 NULL, /* chat_invite */ |
cbebda5f019c
[gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents:
11837
diff
changeset
|
1599 NULL, /* chat_leave */ |
11181 | 1600 NULL, /* chat_whisper */ |
12143
cbebda5f019c
[gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents:
11837
diff
changeset
|
1601 NULL, /* chat_send */ |
cbebda5f019c
[gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents:
11837
diff
changeset
|
1602 simple_keep_alive, /* keepalive */ |
11181 | 1603 NULL, /* register_user */ |
1604 NULL, /* get_cb_info */ | |
1605 NULL, /* get_cb_away */ | |
1606 NULL, /* alias_buddy */ | |
1607 NULL, /* group_buddy */ | |
1608 NULL, /* rename_group */ | |
1609 NULL, /* buddy_free */ | |
1610 NULL, /* convo_closed */ | |
1611 NULL, /* normalize */ | |
1612 NULL, /* set_buddy_icon */ | |
1613 NULL, /* remove_group */ | |
1614 NULL, /* get_cb_real_name */ | |
12143
cbebda5f019c
[gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents:
11837
diff
changeset
|
1615 NULL, /* set_chat_topic */ |
11181 | 1616 NULL, /* find_blist_chat */ |
12143
cbebda5f019c
[gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents:
11837
diff
changeset
|
1617 NULL, /* roomlist_get_list */ |
cbebda5f019c
[gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents:
11837
diff
changeset
|
1618 NULL, /* roomlist_cancel */ |
11181 | 1619 NULL, /* roomlist_expand_category */ |
1620 NULL, /* can_receive_file */ | |
12143
cbebda5f019c
[gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents:
11837
diff
changeset
|
1621 NULL, /* send_file */ |
12600
e856f985a0b9
[gaim-migrate @ 14934]
Richard Laager <rlaager@wiktel.com>
parents:
12595
diff
changeset
|
1622 NULL, /* new_xfer */ |
12645
fc28451f5d96
[gaim-migrate @ 14983]
Richard Laager <rlaager@wiktel.com>
parents:
12600
diff
changeset
|
1623 NULL, /* offline_message */ |
12600
e856f985a0b9
[gaim-migrate @ 14934]
Richard Laager <rlaager@wiktel.com>
parents:
12595
diff
changeset
|
1624 NULL, /* whiteboard_prpl_ops */ |
11181 | 1625 }; |
1626 | |
1627 | |
1628 static GaimPluginInfo info = | |
1629 { | |
1630 GAIM_PLUGIN_MAGIC, | |
1631 GAIM_MAJOR_VERSION, | |
1632 GAIM_MINOR_VERSION, | |
1633 GAIM_PLUGIN_PROTOCOL, /**< type */ | |
1634 NULL, /**< ui_requirement */ | |
1635 0, /**< flags */ | |
1636 NULL, /**< dependencies */ | |
1637 GAIM_PRIORITY_DEFAULT, /**< priority */ | |
1638 | |
12489 | 1639 "prpl-simple", /**< id */ |
1640 "SIMPLE", /**< name */ | |
11181 | 1641 VERSION, /**< version */ |
12489 | 1642 N_("SIP/SIMPLE Protocol Plugin"), /** summary */ |
1643 N_("The SIP/SIMPLE Protocol Plugin"), /** description */ | |
1644 "Thomas Butter <butter@uni-mannheim.de>", /**< author */ | |
11181 | 1645 GAIM_WEBSITE, /**< homepage */ |
1646 | |
1647 NULL, /**< load */ | |
1648 NULL, /**< unload */ | |
1649 NULL, /**< destroy */ | |
1650 | |
1651 NULL, /**< ui_info */ | |
1652 &prpl_info, /**< extra_info */ | |
1653 NULL, | |
1654 NULL | |
1655 }; | |
1656 | |
1657 static void _init_plugin(GaimPlugin *plugin) | |
1658 { | |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
1659 GaimAccountUserSplit *split; |
11189 | 1660 GaimAccountOption *option; |
11181 | 1661 |
11396
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
1662 split = gaim_account_user_split_new(_("Server"), "", '@'); |
be776f9b1818
[gaim-migrate @ 13627]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
11383
diff
changeset
|
1663 prpl_info.user_splits = g_list_append(prpl_info.user_splits, split); |
11181 | 1664 |
12489 | 1665 option = gaim_account_option_bool_new(_("Publish status (note: everyone may watch you)"), "dopublish", TRUE); |
11345 | 1666 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); |
1667 | |
12769 | 1668 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
|
1669 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
|
1670 |
11189 | 1671 option = gaim_account_option_bool_new(_("Use UDP"), "udp", FALSE); |
1672 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
12489 | 1673 option = gaim_account_option_bool_new(_("Use proxy"), "useproxy", FALSE); |
11210 | 1674 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); |
1675 option = gaim_account_option_string_new(_("Proxy"), "proxy", ""); | |
1676 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
13084 | 1677 option = gaim_account_option_string_new(_("Auth User"), "authuser", ""); |
1678 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
1679 option = gaim_account_option_string_new(_("Auth Domain"), "authdomain", ""); | |
1680 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
11181 | 1681 } |
1682 | |
1683 GAIM_INIT_PLUGIN(simple, _init_plugin, info); |