2000-04-26 04:03:38 -04:00
|
|
|
/*
|
|
|
|
core.c : irssi
|
|
|
|
|
2000-08-26 11:39:44 -04:00
|
|
|
Copyright (C) 1999-2000 Timo Sirainen
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "module.h"
|
2001-06-01 16:21:07 -04:00
|
|
|
#include <signal.h>
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-07-14 20:39:48 -04:00
|
|
|
#include "args.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
#include "pidwait.h"
|
2001-06-01 16:21:07 -04:00
|
|
|
#include "misc.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
#include "net-disconnect.h"
|
2000-07-16 15:00:41 -04:00
|
|
|
#include "net-sendbuffer.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
#include "signals.h"
|
|
|
|
#include "settings.h"
|
|
|
|
|
2000-08-31 20:26:46 -04:00
|
|
|
#include "chat-protocols.h"
|
2000-08-26 11:39:44 -04:00
|
|
|
#include "servers.h"
|
|
|
|
#include "chatnets.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
#include "commands.h"
|
2000-12-04 19:53:04 -05:00
|
|
|
#include "expandos.h"
|
2001-02-10 00:54:35 -05:00
|
|
|
#include "write-buffer.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
#include "log.h"
|
|
|
|
#include "rawlog.h"
|
2000-10-09 19:40:18 -04:00
|
|
|
#include "ignore.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-08-26 11:39:44 -04:00
|
|
|
#include "channels.h"
|
|
|
|
#include "queries.h"
|
|
|
|
#include "nicklist.h"
|
2001-01-20 23:09:48 -05:00
|
|
|
#include "nickmatch-cache.h"
|
2000-08-26 11:39:44 -04:00
|
|
|
|
2000-09-30 18:49:48 -04:00
|
|
|
void chat_commands_init(void);
|
|
|
|
void chat_commands_deinit(void);
|
|
|
|
|
2000-04-26 04:03:38 -04:00
|
|
|
int irssi_gui;
|
|
|
|
|
2001-07-14 20:39:48 -04:00
|
|
|
static char *irssi_dir, *irssi_config_file;
|
2001-07-14 15:10:17 -04:00
|
|
|
static GSList *dialog_type_queue, *dialog_text_queue;
|
|
|
|
|
2001-07-14 20:39:48 -04:00
|
|
|
const char *get_irssi_dir(void)
|
|
|
|
{
|
|
|
|
return irssi_dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* return full path for ~/.irssi/config */
|
|
|
|
const char *get_irssi_config(void)
|
|
|
|
{
|
|
|
|
return irssi_config_file;
|
|
|
|
}
|
|
|
|
|
2001-06-01 16:21:07 -04:00
|
|
|
static void read_signals(void)
|
|
|
|
{
|
|
|
|
#ifndef WIN32
|
|
|
|
int signals[] = {
|
|
|
|
SIGHUP, SIGINT, SIGQUIT, SIGTERM,
|
|
|
|
SIGALRM, SIGUSR1, SIGUSR2
|
|
|
|
};
|
|
|
|
char *signames[] = {
|
|
|
|
"hup", "int", "quit", "term",
|
|
|
|
"alrm", "usr1", "usr2"
|
|
|
|
};
|
|
|
|
|
|
|
|
const char *ignores;
|
|
|
|
struct sigaction act;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
ignores = settings_get_str("ignore_signals");
|
|
|
|
|
|
|
|
sigemptyset (&act.sa_mask);
|
|
|
|
act.sa_flags = 0;
|
|
|
|
|
|
|
|
for (n = 0; n < sizeof(signals)/sizeof(signals[0]); n++) {
|
|
|
|
act.sa_handler = find_substr(ignores, signames[n]) ?
|
|
|
|
SIG_IGN : SIG_DFL;
|
|
|
|
sigaction(signals[n], &act, NULL);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2001-07-14 15:10:17 -04:00
|
|
|
static void sig_gui_dialog(const char *type, const char *text)
|
|
|
|
{
|
|
|
|
dialog_type_queue = g_slist_append(dialog_type_queue, g_strdup(type));
|
|
|
|
dialog_text_queue = g_slist_append(dialog_text_queue, g_strdup(text));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sig_init_finished(void)
|
|
|
|
{
|
|
|
|
GSList *type, *text;
|
|
|
|
|
|
|
|
signal_remove("gui dialog", (SIGNAL_FUNC) sig_gui_dialog);
|
|
|
|
signal_remove("irssi init finished", (SIGNAL_FUNC) sig_init_finished);
|
|
|
|
|
|
|
|
/* send the dialog texts that were in queue before irssi
|
|
|
|
was initialized */
|
|
|
|
type = dialog_type_queue;
|
|
|
|
text = dialog_text_queue;
|
|
|
|
for (; text != NULL; text = text->next, type = type->next) {
|
|
|
|
signal_emit("gui dialog", 2, type->data, text->data);
|
|
|
|
g_free(type->data);
|
|
|
|
g_free(text->data);
|
|
|
|
}
|
|
|
|
g_slist_free(dialog_type_queue);
|
|
|
|
g_slist_free(dialog_text_queue);
|
|
|
|
}
|
|
|
|
|
2001-07-14 20:39:48 -04:00
|
|
|
void core_init_paths(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
static struct poptOption options[] = {
|
|
|
|
{ "config", 0, POPT_ARG_STRING, NULL, 0, "Configuration file location (~/.irssi/config)", "PATH" },
|
|
|
|
{ "home", 0, POPT_ARG_STRING, NULL, 0, "Irssi home dir location (~/.irssi)", "PATH" },
|
|
|
|
{ NULL, '\0', 0, NULL }
|
|
|
|
};
|
|
|
|
int n, len;
|
|
|
|
|
|
|
|
for (n = 1; n < argc; n++) {
|
|
|
|
if (strncmp(argv[n], "--home=", 7) == 0) {
|
|
|
|
g_free_not_null(irssi_dir);
|
|
|
|
irssi_dir = convert_home(argv[n]+7);
|
|
|
|
len = strlen(irssi_dir);
|
|
|
|
if (irssi_dir[len-1] == G_DIR_SEPARATOR)
|
|
|
|
irssi_dir[len-1] = '\0';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (strncmp(argv[n], "--config=", 9) == 0) {
|
|
|
|
g_free_not_null(irssi_config_file);
|
|
|
|
irssi_config_file = convert_home(argv[n]+9);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
args_register(options);
|
|
|
|
|
|
|
|
if (irssi_dir == NULL)
|
|
|
|
irssi_dir = g_strdup_printf(IRSSI_DIR_FULL, g_get_home_dir());
|
|
|
|
if (irssi_config_file == NULL)
|
|
|
|
irssi_config_file = g_strdup_printf("%s/config", irssi_dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
void core_init(int argc, char *argv[])
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2001-07-14 15:10:17 -04:00
|
|
|
dialog_type_queue = NULL;
|
|
|
|
dialog_text_queue = NULL;
|
|
|
|
|
2000-04-26 04:03:38 -04:00
|
|
|
modules_init();
|
2000-10-26 14:57:23 -04:00
|
|
|
#ifndef WIN32
|
2000-04-26 04:03:38 -04:00
|
|
|
pidwait_init();
|
2000-10-26 14:57:23 -04:00
|
|
|
#endif
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
net_disconnect_init();
|
2000-07-16 15:00:41 -04:00
|
|
|
net_sendbuffer_init();
|
2000-04-26 04:03:38 -04:00
|
|
|
signals_init();
|
2001-07-14 15:10:17 -04:00
|
|
|
|
|
|
|
signal_add_first("gui dialog", (SIGNAL_FUNC) sig_gui_dialog);
|
|
|
|
signal_add_first("irssi init finished", (SIGNAL_FUNC) sig_init_finished);
|
|
|
|
|
2000-04-26 04:03:38 -04:00
|
|
|
settings_init();
|
2000-05-15 04:25:45 -04:00
|
|
|
commands_init();
|
2001-01-28 02:22:22 -05:00
|
|
|
nickmatch_cache_init();
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-08-31 20:26:46 -04:00
|
|
|
chat_protocols_init();
|
2000-08-26 11:39:44 -04:00
|
|
|
chatnets_init();
|
2000-12-04 19:53:04 -05:00
|
|
|
expandos_init();
|
2000-10-09 19:40:18 -04:00
|
|
|
ignore_init();
|
2000-04-26 04:03:38 -04:00
|
|
|
servers_init();
|
2001-02-10 00:54:35 -05:00
|
|
|
write_buffer_init();
|
2000-04-26 04:03:38 -04:00
|
|
|
log_init();
|
|
|
|
rawlog_init();
|
2000-08-26 11:39:44 -04:00
|
|
|
|
|
|
|
channels_init();
|
|
|
|
queries_init();
|
|
|
|
nicklist_init();
|
2000-09-30 18:49:48 -04:00
|
|
|
|
|
|
|
chat_commands_init();
|
2001-06-01 16:21:07 -04:00
|
|
|
|
|
|
|
settings_add_str("misc", "ignore_signals", "");
|
|
|
|
signal_add("setup changed", (SIGNAL_FUNC) read_signals);
|
|
|
|
read_signals();
|
|
|
|
|
2000-12-17 00:44:45 -05:00
|
|
|
settings_check();
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void core_deinit(void)
|
|
|
|
{
|
2001-06-01 16:21:07 -04:00
|
|
|
signal_remove("setup changed", (SIGNAL_FUNC) read_signals);
|
|
|
|
|
2000-09-30 18:49:48 -04:00
|
|
|
chat_commands_deinit();
|
|
|
|
|
2000-08-26 11:39:44 -04:00
|
|
|
nicklist_deinit();
|
|
|
|
queries_deinit();
|
|
|
|
channels_deinit();
|
|
|
|
|
2000-04-26 04:03:38 -04:00
|
|
|
rawlog_deinit();
|
|
|
|
log_deinit();
|
2001-02-10 00:54:35 -05:00
|
|
|
write_buffer_deinit();
|
2000-04-26 04:03:38 -04:00
|
|
|
servers_deinit();
|
2000-10-09 19:40:18 -04:00
|
|
|
ignore_deinit();
|
2000-12-04 19:53:04 -05:00
|
|
|
expandos_deinit();
|
2000-08-26 11:39:44 -04:00
|
|
|
chatnets_deinit();
|
2000-08-31 20:26:46 -04:00
|
|
|
chat_protocols_deinit();
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-01-28 02:22:22 -05:00
|
|
|
nickmatch_cache_deinit();
|
2000-05-15 04:25:45 -04:00
|
|
|
commands_deinit();
|
2000-04-26 04:03:38 -04:00
|
|
|
settings_deinit();
|
|
|
|
signals_deinit();
|
2000-07-16 15:00:41 -04:00
|
|
|
net_sendbuffer_deinit();
|
2000-04-26 04:03:38 -04:00
|
|
|
net_disconnect_deinit();
|
|
|
|
|
2000-10-26 14:57:23 -04:00
|
|
|
#ifndef WIN32
|
2000-04-26 04:03:38 -04:00
|
|
|
pidwait_deinit();
|
2000-10-26 14:57:23 -04:00
|
|
|
#endif
|
2000-04-26 04:03:38 -04:00
|
|
|
modules_deinit();
|
2001-07-14 20:39:48 -04:00
|
|
|
|
|
|
|
g_free(irssi_dir);
|
|
|
|
g_free(irssi_config_file);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|