http_common.h
Go to the documentation of this file.
1 /**
2  * @file http_common.h
3  * @brief Definitions common to HTTP client and server
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2019 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneTCP Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 1.9.2
29  **/
30 
31 #ifndef _HTTP_COMMON_H
32 #define _HTTP_COMMON_H
33 
34 //Dependencies
35 #include "core/net.h"
36 
37 //HTTP port number
38 #define HTTP_PORT 80
39 //HTTPS port number (HTTP over TLS)
40 #define HTTPS_PORT 443
41 
42 //Test macros for HTTP status codes
43 #define HTTP_STATUS_CODE_1YZ(code) ((code) >= 100 && (code) < 200)
44 #define HTTP_STATUS_CODE_2YZ(code) ((code) >= 200 && (code) < 300)
45 #define HTTP_STATUS_CODE_3YZ(code) ((code) >= 300 && (code) < 400)
46 #define HTTP_STATUS_CODE_4YZ(code) ((code) >= 400 && (code) < 500)
47 #define HTTP_STATUS_CODE_5YZ(code) ((code) >= 500 && (code) < 600)
48 
49 //C++ guard
50 #ifdef __cplusplus
51  extern "C" {
52 #endif
53 
54 
55 /**
56  * @brief HTTP version numbers
57  **/
58 
59 typedef enum
60 {
61  HTTP_VERSION_0_9 = 0x0009,
62  HTTP_VERSION_1_0 = 0x0100,
64 } HttpVersion;
65 
66 
67 /**
68  * @brief HTTP authentication schemes
69  **/
70 
71 typedef enum
72 {
76 } HttpAuthMode;
77 
78 
79 /**
80  * @brief Quality of protection (digest authentication)
81  **/
82 
83 typedef enum
84 {
88 } HttpAuthQop;
89 
90 
91 /**
92  * @brief Flags used by I/O functions
93  **/
94 
95 typedef enum
96 {
102 } HttpFlags;
103 
104 
105 /**
106  * @brief HTTP request states
107  */
108 
109 typedef enum
110 {
129 
130 
131 /**
132  * @brief HTTP character sets
133  */
134 
135 typedef enum
136 {
147 } HttpCharset;
148 
149 
150 /**
151  * @brief Attribute-value pair
152  **/
153 
154 typedef struct
155 {
156  const char_t *name;
157  size_t nameLen;
158  const char_t *value;
159  size_t valueLen;
160 } HttpParam;
161 
162 
163 //HTTP related functions
164 error_t httpCheckCharset(const char_t *s, size_t length, uint_t charset);
165 
166 error_t httpParseParam(const char_t **pos, HttpParam *param);
167 bool_t httpCompareParamName(const HttpParam *param, const char_t *name);
168 bool_t httpCompareParamValue(const HttpParam *param, const char_t *value);
169 
171  size_t maxLen);
172 
173 void httpEncodeHexString(const uint8_t *input, size_t inputLen, char_t *output);
174 
175 //C++ guard
176 #ifdef __cplusplus
177  }
178 #endif
179 
180 #endif
bool_t httpCompareParamName(const HttpParam *param, const char_t *name)
Compare parameter name with the supplied string.
Definition: http_common.c:368
const char_t * value
Definition: http_common.h:158
error_t httpParseParam(const char_t **pos, HttpParam *param)
Parse a list of parameters.
Definition: http_common.c:117
char char_t
Definition: compiler_port.h:43
TCP/IP stack core.
void httpEncodeHexString(const uint8_t *input, size_t inputLen, char_t *output)
Convert byte array to hex string.
Definition: http_common.c:476
size_t nameLen
Definition: http_common.h:157
HttpRequestState
HTTP request states.
Definition: http_common.h:109
HttpAuthMode
HTTP authentication schemes.
Definition: http_common.h:71
HttpAuthQop
Quality of protection (digest authentication)
Definition: http_common.h:83
size_t valueLen
Definition: http_common.h:159
HttpFlags
Flags used by I/O functions.
Definition: http_common.h:95
const char_t * name
Definition: http_common.h:156
error_t httpCheckCharset(const char_t *s, size_t length, uint_t charset)
Check whether a string contains valid characters.
Definition: http_common.c:49
bool_t httpCompareParamValue(const HttpParam *param, const char_t *value)
Compare parameter name with the supplied string.
Definition: http_common.c:401
Attribute-value pair.
Definition: http_common.h:154
char_t name[]
error_t
Error codes.
Definition: error.h:42
unsigned int uint_t
Definition: compiler_port.h:45
HttpVersion
HTTP version numbers.
Definition: http_common.h:59
uint8_t value[]
Definition: dtls_misc.h:143
error_t httpCopyParamValue(const HttpParam *param, char_t *value, size_t maxLen)
Copy the value of a parameter.
Definition: http_common.c:435
HttpCharset
HTTP character sets.
Definition: http_common.h:135
uint8_t length
Definition: dtls_misc.h:142
int bool_t
Definition: compiler_port.h:49