Mercurial > pidgin.yaz
annotate src/protocols/msn/servconn.c @ 9873:aa0761051017
[gaim-migrate @ 10752]
NEWS
committer: Tailor Script <tailor@pidgin.im>
author | Tim Ringenbach <marv@pidgin.im> |
---|---|
date | Wed, 25 Aug 2004 22:41:54 +0000 |
parents | ab6636c5a136 |
children | ecf3ce2e2ab1 |
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 static void |
9092
9e5a709c30a8
[gaim-migrate @ 9869]
Christian Hammond <chipx86@chipx86.com>
parents:
9088
diff
changeset
|
31 show_error(MsnServConn *servconn) |
9e5a709c30a8
[gaim-migrate @ 9869]
Christian Hammond <chipx86@chipx86.com>
parents:
9088
diff
changeset
|
32 { |
9e5a709c30a8
[gaim-migrate @ 9869]
Christian Hammond <chipx86@chipx86.com>
parents:
9088
diff
changeset
|
33 GaimConnection *gc; |
9e5a709c30a8
[gaim-migrate @ 9869]
Christian Hammond <chipx86@chipx86.com>
parents:
9088
diff
changeset
|
34 char *tmp; |
9e5a709c30a8
[gaim-migrate @ 9869]
Christian Hammond <chipx86@chipx86.com>
parents:
9088
diff
changeset
|
35 char *cmd; |
9e5a709c30a8
[gaim-migrate @ 9869]
Christian Hammond <chipx86@chipx86.com>
parents:
9088
diff
changeset
|
36 |
9e5a709c30a8
[gaim-migrate @ 9869]
Christian Hammond <chipx86@chipx86.com>
parents:
9088
diff
changeset
|
37 const char *names[] = { "Notification", "Switchboard" }; |
9e5a709c30a8
[gaim-migrate @ 9869]
Christian Hammond <chipx86@chipx86.com>
parents:
9088
diff
changeset
|
38 const char *name; |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
39 |
9092
9e5a709c30a8
[gaim-migrate @ 9869]
Christian Hammond <chipx86@chipx86.com>
parents:
9088
diff
changeset
|
40 gc = gaim_account_get_connection(servconn->session->account); |
9e5a709c30a8
[gaim-migrate @ 9869]
Christian Hammond <chipx86@chipx86.com>
parents:
9088
diff
changeset
|
41 name = names[servconn->type]; |
9e5a709c30a8
[gaim-migrate @ 9869]
Christian Hammond <chipx86@chipx86.com>
parents:
9088
diff
changeset
|
42 |
9e5a709c30a8
[gaim-migrate @ 9869]
Christian Hammond <chipx86@chipx86.com>
parents:
9088
diff
changeset
|
43 switch (servconn->cmdproc->error) |
9e5a709c30a8
[gaim-migrate @ 9869]
Christian Hammond <chipx86@chipx86.com>
parents:
9088
diff
changeset
|
44 { |
9e5a709c30a8
[gaim-migrate @ 9869]
Christian Hammond <chipx86@chipx86.com>
parents:
9088
diff
changeset
|
45 case MSN_ERROR_CONNECT: |
9e5a709c30a8
[gaim-migrate @ 9869]
Christian Hammond <chipx86@chipx86.com>
parents:
9088
diff
changeset
|
46 tmp = g_strdup_printf(_("Unable to connect to %s server"), |
9e5a709c30a8
[gaim-migrate @ 9869]
Christian Hammond <chipx86@chipx86.com>
parents:
9088
diff
changeset
|
47 name); |
9e5a709c30a8
[gaim-migrate @ 9869]
Christian Hammond <chipx86@chipx86.com>
parents:
9088
diff
changeset
|
48 break; |
9e5a709c30a8
[gaim-migrate @ 9869]
Christian Hammond <chipx86@chipx86.com>
parents:
9088
diff
changeset
|
49 case MSN_ERROR_WRITE: |
9e5a709c30a8
[gaim-migrate @ 9869]
Christian Hammond <chipx86@chipx86.com>
parents:
9088
diff
changeset
|
50 tmp = g_strdup_printf(_("Error writing to %s server"), name); |
9e5a709c30a8
[gaim-migrate @ 9869]
Christian Hammond <chipx86@chipx86.com>
parents:
9088
diff
changeset
|
51 break; |
9e5a709c30a8
[gaim-migrate @ 9869]
Christian Hammond <chipx86@chipx86.com>
parents:
9088
diff
changeset
|
52 case MSN_ERROR_READ: |
9e5a709c30a8
[gaim-migrate @ 9869]
Christian Hammond <chipx86@chipx86.com>
parents:
9088
diff
changeset
|
53 cmd = servconn->cmdproc->last_trans; |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
54 tmp = g_strdup_printf(_("Error reading from %s server"), name); |
9092
9e5a709c30a8
[gaim-migrate @ 9869]
Christian Hammond <chipx86@chipx86.com>
parents:
9088
diff
changeset
|
55 gaim_debug_info("msn", "Last command was: %s\n", cmd); |
9e5a709c30a8
[gaim-migrate @ 9869]
Christian Hammond <chipx86@chipx86.com>
parents:
9088
diff
changeset
|
56 break; |
9e5a709c30a8
[gaim-migrate @ 9869]
Christian Hammond <chipx86@chipx86.com>
parents:
9088
diff
changeset
|
57 default: |
9e5a709c30a8
[gaim-migrate @ 9869]
Christian Hammond <chipx86@chipx86.com>
parents:
9088
diff
changeset
|
58 tmp = g_strdup_printf(_("Unknown error from %s server"), name); |
9e5a709c30a8
[gaim-migrate @ 9869]
Christian Hammond <chipx86@chipx86.com>
parents:
9088
diff
changeset
|
59 break; |
9e5a709c30a8
[gaim-migrate @ 9869]
Christian Hammond <chipx86@chipx86.com>
parents:
9088
diff
changeset
|
60 } |
9e5a709c30a8
[gaim-migrate @ 9869]
Christian Hammond <chipx86@chipx86.com>
parents:
9088
diff
changeset
|
61 |
9165
43ea2b858112
[gaim-migrate @ 9950]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
62 if (servconn->type != MSN_SERVER_SB) |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
63 { |
9165
43ea2b858112
[gaim-migrate @ 9950]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
64 gaim_connection_error(gc, tmp); |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
65 } |
9165
43ea2b858112
[gaim-migrate @ 9950]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
66 else |
43ea2b858112
[gaim-migrate @ 9950]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
67 { |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
68 GaimAccount *account; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
69 char *primary; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
70 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
71 account = gaim_connection_get_account(gc); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
72 primary = g_strdup_printf(_("MSN error for account %s"), |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
73 gaim_account_get_username(account)); |
9165
43ea2b858112
[gaim-migrate @ 9950]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
74 |
43ea2b858112
[gaim-migrate @ 9950]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
75 gaim_notify_error(gc, NULL, primary, tmp); |
43ea2b858112
[gaim-migrate @ 9950]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
76 |
43ea2b858112
[gaim-migrate @ 9950]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
77 g_free(primary); |
43ea2b858112
[gaim-migrate @ 9950]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
78 } |
43ea2b858112
[gaim-migrate @ 9950]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
79 |
9092
9e5a709c30a8
[gaim-migrate @ 9869]
Christian Hammond <chipx86@chipx86.com>
parents:
9088
diff
changeset
|
80 g_free(tmp); |
9e5a709c30a8
[gaim-migrate @ 9869]
Christian Hammond <chipx86@chipx86.com>
parents:
9088
diff
changeset
|
81 } |
9e5a709c30a8
[gaim-migrate @ 9869]
Christian Hammond <chipx86@chipx86.com>
parents:
9088
diff
changeset
|
82 |
9e5a709c30a8
[gaim-migrate @ 9869]
Christian Hammond <chipx86@chipx86.com>
parents:
9088
diff
changeset
|
83 static void |
5793
952710ac6635
[gaim-migrate @ 6218]
Christian Hammond <chipx86@chipx86.com>
parents:
5785
diff
changeset
|
84 connect_cb(gpointer data, gint source, GaimInputCondition cond) |
5309 | 85 { |
86 MsnServConn *servconn = data; | |
87 | |
8583
fc27237783ee
[gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents:
8569
diff
changeset
|
88 servconn->fd = source; |
fc27237783ee
[gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents:
8569
diff
changeset
|
89 |
fc27237783ee
[gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents:
8569
diff
changeset
|
90 if (source > 0) |
fc27237783ee
[gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents:
8569
diff
changeset
|
91 { |
fc27237783ee
[gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents:
8569
diff
changeset
|
92 /* Someone wants to know we connected. */ |
fc27237783ee
[gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents:
8569
diff
changeset
|
93 servconn->connect_cb(servconn); |
5309 | 94 servconn->inpa = gaim_input_add(servconn->fd, GAIM_INPUT_READ, |
8583
fc27237783ee
[gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents:
8569
diff
changeset
|
95 read_cb, data); |
fc27237783ee
[gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents:
8569
diff
changeset
|
96 } |
fc27237783ee
[gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents:
8569
diff
changeset
|
97 else |
fc27237783ee
[gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents:
8569
diff
changeset
|
98 { |
9092
9e5a709c30a8
[gaim-migrate @ 9869]
Christian Hammond <chipx86@chipx86.com>
parents:
9088
diff
changeset
|
99 servconn->cmdproc->error = MSN_ERROR_CONNECT; |
9e5a709c30a8
[gaim-migrate @ 9869]
Christian Hammond <chipx86@chipx86.com>
parents:
9088
diff
changeset
|
100 show_error(servconn); |
8583
fc27237783ee
[gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents:
8569
diff
changeset
|
101 } |
5309 | 102 } |
103 | |
104 MsnServConn * | |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
105 msn_servconn_new(MsnSession *session, MsnServConnType type) |
5309 | 106 { |
107 MsnServConn *servconn; | |
108 | |
109 g_return_val_if_fail(session != NULL, NULL); | |
110 | |
111 servconn = g_new0(MsnServConn, 1); | |
112 | |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8662
diff
changeset
|
113 servconn->type = type; |
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8662
diff
changeset
|
114 |
5309 | 115 servconn->session = session; |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8662
diff
changeset
|
116 servconn->cmdproc = msn_cmdproc_new(session); |
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8662
diff
changeset
|
117 servconn->cmdproc->servconn = servconn; |
5309 | 118 |
7288
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
119 if (session->http_method) |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
120 { |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
121 servconn->http_data = g_new0(MsnHttpMethodData, 1); |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
122 servconn->http_data->virgin = TRUE; |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
123 } |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
124 |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8662
diff
changeset
|
125 servconn->num = session->servconns_count++; |
5898
5baeb89ee2d4
[gaim-migrate @ 6330]
Christian Hammond <chipx86@chipx86.com>
parents:
5897
diff
changeset
|
126 |
5309 | 127 return servconn; |
128 } | |
129 | |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
130 void |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
131 msn_servconn_destroy(MsnServConn *servconn) |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
132 { |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
133 g_return_if_fail(servconn != NULL); |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
134 |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
135 if (servconn->processing) |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
136 { |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
137 servconn->wasted = TRUE; |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
138 return; |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
139 } |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
140 |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
141 if (servconn->connected) |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
142 msn_servconn_disconnect(servconn); |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
143 |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
144 if (servconn->http_data != NULL) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
145 g_free(servconn->http_data); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
146 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
147 #if 0 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
148 if (servconn->rx_buf != NULL) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
149 g_free(servconn->rx_buf); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
150 #endif |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
151 |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
152 msn_cmdproc_destroy(servconn->cmdproc); |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
153 g_free(servconn); |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
154 } |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
155 |
5309 | 156 gboolean |
8583
fc27237783ee
[gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents:
8569
diff
changeset
|
157 msn_servconn_connect(MsnServConn *servconn, const char *host, int port) |
5309 | 158 { |
7288
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
159 MsnSession *session; |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
160 int r; |
5309 | 161 |
8583
fc27237783ee
[gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents:
8569
diff
changeset
|
162 g_return_val_if_fail(servconn != NULL, FALSE); |
fc27237783ee
[gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents:
8569
diff
changeset
|
163 g_return_val_if_fail(host != NULL, FALSE); |
fc27237783ee
[gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents:
8569
diff
changeset
|
164 g_return_val_if_fail(port > 0, FALSE); |
7288
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
165 |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
166 session = servconn->session; |
5309 | 167 |
8583
fc27237783ee
[gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents:
8569
diff
changeset
|
168 if (servconn->connected) |
fc27237783ee
[gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents:
8569
diff
changeset
|
169 msn_servconn_disconnect(servconn); |
fc27237783ee
[gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents:
8569
diff
changeset
|
170 |
7288
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
171 if (session->http_method) |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
172 { |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
173 if (servconn->http_data->gateway_host != NULL) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
174 g_free(servconn->http_data->gateway_host); |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
175 |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
176 servconn->http_data->gateway_host = g_strdup(host); |
7288
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
177 } |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
178 |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
179 r = gaim_proxy_connect(session->account, host, port, connect_cb, |
8583
fc27237783ee
[gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents:
8569
diff
changeset
|
180 servconn); |
5309 | 181 |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
182 if (r == 0) |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
183 { |
5309 | 184 servconn->connected = TRUE; |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
185 servconn->cmdproc->ready = TRUE; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
186 return TRUE; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
187 } |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
188 else |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
189 return FALSE; |
5309 | 190 } |
191 | |
192 void | |
193 msn_servconn_disconnect(MsnServConn *servconn) | |
194 { | |
195 g_return_if_fail(servconn != NULL); | |
196 g_return_if_fail(servconn->connected); | |
197 | |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
198 if (servconn->inpa > 0) |
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
199 { |
5309 | 200 gaim_input_remove(servconn->inpa); |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
201 servconn->inpa = 0; |
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
202 } |
5309 | 203 |
5744
6b87c127fe7b
[gaim-migrate @ 6168]
Christian Hammond <chipx86@chipx86.com>
parents:
5681
diff
changeset
|
204 close(servconn->fd); |
6b87c127fe7b
[gaim-migrate @ 6168]
Christian Hammond <chipx86@chipx86.com>
parents:
5681
diff
changeset
|
205 |
7288
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
206 if (servconn->http_data != NULL) |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
207 { |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
208 if (servconn->http_data->session_id != NULL) |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
209 g_free(servconn->http_data->session_id); |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
210 |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
211 if (servconn->http_data->old_gateway_host != NULL) |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
212 g_free(servconn->http_data->old_gateway_host); |
7288
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
213 |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
214 if (servconn->http_data->gateway_host != NULL) |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
215 g_free(servconn->http_data->gateway_host); |
7288
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
216 |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
217 if (servconn->http_data->timer) |
8287
ef881489396e
[gaim-migrate @ 9011]
Christian Hammond <chipx86@chipx86.com>
parents:
7938
diff
changeset
|
218 gaim_timeout_remove(servconn->http_data->timer); |
7288
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
219 } |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
220 |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
221 servconn->rx_len = 0; |
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
222 servconn->payload_len = 0; |
5309 | 223 |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
224 servconn->connected = FALSE; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
225 servconn->cmdproc->ready = FALSE; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
226 |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
227 if (servconn->disconnect_cb != NULL) |
8583
fc27237783ee
[gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents:
8569
diff
changeset
|
228 servconn->disconnect_cb(servconn); |
5309 | 229 } |
230 | |
231 void | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
232 msn_servconn_set_connect_cb(MsnServConn *servconn, void (*connect_cb)(MsnServConn *)) |
5309 | 233 { |
234 g_return_if_fail(servconn != NULL); | |
235 servconn->connect_cb = connect_cb; | |
236 } | |
237 | |
238 void | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
239 msn_servconn_set_disconnect_cb(MsnServConn *servconn, void (*disconnect_cb)(MsnServConn *)) |
5309 | 240 { |
241 g_return_if_fail(servconn != NULL); | |
242 | |
8583
fc27237783ee
[gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents:
8569
diff
changeset
|
243 servconn->disconnect_cb = disconnect_cb; |
5309 | 244 } |
245 | |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8662
diff
changeset
|
246 static void |
8583
fc27237783ee
[gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents:
8569
diff
changeset
|
247 failed_io(MsnServConn *servconn) |
fc27237783ee
[gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents:
8569
diff
changeset
|
248 { |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
249 g_return_if_fail(servconn != NULL); |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
250 |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8662
diff
changeset
|
251 show_error(servconn); |
8583
fc27237783ee
[gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents:
8569
diff
changeset
|
252 |
fc27237783ee
[gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents:
8569
diff
changeset
|
253 msn_servconn_disconnect(servconn); |
fc27237783ee
[gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents:
8569
diff
changeset
|
254 } |
fc27237783ee
[gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents:
8569
diff
changeset
|
255 |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8662
diff
changeset
|
256 size_t |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
257 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
|
258 { |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8662
diff
changeset
|
259 size_t ret = FALSE; |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
260 |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8662
diff
changeset
|
261 g_return_val_if_fail(servconn != NULL, 0); |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
262 |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
263 if (servconn->http_data == NULL) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
264 { |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
265 switch (servconn->type) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
266 { |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
267 case MSN_SERVER_NS: |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
268 case MSN_SERVER_SB: |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
269 ret = write(servconn->fd, buf, len); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
270 break; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
271 case MSN_SERVER_DC: |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
272 ret = write(servconn->fd, &buf, sizeof(len)); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
273 ret = write(servconn->fd, buf, len); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
274 break; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
275 default: |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
276 ret = write(servconn->fd, buf, len); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
277 break; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
278 } |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
279 } |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
280 else |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8662
diff
changeset
|
281 { |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
282 ret = msn_http_servconn_write(servconn, buf, len, |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
283 servconn->http_data->server_type); |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8662
diff
changeset
|
284 } |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
285 |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
286 if (ret == -1) |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8662
diff
changeset
|
287 { |
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8662
diff
changeset
|
288 servconn->cmdproc->error = MSN_ERROR_WRITE; |
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8662
diff
changeset
|
289 failed_io(servconn); |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
290 } |
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 return ret; |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
293 } |
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
294 |
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
295 static void |
8583
fc27237783ee
[gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents:
8569
diff
changeset
|
296 read_cb(gpointer data, gint source, GaimInputCondition cond) |
5309 | 297 { |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8662
diff
changeset
|
298 MsnServConn *servconn; |
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8662
diff
changeset
|
299 MsnSession *session; |
5309 | 300 char buf[MSN_BUF_LEN]; |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
301 char *cur, *end, *old_rx_buf; |
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
302 int len, cur_len; |
5309 | 303 |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8662
diff
changeset
|
304 servconn = data; |
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8662
diff
changeset
|
305 session = servconn->session; |
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8662
diff
changeset
|
306 |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
307 len = read(servconn->fd, buf, sizeof(buf) - 1); |
5309 | 308 |
7288
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
309 if (len <= 0) |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
310 { |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8662
diff
changeset
|
311 servconn->cmdproc->error = MSN_ERROR_READ; |
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8662
diff
changeset
|
312 |
8583
fc27237783ee
[gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents:
8569
diff
changeset
|
313 failed_io(servconn); |
5309 | 314 |
315 return; | |
316 } | |
317 | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
318 buf[len] = '\0'; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
319 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
320 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
|
321 memcpy(servconn->rx_buf + servconn->rx_len, buf, len + 1); |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
322 servconn->rx_len += len; |
5309 | 323 |
7288
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
324 if (session->http_method) |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
325 { |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
326 char *result_msg = NULL; |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
327 size_t result_len = 0; |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
328 gboolean error; |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
329 char *tmp; |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
330 |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
331 tmp = g_strndup(servconn->rx_buf, servconn->rx_len); |
7288
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
332 |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
333 if (!msn_http_servconn_parse_data(servconn, tmp, servconn->rx_len, |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
334 &result_msg, &result_len, |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
335 &error)) |
7288
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
336 { |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
337 g_free(tmp); |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
338 return; |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
339 } |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
340 |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
341 g_free(tmp); |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
342 |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
343 if (error) |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
344 { |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
345 gaim_connection_error(gaim_account_get_connection(session->account), |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
346 _("Received HTTP error. Please report this.")); |
7288
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
347 |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
348 return; |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
349 } |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
350 |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
351 if (servconn->http_data->session_id != NULL && |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
352 !strcmp(servconn->http_data->session_id, "close")) |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
353 { |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
354 msn_servconn_destroy(servconn); |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
355 |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
356 return; |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
357 } |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
358 |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
359 #if 0 |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
360 if (strcmp(servconn->http_data->gateway_ip, |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
361 msn_servconn_get_server(servconn)) != 0) |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
362 { |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
363 int i; |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
364 |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
365 /* Evil hackery. I promise to remove it, even though I can't. */ |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
366 |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
367 servconn->connected = FALSE; |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
368 |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
369 if (servconn->inpa) |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
370 gaim_input_remove(servconn->inpa); |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
371 |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
372 close(servconn->fd); |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
373 |
8583
fc27237783ee
[gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents:
8569
diff
changeset
|
374 i = gaim_proxy_connect(session->account, servconn->host, |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9093
diff
changeset
|
375 servconn->port, read_cb, servconn); |
7288
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
376 |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
377 if (i == 0) |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
378 servconn->connected = TRUE; |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
379 } |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
380 #endif |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
381 |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
382 g_free(servconn->rx_buf); |
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
383 servconn->rx_buf = result_msg; |
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
384 servconn->rx_len = result_len; |
7288
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
385 } |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
386 |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
387 end = old_rx_buf = servconn->rx_buf; |
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
388 |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8662
diff
changeset
|
389 servconn->processing = TRUE; |
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8662
diff
changeset
|
390 |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
391 do |
7288
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
392 { |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
393 cur = end; |
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
394 |
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
395 if (servconn->payload_len) |
7288
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
396 { |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
397 if (servconn->payload_len > servconn->rx_len) |
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
398 /* The payload is still not complete. */ |
5309 | 399 break; |
400 | |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
401 cur_len = servconn->payload_len; |
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
402 end += cur_len; |
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
403 } |
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
404 else |
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
405 { |
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
406 end = strstr(cur, "\r\n"); |
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
407 |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
408 if (end == NULL) |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
409 /* The command is still not complete. */ |
5309 | 410 break; |
411 | |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
412 *end = '\0'; |
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
413 end += 2; |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
414 cur_len = end - cur; |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
415 } |
5309 | 416 |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
417 servconn->rx_len -= cur_len; |
5899
349204c9a709
[gaim-migrate @ 6331]
Christian Hammond <chipx86@chipx86.com>
parents:
5898
diff
changeset
|
418 |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
419 if (servconn->payload_len) |
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
420 { |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8662
diff
changeset
|
421 msn_cmdproc_process_payload(servconn->cmdproc, cur, cur_len); |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
422 servconn->payload_len = 0; |
5309 | 423 } |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
424 else |
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
425 { |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8662
diff
changeset
|
426 msn_cmdproc_process_cmd_text(servconn->cmdproc, cur); |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
427 } |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
428 } while (servconn->connected && servconn->rx_len > 0); |
5309 | 429 |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
430 if (servconn->connected) |
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
431 { |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
432 if (servconn->rx_len > 0) |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
433 servconn->rx_buf = g_memdup(cur, servconn->rx_len); |
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
434 else |
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
435 servconn->rx_buf = NULL; |
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
436 } |
5309 | 437 |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8662
diff
changeset
|
438 servconn->processing = FALSE; |
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8662
diff
changeset
|
439 |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
440 if (servconn->wasted) |
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
441 msn_servconn_destroy(servconn); |
5309 | 442 |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
443 g_free(old_rx_buf); |
5309 | 444 } |
9193
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 0 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
447 static int |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
448 create_listener(int port) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
449 { |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
450 int fd; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
451 const int on = 1; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
452 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
453 #if 0 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
454 struct addrinfo hints; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
455 struct addrinfo *c, *res; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
456 char port_str[5]; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
457 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
458 snprintf(port_str, sizeof(port_str), "%d", port); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
459 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
460 memset(&hints, 0, sizeof(hints)); |
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 hints.ai_flags = AI_PASSIVE; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
463 hints.ai_family = AF_UNSPEC; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
464 hints.ai_socktype = SOCK_STREAM; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
465 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
466 if (getaddrinfo(NULL, port_str, &hints, &res) != 0) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
467 { |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
468 gaim_debug_error("msn", "Could not get address info: %s.\n", |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
469 port_str); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
470 return -1; |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
471 } |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
472 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
473 for (c = res; c != NULL; c = c->ai_next) |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
474 { |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
475 fd = socket(c->ai_family, c->ai_socktype, c->ai_protocol); |
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 if (fd < 0) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
478 continue; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
479 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
480 setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); |
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, c->ai_addr, c->ai_addrlen) == 0) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
483 break; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
484 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
485 close(fd); |
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 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
488 if (c == NULL) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
489 { |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
490 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
|
491 return -1; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
492 } |
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 freeaddrinfo(res); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
495 #else |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
496 struct sockaddr_in sockin; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
497 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
498 fd = socket(AF_INET, SOCK_STREAM, 0); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
499 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
500 if (fd < 0) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
501 return -1; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
502 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
503 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
|
504 { |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
505 close(fd); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
506 return -1; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
507 } |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
508 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
509 memset(&sockin, 0, sizeof(struct sockaddr_in)); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
510 sockin.sin_family = AF_INET; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
511 sockin.sin_port = htons(port); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
512 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
513 if (bind(fd, (struct sockaddr *)&sockin, sizeof(struct sockaddr_in)) != 0) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
514 { |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
515 close(fd); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
516 return -1; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
517 } |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
518 #endif |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
519 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
520 if (listen (fd, 4) != 0) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
521 { |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
522 close (fd); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
523 return -1; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
524 } |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
525 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
526 fcntl(fd, F_SETFL, O_NONBLOCK); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
527 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
528 return fd; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
529 } |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9165
diff
changeset
|
530 #endif |