1
Vote

Possible bug when interacting with asterisk 1.6.1

description

I am running Asterisk 1.6.1.0 on Fedora 9 server.
If while playing a file (streamfile()) the party hangs up, you get an Argument Exception thrown from ParseResponse() in response to the noop that is sent to the switch.
Sequence:
you send the streamfile
file starts playing
party hangs up
streamfile returns (200 result="-1" offset="34839")
the library send noop to the switch
the switch responds (HANGUP200 result="-1"...)
the regexp in parse response fails to match this so an ArgumentException is thrown.
in my copy I updated the match string to match this and if HANGUP is detected, to throw a hangup excpetion
 
        Regex responseRegex = new Regex(@"^(?<HANGUP>HANGUP){0,1}(?<ResponseCode>\d{3})\sresult=(?<ResultCode>[^\s$]*)(?:\s\((?<ResultPayload>[^)]*)\)){0,1}(?:\sendpos=(?<EndPosition>\d*)){0,1}$", RegexOptions.Singleline);
        Match responseMatch = responseRegex.Match(responseString);
 
        if (responseMatch.Success)
        {
            FastAGIResponse fastAGIResponse = new FastAGIResponse();
 
            fastAGIResponse._rawResponse = responseString;
            fastAGIResponse._responseCode = int.Parse(responseMatch.Groups["ResponseCode"].Value);
            fastAGIResponse._resultValue = responseMatch.Groups["ResultCode"].Value;
 
            if (responseMatch.Groups["HANGUP"].Length != 0)
            {
                throw new HangUpException(string.Format("{0} EndPos={1}", "HANGUP", fastAGIResponse.EndPosition));
            }
 
 
I'm not sure if this is the right fix, but the current operation does not seem to be correct to me. you want to know the difference between some argument error and a hangup.
RecordFile seems to go out of it's way to do something very similar.

comments