]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
Merge pull request #2178 from signalwire/rtmp
authorAndrey Volk <andywolk@gmail.com>
Tue, 25 Jul 2023 00:04:26 +0000 (03:04 +0300)
committerGitHub <noreply@github.com>
Tue, 25 Jul 2023 00:04:26 +0000 (03:04 +0300)
[mod_rtmp] Add OpenSSL 3 support.

13 files changed:
src/include/switch_curl.h
src/mod/applications/mod_cidlookup/mod_cidlookup.c
src/mod/applications/mod_curl/mod_curl.c
src/mod/applications/mod_httapi/mod_httapi.c
src/mod/applications/mod_http_cache/azure.c
src/mod/applications/mod_http_cache/mod_http_cache.c
src/mod/codecs/mod_ilbc/mod_ilbc.c
src/mod/databases/mod_mariadb/mod_mariadb.c
src/mod/event_handlers/mod_kazoo/kazoo_commands.c
src/mod/formats/mod_shout/mod_shout.c
src/switch_core_media.c
src/switch_curl.c
src/switch_utils.c

index 587252786576c28b5ac11fc905bdea8fa20884c6..bad116daf2835f2b3f4597eb67146f933074dd24 100644 (file)
@@ -40,6 +40,9 @@ typedef int switch_CURLINFO;
 typedef int switch_CURLcode;
 typedef int switch_CURLoption;
 
+#define HAVE_SWITCH_CURL_MIME
+typedef void switch_curl_mime;
+
 SWITCH_DECLARE(switch_CURL *) switch_curl_easy_init(void);
 SWITCH_DECLARE(switch_CURLcode) switch_curl_easy_perform(switch_CURL *handle);
 SWITCH_DECLARE(switch_CURLcode) switch_curl_easy_getinfo(switch_CURL *curl, switch_CURLINFO info, ... );
@@ -50,7 +53,9 @@ SWITCH_DECLARE(switch_CURLcode) switch_curl_easy_setopt(CURL *handle, switch_CUR
 SWITCH_DECLARE(const char *) switch_curl_easy_strerror(switch_CURLcode errornum );
 SWITCH_DECLARE(void) switch_curl_init(void);
 SWITCH_DECLARE(void) switch_curl_destroy(void);
-SWITCH_DECLARE(switch_status_t) switch_curl_process_form_post_params(switch_event_t *event, switch_CURL *curl_handle, struct curl_httppost **formpostp);
+SWITCH_DECLARE(switch_status_t) switch_curl_process_mime(switch_event_t *event, switch_CURL *curl_handle, switch_curl_mime **mimep);
+SWITCH_DECLARE(void) switch_curl_mime_free(switch_curl_mime **mimep);
+SWITCH_DECLARE(switch_CURLcode) switch_curl_easy_setopt_mime(switch_CURL *curl_handle, switch_curl_mime *mime);
 #define switch_curl_easy_setopt curl_easy_setopt
 
 SWITCH_END_EXTERN_C
index 55d7aa0d902175602a741b2b98cc9dbe8d9b93ea..55312221975781cdfe859715eccd9eba5e8e1400 100644 (file)
@@ -347,7 +347,7 @@ static size_t file_callback(void *ptr, size_t size, size_t nmemb, void *data)
        return realsize;
 }
 
-static long do_lookup_url(switch_memory_pool_t *pool, switch_event_t *event, char **response, const char *query, struct curl_httppost *post,
+static long do_lookup_url(switch_memory_pool_t *pool, switch_event_t *event, char **response, const char *query, switch_curl_mime *post,
                                                  switch_curl_slist_t *headers, int timeout)
 {
        switch_time_t start_time = switch_micro_time_now();
@@ -373,7 +373,7 @@ static long do_lookup_url(switch_memory_pool_t *pool, switch_event_t *event, cha
                switch_curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 0);
        }
        if (post) {
-               switch_curl_easy_setopt(curl_handle, CURLOPT_HTTPPOST, post);
+               switch_curl_easy_setopt_mime(curl_handle, post);
        } else {
                switch_curl_easy_setopt(curl_handle, CURLOPT_HTTPGET, 1);
        }
index 02079d6767c6e1627fd6181f0c5749b900eff66d..c780e6947edeffb48c90c929fe87fac3ba48fb0f 100644 (file)
@@ -104,8 +104,13 @@ struct http_sendfile_data_obj {
        char *extrapost_elements;
        switch_CURL *curl_handle;
        char *cacert;
+#if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800)
+       curl_mime *mime;
+       curl_mimepart *part;
+#else
        struct curl_httppost *formpost;
        struct curl_httppost *lastptr;
+#endif
        uint8_t flags; /* This is for where to send output of the curl_sendfile commands */
        switch_stream_handle_t *stream;
        char *sendfile_response;
@@ -456,8 +461,19 @@ static void http_sendfile_initialize_curl(http_sendfile_data_t *http_data)
        curl_easy_setopt(http_data->curl_handle, CURLOPT_WRITEFUNCTION, http_sendfile_response_callback);
        curl_easy_setopt(http_data->curl_handle, CURLOPT_WRITEDATA, (void *) http_data);
 
+       /* Initial http_data->mime */
+#if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800)
+       http_data->mime = curl_mime_init(http_data->curl_handle);
+#endif
+
        /* Add the file to upload as a POST form field */
+#if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800)
+       http_data->part = curl_mime_addpart(http_data->mime);
+       curl_mime_name(http_data->part, http_data->filename_element_name);
+       curl_mime_filedata(http_data->part, http_data->filename_element);
+#else
        curl_formadd(&http_data->formpost, &http_data->lastptr, CURLFORM_COPYNAME, http_data->filename_element_name, CURLFORM_FILE, http_data->filename_element, CURLFORM_END);
+#endif
 
        if(!zstr(http_data->extrapost_elements))
        {
@@ -476,16 +492,32 @@ static void http_sendfile_initialize_curl(http_sendfile_data_t *http_data)
                        if(argc2 == 2) {
                                switch_url_decode(argv2[0]);
                                switch_url_decode(argv2[1]);
+#if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800)
+                               http_data->part = curl_mime_addpart(http_data->mime);
+                               curl_mime_name(http_data->part, argv2[0]);
+                               curl_mime_data(http_data->part, argv2[1], CURL_ZERO_TERMINATED);
+#else
                                curl_formadd(&http_data->formpost, &http_data->lastptr, CURLFORM_COPYNAME, argv2[0], CURLFORM_COPYCONTENTS, argv2[1], CURLFORM_END);
+#endif
                        }
                }
        }
 
        /* Fill in the submit field too, even if this isn't really needed */
+#if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800)
+       http_data->part = curl_mime_addpart(http_data->mime);
+       curl_mime_name(http_data->part, "submit");
+       curl_mime_data(http_data->part, "or_die", CURL_ZERO_TERMINATED);
+#else
        curl_formadd(&http_data->formpost, &http_data->lastptr, CURLFORM_COPYNAME, "submit", CURLFORM_COPYCONTENTS, "or_die", CURLFORM_END);
+#endif
 
        /* what URL that receives this POST */
+#if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800)
+       curl_easy_setopt(http_data->curl_handle, CURLOPT_MIMEPOST, http_data->mime);
+#else
        curl_easy_setopt(http_data->curl_handle, CURLOPT_HTTPPOST, http_data->formpost);
+#endif
 
        // This part actually fires off the curl, captures the HTTP response code, and then frees up the handle.
        curl_easy_perform(http_data->curl_handle);
@@ -494,7 +526,11 @@ static void http_sendfile_initialize_curl(http_sendfile_data_t *http_data)
        curl_easy_cleanup(http_data->curl_handle);
 
        // Clean up the form data from POST
+#if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800)
+       curl_mime_free(http_data->mime);
+#else
        curl_formfree(http_data->formpost);
+#endif
 }
 
 static switch_status_t http_sendfile_test_file_open(http_sendfile_data_t *http_data, switch_event_t *event)
index 4b32d87c6d670b0f87374c48ec48685dccf44617..1254a6f93cfd669fc3e00111ebeb08f5eacc992e 100644 (file)
@@ -1419,7 +1419,7 @@ static switch_status_t httapi_sync(client_t *client)
        switch_status_t status = SWITCH_STATUS_FALSE;
        int get_style_method = 0;
        char *method = NULL;
-       struct curl_httppost *formpost=NULL;
+       switch_curl_mime *formpost = NULL;
        switch_event_t *save_params = NULL;
        const char *put_file;
        FILE *fd = NULL;
@@ -1476,7 +1476,7 @@ static switch_status_t httapi_sync(client_t *client)
        }
 
        if (!put_file) {
-               switch_curl_process_form_post_params(client->params, curl_handle, &formpost);
+               switch_curl_process_mime(client->params, curl_handle, &formpost);
        }
 
        if (formpost) {
@@ -1588,7 +1588,7 @@ static switch_status_t httapi_sync(client_t *client)
                curl_easy_setopt(curl_handle, CURLOPT_READFUNCTION, put_file_read);
 
        } else if (formpost) {
-               curl_easy_setopt(curl_handle, CURLOPT_HTTPPOST, formpost);
+               switch_curl_easy_setopt_mime(curl_handle, formpost);
        } else {
                switch_curl_easy_setopt(curl_handle, CURLOPT_POST, !get_style_method);
        }
@@ -1670,9 +1670,7 @@ static switch_status_t httapi_sync(client_t *client)
        switch_curl_easy_cleanup(curl_handle);
        switch_curl_slist_free_all(headers);
 
-       if (formpost) {
-               curl_formfree(formpost);
-       }
+       switch_curl_mime_free(&formpost);
 
        if (client->err) {
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error encountered! [%s]\ndata: [%s]\n", client->profile->url, data);
index f1e4cf8925401b68cd6b56a793dc96c8a99268c0..a16d2e9f94480b6cc7971aa865948c2efa7b1c45 100644 (file)
@@ -279,7 +279,11 @@ switch_status_t azure_blob_finalise_put(http_profile_t *profile, const char *url
                goto done;
        }
 
+#if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x070c01)
+       switch_curl_easy_setopt(curl_handle, CURLOPT_UPLOAD, 1);
+#else
        switch_curl_easy_setopt(curl_handle, CURLOPT_PUT, 1);
+#endif
        switch_curl_easy_setopt(curl_handle, CURLOPT_NOSIGNAL, 1);
        switch_curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, headers);
        switch_curl_easy_setopt(curl_handle, CURLOPT_URL, full_url);
index 9d19099e564d74de151845c0cb9812ff27eda273..365ba27425ee9f9d71b612ef172fb300de26e544 100644 (file)
@@ -393,7 +393,9 @@ static switch_status_t http_put(url_cache_t *cache, http_profile_t *profile, swi
                        goto done;
                }
                switch_curl_easy_setopt(curl_handle, CURLOPT_UPLOAD, 1);
+#if !defined(LIBCURL_VERSION_NUM) || (LIBCURL_VERSION_NUM < 0x070c01)
                switch_curl_easy_setopt(curl_handle, CURLOPT_PUT, 1);
+#endif
                switch_curl_easy_setopt(curl_handle, CURLOPT_NOSIGNAL, 1);
                switch_curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, headers);
                switch_curl_easy_setopt(curl_handle, CURLOPT_URL, full_url);
index 14d67d372e51e2fe2b1ae57ea7b84f713dee195c..2588cdf46b7f1089e5dd3a8c50cfc47f4b4d332f 100644 (file)
@@ -48,7 +48,7 @@ static switch_status_t switch_ilbc_fmtp_parse(const char *fmtp, switch_codec_fmt
 
                memset(codec_fmtp, '\0', sizeof(struct switch_codec_fmtp));
 
-               if (fmtp && (mode = strstr(fmtp, "mode=")) && (mode + 5)) {
+               if (fmtp && (mode = strstr(fmtp, "mode=")) && *(mode + 5)) {
                        codec_ms = atoi(mode + 5);
                }
                if (!codec_ms) {
index 7926ec0c3f52daa86a1565177396fa75408b66b2..5f32e8e90d61c7214993e0963feea28d9235ad1a 100644 (file)
@@ -411,7 +411,7 @@ switch_status_t mariadb_finish_results_real(const char* file, const char* func,
                                if ((status = mysql_next_result(&handle->con))) {
                                        if (status > 0) {
                                                err_str = mariadb_handle_get_error(handle);
-                                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "An error occurred trying to get next for query (%s): %s\n", handle->sql, err_str);
+                                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "An error occurred trying to get next for query (%s): %s\n", handle->sql, switch_str_nil(err_str));
                                                switch_safe_free(err_str);
 
                                                break;
index 6d956376a8365541ef2fb723d476ac6f9b88dc88..16f00ad1a030074cb46025c9fe645867dd365bd6 100644 (file)
@@ -366,7 +366,9 @@ SWITCH_STANDARD_API(kz_http_put)
                goto done;
        }
        switch_curl_easy_setopt(curl_handle, CURLOPT_UPLOAD, 1);
+#if !defined(LIBCURL_VERSION_NUM) || (LIBCURL_VERSION_NUM < 0x070c01)
        switch_curl_easy_setopt(curl_handle, CURLOPT_PUT, 1);
+#endif
        switch_curl_easy_setopt(curl_handle, CURLOPT_NOSIGNAL, 1);
        switch_curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, headers);
        switch_curl_easy_setopt(curl_handle, CURLOPT_URL, url);
index 14cba068d329b962ee6e5692dffff7a7fecbb3fe..7012cb808d8c0c21f9076f292e59092c71939707 100644 (file)
@@ -463,7 +463,11 @@ static size_t stream_callback(void *ptr, size_t size, size_t nmemb, void *data)
        return 0;
 }
 
+#if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x072000)
+static int progress_callback(void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)
+#else
 static int progress_callback(void *clientp,   double dltotal,   double dlnow,   double ultotal,   double ulnow)
+#endif
 {
        shout_context_t *context = (shout_context_t *) clientp;
        return context->err;
@@ -496,8 +500,13 @@ static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void
        switch_mutex_unlock(context->audio_mutex);
        curl_handle = switch_curl_easy_init();
        switch_curl_easy_setopt(curl_handle, CURLOPT_URL, context->stream_url);
+#if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x072000)
+       curl_easy_setopt(curl_handle, CURLOPT_XFERINFOFUNCTION, progress_callback);
+       curl_easy_setopt(curl_handle, CURLOPT_XFERINFODATA, (void *)context);
+#else
        curl_easy_setopt(curl_handle, CURLOPT_PROGRESSFUNCTION, progress_callback);
        curl_easy_setopt(curl_handle, CURLOPT_PROGRESSDATA, (void *)context);
+#endif
        switch_curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1);
        switch_curl_easy_setopt(curl_handle, CURLOPT_MAXREDIRS, 10);
        switch_curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, stream_callback);
index e75387581d0ef4113a181b62c67bb0f59cb98d6c..0d8670622c36fea4fd19feace4fb2d1006d0b8fc 100644 (file)
@@ -1170,7 +1170,7 @@ static uint32_t parse_lifetime_mki(const char **p, const char *end)
                                        val += ((**p) - '0') * i;
                                }
                                res |= (val & 0x000000ff);                                      /* MKI_SIZE */
-                       } else if (isdigit(*(field_begin + 1)) && (field_begin + 2) && (*(field_begin + 2) == '^') && (field_begin + 3) && isdigit(*(field_begin + 3))) {
+                       } else if (isdigit(*(field_begin + 1)) && (*(field_begin + 2) == '^') && isdigit(*(field_begin + 3))) {
                                res |= (CRYPTO_KEY_MATERIAL_LIFETIME << 24);
                                val = ((uint32_t) (*(field_begin + 1) - '0')) << 8;
                                res |= val;                                                                     /* LIFETIME base. */
index c99a5f61de062d8d92bef9249cbe018083ff7213..d6cfd6ce1990fcfa00c3547b15bd97c1940f4582 100644 (file)
@@ -58,11 +58,16 @@ SWITCH_DECLARE(void) switch_curl_destroy(void)
        curl_global_cleanup();
 }
 
-SWITCH_DECLARE(switch_status_t) switch_curl_process_form_post_params(switch_event_t *event, switch_CURL *curl_handle, struct curl_httppost **formpostp)
+SWITCH_DECLARE(switch_status_t) switch_curl_process_mime(switch_event_t *event, switch_CURL *curl_handle, switch_curl_mime **mimep)
 {
-
+#if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800)
+       curl_mime *mime = NULL;
+       curl_mimepart *part = NULL;
+       uint8_t added = 0;
+#else
        struct curl_httppost *formpost=NULL;
        struct curl_httppost *lastptr=NULL;
+#endif
        switch_event_header_t *hp;
        int go = 0;
 
@@ -77,39 +82,87 @@ SWITCH_DECLARE(switch_status_t) switch_curl_process_form_post_params(switch_even
                return SWITCH_STATUS_FALSE;
        }
 
-       for (hp = event->headers; hp; hp = hp->next) {
+#if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800)
+       mime = curl_mime_init(curl_handle);
+#endif
 
+       for (hp = event->headers; hp; hp = hp->next) {
                if (!strncasecmp(hp->name, "attach_file:", 12)) {
                        char *pname = strdup(hp->name + 12);
 
                        if (pname) {
                                char *fname = strchr(pname, ':');
+
                                if (fname) {
                                        *fname++ = '\0';
 
+#if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800)
+                                       part = curl_mime_addpart(mime);
+                                       curl_mime_name(part, pname);
+                                       curl_mime_filename(part, fname);
+                                       curl_mime_filedata(part, hp->value);
+                                       added++;
+#else
                                        curl_formadd(&formpost,
                                                                 &lastptr,
                                                                 CURLFORM_COPYNAME, pname,
                                                                 CURLFORM_FILENAME, fname,
                                                                 CURLFORM_FILE, hp->value,
                                                                 CURLFORM_END);
+#endif
                                }
+
                                free(pname);
                        }
                } else {
+#if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800)
+                       part = curl_mime_addpart(mime);
+                       curl_mime_name(part, hp->name);
+                       curl_mime_data(part, hp->value, CURL_ZERO_TERMINATED);
+                       added++;
+#else
                        curl_formadd(&formpost,
                                                 &lastptr,
                                                 CURLFORM_COPYNAME, hp->name,
                                                 CURLFORM_COPYCONTENTS, hp->value,
                                                 CURLFORM_END);
-
+#endif
                }
        }
 
-       *formpostp = formpost;
+#if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800)
+       if (!added) {
+               curl_mime_free(mime);
+               mime = NULL;
+       }
+
+       *mimep = mime;
+#else
+       *mimep = formpost;
+#endif
 
        return SWITCH_STATUS_SUCCESS;
+}
 
+SWITCH_DECLARE(void) switch_curl_mime_free(switch_curl_mime **mimep)
+{
+       if (mimep && *mimep) {
+#if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800)
+               curl_mime_free(*mimep);
+#else
+               curl_formfree(*mimep);
+#endif
+               mimep = NULL;
+       }
+}
+
+SWITCH_DECLARE(switch_CURLcode) switch_curl_easy_setopt_mime(switch_CURL *curl_handle, switch_curl_mime *mime)
+{
+#if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800)
+       return curl_easy_setopt(curl_handle, CURLOPT_MIMEPOST, mime);
+#else
+       return curl_easy_setopt(curl_handle, CURLOPT_HTTPPOST, mime);
+#endif
 }
 
 /* For Emacs:
index 332137ebdae0ebe1060652ae2e457b0e7d682ef2..7561835e6963c868beb2cc3922bea94c4b261a7a 100644 (file)
@@ -2380,7 +2380,7 @@ SWITCH_DECLARE(int) switch_cmp_addr(switch_sockaddr_t *sa1, switch_sockaddr_t *s
                        return (s1->sin_addr.s_addr == s2->sin_addr.s_addr && s1->sin_port == s2->sin_port);
                }
        case AF_INET6:
-               if (s16->sin6_addr.s6_addr && s26->sin6_addr.s6_addr) {
+               {
                        int i;
 
                        if (!ip_only) {
@@ -2434,7 +2434,7 @@ SWITCH_DECLARE(int) switch_cp_addr(switch_sockaddr_t *sa1, switch_sockaddr_t *sa
 
                return 1;
        case AF_INET6:
-               if (s16->sin6_addr.s6_addr && s26->sin6_addr.s6_addr) {
+               {
                        int i;
 
                        s16->sin6_port = s26->sin6_port;