[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libmicrohttpd] 01/03: test_{digestauth,quiesce}: added report for libcu
From: |
gnunet |
Subject: |
[libmicrohttpd] 01/03: test_{digestauth,quiesce}: added report for libcurl error |
Date: |
Sun, 30 Jan 2022 15:12:59 +0100 |
This is an automated email from the git hooks/post-receive script.
karlson2k pushed a commit to branch master
in repository libmicrohttpd.
commit 4ec79163b2a9061f92717f859c4162c1820627d1
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
AuthorDate: Sun Jan 30 13:05:51 2022 +0300
test_{digestauth,quiesce}: added report for libcurl error
---
src/testcurl/test_digestauth.c | 59 ++++++++++++++++++++++++++++++---
src/testcurl/test_quiesce.c | 74 +++++++++++++++++++++++++++++++++---------
2 files changed, 113 insertions(+), 20 deletions(-)
diff --git a/src/testcurl/test_digestauth.c b/src/testcurl/test_digestauth.c
index 93f79a6a..09272a09 100644
--- a/src/testcurl/test_digestauth.c
+++ b/src/testcurl/test_digestauth.c
@@ -46,6 +46,14 @@
#include <wincrypt.h>
#endif
+#ifndef _MHD_INSTRMACRO
+/* Quoted macro parameter */
+#define _MHD_INSTRMACRO(a) #a
+#endif /* ! _MHD_INSTRMACRO */
+#ifndef _MHD_STRMACRO
+/* Quoted expanded macro parameter */
+#define _MHD_STRMACRO(a) _MHD_INSTRMACRO (a)
+#endif /* ! _MHD_STRMACRO */
#if defined(HAVE___FUNC__)
#define externalErrorExit(ignore) \
@@ -60,6 +68,9 @@
_mhdErrorExit_func(NULL, __func__, __LINE__)
#define mhdErrorExitDesc(errDesc) \
_mhdErrorExit_func(errDesc, __func__, __LINE__)
+#define checkCURLE_OK(libcurlcall) \
+ _checkCURLE_OK_func((libcurlcall), _MHD_STRMACRO(libcurlcall), \
+ __func__, __LINE__)
#elif defined(HAVE___FUNCTION__)
#define externalErrorExit(ignore) \
_externalErrorExit_func(NULL, __FUNCTION__, __LINE__)
@@ -73,6 +84,9 @@
_mhdErrorExit_func(NULL, __FUNCTION__, __LINE__)
#define mhdErrorExitDesc(errDesc) \
_mhdErrorExit_func(errDesc, __FUNCTION__, __LINE__)
+#define checkCURLE_OK(libcurlcall) \
+ _checkCURLE_OK_func((libcurlcall), _MHD_STRMACRO(libcurlcall), \
+ __FUNCTION__, __LINE__)
#else
#define externalErrorExit(ignore) _externalErrorExit_func(NULL, NULL, __LINE__)
#define externalErrorExitDesc(errDesc) \
@@ -82,6 +96,8 @@
_libcurlErrorExit_func(errDesc, NULL, __LINE__)
#define mhdErrorExit(ignore) _mhdErrorExit_func(NULL, NULL, __LINE__)
#define mhdErrorExitDesc(errDesc) _mhdErrorExit_func(errDesc, NULL, __LINE__)
+#define checkCURLE_OK(libcurlcall) \
+ _checkCURLE_OK_func((libcurlcall), _MHD_STRMACRO(libcurlcall), NULL,
__LINE__)
#endif
@@ -125,8 +141,11 @@ _libcurlErrorExit_func (const char *errDesc, const char
*funcName, int lineNum)
fprintf (stderr, ".\nLast errno value: %d (%s)\n", (int) errno,
strerror (errno));
+#ifdef MHD_WINSOCK_SOCKETS
+ fprintf (stderr, "WSAGetLastError() value: %d\n", (int) WSAGetLastError ());
+#endif /* MHD_WINSOCK_SOCKETS */
if (0 != libcurl_errbuf[0])
- fprintf (stderr, "Last libcurl error details: %s\n", libcurl_errbuf);
+ fprintf (stderr, "Last libcurl error description: %s\n", libcurl_errbuf);
fflush (stderr);
exit (99);
@@ -148,12 +167,44 @@ _mhdErrorExit_func (const char *errDesc, const char
*funcName, int lineNum)
fprintf (stderr, ".\nLast errno value: %d (%s)\n", (int) errno,
strerror (errno));
+#ifdef MHD_WINSOCK_SOCKETS
+ fprintf (stderr, "WSAGetLastError() value: %d\n", (int) WSAGetLastError ());
+#endif /* MHD_WINSOCK_SOCKETS */
fflush (stderr);
exit (8);
}
+static void
+_checkCURLE_OK_func (CURLcode code, const char *curlFunc,
+ const char *funcName, int lineNum)
+{
+ if (CURLE_OK == code)
+ return;
+
+ fflush (stdout);
+ if ((NULL != curlFunc) && (0 != curlFunc[0]))
+ fprintf (stderr, "'%s' resulted in '%s'", curlFunc,
+ curl_easy_strerror (code));
+ else
+ fprintf (stderr, "libcurl function call resulted in '%s'",
+ curl_easy_strerror (code));
+ if ((NULL != funcName) && (0 != funcName[0]))
+ fprintf (stderr, " in %s", funcName);
+ if (0 < lineNum)
+ fprintf (stderr, " at line %d", lineNum);
+
+ fprintf (stderr, ".\nLast errno value: %d (%s)\n", (int) errno,
+ strerror (errno));
+ if (0 != libcurl_errbuf[0])
+ fprintf (stderr, "Last libcurl error description: %s\n", libcurl_errbuf);
+
+ fflush (stderr);
+ exit (9);
+}
+
+
/* Could be increased to facilitate debugging */
#define TIMEOUTS_VAL 5
@@ -319,7 +370,6 @@ static int
testDigestAuth ()
{
CURL *c;
- CURLcode errornum;
struct MHD_Daemon *d;
struct CBC cbc;
char buf[2048];
@@ -393,8 +443,9 @@ testDigestAuth ()
port = (int) dinfo->port;
}
c = setupCURL (&cbc, port);
- if (CURLE_OK != (errornum = curl_easy_perform (c)))
- mhdErrorExitDesc ("curl_easy_perform() failed");
+
+ checkCURLE_OK (curl_easy_perform (c));
+
curl_easy_cleanup (c);
MHD_stop_daemon (d);
if (cbc.pos != strlen (PAGE))
diff --git a/src/testcurl/test_quiesce.c b/src/testcurl/test_quiesce.c
index f9bca831..1ea194b9 100644
--- a/src/testcurl/test_quiesce.c
+++ b/src/testcurl/test_quiesce.c
@@ -52,6 +52,15 @@
#endif
+#ifndef _MHD_INSTRMACRO
+/* Quoted macro parameter */
+#define _MHD_INSTRMACRO(a) #a
+#endif /* ! _MHD_INSTRMACRO */
+#ifndef _MHD_STRMACRO
+/* Quoted expanded macro parameter */
+#define _MHD_STRMACRO(a) _MHD_INSTRMACRO (a)
+#endif /* ! _MHD_STRMACRO */
+
#if defined(HAVE___FUNC__)
#define externalErrorExit(ignore) \
_externalErrorExit_func(NULL, __func__, __LINE__)
@@ -65,6 +74,9 @@
_mhdErrorExit_func(NULL, __func__, __LINE__)
#define mhdErrorExitDesc(errDesc) \
_mhdErrorExit_func(errDesc, __func__, __LINE__)
+#define checkCURLE_OK(libcurlcall) \
+ _checkCURLE_OK_func((libcurlcall), _MHD_STRMACRO(libcurlcall), \
+ __func__, __LINE__)
#elif defined(HAVE___FUNCTION__)
#define externalErrorExit(ignore) \
_externalErrorExit_func(NULL, __FUNCTION__, __LINE__)
@@ -78,6 +90,9 @@
_mhdErrorExit_func(NULL, __FUNCTION__, __LINE__)
#define mhdErrorExitDesc(errDesc) \
_mhdErrorExit_func(errDesc, __FUNCTION__, __LINE__)
+#define checkCURLE_OK(libcurlcall) \
+ _checkCURLE_OK_func((libcurlcall), _MHD_STRMACRO(libcurlcall), \
+ __FUNCTION__, __LINE__)
#else
#define externalErrorExit(ignore) _externalErrorExit_func(NULL, NULL, __LINE__)
#define externalErrorExitDesc(errDesc) \
@@ -87,12 +102,15 @@
_libcurlErrorExit_func(errDesc, NULL, __LINE__)
#define mhdErrorExit(ignore) _mhdErrorExit_func(NULL, NULL, __LINE__)
#define mhdErrorExitDesc(errDesc) _mhdErrorExit_func(errDesc, NULL, __LINE__)
+#define checkCURLE_OK(libcurlcall) \
+ _checkCURLE_OK_func((libcurlcall), _MHD_STRMACRO(libcurlcall), NULL,
__LINE__)
#endif
_MHD_NORETURN static void
_externalErrorExit_func (const char *errDesc, const char *funcName, int
lineNum)
{
+ fflush (stdout);
if ((NULL != errDesc) && (0 != errDesc[0]))
fprintf (stderr, "%s", errDesc);
else
@@ -117,6 +135,7 @@ static char libcurl_errbuf[CURL_ERROR_SIZE] = "";
_MHD_NORETURN static void
_libcurlErrorExit_func (const char *errDesc, const char *funcName, int lineNum)
{
+ fflush (stdout);
if ((NULL != errDesc) && (0 != errDesc[0]))
fprintf (stderr, "%s", errDesc);
else
@@ -128,8 +147,11 @@ _libcurlErrorExit_func (const char *errDesc, const char
*funcName, int lineNum)
fprintf (stderr, ".\nLast errno value: %d (%s)\n", (int) errno,
strerror (errno));
+#ifdef MHD_WINSOCK_SOCKETS
+ fprintf (stderr, "WSAGetLastError() value: %d\n", (int) WSAGetLastError ());
+#endif /* MHD_WINSOCK_SOCKETS */
if (0 != libcurl_errbuf[0])
- fprintf (stderr, "Last libcurl error details: %s\n", libcurl_errbuf);
+ fprintf (stderr, "Last libcurl error description: %s\n", libcurl_errbuf);
fflush (stderr);
exit (99);
@@ -139,6 +161,7 @@ _libcurlErrorExit_func (const char *errDesc, const char
*funcName, int lineNum)
_MHD_NORETURN static void
_mhdErrorExit_func (const char *errDesc, const char *funcName, int lineNum)
{
+ fflush (stdout);
if ((NULL != errDesc) && (0 != errDesc[0]))
fprintf (stderr, "%s", errDesc);
else
@@ -150,12 +173,44 @@ _mhdErrorExit_func (const char *errDesc, const char
*funcName, int lineNum)
fprintf (stderr, ".\nLast errno value: %d (%s)\n", (int) errno,
strerror (errno));
+#ifdef MHD_WINSOCK_SOCKETS
+ fprintf (stderr, "WSAGetLastError() value: %d\n", (int) WSAGetLastError ());
+#endif /* MHD_WINSOCK_SOCKETS */
fflush (stderr);
exit (8);
}
+static void
+_checkCURLE_OK_func (CURLcode code, const char *curlFunc,
+ const char *funcName, int lineNum)
+{
+ if (CURLE_OK == code)
+ return;
+
+ fflush (stdout);
+ if ((NULL != curlFunc) && (0 != curlFunc[0]))
+ fprintf (stderr, "'%s' resulted in '%s'", curlFunc,
+ curl_easy_strerror (code));
+ else
+ fprintf (stderr, "libcurl function call resulted in '%s'",
+ curl_easy_strerror (code));
+ if ((NULL != funcName) && (0 != funcName[0]))
+ fprintf (stderr, " in %s", funcName);
+ if (0 < lineNum)
+ fprintf (stderr, " at line %d", lineNum);
+
+ fprintf (stderr, ".\nLast errno value: %d (%s)\n", (int) errno,
+ strerror (errno));
+ if (0 != libcurl_errbuf[0])
+ fprintf (stderr, "Last libcurl error description: %s\n", libcurl_errbuf);
+
+ fflush (stderr);
+ exit (9);
+}
+
+
/* Could be increased to facilitate debugging */
#define TIMEOUTS_VAL 4
@@ -347,7 +402,6 @@ testGet (int type, int pool_count, int poll_flag)
CURL *c;
char buf[2048];
struct CBC cbc;
- CURLcode errornum;
MHD_socket fd;
pthread_t thrd;
const char *thrdRet;
@@ -387,13 +441,7 @@ testGet (int type, int pool_count, int poll_flag)
c = setupCURL (&cbc);
- if (CURLE_OK != (errornum = curl_easy_perform (c)))
- {
- fprintf (stderr,
- "curl_easy_perform() failed: '%s'. ",
- curl_easy_strerror (errornum));
- libcurlErrorExit ();
- }
+ checkCURLE_OK (curl_easy_perform (c));
if (cbc.pos != strlen (MHD_URI_BASE_PATH))
{
@@ -421,13 +469,7 @@ testGet (int type, int pool_count, int poll_flag)
/* No need for the thread sync as socket is already listening,
* so libcurl may start connecting before MHD is started in another thread */
cbc.pos = 0;
- if (CURLE_OK != (errornum = curl_easy_perform (c)))
- {
- fprintf (stderr,
- "curl_easy_perform() failed: `%s'\n",
- curl_easy_strerror (errornum));
- mhdErrorExit ();
- }
+ checkCURLE_OK (curl_easy_perform (c));
if (cbc.pos != strlen (MHD_URI_BASE_PATH))
{
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.