text
stringlengths
0
234
Value_Str : String)
is
begin
Config.Upstream_DNS_Server := To_Unbounded_String (Value_Str);
exception
when Constraint_Error =>
raise Malformed_Line with "Invalid upstrema DNS Server";
end Parse_Upstream_DNS_Server;
-- Loads the upstream DNS Server port from the config file
--
-- @value Config
-- Configuration struct to update
--
-- @value Value_Str
-- Pure text version of the configuration argument
--
procedure Parse_Upstream_DNS_Server_Port
(Config : in out Configuration;
Value_Str : String)
is
begin
Config.Upstream_DNS_Server_Port := Port_Type'Value (Value_Str);
exception
when Constraint_Error =>
raise Malformed_Line
with "Upstream_DNS_Server_Port not a valid port number";
end Parse_Upstream_DNS_Server_Port;
procedure Initialize_Config_Parse is
begin
-- Load String to Type Mapping
GCP_Map.Insert ("LOCAL_LISTEN_PORT", Parse_Local_Listen_Port'Access);
GCP_Map.Insert ("UPSTREAM_DNS_SERVER", Parse_Upstream_DNS_Server'Access);
GCP_Map.Insert
("UPSTREAM_DNS_SERVER_PORT", Parse_Upstream_DNS_Server_Port'Access);
end Initialize_Config_Parse;
procedure Read_Cfg_File
(Config : in out Configuration;
Config_File_Path : String)
is
Config_File : Ada.Text_IO.File_Type;
Line_Count : Integer := 1;
Exception_Message : Unbounded_String;
use GCP_Management;
begin
Initialize_Config_Parse;
-- Try to open the configuration file
Open
(File => Config_File,
Mode => Ada.Text_IO.In_File,
Name => Config_File_Path);
while not End_Of_File (Config_File)
loop
declare
Current_Line : constant String := Get_Line (Config_File);
Key_End_Loc : Integer := 0;
Equals_Loc : Integer := 0;
Value_Loc : Integer := 0;
Is_Whitespace : Boolean := True;
begin
-- Skip lines starting with a comment or blank
if Current_Line = ""
then
goto Config_Parse_Continue;
end if;
-- Has to be done seperately or it blows an index check
if Current_Line (1) = '#'
then
goto Config_Parse_Continue;
end if;
-- Skip line if its all whitespace
for I in Current_Line'range
loop
if Current_Line (I) /= ' ' and
Current_Line (I) /= Ada.Characters.Latin_1.HT
then
Is_Whitespace := False;
end if;
if Current_Line (I) = '='
then
Equals_Loc := I;
end if;
-- Determine length of the key
--
-- This is a little non-obvious at first glance. We subtract 2
-- here to remove the character we want, and the previous char
-- because a 17 char string will be 1..18 in the array.
if (Is_Whitespace or Current_Line (I) = '=') and Key_End_Loc = 0
then
Key_End_Loc := I - 2;
end if;