--- /tmp/app_fax.c 2007-10-28 21:57:28.000000000 +0300 +++ app_fax.c 2007-11-03 01:11:48.000000000 +0300 @@ -52,14 +52,22 @@ " 'a' -- makes the application behave as an answering machine\n" " The default behaviour is to behave as a calling machine.\n" " 'd' -- turn on debug output. This option may be specified multiple\n" -" times to increase verbosity.\n" -"Uses LOCALSTATIONID to identify itself to the remote end.\n" +" times (max 2) to increase verbosity.\n" +"\n" +"This application uses following variables:\n" +" LOCALSTATIONID to identify itself to the remote end.\n" " LOCALHEADERINFO to generate a header line on each page.\n" -"Sets REMOTESTATIONID to the receiver CSID.\n" -" FAXPAGES to the number of pages sent.\n" -" FAXBITRATE to the transmition rate.\n" -" FAXRESOLUTION to the resolution.\n" -"Returns -1 in case of eny error or user hang up.\n" +"\n" +"This application sets the following channel variables upon completion:\n" +" FAXSTATUS - status of operation:\n" +" SUCCESS | FAILED\n" +" FAXERROR - Error when FAILED\n" +" REMOTESTATIONID - CSID of the remote side.\n" +" FAXPAGES - number of pages sent.\n" +" FAXBITRATE - transmition rate.\n" +" FAXRESOLUTION - resolution.\n" +"\n" +"Returns -1 in case of user hang up or any channel error.\n" "Returns 0 on success.\n"; static char *app_rcvfax_name = "ReceiveFAX"; @@ -72,14 +80,22 @@ " 'c' -- makes the application behave as a calling machine\n" " The default behaviour is to behave as an answering machine.\n" " 'd' -- turn on debug output. This option may be specified multiple\n" -" times to increase verbosity.\n" -"Uses LOCALSTATIONID to identify itself to the remote end.\n" +" times (max 2) to increase verbosity.\n" +"\n" +"This application uses following variables:\n" +" LOCALSTATIONID to identify itself to the remote end.\n" " LOCALHEADERINFO to generate a header line on each page.\n" -"Sets REMOTESTATIONID to the receiver CSID.\n" -" FAXPAGES to the number of pages received.\n" -" FAXBITRATE to the transmition rate.\n" -" FAXRESOLUTION to the resolution.\n" -"Returns -1 in case of eny error or user hang up.\n" +"\n" +"This application sets the following channel variables upon completion:\n" +" FAXSTATUS - status of operation:\n" +" SUCCESS | FAILED\n" +" FAXERROR - Error when FAILED\n" +" REMOTESTATIONID - CSID of the remote side.\n" +" FAXPAGES - number of pages sent.\n" +" FAXBITRATE - transmition rate.\n" +" FAXRESOLUTION - resolution.\n" +"\n" +"Returns -1 in case of user hang up or any channel error.\n" "Returns 0 on success.\n"; #define MAX_BLOCK_SIZE 240 @@ -117,6 +133,8 @@ t30_get_local_ident(f, local_ident); t30_get_far_ident(f, far_ident); + pbx_builtin_setvar_helper(s->chan, "FAXSTATUS", "SUCCESS"); + pbx_builtin_setvar_helper(s->chan, "FAXERROR", NULL); pbx_builtin_setvar_helper(s->chan, "REMOTESTATIONID", far_ident); snprintf(buf, sizeof(buf), "%i", stat.pages_transferred); pbx_builtin_setvar_helper(s->chan, "FAXPAGES", buf); @@ -125,11 +143,11 @@ snprintf(buf, sizeof(buf), "%i", stat.bit_rate); pbx_builtin_setvar_helper(s->chan, "FAXBITRATE", buf); - ast_log(LOG_DEBUG, "Fax transmitted successfully.\n"); - ast_log(LOG_DEBUG, " Remote station ID: %s\n", far_ident); - ast_log(LOG_DEBUG, " Pages transferred: %i\n", stat.pages_transferred); - ast_log(LOG_DEBUG, " Image resolution: %i x %i\n", stat.x_resolution, stat.y_resolution); - ast_log(LOG_DEBUG, " Transfer Rate: %i\n", stat.bit_rate); + ast_debug(1, "Fax transmitted successfully.\n"); + ast_debug(1, " Remote station ID: %s\n", far_ident); + ast_debug(1, " Pages transferred: %i\n", stat.pages_transferred); + ast_debug(1, " Image resolution: %i x %i\n", stat.x_resolution, stat.y_resolution); + ast_debug(1, " Transfer Rate: %i\n", stat.bit_rate); manager_event(EVENT_FLAG_CALL, f->tx_file ? "FaxSent" : "FaxReceived", @@ -148,6 +166,10 @@ f->tx_file ? f->tx_file : f->rx_file); } else { s->finished = -1; + + /* FAXSTATUS is already set to FAILED */ + pbx_builtin_setvar_helper(s->chan, "FAXERROR", t30_completion_code_to_str(result)); + ast_log(LOG_WARNING, "Error sending fax - result (%d) %s.\n", result, t30_completion_code_to_str(result)); } } @@ -172,6 +194,14 @@ int last_state = 0; struct timeval now, start, state_change; + pbx_builtin_setvar_helper(s->chan, "FAXSTATUS", "FAILED"); + pbx_builtin_setvar_helper(s->chan, "FAXERROR", "Channel problems"); + + pbx_builtin_setvar_helper(s->chan, "REMOTESTATIONID", NULL); + pbx_builtin_setvar_helper(s->chan, "FAXPAGES", NULL); + pbx_builtin_setvar_helper(s->chan, "FAXRESOLUTION", NULL); + pbx_builtin_setvar_helper(s->chan, "FAXBITRATE", NULL); + if (s->chan->_state != AST_STATE_UP) { /* Shouldn't need this, but checking to see if channel is already answered * Theoretically asterisk should already have answered before running the app */ @@ -217,7 +247,13 @@ t30_set_supported_compressions(&s->fax.t30_state, T30_SUPPORT_T4_1D_COMPRESSION | T30_SUPPORT_T4_2D_COMPRESSION | T30_SUPPORT_T6_COMPRESSION); start = state_change = ast_tvnow(); - while (!s->finished && (res = ast_waitfor(s->chan, -1)) > -1) { + while (!s->finished) { + + if (ast_waitfor(s->chan, -1) < 0) { + res = -1; + break; + } + inf = ast_read(s->chan); if (inf == NULL) break; @@ -286,11 +322,10 @@ res = -1; } else if (s->finished < 0) { ast_log(LOG_WARNING, "Transmission error\n"); - res = -1; } else if (s->finished > 0) { - ast_log(LOG_DEBUG, "Transmission finished Ok\n"); + ast_debug(1, "Transmission finished Ok\n"); } else if (inf == NULL) { - ast_log(LOG_DEBUG, "Channel hangup\n"); + ast_debug(1, "Channel hangup\n"); res = -1; } @@ -340,7 +375,7 @@ /* The next few lines of code parse out the filename and header from the input string */ if (ast_strlen_zero(data)) { /* No data implies no filename or anything is present */ - ast_log(LOG_ERROR, "Txfax requires an argument (filename)\n"); + ast_log(LOG_ERROR, "SendFAX requires an argument (filename)\n"); return -1; } @@ -414,7 +449,7 @@ /* The next few lines of code parse out the filename and header from the input string */ if (ast_strlen_zero(data)) { /* No data implies no filename or anything is present */ - ast_log(LOG_ERROR, "Txfax requires an argument (filename)\n"); + ast_log(LOG_ERROR, "ReceiveFAX requires an argument (filename)\n"); return -1; }