From: Fredrik Tolf Date: Thu, 2 Jan 2014 06:27:08 +0000 (+0100) Subject: lib: Moved default status strings from call[fs]cgi to library. X-Git-Url: http://www.dolda2000.com/gitweb/?p=ashd.git;a=commitdiff_plain;h=62e76c423b0621726c5da1cf9e1bd88005a863eb lib: Moved default status strings from call[fs]cgi to library. --- diff --git a/lib/resp.c b/lib/resp.c index 52fbd4b..25fb2cb 100644 --- a/lib/resp.c +++ b/lib/resp.c @@ -256,3 +256,45 @@ time_t parsehttpdate(char *date) return(timegm(&tm) - tz); } + +char *httpdefstatus(int code) +{ + switch(code) { + case 200: + return("OK"); + case 201: + return("Created"); + case 202: + return("Accepted"); + case 204: + return("No Content"); + case 300: + return("Multiple Choices"); + case 301: + return("Moved Permanently"); + case 302: + return("Found"); + case 303: + return("See Other"); + case 304: + return("Not Modified"); + case 307: + return("Moved Temporarily"); + case 400: + return("Bad Request"); + case 401: + return("Unauthorized"); + case 403: + return("Forbidden"); + case 404: + return("Not Found"); + case 500: + return("Internal Server Error"); + case 501: + return("Not Implemented"); + case 503: + return("Service Unavailable"); + default: + return("Unknown status"); + } +} diff --git a/lib/resp.h b/lib/resp.h index 8730584..6262244 100644 --- a/lib/resp.h +++ b/lib/resp.h @@ -10,5 +10,6 @@ void simpleerror2(FILE *out, int code, char *msg, char *fmt, ...); void stdredir(struct hthead *req, int fd, int code, char *dst); char *fmthttpdate(time_t time); time_t parsehttpdate(char *date); +char *httpdefstatus(int code); #endif diff --git a/src/callfcgi.c b/src/callfcgi.c index 3320f5d..6a8b3f0 100644 --- a/src/callfcgi.c +++ b/src/callfcgi.c @@ -45,6 +45,7 @@ #endif #include #include +#include #include #include #include @@ -509,46 +510,6 @@ static void mkcgienv(struct hthead *req, struct charbuf *dst) } } -static char *defstatus(int code) -{ - if(code == 200) - return("OK"); - else if(code == 201) - return("Created"); - else if(code == 202) - return("Accepted"); - else if(code == 204) - return("No Content"); - else if(code == 300) - return("Multiple Choices"); - else if(code == 301) - return("Moved Permanently"); - else if(code == 302) - return("Found"); - else if(code == 303) - return("See Other"); - else if(code == 304) - return("Not Modified"); - else if(code == 307) - return("Moved Temporarily"); - else if(code == 400) - return("Bad Request"); - else if(code == 401) - return("Unauthorized"); - else if(code == 403) - return("Forbidden"); - else if(code == 404) - return("Not Found"); - else if(code == 500) - return("Internal Server Error"); - else if(code == 501) - return("Not Implemented"); - else if(code == 503) - return("Service Unavailable"); - else - return("Unknown status"); -} - static struct hthead *parseresp(FILE *in) { struct hthead *resp; @@ -567,7 +528,7 @@ static struct hthead *parseresp(FILE *in) resp->msg = sstrdup(p); } else { resp->code = atoi(st); - resp->msg = sstrdup(defstatus(resp->code)); + resp->msg = sstrdup(httpdefstatus(resp->code)); } headrmheader(resp, "Status"); } else if(getheader(resp, "Location")) { diff --git a/src/callscgi.c b/src/callscgi.c index e388ab2..0ad3203 100644 --- a/src/callscgi.c +++ b/src/callscgi.c @@ -40,6 +40,7 @@ #endif #include #include +#include #include #include #include @@ -473,46 +474,6 @@ static void mkcgienv(struct hthead *req, struct charbuf *dst) } } -static char *defstatus(int code) -{ - if(code == 200) - return("OK"); - else if(code == 201) - return("Created"); - else if(code == 202) - return("Accepted"); - else if(code == 204) - return("No Content"); - else if(code == 300) - return("Multiple Choices"); - else if(code == 301) - return("Moved Permanently"); - else if(code == 302) - return("Found"); - else if(code == 303) - return("See Other"); - else if(code == 304) - return("Not Modified"); - else if(code == 307) - return("Moved Temporarily"); - else if(code == 400) - return("Bad Request"); - else if(code == 401) - return("Unauthorized"); - else if(code == 403) - return("Forbidden"); - else if(code == 404) - return("Not Found"); - else if(code == 500) - return("Internal Server Error"); - else if(code == 501) - return("Not Implemented"); - else if(code == 503) - return("Service Unavailable"); - else - return("Unknown status"); -} - static struct hthead *parseresp(FILE *in) { struct hthead *resp; @@ -531,7 +492,7 @@ static struct hthead *parseresp(FILE *in) resp->msg = sstrdup(p); } else { resp->code = atoi(st); - resp->msg = sstrdup(defstatus(resp->code)); + resp->msg = sstrdup(httpdefstatus(resp->code)); } headrmheader(resp, "Status"); } else if(getheader(resp, "Location")) {