I saw a blog post in my Twitter feed a few days ago that included something a bit similar to this. It was at http://tech.iprock.com/?p=17563
Look for the line that says “;Special CallerID name lookup; uses Asterisk Phonebook which also acts as whitelist”, I think that might be somewhat close to what you are trying to do.