1 /* Copyright information is at the end of the file */
3 /*=========================================================================
4 ** XML-RPC Array Functions
5 **=========================================================================
8 #include "xmlrpc_config.h"
14 #include "xmlrpc_int.h"
18 xmlrpc_abort_if_array_bad(xmlrpc_value
* const arrayP
) {
22 else if (arrayP
->_type
!= XMLRPC_TYPE_ARRAY
)
25 size_t const arraySize
=
26 XMLRPC_MEMBLOCK_SIZE(xmlrpc_value
*, &arrayP
->_block
);
27 xmlrpc_value
** const contents
=
28 XMLRPC_MEMBLOCK_CONTENTS(xmlrpc_value
*, &arrayP
->_block
);
35 for (xmIndex
= 0; xmIndex
< arraySize
; ++xmIndex
) {
36 xmlrpc_value
* const itemP
= contents
[xmIndex
];
39 else if (itemP
->_refcount
< 1)
49 xmlrpc_destroyArrayContents(xmlrpc_value
* const arrayP
) {
50 /*----------------------------------------------------------------------------
51 Dispose of the contents of an array (but not the array value itself).
52 The value is not valid after this.
53 -----------------------------------------------------------------------------*/
54 size_t const arraySize
=
55 XMLRPC_MEMBLOCK_SIZE(xmlrpc_value
*, &arrayP
->_block
);
56 xmlrpc_value
** const contents
=
57 XMLRPC_MEMBLOCK_CONTENTS(xmlrpc_value
*, &arrayP
->_block
);
61 XMLRPC_ASSERT_ARRAY_OK(arrayP
);
63 /* Release our reference to each item in the array */
64 for (xmIndex
= 0; xmIndex
< arraySize
; ++xmIndex
) {
65 xmlrpc_value
* const itemP
= contents
[xmIndex
];
68 XMLRPC_MEMBLOCK_CLEAN(xmlrpc_value
*, &arrayP
->_block
);
74 xmlrpc_array_size(xmlrpc_env
* const env
,
75 const xmlrpc_value
* const array
) {
79 /* Suppress a compiler warning about uninitialized variables. */
82 XMLRPC_ASSERT_ENV_OK(env
);
83 XMLRPC_ASSERT_VALUE_OK(array
);
84 XMLRPC_TYPE_CHECK(env
, array
, XMLRPC_TYPE_ARRAY
);
86 retval
= (int)XMLRPC_TYPED_MEM_BLOCK_SIZE(xmlrpc_value
*, &array
->_block
);
89 if (env
->fault_occurred
)
98 xmlrpc_array_append_item(xmlrpc_env
* const envP
,
99 xmlrpc_value
* const arrayP
,
100 xmlrpc_value
* const valueP
) {
102 XMLRPC_ASSERT_ENV_OK(envP
);
103 XMLRPC_ASSERT_VALUE_OK(arrayP
);
105 if (xmlrpc_value_type(arrayP
) != XMLRPC_TYPE_ARRAY
)
106 xmlrpc_env_set_fault_formatted(
107 envP
, XMLRPC_TYPE_ERROR
, "Value is not an array");
110 XMLRPC_MEMBLOCK_SIZE(xmlrpc_value
*, &arrayP
->_block
);
112 XMLRPC_MEMBLOCK_RESIZE(xmlrpc_value
*, envP
, &arrayP
->_block
, size
+1);
114 if (!envP
->fault_occurred
) {
115 xmlrpc_value
** const contents
=
116 XMLRPC_MEMBLOCK_CONTENTS(xmlrpc_value
*, &arrayP
->_block
);
117 xmlrpc_INCREF(valueP
);
118 contents
[size
] = valueP
;
126 xmlrpc_array_read_item(xmlrpc_env
* const envP
,
127 const xmlrpc_value
* const arrayP
,
128 unsigned int const xmIndex
,
129 xmlrpc_value
** const valuePP
) {
131 XMLRPC_ASSERT_ENV_OK(envP
);
132 XMLRPC_ASSERT_VALUE_OK(arrayP
);
133 XMLRPC_ASSERT_PTR_OK(valuePP
);
135 if (arrayP
->_type
!= XMLRPC_TYPE_ARRAY
)
136 xmlrpc_env_set_fault_formatted(
137 envP
, XMLRPC_TYPE_ERROR
, "Attempt to read array item from "
138 "a value that is not an array");
140 xmlrpc_value
** const contents
=
141 XMLRPC_MEMBLOCK_CONTENTS(xmlrpc_value
*, &arrayP
->_block
);
143 XMLRPC_MEMBLOCK_SIZE(xmlrpc_value
*, &arrayP
->_block
);
146 xmlrpc_env_set_fault_formatted(
147 envP
, XMLRPC_INDEX_ERROR
, "Array index %u is beyond end "
148 "of %u-item array", xmIndex
, (unsigned int)size
);
150 *valuePP
= contents
[xmIndex
];
151 xmlrpc_INCREF(*valuePP
);
159 xmlrpc_array_get_item(xmlrpc_env
* const envP
,
160 const xmlrpc_value
* const arrayP
,
163 xmlrpc_value
* valueP
;
166 xmlrpc_env_set_fault_formatted(
167 envP
, XMLRPC_INDEX_ERROR
, "Index %d is negative.");
169 xmlrpc_array_read_item(envP
, arrayP
, xmIndex
, &valueP
);
171 if (!envP
->fault_occurred
)
172 xmlrpc_DECREF(valueP
);
174 if (envP
->fault_occurred
)
182 /* Copyright (C) 2001 by First Peer, Inc. All rights reserved.
183 ** Copyright (C) 2001 by Eric Kidd. All rights reserved.
185 ** Redistribution and use in source and binary forms, with or without
186 ** modification, are permitted provided that the following conditions
188 ** 1. Redistributions of source code must retain the above copyright
189 ** notice, this list of conditions and the following disclaimer.
190 ** 2. Redistributions in binary form must reproduce the above copyright
191 ** notice, this list of conditions and the following disclaimer in the
192 ** documentation and/or other materials provided with the distribution.
193 ** 3. The name of the author may not be used to endorse or promote products
194 ** derived from this software without specific prior written permission.
196 ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
197 ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
198 ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
199 ** ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
200 ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
201 ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
202 ** OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
203 ** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
204 ** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
205 ** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF