1 /*******************************************************************************
2  *
3  * Copyright (c) 2000-2003 Intel Corporation
4  * All rights reserved.
5  * Copyright (c) 2012 France Telecom All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * - Redistributions of source code must retain the above copyright notice,
11  * this list of conditions and the following disclaimer.
12  * - Redistributions in binary form must reproduce the above copyright notice,
13  * this list of conditions and the following disclaimer in the documentation
14  * and/or other materials provided with the distribution.
15  * - Neither name of Intel Corporation nor the names of its contributors
16  * may be used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
23  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
27  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  *
31  ******************************************************************************/
32 
33 /************************************************************************
34 * Purpose: This file defines status codes, buffers to store the status    *
35 * messages and functions to manipulate those buffers                    *
36 ************************************************************************/
37 
38 #include "config.h"
39 #include <map>
40 #include <string>
41 
42 #include "statcodes.h"
43 
44 static const std::map<int, std::string> httpcodes {
45     {HTTP_CONTINUE, "Continue"},
46     {HTTP_SWITCHING_PROCOTOLS , "Switching Protocols"},
47     {HTTP_OK, "OK"},
48     {HTTP_CREATED , "Created"},
49     {HTTP_ACCEPTED , "Accepted"},
50     {HTTP_NON_AUTHORATATIVE , "Non-Authoritative Information"},
51     {HTTP_NO_CONTENT, "No Content"},
52     {HTTP_RESET_CONTENT , "Reset Content"},
53     {HTTP_PARTIAL_CONTENT , "Partial Content"},
54     {HTTP_MULTIPLE_CHOICES , "Multiple Choices"},
55     {HTTP_MOVED_PERMANENTLY , "Moved Permanently"},
56     {HTTP_FOUND , "Found"},
57     {HTTP_SEE_OTHER , "See Other"},
58     {HTTP_NOT_MODIFIED , "Not Modified"},
59     {HTTP_USE_PROXY , "Use Proxy"},
60     {HTTP_TEMPORARY_REDIRECT, "Temporary Redirect"},
61     {HTTP_BAD_REQUEST , "Bad Request"},
62     {HTTP_UNAUTHORIZED , "Unauthorized"},
63     {HTTP_PAYMENT_REQD , "Payment Required"},
64     {HTTP_FORBIDDEN , "Forbidden"},
65     {HTTP_NOT_FOUND , "Not Found"},
66     {HTTP_METHOD_NOT_ALLOWED, "Method Not Allowed"},
67     {HTTP_NOT_ACCEPTABLE , "Not Acceptable"},
68     {HTTP_PROXY_AUTH_REQD , "Proxy Authentication Required"},
69     {HTTP_REQUEST_TIMEOUT , "Request Timeout"},
70     {HTTP_CONFLICT , "Conflict"},
71     {HTTP_GONE , "Gone"},
72     {HTTP_LENGTH_REQUIRED , "Length Required"},
73     {HTTP_PRECONDITION_FAILED , "Precondition Failed"},
74     {HTTP_REQ_ENTITY_TOO_LARGE , "Request Entity Too Large"},
75     {HTTP_REQ_URI_TOO_LONG , "Request-URI Too Long"},
76     {HTTP_UNSUPPORTED_MEDIA_TYPE, "Unsupported Media Type"},
77     {HTTP_REQUEST_RANGE_NOT_SATISFIABLE, "Requested Range Not Satisfiable"},
78     {HTTP_EXPECTATION_FAILED, "Expectation Failed"},
79     {HTTP_INTERNAL_SERVER_ERROR , "Internal Server Error"},
80     {HTTP_NOT_IMPLEMENTED , "Not Implemented"},
81     {HTTP_BAD_GATEWAY , "Bad Gateway"},
82     {HTTP_SERVICE_UNAVAILABLE , "Service Unavailable"},
83     {HTTP_GATEWAY_TIMEOUT , "Gateway Timeout"},
84     {HTTP_HTTP_VERSION_NOT_SUPPORTED , "HTTP Version Not Supported"},
85     {HTTP_VARIANT_ALSO_NEGOTIATES , "Variant Also Negotiates"},
86     {HTTP_INSUFFICIENT_STORAGE , "Insufficient Storage"},
87     {HTTP_LOOP_DETECTED , "Loop Detected"},
88     {HTTP_NOT_EXTENDED , "Not Extended"},
89     };
90 
91 /************************************************************************
92  * Function: http_get_code_text
93  *
94  * Parameters:
95  * int statusCode ; Status code based on which the status table and
96  * status message is returned
97  *
98  * Description: Return the right status message based on the passed in
99  * int statusCode input parameter
100  *
101  * Returns:
102  * const char* ptr - pointer to the status message string
103  ************************************************************************/
http_get_code_text(int statusCode)104 const char *http_get_code_text(int statusCode)
105 {
106     const auto it = httpcodes.find(statusCode);
107     return it == httpcodes.end() ? "" : it->second.c_str();
108 }
109