aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2017-10-23 14:12:08 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2017-10-23 14:12:08 +0200
commit425026b352cec3980d111bdc30e8dcc77c117ee0 (patch)
treeeb7c792457a8ec83b66785d8db8a10951b6b7a3e
parent45088e9f96c9889089d7b0eca810d89a2b3d7374 (diff)
websocket: Add function that explain error codes
Change-Id: I500520edac6792013650fa3cb0e02d0b9f5610d5 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
-rw-r--r--src/websock.c21
-rw-r--r--src/websock.h2
2 files changed, 23 insertions, 0 deletions
diff --git a/src/websock.c b/src/websock.c
index 48de5647..cc1e191e 100644
--- a/src/websock.c
+++ b/src/websock.c
@@ -585,3 +585,24 @@ void websock_set_max_length(struct websock *ws, size_t maxlen)
{
ws->maxlength = (uint64_t)maxlen;
}
+
+const char *websocket_explain_error(uint16_t code)
+{
+ static const char *msgs[] = {
+ "OK", /* 1000 */
+ "GOING_AWAY", /* 1001 */
+ "PROTOCOL_ERROR", /* 1002 */
+ "CANT_ACCEPT", /* 1003 */
+ "RESERVED", /* 1004 */
+ "NOT_SET", /* 1005 */
+ "ABNORMAL", /* 1006 */
+ "INVALID_UTF8", /* 1007 */
+ "POLICY_VIOLATION", /* 1008 */
+ "MESSAGE_TOO_LARGE", /* 1009 */
+ "EXPECT_EXTENSION", /* 1010 */
+ "INTERNAL_ERROR", /* 1011 */
+ };
+ if (code < 1000 || (code - 1000) >= (sizeof msgs / sizeof *msgs))
+ return "?";
+ return msgs[code - 1000];
+}
diff --git a/src/websock.h b/src/websock.h
index 3be89dfe..27acedcd 100644
--- a/src/websock.h
+++ b/src/websock.h
@@ -77,3 +77,5 @@ extern void websock_destroy(struct websock *ws);
extern void websock_set_default_max_length(size_t maxlen);
extern void websock_set_max_length(struct websock *ws, size_t maxlen);
+
+extern const char *websocket_explain_error(uint16_t code);