1 // vim: set noexpandtab tabstop=4 shiftwidth=4:
2 //----------------------------------------------------------------------------
4 //----------------------------------------------------------------------------
5 // This file is part of PlaQui.
7 // PlaQui is free software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the Free Software
9 // Foundation; either version 2 of the License, or (at your option) any later
12 // PlaQui is distributed in the hope that it will be useful, but WITHOUT ANY
13 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 // You should have received a copy of the GNU General Public License along
18 // with PlaQui; if not, write to the Free Software Foundation, Inc., 59 Temple
19 // Place, Suite 330, Boston, MA 02111-1307 USA
20 //----------------------------------------------------------------------------
21 // Creado: sáb nov 8 17:12:10 ART 2003
22 // Autores: Leandro Lucarella <llucare@fi.uba.ar>
23 //----------------------------------------------------------------------------
28 #include "plaqui/server/command.h"
29 #include "plaqui/server/string.h"
31 //#include <exception>
42 Command::~Command(void) {
44 cerr << __FILE__ << "(" << __LINE__ << ")"
45 << ": destructor." << endl;
49 Command::Command(const string& _target, const string& _command) {
51 cerr << __FILE__ << "(" << __LINE__ << ")"
52 << ": target = " << target << " | "
53 << "command = " << command << endl;
56 set_command(_command);
59 void Command::build(void) {
60 uri = string("/") + target;
61 if (command.length()) {
64 uri += '/' + String::join(args, "/");
68 cerr << __FILE__ << "(" << __LINE__ << ")"
69 << ": build() = " << uri << endl;
73 void Command::set_target(const std::string& _target) {
78 const std::string& Command::get_target(void) const {
82 void Command::set_command(const std::string& _command) {
87 const std::string& Command::get_command(void) const {
91 void Command::set_args(const Command::Arguments& _args) {
96 const Command::Arguments& Command::get_args(void) const {
100 void Command::add_arg(const std::string& arg) {
105 void Command::add_arg(const unsigned& arg) {
107 cerr << __FILE__ << "(" << __LINE__ << ")"
108 << ": add_arg(arg = " << arg << ") = "
109 << String().from(arg) << endl;
111 args.push_back(String().from(arg));
115 istream& operator>>(istream& is, Command& command)
116 throw(HTTPError, sockerr, ios::failure) {
118 cerr << __FILE__ << "(" << __LINE__ << ")"
119 << ": operator>>()" << endl;
121 // Obtengo datos del Request HTTP.
122 is >> static_cast<HTTPRequest&>(command);
123 // Segun la URI, obtengo los fragmentos del comando.
124 String uri(command.uri);
125 command.args = uri.split('/');
126 // Borro el primero porque debe estar vacio porque la URI empieza con /.
127 command.args.erase(command.args.begin());
128 if (command.args.size() > 0) {
129 command.target = command.args[0];
130 command.args.erase(command.args.begin());
134 if (command.args.size() > 0) {
135 command.command = command.args[0];
136 command.args.erase(command.args.begin());
138 command.command = "";
143 ostream& operator<<(ostream& os, const Command& command) throw (sockerr) {
145 cerr << __FILE__ << "(" << __LINE__ << ")"
146 << ": operator<<()" << endl;
148 // Manda el request HTTP con la URI que representa el comando.
149 os << static_cast<const HTTPRequest&>(command);
153 } // namespace Server
155 } // namespace PlaQui