Hi Friends!

I wish to do something like:
 - Authorize all sip clients in external DB, for example postgresql.
 - Control each call session duration, just like prepaid calling card.
 - LCR, if one voip provider can't connect call into PSTN, try next PSTN supplier.

Please help me, i can't understand what is docs i might to read to know how to do it.
Could you show me some links and terms. explain it?

Thank you so much!

DM