Added id_payload_parse_data function
authorPekka Riikonen <priikone@silcnet.org>
Tue, 10 Oct 2000 07:27:02 +0000 (07:27 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Tue, 10 Oct 2000 07:27:02 +0000 (07:27 +0000)
lib/silccore/silcpayload.c
lib/silccore/silcpayload.h

index 50c409d922386cc120a7c6ea71fb83937102f109..5d2cacabdce0f0c983790841038c6b6f3e53d2d8 100644 (file)
@@ -36,7 +36,7 @@ struct SilcIDPayloadStruct {
   unsigned char *id;
 };
 
-/* Parses data and return ID payload into payload structure */
+/* Parses buffer and return ID payload into payload structure */
 
 SilcIDPayload silc_id_payload_parse(SilcBuffer buffer)
 {
@@ -51,10 +51,11 @@ SilcIDPayload silc_id_payload_parse(SilcBuffer buffer)
                       SILC_STR_UI_SHORT(&new->len),
                       SILC_STR_END);
 
+  silc_buffer_pull(buffer, 4);
+
   if (new->len > buffer->len)
     goto err;
 
-  silc_buffer_pull(buffer, 4);
   silc_buffer_unformat(buffer,
                       SILC_STR_UI_XNSTRING_ALLOC(&new->id, new->len),
                       SILC_STR_END);
@@ -67,6 +68,45 @@ SilcIDPayload silc_id_payload_parse(SilcBuffer buffer)
   return NULL;
 }
 
+/* Parses data and return ID payload into payload structure. */
+
+SilcIDPayload silc_id_payload_parse_data(unsigned char *data, 
+                                        unsigned int len)
+{
+  SilcIDPayload new;
+  SilcBuffer buffer;
+
+  SILC_LOG_DEBUG(("Parsing ID payload"));
+
+  buffer = silc_buffer_alloc(len);
+  silc_buffer_pull_tail(buffer, SILC_BUFFER_END(buffer));
+  silc_buffer_put(buffer, data, len);
+
+  new = silc_calloc(1, sizeof(*new));
+
+  silc_buffer_unformat(buffer,
+                      SILC_STR_UI_SHORT(&new->type),
+                      SILC_STR_UI_SHORT(&new->len),
+                      SILC_STR_END);
+
+  silc_buffer_pull(buffer, 4);
+
+  if (new->len > buffer->len)
+    goto err;
+
+  silc_buffer_unformat(buffer,
+                      SILC_STR_UI_XNSTRING_ALLOC(&new->id, new->len),
+                      SILC_STR_END);
+
+  silc_buffer_free(buffer);
+  return new;
+
+ err:
+  silc_buffer_free(buffer);
+  silc_free(new);
+  return NULL;
+}
+
 /* Encodes ID Payload */
 
 SilcBuffer silc_id_payload_encode(void *id, unsigned short len,
index a880aca1ab2f1f830aff4417c6087eab6dc844b3..1517b2d862105a0ec7edde60cffd88d0966bf221 100644 (file)
@@ -31,6 +31,8 @@ SilcBuffer silc_id_payload_encode(void *id, unsigned short len,
                                  SilcIdType type);
 SilcArgumentPayload silc_argument_payload_parse(SilcBuffer buffer,
                                                unsigned int argc);
+SilcIDPayload silc_id_payload_parse_data(unsigned char *data, 
+                                        unsigned int len);
 void silc_id_payload_free(SilcIDPayload payload);
 SilcIdType silc_id_payload_get_type(SilcIDPayload payload);
 void *silc_id_payload_get_id(SilcIDPayload payload);