annotate src/protocols/msn/servconn.c @ 12231:c342eb6e8cd3

[gaim-migrate @ 14533] Fix code as per a warning. committer: Tailor Script <tailor@pidgin.im>
author Richard Laager <rlaager@wiktel.com>
date Sun, 27 Nov 2005 03:17:05 +0000
parents 4e7ba55a1db2
children 33bef17125c2
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
10481
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
30 /**************************************************************************
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
31 * Main
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
32 **************************************************************************/
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
33
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
34 MsnServConn *
9158
c30d81b4dd22 [gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents: 9093
diff changeset
35 msn_servconn_new(MsnSession *session, MsnServConnType type)
5309
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 MsnServConn *servconn;
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
38
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
39 g_return_val_if_fail(session != NULL, NULL);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
40
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
41 servconn = g_new0(MsnServConn, 1);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
42
8808
bbd8cdaf0ad5 [gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents: 8662
diff changeset
43 servconn->type = type;
bbd8cdaf0ad5 [gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents: 8662
diff changeset
44
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
45 servconn->session = session;
8808
bbd8cdaf0ad5 [gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents: 8662
diff changeset
46 servconn->cmdproc = msn_cmdproc_new(session);
bbd8cdaf0ad5 [gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents: 8662
diff changeset
47 servconn->cmdproc->servconn = servconn;
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
48
10481
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
49 servconn->httpconn = msn_httpconn_new(servconn);
7288
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
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10434
diff changeset
70 if (servconn->destroy_cb)
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10434
diff changeset
71 servconn->destroy_cb(servconn);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10434
diff changeset
72
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10434
diff changeset
73 if (servconn->httpconn != NULL)
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10434
diff changeset
74 msn_httpconn_destroy(servconn->httpconn);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10434
diff changeset
75
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10434
diff changeset
76 if (servconn->host != NULL)
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10434
diff changeset
77 g_free(servconn->host);
9193
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
78
9158
c30d81b4dd22 [gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents: 9093
diff changeset
79 msn_cmdproc_destroy(servconn->cmdproc);
c30d81b4dd22 [gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents: 9093
diff changeset
80 g_free(servconn);
c30d81b4dd22 [gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents: 9093
diff changeset
81 }
c30d81b4dd22 [gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents: 9093
diff changeset
82
10481
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
83 void
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
84 msn_servconn_set_connect_cb(MsnServConn *servconn,
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
85 void (*connect_cb)(MsnServConn *))
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
86 {
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
87 g_return_if_fail(servconn != NULL);
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
88 servconn->connect_cb = connect_cb;
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
89 }
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
90
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
91 void
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
92 msn_servconn_set_disconnect_cb(MsnServConn *servconn,
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
93 void (*disconnect_cb)(MsnServConn *))
10296
a7b2fd5efcf2 [gaim-migrate @ 11476]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10225
diff changeset
94 {
10481
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
95 g_return_if_fail(servconn != NULL);
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
96
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
97 servconn->disconnect_cb = disconnect_cb;
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
98 }
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
99
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
100 void
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
101 msn_servconn_set_destroy_cb(MsnServConn *servconn,
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
102 void (*destroy_cb)(MsnServConn *))
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
103 {
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
104 g_return_if_fail(servconn != NULL);
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
105
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
106 servconn->destroy_cb = destroy_cb;
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
107 }
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
108
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
109 /**************************************************************************
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
110 * Utility
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
111 **************************************************************************/
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
112
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
113 void
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
114 msn_servconn_got_error(MsnServConn *servconn, MsnServConnError error)
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
115 {
10296
a7b2fd5efcf2 [gaim-migrate @ 11476]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10225
diff changeset
116 char *tmp;
10481
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
117 const char *reason;
10296
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 const char *names[] = { "Notification", "Switchboard" };
a7b2fd5efcf2 [gaim-migrate @ 11476]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10225
diff changeset
120 const char *name;
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 name = names[servconn->type];
a7b2fd5efcf2 [gaim-migrate @ 11476]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10225
diff changeset
123
10481
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
124 switch (error)
10296
a7b2fd5efcf2 [gaim-migrate @ 11476]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10225
diff changeset
125 {
10481
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
126 case MSN_SERVCONN_ERROR_CONNECT:
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
127 reason = _("Unable to connect"); break;
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
128 case MSN_SERVCONN_ERROR_WRITE:
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
129 reason = _("Writing error"); break;
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
130 case MSN_SERVCONN_ERROR_READ:
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
131 reason = _("Reading error"); break;
10296
a7b2fd5efcf2 [gaim-migrate @ 11476]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10225
diff changeset
132 default:
10481
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
133 reason = _("Unknown error"); break;
10296
a7b2fd5efcf2 [gaim-migrate @ 11476]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10225
diff changeset
134 }
a7b2fd5efcf2 [gaim-migrate @ 11476]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10225
diff changeset
135
11897
a1aa681f1448 [gaim-migrate @ 14188]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10773
diff changeset
136 gaim_debug_error("msn", "Connection error from %s server (%s): %s\n",
a1aa681f1448 [gaim-migrate @ 14188]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10773
diff changeset
137 name, servconn->host, reason);
a1aa681f1448 [gaim-migrate @ 14188]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10773
diff changeset
138 tmp = g_strdup_printf(_("Connection error from %s server:\n%s"),
a1aa681f1448 [gaim-migrate @ 14188]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10773
diff changeset
139 name, reason);
10481
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
140
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
141 if (servconn->type == MSN_SERVCONN_NS)
10296
a7b2fd5efcf2 [gaim-migrate @ 11476]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10225
diff changeset
142 {
10481
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
143 msn_session_set_error(servconn->session, MSN_ERROR_SERVCONN, tmp);
10296
a7b2fd5efcf2 [gaim-migrate @ 11476]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10225
diff changeset
144 }
10481
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
145 else if (servconn->type == MSN_SERVCONN_SB)
10296
a7b2fd5efcf2 [gaim-migrate @ 11476]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10225
diff changeset
146 {
a7b2fd5efcf2 [gaim-migrate @ 11476]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10225
diff changeset
147 MsnSwitchBoard *swboard;
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10434
diff changeset
148 swboard = servconn->cmdproc->data;
10481
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
149 if (swboard != NULL)
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
150 swboard->error = MSN_SB_ERROR_CONNECTION;
10296
a7b2fd5efcf2 [gaim-migrate @ 11476]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10225
diff changeset
151 }
a7b2fd5efcf2 [gaim-migrate @ 11476]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10225
diff changeset
152
10481
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
153 msn_servconn_disconnect(servconn);
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
154
10296
a7b2fd5efcf2 [gaim-migrate @ 11476]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10225
diff changeset
155 g_free(tmp);
a7b2fd5efcf2 [gaim-migrate @ 11476]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10225
diff changeset
156 }
a7b2fd5efcf2 [gaim-migrate @ 11476]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10225
diff changeset
157
10481
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
158 /**************************************************************************
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
159 * Connect
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
160 **************************************************************************/
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
161
10296
a7b2fd5efcf2 [gaim-migrate @ 11476]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10225
diff changeset
162 static void
a7b2fd5efcf2 [gaim-migrate @ 11476]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10225
diff changeset
163 connect_cb(gpointer data, gint source, GaimInputCondition cond)
a7b2fd5efcf2 [gaim-migrate @ 11476]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10225
diff changeset
164 {
a7b2fd5efcf2 [gaim-migrate @ 11476]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10225
diff changeset
165 MsnServConn *servconn = data;
a7b2fd5efcf2 [gaim-migrate @ 11476]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10225
diff changeset
166
10403
e5455f1dc9b6 [gaim-migrate @ 11648]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10296
diff changeset
167 servconn->processing = FALSE;
e5455f1dc9b6 [gaim-migrate @ 11648]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10296
diff changeset
168
e5455f1dc9b6 [gaim-migrate @ 11648]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10296
diff changeset
169 if (servconn->wasted)
e5455f1dc9b6 [gaim-migrate @ 11648]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10296
diff changeset
170 {
e5455f1dc9b6 [gaim-migrate @ 11648]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10296
diff changeset
171 msn_servconn_destroy(servconn);
e5455f1dc9b6 [gaim-migrate @ 11648]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10296
diff changeset
172 return;
e5455f1dc9b6 [gaim-migrate @ 11648]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10296
diff changeset
173 }
e5455f1dc9b6 [gaim-migrate @ 11648]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10296
diff changeset
174
10296
a7b2fd5efcf2 [gaim-migrate @ 11476]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10225
diff changeset
175 servconn->fd = source;
a7b2fd5efcf2 [gaim-migrate @ 11476]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10225
diff changeset
176
a7b2fd5efcf2 [gaim-migrate @ 11476]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10225
diff changeset
177 if (source > 0)
a7b2fd5efcf2 [gaim-migrate @ 11476]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10225
diff changeset
178 {
10403
e5455f1dc9b6 [gaim-migrate @ 11648]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10296
diff changeset
179 servconn->connected = TRUE;
e5455f1dc9b6 [gaim-migrate @ 11648]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10296
diff changeset
180
10296
a7b2fd5efcf2 [gaim-migrate @ 11476]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10225
diff changeset
181 /* Someone wants to know we connected. */
a7b2fd5efcf2 [gaim-migrate @ 11476]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10225
diff changeset
182 servconn->connect_cb(servconn);
a7b2fd5efcf2 [gaim-migrate @ 11476]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10225
diff changeset
183 servconn->inpa = gaim_input_add(servconn->fd, GAIM_INPUT_READ,
a7b2fd5efcf2 [gaim-migrate @ 11476]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10225
diff changeset
184 read_cb, data);
a7b2fd5efcf2 [gaim-migrate @ 11476]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10225
diff changeset
185 }
a7b2fd5efcf2 [gaim-migrate @ 11476]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10225
diff changeset
186 else
a7b2fd5efcf2 [gaim-migrate @ 11476]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10225
diff changeset
187 {
10481
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
188 msn_servconn_got_error(servconn, MSN_SERVCONN_ERROR_CONNECT);
10296
a7b2fd5efcf2 [gaim-migrate @ 11476]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10225
diff changeset
189 }
a7b2fd5efcf2 [gaim-migrate @ 11476]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10225
diff changeset
190 }
a7b2fd5efcf2 [gaim-migrate @ 11476]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10225
diff changeset
191
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
192 gboolean
8583
fc27237783ee [gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents: 8569
diff changeset
193 msn_servconn_connect(MsnServConn *servconn, const char *host, int port)
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
194 {
7288
ff9127038a5a [gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents: 6842
diff changeset
195 MsnSession *session;
9158
c30d81b4dd22 [gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents: 9093
diff changeset
196 int r;
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
197
8583
fc27237783ee [gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents: 8569
diff changeset
198 g_return_val_if_fail(servconn != NULL, FALSE);
fc27237783ee [gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents: 8569
diff changeset
199 g_return_val_if_fail(host != NULL, FALSE);
fc27237783ee [gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents: 8569
diff changeset
200 g_return_val_if_fail(port > 0, FALSE);
7288
ff9127038a5a [gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents: 6842
diff changeset
201
ff9127038a5a [gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents: 6842
diff changeset
202 session = servconn->session;
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
203
8583
fc27237783ee [gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents: 8569
diff changeset
204 if (servconn->connected)
fc27237783ee [gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents: 8569
diff changeset
205 msn_servconn_disconnect(servconn);
fc27237783ee [gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents: 8569
diff changeset
206
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10434
diff changeset
207 if (servconn->host != NULL)
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10434
diff changeset
208 g_free(servconn->host);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10434
diff changeset
209
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10434
diff changeset
210 servconn->host = g_strdup(host);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10434
diff changeset
211
7288
ff9127038a5a [gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents: 6842
diff changeset
212 if (session->http_method)
ff9127038a5a [gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents: 6842
diff changeset
213 {
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10434
diff changeset
214 /* HTTP Connection. */
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10434
diff changeset
215
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10434
diff changeset
216 if (!servconn->httpconn->connected)
10568
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10481
diff changeset
217 if (!msn_httpconn_connect(servconn->httpconn, host, port))
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10481
diff changeset
218 return FALSE;;
9198
ab6636c5a136 [gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents: 9193
diff changeset
219
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10434
diff changeset
220 servconn->connected = TRUE;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10434
diff changeset
221 servconn->httpconn->virgin = TRUE;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10434
diff changeset
222
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10434
diff changeset
223 /* Someone wants to know we connected. */
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10434
diff changeset
224 servconn->connect_cb(servconn);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10434
diff changeset
225
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10434
diff changeset
226 return TRUE;
7288
ff9127038a5a [gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents: 6842
diff changeset
227 }
ff9127038a5a [gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents: 6842
diff changeset
228
9158
c30d81b4dd22 [gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents: 9093
diff changeset
229 r = gaim_proxy_connect(session->account, host, port, connect_cb,
8583
fc27237783ee [gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents: 8569
diff changeset
230 servconn);
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
231
9158
c30d81b4dd22 [gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents: 9093
diff changeset
232 if (r == 0)
9193
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
233 {
10403
e5455f1dc9b6 [gaim-migrate @ 11648]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10296
diff changeset
234 servconn->processing = TRUE;
9193
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
235 return TRUE;
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
236 }
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
237 else
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
238 return FALSE;
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
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
241 void
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
242 msn_servconn_disconnect(MsnServConn *servconn)
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 g_return_if_fail(servconn != NULL);
10434
6be6da69d603 [gaim-migrate @ 11691]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10403
diff changeset
245
6be6da69d603 [gaim-migrate @ 11691]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10403
diff changeset
246 if (!servconn->connected)
6be6da69d603 [gaim-migrate @ 11691]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10403
diff changeset
247 {
10481
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
248 /* We could not connect. */
10434
6be6da69d603 [gaim-migrate @ 11691]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10403
diff changeset
249 if (servconn->disconnect_cb != NULL)
6be6da69d603 [gaim-migrate @ 11691]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10403
diff changeset
250 servconn->disconnect_cb(servconn);
6be6da69d603 [gaim-migrate @ 11691]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10403
diff changeset
251
6be6da69d603 [gaim-migrate @ 11691]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10403
diff changeset
252 return;
6be6da69d603 [gaim-migrate @ 11691]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10403
diff changeset
253 }
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
254
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10434
diff changeset
255 if (servconn->session->http_method)
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10434
diff changeset
256 {
10481
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
257 /* Fake disconnection. */
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10434
diff changeset
258 if (servconn->disconnect_cb != NULL)
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10434
diff changeset
259 servconn->disconnect_cb(servconn);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10434
diff changeset
260
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10434
diff changeset
261 return;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10434
diff changeset
262 }
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10434
diff changeset
263
8646
1e211dde3cae [gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents: 8583
diff changeset
264 if (servconn->inpa > 0)
1e211dde3cae [gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents: 8583
diff changeset
265 {
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
266 gaim_input_remove(servconn->inpa);
8646
1e211dde3cae [gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents: 8583
diff changeset
267 servconn->inpa = 0;
1e211dde3cae [gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents: 8583
diff changeset
268 }
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
269
5744
6b87c127fe7b [gaim-migrate @ 6168]
Christian Hammond <chipx86@chipx86.com>
parents: 5681
diff changeset
270 close(servconn->fd);
6b87c127fe7b [gaim-migrate @ 6168]
Christian Hammond <chipx86@chipx86.com>
parents: 5681
diff changeset
271
10403
e5455f1dc9b6 [gaim-migrate @ 11648]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10296
diff changeset
272 servconn->rx_buf = NULL;
8646
1e211dde3cae [gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents: 8583
diff changeset
273 servconn->rx_len = 0;
1e211dde3cae [gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents: 8583
diff changeset
274 servconn->payload_len = 0;
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
275
9193
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
276 servconn->connected = FALSE;
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
277
8646
1e211dde3cae [gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents: 8583
diff changeset
278 if (servconn->disconnect_cb != NULL)
8583
fc27237783ee [gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents: 8569
diff changeset
279 servconn->disconnect_cb(servconn);
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
280 }
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
281
8808
bbd8cdaf0ad5 [gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents: 8662
diff changeset
282 size_t
9158
c30d81b4dd22 [gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents: 9093
diff changeset
283 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
284 {
8808
bbd8cdaf0ad5 [gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents: 8662
diff changeset
285 size_t ret = FALSE;
8646
1e211dde3cae [gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents: 8583
diff changeset
286
8808
bbd8cdaf0ad5 [gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents: 8662
diff changeset
287 g_return_val_if_fail(servconn != NULL, 0);
8646
1e211dde3cae [gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents: 8583
diff changeset
288
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10434
diff changeset
289 if (!servconn->session->http_method)
9193
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
290 {
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
291 switch (servconn->type)
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
292 {
10481
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
293 case MSN_SERVCONN_NS:
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
294 case MSN_SERVCONN_SB:
9193
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
295 ret = write(servconn->fd, buf, len);
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
296 break;
10481
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
297 #if 0
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
298 case MSN_SERVCONN_DC:
9193
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
299 ret = write(servconn->fd, &buf, sizeof(len));
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
300 ret = write(servconn->fd, buf, len);
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
301 break;
10481
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
302 #endif
9193
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
303 default:
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
304 ret = write(servconn->fd, buf, len);
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
305 break;
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
306 }
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
307 }
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
308 else
8808
bbd8cdaf0ad5 [gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents: 8662
diff changeset
309 {
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10434
diff changeset
310 ret = msn_httpconn_write(servconn->httpconn, buf, len);
8808
bbd8cdaf0ad5 [gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents: 8662
diff changeset
311 }
8646
1e211dde3cae [gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents: 8583
diff changeset
312
9193
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
313 if (ret == -1)
8808
bbd8cdaf0ad5 [gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents: 8662
diff changeset
314 {
10481
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
315 msn_servconn_got_error(servconn, MSN_SERVCONN_ERROR_WRITE);
8646
1e211dde3cae [gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents: 8583
diff changeset
316 }
1e211dde3cae [gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents: 8583
diff changeset
317
8808
bbd8cdaf0ad5 [gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents: 8662
diff changeset
318 return ret;
8646
1e211dde3cae [gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents: 8583
diff changeset
319 }
1e211dde3cae [gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents: 8583
diff changeset
320
1e211dde3cae [gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents: 8583
diff changeset
321 static void
8583
fc27237783ee [gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents: 8569
diff changeset
322 read_cb(gpointer data, gint source, GaimInputCondition cond)
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
323 {
8808
bbd8cdaf0ad5 [gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents: 8662
diff changeset
324 MsnServConn *servconn;
bbd8cdaf0ad5 [gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents: 8662
diff changeset
325 MsnSession *session;
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
326 char buf[MSN_BUF_LEN];
8646
1e211dde3cae [gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents: 8583
diff changeset
327 char *cur, *end, *old_rx_buf;
1e211dde3cae [gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents: 8583
diff changeset
328 int len, cur_len;
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
329
8808
bbd8cdaf0ad5 [gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents: 8662
diff changeset
330 servconn = data;
bbd8cdaf0ad5 [gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents: 8662
diff changeset
331 session = servconn->session;
bbd8cdaf0ad5 [gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents: 8662
diff changeset
332
8646
1e211dde3cae [gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents: 8583
diff changeset
333 len = read(servconn->fd, buf, sizeof(buf) - 1);
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
334
7288
ff9127038a5a [gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents: 6842
diff changeset
335 if (len <= 0)
ff9127038a5a [gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents: 6842
diff changeset
336 {
12213
4e7ba55a1db2 [gaim-migrate @ 14515]
Stu Tomlinson <stu@nosnilmot.com>
parents: 12182
diff changeset
337 gaim_debug_error("msn", "servconn read error, len: %d error: %s\n", len, strerror(errno));
10481
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
338 msn_servconn_got_error(servconn, MSN_SERVCONN_ERROR_READ);
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
339
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
340 return;
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
341 }
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
342
9193
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
343 buf[len] = '\0';
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
344
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
345 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
346 memcpy(servconn->rx_buf + servconn->rx_len, buf, len + 1);
8646
1e211dde3cae [gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents: 8583
diff changeset
347 servconn->rx_len += len;
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
348
8646
1e211dde3cae [gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents: 8583
diff changeset
349 end = old_rx_buf = servconn->rx_buf;
1e211dde3cae [gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents: 8583
diff changeset
350
8808
bbd8cdaf0ad5 [gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents: 8662
diff changeset
351 servconn->processing = TRUE;
bbd8cdaf0ad5 [gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents: 8662
diff changeset
352
8646
1e211dde3cae [gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents: 8583
diff changeset
353 do
7288
ff9127038a5a [gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents: 6842
diff changeset
354 {
8646
1e211dde3cae [gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents: 8583
diff changeset
355 cur = end;
1e211dde3cae [gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents: 8583
diff changeset
356
1e211dde3cae [gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents: 8583
diff changeset
357 if (servconn->payload_len)
7288
ff9127038a5a [gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents: 6842
diff changeset
358 {
8646
1e211dde3cae [gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents: 8583
diff changeset
359 if (servconn->payload_len > servconn->rx_len)
1e211dde3cae [gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents: 8583
diff changeset
360 /* The payload is still not complete. */
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
361 break;
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
362
8646
1e211dde3cae [gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents: 8583
diff changeset
363 cur_len = servconn->payload_len;
1e211dde3cae [gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents: 8583
diff changeset
364 end += cur_len;
1e211dde3cae [gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents: 8583
diff changeset
365 }
1e211dde3cae [gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents: 8583
diff changeset
366 else
1e211dde3cae [gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents: 8583
diff changeset
367 {
1e211dde3cae [gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents: 8583
diff changeset
368 end = strstr(cur, "\r\n");
1e211dde3cae [gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents: 8583
diff changeset
369
9193
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
370 if (end == NULL)
8646
1e211dde3cae [gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents: 8583
diff changeset
371 /* The command is still not complete. */
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
372 break;
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
373
8646
1e211dde3cae [gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents: 8583
diff changeset
374 *end = '\0';
1e211dde3cae [gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents: 8583
diff changeset
375 end += 2;
9193
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
376 cur_len = end - cur;
8646
1e211dde3cae [gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents: 8583
diff changeset
377 }
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
378
8646
1e211dde3cae [gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents: 8583
diff changeset
379 servconn->rx_len -= cur_len;
5899
349204c9a709 [gaim-migrate @ 6331]
Christian Hammond <chipx86@chipx86.com>
parents: 5898
diff changeset
380
8646
1e211dde3cae [gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents: 8583
diff changeset
381 if (servconn->payload_len)
1e211dde3cae [gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents: 8583
diff changeset
382 {
8808
bbd8cdaf0ad5 [gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents: 8662
diff changeset
383 msn_cmdproc_process_payload(servconn->cmdproc, cur, cur_len);
8646
1e211dde3cae [gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents: 8583
diff changeset
384 servconn->payload_len = 0;
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
385 }
8646
1e211dde3cae [gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents: 8583
diff changeset
386 else
1e211dde3cae [gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents: 8583
diff changeset
387 {
8808
bbd8cdaf0ad5 [gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents: 8662
diff changeset
388 msn_cmdproc_process_cmd_text(servconn->cmdproc, cur);
8646
1e211dde3cae [gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents: 8583
diff changeset
389 }
10773
888d4c328be5 [gaim-migrate @ 12382]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10568
diff changeset
390 } while (servconn->connected && !servconn->wasted && servconn->rx_len > 0);
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
391
10773
888d4c328be5 [gaim-migrate @ 12382]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10568
diff changeset
392 if (servconn->connected && !servconn->wasted)
8646
1e211dde3cae [gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents: 8583
diff changeset
393 {
9193
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
394 if (servconn->rx_len > 0)
8646
1e211dde3cae [gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents: 8583
diff changeset
395 servconn->rx_buf = g_memdup(cur, servconn->rx_len);
1e211dde3cae [gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents: 8583
diff changeset
396 else
1e211dde3cae [gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents: 8583
diff changeset
397 servconn->rx_buf = NULL;
1e211dde3cae [gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents: 8583
diff changeset
398 }
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
399
8808
bbd8cdaf0ad5 [gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents: 8662
diff changeset
400 servconn->processing = FALSE;
bbd8cdaf0ad5 [gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents: 8662
diff changeset
401
8646
1e211dde3cae [gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents: 8583
diff changeset
402 if (servconn->wasted)
1e211dde3cae [gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents: 8583
diff changeset
403 msn_servconn_destroy(servconn);
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
404
8646
1e211dde3cae [gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents: 8583
diff changeset
405 g_free(old_rx_buf);
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
406 }
9193
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
407
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
408 #if 0
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
409 static int
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
410 create_listener(int port)
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
411 {
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
412 int fd;
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
413 const int on = 1;
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
414
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
415 #if 0
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
416 struct addrinfo hints;
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
417 struct addrinfo *c, *res;
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
418 char port_str[5];
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
419
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
420 snprintf(port_str, sizeof(port_str), "%d", port);
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
421
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
422 memset(&hints, 0, sizeof(hints));
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
423
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
424 hints.ai_flags = AI_PASSIVE;
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
425 hints.ai_family = AF_UNSPEC;
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
426 hints.ai_socktype = SOCK_STREAM;
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
427
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
428 if (getaddrinfo(NULL, port_str, &hints, &res) != 0)
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
429 {
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
430 gaim_debug_error("msn", "Could not get address info: %s.\n",
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
431 port_str);
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
432 return -1;
9198
ab6636c5a136 [gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents: 9193
diff changeset
433 }
9193
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
434
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
435 for (c = res; c != NULL; c = c->ai_next)
9198
ab6636c5a136 [gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents: 9193
diff changeset
436 {
9193
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
437 fd = socket(c->ai_family, c->ai_socktype, c->ai_protocol);
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
438
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
439 if (fd < 0)
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
440 continue;
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
441
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
442 setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
443
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
444 if (bind(fd, c->ai_addr, c->ai_addrlen) == 0)
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
445 break;
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
446
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
447 close(fd);
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
448 }
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
449
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
450 if (c == NULL)
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 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
453 return -1;
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
454 }
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 freeaddrinfo(res);
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
457 #else
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
458 struct sockaddr_in sockin;
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 fd = socket(AF_INET, SOCK_STREAM, 0);
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 if (fd < 0)
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
463 return -1;
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
464
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
465 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
466 {
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
467 close(fd);
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
468 return -1;
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
469 }
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
470
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
471 memset(&sockin, 0, sizeof(struct sockaddr_in));
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
472 sockin.sin_family = AF_INET;
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
473 sockin.sin_port = htons(port);
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
474
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
475 if (bind(fd, (struct sockaddr *)&sockin, sizeof(struct sockaddr_in)) != 0)
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 close(fd);
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
478 return -1;
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 #endif
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 (listen (fd, 4) != 0)
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
483 {
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
484 close (fd);
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
485 return -1;
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
486 }
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
487
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
488 fcntl(fd, F_SETFL, O_NONBLOCK);
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 return fd;
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
491 }
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 9165
diff changeset
492 #endif