eyBuildLib API Reference : eyBuildLib

ebmultiform

NAME

ebmultiform - process http multipart/form-data method

ROUTINES

addPostItem( ) - insert item name and limit the max size of value
getPostItemValue( ) - get post item value by item name
getPostFileCount( ) - get the number of post items
getPostItemValue( ) - get post item value of same-name-item by index
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

DESCRIPTION

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( ).

This library is base on RFC1867, RFC2046, RFC2388.

INCLUDE

ebmultiform.h

SEE ALSO

ebpost.h, itemlist.h


eyBuildLib : Routines

addPostItem( )

NAME

addPostItem( ) - insert item name and limit the max size of value

SYNOPSIS

int addPostItem
    (
    POST_PARAM * p_param,     /* where set to */
    const char * name,        /* item name */
    int          max_size     /* max size of value may be returned */
    )

DESCRIPTION

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.

RETURNS

OK/ERROR

SEE ALSO

ebmultiform


eyBuildLib : Routines

getPostItemValue( )

NAME

getPostItemValue( ) - get post item value by item name

SYNOPSIS

char * getPostItemValue
    (
    THIS_POST *  p_post,      /* where get from */
    const char * name         /* name of item */
    )

DESCRIPTION

This routine is to get post item value by item name

RETURNS

pointer to item value, or NULL if no such item

SEE ALSO

ebmultiform


eyBuildLib : Routines

getPostFileCount( )

NAME

getPostFileCount( ) - get the number of post items

SYNOPSIS

int getPostItemCount
    (
    THIS_POST * p_post        /* where get from */
    )

DESCRIPTION

This routine is get the number of post items, exclude the post files.

RETURNS

the number of post items.

SEE ALSO

ebmultiform


eyBuildLib : Routines

getPostItemValue( )

NAME

getPostItemValue( ) - get post item value of same-name-item by index

SYNOPSIS

char * getPostItemValueByNameIndex
    (
    THIS_POST *  p_post,      /* where get from */
    const char * name,        /* name of item */
    int          index
    )

DESCRIPTION

This routine is to get post item value of same-name-item by index.

RETURNS

pointer to item value, or NULL if no such item

SEE ALSO

ebmultiform


eyBuildLib : Routines

getPostFileCount( )

NAME

getPostFileCount( ) - get the number of files uploaded

SYNOPSIS

int getPostFileCount
    (
    THIS_POST * p_post        /* where get from */
    )

DESCRIPTION

This routine is get the number of files uploaded

RETURNS

get the number of files uploaded

SEE ALSO

ebmultiform


eyBuildLib : Routines

getPostSrcFileName( )

NAME

getPostSrcFileName( ) - get source file name by index from post

SYNOPSIS

char * getPostSrcFileName
    (
    THIS_POST * p_post,       /* where get from */
    int         index         /* index in file list */
    )

DESCRIPTION

This routine return the file name remote user posted by index, the index should less than the retuned value by getPostFileCount( ).

RETURNS

pointer to the filename, or NULL if index is out of range

SEE ALSO

ebmultiform


eyBuildLib : Routines

getPostTempFileName( )

NAME

getPostTempFileName( ) - get temporary file by index from post

SYNOPSIS

char * getPostTempFileName
    (
    THIS_POST * p_post,       /* where get from */
    int         index         /* index in file list */
    )

DESCRIPTION

This routine return the temporary file remote user posted by index, the index should less than the retuned value by getPostFileCount( ).

RETURNS

pointer to the filename, or NULL if index is out of range

SEE ALSO

ebmultiform


eyBuildLib : Routines

movePostFile( )

NAME

movePostFile( ) - move post file by index to specified directory

SYNOPSIS

int movePostFile
    (
    THIS_POST * p_post,       /* where get from */
    int         index,        /* index in file list */
    char *      copyto        /* where copy to, path or filename */
    )

DESCRIPTION

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");

NOTE

This routine will try to replace the exist file

RETURNS

OK if success, othersize a none zero will be returned.

SEE ALSO

ebmultiform


eyBuildLib : Routines

createPostParam( )

NAME

createPostParam( ) - create a struct to hold post parameters

SYNOPSIS

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 */
    )

DESCRIPTION

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

RETURNS

pointer to this parameter struct, or NULL if lack memory

SEE ALSO

ebmultiform


eyBuildLib : Routines

distoryPostParam( )

NAME

distoryPostParam( ) - free post parameters

SYNOPSIS

void distoryPostParam
    (
    POST_PARAM * p_param
    )

DESCRIPTION

this route is to free post parameters. if distoryPost( ) is called, this routine will be called by it.

NOTE

you should not call this after call distoryPost( )

RETURNS

NONE

SEE ALSO

ebmultiform


eyBuildLib : Routines

installPostHook( )

NAME

installPostHook( ) - install hooks and cookie to this post

SYNOPSIS

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 */
    )

DESCRIPTION

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

RETURNS

OK/ERROR

SEE ALSO

ebmultiform


eyBuildLib : Routines

dopost( )

NAME

dopost( ) - read post data and parse it

SYNOPSIS

THIS_POST * dopost
    (
    POST_PARAM * p_param,     /* page post prameters */
    char *       errmsg       /* to return error */
    )

DESCRIPTION

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')

NOTE

encode type (ENCTYPE) must be multipart/form-data.

RETURNS

pointer to the relust parsed, or NULL if error

SEE ALSO

ebmultiform


eyBuildLib : Routines

distoryPost( )

NAME

distoryPost( ) - free this post

SYNOPSIS

void distoryPost
    (
    THIS_POST * p_post,       /* current post */
    BOOL        blremove      /* remove files in temp_dir or not */
    )

DESCRIPTION

This routine will free all the file-list and item list, it will also call distoryPostParam( ) to free the post parameter.

RETURNS

NONE

SEE ALSO

ebmultiform