1 /* Copyright information is at end of file */
3 #include "xmlrpc_config.h"
10 #include "xmlrpc-c/util_int.h"
11 #include "xmlrpc-c/util.h"
14 #define ERROR_BUFFER_SZ (256)
17 xmlrpc_assertion_failed(const char * const fileName,
18 int const lineNumber) {
20 fprintf(stderr, "%s:%d: assertion failed\n", fileName, lineNumber);
26 static const char * const default_fault_string =
27 "Not enough memory for error message";
29 void xmlrpc_env_init (xmlrpc_env* env)
31 XMLRPC_ASSERT(env != NULL);
33 env->fault_occurred = 0;
35 env->fault_string = NULL;
39 xmlrpc_env_clean(xmlrpc_env * const envP) {
41 XMLRPC_ASSERT(envP != NULL);
42 XMLRPC_ASSERT(envP->fault_string != XMLRPC_BAD_POINTER);
44 /* env->fault_string may be one of three things:
46 ** 2) a pointer to the default_fault_string
47 ** 3) a pointer to a malloc'd fault string
48 ** If we have case (3), we'll need to free it. */
49 if (envP->fault_string && envP->fault_string != default_fault_string)
50 free(envP->fault_string);
51 envP->fault_string = XMLRPC_BAD_POINTER;
57 xmlrpc_env_set_fault(xmlrpc_env * const envP,
59 const char * const faultDescription) {
61 XMLRPC_ASSERT(envP != NULL);
62 XMLRPC_ASSERT(faultDescription != NULL);
64 /* Clean up any leftover pointers. */
65 xmlrpc_env_clean(envP);
67 envP->fault_occurred = 1;
68 envP->fault_code = faultCode;
70 /* Try to copy the fault string. If this fails, use a default. */
71 envP->fault_string = strdup(faultDescription);
72 if (envP->fault_string == NULL)
73 envP->fault_string = (char *)default_fault_string;
79 set_fault_formatted_v(xmlrpc_env * const envP,
81 const char * const format,
84 char buffer[ERROR_BUFFER_SZ];
86 vsnprintf(buffer, ERROR_BUFFER_SZ, format, args);
88 /* vsnprintf is guaranteed to terminate the buffer, but we're paranoid. */
89 buffer[ERROR_BUFFER_SZ - 1] = '\0';
92 xmlrpc_env_set_fault(envP, code, buffer);
98 xmlrpc_env_set_fault_formatted(xmlrpc_env * const envP,
100 const char * const format,
104 XMLRPC_ASSERT(envP != NULL);
105 XMLRPC_ASSERT(format != NULL);
107 /* Print our error message to the buffer. */
108 va_start(args, format);
109 set_fault_formatted_v(envP, code, format, args);
116 xmlrpc_faultf(xmlrpc_env * const envP,
117 const char * const format,
122 XMLRPC_ASSERT(envP != NULL);
123 XMLRPC_ASSERT(format != NULL);
125 /* Print our error message to the buffer. */
126 va_start(args, format);
127 set_fault_formatted_v(envP, XMLRPC_INTERNAL_ERROR, format, args);
134 /* Copyright (C) 2001 by First Peer, Inc. All rights reserved.
136 ** Redistribution and use in source and binary forms, with or without
137 ** modification, are permitted provided that the following conditions
139 ** 1. Redistributions of source code must retain the above copyright
140 ** notice, this list of conditions and the following disclaimer.
141 ** 2. Redistributions in binary form must reproduce the above copyright
142 ** notice, this list of conditions and the following disclaimer in the
143 ** documentation and/or other materials provided with the distribution.
144 ** 3. The name of the author may not be used to endorse or promote products
145 ** derived from this software without specific prior written permission.
147 ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
148 ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
149 ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
150 ** ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
151 ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
152 ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
153 ** OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
154 ** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
155 ** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
156 ** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF