X-Git-Url: http://git.silcnet.org/gitweb/?a=blobdiff_plain;f=apps%2Firssi%2Fsrc%2Fsilc%2Fcore%2Fsilc-servers.c;h=0287eb772649ac12d94a9766660881d03276f01b;hb=413da0f8686910f5e627393157566ae729ca99c4;hp=a67fc0b81505b3f58c83248f720ce5bb0c58045a;hpb=fa0904121c6cdc56d0bbc01437a09cf798e2e322;p=silc.git diff --git a/apps/irssi/src/silc/core/silc-servers.c b/apps/irssi/src/silc/core/silc-servers.c index a67fc0b8..0287eb77 100644 --- a/apps/irssi/src/silc/core/silc-servers.c +++ b/apps/irssi/src/silc/core/silc-servers.c @@ -1,14 +1,14 @@ /* silc-server.c : irssi - Copyright (C) 2000 - 2001 Timo Sirainen - Pekka Riikonen + Copyright (C) 2000 - 2003 Timo Sirainen + Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -50,20 +50,20 @@ void silc_servers_reconnect_init(void); void silc_servers_reconnect_deinit(void); -static void silc_send_channel(SILC_SERVER_REC *server, - char *channel, char *msg) +static int silc_send_channel(SILC_SERVER_REC *server, + char *channel, char *msg, + SilcMessageFlags flags) { SILC_CHANNEL_REC *rec; - + rec = silc_channel_find(server, channel); if (rec == NULL || rec->entry == NULL) { - cmd_return_error(CMDERR_NOT_JOINED); - return; + cmd_return_error_value(CMDERR_NOT_JOINED, FALSE); } - silc_client_send_channel_message(silc_client, server->conn, rec->entry, - NULL, SILC_MESSAGE_FLAG_UTF8, - msg, strlen(msg), TRUE); + silc_client_send_channel_message(silc_client, server->conn, rec->entry, + NULL, flags, msg, strlen(msg), TRUE); + return TRUE; } typedef struct { @@ -89,7 +89,7 @@ static void silc_send_msg_clients(SilcClient client, char *nickname = NULL; if (!clients_count) { - printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, + printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "%s: There is no such client", rec->nick); } else { if (clients_count > 1) { @@ -97,11 +97,11 @@ static void silc_send_msg_clients(SilcClient client, /* 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 = silc_client_get_clients_local(silc_client, server->conn, + nickname, rec->nick, &clients_count); if (!clients) { - printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, + printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "%s: There is no such client", rec->nick); silc_free(nickname); goto out; @@ -113,29 +113,29 @@ static void silc_send_msg_clients(SilcClient client, /* Still check for exact math for nickname, this compares the real (formatted) nickname and the nick (maybe formatted) that - use gave. This is to assure that `nick' does not match + use gave. This is to assure that `nick' does not match `nick@host'. */ if (strcasecmp(rec->nick, clients[0]->nickname)) { - printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, + printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "%s: There is no such client", rec->nick); goto out; } /* Send the private message */ - silc_client_send_private_message(client, conn, target, + silc_client_send_private_message(client, conn, target, rec->flags, rec->msg, rec->len, 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, - int msg_len, SilcMessageFlags flags) +static int silc_send_msg(SILC_SERVER_REC *server, char *nick, char *msg, + int msg_len, SilcMessageFlags flags) { PRIVMSG_REC *rec; SilcClientEntry *clients; @@ -145,11 +145,11 @@ static void silc_send_msg(SILC_SERVER_REC *server, char *nick, char *msg, if (!silc_parse_userfqdn(nick, &nickname, NULL)) { printformat_module("fe-common/silc", server, NULL, MSGLEVEL_CRAP, SILCTXT_BAD_NICK, nick); - return; + return FALSE; } /* Find client entry */ - clients = silc_client_get_clients_local(silc_client, server->conn, + clients = silc_client_get_clients_local(silc_client, server->conn, nickname, nick, &clients_count); if (!clients) { rec = g_new0(PRIVMSG_REC, 1); @@ -163,32 +163,37 @@ static void silc_send_msg(SILC_SERVER_REC *server, char *nick, char *msg, silc_client_get_clients(silc_client, server->conn, nickname, NULL, silc_send_msg_clients, rec); silc_free(nickname); - return; + return FALSE; } /* Send the private message directly */ silc_free(nickname); - silc_client_send_private_message(silc_client, server->conn, + silc_client_send_private_message(silc_client, server->conn, clients[0], flags, msg, msg_len, TRUE); + return TRUE; } void silc_send_mime(SILC_SERVER_REC *server, WI_ITEM_REC *to, - const char *data, int data_len, + const char *data, const char *enc, const char *type) { SILC_CHANNEL_REC *channel; QUERY_REC *query; + char *unescaped_data; + SilcUInt32 unescaped_data_len; char *mime_data; int mime_data_len; - - if (!(IS_SILC_SERVER(server)) || (data == NULL) || (to == NULL) || + + if (!(IS_SILC_SERVER(server)) || (data == NULL) || (to == NULL) || (enc == NULL) || (type == NULL)) return; - + + unescaped_data = silc_unescape_data(data, &unescaped_data_len); + #define SILC_MIME_HEADER "MIME-Version: 1.0\r\nContent-Type: %s\r\nContent-Transfer-Encoding: %s\r\n\r\n" - mime_data_len = data_len + strlen(SILC_MIME_HEADER) - 4 + mime_data_len = unescaped_data_len + strlen(SILC_MIME_HEADER) - 4 + strlen(enc) + strlen(type); if (mime_data_len >= SILC_PACKET_MAX_LEN) return; @@ -197,23 +202,24 @@ void silc_send_mime(SILC_SERVER_REC *server, WI_ITEM_REC *to, mime_data = silc_calloc(mime_data_len, sizeof(*mime_data)); snprintf(mime_data, mime_data_len, SILC_MIME_HEADER, type, enc); memmove(mime_data + strlen(SILC_MIME_HEADER) - 4 + strlen(enc) + strlen(type), - data, data_len); + unescaped_data, unescaped_data_len); #undef SILC_MIME_HEADER if (IS_SILC_CHANNEL(to)) { channel = SILC_CHANNEL(to); - silc_client_send_channel_message(silc_client, server->conn, channel->entry, + silc_client_send_channel_message(silc_client, server->conn, channel->entry, NULL, SILC_MESSAGE_FLAG_DATA, mime_data, mime_data_len, TRUE); } else if (IS_SILC_QUERY(to)) { query = SILC_QUERY(to); silc_send_msg(server, query->name, mime_data, mime_data_len, SILC_MESSAGE_FLAG_DATA); - + } silc_free(mime_data); + silc_free(unescaped_data); } static int isnickflag_func(char flag) @@ -249,7 +255,8 @@ static void send_message(SILC_SERVER_REC *server, char *target, } if (target_type == SEND_TARGET_CHANNEL) - silc_send_channel(server, target, message ? message : msg); + silc_send_channel(server, target, message ? message : msg, + SILC_MESSAGE_FLAG_UTF8); else silc_send_msg(server, target, message ? message : msg, message ? strlen(message) : strlen(msg), @@ -258,6 +265,18 @@ static void send_message(SILC_SERVER_REC *server, char *target, silc_free(message); } +void silc_send_heartbeat(SilcSocketConnection sock, + void *hb_context) +{ + SILC_SERVER_REC *server = SILC_SERVER(hb_context); + + if (server == NULL) + return; + + silc_client_send_packet(silc_client, server->conn, SILC_PACKET_HEARTBEAT, + NULL, 0); +} + static void sig_connected(SILC_SERVER_REC *server) { SilcClientConnection conn; @@ -273,6 +292,8 @@ static void sig_connected(SILC_SERVER_REC *server) memset(file, 0, sizeof(file)); snprintf(file, sizeof(file) - 1, "%s/session", get_irssi_dir()); params.detach_data = silc_file_readfile(file, ¶ms.detach_data_len); + if (params.detach_data) + params.detach_data[params.detach_data_len] = 0; /* Add connection to the client library */ conn = silc_client_add_connection(silc_client, ¶ms, @@ -294,6 +315,16 @@ static void sig_connected(SILC_SERVER_REC *server) /* Start key exchange with the server */ silc_client_start_key_exchange(silc_client, conn, fd); + /* Put default attributes */ + silc_query_attributes_default(silc_client, conn); + + /* initialize heartbeat sending */ + if (settings_get_int("heartbeat") > 0) + silc_socket_set_heartbeat(conn->sock, settings_get_int("heartbeat"), + (void *)server, + (SilcSocketConnectionHBCb)silc_send_heartbeat, + silc_client->schedule); + server->ftp_sessions = silc_dlist_init(); server->isnickflag = isnickflag_func; server->ischannel = ischannel_func; @@ -318,36 +349,40 @@ static void sig_disconnected(SILC_SERVER_REC *server) } } -SILC_SERVER_REC *silc_server_connect(SILC_SERVER_CONNECT_REC *conn){ +SERVER_REC *silc_server_init_connect(SERVER_CONNECT_REC *conn) +{ SILC_SERVER_REC *server; g_return_val_if_fail(IS_SILC_SERVER_CONNECT(conn), NULL); - if (conn->address == NULL || *conn->address == '\0') + if (conn->address == NULL || *conn->address == '\0') return NULL; if (conn->nick == NULL || *conn->nick == '\0') { - printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, - "Cannot connect: nickname is not set"); + silc_say_error("Cannot connect: nickname is not set"); return NULL; } server = g_new0(SILC_SERVER_REC, 1); server->chat_type = SILC_PROTOCOL; - server->connrec = conn; - if (server->connrec->port <= 0) + server->connrec = (SILC_SERVER_CONNECT_REC *)conn; + server_connect_ref(conn); + + if (server->connrec->port <= 0) server->connrec->port = 706; - server_connect_ref(SERVER_CONNECT(conn)); + server_connect_init((SERVER_REC *)server); + return (SERVER_REC *)server; +} - if (!server_start_connect((SERVER_REC *) server)) { - server_connect_unref(SERVER_CONNECT(conn)); +void silc_server_connect(SERVER_REC *server) +{ + if (!server_start_connect(server)) { + server_connect_unref(server->connrec); g_free(server); - return NULL; + return; } - - return server; } -/* Return a string of all channels in server in server->channels_join() +/* Return a string of all channels in server in server->channels_join() format */ char *silc_server_get_channels(SILC_SERVER_REC *server) @@ -361,7 +396,7 @@ char *silc_server_get_channels(SILC_SERVER_REC *server) chans = g_string_new(NULL); for (tmp = server->channels; tmp != NULL; tmp = tmp->next) { CHANNEL_REC *channel = tmp->data; - + g_string_sprintfa(chans, "%s,", channel->name); } @@ -370,7 +405,7 @@ char *silc_server_get_channels(SILC_SERVER_REC *server) ret = chans->str; g_string_free(chans, FALSE); - + return ret; } @@ -386,12 +421,12 @@ char *silc_server_get_channels(SILC_SERVER_REC *server) /* SYNTAX: KEY MSG set|unset|list|agreement|negotiate [] */ /* SYNTAX: KEY CHANNEL set|unset|list|change [] */ /* SYNTAX: KICK [@] [] */ -/* SYNTAX: KILL [@] [] */ +/* SYNTAX: KILL [@] [] [-pubkey] */ /* SYNTAX: OPER [-pubkey] */ /* SYNTAX: SILCOPER [-pubkey] */ /* SYNTAX: TOPIC [] */ /* SYNTAX: UMODE +|- */ -/* SYNTAX: WHOIS [@] [] */ +/* SYNTAX: WHOIS [@] [-details] [] */ /* SYNTAX: WHOWAS [@] [] */ /* SYNTAX: CLOSE [] */ /* SYNTAX: SHUTDOWN */ @@ -407,52 +442,27 @@ char *silc_server_get_channels(SILC_SERVER_REC *server) /* SYNTAX: PING */ /* SYNTAX: SCONNECT [] */ /* SYNTAX: USERS */ -/* SYNTAX: FILE SEND [ []] */ -/* SYNTAX: FILE RECEIVE [] */ +/* SYNTAX: FILE SEND [ []] [-no-listener]*/ +/* SYNTAX: FILE ACCEPT [] */ /* SYNTAX: FILE CLOSE [] */ /* SYNTAX: FILE */ -/* SYNTAX: JOIN [] [-cipher ] [-hmac ] [-founder] */ +/* SYNTAX: JOIN [] [-cipher ] [-hmac ] [-founder] [-auth [ []]]*/ /* SYNTAX: DETACH */ /* SYNTAX: WATCH [<-add | -del> ] */ +/* SYNTAX: STATS */ +/* SYNTAX: ATTR [<-del>