annotate src/protocols/simple/simple.c @ 11483:0d18fa6c3b41

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