Add a new gctl_get_paraml_opt() interface to extract optional parameters from

the request.  It is the same as gctl_get_paraml() except that the request
is not marked with an error if the parameter is not present.

Approved by:	imp (mentor)
Reviewed by:	cem
Sponsored by:	Netflix
Differential Revision:	https://reviews.freebsd.org/D21972
This commit is contained in:
chs 2019-10-16 21:49:39 +00:00
parent f4dbe34c21
commit 8356d793be
2 changed files with 14 additions and 4 deletions

View File

@ -428,6 +428,7 @@ void gctl_set_param_err(struct gctl_req *req, const char *param, void const *ptr
void *gctl_get_param(struct gctl_req *req, const char *param, int *len); void *gctl_get_param(struct gctl_req *req, const char *param, int *len);
char const *gctl_get_asciiparam(struct gctl_req *req, const char *param); char const *gctl_get_asciiparam(struct gctl_req *req, const char *param);
void *gctl_get_paraml(struct gctl_req *req, const char *param, int len); void *gctl_get_paraml(struct gctl_req *req, const char *param, int len);
void *gctl_get_paraml_opt(struct gctl_req *req, const char *param, int len);
int gctl_error(struct gctl_req *req, const char *fmt, ...) __printflike(2, 3); int gctl_error(struct gctl_req *req, const char *fmt, ...) __printflike(2, 3);
struct g_class *gctl_get_class(struct gctl_req *req, char const *arg); struct g_class *gctl_get_class(struct gctl_req *req, char const *arg);
struct g_geom *gctl_get_geom(struct gctl_req *req, struct g_class *mpr, char const *arg); struct g_geom *gctl_get_geom(struct gctl_req *req, struct g_class *mpr, char const *arg);

View File

@ -365,21 +365,30 @@ gctl_get_asciiparam(struct gctl_req *req, const char *param)
} }
void * void *
gctl_get_paraml(struct gctl_req *req, const char *param, int len) gctl_get_paraml_opt(struct gctl_req *req, const char *param, int len)
{ {
int i; int i;
void *p; void *p;
p = gctl_get_param(req, param, &i); p = gctl_get_param(req, param, &i);
if (p == NULL) if (i != len) {
gctl_error(req, "Missing %s argument", param);
else if (i != len) {
p = NULL; p = NULL;
gctl_error(req, "Wrong length %s argument", param); gctl_error(req, "Wrong length %s argument", param);
} }
return (p); return (p);
} }
void *
gctl_get_paraml(struct gctl_req *req, const char *param, int len)
{
void *p;
p = gctl_get_paraml_opt(req, param, len);
if (p == NULL)
gctl_error(req, "Missing %s argument", param);
return (p);
}
struct g_class * struct g_class *
gctl_get_class(struct gctl_req *req, char const *arg) gctl_get_class(struct gctl_req *req, char const *arg)
{ {