Tuesday, April 21, 2009

Asterisk 1.2 , 1.4 & 1.6 Mp3 Voicemail using lame

Google Code checkout:
svn co http://codeoftheday.googlecode.com/svn/trunk/21April2009

Uncomment the following line in voicemail.conf

externnotify=/var/lib/asterisk/agi-bin/sendvoicemail.php

#!/usr/bin/php

<?php
/*
Released under Public Domain. Feel Free to modify and use it.
*/
mb_language('uni');
mb_internal_encoding('UTF-8');
require("class.phpmailer.php");

@mysql_connect("localhost","sqlusername","sqlpassword");
$dbselect = @mysql_select_db("asterisktable");

$voicemaildir = "/var/spool/asterisk/voicemail/" . $argv[1] . "/";

$sfilename = sprintf($voicemaildir .
"%s/INBOX/msg%04d.wav",$argv[2],$argv[3]-1);

$dfilename = sprintf($voicemaildir .
"%s/INBOX/msg%04d.mp3",$argv[2],$argv[3]-1);

$infofilename = sprintf($voicemaildir .
"%s/INBOX/msg%04d.txt",$argv[2],$argv[3]-1);

system("lame -V2 $sfilename $dfilename");



$stmt = sprintf("Select * from voicemail_users where mailbox='%s' and
context='%s'",$argv[2],$argv[1]);
$result = mysql_query($stmt);
if( mysql_num_rows($result) == 0 )
{
exit;
}

$row = mysql_fetch_assoc($result);
$rcptemail = $row['email'];
$rcptname = $row['fullname'];

$msginfo = parse_ini_file($infofilename);
$mail = new PHPMailer();
$mail->From = "noreply@voicetoemail.com";
$mail->FromName = "VoicetoEmail";
$mail->AddAddress($rcptemail, $rcptname);
$mail->AddReplyTo("noreply@voicetoemail.com", "VoicetoEmail");
$mail->WordWrap = 50; // set word wrap to 50 characters
$mail->AddAttachment($dfilename); // add attachments
$mail->IsHTML(true); // set email format to HTML

$mail->Subject = "Voicemail from " . $msginfo['callerid'];
$mail->Body = "Dear " . $rcptname . ",\n<br><br>Attached is the voice received
from " . $msginfo['callerid'] . "\n<br>Date & Time:" . $msginfo['origdate'] .
"\n\n<br><br>Support,<br>\nhttp://www.CalltoEmail.com";
$mail->AltBody = $mail->Body;
$mail->Send();

system("rm -rf $sfilename");
system("rm -rf $dfilename");
system("rm -rf $infofilename");

?>

Thursday, October 30, 2008

.spec file for sqlite3 for RPM or LTIB

Was searching for sqlite3 .spec file for LTIB and here is one. If there are anything need to be changed to make it generic, please share it across.

%define pfx /opt/freescale/rootfs/%{_target_cpu}
%define __os_install_post %{nil}

Summary : SQLite is a C library that implements an embeddable SQL database engine
Name : sqlite
Version : 3.6.4
Release : 1
License : Public Domain
Vendor : Sqlite
Packager : Kannaiyan
Group : System/Libraries
Source : %{name}-%{version}.tar.gz
BuildRoot : %{_tmppath}/%{name}
Prefix : %{pfx}

%Description
SQLite is a software library that implements a self-contained, serverless,
zero-configuration, transactional SQL database engine.
Programs that link with the SQLite library can have SQL database access
without running a separate RDBMS process. The distribution comes with a
standalone command-line access program (sqlite) that can be used to
administer an SQLite database and which serves as an example of how to
use the SQLite library.

%Prep
%setup

%Build
export BUILD_CC=/usr/bin/gcc
./configure --prefix=%{_prefix} --host=$CFGHOST --build=%{_build} --mandir=%{_mandir} --infodir=%{_infodir}
make

%Install
rm -rf $RPM_BUILD_ROOT
make install DESTDIR=$RPM_BUILD_ROOT/%{pfx}
rm -f $RPM_BUILD_ROOT/%{pfx}/%{_prefix}/lib/*.la

%Clean
rm -rf $RPM_BUILD_ROOT

%Files
%defattr(-,root,root)
%{pfx}/*

Tuesday, August 21, 2007

Pattern Matching with PCRE Library

Pattern matching is wonderful with Perl and when it is comes to C it is nice to build wonderful applications.

#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <locale.h>
#include <errno.h>
#include <pcre.h>

int main(int argc,char *argv[])
{
pcre *re;
char cgets[250];
const char *error;
int erroffset;
int retexec;
re = pcre_compile("^(gnayiru|thingal|chevvai|budhan|viyazhan|velli|sani)$",0,&error,&erroffset,NULL);
if( re )
{
while(1){
printf("Enter the details you wish to match:");
fgets(cgets,250,stdin);
cgets[strlen(cgets)-1] = '\0';
retexec = pcre_exec(re,NULL,cgets,strlen(cgets),0,PCRE_PARTIAL,NULL,0);
switch( retexec)
{
case PCRE_ERROR_NOMATCH:
printf("No Matches\n");
break;
case PCRE_ERROR_PARTIAL:
printf("Partial Match\n");
break;
case 0:
printf("Perfect Match\n");
break;
default:
printf("Error Code: %d\n",retexec);
break;
}
}
} else {
printf("Error in Regex Compilation");
}
}


Output here:

[root@localhost 21Aug2007]# ./nkans.out
Enter the details you wish to match:thi
Partial Match
Enter the details you wish to match:thing
Partial Match
Enter the details you wish to match:thingal
Perfect Match
Enter the details you wish to match:fldjlsjfl
No Matches
Enter the details you wish to match:

Google Code checkout:

svn co http://codeoftheday.googlecode.com/svn/trunk/21Aug2007

Sunday, August 19, 2007

Getting DNS SRV Records for voip through PHP

It is important for the internet service to automatically locate the services at the moment. Just use this code to get the voip protocols service records from the DNS servers.

#!/usr/bin/php
< ?php


$domain = "pulver.com";

$voipprotocol = array("sip","iax");
$transportproto = array("udp","tcp");

foreach($voipprotocol as $voipprot)
{
foreach($transportproto as $trprot)
{
$voipdomain = "_" . $voipprot . "._" . $trprot . "." . $domain;
echo "Searching $voipdomain\n";
$rootinfo = dns_get_record($voipdomain,DNS_ALL, $nsinfo, $addinfo);
//print_r($rootinfo);
foreach($rootinfo as $srootinfo)
echo strtoupper($voipprot) . " " . strtoupper($trprot) . " HOST: " .
$srootinfo['target'] . ":" . $srootinfo['port'] . "\n";
}
}

?>

You can download using svn with the following command,

svn co http://codeoftheday.googlecode.com/svn/trunk/18Aug2007

Do Let me know if there are any improvements done, will keep updated.

Enjoy.

If you want to get this done under C, you can look into the ruli library.

Ruli - DNS SRV Resolver

Tuesday, August 7, 2007

Convert header file tree to source file tree - Shell Script

It is usual practice to write header files first and then the source code. We usually need to go back an forth to get the header file name to start to go with the coding for enterprise projects.

Using the following command, you can convert the header tree to source tree.

find ./include -ls | awk '{print($3,$11);}' | cut -c1,11- | awk '{print($2,$1)}' | sed -e 's/^\.\/include//g' | awk '{if( $2 != "" ) print($1,$2);}' | awk '{if($2 == "d") printf("\"mkdir -p ./src%s\"\n",$1); else{ sub(/\.h$/,".cpp",$1); printf("\"touch ./src%s\"\n",$1);}}' | xargs | /bin/sh

replace .cpp with the extension you want.

It looks like

./include
|----dir1
|------- dir2
|-----------file.h
etc.,

./src
|--------dir1
|-----------dir2
|------------ file.cpp

All header files will replaced with their equivalent name in .c or .cpp with the extension you supply in the command.


Enjoy.

Monday, August 6, 2007

Find and Replace string in files under linux directory tree - Linux Shell Script

This is one of most used command in linux to replace the string in files.

find . -name "*.cpp" | xargs grep -l stringtofind | xargs sed -i s/stringtofind/stringtoreplace/

Friday, August 3, 2007

Code to generate Unique Random Numbers - PHP

I was looking for a Unique Random Number with different length to use it for one of the calling card company. This PHP script just rocks. Enjoy, download the code from svn rather than copy and paste.

#!/usr/bin/php

function generateuniquenumbers($len,$count,$includezero=1)
{

if( strlen($count) > $len )
{
echo "Looks something funny in the parameter which you have supplied. \n";
return ;
}
echo "Generating " . $count . " numbers with length " . $len . "\n";
$mult = 0;
$fract = 0;
$numbers[] = "";
mt_srand(10);
if( $len > 9 )
{
$mult = (int)($len/9);
$fract = (int) $len % 9;
} else {
$fract = $len;
}
if( $fract > 0 )
{
$minfract = "";
$maxfract = "";
for($m=0; $m<$fract; $m++)
{
if($includezero)
$minfract = "0";
else
$minfract .= "1";
$maxfract .= "9";
}
}

for($numcount=0;$numcount<$count;$numcount++)
{
$curnumber = "";
for($i=0;$i<$mult;$i++)
{
if( $includezero )
$currand = mt_rand(0,999999999);
else
$currand = mt_rand(111111111,999999999);
if( strlen($currand) <>
{
$templen = strlen($currand);
for( $pad = 9 - $templen; $pad > 0; $pad--)
$curnumber .= "0";
}
$curnumber .= $currand;
}
if( $fract > 0 )
{
$currand = mt_rand($minfract,$maxfract);
if( strlen($currand) <>
{
$templen = strlen($currand);
for( $pad=strlen($maxfract)-$templen;$pad > 0;$pad--)
$curnumber .= "0";
}
$curnumber .= $currand;
}
if( !in_array($curnumber,$numbers) )
{
$numbers[] = $curnumber;
}
else
$numcount --;
}
return $numbers;
}

$ncount = 20;
$nlength = 20;

$numbers = generateuniquenumbers($nlength,$ncount,0);

for($k=1;$k<=$ncount;$k++)
echo $numbers[$k] . "\n";

?>

Here is the output:

[root@kansdevhost devel]# ./kansrand.php
Generating 20 numbers with length 20
16181070355240094632
35133279664046683582
56683089348828603637
61797018627269033641
32242637617039241045
53775119541769589123
98009706424319286130
67830750255154478737
4554441961805820434
24613857566557562252
86485415760605734578
30890354240158234429
12549747923000041677
85786735955666425870
44706552566779852177
41866325246584913132
61537972143640201927
52078343311552209047
53657534152010051142
74283518264934633688

You can download using svn with the following command,

svn co http://codeoftheday.googlecode.com/svn/trunk/03Aug2007

Do Let me know if there are any improvements done, will keep updated.

Enjoy.