Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 1 | /* |
| 2 | * SAX Reader implementation |
| 3 | * |
| 4 | * Copyright 2008 Alistair Leslie-Hughes |
Piotr Caban | d3e9ca7 | 2008-07-17 00:40:32 +0200 | [diff] [blame] | 5 | * Copyright 2008 Piotr Caban |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 6 | * |
| 7 | * This library is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Lesser General Public |
| 9 | * License as published by the Free Software Foundation; either |
| 10 | * version 2.1 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * This library is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * Lesser General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Lesser General Public |
| 18 | * License along with this library; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA |
| 20 | */ |
| 21 | #define COBJMACROS |
| 22 | |
| 23 | #include "config.h" |
| 24 | |
| 25 | #include <stdarg.h> |
Alexandre Julliard | a1c8f6d | 2011-02-24 13:11:53 +0100 | [diff] [blame] | 26 | #ifdef HAVE_LIBXML2 |
| 27 | # include <libxml/parser.h> |
| 28 | # include <libxml/xmlerror.h> |
| 29 | # include <libxml/SAX2.h> |
| 30 | # include <libxml/parserInternals.h> |
| 31 | #endif |
| 32 | |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 33 | #include "windef.h" |
| 34 | #include "winbase.h" |
| 35 | #include "winuser.h" |
| 36 | #include "winnls.h" |
| 37 | #include "ole2.h" |
Nikolay Sivov | 62e521a | 2010-08-30 01:31:49 +0400 | [diff] [blame] | 38 | #include "msxml6.h" |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 39 | #include "wininet.h" |
| 40 | #include "urlmon.h" |
| 41 | #include "winreg.h" |
| 42 | #include "shlwapi.h" |
| 43 | |
| 44 | #include "wine/debug.h" |
Nikolay Sivov | 9d66292 | 2011-12-24 16:10:33 +0300 | [diff] [blame] | 45 | #include "wine/list.h" |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 46 | |
| 47 | #include "msxml_private.h" |
| 48 | |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 49 | WINE_DEFAULT_DEBUG_CHANNEL(msxml); |
| 50 | |
| 51 | #ifdef HAVE_LIBXML2 |
| 52 | |
Nikolay Sivov | f999f4a | 2011-12-16 14:33:32 +0300 | [diff] [blame] | 53 | typedef enum |
Nikolay Sivov | ad336be | 2011-10-04 16:27:39 -0500 | [diff] [blame] | 54 | { |
Nikolay Sivov | 137a21d | 2012-04-18 22:39:38 +0400 | [diff] [blame] | 55 | FeatureUnknown = 0, |
Nikolay Sivov | ad336be | 2011-10-04 16:27:39 -0500 | [diff] [blame] | 56 | ExhaustiveErrors = 1 << 1, |
| 57 | ExternalGeneralEntities = 1 << 2, |
| 58 | ExternalParameterEntities = 1 << 3, |
| 59 | ForcedResync = 1 << 4, |
| 60 | NamespacePrefixes = 1 << 5, |
Nikolay Sivov | 3d3786c | 2011-10-05 13:29:37 -0500 | [diff] [blame] | 61 | Namespaces = 1 << 6, |
Nikolay Sivov | ad336be | 2011-10-04 16:27:39 -0500 | [diff] [blame] | 62 | ParameterEntities = 1 << 7, |
| 63 | PreserveSystemIndentifiers = 1 << 8, |
| 64 | ProhibitDTD = 1 << 9, |
| 65 | SchemaValidation = 1 << 10, |
| 66 | ServerHttpRequest = 1 << 11, |
| 67 | SuppressValidationfatalError = 1 << 12, |
| 68 | UseInlineSchema = 1 << 13, |
Nikolay Sivov | cc4c694 | 2011-10-05 09:37:40 -0500 | [diff] [blame] | 69 | UseSchemaLocation = 1 << 14, |
| 70 | LexicalHandlerParEntities = 1 << 15 |
Nikolay Sivov | 137a21d | 2012-04-18 22:39:38 +0400 | [diff] [blame] | 71 | } saxreader_feature; |
| 72 | |
| 73 | /* feature names */ |
| 74 | static const WCHAR FeatureExternalGeneralEntitiesW[] = { |
| 75 | 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/','s','a','x','/', |
| 76 | 'f','e','a','t','u','r','e','s','/','e','x','t','e','r','n','a','l','-','g','e','n','e','r','a','l', |
| 77 | '-','e','n','t','i','t','i','e','s',0 |
| 78 | }; |
| 79 | |
| 80 | static const WCHAR FeatureExternalParameterEntitiesW[] = { |
| 81 | 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/','s','a','x','/','f','e','a','t','u','r','e','s', |
| 82 | '/','e','x','t','e','r','n','a','l','-','p','a','r','a','m','e','t','e','r','-','e','n','t','i','t','i','e','s',0 |
| 83 | }; |
| 84 | |
| 85 | static const WCHAR FeatureLexicalHandlerParEntitiesW[] = { |
| 86 | 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/','s','a','x','/','f','e','a','t','u','r','e','s', |
| 87 | '/','l','e','x','i','c','a','l','-','h','a','n','d','l','e','r','/','p','a','r','a','m','e','t','e','r','-','e','n','t','i','t','i','e','s',0 |
| 88 | }; |
| 89 | |
| 90 | static const WCHAR FeatureProhibitDTDW[] = { |
| 91 | 'p','r','o','h','i','b','i','t','-','d','t','d',0 |
| 92 | }; |
| 93 | |
| 94 | static const WCHAR FeatureNamespacesW[] = { |
| 95 | 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/','s','a','x','/','f','e','a','t','u','r','e','s', |
| 96 | '/','n','a','m','e','s','p','a','c','e','s',0 |
| 97 | }; |
| 98 | |
| 99 | static const WCHAR FeatureNamespacePrefixesW[] = { |
| 100 | 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/','s','a','x','/','f','e','a','t','u','r','e','s', |
| 101 | '/','n','a','m','e','s','p','a','c','e','-','p','r','e','f','i','x','e','s',0 |
| 102 | }; |
| 103 | |
| 104 | struct saxreader_feature_pair |
| 105 | { |
| 106 | saxreader_feature feature; |
| 107 | const WCHAR *name; |
| 108 | }; |
| 109 | |
| 110 | static const struct saxreader_feature_pair saxreader_feature_map[] = { |
| 111 | { ExternalGeneralEntities, FeatureExternalGeneralEntitiesW }, |
| 112 | { ExternalParameterEntities, FeatureExternalParameterEntitiesW }, |
| 113 | { LexicalHandlerParEntities, FeatureLexicalHandlerParEntitiesW }, |
| 114 | { NamespacePrefixes, FeatureNamespacePrefixesW }, |
| 115 | { Namespaces, FeatureNamespacesW }, |
| 116 | { ProhibitDTD, FeatureProhibitDTDW } |
| 117 | }; |
| 118 | |
| 119 | static saxreader_feature get_saxreader_feature(const WCHAR *name) |
| 120 | { |
| 121 | int min, max, n, c; |
| 122 | |
| 123 | min = 0; |
| 124 | max = sizeof(saxreader_feature_map)/sizeof(struct saxreader_feature_pair) - 1; |
| 125 | |
| 126 | while (min <= max) |
| 127 | { |
| 128 | n = (min+max)/2; |
| 129 | |
| 130 | c = strcmpW(saxreader_feature_map[n].name, name); |
| 131 | if (!c) |
| 132 | return saxreader_feature_map[n].feature; |
| 133 | |
| 134 | if (c > 0) |
| 135 | max = n-1; |
| 136 | else |
| 137 | min = n+1; |
| 138 | } |
| 139 | |
| 140 | return FeatureUnknown; |
| 141 | } |
Nikolay Sivov | ad336be | 2011-10-04 16:27:39 -0500 | [diff] [blame] | 142 | |
Andrew Nguyen | 9c5d5d8 | 2011-07-15 07:38:07 -0500 | [diff] [blame] | 143 | struct bstrpool |
| 144 | { |
| 145 | BSTR *pool; |
| 146 | unsigned int index; |
| 147 | unsigned int len; |
| 148 | }; |
| 149 | |
Nikolay Sivov | f999f4a | 2011-12-16 14:33:32 +0300 | [diff] [blame] | 150 | typedef struct |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 151 | { |
Nikolay Sivov | 9d66292 | 2011-12-24 16:10:33 +0300 | [diff] [blame] | 152 | BSTR prefix; |
| 153 | BSTR uri; |
| 154 | } ns; |
| 155 | |
| 156 | typedef struct |
| 157 | { |
| 158 | struct list entry; |
| 159 | BSTR prefix; |
| 160 | BSTR local; |
| 161 | BSTR qname; |
| 162 | ns *ns; /* namespaces defined in this particular element */ |
| 163 | int ns_count; |
| 164 | } element_entry; |
| 165 | |
| 166 | typedef struct |
| 167 | { |
Nikolay Sivov | 0ba0f4c | 2011-11-21 12:23:25 +0300 | [diff] [blame] | 168 | DispatchEx dispex; |
Michael Stefaniuc | 13e1997 | 2010-12-27 23:12:06 +0100 | [diff] [blame] | 169 | IVBSAXXMLReader IVBSAXXMLReader_iface; |
| 170 | ISAXXMLReader ISAXXMLReader_iface; |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 171 | LONG ref; |
Nikolay Sivov | f999f4a | 2011-12-16 14:33:32 +0300 | [diff] [blame] | 172 | ISAXContentHandler *contentHandler; |
| 173 | IVBSAXContentHandler *vbcontentHandler; |
| 174 | ISAXErrorHandler *errorHandler; |
| 175 | IVBSAXErrorHandler *vberrorHandler; |
| 176 | ISAXLexicalHandler *lexicalHandler; |
| 177 | IVBSAXLexicalHandler *vblexicalHandler; |
| 178 | ISAXDeclHandler *declHandler; |
| 179 | IVBSAXDeclHandler *vbdeclHandler; |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 180 | xmlSAXHandler sax; |
Piotr Caban | c7fc926 | 2008-10-01 19:52:36 +0200 | [diff] [blame] | 181 | BOOL isParsing; |
Andrew Nguyen | 9c5d5d8 | 2011-07-15 07:38:07 -0500 | [diff] [blame] | 182 | struct bstrpool pool; |
Nikolay Sivov | 137a21d | 2012-04-18 22:39:38 +0400 | [diff] [blame] | 183 | saxreader_feature features; |
Piotr Caban | e84c410 | 2011-10-24 20:08:46 +0200 | [diff] [blame] | 184 | MSXML_VERSION version; |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 185 | } saxreader; |
| 186 | |
Nikolay Sivov | f999f4a | 2011-12-16 14:33:32 +0300 | [diff] [blame] | 187 | typedef struct |
Piotr Caban | d3e9ca7 | 2008-07-17 00:40:32 +0200 | [diff] [blame] | 188 | { |
Michael Stefaniuc | 13e1997 | 2010-12-27 23:12:06 +0100 | [diff] [blame] | 189 | IVBSAXLocator IVBSAXLocator_iface; |
| 190 | ISAXLocator ISAXLocator_iface; |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 191 | IVBSAXAttributes IVBSAXAttributes_iface; |
| 192 | ISAXAttributes ISAXAttributes_iface; |
Piotr Caban | d3e9ca7 | 2008-07-17 00:40:32 +0200 | [diff] [blame] | 193 | LONG ref; |
| 194 | saxreader *saxreader; |
Piotr Caban | 51c9527 | 2008-07-17 00:40:53 +0200 | [diff] [blame] | 195 | HRESULT ret; |
| 196 | xmlParserCtxtPtr pParserCtxt; |
Piotr Caban | 60ca0a7 | 2008-07-17 00:42:01 +0200 | [diff] [blame] | 197 | WCHAR *publicId; |
Piotr Caban | 3196f78 | 2008-07-17 00:42:07 +0200 | [diff] [blame] | 198 | WCHAR *systemId; |
Piotr Caban | bb849dc | 2008-07-23 16:39:04 +0200 | [diff] [blame] | 199 | int line; |
| 200 | int column; |
Piotr Caban | c52e091 | 2008-07-31 16:48:03 +0200 | [diff] [blame] | 201 | BOOL vbInterface; |
Nikolay Sivov | 9d66292 | 2011-12-24 16:10:33 +0300 | [diff] [blame] | 202 | struct list elements; |
Piotr Caban | d3e9ca7 | 2008-07-17 00:40:32 +0200 | [diff] [blame] | 203 | |
Piotr Caban | a95b35d | 2011-10-31 12:33:18 +0100 | [diff] [blame] | 204 | BSTR namespaceUri; |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 205 | int attributesSize; |
Piotr Caban | 6df49d5 | 2008-07-30 20:24:12 +0200 | [diff] [blame] | 206 | int nb_attributes; |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 207 | struct _attributes |
| 208 | { |
| 209 | BSTR szLocalname; |
| 210 | BSTR szURI; |
| 211 | BSTR szValue; |
| 212 | BSTR szQName; |
| 213 | } *attributes; |
| 214 | } saxlocator; |
Piotr Caban | 5816c38 | 2008-07-27 19:55:05 +0200 | [diff] [blame] | 215 | |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 216 | static inline saxreader *impl_from_IVBSAXXMLReader( IVBSAXXMLReader *iface ) |
| 217 | { |
Michael Stefaniuc | 13e1997 | 2010-12-27 23:12:06 +0100 | [diff] [blame] | 218 | return CONTAINING_RECORD(iface, saxreader, IVBSAXXMLReader_iface); |
Andrew Talbot | 7142fc1 | 2008-03-31 20:42:18 +0100 | [diff] [blame] | 219 | } |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 220 | |
Piotr Caban | 1926760 | 2008-07-08 20:52:04 +0200 | [diff] [blame] | 221 | static inline saxreader *impl_from_ISAXXMLReader( ISAXXMLReader *iface ) |
| 222 | { |
Michael Stefaniuc | 13e1997 | 2010-12-27 23:12:06 +0100 | [diff] [blame] | 223 | return CONTAINING_RECORD(iface, saxreader, ISAXXMLReader_iface); |
Piotr Caban | 1926760 | 2008-07-08 20:52:04 +0200 | [diff] [blame] | 224 | } |
| 225 | |
Piotr Caban | 4c69e86 | 2008-07-31 16:47:26 +0200 | [diff] [blame] | 226 | static inline saxlocator *impl_from_IVBSAXLocator( IVBSAXLocator *iface ) |
| 227 | { |
Michael Stefaniuc | 13e1997 | 2010-12-27 23:12:06 +0100 | [diff] [blame] | 228 | return CONTAINING_RECORD(iface, saxlocator, IVBSAXLocator_iface); |
Piotr Caban | 4c69e86 | 2008-07-31 16:47:26 +0200 | [diff] [blame] | 229 | } |
| 230 | |
Piotr Caban | d3e9ca7 | 2008-07-17 00:40:32 +0200 | [diff] [blame] | 231 | static inline saxlocator *impl_from_ISAXLocator( ISAXLocator *iface ) |
| 232 | { |
Michael Stefaniuc | 13e1997 | 2010-12-27 23:12:06 +0100 | [diff] [blame] | 233 | return CONTAINING_RECORD(iface, saxlocator, ISAXLocator_iface); |
Piotr Caban | d3e9ca7 | 2008-07-17 00:40:32 +0200 | [diff] [blame] | 234 | } |
| 235 | |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 236 | static inline saxlocator *impl_from_IVBSAXAttributes( IVBSAXAttributes *iface ) |
Piotr Caban | 4c69e86 | 2008-07-31 16:47:26 +0200 | [diff] [blame] | 237 | { |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 238 | return CONTAINING_RECORD(iface, saxlocator, IVBSAXAttributes_iface); |
Piotr Caban | 4c69e86 | 2008-07-31 16:47:26 +0200 | [diff] [blame] | 239 | } |
| 240 | |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 241 | static inline saxlocator *impl_from_ISAXAttributes( ISAXAttributes *iface ) |
Piotr Caban | 5816c38 | 2008-07-27 19:55:05 +0200 | [diff] [blame] | 242 | { |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 243 | return CONTAINING_RECORD(iface, saxlocator, ISAXAttributes_iface); |
Piotr Caban | 5816c38 | 2008-07-27 19:55:05 +0200 | [diff] [blame] | 244 | } |
| 245 | |
Nikolay Sivov | 864f170 | 2011-09-21 21:01:10 +0400 | [diff] [blame] | 246 | /* property names */ |
| 247 | static const WCHAR PropertyCharsetW[] = { |
| 248 | 'c','h','a','r','s','e','t',0 |
| 249 | }; |
| 250 | static const WCHAR PropertyDeclHandlerW[] = { |
| 251 | 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/', |
| 252 | 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/', |
| 253 | 'd','e','c','l','a','r','a','t','i','o','n', |
| 254 | '-','h','a','n','d','l','e','r',0 |
| 255 | }; |
| 256 | static const WCHAR PropertyDomNodeW[] = { |
| 257 | 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/', |
| 258 | 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/', |
| 259 | 'd','o','m','-','n','o','d','e',0 |
| 260 | }; |
| 261 | static const WCHAR PropertyInputSourceW[] = { |
| 262 | 'i','n','p','u','t','-','s','o','u','r','c','e',0 |
| 263 | }; |
| 264 | static const WCHAR PropertyLexicalHandlerW[] = { |
| 265 | 'h','t','t','p',':','/','/','x','m','l','.','o','r','g','/', |
| 266 | 's','a','x','/','p','r','o','p','e','r','t','i','e','s','/', |
| 267 | 'l','e','x','i','c','a','l','-','h','a','n','d','l','e','r',0 |
| 268 | }; |
| 269 | static const WCHAR PropertyMaxElementDepthW[] = { |
| 270 | 'm','a','x','-','e','l','e','m','e','n','t','-','d','e','p','t','h',0 |
| 271 | }; |
| 272 | static const WCHAR PropertyMaxXMLSizeW[] = { |
| 273 | 'm','a','x','-','x','m','l','-','s','i','z','e',0 |
| 274 | }; |
| 275 | static const WCHAR PropertySchemaDeclHandlerW[] = { |
| 276 | 's','c','h','e','m','a','-','d','e','c','l','a','r','a','t','i','o','n','-', |
| 277 | 'h','a','n','d','l','e','r',0 |
| 278 | }; |
| 279 | static const WCHAR PropertyXMLDeclEncodingW[] = { |
| 280 | 'x','m','l','d','e','c','l','-','e','n','c','o','d','i','n','g',0 |
| 281 | }; |
| 282 | static const WCHAR PropertyXMLDeclStandaloneW[] = { |
| 283 | 'x','m','l','d','e','c','l','-','s','t','a','n','d','a','l','o','n','e',0 |
| 284 | }; |
| 285 | static const WCHAR PropertyXMLDeclVersionW[] = { |
| 286 | 'x','m','l','d','e','c','l','-','v','e','r','s','i','o','n',0 |
| 287 | }; |
| 288 | |
Nikolay Sivov | 137a21d | 2012-04-18 22:39:38 +0400 | [diff] [blame] | 289 | static inline HRESULT set_feature_value(saxreader *reader, saxreader_feature feature, VARIANT_BOOL value) |
Nikolay Sivov | ad336be | 2011-10-04 16:27:39 -0500 | [diff] [blame] | 290 | { |
Nikolay Sivov | 54df481 | 2012-04-19 10:53:15 +0400 | [diff] [blame] | 291 | /* handling of non-VARIANT_* values is version dependent */ |
| 292 | if ((reader->version < MSXML4) && (value != VARIANT_TRUE)) |
| 293 | value = VARIANT_FALSE; |
| 294 | if ((reader->version >= MSXML4) && (value != VARIANT_FALSE)) |
| 295 | value = VARIANT_TRUE; |
| 296 | |
Nikolay Sivov | ad336be | 2011-10-04 16:27:39 -0500 | [diff] [blame] | 297 | if (value == VARIANT_TRUE) |
| 298 | reader->features |= feature; |
| 299 | else |
| 300 | reader->features &= ~feature; |
| 301 | |
| 302 | return S_OK; |
| 303 | } |
| 304 | |
Nikolay Sivov | 137a21d | 2012-04-18 22:39:38 +0400 | [diff] [blame] | 305 | static inline HRESULT get_feature_value(const saxreader *reader, saxreader_feature feature, VARIANT_BOOL *value) |
Nikolay Sivov | 3d3786c | 2011-10-05 13:29:37 -0500 | [diff] [blame] | 306 | { |
| 307 | *value = reader->features & feature ? VARIANT_TRUE : VARIANT_FALSE; |
| 308 | return S_OK; |
| 309 | } |
| 310 | |
Nikolay Sivov | f27159a | 2012-04-19 10:46:03 +0400 | [diff] [blame] | 311 | static BOOL is_namespaces_enabled(const saxreader *reader) |
| 312 | { |
| 313 | return (reader->version < MSXML4) || (reader->features & Namespaces); |
| 314 | } |
| 315 | |
Nikolay Sivov | 2dc6711 | 2012-05-08 15:50:19 +0400 | [diff] [blame] | 316 | static inline int has_content_handler(const saxlocator *locator) |
Nikolay Sivov | ff99228 | 2010-01-18 23:30:50 +0300 | [diff] [blame] | 317 | { |
| 318 | return (locator->vbInterface && locator->saxreader->vbcontentHandler) || |
| 319 | (!locator->vbInterface && locator->saxreader->contentHandler); |
| 320 | } |
Piotr Caban | bb849dc | 2008-07-23 16:39:04 +0200 | [diff] [blame] | 321 | |
Nikolay Sivov | fc4dab4 | 2012-05-08 15:56:20 +0400 | [diff] [blame] | 322 | static inline int has_lexical_handler(const saxlocator *locator) |
| 323 | { |
| 324 | return (locator->vbInterface && locator->saxreader->vblexicalHandler) || |
| 325 | (!locator->vbInterface && locator->saxreader->lexicalHandler); |
| 326 | } |
| 327 | |
| 328 | static inline int has_error_handler(const saxlocator *locator) |
Nikolay Sivov | 8f9804e | 2010-10-29 01:04:44 +0400 | [diff] [blame] | 329 | { |
| 330 | return (locator->vbInterface && locator->saxreader->vberrorHandler) || |
| 331 | (!locator->vbInterface && locator->saxreader->errorHandler); |
| 332 | } |
| 333 | |
Nikolay Sivov | 9d66292 | 2011-12-24 16:10:33 +0300 | [diff] [blame] | 334 | static BSTR build_qname(BSTR prefix, BSTR local) |
Piotr Caban | 03f7909 | 2008-08-20 18:20:50 +0200 | [diff] [blame] | 335 | { |
Nikolay Sivov | 9d66292 | 2011-12-24 16:10:33 +0300 | [diff] [blame] | 336 | if (prefix && *prefix) |
Piotr Caban | 03f7909 | 2008-08-20 18:20:50 +0200 | [diff] [blame] | 337 | { |
Nikolay Sivov | 9d66292 | 2011-12-24 16:10:33 +0300 | [diff] [blame] | 338 | BSTR qname = SysAllocStringLen(NULL, SysStringLen(prefix) + SysStringLen(local) + 1); |
| 339 | WCHAR *ptr; |
Piotr Caban | 03f7909 | 2008-08-20 18:20:50 +0200 | [diff] [blame] | 340 | |
Nikolay Sivov | 9d66292 | 2011-12-24 16:10:33 +0300 | [diff] [blame] | 341 | ptr = qname; |
| 342 | strcpyW(ptr, prefix); |
| 343 | ptr += SysStringLen(prefix); |
| 344 | *ptr++ = ':'; |
| 345 | strcpyW(ptr, local); |
| 346 | return qname; |
Piotr Caban | 619c2dc | 2011-10-31 12:32:59 +0100 | [diff] [blame] | 347 | } |
| 348 | else |
Nikolay Sivov | 9d66292 | 2011-12-24 16:10:33 +0300 | [diff] [blame] | 349 | return SysAllocString(local); |
Piotr Caban | 03f7909 | 2008-08-20 18:20:50 +0200 | [diff] [blame] | 350 | } |
| 351 | |
Nikolay Sivov | 9d66292 | 2011-12-24 16:10:33 +0300 | [diff] [blame] | 352 | static element_entry* alloc_element_entry(const xmlChar *local, const xmlChar *prefix, int nb_ns, |
| 353 | const xmlChar **namespaces) |
Piotr Caban | 03f7909 | 2008-08-20 18:20:50 +0200 | [diff] [blame] | 354 | { |
Nikolay Sivov | 9d66292 | 2011-12-24 16:10:33 +0300 | [diff] [blame] | 355 | element_entry *ret; |
| 356 | int i; |
| 357 | |
| 358 | ret = heap_alloc(sizeof(*ret)); |
| 359 | if (!ret) return ret; |
| 360 | |
| 361 | ret->local = bstr_from_xmlChar(local); |
| 362 | ret->prefix = bstr_from_xmlChar(prefix); |
| 363 | ret->qname = build_qname(ret->prefix, ret->local); |
| 364 | ret->ns = nb_ns ? heap_alloc(nb_ns*sizeof(ns)) : NULL; |
| 365 | ret->ns_count = nb_ns; |
| 366 | |
| 367 | for (i=0; i < nb_ns; i++) |
Piotr Caban | 619c2dc | 2011-10-31 12:32:59 +0100 | [diff] [blame] | 368 | { |
Nikolay Sivov | 9d66292 | 2011-12-24 16:10:33 +0300 | [diff] [blame] | 369 | ret->ns[i].prefix = bstr_from_xmlChar(namespaces[2*i]); |
| 370 | ret->ns[i].uri = bstr_from_xmlChar(namespaces[2*i+1]); |
Piotr Caban | 619c2dc | 2011-10-31 12:32:59 +0100 | [diff] [blame] | 371 | } |
| 372 | |
Nikolay Sivov | 9d66292 | 2011-12-24 16:10:33 +0300 | [diff] [blame] | 373 | return ret; |
Piotr Caban | 03f7909 | 2008-08-20 18:20:50 +0200 | [diff] [blame] | 374 | } |
| 375 | |
Nikolay Sivov | 9d66292 | 2011-12-24 16:10:33 +0300 | [diff] [blame] | 376 | static void free_element_entry(element_entry *element) |
Piotr Caban | 216b648 | 2011-10-31 12:33:08 +0100 | [diff] [blame] | 377 | { |
| 378 | int i; |
| 379 | |
Nikolay Sivov | 9d66292 | 2011-12-24 16:10:33 +0300 | [diff] [blame] | 380 | for (i=0; i<element->ns_count;i++) |
Piotr Caban | 216b648 | 2011-10-31 12:33:08 +0100 | [diff] [blame] | 381 | { |
Nikolay Sivov | 9d66292 | 2011-12-24 16:10:33 +0300 | [diff] [blame] | 382 | SysFreeString(element->ns[i].prefix); |
| 383 | SysFreeString(element->ns[i].uri); |
Piotr Caban | 216b648 | 2011-10-31 12:33:08 +0100 | [diff] [blame] | 384 | } |
| 385 | |
Nikolay Sivov | 9d66292 | 2011-12-24 16:10:33 +0300 | [diff] [blame] | 386 | SysFreeString(element->prefix); |
| 387 | SysFreeString(element->local); |
| 388 | |
| 389 | heap_free(element->ns); |
| 390 | heap_free(element); |
| 391 | } |
| 392 | |
| 393 | static void push_element_ns(saxlocator *locator, element_entry *element) |
| 394 | { |
| 395 | list_add_head(&locator->elements, &element->entry); |
| 396 | } |
| 397 | |
| 398 | static element_entry * pop_element_ns(saxlocator *locator) |
| 399 | { |
| 400 | element_entry *element = LIST_ENTRY(list_head(&locator->elements), element_entry, entry); |
| 401 | |
| 402 | if (element) |
| 403 | list_remove(&element->entry); |
| 404 | |
| 405 | return element; |
| 406 | } |
| 407 | |
| 408 | static BSTR find_element_uri(saxlocator *locator, const xmlChar *uri) |
| 409 | { |
| 410 | element_entry *element; |
| 411 | BSTR uriW; |
| 412 | int i; |
| 413 | |
| 414 | if (!uri) return NULL; |
| 415 | |
| 416 | uriW = bstr_from_xmlChar(uri); |
| 417 | |
| 418 | LIST_FOR_EACH_ENTRY(element, &locator->elements, element_entry, entry) |
| 419 | { |
| 420 | for (i=0; i < element->ns_count; i++) |
| 421 | if (!strcmpW(uriW, element->ns[i].uri)) |
| 422 | { |
| 423 | SysFreeString(uriW); |
| 424 | return element->ns[i].uri; |
| 425 | } |
| 426 | } |
| 427 | |
| 428 | SysFreeString(uriW); |
| 429 | ERR("namespace uri not found, %s\n", debugstr_a((char*)uri)); |
Piotr Caban | 216b648 | 2011-10-31 12:33:08 +0100 | [diff] [blame] | 430 | return NULL; |
| 431 | } |
| 432 | |
Nikolay Sivov | 9d66292 | 2011-12-24 16:10:33 +0300 | [diff] [blame] | 433 | /* used to localize version dependent error check behaviour */ |
| 434 | static inline BOOL sax_callback_failed(saxlocator *This, HRESULT hr) |
| 435 | { |
Nikolay Sivov | bcd8585 | 2012-04-15 13:47:30 +0400 | [diff] [blame] | 436 | return This->saxreader->version >= MSXML4 ? FAILED(hr) : hr != S_OK; |
Nikolay Sivov | 9d66292 | 2011-12-24 16:10:33 +0300 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | /* index value -1 means it tries to loop for a first time */ |
| 440 | static inline BOOL iterate_endprefix_index(saxlocator *This, const element_entry *element, int *i) |
| 441 | { |
Nikolay Sivov | f9c3a51 | 2012-04-16 02:29:18 +0400 | [diff] [blame] | 442 | if (This->saxreader->version >= MSXML4) |
Nikolay Sivov | 9d66292 | 2011-12-24 16:10:33 +0300 | [diff] [blame] | 443 | { |
| 444 | if (*i == -1) *i = 0; else ++*i; |
| 445 | return *i < element->ns_count; |
| 446 | } |
| 447 | else |
| 448 | { |
| 449 | if (*i == -1) *i = element->ns_count-1; else --*i; |
| 450 | return *i >= 0; |
| 451 | } |
| 452 | } |
| 453 | |
Andrew Nguyen | 9c5d5d8 | 2011-07-15 07:38:07 -0500 | [diff] [blame] | 454 | static BOOL bstr_pool_insert(struct bstrpool *pool, BSTR pool_entry) |
| 455 | { |
| 456 | if (!pool->pool) |
| 457 | { |
| 458 | pool->pool = HeapAlloc(GetProcessHeap(), 0, 16 * sizeof(*pool->pool)); |
| 459 | if (!pool->pool) |
| 460 | return FALSE; |
| 461 | |
| 462 | pool->index = 0; |
| 463 | pool->len = 16; |
| 464 | } |
| 465 | else if (pool->index == pool->len) |
| 466 | { |
| 467 | BSTR *realloc = HeapReAlloc(GetProcessHeap(), 0, pool->pool, pool->len * 2 * sizeof(*realloc)); |
| 468 | |
| 469 | if (!realloc) |
| 470 | return FALSE; |
| 471 | |
| 472 | pool->pool = realloc; |
| 473 | pool->len *= 2; |
| 474 | } |
| 475 | |
| 476 | pool->pool[pool->index++] = pool_entry; |
| 477 | return TRUE; |
| 478 | } |
| 479 | |
| 480 | static void free_bstr_pool(struct bstrpool *pool) |
| 481 | { |
| 482 | unsigned int i; |
| 483 | |
| 484 | for (i = 0; i < pool->index; i++) |
| 485 | SysFreeString(pool->pool[i]); |
| 486 | |
| 487 | HeapFree(GetProcessHeap(), 0, pool->pool); |
| 488 | |
| 489 | pool->pool = NULL; |
| 490 | pool->index = pool->len = 0; |
| 491 | } |
| 492 | |
Piotr Caban | 319d86c | 2008-08-03 14:37:37 +0200 | [diff] [blame] | 493 | static BSTR bstr_from_xmlCharN(const xmlChar *buf, int len) |
Piotr Caban | 6df49d5 | 2008-07-30 20:24:12 +0200 | [diff] [blame] | 494 | { |
| 495 | DWORD dLen; |
Piotr Caban | 6df49d5 | 2008-07-30 20:24:12 +0200 | [diff] [blame] | 496 | BSTR bstr; |
| 497 | |
| 498 | if (!buf) |
| 499 | return NULL; |
| 500 | |
| 501 | dLen = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)buf, len, NULL, 0); |
| 502 | if(len != -1) dLen++; |
Piotr Caban | 7a22365 | 2010-07-17 14:06:53 +0200 | [diff] [blame] | 503 | bstr = SysAllocStringLen(NULL, dLen-1); |
| 504 | if (!bstr) |
Piotr Caban | 6df49d5 | 2008-07-30 20:24:12 +0200 | [diff] [blame] | 505 | return NULL; |
Piotr Caban | 7a22365 | 2010-07-17 14:06:53 +0200 | [diff] [blame] | 506 | MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)buf, len, bstr, dLen); |
| 507 | if(len != -1) bstr[dLen-1] = '\0'; |
Piotr Caban | 6df49d5 | 2008-07-30 20:24:12 +0200 | [diff] [blame] | 508 | |
| 509 | return bstr; |
| 510 | } |
| 511 | |
Piotr Caban | 319d86c | 2008-08-03 14:37:37 +0200 | [diff] [blame] | 512 | static BSTR QName_from_xmlChar(const xmlChar *prefix, const xmlChar *name) |
| 513 | { |
Nikolay Sivov | 2329d2a | 2010-10-29 01:14:08 +0400 | [diff] [blame] | 514 | xmlChar *qname; |
Piotr Caban | 319d86c | 2008-08-03 14:37:37 +0200 | [diff] [blame] | 515 | BSTR bstr; |
| 516 | |
| 517 | if(!name) return NULL; |
| 518 | |
Nikolay Sivov | 2329d2a | 2010-10-29 01:14:08 +0400 | [diff] [blame] | 519 | if(!prefix || !*prefix) |
Piotr Caban | 319d86c | 2008-08-03 14:37:37 +0200 | [diff] [blame] | 520 | return bstr_from_xmlChar(name); |
| 521 | |
Nikolay Sivov | 2329d2a | 2010-10-29 01:14:08 +0400 | [diff] [blame] | 522 | qname = xmlBuildQName(name, prefix, NULL, 0); |
| 523 | bstr = bstr_from_xmlChar(qname); |
| 524 | xmlFree(qname); |
Piotr Caban | 319d86c | 2008-08-03 14:37:37 +0200 | [diff] [blame] | 525 | |
| 526 | return bstr; |
| 527 | } |
| 528 | |
Andrew Nguyen | 9c5d5d8 | 2011-07-15 07:38:07 -0500 | [diff] [blame] | 529 | static BSTR pooled_bstr_from_xmlChar(struct bstrpool *pool, const xmlChar *buf) |
| 530 | { |
| 531 | BSTR pool_entry = bstr_from_xmlChar(buf); |
| 532 | |
| 533 | if (pool_entry && !bstr_pool_insert(pool, pool_entry)) |
| 534 | { |
| 535 | SysFreeString(pool_entry); |
| 536 | return NULL; |
| 537 | } |
| 538 | |
| 539 | return pool_entry; |
| 540 | } |
| 541 | |
| 542 | static BSTR pooled_bstr_from_xmlCharN(struct bstrpool *pool, const xmlChar *buf, int len) |
| 543 | { |
| 544 | BSTR pool_entry = bstr_from_xmlCharN(buf, len); |
| 545 | |
| 546 | if (pool_entry && !bstr_pool_insert(pool, pool_entry)) |
| 547 | { |
| 548 | SysFreeString(pool_entry); |
| 549 | return NULL; |
| 550 | } |
| 551 | |
| 552 | return pool_entry; |
| 553 | } |
| 554 | |
Piotr Caban | bba7eb5 | 2008-07-19 22:32:10 +0200 | [diff] [blame] | 555 | static void format_error_message_from_id(saxlocator *This, HRESULT hr) |
| 556 | { |
| 557 | xmlStopParser(This->pParserCtxt); |
| 558 | This->ret = hr; |
| 559 | |
Nikolay Sivov | 8f9804e | 2010-10-29 01:04:44 +0400 | [diff] [blame] | 560 | if(has_error_handler(This)) |
Piotr Caban | bba7eb5 | 2008-07-19 22:32:10 +0200 | [diff] [blame] | 561 | { |
| 562 | WCHAR msg[1024]; |
| 563 | if(!FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM, |
| 564 | NULL, hr, 0, msg, sizeof(msg), NULL)) |
| 565 | { |
| 566 | FIXME("MSXML errors not yet supported.\n"); |
| 567 | msg[0] = '\0'; |
| 568 | } |
| 569 | |
Piotr Caban | c52e091 | 2008-07-31 16:48:03 +0200 | [diff] [blame] | 570 | if(This->vbInterface) |
| 571 | { |
| 572 | BSTR bstrMsg = SysAllocString(msg); |
| 573 | IVBSAXErrorHandler_fatalError(This->saxreader->vberrorHandler, |
Michael Stefaniuc | 13e1997 | 2010-12-27 23:12:06 +0100 | [diff] [blame] | 574 | &This->IVBSAXLocator_iface, &bstrMsg, hr); |
Nikolay Sivov | bd7787c | 2010-10-27 01:15:38 +0400 | [diff] [blame] | 575 | SysFreeString(bstrMsg); |
Piotr Caban | c52e091 | 2008-07-31 16:48:03 +0200 | [diff] [blame] | 576 | } |
| 577 | else |
| 578 | ISAXErrorHandler_fatalError(This->saxreader->errorHandler, |
Michael Stefaniuc | 13e1997 | 2010-12-27 23:12:06 +0100 | [diff] [blame] | 579 | &This->ISAXLocator_iface, msg, hr); |
Piotr Caban | bba7eb5 | 2008-07-19 22:32:10 +0200 | [diff] [blame] | 580 | } |
| 581 | } |
| 582 | |
Piotr Caban | c253bab | 2011-11-28 15:05:25 +0100 | [diff] [blame] | 583 | static void update_position(saxlocator *This, BOOL fix_column) |
Piotr Caban | bb849dc | 2008-07-23 16:39:04 +0200 | [diff] [blame] | 584 | { |
Piotr Caban | c253bab | 2011-11-28 15:05:25 +0100 | [diff] [blame] | 585 | const xmlChar *p = This->pParserCtxt->input->cur-1; |
| 586 | |
| 587 | This->line = xmlSAX2GetLineNumber(This->pParserCtxt); |
| 588 | if(fix_column) |
Piotr Caban | bb849dc | 2008-07-23 16:39:04 +0200 | [diff] [blame] | 589 | { |
Piotr Caban | c253bab | 2011-11-28 15:05:25 +0100 | [diff] [blame] | 590 | This->column = 1; |
| 591 | for(; *p!='\n' && *p!='\r' && p>=This->pParserCtxt->input->base; p--) |
| 592 | This->column++; |
Piotr Caban | bb849dc | 2008-07-23 16:39:04 +0200 | [diff] [blame] | 593 | } |
Piotr Caban | c253bab | 2011-11-28 15:05:25 +0100 | [diff] [blame] | 594 | else |
Piotr Caban | df5e40e | 2008-07-31 16:45:30 +0200 | [diff] [blame] | 595 | { |
Piotr Caban | c253bab | 2011-11-28 15:05:25 +0100 | [diff] [blame] | 596 | This->column = xmlSAX2GetColumnNumber(This->pParserCtxt); |
Piotr Caban | c801c18 | 2008-10-07 22:10:43 +0200 | [diff] [blame] | 597 | } |
Piotr Caban | bb849dc | 2008-07-23 16:39:04 +0200 | [diff] [blame] | 598 | } |
| 599 | |
Piotr Caban | cafbf85 | 2008-07-31 16:47:41 +0200 | [diff] [blame] | 600 | /*** IVBSAXAttributes interface ***/ |
| 601 | /*** IUnknown methods ***/ |
| 602 | static HRESULT WINAPI ivbsaxattributes_QueryInterface( |
| 603 | IVBSAXAttributes* iface, |
| 604 | REFIID riid, |
| 605 | void **ppvObject) |
| 606 | { |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 607 | saxlocator *This = impl_from_IVBSAXAttributes(iface); |
Piotr Caban | cafbf85 | 2008-07-31 16:47:41 +0200 | [diff] [blame] | 608 | TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject); |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 609 | return IVBSAXLocator_QueryInterface(&This->IVBSAXLocator_iface, riid, ppvObject); |
Piotr Caban | cafbf85 | 2008-07-31 16:47:41 +0200 | [diff] [blame] | 610 | } |
| 611 | |
| 612 | static ULONG WINAPI ivbsaxattributes_AddRef(IVBSAXAttributes* iface) |
| 613 | { |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 614 | saxlocator *This = impl_from_IVBSAXAttributes(iface); |
| 615 | return ISAXLocator_AddRef(&This->ISAXLocator_iface); |
Piotr Caban | cafbf85 | 2008-07-31 16:47:41 +0200 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | static ULONG WINAPI ivbsaxattributes_Release(IVBSAXAttributes* iface) |
| 619 | { |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 620 | saxlocator *This = impl_from_IVBSAXAttributes(iface); |
| 621 | return ISAXLocator_Release(&This->ISAXLocator_iface); |
Piotr Caban | cafbf85 | 2008-07-31 16:47:41 +0200 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | /*** IDispatch methods ***/ |
| 625 | static HRESULT WINAPI ivbsaxattributes_GetTypeInfoCount( IVBSAXAttributes *iface, UINT* pctinfo ) |
| 626 | { |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 627 | saxlocator *This = impl_from_IVBSAXAttributes( iface ); |
Piotr Caban | cafbf85 | 2008-07-31 16:47:41 +0200 | [diff] [blame] | 628 | |
| 629 | TRACE("(%p)->(%p)\n", This, pctinfo); |
| 630 | |
| 631 | *pctinfo = 1; |
| 632 | |
| 633 | return S_OK; |
| 634 | } |
| 635 | |
| 636 | static HRESULT WINAPI ivbsaxattributes_GetTypeInfo( |
| 637 | IVBSAXAttributes *iface, |
| 638 | UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo ) |
| 639 | { |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 640 | saxlocator *This = impl_from_IVBSAXAttributes( iface ); |
Piotr Caban | cafbf85 | 2008-07-31 16:47:41 +0200 | [diff] [blame] | 641 | HRESULT hr; |
| 642 | |
| 643 | TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo); |
| 644 | |
| 645 | hr = get_typeinfo(IVBSAXAttributes_tid, ppTInfo); |
| 646 | |
| 647 | return hr; |
| 648 | } |
| 649 | |
| 650 | static HRESULT WINAPI ivbsaxattributes_GetIDsOfNames( |
| 651 | IVBSAXAttributes *iface, |
| 652 | REFIID riid, |
| 653 | LPOLESTR* rgszNames, |
| 654 | UINT cNames, |
| 655 | LCID lcid, |
| 656 | DISPID* rgDispId) |
| 657 | { |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 658 | saxlocator *This = impl_from_IVBSAXAttributes( iface ); |
Piotr Caban | cafbf85 | 2008-07-31 16:47:41 +0200 | [diff] [blame] | 659 | ITypeInfo *typeinfo; |
| 660 | HRESULT hr; |
| 661 | |
| 662 | TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames, |
| 663 | lcid, rgDispId); |
| 664 | |
| 665 | if(!rgszNames || cNames == 0 || !rgDispId) |
| 666 | return E_INVALIDARG; |
| 667 | |
| 668 | hr = get_typeinfo(IVBSAXAttributes_tid, &typeinfo); |
| 669 | if(SUCCEEDED(hr)) |
| 670 | { |
| 671 | hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId); |
| 672 | ITypeInfo_Release(typeinfo); |
| 673 | } |
| 674 | |
| 675 | return hr; |
| 676 | } |
| 677 | |
| 678 | static HRESULT WINAPI ivbsaxattributes_Invoke( |
| 679 | IVBSAXAttributes *iface, |
| 680 | DISPID dispIdMember, |
| 681 | REFIID riid, |
| 682 | LCID lcid, |
| 683 | WORD wFlags, |
| 684 | DISPPARAMS* pDispParams, |
| 685 | VARIANT* pVarResult, |
| 686 | EXCEPINFO* pExcepInfo, |
| 687 | UINT* puArgErr) |
| 688 | { |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 689 | saxlocator *This = impl_from_IVBSAXAttributes( iface ); |
Piotr Caban | cafbf85 | 2008-07-31 16:47:41 +0200 | [diff] [blame] | 690 | ITypeInfo *typeinfo; |
| 691 | HRESULT hr; |
| 692 | |
| 693 | TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid), |
| 694 | lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr); |
| 695 | |
| 696 | hr = get_typeinfo(IVBSAXAttributes_tid, &typeinfo); |
| 697 | if(SUCCEEDED(hr)) |
| 698 | { |
Michael Stefaniuc | 13e1997 | 2010-12-27 23:12:06 +0100 | [diff] [blame] | 699 | hr = ITypeInfo_Invoke(typeinfo, &This->IVBSAXAttributes_iface, dispIdMember, wFlags, |
| 700 | pDispParams, pVarResult, pExcepInfo, puArgErr); |
Piotr Caban | cafbf85 | 2008-07-31 16:47:41 +0200 | [diff] [blame] | 701 | ITypeInfo_Release(typeinfo); |
| 702 | } |
| 703 | |
| 704 | return hr; |
| 705 | } |
| 706 | |
| 707 | /*** IVBSAXAttributes methods ***/ |
| 708 | static HRESULT WINAPI ivbsaxattributes_get_length( |
| 709 | IVBSAXAttributes* iface, |
| 710 | int *nLength) |
| 711 | { |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 712 | saxlocator *This = impl_from_IVBSAXAttributes( iface ); |
Michael Stefaniuc | 13e1997 | 2010-12-27 23:12:06 +0100 | [diff] [blame] | 713 | return ISAXAttributes_getLength(&This->ISAXAttributes_iface, nLength); |
Piotr Caban | cafbf85 | 2008-07-31 16:47:41 +0200 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | static HRESULT WINAPI ivbsaxattributes_getURI( |
| 717 | IVBSAXAttributes* iface, |
| 718 | int nIndex, |
| 719 | BSTR *uri) |
| 720 | { |
| 721 | int len; |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 722 | saxlocator *This = impl_from_IVBSAXAttributes( iface ); |
Michael Stefaniuc | 13e1997 | 2010-12-27 23:12:06 +0100 | [diff] [blame] | 723 | return ISAXAttributes_getURI(&This->ISAXAttributes_iface, nIndex, (const WCHAR**)uri, &len); |
Piotr Caban | cafbf85 | 2008-07-31 16:47:41 +0200 | [diff] [blame] | 724 | } |
| 725 | |
| 726 | static HRESULT WINAPI ivbsaxattributes_getLocalName( |
| 727 | IVBSAXAttributes* iface, |
| 728 | int nIndex, |
| 729 | BSTR *localName) |
| 730 | { |
| 731 | int len; |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 732 | saxlocator *This = impl_from_IVBSAXAttributes( iface ); |
Michael Stefaniuc | 13e1997 | 2010-12-27 23:12:06 +0100 | [diff] [blame] | 733 | return ISAXAttributes_getLocalName(&This->ISAXAttributes_iface, nIndex, |
| 734 | (const WCHAR**)localName, &len); |
Piotr Caban | cafbf85 | 2008-07-31 16:47:41 +0200 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | static HRESULT WINAPI ivbsaxattributes_getQName( |
| 738 | IVBSAXAttributes* iface, |
| 739 | int nIndex, |
| 740 | BSTR *QName) |
| 741 | { |
| 742 | int len; |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 743 | saxlocator *This = impl_from_IVBSAXAttributes( iface ); |
Michael Stefaniuc | 13e1997 | 2010-12-27 23:12:06 +0100 | [diff] [blame] | 744 | return ISAXAttributes_getQName(&This->ISAXAttributes_iface, nIndex, (const WCHAR**)QName, &len); |
Piotr Caban | cafbf85 | 2008-07-31 16:47:41 +0200 | [diff] [blame] | 745 | } |
| 746 | |
| 747 | static HRESULT WINAPI ivbsaxattributes_getIndexFromName( |
| 748 | IVBSAXAttributes* iface, |
| 749 | BSTR uri, |
| 750 | BSTR localName, |
| 751 | int *index) |
| 752 | { |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 753 | saxlocator *This = impl_from_IVBSAXAttributes( iface ); |
Michael Stefaniuc | 13e1997 | 2010-12-27 23:12:06 +0100 | [diff] [blame] | 754 | return ISAXAttributes_getIndexFromName(&This->ISAXAttributes_iface, uri, SysStringLen(uri), |
Michael Stefaniuc | 6a5dda7 | 2009-01-26 11:01:02 +0100 | [diff] [blame] | 755 | localName, SysStringLen(localName), index); |
Piotr Caban | cafbf85 | 2008-07-31 16:47:41 +0200 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | static HRESULT WINAPI ivbsaxattributes_getIndexFromQName( |
| 759 | IVBSAXAttributes* iface, |
| 760 | BSTR QName, |
| 761 | int *index) |
| 762 | { |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 763 | saxlocator *This = impl_from_IVBSAXAttributes( iface ); |
Michael Stefaniuc | 13e1997 | 2010-12-27 23:12:06 +0100 | [diff] [blame] | 764 | return ISAXAttributes_getIndexFromQName(&This->ISAXAttributes_iface, QName, |
Michael Stefaniuc | 6a5dda7 | 2009-01-26 11:01:02 +0100 | [diff] [blame] | 765 | SysStringLen(QName), index); |
Piotr Caban | cafbf85 | 2008-07-31 16:47:41 +0200 | [diff] [blame] | 766 | } |
| 767 | |
| 768 | static HRESULT WINAPI ivbsaxattributes_getType( |
| 769 | IVBSAXAttributes* iface, |
| 770 | int nIndex, |
| 771 | BSTR *type) |
| 772 | { |
| 773 | int len; |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 774 | saxlocator *This = impl_from_IVBSAXAttributes( iface ); |
Michael Stefaniuc | 13e1997 | 2010-12-27 23:12:06 +0100 | [diff] [blame] | 775 | return ISAXAttributes_getType(&This->ISAXAttributes_iface, nIndex, (const WCHAR**)type, &len); |
Piotr Caban | cafbf85 | 2008-07-31 16:47:41 +0200 | [diff] [blame] | 776 | } |
| 777 | |
| 778 | static HRESULT WINAPI ivbsaxattributes_getTypeFromName( |
| 779 | IVBSAXAttributes* iface, |
| 780 | BSTR uri, |
| 781 | BSTR localName, |
| 782 | BSTR *type) |
| 783 | { |
| 784 | int len; |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 785 | saxlocator *This = impl_from_IVBSAXAttributes( iface ); |
Michael Stefaniuc | 13e1997 | 2010-12-27 23:12:06 +0100 | [diff] [blame] | 786 | return ISAXAttributes_getTypeFromName(&This->ISAXAttributes_iface, uri, SysStringLen(uri), |
Michael Stefaniuc | 6a5dda7 | 2009-01-26 11:01:02 +0100 | [diff] [blame] | 787 | localName, SysStringLen(localName), (const WCHAR**)type, &len); |
Piotr Caban | cafbf85 | 2008-07-31 16:47:41 +0200 | [diff] [blame] | 788 | } |
| 789 | |
| 790 | static HRESULT WINAPI ivbsaxattributes_getTypeFromQName( |
| 791 | IVBSAXAttributes* iface, |
| 792 | BSTR QName, |
| 793 | BSTR *type) |
| 794 | { |
| 795 | int len; |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 796 | saxlocator *This = impl_from_IVBSAXAttributes( iface ); |
Michael Stefaniuc | 13e1997 | 2010-12-27 23:12:06 +0100 | [diff] [blame] | 797 | return ISAXAttributes_getTypeFromQName(&This->ISAXAttributes_iface, QName, SysStringLen(QName), |
| 798 | (const WCHAR**)type, &len); |
Piotr Caban | cafbf85 | 2008-07-31 16:47:41 +0200 | [diff] [blame] | 799 | } |
| 800 | |
| 801 | static HRESULT WINAPI ivbsaxattributes_getValue( |
| 802 | IVBSAXAttributes* iface, |
| 803 | int nIndex, |
| 804 | BSTR *value) |
| 805 | { |
| 806 | int len; |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 807 | saxlocator *This = impl_from_IVBSAXAttributes( iface ); |
Michael Stefaniuc | 13e1997 | 2010-12-27 23:12:06 +0100 | [diff] [blame] | 808 | return ISAXAttributes_getValue(&This->ISAXAttributes_iface, nIndex, (const WCHAR**)value, &len); |
Piotr Caban | cafbf85 | 2008-07-31 16:47:41 +0200 | [diff] [blame] | 809 | } |
| 810 | |
| 811 | static HRESULT WINAPI ivbsaxattributes_getValueFromName( |
| 812 | IVBSAXAttributes* iface, |
| 813 | BSTR uri, |
| 814 | BSTR localName, |
| 815 | BSTR *value) |
| 816 | { |
| 817 | int len; |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 818 | saxlocator *This = impl_from_IVBSAXAttributes( iface ); |
Michael Stefaniuc | 13e1997 | 2010-12-27 23:12:06 +0100 | [diff] [blame] | 819 | return ISAXAttributes_getValueFromName(&This->ISAXAttributes_iface, uri, SysStringLen(uri), |
Michael Stefaniuc | 6a5dda7 | 2009-01-26 11:01:02 +0100 | [diff] [blame] | 820 | localName, SysStringLen(localName), (const WCHAR**)value, &len); |
Piotr Caban | cafbf85 | 2008-07-31 16:47:41 +0200 | [diff] [blame] | 821 | } |
| 822 | |
| 823 | static HRESULT WINAPI ivbsaxattributes_getValueFromQName( |
| 824 | IVBSAXAttributes* iface, |
| 825 | BSTR QName, |
| 826 | BSTR *value) |
| 827 | { |
| 828 | int len; |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 829 | saxlocator *This = impl_from_IVBSAXAttributes( iface ); |
Michael Stefaniuc | 13e1997 | 2010-12-27 23:12:06 +0100 | [diff] [blame] | 830 | return ISAXAttributes_getValueFromQName(&This->ISAXAttributes_iface, QName, |
Michael Stefaniuc | 6a5dda7 | 2009-01-26 11:01:02 +0100 | [diff] [blame] | 831 | SysStringLen(QName), (const WCHAR**)value, &len); |
Piotr Caban | cafbf85 | 2008-07-31 16:47:41 +0200 | [diff] [blame] | 832 | } |
| 833 | |
| 834 | static const struct IVBSAXAttributesVtbl ivbsaxattributes_vtbl = |
| 835 | { |
| 836 | ivbsaxattributes_QueryInterface, |
| 837 | ivbsaxattributes_AddRef, |
| 838 | ivbsaxattributes_Release, |
| 839 | ivbsaxattributes_GetTypeInfoCount, |
| 840 | ivbsaxattributes_GetTypeInfo, |
| 841 | ivbsaxattributes_GetIDsOfNames, |
| 842 | ivbsaxattributes_Invoke, |
| 843 | ivbsaxattributes_get_length, |
| 844 | ivbsaxattributes_getURI, |
| 845 | ivbsaxattributes_getLocalName, |
| 846 | ivbsaxattributes_getQName, |
| 847 | ivbsaxattributes_getIndexFromName, |
| 848 | ivbsaxattributes_getIndexFromQName, |
| 849 | ivbsaxattributes_getType, |
| 850 | ivbsaxattributes_getTypeFromName, |
| 851 | ivbsaxattributes_getTypeFromQName, |
| 852 | ivbsaxattributes_getValue, |
| 853 | ivbsaxattributes_getValueFromName, |
| 854 | ivbsaxattributes_getValueFromQName |
| 855 | }; |
| 856 | |
Piotr Caban | 5816c38 | 2008-07-27 19:55:05 +0200 | [diff] [blame] | 857 | /*** ISAXAttributes interface ***/ |
| 858 | /*** IUnknown methods ***/ |
| 859 | static HRESULT WINAPI isaxattributes_QueryInterface( |
| 860 | ISAXAttributes* iface, |
| 861 | REFIID riid, |
| 862 | void **ppvObject) |
| 863 | { |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 864 | saxlocator *This = impl_from_ISAXAttributes(iface); |
Piotr Caban | 5816c38 | 2008-07-27 19:55:05 +0200 | [diff] [blame] | 865 | TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject); |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 866 | return ISAXLocator_QueryInterface(&This->ISAXLocator_iface, riid, ppvObject); |
Piotr Caban | 5816c38 | 2008-07-27 19:55:05 +0200 | [diff] [blame] | 867 | } |
| 868 | |
| 869 | static ULONG WINAPI isaxattributes_AddRef(ISAXAttributes* iface) |
| 870 | { |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 871 | saxlocator *This = impl_from_ISAXAttributes(iface); |
Piotr Caban | 5816c38 | 2008-07-27 19:55:05 +0200 | [diff] [blame] | 872 | TRACE("%p\n", This); |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 873 | return ISAXLocator_AddRef(&This->ISAXLocator_iface); |
Piotr Caban | 5816c38 | 2008-07-27 19:55:05 +0200 | [diff] [blame] | 874 | } |
| 875 | |
| 876 | static ULONG WINAPI isaxattributes_Release(ISAXAttributes* iface) |
| 877 | { |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 878 | saxlocator *This = impl_from_ISAXAttributes(iface); |
Piotr Caban | 5816c38 | 2008-07-27 19:55:05 +0200 | [diff] [blame] | 879 | |
| 880 | TRACE("%p\n", This); |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 881 | return ISAXLocator_Release(&This->ISAXLocator_iface); |
Piotr Caban | 5816c38 | 2008-07-27 19:55:05 +0200 | [diff] [blame] | 882 | } |
| 883 | |
| 884 | /*** ISAXAttributes methods ***/ |
| 885 | static HRESULT WINAPI isaxattributes_getLength( |
| 886 | ISAXAttributes* iface, |
| 887 | int *length) |
| 888 | { |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 889 | saxlocator *This = impl_from_ISAXAttributes( iface ); |
Piotr Caban | 5816c38 | 2008-07-27 19:55:05 +0200 | [diff] [blame] | 890 | |
Piotr Caban | 58b26f3 | 2008-07-30 20:26:50 +0200 | [diff] [blame] | 891 | *length = This->nb_attributes; |
| 892 | TRACE("Length set to %d\n", *length); |
| 893 | return S_OK; |
Piotr Caban | 5816c38 | 2008-07-27 19:55:05 +0200 | [diff] [blame] | 894 | } |
| 895 | |
| 896 | static HRESULT WINAPI isaxattributes_getURI( |
| 897 | ISAXAttributes* iface, |
Nikolay Sivov | d65f298 | 2011-10-05 14:19:29 -0500 | [diff] [blame] | 898 | int index, |
| 899 | const WCHAR **url, |
| 900 | int *size) |
Piotr Caban | 5816c38 | 2008-07-27 19:55:05 +0200 | [diff] [blame] | 901 | { |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 902 | saxlocator *This = impl_from_ISAXAttributes( iface ); |
Nikolay Sivov | d65f298 | 2011-10-05 14:19:29 -0500 | [diff] [blame] | 903 | TRACE("(%p)->(%d)\n", This, index); |
Piotr Caban | 5816c38 | 2008-07-27 19:55:05 +0200 | [diff] [blame] | 904 | |
Nikolay Sivov | d65f298 | 2011-10-05 14:19:29 -0500 | [diff] [blame] | 905 | if(index >= This->nb_attributes || index < 0) return E_INVALIDARG; |
| 906 | if(!url || !size) return E_POINTER; |
Piotr Caban | 7be136b | 2008-08-03 14:37:52 +0200 | [diff] [blame] | 907 | |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 908 | *size = SysStringLen(This->attributes[index].szURI); |
| 909 | *url = This->attributes[index].szURI; |
Nikolay Sivov | d65f298 | 2011-10-05 14:19:29 -0500 | [diff] [blame] | 910 | |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 911 | TRACE("(%s:%d)\n", debugstr_w(This->attributes[index].szURI), *size); |
Piotr Caban | 7be136b | 2008-08-03 14:37:52 +0200 | [diff] [blame] | 912 | |
| 913 | return S_OK; |
Piotr Caban | 5816c38 | 2008-07-27 19:55:05 +0200 | [diff] [blame] | 914 | } |
| 915 | |
| 916 | static HRESULT WINAPI isaxattributes_getLocalName( |
| 917 | ISAXAttributes* iface, |
| 918 | int nIndex, |
| 919 | const WCHAR **pLocalName, |
| 920 | int *pLocalNameLength) |
| 921 | { |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 922 | saxlocator *This = impl_from_ISAXAttributes( iface ); |
Piotr Caban | 421a9a6 | 2008-07-30 20:27:07 +0200 | [diff] [blame] | 923 | TRACE("(%p)->(%d)\n", This, nIndex); |
Piotr Caban | 5816c38 | 2008-07-27 19:55:05 +0200 | [diff] [blame] | 924 | |
Piotr Caban | 7a5a781 | 2008-08-03 14:37:45 +0200 | [diff] [blame] | 925 | if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG; |
| 926 | if(!pLocalName || !pLocalNameLength) return E_POINTER; |
Piotr Caban | 421a9a6 | 2008-07-30 20:27:07 +0200 | [diff] [blame] | 927 | |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 928 | *pLocalNameLength = SysStringLen(This->attributes[nIndex].szLocalname); |
| 929 | *pLocalName = This->attributes[nIndex].szLocalname; |
Piotr Caban | 421a9a6 | 2008-07-30 20:27:07 +0200 | [diff] [blame] | 930 | |
| 931 | return S_OK; |
Piotr Caban | 5816c38 | 2008-07-27 19:55:05 +0200 | [diff] [blame] | 932 | } |
| 933 | |
| 934 | static HRESULT WINAPI isaxattributes_getQName( |
| 935 | ISAXAttributes* iface, |
| 936 | int nIndex, |
| 937 | const WCHAR **pQName, |
| 938 | int *pQNameLength) |
| 939 | { |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 940 | saxlocator *This = impl_from_ISAXAttributes( iface ); |
Piotr Caban | 6818cc6 | 2008-07-31 16:45:42 +0200 | [diff] [blame] | 941 | TRACE("(%p)->(%d)\n", This, nIndex); |
Piotr Caban | 5816c38 | 2008-07-27 19:55:05 +0200 | [diff] [blame] | 942 | |
Piotr Caban | 7a5a781 | 2008-08-03 14:37:45 +0200 | [diff] [blame] | 943 | if(nIndex>=This->nb_attributes || nIndex<0) return E_INVALIDARG; |
| 944 | if(!pQName || !pQNameLength) return E_POINTER; |
Piotr Caban | 6818cc6 | 2008-07-31 16:45:42 +0200 | [diff] [blame] | 945 | |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 946 | *pQNameLength = SysStringLen(This->attributes[nIndex].szQName); |
| 947 | *pQName = This->attributes[nIndex].szQName; |
Piotr Caban | 6818cc6 | 2008-07-31 16:45:42 +0200 | [diff] [blame] | 948 | |
| 949 | return S_OK; |
Piotr Caban | 5816c38 | 2008-07-27 19:55:05 +0200 | [diff] [blame] | 950 | } |
| 951 | |
| 952 | static HRESULT WINAPI isaxattributes_getName( |
| 953 | ISAXAttributes* iface, |
Nikolay Sivov | d65f298 | 2011-10-05 14:19:29 -0500 | [diff] [blame] | 954 | int index, |
| 955 | const WCHAR **uri, |
Piotr Caban | 5816c38 | 2008-07-27 19:55:05 +0200 | [diff] [blame] | 956 | int *pUriLength, |
Nikolay Sivov | d65f298 | 2011-10-05 14:19:29 -0500 | [diff] [blame] | 957 | const WCHAR **localName, |
Piotr Caban | 5816c38 | 2008-07-27 19:55:05 +0200 | [diff] [blame] | 958 | int *pLocalNameSize, |
Nikolay Sivov | d65f298 | 2011-10-05 14:19:29 -0500 | [diff] [blame] | 959 | const WCHAR **QName, |
Piotr Caban | 5816c38 | 2008-07-27 19:55:05 +0200 | [diff] [blame] | 960 | int *pQNameLength) |
| 961 | { |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 962 | saxlocator *This = impl_from_ISAXAttributes( iface ); |
Nikolay Sivov | d65f298 | 2011-10-05 14:19:29 -0500 | [diff] [blame] | 963 | TRACE("(%p)->(%d)\n", This, index); |
Piotr Caban | 5816c38 | 2008-07-27 19:55:05 +0200 | [diff] [blame] | 964 | |
Nikolay Sivov | d65f298 | 2011-10-05 14:19:29 -0500 | [diff] [blame] | 965 | if(index>=This->nb_attributes || index<0) return E_INVALIDARG; |
| 966 | if(!uri || !pUriLength || !localName || !pLocalNameSize |
| 967 | || !QName || !pQNameLength) return E_POINTER; |
Piotr Caban | 5e1af9b | 2008-08-20 18:30:16 +0200 | [diff] [blame] | 968 | |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 969 | *pUriLength = SysStringLen(This->attributes[index].szURI); |
| 970 | *uri = This->attributes[index].szURI; |
| 971 | *pLocalNameSize = SysStringLen(This->attributes[index].szLocalname); |
| 972 | *localName = This->attributes[index].szLocalname; |
| 973 | *pQNameLength = SysStringLen(This->attributes[index].szQName); |
| 974 | *QName = This->attributes[index].szQName; |
Nikolay Sivov | d65f298 | 2011-10-05 14:19:29 -0500 | [diff] [blame] | 975 | |
| 976 | TRACE("(%s, %s, %s)\n", debugstr_w(*uri), debugstr_w(*localName), debugstr_w(*QName)); |
Piotr Caban | 5e1af9b | 2008-08-20 18:30:16 +0200 | [diff] [blame] | 977 | |
| 978 | return S_OK; |
Piotr Caban | 5816c38 | 2008-07-27 19:55:05 +0200 | [diff] [blame] | 979 | } |
| 980 | |
| 981 | static HRESULT WINAPI isaxattributes_getIndexFromName( |
| 982 | ISAXAttributes* iface, |
| 983 | const WCHAR *pUri, |
| 984 | int cUriLength, |
| 985 | const WCHAR *pLocalName, |
| 986 | int cocalNameLength, |
| 987 | int *index) |
| 988 | { |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 989 | saxlocator *This = impl_from_ISAXAttributes( iface ); |
Piotr Caban | 0afbcd5 | 2008-08-20 18:30:34 +0200 | [diff] [blame] | 990 | int i; |
| 991 | TRACE("(%p)->(%s, %d, %s, %d)\n", This, debugstr_w(pUri), cUriLength, |
Piotr Caban | 5816c38 | 2008-07-27 19:55:05 +0200 | [diff] [blame] | 992 | debugstr_w(pLocalName), cocalNameLength); |
Piotr Caban | 0afbcd5 | 2008-08-20 18:30:34 +0200 | [diff] [blame] | 993 | |
| 994 | if(!pUri || !pLocalName || !index) return E_POINTER; |
| 995 | |
| 996 | for(i=0; i<This->nb_attributes; i++) |
| 997 | { |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 998 | if(cUriLength!=SysStringLen(This->attributes[i].szURI) |
| 999 | || cocalNameLength!=SysStringLen(This->attributes[i].szLocalname)) |
Piotr Caban | 0afbcd5 | 2008-08-20 18:30:34 +0200 | [diff] [blame] | 1000 | continue; |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 1001 | if(cUriLength && memcmp(pUri, This->attributes[i].szURI, |
Piotr Caban | 0afbcd5 | 2008-08-20 18:30:34 +0200 | [diff] [blame] | 1002 | sizeof(WCHAR)*cUriLength)) |
| 1003 | continue; |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 1004 | if(cocalNameLength && memcmp(pLocalName, This->attributes[i].szLocalname, |
Piotr Caban | 0afbcd5 | 2008-08-20 18:30:34 +0200 | [diff] [blame] | 1005 | sizeof(WCHAR)*cocalNameLength)) |
| 1006 | continue; |
| 1007 | |
| 1008 | *index = i; |
| 1009 | return S_OK; |
| 1010 | } |
| 1011 | |
| 1012 | return E_INVALIDARG; |
Piotr Caban | 5816c38 | 2008-07-27 19:55:05 +0200 | [diff] [blame] | 1013 | } |
| 1014 | |
| 1015 | static HRESULT WINAPI isaxattributes_getIndexFromQName( |
| 1016 | ISAXAttributes* iface, |
| 1017 | const WCHAR *pQName, |
| 1018 | int nQNameLength, |
| 1019 | int *index) |
| 1020 | { |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 1021 | saxlocator *This = impl_from_ISAXAttributes( iface ); |
Piotr Caban | fa221f5 | 2008-08-20 18:30:58 +0200 | [diff] [blame] | 1022 | int i; |
| 1023 | TRACE("(%p)->(%s, %d)\n", This, debugstr_w(pQName), nQNameLength); |
Piotr Caban | 5816c38 | 2008-07-27 19:55:05 +0200 | [diff] [blame] | 1024 | |
Piotr Caban | fa221f5 | 2008-08-20 18:30:58 +0200 | [diff] [blame] | 1025 | if(!pQName || !index) return E_POINTER; |
| 1026 | if(!nQNameLength) return E_INVALIDARG; |
| 1027 | |
| 1028 | for(i=0; i<This->nb_attributes; i++) |
| 1029 | { |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 1030 | if(nQNameLength!=SysStringLen(This->attributes[i].szQName)) continue; |
| 1031 | if(memcmp(pQName, This->attributes[i].szQName, sizeof(WCHAR)*nQNameLength)) continue; |
Piotr Caban | fa221f5 | 2008-08-20 18:30:58 +0200 | [diff] [blame] | 1032 | |
| 1033 | *index = i; |
| 1034 | return S_OK; |
| 1035 | } |
| 1036 | |
| 1037 | return E_INVALIDARG; |
Piotr Caban | 5816c38 | 2008-07-27 19:55:05 +0200 | [diff] [blame] | 1038 | } |
| 1039 | |
| 1040 | static HRESULT WINAPI isaxattributes_getType( |
| 1041 | ISAXAttributes* iface, |
| 1042 | int nIndex, |
| 1043 | const WCHAR **pType, |
| 1044 | int *pTypeLength) |
| 1045 | { |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 1046 | saxlocator *This = impl_from_ISAXAttributes( iface ); |
Piotr Caban | 5816c38 | 2008-07-27 19:55:05 +0200 | [diff] [blame] | 1047 | |
| 1048 | FIXME("(%p)->(%d) stub\n", This, nIndex); |
| 1049 | return E_NOTIMPL; |
| 1050 | } |
| 1051 | |
| 1052 | static HRESULT WINAPI isaxattributes_getTypeFromName( |
| 1053 | ISAXAttributes* iface, |
| 1054 | const WCHAR *pUri, |
| 1055 | int nUri, |
| 1056 | const WCHAR *pLocalName, |
| 1057 | int nLocalName, |
| 1058 | const WCHAR **pType, |
| 1059 | int *nType) |
| 1060 | { |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 1061 | saxlocator *This = impl_from_ISAXAttributes( iface ); |
Piotr Caban | 5816c38 | 2008-07-27 19:55:05 +0200 | [diff] [blame] | 1062 | |
| 1063 | FIXME("(%p)->(%s, %d, %s, %d) stub\n", This, debugstr_w(pUri), nUri, |
| 1064 | debugstr_w(pLocalName), nLocalName); |
| 1065 | return E_NOTIMPL; |
| 1066 | } |
| 1067 | |
| 1068 | static HRESULT WINAPI isaxattributes_getTypeFromQName( |
| 1069 | ISAXAttributes* iface, |
| 1070 | const WCHAR *pQName, |
| 1071 | int nQName, |
| 1072 | const WCHAR **pType, |
| 1073 | int *nType) |
| 1074 | { |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 1075 | saxlocator *This = impl_from_ISAXAttributes( iface ); |
Piotr Caban | 5816c38 | 2008-07-27 19:55:05 +0200 | [diff] [blame] | 1076 | |
| 1077 | FIXME("(%p)->(%s, %d) stub\n", This, debugstr_w(pQName), nQName); |
| 1078 | return E_NOTIMPL; |
| 1079 | } |
| 1080 | |
| 1081 | static HRESULT WINAPI isaxattributes_getValue( |
| 1082 | ISAXAttributes* iface, |
Nikolay Sivov | d65f298 | 2011-10-05 14:19:29 -0500 | [diff] [blame] | 1083 | int index, |
| 1084 | const WCHAR **value, |
Piotr Caban | 5816c38 | 2008-07-27 19:55:05 +0200 | [diff] [blame] | 1085 | int *nValue) |
| 1086 | { |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 1087 | saxlocator *This = impl_from_ISAXAttributes( iface ); |
Nikolay Sivov | d65f298 | 2011-10-05 14:19:29 -0500 | [diff] [blame] | 1088 | TRACE("(%p)->(%d)\n", This, index); |
Piotr Caban | 5816c38 | 2008-07-27 19:55:05 +0200 | [diff] [blame] | 1089 | |
Nikolay Sivov | d65f298 | 2011-10-05 14:19:29 -0500 | [diff] [blame] | 1090 | if(index>=This->nb_attributes || index<0) return E_INVALIDARG; |
| 1091 | if(!value || !nValue) return E_POINTER; |
Piotr Caban | 2516840 | 2008-07-30 20:27:25 +0200 | [diff] [blame] | 1092 | |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 1093 | *nValue = SysStringLen(This->attributes[index].szValue); |
| 1094 | *value = This->attributes[index].szValue; |
Nikolay Sivov | d65f298 | 2011-10-05 14:19:29 -0500 | [diff] [blame] | 1095 | |
| 1096 | TRACE("(%s:%d)\n", debugstr_w(*value), *nValue); |
Piotr Caban | 2516840 | 2008-07-30 20:27:25 +0200 | [diff] [blame] | 1097 | |
| 1098 | return S_OK; |
Piotr Caban | 5816c38 | 2008-07-27 19:55:05 +0200 | [diff] [blame] | 1099 | } |
| 1100 | |
| 1101 | static HRESULT WINAPI isaxattributes_getValueFromName( |
| 1102 | ISAXAttributes* iface, |
| 1103 | const WCHAR *pUri, |
| 1104 | int nUri, |
| 1105 | const WCHAR *pLocalName, |
| 1106 | int nLocalName, |
| 1107 | const WCHAR **pValue, |
| 1108 | int *nValue) |
| 1109 | { |
Piotr Caban | c9893d1 | 2008-08-20 18:31:17 +0200 | [diff] [blame] | 1110 | HRESULT hr; |
| 1111 | int index; |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 1112 | saxlocator *This = impl_from_ISAXAttributes( iface ); |
Piotr Caban | c9893d1 | 2008-08-20 18:31:17 +0200 | [diff] [blame] | 1113 | TRACE("(%p)->(%s, %d, %s, %d)\n", This, debugstr_w(pUri), nUri, |
Piotr Caban | 5816c38 | 2008-07-27 19:55:05 +0200 | [diff] [blame] | 1114 | debugstr_w(pLocalName), nLocalName); |
Piotr Caban | c9893d1 | 2008-08-20 18:31:17 +0200 | [diff] [blame] | 1115 | |
| 1116 | hr = ISAXAttributes_getIndexFromName(iface, |
| 1117 | pUri, nUri, pLocalName, nLocalName, &index); |
| 1118 | if(hr==S_OK) hr = ISAXAttributes_getValue(iface, index, pValue, nValue); |
| 1119 | |
| 1120 | return hr; |
Piotr Caban | 5816c38 | 2008-07-27 19:55:05 +0200 | [diff] [blame] | 1121 | } |
| 1122 | |
| 1123 | static HRESULT WINAPI isaxattributes_getValueFromQName( |
| 1124 | ISAXAttributes* iface, |
| 1125 | const WCHAR *pQName, |
| 1126 | int nQName, |
| 1127 | const WCHAR **pValue, |
| 1128 | int *nValue) |
| 1129 | { |
Piotr Caban | 655155f | 2008-08-20 18:31:39 +0200 | [diff] [blame] | 1130 | HRESULT hr; |
| 1131 | int index; |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 1132 | saxlocator *This = impl_from_ISAXAttributes( iface ); |
Piotr Caban | 655155f | 2008-08-20 18:31:39 +0200 | [diff] [blame] | 1133 | TRACE("(%p)->(%s, %d)\n", This, debugstr_w(pQName), nQName); |
Piotr Caban | 5816c38 | 2008-07-27 19:55:05 +0200 | [diff] [blame] | 1134 | |
Piotr Caban | 655155f | 2008-08-20 18:31:39 +0200 | [diff] [blame] | 1135 | hr = ISAXAttributes_getIndexFromQName(iface, pQName, nQName, &index); |
| 1136 | if(hr==S_OK) hr = ISAXAttributes_getValue(iface, index, pValue, nValue); |
| 1137 | |
| 1138 | return hr; |
Piotr Caban | 5816c38 | 2008-07-27 19:55:05 +0200 | [diff] [blame] | 1139 | } |
| 1140 | |
| 1141 | static const struct ISAXAttributesVtbl isaxattributes_vtbl = |
| 1142 | { |
| 1143 | isaxattributes_QueryInterface, |
| 1144 | isaxattributes_AddRef, |
| 1145 | isaxattributes_Release, |
| 1146 | isaxattributes_getLength, |
| 1147 | isaxattributes_getURI, |
| 1148 | isaxattributes_getLocalName, |
| 1149 | isaxattributes_getQName, |
| 1150 | isaxattributes_getName, |
| 1151 | isaxattributes_getIndexFromName, |
| 1152 | isaxattributes_getIndexFromQName, |
| 1153 | isaxattributes_getType, |
| 1154 | isaxattributes_getTypeFromName, |
| 1155 | isaxattributes_getTypeFromQName, |
| 1156 | isaxattributes_getValue, |
| 1157 | isaxattributes_getValueFromName, |
| 1158 | isaxattributes_getValueFromQName |
| 1159 | }; |
| 1160 | |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 1161 | static HRESULT SAXAttributes_populate(saxlocator *locator, |
Piotr Caban | a94e4c1 | 2008-08-03 14:38:10 +0200 | [diff] [blame] | 1162 | int nb_namespaces, const xmlChar **xmlNamespaces, |
Piotr Caban | 6df49d5 | 2008-07-30 20:24:12 +0200 | [diff] [blame] | 1163 | int nb_attributes, const xmlChar **xmlAttributes) |
Piotr Caban | 5816c38 | 2008-07-27 19:55:05 +0200 | [diff] [blame] | 1164 | { |
Piotr Caban | a94e4c1 | 2008-08-03 14:38:10 +0200 | [diff] [blame] | 1165 | static const xmlChar xmlns[] = "xmlns"; |
Piotr Caban | 685be40 | 2011-10-26 13:25:27 +0200 | [diff] [blame] | 1166 | static const WCHAR xmlnsW[] = { 'x','m','l','n','s',0 }; |
Piotr Caban | 5816c38 | 2008-07-27 19:55:05 +0200 | [diff] [blame] | 1167 | |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 1168 | struct _attributes *attrs; |
Nikolay Sivov | 4fb5872 | 2012-04-20 11:03:18 +0400 | [diff] [blame] | 1169 | int i; |
Piotr Caban | 5816c38 | 2008-07-27 19:55:05 +0200 | [diff] [blame] | 1170 | |
Nikolay Sivov | 4fb5872 | 2012-04-20 11:03:18 +0400 | [diff] [blame] | 1171 | /* skip namespace definitions */ |
| 1172 | if ((locator->saxreader->features & NamespacePrefixes) == 0) |
| 1173 | nb_namespaces = 0; |
| 1174 | |
| 1175 | locator->nb_attributes = nb_namespaces + nb_attributes; |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 1176 | if(locator->nb_attributes > locator->attributesSize) |
Piotr Caban | 6df49d5 | 2008-07-30 20:24:12 +0200 | [diff] [blame] | 1177 | { |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 1178 | attrs = heap_realloc(locator->attributes, sizeof(struct _attributes)*locator->nb_attributes*2); |
| 1179 | if(!attrs) |
| 1180 | { |
| 1181 | locator->nb_attributes = 0; |
| 1182 | return E_OUTOFMEMORY; |
| 1183 | } |
| 1184 | locator->attributes = attrs; |
| 1185 | } |
| 1186 | else |
| 1187 | { |
| 1188 | attrs = locator->attributes; |
Piotr Caban | 6df49d5 | 2008-07-30 20:24:12 +0200 | [diff] [blame] | 1189 | } |
| 1190 | |
Nikolay Sivov | 4fb5872 | 2012-04-20 11:03:18 +0400 | [diff] [blame] | 1191 | for (i = 0; i < nb_namespaces; i++) |
Piotr Caban | a94e4c1 | 2008-08-03 14:38:10 +0200 | [diff] [blame] | 1192 | { |
Nikolay Sivov | 4fb5872 | 2012-04-20 11:03:18 +0400 | [diff] [blame] | 1193 | attrs[nb_attributes+i].szLocalname = SysAllocStringLen(NULL, 0); |
| 1194 | attrs[nb_attributes+i].szURI = locator->namespaceUri; |
| 1195 | attrs[nb_attributes+i].szValue = bstr_from_xmlChar(xmlNamespaces[2*i+1]); |
| 1196 | if(!xmlNamespaces[2*i]) |
| 1197 | attrs[nb_attributes+i].szQName = SysAllocString(xmlnsW); |
Piotr Caban | 685be40 | 2011-10-26 13:25:27 +0200 | [diff] [blame] | 1198 | else |
Nikolay Sivov | 4fb5872 | 2012-04-20 11:03:18 +0400 | [diff] [blame] | 1199 | attrs[nb_attributes+i].szQName = QName_from_xmlChar(xmlns, xmlNamespaces[2*i]); |
Piotr Caban | a94e4c1 | 2008-08-03 14:38:10 +0200 | [diff] [blame] | 1200 | } |
| 1201 | |
Nikolay Sivov | 4fb5872 | 2012-04-20 11:03:18 +0400 | [diff] [blame] | 1202 | for (i = 0; i < nb_attributes; i++) |
Piotr Caban | 6df49d5 | 2008-07-30 20:24:12 +0200 | [diff] [blame] | 1203 | { |
Nikolay Sivov | 973f62f | 2012-03-01 21:06:39 +0300 | [diff] [blame] | 1204 | static const xmlChar xmlA[] = "xml"; |
| 1205 | |
Nikolay Sivov | 4fb5872 | 2012-04-20 11:03:18 +0400 | [diff] [blame] | 1206 | if (xmlStrEqual(xmlAttributes[i*5+1], xmlA)) |
| 1207 | attrs[i].szURI = bstr_from_xmlChar(xmlAttributes[i*5+2]); |
Nikolay Sivov | 973f62f | 2012-03-01 21:06:39 +0300 | [diff] [blame] | 1208 | else |
Nikolay Sivov | 4fb5872 | 2012-04-20 11:03:18 +0400 | [diff] [blame] | 1209 | attrs[i].szURI = find_element_uri(locator, xmlAttributes[i*5+2]); |
Nikolay Sivov | 973f62f | 2012-03-01 21:06:39 +0300 | [diff] [blame] | 1210 | |
Nikolay Sivov | 4fb5872 | 2012-04-20 11:03:18 +0400 | [diff] [blame] | 1211 | attrs[i].szLocalname = bstr_from_xmlChar(xmlAttributes[i*5]); |
| 1212 | attrs[i].szValue = bstr_from_xmlCharN(xmlAttributes[i*5+3], |
| 1213 | xmlAttributes[i*5+4]-xmlAttributes[i*5+3]); |
| 1214 | attrs[i].szQName = QName_from_xmlChar(xmlAttributes[i*5+1], |
| 1215 | xmlAttributes[i*5]); |
Piotr Caban | 6df49d5 | 2008-07-30 20:24:12 +0200 | [diff] [blame] | 1216 | } |
| 1217 | |
Piotr Caban | 5816c38 | 2008-07-27 19:55:05 +0200 | [diff] [blame] | 1218 | return S_OK; |
| 1219 | } |
| 1220 | |
Piotr Caban | 072383e | 2008-07-17 00:41:01 +0200 | [diff] [blame] | 1221 | /*** LibXML callbacks ***/ |
| 1222 | static void libxmlStartDocument(void *ctx) |
| 1223 | { |
| 1224 | saxlocator *This = ctx; |
| 1225 | HRESULT hr; |
| 1226 | |
Nikolay Sivov | bcd8585 | 2012-04-15 13:47:30 +0400 | [diff] [blame] | 1227 | if (This->saxreader->version >= MSXML4) |
Piotr Caban | c253bab | 2011-11-28 15:05:25 +0100 | [diff] [blame] | 1228 | { |
| 1229 | const xmlChar *p = This->pParserCtxt->input->cur-1; |
| 1230 | update_position(This, FALSE); |
| 1231 | while(p>This->pParserCtxt->input->base && *p!='>') |
| 1232 | { |
| 1233 | if(*p=='\n' || (*p=='\r' && *(p+1)!='\n')) |
| 1234 | This->line--; |
| 1235 | p--; |
| 1236 | } |
| 1237 | This->column = 0; |
| 1238 | for(; p>=This->pParserCtxt->input->base && *p!='\n' && *p!='\r'; p--) |
| 1239 | This->column++; |
Piotr Caban | e84c410 | 2011-10-24 20:08:46 +0200 | [diff] [blame] | 1240 | } |
| 1241 | |
Nikolay Sivov | ff99228 | 2010-01-18 23:30:50 +0300 | [diff] [blame] | 1242 | if(has_content_handler(This)) |
Piotr Caban | 072383e | 2008-07-17 00:41:01 +0200 | [diff] [blame] | 1243 | { |
Piotr Caban | c52e091 | 2008-07-31 16:48:03 +0200 | [diff] [blame] | 1244 | if(This->vbInterface) |
| 1245 | hr = IVBSAXContentHandler_startDocument(This->saxreader->vbcontentHandler); |
| 1246 | else |
| 1247 | hr = ISAXContentHandler_startDocument(This->saxreader->contentHandler); |
| 1248 | |
Nikolay Sivov | 9d66292 | 2011-12-24 16:10:33 +0300 | [diff] [blame] | 1249 | if (sax_callback_failed(This, hr)) |
Piotr Caban | bba7eb5 | 2008-07-19 22:32:10 +0200 | [diff] [blame] | 1250 | format_error_message_from_id(This, hr); |
Piotr Caban | 072383e | 2008-07-17 00:41:01 +0200 | [diff] [blame] | 1251 | } |
| 1252 | } |
| 1253 | |
Piotr Caban | c58b24b | 2008-07-17 00:41:19 +0200 | [diff] [blame] | 1254 | static void libxmlEndDocument(void *ctx) |
| 1255 | { |
| 1256 | saxlocator *This = ctx; |
| 1257 | HRESULT hr; |
| 1258 | |
Nikolay Sivov | bcd8585 | 2012-04-15 13:47:30 +0400 | [diff] [blame] | 1259 | if (This->saxreader->version >= MSXML4) { |
Piotr Caban | c253bab | 2011-11-28 15:05:25 +0100 | [diff] [blame] | 1260 | update_position(This, FALSE); |
Piotr Caban | e84c410 | 2011-10-24 20:08:46 +0200 | [diff] [blame] | 1261 | if(This->column > 1) |
| 1262 | This->line++; |
| 1263 | This->column = 0; |
| 1264 | } else { |
| 1265 | This->column = 0; |
| 1266 | This->line = 0; |
| 1267 | } |
Piotr Caban | c58b24b | 2008-07-17 00:41:19 +0200 | [diff] [blame] | 1268 | |
Piotr Caban | 2cb215b | 2008-07-19 22:31:56 +0200 | [diff] [blame] | 1269 | if(This->ret != S_OK) return; |
| 1270 | |
Nikolay Sivov | ff99228 | 2010-01-18 23:30:50 +0300 | [diff] [blame] | 1271 | if(has_content_handler(This)) |
Piotr Caban | c58b24b | 2008-07-17 00:41:19 +0200 | [diff] [blame] | 1272 | { |
Piotr Caban | c52e091 | 2008-07-31 16:48:03 +0200 | [diff] [blame] | 1273 | if(This->vbInterface) |
| 1274 | hr = IVBSAXContentHandler_endDocument(This->saxreader->vbcontentHandler); |
| 1275 | else |
| 1276 | hr = ISAXContentHandler_endDocument(This->saxreader->contentHandler); |
| 1277 | |
Nikolay Sivov | 9d66292 | 2011-12-24 16:10:33 +0300 | [diff] [blame] | 1278 | if (sax_callback_failed(This, hr)) |
Piotr Caban | bba7eb5 | 2008-07-19 22:32:10 +0200 | [diff] [blame] | 1279 | format_error_message_from_id(This, hr); |
Piotr Caban | c58b24b | 2008-07-17 00:41:19 +0200 | [diff] [blame] | 1280 | } |
| 1281 | } |
| 1282 | |
Piotr Caban | 965a2ea | 2008-07-17 00:41:27 +0200 | [diff] [blame] | 1283 | static void libxmlStartElementNS( |
| 1284 | void *ctx, |
| 1285 | const xmlChar *localname, |
| 1286 | const xmlChar *prefix, |
| 1287 | const xmlChar *URI, |
| 1288 | int nb_namespaces, |
| 1289 | const xmlChar **namespaces, |
| 1290 | int nb_attributes, |
| 1291 | int nb_defaulted, |
| 1292 | const xmlChar **attributes) |
| 1293 | { |
Piotr Caban | 965a2ea | 2008-07-17 00:41:27 +0200 | [diff] [blame] | 1294 | saxlocator *This = ctx; |
Nikolay Sivov | 9d66292 | 2011-12-24 16:10:33 +0300 | [diff] [blame] | 1295 | element_entry *element; |
| 1296 | HRESULT hr = S_OK; |
Nikolay Sivov | 2dc6711 | 2012-05-08 15:50:19 +0400 | [diff] [blame] | 1297 | BSTR uri; |
Piotr Caban | 965a2ea | 2008-07-17 00:41:27 +0200 | [diff] [blame] | 1298 | |
Piotr Caban | c253bab | 2011-11-28 15:05:25 +0100 | [diff] [blame] | 1299 | update_position(This, TRUE); |
Piotr Caban | de91f26 | 2011-10-31 12:32:22 +0100 | [diff] [blame] | 1300 | if(*(This->pParserCtxt->input->cur) == '/') |
Piotr Caban | c253bab | 2011-11-28 15:05:25 +0100 | [diff] [blame] | 1301 | This->column++; |
Nikolay Sivov | bcd8585 | 2012-04-15 13:47:30 +0400 | [diff] [blame] | 1302 | if(This->saxreader->version < MSXML4) |
Piotr Caban | c253bab | 2011-11-28 15:05:25 +0100 | [diff] [blame] | 1303 | This->column++; |
Piotr Caban | 965a2ea | 2008-07-17 00:41:27 +0200 | [diff] [blame] | 1304 | |
Nikolay Sivov | 9d66292 | 2011-12-24 16:10:33 +0300 | [diff] [blame] | 1305 | element = alloc_element_entry(localname, prefix, nb_namespaces, namespaces); |
| 1306 | push_element_ns(This, element); |
Piotr Caban | 619c2dc | 2011-10-31 12:32:59 +0100 | [diff] [blame] | 1307 | |
Nikolay Sivov | 2dc6711 | 2012-05-08 15:50:19 +0400 | [diff] [blame] | 1308 | if (is_namespaces_enabled(This->saxreader)) |
Piotr Caban | 965a2ea | 2008-07-17 00:41:27 +0200 | [diff] [blame] | 1309 | { |
Nikolay Sivov | 2dc6711 | 2012-05-08 15:50:19 +0400 | [diff] [blame] | 1310 | int i; |
Nikolay Sivov | 9d66292 | 2011-12-24 16:10:33 +0300 | [diff] [blame] | 1311 | |
Nikolay Sivov | 2dc6711 | 2012-05-08 15:50:19 +0400 | [diff] [blame] | 1312 | for (i = 0; i < nb_namespaces && has_content_handler(This); i++) |
Piotr Caban | e9d34b7 | 2008-08-03 17:03:28 +0200 | [diff] [blame] | 1313 | { |
Nikolay Sivov | f27159a | 2012-04-19 10:46:03 +0400 | [diff] [blame] | 1314 | if (This->vbInterface) |
Nikolay Sivov | 2dc6711 | 2012-05-08 15:50:19 +0400 | [diff] [blame] | 1315 | hr = IVBSAXContentHandler_startPrefixMapping( |
| 1316 | This->saxreader->vbcontentHandler, |
| 1317 | &element->ns[i].prefix, |
| 1318 | &element->ns[i].uri); |
Piotr Caban | c52e091 | 2008-07-31 16:48:03 +0200 | [diff] [blame] | 1319 | else |
Nikolay Sivov | 2dc6711 | 2012-05-08 15:50:19 +0400 | [diff] [blame] | 1320 | hr = ISAXContentHandler_startPrefixMapping( |
| 1321 | This->saxreader->contentHandler, |
| 1322 | element->ns[i].prefix, |
| 1323 | SysStringLen(element->ns[i].prefix), |
| 1324 | element->ns[i].uri, |
| 1325 | SysStringLen(element->ns[i].uri)); |
| 1326 | |
| 1327 | if (sax_callback_failed(This, hr)) |
| 1328 | { |
| 1329 | format_error_message_from_id(This, hr); |
| 1330 | return; |
| 1331 | } |
Piotr Caban | 6df49d5 | 2008-07-30 20:24:12 +0200 | [diff] [blame] | 1332 | } |
Piotr Caban | 965a2ea | 2008-07-17 00:41:27 +0200 | [diff] [blame] | 1333 | } |
Piotr Caban | 03f7909 | 2008-08-20 18:20:50 +0200 | [diff] [blame] | 1334 | |
Nikolay Sivov | 2dc6711 | 2012-05-08 15:50:19 +0400 | [diff] [blame] | 1335 | uri = find_element_uri(This, URI); |
| 1336 | hr = SAXAttributes_populate(This, nb_namespaces, namespaces, nb_attributes, attributes); |
| 1337 | if (hr == S_OK && has_content_handler(This)) |
| 1338 | { |
| 1339 | BSTR local; |
| 1340 | |
| 1341 | if (is_namespaces_enabled(This->saxreader)) |
| 1342 | local = element->local; |
| 1343 | else |
| 1344 | uri = local = NULL; |
| 1345 | |
| 1346 | if (This->vbInterface) |
| 1347 | hr = IVBSAXContentHandler_startElement(This->saxreader->vbcontentHandler, |
| 1348 | &uri, &local, &element->qname, &This->IVBSAXAttributes_iface); |
| 1349 | else |
| 1350 | hr = ISAXContentHandler_startElement(This->saxreader->contentHandler, |
| 1351 | uri, SysStringLen(uri), |
| 1352 | local, SysStringLen(local), |
| 1353 | element->qname, SysStringLen(element->qname), |
| 1354 | &This->ISAXAttributes_iface); |
| 1355 | |
| 1356 | if (sax_callback_failed(This, hr)) |
| 1357 | format_error_message_from_id(This, hr); |
| 1358 | } |
Piotr Caban | 965a2ea | 2008-07-17 00:41:27 +0200 | [diff] [blame] | 1359 | } |
| 1360 | |
Piotr Caban | 6693263 | 2008-07-17 00:41:34 +0200 | [diff] [blame] | 1361 | static void libxmlEndElementNS( |
| 1362 | void *ctx, |
| 1363 | const xmlChar *localname, |
| 1364 | const xmlChar *prefix, |
| 1365 | const xmlChar *URI) |
| 1366 | { |
Piotr Caban | 6693263 | 2008-07-17 00:41:34 +0200 | [diff] [blame] | 1367 | saxlocator *This = ctx; |
Nikolay Sivov | 9d66292 | 2011-12-24 16:10:33 +0300 | [diff] [blame] | 1368 | element_entry *element; |
Piotr Caban | c253bab | 2011-11-28 15:05:25 +0100 | [diff] [blame] | 1369 | const xmlChar *p; |
Nikolay Sivov | f27159a | 2012-04-19 10:46:03 +0400 | [diff] [blame] | 1370 | BSTR uri, local; |
Nikolay Sivov | 9d66292 | 2011-12-24 16:10:33 +0300 | [diff] [blame] | 1371 | HRESULT hr; |
Piotr Caban | 6693263 | 2008-07-17 00:41:34 +0200 | [diff] [blame] | 1372 | |
Piotr Caban | c253bab | 2011-11-28 15:05:25 +0100 | [diff] [blame] | 1373 | update_position(This, FALSE); |
| 1374 | p = This->pParserCtxt->input->cur; |
Nikolay Sivov | bcd8585 | 2012-04-15 13:47:30 +0400 | [diff] [blame] | 1375 | |
| 1376 | if (This->saxreader->version >= MSXML4) |
Piotr Caban | c253bab | 2011-11-28 15:05:25 +0100 | [diff] [blame] | 1377 | { |
| 1378 | p--; |
| 1379 | while(p>This->pParserCtxt->input->base && *p!='>') |
| 1380 | { |
| 1381 | if(*p=='\n' || (*p=='\r' && *(p+1)!='\n')) |
| 1382 | This->line--; |
| 1383 | p--; |
| 1384 | } |
Piotr Caban | e84c410 | 2011-10-24 20:08:46 +0200 | [diff] [blame] | 1385 | } |
Piotr Caban | c253bab | 2011-11-28 15:05:25 +0100 | [diff] [blame] | 1386 | else if(*(p-1)!='>' || *(p-2)!='/') |
| 1387 | { |
| 1388 | p--; |
| 1389 | while(p-2>=This->pParserCtxt->input->base |
| 1390 | && *(p-2)!='<' && *(p-1)!='/') |
| 1391 | { |
| 1392 | if(*p=='\n' || (*p=='\r' && *(p+1)!='\n')) |
| 1393 | This->line--; |
| 1394 | p--; |
| 1395 | } |
| 1396 | } |
| 1397 | This->column = 0; |
| 1398 | for(; p>=This->pParserCtxt->input->base && *p!='\n' && *p!='\r'; p--) |
| 1399 | This->column++; |
Piotr Caban | 6693263 | 2008-07-17 00:41:34 +0200 | [diff] [blame] | 1400 | |
Nikolay Sivov | 9d66292 | 2011-12-24 16:10:33 +0300 | [diff] [blame] | 1401 | uri = find_element_uri(This, URI); |
| 1402 | element = pop_element_ns(This); |
| 1403 | |
| 1404 | if (!has_content_handler(This)) |
Piotr Caban | 6693263 | 2008-07-17 00:41:34 +0200 | [diff] [blame] | 1405 | { |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 1406 | This->nb_attributes = 0; |
Nikolay Sivov | 9d66292 | 2011-12-24 16:10:33 +0300 | [diff] [blame] | 1407 | free_element_entry(element); |
| 1408 | return; |
Piotr Caban | 6693263 | 2008-07-17 00:41:34 +0200 | [diff] [blame] | 1409 | } |
Nikolay Sivov | 9d66292 | 2011-12-24 16:10:33 +0300 | [diff] [blame] | 1410 | |
Nikolay Sivov | f27159a | 2012-04-19 10:46:03 +0400 | [diff] [blame] | 1411 | if (is_namespaces_enabled(This->saxreader)) |
| 1412 | local = element->local; |
| 1413 | else |
| 1414 | uri = local = NULL; |
| 1415 | |
| 1416 | if (This->vbInterface) |
Nikolay Sivov | 9d66292 | 2011-12-24 16:10:33 +0300 | [diff] [blame] | 1417 | hr = IVBSAXContentHandler_endElement( |
| 1418 | This->saxreader->vbcontentHandler, |
Nikolay Sivov | f27159a | 2012-04-19 10:46:03 +0400 | [diff] [blame] | 1419 | &uri, &local, &element->qname); |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 1420 | else |
Nikolay Sivov | 9d66292 | 2011-12-24 16:10:33 +0300 | [diff] [blame] | 1421 | hr = ISAXContentHandler_endElement( |
| 1422 | This->saxreader->contentHandler, |
| 1423 | uri, SysStringLen(uri), |
Nikolay Sivov | f27159a | 2012-04-19 10:46:03 +0400 | [diff] [blame] | 1424 | local, SysStringLen(local), |
Nikolay Sivov | 9d66292 | 2011-12-24 16:10:33 +0300 | [diff] [blame] | 1425 | element->qname, SysStringLen(element->qname)); |
| 1426 | |
| 1427 | This->nb_attributes = 0; |
| 1428 | |
| 1429 | if (sax_callback_failed(This, hr)) |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 1430 | { |
Nikolay Sivov | 9d66292 | 2011-12-24 16:10:33 +0300 | [diff] [blame] | 1431 | format_error_message_from_id(This, hr); |
Nikolay Sivov | f39209c | 2012-02-05 22:44:44 +0300 | [diff] [blame] | 1432 | free_element_entry(element); |
Nikolay Sivov | 9d66292 | 2011-12-24 16:10:33 +0300 | [diff] [blame] | 1433 | return; |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 1434 | } |
Nikolay Sivov | 9d66292 | 2011-12-24 16:10:33 +0300 | [diff] [blame] | 1435 | |
Nikolay Sivov | f27159a | 2012-04-19 10:46:03 +0400 | [diff] [blame] | 1436 | if (is_namespaces_enabled(This->saxreader)) |
Nikolay Sivov | 9d66292 | 2011-12-24 16:10:33 +0300 | [diff] [blame] | 1437 | { |
Nikolay Sivov | f27159a | 2012-04-19 10:46:03 +0400 | [diff] [blame] | 1438 | int i = -1; |
Nikolay Sivov | 2dc6711 | 2012-05-08 15:50:19 +0400 | [diff] [blame] | 1439 | while (iterate_endprefix_index(This, element, &i) && has_content_handler(This)) |
Nikolay Sivov | f27159a | 2012-04-19 10:46:03 +0400 | [diff] [blame] | 1440 | { |
| 1441 | if (This->vbInterface) |
| 1442 | hr = IVBSAXContentHandler_endPrefixMapping( |
| 1443 | This->saxreader->vbcontentHandler, &element->ns[i].prefix); |
| 1444 | else |
| 1445 | hr = ISAXContentHandler_endPrefixMapping( |
| 1446 | This->saxreader->contentHandler, |
| 1447 | element->ns[i].prefix, SysStringLen(element->ns[i].prefix)); |
Nikolay Sivov | 9d66292 | 2011-12-24 16:10:33 +0300 | [diff] [blame] | 1448 | |
Nikolay Sivov | f27159a | 2012-04-19 10:46:03 +0400 | [diff] [blame] | 1449 | if (sax_callback_failed(This, hr)) break; |
| 1450 | } |
Nikolay Sivov | 9d66292 | 2011-12-24 16:10:33 +0300 | [diff] [blame] | 1451 | |
Nikolay Sivov | 2dc6711 | 2012-05-08 15:50:19 +0400 | [diff] [blame] | 1452 | if (sax_callback_failed(This, hr)) |
| 1453 | format_error_message_from_id(This, hr); |
| 1454 | } |
Nikolay Sivov | 9d66292 | 2011-12-24 16:10:33 +0300 | [diff] [blame] | 1455 | |
| 1456 | free_element_entry(element); |
Piotr Caban | 6693263 | 2008-07-17 00:41:34 +0200 | [diff] [blame] | 1457 | } |
| 1458 | |
Piotr Caban | 4038863 | 2008-07-17 00:41:40 +0200 | [diff] [blame] | 1459 | static void libxmlCharacters( |
| 1460 | void *ctx, |
| 1461 | const xmlChar *ch, |
| 1462 | int len) |
| 1463 | { |
Piotr Caban | 4038863 | 2008-07-17 00:41:40 +0200 | [diff] [blame] | 1464 | saxlocator *This = ctx; |
Piotr Caban | c801c18 | 2008-10-07 22:10:43 +0200 | [diff] [blame] | 1465 | BSTR Chars; |
Piotr Caban | 4038863 | 2008-07-17 00:41:40 +0200 | [diff] [blame] | 1466 | HRESULT hr; |
Piotr Caban | c253bab | 2011-11-28 15:05:25 +0100 | [diff] [blame] | 1467 | xmlChar *cur, *end; |
Piotr Caban | c801c18 | 2008-10-07 22:10:43 +0200 | [diff] [blame] | 1468 | BOOL lastEvent = FALSE; |
Piotr Caban | 3d4ad64 | 2008-07-23 16:39:12 +0200 | [diff] [blame] | 1469 | |
Nikolay Sivov | ff99228 | 2010-01-18 23:30:50 +0300 | [diff] [blame] | 1470 | if(!(has_content_handler(This))) return; |
Piotr Caban | 4038863 | 2008-07-17 00:41:40 +0200 | [diff] [blame] | 1471 | |
Piotr Caban | c253bab | 2011-11-28 15:05:25 +0100 | [diff] [blame] | 1472 | update_position(This, FALSE); |
| 1473 | cur = (xmlChar*)This->pParserCtxt->input->cur; |
| 1474 | while(cur>=This->pParserCtxt->input->base && *cur!='>') |
| 1475 | { |
| 1476 | if(*cur=='\n' || (*cur=='\r' && *(cur+1)!='\n')) |
| 1477 | This->line--; |
| 1478 | cur--; |
| 1479 | } |
| 1480 | This->column = 1; |
| 1481 | for(; cur>=This->pParserCtxt->input->base && *cur!='\n' && *cur!='\r'; cur--) |
| 1482 | This->column++; |
| 1483 | |
Piotr Caban | c801c18 | 2008-10-07 22:10:43 +0200 | [diff] [blame] | 1484 | cur = (xmlChar*)ch; |
| 1485 | if(*(ch-1)=='\r') cur--; |
| 1486 | end = cur; |
| 1487 | |
Piotr Caban | c801c18 | 2008-10-07 22:10:43 +0200 | [diff] [blame] | 1488 | while(1) |
Piotr Caban | 4038863 | 2008-07-17 00:41:40 +0200 | [diff] [blame] | 1489 | { |
Piotr Caban | c801c18 | 2008-10-07 22:10:43 +0200 | [diff] [blame] | 1490 | while(end-ch<len && *end!='\r') end++; |
| 1491 | if(end-ch==len) |
Piotr Caban | 3d4ad64 | 2008-07-23 16:39:12 +0200 | [diff] [blame] | 1492 | { |
Piotr Caban | c801c18 | 2008-10-07 22:10:43 +0200 | [diff] [blame] | 1493 | lastEvent = TRUE; |
Piotr Caban | 3d4ad64 | 2008-07-23 16:39:12 +0200 | [diff] [blame] | 1494 | } |
Piotr Caban | c253bab | 2011-11-28 15:05:25 +0100 | [diff] [blame] | 1495 | else |
| 1496 | { |
| 1497 | *end = '\n'; |
| 1498 | end++; |
| 1499 | } |
Piotr Caban | 3d4ad64 | 2008-07-23 16:39:12 +0200 | [diff] [blame] | 1500 | |
Nikolay Sivov | bcd8585 | 2012-04-15 13:47:30 +0400 | [diff] [blame] | 1501 | if (This->saxreader->version >= MSXML4) |
Piotr Caban | c253bab | 2011-11-28 15:05:25 +0100 | [diff] [blame] | 1502 | { |
| 1503 | xmlChar *p; |
Piotr Caban | c801c18 | 2008-10-07 22:10:43 +0200 | [diff] [blame] | 1504 | |
Piotr Caban | c253bab | 2011-11-28 15:05:25 +0100 | [diff] [blame] | 1505 | for(p=cur; p!=end; p++) |
| 1506 | { |
| 1507 | if(*p=='\n') |
| 1508 | { |
| 1509 | This->line++; |
| 1510 | This->column = 1; |
| 1511 | } |
| 1512 | else |
| 1513 | { |
| 1514 | This->column++; |
| 1515 | } |
| 1516 | } |
Piotr Caban | e84c410 | 2011-10-24 20:08:46 +0200 | [diff] [blame] | 1517 | |
| 1518 | if(!lastEvent) |
| 1519 | This->column = 0; |
| 1520 | } |
| 1521 | |
Piotr Caban | c253bab | 2011-11-28 15:05:25 +0100 | [diff] [blame] | 1522 | Chars = pooled_bstr_from_xmlCharN(&This->saxreader->pool, cur, end-cur); |
Piotr Caban | c801c18 | 2008-10-07 22:10:43 +0200 | [diff] [blame] | 1523 | if(This->vbInterface) |
| 1524 | hr = IVBSAXContentHandler_characters( |
| 1525 | This->saxreader->vbcontentHandler, &Chars); |
| 1526 | else |
| 1527 | hr = ISAXContentHandler_characters( |
| 1528 | This->saxreader->contentHandler, |
| 1529 | Chars, SysStringLen(Chars)); |
Piotr Caban | c801c18 | 2008-10-07 22:10:43 +0200 | [diff] [blame] | 1530 | |
Nikolay Sivov | 9d66292 | 2011-12-24 16:10:33 +0300 | [diff] [blame] | 1531 | if (sax_callback_failed(This, hr)) |
Ricardo Filipe | e5e301b | 2008-11-13 13:33:27 +0000 | [diff] [blame] | 1532 | { |
| 1533 | format_error_message_from_id(This, hr); |
| 1534 | return; |
| 1535 | } |
| 1536 | |
Nikolay Sivov | bcd8585 | 2012-04-15 13:47:30 +0400 | [diff] [blame] | 1537 | if (This->saxreader->version < MSXML4) |
Piotr Caban | c253bab | 2011-11-28 15:05:25 +0100 | [diff] [blame] | 1538 | This->column += end-cur; |
Piotr Caban | c801c18 | 2008-10-07 22:10:43 +0200 | [diff] [blame] | 1539 | |
| 1540 | if(lastEvent) |
| 1541 | break; |
| 1542 | |
Piotr Caban | c253bab | 2011-11-28 15:05:25 +0100 | [diff] [blame] | 1543 | *(end-1) = '\r'; |
Piotr Caban | c801c18 | 2008-10-07 22:10:43 +0200 | [diff] [blame] | 1544 | if(*end == '\n') |
| 1545 | { |
| 1546 | end++; |
| 1547 | This->column++; |
| 1548 | } |
| 1549 | cur = end; |
| 1550 | |
| 1551 | if(end-ch == len) break; |
Piotr Caban | 4038863 | 2008-07-17 00:41:40 +0200 | [diff] [blame] | 1552 | } |
| 1553 | } |
| 1554 | |
Piotr Caban | e47cbd1 | 2008-07-17 00:41:52 +0200 | [diff] [blame] | 1555 | static void libxmlSetDocumentLocator( |
| 1556 | void *ctx, |
| 1557 | xmlSAXLocatorPtr loc) |
| 1558 | { |
| 1559 | saxlocator *This = ctx; |
Nikolay Sivov | 843bd25 | 2010-10-29 01:00:44 +0400 | [diff] [blame] | 1560 | HRESULT hr = S_OK; |
Piotr Caban | e47cbd1 | 2008-07-17 00:41:52 +0200 | [diff] [blame] | 1561 | |
Nikolay Sivov | 843bd25 | 2010-10-29 01:00:44 +0400 | [diff] [blame] | 1562 | if(has_content_handler(This)) |
| 1563 | { |
| 1564 | if(This->vbInterface) |
Michael Stefaniuc | 13e1997 | 2010-12-27 23:12:06 +0100 | [diff] [blame] | 1565 | hr = IVBSAXContentHandler_putref_documentLocator(This->saxreader->vbcontentHandler, |
| 1566 | &This->IVBSAXLocator_iface); |
Nikolay Sivov | 843bd25 | 2010-10-29 01:00:44 +0400 | [diff] [blame] | 1567 | else |
Michael Stefaniuc | 13e1997 | 2010-12-27 23:12:06 +0100 | [diff] [blame] | 1568 | hr = ISAXContentHandler_putDocumentLocator(This->saxreader->contentHandler, |
| 1569 | &This->ISAXLocator_iface); |
Nikolay Sivov | 843bd25 | 2010-10-29 01:00:44 +0400 | [diff] [blame] | 1570 | } |
Piotr Caban | e47cbd1 | 2008-07-17 00:41:52 +0200 | [diff] [blame] | 1571 | |
| 1572 | if(FAILED(hr)) |
Piotr Caban | bba7eb5 | 2008-07-19 22:32:10 +0200 | [diff] [blame] | 1573 | format_error_message_from_id(This, hr); |
| 1574 | } |
| 1575 | |
Piotr Caban | db2761a | 2008-10-07 22:11:04 +0200 | [diff] [blame] | 1576 | static void libxmlComment(void *ctx, const xmlChar *value) |
| 1577 | { |
| 1578 | saxlocator *This = ctx; |
| 1579 | BSTR bValue; |
| 1580 | HRESULT hr; |
Piotr Caban | c253bab | 2011-11-28 15:05:25 +0100 | [diff] [blame] | 1581 | const xmlChar *p = This->pParserCtxt->input->cur; |
Piotr Caban | db2761a | 2008-10-07 22:11:04 +0200 | [diff] [blame] | 1582 | |
Piotr Caban | c253bab | 2011-11-28 15:05:25 +0100 | [diff] [blame] | 1583 | update_position(This, FALSE); |
| 1584 | while(p-4>=This->pParserCtxt->input->base |
| 1585 | && memcmp(p-4, "<!--", sizeof(char[4]))) |
| 1586 | { |
| 1587 | if(*p=='\n' || (*p=='\r' && *(p+1)!='\n')) |
| 1588 | This->line--; |
| 1589 | p--; |
| 1590 | } |
Nikolay Sivov | 2dc6711 | 2012-05-08 15:50:19 +0400 | [diff] [blame] | 1591 | |
Piotr Caban | c253bab | 2011-11-28 15:05:25 +0100 | [diff] [blame] | 1592 | This->column = 0; |
| 1593 | for(; p>=This->pParserCtxt->input->base && *p!='\n' && *p!='\r'; p--) |
| 1594 | This->column++; |
Piotr Caban | db2761a | 2008-10-07 22:11:04 +0200 | [diff] [blame] | 1595 | |
Nikolay Sivov | fc4dab4 | 2012-05-08 15:56:20 +0400 | [diff] [blame] | 1596 | if (!has_lexical_handler(This)) return; |
Piotr Caban | db2761a | 2008-10-07 22:11:04 +0200 | [diff] [blame] | 1597 | |
Andrew Nguyen | 9c5d5d8 | 2011-07-15 07:38:07 -0500 | [diff] [blame] | 1598 | bValue = pooled_bstr_from_xmlChar(&This->saxreader->pool, value); |
Piotr Caban | db2761a | 2008-10-07 22:11:04 +0200 | [diff] [blame] | 1599 | |
| 1600 | if(This->vbInterface) |
| 1601 | hr = IVBSAXLexicalHandler_comment( |
| 1602 | This->saxreader->vblexicalHandler, &bValue); |
| 1603 | else |
| 1604 | hr = ISAXLexicalHandler_comment( |
| 1605 | This->saxreader->lexicalHandler, |
| 1606 | bValue, SysStringLen(bValue)); |
| 1607 | |
Piotr Caban | db2761a | 2008-10-07 22:11:04 +0200 | [diff] [blame] | 1608 | if(FAILED(hr)) |
| 1609 | format_error_message_from_id(This, hr); |
Piotr Caban | db2761a | 2008-10-07 22:11:04 +0200 | [diff] [blame] | 1610 | } |
| 1611 | |
Piotr Caban | c801c18 | 2008-10-07 22:10:43 +0200 | [diff] [blame] | 1612 | static void libxmlFatalError(void *ctx, const char *msg, ...) |
Piotr Caban | bba7eb5 | 2008-07-19 22:32:10 +0200 | [diff] [blame] | 1613 | { |
| 1614 | saxlocator *This = ctx; |
| 1615 | char message[1024]; |
Nikolay Sivov | 9a3bfce | 2010-10-27 01:25:26 +0400 | [diff] [blame] | 1616 | WCHAR *error; |
Piotr Caban | bba7eb5 | 2008-07-19 22:32:10 +0200 | [diff] [blame] | 1617 | DWORD len; |
| 1618 | va_list args; |
| 1619 | |
Piotr Caban | 6927a11 | 2011-10-24 12:55:13 +0200 | [diff] [blame] | 1620 | if(This->ret != S_OK) { |
| 1621 | xmlStopParser(This->pParserCtxt); |
Piotr Caban | f8112cc | 2011-10-24 12:54:47 +0200 | [diff] [blame] | 1622 | return; |
Piotr Caban | 6927a11 | 2011-10-24 12:55:13 +0200 | [diff] [blame] | 1623 | } |
Piotr Caban | f8112cc | 2011-10-24 12:54:47 +0200 | [diff] [blame] | 1624 | |
Piotr Caban | bba7eb5 | 2008-07-19 22:32:10 +0200 | [diff] [blame] | 1625 | va_start(args, msg); |
| 1626 | vsprintf(message, msg, args); |
| 1627 | va_end(args); |
| 1628 | |
Rob Shearman | fd75c21 | 2008-08-26 20:06:09 +0100 | [diff] [blame] | 1629 | len = MultiByteToWideChar(CP_UNIXCP, 0, message, -1, NULL, 0); |
Nikolay Sivov | 9a3bfce | 2010-10-27 01:25:26 +0400 | [diff] [blame] | 1630 | error = heap_alloc(sizeof(WCHAR)*len); |
| 1631 | if(error) |
| 1632 | { |
| 1633 | MultiByteToWideChar(CP_UNIXCP, 0, message, -1, error, len); |
| 1634 | TRACE("fatal error for %p: %s\n", This, debugstr_w(error)); |
| 1635 | } |
Piotr Caban | bba7eb5 | 2008-07-19 22:32:10 +0200 | [diff] [blame] | 1636 | |
Nikolay Sivov | b1aaa86 | 2010-10-29 02:06:33 +0400 | [diff] [blame] | 1637 | if(!has_error_handler(This)) |
| 1638 | { |
| 1639 | xmlStopParser(This->pParserCtxt); |
| 1640 | This->ret = E_FAIL; |
| 1641 | heap_free(error); |
| 1642 | return; |
| 1643 | } |
| 1644 | |
| 1645 | FIXME("Error handling is not compatible.\n"); |
| 1646 | |
Piotr Caban | c52e091 | 2008-07-31 16:48:03 +0200 | [diff] [blame] | 1647 | if(This->vbInterface) |
| 1648 | { |
Nikolay Sivov | 9a3bfce | 2010-10-27 01:25:26 +0400 | [diff] [blame] | 1649 | BSTR bstrError = SysAllocString(error); |
Michael Stefaniuc | 13e1997 | 2010-12-27 23:12:06 +0100 | [diff] [blame] | 1650 | IVBSAXErrorHandler_fatalError(This->saxreader->vberrorHandler, &This->IVBSAXLocator_iface, |
| 1651 | &bstrError, E_FAIL); |
Nikolay Sivov | bd7787c | 2010-10-27 01:15:38 +0400 | [diff] [blame] | 1652 | SysFreeString(bstrError); |
Piotr Caban | c52e091 | 2008-07-31 16:48:03 +0200 | [diff] [blame] | 1653 | } |
| 1654 | else |
Michael Stefaniuc | 13e1997 | 2010-12-27 23:12:06 +0100 | [diff] [blame] | 1655 | ISAXErrorHandler_fatalError(This->saxreader->errorHandler, &This->ISAXLocator_iface, |
| 1656 | error, E_FAIL); |
Piotr Caban | bba7eb5 | 2008-07-19 22:32:10 +0200 | [diff] [blame] | 1657 | |
Nikolay Sivov | 9a3bfce | 2010-10-27 01:25:26 +0400 | [diff] [blame] | 1658 | heap_free(error); |
Piotr Caban | bba7eb5 | 2008-07-19 22:32:10 +0200 | [diff] [blame] | 1659 | |
| 1660 | xmlStopParser(This->pParserCtxt); |
| 1661 | This->ret = E_FAIL; |
Piotr Caban | e47cbd1 | 2008-07-17 00:41:52 +0200 | [diff] [blame] | 1662 | } |
| 1663 | |
Piotr Caban | b84e478 | 2008-10-07 22:11:11 +0200 | [diff] [blame] | 1664 | static void libxmlCDataBlock(void *ctx, const xmlChar *value, int len) |
| 1665 | { |
| 1666 | saxlocator *This = ctx; |
| 1667 | HRESULT hr = S_OK; |
| 1668 | xmlChar *beg = (xmlChar*)This->pParserCtxt->input->cur-len; |
| 1669 | xmlChar *cur, *end; |
| 1670 | int realLen; |
| 1671 | BSTR Chars; |
| 1672 | BOOL lastEvent = FALSE, change; |
| 1673 | |
Piotr Caban | c253bab | 2011-11-28 15:05:25 +0100 | [diff] [blame] | 1674 | update_position(This, FALSE); |
Piotr Caban | a42a091 | 2010-06-27 15:21:28 +0200 | [diff] [blame] | 1675 | while(beg-9>=This->pParserCtxt->input->base |
Piotr Caban | c253bab | 2011-11-28 15:05:25 +0100 | [diff] [blame] | 1676 | && memcmp(beg-9, "<![CDATA[", sizeof(char[9]))) |
| 1677 | { |
| 1678 | if(*beg=='\n' || (*beg=='\r' && *(beg+1)!='\n')) |
| 1679 | This->line--; |
| 1680 | beg--; |
| 1681 | } |
| 1682 | This->column = 0; |
| 1683 | for(; beg>=This->pParserCtxt->input->base && *beg!='\n' && *beg!='\r'; beg--) |
| 1684 | This->column++; |
Piotr Caban | b84e478 | 2008-10-07 22:11:11 +0200 | [diff] [blame] | 1685 | |
Nikolay Sivov | fc4dab4 | 2012-05-08 15:56:20 +0400 | [diff] [blame] | 1686 | if (has_lexical_handler(This)) |
| 1687 | { |
| 1688 | if (This->vbInterface) |
| 1689 | hr = IVBSAXLexicalHandler_startCDATA(This->saxreader->vblexicalHandler); |
| 1690 | else |
| 1691 | hr = ISAXLexicalHandler_startCDATA(This->saxreader->lexicalHandler); |
| 1692 | } |
Piotr Caban | b84e478 | 2008-10-07 22:11:11 +0200 | [diff] [blame] | 1693 | |
| 1694 | if(FAILED(hr)) |
Andrew Talbot | ce3af50 | 2008-11-13 22:20:52 +0000 | [diff] [blame] | 1695 | { |
| 1696 | format_error_message_from_id(This, hr); |
| 1697 | return; |
| 1698 | } |
Piotr Caban | b84e478 | 2008-10-07 22:11:11 +0200 | [diff] [blame] | 1699 | |
| 1700 | realLen = This->pParserCtxt->input->cur-beg-3; |
| 1701 | cur = beg; |
| 1702 | end = beg; |
| 1703 | |
| 1704 | while(1) |
| 1705 | { |
| 1706 | while(end-beg<realLen && *end!='\r') end++; |
| 1707 | if(end-beg==realLen) |
| 1708 | { |
| 1709 | end--; |
| 1710 | lastEvent = TRUE; |
| 1711 | } |
| 1712 | else if(end-beg==realLen-1 && *end=='\r' && *(end+1)=='\n') |
| 1713 | lastEvent = TRUE; |
| 1714 | |
| 1715 | if(*end == '\r') change = TRUE; |
| 1716 | else change = FALSE; |
| 1717 | |
| 1718 | if(change) *end = '\n'; |
| 1719 | |
Nikolay Sivov | ff99228 | 2010-01-18 23:30:50 +0300 | [diff] [blame] | 1720 | if(has_content_handler(This)) |
Piotr Caban | b84e478 | 2008-10-07 22:11:11 +0200 | [diff] [blame] | 1721 | { |
Andrew Nguyen | 9c5d5d8 | 2011-07-15 07:38:07 -0500 | [diff] [blame] | 1722 | Chars = pooled_bstr_from_xmlCharN(&This->saxreader->pool, cur, end-cur+1); |
Piotr Caban | b84e478 | 2008-10-07 22:11:11 +0200 | [diff] [blame] | 1723 | if(This->vbInterface) |
| 1724 | hr = IVBSAXContentHandler_characters( |
| 1725 | This->saxreader->vbcontentHandler, &Chars); |
| 1726 | else |
| 1727 | hr = ISAXContentHandler_characters( |
| 1728 | This->saxreader->contentHandler, |
| 1729 | Chars, SysStringLen(Chars)); |
Piotr Caban | b84e478 | 2008-10-07 22:11:11 +0200 | [diff] [blame] | 1730 | } |
| 1731 | |
| 1732 | if(change) *end = '\r'; |
| 1733 | |
| 1734 | if(lastEvent) |
| 1735 | break; |
| 1736 | |
| 1737 | This->column += end-cur+2; |
| 1738 | end += 2; |
| 1739 | cur = end; |
| 1740 | } |
| 1741 | |
Nikolay Sivov | fc4dab4 | 2012-05-08 15:56:20 +0400 | [diff] [blame] | 1742 | if (has_lexical_handler(This)) |
| 1743 | { |
| 1744 | if (This->vbInterface) |
| 1745 | hr = IVBSAXLexicalHandler_endCDATA(This->saxreader->vblexicalHandler); |
| 1746 | else |
| 1747 | hr = ISAXLexicalHandler_endCDATA(This->saxreader->lexicalHandler); |
| 1748 | } |
Piotr Caban | b84e478 | 2008-10-07 22:11:11 +0200 | [diff] [blame] | 1749 | |
| 1750 | if(FAILED(hr)) |
| 1751 | format_error_message_from_id(This, hr); |
| 1752 | |
| 1753 | This->column += 4+end-cur; |
| 1754 | } |
| 1755 | |
Piotr Caban | d439ca5 | 2008-07-31 16:48:11 +0200 | [diff] [blame] | 1756 | /*** IVBSAXLocator interface ***/ |
| 1757 | /*** IUnknown methods ***/ |
| 1758 | static HRESULT WINAPI ivbsaxlocator_QueryInterface(IVBSAXLocator* iface, REFIID riid, void **ppvObject) |
| 1759 | { |
| 1760 | saxlocator *This = impl_from_IVBSAXLocator( iface ); |
| 1761 | |
| 1762 | TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject); |
| 1763 | |
| 1764 | *ppvObject = NULL; |
| 1765 | |
| 1766 | if ( IsEqualGUID( riid, &IID_IUnknown ) || |
| 1767 | IsEqualGUID( riid, &IID_IDispatch) || |
| 1768 | IsEqualGUID( riid, &IID_IVBSAXLocator )) |
| 1769 | { |
| 1770 | *ppvObject = iface; |
| 1771 | } |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 1772 | else if ( IsEqualGUID( riid, &IID_IVBSAXAttributes )) |
| 1773 | { |
| 1774 | *ppvObject = &This->IVBSAXAttributes_iface; |
| 1775 | } |
Piotr Caban | d439ca5 | 2008-07-31 16:48:11 +0200 | [diff] [blame] | 1776 | else |
| 1777 | { |
| 1778 | FIXME("interface %s not implemented\n", debugstr_guid(riid)); |
| 1779 | return E_NOINTERFACE; |
| 1780 | } |
| 1781 | |
| 1782 | IVBSAXLocator_AddRef( iface ); |
| 1783 | |
| 1784 | return S_OK; |
| 1785 | } |
| 1786 | |
| 1787 | static ULONG WINAPI ivbsaxlocator_AddRef(IVBSAXLocator* iface) |
| 1788 | { |
| 1789 | saxlocator *This = impl_from_IVBSAXLocator( iface ); |
| 1790 | TRACE("%p\n", This ); |
| 1791 | return InterlockedIncrement( &This->ref ); |
| 1792 | } |
| 1793 | |
| 1794 | static ULONG WINAPI ivbsaxlocator_Release( |
| 1795 | IVBSAXLocator* iface) |
| 1796 | { |
| 1797 | saxlocator *This = impl_from_IVBSAXLocator( iface ); |
Michael Stefaniuc | 13e1997 | 2010-12-27 23:12:06 +0100 | [diff] [blame] | 1798 | return ISAXLocator_Release((ISAXLocator*)&This->IVBSAXLocator_iface); |
Piotr Caban | d439ca5 | 2008-07-31 16:48:11 +0200 | [diff] [blame] | 1799 | } |
| 1800 | |
| 1801 | /*** IDispatch methods ***/ |
| 1802 | static HRESULT WINAPI ivbsaxlocator_GetTypeInfoCount( IVBSAXLocator *iface, UINT* pctinfo ) |
| 1803 | { |
| 1804 | saxlocator *This = impl_from_IVBSAXLocator( iface ); |
| 1805 | |
| 1806 | TRACE("(%p)->(%p)\n", This, pctinfo); |
| 1807 | |
| 1808 | *pctinfo = 1; |
| 1809 | |
| 1810 | return S_OK; |
| 1811 | } |
| 1812 | |
| 1813 | static HRESULT WINAPI ivbsaxlocator_GetTypeInfo( |
| 1814 | IVBSAXLocator *iface, |
| 1815 | UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo ) |
| 1816 | { |
| 1817 | saxlocator *This = impl_from_IVBSAXLocator( iface ); |
| 1818 | HRESULT hr; |
| 1819 | |
| 1820 | TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo); |
| 1821 | |
| 1822 | hr = get_typeinfo(IVBSAXLocator_tid, ppTInfo); |
| 1823 | |
| 1824 | return hr; |
| 1825 | } |
| 1826 | |
| 1827 | static HRESULT WINAPI ivbsaxlocator_GetIDsOfNames( |
| 1828 | IVBSAXLocator *iface, |
| 1829 | REFIID riid, |
| 1830 | LPOLESTR* rgszNames, |
| 1831 | UINT cNames, |
| 1832 | LCID lcid, |
| 1833 | DISPID* rgDispId) |
| 1834 | { |
| 1835 | saxlocator *This = impl_from_IVBSAXLocator( iface ); |
| 1836 | ITypeInfo *typeinfo; |
| 1837 | HRESULT hr; |
| 1838 | |
| 1839 | TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames, |
| 1840 | lcid, rgDispId); |
| 1841 | |
| 1842 | if(!rgszNames || cNames == 0 || !rgDispId) |
| 1843 | return E_INVALIDARG; |
| 1844 | |
| 1845 | hr = get_typeinfo(IVBSAXLocator_tid, &typeinfo); |
| 1846 | if(SUCCEEDED(hr)) |
| 1847 | { |
| 1848 | hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId); |
| 1849 | ITypeInfo_Release(typeinfo); |
| 1850 | } |
| 1851 | |
| 1852 | return hr; |
| 1853 | } |
| 1854 | |
| 1855 | static HRESULT WINAPI ivbsaxlocator_Invoke( |
| 1856 | IVBSAXLocator *iface, |
| 1857 | DISPID dispIdMember, |
| 1858 | REFIID riid, |
| 1859 | LCID lcid, |
| 1860 | WORD wFlags, |
| 1861 | DISPPARAMS* pDispParams, |
| 1862 | VARIANT* pVarResult, |
| 1863 | EXCEPINFO* pExcepInfo, |
| 1864 | UINT* puArgErr) |
| 1865 | { |
| 1866 | saxlocator *This = impl_from_IVBSAXLocator( iface ); |
| 1867 | ITypeInfo *typeinfo; |
| 1868 | HRESULT hr; |
| 1869 | |
| 1870 | TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid), |
| 1871 | lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr); |
| 1872 | |
| 1873 | hr = get_typeinfo(IVBSAXLocator_tid, &typeinfo); |
| 1874 | if(SUCCEEDED(hr)) |
| 1875 | { |
Michael Stefaniuc | 13e1997 | 2010-12-27 23:12:06 +0100 | [diff] [blame] | 1876 | hr = ITypeInfo_Invoke(typeinfo, &This->IVBSAXLocator_iface, dispIdMember, wFlags, |
| 1877 | pDispParams, pVarResult, pExcepInfo, puArgErr); |
Piotr Caban | d439ca5 | 2008-07-31 16:48:11 +0200 | [diff] [blame] | 1878 | ITypeInfo_Release(typeinfo); |
| 1879 | } |
| 1880 | |
| 1881 | return hr; |
| 1882 | } |
| 1883 | |
| 1884 | /*** IVBSAXLocator methods ***/ |
| 1885 | static HRESULT WINAPI ivbsaxlocator_get_columnNumber( |
| 1886 | IVBSAXLocator* iface, |
| 1887 | int *pnColumn) |
| 1888 | { |
| 1889 | saxlocator *This = impl_from_IVBSAXLocator( iface ); |
Michael Stefaniuc | 13e1997 | 2010-12-27 23:12:06 +0100 | [diff] [blame] | 1890 | return ISAXLocator_getColumnNumber((ISAXLocator*)&This->IVBSAXLocator_iface, pnColumn); |
Piotr Caban | d439ca5 | 2008-07-31 16:48:11 +0200 | [diff] [blame] | 1891 | } |
| 1892 | |
| 1893 | static HRESULT WINAPI ivbsaxlocator_get_lineNumber( |
| 1894 | IVBSAXLocator* iface, |
| 1895 | int *pnLine) |
| 1896 | { |
| 1897 | saxlocator *This = impl_from_IVBSAXLocator( iface ); |
Michael Stefaniuc | 13e1997 | 2010-12-27 23:12:06 +0100 | [diff] [blame] | 1898 | return ISAXLocator_getLineNumber((ISAXLocator*)&This->IVBSAXLocator_iface, pnLine); |
Piotr Caban | d439ca5 | 2008-07-31 16:48:11 +0200 | [diff] [blame] | 1899 | } |
| 1900 | |
| 1901 | static HRESULT WINAPI ivbsaxlocator_get_publicId( |
| 1902 | IVBSAXLocator* iface, |
| 1903 | BSTR* publicId) |
| 1904 | { |
| 1905 | saxlocator *This = impl_from_IVBSAXLocator( iface ); |
Michael Stefaniuc | 13e1997 | 2010-12-27 23:12:06 +0100 | [diff] [blame] | 1906 | return ISAXLocator_getPublicId((ISAXLocator*)&This->IVBSAXLocator_iface, |
Piotr Caban | d439ca5 | 2008-07-31 16:48:11 +0200 | [diff] [blame] | 1907 | (const WCHAR**)publicId); |
| 1908 | } |
| 1909 | |
| 1910 | static HRESULT WINAPI ivbsaxlocator_get_systemId( |
| 1911 | IVBSAXLocator* iface, |
| 1912 | BSTR* systemId) |
| 1913 | { |
| 1914 | saxlocator *This = impl_from_IVBSAXLocator( iface ); |
Michael Stefaniuc | 13e1997 | 2010-12-27 23:12:06 +0100 | [diff] [blame] | 1915 | return ISAXLocator_getSystemId((ISAXLocator*)&This->IVBSAXLocator_iface, |
Piotr Caban | d439ca5 | 2008-07-31 16:48:11 +0200 | [diff] [blame] | 1916 | (const WCHAR**)systemId); |
| 1917 | } |
| 1918 | |
Nikolay Sivov | 9d66292 | 2011-12-24 16:10:33 +0300 | [diff] [blame] | 1919 | static const struct IVBSAXLocatorVtbl VBSAXLocatorVtbl = |
Piotr Caban | d439ca5 | 2008-07-31 16:48:11 +0200 | [diff] [blame] | 1920 | { |
| 1921 | ivbsaxlocator_QueryInterface, |
| 1922 | ivbsaxlocator_AddRef, |
| 1923 | ivbsaxlocator_Release, |
| 1924 | ivbsaxlocator_GetTypeInfoCount, |
| 1925 | ivbsaxlocator_GetTypeInfo, |
| 1926 | ivbsaxlocator_GetIDsOfNames, |
| 1927 | ivbsaxlocator_Invoke, |
| 1928 | ivbsaxlocator_get_columnNumber, |
| 1929 | ivbsaxlocator_get_lineNumber, |
| 1930 | ivbsaxlocator_get_publicId, |
| 1931 | ivbsaxlocator_get_systemId |
| 1932 | }; |
| 1933 | |
Piotr Caban | d3e9ca7 | 2008-07-17 00:40:32 +0200 | [diff] [blame] | 1934 | /*** ISAXLocator interface ***/ |
| 1935 | /*** IUnknown methods ***/ |
| 1936 | static HRESULT WINAPI isaxlocator_QueryInterface(ISAXLocator* iface, REFIID riid, void **ppvObject) |
| 1937 | { |
| 1938 | saxlocator *This = impl_from_ISAXLocator( iface ); |
| 1939 | |
| 1940 | TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject ); |
| 1941 | |
| 1942 | *ppvObject = NULL; |
| 1943 | |
| 1944 | if ( IsEqualGUID( riid, &IID_IUnknown ) || |
| 1945 | IsEqualGUID( riid, &IID_ISAXLocator )) |
| 1946 | { |
| 1947 | *ppvObject = iface; |
| 1948 | } |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 1949 | else if ( IsEqualGUID( riid, &IID_ISAXAttributes )) |
| 1950 | { |
| 1951 | *ppvObject = &This->ISAXAttributes_iface; |
| 1952 | } |
Piotr Caban | d3e9ca7 | 2008-07-17 00:40:32 +0200 | [diff] [blame] | 1953 | else |
| 1954 | { |
Nikolay Sivov | 1554cbc | 2012-04-19 10:55:17 +0400 | [diff] [blame] | 1955 | WARN("interface %s not implemented\n", debugstr_guid(riid)); |
Piotr Caban | d3e9ca7 | 2008-07-17 00:40:32 +0200 | [diff] [blame] | 1956 | return E_NOINTERFACE; |
| 1957 | } |
| 1958 | |
| 1959 | ISAXLocator_AddRef( iface ); |
| 1960 | |
| 1961 | return S_OK; |
| 1962 | } |
| 1963 | |
| 1964 | static ULONG WINAPI isaxlocator_AddRef(ISAXLocator* iface) |
| 1965 | { |
| 1966 | saxlocator *This = impl_from_ISAXLocator( iface ); |
Nikolay Sivov | 9d66292 | 2011-12-24 16:10:33 +0300 | [diff] [blame] | 1967 | ULONG ref = InterlockedIncrement( &This->ref ); |
| 1968 | TRACE("(%p)->(%d)\n", This, ref); |
| 1969 | return ref; |
Piotr Caban | d3e9ca7 | 2008-07-17 00:40:32 +0200 | [diff] [blame] | 1970 | } |
| 1971 | |
| 1972 | static ULONG WINAPI isaxlocator_Release( |
| 1973 | ISAXLocator* iface) |
| 1974 | { |
| 1975 | saxlocator *This = impl_from_ISAXLocator( iface ); |
Nikolay Sivov | 9d66292 | 2011-12-24 16:10:33 +0300 | [diff] [blame] | 1976 | LONG ref = InterlockedDecrement( &This->ref ); |
Piotr Caban | d3e9ca7 | 2008-07-17 00:40:32 +0200 | [diff] [blame] | 1977 | |
Nikolay Sivov | 9d66292 | 2011-12-24 16:10:33 +0300 | [diff] [blame] | 1978 | TRACE("(%p)->(%d)\n", This, ref ); |
Piotr Caban | d3e9ca7 | 2008-07-17 00:40:32 +0200 | [diff] [blame] | 1979 | |
Nikolay Sivov | 9d66292 | 2011-12-24 16:10:33 +0300 | [diff] [blame] | 1980 | if (ref == 0) |
Piotr Caban | d3e9ca7 | 2008-07-17 00:40:32 +0200 | [diff] [blame] | 1981 | { |
Nikolay Sivov | 9d66292 | 2011-12-24 16:10:33 +0300 | [diff] [blame] | 1982 | element_entry *element, *element2; |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 1983 | int index; |
| 1984 | |
Detlef Riekenberg | f4558c6 | 2008-09-21 15:56:18 +0200 | [diff] [blame] | 1985 | SysFreeString(This->publicId); |
| 1986 | SysFreeString(This->systemId); |
Piotr Caban | a95b35d | 2011-10-31 12:33:18 +0100 | [diff] [blame] | 1987 | SysFreeString(This->namespaceUri); |
Piotr Caban | 60ca0a7 | 2008-07-17 00:42:01 +0200 | [diff] [blame] | 1988 | |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 1989 | for(index=0; index<This->nb_attributes; index++) |
| 1990 | { |
| 1991 | SysFreeString(This->attributes[index].szLocalname); |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 1992 | SysFreeString(This->attributes[index].szValue); |
| 1993 | SysFreeString(This->attributes[index].szQName); |
| 1994 | } |
| 1995 | heap_free(This->attributes); |
| 1996 | |
Nikolay Sivov | 9d66292 | 2011-12-24 16:10:33 +0300 | [diff] [blame] | 1997 | /* element stack */ |
| 1998 | LIST_FOR_EACH_ENTRY_SAFE(element, element2, &This->elements, element_entry, entry) |
| 1999 | { |
| 2000 | list_remove(&element->entry); |
| 2001 | free_element_entry(element); |
| 2002 | } |
| 2003 | |
Michael Stefaniuc | 13e1997 | 2010-12-27 23:12:06 +0100 | [diff] [blame] | 2004 | ISAXXMLReader_Release(&This->saxreader->ISAXXMLReader_iface); |
Nikolay Sivov | d8a9a69 | 2010-02-03 22:47:53 +0300 | [diff] [blame] | 2005 | heap_free( This ); |
Piotr Caban | d3e9ca7 | 2008-07-17 00:40:32 +0200 | [diff] [blame] | 2006 | } |
| 2007 | |
| 2008 | return ref; |
| 2009 | } |
| 2010 | |
| 2011 | /*** ISAXLocator methods ***/ |
| 2012 | static HRESULT WINAPI isaxlocator_getColumnNumber( |
| 2013 | ISAXLocator* iface, |
| 2014 | int *pnColumn) |
| 2015 | { |
| 2016 | saxlocator *This = impl_from_ISAXLocator( iface ); |
| 2017 | |
Piotr Caban | bb849dc | 2008-07-23 16:39:04 +0200 | [diff] [blame] | 2018 | *pnColumn = This->column; |
Piotr Caban | 4cdcc02 | 2008-07-17 00:41:11 +0200 | [diff] [blame] | 2019 | return S_OK; |
Piotr Caban | d3e9ca7 | 2008-07-17 00:40:32 +0200 | [diff] [blame] | 2020 | } |
| 2021 | |
| 2022 | static HRESULT WINAPI isaxlocator_getLineNumber( |
| 2023 | ISAXLocator* iface, |
| 2024 | int *pnLine) |
| 2025 | { |
| 2026 | saxlocator *This = impl_from_ISAXLocator( iface ); |
| 2027 | |
Piotr Caban | bb849dc | 2008-07-23 16:39:04 +0200 | [diff] [blame] | 2028 | *pnLine = This->line; |
Piotr Caban | 4cdcc02 | 2008-07-17 00:41:11 +0200 | [diff] [blame] | 2029 | return S_OK; |
Piotr Caban | d3e9ca7 | 2008-07-17 00:40:32 +0200 | [diff] [blame] | 2030 | } |
| 2031 | |
| 2032 | static HRESULT WINAPI isaxlocator_getPublicId( |
| 2033 | ISAXLocator* iface, |
| 2034 | const WCHAR ** ppwchPublicId) |
| 2035 | { |
Piotr Caban | 60ca0a7 | 2008-07-17 00:42:01 +0200 | [diff] [blame] | 2036 | BSTR publicId; |
Piotr Caban | d3e9ca7 | 2008-07-17 00:40:32 +0200 | [diff] [blame] | 2037 | saxlocator *This = impl_from_ISAXLocator( iface ); |
| 2038 | |
Detlef Riekenberg | f4558c6 | 2008-09-21 15:56:18 +0200 | [diff] [blame] | 2039 | SysFreeString(This->publicId); |
Piotr Caban | 60ca0a7 | 2008-07-17 00:42:01 +0200 | [diff] [blame] | 2040 | |
| 2041 | publicId = bstr_from_xmlChar(xmlSAX2GetPublicId(This->pParserCtxt)); |
| 2042 | if(SysStringLen(publicId)) |
| 2043 | This->publicId = (WCHAR*)&publicId; |
| 2044 | else |
| 2045 | { |
| 2046 | SysFreeString(publicId); |
| 2047 | This->publicId = NULL; |
| 2048 | } |
| 2049 | |
| 2050 | *ppwchPublicId = This->publicId; |
| 2051 | return S_OK; |
Piotr Caban | d3e9ca7 | 2008-07-17 00:40:32 +0200 | [diff] [blame] | 2052 | } |
| 2053 | |
| 2054 | static HRESULT WINAPI isaxlocator_getSystemId( |
| 2055 | ISAXLocator* iface, |
| 2056 | const WCHAR ** ppwchSystemId) |
| 2057 | { |
Piotr Caban | 3196f78 | 2008-07-17 00:42:07 +0200 | [diff] [blame] | 2058 | BSTR systemId; |
Piotr Caban | d3e9ca7 | 2008-07-17 00:40:32 +0200 | [diff] [blame] | 2059 | saxlocator *This = impl_from_ISAXLocator( iface ); |
| 2060 | |
Detlef Riekenberg | f4558c6 | 2008-09-21 15:56:18 +0200 | [diff] [blame] | 2061 | SysFreeString(This->systemId); |
Piotr Caban | 3196f78 | 2008-07-17 00:42:07 +0200 | [diff] [blame] | 2062 | |
| 2063 | systemId = bstr_from_xmlChar(xmlSAX2GetSystemId(This->pParserCtxt)); |
| 2064 | if(SysStringLen(systemId)) |
| 2065 | This->systemId = (WCHAR*)&systemId; |
| 2066 | else |
| 2067 | { |
| 2068 | SysFreeString(systemId); |
| 2069 | This->systemId = NULL; |
| 2070 | } |
| 2071 | |
| 2072 | *ppwchSystemId = This->systemId; |
| 2073 | return S_OK; |
Piotr Caban | d3e9ca7 | 2008-07-17 00:40:32 +0200 | [diff] [blame] | 2074 | } |
| 2075 | |
Nikolay Sivov | 9d66292 | 2011-12-24 16:10:33 +0300 | [diff] [blame] | 2076 | static const struct ISAXLocatorVtbl SAXLocatorVtbl = |
Piotr Caban | d3e9ca7 | 2008-07-17 00:40:32 +0200 | [diff] [blame] | 2077 | { |
| 2078 | isaxlocator_QueryInterface, |
| 2079 | isaxlocator_AddRef, |
| 2080 | isaxlocator_Release, |
| 2081 | isaxlocator_getColumnNumber, |
| 2082 | isaxlocator_getLineNumber, |
| 2083 | isaxlocator_getPublicId, |
| 2084 | isaxlocator_getSystemId |
| 2085 | }; |
| 2086 | |
Piotr Caban | c52e091 | 2008-07-31 16:48:03 +0200 | [diff] [blame] | 2087 | static HRESULT SAXLocator_create(saxreader *reader, saxlocator **ppsaxlocator, BOOL vbInterface) |
Piotr Caban | d3e9ca7 | 2008-07-17 00:40:32 +0200 | [diff] [blame] | 2088 | { |
Piotr Caban | a95b35d | 2011-10-31 12:33:18 +0100 | [diff] [blame] | 2089 | static const WCHAR w3xmlns[] = { 'h','t','t','p',':','/','/', 'w','w','w','.','w','3','.', |
| 2090 | 'o','r','g','/','2','0','0','0','/','x','m','l','n','s','/',0 }; |
| 2091 | |
Piotr Caban | d3e9ca7 | 2008-07-17 00:40:32 +0200 | [diff] [blame] | 2092 | saxlocator *locator; |
| 2093 | |
Nikolay Sivov | d8a9a69 | 2010-02-03 22:47:53 +0300 | [diff] [blame] | 2094 | locator = heap_alloc( sizeof (*locator) ); |
Piotr Caban | d3e9ca7 | 2008-07-17 00:40:32 +0200 | [diff] [blame] | 2095 | if( !locator ) |
| 2096 | return E_OUTOFMEMORY; |
| 2097 | |
Nikolay Sivov | 9d66292 | 2011-12-24 16:10:33 +0300 | [diff] [blame] | 2098 | locator->IVBSAXLocator_iface.lpVtbl = &VBSAXLocatorVtbl; |
| 2099 | locator->ISAXLocator_iface.lpVtbl = &SAXLocatorVtbl; |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 2100 | locator->IVBSAXAttributes_iface.lpVtbl = &ivbsaxattributes_vtbl; |
| 2101 | locator->ISAXAttributes_iface.lpVtbl = &isaxattributes_vtbl; |
Piotr Caban | d3e9ca7 | 2008-07-17 00:40:32 +0200 | [diff] [blame] | 2102 | locator->ref = 1; |
Piotr Caban | c52e091 | 2008-07-31 16:48:03 +0200 | [diff] [blame] | 2103 | locator->vbInterface = vbInterface; |
Piotr Caban | d3e9ca7 | 2008-07-17 00:40:32 +0200 | [diff] [blame] | 2104 | |
| 2105 | locator->saxreader = reader; |
Michael Stefaniuc | 13e1997 | 2010-12-27 23:12:06 +0100 | [diff] [blame] | 2106 | ISAXXMLReader_AddRef(&reader->ISAXXMLReader_iface); |
Piotr Caban | d3e9ca7 | 2008-07-17 00:40:32 +0200 | [diff] [blame] | 2107 | |
Piotr Caban | 51c9527 | 2008-07-17 00:40:53 +0200 | [diff] [blame] | 2108 | locator->pParserCtxt = NULL; |
Piotr Caban | 60ca0a7 | 2008-07-17 00:42:01 +0200 | [diff] [blame] | 2109 | locator->publicId = NULL; |
Piotr Caban | 3196f78 | 2008-07-17 00:42:07 +0200 | [diff] [blame] | 2110 | locator->systemId = NULL; |
Nikolay Sivov | bcd8585 | 2012-04-15 13:47:30 +0400 | [diff] [blame] | 2111 | locator->line = reader->version < MSXML4 ? 0 : 1; |
Piotr Caban | bb849dc | 2008-07-23 16:39:04 +0200 | [diff] [blame] | 2112 | locator->column = 0; |
Piotr Caban | 51c9527 | 2008-07-17 00:40:53 +0200 | [diff] [blame] | 2113 | locator->ret = S_OK; |
Nikolay Sivov | bcd8585 | 2012-04-15 13:47:30 +0400 | [diff] [blame] | 2114 | if (locator->saxreader->version >= MSXML6) |
Piotr Caban | a95b35d | 2011-10-31 12:33:18 +0100 | [diff] [blame] | 2115 | locator->namespaceUri = SysAllocString(w3xmlns); |
| 2116 | else |
| 2117 | locator->namespaceUri = SysAllocStringLen(NULL, 0); |
| 2118 | if(!locator->namespaceUri) |
| 2119 | { |
| 2120 | ISAXXMLReader_Release(&reader->ISAXXMLReader_iface); |
| 2121 | heap_free(locator); |
| 2122 | return E_OUTOFMEMORY; |
| 2123 | } |
Piotr Caban | 51c9527 | 2008-07-17 00:40:53 +0200 | [diff] [blame] | 2124 | |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 2125 | locator->attributesSize = 8; |
| 2126 | locator->nb_attributes = 0; |
| 2127 | locator->attributes = heap_alloc(sizeof(struct _attributes)*locator->attributesSize); |
| 2128 | if(!locator->attributes) |
| 2129 | { |
| 2130 | ISAXXMLReader_Release(&reader->ISAXXMLReader_iface); |
Piotr Caban | a95b35d | 2011-10-31 12:33:18 +0100 | [diff] [blame] | 2131 | SysFreeString(locator->namespaceUri); |
Piotr Caban | 1b46206 | 2011-10-31 12:32:39 +0100 | [diff] [blame] | 2132 | heap_free(locator); |
| 2133 | return E_OUTOFMEMORY; |
| 2134 | } |
| 2135 | |
Nikolay Sivov | 9d66292 | 2011-12-24 16:10:33 +0300 | [diff] [blame] | 2136 | list_init(&locator->elements); |
| 2137 | |
Piotr Caban | d3e9ca7 | 2008-07-17 00:40:32 +0200 | [diff] [blame] | 2138 | *ppsaxlocator = locator; |
| 2139 | |
| 2140 | TRACE("returning %p\n", *ppsaxlocator); |
| 2141 | |
| 2142 | return S_OK; |
| 2143 | } |
| 2144 | |
Piotr Caban | cb6bcd0 | 2008-07-31 16:48:20 +0200 | [diff] [blame] | 2145 | /*** SAXXMLReader internal functions ***/ |
| 2146 | static HRESULT internal_parseBuffer(saxreader *This, const char *buffer, int size, BOOL vbInterface) |
| 2147 | { |
Nikolay Sivov | 678fbc1 | 2010-10-30 18:49:43 +0400 | [diff] [blame] | 2148 | xmlCharEncoding encoding = XML_CHAR_ENCODING_NONE; |
| 2149 | xmlChar *enc_name = NULL; |
Piotr Caban | cb6bcd0 | 2008-07-31 16:48:20 +0200 | [diff] [blame] | 2150 | saxlocator *locator; |
| 2151 | HRESULT hr; |
| 2152 | |
| 2153 | hr = SAXLocator_create(This, &locator, vbInterface); |
Nikolay Sivov | 221f9ef | 2012-04-21 12:32:15 +0400 | [diff] [blame] | 2154 | if (FAILED(hr)) |
Ricardo Filipe | e5e301b | 2008-11-13 13:33:27 +0000 | [diff] [blame] | 2155 | return hr; |
Piotr Caban | cb6bcd0 | 2008-07-31 16:48:20 +0200 | [diff] [blame] | 2156 | |
Nikolay Sivov | 678fbc1 | 2010-10-30 18:49:43 +0400 | [diff] [blame] | 2157 | if (size >= 4) |
| 2158 | { |
| 2159 | const unsigned char *buff = (unsigned char*)buffer; |
| 2160 | |
| 2161 | encoding = xmlDetectCharEncoding((xmlChar*)buffer, 4); |
| 2162 | enc_name = (xmlChar*)xmlGetCharEncodingName(encoding); |
| 2163 | TRACE("detected encoding: %s\n", enc_name); |
| 2164 | /* skip BOM, parser won't switch encodings and so won't skip it on its own */ |
| 2165 | if ((encoding == XML_CHAR_ENCODING_UTF8) && |
| 2166 | buff[0] == 0xEF && buff[1] == 0xBB && buff[2] == 0xBF) |
| 2167 | { |
| 2168 | buffer += 3; |
| 2169 | size -= 3; |
| 2170 | } |
| 2171 | } |
| 2172 | |
Nikolay Sivov | 221f9ef | 2012-04-21 12:32:15 +0400 | [diff] [blame] | 2173 | /* if libxml2 detection failed try to guess */ |
| 2174 | if (encoding == XML_CHAR_ENCODING_NONE) |
| 2175 | { |
| 2176 | const WCHAR *ptr = (WCHAR*)buffer; |
| 2177 | /* xml declaration with possibly specfied encoding will be still handled by parser */ |
| 2178 | if ((size >= 2) && *ptr == '<' && ptr[1] != '?') |
| 2179 | { |
| 2180 | enc_name = (xmlChar*)xmlGetCharEncodingName(XML_CHAR_ENCODING_UTF16LE); |
| 2181 | encoding = XML_CHAR_ENCODING_UTF16LE; |
| 2182 | } |
| 2183 | } |
| 2184 | else if (encoding == XML_CHAR_ENCODING_UTF8) |
| 2185 | enc_name = (xmlChar*)xmlGetCharEncodingName(encoding); |
| 2186 | else |
| 2187 | enc_name = NULL; |
| 2188 | |
Piotr Caban | cb6bcd0 | 2008-07-31 16:48:20 +0200 | [diff] [blame] | 2189 | locator->pParserCtxt = xmlCreateMemoryParserCtxt(buffer, size); |
Nikolay Sivov | 221f9ef | 2012-04-21 12:32:15 +0400 | [diff] [blame] | 2190 | if (!locator->pParserCtxt) |
Piotr Caban | cb6bcd0 | 2008-07-31 16:48:20 +0200 | [diff] [blame] | 2191 | { |
Michael Stefaniuc | 13e1997 | 2010-12-27 23:12:06 +0100 | [diff] [blame] | 2192 | ISAXLocator_Release(&locator->ISAXLocator_iface); |
Piotr Caban | cb6bcd0 | 2008-07-31 16:48:20 +0200 | [diff] [blame] | 2193 | return E_FAIL; |
| 2194 | } |
| 2195 | |
Nikolay Sivov | 221f9ef | 2012-04-21 12:32:15 +0400 | [diff] [blame] | 2196 | if (enc_name) |
| 2197 | { |
Nikolay Sivov | 678fbc1 | 2010-10-30 18:49:43 +0400 | [diff] [blame] | 2198 | locator->pParserCtxt->encoding = xmlStrdup(enc_name); |
Nikolay Sivov | 221f9ef | 2012-04-21 12:32:15 +0400 | [diff] [blame] | 2199 | if (encoding == XML_CHAR_ENCODING_UTF16LE) { |
| 2200 | TRACE("switching to %s\n", enc_name); |
| 2201 | xmlSwitchEncoding(locator->pParserCtxt, encoding); |
| 2202 | } |
| 2203 | } |
Nikolay Sivov | 678fbc1 | 2010-10-30 18:49:43 +0400 | [diff] [blame] | 2204 | |
Nikolay Sivov | e4d895c | 2010-01-10 18:17:37 +0300 | [diff] [blame] | 2205 | xmlFree(locator->pParserCtxt->sax); |
Piotr Caban | cb6bcd0 | 2008-07-31 16:48:20 +0200 | [diff] [blame] | 2206 | locator->pParserCtxt->sax = &locator->saxreader->sax; |
| 2207 | locator->pParserCtxt->userData = locator; |
| 2208 | |
Piotr Caban | c7fc926 | 2008-10-01 19:52:36 +0200 | [diff] [blame] | 2209 | This->isParsing = TRUE; |
Nikolay Sivov | 221f9ef | 2012-04-21 12:32:15 +0400 | [diff] [blame] | 2210 | if(xmlParseDocument(locator->pParserCtxt) == -1 && locator->ret == S_OK) |
Piotr Caban | 6927a11 | 2011-10-24 12:55:13 +0200 | [diff] [blame] | 2211 | hr = E_FAIL; |
| 2212 | else |
| 2213 | hr = locator->ret; |
Piotr Caban | c7fc926 | 2008-10-01 19:52:36 +0200 | [diff] [blame] | 2214 | This->isParsing = FALSE; |
Piotr Caban | cb6bcd0 | 2008-07-31 16:48:20 +0200 | [diff] [blame] | 2215 | |
| 2216 | if(locator->pParserCtxt) |
| 2217 | { |
| 2218 | locator->pParserCtxt->sax = NULL; |
| 2219 | xmlFreeParserCtxt(locator->pParserCtxt); |
| 2220 | locator->pParserCtxt = NULL; |
| 2221 | } |
| 2222 | |
Michael Stefaniuc | 13e1997 | 2010-12-27 23:12:06 +0100 | [diff] [blame] | 2223 | ISAXLocator_Release(&locator->ISAXLocator_iface); |
Ricardo Filipe | e5e301b | 2008-11-13 13:33:27 +0000 | [diff] [blame] | 2224 | return hr; |
Piotr Caban | cb6bcd0 | 2008-07-31 16:48:20 +0200 | [diff] [blame] | 2225 | } |
| 2226 | |
Piotr Caban | 38b0573 | 2008-09-08 15:07:46 +0200 | [diff] [blame] | 2227 | static HRESULT internal_parseStream(saxreader *This, IStream *stream, BOOL vbInterface) |
| 2228 | { |
| 2229 | saxlocator *locator; |
| 2230 | HRESULT hr; |
| 2231 | ULONG dataRead; |
| 2232 | char data[1024]; |
Nikolay Sivov | 809959d | 2011-09-21 13:48:17 +0400 | [diff] [blame] | 2233 | int ret; |
Piotr Caban | 38b0573 | 2008-09-08 15:07:46 +0200 | [diff] [blame] | 2234 | |
Nikolay Sivov | 809959d | 2011-09-21 13:48:17 +0400 | [diff] [blame] | 2235 | dataRead = 0; |
Piotr Caban | 38b0573 | 2008-09-08 15:07:46 +0200 | [diff] [blame] | 2236 | hr = IStream_Read(stream, data, sizeof(data), &dataRead); |
Nikolay Sivov | 809959d | 2011-09-21 13:48:17 +0400 | [diff] [blame] | 2237 | if(FAILED(hr)) return hr; |
Piotr Caban | 38b0573 | 2008-09-08 15:07:46 +0200 | [diff] [blame] | 2238 | |
| 2239 | hr = SAXLocator_create(This, &locator, vbInterface); |
Nikolay Sivov | 809959d | 2011-09-21 13:48:17 +0400 | [diff] [blame] | 2240 | if(FAILED(hr)) return hr; |
Piotr Caban | 38b0573 | 2008-09-08 15:07:46 +0200 | [diff] [blame] | 2241 | |
| 2242 | locator->pParserCtxt = xmlCreatePushParserCtxt( |
| 2243 | &locator->saxreader->sax, locator, |
| 2244 | data, dataRead, NULL); |
| 2245 | if(!locator->pParserCtxt) |
| 2246 | { |
Michael Stefaniuc | 13e1997 | 2010-12-27 23:12:06 +0100 | [diff] [blame] | 2247 | ISAXLocator_Release(&locator->ISAXLocator_iface); |
Piotr Caban | 38b0573 | 2008-09-08 15:07:46 +0200 | [diff] [blame] | 2248 | return E_FAIL; |
| 2249 | } |
| 2250 | |
Piotr Caban | c7fc926 | 2008-10-01 19:52:36 +0200 | [diff] [blame] | 2251 | This->isParsing = TRUE; |
Nikolay Sivov | 809959d | 2011-09-21 13:48:17 +0400 | [diff] [blame] | 2252 | |
| 2253 | if(dataRead != sizeof(data)) |
Piotr Caban | 38b0573 | 2008-09-08 15:07:46 +0200 | [diff] [blame] | 2254 | { |
Nikolay Sivov | 809959d | 2011-09-21 13:48:17 +0400 | [diff] [blame] | 2255 | ret = xmlParseChunk(locator->pParserCtxt, data, 0, 1); |
Piotr Caban | 6927a11 | 2011-10-24 12:55:13 +0200 | [diff] [blame] | 2256 | hr = ret!=XML_ERR_OK && locator->ret==S_OK ? E_FAIL : locator->ret; |
Nikolay Sivov | 809959d | 2011-09-21 13:48:17 +0400 | [diff] [blame] | 2257 | } |
| 2258 | else |
| 2259 | { |
| 2260 | while(1) |
Piotr Caban | 38b0573 | 2008-09-08 15:07:46 +0200 | [diff] [blame] | 2261 | { |
Nikolay Sivov | 809959d | 2011-09-21 13:48:17 +0400 | [diff] [blame] | 2262 | dataRead = 0; |
| 2263 | hr = IStream_Read(stream, data, sizeof(data), &dataRead); |
| 2264 | if (FAILED(hr)) break; |
Piotr Caban | 38b0573 | 2008-09-08 15:07:46 +0200 | [diff] [blame] | 2265 | |
Nikolay Sivov | 809959d | 2011-09-21 13:48:17 +0400 | [diff] [blame] | 2266 | ret = xmlParseChunk(locator->pParserCtxt, data, dataRead, 0); |
Piotr Caban | 6927a11 | 2011-10-24 12:55:13 +0200 | [diff] [blame] | 2267 | hr = ret!=XML_ERR_OK && locator->ret==S_OK ? E_FAIL : locator->ret; |
Nikolay Sivov | 809959d | 2011-09-21 13:48:17 +0400 | [diff] [blame] | 2268 | |
| 2269 | if (hr != S_OK) break; |
| 2270 | |
| 2271 | if (dataRead != sizeof(data)) |
| 2272 | { |
| 2273 | ret = xmlParseChunk(locator->pParserCtxt, data, 0, 1); |
Piotr Caban | 6927a11 | 2011-10-24 12:55:13 +0200 | [diff] [blame] | 2274 | hr = ret!=XML_ERR_OK && locator->ret==S_OK ? E_FAIL : locator->ret; |
Nikolay Sivov | 809959d | 2011-09-21 13:48:17 +0400 | [diff] [blame] | 2275 | break; |
| 2276 | } |
Piotr Caban | 38b0573 | 2008-09-08 15:07:46 +0200 | [diff] [blame] | 2277 | } |
| 2278 | } |
Nikolay Sivov | 809959d | 2011-09-21 13:48:17 +0400 | [diff] [blame] | 2279 | |
Piotr Caban | c7fc926 | 2008-10-01 19:52:36 +0200 | [diff] [blame] | 2280 | This->isParsing = FALSE; |
Piotr Caban | 38b0573 | 2008-09-08 15:07:46 +0200 | [diff] [blame] | 2281 | |
Piotr Caban | 38b0573 | 2008-09-08 15:07:46 +0200 | [diff] [blame] | 2282 | xmlFreeParserCtxt(locator->pParserCtxt); |
| 2283 | locator->pParserCtxt = NULL; |
Michael Stefaniuc | 13e1997 | 2010-12-27 23:12:06 +0100 | [diff] [blame] | 2284 | ISAXLocator_Release(&locator->ISAXLocator_iface); |
Piotr Caban | 38b0573 | 2008-09-08 15:07:46 +0200 | [diff] [blame] | 2285 | return hr; |
| 2286 | } |
| 2287 | |
Francois Gouget | 848b509 | 2008-11-24 17:23:59 +0100 | [diff] [blame] | 2288 | static HRESULT internal_getEntityResolver( |
Piotr Caban | cb6bcd0 | 2008-07-31 16:48:20 +0200 | [diff] [blame] | 2289 | saxreader *This, |
| 2290 | void *pEntityResolver, |
| 2291 | BOOL vbInterface) |
| 2292 | { |
| 2293 | FIXME("(%p)->(%p) stub\n", This, pEntityResolver); |
| 2294 | return E_NOTIMPL; |
| 2295 | } |
| 2296 | |
Francois Gouget | 848b509 | 2008-11-24 17:23:59 +0100 | [diff] [blame] | 2297 | static HRESULT internal_putEntityResolver( |
Piotr Caban | cb6bcd0 | 2008-07-31 16:48:20 +0200 | [diff] [blame] | 2298 | saxreader *This, |
| 2299 | void *pEntityResolver, |
| 2300 | BOOL vbInterface) |
| 2301 | { |
| 2302 | FIXME("(%p)->(%p) stub\n", This, pEntityResolver); |
| 2303 | return E_NOTIMPL; |
| 2304 | } |
| 2305 | |
Francois Gouget | 848b509 | 2008-11-24 17:23:59 +0100 | [diff] [blame] | 2306 | static HRESULT internal_getContentHandler( |
Piotr Caban | cb6bcd0 | 2008-07-31 16:48:20 +0200 | [diff] [blame] | 2307 | saxreader* This, |
| 2308 | void *pContentHandler, |
| 2309 | BOOL vbInterface) |
| 2310 | { |
| 2311 | TRACE("(%p)->(%p)\n", This, pContentHandler); |
| 2312 | if(pContentHandler == NULL) |
| 2313 | return E_POINTER; |
Piotr Caban | f3ab228 | 2008-08-20 18:26:25 +0200 | [diff] [blame] | 2314 | if((vbInterface && This->vbcontentHandler) |
| 2315 | || (!vbInterface && This->contentHandler)) |
Piotr Caban | cb6bcd0 | 2008-07-31 16:48:20 +0200 | [diff] [blame] | 2316 | { |
| 2317 | if(vbInterface) |
| 2318 | IVBSAXContentHandler_AddRef(This->vbcontentHandler); |
| 2319 | else |
| 2320 | ISAXContentHandler_AddRef(This->contentHandler); |
| 2321 | } |
| 2322 | if(vbInterface) *(IVBSAXContentHandler**)pContentHandler = |
| 2323 | This->vbcontentHandler; |
| 2324 | else *(ISAXContentHandler**)pContentHandler = This->contentHandler; |
| 2325 | |
| 2326 | return S_OK; |
| 2327 | } |
| 2328 | |
Francois Gouget | 848b509 | 2008-11-24 17:23:59 +0100 | [diff] [blame] | 2329 | static HRESULT internal_putContentHandler( |
Piotr Caban | cb6bcd0 | 2008-07-31 16:48:20 +0200 | [diff] [blame] | 2330 | saxreader* This, |
| 2331 | void *contentHandler, |
| 2332 | BOOL vbInterface) |
| 2333 | { |
| 2334 | TRACE("(%p)->(%p)\n", This, contentHandler); |
| 2335 | if(contentHandler) |
| 2336 | { |
| 2337 | if(vbInterface) |
| 2338 | IVBSAXContentHandler_AddRef((IVBSAXContentHandler*)contentHandler); |
| 2339 | else |
| 2340 | ISAXContentHandler_AddRef((ISAXContentHandler*)contentHandler); |
| 2341 | } |
Piotr Caban | f3ab228 | 2008-08-20 18:26:25 +0200 | [diff] [blame] | 2342 | if((vbInterface && This->vbcontentHandler) |
| 2343 | || (!vbInterface && This->contentHandler)) |
Piotr Caban | cb6bcd0 | 2008-07-31 16:48:20 +0200 | [diff] [blame] | 2344 | { |
| 2345 | if(vbInterface) |
| 2346 | IVBSAXContentHandler_Release(This->vbcontentHandler); |
| 2347 | else |
| 2348 | ISAXContentHandler_Release(This->contentHandler); |
| 2349 | } |
| 2350 | if(vbInterface) |
| 2351 | This->vbcontentHandler = contentHandler; |
| 2352 | else |
| 2353 | This->contentHandler = contentHandler; |
| 2354 | |
| 2355 | return S_OK; |
| 2356 | } |
| 2357 | |
Francois Gouget | 848b509 | 2008-11-24 17:23:59 +0100 | [diff] [blame] | 2358 | static HRESULT internal_getDTDHandler( |
Piotr Caban | cb6bcd0 | 2008-07-31 16:48:20 +0200 | [diff] [blame] | 2359 | saxreader* This, |
| 2360 | void *pDTDHandler, |
| 2361 | BOOL vbInterface) |
| 2362 | { |
| 2363 | FIXME("(%p)->(%p) stub\n", This, pDTDHandler); |
| 2364 | return E_NOTIMPL; |
| 2365 | } |
| 2366 | |
Francois Gouget | 848b509 | 2008-11-24 17:23:59 +0100 | [diff] [blame] | 2367 | static HRESULT internal_putDTDHandler( |
Piotr Caban | cb6bcd0 | 2008-07-31 16:48:20 +0200 | [diff] [blame] | 2368 | saxreader* This, |
| 2369 | void *pDTDHandler, |
| 2370 | BOOL vbInterface) |
| 2371 | { |
| 2372 | FIXME("(%p)->(%p) stub\n", This, pDTDHandler); |
| 2373 | return E_NOTIMPL; |
| 2374 | } |
| 2375 | |
Francois Gouget | 848b509 | 2008-11-24 17:23:59 +0100 | [diff] [blame] | 2376 | static HRESULT internal_getErrorHandler( |
Piotr Caban | cb6bcd0 | 2008-07-31 16:48:20 +0200 | [diff] [blame] | 2377 | saxreader* This, |
| 2378 | void *pErrorHandler, |
| 2379 | BOOL vbInterface) |
| 2380 | { |
| 2381 | TRACE("(%p)->(%p)\n", This, pErrorHandler); |
| 2382 | if(pErrorHandler == NULL) |
| 2383 | return E_POINTER; |
Piotr Caban | 7b7a187 | 2008-08-20 18:32:23 +0200 | [diff] [blame] | 2384 | |
| 2385 | if(vbInterface && This->vberrorHandler) |
| 2386 | IVBSAXErrorHandler_AddRef(This->vberrorHandler); |
| 2387 | else if(!vbInterface && This->errorHandler) |
| 2388 | ISAXErrorHandler_AddRef(This->errorHandler); |
| 2389 | |
Piotr Caban | cb6bcd0 | 2008-07-31 16:48:20 +0200 | [diff] [blame] | 2390 | if(vbInterface) |
| 2391 | *(IVBSAXErrorHandler**)pErrorHandler = This->vberrorHandler; |
| 2392 | else |
| 2393 | *(ISAXErrorHandler**)pErrorHandler = This->errorHandler; |
| 2394 | |
| 2395 | return S_OK; |
| 2396 | |
| 2397 | } |
| 2398 | |
Francois Gouget | 848b509 | 2008-11-24 17:23:59 +0100 | [diff] [blame] | 2399 | static HRESULT internal_putErrorHandler( |
Piotr Caban | cb6bcd0 | 2008-07-31 16:48:20 +0200 | [diff] [blame] | 2400 | saxreader* This, |
| 2401 | void *errorHandler, |
| 2402 | BOOL vbInterface) |
| 2403 | { |
| 2404 | TRACE("(%p)->(%p)\n", This, errorHandler); |
| 2405 | if(errorHandler) |
| 2406 | { |
| 2407 | if(vbInterface) |
| 2408 | IVBSAXErrorHandler_AddRef((IVBSAXErrorHandler*)errorHandler); |
| 2409 | else |
| 2410 | ISAXErrorHandler_AddRef((ISAXErrorHandler*)errorHandler); |
| 2411 | } |
Piotr Caban | 7b7a187 | 2008-08-20 18:32:23 +0200 | [diff] [blame] | 2412 | |
| 2413 | if(vbInterface && This->vberrorHandler) |
| 2414 | IVBSAXErrorHandler_Release(This->vberrorHandler); |
| 2415 | else if(!vbInterface && This->errorHandler) |
| 2416 | ISAXErrorHandler_Release(This->errorHandler); |
| 2417 | |
Piotr Caban | cb6bcd0 | 2008-07-31 16:48:20 +0200 | [diff] [blame] | 2418 | if(vbInterface) |
| 2419 | This->vberrorHandler = errorHandler; |
| 2420 | else |
| 2421 | This->errorHandler = errorHandler; |
| 2422 | |
| 2423 | return S_OK; |
| 2424 | |
| 2425 | } |
| 2426 | |
Francois Gouget | 848b509 | 2008-11-24 17:23:59 +0100 | [diff] [blame] | 2427 | static HRESULT internal_parse( |
Piotr Caban | cb6bcd0 | 2008-07-31 16:48:20 +0200 | [diff] [blame] | 2428 | saxreader* This, |
| 2429 | VARIANT varInput, |
| 2430 | BOOL vbInterface) |
| 2431 | { |
| 2432 | HRESULT hr; |
| 2433 | |
Nikolay Sivov | a0a464a | 2011-02-22 02:04:02 +0300 | [diff] [blame] | 2434 | TRACE("(%p)->(%s)\n", This, debugstr_variant(&varInput)); |
Piotr Caban | cb6bcd0 | 2008-07-31 16:48:20 +0200 | [diff] [blame] | 2435 | |
Andrew Nguyen | 9c5d5d8 | 2011-07-15 07:38:07 -0500 | [diff] [blame] | 2436 | /* Dispose of the BSTRs in the pool from a prior run, if any. */ |
| 2437 | free_bstr_pool(&This->pool); |
| 2438 | |
Piotr Caban | cb6bcd0 | 2008-07-31 16:48:20 +0200 | [diff] [blame] | 2439 | switch(V_VT(&varInput)) |
| 2440 | { |
| 2441 | case VT_BSTR: |
| 2442 | hr = internal_parseBuffer(This, (const char*)V_BSTR(&varInput), |
| 2443 | SysStringByteLen(V_BSTR(&varInput)), vbInterface); |
| 2444 | break; |
| 2445 | case VT_ARRAY|VT_UI1: { |
| 2446 | void *pSAData; |
| 2447 | LONG lBound, uBound; |
| 2448 | ULONG dataRead; |
| 2449 | |
| 2450 | hr = SafeArrayGetLBound(V_ARRAY(&varInput), 1, &lBound); |
| 2451 | if(hr != S_OK) break; |
| 2452 | hr = SafeArrayGetUBound(V_ARRAY(&varInput), 1, &uBound); |
| 2453 | if(hr != S_OK) break; |
| 2454 | dataRead = (uBound-lBound)*SafeArrayGetElemsize(V_ARRAY(&varInput)); |
Michael Stefaniuc | 6a5dda7 | 2009-01-26 11:01:02 +0100 | [diff] [blame] | 2455 | hr = SafeArrayAccessData(V_ARRAY(&varInput), &pSAData); |
Piotr Caban | cb6bcd0 | 2008-07-31 16:48:20 +0200 | [diff] [blame] | 2456 | if(hr != S_OK) break; |
| 2457 | hr = internal_parseBuffer(This, pSAData, dataRead, vbInterface); |
| 2458 | SafeArrayUnaccessData(V_ARRAY(&varInput)); |
| 2459 | break; |
| 2460 | } |
| 2461 | case VT_UNKNOWN: |
| 2462 | case VT_DISPATCH: { |
| 2463 | IPersistStream *persistStream; |
| 2464 | IStream *stream = NULL; |
| 2465 | IXMLDOMDocument *xmlDoc; |
| 2466 | |
| 2467 | if(IUnknown_QueryInterface(V_UNKNOWN(&varInput), |
Piotr Caban | a28b604 | 2008-09-19 16:01:03 +0200 | [diff] [blame] | 2468 | &IID_IXMLDOMDocument, (void**)&xmlDoc) == S_OK) |
| 2469 | { |
| 2470 | BSTR bstrData; |
| 2471 | |
| 2472 | IXMLDOMDocument_get_xml(xmlDoc, &bstrData); |
| 2473 | hr = internal_parseBuffer(This, (const char*)bstrData, |
| 2474 | SysStringByteLen(bstrData), vbInterface); |
| 2475 | IXMLDOMDocument_Release(xmlDoc); |
Nikolay Sivov | 73a955e | 2010-01-10 18:46:30 +0300 | [diff] [blame] | 2476 | SysFreeString(bstrData); |
Piotr Caban | a28b604 | 2008-09-19 16:01:03 +0200 | [diff] [blame] | 2477 | break; |
| 2478 | } |
Nikolay Sivov | 850be4d | 2010-10-28 01:27:06 +0400 | [diff] [blame] | 2479 | |
Piotr Caban | a28b604 | 2008-09-19 16:01:03 +0200 | [diff] [blame] | 2480 | if(IUnknown_QueryInterface(V_UNKNOWN(&varInput), |
Piotr Caban | cb6bcd0 | 2008-07-31 16:48:20 +0200 | [diff] [blame] | 2481 | &IID_IPersistStream, (void**)&persistStream) == S_OK) |
| 2482 | { |
Nikolay Sivov | 850be4d | 2010-10-28 01:27:06 +0400 | [diff] [blame] | 2483 | hr = CreateStreamOnHGlobal(NULL, TRUE, &stream); |
| 2484 | if(hr != S_OK) |
| 2485 | { |
| 2486 | IPersistStream_Release(persistStream); |
| 2487 | return hr; |
| 2488 | } |
| 2489 | |
Piotr Caban | cb6bcd0 | 2008-07-31 16:48:20 +0200 | [diff] [blame] | 2490 | hr = IPersistStream_Save(persistStream, stream, TRUE); |
| 2491 | IPersistStream_Release(persistStream); |
Nikolay Sivov | 850be4d | 2010-10-28 01:27:06 +0400 | [diff] [blame] | 2492 | if(hr != S_OK) |
| 2493 | { |
| 2494 | IStream_Release(stream); |
Nikolay Sivov | 012806a | 2012-01-23 10:31:55 +0300 | [diff] [blame] | 2495 | stream = NULL; |
Nikolay Sivov | 850be4d | 2010-10-28 01:27:06 +0400 | [diff] [blame] | 2496 | } |
Piotr Caban | cb6bcd0 | 2008-07-31 16:48:20 +0200 | [diff] [blame] | 2497 | } |
Nikolay Sivov | 012806a | 2012-01-23 10:31:55 +0300 | [diff] [blame] | 2498 | |
Piotr Caban | cb6bcd0 | 2008-07-31 16:48:20 +0200 | [diff] [blame] | 2499 | if(stream || IUnknown_QueryInterface(V_UNKNOWN(&varInput), |
| 2500 | &IID_IStream, (void**)&stream) == S_OK) |
| 2501 | { |
Piotr Caban | 38b0573 | 2008-09-08 15:07:46 +0200 | [diff] [blame] | 2502 | hr = internal_parseStream(This, stream, vbInterface); |
Piotr Caban | cb6bcd0 | 2008-07-31 16:48:20 +0200 | [diff] [blame] | 2503 | IStream_Release(stream); |
| 2504 | break; |
| 2505 | } |
Piotr Caban | cb6bcd0 | 2008-07-31 16:48:20 +0200 | [diff] [blame] | 2506 | } |
| 2507 | default: |
| 2508 | WARN("vt %d not implemented\n", V_VT(&varInput)); |
| 2509 | hr = E_INVALIDARG; |
| 2510 | } |
| 2511 | |
| 2512 | return hr; |
| 2513 | } |
| 2514 | |
| 2515 | static HRESULT internal_vbonDataAvailable(void *obj, char *ptr, DWORD len) |
| 2516 | { |
| 2517 | saxreader *This = obj; |
| 2518 | |
| 2519 | return internal_parseBuffer(This, ptr, len, TRUE); |
| 2520 | } |
| 2521 | |
| 2522 | static HRESULT internal_onDataAvailable(void *obj, char *ptr, DWORD len) |
| 2523 | { |
| 2524 | saxreader *This = obj; |
| 2525 | |
| 2526 | return internal_parseBuffer(This, ptr, len, FALSE); |
| 2527 | } |
| 2528 | |
Francois Gouget | 848b509 | 2008-11-24 17:23:59 +0100 | [diff] [blame] | 2529 | static HRESULT internal_parseURL( |
Piotr Caban | cb6bcd0 | 2008-07-31 16:48:20 +0200 | [diff] [blame] | 2530 | saxreader* This, |
| 2531 | const WCHAR *url, |
| 2532 | BOOL vbInterface) |
| 2533 | { |
Piotr Caban | 2cbd6a6 | 2012-03-12 10:56:59 +0100 | [diff] [blame] | 2534 | IMoniker *mon; |
Piotr Caban | cb6bcd0 | 2008-07-31 16:48:20 +0200 | [diff] [blame] | 2535 | bsc_t *bsc; |
| 2536 | HRESULT hr; |
| 2537 | |
| 2538 | TRACE("(%p)->(%s)\n", This, debugstr_w(url)); |
| 2539 | |
Piotr Caban | 2cbd6a6 | 2012-03-12 10:56:59 +0100 | [diff] [blame] | 2540 | hr = create_moniker_from_url(url, &mon); |
| 2541 | if(FAILED(hr)) |
| 2542 | return hr; |
| 2543 | |
| 2544 | if(vbInterface) hr = bind_url(mon, internal_vbonDataAvailable, This, &bsc); |
| 2545 | else hr = bind_url(mon, internal_onDataAvailable, This, &bsc); |
| 2546 | IMoniker_Release(mon); |
Piotr Caban | cb6bcd0 | 2008-07-31 16:48:20 +0200 | [diff] [blame] | 2547 | |
| 2548 | if(FAILED(hr)) |
| 2549 | return hr; |
| 2550 | |
Piotr Caban | 41eba1c | 2011-10-24 12:55:00 +0200 | [diff] [blame] | 2551 | return detach_bsc(bsc); |
Piotr Caban | cb6bcd0 | 2008-07-31 16:48:20 +0200 | [diff] [blame] | 2552 | } |
| 2553 | |
Francois Gouget | 848b509 | 2008-11-24 17:23:59 +0100 | [diff] [blame] | 2554 | static HRESULT internal_putProperty( |
Piotr Caban | c7fc926 | 2008-10-01 19:52:36 +0200 | [diff] [blame] | 2555 | saxreader* This, |
Nikolay Sivov | 864f170 | 2011-09-21 21:01:10 +0400 | [diff] [blame] | 2556 | const WCHAR *prop, |
Piotr Caban | c7fc926 | 2008-10-01 19:52:36 +0200 | [diff] [blame] | 2557 | VARIANT value, |
| 2558 | BOOL vbInterface) |
| 2559 | { |
Nikolay Sivov | 864f170 | 2011-09-21 21:01:10 +0400 | [diff] [blame] | 2560 | TRACE("(%p)->(%s %s)\n", This, debugstr_w(prop), debugstr_variant(&value)); |
Piotr Caban | c7fc926 | 2008-10-01 19:52:36 +0200 | [diff] [blame] | 2561 | |
Nikolay Sivov | 864f170 | 2011-09-21 21:01:10 +0400 | [diff] [blame] | 2562 | if(!memcmp(prop, PropertyDeclHandlerW, sizeof(PropertyDeclHandlerW))) |
Piotr Caban | c7fc926 | 2008-10-01 19:52:36 +0200 | [diff] [blame] | 2563 | { |
| 2564 | if(This->isParsing) return E_FAIL; |
| 2565 | |
Nikolay Sivov | 7db7d85 | 2011-09-22 10:50:41 +0400 | [diff] [blame] | 2566 | switch (V_VT(&value)) |
Piotr Caban | c7fc926 | 2008-10-01 19:52:36 +0200 | [diff] [blame] | 2567 | { |
Nikolay Sivov | 7db7d85 | 2011-09-22 10:50:41 +0400 | [diff] [blame] | 2568 | case VT_EMPTY: |
| 2569 | if (vbInterface) |
| 2570 | { |
| 2571 | if (This->vbdeclHandler) |
| 2572 | { |
| 2573 | IVBSAXDeclHandler_Release(This->vbdeclHandler); |
| 2574 | This->vbdeclHandler = NULL; |
| 2575 | } |
| 2576 | } |
Piotr Caban | c7fc926 | 2008-10-01 19:52:36 +0200 | [diff] [blame] | 2577 | else |
Nikolay Sivov | 7db7d85 | 2011-09-22 10:50:41 +0400 | [diff] [blame] | 2578 | if (This->declHandler) |
| 2579 | { |
| 2580 | ISAXDeclHandler_Release(This->declHandler); |
| 2581 | This->declHandler = NULL; |
| 2582 | } |
| 2583 | break; |
| 2584 | case VT_UNKNOWN: |
Nikolay Sivov | 7db7d85 | 2011-09-22 10:50:41 +0400 | [diff] [blame] | 2585 | if ((vbInterface && This->vbdeclHandler) || |
| 2586 | (!vbInterface && This->declHandler)) |
| 2587 | { |
| 2588 | if (vbInterface) |
| 2589 | IVBSAXDeclHandler_Release(This->vbdeclHandler); |
| 2590 | else |
| 2591 | ISAXDeclHandler_Release(This->declHandler); |
| 2592 | } |
| 2593 | |
Nikolay Sivov | 28335fb | 2012-04-26 23:54:22 +0400 | [diff] [blame] | 2594 | if (V_UNKNOWN(&value)) |
| 2595 | { |
| 2596 | return vbInterface ? |
| 2597 | IVBSAXDeclHandler_QueryInterface(V_UNKNOWN(&value), &IID_IVBSAXDeclHandler, (void**)&This->vbdeclHandler) : |
| 2598 | ISAXDeclHandler_QueryInterface(V_UNKNOWN(&value), &IID_ISAXDeclHandler, (void**)&This->declHandler); |
| 2599 | } |
Piotr Caban | c7fc926 | 2008-10-01 19:52:36 +0200 | [diff] [blame] | 2600 | else |
Nikolay Sivov | 28335fb | 2012-04-26 23:54:22 +0400 | [diff] [blame] | 2601 | { |
| 2602 | This->vbdeclHandler = NULL; |
| 2603 | This->declHandler = NULL; |
| 2604 | } |
Nikolay Sivov | 7db7d85 | 2011-09-22 10:50:41 +0400 | [diff] [blame] | 2605 | break; |
| 2606 | default: |
| 2607 | return E_INVALIDARG; |
Piotr Caban | c7fc926 | 2008-10-01 19:52:36 +0200 | [diff] [blame] | 2608 | } |
Nikolay Sivov | 7db7d85 | 2011-09-22 10:50:41 +0400 | [diff] [blame] | 2609 | |
Piotr Caban | c7fc926 | 2008-10-01 19:52:36 +0200 | [diff] [blame] | 2610 | return S_OK; |
| 2611 | } |
| 2612 | |
Nikolay Sivov | 864f170 | 2011-09-21 21:01:10 +0400 | [diff] [blame] | 2613 | if(!memcmp(prop, PropertyLexicalHandlerW, sizeof(PropertyLexicalHandlerW))) |
Piotr Caban | c7fc926 | 2008-10-01 19:52:36 +0200 | [diff] [blame] | 2614 | { |
| 2615 | if(This->isParsing) return E_FAIL; |
| 2616 | |
Nikolay Sivov | 864f170 | 2011-09-21 21:01:10 +0400 | [diff] [blame] | 2617 | switch (V_VT(&value)) |
Piotr Caban | c7fc926 | 2008-10-01 19:52:36 +0200 | [diff] [blame] | 2618 | { |
Nikolay Sivov | 864f170 | 2011-09-21 21:01:10 +0400 | [diff] [blame] | 2619 | case VT_EMPTY: |
| 2620 | if (vbInterface) |
| 2621 | { |
| 2622 | if (This->vblexicalHandler) |
| 2623 | { |
| 2624 | IVBSAXLexicalHandler_Release(This->vblexicalHandler); |
| 2625 | This->vblexicalHandler = NULL; |
| 2626 | } |
| 2627 | } |
Piotr Caban | c7fc926 | 2008-10-01 19:52:36 +0200 | [diff] [blame] | 2628 | else |
Nikolay Sivov | 864f170 | 2011-09-21 21:01:10 +0400 | [diff] [blame] | 2629 | if (This->lexicalHandler) |
| 2630 | { |
| 2631 | ISAXLexicalHandler_Release(This->lexicalHandler); |
| 2632 | This->lexicalHandler = NULL; |
| 2633 | } |
| 2634 | break; |
| 2635 | case VT_UNKNOWN: |
Nikolay Sivov | 864f170 | 2011-09-21 21:01:10 +0400 | [diff] [blame] | 2636 | if ((vbInterface && This->vblexicalHandler) || |
| 2637 | (!vbInterface && This->lexicalHandler)) |
| 2638 | { |
| 2639 | if (vbInterface) |
| 2640 | IVBSAXLexicalHandler_Release(This->vblexicalHandler); |
| 2641 | else |
| 2642 | ISAXLexicalHandler_Release(This->lexicalHandler); |
| 2643 | } |
| 2644 | |
Nikolay Sivov | 28335fb | 2012-04-26 23:54:22 +0400 | [diff] [blame] | 2645 | if (V_UNKNOWN(&value)) |
| 2646 | { |
| 2647 | return vbInterface ? |
| 2648 | IVBSAXLexicalHandler_QueryInterface(V_UNKNOWN(&value), &IID_IVBSAXLexicalHandler, (void**)&This->vblexicalHandler) : |
| 2649 | ISAXLexicalHandler_QueryInterface(V_UNKNOWN(&value), &IID_ISAXLexicalHandler, (void**)&This->lexicalHandler); |
| 2650 | } |
Piotr Caban | c7fc926 | 2008-10-01 19:52:36 +0200 | [diff] [blame] | 2651 | else |
Nikolay Sivov | 28335fb | 2012-04-26 23:54:22 +0400 | [diff] [blame] | 2652 | { |
| 2653 | This->vblexicalHandler = NULL; |
| 2654 | This->lexicalHandler = NULL; |
| 2655 | } |
| 2656 | |
Nikolay Sivov | 864f170 | 2011-09-21 21:01:10 +0400 | [diff] [blame] | 2657 | break; |
| 2658 | default: |
| 2659 | return E_INVALIDARG; |
Piotr Caban | c7fc926 | 2008-10-01 19:52:36 +0200 | [diff] [blame] | 2660 | } |
Nikolay Sivov | 864f170 | 2011-09-21 21:01:10 +0400 | [diff] [blame] | 2661 | |
Piotr Caban | c7fc926 | 2008-10-01 19:52:36 +0200 | [diff] [blame] | 2662 | return S_OK; |
| 2663 | } |
| 2664 | |
Nikolay Sivov | 393c232 | 2011-10-05 11:19:43 -0500 | [diff] [blame] | 2665 | if(!memcmp(prop, PropertyMaxXMLSizeW, sizeof(PropertyMaxXMLSizeW))) |
| 2666 | { |
| 2667 | if (V_VT(&value) == VT_I4 && V_I4(&value) == 0) return S_OK; |
| 2668 | FIXME("(%p)->(%s): max-xml-size unsupported\n", This, debugstr_variant(&value)); |
| 2669 | return E_NOTIMPL; |
| 2670 | } |
| 2671 | |
Nikolay Sivov | 5f68f37 | 2011-10-05 11:23:56 -0500 | [diff] [blame] | 2672 | if(!memcmp(prop, PropertyMaxElementDepthW, sizeof(PropertyMaxElementDepthW))) |
| 2673 | { |
| 2674 | if (V_VT(&value) == VT_I4 && V_I4(&value) == 0) return S_OK; |
| 2675 | FIXME("(%p)->(%s): max-element-depth unsupported\n", This, debugstr_variant(&value)); |
| 2676 | return E_NOTIMPL; |
| 2677 | } |
| 2678 | |
Nikolay Sivov | 393c232 | 2011-10-05 11:19:43 -0500 | [diff] [blame] | 2679 | FIXME("(%p)->(%s:%s): unsupported property\n", This, debugstr_w(prop), debugstr_variant(&value)); |
Nikolay Sivov | fd35084 | 2010-08-30 01:33:28 +0400 | [diff] [blame] | 2680 | |
Nikolay Sivov | 864f170 | 2011-09-21 21:01:10 +0400 | [diff] [blame] | 2681 | if(!memcmp(prop, PropertyCharsetW, sizeof(PropertyCharsetW))) |
Nikolay Sivov | fd35084 | 2010-08-30 01:33:28 +0400 | [diff] [blame] | 2682 | return E_NOTIMPL; |
| 2683 | |
Nikolay Sivov | 864f170 | 2011-09-21 21:01:10 +0400 | [diff] [blame] | 2684 | if(!memcmp(prop, PropertyDomNodeW, sizeof(PropertyDomNodeW))) |
Nikolay Sivov | fd35084 | 2010-08-30 01:33:28 +0400 | [diff] [blame] | 2685 | return E_FAIL; |
| 2686 | |
Nikolay Sivov | 864f170 | 2011-09-21 21:01:10 +0400 | [diff] [blame] | 2687 | if(!memcmp(prop, PropertyInputSourceW, sizeof(PropertyInputSourceW))) |
Nikolay Sivov | fd35084 | 2010-08-30 01:33:28 +0400 | [diff] [blame] | 2688 | return E_NOTIMPL; |
| 2689 | |
Nikolay Sivov | 864f170 | 2011-09-21 21:01:10 +0400 | [diff] [blame] | 2690 | if(!memcmp(prop, PropertySchemaDeclHandlerW, sizeof(PropertySchemaDeclHandlerW))) |
Piotr Caban | c7fc926 | 2008-10-01 19:52:36 +0200 | [diff] [blame] | 2691 | return E_NOTIMPL; |
| 2692 | |
Nikolay Sivov | 864f170 | 2011-09-21 21:01:10 +0400 | [diff] [blame] | 2693 | if(!memcmp(prop, PropertyXMLDeclEncodingW, sizeof(PropertyXMLDeclEncodingW))) |
Piotr Caban | c7fc926 | 2008-10-01 19:52:36 +0200 | [diff] [blame] | 2694 | return E_FAIL; |
| 2695 | |
Nikolay Sivov | 864f170 | 2011-09-21 21:01:10 +0400 | [diff] [blame] | 2696 | if(!memcmp(prop, PropertyXMLDeclStandaloneW, sizeof(PropertyXMLDeclStandaloneW))) |
Piotr Caban | c7fc926 | 2008-10-01 19:52:36 +0200 | [diff] [blame] | 2697 | return E_FAIL; |
| 2698 | |
Nikolay Sivov | 864f170 | 2011-09-21 21:01:10 +0400 | [diff] [blame] | 2699 | if(!memcmp(prop, PropertyXMLDeclVersionW, sizeof(PropertyXMLDeclVersionW))) |
Piotr Caban | c7fc926 | 2008-10-01 19:52:36 +0200 | [diff] [blame] | 2700 | return E_FAIL; |
| 2701 | |
| 2702 | return E_INVALIDARG; |
| 2703 | } |
| 2704 | |
Nikolay Sivov | 864f170 | 2011-09-21 21:01:10 +0400 | [diff] [blame] | 2705 | static HRESULT internal_getProperty(const saxreader* This, const WCHAR *prop, VARIANT *value, BOOL vb) |
| 2706 | { |
| 2707 | TRACE("(%p)->(%s)\n", This, debugstr_w(prop)); |
| 2708 | |
| 2709 | if (!value) return E_POINTER; |
| 2710 | |
| 2711 | if (!memcmp(PropertyLexicalHandlerW, prop, sizeof(PropertyLexicalHandlerW))) |
| 2712 | { |
| 2713 | V_VT(value) = VT_UNKNOWN; |
| 2714 | V_UNKNOWN(value) = vb ? (IUnknown*)This->vblexicalHandler : (IUnknown*)This->lexicalHandler; |
| 2715 | if (V_UNKNOWN(value)) IUnknown_AddRef(V_UNKNOWN(value)); |
| 2716 | return S_OK; |
| 2717 | } |
| 2718 | |
Nikolay Sivov | 7db7d85 | 2011-09-22 10:50:41 +0400 | [diff] [blame] | 2719 | if (!memcmp(PropertyDeclHandlerW, prop, sizeof(PropertyDeclHandlerW))) |
| 2720 | { |
| 2721 | V_VT(value) = VT_UNKNOWN; |
| 2722 | V_UNKNOWN(value) = vb ? (IUnknown*)This->vbdeclHandler : (IUnknown*)This->declHandler; |
| 2723 | if (V_UNKNOWN(value)) IUnknown_AddRef(V_UNKNOWN(value)); |
| 2724 | return S_OK; |
| 2725 | } |
| 2726 | |
Nikolay Sivov | 864f170 | 2011-09-21 21:01:10 +0400 | [diff] [blame] | 2727 | FIXME("(%p)->(%s) unsupported property\n", This, debugstr_w(prop)); |
| 2728 | |
| 2729 | return E_NOTIMPL; |
| 2730 | } |
| 2731 | |
Piotr Caban | 1926760 | 2008-07-08 20:52:04 +0200 | [diff] [blame] | 2732 | /*** IVBSAXXMLReader interface ***/ |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 2733 | /*** IUnknown methods ***/ |
| 2734 | static HRESULT WINAPI saxxmlreader_QueryInterface(IVBSAXXMLReader* iface, REFIID riid, void **ppvObject) |
| 2735 | { |
| 2736 | saxreader *This = impl_from_IVBSAXXMLReader( iface ); |
| 2737 | |
| 2738 | TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject ); |
| 2739 | |
| 2740 | *ppvObject = NULL; |
| 2741 | |
| 2742 | if ( IsEqualGUID( riid, &IID_IUnknown ) || |
| 2743 | IsEqualGUID( riid, &IID_IDispatch ) || |
| 2744 | IsEqualGUID( riid, &IID_IVBSAXXMLReader )) |
| 2745 | { |
| 2746 | *ppvObject = iface; |
| 2747 | } |
Piotr Caban | 1926760 | 2008-07-08 20:52:04 +0200 | [diff] [blame] | 2748 | else if( IsEqualGUID( riid, &IID_ISAXXMLReader )) |
| 2749 | { |
Michael Stefaniuc | 13e1997 | 2010-12-27 23:12:06 +0100 | [diff] [blame] | 2750 | *ppvObject = &This->ISAXXMLReader_iface; |
Piotr Caban | 1926760 | 2008-07-08 20:52:04 +0200 | [diff] [blame] | 2751 | } |
Nikolay Sivov | 0ba0f4c | 2011-11-21 12:23:25 +0300 | [diff] [blame] | 2752 | else if (dispex_query_interface(&This->dispex, riid, ppvObject)) |
| 2753 | { |
| 2754 | return *ppvObject ? S_OK : E_NOINTERFACE; |
| 2755 | } |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 2756 | else |
| 2757 | { |
| 2758 | FIXME("interface %s not implemented\n", debugstr_guid(riid)); |
| 2759 | return E_NOINTERFACE; |
| 2760 | } |
| 2761 | |
| 2762 | IVBSAXXMLReader_AddRef( iface ); |
| 2763 | |
| 2764 | return S_OK; |
| 2765 | } |
| 2766 | |
| 2767 | static ULONG WINAPI saxxmlreader_AddRef(IVBSAXXMLReader* iface) |
| 2768 | { |
| 2769 | saxreader *This = impl_from_IVBSAXXMLReader( iface ); |
| 2770 | TRACE("%p\n", This ); |
| 2771 | return InterlockedIncrement( &This->ref ); |
| 2772 | } |
| 2773 | |
| 2774 | static ULONG WINAPI saxxmlreader_Release( |
| 2775 | IVBSAXXMLReader* iface) |
| 2776 | { |
| 2777 | saxreader *This = impl_from_IVBSAXXMLReader( iface ); |
| 2778 | LONG ref; |
| 2779 | |
| 2780 | TRACE("%p\n", This ); |
| 2781 | |
| 2782 | ref = InterlockedDecrement( &This->ref ); |
| 2783 | if ( ref == 0 ) |
| 2784 | { |
Piotr Caban | 3fa75f4 | 2008-07-08 21:00:20 +0200 | [diff] [blame] | 2785 | if(This->contentHandler) |
| 2786 | ISAXContentHandler_Release(This->contentHandler); |
| 2787 | |
Piotr Caban | 7b7a187 | 2008-08-20 18:32:23 +0200 | [diff] [blame] | 2788 | if(This->vbcontentHandler) |
| 2789 | IVBSAXContentHandler_Release(This->vbcontentHandler); |
| 2790 | |
Piotr Caban | be89ee1 | 2008-07-08 20:52:41 +0200 | [diff] [blame] | 2791 | if(This->errorHandler) |
| 2792 | ISAXErrorHandler_Release(This->errorHandler); |
| 2793 | |
Piotr Caban | 7b7a187 | 2008-08-20 18:32:23 +0200 | [diff] [blame] | 2794 | if(This->vberrorHandler) |
| 2795 | IVBSAXErrorHandler_Release(This->vberrorHandler); |
| 2796 | |
Piotr Caban | c7fc926 | 2008-10-01 19:52:36 +0200 | [diff] [blame] | 2797 | if(This->lexicalHandler) |
| 2798 | ISAXLexicalHandler_Release(This->lexicalHandler); |
| 2799 | |
| 2800 | if(This->vblexicalHandler) |
| 2801 | IVBSAXLexicalHandler_Release(This->vblexicalHandler); |
| 2802 | |
| 2803 | if(This->declHandler) |
| 2804 | ISAXDeclHandler_Release(This->declHandler); |
| 2805 | |
| 2806 | if(This->vbdeclHandler) |
| 2807 | IVBSAXDeclHandler_Release(This->vbdeclHandler); |
| 2808 | |
Andrew Nguyen | 9c5d5d8 | 2011-07-15 07:38:07 -0500 | [diff] [blame] | 2809 | free_bstr_pool(&This->pool); |
| 2810 | |
Nikolay Sivov | 0ba0f4c | 2011-11-21 12:23:25 +0300 | [diff] [blame] | 2811 | release_dispex(&This->dispex); |
Nikolay Sivov | d8a9a69 | 2010-02-03 22:47:53 +0300 | [diff] [blame] | 2812 | heap_free( This ); |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 2813 | } |
| 2814 | |
| 2815 | return ref; |
| 2816 | } |
| 2817 | /*** IDispatch ***/ |
| 2818 | static HRESULT WINAPI saxxmlreader_GetTypeInfoCount( IVBSAXXMLReader *iface, UINT* pctinfo ) |
| 2819 | { |
| 2820 | saxreader *This = impl_from_IVBSAXXMLReader( iface ); |
Nikolay Sivov | 0ba0f4c | 2011-11-21 12:23:25 +0300 | [diff] [blame] | 2821 | return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo); |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 2822 | } |
| 2823 | |
| 2824 | static HRESULT WINAPI saxxmlreader_GetTypeInfo( |
| 2825 | IVBSAXXMLReader *iface, |
| 2826 | UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo ) |
| 2827 | { |
| 2828 | saxreader *This = impl_from_IVBSAXXMLReader( iface ); |
Nikolay Sivov | 0ba0f4c | 2011-11-21 12:23:25 +0300 | [diff] [blame] | 2829 | return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, |
| 2830 | iTInfo, lcid, ppTInfo); |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 2831 | } |
| 2832 | |
| 2833 | static HRESULT WINAPI saxxmlreader_GetIDsOfNames( |
| 2834 | IVBSAXXMLReader *iface, |
| 2835 | REFIID riid, |
| 2836 | LPOLESTR* rgszNames, |
| 2837 | UINT cNames, |
| 2838 | LCID lcid, |
| 2839 | DISPID* rgDispId) |
| 2840 | { |
| 2841 | saxreader *This = impl_from_IVBSAXXMLReader( iface ); |
Nikolay Sivov | 0ba0f4c | 2011-11-21 12:23:25 +0300 | [diff] [blame] | 2842 | return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, |
| 2843 | riid, rgszNames, cNames, lcid, rgDispId); |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 2844 | } |
| 2845 | |
| 2846 | static HRESULT WINAPI saxxmlreader_Invoke( |
| 2847 | IVBSAXXMLReader *iface, |
| 2848 | DISPID dispIdMember, |
| 2849 | REFIID riid, |
| 2850 | LCID lcid, |
| 2851 | WORD wFlags, |
| 2852 | DISPPARAMS* pDispParams, |
| 2853 | VARIANT* pVarResult, |
| 2854 | EXCEPINFO* pExcepInfo, |
| 2855 | UINT* puArgErr) |
| 2856 | { |
| 2857 | saxreader *This = impl_from_IVBSAXXMLReader( iface ); |
Nikolay Sivov | 0ba0f4c | 2011-11-21 12:23:25 +0300 | [diff] [blame] | 2858 | return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, |
| 2859 | dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr); |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 2860 | } |
| 2861 | |
| 2862 | /*** IVBSAXXMLReader methods ***/ |
| 2863 | static HRESULT WINAPI saxxmlreader_getFeature( |
| 2864 | IVBSAXXMLReader* iface, |
Nikolay Sivov | 137a21d | 2012-04-18 22:39:38 +0400 | [diff] [blame] | 2865 | const WCHAR *feature_name, |
Nikolay Sivov | 3d3786c | 2011-10-05 13:29:37 -0500 | [diff] [blame] | 2866 | VARIANT_BOOL *value) |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 2867 | { |
Piotr Caban | 4fb786a | 2008-04-01 01:45:13 +0200 | [diff] [blame] | 2868 | saxreader *This = impl_from_IVBSAXXMLReader( iface ); |
Nikolay Sivov | 137a21d | 2012-04-18 22:39:38 +0400 | [diff] [blame] | 2869 | saxreader_feature feature; |
Piotr Caban | 4fb786a | 2008-04-01 01:45:13 +0200 | [diff] [blame] | 2870 | |
Nikolay Sivov | 137a21d | 2012-04-18 22:39:38 +0400 | [diff] [blame] | 2871 | TRACE("(%p)->(%s %p)\n", This, debugstr_w(feature_name), value); |
Nikolay Sivov | 3d3786c | 2011-10-05 13:29:37 -0500 | [diff] [blame] | 2872 | |
Nikolay Sivov | 137a21d | 2012-04-18 22:39:38 +0400 | [diff] [blame] | 2873 | feature = get_saxreader_feature(feature_name); |
| 2874 | if (feature == Namespaces || feature == NamespacePrefixes) |
| 2875 | return get_feature_value(This, feature, value); |
Nikolay Sivov | 9a5da56 | 2012-04-17 09:44:44 +0400 | [diff] [blame] | 2876 | |
Nikolay Sivov | 137a21d | 2012-04-18 22:39:38 +0400 | [diff] [blame] | 2877 | FIXME("(%p)->(%s %p) stub\n", This, debugstr_w(feature_name), value); |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 2878 | return E_NOTIMPL; |
| 2879 | } |
| 2880 | |
| 2881 | static HRESULT WINAPI saxxmlreader_putFeature( |
| 2882 | IVBSAXXMLReader* iface, |
Nikolay Sivov | 137a21d | 2012-04-18 22:39:38 +0400 | [diff] [blame] | 2883 | const WCHAR *feature_name, |
Nikolay Sivov | ad336be | 2011-10-04 16:27:39 -0500 | [diff] [blame] | 2884 | VARIANT_BOOL value) |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 2885 | { |
Piotr Caban | 4fb786a | 2008-04-01 01:45:13 +0200 | [diff] [blame] | 2886 | saxreader *This = impl_from_IVBSAXXMLReader( iface ); |
Nikolay Sivov | 137a21d | 2012-04-18 22:39:38 +0400 | [diff] [blame] | 2887 | saxreader_feature feature; |
Piotr Caban | 4fb786a | 2008-04-01 01:45:13 +0200 | [diff] [blame] | 2888 | |
Nikolay Sivov | 137a21d | 2012-04-18 22:39:38 +0400 | [diff] [blame] | 2889 | TRACE("(%p)->(%s %x)\n", This, debugstr_w(feature_name), value); |
Nikolay Sivov | ad336be | 2011-10-04 16:27:39 -0500 | [diff] [blame] | 2890 | |
Nikolay Sivov | 137a21d | 2012-04-18 22:39:38 +0400 | [diff] [blame] | 2891 | feature = get_saxreader_feature(feature_name); |
Nikolay Sivov | ad336be | 2011-10-04 16:27:39 -0500 | [diff] [blame] | 2892 | |
Nikolay Sivov | 137a21d | 2012-04-18 22:39:38 +0400 | [diff] [blame] | 2893 | /* accepted cases */ |
| 2894 | if ((feature == ExternalGeneralEntities && value == VARIANT_FALSE) || |
| 2895 | (feature == ExternalParameterEntities && value == VARIANT_FALSE) || |
Nikolay Sivov | 4fb5872 | 2012-04-20 11:03:18 +0400 | [diff] [blame] | 2896 | feature == Namespaces || |
| 2897 | feature == NamespacePrefixes) |
Nikolay Sivov | cc4c694 | 2011-10-05 09:37:40 -0500 | [diff] [blame] | 2898 | { |
Nikolay Sivov | 137a21d | 2012-04-18 22:39:38 +0400 | [diff] [blame] | 2899 | return set_feature_value(This, feature, value); |
Nikolay Sivov | cc4c694 | 2011-10-05 09:37:40 -0500 | [diff] [blame] | 2900 | } |
| 2901 | |
Nikolay Sivov | 137a21d | 2012-04-18 22:39:38 +0400 | [diff] [blame] | 2902 | if (feature == LexicalHandlerParEntities || feature == ProhibitDTD) |
Nikolay Sivov | 165d1b5 | 2011-10-05 11:09:28 -0500 | [diff] [blame] | 2903 | { |
Nikolay Sivov | 137a21d | 2012-04-18 22:39:38 +0400 | [diff] [blame] | 2904 | FIXME("(%p)->(%s %x) stub\n", This, debugstr_w(feature_name), value); |
| 2905 | return set_feature_value(This, feature, value); |
Nikolay Sivov | 165d1b5 | 2011-10-05 11:09:28 -0500 | [diff] [blame] | 2906 | } |
| 2907 | |
Nikolay Sivov | 137a21d | 2012-04-18 22:39:38 +0400 | [diff] [blame] | 2908 | FIXME("(%p)->(%s %x) stub\n", This, debugstr_w(feature_name), value); |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 2909 | return E_NOTIMPL; |
| 2910 | } |
| 2911 | |
| 2912 | static HRESULT WINAPI saxxmlreader_getProperty( |
| 2913 | IVBSAXXMLReader* iface, |
Nikolay Sivov | 864f170 | 2011-09-21 21:01:10 +0400 | [diff] [blame] | 2914 | const WCHAR *prop, |
| 2915 | VARIANT *value) |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 2916 | { |
Piotr Caban | 4fb786a | 2008-04-01 01:45:13 +0200 | [diff] [blame] | 2917 | saxreader *This = impl_from_IVBSAXXMLReader( iface ); |
Nikolay Sivov | 864f170 | 2011-09-21 21:01:10 +0400 | [diff] [blame] | 2918 | return internal_getProperty(This, prop, value, TRUE); |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 2919 | } |
| 2920 | |
| 2921 | static HRESULT WINAPI saxxmlreader_putProperty( |
| 2922 | IVBSAXXMLReader* iface, |
| 2923 | const WCHAR *pProp, |
| 2924 | VARIANT value) |
| 2925 | { |
Piotr Caban | 4fb786a | 2008-04-01 01:45:13 +0200 | [diff] [blame] | 2926 | saxreader *This = impl_from_IVBSAXXMLReader( iface ); |
Piotr Caban | c7fc926 | 2008-10-01 19:52:36 +0200 | [diff] [blame] | 2927 | return internal_putProperty(This, pProp, value, TRUE); |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 2928 | } |
| 2929 | |
Rob Shearman | 60b4fee | 2008-09-09 10:26:51 +0100 | [diff] [blame] | 2930 | static HRESULT WINAPI saxxmlreader_get_entityResolver( |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 2931 | IVBSAXXMLReader* iface, |
| 2932 | IVBSAXEntityResolver **pEntityResolver) |
| 2933 | { |
Piotr Caban | 4fb786a | 2008-04-01 01:45:13 +0200 | [diff] [blame] | 2934 | saxreader *This = impl_from_IVBSAXXMLReader( iface ); |
Piotr Caban | cb6bcd0 | 2008-07-31 16:48:20 +0200 | [diff] [blame] | 2935 | return internal_getEntityResolver(This, pEntityResolver, TRUE); |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 2936 | } |
| 2937 | |
Rob Shearman | 60b4fee | 2008-09-09 10:26:51 +0100 | [diff] [blame] | 2938 | static HRESULT WINAPI saxxmlreader_put_entityResolver( |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 2939 | IVBSAXXMLReader* iface, |
| 2940 | IVBSAXEntityResolver *pEntityResolver) |
| 2941 | { |
Piotr Caban | 4fb786a | 2008-04-01 01:45:13 +0200 | [diff] [blame] | 2942 | saxreader *This = impl_from_IVBSAXXMLReader( iface ); |
Piotr Caban | cb6bcd0 | 2008-07-31 16:48:20 +0200 | [diff] [blame] | 2943 | return internal_putEntityResolver(This, pEntityResolver, TRUE); |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 2944 | } |
| 2945 | |
Rob Shearman | 60b4fee | 2008-09-09 10:26:51 +0100 | [diff] [blame] | 2946 | static HRESULT WINAPI saxxmlreader_get_contentHandler( |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 2947 | IVBSAXXMLReader* iface, |
| 2948 | IVBSAXContentHandler **ppContentHandler) |
| 2949 | { |
Piotr Caban | 4fb786a | 2008-04-01 01:45:13 +0200 | [diff] [blame] | 2950 | saxreader *This = impl_from_IVBSAXXMLReader( iface ); |
Piotr Caban | cb6bcd0 | 2008-07-31 16:48:20 +0200 | [diff] [blame] | 2951 | return internal_getContentHandler(This, ppContentHandler, TRUE); |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 2952 | } |
| 2953 | |
Rob Shearman | 60b4fee | 2008-09-09 10:26:51 +0100 | [diff] [blame] | 2954 | static HRESULT WINAPI saxxmlreader_put_contentHandler( |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 2955 | IVBSAXXMLReader* iface, |
| 2956 | IVBSAXContentHandler *contentHandler) |
| 2957 | { |
Piotr Caban | 4fb786a | 2008-04-01 01:45:13 +0200 | [diff] [blame] | 2958 | saxreader *This = impl_from_IVBSAXXMLReader( iface ); |
Piotr Caban | cb6bcd0 | 2008-07-31 16:48:20 +0200 | [diff] [blame] | 2959 | return internal_putContentHandler(This, contentHandler, TRUE); |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 2960 | } |
| 2961 | |
Rob Shearman | 60b4fee | 2008-09-09 10:26:51 +0100 | [diff] [blame] | 2962 | static HRESULT WINAPI saxxmlreader_get_dtdHandler( |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 2963 | IVBSAXXMLReader* iface, |
| 2964 | IVBSAXDTDHandler **pDTDHandler) |
| 2965 | { |
Piotr Caban | 4fb786a | 2008-04-01 01:45:13 +0200 | [diff] [blame] | 2966 | saxreader *This = impl_from_IVBSAXXMLReader( iface ); |
Piotr Caban | cb6bcd0 | 2008-07-31 16:48:20 +0200 | [diff] [blame] | 2967 | return internal_getDTDHandler(This, pDTDHandler, TRUE); |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 2968 | } |
| 2969 | |
Rob Shearman | 60b4fee | 2008-09-09 10:26:51 +0100 | [diff] [blame] | 2970 | static HRESULT WINAPI saxxmlreader_put_dtdHandler( |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 2971 | IVBSAXXMLReader* iface, |
| 2972 | IVBSAXDTDHandler *pDTDHandler) |
| 2973 | { |
Piotr Caban | 4fb786a | 2008-04-01 01:45:13 +0200 | [diff] [blame] | 2974 | saxreader *This = impl_from_IVBSAXXMLReader( iface ); |
Piotr Caban | cb6bcd0 | 2008-07-31 16:48:20 +0200 | [diff] [blame] | 2975 | return internal_putDTDHandler(This, pDTDHandler, TRUE); |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 2976 | } |
| 2977 | |
Rob Shearman | 60b4fee | 2008-09-09 10:26:51 +0100 | [diff] [blame] | 2978 | static HRESULT WINAPI saxxmlreader_get_errorHandler( |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 2979 | IVBSAXXMLReader* iface, |
| 2980 | IVBSAXErrorHandler **pErrorHandler) |
| 2981 | { |
Piotr Caban | 4fb786a | 2008-04-01 01:45:13 +0200 | [diff] [blame] | 2982 | saxreader *This = impl_from_IVBSAXXMLReader( iface ); |
Piotr Caban | cb6bcd0 | 2008-07-31 16:48:20 +0200 | [diff] [blame] | 2983 | return internal_getErrorHandler(This, pErrorHandler, TRUE); |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 2984 | } |
| 2985 | |
Rob Shearman | 60b4fee | 2008-09-09 10:26:51 +0100 | [diff] [blame] | 2986 | static HRESULT WINAPI saxxmlreader_put_errorHandler( |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 2987 | IVBSAXXMLReader* iface, |
| 2988 | IVBSAXErrorHandler *errorHandler) |
| 2989 | { |
Piotr Caban | 4fb786a | 2008-04-01 01:45:13 +0200 | [diff] [blame] | 2990 | saxreader *This = impl_from_IVBSAXXMLReader( iface ); |
Piotr Caban | cb6bcd0 | 2008-07-31 16:48:20 +0200 | [diff] [blame] | 2991 | return internal_putErrorHandler(This, errorHandler, TRUE); |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 2992 | } |
| 2993 | |
Rob Shearman | 60b4fee | 2008-09-09 10:26:51 +0100 | [diff] [blame] | 2994 | static HRESULT WINAPI saxxmlreader_get_baseURL( |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 2995 | IVBSAXXMLReader* iface, |
| 2996 | const WCHAR **pBaseUrl) |
| 2997 | { |
Piotr Caban | 4fb786a | 2008-04-01 01:45:13 +0200 | [diff] [blame] | 2998 | saxreader *This = impl_from_IVBSAXXMLReader( iface ); |
| 2999 | |
| 3000 | FIXME("(%p)->(%p) stub\n", This, pBaseUrl); |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 3001 | return E_NOTIMPL; |
| 3002 | } |
| 3003 | |
Rob Shearman | 60b4fee | 2008-09-09 10:26:51 +0100 | [diff] [blame] | 3004 | static HRESULT WINAPI saxxmlreader_put_baseURL( |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 3005 | IVBSAXXMLReader* iface, |
| 3006 | const WCHAR *pBaseUrl) |
| 3007 | { |
Piotr Caban | 4fb786a | 2008-04-01 01:45:13 +0200 | [diff] [blame] | 3008 | saxreader *This = impl_from_IVBSAXXMLReader( iface ); |
| 3009 | |
| 3010 | FIXME("(%p)->(%s) stub\n", This, debugstr_w(pBaseUrl)); |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 3011 | return E_NOTIMPL; |
| 3012 | } |
| 3013 | |
Rob Shearman | 60b4fee | 2008-09-09 10:26:51 +0100 | [diff] [blame] | 3014 | static HRESULT WINAPI saxxmlreader_get_secureBaseURL( |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 3015 | IVBSAXXMLReader* iface, |
| 3016 | const WCHAR **pSecureBaseUrl) |
| 3017 | { |
Piotr Caban | 4fb786a | 2008-04-01 01:45:13 +0200 | [diff] [blame] | 3018 | saxreader *This = impl_from_IVBSAXXMLReader( iface ); |
| 3019 | |
| 3020 | FIXME("(%p)->(%p) stub\n", This, pSecureBaseUrl); |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 3021 | return E_NOTIMPL; |
| 3022 | } |
| 3023 | |
| 3024 | |
Rob Shearman | 60b4fee | 2008-09-09 10:26:51 +0100 | [diff] [blame] | 3025 | static HRESULT WINAPI saxxmlreader_put_secureBaseURL( |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 3026 | IVBSAXXMLReader* iface, |
| 3027 | const WCHAR *secureBaseUrl) |
| 3028 | { |
Piotr Caban | 4fb786a | 2008-04-01 01:45:13 +0200 | [diff] [blame] | 3029 | saxreader *This = impl_from_IVBSAXXMLReader( iface ); |
| 3030 | |
| 3031 | FIXME("(%p)->(%s) stub\n", This, debugstr_w(secureBaseUrl)); |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 3032 | return E_NOTIMPL; |
| 3033 | } |
| 3034 | |
| 3035 | static HRESULT WINAPI saxxmlreader_parse( |
| 3036 | IVBSAXXMLReader* iface, |
| 3037 | VARIANT varInput) |
| 3038 | { |
Piotr Caban | 4fb786a | 2008-04-01 01:45:13 +0200 | [diff] [blame] | 3039 | saxreader *This = impl_from_IVBSAXXMLReader( iface ); |
Piotr Caban | cb6bcd0 | 2008-07-31 16:48:20 +0200 | [diff] [blame] | 3040 | return internal_parse(This, varInput, TRUE); |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 3041 | } |
| 3042 | |
| 3043 | static HRESULT WINAPI saxxmlreader_parseURL( |
| 3044 | IVBSAXXMLReader* iface, |
| 3045 | const WCHAR *url) |
| 3046 | { |
Piotr Caban | 4fb786a | 2008-04-01 01:45:13 +0200 | [diff] [blame] | 3047 | saxreader *This = impl_from_IVBSAXXMLReader( iface ); |
Piotr Caban | cb6bcd0 | 2008-07-31 16:48:20 +0200 | [diff] [blame] | 3048 | return internal_parseURL(This, url, TRUE); |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 3049 | } |
| 3050 | |
Nikolay Sivov | 9d66292 | 2011-12-24 16:10:33 +0300 | [diff] [blame] | 3051 | static const struct IVBSAXXMLReaderVtbl VBSAXXMLReaderVtbl = |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 3052 | { |
| 3053 | saxxmlreader_QueryInterface, |
| 3054 | saxxmlreader_AddRef, |
| 3055 | saxxmlreader_Release, |
| 3056 | saxxmlreader_GetTypeInfoCount, |
| 3057 | saxxmlreader_GetTypeInfo, |
| 3058 | saxxmlreader_GetIDsOfNames, |
| 3059 | saxxmlreader_Invoke, |
| 3060 | saxxmlreader_getFeature, |
| 3061 | saxxmlreader_putFeature, |
| 3062 | saxxmlreader_getProperty, |
| 3063 | saxxmlreader_putProperty, |
Rob Shearman | 60b4fee | 2008-09-09 10:26:51 +0100 | [diff] [blame] | 3064 | saxxmlreader_get_entityResolver, |
| 3065 | saxxmlreader_put_entityResolver, |
| 3066 | saxxmlreader_get_contentHandler, |
| 3067 | saxxmlreader_put_contentHandler, |
| 3068 | saxxmlreader_get_dtdHandler, |
| 3069 | saxxmlreader_put_dtdHandler, |
| 3070 | saxxmlreader_get_errorHandler, |
| 3071 | saxxmlreader_put_errorHandler, |
| 3072 | saxxmlreader_get_baseURL, |
| 3073 | saxxmlreader_put_baseURL, |
| 3074 | saxxmlreader_get_secureBaseURL, |
| 3075 | saxxmlreader_put_secureBaseURL, |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 3076 | saxxmlreader_parse, |
| 3077 | saxxmlreader_parseURL |
| 3078 | }; |
| 3079 | |
Piotr Caban | 1926760 | 2008-07-08 20:52:04 +0200 | [diff] [blame] | 3080 | /*** ISAXXMLReader interface ***/ |
| 3081 | /*** IUnknown methods ***/ |
| 3082 | static HRESULT WINAPI isaxxmlreader_QueryInterface(ISAXXMLReader* iface, REFIID riid, void **ppvObject) |
| 3083 | { |
| 3084 | saxreader *This = impl_from_ISAXXMLReader( iface ); |
Michael Stefaniuc | 13e1997 | 2010-12-27 23:12:06 +0100 | [diff] [blame] | 3085 | return saxxmlreader_QueryInterface(&This->IVBSAXXMLReader_iface, riid, ppvObject); |
Piotr Caban | 1926760 | 2008-07-08 20:52:04 +0200 | [diff] [blame] | 3086 | } |
| 3087 | |
| 3088 | static ULONG WINAPI isaxxmlreader_AddRef(ISAXXMLReader* iface) |
| 3089 | { |
| 3090 | saxreader *This = impl_from_ISAXXMLReader( iface ); |
Michael Stefaniuc | 13e1997 | 2010-12-27 23:12:06 +0100 | [diff] [blame] | 3091 | return saxxmlreader_AddRef(&This->IVBSAXXMLReader_iface); |
Piotr Caban | 1926760 | 2008-07-08 20:52:04 +0200 | [diff] [blame] | 3092 | } |
| 3093 | |
| 3094 | static ULONG WINAPI isaxxmlreader_Release(ISAXXMLReader* iface) |
| 3095 | { |
| 3096 | saxreader *This = impl_from_ISAXXMLReader( iface ); |
Michael Stefaniuc | 13e1997 | 2010-12-27 23:12:06 +0100 | [diff] [blame] | 3097 | return saxxmlreader_Release(&This->IVBSAXXMLReader_iface); |
Piotr Caban | 1926760 | 2008-07-08 20:52:04 +0200 | [diff] [blame] | 3098 | } |
| 3099 | |
| 3100 | /*** ISAXXMLReader methods ***/ |
| 3101 | static HRESULT WINAPI isaxxmlreader_getFeature( |
| 3102 | ISAXXMLReader* iface, |
| 3103 | const WCHAR *pFeature, |
| 3104 | VARIANT_BOOL *pValue) |
| 3105 | { |
| 3106 | saxreader *This = impl_from_ISAXXMLReader( iface ); |
Michael Stefaniuc | 13e1997 | 2010-12-27 23:12:06 +0100 | [diff] [blame] | 3107 | return IVBSAXXMLReader_getFeature(&This->IVBSAXXMLReader_iface, pFeature, pValue); |
Piotr Caban | 1926760 | 2008-07-08 20:52:04 +0200 | [diff] [blame] | 3108 | } |
| 3109 | |
| 3110 | static HRESULT WINAPI isaxxmlreader_putFeature( |
| 3111 | ISAXXMLReader* iface, |
| 3112 | const WCHAR *pFeature, |
| 3113 | VARIANT_BOOL vfValue) |
| 3114 | { |
| 3115 | saxreader *This = impl_from_ISAXXMLReader( iface ); |
Michael Stefaniuc | 13e1997 | 2010-12-27 23:12:06 +0100 | [diff] [blame] | 3116 | return IVBSAXXMLReader_putFeature(&This->IVBSAXXMLReader_iface, pFeature, vfValue); |
Piotr Caban | 1926760 | 2008-07-08 20:52:04 +0200 | [diff] [blame] | 3117 | } |
| 3118 | |
| 3119 | static HRESULT WINAPI isaxxmlreader_getProperty( |
| 3120 | ISAXXMLReader* iface, |
Nikolay Sivov | 864f170 | 2011-09-21 21:01:10 +0400 | [diff] [blame] | 3121 | const WCHAR *prop, |
| 3122 | VARIANT *value) |
Piotr Caban | 1926760 | 2008-07-08 20:52:04 +0200 | [diff] [blame] | 3123 | { |
| 3124 | saxreader *This = impl_from_ISAXXMLReader( iface ); |
Nikolay Sivov | 864f170 | 2011-09-21 21:01:10 +0400 | [diff] [blame] | 3125 | return internal_getProperty(This, prop, value, FALSE); |
Piotr Caban | 1926760 | 2008-07-08 20:52:04 +0200 | [diff] [blame] | 3126 | } |
| 3127 | |
| 3128 | static HRESULT WINAPI isaxxmlreader_putProperty( |
| 3129 | ISAXXMLReader* iface, |
| 3130 | const WCHAR *pProp, |
| 3131 | VARIANT value) |
| 3132 | { |
| 3133 | saxreader *This = impl_from_ISAXXMLReader( iface ); |
Piotr Caban | c7fc926 | 2008-10-01 19:52:36 +0200 | [diff] [blame] | 3134 | return internal_putProperty(This, pProp, value, FALSE); |
Piotr Caban | 1926760 | 2008-07-08 20:52:04 +0200 | [diff] [blame] | 3135 | } |
| 3136 | |
| 3137 | static HRESULT WINAPI isaxxmlreader_getEntityResolver( |
| 3138 | ISAXXMLReader* iface, |
| 3139 | ISAXEntityResolver **ppEntityResolver) |
| 3140 | { |
| 3141 | saxreader *This = impl_from_ISAXXMLReader( iface ); |
Piotr Caban | cb6bcd0 | 2008-07-31 16:48:20 +0200 | [diff] [blame] | 3142 | return internal_getEntityResolver(This, ppEntityResolver, FALSE); |
Piotr Caban | 1926760 | 2008-07-08 20:52:04 +0200 | [diff] [blame] | 3143 | } |
| 3144 | |
| 3145 | static HRESULT WINAPI isaxxmlreader_putEntityResolver( |
| 3146 | ISAXXMLReader* iface, |
| 3147 | ISAXEntityResolver *pEntityResolver) |
| 3148 | { |
| 3149 | saxreader *This = impl_from_ISAXXMLReader( iface ); |
Piotr Caban | cb6bcd0 | 2008-07-31 16:48:20 +0200 | [diff] [blame] | 3150 | return internal_putEntityResolver(This, pEntityResolver, FALSE); |
Piotr Caban | 1926760 | 2008-07-08 20:52:04 +0200 | [diff] [blame] | 3151 | } |
| 3152 | |
| 3153 | static HRESULT WINAPI isaxxmlreader_getContentHandler( |
| 3154 | ISAXXMLReader* iface, |
| 3155 | ISAXContentHandler **pContentHandler) |
| 3156 | { |
| 3157 | saxreader *This = impl_from_ISAXXMLReader( iface ); |
Piotr Caban | cb6bcd0 | 2008-07-31 16:48:20 +0200 | [diff] [blame] | 3158 | return internal_getContentHandler(This, pContentHandler, FALSE); |
Piotr Caban | 1926760 | 2008-07-08 20:52:04 +0200 | [diff] [blame] | 3159 | } |
| 3160 | |
| 3161 | static HRESULT WINAPI isaxxmlreader_putContentHandler( |
| 3162 | ISAXXMLReader* iface, |
| 3163 | ISAXContentHandler *contentHandler) |
| 3164 | { |
| 3165 | saxreader *This = impl_from_ISAXXMLReader( iface ); |
Piotr Caban | cb6bcd0 | 2008-07-31 16:48:20 +0200 | [diff] [blame] | 3166 | return internal_putContentHandler(This, contentHandler, FALSE); |
Piotr Caban | 1926760 | 2008-07-08 20:52:04 +0200 | [diff] [blame] | 3167 | } |
| 3168 | |
| 3169 | static HRESULT WINAPI isaxxmlreader_getDTDHandler( |
| 3170 | ISAXXMLReader* iface, |
| 3171 | ISAXDTDHandler **pDTDHandler) |
| 3172 | { |
| 3173 | saxreader *This = impl_from_ISAXXMLReader( iface ); |
Piotr Caban | cb6bcd0 | 2008-07-31 16:48:20 +0200 | [diff] [blame] | 3174 | return internal_getDTDHandler(This, pDTDHandler, FALSE); |
Piotr Caban | 1926760 | 2008-07-08 20:52:04 +0200 | [diff] [blame] | 3175 | } |
| 3176 | |
| 3177 | static HRESULT WINAPI isaxxmlreader_putDTDHandler( |
| 3178 | ISAXXMLReader* iface, |
| 3179 | ISAXDTDHandler *pDTDHandler) |
| 3180 | { |
| 3181 | saxreader *This = impl_from_ISAXXMLReader( iface ); |
Piotr Caban | cb6bcd0 | 2008-07-31 16:48:20 +0200 | [diff] [blame] | 3182 | return internal_putDTDHandler(This, pDTDHandler, FALSE); |
Piotr Caban | 1926760 | 2008-07-08 20:52:04 +0200 | [diff] [blame] | 3183 | } |
| 3184 | |
| 3185 | static HRESULT WINAPI isaxxmlreader_getErrorHandler( |
| 3186 | ISAXXMLReader* iface, |
| 3187 | ISAXErrorHandler **pErrorHandler) |
| 3188 | { |
| 3189 | saxreader *This = impl_from_ISAXXMLReader( iface ); |
Piotr Caban | cb6bcd0 | 2008-07-31 16:48:20 +0200 | [diff] [blame] | 3190 | return internal_getErrorHandler(This, pErrorHandler, FALSE); |
Piotr Caban | 1926760 | 2008-07-08 20:52:04 +0200 | [diff] [blame] | 3191 | } |
| 3192 | |
| 3193 | static HRESULT WINAPI isaxxmlreader_putErrorHandler( |
| 3194 | ISAXXMLReader* iface, |
| 3195 | ISAXErrorHandler *errorHandler) |
| 3196 | { |
| 3197 | saxreader *This = impl_from_ISAXXMLReader( iface ); |
Piotr Caban | cb6bcd0 | 2008-07-31 16:48:20 +0200 | [diff] [blame] | 3198 | return internal_putErrorHandler(This, errorHandler, FALSE); |
Piotr Caban | 1926760 | 2008-07-08 20:52:04 +0200 | [diff] [blame] | 3199 | } |
| 3200 | |
| 3201 | static HRESULT WINAPI isaxxmlreader_getBaseURL( |
| 3202 | ISAXXMLReader* iface, |
| 3203 | const WCHAR **pBaseUrl) |
| 3204 | { |
| 3205 | saxreader *This = impl_from_ISAXXMLReader( iface ); |
Michael Stefaniuc | 13e1997 | 2010-12-27 23:12:06 +0100 | [diff] [blame] | 3206 | return IVBSAXXMLReader_get_baseURL(&This->IVBSAXXMLReader_iface, pBaseUrl); |
Piotr Caban | 1926760 | 2008-07-08 20:52:04 +0200 | [diff] [blame] | 3207 | } |
| 3208 | |
| 3209 | static HRESULT WINAPI isaxxmlreader_putBaseURL( |
| 3210 | ISAXXMLReader* iface, |
| 3211 | const WCHAR *pBaseUrl) |
| 3212 | { |
| 3213 | saxreader *This = impl_from_ISAXXMLReader( iface ); |
Michael Stefaniuc | 13e1997 | 2010-12-27 23:12:06 +0100 | [diff] [blame] | 3214 | return IVBSAXXMLReader_put_baseURL(&This->IVBSAXXMLReader_iface, pBaseUrl); |
Piotr Caban | 1926760 | 2008-07-08 20:52:04 +0200 | [diff] [blame] | 3215 | } |
| 3216 | |
| 3217 | static HRESULT WINAPI isaxxmlreader_getSecureBaseURL( |
| 3218 | ISAXXMLReader* iface, |
| 3219 | const WCHAR **pSecureBaseUrl) |
| 3220 | { |
| 3221 | saxreader *This = impl_from_ISAXXMLReader( iface ); |
Michael Stefaniuc | 13e1997 | 2010-12-27 23:12:06 +0100 | [diff] [blame] | 3222 | return IVBSAXXMLReader_get_secureBaseURL(&This->IVBSAXXMLReader_iface, pSecureBaseUrl); |
Piotr Caban | 1926760 | 2008-07-08 20:52:04 +0200 | [diff] [blame] | 3223 | } |
| 3224 | |
| 3225 | static HRESULT WINAPI isaxxmlreader_putSecureBaseURL( |
| 3226 | ISAXXMLReader* iface, |
| 3227 | const WCHAR *secureBaseUrl) |
| 3228 | { |
| 3229 | saxreader *This = impl_from_ISAXXMLReader( iface ); |
Michael Stefaniuc | 13e1997 | 2010-12-27 23:12:06 +0100 | [diff] [blame] | 3230 | return IVBSAXXMLReader_put_secureBaseURL(&This->IVBSAXXMLReader_iface, secureBaseUrl); |
Piotr Caban | b15345d | 2008-07-27 19:54:48 +0200 | [diff] [blame] | 3231 | } |
| 3232 | |
| 3233 | static HRESULT WINAPI isaxxmlreader_parse( |
| 3234 | ISAXXMLReader* iface, |
| 3235 | VARIANT varInput) |
| 3236 | { |
| 3237 | saxreader *This = impl_from_ISAXXMLReader( iface ); |
Piotr Caban | cb6bcd0 | 2008-07-31 16:48:20 +0200 | [diff] [blame] | 3238 | return internal_parse(This, varInput, FALSE); |
Piotr Caban | 1926760 | 2008-07-08 20:52:04 +0200 | [diff] [blame] | 3239 | } |
| 3240 | |
| 3241 | static HRESULT WINAPI isaxxmlreader_parseURL( |
| 3242 | ISAXXMLReader* iface, |
| 3243 | const WCHAR *url) |
| 3244 | { |
| 3245 | saxreader *This = impl_from_ISAXXMLReader( iface ); |
Piotr Caban | cb6bcd0 | 2008-07-31 16:48:20 +0200 | [diff] [blame] | 3246 | return internal_parseURL(This, url, FALSE); |
Piotr Caban | 1926760 | 2008-07-08 20:52:04 +0200 | [diff] [blame] | 3247 | } |
| 3248 | |
Nikolay Sivov | 9d66292 | 2011-12-24 16:10:33 +0300 | [diff] [blame] | 3249 | static const struct ISAXXMLReaderVtbl SAXXMLReaderVtbl = |
Piotr Caban | 1926760 | 2008-07-08 20:52:04 +0200 | [diff] [blame] | 3250 | { |
| 3251 | isaxxmlreader_QueryInterface, |
| 3252 | isaxxmlreader_AddRef, |
| 3253 | isaxxmlreader_Release, |
| 3254 | isaxxmlreader_getFeature, |
| 3255 | isaxxmlreader_putFeature, |
| 3256 | isaxxmlreader_getProperty, |
| 3257 | isaxxmlreader_putProperty, |
| 3258 | isaxxmlreader_getEntityResolver, |
| 3259 | isaxxmlreader_putEntityResolver, |
| 3260 | isaxxmlreader_getContentHandler, |
| 3261 | isaxxmlreader_putContentHandler, |
| 3262 | isaxxmlreader_getDTDHandler, |
| 3263 | isaxxmlreader_putDTDHandler, |
| 3264 | isaxxmlreader_getErrorHandler, |
| 3265 | isaxxmlreader_putErrorHandler, |
| 3266 | isaxxmlreader_getBaseURL, |
| 3267 | isaxxmlreader_putBaseURL, |
| 3268 | isaxxmlreader_getSecureBaseURL, |
| 3269 | isaxxmlreader_putSecureBaseURL, |
| 3270 | isaxxmlreader_parse, |
| 3271 | isaxxmlreader_parseURL |
| 3272 | }; |
| 3273 | |
Nikolay Sivov | 0ba0f4c | 2011-11-21 12:23:25 +0300 | [diff] [blame] | 3274 | static const tid_t saxreader_iface_tids[] = { |
| 3275 | IVBSAXXMLReader_tid, |
| 3276 | 0 |
| 3277 | }; |
| 3278 | static dispex_static_data_t saxreader_dispex = { |
| 3279 | NULL, |
| 3280 | IVBSAXXMLReader_tid, |
| 3281 | NULL, |
| 3282 | saxreader_iface_tids |
| 3283 | }; |
| 3284 | |
Nikolay Sivov | 9d66292 | 2011-12-24 16:10:33 +0300 | [diff] [blame] | 3285 | HRESULT SAXXMLReader_create(MSXML_VERSION version, IUnknown *outer, LPVOID *ppObj) |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 3286 | { |
| 3287 | saxreader *reader; |
| 3288 | |
Nikolay Sivov | 9d66292 | 2011-12-24 16:10:33 +0300 | [diff] [blame] | 3289 | TRACE("(%p, %p)\n", outer, ppObj); |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 3290 | |
Nikolay Sivov | d8a9a69 | 2010-02-03 22:47:53 +0300 | [diff] [blame] | 3291 | reader = heap_alloc( sizeof (*reader) ); |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 3292 | if( !reader ) |
| 3293 | return E_OUTOFMEMORY; |
| 3294 | |
Nikolay Sivov | 9d66292 | 2011-12-24 16:10:33 +0300 | [diff] [blame] | 3295 | reader->IVBSAXXMLReader_iface.lpVtbl = &VBSAXXMLReaderVtbl; |
| 3296 | reader->ISAXXMLReader_iface.lpVtbl = &SAXXMLReaderVtbl; |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 3297 | reader->ref = 1; |
Piotr Caban | 3fa75f4 | 2008-07-08 21:00:20 +0200 | [diff] [blame] | 3298 | reader->contentHandler = NULL; |
Piotr Caban | 7b7a187 | 2008-08-20 18:32:23 +0200 | [diff] [blame] | 3299 | reader->vbcontentHandler = NULL; |
Piotr Caban | be89ee1 | 2008-07-08 20:52:41 +0200 | [diff] [blame] | 3300 | reader->errorHandler = NULL; |
Piotr Caban | 7b7a187 | 2008-08-20 18:32:23 +0200 | [diff] [blame] | 3301 | reader->vberrorHandler = NULL; |
Piotr Caban | c7fc926 | 2008-10-01 19:52:36 +0200 | [diff] [blame] | 3302 | reader->lexicalHandler = NULL; |
| 3303 | reader->vblexicalHandler = NULL; |
| 3304 | reader->declHandler = NULL; |
| 3305 | reader->vbdeclHandler = NULL; |
| 3306 | reader->isParsing = FALSE; |
Andrew Nguyen | 9c5d5d8 | 2011-07-15 07:38:07 -0500 | [diff] [blame] | 3307 | reader->pool.pool = NULL; |
| 3308 | reader->pool.index = 0; |
| 3309 | reader->pool.len = 0; |
Nikolay Sivov | 9a5da56 | 2012-04-17 09:44:44 +0400 | [diff] [blame] | 3310 | reader->features = Namespaces | NamespacePrefixes; |
Piotr Caban | e84c410 | 2011-10-24 20:08:46 +0200 | [diff] [blame] | 3311 | reader->version = version; |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 3312 | |
Nikolay Sivov | 0ba0f4c | 2011-11-21 12:23:25 +0300 | [diff] [blame] | 3313 | init_dispex(&reader->dispex, (IUnknown*)&reader->IVBSAXXMLReader_iface, &saxreader_dispex); |
| 3314 | |
Piotr Caban | 51c9527 | 2008-07-17 00:40:53 +0200 | [diff] [blame] | 3315 | memset(&reader->sax, 0, sizeof(xmlSAXHandler)); |
| 3316 | reader->sax.initialized = XML_SAX2_MAGIC; |
Piotr Caban | 072383e | 2008-07-17 00:41:01 +0200 | [diff] [blame] | 3317 | reader->sax.startDocument = libxmlStartDocument; |
Piotr Caban | c58b24b | 2008-07-17 00:41:19 +0200 | [diff] [blame] | 3318 | reader->sax.endDocument = libxmlEndDocument; |
Piotr Caban | 965a2ea | 2008-07-17 00:41:27 +0200 | [diff] [blame] | 3319 | reader->sax.startElementNs = libxmlStartElementNS; |
Piotr Caban | 6693263 | 2008-07-17 00:41:34 +0200 | [diff] [blame] | 3320 | reader->sax.endElementNs = libxmlEndElementNS; |
Piotr Caban | 4038863 | 2008-07-17 00:41:40 +0200 | [diff] [blame] | 3321 | reader->sax.characters = libxmlCharacters; |
Piotr Caban | e47cbd1 | 2008-07-17 00:41:52 +0200 | [diff] [blame] | 3322 | reader->sax.setDocumentLocator = libxmlSetDocumentLocator; |
Piotr Caban | db2761a | 2008-10-07 22:11:04 +0200 | [diff] [blame] | 3323 | reader->sax.comment = libxmlComment; |
Piotr Caban | bba7eb5 | 2008-07-19 22:32:10 +0200 | [diff] [blame] | 3324 | reader->sax.error = libxmlFatalError; |
| 3325 | reader->sax.fatalError = libxmlFatalError; |
Piotr Caban | b84e478 | 2008-10-07 22:11:11 +0200 | [diff] [blame] | 3326 | reader->sax.cdataBlock = libxmlCDataBlock; |
Piotr Caban | 51c9527 | 2008-07-17 00:40:53 +0200 | [diff] [blame] | 3327 | |
Michael Stefaniuc | 13e1997 | 2010-12-27 23:12:06 +0100 | [diff] [blame] | 3328 | *ppObj = &reader->IVBSAXXMLReader_iface; |
Alistair Leslie-Hughes | b478ec0 | 2008-03-26 14:40:01 +1100 | [diff] [blame] | 3329 | |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 3330 | TRACE("returning iface %p\n", *ppObj); |
Alistair Leslie-Hughes | b478ec0 | 2008-03-26 14:40:01 +1100 | [diff] [blame] | 3331 | |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 3332 | return S_OK; |
| 3333 | } |
| 3334 | |
| 3335 | #else |
| 3336 | |
Piotr Caban | e84c410 | 2011-10-24 20:08:46 +0200 | [diff] [blame] | 3337 | HRESULT SAXXMLReader_create(MSXML_VERSION version, IUnknown *pUnkOuter, LPVOID *ppObj) |
Alistair Leslie-Hughes | 264be58 | 2008-03-25 14:19:10 +1100 | [diff] [blame] | 3338 | { |
| 3339 | MESSAGE("This program tried to use a SAX XML Reader object, but\n" |
| 3340 | "libxml2 support was not present at compile time.\n"); |
| 3341 | return E_NOTIMPL; |
| 3342 | } |
| 3343 | |
| 3344 | #endif |