Пример #1
0
/**
 * 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);
}
Пример #2
0
/**
 * 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);
}