Annotation of embedaddon/libpdel/structs/xmlrpc-test/nestedStructTest.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 nestedStructTest_handler;
! 44:
! 45: const struct http_servlet_xmlrpc_method nestedStructTest_method = {
! 46: "validator1.nestedStructTest",
! 47: nestedStructTest_handler,
! 48: NULL, /* this handler wants "exploded" parameters */
! 49: 1, 1
! 50: };
! 51:
! 52: static void *
! 53: nestedStructTest_handler(void *arg, const char *method,
! 54: struct http_request *req, u_int nparams, const void **params,
! 55: const char *mtype, const struct structs_type **rtypep, int *faulted)
! 56: {
! 57: const char *struct_names[] = { "2000", "04", "01", NULL };
! 58: const struct xmlrpc_value_union *v;
! 59: const struct xmlrpc_struct *s;
! 60: int32_t *result;
! 61: int32_t sum;
! 62: int i;
! 63: int j;
! 64:
! 65: alog(LOG_INFO, "method \"%s\" invoked", method);
! 66:
! 67: /* Find the nested structure */
! 68: for (i = 0, v = params[0]; struct_names[i] != NULL; i++) {
! 69: for (j = 0; ; j++) {
! 70: const struct xmlrpc_member *member;
! 71: const void *data = v;
! 72: char name[32];
! 73:
! 74: snprintf(name, sizeof(name), "struct.%d", j);
! 75: if (structs_find(&structs_type_xmlrpc_value,
! 76: name, (void **)&data, 0) == NULL)
! 77: return (NULL);
! 78: member = data;
! 79: if (strcmp(member->name, struct_names[i]) == 0) {
! 80: v = &member->value; /* found it */
! 81: break;
! 82: }
! 83: }
! 84: }
! 85:
! 86: /* Make sure we're now looking at a structure */
! 87: if (strcmp(v->field_name, "struct") != 0) {
! 88: errno = EINVAL;
! 89: return (NULL);
! 90: }
! 91: s = &v->un->struct_;
! 92:
! 93: /* Add together the three_stooges fields */
! 94: for (sum = i = 0; i < s->length; i++) {
! 95: if (strcmp(s->elems[i].name, "moe") != 0
! 96: && strcmp(s->elems[i].name, "larry") != 0
! 97: && strcmp(s->elems[i].name, "curly") != 0)
! 98: continue;
! 99: if (strcmp(s->elems[i].value.field_name, "i4") != 0) {
! 100: errno = EINVAL;
! 101: return (NULL);
! 102: }
! 103: sum += s->elems[i].value.un->i4;
! 104: }
! 105:
! 106: /* Copy result into malloc'd buffer */
! 107: if ((result = MALLOC(mtype, sizeof(*result))) == NULL)
! 108: return (NULL);
! 109: *result = sum;
! 110:
! 111: /* Return result */
! 112: *rtypep = &structs_type_int;
! 113: return (result);
! 114: }
! 115:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>