Clean up event handling #66

Merged
dyfet merged 1 commits from :event-cleanup into master 6 months ago
  1. 79
      drivers/generic/driver.cpp
  2. 79
      drivers/sipwitch/driver.cpp
  3. 8
      server/exosip.hpp

79
drivers/generic/driver.cpp

@ -115,46 +115,49 @@ void do_events(int priority)
break;
// breakdown events to dispatch handlers with minimal stack frames
auto request = event.request();
auto response = event.response();
auto status_code = response ? response->status_code : 409;
auto to = request ? request->to : nullptr;
auto to_local = to ? is_local(to->url) : false;
switch(event.type()) {
case EXOSIP_MESSAGE_NEW:
if(!request)
fail_message(event, SIP_BAD_REQUEST);
else if(!to_local)
fail_message(event, SIP_FORBIDDEN);
else if(MSG_IS_OPTIONS(request))
do_options(event);
else
fail_message(event, SIP_METHOD_NOT_ALLOWED);
break;
case EXOSIP_REGISTRATION_FAILURE:
if(active_rid != -1 && (status_code == SIP_UNAUTHORIZED || status_code == SIP_PROXY_AUTHENTICATION_REQUIRED)) {
debug(1, "send credentials");
if(is(event)) {
debug(5, "event: {}", event.text());
auto request = event.request();
auto response = event.response();
auto status_code = response ? response->status_code : 409;
auto to = request ? request->to : nullptr;
auto to_local = to ? is_local(to->url) : false;
switch(event.type()) {
case EXOSIP_MESSAGE_NEW:
if(!request)
fail_message(event, SIP_BAD_REQUEST);
else if(!to_local)
fail_message(event, SIP_FORBIDDEN);
else if(MSG_IS_OPTIONS(request))
do_options(event);
else
fail_message(event, SIP_METHOD_NOT_ALLOWED);
break;
case EXOSIP_REGISTRATION_FAILURE:
if(active_rid != -1 && (status_code == SIP_UNAUTHORIZED || status_code == SIP_PROXY_AUTHENTICATION_REQUIRED)) {
debug(1, "send credentials");
event.automatic();
}
else {
online = false;
log_warn("registration failed; code={}", status_code);
}
break;
case EXOSIP_REGISTRATION_SUCCESS:
if(active_rid == -1)
log_info("released registration");
else if(!online) {
online = true;
log_info("registered with server");
}
else
debug(1, "registration confirmed");
break;
default:
event.automatic();
}
else {
online = false;
log_warn("registration failed; code={}", status_code);
}
break;
case EXOSIP_REGISTRATION_SUCCESS:
if(active_rid == -1)
log_info("released registration");
else if(!online) {
online = true;
log_info("registered with server");
}
else
debug(1, "registration confirmed");
break;
default:
if(is(event)) // can get here from timeout, too...
event.automatic();
}
auto current = util::steady_clock();

79
drivers/sipwitch/driver.cpp

@ -115,46 +115,49 @@ void do_events(int priority)
break;
// breakdown events to dispatch handlers with minimal stack frames
auto request = event.request();
auto response = event.response();
auto status_code = response ? response->status_code : 409;
auto to = request ? request->to : nullptr;
auto to_local = to ? is_local(to->url) : false;
switch(event.type()) {
case EXOSIP_MESSAGE_NEW:
if(!request)
fail_message(event, SIP_BAD_REQUEST);
else if(!to_local)
fail_message(event, SIP_FORBIDDEN);
else if(MSG_IS_OPTIONS(request))
do_options(event);
else
fail_message(event, SIP_METHOD_NOT_ALLOWED);
break;
case EXOSIP_REGISTRATION_FAILURE:
if(active_rid != -1 && (status_code == SIP_UNAUTHORIZED || status_code == SIP_PROXY_AUTHENTICATION_REQUIRED)) {
debug(1, "send credentials");
if(is(event)) {
debug(5, "event: {}", event.text());
auto request = event.request();
auto response = event.response();
auto status_code = response ? response->status_code : 409;
auto to = request ? request->to : nullptr;
auto to_local = to ? is_local(to->url) : false;
switch(event.type()) {
case EXOSIP_MESSAGE_NEW:
if(!request)
fail_message(event, SIP_BAD_REQUEST);
else if(!to_local)
fail_message(event, SIP_FORBIDDEN);
else if(MSG_IS_OPTIONS(request))
do_options(event);
else
fail_message(event, SIP_METHOD_NOT_ALLOWED);
break;
case EXOSIP_REGISTRATION_FAILURE:
if(active_rid != -1 && (status_code == SIP_UNAUTHORIZED || status_code == SIP_PROXY_AUTHENTICATION_REQUIRED)) {
debug(1, "send credentials");
event.automatic();
}
else {
online = false;
log_warn("registration failed; code={}", status_code);
}
break;
case EXOSIP_REGISTRATION_SUCCESS:
if(active_rid == -1)
log_info("released registration");
else if(!online) {
online = true;
log_info("registered with server");
}
else
debug(1, "registration confirmed");
break;
default:
event.automatic();
}
else {
online = false;
log_warn("registration failed; code={}", status_code);
}
break;
case EXOSIP_REGISTRATION_SUCCESS:
if(active_rid == -1)
log_info("released registration");
else if(!online) {
online = true;
log_info("registered with server");
}
else
debug(1, "registration confirmed");
break;
default:
if(is(event)) // can get here from timeout, too...
event.automatic();
}
auto current = util::steady_clock();

8
server/exosip.hpp

@ -294,6 +294,10 @@ public:
return evt_ ? evt_->type : -1;
}
inline auto text() const {
return evt_ ? evt_->textinfo : "timeout";
}
inline auto request() const {
return evt_ ? evt_->request : nullptr;
}
@ -302,6 +306,10 @@ public:
return evt_ ? evt_->response : nullptr;
}
inline auto ack() const {
return evt_ ? evt_->ack : nullptr;
}
inline auto method() const {
return request() ? evt_->request->sip_method : "NONE";
}

Loading…
Cancel
Save