Huge thanks to our Platinum Members Endace and LiveAction,
and our Silver Member Veeam, for supporting the Wireshark Foundation and project.

Wireshark-dev: Re: [Wireshark-dev] XML Parser

From: "Luis EG Ontanon" <luis@xxxxxxxxxxx>
Date: Tue, 23 Sep 2008 15:12:25 +0200
BTW, last night I experimented with xsltproc and xsl to be used to
generate C-code directly from the dictionary, that'd be hard-coded not
user configurable.


The attached (far from complete) XSL transform generates C-code from
the diameter dictionary.

run as:

$ xsltproc diam_dict2c.xsl ws_trunk/diameter/dictionary.xml


\Lego


On Mon, Sep 22, 2008 at 4:48 PM, Luis EG Ontanon <luis@xxxxxxxxxxx> wrote:
> Well I wrote that lexer for Diameter to avoid yet-another-dep. I did
> not expect yet more parsers to follow-suit.
>
> I myself hate XML and all the paraphernalia that comes with it... my
> writing of the XML dissector was an unsuccesful exercise of
> de-mystification. I hate it even more after writing it!
>
> If your data can be represented with a simple table avoid XML... use a
> simple table. If YAML can do, YAML does it better...
>
> If your data uses a structure expat and other tools do not populate
> YOUR structures, they load the data into THEIR framework and then you
> have to CODE to get it out... You end up writing as much code for
> navigating their structs as you would if you wrote your own parser.
> And you have to deal with the runtime-lib dependency too!
>
> If there was an XML framework that given an XSL or DTD and a
> conformance file generated C-code to extract data into user defined
> C-structs, I'd certainly had used it...  (there's a plethora of
> similar tools for ASN.1). No such tool found yet arround...
>
>
> On Mon, Sep 22, 2008 at 4:26 PM, Matt Poduska
> <mpoduska.intermec@xxxxxxxxx> wrote:
>> So, it sounds as though there is no generic XML parser available. The beauty
>> of XML is that you don't need to generate a special parser for every schema.
>> Has there been any thought to adding the Expat XML parser
>> (http://expat.sourceforge.net) or something like it? If I submit a snapshot
>> of an open-source XML parsing library to the Wireshark source tree, does it
>> have a chance of being accepted?
>>
>> -----Original Message-----
>> From: Abhik Sarkar [mailto:sarkar.abhik@xxxxxxxxx]
>> Sent: Saturday, September 20, 2008 11:54 PM
>> To: mpoduska.intermec@xxxxxxxxx; Developer support list for Wireshark
>> Subject: Re: [Wireshark-dev] XML Parser
>>
>> I needed something similar for feature I have been working on for the SMPP
>> dissector. I could not (when I started working on this) find any ready-made
>> XML parser library in the WS tool chain. So, I have shamelessly copied
>> LEGO's good work on the Diamater Diameter dictionary support (which us also
>> based on XML files). It was a bit tough for me (because I have never worked
>> with Lex before), but it was a good learning experience. There is also the
>> XML dissector which (if I remember correctly) uses the lemon parser
>> generator.
>>
>> HTH
>> Abhik.
>>
>> On Fri, Sep 19, 2008 at 6:41 PM, Matt Poduska <mpoduska.intermec@xxxxxxxxx>
>> wrote:
>>> I'm looking to add support for loading vendor extension information
>>> into the LLRP protocol dissector (submitted, but not yet accepted).
>>> The vendor extension files are XML formatted, and define the structure
>>> and content of extensions to the LLRP protocol. The vendor extension
>>> XML files would be read when the dissector is initialized, and would
>>> produce structures (in
>>> memory) that would be used to dissect the protocol extensions.
>>>
>>> Is there an XML parsing library available to my dissector?
>>>
>>> Thanks,
>>>
>>> Matt Poduska
>>> Software Engineer, RFID Systems
>>> Intermec
>>> 550 Second Street SE
>>> Cedar Rapids, IA 52401
>>> voice: 319.369.3331
>>> fax: 319.369.3577
>>>
>>> _______________________________________________
>>> Wireshark-dev mailing list
>>> Wireshark-dev@xxxxxxxxxxxxx
>>> https://wireshark.org/mailman/listinfo/wireshark-dev
>>>
>>>
>>
>> _______________________________________________
>> Wireshark-dev mailing list
>> Wireshark-dev@xxxxxxxxxxxxx
>> https://wireshark.org/mailman/listinfo/wireshark-dev
>>
>
>
>
> --
> This information is top security. When you have read it, destroy yourself.
> -- Marshall McLuhan
>



-- 
This information is top security. When you have read it, destroy yourself.
-- Marshall McLuhan
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet 
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
    xmlns="http://www.w3.org/1999/xhtml";>
    
    <xsl:output method="text"/>
  
    <xsl:template match="/dictionary">
        <xsl:text>
            /* GPL2 */
            /*
        </xsl:text>

                <xsl:value-of select="base/@uri"/> 

        <xsl:text>
            */
            static value_string vendors[] = {
        </xsl:text>
        
        <xsl:for-each select="base/vendor">
            <xsl:sort select="vendor-id"/>
            <xsl:text> { </xsl:text> 
            <xsl:value-of select="@code"/> 
            <xsl:text> , "</xsl:text> 
            <xsl:value-of select="@name"/>
            <xsl:text>" }, 
            </xsl:text> 
        </xsl:for-each>
        
        <xsl:text>
                {0,NULL}
            };
        </xsl:text>


            <xsl:text>
                static avp_t avps[] = {
            </xsl:text>

            <xsl:for-each select="*/avp">
            
                <xsl:variable name='vendor-id' select='./@vendor-id'/>  
                          
                <xsl:text> { -1, </xsl:text>
                <xsl:choose>
                    <xsl:when test="./@vendor-id">
                        <xsl:value-of select="/dictionary/base/vendor[@vendor-id=$vendor-id]/@code"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:text>0</xsl:text>
                    </xsl:otherwise>
                </xsl:choose>
                <xsl:text> , </xsl:text>
                <xsl:value-of select="@code"/>
                <xsl:text> , "</xsl:text>
                <xsl:value-of select="@name"/>
                <xsl:text>" },
                </xsl:text>
            
            </xsl:for-each>

                    <xsl:text> };
                     </xsl:text>


            <xsl:for-each select="*/avp">
                <xsl:if test="./enum">
                    <xsl:variable name='vendor-id' select='./@vendor-id'/>
                    <xsl:variable name='code' select='./@code'/>

                    <xsl:text> static value_string values_</xsl:text>
                    <xsl:value-of select="$vendor-id"/>
                    <xsl:text>_</xsl:text>
                    <xsl:value-of select="$code"/>
                    <xsl:text>_vals[] = {
                    </xsl:text>
                    <xsl:for-each select="./enum">
                        <xsl:text> { </xsl:text>
                        <xsl:value-of select="./@code"/>
                        <xsl:text> , "</xsl:text>
                        <xsl:value-of select="./@name"/>
                        <xsl:text>" },
                        </xsl:text>
                    </xsl:for-each>                    
                    <xsl:text> };
                     </xsl:text>
                
                </xsl:if>
            </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>