Example #1
0
/* only change the menory */
int ermXmlSetString(erManifest *pCtx, const char *express, const char *pData)
{
    xmlXPathObjectPtr xpathObj = LocateTo(express, pCtx);
    if (NULL == xpathObj)
        return RET_ERR;

    xmlNodeSetPtr nodes = xpathObj->nodesetval;

    /* MvdW: we need to encode special chars in the input */
    xmlChar *xmlString = xmlEncodeSpecialChars(pCtx->pDoc, (xmlChar *) pData);

    if (nodes && nodes->nodeTab[0])
    {
        xmlNodeSetContent(nodes->nodeTab[0], xmlString);
        xmlFree(xmlString);

        /* See http://www.xmlsoft.org/examples/xpath2.c for detail */
        if (nodes->nodeTab[0]->type != XML_NAMESPACE_DECL)
            nodes->nodeTab[0] = NULL;
        xmlXPathFreeObject(xpathObj);
        return RET_OK;
    }
    xmlXPathFreeObject(xpathObj);
    return RET_ERR;
}
Example #2
0
static void
update_string(xmlDocPtr doc, xmlNodePtr dest, const xmlChar* newstr)
{
    /* TODO: do we need xmlEncodeEntitiesReentrant() too/instead? */
    xmlChar* string = xmlEncodeSpecialChars(doc, newstr);
    xmlNodeSetContent(dest, string);
    xmlFree(string);
}
Example #3
0
File: utils.c Project: rosedu/osmo
void
utl_xml_put_str (gchar *name, gchar *string, xmlNodePtr node, xmlDocPtr doc)
{
	xmlChar *escaped;

	escaped = xmlEncodeSpecialChars(doc, (const xmlChar *) string);
	xmlNewTextChild (node, NULL, (const xmlChar *) name, (xmlChar *) escaped);
	xmlFree (escaped);
}
xmlChar* CWidgetBackupRegistryXml::EncodeStringL(xmlDocPtr aDoc, xmlChar* aStringToConvert)
    {
    xmlChar* noEntitiesContent = xmlEncodeSpecialChars(aDoc, aStringToConvert);
    if ( NULL == noEntitiesContent )
        {
        User::Leave( OOM_FLAG ? KErrNoMemory : KErrCorrupt );
        }
    return noEntitiesContent;
    }
Example #5
0
File: utils.c Project: rosedu/osmo
void
utl_xml_put_char (gchar *name, gchar character, xmlNodePtr node, xmlDocPtr doc)
{
	gchar buffer[32];
	xmlChar *escaped;

	g_snprintf (buffer, 32, "%c", character);
	escaped = xmlEncodeSpecialChars(doc, (const xmlChar *) buffer);
	xmlNewTextChild (node, NULL, (const xmlChar *) name, (xmlChar *) escaped);
	xmlFree (escaped);
}
Example #6
0
/*
 * call-seq:
 *    node.content = "string"
 *
 * Set this node's content to the specified string.
 */
static VALUE rxml_node_content_set(VALUE self, VALUE content)
{
  xmlNodePtr xnode;
  xmlChar* encoded_content;

  Check_Type(content, T_STRING);
  xnode = rxml_get_xnode(self);
  encoded_content = xmlEncodeSpecialChars(xnode->doc, (xmlChar*) StringValuePtr(content));
  xmlNodeSetContent(xnode, encoded_content);
  return (Qtrue);
}
Example #7
0
 XMLNode& XMLNode::operator=(const char *content) {
   if (!node_)
     return *this;
   if (!content)
     content = "";
   xmlChar *encode = xmlEncodeSpecialChars(node_->doc, (xmlChar*)content);
   if (!encode)
     encode = (xmlChar*)"";
   xmlNodeSetContent(node_, encode);
   xmlFree(encode);
   return *this;
 }
Example #8
0
File: utils.c Project: rosedu/osmo
void
utl_xml_put_strn (gchar *name, gchar *string, gint buffer_size, xmlNodePtr node, xmlDocPtr doc)
{
	gchar buffer[BUFFER_SIZE];
	xmlChar *escaped;

	if (buffer_size > BUFFER_SIZE) buffer_size = BUFFER_SIZE;
	g_snprintf (buffer, buffer_size, "%s", string);
	escaped = xmlEncodeSpecialChars(doc, (const xmlChar *) buffer);
	xmlNewTextChild (node, NULL, (const xmlChar *) name, (xmlChar *) escaped);
	xmlFree (escaped);
}
Example #9
0
/*
 * call-seq:
 *  encode_special_chars(string)
 *
 * Encode any special characters in +string+
 */
static VALUE encode_special_chars(VALUE self, VALUE string)
{
  xmlNodePtr node;
  Data_Get_Struct(self, xmlNode, node);
  xmlChar * encoded = xmlEncodeSpecialChars(
      node->doc,
      (const xmlChar *)StringValuePtr(string)
  );

  VALUE encoded_str = rb_str_new2((const char *)encoded);
  xmlFree(encoded);

  return encoded_str;
}
Example #10
0
void xmlSetContent(void *n, char *content) {
	xmlNode *node = (xmlNode*)n;
	xmlNode *child = node->children;
	xmlNode *next = NULL;
	unsigned char *encoded = xmlEncodeSpecialChars(node->doc, (xmlChar*)content);
	if (encoded) {
		while (child) {
			next = child->next ;
			xmlUnlinkNode(child);
			//xmlFreeNode(child);
			xmlUnlinkNodeCallback(child);
			child = next ;
	  	}
	  	xmlNodeSetContent(node, (xmlChar*)encoded);
		xmlFree(encoded);
	}
}
Example #11
0
/*
 * call-seq:
 *  encode_special_chars(string)
 *
 * Encode any special characters in +string+
 */
static VALUE encode_special_chars(VALUE self, VALUE string)
{
  xmlNodePtr node;
  xmlChar *encoded;
  VALUE encoded_str;

  Data_Get_Struct(self, xmlNode, node);
  encoded = xmlEncodeSpecialChars(
      node->doc,
      (const xmlChar *)StringValuePtr(string)
  );

  encoded_str = NOKOGIRI_STR_NEW2(encoded);
  xmlFree(encoded);

  return encoded_str;
}
/**
 * gupnp_didl_lite_create_class_set_content:
 * @create_class: #GUPnPDIDLLiteCreateClass
 * @content: The content
 *
 * Set the content of the @create_class.
 **/
void
gupnp_didl_lite_create_class_set_content
                                    (GUPnPDIDLLiteCreateClass *create_class,
                                     const char               *content)
{
        xmlChar *escaped;

        g_return_if_fail (GUPNP_IS_DIDL_LITE_CREATE_CLASS (create_class));
        g_return_if_fail (create_class != NULL);

        escaped = xmlEncodeSpecialChars (create_class->priv->xml_doc->doc,
                                         (const unsigned char *) content);
        xmlNodeSetContent (create_class->priv->xml_node, escaped);
        xmlFree (escaped);

        g_object_notify (G_OBJECT (create_class), "content");
}
Example #13
0
static void my_characters(void* user_data, const xmlChar* ch, int len) {
    MwsHarvest_SaxUserData* data = (MwsHarvest_SaxUserData*)user_data;

    if (data->state == MWSHARVESTSTATE_IN_MWS_EXPR &&  // Valid state
        data->currentToken != nullptr) {               // Valid token
        data->currentToken->appendTextContent((char*)ch, len);
    }

    if (data->state == MWSHARVESTSTATE_IN_MWS_DATA) {
        string inputChars((const char*)ch, len);
        xmlChar* encodedChars =
            xmlEncodeSpecialChars(nullptr, BAD_CAST inputChars.c_str());
        assert(encodedChars != nullptr);
        xmlTextWriterWriteRawLen(data->stringWriter, encodedChars,
                                 strlen((const char*)encodedChars));
        xmlFree(encodedChars);
    }
}
HBufC* CWidgetBackupRegistryXml::EncodeStringL(xmlDocPtr aDoc, TPtrC aStringToConvert, RFs& aFileSession)
    {
    HBufC8* out = NULL;
    FromUnicodeL( KCharacterSetIdentifierUtf8, 2, aStringToConvert, &out, aFileSession );
    CleanupStack::PushL(out);
    xmlChar* noEntitiesContent = xmlEncodeSpecialChars(aDoc, out->Des().Ptr());
    if ( NULL == noEntitiesContent )
        {
        User::Leave( OOM_FLAG ? KErrNoMemory : KErrCorrupt );
        }
    CleanupStack::PushL( noEntitiesContent );
    TPtrC8 noEntitiesPtr(noEntitiesContent);
    HBufC* noEntitiesBuf = NULL;
    noEntitiesBuf = HBufC::NewL(noEntitiesPtr.Length());
    noEntitiesBuf->Des().Copy(noEntitiesPtr);
    CleanupStack::PopAndDestroy(2, out); // out, noEntitiesContent

    return noEntitiesBuf;
    }
Example #15
0
Datum
xml_encode_special_chars(PG_FUNCTION_ARGS)
{
	text	   *tin = PG_GETARG_TEXT_P(0);
	text	   *tout;
	xmlChar    *ts,
			   *tt;

	ts = pgxml_texttoxmlchar(tin);

	tt = xmlEncodeSpecialChars(NULL, ts);

	pfree(ts);

	tout = cstring_to_text((char *) tt);

	xmlFree(tt);

	PG_RETURN_TEXT_P(tout);
}
Example #16
0
/* Create a new element with string value */
int ermXmlNewString(const erManifest *pCtx, const char *parentExpress, const char *name, const char *content)
{
    xmlXPathObjectPtr xpathObj = LocateTo(parentExpress, pCtx);
    if (NULL == xpathObj)
        return RET_ERR;

    xmlNodeSetPtr nodes = xpathObj->nodesetval;

    /* MvdW: we need to encode special chars in the input */
    xmlChar *xmlString = xmlEncodeSpecialChars(pCtx->pDoc, (xmlChar *) content);

    if (nodes && nodes->nodeTab[0])
    {
        /*xmlNodePtr node = */ xmlNewChild(nodes->nodeTab[0],
                                           NULL, BAD_CAST name, // MvdW: this should ALSO be encoded!
                                           xmlString);
        xmlFree(xmlString);
        xmlXPathFreeObject(xpathObj);
        return RET_OK;
    }
    xmlXPathFreeObject(xpathObj);
    return RET_ERR;
}
Example #17
0
static HRESULT node_set_content_escaped(xmlnode *This, LPCWSTR value)
{
    xmlChar *str, *escaped;

    TRACE("(%p)->(%s)\n", This, debugstr_w(value));
    str = xmlchar_from_wchar(value);
    if(!str)
        return E_OUTOFMEMORY;

    escaped = xmlEncodeSpecialChars(NULL, str);
    if(!escaped)
    {
        heap_free(str);
        return E_OUTOFMEMORY;
    }

    xmlNodeSetContent(This->node, escaped);

    heap_free(str);
    xmlFree(escaped);

    return S_OK;
}
Example #18
0
Datum
xml_encode_special_chars(PG_FUNCTION_ARGS)
{
	text	   *tin = PG_GETARG_TEXT_P(0);
	text	   *tout;
	int32		ressize;
	xmlChar    *ts,
			   *tt;

	ts = pgxml_texttoxmlchar(tin);

	tt = xmlEncodeSpecialChars(NULL, ts);

	pfree(ts);

	ressize = strlen(tt);
	tout = (text *) palloc(ressize + VARHDRSZ);
	memcpy(VARDATA(tout), tt, ressize);
	VARATT_SIZEP(tout) = ressize + VARHDRSZ;

	xmlFree(tt);

	PG_RETURN_TEXT_P(tout);
}