iPXE
Data Structures | Functions | Variables
param_cmd.c File Reference

Request parameter commands. More...

#include <stdlib.h>
#include <errno.h>
#include <getopt.h>
#include <ipxe/params.h>
#include <ipxe/parseopt.h>
#include <ipxe/command.h>

Go to the source code of this file.

Data Structures

struct  params_options
 "params" options More...
 
struct  param_options
 "param" options More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static int params_exec (int argc, char **argv)
 The "params" command. More...
 
static int param_exec (int argc, char **argv)
 The "param" command. More...
 

Variables

static struct option_descriptor params_opts []
 "params" option list More...
 
static struct command_descriptor params_cmd
 "params" command descriptor More...
 
static struct option_descriptor param_opts []
 "param" option list More...
 
static struct command_descriptor param_cmd
 "param" command descriptor More...
 
struct command param_commands [] __command
 Request parameter commands. More...
 

Detailed Description

Request parameter commands.

Definition in file param_cmd.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ params_exec()

static int params_exec ( int  argc,
char **  argv 
)
static

The "params" command.

Parameters
argcArgument count
argvArgument list
Return values
rcReturn status code

Definition at line 66 of file param_cmd.c.

66  {
67  struct params_options opts;
68  struct parameters *params;
69  int rc;
70 
71  /* Parse options */
72  if ( ( rc = parse_options ( argc, argv, &params_cmd, &opts ) ) != 0)
73  return rc;
74 
75  /* Create parameter list */
76  params = create_parameters ( opts.name );
77  if ( ! params )
78  return -ENOMEM;
79 
80  /* Destroy parameter list, if applicable */
81  if ( opts.delete ) {
82  claim_parameters ( params );
83  params_put ( params );
84  }
85 
86  return 0;
87 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
A request parameter list.
Definition: params.h:16
int parse_options(int argc, char **argv, struct command_descriptor *cmd, void *opts)
Parse command-line options.
Definition: parseopt.c:447
#define ENOMEM
Not enough space.
Definition: errno.h:534
"params" options
Definition: param_cmd.c:40
struct parameters * create_parameters(const char *name)
Create request parameter list.
Definition: params.c:86
static union @432 opts
"cert<xxx>" option list
static struct command_descriptor params_cmd
"params" command descriptor
Definition: param_cmd.c:56

References create_parameters(), ENOMEM, opts, params_cmd, parse_options(), and rc.

◆ param_exec()

static int param_exec ( int  argc,
char **  argv 
)
static

The "param" command.

Parameters
argcArgument count
argvArgument list
Return values
rcReturn status code

Definition at line 117 of file param_cmd.c.

117  {
118  struct param_options opts;
119  char *key;
120  char *value;
121  unsigned int flags;
122  struct parameters *params;
123  struct parameter *param;
124  int rc;
125 
126  /* Parse options */
127  if ( ( rc = parse_options ( argc, argv, &param_cmd, &opts ) ) != 0 )
128  goto err_parse_options;
129 
130  /* Parse key */
131  key = argv[optind];
132 
133  /* Parse value */
134  value = concat_args ( &argv[ optind + 1 ] );
135  if ( ! value ) {
136  rc = -ENOMEM;
137  goto err_parse_value;
138  }
139 
140  /* Construct flags */
141  flags = ( opts.header ? PARAMETER_HEADER : PARAMETER_FORM );
142 
143  /* Identify parameter list */
144  if ( ( rc = parse_parameters ( opts.params, &params ) ) != 0 )
145  goto err_parse_parameters;
146 
147  /* Add parameter */
148  param = add_parameter ( params, key, value, flags );
149  if ( ! param ) {
150  rc = -ENOMEM;
151  goto err_add_parameter;
152  }
153 
154  /* Success */
155  rc = 0;
156 
157  err_add_parameter:
158  err_parse_parameters:
159  free ( value );
160  err_parse_value:
161  err_parse_options:
162  return rc;
163 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int optind
Current option index.
Definition: getopt.c:51
A request parameter list.
Definition: params.h:16
int parse_options(int argc, char **argv, struct command_descriptor *cmd, void *opts)
Parse command-line options.
Definition: parseopt.c:447
#define ENOMEM
Not enough space.
Definition: errno.h:534
char * concat_args(char **args)
Concatenate arguments.
Definition: exec.c:358
"param" options
Definition: param_cmd.c:90
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
int parse_parameters(char *text, struct parameters **params)
Parse request parameter list name.
Definition: parseopt.c:311
struct hv_monitor_parameter param[4][32]
Parameters.
Definition: hyperv.h:24
#define PARAMETER_FORM
Request parameter is a form parameter.
Definition: params.h:40
static struct command_descriptor param_cmd
"param" command descriptor
Definition: param_cmd.c:106
static union @432 opts
"cert<xxx>" option list
A request parameter.
Definition: params.h:28
struct parameter * add_parameter(struct parameters *params, const char *key, const char *value, unsigned int flags)
Add request parameter.
Definition: params.c:129
#define PARAMETER_HEADER
Request parameter is a header parameter.
Definition: params.h:43
union @382 key
Sense key.
Definition: scsi.h:18
uint8_t flags
Flags.
Definition: ena.h:18

References add_parameter(), concat_args(), ENOMEM, flags, free, key, optind, opts, param, param_cmd, PARAMETER_FORM, PARAMETER_HEADER, parse_options(), parse_parameters(), rc, and value.

Variable Documentation

◆ params_opts

struct option_descriptor params_opts[]
static
Initial value:
= {
OPTION_DESC ( "delete", 'd', no_argument,
struct params_options, delete, parse_flag ),
}
const char * name
Definition: ath9k_hw.c:1984
int parse_string(char *text, char **value)
Parse string value.
Definition: parseopt.c:70
"params" options
Definition: param_cmd.c:40
int parse_flag(char *text __unused, int *flag)
Parse flag.
Definition: parseopt.c:200
Option does not take an argument.
Definition: getopt.h:16
#define OPTION_DESC(_longopt, _shortopt, _has_arg, _struct, _field, _parse)
Construct option descriptor.
Definition: parseopt.h:66
Option requires an argument.
Definition: getopt.h:18

"params" option list

Definition at line 48 of file param_cmd.c.

◆ params_cmd

struct command_descriptor params_cmd
static
Initial value:
=
static struct option_descriptor params_opts[]
"params" option list
Definition: param_cmd.c:48
"params" options
Definition: param_cmd.c:40
#define COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage)
Construct command descriptor.
Definition: parseopt.h:107
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

"params" command descriptor

Definition at line 56 of file param_cmd.c.

Referenced by params_exec().

◆ param_opts

struct option_descriptor param_opts[]
static
Initial value:
= {
OPTION_DESC ( "params", 'p', required_argument,
struct param_options, params, parse_string ),
OPTION_DESC ( "header", 'H', no_argument,
}
int parse_string(char *text, char **value)
Parse string value.
Definition: parseopt.c:70
"param" options
Definition: param_cmd.c:90
int parse_flag(char *text __unused, int *flag)
Parse flag.
Definition: parseopt.c:200
Option does not take an argument.
Definition: getopt.h:16
#define OPTION_DESC(_longopt, _shortopt, _has_arg, _struct, _field, _parse)
Construct option descriptor.
Definition: parseopt.h:66
Option requires an argument.
Definition: getopt.h:18
struct ena_aq_header header
Header.
Definition: ena.h:12

"param" option list

Definition at line 98 of file param_cmd.c.

◆ param_cmd

struct command_descriptor param_cmd
static
Initial value:
=
"<key> [<value>]" )
#define MAX_ARGUMENTS
No maximum number of arguments.
Definition: parseopt.h:96
"param" options
Definition: param_cmd.c:90
#define COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage)
Construct command descriptor.
Definition: parseopt.h:107
static struct option_descriptor param_opts[]
"param" option list
Definition: param_cmd.c:98

"param" command descriptor

Definition at line 106 of file param_cmd.c.

Referenced by param_exec().

◆ __command

struct command param_commands [] __command
Initial value:
= {
{
.name = "params",
.exec = params_exec,
},
{
.name = "param",
.exec = param_exec,
},
}
static int param_exec(int argc, char **argv)
The "param" command.
Definition: param_cmd.c:117
static int params_exec(int argc, char **argv)
The "params" command.
Definition: param_cmd.c:66

Request parameter commands.

Definition at line 166 of file param_cmd.c.