]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: spoe: Move spoe_str_to_vsn() into the header file
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 4 Jul 2024 09:16:50 +0000 (11:16 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 12 Jul 2024 13:27:04 +0000 (15:27 +0200)
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.

include/haproxy/spoe.h
src/flt_spoe.c

index 6721d9777faee9e43b38be79dca87bef84171a59..55b2c0d50fa9711c1ca08a4861ca6e228fdab67f 100644 (file)
@@ -287,4 +287,64 @@ spoe_decode_data(char **buf, char *end, struct sample *smp)
        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 */
index 603191e6201ca3dc6cd46ce1d6370aa2363a44cc..0970cc842952037ab9665ead653252e31c49efd1 100644 (file)
@@ -435,65 +435,6 @@ static struct spoe_version supported_versions[] = {
 /* Comma-separated list of supported versions */
 #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
  * encoded bytes in the frame on success, 0 if an encoding error occurred and -1
  * if a fatal error occurred. */