19#if PC_ENABLE_HTTP_CLIENT
24bool put(
char *out,
size_t cap,
size_t *pos,
const char *s)
26 size_t n = strnlen(s, cap + 1);
31 memcpy(out + *pos, s, n);
38bool put_escaped(
char *out,
size_t cap,
size_t *pos,
const char *s)
43 if (c ==
'"' || c ==
'\\')
66int pc_ifttt_url(
const char *event,
const char *key,
char *out,
size_t cap)
68 if (!out || cap == 0 || !event || !key)
76 pc_sb sb_out = {out, cap, 0,
true};
77 pc_sb_put(&sb_out,
"https://maker.ifttt.com/trigger/");
92int pc_ifttt_payload(
const char *v1,
const char *v2,
const char *v3,
char *out,
size_t cap)
100 bool ok = put(out, cap, &pos,
"{");
101 const char *names[3] = {
"value1",
"value2",
"value3"};
102 const char *vals[3] = {v1, v2, v3};
104 for (
int i = 0; i < 3 && ok; i++)
114 ok = ok && put(out, cap, &pos,
",");
117 ok = ok && put(out, cap, &pos,
"\"");
118 ok = ok && put(out, cap, &pos, names[i]);
119 ok = ok && put(out, cap, &pos,
"\":\"");
120 ok = ok && put_escaped(out, cap, &pos, vals[i]);
121 ok = ok && put(out, cap, &pos,
"\"");
123 ok = ok && put(out, cap, &pos,
"}");
132#if PC_ENABLE_HTTP_CLIENT
134int pc_webhook_post(
const char *url,
const char *json)
138 return (
int)HttpClientError::HTTP_CLIENT_ERR_URL;
146int pc_webhook_post(
const char *,
const char *)
153int pc_ifttt_trigger(
const char *event,
const char *key,
const char *v1,
const char *v2,
const char *v3)
157 if (pc_ifttt_url(event, key, url,
sizeof(url)) == 0)
161 if (pc_ifttt_payload(v1, v2, v3, body,
sizeof(body)) == 0)
165 return pc_webhook_post(url, body);
Zero-heap outbound HTTP(S) client over raw lwIP (PC_ENABLE_HTTP_CLIENT).
Shared HTTP Content-Type ("MIME") string constants (one source of truth).
#define PC_HTTP_CLIENT_BUF_SIZE
Receive buffer (and max response size) for the outbound HTTP client, bytes.
Bounded no-heap string builder that fails closed on overflow (one shared copy).
size_t pc_sb_finish(pc_sb *b)
NUL-terminate and return the built length, or 0 if the build overflowed.
void pc_sb_put(pc_sb *b, const char *s)
Append NUL-terminated s; leaves the buffer untouched and clears ok if it would not fit.
Bump-append target; ok latches false once an append would overflow cap.
Outbound webhooks / IFTTT (PC_ENABLE_WEBHOOK).