[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Issue 5.1) SSH End of message directive





Is the <?eom?> directive necessary?  I've pasted below
some sample code that uses the expat function XML_ParserReset
to parse a sequence of XML documents such as:

<rpc>
    <get-config>config</get-config>
</rpc>

<?xml version="10"?>
<rpc>
    <set-config>config</set-config>
</rpc>


I've been a bit lazy with the blank eating code (only checking the first character). A more general purpose implementation might reset the parser when the element depth dropped to zero (rather than looking for a closing </rpc>). Note that it is not necessary to eat blank lines outside the parser if XML declarations (<?xml version="1.0"?>) are not used.

The sample code uses fgetln for line detection; this is not
ideal for embedded applications, but could be easily substituted.

Are there failure modes that people are thinking of that this
fundamentally doesn't handle?

Thanks,
Ted.




On Dec 2, 2003, at 5:01 PM, Andy Bierman wrote:


Should an end-of-message directive <?eom?> be used to
provide an easier message framing mechanism than parsing
the entire XML instance document to find the proper end tag?


-- to unsubscribe send a message to netconf-request@ops.ietf.org with the word 'unsubscribe' in a single line as the message text body. archive: <http://ops.ietf.org/lists/netconf/>




#include <stdio.h> #include <expat.h>

XML_Parser parser;
int doReset = 0;
int eatBlanks = 1;

void startElementHandler (void *data, const char *element, const char **attr) {
printf("found start tag: %s\n", element);
}



void endElementHandler (void *data, const char *element) { printf("found end tag: %s\n", element); if (0 == strcmp("rpc", element)) { doReset = 1; } }


int main (int argc, char **argv) { FILE *xmlFile; char *lineBuf; size_t len;

xmlFile = fopen(argv[1], "r");

parser = XML_ParserCreate(NULL);
XML_SetElementHandler(parser, startElementHandler, endElementHandler);


while(lineBuf = fgetln(xmlFile, &len)) {

        if (eatBlanks)  {
          if (isspace(*lineBuf))  {
            continue;
          }
          else {
            eatBlanks = 0;
          }
        }

        if (! XML_Parse(parser, lineBuf, len, 0))  {
            fprintf(stderr, "Parse error at line %d:\n%s\n",
                    XML_GetCurrentLineNumber(parser),
                    XML_ErrorString(XML_GetErrorCode(parser)));
            fwrite(lineBuf, 1, len, stderr);
            fprintf(stderr, "\n");
            return 0;
        }

if (doReset) {
printf(" SNIP\n");
XML_ParserReset(parser, NULL);
XML_SetElementHandler(parser, startElementHandler, endElementHandler);
doReset = 0;
eatBlanks = 1;
}
}



fclose(xmlFile); }


-- to unsubscribe send a message to netconf-request@ops.ietf.org with the word 'unsubscribe' in a single line as the message text body. archive: <http://ops.ietf.org/lists/netconf/>