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