src/server/daemon/error.c

changeset 415
d938228c382e
parent 195
d367b687bc74
child 477
39ebd50cfc12
equal deleted inserted replaced
414:99a34860c105 415:d938228c382e
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29 #include "error.h" 29 #include "error.h"
30 30
31 #include <ucx/string.h> 31 #include <cx/string.h>
32 #include "../util/pblock.h" 32 #include "../util/pblock.h"
33 #include "../util/strbuf.h" 33 #include "../util/strbuf.h"
34 34
35 // macro for creating an error string (ucx sstr_t) 35 // macro for creating an error string (ucx cxmutstr)
36 #define ERRMSG(s) { s, sizeof(s)-1 } 36 #define ERRMSG(s) { s, sizeof(s)-1 }
37 37
38 static sstr_t error_400 = ERRMSG("<html><body>bad request</body></html>"); 38 static cxmutstr error_400 = ERRMSG("<html><body>bad request</body></html>");
39 static sstr_t error_403 = ERRMSG("<html><body>forbidden</body></html>"); 39 static cxmutstr error_403 = ERRMSG("<html><body>forbidden</body></html>");
40 static sstr_t error_404 = ERRMSG("<html><body>not found</body></html>"); 40 static cxmutstr error_404 = ERRMSG("<html><body>not found</body></html>");
41 static sstr_t error_500 = ERRMSG("<html><body>server error</body></html>"); 41 static cxmutstr error_500 = ERRMSG("<html><body>server error</body></html>");
42 static sstr_t error_503 = ERRMSG("<html><body>service unavailable</body></html>"); 42 static cxmutstr error_503 = ERRMSG("<html><body>service unavailable</body></html>");
43 43
44 static sstr_t error_std = ERRMSG("<html><body>error</body></html>"); 44 static cxmutstr error_std = ERRMSG("<html><body>error</body></html>");
45 45
46 int nsapi_error_request(Session *sn, Request *rq) { 46 int nsapi_error_request(Session *sn, Request *rq) {
47 short status = rq->status_num; 47 short status = rq->status_num;
48 sstr_t msg; 48 cxmutstr msg;
49 if(status < 400) { 49 if(status < 400) {
50 msg.ptr = NULL; 50 msg.ptr = NULL;
51 msg.length = 0; 51 msg.length = 0;
52 } else { 52 } else {
53 switch(status) { 53 switch(status) {
80 80
81 return REQ_PROCEED; 81 return REQ_PROCEED;
82 } 82 }
83 83
84 void fatal_error(HTTPRequest *req, int status) { 84 void fatal_error(HTTPRequest *req, int status) {
85 sstr_t msg = error_500; 85 cxmutstr msg = error_500;
86 char *statusmsg = "Internal Server Error"; 86 char *statusmsg = "Internal Server Error";
87 switch(status) { 87 switch(status) {
88 case 400: { 88 case 400: {
89 msg = error_400; 89 msg = error_400;
90 statusmsg = "Bad request"; 90 statusmsg = "Bad request";

mercurial