text stringlengths 0 152 |
|---|
| |
Chapter 15: Relational Database Integration |
Troubleshooting Database Issues |
When working with ODBC database connections and Asterisk, it is important to |
remember that the ODBC connection abstracts some of the information passed |
between Asterisk and the database. In cases where things are not working as |
expected, you may need to enable logging on your database platform to see what |
Asterisk is sending to the database (e.g., which SELECT, INSERT, or UPDATE statements |
are being triggered from Asterisk), what the database is seeing, and why the database |
may be rejecting the statements. |
For example, one of the most common problems found with ODBC database integra‐ |
tion is an incorrectly defined table or a missing column that Asterisk expects to exist. |
While great strides have been made in the form of adaptive modules, not all parts of |
Asterisk are adaptive. In the case of ODBC voicemail storage, you may have missed a |
column such as flag, which is a new column not found in versions of Asterisk prior |
to 11.1 As noted, in order to debug why your data is not being written to the database |
as expected, you should enable statement logging on the database side, and then |
determine what statement is being executed and why the database is rejecting it. |
SQL Injection |
Security is always a consideration when you are building networked applications, and |
database security is no exception. |
In the case of Asterisk, you have to think about what input you are accepting from |
users (typically what they are able to submit to the dialplan), and work to sanitize that |
input to ensure you are only allowing characters that are valid to your application. As |
an example, a typical telephone call would only allow digits as input (and possibly the |
* and # characters), so there would be no reason to accept any other characters. Bear |
in mind that the SIP protocol allows more than just numbers as part of an address, so |
don’t assume that somebody attempting to compromise your system is limited to just |
digits. |
A little extra time spent sanitizing your allowed input will improve the security of |
your application. |
Powering Your Dialplan with func_odbc |
The func_odbc dialplan function module allows you to define and use relatively sim‐ |
ple functions in your dialplan that will retrieve information from databases as calls |
are being processed. There are all kinds of ways in which this might be used, such as |
1 This was actually an issue one of the authors had while working on this book, and he found the flag column |
by looking at the statement logging during testing. |
Powering Your Dialplan with func_odbc |
| |
261 |
managing users or allowing the sharing of dynamic information within a clustered set |
of Asterisk machines. We won’t claim that this will make designing and writing dia‐ |
lplan code easier, but we will promise that it will allow you to add a whole new level |
of power to your dialplans, especially if you are comfortable working with databases. |
We don’t know anybody in the Asterisk community who does not love func_odbc. |
The way func_odbc works is by allowing you to define SQL queries, to which you |
assign function names. The func_odbc.conf file is where you specify the relationships |
between the functions you create and the SQL statements you wish them to perform. |
You use the named functions you have created in your dialplan to retrieve and update |
values in the database. |
In order to get you into the right frame of mind for what follows, we want you to |
picture a Dagwood sandwich.2 |
Can you relay the total experience of such a thing by showing someone a picture of a |
tomato, or by waving a slice of cheese about? Hardly. That is the conundrum we faced |
when trying to give useful examples of why func_odbc is so powerful. So, we decided |
to build the whole sandwich for you. It’s quite a mouthful, but after a few bites of this, |
peanut butter and jelly is never going to be the same. |
ODBC Configuration File Relationships |
Several files must all line up in order for Asterisk to be able to use |
ODBC from the dialplan. Figure 15-1 attempts to convey this visu‐ |
ally. You will probably find this diagram more helpful once you |
have worked through the examples in the following sections. |
2 And if you don’t know what a Dagwood is, that’s what Wikipedia is for. I am not that old. |
262 |
| |
Chapter 15: Relational Database Integration |
Figure 15-1. Relationships between func_odbc.conf, res_odbc.conf, /etc/odbc.ini (uni‐ |
xODBC), and the database connection |
A Gentle Introduction to func_odbc |
Before we dive into func_odbc, we feel a wee bit of history is in order. |
The very first use of func_odbc, which occurred while its author was still writing it, is |
also a good introduction to its use. A customer of one of the module’s authors noted |
that some people calling into his switch had figured out a way to make free calls with |
his system. While his eventual intent was to change his dialplan to avoid those prob‐ |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.