mgw: Release endpoint after last conn times out

Otherwise some state is kept, like the previous CallId, which may then
provoke issues next time the endpoint is to be used.

Change-Id: I3ac4f4542c1c8c877127c64acce6c82b458f697f
diff --git a/src/libosmo-mgcp/mgcp_endp.c b/src/libosmo-mgcp/mgcp_endp.c
index c4f3653..ecb2845 100644
--- a/src/libosmo-mgcp/mgcp_endp.c
+++ b/src/libosmo-mgcp/mgcp_endp.c
@@ -666,3 +666,20 @@
 		OSMO_ASSERT(false);
 	}
 }
+
+void mgcp_endp_add_conn(struct mgcp_endpoint *endp, struct mgcp_conn *conn)
+{
+	llist_add(&conn->entry, &endp->conns);
+}
+
+void mgcp_endp_remove_conn(struct mgcp_endpoint *endp, struct mgcp_conn *conn)
+{
+	/* Run endpoint cleanup action. By this we inform the endpoint about
+	 * the removal of the connection and allow it to clean up its inner
+	 * state accordingly */
+	if (endp->type->cleanup_cb)
+		endp->type->cleanup_cb(endp, conn);
+	llist_del(&conn->entry);
+	if (llist_empty(&endp->conns))
+		mgcp_endp_release(endp);
+}