Wendal Chen пре 3 месеци
родитељ
комит
f0a16342b2
2 измењених фајлова са 17 додато и 8 уклоњено
  1. 5 1
      components/network/libhttp/luat_http_client.c
  2. 12 7
      components/network/libhttp/luat_lib_http.c

+ 5 - 1
components/network/libhttp/luat_http_client.c

@@ -695,6 +695,10 @@ int32_t luat_lib_http_callback(void *data, void *param){
 	OS_EVENT *event = (OS_EVENT *)data;
 	OS_EVENT *event = (OS_EVENT *)data;
 	luat_http_ctrl_t *http_ctrl =(luat_http_ctrl_t *)param;
 	luat_http_ctrl_t *http_ctrl =(luat_http_ctrl_t *)param;
 	int ret = 0;
 	int ret = 0;
+	if (http_ctrl == NULL){
+		LLOGE("http_ctrl is NULL");
+		return -1;
+	}
 	if (!http_ctrl->luatos_mode) {
 	if (!http_ctrl->luatos_mode) {
 	    if (HTTP_STATE_IDLE == http_ctrl->state)
 	    if (HTTP_STATE_IDLE == http_ctrl->state)
 	    {
 	    {
@@ -708,7 +712,7 @@ int32_t luat_lib_http_callback(void *data, void *param){
 	}
 	}
 
 
 	//LLOGD("LINK %d ON_LINE %d EVENT %d TX_OK %d CLOSED %d",EV_NW_RESULT_LINK & 0x0fffffff,EV_NW_RESULT_CONNECT & 0x0fffffff,EV_NW_RESULT_EVENT & 0x0fffffff,EV_NW_RESULT_TX & 0x0fffffff,EV_NW_RESULT_CLOSE & 0x0fffffff);
 	//LLOGD("LINK %d ON_LINE %d EVENT %d TX_OK %d CLOSED %d",EV_NW_RESULT_LINK & 0x0fffffff,EV_NW_RESULT_CONNECT & 0x0fffffff,EV_NW_RESULT_EVENT & 0x0fffffff,EV_NW_RESULT_TX & 0x0fffffff,EV_NW_RESULT_CLOSE & 0x0fffffff);
-	LLOGD("luat_lib_http_callback %08X %d %p",event->ID - EV_NW_RESULT_BASE, event->Param1, http_ctrl);
+	LLOGD("nw cb %08X %d %p", event->ID - EV_NW_RESULT_BASE, event->Param1, http_ctrl);
 	if (event->Param1){
 	if (event->Param1){
 		//LLOGD("LINK %d ON_LINE %d EVENT %d TX_OK %d CLOSED %d",EV_NW_RESULT_LINK & 0x0fffffff,EV_NW_RESULT_CONNECT & 0x0fffffff,EV_NW_RESULT_EVENT & 0x0fffffff,EV_NW_RESULT_TX & 0x0fffffff,EV_NW_RESULT_CLOSE & 0x0fffffff);
 		//LLOGD("LINK %d ON_LINE %d EVENT %d TX_OK %d CLOSED %d",EV_NW_RESULT_LINK & 0x0fffffff,EV_NW_RESULT_CONNECT & 0x0fffffff,EV_NW_RESULT_EVENT & 0x0fffffff,EV_NW_RESULT_TX & 0x0fffffff,EV_NW_RESULT_CLOSE & 0x0fffffff);
 		LLOGE("error event %08X %d host %s port %d",event->ID - EV_NW_RESULT_BASE, event->Param1, http_ctrl->netc->domain_name, http_ctrl->netc->remote_port);
 		LLOGE("error event %08X %d host %s port %d",event->ID - EV_NW_RESULT_BASE, event->Param1, http_ctrl->netc->domain_name, http_ctrl->netc->remote_port);

+ 12 - 7
components/network/libhttp/luat_lib_http.c

@@ -35,7 +35,7 @@ end)
 #define LUAT_HTTP_DEBUG 0
 #define LUAT_HTTP_DEBUG 0
 #endif
 #endif
 #undef LLOGD
 #undef LLOGD
-#define LLOGD(...) if (http_ctrl->debug_onoff) LLOGI(__VA_ARGS__)
+#define LLOGD(fmt, ...) if (http_ctrl->debug_onoff) LLOGI("[%llx]" fmt, http_ctrl->idp, ##__VA_ARGS__)
 
 
 
 
 int http_close(luat_http_ctrl_t *http_ctrl);
 int http_close(luat_http_ctrl_t *http_ctrl);
@@ -342,6 +342,7 @@ static int l_http_request(lua_State *L) {
 
 
 	network_set_ip_invaild(&http_ctrl->ip_addr);
 	network_set_ip_invaild(&http_ctrl->ip_addr);
 	http_ctrl->idp = luat_pushcwait(L);
 	http_ctrl->idp = luat_pushcwait(L);
+	LLOGI("http idp:%llx", http_ctrl->idp);
 
 
     if (luat_http_client_start_luatos(http_ctrl)) {
     if (luat_http_client_start_luatos(http_ctrl)) {
         goto error;
         goto error;
@@ -358,13 +359,13 @@ error:
 }
 }
 
 
 #include "rotable2.h"
 #include "rotable2.h"
-const rotable_Reg_t reg_http[] =
+static const rotable_Reg_t reg_http[] =
 {
 {
 	{"request",			ROREG_FUNC(l_http_request)},
 	{"request",			ROREG_FUNC(l_http_request)},
 	{ NULL,             ROREG_INT(0)}
 	{ NULL,             ROREG_INT(0)}
 };
 };
 
 
-const rotable_Reg_t reg_http_emtry[] =
+static const rotable_Reg_t reg_http_emtry[] =
 {
 {
 	{ NULL,             ROREG_INT(0)}
 	{ NULL,             ROREG_INT(0)}
 };
 };
@@ -391,8 +392,13 @@ int32_t l_http_callback(lua_State *L, void* ptr){
 
 
     rtos_msg_t* msg = (rtos_msg_t*)lua_topointer(L, -1);
     rtos_msg_t* msg = (rtos_msg_t*)lua_topointer(L, -1);
     luat_http_ctrl_t *http_ctrl =(luat_http_ctrl_t *)msg->ptr;
     luat_http_ctrl_t *http_ctrl =(luat_http_ctrl_t *)msg->ptr;
+	if (http_ctrl == NULL){
+		LLOGE("http callback http_ctrl is NULL");
+		return 0;
+	}
 	uint64_t idp = http_ctrl->idp;
 	uint64_t idp = http_ctrl->idp;
-	LLOGI("l_http_callback arg1:%d is_download:%d idp:%d",msg->arg1,http_ctrl->is_download,idp);
+	LLOGD("cb arg1:%d is_download:%d idp:%llx",msg->arg1,http_ctrl->is_download,idp);
+	LLOGD("cb status_code:%d resp_content_len:%d",http_ctrl->parser.status_code,http_ctrl->resp_content_len);
 	if (msg->arg1!=0 && msg->arg1!=HTTP_ERROR_FOTA ){
 	if (msg->arg1!=0 && msg->arg1!=HTTP_ERROR_FOTA ){
 		if (msg->arg1 == HTTP_CALLBACK){
 		if (msg->arg1 == HTTP_CALLBACK){
 			lua_geti(L, LUA_REGISTRYINDEX, (int)http_ctrl->http_cb);
 			lua_geti(L, LUA_REGISTRYINDEX, (int)http_ctrl->http_cb);
@@ -427,8 +433,7 @@ int32_t l_http_callback(lua_State *L, void* ptr){
 		temp = strstr(value,"\r\n")+2;
 		temp = strstr(value,"\r\n")+2;
 		header_len = (uint16_t)(value-header)-1;
 		header_len = (uint16_t)(value-header)-1;
 		value_len = (uint16_t)(temp-value)-2;
 		value_len = (uint16_t)(temp-value)-2;
-		LLOGD("header:%.*s",header_len,header);
-		LLOGD("value:%.*s",value_len,value);
+		LLOGD("header: [%.*s]:[%.*s]",header_len,header,value_len,value);
 		lua_pushlstring(L, header,header_len);
 		lua_pushlstring(L, header,header_len);
 		lua_pushlstring(L, value,value_len);
 		lua_pushlstring(L, value,value_len);
 		lua_settable(L, -3);
 		lua_settable(L, -3);
@@ -483,7 +488,7 @@ exit:
 }
 }
 
 
 void luat_http_client_onevent(luat_http_ctrl_t *http_ctrl, int error_code, int arg) {
 void luat_http_client_onevent(luat_http_ctrl_t *http_ctrl, int error_code, int arg) {
-	LLOGD("luat_http_client_onevent %p %d", http_ctrl, error_code);
+	LLOGD("onevent %p %d", http_ctrl, error_code);
 	if (!http_ctrl->luatos_mode) return;
 	if (!http_ctrl->luatos_mode) return;
 	if (http_ctrl->timeout_timer && error_code != HTTP_CALLBACK){
 	if (http_ctrl->timeout_timer && error_code != HTTP_CALLBACK){
 		luat_stop_rtos_timer(http_ctrl->timeout_timer);
 		luat_stop_rtos_timer(http_ctrl->timeout_timer);