X-Git-Url: http://git.silcnet.org/gitweb/?a=blobdiff_plain;f=lib%2Fsilccore%2Fsilcnotify.c;h=c3600c52eefcfe428a40bd0ccefe700c4788f7c2;hb=386c883d8774999c6e74d7c6c37e52e4163a4cb1;hp=bee44cea970677473b0f72062f6ffb1bb983d0bb;hpb=9d68c4cb77f428470b07a3daab1a3188ff4eecdf;p=silc.git diff --git a/lib/silccore/silcnotify.c b/lib/silccore/silcnotify.c index bee44cea..c3600c52 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, + uint32 payload_len) { + SilcBufferStruct buffer; SilcNotifyPayload new; uint16 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; @@ -97,8 +101,7 @@ SilcBuffer silc_notify_payload_encode(SilcNotifyType type, uint32 argc, 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++;