1 // ANNA - Anna is Not 'N' Anymore
3 // (c) Copyright 2005-2014 Eduardo Ramos Testillano & Francisco Ruiz Rayo
5 // https://bitbucket.org/testillano/anna
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 Google Inc. 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_wims20_ServerSide_hpp
38 #define anna_http_wims20_ServerSide_hpp
40 #include <anna/core/RuntimeException.hpp>
41 #include <anna/core/util/Tokenizer.hpp>
43 #include <anna/http/wims20/Abstract.hpp>
54 Permite interpretar una URI según las recomendaciones de WIMS 2.0, lo que facilita
55 el desarrollo de aplicaciones integradas en Web 2.0; estas recomendaciones indican
56 cómo debe formarse la petición ServerSide (REpresentational State Transfer) para permitir
57 el desarrollo de cualquier servicio.
59 Implementa el interfaz WIMS 2.0 desde el punto de vista del proceso que recibe la petición.
61 El formato general de una URI según la recomendación de WIMS 2.0 es:
64 http://domain-openapis/path-openapis/serviceID/guid/other_possible_levels?query_parameters
67 Dónde los campos tienen siguen la siguiente especificación:
68 \li http://domain-openapis: Identifica el recurso del Open API.
69 \li path-openapis: Recurso opcional que ajusta la ruta hacia los recursos de éste API.
70 \li serviceID: Identificador de recurso.
71 \li guid: Identificador del usuario que solicita la petición.
72 \li other_possible_level: Opcionalmente se pueden indicar tantos niveles jerárquicos como fuera
73 necesario para el servicio.
74 \li query_parameters: Lista de parámetros. Si hay más de un parámetro se separará con '&'.
76 class ServerSide : public Abstract {
79 * Contructor indicando el parámetro opcional \em path-openapis. Estos dos parámetros se obtendrá como
80 * parte de la configuración de nuestro sistema.
81 * \param domain: Identifica el recurso del OpenAPI.
82 * \param path: Parámetro opcional que ajusta la ruta hacia los recusos de éste API.
84 ServerSide(const std::string& domain, const std::string& path) :
85 Abstract("ServerSide", domain, path) {
86 for(int ii = 0; ii < SplitCode::Max; ii ++)
87 a_tokenizer [ii].activateStrip(true);
91 * Constructor que no usará el parámetro opcional \em path-openapis. Este parámetro se obtendrá como
92 * parte de la configuración de nuestro sistema.
93 * \param domain: Identifica el recurso del OpenAPI.
95 explicit ServerSide(const std::string& domain) :
96 Abstract("ServerSide", domain) {
97 for(int ii = 0; ii < SplitCode::Max; ii ++)
98 a_tokenizer [ii].activateStrip(true);
102 * Obtiene el valor asociado a parámetro recibido como parámetro, que habrá sido obtenido
103 * de la URI mediante el método #decode.
104 * \param name Nombre del parámetro que se desea obtener.
105 * \param mode Modo de actuar en caso de que no se encuentre el parámetro.
106 * \return El valor asociado al parámetro recibido como parémtro. Puede ser NULL.
108 const std::string* getValue(const char* name, const Exception::Mode::_v mode = Exception::Mode::Throw) const throw(RuntimeException);
111 * Obtiene el valor asociado a parámetro recibido como parámetro, que habrá sido obtenido
112 * de la URI mediante el método #decode.
113 * \param name Nombre del parámetro que se desea obtener.
114 * \param mode Modo de actuar en caso de que no se encuentre el parámetro.
115 * \return El valor asociado al parámetro recibido como parémtro. Puede ser NULL.
117 const char* getCStringValue(const char* name, const Exception::Mode::_v mode = Exception::Mode::Throw) const throw(RuntimeException);
120 * Obtiene el valor asociado a parámetro recibido como parámetro, que habrá sido obtenido
121 * de la URI mediante el método #decode.
122 * \param name Nombre del parámetro que se desea obtener.
123 * \param mode Modo de actuar en caso de que no se encuentre el parámetro.
124 * \return El valor asociado al parámetro recibido como parémtro. Puede ser NULL.
126 int getIntegerValue(const char* name, const Exception::Mode::_v mode = Exception::Mode::Throw) const throw(RuntimeException);
129 * Decodifica la URI de la petición enviada como parámetro y la interpreta según
130 * las recomendaciones de WIMS 2.0
132 * \param request Petición HTTP que va a tratar este servidor.
134 void decode(const http::Request& request) throw(RuntimeException);
137 struct SplitCode { enum _v { HierarchyAndParameter, HierarchyItem, Parameters, ParameterAndArgument, Max }; };
139 void decodeHierarchy(const std::string& hierarchy) throw(RuntimeException);
140 void decodeParameters(const std::string& parameters) throw(RuntimeException);
142 const Tokenizer& split(const SplitCode::_v splitZone, const std::string&) throw(RuntimeException);
144 anna::Tokenizer a_tokenizer [SplitCode::Max];