static void testReduce(xmlExpCtxtPtr ctxt, xmlExpNodePtr expr, const char *tst) { xmlBufferPtr xmlExpBuf; xmlExpNodePtr sub, deriv; xmlExpBuf = xmlBufferCreate(); sub = xmlExpParse(ctxt, tst); if (sub == NULL) { printf("Subset %s failed to parse\n", tst); return; } xmlExpDump(xmlExpBuf, sub); printf("Subset parsed as: %s\n", (const char *) xmlBufferContent(xmlExpBuf)); deriv = xmlExpExpDerive(ctxt, expr, sub); if (deriv == NULL) { printf("Derivation led to an internal error, report this !\n"); return; } else { xmlBufferEmpty(xmlExpBuf); xmlExpDump(xmlExpBuf, deriv); if (xmlExpIsNillable(deriv)) printf("Resulting nillable derivation: %s\n", (const char *) xmlBufferContent(xmlExpBuf)); else printf("Resulting derivation: %s\n", (const char *) xmlBufferContent(xmlExpBuf)); xmlExpFree(ctxt, deriv); } xmlExpFree(ctxt, sub); }
/* Fall through . . */ case 107: if (tolower (ch) == 'h') { state = 1; start = n; } else state = ST_INITIAL; break; case ST_START_FOUND: if (isspace ((int) ((unsigned char) ch)) || (ch == '"') || (ch == '>')) { end = n; state = ST_END_FOUND; } break; } # undef CHK # undef CCHK } else { if (state == ST_START_FOUND) { end = n; state = ST_END_FOUND; } else state = ST_INITIAL; } n += clen; } else { if (state == ST_START_FOUND) { end = n; state = ST_END_FOUND; } ++n; } if (state == ST_END_FOUND) { int ulen, m, o; ulen = end - start; for (m = 0; m < blockmail -> url_count; ++m) if ((blockmail -> url[m] -> usage & mask) && (blockmail -> url[m] -> dlen == ulen) && (! xmlStrncmp (blockmail -> url[m] -> dptr, cont + start, ulen))) break; if (m < blockmail -> url_count) { if (lstore < start) xmlBufferAdd (block -> out, cont + lstore, start - lstore); for (o = 0; o < rec -> url_count; ++o) if (rec -> url[o] -> uid == blockmail -> url[m] -> uid) break; if (o < rec -> url_count) xmlBufferAdd (block -> out, rec -> url[o] -> dptr, rec -> url[o] -> dlen); lstore = end; changed = true; } state = ST_INITIAL; } } if (changed) { if (lstore < len) xmlBufferAdd (block -> out, cont + lstore, len - lstore); SWAP (block); } return true; }/*}}}*/ static bool_t collect_links (blockmail_t *blockmail, block_t *block, links_t *links) /*{{{*/ { bool_t rc; int n, clen; int len; const xmlChar *cont; int start; rc = true; len = xmlBufferLength (block -> in); cont = xmlBufferContent (block -> in); for (n = 0; rc && (n < len); ) { clen = xmlCharLength (cont[n]); if ((clen == 1) && (cont[n] == 'h')) { start = n; ++n; if ((n + 3 < len) && (cont[n] == 't') && (cont[n + 1] == 't') && (cont[n + 2] == 'p')) { n += 3; if ((n + 1 < len) && (cont[n] == 's')) ++n; if ((n + 3 < len) && (cont[n] == ':') && (cont[n + 1] == '/') && (cont[n + 2] == '/')) { n += 3; while ((n < len) && (xmlCharLength (cont[n]) == 1) && (cont[n] != '"') && (cont[n] != '<') && (cont[n] != '>') && (! isspace (cont[n]))) ++n; rc = links_nadd (links, (const char *) (cont + start), n - start); } } } else n += clen; } return rc; }/*}}}*/ static int find_top (const xmlChar *cont, int len) /*{{{*/ { int pos; int state; int n; int clen; unsigned char ch; for (pos = -1, state = 0, n = 0; (n < len) && (pos == -1); ) { clen = xmlCharLength (cont[n]); if (clen > 1) state = 0; else { ch = cont[n]; switch (state) { case 0: if (ch == '<') state = 1; break; case 1: if ((ch == 'b') || (ch == 'B')) state = 2; else if (ch == '>') state = 0; else if (! isspace (ch)) state = 100; break; case 2: if ((ch == 'o') || (ch == 'O')) state = 3; else if (ch == '>') state = 0; else state = 100; break; case 3: if ((ch == 'd') || (ch == 'D')) state = 4; else if (ch == '>') state = 0; else state = 100; break; case 4: if ((ch == 'y') || (ch == 'Y')) state = 5; else if (ch == '>') state = 0; else state = 100; break; case 5: if (ch == '>') { pos = n + clen; state = 0; } else if (isspace (ch)) state = 6; else state = 100; break; case 6: if (ch == '>') { pos = n + clen; state = 0; } # ifdef STRICT else if (ch == '"') state = 7; break; case 7: if (ch == '"') state = 6; # endif /* STRICT */ break; case 100: if (ch == '>') state = 0; break; } } n += clen; } return pos; }/*}}}*/ static int find_bottom (const xmlChar *cont, int len) /*{{{*/ { int pos; int last; int m; int bclen; for (pos = -1, last = len, m = len - 1; (m >= 0) && (pos == -1); ) { bclen = xmlCharLength (cont[m]); if ((bclen == 1) && (cont[m] == '<')) { int n; int state; int clen; unsigned char ch; for (n = m + bclen, state = 1; (n < last) && (state > 0) && (state != 99); ) { clen = xmlCharLength (cont[n]); if (clen != 1) state = 0; else { ch = cont[n]; switch (state) { case 1: if (ch == '/') state = 2; else if (! isspace (ch)) state = 0; break; case 2: if ((ch == 'b') || (ch == 'B')) state = 3; else if (! isspace (ch)) state = 0; break; case 3: if ((ch == 'o') || (ch == 'O')) state = 4; else state = 0; break; case 4: if ((ch == 'd') || (ch == 'D')) state = 5; else state = 0; break; case 5: if ((ch == 'y') || (ch == 'Y')) state = 6; else state = 0; break; case 6: if ((ch == '>') || isspace (ch)) state = 99; else state = 0; break; } } n += clen; } if (state == 99) pos = m; } else if ((bclen == 1) && (cont[m] == '>')) last = m + bclen; m -= bclen; } return pos; }/*}}}*/ static bool_t add_onepixellog_image (blockmail_t *blockmail, receiver_t *rec, block_t *block, opl_t opl) /*{{{*/ { bool_t rc; const xmlChar tname[] = "[agnONEPIXEL]"; int tlen = sizeof (tname) - 1; tag_t *opltag; rc = true; for (opltag = rec -> tag; opltag; opltag = opltag -> next) if (tag_match (opltag, tname, tlen)) break; if (opltag && opltag -> value) { int pos; int len; const xmlChar *cont; pos = -1; len = xmlBufferLength (block -> in); cont = xmlBufferContent (block -> in); switch (opl) { case OPL_None: break; case OPL_Top: pos = find_top (cont, len); if (pos == -1) pos = 0; break; case OPL_Bottom: pos = find_bottom (cont, len); if (pos == -1) pos = len; break; } if (pos != -1) { const xmlChar lprefix[] = "<img src=\""; const xmlChar lpostfix[] = "\" alt=\"\" border=\"0\" height=\"1\" width=\"1\">"; xmlBufferEmpty (block -> out); if (pos > 0) xmlBufferAdd (block -> out, cont, pos); xmlBufferAdd (block -> out, lprefix, sizeof (lprefix) - 1); xmlBufferAdd (block -> out, xmlBufferContent (opltag -> value), xmlBufferLength (opltag -> value)); xmlBufferAdd (block -> out, lpostfix, sizeof (lpostfix) - 1); if (pos < len) xmlBufferAdd (block -> out, cont + pos, len - pos); SWAP (block); } } return rc; }/*}}}*/
I bool_t xmlEqual (xmlBufferPtr p1, xmlBufferPtr p2) /*{{{*/ { int len; const xmlChar *c1, *c2; len = xmlBufferLength (p1); if ((len == xmlBufferLength (p2)) && (c1 = xmlBufferContent (p1)) && (c2 = xmlBufferContent (p2)) && ((! len) || (! memcmp (c1, c2, len * sizeof (xmlChar))))) return true; return false; }/*}}}*/
int lpc2xml_convert_string(lpc2xml_context* context, char **content) { int ret = -1; xmlBufferPtr buffer = xmlBufferCreate(); xmlSaveCtxtPtr save_ctx; lpc2xml_context_clear_logs(context); xmlSetGenericErrorFunc(context, lpc2xml_genericxml_error); save_ctx = xmlSaveToBuffer(buffer, "UTF-8", XML_SAVE_FORMAT); if(save_ctx != NULL) { ret = internal_convert_lpc2xml(context); if(ret == 0) { ret = xmlSaveDoc(save_ctx, context->doc); if(ret != 0) { lpc2xml_log(context, LPC2XML_ERROR, "Can't save document"); lpc2xml_log(context, LPC2XML_ERROR, "%s", context->errorBuffer); } } xmlSaveClose(save_ctx); } else { lpc2xml_log(context, LPC2XML_ERROR, "Can't initialize internal buffer"); lpc2xml_log(context, LPC2XML_ERROR, "%s", context->errorBuffer); } if(ret == 0) { #if LIBXML_VERSION >= 20800 *content = (char *)xmlBufferDetach(buffer); #else *content = strdup((const char *)xmlBufferContent(buffer)); #endif } xmlBufferFree(buffer); return ret; }
static int xsltNumberFormatGetValue(xmlXPathContextPtr context, xmlNodePtr node, xmlChar *value, double *number) { int amount = 0; xmlBufferPtr pattern; xmlXPathObjectPtr obj; pattern = xmlBufferCreate(); if (pattern != NULL) { xmlBufferCCat(pattern, "number("); xmlBufferCat(pattern, value); xmlBufferCCat(pattern, ")"); context->node = node; obj = xmlXPathEvalExpression(xmlBufferContent(pattern), context); if (obj != NULL) { *number = obj->floatval; amount++; xmlXPathFreeObject(obj); } xmlBufferFree(pattern); } return amount; }
/** * Serialises an xmlNode to a string * * @param log Log context * @param node Input XML node to be serialised * * @return Returns a pointer to a new buffer containing the serialised data. This buffer must be freed * after usage */ char *xmlNodeToString(LogContext *log, xmlNode *node) { xmlBuffer *buf = NULL; xmlSaveCtxt *serctx = NULL; char *ret = NULL; if( node == NULL ) { writelog(log, LOG_ALERT, "xmlNodeToString: Input data is NULL"); return NULL; } buf = xmlBufferCreate(); assert( buf != NULL ); serctx = xmlSaveToBuffer(buf, "UTF-8", XML_SAVE_NO_EMPTY|XML_SAVE_NO_DECL); assert( serctx != NULL ); if( xmlSaveTree(serctx, node) < 0 ) { writelog(log, LOG_ALERT, "xmlNodeToString: Failed to serialise xmlNode"); return NULL; } xmlSaveClose(serctx); ret = strdup_nullsafe((char *) xmlBufferContent(buf)); xmlBufferFree(buf); return ret; }
/* wrapper for stats_event, this takes a charset to convert from */ void stats_event_conv(const char *mount, const char *name, const char *value, const char *charset) { const char *metadata = value; xmlBufferPtr conv = xmlBufferCreate (); if (charset && value) { xmlCharEncodingHandlerPtr handle = xmlFindCharEncodingHandler (charset); if (handle) { xmlBufferPtr raw = xmlBufferCreate (); xmlBufferAdd (raw, (const xmlChar *)value, strlen (value)); if (xmlCharEncInFunc (handle, conv, raw) > 0) metadata = (char *)xmlBufferContent (conv); xmlBufferFree (raw); xmlCharEncCloseFunc (handle); } else WARN1 ("No charset found for \"%s\"", charset); } stats_event (mount, name, metadata); xmlBufferFree (conv); }
/* Fall through . . */ case 107: if (tolower (ch) == 'h') { state = 1; start = n; } else state = ST_INITIAL; break; case ST_START_FOUND: if (isspace ((int) ((unsigned char) ch)) || (ch == '"') || (ch == '>')) { end = n; state = ST_END_FOUND; } break; } # undef CHK # undef CCHK } else { if (state == ST_START_FOUND) { end = n; state = ST_END_FOUND; } else state = ST_INITIAL; } n += clen; } else { if (state == ST_START_FOUND) { end = n; state = ST_END_FOUND; } ++n; } if (state == ST_END_FOUND) { int ulen, m, o; ulen = end - start; for (m = 0; m < blockmail -> url_count; ++m) if ((blockmail -> url[m] -> usage & mask) && (blockmail -> url[m] -> dlen == ulen) && (! xmlStrncmp (blockmail -> url[m] -> dptr, cont + start, ulen))) break; if (m < blockmail -> url_count) { if (lstore < start) xmlBufferAdd (block -> out, cont + lstore, start - lstore); for (o = 0; o < rec -> url_count; ++o) if (rec -> url[o] -> uid == blockmail -> url[m] -> uid) break; if (o < rec -> url_count) xmlBufferAdd (block -> out, rec -> url[o] -> dptr, rec -> url[o] -> dlen); lstore = end; changed = true; } state = ST_INITIAL; } } if (changed) { if (lstore < len) xmlBufferAdd (block -> out, cont + lstore, len - lstore); SWAP (block); } return true; }/*}}}*/ static bool_t collect_links (blockmail_t *blockmail, block_t *block, links_t *links) /*{{{*/ { bool_t rc; int n, clen; int len; const xmlChar *cont; int start; rc = true; len = xmlBufferLength (block -> in); cont = xmlBufferContent (block -> in); for (n = 0; rc && (n < len); ) { clen = xmlCharLength (cont[n]); if ((clen == 1) && (cont[n] == 'h')) { start = n; ++n; if ((n + 3 < len) && (cont[n] == 't') && (cont[n + 1] == 't') && (cont[n + 2] == 'p')) { n += 3; if ((n + 1 < len) && (cont[n] == 's')) ++n; if ((n + 3 < len) && (cont[n] == ':') && (cont[n + 1] == '/') && (cont[n + 2] == '/')) { n += 3; while ((n < len) && (xmlCharLength (cont[n]) == 1) && (cont[n] != '"') && (cont[n] != '<') && (cont[n] != '>') && (! isspace (cont[n]))) ++n; rc = links_nadd (links, (const char *) (cont + start), n - start); } } } else n += clen; } return rc; }/*}}}*/
void TrackerConfig::dump() const { string s; xmlBufferPtr pBuffer = xmlBufferCreate(); xmlNodeDump(pBuffer, m_Doc, m_pRoot, 0, 0); cerr << xmlBufferContent(pBuffer) << endl; }
//! //! Places raw XML result of an xpath query into buf. The query must return //! only one element. //! //! @param[in] xml_path a string containing the path to the XML file to parse //! @param[in] xpath a string contianing the XPATH expression to evaluate //! @param[out] buf for the XML string //! @param[in] buf_len size of the buf //! //! @return EUCA_OK or EUCA_ERROR //! int get_xpath_xml(const char *xml_path, const char *xpath, char *buf, int buf_len) { int ret = EUCA_ERROR; xmlDocPtr doc = NULL; xmlXPathContextPtr context = NULL; xmlXPathObjectPtr result = NULL; xmlNodeSetPtr nodeset = NULL; INIT(); pthread_mutex_lock(&xml_mutex); { if ((doc = xmlParseFile(xml_path)) != NULL) { if ((context = xmlXPathNewContext(doc)) != NULL) { if ((result = xmlXPathEvalExpression(((const xmlChar *)xpath), context)) != NULL) { if (!xmlXPathNodeSetIsEmpty(result->nodesetval)) { nodeset = result->nodesetval; if (nodeset->nodeNr > 1) { fprintf(stderr, "multiple matches for '%s' in '%s'\n", xpath, xml_path); } else { xmlNodePtr node = nodeset->nodeTab[0]->xmlChildrenNode; xmlBufferPtr xbuf = xmlBufferCreate(); if (xbuf) { int len = xmlNodeDump(xbuf, doc, node, 0, 1); if (len < 0) { fprintf(stderr, "failed to extract XML from %s\n", xpath); } else if (len > buf_len) { fprintf(stderr, "insufficient buffer for %s\n", xpath); } else { char *str = (char *)xmlBufferContent(xbuf); euca_strncpy(buf, str, buf_len); ret = EUCA_OK; } xmlBufferFree(xbuf); } else { fprintf(stderr, "failed to allocate XML buffer\n"); } } } xmlXPathFreeObject(result); } else { fprintf(stderr, "no results for '%s' in '%s'\n", xpath, xml_path); } xmlXPathFreeContext(context); } else { fprintf(stderr, "failed to set xpath '%s' context for '%s'\n", xpath, xml_path); } xmlFreeDoc(doc); } else { fprintf(stderr, "failed to parse XML in '%s'\n", xml_path); } } pthread_mutex_unlock(&xml_mutex); return ret; }
static gchar * update_apply_xslt (updateJobPtr job) { xsltStylesheetPtr xslt = NULL; xmlOutputBufferPtr buf; xmlDocPtr srcDoc = NULL, resDoc = NULL; gchar *output = NULL; g_assert (NULL != job->result); do { srcDoc = xml_parse (job->result->data, job->result->size, NULL); if (!srcDoc) { g_warning("fatal: parsing request result XML source failed (%s)!", job->request->filtercmd); break; } /* load localization stylesheet */ xslt = xsltParseStylesheetFile (job->request->filtercmd); if (!xslt) { g_warning ("fatal: could not load filter stylesheet \"%s\"!", job->request->filtercmd); break; } resDoc = xsltApplyStylesheet (xslt, srcDoc, NULL); if (!resDoc) { g_warning ("fatal: applying stylesheet \"%s\" failed!", job->request->filtercmd); break; } buf = xmlAllocOutputBuffer (NULL); if (-1 == xsltSaveResultTo (buf, resDoc, xslt)) { g_warning ("fatal: retrieving result of filter stylesheet failed (%s)!", job->request->filtercmd); break; } #ifdef LIBXML2_NEW_BUFFER if (xmlOutputBufferGetSize (buf) > 0) output = xmlCharStrdup (xmlOutputBufferGetContent (buf)); #else if (xmlBufferLength (buf->buffer) > 0) output = xmlCharStrdup (xmlBufferContent (buf->buffer)); #endif xmlOutputBufferClose (buf); } while (FALSE); if (srcDoc) xmlFreeDoc (srcDoc); if (resDoc) xmlFreeDoc (resDoc); if (xslt) xsltFreeStylesheet (xslt); return output; }
/** * Write the xml document out to a memory location. * @param xml The xml document * @param len The size of the memory buffer * @return a pointer to the memory location, or @c NULL if an error occurs. * @ingroup EXML_Write_Group */ void *exml_mem_write(EXML *xml, size_t *len) { xmlTextWriterPtr writer; xmlBufferPtr buf; CHECK_PARAM_POINTER_RETURN("xml", xml, FALSE); buf = xmlBufferCreate(); writer = xmlNewTextWriterMemory( buf, 0 ); if (_exml_write(xml, writer)) { ecore_hash_set( xml->buffers, (void *) xmlBufferContent( buf ), buf ); *len = xmlBufferLength( buf ); return (void *) xmlBufferContent( buf ); } else { *len = 0; xmlBufferFree( buf ); return NULL; } }
/*Write - writes xml tree of element to buffer output: data - is set to point to buffer containing xml data tlength - is set to length of xml data */ void CXMLElement::Write(char **data,int *tlength,Bool isformatted) { if (!isinited()) return; if (element->doc){ xmlBufferPtr buf; buf = xmlBufferCreate(); xmlNodeDump(buf, element->doc, element, 0, isformatted); *data = (char *)xmlStrdup(xmlBufferContent(buf)); *tlength = xmlBufferLength(buf); xmlBufferFree(buf); } }
static void exprDebug(xmlExpCtxtPtr ctxt, xmlExpNodePtr expr) { xmlBufferPtr xmlExpBuf; xmlExpNodePtr deriv; const char *list[40]; int ret; xmlExpBuf = xmlBufferCreate(); if (expr == NULL) { printf("Failed to parse\n"); return; } xmlExpDump(xmlExpBuf, expr); printf("Parsed as: %s\n", (const char *) xmlBufferContent(xmlExpBuf)); printf("Max token input = %d\n", xmlExpMaxToken(expr)); if (xmlExpIsNillable(expr) == 1) printf("Is nillable\n"); ret = xmlExpGetLanguage(ctxt, expr, (const xmlChar **) &list[0], 40); if (ret < 0) printf("Failed to get list: %d\n", ret); else { int i; printf("Language has %d strings, testing string derivations\n", ret); for (i = 0;i < ret;i++) { deriv = xmlExpStringDerive(ctxt, expr, BAD_CAST list[i], -1); if (deriv == NULL) { printf(" %s -> derivation failed\n", list[i]); } else { xmlBufferEmpty(xmlExpBuf); xmlExpDump(xmlExpBuf, deriv); printf(" %s -> %s\n", list[i], (const char *) xmlBufferContent(xmlExpBuf)); } xmlExpFree(ctxt, deriv); } } xmlBufferFree(xmlExpBuf); }
/********************************************************************************* * The contents of this file are subject to the Common Public Attribution * License Version 1.0 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.openemm.org/cpal1.html. The License is based on the Mozilla * Public License Version 1.1 but Sections 14 and 15 have been added to cover * use of software over a computer network and provide for limited attribution * for the Original Developer. In addition, Exhibit A has been modified to be * consistent with Exhibit B. * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for * the specific language governing rights and limitations under the License. * * The Original Code is OpenEMM. * The Original Developer is the Initial Developer. * The Initial Developer of the Original Code is AGNITAS AG. All portions of * the code written by AGNITAS AG are Copyright (c) 2007 AGNITAS AG. All Rights * Reserved. * * Contributor(s): AGNITAS AG. ********************************************************************************/ # include "xmlback.h" # ifndef I # define I /* */ # endif /* I */ # ifndef __MISC_C # define __MISC_C 1 I bool_t xmlEqual (xmlBufferPtr p1, xmlBufferPtr p2) /*{{{*/ { int len; const xmlChar *c1, *c2; len = xmlBufferLength (p1); if ((len == xmlBufferLength (p2)) && (c1 = xmlBufferContent (p1)) && (c2 = xmlBufferContent (p2)) && ((! len) || (! memcmp (c1, c2, len * sizeof (xmlChar))))) return true; return false; }/*}}}*/ I int xmlCharLength (xmlChar ch) /*{{{*/ { extern int xmlLengthtab[256]; return xmlLengthtab[ch]; }/*}}}*/ I int xmlStrictCharLength (xmlChar ch) /*{{{*/ { extern int xmlStrictLengthtab[256]; return xmlStrictLengthtab[ch]; }/*}}}*/ I int xmlValidPosition (const xmlChar *str, int length) /*{{{*/ { # define VALID(ccc) (((ccc) & 0xc0) == 0x80) int len, n; if (((len = xmlStrictCharLength (*str)) > 0) && (length >= len)) for (n = len; n > 1; ) { --n; if (! VALID (*(str + n))) { len = -1; break; } } else len = -1; return len; # undef VALID }/*}}}*/ I bool_t xmlValid (const xmlChar *str, int length) /*{{{*/ { int n; while (length > 0) if ((n = xmlValidPosition (str, length)) > 0) { str += n; length -= n; } else break; return length == 0 ? true : false; }/*}}}*/ I char * xml2string (xmlBufferPtr p) /*{{{*/ { int len = xmlBufferLength (p); const xmlChar *ptr = xmlBufferContent (p); char *rc; if (rc = malloc (len + 1)) { if (len > 0) memcpy (rc, ptr, len); rc[len] = '\0'; } return rc; }/*}}}*/ I const char * xml2char (const xmlChar *s) /*{{{*/ { return (const char *) s; }/*}}}*/ I const xmlChar * char2xml (const char *s) /*{{{*/ { return (const xmlChar *) s; }/*}}}*/ I const char * byte2char (const byte_t *b) /*{{{*/ { return (const char *) b; }/*}}}*/ I int xmlstrcmp (const xmlChar *s1, const char *s2) /*{{{*/ { return strcmp (xml2char (s1), s2); }/*}}}*/ I int xmlstrncmp (const xmlChar *s1, const char *s2, size_t n) /*{{{*/ { return strncmp (xml2char (s1), s2, n); }/*}}}*/ I long xml2long (xmlBufferPtr p) /*{{{*/ { int len = xmlBufferLength (p); const xmlChar *ptr = xmlBufferContent (p); char scratch[128]; if (len >= sizeof (scratch)) len = sizeof (scratch) - 1; memcpy (scratch, ptr, len); scratch[len] = '\0'; return strtol (scratch, NULL, 0); }/*}}}*/
/********************************************************************************* * The contents of this file are subject to the Common Public Attribution * License Version 1.0 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.openemm.org/cpal1.html. The License is based on the Mozilla * Public License Version 1.1 but Sections 14 and 15 have been added to cover * use of software over a computer network and provide for limited attribution * for the Original Developer. In addition, Exhibit A has been modified to be * consistent with Exhibit B. * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for * the specific language governing rights and limitations under the License. * * The Original Code is OpenEMM. * The Original Developer is the Initial Developer. * The Initial Developer of the Original Code is AGNITAS AG. All portions of * the code written by AGNITAS AG are Copyright (c) 2007 AGNITAS AG. All Rights * Reserved. * * Contributor(s): AGNITAS AG. ********************************************************************************/ # include "xmlback.h" # ifndef I # define I /* */ # endif /* I */ # ifndef __MISC_C # define __MISC_C 1 I bool_t xmlEqual (xmlBufferPtr p1, xmlBufferPtr p2) /*{{{*/ { int len; const xmlChar *c1, *c2; len = xmlBufferLength (p1); if ((len == xmlBufferLength (p2)) && (c1 = xmlBufferContent (p1)) && (c2 = xmlBufferContent (p2)) && ((! len) || (! memcmp (c1, c2, len * sizeof (xmlChar))))) return true; return false; }/*}}}*/ I int xmlCharLength (xmlChar ch) /*{{{*/ { extern int xmlLengthtab[256]; return xmlLengthtab[ch]; }/*}}}*/ I int xmlStrictCharLength (xmlChar ch) /*{{{*/ { extern int xmlStrictLengthtab[256]; return xmlStrictLengthtab[ch]; }/*}}}*/ I int xmlValidPosition (const xmlChar *str, int length) /*{{{*/ { # define VALID(ccc) (((ccc) & 0xc0) == 0x80) int len, n; if (((len = xmlStrictCharLength (*str)) > 0) && (length >= len)) for (n = len; n > 1; ) { --n; if (! VALID (*(str + n))) { len = -1; break; } } else len = -1; return len; # undef VALID }/*}}}*/ I bool_t xmlValid (const xmlChar *str, int length) /*{{{*/ { int n; while (length > 0) if ((n = xmlValidPosition (str, length)) > 0) { str += n; length -= n; } else break; return length == 0 ? true : false; }/*}}}*/ I char * xml2string (xmlBufferPtr p) /*{{{*/ { int len = xmlBufferLength (p); const xmlChar *ptr = xmlBufferContent (p); char *rc; if (rc = malloc (len + 1)) { if (len > 0) memcpy (rc, ptr, len); rc[len] = '\0'; } return rc; }/*}}}*/
/*}}}*/ }; static int psize = sizeof (parseable) / sizeof (parseable[0]); tag_t * tag_alloc (void) /*{{{*/ { tag_t *t; if (t = (tag_t *) malloc (sizeof (tag_t))) { t -> name = xmlBufferCreate (); t -> cname = NULL; t -> hash = 0; t -> type = NULL; t -> topt = NULL; t -> value = xmlBufferCreate (); t -> parm = NULL; t -> used = false; t -> next = NULL; if ((! t -> name) || (! t -> value)) t = tag_free (t); } return t; }/*}}}*/ tag_t * tag_free (tag_t *t) /*{{{*/ { if (t) { if (t -> name) xmlBufferFree (t -> name); if (t -> cname) free (t -> cname); if (t -> type) free (t -> type); if (t -> value) xmlBufferFree (t -> value); if (t -> parm) var_free_all (t -> parm); free (t); } return NULL; }/*}}}*/ tag_t * tag_free_all (tag_t *t) /*{{{*/ { tag_t *tmp; while (tmp = t) { t = t -> next; tag_free (tmp); } return NULL; }/*}}}*/ static void xmlSkip (xmlChar **ptr, int *len) /*{{{*/ { int n; while (*len > 0) { n = xmlCharLength (**ptr); if ((n == 1) && isspace (**ptr)) { *(*ptr)++ = '\0'; *len -= 1; while ((*len > 0) && (xmlCharLength (**ptr) == 1) && isspace (**ptr)) ++(*ptr); break; } else { *ptr += n; *len -= n; } } }/*}}}*/ static int mkRFCdate (char *dbuf, size_t dlen) /*{{{*/ { time_t now; struct tm *tt; time (& now); if (tt = gmtime (& now)) { const char *weekday[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }, *month[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; return sprintf (dbuf, "%s, %2d %s %d %02d:%02d:%02d GMT", weekday[tt -> tm_wday], tt -> tm_mday, month[tt -> tm_mon], tt -> tm_year + 1900, tt -> tm_hour, tt -> tm_min, tt -> tm_sec) > 0; } return 0; }/*}}}*/ static const char * find_default (tag_t *t) /*{{{*/ { const char *dflt = NULL; var_t *run; for (run = t -> parm; run; run = run -> next) if (! strcmp (run -> var, "default")) { dflt = run -> val; break; } return dflt; }/*}}}*/ void tag_parse (tag_t *t, blockmail_t *blockmail) /*{{{*/ { xmlBufferPtr temp; if (t -> name && (xmlBufferLength (t -> name) > 0) && (temp = xmlBufferCreateSize (xmlBufferLength (t -> name) + 1))) { xmlChar *ptr; xmlChar *name; int len; int tid; xmlBufferAdd (temp, xmlBufferContent (t -> name), xmlBufferLength (t -> name)); ptr = (xmlChar *) xmlBufferContent (temp); len = xmlBufferLength (temp); if ((xmlCharLength (*ptr) == 1) && (*ptr == '[')) { ++ptr; --len; if ((len > 0) && (xmlStrictCharLength (*(ptr + len - 1)) == 1) && (*(ptr + len - 1) == ']')) { --len; if ((len > 0) && (xmlStrictCharLength (*(ptr + len - 1)) == 1) && (*(ptr + len - 1) == '/')) --len; ptr[len] = '\0'; } } name = ptr; xmlSkip (& ptr, & len); if (t -> type) { for (tid = 0; tid < psize; ++tid) if (! strcmp (t -> type, parseable[tid].tname)) break; } else tid = psize; if (tid == psize) for (tid = 0; tid < psize; ++tid) if (! xmlstrcmp (name, parseable[tid].tname)) break; if (tid < psize) { var_t *cur, *prev; xmlChar *var, *val; int n; for (prev = t -> parm; prev && prev -> next; prev = prev -> next) ; while (len > 0) { var = ptr; while (len > 0) { n = xmlCharLength (*ptr); if ((n == 1) && (*ptr == '=')) { *ptr++ = '\0'; len -= 1; break; } else { ptr += n; len -= n; } } if (len > 0) { if ((xmlCharLength (*ptr) == 1) && (*ptr == '"')) { ++ptr; --len; val = ptr; while (len > 0) { n = xmlCharLength (*ptr); if ((n == 1) && (*ptr == '"')) { *ptr++ = '\0'; len -= 1; xmlSkip (& ptr, & len); break; } else { ptr += n; len -= n; } } } else { val = ptr; xmlSkip (& ptr, & len); } if (cur = var_alloc (xml2char (var), xml2char (val))) { if (prev) prev -> next = cur; else t -> parm = cur; prev = cur; } } } switch ((enum PType) tid) { case P_Sysinfo: for (cur = t -> parm; cur; cur = cur -> next) if (! strcmp (cur -> var, "name")) { if (! strcmp (cur -> val, "FQDN")) { const char *dflt; if (blockmail -> fqdn) { xmlBufferEmpty (t -> value); xmlBufferCCat (t -> value, blockmail -> fqdn); } else if (dflt = find_default (t)) { xmlBufferEmpty (t -> value); xmlBufferCCat (t -> value, dflt); } } else if (! strcmp (cur -> val, "RFCDATE")) { char dbuf[128]; if (mkRFCdate (dbuf, sizeof (dbuf))) { xmlBufferEmpty (t -> value); xmlBufferCCat (t -> value, dbuf); } } else if (! strcmp (cur -> val, "EPOCH")) { time_t now; char dbuf[64]; time (& now); sprintf (dbuf, "%ld", (long) now); xmlBufferEmpty (t -> value); xmlBufferCCat (t -> value, dbuf); } } break; } } xmlBufferFree (temp); } }/*}}}*/ bool_t tag_match (tag_t *t, const xmlChar *name, int nlen) /*{{{*/ { const xmlChar *ptr; int len; len = xmlBufferLength (t -> name); if (len == nlen) { ptr = xmlBufferContent (t -> name); if (! memcmp (name, ptr, len)) return true; } return false; }/*}}}*/
static gint plugin_ui_hook_construct (EPluginHook *hook, EPlugin *plugin, xmlNodePtr node) { EPluginUIHookPrivate *priv; priv = E_PLUGIN_UI_HOOK_GET_PRIVATE (hook); /* XXX The EPlugin should be a property of EPluginHookClass. * Then it could be passed directly to g_object_new() and * we wouldn't have to chain up here. */ /* Chain up to parent's construct() method. */ E_PLUGIN_HOOK_CLASS (parent_class)->construct (hook, plugin, node); for (node = node->children; node != NULL; node = node->next) { xmlNodePtr child; xmlBufferPtr buffer; const gchar *content; gchar *id; if (strcmp ((gchar *) node->name, "ui-manager") != 0) continue; id = e_plugin_xml_prop (node, "id"); if (id == NULL) { g_warning ("<ui-manager> requires 'id' property"); continue; } /* Extract the XML content below <ui-manager> */ buffer = xmlBufferCreate (); child = node->children; while (child != NULL && xmlNodeIsText (child)) child = child->next; if (child != NULL) xmlNodeDump (buffer, node->doc, child, 2, 1); content = (const gchar *) xmlBufferContent (buffer); g_hash_table_insert ( priv->ui_definitions, id, g_strdup (content)); xmlBufferFree (buffer); } return 0; }
/** * create preferences minimal buffer from NftPrefsNode - compared to * nft_prefs_node_to_buffer, this doesn't include any encapsulation or headers. * Just the bare information contained in the node. This should be used to * export single nodes, e.g. for copying them to a clipboard * * @param p NftPrefs context * @param n NftPrefsNode * @result string holding xml representation of object (use free() to deallocate) * @note s. @ref nft_prefs_node_to_file for description */ char *nft_prefs_node_to_buffer_minimal(NftPrefs *p, NftPrefsNode * n) { if(!n) NFT_LOG_NULL(NULL); /* result pointer (xml dump) */ char *dump = NULL; /* add prefs version to node */ if(!(_updater_node_add_version(p, n))) { NFT_LOG(L_ERROR, "failed to add version to node \"%s\"", nft_prefs_node_get_name(n)); return NULL; } /* create buffer */ xmlBufferPtr buf; if(!(buf = xmlBufferCreate())) { NFT_LOG(L_ERROR, "failed to xmlBufferCreate()"); return NULL; } /* dump node */ if(xmlNodeDump(buf, n->doc, n, 0, true) < 0) { NFT_LOG(L_ERROR, "xmlNodeDump() failed"); goto _pntb_exit; } /* allocate buffer */ size_t length = xmlBufferLength(buf); if(!(dump = malloc(length + 1))) { NFT_LOG_PERROR("malloc()"); goto _pntb_exit; } /* copy buffer */ strncpy(dump, (char *) xmlBufferContent(buf), length); dump[length] = '\0'; _pntb_exit: xmlBufferFree(buf); return dump; }
string BEXMLTextReader::raw_xml() { xmlBufferPtr node_content = xmlBufferCreate(); xmlOutputBufferPtr node = (xmlOutputBufferPtr) xmlMalloc ( sizeof(xmlOutputBuffer) ); memset ( node, 0, (size_t) sizeof(xmlOutputBuffer) ); node->buffer = node_content; xmlNodeDumpOutput ( node, xml_document, xmlTextReaderCurrentNode ( reader ), 0, true, "UTF-8" ); const xmlChar * xml_data = xmlBufferContent ( (xmlBufferPtr)node_content ); size_t xml_length = xmlBufferLength ( node_content ); string xml_result ( (char *)xml_data, xml_length ); xmlFree ( (xmlChar *)xml_data ); return xml_result; } // raw_xml
// shows the XML dump of n in textview1 void show_in_textview1(const xmlNodePtr n) { xmlBufferPtr buf = xmlBufferCreate(); int ret2 = xmlNodeDump(buf, teidoc, n, 0, 1); g_assert(ret2 != -1); // XXX make textview1 global var to save lookups GtkTextView *textview1 = GTK_TEXT_VIEW(glade_xml_get_widget(my_glade_xml, "textview1")); GtkTextBuffer* b = gtk_text_view_get_buffer(textview1); gtk_text_buffer_set_text(b, (char *) xmlBufferContent(buf), -1); xmlBufferFree(buf); gtk_text_buffer_set_modified(b, FALSE); // XXX make sure notebook1 shows page 0 (XML view) }
string getXmlChildrenAsString(const xmlDocPtr xmlDoc, const xmlNodePtr& xmlNode) { string s; xmlBufferPtr pBuffer = xmlBufferCreate(); xmlNodeDump(pBuffer, xmlDoc, xmlNode, 0, 0); s = (const char *)xmlBufferContent(pBuffer); size_t StartPos = s.find('>')+1; size_t EndPos = s.rfind('<')-1; if (StartPos > EndPos) { s = ""; } else { s = s.substr(StartPos, EndPos-StartPos+1); } xmlBufferFree(pBuffer); return s; }
bool XMLWrapper::convertToString(const xmlChar *xmlText, std::string &text) { bool result = false; xmlBufferPtr in = xmlBufferCreateStatic((void*) xmlText, xmlStrlen(xmlText)); xmlBufferPtr out = xmlBufferCreate(); int ret = xmlCharEncOutFunc(mCharEncodingHandler, out, in); if (ret >= 0) { result = true; text = (char*) xmlBufferContent(out); } xmlBufferFree(in); xmlBufferFree(out); return result; }
void RL::Presentity::save (bool reload) { xmlBufferPtr buffer = xmlBufferCreate (); int result = xmlNodeDump (buffer, node->doc, node, 0, 0); if (result >= 0) { boost::shared_ptr<XCAP::Core> xcap = services.get<XCAP::Core> ("xcap-core"); xcap->write (path, "application/xcap-el+xml", (const char*)xmlBufferContent (buffer), boost::bind (&RL::Presentity::save_result, this, _1, reload)); } xmlBufferFree (buffer); }
bool CXmlTree::WriteXmlFileToString(cvs::string& string) const { xmlBufferPtr buffer = xmlBufferCreate(); if(!buffer) return false; xmlSaveCtxtPtr save = xmlSaveToBuffer(buffer, NULL, 0); if(!save) { xmlBufferFree(buffer); return false; } xmlSaveDoc(save, m_doc); xmlSaveFlush(save); xmlSaveClose(save); string = (const char*)xmlBufferContent(buffer); xmlBufferFree(buffer); return true; }
G_GNUC_INTERNAL char * gvir_config_xml_node_to_string(xmlNodePtr node) { xmlBufferPtr xmlbuf; char *xml; if (node == NULL) return NULL; xmlbuf = xmlBufferCreate(); if (xmlNodeDump(xmlbuf, node->doc, node, 0, 1) < 0) xml = NULL; else xml = g_strndup((gchar *)xmlBufferContent(xmlbuf), xmlBufferLength(xmlbuf)); xmlBufferFree(xmlbuf); return xml; }
GDALGMLJP2Expr GDALGMLJP2Expr::Evaluate(xmlXPathContextPtr pXPathCtx, xmlDocPtr pDoc) { switch( eType ) { case GDALGMLJP2ExprType::GDALGMLJP2Expr_XPATH: { xmlXPathObjectPtr pXPathObj = xmlXPathEvalExpression( reinterpret_cast<const xmlChar*>(osValue.c_str()), pXPathCtx); if( pXPathObj == nullptr ) return GDALGMLJP2Expr(""); // Add result of the evaluation. CPLString osXMLRes; if( pXPathObj->type == XPATH_STRING ) osXMLRes = reinterpret_cast<const char*>(pXPathObj->stringval); else if( pXPathObj->type == XPATH_BOOLEAN ) osXMLRes = pXPathObj->boolval ? "true" : "false"; else if( pXPathObj->type == XPATH_NUMBER ) osXMLRes = CPLSPrintf("%.16g", pXPathObj->floatval); else if( pXPathObj->type == XPATH_NODESET ) { xmlNodeSetPtr pNodes = pXPathObj->nodesetval; int nNodes = (pNodes) ? pNodes->nodeNr : 0; for(int i=0;i<nNodes;i++) { xmlNodePtr pCur = pNodes->nodeTab[i]; xmlBufferPtr pBuf = xmlBufferCreate(); xmlNodeDump(pBuf, pDoc, pCur, 2, 1); osXMLRes += reinterpret_cast<const char*>(xmlBufferContent(pBuf)); xmlBufferFree(pBuf); } } xmlXPathFreeObject(pXPathObj); return GDALGMLJP2Expr(osXMLRes); } default: CPLAssert(false); return GDALGMLJP2Expr(""); } }
std::string rss_parser::get_xml_content(xmlNode * node) { xmlBufferPtr buf = xmlBufferCreate(); std::string result; if (node->children) { for (xmlNodePtr ptr = node->children; ptr != NULL; ptr = ptr->next) { if (xmlNodeDump(buf, doc, ptr, 0, 0) >= 0) { result.append((const char *)xmlBufferContent(buf)); xmlBufferEmpty(buf); } else { result.append(get_content(ptr)); } } } else { result = get_content(node); // fallback } xmlBufferFree(buf); return result; }
xmlChar* PmmFastDecodeString( int charset, const xmlChar *string, const xmlChar *encoding) { xmlCharEncodingHandlerPtr coder = NULL; xmlChar *retval = NULL; xmlBufferPtr in = NULL, out = NULL; if ( charset == XML_CHAR_ENCODING_UTF8 ) { return xmlStrdup( string ); } else if ( charset == XML_CHAR_ENCODING_ERROR ) { coder = xmlFindCharEncodingHandler( (const char *) encoding ); } else if ( charset == XML_CHAR_ENCODING_NONE ) { xs_warn("PmmFastDecodeString: no encoding found\n"); } else { coder= xmlGetCharEncodingHandler( charset ); } if ( coder != NULL ) { /* warn( "do encoding %s", string ); */ in = xmlBufferCreate(); out = xmlBufferCreate(); xmlBufferCat( in, string ); if ( xmlCharEncOutFunc( coder, out, in ) >= 0 ) { retval = xmlCharStrndup((const char *)xmlBufferContent(out), xmlBufferLength(out)); } else { xs_warn("PmmFastEncodeString: decoding error\n"); } xmlBufferFree( in ); xmlBufferFree( out ); xmlCharEncCloseFunc( coder ); } return retval; }
bool XMLWrapper::convertFromString(const char *text, xmlChar *&xmlText) { bool result = false; xmlBufferPtr in = xmlBufferCreateStatic((void*) text, strlen(text)); xmlBufferPtr out = xmlBufferCreate(); int ret = xmlCharEncInFunc(mCharEncodingHandler, out, in); if (ret >= 0) { result = true; #if LIBXML_VERSION >= 20800 xmlText = xmlBufferDetach(out); #else xmlText = xmlStrdup(xmlBufferContent(out)); #endif } xmlBufferFree(in); xmlBufferFree(out); return result; }