Return to http_status.c CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / mpd / src / contrib / libpdel / http |
1.1 misho 1: 2: /* 3: * Copyright (c) 2001-2002 Packet Design, LLC. 4: * All rights reserved. 5: * 6: * Subject to the following obligations and disclaimer of warranty, 7: * use and redistribution of this software, in source or object code 8: * forms, with or without modifications are expressly permitted by 9: * Packet Design; provided, however, that: 10: * 11: * (i) Any and all reproductions of the source or object code 12: * must include the copyright notice above and the following 13: * disclaimer of warranties; and 14: * (ii) No rights are granted, in any manner or form, to use 15: * Packet Design trademarks, including the mark "PACKET DESIGN" 16: * on advertising, endorsements, or otherwise except as such 17: * appears in the above copyright notice or in the software. 18: * 19: * THIS SOFTWARE IS BEING PROVIDED BY PACKET DESIGN "AS IS", AND 20: * TO THE MAXIMUM EXTENT PERMITTED BY LAW, PACKET DESIGN MAKES NO 21: * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING 22: * THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED 23: * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, 24: * OR NON-INFRINGEMENT. PACKET DESIGN DOES NOT WARRANT, GUARANTEE, 25: * OR MAKE ANY REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS 26: * OF THE USE OF THIS SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, 27: * RELIABILITY OR OTHERWISE. IN NO EVENT SHALL PACKET DESIGN BE 28: * LIABLE FOR ANY DAMAGES RESULTING FROM OR ARISING OUT OF ANY USE 29: * OF THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, ANY DIRECT, 30: * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE, OR CONSEQUENTIAL 31: * DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, LOSS OF 32: * USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY THEORY OF 33: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 35: * THE USE OF THIS SOFTWARE, EVEN IF PACKET DESIGN IS ADVISED OF 36: * THE POSSIBILITY OF SUCH DAMAGE. 37: * 38: * Author: Archie Cobbs <archie@freebsd.org> 39: */ 40: 41: #include <sys/types.h> 42: #include <sys/syslog.h> 43: 44: #include <stdio.h> 45: #include <stdlib.h> 46: #include <stdarg.h> 47: #include <errno.h> 48: #include <string.h> 49: #include <ctype.h> 50: 51: #include <netinet/in.h> 52: 53: #include <openssl/ssl.h> 54: 55: #include "http/http_defs.h" 56: #include "http/http_server.h" 57: 58: struct http_status { 59: int code; 60: const char *msg; 61: }; 62: 63: static const struct http_status codes[] = { 64: { HTTP_STATUS_CONTINUE, "Continue" }, 65: { HTTP_STATUS_SWITCHING_PROTOCOLS, "Switching Protocols" }, 66: { HTTP_STATUS_OK, "OK" }, 67: { HTTP_STATUS_CREATED, "Created" }, 68: { HTTP_STATUS_ACCEPTED, "Accepted" }, 69: { HTTP_STATUS_NON_AUTHORITATIVE_INFORMATION, "Non-Authoritative Information" }, 70: { HTTP_STATUS_NO_CONTENT, "No Content" }, 71: { HTTP_STATUS_RESET_CONTENT, "Reset Content" }, 72: { HTTP_STATUS_PARTIAL_CONTENT, "Partial Content" }, 73: { HTTP_STATUS_MULTIPLE_CHOICES, "Multiple Choices" }, 74: { HTTP_STATUS_MOVED_PERMANENTLY, "Moved Permanently" }, 75: { HTTP_STATUS_FOUND, "Found" }, 76: { HTTP_STATUS_SEE_OTHER, "See Other" }, 77: { HTTP_STATUS_NOT_MODIFIED, "Not Modified" }, 78: { HTTP_STATUS_USE_PROXY, "Use Proxy" }, 79: { HTTP_STATUS_TEMPORARY_REDIRECT, "Temporary Redirect" }, 80: { HTTP_STATUS_BAD_REQUEST, "Bad Request" }, 81: { HTTP_STATUS_UNAUTHORIZED, "Authorization Required" }, 82: { HTTP_STATUS_PAYMENT_REQUIRED, "Payment Required" }, 83: { HTTP_STATUS_FORBIDDEN, "Forbidden" }, 84: { HTTP_STATUS_NOT_FOUND, "Not Found" }, 85: { HTTP_STATUS_METHOD_NOT_ALLOWED, "Method Not Allowed" }, 86: { HTTP_STATUS_NOT_ACCEPTABLE, "Not Acceptable" }, 87: { HTTP_STATUS_PROXY_AUTHENTICATION_REQUIRED, "Proxy Authentication Required" }, 88: { HTTP_STATUS_REQUEST_TIME_OUT, "Request Time-out" }, 89: { HTTP_STATUS_CONFLICT, "Conflict" }, 90: { HTTP_STATUS_GONE, "Gone" }, 91: { HTTP_STATUS_LENGTH_REQUIRED, "Length Required" }, 92: { HTTP_STATUS_PRECONDITION_FAILED, "Precondition Failed" }, 93: { HTTP_STATUS_REQUEST_ENTITY_TOO_LARGE, "Request Entity Too Large" }, 94: { HTTP_STATUS_REQUEST_URI_TOO_LARGE, "Request-URI Too Large" }, 95: { HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE, "Unsupported Media Type" }, 96: { HTTP_STATUS_REQUESTED_RANGE_NOT_SATISFIABLE, "Requested Range Not Satisfiable" }, 97: { HTTP_STATUS_EXPECTATION_FAILED, "Expectation Failed" }, 98: { HTTP_STATUS_INTERNAL_SERVER_ERROR, "Internal Server Error" }, 99: { HTTP_STATUS_NOT_IMPLEMENTED, "Not Implemented" }, 100: { HTTP_STATUS_BAD_GATEWAY, "Bad Gateway" }, 101: { HTTP_STATUS_SERVICE_UNAVAILABLE, "Service Unavailable" }, 102: { HTTP_STATUS_GATEWAY_TIME_OUT, "Gateway Time-out" }, 103: { HTTP_STATUS_HTTP_VERSION_NOT_SUPPORTED, "HTTP Version Not Supported" }, 104: }; 105: static const int num_codes = sizeof(codes) / sizeof(*codes); 106: 107: /* 108: * Internal functions 109: */ 110: static int code_cmp(const void *v1, const void *v2); 111: 112: const char * 113: http_response_status_msg(int code) 114: { 115: struct http_status key; 116: struct http_status *status; 117: static char buf[32]; 118: 119: key.code = code; 120: if ((status = bsearch(&key, 121: codes, num_codes, sizeof(*codes), code_cmp)) == NULL) { 122: snprintf(buf, sizeof(buf), "Unknown status code %d", code); 123: return (buf); 124: } 125: return (status->msg); 126: } 127: 128: static int 129: code_cmp(const void *v1, const void *v2) 130: { 131: const struct http_status *const s1 = v1; 132: const struct http_status *const s2 = v2; 133: 134: return (s1->code - s2->code); 135: } 136: 137: #if 0 138: 139: /* 140: * Generate the C #define's from the above list. 141: */ 142: int 143: main(int ac, char **av) 144: { 145: const char *prefix = "HTTP_STATUS_"; 146: char buf[128]; 147: int i; 148: 149: for (i = 0; i < num_codes; i++) { 150: const struct http_status *const code = &codes[i]; 151: int ntabs; 152: char *s; 153: int j; 154: 155: strlcpy(buf, code->msg, sizeof(buf)); 156: for (s = buf; *s != '\0'; s++) { 157: if (isalnum(*s)) 158: *s = toupper(*s); 159: else 160: *s = '_'; 161: } 162: printf("#define\t%s%s", prefix, buf); 163: ntabs = 6 - (strlen(buf) + strlen(prefix)) / 8; 164: for (j = 0; j < ntabs; j++) 165: printf("\t"); 166: printf("%d\n", code->code); 167: } 168: return (0); 169: } 170: 171: #endif