]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Add GETINFO current-time/{local,utc} command to ControlPort
authorNeel Chauhan <neel@neelc.org>
Tue, 17 Apr 2018 00:16:37 +0000 (20:16 -0400)
committerNeel Chauhan <neel@neelc.org>
Tue, 17 Apr 2018 00:37:50 +0000 (20:37 -0400)
src/or/control.c
src/or/control.h

index 0539ddaca3a37c67a6407594f48fda2b3597fff6..72122eaafba53ee2f6ebf464b6f1ba1858436a26 100644 (file)
@@ -1931,6 +1931,31 @@ getinfo_helper_listeners(control_connection_t *control_conn,
   return 0;
 }
 
+/** Implementation helper for GETINFO: answers requests for information about
+ * the current time in both local and UTF forms. */
+STATIC int
+getinfo_helper_current_time(control_connection_t *control_conn,
+                         const char *question,
+                         char **answer, const char **errmsg)
+{
+  (void)control_conn;
+  (void)errmsg;
+
+  struct timeval now;
+  tor_gettimeofday(&now);
+  char timebuf[ISO_TIME_LEN+1];
+
+  if (!strcmp(question, "current-time/local"))
+    format_local_iso_time_nospace(timebuf, (time_t)now.tv_sec);
+  else if (!strcmp(question, "current-time/utc"))
+    format_iso_time_nospace(timebuf, (time_t)now.tv_sec);
+  else
+    return 0;
+
+  *answer = tor_strdup(timebuf);
+  return 0;
+}
+
 /** Implementation helper for GETINFO: knows the answers for questions about
  * directory information. */
 STATIC int
@@ -3073,6 +3098,9 @@ static const getinfo_item_t getinfo_items[] = {
   DOC("config/defaults",
       "List of default values for configuration options. "
       "See also config/names"),
+  PREFIX("current-time/", current_time, "Current time."),
+  DOC("current-time/local", "Current time on the local system."),
+  DOC("current-time/utc", "Current UTC time."),
   PREFIX("downloads/networkstatus/", downloads,
          "Download statuses for networkstatus objects"),
   DOC("downloads/networkstatus/ns",
index 2fd3c553f327a1820d3d087bc0f6bf0e07121e04..2f312a6638222e2354876c0461baa9eee73b0db9 100644 (file)
@@ -311,6 +311,10 @@ STATIC int getinfo_helper_dir(
     control_connection_t *control_conn,
     const char *question, char **answer,
     const char **errmsg);
+STATIC int getinfo_helper_current_time(
+    control_connection_t *control_conn,
+    const char *question, char **answer,
+    const char **errmsg);
 
 #endif /* defined(CONTROL_PRIVATE) */