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
may change at any time. Closes #470246.
- Minimum supported libwebsockets version is now 1.3.
- Support for Windows XP has been dropped.
- Miscellaneous fixes on Windows.
Client library:
- 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->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]);
}
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_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]);
}
i++;
@ -854,6 +862,10 @@ static int mosquitto__parse_socks_url(struct mosq_config *cfg, char *url)
}
len = i-start;
host = malloc(len + 1);
if(!host){
fprintf(stderr, "Error: Out of memory.\n");
goto cleanup;
}
memcpy(host, &(str[start]), len);
host[len] = '\0';
start = i+1;
@ -863,6 +875,10 @@ static int mosquitto__parse_socks_url(struct mosq_config *cfg, char *url)
* socks5h://username:password@host[:port] */
len = i-start;
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);
username_or_host[len] = '\0';
start = i+1;
@ -879,6 +895,10 @@ static int mosquitto__parse_socks_url(struct mosq_config *cfg, char *url)
len = i-start;
password = malloc(len + 1);
if(!password){
fprintf(stderr, "Error: Out of memory.\n");
goto cleanup;
}
memcpy(password, &(str[start]), len);
password[len] = '\0';
start = i+1;
@ -891,6 +911,10 @@ static int mosquitto__parse_socks_url(struct mosq_config *cfg, char *url)
}
len = i-start;
username = malloc(len + 1);
if(!username){
fprintf(stderr, "Error: Out of memory.\n");
goto cleanup;
}
memcpy(username, &(str[start]), len);
username[len] = '\0';
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
* socks5h://username[:password]@host:port */
port = malloc(len + 1);
if(!port){
fprintf(stderr, "Error: Out of memory.\n");
goto cleanup;
}
memcpy(port, &(str[start]), len);
port[len] = '\0';
}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;
username_or_host = NULL;
port = malloc(len + 1);
if(!port){
fprintf(stderr, "Error: Out of memory.\n");
goto cleanup;
}
memcpy(port, &(str[start]), len);
port[len] = '\0';
}else{
host = malloc(len + 1);
if(!host){
fprintf(stderr, "Error: Out of memory.\n");
goto cleanup;
}
memcpy(host, &(str[start]), len);
host[len] = '\0';
}

View File

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

View File

@ -230,6 +230,7 @@ int main(int argc, char *argv[])
struct mosquitto *mosq = NULL;
int rc;
memset(&cfg, 0, sizeof(struct mosq_config));
rc = client_config_load(&cfg, CLIENT_SUB, argc, argv);
if(rc){
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)
{
#ifdef WIN32
srand(GetTickCount());
srand(GetTickCount64());
#else
struct timeval tv;
@ -74,9 +74,7 @@ int mosquitto_lib_init(void)
srand(tv.tv_sec*1000 + tv.tv_usec/1000);
#endif
net__init();
return MOSQ_ERR_SUCCESS;
return net__init();
}
int mosquitto_lib_cleanup(void)

View File

@ -79,11 +79,13 @@ Contributors:
int tls_ex_index_mosq = -1;
#endif
void net__init(void)
int net__init(void)
{
#ifdef WIN32
WSADATA wsaData;
WSAStartup(MAKEWORD(2,2), &wsaData);
if(WSAStartup(MAKEWORD(2,2), &wsaData) != 0){
return MOSQ_ERR_UNKNOWN;
}
#endif
#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);
}
#endif
return MOSQ_ERR_SUCCESS;
}
void net__cleanup(void)

View File

@ -49,7 +49,7 @@ struct mosquitto_db;
#define MOSQ_MSB(A) (uint8_t)((A & 0xFF00) >> 8)
#define MOSQ_LSB(A) (uint8_t)(A & 0x00FF)
void net__init(void);
int net__init(void);
void net__cleanup(void);
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 "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)
{
#ifdef WIN32
if(tick64){
return GetTickCount64()/1000;
}else{
return GetTickCount()/1000; /* FIXME - need to deal with overflow. */
}
return GetTickCount64()/1000;
#elif _POSIX_TIMERS>0 && defined(_POSIX_MONOTONIC_CLOCK)
struct timespec tp;

View File

@ -444,7 +444,7 @@ int main(int argc, char *argv[])
}
#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;
int argc = 1;

View File

@ -211,7 +211,7 @@ int gets_quiet(char *s, int len)
{
#ifdef WIN32
HANDLE h;
DWORD con_orig, con_quiet;
DWORD con_orig, con_quiet = 0;
DWORD read_len = 0;
memset(s, 0, len);
@ -418,6 +418,10 @@ int main(int argc, char *argv[])
}
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);
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);
if(service_handle){
memset(conf_path, 0, MAX_PATH + 20);
rc = GetEnvironmentVariable("MOSQUITTO_DIR", conf_path, MAX_PATH);
if(!rc || rc == MAX_PATH){
service_status.dwCurrentState = SERVICE_STOPPED;
@ -91,7 +92,11 @@ void service_install(void)
char exe_path[MAX_PATH + 5];
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");
sc_manager = OpenSCManager(NULL, NULL, SC_MANAGER_CREATE_SERVICE);