Переглянути джерело

Renamed function from sg_httpread_end() to sg_eor().

silvioprog 6 роки тому
батько
коміт
b4a751ba33
9 змінених файлів з 39 додано та 39 видалено
  1. 7 7
      include/sagui.h
  2. 1 1
      src/CMakeLists.txt
  3. 4 4
      src/sg_extra.c
  4. 5 5
      src/sg_extra.h
  5. 2 2
      src/sg_httpauth.c
  6. 4 4
      src/sg_httpreq.c
  7. 2 2
      src/sg_httpres.c
  8. 1 1
      test/CMakeLists.txt
  9. 13 13
      test/test_extra.c

+ 7 - 7
include/sagui.h

@@ -217,6 +217,13 @@ SG_EXTERN char *sg_extract_entrypoint(const char *path);
  */
  */
 SG_EXTERN char *sg_tmpdir(void);
 SG_EXTERN char *sg_tmpdir(void);
 
 
+/**
+ * Indicates the end-of-read processed in #sg_httpres_sendstream().
+ * \param[in] err `true` to return a value indicating a stream reading error.
+ * \return Value to end a stream reading.
+ */
+SG_EXTERN ssize_t sg_eor(bool err);
+
 /** \} */
 /** \} */
 
 
 /**
 /**
@@ -1215,13 +1222,6 @@ SG_EXTERN int sg_httpsrv_set_con_limit(struct sg_httpsrv *srv, unsigned int limi
  */
  */
 SG_EXTERN unsigned int sg_httpsrv_con_limit(struct sg_httpsrv *srv);
 SG_EXTERN unsigned int sg_httpsrv_con_limit(struct sg_httpsrv *srv);
 
 
-/**
- * Returns a value to end a stream reading processed by #sg_httpres_sendstream().
- * \param[in] err `true` to return a value indicating a stream reading error.
- * \return Value to end a stream reading.
- */
-SG_EXTERN ssize_t sg_httpread_end(bool err);
-
 /** \} */
 /** \} */
 
 
 #ifdef SG_PATH_ROUTING
 #ifdef SG_PATH_ROUTING

+ 1 - 1
src/CMakeLists.txt

@@ -53,9 +53,9 @@ set(SG_SOURCE_DIR ${SG_SOURCE_DIR} PARENT_SCOPE)
 
 
 list(APPEND SG_C_SOURCE
 list(APPEND SG_C_SOURCE
         ${SG_SOURCE_DIR}/sg_utils.c
         ${SG_SOURCE_DIR}/sg_utils.c
+        ${SG_SOURCE_DIR}/sg_extra.c
         ${SG_SOURCE_DIR}/sg_str.c
         ${SG_SOURCE_DIR}/sg_str.c
         ${SG_SOURCE_DIR}/sg_strmap.c
         ${SG_SOURCE_DIR}/sg_strmap.c
-        ${SG_SOURCE_DIR}/sg_httputils.c
         ${SG_SOURCE_DIR}/sg_httpauth.c
         ${SG_SOURCE_DIR}/sg_httpauth.c
         ${SG_SOURCE_DIR}/sg_httpuplds.c
         ${SG_SOURCE_DIR}/sg_httpuplds.c
         ${SG_SOURCE_DIR}/sg_httpreq.c
         ${SG_SOURCE_DIR}/sg_httpreq.c

+ 4 - 4
src/sg_httputils.c → src/sg_extra.c

@@ -31,19 +31,19 @@
 #include "microhttpd.h"
 #include "microhttpd.h"
 #include "sg_strmap.h"
 #include "sg_strmap.h"
 #include "sagui.h"
 #include "sagui.h"
-#include "sg_httputils.h"
+#include "sg_extra.h"
 
 
-int sg__httpcon_iter(void *cls, __SG_UNUSED enum MHD_ValueKind kind, const char *key, const char *val) {
+int sg__convals_iter(void *cls, __SG_UNUSED enum MHD_ValueKind kind, const char *key, const char *val) {
     sg_strmap_add(cls, key, val);
     sg_strmap_add(cls, key, val);
     return MHD_YES;
     return MHD_YES;
 }
 }
 
 
-int sg__httpheaders_iter(void *cls, struct sg_strmap *header) {
+int sg__strmap_iter(void *cls, struct sg_strmap *header) {
     MHD_add_response_header(cls, header->name, header->val);
     MHD_add_response_header(cls, header->name, header->val);
     return 0;
     return 0;
 }
 }
 
 
-ssize_t sg_httpread_end(bool err) {
+ssize_t sg_eor(bool err) {
     return
     return
 #ifdef __ANDROID__
 #ifdef __ANDROID__
         (ssize_t)
         (ssize_t)

+ 5 - 5
src/sg_httputils.h → src/sg_extra.h

@@ -25,16 +25,16 @@
  * along with Sagui library.  If not, see <http://www.gnu.org/licenses/>.
  * along with Sagui library.  If not, see <http://www.gnu.org/licenses/>.
  */
  */
 
 
-#ifndef SG_HTTPUTILS_H
-#define SG_HTTPUTILS_H
+#ifndef SG_EXTRA_H
+#define SG_EXTRA_H
 
 
 #include "microhttpd.h"
 #include "microhttpd.h"
 #include "sg_macros.h"
 #include "sg_macros.h"
 #include "sg_strmap.h"
 #include "sg_strmap.h"
 #include "sagui.h"
 #include "sagui.h"
 
 
-SG__EXTERN int sg__httpcon_iter(void *cls, __SG_UNUSED enum MHD_ValueKind kind, const char *key, const char *val);
+SG__EXTERN int sg__convals_iter(void *cls, __SG_UNUSED enum MHD_ValueKind kind, const char *key, const char *val);
 
 
-SG__EXTERN int sg__httpheaders_iter(void *cls, struct sg_strmap *header);
+SG__EXTERN int sg__strmap_iter(void *cls, struct sg_strmap *map);
 
 
-#endif /* SG_HTTPUTILS_H */
+#endif /* SG_EXTRA_H */

+ 2 - 2
src/sg_httpauth.c

@@ -32,7 +32,7 @@
 #include "sg_macros.h"
 #include "sg_macros.h"
 #include "microhttpd.h"
 #include "microhttpd.h"
 #include "sagui.h"
 #include "sagui.h"
-#include "sg_httputils.h"
+#include "sg_extra.h"
 #include "sg_strmap.h"
 #include "sg_strmap.h"
 #include "sg_httpauth.h"
 #include "sg_httpauth.h"
 
 
@@ -64,7 +64,7 @@ bool sg__httpauth_dispatch(struct sg_httpauth *auth) {
         goto done;
         goto done;
     }
     }
     if (auth->res->handle) {
     if (auth->res->handle) {
-        sg_strmap_iter(auth->res->headers, sg__httpheaders_iter, auth->res->handle);
+        sg_strmap_iter(auth->res->headers, sg__strmap_iter, auth->res->handle);
         auth->res->ret = MHD_queue_basic_auth_fail_response(auth->res->con,
         auth->res->ret = MHD_queue_basic_auth_fail_response(auth->res->con,
                                                             auth->realm ? auth->realm : _("Sagui realm"),
                                                             auth->realm ? auth->realm : _("Sagui realm"),
                                                             auth->res->handle);
                                                             auth->res->handle);

+ 4 - 4
src/sg_httpreq.c

@@ -31,7 +31,7 @@
 #include "sg_macros.h"
 #include "sg_macros.h"
 #include "microhttpd.h"
 #include "microhttpd.h"
 #include "sagui.h"
 #include "sagui.h"
-#include "sg_httputils.h"
+#include "sg_extra.h"
 #include "sg_httpres.h"
 #include "sg_httpres.h"
 #include "sg_httpreq.h"
 #include "sg_httpreq.h"
 #include "sg_httpauth.h"
 #include "sg_httpauth.h"
@@ -83,7 +83,7 @@ struct sg_strmap **sg_httpreq_headers(struct sg_httpreq *req) {
         return NULL;
         return NULL;
     }
     }
     if (!req->headers)
     if (!req->headers)
-        MHD_get_connection_values(req->con, MHD_HEADER_KIND, sg__httpcon_iter, &req->headers);
+        MHD_get_connection_values(req->con, MHD_HEADER_KIND, sg__convals_iter, &req->headers);
     return &req->headers;
     return &req->headers;
 }
 }
 
 
@@ -93,7 +93,7 @@ struct sg_strmap **sg_httpreq_cookies(struct sg_httpreq *req) {
         return NULL;
         return NULL;
     }
     }
     if (!req->cookies)
     if (!req->cookies)
-        MHD_get_connection_values(req->con, MHD_COOKIE_KIND, sg__httpcon_iter, &req->cookies);
+        MHD_get_connection_values(req->con, MHD_COOKIE_KIND, sg__convals_iter, &req->cookies);
     return &req->cookies;
     return &req->cookies;
 }
 }
 
 
@@ -103,7 +103,7 @@ struct sg_strmap **sg_httpreq_params(struct sg_httpreq *req) {
         return NULL;
         return NULL;
     }
     }
     if (!req->params)
     if (!req->params)
-        MHD_get_connection_values(req->con, MHD_GET_ARGUMENT_KIND, sg__httpcon_iter, &req->params);
+        MHD_get_connection_values(req->con, MHD_GET_ARGUMENT_KIND, sg__convals_iter, &req->params);
     return &req->params;
     return &req->params;
 }
 }
 
 

+ 2 - 2
src/sg_httpres.c

@@ -40,7 +40,7 @@
 #include "sagui.h"
 #include "sagui.h"
 #include "sg_utils.h"
 #include "sg_utils.h"
 #include "sg_strmap.h"
 #include "sg_strmap.h"
-#include "sg_httputils.h"
+#include "sg_extra.h"
 #include "sg_httpres.h"
 #include "sg_httpres.h"
 
 
 #ifdef SG_HTTP_COMPRESSION
 #ifdef SG_HTTP_COMPRESSION
@@ -104,7 +104,7 @@ void sg__httpres_free(struct sg_httpres *res) {
 }
 }
 
 
 int sg__httpres_dispatch(struct sg_httpres *res) {
 int sg__httpres_dispatch(struct sg_httpres *res) {
-    sg_strmap_iter(res->headers, sg__httpheaders_iter, res->handle);
+    sg_strmap_iter(res->headers, sg__strmap_iter, res->handle);
     res->ret = MHD_queue_response(res->con, res->status, res->handle);
     res->ret = MHD_queue_response(res->con, res->status, res->handle);
     return res->ret;
     return res->ret;
 }
 }

+ 1 - 1
test/CMakeLists.txt

@@ -68,13 +68,13 @@ if (BUILD_TESTING)
     endif ()
     endif ()
     list(APPEND SG_TESTS
     list(APPEND SG_TESTS
             utils
             utils
+            extra
             str
             str
             strmap
             strmap
             entrypoint
             entrypoint
             entrypoints
             entrypoints
             routes
             routes
             router
             router
-            httputils
             httpauth
             httpauth
             httpuplds
             httpuplds
             httpreq
             httpreq

+ 13 - 13
test/test_httputils.c → test/test_extra.c

@@ -31,37 +31,37 @@
 #include <microhttpd.h>
 #include <microhttpd.h>
 #include <sagui.h>
 #include <sagui.h>
 #include "sg_strmap.h"
 #include "sg_strmap.h"
-#include "sg_httputils.h"
+#include "sg_extra.h"
 
 
-static void test__httpcon_iter(void) {
+static void test__convals_iter(void) {
     struct sg_strmap *map = NULL;
     struct sg_strmap *map = NULL;
-    ASSERT(sg__httpcon_iter(NULL, MHD_HEADER_KIND, "foo", "bar") == MHD_YES);
+    ASSERT(sg__convals_iter(NULL, MHD_HEADER_KIND, "foo", "bar") == MHD_YES);
     ASSERT(!map);
     ASSERT(!map);
-    ASSERT(sg__httpcon_iter(&map, MHD_HEADER_KIND, "foo", "bar") == MHD_YES);
+    ASSERT(sg__convals_iter(&map, MHD_HEADER_KIND, "foo", "bar") == MHD_YES);
     ASSERT(map);
     ASSERT(map);
     ASSERT(strcmp(sg_strmap_get(map, "foo"), "bar") == 0);
     ASSERT(strcmp(sg_strmap_get(map, "foo"), "bar") == 0);
     sg_strmap_cleanup(&map);
     sg_strmap_cleanup(&map);
 }
 }
 
 
-static void test__httpheaders_iter(void) {
+static void test__strmap_iter(void) {
     struct sg_strmap *header = sg_alloc(sizeof(struct sg_strmap));
     struct sg_strmap *header = sg_alloc(sizeof(struct sg_strmap));
     struct MHD_Response *res = sg_alloc(64);
     struct MHD_Response *res = sg_alloc(64);
     header->name = "";
     header->name = "";
     header->val = "";
     header->val = "";
-    ASSERT(sg__httpheaders_iter(NULL, header) == 0);
-    ASSERT(sg__httpheaders_iter(res, header) == 0);
+    ASSERT(sg__strmap_iter(NULL, header) == 0);
+    ASSERT(sg__strmap_iter(res, header) == 0);
     sg_free(header);
     sg_free(header);
     sg_free(res);
     sg_free(res);
 }
 }
 
 
-static void test_httpread_end(void) {
-    ASSERT(sg_httpread_end(false) == (ssize_t) MHD_CONTENT_READER_END_OF_STREAM);
-    ASSERT(sg_httpread_end(true) == (ssize_t) MHD_CONTENT_READER_END_WITH_ERROR);
+static void test_eor(void) {
+    ASSERT(sg_eor(false) == (ssize_t) MHD_CONTENT_READER_END_OF_STREAM);
+    ASSERT(sg_eor(true) == (ssize_t) MHD_CONTENT_READER_END_WITH_ERROR);
 }
 }
 
 
 int main(void) {
 int main(void) {
-    test__httpcon_iter();
-    test__httpheaders_iter();
-    test_httpread_end();
+    test__convals_iter();
+    test__strmap_iter();
+    test_eor();
     return EXIT_SUCCESS;
     return EXIT_SUCCESS;
 }
 }