nuclear@1: #include "http.h" nuclear@1: nuclear@1: const char *http_strmsg(int code) nuclear@1: { nuclear@1: static const char **msgxxx[] = { nuclear@1: 0, http_msg1xx, http_msg2xx, http_msg3xx, http_msg4xx, http_msg5xx nuclear@1: }; nuclear@1: static int msgcount[] = { nuclear@1: 0, nuclear@1: sizeof http_msg1xx / sizeof *http_msg1xx, nuclear@1: sizeof http_msg2xx / sizeof *http_msg2xx, nuclear@1: sizeof http_msg3xx / sizeof *http_msg3xx, nuclear@1: sizeof http_msg4xx / sizeof *http_msg4xx, nuclear@1: sizeof http_msg5xx / sizeof *http_msg5xx nuclear@1: }; nuclear@1: nuclear@1: int type = code / 100; nuclear@1: int idx = code % 100; nuclear@1: nuclear@1: if(type < 1 || type >= sizeof msgxxx / sizeof *msgxxx) { nuclear@1: return "Invalid HTTP Status"; nuclear@1: } nuclear@1: nuclear@1: if(idx < 0 || idx >= msgcount[type]) { nuclear@1: return "Unknown HTTP Status"; nuclear@1: } nuclear@1: nuclear@1: return msgxxx[type][idx]; nuclear@1: }