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

Generated on Sun Nov 7 19:06:51 2004 for Mango by doxygen 1.3.6