tr_constraint_set_get_match_strings
authorSam Hartman <hartmans@debian.org>
Thu, 3 Jul 2014 20:40:48 +0000 (16:40 -0400)
committerSam Hartman <hartmans@debian.org>
Mon, 14 Jul 2014 20:07:34 +0000 (16:07 -0400)
New function to retrieve the wild card strings that match a constraint
type for an intersected constraint set.

As a result convert TID_REQ to using talloc.

Depend on talloc project wide.

  # Please enter the commit
message for your changes. Lines starting # with '#' will be ignored,
and an empty message aborts the commit.  # On branch master # Your
branch is ahead of 'origin/master' by 3 commits.  # (use "git push" to
publish your local commits) # # Changes to be committed: # modified:
common/tr_constraint.c # modified: configure.ac # modified:
include/trust_router/tid.h # modified:
include/trust_router/tr_constraint.h # modified:
include/trust_router/tr_name.h # modified: tid/tid_req.c # modified:
tid/tidc.c # # Changes not staged for commit: # modified:
include/trust_router/tr_versioning.h # # Untracked files: # "\a" #
cscope.out # db # dest/ # foo.c # trust_router-1.0.tar.gz #

common/tr_constraint.c
configure.ac
include/trust_router/tid.h
include/trust_router/tr_constraint.h
include/trust_router/tr_name.h
tid/tid_req.c
tid/tidc.c

index bfdf399..78c88f3 100644 (file)
@@ -33,6 +33,7 @@
  */
 #include <jansson.h>
 #include <assert.h>
+#include <talloc.h>
 
 #include <tr_filter.h>
 #include <tr_debug.h>
@@ -278,3 +279,35 @@ TR_CONSTRAINT_SET *tr_constraint_set_intersect( TID_REQ *request,
   tid_req_cleanup_json( request, result_array);
   return (TR_CONSTRAINT_SET *) result_array;
 }
+
+
+int tr_constraint_set_get_match_strings(
+                                       TID_REQ *request,
+                                       TR_CONSTRAINT_SET *constraints,
+                                       const char *constraint_type,
+                                       tr_const_string **output,
+                                       size_t *output_len)
+{
+  json_t *cset = (json_t *) constraints;
+  json_t *member, *matches, *value;;
+  size_t index, array_size;
+  assert (output && output_len);
+  *output = NULL;
+  *output_len = 0;
+  if (json_array_size(cset) != 1) {
+    tr_debug("Constraint set for get_match_strings has more than one member\n");
+    return -1;
+  }
+  member = json_array_get(cset, 0);
+  matches = json_object_get(member, constraint_type);
+  if (!matches)
+    return -1;
+  array_size = json_array_size(matches);
+  if (array_size == 0)
+    return -1;
+  *output = talloc_array_ptrtype(request, *output, array_size);
+  json_array_foreach( matches, index, value)
+    (*output)[index] = json_string_value(value);
+  *output_len = array_size;
+  return 0;
+}
index e34a1c3..f49e2f5 100644 (file)
@@ -4,16 +4,18 @@ AC_INIT([trust_router],[1.2],
 AC_CONFIG_MACRO_DIR(m4)
 AC_CONFIG_AUX_DIR(build-aux)
 AC_USE_SYSTEM_EXTENSIONS
-AM_INIT_AUTOMAKE([1.11 foreign])
+AM_INIT_AUTOMAKE([1.11 foreign subdir-objects])
 AM_SILENT_RULES
 AM_MAINTAINER_MODE
 LT_INIT()
 
 AC_PROG_CC
-AC_PROG_RANLIB
 
 AC_CHECK_LIB([gssapi_krb5], [gss_init_sec_context])
-AC_CHECK_LIB([com_err], [error_message])AC_CHECK_LIB([sqlite3], [sqlite3_open],,
+AC_CHECK_LIB([com_err], [error_message])
+AC_CHECK_LIB(talloc, talloc_asprintf,,
+[AC_MSG_ERROR([Please install talloc development])])
+AC_CHECK_LIB([sqlite3], [sqlite3_open],,
     [AC_MSG_ERROR([Please install sqlite3 development])])
 
 AC_CHECK_LIB([jansson], [json_object])
index ded2c42..299b66a 100644 (file)
@@ -147,7 +147,7 @@ TR_EXPORT TID_REQ *tid_dup_req (TID_REQ *orig_req);
     new reference is not created; in effect the caller is handing a
     reference they already hold to the TID_REQ.*/
 void tid_req_cleanup_json(TID_REQ *, json_t *json);
-#define tid_req_free free
+void TR_EXPORT tid_req_free( TID_REQ *req);
 
 /* Utility functions for TID_RESP structure, in tid/tid_resp.c */
 TR_EXPORT TID_RC tid_resp_get_result(TID_RESP *resp);
index e2a73d5..28f6bd4 100644 (file)
@@ -61,4 +61,18 @@ TR_EXPORT TR_CONSTRAINT_SET *tr_constraint_set_filter(TID_REQ *request,
 TR_EXPORT TR_CONSTRAINT_SET
 *tr_constraint_set_intersect(TID_REQ *request,
                             TR_CONSTRAINT_SET *input);
+
+/** Get the set of wildcard strings that matches a fully intersected
+ * constraint set.  Requires that the constraint set only have one
+ * constraint in it, but the constraint may have multiple matches for
+ * a given type.  Returns true on success false on failure.  The
+ * output is live as long as the request is live.
+ */
+int TR_EXPORT tr_constraint_set_get_match_strings(TID_REQ *,
+                                           TR_CONSTRAINT_SET *,
+                                                 const char * constraint_type,
+                                                 tr_const_string **output,
+                                           size_t *output_len);
+
 #endif
index 486bbbc..418edb5 100644 (file)
@@ -37,6 +37,8 @@
 #include <string.h>
 #include <trust_router/tr_versioning.h>
 
+typedef const char *tr_const_string;
+
 typedef struct tr__name {
   char *buf;
   int len;
index 5ba6c06..6f14be9 100644 (file)
 #include <stdio.h>
 #include <stdlib.h>
 #include <assert.h>
+#include <talloc.h>
 
 #include <trust_router/tid.h>
 #include <jansson.h>
 
+static int destroy_tid_req(TID_REQ *req)
+{
+  if (req->json_references)
+    json_decref(req->json_references);
+  return 0;
+}
+
 TID_REQ *tid_req_new()
 {
-  TID_REQ *req = calloc(sizeof(TID_REQ), 1);
+  TID_REQ *req = talloc_zero(NULL, TID_REQ);
   if(!req)
     return NULL;
+  talloc_set_destructor(req, destroy_tid_req);
   req->json_references = json_array();
   assert(req->json_references);
   req->conn = -1;
@@ -193,3 +202,8 @@ void tid_req_cleanup_json( TID_REQ *req, json_t *ref)
 {
   (void) json_array_append_new(req->json_references, ref);
 }
+
+void tid_req_free(TID_REQ *req)
+{
+  talloc_free(req);
+}
index 9590260..7f675d3 100644 (file)
@@ -190,7 +190,7 @@ int tidc_fwd_request (TIDC_INSTANCE *tidc,
   if (msg)
     free(msg);
   if (tid_req)
-    free(tid_req);
+    tid_req_free(tid_req);
   if (req_buf)
     free(req_buf);
   if (resp_buf)
@@ -201,7 +201,3 @@ int tidc_fwd_request (TIDC_INSTANCE *tidc,
   return 0;
 }
 
-
-
-
-