tinywebd
annotate 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 |
rev | line source |
---|---|
nuclear@1 | 1 #include "http.h" |
nuclear@1 | 2 |
nuclear@1 | 3 const char *http_strmsg(int code) |
nuclear@1 | 4 { |
nuclear@1 | 5 static const char **msgxxx[] = { |
nuclear@1 | 6 0, http_msg1xx, http_msg2xx, http_msg3xx, http_msg4xx, http_msg5xx |
nuclear@1 | 7 }; |
nuclear@1 | 8 static int msgcount[] = { |
nuclear@1 | 9 0, |
nuclear@1 | 10 sizeof http_msg1xx / sizeof *http_msg1xx, |
nuclear@1 | 11 sizeof http_msg2xx / sizeof *http_msg2xx, |
nuclear@1 | 12 sizeof http_msg3xx / sizeof *http_msg3xx, |
nuclear@1 | 13 sizeof http_msg4xx / sizeof *http_msg4xx, |
nuclear@1 | 14 sizeof http_msg5xx / sizeof *http_msg5xx |
nuclear@1 | 15 }; |
nuclear@1 | 16 |
nuclear@1 | 17 int type = code / 100; |
nuclear@1 | 18 int idx = code % 100; |
nuclear@1 | 19 |
nuclear@1 | 20 if(type < 1 || type >= sizeof msgxxx / sizeof *msgxxx) { |
nuclear@1 | 21 return "Invalid HTTP Status"; |
nuclear@1 | 22 } |
nuclear@1 | 23 |
nuclear@1 | 24 if(idx < 0 || idx >= msgcount[type]) { |
nuclear@1 | 25 return "Unknown HTTP Status"; |
nuclear@1 | 26 } |
nuclear@1 | 27 |
nuclear@1 | 28 return msgxxx[type][idx]; |
nuclear@1 | 29 } |