Ejemplo n.º 1
0
int 
main(int argc, char* argv[])
{
  vlist_t vl = vlist_create();

  vlist_test(vl);

  vlist_delete(&vl);
  return 0;
}
Ejemplo n.º 2
0
var_t *
vlist_record_from_table(var_t *scheme, var_t *table)
{
	var_t *record = NULL, *vs, *vt;
	ll_t *ll;
	ll_entry_t *pos;
	void *data;
	var_type_t type;
	char *name;

	record = vlist_create(scheme->v_name, VF_KEEPNAME);
	if (record == NULL)
	{
		log_warning("vlist_record: vlist_create failed");
		return NULL;
	}

	ll = scheme->v_data;
	pos = LL_START(ll);

	while ((vs = ll_next(ll, &pos)))
	{
		name = vs->v_name;
		vt = vtable_lookup(table, name);

		if (vt == NULL && vs->v_flags & VF_KEY)
		{
			log_error("vlist_record_from_table: \"%s\" is missing "
				"in vtable and declared as key", name);
			goto error;
		}


		data = vt == NULL ? NULL : vt->v_data;
		type = vt == NULL ? VT_NULL : vt->v_type;

		if (vlist_append_new(record, type, name, data,
			VF_COPY | vs->v_flags) == -1)
		{
			log_warning("vlist_record_from_table: vlist_append_new"
				" failed");
			goto error;
		}
	}

	return record;

error:
	if(record)
	{
		var_delete(record);
	}
	return NULL;
}
Ejemplo n.º 3
0
var_t *
vlist_record(var_t *scheme, ...)
{
	va_list ap;
	var_t *record = NULL, *v;
	int flags;
	void *data;
	ll_t *ll;
	ll_entry_t *pos;

	va_start(ap, scheme);

	record = vlist_create(scheme->v_name, VF_KEEPNAME);
	if (record == NULL)
	{
		log_warning("vlist_record: vlist_create failed");
		return NULL;
	}

	ll = scheme->v_data;
	pos = LL_START(ll);

	while ((v = ll_next(ll, &pos)))
	{
		flags = v->v_flags;
		flags |= VF_KEEPDATA | VF_KEEPNAME;
		flags &= ~(VF_COPYNAME | VF_COPYDATA);

		data = va_arg(ap, void *);

		if (vlist_append_new(record, v->v_type, v->v_name, data, flags)
		    == -1)
		{
			log_warning("vlist_record: vlist_append_new failed");

			var_delete(record);
			return NULL;
		}
	}

	va_end(ap);

	return record;
}
Ejemplo n.º 4
0
var_t *
vlist_scheme(char *scheme, ...)
{
	va_list ap;
	var_t *record = NULL;
	var_type_t type;
	int flags;
	char *name;
	
	record = vlist_create(scheme, VF_COPYNAME);
	if (record == NULL)
	{
		log_warning("vlist_scheme: vlist_create failed");
		return NULL;
	}

	va_start(ap, scheme);

	for (;;)
	{
		name = va_arg(ap, char *);
		if (name == NULL)
		{
			break;
		}

		type = va_arg(ap, var_type_t);
		flags = va_arg(ap, int);

		if (vlist_append_new(record, type, name, NULL, flags) == -1)
		{
			log_warning("vlist_scheme: vlist_append_new failed");

			var_delete(record);
			return NULL;
		}
	}

	va_end(ap);

	return record;
}
Ejemplo n.º 5
0
static var_t *
exp_eval_list(exp_t *exp, var_t *mailspec)
{
	ll_t *exp_list = exp->ex_data;
	ll_entry_t *pos;
	exp_t *exp_item;
	var_t *var_item, *var_list = NULL;

	var_list = vlist_create(NULL, VF_EXP_FREE);
	if (var_list == NULL)
	{
		log_sys_error("exp_eval_list: malloc");
		goto error;
	}

	pos = LL_START(exp_list);
	while ((exp_item = ll_next(exp_list, &pos)))
	{
		var_item = exp_eval(exp_item, mailspec);

		if (vlist_append(var_list, var_item))
		{
			log_sys_error("exp_eval_list: malloc");
			goto error;
		}
	}

	return var_list;


error:

	if (var_list)
	{
		var_delete(var_list);
	}

	return NULL;
}
Ejemplo n.º 6
0
static var_t *
hitlist_record(hitlist_t *hl, var_t *attrs, int load_data)
{
	ll_entry_t *pos;
	var_t *key;
	char *keystr;
	var_t *v;
	var_t *schema = NULL;
	VAR_INT_T zero = 0;
	char *name;

	name = hl->hl_table? hl->hl_table: hl->hl_name;

	schema = vlist_create(name, VF_KEEPNAME);
	if (schema == NULL)
	{
		log_error("hitlist_schema: vlist_create failed");
		goto error;
	}

	pos = LL_START(hl->hl_keys);
	while ((key = ll_next(hl->hl_keys, &pos)))
	{
		// Impossible
		if (key->v_data == NULL)
		{
			log_error("hitlist_schema: key is NULL");
			goto error;
		}

		// Bad configured
		if (key->v_type != VT_STRING)
		{
			log_error("hitlist_scheme: bad configuration %s:"
				" hitlist keys must be strings.", hl->hl_name);
			goto error;
		}

		keystr = key->v_data;

		// Variables
		if (keystr[0] == '$')
		{
			v = acl_variable_get(attrs, keystr);
		}

		// Regular symbol
		else
		{
			v = acl_symbol_get(attrs, keystr);
		}

		if (v == NULL)
		{
			log_error("hitlist_scheme: %s: lookup %s failed",
				hl->hl_name, keystr);
			goto error;
		}

		if (load_data && v->v_data == NULL)
		{
			log_error("hitlist_scheme: %s: key %s is NULL",
				hl->hl_name, keystr);
			goto error;
		}

		if (vlist_append_new(schema, v->v_type, keystr,
			load_data? v->v_data: NULL, VF_COPY | VF_KEY))
		{
			log_error("hitlist_schema: %s: vlist_append_new"
				" failed", hl->hl_name);
			goto error;
		}
	}

	// Add value
	if (vlist_append_new(schema, VT_INT, hl->hl_value_field,
	    load_data? &zero: NULL, VF_COPY))
	{
		log_error("hitlist_schema: %s: vlist_append_new failed for %s",
			hl->hl_name, hl->hl_value_field);
		goto error;
	}

	if (vlist_append_new(schema, VT_INT, hl->hl_expire_field,
	    load_data? &zero: NULL, VF_COPY))
	{
		log_error("hitlist_schema: %s: vlist_append_new failed for %s",
			hl->hl_name, hl->hl_expire_field);
		goto error;
	}

	return schema;

error:
	if (schema != NULL)
	{
		var_delete(schema);
	}

	return NULL;
}