Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | 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         4. Derivative works are permitted, but they must carry this notice
00027            in full and credit the original source.
00028 
00029 
00030                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00031 
00032         
00033         @version        Initial version, April 2004      
00034         @author         Kris
00035 
00036 
00037 *******************************************************************************/
00038 
00039 module mango.http.server.HttpParams;
00040 
00041 private import  mango.io.Token,
00042                 mango.io.Tokenizer;
00043 
00044 private import  mango.io.model.IBuffer;
00045 
00046 private import  mango.http.server.HttpTokens;
00047 
00048 /******************************************************************************
00049 
00050         Maintains a set of query parameters, parsed from an HTTP request.
00051         Use HttpMutableParams instead for output parameters.
00052 
00053         Note that these input params may have been encoded by the user-
00054         agent. Unfortunately there has been little consensus on what that
00055         encoding should be (especially regarding GET query-params). With
00056         luck, that will change to a consistent usage of UTF-8 within the 
00057         near future.
00058 
00059 ******************************************************************************/
00060 
00061 class HttpParams : HttpTokens
00062 {
00063         private static BoundToken amp;
00064 
00065         // tell compiler to used super.parse() also
00066         alias HttpTokens.parse parse;
00067 
00068         /**********************************************************************
00069                 
00070                 Setup a token for extracting each query construct
00071 
00072         **********************************************************************/
00073 
00074         static this ()
00075         {
00076                 amp = new BoundToken (new SimpleTokenizer('&'));
00077         }
00078 
00079         /**********************************************************************
00080                 
00081                 Construct parameters by telling the TokenStack that
00082                 name/value pairs are seperated by a '=' character.
00083 
00084         **********************************************************************/
00085 
00086         this ()
00087         {
00088                 super ('=');
00089         }
00090 
00091         /**********************************************************************
00092                 
00093                 Clone a source set of HttpParams
00094 
00095         **********************************************************************/
00096 
00097         this (HttpParams source)
00098         {
00099                 super (source);
00100         }
00101 
00102         /**********************************************************************
00103                 
00104                 Clone this set of HttpParams
00105 
00106         **********************************************************************/
00107 
00108         HttpParams clone ()
00109         {
00110                 return new HttpParams (this);
00111         }
00112 
00113         /**********************************************************************
00114                 
00115                 Read all query parameters. Everything is mapped rather 
00116                 than being allocated & copied
00117 
00118         **********************************************************************/
00119 
00120         void parse (IBuffer input)
00121         {
00122                 setParsed (true);
00123                 while (amp.next(input) || amp.getLength())
00124                        stack.push (amp);
00125         }
00126 }
00127 
00128 
00129 /******************************************************************************
00130 
00131         HttpMutableParams are used for output purposes. This can be used
00132         to add a set of queries and then combine then into a text string
00133         using method write().
00134 
00135 ******************************************************************************/
00136 
00137 class HttpMutableParams : HttpParams
00138 {      
00139         /**********************************************************************
00140                 
00141                 Construct output params upon the provided IBuffer
00142 
00143         **********************************************************************/
00144 
00145         this (IBuffer output)
00146         {
00147                 super();
00148                 super.setOutputBuffer (output);
00149         }
00150         
00151         /**********************************************************************
00152                 
00153                 Clone a source set of HttpMutableParams
00154 
00155         **********************************************************************/
00156 
00157         this (HttpMutableParams source)
00158         {
00159                 super (source);
00160         }
00161 
00162         /**********************************************************************
00163                 
00164                 Clone this set of HttpMutableParams
00165 
00166         **********************************************************************/
00167 
00168         HttpMutableParams clone ()
00169         {
00170                 return new HttpMutableParams (this);
00171         }
00172 
00173         /**********************************************************************
00174                 
00175                 Add a name/value pair to the query list
00176 
00177         **********************************************************************/
00178 
00179         void add (char[] name, char[] value)
00180         {
00181                 super.add (name, value);
00182         }
00183 
00184         /**********************************************************************
00185                 
00186                 Add a name/integer pair to the query list 
00187 
00188         **********************************************************************/
00189 
00190         void addInt (char[] name, int value)
00191         {
00192                 super.addInt (name, value);
00193         }
00194 
00195 
00196         /**********************************************************************
00197                 
00198                 Add a name/date(long) pair to the query list
00199 
00200         **********************************************************************/
00201 
00202         void addDate (char[] name, long value)
00203         {
00204                 super.addDate (name, value);
00205         }
00206 }

Generated on Fri Nov 11 18:44:20 2005 for Mango by  doxygen 1.4.0