Added SilcID to describe any ID.
[runtime.git] / lib / silccore / silcid.c
index 1e5727bc215bd96d94831b3aa7119e9e5b71ff97..027cf6eadd676915845e6de6784b6661a9c92b5a 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 1997 - 2005 Pekka Riikonen
+  Copyright (C) 1997 - 2006 Pekka Riikonen
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
@@ -85,8 +85,7 @@ SilcIDPayload silc_id_payload_parse(const unsigned char *payload,
 /* Return the ID directly from the raw payload data. */
 
 SilcBool silc_id_payload_parse_id(const unsigned char *data, SilcUInt32 len,
-                                 SilcIdType *ret_type, void *ret_id,
-                                 SilcUInt32 ret_id_size)
+                                 SilcID *ret_id)
 {
   SilcBufferStruct buffer;
   SilcIdType type;
@@ -94,6 +93,9 @@ SilcBool silc_id_payload_parse_id(const unsigned char *data, SilcUInt32 len,
   unsigned char *id_data;
   int ret;
 
+  if (!ret_id)
+    return FALSE;
+
   silc_buffer_set(&buffer, (unsigned char *)data, len);
   ret = silc_buffer_unformat(&buffer,
                             SILC_STR_UI_SHORT(&type),
@@ -116,11 +118,21 @@ SilcBool silc_id_payload_parse_id(const unsigned char *data, SilcUInt32 len,
   if (ret == -1)
     goto err;
 
-  if (!silc_id_str2id(id_data, idlen, type, ret_id, ret_id_size))
-    goto err;
-
-  if (ret_type)
-    *ret_type = type;
+  ret_id->type = type;
+
+  if (type == SILC_ID_CLIENT) {
+    if (!silc_id_str2id(id_data, idlen, type, &ret_id->u.client_id,
+                       sizeof(SilcClientID)))
+      goto err;
+  } else if (type == SILC_ID_SERVER) {
+    if (!silc_id_str2id(id_data, idlen, type, &ret_id->u.server_id,
+                       sizeof(SilcServerID)))
+      goto err;
+  } else {
+    if (!silc_id_str2id(id_data, idlen, type, &ret_id->u.channel_id,
+                       sizeof(SilcChannelID)))
+      goto err;
+  }
 
   return TRUE;