struct appctx;
+extern const struct spop_version spop_supported_versions[];
+
struct spoe_agent *spoe_appctx_agent(struct appctx *appctx);
/* Encode a buffer. Its length <len> is encoded as a varint, followed by a copy
return vsn;
}
+/* Check if vsn, converted into an integer, is supported by looping on the list
+ * of supported versions. It return -1 on error and 0 on success.
+ */
+static inline int spoe_check_vsn(int vsn)
+{
+ int i;
+
+ for (i = 0; spop_supported_versions[i].str != NULL; ++i) {
+ if (vsn >= spop_supported_versions[i].min &&
+ vsn <= spop_supported_versions[i].max)
+ break;
+ }
+ if (spop_supported_versions[i].str == NULL)
+ return -1;
+ return 0;
+}
#endif /* _HAPROXY_SPOE_H */
#define SPOP_STATUS_CODE_KEY "status-code"
#define SPOP_MSG_KEY "message"
-struct spop_version {
- char *str;
- int min;
- int max;
-};
-
/* All supported versions */
-static struct spop_version spop_supported_versions[] = {
+const struct spop_version spop_supported_versions[] = {
/* 1.0 is now unsupported because of a bug about frame's flags*/
{"2.0", 2000, 2000},
{NULL, 0, 0}
/* Check "version" K/V item */
if (sz >= strlen(SPOP_VERSION_KEY) && !memcmp(str, SPOP_VERSION_KEY, strlen(SPOP_VERSION_KEY))) {
- int i, type = *p++;
+ int type = *p++;
/* The value must be a string */
if ((type & SPOP_DATA_T_MASK) != SPOP_DATA_T_STR) {
vsn = spoe_str_to_vsn(str, sz);
if (vsn == -1) {
- spop_conn_error(spop_conn, SPOP_ERR_BAD_VSN);
+ spop_conn_error(spop_conn, SPOP_ERR_INVALID);
goto fail;
}
- for (i = 0; spop_supported_versions[i].str != NULL; ++i) {
- if (vsn >= spop_supported_versions[i].min &&
- vsn <= spop_supported_versions[i].max)
- break;
- }
- if (spop_supported_versions[i].str == NULL) {
+ if (spoe_check_vsn(vsn) == -1) {
spop_conn_error(spop_conn, SPOP_ERR_BAD_VSN);
goto fail;
}