GNU libmicrohttpd 1.0.0
Loading...
Searching...
No Matches
postprocessor.c File Reference

Methods for parsing POST data. More...

#include "postprocessor.h"
#include "internal.h"
#include "mhd_str.h"
#include "mhd_compat.h"
#include "mhd_assert.h"
Include dependency graph for postprocessor.c:

Go to the source code of this file.

Macros

#define XBUF_SIZE   512
 

Functions

_MHD_EXTERN struct MHD_PostProcessorMHD_create_post_processor (struct MHD_Connection *connection, size_t buffer_size, MHD_PostDataIterator iter, void *iter_cls)
 
static void process_value (struct MHD_PostProcessor *pp, const char *value_start, const char *value_end, const char *last_escape)
 
static enum MHD_Result post_process_urlencoded (struct MHD_PostProcessor *pp, const char *post_data, size_t post_data_len)
 
static int try_match_header (const char *prefix, size_t prefix_len, char *line, char **suffix)
 
static int find_boundary (struct MHD_PostProcessor *pp, const char *boundary, size_t blen, size_t *ioffptr, enum PP_State next_state, enum PP_State next_dash_state)
 
static void try_get_value (const char *buf, const char *key, char **destination)
 
static int process_multipart_headers (struct MHD_PostProcessor *pp, size_t *ioffptr, enum PP_State next_state)
 
static int process_value_to_boundary (struct MHD_PostProcessor *pp, size_t *ioffptr, const char *boundary, size_t blen, enum PP_State next_state, enum PP_State next_dash_state)
 
static void free_unmarked (struct MHD_PostProcessor *pp)
 
static enum MHD_Result post_process_multipart (struct MHD_PostProcessor *pp, const char *post_data, size_t post_data_len)
 
_MHD_EXTERN enum MHD_Result MHD_post_process (struct MHD_PostProcessor *pp, const char *post_data, size_t post_data_len)
 
_MHD_EXTERN enum MHD_Result MHD_destroy_post_processor (struct MHD_PostProcessor *pp)
 

Detailed Description

Methods for parsing POST data.

Author
Christian Grothoff
Karlson2k (Evgeny Grin)

Definition in file postprocessor.c.

Macro Definition Documentation

◆ XBUF_SIZE

#define XBUF_SIZE   512

Size of on-stack buffer that we use for un-escaping of the value. We use a pretty small value to be nice to the stack on embedded systems.

Definition at line 39 of file postprocessor.c.

Referenced by process_value().

Function Documentation

◆ find_boundary()

static int find_boundary ( struct MHD_PostProcessor * pp,
const char * boundary,
size_t blen,
size_t * ioffptr,
enum PP_State next_state,
enum PP_State next_dash_state )
static
Parameters
pppost processor context
boundaryboundary to look for
blennumber of bytes in boundary
ioffptrset to the end of the boundary if found, otherwise incremented by one (FIXME: quirky API!)
next_statestate to which we should advance the post processor if the boundary is found
next_dash_statedash_state to which we should advance the post processor if the boundary is found
Returns
MHD_NO if the boundary is not found, MHD_YES if we did find it

Definition at line 626 of file postprocessor.c.

References MHD_PostProcessor::blen, MHD_PostProcessor::boundary, MHD_PostProcessor::buffer_pos, MHD_PostProcessor::buffer_size, MHD_PostProcessor::dash_state, MHD_NO, MHD_YES, NULL, PP_Error, PP_Init, RN_Dash, MHD_PostProcessor::skip_rn, and MHD_PostProcessor::state.

Referenced by post_process_multipart().

Here is the caller graph for this function:

◆ free_unmarked()

◆ post_process_multipart()

static enum MHD_Result post_process_multipart ( struct MHD_PostProcessor * pp,
const char * post_data,
size_t post_data_len )
static

Decode multipart POST data.

Parameters
pppost processor context
post_datadata to decode
post_data_lennumber of bytes in post_data
Returns
MHD_NO on error,

Per RFC2046 5.1.1 NOTE TO IMPLEMENTORS, consume anything prior to the first multipart boundary:

‍There appears to be room for additional information prior to the first boundary delimiter line and following the final boundary delimiter line. These areas should generally be left blank, and implementations must ignore anything that appears before the first boundary delimiter line or after the last one.

Definition at line 957 of file postprocessor.c.

References _, MHD_PostProcessor::blen, MHD_PostProcessor::boundary, MHD_PostProcessor::buffer_pos, MHD_PostProcessor::buffer_size, MHD_PostProcessor::content_filename, MHD_PostProcessor::content_name, MHD_PostProcessor::content_transfer_encoding, MHD_PostProcessor::content_type, MHD_PostProcessor::dash_state, find_boundary(), free_unmarked(), MHD_PostProcessor::have, MHD_NO, MHD_PANIC, MHD_STATICSTR_LEN_, MHD_str_equal_caseless_n_(), MHD_YES, MHD_PostProcessor::must_ikvi, NE_content_filename, NE_content_name, NE_content_transfer_encoding, NE_content_type, NE_none, MHD_PostProcessor::nested_boundary, MHD_PostProcessor::nlen, NULL, PP_Callback, PP_Done, PP_Error, PP_Init, PP_Nested_Init, PP_Nested_PerformCleanup, PP_Nested_PerformMarking, PP_Nested_ProcessEntryHeaders, PP_Nested_ProcessValueToBoundary, PP_NextBoundary, PP_PerformCheckMultipart, PP_PerformCleanup, PP_ProcessEntryHeaders, PP_ProcessKey, PP_ProcessValue, PP_ProcessValueToBoundary, process_multipart_headers(), process_value_to_boundary(), RN_Dash, RN_Dash2, RN_Full, RN_Inactive, RN_OptN, MHD_PostProcessor::skip_rn, MHD_PostProcessor::state, and MHD_PostProcessor::value_offset.

Referenced by MHD_post_process().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ post_process_urlencoded()

static enum MHD_Result post_process_urlencoded ( struct MHD_PostProcessor * pp,
const char * post_data,
size_t post_data_len )
static

◆ process_multipart_headers()

static int process_multipart_headers ( struct MHD_PostProcessor * pp,
size_t * ioffptr,
enum PP_State next_state )
static

Go over the headers of the part and update the fields in "pp" according to what we find. If we are at the end of the headers (as indicated by an empty line), transition into next_state.

Parameters
pppost processor context
ioffptrset to how many bytes have been processed
next_statestate to which the post processor should be advanced if we find the end of the headers
Returns
MHD_YES if we can continue processing, MHD_NO on error or if we do not have enough data yet

Definition at line 745 of file postprocessor.c.

References MHD_PostProcessor::buffer_pos, MHD_PostProcessor::buffer_size, MHD_PostProcessor::content_filename, MHD_PostProcessor::content_name, MHD_PostProcessor::content_transfer_encoding, MHD_PostProcessor::content_type, MHD_NO, MHD_STATICSTR_LEN_, MHD_str_equal_caseless_n_(), MHD_YES, PP_Error, RN_Full, RN_OptN, MHD_PostProcessor::skip_rn, MHD_PostProcessor::state, try_get_value(), and try_match_header().

Referenced by post_process_multipart().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_value()

static void process_value ( struct MHD_PostProcessor * pp,
const char * value_start,
const char * value_end,
const char * last_escape )
static

Give a (possibly partial) value to the application callback. We have some part of the value in the 'pp->xbuf', the rest is between value_start and value_end. If last_escape is non-NULL, there may be an incomplete escape sequence at at value_escape between value_start and value_end which we should preserve in 'pp->xbuf' for the future.

Unescapes the value and calls the iterator together with the key. The key must already be in the key buffer allocated and 0-terminated at the end of pp at the time of the call.

Parameters
[in,out]pppost processor to act upon
value_startwhere in memory is the value
value_endwhere does the value end
last_escapelast ''-sign in value range, if relevant, or NULL

Definition at line 137 of file postprocessor.c.

References MHD_PostProcessor::cls, MHD_PostProcessor::ikvi, mhd_assert, MHD_http_unescape(), MHD_NO, MHD_POSTDATA_KIND, MHD_unescape_plus(), MHD_PostProcessor::must_ikvi, NULL, PP_Error, MHD_PostProcessor::value_offset, MHD_PostProcessor::xbuf, MHD_PostProcessor::xbuf_pos, and XBUF_SIZE.

Referenced by post_process_urlencoded().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_value_to_boundary()

static int process_value_to_boundary ( struct MHD_PostProcessor * pp,
size_t * ioffptr,
const char * boundary,
size_t blen,
enum PP_State next_state,
enum PP_State next_dash_state )
static

We have the value until we hit the given boundary; process accordingly.

Parameters
pppost processor context
ioffptrincremented based on the number of bytes processed
boundarythe boundary to look for
blenstrlen(boundary)
next_statewhat state to go into after the boundary was found
next_dash_statestate to go into if the next boundary ends with "--"
Returns
MHD_YES if we can continue processing, MHD_NO on error or if we do not have enough data yet

Definition at line 819 of file postprocessor.c.

References MHD_PostProcessor::blen, MHD_PostProcessor::boundary, MHD_PostProcessor::buffer_pos, MHD_PostProcessor::buffer_size, MHD_PostProcessor::cls, MHD_PostProcessor::content_filename, MHD_PostProcessor::content_name, MHD_PostProcessor::content_transfer_encoding, MHD_PostProcessor::content_type, MHD_PostProcessor::dash_state, MHD_PostProcessor::ikvi, MHD_NO, MHD_POSTDATA_KIND, MHD_YES, MHD_PostProcessor::must_ikvi, NULL, PP_Error, RN_Dash, MHD_PostProcessor::skip_rn, MHD_PostProcessor::state, and MHD_PostProcessor::value_offset.

Referenced by post_process_multipart().

Here is the caller graph for this function:

◆ try_get_value()

static void try_get_value ( const char * buf,
const char * key,
char ** destination )
static

In buf, there maybe an expression '$key="$value"'. If that is the case, copy a copy of $value to destination.

If destination is already non-NULL, do nothing.

Definition at line 687 of file postprocessor.c.

References NULL.

Referenced by process_multipart_headers().

Here is the caller graph for this function:

◆ try_match_header()

static int try_match_header ( const char * prefix,
size_t prefix_len,
char * line,
char ** suffix )
static

If the given line matches the prefix, strdup the rest of the line into the suffix ptr.

Parameters
prefixprefix to match
prefix_lenlength of prefix
lineline to match prefix in
suffixset to a copy of the rest of the line, starting at the end of the match
Returns
MHD_YES if there was a match, MHD_NO if not

Definition at line 590 of file postprocessor.c.

References MHD_NO, MHD_str_equal_caseless_n_(), MHD_YES, and NULL.

Referenced by process_multipart_headers().

Here is the call graph for this function:
Here is the caller graph for this function: