Selaa lähdekoodia

rpc doc: added "*" and some minor fixes

- documented the newly introduced "*" modifier for optional
  parameters.
- fixed return value description for rpc->scan and
  rpc->struct_scan (these function always return the number of
  parameters read on success and - number of parameters read so
  far on failure and not 0/-1).
- changed ctl and xmlrpc links to point to the auto-generated html
  files on sip-router.org/docbook/.
- re-generated ser_rpc.txt
Andrei Pelinescu-Onciul 16 vuotta sitten
vanhempi
commit
32c1a13ef4
2 muutettua tiedostoa jossa 106 lisäystä ja 40 poistoa
  1. 46 18
      doc/rpc/ser_rpc.txt
  2. 60 22
      doc/rpc/ser_rpc.xml

+ 46 - 18
doc/rpc/ser_rpc.txt

@@ -238,12 +238,23 @@ add("sd", string_param, int_param);
    be of type struct again). Corresponding character in the formatting
    be of type struct again). Corresponding character in the formatting
    string is "{".
    string is "{".
 
 
+   Optional parameters.  Optional parameters can be used, but only in the
+   scan function. For optional parameters the scan function will not
+   automatically generate a rpc fault if the input ends. Note that in this
+   case the scan will still return a negative value (minus the number of
+   parameters successfully read). Optional parameters can be marked in the
+   format string by preceding the first optional parameter type with a
+   "*". All the parameters following a "*" are considered to be optional.
+   For example for the format string "ds*dds", the last 3 parameters (2
+   ints and a string) are optional.
+
    Table 1. Data Type Overview
    Table 1. Data Type Overview
-   Name    Formating String Char C-Style Variable
-   Integer d                     int
-   Float   f                     double
-   String  s                     char*
-   String  S                     str
+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
 
 
 1.2.3. Getting Parameters
 1.2.3. Getting Parameters
 
 
@@ -265,19 +276,29 @@ Note
    set. The function accepts variable number of parameters. The first
    set. The function accepts variable number of parameters. The first
    parameter is the formatting string that determines the type of the
    parameter is the formatting string that determines the type of the
    parameters to be retrieved. Each parameter is represented by exactly
    parameters to be retrieved. Each parameter is represented by exactly
-   one character in the string. The variable part of parameters must
-   contain as many pointers to C variables as there are formatting
-   characters in the formatting string.
+   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).
 
 
 Warning
 Warning
 
 
    The function will crash if you fail to provide enough parameters.
    The function will crash if you fail to provide enough parameters.
 
 
-   The function indicates success by returning 0. When a failure occurs
-   (incorrect parameter type or no more parameters in the parameter set)
-   then the function will return -1 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. Prototype of the function is:
+   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
+   return -2). When a failure occurs (incorrect parameter type or no more
+   parameters in the parameter set) the function will return a negative
+   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:
 int scan(char* fmt, ...)
 int scan(char* fmt, ...)
 
 
    It is possible to either call the function once to scan all the
    It is possible to either call the function once to scan all the
@@ -293,11 +314,17 @@ rpc->scan("f", &double_val);
 1.2.3.2. struct_scan
 1.2.3.2. struct_scan
 
 
    Function struct_scan can be used to retrieve named attributes from a
    Function struct_scan can be used to retrieve named attributes from a
-   parameter of type structure. When retrieving a structure parameter from
-   the parameter set:
+   parameter of type structure.
+
+Note
+
+   This function is obsolete and not implemented by all the rpc transports
+   (e.g.: ctl / binrpc). Consider using the normal scan instead.
+
+   When retrieving a structure parameter from the parameter set:
 rpc->scan("{", &handle);
 rpc->scan("{", &handle);
 
 
-   The corresponding variable (named handlein the example above) will
+   The corresponding variable (named handle in the example above) will
    contain the index of the structure parameter within the parameter set,
    contain the index of the structure parameter within the parameter set,
    but the index cannot be used to retrieve the contents of the structure.
    but the index cannot be used to retrieve the contents of the structure.
    To retrieve the contents of the structure you can use function
    To retrieve the contents of the structure you can use function
@@ -308,8 +335,9 @@ rpc->struct_scan(handle, "sd", "str_attr", &str_val, "int_attr", &int_val);
    parameters. First parameter in each pair is the name of the attribute
    parameters. First parameter in each pair is the name of the attribute
    to retrieve (string) and the second parameter in each pair is the
    to retrieve (string) and the second parameter in each pair is the
    pointer to the variable to store the value of the parameter. The
    pointer to the variable to store the value of the parameter. The
-   function returns 0 on success and -1 on an error (just like scan
-   function). The function also indicates an error if a requested
+   function returns the number of parameters (name value pairs) read on
+   success and - number of parameters read so far on an error (just like
+   the scan function). The function also indicates an error if a requested
    attribute is missing in the structure.
    attribute is missing in the structure.
 
 
    Example 3. Retrieving Parameters
    Example 3. Retrieving Parameters

+ 60 - 22
doc/rpc/ser_rpc.xml

@@ -31,11 +31,11 @@
 	<para>
 	<para>
 		The RPC transports are implemented by writting a RPC
 		The RPC transports are implemented by writting a RPC
 		transport module. The most used transport modules are
 		transport module. The most used transport modules are
-		<ulink url='http://git.sip-router.org/cgi-bin/gitweb.cgi?p=sip-router;a=blob;f=modules_s/ctl/README'>
+		<ulink url='http://sip-router.org/docbook/sip-router/branch/master/modules_s/ctl/ctl.html'>
 		<emphasis>ctl</emphasis>
 		<emphasis>ctl</emphasis>
 		</ulink>
 		</ulink>
 		and
 		and
-		<ulink url='http://git.sip-router.org/cgi-bin/gitweb.cgi?p=sip-router;a=blob;f=modules_s/xmlrpc/README'>
+		<ulink url='http://sip-router.org/docbook/sip-router/branch/master/modules_s/xmlrpc/xmlrpc.html'>
 		<emphasis>xmlrpc</emphasis>
 		<emphasis>xmlrpc</emphasis>
 		</ulink>.
 		</ulink>.
 		The first one implements a ser-proprietary fast and space efficient
 		The first one implements a ser-proprietary fast and space efficient
@@ -313,6 +313,22 @@ add("sd", string_param, int_param);
 		    formatting string is "{".
 		    formatting string is "{".
 		</para>
 		</para>
 	    </formalpara>
 	    </formalpara>
+		<formalpara>
+		<title>Optional parameters</title>
+		<para>
+			Optional parameters can be used, but only in the
+			<function>scan</function> function.  For optional parameters the
+			<function>scan</function> function will not automatically generate
+			a rpc fault if the input ends. Note that in this case the
+			<function>scan</function> will still return a negative value
+			(minus the number of parameters successfully read).
+			Optional parameters can be marked in the format string by
+			preceding the first optional parameter type with a "*".
+			All the parameters following a "*" are considered to be optional.
+			For example for the format string "ds*dds", the last 3 parameters
+			(2 ints and a string) are optional.
+		</para>
+		</formalpara>
 	    <table>
 	    <table>
 		<title>Data Type Overview</title>
 		<title>Data Type Overview</title>
 		<tgroup cols="3">
 		<tgroup cols="3">
@@ -342,6 +358,11 @@ add("sd", string_param, int_param);
 			    <entry>S</entry>
 			    <entry>S</entry>
 			    <entry>str</entry>
 			    <entry>str</entry>
 			</row>
 			</row>
+			<row>
+				<entry>Optional modifier</entry>
+				<entry>*</entry>
+				<entry>marks all further parameters as optional</entry>
+			</row>
 		    </tbody>
 		    </tbody>
 		</tgroup>
 		</tgroup>
 	    </table>
 	    </table>
@@ -373,22 +394,33 @@ add("sd", string_param, int_param);
 		    variable number of parameters. The first parameter is the
 		    variable number of parameters. The first parameter is the
 		    formatting string that determines the type of the
 		    formatting string that determines the type of the
 		    parameters to be retrieved. Each parameter is represented by
 		    parameters to be retrieved. Each parameter is represented by
-		    exactly one character in the string. The variable part of
-		    parameters must contain as many pointers to C variables as
-		    there are formatting characters in the formatting
-		    string.
+		    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).
 		    <warning>
 		    <warning>
 			<para>
 			<para>
 			    The function will crash if you fail to provide
 			    The function will crash if you fail to provide
 			    enough parameters.
 			    enough parameters.
 			</para>
 			</para>
 		    </warning>
 		    </warning>
-		    The function indicates success by returning 0. When a
-		    failure occurs (incorrect parameter type or no more
-		    parameters in the parameter set) then the function will
-		    return -1 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. Prototype of the function is:
+			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 return -2).
+			When a failure occurs (incorrect parameter type or no more
+			parameters in the parameter set) the function will
+			return a negative 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:
 		    <programlisting>
 		    <programlisting>
 int scan(char* fmt, ...)
 int scan(char* fmt, ...)
 		    </programlisting>
 		    </programlisting>
@@ -409,15 +441,20 @@ rpc->scan("f", &amp;double_val);
 	    <section>
 	    <section>
 		<title><function>struct_scan</function></title>
 		<title><function>struct_scan</function></title>
 		<para>
 		<para>
-		    Function <function>struct_scan</function> can be used to
-		    retrieve named attributes from a parameter of type
-		    structure. When retrieving a structure parameter from the
-		    parameter set:
+			Function <function>struct_scan</function> can be used to
+			retrieve named attributes from a parameter of type
+			structure.
+			<note>This function is obsolete and not implemented by all the
+			rpc transports (e.g.: ctl / binrpc). Consider using the normal
+			<function>scan</function> instead.
+			</note>
+			When retrieving a structure parameter from the
+			parameter set:
 		    <programlisting>
 		    <programlisting>
 rpc->scan("{", &amp;handle);
 rpc->scan("{", &amp;handle);
 		    </programlisting>
 		    </programlisting>
 		    The corresponding variable (named 
 		    The corresponding variable (named 
-		    <varname>handle</varname>in the example above) will contain
+		    <varname>handle</varname> in the example above) will contain
 		    the index of the structure parameter within the parameter
 		    the index of the structure parameter within the parameter
 		    set, but the index cannot be used to retrieve the contents
 		    set, but the index cannot be used to retrieve the contents
 		    of the structure. To retrieve the contents of the structure
 		    of the structure. To retrieve the contents of the structure
@@ -430,10 +467,11 @@ rpc->struct_scan(handle, "sd", "str_attr", &amp;str_val, "int_attr", &amp;int_va
 		    pairs of parameters. First parameter in each pair is the
 		    pairs of parameters. First parameter in each pair is the
 		    name of the attribute to retrieve (string) and the second
 		    name of the attribute to retrieve (string) and the second
 		    parameter in each pair is the pointer to the variable to
 		    parameter in each pair is the pointer to the variable to
-		    store the value of the parameter. The function returns 0 on
-		    success and -1 on an error (just like
-		    <function>scan</function> function). The function also
-		    indicates an error if a requested attribute is missing in
+		    store the value of the parameter. The function returns the
+			number of parameters (name value pairs) read on
+		    success and - number of parameters read so far on an error
+			(just like the <function>scan</function> function). The function
+			also indicates an error if a requested attribute is missing in
 		    the structure.
 		    the structure.
 		</para>
 		</para>
 	    </section>
 	    </section>
@@ -797,7 +835,7 @@ static void rpc_register(rpc_t* rpc)
 <section id="rpc.xmlrpc_examples">
 <section id="rpc.xmlrpc_examples">
 	<title>Examples using xmlrpc</title>
 	<title>Examples using xmlrpc</title>
 	<para>See the <varname>xmlrpc</varname> module documentation:
 	<para>See the <varname>xmlrpc</varname> module documentation:
-	<ulink url='http://git.sip-router.org/cgi-bin/gitweb.cgi?p=sip-router;a=blob;f=modules_s/xmlrpc/README'>modules_s/xmlrpc/README</ulink>.
+	<ulink url='http://sip-router.org/docbook/sip-router/branch/master/modules_s/xmlrpc/xmlrpc.html'>modules_s/xmlrpc/README</ulink>.
 	</para>
 	</para>
 </section>
 </section>