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 mod_init(void);
54 /* the parameters are not used, they are only meant as an example*/
55 char* string_param = 0;
57 str str_param = STR_STATIC_INIT("");
59 static cmd_export_t cmds[]={
60 {"print", print_f_0, 0, 0, REQUEST_ROUTE}, // overload test
61 {"print", print_f_1, 1, print_fixup_f_1, REQUEST_ROUTE},
62 {"print", print_f_2, 2, print_fixup_f_2, REQUEST_ROUTE},
66 static param_export_t params[]={
67 {"string_param", PARAM_STRING, &string_param},
68 {"str_param", PARAM_STR, &str_param},
69 {"int_param", PARAM_INT, &int_param},
73 struct module_exports exports = {
79 mod_init, /* module initialization function */
80 0, /* response function*/
81 0, /* destroy function */
82 0, /* oncancel function */
83 0 /* per-child init function */
87 static int mod_init(void)
89 fprintf(stderr, "print - initializing\n");
90 DBG("print: string_param = '%s'\n", string_param);
91 DBG("print: str_param = '%.*s'\n", str_param.len, str_param.s);
92 DBG("print: int_param = %d\n", int_param);
97 static int print_fixup_f(void **param, int param_no) {
100 n = fixup_get_param_count(param, param_no);
101 for (i=1; i<=n; i++) {
102 a = fixup_get_param(param, param_no, i);
103 DBG("param #%d: '%s'\n", i, a->u.string);
108 static int print_f_0(struct sip_msg* msg, char* s1, char* s2)
114 static int print_f_1(struct sip_msg* msg, char* s1, char* s2)
120 static int print_f_2(struct sip_msg* msg, char* s1, char* s2)
122 printf("%s%s\n",s1, s2);
126 static int print_fixup_f_1(void **param, int param_no) {
127 DBG("print: print_fixup_f_1('%s')\n", (char*)*param);
128 return print_fixup_f(param, param_no);
131 static int print_fixup_f_2(void **param, int param_no) {
132 DBG("print: print_fixup_f_2('%s')\n", (char*)*param);
133 return print_fixup_f(param, param_no);