SDP: Replace SDP telephone_event option with dtmf option
[asterisk/asterisk.git] / main / sdp_options.c
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 2017, Digium, Inc.
5  *
6  * Mark Michelson <mmichelson@digium.com>
7  *
8  * See http://www.asterisk.org for more information about
9  * the Asterisk project. Please do not directly contact
10  * any of the maintainers of this project for assistance;
11  * the project provides a web site, mailing lists and IRC
12  * channels for your use.
13  *
14  * This program is free software, distributed under the terms of
15  * the GNU General Public License Version 2. See the LICENSE file
16  * at the top of the source tree.
17  */
18
19 #include "asterisk.h"
20
21 #include "asterisk/utils.h"
22 #include "asterisk/sdp_options.h"
23
24 #include "sdp_private.h"
25
26 #define DEFAULT_DTMF AST_SDP_DTMF_NONE
27 #define DEFAULT_ICE AST_SDP_ICE_DISABLED
28 #define DEFAULT_IMPL AST_SDP_IMPL_STRING
29 #define DEFAULT_ENCRYPTION AST_SDP_ENCRYPTION_DISABLED
30
31 #define DEFINE_STRINGFIELD_GETTERS_SETTERS_FOR(field, assert_on_null) \
32 void ast_sdp_options_set_##field(struct ast_sdp_options *options, const char *value) \
33 { \
34         ast_assert(options != NULL); \
35         if ((assert_on_null)) ast_assert(!ast_strlen_zero(value)); \
36         if (!strcmp(value, options->field)) return; \
37         ast_string_field_set(options, field, value); \
38 } \
39 const char *ast_sdp_options_get_##field(const struct ast_sdp_options *options) \
40 { \
41         ast_assert(options != NULL); \
42         return options->field; \
43 } \
44
45 #define DEFINE_GETTERS_SETTERS_FOR(type, field) \
46 void ast_sdp_options_set_##field(struct ast_sdp_options *options, type value) \
47 { \
48         ast_assert(options != NULL); \
49         options->field = value; \
50 } \
51 type ast_sdp_options_get_##field(const struct ast_sdp_options *options) \
52 { \
53         ast_assert(options != NULL); \
54         return options->field; \
55 } \
56
57 DEFINE_STRINGFIELD_GETTERS_SETTERS_FOR(media_address, 0);
58 DEFINE_STRINGFIELD_GETTERS_SETTERS_FOR(sdpowner, 0);
59 DEFINE_STRINGFIELD_GETTERS_SETTERS_FOR(sdpsession, 0);
60 DEFINE_STRINGFIELD_GETTERS_SETTERS_FOR(rtp_engine, 0);
61
62 DEFINE_GETTERS_SETTERS_FOR(unsigned int, bind_rtp_to_media_address);
63 DEFINE_GETTERS_SETTERS_FOR(unsigned int, bind_udptl_to_media_address);
64 DEFINE_GETTERS_SETTERS_FOR(unsigned int, rtp_symmetric);
65 DEFINE_GETTERS_SETTERS_FOR(unsigned int, udptl_symmetric);
66 DEFINE_GETTERS_SETTERS_FOR(enum ast_t38_ec_modes, udptl_error_correction);
67 DEFINE_GETTERS_SETTERS_FOR(unsigned int, udptl_far_max_datagram);
68 DEFINE_GETTERS_SETTERS_FOR(unsigned int, rtp_ipv6);
69 DEFINE_GETTERS_SETTERS_FOR(unsigned int, g726_non_standard);
70 DEFINE_GETTERS_SETTERS_FOR(unsigned int, rtcp_mux);
71 DEFINE_GETTERS_SETTERS_FOR(unsigned int, tos_audio);
72 DEFINE_GETTERS_SETTERS_FOR(unsigned int, cos_audio);
73 DEFINE_GETTERS_SETTERS_FOR(unsigned int, tos_video);
74 DEFINE_GETTERS_SETTERS_FOR(unsigned int, cos_video);
75 DEFINE_GETTERS_SETTERS_FOR(enum ast_sdp_options_dtmf, dtmf);
76 DEFINE_GETTERS_SETTERS_FOR(enum ast_sdp_options_ice, ice);
77 DEFINE_GETTERS_SETTERS_FOR(enum ast_sdp_options_impl, impl);
78 DEFINE_GETTERS_SETTERS_FOR(enum ast_sdp_options_encryption, encryption);
79 DEFINE_GETTERS_SETTERS_FOR(unsigned int, ssrc);
80
81 static void set_defaults(struct ast_sdp_options *options)
82 {
83         options->dtmf = DEFAULT_DTMF;
84         options->ice = DEFAULT_ICE;
85         options->impl = DEFAULT_IMPL;
86         options->encryption = DEFAULT_ENCRYPTION;
87 }
88
89 struct ast_sdp_options *ast_sdp_options_alloc(void)
90 {
91         struct ast_sdp_options *options;
92
93         options = ast_calloc(1, sizeof(*options));
94         if (!options) {
95                 return NULL;
96         }
97
98         if (ast_string_field_init(options, 256)) {
99                 ast_free(options);
100                 return NULL;
101         }
102
103         set_defaults(options);
104         return options;
105 }
106
107 void ast_sdp_options_free(struct ast_sdp_options *options)
108 {
109         ast_string_field_free_memory(options);
110         ast_free(options);
111 }