iPXE
Functions
params.c File Reference

Form parameters. More...

#include <stdlib.h>
#include <string.h>
#include <ipxe/params.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
static LIST_HEAD (parameters)
 List of all parameter lists.
static void free_parameters (struct refcnt *refcnt)
 Free form parameter list.
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.c.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
static LIST_HEAD ( parameters  ) [static]

List of all parameter lists.

static void free_parameters ( struct refcnt refcnt) [static]

Free form parameter list.

Parameters:
refcntReference count

Definition at line 44 of file params.c.

References container_of, DBGC, parameters::entries, free, parameter::list, list_del, list_for_each_entry_safe, parameters::name, param, and params.

Referenced by create_parameters().

                                                      {
        struct parameters *params =
                container_of ( refcnt, struct parameters, refcnt );
        struct parameter *param;
        struct parameter *tmp;

        DBGC ( params, "PARAMS \"%s\" destroyed\n", params->name );

        /* Free all parameters */
        list_for_each_entry_safe ( param, tmp, &params->entries, list ) {
                list_del ( &param->list );
                free ( param );
        }

        /* Free parameter list */
        free ( 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;
}