[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libmicrohttpd] 95/156: test_post_form: updated to support the new libcu
From: |
gnunet |
Subject: |
[libmicrohttpd] 95/156: test_post_form: updated to support the new libcurl API |
Date: |
Sun, 28 May 2023 17:52:28 +0200 |
This is an automated email from the git hooks/post-receive script.
karlson2k pushed a commit to tag v0.9.77
in repository libmicrohttpd.
commit 982049e1383bacf8b80045f5205463e3d03d51f2
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
AuthorDate: Mon May 15 18:07:59 2023 +0300
test_post_form: updated to support the new libcurl API
Muted libcurl deprecations warnings.
---
src/testzzuf/test_post_form.c | 126 ++++++++++++++++++++++++++++++++++--------
1 file changed, 103 insertions(+), 23 deletions(-)
diff --git a/src/testzzuf/test_post_form.c b/src/testzzuf/test_post_form.c
index d5a65b77..3c05d632 100644
--- a/src/testzzuf/test_post_form.c
+++ b/src/testzzuf/test_post_form.c
@@ -36,6 +36,18 @@
#include <unistd.h>
#endif
+#ifndef CURL_VERSION_BITS
+#define CURL_VERSION_BITS(x,y,z) ((x) << 16 | (y) << 8 | (z))
+#endif /* ! CURL_VERSION_BITS */
+#ifndef CURL_AT_LEAST_VERSION
+#define CURL_AT_LEAST_VERSION(x,y,z) \
+ (LIBCURL_VERSION_NUM >= CURL_VERSION_BITS (x, y, z))
+#endif /* ! CURL_AT_LEAST_VERSION */
+
+#if CURL_AT_LEAST_VERSION (7,56,0)
+#define HAS_CURL_MIME 1
+#endif /* CURL_AT_LEAST_VERSION(7,56,0) */
+
#include "socat.c"
@@ -165,17 +177,88 @@ ahc_echo (void *cls,
}
-static struct curl_httppost *
-make_form ()
+struct mhd_test_postdata
{
- struct curl_httppost *post = NULL;
+#if defined(HAS_CURL_MIME)
+ curl_mime *mime;
+#else /* ! HAS_CURL_MIME */
+ struct curl_httppost *post;
+#endif /* ! HAS_CURL_MIME */
+};
+
+/* Return non-zero if succeed */
+static int
+add_test_form (CURL *handle, struct mhd_test_postdata *postdata)
+{
+#if defined(HAS_CURL_MIME)
+ postdata->mime = curl_mime_init (handle);
+ if (NULL == postdata->mime)
+ return 0;
+ else
+ {
+ curl_mimepart *part;
+ part = curl_mime_addpart (postdata->mime);
+ if (NULL != part)
+ {
+ if ( (CURLE_OK == curl_mime_data (part, "daniel",
+ CURL_ZERO_TERMINATED)) &&
+ (CURLE_OK == curl_mime_name (part, "name")) )
+ {
+ part = curl_mime_addpart (postdata->mime);
+ if (NULL != part)
+ {
+ if ( (CURLE_OK == curl_mime_data (part, "curl",
+ CURL_ZERO_TERMINATED)) &&
+ (CURLE_OK == curl_mime_name (part, "project")) )
+ {
+ if (CURLE_OK == curl_easy_setopt (handle,
+ CURLOPT_MIMEPOST,
postdata->mime))
+ {
+ return ! 0;
+ }
+ }
+ }
+ }
+ }
+ }
+ curl_mime_free (postdata->mime);
+ postdata->mime = NULL;
+ return 0;
+#else /* ! HAS_CURL_MIME */
+ postdata->post = NULL;
struct curl_httppost *last = NULL;
- curl_formadd (&post, &last, CURLFORM_COPYNAME, "name",
- CURLFORM_COPYCONTENTS, "daniel", CURLFORM_END);
- curl_formadd (&post, &last, CURLFORM_COPYNAME, "project",
- CURLFORM_COPYCONTENTS, "curl", CURLFORM_END);
- return post;
+ if (0 == curl_formadd (&postdata->post, &last,
+ CURLFORM_COPYNAME, "name",
+ CURLFORM_COPYCONTENTS, "daniel", CURLFORM_END))
+ {
+ if (0 == curl_formadd (&postdata->post, &last,
+ CURLFORM_COPYNAME, "project",
+ CURLFORM_COPYCONTENTS, "curl", CURLFORM_END))
+ {
+ if (CURLE_OK == curl_easy_setopt (handle,
+ CURLOPT_HTTPPOST, postdata->post))
+ {
+ return ! 0;
+ }
+ }
+ }
+ curl_formfree (postdata->post);
+ return 0;
+#endif /* ! HAS_CURL_MIME */
+}
+
+
+static void
+free_test_form (struct mhd_test_postdata *postdata)
+{
+#if defined(HAS_CURL_MIME)
+ if (NULL != postdata->mime)
+ curl_mime_free (postdata->mime);
+#else /* ! HAS_CURL_MIME */
+ if (NULL != postdata->post)
+ curl_formfree (postdata->post);
+#endif /* ! HAS_CURL_MIME */
}
@@ -187,7 +270,7 @@ testInternalPost ()
char buf[2048];
struct CBC cbc;
int i;
- struct curl_httppost *pd;
+ struct mhd_test_postdata form;
cbc.buf = buf;
cbc.size = 2048;
@@ -207,8 +290,6 @@ testInternalPost ()
curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world");
curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer);
curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
- pd = make_form ();
- curl_easy_setopt (c, CURLOPT_HTTPPOST, pd);
curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
if (oneone)
@@ -220,9 +301,10 @@ testInternalPost ()
* setting NOSIGNAL results in really weird
* crashes on my system! */
curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
+ add_test_form (c, &form);
curl_easy_perform (c);
curl_easy_cleanup (c);
- curl_formfree (pd);
+ free_test_form (&form);
}
fprintf (stderr, "\n");
zzuf_socat_stop ();
@@ -239,7 +321,7 @@ testMultithreadedPost ()
char buf[2048];
struct CBC cbc;
int i;
- struct curl_httppost *pd;
+ struct mhd_test_postdata form;
cbc.buf = buf;
cbc.size = 2048;
@@ -259,8 +341,6 @@ testMultithreadedPost ()
curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world");
curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer);
curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
- pd = make_form ();
- curl_easy_setopt (c, CURLOPT_HTTPPOST, pd);
curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT);
if (oneone)
@@ -272,9 +352,10 @@ testMultithreadedPost ()
* setting NOSIGNAL results in really weird
* crashes on my system! */
curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
+ add_test_form (c, &form);
curl_easy_perform (c);
curl_easy_cleanup (c);
- curl_formfree (pd);
+ free_test_form (&form);
}
fprintf (stderr, "\n");
zzuf_socat_stop ();
@@ -299,7 +380,7 @@ testExternalPost ()
int running;
time_t start;
struct timeval tv;
- struct curl_httppost *pd;
+ struct mhd_test_postdata form;
int i;
multi = NULL;
@@ -327,8 +408,6 @@ testExternalPost ()
curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:1082/hello_world");
curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer);
curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
- pd = make_form ();
- curl_easy_setopt (c, CURLOPT_HTTPPOST, pd);
curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
if (oneone)
@@ -340,12 +419,13 @@ testExternalPost ()
* setting NOSIGNAL results in really weird
* crashes on my system! */
curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
+ add_test_form (c, &form);
mret = curl_multi_add_handle (multi, c);
if (mret != CURLM_OK)
{
curl_multi_cleanup (multi);
- curl_formfree (pd);
+ free_test_form (&form);
curl_easy_cleanup (c);
zzuf_socat_stop ();
MHD_stop_daemon (d);
@@ -367,7 +447,7 @@ testExternalPost ()
curl_easy_cleanup (c);
zzuf_socat_stop ();
MHD_stop_daemon (d);
- curl_formfree (pd);
+ free_test_form (&form);
return 2048;
}
if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
@@ -375,7 +455,7 @@ testExternalPost ()
curl_multi_remove_handle (multi, c);
curl_multi_cleanup (multi);
curl_easy_cleanup (c);
- curl_formfree (pd);
+ free_test_form (&form);
zzuf_socat_stop ();
MHD_stop_daemon (d);
return 4096;
@@ -398,7 +478,7 @@ testExternalPost ()
curl_multi_remove_handle (multi, c);
curl_easy_cleanup (c);
}
- curl_formfree (pd);
+ free_test_form (&form);
}
fprintf (stderr, "\n");
zzuf_socat_stop ();
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [libmicrohttpd] 77/156: Added test with large folded header, (continued)
- [libmicrohttpd] 77/156: Added test with large folded header, gnunet, 2023/05/28
- [libmicrohttpd] 75/156: Added new tests with header fold, gnunet, 2023/05/28
- [libmicrohttpd] 83/156: autoinit_funcs.h: added functions prototypes, gnunet, 2023/05/28
- [libmicrohttpd] 80/156: Added autoconf patches and fixes, gnunet, 2023/05/28
- [libmicrohttpd] 87/156: autoinit_funcs.h: fixed harmless typos, gnunet, 2023/05/28
- [libmicrohttpd] 89/156: autoinit_funcs.h: updated to use (semi-)official documented sections, gnunet, 2023/05/28
- [libmicrohttpd] 88/156: autoinit_funcs.h: added support for non-x86 arches for MSVC, gnunet, 2023/05/28
- [libmicrohttpd] 86/156: Muted compiler warnings for W32 non-TLS build of the lib, gnunet, 2023/05/28
- [libmicrohttpd] 93/156: Added more mutes for autoconf compiler warnings, gnunet, 2023/05/28
- [libmicrohttpd] 92/156: bootstrap script: improved portability, gnunet, 2023/05/28
- [libmicrohttpd] 95/156: test_post_form: updated to support the new libcurl API,
gnunet <=
- [libmicrohttpd] 104/156: test_quiesce: fixed possible uninitialised var, gnunet, 2023/05/28
- [libmicrohttpd] 101/156: configure: bumped gettext version requirement, gnunet, 2023/05/28
- [libmicrohttpd] 100/156: test_toolarge: fixed reported error description, gnunet, 2023/05/28
- [libmicrohttpd] 108/156: test_client_put_stop: fixed typo in comment, gnunet, 2023/05/28
- [libmicrohttpd] 105/156: Removed redundant autopoint file, gnunet, 2023/05/28
- [libmicrohttpd] 118/156: examples/http_chunked_compression.c: fixed void pointer arithmetic, gnunet, 2023/05/28
- [libmicrohttpd] 126/156: testcurl/https: moved certs variable declaration to the header, gnunet, 2023/05/28
- [libmicrohttpd] 116/156: examples/sessions.c: removed non-portable function, gnunet, 2023/05/28
- [libmicrohttpd] 132/156: W32 VS projects: unified output and intermediate directories, gnunet, 2023/05/28
- [libmicrohttpd] 133/156: W32 VS projects: disabled specific compiler warning on ARM, gnunet, 2023/05/28