static void logs_log_destroy(gpointer data) { logs_log_t *log = data; g_return_if_fail(log != NULL); if ((LOG_FORMAT_IRSSI == log->format) && xstrlen(IRSSI_LOG_EKG2_CLOSED)) { logs_open_file(log); log->daychanged = 0; logs_irssi_sysmsg(log, prepare_timestamp_format(IRSSI_LOG_EKG2_CLOSED, time(NULL))); } logs_log_close(log); debug_function("logs_log_destroy(%d) %s\n", logs_logs->len, log->fname); g_free(log->fname); g_free(log->session); g_free(log->uid); g_free(log); }
static logs_log_t *logs_log_new(const char *session, const char *target, gboolean raw) { logs_log_t *ll; log_format_t format; char *uid, *tmp; if (LOG_FORMAT_NONE == (format = raw ? LOG_FORMAT_RAW : logs_log_format(session_find(session)))) return NULL; if (!(uid = g_strdup(get_uid_any(session_find(session), target)))) uid = g_strdup(target); if ((tmp = xstrchr(uid, '/'))) *tmp = '\0'; // strip resource ll = logs_log_find(session, uid, raw); if (ll) { g_free(uid); return ll; } // Create new ll = xmalloc(sizeof(logs_log_t)); ll->session = g_strdup(session); ll->uid = uid; ll->format = format; ll->fname = logs_prepare_fname(ll); g_ptr_array_add(logs_logs, ll); if (ll->format == LOG_FORMAT_IRSSI && xstrlen(IRSSI_LOG_EKG2_OPENED)) { logs_open_file(ll); logs_irssi_sysmsg(ll, prepare_timestamp_format(IRSSI_LOG_EKG2_OPENED, time(NULL))); } debug("[logs] log_new s=%s uid=%s ff=%d logs_log_t %x\n", __(session), __(uid), ll->format, ll); return ll; }
static int logs_window_check(logs_log_t *ll, time_t t) { session_t *s; log_window_t *l = ll->lw; int chan = 0; int tmp; if (!l || !(s = session_find(ll->session))) return -1; if (l->logformat != (tmp = logs_log_format(s))) { l->logformat = tmp; chan = 1; } if (!(l->path)) { chan = 2; } else { int datechanged = 0; /* bitmaska 0x01 (dzien) 0x02 (miesiac) 0x04 (rok) */ struct tm *tm = g_memdup(localtime(&(ll->t)), sizeof(struct tm)); struct tm *tm2 = localtime(&t); /* sprawdzic czy dane z (tm == tm2) */ if (tm->tm_mday != tm2->tm_mday) datechanged |= 0x01; if (tm->tm_mon != tm2->tm_mon) datechanged |= 0x02; if (tm->tm_year != tm2->tm_year) datechanged |= 0x04; if ( ((datechanged & 0x04) && xstrstr(config_logs_path, "%Y")) || ((datechanged & 0x02) && xstrstr(config_logs_path, "%M")) || ((datechanged & 0x01) && xstrstr(config_logs_path, "%D")) ) chan = 3; /* zalogowac jak sie zmienila data */ if (datechanged && l->logformat == LOG_FORMAT_IRSSI) { /* yes i know it's wrong place for doing this but .... */ if (!(l->file)) l->file = logs_open_file(l->path, LOG_FORMAT_IRSSI); logs_irssi(l->file, ll->session, NULL, prepare_timestamp_format(IRSSI_LOG_DAY_CHANGED, time(NULL)), 0, EKG_MSGCLASS_SYSTEM); } xfree(tm); } ll->t = t; if (chan > 1) { char *tmp = l->path; l->path = logs_prepare_path(s, config_logs_path, ll->uid, t); debug("[logs] logs_window_check chan = %d oldpath = %s newpath = %s\n", chan, __(tmp), __(l->path)); #if 0 /* TODO: nie moze byc - bo mogl logformat sie zmienic... */ if (chan != 3 && !xstrcmp(tmp, l->path)) /* jesli sciezka sie nie zmienila to nie otwieraj na nowo pliku */ chan = -chan; #endif xfree(tmp); } if (chan > 0) { if (l->file) { /* jesli plik byl otwarty otwieramy go z nowa sciezka */ fclose(l->file); l->file = NULL; l->file = logs_open_file(l->path, l->logformat); } } return chan; }