Esempio n. 1
0
/**
 * Process returned value from GetConnectionTypeInfo().
 *
 * @return walloc()'ed structure (whose size is written in lenp) containing
 * the decompiled arguments, or NULL if the returned arguments cannot be
 * processed.
 */
static void *
upnp_ctrl_ret_GetConnectionTypeInfo(nv_table_t *ret, size_t *lenp)
{
	struct upnp_GetConnectionTypeInfo *r;
	const char *type, *possible;

	type = nv_table_lookup_str(ret, "NewConnectionType");
	if (NULL == type)
		return NULL;

	possible = nv_table_lookup_str(ret, "NewPossibleConnectionTypes");
	if (NULL == possible)
		return NULL;

	/*
	 * We can freely reference the memory from the name/value table since
	 * that table will remain alive until we are done with user notification.
	 */

	WALLOC(r);
	r->connection_type = type;
	r->possible_types = possible;

	*lenp = sizeof *r;

	return r;
}
Esempio n. 2
0
/**
 * Parse argument from specified name/value table into a boolean.
 *
 * @param nvt		the name/value table holding arguments
 * @param name		the argument name whose value we need to parse
 * @param valp		where to put the parsed value
 *
 * @return TRUE if OK with the boolean filled in, FALSE on failure.
 */
static gboolean
upnp_ctrl_get_boolean(nv_table_t *nvt, const char *name, gboolean *valp)
{
	const char *value;
	gboolean val;

	value = nv_table_lookup_str(nvt, name);
	if (NULL == value)
		return FALSE;

	if (0 == strcmp(value, ZERO))
		val = FALSE;
	else if (0 == strcmp(value, ONE))
		val = TRUE;
	else if (0 == strcasecmp(value, "false"))
		val = FALSE;
	else if (0 == strcasecmp(value, "true"))
		val = TRUE;
	else if (0 == strcasecmp(value, "no"))
		val = FALSE;
	else if (0 == strcasecmp(value, "yes"))
		val = TRUE;
	else
		return FALSE;

	*valp = val;
	return TRUE;
}
Esempio n. 3
0
/**
 * Parse argument from specified name/value table into an IP address.
 *
 * @param nvt		the name/value table holding arguments
 * @param name		the argument name whose value we need to parse
 * @param addrp		where to put the parsed address
 *
 * @return TRUE if OK with the address filled in, FALSE on failure.
 */
static gboolean
upnp_ctrl_get_addr(nv_table_t *nvt, const char *name, host_addr_t *addrp)
{
	const char *ip;
	
	ip = nv_table_lookup_str(nvt, name);
	if (NULL == ip)
		return FALSE;

	return string_to_host_addr(ip, NULL, addrp);
}
Esempio n. 4
0
/**
 * Allocate a prefix as a shorthand for the URI.
 *
 * @return prefix string to use, which will be freed by symbol tables
 * when leaving scope.
 */
static const char *
xfmt_new_prefix(struct xfmt_pass2 *xp2, const char *uri)
{
    const char *prefix = NULL;
    bool free_prefix = FALSE;

    /* The URI must not already exist in the symbol table */
    g_assert(NULL == symtab_lookup(xp2->uris, uri));

    /*
     * Check whether user has a preference for the prefix to use.
     *
     * If there is a prefix, there must be no identical prefix in scope
     * currently.
     */

    if (xp2->uri2prefix != NULL)
        prefix = nv_table_lookup_str(xp2->uri2prefix, uri);

    if (prefix != NULL) {
        const char *used_uri = symtab_lookup(xp2->prefixes, prefix);

        if (used_uri != NULL) {
            g_carp("XFMT cannot use prefix '%s' for '%s': "
                   "already used by '%s'", prefix, uri, used_uri);
            prefix = NULL;
        }
    }

    /*
     * Allocate a new prefix if required.
     */

    if (NULL == prefix) {
        prefix = h_strdup_printf("ns%u", xp2->pcount++);
        free_prefix = TRUE;
    }

    /*
     * Record associations in the symbol tables.
     */

    xfmt_ns_declare(xp2, prefix, uri, free_prefix);

    return prefix;
}
Esempio n. 5
0
/**
 * Parse argument from specified name/value table into an unsigned 32-bit.
 *
 * @param nvt		the name/value table holding arguments
 * @param name		the argument name whose value we need to parse
 * @param valp		where to put the parsed value
 *
 * @return TRUE if OK with the value filled in, FALSE on failure.
 */
static gboolean
upnp_ctrl_get_uint32(nv_table_t *nvt, const char *name, guint32 *valp)
{
	const char *value;
	guint32 val;
	int error;

	value = nv_table_lookup_str(nvt, name);
	if (NULL == value)
		return FALSE;

	val = parse_uint32(value, NULL, 10, &error);
	if (error)
		return FALSE;

	*valp = val;
	return TRUE;
}
Esempio n. 6
0
/**
 * Process returned value from GetSpecificPortMappingEntry().
 *
 * @return walloc()'ed structure (whose size is written in lenp) containing
 * the decompiled arguments, or NULL if the returned arguments cannot be
 * processed.
 */
static void *
upnp_ctrl_ret_GetSpecificPortMappingEntry(nv_table_t *ret, size_t *lenp)
{
	struct upnp_GetSpecificPortMappingEntry *r;
	host_addr_t addr;
	guint16 port;
	gboolean enabled;
	const char *description;
	time_delta_t lease;

	if (!upnp_ctrl_get_uint16(ret, ARG_INTERNAL_PORT, &port))
		return NULL;

	if (!upnp_ctrl_get_addr(ret, ARG_INTERNAL_CLIENT, &addr))
		return NULL;

	if (!upnp_ctrl_get_boolean(ret, ARG_ENABLED, &enabled))
		return NULL;

	description = nv_table_lookup_str(ret, ARG_PORTMAP_DESC);
	if (NULL == description)
		return NULL;

	if (!upnp_ctrl_get_time_delta(ret, ARG_LEASE_DURATION, &lease))
		return NULL;

	/*
	 * We can freely reference the memory from the name/value table since
	 * that table will remain alive until we are done with user notification.
	 */

	WALLOC(r);
	r->internal_port = port;
	r->internal_client = addr;
	r->enabled = enabled;
	r->description = description;
	r->lease_duration = lease;
	*lenp = sizeof *r;

	return r;
}