# HG changeset patch # User Eric Warmenhoven # Date 1003986305 0 # Node ID 24664768a739a0c35c40acff5ee36589e245f37e # Parent c9192dea2bb1a7015f51627b63e8a9991ec81463 [gaim-migrate @ 2616] i shouldn't have modified gaim.h like i did. *slaps own wrists* Do as I say, not as I do. committer: Tailor Script diff -r c9192dea2bb1 -r 24664768a739 src/gaim.h --- a/src/gaim.h Thu Oct 25 02:30:12 2001 +0000 +++ b/src/gaim.h Thu Oct 25 05:05:05 2001 +0000 @@ -401,5 +401,7 @@ extern void system_log(enum log_event, struct gaim_connection *, struct buddy *, int); extern unsigned char *utf8_to_str(unsigned char *); extern char *str_to_utf8(unsigned char *); +extern char *add_cr(char *); +extern void strip_linefeed(char *); #endif /* _GAIM_H_ */ diff -r c9192dea2bb1 -r 24664768a739 src/protocols/icq/gaim_icq.c --- a/src/protocols/icq/gaim_icq.c Thu Oct 25 02:30:12 2001 +0000 +++ b/src/protocols/icq/gaim_icq.c Thu Oct 25 05:05:05 2001 +0000 @@ -107,20 +107,6 @@ icq_Login(link, id->cur_status); } -void strip_linefeed(gchar *text) -{ - int i, j; - gchar *text2 = g_malloc(strlen(text) + 1); - - for (i = 0, j = 0; text[i]; i++) - if (text[i] != '\r') - text2[j++] = text[i]; - text2[j] = '\0'; - - strcpy(text, text2); - g_free(text2); -} - static void icq_msg_incoming(icq_Link *link, unsigned long uin, unsigned char hour, unsigned char minute, unsigned char day, unsigned char month, unsigned short year, const char *data) { struct gaim_connection *gc = link->icq_UserData; diff -r c9192dea2bb1 -r 24664768a739 src/protocols/msn/msn.c --- a/src/protocols/msn/msn.c Thu Oct 25 02:30:12 2001 +0000 +++ b/src/protocols/msn/msn.c Thu Oct 25 05:05:05 2001 +0000 @@ -426,7 +426,9 @@ add_chat_buddy(ms->chat, user); ms->total++; while (ms->txqueue) { - char *utf8 = str_to_utf8(ms->txqueue->data); + char *send = add_cr(ms->txqueue->data); + char *utf8 = str_to_utf8(send); + g_free(send); g_snprintf(buf, sizeof(buf), "MSG %d N %d\r\n%s%s", ++ms->trId, strlen(MIME_HEADER) + strlen(utf8), MIME_HEADER, utf8); @@ -441,9 +443,8 @@ } } else if (!g_strncasecmp(buf, "MSG", 3)) { char *user, *tmp = buf; - int length; + int length, len, r; char *msg, *content, *agent, *utf; - int len, r; int flags = 0; GET_NEXT(tmp); @@ -454,7 +455,7 @@ GET_NEXT(tmp); length = atoi(tmp); - msg = g_new0(char, MAX(length + 1, MSN_BUF_LEN)); + msg = g_malloc0(length + 1); for (len = 0; len < length; len += r) { if ((r = read(ms->fd, msg+len, length-len)) <= 0) { @@ -477,7 +478,7 @@ } if (!g_strncasecmp(content, "Content-Type: text/plain", strlen("Content-Type: text/plain"))) { - char *final, *skiphead; + char *skiphead; skiphead = strstr(msg, "\r\n\r\n"); if (!skiphead || !skiphead[4]) { g_free(msg); @@ -485,17 +486,14 @@ } skiphead += 4; utf = utf8_to_str(skiphead); - len = MAX(strlen(utf) + 1, BUF_LEN); - final = g_malloc(len); - g_snprintf(final, len, "%s", utf); - g_free(utf); + strip_linefeed(utf); if (ms->chat) - serv_got_chat_in(gc, ms->chat->id, user, flags, final, time(NULL)); + serv_got_chat_in(gc, ms->chat->id, user, flags, utf, time(NULL)); else - serv_got_im(gc, user, final, flags, time(NULL)); + serv_got_im(gc, user, utf, flags, time(NULL)); - g_free(final); + g_free(utf); } g_free(msg); } else if (!g_strncasecmp(buf, "NAK", 3)) { @@ -512,7 +510,7 @@ if (!ms) return; - g_snprintf(buf, sizeof(buf), "CAL %d %s\n", ++ms->trId, ms->user); + g_snprintf(buf, sizeof(buf), "CAL %d %s\r\n", ++ms->trId, ms->user); if (msn_write(ms->fd, buf, strlen(buf)) < 0) msn_kill_switch(ms); } else if (isdigit(*buf)) { @@ -542,7 +540,7 @@ if (ms->fd != source) ms->fd = source; - g_snprintf(buf, sizeof(buf), "ANS %d %s %s %s\n", ++ms->trId, gc->username, ms->auth, ms->sessid); + g_snprintf(buf, sizeof(buf), "ANS %d %s %s %s\r\n", ++ms->trId, gc->username, ms->auth, ms->sessid); if (msn_write(ms->fd, buf, strlen(buf)) < 0) { close(ms->fd); g_free(ms->sessid); @@ -573,7 +571,7 @@ if (ms->fd != source) ms->fd = source; - g_snprintf(buf, sizeof(buf), "USR %d %s %s\n", ++ms->trId, gc->username, ms->auth); + g_snprintf(buf, sizeof(buf), "USR %d %s %s\r\n", ++ms->trId, gc->username, ms->auth); if (msn_write(ms->fd, buf, strlen(buf)) < 0) { g_free(ms->auth); g_free(ms); @@ -594,7 +592,7 @@ struct msn_data *md = map->gc->proto_data; char buf[MSN_BUF_LEN]; - g_snprintf(buf, sizeof(buf), "ADD %d AL %s %s\n", ++md->trId, map->user, map->friend); + g_snprintf(buf, sizeof(buf), "ADD %d AL %s %s\r\n", ++md->trId, map->user, map->friend); if (msn_write(md->fd, buf, strlen(buf)) < 0) { hide_login_progress(map->gc, "Write error"); signoff(map->gc); @@ -786,7 +784,7 @@ if (pos != tot) return; - g_snprintf(buf, sizeof(buf), "CHG %d NLN\n", ++md->trId); + g_snprintf(buf, sizeof(buf), "CHG %d NLN\r\n", ++md->trId); if (msn_write(md->fd, buf, strlen(buf)) < 0) { hide_login_progress(gc, "Unable to write"); signoff(gc); @@ -802,7 +800,7 @@ if (bud_list_cache_exists(gc)) do_import(gc, NULL); else { - g_snprintf(buf, sizeof(buf), "BLP %d AL\n", ++md->trId); + g_snprintf(buf, sizeof(buf), "BLP %d AL\r\n", ++md->trId); if (msn_write(md->fd, buf, strlen(buf)) < 0) { hide_login_progress(gc, "Unable to write"); signoff(gc); @@ -827,7 +825,7 @@ } else if (!g_strncasecmp(buf, "MSG", 3)) { char *user, *tmp = buf; int length; - char *msg, *skiphead, *utf, *final; + char *msg, *skiphead, *utf; int len, r; GET_NEXT(tmp); @@ -862,14 +860,11 @@ } skiphead += 4; utf = utf8_to_str(skiphead); - len = MAX(strlen(utf) + 1, BUF_LEN); - final = g_malloc(len); - g_snprintf(final, len, "%s", utf); + strip_linefeed(utf); + + serv_got_im(gc, user, utf, 0, time(NULL)); + g_free(utf); - - serv_got_im(gc, user, final, 0, time(NULL)); - - g_free(final); g_free(msg); } else if (!g_strncasecmp(buf, "NLN", 3)) { char *state, *user, *tmp = buf; @@ -1025,7 +1020,7 @@ return; } - g_snprintf(buf, sizeof(buf), "VER %d MSNP5\n", ++md->trId); + g_snprintf(buf, sizeof(buf), "VER %d MSNP5\r\n", ++md->trId); if (msn_write(md->fd, buf, strlen(buf)) < 0) { hide_login_progress(gc, "Unable to talk to Notification Server"); signoff(gc); @@ -1063,7 +1058,7 @@ return; } - g_snprintf(buf, sizeof(buf), "INF %d\n", ++md->trId); + g_snprintf(buf, sizeof(buf), "INF %d\r\n", ++md->trId); if (msn_write(md->fd, buf, strlen(buf)) < 0) { hide_login_progress(gc, "Unable to request INF\n"); signoff(gc); @@ -1077,7 +1072,7 @@ return; } - g_snprintf(buf, sizeof(buf), "USR %d MD5 I %s\n", ++md->trId, gc->username); + g_snprintf(buf, sizeof(buf), "USR %d MD5 I %s\r\n", ++md->trId, gc->username); if (msn_write(md->fd, buf, strlen(buf)) < 0) { hide_login_progress(gc, "Unable to send USR\n"); signoff(gc); @@ -1101,7 +1096,7 @@ if (!g_strcasecmp(resp, "OK")) { g_snprintf(gc->displayname, sizeof(gc->displayname), "%s", friend); - g_snprintf(buf, sizeof(buf), "SYN %d 0\n", ++md->trId); + g_snprintf(buf, sizeof(buf), "SYN %d 0\r\n", ++md->trId); if (msn_write(md->fd, buf, strlen(buf)) < 0) { hide_login_progress(gc, "Unable to write"); signoff(gc); @@ -1194,7 +1189,7 @@ return; } - g_snprintf(buf, sizeof(buf), "VER %d MSNP5\n", ++md->trId); + g_snprintf(buf, sizeof(buf), "VER %d MSNP5\r\n", ++md->trId); if (msn_write(md->fd, buf, strlen(buf)) < 0) { hide_login_progress(gc, "Unable to write to server"); signoff(gc); @@ -1244,7 +1239,7 @@ char buf[MSN_BUF_LEN]; if (ms) { - char *utf8; + char *utf8, *send; if (ms->txqueue) { debug_printf("appending to queue\n"); @@ -1252,7 +1247,9 @@ return 1; } - utf8 = str_to_utf8(message); + send = add_cr(message); + utf8 = str_to_utf8(send); + g_free(send); g_snprintf(buf, sizeof(buf), "MSG %d N %d\r\n%s%s", ++ms->trId, strlen(MIME_HEADER) + strlen(utf8), MIME_HEADER, utf8); @@ -1261,7 +1258,7 @@ msn_kill_switch(ms); debug_printf("\n"); } else if (strcmp(who, gc->username)) { - g_snprintf(buf, MSN_BUF_LEN, "XFR %d SB\n", ++md->trId); + g_snprintf(buf, MSN_BUF_LEN, "XFR %d SB\r\n", ++md->trId); if (msn_write(md->fd, buf, strlen(buf)) < 0) { hide_login_progress(gc, "Write error"); signoff(gc); @@ -1284,13 +1281,18 @@ { struct msn_switchboard *ms = msn_find_switch_by_id(gc, id); char buf[MSN_BUF_LEN]; + char *utf8, *send; if (!ms) return -EINVAL; + send = add_cr(message); + utf8 = str_to_utf8(send); + g_free(send); g_snprintf(buf, sizeof(buf), "MSG %d N %d\r\n%s%s", ++ms->trId, strlen(MIME_HEADER) + strlen(message), - MIME_HEADER, message); + MIME_HEADER, utf8); + g_free(utf8); if (msn_write(ms->fd, buf, strlen(buf)) < 0) { msn_kill_switch(ms); return 0; @@ -1308,7 +1310,7 @@ if (!ms) return; - g_snprintf(buf, sizeof(buf), "CAL %d %s\n", ++ms->trId, who); + g_snprintf(buf, sizeof(buf), "CAL %d %s\r\n", ++ms->trId, who); if (msn_write(ms->fd, buf, strlen(buf)) < 0) msn_kill_switch(ms); } @@ -1321,7 +1323,7 @@ if (!ms) return; - g_snprintf(buf, sizeof(buf), "OUT\n"); + g_snprintf(buf, sizeof(buf), "OUT\r\n"); if (msn_write(ms->fd, buf, strlen(buf)) < 0) msn_kill_switch(ms); } @@ -1376,7 +1378,7 @@ else away = "NLN"; - g_snprintf(buf, sizeof(buf), "CHG %d %s\n", ++md->trId, away); + g_snprintf(buf, sizeof(buf), "CHG %d %s\r\n", ++md->trId, away); if (msn_write(md->fd, buf, strlen(buf)) < 0) { hide_login_progress(gc, "Write error"); signoff(gc); @@ -1392,9 +1394,9 @@ if (gc->away) return; if (idle) - g_snprintf(buf, sizeof(buf), "CHG %d IDL\n", ++md->trId); + g_snprintf(buf, sizeof(buf), "CHG %d IDL\r\n", ++md->trId); else - g_snprintf(buf, sizeof(buf), "CHG %d NLN\n", ++md->trId); + g_snprintf(buf, sizeof(buf), "CHG %d NLN\r\n", ++md->trId); if (msn_write(md->fd, buf, strlen(buf)) < 0) { hide_login_progress(gc, "Write error"); signoff(gc); @@ -1470,7 +1472,7 @@ if (l) return; - g_snprintf(buf, sizeof(buf), "ADD %d FL %s %s\n", ++md->trId, who, who); + g_snprintf(buf, sizeof(buf), "ADD %d FL %s %s\r\n", ++md->trId, who, who); if (msn_write(md->fd, buf, strlen(buf)) < 0) { hide_login_progress(gc, "Write error"); signoff(gc); @@ -1483,7 +1485,7 @@ struct msn_data *md = gc->proto_data; char buf[MSN_BUF_LEN]; - g_snprintf(buf, sizeof(buf), "REM %d FL %s\n", ++md->trId, who); + g_snprintf(buf, sizeof(buf), "REM %d FL %s\r\n", ++md->trId, who); if (msn_write(md->fd, buf, strlen(buf)) < 0) { hide_login_progress(gc, "Write error"); signoff(gc); @@ -1497,7 +1499,7 @@ struct msn_data *md = gc->proto_data; char buf[MSN_BUF_LEN]; - g_snprintf(buf, sizeof(buf), "REA %d %s %s\n", ++md->trId, gc->username, url_encode(entry)); + g_snprintf(buf, sizeof(buf), "REA %d %s %s\r\n", ++md->trId, gc->username, url_encode(entry)); if (msn_write(md->fd, buf, strlen(buf)) < 0) { hide_login_progress(gc, "Write error"); signoff(gc); @@ -1534,7 +1536,7 @@ struct msn_data *md = gc->proto_data; char buf[MSN_BUF_LEN]; - g_snprintf(buf, sizeof(buf), "PNG\n"); + g_snprintf(buf, sizeof(buf), "PNG\r\n"); if (msn_write(md->fd, buf, strlen(buf)) < 0) { hide_login_progress(gc, "Write error"); signoff(gc); @@ -1549,9 +1551,9 @@ GSList *s; if (gc->permdeny == PERMIT_ALL || gc->permdeny == DENY_SOME) - g_snprintf(buf, sizeof(buf), "BLP %d AL\n", ++md->trId); + g_snprintf(buf, sizeof(buf), "BLP %d AL\r\n", ++md->trId); else - g_snprintf(buf, sizeof(buf), "BLP %d BL\n", ++md->trId); + g_snprintf(buf, sizeof(buf), "BLP %d BL\r\n", ++md->trId); if (msn_write(md->fd, buf, strlen(buf)) < 0) { hide_login_progress(gc, "Write error"); @@ -1576,7 +1578,7 @@ s = g_slist_nth(gc->permit, g_slist_length(md->permit)); while (s) { char *who = s->data; - g_snprintf(buf, sizeof(buf), "ADD %d AL %s %s\n", ++md->trId, who, who); + g_snprintf(buf, sizeof(buf), "ADD %d AL %s %s\r\n", ++md->trId, who, who); if (msn_write(md->fd, buf, strlen(buf)) < 0) { hide_login_progress(gc, "Write error"); signoff(gc); @@ -1590,7 +1592,7 @@ s = g_slist_nth(gc->deny, g_slist_length(md->deny)); while (s) { char *who = s->data; - g_snprintf(buf, sizeof(buf), "ADD %d AL %s %s\n", ++md->trId, who, who); + g_snprintf(buf, sizeof(buf), "ADD %d AL %s %s\r\n", ++md->trId, who, who); if (msn_write(md->fd, buf, strlen(buf)) < 0) { hide_login_progress(gc, "Write error"); signoff(gc); @@ -1607,7 +1609,7 @@ struct msn_data *md = gc->proto_data; char buf[MSN_BUF_LEN]; - g_snprintf(buf, sizeof(buf), "ADD %d AL %s %s\n", ++md->trId, who, who); + g_snprintf(buf, sizeof(buf), "ADD %d AL %s %s\r\n", ++md->trId, who, who); if (msn_write(md->fd, buf, strlen(buf)) < 0) { hide_login_progress(gc, "Write error"); signoff(gc); @@ -1620,7 +1622,7 @@ struct msn_data *md = gc->proto_data; char buf[MSN_BUF_LEN]; - g_snprintf(buf, sizeof(buf), "REM %d AL %s\n", ++md->trId, who); + g_snprintf(buf, sizeof(buf), "REM %d AL %s\r\n", ++md->trId, who); if (msn_write(md->fd, buf, strlen(buf)) < 0) { hide_login_progress(gc, "Write error"); signoff(gc); @@ -1633,7 +1635,7 @@ struct msn_data *md = gc->proto_data; char buf[MSN_BUF_LEN]; - g_snprintf(buf, sizeof(buf), "ADD %d BL %s %s\n", ++md->trId, who, who); + g_snprintf(buf, sizeof(buf), "ADD %d BL %s %s\r\n", ++md->trId, who, who); if (msn_write(md->fd, buf, strlen(buf)) < 0) { hide_login_progress(gc, "Write error"); signoff(gc); @@ -1646,7 +1648,7 @@ struct msn_data *md = gc->proto_data; char buf[MSN_BUF_LEN]; - g_snprintf(buf, sizeof(buf), "REM %d BL %s\n", ++md->trId, who); + g_snprintf(buf, sizeof(buf), "REM %d BL %s\r\n", ++md->trId, who); if (msn_write(md->fd, buf, strlen(buf)) < 0) { hide_login_progress(gc, "Write error"); signoff(gc); diff -r c9192dea2bb1 -r 24664768a739 src/protocols/oscar/oscar.c --- a/src/protocols/oscar/oscar.c Thu Oct 25 02:30:12 2001 +0000 +++ b/src/protocols/oscar/oscar.c Thu Oct 25 05:05:05 2001 +0000 @@ -1338,8 +1338,9 @@ char *buf = g_malloc(st.st_size); file = fopen(gc->user->iconfile, "r"); if (file) { - fread(buf, 1, st.st_size, file); - debug_printf("Sending buddy icon to %s\n", userinfo->sn); + int len = fread(buf, 1, st.st_size, file); + debug_printf("Sending buddy icon to %s (%d bytes, %d reported)\n", + userinfo->sn, len, st.st_size); aim_send_icon(sess, conn, userinfo->sn, buf, st.st_size, st.st_mtime, aim_iconsum(buf, st.st_size)); fclose(file); diff -r c9192dea2bb1 -r 24664768a739 src/util.c --- a/src/util.c Thu Oct 25 02:30:12 2001 +0000 +++ b/src/util.c Thu Oct 25 05:05:05 2001 +0000 @@ -1166,10 +1166,12 @@ n += 2; continue; } + /* why are we removing newlines and carriage returns? if ((c == 0x0D) || (c == 0x0A)) { n++; continue; } + */ if (c < 128) result[i++] = (char)c; else { @@ -1183,6 +1185,51 @@ return result; } +void strip_linefeed(gchar *text) +{ + int i, j; + gchar *text2 = g_malloc(strlen(text) + 1); + + for (i = 0, j = 0; text[i]; i++) + if (text[i] != '\r') + text2[j++] = text[i]; + text2[j] = '\0'; + + strcpy(text, text2); + g_free(text2); +} + +char *add_cr(char *text) +{ + char *ret = NULL; + int count = 0, i, j; + + if (text[0] == '\n') + count++; + for (i = 1; i < strlen(text); i++) + if (text[i] == '\n' && text[i - 1] != '\r') + count++; + + if (count == 0) + return g_strdup(text); + + ret = g_malloc0(strlen(text) + count + 1); + + i = 0; j = 0; + if (text[i] == '\n') + ret[j++] = '\r'; + ret[j++] = text[i++]; + for (; i < strlen(text); i++) { + if (text[i] == '\n' && text[i - 1] != '\r') + ret[j++] = '\r'; + ret[j++] = text[i]; + } + + debug_printf("got: %s, leaving with %s\n", text, ret); + + return ret; +} + time_t get_time(int year, int month, int day, int hour, int min, int sec) { struct tm tm;