Changeset 1fdca1b


Ignore:
Timestamp:
Oct 3, 2009, 8:45:52 PM (12 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
3b80321
Parents:
82a79a6
git-author:
Nelson Elhage <nelhage@mit.edu> (10/03/09 18:33:38)
git-committer:
Nelson Elhage <nelhage@mit.edu> (10/03/09 20:45:52)
Message:
AIM: Decode incoming messages properly.

We can handle unicode now, so there's no need to HTML-encode high-bit
characters. Encode them into utf-8 so they show up properly.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • aim.c

    r82a79a6 r1fdca1b  
    11891189  owl_message *m;
    11901190  char *stripmsg, *nz_screenname, *wrapmsg;
    1191   char realmsg[8192+1] = "";
    1192   /* int clienttype = AIM_CLIENTTYPE_UNKNOWN; */
    1193 
    1194   /* clienttype = aim_fingerprintclient(args->features, args->featureslen); */
    1195 
    1196   /*
    1197   printf("icbm: sn = \"%s\"\n", userinfo->sn);
    1198   printf("icbm: probable client type: %d\n", clienttype);
    1199   printf("icbm: warnlevel = %f\n", aim_userinfo_warnlevel(userinfo));
    1200   printf("icbm: flags = 0x%04x = ", userinfo->flags);
    1201   printuserflags(userinfo->flags);
    1202   printf("\n");
    1203   */
    1204 
    1205   /*
    1206   printf("icbm: membersince = %lu\n", userinfo->membersince);
    1207   printf("icbm: onlinesince = %lu\n", userinfo->onlinesince);
    1208   printf("icbm: idletime = 0x%04x\n", userinfo->idletime);
    1209   printf("icbm: capabilities = %s = 0x%08lx\n", (userinfo->present & AIM_USERINFO_PRESENT_CAPABILITIES) ? "present" : "not present", userinfo->capabilities);
    1210   */
    1211 
    1212   /*
    1213   printf("icbm: icbmflags = ");
    1214   if (args->icbmflags & AIM_IMFLAGS_AWAY) printf("away ");
    1215   if (args->icbmflags & AIM_IMFLAGS_ACK) printf("ackrequest ");
    1216   if (args->icbmflags & AIM_IMFLAGS_OFFLINE) printf("offline ");
    1217   if (args->icbmflags & AIM_IMFLAGS_BUDDYREQ) printf("buddyreq ");
    1218   if (args->icbmflags & AIM_IMFLAGS_HASICON) printf("hasicon ");
    1219   printf("\n");
    1220   */
    1221 
    1222   /*
    1223   if (args->icbmflags & AIM_IMFLAGS_CUSTOMCHARSET) {
    1224   printf("icbm: encoding flags = {%04x, %04x}\n", args->charset, args->charsubset);
    1225   }
    1226   */
    1227  
    1228   /*
    1229    * Quickly convert it to eight bit format, replacing non-ASCII UNICODE
    1230    * characters with their equivelent HTML entity.
    1231    */
    1232   if (args->icbmflags & AIM_IMFLAGS_UNICODE) {
    1233     int i;
    1234    
    1235     for (i=0; i<args->msglen; i+=2) {
    1236       fu16_t uni;
    1237 
    1238       uni = ((args->msg[i] & 0xff) << 8) | (args->msg[i+1] & 0xff);
    1239       if ((uni < 128) || ((uni >= 160) && (uni <= 255))) { /* ISO 8859-1 */
    1240         snprintf(realmsg+strlen(realmsg), sizeof(realmsg)-strlen(realmsg), "%c", uni);
    1241       } else { /* something else, do UNICODE entity */
    1242         snprintf(realmsg+strlen(realmsg), sizeof(realmsg)-strlen(realmsg), "&#%04x;", uni);
    1243       }
    1244     }
     1191  char *realmsg = NULL;
     1192
     1193  if (!args->msg) {
     1194    realmsg = owl_strdup("");
     1195  } else if (args->icbmflags & AIM_IMFLAGS_UNICODE) {
     1196    realmsg = g_convert(args->msg, args->msglen, "UTF-8", "UCS-2BE",
     1197                        NULL, NULL, NULL);
     1198  } else if(args->icbmflags & AIM_IMFLAGS_ISO_8859_1) {
     1199    realmsg = g_convert(args->msg, args->msglen, "UTF-8", "ISO-8859-1",
     1200                        NULL, NULL, NULL);
    12451201  } else {
    1246     /*
    1247      * For non-UNICODE encodings (ASCII and ISO 8859-1), there is
    1248      * no need to do anything special here.  Most
    1249      * terminals/whatever will be able to display such characters
    1250      * unmodified.
    1251      *
    1252      * Beware that PC-ASCII 128 through 159 are _not_ actually
    1253      * defined in ASCII or ISO 8859-1, and you should send them as
    1254      * UNICODE.  WinAIM will send these characters in a UNICODE
    1255      * message, so you need to do so as well.
    1256      *
    1257      * You may not think it necessary to handle UNICODE messages. 
    1258      * You're probably wrong.  For one thing, Microsoft "Smart
    1259      * Quotes" will be sent by WinAIM as UNICODE (not HTML UNICODE,
    1260      * but real UNICODE). If you don't parse UNICODE at all, your
    1261      * users will get a blank message instead of the message
    1262      * containing Smart Quotes.
    1263      *
    1264      */
    1265     if (args->msg && args->msglen)
    1266       strncpy(realmsg, args->msg, sizeof(realmsg));
     1202    realmsg = owl_strdup(args->msg);
     1203  }
     1204
     1205  if (!realmsg) {
     1206    realmsg = owl_strdup("[Error decoding incoming IM]");
    12671207  }
    12681208
     
    13091249  }
    13101250
    1311   /*
    1312   if (realmsg) {
    1313     int i = 0;
    1314     while (realmsg[i] == '<') {
    1315       if (realmsg[i] == '<') {
    1316         while (realmsg[i] != '>')
    1317           i++;
    1318         i++;
    1319       }
    1320     }
    1321     tmpstr = realmsg+i;
    1322     faimtest_handlecmd(sess, conn, userinfo, tmpstr);
    1323   }
    1324   */
    1325  
     1251  owl_free(realmsg);
     1252
    13261253  return(1);
    13271254}
Note: See TracChangeset for help on using the changeset viewer.