Ver Fonte

!4 add terminalno to http posts

chenliangyu há 1 ano atrás
pai
commit
51c4c595a2

+ 1 - 1
Framework/Common/IHttpFunc.h

@@ -98,7 +98,7 @@ public:
 
 typedef void (*LogFnCallback)(const char*);
 RVCCOMM_API IHttpFunc* create_http(LogFnCallback oLogger);
-typedef void (*GetTokenCallBack)(std::string &, std::string &);
+typedef void (*GetTokenCallBack)(std::string &, std::string &, std::string&, std::string&);
 RVCCOMM_API void SetTokenCallBack(GetTokenCallBack t_callBack);
 
 #endif

+ 1 - 1
Framework/Common/SpSecureClient.h

@@ -105,7 +105,7 @@ private:
 	friend struct OnDisconnectTask;
 	friend struct OnErrorTask;
 };
-void getHttpToken(std::string &channelId, std::string &token);
+void getHttpToken(std::string& channelId, std::string& token, std::string& terminalNo, std::string& reserve1);
 
 
 

+ 8 - 2
Framework/RVCComm/HTTPClient.cpp

@@ -1567,11 +1567,14 @@ const bool CHTTPClient::Get(CHTTPReq &req, CHTTPRet &ret){
 	{
 		std::string channelId = "";
 		std::string token = "";
-		g_tokenCall(channelId, token);
+		std::string terminalno = "";
+		std::string reserve1 = "";
+		g_tokenCall(channelId, token, terminalno, reserve1);
 		if (channelId.length() != 0 && token.length() != 0)
 		{
 			req.m_headers.emplace(std::make_pair("channelId", channelId));
 			req.m_headers.emplace(std::make_pair("token", token));
+			req.m_headers.emplace(std::make_pair("terminalno", terminalno));
 			string out = "channelId:" + channelId + ", token:" + token;
 			if (req.m_printDbg)
 				m_oLog(out.c_str());
@@ -1695,11 +1698,14 @@ const bool CHTTPClient::Post(CHTTPReq &req, CHTTPRet &ret){
 	{
 		std::string channelId = "";
 		std::string token = "";
-		g_tokenCall(channelId, token);
+		std::string terminalno = "";
+		std::string reserve1 = "";
+		g_tokenCall(channelId, token, terminalno, reserve1);
 		if (channelId.length() != 0 && token.length() != 0)
 		{
 			req.m_headers.emplace(std::make_pair("channelId", channelId));
 			req.m_headers.emplace(std::make_pair("token", token));
+			req.m_headers.emplace(std::make_pair("terminalno", terminalno));
 			string out = "channelId:" + channelId + ", token:" + token;
 			if (req.m_printDbg)
 				m_oLog(out.c_str());

+ 3 - 3
Framework/RvcLogSdk/log_api.cpp

@@ -204,7 +204,7 @@ int LOG_OS_HttpPost(const char* url,
 	char** header_array,
 	int header_count,
 	const void* data,
-	int data_len, const char* channelId, const char* token)
+	int data_len, const char* channelId, const char* token, const char* terminalno, const char* reserve1)
 {
 	int retCode = 480;
 	HttpClientResponseResult result;
@@ -402,7 +402,7 @@ void cur_slist_free_all(struct cur_slist *lst)
 }
 
 post_log_result* post_logs(const char* endpoint, const char* accesskeyId, const char* accessKey, const char* stsToken, lz4_log_buf* buffer, log_post_option* option,
-	const char* channelId, const char* token)
+	const char* channelId, const char* token, const char *terminalno, const char *reserve1)
 {
     post_log_result * result = (post_log_result *)malloc(sizeof(post_log_result));
     memset(result, 0, sizeof(post_log_result));
@@ -424,7 +424,7 @@ post_log_result* post_logs(const char* endpoint, const char* accesskeyId, const
         url = sdscat(url, endpoint);
         
         if(buffer->data != NULL && buffer->length != 0)
-			res = LOG_OS_HttpPost(url, header_array, header_count, (const void *) buffer->data, buffer->length, channelId, token);
+			res = LOG_OS_HttpPost(url, header_array, header_count, (const void *) buffer->data, buffer->length, channelId, token, terminalno, reserve1);
 
         result->statusCode = res;
 

+ 1 - 1
Framework/RvcLogSdk/log_api.h

@@ -25,7 +25,7 @@ log_status_t sls_log_init(int32_t log_global_flag);
 void sls_log_destroy();
 
 post_log_result * post_logs(const char *endpoint, const char * accesskeyId, const char *accessKey, const char *stsToken, lz4_log_buf* buffer, log_post_option * option,
-	const char *channelId, const char* token);
+	const char *channelId, const char* token, const char* terminalno, const char* reserve1);
 
 void post_log_result_destroy(post_log_result * result);
 

+ 1 - 1
Framework/RvcLogSdk/log_producer_config.h

@@ -11,7 +11,7 @@
 LOG_CPP_START
 
 #define MAX_TOKEN_LEN 256
-typedef void (*Log_GetTokenCallBack)(char*, char*);
+typedef void (*Log_GetTokenCallBack)(char*, char*, char*, char*);
 
 typedef struct _log_producer_config
 {

+ 3 - 3
Framework/RvcLogSdk/log_producer_sender.c

@@ -179,7 +179,7 @@ void * log_producer_send_fun(void * param)
         post_log_result* rst;
         int32_t sleepMs;
         int i = 0;
-        char channelId[MAX_TOKEN_LEN] = "", token[MAX_TOKEN_LEN] = "";
+        char channelId[MAX_TOKEN_LEN] = "", token[MAX_TOKEN_LEN] = "", terminalno[MAX_TOKEN_LEN] = "", reserve1[MAX_TOKEN_LEN] = "";
         if (producer_manager->shutdown)
         {
             aos_info_log((LB, "send fail but shutdown signal received, force exit"));
@@ -208,9 +208,9 @@ void * log_producer_send_fun(void * param)
 
         
         if(config->tokenFun != NULL)
-            config->tokenFun(channelId, token);
+            config->tokenFun(channelId, token, terminalno, reserve1);
 
-        rst = post_logs(config->endpoint, accessKeyId, accessKey, stsToken, send_buf, &option, channelId, token); //通过http发送logs
+        rst = post_logs(config->endpoint, accessKeyId, accessKey, stsToken, send_buf, &option, channelId, token, terminalno, reserve1); //通过http发送logs
         aos_info_log((LB, "post_logs, type:%d, %s, result:%d", send_buf->type, config->endpoint, rst->statusCode));
 
         sdsfree(accessKeyId);

+ 2 - 2
Framework/RvcRestfulSdk/RestfulFunc.h

@@ -153,7 +153,7 @@ struct HttpClientRequestConfig
 
     void SetTimeout(uint32_t timeoutSecs) { mTimeoutSecs = timeoutSecs; }
     uint32_t GetTimeout() const { return mTimeoutSecs; }
-    bool getToken(std::string& t_channelId, std::string& t_token) const;
+    bool getToken(std::string& t_channelId, std::string& t_token, std::string& terminalNo, std::string& reserve1) const;
 
     virtual void PreDo() {}
     virtual void PostDo() {}
@@ -241,7 +241,7 @@ private:
     
 };
 
-typedef void (*GetRestfulTokenCallBack)(std::string&, std::string&);
+typedef void (*GetRestfulTokenCallBack)(std::string&, std::string&, std::string&, std::string&);
 RVCRESTFULSDK_API void SetRestfulTokenCallBack(GetRestfulTokenCallBack t_callBack);
 
 #endif //_OTHER_RESFULFUNCEXPORT_HEADER_

+ 5 - 4
Framework/RvcRestfulSdk/RestfulFuncImpl.cpp

@@ -33,10 +33,10 @@ RestfulClient::~RestfulClient()
 }
 
 
-bool HttpClientRequestConfig::getToken(std::string& t_channelId, std::string& t_token) const {
+bool HttpClientRequestConfig::getToken(std::string& t_channelId, std::string& t_token, std::string& terminalNo, std::string& reserve1) const {
     if (m_withToken && g_tokenCall != NULL)
     {
-        g_tokenCall(t_channelId, t_token);
+        g_tokenCall(t_channelId, t_token, terminalNo, reserve1);
         if (t_channelId.length() > 0 && t_token.length() > 0)
             return true;
     }
@@ -195,11 +195,12 @@ void RestfulClient::Do(const HttpClientRequestConfig* const pRequestConfig, Http
     }
     request.set_request_uri(urib.to_string());
     request.headers().add(header_names::accept, STRW(pRequestConfig->GetAcceptType()));
-    std::string token, channelId;
-    if (pRequestConfig->getToken(channelId, token))
+    std::string token, channelId, terminalno, reserve1;
+    if (pRequestConfig->getToken(channelId, token, terminalno, reserve1))
     {
         request.headers().add(STRW("channelId"), STRW(channelId));
         request.headers().add(STRW("token"), STRW(token));
+        request.headers().add(STRW("terminalno"), STRW(terminalno));
     }
 
     if (pRequestConfig->GetRequestType() != HttpRequestMethod::GET) {

+ 1 - 4
Framework/spbase/SpBase.cpp

@@ -33,11 +33,10 @@
 #include <DbgHelp.h>
 #else
 #include <exception>
-#include <RestfulFunc.h>
 #endif // RVC_OS_WIN
 #include "SpSecureClient.h"
 #include "IHttpFunc.h"
-
+#include <RestfulFunc.h>
 #include<winpr/library.h>
 #include <winpr/locale.h>
 #include <winpr/exception.h>
@@ -591,9 +590,7 @@ extern "C" SPBASE_API int __stdcall SpRun(const char *mod_name, int epid, int ra
 	}
 
 	SetTokenCallBack(getHttpToken);
-#ifdef RVC_OS_LINUX
 	SetRestfulTokenCallBack(getHttpToken);
-#endif
 
 	//need init shm first, because log_record save in shm
     hint_addr = sp_shm_init(range, FALSE);

+ 8 - 3
Framework/spbase/SpSecureClient.cpp

@@ -20,15 +20,20 @@ using namespace TokenKeeper;
 CEntityBase* SpSecureClient::m_pEntity = NULL;
 
 
-void getHttpToken(std::string &channelId, std::string &token)
+void getHttpToken(std::string &channelId, std::string &token, std::string &terminalNo, std::string &reserve1)
 {
 	CSimpleString t_channelId, t_token;
-	if (SpSecureClient::m_pEntity == NULL || SpSecureClient::m_pEntity->GetFunction()->GetToken(t_channelId, t_token) != ErrorCodeEnum::Error_Succeed)
+	CSystemStaticInfo info;
+	
+	if (SpSecureClient::m_pEntity == NULL ||
+		SpSecureClient::m_pEntity->GetFunction()->GetToken(t_channelId, t_token) != ErrorCodeEnum::Error_Succeed ||
+		SpSecureClient::m_pEntity->GetFunction()->GetSystemStaticInfo(info) != ErrorCodeEnum::Error_Succeed)
 		return;
-	if(t_channelId.GetLength() != 0 && t_token.GetLength() != 0)
+	if(t_channelId.GetLength() != 0 && t_token.GetLength() != 0 && info.strTerminalID.GetLength() != 0)
 	{
 		channelId = t_channelId.GetData();
 		token = t_token.GetData();
+		terminalNo = info.strTerminalID.GetData();
 	}
 }
 

+ 3 - 5
Framework/spbase/sp_cfg.cpp

@@ -30,7 +30,7 @@
 #include "sp_httpDefine.h"
 
 #include "sp_logwithlink.h"
-
+#include "RestfulFunc.h"
 #if defined(_MSC_VER)
 #include "AutoLock.h"
 #include <memory>
@@ -43,7 +43,6 @@
 #include <iomanip>
 #define UPDATE_ROOT_BY_HTTP
 #else
-#include "RestfulFunc.h"
 #include "JsonConvertHelper.hpp"
 #endif //_MSC_VER
 #include "sp_checkEntity.h"
@@ -119,7 +118,7 @@ int sp_tryReadFromCacheConfig(int cfgType, const char* section, const char* key,
 int sp_tryRefreshLogLevelFromCacheConfig();
 
 
-void shell_getHttpToken(std::string& channelId, std::string& token)
+void shell_getHttpToken(std::string& channelId, std::string& token, std::string& terminalNo, std::string& reserve1)
 {
 	sp_env_t* env = sp_get_env();
 	if (NULL != env && NULL != env->cfg && NULL != env->cfg->shell_ini &&
@@ -127,6 +126,7 @@ void shell_getHttpToken(std::string& channelId, std::string& token)
 	{
 		channelId = env->cfg->shell_ini->channelId;
 		token = env->cfg->shell_ini->token;
+		terminalNo = env->cfg->root_ini->terminal_no;
 	}
 	else if(NULL == env)
 		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("shell_getHttpToken can not get token!env == NULL");
@@ -2660,9 +2660,7 @@ int sp_cfg_create(sp_dir_t* dir, const sp_cfg_start_args_t* args, sp_cfg_t** p_c
 */
 
 	SetTokenCallBack(shell_getHttpToken);
-#ifdef RVC_OS_LINUX
 	SetRestfulTokenCallBack(shell_getHttpToken);
-#endif
 
 	if (Error_Succeed != (rc = init_defaultShellCfg(dir, cfg)))
 		return rc;

+ 2 - 9
Framework/spbase/sp_httpDefine.cpp

@@ -14,13 +14,6 @@
 
 #define QUERY_TERMINAL_MAX_WAIT_TIME 10000
 
-std::string Token_Save::channelId = "";
-std::string Token_Save::token = "";
-void Token_Save::getToken(std::string& t_channelId, std::string& t_token)
-{
-	t_channelId = channelId;
-	t_token = token;
-}
 
 CAutoArray<CSimpleString> generateUrlArr(CSimpleString url, CSimpleString appendStr)
 {
@@ -596,8 +589,8 @@ std::pair<bool, std::string> refreshToken(std::string terminalNo, std::string in
 		{
 			t_isGetTokenSuccess = true;
 			//DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("total getToken success from url %s", reqArr[tokenRet - WAIT_OBJECT_0].m_url.c_str());
-			Token_Save::channelId = channelId.c_str();
-			Token_Save::token = reqArr[tokenRet - WAIT_OBJECT_0].ret.m_token;
+			//Token_Save::channelId = channelId.c_str();
+			//Token_Save::token = reqArr[tokenRet - WAIT_OBJECT_0].ret.m_token;
 			return std::make_pair(true, reqArr[tokenRet - WAIT_OBJECT_0].ret.m_token);
 		}
 	}

+ 0 - 5
Framework/spbase/sp_httpDefine.h

@@ -121,11 +121,6 @@ struct TerminalVerUpdateRet : CHTTPRet {
 	virtual bool Parse(string strData);
 };
 
-struct Token_Save {
-	static std::string channelId;
-	static std::string token;
-	static void getToken(std::string& t_channelId, std::string& t_token);
-};
 
 std::pair<bool, TerminalCfgRet> GetTerminalCfgFromUrl(CSimpleString url, const std::string& terminalNo,
 	const std::string& center_version, const std::string& root_version, const std::string& shell_version,

+ 4 - 2
Framework/spbase/sp_logwithlink.cpp

@@ -39,12 +39,14 @@ void* g_logProduceSender = NULL;
 int curEntityLogLevel = 1;
 
 
-void Log_GetToken(char* channelId, char* token) {
+void Log_GetToken(char* channelId, char* token, char *terminalno, char *reserve1) {
     sp_env_t* env = sp_get_env();
-    if (NULL != env && NULL != env->cfg && NULL != env->cfg->shell_ini && env->cfg->shell_ini->channelId != NULL && env->cfg->shell_ini->token != NULL)
+    if (NULL != env && NULL != env->cfg && NULL != env->cfg->shell_ini && env->cfg->shell_ini->channelId != NULL && env->cfg->shell_ini->token != NULL
+        && NULL != env->cfg->root_ini && NULL != env->cfg->root_ini->terminal_no)
     {
         snprintf(channelId, 256, "%s", env->cfg->shell_ini->channelId);
         snprintf(token, 256, "%s", env->cfg->shell_ini->token);
+        snprintf(terminalno, 256, "%s", env->cfg->root_ini->terminal_no);
     }
 }
 

+ 6 - 3
Other/libRestfulFunc/RestfulFunc.h

@@ -33,7 +33,7 @@
 * -3:地址不符合规范
 */
 
-typedef void (*restFul_GetTokenCallBack)(char *, char *);
+typedef void (*restFul_GetTokenCallBack)(char *, char *, char*, char*);
 
 RESTFULFUNC_API int HttpProbe(const std::string& url, std::string& out_msg, uint32_t wait_max_secs = (uint32_t)-1);
 
@@ -181,16 +181,19 @@ struct HttpClientRequestConfig
     virtual void PreDo() {}
     virtual void PostDo() {}
 
-    bool getToken(std::string & t_channelId, std::string &t_token) const {
+    bool getToken(std::string & t_channelId, std::string &t_token, std::string& t_terminalNo, std::string& t_reserve1) const {
         char channelId[256] = "";
         char token[256] = "";
+        char terminalNo[256] = "";
+        char reserve1[256] = "";
         if (m_withToken && g_tokenCall != NULL)
         {
-            g_tokenCall(channelId, token);
+            g_tokenCall(channelId, token, terminalNo, reserve1);
             if (std::string(channelId).length() > 0 && std::string(token).length() > 0)
             {
                 t_channelId = channelId;
                 t_token = token;
+                t_terminalNo = terminalNo;
                 return true;
             }
         }

+ 3 - 2
Other/libRestfulFunc/RestfulFuncImpl.cpp

@@ -181,11 +181,12 @@ void RestfulClient::Do(const HttpClientRequestConfig* const pRequestConfig, Http
 	request.set_request_uri(urib.to_string());
 	request.headers().add(header_names::accept, STRW(pRequestConfig->GetAcceptType()));
 
-	std::string token, channelId;
-	if (pRequestConfig->getToken(channelId, token))
+	std::string token, channelId, terminalno, reserve1;
+	if (pRequestConfig->getToken(channelId, token, terminalno, reserve1))
 	{
 		request.headers().add(STRW("channelId"), STRW(channelId));
 		request.headers().add(STRW("token"), STRW(token));
+		request.headers().add(STRW("terminalno"), STRW(terminalno));
 	}
 
 	if (pRequestConfig->GetRequestType() != HttpRequestMethod::GET) {