[OpenSER-Users] Giving more power to CPL language: Addressbook Categories feature

Iñaki Baz Castillo ibc at in.ilimit.es
Fri Jan 11 10:15:11 CET 2008


Hi, in my opinion CPL language is not enough powerful, the absence of regular 
expression or any header reading makes it poor (IMHO). It would become really 
cool if it could match AVP's but it can :(


I'm trying to give some power to CPL logic. I want to implement "addressbook
categories" for each user, this is: each user has its own addressbook in which 
he can set a category for each contact:
- Work
- Friend
- Family
- Custom

And of course what I need it a way to match that category **inside** the CPL logic.
This is impossible with CPL itself so I'm thinking in a very very dirty trick:


** Addressbook Categories **


- In an incoming call for "bob at domain.org" OpenSer will match the callerid against 
Bob's addressbook. This will return a variable or AVP:
  $avp(s:caller_category)


- CPL module just can match "Organization", "Subject", and "User-Agent", so 
OpenSer will do:

    append_hf("Bak_Organization: $hdr(Organization)\r\n");  # To preserve original Organization
    remove_hf("Organization");  # Remove original Organization
    append_hf("Organization: $avp(s:caller_category)\r\n");  # Set category as Organization


- But since OpenSer appends/removes headers when the message leaves the proxy I 
can't run CPL now (it will not read the new "Organization" header), so I need to do a
dirty loop in order to append the header.


- When the message comes back into OpenSer the headers are updated so I do:

    remove_hf("Organization");  # Remove current Organization (that is a hack)
    append_hf("Organization: $hdr(Backup_Organization)\r\n");  # Restore original Organization

(those changes will be applied again when message leaves OpenSer, not now).

- And I run CPL:

    cpl_run_script("incoming","FORCE_STATEFUL");


- Into CPL I match "Organization" header by:

    <string-switch field="Organization">
        <string is="Friends">
            <reject status="reject" reason="I have no friends" />
        </string>
    </string-switch>




Is it enough dirty or could I make it more?
Any suggestion? how do you people implement things like this?

Thank a lot.






-- 
Iñaki Baz Castillo
ibc at in.ilimit.es




More information about the Users mailing list