Commits (5)
......@@ -5160,8 +5160,8 @@ void ftp_server(void* arg)
}
if(protected_uint32_value(active_clients)>=startup->max_clients) {
lprintf(LOG_WARNING,"%04d !MAXIMUM CLIENTS (%d) reached, access denied"
,client_socket, startup->max_clients);
lprintf(LOG_WARNING,"%04d [%s] !MAXIMUM CLIENTS (%d) reached, access denied"
,client_socket, client_ip, startup->max_clients);
sockprintf(client_socket,-1,"421 Maximum active clients reached, please try again later.");
ftp_close_socket(&client_socket,&none,__LINE__);
continue;
......
......@@ -6337,8 +6337,8 @@ void mail_server(void* arg)
}
if(protected_uint32_value(active_clients)>=startup->max_clients) {
lprintf(LOG_WARNING,"%04d %s !MAXIMUM CLIENTS (%u) reached, access denied (%lu total)"
,client_socket, servprot, startup->max_clients, ++stats.connections_refused);
lprintf(LOG_WARNING,"%04d %s [%s] !MAXIMUM CLIENTS (%u) reached, access denied (%lu total)"
,client_socket, servprot, host_ip, startup->max_clients, ++stats.connections_refused);
sockprintf(client_socket, servprot, session, is_smtp ? smtp_error : pop_error, "Maximum active clients reached");
mswait(3000);
mail_close_socket(&client_socket, &session);
......
......@@ -23,6 +23,7 @@
#include "mqtt.h"
#include "startup.h"
#include "xpdatetime.h"
const char* server_type_desc(enum server_type type)
{
......@@ -164,30 +165,34 @@ int mqtt_lputs(struct mqtt* mqtt, enum topic_depth depth, int level, const char*
return MQTT_SUCCESS;
#ifdef USE_MOSQUITTO
if(mqtt->handle != NULL && str != NULL) {
int result;
char sub[128];
mqtt_topic(mqtt, depth, sub, sizeof(sub), "log/%d", level);
char lvl[32];
sprintf(lvl, "%d", level);
mosquitto_publish_v5(mqtt->handle,
/* mid: */NULL,
/* topic: */sub,
/* payloadlen */strlen(str),
/* payload */str,
/* qos */mqtt->cfg->mqtt.publish_qos,
/* retain */true,
/* properties */NULL);
mqtt_topic(mqtt, depth, sub, sizeof(sub), "log");
mosquitto_property* props = NULL;
mosquitto_property_add_string_pair(&props, MQTT_PROP_USER_PROPERTY, "level", lvl);
int result = mosquitto_publish_v5(mqtt->handle,
/* mid: */NULL,
/* topic: */sub,
/* payloadlen */strlen(str),
/* payload */str,
/* qos */mqtt->cfg->mqtt.publish_qos,
/* retain */true,
/* properties */props);
mosquitto_property_free_all(&props);
if(mqtt->cfg->mqtt.protocol_version < 5) {
mqtt_topic(mqtt, depth, sub, sizeof(sub), "log/%d", level);
result = mosquitto_publish_v5(mqtt->handle,
/* mid: */NULL,
/* topic: */sub,
/* payloadlen */strlen(str),
/* payload */str,
/* qos */mqtt->cfg->mqtt.publish_qos,
/* retain */true,
/* properties */NULL);
} else {
mqtt_topic(mqtt, depth, sub, sizeof(sub), "log");
char lvl[32];
sprintf(lvl, "%d", level);
mosquitto_property* props = NULL;
mosquitto_property_add_string_pair(&props, MQTT_PROP_USER_PROPERTY, "level", lvl);
result = mosquitto_publish_v5(mqtt->handle,
/* mid: */NULL,
/* topic: */sub,
/* payloadlen */strlen(str),
/* payload */str,
/* qos */mqtt->cfg->mqtt.publish_qos,
/* retain */true,
/* properties */props);
mosquitto_property_free_all(&props);
}
return result;
}
#endif
......@@ -339,7 +344,7 @@ static int pw_callback(char* buf, int size, int rwflag, void* userdata)
static char* server_state_str(char* str, size_t size, enum server_state state)
{
snprintf(str, size, "%u\t%s", state, server_state_desc(state));
snprintf(str, size, "%u-%s", state, server_state_desc(state));
return str;
}
......@@ -536,12 +541,12 @@ int mqtt_startup(struct mqtt* mqtt, scfg_t* cfg, struct startup* startup, const
int mqtt_server_state(struct mqtt* mqtt, enum server_state state)
{
char str[128];
char tmp[256];
if(mqtt == NULL || mqtt->cfg == NULL)
return MQTT_FAILURE;
if(mqtt->cfg->mqtt.verbose) {
char tmp[256];
char errors[64] = "";
if(mqtt->error_count)
snprintf(errors, sizeof(errors), "%lu error%s", mqtt->error_count, mqtt->error_count > 1 ? "s" : "");
......@@ -561,8 +566,17 @@ int mqtt_server_state(struct mqtt* mqtt, enum server_state state)
,errors);
} else
server_state_str(str, sizeof(str), state);
mqtt->server_state = state;
return mqtt_pub_strval(mqtt, TOPIC_SERVER_LEVEL, NULL, str);
int result = mqtt_pub_strval(mqtt, TOPIC_SERVER_LEVEL, NULL, str);
if(mqtt->server_state != state) {
mqtt->server_state = state;
char topic[128];
time_t t = time(NULL);
snprintf(topic, sizeof(topic), "state/%s", server_state_str(tmp, sizeof(tmp), state));
safe_snprintf(str, sizeof(str), "%" PRIu32 "T%06" PRIu32 "%d"
,time_to_isoDate(t), time_to_isoTime(t), xpTimeZone_local());
result = mqtt_pub_strval(mqtt, TOPIC_SERVER, topic, str);
}
return result;
}
int mqtt_errormsg(struct mqtt* mqtt, int level, const char* msg)
......
......@@ -544,7 +544,6 @@ void sbbs_t::readmail(uint usernumber, int which, long lm_mode)
break;
case ')':
case '}': /* Search Author forward */
strcpy(str,msg.from);
for(u=smb.curmsg+1;u<smb.msgs;u++)
if(mail[u].from==msg.idx.from)
break;
......@@ -568,7 +567,6 @@ void sbbs_t::readmail(uint usernumber, int which, long lm_mode)
break;
case '(':
case '{': /* Search Author backward */
strcpy(str,msg.from);
if(smb.curmsg > 0) {
for(u=smb.curmsg-1;;u--) {
if(mail[u].from==msg.idx.from) {
......@@ -584,7 +582,6 @@ void sbbs_t::readmail(uint usernumber, int which, long lm_mode)
}
break;
case ']': /* Search To User forward */
strcpy(str,msg.to);
for(u=smb.curmsg+1;u<smb.msgs;u++)
if(mail[u].to==msg.idx.to)
break;
......@@ -596,7 +593,6 @@ void sbbs_t::readmail(uint usernumber, int which, long lm_mode)
}
break;
case '[': /* Search To User backward */
strcpy(str,msg.to);
if(smb.curmsg > 0) {
for(u=smb.curmsg-1;;u--) {
if(mail[u].to==msg.idx.to) {
......
......@@ -156,7 +156,7 @@ void mqtt_cfg()
static char* mqttQOS[]
= { "0: At most once", "1: At least once", "2: Exactly once", NULL };
static char* mqttVersion[]
= { "3.1", "3.1.1", "5", NULL };
= { "3.1.0", "3.1.1", "5.0", NULL };
static char* mqttTlsMode[]
= { "Off", "Certificate", "Pre-Shared-Key", NULL };
......
......@@ -213,7 +213,7 @@ BOOL read_main_cfg(scfg_t* cfg, char* error, size_t maxerrlen)
cfg->mqtt.keepalive = iniGetIntInRange(section, NULL, "keepalive", 5, 60, INT_MAX); // seconds
cfg->mqtt.publish_qos = iniGetIntInRange(section, NULL, "publish_qos", 0, 0, 2);
cfg->mqtt.subscribe_qos = iniGetIntInRange(section, NULL, "subscribe_qos", 0, 2, 2);
cfg->mqtt.protocol_version = iniGetIntInRange(section, NULL, "protocol_version", 3, 5, 5);
cfg->mqtt.protocol_version = iniGetIntInRange(section, NULL, "protocol_version", 3, 4, 5);
cfg->mqtt.log_level = iniGetLogLevel(section, NULL, "LogLevel", LOG_INFO);
cfg->mqtt.tls.mode = iniGetIntInRange(section, NULL, "tls_mode", MQTT_TLS_DISABLED, MQTT_TLS_DISABLED, MQTT_TLS_PSK);
SAFECOPY(cfg->mqtt.tls.cafile, iniGetString(section, NULL, "tls_cafile", "", value));
......
......@@ -2292,8 +2292,8 @@ void services_thread(void* arg)
if(service[i].max_clients && protected_uint32_value(service[i].clients) + 1 > service[i].max_clients) {
FREE_AND_NULL(udp_buf);
lprintf(LOG_WARNING,"%04d %s !MAXIMUM CLIENTS (%u) reached, access denied"
,client_socket, service[i].protocol, service[i].max_clients);
lprintf(LOG_WARNING,"%04d %s [%s] !MAXIMUM CLIENTS (%u) reached, access denied"
,client_socket, service[i].protocol, host_ip, service[i].max_clients);
close_socket(client_socket);
continue;
}
......
......@@ -7293,8 +7293,8 @@ void web_server(void* arg)
,client_socket, client_highwater);
}
if(startup->max_clients && protected_uint32_value(active_clients)>=startup->max_clients) {
lprintf(LOG_WARNING,"%04d !MAXIMUM CLIENTS (%d) reached, access denied"
,client_socket, startup->max_clients);
lprintf(LOG_WARNING,"%04d [%s] !MAXIMUM CLIENTS (%d) reached, access denied"
,client_socket, host_ip, startup->max_clients);
if (!len_503)
len_503 = strlen(error_503);
sendsocket(client_socket, error_503, len_503);
......