Commit 0fe9ec14 authored by Deomid Ryabkov's avatar Deomid Ryabkov Committed by Cesanta Bot

C Clubby refactoring

Complete rewrite of the C Clubby implementation: it is now modeled after
the Go implementation, with a slight difference that codec and channel
are the same object (something we should probably do in Go as well, as
we only have a single type of channel so far, which is used with all
types of codecs).

This implementation also comes with a new external API,
which is hopefully cleaner and easier to use (see mg_clubby.h).

In this PR I am not adding any new types of channels, but a UART channel
as well as websocket listener channel will be added after this lands.

PUBLISHED_FROM=d545d4bb6434e2a02ad159f9e4b64e594a4797e7
parent b3fb21da
......@@ -1064,6 +1064,7 @@ void mbuf_remove(struct mbuf *mb, size_t n) {
/* Amalgamated: #include "common/mg_str.h" */
#include <stdlib.h>
#include <string.h>
int mg_ncasecmp(const char *s1, const char *s2, size_t len);
......@@ -1096,6 +1097,30 @@ int mg_vcasecmp(const struct mg_str *str1, const char *str2) {
}
return r;
}
struct mg_str mg_strdup(const struct mg_str s) {
struct mg_str r = {NULL, 0};
if (s.len > 0 && s.p != NULL) {
r.p = (char *) malloc(s.len);
if (r.p != NULL) {
memcpy((char *) r.p, s.p, s.len);
r.len = s.len;
}
}
return r;
}
int mg_strcmp(const struct mg_str str1, const struct mg_str str2) {
size_t i = 0;
while (i < str1.len && i < str2.len) {
if (str1.p[i] < str2.p[i]) return -1;
if (str1.p[i] > str2.p[i]) return 1;
i++;
}
if (i < str1.len) return 1;
if (i < str2.len) return -1;
return 0;
}
#ifdef MG_MODULE_LINES
#line 1 "./src/../../common/sha1.c"
#endif
......
......@@ -811,6 +811,9 @@ int mg_vcmp(const struct mg_str *str2, const char *str1);
*/
int mg_vcasecmp(const struct mg_str *str2, const char *str1);
struct mg_str mg_strdup(const struct mg_str s);
int mg_strcmp(const struct mg_str str1, const struct mg_str str2);
#ifdef __cplusplus
}
#endif /* __cplusplus */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment