Changeset 82a79a6


Ignore:
Timestamp:
Oct 3, 2009, 8:45:52 PM (15 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
1fdca1b
Parents:
0c4a190
git-author:
Nelson Elhage <nelhage@mit.edu> (10/03/09 18:14:53)
git-committer:
Nelson Elhage <nelhage@mit.edu> (10/03/09 20:45:52)
Message:
AIM: Correctly send outgoing IMs with high-bit characters.

Encode messages as either iso-8859-1 or ucs-2 as necessary, and set
the appropriate flags to make it work properly.

We don't support sending characters that are not representable in
UCS-2, for now. Doing so would probably require that I better
understand libfaim.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • aim.c

    rc79a047 r82a79a6  
    249249}
    250250
     251/*
     252 * I got these constants by skimming libfaim/im.c
     253 *
     254 * "UNICODE" actually means "UCS-2BE".
     255 */
     256#define AIM_CHARSET_ISO_8859_1         0x0003
     257#define AIM_CHARSET_UNICODE            0x0002
     258
     259int owl_aim_do_send(const char *to, const char *msg, int flags) /* noproto */
     260{
     261  int ret;
     262  char *encoded;
     263  struct aim_sendimext_args args;
     264    gsize len;
     265
     266  encoded = g_convert(msg, -1, "ISO-8859-1", "UTF-8", NULL, &len, NULL);
     267  if (encoded) {
     268    owl_function_debugmsg("Encoded outgoing AIM as ISO-8859-1");
     269    args.charset = AIM_CHARSET_ISO_8859_1;
     270    args.charsubset = 0;
     271    args.flags = AIM_IMFLAGS_ISO_8859_1;
     272  } else {
     273    owl_function_debugmsg("Encoding outgoing IM as UCS-2BE");
     274    encoded = g_convert(msg, -1, "UCS-2BE", "UTF-8", NULL, &len, NULL);
     275    if (!encoded) {
     276      /*
     277       * TODO: Strip or HTML-encode characters, or figure out how to
     278       * send in a differen charset.
     279       */
     280      owl_function_error("Unable to encode outgoing AIM message in UCS-2");
     281      return 1;
     282    }
     283
     284    args.charset = AIM_CHARSET_UNICODE;
     285    args.charsubset = 0;
     286    args.flags = AIM_IMFLAGS_UNICODE;
     287  }
     288
     289  args.destsn = to;
     290  args.msg = encoded;
     291  args.msglen = len;
     292  args.flags |= flags;
     293
     294  ret=aim_im_sendch1_ext(owl_global_get_aimsess(&g), &args);
     295
     296  owl_free(encoded);
     297
     298  return(ret);
     299}
     300
    251301int owl_aim_send_im(const char *to, const char *msg)
    252302{
    253   int ret;
    254 
    255   ret=aim_im_sendch1(owl_global_get_aimsess(&g), to, 0, msg);
    256    
    257   /* I don't know how to check for an error yet */
    258   return(ret);
     303  return owl_aim_do_send(to, msg, 0);
    259304}
    260305
    261306int owl_aim_send_awaymsg(const char *to, const char *msg)
    262307{
    263   int ret;
    264 
    265   ret=aim_im_sendch1(owl_global_get_aimsess(&g), to, AIM_IMFLAGS_AWAY, msg);
    266 
    267   /* I don't know how to check for an error yet */
    268   return(ret);
     308  return owl_aim_do_send(to, msg, AIM_IMFLAGS_AWAY);
    269309}
    270310
Note: See TracChangeset for help on using the changeset viewer.