OCT 优化函数调用参数传递

This commit is contained in:
huangxin 2022-10-17 15:50:45 +08:00
parent 2e2ff5a6fc
commit e6a0f3546a
3 changed files with 17 additions and 14 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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) {