📄 nua_stack.c
字号:
NUTAG_SMIME_KEY_ENCRYPTION_REF(smime_key_encryption), NUTAG_SMIME_MESSAGE_ENCRYPTION_REF(smime_message_encryption), NUTAG_CERTIFICATE_DIR_REF(smime_path),#endif TAG_NULL()); if (n < 0) return UA_EVENT2(e, 400, "Error obtaining NUA parameters"), -1; *nhp = *ohp; NHP_UNSET_ALL(nhp);#if 0 reinit_contact = nua->nua_dhandle->nh_callee_caps != callee_caps || media_path != NONE || allow != NONE || allow_str != NONE;#endif if (invite_timeout > 0 && invite_timeout < 30) invite_timeout = 30; if (min_se > 0 && min_se < 30) min_se = 30; if (session_timer > 0) { if (session_timer < 30) session_timer = 30; if (session_timer < min_se) session_timer = min_se; } if (refresher >= nua_remote_refresher) refresher = nua_remote_refresher; else if (refresher <= nua_no_refresher) refresher = nua_no_refresher; /* Set int in handle pref structure */#define NHP_SET(nhp, pref, value) \ (((nhp)->nhp_set.set_bits.nhp_##pref = (value) != (nhp)->nhp_##pref), \ (nhp)->nhp_##pref = value) NHP_SET(nhp, retry_count, retry_count); NHP_SET(nhp, max_subscriptions, max_subscriptions); NHP_SET(nhp, invite_enable, invite_enable); NHP_SET(nhp, auto_alert, auto_alert != 0); NHP_SET(nhp, early_media, early_media != 0); NHP_SET(nhp, auto_answer, auto_answer != 0); NHP_SET(nhp, auto_ack, auto_ack != 0); NHP_SET(nhp, invite_timeout, invite_timeout); NHP_SET(nhp, session_timer, session_timer); NHP_SET(nhp, min_se, min_se); NHP_SET(nhp, refresher, refresher); NHP_SET(nhp, update_refresh, update_refresh != 0); NHP_SET(nhp, message_enable, message_enable); NHP_SET(nhp, win_messenger_enable, win_messenger_enable); NHP_SET(nhp, message_auto_respond, message_auto_respond); NHP_SET(nhp, media_features, media_features != 0); NHP_SET(nhp, callee_caps, callee_caps != 0); NHP_SET(nhp, service_route_enable, service_route_enable != 0); NHP_SET(nhp, path_enable, path_enable != 0); NHP_SET(nhp, substate, substate); /* Set string in handle pref structure */#define NHP_SET_STR(nhp, name, str) \ if (str != NONE && str0cmp(str, nhp->nhp_##name)) { \ char *new_str = su_strdup(tmphome, str); \ if (new_str != NULL || str == NULL) { \ NHP_SET(nhp, name, new_str); \ } \ else { \ n = -1; \ } \ } /* Set header in handle pref structure */#define NHP_SET_HEADER(nhp, name, header, str) \ if (header != NONE || str != NONE) { \ sip_##name##_t *new_header; \ if (header != NONE) \ new_header = sip_##name##_dup(tmphome, header); \ else \ new_header = sip_##name##_make(tmphome, str); \ if (new_header != NULL || (header == NULL || str == NULL)) { \ NHP_SET(nhp, name, new_header); \ } \ else { \ n = -1; \ } \ } /* Add contents of NUTAG_ALLOW() to list of currently allowed methods */ if (allow == NONE && allow_str == NONE && allowing != NULL) { sip_allow_t *methods = sip_allow_make(tmphome, allowing); if (methods) allow = sip_allow_dup(tmphome, NHP_GET(ohp, dnhp, allow)); if (allow == NULL) allow = NONE; if (allow != NONE) if (msg_params_join(tmphome, (msg_param_t **)&allow->k_items, methods->k_items, 1 /* prune */, 0 /* don't dup */) < 0) allow = NONE; } NHP_SET_HEADER(nhp, supported, supported, supported_str); NHP_SET_HEADER(nhp, allow, allow, allow_str); /* Add contents of NUTAG_USER_AGENT() to our distribution name */ if (ua_name != NONE && user_agent_str == NONE && user_agent == NONE) user_agent_str = ua_name ? su_sprintf(tmphome, "%s %s", ua_name, PACKAGE_NAME "/" PACKAGE_VERSION) : PACKAGE_NAME "/" PACKAGE_VERSION; NHP_SET_HEADER(nhp, user_agent, user_agent, user_agent_str); NHP_SET_STR(nhp, ua_name, ua_name); NHP_SET_HEADER(nhp, organization, organization, organization_str); if (n > 0 && NHP_IS_ANY_SET(nhp)) { /* Move allocations from tmphome to handle's home */ if (nh != dnh && nh->nh_prefs == dnh->nh_prefs) { /* We have made changes to handle-specific settings * but we don't have a prefs structure owned by handle yet */ nua_handle_preferences_t *ahp = su_alloc(nh->nh_home, sizeof *ahp); if (ahp && su_home_move(nh->nh_home, tmphome) >= 0) { memcpy(ahp, nhp, sizeof *ahp); /* Zap pointers which are not set */#define NHP_ZAP_UNSET_PTR(nhp, pref) \ (!(nhp)->nhp_set.set_bits.nhp_##pref ? (nhp)->nhp_##pref = NULL : NULL) NHP_ZAP_UNSET_PTR(ahp, supported); NHP_ZAP_UNSET_PTR(ahp, allow); NHP_ZAP_UNSET_PTR(ahp, user_agent); NHP_ZAP_UNSET_PTR(ahp, ua_name); NHP_ZAP_UNSET_PTR(ahp, organization); nh->nh_prefs = ahp; } else { n = -1; } } else if (su_home_move(nh->nh_home, tmphome) >= 0) { /* Update prefs structure */ nua_handle_preferences_t tbf[1]; nhp->nhp_set.set_any |= ohp->nhp_set.set_any; *tbf = *ohp; *ohp = *nhp; /* Free changed items */#define NHP_ZAP_OVERRIDEN(tbf, nhp, pref) \ ((tbf)->nhp_set.set_bits.nhp_##pref \ && (tbf)->nhp_##pref != (nhp)->nhp_##pref \ ? su_free(nh->nh_home, (void *)(tbf)->nhp_##pref) : (void)0) NHP_ZAP_OVERRIDEN(tbf, nhp, supported); NHP_ZAP_OVERRIDEN(tbf, nhp, allow); NHP_ZAP_OVERRIDEN(tbf, nhp, user_agent); NHP_ZAP_OVERRIDEN(tbf, nhp, ua_name); NHP_ZAP_OVERRIDEN(tbf, nhp, organization); } else /* Fail miserably with ENOMEM */ n = -1; } su_home_deinit(tmphome); if (n < 0) return UA_EVENT2(e, 500, "Error storing parameters"), -1; if (nh != dnh) return e == nua_r_set_params ? UA_EVENT2(e, 200, "OK") : 0; if (registrar != NONE) { if (registrar && (url_string_p(registrar) ? strcmp(registrar->us_str, "*") == 0 : registrar->us_url->url_type == url_any)) registrar = NULL; su_free(nua->nua_home, nua->nua_registrar); nua->nua_registrar = url_hdup(nua->nua_home, registrar->us_url); } if (from != NONE || from_str != NONE) { if (from == NONE) from = NULL; if (from_str == NONE) from_str = NULL; ua_set_from(nua, from, from_str); } ua_init_contact(nua);#if HAVE_SOFIA_SMIME /* XXX - all S/MIME other parameters? */ sm_set_params(nua->sm, smime_enable, smime_opt, smime_protection_mode, smime_path);#endif return e == nua_r_set_params ? UA_EVENT2(e, 200, "OK") : 0;}/**Send a list of NUA parameters to the application. * * This function gets invoked when application calls either nua_get_params() * or nua_get_hparams(). * * The parameter tag list will initially contain all the relevant parameter * tags, and it will be filtered down to parameters asked by application. * * The handle-specific parameters will contain only the parameters actually * modified by application, either by nua_set_hparams() or some other * handle-specific call. NTA parameters are returned only when application * asks for user-agent-level parameters using nua_get_params(). * */int nua_stack_get_params(nua_t *nua, nua_handle_t *nh, nua_event_t e, tagi_t const *tags){ nua_handle_t *dnh = nua->nua_dhandle; nua_handle_preferences_t const *nhp = nh->nh_prefs; tagi_t *lst; int has_from; sip_from_t from[1]; /* nta */ unsigned udp_mtu = 0, sip_t1 = 0, sip_t2 = 0, sip_t4 = 0, sip_t1x64 = 0; unsigned debug_drop_prob = 0; url_string_t const *proxy = NULL; sip_contact_t const *aliases = NULL; unsigned flags = 0; /* soa */ tagi_t *media_params = NULL; su_home_t tmphome[SU_HOME_AUTO_SIZE(16536)]; enter; su_home_auto(tmphome, sizeof(tmphome)); nta_agent_get_params(nua->nua_nta, NTATAG_UDP_MTU_REF(udp_mtu), NTATAG_SIP_T1_REF(sip_t1), NTATAG_SIP_T2_REF(sip_t2), NTATAG_SIP_T4_REF(sip_t4), NTATAG_SIP_T1X64_REF(sip_t1x64), NTATAG_DEBUG_DROP_PROB_REF(debug_drop_prob), NTATAG_DEFAULT_PROXY_REF(proxy), NTATAG_ALIASES_REF(aliases), NTATAG_SIPFLAGS_REF(flags), TAG_END()); if (nh->nh_ds->ds_local) has_from = 1, *from = *nh->nh_ds->ds_local, from->a_params = NULL; else has_from = 0; media_params = soa_get_paramlist(nh->nh_soa, TAG_END()); /* Include tag in list returned to user * if it has been earlier set (by user) */#define TIF(TAG, pref) \ TAG_IF(nhp->nhp_set.set_bits.nhp_##pref, TAG(nhp->nhp_##pref)) /* Include string tag made out of SIP header * if it has been earlier set (by user) */#define TIF_STR(TAG, pref) \ TAG_IF(nhp->nhp_set.set_bits.nhp_##pref, \ TAG(nhp->nhp_set.set_bits.nhp_##pref && nhp->nhp_##pref \ ? sip_header_as_string(tmphome, (void *)nhp->nhp_##pref) : NULL)) lst = tl_filtered_tlist (tmphome, tags, TAG_IF(has_from, SIPTAG_FROM(from)), TAG_IF(has_from, SIPTAG_FROM_STR(has_from ? sip_header_as_string(tmphome, (void *)from) : NULL)), TIF(NUTAG_RETRY_COUNT, retry_count), TIF(NUTAG_MAX_SUBSCRIPTIONS, max_subscriptions), TIF(NUTAG_ENABLEINVITE, invite_enable), TIF(NUTAG_AUTOALERT, auto_alert), TIF(NUTAG_EARLY_MEDIA, early_media), TIF(NUTAG_AUTOANSWER, auto_answer), TIF(NUTAG_AUTOACK, auto_ack), TIF(NUTAG_INVITE_TIMER, invite_timeout), TIF(NUTAG_SESSION_TIMER, session_timer), TIF(NUTAG_MIN_SE, min_se), TIF(NUTAG_SESSION_REFRESHER, refresher), TIF(NUTAG_UPDATE_REFRESH, update_refresh), TIF(NUTAG_ENABLEMESSAGE, message_enable), TIF(NUTAG_ENABLEMESSENGER, win_messenger_enable), /* TIF(NUTAG_MESSAGE_AUTOANSWER, message_auto_respond), */ TIF(NUTAG_CALLEE_CAPS, callee_caps), TIF(NUTAG_MEDIA_FEATURES, media_features), TIF(NUTAG_SERVICE_ROUTE_ENABLE, service_route_enable), TIF(NUTAG_PATH_ENABLE, path_enable), TIF(NUTAG_SUBSTATE, substate), TIF(SIPTAG_SUPPORTED, supported), TIF_STR(SIPTAG_SUPPORTED_STR, supported), TIF(SIPTAG_ALLOW, allow), TIF_STR(SIPTAG_ALLOW_STR, allow), TIF(SIPTAG_USER_AGENT, user_agent), TIF_STR(SIPTAG_USER_AGENT_STR, user_agent), TIF(NUTAG_USER_AGENT, ua_name), TIF(SIPTAG_ORGANIZATION, organization), TIF_STR(SIPTAG_ORGANIZATION_STR, organization), /* Skip user-agent-level parameters if parameters are for handle only */ TAG_IF(nh != dnh, TAG_NEXT(media_params)), NUTAG_MEDIA_ENABLE(nua->nua_media_enable), NUTAG_REGISTRAR(nua->nua_registrar), NTATAG_CONTACT(nua->nua_contact ? nua->nua_contact : nua->nua_sips_contact),#if HAVE_SOFIA_SMIME NUTAG_SMIME_ENABLE(nua->sm->sm_enable), NUTAG_SMIME_OPT(nua->sm->sm_opt), NUTAG_SMIME_PROTECTION_MODE(nua->sm->sm_protection_mode), NUTAG_SMIME_MESSAGE_DIGEST(nua->sm->sm_message_digest), NUTAG_SMIME_SIGNATURE(nua->sm->sm_signature), NUTAG_SMIME_KEY_ENCRYPTION(nua->sm->sm_key_encryption), NUTAG_SMIME_MESSAGE_ENCRYPTION(nua->sm->sm_message_encryption),#endif NTATAG_UDP_MTU(udp_mtu), NTATAG_SIP_T1(sip_t1), NTATAG_SIP_T2(sip_t2), NTATAG_SIP_T4(sip_t4), NTATAG_SIP_T1X64(sip_t1x64), NTATAG_DEBUG_DROP_PROB(debug_drop_prob), NTATAG_DEFAULT_PROXY(proxy), NTATAG_ALIASES(aliases), NTATAG_SIPFLAGS(flags), TAG_NEXT(media_params)); nua_stack_event(nua, nh, NULL, nua_r_get_params, SIP_200_OK, TAG_NEXT(lst)); su_home_deinit(tmphome); tl_vfree(media_params); return 0;}/* ---------------------------------------------------------------------- *//** Create a handle */nua_handle_t *nh_create(nua_t *nua, tag_type_t tag, tag_value_t value, ...){ ta_list ta; nua_handle_t *nh; enter; ta_start(ta, tag, value); nh = nh_create_handle(nua, NULL, ta_args(ta)); ta_end(ta); if (nh) { nh->nh_ref_by_stack = 1; nh_append(nua, nh); } return nh;}/** Append an handle to the list of handles */void nh_append(nua_t *nua, nua_handle_t *nh){ nh->nh_next = NULL; nh->nh_prev = nua->nua_handles_tail; *nua->nua_handles_tail = nh; nua->nua_handles_tail = &nh->nh_next;}nua_handle_t *nh_validate(nua_t *nua, nua_handle_t *maybe){ nua_handle_t *nh; if (maybe) for (nh = nua->nua_handles; nh; nh = nh->nh_next) if (nh == maybe) return nh; return NULL;}void nua_stack_destroy_handle(nua_t *nua, nua_handle_t *nh, tagi_t const *tags){ nh_call_pending(nh, 0); /* Call pending operations with 0 */ if (nh->nh_notifier) nua_stack_terminate(nua, nh, 0, NULL);#if 0 if (nh->nh_ref_by_user) { nh->nh_ref_by_user = 0; nua_handle_unref(nh); }#endif nh_destroy(nua, nh);}#define nh_is_inserted(nh) ((nh)->nh_prev != NULL)/** Remove a handle from list of handles */staticvoid nh_remove(nua_t *nua, nua_handle_t *nh){ assert(nh_is_inserted(nh)); assert(*nh->nh_prev == nh); if (nh->nh_next) nh->nh_next->nh_prev = nh->nh_prev; else nua->nua_handles_tail = nh->nh_prev; *nh->nh_prev = nh->nh_next; nh->nh_prev = NULL; nh->nh_next = NULL;}void nh_destroy(nua_t *nua, nua_handle_t *nh){ assert(nh); assert(nh != nua->nua_dhandle); nh_enter; if (nh->nh_notifier) nea_server_destroy(nh->nh_notifier), nh->nh_notifier = NULL; nua_creq_deinit(nh->nh_cr, NULL); if (nh->nh_ss) nua_creq_deinit(nh->nh_ss->ss_crequest, NULL); if (nh->nh_ds->ds_leg) { nta_leg_destroy(nh->nh_ds->ds_leg), nh->nh_ds->ds_leg = NULL; } if (nh->nh_ss->ss_srequest->sr_irq) { nta_incoming_destroy(nh->nh_ss->ss_srequest->sr_irq); nh->nh_ss->ss_srequest->sr_irq = NULL; } if (nh->nh_soa) soa_destroy(nh->nh_soa), nh->nh_soa = NULL; if (nh_is_inserted(nh)) nh_remove(nua, nh);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -