Commits (1)
  • Rob Swindell's avatar
    Second part of MQTT overhaul · a960f2c8
    Rob Swindell authored
    Now support subscriptions (e.g. recycle topics, node input topics) in SBBSCTRL.
    This required a lot of search/replace and fun with circular struct pointers.
    a960f2c8
......@@ -582,7 +582,7 @@ bool sbbs_t::update_nodeterm(void)
,mouse_mode
,console
);
mqtt_pub_strval(&startup->mqtt, TOPIC_BBS, topic, str);
mqtt_pub_strval((struct startup*)startup, TOPIC_BBS, topic, str);
}
return result;
}
......
......@@ -171,7 +171,7 @@ static void thread_up(void* p, BOOL up, BOOL setuid)
threads++;
else if(threads>0)
threads--;
mqtt_thread_count(&MainForm->bbs_startup.mqtt, TOPIC_HOST, threads);
mqtt_thread_count((struct startup*)&MainForm->bbs_startup, TOPIC_HOST, threads);
ReleaseMutex(mutex);
}
......@@ -189,7 +189,7 @@ void socket_open(void* p, BOOL open)
sockets++;
else if(sockets>0)
sockets--;
mqtt_socket_count(&MainForm->bbs_startup.mqtt, TOPIC_HOST, sockets);
mqtt_socket_count((struct startup*)&MainForm->bbs_startup, TOPIC_HOST, sockets);
ReleaseMutex(mutex);
}
......@@ -203,10 +203,10 @@ static void client_add(void* p, BOOL add)
if(add) {
clients++;
total_clients++;
mqtt_served_count(&MainForm->bbs_startup.mqtt, TOPIC_HOST, total_clients);
mqtt_served_count((struct startup*)&MainForm->bbs_startup, TOPIC_HOST, total_clients);
} else if(clients>0)
clients--;
mqtt_client_count(&MainForm->bbs_startup.mqtt, TOPIC_HOST, clients);
mqtt_client_count((struct startup*)&MainForm->bbs_startup, TOPIC_HOST, clients);
}
static void client_on(void* p, BOOL on, int sock, client_t* client, BOOL update)
......@@ -217,7 +217,7 @@ static void client_on(void* p, BOOL on, int sock, client_t* client, BOOL update)
static HANDLE mutex;
TListItem* Item;
mqtt_client_on(&MainForm->bbs_startup.mqtt, on, sock, client, update);
mqtt_client_on((struct startup*)&MainForm->bbs_startup, on, sock, client, update);
if(!mutex)
mutex=CreateMutex(NULL,false,NULL);
......@@ -338,7 +338,7 @@ static void bbs_set_state(void* p, enum server_state state)
{
TelnetForm->Status->Caption = server_state_str(state);
mqtt_server_state(&MainForm->bbs_startup.mqtt, state);
mqtt_server_state((struct startup*)&MainForm->bbs_startup, state);
switch(state) {
case SERVER_STOPPED:
MainForm->TelnetStart->Enabled=true;
......@@ -436,7 +436,7 @@ static void services_set_state(void* p, enum server_state state)
{
ServicesForm->Status->Caption = server_state_str(state);
mqtt_server_state(&MainForm->services_startup.mqtt, state);
mqtt_server_state((struct startup*)&MainForm->services_startup, state);
switch(state) {
case SERVER_STOPPED:
MainForm->ServicesStart->Enabled=true;
......@@ -503,7 +503,7 @@ static void mail_set_state(void* p, enum server_state state)
{
MailForm->Status->Caption = server_state_str(state);
mqtt_server_state(&MainForm->mail_startup.mqtt, state);
mqtt_server_state((struct startup*)&MainForm->mail_startup, state);
switch(state) {
case SERVER_STOPPED:
MainForm->MailStart->Enabled=true;
......@@ -599,7 +599,7 @@ static void ftp_set_state(void* p, enum server_state state)
{
FtpForm->Status->Caption = server_state_str(state);
mqtt_server_state(&MainForm->ftp_startup.mqtt, state);
mqtt_server_state((struct startup*)&MainForm->ftp_startup, state);
switch(state) {
case SERVER_STOPPED:
MainForm->FtpStart->Enabled=true;
......@@ -668,7 +668,7 @@ static void web_set_state(void* p, enum server_state state)
{
WebForm->Status->Caption = server_state_str(state);
mqtt_server_state(&MainForm->web_startup.mqtt, state);
mqtt_server_state((struct startup*)&MainForm->web_startup, state);
switch(state) {
case SERVER_STOPPED:
MainForm->WebStart->Enabled=true;
......@@ -1054,7 +1054,7 @@ BOOL __fastcall TMainForm::servicesServiceEnabled(void)
//---------------------------------------------------------------------------
void __fastcall TMainForm::FormClose(TObject *Sender, TCloseAction &Action)
{
mqtt_terminating(&bbs_startup.mqtt);
mqtt_terminating((struct startup*)&bbs_startup);
UpTimer->Enabled=false; /* Stop updating the status bar */
StatsTimer->Enabled=false;
......@@ -1083,14 +1083,14 @@ void __fastcall TMainForm::FormClose(TObject *Sender, TCloseAction &Action)
}
StatusBar->Panels->Items[STATUSBAR_LAST_PANEL]->Text="Closing...";
Application->ProcessMessages();
mqtt_terminating(&bbs_startup.mqtt);
mqtt_terminating((struct startup*)&bbs_startup);
LogTimer->Enabled=false;
ServiceStatusTimer->Enabled=false;
NodeForm->Timer->Enabled=false;
ClientForm->Timer->Enabled=false;
mqtt_shutdown(&bbs_startup.mqtt);
mqtt_shutdown((struct startup*)&bbs_startup);
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FormCloseQuery(TObject *Sender, bool &CanClose)
......@@ -1971,20 +1971,21 @@ void __fastcall TMainForm::StartupTimerTick(TObject *Sender)
StartupTimer->Enabled = true;
} else {
if(!bbsServiceEnabled()) {
mqtt_startup(&bbs_startup.mqtt, &cfg, SERVER_TERM, ver()
bbs_startup.startup[SERVER_TERM] = (struct startup*)&bbs_startup;
bbs_startup.startup[SERVER_FTP] = (struct startup*)&ftp_startup;
bbs_startup.startup[SERVER_WEB] = (struct startup*)&web_startup;
bbs_startup.startup[SERVER_MAIL] = (struct startup*)&mail_startup;
bbs_startup.startup[SERVER_SERVICES] = (struct startup*)&services_startup;
mqtt_startup((struct startup*)&bbs_startup, &cfg, ver()
,/* lputs: */NULL
,/* shared_client_list: */TRUE);
ftp_startup.mqtt = bbs_startup.mqtt;
ftp_startup.mqtt.server_type = SERVER_FTP;
web_startup.mqtt = bbs_startup.mqtt;
web_startup.mqtt.server_type = SERVER_WEB;
mail_startup.mqtt = bbs_startup.mqtt;
mail_startup.mqtt.server_type = SERVER_MAIL;
services_startup.mqtt = bbs_startup.mqtt;
services_startup.mqtt.server_type = SERVER_SERVICES;
}
DisplayMainPanels(Sender);
mqtt_online(&bbs_startup.mqtt);
mqtt_online((struct startup*)&bbs_startup);
}
Initialized=true;
}
......
......@@ -142,13 +142,13 @@ static int lprintf(int level, const char *fmt, ...)
if(level <= LOG_ERR) {
char errmsg[sizeof(sbuf)+16];
errorlog(&scfg, &startup->mqtt, level, startup==NULL ? NULL:startup->host_name, sbuf);
errorlog(&scfg, (struct startup*)startup, level, startup==NULL ? NULL:startup->host_name, sbuf);
SAFEPRINTF2(errmsg, "%s %s", server_abbrev, sbuf);
if(startup!=NULL && startup->errormsg!=NULL)
startup->errormsg(startup->cbdata,level,errmsg);
}
if(startup != NULL)
mqtt_lputs(&startup->mqtt, TOPIC_SERVER, level, sbuf);
mqtt_lputs((struct startup*)startup, TOPIC_SERVER, level, sbuf);
if(startup==NULL || startup->lputs==NULL || level > startup->log_level)
return(0);
......@@ -199,7 +199,7 @@ static void set_state(enum server_state state)
if(startup != NULL) {
if(startup->set_state != NULL)
startup->set_state(startup->cbdata, state);
mqtt_server_state(&startup->mqtt, state);
mqtt_server_state((struct startup*)startup, state);
}
}
......@@ -209,7 +209,7 @@ static void update_clients(void)
uint32_t count = protected_uint32_value(active_clients);
if(startup->clients != NULL)
startup->clients(startup->cbdata, count);
mqtt_client_count(&startup->mqtt, TOPIC_SERVER, count);
mqtt_client_count((struct startup*)startup, TOPIC_SERVER, count);
}
}
......@@ -233,7 +233,7 @@ static void thread_up(BOOL setuid)
if(startup != NULL) {
if(startup->thread_up != NULL)
startup->thread_up(startup->cbdata,TRUE, setuid);
mqtt_thread_count(&startup->mqtt, TOPIC_SERVER, protected_uint32_value(thread_count));
mqtt_thread_count((struct startup*)startup, TOPIC_SERVER, protected_uint32_value(thread_count));
}
}
......@@ -243,7 +243,7 @@ static int32_t thread_down(void)
if(startup != NULL) {
if(startup->thread_up != NULL)
startup->thread_up(startup->cbdata,FALSE, FALSE);
mqtt_thread_count(&startup->mqtt, TOPIC_SERVER, count);
mqtt_thread_count((struct startup*)startup, TOPIC_SERVER, count);
}
return count;
}
......@@ -1726,7 +1726,7 @@ static BOOL ftp_hacklog(char* prot, char* user, char* text, char* host, union xp
PlaySound(startup->sound.hack, NULL, SND_ASYNC|SND_FILENAME);
#endif
return hacklog(&scfg, &startup->mqtt, prot, user, text, host, addr);
return hacklog(&scfg, (struct startup*)startup, prot, user, text, host, addr);
}
/****************************************************************************/
......@@ -4955,7 +4955,7 @@ void ftp_server(void* arg)
}
set_state(SERVER_INIT);
mqtt_server_version(&startup->mqtt, ftp_ver());
mqtt_server_version((struct startup*)startup, ftp_ver());
uptime=0;
served=0;
......@@ -5096,7 +5096,7 @@ void ftp_server(void* arg)
set_state(SERVER_READY);
lprintf(LOG_INFO,"FTP Server thread started");
mqtt_client_max(&startup->mqtt, startup->max_clients);
mqtt_client_max((struct startup*)startup, startup->max_clients);
while(ftp_set!=NULL && !terminate_server) {
YIELD();
......
......@@ -25,7 +25,7 @@
const char* log_line_ending = "\r\n";
extern "C" BOOL hacklog(scfg_t* cfg, struct mqtt* mqtt, const char* prot, const char* user, const char* text, const char* host, union xp_sockaddr* addr)
extern "C" BOOL hacklog(scfg_t* cfg, struct startup* startup, const char* prot, const char* user, const char* text, const char* host, union xp_sockaddr* addr)
{
char tstr[64];
char fname[MAX_PATH+1];
......@@ -54,12 +54,12 @@ extern "C" BOOL hacklog(scfg_t* cfg, struct mqtt* mqtt, const char* prot, const
fputs(log_line_ending, fp);
fcloselog(fp);
if(mqtt != NULL) {
if(startup != NULL) {
char str[1024];
if(text == NULL)
text= "";
snprintf(str, sizeof(str), "%s\t%s\t%u\t%s\t%s\t%s", prot, user, inet_addrport(addr), host, ip, text);
mqtt_pub_strval(mqtt, TOPIC_HOST, "hack", str);
mqtt_pub_strval(startup, TOPIC_HOST, "hack", str);
}
return true;
......@@ -67,10 +67,10 @@ extern "C" BOOL hacklog(scfg_t* cfg, struct mqtt* mqtt, const char* prot, const
BOOL sbbs_t::hacklog(const char* prot, const char* text)
{
return ::hacklog(&cfg, &startup->mqtt, prot, useron.alias, text, client_name, &client_addr);
return ::hacklog(&cfg, (struct startup*)startup, prot, useron.alias, text, client_name, &client_addr);
}
extern "C" BOOL spamlog(scfg_t* cfg, struct mqtt* mqtt, char* prot, char* action
extern "C" BOOL spamlog(scfg_t* cfg, struct startup* startup, char* prot, char* action
,char* reason, char* host, char* ip_addr
,char* to, char* from)
{
......@@ -110,18 +110,18 @@ extern "C" BOOL spamlog(scfg_t* cfg, struct mqtt* mqtt, char* prot, char* action
fputs(log_line_ending, fp);
fcloselog(fp);
if(mqtt != NULL) {
if(startup != NULL) {
char str[1024];
if(reason == NULL)
reason = (char*)"";
snprintf(str, sizeof(str), "%s\t%s\t%s\t%s\t%s\t%s\t%s", prot, action, host, ip_addr, from, to_user, reason);
mqtt_pub_strval(mqtt, TOPIC_HOST, "spam", str);
mqtt_pub_strval(startup, TOPIC_HOST, "spam", str);
}
return true;
}
extern "C" int errorlog(scfg_t* cfg, struct mqtt* mqtt, int level, const char* host, const char* text)
extern "C" int errorlog(scfg_t* cfg, struct startup* startup, int level, const char* host, const char* text)
{
FILE* fp;
char buf[128];
......@@ -150,7 +150,7 @@ extern "C" int errorlog(scfg_t* cfg, struct mqtt* mqtt, int level, const char* h
SAFEPRINTF2(subject, "%s %sERROR occurred", host, level <= LOG_CRIT ? "CRITICAL " : "");
notify(cfg, cfg->node_erruser, subject, text);
}
mqtt_errormsg(mqtt, level, text);
mqtt_errormsg(startup, level, text);
return 0;
}
......
......@@ -145,7 +145,7 @@ void sbbs_t::badlogin(const char* user, const char* passwd, const char* protocol
count=loginFailure(startup->login_attempt_list, addr, protocol, user, passwd);
if(user!=NULL && startup->login_attempt.hack_threshold && count>=startup->login_attempt.hack_threshold) {
getnameinfo(&addr->addr, addr_len, host_name, sizeof(host_name), NULL, 0, NI_NAMEREQD);
::hacklog(&cfg, &startup->mqtt, reason, user, passwd, host_name, addr);
::hacklog(&cfg, (struct startup*)startup, reason, user, passwd, host_name, addr);
#ifdef _WIN32
if(startup->sound.hack[0] && !sound_muted(&cfg))
PlaySound(startup->sound.hack, NULL, SND_ASYNC|SND_FILENAME);
......
......@@ -191,7 +191,7 @@ static int lprintf(int level, const char *fmt, ...)
if(level <= LOG_ERR) {
char errmsg[sizeof(sbuf)+16];
errorlog(&scfg, &startup->mqtt, level, startup==NULL ? NULL:startup->host_name, sbuf), stats.errors++;
errorlog(&scfg, (struct startup*)startup, level, startup==NULL ? NULL:startup->host_name, sbuf), stats.errors++;
SAFEPRINTF2(errmsg, "%s %s", server_abbrev, sbuf);
if(startup!=NULL && startup->errormsg!=NULL)
startup->errormsg(startup->cbdata,level,errmsg);
......@@ -201,7 +201,7 @@ static int lprintf(int level, const char *fmt, ...)
stats.crit_errors++;
if(startup != NULL)
mqtt_lputs(&startup->mqtt, TOPIC_SERVER, level, sbuf);
mqtt_lputs((struct startup*)startup, TOPIC_SERVER, level, sbuf);
if(startup==NULL || startup->lputs==NULL || level > startup->log_level)
return(0);
......@@ -251,7 +251,7 @@ static void set_state(enum server_state state)
if(startup != NULL) {
if(startup->set_state != NULL)
startup->set_state(startup->cbdata, state);
mqtt_server_state(&startup->mqtt, state);
mqtt_server_state((struct startup*)startup, state);
}
}
......@@ -260,7 +260,7 @@ static void update_clients(void)
if(startup != NULL) {
if(startup->clients != NULL)
startup->clients(startup->cbdata,protected_uint32_value(active_clients)+active_sendmail);
mqtt_client_count(&startup->mqtt, TOPIC_SERVER, protected_uint32_value(active_clients));
mqtt_client_count((struct startup*)startup, TOPIC_SERVER, protected_uint32_value(active_clients));
}
}
......@@ -284,7 +284,7 @@ static void thread_up(BOOL setuid)
if(startup != NULL) {
if(startup->thread_up != NULL)
startup->thread_up(startup->cbdata,TRUE,setuid);
mqtt_thread_count(&startup->mqtt, TOPIC_SERVER, protected_uint32_value(thread_count));
mqtt_thread_count((struct startup*)startup, TOPIC_SERVER, protected_uint32_value(thread_count));
}
}
......@@ -294,7 +294,7 @@ static int32_t thread_down(void)
if(startup != NULL) {
if(startup->thread_up != NULL)
startup->thread_up(startup->cbdata,FALSE,FALSE);
mqtt_thread_count(&startup->mqtt, TOPIC_SERVER, count);
mqtt_thread_count((struct startup*)startup, TOPIC_SERVER, count);
}
return count;
}
......@@ -313,7 +313,7 @@ void mail_open_socket(SOCKET sock, void* cb_protocol)
stats.sockets++;
if(startup != NULL)
mqtt_socket_count(&startup->mqtt, TOPIC_SERVER, stats.sockets);
mqtt_socket_count((struct startup*)startup, TOPIC_SERVER, stats.sockets);
}
void mail_close_socket_cb(SOCKET sock, void* cb_protocol)
......@@ -322,7 +322,7 @@ void mail_close_socket_cb(SOCKET sock, void* cb_protocol)
startup->socket_open(startup->cbdata,FALSE);
stats.sockets--;
if(startup != NULL)
mqtt_socket_count(&startup->mqtt, TOPIC_SERVER, stats.sockets);
mqtt_socket_count((struct startup*)startup, TOPIC_SERVER, stats.sockets);
}
int mail_close_socket(SOCKET *sock, int *sess)
......@@ -342,7 +342,7 @@ int mail_close_socket(SOCKET *sock, int *sess)
startup->socket_open(startup->cbdata,FALSE);
stats.sockets--;
if(startup != NULL)
mqtt_socket_count(&startup->mqtt, TOPIC_SERVER, stats.sockets);
mqtt_socket_count((struct startup*)startup, TOPIC_SERVER, stats.sockets);
if(result!=0) {
if(ERROR_VALUE!=ENOTSOCK)
lprintf(LOG_WARNING,"%04d !ERROR %d closing socket",*sock, ERROR_VALUE);
......@@ -981,7 +981,7 @@ static void badlogin(SOCKET sock, CRYPT_SESSION sess, const char* prot, const ch
SAFEPRINTF(reason,"%s LOGIN", prot);
count=loginFailure(startup->login_attempt_list, addr, prot, user, passwd);
if(startup->login_attempt.hack_threshold && count>=startup->login_attempt.hack_threshold) {
hacklog(&scfg, &startup->mqtt, reason, user, passwd, host, addr);
hacklog(&scfg, (struct startup*)startup, reason, user, passwd, host, addr);
#ifdef _WIN32
if(startup->sound.hack[0] && !sound_muted(&scfg))
PlaySound(startup->sound.hack, NULL, SND_ASYNC|SND_FILENAME);
......@@ -1916,7 +1916,7 @@ static BOOL chk_email_addr(SOCKET socket, const char* prot, char* p, char* host_
lprintf(LOG_NOTICE,"%04d %s [%s] !BLOCKED %s e-mail address: %s"
,socket, prot, host_ip, source, addr);
SAFEPRINTF2(tmp,"Blocked %s e-mail address: %s", source, addr);
spamlog(&scfg, &startup->mqtt, (char*)prot, "REFUSED", tmp, host_name, host_ip, to, from);
spamlog(&scfg, (struct startup*)startup, (char*)prot, "REFUSED", tmp, host_name, host_ip, to, from);
return(FALSE);
}
......@@ -3112,7 +3112,7 @@ static void smtp_thread(void* arg)
,socket, client.protocol, dnsbl_ip, dnsbl, host_name, inet_ntoa(dnsbl_result));
if(startup->options&MAIL_OPT_DNSBL_REFUSE) {
SAFEPRINTF2(str,"Listed on %s as %s", dnsbl, inet_ntoa(dnsbl_result));
spamlog(&scfg, &startup->mqtt, (char*)client.protocol, "SESSION REFUSED", str, host_name, dnsbl_ip, NULL, NULL);
spamlog(&scfg, (struct startup*)startup, (char*)client.protocol, "SESSION REFUSED", str, host_name, dnsbl_ip, NULL, NULL);
sockprintf(socket,client.protocol,session
,"550 Mail from %s refused due to listing at %s"
,dnsbl_ip, dnsbl);
......@@ -3238,7 +3238,7 @@ static void smtp_thread(void* arg)
lprintf(LOG_NOTICE,"%04d %s %s !FILTERING TWIT-LISTED SENDER: '%s' <%s> (%lu total)"
,socket, client.protocol, client_id, sender, sender_addr, ++stats.msgs_refused);
SAFEPRINTF2(tmp,"Twit-listed sender: '%s' <%s>", sender, sender_addr);
spamlog(&scfg, &startup->mqtt, (char*)client.protocol, "REFUSED", tmp, host_name, host_ip, rcpt_addr, reverse_path);
spamlog(&scfg, (struct startup*)startup, (char*)client.protocol, "REFUSED", tmp, host_name, host_ip, rcpt_addr, reverse_path);
sockprintf(socket,client.protocol,session, "554 Sender not allowed.");
continue;
}
......@@ -3512,7 +3512,7 @@ static void smtp_thread(void* arg)
,socket, client.protocol, client_id, p, reverse_path, ++stats.msgs_refused);
SAFEPRINTF2(tmp,"Blocked subject (%s) from: %s"
,p, reverse_path);
spamlog(&scfg, &startup->mqtt, (char*)client.protocol, "REFUSED"
spamlog(&scfg, (struct startup*)startup, (char*)client.protocol, "REFUSED"
,tmp, host_name, host_ip, rcpt_addr, reverse_path);
errmsg="554 Subject not allowed.";
smb_error=SMB_FAILURE;
......@@ -3615,7 +3615,7 @@ static void smtp_thread(void* arg)
}
if(startup->dnsbl_hdr[0] || startup->dnsbl_tag[0]) {
SAFEPRINTF2(str,"Listed on %s as %s", dnsbl, inet_ntoa(dnsbl_result));
spamlog(&scfg, &startup->mqtt, (char*)client.protocol, "TAGGED", str, host_name, dnsbl_ip, rcpt_addr, reverse_path);
spamlog(&scfg, (struct startup*)startup, (char*)client.protocol, "TAGGED", str, host_name, dnsbl_ip, rcpt_addr, reverse_path);
}
}
if(dnsbl_recvhdr) /* DNSBL-listed IP found in Received header? */
......@@ -3804,7 +3804,7 @@ static void smtp_thread(void* arg)
);
lprintf(LOG_NOTICE,"%04d %s %s Message from %s %s", socket, client.protocol, client_id, sender_info, str);
if(!is_spam) {
spamlog(&scfg, &startup->mqtt, (char*)client.protocol, "IGNORED"
spamlog(&scfg, (struct startup*)startup, (char*)client.protocol, "IGNORED"
,str, host_name, host_ip, rcpt_addr, reverse_path);
is_spam=TRUE;
}
......@@ -3849,7 +3849,7 @@ static void smtp_thread(void* arg)
SAFEPRINTF2(str,"Listed on %s as %s", dnsbl, inet_ntoa(dnsbl_result));
lprintf(LOG_NOTICE,"%04d %s %s !IGNORED MAIL from %s to <%s> from server: %s (%lu total)"
,socket, client.protocol, client_id, sender_info, rcpt_addr, str, ++stats.msgs_ignored);
spamlog(&scfg, &startup->mqtt, (char*)client.protocol, "IGNORED"
spamlog(&scfg, (struct startup*)startup, (char*)client.protocol, "IGNORED"
,str, host_name, dnsbl_ip, rcpt_addr, reverse_path);
}
/* pretend we received it */
......@@ -4508,7 +4508,7 @@ static void smtp_thread(void* arg)
lprintf(LOG_NOTICE,"%04d %s %s !MAXIMUM RECIPIENTS (%d) REACHED"
,socket, client.protocol, client_id, startup->max_recipients);
SAFEPRINTF(tmp,"Maximum recipient count (%d)",startup->max_recipients);
spamlog(&scfg, &startup->mqtt, (char*)client.protocol, "REFUSED", tmp
spamlog(&scfg, (struct startup*)startup, (char*)client.protocol, "REFUSED", tmp
,host_name, host_ip, rcpt_addr, reverse_path);
sockprintf(socket,client.protocol,session, "452 Too many recipients");
stats.msgs_refused++;
......@@ -4530,7 +4530,7 @@ static void smtp_thread(void* arg)
,socket, client.protocol, client_id, scfg.level_emailperday[relay_user.level], relay_user.number, relay_user.alias);
SAFEPRINTF2(tmp,"Maximum emails per day (%u) for %s"
,scfg.level_emailperday[relay_user.level], relay_user.alias);
spamlog(&scfg, &startup->mqtt, (char*)client.protocol, "REFUSED", tmp
spamlog(&scfg, (struct startup*)startup, (char*)client.protocol, "REFUSED", tmp
,host_name, host_ip, rcpt_addr, reverse_path);
sockprintf(socket,client.protocol,session, "452 Too many emails today");
stats.msgs_refused++;
......@@ -4551,7 +4551,7 @@ static void smtp_thread(void* arg)
filter_ip(&scfg, client.protocol, reason, host_name, host_ip, reverse_path, spam_block);
strcat(tmp," and BLOCKED");
}
spamlog(&scfg, &startup->mqtt, (char*)client.protocol, tmp, "Attempted recipient in SPAM BAIT list"
spamlog(&scfg, (struct startup*)startup, (char*)client.protocol, tmp, "Attempted recipient in SPAM BAIT list"
,host_name, host_ip, rcpt_addr, reverse_path);
dnsbl_result.s_addr=0;
}
......@@ -4572,7 +4572,7 @@ static void smtp_thread(void* arg)
lprintf(LOG_NOTICE,"%04d %s %s !REFUSED MAIL from blacklisted server (%lu total)"
,socket, client.protocol, client_id, ++stats.sessions_refused);
SAFEPRINTF2(str,"Listed on %s as %s", dnsbl, inet_ntoa(dnsbl_result));
spamlog(&scfg, &startup->mqtt, (char*)client.protocol, "REFUSED", str, host_name, host_ip, rcpt_addr, reverse_path);
spamlog(&scfg, (struct startup*)startup, (char*)client.protocol, "REFUSED", str, host_name, host_ip, rcpt_addr, reverse_path);
sockprintf(socket,client.protocol,session
,"550 Mail from %s refused due to listing at %s"
,host_ip, dnsbl);
......@@ -4666,7 +4666,7 @@ static void smtp_thread(void* arg)
lprintf(LOG_WARNING,"%04d %s %s !ILLEGAL RELAY ATTEMPT from %s [%s] to %s"
,socket, client.protocol, client_id, reverse_path, host_ip, p);
SAFEPRINTF(tmp,"Relay attempt to: %s", p);
spamlog(&scfg, &startup->mqtt, (char*)client.protocol, "REFUSED", tmp, host_name, host_ip, rcpt_addr, reverse_path);
spamlog(&scfg, (struct startup*)startup, (char*)client.protocol, "REFUSED", tmp, host_name, host_ip, rcpt_addr, reverse_path);
if(startup->options&MAIL_OPT_ALLOW_RELAY)
sockprintf(socket,client.protocol,session, "553 Relaying through this server "
"requires authentication. "
......@@ -6055,7 +6055,7 @@ void mail_server(void* arg)
set_state(SERVER_INIT);
mqtt_server_version(&startup->mqtt, mail_ver());
mqtt_server_version((struct startup*)startup, mail_ver());
ZERO_VAR(js_server_props);
SAFEPRINTF3(js_server_props.version,"%s %s%c",server_name, VERSION, REVISION);
......@@ -6276,7 +6276,7 @@ void mail_server(void* arg)
set_state(SERVER_READY);
lprintf(LOG_INFO,"Mail Server thread started");
mqtt_client_max(&startup->mqtt, startup->max_clients);
mqtt_client_max((struct startup*)startup, startup->max_clients);
while(!terminated && !terminate_server) {
YIELD();
......
......@@ -163,7 +163,7 @@ static void set_state(enum server_state state)
if(startup != NULL) {
if(startup->set_state != NULL)
startup->set_state(startup->cbdata, state);
mqtt_server_state(&startup->mqtt, state);
mqtt_server_state((struct startup*)startup, state);
}
}
......@@ -172,7 +172,7 @@ static void update_clients()
if(startup != NULL) {
if(startup->clients != NULL)
startup->clients(startup->cbdata,protected_uint32_value(node_threads_running));
mqtt_client_count(&startup->mqtt, TOPIC_SERVER, protected_uint32_value(node_threads_running));
mqtt_client_count((struct startup*)startup, TOPIC_SERVER, protected_uint32_value(node_threads_running));
}
}
......@@ -206,10 +206,10 @@ static void thread_down()
int lputs(int level, const char* str)
{
if(startup != NULL)
mqtt_lputs(&startup->mqtt, TOPIC_SERVER, level, str);
mqtt_lputs((struct startup*)startup, TOPIC_SERVER, level, str);
if(level <= LOG_ERR) {
char errmsg[1024];
errorlog(&scfg, &startup->mqtt, level, startup==NULL ? NULL:startup->host_name, str);
errorlog(&scfg, (struct startup*)startup, level, startup==NULL ? NULL:startup->host_name, str);
SAFEPRINTF2(errmsg, "%s %s", server_abbrev, str);
if(startup!=NULL && startup->errormsg!=NULL)
startup->errormsg(startup->cbdata,level,errmsg);
......@@ -232,11 +232,11 @@ int eputs(int level, const char *str)
return 0;
if(startup != NULL)
mqtt_lputs(&startup->mqtt, TOPIC_EVENT, level, str);
mqtt_lputs((struct startup*)startup, TOPIC_EVENT, level, str);
if(level <= LOG_ERR) {
char errmsg[1024];
errorlog(&scfg, &startup->mqtt, level, startup==NULL ? NULL:startup->host_name, str);
errorlog(&scfg, (struct startup*)startup, level, startup==NULL ? NULL:startup->host_name, str);
SAFEPRINTF(errmsg, "evnt %s", str);
if(startup!=NULL && startup->errormsg!=NULL)
startup->errormsg(startup->cbdata, level, errmsg);
......@@ -2483,7 +2483,7 @@ void output_thread(void* arg)
}
/* Spy on the user remotely */
if(sbbs->cfg.mqtt.enabled) {
int result = mqtt_pub_message(&startup->mqtt, TOPIC_BBS, spy_topic, buf+bufbot, i);
int result = mqtt_pub_message((struct startup*)startup, TOPIC_BBS, spy_topic, buf+bufbot, i);
if(result != MQTT_SUCCESS)
lprintf(LOG_WARNING, "%s ERROR %d (%d) publishing node output (%u bytes): %s"
,node, result, errno, i, spy_topic);
......@@ -4410,7 +4410,7 @@ void node_thread(void* arg)
char topic[128];
SAFEPRINTF(topic, "node%u/laston", sbbs->cfg.node_num);
SAFEPRINTF2(str, "%u\t%s", sbbs->useron.number, sbbs->useron.alias);
mqtt_pub_strval(&startup->mqtt, TOPIC_BBS, topic, str);
mqtt_pub_strval((struct startup*)startup, TOPIC_BBS, topic, str);
}
if(sbbs->sys_status&SS_DAILY) { // New day, run daily events/maintenance
......@@ -4940,7 +4940,7 @@ void bbs_thread(void* arg)
cleanup(1);
return;
}
mqtt_server_version(&startup->mqtt, bbs_ver());
mqtt_server_version((struct startup*)startup, bbs_ver());
t=time(NULL);
lprintf(LOG_INFO,"Initializing on %.24s with options: %x"
......@@ -4985,7 +4985,7 @@ void bbs_thread(void* arg)
startup->last_node=scfg.sys_nodes;
}
mqtt_pub_uintval(&startup->mqtt, TOPIC_BBS, "node_count", scfg.sys_nodes);
mqtt_pub_uintval((struct startup*)startup, TOPIC_BBS, "node_count", scfg.sys_nodes);
/* Create missing directories */
lprintf(LOG_INFO,"Verifying/creating data directories");
......@@ -5232,7 +5232,7 @@ NO_SSH:
set_state(SERVER_READY);
lprintf(LOG_INFO,"Terminal Server thread started for nodes %d through %d", first_node, last_node);
mqtt_client_max(&startup->mqtt, (last_node - first_node) + 1);
mqtt_client_max((struct startup*)startup, (last_node - first_node) + 1);
while(!terminate_server) {
YIELD();
......
This diff is collapsed.
......@@ -42,19 +42,19 @@ struct mqtt {
mqtt_handle_t handle;
scfg_t* cfg;
char* host;
enum server_type server_type;
ulong error_count;
ulong served;
link_list_t client_list;
BOOL shared_client_list;
BOOL shared_instance;
};
enum topic_depth {
TOPIC_ROOT,
TOPIC_BBS,
TOPIC_HOST,
TOPIC_EVENT,
TOPIC_SERVER
TOPIC_OTHER,
TOPIC_ROOT, // sbbs/*
TOPIC_BBS, // sbbs/BBS-ID/*
TOPIC_HOST, // sbbs/BBS-ID/hostname/*
TOPIC_EVENT, // sbbs/BBS-ID/event/*
TOPIC_SERVER // sbbs/BBS-ID/server/*
};
#define MQTT_SUCCESS 0 // Same as MOSQ_ERR_SUCCESS
......@@ -64,36 +64,36 @@ enum topic_depth {
extern "C" {
#endif
DLLEXPORT int mqtt_init(struct mqtt*, scfg_t*, enum server_type);
DLLEXPORT int mqtt_startup(struct mqtt*, scfg_t*, enum server_type, const char* version
DLLEXPORT int mqtt_init(struct startup*, scfg_t*);
DLLEXPORT int mqtt_startup(struct startup*, scfg_t*, const char* version
,int (*lputs)(int level, const char* str)
,BOOL shared_client_list);
DLLEXPORT int mqtt_online(struct mqtt*);
DLLEXPORT int mqtt_server_state(struct mqtt*, enum server_state);
DLLEXPORT int mqtt_server_version(struct mqtt*, const char*);
DLLEXPORT int mqtt_errormsg(struct mqtt*, int level, const char*);
DLLEXPORT int mqtt_terminating(struct mqtt*);
DLLEXPORT void mqtt_shutdown(struct mqtt*);
,BOOL shared_instance);
DLLEXPORT int mqtt_online(struct startup*);
DLLEXPORT int mqtt_server_state(struct startup*, enum server_state);
DLLEXPORT int mqtt_server_version(struct startup*, const char*);
DLLEXPORT int mqtt_errormsg(struct startup*, int level, const char*);
DLLEXPORT int mqtt_terminating(struct startup*);
DLLEXPORT void mqtt_shutdown(struct startup*);
DLLEXPORT char* mqtt_libver(char* str, size_t size);
DLLEXPORT char* mqtt_topic(struct mqtt*, enum topic_depth, char* str, size_t size, const char* fmt, ...);
DLLEXPORT int mqtt_subscribe(struct mqtt*, enum topic_depth, char* str, size_t size, const char* fmt, ...);
DLLEXPORT int mqtt_lputs(struct mqtt*, enum topic_depth, int level, const char* str);
DLLEXPORT int mqtt_pub_noval(struct mqtt*, enum topic_depth, const char* key);
DLLEXPORT int mqtt_pub_strval(struct mqtt*, enum topic_depth, const char* key, const char* str);
DLLEXPORT int mqtt_pub_uintval(struct mqtt*, enum topic_depth, const char* key, ulong value);
DLLEXPORT int mqtt_pub_message(struct mqtt*, enum topic_depth, const char* key, const void* buf, size_t len);
DLLEXPORT int mqtt_open(struct mqtt*);
DLLEXPORT void mqtt_close(struct mqtt*);
DLLEXPORT int mqtt_connect(struct mqtt*, const char* bind_address);
DLLEXPORT int mqtt_disconnect(struct mqtt*);
DLLEXPORT int mqtt_thread_start(struct mqtt*);
DLLEXPORT int mqtt_thread_stop(struct mqtt*);
DLLEXPORT int mqtt_thread_count(struct mqtt*, enum topic_depth, ulong count);
DLLEXPORT int mqtt_socket_count(struct mqtt*, enum topic_depth, ulong count);
DLLEXPORT int mqtt_served_count(struct mqtt*, enum topic_depth, ulong count);
DLLEXPORT int mqtt_client_count(struct mqtt*, enum topic_depth, ulong count);
DLLEXPORT int mqtt_client_on(struct mqtt*, BOOL on, int sock, client_t* client, BOOL update);
DLLEXPORT int mqtt_client_max(struct mqtt*, ulong count);
DLLEXPORT char* mqtt_topic(struct startup*, enum topic_depth, char* str, size_t size, const char* fmt, ...);
DLLEXPORT int mqtt_subscribe(struct startup*, enum topic_depth, char* str, size_t size, const char* fmt, ...);
DLLEXPORT int mqtt_lputs(struct startup*, enum topic_depth, int level, const char* str);
DLLEXPORT int mqtt_pub_noval(struct startup*, enum topic_depth, const char* key);
DLLEXPORT int mqtt_pub_strval(struct startup*, enum topic_depth, const char* key, const char* str);
DLLEXPORT int mqtt_pub_uintval(struct startup*, enum topic_depth, const char* key, ulong value);
DLLEXPORT int mqtt_pub_message(struct startup*, enum topic_depth, const char* key, const void* buf, size_t len);
DLLEXPORT int mqtt_open(struct startup*);
DLLEXPORT void mqtt_close(struct startup*);
DLLEXPORT int mqtt_connect(struct startup*, const char* bind_address);
DLLEXPORT int mqtt_disconnect(struct startup*);
DLLEXPORT int mqtt_thread_start(struct startup*);
DLLEXPORT int mqtt_thread_stop(struct startup*);
DLLEXPORT int mqtt_thread_count(struct startup*, enum topic_depth, ulong count);
DLLEXPORT int mqtt_socket_count(struct startup*, enum topic_depth, ulong count);
DLLEXPORT int mqtt_served_count(struct startup*, enum topic_depth, ulong count);
DLLEXPORT int mqtt_client_count(struct startup*, enum topic_depth, ulong count);
DLLEXPORT int mqtt_client_on(struct startup*, BOOL on, int sock, client_t* client, BOOL update);
DLLEXPORT int mqtt_client_max(struct startup*, ulong count);
#ifdef __cplusplus
}
......
......@@ -103,7 +103,7 @@ int sbbs_t::putnodedat(uint number, node_t* node)
,node->errors
);
SAFEPRINTF(topic, "node%u/status", number + 1);
int result = mqtt_pub_strval(&startup->mqtt, TOPIC_BBS, topic, str);
int result = mqtt_pub_strval((struct startup*)startup, TOPIC_BBS, topic, str);
if(result != MQTT_SUCCESS)
lprintf(LOG_WARNING, "ERROR %d (%d) publishing node status: %s", result, errno, topic);
}
......
......@@ -1246,11 +1246,11 @@ extern "C" {
DLLEXPORT int notify(scfg_t*, uint usernumber, const char* subject, const char* msg);
/* logfile.cpp */
DLLEXPORT int errorlog(scfg_t* cfg, struct mqtt*, int level, const char* host, const char* text);
DLLEXPORT int errorlog(scfg_t* cfg, struct startup*, int level, const char* host, const char* text);
DLLEXPORT BOOL hacklog(scfg_t* cfg, struct mqtt*, const char* prot, const char* user, const char* text
DLLEXPORT BOOL hacklog(scfg_t* cfg, struct startup*, const char* prot, const char* user, const char* text
,const char* host, union xp_sockaddr* addr);
DLLEXPORT BOOL spamlog(scfg_t* cfg, struct mqtt*, char* prot, char* action, char* reason
DLLEXPORT BOOL spamlog(scfg_t* cfg, struct startup*, char* prot, char* action, char* reason
,char* host, char* ip_addr, char* to, char* from);
/* data.cpp */
......
......@@ -72,7 +72,6 @@ BOOL terminated=FALSE;
enum server_state server_state[SERVER_COUNT];
BOOL server_stopped[SERVER_COUNT];
struct mqtt* mqtt[SERVER_COUNT];
BOOL run_bbs=FALSE;
bbs_startup_t bbs_startup;
BOOL run_ftp=FALSE;
......@@ -294,7 +293,7 @@ static int log_puts(int level, const char *str)
static int lputs(int level, const char *str)
{
if(str != NULL && *str != '\0')
mqtt_lputs(&bbs_startup.mqtt, TOPIC_HOST, level, str);
mqtt_lputs((struct startup*)&bbs_startup, TOPIC_HOST, level, str);
return log_puts(level, str);
}
......@@ -324,46 +323,6 @@ static void recycle_all()
services_startup.recycle_now = TRUE;
}
#ifdef USE_MOSQUITTO
static void mqtt_message_received(struct mosquitto* mosq, void* cbdata, const struct mosquitto_message* msg)
{
char topic[128];
lprintf(LOG_DEBUG, "MQTT message received (%d bytes) on %s", msg->payloadlen, msg->topic);
for(int i = bbs_startup.first_node; i <= bbs_startup.last_node; i++) {
mqtt_topic(&bbs_startup.mqtt, TOPIC_BBS, topic, sizeof(topic), "node%d/input", i);
if(strcmp(msg->topic, topic) != 0)
continue;
if(bbs_startup.node_inbuf != NULL && bbs_startup.node_inbuf[i - 1] != NULL)
RingBufWrite(bbs_startup.node_inbuf[i - 1], msg->payload, msg->payloadlen);
return;
}
if(strcmp(msg->topic, mqtt_topic(&bbs_startup.mqtt, TOPIC_HOST, topic, sizeof(topic), "recycle")) == 0) {
recycle_all();
return;
}
if(strcmp(msg->topic, mqtt_topic(&bbs_startup.mqtt, TOPIC_SERVER, topic, sizeof(topic), "recycle")) == 0) {
bbs_startup.recycle_now = true;
return;
}
if(strcmp(msg->topic, mqtt_topic(&ftp_startup.mqtt, TOPIC_SERVER, topic, sizeof(topic), "recycle")) == 0) {
ftp_startup.recycle_now = true;
return;
}
if(strcmp(msg->topic, mqtt_topic(&web_startup.mqtt, TOPIC_SERVER, topic, sizeof(topic), "recycle")) == 0) {
web_startup.recycle_now = true;
return;
}
if(strcmp(msg->topic, mqtt_topic(&mail_startup.mqtt, TOPIC_SERVER, topic, sizeof(topic), "recycle")) == 0) {
mail_startup.recycle_now = true;
return;
}
if(strcmp(msg->topic, mqtt_topic(&services_startup.mqtt, TOPIC_SERVER, topic, sizeof(topic), "recycle")) == 0) {
services_startup.recycle_now = true;
return;
}
}
#endif // USE_MOSQUITTO
#ifdef __unix__
static pthread_mutex_t setid_mutex;
static BOOL setid_mutex_initialized=0;
......@@ -671,7 +630,7 @@ static void thread_up(void* p, BOOL up, BOOL setuid)
thread_count++;
else if(thread_count>0)
thread_count--;
mqtt_thread_count(&bbs_startup.mqtt, TOPIC_HOST, thread_count);
mqtt_thread_count((struct startup*)&bbs_startup, TOPIC_HOST, thread_count);
pthread_mutex_unlock(&mutex);
lputs(LOG_INFO,NULL); /* update displayed stats */
}
......@@ -692,7 +651,7 @@ static void socket_open(void* cbdata, BOOL open)
socket_count++;
else if(socket_count>0)
socket_count--;
mqtt_socket_count(mqtt[server_type], TOPIC_HOST, socket_count);
mqtt_socket_count(bbs_startup.startup[server_type], TOPIC_HOST, socket_count);
pthread_mutex_unlock(&mutex);
lputs(LOG_INFO,NULL); /* update displayed stats */
}
......@@ -714,7 +673,7 @@ static void client_on(void* p, BOOL on, int sock, client_t* client, BOOL update)
} else
listRemoveTaggedNode(&client_list, sock, /* free_data: */TRUE);
mqtt_client_on(&bbs_startup.mqtt, on, sock, client, update);
mqtt_client_on((struct startup*)&bbs_startup, on, sock, client, update);
lputs(LOG_INFO,NULL); /* update displayed stats */
}
......@@ -1786,35 +1745,16 @@ int main(int argc, char** argv)
#endif // __unix__
mqtt_startup(&bbs_startup.mqtt, &scfg, SERVER_TERM, sbbscon_ver(), log_puts, /* shared_client_list: */TRUE);
mqtt[SERVER_TERM] = &bbs_startup.mqtt;
bbs_startup.startup[SERVER_TERM] = (struct startup*)&bbs_startup;
bbs_startup.startup[SERVER_MAIL] = (struct startup*)&mail_startup;
bbs_startup.startup[SERVER_FTP] = (struct startup*)&ftp_startup;
bbs_startup.startup[SERVER_WEB] = (struct startup*)&web_startup;
bbs_startup.startup[SERVER_SERVICES] = (struct startup*)&services_startup;
mqtt_startup((struct startup*)&bbs_startup, &scfg, sbbscon_ver(), log_puts, /* shared_client_list: */TRUE);
mail_startup.mqtt = bbs_startup.mqtt;
mail_startup.mqtt.server_type = SERVER_MAIL;
mqtt[SERVER_MAIL] = &mail_startup.mqtt;
ftp_startup.mqtt = bbs_startup.mqtt;
ftp_startup.mqtt.server_type = SERVER_FTP;
mqtt[SERVER_FTP] = &ftp_startup.mqtt;
web_startup.mqtt = bbs_startup.mqtt;
web_startup.mqtt.server_type = SERVER_WEB;
mqtt[SERVER_WEB] = &web_startup.mqtt;
services_startup.mqtt = bbs_startup.mqtt;
services_startup.mqtt.server_type = SERVER_SERVICES;
mqtt[SERVER_SERVICES] = &services_startup.mqtt;
#ifdef USE_MOSQUITTO
if(bbs_startup.mqtt.handle != NULL) {
mosquitto_message_callback_set(bbs_startup.mqtt.handle, mqtt_message_received);
for(int i = bbs_startup.first_node; i <= bbs_startup.last_node; i++) {
mqtt_subscribe(&bbs_startup.mqtt, TOPIC_BBS, str, sizeof(str), "node%d/input", i);
}
mqtt_subscribe(&bbs_startup.mqtt, TOPIC_HOST, str, sizeof(str), "recycle");
mqtt_subscribe(&bbs_startup.mqtt, TOPIC_SERVER, str, sizeof(str), "recycle");
mqtt_subscribe(&ftp_startup.mqtt, TOPIC_SERVER, str, sizeof(str), "recycle");
mqtt_subscribe(&web_startup.mqtt, TOPIC_SERVER, str, sizeof(str), "recycle");
mqtt_subscribe(&mail_startup.mqtt, TOPIC_SERVER, str, sizeof(str), "recycle");
mqtt_subscribe(&services_startup.mqtt, TOPIC_SERVER, str, sizeof(str), "recycle");
}
#endif
#ifdef _THREAD_SUID_BROKEN
/* check if we're using NPTL */
......@@ -1928,7 +1868,7 @@ int main(int argc, char** argv)
if(run_web)
_beginthread((void(*)(void*))web_server,0,&web_startup);
mqtt_online(&bbs_startup.mqtt);
mqtt_online((struct startup*)&bbs_startup);
#ifdef __unix__
uid_t uid = getuid();
......@@ -2240,13 +2180,13 @@ int main(int argc, char** argv)
}
}
mqtt_terminating(&bbs_startup.mqtt);
mqtt_terminating((struct startup*)&bbs_startup);
terminate();
/* erase the prompt */
printf("\r%*s\r",prompt_len,"");
mqtt_shutdown(&bbs_startup.mqtt);
mqtt_shutdown((struct startup*)&bbs_startup);
return(0);
}
......@@ -125,14 +125,14 @@ static int lprintf(int level, const char *fmt, ...)
if(level <= LOG_ERR) {
char errmsg[sizeof(sbuf)+16];
errorlog(&scfg, &startup->mqtt, level, startup==NULL ? NULL:startup->host_name, sbuf);
errorlog(&scfg, (struct startup*)startup, level, startup==NULL ? NULL:startup->host_name, sbuf);
SAFEPRINTF2(errmsg, "%s %s", server_abbrev, sbuf);
if(startup!=NULL && startup->errormsg!=NULL)
startup->errormsg(startup->cbdata,level,errmsg);
}
if(startup != NULL)
mqtt_lputs(&startup->mqtt, TOPIC_SERVER, level, sbuf);
mqtt_lputs((struct startup*)startup, TOPIC_SERVER, level, sbuf);
if(startup==NULL || startup->lputs==NULL || level > startup->log_level)
return(0);
......@@ -182,7 +182,7 @@ static void set_state(enum server_state state)
if(startup != NULL) {
if(startup->set_state != NULL)
startup->set_state(startup->cbdata, state);
mqtt_server_state(&startup->mqtt, state);
mqtt_server_state((struct startup*)startup, state);
}
}
......@@ -336,7 +336,7 @@ static void badlogin(SOCKET sock, char* prot, char* user, char* passwd, char* ho
SAFEPRINTF(reason,"%s LOGIN", prot);
count=loginFailure(startup->login_attempt_list, addr, prot, user, passwd);
if(startup->login_attempt.hack_threshold && count>=startup->login_attempt.hack_threshold) {
hacklog(&scfg, &startup->mqtt, reason, user, passwd, host, addr);
hacklog(&scfg, (struct startup*)startup, reason, user, passwd, host, addr);
#ifdef _WIN32
if(startup->sound.hack[0] && !sound_muted(&scfg))
PlaySound(startup->sound.hack, NULL, SND_ASYNC|SND_FILENAME);
......@@ -1860,7 +1860,7 @@ void services_thread(void* arg)
}
set_state(SERVER_INIT);
mqtt_server_version(&startup->mqtt, services_ver());
mqtt_server_version((struct startup*)startup, services_ver());
#ifdef _THREAD_SUID_BROKEN
if(thread_suid_broken)
......
......@@ -112,7 +112,8 @@ typedef struct {
struct startup_sound_settings sound; \
struct login_attempt_settings login_attempt; \
link_list_t* login_attempt_list; \
struct mqtt mqtt;
struct mqtt mqtt; \
struct startup* startup[SERVER_COUNT];
struct startup {
STARTUP_COMMON_ELEMENTS
......
......@@ -550,14 +550,14 @@ static int lprintf(int level, const char *fmt, ...)
if(level <= LOG_ERR) {
char errmsg[sizeof(sbuf)+16];
errorlog(&scfg, &startup->mqtt, level, startup==NULL ? NULL:startup->host_name, sbuf);
errorlog(&scfg, (struct startup*)startup, level, startup==NULL ? NULL:startup->host_name, sbuf);
SAFEPRINTF2(errmsg, "%s %s", server_abbrev, sbuf);
if(startup!=NULL && startup->errormsg!=NULL)
startup->errormsg(startup->cbdata,level,errmsg);
}
if(startup != NULL)
mqtt_lputs(&startup->mqtt, TOPIC_SERVER, level, sbuf);
mqtt_lputs((struct startup*)startup, TOPIC_SERVER, level, sbuf);
if(startup==NULL || startup->lputs==NULL || level > startup->log_level)
return(0);
......@@ -741,7 +741,7 @@ static void set_state(enum server_state state)
if(startup != NULL) {
if(startup->set_state != NULL)
startup->set_state(startup->cbdata, state);
mqtt_server_state(&startup->mqtt, state);
mqtt_server_state((struct startup*)startup, state);
}
}
......@@ -751,7 +751,7 @@ static void update_clients(void)
uint32_t count = protected_uint32_value(active_clients);
if(startup->clients!=NULL)
startup->clients(startup->cbdata, count);
mqtt_client_count(&startup->mqtt, TOPIC_SERVER, count);
mqtt_client_count((struct startup*)startup, TOPIC_SERVER, count);
}
}
......@@ -1868,7 +1868,7 @@ static void badlogin(SOCKET sock, const char* prot, const char* user, const char
SAFEPRINTF(reason,"%s LOGIN", prot);
count=loginFailure(startup->login_attempt_list, addr, prot, user, passwd);
if(startup->login_attempt.hack_threshold && count>=startup->login_attempt.hack_threshold) {
hacklog(&scfg, &startup->mqtt, reason, user, passwd, host, addr);
hacklog(&scfg, (struct startup*)startup, reason, user, passwd, host, addr);
#ifdef _WIN32
if(startup->sound.hack[0] && !sound_muted(&scfg))
PlaySound(startup->sound.hack, NULL, SND_ASYNC|SND_FILENAME);
......@@ -3685,7 +3685,7 @@ static BOOL check_request(http_session_t * session)
send_error(session,__LINE__,"400 Bad Request");
SAFEPRINTF2(str, "Request for '%s' is outside of web root: %s", path, root_dir);
lprintf(LOG_NOTICE,"%04d %s [%s] !ERROR %s", session->socket, session->client.protocol, session->host_ip, str);
hacklog(&scfg, &startup->mqtt, session->client.protocol, session->username, str, session->client.host, &session->addr);
hacklog(&scfg, (struct startup*)startup, session->client.protocol, session->username, str, session->client.host, &session->addr);
#ifdef _WIN32
if(startup->sound.hack[0] && !sound_muted(&scfg))
PlaySound(startup->sound.hack, NULL, SND_ASYNC|SND_FILENAME);
......@@ -7006,7 +7006,7 @@ void web_server(void* arg)
}
set_state(SERVER_INIT);
mqtt_server_version(&startup->mqtt, web_ver());
mqtt_server_version((struct startup*)startup, web_ver());
#ifdef _THREAD_SUID_BROKEN
if(thread_suid_broken)
......@@ -7200,7 +7200,7 @@ void web_server(void* arg)
set_state(SERVER_READY);
lprintf(LOG_INFO,"Web Server thread started");
mqtt_client_max(&startup->mqtt, startup->max_clients);
mqtt_client_max((struct startup*)startup, startup->max_clients);
while(!terminated && !terminate_server) {
YIELD();
......