annotate src/protocols/msn/httpconn.c @ 13500:e66846dafeca

[gaim-migrate @ 15876] making grim happy committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Mon, 13 Mar 2006 22:08:53 +0000
parents 2a9580fc922b
children 4279e5b5e9ac
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
1 /**
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
2 * @file httpmethod.c HTTP connection method
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
3 *
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
4 * gaim
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
5 *
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
6 * Gaim is the legal property of its developers, whose names are too numerous
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
7 * to list here. Please refer to the COPYRIGHT file distributed with this
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
8 * source distribution.
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
9 *
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
10 * This program is free software; you can redistribute it and/or modify
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
11 * it under the terms of the GNU General Public License as published by
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
12 * the Free Software Foundation; either version 2 of the License, or
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
13 * (at your option) any later version.
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
14 *
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
15 * This program is distributed in the hope that it will be useful,
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
18 * GNU General Public License for more details.
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
19 *
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
20 * You should have received a copy of the GNU General Public License
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
21 * along with this program; if not, write to the Free Software
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
23 */
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
24 #include "msn.h"
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
25 #include "debug.h"
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
26 #include "httpconn.h"
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
27
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
28 static void read_cb(gpointer data, gint source, GaimInputCondition cond);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
29 gboolean msn_httpconn_parse_data(MsnHttpConn *httpconn, const char *buf,
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
30 size_t size, char **ret_buf, size_t *ret_size,
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
31 gboolean *error);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
32
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
33 MsnHttpConn *
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
34 msn_httpconn_new(MsnServConn *servconn)
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
35 {
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
36 MsnHttpConn *httpconn;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
37
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
38 g_return_val_if_fail(servconn != NULL, NULL);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
39
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
40 httpconn = g_new0(MsnHttpConn, 1);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
41
10481
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
42 gaim_debug_info("msn", "new httpconn (%p)\n", httpconn);
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
43
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
44 /* TODO: Remove this */
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
45 httpconn->session = servconn->session;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
46
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
47 httpconn->servconn = servconn;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
48
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
49 httpconn->tx_buf = gaim_circ_buffer_new(MSN_BUF_LEN);
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
50 httpconn->tx_handler = -1;
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
51
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
52 return httpconn;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
53 }
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
54
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
55 void
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
56 msn_httpconn_destroy(MsnHttpConn *httpconn)
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
57 {
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
58 g_return_if_fail(httpconn != NULL);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
59
10481
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
60 gaim_debug_info("msn", "destroy httpconn (%p)\n", httpconn);
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
61
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
62 if (httpconn->connected)
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
63 msn_httpconn_disconnect(httpconn);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
64
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
65 g_free(httpconn->full_session_id);
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
66
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
67 g_free(httpconn->session_id);
10504
1a97d5e88d12 [gaim-migrate @ 11796]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10481
diff changeset
68
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
69 g_free(httpconn->host);
10504
1a97d5e88d12 [gaim-migrate @ 11796]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10481
diff changeset
70
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
71 gaim_circ_buffer_destroy(httpconn->tx_buf);
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
72 if (httpconn->tx_handler > 0)
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
73 gaim_input_remove(httpconn->tx_handler);
10504
1a97d5e88d12 [gaim-migrate @ 11796]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10481
diff changeset
74
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
75 g_free(httpconn);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
76 }
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
77
10568
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
78 static char *
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
79 msn_httpconn_proxy_auth(MsnHttpConn *httpconn)
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
80 {
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
81 GaimAccount *account;
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
82 GaimProxyInfo *gpi;
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
83 const char *username, *password;
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
84 char *auth = NULL;
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
85
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
86 account = httpconn->session->account;
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
87
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
88 if (gaim_account_get_proxy_info(account) == NULL)
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
89 gpi = gaim_global_proxy_get_info();
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
90 else
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
91 gpi = gaim_account_get_proxy_info(account);
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
92
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
93 if (gpi == NULL || !(gaim_proxy_info_get_type(gpi) == GAIM_PROXY_HTTP ||
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
94 gaim_proxy_info_get_type(gpi) == GAIM_PROXY_USE_ENVVAR))
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
95 return NULL;
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
96
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
97 username = gaim_proxy_info_get_username(gpi);
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
98 password = gaim_proxy_info_get_password(gpi);
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
99
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
100 if (username != NULL) {
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
101 char *tmp;
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
102 auth = g_strdup_printf("%s:%s", username, password ? password : "");
11137
096020ae09a9 [gaim-migrate @ 13201]
Mark Doliner <mark@kingant.net>
parents: 10718
diff changeset
103 tmp = gaim_base64_encode((const guchar *)auth, strlen(auth));
10568
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
104 g_free(auth);
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
105 auth = g_strdup_printf("Proxy-Authorization: Basic %s\r\n", tmp);
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
106 g_free(tmp);
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
107 }
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
108
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
109 return auth;
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
110 }
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
111
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
112 static void
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
113 httpconn_write_cb(gpointer data, gint source, GaimInputCondition cond)
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
114 {
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
115 MsnHttpConn *httpconn = data;
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
116 int ret, writelen;
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
117
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
118 if (httpconn->waiting_response)
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
119 return;
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
120
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
121 writelen = gaim_circ_buffer_get_max_read(httpconn->tx_buf);
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
122
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
123 if (writelen == 0) {
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
124 gaim_input_remove(httpconn->tx_handler);
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
125 httpconn->tx_handler = -1;
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
126 return;
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
127 }
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
128
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
129 ret = write(httpconn->fd, httpconn->tx_buf->outptr, writelen);
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
130
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
131 if (ret < 0 && errno == EAGAIN)
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
132 return;
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
133 else if (ret <= 0) {
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
134 msn_servconn_got_error(httpconn->servconn,
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
135 MSN_SERVCONN_ERROR_WRITE);
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
136 return;
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
137 }
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
138
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
139 gaim_circ_buffer_mark_read(httpconn->tx_buf, ret);
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
140 }
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
141
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
142 static ssize_t
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
143 write_raw(MsnHttpConn *httpconn, const char *data, size_t data_len)
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
144 {
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
145 ssize_t res; /* result of the write operation */
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
146
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
147 #ifdef MSN_DEBUG_HTTP
10481
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
148 gaim_debug_misc("msn", "Writing HTTP (header): {%s}\n", header);
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
149 #endif
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
150
10481
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
151
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
152 if (httpconn->tx_handler == -1 && !httpconn->waiting_response)
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
153 res = write(httpconn->fd, data, data_len);
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
154 else
10481
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
155 {
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
156 res = -1;
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
157 errno = EAGAIN;
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
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
160 if (res <= 0 && errno != EAGAIN)
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
161 {
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
162 msn_servconn_got_error(httpconn->servconn,
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
163 MSN_SERVCONN_ERROR_WRITE);
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
164 return -1;
13277
2a9580fc922b [gaim-migrate @ 15643]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13270
diff changeset
165 } else if (res < 0 || res < data_len) {
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
166 if (res < 0)
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
167 res = 0;
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
168 if (httpconn->tx_handler == -1)
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
169 httpconn->tx_handler = gaim_input_add(httpconn->fd,
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
170 GAIM_INPUT_WRITE, httpconn_write_cb, httpconn);
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
171 gaim_circ_buffer_append(httpconn->tx_buf, data + res,
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
172 data_len - res);
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
173 }
10481
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
174
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
175 return res;
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
176 }
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
177
12323
fc464a0abccc [gaim-migrate @ 14627]
Richard Laager <rlaager@wiktel.com>
parents: 12213
diff changeset
178 static void
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
179 msn_httpconn_poll(MsnHttpConn *httpconn)
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
180 {
10481
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
181 char *header;
10568
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
182 char *auth;
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
183 int r;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
184
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
185 g_return_if_fail(httpconn != NULL);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
186
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
187 if (httpconn->waiting_response ||
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
188 httpconn->tx_handler > 0)
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
189 {
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
190 return;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
191 }
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
192
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
193 /* It is OK if this is buffered because it will only be buffered if
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
194 nothing else is in the buffer */
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
195
10568
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
196 auth = msn_httpconn_proxy_auth(httpconn);
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
197
10481
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
198 header = g_strdup_printf(
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
199 "POST http://%s/gateway/gateway.dll?Action=poll&SessionID=%s HTTP/1.1\r\n"
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
200 "Accept: */*\r\n"
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
201 "Accept-Language: en-us\r\n"
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
202 "User-Agent: MSMSGS\r\n"
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
203 "Host: %s\r\n"
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
204 "Proxy-Connection: Keep-Alive\r\n"
10568
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
205 "%s" /* Proxy auth */
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
206 "Connection: Keep-Alive\r\n"
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
207 "Pragma: no-cache\r\n"
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
208 "Content-Type: application/x-msn-messenger\r\n"
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
209 "Content-Length: 0\r\n\r\n",
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
210 httpconn->host,
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
211 httpconn->full_session_id,
10568
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
212 httpconn->host,
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
213 auth ? auth : "");
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
214
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
215 g_free(auth);
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
216
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
217 r = write_raw(httpconn, header, strlen(header));
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
218
10481
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
219 g_free(header);
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
220
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
221 if (r >= 0)
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
222 {
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
223 httpconn->waiting_response = TRUE;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
224 httpconn->dirty = FALSE;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
225 }
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
226 }
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
227
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
228 static gboolean
10543
052ef28a0695 [gaim-migrate @ 11909]
Nathan Walp <nwalp@pidgin.im>
parents: 10533
diff changeset
229 do_poll(gpointer data)
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
230 {
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
231 MsnHttpConn *httpconn;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
232
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
233 httpconn = data;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
234
10568
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
235 g_return_val_if_fail(httpconn != NULL, TRUE);
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
236
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
237 #if 0
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
238 gaim_debug_info("msn", "polling from %s\n", httpconn->session_id);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
239 #endif
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
240
10568
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
241 if ((httpconn->host == NULL) || (httpconn->full_session_id == NULL))
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
242 {
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
243 gaim_debug_warning("msn", "Attempted HTTP poll before session is established\n");
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
244 return TRUE;
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
245 }
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
246
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
247 if (httpconn->dirty)
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
248 msn_httpconn_poll(httpconn);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
249
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
250 return TRUE;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
251 }
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
252
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
253 static void
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
254 connect_cb(gpointer data, gint source, GaimInputCondition cond)
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
255 {
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
256 MsnHttpConn *httpconn = data;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
257
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
258 httpconn->fd = source;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
259
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
260 if (source > 0)
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
261 {
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
262 httpconn->inpa = gaim_input_add(httpconn->fd, GAIM_INPUT_READ,
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
263 read_cb, data);
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
264
10543
052ef28a0695 [gaim-migrate @ 11909]
Nathan Walp <nwalp@pidgin.im>
parents: 10533
diff changeset
265 httpconn->timer = gaim_timeout_add(2000, do_poll, httpconn);
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
266
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
267 httpconn->waiting_response = FALSE;
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
268 if (httpconn->tx_handler > 0)
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
269 httpconn_write_cb(httpconn, source, GAIM_INPUT_WRITE);
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
270 }
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
271 else
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
272 {
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
273 gaim_debug_error("msn", "HTTP: Connection error\n");
10481
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
274 msn_servconn_got_error(httpconn->servconn, MSN_SERVCONN_ERROR_CONNECT);
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
275 }
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
276 }
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
277
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
278 gboolean
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
279 msn_httpconn_connect(MsnHttpConn *httpconn, const char *host, int port)
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
280 {
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
281 int r;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
282
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
283 g_return_val_if_fail(httpconn != NULL, FALSE);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
284 g_return_val_if_fail(host != NULL, FALSE);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
285 g_return_val_if_fail(port > 0, FALSE);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
286
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
287 if (httpconn->connected)
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
288 msn_httpconn_disconnect(httpconn);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
289
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
290 r = gaim_proxy_connect(httpconn->session->account,
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
291 "gateway.messenger.hotmail.com", 80, connect_cb, httpconn);
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
292
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
293 if (r == 0)
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
294 {
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
295 httpconn->waiting_response = TRUE;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
296 httpconn->connected = TRUE;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
297 }
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
298
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
299 return httpconn->connected;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
300 }
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
301
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
302 void
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
303 msn_httpconn_disconnect(MsnHttpConn *httpconn)
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
304 {
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
305 g_return_if_fail(httpconn != NULL);
10481
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
306
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
307 if (!httpconn->connected)
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
308 return;
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
309
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
310 if (httpconn->timer)
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
311 gaim_timeout_remove(httpconn->timer);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
312
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
313 httpconn->timer = 0;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
314
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
315 if (httpconn->inpa > 0)
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
316 {
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
317 gaim_input_remove(httpconn->inpa);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
318 httpconn->inpa = 0;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
319 }
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
320
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
321 close(httpconn->fd);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
322
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
323 httpconn->rx_buf = NULL;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
324 httpconn->rx_len = 0;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
325
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
326 httpconn->connected = FALSE;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
327
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
328 /* msn_servconn_disconnect(httpconn->servconn); */
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
329 }
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
330
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
331 static void
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
332 read_cb(gpointer data, gint source, GaimInputCondition cond)
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
333 {
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
334 MsnHttpConn *httpconn;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
335 MsnServConn *servconn;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
336 MsnSession *session;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
337 char buf[MSN_BUF_LEN];
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
338 char *cur, *end, *old_rx_buf;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
339 int len, cur_len;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
340 char *result_msg = NULL;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
341 size_t result_len = 0;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
342 gboolean error;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
343
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
344 httpconn = data;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
345 servconn = NULL;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
346 session = httpconn->session;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
347
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
348 len = read(httpconn->fd, buf, sizeof(buf) - 1);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
349
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
350 if (len < 0 && errno == EAGAIN)
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
351 return;
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
352 else if (len <= 0)
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
353 {
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
354 gaim_debug_error("msn", "HTTP: Read error\n");
10481
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
355 msn_servconn_got_error(httpconn->servconn, MSN_SERVCONN_ERROR_READ);
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
356
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
357 return;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
358 }
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
359
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
360 buf[len] = '\0';
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
361
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
362 httpconn->rx_buf = g_realloc(httpconn->rx_buf, len + httpconn->rx_len + 1);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
363 memcpy(httpconn->rx_buf + httpconn->rx_len, buf, len + 1);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
364 httpconn->rx_len += len;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
365
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
366 if (!msn_httpconn_parse_data(httpconn, httpconn->rx_buf, httpconn->rx_len,
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
367 &result_msg, &result_len, &error))
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
368 {
10568
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
369 /* We must wait for more input, or something went wrong */
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
370 if (error)
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
371 msn_servconn_got_error(httpconn->servconn, MSN_SERVCONN_ERROR_READ);
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
372
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
373 return;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
374 }
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
375
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
376 httpconn->servconn->processing = FALSE;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
377
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
378 servconn = httpconn->servconn;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
379
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
380 if (error)
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
381 {
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
382 gaim_debug_error("msn", "HTTP: Special error\n");
10481
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
383 msn_servconn_got_error(httpconn->servconn, MSN_SERVCONN_ERROR_READ);
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
384
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
385 return;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
386 }
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
387
10533
ace8cd0de6ea [gaim-migrate @ 11862]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10504
diff changeset
388 if (httpconn->rx_buf != NULL)
ace8cd0de6ea [gaim-migrate @ 11862]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10504
diff changeset
389 g_free(httpconn->rx_buf);
ace8cd0de6ea [gaim-migrate @ 11862]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10504
diff changeset
390 httpconn->rx_buf = NULL;
ace8cd0de6ea [gaim-migrate @ 11862]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10504
diff changeset
391 httpconn->rx_len = 0;
ace8cd0de6ea [gaim-migrate @ 11862]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10504
diff changeset
392
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
393 if (result_len == 0)
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
394 {
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
395 /* Nothing to do here */
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
396 #if 0
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
397 gaim_debug_info("msn", "HTTP: nothing to do here\n");
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
398 #endif
10481
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
399 g_free(result_msg);
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
400 return;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
401 }
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
402
13270
8754a0fe2297 [gaim-migrate @ 15636]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13200
diff changeset
403 g_free(servconn->rx_buf);
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
404 servconn->rx_buf = result_msg;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
405 servconn->rx_len = result_len;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
406
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
407 end = old_rx_buf = servconn->rx_buf;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
408
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
409 servconn->processing = TRUE;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
410
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
411 do
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
412 {
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
413 cur = end;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
414
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
415 if (servconn->payload_len)
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
416 {
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
417 if (servconn->payload_len > servconn->rx_len)
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
418 /* The payload is still not complete. */
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
419 break;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
420
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
421 cur_len = servconn->payload_len;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
422 end += cur_len;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
423 }
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
424 else
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
425 {
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
426 end = strstr(cur, "\r\n");
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
427
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
428 if (end == NULL)
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
429 /* The command is still not complete. */
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
430 break;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
431
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
432 *end = '\0';
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
433 end += 2;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
434 cur_len = end - cur;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
435 }
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
436
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
437 servconn->rx_len -= cur_len;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
438
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
439 if (servconn->payload_len)
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
440 {
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
441 msn_cmdproc_process_payload(servconn->cmdproc, cur, cur_len);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
442 servconn->payload_len = 0;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
443 }
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
444 else
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
445 {
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
446 msn_cmdproc_process_cmd_text(servconn->cmdproc, cur);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
447 }
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
448 } while (servconn->connected && servconn->rx_len > 0);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
449
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
450 if (servconn->connected)
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
451 {
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
452 if (servconn->rx_len > 0)
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
453 servconn->rx_buf = g_memdup(cur, servconn->rx_len);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
454 else
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
455 servconn->rx_buf = NULL;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
456 }
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
457
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
458 servconn->processing = FALSE;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
459
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
460 if (servconn->wasted)
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
461 msn_servconn_destroy(servconn);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
462
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
463 g_free(old_rx_buf);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
464 }
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
465
13270
8754a0fe2297 [gaim-migrate @ 15636]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13200
diff changeset
466 ssize_t
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
467 msn_httpconn_write(MsnHttpConn *httpconn, const char *body, size_t size)
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
468 {
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
469 char *params;
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
470 char *data;
10568
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
471 char *auth;
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
472 const char *server_types[] = { "NS", "SB" };
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
473 const char *server_type;
13270
8754a0fe2297 [gaim-migrate @ 15636]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13200
diff changeset
474 ssize_t r; /* result of the write operation */
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
475 char *host;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
476 MsnServConn *servconn;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
477
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
478 /* TODO: remove http data from servconn */
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
479
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
480 g_return_val_if_fail(httpconn != NULL, 0);
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
481 g_return_val_if_fail(body != NULL, 0);
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
482 g_return_val_if_fail(size > 0, 0);
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
483
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
484 servconn = httpconn->servconn;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
485
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
486 server_type = server_types[servconn->type];
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
487
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
488 if (httpconn->virgin)
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
489 {
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
490 host = "gateway.messenger.hotmail.com";
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
491
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
492 /* The first time servconn->host is the host we should connect to. */
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
493 params = g_strdup_printf("Action=open&Server=%s&IP=%s",
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
494 server_type,
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
495 servconn->host);
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
496 httpconn->virgin = FALSE;
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
497 }
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
498 else
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
499 {
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
500 /* The rest of the times servconn->host is the gateway host. */
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
501 host = httpconn->host;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
502
10568
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
503 if (host == NULL || httpconn->full_session_id == NULL)
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
504 {
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
505 gaim_debug_warning("msn", "Attempted HTTP write before session is established\n");
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
506 return -1;
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
507 }
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
508
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
509 params = g_strdup_printf("SessionID=%s",
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
510 httpconn->full_session_id);
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
511 }
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
512
10568
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
513 auth = msn_httpconn_proxy_auth(httpconn);
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
514
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
515 data = g_strdup_printf(
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
516 "POST http://%s/gateway/gateway.dll?%s HTTP/1.1\r\n"
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
517 "Accept: */*\r\n"
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
518 "Accept-Language: en-us\r\n"
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
519 "User-Agent: MSMSGS\r\n"
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
520 "Host: %s\r\n"
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
521 "Proxy-Connection: Keep-Alive\r\n"
10568
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
522 "%s" /* Proxy auth */
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
523 "Connection: Keep-Alive\r\n"
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
524 "Pragma: no-cache\r\n"
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
525 "Content-Type: application/x-msn-messenger\r\n"
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
526 "Content-Length: %d\r\n\r\n"
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
527 "%s",
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
528 host,
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
529 params,
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
530 host,
10568
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
531 auth ? auth : "",
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
532 (int) size,
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
533 body ? body : "");
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
534
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
535
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
536 g_free(params);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
537
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
538 g_free(auth);
10568
fed2a7c2471d [gaim-migrate @ 11954]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10543
diff changeset
539
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
540 r = write_raw(httpconn, data, strlen(data));
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
541
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
542 g_free(data);
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
543
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
544 if (r >= 0)
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
545 {
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
546 httpconn->waiting_response = TRUE;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
547 httpconn->dirty = FALSE;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
548 }
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
549
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
550 return r;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
551 }
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
552
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
553 gboolean
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
554 msn_httpconn_parse_data(MsnHttpConn *httpconn, const char *buf,
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
555 size_t size, char **ret_buf, size_t *ret_size,
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
556 gboolean *error)
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
557 {
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
558 GaimConnection *gc;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
559 const char *s, *c;
10481
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
560 char *header, *body;
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
561 const char *body_start;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
562 char *tmp;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
563 size_t body_len = 0;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
564 gboolean wasted = FALSE;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
565
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
566 g_return_val_if_fail(httpconn != NULL, FALSE);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
567 g_return_val_if_fail(buf != NULL, FALSE);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
568 g_return_val_if_fail(size > 0, FALSE);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
569 g_return_val_if_fail(ret_buf != NULL, FALSE);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
570 g_return_val_if_fail(ret_size != NULL, FALSE);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
571 g_return_val_if_fail(error != NULL, FALSE);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
572
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
573 #if 0
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
574 gaim_debug_info("msn", "HTTP: parsing data {%s}\n", buf);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
575 #endif
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
576
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
577 httpconn->waiting_response = FALSE;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
578
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
579 gc = gaim_account_get_connection(httpconn->session->account);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
580
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
581 /* Healthy defaults. */
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
582 body = NULL;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
583
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
584 *ret_buf = NULL;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
585 *ret_size = 0;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
586 *error = FALSE;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
587
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
588 /* First, some tests to see if we have a full block of stuff. */
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
589 if (((strncmp(buf, "HTTP/1.1 200 OK\r\n", 17) != 0) &&
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
590 (strncmp(buf, "HTTP/1.1 100 Continue\r\n", 23) != 0)) &&
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
591 ((strncmp(buf, "HTTP/1.0 200 OK\r\n", 17) != 0) &&
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
592 (strncmp(buf, "HTTP/1.0 100 Continue\r\n", 23) != 0)))
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
593 {
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
594 *error = TRUE;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
595
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
596 return FALSE;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
597 }
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
598
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
599 if (strncmp(buf, "HTTP/1.1 100 Continue\r\n", 23) == 0)
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
600 {
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
601 if ((s = strstr(buf, "\r\n\r\n")) == NULL)
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
602 return FALSE;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
603
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
604 s += 4;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
605
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
606 if (*s == '\0')
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
607 {
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
608 *ret_buf = g_strdup("");
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
609 *ret_size = 0;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
610
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
611 if (httpconn->tx_handler > 0)
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
612 httpconn_write_cb(httpconn, httpconn->fd,
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
613 GAIM_INPUT_WRITE);
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
614
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
615 return TRUE;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
616 }
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
617
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
618 buf = s;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
619 size -= (s - buf);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
620 }
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
621
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
622 if ((s = strstr(buf, "\r\n\r\n")) == NULL)
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
623 return FALSE;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
624
10718
56f1c92b943f [gaim-migrate @ 12315]
Mark Doliner <mark@kingant.net>
parents: 10568
diff changeset
625 s += 4; /* Skip \r\n */
10481
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
626 header = g_strndup(buf, s - buf);
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
627 body_start = s;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
628 body_len = size - (body_start - buf);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
629
12213
4e7ba55a1db2 [gaim-migrate @ 14515]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11340
diff changeset
630 if ((s = gaim_strcasestr(header, "Content-Length: ")) != NULL)
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
631 {
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
632 int tmp_len;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
633
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
634 s += strlen("Content-Length: ");
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
635
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
636 if ((c = strchr(s, '\r')) == NULL)
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
637 {
10481
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
638 g_free(header);
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
639
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
640 return FALSE;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
641 }
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
642
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
643 tmp = g_strndup(s, c - s);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
644 tmp_len = atoi(tmp);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
645 g_free(tmp);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
646
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
647 if (body_len != tmp_len)
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
648 {
10481
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
649 g_free(header);
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
650
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
651 #if 0
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
652 gaim_debug_warning("msn",
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
653 "body length (%d) != content length (%d)\n",
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
654 body_len, tmp_len);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
655 #endif
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
656
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
657 return FALSE;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
658 }
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
659 }
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
660
10481
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
661 body = g_malloc0(body_len + 1);
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
662 memcpy(body, body_start, body_len);
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
663
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
664 #ifdef MSN_DEBUG_HTTP
10481
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
665 gaim_debug_misc("msn", "Incoming HTTP buffer (header): {%s\r\n}\n",
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
666 header);
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
667 #endif
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
668
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
669 /* Now we should be able to process the data. */
12213
4e7ba55a1db2 [gaim-migrate @ 14515]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11340
diff changeset
670 if ((s = gaim_strcasestr(header, "X-MSN-Messenger: ")) != NULL)
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
671 {
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
672 char *full_session_id, *gw_ip, *session_action;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
673 char *t, *session_id;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
674 char **elems, **cur, **tokens;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
675
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
676 full_session_id = gw_ip = session_action = NULL;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
677
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
678 s += strlen("X-MSN-Messenger: ");
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
679
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
680 if ((c = strchr(s, '\r')) == NULL)
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
681 {
10481
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
682 msn_session_set_error(httpconn->session,
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
683 MSN_ERROR_HTTP_MALFORMED, NULL);
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
684 gaim_debug_error("msn", "Malformed X-MSN-Messenger field.\n{%s}",
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
685 buf);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
686
10481
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
687 g_free(body);
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
688 return FALSE;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
689 }
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
690
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
691 tmp = g_strndup(s, c - s);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
692
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
693 elems = g_strsplit(tmp, "; ", 0);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
694
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
695 for (cur = elems; *cur != NULL; cur++)
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
696 {
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
697 tokens = g_strsplit(*cur, "=", 2);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
698
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
699 if (strcmp(tokens[0], "SessionID") == 0)
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
700 full_session_id = tokens[1];
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
701 else if (strcmp(tokens[0], "GW-IP") == 0)
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
702 gw_ip = tokens[1];
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
703 else if (strcmp(tokens[0], "Session") == 0)
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
704 session_action = tokens[1];
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
705
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
706 g_free(tokens[0]);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
707 /* Don't free each of the tokens, only the array. */
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
708 g_free(tokens);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
709 }
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
710
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
711 g_strfreev(elems);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
712
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
713 g_free(tmp);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
714
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
715 if ((session_action != NULL) && (strcmp(session_action, "close") == 0))
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
716 wasted = TRUE;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
717
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
718 g_free(session_action);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
719
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
720 t = strchr(full_session_id, '.');
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
721 session_id = g_strndup(full_session_id, t - full_session_id);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
722
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
723 if (!wasted)
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
724 {
10504
1a97d5e88d12 [gaim-migrate @ 11796]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10481
diff changeset
725 if (httpconn->full_session_id != NULL)
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
726 g_free(httpconn->full_session_id);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
727
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
728 httpconn->full_session_id = full_session_id;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
729
10504
1a97d5e88d12 [gaim-migrate @ 11796]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10481
diff changeset
730 if (httpconn->session_id != NULL)
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
731 g_free(httpconn->session_id);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
732
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
733 httpconn->session_id = session_id;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
734
10504
1a97d5e88d12 [gaim-migrate @ 11796]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10481
diff changeset
735 if (httpconn->host != NULL)
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
736 g_free(httpconn->host);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
737
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
738 httpconn->host = gw_ip;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
739 }
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
740 else
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
741 {
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
742 MsnServConn *servconn;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
743
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
744 /* It's going to die. */
10504
1a97d5e88d12 [gaim-migrate @ 11796]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10481
diff changeset
745 /* poor thing */
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
746
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
747 servconn = httpconn->servconn;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
748
10533
ace8cd0de6ea [gaim-migrate @ 11862]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10504
diff changeset
749 /* I'll be honest, I don't fully understand all this, but this
ace8cd0de6ea [gaim-migrate @ 11862]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10504
diff changeset
750 * causes crashes, Stu. */
ace8cd0de6ea [gaim-migrate @ 11862]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10504
diff changeset
751 /* if (servconn != NULL)
ace8cd0de6ea [gaim-migrate @ 11862]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10504
diff changeset
752 servconn->wasted = TRUE; */
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
753
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
754 g_free(full_session_id);
10504
1a97d5e88d12 [gaim-migrate @ 11796]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10481
diff changeset
755 g_free(session_id);
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
756 g_free(gw_ip);
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
757 }
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
758 }
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
759
10481
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10463
diff changeset
760 g_free(header);
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
761
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
762 *ret_buf = body;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
763 *ret_size = body_len;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
764
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
765 if (httpconn->tx_handler > 0)
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12323
diff changeset
766 httpconn_write_cb(httpconn, httpconn->fd, GAIM_INPUT_WRITE);
10463
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
767
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
768 return TRUE;
9bed28273ec7 [gaim-migrate @ 11737]
Stu Tomlinson <stu@nosnilmot.com>
parents:
diff changeset
769 }