Repository: trafficserver Updated Branches: refs/heads/master 8e0f81454 -> 8261460fc
TS-4060: add JSON support consistently for traffic_layout This closes #417. Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/8261460f Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/8261460f Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/8261460f Branch: refs/heads/master Commit: 8261460fc1e3483a3581d5318b14033f0c986b0e Parents: 8e0f814 Author: Leif Hedstrom <zw...@apache.org> Authored: Mon Dec 7 20:39:14 2015 -0700 Committer: James Peach <jpe...@apache.org> Committed: Tue Jan 12 16:59:43 2016 -0800 ---------------------------------------------------------------------- cmd/traffic_layout/traffic_layout.cc | 59 +++++++++++++++++++------------ 1 file changed, 36 insertions(+), 23 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafficserver/blob/8261460f/cmd/traffic_layout/traffic_layout.cc ---------------------------------------------------------------------- diff --git a/cmd/traffic_layout/traffic_layout.cc b/cmd/traffic_layout/traffic_layout.cc index b561132..f5dabac 100644 --- a/cmd/traffic_layout/traffic_layout.cc +++ b/cmd/traffic_layout/traffic_layout.cc @@ -126,38 +126,51 @@ produce_features(bool json) static void -print_var(const char *name, char *val) +print_var(const char *name, char *value, bool json, bool free = true, bool last = false) { - printf("%s: %s\n", name, val); - ats_free(val); + if (json) { + printf(" \"%s\": \"%s\"%s", name, value, last ? "\n" : ",\n"); + } else { + printf("%s: %s\n", name, value); + } + + if (free) { + ats_free(value); + } } static void -produce_layout() +produce_layout(bool json) { Layout::create(); RecProcessInit(RECM_STAND_ALONE, NULL /* diags */); LibRecordsConfigInit(); - printf("%s: %s\n", "PREFIX", Layout::get()->prefix); - print_var("BINDIR", RecConfigReadBinDir()); - print_var("SYSCONFDIR", RecConfigReadConfigDir()); - print_var("LIBDIR", Layout::get()->libdir); - print_var("LOGDIR", RecConfigReadLogDir()); - print_var("RUNTIMEDIR", RecConfigReadRuntimeDir()); - print_var("PLUGINDIR", RecConfigReadPrefixPath("proxy.config.plugin.plugin_dir")); - print_var("INCLUDEDIR", Layout::get()->includedir); - print_var("SNAPSHOTDIR", RecConfigReadSnapshotDir()); - - print_var("records.config", RecConfigReadConfigPath(NULL, REC_CONFIG_FILE)); - print_var("remap.config", RecConfigReadConfigPath("proxy.config.url_remap.filename")); - print_var("plugin.config", RecConfigReadConfigPath(NULL, "plugin.config")); - print_var("ssl_multicert.config", RecConfigReadConfigPath("proxy.config.ssl.server.multicert.filename")); - print_var("storage.config", RecConfigReadConfigPath("proxy.config.cache.storage_filename")); - print_var("hosting.config", RecConfigReadConfigPath("proxy.config.cache.hosting_filename")); - print_var("volume.config", RecConfigReadConfigPath("proxy.config.cache.volume_filename")); - print_var("ip_allow.config", RecConfigReadConfigPath("proxy.config.cache.ip_allow.filename")); + if (json) { + printf("{\n"); + } + print_var("PREFIX", Layout::get()->prefix, json, false); // Don't free this + print_var("BINDIR", RecConfigReadBinDir(), json); + print_var("SYSCONFDIR", RecConfigReadConfigDir(), json); + print_var("LIBDIR", Layout::get()->libdir, json, false); // Don't free this + print_var("LOGDIR", RecConfigReadLogDir(), json); + print_var("RUNTIMEDIR", RecConfigReadRuntimeDir(), json); + print_var("PLUGINDIR", RecConfigReadPrefixPath("proxy.config.plugin.plugin_dir"), json); + print_var("INCLUDEDIR", Layout::get()->includedir, json, false); // Dont' free this + print_var("SNAPSHOTDIR", RecConfigReadSnapshotDir(), json); + + print_var("records.config", RecConfigReadConfigPath(NULL, REC_CONFIG_FILE), json); + print_var("remap.config", RecConfigReadConfigPath("proxy.config.url_remap.filename"), json); + print_var("plugin.config", RecConfigReadConfigPath(NULL, "plugin.config"), json); + print_var("ssl_multicert.config", RecConfigReadConfigPath("proxy.config.ssl.server.multicert.filename"), json); + print_var("storage.config", RecConfigReadConfigPath("proxy.config.cache.storage_filename"), json); + print_var("hosting.config", RecConfigReadConfigPath("proxy.config.cache.hosting_filename"), json); + print_var("volume.config", RecConfigReadConfigPath("proxy.config.cache.volume_filename"), json); + print_var("ip_allow.config", RecConfigReadConfigPath("proxy.config.cache.ip_allow.filename"), json, true, true); + if (json) { + printf("}\n"); + } } int @@ -173,7 +186,7 @@ main(int /* argc ATS_UNUSED */, const char **argv) if (cl.features) { produce_features(0 != cl.json); } else { - produce_layout(); + produce_layout(0 != cl.json); } exit(0); }