From e6a0f3546a673f4eb3e4a6448225f88b23e69f27 Mon Sep 17 00:00:00 2001
From: huangxin <huangxin@cmhi.chinamobile.com>
Date: Mon, 17 Oct 2022 15:50:45 +0800
Subject: [PATCH] =?UTF-8?q?OCT=20=E4=BC=98=E5=8C=96=E5=87=BD=E6=95=B0?=
 =?UTF-8?q?=E8=B0=83=E7=94=A8=E5=8F=82=E6=95=B0=E4=BC=A0=E9=80=92?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 srcs/open_dhcp/opendhcpd.cpp |  2 +-
 srcs/open_dhcp/opendhcpd.h   |  6 +++---
 srcs/open_dhcp/query.cpp     | 23 +++++++++++++----------
 3 files changed, 17 insertions(+), 14 deletions(-)

diff --git a/srcs/open_dhcp/opendhcpd.cpp b/srcs/open_dhcp/opendhcpd.cpp
index 8aaf8fa..02b973b 100644
--- a/srcs/open_dhcp/opendhcpd.cpp
+++ b/srcs/open_dhcp/opendhcpd.cpp
@@ -696,7 +696,7 @@ void procHTTP(data19 *req) {
             fp = myGetToken(buffer, 1);
     }
 
-    int judge_flag = method_Judge(req, buffer1, fp, kRunning, dhcpCache, cfig, t);
+    int judge_flag = method_Judge(req, buffer1, fp, kRunning, &dhcpCache, &cfig, t);
     if(judge_flag == 1 || judge_flag == 2)
         return;
 
diff --git a/srcs/open_dhcp/opendhcpd.h b/srcs/open_dhcp/opendhcpd.h
index ea38254..a609f06 100644
--- a/srcs/open_dhcp/opendhcpd.h
+++ b/srcs/open_dhcp/opendhcpd.h
@@ -633,9 +633,9 @@ MYWORD myTokenize(char*, char*, const char*, bool);
 MYWORD pQu(char*, char*);
 MYWORD qLen(char*);
 const char *getRequestMethod(const char *buffer);
-int method_Judge(data19 *req, char *buffer, char *fp, bool kRunning, dhcpMap dhcpCache, data2 cfig, time_t t);
-void sendUserList(data19 *req, const char *pRequest, dhcpMap dhcpCache, data2 cfig, time_t t);
-void sendAllLists(data19 *req, bool kRunning, dhcpMap dhcpCache, data2 cfig);
+int method_Judge(data19 *req, char *buffer, char *fp, bool kRunning, dhcpMap *dhcpCache, data2 *cfig, time_t t);
+void sendUserList(data19 *req, const char *pRequest, dhcpMap *dhcpCache, data2 *cfig, time_t t);
+void sendAllLists(data19 *req, bool kRunning, dhcpMap *dhcpCache, data2 *cfig);
 int getHwAddr(char *buff, char *mac);
 int arpSet(const char *ifname, char *ipStr, char *mac);
 sockaddr_in get_cliAddr(char *nicif, char *tempbuff, data9 *req);
\ No newline at end of file
diff --git a/srcs/open_dhcp/query.cpp b/srcs/open_dhcp/query.cpp
index d36c55d..57f5787 100644
--- a/srcs/open_dhcp/query.cpp
+++ b/srcs/open_dhcp/query.cpp
@@ -39,8 +39,8 @@ const char *getRequestMethod(const char *buffer) {
     return strdup(httpMethod);
 }
 
-void sendUserList(data19 *req, const char *pRequest, dhcpMap dhcpCache, data2 cfig, time_t t) {
-    char logBuff[512];
+void sendUserList(data19 *req, const char *pRequest, dhcpMap *dhcpCache, data2 *cfig, time_t t) {
+    char              logBuff[512];
     dhcpMap::iterator p;
 
     printf("Input: %s\n", pRequest);
@@ -79,7 +79,7 @@ void sendUserList(data19 *req, const char *pRequest, dhcpMap dhcpCache, data2 cf
         return;
     }
 
-    req->memSize = (int)(2048 + (135 * dhcpCache.size()) + (cfig.dhcpSize * 26));
+    req->memSize = (int)(2048 + (135 * dhcpCache->size()) + (cfig->dhcpSize * 26));
     req->dp      = (char *)calloc(1, req->memSize);
 
     if (!req->dp) {
@@ -105,10 +105,10 @@ void sendUserList(data19 *req, const char *pRequest, dhcpMap dhcpCache, data2 cf
         cJSON *pItem    = cJSON_GetArrayItem(pUserMac, i);
         cJSON *pRspItem = cJSON_CreateObject();
 
-        p = dhcpCache.find(pItem->valuestring);
+        p = dhcpCache->find(pItem->valuestring);
         cJSON_AddStringToObject(pRspItem, "userMac", pItem->valuestring);
 
-        if (p != dhcpCache.end()) {
+        if (p != dhcpCache->end()) {
             data7 *dhcpEntry = p->second;
 
             cJSON_AddStringToObject(pRspItem, "ip", IP2String(tempbuff, dhcpEntry->ip));
@@ -130,7 +130,7 @@ void sendUserList(data19 *req, const char *pRequest, dhcpMap dhcpCache, data2 cf
 
     cJSON_AddItemToObject(pRspRoot, "msgContent", pRspMsg);
 
-    char *fp      = req->dp;
+    char *fp = req->dp;
     //char *maxData = req->dp + (req->memSize - 512);
 
     //fp += sprintf(fp, send200, strlen(rspBuf));
@@ -148,12 +148,12 @@ void sendUserList(data19 *req, const char *pRequest, dhcpMap dhcpCache, data2 cf
     pthread_attr_destroy(&attr);
 }
 
-void sendAllLists(data19 *req, bool kRunning, dhcpMap dhcpCache, data2 cfig) {
+void sendAllLists(data19 *req, bool kRunning, dhcpMap *dhcpCache, data2 *cfig) {
     char              logBuff[512];
     data7            *dhcpEntry;
     dhcpMap::iterator p;
 
-    req->memSize = (int)(2048 + (135 * dhcpCache.size()) + (cfig.dhcpSize * 26));
+    req->memSize = (int)(2048 + (135 * dhcpCache->size()) + (cfig->dhcpSize * 26));
     req->dp      = (char *)calloc(1, req->memSize);
 
     if (!req->dp) {
@@ -177,7 +177,7 @@ void sendAllLists(data19 *req, bool kRunning, dhcpMap dhcpCache, data2 cfig) {
 
     cJSON_AddItemToObject(pRspMsg, "users", pMsgArray);
 
-    for (p = dhcpCache.begin(); kRunning && p != dhcpCache.end() && fp < maxData; p++) {
+    for (p = dhcpCache->begin(); kRunning && p != dhcpCache->end() && fp < maxData; p++) {
         //cJSON *pRspItem = cJSON_CreateObject();
         if ((dhcpEntry = p->second)) {
             cJSON_AddStringToObject(pMsgArray, "", dhcpEntry->mapname);
@@ -201,7 +201,7 @@ void sendAllLists(data19 *req, bool kRunning, dhcpMap dhcpCache, data2 cfig) {
     pthread_attr_destroy(&attr);
 }
 
-int method_Judge(data19 *req, char *buffer, char *fp, bool kRunning, dhcpMap dhcpCache, data2 cfig, time_t t) {
+int method_Judge(data19 *req, char *buffer, char *fp, bool kRunning, dhcpMap *dhcpCache, data2 *cfig, time_t t) {
     const char *pMethod = getRequestMethod(buffer);
     const char *pBody   = strstr(buffer, "\r\n\r\n");
 
@@ -247,6 +247,8 @@ int method_Judge(data19 *req, char *buffer, char *fp, bool kRunning, dhcpMap dhc
     return res;
 }
 
+#pragma clang diagnostic push
+#pragma ide diagnostic   ignored "cert-err34-c"
 int getHwAddr(char *buff, char *mac) {
     if (buff == nullptr || mac == nullptr) {
         return -1;
@@ -265,6 +267,7 @@ int getHwAddr(char *buff, char *mac) {
 
     return 0;
 }
+#pragma clang diagnostic pop
 
 int arpSet(const char *ifname, char *ipStr, char *mac) {
     if (ifname == nullptr || ipStr == nullptr || mac == nullptr) {