tinywebd

diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/http.c	Tue Apr 14 08:32:51 2015 +0300
     1.3 @@ -0,0 +1,29 @@
     1.4 +#include "http.h"
     1.5 +
     1.6 +const char *http_strmsg(int code)
     1.7 +{
     1.8 +	static const char **msgxxx[] = {
     1.9 +		0, http_msg1xx, http_msg2xx, http_msg3xx, http_msg4xx, http_msg5xx
    1.10 +	};
    1.11 +	static int msgcount[] = {
    1.12 +		0,
    1.13 +		sizeof http_msg1xx / sizeof *http_msg1xx,
    1.14 +		sizeof http_msg2xx / sizeof *http_msg2xx,
    1.15 +		sizeof http_msg3xx / sizeof *http_msg3xx,
    1.16 +		sizeof http_msg4xx / sizeof *http_msg4xx,
    1.17 +		sizeof http_msg5xx / sizeof *http_msg5xx
    1.18 +	};
    1.19 +
    1.20 +	int type = code / 100;
    1.21 +	int idx = code % 100;
    1.22 +
    1.23 +	if(type < 1 || type >= sizeof msgxxx / sizeof *msgxxx) {
    1.24 +		return "Invalid HTTP Status";
    1.25 +	}
    1.26 +
    1.27 +	if(idx < 0 || idx >= msgcount[type]) {
    1.28 +		return "Unknown HTTP Status";
    1.29 +	}
    1.30 +
    1.31 +	return msgxxx[type][idx];
    1.32 +}