login | register
Wed 09 of Jul, 2008 [05:11 UTC]

voip-info.org

Discuss [12] History

Asterisk app_dbodbc

Created by: flavour,Last modification on Fri 17 of Feb, 2006 [20:05 UTC] by lhgomes

app_dbodbc

This is original Brian's re-implementation of the Asterisk database using unixODBC.
This allows for easy creation of dialplan modifiers that link into a GUI with a back-end database.

Download Brian's Version (patched to work with 1.0RC1 and above)

or

Download modified version to work with Asterisk 1.0RC1 and above. This version is also extended by Rob Fugina (ODBCLookupCIDName, ODBCLookupBlacklist) and Jukka Laaksola (database recconnect function).

or

Download modified version to work with asterisk cvs-head. This version is modified by Gregory Nietsky. Also a patch for realtime.



Install

rpm -ivh unixODBC*rpm
rpm -ivh MyODBC*rpm

cp app_dbodbc.c  /usr/src/asterisk/apps/

vi /usr/src/asterisk/apps/Makefile +28
add in the end of line: app_dbodbc.so


vi /usr/src/asterisk/apps/Makefile +110
app_dbodbc.so: app_dbodbc.o
       $(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} -lodbc

cd /usr/src/asterisk
make
make install

Configure

This assumes using MySQL database on RedHat - will vary for other DBs & slightly for other OS's.

Configure MySQL:
  • Add a database called 'asterisk'
  • Create a user with full read/write access to this database
  • Add a table within this database called 'astdb'
  • Add 3 fields to the structure of this table: 'astfamily', 'astkey' & 'astvalue'

vi /etc/odbcinst.ini
[MySQL]
Description     = ODBC for MySQL
Driver          = /usr/lib/libmyodbc.so
Setup           = /usr/lib/libodbcmyS.so
FileUsage       = 1

vi /etc/odbc.ini
[MySQL-asterisk]
Description = MySQL Asterisk database
Trace       = Off
TraceFile   = stderr
Driver      = MySQL
SERVER      = localhost
USER        = 
PASSWORD    = 
PORT        = 3306
DATABASE    = asterisk

Test ODBC:
isql -v MySQL-asterisk myusername mypassword

vi /etc/asterisk/odbc.conf
[global]
dsn=MySQL-asterisk
username=myusername
password=mypassword

Usage

  • ODBCget(varname=family/key):
Retrieves a value from the Asterisk database and stores it in the given variable. Always returns 0. If the requested key is not found, jumps to priority n+101 if available.
  • ODBCput(family/key=value):
Stores the given value in the Asterisk database. Always returns 0.
  • ODBCdel(family/key):
Deletes a key from the Asterisk database. Always returns 0.
  • ODBCdeltree(family[/keytree]):
Deletes a family or keytree from the Asterisk database. Always returns 0.

and if you use the extented version:

  • ODBCLookupCIDName:
Looks up Caller*ID number on the the active channel in the ODBC database (family 'cidname') and sets the Caller*ID name. Does nothing if no Caller*ID was received on the channel. This is useful if you do not subscribe to Caller*ID name delivery, or if you want to change the names on some incoming calls. Always returns 0.
  • ODBCLookupBlacklist:
Looks up the Caller*ID number on the active channel in the ODBC database. If the number is found, and if there exists a priority n + 101, where 'n' is the priority of the current instance, then the channel will be setup to continue at that priority level. Otherwise, it returns 0. Does nothing if no Caller*ID was received on the channel. Example: database put blacklist name/number> 1


See also




Comments

Comments Filter
222

333Values get cut to 50 chars on odbcget

by jwegener, Friday 10 of November, 2006 [13:13:06 UTC]
For me it worked to change a value in line 682 from 50 to 265.

SQLBindCol(ODBC_stmt, 1, SQL_C_CHAR, &tmp, 50, &ODBC_err);

SQLBindCol(ODBC_stmt, 1, SQL_C_CHAR, &tmp, 256, &ODBC_err);

--
Jens
222

333Gregorys module stops Asterisk load

by dustintodd, Thursday 14 of September, 2006 [01:38:20 UTC]
I am using the CVS head version from Gregory and it compiles fine. But when I try to start Asterisk I get
app_dbodbc.soSep 13 13:49:47 WARNING31772: loader.c:325 __load_resource: /usr/lib/asterisk/modules/app_dbodbc.so: undefined symbol: ast_direct_realtime
Sep 13 13:49:47 WARNING31772: loader.c:554 load_modules: Loading module app_dbodbc.so failed!

Must I apply the realtime patch found on his website to allow the ODBC module to run?
222

333load module problem

by lhgomes, Friday 17 of February, 2006 [22:50:39 UTC]
if you get error when load module, edit source file (app_dbodbc.c) and change the follow functions:

ast_load --> ast_config_load
ast_destroy --> ast_config_destroy

recompile and re-install.
222

333Re: odbc compilation problems

by lhgomes, Friday 17 of February, 2006 [20:00:34 UTC]
make & make install must be run from asterisk directory, not apps. See: http://lists.digium.com/pipermail/asterisk-dev/2004-June/004809.html
222

333Re: odbc compilation problems

by lhgomes, Friday 17 of February, 2006 [20:00:01 UTC]
make & make install must be run from asterisk directory, not apps. See: http://lists.digium.com/pipermail/asterisk-dev/2004-June/004809.html
222

333Re: odbc compilation problems

by , Thursday 02 of December, 2004 [19:35:52 UTC]
the file is out of date. on line 271, where chan->callerid is, replace callerid with cid.cid_num
222

333odbc compilation problems

by bais, Sunday 24 of October, 2004 [19:35:39 UTC]
RH 9.0 apt-get update & upgrade 10 minutes ago

packages installed:

  1. rpm -qa | grep ODBC
MyODBC-2.50.39-11
unixODBC-2.2.3-6
unixODBC-devel-2.2.3-6

result of compilation:
gcc -pipe -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -g -Iinclude -I../include -D_REENTRANT -D_GNU_SOURCE -O6 -march=i686 -DASTERISK_VERSION=\"CVS-HEAD-10/25/04-00:58:46\" -DASTERISK_VERSION_NUM=999999 -DINSTALL_PREFIX=\"\" -DASTETCDIR=\"/etc/asterisk\" -DASTLIBDIR=\"/usr/lib/asterisk\" -DASTVARLIBDIR=\"/var/lib/asterisk\" -DASTVARRUNDIR=\"/var/run\" -DASTSPOOLDIR=\"/var/spool/asterisk\" -DASTLOGDIR=\"/var/log/asterisk\" -DASTCONFPATH=\"/etc/asterisk/asterisk.conf\" -DASTMODDIR=\"/usr/lib/asterisk/modules\" -DASTAGIDIR=\"/var/lib/asterisk/agi-bin\" -DBUSYDETECT_MARTIN -fPIC -c -o app_dbodbc.o app_dbodbc.c
app_dbodbc.c: In function `odbcget_exec':
app_dbodbc.c:271: structure has no member named `callerid'
make1: *** app_dbodbc.o Error 1
make1: Leaving directory `/root/asterisk/apps'
make: *** subdirs Error 1
for x in res channels pbx apps codecs formats agi cdr astman stdtime; do make -C $x depend || exit 1 ; done
make1: Entering directory `/root/asterisk/res'
make1: Nothing to be done for `depend'.
make1: Leaving directory `/root/asterisk/res'
make1: Entering directory `/root/asterisk/channels'
make1: Nothing to be done for `depend'.
make1: Leaving directory `/root/asterisk/channels'
make1: Entering directory `/root/asterisk/pbx'
make1: Nothing to be done for `depend'.
make1: Leaving directory `/root/asterisk/pbx'
make1: Entering directory `/root/asterisk/apps'
make1: Nothing to be done for `depend'.
make1: Leaving directory `/root/asterisk/apps'
make1: Entering directory `/root/asterisk/codecs'
make1: Nothing to be done for `depend'.
make1: Leaving directory `/root/asterisk/codecs'
make1: Entering directory `/root/asterisk/formats'
make1: Nothing to be done for `depend'.
make1: Leaving directory `/root/asterisk/formats'
make1: Entering directory `/root/asterisk/agi'
make1: Nothing to be done for `depend'.
make1: Leaving directory `/root/asterisk/agi'
make1: Entering directory `/root/asterisk/cdr'
make1: Nothing to be done for `depend'.
make1: Leaving directory `/root/asterisk/cdr'
make1: Entering directory `/root/asterisk/astman'
make1: Nothing to be done for `depend'.
make1: Leaving directory `/root/asterisk/astman'
make1: Entering directory `/root/asterisk/stdtime'
make1: Nothing to be done for `depend'.
make1: Leaving directory `/root/asterisk/stdtime'
cd editline && unset CFLAGS LIBS && test -f config.h || ./configure
make -C editline libedit.a
make1: Entering directory `/root/asterisk/editline'
make1: `libedit.a' is up to date.
make1: Leaving directory `/root/asterisk/editline'
make1: Entering directory `/root/asterisk/db1-ast'
make1: `libdb1.a' is up to date.
make1: Leaving directory `/root/asterisk/db1-ast'
make1: Entering directory `/root/asterisk/stdtime'
make1: `libtime.a' is up to date.
make1: Leaving directory `/root/asterisk/stdtime'
if -d CVS && ! -f .version ; then echo CVS-HEAD-10/25/04-00:58:46 > .version; fi
for x in res channels pbx apps codecs formats agi cdr astman stdtime; do make -C $x || exit 1 ; done
make1: Entering directory `/root/asterisk/res'
make1: Nothing to be done for `all'.
make1: Leaving directory `/root/asterisk/res'
make1: Entering directory `/root/asterisk/channels'
make1: Nothing to be done for `all'.
make1: Leaving directory `/root/asterisk/channels'
make1: Entering directory `/root/asterisk/pbx'
make1: Nothing to be done for `all'.
make1: Leaving directory `/root/asterisk/pbx'
make1: Entering directory `/root/asterisk/apps'
gcc -pipe -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -g -Iinclude -I../include -D_REENTRANT -D_GNU_SOURCE -O6 -march=i686 -DASTERISK_VERSION=\"CVS-HEAD-10/25/04-00:58:46\" -DASTERISK_VERSION_NUM=999999 -DINSTALL_PREFIX=\"\" -DASTETCDIR=\"/etc/asterisk\" -DASTLIBDIR=\"/usr/lib/asterisk\" -DASTVARLIBDIR=\"/var/lib/asterisk\" -DASTVARRUNDIR=\"/var/run\" -DASTSPOOLDIR=\"/var/spool/asterisk\" -DASTLOGDIR=\"/var/log/asterisk\" -DASTCONFPATH=\"/etc/asterisk/asterisk.conf\" -DASTMODDIR=\"/usr/lib/asterisk/modules\" -DASTAGIDIR=\"/var/lib/asterisk/agi-bin\" -DBUSYDETECT_MARTIN -fPIC -c -o app_dbodbc.o app_dbodbc.c
app_dbodbc.c: In function `odbcget_exec':
app_dbodbc.c:271: structure has no member named `callerid'
make1: *** app_dbodbc.o Error 1
make1: Leaving directory `/root/asterisk/apps'
make: *** subdirs Error 1


some advices?
(:mrgreen:)
222

333No data

by , Thursday 07 of October, 2004 [01:15:36 UTC]
I followed the instructions and created the table. During start up the app loads:
app_dbodbc.so] => (Database access functions for Asterisk extension logic)
 == Parsing '/etc/asterisk/odbc.conf': Found
      > app_dbodbc: dsn is AsteriskProduction
      > app_dbodbc: username is asterisk
      > app_dbodbc: password is secret
      > app_dbodbc: Connected to AsteriskProduction
 == Registered application 'ODBCget'
 == Registered application 'ODBCput'
 == Registered application 'ODBCdel'
 == Registered application 'ODBCdeltree'

But no data is being put in the table.
Does something need to be done to tell * to save via odbc instead of to the local db?
222

333Field specs

by , Wednesday 06 of October, 2004 [14:43:53 UTC]
What are the definitions of the fields? Ex. Size.
222

333Compile Problems

by , Friday 16 of July, 2004 [06:59:04 UTC]
I'm new to asterisk and had problems getting this module compiled, in the end I had to change a line in app_dbodbc.c from

static ast_mutex_t odbc_lock = AST_MUTEX_INITIALIZER;

to

AST_MUTEX_DEFINE_STATIC(odbc_lock);

before it would let me compile it because of a change in the way lock.h does something. Seems to be working now! (:biggrin:)