1 // ANNA - Anna is Not Nothingness Anymore
3 // (c) Copyright 2005-2014 Eduardo Ramos Testillano & Francisco Ruiz Rayo
5 // http://redmine.teslayout.com/projects/anna-suite
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions
11 // * Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 // * Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following disclaimer
15 // in the documentation and/or other materials provided with the
17 // * Neither the name of the copyright holder nor the names of its
18 // contributors may be used to endorse or promote products derived from
19 // this software without specific prior written permission.
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 // Authors: eduardo.ramos.testillano@gmail.com
34 // cisco.tierra@gmail.com
37 #ifndef anna_http_Header_hpp
38 #define anna_http_Header_hpp
40 #include <anna/core/RuntimeException.hpp>
41 #include <anna/core/Allocator.hpp>
51 Representacion de las cabeceras HTTP.
56 Tipos de cabeceras definidos en la RFC 2616.
63 CacheControl, Connection, Date, Pragma, Trailer, TransferEncoding, Upgrade, Via,
66 Accept, AcceptCharset, AcceptEncoding, AcceptLanguage, Authorization, Expect, From,
67 Host, IfMatch, IfModifiedSince, IfNoneMatch, IfRange, IfUnmodifiedSince, MaxForwards,
68 ProxyAuthorization, Range, Referer, TE, UserAgent,
70 Allow, ContentEncoding, ContentLanguage, ContentLength, ContentLocation, ContentMD5,
71 ContentRange, ContentType, Expires, LastModified,
73 AcceptRanges, Age, ETAG, Location, ProxyAuthenticate, RetryAfter, Server, Vary,
76 Unknown, End, Begin = 1
81 Categorias de cabeceras definidos en la RFC 2616.
84 struct Category { enum _v { General, Response, Request, Entity, Extension }; };
87 Modos de comparacion aplicados en el metodo #compare.
90 struct Compare { enum _v { Exact = 0, RightTrim = 1, LeftTrim = 2, NoCase = 4, FullMode = 7 }; };
95 ~Header() { delete a_extensionName; }
98 Devuelve el tipo de la cabecera.
99 \return el tipo de la cabecera.
101 Type::_v getType() const throw() { return a_type; }
104 Devuelve la categoria de la cabecera.
105 \return la categoria de la cabecera.
107 Category::_v getCategory() const throw() { return a_category; }
110 Devuelve el puntero nombre de la extension, puede ser NULL.
111 \return el puntero nombre de la extension, puede ser NULL.
113 const std::string* getExtensionName() const throw() { return a_extensionName; }
116 Devuelve el valor asociado a esta cabecera.
117 \return el valor asociado a esta cabecera.
119 const std::string& getStringValue() const throw() { return a_value; }
122 Devuelve el valor numerico asociado a esta cabecera.
123 \return el valor numerico asociado a esta cabecera.
125 const int getIntegerValue() const throw();
128 Establece el valor de esta cabecera.
129 \param token Token del que obtendremos el valor.
130 \warning Exclusivamente uso interno.
132 void setValue(const Token* token) throw();
135 Establece el valor asociado a esta cabecera.
136 \param value Valor a establecer.
138 void setValue(const std::string& value) throw() { a_value = value; }
141 Establece el valor asociado a esta cabecera.
142 \param value Valor a establecer.
144 void setValue(const int value) throw();
148 \param other Cabecera de la que copiar.
149 \return La instancia de si misma.
151 Header& operator = (const Header& other) throw();
154 Compara el contenido actual de esta cabecera con el literal recibido como parametro y
155 devuelve un entero menor, igual o mayor que cero si se encuentra que el contenido
156 es, respectivamente, menor que, igual a (concordante), o mayor que \em str.
158 \param str La cadena con la que comparar.
159 \param flags Modo de comparacion aplicado.
161 \return Un entero menor, igual o mayor que cero si se encuentra que el contenido
162 es, respectivamente, menor que, igual a (concordante), o mayor que \em str.
164 int compare(const char* str, const int flags = Compare::LeftTrim | Compare::NoCase) const throw();
167 Compara el contenido actual de esta cabecera con el literal recibido como parametro y
168 devuelve \em true o \em false dependiendo de si el contenido coincide con \em str.
170 \param str La cadena con la que comparar.
171 \param flags Modo de comparacion aplicado.
173 \return \em true o \em false dependiendo de si el contenido coincide con \em str.
175 bool match(const char* str, const int flags = Compare::LeftTrim | Compare::NoCase) const throw() {
176 return compare(str, flags) == 0;
180 Devuelve una cadena con toda la informacion relevante de este objeto.
181 \return una cadena con toda la informacion relevante de este objeto.
183 std::string asString() const throw();
186 Interpreta el token recibido como parametro y devuelve el valor de Type con el
188 \param token Token obtenido en la fase de analisis.
189 \warning Exclusivamente uso interno.
190 \return El tipo de cabecera.
192 static Type::_v asType(const Token* token) throw();
195 Interpreta el token recibido como parametro y devuelve el nombre de la cabecera
196 con la que esta asociado.
197 \param type Tipo de cabecera.
198 \warning Exclusivamente uso interno.
199 \return El literal con el nombre de la cabecera correspondiente al tipo recibido.
201 static const char* asLiteral(const Type::_v type) throw();
205 Category::_v a_category;
206 std::string* a_extensionName;
208 static const char* st_names [Type::End];
210 Header() : a_extensionName(NULL), a_category(Category::Extension) {;}
211 Header* initialize(const Type::_v type) throw(RuntimeException);
212 Header* initialize(const std::string& name) throw(RuntimeException);
213 std::string code() const throw();
215 friend class Message;
216 friend class Allocator<Header>;