2626# Version scheme (MAJOR.MINOR.PATCH) should orientate on "Semantic Versioning" https://semver.org/
2727# Every change in this script should result in increasing the version number accordingly (exceptions may be cosmetic
2828# changes)
29- SERVER_VERSION = "1.3.49 "
29+ SERVER_VERSION = "1.3.50 "
3030
3131OLD_VERSION = '2.14.0'
3232
@@ -1233,15 +1233,24 @@ def read_data(connection, cmd, pos_nl, max_data_size, check_done, cmd_name, time
12331233 else :
12341234 time .sleep (0.2 )
12351235 t += 0.2
1236- connection .close ()
12371236 except socket .error as e :
12381237 print_ts ('Socket error occurred ({}): {}' .format (cmd_name , e ))
12391238 data = None
12401239
1241- if timeout > 0 and t >= timeout :
1240+ connection .close ()
1241+
1242+ if (timeout > 0 ) and (t >= timeout ):
12421243 print_ts ('Timeout occurred ({}).' .format (cmd_name ))
12431244 data = None
12441245
1246+ if data and (len (data ) >= (max_data_size + 1024 )):
1247+ print_ts ('Maximum allowed data ({} bytes) exceeded ({}).' .format (max_data_size , cmd_name ))
1248+ data = None
1249+
1250+ if data and check_done and not data .endswith ('\n DONE' ):
1251+ print_ts ('Incomplete data received ({}).' .format (cmd_name ))
1252+ data = None
1253+
12451254 return data
12461255
12471256def server (server_address_port : int , packages : list , packageIndex : int , resultPath : str ) -> None :
@@ -1268,16 +1277,18 @@ def server(server_address_port: int, packages: list, packageIndex: int, resultPa
12681277 try :
12691278 bytes_received = connection .recv (128 )
12701279 cmd = bytes_received .decode ('utf-8' , 'ignore' )
1271- except socket .error :
1280+ except socket .error as e :
1281+ print_ts ('Error: Recv error: ' + str (e ))
12721282 connection .close ()
12731283 continue
12741284 except UnicodeDecodeError as e :
1275- connection .close ()
12761285 print_ts ('Error: Decoding failed: ' + str (e ))
1286+ connection .close ()
12771287 continue
12781288 pos_nl = cmd .find ('\n ' )
12791289 if pos_nl < 1 :
12801290 print_ts ('No newline found in data.' )
1291+ connection .close ()
12811292 continue
12821293 firstLine = cmd [:pos_nl ]
12831294 if re .match ('[a-zA-Z0-9./ ]+' , firstLine ) is None :
@@ -1292,6 +1303,7 @@ def server(server_address_port: int, packages: list, packageIndex: int, resultPa
12921303 print_ts ('GetCppcheckVersions: ' + reply )
12931304 connection .send (reply .encode ('utf-8' , 'ignore' ))
12941305 connection .close ()
1306+ continue
12951307 elif cmd == 'get\n ' :
12961308 while True :
12971309 pkg = packages [packageIndex ]
@@ -1307,6 +1319,7 @@ def server(server_address_port: int, packages: list, packageIndex: int, resultPa
13071319 print_ts ('get:' + pkg )
13081320 connection .send (pkg .encode ('utf-8' , 'ignore' ))
13091321 connection .close ()
1322+ continue
13101323 elif cmd .startswith ('write\n ftp://' ) or cmd .startswith ('write\n http://' ):
13111324 data = read_data (connection , cmd , pos_nl , max_data_size = 2 * 1024 * 1024 , check_done = True , cmd_name = 'write' )
13121325 if data is None :
@@ -1349,7 +1362,7 @@ def server(server_address_port: int, packages: list, packageIndex: int, resultPa
13491362 if old_version_wrong :
13501363 print_ts ('Unexpected old version. Ignoring result data.' )
13511364 continue
1352- print_ts ('results added for package ' + res .group (1 ))
1365+ print_ts ('results added for package ' + res .group (1 ) + ' (' + str ( len ( data )) + ' bytes)' )
13531366 filename = os .path .join (resultPath , res .group (1 ))
13541367 with open (filename , 'wt' ) as f :
13551368 f .write (strDateTime () + '\n ' + data )
@@ -1361,6 +1374,7 @@ def server(server_address_port: int, packages: list, packageIndex: int, resultPa
13611374 f .write (' ' .join (latestResults ))
13621375 # generate package.diff..
13631376 generate_package_diff_statistics (filename )
1377+ continue
13641378 elif cmd .startswith ('write_info\n ftp://' ) or cmd .startswith ('write_info\n http://' ):
13651379 data = read_data (connection , cmd , pos_nl , max_data_size = 1024 * 1024 , check_done = True , cmd_name = 'write_info' )
13661380 if data is None :
@@ -1386,29 +1400,29 @@ def server(server_address_port: int, packages: list, packageIndex: int, resultPa
13861400 if url not in packages :
13871401 print_ts ('Url is not in packages. Ignoring information data.' )
13881402 continue
1389- print_ts ('adding info output for package ' + res .group (1 ))
1403+ print_ts ('adding info output for package ' + res .group (1 ) + ' (' + str ( len ( data )) + ' bytes)' )
13901404 info_path = resultPath + '/' + 'info_output'
13911405 if not os .path .exists (info_path ):
13921406 os .mkdir (info_path )
13931407 filename = info_path + '/' + res .group (1 )
13941408 with open (filename , 'wt' ) as f :
13951409 f .write (strDateTime () + '\n ' + data )
1410+ continue
13961411 elif cmd == 'getPackagesCount\n ' :
13971412 packages_count = str (len (packages ))
13981413 connection .send (packages_count .encode ('utf-8' , 'ignore' ))
1399- connection .close ()
14001414 print_ts ('getPackagesCount: ' + packages_count )
1415+ connection .close ()
14011416 continue
14021417 elif cmd .startswith ('getPackageIdx' ):
14031418 request_idx = abs (int (cmd [len ('getPackageIdx:' ):]))
14041419 if request_idx < len (packages ):
14051420 pkg = packages [request_idx ]
14061421 connection .send (pkg .encode ('utf-8' , 'ignore' ))
1407- connection .close ()
14081422 print_ts ('getPackageIdx: ' + pkg )
14091423 else :
1410- connection .close ()
14111424 print_ts ('getPackageIdx: index is out of range' )
1425+ connection .close ()
14121426 continue
14131427 elif cmd .startswith ('write_nodata\n ftp://' ):
14141428 data = read_data (connection , cmd , pos_nl , max_data_size = 8 * 1024 , check_done = False , cmd_name = 'write_nodata' )
@@ -1441,8 +1455,7 @@ def server(server_address_port: int, packages: list, packageIndex: int, resultPa
14411455 if currentIdx == startIdx :
14421456 print_ts ('write_nodata:' + url + ' - package not found' )
14431457 break
1444-
1445- connection .close ()
1458+ continue
14461459 else :
14471460 if pos_nl < 0 :
14481461 print_ts ('invalid command: "' + firstLine + '"' )
@@ -1453,6 +1466,7 @@ def server(server_address_port: int, packages: list, packageIndex: int, resultPa
14531466 s += '...'
14541467 print_ts ('invalid command: "' + s + '"' )
14551468 connection .close ()
1469+ continue
14561470
14571471
14581472if __name__ == "__main__" :
0 commit comments