/* * plugin's variable handler * */ static void logs_variable_changed(const char *var) { int i; g_return_if_fail(logs_logs != NULL); if (!xstrcmp(var, "logs:max_open_files")) { logs_open_files_check(); } else if (!xstrcmp(var, "logs:log_raw") && !config_logs_log_raw) { // remove raw logs for (i = logs_logs->len - 1; 0 <= i; i--) { logs_log_t *ll = g_ptr_array_index(logs_logs, i); if (LOG_FORMAT_RAW == ll->format) g_ptr_array_remove(logs_logs, ll); } } else if (!xstrcmp(var, "logs:path") || !xstrcmp(var, "logs:log")) { for (i = logs_logs->len - 1; 0 <= i; i--) { logs_log_t *ll = g_ptr_array_index(logs_logs, i); char *tmp; if (LOG_FORMAT_RAW == ll->format) continue; if (!config_logs_path || (LOG_FORMAT_NONE == config_logs_log)) { g_ptr_array_remove(logs_logs, ll); continue; } tmp = logs_prepare_fname(ll); if (xstrcmp(tmp, ll->fname)) { // new file name; reopen logs_log_reopen(ll); } g_free(tmp); } } else if (!xstrcmp(var, "logs:log_status") && !config_logs_log_status) { for (i = logs_logs->len - 1; 0 <= i; i--) { logs_log_t *ll = g_ptr_array_index(logs_logs, i); if (LOG_FORMAT_RAW == ll->format) continue; if (!window_find_s(session_find(ll->session), ll->uid)) g_ptr_array_remove(logs_logs, ll); } } }
/* 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; }