iPXE
Data Structures | Defines | Functions
params.h File Reference

Form parameters. More...

#include <ipxe/list.h>
#include <ipxe/refcnt.h>

Go to the source code of this file.

Data Structures

struct  parameters
 A form parameter list. More...
struct  parameter
 A form parameter. More...

Defines

#define for_each_param(param, params)   list_for_each_entry ( (param), &(params)->entries, list )
 Iterate over all form parameters in a list.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
static __attribute__ ((always_inline)) struct parameters *params_get(struct parameters *params)
 Increment form parameter list reference count.
struct parametersfind_parameters (const char *name)
 Find form parameter list by name.
struct parameterscreate_parameters (const char *name)
 Create form parameter list.
struct parameteradd_parameter (struct parameters *params, const char *key, const char *value)
 Add form parameter.

Detailed Description

Form parameters.

Definition in file params.h.


Define Documentation

#define for_each_param (   param,
  params 
)    list_for_each_entry ( (param), &(params)->entries, list )

Iterate over all form parameters in a list.

Definition at line 75 of file params.h.

Referenced by http_params(), and uri_params_list_okx().


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
static __attribute__ ( (always_inline)  ) [inline, static]

Increment form parameter list reference count.

Claim ownership of form parameter list.

Decrement form parameter list reference count.

Parameters:
paramsParameter list, or NULL
Return values:
paramsParameter list as passed in
Parameters:
paramsParameter list, or NULL
paramsParameter list
Return values:
paramsParameter list

Definition at line 43 of file params.h.

References params, and ref_get.

                                         {
        ref_get ( &params->refcnt );
        return params;
}
struct parameters* find_parameters ( const char *  name) [read]

Find form parameter list by name.

Parameters:
nameParameter list name (may be NULL)
Return values:
paramsParameter list, or NULL if not found

Definition at line 68 of file params.c.

References parameters::list, list_for_each_entry, parameters::name, NULL, params, and strcmp().

Referenced by create_parameters(), parse_parameters(), and parse_uri().

                                                         {
        struct parameters *params;

        list_for_each_entry ( params, &parameters, list ) {
                if ( ( params->name == name ) ||
                     ( strcmp ( params->name, name ) == 0 ) ) {
                        return params;
                }
        }
        return NULL;
}
struct parameters* create_parameters ( const char *  name) [read]

Create form parameter list.

Parameters:
nameParameter list name (may be NULL)
Return values:
paramsParameter list, or NULL on failure

Definition at line 86 of file params.c.

References DBGC, parameters::entries, find_parameters(), free_parameters(), INIT_LIST_HEAD, parameters::list, list_add_tail, parameters::name, NULL, params, ref_init, parameters::refcnt, strcpy(), strlen(), and zalloc().

Referenced by params_exec(), and uri_params_okx().

                                                           {
        struct parameters *params;
        size_t name_len;
        char *name_copy;

        /* Destroy any existing parameter list of this name */
        params = find_parameters ( name );
        if ( params ) {
                claim_parameters ( params );
                params_put ( params );
        }

        /* Allocate parameter list */
        name_len = ( name ? ( strlen ( name ) + 1 /* NUL */ ) : 0 );
        params = zalloc ( sizeof ( *params ) + name_len );
        if ( ! params )
                return NULL;
        ref_init ( &params->refcnt, free_parameters );
        name_copy = ( ( void * ) ( params + 1 ) );

        /* Populate parameter list */
        if ( name ) {
                strcpy ( name_copy, name );
                params->name = name_copy;
        }
        INIT_LIST_HEAD ( &params->entries );

        /* Add to list of parameter lists */
        list_add_tail ( &params->list, &parameters );

        DBGC ( params, "PARAMS \"%s\" created\n", params->name );
        return params;
}
struct parameter* add_parameter ( struct parameters params,
const char *  key,
const char *  value 
) [read]

Add form parameter.

Parameters:
paramsParameter list
keyParameter key
valueParameter value
Return values:
paramParameter, or NULL on failure

Definition at line 128 of file params.c.

References DBGC, parameters::entries, parameter::key, parameter::list, list_add_tail, parameters::name, NULL, param, strcpy(), strlen(), parameter::value, and zalloc().

Referenced by param_exec(), and uri_params_okx().

                                                                        {
        struct parameter *param;
        size_t key_len;
        size_t value_len;
        char *key_copy;
        char *value_copy;

        /* Allocate parameter */
        key_len = ( strlen ( key ) + 1 /* NUL */ );
        value_len = ( strlen ( value ) + 1 /* NUL */ );
        param = zalloc ( sizeof ( *param ) + key_len + value_len );
        if ( ! param )
                return NULL;
        key_copy = ( ( void * ) ( param + 1 ) );
        value_copy = ( key_copy + key_len );

        /* Populate parameter */
        strcpy ( key_copy, key );
        param->key = key_copy;
        strcpy ( value_copy, value );
        param->value = value_copy;

        /* Add to list of parameters */
        list_add_tail ( &param->list, &params->entries );

        DBGC ( params, "PARAMS \"%s\" added \"%s\"=\"%s\"\n",
               params->name, param->key, param->value );
        return param;
}