Help with routing by callerid

I am a 1 week newbie to Asterisk. I am planning to use asterisk in my home to route telemarketers to an answering machine based on callerid output. Both my provider and home loop are PSTN. I will be running Asterisk 11.6 on CentOS 6.5. I have a 4 port FXO/FXS card on order. Here is what I would like to do:

  1. Answer incoming calls, but suppress ring until the callerid is transmitted
  2. Compare the callerid number to a blacklist. (I do not anticipate the blacklist to ever exceed 1000 entries)
  3. If the number is blacklisted, route to a hardware answering machine
  4. If the call is not blacklisted, route to my home loop.
    Once I get this working, I will work on adding a callerid name capability to the blacklisting. I have been reading all the Asterisk documentation I can find and have a few questions:
  5. I have concluded that the blacklist comparison will need to be done outside of the dial plan. I am not familiar with Python, Perl, PGP, but I was a C programmer and KORN shell scripter in the 1980s. Can I call a complied C program with arguments using AGI? How about calling a KORN shell script?
  6. With a blacklist of less than 1000 entries, I plan to use a flat file instead of a full-fledged database to simplify implementation. From a performance impact perspective, are there any guidelines on the maximum allowable elapsed time from the start of the AGI call to the return of a yes/no response to the dialplan?
  7. I am sure I am not the first person to want to route calls based on callerid. Am I missing an easier way that is readily available?

Please feel free to correct any wrong assumptions I have and thanks in advance for any help or advice you can provide.

Google “asterisk ex-girlfriend logic” as well as looking at the obvious functions.

Given the amount of anti-telemarketing support I’d be surprised in none of this was covered in the sample dialplans.

Answering calls before you ring the internal phone is bad practice, as it can result in the caller being charged for a call that then fails. By all means answer once you know you have a junk call.

Update to my initial post: I obtained Oreilly’s “Asterisk: The Definitive Guide 4th edition”. This is an excellent book and answers most of my questions. I was clearly over thinking and over engineering a solution. I guess that is the downside of being a newbie to Asterisk. Everything I want to do can be done within Asterisk using the BLACKLIST() function and the blacklist family in the AstDB. It appears that the dial plan coding for this is going to be simple and straight forward.
One bit of advice for other newbies: I thought that installing CentOS and then compiling Asterisk from source would take an hour or two. Not true, at least for me. Installing additions modules and drivers you may need and configuring the conf files will add several hours to the process. I have about 4 hours into installation and I have not installed and configured my PTSN port card yet.