/usr/share/ada/adainclude/aws/aws-cookie.adb is in libaws3.3.2.2-dev 17.2.2017-2.
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 | ------------------------------------------------------------------------------
-- Ada Web Server --
-- --
-- Copyright (C) 2010-2017, 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/>. --
-- --
-- --
-- --
-- --
-- --
-- --
-- --
------------------------------------------------------------------------------
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with AWS.Headers.Values;
with AWS.Messages;
with AWS.Response.Set;
with AWS.URL;
with AWS.Utils;
package body AWS.Cookie is
Version_Token : constant String := "Version=1";
--------------
-- Exists --
--------------
function Exists
(Request : Status.Data;
Key : String;
Case_Sensitive : Boolean := True) return Boolean
is
Headers : constant AWS.Headers.List := Status.Header (Request);
Cookies : constant String :=
AWS.Headers.Get_Values (Headers, Messages.Cookie_Token);
Headers_Set : constant AWS.Headers.Values.Set :=
AWS.Headers.Values.Split (Cookies);
Key_Index : constant Natural :=
AWS.Headers.Values.Index
(Headers_Set, Key, Case_Sensitive);
begin
return Key_Index > 0;
end Exists;
--------------
-- Expire --
--------------
procedure Expire
(Content : in out Response.Data;
Key : String;
Path : String := "/") is
begin
Set (Content => Content,
Key => Key,
Value => "",
Max_Age => 0.0,
Path => Path);
end Expire;
-----------
-- Get --
-----------
function Get
(Request : Status.Data;
Key : String;
Case_Sensitive : Boolean := True) return String
is
Headers : constant AWS.Headers.List := Status.Header (Request);
Cookies : constant String :=
AWS.Headers.Get_Values (Headers, Messages.Cookie_Token);
Value : constant String :=
AWS.Headers.Values.Search (Cookies, Key, Case_Sensitive);
begin
return URL.Decode (Value);
end Get;
function Get
(Request : Status.Data;
Key : String;
Case_Sensitive : Boolean := True) return Integer
is
Value : constant String := Get (Request, Key, Case_Sensitive);
begin
return Integer'Value (Value);
exception
when Constraint_Error =>
return 0;
end Get;
function Get
(Request : Status.Data;
Key : String;
Case_Sensitive : Boolean := True) return Float
is
Value : constant String := Get (Request, Key, Case_Sensitive);
begin
return Float'Value (Value);
exception
when Constraint_Error =>
return 0.0;
end Get;
function Get
(Request : Status.Data;
Key : String;
Case_Sensitive : Boolean := True) return Boolean is
begin
return Get (Request, Key, Case_Sensitive) = "True";
end Get;
-----------
-- Set --
-----------
procedure Set
(Content : in out Response.Data;
Key : String;
Value : String;
Comment : String := "";
Domain : String := "";
Max_Age : Duration := Default.Ten_Years;
Path : String := "/";
Secure : Boolean := False)
is
Value_Part : constant String :=
Key & "=" & URL.Encode (Value) & "; ";
Path_Part : constant String :=
Messages.Path_Token & "=" & Path & "; ";
Cookie_UString : Unbounded_String :=
To_Unbounded_String (Value_Part & Path_Part);
begin
if Response.Mode (Content) = Response.No_Data then
raise Response_Data_Not_Initialized;
end if;
if Max_Age /= No_Max_Age then
Append
(Cookie_UString,
Messages.Max_Age_Token & "="
& Utils.Image (Natural (Max_Age)) & "; ");
end if;
if Comment /= "" then
Append
(Cookie_UString, Messages.Comment_Token & "=" & Comment & "; ");
end if;
if Domain /= "" then
Append
(Cookie_UString, Messages.Domain_Token & "=" & Domain & "; ");
end if;
if Secure then
Append (Cookie_UString, Messages.Secure_Token & "; ");
end if;
Append (Cookie_UString, Version_Token & "; ");
Response.Set.Add_Header
(Content,
Name => Messages.Set_Cookie_Token,
Value => To_String (Cookie_UString));
end Set;
procedure Set
(Content : in out Response.Data;
Key : String;
Value : Integer;
Comment : String := "";
Domain : String := "";
Max_Age : Duration := Default.Ten_Years;
Path : String := "/";
Secure : Boolean := False)
is
String_Value : constant String := Utils.Image (Value);
begin
Set (Content => Content,
Key => Key,
Value => String_Value,
Comment => Comment,
Domain => Domain,
Max_Age => Max_Age,
Path => Path,
Secure => Secure);
end Set;
procedure Set
(Content : in out Response.Data;
Key : String;
Value : Float;
Comment : String := "";
Domain : String := "";
Max_Age : Duration := Default.Ten_Years;
Path : String := "/";
Secure : Boolean := False)
is
String_Value : constant String :=
Trim (Float'Image (Value), Ada.Strings.Left);
begin
Set (Content => Content,
Key => Key,
Value => String_Value,
Comment => Comment,
Domain => Domain,
Max_Age => Max_Age,
Path => Path,
Secure => Secure);
end Set;
procedure Set
(Content : in out Response.Data;
Key : String;
Value : Boolean;
Comment : String := "";
Domain : String := "";
Max_Age : Duration := Default.Ten_Years;
Path : String := "/";
Secure : Boolean := False) is
begin
if Value then
Set (Content => Content,
Key => Key,
Value => "True",
Comment => Comment,
Domain => Domain,
Max_Age => Max_Age,
Path => Path,
Secure => Secure);
else
Set (Content => Content,
Key => Key,
Value => "False",
Comment => Comment,
Domain => Domain,
Max_Age => Max_Age,
Path => Path,
Secure => Secure);
end if;
end Set;
end AWS.Cookie;
|