Author: Pekka Riikonen <priikone@silcnet.org>
- Copyright (C) 1997 - 2005 Pekka Riikonen
+ Copyright (C) 1997 - 2007 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
goto err;
ret = silc_buffer_unformat(&buffer,
- SILC_STR_UI_XNSTRING_ALLOC(&newp->id, newp->len),
+ SILC_STR_DATA_ALLOC(&newp->id, newp->len),
SILC_STR_END);
if (ret == -1)
goto err;
/* 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;
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),
goto err;
ret = silc_buffer_unformat(&buffer,
- SILC_STR_UI_XNSTRING(&id_data, idlen),
+ SILC_STR_DATA(&id_data, idlen),
SILC_STR_END);
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;
silc_buffer_format(buffer,
SILC_STR_UI_SHORT(type),
SILC_STR_UI_SHORT(id_len),
- SILC_STR_UI_XNSTRING(id, id_len),
+ SILC_STR_DATA(id, id_len),
SILC_STR_END);
return buffer;
}
return FALSE;
}
+/* Converts string to ID */
+
+SilcBool silc_id_str2id2(const unsigned char *id, SilcUInt32 id_len,
+ SilcIdType type, SilcID *ret_id)
+{
+ if (!ret_id)
+ return FALSE;
+
+ ret_id->type = type;
+
+ switch (type) {
+ case SILC_ID_CLIENT:
+ return silc_id_str2id(id, id_len, type, &ret_id->u.client_id,
+ sizeof(ret_id->u.client_id));
+ break;
+
+ case SILC_ID_SERVER:
+ return silc_id_str2id(id, id_len, type, &ret_id->u.server_id,
+ sizeof(ret_id->u.server_id));
+ break;
+
+ case SILC_ID_CHANNEL:
+ return silc_id_str2id(id, id_len, type, &ret_id->u.channel_id,
+ sizeof(ret_id->u.channel_id));
+ break;
+ }
+
+ return FALSE;
+}
+
/* Returns length of the ID */
SilcUInt32 silc_id_get_len(const void *id, SilcIdType type)