--- libelwix/src/vars.c 2013/05/30 09:07:34 1.4 +++ libelwix/src/vars.c 2013/08/22 08:48:08 1.4.20.3 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: vars.c,v 1.4 2013/05/30 09:07:34 misho Exp $ +* $Id: vars.c,v 1.4.20.3 2013/08/22 08:48:08 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -123,6 +123,7 @@ vars2buffer(u_char * __restrict buf, int buflen, int b break; case buffer: case string: + case ptr: if (AIT_LEN(val) > buflen - Limit) { elwix_SetErr(EMSGSIZE, "Short buffer buflen=%d " "needed min %d", buflen, Limit + AIT_LEN(val)); @@ -218,7 +219,8 @@ buffer2vars(u_char * __restrict buf, int buflen, int v val->val.net = le64toh(v[i].val.net); break; case data: - /* WARNING:: remap data type to buffer */ + case ptr: + /* WARNING:: remap data and ptr type to buffer! */ val->val_type = buffer; case buffer: case string: @@ -413,6 +415,36 @@ ait_freeVars(array_t ** __restrict vars) ait_clrVars(*vars); array_Free(*vars); array_Destroy(vars); +} + +/* + * ait_resideVars() - Calculate footprint of resided variables into array + * + * @vars = Variable array + * return: bytes for whole array + */ +size_t +ait_resideVars(array_t * __restrict vars) +{ + size_t ret = 0; + register int i; + + if (vars) { + ret = array_Size(vars) * sizeof(ait_val_t); + for (i = 0; i < array_Size(vars); i++) + switch (AIT_TYPE(array(vars, i, ait_val_t*))) { + case buffer: + case string: + case data: + case ptr: + ret += AIT_LEN(array(vars, i, ait_val_t*)); + break; + default: + break; + } + } + + return ret; }