nat: Remove the broken empty line check, follow \n vs \r\n of input

Instead of checking the token for NULL we need to check if running
was set to null. Look at the data of the token and check if the line
was ending with a \r\n or \n and then when rewriting a line use that
line ending as well. Add a new test for that.
diff --git a/openbsc/src/nat/bsc_mgcp_utils.c b/openbsc/src/nat/bsc_mgcp_utils.c
index 164b6f6..2b28305 100644
--- a/openbsc/src/nat/bsc_mgcp_utils.c
+++ b/openbsc/src/nat/bsc_mgcp_utils.c
@@ -277,21 +277,24 @@
 
 	running = input;
 	output->l2h = output->data;
-	for (token = strsep(&running, "\n"); token; token = strsep(&running, "\n")) {
+	for (token = strsep(&running, "\n"); running; token = strsep(&running, "\n")) {
 		int len = strlen(token);
-
-		/* ignore completely empty lines for now */
-		if (len == 0)
-			continue;
+		int cr = len > 0 && token[len - 1] == '\r';
 
 		if (strncmp(ip_str, token, (sizeof ip_str) - 1) == 0) {
 			output->l3h = msgb_put(output, strlen(ip_str));
 			memcpy(output->l3h, ip_str, strlen(ip_str));
 			output->l3h = msgb_put(output, strlen(ip));
 			memcpy(output->l3h, ip, strlen(ip));
-			output->l3h = msgb_put(output, 2);
-			output->l3h[0] = '\r';
-			output->l3h[1] = '\n';
+
+			if (cr) {
+				output->l3h = msgb_put(output, 2);
+				output->l3h[0] = '\r';
+				output->l3h[1] = '\n';
+			} else {
+				output->l3h = msgb_put(output, 1);
+				output->l3h[0] = '\n';
+			}
 		} else if (strncmp(aud_str, token, (sizeof aud_str) - 1) == 0) {
 			int payload;
 			if (sscanf(token, "m=audio %*d RTP/AVP %d", &payload) != 1) {
@@ -300,7 +303,8 @@
 				return NULL;
 			}
 
-			snprintf(buf, sizeof(buf)-1, "m=audio %d RTP/AVP %d\r\n", port, payload);
+			snprintf(buf, sizeof(buf)-1, "m=audio %d RTP/AVP %d%s",
+				 port, payload, cr ? "\r\n" : "\n");
 			buf[sizeof(buf)-1] = '\0';
 
 			output->l3h = msgb_put(output, strlen(buf));