/*
* $Id$
* $Log$
+ * Revision 1.3 2000/07/06 07:11:06 priikone
+ * Removed status paylaod encoding functions -> not needed anymore.
+ * Added encode_reply_payload_va to encode reply packets only.
+ * Normal encode_payload_va accepts now argument type as variable
+ * argument as well.
+ *
* Revision 1.2 2000/07/05 06:06:35 priikone
* Global cosmetic change.
*
}
/* Encodes Command payload with variable argument list. The arguments
- must be: unsigned char *, unsigned int, ... One unsigned char *
- and unsigned int forms one argument, hence `argc' in case when
- sending one 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. */
+ 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(SilcCommand cmd,
unsigned int argc, ...)
unsigned int *argv_lens = NULL, *argv_types = NULL;
unsigned char *x;
unsigned int x_len;
+ unsigned int x_type;
SilcBuffer buffer;
int i;
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] = i + 1;
+ argv_types[i] = x_type;
+ }
+
+ buffer = silc_command_encode_payload(cmd, 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;
+}
+
+/* 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'
+ as on argument. */
+
+SilcBuffer
+silc_command_encode_reply_payload_va(SilcCommand cmd,
+ SilcCommandStatus status,
+ unsigned int argc, ...)
+{
+ va_list ap;
+ unsigned char **argv;
+ unsigned int *argv_lens = NULL, *argv_types = NULL;
+ unsigned char status_data[2];
+ unsigned char *x;
+ unsigned int x_len;
+ unsigned int x_type;
+ SilcBuffer buffer;
+ int i;
+
+ va_start(ap, argc);
+
+ argc++;
+ argv = silc_calloc(argc, sizeof(unsigned char *));
+ argv_lens = silc_calloc(argc, sizeof(unsigned int));
+ argv_types = silc_calloc(argc, sizeof(unsigned int));
+
+ SILC_PUT16_MSB(status, status_data);
+ argv[0] = silc_calloc(sizeof(status_data) + 1, sizeof(unsigned char));
+ memcpy(argv[0], status_data, sizeof(status_data));
+ argv_lens[0] = sizeof(status_data);
+ argv_types[0] = 1;
+
+ for (i = 1; 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_encode_payload(cmd, argc, argv,
return payload->argv[i];
}
-
-/* Encodes command status payload. Status payload is sent as one reply
- argument. The returned payload still has to be saved into the
- Command Argument payload. */
-
-SilcBuffer silc_command_encode_status_payload(SilcCommandStatus status,
- unsigned char *data,
- unsigned int len)
-{
- SilcBuffer sp;
-
- sp = silc_buffer_alloc(len + 2);
- silc_buffer_pull_tail(sp, SILC_BUFFER_END(sp));
- silc_buffer_format(sp,
- SILC_STR_UI_SHORT(status),
- SILC_STR_UI_XNSTRING(data, len),
- SILC_STR_END);
-
- return sp;
-}