[Asterisk-Dev] New Query API I wrote... want to discuss inclusion:

Rob Gagnon rob at networkip.net
Mon Mar 15 12:48:44 MST 2004


I hope I didn't spam people with this.  I sent the original from the wrong email address:
----------------------------------------------------------------------------------------------------------------------------
After debating with citats for a bit in IRC, his idea of an abstract query interface finally made sense to me :-)

So I set about writing it on the weekend, and it is in a working state now.

With this API (which I named "qint" for query interface), (similar to how cdr.c works)....
1) All mySQL, and other DB specific code can be removed from being all over Asterisk (voicemail, chan_sip, directory, etc.)
2) All the #ifdef MYSQL lines of code can be removed from Asterisk
3) Modules (ie: qint/qint_mysql.c, or qint_odbc.c, or qint_radius.c) can be written that contain the specific code for the lookups that are moved to qint.
4) A Single database connection can be shared by qint, instead of having one for each piece that connects
5) Configuring the database connection doesnt have to be in 3 or 4 different .conf files

So, here's a quick list of the changes... with more discussion, we can figure out where to put code for others to review:

- new file qint.c compiles into Asterisk just like cdr.c does, with some of its functions exported in qint.h
- new file qint_mysql.c which can handle any query Asterisk would normally do from itself. (example:  I already removed ALL mysql code from chan_sip.c and put it int qint_mysql.c---- best part is it still all works as if the code were right inside of chan_sip.c)
- changed chan_sip.c and removed all mysql code, and #ifdefs.  replaced with code like:
//search for user/peer code as it exists
...
if (!u) qint_sip_find_user(&u, other params...);
...
the qint_sip_find_user() function exists within qint.c: It will dynamically find a possible registered function for performing a sipfriends lookup in an external .so module (ie: qint_mysql.so)

qint_mysql.so's load_module() function just performs a qint_register(name, desc, query_type, function_ptr) call in order to register a function as a handler for a specific type of query.

Of course, this did require some other minor changes....
- Had to make a chan_sip.h file to define some things external of chan_sip.c (so both chan_sip.c, and qint_mysql.c can see the sip_peer and sip_user structs for example)
- a #include <asterisk/qint.h> needed to be added to chan_sip.c and so on... lots of little things.

This helps moving toward a dynamic db lookup for the extensions.conf file as well.  With this, I was able to catch any query for pbx_find_extension(), which was a 2 line change to pbx.c, and a handler in qint_mysql.c to catch the call.

If anyone would like to review the source I have, just reply.

----------------------------
#asterisk - rgagnon
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.digium.com/pipermail/asterisk-dev/attachments/20040315/711730a0/attachment.htm


More information about the asterisk-dev mailing list