[asterisk-dev] URI parsing

Kevin Harwell kharwell at digium.com
Tue May 20 15:33:04 CDT 2014


Greetings,

For a task I have been working on in Asterisk I have found myself
needing to parse URIs.  Luckily, Asterisk is already using such a
library [1], albeit limitedly.  As the library also may not be installed
on every system Asterisk uses #ifdef to work around this.

So instead of having a bunch of #ifdefs sprinkled throughout the code I
was thinking of locating the parsing code in a central place.  Perhaps
http.c?  A new file?

For now I was thinking of having a structure that will contain the
various parts of a parsed uri:

struct ast_uri {
/*! scheme (e.g. http, https, ws, wss, etc...) */
char *scheme;
/*! username:password */
char *user_info;
/*! host name or address */
char *host;
/*! associated port */
char *port;
/*! path info following host[:port] */
char *path;
/*! true if scheme is a secure type */
int is_secure;
}

and a single ast_uri_create method that takes a URI string (ex format:
<scheme>://[user:pass@]<host>[:port][/<path>]) and parses it into the
above structure.

If the third party library is installed it will use that to parse and
place the data in the structure, otherwise it will fall back and use
some basic parsing code to do it.

Thoughts?

[1] http://uriparser.sourceforge.net/doc/html/index.html


-- 
Kevin Harwell
Digium, Inc. | Software Developer
445 Jan Davis Drive NW - Huntsville, AL 35806 - USA
Check us out at: http://digium.com & http://asterisk.org




More information about the asterisk-dev mailing list