summaryrefslogtreecommitdiff
path: root/src/print_ipv6_addr.c
diff options
context:
space:
mode:
authorMichael Stapelberg <michael@stapelberg.de>2012-03-25 20:55:55 +0200
committerMichael Stapelberg <michael@stapelberg.de>2012-03-25 22:05:00 +0200
commit12b1bfa9b8485de88b0bda82821c021aee197673 (patch)
treeb6d87f7ed5876109863a6599992e351509a30d58 /src/print_ipv6_addr.c
parentafb0525235c57fc4896633003a45bfb013af38d2 (diff)
Properly output JSON with libyajl
Diffstat (limited to 'src/print_ipv6_addr.c')
-rw-r--r--src/print_ipv6_addr.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/src/print_ipv6_addr.c b/src/print_ipv6_addr.c
index 3ace6a2..3f1c81d 100644
--- a/src/print_ipv6_addr.c
+++ b/src/print_ipv6_addr.c
@@ -8,6 +8,7 @@
#include <netdb.h>
#include <string.h>
#include <arpa/inet.h>
+#include <yajl/yajl_gen.h>
#include "i3status.h"
@@ -109,30 +110,27 @@ static char *get_ipv6_addr() {
return NULL;
}
-void print_ipv6_info(const char *format_up, const char *format_down) {
+void print_ipv6_info(yajl_gen json_gen, char *buffer, const char *format_up, const char *format_down) {
const char *walk;
char *addr_string = get_ipv6_addr();
-
- if (output_format == O_I3BAR)
- printf("{\"name\":\"ipv6\", \"full_text\":\"");
+ char *outwalk = buffer;
if (addr_string == NULL) {
- printf("%s", format_down);
+ OUTPUT_FULL_TEXT(format_down);
return;
}
for (walk = format_up; *walk != '\0'; walk++) {
if (*walk != '%') {
- putchar(*walk);
+ *(outwalk++) = *walk;
continue;
}
if (strncmp(walk+1, "ip", strlen("ip")) == 0) {
- printf("%s", addr_string);
+ outwalk += sprintf(outwalk, "%s", addr_string);
walk += strlen("ip");
}
}
- if (output_format == O_I3BAR)
- printf("\"}");
+ OUTPUT_FULL_TEXT(buffer);
}