annotate src/protocols/simple/simple.c @ 12862:b503265495f7

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