2016-12-02 19:18:50 +00:00
|
|
|
%top {
|
|
|
|
/* Include this before everything else, for various large-file definitions */
|
|
|
|
#include "config.h"
|
2021-10-16 09:33:34 +00:00
|
|
|
#include <wireshark.h>
|
2016-12-02 19:18:50 +00:00
|
|
|
}
|
|
|
|
|
2016-03-31 01:44:01 +00:00
|
|
|
/*
|
|
|
|
* We want a reentrant scanner.
|
|
|
|
*/
|
|
|
|
%option reentrant
|
|
|
|
|
2013-02-10 19:13:07 +00:00
|
|
|
/*
|
|
|
|
* We don't use input, so don't generate code for it.
|
|
|
|
*/
|
|
|
|
%option noinput
|
|
|
|
|
2007-07-30 20:22:37 +00:00
|
|
|
/*
|
|
|
|
* We don't use unput, so don't generate code for it.
|
|
|
|
*/
|
2011-08-11 03:10:11 +00:00
|
|
|
%option nounput
|
2007-07-30 20:22:37 +00:00
|
|
|
|
|
|
|
/*
|
2015-11-05 23:35:04 +00:00
|
|
|
* We don't read interactively from the terminal.
|
2007-07-30 20:22:37 +00:00
|
|
|
*/
|
2005-09-10 17:29:15 +00:00
|
|
|
%option never-interactive
|
|
|
|
|
2015-12-05 03:52:51 +00:00
|
|
|
/*
|
|
|
|
* We want to stop processing when we get to the end of the input.
|
|
|
|
*/
|
|
|
|
%option noyywrap
|
|
|
|
|
2016-03-31 01:44:01 +00:00
|
|
|
/*
|
|
|
|
* The type for the state we keep for a scanner.
|
|
|
|
*/
|
|
|
|
%option extra-type="Dtd_Parse_scanner_state_t *"
|
|
|
|
|
2007-07-30 20:22:37 +00:00
|
|
|
/*
|
|
|
|
* Prefix scanner routines with "Dtd_Parse_" rather than "yy", so this scanner
|
|
|
|
* can coexist with other scanners.
|
|
|
|
*/
|
|
|
|
%option prefix="Dtd_Parse_"
|
|
|
|
|
|
|
|
%option outfile="dtd_parse.c"
|
|
|
|
|
2016-03-31 01:44:01 +00:00
|
|
|
/*
|
|
|
|
* We have to override the memory allocators so that we don't get
|
|
|
|
* "unused argument" warnings from the yyscanner argument (which
|
|
|
|
* we don't use, as we have a global memory allocator).
|
|
|
|
*
|
|
|
|
* We provide, as macros, our own versions of the routines generated by Flex,
|
|
|
|
* which just call malloc()/realloc()/free() (as the Flex versions do),
|
|
|
|
* discarding the extra argument.
|
|
|
|
*/
|
|
|
|
%option noyyalloc
|
|
|
|
%option noyyrealloc
|
|
|
|
%option noyyfree
|
|
|
|
|
2005-09-10 17:29:15 +00:00
|
|
|
%{
|
|
|
|
|
2005-09-12 19:32:35 +00:00
|
|
|
/* dtd_parse.l
|
2011-08-11 03:10:11 +00:00
|
|
|
* an XML dissector for Wireshark
|
2005-09-10 17:29:15 +00:00
|
|
|
* lexical analyzer for DTDs
|
|
|
|
*
|
2008-08-05 21:03:46 +00:00
|
|
|
* Copyright 2004, Luis E. Garcia Ontanon <luis@ontanon.org>
|
2005-09-10 17:29:15 +00:00
|
|
|
*
|
2006-05-21 05:12:17 +00:00
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
2005-09-10 17:29:15 +00:00
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2011-08-11 03:10:11 +00:00
|
|
|
*
|
2005-09-10 17:29:15 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2011-08-11 03:10:11 +00:00
|
|
|
*
|
2005-09-10 17:29:15 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2007-07-30 20:22:37 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2005-09-10 17:29:15 +00:00
|
|
|
*/
|
2011-08-11 03:10:11 +00:00
|
|
|
|
2005-09-10 17:29:15 +00:00
|
|
|
#include <glib.h>
|
|
|
|
#include <string.h>
|
2011-08-11 03:10:11 +00:00
|
|
|
|
2005-09-10 17:29:15 +00:00
|
|
|
#include "dtd.h"
|
|
|
|
#include "dtd_grammar.h"
|
2005-09-12 19:32:35 +00:00
|
|
|
#include "dtd_parse.h"
|
2011-08-11 03:10:11 +00:00
|
|
|
|
2018-02-16 11:15:32 +00:00
|
|
|
/*
|
|
|
|
* Disable diagnostics in the code generated by Flex.
|
|
|
|
*/
|
|
|
|
DIAG_OFF_FLEX
|
2017-08-18 19:11:47 +00:00
|
|
|
|
2005-09-10 17:29:15 +00:00
|
|
|
struct _proto_xmlpi_attr {
|
2013-02-08 09:09:29 +00:00
|
|
|
const gchar* name;
|
2005-09-10 17:29:15 +00:00
|
|
|
void (*act)(gchar*);
|
|
|
|
};
|
|
|
|
|
2016-03-31 01:44:01 +00:00
|
|
|
typedef struct {
|
|
|
|
GString* input_string;
|
|
|
|
size_t offsetx;
|
|
|
|
size_t len;
|
|
|
|
void* pParser;
|
|
|
|
gchar* location;
|
|
|
|
gchar* attr_name;
|
|
|
|
} Dtd_Parse_scanner_state_t;
|
2011-08-11 03:10:11 +00:00
|
|
|
|
2016-03-31 01:44:01 +00:00
|
|
|
static size_t my_yyinput(Dtd_Parse_scanner_state_t *state,char* buff,size_t size);
|
2011-08-11 03:10:11 +00:00
|
|
|
|
2016-03-31 01:44:01 +00:00
|
|
|
static dtd_token_data_t* new_token(gchar*,gchar*);
|
2005-09-10 17:29:15 +00:00
|
|
|
|
|
|
|
static dtd_build_data_t* build_data;
|
2011-08-11 03:10:11 +00:00
|
|
|
|
2017-08-26 08:30:47 +00:00
|
|
|
static void set_proto_name (gchar* val) { g_free(build_data->proto_name); build_data->proto_name = g_strdup(val); }
|
|
|
|
static void set_media_type (gchar* val) { g_free(build_data->media_type); build_data->media_type = g_strdup(val); }
|
|
|
|
static void set_proto_root (gchar* val) { g_free(build_data->proto_root); build_data->proto_root = g_strdup(val); }
|
|
|
|
static void set_description (gchar* val) { g_free(build_data->description); build_data->description = g_strdup(val); }
|
strcasecmp(), strncasecmp(), g_strcasecmp(), and g_strncasecmp() delenda
est. Use g_ascii_strcasecmp() and g_ascii_strncasecmp(), and supply our
own versions if they're missing from GLib (as is the case with GLib
1.x).
In the code to build the list of named fields for Diameter, don't use
g_strdown(); do our own g_ascii_-style upper-case to lower-case mapping
in the hash function and use g_ascii_strcasecmp() in the compare
function.
We do this because there is no guarantee that toupper(), tolower(), and
functions that use them will, for example, map between "I" and "i" in
all locales; in Turkish locales, for example, there are, in both
upper case and lower case, versions of "i" with and without a dot, and
the upper-case version of "i" is "I"-with-a-dot and the lower-case
version of "I" is "i"-without-a-dot. This causes strings that should
match not to match.
This finishes fixing bug 2010 - an earlier checkin prevented the crash
(as there are other ways to produce the same crash, e.g. a bogus
dictionary.xml file), but didn't fix the case-insensitive string matching.
svn path=/trunk/; revision=23623
2007-11-27 18:52:51 +00:00
|
|
|
static void set_recursive (gchar* val) { build_data->recursion = ( g_ascii_strcasecmp(val,"yes") == 0 ) ? TRUE : FALSE; }
|
2005-09-10 17:29:15 +00:00
|
|
|
|
2005-09-20 00:31:53 +00:00
|
|
|
#ifdef DEBUG_DTD_PARSER
|
|
|
|
#define DEBUG_DTD_TOKEN fprintf(stderr,"->%s (%i)%s\n",location,token_type,yytext)
|
|
|
|
#else
|
|
|
|
#define DEBUG_DTD_TOKEN
|
|
|
|
#endif
|
2011-08-11 03:10:11 +00:00
|
|
|
|
2005-09-10 17:29:15 +00:00
|
|
|
#define DTD_PARSE(token_type) \
|
2005-09-20 00:31:53 +00:00
|
|
|
{ DEBUG_DTD_TOKEN; \
|
2016-03-31 01:44:01 +00:00
|
|
|
DtdParse(yyextra->pParser, (token_type), new_token(yytext, yyextra->location), build_data); \
|
2005-09-10 17:29:15 +00:00
|
|
|
if(build_data->error->len > 0) yyterminate(); \
|
|
|
|
}
|
|
|
|
|
2005-09-20 00:31:53 +00:00
|
|
|
|
2016-03-31 01:44:01 +00:00
|
|
|
#define YY_INPUT(buff,result,max_size) ( (result) = my_yyinput(yyextra,(buff),(max_size)) )
|
|
|
|
#define YY_USER_INIT BEGIN DTD;
|
2005-09-10 17:29:15 +00:00
|
|
|
|
2008-04-25 17:40:29 +00:00
|
|
|
/*
|
|
|
|
* Flex (v 2.5.35) uses this symbol to "exclude" unistd.h
|
|
|
|
*/
|
|
|
|
#ifdef _WIN32
|
|
|
|
#define YY_NO_UNISTD_H
|
|
|
|
#endif
|
|
|
|
|
2016-03-31 01:44:01 +00:00
|
|
|
/*
|
|
|
|
* Sleazy hack to suppress compiler warnings in yy_fatal_error().
|
|
|
|
*/
|
|
|
|
#define YY_EXIT_FAILURE ((void)yyscanner, 2)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Macros for the allocators, to discard the extra argument.
|
|
|
|
*/
|
|
|
|
#define Dtd_Parse_alloc(size, yyscanner) (void *)malloc(size)
|
|
|
|
#define Dtd_Parse_realloc(ptr, size, yyscanner) (void *)realloc((char *)(ptr), (size))
|
|
|
|
#define Dtd_Parse_free(ptr, yyscanner) free((char *)ptr)
|
|
|
|
|
2005-09-10 17:29:15 +00:00
|
|
|
%}
|
|
|
|
|
2005-09-17 17:05:46 +00:00
|
|
|
comment_start "<!--"
|
|
|
|
comment_stop "-->"
|
|
|
|
|
2005-09-10 17:29:15 +00:00
|
|
|
start_xmlpi "<?"
|
|
|
|
|
2006-05-29 20:44:06 +00:00
|
|
|
location_xmlpi "wireshark:location"
|
|
|
|
protocol_xmlpi "wireshark:protocol"
|
2005-09-10 17:29:15 +00:00
|
|
|
|
|
|
|
get_attr_quote =[:blank:]*["]
|
|
|
|
avoid_editor_bug ["]
|
|
|
|
|
|
|
|
get_location_xmlpi [^[:blank:]]+
|
|
|
|
|
|
|
|
stop_xmlpi "?>"
|
|
|
|
|
2005-09-24 19:03:35 +00:00
|
|
|
notation_tag "<!"[:blank:]*NOTATION
|
|
|
|
|
2005-09-10 17:29:15 +00:00
|
|
|
special_start "<!"
|
|
|
|
special_stop ">"
|
|
|
|
whitespace [[:blank:]\r\n]+
|
|
|
|
newline \n
|
|
|
|
attlist_kw ATTLIST
|
|
|
|
doctype_kw DOCTYPE
|
|
|
|
element_kw ELEMENT
|
|
|
|
|
|
|
|
pcdata #PCDATA
|
|
|
|
any ANY
|
|
|
|
cdata #CDATA
|
|
|
|
|
|
|
|
iD ID
|
|
|
|
idref IDREF
|
|
|
|
idrefs IDREFS
|
|
|
|
nmtoken NMTOKEN
|
|
|
|
nmtokens NMTOKENS
|
|
|
|
entity ENTITY
|
|
|
|
entities ENTITIES
|
|
|
|
notation NOTATION
|
|
|
|
cdata_t CDATA
|
|
|
|
|
|
|
|
empty EMPTY
|
|
|
|
defaulT #DEFAULT
|
|
|
|
fixed #FIXED
|
|
|
|
required #REQUIRED
|
|
|
|
implied #IMPLIED
|
|
|
|
|
|
|
|
star "*"
|
|
|
|
question "?"
|
|
|
|
plus "+"
|
|
|
|
open_parens "("
|
|
|
|
close_parens ")"
|
|
|
|
open_bracket "["
|
|
|
|
close_bracket "]"
|
|
|
|
comma ","
|
|
|
|
pipe "|"
|
|
|
|
dquote ["]
|
|
|
|
|
2006-11-15 18:40:37 +00:00
|
|
|
name [A-Za-z0-9][-a-zA-Z0-9_]*
|
2005-09-10 17:29:15 +00:00
|
|
|
dquoted ["][^\"]*["]
|
|
|
|
squoted ['][^\']*[']
|
|
|
|
|
2011-08-11 03:10:11 +00:00
|
|
|
%START DTD XMLPI LOCATION DONE PROTOCOL GET_ATTR_QUOTE GET_ATTR_VAL GET_ATTR_CLOSE_QUOTE IN_COMMENT IN_NOTATION
|
2005-09-10 17:29:15 +00:00
|
|
|
%%
|
|
|
|
|
|
|
|
{whitespace} ;
|
|
|
|
|
2005-09-17 17:05:46 +00:00
|
|
|
|
|
|
|
<DTD>{comment_start} { BEGIN IN_COMMENT; }
|
|
|
|
<IN_COMMENT>[^-]? |
|
|
|
|
<IN_COMMENT>[-] ;
|
|
|
|
<IN_COMMENT>{comment_stop} { BEGIN DTD; }
|
|
|
|
|
2005-09-24 19:03:35 +00:00
|
|
|
<DTD>{notation_tag} { BEGIN IN_NOTATION; }
|
2005-10-07 08:36:23 +00:00
|
|
|
<IN_NOTATION>[^>] ;
|
2005-09-24 19:03:35 +00:00
|
|
|
<IN_NOTATION>{special_stop} { BEGIN DTD; }
|
|
|
|
|
2005-09-10 17:29:15 +00:00
|
|
|
<DTD>{start_xmlpi} {
|
|
|
|
BEGIN XMLPI;
|
|
|
|
}
|
|
|
|
|
|
|
|
<XMLPI>{location_xmlpi} {
|
|
|
|
BEGIN LOCATION;
|
|
|
|
}
|
|
|
|
|
|
|
|
<XMLPI>{protocol_xmlpi} {
|
|
|
|
BEGIN PROTOCOL;
|
|
|
|
}
|
|
|
|
|
|
|
|
<XMLPI><.> ;
|
|
|
|
<XMLPI>{stop_xmlpi} BEGIN DTD;
|
|
|
|
|
|
|
|
<LOCATION>{get_location_xmlpi} {
|
2017-08-26 08:30:47 +00:00
|
|
|
g_free(yyextra->location);
|
2016-03-31 01:44:01 +00:00
|
|
|
yyextra->location = g_strdup(yytext);
|
2005-09-10 17:29:15 +00:00
|
|
|
BEGIN DONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
<DONE>{stop_xmlpi} BEGIN DTD;
|
|
|
|
|
|
|
|
<PROTOCOL>{name} {
|
2016-03-31 01:44:01 +00:00
|
|
|
yyextra->attr_name = g_ascii_strdown(yytext, -1);
|
2005-09-10 17:29:15 +00:00
|
|
|
BEGIN GET_ATTR_QUOTE;
|
|
|
|
}
|
|
|
|
|
|
|
|
<GET_ATTR_QUOTE>{get_attr_quote} { BEGIN GET_ATTR_VAL; }
|
|
|
|
|
|
|
|
<GET_ATTR_QUOTE>. {
|
2008-05-11 18:33:49 +00:00
|
|
|
g_string_append_printf(build_data->error,
|
2006-05-22 08:14:01 +00:00
|
|
|
"error in wireshark:protocol xmpli at %s : could not find attribute value!",
|
2016-03-31 01:44:01 +00:00
|
|
|
yyextra->location);
|
2005-09-10 17:29:15 +00:00
|
|
|
yyterminate();
|
|
|
|
}
|
|
|
|
|
|
|
|
<GET_ATTR_VAL>[^"]+ {
|
|
|
|
/*"*/
|
|
|
|
struct _proto_xmlpi_attr* pa;
|
|
|
|
gboolean got_it = FALSE;
|
2016-03-31 01:44:01 +00:00
|
|
|
static struct _proto_xmlpi_attr proto_attrs[] =
|
|
|
|
{
|
|
|
|
{ "proto_name", set_proto_name },
|
|
|
|
{ "media", set_media_type },
|
|
|
|
{ "root", set_proto_root },
|
|
|
|
{ "description", set_description },
|
|
|
|
{ "hierarchy", set_recursive },
|
|
|
|
{NULL,NULL}
|
|
|
|
};
|
2011-08-11 03:10:11 +00:00
|
|
|
|
2005-09-10 17:29:15 +00:00
|
|
|
for(pa = proto_attrs; pa->name; pa++) {
|
2016-03-31 01:44:01 +00:00
|
|
|
if (g_ascii_strcasecmp(yyextra->attr_name,pa->name) == 0) {
|
2005-09-10 17:29:15 +00:00
|
|
|
pa->act(yytext);
|
|
|
|
got_it = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-08-11 03:10:11 +00:00
|
|
|
|
2005-09-10 17:29:15 +00:00
|
|
|
if (! got_it) {
|
2008-05-11 18:33:49 +00:00
|
|
|
g_string_append_printf(build_data->error,
|
2006-05-22 08:14:01 +00:00
|
|
|
"error in wireshark:protocol xmpli at %s : no such parameter %s!",
|
2016-03-31 01:44:01 +00:00
|
|
|
yyextra->location, yyextra->attr_name);
|
|
|
|
g_free(yyextra->attr_name);
|
2005-09-10 17:29:15 +00:00
|
|
|
yyterminate();
|
|
|
|
}
|
2011-08-11 03:10:11 +00:00
|
|
|
|
2016-03-31 01:44:01 +00:00
|
|
|
g_free(yyextra->attr_name);
|
2011-08-11 03:10:11 +00:00
|
|
|
|
2005-09-10 17:29:15 +00:00
|
|
|
BEGIN GET_ATTR_CLOSE_QUOTE;
|
|
|
|
}
|
|
|
|
|
|
|
|
<GET_ATTR_CLOSE_QUOTE>{dquote} { BEGIN PROTOCOL;}
|
|
|
|
|
|
|
|
<PROTOCOL>{stop_xmlpi} BEGIN DTD;
|
|
|
|
|
|
|
|
<DTD>{special_start} { DTD_PARSE(TOKEN_TAG_START); }
|
|
|
|
<DTD>{special_stop} { DTD_PARSE(TOKEN_TAG_STOP); }
|
|
|
|
|
|
|
|
<DTD>{attlist_kw} { DTD_PARSE(TOKEN_ATTLIST_KW); }
|
|
|
|
<DTD>{element_kw} { DTD_PARSE(TOKEN_ELEMENT_KW); }
|
|
|
|
<DTD>{doctype_kw} { DTD_PARSE(TOKEN_DOCTYPE_KW); }
|
|
|
|
|
2011-08-11 03:10:11 +00:00
|
|
|
<DTD>{pcdata} { DTD_PARSE(TOKEN_ELEM_DATA); }
|
2005-09-10 17:29:15 +00:00
|
|
|
<DTD>{any} { DTD_PARSE(TOKEN_ELEM_DATA); }
|
|
|
|
<DTD>{cdata} { DTD_PARSE(TOKEN_ELEM_DATA); }
|
|
|
|
<DTD>{empty} { DTD_PARSE(TOKEN_EMPTY_KW); }
|
|
|
|
|
|
|
|
<DTD>{iD} { DTD_PARSE(TOKEN_ATT_TYPE); }
|
|
|
|
<DTD>{idref} { DTD_PARSE(TOKEN_ATT_TYPE); }
|
|
|
|
<DTD>{idrefs} { DTD_PARSE(TOKEN_ATT_TYPE); }
|
|
|
|
<DTD>{nmtoken} { DTD_PARSE(TOKEN_ATT_TYPE); }
|
|
|
|
<DTD>{nmtokens} { DTD_PARSE(TOKEN_ATT_TYPE); }
|
|
|
|
<DTD>{entity} { DTD_PARSE(TOKEN_ATT_TYPE); }
|
|
|
|
<DTD>{entities} { DTD_PARSE(TOKEN_ATT_TYPE); }
|
|
|
|
<DTD>{notation} { DTD_PARSE(TOKEN_ATT_TYPE); }
|
|
|
|
<DTD>{cdata_t} { DTD_PARSE(TOKEN_ATT_TYPE); }
|
|
|
|
<DTD>{defaulT} { DTD_PARSE(TOKEN_ATT_DEF_WITH_VALUE); }
|
|
|
|
<DTD>{fixed} { DTD_PARSE(TOKEN_ATT_DEF_WITH_VALUE); }
|
|
|
|
<DTD>{required} { DTD_PARSE(TOKEN_ATT_DEF); }
|
|
|
|
<DTD>{implied} { DTD_PARSE(TOKEN_ATT_DEF); }
|
|
|
|
|
|
|
|
<DTD>{star} { DTD_PARSE(TOKEN_STAR); }
|
|
|
|
<DTD>{question} { DTD_PARSE(TOKEN_QUESTION); }
|
|
|
|
<DTD>{plus} { DTD_PARSE(TOKEN_PLUS); }
|
|
|
|
<DTD>{comma} { DTD_PARSE(TOKEN_COMMA); }
|
|
|
|
<DTD>{open_parens} { DTD_PARSE(TOKEN_OPEN_PARENS); }
|
|
|
|
<DTD>{close_parens} { DTD_PARSE(TOKEN_CLOSE_PARENS); }
|
|
|
|
<DTD>{open_bracket} { DTD_PARSE(TOKEN_OPEN_BRACKET); }
|
|
|
|
<DTD>{close_bracket} { DTD_PARSE(TOKEN_CLOSE_BRACKET); }
|
|
|
|
<DTD>{pipe} { DTD_PARSE(TOKEN_PIPE); }
|
|
|
|
|
|
|
|
<DTD>{dquoted} |
|
|
|
|
<DTD>{squoted} { DTD_PARSE(TOKEN_QUOTED); }
|
|
|
|
<DTD>{name} { DTD_PARSE(TOKEN_NAME); }
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
2018-02-16 11:15:32 +00:00
|
|
|
/*
|
|
|
|
* Turn diagnostics back on, so we check the code that we've written.
|
|
|
|
*/
|
|
|
|
DIAG_ON_FLEX
|
2017-08-18 19:11:47 +00:00
|
|
|
|
2016-03-31 01:44:01 +00:00
|
|
|
static dtd_token_data_t* new_token(gchar* text, gchar* location) {
|
2013-03-16 08:52:09 +00:00
|
|
|
dtd_token_data_t* t = g_new(dtd_token_data_t,1);
|
2011-08-11 03:10:11 +00:00
|
|
|
|
2005-09-10 17:29:15 +00:00
|
|
|
t->text = g_strdup(text);
|
|
|
|
t->location = g_strdup(location);
|
2011-08-11 03:10:11 +00:00
|
|
|
|
2005-09-10 17:29:15 +00:00
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-03-31 01:44:01 +00:00
|
|
|
static size_t my_yyinput(Dtd_Parse_scanner_state_t *state, char* buff, size_t size) {
|
2005-09-10 17:29:15 +00:00
|
|
|
|
2016-03-31 01:44:01 +00:00
|
|
|
if (state->offsetx >= state->len) {
|
2005-09-10 17:29:15 +00:00
|
|
|
return YY_NULL;
|
2016-03-31 01:44:01 +00:00
|
|
|
} else if (state->offsetx + size <= state->len) {
|
|
|
|
memcpy(buff, state->input_string->str + state->offsetx, size);
|
|
|
|
state->offsetx += size;
|
2005-09-10 17:29:15 +00:00
|
|
|
return size;
|
|
|
|
} else {
|
2016-03-31 01:44:01 +00:00
|
|
|
size = state->len - state->offsetx;
|
|
|
|
memcpy(buff, state->input_string->str + state->offsetx, size);
|
|
|
|
state->offsetx = state->len;
|
2005-09-10 17:29:15 +00:00
|
|
|
return size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extern dtd_build_data_t* dtd_parse(GString* s) {
|
2016-03-31 01:44:01 +00:00
|
|
|
yyscan_t scanner;
|
|
|
|
Dtd_Parse_scanner_state_t state;
|
2005-09-10 17:29:15 +00:00
|
|
|
|
2016-03-31 01:44:01 +00:00
|
|
|
if (Dtd_Parse_lex_init(&scanner) != 0) {
|
|
|
|
#ifdef DEBUG_DTD_PARSER
|
|
|
|
fprintf(stderr, "Can't initialize scanner: %s\n",
|
|
|
|
strerror(errno));
|
|
|
|
#endif
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-08-11 03:10:11 +00:00
|
|
|
|
2016-03-31 01:44:01 +00:00
|
|
|
state.input_string = s;
|
|
|
|
state.offsetx = 0;
|
|
|
|
state.len = state.input_string->len;
|
|
|
|
|
|
|
|
state.pParser = DtdParseAlloc(g_malloc);
|
2005-09-20 00:31:53 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG_DTD_PARSER
|
2005-09-22 18:39:25 +00:00
|
|
|
DtdParseTrace(stderr, ">>");
|
2005-09-20 00:31:53 +00:00
|
|
|
#endif
|
2011-08-11 03:10:11 +00:00
|
|
|
|
2013-03-16 08:52:09 +00:00
|
|
|
build_data = g_new(dtd_build_data_t,1);
|
2005-09-10 17:29:15 +00:00
|
|
|
|
|
|
|
build_data->proto_name = NULL;
|
|
|
|
build_data->media_type = NULL;
|
|
|
|
build_data->description = NULL;
|
|
|
|
build_data->proto_root = NULL;
|
2005-09-17 17:05:46 +00:00
|
|
|
build_data->recursion = FALSE;
|
2011-08-11 03:10:11 +00:00
|
|
|
|
2005-09-10 17:29:15 +00:00
|
|
|
build_data->elements = g_ptr_array_new();
|
|
|
|
build_data->attributes = g_ptr_array_new();
|
|
|
|
|
|
|
|
build_data->error = g_string_new("");
|
2011-08-11 03:10:11 +00:00
|
|
|
|
2016-03-31 01:44:01 +00:00
|
|
|
state.location = NULL;
|
|
|
|
state.attr_name = NULL;
|
2011-08-11 03:10:11 +00:00
|
|
|
|
2016-03-31 01:44:01 +00:00
|
|
|
/* Associate the state with the scanner */
|
|
|
|
Dtd_Parse_set_extra(&state, scanner);
|
2005-09-10 17:29:15 +00:00
|
|
|
|
2016-03-31 01:44:01 +00:00
|
|
|
Dtd_Parse_lex(scanner);
|
2005-09-10 17:29:15 +00:00
|
|
|
|
2016-03-31 01:44:01 +00:00
|
|
|
DtdParse(state.pParser, 0, NULL, build_data);
|
2011-08-11 03:10:11 +00:00
|
|
|
|
2016-03-31 01:44:01 +00:00
|
|
|
Dtd_Parse_lex_destroy(scanner);
|
2011-08-11 03:10:11 +00:00
|
|
|
|
2017-08-26 08:30:47 +00:00
|
|
|
g_free(state.location);
|
2011-08-11 03:10:11 +00:00
|
|
|
|
2016-03-31 01:44:01 +00:00
|
|
|
DtdParseFree(state.pParser, g_free);
|
2011-08-11 03:10:11 +00:00
|
|
|
|
2005-09-10 17:29:15 +00:00
|
|
|
return build_data;
|
|
|
|
}
|