]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: tevt/dev: Parse tuple of termination events
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 30 Jan 2025 15:19:48 +0000 (16:19 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 31 Jan 2025 09:46:08 +0000 (10:46 +0100)
term_events tool is now able to parse tuple of termination events, as returned
by "term_events" sample fetch function.

dev/term_events/term_events.c

index 4e9b8d0eda19ec34fcdc975b4622e23ef77a187e..417793fb6bbae52ffdbf48ea6cf8f7db5153c413 100644 (file)
@@ -101,8 +101,14 @@ char *tevt_show_events(char *buf, size_t len, const char *delim, const char *val
        char loc[5];
        int ret;
 
-       if (!value)
+       if (!value || !*value) {
+               snprintf(buf, len, "##NONE");
                goto end;
+       }
+       if (strcmp(value, "-") == 0) {
+               snprintf(buf, len, "##UNK");
+               goto end;
+       }
 
        if (strlen(value) % 2 != 0) {
                snprintf(buf, len, "##INV");
@@ -135,10 +141,47 @@ char *tevt_show_events(char *buf, size_t len, const char *delim, const char *val
        return buf;
 }
 
+char *tevt_show_tuple_events(char *buf, size_t len, char *value)
+{
+       char *p = value;
+
+       /* skip '{' */
+       p++;
+       while (*p) {
+               char *v;
+               char c;
+
+               while (*p == ' ' || *p == '\t')
+                       p++;
+
+               v = p;
+               while (*p && *p != ',' && *p != '}')
+                       p++;
+               c = *p;
+               *p = 0;
+
+               tevt_show_events(buf, len, " > ", v);
+               printf("\t- %s\n", buf);
+
+               *p = c;
+               if (*p == ',')
+                       p++;
+               else if (*p == '}')
+                       break;
+               else {
+                       printf("\t- ##INV\n");
+                       break;
+               }
+       }
+
+       *buf = 0;
+       return buf;
+}
+
 int main(int argc, char **argv)
 {
        const char *name = argv[0];
-       char line[20];
+       char line[128];
        char *value;
        int multi = 0;
        int use_stdin = 0;
@@ -165,7 +208,7 @@ int main(int argc, char **argv)
                                value++;
 
                        err = value;
-                       while (isalnum((unsigned char)*err))
+                       while (*err && *err != '\n')
                                err++;
                        *err = 0;
                }
@@ -177,7 +220,13 @@ int main(int argc, char **argv)
                if (multi)
                        printf("### %-8s : ", value);
 
-               tevt_show_events(buf, bsz, " > ", value);
+               if (*value == '{') {
+                       if (!use_stdin)
+                               printf("\n");
+                       tevt_show_tuple_events(buf, bsz, value);
+               }
+               else
+                       tevt_show_events(buf, bsz, " > ", value);
                printf("%s\n", buf);
        }
        return 0;