Sunday, December 10, 2006

Asterisk + Freetds +MSSQL 2000

If you are anything like my surely you like to steer clear of all things NOT opensource (i.e. Microsoft) althought I got to admit i have always had a soft spot for Solaris (mmm thinking about it I don't were they stand these days in OpenSource world...) but there comes time that it is unavoidable to work with some of this stuff.

One of the things I love about linux is that it will handle all/most things you throw at it and MSSQL Server integration is one of those, here is my recipe:

  1. freetds , an open source Tabular Data Stream implementation. TDS is the protocol that databases such as Sybase and MSSQL "speak", there are many versions of it, MS SQL 2000 version is TDS 8.0
  2. DBD-Sybase Perl Module, although the name can seem misleading, since Sybase and MSSQL both "speak" TDS it allows the Perl DBI driver to work with both. As of this writing the latest version is 1.07
In this post I am asuming you already know how to work with AGI scripts, we will use Asterisk::AGI Perl module in this examples. I will devote a post for this later on.. for now you might want to check this out.

Ok lets start cooking.

freetds part
#tar -xzvzf freetds-stable.tgz
# cd freetds-0.64
#./configure --prefix=/usr/local/freetds --with-tdsver=8.0 (we will be installing inito /usr/local/freetds dir, and since we will be using it for MSSQL we us version 8.0 of TDS)
#make
#make install

DBD-Sybase part
#tar -xvzf DBD-Sybase-1.07.tar.gz
#cd DBD-Sybase-1.07
#export set SYBASE=/usr/local/freetds
#export set LD_LIBRARY_PATH (this is REALLY really really important step, it will save you dealing with the Dynaloader.pm error which took me a LONG LONG LONG time to figure out... i wish i had this recipe in my hands a few years ago...)
#./configure
#make
#make install

Ok, now I will throw out a little example on how to use this with Asterisk::AGI this next program connects to MSSQL and checks if the callerid of the calling party is a client.

alright aaaall together now:

#!/usr/bin/perl
use Asterisk::AGI;
use DBI;
$AGI = new Asterisk::AGI;
my %input = $AGI->ReadParse(); #Read in the initial data
#Connect to MSSQL Server
$user = "user";

$passwd = "password";
$dbh = DBI->connect("DBI:Sybase:server=10.1.34.0", $user, $passwd, {PrintError => 0});
$dbh->do("use Clients");
unless ($dbh) {
die "Unable for connect to server $DBI::errstr";
}
$AGI->verbose("Checking IF client",1);
$sql = "select count(*) from clients where ClientPhone=\"$input{callerid}\"";
$sth = $dbh->prepare($sql);
$sth->execute();
while ( my @row = $sth->fetchrow_array( ) ) {
$isclient=$row[0];
}
$sth->finish();
$dbh->disconnect();
if ($isclient > 0)
{
$AGI->verbose("$input{callerid} is a client!!",1);
$AGI->stream_file('you are a client');
}
else
{
$AGI->verbose("$input{callerid} is not a client!!",1);
$AGI->stream_file('you are not a client');
}




Pretty neat huh? I thought so!! Good luck!








Thursday, December 7, 2006

/bin/rm: Argument list too long.


"what, a savvy guy like me having problems with a simple shell command like rm? Pleaaasee!!"


Linux always finds a way to make you humble again. Just when you begin to get cocky it has a way of slapping you behind the head and keeping you alert again. I just had such an experience...

while trying to delete a big directory (big as in many files....) i do this:

#rm -fr 200611*

and i get this:

/bin/rm: Argument list too long.

oh the agony... the intrigue... but don't worry... there is a way around this (as everything else in Linux).


strange as it seems most of the /bin/ commands have a limit of items it can process in order to avoid buffer overflows...so now it is time to ask our dear bash shell to help us out.

try this instead:

#find . -name '200611*'|xargs rm

this very simple script finds all files in the current directory which names starts with 200611 and then deletes them, passing the results via xargs and deleting them. xargs takes care for us to process batches of information big enough so the system may handle them without causing a buffer overflow. If more than one batch is needed, no problem xargs takes care of this.


Got slapped in the back also? kinda makes me feel in kindergarten all over again... don't eat the crayon...don't eat the crayon...



Friday, December 1, 2006

Modifying Asterisk Meetme enter/leave sounds Part 2

Ok, so im still dealing with modifying app_meetme.c enter/leave sounds. It is getting a little bit complicated.

I've found a little ms dos/windows utility called bin2h , you can find it here:

http://jonripley.com/windows/Software/bin2h/

this utility successfully converts binary files (audio, images) into a hex array that can be used in C.

Now my problem basically lies in understanding in which sound format i should record the sounds i want to be played during the enter/leave process of the conference.

The original enter.h files has this commented in the very beginning of the file:
00001 /* 00002   * U-law 8-bit audio data 00003   * 00004   * Source: enter.raw

Pretty easy huh? .raw file... 8 bit U-law? WRONG... i can't seem to get this sound file right..

with sox I'm trying the following command

sox audio.wav -r 8000 -c1 audio.ul

then from windows I do: bin2h audio.ul audio.h, replace/rename this into enter.h... recompile asterisk source... and then

NOTHING...

but we are still working on it.. so hopefully we get some results in part 3.


Bye!



Tuesday, November 28, 2006

Modifying Asterisk Meetme enter/leave sounds Part 1


hi there! this is my first post.

Im trying right now to change the sounds made when a person enters or leaves a conference room in Asterisk.

I was somehow disappointed to see that this sounds are HARDCODED into the app_meetme.c file

From the developer documentation I found out that enter and leave functions
call these files:

enter.h
and
leave.h

basically enter.h says this at the very beginning:
00001 /* 00002   * U-law 8-bit audio data 00003   * 00004   * Source: enter.raw 00005   * 00006   * Copyright (C) 1999, Mark Spencer and Linux Support Services 00007   * 00008   * Distributed under the terms of the GNU General Public License 00009   * 00010   */ 00011
00012
static unsigned char enter[] = {
00013 0xba, 0xba, 0xb0, 0xa6, 0xa9, 0xb8, 0xfe, 0x46, 0x42, 0x46,

So now I must find a way to change a wav or gsm file into this type of C array...

Im starting to fiddle around with sox, and i think i can get a raw output there...

now the challenge will be to find a utility that changes this binary output into a valid C array!!

Hope i have some good news in Part 2!!