tinywebd
view src/http.c @ 1:f425a9805d17
foo
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Tue, 14 Apr 2015 08:32:51 +0300 |
parents | |
children | 7bb4c2a0a360 |
line source
1 #include "http.h"
3 const char *http_strmsg(int code)
4 {
5 static const char **msgxxx[] = {
6 0, http_msg1xx, http_msg2xx, http_msg3xx, http_msg4xx, http_msg5xx
7 };
8 static int msgcount[] = {
9 0,
10 sizeof http_msg1xx / sizeof *http_msg1xx,
11 sizeof http_msg2xx / sizeof *http_msg2xx,
12 sizeof http_msg3xx / sizeof *http_msg3xx,
13 sizeof http_msg4xx / sizeof *http_msg4xx,
14 sizeof http_msg5xx / sizeof *http_msg5xx
15 };
17 int type = code / 100;
18 int idx = code % 100;
20 if(type < 1 || type >= sizeof msgxxx / sizeof *msgxxx) {
21 return "Invalid HTTP Status";
22 }
24 if(idx < 0 || idx >= msgcount[type]) {
25 return "Unknown HTTP Status";
26 }
28 return msgxxx[type][idx];
29 }