[mgcp] Make the mgcp_protocol generate a struct msgb*
Do not directly send data from inside the mgcp_protocol.c
implementation. Instead allocate and return a struct msgb*. The
caller can then either wrap that into the IPA protcol or directly
send it over the UDP socket.
diff --git a/openbsc/src/mgcp/mgcp_main.c b/openbsc/src/mgcp/mgcp_main.c
index 134148c..6d8b3e9 100644
--- a/openbsc/src/mgcp/mgcp_main.c
+++ b/openbsc/src/mgcp/mgcp_main.c
@@ -106,6 +106,7 @@
struct sockaddr_in addr;
socklen_t slen = sizeof(addr);
struct msgb *msg;
+ struct msgb *resp;
msg = (struct msgb *) fd->data;
@@ -123,14 +124,25 @@
if (first_request) {
first_request = 0;
- mgcp_send_rsip(bfd.fd, &addr);
+ resp = mgcp_create_rsip();
+
+ if (resp) {
+ sendto(bfd.fd, resp->l2h, msgb_l2len(resp), 0,
+ (struct sockaddr *) &addr, sizeof(addr));
+ msgb_free(resp);
+ }
return 0;
}
/* handle message now */
msg->l2h = msgb_put(msg, rc);
- mgcp_handle_message(bfd.fd, msg, &addr);
+ resp = mgcp_handle_message(msg);
msgb_reset(msg);
+
+ if (resp) {
+ sendto(bfd.fd, resp->l2h, msgb_l2len(resp), 0, (struct sockaddr *) &addr, sizeof(addr));
+ msgb_free(resp);
+ }
return 0;
}