|
|
@ -10,6 +10,12 @@ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
#define APIVERSION "1.0" |
|
|
|
#define APIVERSION "1.0" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef _MSC_VER |
|
|
|
|
|
|
|
# define _WINSOCK_DEPRECATED_NO_WARNINGS |
|
|
|
|
|
|
|
# include <winsock2.h> |
|
|
|
|
|
|
|
# include <mstcpip.h> |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h> |
|
|
|
#include <stdio.h> |
|
|
|
#include <ctype.h> |
|
|
|
#include <ctype.h> |
|
|
|
#include <stdlib.h> |
|
|
|
#include <stdlib.h> |
|
|
@ -29,7 +35,7 @@ |
|
|
|
#include "compat.h" |
|
|
|
#include "compat.h" |
|
|
|
#include "miner.h" |
|
|
|
#include "miner.h" |
|
|
|
|
|
|
|
|
|
|
|
#ifndef WIN32 |
|
|
|
#ifndef _MSC_VER |
|
|
|
# include <errno.h> |
|
|
|
# include <errno.h> |
|
|
|
# include <sys/socket.h> |
|
|
|
# include <sys/socket.h> |
|
|
|
# include <netinet/in.h> |
|
|
|
# include <netinet/in.h> |
|
|
@ -43,12 +49,12 @@ |
|
|
|
# define SOCKETINIT {} |
|
|
|
# define SOCKETINIT {} |
|
|
|
# define SOCKERRMSG strerror(errno) |
|
|
|
# define SOCKERRMSG strerror(errno) |
|
|
|
#else |
|
|
|
#else |
|
|
|
# include <winsock2.h> |
|
|
|
|
|
|
|
# define SOCKETTYPE SOCKET |
|
|
|
# define SOCKETTYPE SOCKET |
|
|
|
# define SOCKETFAIL(a) ((a) == SOCKET_ERROR) |
|
|
|
# define SOCKETFAIL(a) ((a) == SOCKET_ERROR) |
|
|
|
# define INVSOCK INVALID_SOCKET |
|
|
|
# define INVSOCK INVALID_SOCKET |
|
|
|
# define INVINETADDR INADDR_NONE |
|
|
|
# define INVINETADDR INADDR_NONE |
|
|
|
# define CLOSESOCKET closesocket |
|
|
|
# define CLOSESOCKET closesocket |
|
|
|
|
|
|
|
#define in_addr_t uint32_t |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
#define GROUP(g) (toupper(g)) |
|
|
|
#define GROUP(g) (toupper(g)) |
|
|
@ -125,7 +131,9 @@ static void gpustatus(int thr_id) |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
gt = gf = gp = 0; |
|
|
|
{ |
|
|
|
|
|
|
|
gt = 0.0; gf = gp = 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// todo: can be 0 if set by algo (auto)
|
|
|
|
// todo: can be 0 if set by algo (auto)
|
|
|
|
if (opt_intensity == 0 && opt_work_size) { |
|
|
|
if (opt_intensity == 0 && opt_work_size) { |
|
|
@ -186,7 +194,7 @@ struct CMDS { |
|
|
|
|
|
|
|
|
|
|
|
#define CMDMAX 2 |
|
|
|
#define CMDMAX 2 |
|
|
|
|
|
|
|
|
|
|
|
static void send_result(int c, char *result) |
|
|
|
static void send_result(SOCKETTYPE c, char *result) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int n; |
|
|
|
int n; |
|
|
|
|
|
|
|
|
|
|
@ -194,7 +202,7 @@ static void send_result(int c, char *result) |
|
|
|
result = ""; |
|
|
|
result = ""; |
|
|
|
|
|
|
|
|
|
|
|
// ignore failure - it's closed immediately anyway
|
|
|
|
// ignore failure - it's closed immediately anyway
|
|
|
|
n = write(c, result, strlen(result)+1); |
|
|
|
n = send(c, result, strlen(result) + 1, 0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
@ -211,7 +219,7 @@ static void setup_ipaccess() |
|
|
|
int ipcount, mask, octet, i; |
|
|
|
int ipcount, mask, octet, i; |
|
|
|
char group; |
|
|
|
char group; |
|
|
|
|
|
|
|
|
|
|
|
buf = malloc(strlen(opt_api_allow) + 1); |
|
|
|
buf = (char*) calloc(1, strlen(opt_api_allow) + 1); |
|
|
|
if (unlikely(!buf)) |
|
|
|
if (unlikely(!buf)) |
|
|
|
proper_exit(1);//, "Failed to malloc ipaccess buf");
|
|
|
|
proper_exit(1);//, "Failed to malloc ipaccess buf");
|
|
|
|
|
|
|
|
|
|
|
@ -223,7 +231,11 @@ static void setup_ipaccess() |
|
|
|
ipcount++; |
|
|
|
ipcount++; |
|
|
|
|
|
|
|
|
|
|
|
// possibly more than needed, but never less
|
|
|
|
// possibly more than needed, but never less
|
|
|
|
|
|
|
|
#ifdef _MSC_VER |
|
|
|
|
|
|
|
ipaccess = (IP4ACCESS *) calloc(ipcount, sizeof(struct IP4ACCESS)); |
|
|
|
|
|
|
|
#else |
|
|
|
ipaccess = calloc(ipcount, sizeof(struct IP4ACCESS)); |
|
|
|
ipaccess = calloc(ipcount, sizeof(struct IP4ACCESS)); |
|
|
|
|
|
|
|
#endif |
|
|
|
if (unlikely(!ipaccess)) |
|
|
|
if (unlikely(!ipaccess)) |
|
|
|
proper_exit(1);//, "Failed to calloc ipaccess");
|
|
|
|
proper_exit(1);//, "Failed to calloc ipaccess");
|
|
|
|
|
|
|
|
|
|
|
@ -354,7 +366,7 @@ static void api() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
apisock = calloc(1, sizeof(*apisock)); |
|
|
|
apisock = (SOCKETTYPE*) calloc(1, sizeof(*apisock)); |
|
|
|
*apisock = INVSOCK; |
|
|
|
*apisock = INVSOCK; |
|
|
|
|
|
|
|
|
|
|
|
sleep(1); |
|
|
|
sleep(1); |
|
|
@ -420,7 +432,7 @@ static void api() |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
buffer = malloc(MYBUFSIZ+1); |
|
|
|
buffer = (char *) calloc(1, MYBUFSIZ + 1); |
|
|
|
|
|
|
|
|
|
|
|
counter = 0; |
|
|
|
counter = 0; |
|
|
|
while (bye == 0) { |
|
|
|
while (bye == 0) { |
|
|
@ -441,10 +453,9 @@ static void api() |
|
|
|
connectaddr, addrok ? "Accepted" : "Ignored"); |
|
|
|
connectaddr, addrok ? "Accepted" : "Ignored"); |
|
|
|
|
|
|
|
|
|
|
|
if (addrok) { |
|
|
|
if (addrok) { |
|
|
|
n = read(c, &buf[0], BUFSIZ-1); |
|
|
|
n = recv(c, &buf[0], BUFSIZ - 1, 0); |
|
|
|
if (n < 0) |
|
|
|
// applog(LOG_DEBUG, "API: recv command: (%d) '%s'", n, buf);
|
|
|
|
close(c); |
|
|
|
if (!SOCKETFAIL(n)) { |
|
|
|
else { |
|
|
|
|
|
|
|
buf[n] = '\0'; |
|
|
|
buf[n] = '\0'; |
|
|
|
params = strchr(buf, '|'); |
|
|
|
params = strchr(buf, '|'); |
|
|
|
if (params != NULL) |
|
|
|
if (params != NULL) |
|
|
@ -454,7 +465,7 @@ static void api() |
|
|
|
if (strcmp(buf, cmds[i].name) == 0) { |
|
|
|
if (strcmp(buf, cmds[i].name) == 0) { |
|
|
|
result = (cmds[i].func)(params); |
|
|
|
result = (cmds[i].func)(params); |
|
|
|
send_result(c, result); |
|
|
|
send_result(c, result); |
|
|
|
close(c); |
|
|
|
CLOSESOCKET(c); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -476,4 +487,4 @@ void *api_thread(void *userdata) |
|
|
|
tq_freeze(mythr->q); |
|
|
|
tq_freeze(mythr->q); |
|
|
|
|
|
|
|
|
|
|
|
return NULL; |
|
|
|
return NULL; |
|
|
|
} |
|
|
|
} |
|
|
|