Module: sip-router
Branch: master
Commit: d6e8fdb3a06aab44c01ce5e5a2ca4f2d43117676
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=d6e8fdb…
Author: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Date: Thu Jul 16 10:38:14 2009 +0200
xmlrpc(s) doc: added the autoconversion parameter
---
modules_s/xmlrpc/doc/params.xml | 29 ++++++++++++++++++++++++++++-
1 files changed, 28 insertions(+), 1 deletions(-)
diff --git a/modules_s/xmlrpc/doc/params.xml b/modules_s/xmlrpc/doc/params.xml
index 324495d..be7fd63 100644
--- a/modules_s/xmlrpc/doc/params.xml
+++ b/modules_s/xmlrpc/doc/params.xml
@@ -41,8 +41,35 @@ modparam("xmlrpc", "route", "route_for_xmlrpcs")
</example>
</section>
+ <section id="autoconversion">
+ <title><varname>autoconversion</varname> (string)</title>
+ <para>
+ Enable or disable automatic parameter type conversion globally,
+ for all the methods parameters.
+ If on, a type mismatch in a method parameter
+ will not cause a fault if it is possible to automatically
+ convert it to the type expected by the method.
+ </para>
+ <para>
+ Default: off.
+ </para>
+ <para>
+ It is recommended to leave this parameter to its default off value
+ and fix instead the client application (which should use the
+ proper types) or to modify the target rpc to accept any type
+ (see the rpc scan '.' modifier).
+ </para>
+ <example>
+ <title>Set the <varname>autoconversion</varname> parameter</title>
+ <programlisting>
+modparam("xmlrpc", "autoconversion", 1)
+ </programlisting>
+ </example>
+ </section>
+
<!--
- Seems to be obsolete (on always) -andrei
+ Obsolete (hardwired on in the rpc core functions, cannot be turned off)
+ -andrei
<section id="enable_introspection">
<title><varname>enable_introspection</varname> (integer)</title>
<para>
Module: sip-router
Branch: master
Commit: 46fb4917c2163fd5c8bd01fdd866813211cd6ec7
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=46fb491…
Author: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Date: Thu Jul 16 09:36:22 2009 +0200
doc: rpc api documentation updated: the '.' modifier
---
doc/rpc/ser_rpc.txt | 59 ++++++++++++++++++++++++++++++++++++++------------
doc/rpc/ser_rpc.xml | 60 +++++++++++++++++++++++++++++++++++++++++++++------
2 files changed, 98 insertions(+), 21 deletions(-)
diff --git a/doc/rpc/ser_rpc.txt b/doc/rpc/ser_rpc.txt
index 778c03f..b2c5337 100644
--- a/doc/rpc/ser_rpc.txt
+++ b/doc/rpc/ser_rpc.txt
@@ -249,12 +249,13 @@ add("sd", string_param, int_param);
ints and a string) are optional.
Table 1. Data Type Overview
-Name Formating String Char C-Style Variable
-Integer d int
-Float f double
-String s char*
-String S str
-Optional modifier * marks all further parameters as optional
+ Name Formating String Char C-Style Variable
+ Integer d int
+ Float f double
+ String s char*
+ String S str
+ Optional modifier * marks all further parameters as optional
+ Autoconvert modifier . requires auto-conversion for the next parameter
1.2.3. Getting Parameters
@@ -278,17 +279,27 @@ Note
parameters to be retrieved. Each parameter is represented by exactly
one parameter type character in the string. The variable part of
parameters must contain as many pointers to C variables as there are
- formatting non-modifiers characters in the formatting string. The
- formatting string can also contain a "*" modifier that does not have a
- correspondent in the variable part of the parameters. The meaning of
- "*" is that any further parameters (defined by other type characters in
- the formatting string) are optional (they can be missing in the input
- and no rpc fault will automatically be generated).
+ formatting non-modifiers characters in the formatting string.
Warning
The function will crash if you fail to provide enough parameters.
+ Besides characters representing parameter types, the formatting string
+ can contain two special modifiers: "*" and ".". The modifiers do not
+ have a correspondent in the variable part of the parameters.
+
+ The meaning of "*" modifier is that any further parameters (defined by
+ other type characters in the formatting string) are optional (they can
+ be missing in the input and no rpc fault will automatically be
+ generated).
+
+ The '.' modifiers turns on type autoconversion for the next parameter.
+ This means that if the type of the next parameter differs from the type
+ specified in the formatting string, the parameter will be automatically
+ converted to the formatting string type (if possible) and if the
+ automatic conversion succeeds, no fault will be generated.
+
The function returns the number of parameters read on success (a number
greater or equal 0) and - (minus) the number of parameters read on
error (for example for an error after reading 2 parameters it will
@@ -297,8 +308,9 @@ Warning
number (- number of parameters read so far) and it will also
automatically change the reply that will be sent to the caller to
indicate that a failure has occurred on the server (unless the "*" is
- used and the error is lack of more parameters). The prototype of the
- function is:
+ used and the error is lack of more parameters).
+
+ The prototype of the function is:
int scan(char* fmt, ...)
It is possible to either call the function once to scan all the
@@ -368,6 +380,25 @@ static void rpc_delete_contact(rpc_t* rpc)
/* Process retrieved parameters here */
}
+/* variable number of parameters:
+ echo back all the parameters, string type required */
+static void core_prints(rpc_t* rpc, void* c)
+{
+ char* string = 0;
+ while((rpc->scan(c, "*s", &string)>0))
+ rpc->add(c, "s", string);
+}
+
+/* variable number of parameters and auto conversion:
+ echo back all the parameters, works with any type (everything is
+ internally converted to string, notice the '.' modifier) */
+static void core_echo(rpc_t* rpc, void* c)
+{
+ char* string = 0;
+ while((rpc->scan(c, "*.s", &string)>0))
+ rpc->add(c, "s", string);
+}
+
1.2.4. Building Reply
The RPC API contains several functions that can be used to modify
diff --git a/doc/rpc/ser_rpc.xml b/doc/rpc/ser_rpc.xml
index 5a20d8a..698bc9c 100644
--- a/doc/rpc/ser_rpc.xml
+++ b/doc/rpc/ser_rpc.xml
@@ -363,6 +363,11 @@ add("sd", string_param, int_param);
<entry>*</entry>
<entry>marks all further parameters as optional</entry>
</row>
+ <row>
+ <entry>Autoconvert modifier</entry>
+ <entry>.</entry>
+ <entry>requires auto-conversion for the next parameter</entry>
+ </row>
</tbody>
</tgroup>
</table>
@@ -398,18 +403,34 @@ add("sd", string_param, int_param);
The variable part of parameters must contain as many pointers to C
variables as there are formatting non-modifiers characters in the
formatting string.
- The formatting string can also contain a "*" modifier that does not
- have a correspondent in the variable part of the parameters. The
- meaning of "*" is that any further parameters (defined by other
- type characters in the formatting string) are optional (they
- can be missing in the input and no rpc fault will automatically
- be generated).
<warning>
<para>
The function will crash if you fail to provide
enough parameters.
</para>
</warning>
+ </para>
+ <para>
+ Besides characters representing parameter types, the formatting
+ string can contain two special modifiers: "*" and ".". The
+ modifiers do not have a correspondent in the variable part of the
+ parameters.
+ </para>
+ <para>
+ The meaning of "*" modifier is that any further parameters
+ (defined by other type characters in the formatting string) are
+ optional (they can be missing in the input and no rpc fault will
+ automatically be generated).
+ </para>
+ <para>
+ The '.' modifiers turns on type autoconversion for the next
+ parameter. This means that if the type of the next parameter
+ differs from the type specified in the formatting string, the
+ parameter will be automatically converted to the formatting string
+ type (if possible) and if the automatic conversion succeeds, no
+ fault will be generated.
+ </para>
+ <para>
The function returns the number of parameters read on success
(a number greater or equal 0) and - (minus) the number of
parameters read on error (for example for an error after
@@ -420,7 +441,10 @@ add("sd", string_param, int_param);
and it will also automatically change the reply that will be
sent to the caller to indicate that a failure has occurred on
the server (unless the "*" is used and the error is lack
- of more parameters). The prototype of the function is:
+ of more parameters).
+ </para>
+ <para>
+ The prototype of the function is:
<programlisting>
int scan(char* fmt, ...)
</programlisting>
@@ -437,6 +461,8 @@ rpc->scan("d", &int_val);
rpc->scan("f", &double_val);
</programlisting>
</para>
+ <para>
+ </para>
</section>
<section>
<title><function>struct_scan</function></title>
@@ -506,6 +532,26 @@ static void rpc_delete_contact(rpc_t* rpc)
/* Process retrieved parameters here */
}
+
+/* variable number of parameters:
+ echo back all the parameters, string type required */
+static void core_prints(rpc_t* rpc, void* c)
+{
+ char* string = 0;
+ while((rpc->scan(c, "*s", &string)>0))
+ rpc->add(c, "s", string);
+}
+
+/* variable number of parameters and auto conversion:
+ echo back all the parameters, works with any type (everything is
+ internally converted to string, notice the '.' modifier) */
+static void core_echo(rpc_t* rpc, void* c)
+{
+ char* string = 0;
+ while((rpc->scan(c, "*.s", &string)>0))
+ rpc->add(c, "s", string);
+}
+
]]>
</programlisting>
</example>
next i tried 'mi set_gflag' and it failed like this:
srctl> mi set_gflag 1024
error: 400 - error at parameter 2: expected string type but record doesn't match type
did i do something wrong or is also this mi command buggy?
-- juha
Module: sip-router
Branch: master
Commit: 6f38c000cc3b5c76c99904fa7d5ab244aaa774f4
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=6f38c00…
Author: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Date: Wed Jul 15 20:32:53 2009 +0200
xmlrpc(s): type autoconversion support
- added a new module parameter ("autoconversion") that when enabled
will try to autoconvert the xmlrpc parameters types into what
the rpc method expects (e.g. if the method expects a string, but
receives an int, convert the int to string). By default it's
off.
- support for a new modifier: '.' for rpc_scan. When used it turns
auto-conversion on for the next input.
E.g. rpc->scan(".s", &string) will work even if the next input
is an int (it will convert it to string).
More complex example:
while((rpc->scan(c, "*.s", &p)>0)) rpc->add(c, "s", p);
(work with any number of inputs/parameters, convert all of
them to string and echo them back in the reply)
---
modules_s/xmlrpc/xmlrpc.c | 304 ++++++++++++++++++++++++++++++++++++++-------
1 files changed, 256 insertions(+), 48 deletions(-)
Diff: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commitdiff;h=6f3…