Thread: [Asterisk-java-devel] org.asteriskjava.fastagi.internal.AgiReaderImpl doesn't haven't multiline re
Brought to you by:
srt
From: Steve P. <sp...@ge...> - 2006-12-24 22:03:46
|
I've been playing with the Lumenvox integration with Asterisk with asterisk-java and for a start I've been trying to port over the Lumenvox Pizza demo to Java. I've made decent progress and like how asterisk-java is working out as a programming environment for speech apps, but I've run into a problem. String text = this.getFullVariable("${SPEECH_TEXT(0)}"); Is used to retrieve the spoken words recognized by the Lumenvox engine. In the case of the individual pizza ingredients prompt, this value isn't filled in with a single word (which works fine in asterisk-java), but rather returns a multi-line XML structure which contains a list of each ingredient recognized. Unfortunately it seems that getFullVariable() returns null when it is given a multi-line value from Asterisk. I traced this down to AsiReaderImpl.readReply() which only seems to read multiple lines of response when the response starts with AgiReply.SC_INVALID_COMMAND_SYNTAX. So it seems that there are cases when readReply() should be reading additional lines of response before the line: reply = new AgiReplyImpl(lines); The big thing stopping me from fixing this right now is that I don't know exactly what the format for a multi-line response to getFullVariable is defined to be. Anyone know what this is? Steve |
From: Stefan R. <ste...@re...> - 2006-12-27 18:41:46
Attachments:
signature.asc
|
Hi Steve, Steve Prior wrote: > The big thing stopping me from fixing this right now is that I don't=20 > know exactly what the format for a multi-line response to=20 > getFullVariable is defined to be. Anyone know what this is? Can you point me to some documentation regarding Lumenvox so I can have a look at what behavior it expects? =3DStefan --=20 reuter network consulting Neusser Str. 110 50760 Koeln Germany Telefon: +49 221 1305699-0 Telefax: +49 221 1305699-90 E-Mail: ste...@re... Jabber: ste...@re... |
From: Steve P. <sp...@ge...> - 2006-12-27 19:39:36
|
Stefan Reuter wrote: > Hi Steve, > > Steve Prior wrote: > >>The big thing stopping me from fixing this right now is that I don't >>know exactly what the format for a multi-line response to >>getFullVariable is defined to be. Anyone know what this is? > > > Can you point me to some documentation regarding Lumenvox so I can have > a look at what behavior it expects? > > =Stefan I don't have this documentation, but I don't think I'm actually asking for anything Lumenvox specific. It's more about how the AGI protocol works. Here's a bit of my asterisk log while running the normal pizza demo: -- Executing Set("IAX2/66.225.202.80:4569-4", "TOPPING=<item index=0> <toppinglist> <item index=0> <ingredient> onions </ingredient> </item> <item index=1> <ingredient> pepperoni </ingredient> </item> </toppinglist> </item> ") in new stack So as you can see the demo is setting the value of an asterisk variable to a value which spans lines (and happens to be an XML fragment, but I don't think you care about that). The problem appears when I try to call getFullVariable() on a variable which returns such a multiline value - the current implementation of AgiImpl only reads the first line which here is "TOPPING=<item index=0> and doesn't follow through and read the rest of the lines up to the following double quotes. Now I'm sure there is some complication in the AGI protocol as to how to handle escaped quotes (if they are allowed at all). So I think the solution is to modify AgiImpl to read the full set of lines for a response and not stop at one - up until it reads the close quote. Then I can simply get that multiline string to my java code, interpret the XML as I see fit, and should be all set. So multiline variable values has been a possibility all along, it's just never been encountered before now. Thanks Steve |
From: Stefan R. <ste...@re...> - 2006-12-27 22:16:29
Attachments:
signature.asc
|
Hi, AGI (as many Asterisk APIs) is very poorly documented and a "specification" (besides the source) does not exist (at least as far as know). What I thought when implementing the AgiReader was that newlines are forbidden in variable names (in fact you are unable to set them through the dialplan). I played around with the current implementation (Asterisk 1.2.13) and checked the handling of quotes. If we try to support multiline values in variable content by looking for matching quotes before returning, quotes must be correctly escaped by Asterisk as you aready noted. Here are my results: This is the Java code I used: public void service(AgiRequest request, AgiChannel channel) throws AgiException { setVariable("TESTVAR", "ab \" cd"); System.out.println(getVariable("TESTVAR")); } which prints: ab " cd The network dump shows: # ngrep port 4573 interface: eth0 (10.13.0.0/255.255.255.0) filter: (ip or ip6) and ( port 4573 ) (snip) T 10.13.0.57:4573 -> 10.13.0.102:55592 [AP] SET VARIABLE "TESTVAR" "ab \" cd". ## T 10.13.0.102:55592 -> 10.13.0.57:4573 [AP] 200 result=3D1. # T 10.13.0.57:4573 -> 10.13.0.102:55592 [AP] GET VARIABLE "TESTVAR". # T 10.13.0.102:55592 -> 10.13.0.57:4573 [AP] 200 result=3D1 (ab " cd). Until now I have no idea on how to support newlines as matching by quotes seems to be impossible. Additionally I have worries regarding the Manager API. The Manager reponses follow this syntax: key1: value1\n key2: value2\n \n Variables values with newlines would probably cause Asterisk to return an invalid response to a GetVariable action (I am speculating here as I didnt test it actually). Any ideas? =3DStefan Steve Prior wrote: > Stefan Reuter wrote: >=20 >> Hi Steve, >> >> Steve Prior wrote: >> >>> The big thing stopping me from fixing this right now is that I don't = >>> know exactly what the format for a multi-line response to=20 >>> getFullVariable is defined to be. Anyone know what this is? >> >> Can you point me to some documentation regarding Lumenvox so I can hav= e >> a look at what behavior it expects? >> >> =3DStefan >=20 >=20 > I don't have this documentation, but I don't think I'm actually asking = for anything > Lumenvox specific. It's more about how the AGI protocol works. Here's= a bit of > my asterisk log while running the normal pizza demo: >=20 >=20 > -- Executing Set("IAX2/66.225.202.80:4569-4", "TOPPING=3D<item ind= ex=3D0> > <toppinglist> > <item index=3D0> > <ingredient> > onions > </ingredient> >=20 > </item> > <item index=3D1> > <ingredient> > pepperoni > </ingredient> >=20 > </item> >=20 > </toppinglist> >=20 > </item> > ") in new stack >=20 >=20 > So as you can see the demo is setting the value of an asterisk variable= to a > value which spans lines (and happens to be an XML fragment, but I don't= think you care > about that). The problem appears when I try to call getFullVariable() = on a > variable which returns such a multiline value - the current implementat= ion > of AgiImpl only reads the first line which here is "TOPPING=3D<item ind= ex=3D0> > and doesn't follow through and read the rest of the lines up to the fol= lowing > double quotes. Now I'm sure there is some complication in the AGI prot= ocol > as to how to handle escaped quotes (if they are allowed at all). >=20 > So I think the solution is to modify AgiImpl to read the full set of li= nes for a > response and not stop at one - up until it reads the close quote. Then= I > can simply get that multiline string to my java code, interpret the XML= > as I see fit, and should be all set. >=20 > So multiline variable values has been a possibility all along, it's jus= t never > been encountered before now. >=20 > Thanks > Steve >=20 > -----------------------------------------------------------------------= -- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share= your > opinions on IT & business topics through brief surveys - and earn cash > http://www.techsay.com/default.php?page=3Djoin.php&p=3Dsourceforge&CID=3D= DEVDEV > _______________________________________________ > Asterisk-java-devel mailing list > Ast...@li... > https://lists.sourceforge.net/lists/listinfo/asterisk-java-devel --=20 reuter network consulting Neusser Str. 110 50760 Koeln Germany Telefon: +49 221 1305699-0 Telefax: +49 221 1305699-90 E-Mail: ste...@re... Jabber: ste...@re... |
From: Steve P. <sp...@ge...> - 2006-12-27 22:30:28
|
Stefan Reuter wrote: > Any ideas? > > =Stefan I would suggest that for the beginning we assume that quotes within a variable value are not allowed and we don't have to deal with them - no need to fight that battle before we have to. Therefore life becomes more simple - you can start reading a value and simply cross newline borders until you find the next close quote. Any newlines encountered would be returned as part of the value. I don't know if there are any valid multiline responses to any queries besides the error one that's already there and now the result of getvariable which could be coded as a special case as well, so as long as the manager interface is using different queries it wouldn't be affected. If quotes really do start showing up anyplace in variable values, then we'll have to deal with it then, but this is a step in the right direction I think. Steve |
From: Stefan R. <ste...@re...> - 2006-12-27 23:11:38
Attachments:
signature.asc
|
To me it seems that using a newline character in variable values violates the non-existing specification. If we disallow quotes instead of newline characters we produce two proble= ms: - code that has worked before will break - usage of quotes that does not match our point of view will cause the whole application to hang because the closing quote never appears. To me it sounds much more reasonable to disallow newlines. In the case of the xml reply you presented this would be very simple as the string without newlines would represent the exact same information. =3DStefan --=20 reuter network consulting Neusser Str. 110 50760 Koeln Germany Telefon: +49 221 1305699-0 Telefax: +49 221 1305699-90 E-Mail: ste...@re... Jabber: ste...@re... |
From: Stefan R. <ste...@re...> - 2006-12-27 23:13:12
Attachments:
signature.asc
|
P.S. If you like we could discuss on the asterisk-dev list and/or with Lumenvox to find a solution that works for everyone and does not impose another set of issues. =3DStefan --=20 reuter network consulting Neusser Str. 110 50760 Koeln Germany Telefon: +49 221 1305699-0 Telefax: +49 221 1305699-90 E-Mail: ste...@re... Jabber: ste...@re... |
From: Steve P. <sp...@ge...> - 2007-01-03 21:37:09
|
Stefan Reuter wrote: > To me it seems that using a newline character in variable values > violates the non-existing specification. > If we disallow quotes instead of newline characters we produce two problems: > - code that has worked before will break > - usage of quotes that does not match our point of view will cause the > whole application to hang because the closing quote never appears. > > To me it sounds much more reasonable to disallow newlines. In the case > of the xml reply you presented this would be very simple as the string > without newlines would represent the exact same information. > > =Stefan You've convinced me - I withdraw the request. I've also discussed this with Lumenvox and they're going to eliminate the newlines in their values. Steve |