예제 #1
0
static as_val *udf_arglist_get(const as_list * l, const uint32_t idx) {
	as_msg_field * field = (as_msg_field *) l->data;

	if ( field != NULL ) {
		as_unpacker unpacker;
		unpacker.buffer = (const unsigned char*)field->data;
		unpacker.length = as_msg_field_get_value_sz(field);
		unpacker.offset = 0;
		if ( unpacker.length == 0 )
			return NULL;

		as_val* item = 0;
		as_val* val = 0;
		int ret = as_unpack_val(&unpacker, &val);

		if (ret == 0 && as_val_type(val) == AS_LIST) {
			item = as_list_get((as_list*)val, idx);
		}
		as_val_destroy(val);
		return item;
	}
	return NULL;
}
예제 #2
0
static int check_bin4(as_record * rec, scan_check * check)
{
	as_val * bin = (as_val *) as_record_get(rec, "bin4");
	if ( !bin ) {
		error("Expected a value in bin('%s'), but got null", "bin4");
		return !(check->failed = true);
	}

	as_list * list = as_list_fromval(bin);
	if ( !list ) {
		error("Expected a list in bin('%s'), but got type %d", "bin4", as_val_type(bin));
		return !(check->failed = true);
	}

	int sz = as_list_size(list);
	if ( sz < 3 ) {
		error("Expected list size of %d, but got %d", 3, sz);
		return !(check->failed = true);
	}

	for ( int i = 0; i < sz; i++ ) {
		as_val * val = as_list_get(list, i);
		if ( !val ) {
			error("Expecting value at %d, but got null", i);
			return !(check->failed = true);
		}

		as_integer * ival = as_integer_fromval(val);
		if ( !ival ) {
			error("Expecting integer at %d, but got type %d", i, as_val_type(val));
			return !(check->failed = true);
		}
	}

	return !(check->failed = false);
}