Mercurial > pidgin
comparison src/protocols/oscar/oscar.c @ 3642:5e50f6746509
[gaim-migrate @ 3766]
(10:16:03) deryni: we're fully 'compliant'? (sorry if that betrays some underlying stupidity)
(10:16:55) Paco-Paco: yes
(10:17:24) Paco-Paco: provided the user has the font, on any of the services supporting unicode we should support every known language in the world :-)
(10:17:36) Paco-Paco: well, as soon as we have a proper utf-8 input widget
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Fri, 11 Oct 2002 14:19:24 +0000 |
parents | 1607fa5f3c1e |
children | 498e78765620 |
comparison
equal
deleted
inserted
replaced
3641:e2391338c394 | 3642:5e50f6746509 |
---|---|
1707 | 1707 |
1708 return TRUE; | 1708 return TRUE; |
1709 } | 1709 } |
1710 | 1710 |
1711 static int incomingim_chan1(aim_session_t *sess, aim_conn_t *conn, aim_userinfo_t *userinfo, struct aim_incomingim_ch1_args *args) { | 1711 static int incomingim_chan1(aim_session_t *sess, aim_conn_t *conn, aim_userinfo_t *userinfo, struct aim_incomingim_ch1_args *args) { |
1712 char *tmp = g_malloc(BUF_LONG); | 1712 char *tmp; |
1713 struct gaim_connection *gc = sess->aux_data; | 1713 struct gaim_connection *gc = sess->aux_data; |
1714 struct oscar_data *od = gc->proto_data; | 1714 struct oscar_data *od = gc->proto_data; |
1715 int flags = 0; | 1715 int flags = 0; |
1716 | 1716 |
1717 if (args->icbmflags & AIM_IMFLAGS_AWAY) | 1717 if (args->icbmflags & AIM_IMFLAGS_AWAY) |
1767 * Quickly convert it to eight bit format, replacing | 1767 * Quickly convert it to eight bit format, replacing |
1768 * non-ASCII UNICODE characters with their equivelent | 1768 * non-ASCII UNICODE characters with their equivelent |
1769 * HTML entity. | 1769 * HTML entity. |
1770 */ | 1770 */ |
1771 if (args->icbmflags & AIM_IMFLAGS_UNICODE) { | 1771 if (args->icbmflags & AIM_IMFLAGS_UNICODE) { |
1772 int i, j; | |
1773 GError *err = NULL; | |
1774 FILE *fp; | |
1775 | |
1776 tmp = g_convert(args->msg, args->msglen, "UTF-8", "UCS-2BE", &j, &i, &err); | |
1777 if (err) | |
1778 debug_printf("Unicode IM conversion: %s\n", err->message); | |
1779 if (!tmp) { | |
1780 /* Conversion to HTML entities isn't a bad fallback */ | |
1781 debug_printf ("AIM charset conversion failed!\n"); | |
1782 for (i = 0, tmp[0] = '\0'; i < args->msglen; i += 2) { | |
1783 unsigned short uni; | |
1784 | |
1785 uni = ((args->msg[i] & 0xff) << 8) | (args->msg[i+1] & 0xff); | |
1786 | |
1787 if ((uni < 128) || ((uni >= 160) && (uni <= 255))) { /* ISO 8859-1 */ | |
1788 | |
1789 g_snprintf(tmp+strlen(tmp), BUF_LONG-strlen(tmp), "%c", uni); | |
1790 | |
1791 } else { /* something else, do UNICODE entity */ | |
1792 g_snprintf(tmp+strlen(tmp), BUF_LONG-strlen(tmp), "&#%04x;", uni); | |
1793 } | |
1794 | |
1795 } | |
1796 } | |
1797 } else if (args->icbmflags & AIM_IMFLAGS_ISO_8859_1) { | |
1772 int i; | 1798 int i; |
1773 | 1799 debug_printf("ISO-8859-1 IM"); |
1774 for (i = 0, tmp[0] = '\0'; i < args->msglen; i += 2) { | 1800 tmp = g_convert(args->msg, args->msglen, "UTF-8", "ISO-8859-1", NULL, &i, NULL); |
1775 unsigned short uni; | 1801 } else { |
1776 | 1802 /* ASCII is valid UTF-8 */ |
1777 uni = ((args->msg[i] & 0xff) << 8) | (args->msg[i+1] & 0xff); | 1803 debug_printf("ASCII IM\n"); |
1778 | 1804 tmp = g_strdup(args->msg); |
1779 if ((uni < 128) || ((uni >= 160) && (uni <= 255))) { /* ISO 8859-1 */ | 1805 } |
1780 | |
1781 g_snprintf(tmp+strlen(tmp), BUF_LONG-strlen(tmp), "%c", uni); | |
1782 | |
1783 } else { /* something else, do UNICODE entity */ | |
1784 g_snprintf(tmp+strlen(tmp), BUF_LONG-strlen(tmp), "&#%04x;", uni); | |
1785 } | |
1786 } | |
1787 } else | |
1788 g_snprintf(tmp, BUF_LONG, "%s", args->msg); | |
1789 | 1806 |
1790 if (args->icbmflags & AIM_IMFLAGS_TYPINGNOT) { | 1807 if (args->icbmflags & AIM_IMFLAGS_TYPINGNOT) { |
1791 char *who = normalize(userinfo->sn); | 1808 char *who = normalize(userinfo->sn); |
1792 if (!g_hash_table_lookup(od->supports_tn, who)) | 1809 if (!g_hash_table_lookup(od->supports_tn, who)) |
1793 g_hash_table_insert(od->supports_tn, who, who); | 1810 g_hash_table_insert(od->supports_tn, who, who); |
1794 } | 1811 } |
1795 | 1812 |
1796 strip_linefeed(tmp); | 1813 //strip_linefeed(tmp); |
1797 serv_got_im(gc, userinfo->sn, tmp, flags, time(NULL), -1); | 1814 serv_got_im(gc, userinfo->sn, tmp, flags, time(NULL), -1); |
1798 g_free(tmp); | 1815 g_free(tmp); |
1799 | 1816 |
1800 return 1; | 1817 return 1; |
1801 } | 1818 } |
3298 struct aim_sendimext_args args; | 3315 struct aim_sendimext_args args; |
3299 GSList *h = odata->hasicons; | 3316 GSList *h = odata->hasicons; |
3300 struct icon_req *ir = NULL; | 3317 struct icon_req *ir = NULL; |
3301 char *who = normalize(name); | 3318 char *who = normalize(name); |
3302 struct stat st; | 3319 struct stat st; |
3320 int i, len; | |
3303 | 3321 |
3304 args.flags = AIM_IMFLAGS_ACK | AIM_IMFLAGS_CUSTOMFEATURES; | 3322 args.flags = AIM_IMFLAGS_ACK | AIM_IMFLAGS_CUSTOMFEATURES; |
3305 if (odata->icq) | 3323 if (odata->icq) |
3306 args.flags |= AIM_IMFLAGS_OFFLINE; | 3324 args.flags |= AIM_IMFLAGS_OFFLINE; |
3307 | 3325 |
3337 g_free(buf); | 3355 g_free(buf); |
3338 } | 3356 } |
3339 } | 3357 } |
3340 | 3358 |
3341 args.destsn = name; | 3359 args.destsn = name; |
3342 args.msg = message; | 3360 |
3343 args.msglen = strlen(message); | 3361 /* Determine how we can send this message. Per the |
3362 * warnings elsewhere in this file, these little | |
3363 * checks determine the simplest encoding we can use | |
3364 * for a given message send using it. */ | |
3365 len = strlen(message); | |
3366 i = 0; | |
3367 while (message[i]) { | |
3368 if ((unsigned char)message[i] > 0x7f) { | |
3369 /* not ASCII! */ | |
3370 args.flags |= AIM_IMFLAGS_ISO_8859_1; | |
3371 break; | |
3372 } | |
3373 i++; | |
3374 } | |
3375 while (message[i]) { | |
3376 /* ISO-8859-1 is 0x00-0xbf in the first byte | |
3377 * followed by 0xc0-0xc3 in the second */ | |
3378 if ((unsigned char)message[i] > 0x80 && ((unsigned char)message[i] > 0xbf || | |
3379 ((unsigned char)message[i + 1] < 0xc0 || (unsigned char)message[i + 1] > 0xc3))) { | |
3380 args.flags ^= AIM_IMFLAGS_ISO_8859_1; | |
3381 args.flags |= AIM_IMFLAGS_UNICODE; | |
3382 break; | |
3383 } | |
3384 i++; | |
3385 } | |
3386 if (args.flags & AIM_IMFLAGS_UNICODE) { | |
3387 args.msg = g_convert(message, len, "UCS-2BE", "UTF-8", NULL, &len, NULL); | |
3388 } else if (args.flags & AIM_IMFLAGS_UNICODE) { | |
3389 args.msg = g_convert(message, len, "ISO-8859-1", "UTF-8", NULL, &len, NULL); | |
3390 if (!args.msg) { | |
3391 debug_printf("Someone tell Ethan his 8859-1 detection is wrong\n"); | |
3392 args.flags ^= AIM_IMFLAGS_ISO_8859_1 | AIM_IMFLAGS_UNICODE; | |
3393 len = strlen(message); | |
3394 args.msg = g_convert(message, len, "UCS-2BE", "UTF8", NULL, &len, NULL); | |
3395 } | |
3396 } else { | |
3397 args.msg = message; | |
3398 } | |
3399 args.msglen = len; | |
3344 | 3400 |
3345 ret = aim_send_im_ext(odata->sess, &args); | 3401 ret = aim_send_im_ext(odata->sess, &args); |
3346 | |
3347 } | 3402 } |
3348 if (ret >= 0) | 3403 if (ret >= 0) |
3349 return 1; | 3404 return 1; |
3350 return ret; | 3405 return ret; |
3351 } | 3406 } |