00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #define ULXR_NEED_EXPORTS
00033 #include <ulxmlrpcpp/ulxmlrpcpp.h>
00034
00035 #include <ulxmlrpcpp/ulxr_wbxmlparse.h>
00036 #include <ulxmlrpcpp/ulxr_except.h>
00037 #include <ulxmlrpcpp/ulxr_htmlform_handler.h>
00038
00039
00040 namespace ulxr {
00041
00042
00043 #define MIB_Enum_UTF8 (char) 106
00044 #define MIB_Enum_LATIN1 (char) 4
00045
00046
00047
00048
00049
00050
00051 ULXR_API_IMPL(const char)
00052 WbXmlParser::wbxml_START_SEQ_STR[] = {
00053 0x01,
00054 0x01,
00055 #ifdef ULXR_UNICODE
00056 MIB_Enum_UTF8,
00057 #else
00058 MIB_Enum_LATIN1,
00059 #endif
00060 0x00
00061 };
00062
00063 const unsigned WbXmlParser::wbxml_START_SEQ_LEN = 4;
00064
00065 enum WbStates
00066 {
00067 stNone,
00068 stVersion,
00069 stPubId,
00070 stCharset,
00071 stStrTableLen,
00072 stBody,
00073
00074 stStr_I
00075 };
00076
00077
00079
00080
00081 ULXR_API_IMPL0 WbXmlParser::WbXmlState::WbXmlState(unsigned in_state)
00082 {
00083 current_str = "";
00084 state = in_state;
00085 }
00086
00087
00089
00090
00091 ULXR_API_IMPL0 WbXmlParser::WbXmlParser()
00092 : XmlParserBase()
00093 {
00094 init();
00095 }
00096
00097
00098 ULXR_API_IMPL(void) WbXmlParser::init()
00099 {
00100 lastErrorCode = 0;
00101 tag_count = 0;
00102 wbxmlstates.push(stNone);
00103 }
00104
00105
00106 ULXR_API_IMPL0 WbXmlParser::~WbXmlParser()
00107 {
00108 }
00109
00110
00111 ULXR_API_IMPL(unsigned) WbXmlParser::getErrorCode() const
00112 {
00113 return lastErrorCode;
00114 }
00115
00116
00117
00118 ULXR_API_IMPL(int) WbXmlParser::parse(const char* buffer, int len, int isFinal)
00119 {
00120 while(len > 0)
00121 {
00122 unsigned c = *buffer;
00123 ++buffer;
00124 --len;
00125 ULXR_TRACE((ULXR_PCHAR("wb parse: "))+HtmlFormHandler::makeHexNumber(c));
00126 ULXR_TRACE((ULXR_PCHAR("state: "))+HtmlFormHandler::makeNumber(wbxmlstates.top().state));
00127
00128 switch(wbxmlstates.top().state)
00129 {
00130 case stNone:
00131 wb_version = c;
00132 ULXR_TRACE((ULXR_PCHAR("version: "))+HtmlFormHandler::makeHexNumber(c));
00133 wbxmlstates.top().state = stPubId;
00134 break;
00135
00136 case stPubId:
00137 wb_pubId = c;
00138 ULXR_TRACE((ULXR_PCHAR("pub id: "))+HtmlFormHandler::makeHexNumber(c));
00139 wbxmlstates.top().state = stCharset;
00140 break;
00141
00142 case stCharset:
00143 wb_charset = c;
00144 ULXR_TRACE(ULXR_PCHAR("char set: ")+HtmlFormHandler::makeHexNumber(c));
00145 wbxmlstates.top().state = stStrTableLen;
00146 break;
00147
00148 case stStrTableLen:
00149 ULXR_TRACE(ULXR_PCHAR("str table len: "));
00150 wbxmlstates.top().state = stBody;
00151 break;
00152
00153 case stStr_I:
00154 if (c == 0)
00155 {
00156 charData(wbxmlstates.top().current_str);
00157 wbxmlstates.pop();
00158 }
00159 else
00160 wbxmlstates.top().current_str += (char) c;
00161 break;
00162
00163 case stBody:
00164 switch (c)
00165 {
00166 case wbxml_STR_I:
00167 ULXR_TRACE(ULXR_PCHAR("start inline string"));
00168 wbxmlstates.push(stStr_I);
00169 break;
00170
00171 case wbxml_END:
00172 ULXR_TRACE(ULXR_PCHAR("end element"));
00173 endElement();
00174 tag_count--;
00175 break;
00176
00177 default:
00178 {
00179 ULXR_TRACE(ULXR_PCHAR("start element: ")+HtmlFormHandler::makeHexNumber(c));
00180 tag_count++;
00181 Attributes atts;
00182 startElement(c, atts);
00183 }
00184 }
00185 break;
00186 }
00187 }
00188
00189 if (isFinal && tag_count != 0)
00190 throw XmlException(NotWellformedError,
00191 ulxr_i18n(ULXR_PCHAR("Problem while parsing wbxml structure")),
00192 getCurrentLineNumber(),
00193 ulxr_i18n(ULXR_PCHAR("Opening and closing tags are not equal")));
00194
00195 return true;
00196 }
00197
00198
00199 ULXR_API_IMPL(CppString) WbXmlParser::getErrorString(unsigned ) const
00200 {
00201 return ULXR_PCHAR("");
00202 }
00203
00204
00205 ULXR_API_IMPL(int) WbXmlParser::getCurrentLineNumber() const
00206 {
00207 return tag_count;
00208 }
00209
00210
00211 ULXR_API_IMPL(int) WbXmlParser::mapToFaultCode(int xpatcode) const
00212 {
00213 return xpatcode;
00214 }
00215
00216
00217 ULXR_API_IMPL(void) WbXmlParser::charData(const std::string &s)
00218 {
00219 ULXR_TRACE(ULXR_PCHAR("WbXmlParser::charData()")
00220 << ULXR_PCHAR("\n s: >>")
00221 << ULXR_GET_STRING(s)
00222 << ULXR_PCHAR("<<")
00223 );
00224 states.top()->appendCharData(s.data(), s.length());
00225 ULXR_TRACE(ULXR_PCHAR("WbXmlParser::charData() finished"));
00226 }
00227
00228
00229 ULXR_API_IMPL(void)
00230 WbXmlParser::startElement(unsigned token, const Attributes &attr)
00231 {
00232 if (!testStartElement(token, attr))
00233 WbXmlParser::testStartElement(token, attr);
00234 }
00235
00236
00237 ULXR_API_IMPL(bool) WbXmlParser::testStartElement(unsigned token, const Attributes &)
00238 {
00239 throw XmlException(NotWellformedError,
00240 ulxr_i18n(ULXR_PCHAR("Problem while parsing wbxml structure")),
00241 getCurrentLineNumber(),
00242 ulxr_i18n(ULXR_PCHAR("unexpected opening token: "))+HtmlFormHandler::makeHexNumber(token));
00243 }
00244
00245
00246 ULXR_API_IMPL(bool) WbXmlParser::testEndElement()
00247 {
00248 throw XmlException(NotWellformedError,
00249 ulxr_i18n(ULXR_PCHAR("Problem while parsing wbxml structure")),
00250 getCurrentLineNumber(),
00251 ulxr_i18n(ULXR_PCHAR("unexpected closing token")));
00252 }
00253
00254
00255 }
00256
00257
00258
00259
00260