Index: libabac/abac.h
===================================================================
--- libabac/abac.h	(revision 202a7f97d0dc5cb5eb2b43332f0711eafa4d7170)
+++ libabac/abac.h	(revision 8bd77b59df89993868555d3b87f91fc241b09228)
@@ -1,1 +1,206 @@
-abac_pl.h
+#ifndef __ABAC_H__
+#define __ABAC_H__
+
+#include <stdlib.h>
+#include <abac_list.h>
+#include <abac_stack.h>
+#include <abac_common.h>
+
+typedef struct _abac_context_t abac_context_t;
+typedef struct _abac_credential_t abac_credential_t;
+typedef struct _abac_aspect_t abac_aspect_t;
+typedef struct _abac_attribute_t abac_attribute_t;
+typedef struct _abac_id_t abac_id_t;
+typedef struct _abac_id_credential_t abac_id_credential_t;
+
+typedef struct _abac_condition_t abac_condition_t;
+typedef struct _abac_term_t abac_term_t;
+typedef struct _abac_param_list_t abac_param_list_t;
+
+/*
+ * ABAC functions, operating on an ABAC context.
+ */
+abac_context_t *abac_context_new(void);
+abac_context_t *abac_context_dup(abac_context_t *ctx);
+void abac_context_free(abac_context_t *ctx);
+
+/* see the bottom of the file for possible return codes */
+int abac_context_load_id_id(abac_context_t *ctx, abac_id_t *);
+int abac_context_load_id_file(abac_context_t *ctx, char *filename);
+int abac_context_load_id_chunk(abac_context_t *ctx, abac_chunk_t cert);
+int abac_context_load_attribute_attribute(abac_context_t *ctx, abac_attribute_t *);
+int abac_context_load_attribute_file(abac_context_t *ctx, char *filename);
+int abac_context_load_attribute_chunk(abac_context_t *ctx, abac_chunk_t cert);
+
+/* load an entire directory full of certs */
+void abac_context_load_directory(abac_context_t *ctx, char *path);
+
+/* abac query, returns a NULL-terminated array of credentials on success, NULL on fail */
+abac_credential_t **abac_context_query(abac_context_t *ctx, char *role, char *principal, int *success);
+
+/* get all the credentials from the context, returns a NULL-terminated array of credentials */
+abac_credential_t **abac_context_credentials(abac_context_t *ctx);
+
+/* use this to free the results of either of the previous two functions */
+void abac_context_credentials_free(abac_credential_t **credentials);
+
+/*
+ * Operations on credentials
+ */
+abac_aspect_t *abac_credential_head(abac_credential_t *cred);
+abac_aspect_t *abac_credential_tail(abac_credential_t *cred);
+abac_chunk_t abac_credential_attribute_cert(abac_credential_t *cred);
+abac_chunk_t abac_credential_issuer_cert(abac_credential_t *cred);
+abac_credential_t *abac_credential_lookup(char *cred_string);
+abac_id_credential_t *abac_id_credential_lookup(char*);
+abac_id_t *abac_id_credential_id(abac_id_credential_t *ptr);
+
+abac_credential_t *abac_credential_dup(abac_credential_t *cred);
+abac_attribute_t *abac_credential_attribute(abac_credential_t *cred);
+void abac_credential_free(abac_credential_t *cred);
+
+/*
+ * Operations on aspect.
+ */
+abac_aspect_t *abac_aspect_role_principal_create(char *principal_name);
+abac_aspect_t *abac_aspect_oset_principal_create(char *principal_name);
+abac_aspect_t *abac_aspect_role_create(char *principal_name, char *role_name);
+abac_aspect_t *abac_aspect_oset_create(char *principal_name, char *oset_name);
+
+bool abac_aspect_is_principal(abac_aspect_t *ptr);
+abac_aspect_t *abac_aspect_dup(abac_aspect_t *ptr);
+char *abac_aspect_string(abac_aspect_t *ptr);
+bool abac_aspect_is_linking(abac_aspect_t *ptr);
+char *abac_aspect_typed_string(abac_aspect_t *ptr);
+abac_aspect_t *abac_aspect_add_param(abac_aspect_t *ptr, abac_term_t *param);
+abac_aspect_t *abac_aspect_add_linked_param(abac_aspect_t *ptr, abac_term_t *param);
+bool abac_aspect_is_object(abac_aspect_t *ptr);
+char *abac_aspect_principal_name(abac_aspect_t *ptr);
+char* abac_aspect_type_string(abac_aspect_t *ptr);
+char *abac_aspect_aspect_name(abac_aspect_t *ptr);
+int abac_aspect_aspect_type(abac_aspect_t *ptr);
+abac_param_list_t *abac_aspect_aspect_params(abac_aspect_t *ptr);
+abac_param_list_t *abac_aspect_linked_role_params(abac_aspect_t *ptr);
+abac_aspect_t *abac_aspect_oset_linking_new(char *principal_name, 
+                              char *linked_role_name, char *oset_name);
+abac_aspect_t *abac_aspect_role_linking_new(char *principal_name,
+                              char *linked_role_name, char *role_name);
+abac_aspect_t *abac_aspect_role_new(char *principal_name, char *role_name);
+abac_aspect_t *abac_aspect_oset_new(char *principal_name, char *oset_name);
+abac_aspect_t *abac_aspect_oset_principal_new(char *principal_name);
+abac_aspect_t *abac_aspect_role_principal_new(char *principal_name);
+abac_aspect_t *abac_aspect_oset_object_new(abac_term_t *object);
+char *abac_aspect_linked_role_name(abac_aspect_t *ptr);
+char *abac_aspect_object_name(abac_aspect_t *ptr);
+char *abac_aspect_object_type(abac_aspect_t *ptr);
+abac_list_t *abac_aspect_prereqs(abac_aspect_t *ptr);
+char *abac_aspect_string_with_condition(abac_aspect_t *);
+char *abac_aspect_typed_string_with_condition(abac_aspect_t *);
+char *abac_aspect_principal_principalname(abac_aspect_t *ptr);
+void abac_print_aspect_string_with_condition(abac_aspect_t *ptr,FILE *fp);
+char *abac_aspect_aspect_param_string(abac_aspect_t *ptr);
+abac_aspect_t *abac_aspect_intersection_new(abac_aspect_t *);
+abac_aspect_t *abac_aspect_add_intersecting_aspect(abac_aspect_t *ptr, abac_aspect_t *aspect);
+abac_id_t *abac_aspect_get_issuer_id(abac_aspect_t *ptr);
+int abac_aspect_intersecting_aspect_type(abac_aspect_t *ptr);
+
+/* abac_attribute */
+abac_chunk_t abac_attribute_cert_chunk(abac_attribute_t *ptr);
+int abac_attribute_write(abac_attribute_t *ptr, FILE *out);
+int abac_attribute_bake(abac_attribute_t *ptr);
+int abac_attribute_baked(abac_attribute_t *ptr);
+abac_aspect_t *abac_attribute_head(abac_attribute_t *ptr);
+abac_aspect_t *abac_attribute_tail(abac_attribute_t *ptr);
+int abac_attribute_lastone(abac_attribute_t *ptr);
+int abac_attribute_create(abac_attribute_t **ret,abac_aspect_t *head, abac_aspect_t *tail,int validity);
+abac_attribute_t *abac_attribute_set_head(abac_attribute_t *ptr, abac_aspect_t *);
+abac_attribute_t *abac_attribute_add_tail(abac_attribute_t *ptr, abac_aspect_t *);
+abac_attribute_t *abac_attribute_dup(abac_attribute_t *ptr);
+abac_aspect_t **abac_attribute_tail_vectorized(abac_attribute_t *ptr);
+void abac_attribute_free(abac_attribute_t *ptr);
+void abac_aspects_free(abac_aspect_t **aspects);
+
+/*
+ * Operations on term/params.
+ */
+abac_condition_t *abac_condition_dup(abac_condition_t *ptr);
+void abac_condition_free(abac_condition_t *ptr);
+abac_condition_t *abac_condition_from_string(char *string);
+abac_condition_t *abac_condition_from_aspect(abac_aspect_t *ptr);
+char *abac_condition_typed_string(abac_condition_t *ptr);
+char *abac_condition_string(abac_condition_t *ptr);
+char *abac_condtype_name(int);
+char *abac_term_to_time(char *string);
+char *abac_term_typed_string(abac_term_t *ptr);
+char *abac_term_string(abac_term_t *ptr);
+char *abac_termtype_name(int i);
+char *abac_term_type_name(abac_term_t *term);
+abac_term_t *abac_term_dup(abac_term_t *ptr);
+abac_term_t *abac_term_create(int type, char *name, abac_condition_t *cptr);
+bool abac_term_is_urn_type(abac_term_t *);
+bool abac_term_is_integer_type(abac_term_t *);
+int abac_term_type(abac_term_t *term);
+abac_term_t *abac_term_add_constraint(abac_term_t *ptr, abac_condition_t *cond);
+abac_term_t *abac_term_new(int, char *, char *, abac_aspect_t *);
+void abac_term_free(abac_term_t *);
+bool abac_term_is_time_type(abac_term_t *);
+bool abac_term_is_string_type(abac_term_t *);
+char *abac_term_name(abac_term_t *);
+abac_condition_t *abac_term_constraint(abac_term_t *term);
+abac_param_list_t *abac_param_list_new(abac_term_t *term);
+abac_param_list_t *abac_param_list_free(abac_param_list_t *ptr);
+abac_param_list_t *abac_param_list_add_term(abac_param_list_t *, abac_term_t *term);
+char* abac_param_list_string(abac_param_list_t *ptr);
+char* abac_param_list_string_with_condition(abac_param_list_t *ptr);
+char* abac_param_list_typed_string_with_condition(abac_param_list_t *ptr);
+abac_term_t **abac_param_list_vectorize(abac_param_list_t *ptr);
+void abac_terms_free(abac_term_t **terms);
+
+/* from abac_verifier */
+char *abac_cn_with_sha(char*);
+char *abac_idtype_with_sha(char*);
+char *abac_idtype_string(int);
+abac_stack_t *abac_verifier_dump_creds();
+abac_id_credential_t *abac_verifier_add_id_credential(abac_id_t *a_id);
+
+/* from abac_id */
+int abac_id_lastone(abac_id_t *ptr);
+abac_id_t *abac_id_dup(abac_id_t *id);
+void abac_id_free(abac_id_t *id);
+char *abac_id_cn(abac_id_t *id);
+char *abac_id_keyid(abac_id_t *id);
+abac_id_t *abac_id_from_file(char *filename);
+int abac_id_load_privkey(abac_id_t *id, char *filename);
+int abac_id_write_privkey(abac_id_t *id, FILE *out);
+int abac_id_has_privkey(abac_id_t *id);
+void abac_id_write_cert(abac_id_t *id, FILE *out);
+int abac_id_generate(abac_id_t **ret, char *cn, int validity);
+abac_chunk_t abac_id_cert_chunk(abac_id_t *id);
+
+/* from abac_aspect */
+void abac_aspect_free(abac_aspect_t *);
+void abac_errx(int val, char *string);
+
+/*
+ * Error codes for loading certificates.
+ */
+#define ABAC_CERT_SUCCESS           0   // certificate loaded, all is well
+#define ABAC_CERT_INVALID           -1  // invalid format; also file not found
+#define ABAC_CERT_BAD_SIG           -2  // invalid signature
+#define ABAC_CERT_MISSING_ISSUER    -3  // missing ID cert that issued the attribute cert
+#define ABAC_CERT_BAD_CN            -4  // ID cert is not matching CN=principal format
+#define ABAC_CERT_BAD_YAP           -5  // failed to insert into prolog engine
+
+#define ABAC_ID_SUCCESS                     0
+#define ABAC_ID_GENERATE_INVALID_CN        -1
+#define ABAC_ID_GENERATE_INVALID_VALIDITY  -2
+
+#define ABAC_ATTRIBUTE_SUCCESS              0
+#define ABAC_ATTRIBUTE_INVALID_ROLE        -1
+#define ABAC_ATTRIBUTE_INVALID_VALIDITY    -2
+#define ABAC_ATTRIBUTE_ISSUER_NOKEY        -3
+
+
+#define USE(evalue) ((getenv(evalue)!=NULL)?1:0)
+
+#endif /* __ABAC_H__ */
