The Alchemist's profileMaverick's SpacePhotosBlogListsMore ![]() | Help |
Maverick's SpaceThe Alchemist |
||||||||||||||||||||||||||||||||
|
5/14/2008 Hell is near!Heard about quakes in china :( ; it's pathetic to see loss of so
many human lives in a zap motion of earth; we live so much short
uncontrolled lives, and nature reminds us that. Yesterday, at least 60 people died in Jaipur in serial blasts , that was more painful to see people taking the news with equal status of IPL matches; how come humans become so heartless; 60 people died, and all people care for is how Shoaib akhtar took wickets yesterday? My heartiest condolence for the families of demised; and Prayers to god for resting the souls in peace. I feel like Hell is coming near to us all; around 10 million people died in Myanmar a weak back due to cyclone Nargis, then China, and then blasts in India, feels as if Lucifer is getting hold of mankind; but we shall not forget that god gave us a gift of love. and humanity; we shall practice the most basic right of being loved and loving people. My love to all.... 5/7/2008 asterisk for java - installationNow a days i am playing with Asterisk, and now I needed to integrate a Java based application with asterisk. I started searching, and found about JAsterisk, but later i found that JAsterisk was made with Asterisk 1.0.0 while I am running with Asterisk 1.4, and 1.2 installations. Then I found Asterisk for Java ; this package is built on top of Maven [a project management API for Linux], the pre-requisites were as follows 1. JDK above version 1.5 2. Maven Now, JDK has a significant style of it :) ... but As I am a .net developer I'll say it sucks....I tumbled a lot with installation sof JDK's and JVM' and environment variables, let me simplify it for you.... 1. Download JDK from http://java.sun.com/javase/downloads/ you need to download the self extracting binary .. with a name somewhat like this jdk-6u6-linux-i586-rpm.bin 2. Copy it into a directory; I copied it in /opt , extracted it there by command ./jdk-6u6-linux-i586-rpm.bin Note - it should install automatically, but if it doesn't or it says some Java Package is already installed you'll have to remove it yum remove <packagetoremove> 3. Now we need to create environment variables My JAVA is installed in directory /usr/java/jdk1.6.0_06 this is how you can persist your Java environment variables for good in your linux machine, be it on root OR on user open the directory /etc Find the file profile open it type these lines, one for PATH, one for JAVA_HOME, and one for CLASSPATH Note - remove my comments from here before copy pasting these lines, also put them at end of file //for the directory path where JAVA imnstallation resides export JAVA_HOME=/usr/java/jdk1.6.0_06 //For the path where compiler resides, the bin dir contains javac which is the compiler export PATH=PATH=$PATH:/usr/java/jdk1.6.0_06/bin //For the PATH where classes may reside,m in our case they may reside in any directory export CLASSPATH=$CLASSPATH:. Now, you should restart your machine, raise the terminal window [command prompt] and cross check type these commands, and you may see the results like this [root@localhost ~]# java -version java version "1.7.0" IcedTea Runtime Environment (build 1.7.0-b21) IcedTea Client VM (build 1.7.0-b21, mixed mode) [root@localhost ~]# which java /usr/bin/java [root@localhost ~]# which javac /usr/bin/javac [root@localhost ~]# echo $JAVA_HOME /usr/java/jdk1.6.0_06 [root@localhost ~]# echo $PATH /usr/local/apache-maven-2.0.9/bin:PATH=/usr/local/apache-maven-2.0.9/bin:PATH=/usr/local/apache-maven-2.0.9/bin:PATH=/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/usr/java/jdk1.6.0_06/bin:/usr/java/jdk1.6.0_06/bin:/root/bin:/usr/java/jdk1.6.0_06/bin [root@localhost ~]# echo $CLASSPATH :.:.:. Ok , Now lets get the runtime of Asterisk for Java, As I don't have any plans to play with source of asterisk for Java download the Asterisk-java-03.jar from http://sourceforge.net/projects/asterisk-java/ for testing create a directory and copy this Asterisk-java-03.jar file in it Now create a file HelloAGIScript.java and copy paste this code import org.asteriskjava.fastagi.AgiChannel; import org.asteriskjava.fastagi.AgiException; import org.asteriskjava.fastagi.AgiRequest; import org.asteriskjava.fastagi.BaseAgiScript; public class HelloAGIScript extends BaseAgiScript { public void service(AgiRequest request, AgiChannel channel) throws AgiException { // Answer the channel... answer(); // ...say hello... streamFile("tt-monkeysintro"); // ...and hangup. hangup(); } } Save it in the same folder, I have saved both of these files at /root/MyAgiScript, now go to terminal window, and compile it [root@localhost MyAgiScripts]# javac -g -cp asterisk-java-0.3.jar HelloAGIScript.java Now, create a file fastagi-mapping.properties copy and paste this code //for mapping the agi script to the Java code we created hello.agi = HelloAGIScript now go to your dialplan in asterisk /etc/asterisk/extensions..conf I have a dialplan like this, which I can dial from a SIP phone [sip] ; exten => 1,1,Answer() exten => 1,2,Wait(2) exten => 1,3,Record(asterisk-recording%d:ulaw) exten => 1,4,Wait(2) exten => 1,5,Playback(${RECORDED_FILE}) exten => 1,6,Agi(agi://localhost/hello.agi) exten => 1,6,Hangup() Now open another terminal window, and run your AGI server java -cp asterisk-java-0.3.jar:. org.asteriskjava.fastagi.DefaultAgiServer and it should run like this May 7, 2008 5:38:29 PM org.asteriskjava.fastagi.DefaultAgiServer startup INFO: Thread pool started. May 7, 2008 5:38:30 PM org.asteriskjava.fastagi.DefaultAgiServer startup INFO: Listening on *:4573. May 7, 2008 5:39:25 PM org.asteriskjava.fastagi.DefaultAgiServer startup INFO: Received connection from /127.0.0.1 May 7, 2008 5:39:25 PM org.asteriskjava.fastagi.ResourceBundleMappingStrategy loadResourceBundle INFO: Added mapping for 'hello.agi' to class HelloAGIScript May 7, 2008 5:39:25 PM org.asteriskjava.fastagi.internal.AgiConnectionHandler runScript INFO: Begin AgiScript HelloAGIScript on Asterisk-Java DaemonPool-1-thread-1 May 7, 2008 5:39:25 PM org.asteriskjava.fastagi.internal.AgiConnectionHandler runScript INFO: End AgiScript HelloAGIScript on Asterisk-Java DaemonPool-1-thread-1 This output- comes when I dial a call from my sip-phone to the asterisk server; and it plays a sound file for me...... Please feel free to ask me any questions you may have; it was sweet to do this, hope someone could've posted all the details like this. 3/12/2008 IIT ka bhoot !
Hieeee! it was another fire fighting day in my office, a service stopped working for no good reasons; anyways Mr. Prawal gupta, our Managing partner in UK , was visiting us , and we [ employees ] thought "why not give him a treat ?" So, Praveen Kumar [ apna local bindaas project managgger * , woh kirket waala nahi :) ] asked me to invite both of our bosses and the rest of team to come and join us for a lunch; for which all the hungry stomachs' agreed; "Mein toh ghar se lunch laata hoon" but i thought i'll give it a skip today. They all left for Atta Market, CSM Mall in two cabs, and Me, Praveen decided to come by Bike, toh fir ek honey waaley Papa ka [ "samajh gaye naa ! :)"] bojh apney pichhli seat par lekar hum nikal padey atta ki ore. Skinny, moti, aur sexy punjaabi ladkiyan taadtey huey [Taadtey - boley toh aankh seenkna, ab yeh kya hota hai, yeh samjhaaney ka time ko naa beta mere paas, je reader chhori hai toh saturday ko aaja, TwoSON de doon !], haan toh apun pahunch gaye CSM MAAAL, and we joined in at Punjabi tadka restaurant. ab muddey ki baat, Praveen wanted to Ask Tarun [my iitian boss] ,and Prawal [he's a fellow iitian with Tarun] , that when should a guy start preparing for IIT, and Tarun, prawal replied satisfactorily, though i didn't took much part in this conversation, i hardly know about iit's, but it put me in thoughts for a while when i was in 8th , 9th or even 11th, 12th, God promise mujhkko bilkul nahi pata tha yeh hoti kya hai?, i was like a lost kid, woh "Taarey zammen Par" waala Chu*** bachcha hai naa, bilkul waisa tha mein :); socha yaar "maa baap ko aajkal kitna pata hai, IIT, FIIT", Tabhi Tarun sir na bataya ki, udhar par back to back exam hotey hain, aur Discipline is hard, aur haan curse words ki bhi baat hui, fir dimaag ke ghodey chaley aur apney graduation ke din aaye - discipline ? yeh kya hota hai ? yaad hai woh mussorie ki trip, apun 5 yaar they, ek car mein, aur woh B****C*** toh koi 500000 baar use kiya tha humney, thank god meri behan nahi hai, varna bechaari ko kitna khatra ho jaata tha..... Rest - abey yeh aaram waala hai, bachi hui post baad mein kabhi likhoonga..... 2/21/2008 Copy Lines from a file to an array of Character pointer or say char*array[]
SO I happened to be in position to write some C code, to copy the contents of a file line by line to an array of character pointers; for a .net guy it's nothing but array of strings, and each string would contain a line of this file, and we had to iterate line by line....seems easy so I came up with this code.... I initialised the variables like
/* PS - it's a wrong code...I'll narrate the problem after U see the code...... */ char c[256]={0}; static char *recogArgv[6]; file = fopen("MyArgs.txt","r"); if(file==NULL) /* here goes my code to iterate line by line and put variables into the array of char*/ so every time i ran this "Else" loop. it did get the new line in variable c but always, when i iterate i found that all the contents in the array of char* are same , obvious? coz the c is nothing but a pointer, and it ought just copy the pointer address to the recogArgv, leading to the problem of same content in all the items of this array. solution? i did live search, Google search and nothing....people are talking about malloc, calloc, free....Guys I am a .net guy and i want an API, I don't get registers...and hey I did found an API. and here's the right code...it uses strdup API to get me a duplicate address for the c which I would pass to my recogArgv and problem solved.... /* The perfect Code */ char c[256]={0}; static char *recogArgv[6]; file = fopen("MyArgs.txt","r"); if(file==NULL) /* here goes my code to iterate line by line and put variables into the array of char*/ recogArgv[i] = strdup(c); /*The use of strdup not only made my program pointer safe, but also helped me from getting into the malloc, calloc stuff */ i = i + 1; Cheers!
|
|||||||||||||||||||||||||||||||
|
|