static void _qualify_namespace(XML_Parser parser, const xmlChar *name, const xmlChar *URI, xmlChar **qualified) { if (URI) { /* Use libxml functions otherwise its memory deallocation is screwed up */ *qualified = xmlStrdup(URI); *qualified = xmlStrncat(*qualified, parser->_ns_seperator, 1); *qualified = xmlStrncat(*qualified, name, xmlStrlen(name)); } else { *qualified = xmlStrdup(name); } }
/** * exsltStrReplaceInternal: * @str: string to modify * @searchStr: string to find * @replaceStr: string to replace occurrences of searchStr * * Search and replace string function used by exsltStrReplaceFunction */ static xmlChar* exsltStrReplaceInternal(const xmlChar* str, const xmlChar* searchStr, const xmlChar* replaceStr) { const xmlChar *curr, *next; xmlChar *ret = NULL; int searchStrSize; curr = str; searchStrSize = xmlStrlen(searchStr); do { next = xmlStrstr(curr, searchStr); if (next == NULL) { ret = xmlStrcat (ret, curr); break; } ret = xmlStrncat (ret, curr, next - curr); ret = xmlStrcat (ret, replaceStr); curr = next + searchStrSize; } while (*curr != 0); return ret; }
/** * exsltStrPaddingFunction: * @ctxt: an XPath parser context * @nargs: the number of arguments * * Creates a padding string of a certain length. */ static void exsltStrPaddingFunction (xmlXPathParserContextPtr ctxt, int nargs) { int number, str_len = 0, str_size = 0; xmlChar *str = NULL, *ret = NULL; if ((nargs < 1) || (nargs > 2)) { xmlXPathSetArityError(ctxt); return; } if (nargs == 2) { str = xmlXPathPopString(ctxt); str_len = xmlUTF8Strlen(str); str_size = xmlStrlen(str); } if (str_len == 0) { if (str != NULL) xmlFree(str); str = xmlStrdup((const xmlChar *) " "); str_len = 1; str_size = 1; } number = (int) xmlXPathPopNumber(ctxt); if (number <= 0) { xmlXPathReturnEmptyString(ctxt); xmlFree(str); return; } while (number >= str_len) { ret = xmlStrncat(ret, str, str_size); number -= str_len; } if (number > 0) { str_size = xmlUTF8Strsize(str, number); ret = xmlStrncat(ret, str, str_size); } xmlXPathReturnString(ctxt, ret); if (str != NULL) xmlFree(str); }
/** * xmlStrcat: * @cur: the original xmlChar * array * @add: the xmlChar * array added * * a strcat for array of xmlChar's. Since they are supposed to be * encoded in UTF-8 or an encoding with 8bit based chars, we assume * a termination mark of '0'. * * Returns a new xmlChar * containing the concatenated string. */ xmlChar * xmlStrcat(xmlChar *cur, const xmlChar *add) { const xmlChar *p = add; if (add == NULL) return(cur); if (cur == NULL) return(xmlStrdup(add)); while (*p != 0) p++; /* non input consuming */ return(xmlStrncat(cur, add, p - add)); }
static void _start_element_handler(void *user, const xmlChar *name, const xmlChar **attributes) { XML_Parser parser = (XML_Parser) user; xmlChar *qualified_name = NULL; if (parser->h_start_element == NULL) { if (parser->h_default) { int attno = 0; qualified_name = xmlStrncatNew((xmlChar *)"<", name, xmlStrlen(name)); if (attributes) { while (attributes[attno] != NULL) { int att_len; char *att_string, *att_name, *att_value; att_name = (char *)attributes[attno++]; att_value = (char *)attributes[attno++]; att_len = spprintf(&att_string, 0, " %s=\"%s\"", att_name, att_value); qualified_name = xmlStrncat(qualified_name, (xmlChar *)att_string, att_len); efree(att_string); } } qualified_name = xmlStrncat(qualified_name, (xmlChar *)">", 1); parser->h_default(parser->user, (const XML_Char *) qualified_name, xmlStrlen(qualified_name)); xmlFree(qualified_name); } return; } qualified_name = xmlStrdup(name); parser->h_start_element(parser->user, (const XML_Char *) qualified_name, (const XML_Char **) attributes); xmlFree(qualified_name); }
/** * xmlStrcat: * @param cur the original xmlChar* array * @param add the xmlChar* array added * * a strcat for array of xmlChar's. Since they are supposed to be * encoded in UTF-8 or an encoding with 8bit based chars, we assume * a termination mark of '0'. * * Returns a new xmlChar* containing the concatenated string. * * OOM: possible --> OOM flag is set */ XMLPUBFUNEXPORT xmlChar* xmlStrcat(xmlChar* cur, const xmlChar *add) { const xmlChar* p = add; if (!add) return(cur); if (!cur) return(xmlStrdup(add)); while (*p != 0) p++; /* non input consuming */ return(xmlStrncat(cur, add, p - add)); }
xmlbusErrorPtr serviceExecutionFunc(xmlbusServicePtr service, xmlbusSoapMessagePtr request, xmlbusSoapMessagePtr* response) { xmlbusErrorPtr xbErr = XMLBUS_OK; xmlbusErrorPtr xbCallingError = XMLBUS_OK; xmlbusServiceCustomDataPtr serviceCustomData = NULL; xmlNodePtr foundActionNode = NULL; xmlChar* actionToExecute = NULL; int result = -1; serviceCustomData = xmlbusServiceGetCustomData(service); if (serviceCustomData == NULL) { xbErr = xmlbusErrorAdd(xbErr, XMLBUS_ERRORS_LOCATION, -1, BAD_CAST "Could not get to the service custom data"); goto onError; } dlserviceExecutionFunc execFunc; foundActionNode = xmlbusSoapGetBodyActionAsNode(request); if (foundActionNode == NULL || foundActionNode->type != XML_ELEMENT_NODE || foundActionNode->name == NULL) { xbErr = xmlbusErrorAdd(xbErr, XMLBUS_ERRORS_LOCATION, -1, BAD_CAST "Could not get the first child element under the body in order to determine the action"); goto onError; } actionToExecute = xmlStrdup(foundActionNode->name); actionToExecute = xmlStrncat(actionToExecute, BAD_CAST "Action",6); result = xmlModuleSymbol(serviceCustomData->modServiceImpl,(char*) actionToExecute,(void**)&execFunc); if (result == 0) { xbCallingError = (execFunc)(request, response); if (xbCallingError != XMLBUS_OK) { xbErr = xmlbusErrorAdd(xbCallingError, XMLBUS_ERRORS_LOCATION, -1, BAD_CAST "Exection of the service %s failed", actionToExecute); xmlFree(actionToExecute); goto onError; } } else { // error action not found xbErr = xmlbusErrorAdd(xbErr, XMLBUS_ERRORS_LOCATION, -1, BAD_CAST "Could not find the implementing action: %s", actionToExecute); xmlFree(actionToExecute); goto onError; } xmlFree(actionToExecute); return xbErr; onError: return xbErr; }
static void _start_element_handler_ns(void *user, const xmlChar *name, const xmlChar *prefix, const xmlChar *URI, int nb_namespaces, const xmlChar ** namespaces, int nb_attributes, int nb_defaulted, const xmlChar ** attributes) { XML_Parser parser = (XML_Parser) user; xmlChar *qualified_name = NULL; xmlChar **attrs = NULL; int i; int z = 0; int y = 0; if (nb_namespaces > 0 && parser->h_start_ns != NULL) { for (i = 0; i < nb_namespaces; i += 1) { parser->h_start_ns(parser->user, (const XML_Char *) namespaces[y], (const XML_Char *) namespaces[y+1]); y += 2; } y = 0; } if (parser->h_start_element == NULL) { if (parser->h_default) { if (prefix) { qualified_name = xmlStrncatNew((xmlChar *)"<", prefix, xmlStrlen(prefix)); qualified_name = xmlStrncat(qualified_name, (xmlChar *)":", 1); qualified_name = xmlStrncat(qualified_name, name, xmlStrlen(name)); } else { qualified_name = xmlStrncatNew((xmlChar *)"<", name, xmlStrlen(name)); } if (namespaces) { int i, j; for (i = 0,j = 0;j < nb_namespaces;j++) { int ns_len; char *ns_string, *ns_prefix, *ns_url; ns_prefix = (char *) namespaces[i++]; ns_url = (char *) namespaces[i++]; if (ns_prefix) { ns_len = spprintf(&ns_string, 0, " xmlns:%s=\"%s\"", ns_prefix, ns_url); } else { ns_len = spprintf(&ns_string, 0, " xmlns=\"%s\"", ns_url); } qualified_name = xmlStrncat(qualified_name, (xmlChar *)ns_string, ns_len); efree(ns_string); } } if (attributes) { for (i = 0; i < nb_attributes; i += 1) { int att_len; char *att_string, *att_name, *att_value, *att_prefix, *att_valueend; att_name = (char *) attributes[y++]; att_prefix = (char *)attributes[y++]; y++; att_value = (char *)attributes[y++]; att_valueend = (char *)attributes[y++]; if (att_prefix) { att_len = spprintf(&att_string, 0, " %s:%s=\"", att_prefix, att_name); } else { att_len = spprintf(&att_string, 0, " %s=\"", att_name); } qualified_name = xmlStrncat(qualified_name, (xmlChar *)att_string, att_len); qualified_name = xmlStrncat(qualified_name, (xmlChar *)att_value, att_valueend - att_value); qualified_name = xmlStrncat(qualified_name, (xmlChar *)"\"", 1); efree(att_string); } } qualified_name = xmlStrncat(qualified_name, (xmlChar *)">", 1); parser->h_default(parser->user, (const XML_Char *) qualified_name, xmlStrlen(qualified_name)); xmlFree(qualified_name); } return; } _qualify_namespace(parser, name, URI, &qualified_name); if (attributes != NULL) { xmlChar *qualified_name_attr = NULL; attrs = safe_emalloc((nb_attributes * 2) + 1, sizeof(int *), 0); for (i = 0; i < nb_attributes; i += 1) { if (attributes[y+1] != NULL) { _qualify_namespace(parser, attributes[y] , attributes[y + 2], &qualified_name_attr); } else { qualified_name_attr = xmlStrdup(attributes[y]); } attrs[z] = qualified_name_attr; attrs[z + 1] = xmlStrndup(attributes[y + 3] , (int) (attributes[y + 4] - attributes[y + 3])); z += 2; y += 5; } attrs[z] = NULL; } parser->h_start_element(parser->user, (const XML_Char *) qualified_name, (const XML_Char **) attrs); if (attrs) { for (i = 0; i < z; i++) { xmlFree(attrs[i]); } efree(attrs); } xmlFree(qualified_name); }
/** * xsltAttrTemplateValueProcessNode: * @ctxt: the XSLT transformation context * @str: the attribute template node value * @inst: the instruction (or LRE) in the stylesheet holding the * attribute with an AVT * * Process the given string, allowing to pass a namespace mapping * context and return the new string value. * * Called by: * - xsltAttrTemplateValueProcess() (templates.c) * - xsltEvalAttrValueTemplate() (templates.c) * * QUESTION: Why is this function public? It is not used outside * of templates.c. * * Returns the computed string value or NULL, must be deallocated by the * caller. */ xmlChar * xsltAttrTemplateValueProcessNode(xsltTransformContextPtr ctxt, const xmlChar *str, xmlNodePtr inst) { xmlChar *ret = NULL; const xmlChar *cur; xmlChar *expr, *val; xmlNsPtr *nsList = NULL; int nsNr = 0; if (str == NULL) return(NULL); if (*str == 0) return(xmlStrndup((xmlChar *)"", 0)); cur = str; while (*cur != 0) { if (*cur == '{') { if (*(cur+1) == '{') { /* escaped '{' */ cur++; ret = xmlStrncat(ret, str, cur - str); cur++; str = cur; continue; } ret = xmlStrncat(ret, str, cur - str); str = cur; cur++; while ((*cur != 0) && (*cur != '}')) cur++; if (*cur == 0) { xsltTransformError(ctxt, NULL, inst, "xsltAttrTemplateValueProcessNode: unmatched '{'\n"); ret = xmlStrncat(ret, str, cur - str); return(ret); } str++; expr = xmlStrndup(str, cur - str); if (expr == NULL) return(ret); else if (*expr == '{') { ret = xmlStrcat(ret, expr); xmlFree(expr); } else { xmlXPathCompExprPtr comp; /* * TODO: keep precompiled form around */ if ((nsList == NULL) && (inst != NULL)) { int i = 0; nsList = xmlGetNsList(inst->doc, inst); if (nsList != NULL) { while (nsList[i] != NULL) i++; nsNr = i; } } comp = xmlXPathCompile(expr); val = xsltEvalXPathStringNs(ctxt, comp, nsNr, nsList); xmlXPathFreeCompExpr(comp); xmlFree(expr); if (val != NULL) { ret = xmlStrcat(ret, val); xmlFree(val); } } cur++; str = cur; } else if (*cur == '}') { cur++; if (*cur == '}') { /* escaped '}' */ ret = xmlStrncat(ret, str, cur - str); cur++; str = cur; continue; } else { xsltTransformError(ctxt, NULL, inst, "xsltAttrTemplateValueProcessNode: unmatched '}'\n"); } } else cur++; } if (cur != str) { ret = xmlStrncat(ret, str, cur - str); } if (nsList != NULL) xmlFree(nsList); return(ret); }
/** * xsltAddKey: * @style: an XSLT stylesheet * @name: the key name or NULL * @nameURI: the name URI or NULL * @match: the match value * @use: the use value * @inst: the key instruction * * add a key definition to a stylesheet * * Returns 0 in case of success, and -1 in case of failure. */ int xsltAddKey(xsltStylesheetPtr style, const xmlChar *name, const xmlChar *nameURI, const xmlChar *match, const xmlChar *use, xmlNodePtr inst) { xsltKeyDefPtr key; xmlChar *pattern = NULL; int current, end, start, i = 0; if ((style == NULL) || (name == NULL) || (match == NULL) || (use == NULL)) return(-1); #ifdef WITH_XSLT_DEBUG_KEYS xsltGenericDebug(xsltGenericDebugContext, "Add key %s, match %s, use %s\n", name, match, use); #endif key = xsltNewKeyDef(name, nameURI); key->match = xmlStrdup(match); key->use = xmlStrdup(use); key->inst = inst; key->nsList = xmlGetNsList(inst->doc, inst); if (key->nsList != NULL) { while (key->nsList[i] != NULL) i++; } key->nsNr = i; /* * Split the | and register it as as many keys */ current = end = 0; while (match[current] != 0) { start = current; while (IS_BLANK_CH(match[current])) current++; end = current; while ((match[end] != 0) && (match[end] != '|')) { if (match[end] == '[') { end = skipPredicate(match, end); if (end <= 0) { xsltTransformError(NULL, style, inst, "xsl:key : 'match' pattern is malformed: %s", key->match); if (style != NULL) style->errors++; goto error; } } else end++; } if (current == end) { xsltTransformError(NULL, style, inst, "xsl:key : 'match' pattern is empty\n"); if (style != NULL) style->errors++; goto error; } if (match[start] != '/') { pattern = xmlStrcat(pattern, (xmlChar *)"//"); if (pattern == NULL) { if (style != NULL) style->errors++; goto error; } } pattern = xmlStrncat(pattern, &match[start], end - start); if (pattern == NULL) { if (style != NULL) style->errors++; goto error; } if (match[end] == '|') { pattern = xmlStrcat(pattern, (xmlChar *)"|"); end++; } current = end; } if (pattern == NULL) { xsltTransformError(NULL, style, inst, "xsl:key : 'match' pattern is empty\n"); if (style != NULL) style->errors++; goto error; } #ifdef WITH_XSLT_DEBUG_KEYS xsltGenericDebug(xsltGenericDebugContext, " resulting pattern %s\n", pattern); #endif /* * XSLT-1: "It is an error for the value of either the use * attribute or the match attribute to contain a * VariableReference." * TODO: We should report a variable-reference at compile-time. * Maybe a search for "$", if it occurs outside of quotation * marks, could be sufficient. */ #ifdef XML_XPATH_NOVAR key->comp = xsltXPathCompileFlags(style, pattern, XML_XPATH_NOVAR); #else key->comp = xsltXPathCompile(style, pattern); #endif if (key->comp == NULL) { xsltTransformError(NULL, style, inst, "xsl:key : 'match' pattern compilation failed '%s'\n", pattern); if (style != NULL) style->errors++; } #ifdef XML_XPATH_NOVAR key->usecomp = xsltXPathCompileFlags(style, use, XML_XPATH_NOVAR); #else key->usecomp = xsltXPathCompile(style, use); #endif if (key->usecomp == NULL) { xsltTransformError(NULL, style, inst, "xsl:key : 'use' expression compilation failed '%s'\n", use); if (style != NULL) style->errors++; } /* * Sometimes the stylesheet writer use the order to ease the * resolution of keys when they are dependant, keep the provided * order so add the new one at the end. */ if (style->keys == NULL) { style->keys = key; } else { xsltKeyDefPtr prev = style->keys; while (prev->next != NULL) prev = prev->next; prev->next = key; } key->next = NULL; error: if (pattern != NULL) xmlFree(pattern); return(0); }
/** * xsltCompileAttr: * @style: a XSLT process context * @attr: the attribute coming from the stylesheet. * * Precompile an attribute in a stylesheet, basically it checks if it is * an attrubute value template, and if yes establish some structures needed * to process it at transformation time. */ void xsltCompileAttr(xsltStylesheetPtr style, xmlAttrPtr attr) { const xmlChar *str; const xmlChar *cur; xmlChar *ret = NULL; xmlChar *expr = NULL; xsltAttrVTPtr avt; int i = 0, lastavt = 0; if ((style == NULL) || (attr == NULL) || (attr->children == NULL)) return; if ((attr->children->type != XML_TEXT_NODE) || (attr->children->next != NULL)) { xsltTransformError(NULL, style, attr->parent, "Attribute '%s': The content is expected to be a single text " "node when compiling an AVT.\n", attr->name); style->errors++; return; } str = attr->children->content; if ((xmlStrchr(str, '{') == NULL) && (xmlStrchr(str, '}') == NULL)) return; #ifdef WITH_XSLT_DEBUG_AVT xsltGenericDebug(xsltGenericDebugContext, "Found AVT %s: %s\n", attr->name, str); #endif if (attr->psvi != NULL) { #ifdef WITH_XSLT_DEBUG_AVT xsltGenericDebug(xsltGenericDebugContext, "AVT %s: already compiled\n", attr->name); #endif return; } /* * Create a new AVT object. */ avt = xsltNewAttrVT(style); if (avt == NULL) return; attr->psvi = avt; avt->nsList = xmlGetNsList(attr->doc, attr->parent); if (avt->nsList != NULL) { while (avt->nsList[i] != NULL) i++; } avt->nsNr = i; cur = str; while (*cur != 0) { if (*cur == '{') { if (*(cur+1) == '{') { /* escaped '{' */ cur++; ret = xmlStrncat(ret, str, cur - str); cur++; str = cur; continue; } if (*(cur+1) == '}') { /* skip empty AVT */ ret = xmlStrncat(ret, str, cur - str); cur += 2; str = cur; continue; } if ((ret != NULL) || (cur - str > 0)) { ret = xmlStrncat(ret, str, cur - str); str = cur; if (avt->nb_seg == 0) avt->strstart = 1; if ((avt = xsltSetAttrVTsegment(avt, (void *) ret)) == NULL) goto error; ret = NULL; lastavt = 0; } cur++; while ((*cur != 0) && (*cur != '}')) { /* Need to check for literal (bug539741) */ if ((*cur == '\'') || (*cur == '"')) { char delim = *(cur++); while ((*cur != 0) && (*cur != delim)) cur++; if (*cur != 0) cur++; /* skip the ending delimiter */ } else cur++; } if (*cur == 0) { xsltTransformError(NULL, style, attr->parent, "Attribute '%s': The AVT has an unmatched '{'.\n", attr->name); style->errors++; goto error; } str++; expr = xmlStrndup(str, cur - str); if (expr == NULL) { /* * TODO: What needs to be done here? */ XSLT_TODO goto error; } else { xmlXPathCompExprPtr comp; comp = xsltXPathCompile(style, expr); if (comp == NULL) { xsltTransformError(NULL, style, attr->parent, "Attribute '%s': Failed to compile the expression " "'%s' in the AVT.\n", attr->name, expr); style->errors++; goto error; } if (avt->nb_seg == 0) avt->strstart = 0; if (lastavt == 1) { if ((avt = xsltSetAttrVTsegment(avt, NULL)) == NULL) goto error; } if ((avt = xsltSetAttrVTsegment(avt, (void *) comp)) == NULL) goto error; lastavt = 1; xmlFree(expr); expr = NULL; } cur++; str = cur; } else if (*cur == '}') {
SDOXMLString& SDOXMLString::operator+=(const SDOXMLString& str) { xmlForm = xmlStrncat(xmlForm, str.xmlForm, xmlStrlen(str.xmlForm)); return *this; }