From 7ed261b27b84ebcd42d7635a1c27e9c72c180e01 Mon Sep 17 00:00:00 2001 From: Aron Podrigal Date: Tue, 14 Jan 2025 16:03:49 -0600 Subject: [PATCH 1/3] [mod_pgsql] Add support for PGRES_TUPLES_CHUNK in PostgreSQL 17+ Extend the database module to handle the PGRES_TUPLES_CHUNK case introduced in PostgreSQL 17. This ensures compatibility with the latest PostgreSQL version and prevents potential issues when processing query results. --- src/mod/databases/mod_pgsql/mod_pgsql.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/mod/databases/mod_pgsql/mod_pgsql.c b/src/mod/databases/mod_pgsql/mod_pgsql.c index 09d6b32e5c..89fdd710f6 100644 --- a/src/mod/databases/mod_pgsql/mod_pgsql.c +++ b/src/mod/databases/mod_pgsql/mod_pgsql.c @@ -605,6 +605,10 @@ switch_status_t database_handle_exec_string(switch_database_interface_handle_t * #if PG_VERSION_NUM >= 90002 case PGRES_SINGLE_TUPLE: /* Added in PostgreSQL 9.2 */ +#endif +#if PG_VERSION_NUM >= 170000 + case PGRES_TUPLES_CHUNK: + /* Added in PostgreSQL 17 */ #endif case PGRES_COMMAND_OK: case PGRES_TUPLES_OK: @@ -766,6 +770,10 @@ switch_status_t pgsql_next_result_timed(switch_pgsql_handle_t *handle, switch_pg #if PG_VERSION_NUM >= 90002 case PGRES_SINGLE_TUPLE: /* Added in PostgreSQL 9.2 */ +#endif +#if PG_VERSION_NUM >= 170000 + case PGRES_TUPLES_CHUNK: + /* Added in PostgreSQL 17 */ #endif case PGRES_TUPLES_OK: { From 54fb4499637eb341ed7fd4d44f8f59ca000087c1 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Mon, 23 Dec 2024 20:13:56 +0300 Subject: [PATCH 2/3] [mod_event_zmq] Remove from tree --- build/modules.conf.in | 1 - build/modules.conf.most | 1 - .../vanilla/autoload_configs/modules.conf.xml | 1 - configure.ac | 1 - debian/bootstrap.sh | 1 - debian/control-modules | 4 - freeswitch.spec | 12 -- .../event_handlers/mod_event_zmq/Makefile.am | 34 --- .../mod_event_zmq/mod_event_zmq.cpp | 193 ------------------ .../mod_event_zmq/mod_event_zmq.h | 20 -- 10 files changed, 268 deletions(-) delete mode 100644 src/mod/event_handlers/mod_event_zmq/Makefile.am delete mode 100644 src/mod/event_handlers/mod_event_zmq/mod_event_zmq.cpp delete mode 100644 src/mod/event_handlers/mod_event_zmq/mod_event_zmq.h diff --git a/build/modules.conf.in b/build/modules.conf.in index 9c63ccdb23..d30c5f0177 100755 --- a/build/modules.conf.in +++ b/build/modules.conf.in @@ -91,7 +91,6 @@ event_handlers/mod_event_socket #event_handlers/mod_odbc_cdr #event_handlers/mod_smpp #event_handlers/mod_snmp -#event_handlers/mod_event_zmq #formats/mod_imagick formats/mod_local_stream formats/mod_native_file diff --git a/build/modules.conf.most b/build/modules.conf.most index 8f8a8e2f14..40a61c8daa 100755 --- a/build/modules.conf.most +++ b/build/modules.conf.most @@ -88,7 +88,6 @@ event_handlers/mod_format_cdr event_handlers/mod_json_cdr event_handlers/mod_odbc_cdr event_handlers/mod_snmp -#event_handlers/mod_event_zmq formats/mod_imagick formats/mod_local_stream formats/mod_native_file diff --git a/conf/vanilla/autoload_configs/modules.conf.xml b/conf/vanilla/autoload_configs/modules.conf.xml index 19581f57db..6363e233cb 100755 --- a/conf/vanilla/autoload_configs/modules.conf.xml +++ b/conf/vanilla/autoload_configs/modules.conf.xml @@ -24,7 +24,6 @@ - diff --git a/configure.ac b/configure.ac index 49232f5c60..7474353205 100755 --- a/configure.ac +++ b/configure.ac @@ -2188,7 +2188,6 @@ AC_CONFIG_FILES([Makefile src/mod/event_handlers/mod_odbc_cdr/Makefile src/mod/event_handlers/mod_smpp/Makefile src/mod/event_handlers/mod_snmp/Makefile - src/mod/event_handlers/mod_event_zmq/Makefile src/mod/formats/mod_imagick/Makefile src/mod/formats/mod_local_stream/Makefile src/mod/formats/mod_native_file/Makefile diff --git a/debian/bootstrap.sh b/debian/bootstrap.sh index fcb007735f..ce5adea315 100755 --- a/debian/bootstrap.sh +++ b/debian/bootstrap.sh @@ -46,7 +46,6 @@ avoid_mods=( endpoints/mod_opal endpoints/mod_reference event_handlers/mod_smpp - event_handlers/mod_event_zmq formats/mod_webm sdk/autotools xml_int/mod_xml_ldap diff --git a/debian/control-modules b/debian/control-modules index bf0d700871..101fab9e08 100755 --- a/debian/control-modules +++ b/debian/control-modules @@ -440,10 +440,6 @@ Module: event_handlers/mod_event_test Description: mod_event_test Adds mod_event_test. -Module: event_handlers/mod_event_zmq -Description: mod_event_zmq - Adds mod_event_zmq. - Module: event_handlers/mod_format_cdr Description: mod_format_cdr Adds mod_format_cdr. diff --git a/freeswitch.spec b/freeswitch.spec index 495e8f1564..1d98356588 100755 --- a/freeswitch.spec +++ b/freeswitch.spec @@ -830,14 +830,6 @@ Requires: %{name} = %{version}-%{release} %description event-multicast Multicast Event System for FreeSWITCH. -#%package event-zmq -#Summary: ZeroMQ Event System for the FreeSWITCH open source telephony platform -#Group: System/Libraries -#Requires: %{name} = %{version}-%{release} -# -#%description event-zmq -#ZeroMQ Event System for FreeSWITCH. - %package event-json-cdr Summary: JSON CDR Logger for the FreeSWITCH open source telephony platform Group: System/Libraries @@ -1295,7 +1287,6 @@ EVENT_HANDLERS_MODULES="event_handlers/mod_cdr_csv event_handlers/mod_cdr_pg_csv event_handlers/mod_event_socket event_handlers/mod_json_cdr \ event_handlers/mod_snmp" -#### BUILD ISSUES NET RESOLVED FOR RELEASE event_handlers/mod_event_zmq ###################################################################################################################### # # File and Audio Format Handlers @@ -2026,9 +2017,6 @@ fi %files event-multicast %{MODINSTDIR}/mod_event_multicast.so* -#%files event-zmq -#%{MODINSTDIR}/mod_xmq.so* - %files event-json-cdr %{MODINSTDIR}/mod_json_cdr.so* diff --git a/src/mod/event_handlers/mod_event_zmq/Makefile.am b/src/mod/event_handlers/mod_event_zmq/Makefile.am deleted file mode 100644 index 1b171a69c0..0000000000 --- a/src/mod/event_handlers/mod_event_zmq/Makefile.am +++ /dev/null @@ -1,34 +0,0 @@ -include $(top_srcdir)/build/modmake.rulesam -MODNAME=mod_event_zmq -ZMQ=zeromq-2.1.9 - -ZMQ_BASEURL=http://download.zeromq.org -ZMQ_BASEURL_ALT=http://download.zeromq.org/historic - -ZMQ_DIR=$(switch_srcdir)/libs/$(ZMQ) -ZMQ_BUILDDIR=$(switch_builddir)/libs/$(ZMQ) -ZMQ_LA=$(ZMQ_BUILDDIR)/src/libzmq.la - -mod_LTLIBRARIES = mod_event_zmq.la -mod_event_zmq_la_SOURCES = mod_event_zmq.cpp -mod_event_zmq_la_CFLAGS = $(AM_CFLAGS) -mod_event_zmq_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(ZMQ_DIR)/include -I$(switch_srcdir)/libs/libteletone/src/ -mod_event_zmq_la_LIBADD = $(switch_builddir)/libfreeswitch.la $(ZMQ_LA) -mod_event_zmq_la_LDFLAGS = -avoid-version -module -no-undefined -shared - -BUILT_SOURCES=$(ZMQ_LA) - -$(ZMQ_DIR): - $(GETLIB) $(ZMQ_BASEURL) $(ZMQ).tar.gz || $(GETLIB) $(ZMQ_BASEURL_ALT) $(ZMQ).tar.gz - sed -e 's:AM_CONFIG_HEADER:AC_CONFIG_HEADERS:' $(ZMQ_DIR)/configure.in > $(ZMQ_DIR)/configure.in.tmp && \ - mv $(ZMQ_DIR)/configure.in.tmp $(ZMQ_DIR)/configure.in - cd $(ZMQ_DIR) && ./autogen.sh - -$(ZMQ_BUILDDIR)/Makefile: $(ZMQ_DIR) - mkdir -p $(ZMQ_BUILDDIR) - cd $(ZMQ_BUILDDIR) && $(DEFAULT_VARS) $(ZMQ_DIR)/configure $(DEFAULT_ARGS) --srcdir=$(ZMQ_DIR) - $(TOUCH_TARGET) - -$(ZMQ_LA): $(ZMQ_BUILDDIR)/Makefile - cd $(ZMQ_BUILDDIR) && $(MAKE) - $(TOUCH_TARGET) diff --git a/src/mod/event_handlers/mod_event_zmq/mod_event_zmq.cpp b/src/mod/event_handlers/mod_event_zmq/mod_event_zmq.cpp deleted file mode 100644 index b7f517bac2..0000000000 --- a/src/mod/event_handlers/mod_event_zmq/mod_event_zmq.cpp +++ /dev/null @@ -1,193 +0,0 @@ -#include -#include -#include -#include -#include - -#include "mod_event_zmq.h" - -namespace mod_event_zmq { - -// Handles publishing events out to clients -class ZmqEventPublisher { -public: - ZmqEventPublisher(zmq::context_t &context) : - _publisher(context, ZMQ_PUB) - { - _publisher.bind("tcp://*:5556"); - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Listening for clients\n"); - } - - void PublishEvent(const switch_event_t *event) { - // Serialize the event into a JSON string - char* pjson; - switch_event_serialize_json(const_cast(event), &pjson); - - // Use the JSON string as the message body - zmq::message_t msg(pjson, strlen(pjson), free_message_data, NULL); - - // Send the message - _publisher.send(msg); - } - -private: - static void free_message_data(void *data, void *hint) { - free (data); - } - - zmq::socket_t _publisher; -}; - -class char_msg : public zmq::message_t { -public: - char_msg() : zmq::message_t(sizeof(char)) { } - char_msg(char data) : zmq::message_t(sizeof(char)) { - *char_data() = data; - } - - char* char_data() { - return static_cast(this->data()); - } -}; - -// Handles global inititalization and teardown of the module -class ZmqModule { -public: - ZmqModule(switch_loadable_module_interface_t **module_interface, switch_memory_pool_t *pool) : - _context(1), _term_rep(_context, ZMQ_REP), _term_req(_context, ZMQ_REQ), _publisher(_context) { - - // Set up the term messaging connection - _term_rep.bind(TERM_URI); - _term_req.connect(TERM_URI); - - // Subscribe to all switch events of any subclass - // Store a pointer to ourself in the user data - if (switch_event_bind_removable(modname, SWITCH_EVENT_ALL, SWITCH_EVENT_SUBCLASS_ANY, event_handler, static_cast(&_publisher), &_node) - != SWITCH_STATUS_SUCCESS) { - throw std::runtime_error("Couldn't bind to switch events."); - } - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Subscribed to events\n"); - - // Create our module interface registration - *module_interface = switch_loadable_module_create_module_interface(pool, modname); - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Module loaded\n"); - } - - void Listen() { - // All we do is sit here and block the run loop thread so it doesn't return - // it seems that if you want to keep your module running you can't return from the run loop - - char_msg msg; - while(true) { - // Listen for term message - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Entered run loop, waiting for term message\n"); - _term_rep.recv(&msg); - if(*msg.char_data() == MODULE_TERM_REQ_MESSAGE) { - // Ack term message - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Got term message, sending ack and leaving run loop\n"); - - *msg.char_data() = MODULE_TERM_ACK_MESSAGE; - _term_rep.send(msg); - - break; - } - } - } - - void Shutdown() { - // Send term message - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Shutdown requested, sending term message to runloop\n"); - char_msg msg(MODULE_TERM_REQ_MESSAGE); - _term_req.send(msg); - - while(true) { - // Wait for the term ack message - _term_req.recv(&msg); - if(*msg.char_data() == MODULE_TERM_ACK_MESSAGE) { - // Continue shutdown - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Got term ack message, continuing shutdown\n"); - break; - } - } - } - - ~ZmqModule() { - // Unsubscribe from the switch events - switch_event_unbind(&_node); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Module shut down\n"); - } - -private: - // Dispatches events to the publisher - static void event_handler(switch_event_t *event) { - try { - ZmqEventPublisher *publisher = static_cast(event->bind_user_data); - publisher->PublishEvent(event); - } catch(std::exception ex) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Error publishing event via 0MQ: %s\n", ex.what()); - } catch(...) { // Exceptions must not propogate to C caller - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unknown error publishing event via 0MQ\n"); - } - } - - switch_event_node_t *_node; - - zmq::context_t _context; - zmq::socket_t _term_rep; - zmq::socket_t _term_req; - - ZmqEventPublisher _publisher; -}; - -//*****************************// -// GLOBALS // -//*****************************// -std::auto_ptr module; - - -//*****************************// -// Module interface funtions // -//*****************************// -SWITCH_MODULE_LOAD_FUNCTION(load) { - try { - module.reset(new ZmqModule(module_interface, pool)); - return SWITCH_STATUS_SUCCESS; - } catch(...) { // Exceptions must not propogate to C caller - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error loading 0MQ module\n"); - return SWITCH_STATUS_GENERR; - } - -} - -SWITCH_MODULE_RUNTIME_FUNCTION(runtime) { - try { - // Begin listening for clients - module->Listen(); - } catch(std::exception &ex) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error listening for clients: %s\n", ex.what()); - } catch(...) { // Exceptions must not propogate to C caller - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unknown error listening for clients\n"); - } - - // Tell the switch to stop calling this runtime loop - return SWITCH_STATUS_TERM; -} - -SWITCH_MODULE_SHUTDOWN_FUNCTION(shutdown) { - try { - // Tell the module to shutdown - module->Shutdown(); - - // Free the module object - module.reset(); - } catch(std::exception &ex) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error shutting down module: %s\n", ex.what()); - } catch(...) { // Exceptions must not propogate to C caller - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unknown error shutting down module\n"); - } - return SWITCH_STATUS_SUCCESS; -} - -} diff --git a/src/mod/event_handlers/mod_event_zmq/mod_event_zmq.h b/src/mod/event_handlers/mod_event_zmq/mod_event_zmq.h deleted file mode 100644 index a60c720d74..0000000000 --- a/src/mod/event_handlers/mod_event_zmq/mod_event_zmq.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef MOD_EVENT_ZMQ_H -#define MOD_EVENT_ZMQ_H - -namespace mod_event_zmq { -static const char MODULE_TERM_REQ_MESSAGE = 1; -static const char MODULE_TERM_ACK_MESSAGE = 2; - -static const char *TERM_URI = "inproc://mod_event_zmq_term"; - -SWITCH_MODULE_LOAD_FUNCTION(load); -SWITCH_MODULE_SHUTDOWN_FUNCTION(shutdown); -SWITCH_MODULE_RUNTIME_FUNCTION(runtime); - -extern "C" { -SWITCH_MODULE_DEFINITION(mod_event_zmq, load, shutdown, runtime); -}; - -} - -#endif // MOD_EVENT_ZMQ_H From e359409cae6feb6a8748f14ecd714a342653f0fc Mon Sep 17 00:00:00 2001 From: Aron Podrigal Date: Tue, 14 Jan 2025 16:47:35 -0600 Subject: [PATCH 3/3] [mod_curl] Increase argument limit and enforce max args constraint Introduced a configurable limit on the number of arguments for mod_curl functions with a default of 30. Adjusted the code to handle scenarios exceeding this limit by logging an error and returning failure. This improves flexibility and prevents potential overflow issues. --- src/mod/applications/mod_curl/mod_curl.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/mod/applications/mod_curl/mod_curl.c b/src/mod/applications/mod_curl/mod_curl.c index c780e6947e..82b38d42a9 100644 --- a/src/mod/applications/mod_curl/mod_curl.c +++ b/src/mod/applications/mod_curl/mod_curl.c @@ -57,6 +57,10 @@ static char *SYNTAX = "curl url [headers|json|content-type |connect-t #define HTTP_MAX_APPEND_HEADERS 10 #define HTTP_DEFAULT_MAX_BYTES 64000 +#ifndef MOD_CURL_MAX_ARGS +#define MOD_CURL_MAX_ARGS 30 +#endif + static struct { switch_memory_pool_t *pool; switch_event_node_t *node; @@ -866,7 +870,7 @@ SWITCH_STANDARD_APP(curl_app_function) { switch_status_t status = SWITCH_STATUS_SUCCESS; - char *argv[10] = { 0 }; + char *argv[MOD_CURL_MAX_ARGS + 1] = { 0 }; int argc; char *mydata = NULL; @@ -894,6 +898,9 @@ SWITCH_STANDARD_APP(curl_app_function) if ((argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) { if (argc == 0) { switch_goto_status(SWITCH_STATUS_SUCCESS, usage); + } else if (argc >= MOD_CURL_MAX_ARGS) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Max args exceeded: %d\n", MOD_CURL_MAX_ARGS); + switch_goto_status(SWITCH_STATUS_FALSE, done); } url = switch_core_strdup(pool, argv[0]); @@ -982,7 +989,7 @@ SWITCH_STANDARD_APP(curl_app_function) SWITCH_STANDARD_API(curl_function) { switch_status_t status; - char *argv[10] = { 0 }; + char *argv[MOD_CURL_MAX_ARGS + 1] = { 0 }; int argc; char *mydata = NULL; char *url = NULL; @@ -1014,6 +1021,9 @@ SWITCH_STANDARD_API(curl_function) if ((argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) { if (argc < 1) { switch_goto_status(SWITCH_STATUS_SUCCESS, usage); + } else if (argc >= MOD_CURL_MAX_ARGS) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Max args exceeded: %d\n", MOD_CURL_MAX_ARGS); + switch_goto_status(SWITCH_STATUS_FALSE, done); } url = switch_core_strdup(pool, argv[0]);