Asterisk - The Open Source Telephony Project  18.5.0
Functions | Variables
res_pjsip_sips_contact.c File Reference
#include "asterisk.h"
#include <pjsip.h>
#include "asterisk/res_pjsip.h"
#include "asterisk/module.h"
Include dependency graph for res_pjsip_sips_contact.c:

Go to the source code of this file.

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static int load_module (void)
 
static pj_status_t sips_contact_on_tx_request (pjsip_tx_data *tdata)
 Upgrade Contact URIs on outgoing SIP requests to SIPS if required. More...
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "UAC SIPS Contact support" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "30ef0c93b36035ec78c9cfd712d36d9b" , .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_APP_DEPEND, .requires = "res_pjsip", }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static pjsip_module sips_contact_module
 

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 106 of file res_pjsip_sips_contact.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 106 of file res_pjsip_sips_contact.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 106 of file res_pjsip_sips_contact.c.

◆ load_module()

static int load_module ( void  )
static

Definition at line 91 of file res_pjsip_sips_contact.c.

References AST_MODFLAG_LOAD_ORDER, AST_MODPRI_APP_DEPEND, AST_MODULE_INFO(), AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, AST_MODULE_SUPPORT_CORE, ast_sip_register_service(), ASTERISK_GPL_KEY, sips_contact_module, and unload_module().

92 {
95  }
96 
98 }
int ast_sip_register_service(pjsip_module *module)
Register a SIP service in Asterisk.
Definition: res_pjsip.c:3315
static pjsip_module sips_contact_module
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78

◆ sips_contact_on_tx_request()

static pj_status_t sips_contact_on_tx_request ( pjsip_tx_data *  tdata)
static

Upgrade Contact URIs on outgoing SIP requests to SIPS if required.

The rules being used here are according to RFC 3261 section 8.1.1.8. In brief, if the request URI is SIPS or the topmost Route header is SIPS, then the Contact header we send must also be SIPS.

Definition at line 39 of file res_pjsip_sips_contact.c.

References ast_debug, and NULL.

40 {
41  pjsip_contact_hdr *contact;
42  pjsip_route_hdr *route;
43  pjsip_sip_uri *contact_uri;
44 
45  contact = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_CONTACT, NULL);
46  if (!contact) {
47  return PJ_SUCCESS;
48  }
49 
50  contact_uri = pjsip_uri_get_uri(contact->uri);
51  if (PJSIP_URI_SCHEME_IS_SIPS(contact_uri)) {
52  /* If the Contact header is already SIPS, then we don't need to do anything */
53  return PJ_SUCCESS;
54  }
55 
56  if (PJSIP_URI_SCHEME_IS_SIPS(tdata->msg->line.req.uri)) {
57  ast_debug(1, "Upgrading contact URI on outgoing SIP request to SIPS due to SIPS Request URI\n");
58  pjsip_sip_uri_set_secure(contact_uri, PJ_TRUE);
59  return PJ_SUCCESS;
60  }
61 
62  route = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_ROUTE, NULL);
63  if (!route) {
64  return PJ_SUCCESS;
65  }
66 
67  if (!PJSIP_URI_SCHEME_IS_SIPS(&route->name_addr)) {
68  return PJ_SUCCESS;
69  }
70 
71  /* Our Contact header is not a SIPS URI, but our topmost Route header is. */
72  ast_debug(1, "Upgrading contact URI on outgoing SIP request to SIPS due to SIPS Route header\n");
73  pjsip_sip_uri_set_secure(contact_uri, PJ_TRUE);
74 
75  return PJ_SUCCESS;
76 }
#define NULL
Definition: resample.c:96
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 85 of file res_pjsip_sips_contact.c.

References ast_sip_unregister_service(), and sips_contact_module.

Referenced by load_module().

86 {
88  return 0;
89 }
static pjsip_module sips_contact_module
void ast_sip_unregister_service(pjsip_module *module)
Definition: res_pjsip.c:3331

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "UAC SIPS Contact support" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "30ef0c93b36035ec78c9cfd712d36d9b" , .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_APP_DEPEND, .requires = "res_pjsip", }
static

Definition at line 106 of file res_pjsip_sips_contact.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 106 of file res_pjsip_sips_contact.c.

◆ sips_contact_module

pjsip_module sips_contact_module
static

Definition at line 78 of file res_pjsip_sips_contact.c.

Referenced by load_module(), and unload_module().