Skip to content

Commit e1737c5

Browse files
committed
app_coin: Add Class 5 coin wrapper application.
Add an application for Class 5 coin calls that is similar in function to what the ACTS application in app_acts does for Class 4 coin trunks. Also fix a couple remaining bugs in the ACTS application by fixing cases where result variable was set wrong and adding variable for easier summary usage. Resolves: #35
1 parent bab4354 commit e1737c5

File tree

5 files changed

+1584
-5
lines changed

5 files changed

+1584
-5
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ PhreakScript installs:
66
- Asterisk 21.2.0 (latest standard release[1] of Asterisk)
77
- DAHDI Linux 3.3.0 (with optional DAHDI install flag)
88
- DAHDI Tools 3.3.0 (with optional DAHDI install flag)
9+
- wanpipe 7.0.38 (with optional wanpipe install flag)
910
- many additional features and stability improvements
1011
- Restores the "great purge" of DAHDI drivers that were removed in 2018 by Sangoma
1112
- DAHDI/wanpipe/LibPRI compilation fixes
@@ -52,6 +53,8 @@ PhreakScript installs:
5253
- ``WaitForSignal``
5354
- ``WaitForDeposit``
5455
- ``CoinDisposition``
56+
- ``LocalCoinDisposition``
57+
- ``CoinCall``
5558
- ``ACTS``
5659
- ``SendCWCID``
5760
- ``DAHDIMonitor``

apps/app_acts.c

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,13 @@
126126
<variable name="ACTS_RESULT">
127127
<para>This is the result of the call.</para>
128128
<value name="CALLER_HANGUP">
129-
Caller hung up
129+
Call was answered and caller hung up
130+
</value>
131+
<value name="CALLER_ABORT">
132+
Caller hung up before call was answered
130133
</value>
131134
<value name="CALLEE_HANGUP">
132-
Callee hung up
135+
Call was answered and callee hung up
133136
</value>
134137
<value name="NOANSWER">
135138
Callee hung up without far end supervision
@@ -156,6 +159,16 @@
156159
Invalid arguments.
157160
</value>
158161
</variable>
162+
<variable name="ACTS_FINAL_DISPOSITION">
163+
<para>This indicates whether any coins in the hopper at call completition should be collected or returned.</para>
164+
<para>This is intended as a convenience variable - <literal>ACTS_RESULT</literal> provides more granularity.</para>
165+
<value name="COLLECT">
166+
Any coins in the hopper should be collected
167+
</value>
168+
<value name="RETURN">
169+
Any coins in the hopper should be returned
170+
</value>
171+
</variable>
159172
<variable name="ACTS_COLLECTED">
160173
<para>The total amount of money, in cents, collected into the coin vault for this call.</para>
161174
<para>This variable is only set if <literal>ACTS_RESULT</literal> is not <literal>INVALID</literal>.</para>
@@ -180,6 +193,8 @@
180193
</variablelist>
181194
</description>
182195
<see-also>
196+
<ref type="application">CoinCall</ref>
197+
<ref type="application">LocalCoinDisposition</ref>
183198
<ref type="application">CoinDisposition</ref>
184199
<ref type="application">WaitForDeposit</ref>
185200
<ref type="function">COIN_DETECT</ref>
@@ -230,6 +245,7 @@ struct acts_call {
230245
unsigned int postpaid:1; /* Collect overtime deposits after call */
231246
unsigned int postpaidended:1; /* Postpaid session ended */
232247
const char *result;
248+
const char *finaldisp;
233249
pthread_t opthread;
234250
ast_mutex_t lock;
235251
AST_RWLIST_ENTRY(acts_call) entry;
@@ -751,6 +767,7 @@ static int initial_deposit_helper(struct acts_call *acts, int required, int over
751767
ast_verb(4, "Insufficient deposit, disconnecting...\n");
752768
res = 1;
753769
acts->result = "INSUFFICIENT_INITIAL";
770+
acts->finaldisp = "RETURN";
754771
}
755772
}
756773

@@ -888,7 +905,6 @@ static void *async_signal_announcements(void *varg)
888905

889906
static int set_gains(struct acts_call *acts, int lopsided)
890907
{
891-
/* XXX Should probably get/ref the channel rather than using directly */
892908
ast_channel_lock(acts->ochan);
893909
ast_func_write(acts->ochan, "VOLUME(RX)", lopsided ? "-3" : "0");
894910
ast_channel_unlock(acts->ochan);
@@ -1079,6 +1095,7 @@ static int wait_for_answer(struct acts_call *acts)
10791095
DISCONNECT_FAR_END();
10801096
ast_verb(4, "Outgoing channel disconnected before answer\n");
10811097
acts->result = "NOANSWER";
1098+
acts->finaldisp = "RETURN";
10821099
return 1;
10831100
}
10841101
switch (f->frametype) {
@@ -1095,12 +1112,14 @@ static int wait_for_answer(struct acts_call *acts)
10951112
DISCONNECT_FAR_END();
10961113
res = 1;
10971114
acts->result = "BUSY";
1115+
acts->finaldisp = "RETURN";
10981116
break;
10991117
case AST_CONTROL_CONGESTION:
11001118
ast_verb(3, "%s is circuit-busy\n", ast_channel_name(acts->ochan));
11011119
DISCONNECT_FAR_END();
11021120
res = 1;
11031121
acts->result = "CONGESTION";
1122+
acts->finaldisp = "RETURN";
11041123
break;
11051124
case AST_CONTROL_PROGRESS:
11061125
case AST_CONTROL_PROCEEDING:
@@ -1158,8 +1177,9 @@ static int wait_for_answer(struct acts_call *acts)
11581177
struct ast_frame *f = ast_read(acts->chan);
11591178
if (!f || (f->frametype == AST_FRAME_CONTROL && f->subclass.integer == AST_CONTROL_HANGUP)) {
11601179
/* Caller cancelled call */
1161-
ast_verb(4, "Caller %s hung up\n", ast_channel_name(acts->chan));
1162-
acts->result = "CALLER_HANGUP";
1180+
ast_verb(4, "Caller %s hung up prior to answer\n", ast_channel_name(acts->chan));
1181+
acts->result = "CALLER_ABORT";
1182+
acts->finaldisp = "RETURN";
11631183
if (f) {
11641184
ast_frfree(f);
11651185
}
@@ -1803,6 +1823,7 @@ static int acts_run(struct acts_call *acts)
18031823
acts->callerdisconnected = 1;
18041824
ast_mutex_unlock(&acts->lock);
18051825
acts->result = "OVERTIME_EXPIRED";
1826+
acts->result = "RETURN"; /* Return deposit call is being cut off */
18061827

18071828
if (acts->hopper) {
18081829
res = coin_disposition(acts, COIN_RETURN);
@@ -1847,6 +1868,17 @@ static int acts_run(struct acts_call *acts)
18471868
}
18481869

18491870
cleanup:
1871+
if (!acts->finaldisp) {
1872+
/* Defaults, if not overridden.
1873+
* If time is up, then we already collected what we're owed,
1874+
* and more time hasn't been granted yet, so return any partial deposit.
1875+
* Otherwise, collect, before we release (or instruct the Class 5 office to). */
1876+
if (time(NULL) >= acts->expiretime) {
1877+
acts->finaldisp = "RETURN";
1878+
} else {
1879+
acts->finaldisp = "COLLECT";
1880+
}
1881+
}
18501882
ast_mutex_lock(&acts->lock);
18511883
if (framehook_id >= 0 && ast_framehook_detach(acts->chan, framehook_id)) {
18521884
ast_log(LOG_WARNING, "Failed to remove framehook from channel %s\n", ast_channel_name(acts->chan));
@@ -1906,6 +1938,7 @@ static int acts_run(struct acts_call *acts)
19061938
snprintf(buf, sizeof(buf), "%d", -acts->credit);
19071939
pbx_builtin_setvar_helper(acts->chan, "ACTS_OVERTIME_SHORTAGE_AMOUNT", buf);
19081940
acts->result = "OVERTIME_SHORTAGE";
1941+
acts->finaldisp = "COLLECT";
19091942
ast_verb(3, "Caller hung up without paying overtime shortage and will need to be rung back...\n");
19101943
}
19111944
}
@@ -2024,9 +2057,11 @@ static int acts_exec(struct ast_channel *chan, const char *data)
20242057

20252058
if (acts.result) {
20262059
pbx_builtin_setvar_helper(chan, "ACTS_RESULT", acts.result);
2060+
pbx_builtin_setvar_helper(chan, "ACTS_FINAL_DISPOSITION", acts.finaldisp);
20272061
} else {
20282062
ast_log(LOG_WARNING, "Missing internal result disposition... assuming failure\n");
20292063
pbx_builtin_setvar_helper(chan, "ACTS_RESULT", "FAILURE");
2064+
pbx_builtin_setvar_helper(chan, "ACTS_FINAL_DISPOSITION", "RETURN"); /* Fail safe to return, but this shouldn't happen */
20302065
}
20312066

20322067
if (res > 0) {

0 commit comments

Comments
 (0)