Index: aim.c
===================================================================
--- aim.c	(revision 9854278fd0ac47586e8157e1efa798dd2583d81e)
+++ aim.c	(revision dab82f298627df39e6a1cd885cf0ee0f353af7a0)
@@ -1,2 +1,26 @@
+/* Copyright (c) 2002,2003,2004,2009 James M. Kretchmar
+ *
+ * This file is part of Owl.
+ *
+ * Owl is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Owl is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Owl.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * ---------------------------------------------------------------
+ * 
+ * As of Owl version 2.1.12 there are patches contributed by
+ * developers of the the branched BarnOwl project, Copyright (c)
+ * 2006-2008 The BarnOwl Developers. All rights reserved.
+ */
+
 #include <stdio.h>
 #include <stdio.h>
@@ -239,5 +263,5 @@
 {
   if (message) {
-    owl_function_error(message);
+    owl_function_error("%s", message);
   } else {
     owl_function_error("Authentication error on login");
@@ -948,5 +972,5 @@
   
   if (modname) {
-    if (!(filename = malloc(strlen(priv->aimbinarypath)+1+strlen(modname)+4+1))) {
+    if (!(filename = owl_malloc(strlen(priv->aimbinarypath)+1+strlen(modname)+4+1))) {
       /* perror("memrequest: malloc"); */
       return -1;
@@ -954,5 +978,5 @@
     sprintf(filename, "%s/%s.ocm", priv->aimbinarypath, modname);
   } else {
-    if (!(filename = malloc(strlen(priv->aimbinarypath)+1+strlen(defaultmod)+1))) {
+    if (!(filename = owl_malloc(strlen(priv->aimbinarypath)+1+strlen(defaultmod)+1))) {
       /* perror("memrequest: malloc"); */
       return -1;
@@ -964,5 +988,5 @@
     if (!modname) {
       /* perror("memrequest: stat"); */
-      free(filename);
+      owl_free(filename);
       return -1;
     }
@@ -986,5 +1010,5 @@
     int i;
     
-    free(filename); /* not needed */
+    owl_free(filename); /* not needed */
     owl_function_error("getaimdata memrequest: recieved invalid request for 0x%08lx bytes at 0x%08lx (file %s)\n", len, offset, modname);
     i = 8;
@@ -993,5 +1017,5 @@
     }
     
-    if (!(buf = malloc(i))) {
+    if (!(buf = owl_malloc(i))) {
       return -1;
     }
@@ -1017,6 +1041,6 @@
     *buflenret = i;
   } else {
-    if (!(buf = malloc(len))) {
-      free(filename);
+    if (!(buf = owl_malloc(len))) {
+      owl_free(filename);
       return -1;
     }
@@ -1024,15 +1048,15 @@
     if (!(f = fopen(filename, "r"))) {
       /* perror("memrequest: fopen"); */
-      free(filename);
-      free(buf);
+      owl_free(filename);
+      owl_free(buf);
       return -1;
     }
     
-    free(filename);
+    owl_free(filename);
     
     if (fseek(f, offset, SEEK_SET) == -1) {
       /* perror("memrequest: fseek"); */
       fclose(f);
-      free(buf);
+      owl_free(buf);
       return -1;
     }
@@ -1041,5 +1065,5 @@
       /* perror("memrequest: fread"); */
       fclose(f);
-      free(buf);
+      owl_free(buf);
       return -1;
     }
@@ -1076,5 +1100,5 @@
   if (priv->aimbinarypath && (getaimdata(sess, &buf, &buflen, offset, len, modname) == 0)) {
     aim_sendmemblock(sess, fr->conn, offset, buflen, buf, AIM_SENDMEMBLOCK_FLAG_ISREQUEST);
-    free(buf);
+    owl_free(buf);
   } else {
     owl_function_debugmsg("faimtest_memrequest: unable to use AIM binary (\"%s/%s\"), sending defaults...\n", priv->aimbinarypath, modname);
@@ -1342,10 +1366,10 @@
       int z;
       
-      newbuf = malloc(i+1);
+      newbuf = owl_malloc(i+1);
       for (z = 0; z < i; z++)
 	newbuf[z] = (z % 10)+0x30;
       newbuf[i] = '\0';
       /* aim_send_im(sess, userinfo->sn, AIM_IMFLAGS_ACK | AIM_IMFLAGS_AWAY, newbuf); */
-      free(newbuf);
+      owl_free(newbuf);
     }
   } else if (strstr(tmpstr, "seticqstatus")) {
@@ -1452,5 +1476,13 @@
      *
      */
-    strncpy(realmsg, args->msg, sizeof(realmsg));
+    if (!args->msg) {
+      if (args->mpmsg.parts->data) {
+	strncpy(realmsg,args->mpmsg.parts->data, sizeof(realmsg));
+      } else {
+	strncpy(realmsg,"",1);
+      }
+    } else {
+      strncpy(realmsg, args->msg, sizeof(realmsg));
+    }
   }
 
@@ -1697,5 +1729,5 @@
   
   /* printf("snac threw error (reason 0x%04x: %s)\n", reason, (reason<msgerrreasonslen)?msgerrreasons[reason]:"unknown"); */
-  if (reason<msgerrreasonslen) owl_function_error(msgerrreasons[reason]);
+  if (reason<msgerrreasonslen) owl_function_error("%s", msgerrreasons[reason]);
   
   return 1;
@@ -1714,5 +1746,5 @@
   
   /* printf("message to %s bounced (reason 0x%04x: %s)\n", destsn, reason, (reason<msgerrreasonslen)?msgerrreasons[reason]:"unknown"); */
-  if (reason<msgerrreasonslen) owl_function_error(msgerrreasons[reason]);
+  if (reason<msgerrreasonslen) owl_function_error("%s", msgerrreasons[reason]);
 
   if (reason==4) {
@@ -1735,5 +1767,5 @@
   
   /* printf("user information for %s unavailable (reason 0x%04x: %s)\n", destsn, reason, (reason<msgerrreasonslen)?msgerrreasons[reason]:"unknown"); */
-  if (reason<msgerrreasonslen) owl_function_error(msgerrreasons[reason]);
+  if (reason<msgerrreasonslen) owl_function_error("%s", msgerrreasons[reason]);
   
   return 1;
@@ -2310,4 +2342,10 @@
 }
 
+void owl_process_aim()
+{
+  if (owl_global_is_doaimevents(&g)) {
+    owl_aim_process_events();
+  }
+}
 
 /**********************************************************************************/
