diff --git a/docs/c-api/net.h/intro.md b/docs/c-api/net.h/intro.md index bad4f7fd..aa93e440 100644 --- a/docs/c-api/net.h/intro.md +++ b/docs/c-api/net.h/intro.md @@ -25,7 +25,6 @@ items: - { type: file, name: mg_set_timer.md } - { type: file, name: mg_time.md } - { type: file, name: mg_event_handler_t.md } - - { type: file, name: struct_mg_str.md } - { type: file, name: struct_mg_mgr.md } - { type: file, name: struct_mg_connection.md } - { type: file, name: struct_mg_add_sock_opts.md } diff --git a/docs/c-api/net.h/struct_mg_str.md b/docs/c-api/net.h/struct_mg_str.md deleted file mode 100644 index 6c0ad613..00000000 --- a/docs/c-api/net.h/struct_mg_str.md +++ /dev/null @@ -1,13 +0,0 @@ ---- -title: "struct mg_str" -decl_name: "struct mg_str" -symbol_kind: "struct" -signature: | - struct mg_str { - const char *p; /* Memory chunk pointer */ - size_t len; /* Memory chunk length */ - }; ---- - -Describes chunk of memory - diff --git a/docs/c-api/util.h/MG_MK_STR.md b/docs/c-api/util.h/MG_MK_STR.md deleted file mode 100644 index 4862e862..00000000 --- a/docs/c-api/util.h/MG_MK_STR.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -title: "MG_MK_STR()" -decl_name: "MG_MK_STR" -symbol_kind: "func" -signature: | - #define MG_MK_STR(str_literal); ---- - -Macro for initializing mg_str. - diff --git a/docs/c-api/util.h/intro.md b/docs/c-api/util.h/intro.md index a3237a11..e157a526 100644 --- a/docs/c-api/util.h/intro.md +++ b/docs/c-api/util.h/intro.md @@ -6,8 +6,6 @@ items: - { type: file, name: mg_skip.md } - { type: file, name: mg_ncasecmp.md } - { type: file, name: mg_casecmp.md } - - { type: file, name: mg_vcmp.md } - - { type: file, name: mg_vcasecmp.md } - { type: file, name: mg_base64_decode.md } - { type: file, name: mg_base64_encode.md } - { type: file, name: mg_stat.md } @@ -23,8 +21,6 @@ items: - { type: file, name: mg_is_big_endian.md } - { type: file, name: mg_next_comma_list_entry.md } - { type: file, name: mg_match_prefix.md } - - { type: file, name: mg_mk_str.md } - - { type: file, name: MG_MK_STR.md } --- diff --git a/docs/c-api/util.h/mg_mk_str.md b/docs/c-api/util.h/mg_mk_str.md deleted file mode 100644 index 89afcefd..00000000 --- a/docs/c-api/util.h/mg_mk_str.md +++ /dev/null @@ -1,11 +0,0 @@ ---- -title: "mg_mk_str()" -decl_name: "mg_mk_str" -symbol_kind: "func" -signature: | - struct mg_str mg_mk_str(const char *s); ---- - -A helper function for creating mg_str struct from plain C string. -`NULL` is allowed and becomes `{NULL, 0}`. - diff --git a/docs/c-api/util.h/mg_vcasecmp.md b/docs/c-api/util.h/mg_vcasecmp.md deleted file mode 100644 index 54cb1ab0..00000000 --- a/docs/c-api/util.h/mg_vcasecmp.md +++ /dev/null @@ -1,11 +0,0 @@ ---- -title: "mg_vcasecmp()" -decl_name: "mg_vcasecmp" -symbol_kind: "func" -signature: | - int mg_vcasecmp(const struct mg_str *str2, const char *str1); ---- - -Cross-platform version of `strncasecmp()` where first string is -specified by `struct mg_str`. - diff --git a/docs/c-api/util.h/mg_vcmp.md b/docs/c-api/util.h/mg_vcmp.md deleted file mode 100644 index 74c29d12..00000000 --- a/docs/c-api/util.h/mg_vcmp.md +++ /dev/null @@ -1,11 +0,0 @@ ---- -title: "mg_vcmp()" -decl_name: "mg_vcmp" -symbol_kind: "func" -signature: | - int mg_vcmp(const struct mg_str *str2, const char *str1); ---- - -Cross-platform version of `strcmp()` where where first string is -specified by `struct mg_str`. - diff --git a/mongoose.c b/mongoose.c index d50777da..1a3ab0aa 100644 --- a/mongoose.c +++ b/mongoose.c @@ -954,6 +954,41 @@ void mbuf_remove(struct mbuf *mb, size_t n) { #endif /* EXCLUDE_COMMON */ #ifdef MG_MODULE_LINES +#line 1 "./src/../../common/mg_str.c" +#endif +/* + * Copyright (c) 2014-2016 Cesanta Software Limited + * All rights reserved + */ + +/* Amalgamated: #include "common/mg_str.h" */ + +#include + +struct mg_str mg_mk_str(const char *s) { + struct mg_str ret = {s, 0}; + if (s != NULL) ret.len = strlen(s); + return ret; +} + +int mg_vcmp(const struct mg_str *str1, const char *str2) { + size_t n2 = strlen(str2), n1 = str1->len; + int r = memcmp(str1->p, str2, (n1 < n2) ? n1 : n2); + if (r == 0) { + return n1 - n2; + } + return r; +} + +int mg_vcasecmp(const struct mg_str *str1, const char *str2) { + size_t n2 = strlen(str2), n1 = str1->len; + int r = mg_ncasecmp(str1->p, str2, (n1 < n2) ? n1 : n2); + if (r == 0) { + return n1 - n2; + } + return r; +} +#ifdef MG_MODULE_LINES #line 1 "./src/../../common/sha1.c" #endif /* Copyright(c) By Steve Reid */ @@ -7302,24 +7337,6 @@ int mg_casecmp(const char *s1, const char *s2) { return mg_ncasecmp(s1, s2, (size_t) ~0); } -int mg_vcasecmp(const struct mg_str *str1, const char *str2) { - size_t n2 = strlen(str2), n1 = str1->len; - int r = mg_ncasecmp(str1->p, str2, (n1 < n2) ? n1 : n2); - if (r == 0) { - return n1 - n2; - } - return r; -} - -int mg_vcmp(const struct mg_str *str1, const char *str2) { - size_t n2 = strlen(str2), n1 = str1->len; - int r = memcmp(str1->p, str2, (n1 < n2) ? n1 : n2); - if (r == 0) { - return n1 - n2; - } - return r; -} - #ifndef MG_DISABLE_FILESYSTEM int mg_stat(const char *path, cs_stat_t *st) { #ifdef _WIN32 @@ -7641,12 +7658,6 @@ int mg_match_prefix(const char *pattern, int pattern_len, const char *str) { const struct mg_str pstr = {pattern, (size_t) pattern_len}; return mg_match_prefix_n(pstr, mg_mk_str(str)); } - -struct mg_str mg_mk_str(const char *s) { - struct mg_str ret = {s, 0}; - if (s != NULL) ret.len = strlen(s); - return ret; -} #ifdef MG_MODULE_LINES #line 1 "./src/mqtt.c" #endif diff --git a/mongoose.h b/mongoose.h index a2c97e3a..0a0057c6 100644 --- a/mongoose.h +++ b/mongoose.h @@ -841,6 +841,53 @@ double cs_time(); #endif /* __cplusplus */ #endif /* CS_COMMON_CS_TIME_H_ */ +/* + * Copyright (c) 2014-2016 Cesanta Software Limited + * All rights reserved + */ + +#ifndef CS_COMMON_MG_STR_H_ +#define CS_COMMON_MG_STR_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/* Describes chunk of memory */ +struct mg_str { + const char *p; /* Memory chunk pointer */ + size_t len; /* Memory chunk length */ +}; + +/* + * A helper function for creating mg_str struct from plain C string. + * `NULL` is allowed and becomes `{NULL, 0}`. + */ +struct mg_str mg_mk_str(const char *s); + +/* Macro for initializing mg_str. */ +#define MG_MK_STR(str_literal) \ + { str_literal, sizeof(str_literal) - 1 } + +/* + * Cross-platform version of `strcmp()` where where first string is + * specified by `struct mg_str`. + */ +int mg_vcmp(const struct mg_str *str2, const char *str1); + +/* + * Cross-platform version of `strncasecmp()` where first string is + * specified by `struct mg_str`. + */ +int mg_vcasecmp(const struct mg_str *str2, const char *str1); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* CS_COMMON_MG_STR_H_ */ /* * Copyright (c) 2015 Cesanta Software Limited * All rights reserved @@ -1140,12 +1187,6 @@ union socket_address { #endif }; -/* Describes chunk of memory */ -struct mg_str { - const char *p; /* Memory chunk pointer */ - size_t len; /* Memory chunk length */ -}; - struct mg_connection; /* @@ -1793,18 +1834,6 @@ int mg_ncasecmp(const char *s1, const char *s2, size_t len); */ int mg_casecmp(const char *s1, const char *s2); -/* - * Cross-platform version of `strcmp()` where where first string is - * specified by `struct mg_str`. - */ -int mg_vcmp(const struct mg_str *str2, const char *str1); - -/* - * Cross-platform version of `strncasecmp()` where first string is - * specified by `struct mg_str`. - */ -int mg_vcasecmp(const struct mg_str *str2, const char *str1); - /* * Decode base64-encoded string `s`, `len` into the destination `dst`. * Destination has to have enough space to hold decoded buffer. @@ -1963,16 +1992,6 @@ const char *mg_next_comma_list_entry(const char *list, struct mg_str *val, int mg_match_prefix(const char *pattern, int pattern_len, const char *str); int mg_match_prefix_n(const struct mg_str pattern, const struct mg_str str); -/* - * A helper function for creating mg_str struct from plain C string. - * `NULL` is allowed and becomes `{NULL, 0}`. - */ -struct mg_str mg_mk_str(const char *s); - -/* Macro for initializing mg_str. */ -#define MG_MK_STR(str_literal) \ - { str_literal, sizeof(str_literal) - 1 } - #ifdef __cplusplus } #endif /* __cplusplus */