SilcIDPayload silc_id_payload_parse(SilcBuffer buffer)
{
SilcIDPayload new;
+ int ret;
SILC_LOG_DEBUG(("Parsing ID payload"));
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);
+ ret = silc_buffer_unformat(buffer,
+ SILC_STR_UI_SHORT(&new->type),
+ SILC_STR_UI_SHORT(&new->len),
+ SILC_STR_END);
+ if (ret == -1)
+ goto err;
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);
+ ret = silc_buffer_unformat(buffer,
+ SILC_STR_UI_XNSTRING_ALLOC(&new->id, new->len),
+ SILC_STR_END);
+ if (ret == -1)
+ goto err;
+
silc_buffer_push(buffer, 4);
return new;
{
SilcIDPayload new;
SilcBuffer buffer;
+ int ret;
SILC_LOG_DEBUG(("Parsing ID payload"));
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);
+ ret = silc_buffer_unformat(buffer,
+ SILC_STR_UI_SHORT(&new->type),
+ SILC_STR_UI_SHORT(&new->len),
+ SILC_STR_END);
+ if (ret == -1)
+ goto err;
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);
+ ret = silc_buffer_unformat(buffer,
+ SILC_STR_UI_XNSTRING_ALLOC(&new->id, new->len),
+ SILC_STR_END);
+ if (ret == -1)
+ goto err;
silc_buffer_free(buffer);
return new;
SilcIdType type;
unsigned short idlen;
unsigned char *id;
+ int ret;
buffer = silc_buffer_alloc(len);
silc_buffer_pull_tail(buffer, SILC_BUFFER_END(buffer));
silc_buffer_put(buffer, data, len);
- silc_buffer_unformat(buffer,
- SILC_STR_UI_SHORT(&type),
- SILC_STR_UI_SHORT(&idlen),
- SILC_STR_END);
+ ret = silc_buffer_unformat(buffer,
+ SILC_STR_UI_SHORT(&type),
+ SILC_STR_UI_SHORT(&idlen),
+ SILC_STR_END);
+ if (ret == -1)
+ goto err;
silc_buffer_pull(buffer, 4);
if (idlen > buffer->len)
goto err;
- silc_buffer_unformat(buffer,
- SILC_STR_UI_XNSTRING_ALLOC(&id, idlen),
- SILC_STR_END);
+ ret = silc_buffer_unformat(buffer,
+ SILC_STR_UI_XNSTRING_ALLOC(&id, idlen),
+ SILC_STR_END);
+ if (ret == -1)
+ goto err;
silc_buffer_free(buffer);
- return silc_id_str2id(id, type);
+ return silc_id_str2id(id, idlen, type);
err:
silc_buffer_free(buffer);
void *silc_id_payload_get_id(SilcIDPayload payload)
{
- return silc_id_str2id(payload->id, payload->type);
+ return silc_id_str2id(payload->id, payload->len, payload->type);
}
/* Get raw ID data. Data is duplicated. */
unsigned char arg_num = 0;
unsigned char arg_type = 0;
unsigned int pull_len = 0;
- int i = 0;
+ int i = 0, ret;
SILC_LOG_DEBUG(("Parsing argument payload"));
/* Get arguments */
arg_num = 1;
for (i = 0; i < argc; i++) {
- silc_buffer_unformat(buffer,
- SILC_STR_UI_SHORT(&payload_len),
- SILC_STR_UI_CHAR(&arg_type),
- SILC_STR_END);
+ ret = silc_buffer_unformat(buffer,
+ SILC_STR_UI_SHORT(&payload_len),
+ SILC_STR_UI_CHAR(&arg_type),
+ SILC_STR_END);
+ if (ret == -1)
+ goto err;
new->argv_lens[i] = payload_len;
new->argv_types[i] = arg_type;
/* Get argument data */
silc_buffer_pull(buffer, 3);
- silc_buffer_unformat(buffer,
- SILC_STR_UI_XNSTRING_ALLOC(&new->argv[i],
- payload_len),
- SILC_STR_END);
+ ret = silc_buffer_unformat(buffer,
+ SILC_STR_UI_XNSTRING_ALLOC(&new->argv[i],
+ payload_len),
+ SILC_STR_END);
+ if (ret == -1)
+ goto err;
silc_buffer_pull(buffer, payload_len);
pull_len += 3 + payload_len;
return buffer;
}
-#if 0
-/* Encodes Argument payload with variable argument list. The arguments
- must be: unsigned int, unsigned char *, unsigned int, ... One
- {unsigned int, unsigned char * and unsigned int} forms one argument,
- thus `argc' in case when sending one {unsigned int, unsigned char *
- and unsigned int} equals one (1) and when sending two of those it
- equals two (2), and so on. This has to be preserved or bad things
- will happen. The variable arguments is: {type, data, data_len}. */
-
-SilcBuffer silc_command_encode_payload_va(unsigned int argc, ...)
-{
- va_list ap;
- unsigned char **argv;
- unsigned int *argv_lens = NULL, *argv_types = NULL;
- unsigned char *x;
- unsigned int x_len;
- unsigned int x_type;
- SilcBuffer buffer;
- int i;
-
- va_start(ap, argc);
-
- argv = silc_calloc(argc, sizeof(unsigned char *));
- argv_lens = silc_calloc(argc, sizeof(unsigned int));
- argv_types = silc_calloc(argc, sizeof(unsigned int));
-
- for (i = 0; i < argc; i++) {
- x_type = va_arg(ap, unsigned int);
- x = va_arg(ap, unsigned char *);
- x_len = va_arg(ap, unsigned int);
-
- argv[i] = silc_calloc(x_len + 1, sizeof(unsigned char));
- memcpy(argv[i], x, x_len);
- argv_lens[i] = x_len;
- argv_types[i] = x_type;
- }
-
- buffer = silc_argument_payload_encode(argc, argv,
- argv_lens, argv_types);
-
- for (i = 0; i < argc; i++)
- silc_free(argv[i]);
- silc_free(argv);
- silc_free(argv_lens);
- silc_free(argv_types);
-
- return buffer;
-}
-#endif
-
/* Free's Command Payload */
void silc_argument_payload_free(SilcArgumentPayload payload)