mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-07 15:47:01 +02:00
MINOR: spoe: Move spoe_str_to_vsn() into the header file
The function used to convert the SPOE version from a string to an integer is now located in spoe-t.h header file. The related issue is #2502.
This commit is contained in:
parent
08b522d6ac
commit
d0d23a7a66
@ -287,4 +287,64 @@ spoe_decode_data(char **buf, char *end, struct sample *smp)
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Convert a string to a SPOP version value. The string must follow the format
|
||||||
|
* "MAJOR.MINOR". It will be concerted into the integer (1000 * MAJOR + MINOR).
|
||||||
|
* If an error occurred, -1 is returned.
|
||||||
|
*/
|
||||||
|
static inline int spoe_str_to_vsn(const char *str, size_t len)
|
||||||
|
{
|
||||||
|
const char *p, *end;
|
||||||
|
int maj, min, vsn;
|
||||||
|
|
||||||
|
p = str;
|
||||||
|
end = str+len;
|
||||||
|
maj = min = 0;
|
||||||
|
vsn = -1;
|
||||||
|
|
||||||
|
/* skip leading spaces */
|
||||||
|
while (p < end && isspace((unsigned char)*p))
|
||||||
|
p++;
|
||||||
|
|
||||||
|
/* parse Major number, until the '.' */
|
||||||
|
while (*p != '.') {
|
||||||
|
if (p >= end || *p < '0' || *p > '9')
|
||||||
|
goto out;
|
||||||
|
maj *= 10;
|
||||||
|
maj += (*p - '0');
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* check Major version */
|
||||||
|
if (!maj)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
p++; /* skip the '.' */
|
||||||
|
if (p >= end || *p < '0' || *p > '9') /* Minor number is missing */
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
/* Parse Minor number */
|
||||||
|
while (p < end) {
|
||||||
|
if (*p < '0' || *p > '9')
|
||||||
|
break;
|
||||||
|
min *= 10;
|
||||||
|
min += (*p - '0');
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* check Minor number */
|
||||||
|
if (min > 999)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
/* skip trailing spaces */
|
||||||
|
while (p < end && isspace((unsigned char)*p))
|
||||||
|
p++;
|
||||||
|
if (p != end)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
vsn = maj * 1000 + min;
|
||||||
|
out:
|
||||||
|
return vsn;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif /* _HAPROXY_SPOE_H */
|
#endif /* _HAPROXY_SPOE_H */
|
||||||
|
@ -435,65 +435,6 @@ static struct spoe_version supported_versions[] = {
|
|||||||
/* Comma-separated list of supported versions */
|
/* Comma-separated list of supported versions */
|
||||||
#define SUPPORTED_VERSIONS_VAL "2.0"
|
#define SUPPORTED_VERSIONS_VAL "2.0"
|
||||||
|
|
||||||
/* Convert a string to a SPOE version value. The string must follow the format
|
|
||||||
* "MAJOR.MINOR". It will be concerted into the integer (1000 * MAJOR + MINOR).
|
|
||||||
* If an error occurred, -1 is returned. */
|
|
||||||
static int
|
|
||||||
spoe_str_to_vsn(const char *str, size_t len)
|
|
||||||
{
|
|
||||||
const char *p, *end;
|
|
||||||
int maj, min, vsn;
|
|
||||||
|
|
||||||
p = str;
|
|
||||||
end = str+len;
|
|
||||||
maj = min = 0;
|
|
||||||
vsn = -1;
|
|
||||||
|
|
||||||
/* skip leading spaces */
|
|
||||||
while (p < end && isspace((unsigned char)*p))
|
|
||||||
p++;
|
|
||||||
|
|
||||||
/* parse Major number, until the '.' */
|
|
||||||
while (*p != '.') {
|
|
||||||
if (p >= end || *p < '0' || *p > '9')
|
|
||||||
goto out;
|
|
||||||
maj *= 10;
|
|
||||||
maj += (*p - '0');
|
|
||||||
p++;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* check Major version */
|
|
||||||
if (!maj)
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
p++; /* skip the '.' */
|
|
||||||
if (p >= end || *p < '0' || *p > '9') /* Minor number is missing */
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
/* Parse Minor number */
|
|
||||||
while (p < end) {
|
|
||||||
if (*p < '0' || *p > '9')
|
|
||||||
break;
|
|
||||||
min *= 10;
|
|
||||||
min += (*p - '0');
|
|
||||||
p++;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* check Minor number */
|
|
||||||
if (min > 999)
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
/* skip trailing spaces */
|
|
||||||
while (p < end && isspace((unsigned char)*p))
|
|
||||||
p++;
|
|
||||||
if (p != end)
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
vsn = maj * 1000 + min;
|
|
||||||
out:
|
|
||||||
return vsn;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Encode the HELLO frame sent by HAProxy to an agent. It returns the number of
|
/* Encode the HELLO frame sent by HAProxy to an agent. It returns the number of
|
||||||
* encoded bytes in the frame on success, 0 if an encoding error occurred and -1
|
* encoded bytes in the frame on success, 0 if an encoding error occurred and -1
|
||||||
* if a fatal error occurred. */
|
* if a fatal error occurred. */
|
||||||
|
Loading…
Reference in New Issue
Block a user