comparison libpurple/protocols/irc/irc.c @ 27735:98604b4bfa3b

propagate from branch 'im.pidgin.pidgin' (head cc8513f94aa94550d600cd8a5d42475dbf7249c0) to branch 'im.pidgin.pidgin.yaz' (head 3a859b75c16c1c1e2e79d4f4acb4424d13af5e0b)
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Thu, 22 Nov 2007 07:44:59 +0000
parents 26f55eb6ab59 38cc722159ff
children e13759a83714
comparison
equal deleted inserted replaced
27734:3f5b0039428b 27735:98604b4bfa3b
121 ret = do_send(irc, irc->outbuf->outptr, writelen); 121 ret = do_send(irc, irc->outbuf->outptr, writelen);
122 122
123 if (ret < 0 && errno == EAGAIN) 123 if (ret < 0 && errno == EAGAIN)
124 return; 124 return;
125 else if (ret <= 0) { 125 else if (ret <= 0) {
126 purple_connection_error(purple_account_get_connection(irc->account), 126 PurpleConnection *gc = purple_account_get_connection(irc->account);
127 _("Server has disconnected")); 127 purple_connection_error_reason (gc,
128 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
129 _("Server has disconnected"));
128 return; 130 return;
129 } 131 }
130 132
131 purple_circ_buffer_mark_read(irc->outbuf, ret); 133 purple_circ_buffer_mark_read(irc->outbuf, ret);
132 134
159 } 161 }
160 162
161 /* purple_debug(PURPLE_DEBUG_MISC, "irc", "sent%s: %s", 163 /* purple_debug(PURPLE_DEBUG_MISC, "irc", "sent%s: %s",
162 irc->gsc ? " (ssl)" : "", tosend); */ 164 irc->gsc ? " (ssl)" : "", tosend); */
163 if (ret <= 0 && errno != EAGAIN) { 165 if (ret <= 0 && errno != EAGAIN) {
164 purple_connection_error(purple_account_get_connection(irc->account), 166 PurpleConnection *gc = purple_account_get_connection(irc->account);
165 _("Server has disconnected")); 167 purple_connection_error_reason (gc,
168 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
169 _("Server has disconnected"));
166 } else if (ret < buflen) { 170 } else if (ret < buflen) {
167 if (ret < 0) 171 if (ret < 0)
168 ret = 0; 172 ret = 0;
169 if (!irc->writeh) 173 if (!irc->writeh)
170 irc->writeh = purple_input_add( 174 irc->writeh = purple_input_add(
293 297
294 gc = purple_account_get_connection(account); 298 gc = purple_account_get_connection(account);
295 gc->flags |= PURPLE_CONNECTION_NO_NEWLINES; 299 gc->flags |= PURPLE_CONNECTION_NO_NEWLINES;
296 300
297 if (strpbrk(username, " \t\v\r\n") != NULL) { 301 if (strpbrk(username, " \t\v\r\n") != NULL) {
298 purple_connection_error(gc, _("IRC nicks may not contain whitespace")); 302 purple_connection_error_reason (gc,
303 PURPLE_CONNECTION_ERROR_INVALID_SETTINGS,
304 _("IRC nicks may not contain whitespace"));
299 return; 305 return;
300 } 306 }
301 307
302 gc->proto_data = irc = g_new0(struct irc_conn, 1); 308 gc->proto_data = irc = g_new0(struct irc_conn, 1);
303 irc->fd = -1; 309 irc->fd = -1;
322 if (purple_ssl_is_supported()) { 328 if (purple_ssl_is_supported()) {
323 irc->gsc = purple_ssl_connect(account, irc->server, 329 irc->gsc = purple_ssl_connect(account, irc->server,
324 purple_account_get_int(account, "port", IRC_DEFAULT_SSL_PORT), 330 purple_account_get_int(account, "port", IRC_DEFAULT_SSL_PORT),
325 irc_login_cb_ssl, irc_ssl_connect_failure, gc); 331 irc_login_cb_ssl, irc_ssl_connect_failure, gc);
326 } else { 332 } else {
327 purple_connection_error(gc, _("SSL support unavailable")); 333 purple_connection_error_reason (gc,
334 PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT,
335 _("SSL support unavailable"));
328 return; 336 return;
329 } 337 }
330 } 338 }
331 339
332 if (!irc->gsc) { 340 if (!irc->gsc) {
333 341
334 if (purple_proxy_connect(gc, account, irc->server, 342 if (purple_proxy_connect(gc, account, irc->server,
335 purple_account_get_int(account, "port", IRC_DEFAULT_PORT), 343 purple_account_get_int(account, "port", IRC_DEFAULT_PORT),
336 irc_login_cb, gc) == NULL) 344 irc_login_cb, gc) == NULL)
337 { 345 {
338 purple_connection_error(gc, _("Couldn't create socket")); 346 purple_connection_error_reason (gc,
347 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
348 _("Couldn't create socket"));
339 return; 349 return;
340 } 350 }
341 } 351 }
342 } 352 }
343 353
350 int ret; 360 int ret;
351 361
352 if (pass && *pass) { 362 if (pass && *pass) {
353 buf = irc_format(irc, "vv", "PASS", pass); 363 buf = irc_format(irc, "vv", "PASS", pass);
354 if (irc_send(irc, buf) < 0) { 364 if (irc_send(irc, buf) < 0) {
355 /* purple_connection_error(gc, "Error sending password"); */
356 g_free(buf); 365 g_free(buf);
357 return FALSE; 366 return FALSE;
358 } 367 }
359 g_free(buf); 368 g_free(buf);
360 } 369 }
382 391
383 buf = irc_format(irc, "vvvv:", "USER", tmp ? tmp : username, hostname, irc->server, 392 buf = irc_format(irc, "vvvv:", "USER", tmp ? tmp : username, hostname, irc->server,
384 strlen(realname) ? realname : IRC_DEFAULT_ALIAS); 393 strlen(realname) ? realname : IRC_DEFAULT_ALIAS);
385 g_free(tmp); 394 g_free(tmp);
386 if (irc_send(irc, buf) < 0) { 395 if (irc_send(irc, buf) < 0) {
387 /* purple_connection_error(gc, "Error registering with server");*/
388 g_free(buf); 396 g_free(buf);
389 return FALSE; 397 return FALSE;
390 } 398 }
391 g_free(buf); 399 g_free(buf);
392 buf = irc_format(irc, "vn", "NICK", purple_connection_get_display_name(gc)); 400 buf = irc_format(irc, "vn", "NICK", purple_connection_get_display_name(gc));
393 if (irc_send(irc, buf) < 0) { 401 if (irc_send(irc, buf) < 0) {
394 /* purple_connection_error(gc, "Error sending nickname");*/
395 g_free(buf); 402 g_free(buf);
396 return FALSE; 403 return FALSE;
397 } 404 }
398 g_free(buf); 405 g_free(buf);
399 406
416 { 423 {
417 PurpleConnection *gc = data; 424 PurpleConnection *gc = data;
418 struct irc_conn *irc = gc->proto_data; 425 struct irc_conn *irc = gc->proto_data;
419 426
420 if (source < 0) { 427 if (source < 0) {
421 purple_connection_error(gc, _("Couldn't connect to host")); 428 purple_connection_error_reason (gc,
429 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
430 _("Couldn't connect to host"));
422 return; 431 return;
423 } 432 }
424 433
425 irc->fd = source; 434 irc->fd = source;
426 435
436 PurpleConnection *gc = data; 445 PurpleConnection *gc = data;
437 struct irc_conn *irc = gc->proto_data; 446 struct irc_conn *irc = gc->proto_data;
438 447
439 irc->gsc = NULL; 448 irc->gsc = NULL;
440 449
441 purple_connection_error(gc, purple_ssl_strerror(error)); 450 purple_connection_ssl_error (gc, error);
442 } 451 }
443 452
444 static void irc_close(PurpleConnection *gc) 453 static void irc_close(PurpleConnection *gc)
445 { 454 {
446 struct irc_conn *irc = gc->proto_data; 455 struct irc_conn *irc = gc->proto_data;
604 613
605 if (len < 0 && errno == EAGAIN) { 614 if (len < 0 && errno == EAGAIN) {
606 /* Try again later */ 615 /* Try again later */
607 return; 616 return;
608 } else if (len < 0) { 617 } else if (len < 0) {
609 purple_connection_error(gc, _("Read error")); 618 purple_connection_error_reason (gc,
619 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
620 _("Read error"));
610 return; 621 return;
611 } else if (len == 0) { 622 } else if (len == 0) {
612 purple_connection_error(gc, _("Server has disconnected")); 623 purple_connection_error_reason (gc,
624 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
625 _("Server has disconnected"));
613 return; 626 return;
614 } 627 }
615 628
616 read_input(irc, len); 629 read_input(irc, len);
617 } 630 }
629 642
630 len = read(irc->fd, irc->inbuf + irc->inbufused, IRC_INITIAL_BUFSIZE - 1); 643 len = read(irc->fd, irc->inbuf + irc->inbufused, IRC_INITIAL_BUFSIZE - 1);
631 if (len < 0 && errno == EAGAIN) { 644 if (len < 0 && errno == EAGAIN) {
632 return; 645 return;
633 } else if (len < 0) { 646 } else if (len < 0) {
634 purple_connection_error(gc, _("Read error")); 647 purple_connection_error_reason (gc,
648 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
649 _("Read error"));
635 return; 650 return;
636 } else if (len == 0) { 651 } else if (len == 0) {
637 purple_connection_error(gc, _("Server has disconnected")); 652 purple_connection_error_reason (gc,
653 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
654 _("Server has disconnected"));
638 return; 655 return;
639 } 656 }
640 657
641 read_input(irc, len); 658 read_input(irc, len);
642 } 659 }
908 NULL, /**< dependencies */ 925 NULL, /**< dependencies */
909 PURPLE_PRIORITY_DEFAULT, /**< priority */ 926 PURPLE_PRIORITY_DEFAULT, /**< priority */
910 927
911 "prpl-irc", /**< id */ 928 "prpl-irc", /**< id */
912 "IRC", /**< name */ 929 "IRC", /**< name */
913 VERSION, /**< version */ 930 DISPLAY_VERSION, /**< version */
914 N_("IRC Protocol Plugin"), /** summary */ 931 N_("IRC Protocol Plugin"), /** summary */
915 N_("The IRC Protocol Plugin that Sucks Less"), /** description */ 932 N_("The IRC Protocol Plugin that Sucks Less"), /** description */
916 NULL, /**< author */ 933 NULL, /**< author */
917 PURPLE_WEBSITE, /**< homepage */ 934 PURPLE_WEBSITE, /**< homepage */
918 935