[PATCH 1/2] capabilities: conditionalize mhd callback return type
authorJose M. Guisado Gomez <guigom@riseup.net>
Sat, 18 Jul 2020 10:25:21 +0000 (12:25 +0200)
committerPeter Michael Green <plugwash@raspbian.org>
Tue, 22 Sep 2020 14:58:41 +0000 (15:58 +0100)
libmicrohttpd introduced an API change with respect its callback
return types. Now its signature says that an enum must be returned
instead of an int. This causes collectd to not finish compilation
because of the compiler warnings this arised (in addition to -Werror)

Add conditional compiling so systems with microhttpd >=0.9.71 can
compile collectd with -Werror

Fixes #3511

Gbp-Pq: Name 3512.patch

src/capabilities.c
src/capabilities_test.c
src/write_prometheus.c

index 5c27e6a3a1eaf0016b69d664795fd97f99397c47..a3a31c1aec197bc5f912d348e1f3ded5d105abb3 100644 (file)
 #include "utils/dmi/dmi.h"
 
 #include <microhttpd.h>
+#if MHD_VERSION >= 0x00097002
+#define MHD_RESULT enum MHD_Result
+#else
+#define MHD_RESULT int
+#endif
 
 #include <jansson.h>
 #include <netdb.h>
@@ -187,10 +192,11 @@ static int cap_get_dmi_variables(json_t *parent, const dmi_type type,
 
 /* http_handler is the callback called by the microhttpd library. It essentially
  * handles all HTTP request aspects and creates an HTTP response. */
-static int cap_http_handler(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 **connection_state) {
+static MHD_RESULT cap_http_handler(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 **connection_state) {
   if (strcmp(method, MHD_HTTP_METHOD_GET) != 0) {
     return MHD_NO;
   }
index 16061d294a9d523e735f4280a90d2ed29d158671..8207740df599c3a34492829a748ed99d939d1829 100644 (file)
@@ -93,14 +93,14 @@ struct MHD_Response *MHD_create_response_from_data(size_t size, void *data,
   return mhd_res;
 }
 
-int MHD_add_response_header(struct MHD_Response *response, const char *header,
-                            const char *content) {
+MHD_RESULT MHD_add_response_header(struct MHD_Response *response,
+                                   const char *header, const char *content) {
   return 0;
 }
 
-int MHD_queue_response(struct MHD_Connection *connection,
-                       unsigned int status_code,
-                       struct MHD_Response *response) {
+MHD_RESULT MHD_queue_response(struct MHD_Connection *connection,
+                              unsigned int status_code,
+                              struct MHD_Response *response) {
   return MHD_HTTP_OK;
 }
 
index b9040223bcc0559855f4f2dd6f9e59cc473fcb53..9d3df08f55e539f90b747b78c0387c685c2c5536 100644 (file)
   "encoding=delimited"
 #define CONTENT_TYPE_TEXT "text/plain; version=0.0.4"
 
+#if MHD_VERSION >= 0x00097002
+#define MHD_RESULT enum MHD_Result
+#else
+#define MHD_RESULT int
+#endif
+
+
 static c_avl_tree_t *metrics;
 static pthread_mutex_t metrics_lock = PTHREAD_MUTEX_INITIALIZER;
 
@@ -227,7 +234,7 @@ static void format_text(ProtobufCBuffer *buffer) {
 
 /* http_handler is the callback called by the microhttpd library. It essentially
  * handles all HTTP request aspects and creates an HTTP response. */
-static int http_handler(void *cls, struct MHD_Connection *connection,
+static MHD_RESULT http_handler(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 **connection_state) {
@@ -268,7 +275,7 @@ static int http_handler(void *cls, struct MHD_Connection *connection,
   MHD_add_response_header(res, MHD_HTTP_HEADER_CONTENT_TYPE,
                           want_proto ? CONTENT_TYPE_PROTO : CONTENT_TYPE_TEXT);
 
-  int status = MHD_queue_response(connection, MHD_HTTP_OK, res);
+  MHD_RESULT status = MHD_queue_response(connection, MHD_HTTP_OK, res);
 
   MHD_destroy_response(res);
   PROTOBUF_C_BUFFER_SIMPLE_CLEAR(&simple);