diff --git a/modules/menu/menu.c b/modules/menu/menu.c index a28ad2e023..aebb0674c5 100644 --- a/modules/menu/menu.c +++ b/modules/menu/menu.c @@ -652,17 +652,19 @@ static void process_module_event(struct call *call, const char *prm) } -static void ua_event_handler(struct ua *ua, enum ua_event ev, - struct call *call, const char *prm, void *arg) +static void event_handler(enum ua_event ev, struct bevent *event, void *arg) { struct call *call2 = NULL; - struct account *acc = ua_account(ua); int32_t adelay = -1; bool incall; enum sdp_dir ardir, vrdir; uint32_t count; struct pl val; char * uri; + const char *prm = bevent_get_text(event); + struct call *call = bevent_get_call(event); + struct ua *ua = bevent_get_ua(event); + struct account *acc = ua_account(bevent_get_ua(event)); int err; (void)arg; @@ -1179,7 +1181,7 @@ static int module_init(void) if (err) return err; - err = uag_event_register(ua_event_handler, NULL); + err = bevent_register(event_handler, NULL); if (err) return err; @@ -1199,7 +1201,7 @@ static int module_close(void) message_unlisten(baresip_message(), message_handler); - uag_event_unregister(ua_event_handler); + bevent_unregister(event_handler); static_menu_unregister(); dial_menu_unregister(); dynamic_menu_unregister(); diff --git a/src/bevent.c b/src/bevent.c index 27b041b808..54e0208e9b 100644 --- a/src/bevent.c +++ b/src/bevent.c @@ -724,8 +724,8 @@ void ua_event(struct ua *ua, enum ua_event ev, struct call *call, warning("Used deprecated ua_event() for %s. " "Use one of event_xxx_emit() instead!\n", uag_event_str(ev)); - struct bevent event = {.ev = ev, .txt = buf}; + struct bevent event = {.ev = ev, .txt = buf}; if (bevent_class(ev) == BEVENT_CLASS_CALL) event.u.call = call; else if (bevent_class(ev) == BEVENT_CLASS_UA) @@ -781,7 +781,6 @@ void module_event(const char *module, const char *event, struct ua *ua, } struct bevent bevent = {.ev = UA_EVENT_MODULE, .txt = buf}; - if (call) bevent.u.call = call; diff --git a/src/call.c b/src/call.c index 77cee843c8..7a3e98a68e 100644 --- a/src/call.c +++ b/src/call.c @@ -313,8 +313,8 @@ static int update_media(struct call *call) { debug("call: update media\n"); - ua_event(call->ua, UA_EVENT_CALL_REMOTE_SDP, call, - call->got_offer ? "offer" : "answer"); + bevent_call_emit(UA_EVENT_CALL_REMOTE_SDP, call, + call->got_offer ? "offer" : "answer"); return call_update_media(call); } @@ -384,8 +384,8 @@ static void audio_level_handler(bool tx, double lvl, void *arg) struct call *call = arg; MAGIC_CHECK(call); - ua_event(call->ua, tx ? UA_EVENT_VU_TX : UA_EVENT_VU_RX, - call, "%.2f", lvl); + bevent_call_emit(tx ? UA_EVENT_VU_TX : UA_EVENT_VU_RX, call, + "%.2f", lvl); } @@ -397,14 +397,15 @@ static void audio_error_handler(int err, const char *str, void *arg) if (err) { warning("call: audio device error: %m (%s)\n", err, str); - ua_event(call->ua, UA_EVENT_AUDIO_ERROR, call, "%d,%s", - err, str); + bevent_call_emit(UA_EVENT_AUDIO_ERROR, call, + "%d,%s", err, str); + call_stream_stop(call); call_event_handler(call, CALL_EVENT_CLOSED, "%s", str); } else - ua_event(call->ua, UA_EVENT_END_OF_FILE, call, ""); + bevent_call_emit(UA_EVENT_END_OF_FILE, call, ""); } @@ -525,8 +526,8 @@ static void stream_rtpestab_handler(struct stream *strm, void *arg) struct call *call = arg; MAGIC_CHECK(call); - ua_event(call->ua, UA_EVENT_CALL_RTPESTAB, call, - "%s", sdp_media_name(stream_sdpmedia(strm))); + bevent_call_emit(UA_EVENT_CALL_RTPESTAB, call, + "%s", sdp_media_name(stream_sdpmedia(strm))); } @@ -543,13 +544,13 @@ static void stream_rtcp_handler(struct stream *strm, if (call->config_avt.rtp_stats) call_set_xrtpstat(call); - ua_event(call->ua, UA_EVENT_CALL_RTCP, call, - "%s", sdp_media_name(stream_sdpmedia(strm))); + bevent_call_emit(UA_EVENT_CALL_RTCP, call, + "%s", sdp_media_name(stream_sdpmedia(strm))); break; case RTCP_APP: - ua_event(call->ua, UA_EVENT_CALL_RTCP, call, - "%s", sdp_media_name(stream_sdpmedia(strm))); + bevent_call_emit(UA_EVENT_CALL_RTCP, call, + "%s", sdp_media_name(stream_sdpmedia(strm))); break; } } @@ -1092,8 +1093,8 @@ int call_modify(struct call *call) if (call_refresh_allowed(call)) { err = call_sdp_get(call, &desc, true); if (!err) { - ua_event(call->ua, UA_EVENT_CALL_LOCAL_SDP, call, - "offer"); + bevent_call_emit(UA_EVENT_CALL_LOCAL_SDP, call, + "offer"); err = sipsess_modify(call->sess, desc); if (err) @@ -1226,7 +1227,7 @@ int call_progress_dir(struct call *call, enum sdp_dir adir, enum sdp_dir vdir) goto out; if (call->got_offer) { - ua_event(call->ua, UA_EVENT_CALL_LOCAL_SDP, call, "answer"); + bevent_call_emit(UA_EVENT_CALL_LOCAL_SDP, call, "answer"); err = call_update_media(call); } @@ -1294,8 +1295,8 @@ int call_answer(struct call *call, uint16_t scode, enum vidmode vmode) if (call->got_offer) err = call_apply_sdp(call); - ua_event(call->ua, UA_EVENT_CALL_LOCAL_SDP, call, - "%s", !call->got_offer ? "offer" : "answer"); + bevent_call_emit(UA_EVENT_CALL_LOCAL_SDP, call, + "%s", !call->got_offer ? "offer" : "answer"); err = sdp_encode(&desc, call->sdp, !call->got_offer); if (err) @@ -1749,9 +1750,9 @@ static int sipsess_offer_handler(struct mbuf **descp, } if (aurx && !(sdp_media_dir(m) & SDP_SENDONLY)) - ua_event(call->ua, UA_EVENT_CALL_HOLD, call, ""); + bevent_call_emit(UA_EVENT_CALL_HOLD, call, ""); else if (!aurx && sdp_media_dir(m) & SDP_SENDONLY) - ua_event(call->ua, UA_EVENT_CALL_RESUME, call, ""); + bevent_call_emit(UA_EVENT_CALL_RESUME, call, ""); err = update_media(call); if (err) { @@ -2337,8 +2338,8 @@ static void redirect_handler(const struct sip_msg *msg, const char *uri, struct call *call = arg; info("call: redirect to %s\n", uri); - ua_event(call->ua, UA_EVENT_CALL_REDIRECT, call, - "%d,%s", msg->scode, uri); + bevent_call_emit(UA_EVENT_CALL_REDIRECT, call, + "%d,%s", msg->scode, uri); return; } @@ -2434,7 +2435,7 @@ static int send_invite(struct call *call) /* save call setup timer */ call->time_conn = time(NULL); - ua_event(call->ua, UA_EVENT_CALL_LOCAL_SDP, call, "offer"); + bevent_call_emit(UA_EVENT_CALL_LOCAL_SDP, call, "offer"); return 0; } diff --git a/src/reg.c b/src/reg.c index bb9eed6ad1..0b8784d086 100644 --- a/src/reg.c +++ b/src/reg.c @@ -119,7 +119,7 @@ static void register_handler(int err, const struct sip_msg *msg, void *arg) reg->scode = 999; - ua_event(reg->ua, evfail, NULL, "%m", err); + bevent_ua_emit(evfail, reg->ua, "%m", err); return; } @@ -162,8 +162,8 @@ static void register_handler(int err, const struct sip_msg *msg, void *arg) } } - ua_event(reg->ua, evok, NULL, "%u %r", - msg->scode, &msg->reason); + bevent_ua_emit(evok, reg->ua, + "%u %r", msg->scode, &msg->reason); } else if (msg->scode >= 300) { @@ -172,8 +172,8 @@ static void register_handler(int err, const struct sip_msg *msg, void *arg) reg->scode = msg->scode; - ua_event(reg->ua, evfail, NULL, "%u %r", - msg->scode, &msg->reason); + bevent_ua_emit(evfail, reg->ua, + "%u %r", msg->scode, &msg->reason); } } diff --git a/src/ua.c b/src/ua.c index c669dfd1cd..9e96cff7db 100644 --- a/src/ua.c +++ b/src/ua.c @@ -46,11 +46,12 @@ static void ua_destructor(void *arg) list_unlink(&ua->le); if (!list_isempty(&ua->regl)) - ua_event(ua, UA_EVENT_UNREGISTERING, NULL, NULL); + bevent_ua_emit(UA_EVENT_UNREGISTERING, ua, NULL); LIST_FOREACH(&ua->calls, le) { struct call *call = le->data; - ua_event(ua, UA_EVENT_CALL_CLOSED, call, "User-Agent deleted"); + bevent_call_emit(UA_EVENT_CALL_CLOSED, call, + "User-Agent deleted"); } list_flush(&ua->calls); @@ -219,7 +220,7 @@ static int start_register(struct ua *ua, bool fallback) create_register_clients(ua); if (!fallback && !list_isempty(&ua->regl)) - ua_event(ua, UA_EVENT_REGISTERING, NULL, NULL); + bevent_ua_emit(UA_EVENT_REGISTERING, ua, NULL); for (le = ua->regl.head, i=0; le; le = le->next, i++) { struct reg *reg = le->data; @@ -234,10 +235,10 @@ static int start_register(struct ua *ua, bool fallback) warning("ua: SIP%s register failed: %m\n", fallback ? " fallback" : "", err); - ua_event(ua, fallback ? - UA_EVENT_FALLBACK_FAIL : - UA_EVENT_REGISTER_FAIL, - NULL, "%m", err); + bevent_ua_emit(fallback ? + UA_EVENT_FALLBACK_FAIL : + UA_EVENT_REGISTER_FAIL, + ua, "%m", err); goto out; } } @@ -302,7 +303,7 @@ void ua_stop_register(struct ua *ua) return; if (!list_isempty(&ua->regl)) - ua_event(ua, UA_EVENT_UNREGISTERING, NULL, NULL); + bevent_ua_emit(UA_EVENT_UNREGISTERING, ua, NULL); for (le = ua->regl.head; le; le = le->next) { struct reg *reg = le->data; @@ -325,7 +326,7 @@ void ua_unregister(struct ua *ua) return; if (!list_isempty(&ua->regl)) - ua_event(ua, UA_EVENT_UNREGISTERING, NULL, NULL); + bevent_ua_emit(UA_EVENT_UNREGISTERING, ua, NULL); for (le = ua->regl.head; le; le = le->next) { struct reg *reg = le->data; @@ -425,7 +426,7 @@ unsigned ua_destroy(struct ua *ua) list_unlink(&ua->le); /* send the shutdown event */ - ua_event(ua, UA_EVENT_SHUTDOWN, NULL, NULL); + bevent_app_emit(UA_EVENT_SHUTDOWN, NULL, NULL); /* terminate all calls now */ list_flush(&ua->calls); @@ -524,12 +525,13 @@ static void call_event_handler(struct call *call, enum call_event ev, info("ua: blocked access: \"%s\"\n", peeruri); - ua_event(ua, UA_EVENT_CALL_CLOSED, call, "%s", str); + bevent_call_emit(UA_EVENT_CALL_CLOSED, call, + "%s", str); mem_deref(call); break; } - ua_event(ua, UA_EVENT_CALL_INCOMING, call, "%s", peeruri); + bevent_call_emit(UA_EVENT_CALL_INCOMING, call, "%s", peeruri); switch (ua->acc->answermode) { case ANSWERMODE_EARLY: @@ -553,43 +555,45 @@ static void call_event_handler(struct call *call, enum call_event ev, break; case CALL_EVENT_RINGING: - ua_event(ua, UA_EVENT_CALL_RINGING, call, "%s", peeruri); + bevent_call_emit(UA_EVENT_CALL_RINGING, call, "%s", peeruri); break; case CALL_EVENT_OUTGOING: - ua_event(ua, UA_EVENT_CALL_OUTGOING, call, "%s", peeruri); + bevent_call_emit(UA_EVENT_CALL_OUTGOING, call, "%s", peeruri); break; case CALL_EVENT_PROGRESS: ua_printf(ua, "Call in-progress: %s\n", peeruri); - ua_event(ua, UA_EVENT_CALL_PROGRESS, call, "%s", peeruri); + bevent_call_emit(UA_EVENT_CALL_PROGRESS, call, "%s", peeruri); break; case CALL_EVENT_ANSWERED: ua_printf(ua, "Call answered: %s\n", peeruri); - ua_event(ua, UA_EVENT_CALL_ANSWERED, call, "%s", peeruri); + bevent_call_emit(UA_EVENT_CALL_ANSWERED, call, "%s", peeruri); break; case CALL_EVENT_ESTABLISHED: ua_printf(ua, "Call established: %s\n", peeruri); - ua_event(ua, UA_EVENT_CALL_ESTABLISHED, call, "%s", peeruri); + bevent_call_emit(UA_EVENT_CALL_ESTABLISHED, call, + "%s", peeruri); break; case CALL_EVENT_CLOSED: - ua_event(ua, UA_EVENT_CALL_CLOSED, call, "%s", str); + bevent_call_emit(UA_EVENT_CALL_CLOSED, call, "%s", str); mem_deref(call); break; case CALL_EVENT_TRANSFER: - ua_event(ua, UA_EVENT_CALL_TRANSFER, call, "%s", str); + bevent_call_emit(UA_EVENT_CALL_TRANSFER, call, "%s", str); break; case CALL_EVENT_TRANSFER_FAILED: - ua_event(ua, UA_EVENT_CALL_TRANSFER_FAILED, call, "%s", str); + bevent_call_emit(UA_EVENT_CALL_TRANSFER_FAILED, call, + "%s", str); break; case CALL_EVENT_MENC: - ua_event(ua, UA_EVENT_CALL_MENC, call, "%s", str); + bevent_call_emit(UA_EVENT_CALL_MENC, call, "%s", str); break; } } @@ -607,10 +611,11 @@ static void call_dtmf_handler(struct call *call, char key, void *arg) key_str[0] = key; key_str[1] = '\0'; - ua_event(ua, UA_EVENT_CALL_DTMF_START, call, "%s", key_str); + bevent_call_emit(UA_EVENT_CALL_DTMF_START, call, + "%s", key_str); } else { - ua_event(ua, UA_EVENT_CALL_DTMF_END, call, NULL); + bevent_call_emit(UA_EVENT_CALL_DTMF_END, call, NULL); } } @@ -720,12 +725,6 @@ void sipsess_conn_handler(const struct sip_msg *msg, void *arg) return; } - if (uag_dnd()) { - (void)sip_treply(NULL, uag_sip(), msg, - 480,"Temporarily Unavailable"); - return; - } - /* handle multiple calls */ if (config->call.max_calls && uag_call_count() + 1 > config->call.max_calls) { @@ -766,6 +765,10 @@ void sipsess_conn_handler(const struct sip_msg *msg, void *arg) return; } + err = bevent_sip_msg_emit(UA_EVENT_SIPSESS_CONN, msg, ""); + if (err == ENOENT) + return; + (void)pl_strcpy(&msg->to.auri, to_uri, sizeof(to_uri)); err = ua_call_alloc(&call, ua, VIDMODE_ON, msg, NULL, to_uri, true); @@ -1100,7 +1103,7 @@ bool ua_handle_refer(struct ua *ua, const struct sip_msg *msg) } debug("ua: REFER to %r\n", &hdr->val); - ua_event(ua, UA_EVENT_REFER, NULL, "%r", &hdr->val); + bevent_ua_emit(UA_EVENT_REFER, ua, "%r", &hdr->val); out: @@ -1214,7 +1217,7 @@ int ua_alloc(struct ua **uap, const char *aor) goto out; list_append(uag_list(), &ua->le, ua); - ua_event(ua, UA_EVENT_CREATE, NULL, "%s", aor); + bevent_ua_emit(UA_EVENT_CREATE, ua, "%s", aor); out: mem_deref(host); @@ -1414,8 +1417,8 @@ void ua_hangup(struct ua *ua, struct call *call, call_hangup(call, scode, reason); - ua_event(ua, UA_EVENT_CALL_CLOSED, call, - reason ? reason : "Connection reset by user"); + bevent_call_emit(UA_EVENT_CALL_CLOSED, call, + reason ? reason : "Connection reset by user"); mem_deref(call); } diff --git a/src/uag.c b/src/uag.c index 43bd73e064..e2003e84a4 100644 --- a/src/uag.c +++ b/src/uag.c @@ -19,7 +19,7 @@ static void exit_handler(void *arg) { (void)arg; - ua_event(NULL, UA_EVENT_EXIT, NULL, NULL); + bevent_app_emit(UA_EVENT_EXIT, NULL, NULL); debug("ua: sip-stack exit\n"); @@ -734,9 +734,9 @@ int uag_reset_transp(bool reg, bool reinvite) if (!call_refresh_allowed(call)) { call_hangup(call, 500, "Transport of " "User Agent changed"); - ua_event(ua, UA_EVENT_CALL_CLOSED, - call, "Transport of " - "User Agent changed"); + bevent_call_emit(UA_EVENT_CALL_CLOSED, + call, "Transport of " + "User Agent changed"); mem_deref(call); continue; } diff --git a/test/call.c b/test/call.c index 3ba118ef57..869dd0fe48 100644 --- a/test/call.c +++ b/test/call.c @@ -146,7 +146,7 @@ struct fixture { f->a.peer = &f->b; \ f->b.peer = &f->a; \ \ - err = uag_event_register(event_handler, f); \ + err = bevent_register(event_handler, f); \ TEST_ERR(err); \ \ err = sip_transp_laddr(uag_sip(), &f->laddr_udp, \ @@ -187,7 +187,7 @@ struct fixture { \ module_unload("g711"); \ \ - uag_event_unregister(event_handler); \ + bevent_unregister(event_handler); \ \ ua_stop_all(true); \ ua_close(); \ @@ -433,7 +433,7 @@ static void check_ack(void *arg) ag->gotack = !call_ack_pending(ua_call(ag->ua)); if (ag->gotack) - ua_event(ag->ua, UA_EVENT_CUSTOM, ua_call(ag->ua), "gotack"); + bevent_ua_emit(UA_EVENT_CUSTOM, ag->ua, "gotack"); else tmr_start(&ag->tmr_ack, 1, check_ack, ag); @@ -607,16 +607,17 @@ static void process_rules(struct agent *ag, enum ua_event ev, const char *prm) } -static void event_handler(struct ua *ua, enum ua_event ev, - struct call *call, const char *prm, void *arg) +static void event_handler(enum ua_event ev, struct bevent *event, void *arg) { struct fixture *f = arg; struct call *call2 = NULL; struct agent *ag; struct stream *strm = NULL; char curi[256]; + const char *prm = bevent_get_text(event); + struct call *call = bevent_get_call(event); + struct ua *ua = bevent_get_ua(event); int err = 0; - (void)prm; #if 1 info("test: [ %s ] event: %s (%s)\n", @@ -877,6 +878,8 @@ static void event_handler(struct ua *ua, enum ua_event ev, warning("error in event-handler (%m)\n", err); fixture_abort(f, err); } + + return; } @@ -1286,8 +1289,7 @@ static void mock_vidisp_handler(const struct vidframe *frame, ++ag->n_vidframe; ua = ag->ua; - ua_event(ua, UA_EVENT_CUSTOM, ua_call(ua), "vidframe %u", - ag->n_vidframe); + bevent_ua_emit(UA_EVENT_CUSTOM, ua, "vidframe %u", ag->n_vidframe); out: if (err) @@ -1599,8 +1601,7 @@ static void auframe_handler(struct auframe *af, const char *dev, void *arg) ++ag->n_auframe; (void)audio_level_get(call_audio(ua_call(ua)), &ag->aulvl); - ua_event(ua, UA_EVENT_CUSTOM, ua_call(ua), "auframe %u", - ag->n_auframe); + bevent_ua_emit(UA_EVENT_CUSTOM, ua, "auframe %u", ag->n_auframe); out: if (err) @@ -2388,8 +2389,7 @@ static void delayed_audio_debug(void *arg) ++ag->n_audebug; - ua_event(ag->ua, UA_EVENT_CUSTOM, ua_call(ag->ua), "audebug %u", - ag->n_audebug); + bevent_ua_emit(UA_EVENT_CUSTOM, ag->ua, "audebug %u", ag->n_audebug); tmr_start(&ag->tmr, 2, delayed_audio_debug, ag); out: diff --git a/test/ua.c b/test/ua.c index 8d2aaacc32..ac27cf2ecc 100644 --- a/test/ua.c +++ b/test/ua.c @@ -55,11 +55,13 @@ static void test_abort(struct test *t, int err) } -static void ua_event_handler(struct ua *ua, enum ua_event ev, - struct call *call, const char *prm, void *arg) +static void event_handler(enum ua_event ev, struct bevent *event, void *arg) { struct test *t = arg; size_t i; + const char *prm = bevent_get_text(event); + struct call *call = bevent_get_call(event); + struct ua *ua = bevent_get_ua(event); int err = 0; const char referto[] = "sip:user@127.0.0.1"; (void)call; @@ -135,7 +137,7 @@ static int reg(enum sip_transp tp) err = ua_register(t.ua); TEST_ERR(err); - err = uag_event_register(ua_event_handler, &t); + err = bevent_register(event_handler, &t); if (err) goto out; @@ -155,7 +157,7 @@ static int reg(enum sip_transp tp) if (err) { warning("selftest: ua_register test failed (%m)\n", err); } - uag_event_unregister(ua_event_handler); + bevent_unregister(event_handler); test_reset(&t); return err; @@ -363,7 +365,7 @@ static int reg_dns(enum sip_transp tp) err = ua_register(t.ua); TEST_ERR(err); - err = uag_event_register(ua_event_handler, &t); + err = bevent_register(event_handler, &t); if (err) goto out; @@ -386,7 +388,7 @@ static int reg_dns(enum sip_transp tp) if (err) { warning("selftest: ua_register test failed (%m)\n", err); } - uag_event_unregister(ua_event_handler); + bevent_unregister(event_handler); test_reset(&t); @@ -469,7 +471,7 @@ static int reg_auth(enum sip_transp tp) err = ua_register(t.ua); TEST_ERR(err); - err = uag_event_register(ua_event_handler, &t); + err = bevent_register(event_handler, &t); if (err) goto out; @@ -491,7 +493,7 @@ static int reg_auth(enum sip_transp tp) if (err) { warning("selftest: ua_register test failed (%m)\n", err); } - uag_event_unregister(ua_event_handler); + bevent_unregister(event_handler); test_reset(&t); return err; @@ -640,7 +642,7 @@ static int reg_auth_dns(enum sip_transp tp) err = ua_register(t.ua); TEST_ERR(err); - err = uag_event_register(ua_event_handler, &t); + err = bevent_register(event_handler, &t); if (err) goto out; @@ -672,7 +674,7 @@ static int reg_auth_dns(enum sip_transp tp) if (err) { warning("selftest: ua_register test failed (%m)\n", err); } - uag_event_unregister(ua_event_handler); + bevent_unregister(event_handler); test_reset(&t); @@ -903,7 +905,7 @@ static int test_ua_refer_base(enum sip_transp transp) test_init(&t); - err = uag_event_register(ua_event_handler, &t); + err = bevent_register(event_handler, &t); TEST_ERR(err); err = ua_init("test", @@ -950,7 +952,7 @@ static int test_ua_refer_base(enum sip_transp transp) out: test_reset(&t); - uag_event_unregister(ua_event_handler); + bevent_unregister(event_handler); ua_stop_all(true); ua_close();