static void xmlNanoHTTPScanAnswer(xmlNanoHTTPCtxtPtr ctxt, const char *line) { const char *cur = line; if (line == NULL) return; if (!strncmp(line, "HTTP/", 5)) { int version = 0; int ret = 0; cur += 5; while ((*cur >= '0') && (*cur <= '9')) { version *= 10; version += *cur - '0'; cur++; } if (*cur == '.') { cur++; if ((*cur >= '0') && (*cur <= '9')) { version *= 10; version += *cur - '0'; cur++; } while ((*cur >= '0') && (*cur <= '9')) cur++; } else version *= 10; if ((*cur != ' ') && (*cur != '\t')) return; while ((*cur == ' ') || (*cur == '\t')) cur++; if ((*cur < '0') || (*cur > '9')) return; while ((*cur >= '0') && (*cur <= '9')) { ret *= 10; ret += *cur - '0'; cur++; } if ((*cur != 0) && (*cur != ' ') && (*cur != '\t')) return; ctxt->returnValue = ret; ctxt->version = version; } else if (!xmlStrncasecmp(BAD_CAST line, BAD_CAST"Content-Type:", 13)) { const xmlChar *charset, *last, *mime; cur += 13; while ((*cur == ' ') || (*cur == '\t')) cur++; if (ctxt->contentType != NULL) xmlFree(ctxt->contentType); ctxt->contentType = xmlMemStrdup(cur); mime = (const xmlChar *) cur; last = mime; while ((*last != 0) && (*last != ' ') && (*last != '\t') && (*last != ';') && (*last != ',')) last++; if (ctxt->mimeType != NULL) xmlFree(ctxt->mimeType); ctxt->mimeType = (char *) xmlStrndup(mime, last - mime); charset = xmlStrstr(BAD_CAST ctxt->contentType, BAD_CAST "charset="); if (charset != NULL) { charset += 8; last = charset; while ((*last != 0) && (*last != ' ') && (*last != '\t') && (*last != ';') && (*last != ',')) last++; if (ctxt->encoding != NULL) xmlFree(ctxt->encoding); ctxt->encoding = (char *) xmlStrndup(charset, last - charset); } } else if (!xmlStrncasecmp(BAD_CAST line, BAD_CAST"ContentType:", 12)) { const xmlChar *charset, *last, *mime; cur += 12; if (ctxt->contentType != NULL) return; while ((*cur == ' ') || (*cur == '\t')) cur++; ctxt->contentType = xmlMemStrdup(cur); mime = (const xmlChar *) cur; last = mime; while ((*last != 0) && (*last != ' ') && (*last != '\t') && (*last != ';') && (*last != ',')) last++; if (ctxt->mimeType != NULL) xmlFree(ctxt->mimeType); ctxt->mimeType = (char *) xmlStrndup(mime, last - mime); charset = xmlStrstr(BAD_CAST ctxt->contentType, BAD_CAST "charset="); if (charset != NULL) { charset += 8; last = charset; while ((*last != 0) && (*last != ' ') && (*last != '\t') && (*last != ';') && (*last != ',')) last++; if (ctxt->encoding != NULL) xmlFree(ctxt->encoding); ctxt->encoding = (char *) xmlStrndup(charset, last - charset); } } else if (!xmlStrncasecmp(BAD_CAST line, BAD_CAST"Location:", 9)) { cur += 9; while ((*cur == ' ') || (*cur == '\t')) cur++; if (ctxt->location != NULL) xmlFree(ctxt->location); if (*cur == '/') { xmlChar *tmp_http = xmlStrdup(BAD_CAST "http://"); xmlChar *tmp_loc = xmlStrcat(tmp_http, (const xmlChar *) ctxt->hostname); ctxt->location = (char *) xmlStrcat (tmp_loc, (const xmlChar *) cur); } else { ctxt->location = xmlMemStrdup(cur); } } else if (!xmlStrncasecmp(BAD_CAST line, BAD_CAST"WWW-Authenticate:", 17)) { cur += 17; while ((*cur == ' ') || (*cur == '\t')) cur++; if (ctxt->authHeader != NULL) xmlFree(ctxt->authHeader); ctxt->authHeader = xmlMemStrdup(cur); } else if (!xmlStrncasecmp(BAD_CAST line, BAD_CAST"Proxy-Authenticate:", 19)) { cur += 19; while ((*cur == ' ') || (*cur == '\t')) cur++; if (ctxt->authHeader != NULL) xmlFree(ctxt->authHeader); ctxt->authHeader = xmlMemStrdup(cur); #ifdef HAVE_ZLIB_H } else if ( !xmlStrncasecmp( BAD_CAST line, BAD_CAST"Content-Encoding:", 17) ) { cur += 17; while ((*cur == ' ') || (*cur == '\t')) cur++; if ( !xmlStrncasecmp( BAD_CAST cur, BAD_CAST"gzip", 4) ) { ctxt->usesGzip = 1; ctxt->strm = xmlMalloc(sizeof(z_stream)); if (ctxt->strm != NULL) { ctxt->strm->zalloc = Z_NULL; ctxt->strm->zfree = Z_NULL; ctxt->strm->opaque = Z_NULL; ctxt->strm->avail_in = 0; ctxt->strm->next_in = Z_NULL; inflateInit2( ctxt->strm, 31 ); } } #endif } else if ( !xmlStrncasecmp( BAD_CAST line, BAD_CAST"Content-Length:", 15) ) { cur += 15; ctxt->ContentLength = strtol( cur, NULL, 10 ); } }
/** * exsltStrSplitFunction: * @ctxt: an XPath parser context * @nargs: the number of arguments * * Splits up a string on a delimiting string and returns a node set of token * elements, each containing one token from the string. */ static void exsltStrSplitFunction(xmlXPathParserContextPtr ctxt, int nargs) { xsltTransformContextPtr tctxt; xmlChar *str, *delimiter, *cur; const xmlChar *token; xmlNodePtr node; xmlDocPtr container; xmlXPathObjectPtr ret = NULL; int delimiterLength; if ((nargs < 1) || (nargs > 2)) { xmlXPathSetArityError(ctxt); return; } if (nargs == 2) { delimiter = xmlXPathPopString(ctxt); if (xmlXPathCheckError(ctxt)) return; } else { delimiter = xmlStrdup((const xmlChar *) " "); } if (delimiter == NULL) return; delimiterLength = xmlStrlen (delimiter); str = xmlXPathPopString(ctxt); if (xmlXPathCheckError(ctxt) || (str == NULL)) { xmlFree(delimiter); return; } /* Return a result tree fragment */ tctxt = xsltXPathGetTransformContext(ctxt); if (tctxt == NULL) { xsltTransformError(xsltXPathGetTransformContext(ctxt), NULL, NULL, "exslt:tokenize : internal error tctxt == NULL\n"); goto fail; } /* * OPTIMIZE TODO: We are creating an xmlDoc for every split! */ container = xsltCreateRVT(tctxt); if (container != NULL) { xsltRegisterLocalRVT(tctxt, container); ret = xmlXPathNewNodeSet(NULL); if (ret != NULL) { for (cur = str, token = str; *cur != 0; cur++) { if (delimiterLength == 0) { if (cur != token) { xmlChar tmp = *cur; *cur = 0; node = xmlNewDocRawNode(container, NULL, (const xmlChar *) "token", token); xmlAddChild((xmlNodePtr) container, node); xmlXPathNodeSetAddUnique(ret->nodesetval, node); *cur = tmp; token++; } } else if (!xmlStrncasecmp(cur, delimiter, delimiterLength)) { if (cur == token) { /* discard empty tokens */ cur = cur + delimiterLength - 1; token = cur + 1; continue; } *cur = 0; node = xmlNewDocRawNode(container, NULL, (const xmlChar *) "token", token); xmlAddChild((xmlNodePtr) container, node); xmlXPathNodeSetAddUnique(ret->nodesetval, node); *cur = *delimiter; cur = cur + delimiterLength - 1; token = cur + 1; } } if (token != cur) { node = xmlNewDocRawNode(container, NULL, (const xmlChar *) "token", token); xmlAddChild((xmlNodePtr) container, node); xmlXPathNodeSetAddUnique(ret->nodesetval, node); } /* * Mark it as a function result in order to avoid garbage * collecting of tree fragments */ xsltExtensionInstructionResultRegister(tctxt, ret); } } fail: if (str != NULL) xmlFree(str); if (delimiter != NULL) xmlFree(delimiter); if (ret != NULL) valuePush(ctxt, ret); else valuePush(ctxt, xmlXPathNewNodeSet(NULL)); }
static void handle_start_font (GstSamiContext * sctx, const xmlChar ** atts) { int i; sami_context_pop_state (sctx, SPAN_TAG); if (atts != NULL) { g_string_append (sctx->buf, "<span"); for (i = 0; (atts[i] != NULL); i += 2) { const xmlChar *key, *value; key = atts[i]; value = atts[i + 1]; if (!value) continue; if (!xmlStrncmp ((const xmlChar *) "color", key, 5)) { /* * There are invalid color value in many * sami files. * It will fix hex color value that start without '#' */ gchar *sharp = ""; int len = xmlStrlen (value); if (!(*value == '#' && len == 7)) { gchar *r; /* check if it looks like hex */ if (strtol ((const char *) value, &r, 16) >= 0 && ((xmlChar *) r == (value + 6) && len == 6)) { sharp = "#"; } } /* some colours can be found in many sami files, but X RGB database * doesn't contain a colour by this name, so map explicitly */ if (!xmlStrncasecmp (value, (const xmlChar *) "aqua", len)) { value = (const xmlChar *) "#00ffff"; } else if (!xmlStrncasecmp (value, (const xmlChar *) "crimson", len)) { value = (const xmlChar *) "#dc143c"; } else if (!xmlStrncasecmp (value, (const xmlChar *) "fuchsia", len)) { value = (const xmlChar *) "#ff00ff"; } else if (!xmlStrncasecmp (value, (const xmlChar *) "indigo", len)) { value = (const xmlChar *) "#4b0082"; } else if (!xmlStrncasecmp (value, (const xmlChar *) "lime", len)) { value = (const xmlChar *) "#00ff00"; } else if (!xmlStrncasecmp (value, (const xmlChar *) "olive", len)) { value = (const xmlChar *) "#808000"; } else if (!xmlStrncasecmp (value, (const xmlChar *) "silver", len)) { value = (const xmlChar *) "#c0c0c0"; } else if (!xmlStrncasecmp (value, (const xmlChar *) "teal", len)) { value = (const xmlChar *) "#008080"; } g_string_append_printf (sctx->buf, " foreground=\"%s%s\"", sharp, value); } else if (!xmlStrncasecmp ((const xmlChar *) "face", key, 4)) { g_string_append_printf (sctx->buf, " font_family=\"%s\"", value); } } g_string_append_c (sctx->buf, '>'); sami_context_push_state (sctx, SPAN_TAG); } }
/** * xsltAttributeInternal: * @ctxt: a XSLT process context * @node: the node in the source tree. * @inst: the xsl:attribute element * @comp: precomputed information * @fromAttributeSet: the attribute comes from an attribute-set * * Process the xslt attribute node on the source node */ static void xsltAttributeInternal(xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr inst, xsltStylePreCompPtr castedComp, int fromAttributeSet) { #ifdef XSLT_REFACTORED xsltStyleItemAttributePtr comp = (xsltStyleItemAttributePtr) castedComp; /* * TODO: Change the fields of the compiled struct: * 1) @name (char) * 2) @nameType (String, AVT) * 3) @nsName (char) * 4) nsNameType (None, String, AVT) */ #else xsltStylePreCompPtr comp = castedComp; #endif xmlNodePtr targetElem; xmlChar *prop = NULL; const xmlChar *name = NULL, *prefix = NULL, *nsName = NULL; xmlChar *value = NULL; xmlNsPtr ns = NULL; xmlAttrPtr attr; if ((ctxt == NULL) || (node == NULL) || (inst == NULL)) return; /* * BIG NOTE: This previously used xsltGetSpecialNamespace() and * xsltGetNamespace(), but since both are not appropriate, we * will process namespace lookup here to avoid adding yet another * ns-lookup function to namespaces.c. */ /* * SPEC XSLT 1.0: Error cases: * - Creating nodes other than text nodes during the instantiation of * the content of the xsl:attribute element; implementations may * either signal the error or ignore the offending nodes." */ if (comp == NULL) { xsltTransformError(ctxt, NULL, inst, "Internal error in xsltAttributeInternal(): " "The instruction was no compiled.\n"); return; } /* * TODO: Shouldn't ctxt->insert == NULL be treated as an internal error? * So report an internal error? */ if (ctxt->insert == NULL) return; /* * SPEC XSLT 1.0: * "Adding an attribute to a node that is not an element; * implementations may either signal the error or ignore the attribute." * * TODO: I think we should signal such errors in the future, and maybe * provide an option to ignore such errors. */ targetElem = ctxt->insert; if (targetElem->type != XML_ELEMENT_NODE) return; /* * SPEC XSLT 1.0: * "Adding an attribute to an element after children have been added * to it; implementations may either signal the error or ignore the * attribute." * * TODO: We should decide whether not to report such errors or * to ignore them; note that we *ignore* if the parent is not an * element, but here we report an error. */ if (targetElem->children != NULL) { /* * NOTE: Ah! This seems to be intended to support streamed * result generation!. */ xsltTransformError(ctxt, NULL, inst, "xsl:attribute: Cannot add attributes to an " "element if children have been already added " "to the element.\n"); return; } /* * Process the name * ---------------- */ if (!comp->has_name) /* TODO: raise error */ return; #ifdef WITH_DEBUGGER if (ctxt->debugStatus != XSLT_DEBUG_NONE) xslHandleDebugger(inst, node, NULL, ctxt); #endif if (comp->name == NULL) { /* TODO: fix attr acquisition wrt to the XSLT namespace */ prop = xsltEvalAttrValueTemplate(ctxt, inst, (const xmlChar *) "name", XSLT_NAMESPACE); if (prop == NULL) { xsltTransformError(ctxt, NULL, inst, "xsl:attribute: The attribute 'name' is missing.\n"); goto error; } if (xmlValidateQName(prop, 0)) { xsltTransformError(ctxt, NULL, inst, "xsl:attribute: The effective name '%s' is not a " "valid QName.\n", prop); /* we fall through to catch any further errors, if possible */ } name = xsltSplitQName(ctxt->dict, prop, &prefix); xmlFree(prop); } else { name = xsltSplitQName(ctxt->dict, comp->name, &prefix); } if (!xmlStrncasecmp(prefix, (xmlChar *) "xmlns", 5)) { #ifdef WITH_XSLT_DEBUG_PARSING xsltGenericDebug(xsltGenericDebugContext, "xsltAttribute: xmlns prefix forbidden\n"); #endif /* * SPEC XSLT 1.0: * "It is an error if the string that results from instantiating * the attribute value template is not a QName or is the string * xmlns. An XSLT processor may signal the error; if it does not * signal the error, it must recover by not adding the attribute * to the result tree." * TODO: Decide which way to go here. */ goto error; } /* * Process namespace semantics * --------------------------- * * Evaluate the namespace name. */ if (comp->has_ns) { if (comp->ns != NULL) { if (comp->ns[0] != 0) nsName = comp->ns; } else { xmlChar *tmpNsName; /* * Eval the AVT. */ /* TODO: check attr acquisition wrt to the XSLT namespace */ tmpNsName = xsltEvalAttrValueTemplate(ctxt, inst, (const xmlChar *) "namespace", XSLT_NAMESPACE); /* * This fixes bug #302020: The AVT might also evaluate to the * empty string; this means that the empty string also indicates * "no namespace". * SPEC XSLT 1.0: * "If the string is empty, then the expanded-name of the * attribute has a null namespace URI." */ if ((tmpNsName != NULL) && (tmpNsName[0] != 0)) nsName = xmlDictLookup(ctxt->dict, BAD_CAST tmpNsName, -1); xmlFree(tmpNsName); }; } else if (prefix != NULL) { /* * SPEC XSLT 1.0: * "If the namespace attribute is not present, then the QName is * expanded into an expanded-name using the namespace declarations * in effect for the xsl:attribute element, *not* including any * default namespace declaration." */ ns = xmlSearchNs(inst->doc, inst, prefix); if (ns == NULL) { /* * Note that this is treated as an error now (checked with * Saxon, Xalan-J and MSXML). */ xsltTransformError(ctxt, NULL, inst, "xsl:attribute: The effective prefix '%s', has no " "namespace binding in scope in the stylesheet; " "this is an error, since the namespace was not " "specified by the instruction itself.\n", prefix); } else nsName = ns->href; } if (fromAttributeSet) { /* * I think this tries to ensure that xsl:attribute(s) coming * from an xsl:attribute-set won't override attribute of * literal result elements or of explicit xsl:attribute(s). */ attr = xmlHasNsProp(targetElem, name, nsName); if (attr != NULL) return; } /* * Something about ns-prefixes: * SPEC XSLT 1.0: * "XSLT processors may make use of the prefix of the QName specified * in the name attribute when selecting the prefix used for outputting * the created attribute as XML; however, they are not required to do * so and, if the prefix is xmlns, they must not do so" */ /* * Find/create a matching ns-decl in the result tree. */ ns = NULL; #if 0 if (0) { /* * OPTIMIZE TODO: How do we know if we are adding to a * fragment or not? * * If we are adding to a result tree fragment (i.e., not to the * actual result tree), we'll don't bother searching for the * ns-decl, but just store it in the dummy-doc of the result * tree fragment. */ if (nsName != NULL) { ns = xsltTreeAcquireStoredNs(ctxt->document->doc, nsName, prefix); } } #endif if (nsName != NULL) { /* * The owner-element might be in the same namespace. */ if ((targetElem->ns != NULL) && (targetElem->ns->prefix != NULL) && xmlStrEqual(targetElem->ns->href, nsName)) { ns = targetElem->ns; goto namespace_finished; } if (prefix != NULL) { /* * Search by ns-prefix. */ ns = xmlSearchNs(targetElem->doc, targetElem, prefix); if ((ns != NULL) && (xmlStrEqual(ns->href, nsName))) { goto namespace_finished; } } /* * Fallback to a search by ns-name. */ ns = xmlSearchNsByHref(targetElem->doc, targetElem, nsName); if ((ns != NULL) && (ns->prefix != NULL)) { goto namespace_finished; } /* * OK, we need to declare the namespace on the target element. */ if (prefix) { if (targetElem->nsDef != NULL) { ns = targetElem->nsDef; do { if ((ns->prefix) && xmlStrEqual(ns->prefix, prefix)) { /* * The prefix is aready occupied. */ break; } ns = ns->next; } while (ns != NULL); if (ns == NULL) { ns = xmlNewNs(targetElem, nsName, prefix); goto namespace_finished; } } } /* * Generate a new prefix. */ { const xmlChar *basepref = prefix; xmlChar pref[30]; int counter = 1; if (prefix != NULL) basepref = prefix; else basepref = xmlStrdup(BAD_CAST "ns"); do { snprintf((char *) pref, 30, "%s%d", basepref, counter++); ns = xmlSearchNs(targetElem->doc, targetElem, BAD_CAST pref); if (counter > 1000) { xsltTransformError(ctxt, NULL, inst, "Namespace fixup error: Failed to compute a " "new unique ns-prefix for the generated attribute " "{%s}%s'.\n", nsName, name); ns = NULL; break; } } while (ns != NULL); if (basepref != prefix) xmlFree((xmlChar *)basepref); ns = xmlNewNs(targetElem, nsName, BAD_CAST pref); } namespace_finished: if (ns == NULL) { xsltTransformError(ctxt, NULL, inst, "Namespace fixup error: Failed to acquire an in-scope " "namespace binding of the generated attribute '{%s}%s'.\n", nsName, name); /* * TODO: Should we just stop here? */ } } /* * Construction of the value * ------------------------- */ if (inst->children == NULL) { /* * No content. * TODO: Do we need to put the empty string in ? */ attr = xmlSetNsProp(ctxt->insert, ns, name, (const xmlChar *) ""); } else if ((inst->children->next == NULL) && ((inst->children->type == XML_TEXT_NODE) || (inst->children->type == XML_CDATA_SECTION_NODE))) { xmlNodePtr origTxt = inst->children, copyTxt; /* * Optimization: if the content is just 1 text node, then * just need to copy it over, or just assign it to the result * if the string is shared. */ attr = xmlSetNsProp(ctxt->insert, ns, name, NULL); if (attr == NULL) /* TODO: report error ? */ goto error; /* * This was taken over from xsltCopyText() (transform.c). */ if (ctxt->internalized && (ctxt->insert->doc != NULL) && (ctxt->insert->doc->dict == ctxt->dict)) { copyTxt = xmlNewText(NULL); if (copyTxt == NULL) /* TODO: report error */ goto error; /* * This is a safe scenario where we don't need to lookup * the dict. */ copyTxt->content = origTxt->content; /* * Copy "disable-output-escaping" information. * TODO: Does this have any effect for attribute values * anyway? */ if (origTxt->name == xmlStringTextNoenc) copyTxt->name = xmlStringTextNoenc; } else { /* * Copy the value. */ copyTxt = xmlNewText(origTxt->content); if (copyTxt == NULL) /* TODO: report error */ goto error; /* * Copy "disable-output-escaping" information. * TODO: Does this have any effect for attribute values * anyway? */ if (origTxt->name == xmlStringTextNoenc) copyTxt->name = xmlStringTextNoenc; } if (copyTxt != NULL) { copyTxt->doc = attr->doc; xmlAddChild((xmlNodePtr) attr, copyTxt); } } else { /* * The sequence constructor might be complex, so instantiate it. */ value = xsltEvalTemplateString(ctxt, node, inst); if (value != NULL) { attr = xmlSetNsProp(ctxt->insert, ns, name, value); xmlFree(value); } else { /* * TODO: Do we have to add the empty string to the attr? */ attr = xmlSetNsProp(ctxt->insert, ns, name, (const xmlChar *) ""); } } error: return; }
/** * Reinit a program object using data from [cur] xmlNode and applying [locale] * When [cur]==0 the object is cleared, memory freed and the object is put to its * initial empty state */ static void reinit_program( program_t *pro, xmlNodePtr cur, xmlChar *locale ) { if( cur ) { xmlChar *start = xmlGetProp( cur, BAD_CAST "start" ); xmlChar *stop = xmlGetProp( cur, BAD_CAST "stop" ); xmlChar *lang; time_t start_time = 0; time_t end_time = 0; if( start ) { start_time = parse_xmltv_date( (char *) start ); xmlFree( start ); } if( stop ) { end_time = parse_xmltv_date( (char *) stop ); xmlFree( stop ); } else { end_time = start_time + 1800; } pro->start_time = start_time; pro->end_time = end_time; cur = cur->xmlChildrenNode; while( cur ) { lang = xmlGetProp( cur, BAD_CAST "lang"); if( !xmlStrcasecmp( cur->name, BAD_CAST "title" ) ) { if( !lang || !locale ) { if ( pro->title ) xmlFree ( pro->title ); pro->title = xmlNodeGetContent( cur ); } else if( !xmlStrncasecmp( lang, locale, 2 ) ) { if ( pro->title_local ) xmlFree ( pro->title_local ); pro->title_local = xmlNodeGetContent( cur ); } else if( !pro->title ) { pro->title = xmlNodeGetContent( cur ); } } else if( !xmlStrcasecmp( cur->name, BAD_CAST "sub-title" ) ) { if( !lang || !locale ) { if ( pro->subtitle ) xmlFree ( pro->subtitle ); pro->subtitle = xmlNodeGetContent( cur ); } else if( !xmlStrncasecmp( lang, locale, 2 ) ) { if ( pro->subtitle_local ) xmlFree ( pro->subtitle_local ); pro->subtitle_local = xmlNodeGetContent( cur ); } else if( !pro->subtitle ) { pro->subtitle = xmlNodeGetContent( cur ); } } else if( !xmlStrcasecmp( cur->name, BAD_CAST "desc" ) ) { if( !lang || !locale ) { if ( pro->description ) xmlFree ( pro->description ); pro->description = xmlNodeGetContent( cur ); } else if( !xmlStrncasecmp( lang, locale, 2 ) ) { if ( pro->description_local ) xmlFree ( pro->description_local ); pro->description_local = xmlNodeGetContent( cur ); } else if( !pro->description ) { pro->description = xmlNodeGetContent( cur ); } } if( lang ) xmlFree( lang ); cur = cur->next; } } else { pro->title = pro->subtitle = pro->description = 0; pro->title_local = pro->subtitle_local = pro->description_local = 0; pro->start_time = 0; pro->end_time = 0; } }