This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch tymux-10-quiet-head
in repository terminology.
View the commit online.
commit 1a8190f184f7db02e4d0aab2c4076ef6732d8634
Author: Boris Faure <[email protected]>
AuthorDate: Sun Nov 15 19:07:10 2026 +0000
termptystatus: parse the 7501 payload pairs
Split the payload of a report into key=value pairs: pairs are
separated by ':', a pair splits on its first '=', and whitespace
around keys and values is removed. A malformed pair, an unknown key
or a value outside the payload alphabet is skipped; the rest of the
report still applies.
The pairs land in a staging struct of pointers into a scratch copy
of the payload; a repeated key keeps only the last value.
Nothing feeds the parser yet, so it sits unused until the report
handling lands.
---
src/bin/termptystatus.c | 141 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 141 insertions(+)
diff --git a/src/bin/termptystatus.c b/src/bin/termptystatus.c
index 57b81656..305c9322 100644
--- a/src/bin/termptystatus.c
+++ b/src/bin/termptystatus.c
@@ -26,6 +26,19 @@
#define _PS_REC(l) EINA_INLIST_CONTAINER_GET(l, Termpty_Program_Record)
+/* The pairs of one report, validated but not yet applied. Strings
+ * point into a scratch copy of the payload. */
+struct ps_staging
+{
+ const char *state;
+ const char *id;
+ const char *kind;
+ const char *progress;
+ const char *app;
+ const char *title;
+ const char *msg;
+};
+
static void
_ps_record_free(Termpty_Program_Record *rec)
{
@@ -34,6 +47,134 @@ _ps_record_free(Termpty_Program_Record *rec)
free(rec);
}
+static Eina_Bool
+_ps_key_ok(const char *key, size_t len)
+{
+ size_t i;
+
+ if ((len == 0) || (len > PS_KEY_MAX))
+ return EINA_FALSE;
+ for (i = 0; i < len; i++)
+ {
+ if ((key[i] < 'a') || (key[i] > 'z'))
+ return EINA_FALSE;
+ }
+ return EINA_TRUE;
+}
+
+static Eina_Bool
+_ps_value_byte_ok(char c)
+{
+ return ((c >= 'A' && c <= 'Z') ||
+ (c >= 'a' && c <= 'z') ||
+ (c >= '0' && c <= '9') ||
+ c == '_' || c == '.' || c == ',' || c == '+' ||
+ c == '/' || c == '=' || c == '-');
+}
+
+static Eina_Bool
+_ps_value_ok(const char *value, size_t len)
+{
+ size_t i;
+
+ for (i = 0; i < len; i++)
+ {
+ if (!_ps_value_byte_ok(value[i]))
+ return EINA_FALSE;
+ }
+ return EINA_TRUE;
+}
+
+static void
+_ps_stage_set(struct ps_staging *staging, const char *key, size_t key_len,
+ char *value)
+{
+ /* last value wins: a repeated key overwrites the earlier one */
+ switch (key_len)
+ {
+ case 2:
+ if (memcmp(key, "id", 2) == 0)
+ staging->id = value;
+ break;
+ case 3:
+ if (memcmp(key, "app", 3) == 0)
+ staging->app = value;
+ else if (memcmp(key, "msg", 3) == 0)
+ staging->msg = value;
+ break;
+ case 4:
+ if (memcmp(key, "kind", 4) == 0)
+ staging->kind = value;
+ break;
+ case 5:
+ if (memcmp(key, "state", 5) == 0)
+ staging->state = value;
+ else if (memcmp(key, "title", 5) == 0)
+ staging->title = value;
+ break;
+ case 8:
+ if (memcmp(key, "progress", 8) == 0)
+ staging->progress = value;
+ break;
+ default:
+ break;
+ }
+}
+
+/* Split the payload into pairs on ':', each pair on its first '='.
+ * Whitespace around keys and values is removed. A malformed pair is
+ * skipped; the rest of the report still applies. */
+static void
+_ps_pairs_parse(char *body, struct ps_staging *staging)
+{
+ char *p = body;
+
+ while (p)
+ {
+ char *next = strchr(p, ':');
+ char *pair_end, *eq, *key, *key_end, *value, *value_end;
+
+ if (next)
+ *next++ = '\0';
+ pair_end = p + strlen(p);
+
+ while ((p < pair_end) && ((p[0] == ' ') || (p[0] == '\t')))
+ p++;
+ while ((pair_end > p) &&
+ ((pair_end[-1] == ' ') || (pair_end[-1] == '\t')))
+ pair_end--;
+
+ eq = memchr(p, '=', pair_end - p);
+ if (!eq)
+ goto next_pair;
+
+ key = p;
+ key_end = eq;
+ while ((key_end > key) &&
+ ((key_end[-1] == ' ') || (key_end[-1] == '\t')))
+ key_end--;
+ value = eq + 1;
+ value_end = pair_end;
+ while ((value < value_end) && ((value[0] == ' ') || (value[0] == '\t')))
+ value++;
+ while ((value_end > value) &&
+ ((value_end[-1] == ' ') || (value_end[-1] == '\t')))
+ value_end--;
+
+ if (!_ps_key_ok(key, key_end - key))
+ goto next_pair;
+ if (!_ps_value_ok(value, value_end - value))
+ goto next_pair;
+
+ *key_end = '\0';
+ *value_end = '\0';
+ _ps_stage_set(staging, key, key_end - key, value);
+
+next_pair:
+ p = next;
+ }
+}
+
void
termpty_program_status_summary_get(const Termpty *ty,
Termpty_Program_State *state,
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.