Statistics

Content View Hits : 19205
Development
Asterisk Ring Groups PDF Print E-mail
Written by Gurito   

A few days ago I was asked to implement a ring group in Asterisk. I thought okay, it's pretty straight forward, I just put all the devices I want to ring in a Dial command and that's it. So I did, but then I was told that that was not entirely ok. They wanted a delay between devices, such that at first only one phone would ring, X seconds later a second device (without the first one stopping) and so on. I thought I could put more Dial commands in a specific order, but then I had the problem that if the first one didn't answer, it would indicate a missed call.

So here is how I finally solved it with help of my colleague Bleek.

  1. [wait-op]
  2. ; Ask if the channel is available, if it is
  3. ; go to the next step. If it isn't go to no-op
  4. ; and skip the delay.
  5. exten = _XX,1,ChanIsAvail(SIP/${EXTEN})
  6. exten = _XX,n,GotoIf($[ "${AVAILCHAN}"="" ]?no-op|s-na|1:3)
  7. ; Increment the delay by a value of five.
  8. exten = _XX,n,Set(DB(cross/delay-${key})=$[${DB(cross/delay-${key})}+5])
  9. exten = _XX,n,Wait(${DB(cross/delay-${key})})
  10. exten = _XX,n,Dial(SIP/${EXTEN})
  11.  
  12. [no-op]
  13. ; Do nothing
  14. exten = s,1,NoOp(Dummy)
  15. exten = s-na,1,NoOp(Channel is not available)
  16.  
  17. [hotline-0]
  18. ; Define a custom name for the caller ID.
  19. ; This was an extra that I did
  20. exten = s,1,Set(CALLERID(name)=hotline ${CALLERID(name)} ${CALLERID(num)})
  21. ; Set a key unique for each channel. So id doesn't matter how
  22. ; many calls we get, there will always exist just one key per channel
  23. ; This way we increase the delay only when we want to.
  24. exten = s,n,Set(__key=${CHANNEL})
  25. ; Define the initial delay value on the database. That's even better than
  26. ; a global variable. One advantage, pointed out by a collegue of mine, is
  27. ; that when the process is over, you can delete the key from the DB.
  28. exten = s,n,Set(DB(cross/delay-${key})=-5)
  29. ; Set all the devices as a single variable.
  30. ; Note that all of them use the "Local" context
  31. exten = s,n,Set(dg0=Local/91@wait-op)
  32. exten = s,n,Set(dg0=${dg0}&Local/93@wait-op)
  33. exten = s,n,Set(dg0=${dg0}&Local/95@wait-op)
  34. exten = s,n,Set(dg0=${dg0}&Local/20@wait-op)
  35. exten = s,n,Set(dg0=${dg0}&Local/21@wait-op)
  36. exten = s,n,Set(dg0=${dg0}&Local/50@wait-op)
  37. exten = s,n,Set(dg0=${dg0}&Local/22@wait-op)
  38. exten = s,n,Dial(${dg0}|80)
  39. ; Manage the voicemail with a macro
  40. exten = s,n,Macro(hotline-voicemail|${DIALSTATUS}|0)
  41. ; Delete the keys at hangup
  42. exten = h,1,NoOp(DB_DELETE(cross/inc-${key})
  43. exten = h,n,Hangup
  44.  
  45. [macro-hotline-voicemail]
  46. ; ${ARG1} Dialstatus
  47. ; ${ARG2} Whose voicemail?
  48. exten = s,1,Set(CHANNEL(language)=de)
  49. exten = s,n,Goto(s-${ARG1},1)
  50. exten = s-BUSY,1,Voicemail(${ARG2},b)
  51. exten = s-NOANSWER,1,Voicemail(${ARG2},u)
  52. exten = s-CONGESTION,1,Voicemail(${ARG2},b)
  53. exten = s-CHANUNAVAIL,1,Voicemail(${ARG2},u)

I know it's perhaps not the best approach. We didn't want to use queues, because our peers aren't agents, and, though it can be optimised, it works now :)

Hope it helps somebody,

Happy coding. 

Last Updated on Tuesday, 31 March 2009 14:55
 
Asterisk Voicemail PDF Print E-mail
Written by Gurito   

So, I did a fresh install from Asterisk on a server, then configured some SIP users and connected Snom phones for each one of them. Then, as I was testing, I noticed that the "Mail" button on the Snom phones dialed an extension "asterisk". So I couldn't get around dialing the general voicemail extension in order to check my mail.

Anyway, there are a few solutions to this problem. One of them is including the option "vmexten" for each user, either in sip.conf or in users.conf. The problem with this approach is that any other user can dial any existing "vmexten" value and, given that he/she knows the password for this voicemail, access the mailbox. So, in order to solve this problem a collegue told me that it was perhaps a good idea to use the "asterisk" extension.

Here is how I did it. In the file "extensions.conf" I performed the next changes:

  1. ;
  2. ; *First thing is defining an ew context for the voicemail*
  3. [voicemail]
  4. exten = asterisk,1,NoOp(This extension takes us to check the voicemail)
  5. exten = asterisk,n,NoOp(Caller ID : ${CALLERID(num)})
  6. exten = asterisk,n,NoOp(Channel Type : ${CHANNEL(channeltype)})
  7. exten = asterisk,n,GotoIf($[ "${CHANNEL(channeltype)}" = "SIP" ]?asterisk-sip,1)
  8. exten = asterisk,n,GotoIf($[ "${CHANNEL(channeltype)}" = "IAX2" ]?asterisk-iax,1)
  9. exten = asterisk-sip,1,NoOp(SIP Name : ${SIPCHANINFO(peername)})
  10. exten = asterisk-sip,n,NoOp(Mailbox : ${SIPPEER(${SIPCHANINFO(peername)}|mailbox)})
  11. exten = asterisk-sip,n,Macro(voicemail-general|${SIPPEER(${SIPCHANINFO(peername)}|mailbox)})
  12. ; *Now, there's no IAXCHANINFO on asterisk 1.2 - 1.4. But it will work if you have an IAX2 client*
  13. ; *that supports entering voicemail login info. (like voix phone)*
  14. exten = asterisk-iax,1,NoOp(IAX automatic voicemail is not yet supported)
  15. exten = asterisk-iax,n,Macro(voicemail-general)
  16.  
  17.  
  18. ; *Second thing is definig a Voicemail Macro.*
  19. ; *Think of this macro as of a function which performs a login for the voicemail.*
  20. [macro-voicemail-general]
  21. ; ${ARG1} = User's mailbox
  22. ; *If the SIP 12 has the mailbox 30, then ${ARG1} = 30.*
  23. ; *But don't worry, this parameter is already given by the "asterisk" context previously defined.*
  24. ; Set the language for the voicemail message.
  25. exten = s,1,Set(CHANNEL(language)=de)
  26. exten = s,n,Answer()
  27. exten = s,n,GotoIf($[ ${ISNULL(${ARG1})} ]?s-null,1)
  28. ; *In my case I had to put this wait in order for the greeting message to play completely.*
  29. exten = s,n,Wait(1)
  30. exten = s,n,VoiceMailMain(${ARG1})
  31. exten = s,n,Hangup()
  32. ; *The extension s-null is called when ${ARG1} is empty*
  33. ; *In this case, we call VoiceMailMain withouth parameters and, if the client, say voix phone,*
  34. ; *has the voicemail login data configured, it will pass it automatically to asterisk.*
  35. ; *It may well be that you don't need the "Wait()" here*
  36. exten = s-null,1,Wait(1)
  37. exten = s-null,n,VoiceMailMain()
  38. exten = s-null,n,Hangup()
  39.  
  40.  
  41. ; *Finally, I included the "voicemail" context on the default context for my users.*
  42. [default]
  43. include = voicemail
  44. ...
  45.  


So that's it... I hope you find it useful.

Happy coding. :)

Last Updated on Tuesday, 31 March 2009 15:03
 
ServerSocket + certificates PDF Print E-mail
Written by Gurito   

Recently I'm involved in a project in which we have the following (simplest) scenario. Two machines are using RMI in a network. We want to use RMI over SSL in order to make it secure. And we want to be able to read certificates in both sides, server and client. In both sides we want to check the contents of the certificates before actually establishing a connection.

For this purpose I wrote a very basic implementation of ServerSocket. In this class I delegate the methods to SSLServerSocket and CryptoBroker is a class which provides a Context, with which we construct an SSLServerSocket.  You should write your own methods to do this.

Last Updated on Tuesday, 31 March 2009 15:07
Read more...
 
Sun Java 64 rpm PDF Print E-mail
Written by Gurito   

Well, I really don't know why the guys from Jpackage don't provide an rpm for sun java 64 bit. And, well, I did want to use it. So I just made myself a java-sun-compat which works with the latest version of java (1.6_u2). I'm using it currently in Fedora 7 (I guess it works for more distros though), and it should be safe --as I built it from the Source rpm from Jpackage. So, actually, the credit is not mine, I just rebuilt it. :p

Anyway, as always, you're free to download it from the downloads section. :)

 
Sum of squares without multiplying PDF Print E-mail
Written by Gurito   

This was a program we had to implement at the university a couple of months ago... It's just a tiny piece of code showing how to perform the sum of the squared numbers in [0, N]. That means, 1^2 + 2^2 + ... + N^2.

It's written in c and, well.. you'll find it pretty straight forward.

Last Updated on Tuesday, 31 March 2009 15:13
Read more...
 
«StartPrev12NextEnd»

Page 1 of 2