]> andersk Git - libfaim.git/commitdiff
- Mon Mar 20 05:30:59 UTC 2000
authormid <mid>
Mon, 20 Mar 2000 05:32:28 +0000 (05:32 +0000)
committermid <mid>
Mon, 20 Mar 2000 05:32:28 +0000 (05:32 +0000)
   - Added some server-only functions for login
   - Added aim_counttlvchain()
   - Added aim_sncmp() and aim_snlen()

CHANGES
aim_conn.c
aim_im.c
aim_login.c
aim_tlv.c
aim_util.c
faim/aim.h

diff --git a/CHANGES b/CHANGES
index b70fa8acb04585dc3452f7393ed581307826c1e9..17068a97b23c7733f239dc9865ba3addd7a546c7 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,11 @@
 
 No release numbers
 ------------------
+ - Mon Mar 20 05:30:59 UTC 2000
+   - Added some server-only functions for login
+   - Added aim_counttlvchain()
+   - Added aim_sncmp() and aim_snlen()
+
  - Sun Mar 19 06:07:52 UTC 2000
    - Added a parameter to aim_select to return event type 
      - REQUIRES CLIENT CHANGES.
index 75ad013c09a1ae7bc0d1fb1ff57bd48576ecbf19..5cb4a79fa14fd88d57b9445a45da3ca9da362a93 100644 (file)
@@ -80,11 +80,17 @@ struct aim_conn_t *aim_newconn(struct aim_session_t *sess,
   char *host = NULL;
   int i=0;
   
-  if (!dest || ((connstruct=aim_conn_getnext(sess))==NULL))
+  if ((connstruct=aim_conn_getnext(sess))==NULL)
     return NULL;
 
   connstruct->type = type;
 
+  if (!dest) { /* just allocate a struct */
+    connstruct->fd = -1;
+    connstruct->status = 0;
+    return connstruct;
+  }
+
   /* 
    * As of 23 Jul 1999, AOL now sends the port number, preceded by a 
    * colon, in the BOS redirect.  This fatally breaks all previous 
index 867750b8944c63ff6a3eb5c504880398ccd30058..3a777faa6819947c2883cdd194b1568658d311cb 100644 (file)
--- a/aim_im.c
+++ b/aim_im.c
@@ -286,6 +286,7 @@ int aim_parse_incoming_im_middle(struct aim_session_t *sess,
        {
          printf("faim: icbm: major error! no message block TLV found!\n");
          aim_freetlvchain(&tlvlist);
+         return 1;
        }
       
       /*
@@ -556,3 +557,5 @@ int aim_parse_msgerror_middle(struct aim_session_t *sess,
 
   return ret;
 }
+
+
index 61992a164687cab5496d078309ad865ee1790a24..2c75d64d7d0d740cef963af6b70fdc7faaa721ea 100644 (file)
@@ -332,3 +332,147 @@ int aim_authparse(struct aim_session_t *sess,
 
   return ret;
 }
+
+/*
+ * Generate an authorization response.  
+ *
+ * You probably don't want this unless you're writing an AIM server.
+ *
+ */
+unsigned long aim_sendauthresp(struct aim_session_t *sess, 
+                              struct aim_conn_t *conn, 
+                              char *sn, char *bosip, 
+                              char *cookie, char *email, 
+                              int regstatus)
+{      
+  struct command_tx_struct tx;
+  struct aim_tlvlist_t *tlvlist = NULL;
+
+  tx.conn = conn;
+
+  tx.commandlen = 1152; /* arbitrarily large */
+  tx.data = malloc(tx.commandlen);
+  memset(tx.data, 0x00, tx.commandlen);
+  
+  tx.lock = 1;
+  tx.type = 0x01; /* XXX: right? */
+
+  if (sn)
+    aim_addtlvtochain_str(&tlvlist, 0x0001, sn, strlen(sn));
+  else
+    aim_addtlvtochain_str(&tlvlist, 0x0001, sess->logininfo.screen_name, strlen(sess->logininfo.screen_name));
+
+  if (sess->logininfo.errorcode) {
+    aim_addtlvtochain16(&tlvlist, 0x0008, sess->logininfo.errorcode);
+    aim_addtlvtochain_str(&tlvlist, 0x0004, sess->logininfo.errorurl, strlen(sess->logininfo.errorurl));
+  } else {
+    aim_addtlvtochain_str(&tlvlist, 0x0005, bosip, strlen(bosip));
+    aim_addtlvtochain_str(&tlvlist, 0x0006, cookie, AIM_COOKIELEN);
+    aim_addtlvtochain_str(&tlvlist, 0x0011, email, strlen(email));
+    aim_addtlvtochain16(&tlvlist, 0x0013, regstatus);
+  }
+
+  tx.commandlen = aim_writetlvchain(tx.data, tx.commandlen, &tlvlist);
+  tx.lock = 0;
+  aim_tx_enqueue(sess, &tx);
+
+  return 0;
+}
+
+/*
+ * Generate a random cookie.  (Non-client use only)
+ */
+int aim_gencookie(unsigned char *buf)
+{
+  int i;
+
+  srand(time(NULL));
+
+  for (i=0; i < AIM_COOKIELEN; i++)
+    buf[i] = 1+(int) (256.0*rand()/(RAND_MAX+0.0));
+
+  return i;
+}
+
+/*
+ * Send Server Ready.  (Non-client)
+ */
+int aim_sendserverready(struct aim_session_t *sess, struct aim_conn_t *conn)
+{
+  struct command_tx_struct tx;
+  int i = 0;
+
+  tx.conn = conn;
+
+  tx.commandlen = 10 + 0x20;
+  tx.data = malloc(tx.commandlen);
+  memset(tx.data, 0x00, tx.commandlen);
+  
+  tx.lock = 1;
+  tx.type = 0x02;
+
+  i += aimutil_put16(tx.data+i, 0x0001);
+  i += aimutil_put16(tx.data+i, 0x0003);
+  i += aimutil_put16(tx.data+i, 0x0000);
+  i += aimutil_put16(tx.data+i, 0x0000);
+  i += aimutil_put16(tx.data+i, 0x0000);
+  
+  i += aimutil_put16(tx.data+i, 0x0001);  
+  i += aimutil_put16(tx.data+i, 0x0002);
+  i += aimutil_put16(tx.data+i, 0x0003);
+  i += aimutil_put16(tx.data+i, 0x0004);
+  i += aimutil_put16(tx.data+i, 0x0006);
+  i += aimutil_put16(tx.data+i, 0x0008);
+  i += aimutil_put16(tx.data+i, 0x0009);
+  i += aimutil_put16(tx.data+i, 0x000a);
+  i += aimutil_put16(tx.data+i, 0x000b);
+  i += aimutil_put16(tx.data+i, 0x000c);
+
+  tx.lock = 0;
+
+  aim_tx_enqueue(sess, &tx);
+
+  return 0;
+}
+
+
+/* 
+ * Send service redirect.  (Non-Client)
+ */
+unsigned long aim_sendredirect(struct aim_session_t *sess, 
+                              struct aim_conn_t *conn, 
+                              unsigned short servid, 
+                              char *ip,
+                              char *cookie)
+{      
+  struct command_tx_struct tx;
+  struct aim_tlvlist_t *tlvlist = NULL;
+  int i = 0;
+
+  tx.conn = conn;
+
+  tx.commandlen = 1152; /* arbitrarily large */
+  tx.data = malloc(tx.commandlen);
+  memset(tx.data, 0x00, tx.commandlen);
+  
+  tx.lock = 1;
+  tx.type = 0x02;
+
+  i += aimutil_put16(tx.data+i, 0x0001);
+  i += aimutil_put16(tx.data+i, 0x0005);
+  i += aimutil_put16(tx.data+i, 0x0000);
+  i += aimutil_put16(tx.data+i, 0x0000);
+  i += aimutil_put16(tx.data+i, 0x0000);
+  
+  aim_addtlvtochain16(&tlvlist, 0x000d, servid);
+  aim_addtlvtochain_str(&tlvlist, 0x0005, ip, strlen(ip));
+  aim_addtlvtochain_str(&tlvlist, 0x0006, cookie, AIM_COOKIELEN);
+
+  tx.commandlen = aim_writetlvchain(tx.data+i, tx.commandlen-i, &tlvlist)+i;
+  aim_freetlvchain(&tlvlist);
+
+  tx.lock = 0;
+  aim_tx_enqueue(sess, &tx);
+
+  return 0;
+}
index 06f1f7a1d5e5ba40aeeb6f1fd5bb624b7bbb7fe0..42d36027ecb00e30990ff0c74a87a9a9bd6056d3 100644 (file)
--- a/aim_tlv.c
+++ b/aim_tlv.c
@@ -67,7 +67,21 @@ void aim_freetlvchain(struct aim_tlvlist_t **list)
   return;
 }
 
-int aim_addtlvtochain_str(struct aim_tlvlist_t **list, unsigned short type, char *str)
+int aim_counttlvchain(struct aim_tlvlist_t **list)
+{
+  struct aim_tlvlist_t *cur;
+  int count = 0;
+
+  if (!list || !(*list))
+    return 0;
+
+  for (cur = *list; cur; cur = cur->next)
+    count++;
+  return count;
+}
+
+int aim_addtlvtochain_str(struct aim_tlvlist_t **list, unsigned short type, char *str, int len)
 {
   struct aim_tlvlist_t *new;
   struct aim_tlvlist_t *cur;
@@ -80,7 +94,7 @@ int aim_addtlvtochain_str(struct aim_tlvlist_t **list, unsigned short type, char
 
   new->tlv = aim_createtlv();  
   new->tlv->type = type;
-  new->tlv->length = strlen(str);
+  new->tlv->length = len;
   new->tlv->value = (u_char *)malloc(new->tlv->length*sizeof(u_char));
   memcpy(new->tlv->value, str, new->tlv->length);
 
index f7cb012021ff01a112e89e143215fc3acd5747e3..0fa8427cc790bf35b63f6d658b6f81a581e22e72 100644 (file)
@@ -5,6 +5,7 @@
  */
 
 #include <faim/aim.h>
+#include <ctype.h>
 
 int aimutil_put8(u_char *buf, u_char data)
 {
@@ -155,3 +156,73 @@ char *aimutil_itemidx(char *toSearch, int index, char dl)
     }
   return toReturn;
 }
+
+/*
+ * int snlen(const char *)
+ * 
+ * This takes a screen name and returns its length without
+ * spaces.  If there are no spaces in the SN, then the 
+ * return is equal to that of strlen().
+ *
+ */
+int aim_snlen(const char *sn)
+{
+  int i = 0;
+  const char *curPtr = NULL;
+
+  if (!sn)
+    return 0;
+
+  curPtr = sn;
+  while ( (*curPtr) != (char) NULL)
+    {
+      if ((*curPtr) != ' ')
+       i++;
+      curPtr++;
+    }
+
+  return i;
+}
+
+/*
+ * int sncmp(const char *, const char *)
+ *
+ * This takes two screen names and compares them using the rules
+ * on screen names for AIM/AOL.  Mainly, this means case and space
+ * insensitivity (all case differences and spacing differences are
+ * ignored).
+ *
+ * Return: 0 if equal
+ *     non-0 if different
+ *
+ */
+
+int aim_sncmp(const char *sn1, const char *sn2)
+{
+  const char *curPtr1 = NULL, *curPtr2 = NULL;
+
+  if (aim_snlen(sn1) != aim_snlen(sn2))
+    return 1;
+
+  curPtr1 = sn1;
+  curPtr2 = sn2;
+  while ( (*curPtr1 != (char) NULL) && (*curPtr2 != (char) NULL) )
+    {
+      if ( (*curPtr1 == ' ') || (*curPtr2 == ' ') )
+       {
+         if (*curPtr1 == ' ')
+           curPtr1++;
+         if (*curPtr2 == ' ')
+           curPtr2++;
+       }
+      else
+       {
+         if ( toupper(*curPtr1) != toupper(*curPtr2))
+             return 1;
+         curPtr1++;
+         curPtr2++;
+       }
+    }
+
+  return 0;
+}
index 96b2059dea4c114fef4845cef50005ad674a8d4d..f67bbb858a840c2940aee7d8e413cb6ee2efd825 100644 (file)
@@ -254,7 +254,9 @@ int aim_puttlv_32(u_char *, u_short, u_long);
 int aim_puttlv_str(u_char *buf, u_short t, u_short l, u_char *v);
 int aim_writetlvchain(u_char *buf, int buflen, struct aim_tlvlist_t **list);
 int aim_addtlvtochain16(struct aim_tlvlist_t **list, unsigned short type, unsigned short val);
-int aim_addtlvtochain_str(struct aim_tlvlist_t **list, unsigned short type, char *str);
+int aim_addtlvtochain32(struct aim_tlvlist_t **list, unsigned short type, unsigned long val);
+int aim_addtlvtochain_str(struct aim_tlvlist_t **list, unsigned short type, char *str, int len);
+int aim_counttlvchain(struct aim_tlvlist_t **list);
 
 /*
  * Get command from connections / Dispatch commands
@@ -278,8 +280,18 @@ int aim_sendconnack(struct aim_session_t *sess, struct aim_conn_t *conn);
 int aim_request_login (struct aim_session_t *sess, struct aim_conn_t *conn, char *sn);
 int aim_send_login (struct aim_session_t *, struct aim_conn_t *, char *, char *, struct client_info_s *);
 int aim_encode_password(const char *, u_char *);
-
-
+unsigned long aim_sendauthresp(struct aim_session_t *sess, 
+                              struct aim_conn_t *conn, 
+                              char *sn, char *bosip, 
+                              char *cookie, char *email, 
+                              int regstatus);
+int aim_gencookie(unsigned char *buf);
+int aim_sendserverready(struct aim_session_t *sess, struct aim_conn_t *conn);
+unsigned long aim_sendredirect(struct aim_session_t *sess, 
+                              struct aim_conn_t *conn, 
+                              unsigned short servid, 
+                              char *ip,
+                              char *cookie);
 void aim_purge_rxqueue(struct aim_session_t *);
 
 
@@ -445,5 +457,8 @@ int aimutil_tokslen(char *toSearch, int index, char dl);
 int aimutil_itemcnt(char *toSearch, char dl);
 char *aimutil_itemidx(char *toSearch, int index, char dl);
 
+int aim_snlen(const char *sn);
+int aim_sncmp(const char *sn1, const char *sn2);
+
 #endif /* __AIM_H__ */
 
This page took 1.134179 seconds and 5 git commands to generate.