1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
5 -- G N A T . C G I . C O O K I E --
11 -- Copyright (C) 2000-2001 Ada Core Technologies, Inc. --
13 -- GNAT is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNAT; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
24 -- As a special exception, if other files instantiate generics from this --
25 -- unit, or you link this unit with other files to produce an executable, --
26 -- this unit does not by itself cause the resulting executable to be --
27 -- covered by the GNU General Public License. This exception does not --
28 -- however invalidate any other reasons why the executable file might be --
29 -- covered by the GNU Public License. --
31 -- GNAT is maintained by Ada Core Technologies Inc (http://www.gnat.com). --
33 ------------------------------------------------------------------------------
35 -- This is a package to interface a GNAT program with a Web server via the
36 -- Common Gateway Interface (CGI). It exports services to deal with Web
37 -- cookies (piece of information kept in the Web client software).
39 -- The complete CGI Cookie specification can be found in the RFC2109 at:
40 -- http://www.ics.uci.edu/pub/ietf/http/rfc2109.txt
42 -- This package builds up data tables whose memory is not released.
43 -- A CGI program is expected to be a short lived program and so it
44 -- is adequate to have the underlying OS free the program on exit.
46 package GNAT.CGI.Cookie is
48 -- The package will initialize itself by parsing the HTTP_Cookie runtime
49 -- CGI environment variable during elaboration but we do not want to raise
50 -- an exception at this time, so the exception Data_Error is deferred and
51 -- will be raised when calling any services below (except for Ok).
53 Cookie_Not_Found : exception;
54 -- This exception is raised when a specific parameter is not found.
57 (Header : String := Default_Header;
58 Force : Boolean := False);
59 -- Output standard CGI header by default. This header must be returned
60 -- back to the server at the very beginning and will be output only for
61 -- the first call to Put_Header if Force is set to False. This procedure
62 -- also outputs the Cookies that have been defined. If the program uses
63 -- the GNAT.CGI.Put_Header service, cookies will not be set.
65 -- Cookies are passed back to the server in the header, the format is:
67 -- Set-Cookie: <key>=<value>; comment=<comment>; domain=<domain>;
68 -- max_age=<max_age>; path=<path>[; secured]
70 function Ok return Boolean;
71 -- Returns True if the CGI cookie environment is valid and False
72 -- otherwise. Every service used when the CGI environment is not valid
73 -- will raise the exception Data_Error.
75 function Count return Natural;
76 -- Returns the number of cookies received by the CGI.
80 Required : Boolean := False)
82 -- Returns the cookie value associated with the cookie named Key. If
83 -- cookie does not exist, returns an empty string if Required is
84 -- False and raises the exception Cookie_Not_Found otherwise.
86 function Value (Position : Positive) return String;
87 -- Returns the value associated with the cookie number Position
88 -- of the CGI. It raises Cookie_Not_Found if there is no such
89 -- cookie (i.e. Position > Count)
91 function Exists (Key : String) return Boolean;
92 -- Returns True if the cookie named Key exist and False otherwise.
94 function Key (Position : Positive) return String;
95 -- Returns the key associated with the cookie number Position of
96 -- the CGI. It raises Cookie_Not_Found if there is no such cookie
97 -- (i.e. Position > Count)
102 Comment : String := "";
103 Domain : String := "";
104 Max_Age : Natural := Natural'Last;
105 Path : String := "/";
106 Secure : Boolean := False);
107 -- Add a cookie to the list of cookies. This will be sent back
108 -- to the server by the Put_Header service above.
116 Quit : in out Boolean);
117 procedure For_Every_Cookie;
118 -- Iterate through all cookies received from the server and call
119 -- the Action supplied procedure. The Key, Value parameters are set
120 -- appropriately, Position is the cookie order in the list, Quit is set to
121 -- True by default. Quit can be set to False to control the iterator