A LOT updates. Cannot separate. :)
[silc.git] / lib / silccore / silcpacket.c
index 3642ddb8434f0add6f1fa0a72c3155a1b15531af..63f179aea402b2d441648286fad2151b35121cf2 100644 (file)
@@ -732,3 +732,37 @@ SilcPacketType silc_packet_parse_special(SilcPacketContext *ctx)
 
   return ctx->type;
 }
+
+/* Duplicates packet context. Duplicates the entire context and its
+   contents. */
+
+SilcPacketContext *silc_packet_context_dup(SilcPacketContext *ctx)
+{
+  SilcPacketContext *new;
+
+  new = silc_calloc(1, sizeof(*new));
+  new->buffer = silc_buffer_copy(ctx->buffer);
+  new->type = ctx->type;
+  new->flags = ctx->flags;
+
+  new->src_id = silc_calloc(ctx->src_id_len, sizeof(*new->src_id));
+  memcpy(new->src_id, ctx->src_id, ctx->src_id_len);
+  new->src_id_len = ctx->src_id_len;
+  new->src_id_type = ctx->src_id_type;
+
+  new->dst_id = silc_calloc(ctx->dst_id_len, sizeof(*new->dst_id));
+  memcpy(new->dst_id, ctx->dst_id, ctx->dst_id_len);
+  new->dst_id_len = ctx->dst_id_len;
+  new->dst_id_type = ctx->dst_id_type;
+
+  new->truelen = ctx->truelen;
+  new->padlen = ctx->padlen;
+
+  new->rng = ctx->rng;
+  new->context = ctx->context;
+  new->sock = ctx->sock;
+
+  return new;
+}
+
+