[HELP]Ast Realtime+different registeration for cariers&u

Hi All,
I am using asterisk realtime for my sip accounts only (sip.conf) and in extension.conf has only one context which run my AGI script for further routing. All is going good except one probelm i-e I want to add/register SIP carrier and Users using real time but with difference that all the users will first register to the asterisk using thier username/passowrd but carriers will only authenticated on the basis of IP i-e if there is a call form an unregistered host A.B.C.D. and IP A.B.C.D is defined in the realtime database then It should be allowed to call.

Outline is that (call should only be possible When)
A host is registered using its username/password using account present in Real-time
or able to place call without registration if its IP is defined in real-time

Waiting for a response

Irfan Azher