void DrachtioController::getTransactionSender( nta_incoming_t* irq, string& host, unsigned int& port ) { su_sockaddr_t su[1]; socklen_t sulen = sizeof su; msg_t* msg = nta_incoming_getrequest( irq ) ; if( 0 != msg_get_address(msg, su, &sulen) ) { throw std::runtime_error("Failed trying to retrieve socket associated with incoming sip message") ; } char h[256], s[256] ; su_getnameinfo(su, sulen, h, 256, s, 256, NI_NUMERICHOST | NI_NUMERICSERV); host = h ; port = ::atoi( s ) ; }
/* Callback from nea_server asking nua to authorize subscription */ static void authorize_watcher(nea_server_t *nes, nua_handle_t *nh, nea_event_t *ev, nea_subnode_t *sn, sip_t const *sip) { nua_t *nua = nh->nh_nua; msg_t *msg = NULL; nta_incoming_t *irq = NULL; int substate = sn->sn_state; int status; char const *phrase; SET_STATUS1(SIP_200_OK); /* OK. In nhp (nua_handle_preferences_t) structure we have the current default action (or state) for incoming subscriptions. Action can now be modified by the application with NUTAG_SUBSTATE(). */ irq = nea_sub_get_request(sn->sn_subscriber); msg = nta_incoming_getrequest(irq); if (sn->sn_state == nea_embryonic) { char const *what; substate = NH_PGET(nh, substate); if (substate == nua_substate_embryonic) substate = nua_substate_pending; if (substate == nua_substate_terminated) { what = "rejected"; SET_STATUS1(SIP_403_FORBIDDEN); } else if (substate == nua_substate_pending) { what = "pending"; SET_STATUS1(SIP_202_ACCEPTED); } else { what = "active"; } SU_DEBUG_7(("nua(%p): authorize_watcher: %s\n", (void *)nh, what)); nea_sub_auth(sn->sn_subscriber, (nea_state_t)substate, TAG_IF(substate == nua_substate_pending, NEATAG_FAKE(1)), TAG_IF(substate == nua_substate_terminated, NEATAG_REASON("rejected")), TAG_END()); } else if (sn->sn_state == nea_terminated || sn->sn_expires == 0) { substate = nua_substate_terminated; nea_server_flush(nes, NULL); SU_DEBUG_7(("nua(%p): authorize_watcher: %s\n", (void *)nh, "watcher is removed")); } nua_stack_tevent(nua, nh, msg, nua_i_subscription, status, phrase, NUTAG_SUBSTATE(substate), NEATAG_SUB(sn->sn_subscriber), TAG_END()); }