Merge remote-tracking branch 'origin/master'
# Conflicts: # srcs/open_dhcp/query.cpp
This commit is contained in:
commit
9efa161728
|
@ -4,10 +4,23 @@ AccessModifierOffset: -4
|
|||
InsertBraces: true
|
||||
AlignArrayOfStructures: Left
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignConsecutiveMacros: Consecutive
|
||||
AlignConsecutiveAssignments: Consecutive
|
||||
AlignConsecutiveMacros:
|
||||
Enabled: true
|
||||
AcrossEmptyLines: true
|
||||
AcrossComments: true
|
||||
AlignConsecutiveAssignments:
|
||||
Enabled: true
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: true
|
||||
PadOperators: true
|
||||
AlignCompound: true
|
||||
AlignConsecutiveBitFields: None
|
||||
AlignConsecutiveDeclarations: Consecutive
|
||||
AlignConsecutiveDeclarations:
|
||||
Enabled: true
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: true
|
||||
PadOperators: true
|
||||
AlignCompound: true
|
||||
AlignEscapedNewlines: Left
|
||||
AlignOperands: DontAlign
|
||||
AlignTrailingComments: true
|
||||
|
@ -195,6 +208,7 @@ StatementMacros:
|
|||
TabWidth: 4
|
||||
UseCRLF: false
|
||||
UseTab: Never
|
||||
SeparateDefinitionBlocks: Always
|
||||
WhitespaceSensitiveMacros:
|
||||
- STRINGIZE
|
||||
- PP_STRINGIZE
|
||||
|
|
|
@ -166,6 +166,7 @@ typedef struct {
|
|||
void *headers;
|
||||
hw_string *body;
|
||||
size_t body_length;
|
||||
|
||||
enum {
|
||||
OK,
|
||||
SIZE_EXCEEDED,
|
||||
|
@ -174,8 +175,9 @@ typedef struct {
|
|||
} state;
|
||||
} http_request;
|
||||
|
||||
typedef void(HAYWIRE_CALLING_CONVENTION *http_request_callback)(http_request *request, hw_http_response *response,
|
||||
void *user_data);
|
||||
typedef void(HAYWIRE_CALLING_CONVENTION *http_request_callback)(http_request *request,
|
||||
hw_http_response *response,
|
||||
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);
|
||||
|
@ -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 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_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_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_http_response_send(hw_http_response *response, void *user_data,
|
||||
http_response_complete_callback callback);
|
||||
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_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_body(hw_http_response *response, hw_string *body);
|
||||
HAYWIRE_EXTERN void hw_http_response_send(hw_http_response *response,
|
||||
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_print_request_headers(http_request *request);
|
||||
|
||||
|
|
|
@ -42,34 +42,34 @@ using namespace std;
|
|||
#include "task_manager.h"
|
||||
#include "user_errno.h"
|
||||
|
||||
void on_system_exit(void *p);
|
||||
void on_system_exit(void *p);
|
||||
//Global Variables
|
||||
timeval tv;
|
||||
fd_set readfds;
|
||||
timeval tv;
|
||||
fd_set readfds;
|
||||
//fd_set writefds;
|
||||
data9 dhcpr;
|
||||
data9 token;
|
||||
data1 network;
|
||||
data1 newNetwork;
|
||||
data2 cfig;
|
||||
data71 lump;
|
||||
bool kRunning = true;
|
||||
dhcpMap dhcpCache;
|
||||
char serviceName[] = "OpenDHCPServer";
|
||||
data9 dhcpr;
|
||||
data9 token;
|
||||
data1 network;
|
||||
data1 newNetwork;
|
||||
data2 cfig;
|
||||
data71 lump;
|
||||
bool kRunning = true;
|
||||
dhcpMap dhcpCache;
|
||||
char serviceName[] = "OpenDHCPServer";
|
||||
//char tempbuff[512] = "";
|
||||
//char logBuff[256];
|
||||
//char extbuff[256] = "";
|
||||
bool verbatim = false;
|
||||
char iniFile[256] = "";
|
||||
char leaFile[256] = "";
|
||||
bool verbatim = false;
|
||||
char iniFile[256] = "";
|
||||
char leaFile[256] = "";
|
||||
//char logFile[256] = "";
|
||||
char filePATH[256] = "";
|
||||
char htmlTitle[256] = "";
|
||||
char nicif[256] = "";
|
||||
char filePATH[256] = "";
|
||||
char htmlTitle[256] = "";
|
||||
char nicif[256] = "";
|
||||
//char arpa[] = ".in-addr.arpa";
|
||||
time_t t = time(nullptr);
|
||||
pthread_mutex_t mutStateFile = PTHREAD_MUTEX_INITIALIZER;
|
||||
pthread_mutex_t mutLogFile = PTHREAD_MUTEX_INITIALIZER;
|
||||
time_t t = time(nullptr);
|
||||
pthread_mutex_t mutStateFile = PTHREAD_MUTEX_INITIALIZER;
|
||||
pthread_mutex_t mutLogFile = PTHREAD_MUTEX_INITIALIZER;
|
||||
struct ifconf Ifc;
|
||||
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\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 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 td200[] = "<td>%s</td>";
|
||||
const char tdnowrap200[] = "<td nowrap>%s</td>";
|
||||
const char sVersion[] = "Open DHCP Server Version 1.80 Linux Build 1054";
|
||||
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 td200[] = "<td>%s</td>";
|
||||
const char tdnowrap200[] = "<td nowrap>%s</td>";
|
||||
const char sVersion[] = "Open DHCP Server Version 1.80 Linux Build 1054";
|
||||
const char htmlStart[] =
|
||||
"<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";
|
||||
|
@ -766,8 +766,8 @@ void prepareUserHtmlRespStatus(data19 *req) {
|
|||
data7 *dhcpEntry = nullptr;
|
||||
//data7 *cache = nullptr;
|
||||
//printf("%d=%d\n", dhcpCache.size(), cfig.dhcpSize);
|
||||
req->memSize = (int)(2048 + (135 * dhcpCache.size()) + (cfig.dhcpSize * 26));
|
||||
req->dp = (char *)calloc(1, req->memSize);
|
||||
req->memSize = (int)(2048 + (135 * dhcpCache.size()) + (cfig.dhcpSize * 26));
|
||||
req->dp = (char *)calloc(1, req->memSize);
|
||||
|
||||
if (!req->dp) {
|
||||
sprintf(logBuff, "Memory Error");
|
||||
|
@ -784,7 +784,7 @@ void prepareUserHtmlRespStatus(data19 *req) {
|
|||
//fp += sprintf(fp, send200, tempbuff, tempbuff);
|
||||
//fp += sprintf(fp, send200);
|
||||
//char *contentStart = fp;
|
||||
fp += sprintf(fp, htmlStart, htmlTitle);
|
||||
fp += sprintf(fp, htmlStart, htmlTitle);
|
||||
|
||||
if (cfig.replication == 1) {
|
||||
fp += sprintf(fp, bodyStart, sVersion, cfig.servername, "(Primary)");
|
||||
|
@ -826,7 +826,7 @@ void prepareUserHtmlRespStatus(data19 *req) {
|
|||
if (dhcpEntry->hostname[0]) {
|
||||
strcpy(tempbuff, dhcpEntry->hostname);
|
||||
tempbuff[20] = 0;
|
||||
fp += sprintf(fp, td200, tempbuff);
|
||||
fp += sprintf(fp, td200, tempbuff);
|
||||
} else {
|
||||
fp += sprintf(fp, td200, " ");
|
||||
}
|
||||
|
@ -890,12 +890,12 @@ void prepareUserHtmlRespStatus(data19 *req) {
|
|||
for (p = dhcpCache.begin(); kRunning && p != dhcpCache.end() && fp < maxData; p++) {
|
||||
if ((dhcpEntry = p->second) && dhcpEntry->fixed && dhcpEntry->expiry < t) {
|
||||
if (!colNum) {
|
||||
fp += sprintf(fp, "<tr>");
|
||||
fp += sprintf(fp, "<tr>");
|
||||
colNum = 1;
|
||||
} else if (colNum == 1) {
|
||||
colNum = 2;
|
||||
} else if (colNum == 2) {
|
||||
fp += sprintf(fp, "</tr>\n<tr>");
|
||||
fp += sprintf(fp, "</tr>\n<tr>");
|
||||
colNum = 1;
|
||||
}
|
||||
|
||||
|
@ -908,7 +908,7 @@ void prepareUserHtmlRespStatus(data19 *req) {
|
|||
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));
|
||||
//memcpy((contentStart - 12), tempbuff, x);
|
||||
req->bytes = (int)(fp - req->dp);
|
||||
|
@ -1145,7 +1145,7 @@ void *sendHTTP(void *lpParam) {
|
|||
break;
|
||||
}
|
||||
|
||||
dp += sent;
|
||||
dp += sent;
|
||||
req->bytes -= sent;
|
||||
} else {
|
||||
break;
|
||||
|
@ -2698,7 +2698,7 @@ void loadOptions(FILE *f, const char *sectionName, data20 *optionData) {
|
|||
*dp = valSize;
|
||||
dp++;
|
||||
memcpy(dp, value, valSize);
|
||||
dp += valSize;
|
||||
dp += valSize;
|
||||
buffsize -= (valSize + 2);
|
||||
} else {
|
||||
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++;
|
||||
memcpy(dp, value, valSize);
|
||||
dp += valSize;
|
||||
dp += valSize;
|
||||
buffsize -= (valSize + 2);
|
||||
} else {
|
||||
sprintf(logBuff,
|
||||
|
@ -2814,7 +2814,7 @@ void loadOptions(FILE *f, const char *sectionName, data20 *optionData) {
|
|||
dp++;
|
||||
*dp = 4;
|
||||
dp++;
|
||||
dp += pUInt(dp, j);
|
||||
dp += pUInt(dp, j);
|
||||
buffsize -= 6;
|
||||
//printf("%s=%u=%u\n",opData[op_index].opName,opData[op_index].opType,htonl(j));
|
||||
} else {
|
||||
|
@ -2846,7 +2846,7 @@ void loadOptions(FILE *f, const char *sectionName, data20 *optionData) {
|
|||
dp++;
|
||||
*dp = 2;
|
||||
dp++;
|
||||
dp += pUShort(dp, j);
|
||||
dp += pUShort(dp, j);
|
||||
buffsize -= 4;
|
||||
} else {
|
||||
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++;
|
||||
memcpy(dp, value, valSize);
|
||||
dp += valSize;
|
||||
dp += valSize;
|
||||
buffsize -= (valSize + 2);
|
||||
} else {
|
||||
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) {
|
||||
cfig.dhcpSize += (re - rs + 1);
|
||||
cfig.dhcpSize += (re - rs + 1);
|
||||
range = &cfig.dhcpRanges[m];
|
||||
range->rangeStart = rs;
|
||||
range->rangeEnd = re;
|
||||
|
@ -3465,7 +3465,7 @@ void loadDHCP() {
|
|||
dhcpData.expiry = dhcpEntry->expiry;
|
||||
dhcpData.local = dhcpEntry->local;
|
||||
strcpy(dhcpData.hostname, dhcpEntry->hostname);
|
||||
cfig.dhcpInd += 1;
|
||||
cfig.dhcpInd += 1;
|
||||
dhcpEntry->dhcpInd = cfig.dhcpInd;
|
||||
dhcpData.dhcpInd = dhcpEntry->dhcpInd;
|
||||
|
||||
|
@ -4233,7 +4233,7 @@ void *updateStateFile(void *lpParam) {
|
|||
strcpy(dhcpData.hostname, dhcpEntry->hostname);
|
||||
|
||||
if (!dhcpEntry->dhcpInd) {
|
||||
cfig.dhcpInd += 1;
|
||||
cfig.dhcpInd += 1;
|
||||
dhcpEntry->dhcpInd = cfig.dhcpInd;
|
||||
}
|
||||
|
||||
|
@ -4999,11 +4999,11 @@ void getInterfaces(data1 *pNetwork) {
|
|||
Ifc.ifc_buf = (char *)IfcBuf;
|
||||
|
||||
if (ioctl(cfig.fixedSocket, SIOCGIFCONF, &Ifc) >= 0) {
|
||||
|
||||
MYDWORD addr, mask;
|
||||
short flags;
|
||||
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++) {
|
||||
memcpy(&pIfr, &(IfcBuf[i]), sizeof(ifreq));
|
||||
|
|
|
@ -123,7 +123,7 @@ static int dhcp_get_user_info(data19 *req, const char *pRequest) {
|
|||
//char *maxData = req->dp + (req->memSize - 512);
|
||||
|
||||
//fp += sprintf(fp, send200, strlen(rspBuf));
|
||||
fp += sprintf(fp, "%s", pStrPro);
|
||||
fp += sprintf(fp, "%s", pStrPro);
|
||||
req->bytes = (int)(fp - req->dp);
|
||||
|
||||
cJSON_Delete(pRoot);
|
||||
|
@ -169,7 +169,7 @@ static int dhcp_get_all_user(data19 *req) {
|
|||
|
||||
const char *pStrPro = proto_create_new(pRspMsg, 200);
|
||||
|
||||
fp += sprintf(fp, "%s", pStrPro);
|
||||
fp += sprintf(fp, "%s", pStrPro);
|
||||
req->bytes = (int)(fp - req->dp);
|
||||
|
||||
free((void *)pStrPro);
|
||||
|
@ -199,7 +199,7 @@ static int dhcp_get_all_user(data19 *req) {
|
|||
*dp = valSize; \
|
||||
dp++; \
|
||||
memcpy(dp, (val), valSize); \
|
||||
dp += valSize; \
|
||||
dp += valSize; \
|
||||
buffSize -= (valSize + 2); \
|
||||
} \
|
||||
} \
|
||||
|
@ -393,9 +393,9 @@ static int add_dhcpd_rangeset(data19 *req, const char *pRequest) {
|
|||
return ERR_SUCCESS;
|
||||
}
|
||||
|
||||
struct hash_map{
|
||||
unsigned int key;
|
||||
unsigned int value;
|
||||
struct hash_map {
|
||||
unsigned int key;
|
||||
unsigned int value;
|
||||
UT_hash_handle hh;
|
||||
};
|
||||
|
||||
|
@ -406,7 +406,7 @@ static int delete_dhcpd_rangeset(data19 *req, const char *pRequest) {
|
|||
cJSON *pRspRoot;
|
||||
cJSON *pdelArray;
|
||||
data13 dhcpRanges[MAX_DHCP_RANGES];
|
||||
hash_map *delMap = nullptr;
|
||||
hash_map *delMap = nullptr;
|
||||
int resCount = 0;
|
||||
|
||||
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);
|
||||
|
||||
for (int i = 0; i < cJSON_GetArraySize(pdhcp_range); i++) {
|
||||
cJSON *pdelRange = cJSON_GetArrayItem(pdhcp_range, i);
|
||||
char del_range[256];
|
||||
auto *delItem = (struct hash_map*)malloc(sizeof(hash_map));
|
||||
cJSON *pdelRange = cJSON_GetArrayItem(pdhcp_range, i);
|
||||
char del_range[256];
|
||||
auto *delItem = (struct hash_map *)malloc(sizeof(hash_map));
|
||||
|
||||
if (!pdelRange) {
|
||||
continue;
|
||||
|
@ -467,15 +467,15 @@ static int delete_dhcpd_rangeset(data19 *req, const char *pRequest) {
|
|||
en_addr = htonl(inet_addr(end));
|
||||
|
||||
HASH_FIND_INT(delMap, &st_addr, delItem);
|
||||
if (delItem == nullptr){
|
||||
hash_map *s = (struct hash_map*)malloc(sizeof(struct hash_map));
|
||||
s->key = st_addr;
|
||||
s->value = en_addr;
|
||||
if (delItem == nullptr) {
|
||||
hash_map *s = (struct hash_map *)malloc(sizeof(struct hash_map));
|
||||
s->key = st_addr;
|
||||
s->value = en_addr;
|
||||
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();
|
||||
hash_map *delRange;
|
||||
char del_range[256];
|
||||
|
@ -484,7 +484,7 @@ static int delete_dhcpd_rangeset(data19 *req, const char *pRequest) {
|
|||
memset(del_range, 0, 256);
|
||||
|
||||
HASH_FIND_INT(delMap, &cfig.dhcpRanges[i].rangeStart, delRange);
|
||||
if(delRange != nullptr){
|
||||
if (delRange != nullptr) {
|
||||
IP2String(saddr, ntohl(delRange->key));
|
||||
IP2String(eaddr, ntohl(delRange->value));
|
||||
|
||||
|
@ -541,8 +541,8 @@ static int delete_dhcpd_rangeset(data19 *req, const char *pRequest) {
|
|||
}
|
||||
|
||||
//rewite cfig.dhcpRanges
|
||||
for(int i = 0; i < cfig.rangeCount; i++){
|
||||
if(i < resCount){
|
||||
for (int i = 0; i < cfig.rangeCount; i++) {
|
||||
if (i < resCount) {
|
||||
memcpy(&cfig.dhcpRanges[i], &dhcpRanges[i], sizeof(struct data13));
|
||||
} else {
|
||||
memset(&cfig.dhcpRanges[i], 0, sizeof(struct data13));
|
||||
|
@ -552,7 +552,7 @@ static int delete_dhcpd_rangeset(data19 *req, const char *pRequest) {
|
|||
cfig.rangeCount = resCount;
|
||||
|
||||
const char *pStrPro = proto_create_new(pRspRoot, 200);
|
||||
fp += sprintf(fp, "%s", pStrPro);
|
||||
fp += sprintf(fp, "%s", pStrPro);
|
||||
|
||||
cJSON_Delete(pRoot);
|
||||
req->bytes = (int)(fp - req->dp);
|
||||
|
@ -561,15 +561,14 @@ static int delete_dhcpd_rangeset(data19 *req, const char *pRequest) {
|
|||
return ERR_SUCCESS;
|
||||
}
|
||||
|
||||
static void revert(unsigned int* num) {
|
||||
unsigned int v = *num ;
|
||||
v = ((v & 0x000000FF) << 24) | ((v & 0x0000FF00) << 8) |
|
||||
((v & 0x00FF0000) >> 8) | ((v & 0xFF000000) >> 24) ;
|
||||
*num = v ;
|
||||
static void revert(unsigned int *num) {
|
||||
unsigned int v = *num;
|
||||
v = ((v & 0x000000FF) << 24) | ((v & 0x0000FF00) << 8) | ((v & 0x00FF0000) >> 8) | ((v & 0xFF000000) >> 24);
|
||||
*num = v;
|
||||
}
|
||||
|
||||
static int query_dhcpd_rangeset(data19 *req){
|
||||
char logBuff[512];
|
||||
static int query_dhcpd_rangeset(data19 *req) {
|
||||
char logBuff[512];
|
||||
req->memSize = (int)(2048 + (135 * dhcpCache.size()) + (cfig.dhcpSize * 26));
|
||||
req->dp = (char *)calloc(1, req->memSize);
|
||||
|
||||
|
@ -586,7 +585,7 @@ static int query_dhcpd_rangeset(data19 *req){
|
|||
cJSON *pMsgArray = cJSON_CreateArray();
|
||||
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 addrEnd[64];
|
||||
char rangeSet[128];
|
||||
|
@ -596,7 +595,7 @@ static int query_dhcpd_rangeset(data19 *req){
|
|||
cJSON *pRangeItem = cJSON_CreateObject();
|
||||
unsigned int lease;
|
||||
|
||||
memset(domainServer, 0 , 128);
|
||||
memset(domainServer, 0, 128);
|
||||
IP2String(addrStart, ntohl(cfig.dhcpRanges[rangeInd].rangeStart));
|
||||
IP2String(addrEnd, ntohl(cfig.dhcpRanges[rangeInd].rangeEnd));
|
||||
IP2String(rangeMask, cfig.dhcpRanges[rangeInd].mask);
|
||||
|
@ -610,10 +609,10 @@ static int query_dhcpd_rangeset(data19 *req){
|
|||
if (opPointer) {
|
||||
opPointer++;
|
||||
while (*opPointer && *opPointer != DHCP_OPTION_END) {
|
||||
unsigned int tmpVal = 0;
|
||||
unsigned char dnsSize;
|
||||
unsigned char offset = 0;
|
||||
char dns_op[64];
|
||||
unsigned int tmpVal = 0;
|
||||
unsigned char dnsSize;
|
||||
unsigned char offset = 0;
|
||||
char dns_op[64];
|
||||
|
||||
op.opt_code = *opPointer;
|
||||
opPointer++;
|
||||
|
@ -621,28 +620,28 @@ static int query_dhcpd_rangeset(data19 *req){
|
|||
opPointer++;
|
||||
|
||||
memcpy(op.value, opPointer, op.size);
|
||||
if(op.opt_code == DHCP_OPTION_DNS){
|
||||
if (op.opt_code == DHCP_OPTION_DNS) {
|
||||
dnsSize = op.size;
|
||||
do {
|
||||
tmpVal = fIP(op.value + offset);
|
||||
revert(&tmpVal);
|
||||
IP2String(dns_op, ntohl(tmpVal));
|
||||
sprintf(domainServer, "%s%s", domainServer, dns_op);
|
||||
if(dnsSize != 4){
|
||||
if (dnsSize != 4) {
|
||||
sprintf(domainServer, "%s,", domainServer);
|
||||
}
|
||||
dnsSize -= 4;
|
||||
offset = op.size - dnsSize;
|
||||
}while (dnsSize != 0);
|
||||
offset = op.size - dnsSize;
|
||||
} while (dnsSize != 0);
|
||||
|
||||
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);
|
||||
revert(&tmpVal);
|
||||
IP2String(gateway, ntohl(tmpVal));
|
||||
|
||||
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);
|
||||
|
||||
cJSON_AddNumberToObject(pRangeItem, "lease", lease);
|
||||
|
@ -658,7 +657,7 @@ static int query_dhcpd_rangeset(data19 *req){
|
|||
|
||||
const char *pStrPro = proto_create_new(pRspMsg, 200);
|
||||
|
||||
fp += sprintf(fp, "%s", pStrPro);
|
||||
fp += sprintf(fp, "%s", pStrPro);
|
||||
req->bytes = (int)(fp - req->dp);
|
||||
|
||||
free((void *)pStrPro);
|
||||
|
@ -667,7 +666,8 @@ static int query_dhcpd_rangeset(data19 *req){
|
|||
|
||||
#pragma clang diagnostic push
|
||||
#pragma ide diagnostic ignored "cert-err34-c"
|
||||
int getHwAddr(char *buff, char *mac) {
|
||||
|
||||
int getHwAddr(char *buff, char *mac) {
|
||||
if (buff == nullptr || mac == nullptr) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -685,6 +685,7 @@ int getHwAddr(char *buff, char *mac) {
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
int arpSet(const char *ifname, char *ipStr, char *mac) {
|
||||
|
@ -860,8 +861,7 @@ static void opendhcp_http_get_alluser(http_request *request, hw_http_response *r
|
|||
hw_string keep_alive_name;
|
||||
hw_string keep_alive_value;
|
||||
int ret;
|
||||
|
||||
auto *req = (data19 *)malloc(sizeof(struct data19));
|
||||
auto *req = (data19 *)malloc(sizeof(struct data19));
|
||||
|
||||
if (req == nullptr) {
|
||||
proto_response_error(response, 500, HTTP_STATUS_500, ERR_MALLOC_MEMORY);
|
||||
|
@ -908,16 +908,15 @@ static void opendhcp_http_add_rangeset(http_request *request, hw_http_response *
|
|||
hw_string keep_alive_name;
|
||||
hw_string keep_alive_value;
|
||||
int ret;
|
||||
|
||||
auto *req = (data19 *)malloc(sizeof(struct data19));
|
||||
auto *req = (data19 *)malloc(sizeof(struct data19));
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -956,16 +955,15 @@ static void opendhcp_http_delete_rangeset(http_request *request, hw_http_respons
|
|||
hw_string keep_alive_name;
|
||||
hw_string keep_alive_value;
|
||||
int ret;
|
||||
|
||||
auto *req = (data19 *)malloc(sizeof(struct data19));
|
||||
auto *req = (data19 *)malloc(sizeof(struct data19));
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -1004,16 +1002,15 @@ static void opendhcp_http_query_rangeset(http_request *request, hw_http_response
|
|||
hw_string keep_alive_name;
|
||||
hw_string keep_alive_value;
|
||||
int ret;
|
||||
|
||||
auto *req = (data19 *)malloc(sizeof(struct data19));
|
||||
auto *req = (data19 *)malloc(sizeof(struct data19));
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -1043,6 +1040,7 @@ static void opendhcp_http_query_rangeset(http_request *request, hw_http_response
|
|||
|
||||
hw_http_response_send(response, req, response_complete);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加配置文件监听接口
|
||||
* @return
|
||||
|
|
Loading…
Reference in New Issue