res_pjsip: Remove ephemeral registered contacts on transport shutdown.
[asterisk/asterisk.git] / res / res_pjsip.c
index 0cf0343..ca0c301 100644 (file)
                                        <description>
                                                <para>Method used when updating connected line information.</para>
                                                <enumlist>
-                                                       <enum name="invite" />
+                                                       <enum name="invite">
+                                                       <para>When set to <literal>invite</literal>, check the remote's Allow header and
+                                                       if UPDATE is allowed, send UPDATE instead of INVITE to avoid SDP
+                                                       renegotiation.  If UPDATE is not Allowed, send INVITE.</para>
+                                                       </enum>
                                                        <enum name="reinvite">
                                                                <para>Alias for the <literal>invite</literal> value.</para>
                                                        </enum>
-                                                       <enum name="update" />
+                                                       <enum name="update">
+                                                       <para>If set to <literal>update</literal>, send UPDATE regardless of what the remote
+                                                       Allows. </para>
+                                                       </enum>
                                                </enumlist>
                                        </description>
                                </configOption>
                                <configOption name="rewrite_contact">
                                        <synopsis>Allow Contact header to be rewritten with the source IP address-port</synopsis>
                                        <description><para>
-                                               On inbound SIP messages from this endpoint, the Contact header or an appropriate Record-Route
-                                               header will be changed to have the source IP address and port. This option does not affect
-                                               outbound messages sent to this endpoint.
+                                               On inbound SIP messages from this endpoint, the Contact header or an
+                                               appropriate Record-Route header will be changed to have the source IP
+                                               address and port.  This option does not affect outbound messages sent to
+                                               this endpoint.  This option helps servers communicate with endpoints
+                                               that are behind NATs.  This option also helps reuse reliable transport
+                                               connections such as TCP and TLS.
                                        </para></description>
                                </configOption>
                                <configOption name="rtp_ipv6" default="no">
                                                streams allowed for the endpoint.
                                        </para></description>
                                </configOption>
+                               <configOption name="bundle" default="no">
+                                       <synopsis>Enable RTP bundling</synopsis>
+                                       <description><para>
+                                               With this option enabled, Asterisk will attempt to negotiate the use of bundle.
+                                               If negotiated this will result in multiple RTP streams being carried over the same
+                                               underlying transport. Note that enabling bundle will also enable the rtcp_mux option.
+                                       </para></description>
+                               </configOption>
+                               <configOption name="webrtc" default="no">
+                                       <synopsis>Defaults and enables some options that are relevant to WebRTC</synopsis>
+                                       <description><para>
+                                               When set to "yes" this also enables the following values that are needed in
+                                               order for basic WebRTC support to work: rtcp_mux, use_avpf, ice_support, and
+                                               use_received_transport. The following configuration settings also get defaulted
+                                               as follows:</para>
+                                               <para>media_encryption=dtls</para>
+                                               <para>dtls_verify=fingerprint</para>
+                                               <para>dtls_setup=actpass</para>
+                                       </description>
+                               </configOption>
                        </configObject>
                        <configObject name="auth">
                                <synopsis>Authentication type</synopsis>
                                                in incoming SIP REGISTER requests and is not intended to be configured manually.
                                        </para></description>
                                </configOption>
+                               <configOption name="prune_on_boot">
+                                       <synopsis>A contact that cannot survive a restart/boot.</synopsis>
+                                       <description><para>
+                                               The option is set if the incoming SIP REGISTER contact is rewritten
+                                               on a reliable transport and is not intended to be configured manually.
+                                       </para></description>
+                               </configOption>
                        </configObject>
                        <configObject name="aor">
                                <synopsis>The configuration for a location of an endpoint</synopsis>
@@ -3084,6 +3121,14 @@ pjsip_dialog *ast_sip_create_dialog_uac(const struct ast_sip_endpoint *endpoint,
        /* Update the dialog with the new local URI, we do it afterwards so we can use the dialog pool for construction */
        pj_strdup_with_null(dlg->pool, &dlg->local.info_str, &local_uri);
        dlg->local.info->uri = pjsip_parse_uri(dlg->pool, dlg->local.info_str.ptr, dlg->local.info_str.slen, 0);
+       if (!dlg->local.info->uri) {
+               ast_log(LOG_ERROR,
+                       "Could not parse URI '%s' for endpoint '%s'\n",
+                       dlg->local.info_str.ptr, ast_sorcery_object_get_id(endpoint));
+               dlg->sess_count--;
+               pjsip_dlg_terminate(dlg);
+               return NULL;
+       }
 
        dlg->local.contact = pjsip_parse_hdr(dlg->pool, &HCONTACT, local_uri.ptr, local_uri.slen, NULL);
 
@@ -4221,6 +4266,18 @@ void ast_copy_pj_str(char *dest, const pj_str_t *src, size_t size)
        dest[chars_to_copy] = '\0';
 }
 
+int ast_copy_pj_str2(char **dest, const pj_str_t *src)
+{
+       int res = ast_asprintf(dest, "%.*s", (int)pj_strlen(src), pj_strbuf(src));
+
+       if (res < 0) {
+               *dest = NULL;
+       }
+
+       return res;
+}
+
+
 int ast_sip_is_content_type(pjsip_media_type *content_type, char *type, char *subtype)
 {
        pjsip_media_type compare;
@@ -4436,6 +4493,56 @@ const char *ast_sip_get_host_ip_string(int af)
        return NULL;
 }
 
+int ast_sip_dtmf_to_str(const enum ast_sip_dtmf_mode dtmf,
+                       char *buf, size_t buf_len)
+{
+       switch (dtmf) {
+       case AST_SIP_DTMF_NONE:
+               ast_copy_string(buf, "none", buf_len);
+               break;
+       case AST_SIP_DTMF_RFC_4733:
+               ast_copy_string(buf, "rfc4733", buf_len);
+               break;
+       case AST_SIP_DTMF_INBAND:
+               ast_copy_string(buf, "inband", buf_len);
+               break;
+       case AST_SIP_DTMF_INFO:
+               ast_copy_string(buf, "info", buf_len);
+               break;
+       case AST_SIP_DTMF_AUTO:
+               ast_copy_string(buf, "auto", buf_len);
+               break;
+       case AST_SIP_DTMF_AUTO_INFO:
+               ast_copy_string(buf, "auto_info", buf_len);
+               break;
+       default:
+               buf[0] = '\0';
+               return -1;
+       }
+       return 0;
+}
+
+int ast_sip_str_to_dtmf(const char * dtmf_mode)
+{
+       int result = -1;
+
+       if (!strcasecmp(dtmf_mode, "info")) {
+               result = AST_SIP_DTMF_INFO;
+       } else if (!strcasecmp(dtmf_mode, "rfc4733")) {
+               result = AST_SIP_DTMF_RFC_4733;
+       } else if (!strcasecmp(dtmf_mode, "inband")) {
+               result = AST_SIP_DTMF_INBAND;
+       } else if (!strcasecmp(dtmf_mode, "none")) {
+               result = AST_SIP_DTMF_NONE;
+       } else if (!strcasecmp(dtmf_mode, "auto")) {
+               result = AST_SIP_DTMF_AUTO;
+       } else if (!strcasecmp(dtmf_mode, "auto_info")) {
+               result = AST_SIP_DTMF_AUTO_INFO;
+       }
+
+       return result;
+}
+
 /*!
  * \brief Set name and number information on an identity header.
  *
@@ -4565,6 +4672,7 @@ static int unload_pjsip(void *data)
                ast_sip_destroy_system();
                ast_sip_destroy_global_headers();
                internal_sip_unregister_service(&supplement_module);
+               ast_sip_destroy_transport_events();
        }
 
        if (monitor_thread) {
@@ -4643,7 +4751,6 @@ static int load_pjsip(void)
        return AST_MODULE_LOAD_SUCCESS;
 
 error:
-       unload_pjsip(NULL);
        return AST_MODULE_LOAD_DECLINE;
 }
 
@@ -4709,6 +4816,11 @@ static int load_module(void)
                goto error;
        }
 
+       if (ast_sip_initialize_transport_events()) {
+               ast_log(LOG_ERROR, "Failed to initialize SIP transport monitor. Aborting load\n");
+               goto error;
+       }
+
        ast_sip_initialize_dns();
 
        ast_sip_initialize_global_headers();