1 /* Copyright (C) 2000-2015 Lavtech.com corp. All rights reserved. 2 3 This program is free software; you can redistribute it and/or modify 4 it under the terms of the GNU General Public License as published by 5 the Free Software Foundation; either version 2 of the License, or 6 (at your option) any later version. 7 8 This program is distributed in the hope that it will be useful, 9 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 GNU General Public License for more details. 12 13 You should have received a copy of the GNU General Public License 14 along with this program; if not, write to the Free Software 15 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 */ 17 18 #ifndef _UDM_PARSE_XML_H 19 #define _UDM_PARSE_XML_H 20 21 #include "udm_lex.h" 22 23 #define UDM_XML_SKIP_TEXT_NORMALIZATION 1 24 25 struct xml_stack_st; 26 27 typedef struct xml_handler_st 28 { 29 udm_rc_t (*enter_action)(struct xml_stack_st *st, const char *val, size_t len); 30 udm_rc_t (*value_action)(struct xml_stack_st *st, const char *val, size_t len); 31 udm_rc_t (*leave_action)(struct xml_stack_st *st, const char *val, size_t len); 32 } UDM_XML_HANDLER; 33 34 35 typedef struct xml_stack_st 36 { 37 char errstr[128]; 38 char attr[128]; 39 char *attrend; 40 UDM_LEX_SCANNER scanner; 41 udm_bool_t xmldecl; /* If in XMLDecl rather than in the document body */ 42 int flags; 43 void *user_data; 44 UDM_XML_HANDLER handler; 45 } UDM_XML_PARSER; 46 47 48 #define UdmXMLParserLastTokenType(p) (p)->scanner.token.type 49 #define UdmXMLParserLastToken(p) (&(p)->scanner.token) 50 #define UdmXMLParserLastStrToken(p) (&(p)->scanner.token.token) 51 52 53 void UdmXMLParserCreate(UDM_XML_PARSER *p); 54 void UdmXMLParserFree(UDM_XML_PARSER *p); 55 void UdmXMLSetValueHandler(UDM_XML_PARSER *p, udm_rc_t (*action)(UDM_XML_PARSER *p, const char *s, size_t l)); 56 void UdmXMLSetEnterHandler(UDM_XML_PARSER *p, udm_rc_t (*action)(UDM_XML_PARSER *p, const char *s, size_t l)); 57 void UdmXMLSetLeaveHandler(UDM_XML_PARSER *p, udm_rc_t (*action)(UDM_XML_PARSER *p, const char *s, size_t l)); 58 void UdmXMLSetHandler(UDM_XML_PARSER *p, const UDM_XML_HANDLER *handler); 59 void UdmXMLSetUserData(UDM_XML_PARSER *p, void *user_data); 60 const char *UdmXMLErrorString (UDM_XML_PARSER *p); 61 size_t UdmXMLErrorPos(UDM_XML_PARSER *p); 62 size_t UdmXMLErrorLineno(UDM_XML_PARSER *p); 63 udm_rc_t UdmXMLParserExec(UDM_XML_PARSER *p, const char *str, size_t len); 64 65 udm_rc_t UdmXMLParse(UDM_AGENT*, UDM_DOCUMENT*); 66 67 #endif 68