ulxr_callparse.cpp

Go to the documentation of this file.
00001 /**************************************************************************
00002                ulxr_callparse.cpp  -  parse xml-rpc method call
00003                              -------------------
00004     begin                : Wed Mar 13 2002
00005     copyright            : (C) 2002-2007 by Ewald Arnold
00006     email                : ulxmlrpcpp@ewald-arnold.de
00007 
00008     $Id: ulxr_callparse.cpp 940 2006-12-30 18:22:05Z 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 //#define ULXR_SHOW_XML
00035 
00036 #define ULXR_NEED_EXPORTS
00037 #include <ulxmlrpcpp/ulxmlrpcpp.h>  // always first header
00038 
00039 #include <ulxmlrpcpp/ulxr_callparse.h>
00040 #include <ulxmlrpcpp/ulxr_except.h>
00041 
00042 
00043 namespace ulxr {
00044 
00045 
00046 ULXR_API_IMPL(void) MethodCallParser::startElement(const XML_Char* name,
00047                                                 const XML_Char** atts)
00048 {
00049   if (!testStartElement(name, atts))
00050     ValueParser::testStartElement(name, atts);
00051 }
00052 
00053 
00054 ULXR_API_IMPL(bool)
00055   MethodCallParser::testStartElement(const XML_Char* name,
00056                                      const XML_Char** /*atts*/)
00057 {
00058   ULXR_TRACE(ULXR_PCHAR("MethodCallParser::testStartElement(const XML_Char*, const char**)")
00059              << ULXR_PCHAR("\n  name: ")
00060              << ULXR_GET_STRING(name)
00061             );
00062 
00063   switch(states.top()->getParserState() )
00064   {
00065     case eNone:
00066       if (strcmp(name, "methodCall") == 0)
00067       {
00068         setComplete(false);
00069         states.push(new ValueState(eMethodCall));
00070       }
00071       else
00072         return false;
00073     break;
00074 
00075     case eMethodCall:
00076       if (strcmp(name, "methodName") == 0)
00077         states.push(new ValueState(eMethodName));
00078 
00079       else if (strcmp(name, "params") == 0)
00080         states.push(new ValueState(eParams));
00081 
00082       else
00083         return false;
00084     break;
00085 
00086     case eParams:
00087       if (strcmp(name, "param") == 0)
00088         states.push(new ValueState(eParam));
00089       else
00090         return false;
00091     break;
00092 
00093     case eParam:
00094       if(strcmp(name, "value") == 0)
00095         states.push(new ValueState(eValue));
00096       else
00097         return false;
00098     break;
00099 
00100     default:
00101         return false;
00102   }
00103 
00104   return true;
00105 }
00106 
00107 
00108 ULXR_API_IMPL(void) MethodCallParser::endElement(const XML_Char *name)
00109 {
00110   if (!testEndElement(name))
00111     ValueParser::testEndElement(name);
00112 }
00113 
00114 
00115 ULXR_API_IMPL(bool) MethodCallParser::testEndElement(const XML_Char *name)
00116 {
00117   ULXR_TRACE(ULXR_PCHAR("MethodCallParser::testEndElement(const XML_Char*)"));
00118 
00119   if (states.size() <= 1)
00120     throw RuntimeException(ApplicationError, ulxr_i18n(ULXR_PCHAR("abnormal program behaviour: MethodCallParser::testEndElement() had no states left")));
00121 
00122   ValueState *curr = getTopValueState();
00123   states.pop();
00124 
00125 //   ULXR_TRACE(ULXR_PCHAR("\n  current data: <")
00126 //              << curr->getCharData() << ULXR_PCHAR(">"));
00127 
00128   switch(curr->getParserState() )
00129   {
00130     case eMethodName:
00131       assertEndElement(name, "methodName");
00132       methodcall.setMethodName(curr->getCharData());
00133     break;
00134 
00135     case eMethodCall:
00136       assertEndElement(name, "methodCall");
00137       setComplete(true);
00138     break;
00139 
00140     case eParams:
00141       assertEndElement(name, "params");
00142     break;
00143 
00144     case eParam:
00145       assertEndElement(name, "param");
00146       if (curr->getValue() != 0)
00147         methodcall.addParam(*curr->getValue());
00148       delete curr->getValue();
00149     break;
00150 
00151     default:
00152       states.push(curr);  // put back, someone else will process
00153       return false;
00154   }
00155   delete curr;
00156   return true;
00157 }
00158 
00159 
00160 }  // namespace ulxr
00161 

Generated on Sun Aug 19 20:08:57 2007 for ulxmlrpcpp by  doxygen 1.5.1