OCT 1.简化删除接口部分变量

This commit is contained in:
dongwenze 2023-03-07 18:45:37 +08:00
parent 32fec2621b
commit 701d9ac1f0
1 changed files with 13 additions and 20 deletions

View File

@ -467,10 +467,12 @@ static int delete_dhcpd_rangeset(const char **pRsp, const char *pRequest) {
pdelArray = cJSON_CreateArray();
cJSON_AddItemToObject(pRspRoot, "rangeSet", pdelArray);
char start[128];
char end[128];
char del_range[256];
for (int i = 0; i < cJSON_GetArraySize(pdhcp_range); i++) {
cJSON *pdel_Item = cJSON_CreateObject();
cJSON *pdelRange = cJSON_GetArrayItem(pdhcp_range, i);
char del_range[256];
if (!pdelRange) {
continue;
@ -480,8 +482,6 @@ static int delete_dhcpd_rangeset(const char **pRsp, const char *pRequest) {
MYDWORD st_addr;
MYDWORD en_addr;
char start[128];
char end[128];
mySplit(start, end, del_range, '-');
st_addr = htonl(inet_addr(start));
en_addr = htonl(inet_addr(end));
@ -509,17 +509,14 @@ static int delete_dhcpd_rangeset(const char **pRsp, const char *pRequest) {
for (int i = 0; i < cfig.rangeCount; i++) {
cJSON *pdel_Item = cJSON_CreateObject();
PHASH_MAP delRange;
char del_range[256];
char saddr[128];
char eaddr[128];
memset(del_range, 0, 256);
HASH_FIND_INT(delMap, &cfig.dhcpRanges[i].rangeStart, delRange);
if (delRange != nullptr) {
IP2String(saddr, ntohl(delRange->key));
IP2String(eaddr, ntohl(delRange->value));
IP2String(start, ntohl(delRange->key));
IP2String(end, ntohl(delRange->value));
sprintf(del_range, "%s-%s", saddr, eaddr);
sprintf(del_range, "%s-%s", start, end);
cJSON_AddStringToObject(pdel_Item, "dhcpRange", del_range);
//Determine whether the input is correct or not
if (delRange->value == cfig.dhcpRanges[i].rangeEnd) {
@ -527,6 +524,10 @@ static int delete_dhcpd_rangeset(const char **pRsp, const char *pRequest) {
cJSON_AddStringToObject(pdel_Item, "message", getErrorEnumDesc(ERR_SUCCESS));
cJSON_AddItemToArray(pdelArray, pdel_Item);
free(cfig.dhcpRanges[i].options);
free(cfig.dhcpRanges[i].expiry);
free(cfig.dhcpRanges[i].dhcpEntry);
free(*(cfig.dhcpRanges[i].dhcpEntry));
} else {
memcpy(&dhcpRanges[resCount], &cfig.dhcpRanges[i], sizeof(struct data13));
resCount++;
@ -537,11 +538,6 @@ static int delete_dhcpd_rangeset(const char **pRsp, const char *pRequest) {
HASH_DEL(delMap, delRange);
free(delRange);
free(cfig.dhcpRanges[i].options);
free(cfig.dhcpRanges[i].expiry);
free(cfig.dhcpRanges[i].dhcpEntry);
free(*(cfig.dhcpRanges[i].dhcpEntry));
} else {
memcpy(&dhcpRanges[resCount], &cfig.dhcpRanges[i], sizeof(struct data13));
resCount++;
@ -552,16 +548,13 @@ static int delete_dhcpd_rangeset(const char **pRsp, const char *pRequest) {
//The input parameter does not exist
PHASH_MAP s;
PHASH_MAP tmp;
char saddr[128];
char eaddr[128];
char del_range[256];
memset(del_range, 0, 256);
HASH_ITER(hh, delMap, s, tmp) HASH_ITER(hh, delMap, s, tmp) {
cJSON *pdel_Item = cJSON_CreateObject();
IP2String(saddr, ntohl(s->key));
IP2String(eaddr, ntohl(s->value));
IP2String(start, ntohl(s->key));
IP2String(end, ntohl(s->value));
sprintf(del_range, "%s-%s", saddr, eaddr);
sprintf(del_range, "%s-%s", start, end);
cJSON_AddStringToObject(pdel_Item, "dhcpRange", del_range);
cJSON_AddNumberToObject(pdel_Item, "status", ERR_ITEM_UNEXISTS);