Mercurial > pidgin.yaz
annotate src/protocols/msn/servconn.c @ 10463:9bed28273ec7
[gaim-migrate @ 11737]
Felipe Contreras fixed the MSN HTTP Method. Yay! Thanks Felipe.
committer: Tailor Script <tailor@pidgin.im>
author | Stu Tomlinson <stu@nosnilmot.com> |
---|---|
date | Fri, 31 Dec 2004 16:34:22 +0000 |
parents | 6be6da69d603 |
children | bcfea6c3d5c9 |
rev | line source |
---|---|
5309 | 1 /** |
2 * @file servconn.c Server connection functions | |
3 * | |
4 * gaim | |
5 * | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
6 * Gaim is the legal property of its developers, whose names are too numerous |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
7 * to list here. Please refer to the COPYRIGHT file distributed with this |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
8 * source distribution. |
6701
b7e113a59b51
[gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents:
6122
diff
changeset
|
9 * |
5309 | 10 * This program is free software; you can redistribute it and/or modify |
11 * it under the terms of the GNU General Public License as published by | |
12 * the Free Software Foundation; either version 2 of the License, or | |
13 * (at your option) any later version. | |
14 * | |
15 * This program is distributed in the hope that it will be useful, | |
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 * GNU General Public License for more details. | |
19 * | |
20 * You should have received a copy of the GNU General Public License | |
21 * along with this program; if not, write to the Free Software | |
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
23 */ | |
24 #include "msn.h" | |
25 #include "servconn.h" | |
8569
ee13d1befabe
[gaim-migrate @ 9317]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
26 #include "error.h" |
5309 | 27 |
8583
fc27237783ee
[gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents:
8569
diff
changeset
|
28 static void read_cb(gpointer data, gint source, GaimInputCondition cond); |
fc27237783ee
[gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents:
8569
diff
changeset
|
29 |
5309 | 30 MsnServConn * |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
31 msn_servconn_new(MsnSession *session, MsnServConnType type) |
5309 | 32 { |
33 MsnServConn *servconn; | |
34 | |
35 g_return_val_if_fail(session != NULL, NULL); | |
36 | |
37 servconn = g_new0(MsnServConn, 1); | |
38 | |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8662
diff
changeset
|
39 servconn->type = type; |
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8662
diff
changeset
|
40 |
5309 | 41 servconn->session = session; |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8662
diff
changeset
|
42 servconn->cmdproc = msn_cmdproc_new(session); |
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8662
diff
changeset
|
43 servconn->cmdproc->servconn = servconn; |
5309 | 44 |
7288
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
45 if (session->http_method) |
10463 | 46 servconn->httpconn = msn_httpconn_new(servconn); |
7288
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
47 |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8662
diff
changeset
|
48 servconn->num = session->servconns_count++; |
5898
5baeb89ee2d4
[gaim-migrate @ 6330]
Christian Hammond <chipx86@chipx86.com>
parents:
5897
diff
changeset
|
49 |
5309 | 50 return servconn; |
51 } | |
52 | |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
53 void |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
54 msn_servconn_destroy(MsnServConn *servconn) |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
55 { |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
56 g_return_if_fail(servconn != NULL); |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
57 |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
58 if (servconn->processing) |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
59 { |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
60 servconn->wasted = TRUE; |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
61 return; |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
62 } |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
63 |
10463 | 64 if (servconn->destroying) |
65 return; | |
66 | |
67 servconn->destroying = TRUE; | |
68 | |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
69 if (servconn->connected) |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
70 msn_servconn_disconnect(servconn); |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
71 |
10463 | 72 if (servconn->destroy_cb) |
73 servconn->destroy_cb(servconn); | |
74 | |
75 if (servconn->httpconn != NULL) | |
76 msn_httpconn_destroy(servconn->httpconn); | |
77 | |
78 if (servconn->host != NULL) | |
79 g_free(servconn->host); | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
80 |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
81 msn_cmdproc_destroy(servconn->cmdproc); |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
82 g_free(servconn); |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
83 } |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
84 |
10296 | 85 static void |
86 show_error(MsnServConn *servconn) | |
87 { | |
88 GaimConnection *gc; | |
89 char *tmp; | |
90 char *cmd; | |
91 | |
92 const char *names[] = { "Notification", "Switchboard" }; | |
93 const char *name; | |
94 | |
95 gc = gaim_account_get_connection(servconn->session->account); | |
96 name = names[servconn->type]; | |
97 | |
98 switch (servconn->cmdproc->error) | |
99 { | |
100 case MSN_ERROR_CONNECT: | |
101 tmp = g_strdup_printf(_("Unable to connect to %s server"), | |
102 name); | |
103 break; | |
104 case MSN_ERROR_WRITE: | |
105 tmp = g_strdup_printf(_("Error writing to %s server"), name); | |
106 break; | |
107 case MSN_ERROR_READ: | |
108 cmd = servconn->cmdproc->last_trans; | |
109 tmp = g_strdup_printf(_("Error reading from %s server"), name); | |
110 gaim_debug_info("msn", "Last command was: %s\n", cmd); | |
111 break; | |
112 default: | |
113 tmp = g_strdup_printf(_("Unknown error from %s server"), name); | |
114 break; | |
115 } | |
116 | |
117 if (servconn->type != MSN_SERVER_SB) | |
118 { | |
119 gaim_connection_error(gc, tmp); | |
120 } | |
121 else | |
122 { | |
123 MsnSwitchBoard *swboard; | |
10463 | 124 swboard = servconn->cmdproc->data; |
10296 | 125 swboard->error = MSN_SB_ERROR_CONNECTION; |
126 } | |
127 | |
128 g_free(tmp); | |
129 } | |
130 | |
131 static void | |
132 connect_cb(gpointer data, gint source, GaimInputCondition cond) | |
133 { | |
134 MsnServConn *servconn = data; | |
135 | |
10403 | 136 servconn->processing = FALSE; |
137 | |
138 if (servconn->wasted) | |
139 { | |
140 msn_servconn_destroy(servconn); | |
141 return; | |
142 } | |
143 | |
10296 | 144 servconn->fd = source; |
145 | |
146 if (source > 0) | |
147 { | |
10403 | 148 servconn->connected = TRUE; |
149 servconn->cmdproc->ready = TRUE; | |
150 | |
10296 | 151 /* Someone wants to know we connected. */ |
152 servconn->connect_cb(servconn); | |
153 servconn->inpa = gaim_input_add(servconn->fd, GAIM_INPUT_READ, | |
154 read_cb, data); | |
155 } | |
156 else | |
157 { | |
158 servconn->cmdproc->error = MSN_ERROR_CONNECT; | |
159 show_error(servconn); | |
160 } | |
161 } | |
162 | |
5309 | 163 gboolean |
8583
fc27237783ee
[gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents:
8569
diff
changeset
|
164 msn_servconn_connect(MsnServConn *servconn, const char *host, int port) |
5309 | 165 { |
7288
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
166 MsnSession *session; |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
167 int r; |
5309 | 168 |
8583
fc27237783ee
[gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents:
8569
diff
changeset
|
169 g_return_val_if_fail(servconn != NULL, FALSE); |
fc27237783ee
[gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents:
8569
diff
changeset
|
170 g_return_val_if_fail(host != NULL, FALSE); |
fc27237783ee
[gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents:
8569
diff
changeset
|
171 g_return_val_if_fail(port > 0, FALSE); |
7288
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
172 |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
173 session = servconn->session; |
5309 | 174 |
8583
fc27237783ee
[gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents:
8569
diff
changeset
|
175 if (servconn->connected) |
fc27237783ee
[gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents:
8569
diff
changeset
|
176 msn_servconn_disconnect(servconn); |
fc27237783ee
[gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents:
8569
diff
changeset
|
177 |
10463 | 178 if (servconn->host != NULL) |
179 g_free(servconn->host); | |
180 | |
181 servconn->host = g_strdup(host); | |
182 | |
7288
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
183 if (session->http_method) |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
184 { |
10463 | 185 /* HTTP Connection. */ |
186 | |
187 if (!servconn->httpconn->connected) | |
188 msn_httpconn_connect(servconn->httpconn, host, port); | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
189 |
10463 | 190 servconn->connected = TRUE; |
191 servconn->cmdproc->ready = TRUE; | |
192 servconn->httpconn->virgin = TRUE; | |
193 | |
194 /* Someone wants to know we connected. */ | |
195 servconn->connect_cb(servconn); | |
196 | |
197 return TRUE; | |
7288
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
198 } |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
199 |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
200 r = gaim_proxy_connect(session->account, host, port, connect_cb, |
8583
fc27237783ee
[gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents:
8569
diff
changeset
|
201 servconn); |
5309 | 202 |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
203 if (r == 0) |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
204 { |
10403 | 205 servconn->processing = TRUE; |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
206 return TRUE; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
207 } |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
208 else |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
209 return FALSE; |
5309 | 210 } |
211 | |
212 void | |
213 msn_servconn_disconnect(MsnServConn *servconn) | |
214 { | |
215 g_return_if_fail(servconn != NULL); | |
10434 | 216 |
217 if (!servconn->connected) | |
218 { | |
219 if (servconn->disconnect_cb != NULL) | |
220 servconn->disconnect_cb(servconn); | |
221 | |
222 return; | |
223 } | |
5309 | 224 |
10463 | 225 if (servconn->session->http_method) |
226 { | |
227 /* Fake disconnection */ | |
228 if (servconn->disconnect_cb != NULL) | |
229 servconn->disconnect_cb(servconn); | |
230 | |
231 return; | |
232 } | |
233 | |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
234 if (servconn->inpa > 0) |
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
235 { |
5309 | 236 gaim_input_remove(servconn->inpa); |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
237 servconn->inpa = 0; |
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
238 } |
5309 | 239 |
5744
6b87c127fe7b
[gaim-migrate @ 6168]
Christian Hammond <chipx86@chipx86.com>
parents:
5681
diff
changeset
|
240 close(servconn->fd); |
6b87c127fe7b
[gaim-migrate @ 6168]
Christian Hammond <chipx86@chipx86.com>
parents:
5681
diff
changeset
|
241 |
10403 | 242 servconn->rx_buf = NULL; |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
243 servconn->rx_len = 0; |
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
244 servconn->payload_len = 0; |
5309 | 245 |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
246 servconn->connected = FALSE; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
247 servconn->cmdproc->ready = FALSE; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
248 |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
249 if (servconn->disconnect_cb != NULL) |
8583
fc27237783ee
[gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents:
8569
diff
changeset
|
250 servconn->disconnect_cb(servconn); |
5309 | 251 } |
252 | |
253 void | |
10463 | 254 msn_servconn_set_connect_cb(MsnServConn *servconn, |
255 void (*connect_cb)(MsnServConn *)) | |
5309 | 256 { |
257 g_return_if_fail(servconn != NULL); | |
258 servconn->connect_cb = connect_cb; | |
259 } | |
260 | |
261 void | |
10463 | 262 msn_servconn_set_disconnect_cb(MsnServConn *servconn, |
263 void (*disconnect_cb)(MsnServConn *)) | |
5309 | 264 { |
265 g_return_if_fail(servconn != NULL); | |
266 | |
8583
fc27237783ee
[gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents:
8569
diff
changeset
|
267 servconn->disconnect_cb = disconnect_cb; |
5309 | 268 } |
269 | |
10463 | 270 void |
271 msn_servconn_set_destroy_cb(MsnServConn *servconn, | |
272 void (*destroy_cb)(MsnServConn *)) | |
273 { | |
274 g_return_if_fail(servconn != NULL); | |
275 | |
276 servconn->destroy_cb = destroy_cb; | |
277 } | |
278 | |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8662
diff
changeset
|
279 static void |
8583
fc27237783ee
[gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents:
8569
diff
changeset
|
280 failed_io(MsnServConn *servconn) |
fc27237783ee
[gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents:
8569
diff
changeset
|
281 { |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
282 g_return_if_fail(servconn != NULL); |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
283 |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8662
diff
changeset
|
284 show_error(servconn); |
8583
fc27237783ee
[gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents:
8569
diff
changeset
|
285 |
fc27237783ee
[gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents:
8569
diff
changeset
|
286 msn_servconn_disconnect(servconn); |
fc27237783ee
[gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents:
8569
diff
changeset
|
287 } |
fc27237783ee
[gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents:
8569
diff
changeset
|
288 |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8662
diff
changeset
|
289 size_t |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
290 msn_servconn_write(MsnServConn *servconn, const char *buf, size_t len) |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
291 { |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8662
diff
changeset
|
292 size_t ret = FALSE; |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
293 |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8662
diff
changeset
|
294 g_return_val_if_fail(servconn != NULL, 0); |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
295 |
10463 | 296 if (!servconn->session->http_method) |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
297 { |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
298 switch (servconn->type) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
299 { |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
300 case MSN_SERVER_NS: |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
301 case MSN_SERVER_SB: |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
302 ret = write(servconn->fd, buf, len); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
303 break; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
304 case MSN_SERVER_DC: |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
305 ret = write(servconn->fd, &buf, sizeof(len)); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
306 ret = write(servconn->fd, buf, len); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
307 break; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
308 default: |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
309 ret = write(servconn->fd, buf, len); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
310 break; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
311 } |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
312 } |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
313 else |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8662
diff
changeset
|
314 { |
10463 | 315 ret = msn_httpconn_write(servconn->httpconn, buf, len); |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8662
diff
changeset
|
316 } |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
317 |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
318 if (ret == -1) |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8662
diff
changeset
|
319 { |
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8662
diff
changeset
|
320 servconn->cmdproc->error = MSN_ERROR_WRITE; |
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8662
diff
changeset
|
321 failed_io(servconn); |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
322 } |
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
323 |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8662
diff
changeset
|
324 return ret; |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
325 } |
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
326 |
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
327 static void |
8583
fc27237783ee
[gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents:
8569
diff
changeset
|
328 read_cb(gpointer data, gint source, GaimInputCondition cond) |
5309 | 329 { |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8662
diff
changeset
|
330 MsnServConn *servconn; |
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8662
diff
changeset
|
331 MsnSession *session; |
5309 | 332 char buf[MSN_BUF_LEN]; |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
333 char *cur, *end, *old_rx_buf; |
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
334 int len, cur_len; |
5309 | 335 |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8662
diff
changeset
|
336 servconn = data; |
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8662
diff
changeset
|
337 session = servconn->session; |
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8662
diff
changeset
|
338 |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
339 len = read(servconn->fd, buf, sizeof(buf) - 1); |
5309 | 340 |
7288
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
341 if (len <= 0) |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
342 { |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8662
diff
changeset
|
343 servconn->cmdproc->error = MSN_ERROR_READ; |
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8662
diff
changeset
|
344 |
8583
fc27237783ee
[gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents:
8569
diff
changeset
|
345 failed_io(servconn); |
5309 | 346 |
347 return; | |
348 } | |
349 | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
350 buf[len] = '\0'; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
351 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
352 servconn->rx_buf = g_realloc(servconn->rx_buf, len + servconn->rx_len + 1); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
353 memcpy(servconn->rx_buf + servconn->rx_len, buf, len + 1); |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
354 servconn->rx_len += len; |
5309 | 355 |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
356 end = old_rx_buf = servconn->rx_buf; |
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
357 |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8662
diff
changeset
|
358 servconn->processing = TRUE; |
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8662
diff
changeset
|
359 |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
360 do |
7288
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
361 { |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
362 cur = end; |
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
363 |
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
364 if (servconn->payload_len) |
7288
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
365 { |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
366 if (servconn->payload_len > servconn->rx_len) |
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
367 /* The payload is still not complete. */ |
5309 | 368 break; |
369 | |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
370 cur_len = servconn->payload_len; |
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
371 end += cur_len; |
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
372 } |
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
373 else |
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
374 { |
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
375 end = strstr(cur, "\r\n"); |
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
376 |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
377 if (end == NULL) |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
378 /* The command is still not complete. */ |
5309 | 379 break; |
380 | |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
381 *end = '\0'; |
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
382 end += 2; |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
383 cur_len = end - cur; |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
384 } |
5309 | 385 |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
386 servconn->rx_len -= cur_len; |
5899
349204c9a709
[gaim-migrate @ 6331]
Christian Hammond <chipx86@chipx86.com>
parents:
5898
diff
changeset
|
387 |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
388 if (servconn->payload_len) |
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
389 { |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8662
diff
changeset
|
390 msn_cmdproc_process_payload(servconn->cmdproc, cur, cur_len); |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
391 servconn->payload_len = 0; |
5309 | 392 } |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
393 else |
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
394 { |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8662
diff
changeset
|
395 msn_cmdproc_process_cmd_text(servconn->cmdproc, cur); |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
396 } |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
397 } while (servconn->connected && servconn->rx_len > 0); |
5309 | 398 |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
399 if (servconn->connected) |
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
400 { |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
401 if (servconn->rx_len > 0) |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
402 servconn->rx_buf = g_memdup(cur, servconn->rx_len); |
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
403 else |
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
404 servconn->rx_buf = NULL; |
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
405 } |
5309 | 406 |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8662
diff
changeset
|
407 servconn->processing = FALSE; |
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8662
diff
changeset
|
408 |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
409 if (servconn->wasted) |
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
410 msn_servconn_destroy(servconn); |
5309 | 411 |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
412 g_free(old_rx_buf); |
5309 | 413 } |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
414 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
415 #if 0 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
416 static int |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
417 create_listener(int port) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
418 { |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
419 int fd; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
420 const int on = 1; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
421 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
422 #if 0 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
423 struct addrinfo hints; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
424 struct addrinfo *c, *res; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
425 char port_str[5]; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
426 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
427 snprintf(port_str, sizeof(port_str), "%d", port); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
428 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
429 memset(&hints, 0, sizeof(hints)); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
430 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
431 hints.ai_flags = AI_PASSIVE; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
432 hints.ai_family = AF_UNSPEC; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
433 hints.ai_socktype = SOCK_STREAM; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
434 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
435 if (getaddrinfo(NULL, port_str, &hints, &res) != 0) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
436 { |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
437 gaim_debug_error("msn", "Could not get address info: %s.\n", |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
438 port_str); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
439 return -1; |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
440 } |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
441 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
442 for (c = res; c != NULL; c = c->ai_next) |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
443 { |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
444 fd = socket(c->ai_family, c->ai_socktype, c->ai_protocol); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
445 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
446 if (fd < 0) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
447 continue; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
448 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
449 setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
450 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
451 if (bind(fd, c->ai_addr, c->ai_addrlen) == 0) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
452 break; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
453 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
454 close(fd); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
455 } |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
456 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
457 if (c == NULL) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
458 { |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
459 gaim_debug_error("msn", "Could not find socket: %s.\n", port_str); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
460 return -1; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
461 } |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
462 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
463 freeaddrinfo(res); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
464 #else |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
465 struct sockaddr_in sockin; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
466 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
467 fd = socket(AF_INET, SOCK_STREAM, 0); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
468 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
469 if (fd < 0) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
470 return -1; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
471 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
472 if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) != 0) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
473 { |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
474 close(fd); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
475 return -1; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
476 } |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
477 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
478 memset(&sockin, 0, sizeof(struct sockaddr_in)); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
479 sockin.sin_family = AF_INET; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
480 sockin.sin_port = htons(port); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
481 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
482 if (bind(fd, (struct sockaddr *)&sockin, sizeof(struct sockaddr_in)) != 0) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
483 { |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
484 close(fd); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
485 return -1; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
486 } |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
487 #endif |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
488 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
489 if (listen (fd, 4) != 0) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
490 { |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
491 close (fd); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
492 return -1; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
493 } |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
494 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
495 fcntl(fd, F_SETFL, O_NONBLOCK); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
496 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
497 return fd; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
498 } |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
499 #endif |