From 32792249a45039b0a0e332091a499956498b55ca Mon Sep 17 00:00:00 2001 From: Sam Hartman Date: Thu, 3 Jul 2014 16:40:48 -0400 Subject: [PATCH] tr_constraint_set_get_match_strings 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 | 33 +++++++++++++++++++++++++++++++++ configure.ac | 8 +++++--- include/trust_router/tid.h | 2 +- include/trust_router/tr_constraint.h | 14 ++++++++++++++ include/trust_router/tr_name.h | 2 ++ tid/tid_req.c | 16 +++++++++++++++- tid/tidc.c | 6 +----- 7 files changed, 71 insertions(+), 10 deletions(-) diff --git a/common/tr_constraint.c b/common/tr_constraint.c index bfdf399..78c88f3 100644 --- a/common/tr_constraint.c +++ b/common/tr_constraint.c @@ -33,6 +33,7 @@ */ #include #include +#include #include #include @@ -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; +} diff --git a/configure.ac b/configure.ac index e34a1c3..f49e2f5 100644 --- a/configure.ac +++ b/configure.ac @@ -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]) diff --git a/include/trust_router/tid.h b/include/trust_router/tid.h index ded2c42..299b66a 100644 --- a/include/trust_router/tid.h +++ b/include/trust_router/tid.h @@ -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); diff --git a/include/trust_router/tr_constraint.h b/include/trust_router/tr_constraint.h index e2a73d5..28f6bd4 100644 --- a/include/trust_router/tr_constraint.h +++ b/include/trust_router/tr_constraint.h @@ -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 diff --git a/include/trust_router/tr_name.h b/include/trust_router/tr_name.h index 486bbbc..418edb5 100644 --- a/include/trust_router/tr_name.h +++ b/include/trust_router/tr_name.h @@ -37,6 +37,8 @@ #include #include +typedef const char *tr_const_string; + typedef struct tr__name { char *buf; int len; diff --git a/tid/tid_req.c b/tid/tid_req.c index 5ba6c06..6f14be9 100644 --- a/tid/tid_req.c +++ b/tid/tid_req.c @@ -35,15 +35,24 @@ #include #include #include +#include #include #include +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); +} diff --git a/tid/tidc.c b/tid/tidc.c index 9590260..7f675d3 100644 --- a/tid/tidc.c +++ b/tid/tidc.c @@ -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; } - - - - -- 2.1.4