Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

HttpParams.d

Go to the documentation of this file.
00001 /*******************************************************************************
00002 
00003         @file HttpParams.d
00004         
00005         Copyright (C) 2004 Kris Bell
00006         
00007         This software is provided 'as-is', without any express or implied
00008         warranty. In no event will the authors be held liable for damages
00009         of any kind arising from the use of this software.
00010         
00011         Permission is hereby granted to anyone to use this software for any 
00012         purpose, including commercial applications, and to alter it and/or 
00013         redistribute it freely, subject to the following restrictions:
00014         
00015         1. The origin of this software must not be misrepresented; you must 
00016            not claim that you wrote the original software. If you use this 
00017            software in a product, an acknowledgment within documentation of 
00018            said product would be appreciated but is not required.
00019 
00020         2. Altered source versions must be plainly marked as such, and must 
00021            not be misrepresented as being the original software.
00022 
00023         3. This notice may not be removed or altered from any distribution
00024            of the source.
00025 
00026 
00027                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00028 
00029         
00030         @version        Initial version, April 2004      
00031         @author         Kris
00032 
00033 
00034 *******************************************************************************/
00035 
00036 module mango.http.server.HttpParams;
00037 
00038 private import  mango.io.Token,
00039                 mango.io.Tokenizer;
00040 
00041 private import  mango.io.model.IBuffer;
00042 
00043 private import  mango.http.server.HttpTokens;
00044 
00045 /******************************************************************************
00046 
00047         Maintains a set of query parameters, parsed from an HTTP request.
00048         Use HttpMutableParams instead for output parameters.
00049 
00050 ******************************************************************************/
00051 
00052 class HttpParams : HttpTokens
00053 {
00054         private static BoundToken amp;
00055 
00056         // tell compiler to used super.parse() also
00057         alias HttpTokens.parse parse;
00058 
00059         /**********************************************************************
00060                 
00061                 Setup a token for extracting each query construct
00062 
00063         **********************************************************************/
00064 
00065         static this ()
00066         {
00067                 amp = new BoundToken (new SimpleTokenizer('&'));
00068         }
00069 
00070         /**********************************************************************
00071                 
00072                 Construct parameters by telling the TokenStack that
00073                 name/value pairs are seperated by a '=' character.
00074 
00075         **********************************************************************/
00076 
00077         this ()
00078         {
00079                 super ('=');
00080         }
00081 
00082         /**********************************************************************
00083                 
00084                 Clone a source set of HttpParams
00085 
00086         **********************************************************************/
00087 
00088         this (HttpParams source)
00089         {
00090                 super (source);
00091         }
00092 
00093         /**********************************************************************
00094                 
00095                 Clone this set of HttpParams
00096 
00097         **********************************************************************/
00098 
00099         HttpParams clone ()
00100         {
00101                 return new HttpParams (this);
00102         }
00103 
00104         /**********************************************************************
00105                 
00106                 Read all query parameters. Everything is mapped rather 
00107                 than being allocated & copied
00108 
00109         **********************************************************************/
00110 
00111         void parse (IBuffer input)
00112         {
00113                 setParsed (true);
00114                 while (amp.next(input) || amp.getLength())
00115                        stack.push (amp);
00116         }
00117 }
00118 
00119 
00120 /******************************************************************************
00121 
00122         HttpMutableParams are used for output purposes. This can be used
00123         to add a set of queries and then combine then into a text string
00124         using method write().
00125 
00126 ******************************************************************************/
00127 
00128 class HttpMutableParams : HttpParams
00129 {      
00130         /**********************************************************************
00131                 
00132                 Construct output params upon the provided IBuffer
00133 
00134         **********************************************************************/
00135 
00136         this (IBuffer output)
00137         {
00138                 super();
00139                 super.setOutputBuffer (output);
00140         }
00141         
00142         /**********************************************************************
00143                 
00144                 Clone a source set of HttpMutableParams
00145 
00146         **********************************************************************/
00147 
00148         this (HttpMutableParams source)
00149         {
00150                 super (source);
00151         }
00152 
00153         /**********************************************************************
00154                 
00155                 Clone this set of HttpMutableParams
00156 
00157         **********************************************************************/
00158 
00159         HttpMutableParams clone ()
00160         {
00161                 return new HttpMutableParams (this);
00162         }
00163 
00164         /**********************************************************************
00165                 
00166                 Add a name/value pair to the query list
00167 
00168         **********************************************************************/
00169 
00170         void add (char[] name, char[] value)
00171         {
00172                 super.add (name, value);
00173         }
00174 
00175         /**********************************************************************
00176                 
00177                 Add a name/integer pair to the query list 
00178 
00179         **********************************************************************/
00180 
00181         void addInt (char[] name, int value)
00182         {
00183                 super.addInt (name, value);
00184         }
00185 
00186 
00187         /**********************************************************************
00188                 
00189                 Add a name/date(long) pair to the query list
00190 
00191         **********************************************************************/
00192 
00193         void addDate (char[] name, long value)
00194         {
00195                 super.addDate (name, value);
00196         }
00197 }

Generated on Sun Oct 24 22:31:14 2004 for Mango by doxygen 1.3.6