[Serusers] HELP: custom ser module

Java Rockx javarockx at yahoo.com
Fri Dec 3 03:59:52 CET 2004


Hi All.

I'm using ser-0.8.99-dev21 and I'm trying to create a module which will query MySQL to see if the
number dialed is in a table of unassigned DIDs. The reason is that we use a third party for PSTN
access and they assign us DIDs. If a DID is dialed that is not assigned to a ser subscriber our
sip proxy routes the caller to the PSTN gateway.

But the PSTN gateway provider sees the DID as belonging to our sip proxy so they route it right
back to us. And we get in a loop.

I've basically got my custom ser module working but there is a bug that I cannot find. This
modules exports a single function called "is_did_unassigned()".

The bug is this - when I dial a number that is unassigned is_did_unassigned() returns "0". But if
I dial a number on the PSTN the call to "is_did_unassigned()" hangs. So it appears that when the
MySQL query returns zero rows the module freezes.

My question is this - can someone give the attached source code a quick look to see what I've
messed up. Please be nice - this is my first stab at ser modules and I'm still very unclear on all
the db abstractions.


The MySQL table looks like this

CREATE TABLE unassigned_dids (username char(10))

My ser.cfg looks like this:

loadmodule "/usr/local/lib/ser/modules/dbdid.so"
modparam("dbdid", "db_url", "mysql://ser:heslo@localhost/ser")

route {
        if (!lookup("location")) {
                                                                                                  
                      
                if (isflagset(31)) {
                                                                                                  
                      
                        # Send to voicemail
                        route(5);
                                                                                                  
                      
                } else if (does_uri_exist()) {
                                                                                                  
                      
                        sl_send_reply("480", "Temporarily Unavailable");
 
                } else if (is_did_unassigned()) {
 
                        # User Does Not Exist, but the DID is ours
                        sl_send_reply("480", "Temporarily Unavailable");
 
                } else if (uri=~"^sip:[0-9]{10}@") {
 
                        # Send to PSTN Gateway
                        route(3);
 
                } else {
 
                        sl_send_reply("404", "User Not Found");
                };
 
                break;
        };
}


And finally the code for the custom module which provided the "is_did_unassigned()" function is
attached.

Regards,
Paul


		
__________________________________ 
Do you Yahoo!? 
Yahoo! Mail - Find what you need with new enhanced search.
http://info.mail.yahoo.com/mail_250
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dbdid.c
Type: text/x-csrc
Size: 4438 bytes
Desc: dbdid.c
URL: <http://lists.sip-router.org/pipermail/sr-users/attachments/20041202/571857a2/attachment.c>


More information about the sr-users mailing list