Raise priority of error messages when cannot open a socket
[trust_router.git] / trp / trps.c
index 61c02e8..ebc365d 100644 (file)
@@ -44,7 +44,7 @@
 #include <tr_comm.h>
 #include <tr_apc.h>
 #include <tr_rp.h>
-#include <trust_router/tr_name.h>
+#include <tr_name_internal.h>
 #include <trp_internal.h>
 #include <tr_gss.h>
 #include <trp_ptable.h>
@@ -464,15 +464,15 @@ int trps_get_listener(TRPS_INSTANCE *trps,
 
   n_fd=trps_listen(trps, port, fd_out, max_fd);
   if (n_fd==0)
-    tr_debug("trps_get_listener: Error opening port %d.");
+    tr_err("trps_get_listener: Error opening port %d.");
   else {
     /* opening port succeeded */
-    tr_debug("trps_get_listener: Opened port %d.", port);
+    tr_info("trps_get_listener: Opened port %d.", port);
     
     /* make the sockets non-blocking */
     for (ii=0; ii<n_fd; ii++) {
       if (0 != fcntl(fd_out[ii], F_SETFL, O_NONBLOCK)) {
-        tr_debug("trps_get_listener: Error setting O_NONBLOCK.");
+        tr_err("trps_get_listener: Error setting O_NONBLOCK.");
         for (ii=0; ii<n_fd; ii++) {
           close(fd_out[ii]);
           fd_out[ii]=-1;
@@ -1007,20 +1007,20 @@ cleanup:
  * Apply applicable TRP_INBOUND filters to an inforec. Rejects everything if peer has no filters.
  *
  * @param trps Active TRPS instance
- * @param peer_name Name of peer that sent this inforec
+ * @param upd TRP_UPD that contains the inforec to filter
  * @param rec Inforec to filter
- * @param realm Name of realm
- * @param comm Name of community
  * @return 1 if accepted by the filter, 0 otherwise
  */
-static int trps_filter_inbound_inforec(TRPS_INSTANCE *trps, TR_NAME *peer_name, TRP_INFOREC *rec, TR_NAME *realm, TR_NAME *comm)
+static int trps_filter_inbound_inforec(TRPS_INSTANCE *trps, TRP_UPD *upd, TRP_INFOREC *rec)
 {
   TRP_PEER *peer=NULL;
+  TR_NAME *peer_name=NULL;
   TR_FILTER_ACTION action=TR_FILTER_ACTION_REJECT;
   TR_FILTER_TARGET *target=NULL;
   int retval=0;
 
   /* Look up the peer. For inbound messages, the peer is identified by its GSS name */
+  peer_name=trp_upd_get_peer(upd);
   peer=trps_get_peer_by_gssname(trps, peer_name);
   if (peer==NULL) {
     tr_err("trps_filter_inbound_inforec: received inforec from unknown peer (%.*s), rejecting.",
@@ -1030,7 +1030,7 @@ static int trps_filter_inbound_inforec(TRPS_INSTANCE *trps, TR_NAME *peer_name,
   }
 
   /* tr_filter_apply() and tr_filter_set_get() handle null filter sets/filters by rejecting */
-  target=tr_filter_target_trp_inforec(NULL, rec, realm, comm);
+  target= tr_filter_target_trp_inforec(NULL, upd, rec);
   if (target==NULL) {
     /* TODO: signal that filtering failed. Until then, just filter everything and give an error message. */
     tr_crit("trps_filter_inbound_inforec: Unable to allocate filter target, cannot apply filter!");
@@ -1071,11 +1071,7 @@ static TRP_RC trps_handle_update(TRPS_INSTANCE *trps, TRP_UPD *upd)
   }
 
   for (rec=trp_upd_get_inforec(upd); rec!=NULL; rec=trp_inforec_get_next(rec)) {
-    if (!trps_filter_inbound_inforec(trps,
-                                     trp_upd_get_peer(upd),
-                                     rec,
-                                     trp_upd_get_realm(upd),
-                                     trp_upd_get_comm(upd))) {
+    if (!trps_filter_inbound_inforec(trps, upd, rec)) {
       tr_debug("trps_handle_update: inforec rejected by filter.");
       continue; /* just go on to the next record */
     }
@@ -1683,7 +1679,7 @@ static void trps_filter_one_outbound_update(TR_FILTER *filt, TRP_UPD *upd)
 
   for(this=trp_upd_get_inforec(upd); this!=NULL; this=next) {
     next=this->next;
-    target=tr_filter_target_trp_inforec(NULL, this, trp_upd_get_realm(upd), trp_upd_get_comm(upd));
+    target= tr_filter_target_trp_inforec(NULL, upd, this);
     if (target==NULL) {
       /* TODO: signal that filtering failed. Until then, just filter everything and give an error message. */
       tr_crit("trps_filter_one_outbound_update: Unable to allocate filter target, cannot apply filter!");
@@ -1709,15 +1705,16 @@ static void trps_filter_one_outbound_update(TR_FILTER *filt, TRP_UPD *upd)
 static void trps_filter_outbound_updates(TR_FILTER_SET *filters, GPtrArray *updates)
 {
   TRP_UPD *upd=NULL;
-  int ii=0;
+  guint ii=0;
 
-  /* walk backward through the array so we can remove elements */
-  for (ii=updates->len-1; ii>=0; ii--) {
-    upd=g_ptr_array_index(updates, ii);
+  /* Walk backward through the array so we can remove elements. Careful about loop
+   * termination - remember that ii is unsigned. */
+  for (ii=updates->len; ii>0; ii--) {
+    upd=g_ptr_array_index(updates, ii-1);
     trps_filter_one_outbound_update(tr_filter_set_get(filters, TR_FILTER_TYPE_TRP_OUTBOUND), upd);
     /* see if we removed all the records from this update */
     if (trp_upd_num_inforecs(upd)==0)
-      g_ptr_array_remove_index_fast(updates, ii); /* does not preserve order at index ii or higher */
+      g_ptr_array_remove_index_fast(updates, ii-1); /* does not preserve order at index ii or higher */
   }
 }