postprocessor.c File Reference

Methods for parsing POST data. More...

#include "internal.h"

Include dependency graph for postprocessor.c:

Go to the source code of this file.

Defines

#define XBUF_SIZE   1024

Enumerations

enum  PP_State {
  PP_Error, PP_Done, PP_Init, PP_ProcessValue,
  PP_ExpectNewLine, PP_ProcessEntryHeaders, PP_PerformCheckMultipart, PP_ProcessValueToBoundary,
  PP_PerformCleanup, PP_Nested_Init, PP_Nested_PerformMarking, PP_Nested_ProcessEntryHeaders,
  PP_Nested_ProcessValueToBoundary, PP_Nested_PerformCleanup
}
enum  RN_State {
  RN_Inactive = 0, RN_OptN = 1, RN_Full = 2, RN_Dash = 3,
  RN_Dash2 = 4
}
enum  NE_State {
  NE_none = 0, NE_content_name = 1, NE_content_type = 2, NE_content_filename = 4,
  NE_content_transfer_encoding = 8
}

Functions

struct MHD_PostProcessor * MHD_create_post_processor (struct MHD_Connection *connection, size_t buffer_size, MHD_PostDataIterator ikvi, void *cls)
static int post_process_urlencoded (struct MHD_PostProcessor *pp, const char *post_data, size_t post_data_len)
static int try_match_header (const char *prefix, 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 int post_process_multipart (struct MHD_PostProcessor *pp, const char *post_data, size_t post_data_len)
int MHD_post_process (struct MHD_PostProcessor *pp, const char *post_data, size_t post_data_len)
int MHD_destroy_post_processor (struct MHD_PostProcessor *pp)


Detailed Description

Methods for parsing POST data.

Author:
Christian Grothoff

Definition in file postprocessor.c.


Define Documentation

#define XBUF_SIZE   1024

Size of on-stack buffer that we use for un-escaping of the value.

Definition at line 31 of file postprocessor.c.

Referenced by post_process_urlencoded().


Enumeration Type Documentation

enum NE_State

Bits for the globally known fields that should not be deleted when we exit the nested state.

Enumerator:
NE_none 
NE_content_name 
NE_content_type 
NE_content_filename 
NE_content_transfer_encoding 

Definition at line 98 of file postprocessor.c.

enum PP_State

States in the PP parser's state machine.

Enumerator:
PP_Error 
PP_Done 
PP_Init 
PP_ProcessValue 
PP_ExpectNewLine 
PP_ProcessEntryHeaders 
PP_PerformCheckMultipart 
PP_ProcessValueToBoundary 
PP_PerformCleanup 
PP_Nested_Init 
PP_Nested_PerformMarking 
PP_Nested_ProcessEntryHeaders 
PP_Nested_ProcessValueToBoundary 
PP_Nested_PerformCleanup 

Definition at line 36 of file postprocessor.c.

enum RN_State

Enumerator:
RN_Inactive  No RN-preprocessing in this state.
RN_OptN  If the next character is '
', skip it. Otherwise, just go inactive.
RN_Full  Expect '
' (and only '
'). As always, we also expect only '' or only '
'.
RN_Dash  Expect either '
' or '--
'. If '--
', transition into dash-state for the main state machine
RN_Dash2  Got a single dash, expect second dash.

Definition at line 62 of file postprocessor.c.


Function Documentation

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]

Definition at line 473 of file postprocessor.c.

References MHD_NO, MHD_YES, PP_Error, and RN_Dash.

Referenced by post_process_multipart().

Here is the caller graph for this function:

static void free_unmarked ( struct MHD_PostProcessor *  pp  )  [static]

Definition at line 689 of file postprocessor.c.

References NE_content_filename, NE_content_name, NE_content_transfer_encoding, and NE_content_type.

Referenced by MHD_destroy_post_processor(), and post_process_multipart().

Here is the caller graph for this function:

struct MHD_PostProcessor* MHD_create_post_processor ( struct MHD_Connection connection,
size_t  buffer_size,
MHD_PostDataIterator  ikvi,
void *  cls 
) [read]

Create a PostProcessor.

A PostProcessor can be used to (incrementally) parse the data portion of a POST request.

Parameters:
connection the connection on which the POST is happening (used to determine the POST format)
buffer_size maximum number of bytes to use for internal buffering (used only for the parsing, specifically the parsing of the keys). A tiny value (256-1024) should be sufficient. Do NOT use 0.
ikvi iterator to be called with the parsed data
cls first argument to ikvi
Returns:
NULL on error (out of memory, unsupported encoding), otherwise a PP handle

Definition at line 249 of file postprocessor.c.

References MHD_HEADER_KIND, MHD_HTTP_HEADER_CONTENT_TYPE, MHD_HTTP_POST_ENCODING_FORM_URLENCODED, MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA, MHD_lookup_connection_value(), PP_Init, and RN_Inactive.

Referenced by test_simple_large().

Here is the call graph for this function:

Here is the caller graph for this function:

int MHD_destroy_post_processor ( struct MHD_PostProcessor *  pp  ) 

Release PostProcessor resources.

Definition at line 1025 of file postprocessor.c.

References free_unmarked(), MHD_NO, MHD_YES, NE_none, and PP_Done.

Referenced by test_simple_large().

Here is the call graph for this function:

Here is the caller graph for this function:

int MHD_post_process ( struct MHD_PostProcessor *  pp,
const char *  post_data,
size_t  post_data_len 
)

Parse and process POST data. Call this function when POST data is available (usually during an MHD_AccessHandlerCallback) with the upload_data and upload_data_size. Whenever possible, this will then cause calls to the MHD_IncrementalKeyValueIterator.

Parameters:
pp the post processor
post_data post_data_len bytes of POST data
post_data_len length of post_data
Returns:
MHD_YES on success, MHD_NO on error (out-of-memory, iterator aborted, parse error)

Definition at line 1003 of file postprocessor.c.

References MHD_HTTP_POST_ENCODING_FORM_URLENCODED, MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA, MHD_NO, MHD_YES, post_process_multipart(), and post_process_urlencoded().

Referenced by test_simple_large().

Here is the call graph for this function:

Here is the caller graph for this function:

static int post_process_multipart ( struct MHD_PostProcessor *  pp,
const char *  post_data,
size_t  post_data_len 
) [static]

static int post_process_urlencoded ( struct MHD_PostProcessor *  pp,
const char *  post_data,
size_t  post_data_len 
) [static]

Process url-encoded POST data.

Definition at line 306 of file postprocessor.c.

References MHD_http_unescape(), MHD_NO, MHD_POSTDATA_KIND, MHD_YES, PP_Done, PP_Error, PP_ExpectNewLine, PP_Init, PP_ProcessValue, and XBUF_SIZE.

Referenced by MHD_post_process().

Here is the call graph for this function:

Here is the caller graph for this function:

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:
ioffptr set to how many bytes have been processed
Returns:
MHD_YES if we can continue processing, MHD_NO on error or if we do not have enough data yet

Definition at line 557 of file postprocessor.c.

References MHD_NO, MHD_YES, PP_Error, RN_Full, RN_OptN, 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:

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:
boundary the boundary to look for
blen strlen(boundary)
next_state what state to go into after the boundary was found
next_dash_state state 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 618 of file postprocessor.c.

References MHD_NO, MHD_POSTDATA_KIND, MHD_YES, PP_Error, and RN_Dash.

Referenced by post_process_multipart().

Here is the caller graph for this function:

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 510 of file postprocessor.c.

Referenced by process_multipart_headers().

Here is the caller graph for this function:

static int try_match_header ( const char *  prefix,
char *  line,
char **  suffix 
) [static]

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

Returns:
MHD_YES if there was a match, MHD_NO if not

Definition at line 456 of file postprocessor.c.

References MHD_NO, and MHD_YES.

Referenced by process_multipart_headers().

Here is the caller graph for this function:


Generated on Sun Jul 26 17:23:26 2009 for GNU libmicrohttpd by  doxygen 1.5.9