http_common.h File Reference

Definitions common to HTTP client and server. More...

#include "core/net.h"

Go to the source code of this file.

Data Structures

struct  HttpParam
 Attribute-value pair. More...
 

Macros

#define HTTP_PORT   80
 
#define HTTPS_PORT   443
 
#define HTTP_STATUS_CODE_1YZ(code)   ((code) >= 100 && (code) < 200)
 
#define HTTP_STATUS_CODE_2YZ(code)   ((code) >= 200 && (code) < 300)
 
#define HTTP_STATUS_CODE_3YZ(code)   ((code) >= 300 && (code) < 400)
 
#define HTTP_STATUS_CODE_4YZ(code)   ((code) >= 400 && (code) < 500)
 
#define HTTP_STATUS_CODE_5YZ(code)   ((code) >= 500 && (code) < 600)
 

Enumerations

enum  HttpVersion { HTTP_VERSION_0_9 = 0x0009, HTTP_VERSION_1_0 = 0x0100, HTTP_VERSION_1_1 = 0x0101 }
 HTTP version numbers. More...
 
enum  HttpAuthMode { HTTP_AUTH_MODE_NONE = 0, HTTP_AUTH_MODE_BASIC = 1, HTTP_AUTH_MODE_DIGEST = 2 }
 HTTP authentication schemes. More...
 
enum  HttpAuthQop { HTTP_AUTH_QOP_NONE = 0, HTTP_AUTH_QOP_AUTH = 1, HTTP_AUTH_QOP_AUTH_INT = 2 }
 Quality of protection (digest authentication) More...
 
enum  HttpFlags {
  HTTP_FLAG_WAIT_ALL = 0x0800, HTTP_FLAG_BREAK_CHAR = 0x1000, HTTP_FLAG_BREAK_CRLF = 0x100A, HTTP_FLAG_NO_DELAY = 0x4000,
  HTTP_FLAG_DELAY = 0x8000
}
 Flags used by I/O functions. More...
 
enum  HttpRequestState {
  HTTP_REQ_STATE_INIT = 0, HTTP_REQ_STATE_FORMAT_HEADER = 1, HTTP_REQ_STATE_SEND_HEADER = 2, HTTP_REQ_STATE_SEND_BODY = 3,
  HTTP_REQ_STATE_SEND_CHUNK_SIZE = 4, HTTP_REQ_STATE_SEND_CHUNK_DATA = 5, HTTP_REQ_STATE_FORMAT_TRAILER = 6, HTTP_REQ_STATE_SEND_TRAILER = 7,
  HTTP_REQ_STATE_RECEIVE_STATUS_LINE = 8, HTTP_REQ_STATE_RECEIVE_HEADER = 9, HTTP_REQ_STATE_PARSE_HEADER = 10, HTTP_REQ_STATE_RECEIVE_BODY = 11,
  HTTP_REQ_STATE_RECEIVE_CHUNK_SIZE = 12, HTTP_REQ_STATE_RECEIVE_CHUNK_DATA = 13, HTTP_REQ_STATE_RECEIVE_TRAILER = 14, HTTP_REQ_STATE_PARSE_TRAILER = 15,
  HTTP_REQ_STATE_COMPLETE = 16
}
 HTTP request states. More...
 
enum  HttpCharset {
  HTTP_CHARSET_OCTET = 0x0001, HTTP_CHARSET_CTL = 0x0002, HTTP_CHARSET_LWS = 0x0004, HTTP_CHARSET_ALPHA = 0x0008,
  HTTP_CHARSET_DIGIT = 0x0010, HTTP_CHARSET_HEX = 0x0020, HTTP_CHARSET_VCHAR = 0x0040, HTTP_CHARSET_TCHAR = 0x0080,
  HTTP_CHARSET_TEXT = 0x0100, HTTP_CHARSET_OBS_TEXT = 0x0200
}
 HTTP character sets. More...
 

Functions

error_t httpCheckCharset (const char_t *s, size_t length, uint_t charset)
 Check whether a string contains valid characters. More...
 
error_t httpParseParam (const char_t **pos, HttpParam *param)
 Parse a list of parameters. More...
 
bool_t httpCompareParamName (const HttpParam *param, const char_t *name)
 Compare parameter name with the supplied string. More...
 
bool_t httpCompareParamValue (const HttpParam *param, const char_t *value)
 Compare parameter name with the supplied string. More...
 
error_t httpCopyParamValue (const HttpParam *param, char_t *value, size_t maxLen)
 Copy the value of a parameter. More...
 
void httpEncodeHexString (const uint8_t *input, size_t inputLen, char_t *output)
 Convert byte array to hex string. More...
 

Detailed Description

Definitions common to HTTP client and server.

License

SPDX-License-Identifier: GPL-2.0-or-later

Copyright (C) 2010-2019 Oryx Embedded SARL. All rights reserved.

This file is part of CycloneTCP Open.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Author
Oryx Embedded SARL (www.oryx-embedded.com)
Version
1.9.4

Definition in file http_common.h.

Macro Definition Documentation

◆ HTTP_PORT

#define HTTP_PORT   80

Definition at line 38 of file http_common.h.

◆ HTTP_STATUS_CODE_1YZ

#define HTTP_STATUS_CODE_1YZ (   code)    ((code) >= 100 && (code) < 200)

Definition at line 43 of file http_common.h.

◆ HTTP_STATUS_CODE_2YZ

#define HTTP_STATUS_CODE_2YZ (   code)    ((code) >= 200 && (code) < 300)

Definition at line 44 of file http_common.h.

◆ HTTP_STATUS_CODE_3YZ

#define HTTP_STATUS_CODE_3YZ (   code)    ((code) >= 300 && (code) < 400)

Definition at line 45 of file http_common.h.

◆ HTTP_STATUS_CODE_4YZ

#define HTTP_STATUS_CODE_4YZ (   code)    ((code) >= 400 && (code) < 500)

Definition at line 46 of file http_common.h.

◆ HTTP_STATUS_CODE_5YZ

#define HTTP_STATUS_CODE_5YZ (   code)    ((code) >= 500 && (code) < 600)

Definition at line 47 of file http_common.h.

◆ HTTPS_PORT

#define HTTPS_PORT   443

Definition at line 40 of file http_common.h.

Enumeration Type Documentation

◆ HttpAuthMode

HTTP authentication schemes.

Enumerator
HTTP_AUTH_MODE_NONE 
HTTP_AUTH_MODE_BASIC 
HTTP_AUTH_MODE_DIGEST 

Definition at line 71 of file http_common.h.

◆ HttpAuthQop

Quality of protection (digest authentication)

Enumerator
HTTP_AUTH_QOP_NONE 
HTTP_AUTH_QOP_AUTH 
HTTP_AUTH_QOP_AUTH_INT 

Definition at line 83 of file http_common.h.

◆ HttpCharset

HTTP character sets.

Enumerator
HTTP_CHARSET_OCTET 
HTTP_CHARSET_CTL 
HTTP_CHARSET_LWS 
HTTP_CHARSET_ALPHA 
HTTP_CHARSET_DIGIT 
HTTP_CHARSET_HEX 
HTTP_CHARSET_VCHAR 
HTTP_CHARSET_TCHAR 
HTTP_CHARSET_TEXT 
HTTP_CHARSET_OBS_TEXT 

Definition at line 135 of file http_common.h.

◆ HttpFlags

enum HttpFlags

Flags used by I/O functions.

Enumerator
HTTP_FLAG_WAIT_ALL 
HTTP_FLAG_BREAK_CHAR 
HTTP_FLAG_BREAK_CRLF 
HTTP_FLAG_NO_DELAY 
HTTP_FLAG_DELAY 

Definition at line 95 of file http_common.h.

◆ HttpRequestState

HTTP request states.

Enumerator
HTTP_REQ_STATE_INIT 
HTTP_REQ_STATE_FORMAT_HEADER 
HTTP_REQ_STATE_SEND_HEADER 
HTTP_REQ_STATE_SEND_BODY 
HTTP_REQ_STATE_SEND_CHUNK_SIZE 
HTTP_REQ_STATE_SEND_CHUNK_DATA 
HTTP_REQ_STATE_FORMAT_TRAILER 
HTTP_REQ_STATE_SEND_TRAILER 
HTTP_REQ_STATE_RECEIVE_STATUS_LINE 
HTTP_REQ_STATE_RECEIVE_HEADER 
HTTP_REQ_STATE_PARSE_HEADER 
HTTP_REQ_STATE_RECEIVE_BODY 
HTTP_REQ_STATE_RECEIVE_CHUNK_SIZE 
HTTP_REQ_STATE_RECEIVE_CHUNK_DATA 
HTTP_REQ_STATE_RECEIVE_TRAILER 
HTTP_REQ_STATE_PARSE_TRAILER 
HTTP_REQ_STATE_COMPLETE 

Definition at line 109 of file http_common.h.

◆ HttpVersion

HTTP version numbers.

Enumerator
HTTP_VERSION_0_9 
HTTP_VERSION_1_0 
HTTP_VERSION_1_1 

Definition at line 59 of file http_common.h.

Function Documentation

◆ httpCheckCharset()

error_t httpCheckCharset ( const char_t s,
size_t  length,
uint_t  charset 
)

Check whether a string contains valid characters.

Parameters
[in]sPointer to the string
[in]lengthLength of the string
[in]charsetAcceptable charset
Returns
Error code

Definition at line 49 of file http_common.c.

◆ httpCompareParamName()

bool_t httpCompareParamName ( const HttpParam param,
const char_t name 
)

Compare parameter name with the supplied string.

Parameters
[in]paramPointer to the parameter
[in]nameNULL-terminated string
Returns
Comparison result

Definition at line 368 of file http_common.c.

◆ httpCompareParamValue()

bool_t httpCompareParamValue ( const HttpParam param,
const char_t value 
)

Compare parameter name with the supplied string.

Parameters
[in]paramPointer to the parameter
[in]valueNULL-terminated string
Returns
Comparison result

Definition at line 401 of file http_common.c.

◆ httpCopyParamValue()

error_t httpCopyParamValue ( const HttpParam param,
char_t value,
size_t  maxLen 
)

Copy the value of a parameter.

Parameters
[in]paramPointer to the parameter
[out]valuePointer to the buffer where to copy the parameter value
[out]maxLenMaximum number of characters the buffer can hold
Returns
Error code

Definition at line 435 of file http_common.c.

◆ httpEncodeHexString()

void httpEncodeHexString ( const uint8_t *  input,
size_t  inputLen,
char_t output 
)

Convert byte array to hex string.

Parameters
[in]inputPoint to the byte array
[in]inputLenLength of the byte array
[out]outputNULL-terminated string resulting from the conversion
Returns
Error code

Definition at line 476 of file http_common.c.

◆ httpParseParam()

error_t httpParseParam ( const char_t **  pos,
HttpParam param 
)

Parse a list of parameters.

Parameters
[in,out]posActual position if the list of parameters
[out]paramStructure that contains the parameter name and value
Returns
Error code

Definition at line 117 of file http_common.c.