From: Pekka Riikonen Date: Sun, 18 Feb 2001 22:49:05 +0000 (+0000) Subject: updates. X-Git-Tag: SILC.0.1~211 X-Git-Url: http://git.silcnet.org/gitweb/?a=commitdiff_plain;h=74debe93b0a49dac4d17bfff53b60a6c95e015cc;p=silc.git updates. --- diff --git a/CHANGES b/CHANGES index f4e6ed1b..14b9cebd 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,15 @@ +Mon Feb 19 00:50:57 EET 2001 Pekka Riikonen + + * 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 * Moved the calling of ops->connect() from connect_to_server_final diff --git a/apps/silc/client_ops.c b/apps/silc/client_ops.c index cb730293..d87393a7 100644 --- a/apps/silc/client_ops.c +++ b/apps/silc/client_ops.c @@ -46,22 +46,26 @@ 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, - 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 : "[]", + msg); else - silc_print(client, "<%s:%s> %s", sender, channel_name, msg); + 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, - char *sender, char *msg) + SilcClientEntry sender, char *msg) { - silc_print(client, "*%s* %s", sender, msg); + silc_print(client, "*%s* %s", sender->nickname, msg); } diff --git a/apps/silc/client_ops.h b/apps/silc/client_ops.h index db8f1af9..7d58937f 100644 --- a/apps/silc/client_ops.h +++ b/apps/silc/client_ops.h @@ -23,9 +23,10 @@ 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, diff --git a/lib/silcclient/client.c b/lib/silcclient/client.c index 29a352f7..b40bd47f 100644 --- a/lib/silcclient/client.c +++ b/lib/silcclient/client.c @@ -1996,7 +1996,7 @@ void silc_client_channel_message(SilcClient client, 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) @@ -2030,20 +2030,18 @@ void silc_client_channel_message(SilcClient client, 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) @@ -2063,10 +2061,16 @@ void silc_client_private_message(SilcClient client, { 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), @@ -2079,47 +2083,39 @@ void silc_client_private_message(SilcClient client, 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, @@ -2127,8 +2123,13 @@ void silc_client_private_message(SilcClient client, } 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); } diff --git a/lib/silcclient/ops.h b/lib/silcclient/ops.h index 5c619192..648a8121 100644 --- a/lib/silcclient/ops.h +++ b/lib/silcclient/ops.h @@ -34,9 +34,10 @@ 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, @@ -70,18 +71,19 @@ typedef struct { 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, ...);