Browse code

mqueue: kemi functions to retrieve key and value from mqueue

Daniel-Constantin Mierla authored on 07/06/2019 08:36:45
Showing 3 changed files
... ...
@@ -35,39 +35,6 @@
35 35
 
36 36
 #include "mqueue_api.h"
37 37
 
38
-/**
39
- *
40
- */
41
-typedef struct _mq_item
42
-{
43
-	str key;
44
-	str val;
45
-	struct _mq_item *next;
46
-} mq_item_t;
47
-
48
-/**
49
- *
50
- */
51
-typedef struct _mq_head
52
-{
53
-	str name;
54
-	int msize;
55
-	int csize;
56
-	gen_lock_t lock;
57
-	mq_item_t *ifirst;
58
-	mq_item_t *ilast;
59
-	struct _mq_head *next;
60
-} mq_head_t;
61
-
62
-/**
63
- *
64
- */
65
-typedef struct _mq_pv
66
-{
67
-	str *name;
68
-	mq_item_t *item;
69
-	struct _mq_pv *next;
70
-} mq_pv_t;
71 38
 
72 39
 /**
73 40
  *
... ...
@@ -26,6 +26,42 @@
26 26
 #include "../../core/pvar.h"
27 27
 #include "../../core/parser/msg_parser.h"
28 28
 
29
+/**
30
+ *
31
+ */
32
+typedef struct _mq_item
33
+{
34
+	str key;
35
+	str val;
36
+	struct _mq_item *next;
37
+} mq_item_t;
38
+
39
+/**
40
+ *
41
+ */
42
+typedef struct _mq_head
43
+{
44
+	str name;
45
+	int msize;
46
+	int csize;
47
+	gen_lock_t lock;
48
+	mq_item_t *ifirst;
49
+	mq_item_t *ilast;
50
+	struct _mq_head *next;
51
+} mq_head_t;
52
+
53
+/**
54
+ *
55
+ */
56
+typedef struct _mq_pv
57
+{
58
+	str *name;
59
+	mq_item_t *item;
60
+	struct _mq_pv *next;
61
+} mq_pv_t;
62
+
63
+mq_pv_t *mq_pv_get(str *name);
64
+
29 65
 int pv_parse_mq_name(pv_spec_p sp, str *in);
30 66
 int pv_get_mqk(struct sip_msg *msg, pv_param_t *param,
31 67
 		pv_value_t *res);
... ...
@@ -438,6 +438,82 @@ static int ki_mq_pv_free(sip_msg_t* msg, str *mq)
438 438
 /**
439 439
  *
440 440
  */
441
+static sr_kemi_xval_t _sr_kemi_mqueue_xval = {0};
442
+
443
+/**
444
+ *
445
+ */
446
+static sr_kemi_xval_t* ki_mqx_get_mode(sip_msg_t *msg, str *qname, int qtype,
447
+			int rmode)
448
+{
449
+	mq_pv_t *mp = NULL;
450
+
451
+	memset(&_sr_kemi_mqueue_xval, 0, sizeof(sr_kemi_xval_t));
452
+	mp = mq_pv_get(qname);
453
+	if(mp == NULL || mp->item==NULL) {
454
+		sr_kemi_xval_null(&_sr_kemi_mqueue_xval, 0);
455
+		return &_sr_kemi_mqueue_xval;
456
+	}
457
+	_sr_kemi_mqueue_xval.vtype = SR_KEMIP_STR;
458
+	if(qtype==0) {
459
+		_sr_kemi_mqueue_xval.v.s = mp->item->key;
460
+	} else {
461
+		_sr_kemi_mqueue_xval.v.s = mp->item->val;
462
+	}
463
+	return &_sr_kemi_mqueue_xval;
464
+}
465
+
466
+/**
467
+ *
468
+ */
469
+static sr_kemi_xval_t* ki_mqk_get(sip_msg_t *msg, str *qname)
470
+{
471
+	return ki_mqx_get_mode(msg, qname, 0, SR_KEMI_XVAL_NULL_NONE);
472
+}
473
+
474
+/**
475
+ *
476
+ */
477
+static sr_kemi_xval_t* ki_mqk_gete(sip_msg_t *msg, str *qname)
478
+{
479
+	return ki_mqx_get_mode(msg, qname, 0, SR_KEMI_XVAL_NULL_EMPTY);
480
+}
481
+
482
+/**
483
+ *
484
+ */
485
+static sr_kemi_xval_t* ki_mqk_getw(sip_msg_t *msg, str *qname)
486
+{
487
+	return ki_mqx_get_mode(msg, qname, 0, SR_KEMI_XVAL_NULL_PRINT);
488
+}
489
+
490
+/**
491
+ *
492
+ */
493
+static sr_kemi_xval_t* ki_mqv_get(sip_msg_t *msg, str *qname)
494
+{
495
+	return ki_mqx_get_mode(msg, qname, 1, SR_KEMI_XVAL_NULL_NONE);
496
+}
497
+
498
+/**
499
+ *
500
+ */
501
+static sr_kemi_xval_t* ki_mqv_gete(sip_msg_t *msg, str *qname)
502
+{
503
+	return ki_mqx_get_mode(msg, qname, 1, SR_KEMI_XVAL_NULL_EMPTY);
504
+}
505
+
506
+/**
507
+ *
508
+ */
509
+static sr_kemi_xval_t* ki_mqv_getw(sip_msg_t *msg, str *qname)
510
+{
511
+	return ki_mqx_get_mode(msg, qname, 1, SR_KEMI_XVAL_NULL_PRINT);
512
+}
513
+
514
+/**
515
+ *
516
+ */
441 517
 /* clang-format off */
442 518
 static sr_kemi_t sr_kemi_mqueue_exports[] = {
443 519
 	{ str_init("mqueue"), str_init("mq_add"),
... ...
@@ -460,6 +536,36 @@ static sr_kemi_t sr_kemi_mqueue_exports[] = {
460 460
 		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
461 461
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
462 462
 	},
463
+	{ str_init("mqueue"), str_init("mqk_get"),
464
+		SR_KEMIP_XVAL, ki_mqk_get,
465
+		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
466
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
467
+	},
468
+	{ str_init("mqueue"), str_init("mqk_gete"),
469
+		SR_KEMIP_XVAL, ki_mqk_gete,
470
+		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
471
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
472
+	},
473
+	{ str_init("mqueue"), str_init("mqk_getw"),
474
+		SR_KEMIP_XVAL, ki_mqk_getw,
475
+		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
476
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
477
+	},
478
+	{ str_init("mqueue"), str_init("mqv_get"),
479
+		SR_KEMIP_XVAL, ki_mqv_get,
480
+		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
481
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
482
+	},
483
+	{ str_init("mqueue"), str_init("mqv_gete"),
484
+		SR_KEMIP_XVAL, ki_mqv_gete,
485
+		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
486
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
487
+	},
488
+	{ str_init("mqueue"), str_init("mqv_getw"),
489
+		SR_KEMIP_XVAL, ki_mqv_getw,
490
+		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
491
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
492
+	},
463 493
 
464 494
 	{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
465 495
 };