Browse Source

Add CLI support for /explicit/urls (automatically outputs JSON in this case), and some cleanup.

Adam Ierymenko 10 years ago
parent
commit
2599b1bacc
2 changed files with 18 additions and 4 deletions
  1. 18 2
      one.cpp
  2. 0 2
      service/OneService.hpp

+ 18 - 2
one.cpp

@@ -256,7 +256,23 @@ static int cli(int argc,char **argv)
 
 
 	requestHeaders["X-ZT1-Auth"] = authToken;
 	requestHeaders["X-ZT1-Auth"] = authToken;
 
 
-	if ((command == "info")||(command == "status")) {
+	if ((command.length() > 0)&&(command[0] == '/')) {
+		unsigned int scode = Http::GET(
+			1024 * 1024 * 16,
+			60000,
+			(const struct sockaddr *)&addr,
+			command.c_str(),
+			requestHeaders,
+			responseHeaders,
+			responseBody);
+		if (scode == 200) {
+			printf("%s",cliFixJsonCRs(responseBody).c_str());
+			return 0;
+		} else {
+			printf("%u %s %s"ZT_EOL_S,scode,command.c_str(),responseBody.c_str());
+			return 1;
+		}
+	} else if ((command == "info")||(command == "status")) {
 		unsigned int scode = Http::GET(
 		unsigned int scode = Http::GET(
 			1024 * 1024 * 16,
 			1024 * 1024 * 16,
 			60000,
 			60000,
@@ -363,7 +379,7 @@ static int cli(int argc,char **argv)
 													else if ((!strcmp(jpath->u.object.values[kk].name,"active"))&&(jpath->u.object.values[kk].value->type == json_boolean))
 													else if ((!strcmp(jpath->u.object.values[kk].name,"active"))&&(jpath->u.object.values[kk].value->type == json_boolean))
 														active = (jpath->u.object.values[kk].value->u.boolean != 0);
 														active = (jpath->u.object.values[kk].value->u.boolean != 0);
 												}
 												}
-												if (paddr) {
+												if ((paddr)&&((active)||(fixed))) {
 													int64_t now = (int64_t)OSUtils::now();
 													int64_t now = (int64_t)OSUtils::now();
 													if (lastSend > 0)
 													if (lastSend > 0)
 														lastSend = now - lastSend;
 														lastSend = now - lastSend;

+ 0 - 2
service/OneService.hpp

@@ -106,8 +106,6 @@ public:
 	 * The terminate() method may be called from a signal handler or another
 	 * The terminate() method may be called from a signal handler or another
 	 * thread to terminate execution. Otherwise this will not return unless
 	 * thread to terminate execution. Otherwise this will not return unless
 	 * another condition terminates execution such as a fatal error.
 	 * another condition terminates execution such as a fatal error.
-	 *
-	 * @param 
 	 */
 	 */
 	virtual ReasonForTermination run() = 0;
 	virtual ReasonForTermination run() = 0;