changeset 99:738be11ac432

mgw internal code: simplify MDCX error handling
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 26 Sep 2022 13:42:46 -0800
parents 423610bb2c9e
children 1579ec0e9fb9
files mgw/crcx.c mgw/mdcx.c
diffstat 2 files changed, 25 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
--- a/mgw/crcx.c	Sun Sep 25 20:28:54 2022 -0800
+++ b/mgw/crcx.c	Mon Sep 26 13:42:46 2022 -0800
@@ -143,13 +143,14 @@
 			return;
 		}
 	}
-	rc = mdcx_operation(ep, req, resp);
-	if (rc < 0) {
+	rc = mdcx_operation(ep, req);
+	if (rc != TMGW_RESP_OK) {
 		if (ep->ep_type & TMGW_EP_HAS_GSM_SOCK)
 			free_rtp_end(&ep->rtp_gsm);
 		if (ep->ep_type & TMGW_EP_HAS_PSTN_SOCK)
 			free_rtp_end(&ep->rtp_pstn);
 		free(ep);
+		resp->res = rc;
 		return;
 	}
 	/* all good - accept the new endpoint and return OK */
--- a/mgw/mdcx.c	Sun Sep 25 20:28:54 2022 -0800
+++ b/mgw/mdcx.c	Mon Sep 26 13:42:46 2022 -0800
@@ -17,64 +17,48 @@
 
 extern struct endpoint *find_ep_by_id();
 
-mdcx_operation(ep, req, resp)
+mdcx_operation(ep, req)
 	struct endpoint *ep;
 	struct tmgw_ctrl_req *req;
-	struct tmgw_ctrl_resp *resp;
 {
 	int rc;
 
 	if (req->setup_mask & TMGW_CTRL_MASK_GSM_CONN) {
-		if (ep->ep_type != TMGW_EP_TYPE_GATEWAY) {
-			resp->res = TMGW_RESP_ERR_PROT;
-			return(-1);
-		}
-		if (req->gsm_addr.ss_family != AF_INET) {
-			resp->res = TMGW_RESP_ERR_PARAM;
-			return(-1);
-		}
-		if (req->gsm_payload_type > 0x7F) {
-			resp->res = TMGW_RESP_ERR_PARAM;
-			return(-1);
-		}
+		if (ep->ep_type != TMGW_EP_TYPE_GATEWAY)
+			return TMGW_RESP_ERR_PROT;
+		if (req->gsm_addr.ss_family != AF_INET)
+			return TMGW_RESP_ERR_PARAM;
+		if (req->gsm_payload_type > 0x7F)
+			return TMGW_RESP_ERR_PARAM;
 		switch (req->gsm_payload_msg_type) {
 		case GSM_TCHF_FRAME:
 			break;
 		case GSM_TCHF_FRAME_EFR:
 		case GSM_TCHH_FRAME:
 		case GSM_TCH_FRAME_AMR:
-			resp->res = TMGW_RESP_ERR_NOTSUP;
-			return(-1);
+			return TMGW_RESP_ERR_NOTSUP;
 		default:
-			resp->res = TMGW_RESP_ERR_PARAM;
-			return(-1);
+			return TMGW_RESP_ERR_PARAM;
 		}
 		if (ep->gsm_payload_msg_type &&
-		    ep->gsm_payload_msg_type != req->gsm_payload_msg_type) {
-			resp->res = TMGW_RESP_ERR_PROT;
-			return(-1);
-		}
+		    ep->gsm_payload_msg_type != req->gsm_payload_msg_type)
+			return TMGW_RESP_ERR_PROT;
 		bcopy(&req->gsm_addr, &ep->rtp_gsm.remote_addr,
 			sizeof(struct sockaddr_in));
 		ep->gsm_payload_type = req->gsm_payload_type;
 		ep->gsm_payload_msg_type = req->gsm_payload_msg_type;
 	}
 	if (req->setup_mask & TMGW_CTRL_MASK_PSTN_CONN) {
-		if (ep->ep_type != TMGW_EP_TYPE_GATEWAY) {
-			resp->res = TMGW_RESP_ERR_PROT;
-			return(-1);
-		}
-		if (req->pstn_addr.ss_family != AF_INET) {
-			resp->res = TMGW_RESP_ERR_PARAM;
-			return(-1);
-		}
+		if (ep->ep_type != TMGW_EP_TYPE_GATEWAY)
+			return TMGW_RESP_ERR_PROT;
+		if (req->pstn_addr.ss_family != AF_INET)
+			return TMGW_RESP_ERR_PARAM;
 		switch (req->pstn_payload_type) {
 		case PSTN_CODEC_PCMU:
 		case PSTN_CODEC_PCMA:
 			break;
 		default:
-			resp->res = TMGW_RESP_ERR_PARAM;
-			return(-1);
+			return TMGW_RESP_ERR_PARAM;
 		}
 		bcopy(&req->pstn_addr, &ep->rtp_pstn.remote_addr,
 			sizeof(struct sockaddr_in));
@@ -83,21 +67,17 @@
 	if (req->setup_mask & TMGW_CTRL_MASK_FWD_MODE) {
 		if (ep->ep_type != TMGW_EP_TYPE_GATEWAY ||
 		    ep->rtp_gsm.remote_addr.sin_family != AF_INET ||
-		    ep->rtp_pstn.remote_addr.sin_family != AF_INET) {
-			resp->res = TMGW_RESP_ERR_PROT;
-			return(-1);
-		}
+		    ep->rtp_pstn.remote_addr.sin_family != AF_INET)
+			return TMGW_RESP_ERR_PROT;
 		if ((req->fwd_mode & TMGW_FWD_ENABLE_PSTN2GSM) &&
 		    !(ep->fwd_mode & TMGW_FWD_ENABLE_PSTN2GSM)) {
 			rc = pstn2gsm_init(ep);
-			if (rc != TMGW_RESP_OK) {
-				resp->res = rc;
-				return(-1);
-			}
+			if (rc != TMGW_RESP_OK)
+				return rc;
 		}
 		ep->fwd_mode = req->fwd_mode;
 	}
-	return(0);
+	return TMGW_RESP_OK;
 }
 
 void
@@ -114,7 +94,5 @@
 		resp->res = TMGW_RESP_ERR_PROT;
 		return;
 	}
-	rc = mdcx_operation(ep, req, resp);
-	if (rc == 0)
-		resp->res = TMGW_RESP_OK;
+	resp->res = mdcx_operation(ep, req);
 }