Exemplo n.º 1
0
/**
 * Same as xnode_to_string().
 */
const char *
xnode_to_string2(const xnode_t *xn)
{
	buf_t *b = buf_private(G_STRFUNC, 256);
	char *p = buf_data(b);

	xnode_to_string_buf(xn, p, buf_size(b));
	return p;
}
Exemplo n.º 2
0
/**
 * @return the "address:port" string for a host
 */
const char *
gnet_host_to_string2(const gnet_host_t *h)
{
	buf_t *b = buf_private(G_STRFUNC, HOST_ADDR_PORT_BUFLEN);
	char *p = buf_data(b);

	gnet_host_to_string_buf(h, p, buf_size(b));
	return p;
}
Exemplo n.º 3
0
/**
 * Prints the host address ``ha'' followed by ``port'' to a static buffer.
 *
 * @param ha the host address.
 * @param port the port number.
 *
 * @return a pointer to a static buffer holding a NUL-terminated string
 *         representing the given host address and port.
 */
const char *
port_host_addr_to_string(uint16 port, const host_addr_t ha)
{
	buf_t *b = buf_private(G_STRFUNC, HOST_ADDR_PORT_BUFLEN);
	char *p = buf_data(b);
	size_t len, n = buf_size(b);

	len = host_port_addr_to_string_buf(port, ha, p, n);
	g_assert(len < n);
	return p;
}
Exemplo n.º 4
0
/**
 * Same as host_addr_to_string(), but in another static buffer.
 */
const char *
host_addr_to_string2(const host_addr_t ha)
{
	buf_t *b = buf_private(G_STRFUNC, HOST_ADDR_BUFLEN);
	char *p = buf_data(b);
	size_t len, n = buf_size(b);

	len = host_addr_to_string_buf(ha, p, n);
	g_assert(len < n);
	return p;
}
Exemplo n.º 5
0
/**
 * Pretty-print the message information.
 *
 * @param data		start of the G2 message
 * @param len		length of the message
 *
 * @return formatted static string.
 */
const char *
g2_msg_infostr(const void *data, size_t len)
{
	buf_t *b = buf_private(G_STRFUNC, 64);
	char *p = buf_data(b);
	size_t n, sz = buf_size(b);

	n = g2_msg_infostr_to_buf(data, len, p, sz);
	g_assert(n < sz);
	return p;
}
Exemplo n.º 6
0
/**
 * Stringify an UPnP service.
 *
 * @return pointer to static buffer.
 */
const char *
upnp_service_to_string(const upnp_service_t *usd)
{
	buf_t *b = buf_private(G_STRFUNC, 128);

	upnp_service_check(usd);

	buf_printf(b, "\"%s\" v%u at %s",
		upnp_service_type_to_string(usd->type), usd->version, usd->control_url);

	return buf_data(b);
}
Exemplo n.º 7
0
/**
 * 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;
}
Exemplo n.º 8
0
const char *
host_port_to_string(const char *hostname, host_addr_t addr, uint16 port)
{
	buf_t *b = buf_private(G_STRFUNC, MAX_HOSTLEN + HOST_ADDR_PORT_BUFLEN);
	char *p = buf_data(b);

	if (hostname != NULL) {
		char port_buf[UINT32_DEC_BUFLEN];

		uint32_to_string_buf(port, port_buf, sizeof port_buf);
		concat_strings(p, buf_size(b), hostname, ":", port_buf, NULL_PTR);
	} else {
		host_addr_port_to_string_buf(addr, port, p, buf_size(b));
	}
	return p;
}