Mercurial > pidgin
comparison src/protocols/oscar/oscar.c @ 9826:6f2a90c36ee2
[gaim-migrate @ 10697]
Kevin pointed out that the error message for AIM when you couldn't send
a message to someone could be better. So I made it better.
Also renamed AIM_IMCHARSET_bleh to AIM_CHARSET_bleh, since they're used
in direct connect stuff, too.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Sun, 22 Aug 2004 17:59:17 +0000 |
parents | f64e382d5334 |
children | 2e3c63811475 |
comparison
equal
deleted
inserted
replaced
9825:c00def44d76a | 9826:6f2a90c36ee2 |
---|---|
308 } | 308 } |
309 | 309 |
310 static fu32_t oscar_charset_check(const char *utf8) | 310 static fu32_t oscar_charset_check(const char *utf8) |
311 { | 311 { |
312 int i = 0; | 312 int i = 0; |
313 int charset = AIM_IMCHARSET_ASCII; | 313 int charset = AIM_CHARSET_ASCII; |
314 | 314 |
315 /* Determine how we can send this message. Per the warnings elsewhere | 315 /* Determine how we can send this message. Per the warnings elsewhere |
316 * in this file, these little checks determine the simplest encoding | 316 * in this file, these little checks determine the simplest encoding |
317 * we can use for a given message send using it. */ | 317 * we can use for a given message send using it. */ |
318 while (utf8[i]) { | 318 while (utf8[i]) { |
319 if ((unsigned char)utf8[i] > 0x7f) { | 319 if ((unsigned char)utf8[i] > 0x7f) { |
320 /* not ASCII! */ | 320 /* not ASCII! */ |
321 charset = AIM_IMCHARSET_CUSTOM; | 321 charset = AIM_CHARSET_CUSTOM; |
322 break; | 322 break; |
323 } | 323 } |
324 i++; | 324 i++; |
325 } | 325 } |
326 while (utf8[i]) { | 326 while (utf8[i]) { |
332 } else if (((unsigned char)utf8[i] & 0xfc) == 0xc0 && | 332 } else if (((unsigned char)utf8[i] & 0xfc) == 0xc0 && |
333 ((unsigned char)utf8[i + 1] & 0xc0) == 0x80) { | 333 ((unsigned char)utf8[i + 1] & 0xc0) == 0x80) { |
334 i += 2; | 334 i += 2; |
335 continue; | 335 continue; |
336 } | 336 } |
337 charset = AIM_IMCHARSET_UNICODE; | 337 charset = AIM_CHARSET_UNICODE; |
338 break; | 338 break; |
339 } | 339 } |
340 | 340 |
341 return charset; | 341 return charset; |
342 } | 342 } |
3036 | 3036 |
3037 if ((datalen == 0) || (data == NULL)) | 3037 if ((datalen == 0) || (data == NULL)) |
3038 return NULL; | 3038 return NULL; |
3039 | 3039 |
3040 switch (charset) { | 3040 switch (charset) { |
3041 case AIM_IMCHARSET_UNICODE: /* UCS-2BE */ | 3041 case AIM_CHARSET_UNICODE: /* UCS-2BE */ |
3042 ret = g_convert(data, datalen, "UTF-8", "UCS-2BE", NULL, &convlen, &err); | 3042 ret = g_convert(data, datalen, "UTF-8", "UCS-2BE", NULL, &convlen, &err); |
3043 if (err != NULL) { | 3043 if (err != NULL) { |
3044 gaim_debug_warning("oscar", | 3044 gaim_debug_warning("oscar", |
3045 "UCS-2BE conversation failed: %s\n", err->message); | 3045 "UCS-2BE conversation failed: %s\n", err->message); |
3046 g_error_free(err); | 3046 g_error_free(err); |
3047 ret = g_strdup(_("(There was an error receiving this message)")); | 3047 ret = g_strdup(_("(There was an error receiving this message)")); |
3048 } | 3048 } |
3049 break; | 3049 break; |
3050 | 3050 |
3051 case AIM_IMCHARSET_CUSTOM: /* Use the value specified for this account */ | 3051 case AIM_CHARSET_CUSTOM: /* Use the value specified for this account */ |
3052 /* XXX - Make the encoding user customizable */ | 3052 /* XXX - Make the encoding user customizable */ |
3053 ret = g_convert(data, datalen, "UTF-8", "ISO-8859-1", NULL, &convlen, &err); | 3053 ret = g_convert(data, datalen, "UTF-8", "ISO-8859-1", NULL, &convlen, &err); |
3054 if (err != NULL) { | 3054 if (err != NULL) { |
3055 gaim_debug_warning("oscar", | 3055 gaim_debug_warning("oscar", |
3056 "UCS-2BE conversation failed: %s\n", err->message); | 3056 "UCS-2BE conversation failed: %s\n", err->message); |
3057 g_error_free(err); | 3057 g_error_free(err); |
3058 ret = g_strdup(_("(There was an error receiving this message)")); | 3058 ret = g_strdup(_("(There was an error receiving this message)")); |
3059 } | 3059 } |
3060 break; | 3060 break; |
3061 | 3061 |
3062 case AIM_IMCHARSET_ASCII: | 3062 case AIM_CHARSET_ASCII: |
3063 case 0x000d: /* Mobile AIM client on a Nokia 3100 and an LG VX6000 */ | 3063 case 0x000d: /* Mobile AIM client on a Nokia 3100 and an LG VX6000 */ |
3064 default: /* Unknown, hope for valid UTF-8... */ | 3064 default: /* Unknown, hope for valid UTF-8... */ |
3065 if (g_utf8_validate(data, datalen, NULL)) { | 3065 if (g_utf8_validate(data, datalen, NULL)) { |
3066 ret = g_strndup(data, datalen); | 3066 ret = g_strndup(data, datalen); |
3067 } else { | 3067 } else { |
3938 return 1; | 3938 return 1; |
3939 } | 3939 } |
3940 #endif | 3940 #endif |
3941 | 3941 |
3942 /* Data is assumed to be the destination sn */ | 3942 /* Data is assumed to be the destination sn */ |
3943 if (!gaim_conv_present_error(data, gaim_connection_get_account(gc), | 3943 buf = g_strdup_printf(_("Unable to send message: %s"), (reason < msgerrreasonlen) ? msgerrreason[reason] : _("Unknown reason.")); |
3944 (reason < msgerrreasonlen) ? _(msgerrreason[reason]) : _("Your message did not get sent."))) { | 3944 if (!gaim_conv_present_error(data, gaim_connection_get_account(gc), buf)) { |
3945 buf = g_strdup_printf(_("Your message to %s did not get sent:"), data ? data : "(null)"); | 3945 g_free(buf); |
3946 buf = g_strdup_printf(_("Unable to send message to %s:"), data ? data : "(unknown)"); | |
3946 gaim_notify_error(sess->aux_data, NULL, buf, | 3947 gaim_notify_error(sess->aux_data, NULL, buf, |
3947 (reason < msgerrreasonlen) ? _(msgerrreason[reason]) : _("No reason given.")); | 3948 (reason < msgerrreasonlen) ? _(msgerrreason[reason]) : _("Unknown reason.")); |
3948 g_free(buf); | 3949 } |
3949 } | 3950 g_free(buf); |
3951 | |
3950 return 1; | 3952 return 1; |
3951 } | 3953 } |
3952 | 3954 |
3953 static int gaim_parse_mtn(aim_session_t *sess, aim_frame_t *fr, ...) { | 3955 static int gaim_parse_mtn(aim_session_t *sess, aim_frame_t *fr, ...) { |
3954 GaimConnection *gc = sess->aux_data; | 3956 GaimConnection *gc = sess->aux_data; |
3986 /* | 3988 /* |
3987 * We get this error when there was an error in the locate family. This | 3989 * We get this error when there was an error in the locate family. This |
3988 * happens when you request info of someone who is offline. | 3990 * happens when you request info of someone who is offline. |
3989 */ | 3991 */ |
3990 static int gaim_parse_locerr(aim_session_t *sess, aim_frame_t *fr, ...) { | 3992 static int gaim_parse_locerr(aim_session_t *sess, aim_frame_t *fr, ...) { |
3991 gchar *buf, *cbuf; | 3993 gchar *buf; |
3992 va_list ap; | 3994 va_list ap; |
3993 fu16_t reason; | 3995 fu16_t reason; |
3994 char *destn; | 3996 char *destn; |
3995 | 3997 |
3996 va_start(ap, fr); | 3998 va_start(ap, fr); |
3999 va_end(ap); | 4001 va_end(ap); |
4000 | 4002 |
4001 if (destn == NULL) | 4003 if (destn == NULL) |
4002 return 1; | 4004 return 1; |
4003 | 4005 |
4004 cbuf = g_strdup_printf(_("User information not available: %s"), (reason < msgerrreasonlen) ? _(msgerrreason[reason]) : _("No reason given.")); | 4006 buf = g_strdup_printf(_("User information not available: %s"), (reason < msgerrreasonlen) ? _(msgerrreason[reason]) : _("Unknown reason.")); |
4005 if (!gaim_conv_present_error(destn, gaim_connection_get_account((GaimConnection*)sess->aux_data), cbuf)) { | 4007 if (!gaim_conv_present_error(destn, gaim_connection_get_account((GaimConnection*)sess->aux_data), buf)) { |
4008 g_free(buf); | |
4006 buf = g_strdup_printf(_("User information for %s unavailable:"), destn); | 4009 buf = g_strdup_printf(_("User information for %s unavailable:"), destn); |
4007 gaim_notify_error(sess->aux_data, NULL, buf, | 4010 gaim_notify_error(sess->aux_data, NULL, buf, (reason < msgerrreasonlen) ? _(msgerrreason[reason]) : _("Unknown reason.")); |
4008 (reason < msgerrreasonlen) ? _(msgerrreason[reason]) : _("No reason given.")); | 4011 } |
4009 g_free(buf); | 4012 g_free(buf); |
4010 } | |
4011 g_free(cbuf); | |
4012 | 4013 |
4013 return 1; | 4014 return 1; |
4014 } | 4015 } |
4015 | 4016 |
4016 static int gaim_parse_userinfo(aim_session_t *sess, aim_frame_t *fr, ...) { | 4017 static int gaim_parse_userinfo(aim_session_t *sess, aim_frame_t *fr, ...) { |
5296 tmpmsg = gaim_strdup_withhtml(message); | 5297 tmpmsg = gaim_strdup_withhtml(message); |
5297 } | 5298 } |
5298 len = strlen(tmpmsg); | 5299 len = strlen(tmpmsg); |
5299 | 5300 |
5300 args.charset = oscar_charset_check(tmpmsg); | 5301 args.charset = oscar_charset_check(tmpmsg); |
5301 if (args.charset == AIM_IMCHARSET_UNICODE) { | 5302 if (args.charset == AIM_CHARSET_UNICODE) { |
5302 gaim_debug_info("oscar", "Sending Unicode IM\n"); | 5303 gaim_debug_info("oscar", "Sending Unicode IM\n"); |
5303 args.charsubset = 0x0000; | 5304 args.charsubset = 0x0000; |
5304 args.msg = g_convert(tmpmsg, len, "UCS-2BE", "UTF-8", NULL, &len, &err); | 5305 args.msg = g_convert(tmpmsg, len, "UCS-2BE", "UTF-8", NULL, &len, &err); |
5305 if (err) { | 5306 if (err) { |
5306 gaim_debug_error("oscar", | 5307 gaim_debug_error("oscar", |
5309 "This really shouldn't happen!\n"); | 5310 "This really shouldn't happen!\n"); |
5310 /* We really shouldn't try to send the | 5311 /* We really shouldn't try to send the |
5311 * IM now, but I'm not sure what to do */ | 5312 * IM now, but I'm not sure what to do */ |
5312 g_error_free(err); | 5313 g_error_free(err); |
5313 } | 5314 } |
5314 } else if (args.charset == AIM_IMCHARSET_CUSTOM) { | 5315 } else if (args.charset == AIM_CHARSET_CUSTOM) { |
5315 gaim_debug_info("oscar", "Sending ISO-8859-1 IM\n"); | 5316 gaim_debug_info("oscar", "Sending ISO-8859-1 IM\n"); |
5316 args.charsubset = 0x0000; | 5317 args.charsubset = 0x0000; |
5317 args.msg = g_convert(tmpmsg, len, "ISO-8859-1", "UTF-8", NULL, &len, &err); | 5318 args.msg = g_convert(tmpmsg, len, "ISO-8859-1", "UTF-8", NULL, &len, &err); |
5318 if (err) { | 5319 if (err) { |
5319 gaim_debug_error("oscar", | 5320 gaim_debug_error("oscar", |
5390 return; | 5391 return; |
5391 } | 5392 } |
5392 | 5393 |
5393 text_html = gaim_strdup_withhtml(text); | 5394 text_html = gaim_strdup_withhtml(text); |
5394 charset = oscar_charset_check(text_html); | 5395 charset = oscar_charset_check(text_html); |
5395 if (charset == AIM_IMCHARSET_UNICODE) { | 5396 if (charset == AIM_CHARSET_UNICODE) { |
5396 msg = g_convert(text_html, strlen(text_html), "UCS-2BE", "UTF-8", NULL, &msglen, NULL); | 5397 msg = g_convert(text_html, strlen(text_html), "UCS-2BE", "UTF-8", NULL, &msglen, NULL); |
5397 aim_locate_setprofile(od->sess, "unicode-2-0", msg, (msglen > od->rights.maxsiglen ? od->rights.maxsiglen : msglen), NULL, NULL, 0); | 5398 aim_locate_setprofile(od->sess, "unicode-2-0", msg, (msglen > od->rights.maxsiglen ? od->rights.maxsiglen : msglen), NULL, NULL, 0); |
5398 g_free(msg); | 5399 g_free(msg); |
5399 } else if (charset == AIM_IMCHARSET_CUSTOM) { | 5400 } else if (charset == AIM_CHARSET_CUSTOM) { |
5400 msg = g_convert(text_html, strlen(text_html), "ISO-8859-1", "UTF-8", NULL, &msglen, NULL); | 5401 msg = g_convert(text_html, strlen(text_html), "ISO-8859-1", "UTF-8", NULL, &msglen, NULL); |
5401 aim_locate_setprofile(od->sess, "iso-8859-1", msg, (msglen > od->rights.maxsiglen ? od->rights.maxsiglen : msglen), NULL, NULL, 0); | 5402 aim_locate_setprofile(od->sess, "iso-8859-1", msg, (msglen > od->rights.maxsiglen ? od->rights.maxsiglen : msglen), NULL, NULL, 0); |
5402 g_free(msg); | 5403 g_free(msg); |
5403 } else { | 5404 } else { |
5404 msglen = strlen(text_html); | 5405 msglen = strlen(text_html); |
5463 return; | 5464 return; |
5464 } | 5465 } |
5465 | 5466 |
5466 text_html = gaim_strdup_withhtml(text); | 5467 text_html = gaim_strdup_withhtml(text); |
5467 charset = oscar_charset_check(text_html); | 5468 charset = oscar_charset_check(text_html); |
5468 if (charset == AIM_IMCHARSET_UNICODE) { | 5469 if (charset == AIM_CHARSET_UNICODE) { |
5469 msg = g_convert(text_html, strlen(text_html), "UCS-2BE", "UTF-8", NULL, &msglen, NULL); | 5470 msg = g_convert(text_html, strlen(text_html), "UCS-2BE", "UTF-8", NULL, &msglen, NULL); |
5470 aim_locate_setprofile(od->sess, NULL, NULL, 0, "unicode-2-0", msg, | 5471 aim_locate_setprofile(od->sess, NULL, NULL, 0, "unicode-2-0", msg, |
5471 (msglen > od->rights.maxawaymsglen ? od->rights.maxawaymsglen : msglen)); | 5472 (msglen > od->rights.maxawaymsglen ? od->rights.maxawaymsglen : msglen)); |
5472 g_free(msg); | 5473 g_free(msg); |
5473 gc->away = g_strndup(text, od->rights.maxawaymsglen/2); | 5474 gc->away = g_strndup(text, od->rights.maxawaymsglen/2); |
5474 } else if (charset == AIM_IMCHARSET_CUSTOM) { | 5475 } else if (charset == AIM_CHARSET_CUSTOM) { |
5475 msg = g_convert(text_html, strlen(text_html), "ISO-8859-1", "UTF-8", NULL, &msglen, NULL); | 5476 msg = g_convert(text_html, strlen(text_html), "ISO-8859-1", "UTF-8", NULL, &msglen, NULL); |
5476 aim_locate_setprofile(od->sess, NULL, NULL, 0, "iso-8859-1", msg, | 5477 aim_locate_setprofile(od->sess, NULL, NULL, 0, "iso-8859-1", msg, |
5477 (msglen > od->rights.maxawaymsglen ? od->rights.maxawaymsglen : msglen)); | 5478 (msglen > od->rights.maxawaymsglen ? od->rights.maxawaymsglen : msglen)); |
5478 g_free(msg); | 5479 g_free(msg); |
5479 gc->away = g_strndup(text_html, od->rights.maxawaymsglen); | 5480 gc->away = g_strndup(text_html, od->rights.maxawaymsglen); |
6366 _("Your IM Image was not sent. " | 6367 _("Your IM Image was not sent. " |
6367 "You cannot send IM Images in AIM chats."), | 6368 "You cannot send IM Images in AIM chats."), |
6368 GAIM_MESSAGE_ERROR, time(NULL)); | 6369 GAIM_MESSAGE_ERROR, time(NULL)); |
6369 | 6370 |
6370 charset = oscar_charset_check(buf); | 6371 charset = oscar_charset_check(buf); |
6371 if (charset == AIM_IMCHARSET_UNICODE) { | 6372 if (charset == AIM_CHARSET_UNICODE) { |
6372 gaim_debug_info("oscar", "Sending Unicode chat\n"); | 6373 gaim_debug_info("oscar", "Sending Unicode chat\n"); |
6373 charsetstr = "unicode-2-0"; | 6374 charsetstr = "unicode-2-0"; |
6374 buf2 = g_convert(buf, len, "UCS-2BE", "UTF-8", NULL, &len, &err); | 6375 buf2 = g_convert(buf, len, "UCS-2BE", "UTF-8", NULL, &len, &err); |
6375 if (err) { | 6376 if (err) { |
6376 gaim_debug_error("oscar", | 6377 gaim_debug_error("oscar", |
6377 "Error converting to unicode-2-0: %s\n", err->message); | 6378 "Error converting to unicode-2-0: %s\n", err->message); |
6378 g_error_free(err); | 6379 g_error_free(err); |
6379 } | 6380 } |
6380 } else if (charset == AIM_IMCHARSET_CUSTOM) { | 6381 } else if (charset == AIM_CHARSET_CUSTOM) { |
6381 gaim_debug_info("oscar", "Sending ISO-8859-1 chat\n"); | 6382 gaim_debug_info("oscar", "Sending ISO-8859-1 chat\n"); |
6382 charsetstr = "iso-8859-1"; | 6383 charsetstr = "iso-8859-1"; |
6383 buf2 = g_convert(buf, len, "ISO-8859-1", "UTF-8", NULL, &len, &err); | 6384 buf2 = g_convert(buf, len, "ISO-8859-1", "UTF-8", NULL, &len, &err); |
6384 if (err) { | 6385 if (err) { |
6385 gaim_debug_error("oscar", | 6386 gaim_debug_error("oscar", |