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. More...
 
static void free_parameters (struct refcnt *refcnt)
 Free form parameter list. 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.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ LIST_HEAD()

static LIST_HEAD ( parameters  )
static

List of all parameter lists.

◆ free_parameters()

static void free_parameters ( struct refcnt refcnt)
static

Free form parameter list.

Parameters
refcntReference count

Definition at line 44 of file params.c.

44  {
45  struct parameters *params =
46  container_of ( refcnt, struct parameters, refcnt );
47  struct parameter *param;
48  struct parameter *tmp;
49 
50  DBGC ( params, "PARAMS \"%s\" destroyed\n", params->name );
51 
52  /* Free all parameters */
54  list_del ( &param->list );
55  free ( param );
56  }
57 
58  /* Free parameter list */
59  free ( params );
60 }
A form parameter list.
Definition: params.h:16
#define DBGC(...)
Definition: compiler.h:505
A reference counter.
Definition: refcnt.h:26
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
#define list_for_each_entry_safe(pos, tmp, head, member)
Iterate over entries in a list, safe against deletion of the current entry.
Definition: list.h:447
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
struct hv_monitor_parameter param[4][32]
Parameters.
Definition: hyperv.h:24
uint8_t * tmp
Definition: entropy.h:156
struct list_head entries
Parameters.
Definition: params.h:24
struct list_head list
List of form parameters.
Definition: params.h:30
const char * name
Name.
Definition: params.h:22
A form parameter.
Definition: params.h:28

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

Referenced by create_parameters().

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