mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-08-13 09:36:46 +00:00
merged new xmlrpc-c revision 1472 from https://xmlrpc-c.svn.sourceforge.net/svnroot/xmlrpc-c/trunk
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8545 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
27
libs/xmlrpc-c/lib/util/include/assertx.hpp
Normal file
27
libs/xmlrpc-c/lib/util/include/assertx.hpp
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifndef ASSERTX_HPP_INCLUDED
|
||||
#define ASSERTX_HPP_INCLUDED
|
||||
|
||||
#include <cassert>
|
||||
|
||||
/* The compiler often warns you if you give a function formal parameter a
|
||||
name, but don't use it. But because assert() disappears when doing an
|
||||
optimized build, the compiler doesn't recognize your reference to the
|
||||
parameter in the assert() argument. To avoid the bogus warning in
|
||||
this case, we have ASSERT_ONLY_ARG(), which declares a name for a
|
||||
formal parameter for purposes of assert() only. In cases where an
|
||||
assert() would disappear, ASSERT_ONLY_ARG() disappears too.
|
||||
|
||||
E.g.
|
||||
|
||||
void foo(int const ASSERT_ONLY_ARG(arg1)) {
|
||||
|
||||
assert(arg1 > 0);
|
||||
}
|
||||
*/
|
||||
#ifdef NDEBUG
|
||||
#define ASSERT_ONLY_ARG(x)
|
||||
#else
|
||||
#define ASSERT_ONLY_ARG(x) x
|
||||
#endif
|
||||
|
||||
#endif
|
@@ -1,18 +1,18 @@
|
||||
#ifndef BOOL_H_INCLUDED
|
||||
#define BOOL_H_INCLUDED
|
||||
/* This takes the place of C99 stdbool.h, which at least some Windows
|
||||
compilers don't have. (October 2005).
|
||||
|
||||
#ifndef TRUE
|
||||
#define TRUE (1)
|
||||
#endif
|
||||
#ifndef FALSE
|
||||
#define FALSE (0)
|
||||
#endif
|
||||
One must not also include <stdbool.h>, because it might cause a name
|
||||
collision.
|
||||
*/
|
||||
|
||||
#ifndef __cplusplus
|
||||
#ifndef HAVE_BOOL
|
||||
#define HAVE_BOOL
|
||||
typedef int bool;
|
||||
/* At least the GNU compiler defines __bool_true_false_are_defined */
|
||||
#ifndef __bool_true_false_are_defined
|
||||
#define __bool_true_false_are_defined
|
||||
typedef enum {
|
||||
false = 0,
|
||||
true = 1
|
||||
} bool;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
19
libs/xmlrpc-c/lib/util/include/c_util.h
Normal file
19
libs/xmlrpc-c/lib/util/include/c_util.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#ifndef C_UTIL_H_INCLUDED
|
||||
#define C_UTIL_H_INCLUDED
|
||||
|
||||
/* C language stuff. Doesn't involve any libraries that aren't part of
|
||||
the compiler.
|
||||
*/
|
||||
|
||||
#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
|
||||
|
||||
/* GNU_PRINTF_ATTR lets the GNU compiler check printf-type
|
||||
calls to be sure the arguments match the format string, thus preventing
|
||||
runtime segmentation faults and incorrect messages.
|
||||
*/
|
||||
#ifdef __GNUC__
|
||||
#define GNU_PRINTF_ATTR(a,b) __attribute__ ((format (printf, a, b)))
|
||||
#else
|
||||
#define GNU_PRINTF_ATTR(a,b)
|
||||
#endif
|
||||
#endif
|
@@ -3,16 +3,14 @@
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
/* GNU_PRINTF_ATTR lets the GNU compiler check printf-type
|
||||
calls to be sure the arguments match the format string, thus preventing
|
||||
runtime segmentation faults and incorrect messages.
|
||||
*/
|
||||
#ifdef __GNUC__
|
||||
#define GNU_PRINTF_ATTR(a,b) __attribute__ ((format (printf, a, b)))
|
||||
#else
|
||||
#define GNU_PRINTF_ATTR(a,b)
|
||||
#include "c_util.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern const char * const strsol;
|
||||
|
||||
void
|
||||
cvasprintf(const char ** const retvalP,
|
||||
const char * const fmt,
|
||||
@@ -24,4 +22,8 @@ casprintf(const char ** const retvalP, const char * const fmt, ...);
|
||||
void
|
||||
strfree(const char * const string);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@@ -1,6 +1,14 @@
|
||||
#ifndef CMDLINE_PARSER_H
|
||||
#define CMDLINE_PARSER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#if 0
|
||||
} /* to fake out automatic code indenters */
|
||||
#endif
|
||||
|
||||
#include "int.h"
|
||||
|
||||
/*
|
||||
|
||||
@@ -10,17 +18,24 @@
|
||||
|
||||
*/
|
||||
|
||||
enum optiontype {OPTTYPE_FLAG, OPTTYPE_INT, OPTTYPE_UINT, OPTTYPE_STRING};
|
||||
enum optiontype {
|
||||
OPTTYPE_FLAG,
|
||||
OPTTYPE_INT,
|
||||
OPTTYPE_UINT,
|
||||
OPTTYPE_STRING,
|
||||
OPTTYPE_BINUINT,
|
||||
OPTTYPE_FLOAT
|
||||
};
|
||||
|
||||
struct cmdlineParserCtl;
|
||||
|
||||
typedef struct cmdlineParserCtl * cmdlineParser;
|
||||
|
||||
void
|
||||
cmd_processOptions(cmdlineParser const cpP,
|
||||
int const argc,
|
||||
const char ** const argv,
|
||||
const char ** const errorP);
|
||||
cmd_processOptions(cmdlineParser const cpP,
|
||||
int const argc,
|
||||
const char ** const argv,
|
||||
const char ** const errorP);
|
||||
|
||||
cmdlineParser
|
||||
cmd_createOptionParser(void);
|
||||
@@ -37,18 +52,26 @@ int
|
||||
cmd_optionIsPresent(cmdlineParser const cpP,
|
||||
const char * const name);
|
||||
|
||||
unsigned int
|
||||
cmd_getOptionValueUint(cmdlineParser const cpP,
|
||||
const char * const name);
|
||||
|
||||
int
|
||||
cmd_getOptionValueInt(cmdlineParser const cpP,
|
||||
const char * const name);
|
||||
|
||||
unsigned int
|
||||
cmd_getOptionValueUint(cmdlineParser const cpP,
|
||||
const char * const name);
|
||||
|
||||
const char *
|
||||
cmd_getOptionValueString(cmdlineParser const cpP,
|
||||
const char * const name);
|
||||
|
||||
uint64_t
|
||||
cmd_getOptionValueBinUint(cmdlineParser const cpP,
|
||||
const char * const name);
|
||||
|
||||
double
|
||||
cmd_getOptionValueFloat(cmdlineParser const cpP,
|
||||
const char * const name);
|
||||
|
||||
unsigned int
|
||||
cmd_argumentCount(cmdlineParser const cpP);
|
||||
|
||||
@@ -56,4 +79,8 @@ const char *
|
||||
cmd_getArgument(cmdlineParser const cpP,
|
||||
unsigned int const argNumber);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
59
libs/xmlrpc-c/lib/util/include/cmdline_parser.hpp
Normal file
59
libs/xmlrpc-c/lib/util/include/cmdline_parser.hpp
Normal file
@@ -0,0 +1,59 @@
|
||||
#ifndef CMDLINE_PARSER_HPP_INCLUDED
|
||||
#define CMDLINE_PARSER_HPP_INCLUDED
|
||||
|
||||
#include <string>
|
||||
|
||||
struct cmdlineParserCtl;
|
||||
|
||||
class CmdlineParser {
|
||||
public:
|
||||
CmdlineParser();
|
||||
|
||||
~CmdlineParser();
|
||||
|
||||
enum optType {FLAG, INT, UINT, STRING, BINUINT, FLOAT};
|
||||
|
||||
void
|
||||
defineOption(std::string const optionName,
|
||||
optType const optionType);
|
||||
|
||||
void
|
||||
processOptions(int const argc,
|
||||
const char ** const argv);
|
||||
|
||||
bool
|
||||
optionIsPresent(std::string const optionName) const;
|
||||
|
||||
int
|
||||
getOptionValueInt(std::string const optionName) const;
|
||||
|
||||
unsigned int
|
||||
getOptionValueUint(std::string const optionName) const;
|
||||
|
||||
std::string
|
||||
getOptionValueString(std::string const optionName) const;
|
||||
|
||||
unsigned long long
|
||||
getOptionValueBinUint(std::string const optionName) const;
|
||||
|
||||
double
|
||||
getOptionValueFloat(std::string const optionName) const;
|
||||
|
||||
unsigned int
|
||||
argumentCount() const;
|
||||
|
||||
std::string
|
||||
getArgument(unsigned int const argNumber) const;
|
||||
|
||||
private:
|
||||
struct cmdlineParserCtl * cp;
|
||||
|
||||
// Make sure no one can copy this object, because if there are two
|
||||
// copies, there will be two attempts to destroy *cp.
|
||||
CmdlineParser(CmdlineParser const&) {};
|
||||
|
||||
CmdlineParser&
|
||||
operator=(CmdlineParser const&) {return *this;}
|
||||
};
|
||||
|
||||
#endif
|
8
libs/xmlrpc-c/lib/util/include/girmath.h
Normal file
8
libs/xmlrpc-c/lib/util/include/girmath.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef __GIRMATH_H
|
||||
#define __GIRMATH_H
|
||||
|
||||
#define MIN(a,b) ((a) < (b) ? (a) : (b))
|
||||
#define MAX(a,b) ((a) > (b) ? (a) : (b))
|
||||
|
||||
#endif
|
||||
|
51
libs/xmlrpc-c/lib/util/include/girstring.h
Normal file
51
libs/xmlrpc-c/lib/util/include/girstring.h
Normal file
@@ -0,0 +1,51 @@
|
||||
#ifndef GIRSTRING_H_INCLUDED
|
||||
#define GIRSTRING_H_INCLUDED
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "xmlrpc_config.h"
|
||||
#include "bool.h"
|
||||
|
||||
bool
|
||||
stripcaseeq(const char * const comparand,
|
||||
const char * const comparator);
|
||||
|
||||
static __inline__ bool
|
||||
streq(const char * const comparator,
|
||||
const char * const comparand) {
|
||||
|
||||
return (strcmp(comparand, comparator) == 0);
|
||||
}
|
||||
|
||||
static __inline__ bool
|
||||
memeq(const void * const comparator,
|
||||
const void * const comparand,
|
||||
size_t const size) {
|
||||
|
||||
return (memcmp(comparator, comparand, size) == 0);
|
||||
}
|
||||
|
||||
#define MEMEQ(a,b,c) (memcmp(a, b, c) == 0)
|
||||
|
||||
#define MEMSSET(a,b) (memset(a, b, sizeof(*a)))
|
||||
|
||||
#define MEMSCPY(a,b) (memcpy(a, b, sizeof(*a)))
|
||||
|
||||
#define MEMSZERO(a) (MEMSSET(a, 0))
|
||||
|
||||
static __inline__ const char *
|
||||
sdup(const char * const input) {
|
||||
return (const char *) strdup(input);
|
||||
}
|
||||
|
||||
/* Copy string pointed by B to array A with size checking. */
|
||||
#define STRSCPY(A,B) \
|
||||
(strncpy((A), (B), sizeof(A)), *((A)+sizeof(A)-1) = '\0')
|
||||
#define STRSCMP(A,B) \
|
||||
(strncmp((A), (B), sizeof(A)))
|
||||
|
||||
/* Concatenate string B onto string in array A with size checking */
|
||||
#define STRSCAT(A,B) \
|
||||
(strncat((A), (B), sizeof(A)-strlen(A)), *((A)+sizeof(A)-1) = '\0')
|
||||
|
||||
#endif
|
53
libs/xmlrpc-c/lib/util/include/int.h
Normal file
53
libs/xmlrpc-c/lib/util/include/int.h
Normal file
@@ -0,0 +1,53 @@
|
||||
/* This takes the place of C99 inttypes.h, which at least some Windows
|
||||
compilers don't have. (October 2007).
|
||||
*/
|
||||
|
||||
/* PRId64 is the printf-style format specifier for a long long type, as in
|
||||
long long mynumber = 5;
|
||||
printf("My number is %" PRId64 ".\n", mynumber);
|
||||
|
||||
The LL/ULL macro is for 64 bit integer literals, like this:
|
||||
|
||||
long long mask= ULL(1) << 33;
|
||||
*/
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# define PRId64 "I64d"
|
||||
# define PRIu64 "I64u"
|
||||
|
||||
#ifndef int16_t
|
||||
typedef short int16_t;
|
||||
#endif
|
||||
#ifndef uint16_t
|
||||
typedef unsigned short uint16_t;
|
||||
#endif
|
||||
#ifndef int32_t
|
||||
typedef int int32_t;
|
||||
#endif
|
||||
#ifndef uint32_t
|
||||
typedef unsigned int uint32_t;
|
||||
#endif
|
||||
#ifndef int64_t
|
||||
typedef __int64 int64_t;
|
||||
#endif
|
||||
#ifndef uint64_t
|
||||
typedef unsigned __int64 uint64_t;
|
||||
#endif
|
||||
#ifndef uint
|
||||
typedef unsigned int uint;
|
||||
#endif
|
||||
#ifndef uint8_t
|
||||
typedef unsigned char uint8_t;
|
||||
#endif
|
||||
|
||||
/* Older Microsoft compilers don't know the standard ll/ull suffixes */
|
||||
#define LL(x) x ## i64
|
||||
#define ULL(x) x ## u64
|
||||
|
||||
#else
|
||||
/* Not Microsoft compiler */
|
||||
#include <inttypes.h>
|
||||
#define LL(x) x ## ll
|
||||
#define ULL(x) x ## ull
|
||||
#endif
|
||||
|
@@ -50,14 +50,28 @@ static __inline__ void
|
||||
reallocProduct(void ** const blockP,
|
||||
unsigned int const factor1,
|
||||
unsigned int const factor2) {
|
||||
|
||||
void * const oldBlockP = *blockP;
|
||||
|
||||
void * newBlockP;
|
||||
|
||||
if (UINT_MAX / factor2 < factor1)
|
||||
*blockP = NULL;
|
||||
newBlockP = NULL;
|
||||
else
|
||||
*blockP = realloc(*blockP, factor1 * factor2);
|
||||
newBlockP = realloc(oldBlockP, factor1 * factor2);
|
||||
|
||||
if (newBlockP)
|
||||
*blockP = newBlockP;
|
||||
else {
|
||||
free(oldBlockP);
|
||||
*blockP = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* IMPLEMENTATION NOTE: There are huge strict aliasing pitfalls here
|
||||
if you cast pointers, e.g. (void **)
|
||||
*/
|
||||
|
||||
#define MALLOCARRAY(arrayName, nElements) do { \
|
||||
void * array; \
|
||||
@@ -65,8 +79,11 @@ reallocProduct(void ** const blockP,
|
||||
arrayName = array; \
|
||||
} while (0)
|
||||
|
||||
#define REALLOCARRAY(arrayName, nElements) \
|
||||
reallocProduct((void **)&arrayName, nElements, sizeof(arrayName[0]))
|
||||
#define REALLOCARRAY(arrayName, nElements) do { \
|
||||
void * array = arrayName; \
|
||||
reallocProduct(&array, nElements, sizeof(arrayName[0])); \
|
||||
arrayName = array; \
|
||||
} while (0)
|
||||
|
||||
|
||||
#define MALLOCARRAY_NOFAIL(arrayName, nElements) \
|
||||
|
@@ -30,39 +30,51 @@
|
||||
# define _REENTRANT
|
||||
# include <pthread.h>
|
||||
#elif defined (WIN32)
|
||||
#include <windows.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef HANDLE pthread_t;
|
||||
typedef CRITICAL_SECTION pthread_mutex_t;
|
||||
|
||||
#define PTHREAD_MUTEX_INITIALIZER NULL
|
||||
//usage: pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
/* usage: pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; */
|
||||
|
||||
typedef
|
||||
struct {
|
||||
int attrs; //currently unused. placeholder.
|
||||
int attrs; /* currently unused. placeholder. */
|
||||
} pthread_attr_t;
|
||||
|
||||
typedef
|
||||
struct {
|
||||
int attrs; //currently unused. placeholder.
|
||||
int attrs; /* currently unused. placeholder. */
|
||||
} pthread_mutexattr_t;
|
||||
|
||||
//typedef void * (*pthread_func)(void *);
|
||||
typedef unsigned ( __stdcall *pthread_func )( void * );
|
||||
/* We make pthread_func identical to a Windows thread start function
|
||||
so we can use Windows thread functions to implement these pthread
|
||||
functions directly.
|
||||
*/
|
||||
typedef unsigned (WINAPI pthread_func)(void *);
|
||||
|
||||
extern int pthread_create(pthread_t *new_thread_ID,
|
||||
const pthread_attr_t *attr,
|
||||
pthread_func start_func, void *arg);
|
||||
extern int pthread_create(pthread_t * const new_thread_ID,
|
||||
const pthread_attr_t * const attr,
|
||||
pthread_func * start_func,
|
||||
void * const arg);
|
||||
extern int pthread_cancel(pthread_t target_thread);
|
||||
extern int pthread_join(pthread_t target_thread, void **status);
|
||||
extern int pthread_detach(pthread_t target_thread);
|
||||
|
||||
extern int pthread_mutex_init(pthread_mutex_t *mp,
|
||||
const pthread_mutexattr_t *attr);
|
||||
extern int pthread_mutex_lock(pthread_mutex_t *mp);
|
||||
extern int pthread_mutex_unlock(pthread_mutex_t *mp);
|
||||
extern int pthread_mutex_destroy(pthread_mutex_t *mp);
|
||||
extern int pthread_mutex_init(pthread_mutex_t * const mp,
|
||||
const pthread_mutexattr_t * const attr);
|
||||
extern int pthread_mutex_lock(pthread_mutex_t * const mp);
|
||||
extern int pthread_mutex_unlock(pthread_mutex_t * const mp);
|
||||
extern int pthread_mutex_destroy(pthread_mutex_t * const mp);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* WIN32 */
|
||||
|
||||
#endif
|
||||
|
67
libs/xmlrpc-c/lib/util/include/stdargx.h
Normal file
67
libs/xmlrpc-c/lib/util/include/stdargx.h
Normal file
@@ -0,0 +1,67 @@
|
||||
#ifndef STDARGX_H_INCLUDED
|
||||
#define STDARGX_H_INCLUDED
|
||||
|
||||
#include "xmlrpc_config.h"
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
We need a special version of va_list in order to pass around the
|
||||
variable argument heap by reference, thus allowing a subroutine to
|
||||
advance the heap's pointer.
|
||||
|
||||
On some systems (e.g. Gcc for PPC or AMD64), va_list is an array.
|
||||
That invites the scourge of array-to-pointer degeneration if you try
|
||||
to take its address. Burying it inside a struct as we do with out
|
||||
va_listx type makes it immune.
|
||||
|
||||
Example of what would happen if we used va_list instead of va_listx,
|
||||
on a system where va_list is an array:
|
||||
|
||||
void sub2(va_list * argsP) [
|
||||
...
|
||||
}
|
||||
|
||||
void sub1(va_list args) {
|
||||
sub2(&args);
|
||||
}
|
||||
|
||||
This doesn't work. '&args' is the same thing as 'args', so is
|
||||
va_list, not va_list *. The compiler will even warn you about the
|
||||
pointer type mismatch.
|
||||
|
||||
To use va_listx:
|
||||
|
||||
void sub1_va(char * format, va_list args) {
|
||||
va_listx argsx;
|
||||
init_va_listx(&argsx, args);
|
||||
sub2(format, &argsx);
|
||||
}
|
||||
|
||||
-----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
typedef struct {
|
||||
/*----------------------------------------------------------------------------
|
||||
Same thing as va_list, but in a form that works everywhere. See above.
|
||||
-----------------------------------------------------------------------------*/
|
||||
va_list v;
|
||||
} va_listx;
|
||||
|
||||
|
||||
|
||||
static __inline__ void
|
||||
init_va_listx(va_listx * const argsxP,
|
||||
va_list const args) {
|
||||
#if VA_LIST_IS_ARRAY
|
||||
/* 'args' is NOT a va_list. It is a pointer to the first element of a
|
||||
'va_list', which is the same address as a pointer to the va_list
|
||||
itself.
|
||||
*/
|
||||
memcpy(&argsxP->v, args, sizeof(argsxP->v));
|
||||
#else
|
||||
argsxP->v = args;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
31
libs/xmlrpc-c/lib/util/include/string_parser.h
Normal file
31
libs/xmlrpc-c/lib/util/include/string_parser.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#ifndef STRING_PARSER_H_INCLUDED
|
||||
#define STRING_PARSER_H_INCLUDED
|
||||
|
||||
#include "int.h"
|
||||
|
||||
void
|
||||
interpretUll(const char * const string,
|
||||
uint64_t * const ullP,
|
||||
const char ** const errorP);
|
||||
|
||||
void
|
||||
interpretLl(const char * const string,
|
||||
int64_t * const llP,
|
||||
const char ** const errorP);
|
||||
|
||||
void
|
||||
interpretUint(const char * const string,
|
||||
unsigned int * const uintP,
|
||||
const char ** const errorP);
|
||||
|
||||
void
|
||||
interpretInt(const char * const string,
|
||||
int * const uintP,
|
||||
const char ** const errorP);
|
||||
|
||||
void
|
||||
interpretBinUint(const char * const string,
|
||||
uint64_t * const valueP,
|
||||
const char ** const errorP);
|
||||
|
||||
#endif
|
14
libs/xmlrpc-c/lib/util/include/unistdx.h
Normal file
14
libs/xmlrpc-c/lib/util/include/unistdx.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef UNISTDX_H_INCLUDED
|
||||
#define UNISTDX_H_INCLUDED
|
||||
|
||||
/* Xmlrpc-c code #includes "unistdx.h" instead of <unistd.h> because
|
||||
<unistd.h> does not exist on WIN32.
|
||||
*/
|
||||
|
||||
#ifndef WIN32
|
||||
# include <unistd.h>
|
||||
#else
|
||||
|
||||
#endif /* WIN32 */
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user