From 52ce9893a71311c46d4e9ba14ef2a98b3b715e36 Mon Sep 17 00:00:00 2001
From: fujuntang <fujuntang@smartai.com>
Date: 星期日, 26 九月 2021 21:57:24 +0800
Subject: [PATCH] trival version: need confirm whether protobuf can run weil yet.

---
 src/bh_api.cpp |   36 ++++++++++++++++++++----------------
 1 files changed, 20 insertions(+), 16 deletions(-)

diff --git a/src/bh_api.cpp b/src/bh_api.cpp
index 635fe95..f4215d3 100644
--- a/src/bh_api.cpp
+++ b/src/bh_api.cpp
@@ -7,9 +7,7 @@
 #include "bh_api.h"
 #include <pthread.h>
 #include <getopt.h>
-#include "bhome_msg_api.pb.h"
-#include "bhome_msg.pb.h"
-#include "error_msg.pb.h"
+#include "../proto/source/error_msg.pb.h"
 #include "../proto/source/bhome_msg.pb.h"
 #include "../proto/source/bhome_msg_api.pb.h"
 
@@ -123,49 +121,49 @@
 #if defined(PRO_DE_SERIALIZE)
     if (_input.proc_id != NULL) {
       count = strlen(_input.proc_id) + 1;
-      min = count > MAX_STR_LEN ? MAX_STR_LEN : count;
+      min = count > (MAX_STR_LEN - 1) ? (MAX_STR_LEN - 1) : count;
       strncpy(pData.proc_id, _input.proc_id, min);
     }
 
     if (_input.name != NULL) {
       count = strlen(_input.name) + 1;
-      min = count > MAX_STR_LEN ? MAX_STR_LEN : count;
+      min = count > (MAX_STR_LEN - 1)? (MAX_STR_LEN -1) : count;
       strncpy(pData.name, _input.name, min); 
     }
 
     if (_input.public_info != NULL) {
       count = strlen(_input.public_info) + 1;
-      min = count > MAX_STR_LEN ? MAX_STR_LEN : count;
+      min = count > (MAX_STR_LEN - 1)? (MAX_STR_LEN - 1) : count;
       strncpy(pData.public_info, _input.public_info, min);
     }
  
     if (_input.private_info != NULL) {
       count = strlen(_input.private_info) + 1;
-      min = count > MAX_STR_LEN ? MAX_STR_LEN : count;
+      min = count > (MAX_STR_LEN - 1)? (MAX_STR_LEN - 1): count;
       strncpy(pData.private_info, _input.private_info, min);
     }
 #else 
     if (strlen((const char *)(((ProcInfo *)proc_info)->proc_id)) > 0) {
       count = strlen((const char *)(((ProcInfo *)proc_info)->proc_id)) + 1;
-      min = count > MAX_STR_LEN ? MAX_STR_LEN : count;
+      min = count > (MAX_STR_LEN - 1) ? (MAX_STR_LEN - 1): count;
       strncpy(pData.proc_id, ((ProcInfo *)proc_info)->proc_id, min);
     }
 
     if (strlen((const char *)(((ProcInfo *)proc_info)->name)) > 0) {
       count = strlen((const char *)(((ProcInfo *)proc_info)->name)) + 1;
-      min = count > MAX_STR_LEN ? MAX_STR_LEN : count;
+      min = count > (MAX_STR_LEN - 1) ? (MAX_STR_LEN - 1) : count;
       strncpy(pData.name, ((ProcInfo *)proc_info)->name, min); 
     }
 
     if (strlen((const char *)(((ProcInfo *)proc_info)->public_info)) > 0) {
       count = strlen((const char *)(((ProcInfo *)proc_info)->public_info)) + 1;
-      min = count > MAX_STR_LEN ? MAX_STR_LEN : count;
+      min = count > (MAX_STR_LEN - 1) ? (MAX_STR_LEN - 1) : count;
       strncpy(pData.public_info, ((ProcInfo *)proc_info)->public_info, min);
     }
  
     if (strlen((const char *)(((ProcInfo *)proc_info)->private_info)) > 0) {
       count = strlen((const char *)(((ProcInfo *)proc_info)->private_info)) + 1;
-      min = count > MAX_STR_LEN ? MAX_STR_LEN : count;
+      min = count > (MAX_STR_LEN - 1) ? (MAX_STR_LEN - 1) : count;
       strncpy(pData.private_info, ((ProcInfo *)proc_info)->private_info, min);
     }
 #endif 
@@ -530,9 +528,10 @@
     if (mtr_list_num > sizeof(mtr_list) / sizeof(mtr_list[0])) {
       mtr_list_num = sizeof(mtr_list) / sizeof(mtr_list[0]);
     }
-    
+  
+    Proc_ptr = &(ptr->procData);
     for(int i = 0; i < mtr_list_num; i++) {
-      mtr_list[i].proc_id = ptr->procData.proc_id;
+      mtr_list[i].proc_id = (Proc_ptr + i)->proc_id;
       mtr_list[i].mq_id = ID_RSV;
       mtr_list[i].abs_addr = ABS_ID_RSV;
       mtr_list[i].ip = "127.0.0.1";
@@ -1162,6 +1161,7 @@
   int sec, nsec;
   std::string MsgID;
   int timeout_ms = 3000;
+  char data_buf[MAX_STR_LEN] = { 0x00 };
   char buf_temp[MAX_STR_LEN] = { 0x00 };
   char *topics_buf = NULL;
   
@@ -1225,7 +1225,9 @@
   rv = net_mod_socket_reg(gNetmod_socket, buf_temp, strlen(buf_temp), &buf, &size, timeout_ms, PROC_QUE_STCS);
   if (rv == 0) {
 
-    val = atoi((char *)buf);
+    len = size > (sizeof(data_buf) - 1) ? (sizeof(data_buf) - 1) : size;
+    memcpy(data_buf, (char *)buf, len);
+    val = atoi((char *)data_buf);
 
     free(buf);
 
@@ -1316,6 +1318,7 @@
   net_node_t node;
   int node_size;  
   int recv_arr_size;
+  char data_buf[MAX_STR_LEN] = { 0x00 };
   net_mod_recv_msg_t *recv_arr;
   net_mod_err_t *errarr;
   int errarr_size = 0;
@@ -1389,7 +1392,9 @@
   rv = net_mod_socket_reg(gNetmod_socket, buf_temp, strlen(buf_temp), &buf, &size, timeout_ms, PROC_QUE_STCS);
   if (rv == 0) {
     
-    val = atoi((char *)buf);
+    len = size > (sizeof(data_buf) - 1) ? (sizeof(data_buf) - 1) : size;
+    memcpy(data_buf, (char *)buf, len);
+    val = atoi((char *)data_buf);
 
     free(buf);
 
@@ -1401,7 +1406,6 @@
       len += strlen(_input1.data);
 #endif
 
-      data = net_mod_socket_svr_get(gNetmod_socket);
       topics_buf = (char *)malloc(len);
       if (topics_buf == NULL) {
         

--
Gitblit v1.8.0