Browse code

call_obj: KEMI functions call_obj.get and call_obj.free

Vicente Hernando authored on 25/06/2019 13:23:41
Showing 1 changed files
... ...
@@ -9,6 +9,7 @@
9 9
 #include "../../core/rpc.h"
10 10
 #include "../../core/rpc_lookup.h"
11 11
 #include "../../core/trim.h"
12
+#include "../../core/kemi.h"
12 13
 
13 14
 MODULE_VERSION
14 15
 
... ...
@@ -363,3 +364,82 @@ static int w_call_obj_free(struct sip_msg* msg, char* num_obj)
363 364
 
364 365
 	return 1;
365 366
 }
367
+
368
+/**
369
+ * Get a free object.
370
+ *
371
+ * /return -1 on error.
372
+ * /return number of free object on success.
373
+ */
374
+static int ki_call_obj_get(sip_msg_t *msg)
375
+{
376
+	str call_id;
377
+	if (get_call_id(msg, &call_id)) {
378
+		LM_ERR("Cannot get callid header\n");
379
+		goto error;
380
+	}
381
+	LM_DBG("CallId: %.*s\n", call_id.len, call_id.s);
382
+
383
+	uint64_t current_ts;
384
+	if (get_timestamp(&current_ts)) {
385
+		LM_ERR("error getting timestamp");
386
+		goto error;
387
+	}
388
+
389
+	int obj = cobj_get(current_ts, &call_id);
390
+	if (obj == -1) {
391
+		LM_ERR("Getting object\n");
392
+		goto error;
393
+	}
394
+	/* obj >= 0 */
395
+
396
+	return obj;
397
+
398
+error:
399
+	return -1;
400
+}
401
+
402
+/**
403
+ * Free an object.
404
+ *
405
+ * /param num_obj number of the object to free.
406
+ * /return 1 on success.
407
+ * /return 0 on error.
408
+ */
409
+static int ki_call_obj_free(sip_msg_t *msg, int num_obj)
410
+{
411
+	if (cobj_free(num_obj)) {
412
+		LM_ERR("Freeing object: %d\n", num_obj);
413
+		return 0;
414
+	}
415
+
416
+	return 1;
417
+}
418
+
419
+/**
420
+ *
421
+ */
422
+/* clang-format off */
423
+static sr_kemi_t sr_kemi_call_obj_exports[] = {
424
+	{ str_init("call_obj"), str_init("get"),
425
+		SR_KEMIP_INT, ki_call_obj_get,
426
+		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
427
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
428
+	},
429
+	{ str_init("call_obj"), str_init("free"),
430
+	    SR_KEMIP_INT, ki_call_obj_free,
431
+		{ SR_KEMIP_INT, SR_KEMIP_NONE, SR_KEMIP_NONE,
432
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
433
+	},
434
+	{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
435
+};
436
+/* clang-format on */
437
+
438
+/**
439
+ *
440
+ */
441
+int mod_register(char *path, int *dlflags, void *p1, void *p2)
442
+{
443
+	sr_kemi_modules_add(sr_kemi_call_obj_exports);
444
+	return 0;
445
+}