Rework Configuration Load, it is possible to set directly a xml String or a file
This commit is contained in:
		
							parent
							
								
									e8651f7602
								
							
						
					
					
						commit
						beef8490f5
					
				
					 3 changed files with 17 additions and 9 deletions
				
			
		|  | @ -53,20 +53,28 @@ | ||||||
|     EndIf |     EndIf | ||||||
|   EndProcedure |   EndProcedure | ||||||
| 
 | 
 | ||||||
|   Procedure server_initial(ConfigFile.s) |   Procedure server_initial(ConfigOptions.s) | ||||||
|     ;Initialize Webserver from the Config File(s) |     ;Initialize Webserver from the Config File(s) | ||||||
|      |      | ||||||
|     Protected FileHandle.i, XMLHandle.i, DirectoryHandle.i |     Protected FileHandle.i, XMLHandle.i, DirectoryHandle.i | ||||||
|     Protected XMLReaded.s |     Protected XMLReaded.s, ConfigFile.s | ||||||
|     FileHandle = ReadFile(#PB_Any, ConfigFile) |     If Left(ConfigOptions, 5) = "file:" | ||||||
|     If IsFile(FileHandle) |       ConfigFile = RemoveString(ConfigOptions, "file:") | ||||||
|       XMLReaded = ReadString(FileHandle, #PB_File_IgnoreEOL) |       FileHandle = ReadFile(#PB_Any, ConfigFile) | ||||||
|       CloseFile(FileHandle) |       If IsFile(FileHandle) | ||||||
|  |         XMLReaded = ReadString(FileHandle, #PB_File_IgnoreEOL) | ||||||
|  |         CloseFile(FileHandle) | ||||||
|  |       EndIf | ||||||
|  |     Else | ||||||
|  |       XMLReaded = ConfigOptions | ||||||
|  |     EndIf | ||||||
|  |      | ||||||
|  |     If Len(XMLReaded) > 0   | ||||||
|       XMLHandle = ParseXML(#PB_Any, XMLReaded) |       XMLHandle = ParseXML(#PB_Any, XMLReaded) | ||||||
|       If XMLStatus(XMLHandle) = #PB_XML_Success |       If XMLStatus(XMLHandle) = #PB_XML_Success | ||||||
|         ExtractXMLStructure(MainXMLNode(XMLHandle), @configuration, server, #PB_XML_NoCase) |         ExtractXMLStructure(MainXMLNode(XMLHandle), @configuration, server, #PB_XML_NoCase) | ||||||
|         FreeXML(XMLHandle) |         FreeXML(XMLHandle) | ||||||
|         ;Now we need to load  |         ;Now we need to load additional Config Files | ||||||
|         ResetMap(configuration\config_file()) |         ResetMap(configuration\config_file()) | ||||||
|         While NextMapElement(configuration\config_file()) |         While NextMapElement(configuration\config_file()) | ||||||
|           Debug configuration\config_file()\configtype |           Debug configuration\config_file()\configtype | ||||||
|  |  | ||||||
|  | @ -7,5 +7,5 @@ | ||||||
| ;* Configuration functions. | ;* Configuration functions. | ||||||
| ;* | ;* | ||||||
| 
 | 
 | ||||||
| Declare server_initial(ConfigFile.s) | Declare server_initial(ConfigOptions.s) | ||||||
| Declare.s server_get_config(Type.s, UUID.s = "") | Declare.s server_get_config(Type.s, UUID.s = "") | ||||||
|  | @ -49,7 +49,7 @@ PrintN("Read Configuration:") | ||||||
| ;* | ;* | ||||||
| ;* Read Configuration http & https Server | ;* Read Configuration http & https Server | ||||||
| ;* | ;* | ||||||
| If lhs_web::server_initial("cfg/server_config.xml") | If lhs_web::server_initial("file:cfg/server_config.xml") | ||||||
|   ldl::Logging("config succesfully loaded.") |   ldl::Logging("config succesfully loaded.") | ||||||
| Else | Else | ||||||
|   ldl::Logging("config load failed.") |   ldl::Logging("config load failed.") | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue