| 144 char *tosend= g_strdup(buf); |
144 char *tosend= g_strdup(buf); |
| 145 |
145 |
| 146 purple_signal_emit(_irc_plugin, "irc-sending-text", purple_account_get_connection(irc->account), &tosend); |
146 purple_signal_emit(_irc_plugin, "irc-sending-text", purple_account_get_connection(irc->account), &tosend); |
| 147 if (tosend == NULL) |
147 if (tosend == NULL) |
| 148 return 0; |
148 return 0; |
| 149 |
149 |
| 150 buflen = strlen(tosend); |
150 buflen = strlen(tosend); |
| 151 |
151 |
| 152 |
152 |
| 153 /* If we're not buffering writes, try to send immediately */ |
153 /* If we're not buffering writes, try to send immediately */ |
| 154 if (!irc->writeh) |
154 if (!irc->writeh) |
| 155 ret = do_send(irc, tosend, buflen); |
155 ret = do_send(irc, tosend, buflen); |
| 156 else { |
156 else { |
| 157 ret = -1; |
157 ret = -1; |
| 340 } |
340 } |
| 341 } |
341 } |
| 342 } |
342 } |
| 343 |
343 |
| 344 static gboolean do_login(PurpleConnection *gc) { |
344 static gboolean do_login(PurpleConnection *gc) { |
| 345 char *buf; |
345 char *buf, *tmp = NULL; |
| 346 char hostname[256]; |
346 char hostname[256]; |
| 347 const char *username, *realname; |
347 const char *username, *realname; |
| 348 struct irc_conn *irc = gc->proto_data; |
348 struct irc_conn *irc = gc->proto_data; |
| 349 const char *pass = purple_connection_get_password(gc); |
349 const char *pass = purple_connection_get_password(gc); |
| 350 |
350 |
| 356 return FALSE; |
356 return FALSE; |
| 357 } |
357 } |
| 358 g_free(buf); |
358 g_free(buf); |
| 359 } |
359 } |
| 360 |
360 |
| |
361 |
| 361 gethostname(hostname, sizeof(hostname)); |
362 gethostname(hostname, sizeof(hostname)); |
| 362 hostname[sizeof(hostname) - 1] = '\0'; |
363 hostname[sizeof(hostname) - 1] = '\0'; |
| |
364 realname = purple_account_get_string(irc->account, "realname", ""); |
| 363 username = purple_account_get_string(irc->account, "username", ""); |
365 username = purple_account_get_string(irc->account, "username", ""); |
| 364 realname = purple_account_get_string(irc->account, "realname", ""); |
366 |
| 365 buf = irc_format(irc, "vvvv:", "USER", strlen(username) ? username : g_get_user_name(), hostname, irc->server, |
367 if (username == NULL || *username == '\0') { |
| |
368 username = g_get_user_name(); |
| |
369 } |
| |
370 |
| |
371 if (username != NULL && strchr(username, ' ') != NULL) { |
| |
372 tmp = g_strdup(username); |
| |
373 while ((buf = strchr(tmp, ' ')) != NULL) { |
| |
374 *buf = '_'; |
| |
375 } |
| |
376 } |
| |
377 |
| |
378 buf = irc_format(irc, "vvvv:", "USER", tmp ? tmp : username, hostname, irc->server, |
| 366 strlen(realname) ? realname : IRC_DEFAULT_ALIAS); |
379 strlen(realname) ? realname : IRC_DEFAULT_ALIAS); |
| |
380 g_free(tmp); |
| 367 if (irc_send(irc, buf) < 0) { |
381 if (irc_send(irc, buf) < 0) { |
| 368 /* purple_connection_error(gc, "Error registering with server");*/ |
382 /* purple_connection_error(gc, "Error registering with server");*/ |
| 369 g_free(buf); |
383 g_free(buf); |
| 370 return FALSE; |
384 return FALSE; |
| 371 } |
385 } |
| 546 |
560 |
| 547 irc->inbufused += len; |
561 irc->inbufused += len; |
| 548 irc->inbuf[irc->inbufused] = '\0'; |
562 irc->inbuf[irc->inbufused] = '\0'; |
| 549 |
563 |
| 550 cur = irc->inbuf; |
564 cur = irc->inbuf; |
| 551 |
565 |
| 552 /* This is a hack to work around the fact that marv gets messages |
566 /* This is a hack to work around the fact that marv gets messages |
| 553 * with null bytes in them while using some weird irc server at work |
567 * with null bytes in them while using some weird irc server at work |
| 554 */ |
568 */ |
| 555 while ((cur < (irc->inbuf + irc->inbufused)) && !*cur) |
569 while ((cur < (irc->inbuf + irc->inbufused)) && !*cur) |
| 556 cur++; |
570 cur++; |
| 557 |
571 |
| 558 while (cur < irc->inbuf + irc->inbufused && |
572 while (cur < irc->inbuf + irc->inbufused && |
| 559 ((end = strstr(cur, "\r\n")) || (end = strstr(cur, "\n")))) { |
573 ((end = strstr(cur, "\r\n")) || (end = strstr(cur, "\n")))) { |
| 560 int step = (*end == '\r' ? 2 : 1); |
574 int step = (*end == '\r' ? 2 : 1); |
| 561 *end = '\0'; |
575 *end = '\0'; |
| 562 irc_parse_msg(irc, cur); |
576 irc_parse_msg(irc, cur); |
| 641 |
655 |
| 642 static char *irc_get_chat_name(GHashTable *data) { |
656 static char *irc_get_chat_name(GHashTable *data) { |
| 643 return g_strdup(g_hash_table_lookup(data, "channel")); |
657 return g_strdup(g_hash_table_lookup(data, "channel")); |
| 644 } |
658 } |
| 645 |
659 |
| 646 static void irc_chat_invite(PurpleConnection *gc, int id, const char *message, const char *name) |
660 static void irc_chat_invite(PurpleConnection *gc, int id, const char *message, const char *name) |
| 647 { |
661 { |
| 648 struct irc_conn *irc = gc->proto_data; |
662 struct irc_conn *irc = gc->proto_data; |
| 649 PurpleConversation *convo = purple_find_chat(gc, id); |
663 PurpleConversation *convo = purple_find_chat(gc, id); |
| 650 const char *args[2]; |
664 const char *args[2]; |
| 651 |
665 |