iPXE
Data Structures | Macros | 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...
 

Macros

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

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. More...
 
struct parametersfind_parameters (const char *name)
 Find form parameter list by name. More...
 
struct parameterscreate_parameters (const char *name)
 Create form parameter list. More...
 
struct parameteradd_parameter (struct parameters *params, const char *key, const char *value)
 Add form parameter. More...
 

Detailed Description

Form parameters.

Definition in file params.h.

Macro Definition Documentation

◆ for_each_param

#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.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ __attribute__()

static __attribute__ ( (always_inline)  )
inlinestatic

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.

44  {
45  ref_get ( &params->refcnt );
46  return params;
47 }
#define ref_get(refcnt)
Get additional reference to object.
Definition: refcnt.h:92

References ref_get, and parameters::refcnt.

◆ find_parameters()

struct parameters* find_parameters ( const char *  name)

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.

68  {
69  struct parameters *params;
70 
71  list_for_each_entry ( params, &parameters, list ) {
72  if ( ( params->name == name ) ||
73  ( strcmp ( params->name, name ) == 0 ) ) {
74  return params;
75  }
76  }
77  return NULL;
78 }
const char * name
Definition: ath9k_hw.c:1984
A form parameter list.
Definition: params.h:16
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:420
const char * name
Name.
Definition: params.h:22
struct list_head list
List of all parameter lists.
Definition: params.h:20
int strcmp(const char *first, const char *second)
Compare strings.
Definition: string.c:157
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

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

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

◆ create_parameters()

struct parameters* create_parameters ( const char *  name)

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.

86  {
87  struct parameters *params;
88  size_t name_len;
89  char *name_copy;
90 
91  /* Destroy any existing parameter list of this name */
92  params = find_parameters ( name );
93  if ( params ) {
94  claim_parameters ( params );
95  params_put ( params );
96  }
97 
98  /* Allocate parameter list */
99  name_len = ( name ? ( strlen ( name ) + 1 /* NUL */ ) : 0 );
100  params = zalloc ( sizeof ( *params ) + name_len );
101  if ( ! params )
102  return NULL;
103  ref_init ( &params->refcnt, free_parameters );
104  name_copy = ( ( void * ) ( params + 1 ) );
105 
106  /* Populate parameter list */
107  if ( name ) {
108  strcpy ( name_copy, name );
109  params->name = name_copy;
110  }
111  INIT_LIST_HEAD ( &params->entries );
112 
113  /* Add to list of parameter lists */
114  list_add_tail ( &params->list, &parameters );
115 
116  DBGC ( params, "PARAMS \"%s\" created\n", params->name );
117  return params;
118 }
const char * name
Definition: ath9k_hw.c:1984
static void free_parameters(struct refcnt *refcnt)
Free form parameter list.
Definition: params.c:44
#define ref_init(refcnt, free)
Initialise a reference counter.
Definition: refcnt.h:64
A form parameter list.
Definition: params.h:16
#define DBGC(...)
Definition: compiler.h:505
struct parameters * find_parameters(const char *name)
Find form parameter list by name.
Definition: params.c:68
struct refcnt refcnt
Reference count.
Definition: params.h:18
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
Definition: list.h:93
char * strcpy(char *dest, const char *src)
Copy string.
Definition: string.c:296
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
size_t strlen(const char *src)
Get length of string.
Definition: string.c:213
struct list_head entries
Parameters.
Definition: params.h:24
const char * name
Name.
Definition: params.h:22
struct list_head list
List of all parameter lists.
Definition: params.h:20
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition: list.h:45
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

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

Referenced by params_exec(), and uri_params_okx().

◆ add_parameter()

struct parameter* add_parameter ( struct parameters params,
const char *  key,
const char *  value 
)

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.

129  {
130  struct parameter *param;
131  size_t key_len;
132  size_t value_len;
133  char *key_copy;
134  char *value_copy;
135 
136  /* Allocate parameter */
137  key_len = ( strlen ( key ) + 1 /* NUL */ );
138  value_len = ( strlen ( value ) + 1 /* NUL */ );
139  param = zalloc ( sizeof ( *param ) + key_len + value_len );
140  if ( ! param )
141  return NULL;
142  key_copy = ( ( void * ) ( param + 1 ) );
143  value_copy = ( key_copy + key_len );
144 
145  /* Populate parameter */
146  strcpy ( key_copy, key );
147  param->key = key_copy;
148  strcpy ( value_copy, value );
149  param->value = value_copy;
150 
151  /* Add to list of parameters */
152  list_add_tail ( &param->list, &params->entries );
153 
154  DBGC ( params, "PARAMS \"%s\" added \"%s\"=\"%s\"\n",
155  params->name, param->key, param->value );
156  return param;
157 }
#define DBGC(...)
Definition: compiler.h:505
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
Definition: list.h:93
char * strcpy(char *dest, const char *src)
Copy string.
Definition: string.c:296
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
struct hv_monitor_parameter param[4][32]
Parameters.
Definition: hyperv.h:24
size_t strlen(const char *src)
Get length of string.
Definition: string.c:213
struct list_head entries
Parameters.
Definition: params.h:24
const char * name
Name.
Definition: params.h:22
A form parameter.
Definition: params.h:28
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
union @375 key
Sense key.
Definition: scsi.h:18

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

Referenced by param_exec(), and uri_params_okx().