comparison src/protocols/msn/httpconn.c @ 13516:4279e5b5e9ac

[gaim-migrate @ 15892] Bring MSN HTTP method closer to working again. Thanks to wabs in #gaim for noticing my braindead mistakes and pointing me in the right direction. This still needs more work. committer: Tailor Script <tailor@pidgin.im>
author Daniel Atallah <daniel.atallah@gmail.com>
date Wed, 15 Mar 2006 04:51:59 +0000
parents 2a9580fc922b
children bbc56ff2bd62
comparison
equal deleted inserted replaced
13515:f5d4300aeed8 13516:4279e5b5e9ac
45 httpconn->session = servconn->session; 45 httpconn->session = servconn->session;
46 46
47 httpconn->servconn = servconn; 47 httpconn->servconn = servconn;
48 48
49 httpconn->tx_buf = gaim_circ_buffer_new(MSN_BUF_LEN); 49 httpconn->tx_buf = gaim_circ_buffer_new(MSN_BUF_LEN);
50 httpconn->tx_handler = -1; 50 httpconn->tx_handler = 0;
51 51
52 return httpconn; 52 return httpconn;
53 } 53 }
54 54
55 void 55 void
119 return; 119 return;
120 120
121 writelen = gaim_circ_buffer_get_max_read(httpconn->tx_buf); 121 writelen = gaim_circ_buffer_get_max_read(httpconn->tx_buf);
122 122
123 if (writelen == 0) { 123 if (writelen == 0) {
124 httpconn->waiting_response = TRUE;
124 gaim_input_remove(httpconn->tx_handler); 125 gaim_input_remove(httpconn->tx_handler);
125 httpconn->tx_handler = -1; 126 httpconn->tx_handler = 0;
126 return; 127 return;
127 } 128 }
128 129
129 ret = write(httpconn->fd, httpconn->tx_buf->outptr, writelen); 130 ret = write(httpconn->fd, httpconn->tx_buf->outptr, writelen);
130 131
135 MSN_SERVCONN_ERROR_WRITE); 136 MSN_SERVCONN_ERROR_WRITE);
136 return; 137 return;
137 } 138 }
138 139
139 gaim_circ_buffer_mark_read(httpconn->tx_buf, ret); 140 gaim_circ_buffer_mark_read(httpconn->tx_buf, ret);
141
142 if (ret == writelen)
143 httpconn_write_cb(data, source, cond);
140 } 144 }
141 145
142 static ssize_t 146 static ssize_t
143 write_raw(MsnHttpConn *httpconn, const char *data, size_t data_len) 147 write_raw(MsnHttpConn *httpconn, const char *data, size_t data_len)
144 { 148 {
147 #ifdef MSN_DEBUG_HTTP 151 #ifdef MSN_DEBUG_HTTP
148 gaim_debug_misc("msn", "Writing HTTP (header): {%s}\n", header); 152 gaim_debug_misc("msn", "Writing HTTP (header): {%s}\n", header);
149 #endif 153 #endif
150 154
151 155
152 if (httpconn->tx_handler == -1 && !httpconn->waiting_response) 156 if (httpconn->tx_handler == 0 && !httpconn->waiting_response)
153 res = write(httpconn->fd, data, data_len); 157 res = write(httpconn->fd, data, data_len);
154 else 158 else
155 { 159 {
156 res = -1; 160 res = -1;
157 errno = EAGAIN; 161 errno = EAGAIN;
163 MSN_SERVCONN_ERROR_WRITE); 167 MSN_SERVCONN_ERROR_WRITE);
164 return -1; 168 return -1;
165 } else if (res < 0 || res < data_len) { 169 } else if (res < 0 || res < data_len) {
166 if (res < 0) 170 if (res < 0)
167 res = 0; 171 res = 0;
168 if (httpconn->tx_handler == -1) 172 if (httpconn->tx_handler == 0 && httpconn->fd)
169 httpconn->tx_handler = gaim_input_add(httpconn->fd, 173 httpconn->tx_handler = gaim_input_add(httpconn->fd,
170 GAIM_INPUT_WRITE, httpconn_write_cb, httpconn); 174 GAIM_INPUT_WRITE, httpconn_write_cb, httpconn);
171 gaim_circ_buffer_append(httpconn->tx_buf, data + res, 175 gaim_circ_buffer_append(httpconn->tx_buf, data + res,
172 data_len - res); 176 data_len - res);
173 } 177 }
264 268
265 httpconn->timer = gaim_timeout_add(2000, do_poll, httpconn); 269 httpconn->timer = gaim_timeout_add(2000, do_poll, httpconn);
266 270
267 httpconn->waiting_response = FALSE; 271 httpconn->waiting_response = FALSE;
268 if (httpconn->tx_handler > 0) 272 if (httpconn->tx_handler > 0)
269 httpconn_write_cb(httpconn, source, GAIM_INPUT_WRITE); 273 gaim_input_remove(httpconn->tx_handler);
274
275 httpconn->tx_handler = gaim_input_add(source,
276 GAIM_INPUT_WRITE, httpconn_write_cb, httpconn);
277
278 httpconn_write_cb(httpconn, source, GAIM_INPUT_WRITE);
270 } 279 }
271 else 280 else
272 { 281 {
273 gaim_debug_error("msn", "HTTP: Connection error\n"); 282 gaim_debug_error("msn", "HTTP: Connection error\n");
274 msn_servconn_got_error(httpconn->servconn, MSN_SERVCONN_ERROR_CONNECT); 283 msn_servconn_got_error(httpconn->servconn, MSN_SERVCONN_ERROR_CONNECT);
609 *ret_size = 0; 618 *ret_size = 0;
610 619
611 if (httpconn->tx_handler > 0) 620 if (httpconn->tx_handler > 0)
612 httpconn_write_cb(httpconn, httpconn->fd, 621 httpconn_write_cb(httpconn, httpconn->fd,
613 GAIM_INPUT_WRITE); 622 GAIM_INPUT_WRITE);
623 else
624 httpconn->dirty = TRUE;
614 625
615 return TRUE; 626 return TRUE;
616 } 627 }
617 628
618 buf = s; 629 buf = s;
762 *ret_buf = body; 773 *ret_buf = body;
763 *ret_size = body_len; 774 *ret_size = body_len;
764 775
765 if (httpconn->tx_handler > 0) 776 if (httpconn->tx_handler > 0)
766 httpconn_write_cb(httpconn, httpconn->fd, GAIM_INPUT_WRITE); 777 httpconn_write_cb(httpconn, httpconn->fd, GAIM_INPUT_WRITE);
778 else
779 httpconn->dirty = TRUE;
767 780
768 return TRUE; 781 return TRUE;
769 } 782 }