mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-12 15:45:18 +00:00
res_pjsip_messaging: send message to a default outbound endpoint
In some cases messages need to be sent to a direct URI (sip:<ip address>). This patch adds in that support by using a default outbound endpoint. When sending messages, if no endpoint can be found then the default one is used. To facilitate this a new default_outbound_endpoint option was added to the globals section for pjsip.conf. Review: https://reviewboard.asterisk.org/r/2944/ ........ Merged revisions 403680 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@403687 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -22,11 +22,13 @@
|
||||
#include <pjlib.h>
|
||||
|
||||
#include "asterisk/res_pjsip.h"
|
||||
#include "include/res_pjsip_private.h"
|
||||
#include "asterisk/sorcery.h"
|
||||
#include "asterisk/ast_version.h"
|
||||
|
||||
#define DEFAULT_MAX_FORWARDS 70
|
||||
#define DEFAULT_USERAGENT_PREFIX "Asterisk PBX"
|
||||
#define DEFAULT_OUTBOUND_ENDPOINT "default_outbound_endpoint"
|
||||
|
||||
static char default_useragent[128];
|
||||
|
||||
@@ -34,6 +36,7 @@ struct global_config {
|
||||
SORCERY_OBJECT(details);
|
||||
AST_DECLARE_STRING_FIELDS(
|
||||
AST_STRING_FIELD(useragent);
|
||||
AST_STRING_FIELD(default_outbound_endpoint);
|
||||
);
|
||||
/* Value to put in Max-Forwards header */
|
||||
unsigned int max_forwards;
|
||||
@@ -70,6 +73,30 @@ static int global_apply(const struct ast_sorcery *sorcery, void *obj)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct global_config *get_global_cfg(void)
|
||||
{
|
||||
RAII_VAR(struct ao2_container *, globals, ast_sorcery_retrieve_by_fields(
|
||||
ast_sip_get_sorcery(), "global", AST_RETRIEVE_FLAG_MULTIPLE,
|
||||
NULL), ao2_cleanup);
|
||||
|
||||
if (!globals) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return ao2_find(globals, NULL, 0);
|
||||
}
|
||||
|
||||
char *ast_sip_global_default_outbound_endpoint(void)
|
||||
{
|
||||
RAII_VAR(struct global_config *, cfg, get_global_cfg(), ao2_cleanup);
|
||||
|
||||
if (!cfg) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return ast_strdup(cfg->default_outbound_endpoint);
|
||||
}
|
||||
|
||||
int ast_sip_initialize_sorcery_global(struct ast_sorcery *sorcery)
|
||||
{
|
||||
snprintf(default_useragent, sizeof(default_useragent), "%s %s", DEFAULT_USERAGENT_PREFIX, ast_get_version());
|
||||
@@ -85,6 +112,8 @@ int ast_sip_initialize_sorcery_global(struct ast_sorcery *sorcery)
|
||||
OPT_UINT_T, 0, FLDSET(struct global_config, max_forwards));
|
||||
ast_sorcery_object_field_register(sorcery, "global", "user_agent", default_useragent,
|
||||
OPT_STRINGFIELD_T, 0, STRFLDSET(struct global_config, useragent));
|
||||
ast_sorcery_object_field_register(sorcery, "global", "default_outbound_endpoint", DEFAULT_OUTBOUND_ENDPOINT,
|
||||
OPT_STRINGFIELD_T, 0, STRFLDSET(struct global_config, default_outbound_endpoint));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@@ -105,4 +105,15 @@ int ast_sip_for_each_channel_snapshot(const struct ast_endpoint_snapshot *endpoi
|
||||
on_channel_snapshot_t on_channel_snapshot,
|
||||
void *arg);
|
||||
|
||||
/*!
|
||||
* \brief Retrieve the name of the default outbound endpoint.
|
||||
*
|
||||
* \note This returns a memory allocated copy of the name that
|
||||
* needs to be freed by the caller.
|
||||
*
|
||||
* \retval The name of the default outbound endpoint.
|
||||
* \retval NULL if configuration not found.
|
||||
*/
|
||||
char *ast_sip_global_default_outbound_endpoint(void);
|
||||
|
||||
#endif /* RES_PJSIP_PRIVATE_H_ */
|
||||
|
@@ -1528,6 +1528,13 @@ struct ao2_container *ast_sip_get_endpoints(void)
|
||||
return endpoints;
|
||||
}
|
||||
|
||||
struct ast_sip_endpoint *ast_sip_default_outbound_endpoint(void)
|
||||
{
|
||||
RAII_VAR(char *, name, ast_sip_global_default_outbound_endpoint(), ast_free);
|
||||
return ast_strlen_zero(name) ? NULL : ast_sorcery_retrieve_by_id(
|
||||
sip_sorcery, "endpoint", name);
|
||||
}
|
||||
|
||||
int ast_sip_retrieve_auths(const struct ast_sip_auth_vector *auths, struct ast_sip_auth **out)
|
||||
{
|
||||
int i;
|
||||
|
Reference in New Issue
Block a user