eyBuildLib API Reference : eyBuildLib
ebmultiform - process http multipart/form-data method
addPostItem( ) - insert item name and limit the max size of value
getPostItemValue( ) - get post item value by item name
getPostFileCount( ) - get the number of files uploaded
getPostSrcFileName( ) - get source file name by index from post
getPostTempFileName( ) - get temporary file by index from post
movePostFile( ) - move post file by index to specified directory
createPostParam( ) - create a struct to hold post parameters
distoryPostParam( ) - free post parameters
installPostHook( ) - install hooks and cookie to this post
dopost( ) - read post data and parse it
distoryPost( ) - free this post
This module read post data (multipart/form-data only) and parse each part and store into file-list and item-list. Later user can get each part in post by call getPostItemValue( ), getPostSrcFileName( ), getPostFileCount( ), movePostFile( ) and so on.
User can limit this post actions by call createPostParam( ), setPostItem( ). setPostItem( ) is to insert an post item and limit the max size of items value. If you don't call it in advance, dopost( ) will call it and set to default size (256Bytes).
At last user should free those list by call distoryPostParam( ) or distoryPost( ). Note, you should not call distoryPostParam( ) after call distoryPost( ).
ebmultiform.h
ebpost.h, itemlist.h
addPostItem( ) - insert item name and limit the max size of value
int addPostItem ( POST_PARAM * p_param, /* where set to */ const char * name, /* item name */ int max_size /* max size of value may be returned */ )
this routine is to insert an item before post done it, we can limit the max size of value of the item by parameter max_size. if we don't call addPostItem( ), while dopost( ) find a new one it will insert that and limit the max size 256 bytes.
OK/ERROR
getPostItemValue( ) - get post item value by item name
char * getPostItemValue ( THIS_POST * p_post, /* where get from */ const char * name /* name of item */ )
this routine is to get post item value by item name
pointer to item value, or NULL if no such item
getPostFileCount( ) - get the number of files uploaded
int getPostFileCount ( THIS_POST * p_post /* where get from */ )
this routine is get the number of files uploaded
get the number of files uploaded
getPostSrcFileName( ) - get source file name by index from post
char * getPostSrcFileName ( THIS_POST * p_post, /* where get from */ int index /* index in file list */ )
this routine return the file name remote user posted by index, the index should less than the retuned value by getPostFileCount( ).
pointer to the filename, or NULL if index is out of range
getPostTempFileName( ) - get temporary file by index from post
char * getPostTempFileName ( THIS_POST * p_post, /* where get from */ int index /* index in file list */ )
this routine return the temporary file remote user posted by index, the index should less than the retuned value by getPostFileCount( ).
pointer to the filename, or NULL if index is out of range
movePostFile( ) - move post file by index to specified directory
int movePostFile ( THIS_POST * p_post, /* where get from */ int index, /* index in file list */ char * copyto /* where copy to, path or filename */ )
this routine move post file by index to specified directory, the index should less than the retuned value by getPostFileCount( ).
if you given only file path in copyto (eg: ../upload/), this routine will append file name the same as uploaded, othersize will be rename as specified by copyto, eg:
movePostFile(p_post, index, "../upload/"); movePostFile(p_post, index, "../upload/xx.doc");
this routine will try to replace the exist file
OK if success, othersize a none zero will be returned.
createPostParam( ) - create a struct to hold post parameters
POST_PARAM * createPostParam ( int max_post_size, /* max post size */ int file_max_size, /* max size each file */ int max_file_number, /* max file may uploads */ const char * upload_tmp_dir, /* where to store temp */ int options /* other options */ )
this routine create a struct to hold those parameters, if less or equal zero or NULL, it will be set to default value, as:
max_post_size 2M file_max_size 1M max_file_number 1 upload_tmp_dir system temp directory options NONE
pointer to this parameter struct, or NULL if lack memory
distoryPostParam( ) - free post parameters
void distoryPostParam ( POST_PARAM * p_param )
this route is to free post parameters. if distoryPost( ) is called, this routine will be called by it.
you should not call this after call distoryPost( )
NONE
installPostHook( ) - install hooks and cookie to this post
int installPostHook ( POST_PARAM * p_param, /* where store to */ FUNC_ON_DOHEADER on_header, /* user hook */ FUNC_ON_DODATA on_data, /* user hook */ FUNC_ON_DOEND on_end, /* user hook */ void * cookie /* user data struct */ )
this routine is to install user hooks and cookie to this post. when parse each post-part-header will call on_header( ), if the value hooks on_header( ) returned:
a. < 0 - return error b. > 0 - user hooks (on_body(), on_end()) will done this part c. = 0 - user hooks (on_body(), on_end()) will give up done this part
OK/ERROR
dopost( ) - read post data and parse it
THIS_POST * dopost ( POST_PARAM * p_param, /* page post prameters */ char * errmsg /* to return error */ )
this routine read post data and parse it, store the result into file-list and item-list and return a handle pointer to it.
we can limit item max size by call addPostItem( ) before call this routine. if we don't limit the size, system will limit the item with default size EB_ITEM_DEFAULT_SIZE (include tail '\0')
encode type (ENCTYPE) must be multipart/form-data.
pointer to the relust parsed, or NULL if error
distoryPost( ) - free this post
void distoryPost ( THIS_POST * p_post, /* current post */ BOOL blremove /* remove files in temp_dir or not */ )
this routine will free all the file-list and item list, it will also call distoryPostParam( ) to free the post parameter.
NONE