babelouest / ulfius

Web Framework to build REST APIs, Webservices or any HTTP endpoint in C language. Can stream large amount of data, integrate JSON data with Jansson, and create websocket services
https://babelouest.github.io/ulfius
GNU Lesser General Public License v2.1
1.07k stars 183 forks source link

Two Darwin MacOS Building Issues with Fixes #187

Closed vergaraed closed 3 years ago

vergaraed commented 3 years ago

Two issues with fixes when building on Darwin/MacOS

1. Define MSG_NOSIGNAL=0

diff --git a/src/u_websocket.c b/src/u_websocket.c index a17cfe0..2fba8e2 100644 --- a/src/u_websocket.c +++ b/src/u_websocket.c @@ -47,6 +47,7 @@ /**********************************/ /** Internal websocket functions **/ /**********************************/ +#define MSG_NOSIGNAL 0

2. Change int to _enum MHD_Result_ on libmicrohttpd callback handles

diff --git a/src/ulfius.c b/src/ulfius.c index 5319dd3..3e7f744 100644 --- a/src/ulfius.c +++ b/src/ulfius.c @@ -56,12 +56,13 @@ void y_log_message(const unsigned long type, const char * message, ...) { int y_close_logs() { return 1; } + #endif

/** * Fill a map with the key/values specified */ -static int ulfius_fill_map_check_utf8(void * cls, enum MHD_ValueKind kind, const char * key, const char * value) { +static enum MHD_Result ulfius_fill_map_check_utf8(void * cls, enum MHD_ValueKind kind, const char * key, const char * value) { char * tmp; int res; UNUSED(kind); @@ -94,7 +95,7 @@ static int ulfius_fill_map_check_utf8(void * cls, enum MHD_ValueKind kind, const /** * Fill a map with the key/values specified */ -static int ulfius_fill_map(void * cls, enum MHD_ValueKind kind, const char * key, const char * value) { +static enum MHD_Result ulfius_fill_map(void * cls, enum MHD_ValueKind kind, const char * key, const char * value) { char * tmp; int res; UNUSED(kind); @@ -124,7 +125,7 @@ static int ulfius_fill_map(void * cls, enum MHD_ValueKind kind, const char * key * ulfius_is_valid_endpoint * return true if the endpoind has valid parameters */ -static int ulfius_is_valid_endpoint(const struct _u_endpoint * endpoint, int to_delete) { +static enum MHD_Result ulfius_is_valid_endpoint(const struct _u_endpoint * endpoint, int to_delete) { if (endpoint != NULL) { if (ulfius_equals_endpoints(endpoint, ulfius_empty_endpoint())) { // Should be the last endpoint of the list to close it @@ -290,7 +291,7 @@ static void mhd_request_completed (void *cls, struct MHD_Connection *connection, * if a parameter is larger than max_post_param_size, truncate it * return MHD_NO on error */ -static int mhd_iterate_post_data (void * coninfo_cls, enum MHD_ValueKind kind, const char * key, +static enum MHD_Result mhd_iterate_post_data (void * coninfo_cls, enum MHD_ValueKind kind, const char * key, const char * filename, const char * content_type, const char * transfer_encoding, const char * data, uint64_t off, size_t size) {

@@ -352,7 +353,7 @@ static int mhd_iterate_post_data (void * coninfo_cls, enum MHD_ValueKind kind, c * function executed by libmicrohttpd every time an HTTP call is made * return MHD_NO on error */ -static int ulfius_webservice_dispatcher (void * cls, struct MHD_Connection * connection, +static enum MHD_Result ulfius_webservice_dispatcher (void * cls, struct MHD_Connection * connection, const char * url, const char * method, const char * version, const char * upload_data, size_t * upload_data_size, void ** con_cls) {

Build From Source

mkdir build; cd build; rm CMakeCache.txt cmake -DWITH_JOURNALD=off .. make DISABLE_MARIADB=1 DISABLE_POSTGRESQL=1 && su make install

vergara_ed@yahoo.com

babelouest commented 3 years ago

Hello @vergaraed , thanks for contributing

Can you open a pull request instead of providing a diff file in the issue?

Also, in the pull request, make sure you use enum MHD_Result when relevant, because Ulfius is supported on old platforms where libmicrohttpd is older than the one provuding enum MHD_Result.

See an example here on how to use enum MHD_Result:

#if MHD_VERSION >= 0x00097002
static enum MHD_Result ulfius_fill_map_check_utf8(void * cls, enum MHD_ValueKind kind, const char * key, const char * value) {
#else
static int ulfius_fill_map_check_utf8(void * cls, enum MHD_ValueKind kind, const char * key, const char * value) {
#endif

And finally, if #define MSG_NOSIGNAL 0 is required for MacOSX, I'd disable this variable for MacOS only, something like this:

#if __APPLE__
#define MSG_NOSIGNAL 0
#endif

Thanks in advance!

vergaraed commented 3 years ago

So my repo was stale by several months, after pulling the latest, these issues were fixed.
Thanks very much.

babelouest commented 3 years ago

no problem