Exemple #1
0
extern "C" const char* XMLNodeDocumentStringConst(std::shared_ptr<const ePub3::xml::Node> aNode)
{
    xmlChar* s = nullptr;
    int ssize = 0;
    xmlDocDumpFormatMemory(aNode->Document()->xml(), &s, &ssize, 1);
    return reinterpret_cast<char*>(s);
}
Exemple #2
0
gboolean
mrp_parser_to_xml (MrpStorageMrproject  *module,
		   gchar               **str,
		   GError              **error)
{
	xmlDocPtr  doc;
	xmlChar   *buf;
	int        len;

	g_return_val_if_fail (MRP_IS_STORAGE_MRPROJECT (module), FALSE);

	doc = parser_build_xml_doc (module, error);
	if (!doc) {
		return FALSE;
	}

	xmlDocDumpFormatMemory (doc, &buf, &len, 1);
	xmlFreeDoc (doc);

	*str = g_strdup (buf);
	xmlFree (buf);

	if (len <= 0) {
		g_set_error (error,
			     MRP_ERROR,
			     MRP_ERROR_SAVE_WRITE_FAILED,
			     _("Could not create XML tree"));

		return FALSE;
	}

	return TRUE;
}
Exemple #3
0
char *DomTree::dumpXmlStr() const {
	xmlDocPtr doc;
	xmlNodePtr cur;
	
	doc = xmlNewDoc((const xmlChar *)version.c_str());
	doc->children = xmlNewDocNode(doc, NULL,(const xmlChar *)name.c_str(), NULL);
	
	for(unsigned int i = 0; i < elements.size() ; i++) {
		cur = xmlNewChild(doc->children,NULL,(const xmlChar *)elements[i]->getName().c_str(),(xmlChar *)elements[i]->getValue().c_str());
		if(elements[i]->getAttributes().size() > 0) {
			for(unsigned int a = 0; a < elements[i]->getAttributes().size() ; a++) {
				xmlSetProp(cur,(const xmlChar *)elements[i]->getAttributes()[a]->getName().c_str(),(const xmlChar *)elements[i]->getAttributes()[a]->getValue().c_str());
			}
		}
		if ( elements[i]->getChildren().size() > 0 ) {	
			for(unsigned int b = 0; b < elements[i]->getChildren().size() ; b++) {
				dumpXmlChild(cur,elements[i]->getChildren()[b]);
			}
		}
	}
	
	xmlChar *output;
	int len;
	//len = sizeof(doc);
	xmlDocDumpFormatMemory(doc, &output, &len,1);
	
	xmlFreeDoc(doc);
	return((char *)output);
}
void saveCterms(CIndexer *indexer)
{
   CConnbas_dbox *connbas = indexer->connbas;
	xmlNodePtr root = xmlDocGetRootElement(indexer->DocCterms);
	char moddate[16];

	// date de maj
	time_t timer;
	time(&timer);
	struct tm *today;
	today = localtime(&timer);

	strftime((char *)moddate, 15, "%Y%m%d%H%M%S", today);

	xmlSetProp(root, (const xmlChar*)"modification_date", (const xmlChar *)moddate );

	xmlChar *out;
	int outsize;
	xmlKeepBlanksDefault(0);
	xmlDocDumpFormatMemory(indexer->DocCterms, &out, &outsize, 1);

	zSyslog._log(CSyslog::LOGL_THESAURUS, CSyslog::LOGC_THESAURUS, "#%d : CTERMS saved", connbas->sbas_id);

	connbas->updatePref_cterms((char *)out, outsize, moddate );

	xmlFree(out);

	indexer->current_cterms_moddate = timer;
}
Exemple #5
0
/*
 * a standard function to request the users roster
 * args:
 *    -> from - the jid of the user
 *    -> id - a unique ID which don't have a proper form
 */
char *requestRoster(char *from, char *id){
  if(!id || !from)
    return NULL;
  
  int buffersize = 0;
  xmlDocPtr doc = NULL;
  xmlNodePtr root_node = NULL, node = NULL;
  xmlChar *xmlbuff = NULL;

  doc = xmlNewDoc(BAD_CAST "1.0");
  root_node = xmlNewNode(NULL, BAD_CAST "iq");
  xmlDocSetRootElement(doc, root_node);
  xmlNewProp(root_node, BAD_CAST "xml:lang", BAD_CAST "en");
  xmlNewProp(root_node, BAD_CAST "from", BAD_CAST from);
  xmlNewProp(root_node, BAD_CAST "type", BAD_CAST "get");
  xmlNewProp(root_node, BAD_CAST "id", BAD_CAST id);
  node=xmlNewChild(root_node, NULL, BAD_CAST "query", NULL);
  xmlNewProp(node, BAD_CAST "xmlns", BAD_CAST XMLNS_ROSTER);

  xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1);
  xmlFreeDoc(doc);
  xmlCleanupParser();
  xmlMemoryDump();
  return (char *)xmlbuff;
}
Exemple #6
0
/*
 * a standard function to set roster items such as adding new participants
 * args:
 *    -> from - the jid of the user
 *    -> id - a unique ID which don't have a proper form
 *    -> jid - the jid of the participant
 *    -> name - the name which is displayed in the roster
 *    -> group - the group displayed in the roster
 */
char *setRoster(char *from, char *id, 
                char *jid, char *name, 
                char *group, int subscription){
  if(!from || !id || !jid)
    return NULL;
  int buffersize=0;
  xmlDocPtr doc = NULL;
  xmlNodePtr root_node=NULL, node=NULL, node2=NULL;
  xmlChar *xmlbuff = NULL;
  
  doc = xmlNewDoc(BAD_CAST "1.0");
  root_node = xmlNewNode(NULL, BAD_CAST "iq");
  xmlDocSetRootElement(doc, root_node);
  xmlNewProp(root_node, BAD_CAST "from", BAD_CAST from);
  xmlNewProp(root_node, BAD_CAST "type", BAD_CAST "set");
  xmlNewProp(root_node, BAD_CAST "id", BAD_CAST id);
  node=xmlNewChild(root_node, NULL, BAD_CAST "query", NULL);
  xmlNewProp(node, BAD_CAST "xmlns", BAD_CAST XMLNS_ROSTER);
  node2=xmlNewChild(node, NULL, BAD_CAST "item", NULL);
  xmlNewProp(node2, BAD_CAST "jid", BAD_CAST jid);
  if(name)
    xmlNewProp(node2, BAD_CAST "name", BAD_CAST name);
  if(group)
    xmlNewChild(node2, NULL, BAD_CAST "group", BAD_CAST group);

  xmlDocDumpFormatMemory(doc,&xmlbuff,&buffersize,1);
  xmlFreeDoc(doc);
  xmlCleanupParser();
  xmlMemoryDump();
  return (char *)xmlbuff;
}
Exemple #7
0
int _sendXmlToFd(int sockfd, xmlDocPtr xml) {
	int res = -1;    
	xmlChar *xmlbuff;
	int buffersize;

	xmlDocDumpFormatMemory(xml, &xmlbuff, &buffersize, 1);
	res = write(sockfd,xmlbuff, buffersize);
	xmlFree(xmlbuff);
	return res;
	/*
	xmlSaveCtxtPtr saveCtxt = NULL;
	saveCtxt = xmlSaveToFd(sockfd, NULL, 0);
	if (saveCtxt == NULL) {
		return -1;
	}
	res = xmlSaveDoc(saveCtxt, xml);
	 */
	/* NOTE libxml2 API states that this can only return 0 (succeed) or -1 (fail) at the moment, 
		but will return the number of bytes when succesfull later */
	/*
	 if (res < 0) {
		xmlFree(saveCtxt);
		return -2;
	}
	xmlSaveClose(saveCtxt);
	return 0;
	 */
}
static void
gss_config_append_config_file (GString * s)
{
  GList *g;
  xmlNsPtr ns;
  xmlDocPtr doc;

  doc = xmlNewDoc ((xmlChar *) "1.0");

  doc->xmlRootNode = xmlNewDocNode (doc, NULL, (xmlChar *) "oberon", NULL);
  ns = xmlNewNs (doc->xmlRootNode,
      (xmlChar *) "http://entropywave.com/oberon/1.0/", (xmlChar *) "ew");

  for (g = config_list; g; g = g_list_next (g)) {
    GObject *object = g->data;

    gss_config_dump_object (object, ns, doc->xmlRootNode);
  }

  {
    xmlChar *str;
    int len;
    xmlDocDumpFormatMemory (doc, &str, &len, 1);
    g_string_append (s, (char *) str);
    xmlFree (str);
  }

  xmlFreeDoc (doc);
}
void xml_parser_doc_dump_memory(WsXmlDocH doc, char **buf, int *ptrSize)
{

	xmlDocPtr d = (xmlDocPtr) doc->parserDoc;
	xmlDocDumpFormatMemory(d, (xmlChar **) buf, ptrSize, 1);
	return;
}
Exemple #10
0
int gtodo_client_save_xml_to_file(GTodoClient *cl, GFile *file, GError **error)
{
	xmlChar *buffer;
	GError *tmp_error = NULL;
	int size;

	/* Test if there is actually a client to save */
	if(cl == NULL)
	{
		g_set_error(&tmp_error,LIBGTODO_ERROR,LIBGTODO_ERROR_GENERIC,_("No Gtodo Client to save.") );
		g_propagate_error(error, tmp_error);
		return TRUE;
	}
	/* dump the xml to memory */
	/* xmlIndentTreeOutput = 1; */
	xmlKeepBlanksDefault(0);
	xmlDocDumpFormatMemory(cl->gtodo_doc, &buffer, &size, TRUE);

	if (!g_file_replace_contents (file, 
			(char *)buffer, size, 
			NULL, FALSE, G_FILE_CREATE_NONE, 
			NULL, NULL, &tmp_error))
	{
		g_propagate_error(error, tmp_error);
		xmlFree(buffer);
		return TRUE;
	}

	xmlFree(buffer);
	/* return that everything is ok */
	return FALSE;
}
Exemple #11
0
void saveCterms(CIndexer *indexer)
{
  CConnbas_dbox *connbas = indexer->connbas;
	xmlNodePtr root = xmlDocGetRootElement(indexer->DocCterms);
	char moddate[16];
	
	// date de m�j
	time_t timer;
	time(&timer);
	struct tm *today;
	today = localtime(&timer);

	strftime((char *)moddate, 15, "%Y%m%d%H%M%S", today);

	xmlSetProp(root, (const xmlChar*)"modification_date", (const xmlChar *)moddate );

	xmlChar *out;
	int outsize;
	xmlKeepBlanksDefault(0);
	xmlDocDumpFormatMemory(indexer->DocCterms, &out, &outsize, 1);

//	zSyslog.log(CSyslog::LOG_INFO, "\n/=================================== Saving CTERMS =========================");
//	zSyslog.log(CSyslog::LOG_INFO, "root = %s", root->name);
//	for(int i=0; i<outsize && i<300; i++)
//	{
//		putchar(out[i]);
//	}
	zSyslog.log(CSyslog::LOGL_INFO, CSyslog::LOGC_THESAURUS, "#%d : CTERMS saved", connbas->sbas_id);

	connbas->updatePref_cterms((char *)out, outsize, moddate );

	xmlFree(out);

	indexer->current_cterms_moddate = timer;
}
Exemple #12
0
ssize_t XMLMetadata::getRaw(unsigned char *buf, size_t len)
{
	int xmlLen;
	xmlChar *xml;

	if (!buf)
		return -1;

	memset(buf, 0, len);

        if (!createXMLDoc())
                return false;

	xmlDocDumpFormatMemory(doc, &xml, &xmlLen, 1);

        xmlFreeDoc(doc);
	doc = NULL;

        if (xmlLen < 0)
                return -2;
        
	if ((unsigned int) xmlLen > len) {
		xmlFree(xml);
		return -3;
	}
        
	memcpy(buf, xml, xmlLen);

	xmlFree(xml);

	return xmlLen;
}
Exemple #13
0
int reginfo_process_body(publ_info_t* publ, str** fin_body, int ver, str** tuple)
{
	xmlNodePtr node= NULL;
	xmlDocPtr doc= NULL;
	char* version;
	str* body= NULL;
	int len;
	str* init_body;

	init_body= publ->body;

	doc= xmlParseMemory(init_body->s, init_body->len );
	if(doc== NULL) {
		LM_ERR("while parsing xml memory\n");
		goto error;
	}
	/* change version and state*/
	node= xmlDocGetNodeByName(doc, "reginfo", NULL);
	if(node == NULL) {
		LM_ERR("while extracting dialog-info node\n");
		goto error;
	}
	version= int2str(ver,&len);
	version[len]= '\0';

	if( xmlSetProp(node, (const xmlChar *)"version",(const xmlChar*)version)== NULL) {
		LM_ERR("while setting version attribute\n");
		goto error;	
	}
	body= (str*)pkg_malloc(sizeof(str));
	if(body== NULL) {
		LM_ERR("NO more memory left\n");
		goto error;
	}
	memset(body, 0, sizeof(str));
	xmlDocDumpFormatMemory(doc, (xmlChar**)(void*)&body->s, &body->len, 1);	

	xmlFreeDoc(doc);
	doc= NULL;
	*fin_body= body;	
	if(*fin_body== NULL)
		LM_DBG("NULL fin_body\n");

	xmlMemoryDump();
	xmlCleanupParser();
	LM_DBG("successful\n");
	return 1;

error:
	if(doc)
		xmlFreeDoc(doc);
	if(body)
		pkg_free(body);
	
	xmlMemoryDump();
	xmlCleanupParser();
	return -1;
}
Exemple #14
0
const std::string XMLDocument::dump(bool indent) const
{
    xmlChar *buffer = 0;
    int size = 0;
    xmlDocDumpFormatMemory(document, &buffer, &size, indent ? 1 : 0);
    std::string str((const char *)buffer);
    xmlFree(buffer);

    return str;
}
Exemple #15
0
void EB_Msg_toBuffer(EB_MSG *m, GWEN_BUFFER *buf) {
  xmlChar *xmlbuff;
  int buffersize;

  assert(m);
  assert(m->usage);
  xmlDocDumpFormatMemory(m->doc, &xmlbuff, &buffersize, 0);
  GWEN_Buffer_AppendBytes(buf, (const char*)xmlbuff, (uint32_t)buffersize);
  xmlFree(xmlbuff);
}
Exemple #16
0
int DEFAULT_CC
xml_send_error(int client, const char* message)
{
	xmlChar* xmlbuff;
	xmlDocPtr doc;
	xmlNodePtr node;
	struct stream* s;
	int buff_size, size;
	xmlChar* version;
	xmlChar* error;
	xmlChar* msg;


	version = xmlCharStrdup("1.0");
	doc = xmlNewDoc(version);
	if (doc == NULL)
	{
		log_message(&(g_cfg->log), LOG_LEVEL_WARNING, "sesman[xml_send_error]: "
				"Unable to create the document");
		xmlFree(version);
		return 0;
	}
	error = xmlCharStrdup("error");
	msg = xmlCharStrdup(message);
	doc->encoding = xmlCharStrdup("UTF-8");
	node = xmlNewNode(NULL, error);
	xmlNodeSetContent(node, msg);
	xmlDocSetRootElement(doc, node);

	xmlDocDumpFormatMemory(doc, &xmlbuff, &buff_size, 1);
	log_message(&(g_cfg->log), LOG_LEVEL_WARNING, "sesman[xml_send_error]: "
			"data send : %s",xmlbuff);

	make_stream(s);
	init_stream(s, buff_size + 6);
	out_uint32_be(s,buff_size);
	out_uint8p(s, xmlbuff, buff_size)
	size = s->p - s->data;
	if (g_tcp_can_send(client, 10))
	{
		buff_size = g_tcp_send(client, s->data, size, 0);
	}
	else
	{
		log_message(&(g_cfg->log), LOG_LEVEL_DEBUG_PLUS, "sesman[xml_send_error]: "
				"Unable to send xml response: %s, cause: %s", xmlbuff, strerror(g_get_errno()));
	}
	free_stream(s);
	xmlFreeDoc(doc);
	xmlFree(xmlbuff);
	xmlFree(version);
	xmlFree(error);
	xmlFree(msg);
	return buff_size;
}
Exemple #17
0
int cmd_print(const char* arg) {
	char* ptr, *argv;
	xmlDocPtr doc;
	struct ncds_ds_list* ds;
	struct model_list* model;

	argv = strdupa(arg);
	strtok(argv, " ");
	ptr = strtok(NULL, " ");

	if (ptr == NULL) {
		ds = ncds.datastores;
		model = models_list;

		printf("Datastores:\n");
		if (ds == NULL) {
			printf("\tnone\n");
		}
		for (; ds != NULL; ds = ds->next) {
			printf("\t%s\n", ds->datastore->data_model->name);
		}

		printf("Models:\n");
		if (model == NULL) {
			printf("\tnone\n");
		}
		for (; model != NULL; model = model->next) {
			printf("\t%s\n", model->model->name);
		}
	} else {
		char* buf = NULL;
		int buf_len = 0;

		ds = find_datastore(ptr);
		if (ds == NULL) {
			model = find_model(ptr);
			if (model == NULL) {
				nc_verb_error("No datastore or model \"%s\" found", ptr);
				return 1;
			} else {
				doc = model->model->xml;
			}
		} else {
			doc = ds->datastore->ext_model;
		}

		xmlDocDumpFormatMemory(doc, (xmlChar**)&buf, &buf_len, 1);
		fwrite(buf, 1, buf_len, stdout);
		free(buf);
	}

	return 0;
}
Exemple #18
0
void XmlMemWriter::write(const Document &doc, void **ppvBuf, size_t *pcbSize)
{
    if (m_pBuf)
    {
        xmlFree(m_pBuf);
        m_pBuf = 0;
    }
    int size;
    xmlDocDumpFormatMemory(doc.m->plibDocument, (xmlChar**)&m_pBuf, &size, 1);
    *ppvBuf = m_pBuf;
    *pcbSize = size;
}
Exemple #19
0
static int convert_xslt(void *vinfo, WRBUF record, WRBUF wr_error)
{
    int ret = 0;
    struct xslt_info *info = vinfo;

    xmlDocPtr doc = xmlParseMemory(wrbuf_buf(record),
                                   wrbuf_len(record));
    if (!doc)
    {
        wrbuf_printf(wr_error, "xmlParseMemory failed");
        ret = -1;
    }
    else
    {
        xmlDocPtr xsp_doc = xmlCopyDoc(info->xsp_doc, 1);
        xsltStylesheetPtr xsp = xsltParseStylesheetDoc(xsp_doc);
        xmlDocPtr res = xsltApplyStylesheet(xsp, doc, info->xsl_parms);
        if (res)
        {
            xmlChar *out_buf = 0;
            int out_len;

#if HAVE_XSLTSAVERESULTTOSTRING
            xsltSaveResultToString(&out_buf, &out_len, res, xsp);
#else
            xmlDocDumpFormatMemory (res, &out_buf, &out_len, 1);
#endif
            if (!out_buf)
            {
                wrbuf_printf(wr_error,
                             "xsltSaveResultToString failed");
                ret = -1;
            }
            else
            {
                wrbuf_rewind(record);
                wrbuf_write(record, (const char *) out_buf, out_len);

                xmlFree(out_buf);
            }
            xmlFreeDoc(res);
        }
        else
        {
            wrbuf_printf(wr_error, "xsltApplyStylesheet failed");
            ret = -1;
        }
        xmlFreeDoc(doc);
        xsltFreeStylesheet(xsp); /* frees xsp_doc too */
    }
    return ret;
}
Exemple #20
0
/* This prints an XML document to a XMPP server */
void xmpp_xml_send(struct xmpp_server *xs, xmlDocPtr doc)
{
	xmlChar    *xmlbuf;
	int        buffer_size;

	xmlDocDumpFormatMemory(doc, &xmlbuf, &buffer_size, 0);

	printf("Sending XML Packet: %s\n",xmlbuf);
	send(xs->sock,xmlbuf,buffer_size, 0);
	send(xs->sock,"\n",1, 0);

	xmlFree(xmlbuf);
	return;
}
Exemple #21
0
int DEFAULT_CC
xml_send_info(int client, xmlDocPtr doc)
{
	xmlChar* xmlbuff;
	int buff_size, size;
	struct stream* s;

	xmlDocDumpFormatMemory(doc, &xmlbuff, &buff_size, 1);
	log_message(&(g_cfg->log), LOG_LEVEL_DEBUG_PLUS, "sesman[xml_send_info]: "
			"data send : %s\n",xmlbuff);

	make_stream(s);
	init_stream(s, buff_size + 6);
	out_uint32_be(s,buff_size);
	out_uint8p(s, xmlbuff, buff_size)
	size = s->p - s->data;
	if (g_tcp_can_send(client, 10))
	{
		int sended = 0;
		int send = 0;
		while(sended < size)
		{
			send = (size-sended) > 2048 ? 2048 : size-sended;
			sended += g_tcp_send(client, s->data+sended, send, 0);
			if (sended < size)
			{
				if (g_get_errno() != 0)
				{
					log_message(&(g_cfg->log), LOG_LEVEL_DEBUG_PLUS, "sesman[xml_send_info]: "
							"Error while send %s\n",g_get_strerror());
					goto end;
				}
			}
		}
		if (sended != size)
		{
			log_message(&(g_cfg->log), LOG_LEVEL_DEBUG_PLUS, "sesman[xml_send_info]: "
					"Error while sending data %i != %i\n",sended, size);
		}
	}
	else
	{
		log_message(&(g_cfg->log), LOG_LEVEL_DEBUG_PLUS, "sesman[xml_send_info]: "
				"Unable to send xml response: %s, cause: %s", xmlbuff, strerror(g_get_errno()));
	}
end:
	free_stream(s);
	xmlFree(xmlbuff);
	return buff_size;
}
Exemple #22
0
char *xmldoc_tostring(struct xmldoc *doc)
{
	char *result = NULL;
	assert(doc != NULL);
#ifdef HAVE_LIBUPNP
	result = ixmlDocumenttoString(doc->doc);
#else
#ifdef HAVE_LIBXML
	int buffersize;
	xmlDocDumpFormatMemory(doc->doc, (xmlChar **)&result, &buffersize, 1);
#endif
#endif
	return result;
}
Exemple #23
0
static int uwsgi_rpc_xmlrpc(struct wsgi_request *wsgi_req, xmlDoc *doc, char **argv, uint16_t *argvs, uint8_t *argc, char *response_buf) {
	char *method = NULL;
	xmlNode *element = xmlDocGetRootElement(doc);
        if (!element) return -1;

        if (strcmp((char *) element->name, "methodCall")) return -1;

	*argc = 0;
	xmlNode *node;
        for (node = element->children; node; node = node->next) {
                if (node->type == XML_ELEMENT_NODE) {
                	if (!strcmp((char *) node->name, "methodName") && node->children) {
				method = (char *) node->children->content;
			}
			else if (!strcmp((char *) node->name, "params")) {
				if (uwsgi_rpc_xmlrpc_args(node, argv, argvs, argc)) return -1;	
			}
                }
        }

	if (!method) return -1;
	wsgi_req->uh->pktsize = uwsgi_rpc(method, *argc, argv+1, argvs+1, response_buf);

	if (!wsgi_req->uh->pktsize) return -1;
	if (wsgi_req->uh->pktsize == UMAX16-1) return -1;
	// add final NULL byte
	response_buf[wsgi_req->uh->pktsize] = 0;

	xmlDoc *rdoc = xmlNewDoc(BAD_CAST "1.0");
        xmlNode *m_response = xmlNewNode(NULL, BAD_CAST "methodResponse");
        xmlDocSetRootElement(rdoc, m_response);
	xmlNode *x_params = xmlNewChild(m_response, NULL, BAD_CAST "params", NULL);
	xmlNode *x_param = xmlNewChild(x_params, NULL, BAD_CAST "param", NULL);
	xmlNode *x_value = xmlNewChild(x_param, NULL, BAD_CAST "value", NULL);
        xmlNewTextChild(x_value, NULL, BAD_CAST "string", BAD_CAST response_buf);
	
	xmlChar *xmlbuf;
        int xlen = 0;
        xmlDocDumpFormatMemory(rdoc, &xmlbuf, &xlen, 1);
	uwsgi_response_prepare_headers(wsgi_req,"200 OK", 6);
        uwsgi_response_add_content_length(wsgi_req, xlen);
        uwsgi_response_add_content_type(wsgi_req, "application/xml", 15);
        uwsgi_response_write_body_do(wsgi_req, (char *) xmlbuf, xlen);

	xmlFreeDoc(rdoc);
	xmlFree(xmlbuf);

	return 0;
}
Exemple #24
0
bool XMLFile::Save( const string& filename ) {
	LogMsg(INFO, "Saving XML File '%s'.",filename.c_str() );

	xmlChar *xmlbuff;
	int buffersize;
	xmlDocDumpFormatMemory( xmlPtr, &xmlbuff, &buffersize, 1 );
	File saved = File( filename.c_str(), true );
	if(saved.Write( (char *)xmlbuff, buffersize ) != true) {
		LogMsg(ERR, "Could not save XML\n");
	}
	xmlFree(xmlbuff);

	//xmlSaveFormatFileEnc( filename.c_str(), xmlPtr, "ISO-8859-1", 1);
	return true;
}
Exemple #25
0
int SXmlDocument::SaveToString(std::string &str)
{	
	xmlChar *xmlbuff=NULL;
	int buffersize;
	std::string output="";

	if (!_doc)
		return -1;
	int ret=0;
	xmlDocDumpFormatMemory(_doc, &xmlbuff, &buffersize, 1);
	if(!xmlbuff){
		return -1;
	}
	char * buf = (char *)xmlbuff;
	for (int i=0;i<buffersize;i++)
		output += buf[i];
	
	
	//WEBSEARCH_DEBUG((LM_ERROR, "SXmlDocument::SaveToString : %s\n",output.c_str()));
	if (_encoding == "utf-16"){	

		ret = ChangeEncodeDeclaration(output,output,"utf-8","utf-16");		
		ret = utf8_to_utf16(output,output);
		if (ret<0){
			xmlFree(xmlbuff);
			return -1;
		}
			
	}else if (_encoding == "gbk"){
		
		ret = utf8_to_gbk(output,output);
		
		if (ret < 0){
			xmlFree(xmlbuff);
			return -1;
		}
		ret = ChangeEncodeDeclaration(output,output,"utf-8","gbk");		
		//WEBSEARCH_DEBUG((LM_ERROR, "SXmlDocument::SaveToString : %s\n",_encoding.c_str()));
	}else if (_encoding == "utf-8"){

	}else{
	}
	
	str = output;
	xmlFree(xmlbuff);
	
	return 0;
}
Exemple #26
0
/*------------------------------------------------------------------------------*/
static void
cluster_getparam(int thr_nb, void *data, cl_error_desc_t *err_desc)
{
  xmlDocPtr doc = NULL;
  xmlNodePtr exanodes_node;
  int ret;

  exalog_debug("getparam");

  /* Create XML document */

  doc = xmlNewDoc(BAD_CAST("1.0"));
  if (doc == NULL)
  {
    set_error(err_desc, -EXA_ERR_XML_INIT, "Failed to create result document");
    return;
  }

  exanodes_node = xmlNewNode(NULL, BAD_CAST("Exanodes"));
  if (exanodes_node == NULL)
  {
    set_error(err_desc, -EXA_ERR_XML_INIT,
	      "Failed to create node in result document");
    xmlFreeDoc(doc);
    return;
  }

  xmlDocSetRootElement(doc, exanodes_node);


  ret = build_response(exanodes_node);

  if (ret ==  EXA_SUCCESS)
    {
      xmlChar *xmlchar_doc;
      int buf_size;

      xmlDocDumpFormatMemory(doc, &xmlchar_doc, &buf_size, 1);

      send_payload_str((char *)xmlchar_doc);

      xmlFree(xmlchar_doc);
    }

  xmlFreeDoc(doc);

  set_error(err_desc, ret, NULL);
}
char* createRequestBody2(unsigned short ivid, connectionTp AEndTp, connectionTp ZEndTp)
{
    xmlNodePtr node1, node2;
    xmlDocPtr xmlDoc;
    xmlChar *xmlbuff;
    char auxBuff[100];
    char* retBuff;
    int buffersize, i;

    xmlDoc = xmlNewDoc(BAD_CAST "1.0");                                     //create document
    node1 = xmlNewNode(NULL, BAD_CAST "ns0:createAndActivateEvplRequest");
    xmlNewProp(node1, BAD_CAST "xmlns:xsi", BAD_CAST "http://www.w3.org/2001/XMLSchema-instance");
    xmlNewProp(node1, BAD_CAST "xmlns:ns0", BAD_CAST "http://www.intunenetworks.com/inx/mgmt/nsp/eth/v1");
    xmlNewProp(node1, BAD_CAST "xsi:schemaLocation", BAD_CAST "http://www.intunenetworks.com/inx/mgmt/nsp/eth/v1 ecs.xsd");

    xmlDocSetRootElement(xmlDoc, node1);
    node2 = xmlNewChild(node1, NULL, BAD_CAST "ns0:createEvplData", NULL);
    node1 = xmlNewChild(node2, NULL, BAD_CAST "ns0:evplServiceAttributeParameters", NULL);
    sprintf(auxBuff, "%d", ivid);
    xmlNewChild(node1, NULL, BAD_CAST "ns0:ivid", BAD_CAST auxBuff);

    node1 = xmlNewChild(node2, NULL, BAD_CAST "ns0:createAEndTp", NULL);
    xmlNewChild(node1, NULL, BAD_CAST "ns0:parentTp", AEndTp.parentTp);
    sprintf(auxBuff, "%d", AEndTp.ivid);
    xmlNewChild(node1, NULL, BAD_CAST "ns0:ivid", auxBuff);
    xmlNewChild(node1, NULL, BAD_CAST "ns0:portTpRoleState", AEndTp.portTpRoleState);

    node1 = xmlNewChild(node2, NULL, BAD_CAST "ns0:createZEndTp", NULL);
    xmlNewChild(node1, NULL, BAD_CAST "ns0:parentTp", ZEndTp.parentTp);
    sprintf(auxBuff, "%d", ZEndTp.ivid);
    xmlNewChild(node1, NULL, BAD_CAST "ns0:ivid", auxBuff);
    xmlNewChild(node1, NULL, BAD_CAST "ns0:portTpRoleState", ZEndTp.portTpRoleState);

    xmlDocDumpFormatMemory(xmlDoc, &xmlbuff, &buffersize, 1);
    retBuff = malloc(buffersize + 1);
    memcpy(retBuff, (char*) xmlbuff, buffersize);
    retBuff[buffersize] = 0;

    /*
    printf("xmlbuff:\n\n");
    displayMemory((char*) xmlbuff, buffersize + 1);
    printf("retbuff:\n\n");
    displayMemory((char*) retBuff, buffersize + 1);
    */
    xmlFree(xmlbuff);
    xmlFreeDoc(xmlDoc);
    return retBuff;
}
Exemple #28
0
char * regenerate_chain(EC_CONFIG * cfg)
{
    /* output expanded chain file with modified position values */
    int ecount;
    unsigned char * ebuf;
    xmlDocDumpFormatMemory(cfg->doc, &ebuf, &ecount, 0);
    
    /* alloc space for chain file*/
    char * sbuf = calloc(ecount, sizeof(char));
    
    /* write in the chain file and free it */
    strncat(sbuf, (char *) ebuf, ecount-strlen(sbuf)-1);
    xmlFree(ebuf);
    
    return sbuf;   
}
Exemple #29
0
enum jal_status jal_xml_output(
    xmlDocPtr doc,
    xmlChar **buffer)
{
    if (!doc || !buffer || *buffer) {
        return JAL_E_INVAL;
    }

    xmlChar *xmlbuff = NULL;
    int buffersize;

    xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1);

    *buffer = xmlbuff;

    return JAL_OK;
}
Exemple #30
0
void dump_doc(xmlDocPtr doc, xmlNodePtr hilight)
{
    xmlChar *xmlbuff;
    int buffersize;
    xmlChar space[255] = "";
    const xmlChar* was = NULL;
    if (hilight != NULL) {
	sprintf((char*)space, "***%s***", hilight->name);
	was = hilight->name;
	hilight->name = space;
    }
    xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1);
    if (hilight != NULL)
	hilight->name = was;
    printf("%s", (char *) xmlbuff);
    xmlFree(xmlbuff);
}