Why is this system call in the dial plan sometimes not performed?

After a couple of days I gathered a dialplan I thought was working. Well, may be the weird handling of the variable __SendURL is avoidable. Nevertheless, I think that the system call System(/var/www/writedlr.php...) should performed anyway - no matter if the call fails, cancels or succeeds. However, there are some calls in my log that appear not to run the system call. How come?

The callfile initates a local call on fax_caller,faxout,1 and connects the remote end to fax_caller,faxsend,1

; Start
exten => faxout,1,NoOp(** Fax caller **)
same => n,Set(__SendDLR=1)
same => n,Dial(${ChannelPrefix}:${ReceiverPhoneNr}@${ChannelPostfix},,b(fax_outgoing_init^faxout^1(${SenderPhoneNr},${ChannelPostfix})))

; Sending fax
exten => faxsend,1,NoOp(** Sending fax **)
same => n,Set(__SendDLR=1)
same => n,SendFAX(/var/spool/asterisk/fax/${TIFF_FILE},dfs)
same => n,NoOp(** Fax status: ${FAXSTATUS})
same => n,GotoIf($[ "${FAXSTATUS}" = "SUCCESS" ]?lSuccess:lFailed)
same => n(lSuccess),NoOp(Success)
same => n,Set(status=OK)
same => n,Set(pages=${FAXPAGES})
same => n,Goto(lReady)
same => n(lFailed),NoOp(Failed)
same => n,Set(status=failed)
same => n,Set(pages=0)
same => n,Goto(lReady)
same => n(lReady),NoOp(** Ready **)
same => n,Gosub(dlrsend,1(${__SendDLR},${status},${pages},${DLR_URL}))

; Delivery notification
exten => dlrsend,1,NoOp(** Sending Delivery Notification: **)
same => n,Set(doDLR=${ARG1})
same => n,Set(status=${ARG2})
same => n,Set(pages=${ARG3})
same => n,Set(DLR_URL=${ARG4})
same => n,GotoIf($[ "${doDLR}" = "0" ]?lDLRready:)
same => n,System(/var/www/writedlr.php -u '${DLR_URL}' -s '${status}' -n '${pages}' -t '${STRFTIME(${EPOCH},,%Y-%m-%d %H:%M:%S)}')
same => n,Set(__SendDLR=0)
same => n(lDLRready),NoOp(** DLR ready **)
same => n,Return()

; Failed
exten => failed,1,NoOp(** Fax failed **)
same => n,Gosub(dlrsend,1(1,failed,0,${DLR_URL}))

exten => faxout,1,NoOp(** Fax, pre-dial hook **)
same => n,Set(PJSIP_HEADER(add,P-Preferred-Identity)="<sip:${ARG1}@${ARG2}>")
same => n,Return()

Because ARG1 is sometimes set to “0”.

@david551 Ok, but where from? There is only one point ARG1 can be set to 0, this is when having been called from failed first, then from faxsend. This however leads to the fact the failed invoked dlrsend with ARG1 set to 1 as constant value.

Oh, I just realised that this happens if the remote end is not a fax and the line is hung up during SendFax is executing. Obviosuly, this quits the extension. How can I handle this? E.g. ignore the exit status of SendFax?

Dialplan execution normally stops if the channel is hung up. You can use a hangup handler[1] to ensure logic is executed despite the hang up.

[1] https://wiki.asterisk.org/wiki/display/AST/Hangup+Handlers

1 Like

@jcolp I know there was a reason why I wanted to avoid the hangup extension. Ok, I have to prepare writedlr.php for being called twice every time.

@jcolp, Ok I prepared my callfile to set a unique Id which is then used in the database written by writedlr.php. However, I would find it nicer to have writedlr.php really called exactly once, no matter if

  • The destination number does not exist (local connection fails)
  • The destination number exists but is no fax (SendFax fails)
  • The fax goes through.
    Is the a way I can control this - e.g. by the variable __SendDLR - it seems that their value is not correctly passed among different extensions. Especially not to the hangup extension.