- SilcChannelEntry channel = (SilcChannelEntry)context;
- SilcChannelUser chu;
- SILC_SERVER_REC *server = conn->context;
- SILC_CHANNEL_REC *chanrec;
- NICK_REC *ownnick;
-
- if (!clients)
- return;
-
- chanrec = silc_channel_find_entry(server, channel);
- if (chanrec == NULL)
- return;
-
- silc_list_start(channel->clients);
- while ((chu = silc_list_get(channel->clients)) != SILC_LIST_END)
- silc_nicklist_insert(chanrec, chu, FALSE);
-
- ownnick = NICK(silc_nicklist_find(chanrec, conn->local_entry));
- nicklist_set_own(CHANNEL(chanrec), ownnick);
- signal_emit("channel joined", 1, chanrec);
- fe_channels_nicklist(CHANNEL(chanrec), CHANNEL_NICKLIST_FLAG_ALL);
-}
-
-/* Command reply handler. This function is called always in the command reply
- function. If error occurs it will be called as well. Normal scenario
- is that it will be called after the received command data has been parsed
- and processed. The function is used to pass the received command data to
- the application.
-
- `conn' is the associated client connection. `cmd_payload' is the command
- payload data received from server and it can be ignored. It is provided
- if the application would like to re-parse the received command data,
- however, it must be noted that the data is parsed already by the library
- thus the payload can be ignored. `success' is FALSE if error occured.
- In this case arguments are not sent to the application. `command' is the
- command reply being processed. The function has variable argument list
- and each command defines the number and type of arguments it passes to the
- application (on error they are not sent). */
-
-static void
-silc_command_reply(SilcClient client, SilcClientConnection conn,
- SilcCommandPayload cmd_payload, int success,
- SilcCommand command, SilcCommandStatus status, ...)
-
-{
- SILC_SERVER_REC *server = conn->context;
- SILC_CHANNEL_REC *chanrec;
- va_list vp;
-
- va_start(vp, status);
-
- switch(command) {
- case SILC_COMMAND_WHOIS:
- {
- char buf[1024], *nickname, *username, *realname;
- int len;
- uint32 idle, mode;
- SilcBuffer channels;
-
- /* XXX should use irssi routines */
-
- if (status == SILC_STATUS_ERR_NO_SUCH_NICK ||
- status == SILC_STATUS_ERR_NO_SUCH_CLIENT_ID) {
- char *tmp;
- tmp = silc_argument_get_arg_type(silc_command_get_args(cmd_payload),
- 3, NULL);
- if (tmp)
- client->ops->say(client, conn, "%s: %s", tmp,
- silc_client_command_status_message(status));
- else
- client->ops->say(client, conn, "%s",
- silc_client_command_status_message(status));
- break;
- }
-
- if (!success)
- return;
-
- (void)va_arg(vp, SilcClientEntry);
- nickname = va_arg(vp, char *);
- username = va_arg(vp, char *);
- realname = va_arg(vp, char *);
- channels = va_arg(vp, SilcBuffer);
- mode = va_arg(vp, uint32);
- idle = va_arg(vp, uint32);
-
- memset(buf, 0, sizeof(buf));
-
- if (nickname) {
- len = strlen(nickname);
- strncat(buf, nickname, len);
- strncat(buf, " is ", 4);
- }
-
- if (username) {
- strncat(buf, username, strlen(username));
- }
-
- if (realname) {
- strncat(buf, " (", 2);
- strncat(buf, realname, strlen(realname));
- strncat(buf, ")", 1);
- }
-
- client->ops->say(client, conn, "%s", buf);
-
- if (channels) {
- SilcDList list = silc_channel_payload_parse_list(channels);
- if (list) {
- SilcChannelPayload entry;
-
- memset(buf, 0, sizeof(buf));
- strcat(buf, "on channels: ");
-
- silc_dlist_start(list);
- while ((entry = silc_dlist_get(list)) != SILC_LIST_END) {
- char *m = silc_client_chumode_char(silc_channel_get_mode(entry));
- uint32 name_len;
- char *name = silc_channel_get_name(entry, &name_len);
-
- if (m)
- strncat(buf, m, strlen(m));
- strncat(buf, name, name_len);
- strncat(buf, " ", 1);
- silc_free(m);
- }
-
- client->ops->say(client, conn, "%s", buf);
- silc_channel_payload_list_free(list);
- }
- }
-
- if (mode) {
- if ((mode & SILC_UMODE_SERVER_OPERATOR) ||
- (mode & SILC_UMODE_ROUTER_OPERATOR))
- client->ops->say(client, conn, "%s is %s", nickname,
- (mode & SILC_UMODE_SERVER_OPERATOR) ?
- "Server Operator" :
- (mode & SILC_UMODE_ROUTER_OPERATOR) ?
- "SILC Operator" : "[Unknown mode]");
-
- if (mode & SILC_UMODE_GONE)
- client->ops->say(client, conn, "%s is gone", nickname);
- }
-
- if (idle && nickname)
- client->ops->say(client, conn, "%s has been idle %d %s",
- nickname,
- idle > 60 ? (idle / 60) : idle,
- idle > 60 ? "minutes" : "seconds");
- }
- break;
-
- case SILC_COMMAND_WHOWAS:
- {
- char buf[1024], *nickname, *username, *realname;
- int len;
-
- /* XXX should use irssi routines */
-
- if (status == SILC_STATUS_ERR_NO_SUCH_NICK ||
- status == SILC_STATUS_ERR_NO_SUCH_CLIENT_ID) {
- char *tmp;
- tmp = silc_argument_get_arg_type(silc_command_get_args(cmd_payload),
- 3, NULL);
- if (tmp)
- client->ops->say(client, conn, "%s: %s", tmp,
- silc_client_command_status_message(status));
- else
- client->ops->say(client, conn, "%s",
- silc_client_command_status_message(status));
- break;
- }
-
- if (!success)
- return;
-
- (void)va_arg(vp, SilcClientEntry);
- nickname = va_arg(vp, char *);
- username = va_arg(vp, char *);
- realname = va_arg(vp, char *);
-
- memset(buf, 0, sizeof(buf));
-
- if (nickname) {
- len = strlen(nickname);
- strncat(buf, nickname, len);
- strncat(buf, " was ", 5);
- }
-
- if (username) {
- strncat(buf, username, strlen(nickname));
- }
-
- if (realname) {
- strncat(buf, " (", 2);
- strncat(buf, realname, strlen(realname));
- strncat(buf, ")", 1);
- }
-
- client->ops->say(client, conn, "%s", buf);
- }
- break;
-
- case SILC_COMMAND_INVITE:
- {
- SilcChannelEntry channel;
- char *invite_list;
-
- if (!success)
- return;
-
- /* XXX should use irssi routines */
-
- channel = va_arg(vp, SilcChannelEntry);
- invite_list = va_arg(vp, char *);
-
- if (invite_list)
- silc_say(client, conn, "%s invite list: %s", channel->channel_name,
- invite_list);
- else
- silc_say(client, conn, "%s invite list not set",
- channel->channel_name);
- }
- break;
-
- case SILC_COMMAND_JOIN:
- {
- char *channel, *mode, *topic;
- uint32 modei;
- SilcChannelEntry channel_entry;
- SilcBuffer client_id_list;
- uint32 list_count;
-
- channel = va_arg(vp, char *);
- channel_entry = va_arg(vp, SilcChannelEntry);
- modei = va_arg(vp, uint32);
- (void)va_arg(vp, uint32);
- (void)va_arg(vp, unsigned char *);
- (void)va_arg(vp, unsigned char *);
- (void)va_arg(vp, unsigned char *);
- topic = va_arg(vp, char *);
- (void)va_arg(vp, unsigned char *);
- list_count = va_arg(vp, uint32);
- client_id_list = va_arg(vp, SilcBuffer);
-
- if (!success)
- return;
-
- chanrec = silc_channel_find(server, channel);
- if (chanrec != NULL && !success)
- channel_destroy(CHANNEL(chanrec));
- else if (chanrec == NULL && success)
- chanrec = silc_channel_create(server, channel, TRUE);
-
- if (topic) {
- g_free_not_null(chanrec->topic);
- chanrec->topic = *topic == '\0' ? NULL : g_strdup(topic);
- signal_emit("channel topic changed", 1, chanrec);
- silc_say(client, conn, "Topic for %s: %s", channel, topic);