From: <mik...@us...> - 2004-01-01 14:21:14
|
Update of /cvsroot/sharedaemon/sharedaemon-ui-web/src/server/http/manager In directory sc8-pr-cvs1:/tmp/cvs-serv6022/src/server/http/manager Modified Files: HttpProcessor.cpp HttpProcessor.h Added Files: PostMethodProcessor.h PostMethodProcessor.cpp MethodProcessor.h GetMethodProcessor.h HeadMethodProcessor.cpp GetMethodProcessor.cpp HeadMethodProcessor.h Log Message: 01/01/2004 Mikael Barbeaux * Externalized http method processing algorithms. --- NEW FILE: PostMethodProcessor.h --- /* * This file is part of webInterface. * Copyright (C) 2003 Mikael Barbeaux <mik...@us...> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef _POST_METHOD_PROCESSOR_H_ #define _POST_METHOD_PROCESSOR_H_ #include "MethodProcessor.h" /** * Defines a processor for the POST http method. * Implements the MethodProcessor abstract class. */ class PostMethodProcessor : public MethodProcessor { public: /** * Creates a PostMethodProcessor object. */ PostMethodProcessor(); /** * Destructor for PostMethodProcessor. */ ~PostMethodProcessor(); /** * Processes a POST http method. * * @param request * @return HttpResponse* */ virtual HttpResponse *process(HttpRequest& request); }; #endif --- NEW FILE: PostMethodProcessor.cpp --- /* * This file is part of webInterface. * Copyright (C) 2003 Mikael Barbeaux <mik...@us...> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "PostMethodProcessor.h" /** * Creates a PostMethodProcessor object. */ PostMethodProcessor::PostMethodProcessor() : MethodProcessor() { } /** * Destructor for PostMethodProcessor. */ PostMethodProcessor::~PostMethodProcessor() { } /** * Processes a Post http method. */ HttpResponse *PostMethodProcessor::process(HttpRequest& request) { return new HttpResponse(0); } --- NEW FILE: MethodProcessor.h --- /* * This file is part of webInterface. * Copyright (C) 2003 Mikael Barbeaux <mik...@us...> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef _METHOD_PROCESSOR_H_ #define _METHOD_PROCESSOR_H_ #include "../HttpRequest.h" #include "../HttpResponse.h" /** * Defines a generic processor for Http methods. * As this class is abstract, you need to extend * it in a subclass and implement the process * method. */ class MethodProcessor { public: /** * Creates a MethodProcessor object. */ MethodProcessor() {} /** * Destructor for MethodProcessor. */ virtual ~MethodProcessor() {} /** * Process a request to build the response. * * @param request * @return HttpResponse* */ virtual HttpResponse *process(HttpRequest& request) = 0; }; #endif --- NEW FILE: GetMethodProcessor.h --- /* * This file is part of webInterface. * Copyright (C) 2003 Mikael Barbeaux <mik...@us...> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef _GET_METHOD_PROCESSOR_H_ #define _GET_METHOD_PROCESSOR_H_ #include "MethodProcessor.h" /** * Defines a processor for the GET http method. * Implements the MethodProcessor abstract class. */ class GetMethodProcessor : public MethodProcessor { public: /** * Creates a GetMethodProcessor object. */ GetMethodProcessor(); /** * Destructor for GetMethodProcessor. */ ~GetMethodProcessor(); /** * Processes a GET http method. * * @param request * @return HttpResponse* */ virtual HttpResponse *process(HttpRequest& request); }; #endif --- NEW FILE: HeadMethodProcessor.cpp --- /* * This file is part of webInterface. * Copyright (C) 2003 Mikael Barbeaux <mik...@us...> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "HeadMethodProcessor.h" /** * Creates a HeadMethodProcessor object. */ HeadMethodProcessor::HeadMethodProcessor() : MethodProcessor() { } /** * Destructor for HeadMethodProcessor. */ HeadMethodProcessor::~HeadMethodProcessor() { } /** * Processes a Head http method. */ HttpResponse *HeadMethodProcessor::process(HttpRequest& request) { return new HttpResponse(0); } --- NEW FILE: GetMethodProcessor.cpp --- /* * This file is part of webInterface. * Copyright (C) 2003 Mikael Barbeaux <mik...@us...> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "GetMethodProcessor.h" /** * Creates a GetMethodProcessor object. */ GetMethodProcessor::GetMethodProcessor() : MethodProcessor() { } /** * Destructor for GetMethodProcessor. */ GetMethodProcessor::~GetMethodProcessor() { } /** * Processes a GET http method. */ HttpResponse *GetMethodProcessor::process(HttpRequest& request) { return new HttpResponse(0); } --- NEW FILE: HeadMethodProcessor.h --- /* * This file is part of webInterface. * Copyright (C) 2003 Mikael Barbeaux <mik...@us...> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef _HEAD_METHOD_PROCESSOR_H_ #define _HEAD_METHOD_PROCESSOR_H_ #include "MethodProcessor.h" /** * Defines a processor for the HEAD http method. * Implements the MethodProcessor abstract class. */ class HeadMethodProcessor : public MethodProcessor { public: /** * Creates a HeadMethodProcessor object. */ HeadMethodProcessor(); /** * Destructor for HeadMethodProcessor. */ ~HeadMethodProcessor(); /** * Processes a HEAD http method. * * @param request * @return HttpResponse* */ virtual HttpResponse *process(HttpRequest& request); }; #endif Index: HttpProcessor.cpp =================================================================== RCS file: /cvsroot/sharedaemon/sharedaemon-ui-web/src/server/http/manager/HttpProcessor.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- HttpProcessor.cpp 1 Jan 2004 10:44:11 -0000 1.2 +++ HttpProcessor.cpp 1 Jan 2004 14:21:11 -0000 1.3 @@ -20,7 +20,10 @@ #include "HttpProcessor.h" #include "HttpManager.h" #include "../TextWriter.h" - +#include "MethodProcessor.h" +#include "GetMethodProcessor.h" +#include "PostMethodProcessor.h" +#include "HeadMethodProcessor.h" /** * Creates a HttpProcessor with the given id. @@ -68,15 +71,19 @@ * response. */ HttpResponse *response; - if(request.getMethod() == GET) - response = processGet(request, connection); + MethodProcessor *processor; + if(request.getMethod() == GET) + processor = new GetMethodProcessor(); else if(request.getMethod() == POST) - response = processPost(request, connection); + processor = new PostMethodProcessor(); else if(request.getMethod() == HEAD) - response = processHead(request, connection); - else - response = processError(); - + processor = new HeadMethodProcessor(); + else { + processor = 0; + // process an error + } + response = processor->process(request); + delete processor; /** * Now we can send the response to the client. @@ -92,34 +99,3 @@ } } -/** - * Processes a GET method. - */ -HttpResponse *HttpProcessor::processGet(HttpRequest& request, - HttpSocket *client) { - return new HttpResponse(new TextWriter()); -} - -/** - * Processes a POST method. - */ -HttpResponse *HttpProcessor::processPost(HttpRequest& request, - HttpSocket *client) { - return new HttpResponse(new TextWriter()); -} - -/** - * Processes a HEAD method. - */ -HttpResponse *HttpProcessor::processHead(HttpRequest& request, - HttpSocket *client) { - return new HttpResponse(new TextWriter()); -} - -/** - * Process a HTTP error - */ -HttpResponse *HttpProcessor::processError() { - return new HttpResponse(new TextWriter()); -} - Index: HttpProcessor.h =================================================================== RCS file: /cvsroot/sharedaemon/sharedaemon-ui-web/src/server/http/manager/HttpProcessor.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- HttpProcessor.h 1 Jan 2004 10:44:11 -0000 1.2 +++ HttpProcessor.h 1 Jan 2004 14:21:11 -0000 1.3 @@ -38,42 +38,6 @@ // identifiant for this thread unsigned int id; - - /** - * Processes a GET method. - * - * @param request - * @param client - * @return HttpResponse* - */ - HttpResponse *processGet(HttpRequest& request, - HttpSocket *client); - - /** - * Processes a POST method. - * - * @param request - * @param client - * @return HttpResponse* - */ - HttpResponse *processPost(HttpRequest& request, - HttpSocket *client); - - /** - * Processes a HEAD method. - * - * @param request - * @param client - * @return HttpResponse* - */ - HttpResponse *processHead(HttpRequest& request, - HttpSocket *client); - - /** - * Process a HTTP error - */ - HttpResponse *processError(); - public: |