XML it’s not all bad.

I just wanted to take the time to defend our use of XML if I can. =D

Originally, FreeSWITCH used the same .ini format that Asterisk uses in all of it’s config. Actually the interface to parse .ini still exists and a module writer is able to use it if he pleases. The reasoning for XMLizing what we chose to XMLize becomes more clear when you begin to scale the system. FreeSWITCH parses it’s XML registry when it first starts and keeps it in memory. This is one big entity that can be navigated similar to a file system. There are top level major sections: configuration, dialplan, directory and phrases. All of the bits and pieces of these sections are exploded out onto the disk in the default arrangement so you can edit the portion of the document you need and it also allows you to insert small XML representations of a single entity such as a SIP UA, a user on the system, the configuration for what modules you want to load. All of these files will be concatenated in the end into 1 big XML document that the entire core and its modules can access with a common API that gives you the entities as a tangible object that can be extended without more code.

Now for the interesting part. It’s possible to bind callback functions to certain sections of the XML registry so that when code tries to access a particular section your handler can conjure the XML on-demand any way it wants and deliver it back in place of whatever is in the default document. For instance, you can bind your dialplan and user directory sections to mod_xml_curl, A callback that translates XML lookups to and from a nearby HTTP server. When the call hits the XML dialplan the cURL handler kicks in and posts a request to a custom CGI. The CGI gets post data that is identical to a web form being posted with a few dozen facts about the channel that you can use to determine where the call was intended to go and who’s calling etc. The CGI then creates a small snippet of XML that will satisfy the request and returns it to FreeSWITCH who will parse it as if it was part of the static config. The same can be done when someone registers to SIP or tries to check their voicemail or when the config is called up during load.

Trust me. I am far from XML’s biggest fan, but I do feel it’s actual uses are lost in a sea of contrived forced solutions that give it a bad name. To serialize complex objects to and from a text format and to make markup that is easily parsed and generated are the real strengths of XML. The best used XML is XML nobody ever realizes is even there. Certainly that is not true completely with FreeSWITCH today but as we scale and more GUI’s and config apps are made, the curve will be in our favor and most people besides only the truly advanced users will ever have to see the XML again.

Caveat: We do have mod_dialplan_asterisk in tree that will allow your dialplan to look and feel more like the asterisk extensions.conf (using .ini) for a sort of cross-over feel.

Pin It

Leave a Reply