1
0
mirror of https://github.com/irssi/irssi.git synced 2024-07-07 02:54:19 -04:00

Some logging fixes. Flood checking had a memory leak. Query had a small

memory leak. Text buffer fixes.


git-svn-id: http://svn.irssi.org/repos/irssi/trunk@226 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
Timo Sirainen 2000-05-18 08:46:56 +00:00 committed by cras
parent a0aa649368
commit ae25925a1f
10 changed files with 131 additions and 91 deletions

View File

@ -160,6 +160,7 @@ log.c:
"log new", LOG_REC
"log remove", LOG_REC
"log open failed", LOG_REC
"log locked", LOG_REC
"log started", LOG_REC
"log stopped", LOG_REC

View File

@ -45,6 +45,9 @@ static void log_write_timestamp(int handle, const char *format, const char *suff
struct tm *tm;
char str[256];
g_return_if_fail(format != NULL);
if (*format == '\0') return;
tm = localtime(&t);
str[sizeof(str)-1] = '\0';
@ -74,7 +77,10 @@ int log_start_logging(LOG_REC *log)
log->handle = open(fname, O_WRONLY | O_APPEND | O_CREAT, log_file_create_mode);
g_free(str);
if (log->handle == -1) return FALSE;
if (log->handle == -1) {
signal_emit("log create failed", 1, log);
return FALSE;
}
#ifdef HAVE_FCNTL
memset(&lock, 0, sizeof(lock));
lock.l_type = F_WRLCK;
@ -317,7 +323,7 @@ void log_close(LOG_REC *log)
g_free(log);
}
static void sig_printtext_stripped(void *server, const char *item, gpointer levelp, const char *str)
static void sig_printtext_stripped(void *window, void *server, const char *item, gpointer levelp, const char *str)
{
int level;

View File

@ -48,7 +48,7 @@ static void cmd_log_open(const char *data)
char *params, *args, *targetarg, *rotatearg, *fname, *levels;
char window[MAX_INT_STRLEN];
LOG_REC *log;
int opened, level, rotate;
int level, rotate;
args = "targets rotate";
params = cmd_get_params(data, 5 | PARAM_FLAG_MULTIARGS | PARAM_FLAG_GETREST,
@ -73,12 +73,15 @@ static void cmd_log_open(const char *data)
log = log_create_rec(fname, level, targetarg);
if (log != NULL && log->handle == -1 && stristr(args, "-noopen") == NULL) {
/* start logging */
opened = log_start_logging(log);
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
opened ? IRCTXT_LOG_OPENED :
IRCTXT_LOG_CREATE_FAILED, fname);
if (!opened) log_close(log);
if (log_start_logging(log)) {
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
IRCTXT_LOG_OPENED, fname);
} else {
log_close(log);
log = NULL;
}
}
if (log != NULL) {
if (stristr(args, "-autoopen"))
log->autoopen = TRUE;
@ -366,6 +369,12 @@ static void sig_log_locked(LOG_REC *log)
IRCTXT_LOG_LOCKED, log->fname);
}
static void sig_log_create_failed(LOG_REC *log)
{
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
IRCTXT_LOG_CREATE_FAILED, log->fname, g_strerror(errno));
}
static void read_settings(void)
{
int old_autolog = autolog_level;
@ -401,6 +410,7 @@ void fe_log_init(void)
signal_add("window item remove", (SIGNAL_FUNC) sig_window_item_remove);
signal_add("window refnum changed", (SIGNAL_FUNC) sig_window_refnum_changed);
signal_add("log locked", (SIGNAL_FUNC) sig_log_locked);
signal_add("log create failed", (SIGNAL_FUNC) sig_log_create_failed);
signal_add("setup changed", (SIGNAL_FUNC) read_settings);
}
@ -420,5 +430,6 @@ void fe_log_deinit(void)
signal_remove("window item remove", (SIGNAL_FUNC) sig_window_item_remove);
signal_remove("window refnum changed", (SIGNAL_FUNC) sig_window_refnum_changed);
signal_remove("log locked", (SIGNAL_FUNC) sig_log_locked);
signal_remove("log create failed", (SIGNAL_FUNC) sig_log_create_failed);
signal_remove("setup changed", (SIGNAL_FUNC) read_settings);
}

View File

@ -73,7 +73,7 @@ FORMAT_REC fecommon_core_formats[] = {
{ "log_opened", "Log file %W$0%n opened", 1, { 0 } },
{ "log_closed", "Log file %W$0%n closed", 1, { 0 } },
{ "log_create_failed", "Couldn't create log file %W$0", 1, { 0 } },
{ "log_create_failed", "Couldn't create log file %_$0%_: $1", 2, { 0, 0 } },
{ "log_locked", "Log file %W$0%n is locked, probably by another running Irssi", 1, { 0 } },
{ "log_not_open", "Log file %W$0%n not open", 1, { 0 } },
{ "log_started", "Started logging to file %W$0", 1, { 0 } },

View File

@ -220,7 +220,7 @@ static void gui_printtext(WINDOW_REC *window, gpointer fgcolor, gpointer bgcolor
{
GUI_WINDOW_REC *gui;
LINE_REC *line;
int fg, bg, flags, new_lines, n, visible, ypos;
int fg, bg, flags, new_lines, n, visible, ypos, subline;
g_return_if_fail(window != NULL);
@ -265,12 +265,21 @@ static void gui_printtext(WINDOW_REC *window, gpointer fgcolor, gpointer bgcolor
if (visible) {
/* draw the line to screen. */
ypos = gui->parent->first_line+gui->ypos-new_lines;
ypos = gui->ypos-new_lines;
if (new_lines > 0) {
set_color(0);
move(ypos, 0); clrtoeol();
move(gui->parent->first_line+ypos, 0); clrtoeol();
}
gui_window_line_draw(gui, line, ypos, gui->last_subline, -1);
if (ypos >= 0)
subline = gui->last_subline;
else {
/* *LONG* line - longer than screen height */
subline = -ypos+gui->last_subline;
ypos = 0;
}
ypos += gui->parent->first_line;
gui_window_line_draw(gui, line, ypos, subline, -1);
}
gui->last_subline += new_lines;

View File

@ -173,7 +173,6 @@ static int gui_window_update_bottom(GUI_WINDOW_REC *gui, int lines)
break;
gui->bottom_startline = gui->bottom_startline->next;
}
lines--;
}
return last_linecount;
@ -471,81 +470,84 @@ void gui_window_redraw(WINDOW_REC *window)
screen_refresh();
}
static void gui_window_scroll_up(GUI_WINDOW_REC *gui, gint lines)
#define is_window_bottom(gui) \
((gui)->startline == (gui)->bottom_startline && \
(gui)->subline >= (gui)->bottom_subline)
static void gui_window_scroll_up(GUI_WINDOW_REC *gui, int lines)
{
LINE_REC *line;
gint count, linecount;
LINE_REC *line;
gint count, linecount;
if (gui->startline == NULL)
return;
if (gui->startline == NULL)
return;
count = lines-gui->subline; gui->ypos += gui->subline;
gui->subline = 0;
count = lines-gui->subline; gui->ypos += gui->subline;
gui->subline = 0;
while (gui->startline->prev != NULL && count > 0)
{
gui->startline = gui->startline->prev;
while (gui->startline->prev != NULL && count > 0) {
gui->startline = gui->startline->prev;
line = gui->startline->data;
linecount = gui_window_get_linecount(gui, line);
count -= linecount;
gui->ypos += linecount;
}
line = gui->startline->data;
linecount = gui_window_get_linecount(gui, line);
count -= linecount;
gui->ypos += linecount;
}
if (count < 0)
{
gui->subline = -count;
gui->ypos -= -count;
}
if (count < 0) {
gui->subline = -count;
gui->ypos -= -count;
}
gui->bottom = (gui->ypos >= -1 && gui->ypos <= gui->parent->last_line-gui->parent->first_line);
gui->bottom = is_window_bottom(gui);
}
static void gui_window_scroll_down(GUI_WINDOW_REC *gui, gint lines)
static void gui_window_scroll_down(GUI_WINDOW_REC *gui, int lines)
{
LINE_REC *line;
gint count, linecount;
LINE_REC *line;
int count, linecount;
if (gui->startline == gui->bottom_startline && gui->subline == gui->bottom_subline)
return;
if (is_window_bottom(gui))
return;
count = lines+gui->subline; gui->ypos += gui->subline;
gui->subline = 0;
count = lines+gui->subline; gui->ypos += gui->subline;
gui->subline = 0;
while (count > 0)
{
line = gui->startline->data;
while (count > 0) {
line = gui->startline->data;
linecount = gui_window_get_linecount(gui, line);
count -= linecount;
gui->ypos -= linecount;
linecount = gui_window_get_linecount(gui, line);
count -= linecount;
gui->ypos -= linecount;
if (gui->startline == gui->bottom_startline &&
linecount+count > gui->bottom_subline)
{
/* reached the last screenful of text */
gui->subline = gui->bottom_subline;
gui->ypos += linecount;
gui->ypos -= gui->subline;
break;
if (gui->startline == gui->bottom_startline &&
linecount+count > gui->bottom_subline) {
/* reached the last screenful of text */
gui->subline = gui->bottom_subline;
gui->ypos += linecount;
gui->ypos -= gui->subline;
break;
}
if (count == 0) {
gui->startline = gui->startline->next;
break;
}
if (count < 0) {
gui->subline = linecount+count;
gui->ypos += -count;
break;
}
if (gui->startline->next == NULL) {
gui->subline = linecount;
break;
}
gui->startline = gui->startline->next;
}
if (count <= 0)
{
gui->subline = linecount+count;
gui->ypos += -count;
break;
}
if (gui->startline->next == NULL)
{
gui->subline = linecount;
break;
}
gui->startline = gui->startline->next;
}
gui->bottom = (gui->ypos >= -1 && gui->ypos <= gui->parent->last_line-gui->parent->first_line);
gui->bottom = is_window_bottom(gui);
}
void gui_window_scroll(WINDOW_REC *window, int lines)

View File

@ -251,7 +251,6 @@ static void read_ignores(void)
IGNORE_REC *rec;
CONFIG_NODE *node;
GSList *tmp;
char *str;
while (ignores != NULL)
ignore_destroy(ignores->data);

View File

@ -40,20 +40,15 @@ static void event_away(const char *data, IRC_SERVER_REC *server)
if (level == 0) return;
log = log_find(fname);
if (log != NULL) {
/* awaylog already created */
if (log->handle == -1) {
/* ..but not open, open it. */
log_start_logging(log);
}
return;
}
log = log_create_rec(fname, level, NULL);
if (log != NULL) {
if (log == NULL) {
log = log_create_rec(fname, level, NULL);
log->temp = TRUE;
log_update(log);
log_start_logging(log);
}
if (!log_start_logging(log)) {
/* creating log file failed? close it. */
log_close(log);
}
}

View File

@ -63,6 +63,7 @@ void query_destroy(QUERY_REC *query)
signal_emit("query destroyed", 1, query);
MODULE_DATA_DEINIT(query);
g_free_not_null(query->address);
g_free(query->nick);
g_free(query->server_tag);
g_free(query);

View File

@ -46,7 +46,7 @@ typedef struct {
static int flood_tag;
static int flood_max_msgs, flood_timecheck;
static int flood_hash_deinit(const char *key, FLOOD_REC *flood, gpointer nowp)
static int flood_hash_check_remove(const char *key, FLOOD_REC *flood, gpointer nowp)
{
GSList *tmp, *next;
time_t now;
@ -59,8 +59,11 @@ static int flood_hash_deinit(const char *key, FLOOD_REC *flood, gpointer nowp)
FLOOD_ITEM_REC *rec = tmp->data;
next = tmp->next;
if (now-rec->first >= flood_timecheck)
if (now-rec->first >= flood_timecheck) {
flood->items = g_slist_remove(flood->items, rec);
g_free(rec->target);
g_free(rec);
}
}
if (flood->items != NULL)
@ -83,7 +86,7 @@ static int flood_timeout(void)
IRC_SERVER_REC *rec = tmp->data;
mserver = MODULE_DATA(rec);
g_hash_table_foreach_remove(mserver->floodlist, (GHRFunc) flood_hash_deinit, GINT_TO_POINTER((int) now));
g_hash_table_foreach_remove(mserver->floodlist, (GHRFunc) flood_hash_check_remove, GINT_TO_POINTER((int) now));
}
return 1;
}
@ -101,6 +104,21 @@ static void flood_init_server(IRC_SERVER_REC *server)
rec->floodlist = g_hash_table_new((GHashFunc) g_istr_hash, (GCompareFunc) g_istr_equal);
}
static void flood_hash_destroy(const char *key, FLOOD_REC *flood)
{
while (flood->items != NULL) {
FLOOD_ITEM_REC *rec = flood->items->data;
g_free(rec->target);
g_free(rec);
flood->items = g_slist_remove(flood->items, rec);
}
g_free(flood->nick);
g_free(flood);
}
/* Deinitialize flood protection */
static void flood_deinit_server(IRC_SERVER_REC *server)
{
@ -112,9 +130,7 @@ static void flood_deinit_server(IRC_SERVER_REC *server)
if (mserver != NULL && mserver->floodlist != NULL) {
flood_timecheck = 0;
g_hash_table_freeze(mserver->floodlist);
g_hash_table_foreach(mserver->floodlist, (GHFunc) flood_hash_deinit, NULL);
g_hash_table_thaw(mserver->floodlist);
g_hash_table_foreach(mserver->floodlist, (GHFunc) flood_hash_destroy, NULL);
g_hash_table_destroy(mserver->floodlist);
}
g_free(mserver);