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