static void logs_buffer_raw_display(window_t *w) { char *line, **lines; logs_log_t *ll; int i, j, n, all = (config_logs_remind_number <= 0); if (!w || !w->session) return; if ((WINDOW_STATUS_ID == w->id) || (WINDOW_CONTACTS_ID == w->id) || (WINDOW_LASTLOG_ID ==w->id )) return; if (!(ll = logs_log_open(session_uid_get(w->session), w->target, TRUE))) return; if (!all) lines = g_new0(char *, config_logs_remind_number + 1); // read log n = 0; fseek(ll->file, 0, SEEK_SET); while ((line = read_file(ll->file, 0))) { ekg_fix_utf8(line); if (all) { time_t t = g_ascii_strtoll(line, &line, 10); if (t>0 && *line == ' ') line++; logs_print_window(w->session, w, line, t); } else { j = n % config_logs_remind_number; g_free(lines[j]); lines[j] = g_strdup(line); n++; } } if (all) { query_emit(NULL, "ui-window-refresh"); return; } ftruncate(fileno(ll->file), 0); // display and rewrite log w->lock++; for (i=0; i < config_logs_remind_number; i++, n++) { time_t t; j = n % config_logs_remind_number; if (!lines[j]) continue; fputs(lines[j], ll->file); fputc('\n', ll->file); t = g_ascii_strtoll(lines[j], &line, 10); if (t>0 && *line == ' ') line++; logs_print_window(w->session, w, line, t); } w->lock--; g_strfreev(lines); query_emit(NULL, "ui-window-refresh"); }
/* items == -1 display all */ static int logs_buffer_raw_display(const char *file, int items) { struct buffer **bs = NULL; struct buffer *b; char *beg = NULL, *profile = NULL, *sesja = NULL, *target = NULL; int item = 0; int i; session_t *s; window_t *w; if (!file) return -1; if (!items) return 0; /* i'm weird, let's search for logs/__internal__ than check if there are smth after it... & check if there are two '/' */ if ((beg = xstrstr(file, "logs/__internal__")) && xstrlen(beg) > 19 && xstrchr(beg+18, '/') && xstrchr(beg+18, '/') != xstrrchr(beg+18, '/')) { profile = beg + 18; sesja = xstrchr(profile, '/')+1; target = xstrchr(sesja, '/')+1; } debug("[logs_buffer_raw_display()] profile: 0x%x sesja: 0x%x target: 0x%x\n", profile, sesja, target); if (!profile || !sesja || !target) return -1; profile = (xstrcmp(target, "_default_")) ? xstrndup(profile, sesja-profile-1) : NULL; sesja = (xstrcmp(target, "_null_")) ? xstrndup(sesja, target-sesja-1) : NULL; target = xstrdup(target); debug("[logs_buffer_raw_display()] profile: %s sesja: %s target: %s\n", __(profile), __(sesja), __(target)); /* search for session+window */ s = session_find(sesja); w = window_find_s(s, target); debug("[logs_buffer_raw_display()] s:0x%x; w:0x%x;\n", s, w); if (!w) w = window_current; if (w) w->lock++; for (b = buffer_lograw.data; b; b = b->next) { if (!xstrcmp(b->target, file)) { /* we asume that (b->ts < (b->next)->ts, it's quite correct unless other plugin do this trick... */ if (items == -1) { logs_print_window(s, w, b->line, b->ts); } else { bs = (struct buffer **) xrealloc(bs, (item+2) * sizeof(struct buffer *)); bs[item + 1] = NULL; bs[item] = b; } item++; } } if (bs) for (i = item < items ? 0 : item-items; i < item; i++) logs_print_window(s, w, bs[i]->line, bs[i]->ts); if (w) { w->lock--; query_emit(NULL, "ui-window-refresh"); } xfree(bs); xfree(profile); xfree(sesja); xfree(target); return item; }