Exemple #1
0
static logs_log_t *logs_log_new(logs_log_t *l, const char *session, const char *uid) {
	logs_log_t *ll;
	int created = 0;

	debug("[logs] log_new uid = %s session %s", __(uid), __(session));
	ll = l ? l : logs_log_find(session, uid, 0);
	debug(" logs_log_t %x\n", ll);

	if (!ll) {
		ll = xmalloc(sizeof(logs_log_t));
		ll->session = xstrdup(session);
		ll->uid = xstrdup(uid);
		created = 1;
	}

	if (!(ll->lw)) {
		ll->lw = xmalloc(sizeof(log_window_t));
		logs_window_check(ll, time(NULL)); /* l->log_format i l->path, l->t */
		ll->lw->file = logs_open_file(ll->lw->path, ll->lw->logformat);
	}

	if (created) {
		if (ll->lw->logformat == LOG_FORMAT_IRSSI && xstrlen(IRSSI_LOG_EKG2_OPENED)) {
			logs_irssi(ll->lw->file, session, NULL,
					prepare_timestamp_format(IRSSI_LOG_EKG2_OPENED, time(NULL)),
					0, EKG_MSGCLASS_SYSTEM);
		} 
		list_add(&log_logs, ll);
	}
	return ll;
}
Exemple #2
0
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);
}
Exemple #3
0
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;
}
Exemple #4
0
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;
}
Exemple #5
0
			fputs("</ekg2log>\n", fdesc);
		} 
		return fdesc;
	}

	return fopen(fullname, "a+");
}

/*
 * zapis w formacie znanym z ekg1
 * typ,uid,nickname,timestamp,{timestamp wyslania dla odleglych}, text
 */

static void logs_simple(FILE *file, const char *session, const char *uid, const char *text, time_t sent, msgclass_t class, const char *status) {
	char *textcopy;
	const char *timestamp = prepare_timestamp_format(config_logs_timestamp, time(0));

	session_t *s = session_find((const char*)session);
	const char *gotten_uid = get_uid(s, uid);
	const char *gotten_nickname = get_nickname(s, uid);

	const gchar *logsenc = config_logs_encoding ? config_logs_encoding : console_charset;
	GString *tmp;

	if (!file)
		return;
	textcopy = log_escape(text);

	if (!gotten_uid)	gotten_uid = uid;
	if (!gotten_nickname)	gotten_nickname = uid;