Integer type name change.
[silc.git] / lib / silccore / silcid.c
index 9a35723a38832fc94ac599558dfe18edc07dc271..655601efffc5ce0ff65afd0b3b6cacc9da204b8c 100644 (file)
 
 struct SilcIDPayloadStruct {
   SilcIdType type;
-  uint16 len;
+  SilcUInt16 len;
   unsigned char *id;
 };
 
 /* Parses buffer and return ID payload into payload structure */
 
 SilcIDPayload silc_id_payload_parse(const unsigned char *payload,
-                                   uint32 payload_len)
+                                   SilcUInt32 payload_len)
 {
   SilcBufferStruct buffer;
   SilcIDPayload new;
@@ -82,11 +82,11 @@ SilcIDPayload silc_id_payload_parse(const unsigned char *payload,
 
 /* Return the ID directly from the raw payload data. */
 
-void *silc_id_payload_parse_id(const unsigned char *data, uint32 len)
+void *silc_id_payload_parse_id(const unsigned char *data, SilcUInt32 len)
 {
   SilcBufferStruct buffer;
   SilcIdType type;
-  uint16 idlen;
+  SilcUInt16 idlen;
   unsigned char *id_data = NULL;
   int ret;
   void *id;
@@ -124,7 +124,7 @@ SilcBuffer silc_id_payload_encode(const void *id, SilcIdType type)
 {
   SilcBuffer buffer;
   unsigned char *id_data;
-  uint32 len;
+  SilcUInt32 len;
 
   id_data = silc_id_id2str(id, type);
   len = silc_id_get_len(id, type);
@@ -135,7 +135,7 @@ SilcBuffer silc_id_payload_encode(const void *id, SilcIdType type)
 }
 
 SilcBuffer silc_id_payload_encode_data(const unsigned char *id,
-                                      uint32 id_len, SilcIdType type)
+                                      SilcUInt32 id_len, SilcIdType type)
 {
   SilcBuffer buffer;
 
@@ -182,19 +182,15 @@ void *silc_id_payload_get_id(SilcIDPayload payload)
 
 unsigned char *silc_id_payload_get_data(SilcIDPayload payload)
 {
-  unsigned char *ret;
-
   if (!payload)
     return NULL;
 
-  ret = silc_calloc(payload->len, sizeof(*ret));
-  memcpy(ret, payload->id, payload->len);
-  return ret;
+  return silc_memdup(payload->id, payload->len);
 }
 
 /* Get length of ID */
 
-uint32 silc_id_payload_get_len(SilcIDPayload payload)
+SilcUInt32 silc_id_payload_get_len(SilcIDPayload payload)
 {
   return payload ? payload->len : 0;
 }
@@ -207,7 +203,7 @@ unsigned char *silc_id_id2str(const void *id, SilcIdType type)
   SilcServerID *server_id;
   SilcClientID *client_id;
   SilcChannelID *channel_id;
-  uint32 id_len = silc_id_get_len(id, type);
+  SilcUInt32 id_len = silc_id_get_len(id, type);
 
   switch(type) {
   case SILC_ID_SERVER:
@@ -241,7 +237,7 @@ unsigned char *silc_id_id2str(const void *id, SilcIdType type)
 
 /* Converts string to a ID */
 
-void *silc_id_str2id(const unsigned char *id, uint32 id_len, SilcIdType type)
+void *silc_id_str2id(const unsigned char *id, SilcUInt32 id_len, SilcIdType type)
 {
 
   switch(type) {
@@ -303,7 +299,7 @@ void *silc_id_str2id(const unsigned char *id, uint32 id_len, SilcIdType type)
 
 /* Returns length of the ID */
 
-uint32 silc_id_get_len(const void *id, SilcIdType type)
+SilcUInt32 silc_id_get_len(const void *id, SilcIdType type)
 {
   switch(type) {
   case SILC_ID_SERVER:
@@ -336,26 +332,20 @@ void *silc_id_dup(const void *id, SilcIdType type)
   switch(type) {
   case SILC_ID_SERVER:
     {
-      SilcServerID *server_id = (SilcServerID *)id, *new;
-      new = silc_calloc(1, sizeof(*server_id));
-      memcpy(new, server_id, sizeof(*server_id));
-      return new;
+      SilcServerID *server_id = (SilcServerID *)id;
+      return silc_memdup(server_id, sizeof(*server_id));
     }
     break;
   case SILC_ID_CLIENT:
     {
-      SilcClientID *client_id = (SilcClientID *)id, *new;
-      new = silc_calloc(1, sizeof(*client_id));
-      memcpy(new, client_id, sizeof(*client_id));
-      return new;
+      SilcClientID *client_id = (SilcClientID *)id;
+      return silc_memdup(client_id, sizeof(*client_id));
     }
     break;
   case SILC_ID_CHANNEL:
     {
-      SilcChannelID *channel_id = (SilcChannelID *)id, *new;
-      new = silc_calloc(1, sizeof(*channel_id));
-      memcpy(new, channel_id, sizeof(*channel_id));
-      return new;
+      SilcChannelID *channel_id = (SilcChannelID *)id;
+      return silc_memdup(channel_id, sizeof(*channel_id));
     }
     break;
   }