+Mon Feb 19 00:50:57 EET 2001 Pekka Riikonen <priikone@poseidon.pspt.fi>
+
+ * Changed the client operation API: channel_message operation's
+ `sender' is now the client entry of the sender, not the nickname
+ and the `channel' is the channel entry, not the channel name.
+
+ In the private_message operation the `sender' is now also the
+ client entry of the sender not the nickname.
+
+ Affected file is lib/silcclient/ops.h and all applications
+ using the client operations.
+
Sat Feb 17 22:11:50 EET 2001 Pekka Riikonen <priikone@poseidon.pspt.fi>
* Moved the calling of ops->connect() from connect_to_server_final
received in the packet. The `channel_name' is the name of the channel. */
void silc_channel_message(SilcClient client, SilcClientConnection conn,
- char *sender, char *channel_name, char *msg)
+ SilcClientEntry sender, SilcChannelEntry channel
+ , char *msg)
{
/* Message from client */
- if (conn && !strcmp(conn->current_channel->channel_name, channel_name))
- silc_print(client, "<%s> %s", sender, msg);
+ if (conn && !strcmp(conn->current_channel->channel_name,
+ channel->channel_name))
+ silc_print(client, "<%s> %s", sender ? sender->nickname : "[<unknown>]",
+ msg);
else
- silc_print(client, "<%s:%s> %s", sender, channel_name, msg);
+ silc_print(client, "<%s:%s> %s", sender ? sender->nickname : "[<unknown>]",
+ 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,
- char *sender, char *msg)
+ SilcClientEntry sender, char *msg)
{
- silc_print(client, "*%s* %s", sender, msg);
+ silc_print(client, "*%s* %s", sender->nickname, msg);
}
void silc_say(SilcClient client, SilcClientConnection conn, char *msg, ...);
void silc_channel_message(SilcClient client, SilcClientConnection conn,
- char *sender, char *channel_name, char *msg);
+ SilcClientEntry sender,
+ SilcChannelEntry channel, char *msg);
void silc_private_message(SilcClient client, SilcClientConnection conn,
- char *sender, char *msg);
+ SilcClientEntry sender, char *msg);
void silc_notify(SilcClient client, SilcClientConnection conn,
SilcNotifyType type, ...);
void silc_command(SilcClient client, SilcClientConnection conn,
SilcChannelUser chu;
SilcIDCacheEntry id_cache = NULL;
SilcClientID *client_id = NULL;
- char *nickname;
+ int found = FALSE;
/* Sanity checks */
if (packet->dst_id_type != SILC_ID_CHANNEL)
if (!payload)
goto out;
- /* Find nickname */
- nickname = "[unknown]";
+ /* Find client entry */
silc_list_start(channel->clients);
while ((chu = silc_list_get(channel->clients)) != SILC_LIST_END) {
if (!SILC_ID_CLIENT_COMPARE(chu->client->id, client_id)) {
- nickname = chu->client->nickname;
+ found = TRUE;
break;
}
}
/* Pass the message to application */
- client->ops->channel_message(client, conn, nickname,
- channel->channel_name,
- silc_channel_get_data(payload, NULL));
+ client->ops->channel_message(client, conn, found ? chu->client : NULL,
+ channel, silc_channel_get_data(payload, NULL));
out:
if (id)
{
SilcClientConnection conn = (SilcClientConnection)sock->user_data;
SilcBuffer buffer = packet->buffer;
+ SilcIDCacheEntry id_cache;
+ SilcClientID *remote_id = NULL;
+ SilcClientEntry remote_client;
unsigned short nick_len;
- unsigned char *nickname, *message;
+ unsigned char *nickname, *message = NULL;
int ret;
+ if (packet->src_id_type != SILC_ID_CLIENT)
+ goto out;
+
/* Get nickname */
ret = silc_buffer_unformat(buffer,
SILC_STR_UI16_NSTRING_ALLOC(&nickname, &nick_len),
message = silc_calloc(buffer->len + 1, sizeof(char));
memcpy(message, buffer->data, buffer->len);
+ remote_id = silc_id_str2id(packet->src_id, packet->src_id_len,
+ SILC_ID_CLIENT);
+ if (!remote_id)
+ goto out;
+
+ /* Check whether we know this client already */
+ if (!silc_idcache_find_by_id_one(conn->client_cache, remote_id,
+ SILC_ID_CLIENT, &id_cache))
+ {
+ /* Allocate client entry */
+ remote_client = silc_calloc(1, sizeof(*remote_client));
+ remote_client->id = remote_id;
+ silc_parse_nickname(nickname, &remote_client->nickname,
+ &remote_client->server, &remote_client->num);
+
+ /* Save the client to cache */
+ silc_idcache_add(conn->client_cache, remote_client->nickname,
+ SILC_ID_CLIENT, remote_client->id, remote_client,
+ TRUE);
+ } else {
+ remote_client = (SilcClientEntry)id_cache->context;
+ }
+
/* Pass the private message to application */
- client->ops->private_message(client, conn, nickname, message);
+ client->ops->private_message(client, conn, remote_client, message);
/* See if we are away (gone). If we are away we will reply to the
sender with the set away message. */
if (conn->away && conn->away->away) {
- SilcClientID *remote_id;
- SilcClientEntry remote_client;
- SilcIDCacheEntry id_cache;
-
- if (packet->src_id_type != SILC_ID_CLIENT)
- goto out;
-
- remote_id = silc_id_str2id(packet->src_id, packet->src_id_len,
- SILC_ID_CLIENT);
- if (!remote_id)
- goto out;
-
/* If it's me, ignore */
if (!SILC_ID_CLIENT_COMPARE(remote_id, conn->local_id))
goto out;
- /* Check whether we know this client already */
- if (!silc_idcache_find_by_id_one(conn->client_cache, remote_id,
- SILC_ID_CLIENT, &id_cache))
- {
- /* Allocate client entry */
- remote_client = silc_calloc(1, sizeof(*remote_client));
- remote_client->id = remote_id;
- silc_parse_nickname(nickname, &remote_client->nickname,
- &remote_client->server, &remote_client->num);
-
- /* Save the client to cache */
- silc_idcache_add(conn->client_cache, remote_client->nickname,
- SILC_ID_CLIENT, remote_client->id, remote_client,
- TRUE);
- } else {
- silc_free(remote_id);
- remote_client = (SilcClientEntry)id_cache->context;
- }
-
/* Send the away message */
silc_client_packet_send_private_message(client, sock, remote_client,
conn->away->away,
}
out:
- memset(message, 0, buffer->len);
- silc_free(message);
+ if (remote_id)
+ silc_free(remote_id);
+
+ if (message) {
+ memset(message, 0, buffer->len);
+ silc_free(message);
+ }
silc_free(nickname);
}
typedef struct {
void (*say)(SilcClient client, SilcClientConnection conn, char *msg, ...);
void (*channel_message)(SilcClient client, SilcClientConnection conn,
- char *sender, char *channel_name, char *msg);
+ SilcClientEntry sender, SilcChannelEntry channel,
+ char *msg);
void (*private_message)(SilcClient client, SilcClientConnection conn,
- char *sender, char *msg);
+ SilcClientEntry sender, char *msg);
void (*notify)(SilcClient client, SilcClientConnection conn,
SilcNotifyType type, ...);
void (*command)(SilcClient client, SilcClientConnection conn,
message to a specific connection. `conn', however, may be NULL.
- void (*channel_message)(client, SilcClientConnection conn,
- char *sender, char *channel_name, char *msg);
+ void (*channel_message)(SilcClient client, SilcClientConnection conn,
+ SilcClientEntry client, SilcChannelEntry channel,
+ char *msg);
- Message for a channel. The `sender' is the nickname of the sender
- received in the packet. The `channel_name' is the name of the channel.
+ Message for a channel. The `sender' is the sender of the message
+ The `channel' is the channel.
- void (*private_message)(client, SilcClientConnection conn,
+ void (*private_message)(SilcClient client, SilcClientConnection conn,
char *sender, char *msg);
- Private message to the client. The `sender' is the nickname of the
- sender received in the packet.
+ Private message to the client. The `sender' is the sender of the
+ message.
void (*notify)(SilcClient client, SilcClientConnection conn, ...);