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

Go to the source code of this file.

Macros

#define DOMAIN_NAME_LEN   255
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
static struct ast_sip_endpointanonymous_identify (pjsip_rx_data *rdata)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static int find_transport_state_in_use (void *obj, void *arg, int flags)
 
static int get_endpoint_details (pjsip_rx_data *rdata, char *domain, size_t domain_size)
 
static int load_module (void)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "PJSIP Anonymous endpoint identifier" , .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 = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .requires = "res_pjsip", }
 
static struct ast_sip_endpoint_identifier anonymous_identifier
 
static const struct ast_module_infoast_module_info = &__mod_info
 

Macro Definition Documentation

◆ DOMAIN_NAME_LEN

#define DOMAIN_NAME_LEN   255

Definition at line 58 of file res_pjsip_endpoint_identifier_anonymous.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 142 of file res_pjsip_endpoint_identifier_anonymous.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 142 of file res_pjsip_endpoint_identifier_anonymous.c.

◆ anonymous_identify()

static struct ast_sip_endpoint * anonymous_identify ( pjsip_rx_data *  rdata)
static

Definition at line 60 of file res_pjsip_endpoint_identifier_anonymous.c.

61{
62 char domain_name[DOMAIN_NAME_LEN + 1];
63 struct ast_sip_endpoint *endpoint;
64
65 if (get_endpoint_details(rdata, domain_name, sizeof(domain_name))) {
66 return NULL;
67 }
68
70 struct ast_sip_domain_alias *alias;
72 struct ast_sip_transport_state *transport_state = NULL;
73 struct ast_sip_transport *transport = NULL;
74 char id[sizeof("anonymous@") + DOMAIN_NAME_LEN];
75
76 /* Attempt to find the endpoint given the name and domain provided */
77 snprintf(id, sizeof(id), "anonymous@%s", domain_name);
78 endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", id);
79 if (endpoint) {
80 goto done;
81 }
82
83 /* See if an alias exists for the domain provided */
84 alias = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "domain_alias",
85 domain_name);
86 if (alias) {
87 snprintf(id, sizeof(id), "anonymous@%s", alias->domain);
88 ao2_ref(alias, -1);
89 endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", id);
90 if (endpoint) {
91 goto done;
92 }
93 }
94
95 /* See if the transport this came in on has a provided domain */
97 && (transport_state = ao2_callback(transport_states, 0, find_transport_state_in_use, rdata))
98 && (transport = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "transport", transport_state->id))
99 && !ast_strlen_zero(transport->domain)) {
100 snprintf(id, sizeof(id), "anonymous@%s", transport->domain);
101 endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", id);
102 }
103 ao2_cleanup(transport);
104 ao2_cleanup(transport_state);
106 if (endpoint) {
107 goto done;
108 }
109 }
110
111 /* Fall back to no domain */
112 endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", "anonymous");
113
114done:
115 if (endpoint) {
116 ast_debug(3, "Retrieved anonymous endpoint '%s'\n", ast_sorcery_object_get_id(endpoint));
117 }
118 return endpoint;
119}
#define ao2_callback(c, flags, cb_fn, arg)
ao2_callback() is a generic function that applies cb_fn() to all objects in a container,...
Definition: astobj2.h:1693
#define ao2_cleanup(obj)
Definition: astobj2.h:1934
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
static struct ao2_container * transport_states
#define ast_debug(level,...)
Log a DEBUG message.
struct ao2_container * ast_sip_get_transport_states(void)
Retrieves all transport states.
unsigned int ast_sip_get_disable_multi_domain(void)
Retrieve the system setting 'disable multi domain'.
struct ast_sorcery * ast_sip_get_sorcery(void)
Get a pointer to the SIP sorcery structure.
static int get_endpoint_details(pjsip_rx_data *rdata, char *domain, size_t domain_size)
static int find_transport_state_in_use(void *obj, void *arg, int flags)
#define NULL
Definition: resample.c:96
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
Definition: sorcery.c:2317
void * ast_sorcery_retrieve_by_id(const struct ast_sorcery *sorcery, const char *type, const char *id)
Retrieve an object using its unique identifier.
Definition: sorcery.c:1853
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
Generic container type.
const ast_string_field domain
Definition: res_pjsip.h:320
An entity with which Asterisk communicates.
Definition: res_pjsip.h:958
Structure for SIP transport information.
Definition: res_pjsip.h:116
Transport to bind to.
Definition: res_pjsip.h:218
const ast_string_field domain
Definition: res_pjsip.h:238
int done
Definition: test_amihooks.c:48

References ao2_callback, ao2_cleanup, ao2_ref, ast_debug, ast_sip_get_disable_multi_domain(), ast_sip_get_sorcery(), ast_sip_get_transport_states(), ast_sorcery_object_get_id(), ast_sorcery_retrieve_by_id(), ast_strlen_zero(), ast_sip_transport::domain, ast_sip_domain_alias::domain, DOMAIN_NAME_LEN, done, find_transport_state_in_use(), get_endpoint_details(), ast_sip_transport_state::id, NULL, and transport_states.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 142 of file res_pjsip_endpoint_identifier_anonymous.c.

◆ find_transport_state_in_use()

static int find_transport_state_in_use ( void *  obj,
void *  arg,
int  flags 
)
static

Definition at line 43 of file res_pjsip_endpoint_identifier_anonymous.c.

44{
45 struct ast_sip_transport_state *transport_state = obj;
46 pjsip_rx_data *rdata = arg;
47
48 if (transport_state->transport == rdata->tp_info.transport
49 || (transport_state->factory
50 && !pj_strcmp(&transport_state->factory->addr_name.host, &rdata->tp_info.transport->local_name.host)
51 && transport_state->factory->addr_name.port == rdata->tp_info.transport->local_name.port)) {
52 return CMP_MATCH;
53 }
54
55 return 0;
56}
@ CMP_MATCH
Definition: astobj2.h:1027
struct pjsip_tpfactory * factory
Transport factory.
Definition: res_pjsip.h:120
struct pjsip_transport * transport
Transport itself.
Definition: res_pjsip.h:118

References CMP_MATCH, ast_sip_transport_state::factory, and ast_sip_transport_state::transport.

Referenced by anonymous_identify().

◆ get_endpoint_details()

static int get_endpoint_details ( pjsip_rx_data *  rdata,
char *  domain,
size_t  domain_size 
)
static

Definition at line 33 of file res_pjsip_endpoint_identifier_anonymous.c.

34{
35 pjsip_uri *from = rdata->msg_info.from->uri;
36 if (!ast_sip_is_uri_sip_sips(from)) {
37 return -1;
38 }
39 ast_copy_pj_str(domain, ast_sip_pjsip_uri_get_hostname(from), domain_size);
40 return 0;
41}
int ast_sip_is_uri_sip_sips(pjsip_uri *uri)
Check whether a pjsip_uri is SIP/SIPS or not.
Definition: res_pjsip.c:3467
void ast_copy_pj_str(char *dest, const pj_str_t *src, size_t size)
Copy a pj_str_t into a standard character buffer.
Definition: res_pjsip.c:2201
const pj_str_t * ast_sip_pjsip_uri_get_hostname(pjsip_uri *uri)
Get the host portion of the pjsip_uri.
Definition: res_pjsip.c:3496

References ast_copy_pj_str(), ast_sip_is_uri_sip_sips(), and ast_sip_pjsip_uri_get_hostname().

Referenced by anonymous_identify().

◆ load_module()

static int load_module ( void  )
static

Definition at line 125 of file res_pjsip_endpoint_identifier_anonymous.c.

126{
129}
@ AST_MODULE_LOAD_SUCCESS
Definition: module.h:70
int ast_sip_register_endpoint_identifier_with_name(struct ast_sip_endpoint_identifier *identifier, const char *name)
Register a SIP endpoint identifier with a name.
Definition: res_pjsip.c:233
static struct ast_sip_endpoint_identifier anonymous_identifier

References anonymous_identifier, AST_MODULE_LOAD_SUCCESS, and ast_sip_register_endpoint_identifier_with_name().

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 131 of file res_pjsip_endpoint_identifier_anonymous.c.

132{
134 return 0;
135}
void ast_sip_unregister_endpoint_identifier(struct ast_sip_endpoint_identifier *identifier)
Unregister a SIP endpoint identifier.
Definition: res_pjsip.c:315

References anonymous_identifier, and ast_sip_unregister_endpoint_identifier().

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "PJSIP Anonymous endpoint identifier" , .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 = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .requires = "res_pjsip", }
static

Definition at line 142 of file res_pjsip_endpoint_identifier_anonymous.c.

◆ anonymous_identifier

struct ast_sip_endpoint_identifier anonymous_identifier
static
Initial value:
= {
.identify_endpoint = anonymous_identify,
}
static struct ast_sip_endpoint * anonymous_identify(pjsip_rx_data *rdata)

Definition at line 121 of file res_pjsip_endpoint_identifier_anonymous.c.

Referenced by load_module(), and unload_module().

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 142 of file res_pjsip_endpoint_identifier_anonymous.c.