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