mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-01-18 19:47:15 +01:00
Rename source to module.
This commit is contained in:
parent
a5c87bae5e
commit
c0fd374404
@ -1,51 +0,0 @@
|
||||
#ifndef MAXMINDDB_CONFIG_H
|
||||
#define MAXMINDDB_CONFIG_H
|
||||
|
||||
#ifndef MMDB_UINT128_USING_MODE
|
||||
/* Define as 1 if we we use unsigned int __atribute__ ((__mode__(TI))) for uint128 values */
|
||||
#if __x86_64__
|
||||
#define MMDB_UINT128_USING_MODE 1
|
||||
#else
|
||||
#define MMDB_UINT128_USING_MODE 0
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef MMDB_UINT128_IS_BYTE_ARRAY
|
||||
/* Define as 1 if we don't have an unsigned __int128 type */\
|
||||
#if __x86_64__
|
||||
#undef MMDB_UINT128_IS_BYTE_ARRAY
|
||||
#else
|
||||
#define MMDB_UINT128_IS_BYTE_ARRAY 1
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/* Name of package */
|
||||
#define PACKAGE "libmaxminddb"
|
||||
|
||||
/* Define to the address where bug reports for this package should be sent. */
|
||||
#define PACKAGE_BUGREPORT "support@maxmind.com"
|
||||
|
||||
/* Define to the full name of this package. */
|
||||
#define PACKAGE_NAME "libmaxminddb"
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#define PACKAGE_STRING "libmaxminddb 1.4.2"
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#define PACKAGE_TARNAME "libmaxminddb"
|
||||
|
||||
/* Define to the home page for this package. */
|
||||
#define PACKAGE_URL ""
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#define PACKAGE_VERSION "1.4.2"
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
#define STDC_HEADERS 1
|
||||
|
||||
/* Version number of package */
|
||||
#define VERSION "1.4.2"
|
||||
|
||||
#endif /* MAXMINDDB_CONFIG_H */
|
@ -1,74 +0,0 @@
|
||||
/**
|
||||
* pugixml parser - version 1.9
|
||||
* --------------------------------------------------------
|
||||
* Copyright (C) 2006-2019, by Arseny Kapoulkine (arseny.kapoulkine@gmail.com)
|
||||
* Report bugs and download new versions at https://pugixml.org/
|
||||
*
|
||||
* This library is distributed under the MIT License. See notice at the end
|
||||
* of this file.
|
||||
*
|
||||
* This work is based on the pugxml parser, which is:
|
||||
* Copyright (C) 2003, by Kristen Wegner (kristen@tima.net)
|
||||
*/
|
||||
|
||||
#ifndef HEADER_PUGICONFIG_HPP
|
||||
#define HEADER_PUGICONFIG_HPP
|
||||
|
||||
// Uncomment this to enable wchar_t mode
|
||||
// #define PUGIXML_WCHAR_MODE
|
||||
|
||||
// Uncomment this to enable compact mode
|
||||
// #define PUGIXML_COMPACT
|
||||
|
||||
// Uncomment this to disable XPath
|
||||
// #define PUGIXML_NO_XPATH
|
||||
|
||||
// Uncomment this to disable STL
|
||||
#define PUGIXML_NO_STL
|
||||
|
||||
// Uncomment this to disable exceptions
|
||||
#define PUGIXML_NO_EXCEPTIONS
|
||||
|
||||
// Set this to control attributes for public classes/functions, i.e.:
|
||||
// #define PUGIXML_API __declspec(dllexport) // to export all public symbols from DLL
|
||||
// #define PUGIXML_CLASS __declspec(dllimport) // to import all classes from DLL
|
||||
// #define PUGIXML_FUNCTION __fastcall // to set calling conventions to all public functions to fastcall
|
||||
// In absence of PUGIXML_CLASS/PUGIXML_FUNCTION definitions PUGIXML_API is used instead
|
||||
|
||||
// Tune these constants to adjust memory-related behavior
|
||||
// #define PUGIXML_MEMORY_PAGE_SIZE 32768
|
||||
// #define PUGIXML_MEMORY_OUTPUT_STACK 10240
|
||||
// #define PUGIXML_MEMORY_XPATH_PAGE_SIZE 4096
|
||||
|
||||
// Uncomment this to switch to header-only version
|
||||
// #define PUGIXML_HEADER_ONLY
|
||||
|
||||
// Uncomment this to enable long long support
|
||||
#define PUGIXML_HAS_LONG_LONG
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Copyright (c) 2006-2019 Arseny Kapoulkine
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use,
|
||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
@ -1,110 +0,0 @@
|
||||
/* src/config.h. Generated from config.h.in by configure. */
|
||||
/* include/config.h.in. Generated from configure.in by autoheader. */
|
||||
|
||||
/* Define to 1 if you have the `getaddrinfo' function. */
|
||||
/* #undef HAVE_GETADDRINFO */
|
||||
|
||||
/* Define to 1 if you have the `gethostbyname_r' function. */
|
||||
#define HAVE_GETHOSTBYNAME_R 1
|
||||
|
||||
/* Define to 1 if you have the `inet_ntoa' function. */
|
||||
#define HAVE_INET_NTOA 1
|
||||
|
||||
/* Define to 1 if you have the `inet_pton' function. */
|
||||
/* #undef HAVE_INET_PTON */
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#define HAVE_INTTYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the `localtime_r' function. */
|
||||
#define HAVE_LOCALTIME_R 1
|
||||
|
||||
/* Define to 1 if your system has a GNU libc compatible `malloc' function, and
|
||||
to 0 otherwise. */
|
||||
#define HAVE_MALLOC 1
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#define HAVE_MEMORY_H 1
|
||||
|
||||
/* Define to 1 if you have the `socket' function. */
|
||||
#define HAVE_SOCKET 1
|
||||
|
||||
/* Define to 1 if `stat' has the bug that it succeeds when given the
|
||||
zero-length file name argument. */
|
||||
/* #undef HAVE_STAT_EMPTY_STRING_BUG */
|
||||
|
||||
/* Define to 1 if stdbool.h conforms to C99. */
|
||||
#define HAVE_STDBOOL_H 1
|
||||
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
#define HAVE_STDINT_H 1
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#define HAVE_STDLIB_H 1
|
||||
|
||||
/* Define to 1 if you have the <strings.h> header file. */
|
||||
#define HAVE_STRINGS_H 1
|
||||
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#define HAVE_STRING_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/select.h> header file. */
|
||||
#define HAVE_SYS_SELECT_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/socket.h> header file. */
|
||||
#define HAVE_SYS_SOCKET_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#define HAVE_SYS_STAT_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#define HAVE_SYS_TYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#define HAVE_UNISTD_H 1
|
||||
|
||||
/* Define to 1 if the system has the type `_Bool'. */
|
||||
#define HAVE__BOOL 1
|
||||
|
||||
/* Define to 1 if `lstat' dereferences a symlink specified with a trailing
|
||||
slash. */
|
||||
#define LSTAT_FOLLOWS_SLASHED_SYMLINK 1
|
||||
|
||||
/* Define to the address where bug reports for this package should be sent. */
|
||||
#define PACKAGE_BUGREPORT "gyunaev@ulduzsoft.com"
|
||||
|
||||
/* Define to the full name of this package. */
|
||||
#define PACKAGE_NAME "libircclient"
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#define PACKAGE_STRING "libircclient 1.3"
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#define PACKAGE_TARNAME "libircclient"
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#define PACKAGE_VERSION "1.3"
|
||||
|
||||
/* Define to the type of arg 1 for `select'. */
|
||||
#define SELECT_TYPE_ARG1 int
|
||||
|
||||
/* Define to the type of args 2, 3 and 4 for `select'. */
|
||||
#define SELECT_TYPE_ARG234 (fd_set *)
|
||||
|
||||
/* Define to the type of arg 5 for `select'. */
|
||||
#define SELECT_TYPE_ARG5 (struct timeval *)
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
#define STDC_HEADERS 1
|
||||
|
||||
/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
|
||||
#define TIME_WITH_SYS_TIME 1
|
||||
|
||||
/* Define to empty if `const' does not conform to ANSI C. */
|
||||
/* #undef const */
|
||||
|
||||
/* Define to rpl_malloc if the replacement function should be used. */
|
||||
/* #undef malloc */
|
||||
|
||||
/* Define to `unsigned int' if <sys/types.h> does not define. */
|
||||
/* #undef size_t */
|
@ -1,195 +0,0 @@
|
||||
/* include/maxminddb_config.h. Generated from maxminddb_config.h.in by configure. */
|
||||
#ifndef MAXMINDDB_CONFIG_H
|
||||
#define MAXMINDDB_CONFIG_H
|
||||
/* config.h. Generated from config.h.in by configure. */
|
||||
/* config.h.in. Generated from configure.ac by autoheader. */
|
||||
|
||||
/* Define to 1 if you have the <arpa/inet.h> header file. */
|
||||
#define HAVE_ARPA_INET_H 1
|
||||
|
||||
/* Define to 1 if you have the <assert.h> header file. */
|
||||
#define HAVE_ASSERT_H 1
|
||||
|
||||
/* Define to 1 if the system has the type `boolean'. */
|
||||
/* #undef HAVE_BOOLEAN */
|
||||
|
||||
/* Define to 1 if you have the <dlfcn.h> header file. */
|
||||
#define HAVE_DLFCN_H 1
|
||||
|
||||
/* Define to 1 if you have the <fcntl.h> header file. */
|
||||
#define HAVE_FCNTL_H 1
|
||||
|
||||
/* Define to 1 if you have the `getpagesize' function. */
|
||||
#define HAVE_GETPAGESIZE 1
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#define HAVE_INTTYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the <libgen.h> header file. */
|
||||
#define HAVE_LIBGEN_H 1
|
||||
|
||||
/* Define to 1 if your system has a GNU libc compatible `malloc' function, and
|
||||
to 0 otherwise. */
|
||||
#define HAVE_MALLOC 1
|
||||
|
||||
/* Define to 1 if you have the <math.h> header file. */
|
||||
#define HAVE_MATH_H 1
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#define HAVE_MEMORY_H 1
|
||||
|
||||
/* Define to 1 if you have a working `mmap' system call. */
|
||||
#define HAVE_MMAP 1
|
||||
|
||||
/* Define to 1 if you have the <netdb.h> header file. */
|
||||
#define HAVE_NETDB_H 1
|
||||
|
||||
/* Define to 1 if you have the <netinet/in.h> header file. */
|
||||
#define HAVE_NETINET_IN_H 1
|
||||
|
||||
/* Has an open_memstream() function */
|
||||
#define HAVE_OPEN_MEMSTREAM 1
|
||||
|
||||
/* Define to 1 if you have the <stdarg.h> header file. */
|
||||
#define HAVE_STDARG_H 1
|
||||
|
||||
/* Define to 1 if you have the <stdbool.h> header file. */
|
||||
#define HAVE_STDBOOL_H 1
|
||||
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
#define HAVE_STDINT_H 1
|
||||
|
||||
/* Define to 1 if you have the <stdio.h> header file. */
|
||||
#define HAVE_STDIO_H 1
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#define HAVE_STDLIB_H 1
|
||||
|
||||
/* Define to 1 if you have the <strings.h> header file. */
|
||||
#define HAVE_STRINGS_H 1
|
||||
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#define HAVE_STRING_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/mman.h> header file. */
|
||||
#define HAVE_SYS_MMAN_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/param.h> header file. */
|
||||
#define HAVE_SYS_PARAM_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/socket.h> header file. */
|
||||
#define HAVE_SYS_SOCKET_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#define HAVE_SYS_STAT_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/time.h> header file. */
|
||||
#define HAVE_SYS_TIME_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#define HAVE_SYS_TYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#define HAVE_UNISTD_H 1
|
||||
|
||||
/* Define to the sub-directory in which libtool stores uninstalled libraries.
|
||||
*/
|
||||
#define LT_OBJDIR ".libs/"
|
||||
|
||||
/* Missing the unsigned __int128 type */
|
||||
#define MMDB_UINT128_IS_BYTE_ARRAY 1
|
||||
|
||||
/* int128 types are available with __attribute__((mode(TI))) */
|
||||
/* #undef MMDB_UINT128_USING_MODE */
|
||||
|
||||
/* Name of package */
|
||||
#define PACKAGE "libmaxminddb"
|
||||
|
||||
/* Define to the address where bug reports for this package should be sent. */
|
||||
#define PACKAGE_BUGREPORT "support@maxmind.com"
|
||||
|
||||
/* Define to the full name of this package. */
|
||||
#define PACKAGE_NAME "libmaxminddb"
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#define PACKAGE_STRING "libmaxminddb 1.4.2"
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#define PACKAGE_TARNAME "libmaxminddb"
|
||||
|
||||
/* Define to the home page for this package. */
|
||||
#define PACKAGE_URL ""
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#define PACKAGE_VERSION "1.4.2"
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
#define STDC_HEADERS 1
|
||||
|
||||
/* Version number of package */
|
||||
#define VERSION "1.4.2"
|
||||
|
||||
/* Define for Solaris 2.5.1 so the uint32_t typedef from <sys/synch.h>,
|
||||
<pthread.h>, or <semaphore.h> is not used. If the typedef were allowed, the
|
||||
#define below would cause a syntax error. */
|
||||
/* #undef _UINT32_T */
|
||||
|
||||
/* Define for Solaris 2.5.1 so the uint64_t typedef from <sys/synch.h>,
|
||||
<pthread.h>, or <semaphore.h> is not used. If the typedef were allowed, the
|
||||
#define below would cause a syntax error. */
|
||||
/* #undef _UINT64_T */
|
||||
|
||||
/* Define for Solaris 2.5.1 so the uint8_t typedef from <sys/synch.h>,
|
||||
<pthread.h>, or <semaphore.h> is not used. If the typedef were allowed, the
|
||||
#define below would cause a syntax error. */
|
||||
/* #undef _UINT8_T */
|
||||
|
||||
/* Define to rpl_malloc if the replacement function should be used. */
|
||||
/* #undef malloc */
|
||||
|
||||
/* Define to `long int' if <sys/types.h> does not define. */
|
||||
/* #undef off_t */
|
||||
|
||||
/* Define to the equivalent of the C99 'restrict' keyword, or to
|
||||
nothing if this is not supported. Do not define if restrict is
|
||||
supported directly. */
|
||||
#define restrict __restrict
|
||||
/* Work around a bug in Sun C++: it does not support _Restrict or
|
||||
__restrict__, even though the corresponding Sun C compiler ends up with
|
||||
"#define restrict _Restrict" or "#define restrict __restrict__" in the
|
||||
previous line. Perhaps some future version of Sun C++ will work with
|
||||
restrict; if so, hopefully it defines __RESTRICT like Sun C does. */
|
||||
#if defined __SUNPRO_CC && !defined __RESTRICT
|
||||
# define _Restrict
|
||||
# define __restrict__
|
||||
#endif
|
||||
|
||||
/* Define to `unsigned int' if <sys/types.h> does not define. */
|
||||
/* #undef size_t */
|
||||
|
||||
/* Define to `int' if <sys/types.h> does not define. */
|
||||
/* #undef ssize_t */
|
||||
|
||||
/* Define to the type of an unsigned integer type of width exactly 32 bits if
|
||||
such a type exists and the standard includes do not define it. */
|
||||
/* #undef uint32_t */
|
||||
|
||||
/* Define to the type of an unsigned integer type of width exactly 64 bits if
|
||||
such a type exists and the standard includes do not define it. */
|
||||
/* #undef uint64_t */
|
||||
|
||||
/* Define to the type of an unsigned integer type of width exactly 8 bits if
|
||||
such a type exists and the standard includes do not define it. */
|
||||
/* #undef uint8_t */
|
||||
|
||||
#ifndef MMDB_UINT128_USING_MODE
|
||||
/* Define as 1 if we we use unsigned int __atribute__ ((__mode__(TI))) for uint128 values */
|
||||
#define MMDB_UINT128_USING_MODE 0
|
||||
#endif
|
||||
|
||||
#ifndef MMDB_UINT128_IS_BYTE_ARRAY
|
||||
/* Define as 1 if we don't have an unsigned __int128 type */
|
||||
#define MMDB_UINT128_IS_BYTE_ARRAY 0
|
||||
#endif
|
||||
|
||||
#endif /* MAXMINDDB_CONFIG_H */
|
@ -1,110 +0,0 @@
|
||||
/* src/config.h. Generated from config.h.in by configure. */
|
||||
/* include/config.h.in. Generated from configure.in by autoheader. */
|
||||
|
||||
/* Define to 1 if you have the `getaddrinfo' function. */
|
||||
/* #undef HAVE_GETADDRINFO */
|
||||
|
||||
/* Define to 1 if you have the `gethostbyname_r' function. */
|
||||
#define HAVE_GETHOSTBYNAME_R 1
|
||||
|
||||
/* Define to 1 if you have the `inet_ntoa' function. */
|
||||
#define HAVE_INET_NTOA 1
|
||||
|
||||
/* Define to 1 if you have the `inet_pton' function. */
|
||||
/* #undef HAVE_INET_PTON */
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#define HAVE_INTTYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the `localtime_r' function. */
|
||||
#define HAVE_LOCALTIME_R 1
|
||||
|
||||
/* Define to 1 if your system has a GNU libc compatible `malloc' function, and
|
||||
to 0 otherwise. */
|
||||
#define HAVE_MALLOC 1
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#define HAVE_MEMORY_H 1
|
||||
|
||||
/* Define to 1 if you have the `socket' function. */
|
||||
#define HAVE_SOCKET 1
|
||||
|
||||
/* Define to 1 if `stat' has the bug that it succeeds when given the
|
||||
zero-length file name argument. */
|
||||
/* #undef HAVE_STAT_EMPTY_STRING_BUG */
|
||||
|
||||
/* Define to 1 if stdbool.h conforms to C99. */
|
||||
#define HAVE_STDBOOL_H 1
|
||||
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
#define HAVE_STDINT_H 1
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#define HAVE_STDLIB_H 1
|
||||
|
||||
/* Define to 1 if you have the <strings.h> header file. */
|
||||
#define HAVE_STRINGS_H 1
|
||||
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#define HAVE_STRING_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/select.h> header file. */
|
||||
#define HAVE_SYS_SELECT_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/socket.h> header file. */
|
||||
#define HAVE_SYS_SOCKET_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#define HAVE_SYS_STAT_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#define HAVE_SYS_TYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#define HAVE_UNISTD_H 1
|
||||
|
||||
/* Define to 1 if the system has the type `_Bool'. */
|
||||
#define HAVE__BOOL 1
|
||||
|
||||
/* Define to 1 if `lstat' dereferences a symlink specified with a trailing
|
||||
slash. */
|
||||
#define LSTAT_FOLLOWS_SLASHED_SYMLINK 1
|
||||
|
||||
/* Define to the address where bug reports for this package should be sent. */
|
||||
#define PACKAGE_BUGREPORT "gyunaev@ulduzsoft.com"
|
||||
|
||||
/* Define to the full name of this package. */
|
||||
#define PACKAGE_NAME "libircclient"
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#define PACKAGE_STRING "libircclient 1.3"
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#define PACKAGE_TARNAME "libircclient"
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#define PACKAGE_VERSION "1.3"
|
||||
|
||||
/* Define to the type of arg 1 for `select'. */
|
||||
#define SELECT_TYPE_ARG1 int
|
||||
|
||||
/* Define to the type of args 2, 3 and 4 for `select'. */
|
||||
#define SELECT_TYPE_ARG234 (fd_set *)
|
||||
|
||||
/* Define to the type of arg 5 for `select'. */
|
||||
#define SELECT_TYPE_ARG5 (struct timeval *)
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
#define STDC_HEADERS 1
|
||||
|
||||
/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
|
||||
#define TIME_WITH_SYS_TIME 1
|
||||
|
||||
/* Define to empty if `const' does not conform to ANSI C. */
|
||||
/* #undef const */
|
||||
|
||||
/* Define to rpl_malloc if the replacement function should be used. */
|
||||
/* #undef malloc */
|
||||
|
||||
/* Define to `unsigned int' if <sys/types.h> does not define. */
|
||||
/* #undef size_t */
|
@ -1,195 +0,0 @@
|
||||
/* include/maxminddb_config.h. Generated from maxminddb_config.h.in by configure. */
|
||||
#ifndef MAXMINDDB_CONFIG_H
|
||||
#define MAXMINDDB_CONFIG_H
|
||||
/* config.h. Generated from config.h.in by configure. */
|
||||
/* config.h.in. Generated from configure.ac by autoheader. */
|
||||
|
||||
/* Define to 1 if you have the <arpa/inet.h> header file. */
|
||||
#define HAVE_ARPA_INET_H 1
|
||||
|
||||
/* Define to 1 if you have the <assert.h> header file. */
|
||||
#define HAVE_ASSERT_H 1
|
||||
|
||||
/* Define to 1 if the system has the type `boolean'. */
|
||||
/* #undef HAVE_BOOLEAN */
|
||||
|
||||
/* Define to 1 if you have the <dlfcn.h> header file. */
|
||||
#define HAVE_DLFCN_H 1
|
||||
|
||||
/* Define to 1 if you have the <fcntl.h> header file. */
|
||||
#define HAVE_FCNTL_H 1
|
||||
|
||||
/* Define to 1 if you have the `getpagesize' function. */
|
||||
#define HAVE_GETPAGESIZE 1
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#define HAVE_INTTYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the <libgen.h> header file. */
|
||||
#define HAVE_LIBGEN_H 1
|
||||
|
||||
/* Define to 1 if your system has a GNU libc compatible `malloc' function, and
|
||||
to 0 otherwise. */
|
||||
#define HAVE_MALLOC 1
|
||||
|
||||
/* Define to 1 if you have the <math.h> header file. */
|
||||
#define HAVE_MATH_H 1
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#define HAVE_MEMORY_H 1
|
||||
|
||||
/* Define to 1 if you have a working `mmap' system call. */
|
||||
#define HAVE_MMAP 1
|
||||
|
||||
/* Define to 1 if you have the <netdb.h> header file. */
|
||||
#define HAVE_NETDB_H 1
|
||||
|
||||
/* Define to 1 if you have the <netinet/in.h> header file. */
|
||||
#define HAVE_NETINET_IN_H 1
|
||||
|
||||
/* Has an open_memstream() function */
|
||||
#define HAVE_OPEN_MEMSTREAM 1
|
||||
|
||||
/* Define to 1 if you have the <stdarg.h> header file. */
|
||||
#define HAVE_STDARG_H 1
|
||||
|
||||
/* Define to 1 if you have the <stdbool.h> header file. */
|
||||
#define HAVE_STDBOOL_H 1
|
||||
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
#define HAVE_STDINT_H 1
|
||||
|
||||
/* Define to 1 if you have the <stdio.h> header file. */
|
||||
#define HAVE_STDIO_H 1
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#define HAVE_STDLIB_H 1
|
||||
|
||||
/* Define to 1 if you have the <strings.h> header file. */
|
||||
#define HAVE_STRINGS_H 1
|
||||
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#define HAVE_STRING_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/mman.h> header file. */
|
||||
#define HAVE_SYS_MMAN_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/param.h> header file. */
|
||||
#define HAVE_SYS_PARAM_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/socket.h> header file. */
|
||||
#define HAVE_SYS_SOCKET_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#define HAVE_SYS_STAT_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/time.h> header file. */
|
||||
#define HAVE_SYS_TIME_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#define HAVE_SYS_TYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#define HAVE_UNISTD_H 1
|
||||
|
||||
/* Define to the sub-directory in which libtool stores uninstalled libraries.
|
||||
*/
|
||||
#define LT_OBJDIR ".libs/"
|
||||
|
||||
/* Missing the unsigned __int128 type */
|
||||
#define MMDB_UINT128_IS_BYTE_ARRAY 0
|
||||
|
||||
/* int128 types are available with __attribute__((mode(TI))) */
|
||||
/* #undef MMDB_UINT128_USING_MODE */
|
||||
|
||||
/* Name of package */
|
||||
#define PACKAGE "libmaxminddb"
|
||||
|
||||
/* Define to the address where bug reports for this package should be sent. */
|
||||
#define PACKAGE_BUGREPORT "support@maxmind.com"
|
||||
|
||||
/* Define to the full name of this package. */
|
||||
#define PACKAGE_NAME "libmaxminddb"
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#define PACKAGE_STRING "libmaxminddb 1.4.2"
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#define PACKAGE_TARNAME "libmaxminddb"
|
||||
|
||||
/* Define to the home page for this package. */
|
||||
#define PACKAGE_URL ""
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#define PACKAGE_VERSION "1.4.2"
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
#define STDC_HEADERS 1
|
||||
|
||||
/* Version number of package */
|
||||
#define VERSION "1.4.2"
|
||||
|
||||
/* Define for Solaris 2.5.1 so the uint32_t typedef from <sys/synch.h>,
|
||||
<pthread.h>, or <semaphore.h> is not used. If the typedef were allowed, the
|
||||
#define below would cause a syntax error. */
|
||||
/* #undef _UINT32_T */
|
||||
|
||||
/* Define for Solaris 2.5.1 so the uint64_t typedef from <sys/synch.h>,
|
||||
<pthread.h>, or <semaphore.h> is not used. If the typedef were allowed, the
|
||||
#define below would cause a syntax error. */
|
||||
/* #undef _UINT64_T */
|
||||
|
||||
/* Define for Solaris 2.5.1 so the uint8_t typedef from <sys/synch.h>,
|
||||
<pthread.h>, or <semaphore.h> is not used. If the typedef were allowed, the
|
||||
#define below would cause a syntax error. */
|
||||
/* #undef _UINT8_T */
|
||||
|
||||
/* Define to rpl_malloc if the replacement function should be used. */
|
||||
/* #undef malloc */
|
||||
|
||||
/* Define to `long int' if <sys/types.h> does not define. */
|
||||
/* #undef off_t */
|
||||
|
||||
/* Define to the equivalent of the C99 'restrict' keyword, or to
|
||||
nothing if this is not supported. Do not define if restrict is
|
||||
supported directly. */
|
||||
#define restrict __restrict
|
||||
/* Work around a bug in Sun C++: it does not support _Restrict or
|
||||
__restrict__, even though the corresponding Sun C compiler ends up with
|
||||
"#define restrict _Restrict" or "#define restrict __restrict__" in the
|
||||
previous line. Perhaps some future version of Sun C++ will work with
|
||||
restrict; if so, hopefully it defines __RESTRICT like Sun C does. */
|
||||
#if defined __SUNPRO_CC && !defined __RESTRICT
|
||||
# define _Restrict
|
||||
# define __restrict__
|
||||
#endif
|
||||
|
||||
/* Define to `unsigned int' if <sys/types.h> does not define. */
|
||||
/* #undef size_t */
|
||||
|
||||
/* Define to `int' if <sys/types.h> does not define. */
|
||||
/* #undef ssize_t */
|
||||
|
||||
/* Define to the type of an unsigned integer type of width exactly 32 bits if
|
||||
such a type exists and the standard includes do not define it. */
|
||||
/* #undef uint32_t */
|
||||
|
||||
/* Define to the type of an unsigned integer type of width exactly 64 bits if
|
||||
such a type exists and the standard includes do not define it. */
|
||||
/* #undef uint64_t */
|
||||
|
||||
/* Define to the type of an unsigned integer type of width exactly 8 bits if
|
||||
such a type exists and the standard includes do not define it. */
|
||||
/* #undef uint8_t */
|
||||
|
||||
#ifndef MMDB_UINT128_USING_MODE
|
||||
/* Define as 1 if we we use unsigned int __atribute__ ((__mode__(TI))) for uint128 values */
|
||||
#define MMDB_UINT128_USING_MODE 0
|
||||
#endif
|
||||
|
||||
#ifndef MMDB_UINT128_IS_BYTE_ARRAY
|
||||
/* Define as 1 if we don't have an unsigned __int128 type */
|
||||
#define MMDB_UINT128_IS_BYTE_ARRAY 0
|
||||
#endif
|
||||
|
||||
#endif /* MAXMINDDB_CONFIG_H */
|
@ -1,110 +0,0 @@
|
||||
/* src/config.h. Generated from config.h.in by configure. */
|
||||
/* include/config.h.in. Generated from configure.in by autoheader. */
|
||||
|
||||
/* Define to 1 if you have the `getaddrinfo' function. */
|
||||
/* #undef HAVE_GETADDRINFO */
|
||||
|
||||
/* Define to 1 if you have the `gethostbyname_r' function. */
|
||||
/* #undef HAVE_GETHOSTBYNAME_R */
|
||||
|
||||
/* Define to 1 if you have the `inet_ntoa' function. */
|
||||
/* #undef HAVE_INET_NTOA */
|
||||
|
||||
/* Define to 1 if you have the `inet_pton' function. */
|
||||
/* #undef HAVE_INET_PTON */
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#define HAVE_INTTYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the `localtime_r' function. */
|
||||
/* #undef HAVE_LOCALTIME_R */
|
||||
|
||||
/* Define to 1 if your system has a GNU libc compatible `malloc' function, and
|
||||
to 0 otherwise. */
|
||||
#define HAVE_MALLOC 1
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#define HAVE_MEMORY_H 1
|
||||
|
||||
/* Define to 1 if you have the `socket' function. */
|
||||
/* #undef HAVE_SOCKET */
|
||||
|
||||
/* Define to 1 if `stat' has the bug that it succeeds when given the
|
||||
zero-length file name argument. */
|
||||
/* #undef HAVE_STAT_EMPTY_STRING_BUG */
|
||||
|
||||
/* Define to 1 if stdbool.h conforms to C99. */
|
||||
#define HAVE_STDBOOL_H 1
|
||||
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
#define HAVE_STDINT_H 1
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#define HAVE_STDLIB_H 1
|
||||
|
||||
/* Define to 1 if you have the <strings.h> header file. */
|
||||
#define HAVE_STRINGS_H 1
|
||||
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#define HAVE_STRING_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/select.h> header file. */
|
||||
/* #undef HAVE_SYS_SELECT_H */
|
||||
|
||||
/* Define to 1 if you have the <sys/socket.h> header file. */
|
||||
/* #undef HAVE_SYS_SOCKET_H */
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#define HAVE_SYS_STAT_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#define HAVE_SYS_TYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#define HAVE_UNISTD_H 1
|
||||
|
||||
/* Define to 1 if the system has the type `_Bool'. */
|
||||
#define HAVE__BOOL 1
|
||||
|
||||
/* Define to 1 if `lstat' dereferences a symlink specified with a trailing
|
||||
slash. */
|
||||
/* #undef LSTAT_FOLLOWS_SLASHED_SYMLINK */
|
||||
|
||||
/* Define to the address where bug reports for this package should be sent. */
|
||||
#define PACKAGE_BUGREPORT "gyunaev@ulduzsoft.com"
|
||||
|
||||
/* Define to the full name of this package. */
|
||||
#define PACKAGE_NAME "libircclient"
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#define PACKAGE_STRING "libircclient 1.3"
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#define PACKAGE_TARNAME "libircclient"
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#define PACKAGE_VERSION "1.3"
|
||||
|
||||
/* Define to the type of arg 1 for `select'. */
|
||||
#define SELECT_TYPE_ARG1 int
|
||||
|
||||
/* Define to the type of args 2, 3 and 4 for `select'. */
|
||||
#define SELECT_TYPE_ARG234 (int *)
|
||||
|
||||
/* Define to the type of arg 5 for `select'. */
|
||||
#define SELECT_TYPE_ARG5 (struct timeval *)
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
#define STDC_HEADERS 1
|
||||
|
||||
/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
|
||||
#define TIME_WITH_SYS_TIME 1
|
||||
|
||||
/* Define to empty if `const' does not conform to ANSI C. */
|
||||
/* #undef const */
|
||||
|
||||
/* Define to rpl_malloc if the replacement function should be used. */
|
||||
/* #undef malloc */
|
||||
|
||||
/* Define to `unsigned int' if <sys/types.h> does not define. */
|
||||
/* #undef size_t */
|
@ -1,14 +0,0 @@
|
||||
#ifndef _ENDIAN_H_
|
||||
#define _ENDIAN_H_
|
||||
|
||||
#if defined(__MINGW32__) || defined(__MINGW64__)
|
||||
// Workaround for MinGW and it's lack of <endian.h> file
|
||||
#define __BYTE_ORDER __BYTE_ORDER__
|
||||
#define __LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__
|
||||
#define __BIG_ENDIAN __ORDER_BIG_ENDIAN__
|
||||
#elif !defined(_MSC_VER)
|
||||
// Just include the system file
|
||||
#include <endian.h>
|
||||
#endif
|
||||
|
||||
#endif // _ENDIAN_H_
|
@ -1,110 +0,0 @@
|
||||
/* src/config.h. Generated from config.h.in by configure. */
|
||||
/* include/config.h.in. Generated from configure.in by autoheader. */
|
||||
|
||||
/* Define to 1 if you have the `getaddrinfo' function. */
|
||||
/* #undef HAVE_GETADDRINFO */
|
||||
|
||||
/* Define to 1 if you have the `gethostbyname_r' function. */
|
||||
/* #undef HAVE_GETHOSTBYNAME_R */
|
||||
|
||||
/* Define to 1 if you have the `inet_ntoa' function. */
|
||||
/* #undef HAVE_INET_NTOA */
|
||||
|
||||
/* Define to 1 if you have the `inet_pton' function. */
|
||||
/* #undef HAVE_INET_PTON */
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#define HAVE_INTTYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the `localtime_r' function. */
|
||||
/* #undef HAVE_LOCALTIME_R */
|
||||
|
||||
/* Define to 1 if your system has a GNU libc compatible `malloc' function, and
|
||||
to 0 otherwise. */
|
||||
#define HAVE_MALLOC 1
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#define HAVE_MEMORY_H 1
|
||||
|
||||
/* Define to 1 if you have the `socket' function. */
|
||||
/* #undef HAVE_SOCKET */
|
||||
|
||||
/* Define to 1 if `stat' has the bug that it succeeds when given the
|
||||
zero-length file name argument. */
|
||||
/* #undef HAVE_STAT_EMPTY_STRING_BUG */
|
||||
|
||||
/* Define to 1 if stdbool.h conforms to C99. */
|
||||
#define HAVE_STDBOOL_H 1
|
||||
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
#define HAVE_STDINT_H 1
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#define HAVE_STDLIB_H 1
|
||||
|
||||
/* Define to 1 if you have the <strings.h> header file. */
|
||||
#define HAVE_STRINGS_H 1
|
||||
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#define HAVE_STRING_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/select.h> header file. */
|
||||
/* #undef HAVE_SYS_SELECT_H */
|
||||
|
||||
/* Define to 1 if you have the <sys/socket.h> header file. */
|
||||
/* #undef HAVE_SYS_SOCKET_H */
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#define HAVE_SYS_STAT_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#define HAVE_SYS_TYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#define HAVE_UNISTD_H 1
|
||||
|
||||
/* Define to 1 if the system has the type `_Bool'. */
|
||||
#define HAVE__BOOL 1
|
||||
|
||||
/* Define to 1 if `lstat' dereferences a symlink specified with a trailing
|
||||
slash. */
|
||||
/* #undef LSTAT_FOLLOWS_SLASHED_SYMLINK */
|
||||
|
||||
/* Define to the address where bug reports for this package should be sent. */
|
||||
#define PACKAGE_BUGREPORT "gyunaev@ulduzsoft.com"
|
||||
|
||||
/* Define to the full name of this package. */
|
||||
#define PACKAGE_NAME "libircclient"
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#define PACKAGE_STRING "libircclient 1.3"
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#define PACKAGE_TARNAME "libircclient"
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#define PACKAGE_VERSION "1.3"
|
||||
|
||||
/* Define to the type of arg 1 for `select'. */
|
||||
#define SELECT_TYPE_ARG1 int
|
||||
|
||||
/* Define to the type of args 2, 3 and 4 for `select'. */
|
||||
#define SELECT_TYPE_ARG234 (int *)
|
||||
|
||||
/* Define to the type of arg 5 for `select'. */
|
||||
#define SELECT_TYPE_ARG5 (struct timeval *)
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
#define STDC_HEADERS 1
|
||||
|
||||
/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
|
||||
#define TIME_WITH_SYS_TIME 1
|
||||
|
||||
/* Define to empty if `const' does not conform to ANSI C. */
|
||||
/* #undef const */
|
||||
|
||||
/* Define to rpl_malloc if the replacement function should be used. */
|
||||
/* #undef malloc */
|
||||
|
||||
/* Define to `unsigned int' if <sys/types.h> does not define. */
|
||||
/* #undef size_t */
|
0
external/Common/CMakeLists.txt
vendored
0
external/Common/CMakeLists.txt
vendored
0
external/Jansson/CMakeLists.txt
vendored
0
external/Jansson/CMakeLists.txt
vendored
467
external/Jansson/dump.c
vendored
467
external/Jansson/dump.c
vendored
@ -1,467 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2014 Petri Lehtinen <petri@digip.org>
|
||||
*
|
||||
* Jansson is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the MIT license. See LICENSE for details.
|
||||
*/
|
||||
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "jansson.h"
|
||||
#include "jansson_private.h"
|
||||
#include "strbuffer.h"
|
||||
#include "utf.h"
|
||||
|
||||
#define MAX_INTEGER_STR_LENGTH 100
|
||||
#define MAX_REAL_STR_LENGTH 100
|
||||
|
||||
#define FLAGS_TO_INDENT(f) ((f) & 0x1F)
|
||||
#define FLAGS_TO_PRECISION(f) (((f) >> 11) & 0x1F)
|
||||
|
||||
struct object_key {
|
||||
size_t serial;
|
||||
const char *key;
|
||||
};
|
||||
|
||||
static int dump_to_strbuffer(const char *buffer, size_t size, void *data)
|
||||
{
|
||||
return strbuffer_append_bytes((strbuffer_t *)data, buffer, size);
|
||||
}
|
||||
|
||||
static int dump_to_file(const char *buffer, size_t size, void *data)
|
||||
{
|
||||
FILE *dest = (FILE *)data;
|
||||
if(fwrite(buffer, size, 1, dest) != 1)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* 32 spaces (the maximum indentation size) */
|
||||
static const char whitespace[] = " ";
|
||||
|
||||
static int dump_indent(size_t flags, int depth, int space, json_dump_callback_t dump, void *data)
|
||||
{
|
||||
if(FLAGS_TO_INDENT(flags) > 0)
|
||||
{
|
||||
unsigned int ws_count = FLAGS_TO_INDENT(flags), n_spaces = depth * ws_count;
|
||||
|
||||
if(dump("\n", 1, data))
|
||||
return -1;
|
||||
|
||||
while(n_spaces > 0)
|
||||
{
|
||||
int cur_n = n_spaces < sizeof whitespace - 1 ? n_spaces : sizeof whitespace - 1;
|
||||
|
||||
if(dump(whitespace, cur_n, data))
|
||||
return -1;
|
||||
|
||||
n_spaces -= cur_n;
|
||||
}
|
||||
}
|
||||
else if(space && !(flags & JSON_COMPACT))
|
||||
{
|
||||
return dump(" ", 1, data);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int dump_string(const char *str, size_t len, json_dump_callback_t dump, void *data, size_t flags)
|
||||
{
|
||||
const char *pos, *end, *lim;
|
||||
int32_t codepoint;
|
||||
|
||||
if(dump("\"", 1, data))
|
||||
return -1;
|
||||
|
||||
end = pos = str;
|
||||
lim = str + len;
|
||||
while(1)
|
||||
{
|
||||
const char *text;
|
||||
char seq[13];
|
||||
int length;
|
||||
|
||||
while(end < lim)
|
||||
{
|
||||
end = utf8_iterate(pos, lim - pos, &codepoint);
|
||||
if(!end)
|
||||
return -1;
|
||||
|
||||
/* mandatory escape or control char */
|
||||
if(codepoint == '\\' || codepoint == '"' || codepoint < 0x20)
|
||||
break;
|
||||
|
||||
/* slash */
|
||||
if((flags & JSON_ESCAPE_SLASH) && codepoint == '/')
|
||||
break;
|
||||
|
||||
/* non-ASCII */
|
||||
if((flags & JSON_ENSURE_ASCII) && codepoint > 0x7F)
|
||||
break;
|
||||
|
||||
pos = end;
|
||||
}
|
||||
|
||||
if(pos != str) {
|
||||
if(dump(str, pos - str, data))
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(end == pos)
|
||||
break;
|
||||
|
||||
/* handle \, /, ", and control codes */
|
||||
length = 2;
|
||||
switch(codepoint)
|
||||
{
|
||||
case '\\': text = "\\\\"; break;
|
||||
case '\"': text = "\\\""; break;
|
||||
case '\b': text = "\\b"; break;
|
||||
case '\f': text = "\\f"; break;
|
||||
case '\n': text = "\\n"; break;
|
||||
case '\r': text = "\\r"; break;
|
||||
case '\t': text = "\\t"; break;
|
||||
case '/': text = "\\/"; break;
|
||||
default:
|
||||
{
|
||||
/* codepoint is in BMP */
|
||||
if(codepoint < 0x10000)
|
||||
{
|
||||
snprintf(seq, sizeof(seq), "\\u%04X", (unsigned int)codepoint);
|
||||
length = 6;
|
||||
}
|
||||
|
||||
/* not in BMP -> construct a UTF-16 surrogate pair */
|
||||
else
|
||||
{
|
||||
int32_t first, last;
|
||||
|
||||
codepoint -= 0x10000;
|
||||
first = 0xD800 | ((codepoint & 0xffc00) >> 10);
|
||||
last = 0xDC00 | (codepoint & 0x003ff);
|
||||
|
||||
snprintf(seq, sizeof(seq), "\\u%04X\\u%04X", (unsigned int)first, (unsigned int)last);
|
||||
length = 12;
|
||||
}
|
||||
|
||||
text = seq;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(dump(text, length, data))
|
||||
return -1;
|
||||
|
||||
str = pos = end;
|
||||
}
|
||||
|
||||
return dump("\"", 1, data);
|
||||
}
|
||||
|
||||
static int object_key_compare_keys(const void *key1, const void *key2)
|
||||
{
|
||||
return strcmp(((const struct object_key *)key1)->key,
|
||||
((const struct object_key *)key2)->key);
|
||||
}
|
||||
|
||||
static int object_key_compare_serials(const void *key1, const void *key2)
|
||||
{
|
||||
size_t a = ((const struct object_key *)key1)->serial;
|
||||
size_t b = ((const struct object_key *)key2)->serial;
|
||||
|
||||
return a < b ? -1 : a == b ? 0 : 1;
|
||||
}
|
||||
|
||||
static int do_dump(const json_t *json, size_t flags, int depth,
|
||||
json_dump_callback_t dump, void *data)
|
||||
{
|
||||
if(!json)
|
||||
return -1;
|
||||
|
||||
switch(json_typeof(json)) {
|
||||
case JSON_NULL:
|
||||
return dump("null", 4, data);
|
||||
|
||||
case JSON_TRUE:
|
||||
return dump("true", 4, data);
|
||||
|
||||
case JSON_FALSE:
|
||||
return dump("false", 5, data);
|
||||
|
||||
case JSON_INTEGER:
|
||||
{
|
||||
char buffer[MAX_INTEGER_STR_LENGTH];
|
||||
int size;
|
||||
|
||||
size = snprintf(buffer, MAX_INTEGER_STR_LENGTH,
|
||||
"%" JSON_INTEGER_FORMAT,
|
||||
json_integer_value(json));
|
||||
if(size < 0 || size >= MAX_INTEGER_STR_LENGTH)
|
||||
return -1;
|
||||
|
||||
return dump(buffer, size, data);
|
||||
}
|
||||
|
||||
case JSON_REAL:
|
||||
{
|
||||
char buffer[MAX_REAL_STR_LENGTH];
|
||||
int size;
|
||||
double value = json_real_value(json);
|
||||
|
||||
size = jsonp_dtostr(buffer, MAX_REAL_STR_LENGTH, value,
|
||||
FLAGS_TO_PRECISION(flags));
|
||||
if(size < 0)
|
||||
return -1;
|
||||
|
||||
return dump(buffer, size, data);
|
||||
}
|
||||
|
||||
case JSON_STRING:
|
||||
return dump_string(json_string_value(json), json_string_length(json), dump, data, flags);
|
||||
|
||||
case JSON_ARRAY:
|
||||
{
|
||||
size_t n;
|
||||
size_t i;
|
||||
|
||||
json_array_t *array;
|
||||
|
||||
/* detect circular references */
|
||||
array = json_to_array(json);
|
||||
if(array->visited)
|
||||
goto array_error;
|
||||
array->visited = 1;
|
||||
|
||||
n = json_array_size(json);
|
||||
|
||||
if(dump("[", 1, data))
|
||||
goto array_error;
|
||||
if(n == 0) {
|
||||
array->visited = 0;
|
||||
return dump("]", 1, data);
|
||||
}
|
||||
if(dump_indent(flags, depth + 1, 0, dump, data))
|
||||
goto array_error;
|
||||
|
||||
for(i = 0; i < n; ++i) {
|
||||
if(do_dump(json_array_get(json, i), flags, depth + 1,
|
||||
dump, data))
|
||||
goto array_error;
|
||||
|
||||
if(i < n - 1)
|
||||
{
|
||||
if(dump(",", 1, data) ||
|
||||
dump_indent(flags, depth + 1, 1, dump, data))
|
||||
goto array_error;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(dump_indent(flags, depth, 0, dump, data))
|
||||
goto array_error;
|
||||
}
|
||||
}
|
||||
|
||||
array->visited = 0;
|
||||
return dump("]", 1, data);
|
||||
|
||||
array_error:
|
||||
array->visited = 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
case JSON_OBJECT:
|
||||
{
|
||||
json_object_t *object;
|
||||
void *iter;
|
||||
const char *separator;
|
||||
int separator_length;
|
||||
|
||||
if(flags & JSON_COMPACT) {
|
||||
separator = ":";
|
||||
separator_length = 1;
|
||||
}
|
||||
else {
|
||||
separator = ": ";
|
||||
separator_length = 2;
|
||||
}
|
||||
|
||||
/* detect circular references */
|
||||
object = json_to_object(json);
|
||||
if(object->visited)
|
||||
goto object_error;
|
||||
object->visited = 1;
|
||||
|
||||
iter = json_object_iter((json_t *)json);
|
||||
|
||||
if(dump("{", 1, data))
|
||||
goto object_error;
|
||||
if(!iter) {
|
||||
object->visited = 0;
|
||||
return dump("}", 1, data);
|
||||
}
|
||||
if(dump_indent(flags, depth + 1, 0, dump, data))
|
||||
goto object_error;
|
||||
|
||||
if(flags & JSON_SORT_KEYS || flags & JSON_PRESERVE_ORDER)
|
||||
{
|
||||
struct object_key *keys;
|
||||
size_t size, i;
|
||||
int (*cmp_func)(const void *, const void *);
|
||||
|
||||
size = json_object_size(json);
|
||||
keys = jsonp_malloc(size * sizeof(struct object_key));
|
||||
if(!keys)
|
||||
goto object_error;
|
||||
|
||||
i = 0;
|
||||
while(iter)
|
||||
{
|
||||
keys[i].serial = hashtable_iter_serial(iter);
|
||||
keys[i].key = json_object_iter_key(iter);
|
||||
iter = json_object_iter_next((json_t *)json, iter);
|
||||
i++;
|
||||
}
|
||||
assert(i == size);
|
||||
|
||||
if(flags & JSON_SORT_KEYS)
|
||||
cmp_func = object_key_compare_keys;
|
||||
else
|
||||
cmp_func = object_key_compare_serials;
|
||||
|
||||
qsort(keys, size, sizeof(struct object_key), cmp_func);
|
||||
|
||||
for(i = 0; i < size; i++)
|
||||
{
|
||||
const char *key;
|
||||
json_t *value;
|
||||
|
||||
key = keys[i].key;
|
||||
value = json_object_get(json, key);
|
||||
assert(value);
|
||||
|
||||
dump_string(key, strlen(key), dump, data, flags);
|
||||
if(dump(separator, separator_length, data) ||
|
||||
do_dump(value, flags, depth + 1, dump, data))
|
||||
{
|
||||
jsonp_free(keys);
|
||||
goto object_error;
|
||||
}
|
||||
|
||||
if(i < size - 1)
|
||||
{
|
||||
if(dump(",", 1, data) ||
|
||||
dump_indent(flags, depth + 1, 1, dump, data))
|
||||
{
|
||||
jsonp_free(keys);
|
||||
goto object_error;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(dump_indent(flags, depth, 0, dump, data))
|
||||
{
|
||||
jsonp_free(keys);
|
||||
goto object_error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
jsonp_free(keys);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Don't sort keys */
|
||||
|
||||
while(iter)
|
||||
{
|
||||
void *next = json_object_iter_next((json_t *)json, iter);
|
||||
const char *key = json_object_iter_key(iter);
|
||||
|
||||
dump_string(key, strlen(key), dump, data, flags);
|
||||
if(dump(separator, separator_length, data) ||
|
||||
do_dump(json_object_iter_value(iter), flags, depth + 1,
|
||||
dump, data))
|
||||
goto object_error;
|
||||
|
||||
if(next)
|
||||
{
|
||||
if(dump(",", 1, data) ||
|
||||
dump_indent(flags, depth + 1, 1, dump, data))
|
||||
goto object_error;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(dump_indent(flags, depth, 0, dump, data))
|
||||
goto object_error;
|
||||
}
|
||||
|
||||
iter = next;
|
||||
}
|
||||
}
|
||||
|
||||
object->visited = 0;
|
||||
return dump("}", 1, data);
|
||||
|
||||
object_error:
|
||||
object->visited = 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
default:
|
||||
/* not reached */
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
char *json_dumps(const json_t *json, size_t flags)
|
||||
{
|
||||
strbuffer_t strbuff;
|
||||
char *result;
|
||||
|
||||
if(strbuffer_init(&strbuff))
|
||||
return NULL;
|
||||
|
||||
if(json_dump_callback(json, dump_to_strbuffer, (void *)&strbuff, flags))
|
||||
result = NULL;
|
||||
else
|
||||
result = jsonp_strdup(strbuffer_value(&strbuff));
|
||||
|
||||
strbuffer_close(&strbuff);
|
||||
return result;
|
||||
}
|
||||
|
||||
int json_dumpf(const json_t *json, FILE *output, size_t flags)
|
||||
{
|
||||
return json_dump_callback(json, dump_to_file, (void *)output, flags);
|
||||
}
|
||||
|
||||
int json_dump_file(const json_t *json, const char *path, size_t flags)
|
||||
{
|
||||
int result;
|
||||
|
||||
FILE *output = fopen(path, "w");
|
||||
if(!output)
|
||||
return -1;
|
||||
|
||||
result = json_dumpf(json, output, flags);
|
||||
|
||||
fclose(output);
|
||||
return result;
|
||||
}
|
||||
|
||||
int json_dump_callback(const json_t *json, json_dump_callback_t callback, void *data, size_t flags)
|
||||
{
|
||||
if(!(flags & JSON_ENCODE_ANY)) {
|
||||
if(!json_is_array(json) && !json_is_object(json))
|
||||
return -1;
|
||||
}
|
||||
|
||||
return do_dump(json, flags, 0, callback, data);
|
||||
}
|
63
external/Jansson/error.c
vendored
63
external/Jansson/error.c
vendored
@ -1,63 +0,0 @@
|
||||
#include <string.h>
|
||||
#include "jansson_private.h"
|
||||
|
||||
void jsonp_error_init(json_error_t *error, const char *source)
|
||||
{
|
||||
if(error)
|
||||
{
|
||||
error->text[0] = '\0';
|
||||
error->line = -1;
|
||||
error->column = -1;
|
||||
error->position = 0;
|
||||
if(source)
|
||||
jsonp_error_set_source(error, source);
|
||||
else
|
||||
error->source[0] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
void jsonp_error_set_source(json_error_t *error, const char *source)
|
||||
{
|
||||
size_t length;
|
||||
|
||||
if(!error || !source)
|
||||
return;
|
||||
|
||||
length = strlen(source);
|
||||
if(length < JSON_ERROR_SOURCE_LENGTH)
|
||||
strncpy(error->source, source, length + 1);
|
||||
else {
|
||||
size_t extra = length - JSON_ERROR_SOURCE_LENGTH + 4;
|
||||
strncpy(error->source, "...", 3);
|
||||
strncpy(error->source + 3, source + extra, length - extra + 1);
|
||||
}
|
||||
}
|
||||
|
||||
void jsonp_error_set(json_error_t *error, int line, int column,
|
||||
size_t position, const char *msg, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, msg);
|
||||
jsonp_error_vset(error, line, column, position, msg, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void jsonp_error_vset(json_error_t *error, int line, int column,
|
||||
size_t position, const char *msg, va_list ap)
|
||||
{
|
||||
if(!error)
|
||||
return;
|
||||
|
||||
if(error->text[0] != '\0') {
|
||||
/* error already set */
|
||||
return;
|
||||
}
|
||||
|
||||
error->line = line;
|
||||
error->column = column;
|
||||
error->position = (int)position;
|
||||
|
||||
vsnprintf(error->text, JSON_ERROR_TEXT_LENGTH, msg, ap);
|
||||
error->text[JSON_ERROR_TEXT_LENGTH - 1] = '\0';
|
||||
}
|
356
external/Jansson/hashtable.c
vendored
356
external/Jansson/hashtable.c
vendored
@ -1,356 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2014 Petri Lehtinen <petri@digip.org>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the MIT license. See LICENSE for details.
|
||||
*/
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
#include <jansson_private_config.h>
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#if HAVE_STDINT_H
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
#include <jansson_config.h> /* for JSON_INLINE */
|
||||
#include "jansson_private.h" /* for container_of() */
|
||||
#include "hashtable.h"
|
||||
|
||||
#ifndef INITIAL_HASHTABLE_ORDER
|
||||
#define INITIAL_HASHTABLE_ORDER 3
|
||||
#endif
|
||||
|
||||
typedef struct hashtable_list list_t;
|
||||
typedef struct hashtable_pair pair_t;
|
||||
typedef struct hashtable_bucket bucket_t;
|
||||
|
||||
extern volatile uint32_t hashtable_seed;
|
||||
|
||||
/* Implementation of the hash function */
|
||||
#include "lookup3.h"
|
||||
|
||||
#define list_to_pair(list_) container_of(list_, pair_t, list)
|
||||
#define hash_str(key) ((size_t)hashlittle((key), strlen(key), hashtable_seed))
|
||||
|
||||
static JSON_INLINE void list_init(list_t *list)
|
||||
{
|
||||
list->next = list;
|
||||
list->prev = list;
|
||||
}
|
||||
|
||||
static JSON_INLINE void list_insert(list_t *list, list_t *node)
|
||||
{
|
||||
node->next = list;
|
||||
node->prev = list->prev;
|
||||
list->prev->next = node;
|
||||
list->prev = node;
|
||||
}
|
||||
|
||||
static JSON_INLINE void list_remove(list_t *list)
|
||||
{
|
||||
list->prev->next = list->next;
|
||||
list->next->prev = list->prev;
|
||||
}
|
||||
|
||||
static JSON_INLINE int bucket_is_empty(hashtable_t *hashtable, bucket_t *bucket)
|
||||
{
|
||||
return bucket->first == &hashtable->list && bucket->first == bucket->last;
|
||||
}
|
||||
|
||||
static void insert_to_bucket(hashtable_t *hashtable, bucket_t *bucket,
|
||||
list_t *list)
|
||||
{
|
||||
if(bucket_is_empty(hashtable, bucket))
|
||||
{
|
||||
list_insert(&hashtable->list, list);
|
||||
bucket->first = bucket->last = list;
|
||||
}
|
||||
else
|
||||
{
|
||||
list_insert(bucket->first, list);
|
||||
bucket->first = list;
|
||||
}
|
||||
}
|
||||
|
||||
static pair_t *hashtable_find_pair(hashtable_t *hashtable, bucket_t *bucket,
|
||||
const char *key, size_t hash)
|
||||
{
|
||||
list_t *list;
|
||||
pair_t *pair;
|
||||
|
||||
if(bucket_is_empty(hashtable, bucket))
|
||||
return NULL;
|
||||
|
||||
list = bucket->first;
|
||||
while(1)
|
||||
{
|
||||
pair = list_to_pair(list);
|
||||
if(pair->hash == hash && strcmp(pair->key, key) == 0)
|
||||
return pair;
|
||||
|
||||
if(list == bucket->last)
|
||||
break;
|
||||
|
||||
list = list->next;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* returns 0 on success, -1 if key was not found */
|
||||
static int hashtable_do_del(hashtable_t *hashtable,
|
||||
const char *key, size_t hash)
|
||||
{
|
||||
pair_t *pair;
|
||||
bucket_t *bucket;
|
||||
size_t index;
|
||||
|
||||
index = hash & hashmask(hashtable->order);
|
||||
bucket = &hashtable->buckets[index];
|
||||
|
||||
pair = hashtable_find_pair(hashtable, bucket, key, hash);
|
||||
if(!pair)
|
||||
return -1;
|
||||
|
||||
if(&pair->list == bucket->first && &pair->list == bucket->last)
|
||||
bucket->first = bucket->last = &hashtable->list;
|
||||
|
||||
else if(&pair->list == bucket->first)
|
||||
bucket->first = pair->list.next;
|
||||
|
||||
else if(&pair->list == bucket->last)
|
||||
bucket->last = pair->list.prev;
|
||||
|
||||
list_remove(&pair->list);
|
||||
json_decref(pair->value);
|
||||
|
||||
jsonp_free(pair);
|
||||
hashtable->size--;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void hashtable_do_clear(hashtable_t *hashtable)
|
||||
{
|
||||
list_t *list, *next;
|
||||
pair_t *pair;
|
||||
|
||||
for(list = hashtable->list.next; list != &hashtable->list; list = next)
|
||||
{
|
||||
next = list->next;
|
||||
pair = list_to_pair(list);
|
||||
json_decref(pair->value);
|
||||
jsonp_free(pair);
|
||||
}
|
||||
}
|
||||
|
||||
static int hashtable_do_rehash(hashtable_t *hashtable)
|
||||
{
|
||||
list_t *list, *next;
|
||||
pair_t *pair;
|
||||
size_t i, index, new_size;
|
||||
|
||||
jsonp_free(hashtable->buckets);
|
||||
|
||||
hashtable->order++;
|
||||
new_size = hashsize(hashtable->order);
|
||||
|
||||
hashtable->buckets = jsonp_malloc(new_size * sizeof(bucket_t));
|
||||
if(!hashtable->buckets)
|
||||
return -1;
|
||||
|
||||
for(i = 0; i < hashsize(hashtable->order); i++)
|
||||
{
|
||||
hashtable->buckets[i].first = hashtable->buckets[i].last =
|
||||
&hashtable->list;
|
||||
}
|
||||
|
||||
list = hashtable->list.next;
|
||||
list_init(&hashtable->list);
|
||||
|
||||
for(; list != &hashtable->list; list = next) {
|
||||
next = list->next;
|
||||
pair = list_to_pair(list);
|
||||
index = pair->hash % new_size;
|
||||
insert_to_bucket(hashtable, &hashtable->buckets[index], &pair->list);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int hashtable_init(hashtable_t *hashtable)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
hashtable->size = 0;
|
||||
hashtable->order = INITIAL_HASHTABLE_ORDER;
|
||||
hashtable->buckets = jsonp_malloc(hashsize(hashtable->order) * sizeof(bucket_t));
|
||||
if(!hashtable->buckets)
|
||||
return -1;
|
||||
|
||||
list_init(&hashtable->list);
|
||||
|
||||
for(i = 0; i < hashsize(hashtable->order); i++)
|
||||
{
|
||||
hashtable->buckets[i].first = hashtable->buckets[i].last =
|
||||
&hashtable->list;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void hashtable_close(hashtable_t *hashtable)
|
||||
{
|
||||
hashtable_do_clear(hashtable);
|
||||
jsonp_free(hashtable->buckets);
|
||||
}
|
||||
|
||||
int hashtable_set(hashtable_t *hashtable,
|
||||
const char *key, size_t serial,
|
||||
json_t *value)
|
||||
{
|
||||
pair_t *pair;
|
||||
bucket_t *bucket;
|
||||
size_t hash, index;
|
||||
|
||||
/* rehash if the load ratio exceeds 1 */
|
||||
if(hashtable->size >= hashsize(hashtable->order))
|
||||
if(hashtable_do_rehash(hashtable))
|
||||
return -1;
|
||||
|
||||
hash = hash_str(key);
|
||||
index = hash & hashmask(hashtable->order);
|
||||
bucket = &hashtable->buckets[index];
|
||||
pair = hashtable_find_pair(hashtable, bucket, key, hash);
|
||||
|
||||
if(pair)
|
||||
{
|
||||
json_decref(pair->value);
|
||||
pair->value = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* offsetof(...) returns the size of pair_t without the last,
|
||||
flexible member. This way, the correct amount is
|
||||
allocated. */
|
||||
|
||||
size_t len = strlen(key);
|
||||
if(len >= (size_t)-1 - offsetof(pair_t, key)) {
|
||||
/* Avoid an overflow if the key is very long */
|
||||
return -1;
|
||||
}
|
||||
|
||||
pair = jsonp_malloc(offsetof(pair_t, key) + len + 1);
|
||||
if(!pair)
|
||||
return -1;
|
||||
|
||||
pair->hash = hash;
|
||||
pair->serial = serial;
|
||||
strncpy(pair->key, key, len + 1);
|
||||
pair->value = value;
|
||||
list_init(&pair->list);
|
||||
|
||||
insert_to_bucket(hashtable, bucket, &pair->list);
|
||||
|
||||
hashtable->size++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *hashtable_get(hashtable_t *hashtable, const char *key)
|
||||
{
|
||||
pair_t *pair;
|
||||
size_t hash;
|
||||
bucket_t *bucket;
|
||||
|
||||
hash = hash_str(key);
|
||||
bucket = &hashtable->buckets[hash & hashmask(hashtable->order)];
|
||||
|
||||
pair = hashtable_find_pair(hashtable, bucket, key, hash);
|
||||
if(!pair)
|
||||
return NULL;
|
||||
|
||||
return pair->value;
|
||||
}
|
||||
|
||||
int hashtable_del(hashtable_t *hashtable, const char *key)
|
||||
{
|
||||
size_t hash = hash_str(key);
|
||||
return hashtable_do_del(hashtable, key, hash);
|
||||
}
|
||||
|
||||
void hashtable_clear(hashtable_t *hashtable)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
hashtable_do_clear(hashtable);
|
||||
|
||||
for(i = 0; i < hashsize(hashtable->order); i++)
|
||||
{
|
||||
hashtable->buckets[i].first = hashtable->buckets[i].last =
|
||||
&hashtable->list;
|
||||
}
|
||||
|
||||
list_init(&hashtable->list);
|
||||
hashtable->size = 0;
|
||||
}
|
||||
|
||||
void *hashtable_iter(hashtable_t *hashtable)
|
||||
{
|
||||
return hashtable_iter_next(hashtable, &hashtable->list);
|
||||
}
|
||||
|
||||
void *hashtable_iter_at(hashtable_t *hashtable, const char *key)
|
||||
{
|
||||
pair_t *pair;
|
||||
size_t hash;
|
||||
bucket_t *bucket;
|
||||
|
||||
hash = hash_str(key);
|
||||
bucket = &hashtable->buckets[hash & hashmask(hashtable->order)];
|
||||
|
||||
pair = hashtable_find_pair(hashtable, bucket, key, hash);
|
||||
if(!pair)
|
||||
return NULL;
|
||||
|
||||
return &pair->list;
|
||||
}
|
||||
|
||||
void *hashtable_iter_next(hashtable_t *hashtable, void *iter)
|
||||
{
|
||||
list_t *list = (list_t *)iter;
|
||||
if(list->next == &hashtable->list)
|
||||
return NULL;
|
||||
return list->next;
|
||||
}
|
||||
|
||||
void *hashtable_iter_key(void *iter)
|
||||
{
|
||||
pair_t *pair = list_to_pair((list_t *)iter);
|
||||
return pair->key;
|
||||
}
|
||||
|
||||
size_t hashtable_iter_serial(void *iter)
|
||||
{
|
||||
pair_t *pair = list_to_pair((list_t *)iter);
|
||||
return pair->serial;
|
||||
}
|
||||
|
||||
void *hashtable_iter_value(void *iter)
|
||||
{
|
||||
pair_t *pair = list_to_pair((list_t *)iter);
|
||||
return pair->value;
|
||||
}
|
||||
|
||||
void hashtable_iter_set(void *iter, json_t *value)
|
||||
{
|
||||
pair_t *pair = list_to_pair((list_t *)iter);
|
||||
|
||||
json_decref(pair->value);
|
||||
pair->value = value;
|
||||
}
|
184
external/Jansson/hashtable.h
vendored
184
external/Jansson/hashtable.h
vendored
@ -1,184 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2014 Petri Lehtinen <petri@digip.org>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the MIT license. See LICENSE for details.
|
||||
*/
|
||||
|
||||
#ifndef HASHTABLE_H
|
||||
#define HASHTABLE_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "jansson.h"
|
||||
|
||||
struct hashtable_list {
|
||||
struct hashtable_list *prev;
|
||||
struct hashtable_list *next;
|
||||
};
|
||||
|
||||
/* "pair" may be a bit confusing a name, but think of it as a
|
||||
key-value pair. In this case, it just encodes some extra data,
|
||||
too */
|
||||
struct hashtable_pair {
|
||||
struct hashtable_list list;
|
||||
size_t hash;
|
||||
json_t *value;
|
||||
size_t serial;
|
||||
char key[1];
|
||||
};
|
||||
|
||||
struct hashtable_bucket {
|
||||
struct hashtable_list *first;
|
||||
struct hashtable_list *last;
|
||||
};
|
||||
|
||||
typedef struct hashtable {
|
||||
size_t size;
|
||||
struct hashtable_bucket *buckets;
|
||||
size_t order; /* hashtable has pow(2, order) buckets */
|
||||
struct hashtable_list list;
|
||||
} hashtable_t;
|
||||
|
||||
|
||||
#define hashtable_key_to_iter(key_) \
|
||||
(&(container_of(key_, struct hashtable_pair, key)->list))
|
||||
|
||||
|
||||
/**
|
||||
* hashtable_init - Initialize a hashtable object
|
||||
*
|
||||
* @hashtable: The (statically allocated) hashtable object
|
||||
*
|
||||
* Initializes a statically allocated hashtable object. The object
|
||||
* should be cleared with hashtable_close when it's no longer used.
|
||||
*
|
||||
* Returns 0 on success, -1 on error (out of memory).
|
||||
*/
|
||||
int hashtable_init(hashtable_t *hashtable);
|
||||
|
||||
/**
|
||||
* hashtable_close - Release all resources used by a hashtable object
|
||||
*
|
||||
* @hashtable: The hashtable
|
||||
*
|
||||
* Destroys a statically allocated hashtable object.
|
||||
*/
|
||||
void hashtable_close(hashtable_t *hashtable);
|
||||
|
||||
/**
|
||||
* hashtable_set - Add/modify value in hashtable
|
||||
*
|
||||
* @hashtable: The hashtable object
|
||||
* @key: The key
|
||||
* @serial: For addition order of keys
|
||||
* @value: The value
|
||||
*
|
||||
* If a value with the given key already exists, its value is replaced
|
||||
* with the new value. Value is "stealed" in the sense that hashtable
|
||||
* doesn't increment its refcount but decreases the refcount when the
|
||||
* value is no longer needed.
|
||||
*
|
||||
* Returns 0 on success, -1 on failure (out of memory).
|
||||
*/
|
||||
int hashtable_set(hashtable_t *hashtable,
|
||||
const char *key, size_t serial,
|
||||
json_t *value);
|
||||
|
||||
/**
|
||||
* hashtable_get - Get a value associated with a key
|
||||
*
|
||||
* @hashtable: The hashtable object
|
||||
* @key: The key
|
||||
*
|
||||
* Returns value if it is found, or NULL otherwise.
|
||||
*/
|
||||
void *hashtable_get(hashtable_t *hashtable, const char *key);
|
||||
|
||||
/**
|
||||
* hashtable_del - Remove a value from the hashtable
|
||||
*
|
||||
* @hashtable: The hashtable object
|
||||
* @key: The key
|
||||
*
|
||||
* Returns 0 on success, or -1 if the key was not found.
|
||||
*/
|
||||
int hashtable_del(hashtable_t *hashtable, const char *key);
|
||||
|
||||
/**
|
||||
* hashtable_clear - Clear hashtable
|
||||
*
|
||||
* @hashtable: The hashtable object
|
||||
*
|
||||
* Removes all items from the hashtable.
|
||||
*/
|
||||
void hashtable_clear(hashtable_t *hashtable);
|
||||
|
||||
/**
|
||||
* hashtable_iter - Iterate over hashtable
|
||||
*
|
||||
* @hashtable: The hashtable object
|
||||
*
|
||||
* Returns an opaque iterator to the first element in the hashtable.
|
||||
* The iterator should be passed to hashtable_iter_* functions.
|
||||
* The hashtable items are not iterated over in any particular order.
|
||||
*
|
||||
* There's no need to free the iterator in any way. The iterator is
|
||||
* valid as long as the item that is referenced by the iterator is not
|
||||
* deleted. Other values may be added or deleted. In particular,
|
||||
* hashtable_iter_next() may be called on an iterator, and after that
|
||||
* the key/value pair pointed by the old iterator may be deleted.
|
||||
*/
|
||||
void *hashtable_iter(hashtable_t *hashtable);
|
||||
|
||||
/**
|
||||
* hashtable_iter_at - Return an iterator at a specific key
|
||||
*
|
||||
* @hashtable: The hashtable object
|
||||
* @key: The key that the iterator should point to
|
||||
*
|
||||
* Like hashtable_iter() but returns an iterator pointing to a
|
||||
* specific key.
|
||||
*/
|
||||
void *hashtable_iter_at(hashtable_t *hashtable, const char *key);
|
||||
|
||||
/**
|
||||
* hashtable_iter_next - Advance an iterator
|
||||
*
|
||||
* @hashtable: The hashtable object
|
||||
* @iter: The iterator
|
||||
*
|
||||
* Returns a new iterator pointing to the next element in the
|
||||
* hashtable or NULL if the whole hastable has been iterated over.
|
||||
*/
|
||||
void *hashtable_iter_next(hashtable_t *hashtable, void *iter);
|
||||
|
||||
/**
|
||||
* hashtable_iter_key - Retrieve the key pointed by an iterator
|
||||
*
|
||||
* @iter: The iterator
|
||||
*/
|
||||
void *hashtable_iter_key(void *iter);
|
||||
|
||||
/**
|
||||
* hashtable_iter_serial - Retrieve the serial number pointed to by an iterator
|
||||
*
|
||||
* @iter: The iterator
|
||||
*/
|
||||
size_t hashtable_iter_serial(void *iter);
|
||||
|
||||
/**
|
||||
* hashtable_iter_value - Retrieve the value pointed by an iterator
|
||||
*
|
||||
* @iter: The iterator
|
||||
*/
|
||||
void *hashtable_iter_value(void *iter);
|
||||
|
||||
/**
|
||||
* hashtable_iter_set - Set the value pointed by an iterator
|
||||
*
|
||||
* @iter: The iterator
|
||||
* @value: The value to set
|
||||
*/
|
||||
void hashtable_iter_set(void *iter, json_t *value);
|
||||
|
||||
#endif
|
277
external/Jansson/hashtable_seed.c
vendored
277
external/Jansson/hashtable_seed.c
vendored
@ -1,277 +0,0 @@
|
||||
/* Generate sizeof(uint32_t) bytes of as random data as possible to seed
|
||||
the hash function.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <jansson_private_config.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
#ifdef HAVE_STDINT_H
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_FCNTL_H
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SCHED_H
|
||||
#include <sched.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_STAT_H
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_TIME_H
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32)
|
||||
/* For GetModuleHandle(), GetProcAddress() and GetCurrentProcessId() */
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include "jansson.h"
|
||||
|
||||
|
||||
static uint32_t buf_to_uint32(char *data) {
|
||||
size_t i;
|
||||
uint32_t result = 0;
|
||||
|
||||
for (i = 0; i < sizeof(uint32_t); i++)
|
||||
result = (result << 8) | (unsigned char)data[i];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* /dev/urandom */
|
||||
#if !defined(_WIN32) && defined(USE_URANDOM)
|
||||
static int seed_from_urandom(uint32_t *seed) {
|
||||
/* Use unbuffered I/O if we have open(), close() and read(). Otherwise
|
||||
fall back to fopen() */
|
||||
|
||||
char data[sizeof(uint32_t)];
|
||||
int ok;
|
||||
|
||||
#if defined(HAVE_OPEN) && defined(HAVE_CLOSE) && defined(HAVE_READ)
|
||||
int urandom;
|
||||
urandom = open("/dev/urandom", O_RDONLY);
|
||||
if (urandom == -1)
|
||||
return 1;
|
||||
|
||||
ok = read(urandom, data, sizeof(uint32_t)) == sizeof(uint32_t);
|
||||
close(urandom);
|
||||
#else
|
||||
FILE *urandom;
|
||||
|
||||
urandom = fopen("/dev/urandom", "rb");
|
||||
if (!urandom)
|
||||
return 1;
|
||||
|
||||
ok = fread(data, 1, sizeof(uint32_t), urandom) == sizeof(uint32_t);
|
||||
fclose(urandom);
|
||||
#endif
|
||||
|
||||
if (!ok)
|
||||
return 1;
|
||||
|
||||
*seed = buf_to_uint32(data);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Windows Crypto API */
|
||||
#if defined(_WIN32) && defined(USE_WINDOWS_CRYPTOAPI)
|
||||
#include <wincrypt.h>
|
||||
|
||||
typedef BOOL (WINAPI *CRYPTACQUIRECONTEXTA)(HCRYPTPROV *phProv, LPCSTR pszContainer, LPCSTR pszProvider, DWORD dwProvType, DWORD dwFlags);
|
||||
typedef BOOL (WINAPI *CRYPTGENRANDOM)(HCRYPTPROV hProv, DWORD dwLen, BYTE *pbBuffer);
|
||||
typedef BOOL (WINAPI *CRYPTRELEASECONTEXT)(HCRYPTPROV hProv, DWORD dwFlags);
|
||||
|
||||
static int seed_from_windows_cryptoapi(uint32_t *seed)
|
||||
{
|
||||
HINSTANCE hAdvAPI32 = NULL;
|
||||
CRYPTACQUIRECONTEXTA pCryptAcquireContext = NULL;
|
||||
CRYPTGENRANDOM pCryptGenRandom = NULL;
|
||||
CRYPTRELEASECONTEXT pCryptReleaseContext = NULL;
|
||||
HCRYPTPROV hCryptProv = 0;
|
||||
BYTE data[sizeof(uint32_t)];
|
||||
int ok;
|
||||
|
||||
hAdvAPI32 = GetModuleHandle(TEXT("advapi32.dll"));
|
||||
if(hAdvAPI32 == NULL)
|
||||
return 1;
|
||||
|
||||
pCryptAcquireContext = (CRYPTACQUIRECONTEXTA)GetProcAddress(hAdvAPI32, "CryptAcquireContextA");
|
||||
if (!pCryptAcquireContext)
|
||||
return 1;
|
||||
|
||||
pCryptGenRandom = (CRYPTGENRANDOM)GetProcAddress(hAdvAPI32, "CryptGenRandom");
|
||||
if (!pCryptGenRandom)
|
||||
return 1;
|
||||
|
||||
pCryptReleaseContext = (CRYPTRELEASECONTEXT)GetProcAddress(hAdvAPI32, "CryptReleaseContext");
|
||||
if (!pCryptReleaseContext)
|
||||
return 1;
|
||||
|
||||
if (!pCryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT))
|
||||
return 1;
|
||||
|
||||
ok = pCryptGenRandom(hCryptProv, sizeof(uint32_t), data);
|
||||
pCryptReleaseContext(hCryptProv, 0);
|
||||
|
||||
if (!ok)
|
||||
return 1;
|
||||
|
||||
*seed = buf_to_uint32((char *)data);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* gettimeofday() and getpid() */
|
||||
static int seed_from_timestamp_and_pid(uint32_t *seed) {
|
||||
#ifdef HAVE_GETTIMEOFDAY
|
||||
/* XOR of seconds and microseconds */
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
*seed = (uint32_t)tv.tv_sec ^ (uint32_t)tv.tv_usec;
|
||||
#else
|
||||
/* Seconds only */
|
||||
*seed = (uint32_t)time(NULL);
|
||||
#endif
|
||||
|
||||
/* XOR with PID for more randomness */
|
||||
#if defined(_WIN32)
|
||||
*seed ^= (uint32_t)GetCurrentProcessId();
|
||||
#elif defined(HAVE_GETPID)
|
||||
*seed ^= (uint32_t)getpid();
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static uint32_t generate_seed() {
|
||||
uint32_t seed;
|
||||
int done = 0;
|
||||
|
||||
#if !defined(_WIN32) && defined(USE_URANDOM)
|
||||
if (!done && seed_from_urandom(&seed) == 0)
|
||||
done = 1;
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32) && defined(USE_WINDOWS_CRYPTOAPI)
|
||||
if (!done && seed_from_windows_cryptoapi(&seed) == 0)
|
||||
done = 1;
|
||||
#endif
|
||||
|
||||
if (!done) {
|
||||
/* Fall back to timestamp and PID if no better randomness is
|
||||
available */
|
||||
seed_from_timestamp_and_pid(&seed);
|
||||
}
|
||||
|
||||
/* Make sure the seed is never zero */
|
||||
if (seed == 0)
|
||||
seed = 1;
|
||||
|
||||
return seed;
|
||||
}
|
||||
|
||||
|
||||
volatile uint32_t hashtable_seed = 0;
|
||||
|
||||
#if defined(HAVE_ATOMIC_BUILTINS) && (defined(HAVE_SCHED_YIELD) || !defined(_WIN32))
|
||||
static volatile char seed_initialized = 0;
|
||||
|
||||
void json_object_seed(size_t seed) {
|
||||
uint32_t new_seed = (uint32_t)seed;
|
||||
|
||||
if (hashtable_seed == 0) {
|
||||
if (__atomic_test_and_set(&seed_initialized, __ATOMIC_RELAXED) == 0) {
|
||||
/* Do the seeding ourselves */
|
||||
if (new_seed == 0)
|
||||
new_seed = generate_seed();
|
||||
|
||||
__atomic_store_n(&hashtable_seed, new_seed, __ATOMIC_RELEASE);
|
||||
} else {
|
||||
/* Wait for another thread to do the seeding */
|
||||
do {
|
||||
#ifdef HAVE_SCHED_YIELD
|
||||
sched_yield();
|
||||
#endif
|
||||
} while(__atomic_load_n(&hashtable_seed, __ATOMIC_ACQUIRE) == 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
#elif defined(HAVE_SYNC_BUILTINS) && (defined(HAVE_SCHED_YIELD) || !defined(_WIN32))
|
||||
void json_object_seed(size_t seed) {
|
||||
uint32_t new_seed = (uint32_t)seed;
|
||||
|
||||
if (hashtable_seed == 0) {
|
||||
if (new_seed == 0) {
|
||||
/* Explicit synchronization fences are not supported by the
|
||||
__sync builtins, so every thread getting here has to
|
||||
generate the seed value.
|
||||
*/
|
||||
new_seed = generate_seed();
|
||||
}
|
||||
|
||||
do {
|
||||
if (__sync_bool_compare_and_swap(&hashtable_seed, 0, new_seed)) {
|
||||
/* We were the first to seed */
|
||||
break;
|
||||
} else {
|
||||
/* Wait for another thread to do the seeding */
|
||||
#ifdef HAVE_SCHED_YIELD
|
||||
sched_yield();
|
||||
#endif
|
||||
}
|
||||
} while(hashtable_seed == 0);
|
||||
}
|
||||
}
|
||||
#elif defined(_WIN32)
|
||||
static long seed_initialized = 0;
|
||||
void json_object_seed(size_t seed) {
|
||||
uint32_t new_seed = (uint32_t)seed;
|
||||
|
||||
if (hashtable_seed == 0) {
|
||||
if (InterlockedIncrement(&seed_initialized) == 1) {
|
||||
/* Do the seeding ourselves */
|
||||
if (new_seed == 0)
|
||||
new_seed = generate_seed();
|
||||
|
||||
hashtable_seed = new_seed;
|
||||
} else {
|
||||
/* Wait for another thread to do the seeding */
|
||||
do {
|
||||
SwitchToThread();
|
||||
} while (hashtable_seed == 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
/* Fall back to a thread-unsafe version */
|
||||
void json_object_seed(size_t seed) {
|
||||
uint32_t new_seed = (uint32_t)seed;
|
||||
|
||||
if (hashtable_seed == 0) {
|
||||
if (new_seed == 0)
|
||||
new_seed = generate_seed();
|
||||
|
||||
hashtable_seed = new_seed;
|
||||
}
|
||||
}
|
||||
#endif
|
70
external/Jansson/jansson.def
vendored
70
external/Jansson/jansson.def
vendored
@ -1,70 +0,0 @@
|
||||
EXPORTS
|
||||
json_delete
|
||||
json_true
|
||||
json_false
|
||||
json_null
|
||||
json_string
|
||||
json_stringn
|
||||
json_string_nocheck
|
||||
json_stringn_nocheck
|
||||
json_string_value
|
||||
json_string_length
|
||||
json_string_set
|
||||
json_string_setn
|
||||
json_string_set_nocheck
|
||||
json_string_setn_nocheck
|
||||
json_integer
|
||||
json_integer_value
|
||||
json_integer_set
|
||||
json_real
|
||||
json_real_value
|
||||
json_real_set
|
||||
json_number_value
|
||||
json_array
|
||||
json_array_size
|
||||
json_array_get
|
||||
json_array_set_new
|
||||
json_array_append_new
|
||||
json_array_insert_new
|
||||
json_array_remove
|
||||
json_array_clear
|
||||
json_array_extend
|
||||
json_object
|
||||
json_object_size
|
||||
json_object_get
|
||||
json_object_set_new
|
||||
json_object_set_new_nocheck
|
||||
json_object_del
|
||||
json_object_clear
|
||||
json_object_update
|
||||
json_object_update_existing
|
||||
json_object_update_missing
|
||||
json_object_iter
|
||||
json_object_iter_at
|
||||
json_object_iter_next
|
||||
json_object_iter_key
|
||||
json_object_iter_value
|
||||
json_object_iter_set_new
|
||||
json_object_key_to_iter
|
||||
json_object_seed
|
||||
json_dumps
|
||||
json_dumpf
|
||||
json_dump_file
|
||||
json_dump_callback
|
||||
json_loads
|
||||
json_loadb
|
||||
json_loadf
|
||||
json_load_file
|
||||
json_load_callback
|
||||
json_equal
|
||||
json_copy
|
||||
json_deep_copy
|
||||
json_pack
|
||||
json_pack_ex
|
||||
json_vpack_ex
|
||||
json_unpack
|
||||
json_unpack_ex
|
||||
json_vunpack_ex
|
||||
json_set_alloc_funcs
|
||||
json_get_alloc_funcs
|
||||
|
298
external/Jansson/jansson.h
vendored
298
external/Jansson/jansson.h
vendored
@ -1,298 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2014 Petri Lehtinen <petri@digip.org>
|
||||
*
|
||||
* Jansson is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the MIT license. See LICENSE for details.
|
||||
*/
|
||||
|
||||
#ifndef JANSSON_H
|
||||
#define JANSSON_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h> /* for size_t */
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "jansson_config.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* version */
|
||||
|
||||
#define JANSSON_MAJOR_VERSION 2
|
||||
#define JANSSON_MINOR_VERSION 7
|
||||
#define JANSSON_MICRO_VERSION 0
|
||||
|
||||
/* Micro version is omitted if it's 0 */
|
||||
#define JANSSON_VERSION "2.7"
|
||||
|
||||
/* Version as a 3-byte hex number, e.g. 0x010201 == 1.2.1. Use this
|
||||
for numeric comparisons, e.g. #if JANSSON_VERSION_HEX >= ... */
|
||||
#define JANSSON_VERSION_HEX ((JANSSON_MAJOR_VERSION << 16) | \
|
||||
(JANSSON_MINOR_VERSION << 8) | \
|
||||
(JANSSON_MICRO_VERSION << 0))
|
||||
|
||||
|
||||
/* types */
|
||||
|
||||
typedef enum {
|
||||
JSON_OBJECT,
|
||||
JSON_ARRAY,
|
||||
JSON_STRING,
|
||||
JSON_INTEGER,
|
||||
JSON_REAL,
|
||||
JSON_TRUE,
|
||||
JSON_FALSE,
|
||||
JSON_NULL
|
||||
} json_type;
|
||||
|
||||
typedef struct json_t {
|
||||
json_type type;
|
||||
size_t refcount;
|
||||
} json_t;
|
||||
|
||||
#ifndef JANSSON_USING_CMAKE /* disabled if using cmake */
|
||||
#if JSON_INTEGER_IS_LONG_LONG
|
||||
#ifdef _WIN32
|
||||
#define JSON_INTEGER_FORMAT "I64d"
|
||||
#else
|
||||
#define JSON_INTEGER_FORMAT "lld"
|
||||
#endif
|
||||
typedef long long json_int_t;
|
||||
#else
|
||||
#define JSON_INTEGER_FORMAT "ld"
|
||||
typedef long json_int_t;
|
||||
#endif /* JSON_INTEGER_IS_LONG_LONG */
|
||||
#endif
|
||||
|
||||
#define json_typeof(json) ((json)->type)
|
||||
#define json_is_object(json) ((json) && json_typeof(json) == JSON_OBJECT)
|
||||
#define json_is_array(json) ((json) && json_typeof(json) == JSON_ARRAY)
|
||||
#define json_is_string(json) ((json) && json_typeof(json) == JSON_STRING)
|
||||
#define json_is_integer(json) ((json) && json_typeof(json) == JSON_INTEGER)
|
||||
#define json_is_real(json) ((json) && json_typeof(json) == JSON_REAL)
|
||||
#define json_is_number(json) (json_is_integer(json) || json_is_real(json))
|
||||
#define json_is_true(json) ((json) && json_typeof(json) == JSON_TRUE)
|
||||
#define json_is_false(json) ((json) && json_typeof(json) == JSON_FALSE)
|
||||
#define json_boolean_value json_is_true
|
||||
#define json_is_boolean(json) (json_is_true(json) || json_is_false(json))
|
||||
#define json_is_null(json) ((json) && json_typeof(json) == JSON_NULL)
|
||||
|
||||
/* construction, destruction, reference counting */
|
||||
|
||||
json_t *json_object(void);
|
||||
json_t *json_array(void);
|
||||
json_t *json_string(const char *value);
|
||||
json_t *json_stringn(const char *value, size_t len);
|
||||
json_t *json_string_nocheck(const char *value);
|
||||
json_t *json_stringn_nocheck(const char *value, size_t len);
|
||||
json_t *json_integer(json_int_t value);
|
||||
json_t *json_real(double value);
|
||||
json_t *json_true(void);
|
||||
json_t *json_false(void);
|
||||
#define json_boolean(val) ((val) ? json_true() : json_false())
|
||||
json_t *json_null(void);
|
||||
|
||||
static JSON_INLINE
|
||||
json_t *json_incref(json_t *json)
|
||||
{
|
||||
if(json && json->refcount != (size_t)-1)
|
||||
++json->refcount;
|
||||
return json;
|
||||
}
|
||||
|
||||
/* do not call json_delete directly */
|
||||
void json_delete(json_t *json);
|
||||
|
||||
static JSON_INLINE
|
||||
void json_decref(json_t *json)
|
||||
{
|
||||
if(json && json->refcount != (size_t)-1 && --json->refcount == 0)
|
||||
json_delete(json);
|
||||
}
|
||||
|
||||
|
||||
/* error reporting */
|
||||
|
||||
#define JSON_ERROR_TEXT_LENGTH 160
|
||||
#define JSON_ERROR_SOURCE_LENGTH 80
|
||||
|
||||
typedef struct {
|
||||
int line;
|
||||
int column;
|
||||
int position;
|
||||
char source[JSON_ERROR_SOURCE_LENGTH];
|
||||
char text[JSON_ERROR_TEXT_LENGTH];
|
||||
} json_error_t;
|
||||
|
||||
|
||||
/* getters, setters, manipulation */
|
||||
|
||||
void json_object_seed(size_t seed);
|
||||
size_t json_object_size(const json_t *object);
|
||||
json_t *json_object_get(const json_t *object, const char *key);
|
||||
int json_object_set_new(json_t *object, const char *key, json_t *value);
|
||||
int json_object_set_new_nocheck(json_t *object, const char *key, json_t *value);
|
||||
int json_object_del(json_t *object, const char *key);
|
||||
int json_object_clear(json_t *object);
|
||||
int json_object_update(json_t *object, json_t *other);
|
||||
int json_object_update_existing(json_t *object, json_t *other);
|
||||
int json_object_update_missing(json_t *object, json_t *other);
|
||||
void *json_object_iter(json_t *object);
|
||||
void *json_object_iter_at(json_t *object, const char *key);
|
||||
void *json_object_key_to_iter(const char *key);
|
||||
void *json_object_iter_next(json_t *object, void *iter);
|
||||
const char *json_object_iter_key(void *iter);
|
||||
json_t *json_object_iter_value(void *iter);
|
||||
int json_object_iter_set_new(json_t *object, void *iter, json_t *value);
|
||||
|
||||
#define json_object_foreach(object, key, value) \
|
||||
for(key = json_object_iter_key(json_object_iter(object)); \
|
||||
key && (value = json_object_iter_value(json_object_key_to_iter(key))); \
|
||||
key = json_object_iter_key(json_object_iter_next(object, json_object_key_to_iter(key))))
|
||||
|
||||
#define json_object_foreach_safe(object, n, key, value) \
|
||||
for(key = json_object_iter_key(json_object_iter(object)), \
|
||||
n = json_object_iter_next(object, json_object_key_to_iter(key)); \
|
||||
key && (value = json_object_iter_value(json_object_key_to_iter(key))); \
|
||||
key = json_object_iter_key(n), \
|
||||
n = json_object_iter_next(object, json_object_key_to_iter(key)))
|
||||
|
||||
#define json_array_foreach(array, index, value) \
|
||||
for(index = 0; \
|
||||
index < json_array_size(array) && (value = json_array_get(array, index)); \
|
||||
index++)
|
||||
|
||||
static JSON_INLINE
|
||||
int json_object_set(json_t *object, const char *key, json_t *value)
|
||||
{
|
||||
return json_object_set_new(object, key, json_incref(value));
|
||||
}
|
||||
|
||||
static JSON_INLINE
|
||||
int json_object_set_nocheck(json_t *object, const char *key, json_t *value)
|
||||
{
|
||||
return json_object_set_new_nocheck(object, key, json_incref(value));
|
||||
}
|
||||
|
||||
static JSON_INLINE
|
||||
int json_object_iter_set(json_t *object, void *iter, json_t *value)
|
||||
{
|
||||
return json_object_iter_set_new(object, iter, json_incref(value));
|
||||
}
|
||||
|
||||
size_t json_array_size(const json_t *array);
|
||||
json_t *json_array_get(const json_t *array, size_t index);
|
||||
int json_array_set_new(json_t *array, size_t index, json_t *value);
|
||||
int json_array_append_new(json_t *array, json_t *value);
|
||||
int json_array_insert_new(json_t *array, size_t index, json_t *value);
|
||||
int json_array_remove(json_t *array, size_t index);
|
||||
int json_array_clear(json_t *array);
|
||||
int json_array_extend(json_t *array, json_t *other);
|
||||
|
||||
static JSON_INLINE
|
||||
int json_array_set(json_t *array, size_t ind, json_t *value)
|
||||
{
|
||||
return json_array_set_new(array, ind, json_incref(value));
|
||||
}
|
||||
|
||||
static JSON_INLINE
|
||||
int json_array_append(json_t *array, json_t *value)
|
||||
{
|
||||
return json_array_append_new(array, json_incref(value));
|
||||
}
|
||||
|
||||
static JSON_INLINE
|
||||
int json_array_insert(json_t *array, size_t ind, json_t *value)
|
||||
{
|
||||
return json_array_insert_new(array, ind, json_incref(value));
|
||||
}
|
||||
|
||||
const char *json_string_value(const json_t *string);
|
||||
size_t json_string_length(const json_t *string);
|
||||
json_int_t json_integer_value(const json_t *integer);
|
||||
double json_real_value(const json_t *real);
|
||||
double json_number_value(const json_t *json);
|
||||
|
||||
int json_string_set(json_t *string, const char *value);
|
||||
int json_string_setn(json_t *string, const char *value, size_t len);
|
||||
int json_string_set_nocheck(json_t *string, const char *value);
|
||||
int json_string_setn_nocheck(json_t *string, const char *value, size_t len);
|
||||
int json_integer_set(json_t *integer, json_int_t value);
|
||||
int json_real_set(json_t *real, double value);
|
||||
|
||||
/* pack, unpack */
|
||||
|
||||
json_t *json_pack(const char *fmt, ...);
|
||||
json_t *json_pack_ex(json_error_t *error, size_t flags, const char *fmt, ...);
|
||||
json_t *json_vpack_ex(json_error_t *error, size_t flags, const char *fmt, va_list ap);
|
||||
|
||||
#define JSON_VALIDATE_ONLY 0x1
|
||||
#define JSON_STRICT 0x2
|
||||
|
||||
int json_unpack(json_t *root, const char *fmt, ...);
|
||||
int json_unpack_ex(json_t *root, json_error_t *error, size_t flags, const char *fmt, ...);
|
||||
int json_vunpack_ex(json_t *root, json_error_t *error, size_t flags, const char *fmt, va_list ap);
|
||||
|
||||
|
||||
/* equality */
|
||||
|
||||
int json_equal(json_t *value1, json_t *value2);
|
||||
|
||||
|
||||
/* copying */
|
||||
|
||||
json_t *json_copy(json_t *value);
|
||||
json_t *json_deep_copy(const json_t *value);
|
||||
|
||||
|
||||
/* decoding */
|
||||
|
||||
#define JSON_REJECT_DUPLICATES 0x1
|
||||
#define JSON_DISABLE_EOF_CHECK 0x2
|
||||
#define JSON_DECODE_ANY 0x4
|
||||
#define JSON_DECODE_INT_AS_REAL 0x8
|
||||
#define JSON_ALLOW_NUL 0x10
|
||||
|
||||
typedef size_t (*json_load_callback_t)(void *buffer, size_t buflen, void *data);
|
||||
|
||||
json_t *json_loads(const char *input, size_t flags, json_error_t *error);
|
||||
json_t *json_loadb(const char *buffer, size_t buflen, size_t flags, json_error_t *error);
|
||||
json_t *json_loadf(FILE *input, size_t flags, json_error_t *error);
|
||||
json_t *json_load_file(const char *path, size_t flags, json_error_t *error);
|
||||
json_t *json_load_callback(json_load_callback_t callback, void *data, size_t flags, json_error_t *error);
|
||||
|
||||
|
||||
/* encoding */
|
||||
|
||||
#define JSON_MAX_INDENT 0x1F
|
||||
#define JSON_INDENT(n) ((n) & JSON_MAX_INDENT)
|
||||
#define JSON_COMPACT 0x20
|
||||
#define JSON_ENSURE_ASCII 0x40
|
||||
#define JSON_SORT_KEYS 0x80
|
||||
#define JSON_PRESERVE_ORDER 0x100
|
||||
#define JSON_ENCODE_ANY 0x200
|
||||
#define JSON_ESCAPE_SLASH 0x400
|
||||
#define JSON_REAL_PRECISION(n) (((n) & 0x1F) << 11)
|
||||
|
||||
typedef int (*json_dump_callback_t)(const char *buffer, size_t size, void *data);
|
||||
|
||||
char *json_dumps(const json_t *json, size_t flags);
|
||||
int json_dumpf(const json_t *json, FILE *output, size_t flags);
|
||||
int json_dump_file(const json_t *json, const char *path, size_t flags);
|
||||
int json_dump_callback(const json_t *json, json_dump_callback_t callback, void *data, size_t flags);
|
||||
|
||||
/* custom memory allocation */
|
||||
|
||||
typedef void *(*json_malloc_t)(size_t);
|
||||
typedef void (*json_free_t)(void *);
|
||||
|
||||
void json_set_alloc_funcs(json_malloc_t malloc_fn, json_free_t free_fn);
|
||||
void json_get_alloc_funcs(json_malloc_t *malloc_fn, json_free_t *free_fn);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
109
external/Jansson/jansson_private.h
vendored
109
external/Jansson/jansson_private.h
vendored
@ -1,109 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2014 Petri Lehtinen <petri@digip.org>
|
||||
*
|
||||
* Jansson is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the MIT license. See LICENSE for details.
|
||||
*/
|
||||
|
||||
#ifndef JANSSON_PRIVATE_H
|
||||
#define JANSSON_PRIVATE_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include "jansson.h"
|
||||
#include "hashtable.h"
|
||||
#include "strbuffer.h"
|
||||
|
||||
#define container_of(ptr_, type_, member_) \
|
||||
((type_ *)((char *)ptr_ - offsetof(type_, member_)))
|
||||
|
||||
/* On some platforms, max() may already be defined */
|
||||
#ifndef max
|
||||
#define max(a, b) ((a) > (b) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
/* va_copy is a C99 feature. In C89 implementations, it's sometimes
|
||||
available as __va_copy. If not, memcpy() should do the trick. */
|
||||
#ifndef va_copy
|
||||
#ifdef __va_copy
|
||||
#define va_copy __va_copy
|
||||
#else
|
||||
#define va_copy(a, b) memcpy(&(a), &(b), sizeof(va_list))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
json_t json;
|
||||
hashtable_t hashtable;
|
||||
size_t serial;
|
||||
int visited;
|
||||
} json_object_t;
|
||||
|
||||
typedef struct {
|
||||
json_t json;
|
||||
size_t size;
|
||||
size_t entries;
|
||||
json_t **table;
|
||||
int visited;
|
||||
} json_array_t;
|
||||
|
||||
typedef struct {
|
||||
json_t json;
|
||||
char *value;
|
||||
size_t length;
|
||||
} json_string_t;
|
||||
|
||||
typedef struct {
|
||||
json_t json;
|
||||
double value;
|
||||
} json_real_t;
|
||||
|
||||
typedef struct {
|
||||
json_t json;
|
||||
json_int_t value;
|
||||
} json_integer_t;
|
||||
|
||||
#define json_to_object(json_) container_of(json_, json_object_t, json)
|
||||
#define json_to_array(json_) container_of(json_, json_array_t, json)
|
||||
#define json_to_string(json_) container_of(json_, json_string_t, json)
|
||||
#define json_to_real(json_) container_of(json_, json_real_t, json)
|
||||
#define json_to_integer(json_) container_of(json_, json_integer_t, json)
|
||||
|
||||
/* Create a string by taking ownership of an existing buffer */
|
||||
json_t *jsonp_stringn_nocheck_own(const char *value, size_t len);
|
||||
|
||||
/* Error message formatting */
|
||||
void jsonp_error_init(json_error_t *error, const char *source);
|
||||
void jsonp_error_set_source(json_error_t *error, const char *source);
|
||||
void jsonp_error_set(json_error_t *error, int line, int column,
|
||||
size_t position, const char *msg, ...);
|
||||
void jsonp_error_vset(json_error_t *error, int line, int column,
|
||||
size_t position, const char *msg, va_list ap);
|
||||
|
||||
/* Locale independent string<->double conversions */
|
||||
int jsonp_strtod(strbuffer_t *strbuffer, double *out);
|
||||
int jsonp_dtostr(char *buffer, size_t size, double value, int prec);
|
||||
|
||||
/* Wrappers for custom memory functions */
|
||||
void* jsonp_malloc(size_t size);
|
||||
void jsonp_free(void *ptr);
|
||||
char *jsonp_strndup(const char *str, size_t length);
|
||||
char *jsonp_strdup(const char *str);
|
||||
char *jsonp_strndup(const char *str, size_t len);
|
||||
|
||||
|
||||
/* Windows compatibility */
|
||||
#if defined(_WIN32) || defined(WIN32)
|
||||
# if defined(_MSC_VER) /* MS compiller */
|
||||
# if (_MSC_VER < 1900) && !defined(snprintf) /* snprintf not defined yet & not introduced */
|
||||
# define snprintf _snprintf
|
||||
# endif
|
||||
# if (_MSC_VER < 1500) && !defined(vsnprintf) /* vsnprintf not defined yet & not introduced */
|
||||
# define vsnprintf(b,c,f,a) _vsnprintf(b,c,f,a)
|
||||
# endif
|
||||
# else /* Other Windows compiller, old definition */
|
||||
# define snprintf _snprintf
|
||||
# define vsnprintf _vsnprintf
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#endif
|
1110
external/Jansson/load.c
vendored
1110
external/Jansson/load.c
vendored
File diff suppressed because it is too large
Load Diff
381
external/Jansson/lookup3.h
vendored
381
external/Jansson/lookup3.h
vendored
@ -1,381 +0,0 @@
|
||||
/*
|
||||
-------------------------------------------------------------------------------
|
||||
lookup3.c, by Bob Jenkins, May 2006, Public Domain.
|
||||
|
||||
These are functions for producing 32-bit hashes for hash table lookup.
|
||||
hashword(), hashlittle(), hashlittle2(), hashbig(), mix(), and final()
|
||||
are externally useful functions. Routines to test the hash are included
|
||||
if SELF_TEST is defined. You can use this free for any purpose. It's in
|
||||
the public domain. It has no warranty.
|
||||
|
||||
You probably want to use hashlittle(). hashlittle() and hashbig()
|
||||
hash byte arrays. hashlittle() is is faster than hashbig() on
|
||||
little-endian machines. Intel and AMD are little-endian machines.
|
||||
On second thought, you probably want hashlittle2(), which is identical to
|
||||
hashlittle() except it returns two 32-bit hashes for the price of one.
|
||||
You could implement hashbig2() if you wanted but I haven't bothered here.
|
||||
|
||||
If you want to find a hash of, say, exactly 7 integers, do
|
||||
a = i1; b = i2; c = i3;
|
||||
mix(a,b,c);
|
||||
a += i4; b += i5; c += i6;
|
||||
mix(a,b,c);
|
||||
a += i7;
|
||||
final(a,b,c);
|
||||
then use c as the hash value. If you have a variable length array of
|
||||
4-byte integers to hash, use hashword(). If you have a byte array (like
|
||||
a character string), use hashlittle(). If you have several byte arrays, or
|
||||
a mix of things, see the comments above hashlittle().
|
||||
|
||||
Why is this so big? I read 12 bytes at a time into 3 4-byte integers,
|
||||
then mix those integers. This is fast (you can do a lot more thorough
|
||||
mixing with 12*3 instructions on 3 integers than you can with 3 instructions
|
||||
on 1 byte), but shoehorning those bytes into integers efficiently is messy.
|
||||
-------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <jansson_private_config.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STDINT_H
|
||||
#include <stdint.h> /* defines uint32_t etc */
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_PARAM_H
|
||||
#include <sys/param.h> /* attempt to define endianness */
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_ENDIAN_H
|
||||
# include <endian.h> /* attempt to define endianness */
|
||||
#endif
|
||||
|
||||
/*
|
||||
* My best guess at if you are big-endian or little-endian. This may
|
||||
* need adjustment.
|
||||
*/
|
||||
#if (defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && \
|
||||
__BYTE_ORDER == __LITTLE_ENDIAN) || \
|
||||
(defined(i386) || defined(__i386__) || defined(__i486__) || \
|
||||
defined(__i586__) || defined(__i686__) || defined(vax) || defined(MIPSEL))
|
||||
# define HASH_LITTLE_ENDIAN 1
|
||||
# define HASH_BIG_ENDIAN 0
|
||||
#elif (defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) && \
|
||||
__BYTE_ORDER == __BIG_ENDIAN) || \
|
||||
(defined(sparc) || defined(POWERPC) || defined(mc68000) || defined(sel))
|
||||
# define HASH_LITTLE_ENDIAN 0
|
||||
# define HASH_BIG_ENDIAN 1
|
||||
#else
|
||||
# define HASH_LITTLE_ENDIAN 0
|
||||
# define HASH_BIG_ENDIAN 0
|
||||
#endif
|
||||
|
||||
#define hashsize(n) ((uint32_t)1<<(n))
|
||||
#define hashmask(n) (hashsize(n)-1)
|
||||
#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
|
||||
|
||||
/*
|
||||
-------------------------------------------------------------------------------
|
||||
mix -- mix 3 32-bit values reversibly.
|
||||
|
||||
This is reversible, so any information in (a,b,c) before mix() is
|
||||
still in (a,b,c) after mix().
|
||||
|
||||
If four pairs of (a,b,c) inputs are run through mix(), or through
|
||||
mix() in reverse, there are at least 32 bits of the output that
|
||||
are sometimes the same for one pair and different for another pair.
|
||||
This was tested for:
|
||||
* pairs that differed by one bit, by two bits, in any combination
|
||||
of top bits of (a,b,c), or in any combination of bottom bits of
|
||||
(a,b,c).
|
||||
* "differ" is defined as +, -, ^, or ~^. For + and -, I transformed
|
||||
the output delta to a Gray code (a^(a>>1)) so a string of 1's (as
|
||||
is commonly produced by subtraction) look like a single 1-bit
|
||||
difference.
|
||||
* the base values were pseudorandom, all zero but one bit set, or
|
||||
all zero plus a counter that starts at zero.
|
||||
|
||||
Some k values for my "a-=c; a^=rot(c,k); c+=b;" arrangement that
|
||||
satisfy this are
|
||||
4 6 8 16 19 4
|
||||
9 15 3 18 27 15
|
||||
14 9 3 7 17 3
|
||||
Well, "9 15 3 18 27 15" didn't quite get 32 bits diffing
|
||||
for "differ" defined as + with a one-bit base and a two-bit delta. I
|
||||
used http://burtleburtle.net/bob/hash/avalanche.html to choose
|
||||
the operations, constants, and arrangements of the variables.
|
||||
|
||||
This does not achieve avalanche. There are input bits of (a,b,c)
|
||||
that fail to affect some output bits of (a,b,c), especially of a. The
|
||||
most thoroughly mixed value is c, but it doesn't really even achieve
|
||||
avalanche in c.
|
||||
|
||||
This allows some parallelism. Read-after-writes are good at doubling
|
||||
the number of bits affected, so the goal of mixing pulls in the opposite
|
||||
direction as the goal of parallelism. I did what I could. Rotates
|
||||
seem to cost as much as shifts on every machine I could lay my hands
|
||||
on, and rotates are much kinder to the top and bottom bits, so I used
|
||||
rotates.
|
||||
-------------------------------------------------------------------------------
|
||||
*/
|
||||
#define mix(a,b,c) \
|
||||
{ \
|
||||
a -= c; a ^= rot(c, 4); c += b; \
|
||||
b -= a; b ^= rot(a, 6); a += c; \
|
||||
c -= b; c ^= rot(b, 8); b += a; \
|
||||
a -= c; a ^= rot(c,16); c += b; \
|
||||
b -= a; b ^= rot(a,19); a += c; \
|
||||
c -= b; c ^= rot(b, 4); b += a; \
|
||||
}
|
||||
|
||||
/*
|
||||
-------------------------------------------------------------------------------
|
||||
final -- final mixing of 3 32-bit values (a,b,c) into c
|
||||
|
||||
Pairs of (a,b,c) values differing in only a few bits will usually
|
||||
produce values of c that look totally different. This was tested for
|
||||
* pairs that differed by one bit, by two bits, in any combination
|
||||
of top bits of (a,b,c), or in any combination of bottom bits of
|
||||
(a,b,c).
|
||||
* "differ" is defined as +, -, ^, or ~^. For + and -, I transformed
|
||||
the output delta to a Gray code (a^(a>>1)) so a string of 1's (as
|
||||
is commonly produced by subtraction) look like a single 1-bit
|
||||
difference.
|
||||
* the base values were pseudorandom, all zero but one bit set, or
|
||||
all zero plus a counter that starts at zero.
|
||||
|
||||
These constants passed:
|
||||
14 11 25 16 4 14 24
|
||||
12 14 25 16 4 14 24
|
||||
and these came close:
|
||||
4 8 15 26 3 22 24
|
||||
10 8 15 26 3 22 24
|
||||
11 8 15 26 3 22 24
|
||||
-------------------------------------------------------------------------------
|
||||
*/
|
||||
#define final(a,b,c) \
|
||||
{ \
|
||||
c ^= b; c -= rot(b,14); \
|
||||
a ^= c; a -= rot(c,11); \
|
||||
b ^= a; b -= rot(a,25); \
|
||||
c ^= b; c -= rot(b,16); \
|
||||
a ^= c; a -= rot(c,4); \
|
||||
b ^= a; b -= rot(a,14); \
|
||||
c ^= b; c -= rot(b,24); \
|
||||
}
|
||||
|
||||
/*
|
||||
-------------------------------------------------------------------------------
|
||||
hashlittle() -- hash a variable-length key into a 32-bit value
|
||||
k : the key (the unaligned variable-length array of bytes)
|
||||
length : the length of the key, counting by bytes
|
||||
initval : can be any 4-byte value
|
||||
Returns a 32-bit value. Every bit of the key affects every bit of
|
||||
the return value. Two keys differing by one or two bits will have
|
||||
totally different hash values.
|
||||
|
||||
The best hash table sizes are powers of 2. There is no need to do
|
||||
mod a prime (mod is sooo slow!). If you need less than 32 bits,
|
||||
use a bitmask. For example, if you need only 10 bits, do
|
||||
h = (h & hashmask(10));
|
||||
In which case, the hash table should have hashsize(10) elements.
|
||||
|
||||
If you are hashing n strings (uint8_t **)k, do it like this:
|
||||
for (i=0, h=0; i<n; ++i) h = hashlittle( k[i], len[i], h);
|
||||
|
||||
By Bob Jenkins, 2006. bob_jenkins@burtleburtle.net. You may use this
|
||||
code any way you wish, private, educational, or commercial. It's free.
|
||||
|
||||
Use for hash table lookup, or anything where one collision in 2^^32 is
|
||||
acceptable. Do NOT use for cryptographic purposes.
|
||||
-------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
static uint32_t hashlittle(const void *key, size_t length, uint32_t initval)
|
||||
{
|
||||
uint32_t a,b,c; /* internal state */
|
||||
union { const void *ptr; size_t i; } u; /* needed for Mac Powerbook G4 */
|
||||
|
||||
/* Set up the internal state */
|
||||
a = b = c = 0xdeadbeef + ((uint32_t)length) + initval;
|
||||
|
||||
u.ptr = key;
|
||||
if (HASH_LITTLE_ENDIAN && ((u.i & 0x3) == 0)) {
|
||||
const uint32_t *k = (const uint32_t *)key; /* read 32-bit chunks */
|
||||
|
||||
/* Detect Valgrind or AddressSanitizer */
|
||||
#ifdef VALGRIND
|
||||
# define NO_MASKING_TRICK 1
|
||||
#else
|
||||
# if defined(__has_feature) /* Clang */
|
||||
# if __has_feature(address_sanitizer) /* is ASAN enabled? */
|
||||
# define NO_MASKING_TRICK 1
|
||||
# endif
|
||||
# else
|
||||
# if defined(__SANITIZE_ADDRESS__) /* GCC 4.8.x, is ASAN enabled? */
|
||||
# define NO_MASKING_TRICK 1
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef NO_MASKING_TRICK
|
||||
const uint8_t *k8;
|
||||
#endif
|
||||
|
||||
/*------ all but last block: aligned reads and affect 32 bits of (a,b,c) */
|
||||
while (length > 12)
|
||||
{
|
||||
a += k[0];
|
||||
b += k[1];
|
||||
c += k[2];
|
||||
mix(a,b,c);
|
||||
length -= 12;
|
||||
k += 3;
|
||||
}
|
||||
|
||||
/*----------------------------- handle the last (probably partial) block */
|
||||
/*
|
||||
* "k[2]&0xffffff" actually reads beyond the end of the string, but
|
||||
* then masks off the part it's not allowed to read. Because the
|
||||
* string is aligned, the masked-off tail is in the same word as the
|
||||
* rest of the string. Every machine with memory protection I've seen
|
||||
* does it on word boundaries, so is OK with this. But VALGRIND will
|
||||
* still catch it and complain. The masking trick does make the hash
|
||||
* noticably faster for short strings (like English words).
|
||||
*/
|
||||
#ifndef NO_MASKING_TRICK
|
||||
|
||||
switch(length)
|
||||
{
|
||||
case 12: c+=k[2]; b+=k[1]; a+=k[0]; break;
|
||||
case 11: c+=k[2]&0xffffff; b+=k[1]; a+=k[0]; break;
|
||||
case 10: c+=k[2]&0xffff; b+=k[1]; a+=k[0]; break;
|
||||
case 9 : c+=k[2]&0xff; b+=k[1]; a+=k[0]; break;
|
||||
case 8 : b+=k[1]; a+=k[0]; break;
|
||||
case 7 : b+=k[1]&0xffffff; a+=k[0]; break;
|
||||
case 6 : b+=k[1]&0xffff; a+=k[0]; break;
|
||||
case 5 : b+=k[1]&0xff; a+=k[0]; break;
|
||||
case 4 : a+=k[0]; break;
|
||||
case 3 : a+=k[0]&0xffffff; break;
|
||||
case 2 : a+=k[0]&0xffff; break;
|
||||
case 1 : a+=k[0]&0xff; break;
|
||||
case 0 : return c; /* zero length strings require no mixing */
|
||||
}
|
||||
|
||||
#else /* make valgrind happy */
|
||||
|
||||
k8 = (const uint8_t *)k;
|
||||
switch(length)
|
||||
{
|
||||
case 12: c+=k[2]; b+=k[1]; a+=k[0]; break;
|
||||
case 11: c+=((uint32_t)k8[10])<<16; /* fall through */
|
||||
case 10: c+=((uint32_t)k8[9])<<8; /* fall through */
|
||||
case 9 : c+=k8[8]; /* fall through */
|
||||
case 8 : b+=k[1]; a+=k[0]; break;
|
||||
case 7 : b+=((uint32_t)k8[6])<<16; /* fall through */
|
||||
case 6 : b+=((uint32_t)k8[5])<<8; /* fall through */
|
||||
case 5 : b+=k8[4]; /* fall through */
|
||||
case 4 : a+=k[0]; break;
|
||||
case 3 : a+=((uint32_t)k8[2])<<16; /* fall through */
|
||||
case 2 : a+=((uint32_t)k8[1])<<8; /* fall through */
|
||||
case 1 : a+=k8[0]; break;
|
||||
case 0 : return c;
|
||||
}
|
||||
|
||||
#endif /* !valgrind */
|
||||
|
||||
} else if (HASH_LITTLE_ENDIAN && ((u.i & 0x1) == 0)) {
|
||||
const uint16_t *k = (const uint16_t *)key; /* read 16-bit chunks */
|
||||
const uint8_t *k8;
|
||||
|
||||
/*--------------- all but last block: aligned reads and different mixing */
|
||||
while (length > 12)
|
||||
{
|
||||
a += k[0] + (((uint32_t)k[1])<<16);
|
||||
b += k[2] + (((uint32_t)k[3])<<16);
|
||||
c += k[4] + (((uint32_t)k[5])<<16);
|
||||
mix(a,b,c);
|
||||
length -= 12;
|
||||
k += 6;
|
||||
}
|
||||
|
||||
/*----------------------------- handle the last (probably partial) block */
|
||||
k8 = (const uint8_t *)k;
|
||||
switch(length)
|
||||
{
|
||||
case 12: c+=k[4]+(((uint32_t)k[5])<<16);
|
||||
b+=k[2]+(((uint32_t)k[3])<<16);
|
||||
a+=k[0]+(((uint32_t)k[1])<<16);
|
||||
break;
|
||||
case 11: c+=((uint32_t)k8[10])<<16; /* fall through */
|
||||
case 10: c+=k[4];
|
||||
b+=k[2]+(((uint32_t)k[3])<<16);
|
||||
a+=k[0]+(((uint32_t)k[1])<<16);
|
||||
break;
|
||||
case 9 : c+=k8[8]; /* fall through */
|
||||
case 8 : b+=k[2]+(((uint32_t)k[3])<<16);
|
||||
a+=k[0]+(((uint32_t)k[1])<<16);
|
||||
break;
|
||||
case 7 : b+=((uint32_t)k8[6])<<16; /* fall through */
|
||||
case 6 : b+=k[2];
|
||||
a+=k[0]+(((uint32_t)k[1])<<16);
|
||||
break;
|
||||
case 5 : b+=k8[4]; /* fall through */
|
||||
case 4 : a+=k[0]+(((uint32_t)k[1])<<16);
|
||||
break;
|
||||
case 3 : a+=((uint32_t)k8[2])<<16; /* fall through */
|
||||
case 2 : a+=k[0];
|
||||
break;
|
||||
case 1 : a+=k8[0];
|
||||
break;
|
||||
case 0 : return c; /* zero length requires no mixing */
|
||||
}
|
||||
|
||||
} else { /* need to read the key one byte at a time */
|
||||
const uint8_t *k = (const uint8_t *)key;
|
||||
|
||||
/*--------------- all but the last block: affect some 32 bits of (a,b,c) */
|
||||
while (length > 12)
|
||||
{
|
||||
a += k[0];
|
||||
a += ((uint32_t)k[1])<<8;
|
||||
a += ((uint32_t)k[2])<<16;
|
||||
a += ((uint32_t)k[3])<<24;
|
||||
b += k[4];
|
||||
b += ((uint32_t)k[5])<<8;
|
||||
b += ((uint32_t)k[6])<<16;
|
||||
b += ((uint32_t)k[7])<<24;
|
||||
c += k[8];
|
||||
c += ((uint32_t)k[9])<<8;
|
||||
c += ((uint32_t)k[10])<<16;
|
||||
c += ((uint32_t)k[11])<<24;
|
||||
mix(a,b,c);
|
||||
length -= 12;
|
||||
k += 12;
|
||||
}
|
||||
|
||||
/*-------------------------------- last block: affect all 32 bits of (c) */
|
||||
switch(length) /* all the case statements fall through */
|
||||
{
|
||||
case 12: c+=((uint32_t)k[11])<<24;
|
||||
case 11: c+=((uint32_t)k[10])<<16;
|
||||
case 10: c+=((uint32_t)k[9])<<8;
|
||||
case 9 : c+=k[8];
|
||||
case 8 : b+=((uint32_t)k[7])<<24;
|
||||
case 7 : b+=((uint32_t)k[6])<<16;
|
||||
case 6 : b+=((uint32_t)k[5])<<8;
|
||||
case 5 : b+=k[4];
|
||||
case 4 : a+=((uint32_t)k[3])<<24;
|
||||
case 3 : a+=((uint32_t)k[2])<<16;
|
||||
case 2 : a+=((uint32_t)k[1])<<8;
|
||||
case 1 : a+=k[0];
|
||||
break;
|
||||
case 0 : return c;
|
||||
}
|
||||
}
|
||||
|
||||
final(a,b,c);
|
||||
return c;
|
||||
}
|
69
external/Jansson/memory.c
vendored
69
external/Jansson/memory.c
vendored
@ -1,69 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2014 Petri Lehtinen <petri@digip.org>
|
||||
* Copyright (c) 2011-2012 Basile Starynkevitch <basile@starynkevitch.net>
|
||||
*
|
||||
* Jansson is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MIT license. See LICENSE for details.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "jansson.h"
|
||||
#include "jansson_private.h"
|
||||
|
||||
/* C89 allows these to be macros */
|
||||
#undef malloc
|
||||
#undef free
|
||||
|
||||
/* memory function pointers */
|
||||
static json_malloc_t do_malloc = malloc;
|
||||
static json_free_t do_free = free;
|
||||
|
||||
void *jsonp_malloc(size_t size)
|
||||
{
|
||||
if(!size)
|
||||
return NULL;
|
||||
|
||||
return (*do_malloc)(size);
|
||||
}
|
||||
|
||||
void jsonp_free(void *ptr)
|
||||
{
|
||||
if(!ptr)
|
||||
return;
|
||||
|
||||
(*do_free)(ptr);
|
||||
}
|
||||
|
||||
char *jsonp_strdup(const char *str)
|
||||
{
|
||||
return jsonp_strndup(str, strlen(str));
|
||||
}
|
||||
|
||||
char *jsonp_strndup(const char *str, size_t len)
|
||||
{
|
||||
char *new_str;
|
||||
|
||||
new_str = jsonp_malloc(len + 1);
|
||||
if(!new_str)
|
||||
return NULL;
|
||||
|
||||
memcpy(new_str, str, len);
|
||||
new_str[len] = '\0';
|
||||
return new_str;
|
||||
}
|
||||
|
||||
void json_set_alloc_funcs(json_malloc_t malloc_fn, json_free_t free_fn)
|
||||
{
|
||||
do_malloc = malloc_fn;
|
||||
do_free = free_fn;
|
||||
}
|
||||
|
||||
void json_get_alloc_funcs(json_malloc_t *malloc_fn, json_free_t *free_fn)
|
||||
{
|
||||
if (malloc_fn)
|
||||
*malloc_fn = do_malloc;
|
||||
if (free_fn)
|
||||
*free_fn = do_free;
|
||||
}
|
871
external/Jansson/pack_unpack.c
vendored
871
external/Jansson/pack_unpack.c
vendored
@ -1,871 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2014 Petri Lehtinen <petri@digip.org>
|
||||
* Copyright (c) 2011-2012 Graeme Smecher <graeme.smecher@mail.mcgill.ca>
|
||||
*
|
||||
* Jansson is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the MIT license. See LICENSE for details.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include "jansson.h"
|
||||
#include "jansson_private.h"
|
||||
#include "utf.h"
|
||||
|
||||
typedef struct {
|
||||
int line;
|
||||
int column;
|
||||
size_t pos;
|
||||
char token;
|
||||
} token_t;
|
||||
|
||||
typedef struct {
|
||||
const char *start;
|
||||
const char *fmt;
|
||||
token_t prev_token;
|
||||
token_t token;
|
||||
token_t next_token;
|
||||
json_error_t *error;
|
||||
size_t flags;
|
||||
int line;
|
||||
int column;
|
||||
size_t pos;
|
||||
} scanner_t;
|
||||
|
||||
#define token(scanner) ((scanner)->token.token)
|
||||
|
||||
static const char * const type_names[] = {
|
||||
"object",
|
||||
"array",
|
||||
"string",
|
||||
"integer",
|
||||
"real",
|
||||
"true",
|
||||
"false",
|
||||
"null"
|
||||
};
|
||||
|
||||
#define type_name(x) type_names[json_typeof(x)]
|
||||
|
||||
static const char unpack_value_starters[] = "{[siIbfFOon";
|
||||
|
||||
static void scanner_init(scanner_t *s, json_error_t *error,
|
||||
size_t flags, const char *fmt)
|
||||
{
|
||||
s->error = error;
|
||||
s->flags = flags;
|
||||
s->fmt = s->start = fmt;
|
||||
memset(&s->prev_token, 0, sizeof(token_t));
|
||||
memset(&s->token, 0, sizeof(token_t));
|
||||
memset(&s->next_token, 0, sizeof(token_t));
|
||||
s->line = 1;
|
||||
s->column = 0;
|
||||
s->pos = 0;
|
||||
}
|
||||
|
||||
static void next_token(scanner_t *s)
|
||||
{
|
||||
const char *t;
|
||||
s->prev_token = s->token;
|
||||
|
||||
if(s->next_token.line) {
|
||||
s->token = s->next_token;
|
||||
s->next_token.line = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
t = s->fmt;
|
||||
s->column++;
|
||||
s->pos++;
|
||||
|
||||
/* skip space and ignored chars */
|
||||
while(*t == ' ' || *t == '\t' || *t == '\n' || *t == ',' || *t == ':') {
|
||||
if(*t == '\n') {
|
||||
s->line++;
|
||||
s->column = 1;
|
||||
}
|
||||
else
|
||||
s->column++;
|
||||
|
||||
s->pos++;
|
||||
t++;
|
||||
}
|
||||
|
||||
s->token.token = *t;
|
||||
s->token.line = s->line;
|
||||
s->token.column = s->column;
|
||||
s->token.pos = s->pos;
|
||||
|
||||
t++;
|
||||
s->fmt = t;
|
||||
}
|
||||
|
||||
static void prev_token(scanner_t *s)
|
||||
{
|
||||
s->next_token = s->token;
|
||||
s->token = s->prev_token;
|
||||
}
|
||||
|
||||
static void set_error(scanner_t *s, const char *source, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
|
||||
jsonp_error_vset(s->error, s->token.line, s->token.column, s->token.pos,
|
||||
fmt, ap);
|
||||
|
||||
jsonp_error_set_source(s->error, source);
|
||||
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
static json_t *pack(scanner_t *s, va_list *ap);
|
||||
|
||||
|
||||
/* ours will be set to 1 if jsonp_free() must be called for the result
|
||||
afterwards */
|
||||
static char *read_string(scanner_t *s, va_list *ap,
|
||||
const char *purpose, size_t *out_len, int *ours)
|
||||
{
|
||||
char t;
|
||||
strbuffer_t strbuff;
|
||||
const char *str;
|
||||
size_t length;
|
||||
|
||||
next_token(s);
|
||||
t = token(s);
|
||||
prev_token(s);
|
||||
|
||||
if(t != '#' && t != '%' && t != '+') {
|
||||
/* Optimize the simple case */
|
||||
str = va_arg(*ap, const char *);
|
||||
|
||||
if(!str) {
|
||||
set_error(s, "<args>", "NULL string argument");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
length = strlen(str);
|
||||
|
||||
if(!utf8_check_string(str, length)) {
|
||||
set_error(s, "<args>", "Invalid UTF-8 %s", purpose);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
*out_len = length;
|
||||
*ours = 0;
|
||||
return (char *)str;
|
||||
}
|
||||
|
||||
strbuffer_init(&strbuff);
|
||||
|
||||
while(1) {
|
||||
str = va_arg(*ap, const char *);
|
||||
if(!str) {
|
||||
set_error(s, "<args>", "NULL string argument");
|
||||
strbuffer_close(&strbuff);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
next_token(s);
|
||||
|
||||
if(token(s) == '#') {
|
||||
length = va_arg(*ap, int);
|
||||
}
|
||||
else if(token(s) == '%') {
|
||||
length = va_arg(*ap, size_t);
|
||||
}
|
||||
else {
|
||||
prev_token(s);
|
||||
length = strlen(str);
|
||||
}
|
||||
|
||||
if(strbuffer_append_bytes(&strbuff, str, length) == -1) {
|
||||
set_error(s, "<internal>", "Out of memory");
|
||||
strbuffer_close(&strbuff);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
next_token(s);
|
||||
if(token(s) != '+') {
|
||||
prev_token(s);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!utf8_check_string(strbuff.value, strbuff.length)) {
|
||||
set_error(s, "<args>", "Invalid UTF-8 %s", purpose);
|
||||
strbuffer_close(&strbuff);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
*out_len = strbuff.length;
|
||||
*ours = 1;
|
||||
return strbuffer_steal_value(&strbuff);
|
||||
}
|
||||
|
||||
static json_t *pack_object(scanner_t *s, va_list *ap)
|
||||
{
|
||||
json_t *object = json_object();
|
||||
next_token(s);
|
||||
|
||||
while(token(s) != '}') {
|
||||
char *key;
|
||||
size_t len;
|
||||
int ours;
|
||||
json_t *value;
|
||||
|
||||
if(!token(s)) {
|
||||
set_error(s, "<format>", "Unexpected end of format string");
|
||||
goto error;
|
||||
}
|
||||
|
||||
if(token(s) != 's') {
|
||||
set_error(s, "<format>", "Expected format 's', got '%c'", token(s));
|
||||
goto error;
|
||||
}
|
||||
|
||||
key = read_string(s, ap, "object key", &len, &ours);
|
||||
if(!key)
|
||||
goto error;
|
||||
|
||||
next_token(s);
|
||||
|
||||
value = pack(s, ap);
|
||||
if(!value) {
|
||||
if(ours)
|
||||
jsonp_free(key);
|
||||
|
||||
goto error;
|
||||
}
|
||||
|
||||
if(json_object_set_new_nocheck(object, key, value)) {
|
||||
set_error(s, "<internal>", "Unable to add key \"%s\"", key);
|
||||
if(ours)
|
||||
jsonp_free(key);
|
||||
|
||||
goto error;
|
||||
}
|
||||
|
||||
if(ours)
|
||||
jsonp_free(key);
|
||||
|
||||
next_token(s);
|
||||
}
|
||||
|
||||
return object;
|
||||
|
||||
error:
|
||||
json_decref(object);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static json_t *pack_array(scanner_t *s, va_list *ap)
|
||||
{
|
||||
json_t *array = json_array();
|
||||
next_token(s);
|
||||
|
||||
while(token(s) != ']') {
|
||||
json_t *value;
|
||||
|
||||
if(!token(s)) {
|
||||
set_error(s, "<format>", "Unexpected end of format string");
|
||||
goto error;
|
||||
}
|
||||
|
||||
value = pack(s, ap);
|
||||
if(!value)
|
||||
goto error;
|
||||
|
||||
if(json_array_append_new(array, value)) {
|
||||
set_error(s, "<internal>", "Unable to append to array");
|
||||
goto error;
|
||||
}
|
||||
|
||||
next_token(s);
|
||||
}
|
||||
return array;
|
||||
|
||||
error:
|
||||
json_decref(array);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static json_t *pack_string(scanner_t *s, va_list *ap)
|
||||
{
|
||||
char *str;
|
||||
size_t len;
|
||||
int ours;
|
||||
int nullable;
|
||||
|
||||
next_token(s);
|
||||
nullable = token(s) == '?';
|
||||
if (!nullable)
|
||||
prev_token(s);
|
||||
|
||||
str = read_string(s, ap, "string", &len, &ours);
|
||||
if (!str) {
|
||||
return nullable ? json_null() : NULL;
|
||||
} else if (ours) {
|
||||
return jsonp_stringn_nocheck_own(str, len);
|
||||
} else {
|
||||
return json_stringn_nocheck(str, len);
|
||||
}
|
||||
}
|
||||
|
||||
static json_t *pack(scanner_t *s, va_list *ap)
|
||||
{
|
||||
switch(token(s)) {
|
||||
case '{':
|
||||
return pack_object(s, ap);
|
||||
|
||||
case '[':
|
||||
return pack_array(s, ap);
|
||||
|
||||
case 's': /* string */
|
||||
return pack_string(s, ap);
|
||||
|
||||
case 'n': /* null */
|
||||
return json_null();
|
||||
|
||||
case 'b': /* boolean */
|
||||
return va_arg(*ap, int) ? json_true() : json_false();
|
||||
|
||||
case 'i': /* integer from int */
|
||||
return json_integer(va_arg(*ap, int));
|
||||
|
||||
case 'I': /* integer from json_int_t */
|
||||
return json_integer(va_arg(*ap, json_int_t));
|
||||
|
||||
case 'f': /* real */
|
||||
return json_real(va_arg(*ap, double));
|
||||
|
||||
case 'O': /* a json_t object; increments refcount */
|
||||
{
|
||||
int nullable;
|
||||
json_t *json;
|
||||
|
||||
next_token(s);
|
||||
nullable = token(s) == '?';
|
||||
if (!nullable)
|
||||
prev_token(s);
|
||||
|
||||
json = va_arg(*ap, json_t *);
|
||||
if (!json && nullable) {
|
||||
return json_null();
|
||||
} else {
|
||||
return json_incref(json);
|
||||
}
|
||||
}
|
||||
|
||||
case 'o': /* a json_t object; doesn't increment refcount */
|
||||
{
|
||||
int nullable;
|
||||
json_t *json;
|
||||
|
||||
next_token(s);
|
||||
nullable = token(s) == '?';
|
||||
if (!nullable)
|
||||
prev_token(s);
|
||||
|
||||
json = va_arg(*ap, json_t *);
|
||||
if (!json && nullable) {
|
||||
return json_null();
|
||||
} else {
|
||||
return json;
|
||||
}
|
||||
}
|
||||
|
||||
default:
|
||||
set_error(s, "<format>", "Unexpected format character '%c'",
|
||||
token(s));
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static int unpack(scanner_t *s, json_t *root, va_list *ap);
|
||||
|
||||
static int unpack_object(scanner_t *s, json_t *root, va_list *ap)
|
||||
{
|
||||
int ret = -1;
|
||||
int strict = 0;
|
||||
int gotopt = 0;
|
||||
|
||||
/* Use a set (emulated by a hashtable) to check that all object
|
||||
keys are accessed. Checking that the correct number of keys
|
||||
were accessed is not enough, as the same key can be unpacked
|
||||
multiple times.
|
||||
*/
|
||||
hashtable_t key_set;
|
||||
|
||||
if(hashtable_init(&key_set)) {
|
||||
set_error(s, "<internal>", "Out of memory");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(root && !json_is_object(root)) {
|
||||
set_error(s, "<validation>", "Expected object, got %s",
|
||||
type_name(root));
|
||||
goto out;
|
||||
}
|
||||
next_token(s);
|
||||
|
||||
while(token(s) != '}') {
|
||||
const char *key;
|
||||
json_t *value;
|
||||
int opt = 0;
|
||||
|
||||
if(strict != 0) {
|
||||
set_error(s, "<format>", "Expected '}' after '%c', got '%c'",
|
||||
(strict == 1 ? '!' : '*'), token(s));
|
||||
goto out;
|
||||
}
|
||||
|
||||
if(!token(s)) {
|
||||
set_error(s, "<format>", "Unexpected end of format string");
|
||||
goto out;
|
||||
}
|
||||
|
||||
if(token(s) == '!' || token(s) == '*') {
|
||||
strict = (token(s) == '!' ? 1 : -1);
|
||||
next_token(s);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(token(s) != 's') {
|
||||
set_error(s, "<format>", "Expected format 's', got '%c'", token(s));
|
||||
goto out;
|
||||
}
|
||||
|
||||
key = va_arg(*ap, const char *);
|
||||
if(!key) {
|
||||
set_error(s, "<args>", "NULL object key");
|
||||
goto out;
|
||||
}
|
||||
|
||||
next_token(s);
|
||||
|
||||
if(token(s) == '?') {
|
||||
opt = gotopt = 1;
|
||||
next_token(s);
|
||||
}
|
||||
|
||||
if(!root) {
|
||||
/* skipping */
|
||||
value = NULL;
|
||||
}
|
||||
else {
|
||||
value = json_object_get(root, key);
|
||||
if(!value && !opt) {
|
||||
set_error(s, "<validation>", "Object item not found: %s", key);
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
if(unpack(s, value, ap))
|
||||
goto out;
|
||||
|
||||
hashtable_set(&key_set, key, 0, json_null());
|
||||
next_token(s);
|
||||
}
|
||||
|
||||
if(strict == 0 && (s->flags & JSON_STRICT))
|
||||
strict = 1;
|
||||
|
||||
if(root && strict == 1) {
|
||||
/* We need to check that all non optional items have been parsed */
|
||||
const char *key;
|
||||
int have_unrecognized_keys = 0;
|
||||
strbuffer_t unrecognized_keys;
|
||||
json_t *value;
|
||||
long unpacked = 0;
|
||||
if (gotopt) {
|
||||
/* We have optional keys, we need to iter on each key */
|
||||
json_object_foreach(root, key, value) {
|
||||
if(!hashtable_get(&key_set, key)) {
|
||||
unpacked++;
|
||||
|
||||
/* Save unrecognized keys for the error message */
|
||||
if (!have_unrecognized_keys) {
|
||||
strbuffer_init(&unrecognized_keys);
|
||||
have_unrecognized_keys = 1;
|
||||
} else {
|
||||
strbuffer_append_bytes(&unrecognized_keys, ", ", 2);
|
||||
}
|
||||
strbuffer_append_bytes(&unrecognized_keys, key, strlen(key));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* No optional keys, we can just compare the number of items */
|
||||
unpacked = (long)json_object_size(root) - (long)key_set.size;
|
||||
}
|
||||
if (unpacked) {
|
||||
if (!gotopt) {
|
||||
/* Save unrecognized keys for the error message */
|
||||
json_object_foreach(root, key, value) {
|
||||
if(!hashtable_get(&key_set, key)) {
|
||||
if (!have_unrecognized_keys) {
|
||||
strbuffer_init(&unrecognized_keys);
|
||||
have_unrecognized_keys = 1;
|
||||
} else {
|
||||
strbuffer_append_bytes(&unrecognized_keys, ", ", 2);
|
||||
}
|
||||
strbuffer_append_bytes(&unrecognized_keys, key, strlen(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
set_error(s, "<validation>",
|
||||
"%li object item(s) left unpacked: %s",
|
||||
unpacked, strbuffer_value(&unrecognized_keys));
|
||||
strbuffer_close(&unrecognized_keys);
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
out:
|
||||
hashtable_close(&key_set);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int unpack_array(scanner_t *s, json_t *root, va_list *ap)
|
||||
{
|
||||
size_t i = 0;
|
||||
int strict = 0;
|
||||
|
||||
if(root && !json_is_array(root)) {
|
||||
set_error(s, "<validation>", "Expected array, got %s", type_name(root));
|
||||
return -1;
|
||||
}
|
||||
next_token(s);
|
||||
|
||||
while(token(s) != ']') {
|
||||
json_t *value;
|
||||
|
||||
if(strict != 0) {
|
||||
set_error(s, "<format>", "Expected ']' after '%c', got '%c'",
|
||||
(strict == 1 ? '!' : '*'),
|
||||
token(s));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(!token(s)) {
|
||||
set_error(s, "<format>", "Unexpected end of format string");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(token(s) == '!' || token(s) == '*') {
|
||||
strict = (token(s) == '!' ? 1 : -1);
|
||||
next_token(s);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!strchr(unpack_value_starters, token(s))) {
|
||||
set_error(s, "<format>", "Unexpected format character '%c'",
|
||||
token(s));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(!root) {
|
||||
/* skipping */
|
||||
value = NULL;
|
||||
}
|
||||
else {
|
||||
value = json_array_get(root, i);
|
||||
if(!value) {
|
||||
set_error(s, "<validation>", "Array index %lu out of range",
|
||||
(unsigned long)i);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if(unpack(s, value, ap))
|
||||
return -1;
|
||||
|
||||
next_token(s);
|
||||
i++;
|
||||
}
|
||||
|
||||
if(strict == 0 && (s->flags & JSON_STRICT))
|
||||
strict = 1;
|
||||
|
||||
if(root && strict == 1 && i != json_array_size(root)) {
|
||||
long diff = (long)json_array_size(root) - (long)i;
|
||||
set_error(s, "<validation>", "%li array item(s) left unpacked", diff);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int unpack(scanner_t *s, json_t *root, va_list *ap)
|
||||
{
|
||||
switch(token(s))
|
||||
{
|
||||
case '{':
|
||||
return unpack_object(s, root, ap);
|
||||
|
||||
case '[':
|
||||
return unpack_array(s, root, ap);
|
||||
|
||||
case 's':
|
||||
if(root && !json_is_string(root)) {
|
||||
set_error(s, "<validation>", "Expected string, got %s",
|
||||
type_name(root));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(!(s->flags & JSON_VALIDATE_ONLY)) {
|
||||
const char **str_target;
|
||||
size_t *len_target = NULL;
|
||||
|
||||
str_target = va_arg(*ap, const char **);
|
||||
if(!str_target) {
|
||||
set_error(s, "<args>", "NULL string argument");
|
||||
return -1;
|
||||
}
|
||||
|
||||
next_token(s);
|
||||
|
||||
if(token(s) == '%') {
|
||||
len_target = va_arg(*ap, size_t *);
|
||||
if(!len_target) {
|
||||
set_error(s, "<args>", "NULL string length argument");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
prev_token(s);
|
||||
|
||||
if(root) {
|
||||
*str_target = json_string_value(root);
|
||||
if(len_target)
|
||||
*len_target = json_string_length(root);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
||||
case 'i':
|
||||
if(root && !json_is_integer(root)) {
|
||||
set_error(s, "<validation>", "Expected integer, got %s",
|
||||
type_name(root));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(!(s->flags & JSON_VALIDATE_ONLY)) {
|
||||
int *target = va_arg(*ap, int*);
|
||||
if(root)
|
||||
*target = (int)json_integer_value(root);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
case 'I':
|
||||
if(root && !json_is_integer(root)) {
|
||||
set_error(s, "<validation>", "Expected integer, got %s",
|
||||
type_name(root));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(!(s->flags & JSON_VALIDATE_ONLY)) {
|
||||
json_int_t *target = va_arg(*ap, json_int_t*);
|
||||
if(root)
|
||||
*target = json_integer_value(root);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
case 'b':
|
||||
if(root && !json_is_boolean(root)) {
|
||||
set_error(s, "<validation>", "Expected true or false, got %s",
|
||||
type_name(root));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(!(s->flags & JSON_VALIDATE_ONLY)) {
|
||||
int *target = va_arg(*ap, int*);
|
||||
if(root)
|
||||
*target = json_is_true(root);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
case 'f':
|
||||
if(root && !json_is_real(root)) {
|
||||
set_error(s, "<validation>", "Expected real, got %s",
|
||||
type_name(root));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(!(s->flags & JSON_VALIDATE_ONLY)) {
|
||||
double *target = va_arg(*ap, double*);
|
||||
if(root)
|
||||
*target = json_real_value(root);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
case 'F':
|
||||
if(root && !json_is_number(root)) {
|
||||
set_error(s, "<validation>", "Expected real or integer, got %s",
|
||||
type_name(root));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(!(s->flags & JSON_VALIDATE_ONLY)) {
|
||||
double *target = va_arg(*ap, double*);
|
||||
if(root)
|
||||
*target = json_number_value(root);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
case 'O':
|
||||
if(root && !(s->flags & JSON_VALIDATE_ONLY))
|
||||
json_incref(root);
|
||||
/* Fall through */
|
||||
|
||||
case 'o':
|
||||
if(!(s->flags & JSON_VALIDATE_ONLY)) {
|
||||
json_t **target = va_arg(*ap, json_t**);
|
||||
if(root)
|
||||
*target = root;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
case 'n':
|
||||
/* Never assign, just validate */
|
||||
if(root && !json_is_null(root)) {
|
||||
set_error(s, "<validation>", "Expected null, got %s",
|
||||
type_name(root));
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
|
||||
default:
|
||||
set_error(s, "<format>", "Unexpected format character '%c'",
|
||||
token(s));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
json_t *json_vpack_ex(json_error_t *error, size_t flags,
|
||||
const char *fmt, va_list ap)
|
||||
{
|
||||
scanner_t s;
|
||||
va_list ap_copy;
|
||||
json_t *value;
|
||||
|
||||
if(!fmt || !*fmt) {
|
||||
jsonp_error_init(error, "<format>");
|
||||
jsonp_error_set(error, -1, -1, 0, "NULL or empty format string");
|
||||
return NULL;
|
||||
}
|
||||
jsonp_error_init(error, NULL);
|
||||
|
||||
scanner_init(&s, error, flags, fmt);
|
||||
next_token(&s);
|
||||
|
||||
va_copy(ap_copy, ap);
|
||||
value = pack(&s, &ap_copy);
|
||||
va_end(ap_copy);
|
||||
|
||||
if(!value)
|
||||
return NULL;
|
||||
|
||||
next_token(&s);
|
||||
if(token(&s)) {
|
||||
json_decref(value);
|
||||
set_error(&s, "<format>", "Garbage after format string");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
json_t *json_pack_ex(json_error_t *error, size_t flags, const char *fmt, ...)
|
||||
{
|
||||
json_t *value;
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
value = json_vpack_ex(error, flags, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
json_t *json_pack(const char *fmt, ...)
|
||||
{
|
||||
json_t *value;
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
value = json_vpack_ex(NULL, 0, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
int json_vunpack_ex(json_t *root, json_error_t *error, size_t flags,
|
||||
const char *fmt, va_list ap)
|
||||
{
|
||||
scanner_t s;
|
||||
va_list ap_copy;
|
||||
|
||||
if(!root) {
|
||||
jsonp_error_init(error, "<root>");
|
||||
jsonp_error_set(error, -1, -1, 0, "NULL root value");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(!fmt || !*fmt) {
|
||||
jsonp_error_init(error, "<format>");
|
||||
jsonp_error_set(error, -1, -1, 0, "NULL or empty format string");
|
||||
return -1;
|
||||
}
|
||||
jsonp_error_init(error, NULL);
|
||||
|
||||
scanner_init(&s, error, flags, fmt);
|
||||
next_token(&s);
|
||||
|
||||
va_copy(ap_copy, ap);
|
||||
if(unpack(&s, root, &ap_copy)) {
|
||||
va_end(ap_copy);
|
||||
return -1;
|
||||
}
|
||||
va_end(ap_copy);
|
||||
|
||||
next_token(&s);
|
||||
if(token(&s)) {
|
||||
set_error(&s, "<format>", "Garbage after format string");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int json_unpack_ex(json_t *root, json_error_t *error, size_t flags, const char *fmt, ...)
|
||||
{
|
||||
int ret;
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
ret = json_vunpack_ex(root, error, flags, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int json_unpack(json_t *root, const char *fmt, ...)
|
||||
{
|
||||
int ret;
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
ret = json_vunpack_ex(root, NULL, 0, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
return ret;
|
||||
}
|
111
external/Jansson/strbuffer.c
vendored
111
external/Jansson/strbuffer.c
vendored
@ -1,111 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2014 Petri Lehtinen <petri@digip.org>
|
||||
*
|
||||
* Jansson is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the MIT license. See LICENSE for details.
|
||||
*/
|
||||
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "jansson_private.h"
|
||||
#include "strbuffer.h"
|
||||
|
||||
#define STRBUFFER_MIN_SIZE 16
|
||||
#define STRBUFFER_FACTOR 2
|
||||
#define STRBUFFER_SIZE_MAX ((size_t)-1)
|
||||
|
||||
int strbuffer_init(strbuffer_t *strbuff)
|
||||
{
|
||||
strbuff->size = STRBUFFER_MIN_SIZE;
|
||||
strbuff->length = 0;
|
||||
|
||||
strbuff->value = jsonp_malloc(strbuff->size);
|
||||
if(!strbuff->value)
|
||||
return -1;
|
||||
|
||||
/* initialize to empty */
|
||||
strbuff->value[0] = '\0';
|
||||
return 0;
|
||||
}
|
||||
|
||||
void strbuffer_close(strbuffer_t *strbuff)
|
||||
{
|
||||
if(strbuff->value)
|
||||
jsonp_free(strbuff->value);
|
||||
|
||||
strbuff->size = 0;
|
||||
strbuff->length = 0;
|
||||
strbuff->value = NULL;
|
||||
}
|
||||
|
||||
void strbuffer_clear(strbuffer_t *strbuff)
|
||||
{
|
||||
strbuff->length = 0;
|
||||
strbuff->value[0] = '\0';
|
||||
}
|
||||
|
||||
const char *strbuffer_value(const strbuffer_t *strbuff)
|
||||
{
|
||||
return strbuff->value;
|
||||
}
|
||||
|
||||
char *strbuffer_steal_value(strbuffer_t *strbuff)
|
||||
{
|
||||
char *result = strbuff->value;
|
||||
strbuff->value = NULL;
|
||||
return result;
|
||||
}
|
||||
|
||||
int strbuffer_append_byte(strbuffer_t *strbuff, char byte)
|
||||
{
|
||||
return strbuffer_append_bytes(strbuff, &byte, 1);
|
||||
}
|
||||
|
||||
int strbuffer_append_bytes(strbuffer_t *strbuff, const char *data, size_t size)
|
||||
{
|
||||
if(size >= strbuff->size - strbuff->length)
|
||||
{
|
||||
size_t new_size;
|
||||
char *new_value;
|
||||
|
||||
/* avoid integer overflow */
|
||||
if (strbuff->size > STRBUFFER_SIZE_MAX / STRBUFFER_FACTOR
|
||||
|| size > STRBUFFER_SIZE_MAX - 1
|
||||
|| strbuff->length > STRBUFFER_SIZE_MAX - 1 - size)
|
||||
return -1;
|
||||
|
||||
new_size = max(strbuff->size * STRBUFFER_FACTOR,
|
||||
strbuff->length + size + 1);
|
||||
|
||||
new_value = jsonp_malloc(new_size);
|
||||
if(!new_value)
|
||||
return -1;
|
||||
|
||||
memcpy(new_value, strbuff->value, strbuff->length);
|
||||
|
||||
jsonp_free(strbuff->value);
|
||||
strbuff->value = new_value;
|
||||
strbuff->size = new_size;
|
||||
}
|
||||
|
||||
memcpy(strbuff->value + strbuff->length, data, size);
|
||||
strbuff->length += size;
|
||||
strbuff->value[strbuff->length] = '\0';
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
char strbuffer_pop(strbuffer_t *strbuff)
|
||||
{
|
||||
if(strbuff->length > 0) {
|
||||
char c = strbuff->value[--strbuff->length];
|
||||
strbuff->value[strbuff->length] = '\0';
|
||||
return c;
|
||||
}
|
||||
else
|
||||
return '\0';
|
||||
}
|
34
external/Jansson/strbuffer.h
vendored
34
external/Jansson/strbuffer.h
vendored
@ -1,34 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2014 Petri Lehtinen <petri@digip.org>
|
||||
*
|
||||
* Jansson is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the MIT license. See LICENSE for details.
|
||||
*/
|
||||
|
||||
#ifndef STRBUFFER_H
|
||||
#define STRBUFFER_H
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
typedef struct {
|
||||
char *value;
|
||||
size_t length; /* bytes used */
|
||||
size_t size; /* bytes allocated */
|
||||
} strbuffer_t;
|
||||
|
||||
int strbuffer_init(strbuffer_t *strbuff);
|
||||
void strbuffer_close(strbuffer_t *strbuff);
|
||||
|
||||
void strbuffer_clear(strbuffer_t *strbuff);
|
||||
|
||||
const char *strbuffer_value(const strbuffer_t *strbuff);
|
||||
|
||||
/* Steal the value and close the strbuffer */
|
||||
char *strbuffer_steal_value(strbuffer_t *strbuff);
|
||||
|
||||
int strbuffer_append_byte(strbuffer_t *strbuff, char byte);
|
||||
int strbuffer_append_bytes(strbuffer_t *strbuff, const char *data, size_t size);
|
||||
|
||||
char strbuffer_pop(strbuffer_t *strbuff);
|
||||
|
||||
#endif
|
145
external/Jansson/strconv.c
vendored
145
external/Jansson/strconv.c
vendored
@ -1,145 +0,0 @@
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#ifdef __MINGW32__
|
||||
#undef __NO_ISOCEXT /* ensure stdlib.h will declare prototypes for mingw own 'strtod' replacement, called '__strtod' */
|
||||
#endif
|
||||
#include "jansson_private.h"
|
||||
#include "strbuffer.h"
|
||||
|
||||
/* need jansson_private_config.h to get the correct snprintf */
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <jansson_private_config.h>
|
||||
#endif
|
||||
|
||||
#ifdef __MINGW32__
|
||||
#define strtod __strtod
|
||||
#endif
|
||||
|
||||
#if JSON_HAVE_LOCALECONV
|
||||
#include <locale.h>
|
||||
|
||||
/*
|
||||
- This code assumes that the decimal separator is exactly one
|
||||
character.
|
||||
|
||||
- If setlocale() is called by another thread between the call to
|
||||
localeconv() and the call to sprintf() or strtod(), the result may
|
||||
be wrong. setlocale() is not thread-safe and should not be used
|
||||
this way. Multi-threaded programs should use uselocale() instead.
|
||||
*/
|
||||
|
||||
static void to_locale(strbuffer_t *strbuffer)
|
||||
{
|
||||
const char *point;
|
||||
char *pos;
|
||||
|
||||
point = localeconv()->decimal_point;
|
||||
if(*point == '.') {
|
||||
/* No conversion needed */
|
||||
return;
|
||||
}
|
||||
|
||||
pos = strchr(strbuffer->value, '.');
|
||||
if(pos)
|
||||
*pos = *point;
|
||||
}
|
||||
|
||||
static void from_locale(char *buffer)
|
||||
{
|
||||
const char *point;
|
||||
char *pos;
|
||||
|
||||
point = localeconv()->decimal_point;
|
||||
if(*point == '.') {
|
||||
/* No conversion needed */
|
||||
return;
|
||||
}
|
||||
|
||||
pos = strchr(buffer, *point);
|
||||
if(pos)
|
||||
*pos = '.';
|
||||
}
|
||||
#endif
|
||||
|
||||
int jsonp_strtod(strbuffer_t *strbuffer, double *out)
|
||||
{
|
||||
double value;
|
||||
char *end;
|
||||
|
||||
#if JSON_HAVE_LOCALECONV
|
||||
to_locale(strbuffer);
|
||||
#endif
|
||||
|
||||
errno = 0;
|
||||
value = strtod(strbuffer->value, &end);
|
||||
assert(end == strbuffer->value + strbuffer->length);
|
||||
|
||||
if((value == HUGE_VAL || value == -HUGE_VAL) && errno == ERANGE) {
|
||||
/* Overflow */
|
||||
return -1;
|
||||
}
|
||||
|
||||
*out = value;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int jsonp_dtostr(char *buffer, size_t size, double value, int precision)
|
||||
{
|
||||
int ret;
|
||||
char *start, *end;
|
||||
size_t length;
|
||||
|
||||
if (precision == 0)
|
||||
precision = 17;
|
||||
|
||||
ret = snprintf(buffer, size, "%.*g", precision, value);
|
||||
if(ret < 0)
|
||||
return -1;
|
||||
|
||||
length = (size_t)ret;
|
||||
if(length >= size)
|
||||
return -1;
|
||||
|
||||
#if JSON_HAVE_LOCALECONV
|
||||
from_locale(buffer);
|
||||
#endif
|
||||
|
||||
/* Make sure there's a dot or 'e' in the output. Otherwise
|
||||
a real is converted to an integer when decoding */
|
||||
if(strchr(buffer, '.') == NULL &&
|
||||
strchr(buffer, 'e') == NULL)
|
||||
{
|
||||
if(length + 3 >= size) {
|
||||
/* No space to append ".0" */
|
||||
return -1;
|
||||
}
|
||||
buffer[length] = '.';
|
||||
buffer[length + 1] = '0';
|
||||
buffer[length + 2] = '\0';
|
||||
length += 2;
|
||||
}
|
||||
|
||||
/* Remove leading '+' from positive exponent. Also remove leading
|
||||
zeros from exponents (added by some printf() implementations) */
|
||||
start = strchr(buffer, 'e');
|
||||
if(start) {
|
||||
start++;
|
||||
end = start + 1;
|
||||
|
||||
if(*start == '-')
|
||||
start++;
|
||||
|
||||
while(*end == '0')
|
||||
end++;
|
||||
|
||||
if(end != start) {
|
||||
memmove(start, end, length - (size_t)(end - buffer));
|
||||
length -= (size_t)(end - start);
|
||||
}
|
||||
}
|
||||
|
||||
return (int)length;
|
||||
}
|
187
external/Jansson/utf.c
vendored
187
external/Jansson/utf.c
vendored
@ -1,187 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2014 Petri Lehtinen <petri@digip.org>
|
||||
*
|
||||
* Jansson is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the MIT license. See LICENSE for details.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include "utf.h"
|
||||
|
||||
int utf8_encode(int32_t codepoint, char *buffer, size_t *size)
|
||||
{
|
||||
if(codepoint < 0)
|
||||
return -1;
|
||||
else if(codepoint < 0x80)
|
||||
{
|
||||
buffer[0] = (char)codepoint;
|
||||
*size = 1;
|
||||
}
|
||||
else if(codepoint < 0x800)
|
||||
{
|
||||
buffer[0] = 0xC0 + ((codepoint & 0x7C0) >> 6);
|
||||
buffer[1] = 0x80 + ((codepoint & 0x03F));
|
||||
*size = 2;
|
||||
}
|
||||
else if(codepoint < 0x10000)
|
||||
{
|
||||
buffer[0] = 0xE0 + ((codepoint & 0xF000) >> 12);
|
||||
buffer[1] = 0x80 + ((codepoint & 0x0FC0) >> 6);
|
||||
buffer[2] = 0x80 + ((codepoint & 0x003F));
|
||||
*size = 3;
|
||||
}
|
||||
else if(codepoint <= 0x10FFFF)
|
||||
{
|
||||
buffer[0] = 0xF0 + ((codepoint & 0x1C0000) >> 18);
|
||||
buffer[1] = 0x80 + ((codepoint & 0x03F000) >> 12);
|
||||
buffer[2] = 0x80 + ((codepoint & 0x000FC0) >> 6);
|
||||
buffer[3] = 0x80 + ((codepoint & 0x00003F));
|
||||
*size = 4;
|
||||
}
|
||||
else
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t utf8_check_first(char byte)
|
||||
{
|
||||
unsigned char u = (unsigned char)byte;
|
||||
|
||||
if(u < 0x80)
|
||||
return 1;
|
||||
|
||||
if(0x80 <= u && u <= 0xBF) {
|
||||
/* second, third or fourth byte of a multi-byte
|
||||
sequence, i.e. a "continuation byte" */
|
||||
return 0;
|
||||
}
|
||||
else if(u == 0xC0 || u == 0xC1) {
|
||||
/* overlong encoding of an ASCII byte */
|
||||
return 0;
|
||||
}
|
||||
else if(0xC2 <= u && u <= 0xDF) {
|
||||
/* 2-byte sequence */
|
||||
return 2;
|
||||
}
|
||||
|
||||
else if(0xE0 <= u && u <= 0xEF) {
|
||||
/* 3-byte sequence */
|
||||
return 3;
|
||||
}
|
||||
else if(0xF0 <= u && u <= 0xF4) {
|
||||
/* 4-byte sequence */
|
||||
return 4;
|
||||
}
|
||||
else { /* u >= 0xF5 */
|
||||
/* Restricted (start of 4-, 5- or 6-byte sequence) or invalid
|
||||
UTF-8 */
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
size_t utf8_check_full(const char *buffer, size_t size, int32_t *codepoint)
|
||||
{
|
||||
size_t i;
|
||||
int32_t value = 0;
|
||||
unsigned char u = (unsigned char)buffer[0];
|
||||
|
||||
if(size == 2)
|
||||
{
|
||||
value = u & 0x1F;
|
||||
}
|
||||
else if(size == 3)
|
||||
{
|
||||
value = u & 0xF;
|
||||
}
|
||||
else if(size == 4)
|
||||
{
|
||||
value = u & 0x7;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
|
||||
for(i = 1; i < size; i++)
|
||||
{
|
||||
u = (unsigned char)buffer[i];
|
||||
|
||||
if(u < 0x80 || u > 0xBF) {
|
||||
/* not a continuation byte */
|
||||
return 0;
|
||||
}
|
||||
|
||||
value = (value << 6) + (u & 0x3F);
|
||||
}
|
||||
|
||||
if(value > 0x10FFFF) {
|
||||
/* not in Unicode range */
|
||||
return 0;
|
||||
}
|
||||
|
||||
else if(0xD800 <= value && value <= 0xDFFF) {
|
||||
/* invalid code point (UTF-16 surrogate halves) */
|
||||
return 0;
|
||||
}
|
||||
|
||||
else if((size == 2 && value < 0x80) ||
|
||||
(size == 3 && value < 0x800) ||
|
||||
(size == 4 && value < 0x10000)) {
|
||||
/* overlong encoding */
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(codepoint)
|
||||
*codepoint = value;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
const char *utf8_iterate(const char *buffer, size_t bufsize, int32_t *codepoint)
|
||||
{
|
||||
size_t count;
|
||||
int32_t value;
|
||||
|
||||
if(!bufsize)
|
||||
return buffer;
|
||||
|
||||
count = utf8_check_first(buffer[0]);
|
||||
if(count <= 0)
|
||||
return NULL;
|
||||
|
||||
if(count == 1)
|
||||
value = (unsigned char)buffer[0];
|
||||
else
|
||||
{
|
||||
if(count > bufsize || !utf8_check_full(buffer, count, &value))
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(codepoint)
|
||||
*codepoint = value;
|
||||
|
||||
return buffer + count;
|
||||
}
|
||||
|
||||
int utf8_check_string(const char *string, size_t length)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for(i = 0; i < length; i++)
|
||||
{
|
||||
size_t count = utf8_check_first(string[i]);
|
||||
if(count == 0)
|
||||
return 0;
|
||||
else if(count > 1)
|
||||
{
|
||||
if(count > length - i)
|
||||
return 0;
|
||||
|
||||
if(!utf8_check_full(&string[i], count, NULL))
|
||||
return 0;
|
||||
|
||||
i += count - 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
27
external/Jansson/utf.h
vendored
27
external/Jansson/utf.h
vendored
@ -1,27 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2014 Petri Lehtinen <petri@digip.org>
|
||||
*
|
||||
* Jansson is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the MIT license. See LICENSE for details.
|
||||
*/
|
||||
|
||||
#ifndef UTF_H
|
||||
#define UTF_H
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <jansson_private_config.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STDINT_H
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
int utf8_encode(int32_t codepoint, char *buffer, size_t *size);
|
||||
|
||||
size_t utf8_check_first(char byte);
|
||||
size_t utf8_check_full(const char *buffer, size_t size, int32_t *codepoint);
|
||||
const char *utf8_iterate(const char *buffer, size_t size, int32_t *codepoint);
|
||||
|
||||
int utf8_check_string(const char *string, size_t length);
|
||||
|
||||
#endif
|
1048
external/Jansson/value.c
vendored
1048
external/Jansson/value.c
vendored
File diff suppressed because it is too large
Load Diff
0
external/LibIRC/CMakeLists.txt
vendored
0
external/LibIRC/CMakeLists.txt
vendored
482
external/LibIRC/LICENSE
vendored
482
external/LibIRC/LICENSE
vendored
@ -1,482 +0,0 @@
|
||||
GNU LIBRARY GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1991 Free Software Foundation, Inc.
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
[This is the first released version of the library GPL. It is
|
||||
numbered 2 because it goes with version 2 of the ordinary GPL.]
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
Licenses are intended to guarantee your freedom to share and change
|
||||
free software--to make sure the software is free for all its users.
|
||||
|
||||
This license, the Library General Public License, applies to some
|
||||
specially designated Free Software Foundation software, and to any
|
||||
other libraries whose authors decide to use it. You can use it for
|
||||
your libraries, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if
|
||||
you distribute copies of the library, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of the library, whether gratis
|
||||
or for a fee, you must give the recipients all the rights that we gave
|
||||
you. You must make sure that they, too, receive or can get the source
|
||||
code. If you link a program with the library, you must provide
|
||||
complete object files to the recipients so that they can relink them
|
||||
with the library, after making changes to the library and recompiling
|
||||
it. And you must show them these terms so they know their rights.
|
||||
|
||||
Our method of protecting your rights has two steps: (1) copyright
|
||||
the library, and (2) offer you this license which gives you legal
|
||||
permission to copy, distribute and/or modify the library.
|
||||
|
||||
Also, for each distributor's protection, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
library. If the library is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original
|
||||
version, so that any problems introduced by others will not reflect on
|
||||
the original authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that companies distributing free
|
||||
software will individually obtain patent licenses, thus in effect
|
||||
transforming the program into proprietary software. To prevent this,
|
||||
we have made it clear that any patent must be licensed for everyone's
|
||||
free use or not licensed at all.
|
||||
|
||||
Most GNU software, including some libraries, is covered by the ordinary
|
||||
GNU General Public License, which was designed for utility programs. This
|
||||
license, the GNU Library General Public License, applies to certain
|
||||
designated libraries. This license is quite different from the ordinary
|
||||
one; be sure to read it in full, and don't assume that anything in it is
|
||||
the same as in the ordinary license.
|
||||
|
||||
The reason we have a separate public license for some libraries is that
|
||||
they blur the distinction we usually make between modifying or adding to a
|
||||
program and simply using it. Linking a program with a library, without
|
||||
changing the library, is in some sense simply using the library, and is
|
||||
analogous to running a utility program or application program. However, in
|
||||
a textual and legal sense, the linked executable is a combined work, a
|
||||
derivative of the original library, and the ordinary General Public License
|
||||
treats it as such.
|
||||
|
||||
Because of this blurred distinction, using the ordinary General
|
||||
Public License for libraries did not effectively promote software
|
||||
sharing, because most developers did not use the libraries. We
|
||||
concluded that weaker conditions might promote sharing better.
|
||||
|
||||
However, unrestricted linking of non-free programs would deprive the
|
||||
users of those programs of all benefit from the free status of the
|
||||
libraries themselves. This Library General Public License is intended to
|
||||
permit developers of non-free programs to use free libraries, while
|
||||
preserving your freedom as a user of such programs to change the free
|
||||
libraries that are incorporated in them. (We have not seen how to achieve
|
||||
this as regards changes in header files, but we have achieved it as regards
|
||||
changes in the actual functions of the Library.) The hope is that this
|
||||
will lead to faster development of free libraries.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow. Pay close attention to the difference between a
|
||||
"work based on the library" and a "work that uses the library". The
|
||||
former contains code derived from the library, while the latter only
|
||||
works together with the library.
|
||||
|
||||
Note that it is possible for a library to be covered by the ordinary
|
||||
General Public License rather than by this special one.
|
||||
|
||||
GNU LIBRARY GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License Agreement applies to any software library which
|
||||
contains a notice placed by the copyright holder or other authorized
|
||||
party saying it may be distributed under the terms of this Library
|
||||
General Public License (also called "this License"). Each licensee is
|
||||
addressed as "you".
|
||||
|
||||
A "library" means a collection of software functions and/or data
|
||||
prepared so as to be conveniently linked with application programs
|
||||
(which use some of those functions and data) to form executables.
|
||||
|
||||
The "Library", below, refers to any such software library or work
|
||||
which has been distributed under these terms. A "work based on the
|
||||
Library" means either the Library or any derivative work under
|
||||
copyright law: that is to say, a work containing the Library or a
|
||||
portion of it, either verbatim or with modifications and/or translated
|
||||
straightforwardly into another language. (Hereinafter, translation is
|
||||
included without limitation in the term "modification".)
|
||||
|
||||
"Source code" for a work means the preferred form of the work for
|
||||
making modifications to it. For a library, complete source code means
|
||||
all the source code for all modules it contains, plus any associated
|
||||
interface definition files, plus the scripts used to control compilation
|
||||
and installation of the library.
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running a program using the Library is not restricted, and output from
|
||||
such a program is covered only if its contents constitute a work based
|
||||
on the Library (independent of the use of the Library in a tool for
|
||||
writing it). Whether that is true depends on what the Library does
|
||||
and what the program that uses the Library does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Library's
|
||||
complete source code as you receive it, in any medium, provided that
|
||||
you conspicuously and appropriately publish on each copy an
|
||||
appropriate copyright notice and disclaimer of warranty; keep intact
|
||||
all the notices that refer to this License and to the absence of any
|
||||
warranty; and distribute a copy of this License along with the
|
||||
Library.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy,
|
||||
and you may at your option offer warranty protection in exchange for a
|
||||
fee.
|
||||
|
||||
2. You may modify your copy or copies of the Library or any portion
|
||||
of it, thus forming a work based on the Library, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) The modified work must itself be a software library.
|
||||
|
||||
b) You must cause the files modified to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
c) You must cause the whole of the work to be licensed at no
|
||||
charge to all third parties under the terms of this License.
|
||||
|
||||
d) If a facility in the modified Library refers to a function or a
|
||||
table of data to be supplied by an application program that uses
|
||||
the facility, other than as an argument passed when the facility
|
||||
is invoked, then you must make a good faith effort to ensure that,
|
||||
in the event an application does not supply such function or
|
||||
table, the facility still operates, and performs whatever part of
|
||||
its purpose remains meaningful.
|
||||
|
||||
(For example, a function in a library to compute square roots has
|
||||
a purpose that is entirely well-defined independent of the
|
||||
application. Therefore, Subsection 2d requires that any
|
||||
application-supplied function or table used by this function must
|
||||
be optional: if the application does not supply it, the square
|
||||
root function must still compute square roots.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Library,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Library, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote
|
||||
it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Library.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Library
|
||||
with the Library (or with a work based on the Library) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may opt to apply the terms of the ordinary GNU General Public
|
||||
License instead of this License to a given copy of the Library. To do
|
||||
this, you must alter all the notices that refer to this License, so
|
||||
that they refer to the ordinary GNU General Public License, version 2,
|
||||
instead of to this License. (If a newer version than version 2 of the
|
||||
ordinary GNU General Public License has appeared, then you can specify
|
||||
that version instead if you wish.) Do not make any other change in
|
||||
these notices.
|
||||
|
||||
Once this change is made in a given copy, it is irreversible for
|
||||
that copy, so the ordinary GNU General Public License applies to all
|
||||
subsequent copies and derivative works made from that copy.
|
||||
|
||||
This option is useful when you wish to copy part of the code of
|
||||
the Library into a program that is not a library.
|
||||
|
||||
4. You may copy and distribute the Library (or a portion or
|
||||
derivative of it, under Section 2) in object code or executable form
|
||||
under the terms of Sections 1 and 2 above provided that you accompany
|
||||
it with the complete corresponding machine-readable source code, which
|
||||
must be distributed under the terms of Sections 1 and 2 above on a
|
||||
medium customarily used for software interchange.
|
||||
|
||||
If distribution of object code is made by offering access to copy
|
||||
from a designated place, then offering equivalent access to copy the
|
||||
source code from the same place satisfies the requirement to
|
||||
distribute the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
5. A program that contains no derivative of any portion of the
|
||||
Library, but is designed to work with the Library by being compiled or
|
||||
linked with it, is called a "work that uses the Library". Such a
|
||||
work, in isolation, is not a derivative work of the Library, and
|
||||
therefore falls outside the scope of this License.
|
||||
|
||||
However, linking a "work that uses the Library" with the Library
|
||||
creates an executable that is a derivative of the Library (because it
|
||||
contains portions of the Library), rather than a "work that uses the
|
||||
library". The executable is therefore covered by this License.
|
||||
Section 6 states terms for distribution of such executables.
|
||||
|
||||
When a "work that uses the Library" uses material from a header file
|
||||
that is part of the Library, the object code for the work may be a
|
||||
derivative work of the Library even though the source code is not.
|
||||
Whether this is true is especially significant if the work can be
|
||||
linked without the Library, or if the work is itself a library. The
|
||||
threshold for this to be true is not precisely defined by law.
|
||||
|
||||
If such an object file uses only numerical parameters, data
|
||||
structure layouts and accessors, and small macros and small inline
|
||||
functions (ten lines or less in length), then the use of the object
|
||||
file is unrestricted, regardless of whether it is legally a derivative
|
||||
work. (Executables containing this object code plus portions of the
|
||||
Library will still fall under Section 6.)
|
||||
|
||||
Otherwise, if the work is a derivative of the Library, you may
|
||||
distribute the object code for the work under the terms of Section 6.
|
||||
Any executables containing that work also fall under Section 6,
|
||||
whether or not they are linked directly with the Library itself.
|
||||
|
||||
6. As an exception to the Sections above, you may also compile or
|
||||
link a "work that uses the Library" with the Library to produce a
|
||||
work containing portions of the Library, and distribute that work
|
||||
under terms of your choice, provided that the terms permit
|
||||
modification of the work for the customer's own use and reverse
|
||||
engineering for debugging such modifications.
|
||||
|
||||
You must give prominent notice with each copy of the work that the
|
||||
Library is used in it and that the Library and its use are covered by
|
||||
this License. You must supply a copy of this License. If the work
|
||||
during execution displays copyright notices, you must include the
|
||||
copyright notice for the Library among them, as well as a reference
|
||||
directing the user to the copy of this License. Also, you must do one
|
||||
of these things:
|
||||
|
||||
a) Accompany the work with the complete corresponding
|
||||
machine-readable source code for the Library including whatever
|
||||
changes were used in the work (which must be distributed under
|
||||
Sections 1 and 2 above); and, if the work is an executable linked
|
||||
with the Library, with the complete machine-readable "work that
|
||||
uses the Library", as object code and/or source code, so that the
|
||||
user can modify the Library and then relink to produce a modified
|
||||
executable containing the modified Library. (It is understood
|
||||
that the user who changes the contents of definitions files in the
|
||||
Library will not necessarily be able to recompile the application
|
||||
to use the modified definitions.)
|
||||
|
||||
b) Accompany the work with a written offer, valid for at
|
||||
least three years, to give the same user the materials
|
||||
specified in Subsection 6a, above, for a charge no more
|
||||
than the cost of performing this distribution.
|
||||
|
||||
c) If distribution of the work is made by offering access to copy
|
||||
from a designated place, offer equivalent access to copy the above
|
||||
specified materials from the same place.
|
||||
|
||||
d) Verify that the user has already received a copy of these
|
||||
materials or that you have already sent this user a copy.
|
||||
|
||||
For an executable, the required form of the "work that uses the
|
||||
Library" must include any data and utility programs needed for
|
||||
reproducing the executable from it. However, as a special exception,
|
||||
the source code distributed need not include anything that is normally
|
||||
distributed (in either source or binary form) with the major
|
||||
components (compiler, kernel, and so on) of the operating system on
|
||||
which the executable runs, unless that component itself accompanies
|
||||
the executable.
|
||||
|
||||
It may happen that this requirement contradicts the license
|
||||
restrictions of other proprietary libraries that do not normally
|
||||
accompany the operating system. Such a contradiction means you cannot
|
||||
use both them and the Library together in an executable that you
|
||||
distribute.
|
||||
|
||||
7. You may place library facilities that are a work based on the
|
||||
Library side-by-side in a single library together with other library
|
||||
facilities not covered by this License, and distribute such a combined
|
||||
library, provided that the separate distribution of the work based on
|
||||
the Library and of the other library facilities is otherwise
|
||||
permitted, and provided that you do these two things:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work
|
||||
based on the Library, uncombined with any other library
|
||||
facilities. This must be distributed under the terms of the
|
||||
Sections above.
|
||||
|
||||
b) Give prominent notice with the combined library of the fact
|
||||
that part of it is a work based on the Library, and explaining
|
||||
where to find the accompanying uncombined form of the same work.
|
||||
|
||||
8. You may not copy, modify, sublicense, link with, or distribute
|
||||
the Library except as expressly provided under this License. Any
|
||||
attempt otherwise to copy, modify, sublicense, link with, or
|
||||
distribute the Library is void, and will automatically terminate your
|
||||
rights under this License. However, parties who have received copies,
|
||||
or rights, from you under this License will not have their licenses
|
||||
terminated so long as such parties remain in full compliance.
|
||||
|
||||
9. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Library or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Library (or any work based on the
|
||||
Library), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Library or works based on it.
|
||||
|
||||
10. Each time you redistribute the Library (or any work based on the
|
||||
Library), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute, link with or modify the Library
|
||||
subject to these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
11. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Library at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Library by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Library.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under any
|
||||
particular circumstance, the balance of the section is intended to apply,
|
||||
and the section as a whole is intended to apply in other circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
12. If the distribution and/or use of the Library is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Library under this License may add
|
||||
an explicit geographical distribution limitation excluding those countries,
|
||||
so that distribution is permitted only in or among countries not thus
|
||||
excluded. In such case, this License incorporates the limitation as if
|
||||
written in the body of this License.
|
||||
|
||||
13. The Free Software Foundation may publish revised and/or new
|
||||
versions of the Library General Public License from time to time.
|
||||
Such new versions will be similar in spirit to the present version,
|
||||
but may differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Library
|
||||
specifies a version number of this License which applies to it and
|
||||
"any later version", you have the option of following the terms and
|
||||
conditions either of that version or of any later version published by
|
||||
the Free Software Foundation. If the Library does not specify a
|
||||
license version number, you may choose any version ever published by
|
||||
the Free Software Foundation.
|
||||
|
||||
14. If you wish to incorporate parts of the Library into other free
|
||||
programs whose distribution conditions are incompatible with these,
|
||||
write to the author to ask for permission. For software which is
|
||||
copyrighted by the Free Software Foundation, write to the Free
|
||||
Software Foundation; we sometimes make exceptions for this. Our
|
||||
decision will be guided by the two goals of preserving the free status
|
||||
of all derivatives of our free software and of promoting the sharing
|
||||
and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
|
||||
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
|
||||
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
|
||||
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
|
||||
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
|
||||
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
|
||||
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
|
||||
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
|
||||
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
|
||||
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
|
||||
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
|
||||
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
|
||||
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
|
||||
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
|
||||
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||
DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
Appendix: How to Apply These Terms to Your New Libraries
|
||||
|
||||
If you develop a new library, and you want it to be of the greatest
|
||||
possible use to the public, we recommend making it free software that
|
||||
everyone can redistribute and change. You can do so by permitting
|
||||
redistribution under these terms (or, alternatively, under the terms of the
|
||||
ordinary General Public License).
|
||||
|
||||
To apply these terms, attach the following notices to the library. It is
|
||||
safest to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least the
|
||||
"copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the library's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||
MA 02111-1307, USA
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the library, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the
|
||||
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1990
|
||||
Ty Coon, President of Vice
|
||||
|
||||
That's all there is to it!
|
388
external/LibIRC/colors.c
vendored
388
external/LibIRC/colors.c
vendored
@ -1,388 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2012 George Yunaev gyunaev@ulduzsoft.com
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*/
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
#define LIBIRC_COLORPARSER_BOLD (1<<1)
|
||||
#define LIBIRC_COLORPARSER_UNDERLINE (1<<2)
|
||||
#define LIBIRC_COLORPARSER_REVERSE (1<<3)
|
||||
#define LIBIRC_COLORPARSER_COLOR (1<<4)
|
||||
|
||||
#define LIBIRC_COLORPARSER_MAXCOLORS 15
|
||||
|
||||
|
||||
static const char * color_replacement_table[] =
|
||||
{
|
||||
"WHITE",
|
||||
"BLACK",
|
||||
"DARKBLUE",
|
||||
"DARKGREEN",
|
||||
"RED",
|
||||
"BROWN",
|
||||
"PURPLE",
|
||||
"OLIVE",
|
||||
"YELLOW",
|
||||
"GREEN",
|
||||
"TEAL",
|
||||
"CYAN",
|
||||
"BLUE",
|
||||
"MAGENTA",
|
||||
"DARKGRAY",
|
||||
"LIGHTGRAY",
|
||||
0
|
||||
};
|
||||
|
||||
|
||||
static inline void libirc_colorparser_addorcat (char ** destline, unsigned int * destlen, const char * str)
|
||||
{
|
||||
unsigned int len = strlen(str);
|
||||
|
||||
if ( *destline )
|
||||
{
|
||||
strcpy (*destline, str);
|
||||
*destline += len;
|
||||
}
|
||||
else
|
||||
*destlen += len;
|
||||
}
|
||||
|
||||
|
||||
static void libirc_colorparser_applymask (unsigned int * mask,
|
||||
char ** destline, unsigned int * destlen,
|
||||
unsigned int bitmask, const char * start, const char * end)
|
||||
{
|
||||
if ( (*mask & bitmask) != 0 )
|
||||
{
|
||||
*mask &= ~bitmask;
|
||||
libirc_colorparser_addorcat (destline, destlen, end);
|
||||
}
|
||||
else
|
||||
{
|
||||
*mask |= bitmask;
|
||||
libirc_colorparser_addorcat (destline, destlen, start);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void libirc_colorparser_applycolor (unsigned int * mask,
|
||||
char ** destline, unsigned int * destlen,
|
||||
unsigned int colorid, unsigned int bgcolorid)
|
||||
{
|
||||
const char * end = "[/COLOR]";
|
||||
char startbuf[64];
|
||||
|
||||
if ( bgcolorid != 0 )
|
||||
sprintf (startbuf, "[COLOR=%s/%s]", color_replacement_table[colorid], color_replacement_table[bgcolorid]);
|
||||
else
|
||||
sprintf (startbuf, "[COLOR=%s]", color_replacement_table[colorid]);
|
||||
|
||||
if ( (*mask & LIBIRC_COLORPARSER_COLOR) != 0 )
|
||||
libirc_colorparser_addorcat (destline, destlen, end);
|
||||
|
||||
*mask |= LIBIRC_COLORPARSER_COLOR;
|
||||
libirc_colorparser_addorcat (destline, destlen, startbuf);
|
||||
}
|
||||
|
||||
|
||||
static void libirc_colorparser_closetags (unsigned int * mask,
|
||||
char ** destline, unsigned int * destlen)
|
||||
{
|
||||
if ( *mask & LIBIRC_COLORPARSER_BOLD )
|
||||
libirc_colorparser_applymask (mask, destline, destlen, LIBIRC_COLORPARSER_BOLD, 0, "[/B]");
|
||||
|
||||
if ( *mask & LIBIRC_COLORPARSER_UNDERLINE )
|
||||
libirc_colorparser_applymask (mask, destline, destlen, LIBIRC_COLORPARSER_UNDERLINE, 0, "[/U]");
|
||||
|
||||
if ( *mask & LIBIRC_COLORPARSER_REVERSE )
|
||||
libirc_colorparser_applymask (mask, destline, destlen, LIBIRC_COLORPARSER_REVERSE, 0, "[/I]");
|
||||
|
||||
if ( *mask & LIBIRC_COLORPARSER_COLOR )
|
||||
libirc_colorparser_applymask (mask, destline, destlen, LIBIRC_COLORPARSER_COLOR, 0, "[/COLOR]");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* IRC to [code] color conversion. Or strip.
|
||||
*/
|
||||
static char * libirc_colorparser_irc2code (const char * source, int strip)
|
||||
{
|
||||
unsigned int mask = 0, destlen = 0;
|
||||
char * destline = 0, *d = 0;
|
||||
const char *p;
|
||||
int current_bg = 0;
|
||||
|
||||
/*
|
||||
* There will be two passes. First pass calculates the total length of
|
||||
* the destination string. The second pass allocates memory for the string,
|
||||
* and fills it.
|
||||
*/
|
||||
while ( destline == 0 ) // destline will be set after the 2nd pass
|
||||
{
|
||||
if ( destlen > 0 )
|
||||
{
|
||||
// This is the 2nd pass; allocate memory.
|
||||
if ( (destline = malloc (destlen)) == 0 )
|
||||
return 0;
|
||||
|
||||
d = destline;
|
||||
}
|
||||
|
||||
for ( p = source; *p; p++ )
|
||||
{
|
||||
switch (*p)
|
||||
{
|
||||
case 0x02: // bold
|
||||
if ( strip )
|
||||
continue;
|
||||
|
||||
libirc_colorparser_applymask (&mask, &d, &destlen, LIBIRC_COLORPARSER_BOLD, "[B]", "[/B]");
|
||||
break;
|
||||
|
||||
case 0x1F: // underline
|
||||
if ( strip )
|
||||
continue;
|
||||
|
||||
libirc_colorparser_applymask (&mask, &d, &destlen, LIBIRC_COLORPARSER_UNDERLINE, "[U]", "[/U]");
|
||||
break;
|
||||
|
||||
case 0x16: // reverse
|
||||
if ( strip )
|
||||
continue;
|
||||
|
||||
libirc_colorparser_applymask (&mask, &d, &destlen, LIBIRC_COLORPARSER_REVERSE, "[I]", "[/I]");
|
||||
break;
|
||||
|
||||
case 0x0F: // reset colors
|
||||
if ( strip )
|
||||
continue;
|
||||
|
||||
libirc_colorparser_closetags (&mask, &d, &destlen);
|
||||
break;
|
||||
|
||||
case 0x03: // set color
|
||||
if ( isdigit (p[1]) )
|
||||
{
|
||||
// Parse
|
||||
int bgcolor = -1, color = p[1] - 0x30;
|
||||
p++;
|
||||
|
||||
if ( isdigit (p[1]) )
|
||||
{
|
||||
color = color * 10 + (p[1] - 0x30);
|
||||
p++;
|
||||
}
|
||||
|
||||
// If there is a comma, search for the following
|
||||
// background color
|
||||
if ( p[1] == ',' && isdigit (p[2]) )
|
||||
{
|
||||
bgcolor = p[2] - 0x30;
|
||||
p += 2;
|
||||
|
||||
if ( isdigit (p[1]) )
|
||||
{
|
||||
bgcolor = bgcolor * 10 + (p[1] - 0x30);
|
||||
p++;
|
||||
}
|
||||
}
|
||||
|
||||
// Check for range
|
||||
if ( color <= LIBIRC_COLORPARSER_MAXCOLORS
|
||||
&& bgcolor <= LIBIRC_COLORPARSER_MAXCOLORS )
|
||||
{
|
||||
if ( strip )
|
||||
continue;
|
||||
|
||||
if ( bgcolor != -1 )
|
||||
current_bg = bgcolor;
|
||||
|
||||
libirc_colorparser_applycolor (&mask, &d, &destlen, color, current_bg);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
if ( destline )
|
||||
*d++ = *p;
|
||||
else
|
||||
destlen++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Close all the opened tags
|
||||
libirc_colorparser_closetags (&mask, &d, &destlen);
|
||||
destlen++; // for 0-terminator
|
||||
}
|
||||
|
||||
*d = '\0';
|
||||
return destline;
|
||||
}
|
||||
|
||||
|
||||
static int libirc_colorparser_colorlookup (const char * color)
|
||||
{
|
||||
int i;
|
||||
for ( i = 0; color_replacement_table[i]; i++ )
|
||||
if ( !strcmp (color, color_replacement_table[i]) )
|
||||
return i;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* [code] to IRC color conversion.
|
||||
*/
|
||||
char * irc_color_convert_to_mirc (const char * source, void * (*memory_allocator)(size_t))
|
||||
{
|
||||
unsigned int destlen = 0;
|
||||
char * destline = 0, *d = 0;
|
||||
const char *p1, *p2, *cur;
|
||||
|
||||
/*
|
||||
* There will be two passes. First pass calculates the total length of
|
||||
* the destination string. The second pass allocates memory for the string,
|
||||
* and fills it.
|
||||
*/
|
||||
while ( destline == 0 ) // destline will be set after the 2nd pass
|
||||
{
|
||||
if ( destlen > 0 )
|
||||
{
|
||||
// This is the 2nd pass; allocate memory.
|
||||
if ( (destline = memory_allocator (destlen)) == 0 )
|
||||
return 0;
|
||||
|
||||
d = destline;
|
||||
}
|
||||
|
||||
cur = source;
|
||||
while ( (p1 = strchr (cur, '[')) != 0 )
|
||||
{
|
||||
const char * replacedval = 0;
|
||||
p2 = 0;
|
||||
|
||||
// Check if the closing bracket is available after p1
|
||||
// and the tag length is suitable
|
||||
if ( p1[1] != '\0'
|
||||
&& (p2 = strchr (p1, ']')) != 0
|
||||
&& (p2 - p1) > 1
|
||||
&& (p2 - p1) < 31 )
|
||||
{
|
||||
// Get the tag
|
||||
char tagbuf[32];
|
||||
int taglen = p2 - p1 - 1;
|
||||
|
||||
memcpy (tagbuf, p1 + 1, taglen);
|
||||
tagbuf[taglen] = '\0';
|
||||
|
||||
if ( !strcmp (tagbuf, "/COLOR") )
|
||||
replacedval = "\x0F";
|
||||
else if ( strstr (tagbuf, "COLOR=") == tagbuf )
|
||||
{
|
||||
int color, bgcolor = -2;
|
||||
char * bcol;
|
||||
|
||||
bcol = strchr (tagbuf + 6, '/');
|
||||
|
||||
if ( bcol )
|
||||
{
|
||||
*bcol++ = '\0';
|
||||
bgcolor = libirc_colorparser_colorlookup (bcol);
|
||||
}
|
||||
|
||||
color = libirc_colorparser_colorlookup (tagbuf + 6);
|
||||
|
||||
if ( color != -1 && bgcolor == -2 )
|
||||
{
|
||||
sprintf (tagbuf, "\x03%02d", color);
|
||||
replacedval = tagbuf;
|
||||
}
|
||||
else if ( color != -1 && bgcolor >= 0 )
|
||||
{
|
||||
sprintf (tagbuf, "\x03%02d,%02d", color, bgcolor);
|
||||
replacedval = tagbuf;
|
||||
}
|
||||
}
|
||||
else if ( !strcmp (tagbuf, "B") || !strcmp (tagbuf, "/B") )
|
||||
replacedval = "\x02";
|
||||
else if ( !strcmp (tagbuf, "U") || !strcmp (tagbuf, "/U") )
|
||||
replacedval = "\x1F";
|
||||
else if ( !strcmp (tagbuf, "I") || !strcmp (tagbuf, "/I") )
|
||||
replacedval = "\x16";
|
||||
}
|
||||
|
||||
if ( replacedval )
|
||||
{
|
||||
// add a part before the tag
|
||||
int partlen = p1 - cur;
|
||||
|
||||
if ( destline )
|
||||
{
|
||||
memcpy (d, cur, partlen);
|
||||
d += partlen;
|
||||
}
|
||||
else
|
||||
destlen += partlen;
|
||||
|
||||
// Add the replacement
|
||||
libirc_colorparser_addorcat (&d, &destlen, replacedval);
|
||||
|
||||
// And move the pointer
|
||||
cur = p2 + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// add a whole part before the end tag
|
||||
int partlen;
|
||||
|
||||
if ( !p2 )
|
||||
p2 = cur + strlen(cur);
|
||||
|
||||
partlen = p2 - cur + 1;
|
||||
|
||||
if ( destline )
|
||||
{
|
||||
memcpy (d, cur, partlen);
|
||||
d += partlen;
|
||||
}
|
||||
else
|
||||
destlen += partlen;
|
||||
|
||||
// And move the pointer
|
||||
cur = p2 + 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Add the rest of string
|
||||
libirc_colorparser_addorcat (&d, &destlen, cur);
|
||||
destlen++; // for 0-terminator
|
||||
}
|
||||
|
||||
*d = '\0';
|
||||
return destline;
|
||||
}
|
||||
|
||||
|
||||
char * irc_color_strip_from_mirc (const char * message)
|
||||
{
|
||||
return libirc_colorparser_irc2code (message, 1);
|
||||
}
|
||||
|
||||
|
||||
char * irc_color_convert_from_mirc (const char * message)
|
||||
{
|
||||
return libirc_colorparser_irc2code (message, 0);
|
||||
}
|
892
external/LibIRC/dcc.c
vendored
892
external/LibIRC/dcc.c
vendored
@ -1,892 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2012 George Yunaev gyunaev@ulduzsoft.com
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*/
|
||||
|
||||
#define LIBIRC_DCC_CHAT 1
|
||||
#define LIBIRC_DCC_SENDFILE 2
|
||||
#define LIBIRC_DCC_RECVFILE 3
|
||||
|
||||
|
||||
static irc_dcc_session_t * libirc_find_dcc_session (irc_session_t * session, irc_dcc_t dccid, int lock_list)
|
||||
{
|
||||
irc_dcc_session_t * s, *found = 0;
|
||||
|
||||
if ( lock_list )
|
||||
libirc_mutex_lock (&session->mutex_dcc);
|
||||
|
||||
for ( s = session->dcc_sessions; s; s = s->next )
|
||||
{
|
||||
if ( s->id == dccid )
|
||||
{
|
||||
found = s;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( found == 0 && lock_list )
|
||||
libirc_mutex_unlock (&session->mutex_dcc);
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
|
||||
static void libirc_dcc_destroy_nolock (irc_session_t * session, irc_dcc_t dccid)
|
||||
{
|
||||
irc_dcc_session_t * dcc = libirc_find_dcc_session (session, dccid, 0);
|
||||
|
||||
if ( dcc )
|
||||
{
|
||||
if ( dcc->sock >= 0 )
|
||||
socket_close (&dcc->sock);
|
||||
|
||||
dcc->state = LIBIRC_STATE_REMOVED;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void libirc_remove_dcc_session (irc_session_t * session, irc_dcc_session_t * dcc, int lock_list)
|
||||
{
|
||||
if ( dcc->sock >= 0 )
|
||||
socket_close (&dcc->sock);
|
||||
|
||||
if ( dcc->dccsend_file_fp )
|
||||
fclose (dcc->dccsend_file_fp);
|
||||
|
||||
dcc->dccsend_file_fp = 0;
|
||||
|
||||
libirc_mutex_destroy (&dcc->mutex_outbuf);
|
||||
|
||||
if ( lock_list )
|
||||
libirc_mutex_lock (&session->mutex_dcc);
|
||||
|
||||
if ( session->dcc_sessions != dcc )
|
||||
{
|
||||
irc_dcc_session_t * s;
|
||||
for ( s = session->dcc_sessions; s; s = s->next )
|
||||
{
|
||||
if ( s->next == dcc )
|
||||
{
|
||||
s->next = dcc->next;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
session->dcc_sessions = dcc->next;
|
||||
|
||||
if ( lock_list )
|
||||
libirc_mutex_unlock (&session->mutex_dcc);
|
||||
|
||||
free (dcc);
|
||||
}
|
||||
|
||||
|
||||
static void libirc_dcc_add_descriptors (irc_session_t * ircsession, fd_set *in_set, fd_set *out_set, int * maxfd)
|
||||
{
|
||||
irc_dcc_session_t * dcc, *dcc_next;
|
||||
time_t now = time (0);
|
||||
|
||||
libirc_mutex_lock (&ircsession->mutex_dcc);
|
||||
|
||||
// Preprocessing DCC list:
|
||||
// - ask DCC send callbacks for data;
|
||||
// - remove unused DCC structures
|
||||
for ( dcc = ircsession->dcc_sessions; dcc; dcc = dcc_next )
|
||||
{
|
||||
dcc_next = dcc->next;
|
||||
|
||||
// Remove timed-out sessions
|
||||
if ( (dcc->state == LIBIRC_STATE_CONNECTING
|
||||
|| dcc->state == LIBIRC_STATE_INIT
|
||||
|| dcc->state == LIBIRC_STATE_LISTENING)
|
||||
&& now - dcc->timeout > ircsession->dcc_timeout )
|
||||
{
|
||||
// Inform the caller about DCC timeout.
|
||||
// Do not inform when state is LIBIRC_STATE_INIT - session
|
||||
// was initiated from someone else, and callbacks aren't set yet.
|
||||
if ( dcc->state != LIBIRC_STATE_INIT )
|
||||
{
|
||||
libirc_mutex_unlock (&ircsession->mutex_dcc);
|
||||
|
||||
if ( dcc->cb )
|
||||
(*dcc->cb)(ircsession, dcc->id, LIBIRC_ERR_TIMEOUT, dcc->ctx, 0, 0);
|
||||
|
||||
libirc_mutex_lock (&ircsession->mutex_dcc);
|
||||
}
|
||||
|
||||
libirc_remove_dcc_session (ircsession, dcc, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* If we're sending file, and the output buffer is empty, we need
|
||||
* to provide some data.
|
||||
*/
|
||||
if ( dcc->state == LIBIRC_STATE_CONNECTED
|
||||
&& dcc->dccmode == LIBIRC_DCC_SENDFILE
|
||||
&& dcc->dccsend_file_fp
|
||||
&& dcc->outgoing_offset == 0 )
|
||||
{
|
||||
int len = fread (dcc->outgoing_buf, 1, sizeof (dcc->outgoing_buf), dcc->dccsend_file_fp);
|
||||
|
||||
if ( len <= 0 )
|
||||
{
|
||||
int err = (len < 0 ? LIBIRC_ERR_READ : 0);
|
||||
|
||||
libirc_mutex_unlock (&ircsession->mutex_dcc);
|
||||
|
||||
(*dcc->cb)(ircsession, dcc->id, err, dcc->ctx, 0, 0);
|
||||
libirc_mutex_lock (&ircsession->mutex_dcc);
|
||||
libirc_dcc_destroy_nolock (ircsession, dcc->id);
|
||||
}
|
||||
else
|
||||
dcc->outgoing_offset = len;
|
||||
}
|
||||
|
||||
// Clean up unused sessions
|
||||
if ( dcc->state == LIBIRC_STATE_REMOVED )
|
||||
libirc_remove_dcc_session (ircsession, dcc, 0);
|
||||
}
|
||||
|
||||
for ( dcc = ircsession->dcc_sessions; dcc; dcc = dcc->next )
|
||||
{
|
||||
switch (dcc->state)
|
||||
{
|
||||
case LIBIRC_STATE_LISTENING:
|
||||
// While listening, only in_set descriptor should be set
|
||||
libirc_add_to_set (dcc->sock, in_set, maxfd);
|
||||
break;
|
||||
|
||||
case LIBIRC_STATE_CONNECTING:
|
||||
// While connection, only out_set descriptor should be set
|
||||
libirc_add_to_set (dcc->sock, out_set, maxfd);
|
||||
break;
|
||||
|
||||
case LIBIRC_STATE_CONNECTED:
|
||||
// Add input descriptor if there is space in input buffer
|
||||
// and it is DCC chat (during DCC send, there is nothing to recv)
|
||||
if ( dcc->incoming_offset < sizeof(dcc->incoming_buf) - 1 )
|
||||
libirc_add_to_set (dcc->sock, in_set, maxfd);
|
||||
|
||||
// Add output descriptor if there is something in output buffer
|
||||
libirc_mutex_lock (&dcc->mutex_outbuf);
|
||||
|
||||
if ( dcc->outgoing_offset > 0 )
|
||||
libirc_add_to_set (dcc->sock, out_set, maxfd);
|
||||
|
||||
libirc_mutex_unlock (&dcc->mutex_outbuf);
|
||||
break;
|
||||
|
||||
case LIBIRC_STATE_CONFIRM_SIZE:
|
||||
/*
|
||||
* If we're receiving file, then WE should confirm the transferred
|
||||
* part (so we have to sent data). But if we're sending the file,
|
||||
* then RECEIVER should confirm the packet, so we have to receive
|
||||
* data.
|
||||
*
|
||||
* We don't need to LOCK_DCC_OUTBUF - during file transfer, buffers
|
||||
* can't change asynchronously.
|
||||
*/
|
||||
if ( dcc->dccmode == LIBIRC_DCC_RECVFILE && dcc->outgoing_offset > 0 )
|
||||
libirc_add_to_set (dcc->sock, out_set, maxfd);
|
||||
|
||||
if ( dcc->dccmode == LIBIRC_DCC_SENDFILE && dcc->incoming_offset < 4 )
|
||||
libirc_add_to_set (dcc->sock, in_set, maxfd);
|
||||
}
|
||||
}
|
||||
|
||||
libirc_mutex_unlock (&ircsession->mutex_dcc);
|
||||
}
|
||||
|
||||
|
||||
static void libirc_dcc_process_descriptors (irc_session_t * ircsession, fd_set *in_set, fd_set *out_set)
|
||||
{
|
||||
irc_dcc_session_t * dcc;
|
||||
|
||||
/*
|
||||
* We need to use such a complex scheme here, because on every callback
|
||||
* a number of DCC sessions could be destroyed.
|
||||
*/
|
||||
libirc_mutex_lock (&ircsession->mutex_dcc);
|
||||
|
||||
for ( dcc = ircsession->dcc_sessions; dcc; dcc = dcc->next )
|
||||
{
|
||||
if ( dcc->state == LIBIRC_STATE_LISTENING
|
||||
&& FD_ISSET (dcc->sock, in_set) )
|
||||
{
|
||||
socklen_t len = sizeof(dcc->remote_addr);
|
||||
int nsock, err = 0;
|
||||
|
||||
// New connection is available; accept it.
|
||||
if ( socket_accept (&dcc->sock, (socket_t*)&nsock, (struct sockaddr *) &dcc->remote_addr, &len) )
|
||||
err = LIBIRC_ERR_ACCEPT;
|
||||
|
||||
// On success, change the active socket and change the state
|
||||
if ( err == 0 )
|
||||
{
|
||||
// close the listen socket, and replace it by a newly
|
||||
// accepted
|
||||
socket_close (&dcc->sock);
|
||||
dcc->sock = nsock;
|
||||
dcc->state = LIBIRC_STATE_CONNECTED;
|
||||
}
|
||||
|
||||
// If this is DCC chat, inform the caller about accept()
|
||||
// success or failure.
|
||||
// Otherwise (DCC send) there is no reason.
|
||||
if ( dcc->dccmode == LIBIRC_DCC_CHAT )
|
||||
{
|
||||
libirc_mutex_unlock (&ircsession->mutex_dcc);
|
||||
(*dcc->cb)(ircsession, dcc->id, err, dcc->ctx, 0, 0);
|
||||
libirc_mutex_lock (&ircsession->mutex_dcc);
|
||||
}
|
||||
|
||||
if ( err )
|
||||
libirc_dcc_destroy_nolock (ircsession, dcc->id);
|
||||
}
|
||||
|
||||
if ( dcc->state == LIBIRC_STATE_CONNECTING
|
||||
&& FD_ISSET (dcc->sock, out_set) )
|
||||
{
|
||||
// Now we have to determine whether the socket is connected
|
||||
// or the connect is failed
|
||||
struct sockaddr_in saddr;
|
||||
socklen_t slen = sizeof(saddr);
|
||||
int err = 0;
|
||||
|
||||
if ( getpeername (dcc->sock, (struct sockaddr*)&saddr, &slen) < 0 )
|
||||
err = LIBIRC_ERR_CONNECT;
|
||||
|
||||
// On success, change the state
|
||||
if ( err == 0 )
|
||||
dcc->state = LIBIRC_STATE_CONNECTED;
|
||||
|
||||
// If this is DCC chat, inform the caller about connect()
|
||||
// success or failure.
|
||||
// Otherwise (DCC send) there is no reason.
|
||||
if ( dcc->dccmode == LIBIRC_DCC_CHAT )
|
||||
{
|
||||
libirc_mutex_unlock (&ircsession->mutex_dcc);
|
||||
(*dcc->cb)(ircsession, dcc->id, err, dcc->ctx, 0, 0);
|
||||
libirc_mutex_lock (&ircsession->mutex_dcc);
|
||||
}
|
||||
|
||||
if ( err )
|
||||
libirc_dcc_destroy_nolock (ircsession, dcc->id);
|
||||
}
|
||||
|
||||
if ( dcc->state == LIBIRC_STATE_CONNECTED
|
||||
|| dcc->state == LIBIRC_STATE_CONFIRM_SIZE )
|
||||
{
|
||||
if ( FD_ISSET (dcc->sock, in_set) )
|
||||
{
|
||||
int length, offset = 0, err = 0;
|
||||
|
||||
unsigned int amount = sizeof (dcc->incoming_buf) - dcc->incoming_offset;
|
||||
|
||||
length = socket_recv (&dcc->sock, dcc->incoming_buf + dcc->incoming_offset, amount);
|
||||
|
||||
if ( length < 0 )
|
||||
{
|
||||
err = LIBIRC_ERR_READ;
|
||||
}
|
||||
else if ( length == 0 )
|
||||
{
|
||||
err = LIBIRC_ERR_CLOSED;
|
||||
|
||||
if ( dcc->dccsend_file_fp )
|
||||
{
|
||||
fclose (dcc->dccsend_file_fp);
|
||||
dcc->dccsend_file_fp = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dcc->incoming_offset += length;
|
||||
|
||||
if ( dcc->dccmode != LIBIRC_DCC_CHAT )
|
||||
offset = dcc->incoming_offset;
|
||||
else
|
||||
offset = libirc_findcrorlf (dcc->incoming_buf, dcc->incoming_offset);
|
||||
|
||||
/*
|
||||
* In LIBIRC_STATE_CONFIRM_SIZE state we don't call any
|
||||
* callbacks (except there is an error). We just receive
|
||||
* the data, and compare it with the amount sent.
|
||||
*/
|
||||
if ( dcc->state == LIBIRC_STATE_CONFIRM_SIZE )
|
||||
{
|
||||
if ( dcc->dccmode != LIBIRC_DCC_SENDFILE )
|
||||
abort();
|
||||
|
||||
if ( dcc->incoming_offset == 4 )
|
||||
{
|
||||
// The order is big-endian
|
||||
const unsigned char * bptr = (const unsigned char *) dcc->incoming_buf;
|
||||
unsigned int received_size = (bptr[0] << 24) | (bptr[1] << 16) | (bptr[2] << 8) | bptr[3];
|
||||
|
||||
// Sent size confirmed
|
||||
if ( dcc->file_confirm_offset == received_size )
|
||||
{
|
||||
dcc->state = LIBIRC_STATE_CONNECTED;
|
||||
dcc->incoming_offset = 0;
|
||||
}
|
||||
else
|
||||
err = LIBIRC_ERR_WRITE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* If it is DCC_CHAT, we send a 0-terminated string
|
||||
* (which is smaller than offset). Otherwise we send
|
||||
* a full buffer.
|
||||
*/
|
||||
libirc_mutex_unlock (&ircsession->mutex_dcc);
|
||||
|
||||
if ( dcc->dccmode != LIBIRC_DCC_CHAT )
|
||||
{
|
||||
if ( dcc->dccmode != LIBIRC_DCC_RECVFILE )
|
||||
abort();
|
||||
|
||||
(*dcc->cb)(ircsession, dcc->id, err, dcc->ctx, dcc->incoming_buf, offset);
|
||||
|
||||
/*
|
||||
* If the session is not terminated in callback,
|
||||
* put the sent amount into the sent_packet_size_net_byteorder
|
||||
*/
|
||||
if ( dcc->state != LIBIRC_STATE_REMOVED )
|
||||
{
|
||||
dcc->state = LIBIRC_STATE_CONFIRM_SIZE;
|
||||
dcc->file_confirm_offset += offset;
|
||||
|
||||
// Store as big endian
|
||||
dcc->outgoing_buf[0] = (char) dcc->file_confirm_offset >> 24;
|
||||
dcc->outgoing_buf[1] = (char) dcc->file_confirm_offset >> 16;
|
||||
dcc->outgoing_buf[2] = (char) dcc->file_confirm_offset >> 8;
|
||||
dcc->outgoing_buf[3] = (char) dcc->file_confirm_offset;
|
||||
dcc->outgoing_offset = 4;
|
||||
}
|
||||
}
|
||||
else
|
||||
(*dcc->cb)(ircsession, dcc->id, err, dcc->ctx, dcc->incoming_buf, strlen(dcc->incoming_buf));
|
||||
|
||||
libirc_mutex_lock (&ircsession->mutex_dcc);
|
||||
|
||||
if ( dcc->incoming_offset - offset > 0 )
|
||||
memmove (dcc->incoming_buf, dcc->incoming_buf + offset, dcc->incoming_offset - offset);
|
||||
|
||||
dcc->incoming_offset -= offset;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* If error arises somewhere above, we inform the caller
|
||||
* of failure, and destroy this session.
|
||||
*/
|
||||
if ( err )
|
||||
{
|
||||
libirc_mutex_unlock (&ircsession->mutex_dcc);
|
||||
(*dcc->cb)(ircsession, dcc->id, err, dcc->ctx, 0, 0);
|
||||
libirc_mutex_lock (&ircsession->mutex_dcc);
|
||||
libirc_dcc_destroy_nolock (ircsession, dcc->id);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Session might be closed (with sock = -1) after the in_set
|
||||
* processing, so before out_set processing we should check
|
||||
* for this case
|
||||
*/
|
||||
if ( dcc->state == LIBIRC_STATE_REMOVED )
|
||||
continue;
|
||||
|
||||
/*
|
||||
* Write bit set - we can send() something, and it won't block.
|
||||
*/
|
||||
if ( FD_ISSET (dcc->sock, out_set) )
|
||||
{
|
||||
int length, offset, err = 0;
|
||||
|
||||
/*
|
||||
* Because in some cases outgoing_buf could be changed
|
||||
* asynchronously (by another thread), we should lock
|
||||
* it.
|
||||
*/
|
||||
libirc_mutex_lock (&dcc->mutex_outbuf);
|
||||
|
||||
offset = dcc->outgoing_offset;
|
||||
|
||||
if ( offset > 0 )
|
||||
{
|
||||
length = socket_send (&dcc->sock, dcc->outgoing_buf, offset);
|
||||
|
||||
if ( length < 0 )
|
||||
err = LIBIRC_ERR_WRITE;
|
||||
else if ( length == 0 )
|
||||
err = LIBIRC_ERR_CLOSED;
|
||||
else
|
||||
{
|
||||
/*
|
||||
* If this was DCC_SENDFILE, and we just sent a packet,
|
||||
* change the state to wait for confirmation (and store
|
||||
* sent packet size)
|
||||
*/
|
||||
if ( dcc->state == LIBIRC_STATE_CONNECTED
|
||||
&& dcc->dccmode == LIBIRC_DCC_SENDFILE )
|
||||
{
|
||||
dcc->file_confirm_offset += offset;
|
||||
dcc->state = LIBIRC_STATE_CONFIRM_SIZE;
|
||||
|
||||
libirc_mutex_unlock (&ircsession->mutex_dcc);
|
||||
libirc_mutex_unlock (&dcc->mutex_outbuf);
|
||||
(*dcc->cb)(ircsession, dcc->id, err, dcc->ctx, 0, offset);
|
||||
libirc_mutex_lock (&ircsession->mutex_dcc);
|
||||
libirc_mutex_lock (&dcc->mutex_outbuf);
|
||||
}
|
||||
|
||||
if ( dcc->outgoing_offset - length > 0 )
|
||||
memmove (dcc->outgoing_buf, dcc->outgoing_buf + length, dcc->outgoing_offset - length);
|
||||
|
||||
dcc->outgoing_offset -= length;
|
||||
|
||||
/*
|
||||
* If we just sent the confirmation data, change state
|
||||
* back.
|
||||
*/
|
||||
if ( dcc->state == LIBIRC_STATE_CONFIRM_SIZE
|
||||
&& dcc->dccmode == LIBIRC_DCC_RECVFILE
|
||||
&& dcc->outgoing_offset == 0 )
|
||||
{
|
||||
/*
|
||||
* If the file is already received, we should inform
|
||||
* the caller, and close the session.
|
||||
*/
|
||||
if ( dcc->received_file_size == dcc->file_confirm_offset )
|
||||
{
|
||||
libirc_mutex_unlock (&ircsession->mutex_dcc);
|
||||
libirc_mutex_unlock (&dcc->mutex_outbuf);
|
||||
(*dcc->cb)(ircsession, dcc->id, 0, dcc->ctx, 0, 0);
|
||||
libirc_dcc_destroy_nolock (ircsession, dcc->id);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Continue to receive the file */
|
||||
dcc->state = LIBIRC_STATE_CONNECTED;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
libirc_mutex_unlock (&dcc->mutex_outbuf);
|
||||
|
||||
/*
|
||||
* If error arises somewhere above, we inform the caller
|
||||
* of failure, and destroy this session.
|
||||
*/
|
||||
if ( err )
|
||||
{
|
||||
libirc_mutex_unlock (&ircsession->mutex_dcc);
|
||||
(*dcc->cb)(ircsession, dcc->id, err, dcc->ctx, 0, 0);
|
||||
libirc_mutex_lock (&ircsession->mutex_dcc);
|
||||
|
||||
libirc_dcc_destroy_nolock (ircsession, dcc->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
libirc_mutex_unlock (&ircsession->mutex_dcc);
|
||||
}
|
||||
|
||||
|
||||
static int libirc_new_dcc_session (irc_session_t * session, unsigned long ip, unsigned short port, int dccmode, void * ctx, irc_dcc_session_t ** pdcc)
|
||||
{
|
||||
irc_dcc_session_t * dcc = malloc (sizeof(irc_dcc_session_t));
|
||||
|
||||
if ( !dcc )
|
||||
return LIBIRC_ERR_NOMEM;
|
||||
|
||||
// setup
|
||||
memset (dcc, 0, sizeof(irc_dcc_session_t));
|
||||
|
||||
dcc->dccsend_file_fp = 0;
|
||||
|
||||
if ( libirc_mutex_init (&dcc->mutex_outbuf) )
|
||||
goto cleanup_exit_error;
|
||||
|
||||
if ( socket_create (PF_INET, SOCK_STREAM, &dcc->sock) )
|
||||
goto cleanup_exit_error;
|
||||
|
||||
if ( !ip )
|
||||
{
|
||||
unsigned long arg = 1;
|
||||
|
||||
setsockopt (dcc->sock, SOL_SOCKET, SO_REUSEADDR, (char*)&arg, sizeof(arg));
|
||||
|
||||
#if defined (ENABLE_IPV6)
|
||||
if ( session->flags & SESSIONFL_USES_IPV6 )
|
||||
{
|
||||
struct sockaddr_in6 saddr6;
|
||||
|
||||
memset (&saddr6, 0, sizeof(saddr6));
|
||||
saddr6.sin6_family = AF_INET6;
|
||||
memcpy (&saddr6.sin6_addr, &session->local_addr6, sizeof(session->local_addr6));
|
||||
saddr6.sin6_port = htons (0);
|
||||
|
||||
if ( bind (dcc->sock, (struct sockaddr *) &saddr6, sizeof(saddr6)) < 0 )
|
||||
goto cleanup_exit_error;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
struct sockaddr_in saddr;
|
||||
memset (&saddr, 0, sizeof(saddr));
|
||||
saddr.sin_family = AF_INET;
|
||||
memcpy (&saddr.sin_addr, &session->local_addr, sizeof(session->local_addr));
|
||||
saddr.sin_port = htons (0);
|
||||
|
||||
if ( bind (dcc->sock, (struct sockaddr *) &saddr, sizeof(saddr)) < 0 )
|
||||
goto cleanup_exit_error;
|
||||
}
|
||||
|
||||
if ( listen (dcc->sock, 5) < 0 )
|
||||
goto cleanup_exit_error;
|
||||
|
||||
dcc->state = LIBIRC_STATE_LISTENING;
|
||||
}
|
||||
else
|
||||
{
|
||||
// make socket non-blocking, so connect() call won't block
|
||||
if ( socket_make_nonblocking (&dcc->sock) )
|
||||
goto cleanup_exit_error;
|
||||
|
||||
memset (&dcc->remote_addr, 0, sizeof(dcc->remote_addr));
|
||||
dcc->remote_addr.sin_family = AF_INET;
|
||||
dcc->remote_addr.sin_addr.s_addr = htonl (ip); // what idiot came up with idea to send IP address in host-byteorder?
|
||||
dcc->remote_addr.sin_port = htons(port);
|
||||
|
||||
dcc->state = LIBIRC_STATE_INIT;
|
||||
}
|
||||
|
||||
dcc->dccmode = dccmode;
|
||||
dcc->ctx = ctx;
|
||||
time (&dcc->timeout);
|
||||
|
||||
// and store it
|
||||
libirc_mutex_lock (&session->mutex_dcc);
|
||||
|
||||
dcc->id = session->dcc_last_id++;
|
||||
dcc->next = session->dcc_sessions;
|
||||
session->dcc_sessions = dcc;
|
||||
|
||||
libirc_mutex_unlock (&session->mutex_dcc);
|
||||
|
||||
*pdcc = dcc;
|
||||
return 0;
|
||||
|
||||
cleanup_exit_error:
|
||||
if ( dcc->sock >= 0 )
|
||||
socket_close (&dcc->sock);
|
||||
|
||||
free (dcc);
|
||||
return LIBIRC_ERR_SOCKET;
|
||||
}
|
||||
|
||||
|
||||
int irc_dcc_destroy (irc_session_t * session, irc_dcc_t dccid)
|
||||
{
|
||||
// This function doesn't actually destroy the session; it just changes
|
||||
// its state to "removed" and closes the socket. The memory is actually
|
||||
// freed after the processing loop.
|
||||
irc_dcc_session_t * dcc = libirc_find_dcc_session (session, dccid, 1);
|
||||
|
||||
if ( !dcc )
|
||||
return 1;
|
||||
|
||||
if ( dcc->sock >= 0 )
|
||||
socket_close (&dcc->sock);
|
||||
|
||||
dcc->state = LIBIRC_STATE_REMOVED;
|
||||
|
||||
libirc_mutex_unlock (&session->mutex_dcc);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int irc_dcc_chat (irc_session_t * session, void * ctx, const char * nick, irc_dcc_callback_t callback, irc_dcc_t * dccid)
|
||||
{
|
||||
struct sockaddr_in saddr;
|
||||
socklen_t len = sizeof(saddr);
|
||||
char cmdbuf[128], notbuf[128];
|
||||
irc_dcc_session_t * dcc;
|
||||
int err;
|
||||
|
||||
if ( session->state != LIBIRC_STATE_CONNECTED )
|
||||
{
|
||||
session->lasterror = LIBIRC_ERR_STATE;
|
||||
return 1;
|
||||
}
|
||||
|
||||
err = libirc_new_dcc_session (session, 0, 0, LIBIRC_DCC_CHAT, ctx, &dcc);
|
||||
|
||||
if ( err )
|
||||
{
|
||||
session->lasterror = err;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ( getsockname (dcc->sock, (struct sockaddr*) &saddr, &len) < 0 )
|
||||
{
|
||||
session->lasterror = LIBIRC_ERR_SOCKET;
|
||||
libirc_remove_dcc_session (session, dcc, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
sprintf (notbuf, "DCC Chat (%s)", inet_ntoa (saddr.sin_addr));
|
||||
sprintf (cmdbuf, "DCC CHAT chat %lu %u", (unsigned long) ntohl (saddr.sin_addr.s_addr), ntohs (saddr.sin_port));
|
||||
|
||||
if ( irc_cmd_notice (session, nick, notbuf)
|
||||
|| irc_cmd_ctcp_request (session, nick, cmdbuf) )
|
||||
{
|
||||
libirc_remove_dcc_session (session, dcc, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
*dccid = dcc->id;
|
||||
dcc->cb = callback;
|
||||
dcc->dccmode = LIBIRC_DCC_CHAT;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int irc_dcc_msg (irc_session_t * session, irc_dcc_t dccid, const char * text)
|
||||
{
|
||||
irc_dcc_session_t * dcc = libirc_find_dcc_session (session, dccid, 1);
|
||||
|
||||
if ( !dcc )
|
||||
return 1;
|
||||
|
||||
if ( dcc->dccmode != LIBIRC_DCC_CHAT )
|
||||
{
|
||||
session->lasterror = LIBIRC_ERR_INVAL;
|
||||
libirc_mutex_unlock (&session->mutex_dcc);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ( (strlen(text) + 2) >= (sizeof(dcc->outgoing_buf) - dcc->outgoing_offset) )
|
||||
{
|
||||
session->lasterror = LIBIRC_ERR_NOMEM;
|
||||
libirc_mutex_unlock (&session->mutex_dcc);
|
||||
return 1;
|
||||
}
|
||||
|
||||
libirc_mutex_lock (&dcc->mutex_outbuf);
|
||||
|
||||
strcpy (dcc->outgoing_buf + dcc->outgoing_offset, text);
|
||||
dcc->outgoing_offset += strlen (text);
|
||||
dcc->outgoing_buf[dcc->outgoing_offset++] = 0x0D;
|
||||
dcc->outgoing_buf[dcc->outgoing_offset++] = 0x0A;
|
||||
|
||||
libirc_mutex_unlock (&dcc->mutex_outbuf);
|
||||
libirc_mutex_unlock (&session->mutex_dcc);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static void libirc_dcc_request (irc_session_t * session, const char * nick, const char * req)
|
||||
{
|
||||
char filenamebuf[256];
|
||||
unsigned long ip, size;
|
||||
unsigned short port;
|
||||
|
||||
if ( sscanf (req, "DCC CHAT chat %lu %hu", &ip, &port) == 2 )
|
||||
{
|
||||
if ( session->callbacks.event_dcc_chat_req )
|
||||
{
|
||||
irc_dcc_session_t * dcc;
|
||||
|
||||
int err = libirc_new_dcc_session (session, ip, port, LIBIRC_DCC_CHAT, 0, &dcc);
|
||||
if ( err )
|
||||
{
|
||||
session->lasterror = err;
|
||||
return;
|
||||
}
|
||||
|
||||
(*session->callbacks.event_dcc_chat_req) (session,
|
||||
nick,
|
||||
inet_ntoa (dcc->remote_addr.sin_addr),
|
||||
dcc->id);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
else if ( sscanf (req, "DCC SEND %s %lu %hu %lu", filenamebuf, &ip, &port, &size) == 4 )
|
||||
{
|
||||
if ( session->callbacks.event_dcc_send_req )
|
||||
{
|
||||
irc_dcc_session_t * dcc;
|
||||
|
||||
int err = libirc_new_dcc_session (session, ip, port, LIBIRC_DCC_RECVFILE, 0, &dcc);
|
||||
if ( err )
|
||||
{
|
||||
session->lasterror = err;
|
||||
return;
|
||||
}
|
||||
|
||||
(*session->callbacks.event_dcc_send_req) (session,
|
||||
nick,
|
||||
inet_ntoa (dcc->remote_addr.sin_addr),
|
||||
filenamebuf,
|
||||
size,
|
||||
dcc->id);
|
||||
|
||||
dcc->received_file_size = size;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
#if defined (ENABLE_DEBUG)
|
||||
fprintf (stderr, "BUG: Unhandled DCC message: %s\n", req);
|
||||
abort();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
int irc_dcc_accept (irc_session_t * session, irc_dcc_t dccid, void * ctx, irc_dcc_callback_t callback)
|
||||
{
|
||||
irc_dcc_session_t * dcc = libirc_find_dcc_session (session, dccid, 1);
|
||||
|
||||
if ( !dcc )
|
||||
return 1;
|
||||
|
||||
if ( dcc->state != LIBIRC_STATE_INIT )
|
||||
{
|
||||
session->lasterror = LIBIRC_ERR_STATE;
|
||||
libirc_mutex_unlock (&session->mutex_dcc);
|
||||
return 1;
|
||||
}
|
||||
|
||||
dcc->cb = callback;
|
||||
dcc->ctx = ctx;
|
||||
|
||||
// Initiate the connect
|
||||
if ( socket_connect (&dcc->sock, (struct sockaddr *) &dcc->remote_addr, sizeof(dcc->remote_addr)) )
|
||||
{
|
||||
libirc_dcc_destroy_nolock (session, dccid);
|
||||
libirc_mutex_unlock (&session->mutex_dcc);
|
||||
session->lasterror = LIBIRC_ERR_CONNECT;
|
||||
return 1;
|
||||
}
|
||||
|
||||
dcc->state = LIBIRC_STATE_CONNECTING;
|
||||
libirc_mutex_unlock (&session->mutex_dcc);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int irc_dcc_decline (irc_session_t * session, irc_dcc_t dccid)
|
||||
{
|
||||
irc_dcc_session_t * dcc = libirc_find_dcc_session (session, dccid, 1);
|
||||
|
||||
if ( !dcc )
|
||||
return 1;
|
||||
|
||||
if ( dcc->state != LIBIRC_STATE_INIT )
|
||||
{
|
||||
session->lasterror = LIBIRC_ERR_STATE;
|
||||
libirc_mutex_unlock (&session->mutex_dcc);
|
||||
return 1;
|
||||
}
|
||||
|
||||
libirc_dcc_destroy_nolock (session, dccid);
|
||||
libirc_mutex_unlock (&session->mutex_dcc);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int irc_dcc_sendfile (irc_session_t * session, void * ctx, const char * nick, const char * filename, irc_dcc_callback_t callback, irc_dcc_t * dccid)
|
||||
{
|
||||
struct sockaddr_in saddr;
|
||||
socklen_t len = sizeof(saddr);
|
||||
char cmdbuf[128], notbuf[128];
|
||||
irc_dcc_session_t * dcc;
|
||||
const char * p;
|
||||
int err;
|
||||
long filesize;
|
||||
|
||||
if ( !session || !dccid || !filename || !callback )
|
||||
{
|
||||
session->lasterror = LIBIRC_ERR_INVAL;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ( session->state != LIBIRC_STATE_CONNECTED )
|
||||
{
|
||||
session->lasterror = LIBIRC_ERR_STATE;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ( (err = libirc_new_dcc_session (session, 0, 0, LIBIRC_DCC_SENDFILE, ctx, &dcc)) != 0 )
|
||||
{
|
||||
session->lasterror = err;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ( (dcc->dccsend_file_fp = fopen (filename, "rb")) == 0 )
|
||||
{
|
||||
libirc_remove_dcc_session (session, dcc, 1);
|
||||
session->lasterror = LIBIRC_ERR_OPENFILE;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Get file length */
|
||||
if ( fseek (dcc->dccsend_file_fp, 0, SEEK_END)
|
||||
|| (filesize = ftell (dcc->dccsend_file_fp)) == -1
|
||||
|| fseek (dcc->dccsend_file_fp, 0, SEEK_SET) )
|
||||
{
|
||||
libirc_remove_dcc_session (session, dcc, 1);
|
||||
session->lasterror = LIBIRC_ERR_NODCCSEND;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ( getsockname (dcc->sock, (struct sockaddr*) &saddr, &len) < 0 )
|
||||
{
|
||||
libirc_remove_dcc_session (session, dcc, 1);
|
||||
session->lasterror = LIBIRC_ERR_SOCKET;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Remove path from the filename
|
||||
if ( (p = strrchr (filename, '\\')) == 0
|
||||
&& (p = strrchr (filename, '/')) == 0 )
|
||||
p = filename;
|
||||
else
|
||||
p++; // skip directory slash
|
||||
|
||||
sprintf (notbuf, "DCC Send %s (%s)", p, inet_ntoa (saddr.sin_addr));
|
||||
sprintf (cmdbuf, "DCC SEND %s %lu %u %ld", p, (unsigned long) ntohl (saddr.sin_addr.s_addr), ntohs (saddr.sin_port), filesize);
|
||||
|
||||
if ( irc_cmd_notice (session, nick, notbuf)
|
||||
|| irc_cmd_ctcp_request (session, nick, cmdbuf) )
|
||||
{
|
||||
libirc_remove_dcc_session (session, dcc, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
*dccid = dcc->id;
|
||||
dcc->cb = callback;
|
||||
|
||||
return 0;
|
||||
}
|
54
external/LibIRC/dcc.h
vendored
54
external/LibIRC/dcc.h
vendored
@ -1,54 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2012 George Yunaev gyunaev@ulduzsoft.com
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDE_IRC_DCC_H
|
||||
#define INCLUDE_IRC_DCC_H
|
||||
|
||||
|
||||
/*
|
||||
* This structure keeps the state of a single DCC connection.
|
||||
*/
|
||||
struct irc_dcc_session_s
|
||||
{
|
||||
irc_dcc_session_t * next;
|
||||
|
||||
irc_dcc_t id;
|
||||
void * ctx;
|
||||
socket_t sock; /*!< DCC socket */
|
||||
int dccmode; /*!< Boolean value to differ chat vs send
|
||||
requests. Changes the cb behavior - when
|
||||
it is chat, data is sent by lines with
|
||||
stripped CRLFs. In file mode, the data
|
||||
is sent as-is */
|
||||
int state;
|
||||
time_t timeout;
|
||||
|
||||
FILE * dccsend_file_fp;
|
||||
unsigned int received_file_size;
|
||||
unsigned int file_confirm_offset;
|
||||
|
||||
struct sockaddr_in remote_addr;
|
||||
|
||||
char incoming_buf[LIBIRC_DCC_BUFFER_SIZE];
|
||||
unsigned int incoming_offset;
|
||||
|
||||
char outgoing_buf[LIBIRC_DCC_BUFFER_SIZE];
|
||||
unsigned int outgoing_offset;
|
||||
port_mutex_t mutex_outbuf;
|
||||
|
||||
irc_dcc_callback_t cb;
|
||||
};
|
||||
|
||||
|
||||
#endif /* INCLUDE_IRC_DCC_H */
|
54
external/LibIRC/errors.c
vendored
54
external/LibIRC/errors.c
vendored
@ -1,54 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2012 George Yunaev gyunaev@ulduzsoft.com
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*/
|
||||
|
||||
static const char * libirc_strerror[LIBIRC_ERR_MAX] =
|
||||
{
|
||||
"No error",
|
||||
"Invalid argument",
|
||||
"Host not resolved",
|
||||
"Socket error",
|
||||
"Could not connect",
|
||||
"Remote connection closed",
|
||||
"Out of memory",
|
||||
"Could not accept new connection",
|
||||
"Object not found",
|
||||
"Could not DCC send this object",
|
||||
"Read error",
|
||||
"Write error",
|
||||
"Illegal operation for this state",
|
||||
"Timeout error",
|
||||
"Could not open file",
|
||||
"IRC session terminated",
|
||||
"IPv6 not supported",
|
||||
"SSL not supported",
|
||||
"SSL initialization failed",
|
||||
"SSL connection failed",
|
||||
"SSL certificate verify failed",
|
||||
};
|
||||
|
||||
|
||||
int irc_errno (irc_session_t * session)
|
||||
{
|
||||
return session->lasterror;
|
||||
}
|
||||
|
||||
|
||||
const char * irc_strerror (int ircerrno)
|
||||
{
|
||||
if ( ircerrno >= 0 && ircerrno < LIBIRC_ERR_MAX )
|
||||
return libirc_strerror[ircerrno];
|
||||
else
|
||||
return "Invalid irc_errno value";
|
||||
}
|
||||
|
1258
external/LibIRC/libircclient.c
vendored
1258
external/LibIRC/libircclient.c
vendored
File diff suppressed because it is too large
Load Diff
36
external/LibIRC/params.h
vendored
36
external/LibIRC/params.h
vendored
@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2012 George Yunaev gyunaev@ulduzsoft.com
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDE_IRC_PARAMS_H
|
||||
#define INCLUDE_IRC_PARAMS_H
|
||||
|
||||
|
||||
#define LIBIRC_VERSION_HIGH 1
|
||||
#define LIBIRC_VERSION_LOW 8
|
||||
|
||||
#define LIBIRC_BUFFER_SIZE 1024
|
||||
#define LIBIRC_DCC_BUFFER_SIZE 1024
|
||||
|
||||
#define LIBIRC_STATE_INIT 0
|
||||
#define LIBIRC_STATE_LISTENING 1
|
||||
#define LIBIRC_STATE_CONNECTING 2
|
||||
#define LIBIRC_STATE_CONNECTED 3
|
||||
#define LIBIRC_STATE_DISCONNECTED 4
|
||||
#define LIBIRC_STATE_CONFIRM_SIZE 5 // Used only by DCC send to confirm the amount of sent data
|
||||
#define LIBIRC_STATE_REMOVED 10 // this state is used only in DCC
|
||||
|
||||
|
||||
#define SSL_PREFIX '#'
|
||||
|
||||
#endif /* INCLUDE_IRC_PARAMS_H */
|
156
external/LibIRC/portable.c
vendored
156
external/LibIRC/portable.c
vendored
@ -1,156 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2012 George Yunaev gyunaev@ulduzsoft.com
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*/
|
||||
|
||||
#if !defined (_WIN32)
|
||||
#include "ircconfig.h"
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netdb.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
#include <time.h>
|
||||
|
||||
#if defined (ENABLE_THREADS)
|
||||
#include <pthread.h>
|
||||
typedef pthread_mutex_t port_mutex_t;
|
||||
|
||||
#if !defined (PTHREAD_MUTEX_RECURSIVE) && defined (PTHREAD_MUTEX_RECURSIVE_NP)
|
||||
#define PTHREAD_MUTEX_RECURSIVE PTHREAD_MUTEX_RECURSIVE_NP
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#include <windows.h>
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#if defined (ENABLE_THREADS)
|
||||
typedef CRITICAL_SECTION port_mutex_t;
|
||||
#endif
|
||||
|
||||
#define inline
|
||||
#define snprintf _snprintf
|
||||
#define vsnprintf _vsnprintf
|
||||
#define strncasecmp _strnicmp
|
||||
#endif
|
||||
|
||||
|
||||
#if defined (ENABLE_SSL)
|
||||
#include <openssl/ssl.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/rand.h>
|
||||
#endif
|
||||
|
||||
|
||||
#if defined (ENABLE_THREADS)
|
||||
static inline int libirc_mutex_init (port_mutex_t * mutex)
|
||||
{
|
||||
#if defined (_WIN32)
|
||||
InitializeCriticalSection (mutex);
|
||||
return 0;
|
||||
#elif defined (PTHREAD_MUTEX_RECURSIVE)
|
||||
pthread_mutexattr_t attr;
|
||||
|
||||
return (pthread_mutexattr_init (&attr)
|
||||
|| pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE)
|
||||
|| pthread_mutex_init (mutex, &attr));
|
||||
#else /* !defined (PTHREAD_MUTEX_RECURSIVE) */
|
||||
|
||||
return pthread_mutex_init (mutex, 0);
|
||||
|
||||
#endif /* defined (_WIN32) */
|
||||
}
|
||||
|
||||
|
||||
static inline void libirc_mutex_destroy (port_mutex_t * mutex)
|
||||
{
|
||||
#if defined (_WIN32)
|
||||
DeleteCriticalSection (mutex);
|
||||
#else
|
||||
pthread_mutex_destroy (mutex);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
static inline void libirc_mutex_lock (port_mutex_t * mutex)
|
||||
{
|
||||
#if defined (_WIN32)
|
||||
EnterCriticalSection (mutex);
|
||||
#else
|
||||
pthread_mutex_lock (mutex);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
static inline void libirc_mutex_unlock (port_mutex_t * mutex)
|
||||
{
|
||||
#if defined (_WIN32)
|
||||
LeaveCriticalSection (mutex);
|
||||
#else
|
||||
pthread_mutex_unlock (mutex);
|
||||
#endif
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
typedef void * port_mutex_t;
|
||||
|
||||
static inline int libirc_mutex_init (port_mutex_t * mutex) { return 0; }
|
||||
static inline void libirc_mutex_destroy (port_mutex_t * mutex) {}
|
||||
static inline void libirc_mutex_lock (port_mutex_t * mutex) {}
|
||||
static inline void libirc_mutex_unlock (port_mutex_t * mutex) {}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Stub for WIN32 dll to initialize winsock API
|
||||
*/
|
||||
#if defined (WIN32_DLL)
|
||||
BOOL WINAPI DllMain (HINSTANCE hinstDll, DWORD fdwReason, LPVOID lpvReserved)
|
||||
{
|
||||
WORD wVersionRequested = MAKEWORD (1, 1);
|
||||
WSADATA wsaData;
|
||||
|
||||
switch(fdwReason)
|
||||
{
|
||||
case DLL_PROCESS_ATTACH:
|
||||
if ( WSAStartup (wVersionRequested, &wsaData) != 0 )
|
||||
return FALSE;
|
||||
|
||||
DisableThreadLibraryCalls (hinstDll);
|
||||
break;
|
||||
|
||||
case DLL_PROCESS_DETACH:
|
||||
WSACleanup();
|
||||
break;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
#endif
|
79
external/LibIRC/session.h
vendored
79
external/LibIRC/session.h
vendored
@ -1,79 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2012 George Yunaev gyunaev@ulduzsoft.com
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef INCLUDE_IRC_SESSION_H
|
||||
#define INCLUDE_IRC_SESSION_H
|
||||
|
||||
|
||||
#include "params.h"
|
||||
#include "dcc.h"
|
||||
#include "libirc_events.h"
|
||||
|
||||
|
||||
// Session flags
|
||||
#define SESSIONFL_MOTD_RECEIVED (0x00000001)
|
||||
#define SESSIONFL_SSL_CONNECTION (0x00000002)
|
||||
#define SESSIONFL_SSL_WRITE_WANTS_READ (0x00000004)
|
||||
#define SESSIONFL_SSL_READ_WANTS_WRITE (0x00000008)
|
||||
#define SESSIONFL_USES_IPV6 (0x00000010)
|
||||
|
||||
|
||||
|
||||
struct irc_session_s
|
||||
{
|
||||
void * ctx;
|
||||
int dcc_timeout;
|
||||
|
||||
int options;
|
||||
int lasterror;
|
||||
|
||||
char incoming_buf[LIBIRC_BUFFER_SIZE];
|
||||
unsigned int incoming_offset;
|
||||
|
||||
char outgoing_buf[LIBIRC_BUFFER_SIZE];
|
||||
unsigned int outgoing_offset;
|
||||
port_mutex_t mutex_session;
|
||||
|
||||
socket_t sock;
|
||||
int state;
|
||||
int flags;
|
||||
|
||||
char * server;
|
||||
char * server_password;
|
||||
char * realname;
|
||||
char * username;
|
||||
char * nick;
|
||||
char * ctcp_version;
|
||||
|
||||
#if defined( ENABLE_IPV6 )
|
||||
struct in6_addr local_addr6;
|
||||
#endif
|
||||
|
||||
struct in_addr local_addr;
|
||||
irc_dcc_t dcc_last_id;
|
||||
irc_dcc_session_t * dcc_sessions;
|
||||
port_mutex_t mutex_dcc;
|
||||
|
||||
irc_callbacks_t callbacks;
|
||||
|
||||
#if defined (ENABLE_SSL)
|
||||
SSL * ssl;
|
||||
#endif
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif /* INCLUDE_IRC_SESSION_H */
|
159
external/LibIRC/sockets.c
vendored
159
external/LibIRC/sockets.c
vendored
@ -1,159 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2012 George Yunaev gyunaev@ulduzsoft.com
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* The sockets interface was moved out to simplify going OpenSSL integration.
|
||||
*/
|
||||
#if !defined (_WIN32)
|
||||
#include <sys/socket.h>
|
||||
#include <netdb.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#define IS_SOCKET_ERROR(a) ((a)<0)
|
||||
typedef int socket_t;
|
||||
|
||||
#else
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#include <windows.h>
|
||||
|
||||
#define IS_SOCKET_ERROR(a) ((a)==SOCKET_ERROR)
|
||||
|
||||
#if !defined(EWOULDBLOCK)
|
||||
#define EWOULDBLOCK WSAEWOULDBLOCK
|
||||
#endif
|
||||
#if !defined(EINPROGRESS)
|
||||
#define EINPROGRESS WSAEINPROGRESS
|
||||
#endif
|
||||
#if !defined(EINTR)
|
||||
#define EINTR WSAEINTR
|
||||
#endif
|
||||
#if !defined(EAGAIN)
|
||||
#define EAGAIN EWOULDBLOCK
|
||||
#endif
|
||||
|
||||
typedef SOCKET socket_t;
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef INADDR_NONE
|
||||
#define INADDR_NONE 0xFFFFFFFF
|
||||
#endif
|
||||
|
||||
|
||||
static int socket_error()
|
||||
{
|
||||
#if !defined (_WIN32)
|
||||
return errno;
|
||||
#else
|
||||
return WSAGetLastError();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
static int socket_create (int domain, int type, socket_t * sock)
|
||||
{
|
||||
*sock = socket (domain, type, 0);
|
||||
return IS_SOCKET_ERROR(*sock) ? 1 : 0;
|
||||
}
|
||||
|
||||
|
||||
static int socket_make_nonblocking (socket_t * sock)
|
||||
{
|
||||
#if !defined (_WIN32)
|
||||
return fcntl (*sock, F_SETFL, fcntl (*sock, F_GETFL,0 ) | O_NONBLOCK) != 0;
|
||||
#else
|
||||
unsigned long mode = 0;
|
||||
return ioctlsocket (*sock, FIONBIO, &mode) == SOCKET_ERROR;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
static int socket_close (socket_t * sock)
|
||||
{
|
||||
#if !defined (_WIN32)
|
||||
close (*sock);
|
||||
#else
|
||||
closesocket (*sock);
|
||||
#endif
|
||||
|
||||
*sock = -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int socket_connect (socket_t * sock, const struct sockaddr *saddr, socklen_t len)
|
||||
{
|
||||
while ( 1 )
|
||||
{
|
||||
if ( connect (*sock, saddr, len) < 0 )
|
||||
{
|
||||
if ( socket_error() == EINTR )
|
||||
continue;
|
||||
|
||||
if ( socket_error() != EINPROGRESS && socket_error() != EWOULDBLOCK )
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int socket_accept (socket_t * sock, socket_t * newsock, struct sockaddr *saddr, socklen_t * len)
|
||||
{
|
||||
while ( IS_SOCKET_ERROR(*newsock = accept (*sock, saddr, len)) )
|
||||
{
|
||||
if ( socket_error() == EINTR )
|
||||
continue;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int socket_recv (socket_t * sock, void * buf, size_t len)
|
||||
{
|
||||
int length;
|
||||
|
||||
while ( (length = recv (*sock, buf, len, 0)) < 0 )
|
||||
{
|
||||
int err = socket_error();
|
||||
|
||||
if ( err != EINTR && err != EAGAIN )
|
||||
break;
|
||||
}
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
|
||||
static int socket_send (socket_t * sock, const void *buf, size_t len)
|
||||
{
|
||||
int length;
|
||||
|
||||
while ( (length = send (*sock, buf, len, 0)) < 0 )
|
||||
{
|
||||
int err = socket_error();
|
||||
|
||||
if ( err != EINTR && err != EAGAIN )
|
||||
break;
|
||||
}
|
||||
|
||||
return length;
|
||||
}
|
390
external/LibIRC/ssl.c
vendored
390
external/LibIRC/ssl.c
vendored
@ -1,390 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2012 George Yunaev gyunaev@ulduzsoft.com
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*/
|
||||
|
||||
|
||||
#if defined (ENABLE_SSL)
|
||||
|
||||
// Nonzero if OpenSSL has been initialized
|
||||
static SSL_CTX * ssl_context = 0;
|
||||
|
||||
#if defined (_WIN32)
|
||||
#include <windows.h>
|
||||
// This array will store all of the mutexes available to OpenSSL
|
||||
static CRITICAL_SECTION * mutex_buf = 0;
|
||||
|
||||
// OpenSSL callback to utilize static locks
|
||||
static void cb_openssl_locking_function( int mode, int n, const char * file, int line )
|
||||
{
|
||||
if ( mode & CRYPTO_LOCK)
|
||||
EnterCriticalSection( &mutex_buf[n] );
|
||||
else
|
||||
LeaveCriticalSection( &mutex_buf[n] );
|
||||
}
|
||||
|
||||
// OpenSSL callback to get the thread ID
|
||||
static unsigned long cb_openssl_id_function(void)
|
||||
{
|
||||
return ((unsigned long) GetCurrentThreadId() );
|
||||
}
|
||||
|
||||
static int alloc_mutexes( unsigned int total )
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
// Enable thread safety in OpenSSL
|
||||
mutex_buf = (CRITICAL_SECTION*) malloc( total * sizeof(CRITICAL_SECTION) );
|
||||
|
||||
if ( !mutex_buf )
|
||||
return -1;
|
||||
|
||||
for ( i = 0; i < total; i++)
|
||||
InitializeCriticalSection( &(mutex_buf[i]) );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
|
||||
// This array will store all of the mutexes available to OpenSSL
|
||||
static pthread_mutex_t * mutex_buf = 0;
|
||||
|
||||
// OpenSSL callback to utilize static locks
|
||||
static void cb_openssl_locking_function( int mode, int n, const char * file, int line )
|
||||
{
|
||||
(void)file;
|
||||
(void)line;
|
||||
|
||||
if ( mode & CRYPTO_LOCK)
|
||||
pthread_mutex_lock( &mutex_buf[n] );
|
||||
else
|
||||
pthread_mutex_unlock( &mutex_buf[n] );
|
||||
}
|
||||
|
||||
// OpenSSL callback to get the thread ID
|
||||
static unsigned long cb_openssl_id_function()
|
||||
{
|
||||
return ((unsigned long) pthread_self() );
|
||||
}
|
||||
|
||||
static int alloc_mutexes( unsigned int total )
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
// Enable thread safety in OpenSSL
|
||||
mutex_buf = (pthread_mutex_t*) malloc( total * sizeof(pthread_mutex_t) );
|
||||
|
||||
if ( !mutex_buf )
|
||||
return -1;
|
||||
|
||||
for ( i = 0; i < total; i++)
|
||||
pthread_mutex_init( &(mutex_buf[i]), 0 );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static int ssl_init_context( irc_session_t * session )
|
||||
{
|
||||
// Load the strings and init the library
|
||||
SSL_load_error_strings();
|
||||
|
||||
// Enable thread safety in OpenSSL
|
||||
if ( alloc_mutexes( CRYPTO_num_locks() ) )
|
||||
return LIBIRC_ERR_NOMEM;
|
||||
|
||||
// Register our callbacks
|
||||
CRYPTO_set_id_callback( cb_openssl_id_function );
|
||||
CRYPTO_set_locking_callback( cb_openssl_locking_function );
|
||||
|
||||
// Init it
|
||||
if ( !SSL_library_init() )
|
||||
return LIBIRC_ERR_SSL_INIT_FAILED;
|
||||
|
||||
if ( RAND_status() == 0 )
|
||||
return LIBIRC_ERR_SSL_INIT_FAILED;
|
||||
|
||||
// Create an SSL context; currently a single context is used for all connections
|
||||
ssl_context = SSL_CTX_new( SSLv23_method() );
|
||||
|
||||
if ( !ssl_context )
|
||||
return LIBIRC_ERR_SSL_INIT_FAILED;
|
||||
|
||||
// Disable SSLv2 as it is unsecure
|
||||
if ( (SSL_CTX_set_options( ssl_context, SSL_OP_NO_SSLv2) & SSL_OP_NO_SSLv2) == 0 )
|
||||
return LIBIRC_ERR_SSL_INIT_FAILED;
|
||||
|
||||
// Enable only strong ciphers
|
||||
if ( SSL_CTX_set_cipher_list( ssl_context, "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH" ) != 1 )
|
||||
return LIBIRC_ERR_SSL_INIT_FAILED;
|
||||
|
||||
// Set the verification
|
||||
if ( session->options & LIBIRC_OPTION_SSL_NO_VERIFY )
|
||||
SSL_CTX_set_verify( ssl_context, SSL_VERIFY_NONE, 0 );
|
||||
else
|
||||
SSL_CTX_set_verify( ssl_context, SSL_VERIFY_PEER, 0 );
|
||||
|
||||
// Disable session caching
|
||||
SSL_CTX_set_session_cache_mode( ssl_context, SSL_SESS_CACHE_OFF );
|
||||
|
||||
// Enable SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER so we can move the buffer during sending
|
||||
SSL_CTX_set_mode( ssl_context, SSL_CTX_get_mode(ssl_context) | SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER | SSL_MODE_ENABLE_PARTIAL_WRITE );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#if defined (_WIN32)
|
||||
#define SSLINIT_LOCK_MUTEX(a) WaitForSingleObject( a, INFINITE )
|
||||
#define SSLINIT_UNLOCK_MUTEX(a) ReleaseMutex( a )
|
||||
#else
|
||||
#define SSLINIT_LOCK_MUTEX(a) pthread_mutex_lock( &a )
|
||||
#define SSLINIT_UNLOCK_MUTEX(a) pthread_mutex_unlock( &a )
|
||||
#endif
|
||||
|
||||
// Initializes the SSL context. Must be called after the socket is created.
|
||||
static int ssl_init( irc_session_t * session )
|
||||
{
|
||||
static int ssl_context_initialized = 0;
|
||||
|
||||
#if defined (_WIN32)
|
||||
static HANDLE initmutex = 0;
|
||||
|
||||
// First time run? Create the mutex
|
||||
if ( initmutex == 0 )
|
||||
{
|
||||
HANDLE m = CreateMutex( 0, FALSE, 0 );
|
||||
|
||||
// Now we check if the mutex has already been created by another thread performing the init concurrently.
|
||||
// If it was, we close our mutex and use the original one. This could be done synchronously by using the
|
||||
// InterlockedCompareExchangePointer function.
|
||||
if ( InterlockedCompareExchangePointer( &m, m, 0 ) != 0 )
|
||||
CloseHandle( m );
|
||||
}
|
||||
#else
|
||||
static pthread_mutex_t initmutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
#endif
|
||||
|
||||
// This initialization needs to be performed only once. The problem is that it is called from
|
||||
// irc_connect() and this function may be called simultaneously from different threads. So we have
|
||||
// to use mutex on Linux because it allows static mutex initialization. Windows doesn't, so here
|
||||
// we do the sabre dance around it.
|
||||
SSLINIT_LOCK_MUTEX( initmutex );
|
||||
|
||||
if ( ssl_context_initialized == 0 )
|
||||
{
|
||||
int res = ssl_init_context( session );
|
||||
|
||||
if ( res )
|
||||
{
|
||||
SSLINIT_UNLOCK_MUTEX( initmutex );
|
||||
return res;
|
||||
}
|
||||
|
||||
ssl_context_initialized = 1;
|
||||
}
|
||||
|
||||
SSLINIT_UNLOCK_MUTEX( initmutex );
|
||||
|
||||
// Get the SSL context
|
||||
session->ssl = SSL_new( ssl_context );
|
||||
|
||||
if ( !session->ssl )
|
||||
return LIBIRC_ERR_SSL_INIT_FAILED;
|
||||
|
||||
// Let OpenSSL use our socket
|
||||
if ( SSL_set_fd( session->ssl, session->sock) != 1 )
|
||||
return LIBIRC_ERR_SSL_INIT_FAILED;
|
||||
|
||||
// Since we're connecting on our own, tell openssl about it
|
||||
SSL_set_connect_state( session->ssl );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void ssl_handle_error( irc_session_t * session, int ssl_error )
|
||||
{
|
||||
if ( ERR_GET_LIB(ssl_error) == ERR_LIB_SSL )
|
||||
{
|
||||
if ( ERR_GET_REASON(ssl_error) == SSL_R_CERTIFICATE_VERIFY_FAILED )
|
||||
{
|
||||
session->lasterror = LIBIRC_ERR_SSL_CERT_VERIFY_FAILED;
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ERR_GET_REASON(ssl_error) == SSL_R_UNKNOWN_PROTOCOL )
|
||||
{
|
||||
session->lasterror = LIBIRC_ERR_CONNECT_SSL_FAILED;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
#if defined (ENABLE_DEBUG)
|
||||
if ( IS_DEBUG_ENABLED(session) )
|
||||
fprintf (stderr, "[DEBUG] SSL error: %s\n\t(%d, %d)\n",
|
||||
ERR_error_string( ssl_error, NULL), ERR_GET_LIB( ssl_error), ERR_GET_REASON(ssl_error) );
|
||||
#endif
|
||||
}
|
||||
|
||||
static int ssl_recv( irc_session_t * session )
|
||||
{
|
||||
int count;
|
||||
unsigned int amount = (sizeof (session->incoming_buf) - 1) - session->incoming_offset;
|
||||
|
||||
ERR_clear_error();
|
||||
|
||||
// Read up to m_bufferLength bytes
|
||||
count = SSL_read( session->ssl, session->incoming_buf + session->incoming_offset, amount );
|
||||
|
||||
if ( count > 0 )
|
||||
return count;
|
||||
else if ( count == 0 )
|
||||
return -1; // remote connection closed
|
||||
else
|
||||
{
|
||||
int ssl_error = SSL_get_error( session->ssl, count );
|
||||
|
||||
// Handle SSL error since not all of them are actually errors
|
||||
switch ( ssl_error )
|
||||
{
|
||||
case SSL_ERROR_WANT_READ:
|
||||
// This is not really an error. We received something, but
|
||||
// OpenSSL gave nothing to us because all it read was
|
||||
// internal data. Repeat the same read.
|
||||
return 0;
|
||||
|
||||
case SSL_ERROR_WANT_WRITE:
|
||||
// This is not really an error. We received something, but
|
||||
// now OpenSSL needs to send the data before returning any
|
||||
// data to us (like negotiations). This means we'd need
|
||||
// to wait for WRITE event, but call SSL_read() again.
|
||||
session->flags |= SESSIONFL_SSL_READ_WANTS_WRITE;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// This is an SSL error, handle it
|
||||
ssl_handle_error( session, ERR_get_error() );
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
static int ssl_send( irc_session_t * session )
|
||||
{
|
||||
int count;
|
||||
ERR_clear_error();
|
||||
|
||||
count = SSL_write( session->ssl, session->outgoing_buf, session->outgoing_offset );
|
||||
|
||||
if ( count > 0 )
|
||||
return count;
|
||||
else if ( count == 0 )
|
||||
return -1;
|
||||
else
|
||||
{
|
||||
int ssl_error = SSL_get_error( session->ssl, count );
|
||||
|
||||
switch ( ssl_error )
|
||||
{
|
||||
case SSL_ERROR_WANT_READ:
|
||||
// This is not really an error. We sent some internal OpenSSL data,
|
||||
// but now it needs to read more data before it can send anything.
|
||||
// Thus we wait for READ event, but will call SSL_write() again.
|
||||
session->flags |= SESSIONFL_SSL_WRITE_WANTS_READ;
|
||||
return 0;
|
||||
|
||||
case SSL_ERROR_WANT_WRITE:
|
||||
// This is not really an error. We sent some data, but now OpenSSL
|
||||
// wants to send some internal data before sending ours.
|
||||
// Repeat the same write.
|
||||
return 0;
|
||||
}
|
||||
|
||||
// This is an SSL error, handle it
|
||||
ssl_handle_error( session, ERR_get_error() );
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
// Handles both SSL and non-SSL reads.
|
||||
// Returns -1 in case there is an error and socket should be closed/connection terminated
|
||||
// Returns 0 in case there is a temporary error and the call should be retried (SSL_WANTS_WRITE case)
|
||||
// Returns a positive number if we actually read something
|
||||
static int session_socket_read( irc_session_t * session )
|
||||
{
|
||||
int length;
|
||||
|
||||
#if defined (ENABLE_SSL)
|
||||
if ( session->ssl )
|
||||
{
|
||||
// Yes, I know this is tricky
|
||||
if ( session->flags & SESSIONFL_SSL_READ_WANTS_WRITE )
|
||||
{
|
||||
session->flags &= ~SESSIONFL_SSL_READ_WANTS_WRITE;
|
||||
ssl_send( session );
|
||||
return 0;
|
||||
}
|
||||
|
||||
return ssl_recv( session );
|
||||
}
|
||||
#endif
|
||||
|
||||
length = socket_recv( &session->sock,
|
||||
session->incoming_buf + session->incoming_offset,
|
||||
(sizeof (session->incoming_buf) - 1) - session->incoming_offset );
|
||||
|
||||
// There is no "retry" errors for regular sockets
|
||||
if ( length <= 0 )
|
||||
return -1;
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
// Handles both SSL and non-SSL writes.
|
||||
// Returns -1 in case there is an error and socket should be closed/connection terminated
|
||||
// Returns 0 in case there is a temporary error and the call should be retried (SSL_WANTS_WRITE case)
|
||||
// Returns a positive number if we actually sent something
|
||||
static int session_socket_write( irc_session_t * session )
|
||||
{
|
||||
int length;
|
||||
|
||||
#if defined (ENABLE_SSL)
|
||||
if ( session->ssl )
|
||||
{
|
||||
// Yep
|
||||
if ( session->flags & SESSIONFL_SSL_WRITE_WANTS_READ )
|
||||
{
|
||||
session->flags &= ~SESSIONFL_SSL_WRITE_WANTS_READ;
|
||||
ssl_recv( session );
|
||||
return 0;
|
||||
}
|
||||
|
||||
return ssl_send( session );
|
||||
}
|
||||
#endif
|
||||
|
||||
length = socket_send (&session->sock, session->outgoing_buf, session->outgoing_offset);
|
||||
|
||||
// There is no "retry" errors for regular sockets
|
||||
if ( length <= 0 )
|
||||
return -1;
|
||||
|
||||
return length;
|
||||
}
|
130
external/LibIRC/utils.c
vendored
130
external/LibIRC/utils.c
vendored
@ -1,130 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2012 George Yunaev gyunaev@ulduzsoft.com
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*/
|
||||
|
||||
static void libirc_add_to_set (int fd, fd_set *set, int * maxfd)
|
||||
{
|
||||
FD_SET (fd, set);
|
||||
|
||||
if ( *maxfd < fd )
|
||||
*maxfd = fd;
|
||||
}
|
||||
|
||||
#if defined (ENABLE_DEBUG)
|
||||
static void libirc_dump_data (const char * prefix, const char * buf, unsigned int length)
|
||||
{
|
||||
printf ("%s: ", prefix);
|
||||
for ( ; length > 0; length -- )
|
||||
printf ("%c", *buf++);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Finds a separator (\x0D\x0A), which separates two lines.
|
||||
*/
|
||||
static int libirc_findcrlf (const char * buf, int length)
|
||||
{
|
||||
int offset = 0;
|
||||
for ( ; offset < length; offset++ )
|
||||
{
|
||||
if ( buf[offset] == 0x0D && offset < length - 1 && buf[offset+1] == 0x0A )
|
||||
return offset;
|
||||
if ( buf[offset] == 0x0A)
|
||||
return offset;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int libirc_findcrlf_offset(const char *buf, int offset, const int length)
|
||||
{
|
||||
for(; offset < length; offset++)
|
||||
{
|
||||
if(buf[offset] != 0x0D && buf[offset] != 0x0A)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
return offset;
|
||||
}
|
||||
|
||||
static int libirc_findcrorlf (char * buf, int length)
|
||||
{
|
||||
int offset = 0;
|
||||
for ( ; offset < length; offset++ )
|
||||
{
|
||||
if ( buf[offset] == 0x0D || buf[offset] == 0x0A )
|
||||
{
|
||||
buf[offset++] = '\0';
|
||||
|
||||
if ( offset < (length - 1)
|
||||
&& (buf[offset] == 0x0D || buf[offset] == 0x0A) )
|
||||
offset++;
|
||||
|
||||
return offset;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static void libirc_event_ctcp_internal (irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count)
|
||||
{
|
||||
(void)event;
|
||||
(void)count;
|
||||
|
||||
if ( origin )
|
||||
{
|
||||
char nickbuf[128], textbuf[256];
|
||||
irc_target_get_nick (origin, nickbuf, sizeof(nickbuf));
|
||||
|
||||
if ( strstr (params[0], "PING") == params[0] )
|
||||
irc_cmd_ctcp_reply (session, nickbuf, params[0]);
|
||||
else if ( !strcmp (params[0], "VERSION") )
|
||||
{
|
||||
if ( !session->ctcp_version )
|
||||
{
|
||||
unsigned int high, low;
|
||||
irc_get_version (&high, &low);
|
||||
|
||||
snprintf (textbuf, sizeof (textbuf), "VERSION libircclient by Georgy Yunaev ver.%d.%d", high, low);
|
||||
}
|
||||
else
|
||||
snprintf (textbuf, sizeof (textbuf), "VERSION %s", session->ctcp_version);
|
||||
|
||||
irc_cmd_ctcp_reply (session, nickbuf, textbuf);
|
||||
}
|
||||
else if ( !strcmp (params[0], "FINGER") )
|
||||
{
|
||||
sprintf (textbuf, "FINGER %s (%s) Idle 0 seconds",
|
||||
session->username ? session->username : "nobody",
|
||||
session->realname ? session->realname : "noname");
|
||||
|
||||
irc_cmd_ctcp_reply (session, nickbuf, textbuf);
|
||||
}
|
||||
else if ( !strcmp (params[0], "TIME") )
|
||||
{
|
||||
time_t now = time(0);
|
||||
|
||||
#if defined (ENABLE_THREADS) && defined (HAVE_LOCALTIME_R)
|
||||
struct tm tmtmp, *ltime = localtime_r (&now, &tmtmp);
|
||||
#else
|
||||
struct tm * ltime = localtime (&now);
|
||||
#endif
|
||||
strftime (textbuf, sizeof(textbuf), "%a %b %d %H:%M:%S %Z %Y", ltime);
|
||||
irc_cmd_ctcp_reply (session, nickbuf, textbuf);
|
||||
}
|
||||
}
|
||||
}
|
0
external/MaxmindDB/CMakeLists.txt
vendored
0
external/MaxmindDB/CMakeLists.txt
vendored
202
external/MaxmindDB/LICENSE
vendored
202
external/MaxmindDB/LICENSE
vendored
@ -1,202 +0,0 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
180
external/MaxmindDB/data-pool.c
vendored
180
external/MaxmindDB/data-pool.c
vendored
@ -1,180 +0,0 @@
|
||||
#include "data-pool.h"
|
||||
#include "maxminddb.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static bool can_multiply(size_t const, size_t const, size_t const);
|
||||
|
||||
// Allocate an MMDB_data_pool_s. It initially has space for size
|
||||
// MMDB_entry_data_list_s structs.
|
||||
MMDB_data_pool_s *data_pool_new(size_t const size)
|
||||
{
|
||||
MMDB_data_pool_s *const pool = calloc(1, sizeof(MMDB_data_pool_s));
|
||||
if (!pool) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (size == 0 ||
|
||||
!can_multiply(SIZE_MAX, size, sizeof(MMDB_entry_data_list_s))) {
|
||||
data_pool_destroy(pool);
|
||||
return NULL;
|
||||
}
|
||||
pool->size = size;
|
||||
pool->blocks[0] = calloc(pool->size, sizeof(MMDB_entry_data_list_s));
|
||||
if (!pool->blocks[0]) {
|
||||
data_pool_destroy(pool);
|
||||
return NULL;
|
||||
}
|
||||
pool->blocks[0]->pool = pool;
|
||||
|
||||
pool->sizes[0] = size;
|
||||
|
||||
pool->block = pool->blocks[0];
|
||||
|
||||
return pool;
|
||||
}
|
||||
|
||||
// Determine if we can multiply m*n. We can do this if the result will be below
|
||||
// the given max. max will typically be SIZE_MAX.
|
||||
//
|
||||
// We want to know if we'll wrap around.
|
||||
static bool can_multiply(size_t const max, size_t const m, size_t const n)
|
||||
{
|
||||
if (m == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return n <= max / m;
|
||||
}
|
||||
|
||||
// Clean up the data pool.
|
||||
void data_pool_destroy(MMDB_data_pool_s *const pool)
|
||||
{
|
||||
if (!pool) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i <= pool->index; i++) {
|
||||
free(pool->blocks[i]);
|
||||
}
|
||||
|
||||
free(pool);
|
||||
}
|
||||
|
||||
// Claim a new struct from the pool. Doing this may cause the pool's size to
|
||||
// grow.
|
||||
MMDB_entry_data_list_s *data_pool_alloc(MMDB_data_pool_s *const pool)
|
||||
{
|
||||
if (!pool) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (pool->used < pool->size) {
|
||||
MMDB_entry_data_list_s *const element = pool->block + pool->used;
|
||||
pool->used++;
|
||||
return element;
|
||||
}
|
||||
|
||||
// Take it from a new block of memory.
|
||||
|
||||
size_t const new_index = pool->index + 1;
|
||||
if (new_index == DATA_POOL_NUM_BLOCKS) {
|
||||
// See the comment about not growing this on DATA_POOL_NUM_BLOCKS.
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!can_multiply(SIZE_MAX, pool->size, 2)) {
|
||||
return NULL;
|
||||
}
|
||||
size_t const new_size = pool->size * 2;
|
||||
|
||||
if (!can_multiply(SIZE_MAX, new_size, sizeof(MMDB_entry_data_list_s))) {
|
||||
return NULL;
|
||||
}
|
||||
pool->blocks[new_index] = calloc(new_size, sizeof(MMDB_entry_data_list_s));
|
||||
if (!pool->blocks[new_index]) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// We don't need to set this, but it's useful for introspection in tests.
|
||||
pool->blocks[new_index]->pool = pool;
|
||||
|
||||
pool->index = new_index;
|
||||
pool->block = pool->blocks[pool->index];
|
||||
|
||||
pool->size = new_size;
|
||||
pool->sizes[pool->index] = pool->size;
|
||||
|
||||
MMDB_entry_data_list_s *const element = pool->block;
|
||||
pool->used = 1;
|
||||
return element;
|
||||
}
|
||||
|
||||
// Turn the structs in the array-like pool into a linked list.
|
||||
//
|
||||
// Before calling this function, the list isn't linked up.
|
||||
MMDB_entry_data_list_s *data_pool_to_list(MMDB_data_pool_s *const pool)
|
||||
{
|
||||
if (!pool) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (pool->index == 0 && pool->used == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i <= pool->index; i++) {
|
||||
MMDB_entry_data_list_s *const block = pool->blocks[i];
|
||||
|
||||
size_t size = pool->sizes[i];
|
||||
if (i == pool->index) {
|
||||
size = pool->used;
|
||||
}
|
||||
|
||||
for (size_t j = 0; j < size - 1; j++) {
|
||||
MMDB_entry_data_list_s *const cur = block + j;
|
||||
cur->next = block + j + 1;
|
||||
}
|
||||
|
||||
if (i < pool->index) {
|
||||
MMDB_entry_data_list_s *const last = block + size - 1;
|
||||
last->next = pool->blocks[i + 1];
|
||||
}
|
||||
}
|
||||
|
||||
return pool->blocks[0];
|
||||
}
|
||||
|
||||
#ifdef TEST_DATA_POOL
|
||||
|
||||
#include <libtap/tap.h>
|
||||
#include <maxminddb_test_helper.h>
|
||||
|
||||
static void test_can_multiply(void);
|
||||
|
||||
int main(void)
|
||||
{
|
||||
plan(NO_PLAN);
|
||||
test_can_multiply();
|
||||
done_testing();
|
||||
}
|
||||
|
||||
static void test_can_multiply(void)
|
||||
{
|
||||
{
|
||||
ok(can_multiply(SIZE_MAX, 1, SIZE_MAX), "1*SIZE_MAX is ok");
|
||||
}
|
||||
|
||||
{
|
||||
ok(!can_multiply(SIZE_MAX, 2, SIZE_MAX), "2*SIZE_MAX is not ok");
|
||||
}
|
||||
|
||||
{
|
||||
ok(can_multiply(SIZE_MAX, 10240, sizeof(MMDB_entry_data_list_s)),
|
||||
"1024 entry_data_list_s's are okay");
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
52
external/MaxmindDB/data-pool.h
vendored
52
external/MaxmindDB/data-pool.h
vendored
@ -1,52 +0,0 @@
|
||||
#ifndef DATA_POOL_H
|
||||
#define DATA_POOL_H
|
||||
|
||||
#include "maxminddb.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
// This should be large enough that we never need to grow the array of pointers
|
||||
// to blocks. 32 is enough. Even starting out of with size 1 (1 struct), the
|
||||
// 32nd element alone will provide 2**32 structs as we exponentially increase
|
||||
// the number in each block. Being confident that we do not have to grow the
|
||||
// array lets us avoid writing code to do that. That code would be risky as it
|
||||
// would rarely be hit and likely not be well tested.
|
||||
#define DATA_POOL_NUM_BLOCKS 32
|
||||
|
||||
// A pool of memory for MMDB_entry_data_list_s structs. This is so we can
|
||||
// allocate multiple up front rather than one at a time for performance
|
||||
// reasons.
|
||||
//
|
||||
// The order you add elements to it (by calling data_pool_alloc()) ends up as
|
||||
// the order of the list.
|
||||
//
|
||||
// The memory only grows. There is no support for releasing an element you take
|
||||
// back to the pool.
|
||||
typedef struct MMDB_data_pool_s {
|
||||
// Index of the current block we're allocating out of.
|
||||
size_t index;
|
||||
|
||||
// The size of the current block, counting by structs.
|
||||
size_t size;
|
||||
|
||||
// How many used in the current block, counting by structs.
|
||||
size_t used;
|
||||
|
||||
// The current block we're allocating out of.
|
||||
MMDB_entry_data_list_s *block;
|
||||
|
||||
// The size of each block.
|
||||
size_t sizes[DATA_POOL_NUM_BLOCKS];
|
||||
|
||||
// An array of pointers to blocks of memory holding space for list
|
||||
// elements.
|
||||
MMDB_entry_data_list_s *blocks[DATA_POOL_NUM_BLOCKS];
|
||||
} MMDB_data_pool_s;
|
||||
|
||||
MMDB_data_pool_s *data_pool_new(size_t const);
|
||||
void data_pool_destroy(MMDB_data_pool_s *const);
|
||||
MMDB_entry_data_list_s *data_pool_alloc(MMDB_data_pool_s *const);
|
||||
MMDB_entry_data_list_s *data_pool_to_list(MMDB_data_pool_s *const);
|
||||
|
||||
#endif
|
167
external/MaxmindDB/maxminddb-compat-util.h
vendored
167
external/MaxmindDB/maxminddb-compat-util.h
vendored
@ -1,167 +0,0 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
|
||||
/* The memmem, strdup, and strndup functions were all copied from the
|
||||
* FreeBSD source, along with the relevant copyright notice.
|
||||
*
|
||||
* It'd be nicer to simply use the functions available on the system if they
|
||||
* exist, but there doesn't seem to be a good way to detect them without also
|
||||
* defining things like _GNU_SOURCE, which we want to avoid, because then we
|
||||
* end up _accidentally_ using GNU features without noticing, which then
|
||||
* breaks on systems like OSX.
|
||||
*
|
||||
* C is fun! */
|
||||
|
||||
/* Applies to memmem implementation */
|
||||
/*-
|
||||
* Copyright (c) 2005 Pascal Gloor <pascal.gloor@spale.com>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
static void *
|
||||
mmdb_memmem(const void *l, size_t l_len, const void *s, size_t s_len)
|
||||
{
|
||||
register char *cur, *last;
|
||||
const char *cl = (const char *)l;
|
||||
const char *cs = (const char *)s;
|
||||
|
||||
/* we need something to compare */
|
||||
if (l_len == 0 || s_len == 0)
|
||||
return NULL;
|
||||
|
||||
/* "s" must be smaller or equal to "l" */
|
||||
if (l_len < s_len)
|
||||
return NULL;
|
||||
|
||||
/* special case where s_len == 1 */
|
||||
if (s_len == 1)
|
||||
return memchr(l, (int)*cs, l_len);
|
||||
|
||||
/* the last position where its possible to find "s" in "l" */
|
||||
last = (char *)cl + l_len - s_len;
|
||||
|
||||
for (cur = (char *)cl; cur <= last; cur++)
|
||||
if (cur[0] == cs[0] && memcmp(cur, cs, s_len) == 0)
|
||||
return cur;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Applies to strnlen implementation */
|
||||
/*-
|
||||
* Copyright (c) 2009 David Schultz <das@FreeBSD.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
static size_t
|
||||
mmdb_strnlen(const char *s, size_t maxlen)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
for (len = 0; len < maxlen; len++, s++) {
|
||||
if (!*s)
|
||||
break;
|
||||
}
|
||||
return (len);
|
||||
}
|
||||
|
||||
/* Applies to strdup and strndup implementation */
|
||||
/*
|
||||
* Copyright (c) 1988, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
static char *
|
||||
mmdb_strdup(const char *str)
|
||||
{
|
||||
size_t len;
|
||||
char *copy;
|
||||
|
||||
len = strlen(str) + 1;
|
||||
if ((copy = malloc(len)) == NULL)
|
||||
return (NULL);
|
||||
memcpy(copy, str, len);
|
||||
return (copy);
|
||||
}
|
||||
|
||||
static char *
|
||||
mmdb_strndup(const char *str, size_t n)
|
||||
{
|
||||
size_t len;
|
||||
char *copy;
|
||||
|
||||
len = mmdb_strnlen(str, n);
|
||||
if ((copy = malloc(len + 1)) == NULL)
|
||||
return (NULL);
|
||||
memcpy(copy, str, len);
|
||||
copy[len] = '\0';
|
||||
return (copy);
|
||||
}
|
||||
/* *INDENT-ON* */
|
2153
external/MaxmindDB/maxminddb.c
vendored
2153
external/MaxmindDB/maxminddb.c
vendored
File diff suppressed because it is too large
Load Diff
0
external/PUGIXML/CMakeLists.txt
vendored
0
external/PUGIXML/CMakeLists.txt
vendored
22
external/PUGIXML/license.txt
vendored
22
external/PUGIXML/license.txt
vendored
@ -1,22 +0,0 @@
|
||||
Copyright (c) 2006-2016 Arseny Kapoulkine
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use,
|
||||
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
12859
external/PUGIXML/pugixml.cpp
vendored
12859
external/PUGIXML/pugixml.cpp
vendored
File diff suppressed because it is too large
Load Diff
0
external/SQLite/CMakeLists.txt
vendored
0
external/SQLite/CMakeLists.txt
vendored
69
external/SQLite/license.txt
vendored
69
external/SQLite/license.txt
vendored
@ -1,69 +0,0 @@
|
||||
Copyright Release for
|
||||
Contributions To SQLite
|
||||
|
||||
|
||||
SQLite is software that implements an embeddable SQL database engine.
|
||||
SQLite is available for free download from http://www.sqlite.org/.
|
||||
The principal author and maintainer of SQLite has disclaimed all
|
||||
copyright interest in his contributions to SQLite
|
||||
and thus released his contributions into the public domain.
|
||||
In order to keep the SQLite software unencumbered by copyright
|
||||
claims, the principal author asks others who may from time to
|
||||
time contribute changes and enhancements to likewise disclaim
|
||||
their own individual copyright interest.
|
||||
|
||||
Because the SQLite software found at http://www.sqlite.org/ is in the
|
||||
public domain, anyone is free to download the SQLite software
|
||||
from that website, make changes to the software, use, distribute,
|
||||
or sell the modified software, under either the original name or
|
||||
under some new name, without any need to obtain permission, pay
|
||||
royalties, acknowledge the original source of the software, or
|
||||
in any other way compensate, identify, or notify the original authors.
|
||||
Nobody is in any way compelled to contribute their SQLite changes and
|
||||
enhancements back to the SQLite website. This document concerns
|
||||
only changes and enhancements to SQLite that are intentionally and
|
||||
deliberately contributed back to the SQLite website.
|
||||
|
||||
For the purposes of this document, "SQLite software" shall mean any
|
||||
computer source code, documentation, makefiles, test scripts, or
|
||||
other information that is published on the SQLite website,
|
||||
http://www.sqlite.org/. Precompiled binaries are excluded from
|
||||
the definition of "SQLite software" in this document because the
|
||||
process of compiling the software may introduce information from
|
||||
outside sources which is not properly a part of SQLite.
|
||||
|
||||
The header comments on the SQLite source files exhort the reader to
|
||||
share freely and to never take more than one gives.
|
||||
In the spirit of that exhortation I make the following declarations:
|
||||
|
||||
1) I dedicate to the public domain
|
||||
any and all copyright interest in the SQLite software that
|
||||
was publicly available on the SQLite website (http://www.sqlite.org/) prior
|
||||
to the date of the signature below and any changes or enhancements to
|
||||
the SQLite software
|
||||
that I may cause to be published on that website in the future.
|
||||
I make this dedication for the benefit of the public at large and
|
||||
to the detriment of my heirs and successors. I intend this
|
||||
dedication to be an overt act of relinquishment in perpetuity of
|
||||
all present and future rights to the SQLite software under copyright
|
||||
law.
|
||||
|
||||
2) To the best of my knowledge and belief, the changes and enhancements that
|
||||
I have contributed to SQLite are either originally written by me
|
||||
or are derived from prior works which I have verified are also
|
||||
in the public domain and are not subject to claims of copyright
|
||||
by other parties.
|
||||
|
||||
3) To the best of my knowledge and belief, no individual, business, organization,
|
||||
government, or other entity has any copyright interest
|
||||
in the SQLite software as it existed on the
|
||||
SQLite website as of the date on the signature line below.
|
||||
|
||||
4) I agree never to publish any additional information
|
||||
to the SQLite website (by CVS, email, scp, FTP, or any other means) unless
|
||||
that information is an original work of authorship by me or is derived from
|
||||
prior published versions of SQLite.
|
||||
I agree never to copy and paste code into the SQLite code base from
|
||||
other sources.
|
||||
I agree never to publish on the SQLite website any information that
|
||||
would violate a law or breach a contract.
|
228449
external/SQLite/sqlite3.c
vendored
228449
external/SQLite/sqlite3.c
vendored
File diff suppressed because it is too large
Load Diff
0
external/SimpleINI/CMakeLists.txt
vendored
0
external/SimpleINI/CMakeLists.txt
vendored
@ -1,298 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2014 Petri Lehtinen <petri@digip.org>
|
||||
*
|
||||
* Jansson is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the MIT license. See LICENSE for details.
|
||||
*/
|
||||
|
||||
#ifndef JANSSON_H
|
||||
#define JANSSON_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h> /* for size_t */
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "jansson_config.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* version */
|
||||
|
||||
#define JANSSON_MAJOR_VERSION 2
|
||||
#define JANSSON_MINOR_VERSION 7
|
||||
#define JANSSON_MICRO_VERSION 0
|
||||
|
||||
/* Micro version is omitted if it's 0 */
|
||||
#define JANSSON_VERSION "2.7"
|
||||
|
||||
/* Version as a 3-byte hex number, e.g. 0x010201 == 1.2.1. Use this
|
||||
for numeric comparisons, e.g. #if JANSSON_VERSION_HEX >= ... */
|
||||
#define JANSSON_VERSION_HEX ((JANSSON_MAJOR_VERSION << 16) | \
|
||||
(JANSSON_MINOR_VERSION << 8) | \
|
||||
(JANSSON_MICRO_VERSION << 0))
|
||||
|
||||
|
||||
/* types */
|
||||
|
||||
typedef enum {
|
||||
JSON_OBJECT,
|
||||
JSON_ARRAY,
|
||||
JSON_STRING,
|
||||
JSON_INTEGER,
|
||||
JSON_REAL,
|
||||
JSON_TRUE,
|
||||
JSON_FALSE,
|
||||
JSON_NULL
|
||||
} json_type;
|
||||
|
||||
typedef struct json_t {
|
||||
json_type type;
|
||||
size_t refcount;
|
||||
} json_t;
|
||||
|
||||
#ifndef JANSSON_USING_CMAKE /* disabled if using cmake */
|
||||
#if JSON_INTEGER_IS_LONG_LONG
|
||||
#if defined(_WIN32) || defined(WIN32)
|
||||
#define JSON_INTEGER_FORMAT "I64d"
|
||||
#else
|
||||
#define JSON_INTEGER_FORMAT "lld"
|
||||
#endif
|
||||
typedef long long json_int_t;
|
||||
#else
|
||||
#define JSON_INTEGER_FORMAT "ld"
|
||||
typedef long json_int_t;
|
||||
#endif /* JSON_INTEGER_IS_LONG_LONG */
|
||||
#endif
|
||||
|
||||
#define json_typeof(json) ((json)->type)
|
||||
#define json_is_object(json) ((json) && json_typeof(json) == JSON_OBJECT)
|
||||
#define json_is_array(json) ((json) && json_typeof(json) == JSON_ARRAY)
|
||||
#define json_is_string(json) ((json) && json_typeof(json) == JSON_STRING)
|
||||
#define json_is_integer(json) ((json) && json_typeof(json) == JSON_INTEGER)
|
||||
#define json_is_real(json) ((json) && json_typeof(json) == JSON_REAL)
|
||||
#define json_is_number(json) (json_is_integer(json) || json_is_real(json))
|
||||
#define json_is_true(json) ((json) && json_typeof(json) == JSON_TRUE)
|
||||
#define json_is_false(json) ((json) && json_typeof(json) == JSON_FALSE)
|
||||
#define json_boolean_value json_is_true
|
||||
#define json_is_boolean(json) (json_is_true(json) || json_is_false(json))
|
||||
#define json_is_null(json) ((json) && json_typeof(json) == JSON_NULL)
|
||||
|
||||
/* construction, destruction, reference counting */
|
||||
|
||||
json_t *json_object(void);
|
||||
json_t *json_array(void);
|
||||
json_t *json_string(const char *value);
|
||||
json_t *json_stringn(const char *value, size_t len);
|
||||
json_t *json_string_nocheck(const char *value);
|
||||
json_t *json_stringn_nocheck(const char *value, size_t len);
|
||||
json_t *json_integer(json_int_t value);
|
||||
json_t *json_real(double value);
|
||||
json_t *json_true(void);
|
||||
json_t *json_false(void);
|
||||
#define json_boolean(val) ((val) ? json_true() : json_false())
|
||||
json_t *json_null(void);
|
||||
|
||||
static JSON_INLINE
|
||||
json_t *json_incref(json_t *json)
|
||||
{
|
||||
if(json && json->refcount != (size_t)-1)
|
||||
++json->refcount;
|
||||
return json;
|
||||
}
|
||||
|
||||
/* do not call json_delete directly */
|
||||
void json_delete(json_t *json);
|
||||
|
||||
static JSON_INLINE
|
||||
void json_decref(json_t *json)
|
||||
{
|
||||
if(json && json->refcount != (size_t)-1 && --json->refcount == 0)
|
||||
json_delete(json);
|
||||
}
|
||||
|
||||
|
||||
/* error reporting */
|
||||
|
||||
#define JSON_ERROR_TEXT_LENGTH 160
|
||||
#define JSON_ERROR_SOURCE_LENGTH 80
|
||||
|
||||
typedef struct {
|
||||
int line;
|
||||
int column;
|
||||
int position;
|
||||
char source[JSON_ERROR_SOURCE_LENGTH];
|
||||
char text[JSON_ERROR_TEXT_LENGTH];
|
||||
} json_error_t;
|
||||
|
||||
|
||||
/* getters, setters, manipulation */
|
||||
|
||||
void json_object_seed(size_t seed);
|
||||
size_t json_object_size(const json_t *object);
|
||||
json_t *json_object_get(const json_t *object, const char *key);
|
||||
int json_object_set_new(json_t *object, const char *key, json_t *value);
|
||||
int json_object_set_new_nocheck(json_t *object, const char *key, json_t *value);
|
||||
int json_object_del(json_t *object, const char *key);
|
||||
int json_object_clear(json_t *object);
|
||||
int json_object_update(json_t *object, json_t *other);
|
||||
int json_object_update_existing(json_t *object, json_t *other);
|
||||
int json_object_update_missing(json_t *object, json_t *other);
|
||||
void *json_object_iter(json_t *object);
|
||||
void *json_object_iter_at(json_t *object, const char *key);
|
||||
void *json_object_key_to_iter(const char *key);
|
||||
void *json_object_iter_next(json_t *object, void *iter);
|
||||
const char *json_object_iter_key(void *iter);
|
||||
json_t *json_object_iter_value(void *iter);
|
||||
int json_object_iter_set_new(json_t *object, void *iter, json_t *value);
|
||||
|
||||
#define json_object_foreach(object, key, value) \
|
||||
for(key = json_object_iter_key(json_object_iter(object)); \
|
||||
key && (value = json_object_iter_value(json_object_key_to_iter(key))); \
|
||||
key = json_object_iter_key(json_object_iter_next(object, json_object_key_to_iter(key))))
|
||||
|
||||
#define json_object_foreach_safe(object, n, key, value) \
|
||||
for(key = json_object_iter_key(json_object_iter(object)), \
|
||||
n = json_object_iter_next(object, json_object_key_to_iter(key)); \
|
||||
key && (value = json_object_iter_value(json_object_key_to_iter(key))); \
|
||||
key = json_object_iter_key(n), \
|
||||
n = json_object_iter_next(object, json_object_key_to_iter(key)))
|
||||
|
||||
#define json_array_foreach(array, index, value) \
|
||||
for(index = 0; \
|
||||
index < json_array_size(array) && (value = json_array_get(array, index)); \
|
||||
index++)
|
||||
|
||||
static JSON_INLINE
|
||||
int json_object_set(json_t *object, const char *key, json_t *value)
|
||||
{
|
||||
return json_object_set_new(object, key, json_incref(value));
|
||||
}
|
||||
|
||||
static JSON_INLINE
|
||||
int json_object_set_nocheck(json_t *object, const char *key, json_t *value)
|
||||
{
|
||||
return json_object_set_new_nocheck(object, key, json_incref(value));
|
||||
}
|
||||
|
||||
static JSON_INLINE
|
||||
int json_object_iter_set(json_t *object, void *iter, json_t *value)
|
||||
{
|
||||
return json_object_iter_set_new(object, iter, json_incref(value));
|
||||
}
|
||||
|
||||
size_t json_array_size(const json_t *array);
|
||||
json_t *json_array_get(const json_t *array, size_t index);
|
||||
int json_array_set_new(json_t *array, size_t index, json_t *value);
|
||||
int json_array_append_new(json_t *array, json_t *value);
|
||||
int json_array_insert_new(json_t *array, size_t index, json_t *value);
|
||||
int json_array_remove(json_t *array, size_t index);
|
||||
int json_array_clear(json_t *array);
|
||||
int json_array_extend(json_t *array, json_t *other);
|
||||
|
||||
static JSON_INLINE
|
||||
int json_array_set(json_t *array, size_t ind, json_t *value)
|
||||
{
|
||||
return json_array_set_new(array, ind, json_incref(value));
|
||||
}
|
||||
|
||||
static JSON_INLINE
|
||||
int json_array_append(json_t *array, json_t *value)
|
||||
{
|
||||
return json_array_append_new(array, json_incref(value));
|
||||
}
|
||||
|
||||
static JSON_INLINE
|
||||
int json_array_insert(json_t *array, size_t ind, json_t *value)
|
||||
{
|
||||
return json_array_insert_new(array, ind, json_incref(value));
|
||||
}
|
||||
|
||||
const char *json_string_value(const json_t *string);
|
||||
size_t json_string_length(const json_t *string);
|
||||
json_int_t json_integer_value(const json_t *integer);
|
||||
double json_real_value(const json_t *real);
|
||||
double json_number_value(const json_t *json);
|
||||
|
||||
int json_string_set(json_t *string, const char *value);
|
||||
int json_string_setn(json_t *string, const char *value, size_t len);
|
||||
int json_string_set_nocheck(json_t *string, const char *value);
|
||||
int json_string_setn_nocheck(json_t *string, const char *value, size_t len);
|
||||
int json_integer_set(json_t *integer, json_int_t value);
|
||||
int json_real_set(json_t *real, double value);
|
||||
|
||||
/* pack, unpack */
|
||||
|
||||
json_t *json_pack(const char *fmt, ...);
|
||||
json_t *json_pack_ex(json_error_t *error, size_t flags, const char *fmt, ...);
|
||||
json_t *json_vpack_ex(json_error_t *error, size_t flags, const char *fmt, va_list ap);
|
||||
|
||||
#define JSON_VALIDATE_ONLY 0x1
|
||||
#define JSON_STRICT 0x2
|
||||
|
||||
int json_unpack(json_t *root, const char *fmt, ...);
|
||||
int json_unpack_ex(json_t *root, json_error_t *error, size_t flags, const char *fmt, ...);
|
||||
int json_vunpack_ex(json_t *root, json_error_t *error, size_t flags, const char *fmt, va_list ap);
|
||||
|
||||
|
||||
/* equality */
|
||||
|
||||
int json_equal(json_t *value1, json_t *value2);
|
||||
|
||||
|
||||
/* copying */
|
||||
|
||||
json_t *json_copy(json_t *value);
|
||||
json_t *json_deep_copy(const json_t *value);
|
||||
|
||||
|
||||
/* decoding */
|
||||
|
||||
#define JSON_REJECT_DUPLICATES 0x1
|
||||
#define JSON_DISABLE_EOF_CHECK 0x2
|
||||
#define JSON_DECODE_ANY 0x4
|
||||
#define JSON_DECODE_INT_AS_REAL 0x8
|
||||
#define JSON_ALLOW_NUL 0x10
|
||||
|
||||
typedef size_t (*json_load_callback_t)(void *buffer, size_t buflen, void *data);
|
||||
|
||||
json_t *json_loads(const char *input, size_t flags, json_error_t *error);
|
||||
json_t *json_loadb(const char *buffer, size_t buflen, size_t flags, json_error_t *error);
|
||||
json_t *json_loadf(FILE *input, size_t flags, json_error_t *error);
|
||||
json_t *json_load_file(const char *path, size_t flags, json_error_t *error);
|
||||
json_t *json_load_callback(json_load_callback_t callback, void *data, size_t flags, json_error_t *error);
|
||||
|
||||
|
||||
/* encoding */
|
||||
|
||||
#define JSON_MAX_INDENT 0x1F
|
||||
#define JSON_INDENT(n) ((n) & JSON_MAX_INDENT)
|
||||
#define JSON_COMPACT 0x20
|
||||
#define JSON_ENSURE_ASCII 0x40
|
||||
#define JSON_SORT_KEYS 0x80
|
||||
#define JSON_PRESERVE_ORDER 0x100
|
||||
#define JSON_ENCODE_ANY 0x200
|
||||
#define JSON_ESCAPE_SLASH 0x400
|
||||
#define JSON_REAL_PRECISION(n) (((n) & 0x1F) << 11)
|
||||
|
||||
typedef int (*json_dump_callback_t)(const char *buffer, size_t size, void *data);
|
||||
|
||||
char *json_dumps(const json_t *json, size_t flags);
|
||||
int json_dumpf(const json_t *json, FILE *output, size_t flags);
|
||||
int json_dump_file(const json_t *json, const char *path, size_t flags);
|
||||
int json_dump_callback(const json_t *json, json_dump_callback_t callback, void *data, size_t flags);
|
||||
|
||||
/* custom memory allocation */
|
||||
|
||||
typedef void *(*json_malloc_t)(size_t);
|
||||
typedef void (*json_free_t)(void *);
|
||||
|
||||
void json_set_alloc_funcs(json_malloc_t malloc_fn, json_free_t free_fn);
|
||||
void json_get_alloc_funcs(json_malloc_t *malloc_fn, json_free_t *free_fn);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,71 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2010-2014 Petri Lehtinen <petri@digip.org>
|
||||
*
|
||||
* Jansson is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the MIT license. See LICENSE for details.
|
||||
*
|
||||
*
|
||||
* This file specifies a part of the site-specific configuration for
|
||||
* Jansson, namely those things that affect the public API in
|
||||
* jansson.h.
|
||||
*
|
||||
* The CMake system will generate the jansson_config.h file and
|
||||
* copy it to the build and install directories.
|
||||
*/
|
||||
|
||||
#ifndef JANSSON_CONFIG_H
|
||||
#define JANSSON_CONFIG_H
|
||||
|
||||
/* Define this so that we can disable scattered automake configuration in source files */
|
||||
#ifndef JANSSON_USING_CMAKE
|
||||
#define JANSSON_USING_CMAKE
|
||||
#endif
|
||||
|
||||
/* Note: when using cmake, JSON_INTEGER_IS_LONG_LONG is not defined nor used,
|
||||
* as we will also check for __int64 etc types.
|
||||
* (the definition was used in the automake system) */
|
||||
|
||||
/* Bring in the cmake-detected defines */
|
||||
#define HAVE_STDINT_H 1
|
||||
/* #undef HAVE_INTTYPES_H */
|
||||
#define HAVE_SYS_TYPES_H 1
|
||||
|
||||
/* Include our standard type header for the integer typedef */
|
||||
|
||||
#if defined(HAVE_STDINT_H)
|
||||
# include <stdint.h>
|
||||
#elif defined(HAVE_INTTYPES_H)
|
||||
# include <inttypes.h>
|
||||
#elif defined(HAVE_SYS_TYPES_H)
|
||||
# include <sys/types.h>
|
||||
#endif
|
||||
|
||||
|
||||
/* If your compiler supports the inline keyword in C, JSON_INLINE is
|
||||
defined to `inline', otherwise empty. In C++, the inline is always
|
||||
supported. */
|
||||
#ifdef __cplusplus
|
||||
#define JSON_INLINE inline
|
||||
#else
|
||||
#define JSON_INLINE inline
|
||||
#endif
|
||||
|
||||
|
||||
#define json_int_t long long
|
||||
#define json_strtoint strtoll
|
||||
#if defined(_WIN32) || defined(WIN32)
|
||||
#define JSON_INTEGER_FORMAT "I64d"
|
||||
#else
|
||||
#define JSON_INTEGER_FORMAT "lld"
|
||||
#endif
|
||||
|
||||
/* If locale.h and localeconv() are available, define to 1, otherwise to 0. */
|
||||
#define JSON_HAVE_LOCALECONV 1
|
||||
|
||||
|
||||
/* Maximum recursion depth for parsing JSON input.
|
||||
This limits the depth of e.g. array-within-array constructions. */
|
||||
#define JSON_PARSER_MAX_DEPTH 2048
|
||||
|
||||
|
||||
#endif
|
@ -1,53 +0,0 @@
|
||||
#define HAVE_ENDIAN_H 1
|
||||
#define HAVE_FCNTL_H 1
|
||||
#define HAVE_SCHED_H 1
|
||||
#define HAVE_UNISTD_H 1
|
||||
#define HAVE_SYS_PARAM_H 1
|
||||
#define HAVE_SYS_STAT_H 1
|
||||
#define HAVE_SYS_TIME_H 1
|
||||
#define HAVE_SYS_TYPES_H 1
|
||||
#define HAVE_STDINT_H 1
|
||||
|
||||
#define HAVE_CLOSE 1
|
||||
#define HAVE_GETPID 1
|
||||
#define HAVE_GETTIMEOFDAY 1
|
||||
#define HAVE_OPEN 1
|
||||
#define HAVE_READ 1
|
||||
#define HAVE_SCHED_YIELD 1
|
||||
|
||||
#define HAVE_SYNC_BUILTINS 1
|
||||
#define HAVE_ATOMIC_BUILTINS 1
|
||||
|
||||
#define HAVE_LOCALE_H 1
|
||||
#define HAVE_SETLOCALE 1
|
||||
|
||||
#define HAVE_INT32_T 1
|
||||
#ifndef HAVE_INT32_T
|
||||
# define int32_t int32_t
|
||||
#endif
|
||||
|
||||
#define HAVE_UINT32_T 1
|
||||
#ifndef HAVE_UINT32_T
|
||||
# define uint32_t uint32_t
|
||||
#endif
|
||||
|
||||
#define HAVE_UINT16_T 1
|
||||
#ifndef HAVE_UINT16_T
|
||||
# define uint16_t uint16_t
|
||||
#endif
|
||||
|
||||
#define HAVE_UINT8_T 1
|
||||
#ifndef HAVE_UINT8_T
|
||||
# define uint8_t uint8_t
|
||||
#endif
|
||||
|
||||
#define HAVE_SSIZE_T 1
|
||||
|
||||
#ifndef HAVE_SSIZE_T
|
||||
# define ssize_t
|
||||
#endif
|
||||
|
||||
#define USE_URANDOM 1
|
||||
#define USE_WINDOWS_CRYPTOAPI 1
|
||||
|
||||
#define INITIAL_HASHTABLE_ORDER 3
|
@ -1,235 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2012 George Yunaev gyunaev@ulduzsoft.com
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDE_IRC_ERRORS_H
|
||||
#define INCLUDE_IRC_ERRORS_H
|
||||
|
||||
#ifndef IN_INCLUDE_LIBIRC_H
|
||||
#error This file should not be included directly, include just libircclient.h
|
||||
#endif
|
||||
|
||||
|
||||
/*! brief No error
|
||||
* \ingroup errorcodes
|
||||
*/
|
||||
#define LIBIRC_ERR_OK 0
|
||||
|
||||
|
||||
/*! \brief Invalid argument
|
||||
*
|
||||
* An invalid value was given for one of the arguments to a function.
|
||||
* For example, supplying the NULL value for \a channel argument of
|
||||
* irc_cmd_join() produces LIBIRC_ERR_INVAL error. You should fix the code.
|
||||
*
|
||||
* \ingroup errorcodes
|
||||
*/
|
||||
#define LIBIRC_ERR_INVAL 1
|
||||
|
||||
|
||||
/*! \brief Could not resolve host.
|
||||
*
|
||||
* The host name supplied for irc_connect() function could not be resolved
|
||||
* into valid IP address. Usually means that host name is invalid.
|
||||
*
|
||||
* \ingroup errorcodes
|
||||
*/
|
||||
#define LIBIRC_ERR_RESOLV 2
|
||||
|
||||
|
||||
/*! \brief Could not create socket.
|
||||
*
|
||||
* The new socket could not be created or made non-blocking. Usually means
|
||||
* that the server is out of resources, or (rarely :) a bug in libircclient.
|
||||
*
|
||||
* \ingroup errorcodes
|
||||
*/
|
||||
#define LIBIRC_ERR_SOCKET 3
|
||||
|
||||
|
||||
/*! \brief Could not connect.
|
||||
*
|
||||
* The socket could not connect to the IRC server, or to the destination DCC
|
||||
* part. Usually means that either the IRC server is down or its address is
|
||||
* invalid. For DCC the reason usually is the firewall on your or destination
|
||||
* computer, which refuses DCC transfer.
|
||||
*
|
||||
* \sa irc_run irc_connect
|
||||
* \ingroup errorcodes
|
||||
*/
|
||||
#define LIBIRC_ERR_CONNECT 4
|
||||
|
||||
|
||||
/*! \brief Connection closed by remote peer.
|
||||
*
|
||||
* The IRC connection was closed by the IRC server (which could mean that an
|
||||
* IRC operator just have banned you from the server :)), or the DCC connection
|
||||
* was closed by remote peer - for example, the other side just quits his mIrc.
|
||||
* Usually it is not an error.
|
||||
*
|
||||
* \sa irc_run irc_connect irc_dcc_callback_t
|
||||
* \ingroup errorcodes
|
||||
*/
|
||||
#define LIBIRC_ERR_CLOSED 5
|
||||
|
||||
|
||||
/*! \brief Out of memory
|
||||
*
|
||||
* There are two possible reasons for this error. First is that memory could
|
||||
* not be allocated for libircclient use, and this error usually is fatal.
|
||||
* Second reason is that the command queue (which keeps command ready to be
|
||||
* sent to the IRC server) is full, and could not accept more commands yet.
|
||||
* In this case you should just wait, and repeat the command later.
|
||||
*
|
||||
* \ingroup errorcodes
|
||||
*/
|
||||
#define LIBIRC_ERR_NOMEM 6
|
||||
|
||||
|
||||
/*! \brief Could not accept new connection
|
||||
*
|
||||
* A DCC chat/send connection from the remote peer could not be accepted.
|
||||
* Either the connection was just terminated before it is accepted, or there
|
||||
* is a bug in libircclient.
|
||||
*
|
||||
* \ingroup errorcodes
|
||||
*/
|
||||
#define LIBIRC_ERR_ACCEPT 7
|
||||
|
||||
|
||||
/*! \brief Could not send this
|
||||
*
|
||||
* A \a filename supplied to irc_dcc_sendfile() could not be sent. Either is
|
||||
* is not a file (a directory or a socket, for example), or it is not readable. *
|
||||
*
|
||||
* \sa LIBIRC_ERR_OPENFILE
|
||||
* \ingroup errorcodes
|
||||
*/
|
||||
#define LIBIRC_ERR_NODCCSEND 9
|
||||
|
||||
|
||||
/*! \brief Could not read DCC file or socket
|
||||
*
|
||||
* Either a DCC file could not be read (for example, was truncated during
|
||||
* sending), or a DCC socket returns a read error, which usually means that
|
||||
* the network connection is terminated.
|
||||
*
|
||||
* \ingroup errorcodes
|
||||
*/
|
||||
#define LIBIRC_ERR_READ 10
|
||||
|
||||
|
||||
/*! \brief Could not write DCC file or socket
|
||||
*
|
||||
* Either a DCC file could not be written (for example, there is no free space
|
||||
* on disk), or a DCC socket returns a write error, which usually means that
|
||||
* the network connection is terminated.
|
||||
*
|
||||
* \ingroup errorcodes
|
||||
*/
|
||||
#define LIBIRC_ERR_WRITE 11
|
||||
|
||||
|
||||
/*! \brief Invalid state
|
||||
*
|
||||
* The function is called when it is not allowed to be called. For example,
|
||||
* irc_cmd_join() was called before the connection to IRC server succeed, and
|
||||
* ::event_connect is called.
|
||||
*
|
||||
* \ingroup errorcodes
|
||||
*/
|
||||
#define LIBIRC_ERR_STATE 12
|
||||
|
||||
|
||||
/*! \brief Operation timed out
|
||||
*
|
||||
* The DCC request is timed out.
|
||||
* There is a timer for each DCC request, which tracks connecting, accepting
|
||||
* and non-accepted/declined DCC requests. For every request this timer
|
||||
* is currently 60 seconds. If the DCC request was not connected, accepted
|
||||
* or declined during this time, it will be terminated with this error.
|
||||
*
|
||||
* \ingroup errorcodes
|
||||
*/
|
||||
#define LIBIRC_ERR_TIMEOUT 13
|
||||
|
||||
|
||||
/*! \brief Could not open file for DCC send
|
||||
*
|
||||
* The file specified in irc_dcc_sendfile() could not be opened.
|
||||
*
|
||||
* \ingroup errorcodes
|
||||
*/
|
||||
#define LIBIRC_ERR_OPENFILE 14
|
||||
|
||||
|
||||
/*! \brief IRC server connection terminated
|
||||
*
|
||||
* The connection to the IRC server was terminated - possibly, by network
|
||||
* error. Try to irc_connect() again.
|
||||
*
|
||||
* \ingroup errorcodes
|
||||
*/
|
||||
#define LIBIRC_ERR_TERMINATED 15
|
||||
|
||||
|
||||
/*! \brief IPv6 not supported
|
||||
*
|
||||
* The function which requires IPv6 support was called, but the IPv6 support was not compiled
|
||||
* into the application
|
||||
*
|
||||
* \ingroup errorcodes
|
||||
*/
|
||||
#define LIBIRC_ERR_NOIPV6 16
|
||||
|
||||
|
||||
/*! \brief SSL not supported
|
||||
*
|
||||
* The SSL connection was required but the library was not compiled with SSL support
|
||||
*
|
||||
* \ingroup errorcodes
|
||||
*/
|
||||
#define LIBIRC_ERR_SSL_NOT_SUPPORTED 17
|
||||
|
||||
|
||||
/*! \brief SSL initialization failed
|
||||
*
|
||||
* The SSL connection was required but the library was not compiled with SSL support
|
||||
*
|
||||
* \ingroup errorcodes
|
||||
*/
|
||||
#define LIBIRC_ERR_SSL_INIT_FAILED 18
|
||||
|
||||
|
||||
/*! \brief SSL connection failed
|
||||
*
|
||||
* SSL handshare failed when attempting to connect to the server. Typically this means you're trying
|
||||
* to use SSL but attempting to connect to a non-SSL port.
|
||||
* \ingroup errorcodes
|
||||
*/
|
||||
#define LIBIRC_ERR_CONNECT_SSL_FAILED 19
|
||||
|
||||
|
||||
/*! \brief SSL certificate verify failed
|
||||
*
|
||||
* The server is using the self-signed certificate. Use LIBIRC_OPTION_SSL_NO_VERIFY option to connect to it.
|
||||
* \ingroup errorcodes
|
||||
*/
|
||||
#define LIBIRC_ERR_SSL_CERT_VERIFY_FAILED 20
|
||||
|
||||
|
||||
// Internal max error value count.
|
||||
// If you added more errors, add them to errors.c too!
|
||||
#define LIBIRC_ERR_MAX 21
|
||||
|
||||
#endif /* INCLUDE_IRC_ERRORS_H */
|
@ -1,389 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2012 George Yunaev gyunaev@ulduzsoft.com
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef INCLUDE_IRC_EVENTS_H
|
||||
#define INCLUDE_IRC_EVENTS_H
|
||||
|
||||
|
||||
#ifndef IN_INCLUDE_LIBIRC_H
|
||||
#error This file should not be included directly, include just libircclient.h
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
* \fn typedef void (*irc_event_callback_t) (irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count)
|
||||
* \brief A most common event callback
|
||||
*
|
||||
* \param session the session, which generates an event
|
||||
* \param event the text name of the event. Useful in case you use a single
|
||||
* event handler for several events simultaneously.
|
||||
* \param origin the originator of the event. See the note below.
|
||||
* \param params a list of event params. Depending on the event nature, it
|
||||
* could have zero or more params. The actual number of params
|
||||
* is specified in count. None of the params can be NULL, but
|
||||
* 'params' pointer itself could be NULL for some events.
|
||||
* \param count the total number of params supplied.
|
||||
*
|
||||
* Every event generates a callback. This callback is generated by most events.
|
||||
* Depending on the event nature, it can provide zero or more params. For each
|
||||
* event, the number of provided params is fixed, and their meaning is
|
||||
* described.
|
||||
*
|
||||
* Every event has origin, though the \a origin variable may be NULL, which
|
||||
* means that event origin is unknown. The origin usually looks like
|
||||
* nick!host\@ircserver, i.e. like tim!home\@irc.krasnogorsk.ru. Such origins
|
||||
* can not be used in IRC commands, and need to be stripped (i.e. host and
|
||||
* server part should be cut off) before using. This can be done either
|
||||
* explicitly, by calling irc_target_get_nick(), or implicitly for all the
|
||||
* events - by setting the #LIBIRC_OPTION_STRIPNICKS option with irc_option_set().
|
||||
*
|
||||
* \ingroup events
|
||||
*/
|
||||
typedef void (*irc_event_callback_t) (irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count);
|
||||
|
||||
|
||||
/*!
|
||||
* \fn typedef void (*irc_eventcode_callback_t) (irc_session_t * session, unsigned int event, const char * origin, const char ** params, unsigned int count)
|
||||
* \brief A numeric event callback
|
||||
*
|
||||
* \param session the session, which generates an event
|
||||
* \param event the numeric code of the event. Useful in case you use a
|
||||
* single event handler for several events simultaneously.
|
||||
* \param origin the originator of the event. See the note below.
|
||||
* \param params a list of event params. Depending on the event nature, it
|
||||
* could have zero or more params. The actual number of params
|
||||
* is specified in count. None of the params can be NULL, but
|
||||
* 'params' pointer itself could be NULL for some events.
|
||||
* \param count the total number of params supplied.
|
||||
*
|
||||
* Most times in reply to your actions the IRC server generates numeric
|
||||
* callbacks. Most of them are error codes, and some of them mark list start
|
||||
* and list stop markers. Every code has its own set of params; for details
|
||||
* you can either experiment, or read RFC 1459.
|
||||
*
|
||||
* Every event has origin, though the \a origin variable may be NULL, which
|
||||
* means that event origin is unknown. The origin usually looks like
|
||||
* nick!host\@ircserver, i.e. like tim!home\@irc.krasnogorsk.ru. Such origins
|
||||
* can not be used in IRC commands, and need to be stripped (i.e. host and
|
||||
* server part should be cut off) before using. This can be done either
|
||||
* explicitly, by calling irc_target_get_nick(), or implicitly for all the
|
||||
* events - by setting the #LIBIRC_OPTION_STRIPNICKS option with irc_option_set().
|
||||
*
|
||||
* \ingroup events
|
||||
*/
|
||||
typedef void (*irc_eventcode_callback_t) (irc_session_t * session, unsigned int event, const char * origin, const char ** params, unsigned int count);
|
||||
|
||||
|
||||
/*!
|
||||
* \fn typedef void (*irc_event_dcc_chat_t) (irc_session_t * session, const char * nick, const char * addr, irc_dcc_t dccid)
|
||||
* \brief A remote DCC CHAT request callback
|
||||
*
|
||||
* \param session the session, which generates an event
|
||||
* \param nick the person who requested DCC CHAT with you.
|
||||
* \param addr the person's IP address in decimal-dot notation.
|
||||
* \param dccid an id associated with this request. Use it in calls to
|
||||
* irc_dcc_accept() or irc_dcc_decline().
|
||||
*
|
||||
* This callback is called when someone requests DCC CHAT with you. In respond
|
||||
* you should call either irc_dcc_accept() to accept chat request, or
|
||||
* irc_dcc_decline() to decline chat request.
|
||||
*
|
||||
* \sa irc_dcc_accept or irc_dcc_decline
|
||||
* \ingroup events
|
||||
*/
|
||||
typedef void (*irc_event_dcc_chat_t) (irc_session_t * session, const char * nick, const char * addr, irc_dcc_t dccid);
|
||||
|
||||
|
||||
/*!
|
||||
* \fn typedef void (*irc_event_dcc_send_t) (irc_session_t * session, const char * nick, const char * addr, const char * filename, unsigned long size, irc_dcc_t dccid)
|
||||
* \brief A remote DCC CHAT request callback
|
||||
*
|
||||
* \param session the session, which generates an event
|
||||
* \param nick the person who requested DCC CHAT with you.
|
||||
* \param addr the person's IP address in decimal-dot notation.
|
||||
* \param filename the sent filename.
|
||||
* \param size the filename size.
|
||||
* \param dccid an id associated with this request. Use it in calls to
|
||||
* irc_dcc_accept() or irc_dcc_decline().
|
||||
*
|
||||
* This callback is called when someone wants to send a file to you using
|
||||
* DCC SEND. As with chat, in respond you should call either irc_dcc_accept()
|
||||
* to accept this request and receive the file, or irc_dcc_decline() to
|
||||
* decline this request.
|
||||
*
|
||||
* \sa irc_dcc_accept or irc_dcc_decline
|
||||
* \ingroup events
|
||||
*/
|
||||
typedef void (*irc_event_dcc_send_t) (irc_session_t * session, const char * nick, const char * addr, const char * filename, unsigned long size, irc_dcc_t dccid);
|
||||
|
||||
|
||||
/*! \brief Event callbacks structure.
|
||||
*
|
||||
* All the communication with the IRC network is based on events. Generally
|
||||
* speaking, event is anything generated by someone else in the network,
|
||||
* or by the IRC server itself. "Someone sends you a message", "Someone
|
||||
* has joined the channel", "Someone has quits IRC" - all these messages
|
||||
* are events.
|
||||
*
|
||||
* Every event has its own event handler, which is called when the
|
||||
* appropriate event is received. You don't have to define all the event
|
||||
* handlers; define only the handlers for the events you need to intercept.
|
||||
*
|
||||
* Most event callbacks are the types of ::irc_event_callback_t. There are
|
||||
* also events, which generate ::irc_eventcode_callback_t,
|
||||
* ::irc_event_dcc_chat_t and ::irc_event_dcc_send_t callbacks.
|
||||
*
|
||||
* \ingroup events
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
/*!
|
||||
* The "on_connect" event is triggered when the client successfully
|
||||
* connects to the server, and could send commands to the server.
|
||||
* No extra params supplied; \a params is 0.
|
||||
*/
|
||||
irc_event_callback_t event_connect;
|
||||
|
||||
/*!
|
||||
* The "nick" event is triggered when the client receives a NICK message,
|
||||
* meaning that someone (including you) on a channel with the client has
|
||||
* changed their nickname.
|
||||
*
|
||||
* \param origin the person, who changes the nick. Note that it can be you!
|
||||
* \param params[0] mandatory, contains the new nick.
|
||||
*/
|
||||
irc_event_callback_t event_nick;
|
||||
|
||||
/*!
|
||||
* The "quit" event is triggered upon receipt of a QUIT message, which
|
||||
* means that someone on a channel with the client has disconnected.
|
||||
*
|
||||
* \param origin the person, who is disconnected
|
||||
* \param params[0] optional, contains the reason message (user-specified).
|
||||
*/
|
||||
irc_event_callback_t event_quit;
|
||||
|
||||
/*!
|
||||
* The "join" event is triggered upon receipt of a JOIN message, which
|
||||
* means that someone has entered a channel that the client is on.
|
||||
*
|
||||
* \param origin the person, who joins the channel. By comparing it with
|
||||
* your own nickname, you can check whether your JOIN
|
||||
* command succeed.
|
||||
* \param params[0] mandatory, contains the channel name.
|
||||
*/
|
||||
irc_event_callback_t event_join;
|
||||
|
||||
/*!
|
||||
* The "part" event is triggered upon receipt of a PART message, which
|
||||
* means that someone has left a channel that the client is on.
|
||||
*
|
||||
* \param origin the person, who leaves the channel. By comparing it with
|
||||
* your own nickname, you can check whether your PART
|
||||
* command succeed.
|
||||
* \param params[0] mandatory, contains the channel name.
|
||||
* \param params[1] optional, contains the reason message (user-defined).
|
||||
*/
|
||||
irc_event_callback_t event_part;
|
||||
|
||||
/*!
|
||||
* The "mode" event is triggered upon receipt of a channel MODE message,
|
||||
* which means that someone on a channel with the client has changed the
|
||||
* channel's parameters.
|
||||
*
|
||||
* \param origin the person, who changed the channel mode.
|
||||
* \param params[0] mandatory, contains the channel name.
|
||||
* \param params[1] mandatory, contains the changed channel mode, like
|
||||
* '+t', '-i' and so on.
|
||||
* \param params[2] optional, contains the mode argument (for example, a
|
||||
* key for +k mode, or user who got the channel operator status for
|
||||
* +o mode)
|
||||
*/
|
||||
irc_event_callback_t event_mode;
|
||||
|
||||
/*!
|
||||
* The "umode" event is triggered upon receipt of a user MODE message,
|
||||
* which means that your user mode has been changed.
|
||||
*
|
||||
* \param origin the person, who changed the channel mode.
|
||||
* \param params[0] mandatory, contains the user changed mode, like
|
||||
* '+t', '-i' and so on.
|
||||
*/
|
||||
irc_event_callback_t event_umode;
|
||||
|
||||
/*!
|
||||
* The "topic" event is triggered upon receipt of a TOPIC message, which
|
||||
* means that someone on a channel with the client has changed the
|
||||
* channel's topic.
|
||||
*
|
||||
* \param origin the person, who changes the channel topic.
|
||||
* \param params[0] mandatory, contains the channel name.
|
||||
* \param params[1] optional, contains the new topic.
|
||||
*/
|
||||
irc_event_callback_t event_topic;
|
||||
|
||||
/*!
|
||||
* The "kick" event is triggered upon receipt of a KICK message, which
|
||||
* means that someone on a channel with the client (or possibly the
|
||||
* client itself!) has been forcibly ejected.
|
||||
*
|
||||
* \param origin the person, who kicked the poor.
|
||||
* \param params[0] mandatory, contains the channel name.
|
||||
* \param params[0] optional, contains the nick of kicked person.
|
||||
* \param params[1] optional, contains the kick text
|
||||
*/
|
||||
irc_event_callback_t event_kick;
|
||||
|
||||
/*!
|
||||
* The "channel" event is triggered upon receipt of a PRIVMSG message
|
||||
* to an entire channel, which means that someone on a channel with
|
||||
* the client has said something aloud. Your own messages don't trigger
|
||||
* PRIVMSG event.
|
||||
*
|
||||
* \param origin the person, who generates the message.
|
||||
* \param params[0] mandatory, contains the channel name.
|
||||
* \param params[1] optional, contains the message text
|
||||
*/
|
||||
irc_event_callback_t event_channel;
|
||||
|
||||
/*!
|
||||
* The "privmsg" event is triggered upon receipt of a PRIVMSG message
|
||||
* which is addressed to one or more clients, which means that someone
|
||||
* is sending the client a private message.
|
||||
*
|
||||
* \param origin the person, who generates the message.
|
||||
* \param params[0] mandatory, contains your nick.
|
||||
* \param params[1] optional, contains the message text
|
||||
*/
|
||||
irc_event_callback_t event_privmsg;
|
||||
|
||||
/*!
|
||||
* The "notice" event is triggered upon receipt of a NOTICE message
|
||||
* which means that someone has sent the client a public or private
|
||||
* notice. According to RFC 1459, the only difference between NOTICE
|
||||
* and PRIVMSG is that you should NEVER automatically reply to NOTICE
|
||||
* messages. Unfortunately, this rule is frequently violated by IRC
|
||||
* servers itself - for example, NICKSERV messages require reply, and
|
||||
* are NOTICEs.
|
||||
*
|
||||
* \param origin the person, who generates the message.
|
||||
* \param params[0] mandatory, contains the target nick name.
|
||||
* \param params[1] optional, contains the message text
|
||||
*/
|
||||
irc_event_callback_t event_notice;
|
||||
|
||||
/*!
|
||||
* The "channel_notice" event is triggered upon receipt of a NOTICE
|
||||
* message which means that someone has sent the client a public
|
||||
* notice. According to RFC 1459, the only difference between NOTICE
|
||||
* and PRIVMSG is that you should NEVER automatically reply to NOTICE
|
||||
* messages. Unfortunately, this rule is frequently violated by IRC
|
||||
* servers itself - for example, NICKSERV messages require reply, and
|
||||
* are NOTICEs.
|
||||
*
|
||||
* \param origin the person, who generates the message.
|
||||
* \param params[0] mandatory, contains the channel name.
|
||||
* \param params[1] optional, contains the message text
|
||||
*/
|
||||
irc_event_callback_t event_channel_notice;
|
||||
|
||||
/*!
|
||||
* The "invite" event is triggered upon receipt of an INVITE message,
|
||||
* which means that someone is permitting the client's entry into a +i
|
||||
* channel.
|
||||
*
|
||||
* \param origin the person, who INVITEs you.
|
||||
* \param params[0] mandatory, contains your nick.
|
||||
* \param params[1] mandatory, contains the channel name you're invited into.
|
||||
*
|
||||
* \sa irc_cmd_invite irc_cmd_chanmode_invite
|
||||
*/
|
||||
irc_event_callback_t event_invite;
|
||||
|
||||
/*!
|
||||
* The "ctcp" event is triggered when the client receives the CTCP
|
||||
* request. By default, the built-in CTCP request handler is used. The
|
||||
* build-in handler automatically replies on most CTCP messages, so you
|
||||
* will rarely need to override it.
|
||||
*
|
||||
* \param origin the person, who generates the message.
|
||||
* \param params[0] mandatory, the complete CTCP message, including its
|
||||
* arguments.
|
||||
*
|
||||
* Mirc generates PING, FINGER, VERSION, TIME and ACTION messages,
|
||||
* check the source code of \c libirc_event_ctcp_internal function to
|
||||
* see how to write your own CTCP request handler. Also you may find
|
||||
* useful this question in FAQ: \ref faq4
|
||||
*/
|
||||
irc_event_callback_t event_ctcp_req;
|
||||
|
||||
/*!
|
||||
* The "ctcp" event is triggered when the client receives the CTCP reply.
|
||||
*
|
||||
* \param origin the person, who generates the message.
|
||||
* \param params[0] mandatory, the CTCP message itself with its arguments.
|
||||
*/
|
||||
irc_event_callback_t event_ctcp_rep;
|
||||
|
||||
/*!
|
||||
* The "action" event is triggered when the client receives the CTCP
|
||||
* ACTION message. These messages usually looks like:\n
|
||||
* \code
|
||||
* [23:32:55] * Tim gonna sleep.
|
||||
* \endcode
|
||||
*
|
||||
* \param origin the person, who generates the message.
|
||||
* \param params[0] mandatory, the ACTION message.
|
||||
*/
|
||||
irc_event_callback_t event_ctcp_action;
|
||||
|
||||
/*!
|
||||
* The "unknown" event is triggered upon receipt of any number of
|
||||
* unclassifiable miscellaneous messages, which aren't handled by the
|
||||
* library.
|
||||
*/
|
||||
irc_event_callback_t event_unknown;
|
||||
|
||||
/*!
|
||||
* The "numeric" event is triggered upon receipt of any numeric response
|
||||
* from the server. There is a lot of such responses, see the full list
|
||||
* here: \ref rfcnumbers.
|
||||
*
|
||||
* See the params in ::irc_eventcode_callback_t specification.
|
||||
*/
|
||||
irc_eventcode_callback_t event_numeric;
|
||||
|
||||
/*!
|
||||
* The "dcc chat" event is triggered when someone requests a DCC CHAT from
|
||||
* you.
|
||||
*
|
||||
* See the params in ::irc_event_dcc_chat_t specification.
|
||||
*/
|
||||
irc_event_dcc_chat_t event_dcc_chat_req;
|
||||
|
||||
/*!
|
||||
* The "dcc chat" event is triggered when someone wants to send a file
|
||||
* to you via DCC SEND request.
|
||||
*
|
||||
* See the params in ::irc_event_dcc_send_t specification.
|
||||
*/
|
||||
irc_event_dcc_send_t event_dcc_send_req;
|
||||
|
||||
|
||||
} irc_callbacks_t;
|
||||
|
||||
|
||||
#endif /* INCLUDE_IRC_EVENTS_H */
|
@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2012 George Yunaev gyunaev@ulduzsoft.com
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDE_IRC_OPTIONS_H
|
||||
#define INCLUDE_IRC_OPTIONS_H
|
||||
|
||||
#ifndef IN_INCLUDE_LIBIRC_H
|
||||
#error This file should not be included directly, include just libircclient.h
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* enables additional debug output
|
||||
* \ingroup options
|
||||
*/
|
||||
#define LIBIRC_OPTION_DEBUG (1 << 1)
|
||||
|
||||
/*! \brief allows to strip origins automatically.
|
||||
*
|
||||
* For every IRC server event, the event origin is sent in standard form:
|
||||
* nick!host\@ircserver, i.e. like tim!home\@irc.freenet.org. Such origins
|
||||
* can not be used in IRC commands, and need to be stripped (i.e. host and
|
||||
* server part should be cut off) before using. This can be done either
|
||||
* explicitly, by calling irc_target_get_nick(), or implicitly for all the
|
||||
* events - by setting this option with irc_option_set().
|
||||
* \ingroup options
|
||||
*/
|
||||
#define LIBIRC_OPTION_STRIPNICKS (1 << 2)
|
||||
|
||||
|
||||
/*! \brief Disables the certificate verification for SSL connections
|
||||
*
|
||||
* By default the SSL connection authenticy is ensured by verifying that the certificate
|
||||
* presented by the server is signed by a known trusted certificate authority. Since those
|
||||
* typically cost money, some IRC servers use the self-signed certificates. They provide the
|
||||
* benefits of the SSL connection but since they are not signed by the Certificate Authority,
|
||||
* their authencity cannot be verified. This option, if set, disables the certificate
|
||||
* verification - the library will accept any certificate presented by the server.
|
||||
*
|
||||
* This option must be set before the irc_connect function is called.
|
||||
* \ingroup options
|
||||
*/
|
||||
#define LIBIRC_OPTION_SSL_NO_VERIFY (1 << 3)
|
||||
|
||||
|
||||
#endif /* INCLUDE_IRC_OPTIONS_H */
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,255 +0,0 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef MAXMINDDB_H
|
||||
#define MAXMINDDB_H
|
||||
|
||||
/* Request POSIX.1-2008. However, we want to remain compatible with
|
||||
* POSIX.1-2001 (since we have been historically and see no reason to drop
|
||||
* compatibility). By requesting POSIX.1-2008, we can conditionally use
|
||||
* features provided by that standard if the implementation provides it. We can
|
||||
* check for what the implementation provides by checking the _POSIX_VERSION
|
||||
* macro after including unistd.h. If a feature is in POSIX.1-2008 but not
|
||||
* POSIX.1-2001, check that macro before using the feature (or check for the
|
||||
* feature directly if possible). */
|
||||
#ifndef _POSIX_C_SOURCE
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
#endif
|
||||
|
||||
#include "maxminddb_config.h"
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
/* libmaxminddb package version from configure */
|
||||
#define PACKAGE_VERSION "1.4.2"
|
||||
|
||||
typedef ADDRESS_FAMILY sa_family_t;
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
/* MSVC doesn't define signed size_t, copy it from configure */
|
||||
#define ssize_t SSIZE_T
|
||||
|
||||
/* MSVC doesn't support restricted pointers */
|
||||
#define restrict
|
||||
#endif
|
||||
#else
|
||||
#include <netdb.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/socket.h>
|
||||
#endif
|
||||
|
||||
#define MMDB_DATA_TYPE_EXTENDED (0)
|
||||
#define MMDB_DATA_TYPE_POINTER (1)
|
||||
#define MMDB_DATA_TYPE_UTF8_STRING (2)
|
||||
#define MMDB_DATA_TYPE_DOUBLE (3)
|
||||
#define MMDB_DATA_TYPE_BYTES (4)
|
||||
#define MMDB_DATA_TYPE_UINT16 (5)
|
||||
#define MMDB_DATA_TYPE_UINT32 (6)
|
||||
#define MMDB_DATA_TYPE_MAP (7)
|
||||
#define MMDB_DATA_TYPE_INT32 (8)
|
||||
#define MMDB_DATA_TYPE_UINT64 (9)
|
||||
#define MMDB_DATA_TYPE_UINT128 (10)
|
||||
#define MMDB_DATA_TYPE_ARRAY (11)
|
||||
#define MMDB_DATA_TYPE_CONTAINER (12)
|
||||
#define MMDB_DATA_TYPE_END_MARKER (13)
|
||||
#define MMDB_DATA_TYPE_BOOLEAN (14)
|
||||
#define MMDB_DATA_TYPE_FLOAT (15)
|
||||
|
||||
#define MMDB_RECORD_TYPE_SEARCH_NODE (0)
|
||||
#define MMDB_RECORD_TYPE_EMPTY (1)
|
||||
#define MMDB_RECORD_TYPE_DATA (2)
|
||||
#define MMDB_RECORD_TYPE_INVALID (3)
|
||||
|
||||
/* flags for open */
|
||||
#define MMDB_MODE_MMAP (1)
|
||||
#define MMDB_MODE_MASK (7)
|
||||
|
||||
/* error codes */
|
||||
#define MMDB_SUCCESS (0)
|
||||
#define MMDB_FILE_OPEN_ERROR (1)
|
||||
#define MMDB_CORRUPT_SEARCH_TREE_ERROR (2)
|
||||
#define MMDB_INVALID_METADATA_ERROR (3)
|
||||
#define MMDB_IO_ERROR (4)
|
||||
#define MMDB_OUT_OF_MEMORY_ERROR (5)
|
||||
#define MMDB_UNKNOWN_DATABASE_FORMAT_ERROR (6)
|
||||
#define MMDB_INVALID_DATA_ERROR (7)
|
||||
#define MMDB_INVALID_LOOKUP_PATH_ERROR (8)
|
||||
#define MMDB_LOOKUP_PATH_DOES_NOT_MATCH_DATA_ERROR (9)
|
||||
#define MMDB_INVALID_NODE_NUMBER_ERROR (10)
|
||||
#define MMDB_IPV6_LOOKUP_IN_IPV4_DATABASE_ERROR (11)
|
||||
|
||||
#if !(MMDB_UINT128_IS_BYTE_ARRAY)
|
||||
#if MMDB_UINT128_USING_MODE
|
||||
typedef unsigned int mmdb_uint128_t __attribute__ ((__mode__(TI)));
|
||||
#else
|
||||
typedef unsigned __int128 mmdb_uint128_t;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* This is a pointer into the data section for a given IP address lookup */
|
||||
typedef struct MMDB_entry_s {
|
||||
const struct MMDB_s *mmdb;
|
||||
uint32_t offset;
|
||||
} MMDB_entry_s;
|
||||
|
||||
typedef struct MMDB_lookup_result_s {
|
||||
bool found_entry;
|
||||
MMDB_entry_s entry;
|
||||
uint16_t netmask;
|
||||
} MMDB_lookup_result_s;
|
||||
|
||||
typedef struct MMDB_entry_data_s {
|
||||
bool has_data;
|
||||
union {
|
||||
uint32_t pointer;
|
||||
const char *utf8_string;
|
||||
double double_value;
|
||||
const uint8_t *bytes;
|
||||
uint16_t uint16;
|
||||
uint32_t uint32;
|
||||
int32_t int32;
|
||||
uint64_t uint64;
|
||||
#if MMDB_UINT128_IS_BYTE_ARRAY
|
||||
uint8_t uint128[16];
|
||||
#else
|
||||
mmdb_uint128_t uint128;
|
||||
#endif
|
||||
bool boolean;
|
||||
float float_value;
|
||||
};
|
||||
/* This is a 0 if a given entry cannot be found. This can only happen
|
||||
* when a call to MMDB_(v)get_value() asks for hash keys or array
|
||||
* indices that don't exist. */
|
||||
uint32_t offset;
|
||||
/* This is the next entry in the data section, but it's really only
|
||||
* relevant for entries that part of a larger map or array
|
||||
* struct. There's no good reason for an end user to look at this
|
||||
* directly. */
|
||||
uint32_t offset_to_next;
|
||||
/* This is only valid for strings, utf8_strings or binary data */
|
||||
uint32_t data_size;
|
||||
/* This is an MMDB_DATA_TYPE_* constant */
|
||||
uint32_t type;
|
||||
} MMDB_entry_data_s;
|
||||
|
||||
/* This is the return type when someone asks for all the entry data in a map or array */
|
||||
typedef struct MMDB_entry_data_list_s {
|
||||
MMDB_entry_data_s entry_data;
|
||||
struct MMDB_entry_data_list_s *next;
|
||||
void *pool;
|
||||
} MMDB_entry_data_list_s;
|
||||
|
||||
typedef struct MMDB_description_s {
|
||||
const char *language;
|
||||
const char *description;
|
||||
} MMDB_description_s;
|
||||
|
||||
/* WARNING: do not add new fields to this struct without bumping the SONAME.
|
||||
* The struct is allocated by the users of this library and increasing the
|
||||
* size will cause existing users to allocate too little space when the shared
|
||||
* library is upgraded */
|
||||
typedef struct MMDB_metadata_s {
|
||||
uint32_t node_count;
|
||||
uint16_t record_size;
|
||||
uint16_t ip_version;
|
||||
const char *database_type;
|
||||
struct {
|
||||
size_t count;
|
||||
const char **names;
|
||||
} languages;
|
||||
uint16_t binary_format_major_version;
|
||||
uint16_t binary_format_minor_version;
|
||||
uint64_t build_epoch;
|
||||
struct {
|
||||
size_t count;
|
||||
MMDB_description_s **descriptions;
|
||||
} description;
|
||||
/* See above warning before adding fields */
|
||||
} MMDB_metadata_s;
|
||||
|
||||
/* WARNING: do not add new fields to this struct without bumping the SONAME.
|
||||
* The struct is allocated by the users of this library and increasing the
|
||||
* size will cause existing users to allocate too little space when the shared
|
||||
* library is upgraded */
|
||||
typedef struct MMDB_ipv4_start_node_s {
|
||||
uint16_t netmask;
|
||||
uint32_t node_value;
|
||||
/* See above warning before adding fields */
|
||||
} MMDB_ipv4_start_node_s;
|
||||
|
||||
/* WARNING: do not add new fields to this struct without bumping the SONAME.
|
||||
* The struct is allocated by the users of this library and increasing the
|
||||
* size will cause existing users to allocate too little space when the shared
|
||||
* library is upgraded */
|
||||
typedef struct MMDB_s {
|
||||
uint32_t flags;
|
||||
const char *filename;
|
||||
ssize_t file_size;
|
||||
const uint8_t *file_content;
|
||||
const uint8_t *data_section;
|
||||
uint32_t data_section_size;
|
||||
const uint8_t *metadata_section;
|
||||
uint32_t metadata_section_size;
|
||||
uint16_t full_record_byte_size;
|
||||
uint16_t depth;
|
||||
MMDB_ipv4_start_node_s ipv4_start_node;
|
||||
MMDB_metadata_s metadata;
|
||||
/* See above warning before adding fields */
|
||||
} MMDB_s;
|
||||
|
||||
typedef struct MMDB_search_node_s {
|
||||
uint64_t left_record;
|
||||
uint64_t right_record;
|
||||
uint8_t left_record_type;
|
||||
uint8_t right_record_type;
|
||||
MMDB_entry_s left_record_entry;
|
||||
MMDB_entry_s right_record_entry;
|
||||
} MMDB_search_node_s;
|
||||
|
||||
extern int MMDB_open(const char *const filename, uint32_t flags,
|
||||
MMDB_s *const mmdb);
|
||||
extern MMDB_lookup_result_s MMDB_lookup_string(const MMDB_s *const mmdb,
|
||||
const char *const ipstr,
|
||||
int *const gai_error,
|
||||
int *const mmdb_error);
|
||||
extern MMDB_lookup_result_s MMDB_lookup_sockaddr(
|
||||
const MMDB_s *const mmdb,
|
||||
const struct sockaddr *const sockaddr,
|
||||
int *const mmdb_error);
|
||||
extern int MMDB_read_node(const MMDB_s *const mmdb,
|
||||
uint32_t node_number,
|
||||
MMDB_search_node_s *const node);
|
||||
extern int MMDB_get_value(MMDB_entry_s *const start,
|
||||
MMDB_entry_data_s *const entry_data,
|
||||
...);
|
||||
extern int MMDB_vget_value(MMDB_entry_s *const start,
|
||||
MMDB_entry_data_s *const entry_data,
|
||||
va_list va_path);
|
||||
extern int MMDB_aget_value(MMDB_entry_s *const start,
|
||||
MMDB_entry_data_s *const entry_data,
|
||||
const char *const *const path);
|
||||
extern int MMDB_get_metadata_as_entry_data_list(
|
||||
const MMDB_s *const mmdb, MMDB_entry_data_list_s **const entry_data_list);
|
||||
extern int MMDB_get_entry_data_list(
|
||||
MMDB_entry_s *start, MMDB_entry_data_list_s **const entry_data_list);
|
||||
extern void MMDB_free_entry_data_list(
|
||||
MMDB_entry_data_list_s *const entry_data_list);
|
||||
extern void MMDB_close(MMDB_s *const mmdb);
|
||||
extern const char *MMDB_lib_version(void);
|
||||
extern int MMDB_dump_entry_data_list(FILE *const stream,
|
||||
MMDB_entry_data_list_s *const entry_data_list,
|
||||
int indent);
|
||||
extern const char *MMDB_strerror(int error_code);
|
||||
|
||||
#endif /* MAXMINDDB_H */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
1476
include/pugixml.hpp
1476
include/pugixml.hpp
File diff suppressed because it is too large
Load Diff
12084
include/sqlite3.h
12084
include/sqlite3.h
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user