]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
lldpcli: with key/value display, remove any newline
authorVincent Bernat <vincent@bernat.im>
Sat, 12 Mar 2016 13:03:54 +0000 (14:03 +0100)
committerVincent Bernat <vincent@bernat.im>
Sat, 12 Mar 2016 13:03:54 +0000 (14:03 +0100)
They make hard to parse the result. Just remove them. This happens for
example with CDP.

src/client/kv_writer.c

index 2983288e0ea3d38712725d329e33c1e557c969ac..dcbfa09731ed2f7b6aed80108a5446f1215c8791 100644 (file)
@@ -53,10 +53,19 @@ kv_data(struct writer *w, const char *data)
 {
        struct kv_writer_private *p = w->priv;
        char *key = strdup(p->prefix);
-       char *dot;
+       char *value = data?strdup(data):NULL;
+       char *dot, *nl;
        if (!key) fatal(NULL, NULL);
-       while ((dot = strchr(key, '\1')) != NULL) *dot=SEP;
-       fprintf(p->fh, "%s=%s\n", key, data?data:"");
+       while ((dot = strchr(key, '\1')) != NULL)
+               *dot = SEP;
+       if (value) {
+               nl = value;
+               while ((nl = strchr(nl, '\n'))) {
+                       *nl = ' ';
+                       nl++;
+               }
+       }
+       fprintf(p->fh, "%s=%s\n", key, value?value:"");
        free(key);
 }