3 * Example ser module, it will just print its string parameter to stdout
6 * Copyright (C) 2001-2003 FhG Fokus
8 * This file is part of ser, a free SIP server.
10 * ser is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version
15 * For a license to use the ser software under conditions
16 * other than those described here, or to purchase support for this
17 * software, please contact iptel.org by e-mail at the following addresses:
20 * ser is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 * 2003-03-10 module export interface updated to the new format (andrei)
33 * 2003-03-11 flags export parameter added (janakj)
34 * 2006-01-07 str export parameter added, overloading test (tma)
40 #include "../../sr_module.h"
41 #include "../../route_struct.h"
42 #include "../../str.h"
47 static int print_fixup_f_1(void **param, int param_no);
48 static int print_fixup_f_2(void **param, int param_no);
49 static int print_f_0(struct sip_msg*, char*, char*);
50 static int print_f_1(struct sip_msg*, char*, char*);
51 static int print_f_2(struct sip_msg*, char*, char*);
52 static int print_f1(struct sip_msg*, char*, char*);
53 static int print_f2(struct sip_msg*, char*, char*);
54 static int print_f3(struct sip_msg*, char*, char*, char*);
55 static int print_f_var(struct sip_msg*, int argc, action_u_t argv[]);
56 static int mod_init(void);
58 /* the parameters are not used, they are only meant as an example*/
59 char* string_param = 0;
61 str str_param = STR_STATIC_INIT("");
63 static cmd_export_t cmds[]={
64 {"print", print_f_0, 0, 0, REQUEST_ROUTE}, // overload test
65 {"print", print_f_1, 1, print_fixup_f_1, REQUEST_ROUTE},
66 {"print", print_f_2, 2, print_fixup_f_2, REQUEST_ROUTE},
67 {"print1", print_f1, 1, 0, REQUEST_ROUTE},
68 {"print2", print_f2, 2, 0, REQUEST_ROUTE},
69 {"print3", (cmd_function)print_f3, 3, 0, REQUEST_ROUTE},
70 {"printv", (cmd_function)print_f_var, VAR_PARAM_NO, 0, REQUEST_ROUTE},
74 static param_export_t params[]={
75 {"string_param", PARAM_STRING, &string_param},
76 {"str_param", PARAM_STR, &str_param},
77 {"int_param", PARAM_INT, &int_param},
81 struct module_exports exports = {
87 mod_init, /* module initialization function */
88 0, /* response function*/
89 0, /* destroy function */
90 0, /* oncancel function */
91 0 /* per-child init function */
95 static int mod_init(void)
97 fprintf(stderr, "print - initializing\n");
98 DBG("print: string_param = '%s'\n", string_param);
99 DBG("print: str_param = '%.*s'\n", str_param.len, str_param.s);
100 DBG("print: int_param = %d\n", int_param);
101 WARN("this is an example module, it has no practical use\n");
106 static int print_fixup_f(void **param, int param_no) {
109 n = fixup_get_param_count(param, param_no);
110 for (i=1; i<=n; i++) {
111 a = fixup_get_param(param, param_no, i);
112 DBG("param #%d: '%s'\n", i, a->u.string);
117 static int print_f_0(struct sip_msg* msg, char* s1, char* s2)
123 static int print_f_1(struct sip_msg* msg, char* s1, char* s2)
129 static int print_f_2(struct sip_msg* msg, char* s1, char* s2)
131 printf("%s%s\n",s1, s2);
135 static int print_fixup_f_1(void **param, int param_no) {
136 DBG("print: print_fixup_f_1('%s')\n", (char*)*param);
137 return print_fixup_f(param, param_no);
140 static int print_fixup_f_2(void **param, int param_no) {
141 DBG("print: print_fixup_f_2('%s')\n", (char*)*param);
142 return print_fixup_f(param, param_no);
147 /* 1 parameter, no fixup version */
148 static int print_f1(struct sip_msg* msg, char* s1, char* not_used)
155 /* 2 parameters, no fixup version */
156 static int print_f2(struct sip_msg* msg, char* s1, char* s2)
158 printf("%s%s\n", s1, s2);
163 /* 3 parameters, no fixup version */
164 static int print_f3(struct sip_msg* msg, char* s1, char* s2, char* s3)
166 printf("%s%s%s\n", s1, s2, s3);
171 /* variable number of parameters, no fixup version */
172 static int print_f_var(struct sip_msg* msg, int argc, action_u_t argv[])
175 for (i = 0; i < argc; i++)
176 printf("%s", argv[i].u.string);