mgcp: Change the flow of the code when handling a MGCP response
Attempt to detect a response and return only then. Remove one level
of tabls in preparation for the re-transmission handling.
diff --git a/openbsc/src/libmgcp/mgcp_protocol.c b/openbsc/src/libmgcp/mgcp_protocol.c
index 2faf75b..2c3a438 100644
--- a/openbsc/src/libmgcp/mgcp_protocol.c
+++ b/openbsc/src/libmgcp/mgcp_protocol.c
@@ -182,6 +182,7 @@
struct msgb *mgcp_handle_message(struct mgcp_config *cfg, struct msgb *msg)
{
int code;
+ int i, handled = 0;
struct msgb *resp = NULL;
if (msgb_l2len(msg) < 4) {
@@ -192,20 +193,22 @@
/* attempt to treat it as a response */
if (sscanf((const char *)&msg->l2h[0], "%3d %*s", &code) == 1) {
LOGP(DMGCP, LOGL_DEBUG, "Response: Code: %d\n", code);
- } else {
- int i, handled = 0;
- msg->l3h = &msg->l2h[4];
- for (i = 0; i < ARRAY_SIZE(mgcp_requests); ++i)
- if (strncmp(mgcp_requests[i].name, (const char *) &msg->l2h[0], 4) == 0) {
- handled = 1;
- resp = mgcp_requests[i].handle_request(cfg, msg);
- break;
- }
- if (!handled) {
- LOGP(DMGCP, LOGL_NOTICE, "MSG with type: '%.4s' not handled\n", &msg->l2h[0]);
+ return NULL;
+ }
+
+ msg->l3h = &msg->l2h[4];
+
+ for (i = 0; i < ARRAY_SIZE(mgcp_requests); ++i) {
+ if (strncmp(mgcp_requests[i].name, (const char *) &msg->l2h[0], 4) == 0) {
+ handled = 1;
+ resp = mgcp_requests[i].handle_request(cfg, msg);
+ break;
}
}
+ if (!handled)
+ LOGP(DMGCP, LOGL_NOTICE, "MSG with type: '%.4s' not handled\n", &msg->l2h[0]);
+
return resp;
}