X-Git-Url: http://git.silcnet.org/gitweb/?a=blobdiff_plain;f=lib%2Fsilccore%2Fsilcnotify.c;h=44552d564d1b2352030cb96b5f1dd4c819826eb3;hb=a818c5b5411bbc4436d1c5f011236985c96bb787;hp=a3f54556fa5ed1264509b351f330df1c15df02aa;hpb=72cfa31520ebc0058763a30e21c13f6e9a964aa0;p=silc.git diff --git a/lib/silccore/silcnotify.c b/lib/silccore/silcnotify.c index a3f54556..44552d56 100644 --- a/lib/silccore/silcnotify.c +++ b/lib/silccore/silcnotify.c @@ -36,17 +36,20 @@ struct SilcNotifyPayloadStruct { /* Parse notify payload buffer and return data into payload structure */ -SilcNotifyPayload silc_notify_payload_parse(SilcBuffer buffer) +SilcNotifyPayload silc_notify_payload_parse(const unsigned char *payload, + SilcUInt32 payload_len) { + SilcBufferStruct buffer; SilcNotifyPayload new; - uint16 len; + SilcUInt16 len; int ret; SILC_LOG_DEBUG(("Parsing Notify payload")); + silc_buffer_set(&buffer, (unsigned char *)payload, payload_len); new = silc_calloc(1, sizeof(*new)); - ret = silc_buffer_unformat(buffer, + ret = silc_buffer_unformat(&buffer, SILC_STR_UI_SHORT(&new->type), SILC_STR_UI_SHORT(&len), SILC_STR_UI_CHAR(&new->argc), @@ -54,13 +57,14 @@ SilcNotifyPayload silc_notify_payload_parse(SilcBuffer buffer) if (ret == -1) goto err; - if (len > buffer->len) + if (len > buffer.len) goto err; if (new->argc) { - silc_buffer_pull(buffer, 5); - new->args = silc_argument_payload_parse(buffer, new->argc); - silc_buffer_push(buffer, 5); + silc_buffer_pull(&buffer, 5); + new->args = silc_argument_payload_parse(buffer.data, buffer.len, + new->argc); + silc_buffer_push(&buffer, 5); } return new; @@ -72,33 +76,32 @@ SilcNotifyPayload silc_notify_payload_parse(SilcBuffer buffer) /* Encode notify payload with variable argument list. If `argc' is > 0 argument payloads will be associated to the notify payload. Variable - arguments must be {usigned char *, uint32 (len)}. */ + arguments must be {usigned char *, SilcUInt32 (len)}. */ -SilcBuffer silc_notify_payload_encode(SilcNotifyType type, uint32 argc, +SilcBuffer silc_notify_payload_encode(SilcNotifyType type, SilcUInt32 argc, va_list ap) { SilcBuffer buffer; SilcBuffer args = NULL; unsigned char **argv; - uint32 *argv_lens = NULL, *argv_types = NULL; + SilcUInt32 *argv_lens = NULL, *argv_types = NULL; unsigned char *x; - uint32 x_len; + SilcUInt32 x_len; int i, k = 0, len = 0; if (argc) { argv = silc_calloc(argc, sizeof(unsigned char *)); - argv_lens = silc_calloc(argc, sizeof(uint32)); - argv_types = silc_calloc(argc, sizeof(uint32)); + argv_lens = silc_calloc(argc, sizeof(SilcUInt32)); + argv_types = silc_calloc(argc, sizeof(SilcUInt32)); for (i = 0, k = 0; i < argc; i++) { x = va_arg(ap, unsigned char *); - x_len = va_arg(ap, uint32); + x_len = va_arg(ap, SilcUInt32); if (!x || !x_len) continue; - argv[k] = silc_calloc(x_len + 1, sizeof(unsigned char)); - memcpy(argv[k], x, x_len); + argv[k] = silc_memdup(x, x_len); argv_lens[k] = x_len; argv_types[k] = i + 1; k++; @@ -138,7 +141,7 @@ SilcBuffer silc_notify_payload_encode(SilcNotifyType type, uint32 argc, /* Same as above but takes argument from the `args' Argument Payload. */ SilcBuffer silc_notify_payload_encode_args(SilcNotifyType type, - uint32 argc, + SilcUInt32 argc, SilcBuffer args) { SilcBuffer buffer; @@ -164,7 +167,7 @@ SilcBuffer silc_notify_payload_encode_args(SilcNotifyType type, return buffer; } -/* Free's notify payload */ +/* Frees notify payload */ void silc_notify_payload_free(SilcNotifyPayload payload) { @@ -183,7 +186,7 @@ SilcNotifyType silc_notify_get_type(SilcNotifyPayload payload) /* Return argument nums */ -uint32 silc_notify_get_arg_num(SilcNotifyPayload payload) +SilcUInt32 silc_notify_get_arg_num(SilcNotifyPayload payload) { return payload->argc; }