--- libaitrpc/src/lists.c 2010/06/24 11:01:46 1.1.2.3 +++ libaitrpc/src/lists.c 2010/07/07 15:18:22 1.1.2.6 @@ -2,6 +2,28 @@ /* + * rpc_srv_retValsCall() Declare return variables for RPC call and zeroed values + (for safe handling return values, use this!) + * @call = RPC function call + * @return_vals = Number of return variables + * return: NULL error, !=NULL array with return values for RPC call with return_vals items + */ +inline rpc_val_t * +rpc_srv_retValsCall(rpc_func_t * __restrict call, int return_vals) +{ + rpc_val_t *v = NULL; + + if (rpc_srv_declValsCall(call, return_vals) == -1) + return NULL; + else + rpc_srv_zeroValsCall(call); + if (rpc_srv_getValsCall(call, &v) == -1) + return NULL; + + return v; +} + +/* * rpc_srv_freeValsCall() Free return variables for RPC call * @call = RPC function call * return: none @@ -13,7 +35,9 @@ rpc_srv_freeValsCall(rpc_func_t * __restrict call) } /* - * rpc_srv_declValsCall() Declare return variables for RPC call + * rpc_srv_declValsCall() Declare return variables for RPC call, + if already allocated memory for RPC call return values + function reallocate used space with return_vals count elements * @call = RPC function call * @return_vals = Number of return variables * return: -1 error, !=-1 ok @@ -26,8 +50,8 @@ rpc_srv_declValsCall(rpc_func_t * __restrict call, int if (!call || return_vals < 0) { rpc_SetErr(EINVAL, "Error:: Invalid parameter can`t declare return variables for RPC call...\n"); return -1; - } else - call->func_args = return_vals; + } /* else + call->func_args = return_vals; */ if (!return_vals) { if (call->func_vals) { @@ -43,16 +67,16 @@ rpc_srv_declValsCall(rpc_func_t * __restrict call, int call->func_vals = ptr; } - return call->func_args; + return return_vals; } /* - * rpc_srv_delValsCall() Clean values from return variables of RPC call + * rpc_srv_zeroValsCall() Clean values from return variables of RPC call * @call = RPC function call * return: -1 error, !=-1 Returned number of cleaned RPC variables */ inline int -rpc_srv_delValsCall(rpc_func_t * __restrict call) +rpc_srv_zeroValsCall(rpc_func_t * __restrict call) { if (!call) { rpc_SetErr(EINVAL, "Error:: Invalid parameter can`t delete return variables ...\n"); @@ -113,7 +137,7 @@ rpc_srv_getValsCall(rpc_func_t * __restrict call, rpc_ * @srv = RPC Server instance * @csModule = Module name, if NULL self binary * @csFunc = Function name - * @args = Number of function arguments + * @args = Number of return function arguments, use for restriction case! * return: -1 error or 0 register ok */ int @@ -144,6 +168,8 @@ rpc_srv_registerCall(rpc_srv_t * __restrict srv, const func->func_tag = crcFletcher16((u_short*) str, (MAXPATHLEN + UCHAR_MAX + 1) / 2); func->func_hash = hash_fnv((char*) str, MAXPATHLEN + UCHAR_MAX + 1); + func->func_parent = srv; + if (rpc_srv_declValsCall(func, args) == -1) { free(func); return -1; @@ -285,9 +311,10 @@ rpc_srv_getBLOB(rpc_srv_t * __restrict srv, uint32_t v return NULL; } - for (b = srv->srv_blob.blobs; b; b = b->blob_next) + for (b = srv->srv_blob.blobs; b; b = b->blob_next) { if (b->blob_var == var) break; + } return b; } @@ -296,7 +323,7 @@ rpc_srv_getBLOB(rpc_srv_t * __restrict srv, uint32_t v * rpc_srv_registerBLOB() Register new BLOB to server * @srv = RPC Server instance * @len = BLOB length - * return: -1 error or 0 register ok + * return: NULL error or new registered BLOB */ rpc_blob_t * rpc_srv_registerBLOB(rpc_srv_t * __restrict srv, size_t len)