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

Request parameters. More...

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

Go to the source code of this file.

Data Structures

struct  parameters
 A request parameter list. More...
 
struct  parameter
 A request parameter. More...
 

Macros

#define PARAMETER_FORM   0x0001
 Request parameter is a form parameter. More...
 
#define PARAMETER_HEADER   0x0002
 Request parameter is a header parameter. More...
 
#define for_each_param(param, params)   list_for_each_entry ( (param), &(params)->entries, list )
 Iterate over all request 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 request parameter list reference count. More...
 
struct parametersfind_parameters (const char *name)
 Find request parameter list by name. More...
 
struct parameterscreate_parameters (const char *name)
 Create request parameter list. More...
 
struct parameteradd_parameter (struct parameters *params, const char *key, const char *value, unsigned int flags)
 Add request parameter. More...
 

Detailed Description

Request parameters.

Definition in file params.h.

Macro Definition Documentation

◆ PARAMETER_FORM

#define PARAMETER_FORM   0x0001

Request parameter is a form parameter.

Definition at line 40 of file params.h.

◆ PARAMETER_HEADER

#define PARAMETER_HEADER   0x0002

Request parameter is a header parameter.

Definition at line 43 of file params.h.

◆ for_each_param

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

Iterate over all request parameters in a list.

Definition at line 83 of file params.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ __attribute__()

static __attribute__ ( (always_inline)  )
inlinestatic

Increment request parameter list reference count.

Claim ownership of request parameter list.

Decrement request 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 51 of file params.h.

52  {
53  ref_get ( &params->refcnt );
54  return params;
55 }
#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 request 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 request parameter list.
Definition: params.h:16
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:431
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:173
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

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 request 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 request parameter list.
Definition: params.c:44
#define ref_init(refcnt, free)
Initialise a reference counter.
Definition: refcnt.h:64
A request parameter list.
Definition: params.h:16
#define DBGC(...)
Definition: compiler.h:505
struct parameters * find_parameters(const char *name)
Find request 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:346
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:243
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:321

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,
unsigned int  flags 
)

Add request parameter.

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

Definition at line 129 of file params.c.

131  {
132  struct parameter *param;
133  size_t key_len;
134  size_t value_len;
135  char *key_copy;
136  char *value_copy;
137 
138  /* Allocate parameter */
139  key_len = ( strlen ( key ) + 1 /* NUL */ );
140  value_len = ( strlen ( value ) + 1 /* NUL */ );
141  param = zalloc ( sizeof ( *param ) + key_len + value_len );
142  if ( ! param )
143  return NULL;
144  key_copy = ( ( void * ) ( param + 1 ) );
145  value_copy = ( key_copy + key_len );
146 
147  /* Populate parameter */
148  strcpy ( key_copy, key );
149  param->key = key_copy;
150  strcpy ( value_copy, value );
151  param->value = value_copy;
152  param->flags = flags;
153 
154  /* Add to list of parameters */
155  list_add_tail ( &param->list, &params->entries );
156 
157  DBGC ( params, "PARAMS \"%s\" added \"%s\"=\"%s\"%s%s\n",
158  params->name, param->key, param->value,
159  ( ( param->flags & PARAMETER_FORM ) ? " (form)" : "" ),
160  ( ( param->flags & PARAMETER_HEADER ) ? " (header)" : "" ) );
161  return param;
162 }
#define DBGC(...)
Definition: compiler.h:505
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
#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:346
uint8_t flags
Flags.
Definition: ena.h:18
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:243
struct list_head entries
Parameters.
Definition: params.h:24
const char * name
Name.
Definition: params.h:22
#define PARAMETER_FORM
Request parameter is a form parameter.
Definition: params.h:40
A request parameter.
Definition: params.h:28
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
#define PARAMETER_HEADER
Request parameter is a header parameter.
Definition: params.h:43
union @383 key
Sense key.
Definition: scsi.h:18

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

Referenced by param_exec(), and uri_params_okx().