[asterisk-dev] AMI syntax
jg
webaccounts at jgoettgens.de
Sat Sep 28 16:47:22 CDT 2013
Matthew!
>
> Thanks! It does need a few tweaks still, which I'm going to try and get done next week.
>
> As an FYI, we removed the JabberEvent event in Asterisk 12 for two reasons:
> (1) It was spammy as all get out, and didn't convey a lot of useful information: knowing that
> you received a particular XMPP message over an AMI connection doesn't let you do anything with
> it, and if you really want that information outside of Asterisk, you should just relay the
> XMPP message to an XMPP server and deal with it there.
... but it is perfect to test a scanner.
> (2) It isn't really AMI's job to convey another protocol over itself. Doing so sets a rather
> bad precedent (and yes, it was set for a long time, but that doesn't mean we shouldn't correct it)
Yes, but a robust package must be able to deal with a lot of sh*t.
>
> So in 12, at least, the JabberEvent is not a culprit in having keys with no values.
In that case I might write my own module that bends the rules. :-) .
...
# use strong difference to exclude the trailing \r or \n from the matched string
line = [\-_0-9A-Za-z ]+ >KEY1 @KEY3 %KEY4 @err(key_err)
':' @SEP3 @err(sep_err)
white
( any* -- '\r' )? >VAL1 $VAL2 %VAL4 @err(val_err)
crlf+ @CNT %RESULT @err(term_err)
;
main := line*
('\0' @ZERO )
;
skip_line :=
[^\n]* >SKIP1 $SKIP2 %SKIP4
'\n' @{ fgoto main; }
;
#write data;
Just for the the hack of it, this is the core part of my AMI scanner. I am currently having fun
with Ragel scanning these messages. It looks a lot like flex, but it's not exactly the same. In
the background only pointers are set when things match (no runtime lib!) and evaluated when
needed. Works perfectly for cli and gui apps. I've omitted the src of the actions when things
match (but they are simple).
In case you want to allow (or somebody just did not follow the rules) white space in front of
the key this would change to:
...
# use strong difference to exclude the trailing \r or \n from the matched string
line = *white*
[\-_0-9A-Za-z ]+ >KEY1 @KEY3 %KEY4 @err(key_err)
':' @SEP3 @err(sep_err)
white
( any* -- '\r' )? >VAL1 $VAL2 %VAL4 @err(val_err)
crlf+ @CNT %RESULT @err(term_err)
;
main := line*
('\0' @ZERO )
;
skip_line :=
[^\n]* >SKIP1 $SKIP2 %SKIP4
'\n' @{ fgoto main; }
;
#write data;
... and no backtracking at all (if you care). Error messages are generated depending on what has
been matched recently.
jg
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-dev/attachments/20130928/0b7b489b/attachment.html>
More information about the asterisk-dev
mailing list