コード例 #1
0
ファイル: AEXMLWriter.cpp プロジェクト: dtbinh/Arenal-Engine
AEResult AEXMLWriter::CreateXML(const std::wstring& file, bool inMemory)
{
	if (m_IsReady)
	{
		AETODO("Better return code");
		return AEResult::Fail;
	}

	if (file.empty())
	{
		return AEResult::EmptyFilename;
	}

	if (inMemory)
	{
		m_XMLBuffer = xmlBufferCreate();
		if (xmlBufferCreate == nullptr) 
		{
			AETODO("Better return code");
			return AEResult::Fail;
		}

		m_XMLWriter = xmlNewTextWriterMemory(m_XMLBuffer, 0);
		if (m_XMLWriter == NULL)
		{
			CleanUp();

			AETODO("Better return code");
			return AEResult::Fail;
		}

		m_InMemory = true;
	}
	else
	{
		std::string fileStr = AE_Base::WideStr2String(file);

		m_XMLWriter = xmlNewTextWriterFilename(fileStr.c_str(), 0);
		if (m_XMLWriter == NULL)
		{
			AETODO("Better return code");
			return AEResult::Fail;
		}
	}

	int ret = xmlTextWriterStartDocument(m_XMLWriter, NULL, AE_XML_ENCODING, NULL);
	if (ret < 0)
	{
		CleanUp();

		AETODO("Better return code");
		return AEResult::Fail;
	}

	m_Filename = file;

	m_IsReady = true;

	return AEResult::Ok;
}
コード例 #2
0
ファイル: fileInfo.c プロジェクト: antonmazun/gogog
char* fileinfo_get(char* path) {
    FILE* file;
    xmlBufferPtr buf;
    xmlTextWriterPtr writer;
    char* ret;
    int wordCount;

    file  = fopen(path, "r");
    wordCount = countWords(file);
    fclose(file);

    buf = xmlBufferCreate();
    writer = xmlNewTextWriterMemory(buf, 0);

    xmlTextWriterStartDocument(writer, NULL, XML_E, NULL);


    xmlTextWriterStartElement(writer, BAD_CAST "fileInfo");
    xmlTextWriterWriteFormatElement(writer, BAD_CAST "wordCount", "%d", wordCount);
    xmlTextWriterEndElement(writer);

    xmlTextWriterEndDocument(writer);

    ret = malloc(buf->size);
    strcpy(ret,(char*)buf->content);
    xmlBufferFree(buf);

    return ret;
}
コード例 #3
0
ファイル: xmlwriter.cpp プロジェクト: fedor4ever/linux_build
/**
Writes report header to xml file..

Opens the xml file for output.
Allocate the memory for xml report.
Write the Dtd/Xslt info.
Write the root element.

@internalComponent
@released
*/
void XmlWriter::StartReport(void)
{
	iXmlFile.open(iXmlFileName.c_str());

	if(!(iXmlFile.is_open()))
	{
		throw ExceptionReporter(FILEOPENFAIL, __FILE__, __LINE__, (char*)iXmlFileName.c_str());
	}

	if(!(CreateXslFile()))
	{
		ExceptionReporter(XSLCREATIONFAILED, __FILE__, __LINE__, (char*)KXslFileName.c_str()).Report();
	}

	iXmlBufPtr = xmlBufferCreate();
	// xml writer pointer to buffer ( with no compression )
	iXmlTextWriter = xmlNewTextWriterMemory(iXmlBufPtr,0);

	if (!iXmlBufPtr || !iXmlTextWriter)
	{
		throw ExceptionReporter(NOMEMORY,__FILE__,__LINE__);
	}

	xmlTextWriterStartDocument(iXmlTextWriter, KXmlVersion.c_str(), KXmlEncoding.c_str(), KNull);
	xmlTextWriterWriteRaw(iXmlTextWriter,(unsigned char*)KDtdXslInfo.c_str());
	xmlTextWriterStartElement(iXmlTextWriter, BAD_CAST KXmlRootElement.c_str());
	xmlTextWriterStartElement(iXmlTextWriter,BAD_CAST KXmlcomment.c_str());
	xmlTextWriterWriteAttribute(iXmlTextWriter, BAD_CAST KXmlcomment.c_str(), BAD_CAST iInputCommnd.c_str());
}
コード例 #4
0
ファイル: XMLSchema.cpp プロジェクト: mloskot/PDAL
std::string XMLSchema::xml() const
{
    xmlBuffer *b = xmlBufferCreate();
    xmlTextWriterPtr w = xmlNewTextWriterMemory(b, 0);

    xmlTextWriterSetIndent(w, 1);
    xmlTextWriterStartDocument(w, NULL, "utf-8", NULL);
    xmlTextWriterStartElementNS(w, (const xmlChar*)"pc",
        (const xmlChar*)"PointCloudSchema", NULL);
    xmlTextWriterWriteAttributeNS(w, (const xmlChar*) "xmlns",
        (const xmlChar*)"pc", NULL,
        (const xmlChar*)"http://pointcloud.org/schemas/PC/");
    xmlTextWriterWriteAttributeNS(w, (const xmlChar*)"xmlns",
        (const xmlChar*)"xsi", NULL,
        (const xmlChar*)"http://www.w3.org/2001/XMLSchema-instance");

    writeXml(w);

    xmlTextWriterEndElement(w);
    xmlTextWriterEndDocument(w);

    std::string output((const char *)b->content, b->use);
    xmlFreeTextWriter(w);
    xmlBufferFree(b);

    return output;
}
コード例 #5
0
bool c_XMLWriter::t_openmemory() {
  m_output = xmlBufferCreate();
  if (m_output == NULL) {
    raise_warning("Unable to create output buffer");
    return false;
  }
  return (m_ptr = xmlNewTextWriterMemory(m_output, 0));
}
コード例 #6
0
bool c_XMLWriter::t_openmemory() {
  INSTANCE_METHOD_INJECTION_BUILTIN(XMLWriter, XMLWriter::openmemory);
  m_output = xmlBufferCreate();
  if (m_output == NULL) {
    raise_warning("Unable to create output buffer");
    return false;
  }
  return m_ptr = xmlNewTextWriterMemory(m_output, 0);
}
コード例 #7
0
ファイル: xmlinout.cpp プロジェクト: bobwolff68/neuron
bool XMLInOut::SetupDoc(void)
{
	DeleteDoc();

    /* Create a new XML buffer, to which the XML document will be
     * written */

    buf = xmlBufferCreate();
    if (buf == NULL) {
        cout << "testXmlwriterMemory: Error creating the xml buffer\n" << endl;
        return false;
    }

    /* Create a new XmlWriter for memory, with no compression.
     * Remark: there is no compression for this kind of xmlTextWriter */
    writer = xmlNewTextWriterMemory(buf, 0);
    if (writer == NULL) {
        cout << "testXmlwriterMemory: Error creating the xml writer\n" << endl;
        return false;
    }

    if (xmlTextWriterSetIndent(writer, 1) < 0)
    	return false;

    /* Start the document with the xml default for the version,
     * encoding ISO 8859-1 and the default for the standalone
     * declaration. */
/*
    rc = xmlTextWriterStartDocument(writer, NULL, "ISO-8859-1", NULL);
    if (rc < 0) {
        printf
            ("testXmlwriterMemory: Error at xmlTextWriterStartDocument\n");
        return false;
    }
*/

    if (AddElement("neuron-brain") < 0)
    	return false;

    if (AddElement("MACROGROUP") < 0)
    	return false;

    // Important addition. When doing a MarkSection(), the # bytes wont be valid for what your
    // intuition tells you. The above <MACROGROUP> at this stage isn't closed due to possible
    // content and attributes. The comment forces things to "end" making the buffer ok for marking.
    if (AddComment("The Real Group of commands starts here.") < 0)
    	return false;

    MarkSection();

    return true;
}
コード例 #8
0
ファイル: temporal.cpp プロジェクト: alerque/bibledit
void temporal_convert_parallel_passages()
// This was used to convert file NT_order_of_OT_Quotations_in_NT.pps to xml.
// Then for converting NT_Parallel_Passages.pps.
// Then for converting OT_Parallel_Passages.pps.
{
  bool set_opened = false;
  xmlBufferPtr buffer = xmlBufferCreate();
  xmlTextWriterPtr writer = xmlNewTextWriterMemory(buffer, 0);
  xmlTextWriterStartDocument(writer, NULL, "UTF-8", NULL);
  xmlTextWriterSetIndent(writer, 1);
  xmlTextWriterStartElement(writer, BAD_CAST "ot-parallel-passages");

  ReadText rt("/home/joe/parallel-passages/OT_Parallel_Passages.pps", true);
  for (unsigned int i = 0; i < rt.lines.size(); i++) {
    if (rt.lines[i].find("\\key ") == 0) {
      rt.lines[i].erase(0, 5);
      xmlTextWriterStartElement(writer, BAD_CAST "section");
      xmlTextWriterWriteAttribute(writer, BAD_CAST "title", BAD_CAST rt.lines[i].c_str());
    }
    if (rt.lines[i].find("\\ref ") == 0) {
      if (!set_opened) {
        xmlTextWriterStartElement(writer, BAD_CAST "set");
        set_opened = true;
      }
      xmlTextWriterStartElement(writer, BAD_CAST "reference");
      rt.lines[i].erase(0, 5);
      ustring book, chapter, verse;
      decode_reference(rt.lines[i], book, chapter, verse);
      book = books_id_to_english(books_paratext_to_id(book));
      xmlTextWriterWriteAttribute(writer, BAD_CAST "book", BAD_CAST book.c_str());
      xmlTextWriterWriteAttribute(writer, BAD_CAST "chapter", BAD_CAST chapter.c_str());
      xmlTextWriterWriteAttribute(writer, BAD_CAST "verse", BAD_CAST verse.c_str());
      xmlTextWriterEndElement(writer);
    }
    if (rt.lines[i].empty() || (rt.lines[i].find("\\com") == 0)) {
      xmlTextWriterEndElement(writer);
      set_opened = false;
    }
    if (rt.lines[i].empty()) {
      xmlTextWriterEndElement(writer);
    }
  }

  xmlTextWriterEndDocument(writer);
  xmlTextWriterFlush(writer);
  g_file_set_contents("/home/joe/ot-parallel-passages.xml", (const gchar *)buffer->content, -1, NULL);
  if (writer)
    xmlFreeTextWriter(writer);
  if (buffer)
    xmlBufferFree(buffer);
}
コード例 #9
0
ファイル: webdav.c プロジェクト: hchtym/onion
/**
 * @short Prepares the response for propfinds
 * 
 * @param realpath Shared folder
 * @param urlpath URL of the requested propfind
 * @param depth Depth of query, 0 or 1.
 * @param props Properties of the query
 * 
 * @returns An onion_block with the XML data.
 */
onion_block *onion_webdav_write_propfind(const char *basepath, const char *realpath, const char *urlpath, int depth, 
																				 int props){
	onion_block *data=onion_block_new();
	xmlTextWriterPtr writer;
	xmlBufferPtr buf;
	buf = xmlBufferCreate();
	if (buf == NULL) {
		ONION_ERROR("testXmlwriterMemory: Error creating the xml buffer");
		return data;
	}
	writer = xmlNewTextWriterMemory(buf, 0);
	if (writer == NULL) {
		ONION_ERROR("testXmlwriterMemory: Error creating the xml writer");
		return data;
	}
	int error;
	xmlTextWriterStartDocument(writer, NULL, "utf-8", NULL);
	xmlTextWriterStartElement(writer, BAD_CAST "D:multistatus");
		xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:D" ,BAD_CAST "DAV:");
			error=onion_webdav_write_props(writer, basepath, realpath, urlpath, NULL, props);
			if (depth>0){
				ONION_DEBUG("Get also all files");
				DIR *dir=opendir(realpath);
				if (!dir){
					ONION_ERROR("Error opening dir %s to check files on it", realpath);
				}
				else{
					struct dirent *de;
					while ( (de=readdir(dir)) ){
						if (de->d_name[0]!='.')
							onion_webdav_write_props(writer, basepath, realpath, urlpath, de->d_name, props);
					}
					closedir(dir);
				}
			}
		xmlTextWriterEndElement(writer);
	xmlTextWriterEndElement(writer);
	
	
	xmlTextWriterEndDocument(writer);
	xmlFreeTextWriter(writer);
	
	onion_block_add_str(data, (const char*)buf->content);
	xmlBufferFree(buf);

	if (error){
		onion_block_free(data);
		return NULL;
	}
	return data;
}
コード例 #10
0
celix_status_t endpointDescriptorWriter_create(endpoint_descriptor_writer_pt *writer) {
    celix_status_t status = CELIX_SUCCESS;

    *writer = malloc(sizeof(**writer));
    if (!*writer) {
        status = CELIX_ENOMEM;
    } else {
        (*writer)->buffer = xmlBufferCreate();
        if ((*writer)->buffer == NULL) {
            status = CELIX_BUNDLE_EXCEPTION;
        } else {
            (*writer)->writer = xmlNewTextWriterMemory((*writer)->buffer, 0);
            if ((*writer)->writer == NULL) {
                status = CELIX_BUNDLE_EXCEPTION;
            }
        }
    }

    return status;
}
コード例 #11
0
ファイル: exml.c プロジェクト: playya/Enlightenment
/**
 * 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;
	}
}
コード例 #12
0
int output_log_xml_process(struct event *evt, void *obj) {

    struct output_log_xml_priv *priv = obj;
    struct event_reg_info *evt_info = event_get_info(evt);

    xmlBufferPtr buff = xmlBufferCreate();
    if (!buff) {
        pomlog(POMLOG_ERR "Error while creating the xml buffer");
        return POM_ERR;
    }

    xmlTextWriterPtr writer = xmlNewTextWriterMemory(buff, 0);
    if (!writer) {
        pomlog(POMLOG_ERR "Error while creating the xmlTextWriter");
        xmlBufferFree(buff);
        return POM_ERR;
    }

    // <event name="event_name">

    char timestamp[21] = { 0 };
    snprintf(timestamp, 20, "%"PRIu64, (uint64_t) event_get_timestamp(evt));

    if (xmlTextWriterWriteString(writer, BAD_CAST "\n") < 0 ||
            xmlTextWriterStartElement(writer, BAD_CAST "event") < 0 ||
            xmlTextWriterWriteAttribute(writer, BAD_CAST "name", BAD_CAST evt_info->name) < 0 ||
            xmlTextWriterWriteAttribute(writer, BAD_CAST "timestamp", BAD_CAST timestamp) < 0)
        goto err;

    struct data *evt_data = event_get_data(evt);

    int i;
    for (i = 0; i < evt_info->data_reg->data_count; i++) {
        if (evt_info->data_reg->items[i].flags & DATA_REG_FLAG_LIST) {
            // Got a data_list

            if (!evt_data[i].items)
                continue;

            // <data_list name="data_name">
            if (xmlTextWriterWriteString(writer, BAD_CAST "\n\t") < 0 ||
                    xmlTextWriterStartElement(writer, BAD_CAST "data_list") < 0 ||
                    xmlTextWriterWriteAttribute(writer, BAD_CAST "name", BAD_CAST evt_info->data_reg->items[i].name) < 0)
                goto err;

            // <value key="key1">
            struct data_item *itm = evt_data[i].items;
            for (; itm; itm = itm->next) {
                if (xmlTextWriterWriteString(writer, BAD_CAST "\n\t\t") < 0 ||
                        xmlTextWriterStartElement(writer, BAD_CAST "value") < 0 ||
                        xmlTextWriterWriteAttribute(writer, BAD_CAST "key", BAD_CAST itm->key) < 0)
                    goto err;

                char *value = ptype_print_val_alloc(itm->value, NULL);
                if (!value)
                    goto err;

                if (xmlTextWriterWriteString(writer, BAD_CAST value) < 0) {
                    free(value);
                    goto err;
                }

                free(value);

                // </value>
                if (xmlTextWriterEndElement(writer) < 0)
                    goto err;

            }


            // </data_list>
            if (xmlTextWriterWriteString(writer, BAD_CAST "\n\t") < 0 ||
                    xmlTextWriterEndElement(writer) < 0)
                goto err;

        } else {

            // Got a single data

            if (!data_is_set(evt_data[i]))
                continue;


            // <data name="data_name">

            if (xmlTextWriterWriteString(writer, BAD_CAST "\n\t") < 0 ||
                    xmlTextWriterStartElement(writer, BAD_CAST "data") < 0 ||
                    xmlTextWriterWriteAttribute(writer, BAD_CAST "name", BAD_CAST evt_info->data_reg->items[i].name) < 0)
                goto err;

            if (evt_data[i].value) {
                char *value = ptype_print_val_alloc(evt_data[i].value, NULL);
                if (!value)
                    goto err;

                if (xmlTextWriterWriteString(writer, BAD_CAST value) < 0) {
                    free(value);
                    goto err;
                }

                free(value);
            }

            // </data>

            if (xmlTextWriterEndElement(writer) < 0)
                goto err;
        }
    }

    // </event>
    if (xmlTextWriterWriteString(writer, BAD_CAST "\n") < 0 ||
            xmlTextWriterEndElement(writer) < 0 ||
            xmlTextWriterWriteString(writer, BAD_CAST "\n") < 0)
        goto err;

    xmlFreeTextWriter(writer);

    if (pom_write(priv->fd, buff->content, buff->use) != POM_OK) {
        pomlog(POMLOG_ERR "Error while writing to the log file");
        xmlBufferFree(buff);
        return POM_ERR;
    }

    xmlBufferFree(buff);

    if (priv->perf_events)
        registry_perf_inc(priv->perf_events, 1);

    return POM_OK;
err:
    pomlog(POMLOG_ERR "An error occured while processing the event");
    xmlFreeTextWriter(writer);
    xmlBufferFree(buff);

    return POM_ERR;

}
コード例 #13
0
ファイル: xml.c プロジェクト: mittinatten/freesasa
int
freesasa_write_xml(FILE *output,
                   freesasa_node *root,
                   int options)
{
    freesasa_node *child = NULL;
    xmlDocPtr doc = NULL;
    xmlNodePtr xml_root = NULL, xml_result_node = NULL;
    xmlNsPtr ns = NULL;
    xmlBufferPtr buf = NULL;
    xmlTextWriterPtr writer = NULL;
    int ret = FREESASA_FAIL;

    assert(freesasa_node_type(root) == FREESASA_NODE_ROOT);

    doc = xmlNewDoc(BAD_CAST "1.0");
    if (doc == NULL) {
        fail_msg("");
        goto cleanup;
    }

    xml_root = xmlNewNode(NULL, BAD_CAST "results");
    if (xml_root == NULL) {
        fail_msg("");
        goto cleanup;
    }

    ns = xmlNewNs(xml_root, BAD_CAST FREESASA_XMLNS, NULL);
    if (ns == NULL) {
        fail_msg("");
        xmlFreeNode(xml_root);
        goto cleanup;
    }

    xmlDocSetRootElement(doc, xml_root);

    /* global attributes */
    if (xmlNewProp(xml_root, BAD_CAST "source", BAD_CAST freesasa_string) == NULL) {
        fail_msg("");
        goto cleanup;
    }
    if (xmlNewProp(xml_root, BAD_CAST "lengthUnit", BAD_CAST "Ångström") == NULL) {
        fail_msg("");
        goto cleanup;
    }

    child = freesasa_node_children(root);
    while (child) {
        xml_result_node = xml_result(child, options);
        if (xml_result_node == NULL) {
            fail_msg("");
            goto cleanup;
        }
        if (xmlAddChild(xml_root, xml_result_node) == NULL) {
            fail_msg("");
            xmlFreeNode(xml_result_node);
            goto cleanup;
        }
        child = freesasa_node_next(child);
    }

    buf = xmlBufferCreate();
    if (buf == NULL) {
        fail_msg("");
        goto cleanup;
    }

    writer = xmlNewTextWriterMemory(buf, 0);
    if (writer == NULL) {
        xmlBufferFree(buf);
        fail_msg("");
        goto cleanup;
    }

    if (xmlTextWriterStartDocument(writer, XML_DEFAULT_VERSION,
                                   xmlGetCharEncodingName(XML_CHAR_ENCODING_UTF8), NULL)
        == -1) {
        fail_msg("");
        goto cleanup;
    }

    if (xmlTextWriterFlush(writer) == -1) {
        fail_msg("");
        goto cleanup;
    }

    if (xmlNodeDump(buf, doc, xml_root, 0, 1) == 0) {
        fail_msg("");
        goto cleanup;
    }

    if (xmlTextWriterEndDocument(writer) == -1) {
        fail_msg("");
        goto cleanup;
    }

    fprintf(output, "%s", (const char*) buf->content);
    fflush(output);
    if (ferror(output)) {
        fail_msg(strerror(errno));
        goto cleanup;
    }

    ret = FREESASA_SUCCESS;

 cleanup:
    xmlFreeDoc(doc);
    xmlFreeTextWriter(writer);
    return ret;
}
コード例 #14
0
ファイル: stylesheet.cpp プロジェクト: alerque/bibledit
void Stylesheet::save ()
// Saves the stylesheet to its native xml format.
{
  // If no name is given, we work with the template. It can't be saved.
  if (name.empty())
    return;

  // Start the new xml document.
  xmlBufferPtr buffer = xmlBufferCreate();
  xmlTextWriterPtr writer = xmlNewTextWriterMemory(buffer, 0);
  xmlTextWriterStartDocument(writer, NULL, "UTF-8", NULL);
  xmlTextWriterSetIndent(writer, 1);
  xmlTextWriterStartElement(writer, BAD_CAST "bibledit-configuration");

  // Get the combined information, and write it to the document.
  for (unsigned int i = 0; i < styles.size(); i++) {

    StyleV2 * style = styles[i];

    // Open a style for the marker
    xmlTextWriterStartElement(writer, BAD_CAST "style");
    xmlTextWriterWriteFormatAttribute (writer, BAD_CAST "marker", "%s", style->marker.c_str());

    // Write values.

    if (!style->name.empty()) {
      xmlTextWriterStartElement(writer, BAD_CAST "name");
      xmlTextWriterWriteFormatString(writer, "%s", style->name.c_str());
      xmlTextWriterEndElement(writer);
    }        

    if (!style->info.empty()) {
      xmlTextWriterStartElement(writer, BAD_CAST "info");
      xmlTextWriterWriteFormatString(writer, "%s", style->info.c_str());
      xmlTextWriterEndElement(writer);
    }

    xmlTextWriterStartElement(writer, BAD_CAST "type");
    xmlTextWriterWriteFormatString(writer, "%d", style->type);
    xmlTextWriterEndElement(writer);

    xmlTextWriterStartElement(writer, BAD_CAST "subtype");
    xmlTextWriterWriteFormatString(writer, "%d", style->subtype);
    xmlTextWriterEndElement(writer);

    xmlTextWriterStartElement(writer, BAD_CAST "fontsize");
    xmlTextWriterWriteFormatString(writer, "%s", convert_to_string (style->fontsize).c_str());
    xmlTextWriterEndElement(writer);

    xmlTextWriterStartElement(writer, BAD_CAST "italic");
    xmlTextWriterWriteFormatString(writer, "%s", style->italic.c_str());
    xmlTextWriterEndElement(writer);

    xmlTextWriterStartElement(writer, BAD_CAST "bold");
    xmlTextWriterWriteFormatString(writer, "%s", style->bold.c_str());
    xmlTextWriterEndElement(writer);

    xmlTextWriterStartElement(writer, BAD_CAST "underline");
    xmlTextWriterWriteFormatString(writer, "%s", style->underline.c_str());
    xmlTextWriterEndElement(writer);

    xmlTextWriterStartElement(writer, BAD_CAST "smallcaps");
    xmlTextWriterWriteFormatString(writer, "%s", style->smallcaps.c_str());
    xmlTextWriterEndElement(writer);

    xmlTextWriterStartElement(writer, BAD_CAST "superscript");
    xmlTextWriterWriteFormatString(writer, "%s", convert_to_string (style->superscript).c_str());
    xmlTextWriterEndElement(writer);

    xmlTextWriterStartElement(writer, BAD_CAST "justification");
    xmlTextWriterWriteFormatString(writer, "%s", style->justification.c_str());
    xmlTextWriterEndElement(writer);

    xmlTextWriterStartElement(writer, BAD_CAST "spacebefore");
    xmlTextWriterWriteFormatString(writer, "%s", convert_to_string (style->spacebefore).c_str());
    xmlTextWriterEndElement(writer);

    xmlTextWriterStartElement(writer, BAD_CAST "spaceafter");
    xmlTextWriterWriteFormatString(writer, "%s", convert_to_string (style->spaceafter).c_str());
    xmlTextWriterEndElement(writer);

    xmlTextWriterStartElement(writer, BAD_CAST "leftmargin");
    xmlTextWriterWriteFormatString(writer, "%s", convert_to_string (style->leftmargin).c_str());
    xmlTextWriterEndElement(writer);

    xmlTextWriterStartElement(writer, BAD_CAST "rightmargin");
    xmlTextWriterWriteFormatString(writer, "%s", convert_to_string (style->rightmargin).c_str());
    xmlTextWriterEndElement(writer);

    xmlTextWriterStartElement(writer, BAD_CAST "firstlineindent");
    xmlTextWriterWriteFormatString(writer, "%s", convert_to_string (style->firstlineindent).c_str());
    xmlTextWriterEndElement(writer);

    xmlTextWriterStartElement(writer, BAD_CAST "spancolumns");
    xmlTextWriterWriteFormatString(writer, "%s", convert_to_string (style->spancolumns).c_str());
    xmlTextWriterEndElement(writer);

    xmlTextWriterStartElement(writer, BAD_CAST "color");
    xmlTextWriterWriteFormatString(writer, "%d", style->color);
    xmlTextWriterEndElement(writer);

    xmlTextWriterStartElement(writer, BAD_CAST "print");
    xmlTextWriterWriteFormatString(writer, "%s", convert_to_string (style->print).c_str());
    xmlTextWriterEndElement(writer);

    xmlTextWriterStartElement(writer, BAD_CAST "userbool1");
    xmlTextWriterWriteFormatString(writer, "%s", convert_to_string (style->userbool1).c_str());
    xmlTextWriterEndElement(writer);

    xmlTextWriterStartElement(writer, BAD_CAST "userbool2");
    xmlTextWriterWriteFormatString(writer, "%s", convert_to_string (style->userbool2).c_str());
    xmlTextWriterEndElement(writer);

    xmlTextWriterStartElement(writer, BAD_CAST "userbool3");
    xmlTextWriterWriteFormatString(writer, "%s", convert_to_string (style->userbool3).c_str());
    xmlTextWriterEndElement(writer);

    xmlTextWriterStartElement(writer, BAD_CAST "userint1");
    xmlTextWriterWriteFormatString(writer, "%d", style->userint1);
    xmlTextWriterEndElement(writer);

    xmlTextWriterStartElement(writer, BAD_CAST "userint2");
    xmlTextWriterWriteFormatString(writer, "%d", style->userint2);
    xmlTextWriterEndElement(writer);

    xmlTextWriterStartElement(writer, BAD_CAST "userint3");
    xmlTextWriterWriteFormatString(writer, "%d", style->userint3);
    xmlTextWriterEndElement(writer);

    xmlTextWriterStartElement(writer, BAD_CAST "userstring1");
    xmlTextWriterWriteFormatString(writer, "%s", style->userstring1.c_str());
    xmlTextWriterEndElement(writer);

    xmlTextWriterStartElement(writer, BAD_CAST "userstring2");
    xmlTextWriterWriteFormatString(writer, "%s", style->userstring2.c_str());
    xmlTextWriterEndElement(writer);

    xmlTextWriterStartElement(writer, BAD_CAST "userstring3");
    xmlTextWriterWriteFormatString(writer, "%s", style->userstring3.c_str());
    xmlTextWriterEndElement(writer);

    // Close the style.
    xmlTextWriterEndElement(writer);
  }

  // Close document and write it to disk.
  xmlTextWriterEndDocument(writer);
  xmlTextWriterFlush(writer);
  ustring filename = stylesheet_xml_filename (name);
  g_file_set_contents(filename.c_str(), (const gchar *)buffer->content, -1, NULL);

  // Free memory.
  if (writer)
    xmlFreeTextWriter(writer);
  if (buffer)
    xmlBufferFree(buffer);
}
コード例 #15
0
ファイル: pmm_util.c プロジェクト: robfr/pmm
/*
 * TODO pass up return conditions instead of terminating
 */
void print_xml_results(struct timeval *walltime, struct timeval *usedtime) {

    int rc;
    xmlTextWriterPtr writer;
    xmlBufferPtr buf;

    buf = xmlBufferCreate();
    if(buf == NULL) {
        printf("pmm_timer_result: Error creating xml buffer\n");
        exit(-1);
    }

    writer = xmlNewTextWriterMemory(buf, 0);
    if(writer == NULL) {
        printf("pmm_timer_result: Error creating xml writer\n");
        exit(-1);
    }

    rc = xmlTextWriterSetIndent(writer, 1);
    if(rc < 0) {
        printf("pmm_timer_result: Error setting indent\n");
        exit(-1);
    }

    rc = xmlTextWriterStartDocument(writer, NULL, XMLENCODING, NULL);
    if(rc < 0) {
        printf("pmm_timer_result: Error at xmlTextWriterStartDocument\n");
        exit(-1);
    }

    rc = xmlTextWriterStartElement(writer, BAD_CAST "result");
    if(rc < 0) {
        printf("pmm_timer_result: Error creating \'result\' element\n");
        exit(-1);
    }

    rc = print_xml_time_element(writer, "walltime", walltime);
    if(rc < 0) {
        printf("print_xml_results: Error printing walltime result\n");
        exit(rc);
    }

    rc = print_xml_time_element(writer, "usedtime", usedtime);
    if(rc < 0) {
        printf("print_xml_results: Error printing usedtime result\n");
        exit(rc);
    }


    rc = xmlTextWriterEndDocument(writer);
    if(rc < 0) {
        printf("print_xml_results: Error closing xml document\n");
        exit(rc);
    }

    xmlFreeTextWriter(writer);

    printf("%s", (const char*)buf->content);

    xmlBufferFree(buf);

}
コード例 #16
0
ファイル: xmlparsing.c プロジェクト: DJHartley/VitaMTP
/**
 * Takes a metadata linked list and generates XML data.
 * This should be called automatically.
 * 
 * @param p_metadata a pointer to the structure as input.
 * @param data a pointer to the array to output.
 * @param len a pointer to the length of the output.
 * @return zero on success.
 * @see VitaMTP_SendObjectMetadata()
 */
int metadata_to_xml(metadata_t *p_metadata, char** data, int *len){
    xmlTextWriterPtr writer;
    xmlBufferPtr buf;
    
    buf = xmlBufferCreate();
    if (buf == NULL) {
        if(IS_LOGGING(ERROR_LOG)){
            fprintf(stderr, "metadata_to_xml: Error creating the xml buffer\n");
            return 1;
        }
    }
    writer = xmlNewTextWriterMemory(buf, 0);
    if (writer == NULL) {
        if(IS_LOGGING(ERROR_LOG)){
            fprintf(stderr, "metadata_to_xml: Error creating the xml writer\n");
            return 1;
        }
    }
    if(xmlTextWriterStartDocument(writer, NULL, "UTF-8", NULL) < 0){
        if(IS_LOGGING(ERROR_LOG)){
            fprintf(stderr, "metadata_to_xml: Error at xmlTextWriterStartDocument\n");
            return 1;
        }
    }
    xmlTextWriterStartElement(writer, BAD_CAST "objectMetadata");
    
    for(metadata_t *current = p_metadata; current != NULL; current = current->next_metadata){
        char *timestamp;
        switch(current->dataType){
            case Folder:
                xmlTextWriterStartElement(writer, BAD_CAST "folder");
                xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "type", "%d", current->data.folder.type);
                xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "name", "%s", current->data.folder.name);
                break;
            case File:
                xmlTextWriterStartElement(writer, BAD_CAST "file");
                xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "name", "%s", current->data.file.name);
                xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "statusType", "%d", current->data.file.statusType);
                break;
            case SaveData:
                xmlTextWriterStartElement(writer, BAD_CAST "saveData");
                xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "detail", "%s", current->data.saveData.detail);
                xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "dirName", "%s", current->data.saveData.dirName);
                xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "savedataTitle", "%s", current->data.saveData.savedataTitle);
                timestamp = vita_make_time(current->data.saveData.dateTimeUpdated);
                xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "dateTimeUpdated", "%s", timestamp);
                free(timestamp);
                xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "statusType", "%d", current->data.saveData.statusType);
                break;
            case Thumbnail:
                xmlTextWriterStartElement(writer, BAD_CAST "thumbnail");
                xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "codecType", "%d", current->data.thumbnail.codecType);
                xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "width", "%d", current->data.thumbnail.width);
                xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "height", "%d", current->data.thumbnail.height);
                xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "type", "%d", current->data.thumbnail.type);
                xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "orientationType", "%d", current->data.thumbnail.orientationType);
                char *aspectRatio;
                asprintf(&aspectRatio, "%.6f", current->data.thumbnail.aspectRatio);
                char *period = strchr(aspectRatio, '.');
                *period = ','; // All this to make period a comma, maybe there is an easier way?
                xmlTextWriterWriteAttribute(writer, BAD_CAST "aspectRatio", BAD_CAST aspectRatio);
                free(aspectRatio);
                xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "fromType", "%d", current->data.thumbnail.fromType);
                break;
            default:
                continue;
        }
        xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "index", "%d", current->index);
        xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "ohfiParent", "%d", current->ohfiParent);
        xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "ohfi", "%d", current->ohfi);
        xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "title", "%s", current->title);
        xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "size", "%lu", current->size);
        timestamp = vita_make_time(current->dateTimeCreated);
        xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "dateTimeCreated", "%s", timestamp);
        free(timestamp);
        xmlTextWriterEndElement(writer);
    }
    
    xmlTextWriterEndElement(writer);
    if (xmlTextWriterEndDocument(writer) < 0) {
        if(IS_LOGGING(ERROR_LOG)){
            fprintf(stderr, "metadata_to_xml: Error at xmlTextWriterEndDocument\n");
            return 1;
        }
    }
    xmlFreeTextWriter(writer);
    *data = add_size_header((char*)buf->content, (uint32_t)buf->use + 1);
    *len = buf->use + sizeof(uint32_t) + 1;
    xmlBufferFree(buf);
    return 0;
}
コード例 #17
0
ファイル: friendlist.c プロジェクト: Distrotech/linphone
static char * create_resource_list_xml(const LinphoneFriendList *list) {
	char *xml_content = NULL;
	MSList *elem;
	xmlBufferPtr buf;
	xmlTextWriterPtr writer;
	int err;

	if (ms_list_size(list->friends) <= 0) return NULL;

	buf = xmlBufferCreate();
	if (buf == NULL) {
		ms_error("%s: Error creating the XML buffer", __FUNCTION__);
		return NULL;
	}
	writer = xmlNewTextWriterMemory(buf, 0);
	if (writer == NULL) {
		ms_error("%s: Error creating the XML writer", __FUNCTION__);
		return NULL;
	}

	xmlTextWriterSetIndent(writer,1);
	err = xmlTextWriterStartDocument(writer, "1.0", "UTF-8", NULL);
	if (err >= 0) {
		err = xmlTextWriterStartElementNS(writer, NULL, (const xmlChar *)"resource-lists", (const xmlChar *)"urn:ietf:params:xml:ns:resource-lists");
	}
	if (err >= 0) {
		err = xmlTextWriterWriteAttributeNS(writer, (const xmlChar *)"xmlns", (const xmlChar *)"xsi",
						    NULL, (const xmlChar *)"http://www.w3.org/2001/XMLSchema-instance");
	}

	if (err>= 0) {
		err = xmlTextWriterStartElement(writer, (const xmlChar *)"list");
	}
	for (elem = list->friends; elem != NULL; elem = elem->next) {
		LinphoneFriend *friend = (LinphoneFriend *)elem->data;
		char *uri = linphone_address_as_string_uri_only(friend->uri);
		if (err >= 0) {
			err = xmlTextWriterStartElement(writer, (const xmlChar *)"entry");
		}
		if (err >= 0) {
			err = xmlTextWriterWriteAttribute(writer, (const xmlChar *)"uri", (const xmlChar *)uri);
		}
		if (err >= 0) {
			/* Close the "entry" element. */
			err = xmlTextWriterEndElement(writer);
		}
		if (uri) ms_free(uri);
	}
	if (err >= 0) {
		/* Close the "list" element. */
		err = xmlTextWriterEndElement(writer);
	}

	if (err >= 0) {
		/* Close the "resource-lists" element. */
		err = xmlTextWriterEndElement(writer);
	}
	if (err >= 0) {
		err = xmlTextWriterEndDocument(writer);
	}
	if (err > 0) {
		/* xmlTextWriterEndDocument returns the size of the content. */
		xml_content = ms_strdup((char *)buf->content);
	}
	xmlFreeTextWriter(writer);
	xmlBufferFree(buf);

	return xml_content;
}
コード例 #18
0
ファイル: opendocument.cpp プロジェクト: alerque/bibledit
void OpenDocument::generate_styles_xml(bool right_to_left)
// This generates the file "styles.xml" in the OpenDocument.
{
  // Start the new xml document.
  xmlBufferPtr buffer = xmlBufferCreate();
  xmlTextWriterPtr writer = xmlNewTextWriterMemory(buffer, 0);
  xmlTextWriterStartDocument(writer, NULL, "UTF-8", NULL);
  xmlTextWriterSetIndent(writer, 1);
  xmlTextWriterStartElement(writer, BAD_CAST "office:document-styles");
  xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:office", BAD_CAST "urn:oasis:names:tc:opendocument:xmlns:office:1.0");
  xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:style", BAD_CAST "urn:oasis:names:tc:opendocument:xmlns:style:1.0");
  xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:text", BAD_CAST "urn:oasis:names:tc:opendocument:xmlns:text:1.0");
  xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:table", BAD_CAST "urn:oasis:names:tc:opendocument:xmlns:table:1.0");
  xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:draw", BAD_CAST "urn:oasis:names:tc:opendocument:xmlns:drawing:1.0");
  xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:fo", BAD_CAST "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0");
  xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:xlink", BAD_CAST "http://www.w3.org/1999/xlink");
  xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:dc", BAD_CAST "http://purl.org/dc/elements/1.1/");
  xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:meta", BAD_CAST "urn:oasis:names:tc:opendocument:xmlns:meta:1.0");
  xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:number", BAD_CAST "urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0");
  xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:svg", BAD_CAST "urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0");
  xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:chart", BAD_CAST "urn:oasis:names:tc:opendocument:xmlns:chart:1.0");
  xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:dr3d", BAD_CAST "urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0");
  xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:math", BAD_CAST "http://www.w3.org/1998/Math/MathML");
  xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:form", BAD_CAST "urn:oasis:names:tc:opendocument:xmlns:form:1.0");
  xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:script", BAD_CAST "urn:oasis:names:tc:opendocument:xmlns:script:1.0");
  xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:ooo", BAD_CAST "http://openoffice.org/2004/office");
  xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:ooow", BAD_CAST "http://openoffice.org/2004/writer");
  xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:oooc", BAD_CAST "http://openoffice.org/2004/calc");
  xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:dom", BAD_CAST "http://www.w3.org/2001/xml-events");
  xmlTextWriterWriteAttribute(writer, BAD_CAST "office:version", BAD_CAST "1.0");

  // Font face declarations.
  xmlTextWriterStartElement(writer, BAD_CAST "office:font-face-decls");
  xmlTextWriterEndElement(writer);

  // Styles.
  xmlTextWriterStartElement(writer, BAD_CAST "office:styles");
  generate_styles(writer);
  xmlTextWriterEndElement(writer);

  // Automatic styles.
  xmlTextWriterStartElement(writer, BAD_CAST "office:automatic-styles");
  xmlTextWriterStartElement(writer, BAD_CAST "style:page-layout");
  xmlTextWriterWriteAttribute(writer, BAD_CAST "style:name", BAD_CAST "pm1");
  xmlTextWriterStartElement(writer, BAD_CAST "style:page-layout-properties");
  extern Settings *settings;
  xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "fo:page-width", "%.2fcm", settings->genconfig.paper_width_get());
  xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "fo:page-height", "%.2fcm", settings->genconfig.paper_height_get());
  xmlTextWriterWriteAttribute(writer, BAD_CAST "style:print-orientation", BAD_CAST "portrait");
  xmlTextWriterWriteAttribute(writer, BAD_CAST "style:num-format", BAD_CAST "1");
  xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "fo:margin-top", "%.2fcm", settings->genconfig.paper_top_margin_get());
  xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "fo:margin-bottom", "%.2fcm", settings->genconfig.paper_bottom_margin_get());
  xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "fo:margin-left", "%.2fcm", settings->genconfig.paper_inside_margin_get());
  xmlTextWriterWriteFormatAttribute(writer, BAD_CAST "fo:margin-right", "%.2fcm", settings->genconfig.paper_outside_margin_get());
  if (right_to_left) {
    xmlTextWriterWriteAttribute(writer, BAD_CAST "style:writing-mode", BAD_CAST "rl-tb");
    xmlTextWriterWriteAttribute(writer, BAD_CAST "writing-mode", BAD_CAST "rl-tb");
  }
  xmlTextWriterEndElement(writer);
  xmlTextWriterEndElement(writer);
  xmlTextWriterEndElement(writer);

  // Master styles.
  xmlTextWriterStartElement(writer, BAD_CAST "office:master-styles");
  xmlTextWriterStartElement(writer, BAD_CAST "style:master-page");
  xmlTextWriterWriteAttribute(writer, BAD_CAST "style:name", BAD_CAST "Standard");
  xmlTextWriterWriteAttribute(writer, BAD_CAST "style:page-layout-name", BAD_CAST "pm1");
  xmlTextWriterEndElement(writer);
  xmlTextWriterEndElement(writer);

  // Close document.
  xmlTextWriterEndElement(writer);

  // Close document and write it to disk.
  xmlTextWriterEndDocument(writer);
  xmlTextWriterFlush(writer);
  ustring filename = gw_build_filename(workingdirectory, "styles.xml");
  g_file_set_contents(filename.c_str(), (const gchar *)buffer->content, -1, NULL);

  // Free memory.
  if (writer)
    xmlFreeTextWriter(writer);
  if (buffer)
    xmlBufferFree(buffer);
}
コード例 #19
0
ファイル: qgswrite.c プロジェクト: collinanderson/cptutils
extern int qgs_write(const char *path, qgs_t *qgs)
{
  xmlBuffer *buffer;
  int err = 0;

  if ((buffer = xmlBufferCreate()) != NULL)
    {
      xmlTextWriter *writer;

      if ((writer = xmlNewTextWriterMemory(buffer, 0)) != NULL)
        {
          /*
            we free the writer at the start of each of
            these branches since this must be done before
            using the buffer
          */

          if (qgs_write_mem(writer, qgs) == 0)
            {
              xmlFreeTextWriter(writer);

	      if (path)
                {
                  FILE* fp;

                  if ((fp = fopen(path, "w")) != NULL)
                    {
                      fprintf(fp, "%s", buffer->content);

                      if (fclose(fp) != 0)
                        {
                          btrace("error closing file %s", path);
                          err = 1;
                        }
                    }
                  else
                    {
                      btrace("error opening file %s", path);
                      err = 1;
                    }
                }
              else
                fprintf(stdout, "%s", buffer->content);
            }
          else
            {
              xmlFreeTextWriter(writer);

              btrace("failed memory write");
              err = 1;
            }
        }
      else
        {
          btrace("error creating the xml writer");
          err = 1;
        }
    }
  else
    {
      btrace("error creating xml writer buffer");
      err = 1;
    }

  xmlBufferFree(buffer);

  return err;
}
コード例 #20
0
// fetch contents of inventory folder
void fetch_system_folders(simgroup_ctx *sgrp, user_ctx *user,
			  void *user_priv) {
  uuid_t u; char tmp[40]; char uri[256];
  GRID_PRIV_DEF_SGRP(sgrp);
  USER_PRIV_DEF(user_priv);
  xmlTextWriterPtr writer;
  xmlBufferPtr buf;
  SoupMessage *msg;
  inv_items_req *req;
  
  assert(grid->inventory_server != NULL);

  buf = xmlBufferCreate();
  if(buf == NULL) goto fail;
  writer = xmlNewTextWriterMemory(buf, 0);
  if(writer == NULL) goto free_fail_1;
  
  if(xmlTextWriterStartDocument(writer,NULL,"UTF-8",NULL) < 0) 
    goto free_fail;
  if(xmlTextWriterStartElement(writer, BAD_CAST "RestSessionObjectOfGuid") < 0) 
    goto free_fail;
  user_get_session_id(user, u);
  uuid_unparse(u, tmp);
  if(xmlTextWriterWriteFormatElement(writer,BAD_CAST "SessionID",
				       "%s",tmp) < 0) goto free_fail;


  user_get_uuid(user, u);
  uuid_unparse(u, tmp);
  if(xmlTextWriterWriteFormatElement(writer,BAD_CAST "AvatarID",
				       "%s",tmp) < 0) goto free_fail;

  if(xmlTextWriterWriteFormatElement(writer,BAD_CAST "Body",
				       "%s",tmp) < 0) goto free_fail;
  if(xmlTextWriterEndElement(writer) < 0) 
    goto free_fail;

  if(xmlTextWriterEndDocument(writer) < 0) {
    printf("DEBUG: couldn't end XML document\n"); goto fail;
  }

  // FIXME - don't use fixed-length buffer, and handle missing trailing /
  snprintf(uri, 256, "%sSystemFolders/", grid->inventory_server);
  printf("DEBUG: sending inventory request to %s\n", uri);
  msg = soup_message_new ("POST", uri);
  // FIXME - avoid unnecessary strlen
  soup_message_set_request (msg, "application/xml",
			    SOUP_MEMORY_COPY, (char*)buf->content, 
			    strlen ((char*)buf->content));
  req = new inv_items_req();
  req->user_glue = user_glue; 
  user_grid_glue_ref(user_glue);
  caj_queue_soup_message(sgrp, SOUP_MESSAGE(msg),
			 got_system_folders_resp, req);
    
  xmlFreeTextWriter(writer);  
  xmlBufferFree(buf);
  return;

 free_fail:
  xmlFreeTextWriter(writer);  
 free_fail_1:
  xmlBufferFree(buf);
 fail:
  printf("DEBUG: ran into issues sending inventory request\n");
  // FIXME - handle this
}
コード例 #21
0
void fetch_inventory_item(simgroup_ctx *sgrp, user_ctx *user,
			    void *user_priv, const uuid_t item_id,
			    void(*cb)(struct inventory_item* item, 
				      void* priv),
			    void *cb_priv) {
  uuid_t u, user_id; char tmp[40]; char uri[256];
  GRID_PRIV_DEF_SGRP(sgrp);
  USER_PRIV_DEF(user_priv);
  xmlTextWriterPtr writer;
  xmlBufferPtr buf;
  SoupMessage *msg;
  inv_item_req *req;
  struct os_inv_item invitem; // don't ask. Please.
  
  assert(grid->inventory_server != NULL);

  buf = xmlBufferCreate();
  if(buf == NULL) goto fail;
  writer = xmlNewTextWriterMemory(buf, 0);
  if(writer == NULL) goto free_fail_1;
  
  if(xmlTextWriterStartDocument(writer,NULL,"UTF-8",NULL) < 0) 
    goto free_fail;
  if(xmlTextWriterStartElement(writer, BAD_CAST "RestSessionObjectOfInventoryItemBase") < 0) 
    goto free_fail;
  user_get_session_id(user, u);
  uuid_unparse(u, tmp);
  if(xmlTextWriterWriteFormatElement(writer,BAD_CAST "SessionID",
				       "%s",tmp) < 0) goto free_fail;


  user_get_uuid(user, user_id);
  uuid_unparse(user_id, tmp);
  if(xmlTextWriterWriteFormatElement(writer,BAD_CAST "AvatarID",
				       "%s",tmp) < 0) goto free_fail;

  // okay, this is just painful... we have to serialise an entire complex
  // object in this cruddy .Net XML serialisation format... and the only bit
  // they actually use or need is a single UUID. Bletch  *vomit*.
  if(xmlTextWriterStartElement(writer,BAD_CAST "Body") < 0) 
    goto free_fail;
  memset(&invitem, 0, sizeof(invitem));
  invitem.name = invitem.description = const_cast<char*>("");
  invitem.creator_id = const_cast<char*>("");
  uuid_copy(invitem.owner_id, user_id);
  uuid_copy(invitem.item_id, item_id);

  osglue_serialise_xml(writer, deserialise_inv_item, &invitem);

  if(xmlTextWriterEndElement(writer) < 0) 
    goto free_fail;

  // now we should be done serialising the XML crud.

  if(xmlTextWriterEndElement(writer) < 0) 
    goto free_fail;

  if(xmlTextWriterEndDocument(writer) < 0) {
    printf("DEBUG: couldn't end XML document\n"); goto fail;
  }

  // FIXME - don't use fixed-length buffer, and handle missing trailing /
  snprintf(uri, 256, "%sQueryItem/", grid->inventory_server);
  printf("DEBUG: sending inventory request to %s\n", uri);
  msg = soup_message_new ("POST", uri);
  // FIXME - avoid unnecessary strlen
  soup_message_set_request (msg, "text/xml",
			    SOUP_MEMORY_COPY, (char*)buf->content, 
			    strlen ((char*)buf->content));
  req = new inv_item_req();
  req->user_glue = user_glue; req->cb = cb;
  req->cb_priv = cb_priv;
  uuid_copy(req->item_id, item_id);
  user_grid_glue_ref(user_glue);
  caj_queue_soup_message(sgrp, SOUP_MESSAGE(msg),
			 got_inventory_item_resp, req);
    
  xmlFreeTextWriter(writer);  
  xmlBufferFree(buf);
  return;

 free_fail:
  xmlFreeTextWriter(writer);  
 free_fail_1:
  xmlBufferFree(buf);
 fail:
  printf("DEBUG: ran into issues sending inventory QueryItem request\n");
  cb(NULL, cb_priv);
  // FIXME - handle this
  
}
コード例 #22
0
AXIS2_EXTERN axiom_xml_writer_t *AXIS2_CALL
axiom_xml_writer_create_for_memory(
    const axutil_env_t * env,
    axis2_char_t * encoding,
    int is_prefix_default,
    int compression,
    int type)
{
    axis2_libxml2_writer_wrapper_impl_t *writer_impl = NULL;
    AXIS2_ENV_CHECK(env, NULL);
    writer_impl = (axis2_libxml2_writer_wrapper_impl_t *)AXIS2_MALLOC(env->allocator,
        sizeof(axis2_libxml2_writer_wrapper_impl_t));
    if(!writer_impl)
    {
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory. Cannot create writer wrapper");
        return NULL;
    }

    writer_impl->encoding = NULL;
    writer_impl->buffer = NULL;
    writer_impl->doc = NULL;
    writer_impl->in_empty_element = AXIS2_FALSE;
    writer_impl->in_start_element = AXIS2_FALSE;
    writer_impl->stack = NULL;
    writer_impl->uri_prefix_map = NULL;
    writer_impl->default_lang_namespace = NULL;
    writer_impl->compression = compression;

    if(AXIS2_XML_PARSER_TYPE_BUFFER == type)
    {
        writer_impl->writer_type = AXIS2_XML_PARSER_TYPE_BUFFER;
        writer_impl->buffer = xmlBufferCreate();
        if(!(writer_impl->buffer))
        {
            axis2_libxml2_writer_wrapper_free(&(writer_impl->writer), env);
            AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
                "No memory. Cannot create a buffer for writer wrapper");
            return NULL;
        }

        writer_impl->xml_writer = xmlNewTextWriterMemory(writer_impl->buffer, 0);
    }
    else if(AXIS2_XML_PARSER_TYPE_DOC == type)
    {
        writer_impl->writer_type = AXIS2_XML_PARSER_TYPE_DOC;
        writer_impl->xml_writer = xmlNewTextWriterDoc(&writer_impl->doc, 0);
    }
    else
    {
        axis2_libxml2_writer_wrapper_free(&(writer_impl->writer), env);
        AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_XML_PARSER_INVALID_MEM_TYPE, AXIS2_FAILURE);
        return NULL;
    }

    if(!(writer_impl->xml_writer))
    {
        axis2_libxml2_writer_wrapper_free(&(writer_impl->writer), env);
        AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_CREATING_XML_STREAM_WRITER, AXIS2_FAILURE);
        return NULL;
    }

    if(encoding)
    {
        writer_impl->encoding = axutil_strdup(env, encoding);
    }
    else
    {
        writer_impl->encoding = axutil_strdup(env, ENCODING);
    }

    writer_impl->uri_prefix_map = axutil_hash_make(env);
    if(!(writer_impl->uri_prefix_map))
    {
        axis2_libxml2_writer_wrapper_free(&(writer_impl->writer), env);
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory. Cannot create URI prefix hash map");
        return NULL;
    }
    writer_impl->stack = axutil_stack_create(env);
    if(!(writer_impl->stack))
    {
        axis2_libxml2_writer_wrapper_free(&(writer_impl->writer), env);
        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
            "No memory. Cannot create the stack for writer wrapper");
        return NULL;
    }

    writer_impl->writer.ops = &axiom_xml_writer_ops_var;

    return &(writer_impl->writer);
}
コード例 #23
0
/**
 * testXmlwriterMemory:
 * @file: the output file
 *
 * test the xmlWriter interface when writing to memory
 */
void
testXmlwriterMemory(const char *file)
{
    int rc;
    xmlTextWriterPtr writer;
    xmlBufferPtr buf;
    xmlChar *tmp;
    FILE *fp;

    /* Create a new XML buffer, to which the XML document will be
     * written */
    buf = xmlBufferCreate();
    if (buf == NULL) {
        printf("testXmlwriterMemory: Error creating the xml buffer\n");
        return;
    }

    /* Create a new XmlWriter for memory, with no compression.
     * Remark: there is no compression for this kind of xmlTextWriter */
    writer = xmlNewTextWriterMemory(buf, 0);
    if (writer == NULL) {
        printf("testXmlwriterMemory: Error creating the xml writer\n");
        return;
    }

    /* Start the document with the xml default for the version,
     * encoding ISO 8859-1 and the default for the standalone
     * declaration. */
    rc = xmlTextWriterStartDocument(writer, NULL, MY_ENCODING, NULL);
    if (rc < 0) {
        printf
            ("testXmlwriterMemory: Error at xmlTextWriterStartDocument\n");
        return;
    }

    /* Start an element named "EXAMPLE". Since thist is the first
     * element, this will be the root element of the document. */
    rc = xmlTextWriterStartElement(writer, BAD_CAST "EXAMPLE");
    if (rc < 0) {
        printf
            ("testXmlwriterMemory: Error at xmlTextWriterStartElement\n");
        return;
    }

    /* Write a comment as child of EXAMPLE.
     * Please observe, that the input to the xmlTextWriter functions
     * HAS to be in UTF-8, even if the output XML is encoded
     * in iso-8859-1 */
    tmp = ConvertInput("This is a comment with special chars: <äöü>",
                       MY_ENCODING);
    rc = xmlTextWriterWriteComment(writer, tmp);
    if (rc < 0) {
        printf
            ("testXmlwriterMemory: Error at xmlTextWriterWriteComment\n");
        return;
    }
    if (tmp != NULL) xmlFree(tmp);

    /* Start an element named "ORDER" as child of EXAMPLE. */
    rc = xmlTextWriterStartElement(writer, BAD_CAST "ORDER");
    if (rc < 0) {
        printf
            ("testXmlwriterMemory: Error at xmlTextWriterStartElement\n");
        return;
    }

    /* Add an attribute with name "version" and value "1.0" to ORDER. */
    rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "version",
                                     BAD_CAST "1.0");
    if (rc < 0) {
        printf
            ("testXmlwriterMemory: Error at xmlTextWriterWriteAttribute\n");
        return;
    }

    /* Add an attribute with name "xml:lang" and value "de" to ORDER. */
    rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "xml:lang",
                                     BAD_CAST "de");
    if (rc < 0) {
        printf
            ("testXmlwriterMemory: Error at xmlTextWriterWriteAttribute\n");
        return;
    }

    /* Write a comment as child of ORDER */
    tmp = ConvertInput("<äöü>", MY_ENCODING);
    rc = xmlTextWriterWriteFormatComment(writer,
		     "This is another comment with special chars: %s",
                                         tmp);
    if (rc < 0) {
        printf
            ("testXmlwriterMemory: Error at xmlTextWriterWriteFormatComment\n");
        return;
    }
    if (tmp != NULL) xmlFree(tmp);

    /* Start an element named "HEADER" as child of ORDER. */
    rc = xmlTextWriterStartElement(writer, BAD_CAST "HEADER");
    if (rc < 0) {
        printf
            ("testXmlwriterMemory: Error at xmlTextWriterStartElement\n");
        return;
    }

    /* Write an element named "X_ORDER_ID" as child of HEADER. */
    rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "X_ORDER_ID",
                                         "%010d", 53535);
    if (rc < 0) {
        printf
            ("testXmlwriterMemory: Error at xmlTextWriterWriteFormatElement\n");
        return;
    }

    /* Write an element named "CUSTOMER_ID" as child of HEADER. */
    rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "CUSTOMER_ID",
                                         "%d", 1010);
    if (rc < 0) {
        printf
            ("testXmlwriterMemory: Error at xmlTextWriterWriteFormatElement\n");
        return;
    }

    /* Write an element named "NAME_1" as child of HEADER. */
    tmp = ConvertInput("Müller", MY_ENCODING);
    rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_1", tmp);
    if (rc < 0) {
        printf
            ("testXmlwriterMemory: Error at xmlTextWriterWriteElement\n");
        return;
    }
    if (tmp != NULL) xmlFree(tmp);

    /* Write an element named "NAME_2" as child of HEADER. */
    tmp = ConvertInput("Jörg", MY_ENCODING);
    rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_2", tmp);

    if (rc < 0) {
        printf
            ("testXmlwriterMemory: Error at xmlTextWriterWriteElement\n");
        return;
    }
    if (tmp != NULL) xmlFree(tmp);

    /* Close the element named HEADER. */
    rc = xmlTextWriterEndElement(writer);
    if (rc < 0) {
        printf("testXmlwriterMemory: Error at xmlTextWriterEndElement\n");
        return;
    }

    /* Start an element named "ENTRIES" as child of ORDER. */
    rc = xmlTextWriterStartElement(writer, BAD_CAST "ENTRIES");
    if (rc < 0) {
        printf
            ("testXmlwriterMemory: Error at xmlTextWriterStartElement\n");
        return;
    }

    /* Start an element named "ENTRY" as child of ENTRIES. */
    rc = xmlTextWriterStartElement(writer, BAD_CAST "ENTRY");
    if (rc < 0) {
        printf
            ("testXmlwriterMemory: Error at xmlTextWriterStartElement\n");
        return;
    }

    /* Write an element named "ARTICLE" as child of ENTRY. */
    rc = xmlTextWriterWriteElement(writer, BAD_CAST "ARTICLE",
                                   BAD_CAST "<Test>");
    if (rc < 0) {
        printf
            ("testXmlwriterMemory: Error at xmlTextWriterWriteElement\n");
        return;
    }

    /* Write an element named "ENTRY_NO" as child of ENTRY. */
    rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "ENTRY_NO", "%d",
                                         10);
    if (rc < 0) {
        printf
            ("testXmlwriterMemory: Error at xmlTextWriterWriteFormatElement\n");
        return;
    }

    /* Close the element named ENTRY. */
    rc = xmlTextWriterEndElement(writer);
    if (rc < 0) {
        printf("testXmlwriterMemory: Error at xmlTextWriterEndElement\n");
        return;
    }

    /* Start an element named "ENTRY" as child of ENTRIES. */
    rc = xmlTextWriterStartElement(writer, BAD_CAST "ENTRY");
    if (rc < 0) {
        printf
            ("testXmlwriterMemory: Error at xmlTextWriterStartElement\n");
        return;
    }

    /* Write an element named "ARTICLE" as child of ENTRY. */
    rc = xmlTextWriterWriteElement(writer, BAD_CAST "ARTICLE",
                                   BAD_CAST "<Test 2>");
    if (rc < 0) {
        printf
            ("testXmlwriterMemory: Error at xmlTextWriterWriteElement\n");
        return;
    }

    /* Write an element named "ENTRY_NO" as child of ENTRY. */
    rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "ENTRY_NO", "%d",
                                         20);
    if (rc < 0) {
        printf
            ("testXmlwriterMemory: Error at xmlTextWriterWriteFormatElement\n");
        return;
    }

    /* Close the element named ENTRY. */
    rc = xmlTextWriterEndElement(writer);
    if (rc < 0) {
        printf("testXmlwriterMemory: Error at xmlTextWriterEndElement\n");
        return;
    }

    /* Close the element named ENTRIES. */
    rc = xmlTextWriterEndElement(writer);
    if (rc < 0) {
        printf("testXmlwriterMemory: Error at xmlTextWriterEndElement\n");
        return;
    }

    /* Start an element named "FOOTER" as child of ORDER. */
    rc = xmlTextWriterStartElement(writer, BAD_CAST "FOOTER");
    if (rc < 0) {
        printf
            ("testXmlwriterMemory: Error at xmlTextWriterStartElement\n");
        return;
    }

    /* Write an element named "TEXT" as child of FOOTER. */
    rc = xmlTextWriterWriteElement(writer, BAD_CAST "TEXT",
                                   BAD_CAST "This is a text.");
    if (rc < 0) {
        printf
            ("testXmlwriterMemory: Error at xmlTextWriterWriteElement\n");
        return;
    }

    /* Close the element named FOOTER. */
    rc = xmlTextWriterEndElement(writer);
    if (rc < 0) {
        printf("testXmlwriterMemory: Error at xmlTextWriterEndElement\n");
        return;
    }

    /* Here we could close the elements ORDER and EXAMPLE using the
     * function xmlTextWriterEndElement, but since we do not want to
     * write any other elements, we simply call xmlTextWriterEndDocument,
     * which will do all the work. */
    rc = xmlTextWriterEndDocument(writer);
    if (rc < 0) {
        printf("testXmlwriterMemory: Error at xmlTextWriterEndDocument\n");
        return;
    }

    xmlFreeTextWriter(writer);

    fp = fopen(file, "w");
    if (fp == NULL) {
        printf("testXmlwriterMemory: Error at fopen\n");
        return;
    }

    fprintf(fp, "%s", (const char *) buf->content);

    fclose(fp);

    xmlBufferFree(buf);
}
コード例 #24
0
ファイル: xlibxml.c プロジェクト: GNOME/gxml
/**
 * gxml_new_text_writer_memory:
 *
 * Deprecated: 0.15
 */
xmlTextWriterPtr gxml_new_text_writer_memory (xmlBufferPtr buffer, gint compression)
{
  g_return_val_if_fail (buffer != NULL, NULL);
  return xmlNewTextWriterMemory (buffer, compression);
}
コード例 #25
0
ファイル: xmlwriter.cpp プロジェクト: gfunkmonk2/mate-note
 XmlWriter::XmlWriter()
 {
   m_buf = xmlBufferCreate();
   m_writer = xmlNewTextWriterMemory(m_buf, 0);
 }
コード例 #26
0
ファイル: xmlrpc.c プロジェクト: kevinlovesing/linphone
static void format_request(LinphoneXmlRpcRequest *request) {
    char si[64];
    belle_sip_list_t *arg_ptr = request->arg_list;
    xmlBufferPtr buf;
    xmlTextWriterPtr writer;
    int err;

    if (request->content != NULL) {
        belle_sip_free(request->content);
        request->content = NULL;
    }

    buf = xmlBufferCreate();
    if (buf == NULL) {
        ms_error("Error creating the XML buffer");
        return;
    }
    writer = xmlNewTextWriterMemory(buf, 0);
    if (writer == NULL) {
        ms_error("Error creating the XML writer");
        return;
    }

    err = xmlTextWriterStartDocument(writer, "1.0", "UTF-8", NULL);
    if (err >= 0) {
        err = xmlTextWriterStartElement(writer, (const xmlChar *)"methodCall");
    }
    if (err >= 0) {
        err = xmlTextWriterWriteElement(writer, (const xmlChar *)"methodName", (const xmlChar *)request->method);
    }
    if (err >= 0) {
        err = xmlTextWriterStartElement(writer, (const xmlChar *)"params");
    }
    while (arg_ptr != NULL) {
        LinphoneXmlRpcArg *arg = (LinphoneXmlRpcArg *)arg_ptr->data;
        if (err >= 0) {
            err = xmlTextWriterStartElement(writer, (const xmlChar *)"param");
        }
        if (err >= 0) {
            err = xmlTextWriterStartElement(writer, (const xmlChar *)"value");
        }
        switch (arg->type) {
        case LinphoneXmlRpcArgNone:
            break;
        case LinphoneXmlRpcArgInt:
            memset(si, 0, sizeof(si));
            snprintf(si, sizeof(si), "%i", arg->data.i);
            err = xmlTextWriterWriteElement(writer, (const xmlChar *)"int", (const xmlChar *)si);
            break;
        case LinphoneXmlRpcArgString:
            err = xmlTextWriterWriteElement(writer, (const xmlChar *)"string", (const xmlChar *)arg->data.s);
            break;
        }
        if (err >= 0) {
            /* Close the "value" element. */
            err = xmlTextWriterEndElement(writer);
        }
        if (err >= 0) {
            /* Close the "param" element. */
            err = xmlTextWriterEndElement(writer);
        }
        arg_ptr = arg_ptr->next;
    }
    if (err >= 0) {
        /* Close the "params" element. */
        err = xmlTextWriterEndElement(writer);
    }
    if (err >= 0) {
        /* Close the "methodCall" element. */
        err = xmlTextWriterEndElement(writer);
    }
    if (err >= 0) {
        err = xmlTextWriterEndDocument(writer);
    }
    if (err > 0) {
        /* xmlTextWriterEndDocument returns the size of the content. */
        request->content = belle_sip_strdup((const char *)buf->content);
    }
    xmlFreeTextWriter(writer);
    xmlBufferFree(buf);
}
コード例 #27
0
void add_inventory_item(simgroup_ctx *sgrp, user_ctx *user,
			void *user_priv, inventory_item *inv,
			void(*cb)(void* priv, int success, uuid_t item_id),
			void *cb_priv) {
  uuid_t u, user_id; char tmp[40]; char uri[256];
  GRID_PRIV_DEF_SGRP(sgrp);
  USER_PRIV_DEF(user_priv);
  xmlTextWriterPtr writer;
  xmlBufferPtr buf;
  SoupMessage *msg;
  add_inv_item_req *req;
  struct os_inv_item invitem;
  
  assert(grid->inventory_server != NULL);

  buf = xmlBufferCreate();
  if(buf == NULL) goto fail;
  writer = xmlNewTextWriterMemory(buf, 0);
  if(writer == NULL) goto free_fail_1;
  
  if(xmlTextWriterStartDocument(writer,NULL,"UTF-8",NULL) < 0) 
    goto free_fail;
  if(xmlTextWriterStartElement(writer, BAD_CAST "RestSessionObjectOfInventoryItemBase") < 0) 
    goto free_fail;
  user_get_session_id(user, u);
  uuid_unparse(u, tmp);
  if(xmlTextWriterWriteFormatElement(writer,BAD_CAST "SessionID",
				       "%s",tmp) < 0) goto free_fail;


  user_get_uuid(user, user_id);
  uuid_unparse(user_id, tmp);
  if(xmlTextWriterWriteFormatElement(writer,BAD_CAST "AvatarID",
				       "%s",tmp) < 0) goto free_fail;

  if(xmlTextWriterStartElement(writer,BAD_CAST "Body") < 0) 
    goto free_fail;

  inv_item_to_opensim(inv, invitem);
  osglue_serialise_xml(writer, deserialise_inv_item, &invitem);

  if(xmlTextWriterEndElement(writer) < 0) 
    goto free_fail;

  if(xmlTextWriterEndElement(writer) < 0) 
    goto free_fail;

  if(xmlTextWriterEndDocument(writer) < 0) {
    printf("DEBUG: couldn't end XML document\n"); goto fail;
  }

  // FIXME - don't use fixed-length buffer, and handle missing trailing /
  // (note: not AddNewItem, as that's not meant for sim use!)
  snprintf(uri, 256, "%sNewItem/", grid->inventory_server);
  printf("DEBUG: sending inventory add request to %s\n", uri);
  msg = soup_message_new ("POST", uri);
  // FIXME - avoid unnecessary strlen
  soup_message_set_request (msg, "text/xml",
			    SOUP_MEMORY_COPY, (char*)buf->content, 
			    strlen ((char*)buf->content));
  req = new add_inv_item_req();
  req->user_glue = user_glue; req->cb = cb;
  req->cb_priv = cb_priv;
  uuid_copy(req->item_id, inv->item_id);
  user_grid_glue_ref(user_glue);
  caj_queue_soup_message(sgrp, SOUP_MESSAGE(msg),
			 got_add_inv_item_resp, req);
    
  xmlFreeTextWriter(writer);  
  xmlBufferFree(buf);
  return;

 free_fail:
  xmlFreeTextWriter(writer);  
 free_fail_1:
  xmlBufferFree(buf);
 fail:
  printf("DEBUG: ran into issues sending inventory NewItem request\n");
  uuid_clear(u); cb(cb_priv, FALSE, u);
}
コード例 #28
0
gboolean
biji_lazy_serialize_internal (BijiLazySerializer *self)
{
  BijiLazySerializerPrivate *priv = self->priv;
  GList                     *tags;
  GdkRGBA                    color;
  gchar                     *date, *color_str;
  gboolean                   retval;
  const gchar               *path;
  GTimeVal                   time = {0, 0};

  priv->writer = xmlNewTextWriterMemory(priv->buf, 0);

  // Header
  xmlTextWriterStartDocument (priv->writer,"1.0","utf-8",NULL);

  xmlTextWriterStartElement (priv->writer, BAD_CAST "note");
  xmlTextWriterWriteAttributeNS (priv->writer, NULL, 
                                 BAD_CAST "version",NULL, 
                                 BAD_CAST "1");
  xmlTextWriterWriteAttributeNS (priv->writer, BAD_CAST "xmlns",
                                 BAD_CAST "link", NULL, 
                                 BAD_CAST "http://projects.gnome.org/bijiben/link");
  xmlTextWriterWriteAttributeNS (priv->writer, BAD_CAST "xmlns", BAD_CAST "size", NULL,
                                 BAD_CAST "http://projects.gnome.org/bijiben/size");
  xmlTextWriterWriteAttributeNS (priv->writer, NULL, BAD_CAST "xmlns", NULL, 
                                 BAD_CAST "http://projects.gnome.org/bijiben");

  // <Title>
  serialize_node (priv->writer,
                  "title",
                  (gchar*) biji_item_get_title (BIJI_ITEM (priv->note)));

  // <text> 
  xmlTextWriterWriteRaw(priv->writer, BAD_CAST "\n  ");
  xmlTextWriterStartElement(priv->writer, BAD_CAST "text");
  xmlTextWriterWriteAttributeNS(priv->writer, BAD_CAST "xml",
                                BAD_CAST "space", NULL, 
                                BAD_CAST "preserve");
  serialize_html (self);
  // </text>  
  xmlTextWriterEndElement(priv->writer);

  // <last-change-date>
  time.tv_sec = biji_item_get_mtime (BIJI_ITEM (priv->note));
  date = g_time_val_to_iso8601 (&time);
  if (date)
  {
    serialize_node (priv->writer, "last-change-date", date);
    g_free (date);
  }


  time.tv_sec = biji_note_obj_get_last_metadata_change_date (priv->note);
  date = g_time_val_to_iso8601 (&time);
  if (date)
  {
    serialize_node (priv->writer, "last-metadata-change-date", date);
    g_free (date);
  }


  time.tv_sec = biji_note_obj_get_create_date (priv->note);
  date = g_time_val_to_iso8601 (&time);
  if (date)
  {
    serialize_node (priv->writer, "create-date", date);
    g_free (date);
  }

  serialize_node (priv->writer, "cursor-position", "0");
  serialize_node (priv->writer, "selection-bound-position", "0");
  serialize_node (priv->writer, "width", "0");
  serialize_node (priv->writer, "height", "0");
  serialize_node (priv->writer, "x", "0");
  serialize_node (priv->writer, "y", "0");

  if (biji_note_obj_get_rgba (priv->note, &color))
  {
    color_str = gdk_rgba_to_string (&color);
    serialize_node (priv->writer, "color", color_str);
    g_free (color_str);
  }

  //<tags>
  xmlTextWriterWriteRaw(priv->writer, BAD_CAST "\n ");
  xmlTextWriterStartElement (priv->writer, BAD_CAST "tags");
  tags = biji_note_obj_get_notebooks (priv->note);
  g_list_foreach (tags, (GFunc) serialize_tags, priv->writer);
  xmlTextWriterEndElement (priv->writer);
  g_list_free (tags);

  // <open-on-startup>
  serialize_node (priv->writer, "open-on-startup", "False");

  // <note>
  xmlTextWriterWriteRaw(priv->writer, BAD_CAST "\n ");
  xmlTextWriterEndElement(priv->writer);

  xmlFreeTextWriter(priv->writer);

  path = biji_item_get_uuid (BIJI_ITEM (priv->note));
  retval = g_file_set_contents (path, (gchar*) priv->buf->content, -1, NULL);

  return retval;
}
コード例 #29
0
ファイル: xml.c プロジェクト: pagolo/internet-icon
int write_config(void) {
  int rc, result = 0;
  char *config_name = ".internet_icon";
  xmlTextWriterPtr writer;
#ifdef MEMORY
  int fd;
  xmlBufferPtr buf;

  /* Create a new XML buffer, to which the XML document will be
   * written */
  buf = xmlBufferCreate();
  if (buf == NULL) {
    return 0;
  }

  /* Create a new XmlWriter for memory, with no compression.
   * Remark: there is no compression for this kind of xmlTextWriter */
  writer = xmlNewTextWriterMemory(buf, 0);
  if (writer == NULL) {
    xmlBufferFree(buf);
    return 0;
  }
#else
  // create the file
  writer = xmlNewTextWriterFilename(config_name, 0);
  if (writer == NULL) return 0;
#endif

  // start the document
  rc = xmlTextWriterStartDocument(writer, NULL, NULL, NULL);
  if (rc < 0) goto finish;
  // root element
  rc = xmlTextWriterStartElement(writer, BAD_CAST "internet_icon");
  if (rc < 0) goto finish;
  // newline
  rc = xmlTextWriterWriteString(writer, BAD_CAST "\n  ");
  if (rc < 0) goto finish;
  /////////////////////////////////////
  // timeout
  char *tm = mysprintf ("%d", cfg.timeout_seconds);
  rc = xmlTextWriterWriteElement(writer, BAD_CAST "timeout", BAD_CAST tm);
  free (tm);
  if (rc < 0) goto finish;
  // newline
  rc = xmlTextWriterWriteString(writer, BAD_CAST "\n  ");
  if (rc < 0) goto finish;
  // test_ip
  rc = xmlTextWriterWriteElement(writer, BAD_CAST "test_ip", BAD_CAST cfg.test_ip);
  if (rc < 0) goto finish;
  // newline
  rc = xmlTextWriterWriteString(writer, BAD_CAST "\n  ");
  if (rc < 0) goto finish;
  // the port
  char *port = mysprintf ("%d", cfg.test_port);
  rc = xmlTextWriterWriteElement(writer, BAD_CAST "test_port", BAD_CAST port);
  free (port);
  if (rc < 0) goto finish;
  // newline
  rc = xmlTextWriterWriteString(writer, BAD_CAST "\n  ");
  if (rc < 0) goto finish;
  // operating mode
  rc = xmlTextWriterWriteElement(writer, BAD_CAST "opmode", BAD_CAST flag_value[cfg.op_mode]);
  if (rc < 0) goto finish;
  // newline
  rc = xmlTextWriterWriteString(writer, BAD_CAST "\n  ");
  if (rc < 0) goto finish;
  // wan ip page
  rc = xmlTextWriterWriteElement(writer, BAD_CAST "wan_ip_page", BAD_CAST cfg.wanip_page);
  if (rc < 0) goto finish;
  // newline
  rc = xmlTextWriterWriteString(writer, BAD_CAST "\n  ");
  if (rc < 0) goto finish;
  // wan ip page
  rc = xmlTextWriterWriteElement(writer, BAD_CAST "user_agent", BAD_CAST cfg.user_agent);
  if (rc < 0) goto finish;
  // newline
  rc = xmlTextWriterWriteString(writer, BAD_CAST "\n");
  if (rc < 0) goto finish;
  /* Close the start element. */
  rc = xmlTextWriterEndElement(writer);
  if (rc < 0) goto finish;
  /////////////////////////////////////
  /* Close all. */
  rc = xmlTextWriterEndDocument(writer);
  if (rc < 0) goto finish;

#ifdef MEMORY
  xmlFreeTextWriter(writer);
  writer = NULL;

  remove(config_name);
  fd = open(config_name, O_CREAT | O_RDWR | O_TRUNC, 0600);
  if (fd < 0) goto finish;
  write(fd, (const void *) buf->content, strlen((const char *)buf->content));
  close(fd);
#endif

  result = 1;

finish:
  if (writer) xmlFreeTextWriter(writer);
#ifdef MEMORY
  xmlBufferFree(buf);
#endif
  return result;
}
コード例 #30
0
int
rsstool_write_xml (st_rsstool_t *rt)
{
#define XMLPRINTF(s) xmlTextWriterWriteString(writer,BAD_CAST s)
  st_rss_t rss;
  int i = 0;
  xmlTextWriterPtr writer;
  xmlBufferPtr buffer;
  st_hash_t *dl_url_h = NULL;
  st_hash_t *url_h = NULL;
  st_hash_t *title_h = NULL;
  int items = rsstool_get_item_count (rt);
#define ENCODE(s) s
//#define ENCODE(s) base64_enc(s,0)
//#define ENCODE(s) str_escape_xml(s)

  memset (&rss, 0, sizeof (st_rss_t));

  if (!(buffer = xmlBufferCreate ()))
    return -1;

  if (!(writer = xmlNewTextWriterMemory (buffer, 0)))
    return -1;

  xmlTextWriterStartDocument (writer, NULL, "UTF-8", NULL);

  xmlTextWriterWriteComment (writer, BAD_CAST " RSStool - read, parse, merge and write RSS and Atom feeds\n"                            
    "http://rsstool.berlios.de ");

  XMLPRINTF("\n");

  xmlTextWriterWriteComment (writer, BAD_CAST "\n"
         "format:\n"
         "item[]\n"
         "  dl_url           \n"
         "  dl_url_md5\n"
         "  dl_url_crc32\n"
         "  dl_date\n"
         "  user             author\n"
         "  site\n"
         "  url              \n"
         "  url_md5\n"
         "  url_crc32\n"
         "  date             default: current time\n"
         "  title            used by searches for related items\n"
         "  title_md5\n"
         "  title_crc32\n"
         "  desc             description\n"
         "  media_keywords   default: keywords from title and description\n"
         "  media_duration   event length\n"
         "  media_image      thumbnail\n"
         "  event_start      default: date\n"
         "  event_end        default: event_start + media_duration\n"
);

  XMLPRINTF("\n");

  xmlTextWriterStartElement (writer, BAD_CAST "rsstool");  // <rsstool>
  xmlTextWriterWriteAttribute (writer, BAD_CAST "version", BAD_CAST RSSTOOL_VERSION_S);

  for (i = 0; i < items && i < RSSMAXITEM; i++)
//  for (i = 0; i < items; i++)
    {
      dl_url_h = hash_open (HASH_MD5|HASH_CRC32);
      url_h = hash_open (HASH_MD5|HASH_CRC32);
      title_h = hash_open (HASH_MD5|HASH_CRC32);

      dl_url_h = hash_update (dl_url_h, (const unsigned char *) rt->item[i]->feed_url, strlen (rt->item[i]->feed_url));
      url_h = hash_update (url_h, (const unsigned char *) rt->item[i]->url, strlen (rt->item[i]->url));
      title_h = hash_update (title_h, (const unsigned char *) rt->item[i]->title, strlen (rt->item[i]->title));

      XMLPRINTF("\n  ");

      xmlTextWriterStartElement (writer, BAD_CAST "item"); // <item>

      XMLPRINTF("\n    ");

//      xmlTextWriterWriteElement (writer, BAD_CAST "dl_url", BAD_CAST rt->item[i]->feed_url);
      xmlTextWriterWriteFormatElement (writer, BAD_CAST "dl_url", "%s", rt->item[i]->feed_url);

      XMLPRINTF("\n    ");

      xmlTextWriterWriteFormatElement (writer, BAD_CAST "dl_url_md5", "%s", hash_get_s (dl_url_h, HASH_MD5));

      XMLPRINTF("\n    ");

      xmlTextWriterWriteFormatElement (writer, BAD_CAST "dl_url_crc32", "%u", hash_get_crc32 (dl_url_h));

      XMLPRINTF("\n    ");

      xmlTextWriterWriteFormatElement (writer, BAD_CAST "dl_date", "%ld", rsstool.start_time);

      XMLPRINTF("\n    ");

      xmlTextWriterWriteFormatElement (writer, BAD_CAST "user", "%s", ENCODE (rt->item[i]->user));

      XMLPRINTF("\n    ");

      xmlTextWriterWriteFormatElement (writer, BAD_CAST "site", "%s", ENCODE (rt->item[i]->site));

      XMLPRINTF("\n    ");

      xmlTextWriterWriteFormatElement (writer, BAD_CAST "url", "%s", rt->item[i]->url);

      XMLPRINTF("\n    ");

      xmlTextWriterWriteFormatElement (writer, BAD_CAST "url_md5", "%s", hash_get_s (url_h, HASH_MD5));

      XMLPRINTF("\n    ");

      xmlTextWriterWriteFormatElement (writer, BAD_CAST "url_crc32", "%u", hash_get_crc32 (url_h));

      XMLPRINTF("\n    ");

      xmlTextWriterWriteFormatElement (writer, BAD_CAST "date", "%ld", rt->item[i]->date);

      XMLPRINTF("\n    ");

      xmlTextWriterWriteFormatElement (writer, BAD_CAST "title", "%s", ENCODE (rt->item[i]->title));


      XMLPRINTF("\n    ");

      xmlTextWriterWriteFormatElement (writer, BAD_CAST "title_md5", "%s", hash_get_s (title_h, HASH_MD5));

      XMLPRINTF("\n    ");

      xmlTextWriterWriteFormatElement (writer, BAD_CAST "title_crc32", "%u", hash_get_crc32 (title_h));

      XMLPRINTF("\n    ");

      xmlTextWriterWriteFormatElement (writer, BAD_CAST "desc", "%s", ENCODE (rt->item[i]->desc));

      XMLPRINTF("\n    ");

      xmlTextWriterWriteFormatElement (writer, BAD_CAST "media_keywords", "%s", ENCODE (rt->item[i]->media_keywords));

      XMLPRINTF("\n    ");

      xmlTextWriterWriteFormatElement (writer, BAD_CAST "media_duration", "%ld", rt->item[i]->media_duration);

      XMLPRINTF("\n    ");

      xmlTextWriterWriteFormatElement (writer, BAD_CAST "media_image", "%s", rt->item[i]->media_image);

      XMLPRINTF("\n    ");

      xmlTextWriterWriteFormatElement (writer, BAD_CAST "event_start", "%ld", rt->item[i]->event_start);

      XMLPRINTF("\n    ");

      xmlTextWriterWriteFormatElement (writer, BAD_CAST "event_end", "%ld", rt->item[i]->event_end);

      XMLPRINTF("\n  ");

      xmlTextWriterEndElement (writer); // </item>

      hash_close (dl_url_h);
      hash_close (url_h);
      hash_close (title_h);
    }

  XMLPRINTF("\n");

  xmlTextWriterEndDocument (writer);  // </rsstool>

  xmlFreeTextWriter (writer);

  fputs ((const char *) buffer->content, rt->output_file);

  xmlBufferFree (buffer);

  if (items >= RSSMAXITEM)
    {
      char buf[MAXBUFSIZE];

      sprintf (buf, "can write only RSS feeds with up to %d items (was %d items)\n",
        RSSMAXITEM, items);
      rsstool_log (rt, buf);
    }

  return 0;
}