/usr/share/ada/adainclude/aws/aws-parameters-set.adb is in libaws3.2.0-dev 3.2.0-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 | ------------------------------------------------------------------------------
-- Ada Web Server --
-- --
-- Copyright (C) 2000-2013, AdaCore --
-- --
-- This library is free software; you can redistribute it and/or modify --
-- it under terms of the GNU General Public License as published by the --
-- Free Software Foundation; either version 3, or (at your option) any --
-- later version. This library is distributed in the hope that it will be --
-- useful, but WITHOUT ANY WARRANTY; without even the implied warranty of --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- --
-- --
-- --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- --
-- --
-- --
-- --
-- --
-- --
------------------------------------------------------------------------------
pragma Ada_2012;
with Ada.Streams;
with Ada.Strings.Fixed;
with AWS.Config;
with AWS.Containers.Tables.Set;
with AWS.Server;
with AWS.Translator;
with AWS.URL;
with AWS.Utils;
package body AWS.Parameters.Set is
use AWS.Containers;
procedure Add_Internal
(Parameter_List : in out List;
Parameters : String;
Count : in out Natural;
Max_Parameters : Positive);
-- Add parameters as parsed from Parameters and raised Too_Many_Parameters
-- if the Max_Parameters count is reached.
---------
-- Add --
---------
procedure Add
(Parameter_List : in out List;
Name, Value : String;
Decode : Boolean := True) is
begin
if Parameter_List.Parameters = Null_Unbounded_String then
Append (Parameter_List.Parameters, "?");
else
Append (Parameter_List.Parameters, "&");
end if;
if Value = "" then
Append (Parameter_List.Parameters, Name);
else
Append (Parameter_List.Parameters, Name & "=" & Value);
end if;
if Decode then
-- This is default behavior
Tables.Set.Add
(Tables.Table_Type (Parameter_List),
URL.Decode (Name),
URL.Decode (Value));
else
Tables.Set.Add (Tables.Table_Type (Parameter_List), Name, Value);
end if;
end Add;
---------
-- Add --
---------
procedure Add (Parameter_List : in out List; Parameters : String) is
Count : Natural := 0;
begin
Add_Internal (Parameter_List, Parameters, Count, Positive'Last);
end Add;
procedure Add
(Parameter_List : in out List;
Parameters : in out AWS.Containers.Memory_Streams.Stream_Type)
is
use Ada.Streams;
use AWS.Containers.Memory_Streams;
use AWS.Translator;
Max_Parameters : constant Positive :=
Config.Max_POST_Parameters
(Server.Config (Server.Get_Current.all));
-- For security reasons we only allow a maximum number of parameters per
-- HTTP request.
Count : Natural := 0;
Amp : constant Stream_Element := Character'Pos ('&');
Buffer : Stream_Element_Array
(1 .. Stream_Element_Offset'Min
(Stream_Element_Offset
(AWS.Config.Input_Line_Size_Limit),
Size (Parameters)));
First : Stream_Element_Offset := Buffer'First;
Last : Stream_Element_Offset;
Found : Boolean;
WNF : Boolean := False;
-- Was not found. This flag need to detect more than once 'not found'
-- cases. If length of parameter name and value no more than
-- AWS.Config.Input_Line_Size_Limit, 'not Found' case could happen only
-- at the end of parameters line. In case of twice 'not Found' cases we
-- raise Too_Long_Parameter.
begin
if Buffer'Length = 0 then
return;
end if;
Reset (Parameters);
loop
Read (Parameters, Buffer (First .. Buffer'Last), Last);
Found := False;
Find_Last_Amp : for J in reverse First .. Last loop
if Buffer (J) = Amp then
Found := True;
Add_Internal
(Parameter_List, To_String (Buffer (1 .. J - 1)),
Count, Max_Parameters);
Buffer (1 .. Last - J) := Buffer (J + 1 .. Last);
First := Last - J + 1;
exit Find_Last_Amp;
end if;
end loop Find_Last_Amp;
if Found then
if Last < Buffer'Last then
Add_Internal
(Parameter_List, To_String (Buffer (1 .. First - 1)), Count,
Max_Parameters);
exit;
end if;
else
if WNF and then First <= Last then
raise Too_Long_Parameter
with "HTTP parameter line too long : "
& Slice
(Parameter_List.Parameters,
1, Integer'Min (Length (Parameter_List.Parameters), 64));
end if;
WNF := True;
Add_Internal
(Parameter_List, To_String (Buffer (1 .. Last)),
Count, Max_Parameters);
First := 1;
exit when Last < Buffer'Last;
end if;
end loop;
end Add;
------------------
-- Add_Internal --
------------------
procedure Add_Internal
(Parameter_List : in out List;
Parameters : String;
Count : in out Natural;
Max_Parameters : Positive)
is
use Ada.Strings;
procedure Add (Name, Value : String) with Inline;
-- Add Str as parameter, check for Max_Parameters
---------
-- Add --
---------
procedure Add (Name, Value : String) is
begin
Count := Count + 1;
if Count <= Max_Parameters then
Add (Parameter_List, Name, Value);
else
raise Too_Many_Parameters
with "Maximum number of parameters reached: "
& Utils.Image (Max_Parameters)
& ", see Config.Max_POST_Parameters.";
end if;
end Add;
P : String renames Parameters;
C : Positive := P'First;
I : Natural;
S : Positive;
E : Natural;
begin
-- Skip leading question mark if present
if P /= "" and then P (C) = '?' then
C := Positive'Succ (C);
end if;
while C <= P'Last loop
E := Fixed.Index (P (C .. P'Last), "&");
if E = 0 then
-- Last parameter
E := P'Last;
else
E := E - 1;
end if;
I := Fixed.Index (P (C .. E), "=");
if I = 0 then
-- No value for this parameter
S := E + 1;
I := E;
else
S := I + 1;
I := I - 1;
end if;
Add (Name => P (C .. I), Value => P (S .. E));
if E < P'Last then
C := E + 2;
else
C := E + 1;
end if;
end loop;
end Add_Internal;
--------------------
-- Case_Sensitive --
--------------------
procedure Case_Sensitive
(Parameter_List : in out List;
Mode : Boolean) is
begin
Tables.Set.Case_Sensitive (Tables.Table_Type (Parameter_List), Mode);
end Case_Sensitive;
-----------
-- Reset --
-----------
procedure Reset (Parameter_List : in out List) is
begin
Tables.Set.Reset (Tables.Table_Type (Parameter_List));
Parameter_List.Parameters := Null_Unbounded_String;
end Reset;
------------
-- Update --
------------
procedure Update
(Parameter_List : in out List;
Name, Value : String;
Decode : Boolean := True)
is
First : constant Natural :=
Index (Parameter_List.Parameters, Name & "=");
Last : Natural;
begin
if First = 0 then
-- This Name is not already present, add it
if Parameter_List.Parameters = Null_Unbounded_String then
Append (Parameter_List.Parameters, "?");
else
Append (Parameter_List.Parameters, "&");
end if;
Append (Parameter_List.Parameters, Name & "=" & Value);
else
-- Replace the existing value
Last := Index (Parameter_List.Parameters, "&", From => First);
if Last = 0 then
-- This is the last argument
Last := Length (Parameter_List.Parameters);
else
Last := Last - 1;
end if;
Replace_Slice
(Parameter_List.Parameters,
Low => First + Name'Length + 1,
High => Last,
By => Value);
end if;
if Decode then
-- This is default behavior
Tables.Set.Update
(Tables.Table_Type (Parameter_List),
URL.Decode (Name),
URL.Decode (Value));
else
Tables.Set.Update (Tables.Table_Type (Parameter_List), Name, Value);
end if;
end Update;
end AWS.Parameters.Set;
|