Skip to content

Commit 5e40c1a

Browse files
authored
Merge pull request #144 from kmatzen/fix/issue-94-sip-precheck
fix(#94): SIP pre-check before paid calls
2 parents 20f1192 + e9b7805 commit 5e40c1a

File tree

4 files changed

+58
-0
lines changed

4 files changed

+58
-0
lines changed

host/plugins/classic_phone.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,18 @@ static void classic_phone_check_and_call(void) {
323323

324324
static void classic_phone_start_call(void) {
325325
char log_msg[256];
326+
int sip_registered = 0;
327+
328+
/* #94: For paid calls, check SIP registration before attempting */
329+
if (!classic_phone_data.is_emergency_call && !classic_phone_data.is_card_call) {
330+
millennium_sdk_get_sip_status(&sip_registered, NULL, 0);
331+
if (sip_registered != 1) {
332+
display_manager_set_text("SIP unavailable", "Check connection");
333+
logger_warn_with_category("ClassicPhone", "Call refused - SIP not registered");
334+
return;
335+
}
336+
}
337+
326338
classic_phone_data.is_dialing = 1;
327339
strncpy(classic_phone_data.current_number, classic_phone_data.keypad_buffer, sizeof(classic_phone_data.current_number) - 1);
328340
classic_phone_data.current_number[sizeof(classic_phone_data.current_number) - 1] = '\0';

host/simulator.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ static void sim_parse_display(const char *message) {
9191
static int sim_call_pending = 0;
9292
static int sim_call_active = 0;
9393
static int sim_hangup_called = 0;
94+
static int sim_sip_registered = 1; /* 1=registered (default), 0=unavailable */
9495

9596
/* ── Millennium SDK stubs ──────────────────────────────────────────── */
9697

@@ -242,6 +243,13 @@ void millennium_client_write_to_display(millennium_client_t *c, const char *m) {
242243
(void)c; (void)m;
243244
}
244245

246+
/* SIP status stub: controlled by sip_registered scenario command (#94) */
247+
void millennium_sdk_get_sip_status(int *registered, char *last_error, size_t last_error_size) {
248+
if (registered) *registered = sim_sip_registered;
249+
if (last_error && last_error_size > 0) last_error[0] = '\0';
250+
(void)last_error_size;
251+
}
252+
245253
logger_level_t millennium_logger_parse_level(const char *s) { (void)s; return LOGGER_INFO; }
246254
void millennium_logger_set_level(logger_level_t l) { (void)l; }
247255
void millennium_logger_log(logger_level_t l, const char *m) { (void)l; (void)m; }
@@ -448,6 +456,8 @@ static int run_scenario(const char *path) {
448456
return 1;
449457
}
450458

459+
sim_sip_registered = 1; /* default: SIP registered for each scenario */
460+
451461
while (fgets(line, sizeof(line), f)) {
452462
line_num++;
453463
cmd = trim(line);
@@ -674,6 +684,14 @@ static int run_scenario(const char *path) {
674684
sim_drain_events();
675685
}
676686

687+
/* ── sip_registered <0|1> (#94) ──────────────────────────── */
688+
else if (strncmp(cmd, "sip_registered ", 15) == 0) {
689+
const char *p = cmd + 15;
690+
while (*p == ' ') p++;
691+
sim_sip_registered = (*p == '1') ? 1 : 0;
692+
fprintf(stderr, " sip_registered = %d\n", sim_sip_registered);
693+
}
694+
677695
/* ── config <key> <value> ──────────────────────────────── */
678696
else if (strncmp(cmd, "config ", 7) == 0) {
679697
char cfg_key[256];
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Test: #94 SIP pre-check — paid call refused when SIP not registered
2+
# sip_registered 0 simulates SIP unavailable
3+
4+
sip_registered 0
5+
hook_up
6+
assert_state IDLE_UP
7+
assert_display Insert 50c
8+
9+
# Insert coins and dial; call should be refused with "SIP unavailable"
10+
coin 25
11+
coin 25
12+
assert_display Have: 50c
13+
keys 5551234567
14+
assert_display SIP unavailable
15+
assert_display Check connection
16+
assert_state IDLE_UP
17+
18+
# Coins and number remain in plugin state; display shows error until next update
19+
20+
hook_down
21+
assert_state IDLE_DOWN

host/tests/unit_tests.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ void millennium_client_check_serial(millennium_client_t *c) { (void)c; }
4141
void millennium_client_serial_activity(millennium_client_t *c) { (void)c; }
4242
void list_audio_devices(void) {}
4343

44+
/* SIP status stub (classic_phone calls this for paid-call pre-check) */
45+
void millennium_sdk_get_sip_status(int *registered, char *last_error, size_t last_error_size) {
46+
if (registered) *registered = 1;
47+
if (last_error && last_error_size > 0) last_error[0] = '\0';
48+
(void)last_error_size;
49+
}
50+
4451
/* Audio tone stubs */
4552
void audio_tones_init(void) {}
4653
void audio_tones_cleanup(void) {}

0 commit comments

Comments
 (0)