diff options
Diffstat (limited to 'main')
-rw-r--r-- | main/Makefile | 8 | ||||
-rw-r--r-- | main/sdp_options.c | 120 | ||||
-rw-r--r-- | main/sdp_repr.c | 111 | ||||
-rw-r--r-- | main/sdp_translator.c | 99 |
4 files changed, 338 insertions, 0 deletions
diff --git a/main/Makefile b/main/Makefile index 4d1b2c41b..3c371c668 100644 --- a/main/Makefile +++ b/main/Makefile @@ -355,7 +355,11 @@ else # Darwin endif endif ifneq ($(LDCONFIG),) +ifneq ($(DESTDIR),) $(LDCONFIG) $(LDCONFIG_FLAGS) "$(DESTDIR)$(ASTLIBDIR)/" +else + $(LDCONFIG) +endif endif $(LN) -sf asterisk "$(DESTDIR)$(ASTSBINDIR)/rasterisk" @@ -373,7 +377,11 @@ ifneq ($(ASTPJ_LIB).$(ASTPJ_SO_VERSION),.) rm -f "$(DESTDIR)$(ASTLIBDIR)/$(ASTPJ_LIB)" endif ifneq ($(LDCONFIG),) +ifneq ($(DESTDIR),) $(LDCONFIG) $(LDCONFIG_FLAGS) "$(DESTDIR)$(ASTLIBDIR)/" +else + $(LDCONFIG) +endif endif clean:: diff --git a/main/sdp_options.c b/main/sdp_options.c new file mode 100644 index 000000000..e18dfa55a --- /dev/null +++ b/main/sdp_options.c @@ -0,0 +1,120 @@ +/* + * Asterisk -- An open source telephony toolkit. + * + * Copyright (C) 2017, 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 "asterisk/utils.h" +#include "asterisk/sdp_options.h" + +struct ast_sdp_options { + enum ast_sdp_options_ice ice; + int telephone_event; + enum ast_sdp_options_repr repr; + enum ast_sdp_options_encryption encryption; +}; + +#define DEFAULT_ICE AST_SDP_ICE_DISABLED +#define DEFAULT_TELEPHONE_EVENT 0 +#define DEFAULT_REPR AST_SDP_REPR_STRING +#define DEFAULT_ENCRYPTION AST_SDP_ENCRYPTION_DISABLED + +static void set_defaults(struct ast_sdp_options *options) +{ + options->ice = DEFAULT_ICE; + options->telephone_event = DEFAULT_TELEPHONE_EVENT; + options->repr = DEFAULT_REPR; + options->encryption = DEFAULT_ENCRYPTION; +} + +struct ast_sdp_options *ast_sdp_options_alloc(void) +{ + struct ast_sdp_options *options; + + options = ast_calloc(1, sizeof(*options)); + if (!options) { + return NULL; + } + set_defaults(options); + return options; +} + +void ast_sdp_options_free(struct ast_sdp_options *options) +{ + ast_free(options); +} + +int ast_sdp_options_set_ice(struct ast_sdp_options *options, enum ast_sdp_options_ice ice_setting) +{ + ast_assert(options != NULL); + + options->ice = ice_setting; + return 0; +} + +enum ast_sdp_options_ice ast_sdp_options_get_ice(const struct ast_sdp_options *options) +{ + ast_assert(options != NULL); + + return options->ice; +} + +int ast_sdp_options_set_telephone_event(struct ast_sdp_options *options, int telephone_event_enabled) +{ + ast_assert(options != NULL); + + options->telephone_event = telephone_event_enabled; + return 0; +} + +int ast_sdp_options_get_telephone_event(const struct ast_sdp_options *options) +{ + ast_assert(options != NULL); + + return options->telephone_event; +} + +int ast_sdp_options_set_repr(struct ast_sdp_options *options, enum ast_sdp_options_repr repr) +{ + ast_assert(options != NULL); + + options->repr = repr; + return 0; +} + +enum ast_sdp_options_repr ast_sdp_options_get_repr(const struct ast_sdp_options *options) +{ + ast_assert(options != NULL); + + return options->repr; +} + +int ast_sdp_options_set_encryption(struct ast_sdp_options *options, + enum ast_sdp_options_encryption encryption) +{ + ast_assert(options != NULL); + + options->encryption = encryption; + return 0; +} + +enum ast_sdp_options_encryption ast_sdp_options_get_encryption(const struct ast_sdp_options *options) +{ + ast_assert(options != NULL); + + return options->encryption; +} diff --git a/main/sdp_repr.c b/main/sdp_repr.c new file mode 100644 index 000000000..6df243b0e --- /dev/null +++ b/main/sdp_repr.c @@ -0,0 +1,111 @@ +/* + * Asterisk -- An open source telephony toolkit. + * + * Copyright (C) 2017, 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 "asterisk/sdp_priv.h" +#include "asterisk/utils.h" + +struct ast_sdp *ast_sdp_alloc(void) +{ + struct ast_sdp *new_sdp; + + new_sdp = ast_calloc(1, sizeof *new_sdp); + return new_sdp; +} + +static void free_o_line(struct ast_sdp *dead) +{ + ast_free(dead->o_line.user); + ast_free(dead->o_line.family); + ast_free(dead->o_line.addr); +} + +static void free_s_line(struct ast_sdp *dead) +{ + ast_free(dead->s_line); +} + +static void free_c_line(struct ast_sdp_c_line *c_line) +{ + ast_free(c_line->family); + ast_free(c_line->addr); +} + +static void free_t_line(struct ast_sdp_t_line *t_line) +{ + return; +} + +static void free_a_line(struct ast_sdp_a_line *a_line) +{ + ast_free(a_line->name); + ast_free(a_line->value); +} + +static void free_a_lines(struct ast_sdp_a_line_vector *a_lines) +{ + int i; + + for (i = 0; i < AST_VECTOR_SIZE(a_lines); ++i) { + free_a_line(AST_VECTOR_GET_ADDR(a_lines, i)); + } + AST_VECTOR_FREE(a_lines); +} + +static void free_m_line(struct ast_sdp_m_line *m_line) +{ + int i; + + ast_free(m_line->type); + ast_free(m_line->profile); + free_c_line(&m_line->c_line); + + for (i = 0; i < AST_VECTOR_SIZE(&m_line->payloads); ++i) { + ast_free(AST_VECTOR_GET(&m_line->payloads, i)); + } + AST_VECTOR_FREE(&m_line->payloads); + + free_a_lines(&m_line->a_lines); +} + +static void free_m_lines(struct ast_sdp *dead) +{ + int i; + + for (i = 0; i < AST_VECTOR_SIZE(&dead->m_lines); ++i) { + free_m_line(AST_VECTOR_GET_ADDR(&dead->m_lines, i)); + } + + AST_VECTOR_FREE(&dead->m_lines); +} + +void ast_sdp_free(struct ast_sdp *dead) +{ + if (!dead) { + return; + } + + free_o_line(dead); + free_s_line(dead); + free_c_line(&dead->c_line); + free_t_line(&dead->t_line); + free_a_lines(&dead->a_lines); + free_m_lines(dead); + ast_free(dead); +} + diff --git a/main/sdp_translator.c b/main/sdp_translator.c new file mode 100644 index 000000000..5426ae954 --- /dev/null +++ b/main/sdp_translator.c @@ -0,0 +1,99 @@ +/* + * Asterisk -- An open source telephony toolkit. + * + * Copyright (C) 2017, 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 "asterisk/sdp_options.h" +#include "asterisk/sdp_translator.h" +#include "asterisk/logger.h" +#include "asterisk/utils.h" +#include "asterisk/lock.h" + +AST_RWLOCK_DEFINE_STATIC(registered_ops_lock); +static struct ast_sdp_translator_ops *registered_ops[AST_SDP_REPR_END]; + +int ast_sdp_register_translator(struct ast_sdp_translator_ops *ops) +{ + SCOPED_WRLOCK(lock, ®istered_ops_lock); + + if (ops->repr >= AST_SDP_REPR_END) { + ast_log(LOG_ERROR, "SDP translator has unrecognized representation\n"); + return -1; + } + + if (registered_ops[ops->repr] != NULL) { + ast_log(LOG_ERROR, "SDP_translator with this representation already registered\n"); + return -1; + } + + registered_ops[ops->repr] = ops; + ast_log(LOG_NOTICE, "Placed ops %p at slot %d\n", ops, ops->repr); + return 0; +} + +void ast_sdp_unregister_translator(struct ast_sdp_translator_ops *ops) +{ + SCOPED_WRLOCK(lock, ®istered_ops_lock); + + if (ops->repr >= AST_SDP_REPR_END) { + return; + } + + registered_ops[ops->repr] = NULL; +} + +struct ast_sdp_translator *ast_sdp_translator_new(enum ast_sdp_options_repr repr) +{ + struct ast_sdp_translator *translator; + SCOPED_RDLOCK(lock, ®istered_ops_lock); + + if (registered_ops[repr] == NULL) { + ast_log(LOG_NOTICE, "No registered SDP translator with representation %d\n", repr); + return NULL; + } + + translator = ast_calloc(1, sizeof(*translator)); + if (!translator) { + return NULL; + } + + translator->ops = registered_ops[repr]; + + translator->translator_priv = translator->ops->translator_new(); + if (!translator->translator_priv) { + ast_free(translator); + return NULL; + } + + return translator; +} + +void ast_sdp_translator_free(struct ast_sdp_translator *translator) +{ + translator->ops->translator_free(translator->translator_priv); + ast_free(translator); +} + +struct ast_sdp *ast_sdp_translator_to_sdp(struct ast_sdp_translator *translator, void *native_sdp) +{ + return translator->ops->to_sdp(native_sdp, translator->translator_priv); +} + +void *ast_sdp_translator_from_sdp(struct ast_sdp_translator *translator, struct ast_sdp *ast_sdp) +{ + return translator->ops->from_sdp(ast_sdp, translator->translator_priv); +} |