Support "show routes" monitoring request
[trust_router.git] / trp / trp_upd.c
index 98898ff..e1057f1 100644 (file)
  *
  */
 
+#include <strings.h>
 #include <jansson.h>
 #include <talloc.h>
 
-#include <trust_router/tr_name.h>
+#include <tr_name_internal.h>
 #include <trp_internal.h>
 #include <tr_comm.h>
 #include <tr_apc.h>
@@ -80,7 +81,7 @@ TRP_INFOREC_TYPE trp_inforec_type_from_string(const char *s)
   struct trp_inforec_type_entry *entry=trp_inforec_type_table;
 
   while ((entry->type != TRP_INFOREC_TYPE_UNKNOWN)
-        && (strcmp(s, entry->name)!=0)) {
+        && (strcasecmp(s, entry->name)!=0)) {
     entry++;
   }
   return entry->type;
@@ -677,6 +678,45 @@ void trp_upd_add_inforec(TRP_UPD *upd, TRP_INFOREC *rec)
   talloc_steal(upd, rec);
 }
 
+/**
+ * Removes and frees the selected inforec.
+ *
+ * @param upd Update to remove from
+ * @param rec Inforec to remove
+ */
+void trp_upd_remove_inforec(TRP_UPD *upd, TRP_INFOREC *rec)
+{
+  TRP_INFOREC *this=upd->records;
+
+  /* special case for the first element */
+  if (this==rec) {
+    upd->records=upd->records->next;
+    trp_inforec_free(this);
+    return;
+  }
+
+  while (this->next!=NULL) {
+    if (this->next==rec) {
+      this->next=this->next->next; /* this->next is not null */
+      trp_inforec_free(rec);
+    }
+    this=this->next;
+  }
+}
+
+size_t trp_upd_num_inforecs(TRP_UPD *upd)
+{
+  size_t count=0;
+  TRP_INFOREC *this=upd->records;
+
+  while (this != NULL) {
+    count++;
+    this=this->next;
+  }
+  return count;
+}
+
+
 TR_NAME *trp_upd_get_realm(TRP_UPD *upd)
 {
   return upd->realm;
@@ -754,7 +794,7 @@ void trp_upd_add_to_provenance(TRP_UPD *upd, TR_NAME *name)
 static void trp_inforec_route_print(TRP_INFOREC_DATA *data)
 {
   if (data->route!=NULL) {
-    printf("     trust_router=%.*s\n     metric=%d\n     interval=%d]\n",
+    tr_info("     trust_router=%.*s\n     metric=%d\n     interval=%d]\n",
            data->route->trust_router->len, data->route->trust_router->buf,
            data->route->metric, data->route->interval);
   }
@@ -763,7 +803,7 @@ static void trp_inforec_route_print(TRP_INFOREC_DATA *data)
 static void trp_inforec_comm_print(TRP_INFOREC_DATA *data)
 {
   if (data->comm!=NULL) {
-    printf("     type=%s\n     role=%s\n     owner=%.*s\n     contact=%.*s]\n",
+    tr_info("     type=%s\n     role=%s\n     owner=%.*s\n     contact=%.*s]\n",
            tr_comm_type_to_str(data->comm->comm_type),
            tr_realm_role_to_str(data->comm->role),
            data->comm->owner_realm->len, data->comm->owner_realm->buf,