OSDN Git Service

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