⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nua_params.c

📁 sip协议栈
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * This file is part of the Sofia-SIP package * * Copyright (C) 2006 Nokia Corporation. * * Contact: Pekka Pessi <pekka.pessi@nokia.com> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * *//**@CFILE nua_register.c * @brief REGISTER and registrations * * @author Pekka Pessi <Pekka.Pessi@nokia.com> * * @date Created: Wed Mar  8 11:48:49 EET 2006 ppessi */#include "config.h"#include <sofia-sip/string0.h>#include <sofia-sip/su_strlst.h>#include <sofia-sip/sha1.h>#include <sofia-sip/token64.h>#include <sofia-sip/su_tagarg.h>#include <sofia-sip/bnf.h>#include <sofia-sip/sip_protos.h>#include <sofia-sip/sip_util.h>#include <sofia-sip/sip_status.h>#include <sofia-sip/msg_parser.h>#include "nua_stack.h"#include <stddef.h>#include <stdlib.h>#include <string.h>#include <limits.h>#include <assert.h>/* ====================================================================== *//* Stack and handle parameters */static int nua_stack_set_smime_params(nua_t *nua, tagi_t const *tags);/** @internal Methods allowed by default. */static char const nua_allow_str[] ="INVITE, ACK, BYE, CANCEL, OPTIONS, PRACK, ""MESSAGE, SUBSCRIBE, NOTIFY, REFER, UPDATE";/** @internal Set default parameters */int nua_stack_set_defaults(nua_handle_t *nh, 			   nua_handle_preferences_t *nhp){  su_home_t *home = (su_home_t *)nh;  /* Set some defaults */  NHP_SET(nhp, retry_count, 3);  NHP_SET(nhp, max_subscriptions, 20);  NHP_SET(nhp, invite_enable, 1);  NHP_SET(nhp, auto_alert, 0);  NHP_SET(nhp, early_media, 0);  NHP_SET(nhp, auto_answer, 0);  NHP_SET(nhp, auto_ack, 1);  NHP_SET(nhp, invite_timeout, 120);  NHP_SET(nhp, session_timer, 1800);  NHP_SET(nhp, min_se, 120);  NHP_SET(nhp, refresher, nua_no_refresher);  NHP_SET(nhp, update_refresh, 0);  NHP_SET(nhp, message_enable, 1);  NHP_SET(nhp, win_messenger_enable, 0);  if (getenv("PIMIW_HACK") != 0)    NHP_SET(nhp, message_auto_respond, 1);  NHP_SET(nhp, media_features,  0);  NHP_SET(nhp, callee_caps, 0);  NHP_SET(nhp, service_route_enable, 1);  NHP_SET(nhp, path_enable, 1);  NHP_SET(nhp, refer_expires, 300);  NHP_SET(nhp, substate, nua_substate_active);  NHP_SET(nhp, allow, sip_allow_make(home, nua_allow_str));  NHP_SET(nhp, supported, sip_supported_make(home, "timer, 100rel"));  NHP_SET(nhp, user_agent,	   sip_user_agent_make(home, PACKAGE_NAME "/" PACKAGE_VERSION));  NHP_SET(nhp, outbound, su_strdup(home, "natify"));  NHP_SET(nhp, keepalive, 120000);  if (!nhp->nhp_allow ||      !nhp->nhp_supported ||      !nhp->nhp_user_agent ||      !nhp->nhp_outbound)    return -1;  return 0;}/** @internal Set the default from field */int nua_stack_set_from(nua_t *nua, int initial, tagi_t const *tags){  sip_from_t const *from = NONE;  char const *str = NONE;  sip_from_t *f = NULL,  f0[1];  char const *uicc_name = "default";  tl_gets(tags,	  /* By nua_stack_set_from() */	  SIPTAG_FROM_REF(from),	  SIPTAG_FROM_STR_REF(str),	  NUTAG_UICC_REF(uicc_name),	  TAG_END());#if HAVE_UICC_H  if (initial && uicc_name)    nua->nua_uicc = uicc_create(root, uicc_name);#endif  if (!initial && from == NONE && str == NONE)    return 0;  sip_from_init(f0);  if (from && from != NONE) {    f0->a_display = from->a_display;    *f0->a_url = *from->a_url;    f = sip_from_dup(nua->nua_home, f0);  }  else if (str && str != NONE) {    f = sip_from_make(nua->nua_home, str);    if (f)      *f0 = *f, f = f0, f->a_params = NULL;  }  else {    sip_contact_t const *m;    m = nua_stack_get_contact(nua->nua_registrations);        if (m) {      f0->a_display = m->m_display;      *f0->a_url = *m->m_url;      f = sip_from_dup(nua->nua_home, f0);    }  }  if (!f)    return -1;  *nua->nua_from = *f;  return 0;}/** @internal Initialize instance ID. */int nua_stack_init_instance(nua_handle_t *nh, tagi_t const *tags){  nua_handle_preferences_t *nhp = nh->nh_prefs;  char const *instance = NONE;  tl_gets(tags, NUTAG_INSTANCE_REF(instance), TAG_END());  if (instance != NONE) {    NHP_SET(nhp, instance, su_strdup(nh->nh_home, instance));    if (instance && !nhp->nhp_instance)      return -1;  }  return 0;}/**@fn void nua_set_params(nua_t *nua, tag_type_t tag, tag_value_t value, ...) * * Set NUA parameters. * * @param nua             Pointer to NUA stack object * @param tag, value, ... List of tagged parameters * * @return *     nothing * * @par Related tags: *   NUTAG_ALLOW() \n *   NUTAG_AUTOACK() \n *   NUTAG_AUTOALERT() \n *   NUTAG_AUTOANSWER() \n *   NUTAG_CALLEE_CAPS() \n *   NUTAG_CERTIFICATE_DIR() \n *   NUTAG_EARLY_MEDIA() \n *   NUTAG_ENABLEINVITE() \n *   NUTAG_ENABLEMESSAGE() \n *   NUTAG_ENABLEMESSENGER() \n *   NUTAG_INSTANCE() \n *   NUTAG_INVITE_TIMER() \n *   NUTAG_KEEPALIVE() \n *   NUTAG_KEEPALIVE_STREAM() \n *   NUTAG_MAX_SUBSCRIPTIONS() \n *   NUTAG_MEDIA_FEATURES() \n *   NUTAG_MIN_SE() \n *   NUTAG_OUTBOUND() \n *   NUTAG_PATH_ENABLE() \n *   NUTAG_REGISTRAR() \n *   NUTAG_SERVICE_ROUTE_ENABLE() \n *   NUTAG_SESSIONRESHER() \n *   NUTAG_SESSION_TIMER() \n *   NUTAG_SMIME_ENABLE() \n *   NUTAG_SMIME_KEY_ENCRYPTION() \n *   NUTAG_SMIME_MESSAGE_DIGEST() \n *   NUTAG_SMIME_MESSAGE_ENCRYPTION() \n *   NUTAG_SMIME_OPT() \n *   NUTAG_SMIME_PROTECTION_MODE() \n *   NUTAG_SMIME_SIGNATURE() \n *   NUTAG_SUBSTATE() \n *   NUTAG_UPDATERESH() \n *   NUTAG_USER_AGENT() \n *   SIPTAG_ALLOW() \n *   SIPTAG_ALLOW_STR() \n *   SIPTAG_FROM() \n *   SIPTAG_FROM_STR() \n *   SIPTAG_ORGANIZATION() \n *   SIPTAG_ORGANIZATION_STR() \n *   SIPTAG_SUPPORTED() \n *   SIPTAG_SUPPORTED_STR() \n *   SIPTAG_USER_AGENT() \n *   SIPTAG_USER_AGENT_STR() \n *   NUTAG_RETRY_COUNT() \n * * nua_set_params() also accepts any soa tags, defined in * <sofia-sip/soa_tag.h>, and nta tags, defined in <sofia-sip/nta_tag.h>. *  * @par Events: *     nua_r_set_params *//**@fn void nua_set_hparams(nua_handle_t *nh, tag_type_t tag, tag_value_t value, ...); * Set handle-specific parameters. * * @param nh              Pointer to a NUA handle * @param tag, value, ... List of tagged parameters * * @return *     nothing * * @par Related tags: *   NUTAG_ALLOW() \n *   NUTAG_AUTOACK() \n *   NUTAG_AUTOALERT() \n *   NUTAG_AUTOANSWER() \n *   NUTAG_CALLEE_CAPS() \n *   NUTAG_EARLY_MEDIA() \n *   NUTAG_ENABLEINVITE() \n *   NUTAG_ENABLEMESSAGE() \n *   NUTAG_ENABLEMESSENGER() \n *   NUTAG_INVITE_TIMER() \n *   NUTAG_KEEPALIVE() \n *   NUTAG_KEEPALIVE_STREAM() \n *   NUTAG_MAX_SUBSCRIPTIONS() \n *   NUTAG_MEDIA_FEATURES() \n *   NUTAG_MIN_SE() \n *   NUTAG_PATH_ENABLE() \n *   NUTAG_RETRY_COUNT() \n *   NUTAG_SERVICE_ROUTE_ENABLE() \n *   NUTAG_SESSIONRESHER() \n *   NUTAG_SESSION_TIMER() \n *   NUTAG_SUBSTATE() \n *   NUTAG_UPDATERESH() \n *   NUTAG_USER_AGENT() \n *   SIPTAG_ALLOW() \n *   SIPTAG_ALLOW_STR() \n *   SIPTAG_ORGANIZATION() \n *   SIPTAG_ORGANIZATION_STR() \n *   SIPTAG_SUPPORTED() \n *   SIPTAG_SUPPORTED_STR() \n *   SIPTAG_USER_AGENT() \n *   SIPTAG_USER_AGENT_STR() \n * * nua_set_hparams() also accepts any soa tags, defined in * <sofia-sip/soa_tag.h>. * * @par Events: *     none */int nua_stack_set_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 nhp[1], *ohp = nh->nh_prefs;  nua_handle_preferences_t const *dnhp = dnh->nh_prefs;  su_home_t tmphome[1] = { SU_HOME_INIT(tmphome) };  tagi_t const *t;  sip_allow_t const *allow = NONE;  char const   *allow_str = NONE;  char const   *allowing = NULL;  sip_supported_t const *supported = NONE;  char const *supported_str = NONE;  sip_user_agent_t const *user_agent = NONE;  char const *user_agent_str = NONE, *ua_name = NONE;  sip_organization_t const *organization = NONE;  char const *organization_str = NONE;  url_string_t const *registrar = NONE;  char const *instance = NONE;  char const *outbound = NONE;    int error = 0;  enter;  *nhp = *ohp; NHP_UNSET_ALL(nhp);  for (t = tags; t; t = tl_next(t)) {    if (t->t_tag == NULL)      break;    /* NUTAG_RETRY_COUNT(retry_count) */    else if (t->t_tag == nutag_retry_count) {      NHP_SET(nhp, retry_count, (unsigned)t->t_value);    }    /* NUTAG_MAX_SUBSCRIPTIONS(max_subscriptions) */    else if (t->t_tag == nutag_max_subscriptions) {      NHP_SET(nhp, max_subscriptions, (unsigned)t->t_value);    }    /* NUTAG_ENABLEINVITE(invite_enable) */    else if (t->t_tag == nutag_enableinvite) {      NHP_SET(nhp, invite_enable, t->t_value != 0);    }    /* NUTAG_AUTOALERT(auto_alert) */    else if (t->t_tag == nutag_autoalert) {      NHP_SET(nhp, auto_alert, t->t_value != 0);    }    /* NUTAG_EARLY_MEDIA(early_media) */    else if (t->t_tag == nutag_early_media) {      NHP_SET(nhp, early_media, t->t_value != 0);    }    /* NUTAG_AUTOANSWER(auto_answer) */    else if (t->t_tag == nutag_autoanswer) {      NHP_SET(nhp, auto_answer, t->t_value != 0);    }    /* NUTAG_AUTOACK(auto_ack) */    else if (t->t_tag == nutag_autoack) {      NHP_SET(nhp, auto_ack, t->t_value != 0);    }    /* NUTAG_INVITE_TIMER(invite_timeout) */    else if (t->t_tag == nutag_invite_timer) {      NHP_SET(nhp, invite_timeout, (unsigned)t->t_value);    }    /* NUTAG_SESSION_TIMER(session_timer) */    else if (t->t_tag == nutag_session_timer) {      NHP_SET(nhp, session_timer, (unsigned)t->t_value);    }    /* NUTAG_MIN_SE(min_se) */    else if (t->t_tag == nutag_min_se) {      NHP_SET(nhp, min_se, (unsigned)t->t_value);    }    /* NUTAG_SESSION_REFRESHER(refresher) */    else if (t->t_tag == nutag_session_refresher) {      NHP_SET(nhp, refresher, (int)t->t_value);    }    /* NUTAG_UPDATE_REFRESH(update_refresh) */    else if (t->t_tag == nutag_update_refresh) {      NHP_SET(nhp, update_refresh, t->t_value != 0);    }    /* NUTAG_ENABLEMESSAGE(message_enable) */    else if (t->t_tag == nutag_enablemessage) {      NHP_SET(nhp, message_enable, t->t_value != 0);    }    /* NUTAG_ENABLEMESSENGER(win_messenger_enable) */    else if (t->t_tag == nutag_enablemessenger) {      NHP_SET(nhp, win_messenger_enable, t->t_value != 0);    }#if 0    /* NUTAG_MESSAGE_AUTOANSWER(message_auto_respond) */    else if (t->t_tag == nutag_message_autoanwer) {      NHP_SET(nhp, message_auto_respond, t->t_value);    }#endif    /* NUTAG_CALLEE_CAPS(callee_caps) */    else if (t->t_tag == nutag_callee_caps) {      NHP_SET(nhp, callee_caps, t->t_value != 0);    }    /* NUTAG_MEDIA_FEATURES(media_features) */    else if (t->t_tag == nutag_media_features) {      NHP_SET(nhp, media_features, t->t_value != 0);    }    /* NUTAG_SERVICE_ROUTE_ENABLE(service_route_enable) */    else if (t->t_tag == nutag_service_route_enable) {      NHP_SET(nhp, service_route_enable, t->t_value != 0);    }    /* NUTAG_PATH_ENABLE(path_enable) */    else if (t->t_tag == nutag_path_enable != 0) {      NHP_SET(nhp, path_enable, t->t_value);    }    /* NUTAG_SUBSTATE(substate) */    else if (t->t_tag == nutag_substate) {      NHP_SET(nhp, substate, (int)t->t_value);    }    /* NUTAG_KEEPALIVE(keepalive) */    else if (t->t_tag == nutag_keepalive) {      NHP_SET(nhp, keepalive, (unsigned)t->t_value);    }    /* NUTAG_KEEPALIVE_STREAM(keepalive_stream) */    else if (t->t_tag == nutag_keepalive_stream) {      NHP_SET(nhp, keepalive_stream, (unsigned)t->t_value);    }    /* SIPTAG_SUPPORTED_REF(supported) */    else if (t->t_tag == siptag_supported) {      supported = (void *)t->t_value;    }    /* SIPTAG_SUPPORTED_STR_REF(supported_str) */    else if (t->t_tag == siptag_supported_str) {      supported_str = (void *)t->t_value;    }    /* SIPTAG_ALLOW_REF(allow) */    else if (t->t_tag == siptag_allow) {      allow = (void *)t->t_value;    }    /* SIPTAG_ALLOW_STR_REF(allow_str) */    else if (t->t_tag == siptag_allow_str) {      allow_str = (void *)t->t_value;    }    /* NUTAG_ALLOW_REF(allowing) */    else if (t->t_tag == nutag_allow) {      allowing = (void *)t->t_value;    }    /* SIPTAG_USER_AGENT_REF(user_agent) */    else if (t->t_tag == siptag_user_agent) {      user_agent = (void *)t->t_value;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -