TS-2349: Move traffic_shell to the cmd subdirectory

Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/775ad1dc
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/775ad1dc
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/775ad1dc

Branch: refs/heads/master
Commit: 775ad1dc4c8f005f0a23dee1531bfd0288eed444
Parents: c83e1d8
Author: James Peach <[email protected]>
Authored: Sat Nov 9 21:06:00 2013 -0800
Committer: James Peach <[email protected]>
Committed: Thu Nov 14 12:30:54 2013 -0800

----------------------------------------------------------------------
 cmd/Makefile.am                                 |    2 +-
 cmd/traffic_shell/CliCreateCommands.cc          |  318 ++
 cmd/traffic_shell/CliCreateCommands.h           |   39 +
 cmd/traffic_shell/CliDisplay.cc                 |  221 +
 cmd/traffic_shell/CliDisplay.h                  |   91 +
 cmd/traffic_shell/CliMgmtUtils.cc               |  625 +++
 cmd/traffic_shell/CliMgmtUtils.h                |  152 +
 cmd/traffic_shell/ConfigCmd.cc                  | 4626 ++++++++++++++++++
 cmd/traffic_shell/ConfigCmd.h                   |  865 ++++
 cmd/traffic_shell/ConfigUpgradeCmd.cc           |  634 +++
 cmd/traffic_shell/ConfigUpgradeCmd.h            |  252 +
 cmd/traffic_shell/ConfigUpgradeReadCmd.cc       |  498 ++
 cmd/traffic_shell/ConfigUpgradeWriteCmd.cc      |  517 ++
 cmd/traffic_shell/Makefile.am                   |   76 +
 cmd/traffic_shell/ShowCmd.cc                    | 2322 +++++++++
 cmd/traffic_shell/ShowCmd.h                     |  247 +
 cmd/traffic_shell/UtilCmds.cc                   |  196 +
 cmd/traffic_shell/UtilCmds.h                    |   94 +
 cmd/traffic_shell/cliAppInit.cc                 |  165 +
 cmd/traffic_shell/cliParseArg.cc                |  457 ++
 cmd/traffic_shell/cli_detailed_command_list.txt | 1623 ++++++
 cmd/traffic_shell/cli_feature_spec.txt          |  230 +
 cmd/traffic_shell/commandOptions.h              |   47 +
 cmd/traffic_shell/createArgument.cc             |  387 ++
 cmd/traffic_shell/createArgument.h              |  119 +
 cmd/traffic_shell/createCommand.cc              |  166 +
 cmd/traffic_shell/createCommand.h               |   59 +
 cmd/traffic_shell/definitions.h                 |   77 +
 cmd/traffic_shell/hashtable.cc                  |  219 +
 cmd/traffic_shell/hashtable.h                   |   45 +
 cmd/traffic_shell/processArgument.cc            |   57 +
 cmd/traffic_shell/traffic_shell.cc              |  113 +
 configure.ac                                    |    2 +-
 mgmt/Makefile.am                                |    2 +-
 mgmt/cli/CliCreateCommands.cc                   |  318 --
 mgmt/cli/CliCreateCommands.h                    |   39 -
 mgmt/cli/CliDisplay.cc                          |  221 -
 mgmt/cli/CliDisplay.h                           |   91 -
 mgmt/cli/CliMgmtUtils.cc                        |  625 ---
 mgmt/cli/CliMgmtUtils.h                         |  152 -
 mgmt/cli/ConfigCmd.cc                           | 4626 ------------------
 mgmt/cli/ConfigCmd.h                            |  865 ----
 mgmt/cli/ConfigUpgradeCmd.cc                    |  634 ---
 mgmt/cli/ConfigUpgradeCmd.h                     |  252 -
 mgmt/cli/ConfigUpgradeReadCmd.cc                |  498 --
 mgmt/cli/ConfigUpgradeWriteCmd.cc               |  517 --
 mgmt/cli/Makefile.am                            |   78 -
 mgmt/cli/ShowCmd.cc                             | 2322 ---------
 mgmt/cli/ShowCmd.h                              |  247 -
 mgmt/cli/UtilCmds.cc                            |  196 -
 mgmt/cli/UtilCmds.h                             |   94 -
 mgmt/cli/cliAppInit.cc                          |  165 -
 mgmt/cli/cliMain.cc                             |  113 -
 mgmt/cli/cliParseArg.cc                         |  457 --
 mgmt/cli/cli_detailed_command_list.txt          | 1623 ------
 mgmt/cli/cli_feature_spec.txt                   |  230 -
 mgmt/cli/commandOptions.h                       |   47 -
 mgmt/cli/createArgument.cc                      |  387 --
 mgmt/cli/createArgument.h                       |  119 -
 mgmt/cli/createCommand.cc                       |  166 -
 mgmt/cli/createCommand.h                        |   59 -
 mgmt/cli/definitions.h                          |   77 -
 mgmt/cli/hashtable.cc                           |  219 -
 mgmt/cli/hashtable.h                            |   45 -
 mgmt/cli/processArgument.cc                     |   57 -
 65 files changed, 15540 insertions(+), 15542 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/775ad1dc/cmd/Makefile.am
----------------------------------------------------------------------
diff --git a/cmd/Makefile.am b/cmd/Makefile.am
index 58a8a68..6a7d258 100644
--- a/cmd/Makefile.am
+++ b/cmd/Makefile.am
@@ -15,4 +15,4 @@
 #  See the License for the specific language governing permissions and
 #  limitations under the License.
 
-SUBDIRS = traffic_top traffic_cop traffic_line
+SUBDIRS = traffic_top traffic_cop traffic_line traffic_shell

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/775ad1dc/cmd/traffic_shell/CliCreateCommands.cc
----------------------------------------------------------------------
diff --git a/cmd/traffic_shell/CliCreateCommands.cc 
b/cmd/traffic_shell/CliCreateCommands.cc
new file mode 100644
index 0000000..5a22207
--- /dev/null
+++ b/cmd/traffic_shell/CliCreateCommands.cc
@@ -0,0 +1,318 @@
+/** @file
+
+  A brief file description
+
+  @section license License
+
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+ */
+
+/****************************************************************
+ * Filename: CliCreateCommands.cc
+ * Purpose: This file contains the CLI command creation function.
+ *
+ *
+ ****************************************************************/
+
+#include "CliCreateCommands.h"
+#include "createCommand.h"
+#include "ShowCmd.h"
+#include "ConfigCmd.h"
+#include "UtilCmds.h"
+#include "CliDisplay.h"
+#include "I_Layout.h"
+#include <stdlib.h>
+#include <unistd.h>
+#include <string>
+#include <sstream>
+#include <algorithm>
+
+////////////////////////////////////////////////////////////////
+// Called during Tcl_AppInit, this function creates the CLI commands
+//
+int
+CliCreateCommands()
+{
+  createCommand("config:root", Cmd_ConfigRoot, NULL, CLI_COMMAND_EXTERNAL, 
"config:root", "Switch to root user");
+
+  createCommand("show", Cmd_Show, NULL, CLI_COMMAND_EXTERNAL, "show", "Show 
command");
+
+  createCommand("config", Cmd_Config, NULL, CLI_COMMAND_EXTERNAL, "config", 
"Config command");
+
+  createCommand("show:status", Cmd_ShowStatus, NULL, CLI_COMMAND_EXTERNAL, 
"show:status", "Proxy status");
+
+  createCommand("show:version", Cmd_ShowVersion, NULL, CLI_COMMAND_EXTERNAL, 
"show:version", "Version information");
+
+
+  createCommand("show:security", Cmd_ShowSecurity, NULL, CLI_COMMAND_EXTERNAL, 
"show:security", "Security information");
+
+  createCommand("show:http", Cmd_ShowHttp, NULL, CLI_COMMAND_EXTERNAL, 
"show:http", "HTTP protocol configuration");
+
+  createCommand("show:icp", Cmd_ShowIcp, CmdArgs_ShowIcp, CLI_COMMAND_EXTERNAL,
+                "show:icp [peer]", "ICP protocol configuration");
+
+  createCommand("show:proxy", Cmd_ShowProxy, NULL, CLI_COMMAND_EXTERNAL, 
"show:proxy", "Proxy configuration");
+
+  createCommand("show:cache", Cmd_ShowCache, CmdArgs_ShowCache, 
CLI_COMMAND_EXTERNAL,
+                "show:cache [rules|storage]", "Cache configuration");
+
+  createCommand("show:virtual-ip", Cmd_ShowVirtualIp, NULL, 
CLI_COMMAND_EXTERNAL,
+                "show:virtual-ip", "Virtual-ip configuration");
+
+  createCommand("show:hostdb", Cmd_ShowHostDb, NULL, CLI_COMMAND_EXTERNAL,
+                "show:hostdb", "Host database configuration");
+
+  createCommand("show:dns-resolver", Cmd_ShowDnsResolver, NULL, 
CLI_COMMAND_EXTERNAL,
+                "show:dns-resolver", "DNS resolver configuration");
+
+  createCommand("show:logging", Cmd_ShowLogging, NULL, CLI_COMMAND_EXTERNAL, 
"show:logging", "Logging configuration");
+
+  createCommand("show:ssl", Cmd_ShowSsl, NULL, CLI_COMMAND_EXTERNAL, 
"show:ssl", "SSL configuration");
+
+  createCommand("show:parent", Cmd_ShowParents, CmdArgs_ShowParents, 
CLI_COMMAND_EXTERNAL,
+                "show:parent", "Parent configuration");
+
+  createCommand("show:remap", Cmd_ShowRemap, NULL, CLI_COMMAND_EXTERNAL, 
"show:remap", "Remap configuration");
+
+  createCommand("show:socks", Cmd_ShowSocks, CmdArgs_ShowSocks, 
CLI_COMMAND_EXTERNAL,
+                "show:socks", "SOCKS configuration");
+
+  createCommand("show:scheduled-update", Cmd_ShowScheduledUpdate, 
CmdArgs_ShowScheduledUpdate, CLI_COMMAND_EXTERNAL,
+                "show:scheduled-update", "Scheduled update configuration");
+
+  createCommand("show:proxy-stats", Cmd_ShowProxyStats, NULL, 
CLI_COMMAND_EXTERNAL,
+                "show:proxy-stats", "Proxy statistics");
+
+  createCommand("show:http-trans-stats", Cmd_ShowHttpTransStats, NULL, 
CLI_COMMAND_EXTERNAL,
+                "show:http-trans-stats", "HTTP transaction statistics");
+
+  createCommand("show:http-stats", Cmd_ShowHttpStats, NULL, 
CLI_COMMAND_EXTERNAL, "show:http-stats", "HTTP statistics");
+
+  createCommand("show:icp-stats", Cmd_ShowIcpStats, NULL, 
CLI_COMMAND_EXTERNAL, "show:icp-stats", "ICP statistics");
+
+  createCommand("show:cache-stats", Cmd_ShowCacheStats, NULL, 
CLI_COMMAND_EXTERNAL,
+                "show:cache-stats", "Cache statistics");
+
+  createCommand("show:hostdb-stats", Cmd_ShowHostDbStats, NULL, 
CLI_COMMAND_EXTERNAL,
+                "show:hostdb-stats", "Host database statistics");
+
+  createCommand("show:dns-stats", Cmd_ShowDnsStats, NULL, 
CLI_COMMAND_EXTERNAL, "show:dns-stats", "DNS statistics");
+
+  createCommand("show:logging-stats", Cmd_ShowLoggingStats, NULL, 
CLI_COMMAND_EXTERNAL,
+                "show:logging-stats", "Logging statistics");
+
+  createCommand("show:alarms", Cmd_ShowAlarms, NULL, CLI_COMMAND_EXTERNAL, 
"show:alarms", "Show active alarms");
+
+  createCommand("show:cluster", Cmd_ShowCluster, NULL, CLI_COMMAND_EXTERNAL,
+                "show:cluster", "Show Cluster Ports Settings");
+
+  createCommand("config:get", Cmd_ConfigGet, NULL, CLI_COMMAND_EXTERNAL,
+                "config:get <variable>", "Display a variable value");
+
+  createCommand("config:set", Cmd_ConfigSet, NULL, CLI_COMMAND_EXTERNAL,
+                "config:set <variable> <value>", "Set variable to specified 
value");
+
+  createCommand("config:name", Cmd_ConfigName, NULL, CLI_COMMAND_EXTERNAL,
+                "config:name <string>", "Set proxy name <string>");
+
+  createCommand("config:start", Cmd_ConfigStart, NULL, CLI_COMMAND_EXTERNAL, 
"config:start", "Start proxy software");
+
+  createCommand("config:stop", Cmd_ConfigStop, NULL, CLI_COMMAND_EXTERNAL, 
"config:stop", "Stop proxy software");
+
+  createCommand("config:hard-restart", Cmd_ConfigHardRestart, NULL, 
CLI_COMMAND_EXTERNAL,
+                "config:hard-restart", "Perform Hard Restart of all software 
components");
+
+  createCommand("config:restart", Cmd_ConfigRestart, CmdArgs_ConfigRestart, 
CLI_COMMAND_EXTERNAL,
+                "config:restart [cluster]", "Perform Restart of proxy 
software");
+
+  createCommand("config:ssl", Cmd_ConfigSsl, CmdArgs_ConfigSsl, 
CLI_COMMAND_EXTERNAL,
+                "config:ssl status <on | off>\n" "config:ssl ports <int>", 
"Configure ssl");
+
+  createCommand("config:parent", Cmd_ConfigParents, CmdArgs_ConfigParents, 
CLI_COMMAND_EXTERNAL,
+                "config:parent status <on | off>\n"
+                "config:parent name <parent>\n" "config:parent rules <url>", 
"Update parent configuration");
+
+
+  createCommand("config:remap", Cmd_ConfigRemap, NULL, CLI_COMMAND_EXTERNAL,
+                "config:remap <url>", "Update remap configuration file <url>");
+
+  createCommand("config:clock", Cmd_ConfigClock, CmdArgs_ConfigClock, 
CLI_COMMAND_EXTERNAL,
+                "config:clock date <mm/dd/yyyy>\n"
+                "config:clock time <hh:mm:ss>\n"
+                "config:clock timezone <number from list | list>", "Configure 
date, time, timezone");
+
+  createCommand("config:security", Cmd_ConfigSecurity, CmdArgs_ConfigSecurity, 
CLI_COMMAND_EXTERNAL,
+                "config:security <ip-allow | mgmt-allow | admin> 
<url-config-file>\n"
+                "config:security password", "Update security configuration");
+
+  createCommand("config:http", Cmd_ConfigHttp, CmdArgs_ConfigHttp, 
CLI_COMMAND_EXTERNAL,
+                "config:http status <on | off>\n"
+                "config:http <keep-alive-timeout-in | keep-alive-timeout-out> 
<seconds>\n"
+                "config:http <inactive-timeout-in | inactive-timeout-out> 
<seconds>\n"
+                "config:http <active-timeout-in | active-timeout-out> 
<seconds>\n"
+                "config:http <remove-from | remove-referer> <on | off>\n"
+                "config:http <remove-user | remove-cookie> <on | off>\n"
+                "config:http <remove-header> <string>\n"
+                "config:http <insert-ip | remove-ip> <on | off>\n"
+                "config:http proxy <fwd | rev | fwd-rev>", "Configure HTTP");
+
+  createCommand("config:icp", Cmd_ConfigIcp, CmdArgs_ConfigIcp, 
CLI_COMMAND_EXTERNAL,
+                "config:icp mode <disabled | receive | send-receive>\n"
+                "config:icp port <int>\n"
+                "config:icp multicast <on | off>\n"
+                "config:icp query-timeout <seconds>\n" "config:icp peers 
<url-config-file>", "Configure ICP");
+
+  createCommand("config:scheduled-update", Cmd_ConfigScheduledUpdate, 
CmdArgs_ConfigScheduledUpdate,
+                CLI_COMMAND_EXTERNAL,
+                "config:scheduled-update status <on | off>\n" 
"config:scheduled-update retry-count <int>\n"
+                "config:scheduled-update retry-interval <sec>\n" 
"config:scheduled-update max-concurrent <int>\n"
+                "config:scheduled-update force-immediate <on | off>\n"
+                "config:scheduled-update rules <url-config-file>", "Configure 
Scheduled Update");
+
+  createCommand("config:socks", Cmd_ConfigSocks, CmdArgs_ConfigSocks, 
CLI_COMMAND_EXTERNAL,
+                "config:socks status <on | off>\n"
+                "config:socks version <version>\n"
+                "config:socks default-servers <string>\n"
+                "config:socks accept <on | off>\n" "config:socks accept-port 
<int>", "Configure Socks");
+
+  createCommand("config:cache", Cmd_ConfigCache, CmdArgs_ConfigCache, 
CLI_COMMAND_EXTERNAL,
+                "config:cache <http> <on | off>\n"
+                "config:cache ignore-bypass <on | off>\n"
+                "config:cache <max-object-size | max-alternates> <int>\n"
+                "config:cache file <url-config-file>\n"
+                "config:cache freshness verify <when-expired | no-date | 
always | never>\n"
+                "config:cache freshness minimum <explicit | last-modified | 
nothing>\n"
+                "config:cache freshness no-expire-limit greater-than <sec> 
less-than <sec>\n"
+                "config:cache <dynamic | alternates> <on | off>\n"
+                "config:cache vary <text | images | other> <string>\n"
+                "config:cache cookies <none | all | images | non-text>\n" 
"config:cache clear", "Configure Cache");
+
+
+  createCommand("config:hostdb", Cmd_ConfigHostdb, CmdArgs_ConfigHostdb, 
CLI_COMMAND_EXTERNAL,
+                "config:hostdb <lookup-timeout | foreground-timeout> 
<seconds>\n"
+                "config:hostdb <background-timeout | invalid-host-timeout> 
<seconds>\n"
+                "config:hostdb <re-dns-on-reload> <on | off>\n" "config:hostdb 
clear", "Configure Host Database");
+
+  createCommand("config:logging", Cmd_ConfigLogging, CmdArgs_ConfigLogging, 
CLI_COMMAND_EXTERNAL,
+                "config:logging event <enabled | trans-only | error-only | 
disabled>\n"
+                "config:logging mgmt-directory <string>\n"
+                "config:logging <space-limit | space-headroom> <megabytes>\n"
+                "config:logging collation-status <inactive | host | 
send-standard |\n"
+                "                                 send-custom | send-all>\n"
+                "config:logging collation-host <string>\n"
+                "config:logging collation secret <string> tagged <on | off> 
orphan-limit <int>\n"
+                "config:logging format <squid | netscape-common | netscape-ext 
| netscape-ext2> <on | off>\n"
+                "               type <ascii | binary> file <string> header 
<string>\n"
+                "config:logging splitting <icp | http> <on | off>\n"
+                "config:logging custom <on | off> format <traditional | xml>\n"
+                "config:logging rolling <on | off> offset <hour> interval 
<hours>\n"
+                "               auto-delete <on | off>", "Configure Logging");
+
+
+  createCommand("config:dns", Cmd_ConfigDns, CmdArgs_ConfigDns, 
CLI_COMMAND_EXTERNAL,
+                "config:dns resolve-timeout <seconds>\n" "config:dns retries 
<int>", "Configure DNS");
+
+  createCommand("config:virtual-ip", Cmd_ConfigVirtualip, 
CmdArgs_ConfigVirtualip, CLI_COMMAND_EXTERNAL,
+                "config:virtual-ip status <on | off>\n"
+                "config:virtual-ip list\n"
+                "config:virtual-ip add <x.x.x.x> device <string> sub-intf 
<int>\n"
+                "config:virtual-ip delete <virtual ip number>", "Configure 
virtual-ip");
+
+  createCommand("config:alarms", Cmd_ConfigAlarm, CmdArgs_ConfigAlarm, 
CLI_COMMAND_EXTERNAL,
+                "config:alarms resolve-name <string>\n"
+                "config:alarms resolve-number <int>\n"
+                "config:alarms resolve-all\n"
+                "config:alarms notify <on | off>", "Resolve Alarms, Turn 
notification on/off");
+
+  createCommand("enable", Cmd_Enable, CmdArgs_Enable, CLI_COMMAND_EXTERNAL,
+                "enable \n" "enable status ", "Enable Restricted Commands");
+
+  createCommand("disable", Cmd_Disable, NULL, CLI_COMMAND_EXTERNAL, "disable", 
"Disable Restricted Commands");
+
+
+  createCommand("debug", DebugCmd, DebugCmdArgs, CLI_COMMAND_EXTERNAL,
+                "debug <on|off>", "Turn debugging print statements on/off");
+
+  createCommand("help", Cmd_Help, NULL, CLI_COMMAND_EXTERNAL,
+                "help [topic]", "Display online help");
+
+  return CLI_OK;
+}
+
+#if defined(__SUNPRO_CC)
+
+// Solaris doesn't like to link libstdc++ code. I don't have a system to test. 
Sorry.
+
+int
+Cmd_Help(ClientData, Tcl_Interp *, int, const char *[])
+{
+  return CMD_OK;
+}
+
+#else
+
+struct replace_colon
+{
+  char operator() (char c) const {
+    return (c == ':') ? '_' : c;
+  }
+};
+
+static int
+xsystem(const char * cmd)
+{
+  // Some versions of glibc declare system(3) with the warn_unused_result
+  // attribute. Pretend to use the return value so it will shut the hell up.
+  return system(cmd);
+}
+
+int
+Cmd_Help(ClientData /* clientData ATS_UNUSED */, Tcl_Interp * /* interp 
ATS_UNUSED */, int argc, const char *argv[])
+{
+  Cli_Debug("looking for online help in %s\n", Layout::get()->datadir);
+
+  for (int i = 1; i < argc; ++i) {
+    std::ostringstream  cmd;
+    std::string         topic(argv[i]);
+
+    // Replace ':' with '_' so we can find the right on-disk man page.
+    std::transform(topic.begin(), topic.end(), topic.begin(), replace_colon());
+
+    // Check whether we have the man page on disk before we pass any user input
+    // to the shell via system(3).
+    cmd << Layout::get()->datadir << "/trafficshell/" << topic << ".1";
+    if (access(cmd.str().c_str(), R_OK) != 0) {
+      Cli_Debug("missing %s\n", cmd.str().c_str());
+      continue;
+    }
+
+    cmd.clear();
+    cmd.seekp(std::ios_base::beg);
+
+    cmd << "man "
+      << Layout::get()->datadir << "/trafficshell/" << topic << ".1";
+
+    Cli_Debug("%s\n", cmd.str().c_str());
+    xsystem(cmd.str().c_str());
+  }
+
+  return CMD_OK;
+}
+
+#endif  /* __SUNPRO_C */
+
+// vim: set ts=2 sw=2 et :

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/775ad1dc/cmd/traffic_shell/CliCreateCommands.h
----------------------------------------------------------------------
diff --git a/cmd/traffic_shell/CliCreateCommands.h 
b/cmd/traffic_shell/CliCreateCommands.h
new file mode 100644
index 0000000..da49ae7
--- /dev/null
+++ b/cmd/traffic_shell/CliCreateCommands.h
@@ -0,0 +1,39 @@
+/** @file
+
+  A brief file description
+
+  @section license License
+
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+ */
+
+/****************************************************************
+ * Filename: CliCreateCommands.h
+ * Purpose: This file contains the CLI command creation function.
+ *
+ *
+ ****************************************************************/
+
+#ifndef __CLI_CREATE_COMMANDS_H__
+#define __CLI_CREATE_COMMANDS_H__
+
+////////////////////////////////////////////////////////////////
+// Called during Tcl_AppInit, this function creates generic the CLI commands
+//
+int CliCreateCommands();
+
+#endif // __CLI_CREATE_COMMANDS_H__

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/775ad1dc/cmd/traffic_shell/CliDisplay.cc
----------------------------------------------------------------------
diff --git a/cmd/traffic_shell/CliDisplay.cc b/cmd/traffic_shell/CliDisplay.cc
new file mode 100644
index 0000000..74dda07
--- /dev/null
+++ b/cmd/traffic_shell/CliDisplay.cc
@@ -0,0 +1,221 @@
+/** @file
+
+  Implementation of CliDisplay routines for the use of TB
+
+  @section license License
+
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+ */
+
+
+#include "libts.h"
+#include "CliDisplay.h"
+#include "definitions.h"
+#include <string.h>
+
+
+#define BUF_SIZE 1024
+
+extern Tcl_Interp *interp;
+static CliPrintLevelT CliPrintLevel = CLI_PRINT_DEFAULT;
+
+int CliDisplayPrintf = 0;
+
+/*****************************************************************
+ * Display one of the predefined error messages.
+ */
+int
+Cli_Error(const char *errString, ...)
+{
+  char buffer[BUF_SIZE];
+
+  va_list ap;
+  va_start(ap, errString);
+  // XXX/amitk ugh. easy buffer overrun.
+  // why isn't vsnprintf always available??
+  vsprintf(buffer, errString, ap);
+  va_end(ap);
+
+  // fix for BZ27769
+  //   libtrafficshell.a standalone uses Tcl_AppendResult
+  //   traffic_shell binary uses printf
+  if (CliDisplayPrintf) {
+    printf("%s", buffer);
+  } else {
+    Tcl_AppendResult(interp, buffer, (char *) NULL);
+  }
+
+  return CLI_OK;
+}
+
+/****************************************************************
+ * Set print level
+ *   level = CLI_PRINT_DEFAULT (Cli_Printf)
+ *   level = CLI_PRINT_INFO    (Cli_Printf, Cli_Info)
+ *   level = CLI_PRINT_DEBUG   (Cli_Printf, Cli_Debug)
+ *   level = CLI_PRINT_INFO | CLI_PRINT_DEBUG  (Cli_Printf, Cli_Debug, 
Cli_Info)
+ */
+int
+Cli_SetPrintLevel(CliPrintLevelT level)
+{
+  CliPrintLevel = level;
+  return CLI_OK;
+
+}
+
+/****************************************************************
+ * return the current print level
+ */
+CliPrintLevelT
+Cli_GetPrintLevel()
+{
+  return CliPrintLevel;
+}
+
+/****************************************************************
+ * Display string
+ */
+int
+Cli_Printf(const char *string, ...)
+{
+  char buffer[BUF_SIZE];
+  va_list ap;
+
+  va_start(ap, string);
+  vsprintf(buffer, string, ap);
+  va_end(ap);
+
+  // fix for BZ27769
+  //   libtrafficshell.a standalone uses Tcl_AppendResult
+  //   traffic_shell binary uses printf
+  if (CliDisplayPrintf) {
+    printf("%s", buffer);
+  } else {
+    Tcl_AppendResult(interp, buffer, (char *) NULL);
+  }
+
+  return CLI_OK;
+}
+
+/****************************************************************
+ * Display informative message
+ */
+int
+Cli_Info(const char *string, ...)
+{
+  char buffer[BUF_SIZE];
+  va_list ap;
+
+  va_start(ap, string);
+  if (CliPrintLevel & CLI_PRINT_INFO) {
+    vsprintf(buffer, string, ap);
+
+    // fix for BZ27769
+    //   libtrafficshell.a standalone uses Tcl_AppendResult
+    //   traffic_shell binary uses printf
+    if (CliDisplayPrintf) {
+      printf("%s", buffer);
+    } else {
+      Tcl_AppendResult(interp, buffer, (char *) NULL);
+    }
+  }
+  va_end(ap);
+
+  return CLI_OK;
+}
+
+
+/****************************************************************
+ * Display debug statement
+ */
+int
+Cli_Debug(const char *string, ...)
+{
+  char buffer[BUF_SIZE];
+  va_list ap;
+
+  // allocate enough room for "debug: " at beginning of string
+  const size_t new_string_size = strlen(string) + 8;
+  char *new_string = (char *)alloca(new_string_size);
+  ink_strlcpy(new_string, "debug: ", new_string_size);
+  ink_strlcat(new_string, string, new_string_size );
+
+  va_start(ap, string);
+  if (CliPrintLevel & CLI_PRINT_DEBUG) {
+    vsprintf(buffer, new_string, ap);
+
+    // fix for BZ27769
+    //   libtrafficshell.a standalone uses Tcl_AppendResult
+    //   traffic_shell binary uses printf
+    if (CliDisplayPrintf) {
+      printf("%s", buffer);
+    } else {
+      Tcl_AppendResult(interp, buffer, (char *) NULL);
+    }
+  }
+  va_end(ap);
+
+  return CLI_OK;
+}
+
+int
+Cli_PrintEnable(const char *string, int flag)
+{
+  if (flag == 0)
+    Cli_Printf("%soff\n", string);
+  else if (flag == 1)
+    Cli_Printf("%son\n", string);
+  else {
+    Cli_Debug(ERR_INVALID_PARAMETER);
+    return CLI_ERROR;
+  }
+
+  return CLI_OK;
+}
+
+int
+Cli_PrintOnOff(int flag)
+{
+  switch (flag) {
+  case 0:
+    Cli_Printf("off\n");
+    break;
+  case 1:
+    Cli_Printf("on\n");
+    break;
+  default:
+    Cli_Printf("?\n");
+    break;
+  }
+  return CLI_OK;
+}
+
+int
+Cli_PrintArg(int arg_index, const cli_parsedArgInfo * argtable)
+{
+
+
+
+  if (arg_index >= 0) {
+    Cli_Debug("%d %d %s\n", argtable[arg_index].parsed_args,
+              argtable[arg_index].arg_int, argtable[arg_index].arg_string);
+    return CLI_OK;
+  }
+  return CLI_ERROR;
+}
+
+#undef BUF_SIZE

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/775ad1dc/cmd/traffic_shell/CliDisplay.h
----------------------------------------------------------------------
diff --git a/cmd/traffic_shell/CliDisplay.h b/cmd/traffic_shell/CliDisplay.h
new file mode 100644
index 0000000..be47db4
--- /dev/null
+++ b/cmd/traffic_shell/CliDisplay.h
@@ -0,0 +1,91 @@
+/** @file
+
+  A brief file description
+
+  @section license License
+
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+ */
+
+/****************************************************************
+ * Filename: CliDisplay.h
+ * Purpose: This file contains the CLI display routines.
+ *
+ *
+ ****************************************************************/
+
+#include <stdarg.h>
+#include <stdio.h>
+#include "createArgument.h"
+
+#ifndef __CLI_ERROR_HANDLE_H__
+#define __CLI_ERROR_HANDLE_H__
+
+/* CLI print levels
+ */
+typedef enum
+{
+  CLI_PRINT_DEFAULT = 0x0,
+  CLI_PRINT_INFO = 0x2,
+  CLI_PRINT_DEBUG = 0x4
+} CliPrintLevelT;
+
+/* All possible error strings are defined below.
+ *    In the future, this could be changed to a message_id/lookup mechanism.
+ */
+
+#define ERR_RECORD_GET         "INKRecordGet: failed to retrieve %s\n"
+#define ERR_RECORD_GET_INT     "INKRecordGetInt: failed to retrieve %s\n"
+#define ERR_RECORD_GET_COUNTER "INKRecordGetCounter: failed to retrieve %s\n"
+#define ERR_RECORD_GET_FLOAT   "INKRecordGetFloat: failed to retrieve %s\n"
+#define ERR_RECORD_GET_STRING  "INKRecordGetString: failed to retrieve %s\n"
+#define ERR_RECORD_SET         "INKRecordSet: failed to set %s value %s\n"
+#define ERR_RECORD_SET_INT     "INKRecordSetInt: failed to set %s value %d\n"
+#define ERR_RECORD_SET_FLOAT   "INKRecordSetFloat: failed to set %s value %f\n"
+#define ERR_RECORD_SET_STRING  "INKRecordSetString: failed to set %s value 
%s\n"
+
+
+#define ERR_COMMAND_SYNTAX    "\nCommand Syntax: \n%s\n\n"
+#define ERR_REQ_ACTION_UNDEF  "Undefined Action Required before Changes Take 
Effect\n"
+#define ERR_TOO_MANY_ARGS     "\nToo many arguments specified.\n"
+
+#define ERR_INVALID_COMMAND   "wrong # args: should be \n"
+#define ERR_INVALID_PARAMETER "Invalid Parameter\n"
+#define ERR_MISSING_PARAMETER "Missing Parameter\n"
+
+#define ERR_PROXY_STATE_ALREADY "Proxy is already %s\n" // on/off
+#define ERR_PROXY_STATE_SET     "Unable to set Proxy %s\n"      // on/off
+
+#define ERR_CONFIG_FILE_READ  "Error Reading Rules File %d\n"
+#define ERR_CONFIG_FILE_WRITE "Error Writing Rules File %d\n"
+#define ERR_READ_FROM_URL     "Error Reading File from URL %s\n"
+
+#define ERR_ALARM_LIST        "Error Retrieving Alarm List\n"
+#define ERR_ALARM_STATUS      "Error Determining Active/Inactive status of 
alarm %s\n"
+#define ERR_ALARM_RESOLVE_INACTIVE "Error: Attempt to resolve inactive alarm 
%s\n"
+#define ERR_ALARM_RESOLVE     "Errur: Unable to resolve alarm %s\n"
+#define ERR_ALARM_RESOLVE_NUMBER "Error: Alarm number non-existent\n"
+
+int Cli_Error(const char *errString, ...);
+int Cli_SetPrintLevel(CliPrintLevelT level);
+CliPrintLevelT Cli_GetPrintLevel();
+int Cli_Printf(const char *string, ...);
+int Cli_Debug(const char *string, ...);
+int Cli_PrintEnable(const char *string, int flag);
+int Cli_PrintOnOff(int flag);
+int Cli_PrintArg(int arg_index, const cli_parsedArgInfo * argtable);
+#endif // __CLI_ERROR_HANDLE_H__

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/775ad1dc/cmd/traffic_shell/CliMgmtUtils.cc
----------------------------------------------------------------------
diff --git a/cmd/traffic_shell/CliMgmtUtils.cc 
b/cmd/traffic_shell/CliMgmtUtils.cc
new file mode 100644
index 0000000..222e334
--- /dev/null
+++ b/cmd/traffic_shell/CliMgmtUtils.cc
@@ -0,0 +1,625 @@
+/** @file
+
+  This file contains various utility functions which call the TSMgmtAPI.
+
+  @section license License
+
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+ */
+
+
+#include "libts.h"
+#include "I_Layout.h"
+#include <stdlib.h>
+#include <unistd.h>
+#include "CliMgmtUtils.h"
+#include "CliDisplay.h"
+#include "ink_resource.h"
+#include "definitions.h"
+#include "ConfigCmd.h"
+
+
+void Cli_DisplayMgmtAPI_Error(TSError status);
+
+// Get a records.config variable by name
+TSError
+Cli_RecordGet(const char *rec_name, TSRecordEle * rec_val)
+{
+  TSError status;
+  if ((status = TSRecordGet((char *) rec_name, rec_val))) {
+    Cli_Debug(ERR_RECORD_GET, rec_name);
+    Cli_DisplayMgmtAPI_Error(status);
+  }
+  return status;
+}
+
+// Get an integer type records.config variable
+TSError
+Cli_RecordGetInt(const char *rec_name, TSInt * int_val)
+{
+  TSError status;
+  if ((status = TSRecordGetInt(rec_name, int_val))) {
+    Cli_Debug(ERR_RECORD_GET_INT, rec_name);
+    Cli_DisplayMgmtAPI_Error(status);
+  }
+  return status;
+}
+
+// Get an counter type records.config variable
+TSError
+Cli_RecordGetCounter(const char *rec_name, TSCounter * ctr_val)
+{
+  TSError status;
+  if ((status = TSRecordGetCounter(rec_name, ctr_val))) {
+    Cli_Debug(ERR_RECORD_GET_COUNTER, rec_name);
+    Cli_DisplayMgmtAPI_Error(status);
+  }
+  return status;
+}
+
+// Get a float type records.config variable
+TSError
+Cli_RecordGetFloat(const char *rec_name, TSFloat * float_val)
+{
+  TSError status;
+  if ((status = TSRecordGetFloat(rec_name, float_val))) {
+    Cli_Debug(ERR_RECORD_GET_FLOAT, rec_name);
+    Cli_DisplayMgmtAPI_Error(status);
+  }
+  return status;
+}
+
+// Get a string type records.config variable
+TSError
+Cli_RecordGetString(const char *rec_name, char **string_val)
+{
+  TSError status;
+  if ((status = TSRecordGetString(rec_name, string_val))) {
+    Cli_Debug(ERR_RECORD_GET_STRING, rec_name);
+    Cli_DisplayMgmtAPI_Error(status);
+  }
+  return status;
+}
+
+// Use a string to set a records.config variable
+TSError
+Cli_RecordSet(const char *rec_name, const char *rec_value, TSActionNeedT * 
action_need)
+{
+  TSError status;
+  if ((status = TSRecordSet((char *) rec_name, (TSString) rec_value, 
action_need))) {
+    Cli_Debug(ERR_RECORD_SET, rec_name, rec_value);
+    Cli_DisplayMgmtAPI_Error(status);
+  }
+  return status;
+}
+
+// Set an integer type records.config variable
+TSError
+Cli_RecordSetInt(const char *rec_name, TSInt int_val, TSActionNeedT * 
action_need)
+{
+  TSError status;
+  if ((status = TSRecordSetInt(rec_name, int_val, action_need))) {
+    Cli_Debug(ERR_RECORD_SET_INT, rec_name, int_val);
+    Cli_DisplayMgmtAPI_Error(status);
+  }
+  return status;
+}
+
+// Set a float type records.config variable
+TSError
+Cli_RecordSetFloat(const char *rec_name, TSFloat float_val, TSActionNeedT * 
action_need)
+{
+  TSError status;
+  if ((status = TSRecordSetFloat(rec_name, float_val, action_need))) {
+    Cli_Debug(ERR_RECORD_SET_FLOAT, rec_name, float_val);
+    Cli_DisplayMgmtAPI_Error(status);
+  }
+  return status;
+}
+
+
+// Set a string type records.config variable
+TSError
+Cli_RecordSetString(const char *rec_name, TSString str_val, TSActionNeedT * 
action_need)
+{
+  TSError status;
+  if ((status = TSRecordSetString(rec_name, str_val, action_need))) {
+    Cli_Debug(ERR_RECORD_SET_STRING, rec_name, str_val);
+    Cli_DisplayMgmtAPI_Error(status);
+  }
+  return status;
+}
+
+void
+Cli_DisplayMgmtAPI_Error(TSError status)
+{
+  switch (status) {
+  case TS_ERR_OKAY:           // do nothing
+    break;
+  case TS_ERR_READ_FILE:
+    Cli_Printf("\nERROR: Unable to read config file.\n\n");
+    break;
+  case TS_ERR_WRITE_FILE:
+    Cli_Printf("\nERROR: Unable to write config file.\n\n");
+    break;
+  case TS_ERR_PARSE_CONFIG_RULE:
+    Cli_Printf("\nERROR: Unable to parse config file.\n\n");
+    break;
+  case TS_ERR_INVALID_CONFIG_RULE:
+    Cli_Printf("\nERROR: Invalid Configuration Rule in config file.\n\n");
+    break;
+  case TS_ERR_NET_ESTABLISH:
+    Cli_Printf("\nERROR: Unable to establish connection to traffic_manager.\n"
+               "       Ability to make configuration changes depends on 
traffic_manager.\n");
+    break;
+  case TS_ERR_NET_READ:
+    Cli_Printf("\nERROR: Unable to read data from traffic_manager.\n"
+               "       Ability to monitor the system changes depends on 
traffic_manager.\n");
+    break;
+  case TS_ERR_NET_WRITE:
+    Cli_Printf("\nERROR: Unable to write configuration data to 
traffic_manager.\n"
+               "       Ability to make configuration changes depends on 
traffic_manager.\n");
+    break;
+  case TS_ERR_NET_EOF:
+    Cli_Printf("\nERROR: Unexpected EOF while communicating with 
traffic_manager.\n"
+               "       Ability to make configuration changes depends on 
traffic_manager.\n");
+    break;
+  case TS_ERR_NET_TIMEOUT:
+    Cli_Printf("\nERROR: Timed-out while communicating with traffic_manager.\n"
+               "       Ability to make configuration changes depends on 
traffic_manager.\n");
+    break;
+  case TS_ERR_SYS_CALL:
+    Cli_Printf("\nERROR: Internal System Call failed.\n\n");
+    break;
+  case TS_ERR_PARAMS:
+    Cli_Printf("\nERROR: Invalid parameters passed to a function.\n\n");
+    break;
+  case TS_ERR_FAIL:
+    Cli_Printf("\nERROR: Invalid parameter specified.\n" "       Check 
parameters for correct syntax and type.\n\n");
+    break;
+  default:
+    Cli_Printf("\nERROR: Undocumented Error. Status = %d.\n\n", status);
+    break;
+  }
+}
+
+// Retrieve and display contents of a rules file
+TSError
+Cli_DisplayRules(TSFileNameT fname)
+{
+  TSError status;
+  char *text;
+  int size = 0, version = 0;
+
+  if ((status = TSConfigFileRead(fname, &text, &size, &version))) {
+    Cli_Debug(ERR_CONFIG_FILE_READ, fname);
+    Cli_DisplayMgmtAPI_Error(status);
+  } else {
+    if (size) {
+      // Fix TSqa12220: use printf directly since Cli_Printf may
+      // not allocate enough buffer space to display the file contents
+      puts(text);
+      ats_free(text);
+    } else {
+      Cli_Printf("no rules\n");
+    }
+  }
+
+  return status;
+}
+
+// Retrieve and use config file from remote URL
+TSError
+Cli_SetConfigFileFromUrl(TSFileNameT file, const char *url)
+{
+  char *buf;
+  int size = 0;
+  int version = -1;
+  TSError status;
+
+  Cli_Debug("Cli_SetConfigFileFromUrl: file %d url %s\n", file, url);
+
+  // read config file from Url
+  if ((status = TSReadFromUrl((char *) url, NULL, NULL, &buf, &size))) {
+    Cli_Debug(ERR_READ_FROM_URL, url);
+    Cli_DisplayMgmtAPI_Error(status);
+    return status;
+  }
+
+  Cli_Debug("Cli_SetConfigFileFromUrl: size %d version %d\n", size, version);
+
+  Cli_Debug("Cli_SetConfigFileFromUrl: buf\n%s\n", buf);
+
+  // write config file
+  if ((status = TSConfigFileWrite(file, buf, size, version))) {
+    Cli_Debug(ERR_CONFIG_FILE_WRITE, file);
+    Cli_DisplayMgmtAPI_Error(status);
+    if (size)
+      ats_free(buf);
+    return status;
+  }
+
+  if (size)
+    ats_free(buf);
+
+  Cli_Printf("Successfully updated config file.\n");
+
+  return status;
+}
+
+// enable recent configuration changes by performing the action specified
+// by the action_need value
+TSError
+Cli_ConfigEnactChanges(TSActionNeedT action_need)
+{
+  TSError status;
+
+  Cli_Debug("Cli_ConfigEnactChanges: action_need %d\n", action_need);
+
+  switch (action_need) {
+  case TS_ACTION_SHUTDOWN:
+    Cli_Debug("Cli_ConfigEnactChanges: TS_ACTION_SHUTDOWN\n");
+    Cli_Printf("\nHard Restart required.\n"
+               "  Change will take effect after next Hard Restart.\n"
+               "  Use the \"config:hard-restart\" command to restart 
now.\n\n");
+    break;
+
+  case TS_ACTION_RESTART:
+    Cli_Debug("Cli_ConfigEnactChanges: TS_ACTION_RESTART\n");
+    Cli_Printf("\nRestart required.\n"
+               "  Change will take effect after next Restart.\n"
+               "  Use the \"config:restart\" command to restart now.\n\n");
+    break;
+
+  case TS_ACTION_DYNAMIC:
+    Cli_Debug("Cli_ConfigEnactChanges: TS_ACTION_DYNAMIC\n");
+    // no additional action required
+    break;
+
+  case TS_ACTION_RECONFIGURE:
+    Cli_Debug("Cli_ConfigEnactChanges: TS_ACTION_RECONFIGURE\n");
+    status = TSActionDo(TS_ACTION_RECONFIGURE);
+    if (status) {
+      Cli_Error("\nERROR %d: Failed to reread configuration files.\n\n", 
status);
+      return TS_ERR_FAIL;
+    }
+    break;
+
+  default:
+    Cli_Debug("  Status Message #%d\n", action_need);
+    Cli_Error("\nYou may need to use the \"config:hard-restart\" command\n" 
"to enable this configuration change.\n\n");
+    return TS_ERR_OKAY;
+  }
+
+  return TS_ERR_OKAY;
+}
+
+// evaluate "stringval" and return 1 if "on", otherwise 0
+int
+Cli_EvalOnOffString(char *stringval)
+{
+  if (strcmp(stringval, "on") == 0) {
+    return 1;
+  }
+  if (strcmp(stringval, "off") == 0) {
+    return 0;
+  }
+
+  return -1;
+}
+
+////////////////////////////////////////////////////////////////
+// Cli_RecordOnOff_Action
+//
+// used for records.config INT variables when 1 = on, 0 = off
+//
+// action = RECORD_GET retrieve and display the variable
+//          RECORD_SET set the variable
+//
+// record = variable in records.config
+//
+// on_off = "on" mean 1, "off" mean 0
+//
+int
+Cli_RecordOnOff_Action(int action, const char *record, const char *on_off)
+{
+  TSActionNeedT action_need;
+  TSError status;
+  TSInt int_val;
+
+  switch (action) {
+  case RECORD_SET:
+    if (on_off) {
+      if (!strcasecmp(on_off, "on")) {
+        int_val = 1;
+      } else if (!strcasecmp(on_off, "off")) {
+        int_val = 0;
+      } else {
+        Cli_Error("Expected \"on\" or \"off\" but got %s\n", on_off);
+        return CLI_ERROR;
+      }
+    } else {
+      Cli_Error("Expected <on | off> but got nothing.\n");
+      return CLI_ERROR;
+    }
+    status = Cli_RecordSetInt(record, int_val, &action_need);
+    if (status != TS_ERR_OKAY) {
+      return status;
+    }
+    return (Cli_ConfigEnactChanges(action_need));
+
+  case RECORD_GET:
+    int_val = -1;
+    status = Cli_RecordGetInt(record, &int_val);
+    Cli_PrintEnable("", int_val);
+    return CLI_OK;
+  }
+  return CLI_ERROR;
+}
+
+////////////////////////////////////////////////////////////////
+// Cli_RecordInt_Action
+//
+// used for records.config INT variables
+//
+// action = RECORD_GET retrieve and display the variable
+//          RECORD_SET set the variable
+//
+// record = variable in records.config
+//
+// value = the integer value used by RECORD_SET
+//
+int
+Cli_RecordInt_Action(int action, const char *record, int value)
+{
+  switch (action) {
+  case RECORD_SET:
+    {
+      TSActionNeedT action_need = TS_ACTION_UNDEFINED;
+      TSError status = Cli_RecordSetInt(record, value, &action_need);
+
+      if (status) {
+        return status;
+      }
+      return (Cli_ConfigEnactChanges(action_need));
+    }
+  case RECORD_GET:
+    {
+      TSInt value_in = -1;
+      TSError status = Cli_RecordGetInt(record, &value_in);
+
+      if (status) {
+        return status;
+      }
+      Cli_Printf("%d\n", value_in);
+      return CLI_OK;
+    }
+  }
+  return CLI_ERROR;
+}
+
+////////////////////////////////////////////////////////////////
+// Cli_RecordHostname_Action
+//
+// used for records.config STRING variables
+// performs checking to see if string is a valid fully qualified hostname
+//
+// action = RECORD_GET retrieve and display the variable
+//          RECORD_SET set the variable
+//
+// record = variable in records.config
+//
+// hostname = string to set
+//
+int
+Cli_RecordHostname_Action(int action, char *record, char *hostname)
+{
+  TSError status;
+  TSActionNeedT action_need = TS_ACTION_UNDEFINED;
+  TSString str_val = NULL;
+
+  switch (action) {
+  case RECORD_SET:
+    if (IsValidFQHostname(hostname) == CLI_OK) {
+      status = Cli_RecordSetString(record, (TSString) hostname, &action_need);
+
+      if (status) {
+        return status;
+      }
+      return (Cli_ConfigEnactChanges(action_need));
+    }
+    Cli_Error("ERROR: %s is an invalid name.\n", hostname);
+    return CLI_ERROR;
+
+  case RECORD_GET:
+    status = Cli_RecordGetString(record, &str_val);
+    if (status) {
+      return status;
+    }
+    if (str_val)
+      Cli_Printf("%s\n", str_val);
+    else
+      Cli_Printf("none\n");
+    return CLI_OK;
+  }
+  return CLI_ERROR;
+}
+
+////////////////////////////////////////////////////////////////
+// Cli_RecordString_Action
+//
+// used for records.config STRING variables
+//
+// action = RECORD_GET retrieve and display the variable
+//          RECORD_SET set the variable
+//
+// record = variable in records.config
+//
+// string_val = string to set
+//
+int
+Cli_RecordString_Action(int action, const char *record, char *string_val)
+{
+  TSError status;
+  TSActionNeedT action_need = TS_ACTION_UNDEFINED;
+  TSString str_val = NULL;
+
+  switch (action) {
+  case RECORD_SET:
+    status = Cli_RecordSetString(record, (TSString) string_val, &action_need);
+
+    if (status) {
+      return status;
+    }
+    return (Cli_ConfigEnactChanges(action_need));
+
+  case RECORD_GET:
+    status = Cli_RecordGetString(record, &str_val);
+    if (status) {
+      return status;
+    }
+    if (str_val)
+      Cli_Printf("%s\n", str_val);
+    else
+      Cli_Printf("none\n");
+    return CLI_OK;
+  }
+  return CLI_ERROR;
+}
+
+////////////////////////////////////////////////////////////////
+// Cli_ConfigFileURL_Action
+//
+// used for config files other than records.config
+//
+// file = integer which specifies config file
+//
+// filename = config file name to display
+//
+// url = if non-NULL, update the file using contents of URL
+//
+int
+Cli_ConfigFileURL_Action(TSFileNameT file, const char *filename, const char 
*url)
+{
+  TSError status;
+  // Retrieve  file from url
+
+  if (url == NULL) {
+    Cli_Printf("%s File Rules\n", filename);
+    Cli_Printf("----------------------------\n");
+    status = Cli_DisplayRules(file);
+    return status;
+  }
+  Cli_Printf("Retrieve and Install %s file from url %s\n", filename, url);
+
+  status = Cli_SetConfigFileFromUrl(file, url);
+
+  return (status);
+}
+
+int
+cliCheckIfEnabled(const char *command)
+{
+  if (enable_restricted_commands == false) {
+    Cli_Error("\n%s is a restricted command only accessible from enable 
mode\n\n", command);
+    return CLI_ERROR;
+  }
+  return CLI_OK;
+}
+
+int
+GetTSDirectory(char *ts_path, size_t ts_path_len)
+{
+
+  ink_strlcpy(ts_path, Layout::get()->bindir, ts_path_len);
+  if (access(ts_path, R_OK) == -1) {
+    Cli_Error("unable to access() '%s': %d, %s\n",
+              ts_path, errno, strerror(errno));
+    Cli_Error(" Please set correct path in env variable TS_ROOT \n");
+    return -1;
+  }
+
+  return 0;
+}
+
+int
+StopTrafficServer()
+{
+  char ts_path[PATH_NAME_MAX + 1];
+  char stop_ts[1024];
+
+  if (GetTSDirectory(ts_path,sizeof(ts_path))) {
+    return CLI_ERROR;
+  }
+  snprintf(stop_ts, sizeof(stop_ts), "%s/stop_traffic_server", ts_path);
+  if (system(stop_ts) == -1)
+    return CLI_ERROR;
+
+  return 0;
+}
+
+int
+StartTrafficServer()
+{
+  char ts_path[PATH_NAME_MAX + 1];
+  char start_ts[1024];
+
+  if (GetTSDirectory(ts_path,sizeof(ts_path))) {
+    return CLI_ERROR;
+  }
+  // root user should start_traffic_shell as inktomi user
+  if (getuid() == 0) {
+    snprintf(start_ts, sizeof(start_ts), "/bin/su - inktomi -c 
\"%s/start_traffic_server\"", ts_path);
+  } else {
+    snprintf(start_ts, sizeof(start_ts), "%s/start_traffic_server", ts_path);
+  }
+  if (system(start_ts) == -1)
+    return CLI_ERROR;
+
+  return 0;
+}
+
+int
+Cli_CheckPluginStatus(TSString plugin)
+{
+
+  int match = 0;
+  TSCfgContext ctx;
+  TSCfgIterState ctx_state;
+  TSPluginEle *ele;
+
+  ctx = TSCfgContextCreate(TS_FNAME_PLUGIN);
+  if (TSCfgContextGet(ctx) != TS_ERR_OKAY) {
+    printf("ERROR READING FILE\n");
+  }
+  ele = (TSPluginEle *) TSCfgContextGetFirst(ctx, &ctx_state);
+
+  while (ele) {
+    if (!strcasecmp(plugin, ele->name)) {
+      match = 1;
+      break;
+    }
+    ele = (TSPluginEle *) TSCfgContextGetNext(ctx, &ctx_state);
+  }
+
+  if (match) {
+    return CLI_OK;
+  } else {
+    return CLI_ERROR;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/775ad1dc/cmd/traffic_shell/CliMgmtUtils.h
----------------------------------------------------------------------
diff --git a/cmd/traffic_shell/CliMgmtUtils.h b/cmd/traffic_shell/CliMgmtUtils.h
new file mode 100644
index 0000000..3798f70
--- /dev/null
+++ b/cmd/traffic_shell/CliMgmtUtils.h
@@ -0,0 +1,152 @@
+/** @file
+
+  This file declares various utility functions which call the TSMgmtAPI.
+
+  @section license License
+
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+ */
+
+#include "mgmtapi.h"
+
+#define RECORD_GET 0
+#define RECORD_SET 1
+
+// Get a records.config variable by name
+TSError Cli_RecordGet(const char *rec_name, TSRecordEle * rec_val);
+
+// Get an integer type records.config variable
+TSError Cli_RecordGetInt(const char *rec_name, TSInt * int_val);
+
+// Get an counter type records.config variable
+TSError Cli_RecordGetCounter(const char *rec_name, TSCounter * ctr_val);
+
+// Get a float type records.config variable
+TSError Cli_RecordGetFloat(const char *rec_name, TSFloat * float_val);
+
+// Get a string type records.config variable
+TSError Cli_RecordGetString(const char *rec_name, char **string_val);
+
+// Use a string to set a records.config variable
+TSError Cli_RecordSet(const char *rec_name, const char *rec_value, 
TSActionNeedT * action_need);
+
+// Set an integer type records.config variable
+TSError Cli_RecordSetInt(const char *rec_name, TSInt int_val, TSActionNeedT * 
action_need);
+
+//Set a float type records.config variable
+TSError Cli_RecordSetFloat(const char *rec_name, TSFloat float_val, 
TSActionNeedT * action_need);
+
+// Set a string type records.config variable
+TSError Cli_RecordSetString(const char *rec_name, TSString str_val, 
TSActionNeedT * action_need);
+
+// Retrieve and display contents of a rules file
+TSError Cli_DisplayRules(TSFileNameT fname);
+
+// Retrieve and use config file from remote URL
+TSError Cli_SetConfigFileFromUrl(TSFileNameT file, const char *url);
+
+// enable recent configuration changes by performing the action specified
+// by the action_need value
+TSError Cli_ConfigEnactChanges(TSActionNeedT action_need);
+
+// evaluate "stringval" and return 1 if "on", otherwise 0
+int Cli_EvalOnOffString(char *stringval);
+
+////////////////////////////////////////////////////////////////
+// Cli_Record functions are used by various config commands
+// to get/display and set variables in records.config
+//
+
+////////////////////////////////////////////////////////////////
+// Cli_RecordOnOff_Action
+//
+// used for records.config INT variables when 1 = on, 0 = off
+//
+// action = RECORD_GET retrieve and display the variable
+//          RECORD_SET set the variable
+//
+// record = variable in records.config
+//
+// on_off = "on" mean 1, "off" mean 0
+//
+int Cli_RecordOnOff_Action(int action, const char *record, const char *on_off);
+
+////////////////////////////////////////////////////////////////
+// Cli_RecordInt_Action
+//
+// used for records.config INT variables
+//
+// action = RECORD_GET retrieve and display the variable
+//          RECORD_SET set the variable
+//
+// record = variable in records.config
+//
+// value = the integer value used by RECORD_SET
+//
+int Cli_RecordInt_Action(int action, const char *record, int value);
+
+////////////////////////////////////////////////////////////////
+// Cli_RecordHostname_Action
+//
+// used for records.config STRING variables
+// performs checking to see if string is a valid fully qualified hostname
+//
+// action = RECORD_GET retrieve and display the variable
+//          RECORD_SET set the variable
+//
+// record = variable in records.config
+//
+// hostname = string to set
+//
+int Cli_RecordHostname_Action(int action, const char *record, char *hostname);
+
+////////////////////////////////////////////////////////////////
+// Cli_RecordString_Action
+//
+// used for records.config STRING variables
+//
+// action = RECORD_GET retrieve and display the variable
+//          RECORD_SET set the variable
+//
+// record = variable in records.config
+//
+// string_val = string to set
+//
+int Cli_RecordString_Action(int action, const char *record, char *string_val);
+
+////////////////////////////////////////////////////////////////
+// Cli_ConfigFileURL_Action
+//
+// used for config files other than records.config
+//
+// file = integer which specifies config file
+//
+// filename = config file name to display
+//
+// url = if non-NULL, update the file using contents of URL
+//
+int Cli_ConfigFileURL_Action(TSFileNameT file, const char *filename, const 
char *url);
+
+extern bool enable_restricted_commands;
+
+int cliCheckIfEnabled(const char *command);
+
+int GetTSDirectory(char *ts_path, size_t ts_path_len);
+
+int StopTrafficServer();
+int StartTrafficServer();
+int Cli_CheckPluginStatus(TSString plugin);

Reply via email to