/** * @return current header string. */ const char * header_fmt_string(const header_fmt_t *hf) { header_fmt_check(hf); return str_2c(hf->header); /* Guaranteed to be always NUL-terminated */ }
PSLIST_FOREACH(info, sl) { cq_info_t *cqi = sl->data; cq_info_check(cqi); if (THREAD_INVALID_ID == cqi->stid) str_printf(s, "%-2s ", "-"); else str_printf(s, "%-2d ", cqi->stid); str_catf(s, "%-6zu ", cqi->event_count); str_catf(s, "%-4zu ", cqi->periodic_count); str_catf(s, "%-4zu ", cqi->idle_count); str_catf(s, "%-5s ", 0 == cqi->last_idle ? "-" : compact_time(delta_time(tm_time(), cqi->last_idle))); str_catf(s, "%'6d ", cqi->period); str_catf(s, "%10zu ", cqi->heartbeat_count); str_catf(s, "%10zu ", cqi->triggered_count); str_catf(s, "\"%s\"%*s", cqi->name, (int) (maxlen - vstrlen(cqi->name)), ""); if (cqi->parent != NULL) str_catf(s, " (%s)", cqi->parent); str_putc(s, '\n'); shell_write(sh, str_2c(s)); }
/** * Fetch the query text from a /Q2 message. * * @param mb a message block containing a serialized /Q2 * * @return a pointer to the search text string (as static data), NULL if * is no text in the query or the message is not a /Q2. */ const char * g2_msg_search_get_text(const pmsg_t *mb) { str_t *s = str_private(G_STRFUNC, 64); const g2_tree_t *t; t = g2_frame_deserialize( pmsg_start(mb), pmsg_written_size(mb), NULL, FALSE); if (NULL == t) { return NULL; } else { const char *payload; size_t paylen; payload = g2_tree_payload(t, "/Q2/DN", &paylen); if (NULL == payload) { g2_tree_free_null_const(&t); return NULL; } str_cpy_len(s, payload, paylen); } g2_tree_free_null_const(&t); return str_2c(s); }
/** * Get field value, or NULL if not present. The value returned is a * pointer to the internals of the header structure, so it must not be * kept around. */ char * header_get(const header_t *o, const char *field) { str_t *v; header_check(o); if (o->headers) { v = htable_lookup(o->headers, deconstify_char(field)); } else { v = NULL; } return str_2c(v); }
/** * Convert current header to a string. * * @attention * NB: returns pointer to static data! */ const char * header_fmt_to_string(const header_fmt_t *hf) { static char line[HEADER_FMT_MAX_SIZE + 1]; header_fmt_check(hf); if (str_len(hf->header) >= sizeof line) { g_warning("trying to format too long an HTTP line (%lu bytes)", (unsigned long) str_len(hf->header)); } clamp_strncpy(line, sizeof line, str_2c(hf->header), str_len(hf->header)); return line; }
/** * Log message. */ void gl_logv(const char *domain, GLogLevelFlags flags, const char *fmt, va_list args) { static str_t *msg[THREAD_MAX]; static bool logging[THREAD_MAX]; unsigned stid = thread_small_id(); G_IGNORE_PUSH(-Wformat-nonliteral); /* s_minilogv() call below */ if (logging[stid]) { s_minilogv(flags | G_LOG_FLAG_RECURSION, FALSE, fmt, args); return; } G_IGNORE_POP; /* * This call is thread-unsafe by construction, and supposed to be called * only from the main thread. This is why it's OK to have a global * ``logging'' variable. */ logging[stid] = TRUE; if G_UNLIKELY(NULL == msg[stid]) msg[stid] = str_new_not_leaking(0); str_vprintf(msg[stid], fmt, args); if (handler_cb != NULL) (*handler_cb)(domain, flags, str_2c(msg[stid]), handler_data); else s_minilog(flags, "%s", str_2c(msg[stid])); logging[stid] = FALSE; }
/** * Convert current header to a string. * * @attention * NB: returns pointer to static data! */ const char * header_fmt_to_string(const header_fmt_t *hf) { buf_t *b = buf_private(G_STRFUNC, HEADER_FMT_MAX_SIZE + 1); char *p = buf_data(b); size_t n = buf_size(b); header_fmt_check(hf); if (str_len(hf->header) >= n) { g_warning("trying to format too long an HTTP line (%zu bytes)", str_len(hf->header)); } clamp_strncpy(p, n, str_2c(hf->header), str_len(hf->header)); return p; }
/** * Convert open() flags to string, for debugging and logging purposes. * * @param flags open() flags value * * @return pointer to static string. */ const char * file_oflags_to_string(int flags) { str_t *s = str_private(G_STRFUNC, 32); /* We assume there will be at least one of O_RDWR, O_RDONLY or O_WRONLY */ str_printf(s, "%s%s%s%s%s", file_accmode_to_string(flags), (flags & O_APPEND) ? " | O_APPEND" : "", (flags & O_CREAT) ? " | O_CREAT" : "", (flags & O_TRUNC) ? " | O_TRUNC" : "", (flags & O_EXCL) ? " | O_EXCL" : ""); return str_2c(s); }
/** * Get field value, or NULL if not present. The value returned is a * pointer to the internals of the header structure, so it must not be * kept around. * * If the len_ptr pointer is not NULL, it is filled with the length * of the header string. */ char * header_get_extended(const header_t *o, const char *field, size_t *len_ptr) { str_t *v; header_check(o); if (o->headers) { v = htable_lookup(o->headers, deconstify_char(field)); } else { v = NULL; } if (v && len_ptr != NULL) { *len_ptr = str_len(v); } return str_2c(v); }
NO_INLINE void G_GNUC_COLD assertion_warning_log(const assertion_data * const data, const char * const fmt, ...) { static str_t *str; va_list args; assertion_message(data, FALSE); if G_UNLIKELY(NULL == str) str = str_new_not_leaking(512); /* * Log additional message. */ va_start(args, fmt); str_vprintf(str, fmt, args); va_end(args); { char time_buf[18]; char prefix[UINT_DEC_BUFLEN + CONST_STRLEN(" (WARNING-): ")]; unsigned stid = thread_small_id(); DECLARE_STR(4); crash_time(time_buf, sizeof time_buf); print_str(time_buf); if (0 == stid) { print_str(" (WARNING): "); } else { str_bprintf(prefix, sizeof prefix, " (WARNING-%u): ", stid); print_str(prefix); } print_str(str_2c(str)); print_str("\n"); flush_err_str(); if (log_stdout_is_distinct()) flush_str(STDOUT_FILENO); } assertion_stacktrace(); }
void on_button_config_remove_dir_clicked(GtkButton *unused_button, gpointer unused_udata) { GtkTreeView *tv; GtkTreeModel *model; GtkTreeIter iter; GtkTreeSelection *selection; str_t *s; (void) unused_button; (void) unused_udata; tv = GTK_TREE_VIEW(gui_dlg_prefs_lookup("treeview_shared_dirs")); model = gtk_tree_view_get_model(tv); if (!gtk_tree_model_get_iter_first(model, &iter)) return; /* Regenerate the string property holding a list of paths */ selection = gtk_tree_view_get_selection(tv); s = str_new(0); do { gchar *dir = NULL; /* Skip items selected for removal */ if (gtk_tree_selection_iter_is_selected(selection, &iter)) continue; gtk_tree_model_get(model, &iter, 0, &dir, (-1)); if (str_len(s) > 0) str_putc(s, ':'); str_cat(s, dir); G_FREE_NULL(dir); } while (gtk_tree_model_iter_next(model, &iter)); gnet_prop_set_string(PROP_SHARED_DIRS_PATHS, str_2c(s)); str_destroy(s); }
static void html_output_tag(struct html_output *output, const struct array *tag) #if GTK_CHECK_VERSION(2,0,0) { static struct { gboolean initialized; short_string_t centre_line, nbsp, bullet, soft_hyphen, em_dash; short_string_t list_item_prefix; } special; struct html_context *ctx; const gchar *style, *text, *attr; enum html_tag id; gboolean closing; GtkTextBuffer *buffer; if (!special.initialized) { special.initialized = TRUE; special.bullet = utf8_char(0x2022); special.centre_line = utf8_char(0xFE4E); special.soft_hyphen = utf8_char(0x00AD); special.nbsp = utf8_char(0x00A0); special.em_dash = utf8_char(0x2014); concat_strings(special.list_item_prefix.str, sizeof special.list_item_prefix.str, " ", special.bullet.str, " ", (void *) 0); } style = NULL; text = NULL; attr = NULL; closing = html_tag_is_closing(tag); ctx = html_output_get_udata(output); id = html_parse_tag(tag); buffer = gtk_text_view_get_buffer(ctx->html_view->widget); switch (id) { case HTML_TAG_BODY: style = STYLE_TAG_WORD_WRAP; break; case HTML_TAG_A: if (closing) { if (ctx->start[id] && ctx->href) { GtkTextIter start, end; GtkTextTag *anchor; anchor = gtk_text_buffer_create_tag(buffer, NULL, (void *) 0); g_object_set_data(G_OBJECT(anchor), "href", deconstify_gchar(ctx->href)); gtk_text_buffer_get_iter_at_mark(buffer, &start, ctx->start[id]); gtk_text_buffer_get_end_iter(buffer, &end); gtk_text_buffer_apply_tag(buffer, anchor, &start, &end); style = get_style_for_href(ctx->href); ctx->href = NULL; } } else { struct array value; value = html_get_attribute(tag, HTML_ATTR_HREF); if (value.data && value.size > 0) { GtkTextIter iter; ctx->href = g_strndup(value.data, value.size); ctx->html_view->to_free = g_slist_prepend( ctx->html_view->to_free, deconstify_gchar(ctx->href)); gtk_text_buffer_get_end_iter(buffer, &iter); ctx->start[id] = gtk_text_buffer_create_mark(buffer, NULL, &iter, TRUE); g_object_set_data(G_OBJECT(ctx->start[id]), "href", deconstify_gchar(ctx->href)); } value = html_get_attribute(tag, HTML_ATTR_NAME); if (value.data && value.size > 0) { GtkTextTagTable *table; gchar name[256]; size_t n; n = sizeof name - 2; n = MIN(value.size, n); name[0] = '#'; memcpy(&name[1], value.data, n); name[n + 1] = '\0'; table = gtk_text_buffer_get_tag_table(buffer); if (NULL == gtk_text_tag_table_lookup(table, name)) { GtkTextIter iter; gtk_text_buffer_get_end_iter(buffer, &iter); gtk_text_buffer_create_mark(buffer, name, &iter, TRUE); } } } break; case HTML_TAG_B: case HTML_TAG_STRONG: case HTML_TAG_THEAD: style = STYLE_TAG_BOLD; break; case HTML_TAG_TH: if (closing) text = "\t"; break; case HTML_TAG_EM: style = STYLE_TAG_UNDERLINE; break; case HTML_TAG_I: case HTML_TAG_Q: style = STYLE_TAG_ITALIC; break; case HTML_TAG_IMG: if (!closing) { struct array value; static gchar alt[1024]; value = html_get_attribute(tag, HTML_ATTR_ALT); if (value.data) { gm_snprintf(alt, sizeof alt, "\n[image alt=\"%.*s\"]\n", (int)value.size, value.data); text = alt; } value = html_get_attribute(tag, HTML_ATTR_SRC); if (value.data) { GdkPixbuf *pixbuf; gchar *filename; GtkTextIter iter; filename = h_strndup(value.data, value.size); pixbuf = gdk_pixbuf_new_from_file(filename, NULL); if (pixbuf) { gtk_text_buffer_get_end_iter(buffer, &iter); gtk_text_buffer_insert_pixbuf(buffer, &iter, pixbuf); } else { static gchar msg[1024]; gm_snprintf(msg, sizeof msg, "\n[Image not found (\"%s\")]\n", filename); text = msg; } HFREE_NULL(filename); } if (!text) { text = "\n[image]\n"; } } attr = STYLE_TAG_BOLD; break; case HTML_TAG_TD: if (closing) text = "\t"; break; case HTML_TAG_P: case HTML_TAG_DIV: text = closing ? "\n\n" : special.soft_hyphen.str; break; case HTML_TAG_DL: case HTML_TAG_TABLE: case HTML_TAG_TR: case HTML_TAG_UL: case HTML_TAG_OL: case HTML_TAG_BR: text = "\n"; break; case HTML_TAG_DT: case HTML_TAG_LI: if (closing) { GtkTextIter start, end; GtkTextTag *margin; PangoLayout *pl; gint width; pl = pango_layout_new(gtk_widget_get_pango_context( GTK_WIDGET(ctx->html_view->widget))); pango_layout_set_text(pl, special.list_item_prefix.str, -1); pango_layout_get_pixel_size(pl, &width, NULL); g_object_unref(G_OBJECT(pl)); margin = gtk_text_buffer_create_tag(buffer, NULL, "left-margin", width * 2, "left-margin-set", TRUE, (void *) 0); gtk_text_buffer_get_iter_at_mark(buffer, &start, ctx->start[id]); gtk_text_buffer_get_end_iter(buffer, &end); gtk_text_buffer_apply_tag(buffer, margin, &start, &end); } else { GtkTextIter iter; gtk_text_buffer_get_end_iter(buffer, &iter); gtk_text_buffer_insert(buffer, &iter, "\n", (-1)); gtk_text_buffer_get_end_iter(buffer, &iter); gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, special.list_item_prefix.str, (-1), STYLE_TAG_BOLD, (void *) 0); gtk_text_buffer_get_end_iter(buffer, &iter); ctx->start[id] = gtk_text_buffer_create_mark(buffer, NULL, &iter, TRUE); } break; case HTML_TAG_CODE: case HTML_TAG_KBD: case HTML_TAG_PRE: case HTML_TAG_TT: style = STYLE_TAG_MONOSPACE; break; case HTML_TAG_H1: style = STYLE_TAG_HEADING_1; text = closing ? "\n\n" : "\n"; break; case HTML_TAG_H2: style = STYLE_TAG_HEADING_2; text = closing ? "\n\n" : "\n"; break; case HTML_TAG_H3: style = STYLE_TAG_HEADING_3; text = closing ? "\n\n" : "\n"; break; case HTML_TAG_H4: case HTML_TAG_H5: case HTML_TAG_H6: style = STYLE_TAG_HEADING_4; text = closing ? "\n\n" : "\n"; break; case HTML_TAG_TITLE: if (closing) { if (ctx->title) { GtkWidget *window; window = gtk_widget_get_toplevel( GTK_WIDGET(ctx->html_view->widget)); gtk_window_set_title(GTK_WINDOW(window), str_2c(ctx->title)); str_destroy_null(&ctx->title); } } else { ctx->title = str_new(0); } break; case HTML_TAG_HR: { GtkTextIter iter; gtk_text_buffer_get_end_iter(buffer, &iter); gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, "\n \n", (-1), STYLE_TAG_CENTER, STYLE_TAG_UNDERLINE, (void *) 0); } text = "\n"; break; case HTML_TAG_COMMENT: #if 0 { GtkTextIter iter; /* Comments can be made visible this way */ ctx->start[id] = gtk_text_buffer_create_mark(buffer, NULL, &iter, TRUE); gtk_text_buffer_get_end_iter(buffer, &iter); gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, tag->data, tag->size, STYLE_TAG_ITALIC, (void *) 0); } closing = TRUE; text = "\n"; #endif break; case HTML_TAG_HTML: if (closing) { if (ctx->lang && ctx->start[id]) { GtkTextIter start, end; GtkTextTag *lang; lang = gtk_text_buffer_create_tag(buffer, NULL, "language", ctx->lang, "language-set", TRUE, (void *) 0); gtk_text_buffer_get_iter_at_mark(buffer, &start, ctx->start[id]); gtk_text_buffer_get_end_iter(buffer, &end); gtk_text_buffer_apply_tag(buffer, lang, &start, &end); ctx->lang = NULL; } } else { struct array value; value = html_get_attribute(tag, HTML_ATTR_LANG); if (value.data && value.size > 0) { GtkTextIter iter; ctx->lang = g_strndup(value.data, value.size); ctx->html_view->to_free = g_slist_prepend( ctx->html_view->to_free, deconstify_gchar(ctx->lang)); gtk_text_buffer_get_end_iter(buffer, &iter); ctx->start[id] = gtk_text_buffer_create_mark(buffer, NULL, &iter, TRUE); } } case HTML_TAG_HEAD: case HTML_TAG_META: case HTML_TAG_SPAN: case HTML_TAG_COL: case HTML_TAG_DD: case HTML_TAG_TBODY: case HTML_TAG_DOCTYPE: case HTML_TAG_UNKNOWN: break; case NUM_HTML_TAG: g_assert_not_reached(); } if (style) { if (closing) { if (ctx->start[id]) { GtkTextIter start, end; gtk_text_buffer_get_iter_at_mark(buffer, &start, ctx->start[id]); gtk_text_buffer_get_end_iter(buffer, &end); gtk_text_buffer_apply_tag_by_name(buffer, style, &start, &end); ctx->start[id] = NULL; } } else { GtkTextIter iter; gtk_text_buffer_get_end_iter(buffer, &iter); ctx->start[id] = gtk_text_buffer_create_mark(buffer, NULL, &iter, TRUE); } } if (text) { GtkTextIter iter; gtk_text_buffer_get_end_iter(buffer, &iter); gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, text, (-1), attr, (void *) 0); } }