Thread: [Asterisk-java-users] fastagi.command.GetDataCommand issue
Brought to you by:
srt
From: Steve D. <Ste...@Su...> - 2005-04-29 23:17:36
|
It is legal to send this command to asterisk "GET DATA foo". This implies a six second timeout and unlimited digits. But new GetDataCommand("foo") translates to "GET DATA foo 0 1024", which really isn't the same thing. |
From: Stefan R. <sr...@re...> - 2005-04-29 23:33:05
|
On Fri, 2005-04-29 at 16:17 -0700, Steve Drach wrote: > It is legal to send this command to asterisk "GET DATA foo". This=20 > implies a six second timeout and unlimited digits. But new=20 > GetDataCommand("foo") translates to "GET DATA foo 0 1024", > which really isn't the same thing. >=20 when having a look at asterisk's res/res_agi.c the corresponding function is: static int handle_getdata(struct ast_channel *chan, AGI *agi, int argc, char *argv[]) { int res; char data[1024]; int max; int timeout; if (argc < 3) return RESULT_SHOWUSAGE; if (argc >=3D 4) timeout =3D atoi(argv[3]); else timeout =3D 0; if (argc >=3D 5) max =3D atoi(argv[4]); else max =3D 1024; [...] } It seems to me that "GET DATA foo" is translated to "GET DATA foo 0 1024" and thats exactly what asterisk-java sends. right? =3DStefan |
From: Steve D. <Ste...@Su...> - 2005-04-29 23:40:36
|
> On Fri, 2005-04-29 at 16:17 -0700, Steve Drach wrote: >> It is legal to send this command to asterisk "GET DATA foo". This >> implies a six second timeout and unlimited digits. But new >> GetDataCommand("foo") translates to "GET DATA foo 0 1024", >> which really isn't the same thing. ... > It seems to me that "GET DATA foo" is translated to "GET DATA foo 0 > 1024" and thats exactly what asterisk-java sends. right? Yes, that is what it sends. I think it should send "GET DATA foo". |
From: Stefan R. <sr...@re...> - 2005-04-29 23:57:01
|
> > It seems to me that "GET DATA foo" is translated to "GET DATA foo 0 > > 1024" and thats exactly what asterisk-java sends. right? >=20 > Yes, that is what it sends. I think it should send "GET DATA foo". hmm we could do this, though it would imply to use nullable Integers instead of the easier to use ints for timeout and maxDigits. That would make GetDataCommand quite different from the other Commands that use primitive attributes. Nevertheless asterisk uses a default timeout of 0 and a default maxDigits of 1024, so there is really no semantic difference between the two. You might consider this knowledge of asterisk internals a violation of encapsulation practices but some knowledge is needed anyway (i.e. to enforce the maximum maxDigits of 1024 to prevent buffer overflows, see below). Using 0 as timeout indicates "default timeout" and thats defined as 6000 in app.c ast_app_getdata_full(..). Using 1024 as maxDigits is the maximum number of digits GET DATA can handle anyway as the buffer that is used by asterisk is defined as char data[1024]. Although asterisk does not enforce a maximum of 1024 reading more digits would result in a buffer overflow. =3DStefan |
From: Steve D. <Ste...@Su...> - 2005-05-03 19:19:12
|
Apparently it's legal to get this reply from Asterisk: 200 result= (timeout) I got that from a GetData command So, it seems where the patterns are "^200 result=//S+ ", they should be "^200 result=//S* +" (just in case there is more than 1 blank) |
From: Stefan R. <sr...@re...> - 2005-05-03 21:08:37
|
On Tue, 2005-05-03 at 12:17 -0700, Steve Drach wrote: > So, it seems where the patterns are "^200 result=3D//S+ ", they should > be > "^200 result=3D//S* +" (just in case there is more than 1 blank) Thanks, I fixed it in CVS. =3DStefan |
From: Steve D. <Ste...@Su...> - 2005-05-03 23:44:02
|
On Apr 29, 2005, at 4:56 PM, Stefan Reuter wrote: >>> It seems to me that "GET DATA foo" is translated to "GET DATA foo 0 >>> 1024" and thats exactly what asterisk-java sends. right? >>> >> >> Yes, that is what it sends. I think it should send "GET DATA foo". >> > > hmm we could do this, though it would imply to use nullable Integers > instead of the easier to use ints for timeout and maxDigits. Um, just change return "GET DATA " + escapeAndQuote(file) + " " + timeout + ... to "GET DATA " + escapeAndQuote(file) + " " + (timeout != 0 ? timeout : "") and likewise for maxDigits. > That would > make GetDataCommand quite different from the other Commands that use > primitive attributes. "Consistency is the hobgoblin of small minds" ;-) > Nevertheless asterisk uses a default timeout of 0 and a default > maxDigits of 1024, so there is really no semantic difference > between the > two. In fact there is. If you send "GET FILE foo", then ast_readstring_full gets timeout=2000 and ftimeout=6000. But if you send "GET FILE foo 0 1024, then timeout=ftimeout=6000. > You might consider this knowledge of asterisk internals a violation > of encapsulation practices but some knowledge is needed anyway > (i.e. to > enforce the maximum maxDigits of 1024 to prevent buffer overflows, see > below). Not at all. Asterisk enforces the max length of 1024 as it should, since it owns the buffer. Asterisk-java has no business knowing this. Nor should it care as long as it sends the syntactically correct GET DATA command, which is documented in res_agi.c as: GET DATA <file to be streamed> [timeout] [max digits] Which actually is wrong. It should be: GET DATA <file to be streamed> [timeout [max digits]] > Using 1024 as maxDigits is the maximum number of digits GET DATA can > handle anyway as the buffer that is used by asterisk is defined as > char data[1024]. Although asterisk does not enforce a maximum of 1024 > reading more digits would result in a buffer overflow. Actually, Asterisk does enforce the 1024 limit. |
From: Stefan R. <sr...@re...> - 2005-05-08 12:42:36
|
> Um, just change return "GET DATA " + escapeAndQuote(file) + " " + > timeout + ... > to "GET DATA " + escapeAndQuote(file) + " " + (timeout != 0 ? > timeout : "") > and likewise for maxDigits. ok I changed it so that timeout and maxDigits are only included when needed. It seems kinda inconstent as timeout must be send if maxDigits is sent. so if timeout is not set setting maxDigits decides whether to sent a 0 for timeout or not. Thats where I adopted "Consistency is the hobgoblin of small minds" *g* =Stefan |