From bfb102f80db4eaaa3419f526827f7ee46ca3385a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Gro=C3=9Fmann?= Date: Wed, 8 Apr 2026 18:51:58 +0200 Subject: [PATCH 1/3] Remove MQTT telemetry subsystem Removes HTTPT struct, telemetry_thread, and all related MQTT publishing from the HTTP server core. The mqtt370 dependency is also removed from project.toml. Affected files: - include/httpd.h: removed HTTPT/HTTPTC typedefs and struct definitions, replaced httpt field at offset 0x94 with void *unused_94, replaced mqtc_pub slot at offset 0x10C with void *unused_10C - include/httpcgi.h: same HTTPX slot replacement, removed MQTC typedef - include/httppub.h: deleted - src/httpx.c: NULL placeholder at offset 0x10C - src/httpd.c: removed telemetry_thread, http_process_telemetry*, related MQTT publish calls, and unused variables - src/httpdsrv.c: removed httpt display row - src/httpstat.c: removed http_pubf calls and now-unused variables - src/httppubf.c: deleted - project.toml: removed mqtt370 dependency Fixes #44 --- include/httpcgi.h | 9 +- include/httpd.h | 44 +---- include/httppub.h | 48 ----- project.toml | 1 - src/httpd.c | 494 ---------------------------------------------- src/httpdsrv.c | 9 +- src/httppubf.c | 301 ---------------------------- src/httpstat.c | 51 +---- src/httpx.c | 2 +- 9 files changed, 6 insertions(+), 953 deletions(-) delete mode 100644 include/httppub.h delete mode 100644 src/httppubf.c diff --git a/include/httpcgi.h b/include/httpcgi.h index 88748a0..305f491 100644 --- a/include/httpcgi.h +++ b/include/httpcgi.h @@ -46,7 +46,6 @@ typedef struct cred CRED; /* Credentials — opaque */ typedef struct ufs UFS; /* UFS filesystem — opaque */ typedef struct ufsfile UFSFILE; /* UFS file handle — opaque */ #endif -typedef struct mqtc MQTC; /* MQTT client — opaque */ typedef struct cib CIB; /* Console info block — opaque */ #include /* struct in_addr */ @@ -286,10 +285,7 @@ struct httpx { /* 104 add cgi for pgm and path */ int (*http_process_cgi)(HTTPC *httpc, HTTPCGI *cgi); /* 108 process CGI request */ - int (*mqtc_pub)(MQTC *mqtc, unsigned qos, unsigned retain, - const char *topic_name, - const char *application_message); - /* 10C publish MQTT topic */ + void *unused_10C; /* 10C (was: mqtc_pub) */ unsigned char *(*http_xlate)(unsigned char *, int, const unsigned char *); /* 110 translate with explicit table */ HTTPCP *xlate_cp037; /* 114 CP037 codepage pair */ @@ -515,9 +511,6 @@ struct httpx { #define http_process_cgi(httpc,cgi) \ ((httpx->http_process_cgi)((httpc),(cgi))) -#define mqtc_pub(mqtc,qos,retain,topic,message) \ - ((httpx->mqtc_pub)((mqtc),(qos),(retain),(topic),(message))) - #define http_xlate(buf,len,tbl) \ ((httpx->http_xlate)((buf),(len),(tbl))) diff --git a/include/httpd.h b/include/httpd.h index 50873db..5b96f82 100644 --- a/include/httpd.h +++ b/include/httpd.h @@ -43,7 +43,6 @@ #include "racf.h" /* security environment */ #include "types.h" /* UCHAR, USHRT, UINT, ULONG */ #include "cred.h" /* Credentials */ -#include "mqtc370.h" /* MQTT Client */ #include "httpxlat.h" /* ASCII/EBCDIC translation */ #define HTTPLUAX (httpd->luax) /* use this pointer */ @@ -52,8 +51,6 @@ typedef struct httpd HTTPD; /* HTTP Daemon (server) */ typedef struct httpc HTTPC; /* HTTP Client */ typedef struct httpm HTTPM; /* HTTP Mime */ -typedef struct httpt HTTPT; /* HTTP Telemetry (MQTT) */ -typedef struct httptc HTTPTC; /* HTTP Telemetry Cache */ typedef struct httpx HTTPX; /* HTTP function vector */ typedef struct httpv HTTPV; /* HTTP Variables */ typedef struct httpcgi HTTPCGI; /* HTTP CGI path and programs */ @@ -61,8 +58,6 @@ typedef struct httpstat HTTPSTAT; /* HTTP Statistics record */ typedef enum cstate CSTATE; /* HTTP Client state */ typedef enum rdw RDW; /* RDW option */ -#include "httppub.h" /* HTTP Telemetry Publisher */ - #ifndef OR #define OR ??!??! /* logical OR trigraph */ #endif @@ -140,7 +135,7 @@ struct httpd { UCHAR *cgilua_path; /* 88 CGI Lua package.path */ UCHAR *cgilua_cpath; /* 8C CGI Lua package.cpath */ UFS *ufs; /* 90 Unix "like" File System */ - HTTPT *httpt; /* 94 Telemetry (MQTT) */ + void *unused_94; /* 94 (was: HTTPT *httpt) */ CTHDTASK *self; /* 98 HTTPD main thread */ void **cgictx; /* 9C array of CGI context ptrs */ #define HTTPD_CGICTX_MVSMF 0 /* ... MVSMF CGI context index */ @@ -152,37 +147,6 @@ struct httpd { char codepage[16]; /* 124 codepage name */ }; /* 134 */ -/* Telemetry */ -struct httpt { - char eye[8]; /* 00 eye catcher */ -#define HTTPT_EYE "*HTTPT*" /* ... */ - MQTC *mqtc; /* 08 MQTT370 Client Handle */ - unsigned flag; /* 0C Flags */ -#define HTTPT_FLAG_START 0x80000000 /* ... start client */ -#define HTTPT_FLAG_GMT 0x40000000 /* ... datetime values GMT */ - char *broker_host; /* 10 config host name */ - char *broker_port; /* 14 config port number */ - char *prefix; /* 18 config topic prefix */ - char *smfid; /* 1C smfid string */ - char *jobname; /* 20 jobname string */ - unsigned telemetry; /* 24 telemetry interval */ - HTTPTC **httptc; /* 28 telemetry cache array */ - CTHDTASK *telemetry_thread; /* 30 telemetry thread */ - unsigned telemetry_ecb; /* 34 telemetry ecb */ - unsigned unused[2]; /* 38 unused */ -}; /* 40 (64 bytes) */ - -/* Telemetry Cache */ -struct httptc { - char eye[8]; /* 00 eye catcher */ -#define HTTPTC_EYE "*HTTPTC*" /* ,,, */ - time64_t last; /* 08 last update time */ - unsigned topic_len; /* 10 topic name length */ - char *topic; /* 14 topic name */ - unsigned data_len; /* 18 message data length */ - char *data; /* 1C message data */ -}; /* 20 (32 bytes) */ - /* HTTP variables */ struct httpv { char eye[8]; /* 00 eye catcher */ @@ -421,8 +385,7 @@ struct httpx { /* 104 add cgi for pgm and path */ int (*http_process_cgi)(HTTPC *httpc, HTTPCGI *cgi); /* 108 process CGI request */ - int (*mqtc_pub)(MQTC *mqtc, unsigned qos, unsigned retain, const char* topic_name, const char* application_message); - /* 10C publish topic */ + void *unused_10C; /* 10C (was: mqtc_pub) */ unsigned char *(*http_xlate)(unsigned char *, int, const unsigned char *); /* 110 translate with explicit table */ HTTPCP *xlate_cp037; /* 114 CP037 codepage pair */ @@ -714,9 +677,6 @@ extern int http_gets(HTTPC *httpc, UCHAR *buf, unsigned max) asm("HTT #define http_process_cgi(httpc,cgi) \ ((httpx->http_process_cgi)((httpc),(cgi))) -#define mqtc_pub(mqtc,qos,retain,topic,message) \ - ((httpx->mqtc_pub)((mqtc),(qos),(retain),(topic),(message))) - #define http_xlate(buf,len,tbl) \ ((httpx->http_xlate)((buf),(len),(tbl))) diff --git a/include/httppub.h b/include/httppub.h deleted file mode 100644 index 584f6c6..0000000 --- a/include/httppub.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef HTTPPUB_H -#define HTTPPUB_H - -#ifndef HTTPD_H -#error #include "httpd.h" first -#endif - -extern char * -http_get_timebuf(void) - asm("HTTPPUBB"); - -extern int -http_pub_cache(HTTPD *httpd) - asm("HTTPPUBC"); - -extern int -http_pub_datetime(HTTPD *httpd, const char *topic_name) - asm("HTTPPUBD"); - -extern int -http_pubf(HTTPD *httpd, const char *topic_name, const char *fmt, ... ) - asm("HTTPPUBF"); - -extern const char * -http_gmt_datetime(void) - asm("HTTPPUBG"); - -extern const char * -http_local_datetime(void) - asm("HTTPPUBL"); - -extern int -http_pubf_nocache(HTTPD *httpd, const char *topic_name, const char *fmt, ... ) - asm("HTTPPUBN"); - -extern const char * -http_get_datetime(HTTPD *httpd) - asm("HTTPPUBT"); - -extern const char * -http_fmt_datetime(HTTPD *httpd, time64_t *timer, char *timebuf) - asm("HTTPPUBU"); - -extern int -http_pubv(HTTPD *httpd, const char *topic_name, const char *fmt, va_list args, int cache) - asm("HTTPPUBV"); - -#endif /* HTTPPUB_H */ diff --git a/project.toml b/project.toml index 2c8c821..f9daa5b 100644 --- a/project.toml +++ b/project.toml @@ -51,7 +51,6 @@ space = ["TRK", 150, 50, 30] "mvslovers/crent370" = ">=1.0.8" "mvslovers/ufsd" = "=1.0.0-dev" "mvslovers/lua370" = ">=1.0.2" -"mvslovers/mqtt370" = ">=1.0.3" # --- Load Modules ------------------------------------------------ diff --git a/src/httpd.c b/src/httpd.c index 31098a9..3a7f6c4 100644 --- a/src/httpd.c +++ b/src/httpd.c @@ -11,7 +11,6 @@ #include "clibsock.h" static int socket_thread(void *arg1, void *arg2); -static int telemetry_thread(void *arg1, void *arg2); static int worker_thread(void *udata, CTHDWORK *work); unsigned __stklen = 64*1024; @@ -109,20 +108,6 @@ initialize(int argc, char **argv) httpstat_load(httpd, httpd->st_dataset); } - if (httpd->httpt) { - HTTPT *httpt = httpd->httpt; - - /* create telemetry thread */ - if ((httpt->flag & HTTPT_FLAG_START) && (httpt->telemetry > 0)) { - httpt->telemetry_thread = cthread_create_ex(telemetry_thread, - httpd, httpt, 32*1024); - if (!httpt->telemetry_thread) { - wtof("HTTPD033E Unable to telemetry thread\n"); - goto quit; - } - } - } - /* create socket thread */ httpd->socket_thread = cthread_create_ex(socket_thread, httpd, httpx, 32*1024); @@ -281,12 +266,10 @@ terminate(void) http_dbgf("closing socket(%d)\n", httpd->listen); closesocket(httpd->listen); httpd->listen = 0; - http_pubf(httpd, "thread/listener/http", ""); } /* terminate the worker threads */ cthread_manager_term(&httpd->mgr); - http_pubf(httpd, "thread/worker", ""); if (httpd->httpc) { for(httpc=httpd->httpc[0]; httpc; httpc=httpd->httpc[0]) { @@ -323,72 +306,6 @@ terminate(void) httpstat_save(httpd, httpd->st_dataset); } - /* Publish to MQTT Broker */ - http_pubf(httpd, "state", "shutdown"); - http_pub_datetime(httpd, "shutdown"); - - if (httpd->httpt) { /* HTTPD Telemetry (MQTT) */ - HTTPT *httpt = httpd->httpt; - - if (httpt->telemetry_thread) { - CTHDTASK *task = httpt->telemetry_thread; - - /* wake up the telemetry thread */ - cthread_post(&httpt->telemetry_ecb, 0); - - for(i=0; (i < 10) && (!(task->termecb & 0x40000000)); i++) { - if (i) { - wtof("HTTPD040I Waiting for telemetry thread to terminate (%d)", i); - } - /* we need to wait 1 second */ - __asm__("STIMER WAIT,BINTVL==F'100' 1 seconds"); - } - - if(!(task->termecb & 0x40000000)) { - wtof("HTTPD041I Force detaching telemetry thread\n"); - } - cthread_delete(&httpt->telemetry_thread); - http_pubf_nocache(httpd, "thread/telemetry/cache", ""); - } - - if (httpt->mqtc) { - wtof("HTTPD429I Terminating MQTT"); - - mqtc_close_client(httpt->mqtc); - - cthread_yield(); - - mqtc_free_client(&httpt->mqtc); - } - - if (httpt->broker_host) free(httpt->broker_host); - if (httpt->broker_port) free(httpt->broker_port); - if (httpt->prefix) free(httpt->prefix); - if (httpt->smfid) free(httpt->smfid); - if (httpt->jobname) free(httpt->jobname); - - if (httpt->httptc) { - /* free the telemetry cache array */ - count = array_count(&httpt->httptc); - - for(n=count; n > 0; n--) { - HTTPTC *httptc = array_del(&httpt->httptc, n); - - if (!httptc) continue; - - /* free the telemetry cache record */ - if (httptc->data) free(httptc->data); - if (httptc->topic) free(httptc->topic); - free(httptc); - } - - array_free(&httpt->httptc); - } - - free(httpt); - httpd->httpt = NULL; - } - /* just in case we missed something */ close_fd_set(); @@ -506,27 +423,12 @@ socket_thread(void *arg1, void *arg2) fd_set read; struct sockaddr_in addr; struct sockaddr_in *a = (struct sockaddr_in *)&addr; - char *timebuf; http_enter("socket_thread()\n"); wtof("HTTPD061I STARTING socket thread TCB(%06X) TASK(%06X) STACKSIZE(%u)", tcb, task, task->stacksize); - /* Publish to MQTT Broker */ - timebuf = http_get_timebuf(); - if (timebuf) { - lock(timebuf, LOCK_EXC); - http_pubf(httpd, "thread/listener", - "{ \"datetime\" : \"%s\" " - ", \"tcb\" : \"%06X\" " - ", \"task\" : \"%06X\" " - ", \"stacksize\" : %u " - "}", - http_get_datetime(httpd), tcb, task, task->stacksize); - unlock(timebuf, LOCK_EXC); - } - /* if something goes all wrong, capture it! */ abendrpt(ESTAE_CREATE, DUMP_DEFAULT); @@ -643,364 +545,17 @@ socket_thread(void *arg1, void *arg2) wtof("HTTPD060I SHUTDOWN socket thread TCB(%06X) TASK(%06X) STACKSIZE(%u)", tcb, task, task->stacksize); - /* Publish to MQTT Broker */ - http_pubf(httpd, "thread/listener", ""); - abendrpt(ESTAE_DELETE, DUMP_DEFAULT); http_exit("socket_thread()\n"); return 0; } -typedef struct static_process_telemetry_ping { - time64_t ping_time; -} SPTP; -static SPTP *static_process_telemetry_ping; - -static int -http_process_telemetry_ping(HTTPD *httpd) -{ - int rc = 0; - SPTP *sptp = __wsaget(&static_process_telemetry_ping, sizeof(SPTP)); - HTTPT *httpt = httpd->httpt; - MQTC *mqtc; - time64_t now; - char timebuf[26]; - unsigned n; - unsigned count; - unsigned bytes = 0; - - if (!httpt) goto quit; - if (!httpt->mqtc) goto quit; - - time64(&now); - - if (__64_cmp(&sptp->ping_time, &now)== __64_LARGER) goto quit; - - if(!__64_is_zero(&sptp->ping_time)) { - /* send PING request */ - rc = mqtc_send_ping(httpt->mqtc); - } - - /* update next PING time */ - __64_add_u32(&now, 60, &sptp->ping_time); - -quit: - return rc; -} - - - - -typedef struct static_process_telemetry_cache { - unsigned records; - unsigned bytes; -} SPTC; -static SPTC *static_process_telemetry_cache; - -static int -http_process_telemetry_cache(HTTPD *httpd) -{ - int rc = 0; - int lockrc = 8; - SPTC *sptc = __wsaget(&static_process_telemetry_cache, sizeof(SPTC)); - HTTPT *httpt = httpd->httpt; - HTTPTC *httptc; - MQTC *mqtc; - time64_t last; - char timebuf[26]; - unsigned n; - unsigned count; - unsigned bytes = 0; - - if (!httpt) goto quit; - if (!httpt->mqtc) goto quit; - - __64_init(&last); - - lockrc = lock(&httpt->httptc, LOCK_SHR); - - count = array_count(&httpt->httptc); - for(n=0; n < count; n++) { - httptc = httpt->httptc[n]; - - if (!httptc) continue; - bytes += sizeof(HTTPTC); - bytes += (httptc->topic_len + 1 + 7) & 0xFFFFFFF8; - bytes += (httptc->data_len + 1 + 7) & 0xFFFFFFF8; - - if (__64_cmp(&httptc->last, &last) == __64_LARGER) { - last = httptc->last; - } - } - - if (sptc->records == count && sptc->bytes == bytes) { - /* and the same record count and byte count */ - goto quit; - } - - sptc->records = count; - sptc->bytes = bytes; - - if (__64_is_zero(&last)) time64(&last); - - /* don't cache this topic */ - http_pubf_nocache(httpd, "thread/telemetry/cache", - "{ \"datetime\" : \"%s\" " - ", \"records\" : %u " - ", \"bytes\" : %u " - "}", - http_fmt_datetime(httpd, &last, timebuf), - count, - bytes); - - -quit: - if (lockrc==0) unlock(&httpt->httptc, LOCK_SHR); - return rc; -} - -typedef struct static_process_telemetry { - __64 dispatched; - unsigned worker_count; -} SPT; -static SPT *static_process_telemetry; - -static int -http_process_telemetry(HTTPD *httpd, CTHDMGR *mgr) -{ - int rc = 0; - SPT *spt = __wsaget(&static_process_telemetry, sizeof(SPT)); - HTTPT *httpt = httpd->httpt; - MQTC *mqtc; - time64_t now; - char *timebuf = http_get_timebuf(); - CTHDTASK *task; - CTHDWORK *work; - unsigned n; - unsigned worker_count; - unsigned queue_count; - const char *state; - - if (!httpt) goto quit; - if (!httpt->mqtc) goto quit; - - - /* get current time */ - time64(&now); - - task = mgr->task; - worker_count = array_count(&mgr->worker); - queue_count = array_count(&mgr->queue); - - if (__64_cmp(&spt->dispatched, &mgr->dispatched) == __64_EQUAL) { - /* the dispatch count hasn't changed */ - if (spt->worker_count == worker_count) { - /* and the same number of workers */ - goto quit; - } - } - - spt->dispatched = mgr->dispatched; - spt->worker_count = worker_count; - - switch(mgr->state) { - case CTHDMGR_STATE_INIT: state = "INIT"; break; - case CTHDMGR_STATE_RUNNING: state = "RUNNING"; break; - case CTHDMGR_STATE_QUIESCE: state = "QUIESCE"; break; - case CTHDMGR_STATE_STOPPED: state = "STOPPED"; break; - case CTHDMGR_STATE_WAITING: state = "WAITING"; break; - default: state = "UNKNOWN"; break; - } - - if (timebuf) { - lock(timebuf, LOCK_EXC); - http_pubf(httpd, "thread/worker", - "{ \"datetime\" : \"%s\" " - ", \"dispatched\" : %llu " - ", \"state\" : \"%s\" " - ", \"mgr\" : \"%06X\" " - ", \"task\" : \"%06X\" " - ", \"tcb\" : \"%06X\" " - ", \"mintask\" : %u " - ", \"maxtask\" : %u " - ", \"stacksize\" : %u " - ", \"workers\" : %u " - ", \"queued\" : %u " - "}", - http_get_datetime(httpd), - mgr->dispatched, - state, - mgr, - task, - task->tcb, - mgr->mintask, - mgr->maxtask, - task->stacksize, - worker_count, - queue_count); - unlock(timebuf, LOCK_EXC); - } - - for(n=0; n < worker_count; n++) { - char topic[40]; - - work = mgr->worker[n]; - - sprintf(topic, "thread/worker/%u", n+1); - - if (!work) goto discard; /* no worker */ - - task = work->task; - if (!task) goto discard; /* no task */ - if (!task->tcb) goto discard; /* no tcb */ - if (task->termecb) goto discard; /* tcb terminated */ - - switch(work->state) { - case CTHDWORK_STATE_INIT: state = "INIT"; break; - case CTHDWORK_STATE_RUNNING: state = "RUNNING"; break; - case CTHDWORK_STATE_WAITING: state = "WAITING"; break; - case CTHDWORK_STATE_DISPATCH: state = "DISPATCH"; break; - case CTHDWORK_STATE_SHUTDOWN: state = "SHUTDOWN"; break; - case CTHDWORK_STATE_STOPPED: state = "STOPPED"; break; - default: state = "UNKNOWN"; break; - } - - lock(timebuf, LOCK_EXC); - http_pubf(httpd, topic, - "{ \"datetime\" : \"%s\" " - ", \"dispatched\" : %llu " - ", \"state\" : \"%s\" " - ", \"task\" : \"%06X\" " - ", \"tcb\" : \"%06X\" " - ", \"stacksize\" : %u " - "}", - http_fmt_datetime(httpd, &work->start_time, timebuf), - work->dispatched, - state, - task, - task->tcb, - task->stacksize); - unlock(timebuf, LOCK_EXC); - - continue; - -discard: - http_pubf(httpd, topic, ""); - continue; /* tcb has ended */ - } - -quit: - return rc; -} - -static int -telemetry_thread(void *udata1, void *udata2) -{ - HTTPD *httpd = udata1; /* Server handle */ - HTTPT *httpt = httpd->httpt; /* Telemetry handle */ - unsigned *psa = (unsigned *)0; - unsigned *tcb = (unsigned *)psa[0x21C/4]; /* A(TCB) from PSATOLD */ - unsigned *ascb = (unsigned *)psa[0x224/4]; /* A(ASCB) from PSAAOLD */ - CTHDTASK *task = cthread_self(); - CTHDMGR *mgr; - int rc = 0; - char *timebuf; - - wtof("HTTPD061I STARTING telemetry thread TCB(%06X) TASK(%06X) STACKSIZE(%u)", - tcb, task, task->stacksize); - - /* Publish to MQTT Broker */ - timebuf = http_get_timebuf(); - if (timebuf) { - lock(timebuf, LOCK_EXC); - - if (httpt && httpt->mqtc && httpt->mqtc->task) { - MQTC *mqtc = httpt->mqtc; - CTHDTASK *subtask = mqtc->task; - CTHDTASK *self = httpd->self; - unsigned addr, port; - - http_pubf(httpd, "thread/main", - "{ \"datetime\" : \"%s\" " - ", \"tcb\" : \"%06X\" " - ", \"task\" : \"%06X\" " - ", \"stacksize\" : %u " - "}", - http_get_datetime(httpd), self->tcb, self, self->stacksize); - - http_pubf(httpd, "thread/mqtt", - "{ \"datetime\" : \"%s\" " - ", \"tcb\" : \"%06X\" " - ", \"task\" : \"%06X\" " - ", \"stacksize\" : %u " - "}", - http_get_datetime(httpd), subtask->tcb, subtask, subtask->stacksize); - - http_pubf(httpd, "thread/mqtt/broker", - "{ \"host\" : \"%s\" " - ", \"port\" : \"%s\" " - ", \"socket\" : %d " - "}", - mqtc->broker_host, mqtc->broker_port, mqtc->sock); - } - - - http_pubf(httpd, "thread/telemetry", - "{ \"datetime\" : \"%s\" " - ", \"tcb\" : \"%06X\" " - ", \"task\" : \"%06X\" " - ", \"stacksize\" : %u " - "}", - http_get_datetime(httpd), tcb, task, task->stacksize); - unlock(timebuf, LOCK_EXC); - } - - /* if something goes all wrong, capture it! */ - abendrpt(ESTAE_CREATE, DUMP_DEFAULT); - - while(httpd) { - unsigned wait; - - httpt = httpd->httpt; /* Telemetry handle */ - if (!httpt) break; - - wait = httpt->telemetry * 100; - - /* wait for ecb post or timer expire */ - cthread_timed_wait(&httpt->telemetry_ecb, wait, 0); - - if (httpd->flag & HTTPD_FLAG_SHUTDOWN) break; - - /* terminate() may shutdown the thread manager before us */ - mgr = httpd->mgr; - if (!mgr) break; - - http_process_telemetry(httpd, mgr); - http_process_telemetry_cache(httpd); - http_process_telemetry_ping(httpd); - } - - abendrpt(ESTAE_DELETE, DUMP_DEFAULT); - - wtof("HTTPD060I SHUTDOWN telemetry thread TCB(%06X) TASK(%06X) STACKSIZE(%u)", - tcb, task, task->stacksize); - - http_pubf(httpd, "thread/telemetry", ""); - http_pubf(httpd, "thread/mqtt/broker", ""); - http_pubf(httpd, "thread/mqtt", ""); - http_pubf(httpd, "thread/main", ""); - - return 0; -} - - static int worker_thread(void *udata, CTHDWORK *work) { CLIBCRT *crt = __crtget(); /* A(CLIBCRT) from TCBUSER */ CLIBGRT *grt = __grtget(); HTTPD *httpd = grt->grtapp1; - HTTPT *httpt = httpd->httpt; /* Telemtry handle */ unsigned *psa = (unsigned *)0; unsigned *tcb = (unsigned *)psa[0x21C/4]; /* A(TCB) from PSATOLD */ unsigned *ascb = (unsigned *)psa[0x224/4]; /* A(ASCB) from PSAAOLD */ @@ -1009,9 +564,6 @@ worker_thread(void *udata, CTHDWORK *work) int rc = 0; char *data = NULL; HTTPC *httpc = NULL; - char *timebuf; - char topic[40]; - unsigned n, count; http_enter("worker_thread()\n"); @@ -1021,29 +573,6 @@ worker_thread(void *udata, CTHDWORK *work) wtof("HTTPD061I STARTING worker(%06X) TCB(%06X) TASK(%06X) STACKSIZE(%u)", work, tcb, task, task->stacksize); - if (httpt && httpt->telemetry_thread) { - cthread_post(&httpt->telemetry_ecb, 0); - } - -#if 0 - /* Publish to MQTT Broker */ - sprintf(topic, "thread/worker(%06X)", work); - - timebuf = http_get_timebuf(); - if (timebuf) { - lock(timebuf, LOCK_EXC); - http_pubf(httpd, topic, - "{ \"datetime\" : \"%s\" " - ", \"tcb\" : \"%06X\" " - ", \"task\" : \"%06X\" " - ", \"mgr\" : \"%06X\" " - ", \"crt\" : \"%06X\" " - "}", - http_get_datetime(httpd), tcb, task, mgr, crt); - unlock(timebuf, LOCK_EXC); - } -#endif - while(task) { if (work->state == CTHDWORK_STATE_SHUTDOWN) break; @@ -1075,22 +604,6 @@ worker_thread(void *udata, CTHDWORK *work) wtof("HTTPD060I SHUTDOWN worker(%06X) TCB(%06X) TASK(%06X) STACKSIZE(%u)", work, tcb, task, task->stacksize); -#if 0 - /* Delete topic from MQTT Broker */ - http_pubf(httpd, topic, ""); -#endif - - count = array_count(&mgr->worker); - for(n=0; n < count; n++) { - CTHDWORK *w = mgr->worker[n]; - - if (w == work) { - sprintf(topic, "thread/worker/%u", n+1); - http_pubf(httpd, topic, ""); - break; - } - } - abendrpt(ESTAE_DELETE, DUMP_DEFAULT); http_exit("worker_thread()\n"); @@ -1330,10 +843,6 @@ main(int argc, char **argv) httpd->flag |= HTTPD_FLAG_READY; wtof("HTTPD001I Server is READY\n"); - - /* Publish to MQTT Broker */ - http_pub_datetime(httpd, "ready"); - http_pubf(httpd, "state", "ready"); /* Note: The main thread (this thread) waits for console messages * like modify "/F jobname,..." and stop "/P jobname". @@ -1371,9 +880,6 @@ main(int argc, char **argv) httpd->flag |= HTTPD_FLAG_QUIESCE; wtof("HTTPD002I Server is QUIESCE\n"); - http_pubf(httpd, "state", "quiesce"); - http_pub_datetime(httpd, "quiesce"); - i = try(terminate,0); if (i) wtof("terminate failed with rc=%08X", i); diff --git a/src/httpdsrv.c b/src/httpdsrv.c index e1fe619..048efa8 100644 --- a/src/httpdsrv.c +++ b/src/httpdsrv.c @@ -525,14 +525,7 @@ display_httpd(HTTPD *httpd, HTTPC *httpc) "%p\n", O(ufs), httpd->ufs); - http_printf(httpc, - "+%04X" - "httpd->httpt" - "Telemetry (MQTT) Handle" - "%p\n", - O(httpt), httpd->httpt); - - http_printf(httpc, + http_printf(httpc, "+%04X" "httpd->self" "HTTPD Main Thread Handle" diff --git a/src/httppubf.c b/src/httppubf.c deleted file mode 100644 index b5c4a73..0000000 --- a/src/httppubf.c +++ /dev/null @@ -1,301 +0,0 @@ -#include "httpd.h" - -static char static_timebuf[26] = {0}; - -static int -telemetry_cache_update(HTTPT *httpt, const char *topic, const char *data); - -int -http_pubv(HTTPD *httpd, const char *topic_name, const char *fmt, va_list args, int cache) -{ - int rc = 0; - HTTPT *httpt; - MQTC *mqtc; - int len; - char topic[256]; - char data[1024]; - - if (!httpd) goto quit; - if (!httpd->httpt) goto quit; - if (!httpd->httpt->mqtc) goto quit; - - httpt = httpd->httpt; - mqtc = httpt->mqtc; - - if (mqtc->flags & MQTC_FLAG_RECONNECT) { - /* prevent attempts to publish while the MQTT client is in error state */ - goto quit; - } - - /* construct topic for httpd server */ - if (httpt->prefix && httpt->prefix[0]) { - /* use the prefix supplied in the configration */ - len = sprintf(topic, "%s", httpt->prefix); - } - else { - /* use our default prefix */ - len = sprintf(topic, "httpd/"); - } - - len += sprintf(&topic[len], "%s", topic_name); - topic[sizeof(topic)-1] = 0; - - len = vsprintf(data, fmt, args); - if (len < 0) { - rc = -1; - } - else { - if (len >= sizeof(data)) len = sizeof(data)-1; - data[len] = 0; - - rc = mqtc_pub(mqtc, 0, 1, topic, data); - - if (cache) telemetry_cache_update(httpt, topic, data); - - /* check for errors */ - if (rc) { - wtof("%s: MQTT Publish error: %d", __func__, rc); - rc = -1; - } - else { - rc = len; - } - } - -quit: - return rc; -} - -int -http_pubf(HTTPD *httpd, const char *topic_name, const char *fmt, ... ) -{ - int rc; - va_list args; - - va_start( args, fmt ); - rc = http_pubv(httpd, topic_name, fmt, args, 1); - va_end( args ); - - return rc; -} - -int -http_pubf_nocache(HTTPD *httpd, const char *topic_name, const char *fmt, ... ) -{ - int rc; - va_list args; - - va_start( args, fmt ); - rc = http_pubv(httpd, topic_name, fmt, args, 0); - va_end( args ); - - return rc; -} - - -char * -http_get_timebuf(void) -{ - char *timebuf = __wsaget(static_timebuf, sizeof(static_timebuf)); - -quit: - return timebuf; -} - -const char * -http_local_datetime(void) -{ - char *timebuf = http_get_timebuf(); - time64_t timer; - struct tm* tm_info; - - if (timebuf) { - time64(&timer); - tm_info = localtime64(&timer); - strftime(timebuf, 26, "%Y-%m-%d %H:%M:%S", tm_info); - } - - return timebuf; -} - -const char * -http_gmt_datetime(void) -{ - char *timebuf = http_get_timebuf(); - time64_t timer; - struct tm* tm_info; - - if (timebuf) { - time64(&timer); - tm_info = gmtime64(&timer); - strftime(timebuf, 26, "%Y-%m-%d %H:%M:%S", tm_info); - } - - return timebuf; -} - -const char * -http_fmt_datetime(HTTPD *httpd, time64_t *timer, char *timebuf) -{ - int gmt = 0; - struct tm* tm_info; - - if (!httpd) goto dotime; - if (!httpd->httpt) goto dotime; - - if (httpd->httpt->flag & HTTPT_FLAG_GMT) gmt = 1; - -dotime: - if (timebuf) { - if (gmt) { - tm_info = gmtime64(timer); - } - else { - tm_info = localtime64(timer); - } - strftime(timebuf, 26, "%Y-%m-%d %H:%M:%S", tm_info); - } - - return timebuf; -} - - -const char * -http_get_datetime(HTTPD *httpd) -{ - int rc = 0; - const char *timebuf = NULL; - - if (!httpd) goto quit; - if (!httpd->httpt) goto quit; - if (!httpd->httpt->mqtc) goto quit; - - if (httpd->httpt->flag & HTTPT_FLAG_GMT) { - timebuf = http_gmt_datetime(); - } - else { - timebuf = http_local_datetime(); - } - -quit: - return timebuf; -} - -int -http_pub_datetime(HTTPD *httpd, const char *topic_name) -{ - int rc = 0; - char *timebuf = http_get_timebuf(); - - if (timebuf) { - lock(timebuf, LOCK_EXC); - http_get_datetime(httpd); - rc = http_pubf(httpd, topic_name, timebuf); - unlock(timebuf, LOCK_EXC); - } - -quit: - return rc; -} - -int -http_pub_cache(HTTPD *httpd) -{ - int rc = 0; - int lockrc = 8; - unsigned n; - unsigned count; - HTTPT *httpt; - MQTC *mqtc; - HTTPTC *httptc; - - if (!httpd) goto quit; - if (!httpd->httpt) goto quit; - if (!httpd->httpt->mqtc) goto quit; - - httpt = httpd->httpt; - mqtc = httpt->mqtc; - - if (mqtc->flags & MQTC_FLAG_RECONNECT) { - /* prevent attempts to publish while the MQTT client is in error state */ - goto quit; - } - - lockrc = lock(&httpt->httptc, LOCK_SHR); - - count = array_count(&httpt->httptc); - for(n=0; n < count; n++) { - httptc = httpt->httptc[n]; - - if (!httptc) continue; - - rc = mqtc_pub(mqtc, 0, 1, httptc->topic, httptc->data); - - /* check for errors */ - if (rc) { - wtof("%s: MQTT Publish error: %d", __func__, rc); - rc = -1; - goto quit; - } - } - -quit: - if (lockrc==0) unlock(&httpt->httptc, LOCK_SHR); - - return rc; -} - -static int -telemetry_cache_update(HTTPT *httpt, const char *topic, const char *data) -{ - int lockrc; - unsigned n; - unsigned count; - HTTPTC *httptc; - - lockrc = lock(&httpt->httptc, LOCK_EXC); - - if (!topic) goto quit; - if (!data) data = ""; - - count = array_count(&httpt->httptc); - for(n=0; n < count; n++) { - httptc = httpt->httptc[n]; - - if (!httptc) continue; - if (!httptc->topic) continue; - - if (strcmp(httptc->topic, topic)==0) { - /* found our topic */ - if (httptc->data) { - if (strcmp(httptc->data, data)==0) { - /* data has not changed */ - goto quit; - } - free(httptc->data); - } - httptc->data_len = strlen(data); - httptc->data = strdup(data); - time64(&httptc->last); - goto quit; - } - } - - /* not found in cache */ - httptc = calloc(1, sizeof(HTTPTC)); - if (!httptc) goto quit; - - /* populate new record and add to cache */ - strcpy(httptc->eye, HTTPTC_EYE); - time64(&httptc->last); - httptc->topic_len = strlen(topic); - httptc->topic = strdup(topic); - httptc->data_len = strlen(data); - httptc->data = strdup(data); - array_add(&httpt->httptc, httptc); - -quit: - if (lockrc==0) unlock(&httpt->httptc, LOCK_EXC); - - return 0; -} diff --git a/src/httpstat.c b/src/httpstat.c index 7b78c25..4971c45 100644 --- a/src/httpstat.c +++ b/src/httpstat.c @@ -19,12 +19,6 @@ int httpstat_load(HTTPD *httpd, const char *dataset) { int rc = 0; FILE *fp = NULL; - const char *status = "FAILED"; - const char *timebuf; - unsigned months = 0; - unsigned days = 0; - unsigned hours = 0; - unsigned minutes = 0; HTTPSTAT *stat; int which = -1; int len; @@ -83,19 +77,15 @@ int httpstat_load(HTTPD *httpd, const char *dataset) switch (which) { case RPT_MONTHS: rc = array_add(&httpd->st_month, stat); - months++; break; case RPT_DAYS: rc = array_add(&httpd->st_day, stat); - days++; break; case RPT_HOURS: rc = array_add(&httpd->st_hour, stat); - hours++; break; case RPT_MINS: rc = array_add(&httpd->st_min, stat); - minutes++; break; } /* switch */ @@ -107,25 +97,10 @@ int httpstat_load(HTTPD *httpd, const char *dataset) } /* while */ rc = 0; - status = "SUCCESS"; quit: unlock(lockword, LOCK_SHR); - timebuf = http_get_timebuf(); - if (timebuf) { - lock((char*)timebuf, LOCK_EXC); - http_pubf(httpd, "stats/load", - "{ \"datetime\" : \"%s\" , \"status\" : \"%s\" , \"rc\" : %d , \"dataset\" : \"%s\" " - ", \"months\" : %u , \"days\" : %u , \"hours\" : %u , \"minutes\" : %u " - "}", - http_get_datetime(httpd), status, rc, dataset, months, days, hours, minutes); - unlock((char*)timebuf, LOCK_EXC); - - /* delete the "stats/save" topic */ - http_pubf(httpd, "stats/save", ""); - } - if (fp) fclose(fp); return rc; @@ -135,12 +110,6 @@ int httpstat_save(HTTPD *httpd, const char *dataset) { int rc = 0; FILE *fp = NULL; - const char *status = "FAILED"; - unsigned months = 0; - unsigned days = 0; - unsigned hours = 0; - unsigned minutes = 0; - char *timebuf; lock(lockword, LOCK_SHR); @@ -149,7 +118,7 @@ int httpstat_save(HTTPD *httpd, const char *dataset) wtof("HTTPD430E Unable to open \"%s\" for output", dataset); goto quit; } - + if (httpd->st_month) { rc = save_stats(fp, &httpd->st_month, "MONTH"); if (rc) goto quit; @@ -167,27 +136,9 @@ int httpstat_save(HTTPD *httpd, const char *dataset) if (rc) goto quit; } - status = "SUCCESS"; - quit: - months = array_count(&httpd->st_month); - days = array_count(&httpd->st_day); - hours = array_count(&httpd->st_hour); - minutes = array_count(&httpd->st_min); - unlock(lockword, LOCK_SHR); - timebuf = http_get_timebuf(); - if (timebuf) { - lock(timebuf, LOCK_EXC); - http_pubf(httpd, "stats/save", - "{ \"datetime\" : \"%s\" , \"status\" : \"%s\" , \"rc\" : %d , \"dataset\" : \"%s\" " - ", \"months\" : %u , \"days\" : %u , \"hours\" : %u , \"minutes\" : %u " - "}", - http_get_datetime(httpd), status, rc, dataset, months, days, hours, minutes); - unlock(timebuf, LOCK_EXC); - } - if (fp) fclose(fp); return rc; } diff --git a/src/httpx.c b/src/httpx.c index f72101c..796a06c 100644 --- a/src/httpx.c +++ b/src/httpx.c @@ -72,7 +72,7 @@ static HTTPX vect = { http_find_cgi, /* 100 http_find_cgi() */ http_add_cgi, /* 104 http_add_cgi() */ http_process_cgi, /* 108 http_process_cgi() */ - mqtc_pub, /* 10C mqtc_pub() */ + NULL, /* 10C (was: mqtc_pub) */ http_xlate, /* 110 http_xlate() */ &http_cp037, /* 114 CP037 codepage pair */ &http_cp1047, /* 118 IBM-1047 codepage pair */ From ccf0ddbd7a05a4a65bd98c05fcc768a0044dfe9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Gro=C3=9Fmann?= Date: Wed, 8 Apr 2026 19:01:07 +0200 Subject: [PATCH 2/3] Remove MQTT code from Lua publish binding The http_lua_publish() function referenced HTTPT, MQTC, and mqtc_pub which no longer exist after the MQTT telemetry removal. Replace the function body with a stub that returns "not available". Fixes #44 --- src/httplua.c | 41 ----------------------------------------- 1 file changed, 41 deletions(-) diff --git a/src/httplua.c b/src/httplua.c index 3e873f0..23c3b29 100644 --- a/src/httplua.c +++ b/src/httplua.c @@ -1068,47 +1068,6 @@ static int alloc_dummy(char *ddname) { } static int http_lua_publish(lua_State *L) { - HTTPD *httpd = cgihttpd(); - HTTPT *httpt; - MQTC *mqtc; - int rc; - const char *topic = luaL_checkstring(L, 1); - const char *data = luaL_optstring(L, 2, ""); - - if (!httpd) - goto quit; - if (!httpd->httpt) - goto quit; - if (!httpd->httpt->mqtc) - goto quit; - - if (!topic) - goto quit; - if (!data) - goto quit; - - httpt = httpd->httpt; - mqtc = httpt->mqtc; - - if (mqtc->flags & MQTC_FLAG_RECONNECT) { - /* prevent attempts to publish while the MQTT client is in error state */ - goto quit; - } - - rc = mqtc_pub(mqtc, 0, 1, topic, data); - - /* check for errors */ - if (rc) { - lua_pushinteger(L, 8); - lua_pushfstring(L, "publish: client error: %d", rc); - return 2; - } - - lua_pushinteger(L, 0); - lua_pushstring(L, "publish: okay"); - return 2; - -quit: lua_pushinteger(L, 4); lua_pushstring(L, "publish: not available"); return 2; From bed8e61633dc2a9c2e25e08f384da330b7ab761d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Gro=C3=9Fmann?= Date: Wed, 8 Apr 2026 20:13:26 +0200 Subject: [PATCH 3/3] fix: remove remaining http_pubf calls and fix HTTPLUAX macro in publish stub httpd048.c still called http_pubf() (MQTT telemetry), causing unresolved external HTTP@PUB at link time. http_lua_publish() stub used lua_pushinteger which expands via HTTPLUAX macro to httpd->luax, requiring an httpd pointer. --- src/httpd048.c | 2 -- src/httplua.c | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/httpd048.c b/src/httpd048.c index ba7a169..09884c8 100644 --- a/src/httpd048.c +++ b/src/httpd048.c @@ -8,7 +8,6 @@ httpd048(HTTPD *httpd) if (!(httpd->login & HTTPD_LOGIN_ALL)) { wtof("HTTPD048I Login not required for any request"); - http_pubf(httpd, "login", "none"); goto quit; } @@ -30,7 +29,6 @@ httpd048(HTTPD *httpd) } } wtof("HTTPD048I Login required for (%s) request", buf); - http_pubf(httpd, "login", "%s", buf); quit: return rc; diff --git a/src/httplua.c b/src/httplua.c index 23c3b29..9110390 100644 --- a/src/httplua.c +++ b/src/httplua.c @@ -1067,7 +1067,9 @@ static int alloc_dummy(char *ddname) { return err; } +/* TSK-104: HTTPLUA moves to external project, httpd->luax dependency goes away */ static int http_lua_publish(lua_State *L) { + HTTPD *httpd = cgihttpd(); /* needed for HTTPLUAX macro expansion */ lua_pushinteger(L, 4); lua_pushstring(L, "publish: not available"); return 2;