<p>laforge <strong>submitted</strong> this change.</p><p><a href="https://gerrit.osmocom.org/c/osmo-mgw/+/24940">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  daniel: Looks good to me, approved
  pespin: Looks good to me, but someone else must approve
  Jenkins Builder: Verified

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">mgcp_protocol: refactor request handler array<br><br>the various types of MGCP requests are implemented in request handlers<br>functions. The function pointers to those functions are held in an array<br>that is used to find the right handler and call it then. The struct used<br>to model the array is defined somewhat away from the array definition<br>and there is also a macro in between that does not help to make the code<br>more understandable. Lets refactor this a bit to have it more distinct.<br><br>Change-Id: I2ef167b2ac179d2b0683a27a095f9662fda460bf<br>Related: SYS#5535<br>---<br>M src/libosmo-mgcp/mgcp_protocol.c<br>1 file changed, 29 insertions(+), 18 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/src/libosmo-mgcp/mgcp_protocol.c b/src/libosmo-mgcp/mgcp_protocol.c</span><br><span>index 895dd9e..f6daffc 100644</span><br><span>--- a/src/libosmo-mgcp/mgcp_protocol.c</span><br><span>+++ b/src/libosmo-mgcp/mgcp_protocol.c</span><br><span>@@ -46,22 +46,47 @@</span><br><span> #include <osmocom/mgcp/mgcp_codec.h></span><br><span> #include <osmocom/mgcp/mgcp_conn.h></span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/* Request handler specification, here we specify an array with function</span><br><span style="color: hsl(120, 100%, 40%);">+ * pointers to the various MGCP requests implemented below */</span><br><span> struct mgcp_request {</span><br><span style="color: hsl(120, 100%, 40%);">+     /* request name (e.g. "MDCX") */</span><br><span>   char *name;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* function pointer to the request handler */</span><br><span>        struct msgb *(*handle_request) (struct mgcp_parse_data * data);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     /* a human readable name that describes the request */</span><br><span>       char *debug_name;</span><br><span> };</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-#define MGCP_REQUEST(NAME, REQ, DEBUG_NAME) \</span><br><span style="color: hsl(0, 100%, 40%);">-        { .name = NAME, .handle_request = REQ, .debug_name = DEBUG_NAME },</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> static struct msgb *handle_audit_endpoint(struct mgcp_parse_data *data);</span><br><span> static struct msgb *handle_create_con(struct mgcp_parse_data *data);</span><br><span> static struct msgb *handle_delete_con(struct mgcp_parse_data *data);</span><br><span> static struct msgb *handle_modify_con(struct mgcp_parse_data *data);</span><br><span> static struct msgb *handle_rsip(struct mgcp_parse_data *data);</span><br><span> static struct msgb *handle_noti_req(struct mgcp_parse_data *data);</span><br><span style="color: hsl(120, 100%, 40%);">+static const struct mgcp_request mgcp_requests[] = {</span><br><span style="color: hsl(120, 100%, 40%);">+  { .name = "AUEP",</span><br><span style="color: hsl(120, 100%, 40%);">+     .handle_request = handle_audit_endpoint,</span><br><span style="color: hsl(120, 100%, 40%);">+      .debug_name = "AuditEndpoint" },</span><br><span style="color: hsl(120, 100%, 40%);">+  { .name = "CRCX",</span><br><span style="color: hsl(120, 100%, 40%);">+     .handle_request = handle_create_con,</span><br><span style="color: hsl(120, 100%, 40%);">+          .debug_name = "CreateConnection" },</span><br><span style="color: hsl(120, 100%, 40%);">+       { .name = "DLCX",</span><br><span style="color: hsl(120, 100%, 40%);">+     .handle_request = handle_delete_con,</span><br><span style="color: hsl(120, 100%, 40%);">+          .debug_name = "DeleteConnection" },</span><br><span style="color: hsl(120, 100%, 40%);">+       { .name = "MDCX",</span><br><span style="color: hsl(120, 100%, 40%);">+     .handle_request = handle_modify_con,</span><br><span style="color: hsl(120, 100%, 40%);">+          .debug_name = "ModifiyConnection" },</span><br><span style="color: hsl(120, 100%, 40%);">+      { .name = "RQNT",</span><br><span style="color: hsl(120, 100%, 40%);">+     .handle_request = handle_noti_req,</span><br><span style="color: hsl(120, 100%, 40%);">+    .debug_name = "NotificationRequest" },</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+  /* SPEC extension */</span><br><span style="color: hsl(120, 100%, 40%);">+  { .name = "RSIP",</span><br><span style="color: hsl(120, 100%, 40%);">+     .handle_request = handle_rsip,</span><br><span style="color: hsl(120, 100%, 40%);">+        .debug_name = "ReSetInProgress" },</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span> </span><br><span> /* Initalize transcoder */</span><br><span> static int setup_rtp_processing(struct mgcp_endpoint *endp,</span><br><span>@@ -95,20 +120,6 @@</span><br><span>    return cfg->setup_rtp_processing_cb(endp, conn_dst, conn_src);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-/* array of function pointers for handling various</span><br><span style="color: hsl(0, 100%, 40%);">- * messages. In the future this might be binary sorted</span><br><span style="color: hsl(0, 100%, 40%);">- * for performance reasons. */</span><br><span style="color: hsl(0, 100%, 40%);">-static const struct mgcp_request mgcp_requests[] = {</span><br><span style="color: hsl(0, 100%, 40%);">-    MGCP_REQUEST("AUEP", handle_audit_endpoint, "AuditEndpoint")</span><br><span style="color: hsl(0, 100%, 40%);">-        MGCP_REQUEST("CRCX", handle_create_con, "CreateConnection")</span><br><span style="color: hsl(0, 100%, 40%);">- MGCP_REQUEST("DLCX", handle_delete_con, "DeleteConnection")</span><br><span style="color: hsl(0, 100%, 40%);">- MGCP_REQUEST("MDCX", handle_modify_con, "ModifiyConnection")</span><br><span style="color: hsl(0, 100%, 40%);">-        MGCP_REQUEST("RQNT", handle_noti_req, "NotificationRequest")</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-        /* SPEC extension */</span><br><span style="color: hsl(0, 100%, 40%);">-    MGCP_REQUEST("RSIP", handle_rsip, "ReSetInProgress")</span><br><span style="color: hsl(0, 100%, 40%);">-};</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> /* Helper function to allocate some memory for responses and retransmissions */</span><br><span> static struct msgb *mgcp_msgb_alloc(void)</span><br><span> {</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/osmo-mgw/+/24940">change 24940</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/c/osmo-mgw/+/24940"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: osmo-mgw </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I2ef167b2ac179d2b0683a27a095f9662fda460bf </div>
<div style="display:none"> Gerrit-Change-Number: 24940 </div>
<div style="display:none"> Gerrit-PatchSet: 4 </div>
<div style="display:none"> Gerrit-Owner: dexter <pmaier@sysmocom.de> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins Builder </div>
<div style="display:none"> Gerrit-Reviewer: daniel <dwillmann@sysmocom.de> </div>
<div style="display:none"> Gerrit-Reviewer: laforge <laforge@osmocom.org> </div>
<div style="display:none"> Gerrit-Reviewer: pespin <pespin@sysmocom.de> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>