/* chat_login: see chat_login.h. */ #include "chat_login.h" /* ---- small string helpers (no libc: also built on the host) ---- */ static unsigned int c_len(const char *s) { unsigned int n = 0; while (s && s[n]) n++; return n; } static void c_copy(char *d, const char *s, unsigned int cap) { unsigned int i = 0; if (!cap) return; while (s && s[i] && i + 1 < cap) { d[i] = s[i]; i++; } d[i] = '\0'; } static int c_prefix(const char *s, const char *p) { while (*p) { if (*s != *p) return 0; s++; p++; } return 1; } static int __attribute__((unused)) c_suffix(const char *s, const char *suf) { unsigned int a = c_len(s), b = c_len(suf), i; if (b > a) return 0; for (i = 0; i < b; i++) if (s[a - b + i] != suf[i]) return 0; return 1; } /* Find needle in hay[0..len); index or -1. */ static int c_find(const char *hay, unsigned int len, const char *needle, unsigned int from) { unsigned int n = c_len(needle), i, j; if (!n || n > len) return -1; for (i = from; i + n <= len; i++) { for (j = 0; j < n; j++) if (hay[i + j] != needle[j]) break; if (j == n) return (int)i; } return -1; } /* Cloudron's consent interaction page is a bare auto-submit form, not the * login SPA: