Apache HTTPD
chardata.c
Go to the documentation of this file.
1/*
2 __ __ _
3 ___\ \/ /_ __ __ _| |_
4 / _ \\ /| '_ \ / _` | __|
5 | __// \| |_) | (_| | |_
6 \___/_/\_\ .__/ \__,_|\__|
7 |_| XML parser
8
9 Copyright (c) 2002-2004 Fred L. Drake, Jr. <[email protected]>
10 Copyright (c) 2003 Greg Stein <[email protected]>
11 Copyright (c) 2016 Gilles Espinasse <[email protected]>
12 Copyright (c) 2016-2023 Sebastian Pipping <[email protected]>
13 Copyright (c) 2017 Joe Orton <[email protected]>
14 Copyright (c) 2017 Rhodri James <[email protected]>
15 Copyright (c) 2022 Sean McBride <[email protected]>
16 Licensed under the MIT license:
17
18 Permission is hereby granted, free of charge, to any person obtaining
19 a copy of this software and associated documentation files (the
20 "Software"), to deal in the Software without restriction, including
21 without limitation the rights to use, copy, modify, merge, publish,
22 distribute, sublicense, and/or sell copies of the Software, and to permit
23 persons to whom the Software is furnished to do so, subject to the
24 following conditions:
25
26 The above copyright notice and this permission notice shall be included
27 in all copies or substantial portions of the Software.
28
29 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
30 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
31 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
32 NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
33 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
34 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
35 USE OR OTHER DEALINGS IN THE SOFTWARE.
36*/
37
38#if defined(NDEBUG)
39# undef NDEBUG /* because test suite relies on assert(...) at the moment */
40#endif
41
42#include "expat_config.h"
43#include "minicheck.h"
44
45#include <assert.h>
46#include <stdio.h>
47#include <string.h>
48
49#include "chardata.h"
50
51static int
53 int len = 0;
54 assert(s != NULL);
55 while (s[len] != 0)
56 ++len;
57 return len;
58}
59
60void
63 storage->count = -1;
64}
65
66void
68 int maxchars;
69
71 assert(s != NULL);
72 maxchars = sizeof(storage->data) / sizeof(storage->data[0]);
73 if (storage->count < 0)
74 storage->count = 0;
75 if (len < 0)
76 len = xmlstrlen(s);
77 if ((len + storage->count) > maxchars) {
78 len = (maxchars - storage->count);
79 }
80 if (len + storage->count < (int)sizeof(storage->data)) {
81 memcpy(storage->data + storage->count, s, len * sizeof(storage->data[0]));
82 storage->count += len;
83 }
84}
85
86int
88 int len = xmlstrlen(expected);
89 int count;
90
92 count = (storage->count < 0) ? 0 : storage->count;
93 if (len != count) {
94 char buffer[1024];
95 snprintf(buffer, sizeof(buffer),
96 "wrong number of data characters: got %d, expected %d", count,
97 len);
98 fail(buffer);
99 return 0;
100 }
101 if (memcmp(expected, storage->data, len * sizeof(storage->data[0])) != 0) {
102 fail("got bad data bytes");
103 return 0;
104 }
105 return 1;
106}
const char apr_size_t len
Definition ap_regex.h:187
void CharData_Init(CharData *storage)
Definition chardata.c:61
int CharData_CheckXMLChars(CharData *storage, const XML_Char *expected)
Definition chardata.c:87
void CharData_AppendXMLChars(CharData *storage, const XML_Char *s, int len)
Definition chardata.c:67
static int xmlstrlen(const XML_Char *s)
Definition chardata.c:52
char XML_Char
unsigned int count
Definition apr_md5.h:152
apr_size_t size
char * buffer
const char * s
Definition apr_strings.h:95
#define fail(msg)
Definition minicheck.h:87
static const ap_slotmem_provider_t * storage
return NULL
Definition mod_so.c:359