forked from luismartingil/post-kamailio-module-cpp
-
Notifications
You must be signed in to change notification settings - Fork 3
/
zzz_mod.c
130 lines (110 loc) · 3.26 KB
/
zzz_mod.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
* zzz_mod.c
*
*
*/
/*!
* \file
* \brief Module interface
* \ingroup zzz
* Module: \ref zzz
*/
/**
* @defgroup zzz zzz :: Kamailio zzz module
* @brief Kamailio zzz module
*/
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
/* Importing zzz library */
#include "zzz/core-c.hpp"
#include "../../core/mod_fix.h"
#include "../../core/lvalue.h"
#include "../../core/dprint.h"
#include "../../core/mem/mem.h"
MODULE_VERSION
/* module params */
static unsigned int number = 99;
static char* text = "This is a default param text";
void *core = NULL;
/* Module management function prototypes */
static int mod_init(void);
static void destroy(void);
static int fixup_get_params(void** param, int param_no);
static int fixup_get_params_free(void** param, int param_no);
static int get_incremented_number_mod_f (struct sip_msg *msg,
char* result);
/* Exported functions */
static cmd_export_t cmds[] = {
{"get_incremented_number_mod", (cmd_function)get_incremented_number_mod_f, 1,
fixup_get_params, fixup_get_params_free, ANY_ROUTE},
{0, 0, 0, 0, 0}
};
/* Exported parameters */
static param_export_t params[] = {
{"number", PARAM_INT, &number},
{"text", PARAM_STRING, &text},
{0, 0, 0}
};
/* Module interface */
struct module_exports exports = {
"zzz",
DEFAULT_DLFLAGS, /* dlopen flags */
cmds, /* Exported functions */
params, /* Exported parameters */
0, /* exported statistics */
0, /* exported MI functions */
0, /* exported pseudo-variables */
0, /* extra processes */
mod_init, /* module initialization function */
0, /* response function*/
destroy, /* destroy function */
0 /* per-child init function */
};
/* Module initialization function - The main initialization function will be called
before any other function exported by the module. The function will be called only once,
before the main process forks. This function is good for initialization that is common
for all the children (processes). The function should return 0 if everything went OK
and a negative error code otherwise. Server will abort if the function returns a negative value.
*/
static int mod_init(void)
{
core = get_core(number, text);
return 0;
}
static void destroy(void)
{
destroy_core(core);
return;
}
static int fixup_get_params(void** param, int param_no)
{
if (param_no == 1) {
return fixup_pvar_null(param, 1);
}
LM_ERR("invalid parameter number <%d>\n", param_no);
return -1;
}
static int fixup_get_params_free(void** param, int param_no)
{
if (param_no == 1) {
return fixup_free_pvar_null(param, 1);
}
LM_ERR("invalid parameter number <%d>\n", param_no);
return -1;
}
// **********************************************************
// get_incremented_number_mod_f
// **********************************************************
static int get_incremented_number_mod_f (struct sip_msg *msg,
char* result) {
pv_spec_t *dst_pv;
pv_value_t dst_val;
dst_pv = (pv_spec_t *)result;
// Accessing our c-library-interface incremented function
dst_val.ri = get_incremented_number(core);
dst_val.flags = PV_TYPE_INT|PV_VAL_INT;
dst_pv->setf(msg, &dst_pv->pvp, (int)EQ_T, &dst_val);
return 1;
}
// get_incremented_number_mod_f******************************