]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
[mod_xml_curl] Allow XML_CURL_MAX_BYTES to be configured at runtime per-binding 509/head
authorAndrew Topp <andrewt@telekinetica.net>
Sun, 15 Mar 2020 04:05:53 +0000 (14:05 +1000)
committerAndrew Topp <andrewt@telekinetica.net>
Sun, 15 Mar 2020 04:05:53 +0000 (14:05 +1000)
* Added "response-max-bytes" config param for mod_xml_curl
* XML_CURL_MAX_BYTES still used as default if param omitted
* Added example configuration to module example config.

src/mod/xml_int/mod_xml_curl/conf/autoload_configs/xml_curl.conf.xml
src/mod/xml_int/mod_xml_curl/mod_xml_curl.c

index 30951d83c83f28cb870e1ecafe99bf88b97e6ce8..8efee1f9f8e024c284e7d9ee4c0ffc009715ace1 100644 (file)
 
       <!-- one or more of these imply you want to pick the exact variables that are transmitted -->
       <!--<param name="enable-post-var" value="Unique-ID"/>-->
+
+      <!-- optional: maximum response size for this binding in bytes. 
+           Defaults to XML_CURL_MAX_BYTES (1MB) if omitted -->
+      <!--<param name="response-max-bytes" value="10485760"/>-->
     </binding>
   </bindings>
 </configuration>
index dab29a550f88a7b9b2dbc65fcbd900af34ca81fb..5a2e201a72c961130d82266cdbef252577f62653 100644 (file)
@@ -59,6 +59,7 @@ struct xml_binding {
        int use_dynamic_url;
        long auth_scheme;
        int timeout;
+       switch_size_t curl_max_bytes;
 };
 
 static int keep_files_around = 0;
@@ -218,7 +219,7 @@ static switch_xml_t xml_url_fetch(const char *section, const char *tag_name, con
        memset(&config_data, 0, sizeof(config_data));
 
        config_data.name = filename;
-       config_data.max_bytes = XML_CURL_MAX_BYTES;
+       config_data.max_bytes = binding->curl_max_bytes;
 
        if ((config_data.fd = open(filename, O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR)) > -1) {
                if (!zstr(binding->cred)) {
@@ -364,6 +365,7 @@ static switch_status_t do_config(void)
                char *method = NULL;
                int disable100continue = 1;
                int use_dynamic_url = 0, timeout = 0;
+               switch_size_t curl_max_bytes = XML_CURL_MAX_BYTES;
                uint32_t enable_cacert_check = 0;
                char *ssl_cert_file = NULL;
                char *ssl_key_file = NULL;
@@ -452,6 +454,13 @@ static switch_status_t do_config(void)
                                }
                        } else if (!strcasecmp(var, "bind-local")) {
                                bind_local = val;
+                       } else if (!strcasecmp(var, "response-max-bytes")) {
+                               int tmp = atoi(val);
+                               if (tmp >= 0) {
+                                       curl_max_bytes = tmp;
+                               } else {
+                                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't set a negative maximum response bytes!\n");
+                               }
                        }
                }
 
@@ -540,6 +549,8 @@ static switch_status_t do_config(void)
 
                }
 
+               binding->curl_max_bytes = curl_max_bytes;
+
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Binding [%s] XML Fetch Function [%s] [%s]\n",
                                                  zstr(bname) ? "N/A" : bname, binding->url, binding->bindings ? binding->bindings : "all");
                switch_xml_bind_search_function(xml_url_fetch, switch_xml_parse_section_string(binding->bindings), binding);