Annotation of embedaddon/libpdel/structs/xmlrpc-test/countTheEntities.c, revision 1.1.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: struct entities {
                     44:        int32_t ctLeftAngleBrackets;
                     45:        int32_t ctRightAngleBrackets;
                     46:        int32_t ctAmpersands;
                     47:        int32_t ctApostrophes;
                     48:        int32_t ctQuotes;
                     49: };
                     50: 
                     51: static const struct structs_field entities_fields[] = {
                     52:        STRUCTS_STRUCT_FIELD(entities, ctLeftAngleBrackets,
                     53:                &structs_type_int32),
                     54:        STRUCTS_STRUCT_FIELD(entities, ctRightAngleBrackets,
                     55:                &structs_type_int32),
                     56:        STRUCTS_STRUCT_FIELD(entities, ctAmpersands, &structs_type_int32),
                     57:        STRUCTS_STRUCT_FIELD(entities, ctApostrophes, &structs_type_int32),
                     58:        STRUCTS_STRUCT_FIELD(entities, ctQuotes, &structs_type_int32),
                     59:        STRUCTS_STRUCT_FIELD_END
                     60: };
                     61: static const struct structs_type entities_type
                     62:        = STRUCTS_STRUCT_TYPE(entities, entities_fields);
                     63: 
                     64: static const struct structs_type *countTheEntities_ptypes[] = {
                     65:        &structs_type_string
                     66: };
                     67: 
                     68: static http_servlet_xmlrpc_handler_t   countTheEntities_handler;
                     69: 
                     70: const struct   http_servlet_xmlrpc_method countTheEntities_method = {
                     71:        "validator1.countTheEntities",
                     72:        countTheEntities_handler,
                     73:        countTheEntities_ptypes,
                     74:        1, 1
                     75: };
                     76: 
                     77: static void *
                     78: countTheEntities_handler(void *arg, const char *method,
                     79:        struct http_request *req, u_int nparams, const void **params,
                     80:        const char *mtype, const struct structs_type **rtypep, int *faulted)
                     81: {
                     82:        const char *const string = *((char **)params[0]);
                     83:        struct entities *e;
                     84:        const char *s;
                     85: 
                     86:        alog(LOG_INFO, "method \"%s\" invoked", method);
                     87:        if ((e = MALLOC(mtype, sizeof(*e))) == NULL)
                     88:                return (NULL);
                     89:        memset(e, 0, sizeof(*e));
                     90:        for (s = string; *s != '\0'; s++) {
                     91:                switch (*s) {
                     92:                case '<':
                     93:                        e->ctLeftAngleBrackets++;
                     94:                        break;
                     95:                case '>':
                     96:                        e->ctRightAngleBrackets++;
                     97:                        break;
                     98:                case '&':
                     99:                        e->ctAmpersands++;
                    100:                        break;
                    101:                case '\'':
                    102:                        e->ctApostrophes++;
                    103:                        break;
                    104:                case '"':
                    105:                        e->ctQuotes++;
                    106:                        break;
                    107:                default:
                    108:                        break;
                    109:                }
                    110:        }
                    111:        *rtypep = &entities_type;
                    112:        return (e);
                    113: }
                    114: 
                    115: 

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