Annotation of embedaddon/libpdel/structs/xmlrpc-test/manyTypesTest.c, revision 1.1

1.1     ! misho       1: 
        !             2: /*
        !             3:  * Copyright (c) 2001-2002 Packet Design, LLC.
        !             4:  * All rights reserved.
        !             5:  * 
        !             6:  * Subject to the following obligations and disclaimer of warranty,
        !             7:  * use and redistribution of this software, in source or object code
        !             8:  * forms, with or without modifications are expressly permitted by
        !             9:  * Packet Design; provided, however, that:
        !            10:  * 
        !            11:  *    (i)  Any and all reproductions of the source or object code
        !            12:  *         must include the copyright notice above and the following
        !            13:  *         disclaimer of warranties; and
        !            14:  *    (ii) No rights are granted, in any manner or form, to use
        !            15:  *         Packet Design trademarks, including the mark "PACKET DESIGN"
        !            16:  *         on advertising, endorsements, or otherwise except as such
        !            17:  *         appears in the above copyright notice or in the software.
        !            18:  * 
        !            19:  * THIS SOFTWARE IS BEING PROVIDED BY PACKET DESIGN "AS IS", AND
        !            20:  * TO THE MAXIMUM EXTENT PERMITTED BY LAW, PACKET DESIGN MAKES NO
        !            21:  * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING
        !            22:  * THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED
        !            23:  * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
        !            24:  * OR NON-INFRINGEMENT.  PACKET DESIGN DOES NOT WARRANT, GUARANTEE,
        !            25:  * OR MAKE ANY REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS
        !            26:  * OF THE USE OF THIS SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY,
        !            27:  * RELIABILITY OR OTHERWISE.  IN NO EVENT SHALL PACKET DESIGN BE
        !            28:  * LIABLE FOR ANY DAMAGES RESULTING FROM OR ARISING OUT OF ANY USE
        !            29:  * OF THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, ANY DIRECT,
        !            30:  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE, OR CONSEQUENTIAL
        !            31:  * DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, LOSS OF
        !            32:  * USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY THEORY OF
        !            33:  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
        !            34:  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
        !            35:  * THE USE OF THIS SOFTWARE, EVEN IF PACKET DESIGN IS ADVISED OF
        !            36:  * THE POSSIBILITY OF SUCH DAMAGE.
        !            37:  *
        !            38:  * Author: Archie Cobbs <archie@freebsd.org>
        !            39:  */
        !            40: 
        !            41: #include "xmlrpc_test.h"
        !            42: 
        !            43: static http_servlet_xmlrpc_handler_t   manyTypesTest_handler;
        !            44: 
        !            45: const struct   http_servlet_xmlrpc_method manyTypesTest_method = {
        !            46:        "validator1.manyTypesTest",
        !            47:        manyTypesTest_handler,
        !            48:        NULL,                   /* this handler wants "exploded" parameters */
        !            49:        6, 6
        !            50: };
        !            51: 
        !            52: static void *
        !            53: manyTypesTest_handler(void *arg, const char *method, struct http_request *req,
        !            54:        u_int nparams, const void **params, const char *mtype,
        !            55:        const struct structs_type **rtypep, int *faulted)
        !            56: {
        !            57:        const struct structs_type *const vtype = &structs_type_xmlrpc_value;
        !            58:        struct xmlrpc_value_union *v;
        !            59:        int i;
        !            60: 
        !            61:        alog(LOG_INFO, "method \"%s\" invoked", method);
        !            62: 
        !            63:        /* Initialize "exploded" XML-RPC return value */
        !            64:        if ((v = MALLOC(mtype, sizeof(*v))) == NULL)
        !            65:                return (NULL);
        !            66:        if (structs_init(vtype, NULL, v) == -1)
        !            67:                goto fail1;
        !            68: 
        !            69:        /* Set returned value to be an array */
        !            70:        if (structs_union_set(vtype, NULL, v, "array") == -1)
        !            71:                goto fail2;
        !            72: 
        !            73:        /* Copy input parameters into the output array */
        !            74:        for (i = 0; i < nparams; i++) {
        !            75:                char name[32];
        !            76: 
        !            77:                if (structs_array_insert(vtype, "array.data", i, v) == -1)
        !            78:                        goto fail2;
        !            79:                snprintf(name, sizeof(name), "array.data.%d", i);
        !            80:                if (structs_set(vtype, params[i], name, v) == -1)
        !            81:                        goto fail2;
        !            82:        }
        !            83: 
        !            84:        /* Return "raw" result */
        !            85:        *rtypep = NULL;
        !            86:        return (v);
        !            87: 
        !            88:        /* Clean up after failure */
        !            89: fail2: structs_free(vtype, NULL, v);
        !            90: fail1: FREE(mtype, v);
        !            91:        return (NULL);
        !            92: }
        !            93: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>