]> andersk Git - libfaim.git/blobdiff - src/info.c
Hmmm.
[libfaim.git] / src / info.c
index ee140feb91f272f06b098b66b5c388b8e00e3c1c..a36a7f52525f522d457cd9a8a1cbf56d784836b8 100644 (file)
@@ -14,17 +14,21 @@ struct aim_priv_inforeq {
   unsigned short infotype;
 };
 
-faim_export unsigned long aim_getinfo(struct aim_session_t *sess,
-                                     struct aim_conn_t *conn, 
-                                     const char *sn,
-                                     unsigned short infotype)
+faim_export int aim_getinfo(struct aim_session_t *sess,
+                           struct aim_conn_t *conn, 
+                           const char *sn,
+                           unsigned short infotype)
 {
   struct command_tx_struct *newpacket;
   struct aim_priv_inforeq privdata;
   int i = 0;
 
   if (!sess || !conn || !sn)
-    return 0;
+    return -1;
+
+  if ((infotype != AIM_GETINFO_GENERALINFO) &&
+      (infotype != AIM_GETINFO_AWAYMESSAGE))
+    return -1;
 
   if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 12+1+strlen(sn))))
     return -1;
@@ -44,162 +48,107 @@ faim_export unsigned long aim_getinfo(struct aim_session_t *sess,
   privdata.infotype = infotype;
   aim_cachesnac(sess, 0x0002, 0x0005, 0x0000, &privdata, sizeof(struct aim_priv_inforeq));
 
-  return sess->snac_nextid;
-}
-
-faim_internal int aim_parse_locateerr(struct aim_session_t *sess,
-                                     struct command_rx_struct *command)
-{
-  u_long snacid = 0x000000000;
-  struct aim_snac_t *snac = NULL;
-  int ret = 0;
-  rxcallback_t userfunc = NULL;
-  char *dest;
-  unsigned short reason = 0;
-
-  /*
-   * Get SNAC from packet and look it up 
-   * the list of unrepliedto/outstanding
-   * SNACs.
-   *
-   */
-  snacid = aimutil_get32(command->data+6);
-  snac = aim_remsnac(sess, snacid);
-
-  if (!snac) {
-    faimdprintf(sess, 0, "locerr: got an locate-failed error on an unknown SNAC ID! (%08lx)\n", snacid);
-    dest = NULL;
-  } else
-    dest = snac->data;
-
-  reason = aimutil_get16(command->data+10);
-
-  /*
-   * Call client.
-   */
-  userfunc = aim_callhandler(sess, command->conn, 0x0002, 0x0001);
-  if (userfunc)
-    ret =  userfunc(sess, command, dest, reason);
-  else
-    ret = 0;
-  
-  if (snac) {
-    free(snac->data);
-    free(snac);
-  }
-
-  return ret;
+  return 0;
 }
 
 /*
  * Capability blocks.  
  */
-u_char aim_caps[8][16] = {
+static const struct {
+  unsigned short flag;
+  unsigned char data[16];
+} aim_caps[] = {
   
-  /* Buddy icon */
-  {0x09, 0x46, 0x13, 0x46, 0x4c, 0x7f, 0x11, 0xd1, 
-   0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00},
+  {AIM_CAPS_BUDDYICON,
+   {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},
+  {AIM_CAPS_VOICE,
+   {0x09, 0x46, 0x13, 0x41, 0x4c, 0x7f, 0x11, 0xd1, 
+    0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
+
+  {AIM_CAPS_IMIMAGE,
+   {0x09, 0x46, 0x13, 0x45, 0x4c, 0x7f, 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},
+  {AIM_CAPS_CHAT,
+   {0x74, 0x8f, 0x24, 0x20, 0x62, 0x87, 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_CAPS_GETFILE,
+   {0x09, 0x46, 0x13, 0x48, 0x4c, 0x7f, 0x11, 0xd1,
+    0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
 
-  /* Saves stock portfolios */
-  {0x09, 0x46, 0x13, 0x47, 0x4c, 0x7f, 0x11, 0xd1,
-   0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00},
+  {AIM_CAPS_SENDFILE,
+   {0x09, 0x46, 0x13, 0x43, 0x4c, 0x7f, 0x11, 0xd1, 
+    0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
 
-  /* Games */
-  {0x09, 0x46, 0x13, 0x4a, 0x4c, 0x7f, 0x11, 0xd1,
-   0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00},
+  {AIM_CAPS_SAVESTOCKS,
+   {0x09, 0x46, 0x13, 0x47, 0x4c, 0x7f, 0x11, 0xd1,
+    0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
+
+  /*
+   * Indeed, there are two of these.  The former appears
+   * to be correct, but in some versions of winaim, the
+   * second one is set.  Either they forgot to fix endianness,
+   * or they made a typo. It really doesn't matter which.
+   */
+  {AIM_CAPS_GAMES,
+   {0x09, 0x46, 0x13, 0x4a, 0x4c, 0x7f, 0x11, 0xd1,
+    0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
+  {AIM_CAPS_GAMES2,
+   {0x09, 0x46, 0x13, 0x4a, 0x4c, 0x7f, 0x11, 0xd1,
+    0x22, 0x82, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
+
+  {AIM_CAPS_SENDBUDDYLIST,
+   {0x09, 0x46, 0x13, 0x4b, 0x4c, 0x7f, 0x11, 0xd1,
+    0x82, 0x22, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}},
+
+  {AIM_CAPS_LAST}
 };
 
 faim_internal unsigned short aim_getcap(struct aim_session_t *sess, unsigned char *capblock, int buflen)
 {
-  u_short ret = 0;
-  int y;
+  unsigned short flags;
+  int i;
   int offset = 0;
   int identified;
 
-  while (offset < buflen) {
-    identified = 0;
-    for(y=0; y < (sizeof(aim_caps)/0x10); y++) {
-      if (memcmp(&aim_caps[y], capblock+offset, 0x10) == 0) {
-       switch(y) {
-       case 0: ret |= AIM_CAPS_BUDDYICON; identified++; break;
-       case 1: ret |= AIM_CAPS_VOICE; identified++; break;
-       case 2: ret |= AIM_CAPS_IMIMAGE; identified++; break;
-       case 3: ret |= AIM_CAPS_CHAT; identified++; break;
-       case 4: ret |= AIM_CAPS_GETFILE; identified++; break;
-       case 5: ret |= AIM_CAPS_SENDFILE; identified++; break;
-       case 6: ret |= AIM_CAPS_GAMES; identified++; break;
-       case 7: ret |= AIM_CAPS_SAVESTOCKS; identified++; break;
-       }
+  for (offset = 0, flags = 0; offset < buflen; offset += 0x0010) {
+
+    for (i = 0, identified = 0; !(aim_caps[i].flag & AIM_CAPS_LAST); i++) {
+
+      if (memcmp(&aim_caps[i].data, capblock+offset, 0x10) == 0) {
+       flags |= aim_caps[i].flag;
+       identified++;
+       break; /* should only match once... */
       }
+
     }
-    if (!identified) {
+
+    if (!identified)
       faimdprintf(sess, 0, "unknown capability!\n");
-      ret |= 0xff00;
-    }
 
-    offset += 0x10;
-  } 
-  return ret;
+  }
+
+  return flags;
 }
 
-faim_internal int aim_putcap(unsigned char *capblock, int buflen, u_short caps)
+faim_internal int aim_putcap(unsigned char *capblock, int buflen, unsigned short caps)
 {
-  int offset = 0;
+  int offset, i;
 
   if (!capblock)
-    return -1;
+    return 0;
+
+  for (i = 0, offset = 0; 
+       !(aim_caps[i].flag & AIM_CAPS_LAST) && (offset < buflen); i++) {
+
+    if (caps & aim_caps[i].flag) {
+      memcpy(capblock+offset, aim_caps[i].data, 16);
+      offset += 16;
+    }
 
-  if ((caps & AIM_CAPS_BUDDYICON) && (offset < buflen)) {
-    memcpy(capblock+offset, aim_caps[0], sizeof(aim_caps[0]));
-    offset += sizeof(aim_caps[1]);
-  }
-  if ((caps & AIM_CAPS_VOICE) && (offset < buflen)) {
-    memcpy(capblock+offset, aim_caps[1], sizeof(aim_caps[1]));
-    offset += sizeof(aim_caps[1]);
-  }
-  if ((caps & AIM_CAPS_IMIMAGE) && (offset < buflen)) {
-    memcpy(capblock+offset, aim_caps[2], sizeof(aim_caps[2]));
-    offset += sizeof(aim_caps[2]);
-  }
-  if ((caps & AIM_CAPS_CHAT) && (offset < buflen)) {
-    memcpy(capblock+offset, aim_caps[3], sizeof(aim_caps[3]));
-    offset += sizeof(aim_caps[3]);
-  }
-  if ((caps & AIM_CAPS_GETFILE) && (offset < buflen)) {
-    memcpy(capblock+offset, aim_caps[4], sizeof(aim_caps[4]));
-    offset += sizeof(aim_caps[4]);
-  }
-  if ((caps & AIM_CAPS_SENDFILE) && (offset < buflen)) {
-    memcpy(capblock+offset, aim_caps[5], sizeof(aim_caps[5]));
-    offset += sizeof(aim_caps[5]);
-  }
-  if ((caps & AIM_CAPS_GAMES) && (offset < buflen)) {
-    memcpy(capblock+offset, aim_caps[6], sizeof(aim_caps[6]));
-    offset += sizeof(aim_caps[6]);
-  }
-  if ((caps & AIM_CAPS_SAVESTOCKS) && (offset < buflen)) {
-    memcpy(capblock+offset, aim_caps[7], sizeof(aim_caps[7]));
-    offset += sizeof(aim_caps[7]);
   }
 
   return offset;
@@ -461,91 +410,6 @@ faim_internal int aim_extractuserinfo(struct aim_session_t *sess, unsigned char
   return i;
 }
 
-/*
- * This parses the user info stuff out all nice and pretty then calls 
- * the higher-level callback (in the user app).
- *
- */
-faim_internal int aim_parse_userinfo_middle(struct aim_session_t *sess,
-                                           struct command_rx_struct *command)
-{
-  struct aim_userinfo_s userinfo;
-  char *text_encoding = NULL;
-  char *text = NULL;
-  u_int i = 0;
-  rxcallback_t userfunc=NULL;
-  struct aim_tlvlist_t *tlvlist;
-  struct aim_snac_t *origsnac = NULL;
-  u_long snacid;
-  struct aim_priv_inforeq *inforeq;
-  
-  snacid = aimutil_get32(&command->data[6]);
-  origsnac = aim_remsnac(sess, snacid);
-
-  if (!origsnac || !origsnac->data) {
-    faimdprintf(sess, 0, "parse_userinfo_middle: major problem: no snac stored!\n");
-    return 1;
-  }
-
-  inforeq = (struct aim_priv_inforeq *)origsnac->data;
-
-  switch (inforeq->infotype) {
-  case AIM_GETINFO_GENERALINFO:
-  case AIM_GETINFO_AWAYMESSAGE:
-    i = 10;
-
-    /*
-     * extractuserinfo will give us the basic metaTLV information
-     */
-    i += aim_extractuserinfo(sess, command->data+i, &userinfo);
-  
-    /*
-     * However, in this command, there's usually more TLVs following...
-     */ 
-    tlvlist = aim_readtlvchain(command->data+i, command->commandlen-i);
-
-    /* 
-     * Depending on what informational text was requested, different
-     * TLVs will appear here.
-     *
-     * Profile will be 1 and 2, away message will be 3 and 4.
-     */
-    if (aim_gettlv(tlvlist, 0x0001, 1)) {
-      text_encoding = aim_gettlv_str(tlvlist, 0x0001, 1);
-      text = aim_gettlv_str(tlvlist, 0x0002, 1);
-    } else if (aim_gettlv(tlvlist, 0x0003, 1)) {
-      text_encoding = aim_gettlv_str(tlvlist, 0x0003, 1);
-      text = aim_gettlv_str(tlvlist, 0x0004, 1);
-    }
-
-    userfunc = aim_callhandler(sess, command->conn, AIM_CB_FAM_LOC, AIM_CB_LOC_USERINFO);
-    if (userfunc) {
-      i = userfunc(sess,
-                  command, 
-                  &userinfo, 
-                  text_encoding, 
-                  text,
-                  inforeq->infotype); 
-    }
-  
-    free(text_encoding);
-    free(text);
-    aim_freetlvchain(&tlvlist);
-    break;
-  default:
-    faimdprintf(sess, 0, "parse_userinfo_middle: unknown infotype in request! (0x%04x)\n", inforeq->infotype);
-    break;
-  }
-
-  if (origsnac) {
-    if (origsnac->data)
-      free(origsnac->data);
-    free(origsnac);
-  }
-
-  return 1;
-}
-
 /*
  * Inverse of aim_extractuserinfo()
  */
@@ -651,3 +515,137 @@ faim_export int aim_sendbuddyoffgoing(struct aim_session_t *sess, struct aim_con
   return 0;
 }
 
+faim_export int aim_0002_000b(struct aim_session_t *sess, struct aim_conn_t *conn, const char *sn)
+{
+  struct command_tx_struct *tx;
+  int i = 0;
+
+  if (!sess || !conn || !sn)
+    return 0;
+
+  if (!(tx = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+1+strlen(sn))))
+    return -1;
+
+  tx->lock = 1;
+
+  i = aim_putsnac(tx->data, 0x0002, 0x000b, 0x0000, sess->snac_nextid);
+  i += aimutil_put8(tx->data+i, strlen(sn));
+  i += aimutil_putstr(tx->data+i, sn, strlen(sn));
+  
+  tx->commandlen = i;
+  tx->lock = 0;
+  aim_tx_enqueue(sess, tx);
+
+  return 0;
+}
+
+/*
+ * Normally contains:
+ *   t(0001)  - short containing max profile length (value = 1024)
+ *   t(0002)  - short - unknown (value = 16) [max MIME type length?]
+ *   t(0003)  - short - unknown (value = 7)
+ */
+static int rights(struct aim_session_t *sess, aim_module_t *mod, struct command_rx_struct *rx, aim_modsnac_t *snac, unsigned char *data, int datalen)
+{
+       struct aim_tlvlist_t *tlvlist;
+       aim_rxcallback_t userfunc;
+       int ret = 0;
+       unsigned short maxsiglen = 0;
+
+       tlvlist = aim_readtlvchain(data, datalen);
+
+       if (aim_gettlv(tlvlist, 0x0001, 1))
+               maxsiglen = aim_gettlv16(tlvlist, 0x0001, 1);
+
+       if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
+               ret = userfunc(sess, rx, maxsiglen);
+
+       aim_freetlvchain(&tlvlist);
+
+       return ret;
+}
+
+static int userinfo(struct aim_session_t *sess, aim_module_t *mod, struct command_rx_struct *rx, aim_modsnac_t *snac, unsigned char *data, int datalen)
+{
+  struct aim_userinfo_s userinfo;
+  char *text_encoding = NULL;
+  char *text = NULL;
+  int i = 0;
+  aim_rxcallback_t userfunc;
+  struct aim_tlvlist_t *tlvlist;
+  struct aim_snac_t *origsnac = NULL;
+  struct aim_priv_inforeq *inforeq;
+  int ret = 0;
+
+  origsnac = aim_remsnac(sess, snac->id);
+
+  if (!origsnac || !origsnac->data) {
+    faimdprintf(sess, 0, "parse_userinfo_middle: major problem: no snac stored!\n");
+    return 0;
+  }
+
+  inforeq = (struct aim_priv_inforeq *)origsnac->data;
+
+  if ((inforeq->infotype != AIM_GETINFO_GENERALINFO) &&
+      (inforeq->infotype != AIM_GETINFO_AWAYMESSAGE)) {
+    faimdprintf(sess, 0, "parse_userinfo_middle: unknown infotype in request! (0x%04x)\n", inforeq->infotype);
+    return 0;
+  }
+
+  i = aim_extractuserinfo(sess, data, &userinfo);
+  
+  tlvlist = aim_readtlvchain(data+i, datalen-i);
+
+  /* 
+   * Depending on what informational text was requested, different
+   * TLVs will appear here.
+   *
+   * Profile will be 1 and 2, away message will be 3 and 4.
+   */
+  if (aim_gettlv(tlvlist, 0x0001, 1)) {
+    text_encoding = aim_gettlv_str(tlvlist, 0x0001, 1);
+    text = aim_gettlv_str(tlvlist, 0x0002, 1);
+  } else if (aim_gettlv(tlvlist, 0x0003, 1)) {
+    text_encoding = aim_gettlv_str(tlvlist, 0x0003, 1);
+    text = aim_gettlv_str(tlvlist, 0x0004, 1);
+  }
+
+  if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
+    ret = userfunc(sess, rx, &userinfo, text_encoding, text, inforeq->infotype);
+
+  free(text_encoding);
+  free(text);
+
+  aim_freetlvchain(&tlvlist);
+
+  if (origsnac) {
+    if (origsnac->data)
+      free(origsnac->data);
+    free(origsnac);
+  }
+
+  return ret;
+}
+
+static int snachandler(struct aim_session_t *sess, aim_module_t *mod, struct command_rx_struct *rx, aim_modsnac_t *snac, unsigned char *data, int datalen)
+{
+
+  if (snac->subtype == 0x0003)
+    return rights(sess, mod, rx, snac, data, datalen);
+  else if (snac->subtype == 0x0006)
+    return userinfo(sess, mod, rx, snac, data, datalen);
+
+  return 0;
+}
+
+faim_internal int locate_modfirst(struct aim_session_t *sess, aim_module_t *mod)
+{
+
+  mod->family = 0x0002;
+  mod->version = 0x0000;
+  mod->flags = 0;
+  strncpy(mod->name, "locate", sizeof(mod->name));
+  mod->snachandler = snachandler;
+
+  return 0;
+}
This page took 0.14103 seconds and 4 git commands to generate.