mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-06 15:17:01 +02:00
MINOR: guid: define guid_is_valid_fmt()
Extract GUID format validation in a dedicated function named guid_is_valid_fmt(). For the moment, it is only used on guid_insert(). This will be reused when parsing stats-file, to ensure GUID has a valid format before tree lookup.
This commit is contained in:
parent
bc3c117dc0
commit
83731c8048
@ -10,6 +10,7 @@ int guid_insert(enum obj_type *obj_type, const char *uid, char **errmsg);
|
|||||||
void guid_remove(struct guid_node *guid);
|
void guid_remove(struct guid_node *guid);
|
||||||
struct guid_node *guid_lookup(const char *uid);
|
struct guid_node *guid_lookup(const char *uid);
|
||||||
|
|
||||||
|
int guid_is_valid_fmt(const char *uid, char **errmsg);
|
||||||
char *guid_name(const struct guid_node *guid);
|
char *guid_name(const struct guid_node *guid);
|
||||||
|
|
||||||
#endif /* _HAPROXY_GUID_H */
|
#endif /* _HAPROXY_GUID_H */
|
||||||
|
34
src/guid.c
34
src/guid.c
@ -30,18 +30,9 @@ int guid_insert(enum obj_type *objt, const char *uid, char **errmsg)
|
|||||||
struct ebpt_node *node;
|
struct ebpt_node *node;
|
||||||
char *key = NULL;
|
char *key = NULL;
|
||||||
char *dup_name = NULL;
|
char *dup_name = NULL;
|
||||||
const char *c;
|
|
||||||
|
|
||||||
if (strlen(uid) > GUID_MAX_LEN) {
|
if (!guid_is_valid_fmt(uid, errmsg))
|
||||||
memprintf(errmsg, "UID too big");
|
|
||||||
goto err;
|
goto err;
|
||||||
}
|
|
||||||
|
|
||||||
c = invalid_char(uid);
|
|
||||||
if (c) {
|
|
||||||
memprintf(errmsg, "invalid character '%c'", c[0]);
|
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (obj_type(objt)) {
|
switch (obj_type(objt)) {
|
||||||
case OBJ_TYPE_PROXY:
|
case OBJ_TYPE_PROXY:
|
||||||
@ -111,6 +102,29 @@ struct guid_node *guid_lookup(const char *uid)
|
|||||||
return guid;
|
return guid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Returns a boolean checking if <uid> respects GUID format. If <errmsg> is not
|
||||||
|
* NULL, it will be allocated with an error description in case of invalid
|
||||||
|
* format.
|
||||||
|
*/
|
||||||
|
int guid_is_valid_fmt(const char *uid, char **errmsg)
|
||||||
|
{
|
||||||
|
const size_t len = strlen(uid);
|
||||||
|
const char *c;
|
||||||
|
|
||||||
|
if (!len || len > GUID_MAX_LEN) {
|
||||||
|
memprintf(errmsg, "invalid length");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
c = invalid_char(uid);
|
||||||
|
if (c) {
|
||||||
|
memprintf(errmsg, "invalid character '%c'", c[0]);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/* Generate a user-friendly description for the instance attached via <guid>
|
/* Generate a user-friendly description for the instance attached via <guid>
|
||||||
* node. The string is dynamically allocated and the caller is responsible to
|
* node. The string is dynamically allocated and the caller is responsible to
|
||||||
* free it.
|
* free it.
|
||||||
|
Loading…
Reference in New Issue
Block a user