#include "silc-servers.h"
#include "silc-channels.h"
#include "silc-queries.h"
+#include "silc-nicklist.h"
#include "window-item-def.h"
#include "fe-common/core/printtext.h"
SILC_CHANNEL_REC *rec;
rec = silc_channel_find(server, channel);
- if (rec == NULL)
+ if (rec == NULL || rec->entry == NULL)
return;
silc_client_send_channel_message(silc_client, server->conn, rec->entry,
typedef struct {
char *nick;
char *msg;
+ SILC_SERVER_REC *server;
} PRIVMSG_REC;
/* Callback function that sends the private message if the client was
void *context)
{
PRIVMSG_REC *rec = context;
+ SILC_SERVER_REC *server = rec->server;
SilcClientEntry target;
-
- if (clients_count == 0) {
+ char *nickname = NULL;
+
+ if (!clients_count) {
printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "Unknown nick: %s", rec->nick);
} else {
- target = clients[0]; /* FIXME: not a good idea :) */
-
+ if (clients_count > 1) {
+ silc_parse_userfqdn(rec->nick, &nickname, NULL);
+
+ /* Find the correct one. The rec->nick might be a formatted nick
+ so this will find the correct one. */
+ clients = silc_client_get_clients_local(silc_client, server->conn,
+ nickname, rec->nick,
+ &clients_count);
+ if (!clients) {
+ printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "Unknown nick: %s",
+ rec->nick);
+ silc_free(nickname);
+ goto out;
+ }
+ silc_free(nickname);
+ }
+
+ target = clients[0];
+
+ /* Send the private message */
silc_client_send_private_message(client, conn, target, 0,
rec->msg, strlen(rec->msg),
TRUE);
}
+ out:
g_free(rec->nick);
g_free(rec->msg);
g_free(rec);
static void silc_send_msg(SILC_SERVER_REC *server, char *nick, char *msg)
{
PRIVMSG_REC *rec;
- SilcClientEntry client_entry;
- uint32 num = 0;
- char *nickname = NULL, *serv = NULL;
-
- if (!silc_parse_nickname(nick, &nickname, &serv, &num)) {
+ SilcClientEntry *clients;
+ uint32 clients_count;
+ char *nickname = NULL;
+
+ if (!silc_parse_userfqdn(nick, &nickname, NULL)) {
printformat_module("fe-common/silc", server, NULL,
MSGLEVEL_CRAP, SILCTXT_BAD_NICK, nick);
return;
}
/* Find client entry */
- client_entry = silc_idlist_get_client(silc_client, server->conn,
- nickname, serv, num, FALSE);
- if (!client_entry) {
+ clients = silc_client_get_clients_local(silc_client, server->conn,
+ nickname, nick, &clients_count);
+ silc_free(nickname);
+
+ if (!clients) {
rec = g_new0(PRIVMSG_REC, 1);
rec->nick = g_strdup(nick);
rec->msg = g_strdup(msg);
+ rec->server = server;
/* Could not find client with that nick, resolve it from server. */
silc_client_get_clients(silc_client, server->conn,
- nickname, serv, silc_send_msg_clients, rec);
+ nickname, NULL, silc_send_msg_clients, rec);
return;
}
/* Send the private message directly */
- silc_client_send_private_message(silc_client, server->conn, client_entry, 0,
- msg, strlen(msg), TRUE);
+ silc_client_send_private_message(silc_client, server->conn,
+ clients[0], 0, msg, strlen(msg), TRUE);
}
static int isnickflag_func(char flag)
static void sig_disconnected(SILC_SERVER_REC *server)
{
- if (!IS_SILC_SERVER(server) || server->conn == NULL)
+ if (!IS_SILC_SERVER(server))
return;
- if (server->conn->sock != NULL) {
+ if (server->conn && server->conn->sock != NULL) {
silc_client_close_connection(silc_client, NULL, server->conn);
/* SILC closes the handle */
return ret;
}
+/* Syntaxes of all SILC commands for HELP files (the help file generation
+ will snoop these from here). */
+
+/* SYNTAX: BAN <channel> [+|-[<nickname>[@<server>[!<username>[@hostname>]]]]] */
+/* SYNTAX: CMODE <channel> +|-<modes> [{ <arguments>}] */
+/* SYNTAX: CUMODE <channel> +|-<modes> <nickname>[@<hostname>] [-pubkey|<passwd>] */
+/* SYNTAX: GETKEY <nickname or server name> */
+/* SYNTAX: INVITE <channel> [<nickname>[@hostname>] */
+/* SYNTAX: INVITE <channel> [+|-[<nickname>[@<server>[!<username>[@hostname>]]]]] */
+/* SYNTAX: KEY MSG <nickname> set|unset|list|agreement|negotiate [<arguments>] */
+/* SYNTAX: KEY CHANNEL <channel> set|unset|list|agreement|negotiate [<arguments>] */
+/* SYNTAX: KICK <channel> <nickname>[@<hostname>] [<comment>] */
+/* SYNTAX: KILL <nickname>[@<hostname>] [<comment>] */
+/* SYNTAX: OPER <username> [-pubkey] */
+/* SYNTAX: SILCOPER <username> [-pubkey] */
+/* SYNTAX: TOPIC <channel> [<topic>] */
+/* SYNTAX: UMODE +|-<modes> */
+/* SYNTAX: WHOIS <nickname>[@<hostname>] [<count>] */
+/* SYNTAX: WHOWAS <nickname>[@<hostname>] [<count>] */
+/* SYNTAX: CLOSE <server> [<port>] */
+/* SYNTAX: SHUTDOWN */
+/* SYNTAX: MOTD [<server>] */
+/* SYNTAX: LIST [<channel>] */
+/* SYNTAX: ME <message> */
+/* SYNTAX: ACTION <channel> <message> */
+/* SYNTAX: AWAY [<message>] */
+/* SYNTAX: INFO [<server>] */
+/* SYNTAX: NICK <nickname> */
+/* SYNTAX: NOTICE <message> */
+/* SYNTAX: PART [<channel>] */
+/* SYNTAX: PING */
+/* SYNTAX: SCONNECT <server> [<port>] */
+/* SYNTAX: USERS <channel> */
+
void silc_command_exec(SILC_SERVER_REC *server,
const char *command, const char *args)
{
ctx->argv_types = argv_types;
/* Execute command */
- (*cmd->cb)(ctx);
+ (*cmd->cb)(ctx, NULL);
}
/* Generic command function to call any SILC command directly. */
-static void command_self(const char *data, SILC_SERVER_REC *server)
+static void command_self(const char *data, SILC_SERVER_REC *server,
+ WI_ITEM_REC *item)
{
if (!IS_SILC_SERVER(server) || !server->connected) {
printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "Not connected to server");
return;
}
+ if (IS_SILC_CHANNEL(item)) {
+ SILC_CHANNEL_REC *chanrec;
+ chanrec = silc_channel_find(server, item->name);
+ if (chanrec)
+ server->conn->current_channel = chanrec->entry;
+ }
+
silc_command_exec(server, current_command, data);
signal_stop();
}
signal_stop();
}
+typedef struct {
+ SILC_SERVER_REC *server;
+ char *data;
+ WI_ITEM_REC *item;
+} *FileGetClients;
+
+SILC_CLIENT_CMD_FUNC(file_get_clients)
+{
+ FileGetClients internal = (FileGetClients)context;
+ signal_emit("command file", 3, internal->data, internal->server,
+ internal->item);
+ silc_free(internal->data);
+ silc_free(internal);
+}
+
+static void command_file(const char *data, SILC_SERVER_REC *server,
+ WI_ITEM_REC *item)
+{
+ SilcClientConnection conn;
+ SilcClientEntry client_entry;
+ char *nickname, *tmp;
+ unsigned char **argv;
+ uint32 argc;
+ uint32 *argv_lens, *argv_types;
+ int type;
+
+ if (!server || !IS_SILC_SERVER(server) || !server->connected)
+ cmd_return_error(CMDERR_NOT_CONNECTED);
+
+ conn = server->conn;
+
+ /* Now parse all arguments */
+ tmp = g_strconcat("KEY", " ", data, NULL);
+ silc_parse_command_line(tmp, &argv, &argv_lens, &argv_types, &argc, 4);
+ g_free(tmp);
+
+ type = 0;
+ if (!strcasecmp(argv[1], "send"))
+ type = 1;
+ if (!strcasecmp(argv[1], "receive"))
+ type = 2;
+
+ /* Parse the typed nickname. */
+ if (!silc_parse_userfqdn(argv[3], &nickname, NULL)) {
+ printformat_module("fe-common/silc", server, NULL,
+ MSGLEVEL_CRAP, SILCTXT_BAD_NICK, argv[2]);
+ return;
+ }
+
+ /* Find client entry */
+ client_entry = silc_idlist_get_client(silc_client, conn, nickname,
+ argv[3], TRUE);
+ if (!client_entry) {
+ FileGetClients inter = silc_calloc(1, sizeof(*inter));
+ inter->server = server;
+ inter->data = strdup(data);
+ inter->item = item;
+
+ /* Client entry not found, it was requested thus mark this to be
+ pending command. */
+ silc_client_command_pending(conn, SILC_COMMAND_IDENTIFY,
+ conn->cmd_ident,
+ NULL, silc_client_command_file_get_clients,
+ inter);
+ goto out;
+ }
+
+ switch (type) {
+ case 1:
+ silc_client_file_send(silc_client, conn, NULL, NULL, client_entry,
+ argv[2]);
+ break;
+
+ case 2:
+ break;
+
+ default:
+ break;
+ }
+
+ out:
+ silc_free(nickname);
+}
+
void silc_server_init(void)
{
silc_servers_reconnect_init();
command_bind("shutdown", MODULE_NAME, (SIGNAL_FUNC) command_self);
command_bind("getkey", MODULE_NAME, (SIGNAL_FUNC) command_self);
command_bind("sconnect", MODULE_NAME, (SIGNAL_FUNC) command_sconnect);
+ command_bind("file", MODULE_NAME, (SIGNAL_FUNC) command_file);
command_set_options("connect", "+silcnet");
}
command_unbind("shutdown", (SIGNAL_FUNC) command_self);
command_unbind("getkey", (SIGNAL_FUNC) command_self);
command_unbind("sconnect", (SIGNAL_FUNC) command_sconnect);
+ command_unbind("file", (SIGNAL_FUNC) command_file);
}