From 61a263046be86ddb10cde7685c0e3e4c0fe4ca03 Mon Sep 17 00:00:00 2001 From: Maximilian Fridrich Date: Wed, 18 Oct 2023 14:15:15 +0200 Subject: [PATCH] qualify: rename qual_freq to qual_int (interval) --- modules/qualify/qualify.c | 61 +++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 35 deletions(-) diff --git a/modules/qualify/qualify.c b/modules/qualify/qualify.c index 9fd0e5f..7e0ec1b 100644 --- a/modules/qualify/qualify.c +++ b/modules/qualify/qualify.c @@ -18,19 +18,19 @@ * reachable. * * Configure in address parameter `extra`: - * qual_freq [seconds] qualify frequency + * qual_int [seconds] qualify interval * qual_to [seconds] qualify timeout * * The OPTIONS are only sent if both options are present, both are not zero, - * qualify_freq is greater than qual_to, and the call is incoming. As soon as + * qual_int is greater than qual_to, and the call is incoming. As soon as * the call is established or closed, sending of OPTIONS is stopped. * If no response to an OPTIONS request is received within the specified - * timeout, UA_EVENT_CUSTOM with "Peer offline" is triggered. - * The sending of OPTIONS still continues and if a subsequent OPTIONS is - * answered, UA_EVENT_CUSTOM with "Peer online" is triggered. + * timeout, UA_EVENT_MODULE with "peer offline" is triggered. + * In this case, the sending of OPTIONS still continues and if a subsequent + * OPTIONS is answered, UA_EVENT_MODULE with "peer online" is triggered. * * Example: - * ;extra=qual_freq=5,qual_to=2 + * ;extra=qual_int=5,qual_to=2 * */ @@ -44,7 +44,7 @@ struct qualle { struct le he; struct call *call; bool offline; - struct tmr freq_tmr; + struct tmr int_tmr; struct tmr to_tmr; }; @@ -69,7 +69,7 @@ static void qualle_destructor(void *arg) hash_unlink(&qualle->he); tmr_cancel(&qualle->to_tmr); - tmr_cancel(&qualle->freq_tmr); + tmr_cancel(&qualle->int_tmr); } @@ -120,8 +120,8 @@ static void options_resp_handler(int err, const struct sip_msg *msg, void *arg) if (qualle->offline) { qualle->offline = false; - ua_event(call_get_ua(qualle->call), UA_EVENT_CUSTOM, - qualle->call, "Peer online"); + module_event("qualify", "peer online", + call_get_ua(qualle->call), qualle->call, ""); } } @@ -135,15 +135,15 @@ static void to_handler(void *arg) if (!qualle->offline) { qualle->offline = true; - ua_event(call_get_ua(call), UA_EVENT_CUSTOM, call, - "Peer offline"); + module_event("qualify", "peer offline", + call_get_ua(qualle->call), qualle->call, ""); } - info("No response recevied to OPTIONS in %u seconds.", qual_to); + info("No response received to OPTIONS in %u seconds.", qual_to); } -static void freq_handler(void *arg) +static void interval_handler(void *arg) { struct qualle *qualle = arg; (void)call_start_qualify(qualle->call, call_account(qualle->call), @@ -151,12 +151,6 @@ static void freq_handler(void *arg) } -/** - * Returns -1 if qual_freq or qual_to are zero - * -2 if qual_to is greater than or equal to qual_freq - * 0 on success - * else error code - */ static int call_start_qualify(struct call *call, const struct account *acc, struct qualle *qualle) @@ -165,20 +159,20 @@ static int call_start_qualify(struct call *call, struct sa peer_addr; char peer_uri[128]; uint32_t qual_to = 0; - uint32_t qual_freq = 0; + uint32_t qual_int = 0; int newle = qualle == NULL; - account_extra_uint(acc, "qual_freq", &qual_freq); + account_extra_uint(acc, "qual_int", &qual_int); account_extra_uint(acc, "qual_to", &qual_to); - if (!call || !qual_freq || !qual_to) { + if (!call || !qual_int || !qual_to) { return -1; } - if (qual_to >= qual_freq) { + if (qual_to >= qual_int) { warning("Will not send OPTIONS because qualify timeout is " - "greater than or equal to qualify frequency.\n" - "qual_to: %u, qual_freq: %u\n", qual_to, qual_freq); + "greater than or equal to qualify interval.\n" + "qual_to: %u, qual_int: %u\n", qual_to, qual_int); return -2; } @@ -189,7 +183,7 @@ static int call_start_qualify(struct call *call, qualle->call = call; tmr_init(&qualle->to_tmr); - tmr_init(&qualle->freq_tmr); + tmr_init(&qualle->int_tmr); hash_append(q.qual_map, hash_fast_str(account_aor(acc)), &qualle->he, qualle); } @@ -200,8 +194,8 @@ static int call_start_qualify(struct call *call, if (err == -1 || err == 0) { warning("Failed to get peer URI for sending OPTIONS ping. " - "Trying again in %u seconds.\n", err, qual_freq); - tmr_start(&qualle->freq_tmr, qual_freq * 1000, freq_handler, + "Trying again in %u seconds.\n", err, qual_int); + tmr_start(&qualle->int_tmr, qual_int * 1000, interval_handler, qualle); return err; } @@ -210,14 +204,14 @@ static int call_start_qualify(struct call *call, options_resp_handler, qualle); if (err) { warning("Sending OPTIONS failed with err %d. " - "Trying again in %u seconds.\n", err, qual_freq); - tmr_start(&qualle->freq_tmr, qual_freq * 1000, freq_handler, + "Trying again in %u seconds.\n", err, qual_int); + tmr_start(&qualle->int_tmr, qual_int * 1000, interval_handler, qualle); return err; } tmr_start(&qualle->to_tmr, qual_to * 1000, to_handler, qualle); - tmr_start(&qualle->freq_tmr, qual_freq * 1000, freq_handler, qualle); + tmr_start(&qualle->int_tmr, qual_int * 1000, interval_handler, qualle); return 0; } @@ -269,9 +263,6 @@ static void ua_event_handler(struct ua *ua, enum ua_event ev, case UA_EVENT_CALL_CLOSED: call_stop_qualify(acc); break; - case UA_EVENT_CUSTOM: - warning("UA_EVENT_CUSTOM. prm: %s\n", prm); - break; default: break; }