From 9bc7aa726cf320ec4fad29466f884a0db5c89557 Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Wed, 28 Mar 2001 20:57:27 +0000 Subject: [PATCH] updates. --- CHANGES | 14 ++++++- README | 4 ++ TODO | 12 ------ apps/silc/client_ops.c | 25 +++++++++---- apps/silc/client_ops.h | 6 ++- apps/silc/local_command.c | 52 +++++++++++++++++++++++++- apps/silc/local_command.h | 2 + apps/silc/silc.c | 2 +- apps/silcd/packet_receive.c | 12 +++--- apps/silcd/protocol.c | 19 ++++++++-- apps/silcd/testi2.conf | 29 ++++++++------- doc/draft-riikonen-silc-pp-01.nroff | 57 +++++++++++++++++++++++------ lib/silcclient/client_channel.c | 7 +++- lib/silcclient/client_prvmsg.c | 7 +++- lib/silcclient/silcapi.h | 7 +++- lib/silccore/silcchannel.c | 8 ++++ lib/silccore/silcchannel.h | 2 + lib/silccore/silcprivate.c | 28 +++++++------- lib/silccore/silcprivate.h | 8 ++-- 19 files changed, 220 insertions(+), 81 deletions(-) diff --git a/CHANGES b/CHANGES index f603d436..d7dc9102 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,15 @@ +Wed Mar 28 23:55:54 EEST 2001 Pekka Riikonen + + * Added new local command ME to the client. It is used to send + message to a channel with SILC_MESSAGE_FLAG_ACTION to indicate + some action. Affected file silc/local_command.[ch]. + + * Changed channel_message and private_message client operations + to deliver the message flags to the application. Added also + the `flags' arguments to the silc_client_send_channel_message + and silc_client_send_private_message functions. Affected file + silcapi.h. + Wed Mar 28 20:50:47 EEST 2001 Pekka Riikonen * Redefined the Private Message Payload to support private message @@ -18,7 +30,7 @@ Wed Mar 28 20:50:47 EEST 2001 Pekka Riikonen * Defined some of the message (for channel and private message) flags. Updated the protocol specs and added the flags to the - lib/silccore/silcchannel.h. + lib/silccore/silcchannel.h. The type is SilcMessageFlags. Wed Mar 28 15:52:36 EEST 2001 Pekka Riikonen diff --git a/README b/README index 6c0808f1..85b85a37 100644 --- a/README +++ b/README @@ -315,6 +315,10 @@ SILC Commands and port of the remote client's key agreement server. + /ME + + This command is used to send an action to the channel. + This equals to CTCP's ACTION (IRC's /ME) command. Features ======== diff --git a/TODO b/TODO index ee740ec9..ea32c294 100644 --- a/TODO +++ b/TODO @@ -173,18 +173,6 @@ TODO in the protocol before SILC 0.x passphrase or public key that can be used in the authentication when regaining the founder rights. - o New packets and features in the packets - (draft-riikonen-silc-pp-xx.txt): - - o Define the Private Message packet to include private message - flags and define the flags. The flags could indicate whether - the message is, for example autoreply or the receiver should not - reply to the private messages. What other flags? - o Define the Channel Message packet to include channel message - flags and define the flags. Actually the flags should be same - as for the private message flags. This way we can implement - for example the CTCP style ACTION (/ME command) messages. - o New features in the KE/auth protocol (draft-riikonen-silc-ke-auth-xx.txt): diff --git a/apps/silc/client_ops.c b/apps/silc/client_ops.c index 19d675b2..c408656f 100644 --- a/apps/silc/client_ops.c +++ b/apps/silc/client_ops.c @@ -46,24 +46,35 @@ void silc_say(SilcClient client, SilcClientConnection conn, received in the packet. The `channel_name' is the name of the channel. */ void silc_channel_message(SilcClient client, SilcClientConnection conn, - SilcClientEntry sender, SilcChannelEntry channel - , char *msg) + SilcClientEntry sender, SilcChannelEntry channel, + SilcMessageFlags flags, char *msg) { /* Message from client */ if (conn && !strcmp(conn->current_channel->channel_name, channel->channel_name)) - silc_print(client, "<%s> %s", sender ? sender->nickname : "[]", - msg); + if (flags & SILC_MESSAGE_FLAG_ACTION) + silc_print(client, "* %s %s", sender ? sender->nickname : "[]", + msg); + else + silc_print(client, "<%s> %s", sender ? sender->nickname : "[]", + msg); else - silc_print(client, "<%s:%s> %s", sender ? sender->nickname : "[]", - channel->channel_name, msg); + if (flags & SILC_MESSAGE_FLAG_ACTION) + silc_print(client, "* %s:%s %s", sender ? sender->nickname : + "[]", + channel->channel_name, msg); + else + silc_print(client, "<%s:%s> %s", sender ? sender->nickname : + "[]", + channel->channel_name, msg); } /* Private message to the client. The `sender' is the nickname of the sender received in the packet. */ void silc_private_message(SilcClient client, SilcClientConnection conn, - SilcClientEntry sender, char *msg) + SilcClientEntry sender, SilcMessageFlags flags, + char *msg) { silc_print(client, "*%s* %s", sender->nickname, msg); } diff --git a/apps/silc/client_ops.h b/apps/silc/client_ops.h index 2dc68ce1..eb7f8c4f 100644 --- a/apps/silc/client_ops.h +++ b/apps/silc/client_ops.h @@ -24,9 +24,11 @@ void silc_say(SilcClient client, SilcClientConnection conn, char *msg, ...); void silc_channel_message(SilcClient client, SilcClientConnection conn, SilcClientEntry sender, - SilcChannelEntry channel, char *msg); + SilcChannelEntry channel, + SilcMessageFlags flags, char *msg); void silc_private_message(SilcClient client, SilcClientConnection conn, - SilcClientEntry sender, char *msg); + SilcClientEntry sender, + SilcMessageFlags flags, char *msg); void silc_notify(SilcClient client, SilcClientConnection conn, SilcNotifyType type, ...); void silc_command(SilcClient client, SilcClientConnection conn, diff --git a/apps/silc/local_command.c b/apps/silc/local_command.c index 3527a3ff..af7cba4b 100644 --- a/apps/silc/local_command.c +++ b/apps/silc/local_command.c @@ -32,6 +32,7 @@ SilcClientCommand silc_local_command_list[] = SILC_CLIENT_LCMD(msg, MSG, "MSG", 0, 3), SILC_CLIENT_LCMD(away, AWAY, "AWAY", 0, 2), SILC_CLIENT_LCMD(key, KEY, "KEY", 0, 7), + SILC_CLIENT_LCMD(me, ME, "ME", 0, 3), { NULL, 0, NULL, 0, 0 }, }; @@ -131,7 +132,7 @@ SILC_CLIENT_LCMD_FUNC(msg) silc_print(client, "-> *%s* %s", cmd->argv[1], cmd->argv[2]); /* Send the private message */ - silc_client_send_private_message(client, conn, client_entry, + silc_client_send_private_message(client, conn, client_entry, 0, cmd->argv[2], cmd->argv_lens[2], TRUE); @@ -691,3 +692,52 @@ SILC_CLIENT_LCMD_FUNC(key) silc_free(server); silc_client_command_free(cmd); } + +/* Sends an action to the channel. Equals CTCP's ACTION (IRC's /ME) + command. */ + +SILC_CLIENT_LCMD_FUNC(me) +{ + SilcClientCommandContext cmd = (SilcClientCommandContext)context; + SilcClientConnection conn = cmd->conn; + SilcClient client = cmd->client; + SilcChannelEntry channel_entry; + char *name; + + if (!cmd->conn) { + silc_say(client, conn, + "You are not connected to a server, use /SERVER to connect"); + goto out; + } + + if (cmd->argc < 3) { + silc_say(client, conn, "Usage: /ME "); + goto out; + } + + if (cmd->argv[1][0] == '*') { + if (!conn->current_channel) { + cmd->client->ops->say(cmd->client, conn, "You are not on any channel"); + goto out; + } + name = conn->current_channel->channel_name; + } else { + name = cmd->argv[1]; + } + + channel_entry = silc_client_get_channel(client, conn, name); + if (!channel_entry) { + silc_say(client, conn, "You are not on that channel"); + goto out; + } + + /* Send the action message */ + silc_client_send_channel_message(client, conn, channel_entry, NULL, + SILC_MESSAGE_FLAG_ACTION, + cmd->argv[2], cmd->argv_lens[2], TRUE); + + silc_print(client, "* %s %s", conn->nickname, cmd->argv[2]); + + out: + silc_client_command_free(cmd); +} diff --git a/apps/silc/local_command.h b/apps/silc/local_command.h index bd61ae9c..0e4fc3e9 100644 --- a/apps/silc/local_command.h +++ b/apps/silc/local_command.h @@ -32,6 +32,7 @@ extern SilcClientCommand silc_local_command_list[]; #define SILC_LOCAL_COMMAND_MSG 5 #define SILC_LOCAL_COMMAND_AWAY 6 #define SILC_LOCAL_COMMAND_KEY 7 +#define SILC_LOCAL_COMMAND_ME 8 /* Macros */ @@ -53,5 +54,6 @@ SILC_CLIENT_LCMD_FUNC(msg); SILC_CLIENT_LCMD_FUNC(server); SILC_CLIENT_LCMD_FUNC(away); SILC_CLIENT_LCMD_FUNC(key); +SILC_CLIENT_LCMD_FUNC(me); #endif diff --git a/apps/silc/silc.c b/apps/silc/silc.c index ff7e28dc..06f98e2a 100644 --- a/apps/silc/silc.c +++ b/apps/silc/silc.c @@ -567,7 +567,7 @@ static void silc_client_process_message(SilcClientInternal app) silc_client_send_channel_message(app->client, app->conn, app->conn->current_channel, NULL, - data, strlen(data), TRUE); + 0, data, strlen(data), TRUE); } } diff --git a/apps/silcd/packet_receive.c b/apps/silcd/packet_receive.c index ef4a97f4..4cdb7e07 100644 --- a/apps/silcd/packet_receive.c +++ b/apps/silcd/packet_receive.c @@ -1130,7 +1130,8 @@ void silc_server_channel_message(SilcServer server, sock->type == SILC_SOCKET_TYPE_ROUTER && !(channel->mode & SILC_CHANNEL_MODE_PRIVKEY)) { SilcBuffer chp; - unsigned int iv_len, i, data_len; + unsigned int iv_len, i; + unsigned short data_len, flags; iv_len = silc_cipher_get_block_len(channel->channel_key); if (channel->iv[0] == '\0') @@ -1140,12 +1141,13 @@ void silc_server_channel_message(SilcServer server, silc_hash_make(server->md5hash, channel->iv, iv_len, channel->iv); /* Encode new payload. This encrypts it also. */ - SILC_GET16_MSB(data_len, packet->buffer->data); - chp = silc_channel_message_payload_encode(data_len, - packet->buffer->data + 2, + SILC_GET16_MSB(flags, packet->buffer->data); + SILC_GET16_MSB(data_len, packet->buffer->data + 2); + chp = silc_channel_message_payload_encode(flags, data_len, + packet->buffer->data + 4, iv_len, channel->iv, channel->channel_key, - channel->hmac, server->rng); + channel->hmac); silc_buffer_put(packet->buffer, chp->data, chp->len); silc_buffer_free(chp); } diff --git a/apps/silcd/protocol.c b/apps/silcd/protocol.c index cba75ccf..43580638 100644 --- a/apps/silcd/protocol.c +++ b/apps/silcd/protocol.c @@ -599,8 +599,8 @@ SILC_TASK_CALLBACK(silc_server_protocol_connection_auth) /* Get authentication data */ silc_buffer_pull(ctx->packet->buffer, 4); ret = silc_buffer_unformat(ctx->packet->buffer, - SILC_STR_UI_XNSTRING(&auth_data, - payload_len), + SILC_STR_UI_XNSTRING_ALLOC(&auth_data, + payload_len), SILC_STR_END); if (ret == -1) { SILC_LOG_DEBUG(("Bad payload in authentication packet")); @@ -649,6 +649,7 @@ SILC_TASK_CALLBACK(silc_server_protocol_connection_auth) /* Authentication failed */ SILC_LOG_ERROR(("Authentication failed")); SILC_LOG_DEBUG(("Authentication failed")); + silc_free(auth_data); protocol->state = SILC_PROTOCOL_STATE_ERROR; protocol->execute(server->timeout_queue, 0, protocol, fd, 0, 300000); @@ -669,6 +670,7 @@ SILC_TASK_CALLBACK(silc_server_protocol_connection_auth) SILC_LOG_ERROR(("Authentication failed")); SILC_LOG_DEBUG(("Authentication failed")); + silc_free(auth_data); protocol->state = SILC_PROTOCOL_STATE_ERROR; protocol->execute(server->timeout_queue, 0, protocol, fd, 0, 300000); @@ -678,6 +680,7 @@ SILC_TASK_CALLBACK(silc_server_protocol_connection_auth) SILC_LOG_DEBUG(("No configuration for remote connection")); SILC_LOG_ERROR(("Remote connection not configured")); SILC_LOG_ERROR(("Authentication failed")); + silc_free(auth_data); protocol->state = SILC_PROTOCOL_STATE_ERROR; protocol->execute(server->timeout_queue, 0, protocol, fd, 0, 300000); @@ -715,12 +718,13 @@ SILC_TASK_CALLBACK(silc_server_protocol_connection_auth) /* Authentication failed */ SILC_LOG_ERROR(("Authentication failed")); SILC_LOG_DEBUG(("Authentication failed")); + silc_free(auth_data); protocol->state = SILC_PROTOCOL_STATE_ERROR; protocol->execute(server->timeout_queue, 0, protocol, fd, 0, 300000); return; break; - + case SILC_AUTH_PUBLIC_KEY: /* Public key authentication */ SILC_LOG_DEBUG(("Public key authentication")); @@ -735,6 +739,7 @@ SILC_TASK_CALLBACK(silc_server_protocol_connection_auth) SILC_LOG_ERROR(("Authentication failed")); SILC_LOG_DEBUG(("Authentication failed")); + silc_free(auth_data); protocol->state = SILC_PROTOCOL_STATE_ERROR; protocol->execute(server->timeout_queue, 0, protocol, fd, 0, 300000); @@ -747,6 +752,7 @@ SILC_TASK_CALLBACK(silc_server_protocol_connection_auth) protocol->state = SILC_PROTOCOL_STATE_ERROR; protocol->execute(server->timeout_queue, 0, protocol, fd, 0, 300000); + silc_free(auth_data); return; } } @@ -781,6 +787,7 @@ SILC_TASK_CALLBACK(silc_server_protocol_connection_auth) /* Authentication failed */ SILC_LOG_ERROR(("Authentication failed")); SILC_LOG_DEBUG(("Authentication failed")); + silc_free(auth_data); protocol->state = SILC_PROTOCOL_STATE_ERROR; protocol->execute(server->timeout_queue, 0, protocol, fd, 0, 300000); @@ -798,9 +805,10 @@ SILC_TASK_CALLBACK(silc_server_protocol_connection_auth) if (ret) break; - + SILC_LOG_ERROR(("Authentication failed")); SILC_LOG_DEBUG(("Authentication failed")); + silc_free(auth_data); protocol->state = SILC_PROTOCOL_STATE_ERROR; protocol->execute(server->timeout_queue, 0, protocol, fd, 0, 300000); @@ -810,6 +818,7 @@ SILC_TASK_CALLBACK(silc_server_protocol_connection_auth) SILC_LOG_DEBUG(("No configuration for remote connection")); SILC_LOG_ERROR(("Remote connection not configured")); SILC_LOG_ERROR(("Authentication failed")); + silc_free(auth_data); protocol->state = SILC_PROTOCOL_STATE_ERROR; protocol->execute(server->timeout_queue, 0, protocol, fd, 0, 300000); @@ -817,6 +826,8 @@ SILC_TASK_CALLBACK(silc_server_protocol_connection_auth) } } + silc_free(auth_data); + /* Save connection type. This is later used to create the ID for the connection. */ ctx->conn_type = conn_type; diff --git a/apps/silcd/testi2.conf b/apps/silcd/testi2.conf index 0dc9377a..90595798 100644 --- a/apps/silcd/testi2.conf +++ b/apps/silcd/testi2.conf @@ -1,17 +1,23 @@ [Cipher] -rc6:../lib/silcsim/modules/rc6.sim.so:16:16 -twofish:../lib/silcsim/modules/twofish.sim.so:16:16 -mars:../lib/silcsim/modules/mars.sim.so:16:16 +aes-256-cbc:../lib/silcsim/modules/aes.sim.so:32:16 +aes-192-cbc:../lib/silcsim/modules/aes.sim.so:24:16 +aes-128-cbc:../lib/silcsim/modules/aes.sim.so:16:16 +twofish-256-cbc:../lib/silcsim/modules/twofish.sim.so:32:16 +twofish-192-cbc:../lib/silcsim/modules/twofish.sim.so:24:16 +twofish-128-cbc:../lib/silcsim/modules/twofish.sim.so:16:16 +mars-256-cbc:../lib/silcsim/modules/mars.sim.so:32:16 +mars-192-cbc:../lib/silcsim/modules/mars.sim.so:24:16 +mars-128-cbc:../lib/silcsim/modules/mars.sim.so:16:16 none:../lib/silcsim/modules/none.sim.so:0:0 -[Hash] +[Hash] md5::64:16 sha1::64:20 [hmac] hmac-sha1-96:sha1:12 hmac-md5-96:md5:12 -hmac-sha1:sha1:20 +hmac-sha1:sha1:20 hmac-md5:md5:16 #[PKCS] @@ -25,10 +31,10 @@ nobody:nobody Mun huone:Mun servo:Pekka Riikonen:priikone@poseidon.pspt.fi [ServerInfo] -lassi.kuo.fi.ssh.com:10.2.1.7:Kuopio, Finland:1334 +lassi.kuo.fi.ssh.com:212.146.42.253:Kuopio, Finland:1334 [ListenPort] -10.2.1.7:10.2.1.7:1334 +212.146.42.253:212.146.42.253:1334 [Logging] infologfile:silcd2.log:10000 @@ -47,15 +53,12 @@ errorlogfile:silcd2.log:10000 :::1336:1 [AdminConnection] -*:silc:silc:passwd:testi +*:priikone:*:passwd:testi [ServerConnection] -10.2.1.7:passwd:priikone:1333:1:1 +212.146.42.253:passwd:priikone:1336:1:1 [RouterConnection] -10.2.1.7:passwd:priikone:1335:1:1:0 +212.146.42.253:passwd:priikone:1335:1:1:0 [DenyConnection] - -[motd] -./motd diff --git a/doc/draft-riikonen-silc-pp-01.nroff b/doc/draft-riikonen-silc-pp-01.nroff index 65da1422..67b5fb79 100644 --- a/doc/draft-riikonen-silc-pp-01.nroff +++ b/doc/draft-riikonen-silc-pp-01.nroff @@ -1436,8 +1436,8 @@ represents the Channel Message Payload. 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -| Message Length | | -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + +| Flags | Message Length | ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | ~ Message Data ~ | | @@ -1463,6 +1463,39 @@ Figure 12: Channel Message Payload .in 6 +o Flags (2 bytes) - Includes the flags of the channel + messages. The flags can indicate a reason or purpose + for the channel message. Note, that the Private Message + Payload use these same flags for the same purpose. The + following flags are defined: + + 0x0000 SILC_MESSAGE_FLAG_NONE + + No specific flags set. + + 0x0001 SILC_MESSAGE_FLAG_AUTREPLY + + This message is an automatic reply to a earlier + received message. + + 0x0002 SILC_MESSAGE_FLAG_NOREPLY + + There should not be reply messages to this + message. + + 0x0004 SILC_MESSAGE_FLAG_ACTION + + The sender is performing an action and the message + is the indication of the action. + + 0x0008 - 0x0200 RESERVED + + Reserved for future flags + + 0x0400 - 0x8000 PRIVATE RANGE + + Private range for free use. + o Message Length (2 bytes) - Indicates the length of the the Message Data field in the payload, not including any other field. @@ -1634,14 +1667,14 @@ diagram represents the Private Message Payload. 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -| Nickname Length | | -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + +| Flags | Nickname Length | ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | ~ Nickname ~ | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -| Flags | Message Data Length | -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +| Message Data Length | | ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | | ~ Message Data ~ | | @@ -1657,6 +1690,13 @@ Figure 14: Private Message Payload .in 6 +o Flags (2 bytes) - This field includes the flags of the + private message. They can indicate a different reason or + purpose for the private message. See the section 2.3.9 + Channel Message Payload for defined flags. Note, that + the Channel Message Payload use the same flags for the + same purpose. + o Nickname Length (2 bytes) - Indicates the length of the Nickname field, not including any other field. @@ -1668,11 +1708,6 @@ o Nickname (variable length) - Nickname of the sender of the to the Client ID in the SILC Packet Header. This nickname is merely provided to be displayed by the client. -o Flags (2 bytes) - This field includes the flags of the - private message. They can indicate a different reason or - purpose for the private message. See section XXX for the - defined flags. - o Message Data Length (2 bytes) - Indicates the length of the Message Data field, not includes any other field. diff --git a/lib/silcclient/client_channel.c b/lib/silcclient/client_channel.c index bec415ab..26ee63f9 100644 --- a/lib/silcclient/client_channel.c +++ b/lib/silcclient/client_channel.c @@ -36,6 +36,7 @@ void silc_client_send_channel_message(SilcClient client, SilcClientConnection conn, SilcChannelEntry channel, SilcChannelPrivateKey key, + SilcMessageFlags flags, unsigned char *data, unsigned int data_len, int force_send) @@ -98,7 +99,7 @@ void silc_client_send_channel_message(SilcClient client, silc_hash_make(client->md5hash, channel->iv, iv_len, channel->iv); /* Encode the channel payload. This also encrypts the message payload. */ - payload = silc_channel_message_payload_encode(0, data_len, data, iv_len, + payload = silc_channel_message_payload_encode(flags, data_len, data, iv_len, channel->iv, cipher, hmac); /* Get data used in packet header encryption, keys and stuff. */ @@ -233,7 +234,9 @@ void silc_client_channel_message(SilcClient client, /* Pass the message to application */ client->ops->channel_message(client, conn, found ? chu->client : NULL, - channel, message); + channel, + silc_channel_message_get_flags(payload), + message); out: if (id) diff --git a/lib/silcclient/client_prvmsg.c b/lib/silcclient/client_prvmsg.c index 698f51cb..f9f6aa45 100644 --- a/lib/silcclient/client_prvmsg.c +++ b/lib/silcclient/client_prvmsg.c @@ -35,6 +35,7 @@ void silc_client_send_private_message(SilcClient client, SilcClientConnection conn, SilcClientEntry client_entry, + SilcMessageFlags flags, unsigned char *data, unsigned int data_len, int force_send) @@ -48,7 +49,7 @@ void silc_client_send_private_message(SilcClient client, SILC_LOG_DEBUG(("Sending private message")); /* Encode private message payload */ - buffer = silc_private_message_payload_encode(0, strlen(conn->nickname), + buffer = silc_private_message_payload_encode(flags, strlen(conn->nickname), conn->nickname, data_len, data, client_entry->send_key); @@ -172,7 +173,8 @@ void silc_client_private_message(SilcClient client, } /* Pass the private message to application */ - client->ops->private_message(client, conn, remote_client, + client->ops->private_message(client, conn, remote_client, + silc_private_message_get_flags(payload), silc_private_message_get_message(payload, NULL)); @@ -185,6 +187,7 @@ void silc_client_private_message(SilcClient client, /* Send the away message */ silc_client_send_private_message(client, conn, remote_client, + SILC_MESSAGE_FLAG_AUTOREPLY, conn->away->away, strlen(conn->away->away), TRUE); } diff --git a/lib/silcclient/silcapi.h b/lib/silcclient/silcapi.h index b9253518..bdf210bb 100644 --- a/lib/silcclient/silcapi.h +++ b/lib/silcclient/silcapi.h @@ -94,12 +94,13 @@ typedef struct { The `channel' is the channel. */ void (*channel_message)(SilcClient client, SilcClientConnection conn, SilcClientEntry sender, SilcChannelEntry channel, - char *msg); + SilcMessageFlags flags, char *msg); /* Private message to the client. The `sender' is the sender of the message. */ void (*private_message)(SilcClient client, SilcClientConnection conn, - SilcClientEntry sender, char *msg); + SilcClientEntry sender, SilcMessageFlags flags, + char *msg); /* Notify message to the client. The notify arguments are sent in the same order as servers sends them. The arguments are same as received @@ -307,6 +308,7 @@ void silc_client_send_channel_message(SilcClient client, SilcClientConnection conn, SilcChannelEntry channel, SilcChannelPrivateKey key, + SilcMessageFlags flags, unsigned char *data, unsigned int data_len, int force_send); @@ -321,6 +323,7 @@ void silc_client_send_channel_message(SilcClient client, void silc_client_send_private_message(SilcClient client, SilcClientConnection conn, SilcClientEntry client_entry, + SilcMessageFlags flags, unsigned char *data, unsigned int data_len, int force_send); diff --git a/lib/silccore/silcchannel.c b/lib/silccore/silcchannel.c index 5d1dd7d9..d9c19deb 100644 --- a/lib/silccore/silcchannel.c +++ b/lib/silccore/silcchannel.c @@ -396,6 +396,14 @@ void silc_channel_message_payload_free(SilcChannelMessagePayload payload) silc_free(payload); } +/* Return flags */ + +unsigned short +silc_channel_message_get_flags(SilcChannelMessagePayload payload) +{ + return payload->flags; +} + /* Return data */ unsigned char *silc_channel_message_get_data(SilcChannelMessagePayload payload, diff --git a/lib/silccore/silcchannel.h b/lib/silccore/silcchannel.h index 2bd14d10..33422f82 100644 --- a/lib/silccore/silcchannel.h +++ b/lib/silccore/silcchannel.h @@ -78,6 +78,8 @@ SilcBuffer silc_channel_message_payload_encode(unsigned short flags, SilcCipher cipher, SilcHmac hmac); void silc_channel_message_payload_free(SilcChannelMessagePayload payload); +unsigned short +silc_channel_message_get_flags(SilcChannelMessagePayload payload); unsigned char *silc_channel_message_get_data(SilcChannelMessagePayload payload, unsigned int *data_len); unsigned char *silc_channel_message_get_mac(SilcChannelMessagePayload payload); diff --git a/lib/silccore/silcprivate.c b/lib/silccore/silcprivate.c index 45e81d85..41d948e2 100644 --- a/lib/silccore/silcprivate.c +++ b/lib/silccore/silcprivate.c @@ -32,9 +32,9 @@ /* Private Message Payload structure. Contents of this structure is parsed from SILC packets. */ struct SilcPrivateMessagePayloadStruct { + unsigned short flags; unsigned short nickname_len; unsigned char *nickname; - unsigned short flags; unsigned short message_len; unsigned char *message; }; @@ -59,9 +59,9 @@ silc_private_message_payload_parse(SilcBuffer buffer, SilcCipher cipher) /* Parse the Private Message Payload. Ignore the padding. */ ret = silc_buffer_unformat(buffer, + SILC_STR_UI_SHORT(&new->flags), SILC_STR_UI16_NSTRING_ALLOC(&new->nickname, &new->nickname_len), - SILC_STR_UI_SHORT(&new->flags), SILC_STR_UI16_NSTRING_ALLOC(&new->message, &new->message_len), SILC_STR_END); @@ -86,9 +86,9 @@ silc_private_message_payload_parse(SilcBuffer buffer, SilcCipher cipher) the cipher is provided the packet is also encrypted here. It is provided if the private message private keys are used. */ -SilcBuffer silc_private_message_payload_encode(unsigned int nickname_len, +SilcBuffer silc_private_message_payload_encode(unsigned short flags, + unsigned int nickname_len, unsigned char *nickname, - unsigned short flags, unsigned short data_len, unsigned char *data, SilcCipher cipher) @@ -100,7 +100,7 @@ SilcBuffer silc_private_message_payload_encode(unsigned int nickname_len, SILC_LOG_DEBUG(("Encoding private message payload")); - len = 2 + nickname_len + 4 + data_len; + len = 4 + nickname_len + 2 + data_len; if (cipher) { /* Calculate length of padding. */ @@ -117,9 +117,9 @@ SilcBuffer silc_private_message_payload_encode(unsigned int nickname_len, /* Encode the Channel Message Payload */ silc_buffer_pull_tail(buffer, SILC_BUFFER_END(buffer)); silc_buffer_format(buffer, + SILC_STR_UI_SHORT(flags), SILC_STR_UI_SHORT(nickname_len), SILC_STR_UI_XNSTRING(nickname, nickname_len), - SILC_STR_UI_SHORT(flags), SILC_STR_UI_SHORT(data_len), SILC_STR_UI_XNSTRING(data, data_len), SILC_STR_UI_XNSTRING(pad, pad_len), @@ -147,6 +147,14 @@ void silc_private_message_payload_free(SilcPrivateMessagePayload payload) silc_free(payload); } +/* Return flags */ + +unsigned short +silc_private_message_get_flags(SilcPrivateMessagePayload payload) +{ + return payload->flags; +} + /* Return nickname */ unsigned char * @@ -170,11 +178,3 @@ silc_private_message_get_message(SilcPrivateMessagePayload payload, return payload->message; } - -/* Return flags */ - -unsigned short -silc_private_message_get_flags(SilcPrivateMessagePayload payload) -{ - return payload->flags; -} diff --git a/lib/silccore/silcprivate.h b/lib/silccore/silcprivate.h index 4cc2872f..dd8358c6 100644 --- a/lib/silccore/silcprivate.h +++ b/lib/silccore/silcprivate.h @@ -28,20 +28,20 @@ typedef struct SilcPrivateMessagePayloadStruct *SilcPrivateMessagePayload; SilcPrivateMessagePayload silc_private_message_payload_parse(SilcBuffer buffer, SilcCipher cipher); -SilcBuffer silc_private_message_payload_encode(unsigned int nickname_len, +SilcBuffer silc_private_message_payload_encode(unsigned short flags, + unsigned int nickname_len, unsigned char *nickname, - unsigned short flags, unsigned short data_len, unsigned char *data, SilcCipher cipher); void silc_private_message_payload_free(SilcPrivateMessagePayload payload); +unsigned short +silc_private_message_get_flags(SilcPrivateMessagePayload payload); unsigned char * silc_private_message_get_nickname(SilcPrivateMessagePayload payload, unsigned int *nickname_len); unsigned char * silc_private_message_get_message(SilcPrivateMessagePayload payload, unsigned int *message_len); -unsigned short -silc_private_message_get_flags(SilcPrivateMessagePayload payload); #endif -- 2.24.0