annotate src/protocols/msn/servconn.c @ 10456:d23802800eeb

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