* xmlSchemaIDCAddStateObject: * @vctxt: the WXS validation context * @matcher: the IDC matcher * @sel: the XPath information * @parent: the parent "selector" state object if any * @type: "selector" or "field" * * Creates/reuses and activates state objects for the given * XPath information; if the XPath expression consists of unions, * multiple state objects are created for every unioned e
| 22332 | * Returns 0 on success and -1 on internal errors. |
| 22333 | */ |
| 22334 | static int |
| 22335 | xmlSchemaIDCAddStateObject(xmlSchemaValidCtxtPtr vctxt, |
| 22336 | xmlSchemaIDCMatcherPtr matcher, |
| 22337 | xmlSchemaIDCSelectPtr sel, |
| 22338 | int type) |
| 22339 | { |
| 22340 | xmlSchemaIDCStateObjPtr sto; |
| 22341 | |
| 22342 | /* |
| 22343 | * Reuse the state objects from the pool. |
| 22344 | */ |
| 22345 | if (vctxt->xpathStatePool != NULL) { |
| 22346 | sto = vctxt->xpathStatePool; |
| 22347 | vctxt->xpathStatePool = sto->next; |
| 22348 | sto->next = NULL; |
| 22349 | } else { |
| 22350 | /* |
| 22351 | * Create a new state object. |
| 22352 | */ |
| 22353 | sto = (xmlSchemaIDCStateObjPtr) xmlMalloc(sizeof(xmlSchemaIDCStateObj)); |
| 22354 | if (sto == NULL) { |
| 22355 | xmlSchemaVErrMemory(NULL); |
| 22356 | return (-1); |
| 22357 | } |
| 22358 | memset(sto, 0, sizeof(xmlSchemaIDCStateObj)); |
| 22359 | } |
| 22360 | /* |
| 22361 | * Add to global list. |
| 22362 | */ |
| 22363 | if (vctxt->xpathStates != NULL) |
| 22364 | sto->next = vctxt->xpathStates; |
| 22365 | vctxt->xpathStates = sto; |
| 22366 | |
| 22367 | /* |
| 22368 | * Free the old xpath validation context. |
| 22369 | */ |
| 22370 | if (sto->xpathCtxt != NULL) |
| 22371 | xmlFreeStreamCtxt((xmlStreamCtxtPtr) sto->xpathCtxt); |
| 22372 | |
| 22373 | /* |
| 22374 | * Create a new XPath (pattern) validation context. |
| 22375 | */ |
| 22376 | sto->xpathCtxt = (void *) xmlPatternGetStreamCtxt( |
| 22377 | (xmlPatternPtr) sel->xpathComp); |
| 22378 | if (sto->xpathCtxt == NULL) { |
| 22379 | VERROR_INT("xmlSchemaIDCAddStateObject", |
| 22380 | "failed to create an XPath validation context"); |
| 22381 | return (-1); |
| 22382 | } |
| 22383 | sto->type = type; |
| 22384 | sto->depth = vctxt->depth; |
| 22385 | sto->matcher = matcher; |
| 22386 | sto->sel = sel; |
| 22387 | sto->nbHistory = 0; |
| 22388 | |
| 22389 | return (0); |
| 22390 | } |
| 22391 |
no test coverage detected