{
STRUCT_STAT *dumstat;
BOOL as_json = f == FNONE ? 1 : 0; /* We use 1 == first attribute, 2 == need closing array */
- char line_buf[75], *quot = as_json ? "\"" : "";
+ char line_buf[75], item_buf[32];
int line_len, j;
char *info_flags[] = {
for (line_len = 0, j = 0; ; j++) {
char *str = info_flags[j], *next_nfo = str ? info_flags[j+1] : NULL;
- int str_len = str && *str != '*' ? strlen(str) + (as_json ? 2 : 0) : 1000;
int need_comma = next_nfo && *next_nfo != '*' ? 1 : 0;
- if (line_len && line_len + 1 + str_len + need_comma >= (int)sizeof line_buf) {
+ int item_len;
+ if (!str || *str == '*')
+ item_len = 1000;
+ else if (as_json) {
+ char *space = strchr(str, ' ');
+ int is_no = space && strncmp(str, "no ", 3) == 0;
+ int is_bits = space && isDigit(str);
+ char *quot = space && !is_no && !is_bits ? "\"" : "";
+ char *item = space ? space + 1 : str;
+ char *val = !space ? "true" : is_no ? "false" : str;
+ int val_len = !space ? 4 : is_no ? 5 : space - str;
+ if (is_bits && (space = strchr(val, '-')) != NULL)
+ val_len = space - str;
+ item_len = snprintf(item_buf, sizeof item_buf,
+ " \"%s%s\": %s%.*s%s%s", item, is_bits ? "bits" : "",
+ quot, val_len, val, quot, need_comma ? "," : "");
+ if (is_bits)
+ item_buf[strlen(item)+2-1] = '_'; /* Turn the 's' into a '_' */
+ for (space = item; (space = strpbrk(space, " -")) != NULL; space++)
+ item_buf[space - item + 2] = '_';
+ } else
+ item_len = snprintf(item_buf, sizeof item_buf, " %s%s", str, need_comma ? "," : "");
+ if (line_len && line_len + item_len >= (int)sizeof line_buf) {
if (as_json)
printf(" %s\n", line_buf);
else
if (*str == '*') {
if (as_json) {
if (as_json == 2)
- printf(" ]");
+ printf(" }");
else
as_json = 2;
- printf(",\n \"%c%s\": [\n", toLower(str+1), str+2);
+ printf(",\n \"%c%s\": {\n", toLower(str+1), str+2);
} else
rprintf(f, "%s:\n", str+1);
- continue;
+ } else {
+ strlcpy(line_buf + line_len, item_buf, sizeof line_buf - line_len);
+ line_len += item_len;
}
- line_len += snprintf(line_buf+line_len, sizeof line_buf - line_len,
- " %s%s%s%s", quot, str, quot, need_comma ? "," : "");
}
if (as_json == 2)
- printf(" ]");
+ printf(" }");
}
static void output_nno_list(enum logcode f, const char *name, struct name_num_obj *nno)
char verbuf[32];
json_line("program", RSYNC_NAME);
json_line("version", rsync_version());
- snprintf(verbuf, sizeof verbuf, "%d.%d", PROTOCOL_VERSION, SUBPROTOCOL_VERSION);
+ (void)snprintf(verbuf, sizeof verbuf, "%d.%d", PROTOCOL_VERSION, SUBPROTOCOL_VERSION);
json_line("protocol", verbuf);
json_line("copyright", copyright);
json_line("url", url);
output_nno_list(f, "Daemon auth list", &valid_auth_checksums);
if (f == FNONE) {
- json_line("license", "GPL3");
+ json_line("license", "GPLv3");
json_line("caveat", "rsync comes with ABSOLUTELY NO WARRANTY");
printf("\n}\n");
+ fflush(stdout);
return;
}