Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff -rupN asterisk-11.18.0/build_tools/menuselect-deps.in asterisk-11.18.0-oauth/build_tools/menuselect-deps.in
- --- asterisk-11.18.0/build_tools/menuselect-deps.in 2015-06-04 01:44:42.000000000 +0100
- +++ asterisk-11.18.0-oauth/build_tools/menuselect-deps.in 2015-06-22 17:46:02.184534485 +0100
- @@ -25,6 +25,7 @@ IODBC=@PBX_IODBC@
- ISDNNET=@PBX_ISDNNET@
- IXJUSER=@PBX_IXJUSER@
- JACK=@PBX_JACK@
- +JANSSON=@PBX_JANSSON@
- KQUEUE=@PBX_KQUEUE@
- LDAP=@PBX_LDAP@
- LIBEDIT=@PBX_LIBEDIT@
- diff -rupN asterisk-11.18.0/configure.ac asterisk-11.18.0-oauth/configure.ac
- --- asterisk-11.18.0/configure.ac 2015-06-04 01:44:42.000000000 +0100
- +++ asterisk-11.18.0-oauth/configure.ac 2015-06-22 17:46:02.184534485 +0100
- @@ -408,6 +408,7 @@ AST_EXT_LIB_SETUP([INOTIFY], [inotify su
- AST_EXT_LIB_SETUP([IODBC], [iODBC], [iodbc])
- AST_EXT_LIB_SETUP([ISDNNET], [ISDN4Linux], [isdnnet])
- AST_EXT_LIB_SETUP([JACK], [Jack Audio Connection Kit], [jack])
- +AST_EXT_LIB_SETUP([JANSSON], [Jansson JSON library], [jansson])
- AST_EXT_LIB_SETUP([KQUEUE], [kqueue support], [kqueue])
- AST_EXT_LIB_SETUP([LDAP], [OpenLDAP], [ldap])
- AST_LIBCURL_CHECK_CONFIG([], [7.10.1])
- @@ -1883,6 +1884,8 @@ AST_EXT_LIB_CHECK([INOTIFY], [c], [inoti
- AST_EXT_LIB_CHECK([JACK], [jack], [jack_activate], [jack/jack.h])
- +AST_EXT_LIB_CHECK([JANSSON], [jansson], [json_dumps], [jansson.h])
- +
- # BSD (and OS X) equivalent of inotify
- AST_EXT_LIB_CHECK([KQUEUE], [c], [kqueue], [sys/event.h])
- diff -rupN asterisk-11.18.0/contrib/scripts/install_prereq asterisk-11.18.0-oauth/contrib/scripts/install_prereq
- --- asterisk-11.18.0/contrib/scripts/install_prereq 2015-06-04 01:44:42.000000000 +0100
- +++ asterisk-11.18.0-oauth/contrib/scripts/install_prereq 2015-06-22 17:46:02.180534485 +0100
- @@ -27,7 +27,7 @@ PACKAGES_DEBIAN="$PACKAGES_DEBIAN libcur
- PACKAGES_DEBIAN="$PACKAGES_DEBIAN libpq-dev unixodbc-dev libsqlite0-dev libmysqlclient15-dev libneon27-dev libgmime-dev libusb-dev liblua5.1-0-dev lua5.1"
- PACKAGES_DEBIAN="$PACKAGES_DEBIAN libopenh323-dev libvpb-dev libgtk2.0-dev libmysqlclient-dev libbluetooth-dev libradiusclient-ng-dev freetds-dev"
- PACKAGES_DEBIAN="$PACKAGES_DEBIAN libsnmp-dev libiksemel-dev libcorosync-dev libnewt-dev libpopt-dev libical-dev libspandsp-dev libjack-dev"
- -PACKAGES_DEBIAN="$PACKAGES_DEBIAN libresample-dev libc-client-dev binutils-dev libsrtp-dev libgsm1-dev libedit-dev libldap-dev"
- +PACKAGES_DEBIAN="$PACKAGES_DEBIAN libresample-dev libc-client-dev binutils-dev libsrtp-dev libgsm1-dev libedit-dev libldap-dev libjansson-dev"
- PACKAGES_RH="automake gcc gcc-c++ ncurses-devel openssl-devel libxml2-devel unixODBC-devel libcurl-devel libogg-devel libvorbis-devel speex-devel"
- PACKAGES_RH="$PACKAGES_RH spandsp-devel freetds-devel net-snmp-devel iksemel-devel corosynclib-devel newt-devel popt-devel libtool-ltdl-devel lua-devel"
- PACKAGES_RH="$PACKAGES_RH libsqlite3x-devel radiusclient-ng-devel portaudio-devel postgresql-devel libresample-devel neon-devel libical-devel"
- diff -rupN asterisk-11.18.0/include/asterisk/autoconfig.h.in asterisk-11.18.0-oauth/include/asterisk/autoconfig.h.in
- --- asterisk-11.18.0/include/asterisk/autoconfig.h.in 2015-06-04 01:44:42.000000000 +0100
- +++ asterisk-11.18.0-oauth/include/asterisk/autoconfig.h.in 2015-06-22 17:46:02.180534485 +0100
- @@ -370,6 +370,9 @@
- /* Define to 1 if you have the Jack Audio Connection Kit library. */
- #undef HAVE_JACK
- +/* Define to 1 if you have the Jansson JSON library library. */
- +#undef HAVE_JANSSON
- +
- /* Define to 1 if you have the `kevent64' function. */
- #undef HAVE_KEVENT64
- diff -rupN asterisk-11.18.0/include/asterisk/json.h asterisk-11.18.0-oauth/include/asterisk/json.h
- --- asterisk-11.18.0/include/asterisk/json.h 1970-01-01 01:00:00.000000000 +0100
- +++ asterisk-11.18.0-oauth/include/asterisk/json.h 2015-06-22 17:46:02.180534485 +0100
- @@ -0,0 +1,533 @@
- +/*
- + * Asterisk -- An open source telephony toolkit.
- + *
- + * Copyright (C) 2012 - 2013, Digium, Inc.
- + *
- + * David M. Lee, II <dlee@digium.com>
- + *
- + * See http://www.asterisk.org for more information about
- + * the Asterisk project. Please do not directly contact
- + * any of the maintainers of this project for assistance;
- + * the project provides a web site, mailing lists and IRC
- + * channels for your use.
- + *
- + * This program is free software, distributed under the terms of
- + * the GNU General Public License Version 2. See the LICENSE file
- + * at the top of the source tree.
- + */
- +
- +#ifndef _ASTERISK_JSON_H
- +#define _ASTERISK_JSON_H
- +
- +/*! \file
- + *
- + * \brief Asterisk JSON abstraction layer.
- + *
- + * This is a very thin wrapper around the Jansson API. For more details on it, see its
- + * docs at http://www.digip.org/jansson/doc/2.4/apiref.html.
- +
- + * \author David M. Lee, II <dlee@digium.com>
- + */
- +
- +/*!@{*/
- +
- +/*!
- + * \brief Specifies custom allocators instead of the standard ast_malloc() and ast_free().
- + *
- + * This is used by the unit tests to do JSON specific memory leak detection. Since it
- + * affects all users of the JSON library, shouldn't normally be used.
- + */
- +void ast_json_set_alloc_funcs(void *(*malloc_fn)(size_t), void (*free_fn)(void*));
- +
- +/*!
- + * \struct ast_json
- + * \brief Abstract JSON element (object, array, string, int)
- + */
- +struct ast_json;
- +
- +/*!
- + * \brief Increase refcount on \a value.
- + * \return The given \a value.
- + */
- +struct ast_json *ast_json_ref(struct ast_json *value);
- +
- +/*!
- + * \brief Decrease refcount on \a value. If refcount reaches zero, \a value is freed.
- + */
- +void ast_json_unref(struct ast_json *value);
- +
- +/*!@}*/
- +
- +/*!@{*/
- +
- +/*!
- + * \brief Valid types of a JSON element.
- + */
- +enum ast_json_type
- +{
- + AST_JSON_OBJECT,
- + AST_JSON_ARRAY,
- + AST_JSON_STRING,
- + AST_JSON_INTEGER,
- + AST_JSON_REAL,
- + AST_JSON_TRUE,
- + AST_JSON_FALSE,
- + AST_JSON_NULL,
- +};
- +
- +/*!
- + * \brief Return the type of \a value.
- + */
- +enum ast_json_type ast_json_typeof(const struct ast_json *value);
- +
- +/*!@}*/
- +
- +/*!@{*/
- +
- +/*!
- + * \brief Gets the JSON true value.
- + */
- +struct ast_json *ast_json_true(void);
- +
- +/*!
- + * \brief Gets the JSON false value.
- + */
- +struct ast_json *ast_json_false(void);
- +
- +/*!
- + * \brief Returns JSON false if \a value is 0, JSON true otherwise.
- + */
- +struct ast_json *ast_json_boolean(int value);
- +
- +/*!
- + * \brief Gets the JSON null value.
- + */
- +struct ast_json *ast_json_null(void);
- +
- +/*!
- + * \brief Returns true (non-zero) if \a value is the JSON true value, false (zero)
- + * otherwise.
- + */
- +int ast_json_is_true(const struct ast_json *value);
- +
- +/*!
- + * \brief Returns true (non-zero) if \a value is the JSON false value, false (zero)
- + * otherwise.
- + */
- +int ast_json_is_false(const struct ast_json *value);
- +
- +/*!
- + * \brief Returns true (non-zero) if \a value is the JSON null value, false (zero)
- + * otherwise.
- + */
- +int ast_json_is_null(const struct ast_json *value);
- +
- +/*!@}*/
- +
- +/*!@{*/
- +
- +/*!
- + * \brief Constructs a JSON string from \a value.
- + *
- + * \a value must be a valid ASCII or UTF-8 encoded string.
- + *
- + * \return Newly constructed string element, or \c NULL on failure.
- + */
- +struct ast_json *ast_json_string_create(const char *value);
- +
- +/*!
- + * \brief Returns the string value of \a string, or \c NULL if it's not a JSON string.
- + */
- +const char *ast_json_string_get(const struct ast_json *string);
- +
- +/*!
- + * \brief Changes the string value of \a string to \a value.
- + *
- + * \return 0 on success, or -1 on error.
- + */
- +int ast_json_string_set(struct ast_json *string, const char *value);
- +
- +/*!
- + * \brief Create a JSON string, printf style.
- + *
- + * \return Newly allocated string, or \c NULL if allocation fails.
- + */
- +struct ast_json *ast_json_stringf(const char *format, ...) __attribute__((format(printf, 1, 2)));
- +
- +/*!
- + * \brief Create a JSON string, vprintf style.
- + *
- + * \return Newly allocated string, or \c NULL if allocation fails.
- + */
- +struct ast_json *ast_json_vstringf(const char *format, va_list args) __attribute__((format(printf, 1, 0)));
- +
- +/*!@}*/
- +
- +/*!@{*/
- +
- +/*!
- + * \brief Create a JSON integer with the give \a value.
- + *
- + * \return Newly allocated integer, or \c NULL if allocation fails.
- + */
- +struct ast_json *ast_json_integer_create(intmax_t value);
- +
- +/*!
- + * \brief Get the value from \a integer.
- + *
- + * \return integer value, or 0 for non-integers.
- + */
- +intmax_t ast_json_integer_get(const struct ast_json *integer);
- +
- +/*!
- + * \brief Sets the value of \a integer.
- + *
- + * \return 0 on success, -1 on failure
- + */
- +int ast_json_integer_set(struct ast_json *integer, intmax_t value);
- +
- +/*!@}*/
- +
- +/*!@{*/
- +
- +/*!
- + * \brief Create a empty JSON array.
- + *
- + * \return Newly allocated array, or \c NULL if allocation fails.
- + */
- +struct ast_json *ast_json_array_create(void);
- +
- +/*!
- + * \brief Returns the size of \a array, or 0 if argument is not an array.
- + */
- +size_t ast_json_array_size(const struct ast_json *array);
- +
- +/*!
- + * \brief Returns the element in the \a index position from the \a array.
- + *
- + * The returned element is a borrowed reference; use ast_json_ref() to safely keep a
- + * pointer to it.
- + *
- + * \return The specified element, or \c NULL if \a array not an array or \a index is out
- + * of bounds.
- + */
- +struct ast_json *ast_json_array_get(const struct ast_json *array, size_t index);
- +
- +/*!
- + * \brief Changes the \a index element in \a array to \a value.
- + *
- + * The array steals the \a value reference; use ast_json_ref() to safely keep a pointer
- + * to it.
- + *
- + * \return 0 on success, or -1 on failure.
- + */
- +int ast_json_array_set(struct ast_json *array, size_t index, struct ast_json *value);
- +
- +/*!
- + * \brief Appends \a value to \a array.
- + *
- + * The array steals the \a value reference; use ast_json_ref() to safely keep a pointer
- + * to it.
- + *
- + * \return 0 on success, or -1 on failure.
- + */
- +int ast_json_array_append(struct ast_json *array, struct ast_json *value);
- +
- +/*!
- + * \brief Inserts \a value into \a array at position \a index.
- + *
- + * The array steals the \a value reference; use ast_json_ref() to safely keep a pointer
- + * to it.
- + *
- + * \return 0 on success, or -1 on failure.
- + */
- +int ast_json_array_insert(struct ast_json *array, size_t index, struct ast_json *value);
- +
- +/*!
- + * \brief Removes the element at position \a index from \a array.
- + *
- + * \return 0 on success, or -1 on failure.
- + */
- +int ast_json_array_remove(struct ast_json *array, size_t index);
- +
- +/*!
- + * \brief Removes all elements from \a array.
- + *
- + * \return 0 on success, or -1 on failure.
- + */
- +int ast_json_array_clear(struct ast_json *array);
- +
- +/*!
- + * \brief Appends all elements from \a tail to \a array.
- + *
- + * The \a tail argument is left alone, so ast_json_unref() it when you are done with it.
- + *
- + * \return 0 on success, or -1 on failure.
- + */
- +int ast_json_array_extend(struct ast_json *array, struct ast_json *tail);
- +
- +/*!@}*/
- +
- +/*!@{*/
- +
- +/*!
- + * \brief Create a new JSON object.
- + *
- + * \return Newly allocated object, or \c NULL if allocation fails.
- + */
- +struct ast_json *ast_json_object_create(void);
- +
- +/*!
- + * \brief Returns the size of \a object, or 0 if it's not a JSON object.
- + */
- +size_t ast_json_object_size(struct ast_json *object);
- +
- +/*!
- + * \brief Returns the element from \a object with the given \a key, or \c NULL on error.
- + */
- +struct ast_json *ast_json_object_get(struct ast_json *object, const char *key);
- +
- +/*!
- + * \brief Sets the value of \a key to \a value in \a object.
- + *
- + * The object steals the \a value reference; use ast_json_ref() to safely keep a pointer
- + * to it.
- + *
- + * \return 0 on success, or -1 on error.
- + */
- +int ast_json_object_set(struct ast_json *object, const char *key, struct ast_json *value);
- +
- +/*!
- + * \brief Deletes \a key from \a object.
- + *
- + * \return 0 on success, or -1 if key does not exist.
- + */
- +int ast_json_object_del(struct ast_json *object, const char *key);
- +
- +/*!
- + * \brief Deletes all elements from \a object.
- + *
- + * \return 0 on success, or -1 on error.
- + */
- +int ast_json_object_clear(struct ast_json *object);
- +
- +/*!
- + * \brief Updates the elements of \a object with all of the elements \a other, overwriting
- + * existing keys and adding new ones.
- + *
- + * The \a other argument is left alone, so ast_json_unref() it when you are done with it.
- + *
- + * \return 0 on success, or -1 on error.
- + */
- +int ast_json_object_update(struct ast_json *object, struct ast_json *other);
- +
- +/*!
- + * \brief Updates the elements of \a object with the elements of \a other, only
- + * overwriting existing keys.
- + *
- + * The \a other argument is left alone, so ast_json_unref() it when you are done with it.
- + *
- + * \return 0 on success, or -1 on error.
- + */
- +int ast_json_object_update_existing(struct ast_json *object, struct ast_json *other);
- +
- +/*!
- + * \brief Updates the elements of \a object with the elements of \a other, only adding new
- + * ones, not changing existing values.
- + *
- + * The \a other argument is left alone, so ast_json_unref() it when you are done with it.
- + *
- + * \return 0 on success, or -1 on error.
- + */
- +int ast_json_object_update_missing(struct ast_json *object, struct ast_json *other);
- +
- +/*!
- + * \struct ast_json_iter
- + * \brief Iterator for JSON object key/values. Note that iteration order is not specified,
- + * and may change as keys are added to and removed from the object.
- + */
- +struct ast_json_iter;
- +
- +/*!
- + * \brief Returns an iterator pointing to the first element in \a object, or \c NULL if
- + * \a object is \c NULL or empty.
- + */
- +struct ast_json_iter *ast_json_object_iter(struct ast_json *object);
- +
- +/*!
- + * \brief Returns an iterator pointing to a specified \a key in \a object. Iterating
- + * forward from this iterator may not to cover all elements in \a object.
- + */
- +struct ast_json_iter *ast_json_object_iter_at(struct ast_json *object, const char *key);
- +
- +/*!
- + * \brief Returns an iterator pointing to the next key-value pair after \a iter, or
- + * \c NULL if at the end.
- + */
- +struct ast_json_iter *ast_json_object_iter_next(struct ast_json *object, struct ast_json_iter *iter);
- +
- +/*!
- + * \brief Returns key from \a iter.
- + */
- +const char *ast_json_object_iter_key(struct ast_json_iter *iter);
- +
- +/*!
- + * \brief Returns value from \a iter.
- + *
- + * The returned element is a borrowed reference; use ast_json_ref() to safely
- + * keep a pointer to it.
- + */
- +struct ast_json *ast_json_object_iter_value(struct ast_json_iter *iter);
- +
- +/*!
- + * \brief Sets the value in \a object at \a iter to \a value.
- + *
- + * The array steals the value reference; use ast_json_ref() to safely keep a
- + * pointer to it.
- + *
- + * \return 0 on success, or -1 on error.
- + */
- +int ast_json_object_iter_set(struct ast_json *object, struct ast_json_iter *iter, struct ast_json *value);
- +
- +/*!@}*/
- +
- +/*!@{*/
- +
- +/*!
- + * \brief Returns JSON representation of \a root, or \c NULL on error.
- + *
- + * Returned string must be freed by calling ast_free().
- + */
- +char *ast_json_dump_string(struct ast_json *root);
- +
- +/*!
- + * \brief Writes JSON representation of \a root to \a dst.
- + *
- + * If \a dst is too small, it will be grown as needed.
- + *
- + * \return 0 on success, or -1 on error. On error, the contents of \a dst are
- + * undefined.
- + */
- +int ast_json_dump_str(struct ast_json *root, struct ast_str **dst);
- +
- +/*!
- + * \brief Writes JSON representation of \a root to \a output.
- + *
- + * \return 0 on success, or -1 on error.
- + */
- +int ast_json_dump_file(struct ast_json *root, FILE *output);
- +
- +/*!
- + * \brief Writes JSON representation of \a root to a file at \a path.
- + *
- + * \return 0 on success, or -1 on error.
- + */
- +int ast_json_dump_new_file(struct ast_json *root, const char *path);
- +
- +#define AST_JSON_ERROR_TEXT_LENGTH 160
- +#define AST_JSON_ERROR_SOURCE_LENGTH 80
- +
- +/*!
- + * \brief JSON parsing error information.
- + */
- +struct ast_json_error {
- + /*! Line number error occured on */
- + int line;
- + /*! Character (not byte, can be different for UTF-8) column on which the error occurred. */
- + int column;
- + /*! Position in bytes from start of input */
- + int position;
- + /*! Error message */
- + char text[AST_JSON_ERROR_TEXT_LENGTH];
- + /*! Source of the error (filename or <string>) */
- + char source[AST_JSON_ERROR_TEXT_LENGTH];
- +};
- +
- +/*!
- + * \brief Parses null terminated \a input string into a JSON object or array.
- + *
- + * \param[out] error Filled with information on error.
- + *
- + * \return Parsed JSON element, or \c NULL on error.
- + */
- +struct ast_json *ast_json_load_string(const char *input, struct ast_json_error *error);
- +
- +/*!
- + * \brief Parses null terminated \a input ast_str into a JSON object or array.
- + *
- + * \param[out] error Filled with information on error.
- + *
- + * \return Parsed JSON element, or \c NULL on error.
- + */
- +struct ast_json *ast_json_load_str(const struct ast_str *input, struct ast_json_error *error);
- +
- +/*!
- + * \brief Parses \a buffer with length \a buflen into a JSON object or array.
- + *
- + * \param[out] error Filled with information on error.
- + *
- + * \return Parsed JSON element, or \c NULL on error.
- + */
- +struct ast_json *ast_json_load_buf(const char *buffer, size_t buflen, struct ast_json_error *error);
- +
- +/*!
- + * \brief Parses \a input into JSON object or array.
- + *
- + * \param[out] error Filled with information on error.
- + *
- + * \return Parsed JSON element, or \c NULL on error.
- + */
- +struct ast_json *ast_json_load_file(FILE *input, struct ast_json_error *error);
- +
- +/*!
- + * \brief Parses file at \a path into JSON object or array.
- + *
- + * \param[out] error Filled with information on error.
- + *
- + * \return Parsed JSON element, or \c NULL on error.
- + */
- +struct ast_json *ast_json_load_new_file(const char *path, struct ast_json_error *error);
- +
- +/*!
- + * \brief Helper for creating complex JSON values.
- + *
- + * See original Jansson docs at http://www.digip.org/jansson/doc/2.4/apiref.html#apiref-pack
- + * for more details.
- + */
- +struct ast_json *ast_json_pack(char const *format, ...);
- +
- +/*!
- + * \brief Helper for creating complex JSON values simply.
- + *
- + * See original Jansson docs at http://www.digip.org/jansson/doc/2.4/apiref.html#apiref-pack
- + * for more details.
- + */
- +struct ast_json *ast_json_vpack(char const *format, va_list ap);
- +
- +/*!@}*/
- +
- +/*!@{*/
- +
- +/*!
- + * \brief Compares two JSON objects.
- + *
- + * Two JSON objects are equal if they are of the same type, and their contents are equal.
- + *
- + * \return true (non-zero) if \a lhs and \a rhs are equal, and false (zero) otherwise.
- + */
- +int ast_json_equal(const struct ast_json *lhs, const struct ast_json *rhs);
- +
- +/*!
- + * \brief Returns shallow copy (does not copy child elements) of \a value, or \c NULL
- + * on error.
- + */
- +struct ast_json *ast_json_copy(const struct ast_json *value);
- +
- +/*!
- + * \brief Returns deep copy (copies child elements) of \a value, or \c NULL on error.
- + */
- +struct ast_json *ast_json_deep_copy(const struct ast_json *value);
- +
- +/*!@}*/
- +
- +#endif /* _ASTERISK_JSON_H */
- diff -rupN asterisk-11.18.0/include/asterisk/test.h asterisk-11.18.0-oauth/include/asterisk/test.h
- --- asterisk-11.18.0/include/asterisk/test.h 2015-06-04 01:44:42.000000000 +0100
- +++ asterisk-11.18.0-oauth/include/asterisk/test.h 2015-06-22 17:46:02.180534485 +0100
- @@ -297,5 +297,22 @@ int __ast_test_status_update(const char
- } \
- } while(0)
- +/*!
- + * \ref ast_test_check
- + */
- +enum ast_test_result_state __ast_test_check(const char *file, const char *function, int line, struct ast_test *test, const char *condition_str, enum ast_test_result_state current_res, int condition);
- +
- +/*!
- + * \brief Accumulate test results for a test.
- + *
- + * This macro evaluates \a condition, then updates \a res and the test status accordingly. If the condition evaluates to
- + * true (non-zero), nothing happens. If it evaluates to false (zero), then res is set to \a AST_TEST_FAIL and the failure
- + * is printed using \ref ast_test_status_update.
- + *
- + * \param \a res Local variable of type \a ast_test_result_state.
- + * \param \a condition Boolean condition to check.
- + */
- +#define ast_test_check(res, condition) res = __ast_test_check( __FILE__, __PRETTY_FUNCTION__, __LINE__, test, #condition, (res), (condition))
- +
- #endif /* TEST_FRAMEWORK */
- #endif /* _AST_TEST_H */
- diff -rupN asterisk-11.18.0/main/test.c asterisk-11.18.0-oauth/main/test.c
- --- asterisk-11.18.0/main/test.c 2015-06-04 01:44:42.000000000 +0100
- +++ asterisk-11.18.0-oauth/main/test.c 2015-06-22 17:46:02.176534485 +0100
- @@ -936,6 +936,15 @@ static void test_shutdown(void)
- ast_cli_unregister_multiple(test_cli, ARRAY_LEN(test_cli));
- }
- +enum ast_test_result_state __ast_test_check(const char *file, const char *function, int line, struct ast_test *test, const char *condition_str, enum ast_test_result_state current_res, int condition)
- +{
- + if (!condition) {
- + __ast_test_status_update(file, function, line, test, "Condition failed: %s\n", condition_str);
- + return AST_TEST_FAIL;
- + }
- + return current_res;
- +}
- +
- #endif /* TEST_FRAMEWORK */
- int ast_test_init()
- diff -rupN asterisk-11.18.0/makeopts.in asterisk-11.18.0-oauth/makeopts.in
- --- asterisk-11.18.0/makeopts.in 2015-06-04 01:44:42.000000000 +0100
- +++ asterisk-11.18.0-oauth/makeopts.in 2015-06-22 17:46:02.176534485 +0100
- @@ -172,6 +172,9 @@ IODBC_LIB=@IODBC_LIB@
- JACK_INCLUDE=@JACK_INCLUDE@
- JACK_LIB=@JACK_LIB@
- +JANSSON_INCLUDE=@JANSSON_INCLUDE@
- +JANSSON_LIB=@JANSSON_LIB@
- +
- LDAP_INCLUDE=@LDAP_INCLUDE@
- LDAP_LIB=@LDAP_LIB@
- diff -rupN asterisk-11.18.0/res/res_json.c asterisk-11.18.0-oauth/res/res_json.c
- --- asterisk-11.18.0/res/res_json.c 1970-01-01 01:00:00.000000000 +0100
- +++ asterisk-11.18.0-oauth/res/res_json.c 2015-06-22 17:46:02.176534485 +0100
- @@ -0,0 +1,512 @@
- +/*
- + * Asterisk -- An open source telephony toolkit.
- + *
- + * Copyright (C) 2012 - 2013, Digium, Inc.
- + *
- + * David M. Lee, II <dlee@digium.com>
- + *
- + * See http://www.asterisk.org for more information about
- + * the Asterisk project. Please do not directly contact
- + * any of the maintainers of this project for assistance;
- + * the project provides a web site, mailing lists and IRC
- + * channels for your use.
- + *
- + * This program is free software, distributed under the terms of
- + * the GNU General Public License Version 2. See the LICENSE file
- + * at the top of the source tree.
- + */
- +
- +/*! \file
- + *
- + * \brief JSON abstraction layer.
- + *
- + * This is a very thin wrapper around the Jansson API. For more details on it, see its
- + * docs at http://www.digip.org/jansson/doc/2.4/apiref.html.
- + *
- + * \author David M. Lee, II <dlee@digium.com>
- + */
- +
- +/*** MODULEINFO
- + <depend>jansson</depend>
- + <support_level>core</support_level>
- + ***/
- +
- +#include "asterisk.h"
- +
- +ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
- +
- +#include "asterisk/json.h"
- +#include "asterisk/module.h"
- +#include "asterisk/utils.h"
- +
- +#include <jansson.h>
- +
- +/*!
- + * \brief Function wrapper around ast_malloc macro.
- + */
- +static void *json_malloc(size_t size)
- +{
- + return ast_malloc(size);
- +}
- +
- +/*!
- + * \brief Function wrapper around ast_free macro.
- + */
- +static void json_free(void *p)
- +{
- + ast_free(p);
- +}
- +
- +void ast_json_set_alloc_funcs(void *(*malloc_fn)(size_t), void (*free_fn)(void*))
- +{
- + json_set_alloc_funcs(malloc_fn, free_fn);
- +}
- +
- +struct ast_json *ast_json_ref(struct ast_json *json)
- +{
- + json_incref((json_t *)json);
- + return json;
- +}
- +
- +void ast_json_unref(struct ast_json *json)
- +{
- + json_decref((json_t *)json);
- +}
- +
- +enum ast_json_type ast_json_typeof(const struct ast_json *json)
- +{
- + int r = json_typeof((json_t*)json);
- + switch(r) {
- + case JSON_OBJECT: return AST_JSON_OBJECT;
- + case JSON_ARRAY: return AST_JSON_ARRAY;
- + case JSON_STRING: return AST_JSON_STRING;
- + case JSON_INTEGER: return AST_JSON_INTEGER;
- + case JSON_REAL: return AST_JSON_REAL;
- + case JSON_TRUE: return AST_JSON_TRUE;
- + case JSON_FALSE: return AST_JSON_FALSE;
- + case JSON_NULL: return AST_JSON_NULL;
- + }
- + ast_assert(0); /* Unexpect return from json_typeof */
- + return r;
- +}
- +
- +struct ast_json *ast_json_true(void)
- +{
- + return (struct ast_json *)json_true();
- +}
- +
- +struct ast_json *ast_json_false(void)
- +{
- + return (struct ast_json *)json_false();
- +}
- +
- +struct ast_json *ast_json_boolean(int value)
- +{
- +#if JANSSON_VERSION_HEX >= 0x020400
- + return (struct ast_json *)json_boolean(value);
- +#else
- + return value ? ast_json_true() : ast_json_false();
- +#endif
- +}
- +
- +struct ast_json *ast_json_null(void)
- +{
- + return (struct ast_json *)json_null();
- +}
- +
- +int ast_json_is_true(const struct ast_json *json)
- +{
- + return json_is_true((const json_t *)json);
- +}
- +
- +int ast_json_is_false(const struct ast_json *json)
- +{
- + return json_is_false((const json_t *)json);
- +}
- +
- +int ast_json_is_null(const struct ast_json *json)
- +{
- + return json_is_null((const json_t *)json);
- +}
- +
- +struct ast_json *ast_json_string_create(const char *value)
- +{
- + return (struct ast_json *)json_string(value);
- +}
- +
- +const char *ast_json_string_get(const struct ast_json *string)
- +{
- + return json_string_value((json_t *)string);
- +}
- +
- +int ast_json_string_set(struct ast_json *string, const char *value)
- +{
- + return json_string_set((json_t *)string, value);
- +}
- +
- +struct ast_json *ast_json_stringf(const char *format, ...)
- +{
- + struct ast_json *ret;
- + va_list args;
- + va_start(args, format);
- + ret = ast_json_vstringf(format, args);
- + va_end(args);
- + return ret;
- +}
- +
- +struct ast_json *ast_json_vstringf(const char *format, va_list args)
- +{
- + char *str = NULL;
- + json_t *ret = NULL;
- +
- + if (format) {
- + int err = vasprintf(&str, format, args);
- + if (err > 0) {
- + ret = json_string(str);
- + free(str);
- + }
- + }
- + return (struct ast_json *)ret;
- +}
- +
- +struct ast_json *ast_json_integer_create(intmax_t value)
- +{
- + return (struct ast_json *)json_integer(value);
- +}
- +
- +intmax_t ast_json_integer_get(const struct ast_json *integer)
- +{
- + return json_integer_value((json_t *)integer);
- +}
- +
- +int ast_json_integer_set(struct ast_json *integer, intmax_t value)
- +{
- + return json_integer_set((json_t *)integer, value);
- +}
- +
- +
- +int ast_json_equal(const struct ast_json *lhs, const struct ast_json *rhs)
- +{
- + return json_equal((json_t *)lhs, (json_t *)rhs);
- +}
- +
- +struct ast_json *ast_json_array_create(void)
- +{
- + return (struct ast_json *)json_array();
- +}
- +size_t ast_json_array_size(const struct ast_json *array)
- +{
- + return json_array_size((json_t *)array);
- +}
- +struct ast_json *ast_json_array_get(const struct ast_json *array, size_t index)
- +{
- + return (struct ast_json *)json_array_get((json_t *)array, index);
- +}
- +int ast_json_array_set(struct ast_json *array, size_t index, struct ast_json *value)
- +{
- + return json_array_set_new((json_t *)array, index, (json_t *)value);
- +}
- +int ast_json_array_append(struct ast_json *array, struct ast_json *value)
- +{
- + return json_array_append_new((json_t *)array, (json_t *)value);
- +}
- +int ast_json_array_insert(struct ast_json *array, size_t index, struct ast_json *value)
- +{
- + return json_array_insert_new((json_t *)array, index, (json_t *)value);
- +}
- +int ast_json_array_remove(struct ast_json *array, size_t index)
- +{
- + return json_array_remove((json_t *)array, index);
- +}
- +int ast_json_array_clear(struct ast_json *array)
- +{
- + return json_array_clear((json_t *)array);
- +}
- +int ast_json_array_extend(struct ast_json *array, struct ast_json *tail)
- +{
- + return json_array_extend((json_t *)array, (json_t *)tail);
- +}
- +
- +struct ast_json *ast_json_object_create(void)
- +{
- + return (struct ast_json *)json_object();
- +}
- +size_t ast_json_object_size(struct ast_json *object)
- +{
- + return json_object_size((json_t *)object);
- +}
- +struct ast_json *ast_json_object_get(struct ast_json *object, const char *key)
- +{
- + if (key) {
- + return (struct ast_json *)json_object_get((json_t *)object, key);
- + }
- + return NULL;
- +}
- +int ast_json_object_set(struct ast_json *object, const char *key, struct ast_json *value)
- +{
- + return json_object_set_new((json_t *)object, key, (json_t *)value);
- +}
- +int ast_json_object_del(struct ast_json *object, const char *key)
- +{
- + return json_object_del((json_t *)object, key);
- +}
- +int ast_json_object_clear(struct ast_json *object)
- +{
- + return json_object_clear((json_t *)object);
- +}
- +int ast_json_object_update(struct ast_json *object, struct ast_json *other)
- +{
- + return json_object_update((json_t *)object, (json_t *)other);
- +}
- +int ast_json_object_update_existing(struct ast_json *object, struct ast_json *other)
- +{
- +#if JANSSON_VERSION_HEX >= 0x020300
- + return json_object_update_existing((json_t *)object, (json_t *)other);
- +#else
- + struct ast_json_iter *iter = ast_json_object_iter(other);
- + int ret = 0;
- +
- + if (object == NULL || other == NULL) {
- + return -1;
- + }
- +
- + while (iter != NULL && ret == 0) {
- + const char *key = ast_json_object_iter_key(iter);
- + if (ast_json_object_get(object, key) != NULL) {
- + ret = ast_json_object_set(object, key, ast_json_object_iter_value(iter));
- + }
- + iter = ast_json_object_iter_next(other, iter);
- + }
- + return ret;
- +#endif
- +}
- +int ast_json_object_update_missing(struct ast_json *object, struct ast_json *other)
- +{
- +#if JANSSON_VERSION_HEX >= 0x020300
- + return json_object_update_missing((json_t *)object, (json_t *)other);
- +#else
- + struct ast_json_iter *iter = ast_json_object_iter(other);
- + int ret = 0;
- +
- + if (object == NULL || other == NULL) {
- + return -1;
- + }
- +
- + while (iter != NULL && ret == 0) {
- + const char *key = ast_json_object_iter_key(iter);
- + if (ast_json_object_get(object, key) == NULL) {
- + ret = ast_json_object_set(object, key, ast_json_object_iter_value(iter));
- + }
- + iter = ast_json_object_iter_next(other, iter);
- + }
- + return ret;
- +#endif
- +}
- +
- +struct ast_json_iter *ast_json_object_iter(struct ast_json *object)
- +{
- + return json_object_iter((json_t *)object);
- +}
- +struct ast_json_iter *ast_json_object_iter_at(struct ast_json *object, const char *key)
- +{
- + return json_object_iter_at((json_t *)object, key);
- +}
- +struct ast_json_iter *ast_json_object_iter_next(struct ast_json *object, struct ast_json_iter *iter)
- +{
- + return json_object_iter_next((json_t *)object, iter);
- +}
- +const char *ast_json_object_iter_key(struct ast_json_iter *iter)
- +{
- + return json_object_iter_key(iter);
- +}
- +struct ast_json *ast_json_object_iter_value(struct ast_json_iter *iter)
- +{
- + return (struct ast_json *)json_object_iter_value(iter);
- +}
- +int ast_json_object_iter_set(struct ast_json *object, struct ast_json_iter *iter, struct ast_json *value)
- +{
- + return json_object_iter_set_new((json_t *)object, iter, (json_t *)value);
- +}
- +
- +/*!
- + * \brief Default flags for JSON encoding.
- + */
- +static size_t dump_flags(void)
- +{
- + /* There's a chance this could become a runtime flag */
- + int flags = JSON_COMPACT;
- +#ifdef AST_DEVMODE
- + /* In dev mode, write readable JSON */
- + flags = JSON_INDENT(2) | JSON_PRESERVE_ORDER;
- +#endif
- + return flags;
- +}
- +
- +char *ast_json_dump_string(struct ast_json *root)
- +{
- + return json_dumps((json_t *)root, dump_flags());
- +}
- +
- +static int write_to_ast_str(const char *buffer, size_t size, void *data)
- +{
- + struct ast_str **dst = data;
- + size_t str_size = ast_str_size(*dst);
- + size_t remaining = str_size - ast_str_strlen(*dst);
- + int ret;
- +
- + /* While ast_str_append will grow the ast_str, it won't report
- + * allocation errors. Fortunately, it's not that hard.
- + */
- +
- + /* Remaining needs to be big enough for buffer, plus null char */
- + while (remaining < size + 1) {
- + /* doubling the size of the buffer gives us 'amortized
- + * constant' time.
- + * See http://stackoverflow.com/a/249695/115478 for info.
- + */
- + str_size *= 2;
- + remaining = str_size - ast_str_strlen(*dst);
- + }
- +
- + ret = ast_str_make_space(dst, str_size);
- + if (ret == -1) {
- + /* Could not alloc; fail */
- + return -1;
- + }
- +
- + ast_str_append_substr(dst, -1, buffer, size);
- + return 0;
- +}
- +
- +int ast_json_dump_str(struct ast_json *root, struct ast_str **dst)
- +{
- + return json_dump_callback((json_t *)root, write_to_ast_str, dst, dump_flags());
- +}
- +
- +
- +int ast_json_dump_file(struct ast_json *root, FILE *output)
- +{
- + if (root && output) {
- + return json_dumpf((json_t *)root, output, dump_flags());
- + }
- + return -1;
- +}
- +int ast_json_dump_new_file(struct ast_json *root, const char *path)
- +{
- + return json_dump_file((json_t *)root, path, dump_flags());
- +}
- +
- +/*!
- + * \brief Copy Jansson error struct to ours.
- + */
- +static void copy_error(struct ast_json_error *error, const json_error_t *jansson_error)
- +{
- + if (error && jansson_error) {
- + error->line = jansson_error->line;
- + error->column = jansson_error->column;
- + error->position = jansson_error->position;
- + ast_copy_string(error->text, jansson_error->text, sizeof(error->text));
- + ast_copy_string(error->source, jansson_error->source, sizeof(error->source));
- + }
- +
- +}
- +
- +static void parse_error(struct ast_json_error *error, const char *text, const char *source)
- +{
- + if (error != NULL) {
- + error->line = 0;
- + error->column = 0;
- + error->position = 0;
- + strncpy(error->text, text, sizeof(error->text));
- + strncpy(error->source, source, sizeof(error->text));
- + }
- +}
- +
- +struct ast_json *ast_json_load_string(const char *input, struct ast_json_error *error)
- +{
- + json_error_t jansson_error = {};
- + struct ast_json *r = NULL;
- + if (input != NULL) {
- + r = (struct ast_json *)json_loads(input, 0, &jansson_error);
- + copy_error(error, &jansson_error);
- + } else {
- + parse_error(error, "NULL input string", "<null>");
- + }
- + return r;
- +}
- +
- +struct ast_json *ast_json_load_str(const struct ast_str *input, struct ast_json_error *error)
- +{
- + return ast_json_load_string(ast_str_buffer(input), error);
- +}
- +
- +struct ast_json *ast_json_load_buf(const char *buffer, size_t buflen, struct ast_json_error *error)
- +{
- + json_error_t jansson_error = {};
- + struct ast_json *r = (struct ast_json *)json_loadb(buffer, buflen, 0, &jansson_error);
- + copy_error(error, &jansson_error);
- + return r;
- +}
- +struct ast_json *ast_json_load_file(FILE *input, struct ast_json_error *error)
- +{
- + json_error_t jansson_error = {};
- + struct ast_json *r = NULL;
- + if (input != NULL) {
- + r = (struct ast_json *)json_loadf(input, 0, &jansson_error);
- + copy_error(error, &jansson_error);
- + } else {
- + parse_error(error, "NULL input file", "<null>");
- + }
- + return r;
- +}
- +struct ast_json *ast_json_load_new_file(const char *path, struct ast_json_error *error)
- +{
- + json_error_t jansson_error = {};
- + struct ast_json *r = (struct ast_json *)json_load_file(path, 0, &jansson_error);
- + copy_error(error, &jansson_error);
- + return r;
- +}
- +
- +struct ast_json *ast_json_pack(char const *format, ...)
- +{
- + struct ast_json *ret;
- + va_list args;
- + va_start(args, format);
- + ret = ast_json_vpack(format, args);
- + va_end(args);
- + return ret;
- +}
- +struct ast_json *ast_json_vpack(char const *format, va_list ap)
- +{
- + struct ast_json *r = NULL;
- + if (format) {
- + r = (struct ast_json *)json_vpack_ex(NULL, 0, format, ap);
- + }
- + return r;
- +}
- +
- +struct ast_json *ast_json_copy(const struct ast_json *value)
- +{
- + return (struct ast_json *)json_copy((json_t *)value);
- +}
- +struct ast_json *ast_json_deep_copy(const struct ast_json *value)
- +{
- + return (struct ast_json *)json_deep_copy((json_t *)value);
- +}
- +
- +static int unload_module(void)
- +{
- + /* Nothing to do */
- + return 0;
- +}
- +
- +static int load_module(void)
- +{
- + /* Setup to use Asterisk custom allocators */
- + json_set_alloc_funcs(json_malloc, json_free);
- + return AST_MODULE_LOAD_SUCCESS;
- +}
- +
- +AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS, "JSON library",
- + .load = load_module,
- + .unload = unload_module);
- diff -rupN asterisk-11.18.0/res/res_json.exports.in asterisk-11.18.0-oauth/res/res_json.exports.in
- --- asterisk-11.18.0/res/res_json.exports.in 1970-01-01 01:00:00.000000000 +0100
- +++ asterisk-11.18.0-oauth/res/res_json.exports.in 2015-06-22 17:46:02.172534485 +0100
- @@ -0,0 +1,6 @@
- +{
- + global:
- + LINKER_SYMBOL_PREFIXast_json_*;
- + local:
- + *;
- +};
- diff -rupN asterisk-11.18.0/res/res_xmpp.c asterisk-11.18.0-oauth/res/res_xmpp.c
- --- asterisk-11.18.0/res/res_xmpp.c 2015-06-04 01:44:42.000000000 +0100
- +++ asterisk-11.18.0-oauth/res/res_xmpp.c 2015-06-22 17:46:43.916534485 +0100
- @@ -53,6 +53,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revisi
- #include "asterisk/event.h"
- #include "asterisk/cli.h"
- #include "asterisk/config_options.h"
- +#include "asterisk/json.h"
- /*** DOCUMENTATION
- <application name="JabberSend" language="en_US" module="res_xmpp">
- @@ -333,6 +334,7 @@ struct ast_xmpp_client_config {
- AST_STRING_FIELD(name); /*!< Name of the client connection */
- AST_STRING_FIELD(user); /*!< Username to use for authentication */
- AST_STRING_FIELD(password); /*!< Password to use for authentication */
- + AST_STRING_FIELD(refresh_token);
- AST_STRING_FIELD(server); /*!< Server hostname */
- AST_STRING_FIELD(statusmsg); /*!< Status message for presence */
- AST_STRING_FIELD(pubsubnode); /*!< Pubsub node */
- @@ -401,6 +403,7 @@ static ast_cond_t message_received_condi
- static ast_mutex_t messagelock;
- static int xmpp_client_config_post_apply(void *obj, void *arg, int flags);
- +static void fetch_access_token(struct ast_xmpp_client_config *cfg);
- /*! \brief Destructor function for configuration */
- static void ast_xmpp_client_config_destructor(void *obj)
- @@ -610,8 +613,8 @@ static int xmpp_config_prelink(void *new
- if (ast_strlen_zero(clientcfg->user)) {
- ast_log(LOG_ERROR, "No user specified on client '%s'\n", clientcfg->name);
- return -1;
- - } else if (ast_strlen_zero(clientcfg->password)) {
- - ast_log(LOG_ERROR, "No password specified on client '%s'\n", clientcfg->name);
- + } else if (ast_strlen_zero(clientcfg->refresh_token)) {
- + ast_log(LOG_ERROR, "No refresh_token specified on client '%s'\n", clientcfg->name);
- return -1;
- } else if (ast_strlen_zero(clientcfg->server)) {
- ast_log(LOG_ERROR, "No server specified on client '%s'\n", clientcfg->name);
- @@ -2636,7 +2639,9 @@ static int xmpp_client_authenticate_sasl
- }
- iks_insert_attrib(auth, "xmlns", IKS_NS_XMPP_SASL);
- - iks_insert_attrib(auth, "mechanism", "PLAIN");
- + iks_insert_attrib(auth, "mechanism", "X-OAUTH2");
- + iks_insert_attrib(auth, "auth:service", "oauth2");
- + iks_insert_attrib(auth, "xmlns:auth", "http://www.google.com/talk/protocol/auth");
- if (strchr(client->jid->user, '/')) {
- char *user = ast_strdupa(client->jid->user);
- @@ -3446,6 +3451,10 @@ static int xmpp_client_reconnect(struct
- return -1;
- }
- + ast_log(LOG_NOTICE , "Connecting to client token : %s\n" , clientcfg->refresh_token);
- +
- + fetch_access_token(clientcfg);
- +
- ast_xmpp_client_disconnect(client);
- client->timeout = 50;
- @@ -3588,12 +3597,12 @@ static void *xmpp_client_thread(void *da
- do {
- if (client->state == XMPP_STATE_DISCONNECTING) {
- - ast_debug(1, "JABBER: Disconnecting client '%s'\n", client->name);
- + ast_debug(1, "11 JABBER: Disconnecting client '%s'\n", client->name);
- break;
- }
- if (res == IKS_NET_RWERR || client->timeout == 0) {
- - ast_debug(3, "Connecting client '%s'\n", client->name);
- + ast_debug(1, "111 Connecting client '%s'\n", client->name);
- if ((res = xmpp_client_reconnect(client)) != IKS_OK) {
- sleep(4);
- res = IKS_NET_RWERR;
- @@ -3669,6 +3678,37 @@ static int xmpp_client_config_merge_budd
- return 1;
- }
- +static void fetch_access_token(struct ast_xmpp_client_config *cfg) {
- +
- + char cmd[4096];
- + char cBuf[4096];
- + const char * url = "https://www.googleapis.com/oauth2/v3/token";
- + const char * client_id = "470306186573-jtdetm9fb2b28k4gumaleamea7a14deh.apps.googleusercontent.com";
- + const char * client_secret = "zWK1W_I-4ZlfRoFnYRoGhsrB";
- +
- + memset(cmd , 0 , sizeof(cmd));
- + snprintf(cmd , sizeof(cmd) - 1 , "CURL(%s,client_id=%s&client_secret=%s&refresh_token=%s&grant_type=refresh_token)" , url, client_id, client_secret, cfg->refresh_token);
- +
- + ast_log(LOG_NOTICE , "Command %s\n" , cmd);
- +
- + memset(cBuf , 0 , sizeof(cBuf));
- + ast_func_read(NULL, cmd , cBuf , sizeof(cBuf) - 1);
- + ast_log(LOG_NOTICE , "Command status : %s \n" , cBuf);
- +
- + struct ast_json_error error;
- + struct ast_json * jobj = ast_json_load_string(cBuf, &error);
- + if(jobj != NULL) {
- + const char * token = ast_json_string_get(ast_json_object_get(jobj, "access_token"));
- + if(token != NULL) {
- + ast_string_field_set(cfg , password, token);
- + }
- + ast_log(LOG_NOTICE , "access Token : %s\n", token);
- + }
- + else {
- + ast_log(LOG_ERROR , "object is NULL\n");
- + }
- +}
- +
- static int xmpp_client_config_post_apply(void *obj, void *arg, int flags)
- {
- struct ast_xmpp_client_config *cfg = obj;
- @@ -4430,7 +4470,7 @@ static int load_module(void)
- aco_option_register_custom(&cfg_info, "auth_policy", ACO_EXACT, global_options, "accept", global_bitfield_handler, 0);
- aco_option_register(&cfg_info, "username", ACO_EXACT, client_options, NULL, OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_xmpp_client_config, user));
- - aco_option_register(&cfg_info, "secret", ACO_EXACT, client_options, NULL, OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_xmpp_client_config, password));
- + aco_option_register(&cfg_info, "secret", ACO_EXACT, client_options, NULL, OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_xmpp_client_config, refresh_token));
- aco_option_register(&cfg_info, "serverhost", ACO_EXACT, client_options, NULL, OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_xmpp_client_config, server));
- aco_option_register(&cfg_info, "statusmessage", ACO_EXACT, client_options, "Online and Available", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_xmpp_client_config, statusmsg));
- aco_option_register(&cfg_info, "pubsub_node", ACO_EXACT, client_options, NULL, OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_xmpp_client_config, pubsubnode));
- diff -rupN asterisk-11.18.0/tests/test_json.c asterisk-11.18.0-oauth/tests/test_json.c
- --- asterisk-11.18.0/tests/test_json.c 1970-01-01 01:00:00.000000000 +0100
- +++ asterisk-11.18.0-oauth/tests/test_json.c 2015-06-22 17:46:02.172534485 +0100
- @@ -0,0 +1,760 @@
- +/*
- + * Asterisk -- An open source telephony toolkit.
- + *
- + * Copyright (C) 2012 - 2013, Digium, Inc.
- + *
- + * David M. Lee, II <dlee@digium.com>
- + *
- + * See http://www.asterisk.org for more information about
- + * the Asterisk project. Please do not directly contact
- + * any of the maintainers of this project for assistance;
- + * the project provides a web site, mailing lists and IRC
- + * channels for your use.
- + *
- + * This program is free software, distributed under the terms of
- + * the GNU General Public License Version 2. See the LICENSE file
- + * at the top of the source tree.
- + */
- +
- +/*!
- + * \file \brief Test JSON API.
- + *
- + * While some of these tests are actually testing our JSON library wrapper, the bulk of
- + * them are exploratory tests to determine what the behavior of the underlying JSON
- + * library is. This also gives us a good indicator if that behavior changes between
- + * Jansson revisions.
- + *
- + * \author\verbatim David M. Lee, II <dlee@digium.com> \endverbatim
- + *
- + * \ingroup tests
- + */
- +
- +/*** MODULEINFO
- + <depend>TEST_FRAMEWORK</depend>
- + <depend>res_json</depend>
- + <support_level>core</support_level>
- + ***/
- +
- +#include "asterisk.h"
- +
- +ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
- +#include "asterisk/json.h"
- +#include "asterisk/module.h"
- +#include "asterisk/test.h"
- +
- +/*!
- + * Number of allocations from JSON library that have not yet been freed.
- + */
- +static size_t alloc_count;
- +
- +/*!@{*/
- +/*!
- + * JSON library has its own reference counting, so we'll provide our own allocators to
- + * test that everything gets freed as expected.
- + */
- +static void *json_debug_malloc(size_t size)
- +{
- + void *p = ast_malloc(size);
- + if (p) {
- + ++alloc_count;
- + }
- + return p;
- +}
- +static void json_debug_free(void *p)
- +{
- + if (p) {
- + --alloc_count;
- + }
- + ast_free(p);
- +}
- +/*!@}*/
- +
- +AST_TEST_DEFINE(json_test)
- +{
- + enum ast_test_result_state res = AST_TEST_PASS;
- + struct ast_json *uut = NULL;
- + struct ast_json *expected = NULL;
- + struct ast_json *tail = NULL;
- + struct ast_json *merge = NULL;
- + struct ast_json *inner_child = NULL;
- + struct ast_json_iter *iter = NULL;
- + int uut_res = 0;
- + int count = 0;
- + char *str = NULL;
- + FILE *file = NULL;
- + char *filename = NULL;
- + struct ast_str *astr = NULL;
- +
- + auto void clean_vars(void);
- + /*!
- + * Free all local variables and set to NULL. This is an inner function to give a
- + * decent backtrace if a free() fails.
- + */
- + void clean_vars(void) {
- + ast_json_unref(uut);
- + ast_json_unref(expected);
- + ast_json_unref(tail);
- + ast_json_unref(merge);
- + ast_json_unref(inner_child);
- + uut = expected = tail = merge = inner_child = NULL;
- + iter = NULL;
- + uut_res = count = 0;
- + json_debug_free(str);
- + str = NULL;
- + if (file) fclose(file);
- + file = NULL;
- + free(filename);
- + filename = NULL;
- + astr = NULL;
- + }
- +
- + /*!
- + * Macro to free all local variables, and check for memory leaks. This is a macro
- + * so that ast_test_check() can get correct line numbers.
- + */
- +#define CLEAN_VARS() do { \
- + clean_vars(); \
- + ast_test_check(res, 0 == alloc_count); \
- + /* reset alloc_count to prevent false positives */ \
- + alloc_count = 0; \
- + } while (0)
- +
- + switch (cmd) {
- + case TEST_INIT:
- + info->name = "json";
- + info->category = "/main/json/";
- + info->summary = "Testing JSON abstraction library.";
- + info->description = "Test JSON abstraction library.";
- + return AST_TEST_NOT_RUN;
- + case TEST_EXECUTE:
- + break;
- + }
- +
- + /* Setup some special malloc tracking functions. */
- + ast_json_set_alloc_funcs(json_debug_malloc, json_debug_free);
- +
- + /* incref and decref should be NULL safe */
- + ast_json_ref(NULL);
- + ast_json_unref(NULL);
- + CLEAN_VARS();
- + CLEAN_VARS();
- +
- + /* Ridiculous looking tests for the fundamentals */
- + uut = ast_json_false();
- + ast_test_check(res, NULL != uut);
- + ast_test_check(res, AST_JSON_FALSE == ast_json_typeof(uut));
- + ast_test_check(res, !ast_json_is_null(uut));
- + ast_test_check(res, !ast_json_is_true(uut));
- + ast_test_check(res, ast_json_is_false(uut));
- + CLEAN_VARS();
- +
- + uut = ast_json_true();
- + ast_test_check(res, NULL != uut);
- + ast_test_check(res, AST_JSON_TRUE == ast_json_typeof(uut));
- + ast_test_check(res, !ast_json_is_null(uut));
- + ast_test_check(res, ast_json_is_true(uut));
- + ast_test_check(res, !ast_json_is_false(uut));
- + CLEAN_VARS();
- +
- + uut = ast_json_boolean(0);
- + ast_test_check(res, NULL != uut);
- + ast_test_check(res, AST_JSON_FALSE == ast_json_typeof(uut));
- + ast_test_check(res, !ast_json_is_null(uut));
- + ast_test_check(res, !ast_json_is_true(uut));
- + ast_test_check(res, ast_json_is_false(uut));
- + ast_test_check(res, ast_json_equal(uut, ast_json_false()));
- + ast_test_check(res, !ast_json_equal(uut, ast_json_true()));
- + CLEAN_VARS();
- +
- + uut = ast_json_boolean(1);
- + ast_test_check(res, NULL != uut);
- + ast_test_check(res, AST_JSON_TRUE == ast_json_typeof(uut));
- + ast_test_check(res, !ast_json_is_null(uut));
- + ast_test_check(res, ast_json_is_true(uut));
- + ast_test_check(res, !ast_json_is_false(uut));
- + ast_test_check(res, !ast_json_equal(uut, ast_json_false()));
- + ast_test_check(res, ast_json_equal(uut, ast_json_true()));
- + CLEAN_VARS();
- +
- + uut = ast_json_null();
- + ast_test_check(res, NULL != uut);
- + ast_test_check(res, AST_JSON_NULL == ast_json_typeof(uut));
- + ast_test_check(res, ast_json_is_null(uut));
- + ast_test_check(res, !ast_json_is_true(uut));
- + ast_test_check(res, !ast_json_is_false(uut));
- + CLEAN_VARS();
- +
- + /* NULL isn't null, true or false */
- + ast_test_check(res, !ast_json_is_null(NULL));
- + ast_test_check(res, !ast_json_is_false(NULL));
- + ast_test_check(res, !ast_json_is_true(NULL));
- +
- + /* Basic string tests */
- + uut = ast_json_string_create("Hello, json");
- + ast_test_check(res, NULL != uut);
- + ast_test_check(res, AST_JSON_STRING == ast_json_typeof(uut));
- + ast_test_check(res, 0 == strcmp("Hello, json", ast_json_string_get(uut)));
- +
- + uut_res = ast_json_string_set(uut, NULL);
- + ast_test_check(res, -1 == uut_res);
- + ast_test_check(res, 0 == strcmp("Hello, json", ast_json_string_get(uut)));
- +
- + uut_res = ast_json_string_set(uut, "Not UTF-8 - \xff");
- + ast_test_check(res, -1 == uut_res);
- + ast_test_check(res, 0 == strcmp("Hello, json", ast_json_string_get(uut)));
- +
- + uut_res = ast_json_string_set(uut, "Is UTF-8 - \xE2\x98\xBA");
- + ast_test_check(res, 0 == uut_res);
- + ast_test_check(res, 0 == strcmp("Is UTF-8 - \xE2\x98\xBA", ast_json_string_get(uut)));
- +
- + uut_res = ast_json_string_set(uut, "Goodbye, json");
- + ast_test_check(res, 0 == uut_res);
- + ast_test_check(res, 0 == strcmp("Goodbye, json", ast_json_string_get(uut)));
- + CLEAN_VARS();
- +
- + /* formatted string */
- + uut = ast_json_stringf("Hello, %s", "json");
- + expected = ast_json_string_create("Hello, json");
- + ast_test_check(res, NULL != uut);
- + ast_test_check(res, ast_json_equal(expected, uut));
- + CLEAN_VARS();
- +
- + /* Non-UTF-8 strings are invalid */
- + uut = ast_json_stringf("Not UTF-8 - %s", "\xff");
- + ast_test_check(res, NULL == uut);
- + CLEAN_VARS();
- +
- + /* NULL string */
- + uut = ast_json_string_create(NULL);
- + ast_test_check(res, NULL == uut);
- + CLEAN_VARS();
- +
- + /* NULL format string */
- + uut = ast_json_stringf(NULL);
- + ast_test_check(res, NULL == uut);
- + CLEAN_VARS();
- +
- + /* NULL JSON strings */
- + ast_test_check(res, NULL == ast_json_string_create(NULL));
- + ast_test_check(res, NULL == ast_json_string_get(NULL));
- + ast_test_check(res, -1 == ast_json_string_set(NULL, "not null"));
- +
- + /* string_value from non-string elements should return NULL */
- + ast_test_check(res, NULL == ast_json_string_get(ast_json_null()));
- + ast_test_check(res, NULL == ast_json_string_get(ast_json_false()));
- + ast_test_check(res, NULL == ast_json_string_get(ast_json_true()));
- +
- + /* Integer tests */
- + uut = ast_json_integer_create(0);
- + ast_test_check(res, NULL != uut);
- + ast_test_check(res, AST_JSON_INTEGER == ast_json_typeof(uut));
- + ast_test_check(res, 0 == ast_json_integer_get(uut));
- +
- + uut_res = ast_json_integer_set(uut, 1);
- + ast_test_check(res, 0 == uut_res);
- + ast_test_check(res, 1 == ast_json_integer_get(uut));
- +
- + uut_res = ast_json_integer_set(uut, -1);
- + ast_test_check(res, 0 == uut_res);
- + ast_test_check(res, -1 == ast_json_integer_get(uut));
- +
- + uut_res = ast_json_integer_set(uut, LLONG_MAX);
- + ast_test_check(res, 0 == uut_res);
- + ast_test_check(res, LLONG_MAX == ast_json_integer_get(uut));
- +
- + uut_res = ast_json_integer_set(uut, LLONG_MIN);
- + ast_test_check(res, 0 == uut_res);
- + ast_test_check(res, LLONG_MIN == ast_json_integer_get(uut));
- + CLEAN_VARS();
- +
- + /* Non-ints return 0 integer value */
- + ast_test_check(res, 0 == ast_json_integer_get(ast_json_null()));
- + ast_test_check(res, 0 == ast_json_integer_get(ast_json_true()));
- + ast_test_check(res, 0 == ast_json_integer_get(ast_json_false()));
- +
- + /* JSON NULL integers */
- + ast_test_check(res, 0 == ast_json_integer_get(NULL));
- + ast_test_check(res, -1 == ast_json_integer_set(NULL, 911));
- + ast_test_check(res, 0 == ast_json_array_size(NULL));
- +
- + /* No magical parsing of strings into ints */
- + uut = ast_json_string_create("314");
- + ast_test_check(res, 0 == ast_json_integer_get(uut));
- + CLEAN_VARS();
- +
- + /* Or vice-versa */
- + uut = ast_json_integer_create(314);
- + ast_test_check(res, NULL == ast_json_string_get(uut));
- + CLEAN_VARS();
- +
- + /* array creation */
- + uut = ast_json_array_create();
- + ast_test_check(res, NULL != uut);
- + ast_test_check(res, AST_JSON_ARRAY == ast_json_typeof(uut));
- + ast_test_check(res, 0 == ast_json_array_size(uut));
- + CLEAN_VARS();
- +
- + /* array append */
- + uut = ast_json_array_create();
- + uut_res = ast_json_array_append(uut, ast_json_string_create("one"));
- + ast_test_check(res, 0 == uut_res);
- + ast_test_check(res, 1 == ast_json_array_size(uut));
- + ast_test_check(res, 0 == strcmp("one", ast_json_string_get(ast_json_array_get(uut, 0))));
- + /* index out of range */
- + ast_test_check(res, NULL == ast_json_array_get(uut, 1));
- + ast_test_check(res, NULL == ast_json_array_get(uut, -1));
- + CLEAN_VARS();
- +
- + /* array insert */
- + uut = ast_json_pack("[s]", "one");
- + uut_res = ast_json_array_insert(uut, 0, ast_json_string_create("zero"));
- + ast_test_check(res, 0 == uut_res);
- + ast_test_check(res, 2 == ast_json_array_size(uut));
- + ast_test_check(res, 0 == strcmp("zero", ast_json_string_get(ast_json_array_get(uut, 0))));
- + ast_test_check(res, 0 == strcmp("one", ast_json_string_get(ast_json_array_get(uut, 1))));
- + CLEAN_VARS();
- +
- + /* array set */
- + uut = ast_json_pack("[s, s]", "zero", "one");
- + uut_res = ast_json_array_set(uut, 1, ast_json_integer_create(1));
- + ast_test_check(res, 0 == uut_res);
- + ast_test_check(res, 2 == ast_json_array_size(uut));
- + ast_test_check(res, 0 == strcmp("zero", ast_json_string_get(ast_json_array_get(uut, 0))));
- + ast_test_check(res, 1 == ast_json_integer_get(ast_json_array_get(uut, 1)));
- + CLEAN_VARS();
- +
- + /* array remove */
- + uut = ast_json_array_create();
- + uut_res = ast_json_array_append(uut, ast_json_string_create("zero"));
- + uut_res = ast_json_array_append(uut, ast_json_integer_create(1));
- + uut_res = ast_json_array_remove(uut, 0);
- + ast_test_check(res, 0 == uut_res);
- + ast_test_check(res, 1 == ast_json_array_size(uut));
- + ast_test_check(res, 1 == ast_json_integer_get(ast_json_array_get(uut, 0)));
- + CLEAN_VARS();
- +
- + /* array clear */
- + uut = ast_json_array_create();
- + uut_res = ast_json_array_append(uut, ast_json_string_create("zero"));
- + uut_res = ast_json_array_append(uut, ast_json_integer_create(1));
- + uut_res = ast_json_array_clear(uut);
- + ast_test_check(res, 0 == uut_res);
- + ast_test_check(res, 0 == ast_json_array_size(uut));
- + CLEAN_VARS();
- +
- + /* array extending */
- + expected = ast_json_array_create();
- + ast_json_array_append(expected, ast_json_string_create("a"));
- + ast_json_array_append(expected, ast_json_string_create("b"));
- + ast_json_array_append(expected, ast_json_string_create("c"));
- + ast_json_array_append(expected, ast_json_integer_create(1));
- + ast_json_array_append(expected, ast_json_integer_create(2));
- + ast_json_array_append(expected, ast_json_integer_create(3));
- +
- + uut = ast_json_array_create();
- + ast_json_array_append(uut, ast_json_string_create("a"));
- + ast_json_array_append(uut, ast_json_string_create("b"));
- + ast_json_array_append(uut, ast_json_string_create("c"));
- +
- + tail = ast_json_array_create();
- + ast_json_array_append(tail, ast_json_integer_create(1));
- + ast_json_array_append(tail, ast_json_integer_create(2));
- + ast_json_array_append(tail, ast_json_integer_create(3));
- +
- + uut_res = ast_json_array_extend(uut, tail);
- + ast_test_check(res, 0 == uut_res);
- + ast_test_check(res, ast_json_equal(expected, uut));
- + /* tail is preserved */
- + ast_test_check(res, 3 == ast_json_array_size(tail));
- + CLEAN_VARS();
- +
- + /* array NULL checks */
- + ast_test_check(res, 0 == ast_json_array_size(NULL));
- + ast_test_check(res, NULL == ast_json_array_get(NULL, 0));
- + ast_test_check(res, -1 == ast_json_array_set(NULL, 0, ast_json_null()));
- + ast_test_check(res, -1 == ast_json_array_append(NULL, ast_json_null()));
- + ast_test_check(res, -1 == ast_json_array_insert(NULL, 0, ast_json_null()));
- + ast_test_check(res, -1 == ast_json_array_remove(NULL, 0));
- + ast_test_check(res, -1 == ast_json_array_clear(NULL));
- + uut = ast_json_array_create();
- + ast_test_check(res, -1 == ast_json_array_extend(uut, NULL));
- + ast_test_check(res, -1 == ast_json_array_extend(NULL, uut));
- + ast_test_check(res, -1 == ast_json_array_extend(NULL, NULL));
- + CLEAN_VARS();
- +
- + /* object allocation */
- + uut = ast_json_object_create();
- + ast_test_check(res, NULL != uut);
- + ast_test_check(res, AST_JSON_OBJECT == ast_json_typeof(uut));
- + ast_test_check(res, 0 == ast_json_object_size(uut));
- + CLEAN_VARS();
- +
- + /* object set */
- + expected = ast_json_pack("{s: i, s: i, s: i}", "one", 1, "two", 2, "three", 3);
- + uut = ast_json_object_create();
- + uut_res = ast_json_object_set(uut, "one", ast_json_integer_create(1));
- + ast_test_check(res, 0 == uut_res);
- + uut_res = ast_json_object_set(uut, "two", ast_json_integer_create(2));
- + ast_test_check(res, 0 == uut_res);
- + uut_res = ast_json_object_set(uut, "three", ast_json_integer_create(3));
- + ast_test_check(res, 0 == uut_res);
- + ast_test_check(res, ast_json_equal(expected, uut));
- + ast_test_check(res, NULL == ast_json_object_get(uut, "dne"));
- + CLEAN_VARS();
- +
- + /* object set existing */
- + uut = ast_json_pack("{s: i, s: i, s: i}", "one", 1, "two", 2, "three", 3);
- + uut_res = ast_json_object_set(uut, "two", ast_json_integer_create(-2));
- + ast_test_check(res, 0 == uut_res);
- + ast_test_check(res, -2 == ast_json_integer_get(ast_json_object_get(uut, "two")));
- + CLEAN_VARS();
- +
- + /* object get */
- + uut = ast_json_pack("{s: i, s: i, s: i}", "one", 1, "two", 2, "three", 3);
- + ast_test_check(res, 2 == ast_json_integer_get(ast_json_object_get(uut, "two")));
- + ast_test_check(res, NULL == ast_json_object_get(uut, "dne"));
- + ast_test_check(res, NULL == ast_json_object_get(uut, NULL));
- + CLEAN_VARS();
- +
- + /* object del */
- + expected = ast_json_object_create();
- + uut = ast_json_object_create();
- + uut_res = ast_json_object_set(uut, "one", ast_json_integer_create(1));
- + uut_res = ast_json_object_del(uut, "one");
- + ast_test_check(res, 0 == uut_res);
- + ast_test_check(res, ast_json_equal(expected, uut));
- + uut_res = ast_json_object_del(uut, "dne");
- + ast_test_check(res, -1 == uut_res);
- + CLEAN_VARS();
- +
- + /* object clear */
- + uut = ast_json_object_create();
- + ast_json_object_set(uut, "one", ast_json_integer_create(1));
- + ast_json_object_set(uut, "two", ast_json_integer_create(2));
- + ast_json_object_set(uut, "three", ast_json_integer_create(3));
- + uut_res = ast_json_object_clear(uut);
- + ast_test_check(res, 0 == uut_res);
- + ast_test_check(res, 0 == ast_json_object_size(uut));
- + CLEAN_VARS();
- +
- + /* object merging - all */
- + uut = ast_json_object_create();
- + ast_json_object_set(uut, "one", ast_json_integer_create(1));
- + ast_json_object_set(uut, "two", ast_json_integer_create(2));
- + ast_json_object_set(uut, "three", ast_json_integer_create(3));
- +
- + merge = ast_json_object_create();
- + ast_json_object_set(merge, "three", ast_json_integer_create(-3));
- + ast_json_object_set(merge, "four", ast_json_integer_create(-4));
- + ast_json_object_set(merge, "five", ast_json_integer_create(-5));
- +
- + expected = ast_json_object_create();
- + ast_json_object_set(expected, "one", ast_json_integer_create(1));
- + ast_json_object_set(expected, "two", ast_json_integer_create(2));
- + ast_json_object_set(expected, "three", ast_json_integer_create(-3));
- + ast_json_object_set(expected, "four", ast_json_integer_create(-4));
- + ast_json_object_set(expected, "five", ast_json_integer_create(-5));
- +
- + uut_res = ast_json_object_update(uut, merge);
- + ast_test_check(res, 0 == uut_res);
- + ast_test_check(res, ast_json_equal(expected, uut));
- + /* merge object is untouched */
- + ast_test_check(res, 3 == ast_json_object_size(merge));
- + CLEAN_VARS();
- +
- + /* object merging - existing */
- + uut = ast_json_object_create();
- + ast_json_object_set(uut, "one", ast_json_integer_create(1));
- + ast_json_object_set(uut, "two", ast_json_integer_create(2));
- + ast_json_object_set(uut, "three", ast_json_integer_create(3));
- +
- + merge = ast_json_object_create();
- + ast_json_object_set(merge, "three", ast_json_integer_create(-3));
- + ast_json_object_set(merge, "four", ast_json_integer_create(-4));
- + ast_json_object_set(merge, "five", ast_json_integer_create(-5));
- +
- + expected = ast_json_object_create();
- + ast_json_object_set(expected, "one", ast_json_integer_create(1));
- + ast_json_object_set(expected, "two", ast_json_integer_create(2));
- + ast_json_object_set(expected, "three", ast_json_integer_create(-3));
- +
- + uut_res = ast_json_object_update_existing(uut, merge);
- + ast_test_check(res, 0 == uut_res);
- + ast_test_check(res, ast_json_equal(expected, uut));
- + /* merge object is untouched */
- + ast_test_check(res, 3 == ast_json_object_size(merge));
- + CLEAN_VARS();
- +
- + /* object merging - missing */
- + uut = ast_json_object_create();
- + ast_json_object_set(uut, "one", ast_json_integer_create(1));
- + ast_json_object_set(uut, "two", ast_json_integer_create(2));
- + ast_json_object_set(uut, "three", ast_json_integer_create(3));
- +
- + merge = ast_json_object_create();
- + ast_json_object_set(merge, "three", ast_json_integer_create(-3));
- + ast_json_object_set(merge, "four", ast_json_integer_create(-4));
- + ast_json_object_set(merge, "five", ast_json_integer_create(-5));
- +
- + expected = ast_json_object_create();
- + ast_json_object_set(expected, "one", ast_json_integer_create(1));
- + ast_json_object_set(expected, "two", ast_json_integer_create(2));
- + ast_json_object_set(expected, "three", ast_json_integer_create(3));
- + ast_json_object_set(expected, "four", ast_json_integer_create(-4));
- + ast_json_object_set(expected, "five", ast_json_integer_create(-5));
- +
- + uut_res = ast_json_object_update_missing(uut, merge);
- + ast_test_check(res, 0 == uut_res);
- + ast_test_check(res, ast_json_equal(expected, uut));
- + /* merge object is untouched */
- + ast_test_check(res, 3 == ast_json_object_size(merge));
- + CLEAN_VARS();
- +
- + /* Object NULL testing */
- + ast_test_check(res, 0 == ast_json_object_size(NULL));
- + ast_test_check(res, NULL == ast_json_object_get(NULL, "not null"));
- + ast_test_check(res, -1 == ast_json_object_set(NULL, "not null", ast_json_null()));
- + ast_test_check(res, -1 == ast_json_object_del(NULL, "not null"));
- + ast_test_check(res, -1 == ast_json_object_clear(NULL));
- + uut = ast_json_object_create();
- + ast_test_check(res, -1 == ast_json_object_update(NULL, uut));
- + ast_test_check(res, -1 == ast_json_object_update(uut, NULL));
- + ast_test_check(res, -1 == ast_json_object_update(NULL, NULL));
- + ast_test_check(res, -1 == ast_json_object_update_existing(NULL, uut));
- + ast_test_check(res, -1 == ast_json_object_update_existing(uut, NULL));
- + ast_test_check(res, -1 == ast_json_object_update_existing(NULL, NULL));
- + ast_test_check(res, -1 == ast_json_object_update_missing(NULL, uut));
- + ast_test_check(res, -1 == ast_json_object_update_missing(uut, NULL));
- + ast_test_check(res, -1 == ast_json_object_update_missing(NULL, NULL));
- + CLEAN_VARS();
- +
- + /* Object iterator testing */
- + uut = ast_json_object_create();
- + ast_json_object_set(uut, "one", ast_json_integer_create(1));
- + ast_json_object_set(uut, "two", ast_json_integer_create(2));
- + ast_json_object_set(uut, "three", ast_json_integer_create(3));
- + ast_json_object_set(uut, "four", ast_json_integer_create(4));
- + ast_json_object_set(uut, "five", ast_json_integer_create(5));
- +
- + /* Iterate through the object; be aware that order isn't specified */
- + iter = ast_json_object_iter(uut);
- + ast_test_check(res, NULL != iter);
- + while (NULL != iter) {
- + if (0 == strcmp("one", ast_json_object_iter_key(iter))) {
- + ast_test_check(res, 1 == ast_json_integer_get(ast_json_object_iter_value(iter)));
- + } else if (0 == strcmp("two", ast_json_object_iter_key(iter))) {
- + ast_test_check(res, 2 == ast_json_integer_get(ast_json_object_iter_value(iter)));
- + } else if (0 == strcmp("three", ast_json_object_iter_key(iter))) {
- + ast_test_check(res, 3 == ast_json_integer_get(ast_json_object_iter_value(iter)));
- + } else if (0 == strcmp("four", ast_json_object_iter_key(iter))) {
- + ast_test_check(res, 4 == ast_json_integer_get(ast_json_object_iter_value(iter)));
- + } else if (0 == strcmp("five", ast_json_object_iter_key(iter))) {
- + ast_test_check(res, 5 == ast_json_integer_get(ast_json_object_iter_value(iter)));
- + } else {
- + /* Unexpected key */
- + ast_test_check(res, 0);
- + }
- + iter = ast_json_object_iter_next(uut, iter);
- + ++count;
- + }
- + ast_test_check(res, 5 == count);
- +
- + /* iterator non-existing key */
- + iter = ast_json_object_iter_at(uut, "dne");
- + ast_test_check(res, NULL == iter);
- +
- + /* iterator specific key */
- + iter = ast_json_object_iter_at(uut, "three");
- + ast_test_check(res, NULL != iter);
- + ast_test_check(res, 3 == ast_json_integer_get(ast_json_object_iter_value(iter)));
- +
- + /* set via iter */
- + iter = ast_json_object_iter_at(uut, "three");
- + uut_res = ast_json_object_iter_set(uut, iter, ast_json_integer_create(-3));
- + ast_test_check(res, 0 == uut_res);
- + ast_test_check(res, -3 == ast_json_integer_get(ast_json_object_get(uut, "three")));
- + CLEAN_VARS();
- +
- + /* iterator NULL tests */
- + uut = ast_json_object_create();
- + ast_test_check(res, NULL == ast_json_object_iter(NULL));
- + ast_test_check(res, NULL == ast_json_object_iter_at(NULL, "not null"));
- + ast_test_check(res, NULL == ast_json_object_iter_next(NULL, NULL));
- + ast_test_check(res, NULL == ast_json_object_iter_next(uut, NULL));
- + ast_test_check(res, NULL == ast_json_object_iter_key(NULL));
- + ast_test_check(res, NULL == ast_json_object_iter_value(NULL));
- + ast_test_check(res, -1 == ast_json_object_iter_set(NULL, NULL, ast_json_null()));
- + ast_test_check(res, -1 == ast_json_object_iter_set(uut, NULL, ast_json_null()));
- + CLEAN_VARS();
- +
- + /* dump/load string */
- + expected = ast_json_pack("{ s: i }", "one", 1);
- + str = ast_json_dump_string(expected);
- + ast_test_check(res, NULL != str);
- + uut = ast_json_load_string(str, NULL);
- + ast_test_check(res, NULL != uut);
- + ast_test_check(res, ast_json_equal(expected, uut));
- + CLEAN_VARS();
- +
- + /* dump_string NULL */
- + ast_test_check(res, NULL == ast_json_dump_string(NULL));
- +
- + /* dump/load ast_str */
- + expected = ast_json_pack("{ s: i }", "one", 1);
- + astr = ast_str_create(1); /* should expand to hold output */
- + uut_res = ast_json_dump_str(expected, &astr);
- + ast_test_check(res, 0 == uut_res);
- + uut = ast_json_load_str(astr, NULL);
- + ast_test_check(res, NULL != uut);
- + ast_test_check(res, ast_json_equal(expected, uut));
- + ast_free(astr);
- + CLEAN_VARS();
- +
- + /* dump ast_str growth failure */
- + expected = ast_json_pack("{ s: i }", "one", 1);
- + astr = ast_str_alloca(1); /* cannot grow */
- + uut_res = ast_json_dump_str(expected, &astr);
- + ast_test_check(res, 0 != uut_res);
- + CLEAN_VARS();
- +
- + /* load buffer */
- + str = "{ \"one\": 1 } trailing garbage";
- + uut = ast_json_load_string(str, NULL);
- + ast_test_check(res, NULL == uut);
- + uut = ast_json_load_buf(str, strlen("{ \"one\": 1 }"), NULL);
- + ast_test_check(res, NULL != uut);
- + str = NULL;
- + CLEAN_VARS();
- +
- + /* dump/load file */
- + expected = ast_json_pack("{ s: i }", "one", 1);
- + filename = tempnam(NULL, "ast-json");
- + file = fopen(filename, "w");
- + uut_res = ast_json_dump_file(expected, file);
- + ast_test_check(res, 0 == uut_res);
- + fclose(file);
- + file = fopen(filename, "r");
- + uut = ast_json_load_file(file, NULL);
- + ast_test_check(res, ast_json_equal(expected, uut));
- + CLEAN_VARS();
- +
- + /* dump/load filename */
- + expected = ast_json_pack("{ s: i }", "one", 1);
- + filename = tempnam(NULL, "ast-json");
- + uut_res = ast_json_dump_new_file(expected, filename);
- + ast_test_check(res, 0 == uut_res);
- + uut = ast_json_load_new_file(filename, NULL);
- + ast_test_check(res, ast_json_equal(expected, uut));
- + CLEAN_VARS();
- +
- + /* dump/load NULL tests */
- + uut = ast_json_load_string("{ \"one\": 1 }", NULL);
- + ast_test_check(res, NULL != uut);
- + filename = tempnam(NULL, "ast-json");
- + file = fopen(filename, "w");
- + ast_test_check(res, NULL == ast_json_dump_string(NULL));
- + ast_test_check(res, -1 == ast_json_dump_file(NULL, file));
- + ast_test_check(res, -1 == ast_json_dump_file(uut, NULL));
- + ast_test_check(res, -1 == ast_json_dump_file(NULL, NULL));
- + ast_test_check(res, -1 == ast_json_dump_new_file(uut, NULL));
- + ast_test_check(res, -1 == ast_json_dump_new_file(NULL, filename));
- + ast_test_check(res, -1 == ast_json_dump_new_file(NULL, NULL));
- + ast_test_check(res, NULL == ast_json_load_string(NULL, NULL));
- + ast_test_check(res, NULL == ast_json_load_buf(NULL, 0, NULL));
- + ast_test_check(res, NULL == ast_json_load_file(NULL, NULL));
- + ast_test_check(res, NULL == ast_json_load_new_file(NULL, NULL));
- + CLEAN_VARS();
- +
- + /* parse errors */
- + ast_test_check(res, NULL == ast_json_load_string("'singleton'", NULL));
- + ast_test_check(res, NULL == ast_json_load_string("{ no value }", NULL));
- + ast_test_check(res, NULL == ast_json_load_string("{ 'no': 'curly' ", NULL));
- + ast_test_check(res, NULL == ast_json_load_string("[ 'no', 'square'", NULL));
- + ast_test_check(res, NULL == ast_json_load_string("{ 1: 'int key' }", NULL));
- + ast_test_check(res, NULL == ast_json_load_string("", NULL));
- + ast_test_check(res, NULL == ast_json_load_string("{ 'missing' 'colon' }", NULL));
- + ast_test_check(res, NULL == ast_json_load_string("[ 'missing' 'comma' ]", NULL));
- +
- + /* pack test */
- + expected = ast_json_array_create();
- + ast_json_array_append(expected, ast_json_array_create());
- + ast_json_array_append(expected, ast_json_object_create());
- + ast_json_array_append(ast_json_array_get(expected, 0), ast_json_integer_create(1));
- + ast_json_array_append(ast_json_array_get(expected, 0), ast_json_integer_create(2));
- + ast_json_object_set(ast_json_array_get(expected, 1), "cool", ast_json_true());
- + uut = ast_json_pack("[[i,i],{s:b}]", 1, 2, "cool", 1);
- + ast_test_check(res, NULL != uut);
- + ast_test_check(res, ast_json_equal(expected, uut));
- + CLEAN_VARS();
- +
- + /* pack errors */
- + ast_test_check(res, NULL == ast_json_pack(NULL));
- + ast_test_check(res, NULL == ast_json_pack("{s:i", "no curly", 911));
- + ast_test_check(res, NULL == ast_json_pack("[s, s", "no", "square"));
- +
- + /* copy test */
- + expected = ast_json_pack("{s: {s: i}}", "outer", "inner", 8675309);
- + uut = ast_json_copy(expected);
- + ast_test_check(res, NULL != uut);
- + ast_test_check(res, ast_json_equal(expected, uut));
- + ast_test_check(res, ast_json_object_get(expected, "outer") == ast_json_object_get(uut, "outer"));
- + CLEAN_VARS();
- +
- + /* deep copy test */
- + expected = ast_json_pack("{s: {s: i}}", "outer", "inner", 8675309);
- + uut = ast_json_deep_copy(expected);
- + ast_test_check(res, NULL != uut);
- + ast_test_check(res, ast_json_equal(expected, uut));
- + ast_test_check(res, ast_json_object_get(expected, "outer") != ast_json_object_get(uut, "outer"));
- + /* Changing the inner value of one should not change the other */
- + ast_json_integer_set(ast_json_object_get(ast_json_object_get(uut, "outer"), "inner"), 411);
- + ast_test_check(res, !ast_json_equal(expected, uut));
- + CLEAN_VARS();
- +
- + /* copy NULL */
- + ast_test_check(res, NULL == ast_json_copy(NULL));
- + ast_test_check(res, NULL == ast_json_deep_copy(NULL));
- +
- + /* circular reference testing */
- + /* Cannot add self */
- + uut = ast_json_object_create();
- + uut_res = ast_json_object_set(uut, "myself", uut);
- + ast_test_check(res, -1 == uut_res);
- + ast_test_check(res, 0 == ast_json_object_size(uut));
- + CLEAN_VARS();
- +
- + uut = ast_json_array_create();
- + uut_res = ast_json_object_set(uut, "myself", uut);
- + ast_test_check(res, -1 == uut_res);
- + ast_test_check(res, 0 == ast_json_array_size(uut));
- + CLEAN_VARS();
- +
- + /* can add to self if you're clever enough, but it should not encode */
- + uut = ast_json_object_create();
- + inner_child = ast_json_object_create();
- + uut_res = ast_json_object_set(uut, "inner_child", ast_json_ref(inner_child)); /* incref to keep a reference */
- + ast_test_check(res, 0 == uut_res);
- + uut_res = ast_json_object_set(inner_child, "parent", ast_json_ref(uut)); /* incref to keep a reference */
- + ast_test_check(res, 0 == uut_res);
- + str = ast_json_dump_string(uut);
- + ast_test_check(res, NULL == str);
- + /* Circular refs screw up reference counting, so break the cycle */
- + ast_json_object_clear(inner_child);
- + CLEAN_VARS();
- +
- + return res;
- +}
- +
- +static int unload_module(void)
- +{
- + AST_TEST_UNREGISTER(json_test);
- + return 0;
- +}
- +
- +static int load_module(void)
- +{
- + AST_TEST_REGISTER(json_test);
- + return AST_MODULE_LOAD_SUCCESS;
- +}
- +
- +AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "JSON testing.");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement