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