]> andersk Git - libfaim.git/blobdiff - aim_tlv.c
- Thu Sep 14 00:54:48 UTC 2000
[libfaim.git] / aim_tlv.c
index ee260b00eb8a69ba88d8f7d8d952a78909e97551..ba5b1cbb509cbc5f3124673af519add1a19c3a05 100644 (file)
--- a/aim_tlv.c
+++ b/aim_tlv.c
@@ -1,6 +1,6 @@
 #include <faim/aim.h>
 
-struct aim_tlvlist_t *aim_readtlvchain(u_char *buf, int maxlen)
+faim_internal struct aim_tlvlist_t *aim_readtlvchain(u_char *buf, int maxlen)
 {
   int pos;
   struct aim_tlvlist_t *list;
@@ -45,9 +45,11 @@ struct aim_tlvlist_t *aim_readtlvchain(u_char *buf, int maxlen)
 
                cur->tlv = aim_createtlv();     
                cur->tlv->type = type;
-               cur->tlv->length = length;
-               cur->tlv->value = (u_char *)malloc(length*sizeof(u_char));
-               memcpy(cur->tlv->value, buf+pos, length);
+               cur->tlv->length = length; 
+               if (length) {
+                 cur->tlv->value = (unsigned char *)malloc(length);
+                 memcpy(cur->tlv->value, buf+pos, length);
+               } 
 
                cur->next = list;
                list = cur;
@@ -60,7 +62,7 @@ struct aim_tlvlist_t *aim_readtlvchain(u_char *buf, int maxlen)
   return list;
 }
 
-void aim_freetlvchain(struct aim_tlvlist_t **list)
+faim_internal void aim_freetlvchain(struct aim_tlvlist_t **list)
 {
   struct aim_tlvlist_t *cur, *cur2;
 
@@ -79,7 +81,7 @@ void aim_freetlvchain(struct aim_tlvlist_t **list)
   return;
 }
 
-int aim_counttlvchain(struct aim_tlvlist_t **list)
+faim_internal int aim_counttlvchain(struct aim_tlvlist_t **list)
 {
   struct aim_tlvlist_t *cur;
   int count = 0;
@@ -93,100 +95,100 @@ int aim_counttlvchain(struct aim_tlvlist_t **list)
   return count;
 }
 
-int aim_addtlvtochain_str(struct aim_tlvlist_t **list, unsigned short type, char *str, int len)
+faim_internal 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 *newtlv;
   struct aim_tlvlist_t *cur;
 
   if (!list)
     return 0;
 
-  new = (struct aim_tlvlist_t *)malloc(sizeof(struct aim_tlvlist_t));
-  memset(new, 0x00, sizeof(struct aim_tlvlist_t));
+  newtlv = (struct aim_tlvlist_t *)malloc(sizeof(struct aim_tlvlist_t));
+  memset(newtlv, 0x00, sizeof(struct aim_tlvlist_t));
 
-  new->tlv = aim_createtlv();  
-  new->tlv->type = type;
-  new->tlv->length = len;
-  new->tlv->value = (u_char *)malloc(new->tlv->length*sizeof(u_char));
-  memcpy(new->tlv->value, str, new->tlv->length);
+  newtlv->tlv = aim_createtlv();       
+  newtlv->tlv->type = type;
+  newtlv->tlv->length = len;
+  newtlv->tlv->value = (unsigned char *)malloc(newtlv->tlv->length*sizeof(unsigned char));
+  memcpy(newtlv->tlv->value, str, newtlv->tlv->length);
 
-  new->next = NULL;
+  newtlv->next = NULL;
 
   if (*list == NULL) {
-    *list = new;
+    *list = newtlv;
   } else if ((*list)->next == NULL) {
-    (*list)->next = new;
+    (*list)->next = newtlv;
   } else {
     for(cur = *list; cur->next; cur = cur->next)
       ;
-    cur->next = new;
+    cur->next = newtlv;
   }
-  return new->tlv->length;
+  return newtlv->tlv->length;
 }
 
-int aim_addtlvtochain16(struct aim_tlvlist_t **list, unsigned short type, unsigned short val)
+faim_internal int aim_addtlvtochain16(struct aim_tlvlist_t **list, unsigned short type, unsigned short val)
 {
-  struct aim_tlvlist_t *new;
+  struct aim_tlvlist_t *newtl;
   struct aim_tlvlist_t *cur;
 
   if (!list)
     return 0;
 
-  new = (struct aim_tlvlist_t *)malloc(sizeof(struct aim_tlvlist_t));
-  memset(new, 0x00, sizeof(struct aim_tlvlist_t));
+  newtl = (struct aim_tlvlist_t *)malloc(sizeof(struct aim_tlvlist_t));
+  memset(newtl, 0x00, sizeof(struct aim_tlvlist_t));
 
-  new->tlv = aim_createtlv();  
-  new->tlv->type = type;
-  new->tlv->length = 2;
-  new->tlv->value = (u_char *)malloc(new->tlv->length*sizeof(u_char));
-  aimutil_put16(new->tlv->value, val);
+  newtl->tlv = aim_createtlv();        
+  newtl->tlv->type = type;
+  newtl->tlv->length = 2;
+  newtl->tlv->value = (unsigned char *)malloc(newtl->tlv->length*sizeof(unsigned char));
+  aimutil_put16(newtl->tlv->value, val);
 
-  new->next = NULL;
+  newtl->next = NULL;
 
   if (*list == NULL) {
-    *list = new;
+    *list = newtl;
   } else if ((*list)->next == NULL) {
-    (*list)->next = new;
+    (*list)->next = newtl;
   } else {
     for(cur = *list; cur->next; cur = cur->next)
       ;
-    cur->next = new;
+    cur->next = newtl;
   }
   return 2;
 }
 
-int aim_addtlvtochain32(struct aim_tlvlist_t **list, unsigned short type, unsigned long val)
+faim_internal int aim_addtlvtochain32(struct aim_tlvlist_t **list, unsigned short type, unsigned long val)
 {
-  struct aim_tlvlist_t *new;
+  struct aim_tlvlist_t *newtl;
   struct aim_tlvlist_t *cur;
 
   if (!list)
     return 0;
 
-  new = (struct aim_tlvlist_t *)malloc(sizeof(struct aim_tlvlist_t));
-  memset(new, 0x00, sizeof(struct aim_tlvlist_t));
+  newtl = (struct aim_tlvlist_t *)malloc(sizeof(struct aim_tlvlist_t));
+  memset(newtl, 0x00, sizeof(struct aim_tlvlist_t));
 
-  new->tlv = aim_createtlv();  
-  new->tlv->type = type;
-  new->tlv->length = 4;
-  new->tlv->value = (u_char *)malloc(new->tlv->length*sizeof(u_char));
-  aimutil_put32(new->tlv->value, val);
+  newtl->tlv = aim_createtlv();        
+  newtl->tlv->type = type;
+  newtl->tlv->length = 4;
+  newtl->tlv->value = (unsigned char *)malloc(newtl->tlv->length*sizeof(unsigned char));
+  aimutil_put32(newtl->tlv->value, val);
 
-  new->next = NULL;
+  newtl->next = NULL;
 
   if (*list == NULL) {
-    *list = new;
+    *list = newtl;
   } else if ((*list)->next == NULL) {
-    (*list)->next = new;
+    (*list)->next = newtl;
   } else {
     for(cur = *list; cur->next; cur = cur->next)
       ;
-    cur->next = new;
+    cur->next = newtl;
   }
   return 4;
 }
 
-int aim_writetlvchain(u_char *buf, int buflen, struct aim_tlvlist_t **list)
+faim_internal int aim_writetlvchain(u_char *buf, int buflen, struct aim_tlvlist_t **list)
 {
   int goodbuflen = 0;
   int i = 0;
@@ -219,7 +221,7 @@ int aim_writetlvchain(u_char *buf, int buflen, struct aim_tlvlist_t **list)
 /*
  * Grab the Nth TLV of type type in the TLV list list.
  */
-struct aim_tlv_t *aim_gettlv(struct aim_tlvlist_t *list, u_short type, int nth)
+faim_internal struct aim_tlv_t *aim_gettlv(struct aim_tlvlist_t *list, u_short type, int nth)
 {
   int i;
   struct aim_tlvlist_t *cur;
@@ -238,7 +240,7 @@ struct aim_tlv_t *aim_gettlv(struct aim_tlvlist_t *list, u_short type, int nth)
   return NULL;
 }
 
-char *aim_gettlv_str(struct aim_tlvlist_t *list, u_short type, int nth)
+faim_internal char *aim_gettlv_str(struct aim_tlvlist_t *list, u_short type, int nth)
 {
   struct aim_tlv_t *tlv;
   char *newstr;
@@ -253,7 +255,7 @@ char *aim_gettlv_str(struct aim_tlvlist_t *list, u_short type, int nth)
   return newstr;
 }
 
-struct aim_tlv_t *aim_grabtlv(u_char *src)
+faim_internal struct aim_tlv_t *aim_grabtlv(u_char *src)
 {
   struct aim_tlv_t *dest = NULL;
 
@@ -273,7 +275,7 @@ struct aim_tlv_t *aim_grabtlv(u_char *src)
   return dest;
 }
 
-struct aim_tlv_t *aim_grabtlvstr(u_char *src)
+faim_internal struct aim_tlv_t *aim_grabtlvstr(u_char *src)
 {
   struct aim_tlv_t *dest = NULL;
 
@@ -294,7 +296,7 @@ struct aim_tlv_t *aim_grabtlvstr(u_char *src)
   return dest;
 }
 
-int aim_puttlv (u_char *dest, struct aim_tlv_t *newtlv)
+faim_internal int aim_puttlv(u_char *dest, struct aim_tlv_t *newtlv)
 {
   int i=0;
 
@@ -307,7 +309,7 @@ int aim_puttlv (u_char *dest, struct aim_tlv_t *newtlv)
   return i;
 }
 
-struct aim_tlv_t *aim_createtlv(void)
+faim_internal struct aim_tlv_t *aim_createtlv(void)
 {
   struct aim_tlv_t *newtlv = NULL;
   newtlv = (struct aim_tlv_t *)malloc(sizeof(struct aim_tlv_t));
@@ -315,7 +317,7 @@ struct aim_tlv_t *aim_createtlv(void)
   return newtlv;
 }
 
-int aim_freetlv(struct aim_tlv_t **oldtlv)
+faim_internal int aim_freetlv(struct aim_tlv_t **oldtlv)
 {
   if (!oldtlv)
     return -1;
@@ -329,7 +331,7 @@ int aim_freetlv(struct aim_tlv_t **oldtlv)
   return 0;
 }
 
-int aim_puttlv_16(u_char *buf, u_short t, u_short v)
+faim_internal int aim_puttlv_16(u_char *buf, u_short t, u_short v)
 {
   int curbyte=0;
   curbyte += aimutil_put16(buf+curbyte, (u_short)(t&0xffff));
@@ -338,7 +340,7 @@ int aim_puttlv_16(u_char *buf, u_short t, u_short v)
   return curbyte;
 }
 
-int aim_puttlv_32(u_char *buf, u_short t, u_long v)
+faim_internal int aim_puttlv_32(u_char *buf, u_short t, u_long v)
 {
   int curbyte=0;
   curbyte += aimutil_put16(buf+curbyte, (u_short)(t&0xffff));
@@ -347,7 +349,7 @@ int aim_puttlv_32(u_char *buf, u_short t, u_long v)
   return curbyte;
 }
 
-int aim_puttlv_str(u_char *buf, u_short t, u_short l, u_char *v)
+faim_internal int aim_puttlv_str(u_char *buf, u_short t, int l, char *v)
 {
   int curbyte;
   
@@ -355,7 +357,7 @@ int aim_puttlv_str(u_char *buf, u_short t, u_short l, u_char *v)
   curbyte += aimutil_put16(buf+curbyte, (u_short)(t&0xffff));
   curbyte += aimutil_put16(buf+curbyte, (u_short)(l&0xffff));
   if (v)
-    memcpy(buf+curbyte, v, l);
+    memcpy(buf+curbyte, (unsigned char *)v, l);
   curbyte += l;
   return curbyte;
 }
This page took 0.046805 seconds and 4 git commands to generate.