- /* Pass the message to application */
- client->ops->channel_message(client, conn, nickname,
- channel->channel_name,
- silc_channel_get_data(payload, NULL));
-
- out:
- if (id)
- silc_free(id);
- if (client_id)
- silc_free(client_id);
- if (payload)
- silc_channel_payload_free(payload);
-}
-
-/* Private message received. This processes the private message and
- finally displays it on the screen. */
-
-void silc_client_private_message(SilcClient client,
- SilcSocketConnection sock,
- SilcPacketContext *packet)
-{
- SilcClientConnection conn = (SilcClientConnection)sock->user_data;
- SilcBuffer buffer = packet->buffer;
- unsigned short nick_len;
- unsigned char *nickname, *message;
- int ret;
-
- /* Get nickname */
- ret = silc_buffer_unformat(buffer,
- SILC_STR_UI16_NSTRING_ALLOC(&nickname, &nick_len),
- SILC_STR_END);
- if (ret == -1)
- return;
-
- silc_buffer_pull(buffer, 2 + nick_len);
-
- message = silc_calloc(buffer->len + 1, sizeof(char));
- memcpy(message, buffer->data, buffer->len);
-
- /* Pass the private message to application */
- client->ops->private_message(client, conn, nickname, 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;
- }