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