version 1.6.2.1, 2012/03/12 16:28:09
|
version 1.7, 2012/03/15 01:55:33
|
Line 90 rpc_srv_getVars(rpc_func_t * __restrict call, array_t
|
Line 90 rpc_srv_getVars(rpc_func_t * __restrict call, array_t
|
return io_arraySize(call->func_vars); |
return io_arraySize(call->func_vars); |
} |
} |
|
|
static inline int | /* --------------------------------------------------------- */ |
calcHashes(rpc_func_t * __restrict func, const char *csModule, const char *csFunc) | |
{ | |
char *str = NULL; | |
int len = 0; | |
|
|
assert(func && csFunc); |
|
|
|
/* set function name */ |
|
func->func_name = (u_char*) csFunc; |
|
len = strlen(csFunc) + 3; /* extra 3 bytes, because add string "__" and 0 */ |
|
/* set module name if exists */ |
|
if (csModule) { |
|
func->func_file = (u_char*) csModule; |
|
len += strlen(csModule); |
|
} |
|
/* align len to 2 */ |
|
len = (len + 1) & ~1; |
|
|
|
/* prepare hash source string */ |
|
str = malloc(len); |
|
if (!str) { |
|
LOGERR; |
|
return -1; |
|
} else { |
|
memset(str, 0, len); |
|
if (func->func_file) |
|
strlcpy((char*) str, csModule, len); |
|
strlcat((char*) str, "__", len); |
|
strlcat((char*) str, csFunc, len); |
|
} |
|
|
|
func->func_tag = crcFletcher16((u_short*) str, len / 2); |
|
func->func_hash = hash_fnv((char*) str, len); |
|
|
|
free(str); |
|
return len; |
|
} |
|
|
|
// --------------------------------------------------------- |
|
|
|
/* |
/* |
* rpc_srv_registerCall() - Register call to RPC server |
* rpc_srv_registerCall() - Register call to RPC server |
* |
* |
Line 156 rpc_srv_registerCall(rpc_srv_t * __restrict srv, const
|
Line 117 rpc_srv_registerCall(rpc_srv_t * __restrict srv, const
|
} else |
} else |
memset(func, 0, sizeof(rpc_func_t)); |
memset(func, 0, sizeof(rpc_func_t)); |
|
|
/* set function name */ |
|
func->func_name = strdup(csFunc); |
|
/* set module name if exists */ |
|
if (csModule) |
|
func->func_file = strdup(csModule); |
|
|
|
/* calculate hashes */ |
/* calculate hashes */ |
if (calcHashes(func, func->func_file, func->func_name) == -1) { | if (rpc_calcHashes(func, csModule, csFunc) == -1) { |
free(func->func_name); | AIT_FREE_VAL(&func->func_name); |
if (func->func_file) | AIT_FREE_VAL(&func->func_file); |
free(func->func_file); | |
free(func); |
free(func); |
return -1; |
return -1; |
} |
} |
Line 175 rpc_srv_registerCall(rpc_srv_t * __restrict srv, const
|
Line 129 rpc_srv_registerCall(rpc_srv_t * __restrict srv, const
|
|
|
/* allocate return variables */ |
/* allocate return variables */ |
if (args > 0 && rpc_srv_allocVars(func, args) == -1) { |
if (args > 0 && rpc_srv_allocVars(func, args) == -1) { |
free(func->func_name); | AIT_FREE_VAL(&func->func_name); |
if (func->func_file) | AIT_FREE_VAL(&func->func_file); |
free(func->func_file); | |
free(func); |
free(func); |
return -1; |
return -1; |
} |
} |
Line 210 rpc_srv_unregisterCall(rpc_srv_t * __restrict srv, con
|
Line 163 rpc_srv_unregisterCall(rpc_srv_t * __restrict srv, con
|
memset(&func, 0, sizeof func); |
memset(&func, 0, sizeof func); |
|
|
/* calculate hashes */ |
/* calculate hashes */ |
if (calcHashes(&func, csModule, csFunc) == -1) | if (rpc_calcHashes(&func, csModule, csFunc) == -1) |
return -1; |
return -1; |
|
|
pthread_mutex_lock(&srv->srv_mtx); |
|
f = rpc_srv_getCall(srv, func.func_tag, func.func_hash); |
f = rpc_srv_getCall(srv, func.func_tag, func.func_hash); |
|
AIT_FREE_VAL(&func.func_name); |
|
AIT_FREE_VAL(&func.func_file); |
if (!f) /* not found element for unregister */ |
if (!f) /* not found element for unregister */ |
return 0; |
return 0; |
|
|
|
pthread_mutex_lock(&srv->srv_mtx); |
/* remove from list of functions */ |
/* remove from list of functions */ |
if (srv->srv_funcs == f) /* if is 1st element */ |
if (srv->srv_funcs == f) /* if is 1st element */ |
srv->srv_funcs = srv->srv_funcs->func_next; |
srv->srv_funcs = srv->srv_funcs->func_next; |
Line 226 rpc_srv_unregisterCall(rpc_srv_t * __restrict srv, con
|
Line 181 rpc_srv_unregisterCall(rpc_srv_t * __restrict srv, con
|
curr->func_next = curr->func_next->func_next; |
curr->func_next = curr->func_next->func_next; |
} |
} |
io_freeVars(&f->func_vars); |
io_freeVars(&f->func_vars); |
|
AIT_FREE_VAL(&f->func_name); |
|
AIT_FREE_VAL(&f->func_file); |
free(f); |
free(f); |
pthread_mutex_unlock(&srv->srv_mtx); |
pthread_mutex_unlock(&srv->srv_mtx); |
|
|
Line 268 rpc_srv_getCall(rpc_srv_t * __restrict srv, uint16_t t
|
Line 225 rpc_srv_getCall(rpc_srv_t * __restrict srv, uint16_t t
|
rpc_func_t * |
rpc_func_t * |
rpc_srv_getFunc(rpc_srv_t * __restrict srv, const char *csModule, const char *csFunc) |
rpc_srv_getFunc(rpc_srv_t * __restrict srv, const char *csModule, const char *csFunc) |
{ |
{ |
rpc_func_t func; | rpc_func_t func, *f = NULL; |
|
|
if (!srv || !csFunc) { |
if (!srv || !csFunc) { |
rpc_SetErr(EINVAL, "Invalid parameter can`t get function"); |
rpc_SetErr(EINVAL, "Invalid parameter can`t get function"); |
Line 277 rpc_srv_getFunc(rpc_srv_t * __restrict srv, const char
|
Line 234 rpc_srv_getFunc(rpc_srv_t * __restrict srv, const char
|
memset(&func, 0, sizeof(rpc_func_t)); |
memset(&func, 0, sizeof(rpc_func_t)); |
|
|
/* calculate hashes */ |
/* calculate hashes */ |
if (calcHashes(&func, csModule, csFunc) == -1) | if (rpc_calcHashes(&func, csModule, csFunc) == -1) |
return NULL; |
return NULL; |
|
|
return rpc_srv_getCall(srv, func.func_tag, func.func_hash); | f = rpc_srv_getCall(srv, func.func_tag, func.func_hash); |
| |
| AIT_FREE_VAL(&func.func_name); |
| AIT_FREE_VAL(&func.func_file); |
| return f; |
} |
} |
|
|
// --------------------------------------------------------- |
// --------------------------------------------------------- |
Line 375 rpc_srv_unregisterBLOB(rpc_srv_t * __restrict srv, uin
|
Line 336 rpc_srv_unregisterBLOB(rpc_srv_t * __restrict srv, uin
|
|
|
return 1; |
return 1; |
} |
} |
|
|
|
/* |
|
* rpc_calcHashes() - Calculate hashes for RPC call |
|
* |
|
* @func = function |
|
* @csModule = Module name, if NULL self binary |
|
* @csFunc = Function name |
|
* return: -1 error or 0 ok |
|
*/ |
|
int |
|
rpc_calcHashes(rpc_func_t * __restrict func, const char *csModule, const char *csFunc) |
|
{ |
|
char *str = NULL; |
|
int len = 0; |
|
|
|
assert(func && csFunc); |
|
|
|
/* set function name */ |
|
AIT_SET_STR(&func->func_name, csFunc); |
|
len = strlen(csFunc) + 3; /* extra 3 bytes, because add string "__" and 0 */ |
|
/* set module name if exists */ |
|
if (csModule) { |
|
AIT_SET_STR(&func->func_file, csModule); |
|
len += strlen(csModule); |
|
} |
|
/* align len to 2 */ |
|
len = io_align(len, 1); |
|
|
|
/* prepare hash source string */ |
|
str = malloc(len); |
|
if (!str) { |
|
LOGERR; |
|
return -1; |
|
} else { |
|
memset(str, 0, len); |
|
if (csModule) |
|
strlcpy((char*) str, csModule, len); |
|
strlcat((char*) str, "__", len); |
|
strlcat((char*) str, csFunc, len); |
|
} |
|
|
|
func->func_tag = crcFletcher16((u_short*) str, len / 2); |
|
func->func_hash = hash_fnv((char*) str, len); |
|
|
|
free(str); |
|
return len; |
|
} |
|
|