Use json_is_true() in place of json_boolean_value() for compatibility
[trust_router.git] / tr / tr_mon.c
index f96d0ed..1327082 100644 (file)
@@ -37,6 +37,7 @@
 #include <tr_config.h>
 #include <tr_debug.h>
 #include <mon_internal.h>
+#include <tr_mon.h>
 
 /*
  * Cookie for the event handling callback
@@ -95,9 +96,8 @@ static int tr_mons_auth_handler(gss_name_t client_name, TR_NAME *gss_name, void
 {
   struct tr_mons_event_cookie *cookie=talloc_get_type_abort(cookie_in, struct tr_mons_event_cookie);
   MONS_INSTANCE *mons = cookie->mons;
-  TR_CFG_MGR *cfg_mgr = cookie->cfg_mgr;
 
-  if ((!client_name) || (!gss_name) || (!mons) || (!cfg_mgr)) {
+  if ((!client_name) || (!gss_name) || (!mons)) {
     tr_debug("tr_mons_gss_handler: Bad parameters.");
     return -1;
   }
@@ -128,7 +128,10 @@ static int tr_mons_auth_handler(gss_name_t client_name, TR_NAME *gss_name, void
  * @param mons_ev monitoring interface event instance
  * @return 0 on success, nonzero on failure.
  * */
-int tr_mon_event_init(struct event_base *base, MONS_INSTANCE *mons, TR_CFG_MGR *cfg_mgr, struct tr_socket_event *mons_ev)
+int tr_mons_event_init(struct event_base *base,
+                       MONS_INSTANCE *mons,
+                       TR_CFG_MGR *cfg_mgr,
+                       struct tr_socket_event *mons_ev)
 {
   TALLOC_CTX *tmp_ctx=talloc_new(NULL);
   struct tr_mons_event_cookie *cookie=NULL;
@@ -141,6 +144,12 @@ int tr_mon_event_init(struct event_base *base, MONS_INSTANCE *mons, TR_CFG_MGR *
     goto cleanup;
   }
 
+  if (cfg_mgr->active->internal->mons_port == 0) {
+    tr_notice("tr_mons_event_init: monitoring is disabled, not enabling events or opening sockets");
+    retval = 0;
+    goto cleanup;
+  }
+
   /* Create the cookie for callbacks. We'll put it in the mons context, so it will
    * be cleaned up when mons is freed by talloc_free. */
   cookie=talloc(tmp_ctx, struct tr_mons_event_cookie);
@@ -154,12 +163,11 @@ int tr_mon_event_init(struct event_base *base, MONS_INSTANCE *mons, TR_CFG_MGR *
   talloc_steal(mons, cookie);
 
   /* get a monitoring interface listener */
-  mons_ev->n_sock_fd = mons_get_listener(mons,
-                                         tr_mons_req_handler,
+  mons_ev->n_sock_fd = mons_get_listener(mons, tr_mons_req_handler,
                                          tr_mons_auth_handler,
-                                         cfg_mgr->active->internal->monitoring_port,
-                                         (void *)cookie,
-                                         mons_ev->sock_fd,
+                                         cfg_mgr->active->internal->hostname,
+                                         cfg_mgr->active->internal->mons_port,
+                                         (void *) cookie, mons_ev->sock_fd,
                                          TR_MAX_SOCKETS);
   if (mons_ev->n_sock_fd==0) {
     tr_crit("Error opening monitoring interface socket.");