Drop Windows XP support, misc fixes on Windows.

This commit is contained in:
Roger A. Light 2015-09-22 10:03:57 +01:00
parent e2324ff9bb
commit 9a2eb2038f
11 changed files with 61 additions and 34 deletions

View File

@ -23,6 +23,8 @@ Broker:
- Change sys tree printing output. This format shouldn't be relied upon and - Change sys tree printing output. This format shouldn't be relied upon and
may change at any time. Closes #470246. may change at any time. Closes #470246.
- Minimum supported libwebsockets version is now 1.3. - Minimum supported libwebsockets version is now 1.3.
- Support for Windows XP has been dropped.
- Miscellaneous fixes on Windows.
Client library: Client library:
- Outgoing messages with QoS>1 are no longer retried after a timeout period. - Outgoing messages with QoS>1 are no longer retried after a timeout period.

View File

@ -527,6 +527,10 @@ int client_config_line_proc(struct mosq_config *cfg, int pub_or_sub, int argc, c
} }
cfg->topic_count++; cfg->topic_count++;
cfg->topics = realloc(cfg->topics, cfg->topic_count*sizeof(char *)); cfg->topics = realloc(cfg->topics, cfg->topic_count*sizeof(char *));
if(!cfg->topics){
fprintf(stderr, "Error: Out of memory.\n");
return 1;
}
cfg->topics[cfg->topic_count-1] = strdup(argv[i+1]); cfg->topics[cfg->topic_count-1] = strdup(argv[i+1]);
} }
i++; i++;
@ -545,6 +549,10 @@ int client_config_line_proc(struct mosq_config *cfg, int pub_or_sub, int argc, c
} }
cfg->filter_out_count++; cfg->filter_out_count++;
cfg->filter_outs = realloc(cfg->filter_outs, cfg->filter_out_count*sizeof(char *)); cfg->filter_outs = realloc(cfg->filter_outs, cfg->filter_out_count*sizeof(char *));
if(!cfg->filter_outs){
fprintf(stderr, "Error: Out of memory.\n");
return 1;
}
cfg->filter_outs[cfg->filter_out_count-1] = strdup(argv[i+1]); cfg->filter_outs[cfg->filter_out_count-1] = strdup(argv[i+1]);
} }
i++; i++;
@ -854,6 +862,10 @@ static int mosquitto__parse_socks_url(struct mosq_config *cfg, char *url)
} }
len = i-start; len = i-start;
host = malloc(len + 1); host = malloc(len + 1);
if(!host){
fprintf(stderr, "Error: Out of memory.\n");
goto cleanup;
}
memcpy(host, &(str[start]), len); memcpy(host, &(str[start]), len);
host[len] = '\0'; host[len] = '\0';
start = i+1; start = i+1;
@ -863,6 +875,10 @@ static int mosquitto__parse_socks_url(struct mosq_config *cfg, char *url)
* socks5h://username:password@host[:port] */ * socks5h://username:password@host[:port] */
len = i-start; len = i-start;
username_or_host = malloc(len + 1); username_or_host = malloc(len + 1);
if(!username_or_host){
fprintf(stderr, "Error: Out of memory.\n");
goto cleanup;
}
memcpy(username_or_host, &(str[start]), len); memcpy(username_or_host, &(str[start]), len);
username_or_host[len] = '\0'; username_or_host[len] = '\0';
start = i+1; start = i+1;
@ -879,6 +895,10 @@ static int mosquitto__parse_socks_url(struct mosq_config *cfg, char *url)
len = i-start; len = i-start;
password = malloc(len + 1); password = malloc(len + 1);
if(!password){
fprintf(stderr, "Error: Out of memory.\n");
goto cleanup;
}
memcpy(password, &(str[start]), len); memcpy(password, &(str[start]), len);
password[len] = '\0'; password[len] = '\0';
start = i+1; start = i+1;
@ -891,6 +911,10 @@ static int mosquitto__parse_socks_url(struct mosq_config *cfg, char *url)
} }
len = i-start; len = i-start;
username = malloc(len + 1); username = malloc(len + 1);
if(!username){
fprintf(stderr, "Error: Out of memory.\n");
goto cleanup;
}
memcpy(username, &(str[start]), len); memcpy(username, &(str[start]), len);
username[len] = '\0'; username[len] = '\0';
start = i+1; start = i+1;
@ -905,6 +929,10 @@ static int mosquitto__parse_socks_url(struct mosq_config *cfg, char *url)
/* Have already seen a @ , so this must be of form /* Have already seen a @ , so this must be of form
* socks5h://username[:password]@host:port */ * socks5h://username[:password]@host:port */
port = malloc(len + 1); port = malloc(len + 1);
if(!port){
fprintf(stderr, "Error: Out of memory.\n");
goto cleanup;
}
memcpy(port, &(str[start]), len); memcpy(port, &(str[start]), len);
port[len] = '\0'; port[len] = '\0';
}else if(username_or_host){ }else if(username_or_host){
@ -913,10 +941,18 @@ static int mosquitto__parse_socks_url(struct mosq_config *cfg, char *url)
host = username_or_host; host = username_or_host;
username_or_host = NULL; username_or_host = NULL;
port = malloc(len + 1); port = malloc(len + 1);
if(!port){
fprintf(stderr, "Error: Out of memory.\n");
goto cleanup;
}
memcpy(port, &(str[start]), len); memcpy(port, &(str[start]), len);
port[len] = '\0'; port[len] = '\0';
}else{ }else{
host = malloc(len + 1); host = malloc(len + 1);
if(!host){
fprintf(stderr, "Error: Out of memory.\n");
goto cleanup;
}
memcpy(host, &(str[start]), len); memcpy(host, &(str[start]), len);
host[len] = '\0'; host[len] = '\0';
} }

View File

@ -295,6 +295,7 @@ int main(int argc, char *argv[])
int rc; int rc;
int rc2; int rc2;
memset(&cfg, 0, sizeof(struct mosq_config));
rc = client_config_load(&cfg, CLIENT_PUB, argc, argv); rc = client_config_load(&cfg, CLIENT_PUB, argc, argv);
if(rc){ if(rc){
client_config_cleanup(&cfg); client_config_cleanup(&cfg);

View File

@ -230,6 +230,7 @@ int main(int argc, char *argv[])
struct mosquitto *mosq = NULL; struct mosquitto *mosq = NULL;
int rc; int rc;
memset(&cfg, 0, sizeof(struct mosq_config));
rc = client_config_load(&cfg, CLIENT_SUB, argc, argv); rc = client_config_load(&cfg, CLIENT_SUB, argc, argv);
if(rc){ if(rc){
client_config_cleanup(&cfg); client_config_cleanup(&cfg);

View File

@ -66,7 +66,7 @@ int mosquitto_lib_version(int *major, int *minor, int *revision)
int mosquitto_lib_init(void) int mosquitto_lib_init(void)
{ {
#ifdef WIN32 #ifdef WIN32
srand(GetTickCount()); srand(GetTickCount64());
#else #else
struct timeval tv; struct timeval tv;
@ -74,9 +74,7 @@ int mosquitto_lib_init(void)
srand(tv.tv_sec*1000 + tv.tv_usec/1000); srand(tv.tv_sec*1000 + tv.tv_usec/1000);
#endif #endif
net__init(); return net__init();
return MOSQ_ERR_SUCCESS;
} }
int mosquitto_lib_cleanup(void) int mosquitto_lib_cleanup(void)

View File

@ -79,11 +79,13 @@ Contributors:
int tls_ex_index_mosq = -1; int tls_ex_index_mosq = -1;
#endif #endif
void net__init(void) int net__init(void)
{ {
#ifdef WIN32 #ifdef WIN32
WSADATA wsaData; WSADATA wsaData;
WSAStartup(MAKEWORD(2,2), &wsaData); if(WSAStartup(MAKEWORD(2,2), &wsaData) != 0){
return MOSQ_ERR_UNKNOWN;
}
#endif #endif
#ifdef WITH_SRV #ifdef WITH_SRV
@ -98,6 +100,7 @@ void net__init(void)
tls_ex_index_mosq = SSL_get_ex_new_index(0, "client context", NULL, NULL, NULL); tls_ex_index_mosq = SSL_get_ex_new_index(0, "client context", NULL, NULL, NULL);
} }
#endif #endif
return MOSQ_ERR_SUCCESS;
} }
void net__cleanup(void) void net__cleanup(void)

View File

@ -49,7 +49,7 @@ struct mosquitto_db;
#define MOSQ_MSB(A) (uint8_t)((A & 0xFF00) >> 8) #define MOSQ_MSB(A) (uint8_t)((A & 0xFF00) >> 8)
#define MOSQ_LSB(A) (uint8_t)(A & 0x00FF) #define MOSQ_LSB(A) (uint8_t)(A & 0x00FF)
void net__init(void); int net__init(void);
void net__cleanup(void); void net__cleanup(void);
int net__socket_connect(struct mosquitto *mosq, const char *host, uint16_t port, const char *bind_address, bool blocking); int net__socket_connect(struct mosquitto *mosq, const char *host, uint16_t port, const char *bind_address, bool blocking);

View File

@ -30,33 +30,10 @@ Contributors:
#include "mosquitto.h" #include "mosquitto.h"
#include "time_mosq.h" #include "time_mosq.h"
#ifdef WIN32
static bool tick64 = false;
void _windows_time_version_check(void)
{
OSVERSIONINFO vi;
tick64 = false;
memset(&vi, 0, sizeof(OSVERSIONINFO));
vi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if(GetVersionEx(&vi)){
if(vi.dwMajorVersion > 5){
tick64 = true;
}
}
}
#endif
time_t mosquitto_time(void) time_t mosquitto_time(void)
{ {
#ifdef WIN32 #ifdef WIN32
if(tick64){ return GetTickCount64()/1000;
return GetTickCount64()/1000;
}else{
return GetTickCount()/1000; /* FIXME - need to deal with overflow. */
}
#elif _POSIX_TIMERS>0 && defined(_POSIX_MONOTONIC_CLOCK) #elif _POSIX_TIMERS>0 && defined(_POSIX_MONOTONIC_CLOCK)
struct timespec tp; struct timespec tp;

View File

@ -444,7 +444,7 @@ int main(int argc, char *argv[])
} }
#ifdef WIN32 #ifdef WIN32
int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{ {
char **argv; char **argv;
int argc = 1; int argc = 1;

View File

@ -211,7 +211,7 @@ int gets_quiet(char *s, int len)
{ {
#ifdef WIN32 #ifdef WIN32
HANDLE h; HANDLE h;
DWORD con_orig, con_quiet; DWORD con_orig, con_quiet = 0;
DWORD read_len = 0; DWORD read_len = 0;
memset(s, 0, len); memset(s, 0, len);
@ -418,6 +418,10 @@ int main(int argc, char *argv[])
} }
backup_file = malloc(strlen(password_file)+5); backup_file = malloc(strlen(password_file)+5);
if(!backup_file){
fprintf(stderr, "Error: Out of memory.\n");
return 1;
}
snprintf(backup_file, strlen(password_file)+5, "%s.tmp", password_file); snprintf(backup_file, strlen(password_file)+5, "%s.tmp", password_file);
if(create_backup(backup_file, fptr)){ if(create_backup(backup_file, fptr)){

View File

@ -56,6 +56,7 @@ void __stdcall service_main(DWORD dwArgc, LPTSTR *lpszArgv)
service_handle = RegisterServiceCtrlHandler("mosquitto", service_handler); service_handle = RegisterServiceCtrlHandler("mosquitto", service_handler);
if(service_handle){ if(service_handle){
memset(conf_path, 0, MAX_PATH + 20);
rc = GetEnvironmentVariable("MOSQUITTO_DIR", conf_path, MAX_PATH); rc = GetEnvironmentVariable("MOSQUITTO_DIR", conf_path, MAX_PATH);
if(!rc || rc == MAX_PATH){ if(!rc || rc == MAX_PATH){
service_status.dwCurrentState = SERVICE_STOPPED; service_status.dwCurrentState = SERVICE_STOPPED;
@ -91,7 +92,11 @@ void service_install(void)
char exe_path[MAX_PATH + 5]; char exe_path[MAX_PATH + 5];
SERVICE_DESCRIPTION svc_desc; SERVICE_DESCRIPTION svc_desc;
GetModuleFileName(NULL, exe_path, MAX_PATH); memset(exe_path, 0, MAX_PATH+5);
if(GetModuleFileName(NULL, exe_path, MAX_PATH) == MAX_PATH){
fprintf(stderr, "Error: Path too long.\n");
return;
}
strcat(exe_path, " run"); strcat(exe_path, " run");
sc_manager = OpenSCManager(NULL, NULL, SC_MANAGER_CREATE_SERVICE); sc_manager = OpenSCManager(NULL, NULL, SC_MANAGER_CREATE_SERVICE);