diff --git a/include/maxscale/json_api.h b/include/maxscale/json_api.h deleted file mode 100644 index 0553b8606..000000000 --- a/include/maxscale/json_api.h +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright (c) 2018 MariaDB Corporation Ab - * - * Use of this software is governed by the Business Source License included - * in the LICENSE.TXT file and at www.mariadb.com/bsl11. - * - * Change Date: 2022-01-01 - * - * On the date above, in accordance with the Business Source License, use - * of this software will be governed by version 2 or later of the General - * Public License. - */ -#pragma once - -/** - * @file Helper functions for creating JSON API conforming objects - * - * @see http://jsonapi.org/format/ - */ - -#include -#include - -MXS_BEGIN_DECLS - -/** Resource endpoints */ -#define MXS_JSON_API_SERVERS "/servers/" -#define MXS_JSON_API_SERVICES "/services/" -#define MXS_JSON_API_FILTERS "/filters/" -#define MXS_JSON_API_MONITORS "/monitors/" -#define MXS_JSON_API_SESSIONS "/sessions/" -#define MXS_JSON_API_MAXSCALE "/maxscale/" -#define MXS_JSON_API_THREADS "/maxscale/threads/" -#define MXS_JSON_API_LOGS "/maxscale/logs/" -#define MXS_JSON_API_TASKS "/maxscale/tasks/" -#define MXS_JSON_API_MODULES "/maxscale/modules/" -#define MXS_JSON_API_QC_STATS "/maxscale/qc_stats/" -#define MXS_JSON_API_QC "/maxscale/query_classifier/" -#define MXS_JSON_API_QC_CLASSIFY "/maxscale/query_classifier/classify" -#define MXS_JSON_API_USERS "/users/" - -/** - * @brief Create a JSON object - * - * @param host Hostname of this server - * @param self Endpoint of this resource - * @param data The JSON data, either an array or an object, stored in - * the `data` field of the returned object - * - * @return A valid top-level JSON API object - */ -json_t* mxs_json_resource(const char* host, const char* self, json_t* data); - - -/** - * @brief Create a JSON metadata object - * - * This should be used to transport non-standard data to the client. - * - * @param host Hostname of this server - * @param self Endpoint of this resource - * @param data The JSON data, either an array or an object, stored in - * the `meta` field of the returned object - * - * @return A valid top-level JSON API object - */ -json_t* mxs_json_metadata(const char* host, const char* self, json_t* data); - -/** - * @brief Create an empty relationship object - * - * @param host Hostname of this server - * @param endpoint The endpoint for the resource's collection - * - * @return New relationship object - */ -json_t* mxs_json_relationship(const char* host, const char* endpoint); - -/** - * @brief Add an item to a relationship object - * - * @param rel Relationship created with mxs_json_relationship - * @param id The resource identifier - * @param type The resource type - */ -void mxs_json_add_relation(json_t* rel, const char* id, const char* type); - -/** - * @brief Create self link object - * - * The self link points to the object itself. - * - * @param host Hostname of this server - * @param path Base path to the resource collection - * @param id The identified of this resource - * - * @return New self link object - */ -json_t* mxs_json_self_link(const char* host, const char* path, const char* id); - -/** - * @brief Return value at provided JSON Pointer - * - * @param json JSON object - * @param json_ptr JSON Pointer to object - * - * @return Pointed value or NULL if no value is found - */ -json_t* mxs_json_pointer(json_t* json, const char* json_ptr); - - -/** - * @brief Return a JSON formatted error - * - * @param format Format string - * @param ... Variable argument list - * - * @return The error as JSON - */ -json_t* mxs_json_error(const char* format, ...); - -/** - * @brief Append error to existing JSON object. - * - * @param object Existing json error object, or NULL. - * @param format Format string - * @param ... Variable argument list - * - * @return The error added to 'errors' array of the JSON object. - */ -json_t* mxs_json_error_append(json_t* object, const char* format, ...) mxb_attribute((format (printf, 2, 3))); - -MXS_END_DECLS diff --git a/server/core/adminusers.cc b/server/core/adminusers.cc index 6f2488b6f..28056b00c 100644 --- a/server/core/adminusers.cc +++ b/server/core/adminusers.cc @@ -26,7 +26,7 @@ #include #include #include -#include +#include /** * @file adminusers.c - Administration user account management diff --git a/server/core/config.cc b/server/core/config.cc index b25367433..45be52272 100644 --- a/server/core/config.cc +++ b/server/core/config.cc @@ -46,7 +46,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/server/core/config_runtime.cc b/server/core/config_runtime.cc index 77b4b72ec..9d5df5af9 100644 --- a/server/core/config_runtime.cc +++ b/server/core/config_runtime.cc @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include #include #include @@ -50,23 +50,31 @@ using maxscale::Monitor; static std::mutex crt_lock; #define RUNTIME_ERRMSG_BUFSIZE 512 -thread_local char runtime_errmsg[RUNTIME_ERRMSG_BUFSIZE]; +thread_local std::vector runtime_errmsg; typedef std::function JsonValidator; typedef std::pair Relationship; void config_runtime_error(const char* fmt, ...) { + char errmsg[RUNTIME_ERRMSG_BUFSIZE]; va_list list; va_start(list, fmt); - vsnprintf(runtime_errmsg, sizeof(runtime_errmsg), fmt, list); + vsnprintf(errmsg, sizeof(errmsg), fmt, list); va_end(list); + runtime_errmsg.push_back(errmsg); } static std::string runtime_get_error() { - std::string rval(runtime_errmsg); - runtime_errmsg[0] = '\0'; + std::string rval; + + if (!runtime_errmsg.empty()) + { + rval = runtime_errmsg.back(); + runtime_errmsg.clear(); + } + return rval; } @@ -2779,11 +2787,11 @@ bool runtime_create_listener_from_json(Service* service, json_t* json) json_t* runtime_get_json_error() { json_t* obj = NULL; - std::string errmsg = runtime_get_error(); - if (errmsg.length()) + if (!runtime_errmsg.empty()) { - obj = mxs_json_error(errmsg.c_str()); + obj = mxs_json_error(runtime_errmsg); + runtime_errmsg.clear(); } return obj; diff --git a/server/core/filter.cc b/server/core/filter.cc index 9fb5304fe..e394c7582 100644 --- a/server/core/filter.cc +++ b/server/core/filter.cc @@ -35,7 +35,7 @@ #include #include #include -#include +#include #include "internal/config.hh" #include "internal/modules.hh" diff --git a/server/core/housekeeper.cc b/server/core/housekeeper.cc index 9742463a4..56dd71eab 100644 --- a/server/core/housekeeper.cc +++ b/server/core/housekeeper.cc @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include /** diff --git a/server/core/json_api.cc b/server/core/json_api.cc index f876869b1..f6f3c2d2b 100644 --- a/server/core/json_api.cc +++ b/server/core/json_api.cc @@ -11,7 +11,7 @@ * Public License. */ -#include +#include #include @@ -207,6 +207,24 @@ json_t* mxs_json_error(const char* format, ...) return json_error(message); } +json_t* mxs_json_error(const std::vector& errors) +{ + json_t* rval = nullptr; + + if (!errors.empty()) + { + auto it = errors.begin(); + rval = json_error(it->c_str()); + + for (it = std::next(it); it != errors.end(); ++it) + { + rval = mxs_json_error_append(rval, it->c_str()); + } + } + + return rval; +} + static json_t* json_error_append(json_t* obj, const char* message) { json_t* err = json_error_detail(message); diff --git a/server/core/load_utils.cc b/server/core/load_utils.cc index 7cc65536f..607849d9a 100644 --- a/server/core/load_utils.cc +++ b/server/core/load_utils.cc @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/server/core/log.cc b/server/core/log.cc index 2bfddf4c0..246933b75 100644 --- a/server/core/log.cc +++ b/server/core/log.cc @@ -23,7 +23,7 @@ #include #include -#include +#include #include namespace diff --git a/server/core/monitor.cc b/server/core/monitor.cc index 25a04d697..b9cbab8cf 100644 --- a/server/core/monitor.cc +++ b/server/core/monitor.cc @@ -32,7 +32,7 @@ #include #include #include -#include +#include #include #include #include @@ -40,7 +40,7 @@ #include #include #include -#include +#include #include #include "internal/config.hh" diff --git a/server/core/query_classifier.cc b/server/core/query_classifier.cc index e9fec8d70..05dab676a 100644 --- a/server/core/query_classifier.cc +++ b/server/core/query_classifier.cc @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/server/core/resource.cc b/server/core/resource.cc index 8dd5fd638..1b67c23bd 100644 --- a/server/core/resource.cc +++ b/server/core/resource.cc @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include diff --git a/server/core/routingworker.cc b/server/core/routingworker.cc index d6a59e091..11af2d5e2 100644 --- a/server/core/routingworker.cc +++ b/server/core/routingworker.cc @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include #include diff --git a/server/core/server.cc b/server/core/server.cc index c87e8a63f..911055c68 100644 --- a/server/core/server.cc +++ b/server/core/server.cc @@ -38,7 +38,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/server/core/service.cc b/server/core/service.cc index 885ca561a..67a4b7461 100644 --- a/server/core/service.cc +++ b/server/core/service.cc @@ -51,7 +51,7 @@ #include #include #include -#include +#include #include #include diff --git a/server/core/session.cc b/server/core/session.cc index 8eb7235eb..4332da5bf 100644 --- a/server/core/session.cc +++ b/server/core/session.cc @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/server/core/test/test_json.cc b/server/core/test/test_json.cc index 65064a4cc..5c6c8f87a 100644 --- a/server/core/test/test_json.cc +++ b/server/core/test/test_json.cc @@ -16,7 +16,7 @@ #include #include -#include +#include using std::string; diff --git a/server/core/test/test_modulecmd.cc b/server/core/test/test_modulecmd.cc index c471ce699..3f687c33e 100644 --- a/server/core/test/test_modulecmd.cc +++ b/server/core/test/test_modulecmd.cc @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include "../internal/monitor.hh" diff --git a/server/modules/filter/masking/maskingfilter.cc b/server/modules/filter/masking/maskingfilter.cc index 55eee86df..6b005e6b8 100644 --- a/server/modules/filter/masking/maskingfilter.cc +++ b/server/modules/filter/masking/maskingfilter.cc @@ -14,7 +14,7 @@ #define MXS_MODULE_NAME "masking" #include "maskingfilter.hh" -#include +#include #include #include #include diff --git a/server/modules/filter/masking/maskingrules.cc b/server/modules/filter/masking/maskingrules.cc index d584624b5..c36dc2f85 100644 --- a/server/modules/filter/masking/maskingrules.cc +++ b/server/modules/filter/masking/maskingrules.cc @@ -22,7 +22,7 @@ #include #include #include -#include +#include using std::auto_ptr; using std::string; diff --git a/server/modules/filter/qlafilter/qlafilter.cc b/server/modules/filter/qlafilter/qlafilter.cc index b0069762c..a8fdaea7d 100644 --- a/server/modules/filter/qlafilter/qlafilter.cc +++ b/server/modules/filter/qlafilter/qlafilter.cc @@ -45,7 +45,7 @@ #include #include #include -#include +#include using std::string; @@ -100,7 +100,6 @@ void print_string_replace_newlines(const char* sql_string, size_t sql_str_len, const char* rep_newline, std::stringstream* output); bool check_replace_file(const string& filename, FILE** ppFile); - } QlaInstance::QlaInstance(const string& name, MXS_CONFIG_PARAMETER* params) diff --git a/server/modules/filter/throttlefilter/throttlefilter.cc b/server/modules/filter/throttlefilter/throttlefilter.cc index fbab596ea..05059a4c2 100644 --- a/server/modules/filter/throttlefilter/throttlefilter.cc +++ b/server/modules/filter/throttlefilter/throttlefilter.cc @@ -8,7 +8,7 @@ #include #include -#include +#include #include #include "throttlefilter.hh" diff --git a/server/modules/monitor/clustrixmon/clustrixmonitor.cc b/server/modules/monitor/clustrixmon/clustrixmonitor.cc index 5584feffe..37558780a 100644 --- a/server/modules/monitor/clustrixmon/clustrixmonitor.cc +++ b/server/modules/monitor/clustrixmon/clustrixmonitor.cc @@ -14,7 +14,7 @@ #include "clustrixmonitor.hh" #include #include -#include +#include #include "../../../core/internal/config_runtime.hh" #include "../../../core/internal/service.hh" diff --git a/server/modules/monitor/mariadbmon/mariadbmon_common.hh b/server/modules/monitor/mariadbmon/mariadbmon_common.hh index cf815649f..34e0bbaf9 100644 --- a/server/modules/monitor/mariadbmon/mariadbmon_common.hh +++ b/server/modules/monitor/mariadbmon/mariadbmon_common.hh @@ -21,7 +21,7 @@ #include #include -#include +#include /** Utility macros for printing both MXS_ERROR and json error */ #define PRINT_MXS_JSON_ERROR(err_out, format, ...) \