]> andersk Git - libfaim.git/blobdiff - aim_info.c
Random Changes.
[libfaim.git] / aim_info.c
index daf47469a484665baf9466779575c9d700443bff..7a70321ce3b86d337b69b1bbc1af479d88852ddd 100644 (file)
@@ -13,26 +13,25 @@ u_long aim_getinfo(struct aim_session_t *sess,
                   struct aim_conn_t *conn, 
                   const char *sn)
 {
-  struct command_tx_struct newpacket;
+  struct command_tx_struct *newpacket;
+  int i = 0;
 
-  if (conn)
-    newpacket.conn = conn;
-  else
-    newpacket.conn = aim_getconn_type(sess, AIM_CONN_TYPE_BOS);
+  if (!sess || !conn || !sn)
+    return 0;
 
-  newpacket.lock = 1;
-  newpacket.type = 0x0002;
+  if (!(newpacket = aim_tx_new(0x0002, conn, 12+1+strlen(sn))))
+    return -1;
 
-  newpacket.commandlen = 12 + 1 + strlen(sn);
-  newpacket.data = (char *) malloc(newpacket.commandlen);
+  newpacket->lock = 1;
 
-  aim_putsnac(newpacket.data, 0x0002, 0x0005, 0x0000, sess->snac_nextid);
+  i = aim_putsnac(newpacket->data, 0x0002, 0x0005, 0x0000, sess->snac_nextid);
 
-  aimutil_put16(newpacket.data+10, 0x0001);
-  aimutil_put8(newpacket.data+12, strlen(sn));
-  aimutil_putstr(newpacket.data+13, sn, strlen(sn));
+  i += aimutil_put16(newpacket->data+i, 0x0001);
+  i += aimutil_put8(newpacket->data+i, strlen(sn));
+  i += aimutil_putstr(newpacket->data+i, sn, strlen(sn));
 
-  aim_tx_enqueue(sess, &newpacket);
+  newpacket->lock = 0;
+  aim_tx_enqueue(sess, newpacket);
 
   {
     struct aim_snac_t snac;
@@ -43,7 +42,7 @@ u_long aim_getinfo(struct aim_session_t *sess,
     snac.flags = 0x0000;
 
     snac.data = malloc(strlen(sn)+1);
-    memcpy(snac.data, sn, strlen(sn)+1);
+    strcpy(snac.data, sn);
 
     aim_newsnac(sess, &snac);
   }
@@ -51,6 +50,37 @@ u_long aim_getinfo(struct aim_session_t *sess,
   return (sess->snac_nextid++);
 }
 
+
+/*
+ * Capability blocks.  
+ */
+u_char aim_caps[6][16] = {
+  
+  /* Buddy icon */
+  {0x09, 0x46, 0x13, 0x46, 0x4c, 0x7f, 0x11, 0xd1, 
+   0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00},
+  
+  /* Voice */
+  {0x09, 0x46, 0x13, 0x41, 0x4c, 0x7f, 0x11, 0xd1, 
+   0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00},
+  
+  /* IM image */
+  {0x09, 0x46, 0x13, 0x45, 0x4c, 0x7f, 0x11, 0xd1, 
+   0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00},
+  
+  /* Chat */
+  {0x74, 0x8f, 0x24, 0x20, 0x62, 0x87, 0x11, 0xd1, 
+   0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00},
+  
+  /* Get file */
+  {0x09, 0x46, 0x13, 0x48, 0x4c, 0x7f, 0x11, 0xd1,
+   0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00},
+  
+  /* Send file */
+  {0x09, 0x46, 0x13, 0x43, 0x4c, 0x7f, 0x11, 0xd1, 
+   0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}
+};
+
 /*
  * AIM is fairly regular about providing user info.  This
  * is a generic routine to extract it in its standard form.
@@ -165,6 +195,29 @@ int aim_extractuserinfo(u_char *buf, struct aim_userinfo_s *outinfo)
           *
           */
        case 0x000d:
+         {
+           int z,y; 
+           int len;
+           len = aimutil_get16(buf+i+2);
+           if (!len)
+             break;
+
+           for (z = 0; z < len; z+=0x10) {
+             for(y=0; y < 6; y++) {
+               if (memcmp(&aim_caps[y], buf+i+4+z, 0x10) == 0) {
+                 switch(y) {
+                 case 0: outinfo->capabilities |= AIM_CAPS_BUDDYICON; break;
+                 case 1: outinfo->capabilities |= AIM_CAPS_VOICE; break;
+                 case 2: outinfo->capabilities |= AIM_CAPS_IMIMAGE; break;
+                 case 3: outinfo->capabilities |= AIM_CAPS_CHAT; break;
+                 case 4: outinfo->capabilities |= AIM_CAPS_GETFILE; break;
+                 case 5: outinfo->capabilities |= AIM_CAPS_SENDFILE; break;
+                 default: outinfo->capabilities |= 0xff00; break;
+                 }
+               }
+             }
+           }
+         }
          break;
 
          /*
@@ -284,8 +337,8 @@ int aim_parse_offgoing_middle(struct aim_session_t *sess,
   u_int i = 0;
   rxcallback_t userfunc=NULL;
 
-  /* Protect against future SN length extensions */
-  strncpy(sn, command->data+11, (((int)(command->data+10))<=MAXSNLEN)?(int)command->data+10:MAXSNLEN);
+  strncpy(sn, command->data+11, (int)command->data[10]);
+  sn[(int)command->data[10]] = '\0';
 
   userfunc = aim_callhandler(command->conn, AIM_CB_FAM_BUD, AIM_CB_BUD_OFFGOING);
   if (userfunc)
@@ -316,8 +369,16 @@ int aim_parse_userinfo_middle(struct aim_session_t *sess,
     snacid = aimutil_get32(&command->data[6]);
     snac = aim_remsnac(sess, snacid);
 
-    free(snac->data);
-    free(snac);
+    if (snac)
+      {
+       if (snac->data)
+         free(snac->data);
+       else
+         printf("faim: parse_userinfo_middle: warning: no ->data in cached SNAC\n");
+       free(snac);
+      }
+    else
+      printf("faim: parseuserinfo_middle: warning: no SNAC cached with for this response (%08lx)\n", snacid);
 
   }
   
@@ -351,3 +412,90 @@ int aim_parse_userinfo_middle(struct aim_session_t *sess,
 
   return 1;
 }
+
+/*
+ * Inverse of aim_extractuserinfo()
+ */
+int aim_putuserinfo(u_char *buf, int buflen, struct aim_userinfo_s *info)
+{
+  int i = 0;
+  struct aim_tlvlist_t *tlvlist = NULL;
+
+  if (!buf || !info)
+    return 0;
+
+  i += aimutil_put8(buf+i, strlen(info->sn));
+  i += aimutil_putstr(buf+i, info->sn, strlen(info->sn));
+
+  i += aimutil_put16(buf+i, info->warnlevel);
+
+  /* XXX: we only put down five */
+  i += aimutil_put16(buf+i, 5);
+  aim_addtlvtochain16(&tlvlist, 0x0001, info->class);
+  aim_addtlvtochain32(&tlvlist, 0x0002, info->membersince);
+  aim_addtlvtochain32(&tlvlist, 0x0003, info->onlinesince);
+  aim_addtlvtochain16(&tlvlist, 0x0004, info->idletime);
+  /* XXX: should put caps here */
+  aim_addtlvtochain32(&tlvlist, (info->class)&AIM_CLASS_AOL?0x0010:0x000f, info->sessionlen);
+  
+  i += aim_writetlvchain(buf+i, buflen-i, &tlvlist);
+  aim_freetlvchain(&tlvlist);
+  
+  return i;
+}
+
+int aim_sendbuddyoncoming(struct aim_session_t *sess, struct aim_conn_t *conn, struct aim_userinfo_s *info)
+{
+  struct command_tx_struct *tx;
+  int i = 0;
+
+  if (!sess || !conn || !info)
+    return 0;
+
+  if (!(tx = aim_tx_new(0x0002, conn, 1152)))
+    return -1;
+
+  tx->lock = 1;
+
+  i += aimutil_put16(tx->data+i, 0x0003);
+  i += aimutil_put16(tx->data+i, 0x000b);
+  i += aimutil_put16(tx->data+i, 0x0000);
+  i += aimutil_put16(tx->data+i, 0x0000);
+  i += aimutil_put16(tx->data+i, 0x0000);
+
+  i += aim_putuserinfo(tx->data+i, tx->commandlen-i, info);
+
+  tx->commandlen = i;
+  tx->lock = 0;
+  aim_tx_enqueue(sess, tx);
+
+  return 0;
+}
+
+int aim_sendbuddyoffgoing(struct aim_session_t *sess, struct aim_conn_t *conn, char *sn)
+{
+  struct command_tx_struct *tx;
+  int i = 0;
+
+  if (!sess || !conn || !sn)
+    return 0;
+
+  if (!(tx = aim_tx_new(0x0002, conn, 10+1+strlen(sn))))
+    return -1;
+
+  tx->lock = 1;
+
+  i += aimutil_put16(tx->data+i, 0x0003);
+  i += aimutil_put16(tx->data+i, 0x000c);
+  i += aimutil_put16(tx->data+i, 0x0000);
+  i += aimutil_put16(tx->data+i, 0x0000);
+  i += aimutil_put16(tx->data+i, 0x0000);
+
+  i += aimutil_put8(tx->data+i, strlen(sn));
+  i += aimutil_putstr(tx->data+i, sn, strlen(sn));
+  
+  tx->lock = 0;
+  aim_tx_enqueue(sess, tx);
+
+  return 0;
+}
This page took 0.039886 seconds and 4 git commands to generate.