comparison libpurple/protocols/msn/servconn.c @ 15822:32c366eeeb99

sed -ie 's/gaim/purple/g'
author Sean Egan <seanegan@gmail.com>
date Mon, 19 Mar 2007 07:01:17 +0000
parents 5fe8042783c1
children 7a493fc1e763 60bc06498746 4a099e4d0d09
comparison
equal deleted inserted replaced
15821:84b0f9b23ede 15822:32c366eeeb99
1 /** 1 /**
2 * @file servconn.c Server connection functions 2 * @file servconn.c Server connection functions
3 * 3 *
4 * gaim 4 * purple
5 * 5 *
6 * Gaim is the legal property of its developers, whose names are too numerous 6 * Purple is the legal property of its developers, whose names are too numerous
7 * to list here. Please refer to the COPYRIGHT file distributed with this 7 * to list here. Please refer to the COPYRIGHT file distributed with this
8 * source distribution. 8 * source distribution.
9 * 9 *
10 * This program is free software; you can redistribute it and/or modify 10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by 11 * it under the terms of the GNU General Public License as published by
23 */ 23 */
24 #include "msn.h" 24 #include "msn.h"
25 #include "servconn.h" 25 #include "servconn.h"
26 #include "error.h" 26 #include "error.h"
27 27
28 static void read_cb(gpointer data, gint source, GaimInputCondition cond); 28 static void read_cb(gpointer data, gint source, PurpleInputCondition cond);
29 29
30 /************************************************************************** 30 /**************************************************************************
31 * Main 31 * Main
32 **************************************************************************/ 32 **************************************************************************/
33 33
48 48
49 servconn->httpconn = msn_httpconn_new(servconn); 49 servconn->httpconn = msn_httpconn_new(servconn);
50 50
51 servconn->num = session->servconns_count++; 51 servconn->num = session->servconns_count++;
52 52
53 servconn->tx_buf = gaim_circ_buffer_new(MSN_BUF_LEN); 53 servconn->tx_buf = purple_circ_buffer_new(MSN_BUF_LEN);
54 servconn->tx_handler = -1; 54 servconn->tx_handler = -1;
55 55
56 return servconn; 56 return servconn;
57 } 57 }
58 58
76 if (servconn->httpconn != NULL) 76 if (servconn->httpconn != NULL)
77 msn_httpconn_destroy(servconn->httpconn); 77 msn_httpconn_destroy(servconn->httpconn);
78 78
79 g_free(servconn->host); 79 g_free(servconn->host);
80 80
81 gaim_circ_buffer_destroy(servconn->tx_buf); 81 purple_circ_buffer_destroy(servconn->tx_buf);
82 if (servconn->tx_handler > 0) 82 if (servconn->tx_handler > 0)
83 gaim_input_remove(servconn->tx_handler); 83 purple_input_remove(servconn->tx_handler);
84 84
85 msn_cmdproc_destroy(servconn->cmdproc); 85 msn_cmdproc_destroy(servconn->cmdproc);
86 g_free(servconn); 86 g_free(servconn);
87 } 87 }
88 88
137 reason = _("Reading error"); break; 137 reason = _("Reading error"); break;
138 default: 138 default:
139 reason = _("Unknown error"); break; 139 reason = _("Unknown error"); break;
140 } 140 }
141 141
142 gaim_debug_error("msn", "Connection error from %s server (%s): %s\n", 142 purple_debug_error("msn", "Connection error from %s server (%s): %s\n",
143 name, servconn->host, reason); 143 name, servconn->host, reason);
144 tmp = g_strdup_printf(_("Connection error from %s server:\n%s"), 144 tmp = g_strdup_printf(_("Connection error from %s server:\n%s"),
145 name, reason); 145 name, reason);
146 146
147 if (servconn->type == MSN_SERVCONN_NS) 147 if (servconn->type == MSN_SERVCONN_NS)
188 { 188 {
189 servconn->connected = TRUE; 189 servconn->connected = TRUE;
190 190
191 /* Someone wants to know we connected. */ 191 /* Someone wants to know we connected. */
192 servconn->connect_cb(servconn); 192 servconn->connect_cb(servconn);
193 servconn->inpa = gaim_input_add(servconn->fd, GAIM_INPUT_READ, 193 servconn->inpa = purple_input_add(servconn->fd, PURPLE_INPUT_READ,
194 read_cb, data); 194 read_cb, data);
195 } 195 }
196 else 196 else
197 { 197 {
198 msn_servconn_got_error(servconn, MSN_SERVCONN_ERROR_CONNECT); 198 msn_servconn_got_error(servconn, MSN_SERVCONN_ERROR_CONNECT);
231 servconn->connect_cb(servconn); 231 servconn->connect_cb(servconn);
232 232
233 return TRUE; 233 return TRUE;
234 } 234 }
235 235
236 servconn->connect_data = gaim_proxy_connect(NULL, session->account, 236 servconn->connect_data = purple_proxy_connect(NULL, session->account,
237 host, port, connect_cb, servconn); 237 host, port, connect_cb, servconn);
238 238
239 if (servconn->connect_data != NULL) 239 if (servconn->connect_data != NULL)
240 { 240 {
241 servconn->processing = TRUE; 241 servconn->processing = TRUE;
268 return; 268 return;
269 } 269 }
270 270
271 if (servconn->connect_data != NULL) 271 if (servconn->connect_data != NULL)
272 { 272 {
273 gaim_proxy_connect_cancel(servconn->connect_data); 273 purple_proxy_connect_cancel(servconn->connect_data);
274 servconn->connect_data = NULL; 274 servconn->connect_data = NULL;
275 } 275 }
276 276
277 if (servconn->inpa > 0) 277 if (servconn->inpa > 0)
278 { 278 {
279 gaim_input_remove(servconn->inpa); 279 purple_input_remove(servconn->inpa);
280 servconn->inpa = 0; 280 servconn->inpa = 0;
281 } 281 }
282 282
283 close(servconn->fd); 283 close(servconn->fd);
284 284
291 if (servconn->disconnect_cb != NULL) 291 if (servconn->disconnect_cb != NULL)
292 servconn->disconnect_cb(servconn); 292 servconn->disconnect_cb(servconn);
293 } 293 }
294 294
295 static void 295 static void
296 servconn_write_cb(gpointer data, gint source, GaimInputCondition cond) 296 servconn_write_cb(gpointer data, gint source, PurpleInputCondition cond)
297 { 297 {
298 MsnServConn *servconn = data; 298 MsnServConn *servconn = data;
299 int ret, writelen; 299 int ret, writelen;
300 300
301 writelen = gaim_circ_buffer_get_max_read(servconn->tx_buf); 301 writelen = purple_circ_buffer_get_max_read(servconn->tx_buf);
302 302
303 if (writelen == 0) { 303 if (writelen == 0) {
304 gaim_input_remove(servconn->tx_handler); 304 purple_input_remove(servconn->tx_handler);
305 servconn->tx_handler = -1; 305 servconn->tx_handler = -1;
306 return; 306 return;
307 } 307 }
308 308
309 ret = write(servconn->fd, servconn->tx_buf->outptr, writelen); 309 ret = write(servconn->fd, servconn->tx_buf->outptr, writelen);
313 else if (ret <= 0) { 313 else if (ret <= 0) {
314 msn_servconn_got_error(servconn, MSN_SERVCONN_ERROR_WRITE); 314 msn_servconn_got_error(servconn, MSN_SERVCONN_ERROR_WRITE);
315 return; 315 return;
316 } 316 }
317 317
318 gaim_circ_buffer_mark_read(servconn->tx_buf, ret); 318 purple_circ_buffer_mark_read(servconn->tx_buf, ret);
319 } 319 }
320 320
321 ssize_t 321 ssize_t
322 msn_servconn_write(MsnServConn *servconn, const char *buf, size_t len) 322 msn_servconn_write(MsnServConn *servconn, const char *buf, size_t len)
323 { 323 {
351 351
352 if (ret < 0 && errno == EAGAIN) 352 if (ret < 0 && errno == EAGAIN)
353 ret = 0; 353 ret = 0;
354 if (ret < len) { 354 if (ret < len) {
355 if (servconn->tx_handler == -1) 355 if (servconn->tx_handler == -1)
356 servconn->tx_handler = gaim_input_add( 356 servconn->tx_handler = purple_input_add(
357 servconn->fd, GAIM_INPUT_WRITE, 357 servconn->fd, PURPLE_INPUT_WRITE,
358 servconn_write_cb, servconn); 358 servconn_write_cb, servconn);
359 gaim_circ_buffer_append(servconn->tx_buf, buf + ret, 359 purple_circ_buffer_append(servconn->tx_buf, buf + ret,
360 len - ret); 360 len - ret);
361 } 361 }
362 } 362 }
363 else 363 else
364 { 364 {
372 372
373 return ret; 373 return ret;
374 } 374 }
375 375
376 static void 376 static void
377 read_cb(gpointer data, gint source, GaimInputCondition cond) 377 read_cb(gpointer data, gint source, PurpleInputCondition cond)
378 { 378 {
379 MsnServConn *servconn; 379 MsnServConn *servconn;
380 MsnSession *session; 380 MsnSession *session;
381 char buf[MSN_BUF_LEN]; 381 char buf[MSN_BUF_LEN];
382 char *cur, *end, *old_rx_buf; 382 char *cur, *end, *old_rx_buf;
389 389
390 if (len < 0 && errno == EAGAIN) 390 if (len < 0 && errno == EAGAIN)
391 return; 391 return;
392 else if (len <= 0) 392 else if (len <= 0)
393 { 393 {
394 gaim_debug_error("msn", "servconn read error, len: %d error: %s\n", len, strerror(errno)); 394 purple_debug_error("msn", "servconn read error, len: %d error: %s\n", len, strerror(errno));
395 msn_servconn_got_error(servconn, MSN_SERVCONN_ERROR_READ); 395 msn_servconn_got_error(servconn, MSN_SERVCONN_ERROR_READ);
396 396
397 return; 397 return;
398 } 398 }
399 399
482 hints.ai_family = AF_UNSPEC; 482 hints.ai_family = AF_UNSPEC;
483 hints.ai_socktype = SOCK_STREAM; 483 hints.ai_socktype = SOCK_STREAM;
484 484
485 if (getaddrinfo(NULL, port_str, &hints, &res) != 0) 485 if (getaddrinfo(NULL, port_str, &hints, &res) != 0)
486 { 486 {
487 gaim_debug_error("msn", "Could not get address info: %s.\n", 487 purple_debug_error("msn", "Could not get address info: %s.\n",
488 port_str); 488 port_str);
489 return -1; 489 return -1;
490 } 490 }
491 491
492 for (c = res; c != NULL; c = c->ai_next) 492 for (c = res; c != NULL; c = c->ai_next)
504 close(fd); 504 close(fd);
505 } 505 }
506 506
507 if (c == NULL) 507 if (c == NULL)
508 { 508 {
509 gaim_debug_error("msn", "Could not find socket: %s.\n", port_str); 509 purple_debug_error("msn", "Could not find socket: %s.\n", port_str);
510 return -1; 510 return -1;
511 } 511 }
512 512
513 freeaddrinfo(res); 513 freeaddrinfo(res);
514 #else 514 #else