source: sources/src/rpcXmlResponse.cc @ 1439:b23bfdd8a935

Revision 1439:b23bfdd8a935, 4.2 KB checked in by niam, 2 years ago (diff)

change contact info

Line 
1/***************************************************************************
2 *            rpcXmlResponse.cc
3 *
4 *  Wed Apr 09 2008
5 *  Copyright  2008  Dmytro Milinevskyy
6 *  milinevskyy@gmail.com
7 ****************************************************************************/
8
9/*
10 *  This program is free software; you can redistribute it and/or modify
11 *  it under the terms of the GNU Lesser General Public License version 2.1 as published by
12 *  the Free Software Foundation;
13 *
14 *  This program is distributed in the hope that it will be useful,
15 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 *  GNU Library General Public License for more details.
18 *
19 *  You should have received a copy of the GNU Lesser General Public License
20 *  along with this program; if not, write to the Free Software
21 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 */
23
24/**
25 * vim indentation settings
26 * set tabstop=4
27 * set shiftwidth=4
28 */
29
30#include <libdodo/directives.h>
31
32#include <libdodo/rpcXmlResponse.h>
33#include <libdodo/types.h>
34#include <libdodo/dataFormatXmlNode.h>
35#include <libdodo/toolsString.h>
36#include <libdodo/rpcResponse.h>
37#include <libdodo/rpcValue.h>
38#include <libdodo/rpcXmlValue.h>
39
40using namespace dodo::rpc::xml;
41
42dodo::rpc::response
43response::xmlToResponse(dodo::data::format::xml::node &node)
44{
45    dodoMap<dodo::string, dodoArray<dodo::data::format::xml::node>, dodoMapStringCompare>::iterator i = node.nodeChildren.begin();
46    if (i == node.nodeChildren.end())
47        return rpc::response();
48
49    rpc::response resp;
50
51    if (tools::string::iequal(i->first, "fault")) {
52        resp.succ = false;
53
54        dodoArray<dodo::data::format::xml::node> &arr0 = i->second;
55        if (arr0.size() > 0) {
56            dodoArray<dodo::data::format::xml::node> &arr1 = arr0[0].nodeChildren["value"];
57            if (arr1.size() > 0)
58                resp.rValues.assign(1, value::xmlToValue(arr1[0]));
59        }
60    } else {
61        if (tools::string::iequal(i->first, "params")) {
62            resp.succ = true;
63
64            dodoArray<dodo::data::format::xml::node> &arr0 = i->second;
65            if (arr0.size() == 0)
66                return resp;
67
68            dodoArray<dodo::data::format::xml::node> &nodeArray = arr0[0].nodeChildren["param"];
69
70            dodoArray<dodo::data::format::xml::node>::iterator o = nodeArray.begin(), p = nodeArray.end();
71            for (; o != p; ++o) {
72                dodoArray<dodo::data::format::xml::node> &arr1 = o->nodeChildren["value"];
73                if (arr1.size() > 0)
74                    resp.rValues.push_back(value::xmlToValue(arr1[0]));
75            }
76        }
77    }
78
79    return resp;
80}
81
82//-------------------------------------------------------------------
83
84dodo::data::format::xml::node
85response::responseToXml(const rpc::response &data)
86{
87    dodoArray<dodo::data::format::xml::node> nodeArr;
88
89    dodo::data::format::xml::node resp;
90    resp.name = "methodResponse";
91
92    if (data.succ) {
93        dodo::data::format::xml::node params;
94        params.name = "params";
95
96        dodo::data::format::xml::node param;
97        param.name = "param";
98
99        dodoArray<dodo::data::format::xml::node> subNodeArr;
100
101        dodoArray<rpc::value>::const_iterator i = data.rValues.begin(), j = data.rValues.end();
102        for (; i != j; ++i) {
103            param.nodeChildren.clear();
104
105            nodeArr.assign(1, value::valueToXml(*i));
106            param.nodeChildren.insert(std::make_pair("node", nodeArr));
107
108            subNodeArr.push_back(param);
109        }
110        params.nodeChildren.insert(std::make_pair("param", subNodeArr));
111
112        nodeArr.assign(1, params);
113        resp.nodeChildren.insert(std::make_pair(params.name, nodeArr));
114    } else {
115        dodo::data::format::xml::node fault;
116        fault.name = "fault";
117
118        dodoArray<rpc::value>::const_iterator i = data.rValues.begin();
119        if (i != data.rValues.end()) {
120            nodeArr.assign(1, value::valueToXml(*i));
121            fault.nodeChildren.insert(std::make_pair("node", nodeArr));
122        }
123
124        nodeArr.assign(1, fault);
125        resp.nodeChildren.insert(std::make_pair(fault.name, nodeArr));
126    }
127
128    return resp;
129}
130
131//-------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.