--- libelwix/src/vars.c 2013/05/30 09:07:34 1.4 +++ libelwix/src/vars.c 2015/06/25 00:36:48 1.7.20.1 @@ -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.7.20.1 2015/06/25 00:36:48 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -12,7 +12,7 @@ terms: All of the documentation and software included in the ELWIX and AITNET Releases is copyrighted by ELWIX - Sofia/Bulgaria -Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 +Copyright 2004 - 2015 by Michael Pounov . All rights reserved. Redistribution and use in source and binary forms, with or without @@ -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: @@ -407,12 +409,56 @@ ait_clrVars(array_t * __restrict vars) void ait_freeVars(array_t ** __restrict vars) { + register int i; + ait_val_t *v; + if (!vars || !*vars) return; - ait_clrVars(*vars); - array_Free(*vars); + for (i = 0; i < array_Size(*vars); i++) + if ((v = array(*vars, i, ait_val_t*))) { + /* free memory if isn't zero copy */ + if (!AIT_IN(v)) { + AIT_FREE_VAL(v); + if ((*vars)->arr_data[i]) + e_free((*vars)->arr_data[i]); + } else + AIT_FREE_VAL(v); + (*vars)->arr_data[i] = NULL; + } + (*vars)->arr_last = -1; + 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; }