Miscellaneous minor code cleanup for MRW's review comments
authorJennifer Richards <jennifer@painless-security.com>
Mon, 7 May 2018 18:11:43 +0000 (14:11 -0400)
committerJennifer Richards <jennifer@painless-security.com>
Mon, 7 May 2018 18:11:43 +0000 (14:11 -0400)
  * Remove generation of DH in trmon.c, it's not needed
  * Check return value of mon_req_add_option() in a few places it had
    been ignored
  * Spell out "Trust Router" in trmon version/help description
  * Rename _decode -> _encode after a copy/paste
  * Fix a few incorrect comments describing file contents
  * Fix function name in debug messages in tr_cfg_parse_config_files()
  * Include glib.h instead of gmodule.h in a few files

12 files changed:
common/tr_config.c
include/tr_config.h
mon/mon_common.c
mon/mon_req.c
mon/mon_req_decode.c
mon/mon_req_encode.c
mon/mon_resp.c
mon/mon_resp_decode.c
mon/mon_resp_encode.c
mon/mons_handlers.c
tr/trmon_main.c
tr/trpc_main.c

index 8c0f577..2ddda12 100644 (file)
@@ -310,13 +310,13 @@ static json_t **tr_cfg_parse_config_files(TALLOC_CTX *mem_ctx, unsigned int n_fi
 
     this_file->serial = get_cfg_serial(jcfgs[ii]);
     if (this_file->serial != TR_CFG_INVALID_SERIAL) {
-      tr_notice("tr_parse_one_config_file: Attempting to load revision %"
+      tr_notice("tr_parse_config_files: Attempting to load revision %"
                     JSON_INTEGER_FORMAT
                     " of '%s'.",
                 this_file->serial,
                 this_file->name);
     } else {
-      tr_notice("tr_parse_one_config_file: Attempting to load '%s'.",
+      tr_notice("tr_parse_config_files: Attempting to load '%s'.",
                 this_file->name);
     }
   }
index 30317de..8dc66c4 100644 (file)
@@ -41,7 +41,7 @@
 #include <syslog.h>
 #include <sys/time.h>
 #include <talloc.h>
-#include <gmodule.h>
+#include <glib.h>
 
 #include <tr_comm.h>
 #include <tr_rp.h>
index a237b5d..9a71af4 100644 (file)
@@ -34,7 +34,7 @@
 
 
 #include <talloc.h>
-#include <gmodule.h>
+#include <glib.h>
 #include <string.h>
 
 #include <mon_internal.h>
index bffa92e..e7cc43b 100644 (file)
 
 
 #include <talloc.h>
-#include <gmodule.h>
+#include <glib.h>
 
 #include <mon_internal.h>
 
-// Monitoring request message common code
+/* Monitoring request message common code */
 
 /**
  * Destructor used by talloc to ensure proper cleanup
index 21bb64b..2d05620 100644 (file)
@@ -38,7 +38,7 @@
 
 #include <mon_internal.h>
 
-// Monitoring request decoders
+/* Monitoring request decoders */
 
 /**
  * Decode a single option
@@ -98,7 +98,9 @@ static MON_RC mon_options_decode(json_t *opts_json, MON_REQ *req)
                            &opt) != MON_SUCCESS) {
       return MON_NOPARSE;
     }
-    mon_req_add_option(req, opt.type);
+    if (MON_SUCCESS != mon_req_add_option(req, opt.type)){
+      return MON_NOPARSE;
+    }
   }
   return MON_SUCCESS;
 }
index 5bcf8b2..12e408c 100644 (file)
@@ -39,7 +39,7 @@
 
 #include <mon_internal.h>
 
-// Monitoring request encoders
+/* Monitoring request encoders */
 
 /**
  * Encode options array as a JSON array
@@ -54,7 +54,7 @@
  * @param opts array of options
  * @return reference to a JSON array of options
  */
-static json_t *mon_opts_decode(GArray *opts)
+static json_t *mon_opts_encode(GArray *opts)
 {
   json_t *array_json = json_array(); // the array of options
   json_t *opt_json = NULL; // individual option JSON object
@@ -142,7 +142,7 @@ json_t *mon_req_encode(MON_REQ *req)
 
   /* If we have options, add them to the object */
   if (req->options->len > 0) {
-    opts_json = mon_opts_decode(req->options);
+    opts_json = mon_opts_encode(req->options);
     if (opts_json == NULL) {
       json_decref(req_json);
       return NULL;
index f0729ad..3049eaa 100644 (file)
@@ -38,7 +38,7 @@
 
 #include <mon_internal.h>
 
-// Monitoring request message common code
+/* Monitoring response message common code */
 
 /**
  * Destructor used by talloc to ensure proper cleanup
index 83b0ac3..c6ca379 100644 (file)
@@ -38,7 +38,7 @@
 
 #include <mon_internal.h>
 
-// Monitoring response decoder
+/* Monitoring response decoder */
 
 /**
  * Decode a JSON response
index 7e41c65..515fb7a 100644 (file)
@@ -37,6 +37,8 @@
 
 #include <mon_internal.h>
 
+/* Monitoring response encoder */
+
 /* Helper for encoding. Adds a newly allocated JSON object to
  * jobj. If the allocation or setting fails, returns NULL after
  * cleaning up. */
index 5e19db0..24cce1f 100644 (file)
@@ -34,7 +34,7 @@
 
 /* Handlers for monitoring requests */
 
-#include <gmodule.h>
+#include <glib.h>
 
 #include <tr_debug.h>
 #include <mon_internal.h>
index e6d4253..761b433 100644 (file)
@@ -44,7 +44,7 @@
 /* command-line option setup */
 static void print_version_info(void)
 {
-  printf("Moonshot TR Monitoring Client %s\n\n", PACKAGE_VERSION);
+  printf("Moonshot Trust Router Monitoring Client %s\n\n", PACKAGE_VERSION);
 }
 
 
@@ -52,7 +52,7 @@ static void print_version_info(void)
 const char *argp_program_bug_address=PACKAGE_BUGREPORT; /* bug reporting address */
 
 /* doc strings */
-static const char doc[]=PACKAGE_NAME " - Moonshot TR Monitoring Client";
+static const char doc[]=PACKAGE_NAME " - Moonshot Trust Router Monitoring Client";
 static const char arg_doc[]="<server> <port> <command> [<option> ...]"; /* string describing arguments, if any */
 
 /* define the options here. Fields are:
@@ -170,21 +170,13 @@ int main(int argc, char *argv[])
   tr_log_threshold(LOG_CRIT);
   tr_console_threshold(LOG_WARNING);
 
-  /* Create a MON client instance & the client DH */
+  /* Create a MON client instance */
   monc = monc_new(main_ctx);
   if (monc == NULL) {
     printf("Error allocating client instance.\n");
     goto cleanup;
   }
 
-
-  /* fill in the DH parameters */
-  monc_set_dh(monc, tr_create_dh_params(NULL, 0));
-  if (monc_get_dh(monc) == NULL) {
-    printf("Error creating client DH params.\n");
-    goto cleanup;
-  }
-
   /* Set-up MON connection */
   if (0 != monc_open_connection(monc, opts.server, opts.port)) {
     /* Handle error */
@@ -193,8 +185,14 @@ int main(int argc, char *argv[])
   };
 
   req = mon_req_new(main_ctx, opts.command);
-  for (ii=0; ii < opts.n_options; ii++)
-    mon_req_add_option(req, opts.options[ii]);
+  for (ii=0; ii < opts.n_options; ii++) {
+    if (MON_SUCCESS != mon_req_add_option(req, opts.options[ii])) {
+      printf("Error adding option '%s' to request. Request not sent.\n",
+             mon_opt_type_to_string(opts.options[ii]));
+      goto cleanup;
+    }
+
+  }
 
   /* Send a MON request and get the response */
   resp = monc_send_request(main_ctx, monc, req);
index f04b4dd..039bf51 100644 (file)
@@ -49,7 +49,7 @@
 const char *argp_program_bug_address=PACKAGE_BUGREPORT; /* bug reporting address */
 
 /* doc strings */
-static const char doc[]=PACKAGE_NAME " - TRP Client";
+static const char doc[]=PACKAGE_NAME " - Moonshot Trust Router TRP Client";
 static const char arg_doc[]="<message> <server> [<port>]"; /* string describing arguments, if any */
 
 /* define the options here. Fields are: