OCT 1. 更新接口错误返回JSON数据
This commit is contained in:
parent
9794acc41d
commit
92cf406294
|
@ -4,10 +4,23 @@ AccessModifierOffset: -4
|
||||||
InsertBraces: true
|
InsertBraces: true
|
||||||
AlignArrayOfStructures: Left
|
AlignArrayOfStructures: Left
|
||||||
AlignAfterOpenBracket: Align
|
AlignAfterOpenBracket: Align
|
||||||
AlignConsecutiveMacros: Consecutive
|
AlignConsecutiveMacros:
|
||||||
AlignConsecutiveAssignments: Consecutive
|
Enabled: true
|
||||||
|
AcrossEmptyLines: true
|
||||||
|
AcrossComments: true
|
||||||
|
AlignConsecutiveAssignments:
|
||||||
|
Enabled: true
|
||||||
|
AcrossEmptyLines: false
|
||||||
|
AcrossComments: true
|
||||||
|
PadOperators: true
|
||||||
|
AlignCompound: true
|
||||||
AlignConsecutiveBitFields: None
|
AlignConsecutiveBitFields: None
|
||||||
AlignConsecutiveDeclarations: Consecutive
|
AlignConsecutiveDeclarations:
|
||||||
|
Enabled: true
|
||||||
|
AcrossEmptyLines: false
|
||||||
|
AcrossComments: true
|
||||||
|
PadOperators: true
|
||||||
|
AlignCompound: true
|
||||||
AlignEscapedNewlines: Left
|
AlignEscapedNewlines: Left
|
||||||
AlignOperands: DontAlign
|
AlignOperands: DontAlign
|
||||||
AlignTrailingComments: true
|
AlignTrailingComments: true
|
||||||
|
@ -195,6 +208,7 @@ StatementMacros:
|
||||||
TabWidth: 4
|
TabWidth: 4
|
||||||
UseCRLF: false
|
UseCRLF: false
|
||||||
UseTab: Never
|
UseTab: Never
|
||||||
|
SeparateDefinitionBlocks: Always
|
||||||
WhitespaceSensitiveMacros:
|
WhitespaceSensitiveMacros:
|
||||||
- STRINGIZE
|
- STRINGIZE
|
||||||
- PP_STRINGIZE
|
- PP_STRINGIZE
|
||||||
|
|
|
@ -166,6 +166,7 @@ typedef struct {
|
||||||
void *headers;
|
void *headers;
|
||||||
hw_string *body;
|
hw_string *body;
|
||||||
size_t body_length;
|
size_t body_length;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
OK,
|
OK,
|
||||||
SIZE_EXCEEDED,
|
SIZE_EXCEEDED,
|
||||||
|
@ -174,8 +175,9 @@ typedef struct {
|
||||||
} state;
|
} state;
|
||||||
} http_request;
|
} http_request;
|
||||||
|
|
||||||
typedef void(HAYWIRE_CALLING_CONVENTION *http_request_callback)(http_request *request, hw_http_response *response,
|
typedef void(HAYWIRE_CALLING_CONVENTION *http_request_callback)(http_request *request,
|
||||||
void *user_data);
|
hw_http_response *response,
|
||||||
|
void *user_data);
|
||||||
typedef void(HAYWIRE_CALLING_CONVENTION *http_response_complete_callback)(void *user_data);
|
typedef void(HAYWIRE_CALLING_CONVENTION *http_response_complete_callback)(void *user_data);
|
||||||
|
|
||||||
HAYWIRE_EXTERN int hw_init_from_config(char *configuration_filename);
|
HAYWIRE_EXTERN int hw_init_from_config(char *configuration_filename);
|
||||||
|
@ -185,13 +187,14 @@ HAYWIRE_EXTERN void free_http_server();
|
||||||
HAYWIRE_EXTERN void hw_http_add_route(char *route, http_request_callback callback, void *user_data);
|
HAYWIRE_EXTERN void hw_http_add_route(char *route, http_request_callback callback, void *user_data);
|
||||||
HAYWIRE_EXTERN hw_string *hw_get_header(http_request *request, hw_string *key);
|
HAYWIRE_EXTERN hw_string *hw_get_header(http_request *request, hw_string *key);
|
||||||
|
|
||||||
HAYWIRE_EXTERN void hw_free_http_response(hw_http_response *response);
|
HAYWIRE_EXTERN void hw_free_http_response(hw_http_response *response);
|
||||||
HAYWIRE_EXTERN void hw_set_http_version(hw_http_response *response, unsigned short major, unsigned short minor);
|
HAYWIRE_EXTERN void hw_set_http_version(hw_http_response *response, unsigned short major, unsigned short minor);
|
||||||
HAYWIRE_EXTERN void hw_set_response_status_code(hw_http_response *response, hw_string *status_code);
|
HAYWIRE_EXTERN void hw_set_response_status_code(hw_http_response *response, hw_string *status_code);
|
||||||
HAYWIRE_EXTERN void hw_set_response_header(hw_http_response *response, hw_string *name, hw_string *value);
|
HAYWIRE_EXTERN void hw_set_response_header(hw_http_response *response, hw_string *name, hw_string *value);
|
||||||
HAYWIRE_EXTERN void hw_set_body(hw_http_response *response, hw_string *body);
|
HAYWIRE_EXTERN void hw_set_body(hw_http_response *response, hw_string *body);
|
||||||
HAYWIRE_EXTERN void hw_http_response_send(hw_http_response *response, void *user_data,
|
HAYWIRE_EXTERN void hw_http_response_send(hw_http_response *response,
|
||||||
http_response_complete_callback callback);
|
void *user_data,
|
||||||
|
http_response_complete_callback callback);
|
||||||
HAYWIRE_EXTERN void hw_http_response_send_error(hw_http_response *response, const char *error, const char *err_msg);
|
HAYWIRE_EXTERN void hw_http_response_send_error(hw_http_response *response, const char *error, const char *err_msg);
|
||||||
HAYWIRE_EXTERN void hw_print_request_headers(http_request *request);
|
HAYWIRE_EXTERN void hw_print_request_headers(http_request *request);
|
||||||
|
|
||||||
|
|
|
@ -42,34 +42,34 @@ using namespace std;
|
||||||
#include "task_manager.h"
|
#include "task_manager.h"
|
||||||
#include "user_errno.h"
|
#include "user_errno.h"
|
||||||
|
|
||||||
void on_system_exit(void *p);
|
void on_system_exit(void *p);
|
||||||
//Global Variables
|
//Global Variables
|
||||||
timeval tv;
|
timeval tv;
|
||||||
fd_set readfds;
|
fd_set readfds;
|
||||||
//fd_set writefds;
|
//fd_set writefds;
|
||||||
data9 dhcpr;
|
data9 dhcpr;
|
||||||
data9 token;
|
data9 token;
|
||||||
data1 network;
|
data1 network;
|
||||||
data1 newNetwork;
|
data1 newNetwork;
|
||||||
data2 cfig;
|
data2 cfig;
|
||||||
data71 lump;
|
data71 lump;
|
||||||
bool kRunning = true;
|
bool kRunning = true;
|
||||||
dhcpMap dhcpCache;
|
dhcpMap dhcpCache;
|
||||||
char serviceName[] = "OpenDHCPServer";
|
char serviceName[] = "OpenDHCPServer";
|
||||||
//char tempbuff[512] = "";
|
//char tempbuff[512] = "";
|
||||||
//char logBuff[256];
|
//char logBuff[256];
|
||||||
//char extbuff[256] = "";
|
//char extbuff[256] = "";
|
||||||
bool verbatim = false;
|
bool verbatim = false;
|
||||||
char iniFile[256] = "";
|
char iniFile[256] = "";
|
||||||
char leaFile[256] = "";
|
char leaFile[256] = "";
|
||||||
//char logFile[256] = "";
|
//char logFile[256] = "";
|
||||||
char filePATH[256] = "";
|
char filePATH[256] = "";
|
||||||
char htmlTitle[256] = "";
|
char htmlTitle[256] = "";
|
||||||
char nicif[256] = "";
|
char nicif[256] = "";
|
||||||
//char arpa[] = ".in-addr.arpa";
|
//char arpa[] = ".in-addr.arpa";
|
||||||
time_t t = time(nullptr);
|
time_t t = time(nullptr);
|
||||||
pthread_mutex_t mutStateFile = PTHREAD_MUTEX_INITIALIZER;
|
pthread_mutex_t mutStateFile = PTHREAD_MUTEX_INITIALIZER;
|
||||||
pthread_mutex_t mutLogFile = PTHREAD_MUTEX_INITIALIZER;
|
pthread_mutex_t mutLogFile = PTHREAD_MUTEX_INITIALIZER;
|
||||||
struct ifconf Ifc;
|
struct ifconf Ifc;
|
||||||
struct ifreq IfcBuf[MAX_SERVERS];
|
struct ifreq IfcBuf[MAX_SERVERS];
|
||||||
|
|
||||||
|
@ -81,11 +81,11 @@ const char GLOBALOPTIONS[] = "GLOBAL_OPTIONS";
|
||||||
//const char send200[] = "HTTP/1.1 200 OK\r\nDate: %s\r\nLast-Modified: %s\r\nContent-Type: text/html\r\nConnection: Close\r\nTransfer-Encoding: chunked\r\n";
|
//const char send200[] = "HTTP/1.1 200 OK\r\nDate: %s\r\nLast-Modified: %s\r\nContent-Type: text/html\r\nConnection: Close\r\nTransfer-Encoding: chunked\r\n";
|
||||||
//const char send200[] = "HTTP/1.1 200 OK\r\nDate: %s\r\nLast-Modified: %s\r\nContent-Type: text/html\r\nConnection: Close\r\nContent-Length: \r\n\r\n";
|
//const char send200[] = "HTTP/1.1 200 OK\r\nDate: %s\r\nLast-Modified: %s\r\nContent-Type: text/html\r\nConnection: Close\r\nContent-Length: \r\n\r\n";
|
||||||
//const char send200[] = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: Close\r\n\r\n";
|
//const char send200[] = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: Close\r\n\r\n";
|
||||||
const char send403[] = "HTTP/1.1 403 Forbidden\r\n\r\n<h1>403 Forbidden</h1>";
|
const char send403[] = "HTTP/1.1 403 Forbidden\r\n\r\n<h1>403 Forbidden</h1>";
|
||||||
const char send404[] = "HTTP/1.1 404 Not Found\r\n\r\n<h1>404 Not Found</h1>";
|
const char send404[] = "HTTP/1.1 404 Not Found\r\n\r\n<h1>404 Not Found</h1>";
|
||||||
const char td200[] = "<td>%s</td>";
|
const char td200[] = "<td>%s</td>";
|
||||||
const char tdnowrap200[] = "<td nowrap>%s</td>";
|
const char tdnowrap200[] = "<td nowrap>%s</td>";
|
||||||
const char sVersion[] = "Open DHCP Server Version 1.80 Linux Build 1054";
|
const char sVersion[] = "Open DHCP Server Version 1.80 Linux Build 1054";
|
||||||
const char htmlStart[] =
|
const char htmlStart[] =
|
||||||
"<html>\n<head>\n<title>%s</title><meta http-equiv=\"refresh\" content=\"60\">\n<meta http-equiv=\"cache-control\" "
|
"<html>\n<head>\n<title>%s</title><meta http-equiv=\"refresh\" content=\"60\">\n<meta http-equiv=\"cache-control\" "
|
||||||
"content=\"no-cache\">\n</head>\n";
|
"content=\"no-cache\">\n</head>\n";
|
||||||
|
@ -766,8 +766,8 @@ void prepareUserHtmlRespStatus(data19 *req) {
|
||||||
data7 *dhcpEntry = nullptr;
|
data7 *dhcpEntry = nullptr;
|
||||||
//data7 *cache = nullptr;
|
//data7 *cache = nullptr;
|
||||||
//printf("%d=%d\n", dhcpCache.size(), cfig.dhcpSize);
|
//printf("%d=%d\n", dhcpCache.size(), cfig.dhcpSize);
|
||||||
req->memSize = (int)(2048 + (135 * dhcpCache.size()) + (cfig.dhcpSize * 26));
|
req->memSize = (int)(2048 + (135 * dhcpCache.size()) + (cfig.dhcpSize * 26));
|
||||||
req->dp = (char *)calloc(1, req->memSize);
|
req->dp = (char *)calloc(1, req->memSize);
|
||||||
|
|
||||||
if (!req->dp) {
|
if (!req->dp) {
|
||||||
sprintf(logBuff, "Memory Error");
|
sprintf(logBuff, "Memory Error");
|
||||||
|
@ -784,7 +784,7 @@ void prepareUserHtmlRespStatus(data19 *req) {
|
||||||
//fp += sprintf(fp, send200, tempbuff, tempbuff);
|
//fp += sprintf(fp, send200, tempbuff, tempbuff);
|
||||||
//fp += sprintf(fp, send200);
|
//fp += sprintf(fp, send200);
|
||||||
//char *contentStart = fp;
|
//char *contentStart = fp;
|
||||||
fp += sprintf(fp, htmlStart, htmlTitle);
|
fp += sprintf(fp, htmlStart, htmlTitle);
|
||||||
|
|
||||||
if (cfig.replication == 1) {
|
if (cfig.replication == 1) {
|
||||||
fp += sprintf(fp, bodyStart, sVersion, cfig.servername, "(Primary)");
|
fp += sprintf(fp, bodyStart, sVersion, cfig.servername, "(Primary)");
|
||||||
|
@ -826,7 +826,7 @@ void prepareUserHtmlRespStatus(data19 *req) {
|
||||||
if (dhcpEntry->hostname[0]) {
|
if (dhcpEntry->hostname[0]) {
|
||||||
strcpy(tempbuff, dhcpEntry->hostname);
|
strcpy(tempbuff, dhcpEntry->hostname);
|
||||||
tempbuff[20] = 0;
|
tempbuff[20] = 0;
|
||||||
fp += sprintf(fp, td200, tempbuff);
|
fp += sprintf(fp, td200, tempbuff);
|
||||||
} else {
|
} else {
|
||||||
fp += sprintf(fp, td200, " ");
|
fp += sprintf(fp, td200, " ");
|
||||||
}
|
}
|
||||||
|
@ -890,12 +890,12 @@ void prepareUserHtmlRespStatus(data19 *req) {
|
||||||
for (p = dhcpCache.begin(); kRunning && p != dhcpCache.end() && fp < maxData; p++) {
|
for (p = dhcpCache.begin(); kRunning && p != dhcpCache.end() && fp < maxData; p++) {
|
||||||
if ((dhcpEntry = p->second) && dhcpEntry->fixed && dhcpEntry->expiry < t) {
|
if ((dhcpEntry = p->second) && dhcpEntry->fixed && dhcpEntry->expiry < t) {
|
||||||
if (!colNum) {
|
if (!colNum) {
|
||||||
fp += sprintf(fp, "<tr>");
|
fp += sprintf(fp, "<tr>");
|
||||||
colNum = 1;
|
colNum = 1;
|
||||||
} else if (colNum == 1) {
|
} else if (colNum == 1) {
|
||||||
colNum = 2;
|
colNum = 2;
|
||||||
} else if (colNum == 2) {
|
} else if (colNum == 2) {
|
||||||
fp += sprintf(fp, "</tr>\n<tr>");
|
fp += sprintf(fp, "</tr>\n<tr>");
|
||||||
colNum = 1;
|
colNum = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -908,7 +908,7 @@ void prepareUserHtmlRespStatus(data19 *req) {
|
||||||
fp += sprintf(fp, "</tr>\n");
|
fp += sprintf(fp, "</tr>\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
fp += sprintf(fp, "</table></td></tr></table>\n</body>\n</html>");
|
fp += sprintf(fp, "</table></td></tr></table>\n</body>\n</html>");
|
||||||
//MYBYTE x = sprintf(tempbuff, "%u", (fp - contentStart));
|
//MYBYTE x = sprintf(tempbuff, "%u", (fp - contentStart));
|
||||||
//memcpy((contentStart - 12), tempbuff, x);
|
//memcpy((contentStart - 12), tempbuff, x);
|
||||||
req->bytes = (int)(fp - req->dp);
|
req->bytes = (int)(fp - req->dp);
|
||||||
|
@ -1145,7 +1145,7 @@ void *sendHTTP(void *lpParam) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
dp += sent;
|
dp += sent;
|
||||||
req->bytes -= sent;
|
req->bytes -= sent;
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
|
@ -2698,7 +2698,7 @@ void loadOptions(FILE *f, const char *sectionName, data20 *optionData) {
|
||||||
*dp = valSize;
|
*dp = valSize;
|
||||||
dp++;
|
dp++;
|
||||||
memcpy(dp, value, valSize);
|
memcpy(dp, value, valSize);
|
||||||
dp += valSize;
|
dp += valSize;
|
||||||
buffsize -= (valSize + 2);
|
buffsize -= (valSize + 2);
|
||||||
} else {
|
} else {
|
||||||
sprintf(logBuff, "Warning: section [%s] option %s, no more space for options", sectionName, raw);
|
sprintf(logBuff, "Warning: section [%s] option %s, no more space for options", sectionName, raw);
|
||||||
|
@ -2744,7 +2744,7 @@ void loadOptions(FILE *f, const char *sectionName, data20 *optionData) {
|
||||||
*dp = valSize;
|
*dp = valSize;
|
||||||
dp++;
|
dp++;
|
||||||
memcpy(dp, value, valSize);
|
memcpy(dp, value, valSize);
|
||||||
dp += valSize;
|
dp += valSize;
|
||||||
buffsize -= (valSize + 2);
|
buffsize -= (valSize + 2);
|
||||||
} else {
|
} else {
|
||||||
sprintf(logBuff,
|
sprintf(logBuff,
|
||||||
|
@ -2814,7 +2814,7 @@ void loadOptions(FILE *f, const char *sectionName, data20 *optionData) {
|
||||||
dp++;
|
dp++;
|
||||||
*dp = 4;
|
*dp = 4;
|
||||||
dp++;
|
dp++;
|
||||||
dp += pUInt(dp, j);
|
dp += pUInt(dp, j);
|
||||||
buffsize -= 6;
|
buffsize -= 6;
|
||||||
//printf("%s=%u=%u\n",opData[op_index].opName,opData[op_index].opType,htonl(j));
|
//printf("%s=%u=%u\n",opData[op_index].opName,opData[op_index].opType,htonl(j));
|
||||||
} else {
|
} else {
|
||||||
|
@ -2846,7 +2846,7 @@ void loadOptions(FILE *f, const char *sectionName, data20 *optionData) {
|
||||||
dp++;
|
dp++;
|
||||||
*dp = 2;
|
*dp = 2;
|
||||||
dp++;
|
dp++;
|
||||||
dp += pUShort(dp, j);
|
dp += pUShort(dp, j);
|
||||||
buffsize -= 4;
|
buffsize -= 4;
|
||||||
} else {
|
} else {
|
||||||
sprintf(logBuff, "Warning: section [%s] option %s, no more space for options", sectionName, raw);
|
sprintf(logBuff, "Warning: section [%s] option %s, no more space for options", sectionName, raw);
|
||||||
|
@ -2944,7 +2944,7 @@ void loadOptions(FILE *f, const char *sectionName, data20 *optionData) {
|
||||||
*dp = valSize;
|
*dp = valSize;
|
||||||
dp++;
|
dp++;
|
||||||
memcpy(dp, value, valSize);
|
memcpy(dp, value, valSize);
|
||||||
dp += valSize;
|
dp += valSize;
|
||||||
buffsize -= (valSize + 2);
|
buffsize -= (valSize + 2);
|
||||||
} else {
|
} else {
|
||||||
sprintf(logBuff, "Warning: section [%s] option %s, no more space for options", sectionName, raw);
|
sprintf(logBuff, "Warning: section [%s] option %s, no more space for options", sectionName, raw);
|
||||||
|
@ -3057,7 +3057,7 @@ int addDHCPRange(char *dp) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m < MAX_DHCP_RANGES) {
|
if (m < MAX_DHCP_RANGES) {
|
||||||
cfig.dhcpSize += (re - rs + 1);
|
cfig.dhcpSize += (re - rs + 1);
|
||||||
range = &cfig.dhcpRanges[m];
|
range = &cfig.dhcpRanges[m];
|
||||||
range->rangeStart = rs;
|
range->rangeStart = rs;
|
||||||
range->rangeEnd = re;
|
range->rangeEnd = re;
|
||||||
|
@ -3465,7 +3465,7 @@ void loadDHCP() {
|
||||||
dhcpData.expiry = dhcpEntry->expiry;
|
dhcpData.expiry = dhcpEntry->expiry;
|
||||||
dhcpData.local = dhcpEntry->local;
|
dhcpData.local = dhcpEntry->local;
|
||||||
strcpy(dhcpData.hostname, dhcpEntry->hostname);
|
strcpy(dhcpData.hostname, dhcpEntry->hostname);
|
||||||
cfig.dhcpInd += 1;
|
cfig.dhcpInd += 1;
|
||||||
dhcpEntry->dhcpInd = cfig.dhcpInd;
|
dhcpEntry->dhcpInd = cfig.dhcpInd;
|
||||||
dhcpData.dhcpInd = dhcpEntry->dhcpInd;
|
dhcpData.dhcpInd = dhcpEntry->dhcpInd;
|
||||||
|
|
||||||
|
@ -4233,7 +4233,7 @@ void *updateStateFile(void *lpParam) {
|
||||||
strcpy(dhcpData.hostname, dhcpEntry->hostname);
|
strcpy(dhcpData.hostname, dhcpEntry->hostname);
|
||||||
|
|
||||||
if (!dhcpEntry->dhcpInd) {
|
if (!dhcpEntry->dhcpInd) {
|
||||||
cfig.dhcpInd += 1;
|
cfig.dhcpInd += 1;
|
||||||
dhcpEntry->dhcpInd = cfig.dhcpInd;
|
dhcpEntry->dhcpInd = cfig.dhcpInd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4999,11 +4999,11 @@ void getInterfaces(data1 *pNetwork) {
|
||||||
Ifc.ifc_buf = (char *)IfcBuf;
|
Ifc.ifc_buf = (char *)IfcBuf;
|
||||||
|
|
||||||
if (ioctl(cfig.fixedSocket, SIOCGIFCONF, &Ifc) >= 0) {
|
if (ioctl(cfig.fixedSocket, SIOCGIFCONF, &Ifc) >= 0) {
|
||||||
|
|
||||||
MYDWORD addr, mask;
|
|
||||||
short flags;
|
|
||||||
struct ifreq pIfr {};
|
struct ifreq pIfr {};
|
||||||
MYBYTE numInterfaces = Ifc.ifc_len / sizeof(ifreq);
|
|
||||||
|
MYDWORD addr, mask;
|
||||||
|
short flags;
|
||||||
|
MYBYTE numInterfaces = Ifc.ifc_len / sizeof(ifreq);
|
||||||
|
|
||||||
for (MYBYTE i = 0; i < numInterfaces; i++) {
|
for (MYBYTE i = 0; i < numInterfaces; i++) {
|
||||||
memcpy(&pIfr, &(IfcBuf[i]), sizeof(ifreq));
|
memcpy(&pIfr, &(IfcBuf[i]), sizeof(ifreq));
|
||||||
|
|
|
@ -3,8 +3,6 @@
|
||||||
//
|
//
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <map>
|
#include <map>
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
|
@ -25,6 +23,8 @@ using namespace std;
|
||||||
#include "user_errno.h"
|
#include "user_errno.h"
|
||||||
#include "uthash/uthash.h"
|
#include "uthash/uthash.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
extern data2 cfig;
|
extern data2 cfig;
|
||||||
extern bool kRunning;
|
extern bool kRunning;
|
||||||
extern dhcpMap dhcpCache;
|
extern dhcpMap dhcpCache;
|
||||||
|
@ -123,7 +123,7 @@ static int dhcp_get_user_info(data19 *req, const char *pRequest) {
|
||||||
//char *maxData = req->dp + (req->memSize - 512);
|
//char *maxData = req->dp + (req->memSize - 512);
|
||||||
|
|
||||||
//fp += sprintf(fp, send200, strlen(rspBuf));
|
//fp += sprintf(fp, send200, strlen(rspBuf));
|
||||||
fp += sprintf(fp, "%s", pStrPro);
|
fp += sprintf(fp, "%s", pStrPro);
|
||||||
req->bytes = (int)(fp - req->dp);
|
req->bytes = (int)(fp - req->dp);
|
||||||
|
|
||||||
cJSON_Delete(pRoot);
|
cJSON_Delete(pRoot);
|
||||||
|
@ -169,7 +169,7 @@ static int dhcp_get_all_user(data19 *req) {
|
||||||
|
|
||||||
const char *pStrPro = proto_create_new(pRspMsg, 200);
|
const char *pStrPro = proto_create_new(pRspMsg, 200);
|
||||||
|
|
||||||
fp += sprintf(fp, "%s", pStrPro);
|
fp += sprintf(fp, "%s", pStrPro);
|
||||||
req->bytes = (int)(fp - req->dp);
|
req->bytes = (int)(fp - req->dp);
|
||||||
|
|
||||||
free((void *)pStrPro);
|
free((void *)pStrPro);
|
||||||
|
@ -199,7 +199,7 @@ static int dhcp_get_all_user(data19 *req) {
|
||||||
*dp = valSize; \
|
*dp = valSize; \
|
||||||
dp++; \
|
dp++; \
|
||||||
memcpy(dp, (val), valSize); \
|
memcpy(dp, (val), valSize); \
|
||||||
dp += valSize; \
|
dp += valSize; \
|
||||||
buffSize -= (valSize + 2); \
|
buffSize -= (valSize + 2); \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
|
@ -393,9 +393,9 @@ static int add_dhcpd_rangeset(data19 *req, const char *pRequest) {
|
||||||
return ERR_SUCCESS;
|
return ERR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct hash_map{
|
struct hash_map {
|
||||||
unsigned int key;
|
unsigned int key;
|
||||||
unsigned int value;
|
unsigned int value;
|
||||||
UT_hash_handle hh;
|
UT_hash_handle hh;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -406,7 +406,7 @@ static int delete_dhcpd_rangeset(data19 *req, const char *pRequest) {
|
||||||
cJSON *pRspRoot;
|
cJSON *pRspRoot;
|
||||||
cJSON *pdelArray;
|
cJSON *pdelArray;
|
||||||
data13 dhcpRanges[MAX_DHCP_RANGES];
|
data13 dhcpRanges[MAX_DHCP_RANGES];
|
||||||
hash_map *delMap = nullptr;
|
hash_map *delMap = nullptr;
|
||||||
int resCount = 0;
|
int resCount = 0;
|
||||||
|
|
||||||
dzlog_debug("Input: %s\n", pRequest);
|
dzlog_debug("Input: %s\n", pRequest);
|
||||||
|
@ -448,9 +448,9 @@ static int delete_dhcpd_rangeset(data19 *req, const char *pRequest) {
|
||||||
cJSON_AddItemToObject(pRspRoot, "rangeSet", pdelArray);
|
cJSON_AddItemToObject(pRspRoot, "rangeSet", pdelArray);
|
||||||
|
|
||||||
for (int i = 0; i < cJSON_GetArraySize(pdhcp_range); i++) {
|
for (int i = 0; i < cJSON_GetArraySize(pdhcp_range); i++) {
|
||||||
cJSON *pdelRange = cJSON_GetArrayItem(pdhcp_range, i);
|
cJSON *pdelRange = cJSON_GetArrayItem(pdhcp_range, i);
|
||||||
char del_range[256];
|
char del_range[256];
|
||||||
auto *delItem = (struct hash_map*)malloc(sizeof(hash_map));
|
auto *delItem = (struct hash_map *)malloc(sizeof(hash_map));
|
||||||
|
|
||||||
if (!pdelRange) {
|
if (!pdelRange) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -467,15 +467,15 @@ static int delete_dhcpd_rangeset(data19 *req, const char *pRequest) {
|
||||||
en_addr = htonl(inet_addr(end));
|
en_addr = htonl(inet_addr(end));
|
||||||
|
|
||||||
HASH_FIND_INT(delMap, &st_addr, delItem);
|
HASH_FIND_INT(delMap, &st_addr, delItem);
|
||||||
if (delItem == nullptr){
|
if (delItem == nullptr) {
|
||||||
hash_map *s = (struct hash_map*)malloc(sizeof(struct hash_map));
|
hash_map *s = (struct hash_map *)malloc(sizeof(struct hash_map));
|
||||||
s->key = st_addr;
|
s->key = st_addr;
|
||||||
s->value = en_addr;
|
s->value = en_addr;
|
||||||
HASH_ADD_INT(delMap, key, s);
|
HASH_ADD_INT(delMap, key, s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i = 0; i < cfig.rangeCount; i++){
|
for (int i = 0; i < cfig.rangeCount; i++) {
|
||||||
cJSON *pdel_Item = cJSON_CreateObject();
|
cJSON *pdel_Item = cJSON_CreateObject();
|
||||||
hash_map *delRange;
|
hash_map *delRange;
|
||||||
char del_range[256];
|
char del_range[256];
|
||||||
|
@ -484,18 +484,18 @@ static int delete_dhcpd_rangeset(data19 *req, const char *pRequest) {
|
||||||
memset(del_range, 0, 256);
|
memset(del_range, 0, 256);
|
||||||
|
|
||||||
HASH_FIND_INT(delMap, &cfig.dhcpRanges[i].rangeStart, delRange);
|
HASH_FIND_INT(delMap, &cfig.dhcpRanges[i].rangeStart, delRange);
|
||||||
if(delRange != nullptr){
|
if (delRange != nullptr) {
|
||||||
IP2String(saddr, ntohl(delRange->key));
|
IP2String(saddr, ntohl(delRange->key));
|
||||||
IP2String(eaddr, ntohl(delRange->value));
|
IP2String(eaddr, ntohl(delRange->value));
|
||||||
|
|
||||||
sprintf(del_range, "%s-%s", saddr, eaddr);
|
sprintf(del_range, "%s-%s", saddr, eaddr);
|
||||||
cJSON_AddStringToObject(pdel_Item, "dhcpRange", del_range);
|
cJSON_AddStringToObject(pdel_Item, "dhcpRange", del_range);
|
||||||
//judge whether the input has error
|
//judge whether the input has error
|
||||||
if(delRange->key && delRange->value &&
|
if (delRange->key && delRange->value && (delRange->key == cfig.dhcpRanges[i].rangeStart) &&
|
||||||
(delRange->key == cfig.dhcpRanges[i].rangeStart) && (delRange->value == cfig.dhcpRanges[i].rangeEnd)){
|
(delRange->value == cfig.dhcpRanges[i].rangeEnd)) {
|
||||||
cJSON_AddNumberToObject(pdel_Item, "status", ERR_SUCCESS);
|
cJSON_AddNumberToObject(pdel_Item, "status", ERR_SUCCESS);
|
||||||
cJSON_AddStringToObject(pdel_Item, "message", getErrorEnumDesc(ERR_SUCCESS));
|
cJSON_AddStringToObject(pdel_Item, "message", getErrorEnumDesc(ERR_SUCCESS));
|
||||||
cJSON_AddItemToArray(pdelArray, pdel_Item);
|
cJSON_AddItemToArray(pdelArray, pdel_Item);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
memcpy(&dhcpRanges[resCount], &cfig.dhcpRanges[i], sizeof(struct data13));
|
memcpy(&dhcpRanges[resCount], &cfig.dhcpRanges[i], sizeof(struct data13));
|
||||||
|
@ -512,8 +512,8 @@ static int delete_dhcpd_rangeset(data19 *req, const char *pRequest) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//rewite cfig.dhcpRanges
|
//rewite cfig.dhcpRanges
|
||||||
for(int i = 0; i < cfig.rangeCount; i++){
|
for (int i = 0; i < cfig.rangeCount; i++) {
|
||||||
if(i < resCount){
|
if (i < resCount) {
|
||||||
memcpy(&cfig.dhcpRanges[i], &dhcpRanges[i], sizeof(struct data13));
|
memcpy(&cfig.dhcpRanges[i], &dhcpRanges[i], sizeof(struct data13));
|
||||||
} else {
|
} else {
|
||||||
memset(&cfig.dhcpRanges[i], 0, sizeof(struct data13));
|
memset(&cfig.dhcpRanges[i], 0, sizeof(struct data13));
|
||||||
|
@ -523,7 +523,7 @@ static int delete_dhcpd_rangeset(data19 *req, const char *pRequest) {
|
||||||
cfig.rangeCount = resCount;
|
cfig.rangeCount = resCount;
|
||||||
|
|
||||||
const char *pStrPro = proto_create_new(pRspRoot, 200);
|
const char *pStrPro = proto_create_new(pRspRoot, 200);
|
||||||
fp += sprintf(fp, "%s", pStrPro);
|
fp += sprintf(fp, "%s", pStrPro);
|
||||||
|
|
||||||
cJSON_Delete(pRoot);
|
cJSON_Delete(pRoot);
|
||||||
req->bytes = (int)(fp - req->dp);
|
req->bytes = (int)(fp - req->dp);
|
||||||
|
@ -532,15 +532,14 @@ static int delete_dhcpd_rangeset(data19 *req, const char *pRequest) {
|
||||||
return ERR_SUCCESS;
|
return ERR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void revert(unsigned int* num) {
|
static void revert(unsigned int *num) {
|
||||||
unsigned int v = *num ;
|
unsigned int v = *num;
|
||||||
v = ((v & 0x000000FF) << 24) | ((v & 0x0000FF00) << 8) |
|
v = ((v & 0x000000FF) << 24) | ((v & 0x0000FF00) << 8) | ((v & 0x00FF0000) >> 8) | ((v & 0xFF000000) >> 24);
|
||||||
((v & 0x00FF0000) >> 8) | ((v & 0xFF000000) >> 24) ;
|
*num = v;
|
||||||
*num = v ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int query_dhcpd_rangeset(data19 *req){
|
static int query_dhcpd_rangeset(data19 *req) {
|
||||||
char logBuff[512];
|
char logBuff[512];
|
||||||
req->memSize = (int)(2048 + (135 * dhcpCache.size()) + (cfig.dhcpSize * 26));
|
req->memSize = (int)(2048 + (135 * dhcpCache.size()) + (cfig.dhcpSize * 26));
|
||||||
req->dp = (char *)calloc(1, req->memSize);
|
req->dp = (char *)calloc(1, req->memSize);
|
||||||
|
|
||||||
|
@ -557,7 +556,7 @@ static int query_dhcpd_rangeset(data19 *req){
|
||||||
cJSON *pMsgArray = cJSON_CreateArray();
|
cJSON *pMsgArray = cJSON_CreateArray();
|
||||||
cJSON_AddItemToObject(pRspMsg, "rangeSet", pMsgArray);
|
cJSON_AddItemToObject(pRspMsg, "rangeSet", pMsgArray);
|
||||||
|
|
||||||
for (char rangeInd = 0; rangeInd < cfig.rangeCount; rangeInd++){
|
for (char rangeInd = 0; rangeInd < cfig.rangeCount; rangeInd++) {
|
||||||
char addrStart[64];
|
char addrStart[64];
|
||||||
char addrEnd[64];
|
char addrEnd[64];
|
||||||
char rangeSet[128];
|
char rangeSet[128];
|
||||||
|
@ -567,7 +566,7 @@ static int query_dhcpd_rangeset(data19 *req){
|
||||||
cJSON *pRangeItem = cJSON_CreateObject();
|
cJSON *pRangeItem = cJSON_CreateObject();
|
||||||
unsigned int lease;
|
unsigned int lease;
|
||||||
|
|
||||||
memset(domainServer, 0 , 128);
|
memset(domainServer, 0, 128);
|
||||||
IP2String(addrStart, ntohl(cfig.dhcpRanges[rangeInd].rangeStart));
|
IP2String(addrStart, ntohl(cfig.dhcpRanges[rangeInd].rangeStart));
|
||||||
IP2String(addrEnd, ntohl(cfig.dhcpRanges[rangeInd].rangeEnd));
|
IP2String(addrEnd, ntohl(cfig.dhcpRanges[rangeInd].rangeEnd));
|
||||||
IP2String(rangeMask, cfig.dhcpRanges[rangeInd].mask);
|
IP2String(rangeMask, cfig.dhcpRanges[rangeInd].mask);
|
||||||
|
@ -581,10 +580,10 @@ static int query_dhcpd_rangeset(data19 *req){
|
||||||
if (opPointer) {
|
if (opPointer) {
|
||||||
opPointer++;
|
opPointer++;
|
||||||
while (*opPointer && *opPointer != DHCP_OPTION_END) {
|
while (*opPointer && *opPointer != DHCP_OPTION_END) {
|
||||||
unsigned int tmpVal = 0;
|
unsigned int tmpVal = 0;
|
||||||
unsigned char dnsSize;
|
unsigned char dnsSize;
|
||||||
unsigned char offset = 0;
|
unsigned char offset = 0;
|
||||||
char dns_op[64];
|
char dns_op[64];
|
||||||
|
|
||||||
op.opt_code = *opPointer;
|
op.opt_code = *opPointer;
|
||||||
opPointer++;
|
opPointer++;
|
||||||
|
@ -592,28 +591,28 @@ static int query_dhcpd_rangeset(data19 *req){
|
||||||
opPointer++;
|
opPointer++;
|
||||||
|
|
||||||
memcpy(op.value, opPointer, op.size);
|
memcpy(op.value, opPointer, op.size);
|
||||||
if(op.opt_code == DHCP_OPTION_DNS){
|
if (op.opt_code == DHCP_OPTION_DNS) {
|
||||||
dnsSize = op.size;
|
dnsSize = op.size;
|
||||||
do {
|
do {
|
||||||
tmpVal = fIP(op.value + offset);
|
tmpVal = fIP(op.value + offset);
|
||||||
revert(&tmpVal);
|
revert(&tmpVal);
|
||||||
IP2String(dns_op, ntohl(tmpVal));
|
IP2String(dns_op, ntohl(tmpVal));
|
||||||
sprintf(domainServer, "%s%s", domainServer, dns_op);
|
sprintf(domainServer, "%s%s", domainServer, dns_op);
|
||||||
if(dnsSize != 4){
|
if (dnsSize != 4) {
|
||||||
sprintf(domainServer, "%s,", domainServer);
|
sprintf(domainServer, "%s,", domainServer);
|
||||||
}
|
}
|
||||||
dnsSize -= 4;
|
dnsSize -= 4;
|
||||||
offset = op.size - dnsSize;
|
offset = op.size - dnsSize;
|
||||||
}while (dnsSize != 0);
|
} while (dnsSize != 0);
|
||||||
|
|
||||||
cJSON_AddStringToObject(pRangeItem, "domainServer", domainServer);
|
cJSON_AddStringToObject(pRangeItem, "domainServer", domainServer);
|
||||||
}else if(op.opt_code == DHCP_OPTION_ROUTER){
|
} else if (op.opt_code == DHCP_OPTION_ROUTER) {
|
||||||
tmpVal = fIP(op.value);
|
tmpVal = fIP(op.value);
|
||||||
revert(&tmpVal);
|
revert(&tmpVal);
|
||||||
IP2String(gateway, ntohl(tmpVal));
|
IP2String(gateway, ntohl(tmpVal));
|
||||||
|
|
||||||
cJSON_AddStringToObject(pRangeItem, "gateway", gateway);
|
cJSON_AddStringToObject(pRangeItem, "gateway", gateway);
|
||||||
}else if(op.opt_code == DHCP_OPTION_IPADDRLEASE){
|
} else if (op.opt_code == DHCP_OPTION_IPADDRLEASE) {
|
||||||
lease = fUInt(op.value);
|
lease = fUInt(op.value);
|
||||||
|
|
||||||
cJSON_AddNumberToObject(pRangeItem, "lease", lease);
|
cJSON_AddNumberToObject(pRangeItem, "lease", lease);
|
||||||
|
@ -629,7 +628,7 @@ static int query_dhcpd_rangeset(data19 *req){
|
||||||
|
|
||||||
const char *pStrPro = proto_create_new(pRspMsg, 200);
|
const char *pStrPro = proto_create_new(pRspMsg, 200);
|
||||||
|
|
||||||
fp += sprintf(fp, "%s", pStrPro);
|
fp += sprintf(fp, "%s", pStrPro);
|
||||||
req->bytes = (int)(fp - req->dp);
|
req->bytes = (int)(fp - req->dp);
|
||||||
|
|
||||||
free((void *)pStrPro);
|
free((void *)pStrPro);
|
||||||
|
@ -638,7 +637,8 @@ static int query_dhcpd_rangeset(data19 *req){
|
||||||
|
|
||||||
#pragma clang diagnostic push
|
#pragma clang diagnostic push
|
||||||
#pragma ide diagnostic ignored "cert-err34-c"
|
#pragma ide diagnostic ignored "cert-err34-c"
|
||||||
int getHwAddr(char *buff, char *mac) {
|
|
||||||
|
int getHwAddr(char *buff, char *mac) {
|
||||||
if (buff == nullptr || mac == nullptr) {
|
if (buff == nullptr || mac == nullptr) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -656,6 +656,7 @@ int getHwAddr(char *buff, char *mac) {
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma clang diagnostic pop
|
#pragma clang diagnostic pop
|
||||||
|
|
||||||
int arpSet(const char *ifname, char *ipStr, char *mac) {
|
int arpSet(const char *ifname, char *ipStr, char *mac) {
|
||||||
|
@ -831,8 +832,7 @@ static void opendhcp_http_get_alluser(http_request *request, hw_http_response *r
|
||||||
hw_string keep_alive_name;
|
hw_string keep_alive_name;
|
||||||
hw_string keep_alive_value;
|
hw_string keep_alive_value;
|
||||||
int ret;
|
int ret;
|
||||||
|
auto *req = (data19 *)malloc(sizeof(struct data19));
|
||||||
auto *req = (data19 *)malloc(sizeof(struct data19));
|
|
||||||
|
|
||||||
if (req == nullptr) {
|
if (req == nullptr) {
|
||||||
proto_response_error(response, 500, HTTP_STATUS_500, ERR_MALLOC_MEMORY);
|
proto_response_error(response, 500, HTTP_STATUS_500, ERR_MALLOC_MEMORY);
|
||||||
|
@ -879,16 +879,15 @@ static void opendhcp_http_add_rangeset(http_request *request, hw_http_response *
|
||||||
hw_string keep_alive_name;
|
hw_string keep_alive_name;
|
||||||
hw_string keep_alive_value;
|
hw_string keep_alive_value;
|
||||||
int ret;
|
int ret;
|
||||||
|
auto *req = (data19 *)malloc(sizeof(struct data19));
|
||||||
auto *req = (data19 *)malloc(sizeof(struct data19));
|
|
||||||
|
|
||||||
if (req == nullptr) {
|
if (req == nullptr) {
|
||||||
hw_http_response_send_error(response, HTTP_STATUS_500, "memory error");
|
proto_response_error(response, 500, HTTP_STATUS_500, ERR_MALLOC_MEMORY);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request->method != HW_HTTP_POST) {
|
if (request->method != HW_HTTP_POST) {
|
||||||
hw_http_response_send_error(response, HTTP_STATUS_405, HTTP_STATUS_405);
|
proto_response_error(response, 405, HTTP_STATUS_405, ERR_HTTP_UNSUP_METHOD);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -927,16 +926,15 @@ static void opendhcp_http_delete_rangeset(http_request *request, hw_http_respons
|
||||||
hw_string keep_alive_name;
|
hw_string keep_alive_name;
|
||||||
hw_string keep_alive_value;
|
hw_string keep_alive_value;
|
||||||
int ret;
|
int ret;
|
||||||
|
auto *req = (data19 *)malloc(sizeof(struct data19));
|
||||||
auto *req = (data19 *)malloc(sizeof(struct data19));
|
|
||||||
|
|
||||||
if (req == nullptr) {
|
if (req == nullptr) {
|
||||||
hw_http_response_send_error(response, HTTP_STATUS_500, "memory error");
|
proto_response_error(response, 500, HTTP_STATUS_500, ERR_MALLOC_MEMORY);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request->method != HW_HTTP_POST) {
|
if (request->method != HW_HTTP_POST) {
|
||||||
hw_http_response_send_error(response, HTTP_STATUS_405, HTTP_STATUS_405);
|
proto_response_error(response, 405, HTTP_STATUS_405, ERR_HTTP_UNSUP_METHOD);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -975,16 +973,15 @@ static void opendhcp_http_query_rangeset(http_request *request, hw_http_response
|
||||||
hw_string keep_alive_name;
|
hw_string keep_alive_name;
|
||||||
hw_string keep_alive_value;
|
hw_string keep_alive_value;
|
||||||
int ret;
|
int ret;
|
||||||
|
auto *req = (data19 *)malloc(sizeof(struct data19));
|
||||||
auto *req = (data19 *)malloc(sizeof(struct data19));
|
|
||||||
|
|
||||||
if (req == nullptr) {
|
if (req == nullptr) {
|
||||||
hw_http_response_send_error(response, HTTP_STATUS_500, "memory error");
|
proto_response_error(response, 500, HTTP_STATUS_500, ERR_MALLOC_MEMORY);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request->method != HW_HTTP_GET) {
|
if (request->method != HW_HTTP_GET) {
|
||||||
hw_http_response_send_error(response, HTTP_STATUS_405, HTTP_STATUS_405);
|
proto_response_error(response, 405, HTTP_STATUS_405, ERR_HTTP_UNSUP_METHOD);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1014,6 +1011,7 @@ static void opendhcp_http_query_rangeset(http_request *request, hw_http_response
|
||||||
|
|
||||||
hw_http_response_send(response, req, response_complete);
|
hw_http_response_send(response, req, response_complete);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加配置文件监听接口
|
* 添加配置文件监听接口
|
||||||
* @return
|
* @return
|
||||||
|
|
Loading…
Reference in New Issue