Browse Source

[Improve][Modularization][Module_OcppBackend / Moduele_OcppBackend20]

2021.10.26 / Folus Wen

Actions:
1. FTP upload function cancel translate domian name to ip address.
2. ChangeAvailability() connectorId type valid before access value.

Files:
1. As follow commit history

Image version: D0.00.XX.XXXX.XX
Image checksum: XXXXXXXX

Hardware PWB P/N : XXXXXXX
Hardware Version : XXXXXXX
FolusWen 3 years ago
parent
commit
b5a56e46e8

+ 18 - 20
EVSE/Modularization/ocpp20/MessageHandler.c

@@ -18006,36 +18006,34 @@ int httpUploadFile(char *location, char *path, char *filename,char *url)
 
 int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
 {
-	 struct hostent* server;
-	 char *IPbuffer;
-	 char ftpbuf[200];
-	 int systemresult;
-
-	  // To retrieve host information
-	 server = gethostbyname(location);
-	 // To convert an Internet network
-	 // address into ASCII string
-	 IPbuffer = inet_ntoa(*((struct in_addr*)
-			 	 server->h_addr_list[0]));
+	int result = FALSE;
+	char ftpbuf[200];
+	int systemresult;
+
+	/*
+	// Domaind name transfer to IP address
+	struct hostent* server;
+ 	char *IPbuffer;
+	server = gethostbyname(location);
+	IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
 
 	memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
 
-	/* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
-	/* format : ftpput -u  username -p passwd IP  target  source*/
-	sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
-	DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
-	//sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
+	sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
+	DEBUG_INFO("ftp command: %s\n",ftpbuf);
 	systemresult = system(ftpbuf);
 
-	DEBUG_INFO("systemresult=%d\n",systemresult);
 	if(systemresult != 0)
 	{
 		DEBUG_INFO("ftpput error!\n");
-		return FALSE;
+	}
+	else
+	{
+		result = TRUE;
+		DEBUG_INFO("ftpput OK!\n");
 	}
 
-	return TRUE;
-
+	return result;
 }
 
 //=========================================

+ 24 - 26
EVSE/Modularization/ocppfiles/MessageHandler.c

@@ -8504,7 +8504,7 @@ int handleChangeAvailabilityRequest(char *uuid, char *payload)
 {
 	mtrace();
 	int result = FAIL;
-    int gunIndex = 0;
+    int gunIndex = -1;
 	char typeStr[16]={0};
 	char comfirmstr[20];
 	int specificId = FALSE;
@@ -8517,7 +8517,7 @@ int handleChangeAvailabilityRequest(char *uuid, char *payload)
 	if(!is_error(ChangeAvailability))
 	{
 		// Required data
-		if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
+		if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
 			gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
 
 		if(json_object_object_get(ChangeAvailability, "type") != NULL)
@@ -8526,7 +8526,7 @@ int handleChangeAvailabilityRequest(char *uuid, char *payload)
 	json_object_put(ChangeAvailability);
 
 
-	if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
+	if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
 	{
 		ShmOCPP16Data->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
 		sprintf((char *)ShmOCPP16Data->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
@@ -8543,7 +8543,7 @@ int handleChangeAvailabilityRequest(char *uuid, char *payload)
 	memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
 	sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
 
-	if((gunIndex  == 0) || (gunIndex <= gunTotalNumber))
+	if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
 	{
 		specificId = TRUE;
 	}
@@ -10731,7 +10731,7 @@ void* GetDiagnosticsProcess(void* data)
 			ShmOCPP16Data->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
 			sleep(3);
 
-		    isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
+		    isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
 		    if(!isSuccess)
 			{
 				DEBUG_INFO("Diagnostics fail.\n");
@@ -17862,38 +17862,36 @@ int httpUploadFile(char *location, char *path, char *filename,char *url)
 	return TRUE;
 }
 
-int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
+int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
 {
-	 struct hostent* server;
-	 char *IPbuffer;
-	 char ftpbuf[200];
-	 int systemresult;
-
-	  // To retrieve host information
-	 server = gethostbyname(location);
-	 // To convert an Internet network
-	 // address into ASCII string
-	 IPbuffer = inet_ntoa(*((struct in_addr*)
-			 	 server->h_addr_list[0]));
+	int result = FALSE;
+	char ftpbuf[200];
+	int systemresult;
+
+	/*
+	// Domaind name transfer to IP address
+	struct hostent* server;
+ 	char *IPbuffer;
+	server = gethostbyname(location);
+	IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
 
 	memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
 
-	/* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
-	/* format : ftpput -u  username -p passwd IP  target  source*/
-	sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
-	DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
-	//sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
+	sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
+	DEBUG_INFO("ftp command: %s\n",ftpbuf);
 	systemresult = system(ftpbuf);
 
-	DEBUG_INFO("systemresult=%d\n",systemresult);
 	if(systemresult != 0)
 	{
 		DEBUG_INFO("ftpput error!\n");
-		return FALSE;
+	}
+	else
+	{
+		result = TRUE;
+		DEBUG_INFO("ftpput OK!\n");
 	}
 
-	return TRUE;
-
+	return result;
 }
 
 int GetOcppServerURL()

+ 1 - 1
EVSE/Modularization/ocppfiles/MessageHandler.h

@@ -570,7 +570,7 @@ int ftpDownLoadFile(char *location, char *user, char *password, int port, char *
 void *UpdateFirmwareProcess(void* data);
 void* GetDiagnosticsProcess(void* data);
 int httpUploadFile(char *location, char *path, char *filename,char *url);
-int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename);
+int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename);
 void LWS_Send(char * str);
 void LWS_SendNow(char * str);
 extern int queue_operation(int type, char *frontUUID, char *frontData);

+ 24 - 26
EVSE/Modularization/ocppph/MessageHandler.c

@@ -8240,7 +8240,7 @@ int handleChangeAvailabilityRequest(char *uuid, char *payload)
 {
 	mtrace();
 	int result = FAIL;
-    int gunIndex = 0;
+    int gunIndex = -1;
 	char typeStr[16]={0};
 	char comfirmstr[20];
 	int specificId = FALSE;
@@ -8253,7 +8253,7 @@ int handleChangeAvailabilityRequest(char *uuid, char *payload)
 	if(!is_error(ChangeAvailability))
 	{
 		// Required data
-		if(json_object_object_get(ChangeAvailability, "connectorId") != NULL)
+		if((json_object_object_get(ChangeAvailability, "connectorId") != NULL) && (json_object_get_type(json_object_object_get(ChangeAvailability, "connectorId")) == json_type_int))
 			gunIndex = json_object_get_int(json_object_object_get(ChangeAvailability, "connectorId"));
 
 		if(json_object_object_get(ChangeAvailability, "type") != NULL)
@@ -8262,7 +8262,7 @@ int handleChangeAvailabilityRequest(char *uuid, char *payload)
 	json_object_put(ChangeAvailability);
 
 
-	if((gunIndex != 0) && (gunIndex <= gunTotalNumber))
+	if((gunIndex > 0) && (gunIndex <= gunTotalNumber))
 	{
 		ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].ConnectorId= gunIndex;
 		sprintf((char *)ShmOCPP16DataPH->ChangeAvailability[gunIndex - 1].Type, "%s", typeStr);
@@ -8279,7 +8279,7 @@ int handleChangeAvailabilityRequest(char *uuid, char *payload)
 	memset(comfirmstr, 0, ARRAY_SIZE(comfirmstr));
 	sprintf(comfirmstr, "%s", AvailabilityStatusStr[Rejected] );
 
-	if((gunIndex  == 0) || (gunIndex <= gunTotalNumber))
+	if((gunIndex == 0) || ((gunIndex > 0) && (gunIndex <= gunTotalNumber)))
 	{
 		specificId = TRUE;
 	}
@@ -10470,7 +10470,7 @@ void* GetDiagnosticsProcess(void* data)
 			ShmOCPP16DataPH->SpMsg.bits.DiagnosticsStatusNotificationReq = 1;
 			sleep(3);
 
-		    isSuccess = ftpFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
+		    isSuccess = ftpUploadFile(host1, user, password, port, ftppath, fnamePlusPath, fnamePWithNoPath);
 		    if(!isSuccess)
 			{
 				DEBUG_INFO("Diagnostics fail.\n");
@@ -17442,38 +17442,36 @@ int httpUploadFile(char *location, char *path, char *filename,char *url)
 	return TRUE;
 }
 
-int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
+int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename)
 {
-	 struct hostent* server;
-	 char *IPbuffer;
-	 char ftpbuf[200];
-	 int systemresult;
-
-	  // To retrieve host information
-	 server = gethostbyname(location);
-	 // To convert an Internet network
-	 // address into ASCII string
-	 IPbuffer = inet_ntoa(*((struct in_addr*)
-			 	 server->h_addr_list[0]));
+	int result = FALSE;
+	char ftpbuf[200];
+	int systemresult;
+
+	/*
+	// Domaind name transfer to IP address
+	struct hostent* server;
+ 	char *IPbuffer;
+	server = gethostbyname(location);
+	IPbuffer = inet_ntoa(*((struct in_addr*)server->h_addr_list[0]));*/
 
 	memset(ftpbuf, 0, ARRAY_SIZE(ftpbuf));
 
-	/* format : ftpput -u phihong -p y42j%2f4cj84 112.91.88.35 -P 21 /2020-02.zip ../mnt/2020-02.zip*/
-	/* format : ftpput -u  username -p passwd IP  target  source*/
-	sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,port/*21*/,path,filename,fnamePlusPath);
-	DEBUG_INFO("ftpbuf=%s\n",ftpbuf);
-	//sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s",user,password,IPbuffer,21,filename,filename,path);
+	sprintf(ftpbuf, "ftpput -u %s -p %s %s -P %d %s%s %s", user, password, location, port/*21*/, path, filename, fnamePlusPath);
+	DEBUG_INFO("ftp command: %s\n",ftpbuf);
 	systemresult = system(ftpbuf);
 
-	DEBUG_INFO("systemresult=%d\n",systemresult);
 	if(systemresult != 0)
 	{
 		DEBUG_INFO("ftpput error!\n");
-		return FALSE;
+	}
+	else
+	{
+		result = TRUE;
+		DEBUG_INFO("ftpput OK!\n");
 	}
 
-	return TRUE;
-
+	return result;
 }
 
 int GetOcppServerURL()

+ 1 - 1
EVSE/Modularization/ocppph/MessageHandler.h

@@ -567,7 +567,7 @@ int ftpDownLoadFile(char *location, char *user, char *password, int port, char *
 void *UpdateFirmwareProcess(void* data);
 void* GetDiagnosticsProcess(void* data);
 int httpUploadFile(char *location, char *path, char *filename,char *url);
-int ftpFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename);
+int ftpUploadFile(char *location, char *user, char *password, int port, char *path, char *fnamePlusPath,char *filename);
 void LWS_Send(char * str);
 void LWS_SendNow(char * str);
 extern int queue_operation(int type, char *frontUUID, char *frontData);