Browse Source

print: relocated to archive

Daniel-Constantin Mierla 8 months ago
parent
commit
b9003a9f09

+ 8 - 0
src/modules/print/CMakeLists.txt

@@ -0,0 +1,8 @@
+cmake_minimum_required(VERSION 3.10)
+
+project(print)
+
+file(GLOB SRC_FILES "*.c")
+
+add_library(print SHARED ${SRC_FILES})
+target_link_libraries(print PRIVATE kamailio)

+ 12 - 0
src/modules/print/Makefile

@@ -0,0 +1,12 @@
+#
+# print example module makefile
+#
+# 
+# WARNING: do not run this directly, it should be run by the main Makefile
+
+include ../../Makefile.defs
+auto_gen=
+NAME=print.so
+LIBS=
+
+include ../../Makefile.modules

+ 91 - 0
src/modules/print/README

@@ -0,0 +1,91 @@
+Print Module
+
+Andrei Pelinescu-Onciul
+
+   FhG FOKUS
+
+   Copyright © 2003 FhG FOKUS
+     __________________________________________________________________
+
+   Table of Contents
+
+   1. Admin Guide
+
+        1. Overview
+        2. Parameters
+
+              2.1. str_param (string)
+              2.2. int_param (integer)
+
+        3. Functions
+
+              3.1. print(txt)
+
+   List of Examples
+
+   1.1. Set str_param parameter
+   1.2. Set int_param parameter
+   1.3. print usage
+
+Chapter 1. Admin Guide
+
+   Table of Contents
+
+   1. Overview
+   2. Parameters
+
+        2.1. str_param (string)
+        2.2. int_param (integer)
+
+   3. Functions
+
+        3.1. print(txt)
+
+1. Overview
+
+   This is an example module. It implements only one function that prints
+   its string parameter to stdout (it won't work if ser is started in
+   daemon mode). It also shows how module parameters can be declared.
+
+2. Parameters
+
+   2.1. str_param (string)
+   2.2. int_param (integer)
+
+2.1. str_param (string)
+
+   Not used, just an example
+
+   Default value is NULL.
+
+   Example 1.1. Set str_param parameter
+...
+modparam("print", "str_param", "foobar")
+...
+
+2.2. int_param (integer)
+
+   Not used, just an example.
+
+   Default value is 0.
+
+   Example 1.2. Set int_param parameter
+...
+modparam("print", "int_param", 42)
+...
+
+3. Functions
+
+   3.1. print(txt)
+
+3.1.  print(txt)
+
+   Prints string to stdout.
+
+   Meaning of the parameters is as follows:
+     * txt - string to be printed.
+
+   Example 1.3. print usage
+...
+print("The answer is 42\n");
+...

+ 4 - 0
src/modules/print/doc/Makefile

@@ -0,0 +1,4 @@
+docs = print.xml
+
+docbook_dir = ../../../../doc/docbook
+include $(docbook_dir)/Makefile.module

+ 34 - 0
src/modules/print/doc/functions.xml

@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
+   "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
+
+<section id="print.functions" xmlns:xi="http://www.w3.org/2001/XInclude">
+    <sectioninfo>
+    </sectioninfo>
+
+    <title>Functions</title>
+
+    <section id="print.print">
+	<title>
+	    <function>print(txt)</function>
+	</title>
+	<para>
+	    Prints string to stdout.
+	</para>
+	<para>Meaning of the parameters is as follows:</para>
+	<itemizedlist>
+	    <listitem>
+		<para><emphasis>txt</emphasis> - string to be printed.
+		</para>
+	    </listitem>
+	</itemizedlist>
+	<example>
+	    <title><function>print</function> usage</title>
+	    <programlisting>
+...
+print("The answer is 42\n");
+...
+	    </programlisting>
+	</example>
+    </section>
+</section>

+ 47 - 0
src/modules/print/doc/params.xml

@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
+   "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
+
+<section id="print.parameters" xmlns:xi="http://www.w3.org/2001/XInclude">
+    <sectioninfo>
+    </sectioninfo>
+
+    <title>Parameters</title>
+
+    <section id="str_param">
+	<title><varname>str_param</varname> (string)</title>
+	<para>
+	    Not used, just an example
+	</para>
+	<para>
+	    Default value is NULL.
+	</para>
+	<example>
+	    <title>Set <varname>str_param</varname> parameter</title>
+	    <programlisting>
+...
+modparam("print", "str_param", "foobar")
+...
+	    </programlisting>
+	</example>
+    </section>
+
+    <section id="int_param">
+	<title><varname>int_param</varname> (integer)</title>
+	<para>
+	    Not used, just an example.
+	</para>
+	<para>
+	    Default value is 0.
+	</para>
+	<example>
+	    <title>Set <varname>int_param</varname> parameter</title>
+	    <programlisting>
+...
+modparam("print", "int_param", 42)
+...
+	    </programlisting>
+	</example>
+    </section>
+
+</section>

+ 41 - 0
src/modules/print/doc/print.xml

@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
+   "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
+
+<book id="print" xmlns:xi="http://www.w3.org/2001/XInclude">
+    <bookinfo>
+        <title>Print Module</title>
+	<authorgroup>
+	    <author>
+		<firstname>Andrei</firstname>
+		<surname>Pelinescu-Onciul</surname>
+		<affiliation><orgname>FhG FOKUS</orgname></affiliation>
+		<address>
+		    <email>[email protected]</email>
+		</address>
+	    </author>
+	</authorgroup>
+	<copyright>
+	    <year>2003</year>
+	    <holder>FhG FOKUS</holder>
+	</copyright>
+    </bookinfo>
+    <toc></toc>
+
+    <chapter>
+	<title>Admin Guide</title>
+    <section id="print.overview">
+	<title>Overview</title>
+	<para>
+	    This is an example module. It implements only one function that
+	    prints its string parameter to stdout (it won't work if ser is
+	    started in daemon mode). It also shows how module parameters can be
+	    declared.
+	</para>
+    </section>
+
+    <xi:include href="params.xml"/>
+    <xi:include href="functions.xml"/>
+    </chapter>
+</book>
+

+ 182 - 0
src/modules/print/print.c

@@ -0,0 +1,182 @@
+/*$Id$
+ *
+ * Example ser module, it will just print its string parameter to stdout
+ *
+ *
+ * Copyright (C) 2001-2003 FhG Fokus
+ *
+ * This file is part of ser, a free SIP server.
+ *
+ * ser is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version
+ *
+ * For a license to use the ser software under conditions
+ * other than those described here, or to purchase support for this
+ * software, please contact iptel.org by e-mail at the following addresses:
+ *    [email protected]
+ *
+ * ser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+/*
+ * History:
+ * --------
+ *  2003-03-10  module export interface updated to the new format (andrei)
+ *  2003-03-11  flags export parameter added (janakj)
+ *  2006-01-07  str export parameter added, overloading test (tma)
+ */
+
+
+#include "../../core/sr_module.h"
+#include "../../core/route_struct.h"
+#include "../../core/str.h"
+#include <stdio.h>
+
+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_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*/
+char *string_param = 0;
+int int_param = 0;
+str str_param = STR_STATIC_INIT("");
+
+static cmd_export_t cmds[] = {
+		{"print", print_f_0, 0, 0, 0, REQUEST_ROUTE}, // overload test
+		{"print", print_f_1, 1, print_fixup_f_1, 0, REQUEST_ROUTE},
+		{"print", print_f_2, 2, print_fixup_f_2, 0, REQUEST_ROUTE},
+		{"print1", print_f1, 1, 0, 0, REQUEST_ROUTE},
+		{"print2", print_f2, 2, fixup_var_str_12, 0, REQUEST_ROUTE},
+		{"print3", (cmd_function)print_f3, 3, 0, 0, REQUEST_ROUTE},
+		{"printv", (cmd_function)print_f_var, VAR_PARAM_NO, 0, 0,
+				REQUEST_ROUTE},
+		{0, 0, 0, 0, 0, 0}};
+
+static param_export_t params[] = {{"string_param", PARAM_STRING, &string_param},
+		{"str_param", PARAM_STR, &str_param},
+		{"int_param", PARAM_INT, &int_param}, {0, 0, 0}};
+
+struct module_exports exports = {
+		"print_stdout",	 /* module name */
+		DEFAULT_DLFLAGS, /* dlopen flags */
+		cmds,			 /* exported functions */
+		params,			 /* exported parameters */
+		0,				 /* RPC method exports */
+		0,				 /* exported pseudo-variables */
+		0,				 /* response handling function */
+		mod_init,		 /* module initialization function */
+		0,				 /* per-child init function */
+		0				 /* module destroy function */
+};
+
+
+static int mod_init(void)
+{
+	fprintf(stderr, "print - initializing\n");
+	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;
+}
+
+
+static int print_fixup_f(void **param, int param_no)
+{
+	action_u_t *a;
+	int n, i;
+	n = fixup_get_param_count(param, param_no);
+	for(i = 1; i <= n; i++) {
+		a = fixup_get_param(param, param_no, i);
+		DBG("param #%d: '%s'\n", i, a->u.string);
+	}
+	return 1;
+}
+
+static int print_f_0(struct sip_msg *msg, char *s1, char *s2)
+{
+	printf("<null>\n");
+	return 1;
+}
+
+static int print_f_1(struct sip_msg *msg, char *s1, char *s2)
+{
+	printf("%s\n", s1);
+	return 1;
+}
+
+static int print_f_2(struct sip_msg *msg, char *s1, char *s2)
+{
+	printf("%s%s\n", s1, s2);
+	return 1;
+}
+
+static int print_fixup_f_1(void **param, int param_no)
+{
+	DBG("print: print_fixup_f_1('%s')\n", (char *)*param);
+	return print_fixup_f(param, param_no);
+}
+
+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, fparam fixup version */
+static int print_f2(struct sip_msg *msg, char *s1, char *s2)
+{
+	str a, b;
+	if(get_str_fparam(&a, msg, (fparam_t *)s1) != 0
+			|| get_str_fparam(&b, msg, (fparam_t *)s2) != 0) {
+		BUG("get_str_fparam failed\n");
+		return -1;
+	}
+	printf("%.*s%.*s\n", a.len, a.s, b.len, b.s);
+	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;
+}