diff options
author | Mark Michelson <mmichelson@digium.com> | 2013-07-30 18:14:50 +0000 |
---|---|---|
committer | Mark Michelson <mmichelson@digium.com> | 2013-07-30 18:14:50 +0000 |
commit | 735b30ad71110c2a51404cb8686bbe3cf14b630c (patch) | |
tree | 76b1f10135c1b7f210e576be1359539de7e3476c /res/res_pjsip/config_global.c | |
parent | 895c8e0d2c97cd04299f3f179e99d8a3873c06c6 (diff) |
The large GULP->PJSIP renaming effort.
The general gist is to have a clear boundary between old SIP stuff
and new SIP stuff by having the word "SIP" for old stuff and "PJSIP"
for new stuff. Here's a brief rundown of the changes:
* The word "Gulp" in dialstrings, functions, and CLI commands is now
"PJSIP"
* chan_gulp.c is now chan_pjsip.c
* Function names in chan_gulp.c that were "gulp_*" are now "chan_pjsip_*"
* All files that were "res_sip*" are now "res_pjsip*"
* The "res_sip" directory is now "res_pjsip"
* Files in the "res_pjsip" directory that began with "sip_*" are now "pjsip_*"
* The configuration file is now "pjsip.conf" instead of "res_sip.conf"
* The module info for all PJSIP-related files now uses "PJSIP" instead of "SIP"
* CLI and AMI commands created by Asterisk's PJSIP modules now have "pjsip" as
the starting word instead of "sip"
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@395764 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'res/res_pjsip/config_global.c')
-rw-r--r-- | res/res_pjsip/config_global.c | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/res/res_pjsip/config_global.c b/res/res_pjsip/config_global.c new file mode 100644 index 000000000..2b2c021ee --- /dev/null +++ b/res/res_pjsip/config_global.c @@ -0,0 +1,90 @@ +/* + * Asterisk -- An open source telephony toolkit. + * + * Copyright (C) 2013, Digium, Inc. + * + * Mark Michelson <mmichelson@digium.com> + * + * See http://www.asterisk.org for more information about + * the Asterisk project. Please do not directly contact + * any of the maintainers of this project for assistance; + * the project provides a web site, mailing lists and IRC + * channels for your use. + * + * This program is free software, distributed under the terms of + * the GNU General Public License Version 2. See the LICENSE file + * at the top of the source tree. + */ + +#include "asterisk.h" + +#include <pjsip.h> +#include <pjlib.h> + +#include "asterisk/res_pjsip.h" +#include "asterisk/sorcery.h" +#include "asterisk/ast_version.h" + +#define DEFAULT_MAX_FORWARDS 70 +#define DEFAULT_USERAGENT_PREFIX "Asterisk PBX" + +static char default_useragent[128]; + +struct global_config { + SORCERY_OBJECT(details); + AST_DECLARE_STRING_FIELDS( + AST_STRING_FIELD(useragent); + ); + /* Value to put in Max-Forwards header */ + unsigned int max_forwards; +}; + +static void global_destructor(void *obj) +{ + struct global_config *cfg = obj; + + ast_string_field_free_memory(cfg); +} + +static void *global_alloc(const char *name) +{ + struct global_config *cfg = ast_sorcery_generic_alloc(sizeof(*cfg), global_destructor); + + if (!cfg || ast_string_field_init(cfg, 64)) { + return NULL; + } + + return cfg; +} + +static int global_apply(const struct ast_sorcery *sorcery, void *obj) +{ + struct global_config *cfg = obj; + char max_forwards[10]; + + snprintf(max_forwards, sizeof(max_forwards), "%u", cfg->max_forwards); + + ast_sip_add_global_request_header("Max-Forwards", max_forwards, 1); + ast_sip_add_global_request_header("User-Agent", cfg->useragent, 1); + ast_sip_add_global_response_header("Server", cfg->useragent, 1); + return 0; +} + +int ast_sip_initialize_sorcery_global(struct ast_sorcery *sorcery) +{ + snprintf(default_useragent, sizeof(default_useragent), "%s %s", DEFAULT_USERAGENT_PREFIX, ast_get_version()); + + ast_sorcery_apply_default(sorcery, "global", "config", "pjsip.conf,criteria=type=global"); + + if (ast_sorcery_object_register(sorcery, "global", global_alloc, NULL, global_apply)) { + return -1; + } + + ast_sorcery_object_field_register(sorcery, "global", "type", "", OPT_NOOP_T, 0, 0); + ast_sorcery_object_field_register(sorcery, "global", "maxforwards", __stringify(DEFAULT_MAX_FORWARDS), + OPT_UINT_T, 0, FLDSET(struct global_config, max_forwards)); + ast_sorcery_object_field_register(sorcery, "global", "useragent", default_useragent, + OPT_STRINGFIELD_T, 0, STRFLDSET(struct global_config, useragent)); + + return 0; +} |