Beispiel #1
0
char *test_State_exec_error() 
{
    State state;

    // Proxy error where client closed connection mid-connect
    FAILS(failed_proxy, 
            OPEN,  
            REQ_RECV, HTTP_REQ, PROXY, CONNECT, CLOSE);

    return NULL;
}
Beispiel #2
0
static XmlElement *
parseElement(XmlDoc *doc, const char **xmlText, XmlElement *parent)
{
    XmlElement *element = 0;
    XmlElement *childnode = 0;
    XmlAttribute *attribute = 0;
    const char *startval = 0;
    const char *endval = 0;
    size_t valLen = 0;

    ++(*xmlText);
    if (!**xmlText) FAIL(XML_EOF);
    if (**xmlText == '/')
    {
	++(*xmlText);
	FAILS(XML_CLOSEWOOPEN, readBareWord(xmlText, ">"));
    }

    element = calloc(1, sizeof(XmlElement));
    element->prev = element->next = element;
    element->parent = parent;
    if (parent)
    {
	element->depth = parent->depth + 1;
    }
    else
    {
	element->depth = 0;
    }
    element->name = readBareWord(xmlText, ">");
    if (!element->name) FAIL(XML_UNNAMEDTAG);
    if (!**xmlText) FAIL(XML_EOF);

    while (1)
    {
	skipWs(doc, xmlText);
	if (!**xmlText) FAIL(XML_EOF);

	if (**xmlText == '>')
	{
	    ++(*xmlText);
	    break;
	}
	if (**xmlText == '/')
	{
	    ++(*xmlText);
	    skipWs(doc, xmlText);
	    if (!**xmlText) FAIL(XML_EOF);
	    if (**xmlText != '>') FAILC(XML_UNEXPECTED, **xmlText);
	    ++(*xmlText);
	    return element;
	}
	attribute = parseAttribute(doc, xmlText, element);
	if (!attribute) goto failp;
	if (element->attributes)
	{
	    attribute->prev = element->attributes->prev;
	    attribute->next = element->attributes;
	    element->attributes->prev->next = attribute;
	    element->attributes->prev = attribute;
	}
	else
	{
	    element->attributes = attribute;
	}
	attribute = 0;
	if (!**xmlText) FAIL(XML_EOF);
    }

    startval = *xmlText;
    while (**xmlText)
    {
	if (**xmlText == '<')
	{
	    if (hasNonWs(startval, *xmlText))
	    {
		endval = *xmlText;
		while (isspace(*(endval-1))) --endval;
		appendString(&(element->value), startval, &valLen,
			(size_t)(endval - startval));
	    }
	    if ((*xmlText)[1] == '/')
	    {
		*xmlText += 2;
		skipWs(doc, xmlText);
		if (!**xmlText) FAIL(XML_EOF);
		if (strncmp(*xmlText, element->name, strlen(element->name)))
		{
		    FAILS(XML_UNMATCHEDCLOSE, cloneString(element->name));
		}
		*xmlText += strlen(element->name);
		skipWs(doc, xmlText);
		if (!**xmlText) FAIL(XML_EOF);
		if (**xmlText != '>') FAILC(XML_UNEXPECTED, **xmlText);
		++(*xmlText);
		return element;
	    }
	    else
	    {
		childnode = parseElement(doc, xmlText, element);
		if (!childnode) goto failp;
		if (element->children)
		{
		    childnode->prev = element->children->prev;
		    childnode->next = element->children;
		    element->children->prev->next = childnode;
		    element->children->prev = childnode;
		}
		else
		{
		    element->children = childnode;
		}
		childnode = 0;
		startval = *xmlText;
	    }
	}
	else skipUntil(doc, xmlText, '<');
    }
    doc->err = XML_EOF;

fail:
    doc->col = *xmlText - doc->currLine + 1;
failp:
    freeElementList(element);
    return 0;
}