1 /* libcomps - C alternative to yum.comps library
2  * Copyright (C) 2013 Jindrich Luza
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to  Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
17  * USA
18  */
19 
20 #ifndef COMPS_PARSE_H
21 #define COMPS_PARSE_H
22 #include <stdio.h>
23 #include <signal.h>
24 
25 #include "comps_hslist.h"
26 #include "comps_obj.h"
27 #include "comps_doc.h"
28 #include "comps_types.h"
29 #include "comps_log.h"
30 #include "comps_default.h"
31 
32 #include <expat.h>
33 #include <libxml/parser.h>
34 
35 typedef struct COMPS_Parsed {
36     COMPS_HSList *elem_stack;
37     COMPS_Doc *comps_doc;
38     COMPS_HSList *text_buffer;
39     unsigned int text_buffer_len;
40     char **text_buffer_pt;
41     char *tmp_buffer;
42     COMPS_Log *log;
43     char fatal_error;
44     XML_Parser parser;
45     const char *enc;
46     COMPS_DefaultsOptions *def_options;
47 
48     COMPS_Str *doctype_name;
49     COMPS_Str *doctype_sysid;
50     COMPS_Str *doctype_pubid;
51 } COMPS_Parsed;
52 
53 COMPS_Parsed* comps_parse_parsed_create();
54 void comps_parse_parsed_reinit(COMPS_Parsed *parsed);
55 void comps_parse_parsed_destroy(COMPS_Parsed *parsed);
56 unsigned comps_parse_parsed_init(COMPS_Parsed * parsed, const char * encoding,
57                                  char log_stdout);
58 
59 unsigned __comps_is_whitespace_only(const char * s, int len);
60 
61 void comps_parse_end_elem_handler(void *userData, const XML_Char *s);
62 void comps_parse_def_handler(void *userData, const XML_Char *s, int len);
63 void comps_parse_start_elem_handler(void *userData,
64                               const XML_Char *s,
65                               const XML_Char **attrs);
66 void comps_parse_char_data_handler(void *userData,
67                             const XML_Char *s,
68                             int len);
69 void comps_parse_start_doctype(void *userData,
70                                const XML_Char *doctypeName,
71                                const XML_Char *sysid,
72                                const XML_Char *pubid,
73                                int standalone);
74 
75 signed char comps_parse_file(COMPS_Parsed *parsed, FILE *f,
76                              COMPS_DefaultsOptions *options);
77 signed char comps_parse_str(COMPS_Parsed *parsed, char *str,
78                             COMPS_DefaultsOptions *options);
79 
80 unsigned comps_parse_init_parser(XML_Parser *p);
81 void comps_parse_parsed_destroy(COMPS_Parsed *parsed);
82 int comps_parse_validate_dtd(char *filename, char *dtd_file);
83 
84 #endif
85