Module: kamailio Branch: master Commit: 0669b71f52e5c5e1ee942921251787e28c968ea4 URL: https://github.com/kamailio/kamailio/commit/0669b71f52e5c5e1ee942921251787e2...
Author: Vicente Hernando vhernando@systemonenoc.com Committer: Vicente Hernando vhernando@systemonenoc.com Date: 2019-06-27T12:38:44+02:00
call_obj: KEMI functions call_obj.get and call_obj.free
---
Modified: src/modules/call_obj/call_obj_mod.c
---
Diff: https://github.com/kamailio/kamailio/commit/0669b71f52e5c5e1ee942921251787e2... Patch: https://github.com/kamailio/kamailio/commit/0669b71f52e5c5e1ee942921251787e2...
---
diff --git a/src/modules/call_obj/call_obj_mod.c b/src/modules/call_obj/call_obj_mod.c index c8bc1786f0..1b5decb24c 100644 --- a/src/modules/call_obj/call_obj_mod.c +++ b/src/modules/call_obj/call_obj_mod.c @@ -9,6 +9,7 @@ #include "../../core/rpc.h" #include "../../core/rpc_lookup.h" #include "../../core/trim.h" +#include "../../core/kemi.h"
MODULE_VERSION
@@ -363,3 +364,82 @@ static int w_call_obj_free(struct sip_msg* msg, char* num_obj)
return 1; } + +/** + * Get a free object. + * + * /return -1 on error. + * /return number of free object on success. + */ +static int ki_call_obj_get(sip_msg_t *msg) +{ + str call_id; + if (get_call_id(msg, &call_id)) { + LM_ERR("Cannot get callid header\n"); + goto error; + } + LM_DBG("CallId: %.*s\n", call_id.len, call_id.s); + + uint64_t current_ts; + if (get_timestamp(¤t_ts)) { + LM_ERR("error getting timestamp"); + goto error; + } + + int obj = cobj_get(current_ts, &call_id); + if (obj == -1) { + LM_ERR("Getting object\n"); + goto error; + } + /* obj >= 0 */ + + return obj; + +error: + return -1; +} + +/** + * Free an object. + * + * /param num_obj number of the object to free. + * /return 1 on success. + * /return 0 on error. + */ +static int ki_call_obj_free(sip_msg_t *msg, int num_obj) +{ + if (cobj_free(num_obj)) { + LM_ERR("Freeing object: %d\n", num_obj); + return 0; + } + + return 1; +} + +/** + * + */ +/* clang-format off */ +static sr_kemi_t sr_kemi_call_obj_exports[] = { + { str_init("call_obj"), str_init("get"), + SR_KEMIP_INT, ki_call_obj_get, + { SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE, + SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE } + }, + { str_init("call_obj"), str_init("free"), + SR_KEMIP_INT, ki_call_obj_free, + { SR_KEMIP_INT, SR_KEMIP_NONE, SR_KEMIP_NONE, + SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE } + }, + { {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } } +}; +/* clang-format on */ + +/** + * + */ +int mod_register(char *path, int *dlflags, void *p1, void *p2) +{ + sr_kemi_modules_add(sr_kemi_call_obj_exports); + return 0; +}