static String _xml_decode_tag(XmlParser *parser, const char *tag) { auto newstr = xml_utf8_decode((const XML_Char*)tag, strlen(tag), parser->target_encoding); if (parser->case_folding) { string_to_upper(newstr); } return newstr; }
static char *_xml_decode_tag(XmlParser *parser, const char *tag) { char *newstr; int out_len; newstr = xml_utf8_decode((const XML_Char*)tag, strlen(tag), &out_len, parser->target_encoding); if (parser->case_folding) { newstr = string_to_upper(newstr, out_len); } return newstr; }
static void _xml_xmlchar_zval(const XML_Char *s, int len, const XML_Char *encoding, zval *ret) { if (s == NULL) { ZVAL_FALSE(ret); return; } if (len == 0) { len = _xml_xmlcharlen(s); } ZVAL_STR(ret, xml_utf8_decode(s, len, encoding)); }
static Variant _xml_xmlchar_zval(const XML_Char *s, int len, const XML_Char *encoding) { if (s == NULL) { return false; } if (len == 0) { len = _xml_xmlcharlen(s); } String ret = xml_utf8_decode(s, len, encoding); return ret; }
static Variant _xml_xmlchar_zval(const XML_Char *s, int len, const XML_Char *encoding) { if (s == NULL) { return false; } if (len == 0) { len = _xml_xmlcharlen(s); } int ret_len; char * ret = xml_utf8_decode(s, len, &ret_len, encoding); return String(ret, ret_len, AttachString); }
static zval *_xml_xmlchar_zval(const XML_Char *s, int len, const XML_Char *encoding) { zval *ret; MAKE_STD_ZVAL(ret); if (s == NULL) { ZVAL_FALSE(ret); return ret; } if (len == 0) { len = _xml_xmlcharlen(s); } Z_TYPE_P(ret) = IS_STRING; Z_STRVAL_P(ret) = xml_utf8_decode(s, len, &Z_STRLEN_P(ret), encoding); return ret; }
void _xml_characterDataHandler(void *userData, const XML_Char *s, int len) { auto parser = getParserFromToken(userData); if (parser) { Variant retval; Array args = Array::Create(); if (parser->characterDataHandler.toBoolean()) { args.append(Variant(parser)); args.append(_xml_xmlchar_zval(s, len, parser->target_encoding)); xml_call_handler(parser, parser->characterDataHandler, args); } if (!parser->data.isNull()) { int i; int doprint = 0; String decoded_value; int decoded_len; decoded_value = xml_utf8_decode(s,len, parser->target_encoding); decoded_len = decoded_value.size(); for (i = 0; i < decoded_len; i++) { switch (decoded_value[i]) { case ' ': case '\t': case '\n': default: doprint = 1; break; } if (doprint) { break; } } if (doprint || (! parser->skipwhite)) { if (parser->lastwasopen) { String myval; // check if value exists, if yes append to that if (parser->ctag.toArrRef().exists(s_value)) { myval = tvCastToString(parser->ctag.toArray().rvalAt(s_value).tv()); myval += decoded_value; parser->ctag.toArrRef().set(s_value, myval); } else { parser->ctag.toArrRef().set( s_value, decoded_value ); } } else { Array tag; String myval; String mytype; auto curtag = parser->data.toArrRef().pop(); SCOPE_EXIT { try { parser->data.toArrRef().append(curtag); } catch (...) {} }; if (curtag.toArrRef().exists(s_type)) { mytype = tvCastToString(curtag.toArrRef().rvalAt(s_type).tv()); if (!strcmp(mytype.data(), "cdata") && curtag.toArrRef().exists(s_value)) { myval = tvCastToString(curtag.toArrRef().rvalAt(s_value).tv()); myval += decoded_value; curtag.toArrRef().set(s_value, myval); return; } } if (parser->level <= XML_MAXLEVEL && parser->level > 0) { tag = Array::Create(); _xml_add_to_info(parser, parser->ltags[parser->level-1] + parser->toffset); tag.set(s_tag, String(parser->ltags[parser->level-1] + parser->toffset, CopyString)); tag.set(s_value, decoded_value); tag.set(s_type, s_cdata); tag.set(s_level, parser->level); parser->data.toArrRef().append(tag); } else if (parser->level == (XML_MAXLEVEL + 1)) { raise_warning("Maximum depth exceeded - Results truncated"); } } } } }
void _xml_startElementHandler(void *userData, const XML_Char *name, const XML_Char **attributes) { XmlParser *parser = (XmlParser *)userData; const char **attrs = (const char **) attributes; Variant retval; Array args = Array::Create(); if (parser) { parser->level++; char* tag_name = _xml_decode_tag(parser, (const char*)name); if (parser->startElementHandler) { args.append(parser); args.append(_xml_string_zval(tag_name)); args.append(Array::Create()); while (attributes && *attributes) { char* att = _xml_decode_tag(parser, (const char*)attributes[0]); int val_len; char* val = xml_utf8_decode(attributes[1], strlen((const char*)attributes[1]), &val_len, parser->target_encoding); args.lvalAt(2).set(String(att, AttachString), String(val, val_len, AttachString)); attributes += 2; } xml_call_handler(parser, parser->startElementHandler, args); } if (!parser->data.isNull()) { Array tag, atr; int atcnt = 0; tag = Array::Create(); atr = Array::Create(); _xml_add_to_info(parser,((char *) tag_name) + parser->toffset); tag.set(s_tag,String(((char *)tag_name)+parser->toffset,CopyString)); tag.set(s_type, s_open); tag.set(s_level, parser->level); parser->ltags[parser->level-1] = strdup(tag_name); parser->lastwasopen = 1; attributes = (const XML_Char **) attrs; while (attributes && *attributes) { char* att = _xml_decode_tag(parser, (const char*)attributes[0]); int val_len; char* val = xml_utf8_decode(attributes[1], strlen((const char*)attributes[1]), &val_len, parser->target_encoding); atr.set(String(att, AttachString), String(val, val_len, AttachString)); atcnt++; attributes += 2; } if (atcnt) { tag.set(s_attributes,atr); } parser->data.append(tag); parser->ctag.assignRef(parser->data.getArrayData()->endRef()); } free(tag_name); } }
void _xml_characterDataHandler(void *userData, const XML_Char *s, int len) { XmlParser *parser = (XmlParser *)userData; if (parser) { Variant retval; Array args = Array::Create(); if (parser->characterDataHandler) { args.append(parser); args.append(_xml_xmlchar_zval(s, len, parser->target_encoding)); xml_call_handler(parser, parser->characterDataHandler, args); } if (!parser->data.isNull()) { int i; int doprint = 0; char *decoded_value; int decoded_len; decoded_value = xml_utf8_decode(s,len,&decoded_len, parser->target_encoding); for (i = 0; i < decoded_len; i++) { switch (decoded_value[i]) { case ' ': case '\t': case '\n': continue; default: doprint = 1; break; } if (doprint) { break; } } if (doprint || (! parser->skipwhite)) { if (parser->lastwasopen) { String myval; // check if value exists, if yes append to that if (parser->ctag.toArray().exists(s_value)) { myval = parser->ctag.rvalAt(s_value).toString(); myval += String(decoded_value, decoded_len, AttachString); parser->ctag.set(s_value, myval); } else { parser->ctag.set(s_value, String(decoded_value,decoded_len,AttachString)); } } else { Array tag; Variant curtag; String myval; String mytype; curtag.assignRef(parser->data.getArrayData()->endRef()); if (curtag.toArray().exists(s_type)) { mytype = curtag.rvalAt(s_type).toString(); if (!strcmp(mytype.data(), "cdata") && curtag.toArray().exists(s_value)) { myval = curtag.rvalAt(s_value).toString(); myval += String(decoded_value, decoded_len, AttachString); curtag.set(s_value, myval); return; } } tag = Array::Create(); _xml_add_to_info(parser, parser->ltags[parser->level-1] + parser->toffset); tag.set(s_tag, String(parser->ltags[parser->level-1] + parser->toffset, CopyString)); tag.set(s_value, String(decoded_value, AttachString)); tag.set(s_type, s_cdata); tag.set(s_level, parser->level); parser->data.append(tag); } } else { free(decoded_value); } } } }
void _xml_startElementHandler(void *userData, const XML_Char *name, const XML_Char **attributes) { XmlParser *parser = (XmlParser *)userData; const char **attrs = (const char **) attributes; Variant retval; Array args = Array::Create(); if (parser) { parser->level++; char* tag_name = _xml_decode_tag(parser, (const char*)name); if (parser->startElementHandler.toBoolean()) { args.append(parser); args.append(_xml_string_zval(tag_name)); args.append(Array::Create()); while (attributes && *attributes) { char* att = _xml_decode_tag(parser, (const char*)attributes[0]); int val_len; char* val = xml_utf8_decode(attributes[1], strlen((const char*)attributes[1]), &val_len, parser->target_encoding); args.lvalAt(2).toArrRef().set( String(att, AttachString), String(val, val_len, AttachString) ); attributes += 2; } xml_call_handler(parser, parser->startElementHandler, args); } if (!parser->data.isNull()) { if (parser->level <= XML_MAXLEVEL) { Array tag, atr; int atcnt = 0; tag = Array::Create(); atr = Array::Create(); _xml_add_to_info(parser,((char *) tag_name) + parser->toffset); tag.set(s_tag,String(((char *)tag_name)+parser->toffset,CopyString)); tag.set(s_type, s_open); tag.set(s_level, parser->level); parser->ltags[parser->level-1] = strdup(tag_name); parser->lastwasopen = 1; attributes = (const XML_Char **) attrs; while (attributes && *attributes) { char* att = _xml_decode_tag(parser, (const char*)attributes[0]); int val_len; char* val = xml_utf8_decode(attributes[1], strlen((const char*)attributes[1]), &val_len, parser->target_encoding); atr.set(String(att, AttachString), String(val, val_len, AttachString)); atcnt++; attributes += 2; } if (atcnt) { tag.set(s_attributes,atr); } auto& lval = parser->data.toArrRef().lvalAt(); lval.assignRef(tag); parser->ctag.assignRef(lval); } else if (parser->level == (XML_MAXLEVEL + 1)) { raise_warning("Maximum depth exceeded - Results truncated"); } } free(tag_name); } }