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