responder.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009 by Dr. Marc Boris Duerner
3  * Copyright (C) 2009 by Tommi Meakitalo
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * As a special exception, you may use this file as part of a free
11  * software library without restriction. Specifically, if other files
12  * instantiate templates or use macros or inline functions from this
13  * file, or you compile this file and link it with other files to
14  * produce an executable, this file does not by itself cause the
15  * resulting executable to be covered by the GNU General Public
16  * License. This exception does not however invalidate any other
17  * reasons why the executable file might be covered by the GNU Library
18  * General Public License.
19  *
20  * This library is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23  * Lesser General Public License for more details.
24  *
25  * You should have received a copy of the GNU Lesser General Public
26  * License along with this library; if not, write to the Free Software
27  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
28  */
29 #ifndef cxxtools_xmlrpc_Responder_h
30 #define cxxtools_xmlrpc_Responder_h
31 
32 #include <cxxtools/xmlrpc/api.h>
36 #include <cxxtools/xml/xmlreader.h>
37 #include <cxxtools/xml/xmlwriter.h>
40 #include <cxxtools/textstream.h>
41 
42 namespace cxxtools
43 {
44 
45 class ServiceProcedure;
46 class IComposer;
47 class IDecomposer;
48 
49 namespace xmlrpc
50 {
51 
52 class Service;
53 
55 {
56  enum State
57  {
58  OnBegin,
59  OnMethodCallBegin,
60  OnMethodNameBegin,
61  OnMethodName,
62  OnMethodNameEnd,
63  OnParams,
64  OnParam,
65  OnParamsEnd,
66  OnMethodCallEnd
67  };
68 
69  public:
70  explicit XmlRpcResponder(Service& service);
71 
72  ~XmlRpcResponder();
73 
74  void beginRequest(std::istream& in, http::Request& request);
75 
76  std::size_t readBody(std::istream& is);
77 
78  void replyError(std::ostream& os, http::Request& request,
79  http::Reply& reply, const std::exception& ex);
80 
81  void reply(std::ostream& os, http::Request& request, http::Reply& reply);
82 
83  protected:
84  void advance(const cxxtools::xml::Node& node);
85 
86  private:
87  State _state;
88  TextIStream _ts;
89  xml::XmlReader _reader;
90  xml::XmlWriter _writer;
91  Scanner _scanner;
92  Formatter _formatter;
93  DeserializerBase _deserializer;
94  Service* _service;
95  ServiceProcedure* _proc;
96  IComposer** _args;
97  RemoteException _fault;
98 };
99 
100 }
101 
102 }
103 
104 #endif