/** * Short string description for XML node, for debugging purposes. * * This is not a serialization of the XML node for inclusion in a document. * * @param xn node to inspect (may be NULL) * @param buf buffer where value should be printed * @param len buffer length * * @return the length of the resulting string */ size_t xnode_to_string_buf(const xnode_t *xn, char *buf, size_t len) { if (NULL == xn) return g_strlcpy(buf, "{null XML node pointer}", len); xnode_check(xn); switch (xn->type) { case XNODE_T_ELEMENT: if (xn->u.e.ns_uri != NULL) { return str_bprintf(buf, len, "<%s:%s%s>", xn->u.e.ns_uri, xn->u.e.name, xn->u.e.attrs != NULL ? " ..." : ""); } else { return str_bprintf(buf, len, "<%s%s>", xn->u.e.name, xn->u.e.attrs != NULL ? " ..." : ""); } break; case XNODE_T_COMMENT: return str_bprintf(buf, len, "%s", "{XML comment node}"); case XNODE_T_PI: return str_bprintf(buf, len, "<?%s...?>", xn->u.pi.name); case XNODE_T_TEXT: return str_bprintf(buf, len, "%s", "{XML text node}"); case XNODE_T_MAX: g_assert_not_reached(); } return 0; }
/** * Invoked when a newer version is found. */ static void version_new_found(const char *text, bool stable) { static char last_stable[256] = ""; static char last_dev[256] = ""; char s[1024]; if (stable) utf8_strlcpy(last_stable, text, sizeof last_stable); else utf8_strlcpy(last_dev, text, sizeof last_dev); if ('\0' != last_stable[0] && '\0' != last_dev[0]) { str_bprintf(s, sizeof s, _(" - Newer versions available: release %s / from git %s"), last_stable, last_dev); } else if ('\0' != last_stable[0]) { str_bprintf(s, sizeof s, _(" - Newer version available: release %s"), last_stable); } else if ('\0' != last_dev[0]) { str_bprintf(s, sizeof s, _(" - Newer version available: from git %s"), last_dev); } gnet_prop_set_string(PROP_NEW_VERSION_STR, s); }
/** * Fill supplied buffer with the formatted string describing the message. * * @param data start of the G2 message * @param len length of the message * @param buf buffer where formatted string is written * @param buflen length of the destination buffer * * @return the amount of bytes written. */ size_t g2_msg_infostr_to_buf(const void *data, size_t len, char *buf, size_t buflen) { enum g2_msg m; const guid_t *muid = NULL; g_assert(size_is_non_negative(len)); g_assert(size_is_non_negative(buflen)); /* * Check whether we need to decompile the packet to access the GUID, which * is the payload of the root element in the tree. Given the way things * are serialized, that would be the last 16 bytes of the message, so * we don't have to deserialize everything just to access it. */ m = g2_msg_type(data, len); switch (m) { case G2_MSG_Q2: case G2_MSG_QA: case G2_MSG_QH2: if (len > GUID_RAW_SIZE) muid = const_ptr_add_offset(data, len - GUID_RAW_SIZE); /* FALL THROUGH */ default: break; } return str_bprintf(buf, buflen, "/%s (%zu byte%s)%s%s", g2_msg_type_name(m), len, plural(len), NULL == muid ? "" : " #", NULL == muid ? "" : guid_hex_str(muid)); }
/** * Adds the given node to the gui. */ void nodes_gui_add_node(gnet_node_info_t *info) { static const struct node_data zero_data; struct node_data *data; gnet_node_flags_t flags; g_return_if_fail(info); g_return_if_fail(!htable_contains(nodes_handles, info->node_id)); WALLOC(data); *data = zero_data; data->node_id = nid_ref(info->node_id); data->user_agent = info->vendor ? atom_str_get(info->vendor) : NULL; data->country = info->country; data->host_size = w_concat_strings(&data->host, host_addr_port_to_string(info->addr, info->port), (void *) 0); str_bprintf(data->version, sizeof data->version, "%u.%u", info->proto_major, info->proto_minor); guc_node_fill_flags(data->node_id, &flags); nodes_gui_update_node_flags(data, &flags); htable_insert(nodes_handles, data->node_id, data); gtk_list_store_append(nodes_model, &data->iter); gtk_list_store_set(nodes_model, &data->iter, 0, data, (-1)); }
/** * Called from parse_dispatch_lines() on EOF. */ static void ghc_host_eof(struct parse_context *ctx) { char msg[256]; if (GNET_PROPERTY(bootstrap_debug) > 2) g_debug("BOOT GHC all done (%u/%u lines processed)", ctx->processed, ctx->lines); /* * Provide GUI feedback. */ str_bprintf(ARYLEN(msg), NG_("Got %d host from %s", "Got %d hosts from %s", ctx->processed), ctx->processed, http_async_url(ghc_ctx.ha)); gcu_statusbar_message(msg); if (GNET_PROPERTY(bootstrap_debug)) g_debug("BOOT GHC got %d host%s from %s", ctx->processed, plural(ctx->processed), http_async_url(ghc_ctx.ha)); ghc_ctx.ha = NULL; ghc_connecting = FALSE; }
enum shell_reply shell_exec_print(struct gnutella_shell *sh, int argc, const char *argv[]) { property_t prop; shell_check(sh); g_assert(argv); g_assert(argc > 0); if (argc < 2) { shell_set_msg(sh, _("Property missing")); goto error; } prop = gnet_prop_get_by_name(argv[1]); if (prop == NO_PROP) { char buf[120]; str_bprintf(buf, sizeof buf, _("Unknown property \"%s\""), argv[1]); shell_set_msg(sh, buf); goto error; } shell_write(sh, _("Value: ")); shell_write(sh, gnet_prop_to_typed_string(prop)); shell_write(sh, "\n"); shell_set_msg(sh, _("Value found and displayed")); return REPLY_READY; error: return REPLY_ERROR; }
/** * Pretty-printing of node information for logs into the supplied buffers. * * IP address is followed by '*' if the contact's address/port was patched. * IP address is followed by '?' if the UDP message came from another IP * * A "zombie" node is a node retrieved from the persisted routing table that * is not alive. Normally, only alive hosts from which we get traffic are * added, but here we have an instance that is not alive -- a zombie. * * A "cached" node is a node coming from the k-closest root cache. * * A firewalled node is indicated by a trailing "fw" indication. * * @return the buffer where printing was done. */ const char * knode_to_string_buf(const knode_t *kn, char buf[], size_t len) { char host_buf[HOST_ADDR_PORT_BUFLEN]; char vc_buf[VENDOR_CODE_BUFLEN]; char kuid_buf[KUID_HEX_BUFLEN]; knode_check(kn); bin_to_hex_buf(kn->id, KUID_RAW_SIZE, kuid_buf, sizeof kuid_buf); host_addr_port_to_string_buf(kn->addr, kn->port, host_buf, sizeof host_buf); vendor_code_to_string_buf(kn->vcode.u32, vc_buf, sizeof vc_buf); str_bprintf(buf, len, "%s%s%s (%s v%u.%u) [%s] \"%s\", ref=%d%s%s%s%s [%s]", host_buf, (kn->flags & KNODE_F_PCONTACT) ? "*" : "", (kn->flags & KNODE_F_FOREIGN_IP) ? "?" : "", vc_buf, kn->major, kn->minor, kuid_buf, knode_status_to_string(kn->status), kn->refcnt, (kn->status != KNODE_UNKNOWN && !(kn->flags & KNODE_F_ALIVE)) ? " zombie" : "", (kn->flags & KNODE_F_CACHED) ? " cached" : "", (kn->flags & KNODE_F_RPC) ? " RPC" : "", (kn->flags & KNODE_F_FIREWALLED) ? " fw" : "", compact_time(delta_time(tm_time(), kn->first_seen))); return buf; }
/** * Adds the given node to the gui. */ void nodes_gui_add_node(gnet_node_info_t *n) { GtkCList *clist_nodes; const gchar *titles[c_gnet_num]; gchar proto_tmp[32]; gint row; g_assert(n != NULL); str_bprintf(proto_tmp, sizeof proto_tmp, "%d.%d", n->proto_major, n->proto_minor); titles[c_gnet_host] = host_addr_port_to_string(n->addr, n->port); titles[c_gnet_flags] = "..."; titles[c_gnet_user_agent] = n->vendor ? lazy_utf8_to_locale(n->vendor) : "..."; titles[c_gnet_loc] = iso3166_country_cc(n->country); titles[c_gnet_version] = proto_tmp; titles[c_gnet_connected] = "..."; titles[c_gnet_uptime] = "..."; titles[c_gnet_info] = "..."; clist_nodes = GTK_CLIST(gui_main_window_lookup("clist_nodes")); row = gtk_clist_append(clist_nodes, (gchar **) titles); /* override const */ gtk_clist_set_row_data(clist_nodes, row, deconstify_gpointer(nid_ref(n->node_id))); }
/** * @returns the cell contents for the horizon stats table. * * @warning * NB: The static buffers for each column are disjunct. */ const gchar * horizon_stat_str(gint row, c_horizon_t column) { switch (column) { case c_horizon_hops: { static gchar buf[UINT64_DEC_BUFLEN]; str_bprintf(buf, sizeof(buf), "%d", row); return buf; } case c_horizon_nodes: { return guc_hsep_get_static_str(row, HSEP_IDX_NODES); } case c_horizon_files: { return guc_hsep_get_static_str(row, HSEP_IDX_FILES); } case c_horizon_size: { return guc_hsep_get_static_str(row, HSEP_IDX_KIB); } case num_c_horizon: g_assert_not_reached(); } return NULL; }
/** * Pick host at random among the host array. * * @return TRUE if OK. */ static bool uhc_pick(void) { bool success = FALSE; char *uhc; uhc = uhc_get_next(); if (NULL == uhc) { if (GNET_PROPERTY(bootstrap_debug)) g_warning("BOOT ran out of UHCs, switching to GHCs"); ghc_get_hosts(); goto finish; } if (!uhc_get_host_port(uhc, &uhc_ctx.host, &uhc_ctx.port)) { g_warning("cannot parse UDP host cache \"%s\"", uhc); goto finish; } /* * Give GUI feedback. */ { char msg[256]; str_bprintf(msg, sizeof msg, _("Looking for UDP host cache %s"), uhc); gcu_statusbar_message(msg); } success = TRUE; finish: HFREE_NULL(uhc); return success; }
/*** *** Private functions ***/ static gchar * guint_to_str(guint32 i) { static gchar strbuf[UINT32_DEC_BUFLEN]; str_bprintf(strbuf, sizeof(strbuf), "%u", i); return strbuf; }
/** * Convert magnet source to a string representation. * * @return A newly allocated string. */ char * magnet_source_to_string(const struct magnet_source *s) { char *url; g_return_val_if_fail(s, NULL); if (s->url) { url = g_strdup(s->url); } else { char *proxies = NULL; const char *host, *prefix; char prefix_buf[256]; char port_buf[16]; if (s->guid) { char guid_buf[GUID_HEX_SIZE + 1]; guid_to_string_buf(s->guid, guid_buf, sizeof guid_buf); concat_strings(prefix_buf, sizeof prefix_buf, "push://", guid_buf, (void *) 0); prefix = prefix_buf; } else { prefix = "http://"; } port_buf[0] = '\0'; if (s->hostname) { host = s->hostname; if (80 != s->port) { str_bprintf(port_buf, sizeof port_buf, ":%u", (unsigned) s->port); } } else if (s->guid) { proxies = proxies_to_string(s->proxies); host = proxies; } else { host = host_addr_port_to_string(s->addr, s->port); } if (s->path) { url = g_strconcat(prefix, host, port_buf, s->path, (void *) 0); } else if (s->sha1) { url = g_strconcat(prefix, host, port_buf, "/uri-res/N2R?", bitprint_to_urn_string(s->sha1, s->tth), (void *) 0); } else { url = g_strconcat(prefix, host, port_buf, "/", (void *) 0); } HFREE_NULL(proxies); } return url; }
/** * @return a user-friendly description of the version. * NB: returns pointer to static data. */ const char * version_str(const version_t *ver) { static char str[80]; int rw; rw = str_bprintf(str, sizeof(str), "%u.%u", ver->major, ver->minor); if (ver->patchlevel) rw += str_bprintf(&str[rw], sizeof(str)-rw, ".%u", ver->patchlevel); if (ver->tag) { rw += str_bprintf(&str[rw], sizeof(str)-rw, "%c", ver->tag); if (ver->taglevel) rw += str_bprintf(&str[rw], sizeof(str)-rw, "%u", ver->taglevel); } if (ver->build) rw += str_bprintf(&str[rw], sizeof(str)-rw, "-%u", ver->build); if (ver->timestamp) { struct tm *tmp = localtime(&ver->timestamp); rw += str_bprintf(&str[rw], sizeof(str)-rw, " (%d-%02d-%02d)", tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday); } return str; }
NO_INLINE void G_GNUC_COLD assertion_failure_log(const assertion_data * const data, const char * const fmt, ...) { va_list args; const char *msg; assertion_message(data, TRUE); /* * Record the root cause of the assertion failure to be able to log it * in the crash log in case they don't have gdb available. */ crash_assert_failure(data); /* * Record additional message in the crash log as well. */ va_start(args, fmt); msg = crash_assert_logv(fmt, args); va_end(args); /* * Log additional message. */ if (msg != NULL) { char time_buf[18]; char prefix[UINT_DEC_BUFLEN + CONST_STRLEN(" (FATAL-): ")]; unsigned stid = thread_small_id(); DECLARE_STR(4); crash_time(time_buf, sizeof time_buf); print_str(time_buf); if (0 == stid) { print_str(" (FATAL): "); } else { str_bprintf(prefix, sizeof prefix, " (FATAL-%u): ", stid); print_str(prefix); } print_str(msg); print_str("\n"); flush_err_str(); if (log_stdout_is_distinct()) flush_str(STDOUT_FILENO); } assertion_abort(); }
static char * thex_upload_uuid(const struct tth *tth) { static char buf[64]; const char *data; data = tth->data; str_bprintf(buf, sizeof buf, "uuid:%08x-%04x-%04x-%04x-%08x%04x", peek_le32(&data[0]), peek_le16(&data[4]), peek_le16(&data[6]), peek_le16(&data[8]), peek_le32(&data[10]), peek_le16(&data[14])); return buf; }
static void print_node_info(struct gnutella_shell *sh, const gnutella_node_t *n) { gnet_node_flags_t flags; time_delta_t up, con; char buf[1024]; char vendor_escaped[50]; char uptime_buf[8]; char contime_buf[8]; g_return_if_fail(sh); g_return_if_fail(n); if (!node_fill_flags(NODE_ID(n), &flags)) return; con = n->connect_date ? delta_time(tm_time(), n->connect_date) : 0; up = n->up_date ? delta_time(tm_time(), n->up_date) : 0; { const char *vendor; char *escaped; vendor = node_vendor(n); escaped = hex_escape(vendor, TRUE); clamp_strcpy(vendor_escaped, sizeof vendor_escaped, escaped); if (escaped != vendor) { HFREE_NULL(escaped); } } clamp_strcpy(uptime_buf, sizeof uptime_buf, up > 0 ? compact_time(up) : "?"); clamp_strcpy(contime_buf, sizeof contime_buf, con > 0 ? compact_time(con) : "?"); str_bprintf(buf, sizeof buf, "%-21.45s %s %2.2s %6.6s %6.6s %.56s", node_gnet_addr(n), node_flags_to_string(&flags), iso3166_country_cc(n->country), contime_buf, uptime_buf, vendor_escaped); shell_write(sh, buf); shell_write(sh, "\n"); /* Terminate line */ }
static void cell_renderer_func(GtkTreeViewColumn *column, GtkCellRenderer *cell, GtkTreeModel *model, GtkTreeIter *iter, gpointer udata) { static const GValue zero_value; const struct upload_data *data; const gchar *text = NULL; gchar buf[64]; GValue value; if (!gtk_tree_view_column_get_visible(column)) return; value = zero_value; gtk_tree_model_get_value(model, iter, 0, &value); data = g_value_get_pointer(&value); switch ((enum c_us) GPOINTER_TO_UINT(udata)) { case c_us_filename: text = data->filename; break; case c_us_size: text = short_size(data->us->size, show_metric_units()); break; case c_us_attempts: text = uint64_to_string(data->us->attempts); break; case c_us_complete: text = uint64_to_string(data->us->attempts); break; case c_us_norm: str_bprintf(buf, sizeof buf, "%1.3f", data->us->norm); text = buf; break; case c_us_rtime: text = data->us->rtime ? timestamp_to_string(data->us->rtime) : NULL; break; case c_us_dtime: text = data->us->dtime ? timestamp_to_string(data->us->dtime) : NULL; break; case c_us_num: g_assert_not_reached(); } g_object_set(cell, "text", text, (void *) 0); }
/** * Update the row with the given nodeinfo. If row is -1 the row number * is determined by the node_id contained in the gnet_node_info_t. */ static void nodes_gui_update_node_info(gnet_node_info_t *n, gint row) { GtkCList *clist = GTK_CLIST(gui_main_window_lookup("clist_nodes")); g_assert(n != NULL); if (row == -1) { row = gtk_clist_find_row_from_data(clist, deconstify_gpointer(n->node_id)); } if (row != -1) { gchar ver_buf[64]; gnet_node_status_t status; time_t now = tm_time(); if (guc_node_get_status(n->node_id, &status)) { gtk_clist_set_text(clist, row, c_gnet_user_agent, n->vendor ? lazy_utf8_to_locale(n->vendor) : "..."); gtk_clist_set_text(clist, row, c_gnet_loc, deconstify_gchar(iso3166_country_cc(n->country))); str_bprintf(ver_buf, sizeof ver_buf, "%d.%d", n->proto_major, n->proto_minor); gtk_clist_set_text(clist, row, c_gnet_version, ver_buf); if (status.status == GTA_NODE_CONNECTED) gtk_clist_set_text(clist, row, c_gnet_connected, short_uptime(delta_time(now, status.connect_date))); if (status.up_date) gtk_clist_set_text(clist, row, c_gnet_uptime, status.up_date ? short_uptime(delta_time(now, status.up_date)) : "..."); gtk_clist_set_text(clist, row, c_gnet_info, nodes_gui_common_status_str(&status)); } } else { g_warning("%s(): no matching row found", G_STRFUNC); } }
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(); }
/** * 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) { static char buf[64]; /* We assume there will be at least one of O_RDWR, O_RDONLY or O_WRONLY */ str_bprintf(buf, sizeof buf, "%s%s%s%s%s", (flags & O_RDWR) ? "O_RDWR" : (flags & O_WRONLY) ? "O_WRONLY" : (flags & O_RDONLY) ? "O_RDONLY" : (0 == O_RDONLY) ? "O_RDONLY" : "", (flags & O_APPEND) ? " | O_APPEND" : "", (flags & O_CREAT) ? " | O_CREAT" : "", (flags & O_TRUNC) ? " | O_TRUNC" : "", (flags & O_EXCL) ? " | O_EXCL" : ""); return buf; }
/** * Dump field on specified file descriptor. */ static void hfield_dump(const header_field_t *h, FILE *out) { slist_iter_t *iter; bool first; header_field_check(h); g_assert(h->lines); fprintf(out, "%s: ", h->name); first = TRUE; iter = slist_iter_on_head(h->lines); for (/* NOTHING */; slist_iter_has_item(iter); slist_iter_next(iter)) { const char *s; if (first) first = FALSE; else fputs(" ", out); /* Continuation line */ s = slist_iter_current(iter); if (is_printable_iso8859_string(s)) { fputs(s, out); } else { char buf[80]; const char *p = s; int c; size_t len = strlen(s); str_bprintf(buf, sizeof buf, "<%u non-printable byte%s>", (unsigned) len, plural(len)); fputs(buf, out); while ((c = *p++)) { if (is_ascii_print(c) || is_ascii_space(c)) fputc(c, out); else fputc('.', out); /* Less visual clutter than '?' */ } } fputc('\n', out); } slist_iter_free(&iter); }
/** * Watcher callback, invoked when the file from which we read the bogus * addresses changed. */ static void bogons_changed(const char *filename, void *unused_udata) { FILE *f; char buf[80]; int count; (void) unused_udata; f = file_fopen(filename, "r"); if (f == NULL) return; bogons_close(); count = bogons_load(f); str_bprintf(buf, sizeof(buf), "Reloaded %d bogus IP ranges.", count); gcu_statusbar_message(buf); }
/** * Pick a random cache URL among the list we have. * * @return TRUE if OK. */ static bool ghc_pick(void) { bool success = FALSE; char *url; url = ghc_get_next(); if (NULL == url) { if (GNET_PROPERTY(bootstrap_debug)) g_warning("BOOT ran out of GHCs"); goto finish; } g_assert(NULL == ghc_ctx.ha); /* * Give GUI feedback. */ { char msg[256]; str_bprintf(ARYLEN(msg), _("Bootstrapping from %s"), url); gcu_statusbar_message(msg); } ghc_ctx.ha = http_async_get(url, NULL, ghc_data_ind, ghc_error_ind); if (!ghc_ctx.ha) { if (GNET_PROPERTY(bootstrap_debug)) g_warning("BOOT cannot launch a \"GET %s\" HTTP request: %s", url, http_async_strerror(http_async_errno)); goto finish; } parse_context_set(ghc_ctx.ha, GHC_MAX_HOSTS); success = TRUE; finish: HFREE_NULL(url); return success; }
/** * Watcher callback, invoked when the file from which we read the * geographic IP mappings changed. */ static void gip_changed(const char *filename, void *idx_ptr) { FILE *f; char buf[80]; uint count; unsigned idx = pointer_to_uint(idx_ptr); f = file_fopen(filename, "r"); if (f == NULL) return; count = gip_load(f, idx); fclose(f); str_bprintf(buf, sizeof buf, "Reloaded %u geographic IPv%c ranges.", count, GIP_IPV4 == idx ? '4' : '6'); gcu_statusbar_message(buf); }
/** * Send an UDP ping to the host cache. */ static void uhc_send_ping(void) { g_assert(uhc_connecting); guid_random_muid(&uhc_ctx.muid); if (udp_send_ping(&uhc_ctx.muid, uhc_ctx.addr, uhc_ctx.port, TRUE)) { if (GNET_PROPERTY(bootstrap_debug) || GNET_PROPERTY(log_uhc_pings_tx)) { g_debug("BOOT sent UDP SCP ping #%s to %s:%u", guid_hex_str(&uhc_ctx.muid), uhc_ctx.host, uhc_ctx.port); } /* * Give GUI feedback. */ { char msg[256]; str_bprintf(msg, sizeof msg, _("Sent ping to UDP host cache %s:%u"), uhc_ctx.host, uhc_ctx.port); gcu_statusbar_message(msg); } /* * Arm a timer to see whether we should not try to ping another * host cache if we don't get a timely reply. */ g_assert(uhc_ctx.timeout_ev == NULL); uhc_ctx.timeout_ev = cq_main_insert(UHC_TIMEOUT, uhc_ping_timeout, NULL); } else { g_warning("BOOT failed to send UDP SCP to %s", host_addr_port_to_string(uhc_ctx.addr, uhc_ctx.port)); uhc_try_next(); } }
/** * Dump version to specified logging agent. */ void G_COLD version_string_dump_log(logagent_t *la, bool full) { static char buf[80]; log_info(la, "%s", version_build_string()); if (!full) return; #ifndef OFFICIAL_BUILD log_info(la, "(unofficial build, accessing \"%s\")", PACKAGE_SOURCE_DIR); #endif /* * Flag only when compiled with --disable-malloc since this is not the * default setup. It is important to know that fact easily from the * command line. */ #ifndef USE_MY_MALLOC log_info(la, "(libraries are using the system's malloc() implementation)"); #endif str_bprintf(buf, sizeof buf, "GLib %u.%u.%u", glib_major_version, glib_minor_version, glib_micro_version); if ( GLIB_MAJOR_VERSION != glib_major_version || GLIB_MINOR_VERSION != glib_minor_version || GLIB_MICRO_VERSION != glib_micro_version ) { str_bcatf(buf, sizeof buf, " (compiled against %u.%u.%u)", GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION, GLIB_MICRO_VERSION); } log_info(la, "%s", buf); if (gtk_version_string() != NULL) log_info(la, "%s", gtk_version_string()); if (tls_version_string() != NULL) log_info(la, "%s", tls_version_string()); }
/** * Updates vendor, version and info column. */ static void nodes_gui_update_node_info(struct node_data *data, gnet_node_info_t *info) { gnet_node_status_t status; g_assert(info != NULL); if (data == NULL) data = find_node(info->node_id); g_assert(NULL != data); g_assert(data->node_id == info->node_id); if (guc_node_get_status(info->node_id, &status)) { str_bprintf(data->version, sizeof data->version, "%u.%u", info->proto_major, info->proto_minor); atom_str_free_null(&data->user_agent); data->user_agent = info->vendor ? atom_str_get(info->vendor) : NULL; data->country = info->country; } }
static void print_download_info(gnet_fi_t handle, void *udata) { struct gnutella_shell *sh = udata; gnet_fi_status_t status; gnet_fi_info_t *info; char buf[1024]; shell_check(sh); info = guc_fi_get_info(handle); g_return_if_fail(info); guc_fi_get_status(handle, &status); str_bprintf(ARYLEN(buf), "ID: %s", guid_to_string(info->guid)); shell_write(sh, buf); shell_write(sh, "\n"); /* Terminate line */ str_bprintf(ARYLEN(buf), "Filename: \"%s\"", info->filename); shell_write(sh, buf); shell_write(sh, "\n"); /* Terminate line */ str_bprintf(ARYLEN(buf), "Hash: %s", info->sha1 ? sha1_to_urn_string(info->sha1) : "<none>"); shell_write(sh, buf); shell_write(sh, "\n"); /* Terminate line */ str_bprintf(ARYLEN(buf), "Status: %s", file_info_status_to_string(&status)); shell_write(sh, buf); shell_write(sh, "\n"); /* Terminate line */ str_bprintf(ARYLEN(buf), "Size: %s", compact_size(status.size, GNET_PROPERTY(display_metric_units))); shell_write(sh, buf); shell_write(sh, "\n"); /* Terminate line */ str_bprintf(ARYLEN(buf), "Done: %u%% (%s)", filesize_per_100(status.size, status.done), compact_size(status.done, GNET_PROPERTY(display_metric_units))); shell_write(sh, buf); shell_write(sh, "\n"); /* Terminate line */ shell_write(sh, "--\n"); guc_fi_free_info(info); }
/** * @note For maximum safety this is kept signal-safe, so that we can * even use assertions in signal handlers. See also: * http://www.opengroup.org/onlinepubs/009695399/functions/xsh_chap02_04.html */ static G_GNUC_COLD void assertion_message(const assertion_data * const data, int fatal) { char line_buf[22]; char time_buf[18]; char prefix[UINT_DEC_BUFLEN + CONST_STRLEN(" (WARNING-): ")]; unsigned stid; DECLARE_STR(16); crash_time(time_buf, sizeof time_buf); stid = thread_small_id(); print_str(time_buf); if (0 == stid) { print_str(fatal ? " (FATAL): " : " (WARNING): "); } else { str_bprintf(prefix, sizeof prefix, " (%s-%u): ", fatal ? "FATAL" : "WARNING", stid); print_str(prefix); } if (data->expr) { print_str("Assertion failure at "); } else { print_str("Code should not have been reached at "); } print_str(data->file); print_str(":"); print_str(print_number(line_buf, sizeof line_buf, data->line)); if (data->expr) { print_str(": \""); print_str(data->expr); print_str("\""); } print_str("\n"); flush_err_str(); if (log_stdout_is_distinct()) flush_str(STDOUT_FILENO); }
static void print_upload_info(struct gnutella_shell *sh, const struct gnet_upload_info *info) { char buf[1024]; g_return_if_fail(sh); g_return_if_fail(info); str_bprintf(buf, sizeof buf, "%-3.3s %-16.40s %s %s@%s %s%s%s", info->encrypted ? "(E)" : "", host_addr_to_string(info->addr), iso3166_country_cc(info->country), compact_size(info->range_end - info->range_start, GNET_PROPERTY(display_metric_units)), short_size(info->range_start, GNET_PROPERTY(display_metric_units)), info->name ? "\"" : "<", info->name ? info->name : "none", info->name ? "\"" : ">"); shell_write(sh, buf); shell_write(sh, "\n"); /* Terminate line */ }