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-2024 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 2.4.0
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,
63  HTTP_VERSION_1_1 = 0x0101
65 
66 
67 /**
68  * @brief HTTP authentication schemes
69  **/
70 
71 typedef enum
72 {
77 
78 
79 /**
80  * @brief Quality of protection (digest authentication)
81  **/
82 
83 typedef enum
84 {
89 
90 
91 /**
92  * @brief Flags used by I/O functions
93  **/
94 
95 typedef enum
96 {
101  HTTP_FLAG_DELAY = 0x8000
103 
104 
105 /**
106  * @brief HTTP request states
107  */
108 
109 typedef enum
110 {
131 
132 
133 /**
134  * @brief HTTP character sets
135  */
136 
137 typedef enum
138 {
148  HTTP_CHARSET_OBS_TEXT = 0x0200
150 
151 
152 /**
153  * @brief Attribute-value pair
154  **/
155 
156 typedef struct
157 {
158  const char_t *name;
159  size_t nameLen;
160  const char_t *value;
161  size_t valueLen;
162 } HttpParam;
163 
164 
165 //HTTP related functions
166 error_t httpCheckCharset(const char_t *s, size_t length, uint_t charset);
167 
168 error_t httpParseParam(const char_t **pos, HttpParam *param);
169 bool_t httpCompareParamName(const HttpParam *param, const char_t *name);
170 bool_t httpCompareParamValue(const HttpParam *param, const char_t *value);
171 
173  size_t maxLen);
174 
175 void httpEncodeHexString(const uint8_t *input, size_t inputLen, char_t *output);
176 
177 //C++ guard
178 #ifdef __cplusplus
179 }
180 #endif
181 
182 #endif
unsigned int uint_t
Definition: compiler_port.h:50
char char_t
Definition: compiler_port.h:48
int bool_t
Definition: compiler_port.h:53
error_t
Error codes.
Definition: error.h:43
error_t httpParseParam(const char_t **pos, HttpParam *param)
Parse a list of parameters.
Definition: http_common.c:117
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
void httpEncodeHexString(const uint8_t *input, size_t inputLen, char_t *output)
Convert byte array to hex string.
Definition: http_common.c:475
HttpRequestState
HTTP request states.
Definition: http_common.h:110
@ HTTP_REQ_STATE_SEND_CHUNK_SIZE
Definition: http_common.h:116
@ HTTP_REQ_STATE_INIT
Definition: http_common.h:111
@ HTTP_REQ_STATE_FORMAT_HEADER
Definition: http_common.h:112
@ HTTP_REQ_STATE_PARSE_BODY
Definition: http_common.h:126
@ HTTP_REQ_STATE_RECEIVE_HEADER
Definition: http_common.h:121
@ HTTP_REQ_STATE_SEND_BODY
Definition: http_common.h:115
@ HTTP_REQ_STATE_FORMAT_TRAILER
Definition: http_common.h:118
@ HTTP_REQ_STATE_SEND_HEADER
Definition: http_common.h:113
@ HTTP_REQ_STATE_PARSE_TRAILER
Definition: http_common.h:128
@ HTTP_REQ_STATE_FORMAT_BODY
Definition: http_common.h:114
@ HTTP_REQ_STATE_RECEIVE_CHUNK_SIZE
Definition: http_common.h:124
@ HTTP_REQ_STATE_RECEIVE_BODY
Definition: http_common.h:123
@ HTTP_REQ_STATE_RECEIVE_TRAILER
Definition: http_common.h:127
@ HTTP_REQ_STATE_SEND_TRAILER
Definition: http_common.h:119
@ HTTP_REQ_STATE_RECEIVE_CHUNK_DATA
Definition: http_common.h:125
@ HTTP_REQ_STATE_SEND_CHUNK_DATA
Definition: http_common.h:117
@ HTTP_REQ_STATE_COMPLETE
Definition: http_common.h:129
@ HTTP_REQ_STATE_RECEIVE_STATUS_LINE
Definition: http_common.h:120
@ HTTP_REQ_STATE_PARSE_HEADER
Definition: http_common.h:122
bool_t httpCompareParamValue(const HttpParam *param, const char_t *value)
Compare parameter name with the supplied string.
Definition: http_common.c:401
bool_t httpCompareParamName(const HttpParam *param, const char_t *name)
Compare parameter name with the supplied string.
Definition: http_common.c:368
error_t httpCopyParamValue(const HttpParam *param, char_t *value, size_t maxLen)
Copy the value of a parameter.
Definition: http_common.c:435
HttpFlags
Flags used by I/O functions.
Definition: http_common.h:96
@ HTTP_FLAG_NO_DELAY
Definition: http_common.h:100
@ HTTP_FLAG_BREAK_CHAR
Definition: http_common.h:98
@ HTTP_FLAG_WAIT_ALL
Definition: http_common.h:97
@ HTTP_FLAG_BREAK_CRLF
Definition: http_common.h:99
@ HTTP_FLAG_DELAY
Definition: http_common.h:101
HttpCharset
HTTP character sets.
Definition: http_common.h:138
@ HTTP_CHARSET_HEX
Definition: http_common.h:144
@ HTTP_CHARSET_CTL
Definition: http_common.h:140
@ HTTP_CHARSET_OCTET
Definition: http_common.h:139
@ HTTP_CHARSET_TCHAR
Definition: http_common.h:146
@ HTTP_CHARSET_DIGIT
Definition: http_common.h:143
@ HTTP_CHARSET_ALPHA
Definition: http_common.h:142
@ HTTP_CHARSET_LWS
Definition: http_common.h:141
@ HTTP_CHARSET_OBS_TEXT
Definition: http_common.h:148
@ HTTP_CHARSET_TEXT
Definition: http_common.h:147
@ HTTP_CHARSET_VCHAR
Definition: http_common.h:145
HttpVersion
HTTP version numbers.
Definition: http_common.h:60
@ HTTP_VERSION_1_0
Definition: http_common.h:62
@ HTTP_VERSION_0_9
Definition: http_common.h:61
@ HTTP_VERSION_1_1
Definition: http_common.h:63
HttpAuthMode
HTTP authentication schemes.
Definition: http_common.h:72
@ HTTP_AUTH_MODE_DIGEST
Definition: http_common.h:75
@ HTTP_AUTH_MODE_NONE
Definition: http_common.h:73
@ HTTP_AUTH_MODE_BASIC
Definition: http_common.h:74
HttpAuthQop
Quality of protection (digest authentication)
Definition: http_common.h:84
@ HTTP_AUTH_QOP_NONE
Definition: http_common.h:85
@ HTTP_AUTH_QOP_AUTH_INT
Definition: http_common.h:87
@ HTTP_AUTH_QOP_AUTH
Definition: http_common.h:86
uint8_t s
Definition: ndp.h:345
TCP/IP stack core.
char_t name[]
Attribute-value pair.
Definition: http_common.h:157
const char_t * value
Definition: http_common.h:160
const char_t * name
Definition: http_common.h:158
size_t nameLen
Definition: http_common.h:159
size_t valueLen
Definition: http_common.h:161
uint8_t length
Definition: tcp.h:368
uint8_t value[]
Definition: tcp.h:369