diff options
author | Holger Hans Peter Freyther <zecke@selfish.org> | 2010-04-04 19:34:44 +0200 |
---|---|---|
committer | Holger Hans Peter Freyther <zecke@selfish.org> | 2010-04-04 19:40:25 +0200 |
commit | 1e1acafafdb581780c82c81875bc005ae83b6b2b (patch) | |
tree | a4a159d02b1083244f8ea4ab807090ba5c443608 /openbsc/src/nat/bsc_mgcp_utils.c | |
parent | fb83b7a86d1c2ed335f7f3c00782154854233677 (diff) |
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.
Diffstat (limited to 'openbsc/src/nat/bsc_mgcp_utils.c')
-rw-r--r-- | openbsc/src/nat/bsc_mgcp_utils.c | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/openbsc/src/nat/bsc_mgcp_utils.c b/openbsc/src/nat/bsc_mgcp_utils.c index 164b6f64c..2b28305a8 100644 --- a/openbsc/src/nat/bsc_mgcp_utils.c +++ b/openbsc/src/nat/bsc_mgcp_utils.c @@ -277,21 +277,24 @@ struct msgb *bsc_mgcp_rewrite(char *input, int length, const char *ip, int port) 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 @@ struct msgb *bsc_mgcp_rewrite(char *input, int length, const char *ip, int port) 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)); |