Merge Irssi 0.8.16-rc1
[silc.git] / apps / irssi / src / core / session.c
index 40c4f5474938848d41100f3e2a4f75b8d67afd93..b3002632952ef6214344dd628ca8ed749ebbffe7 100644 (file)
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.
 
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+    You should have received a copy of the GNU General Public License along
+    with this program; if not, write to the Free Software Foundation, Inc.,
+    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
 
 #include "module.h"
 #include "signals.h"
 #include "commands.h"
 #include "args.h"
+#include "network.h"
 #include "net-sendbuffer.h"
 #include "pidwait.h"
 #include "lib-config/iconfig.h"
 #include "nicklist.h"
 
 static char *session_file;
-static char *irssi_binary;
+char *irssi_binary = NULL;
 
 static char **session_args;
 
 void session_set_binary(const char *path)
 {
-       const char *envpath;
-       char **paths, **tmp;
-        char *str;
-
        g_free_and_null(irssi_binary);
 
-       if (g_path_is_absolute(path)) {
-                /* full path - easy */
-               irssi_binary = g_strdup(path);
-                return;
-       }
-
-       if (strchr(path, G_DIR_SEPARATOR) != NULL) {
-               /* relative path */
-                str = g_get_current_dir();
-               irssi_binary = g_strconcat(str, G_DIR_SEPARATOR_S, path, NULL);
-               g_free(str);
-                return;
-       }
-
-       /* we'll need to find it from path. */
-       envpath = g_getenv("PATH");
-       if (envpath == NULL) return;
-
-       paths = g_strsplit(envpath, ":", -1);
-       for (tmp = paths; *tmp != NULL; tmp++) {
-                str = g_strconcat(*tmp, G_DIR_SEPARATOR_S, path, NULL);
-               if (access(str, X_OK) == 0) {
-                       irssi_binary = str;
-                        break;
-               }
-                g_free(str);
-       }
-       g_strfreev(paths);
+       irssi_binary = g_find_program_in_path(path);
 }
 
 void session_upgrade(void)
@@ -80,7 +50,7 @@ void session_upgrade(void)
        if (session_args == NULL)
                 return;
 
-       execvp(session_args[0], session_args);
+       execv(session_args[0], session_args);
        fprintf(stderr, "exec failed: %s: %s\n",
                session_args[0], g_strerror(errno));
 }
@@ -90,11 +60,13 @@ static void cmd_upgrade(const char *data)
 {
        CONFIG_REC *session;
        char *session_file, *str;
+       char *binary;
 
        if (*data == '\0')
                data = irssi_binary;
-       if (data == NULL)
-                cmd_return_error(CMDERR_NOT_ENOUGH_PARAMS);
+
+       if ((binary = g_find_program_in_path(data)) == NULL)
+               cmd_return_error(CMDERR_PROGRAM_NOT_FOUND);
 
        /* save the session */
         session_file = g_strdup_printf("%s/session", get_irssi_dir());
@@ -108,7 +80,9 @@ static void cmd_upgrade(const char *data)
        /* data may contain some other program as well, like
           /UPGRADE /usr/bin/screen irssi */
        str = g_strdup_printf("%s --noconnect --session=%s --home=%s --config=%s",
-                             data, session_file, get_irssi_dir(), get_irssi_config());
+                             binary, session_file, get_irssi_dir(), get_irssi_config());
+       g_free(binary);
+       g_free(session_file);
         session_args = g_strsplit(str, " ", -1);
         g_free(str);
 
@@ -125,6 +99,8 @@ static void session_save_nick(CHANNEL_REC *channel, NICK_REC *nick,
        config_node_set_bool(config, node, "halfop", nick->halfop);
        config_node_set_bool(config, node, "voice", nick->voice);
 
+       config_node_set_str(config, node, "prefixes", nick->prefixes);
+
        signal_emit("session save nick", 4, channel, nick, config, node);
 }
 
@@ -181,8 +157,14 @@ static void session_save_server(SERVER_REC *server, CONFIG_REC *config,
        config_node_set_str(config, node, "chatnet", server->connrec->chatnet);
        config_node_set_str(config, node, "password", server->connrec->password);
        config_node_set_str(config, node, "nick", server->nick);
+       config_node_set_str(config, node, "version", server->version);
 
        config_node_set_bool(config, node, "use_ssl", server->connrec->use_ssl);
+       config_node_set_str(config, node, "ssl_cert", server->connrec->ssl_cert);
+       config_node_set_str(config, node, "ssl_pkey", server->connrec->ssl_pkey);
+       config_node_set_bool(config, node, "ssl_verify", server->connrec->ssl_verify);
+       config_node_set_str(config, node, "ssl_cafile", server->connrec->ssl_cafile);
+       config_node_set_str(config, node, "ssl_capath", server->connrec->ssl_capath);
 
        handle = g_io_channel_unix_get_fd(net_sendbuffer_handle(server->handle));
        config_node_set_int(config, node, "handle", handle);
@@ -278,9 +260,10 @@ static void session_restore_server(CONFIG_NODE *node)
                                  chatnet, password, nick);
        if (conn != NULL) {
                conn->reconnection = TRUE;
-               conn->connect_handle = g_io_channel_unix_new(handle);
+               conn->connect_handle = g_io_channel_new(handle);
 
                server = proto->server_init_connect(conn);
+               server->version = g_strdup(config_node_get_str(node, "version", NULL));
                server->session_reconnect = TRUE;
                signal_emit("session restore server", 2, server, node);
 
@@ -302,7 +285,7 @@ static void sig_session_save(CONFIG_REC *config)
        /* save pids */
         str = g_string_new(NULL);
        for (tmp = pidwait_get_pids(); tmp != NULL; tmp = tmp->next)
-                g_string_sprintfa(str, "%d ", GPOINTER_TO_INT(tmp->data));
+                g_string_append_printf(str, "%d ", GPOINTER_TO_INT(tmp->data));
         config_node_set_str(config, config->mainnode, "pids", str->str);
         g_string_free(str, TRUE);
 }
@@ -344,22 +327,22 @@ static void sig_init_finished(void)
        config_close(session);
 
        unlink(session_file);
-       session_file = NULL;
 }
 
-void session_init(void)
+void session_register_options(void)
 {
-       static struct poptOption options[] = {
-#if 0 /* --session is not available in SILC Client */
-               { "session", 0, POPT_ARG_STRING, &session_file, 0, "Used by /UPGRADE command", "PATH" },
-#endif
-               { NULL, '\0', 0, NULL }
+       static GOptionEntry options[] = {
+               { "session", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_STRING, &session_file, "Used by /UPGRADE command", "PATH" },
+               { NULL }
        };
 
-        session_file = NULL;
+       session_file = NULL;
        args_register(options);
+}
 
-       /*command_bind("upgrade", NULL, (SIGNAL_FUNC) cmd_upgrade);*/
+void session_init(void)
+{
+       command_bind("upgrade", NULL, (SIGNAL_FUNC) cmd_upgrade);
 
        signal_add("session save", (SIGNAL_FUNC) sig_session_save);
        signal_add("session restore", (SIGNAL_FUNC) sig_session_restore);
@@ -374,7 +357,7 @@ void session_deinit(void)
 {
        g_free_not_null(irssi_binary);
 
-        /*command_unbind("upgrade", (SIGNAL_FUNC) cmd_upgrade);*/
+        command_unbind("upgrade", (SIGNAL_FUNC) cmd_upgrade);
 
        signal_remove("session save", (SIGNAL_FUNC) sig_session_save);
        signal_remove("session restore", (SIGNAL_FUNC) sig_session_restore);