return buffer;
}
+/* Same as above but encode the buffer from SilcCommandPayload structure
+ instead of raw data. */
+
+SilcBuffer silc_command_payload_encode_payload(SilcCommandPayload payload)
+{
+ SilcBuffer buffer;
+ SilcBuffer args = NULL;
+ unsigned int len = 0;
+ unsigned int argc = 0;
+
+ SILC_LOG_DEBUG(("Encoding command payload"));
+
+ if (payload->args) {
+ args = silc_argument_payload_encode_payload(payload->args);
+ len = args->len;
+ argc = silc_argument_get_arg_num(payload->args);
+ }
+
+ len += SILC_COMMAND_PAYLOAD_LEN;
+ buffer = silc_buffer_alloc(len);
+ silc_buffer_pull_tail(buffer, SILC_BUFFER_END(buffer));
+
+ /* Create Command payload */
+ silc_buffer_format(buffer,
+ SILC_STR_UI_SHORT(len),
+ SILC_STR_UI_CHAR(payload->cmd),
+ SILC_STR_UI_CHAR(argc),
+ SILC_STR_UI_SHORT(payload->ident),
+ SILC_STR_END);
+
+ /* Add arguments */
+ if (args) {
+ silc_buffer_pull(buffer, SILC_COMMAND_PAYLOAD_LEN);
+ silc_buffer_format(buffer,
+ SILC_STR_UI_XNSTRING(args->data, args->len),
+ SILC_STR_END);
+ silc_buffer_push(buffer, SILC_COMMAND_PAYLOAD_LEN);
+ silc_free(args);
+ }
+
+ return buffer;
+}
+
/* Encodes Command 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,
return buffer;
}
+/* Same as above but with va_list. */
+
+SilcBuffer silc_command_payload_encode_vap(SilcCommand cmd,
+ unsigned short ident,
+ 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;
+
+ 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_command_payload_encode(cmd, argc, argv,
+ argv_lens, argv_types, ident);
+
+ for (i = 0; i < argc; i++)
+ silc_free(argv[i]);
+ silc_free(argv);
+ silc_free(argv_lens);
+ silc_free(argv_types);
+
+ return buffer;
+}
+
/* Same as above except that this is used to encode strictly command
reply packets. The command status message to be returned is sent as
extra argument to this function. The `argc' must not count `status'
{
return payload->ident;
}
+
+/* Function to set identifier to already allocated Command Payload. Command
+ payloads are frequentlly resent in SILC and thusly this makes it easy
+ to set the identifier. */
+
+void silc_command_set_ident(SilcCommandPayload payload, unsigned short ident)
+{
+ payload->ident = ident;
+}