From f49a72661ffdc591acf4a8f73e583fd3f1e5a8a5 Mon Sep 17 00:00:00 2001 From: huangxin Date: Sun, 9 Oct 2022 11:41:05 +0800 Subject: [PATCH] =?UTF-8?q?OCT=20ZNJK-1003=201.=20=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E6=97=A0=E7=94=A8=E4=BB=A3=E7=A0=81=202.=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E8=BF=94=E5=9B=9EJSON=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- srcs/open_dhcp/opendhcpd.cpp | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/srcs/open_dhcp/opendhcpd.cpp b/srcs/open_dhcp/opendhcpd.cpp index c4e3e46..e170c86 100644 --- a/srcs/open_dhcp/opendhcpd.cpp +++ b/srcs/open_dhcp/opendhcpd.cpp @@ -743,10 +743,10 @@ void procHTTP(data19 *req) { return; } -// if (strcmp(pMethod, "POST") == 0) { -// sendAllLists(req); -// return; -// } + // if (strcmp(pMethod, "POST") == 0) { + // sendAllLists(req); + // return; + // } if (pMethod) { free((void *)pMethod); @@ -756,7 +756,6 @@ void procHTTP(data19 *req) { free((void *)pBody); } - if (fp && !strcasecmp(fp, "/allusers")) sendAllLists(req); else if (fp && !strcasecmp(fp, "/")) @@ -789,10 +788,6 @@ typedef struct { } USER_INFO, *PUSER_INFO; static void sendUserList(data19 *req, const char *pRequest) { - char rsp[] = - "{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1599187216753,\"code\":200,\"msgContent\":{\"items\":[],\"status\":" - "0,\"message\":[\"Success\"]}}"; - char logBuff[512]; char rspBuf[2048] = {0}; dhcpMap::iterator p; @@ -902,11 +897,7 @@ static void sendUserList(data19 *req, const char *pRequest) { pthread_attr_destroy(&attr); } -static void sendAllLists(data19* req){ - char rsp[] = - "{\"ver\":3,\"cryptoType\":0,\"timeStamp\":1599187216753,\"code\":200,\"msgContent\":{\"items\":[],\"status\":" - "0,\"message\":[\"Success\"]}}"; - +static void sendAllLists(data19 *req) { char logBuff[512]; data7 *dhcpEntry = nullptr; dhcpMap::iterator p; @@ -933,18 +924,18 @@ static void sendAllLists(data19* req){ cJSON *pRspMsg = cJSON_CreateObject(); cJSON *pMsgArray = cJSON_CreateArray(); -// cJSON_AddItemToObject(pRspMsg, "", pMsgArray); + cJSON_AddItemToObject(pRspMsg, "users", pMsgArray); for (p = dhcpCache.begin(); kRunning && p != dhcpCache.end() && fp < maxData; p++) { -// cJSON *pRspItem = cJSON_CreateObject(); + //cJSON *pRspItem = cJSON_CreateObject(); if ((dhcpEntry = p->second)) { - cJSON_AddStringToObject(pMsgArray, " ", dhcpEntry->mapname); + cJSON_AddStringToObject(pMsgArray, "", dhcpEntry->mapname); } -// cJSON_AddItemToArray(pMsgArray, pRspItem); + //cJSON_AddItemToArray(pMsgArray, pRspItem); } - cJSON_AddItemToObject(pRspRoot, "msgContent", pMsgArray); + cJSON_AddItemToObject(pRspRoot, "msgContent", pRspMsg); fp += sprintf(fp, "%s", cJSON_Print(pRspRoot)); @@ -1766,8 +1757,8 @@ MYDWORD chkaddr(data9 *req) { #include #pragma clang diagnostic push -#pragma ide diagnostic ignored "cert-err34-c" -int getHwAddr(char *buff, char *mac) { +#pragma ide diagnostic ignored "cert-err34-c" +int getHwAddr(char *buff, char *mac) { if (buff == nullptr || mac == nullptr) { return -1; }