00001 /*************************************************************************** 00002 ulxr_response.cpp - create xml-rpc response 00003 ------------------- 00004 begin : Sun Mar 10 2002 00005 copyright : (C) 2002-2007 by Ewald Arnold 00006 email : ulxmlrpcpp@ewald-arnold.de 00007 00008 $Id: ulxr_response.cpp 1026 2007-07-25 07:48:09Z ewald-arnold $ 00009 00010 ***************************************************************************/ 00011 00012 /************************************************************************** 00013 * 00014 * This program is free software; you can redistribute it and/or modify 00015 * it under the terms of the GNU Lesser General Public License as 00016 * published by the Free Software Foundation; either version 2 of the License, 00017 * or (at your option) any later version. 00018 * 00019 * This program is distributed in the hope that it will be useful, 00020 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00021 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00022 * GNU General Public License for more details. 00023 * 00024 * You should have received a copy of the GNU Lesser General Public License 00025 * along with this program; if not, write to the Free Software 00026 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00027 * 00028 ***************************************************************************/ 00029 00030 //#define ULXR_SHOW_TRACE 00031 //#define ULXR_DEBUG_OUTPUT 00032 //#define ULXR_SHOW_READ 00033 //#define ULXR_SHOW_WRITE 00034 00035 #define ULXR_NEED_EXPORTS 00036 #include <ulxmlrpcpp/ulxmlrpcpp.h> // always first header 00037 00038 #include <ulxmlrpcpp/ulxr_response.h> 00039 #include <ulxmlrpcpp/ulxr_responseparse_wb.h> 00040 #include <ulxmlrpcpp/ulxr_wbxmlparse.h> 00041 #include <ulxmlrpcpp/ulxr_value.h> 00042 00043 00044 namespace ulxr { 00045 00046 00047 ULXR_API_IMPL0 MethodResponse::MethodResponse() 00048 : wasOk(true) 00049 { 00050 } 00051 00052 00053 ULXR_API_IMPL0 MethodResponse::MethodResponse (const Void & /*val*/) 00054 : wasOk(true) 00055 { 00056 } 00057 00058 00059 ULXR_API_IMPL0 MethodResponse::MethodResponse(int fval, const CppString &fstr) 00060 00061 { 00062 setFault(fval, fstr); 00063 } 00064 00065 00066 ULXR_API_IMPL0 MethodResponse::MethodResponse (const Value &val) 00067 { 00068 setResult (val); 00069 } 00070 00071 00072 ULXR_API_IMPL0 MethodResponse::~MethodResponse() 00073 { 00074 } 00075 00076 00077 ULXR_API_IMPL(bool) MethodResponse::isOK() const 00078 { 00079 return wasOk; 00080 } 00081 00082 00083 ULXR_API_IMPL(void) MethodResponse::setFault(int fval, const CppString &fstr) 00084 { 00085 ULXR_TRACE(ULXR_PCHAR("setFault")); 00086 wasOk = false; 00087 Struct st; 00088 st.addMember(ULXR_PCHAR("faultCode"), Integer(fval)); 00089 st.addMember(ULXR_PCHAR("faultString"), RpcString(fstr)); 00090 respval = st; 00091 } 00092 00093 00094 ULXR_API_IMPL(void) MethodResponse::setResult (const Value &val) 00095 { 00096 ULXR_TRACE(ULXR_PCHAR("setResult")); 00097 wasOk = true; 00098 respval = val; 00099 } 00100 00101 00102 ULXR_API_IMPL(const Value&) MethodResponse::getResult() const 00103 { 00104 return respval; 00105 } 00106 00107 00108 ULXR_API_IMPL(CppString) MethodResponse::getSignature(bool deep) const 00109 { 00110 return respval.getSignature(deep); 00111 } 00112 00113 00114 ULXR_API_IMPL(CppString) MethodResponse::getXml(int indent) const 00115 { 00116 CppString ind = getXmlIndent(indent); 00117 CppString ind1 = getXmlIndent(indent+1); 00118 CppString ind2 = getXmlIndent(indent+2); 00119 CppString s = ULXR_PCHAR("<?xml version=\"1.0\" encoding=\"utf-8\"?>") + getXmlLinefeed(); 00120 s += ind + ULXR_PCHAR("<methodResponse>") + getXmlLinefeed(); 00121 if (wasOk) 00122 { 00123 s += ind1 + ULXR_PCHAR("<params>") + getXmlLinefeed(); 00124 if (!respval.isVoid()) 00125 { 00126 s += ind2 + ULXR_PCHAR("<param>") + getXmlLinefeed(); 00127 s += respval.getXml(indent+3) + getXmlLinefeed(); 00128 s += ind2 + ULXR_PCHAR("</param>") + getXmlLinefeed(); 00129 } 00130 s += ind1 + ULXR_PCHAR("</params>") + getXmlLinefeed(); 00131 } 00132 else 00133 { 00134 s += ind1 + ULXR_PCHAR("<fault>") + getXmlLinefeed(); 00135 s += respval.getXml(indent+2) + getXmlLinefeed(); 00136 s += ind1 + ULXR_PCHAR("</fault>") + getXmlLinefeed(); 00137 } 00138 s += ind + ULXR_PCHAR("</methodResponse>"); 00139 return s; 00140 } 00141 00142 00143 ULXR_API_IMPL(std::string) MethodResponse::getWbXml() const 00144 { 00145 std::string s; 00146 s.assign(WbXmlParser::wbxml_START_SEQ_STR, WbXmlParser::wbxml_START_SEQ_LEN); 00147 s += MethodResponseParserWb::wbToken_MethodResponse; 00148 if (wasOk) 00149 { 00150 s += MethodResponseParserWb::wbToken_Params; 00151 if (!respval.isVoid()) 00152 { 00153 s += MethodResponseParserWb::wbToken_Param; 00154 s += respval.getWbXml(); 00155 s += WbXmlParser::wbxml_END; 00156 } 00157 s += WbXmlParser::wbxml_END; 00158 } 00159 else 00160 { 00161 s += MethodResponseParserWb::wbToken_Fault; 00162 s += respval.getWbXml(); 00163 s += WbXmlParser::wbxml_END; 00164 } 00165 s += WbXmlParser::wbxml_END; 00166 return s; 00167 } 00168 00169 00170 } // namespace ulxr 00171