Module: sip-router Branch: andrei/rve_f_params Commit: 37554f166be7c7eb9ee65ce3dfe591ad4094481a URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=37554f16...
Author: Andrei Pelinescu-Onciul andrei@iptel.org Committer: Andrei Pelinescu-Onciul andrei@iptel.org Date: Mon Mar 15 20:14:40 2010 +0100
print(s): more module function examples
Added example functions with no fixups, with 1, 2, 3 or variable number of parameters (VAR_PARAM_NO).
---
modules_s/print/print.c | 51 ++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 48 insertions(+), 3 deletions(-)
diff --git a/modules_s/print/print.c b/modules_s/print/print.c index b3d6852..7c704c5 100644 --- a/modules_s/print/print.c +++ b/modules_s/print/print.c @@ -46,9 +46,13 @@ MODULE_VERSION
static int print_fixup_f_1(void **param, int param_no); static int print_fixup_f_2(void **param, int param_no); -static int print_f_0(struct sip_msg*, char*,char*); -static int print_f_1(struct sip_msg*, char*,char*); -static int print_f_2(struct sip_msg*, char*,char*); +static int print_f_0(struct sip_msg*, char*, char*); +static int print_f_1(struct sip_msg*, char*, char*); +static int print_f_2(struct sip_msg*, char*, char*); +static int print_f1(struct sip_msg*, char*, char*); +static int print_f2(struct sip_msg*, char*, char*); +static int print_f3(struct sip_msg*, char*, char*, char*); +static int print_f_var(struct sip_msg*, int argc, action_u_t argv[]); static int mod_init(void);
/* the parameters are not used, they are only meant as an example*/ @@ -60,6 +64,10 @@ static cmd_export_t cmds[]={ {"print", print_f_0, 0, 0, REQUEST_ROUTE}, // overload test {"print", print_f_1, 1, print_fixup_f_1, REQUEST_ROUTE}, {"print", print_f_2, 2, print_fixup_f_2, REQUEST_ROUTE}, + {"print1", print_f1, 1, 0, REQUEST_ROUTE}, + {"print2", print_f2, 2, 0, REQUEST_ROUTE}, + {"print3", (cmd_function)print_f3, 3, 0, REQUEST_ROUTE}, + {"printv", (cmd_function)print_f_var, VAR_PARAM_NO, 0, REQUEST_ROUTE}, {0, 0, 0, 0, 0} };
@@ -90,6 +98,7 @@ static int mod_init(void) DBG("print: string_param = '%s'\n", string_param); DBG("print: str_param = '%.*s'\n", str_param.len, str_param.s); DBG("print: int_param = %d\n", int_param); + WARN("this is an example module, it has no practical use\n"); return 0; }
@@ -132,3 +141,39 @@ static int print_fixup_f_2(void **param, int param_no) { DBG("print: print_fixup_f_2('%s')\n", (char*)*param); return print_fixup_f(param, param_no); } + + + +/* 1 parameter, no fixup version */ +static int print_f1(struct sip_msg* msg, char* s1, char* not_used) +{ + printf("%s\n", s1); + return 1; +} + + +/* 2 parameters, no fixup version */ +static int print_f2(struct sip_msg* msg, char* s1, char* s2) +{ + printf("%s%s\n", s1, s2); + return 1; +} + + +/* 3 parameters, no fixup version */ +static int print_f3(struct sip_msg* msg, char* s1, char* s2, char* s3) +{ + printf("%s%s%s\n", s1, s2, s3); + return 1; +} + + +/* variable number of parameters, no fixup version */ +static int print_f_var(struct sip_msg* msg, int argc, action_u_t argv[]) +{ + int i; + for (i = 0; i < argc; i++) + printf("%s", argv[i].u.string); + printf("\n"); + return 1; +}