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