*/
#include <jansson.h>
#include <assert.h>
+#include <talloc.h>
#include <tr_filter.h>
#include <tr_debug.h>
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;
+}
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])
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);
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
#include <string.h>
#include <trust_router/tr_versioning.h>
+typedef const char *tr_const_string;
+
typedef struct tr__name {
char *buf;
int len;
#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;
{
(void) json_array_append_new(req->json_references, ref);
}
+
+void tid_req_free(TID_REQ *req)
+{
+ talloc_free(req);
+}
if (msg)
free(msg);
if (tid_req)
- free(tid_req);
+ tid_req_free(tid_req);
if (req_buf)
free(req_buf);
if (resp_buf)
return 0;
}
-
-
-
-