Move tr_prefix_wildcard_match to tr_constraint.c
authorSam Hartman <hartmans@debian.org>
Wed, 2 Jul 2014 09:30:21 +0000 (05:30 -0400)
committerSam Hartman <hartmans@debian.org>
Wed, 2 Jul 2014 09:43:18 +0000 (05:43 -0400)
We need tr_prefix_wildcard_match for merge_constraints and for
tr_filter.c.  Export it from libtr_tid even though it's in a private
header.  It's not part of the public API but is part of the library so
tr_filter can import it.

Also, fix bug; all strings were treated as wildcards.

common/tr_constraint.c
common/tr_filter.c
include/tr_filter.h

index 3ce6cbe..f0c3316 100644 (file)
 #include <tr_filter.h>
 #include <trust_router/tr_constraint.h>
 
+/* Returns TRUE (1) if the the string (str) matchs the wildcard string (wc_str), FALSE (0) if not.
+ */
+int tr_prefix_wildcard_match (const char *str, const char *wc_str) {
+  const char *wc_post = wc_str;
+  size_t len = 0;
+  size_t wc_len = 0;
+
+  if ((!str) || (!wc_str))
+    return 0;
+
+  len = strlen(str);
+  if (0 == (wc_len = strlen(wc_str)))
+    return 0;
+
+  /* TBD -- skip leading white space? */
+  if ('*' == wc_str[0]) {
+    wc_post = &(wc_str[1]);
+    wc_len--;
+  }else if (len != wc_len)
+    return 0;
+
+
+  if (wc_len > len)
+    return 0;
+  
+  if (0 == strcmp(&(str[len-wc_len]), wc_post)) {
+    return 1;
+  }
+  else
+    return 0;
+  }
+
 TR_CONSTRAINT_SET *tr_constraint_set_from_fline (TR_FLINE *fline)
 {
   json_t *cset = NULL;
index 4f782dc..d4c9acd 100644 (file)
 #include <string.h>
 #include <tr_filter.h>
 
-/* Returns TRUE (1) if the the string (str) matchs the wildcard string (wc_str), FALSE (0) if not.
- */
-int tr_prefix_wildcard_match (char *str, char *wc_str) {
-  char *wc_post = wc_str;
-  size_t len = 0;
-  size_t wc_len = 0;
-
-  if ((!str) || (!wc_str))
-    return 0;
-
-  len = strlen(str);
-  if (0 == (wc_len = strlen(wc_str)))
-    return 0;
-
-  /* TBD -- skip leading white space? */
-  if ('*' == wc_str[0]) {
-    wc_post = &(wc_str[1]);
-    wc_len--;
-  }
-
-  if (wc_len > len)
-    return 0;
-  
-  if (0 == strcmp(&(str[len-wc_len]), wc_post)) {
-    return 1;
-  }
-  else
-    return 0;
-  }
 
 int tr_filter_process_rp_permitted (TR_NAME *rp_realm, TR_FILTER *rpp_filter, TR_CONSTRAINT_SET *in_constraints, TR_CONSTRAINT_SET **out_constraints, int *out_action) 
 {
index 8efdbc4..718dca0 100644 (file)
@@ -73,7 +73,8 @@ typedef struct tr_filter {
 } TR_FILTER;
 
 void tr_filter_free (TR_FILTER *filt);
-int tr_prefix_wildcard_match (char *str, char *wc_str);
+/*In tr_constraint.c and exported, but not really a public symbol; needed by tr_filter.c and by tr_constraint.c*/
+int TR_EXPORT tr_prefix_wildcard_match (const char *str, const char *wc_str);
 int tr_filter_process_rp_permitted (TR_NAME *rp_realm, TR_FILTER *rpp_filter, TR_CONSTRAINT_SET *in_constraints, TR_CONSTRAINT_SET **out_constraints, int *out_action);
 TR_CONSTRAINT_SET *tr_constraint_set_from_fline (TR_FLINE *fline);
 #endif