Currently the local connection options have been stored as a string.

This patch replaces this string by a struct (that still contains a
string) along with the parsed fields (only the packetization period
at the moment).

It also re-adds the calls to set_local_cx_options() to the
handle_create_con() and handle_modify_con() functions. Except for
the test program this has no side effects, since the LCO values
aren't used yet.
---
 openbsc/include/openbsc/mgcp_internal.h |    8 ++++++-
 openbsc/src/libmgcp/mgcp_protocol.c     |   37 ++++++++++++++++++++++++++-----
 openbsc/tests/mgcp/mgcp_test.c          |    9 +++++++-
 openbsc/tests/mgcp/mgcp_test.ok         |    8 +++----
 4 files changed, 51 insertions(+), 11 deletions(-)

diff --git a/openbsc/include/openbsc/mgcp_internal.h 
b/openbsc/include/openbsc/mgcp_internal.h
index d59c5d7..20c433a 100644
--- a/openbsc/include/openbsc/mgcp_internal.h
+++ b/openbsc/include/openbsc/mgcp_internal.h
@@ -114,6 +114,12 @@ struct mgcp_rtp_tap {
        struct sockaddr_in forward;
 };
 
+struct mgcp_lco {
+       char *string;
+       int pkt_period_min; /* time in ms */
+       int pkt_period_max; /* time in ms */
+};
+
 enum mgcp_type {
        MGCP_RTP_DEFAULT        = 0,
        MGCP_RTP_TRANSCODED,
@@ -123,7 +129,7 @@ struct mgcp_endpoint {
        int allocated;
        uint32_t ci;
        char *callid;
-       char *local_options;
+       struct mgcp_lco local_options;
        int conn_mode;
        int orig_mode;
 
diff --git a/openbsc/src/libmgcp/mgcp_protocol.c 
b/openbsc/src/libmgcp/mgcp_protocol.c
index ab94164..5403861 100644
--- a/openbsc/src/libmgcp/mgcp_protocol.c
+++ b/openbsc/src/libmgcp/mgcp_protocol.c
@@ -614,6 +614,29 @@ static int parse_sdp_data(struct mgcp_rtp_end *rtp, struct 
mgcp_parse_data *p)
        return found_media;
 }
 
+/* Set the LCO from a string (see RFC 3435).
+ * The string is stored in the 'string' field. A NULL string is handled excatly
+ * like an empty string, the 'string' field is never NULL after this function
+ * has been called. */
+static void set_local_cx_options(void *ctx, struct mgcp_lco *lco,
+                                const char *options, int size)
+{
+       char *p_opt;
+
+       talloc_free(lco->string);
+       lco->pkt_period_min = lco->pkt_period_max = 0;
+
+       if (size >= 0)
+               lco->string = talloc_strndup(ctx, options, size);
+       else
+               lco->string = talloc_strdup(ctx, options ? options : "");
+
+       p_opt = strstr(lco->string, "p:");
+       if (p_opt && sscanf(p_opt, "p:%d-%d",
+                           &lco->pkt_period_min, &lco->pkt_period_max) == 1)
+                       lco->pkt_period_max = lco->pkt_period_min;
+}
+
 void mgcp_rtp_end_config(struct mgcp_endpoint *endp, int expect_ssrc_change,
                         struct mgcp_rtp_end *rtp)
 {
@@ -712,8 +735,8 @@ mgcp_header_done:
        /* copy some parameters */
        endp->callid = talloc_strdup(tcfg->endpoints, callid);
 
-       if (local_options)
-               endp->local_options = talloc_strdup(tcfg->endpoints, 
local_options);
+       set_local_cx_options(endp->tcfg->endpoints, &endp->local_options,
+                            local_options, -1);
 
        if (parse_conn_mode(mode, &endp->conn_mode) != 0) {
                    error_code = 517;
@@ -789,6 +812,7 @@ static struct msgb *handle_modify_con(struct 
mgcp_parse_data *p)
        int error_code = 500;
        int silent = 0;
        char *line;
+       const char *local_options = NULL;
 
        if (p->found != 0)
                return create_err_response(NULL, 510, "MDCX", p->trans);
@@ -812,7 +836,7 @@ static struct msgb *handle_modify_con(struct 
mgcp_parse_data *p)
                        break;
                }
                case 'L':
-                       /* skip */
+                       local_options = (const char *) line + 3;
                        break;
                case 'M':
                        if (parse_conn_mode(line + 3, &endp->conn_mode) != 0) {
@@ -838,6 +862,9 @@ static struct msgb *handle_modify_con(struct 
mgcp_parse_data *p)
                }
        }
 
+       set_local_cx_options(endp->tcfg->endpoints, &endp->local_options,
+                            local_options, -1);
+
        /* policy CB */
        if (p->cfg->policy_cb) {
                int rc;
@@ -1148,8 +1175,8 @@ void mgcp_free_endp(struct mgcp_endpoint *endp)
        talloc_free(endp->callid);
        endp->callid = NULL;
 
-       talloc_free(endp->local_options);
-       endp->local_options = NULL;
+       talloc_free(endp->local_options.string);
+       endp->local_options.string = NULL;
 
        mgcp_rtp_end_reset(&endp->bts_end);
        mgcp_rtp_end_reset(&endp->net_end);
diff --git a/openbsc/tests/mgcp/mgcp_test.c b/openbsc/tests/mgcp/mgcp_test.c
index 1b183fd..3591124 100644
--- a/openbsc/tests/mgcp/mgcp_test.c
+++ b/openbsc/tests/mgcp/mgcp_test.c
@@ -319,7 +319,14 @@ static void test_messages(void)
                                       endp->net_end.packet_duration_ms);
                        else
                                printf("Packet duration not set\n");
-                       printf("Requested packetization period not set\n");
+                       if (endp->local_options.pkt_period_min ||
+                           endp->local_options.pkt_period_max)
+                               printf("Requested packetetization period: "
+                                      "%d-%d\n",
+                                      endp->local_options.pkt_period_min,
+                                      endp->local_options.pkt_period_max);
+                       else
+                               printf("Requested packetization period not 
set\n");
 
                        endp->net_end.packet_duration_ms = -1;
                }
diff --git a/openbsc/tests/mgcp/mgcp_test.ok b/openbsc/tests/mgcp/mgcp_test.ok
index 509958a..24f9b33 100644
--- a/openbsc/tests/mgcp/mgcp_test.ok
+++ b/openbsc/tests/mgcp/mgcp_test.ok
@@ -17,19 +17,19 @@ Testing MDCX1
 Testing MDCX2
 Testing CRCX
 Packet duration not set
-Requested packetization period not set
+Requested packetetization period: 20-20
 Testing MDCX3
 Packet duration not set
 Requested packetization period not set
 Testing MDCX4
 Packet duration not set
-Requested packetization period not set
+Requested packetetization period: 20-20
 Testing MDCX4_PT1
 Packet duration not set
-Requested packetization period not set
+Requested packetetization period: 20-40
 Testing MDCX4_PT2
 Packet duration not set
-Requested packetization period not set
+Requested packetetization period: 20-20
 Testing MDCX4_PT3
 Packet duration not set
 Requested packetization period not set
-- 
1.7.9.5


Reply via email to