示例#1
0
文件: compat.c 项目: SammyK/php-src
PHP_XML_API XML_Parser
XML_ParserCreate_MM(const XML_Char *encoding, const XML_Memory_Handling_Suite *memsuite, const XML_Char *sep)
{
	XML_Parser parser;

	parser = (XML_Parser) emalloc(sizeof(struct _XML_Parser));
	memset(parser, 0, sizeof(struct _XML_Parser));
	parser->use_namespace = 0;
	parser->_ns_separator = NULL;

	parser->parser = xmlCreatePushParserCtxt((xmlSAXHandlerPtr) &php_xml_compat_handlers, (void *) parser, NULL, 0, NULL);
	if (parser->parser == NULL) {
		efree(parser);
		return NULL;
	}

	xmlCtxtUseOptions(parser->parser, XML_PARSE_OLDSAX);

	parser->parser->replaceEntities = 1;
	parser->parser->wellFormed = 0;
	if (sep != NULL) {
		parser->use_namespace = 1;
		parser->parser->sax2 = 1;
		parser->_ns_separator = xmlStrdup(sep);
	} else {
		/* Reset flag as XML_SAX2_MAGIC is needed for xmlCreatePushParserCtxt
		so must be set in the handlers */
		parser->parser->sax->initialized = 1;
	}
	return parser;
}
示例#2
0
void *WeatherCfg::processEvent(Event *e)
{
    if (e->type() == m_plugin->EventWeather){
        fill();
    }
    if (e->type() == EventFetchDone){
        fetchData *data = (fetchData*)(e->param());
        if (data->req_id != m_fetch_id)
            return NULL;
        m_fetch_id = 0;
        m_ids.clear();
        m_names.clear();
        m_id = "";
        m_data = "";
        m_context = xmlCreatePushParserCtxt(&m_handler, this, "", 0, "");
        if (xmlParseChunk(m_context, data->data->data(), data->data->size(), 0))
            log(L_WARN, "XML parse error");
        xmlFreeParserCtxt(m_context);
        btnSearch->setText(i18n("&Search"));
        QString oldText = cmbLocation->lineEdit()->text();
        cmbLocation->clear();
        if (m_ids.empty()){
            cmbLocation->lineEdit()->setText(oldText);
            BalloonMsg::message(i18n("Location %1 not found") .arg(oldText), btnSearch, false);
        }else{
            for (vector<string>::iterator it = m_names.begin(); it != m_names.end(); ++it)
                cmbLocation->insertItem(QString::fromUtf8((*it).c_str()));
            cmbLocation->setCurrentItem(0);
			activated(0);
        }
        textChanged(cmbLocation->lineEdit()->text());
        return e->param();
    }
    return NULL;
}
示例#3
0
ret_t
cherokee_handler_tmi_init (cherokee_handler_tmi_t *hdl)
{
    ret_t ret;
    cherokee_connection_t *conn = HANDLER_CONN(hdl);
    cherokee_buffer_t	 *tmp  = &HANDLER_THREAD(hdl)->tmp_buf1;
    cherokee_handler_tmi_props_t *props = HANDLER_TMI_PROPS(hdl);

    /* We are going to look for gzipped encoding */
    cherokee_buffer_clean (tmp);
    ret = cherokee_header_copy_known (&conn->header, header_content_encoding, tmp);
    if (ret == ret_ok && cherokee_buffer_cmp_str(tmp, "gzip") == 0) {
        TRACE(ENTRIES, "ZeroMQ: incomming header '%s'\n", tmp->buf);
        hdl->inflated = true;
    } else {
        cherokee_buffer_clean (tmp);
        ret = cherokee_header_copy_known (&conn->header, header_content_type, tmp);
        if (ret == ret_ok && (cherokee_buffer_cmp_str(tmp, "application/gzip") == 0 || cherokee_buffer_cmp_str(tmp, "application/zip") == 0)) {
            TRACE(ENTRIES, "ZeroMQ: incomming header '%s'\n", tmp->buf);
            hdl->inflated = true;
        } else {
            hdl->inflated = false;
        }
    }

#ifdef LIBXML_PUSH_ENABLED
    if (props->validate_xml) {
        hdl->validate_xml = true;
        hdl->ctxt = xmlCreatePushParserCtxt(NULL, NULL, NULL, 0, NULL);
        xmlCtxtUseOptions(hdl->ctxt, XML_PARSE_NOERROR | XML_PARSE_NOWARNING | XML_PARSE_NONET | XML_PARSE_COMPACT);

        if (hdl->inflated) {
            /* allocate inflate state */
            hdl->strm.zalloc = Z_NULL;
            hdl->strm.zfree = Z_NULL;
            hdl->strm.opaque = Z_NULL;
            hdl->strm.avail_in = 0;
            hdl->strm.next_in = Z_NULL;
            hdl->z_ret = inflateInit2(&(hdl->strm), 16+MAX_WBITS);
            if (hdl->z_ret != Z_OK)
                hdl->validate_xml = false;
        }
    }
#endif

    if (!hdl->inflated) {
        /* If we end up here that means content is plain, lets set up an encoder */
        ret = props->encoder_props->instance_func((void **)&hdl->encoder, props->encoder_props);
        if (unlikely (ret != ret_ok)) {
            return ret_error;
        }

        ret = cherokee_encoder_init (hdl->encoder, conn);
        if (unlikely (ret != ret_ok)) {
            return ret_error;
        }
    }

    return ret_ok;
}
示例#4
0
文件: ocr.c 项目: testfarm/testfarm
static void ocr_callback(ocr_t *ocr, char *buf, int size)
{
  if ( buf != NULL ) {
    dprintf("READ '%s'\n", buf);

    /* Create XML parser context if a new page is coming */
    if ( ocr->xml == NULL )
      ocr->xml = xmlCreatePushParserCtxt(&handlers, &(ocr->ctx), buf, size, "ocr-output");
    else
      xmlParseChunk(ocr->xml, buf, size, 0);

    if ( (ocr->xml != NULL) && (ocr->ctx.state == OCR_STATE_END) ) {
      /* End document parsing */
      xmlParseChunk(ocr->xml, buf, 0, 1);

      /* Free XML SAX parser */
      xmlFreeParserCtxt(ocr->xml);
      ocr->xml = NULL;

      ocr->ctx.state = OCR_STATE_IDLE;
    }
  }
  else {
    ocr_terminate(ocr);
  }
}
示例#5
0
文件: entry.c 项目: spotrh/LogJam
static gboolean
lj_entry_load_from_xml(LJEntry *entry, const char *data, int len, GError **err) {
	xmlNodePtr cur;
	xmlDocPtr  doc = NULL;
	xmlParserCtxtPtr ctxt;

	ctxt = xmlCreatePushParserCtxt(NULL, NULL,
				data, 4,
				NULL /* XXX why does this want a filename? */);
	/* suppress error messages */
	ctxt->sax->warning = NULL;
	ctxt->sax->error   = NULL;

	xmlParseChunk(ctxt, data+4, len-4, 0);
	xmlParseChunk(ctxt, data, 0, 1);
	if (!ctxt->errNo)
		doc = ctxt->myDoc;

	xmlFreeParserCtxt(ctxt);

	if (!doc) {
		/* XXX better error message. */
		g_set_error(err, 0, 0, "Error parsing XML");
		return FALSE;
	}

	cur = xmlDocGetRootElement(doc);
	lj_entry_load_from_xml_node(entry, doc, cur);
	xmlFreeDoc(doc);
	return TRUE;
}
示例#6
0
PHPAPI XML_Parser
XML_ParserCreate_MM(const XML_Char *encoding, const XML_Memory_Handling_Suite *memsuite, const XML_Char *sep)
{
	XML_Parser parser;

	parser = (XML_Parser) emalloc(sizeof(struct _XML_Parser));
	memset(parser, 0, sizeof(struct _XML_Parser));
	parser->use_namespace = 0;
	parser->_ns_seperator = NULL;

	parser->parser = xmlCreatePushParserCtxt((xmlSAXHandlerPtr) &php_xml_compat_handlers, (void *) parser, NULL, 0, NULL);
	if (parser->parser == NULL) {
		efree(parser);
		return NULL;
	}
#if LIBXML_VERSION <= 20617
	/* for older versions of libxml2, allow correct detection of
	 * charset in documents with a BOM: */
	parser->parser->charset = XML_CHAR_ENCODING_NONE;
#endif

	parser->parser->replaceEntities = 1;
	parser->parser->wellFormed = 0;
	if (sep != NULL) {
		parser->use_namespace = 1;
		parser->parser->sax2 = 1;
		parser->_ns_seperator = xmlStrdup(sep);
	} else {
		/* Reset flag as XML_SAX2_MAGIC is needed for xmlCreatePushParserCtxt 
		so must be set in the handlers */
		parser->parser->sax->initialized = 1;
	}
	return parser;
}
示例#7
0
bool WeatherPlugin::done(unsigned code, Buffer &data, const char*)
{
    if (code != 200)
        return false;
    m_data  = "";
    m_day   = 0;
    m_bBar  = false;
    m_bWind = false;
    m_bUv	= false;
    m_bCC	= false;
    m_context = xmlCreatePushParserCtxt(&m_handler, this, "", 0, "");
    if (xmlParseChunk(m_context, data.data(), data.size(), 0)){
        log(L_WARN, "XML parse error");
        xmlFreeParserCtxt(m_context);
        return false;
    }
    xmlFreeParserCtxt(m_context);
    time_t now;
    time(&now);
    setTime(now);
	if (m_bForecast)
		setForecastTime(now);
    updateButton();
    Event eUpdate(EventWeather);
    eUpdate.process();
    return false;
}
示例#8
0
int main(void)
{
	FILE *f;
	int ret;
	char chars[10];
	xmlParserCtxtPtr ctxt;
	xdebug_str message = {0, 0, NULL};

	xdebug_xml_reader_priv data;
	data.level   = 0;
	data.xml     = NULL;
	data.current = NULL;

	f = fopen("test.xml", "r");
	
	ctxt = xmlCreatePushParserCtxt(sax_handler_ptr, NULL, NULL, 0, "test");
	ctxt->_private = &data;
	while ((ret = fread(chars, 1, 3, f)) > 0) {
		xmlParseChunk(ctxt, chars, ret, 0);
	}
	xmlParseChunk(ctxt, chars, 0, 1);

	xdebug_xml_return_node(data.xml, &message);
	xdebug_xml_node_dtor(data.xml);
	printf("%s\n", message.d);
	xdebug_str_dtor(message);
	
	xmlFreeParserCtxt(ctxt);
	fclose(f);
	xmlCleanupParser();
	xmlMemoryDump();

	return 0;
}
示例#9
0
static void
soap_got_chunk (SoupMessage *msg,
                SoupBuffer *chunk,
                gpointer data)
{
	ESoapMessagePrivate *priv = E_SOAP_MESSAGE_GET_PRIVATE (msg);

	if (msg->status_code != 200)
		return;

	priv->response_received += chunk->length;

	if (priv->response_size && priv->progress_fn) {
		gint pc = priv->response_received * 100 / priv->response_size;
		priv->progress_fn (priv->progress_data, pc);
	}

	if (!priv->ctxt) {
		priv->ctxt = xmlCreatePushParserCtxt (NULL, msg, chunk->data,
						      chunk->length, NULL);
		priv->ctxt->_private = priv;
		priv->ctxt->sax->startElementNs = soap_sax_startElementNs;
		priv->ctxt->sax->endElementNs = soap_sax_endElementNs;
		priv->ctxt->sax->characters = soap_sax_characters;
	}
	else
		xmlParseChunk (priv->ctxt, chunk->data, chunk->length, 0);
}
示例#10
0
/* create a new CMML parser
 */
GstCmmlParser *
gst_cmml_parser_new (GstCmmlParserMode mode)
{
  GstCmmlParser *parser = g_malloc (sizeof (GstCmmlParser));

  parser->mode = mode;
  parser->context = xmlCreatePushParserCtxt (NULL, NULL,
      NULL, 0, "cmml-bitstream");
  xmlCtxtUseOptions (parser->context, XML_PARSE_NONET | XML_PARSE_NOERROR);
  parser->context->_private = parser;
  parser->context->sax->startElementNs =
      (startElementNsSAX2Func) gst_cmml_parser_parse_start_element_ns;
  parser->context->sax->endElementNs =
      (endElementNsSAX2Func) gst_cmml_parser_parse_end_element_ns;
  parser->context->sax->processingInstruction = (processingInstructionSAXFunc)
      gst_cmml_parser_parse_processing_instruction;
  parser->preamble_callback = NULL;
  parser->cmml_end_callback = NULL;
  parser->stream_callback = NULL;
  parser->head_callback = NULL;
  parser->clip_callback = NULL;
  parser->user_data = NULL;

  return parser;
}
示例#11
0
ParseXML::ParseXML(void* session, startElementNsSAX2Func start)
    : startElementNs(start)
    , endElementNs(NULL)
    , characters(NULL)
{
    XmlError MyError;
    MyError.Len = 0;
    xmlSetGenericErrorFunc(&MyError, ErrorCallback);

    xmlSAXHandler sax;
    memset(&sax, 0, sizeof(sax));
    sax.initialized = XML_SAX2_MAGIC;
    sax.startElementNs = _start;
    sax.endElementNs = _end;
    sax.characters = _char;

    mXmlContext = xmlCreatePushParserCtxt(&sax, this, NULL, 0, NULL);
    if(mXmlContext == NULL)
    {
        xmlSetGenericErrorFunc(NULL, NULL);
        throw std::runtime_error(MyError.Len != 0 ? MyError.Value : "XML Error");
    }

    curl_easy_setopt(session, CURLOPT_WRITEFUNCTION, ParseHandler);
    curl_easy_setopt(session, CURLOPT_WRITEDATA, this);
}
示例#12
0
/*
 * call-seq:
 *  initialize_native(xml_sax, filename)
 *
 * Initialize the push parser with +xml_sax+ using +filename+
 */
static VALUE initialize_native(VALUE self, VALUE _xml_sax, VALUE _filename)
{
  xmlSAXHandlerPtr sax;

  Data_Get_Struct(_xml_sax, xmlSAXHandler, sax);
  
  const char * filename = NULL;

  if(_filename != Qnil) filename = StringValuePtr(_filename);

  xmlParserCtxtPtr ctx = xmlCreatePushParserCtxt(
      sax,
      NULL,
      NULL,
      0,
      filename
  );
  if(ctx == NULL)
    rb_raise(rb_eRuntimeError, "Could not create a parser context");

  ctx->userData = NOKOGIRI_SAX_TUPLE_NEW(ctx, self);

  ctx->sax2 = 1;
  DATA_PTR(self) = ctx;
  return self;
}
示例#13
0
void* dxml_create(const char *optional_filename, int options) {
    DXML_T *parser;
    // allocate the structure to hold the parser information
    parser = (DXML_T*)mm_malloc(sizeof(DXML_T));
    // setup data store
    parser->data = create_parser_data(options, optional_filename);
    // setup meme xml callbacks
    parser->callbacks = (DREME_IO_XML_CALLBACKS_T*)mm_malloc(sizeof(DREME_IO_XML_CALLBACKS_T));
    memset(parser->callbacks, 0, sizeof(DREME_IO_XML_CALLBACKS_T));
    //start callbacks
    parser->callbacks->error = dxml_error;
    parser->callbacks->start_dreme = dxml_start_dreme;
    // start dreme
    // start model
    parser->callbacks->handle_background = dxml_handle_background;
    // end model
    // start motifs
    parser->callbacks->start_motif = dxml_start_motif;
    parser->callbacks->end_motif = dxml_end_motif;
    // start motif
    parser->callbacks->handle_pos = dxml_handle_pos;
    // end motif
    // end motifs
    // end dreme
    // end callbacks
    // setup context for SAX parser
    parser->sax_context = create_dreme_io_xml_sax_context(parser->data, parser->callbacks);
    // setup SAX handler
    parser->handler = (xmlSAXHandler*)mm_malloc(sizeof(xmlSAXHandler));
    register_dreme_io_xml_sax_handlers(parser->handler);
    // create the push parser context
    parser->ctxt = xmlCreatePushParserCtxt(parser->handler, parser->sax_context, NULL, 0, optional_filename);
    return parser;
}
示例#14
0
bool WeatherCfg::done(unsigned, Buffer &data, const char*)
{
    m_ids.clear();
    m_names.clear();
    m_id = "";
    m_data = "";
    m_context = xmlCreatePushParserCtxt(&m_handler, this, "", 0, "");
    if (xmlParseChunk(m_context, data.data(), data.size(), 0))
        log(L_WARN, "XML parse error");
    xmlFreeParserCtxt(m_context);
    btnSearch->setText(i18n("&Search"));
    QString oldText = cmbLocation->lineEdit()->text();
    cmbLocation->clear();
    if (m_ids.empty()){
        cmbLocation->lineEdit()->setText(oldText);
        BalloonMsg::message(i18n("Location %1 not found") .arg(oldText), btnSearch, false);
    }else{
        for (vector<string>::iterator it = m_names.begin(); it != m_names.end(); ++it)
            cmbLocation->insertItem(QString::fromUtf8((*it).c_str()));
        cmbLocation->setCurrentItem(0);
        activated(0);
    }
    textChanged(cmbLocation->lineEdit()->text());
    return false;
}
示例#15
0
文件: tcphelpers.c 项目: olger/xmlbus
xmlDocPtr _waitForAnswer(int sockfd) {
	xmlParserCtxtPtr requestParserCtxt;
	xmlDocPtr parsedDoc = NULL;
    int resRead = 0;
    int bytesRead = 0;
    int readTries = 0;
    int chunkParseResult = 0;
	
    char buffer[XMLBUS_CHUNK_READLENGTH + 1];
    resRead = recv(sockfd, buffer, XMLBUS_CHUNK_INITIAL_READLENGTH, 0);
    if (resRead > 0) {
        buffer[resRead] = '\0';
        requestParserCtxt = xmlCreatePushParserCtxt(NULL, NULL, buffer, resRead, NULL);
        bytesRead += resRead;
    } else {
        printf("Read failed socket readerror:%d -> closing clientsocket", resRead);
        return NULL;
    }
    xmlCtxtUseOptions(requestParserCtxt,XML_PARSE_NOWARNING); 
	
    while(1) {
        resRead = recv(sockfd, buffer, XMLBUS_CHUNK_READLENGTH, 0);
        buffer[resRead] = '\0';
        if (resRead > 0) {
            chunkParseResult = xmlParseChunk(requestParserCtxt,buffer,resRead,0);
            if (chunkParseResult != 0) {
                xmlErrorPtr xmlErr = xmlGetLastError();
                printf("request parsing found error %d: %s", chunkParseResult, xmlErr->message);
                //@TODO recover or bail out
            }
            if (requestParserCtxt->instate == XML_PARSER_EPILOG) {
                break;
            }
            bytesRead += resRead;
            continue;                             // don't need to parse it another time... it is done already
        }                                         // end of reading (no data received)
        else {
            // Closed connection or error (in this case there is no buffer content, is it ?)
            if (readTries < 5) {
                readTries++;
                continue;
            }
            else {
                // end of parsing (check if the xml is valid)
                if (bytesRead > 0) {
                    // end of reading, try to parse the message so far
                    break;
                }
                //log4c_category_error(loggerCategory, "thread %d read: data read failed, bailing out", threadId);
                //close(request->clientSocket);
                return NULL;
            }
        }                                         // end resRead > 0 .. else
    }                                             // end while(1)
    chunkParseResult = xmlParseChunk(requestParserCtxt, NULL, 0, 1);
	parsedDoc = requestParserCtxt->myDoc;
    xmlFreeParserCtxt(requestParserCtxt);
	return parsedDoc;	
}
示例#16
0
SAXParserPrivate::SAXParserPrivate(SAXParser *parser)
{
	m_parser = parser;
    memset(&m_handler, 0, sizeof(m_handler));
    m_handler.startElement = p_element_start;
    m_handler.endElement   = p_element_end;
    m_handler.characters   = p_char_data;
    m_context = xmlCreatePushParserCtxt(&m_handler, m_parser, "", 0, "");
}
示例#17
0
static int
create_parser(struct erim_xml_data *edd)
{
	/* Create a parser. */
	edd->parser = xmlCreatePushParserCtxt(&sax_handler, edd,
	    NULL, 0, NULL);
	if (edd->parser == NULL)
		return (-1);

	return (0);
}
/** 
 * Parses a descriptor that contains part of a document. 
 */
void CXMLEngineSAXPlugin::ParseChunkL(const TDesC8& aDescriptor)
	{	
	
	TInt result = KErrNone;
	
	if (!iParserContext)
		{		
		//creating sax parser object
	    iParserContext = xmlCreatePushParserCtxt( 
   						(xmlSAXHandler*) &iParserEvents, 
   						this, 
  						(const char *) aDescriptor.Ptr(), 
						aDescriptor.Length(),
   						NULL
   						);
		if(!iParserContext)
			{
			CleanupAndLeaveL(KErrNoMemory);			
			}
		
		//creating empty document object
		iParserContext->myDoc = xmlNewDoc(BAD_CAST "SAX compatibility mode document");
		if(!iParserContext->myDoc)
			{
			CleanupAndLeaveL(KErrNoMemory);			
			}
		iParserContext->myDoc->intSubset = xmlNewDtd(iParserContext->myDoc, BAD_CAST "fake", NULL, NULL);
		if(!iParserContext->myDoc->intSubset)
			{
			CleanupAndLeaveL(KErrNoMemory);			
			}
		
		//parsing process
	    result = xmlParseChunk(iParserContext, NULL, 0, 0);					
		}
	else
		{
		//parsing process
		result = xmlParseChunk(
				iParserContext, 
				(const char *) aDescriptor.Ptr(), 
				aDescriptor.Length(),
				0);		
		}
					
	//handling error situation
	//if fatal error, function throws exception 
	//in any other case next chunk is taken (recoverable)
	if ((result == XML_ERR_NO_MEMORY) || (iParserContext->lastError.level == XML_ERR_FATAL)
	        || (result < 0))
		{
		CleanupAndLeaveL(GetErrorNum(result));	
		}
	}
示例#19
0
static gboolean
xmms_xspf_browse (xmms_xform_t *xform, const gchar *url, xmms_error_t *error)
{
	int ret;
	char buf[4096];
	xmlParserCtxtPtr ctx;
	xmlDocPtr doc;

	g_return_val_if_fail (xform, FALSE);

	xmms_error_reset (error);

	ctx = xmlCreatePushParserCtxt (NULL, NULL, buf, 0, NULL);

	if (!ctx) {
		xmms_error_set (error, XMMS_ERROR_OOM, "Could not allocate xml parser");
		return FALSE;
	}

	while ((ret = xmms_xform_read (xform, buf, sizeof (buf), error)) > 0) {
		if ((xmlParseChunk (ctx, buf, ret, 0)) != 0) {
			break;
		}
	}

	if (ret < 0) {
		xmms_error_set (error, XMMS_ERROR_GENERIC,
		                "failed to read data from previous xform");
		xmlFreeParserCtxt (ctx);
		return FALSE;
	}

	xmlParseChunk (ctx, buf, 0, 1);

	if (ctx->lastError.message) {
		xmms_error_set (error, XMMS_ERROR_INVAL, ctx->lastError.message);
		xmlFreeParserCtxt (ctx);
		return FALSE;
	}

	doc = ctx->myDoc;

	if (!xmms_xspf_browse_add_entries (xform, doc, error)) {
		xmlFreeParserCtxt (ctx);
		return FALSE;
	}

	xmms_error_reset (error);
	xmlFreeParserCtxt (ctx);

	return TRUE;
}
示例#20
0
文件: utils.c 项目: UIKit0/libgrss
static void
_unxmlize (gchar *string, ResultBuffer *buffer)
{
	xmlParserCtxtPtr	ctxt;
	xmlSAXHandler		*sax_p;

	sax_p = g_new0 (xmlSAXHandler, 1);
 	sax_p->characters = unhtmlizeHandleCharacters;
	ctxt = xmlCreatePushParserCtxt (sax_p, buffer, string, strlen (string), "");
	xmlParseChunk (ctxt, string, 0, 1);
	xmlFreeParserCtxt (ctxt);
 	g_free(sax_p);
}
示例#21
0
XepParser::XepParser()
{
    memset(&m_handler, 0, sizeof(m_handler));
	m_handler.startElement = p_element_start;
	m_handler.endElement   = p_element_end;
	m_handler.characters   = p_char_data;
	m_handler.cdataBlock   = p_cdata;
	m_context = xmlCreatePushParserCtxt(&m_handler, this, "", 0, "");
    m_data  = NULL;
    m_bRec = false;
    m_width  = 0;
    m_height = 0;
}
示例#22
0
static gboolean
xmms_rss_browse (xmms_xform_t *xform, const gchar *url, xmms_error_t *error)
{
	int ret;
	char buffer[1024];
	xmlSAXHandler handler;
	xmlParserCtxtPtr ctx;
	xmms_rss_data_t data;

	g_return_val_if_fail (xform, FALSE);

	memset (&handler, 0, sizeof (handler));
	memset (&data, 0, sizeof (data));

	handler.startElement = (startElementSAXFunc) xmms_rss_start_element;
	handler.error = (errorSAXFunc) xmms_rss_error;
	handler.fatalError = (fatalErrorSAXFunc) xmms_rss_error;

	data.xform = xform;
	data.error = error;
	data.parse_failure = FALSE;

	xmms_error_reset (error);

	ctx = xmlCreatePushParserCtxt (&handler, &data, buffer, 0, NULL);
	if (!ctx) {
		xmms_error_set (error, XMMS_ERROR_OOM,
		                "Could not allocate xml parser");
		return FALSE;
	}

	while ((ret = xmms_xform_read (xform, buffer, sizeof (buffer), error)) > 0) {
		xmlParseChunk (ctx, buffer, ret, 0);
	}

	if (ret < 0) {
		xmms_error_set (error, XMMS_ERROR_GENERIC, "xmms_xform_read failed");
		return FALSE;
	}

	if (data.parse_failure)
		return FALSE;

	xmlParseChunk (ctx, buffer, 0, 1);

	xmms_error_reset (error);
	xmlFreeParserCtxt (ctx);

	return TRUE;
}
示例#23
0
S3Status simplexml_add(SimpleXml *simpleXml, const char *data, int dataLen)
{
    if (!simpleXml->xmlParser &&
        (!(simpleXml->xmlParser = xmlCreatePushParserCtxt
           (&saxHandlerG, simpleXml, 0, 0, 0)))) {
        return S3StatusInternalError;
    }

    if (xmlParseChunk((xmlParserCtxtPtr) simpleXml->xmlParser, 
                      data, dataLen, 0)) {
        return S3StatusXmlParseFailure;
    }

    return simpleXml->status;
}
示例#24
0
void CXMPPSocket::ReadData(const char *data, size_t len) {
	if (m_bResetParser) {
		m_uiDepth = 0;

		if (m_xmlContext) {
			xmlFreeParserCtxt(m_xmlContext);
		}

		m_xmlContext = xmlCreatePushParserCtxt(&m_xmlHandlers, this, NULL, 0, NULL);

		m_bResetParser = false;
	}

	xmlParseChunk(m_xmlContext, data, len, 0);
}
示例#25
0
static Eupnp_Service_Parser *
eupnp_service_parser_new(const char *first_chunk, int first_chunk_len, Eupnp_Service_Proxy *d)
{
   if (first_chunk_len < 4)
     {
	WRN("First chunk length less than 4 chars, user must provide more than 4.");
	return NULL;
     }

   Eupnp_Service_Parser *p;

   p = calloc(1, sizeof(Eupnp_Service_Parser));

   if (!p)
     {
	ERR("Failed to alloc for service parser");
	return NULL;
     }

   p->handler.initialized = XML_SAX2_MAGIC;
   p->handler.characters = &_characters;
   p->handler.error = &error;
   p->handler.startElementNs = &start_element_ns;
   p->handler.endElementNs = &end_element_ns;

   /*
    * Setup parser state to START, attach the service info object that
    * will get data written into.
    */
   p->state.state = START;
   p->state.data = d;
   p->state.send_events = EINA_TRUE; // default is YES

   p->ctx = xmlCreatePushParserCtxt(&p->handler, &p->state, first_chunk,
				    first_chunk_len, NULL);

   // Force first chunk parse. When not forced, the parser gets lazy on the
   // first time and doesn't parse one-big-chunk feeds.
   xmlParseChunk(p->ctx, NULL, 0, 0);

   if (!p->ctx)
     {
	free(p);
	return NULL;
     }

   return p;
}
示例#26
0
xmlDocPtr ParseXML(SDL_RWops *io)
{
    const size_t bufsize = 1024;
    size_t res;
    char buf [bufsize];

    xmlParserCtxtPtr ctxt;
    xmlDocPtr doc;

    // read first 4 bytes
    if ((res = io->read (io, buf, 1, 4)) < 4)
    {
        SetError ("Failed to read first xml bytes: %s", SDL_GetError ());
        return NULL;
    }

    // Create a progressive parsing context
    ctxt = xmlCreatePushParserCtxt (NULL, NULL, buf, res, NULL);
    if (! ctxt) {
        SetError ("Failed to create parser context!");
        return NULL;
    }

    // loop on the input getting the document data
    while ((res = io->read (io, buf, 1, bufsize)) > 0) {

        xmlParseChunk (ctxt, buf, res, 0);
    }

    // there is no more input, indicate the parsing is finished.
    xmlParseChunk (ctxt, buf, 0, 1);

    // check if it was well formed
    doc = ctxt->myDoc;
    res = ctxt->wellFormed;
    xmlFreeParserCtxt (ctxt);

    if (!res) {

        SetError ("xml document is not well formed");

        xmlFreeDoc (doc);
        doc = NULL;
    }

    return doc;
}
示例#27
0
/* shuts down and restarts XML parser.  true on success */
int parser_reset(parser_t *parser)
{
    if (parser->xmlctx)
        xmlFreeParserCtxt(parser->xmlctx);

    if (parser->stanza) 
	xmpp_stanza_release(parser->stanza);

    parser->xmlctx = xmlCreatePushParserCtxt(&parser->handlers, 
                                             parser, NULL, 0, NULL);
    if (!parser->xmlctx) return 0;

    parser->depth = 0;
    parser->stanza = NULL;

    return 1;
}
示例#28
0
文件: aos_util.c 项目: lixiaofly/oss
int aos_parse_xml_body(aos_list_t *bc, xmlDoc **doc_, xmlNode **root)
{
    int res;
    aos_buf_t *b;    
    xmlDoc *doc;
    xmlParserCtxt *ctxt;
    *root = NULL;

    ctxt = xmlCreatePushParserCtxt(NULL, NULL, NULL, 0, NULL);
    if (ctxt == NULL) {
        aos_error_log("Failed to create parser context.");
        return AOSE_INTERNAL_ERROR;
    }

    aos_list_for_each_entry(b, bc, node) {
        xmlParseChunk(ctxt, (char *)b->pos, aos_buf_size(b), 0);
    }
示例#29
0
oxws_result oxws_autodiscover_try_url(CURL* curl, oxws_autodiscover_sax_context* sax_context,
        const char* url, oxws_connection_settings* settings) {

  if(curl == NULL || sax_context == NULL || url == NULL || settings == NULL)
    return OXWS_ERROR_INVALID_PARAMETER;

  /* set url */
  curl_easy_setopt(curl, CURLOPT_URL, url);

  /* clear SAX context and create response parser */
  oxws_autodiscover_sax_context_init(sax_context);
  xmlParserCtxtPtr response_xml_parser = xmlCreatePushParserCtxt(&oxws_autodiscover_sax_handler, sax_context, NULL, 0, NULL);
  curl_easy_setopt(curl, CURLOPT_WRITEDATA, response_xml_parser);

  /* perform request */
  CURLcode curl_code = curl_easy_perform(curl);
  int result = OXWS_ERROR_CONNECT;
  if(curl_code == CURLE_OK) {
    long http_response = 0;
    curl_easy_getinfo (curl, CURLINFO_RESPONSE_CODE, &http_response);
    if(http_response == 401) {
      result = OXWS_ERROR_AUTH_FAILED;
    } else if(http_response == 200) {
      if (sax_context->state != OXWS_AUTODISCOVER_SAX_CONTEXT_STATE_END_DOCUMENT) {
        result = OXWS_ERROR_AUTODISCOVER_UNAVAILABLE;
      } else if (sax_context->found_target_protocol) {
        result = OXWS_NO_ERROR;
        /* copy settings */
        free(settings->as_url); free(settings->oof_url); free(settings->um_url); free(settings->oab_url);
        memcpy(settings, &sax_context->settings, sizeof(oxws_connection_settings));
        memset(&sax_context->settings, 0, sizeof(oxws_connection_settings));
      } else if (sax_context->error_code == 500 || sax_context->error_code == 501) {
        result = OXWS_ERROR_AUTODISCOVER_BAD_EMAIL;
      } else {
        result = OXWS_ERROR_AUTODISCOVER_UNAVAILABLE;
      }
    }
  }

  /* clean up */
  if(response_xml_parser != NULL)
    xmlFreeParserCtxt(response_xml_parser);
  oxws_autodiscover_sax_context_free(sax_context);

  return result;
}
示例#30
0
void *WeatherPlugin::processEvent(Event *e)
{
    if (e->type() == EventLanguageChanged)
        updateButton();
    if (e->type() == EventInit)
        showBar();
    if (e->type() == EventCommandExec){
        CommandDef *cmd = (CommandDef*)(e->param());
        if ((cmd->id == CmdWeather) && *getID()){
            string url = "http://www.weather.com/outlook/travel/pastweather/";
            url += getID();
            Event eGo(EventGoURL, (void*)url.c_str());
            eGo.process();
            return e->param();
        }
    }
    if (e->type() == EventFetchDone){
        fetchData *d = (fetchData*)(e->param());
        if (d->req_id != m_fetch_id)
            return NULL;
        m_fetch_id = 0;
        if (d->result != 200)
            return NULL;
        m_data  = "";
		m_day   = 0;
        m_bBar  = false;
        m_bWind = false;
        m_bUv	= false;
		m_bCC	= false;
        m_context = xmlCreatePushParserCtxt(&m_handler, this, "", 0, "");
        if (xmlParseChunk(m_context, d->data->data(), d->data->size(), 0)){
            log(L_WARN, "XML parse error");
            xmlFreeParserCtxt(m_context);
            return NULL;
        }
        xmlFreeParserCtxt(m_context);
        time_t now;
        time(&now);
        setTime(now);
        updateButton();
        Event eUpdate(EventWeather);
        eUpdate.process();
    }
    return NULL;
}