From ff63012c4e944f81f6720b7ac84a3228e09619da Mon Sep 17 00:00:00 2001
From: Jonathan Rose <jrose@digium.com>
Date: Fri, 14 Mar 2014 16:42:54 +0000
Subject: [PATCH] PJSIP: TOS values should be represented as decimals in
 sorcery objects

(closes issue ASTERISK-23235)
Reported by: George Joseph
Review: https://reviewboard.asterisk.org/r/3324/
........

Merged revisions 410574 from http://svn.asterisk.org/svn/asterisk/branches/12


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@410575 65c4cc65-6c06-0410-ace0-fbb531ad65f3
---
 CHANGES                                               |  4 ++++
 .../versions/4c573e7135bd_fix_tos_field_types.py      |  2 +-
 include/asterisk/acl.h                                | 11 -----------
 main/acl.c                                            |  6 ------
 res/res_pjsip/config_transport.c                      |  7 +++++--
 res/res_pjsip/pjsip_configuration.c                   | 10 ++++++++--
 6 files changed, 18 insertions(+), 22 deletions(-)

diff --git a/CHANGES b/CHANGES
index 81ed1bc72c..27318f5ffc 100644
--- a/CHANGES
+++ b/CHANGES
@@ -103,6 +103,10 @@ Core
  * Exposed sorcery-based configuration files like pjsip.conf to dialplans via
    the new AST_SORCERY diaplan function.
 
+res_pjsip
+------------------
+ * transport and endpoint ToS options (tos, tos_audio, and tos_video) may now
+   be set as the named set of ToS values (cs0-cs7, af11-af43, ef).
 
 ------------------------------------------------------------------------------
 --- Functionality changes from Asterisk 12.0.0 to Asterisk 12.1.0 ------------
diff --git a/contrib/ast-db-manage/config/versions/4c573e7135bd_fix_tos_field_types.py b/contrib/ast-db-manage/config/versions/4c573e7135bd_fix_tos_field_types.py
index 51e8fa9ca7..2c89bc2b8d 100755
--- a/contrib/ast-db-manage/config/versions/4c573e7135bd_fix_tos_field_types.py
+++ b/contrib/ast-db-manage/config/versions/4c573e7135bd_fix_tos_field_types.py
@@ -8,7 +8,7 @@ Create Date: 2014-03-05 12:16:56.618630
 
 # revision identifiers, used by Alembic.
 revision = '4c573e7135bd'
-down_revision = '21e526ad3040'
+down_revision = '28887f25a46f'
 
 from alembic import op
 from alembic import context
diff --git a/include/asterisk/acl.h b/include/asterisk/acl.h
index 502e7f4475..d1773b6b16 100644
--- a/include/asterisk/acl.h
+++ b/include/asterisk/acl.h
@@ -357,17 +357,6 @@ int ast_str2tos(const char *value, unsigned int *tos);
  */
 const char *ast_tos2str(unsigned int tos);
 
-/*!
- * \brief Convert a TOS value into its string representation
- *        and create a dynamically allocated copy
- *
- * \param tos The TOS value to look up
- * \param buf pointer to character pointer where string will be duplicated to
- *
- * \note The string allocated at buf must be free'd
- */
-void ast_tos2str_buf(unsigned int tos, char **buf);
-
 /*!
  * \brief Retrieve a named ACL
  *
diff --git a/main/acl.c b/main/acl.c
index a55e87458d..c341125fd6 100644
--- a/main/acl.c
+++ b/main/acl.c
@@ -894,12 +894,6 @@ const char *ast_tos2str(unsigned int tos)
 	return "unknown";
 }
 
-void ast_tos2str_buf(unsigned int tos, char **buf)
-{
-	const char *tos_string = ast_tos2str(tos);
-	*buf = ast_strdup(tos_string);
-}
-
 int ast_get_ip(struct ast_sockaddr *addr, const char *hostname)
 {
 	return ast_get_ip_or_srv(addr, hostname, NULL);
diff --git a/res/res_pjsip/config_transport.c b/res/res_pjsip/config_transport.c
index 1559ab77c4..5fbede2bd0 100644
--- a/res/res_pjsip/config_transport.c
+++ b/res/res_pjsip/config_transport.c
@@ -502,7 +502,10 @@ static int transport_tos_handler(const struct aco_option *opt, struct ast_variab
 static int tos_to_str(const void *obj, const intptr_t *args, char **buf)
 {
 	const struct ast_sip_transport *transport = obj;
-	ast_tos2str_buf(transport->tos, buf);
+
+	if (ast_asprintf(buf, "%d", transport->tos) == -1) {
+		return -1;
+	}
 	return 0;
 }
 
@@ -574,7 +577,7 @@ static int cli_print_body(void *obj, void *arg, int flags)
 
 	pj_sockaddr_print(&transport->host, hoststr, sizeof(hoststr), 3);
 
-	ast_str_append(&context->output_buffer, 0, "%*s:  %-21s  %6s  %5x  %5x  %s\n",
+	ast_str_append(&context->output_buffer, 0, "%*s:  %-21s  %6s  %5d  %5d  %s\n",
 		CLI_INDENT_TO_SPACES(context->indent_level), "Transport",
 		ast_sorcery_object_get_id(transport),
 		ARRAY_IN_BOUNDS(transport->type, transport_types) ? transport_types[transport->type] : "Unknown",
diff --git a/res/res_pjsip/pjsip_configuration.c b/res/res_pjsip/pjsip_configuration.c
index b2a86c3c8d..1f289ade93 100644
--- a/res/res_pjsip/pjsip_configuration.c
+++ b/res/res_pjsip/pjsip_configuration.c
@@ -786,14 +786,20 @@ static int tos_handler(const struct aco_option *opt,
 static int tos_audio_to_str(const void *obj, const intptr_t *args, char **buf)
 {
 	const struct ast_sip_endpoint *endpoint = obj;
-	ast_tos2str_buf(endpoint->media.tos_audio, buf);
+
+	if (ast_asprintf(buf, "%d", endpoint->media.tos_audio) == -1) {
+		return -1;
+	}
 	return 0;
 }
 
 static int tos_video_to_str(const void *obj, const intptr_t *args, char **buf)
 {
 	const struct ast_sip_endpoint *endpoint = obj;
-	ast_tos2str_buf(endpoint->media.tos_video, buf);
+
+	if (ast_asprintf(buf, "%d", endpoint->media.tos_video) == -1) {
+		return -1;
+	}
 	return 0;
 }
 
-- 
GitLab