struct json_writer_private *p = w->priv;
struct json_element *current = TAILQ_LAST(p, json_writer_private);
json_t *jvalue;
- if (!strcmp(value, "yes") || !strcmp(value, "on"))
+ if (value && (!strcmp(value, "yes") || !strcmp(value, "on")))
jvalue = json_true();
- else if (!strcmp(value, "no") || !strcmp(value, "off"))
+ else if (value && (!strcmp(value, "no") || !strcmp(value, "off")))
jvalue = json_false();
else
- jvalue = json_string(value);
+ jvalue = json_string(value?value:"");
json_object_set_new(current->el, tag, jvalue);
}
{
struct json_writer_private *p = w->priv;
struct json_element *current = TAILQ_LAST(p, json_writer_private);
- json_object_set_new(current->el, "value", json_string(data));
+ json_object_set_new(current->el, "value",
+ json_string(data?data:""));
}
static void
struct json_writer_private *p = w->priv;
struct json_element *current = TAILQ_LAST(p, json_writer_private);
json_object *jvalue;
- if (!strcmp(value, "yes") || !strcmp(value, "on"))
+ if (value && (!strcmp(value, "yes") || !strcmp(value, "on")))
jvalue = json_object_new_boolean(1);
- else if (!strcmp(value, "no") || !strcmp(value, "off"))
+ else if (value && (!strcmp(value, "no") || !strcmp(value, "off")))
jvalue = json_object_new_boolean(0);
else
- jvalue = json_object_new_string(value);
+ jvalue = json_object_new_string(value?value:"");
json_object_object_add(current->el, tag, jvalue);
}
{
struct json_writer_private *p = w->priv;
struct json_element *current = TAILQ_LAST(p, json_writer_private);
- json_object_object_add(current->el, "value", json_object_new_string(data));
+ json_object_object_add(current->el, "value",
+ json_object_new_string(data?data:""));
}
static void
char *dot;
if (!key) fatal(NULL, NULL);
while ((dot = strchr(key, '\1')) != NULL) *dot=SEP;
- fprintf(p->fh, "%s=%s\n", key, data);
+ fprintf(p->fh, "%s=%s\n", key, data?data:"");
free(key);
}
struct txt_writer_private *p = w->priv;
if (descr == NULL || strlen(descr) == 0) {
- fprintf(p->fh, "%s%s", (p->attrs > 0 ? ", " : " "), value);
+ fprintf(p->fh, "%s%s", (p->attrs > 0 ? ", " : " "), value?value:"(none)");
} else {
- fprintf(p->fh, "%s%s: %s", (p->attrs > 0 ? ", " : " "), descr, value);
+ fprintf(p->fh, "%s%s: %s", (p->attrs > 0 ? ", " : " "), descr, value?value:"(none)");
}
p->attrs++;
txt_data(struct writer *w, const char *data) {
struct txt_writer_private *p = w->priv;
char *nl, *begin;
- char *v = begin = strdup(data);
+ char *v = begin = data?strdup(data):NULL;
if (v == NULL) {
- fprintf(p->fh, " %s", data);
+ fprintf(p->fh, " %s", data?data:"(none)");
return;
}
void xml_attr(struct writer * w, const char * tag, const char * descr, const char * value ) {
struct xml_writer_private * p = w->priv;
- if (xmlTextWriterWriteFormatAttribute(p->xw, BAD_CAST tag, "%s", value) < 0)
- log_warnx("lldpctl", "cannot add attribute %s with value %s", tag, value);
+ if (xmlTextWriterWriteFormatAttribute(p->xw, BAD_CAST tag, "%s", value?value:"") < 0)
+ log_warnx("lldpctl", "cannot add attribute %s with value %s", tag, value?value:"(none)");
}
void xml_data(struct writer * w, const char * data) {
struct xml_writer_private * p = w->priv;
- if (xmlTextWriterWriteString(p->xw, BAD_CAST data) < 0 )
- log_warnx("lldpctl", "cannot add '%s' as data to element", data);
+ if (xmlTextWriterWriteString(p->xw, BAD_CAST (data?data:"")) < 0 )
+ log_warnx("lldpctl", "cannot add '%s' as data to element", data?data:"(none)");
}
void xml_end(struct writer * w) {
}
xmlFreeTextWriter(p->xw);
-
+
if ( ! failed )
xmlSaveFileEnc("-", p->doc, MY_ENCODING);