version 1.10.2.1, 2012/07/22 12:23:04
|
version 1.12.4.3, 2012/08/29 13:49:04
|
Line 463 io_freeVar(ait_val_t ** __restrict val)
|
Line 463 io_freeVar(ait_val_t ** __restrict val)
|
} |
} |
} |
} |
|
|
|
/* |
|
* io_makeVar() - Allocate memory and fill variable |
|
* |
|
* @type = type of variable |
|
* @... = arg1 is value of variable |
|
* @... = arg2 is length of variabla. Not required for numbers and strings! |
|
* return: NULL error or new variable, after use free variable with io_freeVar() |
|
*/ |
|
ait_val_t * |
|
io_makeVar(ait_type_t type, ...) |
|
{ |
|
ait_val_t *v = NULL; |
|
va_list lst; |
|
void *p = NULL; |
|
uint32_t len = 0; |
|
uint64_t n = 0LL; |
|
|
|
v = io_allocVar(); |
|
if (!v) |
|
return NULL; |
|
|
|
va_start(lst, type); |
|
switch (type) { |
|
case empty: |
|
v->val_type = (uint8_t) empty; |
|
break; |
|
case ptr: |
|
p = va_arg(lst, void*); |
|
len = va_arg(lst, uint32_t); |
|
AIT_SET_PTR(v, p, len); |
|
break; |
|
case data: |
|
p = va_arg(lst, void*); |
|
len = va_arg(lst, uint32_t); |
|
AIT_SET_DATA(v, p, len); |
|
break; |
|
case buffer: |
|
p = va_arg(lst, void*); |
|
len = va_arg(lst, uint32_t); |
|
AIT_SET_BUF(v, p, len); |
|
break; |
|
case string: |
|
p = va_arg(lst, char*); |
|
AIT_SET_STR(v, (char*) p); |
|
break; |
|
case blob: |
|
n = va_arg(lst, uint32_t); |
|
len = va_arg(lst, uint32_t); |
|
AIT_SET_BLOB(v, n, len); |
|
break; |
|
case f32: |
|
AIT_SET_F32(v, (float) va_arg(lst, double)); |
|
break; |
|
case f64: |
|
AIT_SET_F64(v, va_arg(lst, double)); |
|
break; |
|
case u8: |
|
AIT_SET_U8(v, (uint8_t) va_arg(lst, int)); |
|
break; |
|
case u16: |
|
AIT_SET_U16(v, (uint16_t) va_arg(lst, int)); |
|
break; |
|
case u32: |
|
AIT_SET_U32(v, va_arg(lst, uint32_t)); |
|
break; |
|
case u64: |
|
AIT_SET_U64(v, va_arg(lst, uint64_t)); |
|
break; |
|
case i8: |
|
AIT_SET_I8(v, (int8_t) va_arg(lst, int)); |
|
break; |
|
case i16: |
|
AIT_SET_I16(v, (int16_t) va_arg(lst, int)); |
|
break; |
|
case i32: |
|
AIT_SET_I32(v, va_arg(lst, int32_t)); |
|
break; |
|
case i64: |
|
AIT_SET_I64(v, va_arg(lst, int64_t)); |
|
break; |
|
} |
|
va_end(lst); |
|
|
|
return v; |
|
} |
|
|
static int |
static int |
_cmp_arr_key_asc(const void *a, const void *b) |
_cmp_arr_key_asc(const void *a, const void *b) |
{ |
{ |
Line 567 io_findKeyVars(array_t * __restrict vars, u_short key)
|
Line 653 io_findKeyVars(array_t * __restrict vars, u_short key)
|
io_arrayDestroy(&tmp); |
io_arrayDestroy(&tmp); |
return v; |
return v; |
} |
} |
|
|
|
/* |
|
* io_hashVar() - Generate hash key for variable from string or value |
|
* |
|
* @v = variable |
|
* @key = key string for hash, if =NULL hash will built from variable |
|
* return: hash key |
|
*/ |
|
u_short |
|
io_hashVar(ait_val_t * __restrict v, const char * __restrict key) |
|
{ |
|
void *p; |
|
u_short cksum; |
|
int l; |
|
|
|
if (!v) |
|
return 0; |
|
|
|
if (key) { |
|
p = (void*) key; |
|
l = (strlen(key) + 1) / 2; |
|
} else { |
|
switch (AIT_TYPE(v)) { |
|
case empty: |
|
AIT_KEY(v) = 0; |
|
return 0; |
|
case string: |
|
case buffer: |
|
p = AIT_ADDR(v); |
|
l = AIT_LEN(v) / 2; |
|
break; |
|
case data: |
|
p = v->val_data; |
|
l = AIT_LEN(v) / 2; |
|
break; |
|
default: |
|
p = &AIT_RAW(v); |
|
l = sizeof AIT_RAW(v) / 2; |
|
break; |
|
} |
|
} |
|
|
|
cksum = crcFletcher16((u_short*) p, l); |
|
|
|
if (AIT_BE(v)) |
|
AIT_KEY(v) = htobe16(cksum); |
|
else if (AIT_LE(v)) |
|
AIT_KEY(v) = htole16(cksum); |
|
else |
|
AIT_KEY(v) = cksum; |
|
|
|
return AIT_KEY(v); |
|
} |
|
|
|
/* |
|
* io_hashKeyVars() - Generate hash keys for variables |
|
* |
|
* @vars = Variables |
|
* return -1 error or 0 ok |
|
*/ |
|
inline int |
|
io_hashKeyVars(array_t * __restrict vars) |
|
{ |
|
register int i; |
|
|
|
if (!vars) |
|
return -1; |
|
|
|
for (i = 0; i < io_arraySize(vars); i++) |
|
io_hashVar(io_array(vars, i, ait_val_t*), NULL); |
|
|
|
return 0; |
|
} |
|
|
|
/* |
|
* io_findKeyHash() - Find variable by hash string from array |
|
* |
|
* @vars = Variables |
|
* @key = Search string |
|
* return: NULL error or not found, !=NULL valid element |
|
*/ |
|
inline ait_val_t * |
|
io_findKeyHash(array_t * __restrict vars, const char * __restrict key) |
|
{ |
|
u_short k = 0; |
|
|
|
if (!vars || !key) |
|
return NULL; |
|
|
|
k = crcFletcher16((u_short*) key, (strlen(key) + 1) / 2); |
|
return io_findKeyVars(vars, k); |
|
} |
|
|