Пример #1
0
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);
  }
}
Пример #2
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;
}
Пример #3
0
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;
}
Пример #4
0
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;	
}
Пример #5
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));	
		}
	}
Пример #6
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;
}
Пример #7
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;
}
Пример #8
0
/**
 * Finalise XML parsing.
 */
int xml_complete(modsec_rec *msr, char **error_msg) {
    if (error_msg == NULL) return -1;
    *error_msg = NULL;

    /* Only if we have a context, meaning we've done some work. */
    if (msr->xml->parsing_ctx != NULL) {
        /* This is how we signalise the end of parsing to libxml. */
        xmlParseChunk(msr->xml->parsing_ctx, NULL, 0, 1);

        /* Preserve the results for our reference. */
        msr->xml->well_formed = msr->xml->parsing_ctx->wellFormed;
        msr->xml->doc = msr->xml->parsing_ctx->myDoc;

        /* Clean up everything else. */
        xmlFreeParserCtxt(msr->xml->parsing_ctx);
        msr->xml->parsing_ctx = NULL;
        msr_log(msr, 4, "XML: Parsing complete (well_formed %u).", msr->xml->well_formed);

        if (msr->xml->well_formed != 1) {
            *error_msg = ngx_pstrndup(msr->mp, "XML: Failed parsing document.");
            return -1;
        }
    }

    return 1;
}
Пример #9
0
/** 
 * Parses a descriptor that contains the last  part of a document. 
 */
void CXMLEngineSAXPlugin::ParseLastChunkL(const TDesC8& /*aDescriptor*/)
	{
	if (!iParserContext)
		{
		User::Leave(EXmlParserError);
		}

	//parsing process
	TInt result(KErrNone);
	result = xmlParseChunk(iParserContext, NULL, 0, 1);
	if ((result == XML_ERR_NO_MEMORY) || (iParserContext->lastError.level == XML_ERR_FATAL)
	        || (result < 0))
		{
		CleanupAndLeaveL(GetErrorNum(result));			
		}			
		
	//releasing context to the parser
    xmlParserCtxtPtr ctxt = reinterpret_cast<xmlParserCtxtPtr>(iParserContext);
    if(ctxt->myDoc)                     
       {
       xmlFreeDoc(ctxt->myDoc); 
       }
    xmlFreeParserCtxt(ctxt);
	iParserContext = NULL;	
	
	}
Пример #10
0
/* feed a chunk of data to the parser */
int parser_feed(parser_t *parser, char *chunk, int len)
{
    if (XML_ERR_OK == xmlParseChunk(parser->xmlctx, chunk, len, 0))
       return 1;
    else 
       return 0;
}
Пример #11
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;
}
Пример #12
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);
}
Пример #13
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;
}
Пример #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
ret_t
cherokee_handler_tmi_step (cherokee_handler_tmi_t *hdl, cherokee_buffer_t *buffer)
{
    char time_buf[21];
    size_t len;

    len = strftime(time_buf, 21, "%Y-%m-%dT%H:%S:%MZ", &cherokee_bogonow_tmgmt);
    cherokee_buffer_add_buffer (buffer, &HANDLER_TMI_PROPS(hdl)->reply);
    cherokee_buffer_add (buffer, time_buf, len);

#ifdef LIBXML_PUSH_ENABLED
    if (hdl->validate_xml) {
        cherokee_buffer_add_str (buffer, "</tmi8:Timestamp><tmi8:ResponseCode>");

        if (hdl->inflated && hdl->z_ret != Z_OK) {
            cherokee_buffer_add_str(buffer, "PE");
        } else {
            xmlParseChunk(hdl->ctxt, NULL, 0, 1);
            if (hdl->ctxt->wellFormed) {
                cherokee_buffer_add_str(buffer, "OK");
            } else {
                cherokee_buffer_add_str(buffer, "SE");
            }
        }

        cherokee_buffer_add_str (buffer, "</tmi8:ResponseCode></tmi8:VV_TM_RES>");

        return ret_eof_have_data;
    }
#endif
    cherokee_buffer_add_str (buffer, "</tmi8:Timestamp><tmi8:ResponseCode>OK</tmi8:ResponseCode></tmi8:VV_TM_RES>");

    return ret_eof_have_data;
}
Пример #16
0
/**
 * e_soap_message_parse_response:
 * @msg: the #ESoapMessage.
 *
 * Parses the response returned by the server.
 *
 * Returns: a #ESoapResponse representing the response from
 * the server, or %NULL if there was an error.
 *
 * Since: 2.92
 */
ESoapResponse *
e_soap_message_parse_response (ESoapMessage *msg)
{
	ESoapMessagePrivate *priv;
	xmlDocPtr xmldoc;

	g_return_val_if_fail (E_IS_SOAP_MESSAGE (msg), NULL);

	priv = E_SOAP_MESSAGE_GET_PRIVATE (msg);

	if (!priv->ctxt)
		return NULL;

	xmlParseChunk (priv->ctxt, 0, 0, 1);

	xmldoc = priv->ctxt->myDoc;

	xmlFreeParserCtxt (priv->ctxt);
	priv->ctxt = NULL;

	if (!xmldoc)
		return NULL;

	return e_soap_response_new_from_xmldoc (xmldoc);
}
Пример #17
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;
}
/*****************************************************************************
 * Update the parser with more file content.
 ****************************************************************************/
void mxml_update(void *data, const char *chunk, size_t size, short end) {
  MXML_T *parser;
  int result;
  parser = (MXML_T*)data;
  if ((result = xmlParseChunk(parser->ctxt, chunk, size, end)) != 0) {
    local_error(parser->data, "MEME XML parser returned error code %d.\n", result);
  }
}
Пример #19
0
void close_gps_file(struct gpsfile *gpsf,int closefd)
{
  if (gpsf->ctxt) {
    xmlParseChunk(gpsf->ctxt,gpsf->buf,0,1);
    xmlFreeParserCtxt(gpsf->ctxt);
  }
  if (closefd)
    close(gpsf->fd);
  free(gpsf);
}
Пример #20
0
/* feed a chunk of data to the parser */
int parser_feed(parser_t *parser, char *chunk, int len)
{
     /* xmlParseChunk API returns 0 on success which is opposite logic to
       the status returned by parser_feed */
    if(!xmlParseChunk(parser->xmlctx, chunk, len, 0)) {
        return 1;
    } else {
        return 0;
    }
}
Пример #21
0
EAPI Eina_Bool
eupnp_service_parse_buffer(const char *buffer, int buffer_len, Eupnp_Service_Proxy *s)
{
   Eina_Bool ret = EINA_FALSE;
   if ((!buffer) || (!buffer_len) || (!s)) return ret;

   Eupnp_Service_Parser *parser;

   if (!s->xml_parser)
     {
	/* Creates the parser, which parses the first chunk */
	DBG("Creating service parser.");

	s->xml_parser = eupnp_service_parser_new(buffer, buffer_len, s);

	if (!s->xml_parser)
          {
	     ERR("Failed to parse first chunk");
	     goto parse_ret;
	  }

        ret = EINA_TRUE;
	goto parse_ret;
     }

   parser = s->xml_parser;

   if (!parser->ctx)
     {
	// first_chunk_len < 4 case
	eina_error_set(EUPNP_ERROR_SERVICE_PARSER_INSUFFICIENT_FEED);
	return EINA_FALSE;
     }

   // Progressive feeds
   if (parser->state.state == FINISH)
     {
	WRN("Already finished parsing");
	ret = EINA_TRUE;
	goto parse_ret;
     }

   DBG("Parsing XML (%d) at %p", buffer_len, buffer);

   if (!xmlParseChunk(parser->ctx, buffer, buffer_len, 0))
     {
	ret = EINA_TRUE;
	goto parse_ret;
     }

   parse_ret:
      eupnp_service_parse_check_finished(s);
      return ret;
}
Пример #22
0
size_t ParseXML::ParseHandler(char* data, size_t size, size_t count, ParseXML* This)
{
    if((xmlParseChunk(This->mXmlContext, data, (int)(size * count), 0) == 0) && !This->mXmlContext->disableSAX)
    {
        return size * count;
    }
    else {
        std::cout << Error << std::endl;
        return 0;
    }
}
Пример #23
0
bool LibXMLParser::parse(const std::string& data) {
	if (xmlParseChunk(context_, data.c_str(), data.size(), false) == XML_ERR_OK) {
		return true;
	}
	xmlError* error = xmlCtxtGetLastError(context_);
	if (error->code == XML_WAR_NS_URI || error->code == XML_WAR_NS_URI_RELATIVE) {
		xmlCtxtResetLastError(context_);
		context_->errNo = XML_ERR_OK;
		return true;
	}
	return false;
}
Пример #24
0
void parseAndPrintFile(char *filename) {
    int res;
    FILE *f;
    char chars[CHUNKSIZE];

    f = fopen(filename, "r");
    if (f != NULL) {
        xmlParserCtxtPtr ctxt;

        res = fread(chars, 1, 4, f);
        if (res > 0) {
            ctxt = xmlCreatePushParserCtxt(SAXHandler, NULL,
                                           chars, res, filename);
            while ((res = fread(chars, 1, CHUNKSIZE, f)) > 0) {
                xmlParseChunk(ctxt, chars, res, 0);
            }
            xmlParseChunk(ctxt, chars, 0, 1);
            xmlFreeParserCtxt(ctxt);
        }
        fclose(f);
    }
}
Пример #25
0
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);
}
Пример #26
0
bool XepParser::parse(QFile &f)
{
    char buf[4096];
    char XML_START[] = "<smiles>";
	xmlParseChunk(m_context, XML_START, strlen(XML_START), 0);
    unsigned start = 0;
    for (;;){
        char s32[] = "<32bit_Icons>";
        char e32[] = "</32bit_Icons>";
        int size = f.readBlock(&buf[start], sizeof(buf) - start);
        if (size <= 0)
            break;
        size += start;
        replace(buf, size, s32, "<AA");
        replace(buf, size, e32, "</AA");
        if (size == sizeof(buf)){
            start = strlen(e32);
            size -= start;
        }
		if (xmlParseChunk(m_context, buf, size, 0))
            return false;
        if (start)
            memmove(buf, &buf[sizeof(buf) - start], start);
    }
    if ((m_pict.size() == 0) || (m_width == 0) || (m_height == 0))
        return false;
    Buffer pict;
    pict.fromBase64(m_pict);
    if (pict.size() < 28)
        return false;
    QByteArray arr;
    arr.assign(pict.data(28), pict.size() - 28);
    QImage img(arr);
    if ((img.width() == 0) || (img.height() == 0))
        return false;
    m_image.convertFromImage(img);
    return true;
}
Пример #27
0
static Eina_Bool
eupnp_service_parse_finish(Eupnp_Service_Proxy *d)
{
   if (!d) return;
   if (!d->xml_parser) return;
   DBG("Service SCPD parse finish");

   Eina_Bool ret;
   Eupnp_Service_Parser *parser = d->xml_parser;
   ret = xmlParseChunk(parser->ctx, NULL, 0, 1);
   eupnp_service_parser_free(parser);
   d->xml_parser = NULL;
   return !ret;
}
Пример #28
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;
}
Пример #29
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);
}
Пример #30
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;
}