http_server_misc.c File Reference

HTTP server (miscellaneous functions) More...

#include <limits.h>
#include "core/net.h"
#include "http/http_server.h"
#include "http/http_server_auth.h"
#include "http/http_server_misc.h"
#include "http/mime.h"
#include "str.h"
#include "path.h"
#include "debug.h"

Go to the source code of this file.

Macros

#define TRACE_LEVEL   HTTP_TRACE_LEVEL
 

Functions

error_t httpReadRequestHeader (HttpConnection *connection)
 Read HTTP request header and parse its contents. More...
 
error_t httpParseRequestLine (HttpConnection *connection, char_t *requestLine)
 Parse Request-Line. More...
 
error_t httpReadHeaderField (HttpConnection *connection, char_t *buffer, size_t size, char_t *firstChar)
 Read multiple-line header field. More...
 
void httpParseHeaderField (HttpConnection *connection, const char_t *name, char_t *value)
 Parse HTTP header field. More...
 
void httpParseConnectionField (HttpConnection *connection, char_t *value)
 Parse Connection header field. More...
 
void httpParseContentTypeField (HttpConnection *connection, char_t *value)
 Parse Content-Type header field. More...
 
void httpParseAcceptEncodingField (HttpConnection *connection, char_t *value)
 Parse Accept-Encoding header field. More...
 
void httpParseCookieField (HttpConnection *connection, char_t *value)
 Parse Cookie header field. More...
 
error_t httpReadChunkSize (HttpConnection *connection)
 Read chunk-size field from the input stream. More...
 
void httpInitResponseHeader (HttpConnection *connection)
 Initialize response header. More...
 
error_t httpFormatResponseHeader (HttpConnection *connection, char_t *buffer)
 Format HTTP response header. More...
 
error_t httpSend (HttpConnection *connection, const void *data, size_t length, uint_t flags)
 Send data to the client. More...
 
error_t httpReceive (HttpConnection *connection, void *data, size_t size, size_t *received, uint_t flags)
 Receive data from the client. More...
 
void httpGetAbsolutePath (HttpConnection *connection, const char_t *relative, char_t *absolute, size_t maxLen)
 Retrieve the full pathname to the specified resource. More...
 
bool_t httpCompExtension (const char_t *filename, const char_t *extension)
 Compare filename extension. More...
 
error_t httpDecodePercentEncodedString (const char_t *input, char_t *output, size_t outputSize)
 Decode a percent-encoded string. More...
 
void httpConvertArrayToHexString (const uint8_t *input, size_t inputLen, char_t *output)
 Convert byte array to hex string. More...
 

Detailed Description

HTTP server (miscellaneous functions)

License

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

Copyright (C) 2010-2024 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
2.4.4

Definition in file http_server_misc.c.

Macro Definition Documentation

◆ TRACE_LEVEL

#define TRACE_LEVEL   HTTP_TRACE_LEVEL

Definition at line 32 of file http_server_misc.c.

Function Documentation

◆ httpCompExtension()

bool_t httpCompExtension ( const char_t filename,
const char_t extension 
)

Compare filename extension.

Parameters
[in]filenameFilename whose extension is to be checked
[in]extensionString defining the extension to be checked
Returns
TRUE is the filename matches the given extension, else FALSE

Definition at line 1100 of file http_server_misc.c.

◆ httpConvertArrayToHexString()

void httpConvertArrayToHexString ( 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

Definition at line 1193 of file http_server_misc.c.

◆ httpDecodePercentEncodedString()

error_t httpDecodePercentEncodedString ( const char_t input,
char_t output,
size_t  outputSize 
)

Decode a percent-encoded string.

Parameters
[in]inputNULL-terminated string to be decoded
[out]outputNULL-terminated string resulting from the decoding process
[in]outputSizeSize of the output buffer in bytes
Returns
Error code

Definition at line 1134 of file http_server_misc.c.

◆ httpFormatResponseHeader()

error_t httpFormatResponseHeader ( HttpConnection connection,
char_t buffer 
)

Format HTTP response header.

Parameters
[in]connectionStructure representing an HTTP connection
[out]bufferPointer to the buffer where to format the HTTP header
Returns
Error code

Definition at line 778 of file http_server_misc.c.

◆ httpGetAbsolutePath()

void httpGetAbsolutePath ( HttpConnection connection,
const char_t relative,
char_t absolute,
size_t  maxLen 
)

Retrieve the full pathname to the specified resource.

Parameters
[in]connectionStructure representing an HTTP connection
[in]relativeString containing the relative path to the resource
[out]absoluteResulting string containing the absolute path
[in]maxLenMaximum acceptable path length

Definition at line 1079 of file http_server_misc.c.

◆ httpInitResponseHeader()

void httpInitResponseHeader ( HttpConnection connection)

Initialize response header.

Parameters
[in]connectionStructure representing an HTTP connection

Definition at line 745 of file http_server_misc.c.

◆ httpParseAcceptEncodingField()

void httpParseAcceptEncodingField ( HttpConnection connection,
char_t value 
)

Parse Accept-Encoding header field.

Parameters
[in]connectionStructure representing an HTTP connection
[in]valueAccept-Encoding field value

Definition at line 614 of file http_server_misc.c.

◆ httpParseConnectionField()

void httpParseConnectionField ( HttpConnection connection,
char_t value 
)

Parse Connection header field.

Parameters
[in]connectionStructure representing an HTTP connection
[in]valueConnection field value

Definition at line 499 of file http_server_misc.c.

◆ httpParseContentTypeField()

void httpParseContentTypeField ( HttpConnection connection,
char_t value 
)

Parse Content-Type header field.

Parameters
[in]connectionStructure representing an HTTP connection
[in]valueContent-Type field value

Definition at line 545 of file http_server_misc.c.

◆ httpParseCookieField()

void httpParseCookieField ( HttpConnection connection,
char_t value 
)

Parse Cookie header field.

Parameters
[in]connectionStructure representing an HTTP connection
[in]valueAccept-Encoding field value

Definition at line 650 of file http_server_misc.c.

◆ httpParseHeaderField()

void httpParseHeaderField ( HttpConnection connection,
const char_t name,
char_t value 
)

Parse HTTP header field.

Parameters
[in]connectionStructure representing an HTTP connection
[in]nameName of the header field
[in]valueValue of the header field

Definition at line 419 of file http_server_misc.c.

◆ httpParseRequestLine()

error_t httpParseRequestLine ( HttpConnection connection,
char_t requestLine 
)

Parse Request-Line.

Parameters
[in]connectionStructure representing an HTTP connection
[in]requestLinePointer to the string that holds the Request-Line
Returns
Error code

Definition at line 200 of file http_server_misc.c.

◆ httpReadChunkSize()

error_t httpReadChunkSize ( HttpConnection connection)

Read chunk-size field from the input stream.

Parameters
[in]connectionStructure representing an HTTP connection

Definition at line 664 of file http_server_misc.c.

◆ httpReadHeaderField()

error_t httpReadHeaderField ( HttpConnection connection,
char_t buffer,
size_t  size,
char_t firstChar 
)

Read multiple-line header field.

Parameters
[in]connectionStructure representing an HTTP connection
[out]bufferBuffer where to store the header field
[in]sizeSize of the buffer, in bytes
[in,out]firstCharLeading character of the header line
Returns
Error code

Definition at line 317 of file http_server_misc.c.

◆ httpReadRequestHeader()

error_t httpReadRequestHeader ( HttpConnection connection)

Read HTTP request header and parse its contents.

Parameters
[in]connectionStructure representing an HTTP connection
Returns
Error code

Definition at line 83 of file http_server_misc.c.

◆ httpReceive()

error_t httpReceive ( HttpConnection connection,
void *  data,
size_t  size,
size_t *  received,
uint_t  flags 
)

Receive data from the client.

Parameters
[in]connectionStructure representing an HTTP connection
[out]dataBuffer into which received data will be placed
[in]sizeMaximum number of bytes that can be received
[out]receivedActual number of bytes that have been received
[in]flagsSet of flags that influences the behavior of this function
Returns
Error code

Definition at line 995 of file http_server_misc.c.

◆ httpSend()

error_t httpSend ( HttpConnection connection,
const void *  data,
size_t  length,
uint_t  flags 
)

Send data to the client.

Parameters
[in]connectionStructure representing an HTTP connection
[in]dataPointer to a buffer containing the data to be transmitted
[in]lengthNumber of bytes to be transmitted
[in]flagsSet of flags that influences the behavior of this function

Definition at line 947 of file http_server_misc.c.