From 3ef2b0672ccc22e35198aaedeb69c1d8b7a0f820 Mon Sep 17 00:00:00 2001 From: dongwenze Date: Fri, 9 Dec 2022 18:04:18 +0800 Subject: [PATCH] =?UTF-8?q?OCT=20=E4=BF=AE=E6=94=B9=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- srcs/open_dhcp/query.cpp | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/srcs/open_dhcp/query.cpp b/srcs/open_dhcp/query.cpp index 95e9b58..c79b145 100644 --- a/srcs/open_dhcp/query.cpp +++ b/srcs/open_dhcp/query.cpp @@ -448,6 +448,7 @@ 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 *pdel_Item = cJSON_CreateObject(); cJSON *pdelRange = cJSON_GetArrayItem(pdhcp_range, i); char del_range[256]; auto *delItem = (struct hash_map *)malloc(sizeof(hash_map)); @@ -465,6 +466,13 @@ static int delete_dhcpd_rangeset(data19 *req, const char *pRequest) { mySplit(start, end, del_range, '-'); st_addr = htonl(inet_addr(start)); en_addr = htonl(inet_addr(end)); + if(en_addr == 0) { + cJSON_AddStringToObject(pdel_Item, "dhcpRange", del_range); + + cJSON_AddNumberToObject(pdel_Item, "status", ERR_INPUT_PARAMS); + cJSON_AddStringToObject(pdel_Item, "message", getErrorEnumDesc(ERR_INPUT_PARAMS)); + cJSON_AddItemToArray(pdelArray, pdel_Item); + } HASH_FIND_INT(delMap, &st_addr, delItem); if (delItem == nullptr) { @@ -491,7 +499,7 @@ static int delete_dhcpd_rangeset(data19 *req, const char *pRequest) { sprintf(del_range, "%s-%s", saddr, eaddr); cJSON_AddStringToObject(pdel_Item, "dhcpRange", del_range); //judge whether the input has error - if(delRange->key && delRange->value && (delRange->value == cfig.dhcpRanges[i].rangeEnd)){ + if(delRange->value == cfig.dhcpRanges[i].rangeEnd) { cJSON_AddNumberToObject(pdel_Item, "status", ERR_SUCCESS); cJSON_AddStringToObject(pdel_Item, "message", getErrorEnumDesc(ERR_SUCCESS)); cJSON_AddItemToArray(pdelArray, pdel_Item); @@ -504,10 +512,7 @@ static int delete_dhcpd_rangeset(data19 *req, const char *pRequest) { cJSON_AddItemToArray(pdelArray, pdel_Item); } - hash_map *s = (struct hash_map*)malloc(sizeof(struct hash_map)); - s->key = delRange->key; - s->value = 0; - HASH_REPLACE_INT(delMap, key, s, delRange); + HASH_DEL(delMap, delRange); } else { //write to dhcpRanges memcpy(&dhcpRanges[resCount], &cfig.dhcpRanges[i], sizeof(struct data13)); @@ -526,17 +531,15 @@ static int delete_dhcpd_rangeset(data19 *req, const char *pRequest) { memset(del_range, 0, 256); HASH_ITER(hh, delMap, s, tmp){ - if(s->value != 0){ - IP2String(saddr, ntohl(s->key)); - IP2String(eaddr, ntohl(s->value)); + IP2String(saddr, ntohl(s->key)); + IP2String(eaddr, ntohl(s->value)); - sprintf(del_range, "%s-%s", saddr, eaddr); - cJSON_AddStringToObject(pdel_Item, "dhcpRange", del_range); + sprintf(del_range, "%s-%s", saddr, eaddr); + cJSON_AddStringToObject(pdel_Item, "dhcpRange", del_range); - cJSON_AddNumberToObject(pdel_Item, "status", ERR_ITEM_UNEXISTS); - cJSON_AddStringToObject(pdel_Item, "message", getErrorEnumDesc(ERR_ITEM_UNEXISTS)); - cJSON_AddItemToArray(pdelArray, pdel_Item); - } + cJSON_AddNumberToObject(pdel_Item, "status", ERR_ITEM_UNEXISTS); + cJSON_AddStringToObject(pdel_Item, "message", getErrorEnumDesc(ERR_ITEM_UNEXISTS)); + cJSON_AddItemToArray(pdelArray, pdel_Item); } }