Code

format string protection/clean up (CVE-2007-1463, CVE-2007-1464)
[inkscape.git] / src / dom / cssparser.h
1 #ifndef __CSSPARSER_H__
2 #define __CSSPARSER_H__
3 /**
4  * Phoebe DOM Implementation.
5  *
6  * This is a C++ approximation of the W3C DOM model, which follows
7  * fairly closely the specifications in the various .idl files, copies of
8  * which are provided for reference.  Most important is this one:
9  *
10  * http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/idl-definitions.html
11  *
12  * Authors:
13  *   Bob Jamison
14  *
15  * Copyright (C) 2005 Bob Jamison
16  *
17  *  This library is free software; you can redistribute it and/or
18  *  modify it under the terms of the GNU Lesser General Public
19  *  License as published by the Free Software Foundation; either
20  *  version 2.1 of the License, or (at your option) any later version.
21  *
22  *  This library is distributed in the hope that it will be useful,
23  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
24  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
25  *  Lesser General Public License for more details.
26  *
27  *  You should have received a copy of the GNU Lesser General Public
28  *  License along with this library; if not, write to the Free Software
29  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
30  */
32 #include <glib.h>
34 #include "dom.h"
36 #include "css.h"
38 namespace org
39 {
40 namespace w3c
41 {
42 namespace dom
43 {
44 namespace css
45 {
47 class CssParser
48 {
50 public:
52     /**
53      *
54      */
55     CssParser()
56         {}
58     /**
59      *
60      */
61     virtual ~CssParser()
62         {}
64     /**
65      *
66      */
67     virtual bool parse(const DOMString &str);
69     /**
70      *
71      */
72     virtual bool parseFile(const DOMString &str);
75 protected:
77     DOMString parsebuf;
78     long parselen;
79     CSSStyleSheet stylesheet;
82     /**
83      *
84      */
85     void error(char *fmt, ...) G_GNUC_PRINTF(2,3);
87     /**
88      * Get the character at the given location in the buffer.
89      *  Return 0 if out-of-bounds
90      */
91     XMLCh get(int index);
94     /**
95      *  Test if the given substring exists at the given position
96      *  in parsebuf.  Use get() in case of out-of-bounds
97      */
98     bool match(int pos, char *str);
100     /**
101      * Skip over whitespace
102      * Return new position
103      */
104     int skipwhite(int index);
106     /**
107      * Get the word at the current position.  Return the new
108      * position if successful, the current position if no word,
109      * -1 if error.
110      */
111     int getWord(int index, DOMString &str);
114     /**
115      * Get a number at the current position
116      * Return the new position if a proper number, else the original pos
117      */
118     int getNumber(int index, double &result);
120     /**
121      * Assume that we are starting on a quote.  Ends on the char
122      * after the final '"'
123      */
124     int getQuoted(int p0, DOMString &result);
126 /**
127  * Not in api.  replaces URI return by lexer
128  */
129 int getUri(int p0, DOMString &str);
132 /**
133  * Skip to the next rule
134  */
135 int skipBlock(int p0);
137 //#########################################################################
138 //# P R O D U C T I O N S
139 //#########################################################################
141 /**
142  * stylesheet
143  *   : [ CHARSET_SYM S* STRING S* ';' ]?
144  *     [S|CDO|CDC]* [ import [S|CDO|CDC]* ]*
145  *     [ [ ruleset | media | page ] [S|CDO|CDC]* ]*
146  *   ;
147  */
148 int getStyleSheet(int p0);
150 /**
151  * import
152  *   : IMPORT_SYM S*
153  *     [STRING|URI] S* [ medium [ COMMA S* medium]* ]? ';' S*
154  *   ;
155  */
156 int getImport(int p0);
158 /**
159  * media
160  *   : MEDIA_SYM S* medium [ COMMA S* medium ]* LBRACE S* ruleset* '}' S*
161  *   ;
162  */
163 int getMedia(int p0);
165 /**
166  * medium
167  *   : IDENT S*
168  *   ;
169  */
170 int getMedium(int p0);
172 /**
173  * page
174  *   : PAGE_SYM S* pseudo_page? S*
175  *     LBRACE S* declaration [ ';' S* declaration ]* '}' S*
176  *   ;
177  */
178 int getPage(int p0);
180 /**
181  * pseudo_page
182  *   : ':' IDENT
183  *   ;
184  */
185 int getPseudoPage(int p0);
187 /**
188  * ruleset
189  *   : selector [ COMMA S* selector ]*
190  *     LBRACE S* declaration [ ';' S* declaration ]* '}' S*
191  *   ;
192  */
193 int getRuleSet(int p0);
195 /**
196  * selector
197  *   : simple_selector [ combinator simple_selector ]*
198  *   ;
199  */
200 int getSelector(int p0);
202 /**
203  * simple_selector
204  *   : element_name [ HASH | class | attrib | pseudo ]*
205  *   | [ HASH | class | attrib | pseudo ]+
206  *   ;
207  */
208 int getSimpleSelector(int p0);
210 /**
211  * declaration
212  *   : property ':' S* expr prio?
213  *   | {empty}
214  *   ;
215  */
216 int getDeclaration(int p0, CSSStyleDeclaration &declarationList);
218 /**
219  * prio
220  *   : IMPORTANT_SYM S*
221  *   ;
222  */
223 int getPrio(int p0, DOMString &val);
225 /**
226  * expr
227  *   : term [ operator term ]*
228  *   ;
229  */
230 int getExpr(int p0);
232 /**
233  * term
234  *   : unary_operator?
235  *     [ NUMBER S* | PERCENTAGE S* | LENGTH S* | EMS S* | EXS S* | ANGLE S* |
236  *       TIME S* | FREQ S* | function ]
237  *   | STRING S* | IDENT S* | URI S* | hexcolor
238  *   ;
239  */
240 int getTerm(int p0);
242 /**
243  * function
244  *   : FUNCTION S* expr ')' S*
245  *   ;
246  */
247 int getFunction(int p0);
249 /**
250  * There is a constraint on the color that it must
251  * have either 3 or 6 hex-digits (i.e., [0-9a-fA-F])
252  * after the "#"; e.g., "#000" is OK, but "#abcd" is not.
253  *
254  * hexcolor
255  *   : HASH S*
256  *   ;
257  */
258 int getHexColor(int p0);
261 int lastPosition;
263 /**
264  * Get the column and row number of the given character position.
265  * Also gets the last-occuring newline before the position
266  */
267 void getColumnAndRow(int p, int &col, int &row, int &lastNL);
269 };
272 } // namespace css
273 } // namespace dom
274 } // namespace w3c
275 } // namespace org
283 #endif /* __CSSPARSER_H__ */
284 //#########################################################################
285 //# E N D    O F    F I L E
286 //#########################################################################