Merge branch 'master' of git.komect.net:ZNJK/vcpe

This commit is contained in:
huangxin 2022-12-12 10:27:25 +08:00
commit 1ea125ab6f
1 changed files with 37 additions and 5 deletions

View File

@ -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,8 +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->key == cfig.dhcpRanges[i].rangeStart) &&
(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,6 +511,8 @@ static int delete_dhcpd_rangeset(data19 *req, const char *pRequest) {
cJSON_AddStringToObject(pdel_Item, "message", getErrorEnumDesc(ERR_INPUT_PARAMS));
cJSON_AddItemToArray(pdelArray, pdel_Item);
}
HASH_DEL(delMap, delRange);
} else {
//write to dhcpRanges
memcpy(&dhcpRanges[resCount], &cfig.dhcpRanges[i], sizeof(struct data13));
@ -511,6 +520,29 @@ static int delete_dhcpd_rangeset(data19 *req, const char *pRequest) {
}
}
//输入参数不存在的情况
if(resCount > cfig.rangeCount - cJSON_GetArraySize(pdhcp_range)){
cJSON *pdel_Item = cJSON_CreateObject();
hash_map *s = (struct hash_map*)malloc(sizeof(struct hash_map));
hash_map *tmp;
char saddr[128];
char eaddr[128];
char del_range[256];
memset(del_range, 0, 256);
HASH_ITER(hh, delMap, s, tmp){
IP2String(saddr, ntohl(s->key));
IP2String(eaddr, ntohl(s->value));
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);
}
}
//rewite cfig.dhcpRanges
for (int i = 0; i < cfig.rangeCount; i++) {
if (i < resCount) {