Index: tests/example_scripts/c/Makefile
===================================================================
--- tests/example_scripts/c/Makefile	(revision ec550f769c681cfa831dc724f82ddacd21fc75cd)
+++ tests/example_scripts/c/Makefile	(revision ec550f769c681cfa831dc724f82ddacd21fc75cd)
@@ -0,0 +1,53 @@
+
+LDFLAGS =-L/usr/local/lib -labac -lm -lpthread -Wl,-rpath
+
+all: attr prove tt
+
+abac_attr.o: abac_attr.c
+	gcc -g -I/usr/local/include -c abac_attr.c -o abac_attr.o
+
+abac_attr: abac_attr.o
+	gcc -g -o abac_attr abac_attr.o $(LDFLAGS)
+
+abac_prover.o: abac_prover.c
+	gcc -g -I/usr/local/include -c abac_prover.c -o abac_prover.o
+
+abac_prover: abac_prover.o
+	gcc -g -o abac_prover abac_prover.o $(LDFLAGS)
+
+tchunk: tchunk.c
+	gcc -g -I/usr/local/include -c tchunk.c -o tchunk.o
+	gcc -g -o tchunk tchunk.o $(LDFLAGS)
+	./tchunk 0 IceCream_ID.pem IceCream_private.pem
+	./tchunk 1 IceCream_ID.pem IceCream_private.pem
+
+tt: tbasic.c
+	gcc -g -I/usr/local/include -c tbasic.c -o tbasic.o
+	gcc -g -o tt tbasic.o $(LDFLAGS)
+	./tt
+
+clean:
+	@rm -rf abac_attr.o abac_attr *.pem *.xml abac_prover.o 
+	@rm -rf abac_prover *.log 
+	@rm -rf tt tbasic.o tbasic
+
+setup2: abac_attr abac_prover abac_attr_partial
+
+setup: abac_attr 
+	creddy --generate --cn IceCream
+	creddy --generate --cn Chocolate
+
+attr: 
+	rm -rf attr.log
+	make setup
+	./abac_attr IceCream_ID.pem  IceCream_private.pem IceCream_attr.xml Chocolate_ID.pem 1>attr.log 2>&1
+
+prove: abac_prover 
+	rm -rf prover.log
+	make attr
+	./run_prover 1>prover.log 2>&1
+
+mattr: attr.c
+	gcc -g -o mattr attr.c $(LDFLAGS)
+mload: loader.c
+	gcc -g -o mload loader.c $(LDFLAGS)
Index: tests/example_scripts/c/abac_attr.c
===================================================================
--- tests/example_scripts/c/abac_attr.c	(revision ec550f769c681cfa831dc724f82ddacd21fc75cd)
+++ tests/example_scripts/c/abac_attr.c	(revision ec550f769c681cfa831dc724f82ddacd21fc75cd)
@@ -0,0 +1,88 @@
+/**
+   attr_abac.c
+
+   To demonstrate how to use ABAC's api in C
+
+   call:   attr_abac IceCream_ID.pem IceCream_private.pem IceCream_attr.der
+
+   pre-condition: generate IceCream_ID.pem and IceCream_private.pem with
+           creddy --generate --cn IceCream
+                  generate Chocolate_ID.pem and Chocolate_private.pem with
+           creddy --generate --cn IceCream
+
+   This program will generate an attribute rule, write it out to an external
+           file and also load it into the context (prolog db)
+           [keyid:IceCream].delicious <- [Keyid:Chocolate]
+
+   Then, a query is made against the context to see if it is populated correctly.
+
+./abac_attr IceCream_ID.pem  IceCream_private.pem IceCream_attr.der Chocolate_ID.pem
+**/
+
+#define _GNU_SOURCE
+#include <err.h>
+#include <stdio.h>
+#include <assert.h>
+
+#include <abac.h>
+
+extern char *abac_id_keyid(abac_id_t *id);
+
+int main(int argc, char **argv) {
+    int i, success=0;
+    abac_credential_t *cred=NULL;
+    abac_credential_t **credentials=NULL;
+
+    abac_context_t *ctx = abac_context_new();
+
+    if(argc != 5) return 1;
+
+    /* build up structure */
+    abac_id_t *id =NULL;
+    id = abac_id_from_file(argv[1]);
+    int rc=abac_id_privkey_from_file(id,argv[2]);
+
+    rc=abac_context_load_id_chunk(ctx, abac_id_cert_chunk(id));
+
+    abac_id_t *chocolate_id = abac_id_from_file(argv[4]);
+    rc=abac_context_load_id_chunk(ctx, abac_id_cert_chunk(chocolate_id));
+
+    abac_attribute_t *attr;
+    rc=abac_attribute_create(&attr, id, "delicious", 1800);
+    abac_attribute_principal(attr, abac_id_keyid(chocolate_id));
+    rc=abac_attribute_bake(attr);
+
+    printf(" attribute being made : %s\n",abac_attribute_role_string(attr));
+
+    abac_attribute_write_file(attr,argv[3]);
+    abac_context_load_attribute_chunk(ctx,abac_attribute_cert_chunk(attr));
+
+    char *tmp=NULL;
+    asprintf(&tmp,"%s.delicious",abac_id_keyid(id));
+
+    /* make a query */
+    credentials = abac_context_query(ctx,
+        tmp, abac_id_keyid(chocolate_id),
+        &success
+    );
+    fprintf(stderr,"query with %s\n",tmp);
+    fprintf(stderr,"      for %s\n",abac_id_keyid(chocolate_id));
+    int sz=abac_list_size(credentials);
+
+    if (success)
+        puts("attr success");
+    else
+        puts("fail, here's a partial proof");
+
+    if (credentials != NULL)
+        for (i = 0; credentials[i] != NULL; ++i) {
+            cred = credentials[i];
+            printf("credential %s <- %s\n",
+                    abac_role_string(abac_credential_head(cred)),
+                    abac_role_string(abac_credential_tail(cred))
+                  );
+        }
+    abac_context_credentials_free(credentials);
+    abac_context_free(ctx);
+    return 0;
+}
Index: tests/example_scripts/c/abac_prover.c
===================================================================
--- tests/example_scripts/c/abac_prover.c	(revision ec550f769c681cfa831dc724f82ddacd21fc75cd)
+++ tests/example_scripts/c/abac_prover.c	(revision ec550f769c681cfa831dc724f82ddacd21fc75cd)
@@ -0,0 +1,99 @@
+/**
+   abac_prover.c
+
+   To demonstrate how to use ABAC's api in C to make a query
+
+   call:   abac_prover "keystorestring" "rolestring" "principalstring"
+
+   pre-condition: run make attr_abac  generate IceCream_ID.pem and IceCream_private.pem with
+
+   This program will make a prover call using 
+           rolestring <- principalstring
+
+**/
+
+#include <err.h>
+#include <stdio.h>
+#include <assert.h>
+#include <string.h>
+
+#include <abac.h>
+
+int main(int argc, char **argv) {
+    int i, success=0;
+    abac_credential_t *cred=NULL;
+    abac_credential_t **credentials=NULL;
+
+    abac_context_t *ctx = abac_context_new();
+    abac_context_load_directory(ctx, argv[1]);
+
+    char *query=strdup(argv[2]);
+    char *with=strdup(argv[3]);
+
+    printf("query %s \n", query);
+    printf("with %s\n", with);
+
+int k=1; /* use to do repetitions */
+while(k) {
+    credentials = abac_context_query(ctx,
+                            query, with,
+                            &success);
+    if (success)
+        puts("prover success!!");
+        else puts("prover failed!!");
+
+    if (credentials != NULL && success) {
+        puts("credentials needed :");
+        for (i = 0; credentials[i] != NULL; ++i) {
+           cred = credentials[i];
+           printf("credential %s <- %s\n",
+                    abac_role_string(abac_credential_head(cred)),
+                    abac_role_string(abac_credential_tail(cred)));
+        }
+    }
+    if(credentials)
+        abac_context_credentials_free(credentials);
+    k=k-1;
+}
+
+
+{ /* dump credentials from context */
+    printf("\n\n");
+    credentials = abac_context_credentials(ctx);
+    printf("Dump context credentials, original ctx \n");
+    if (credentials != NULL) {
+        puts("context credentials :");
+        for (i = 0; credentials[i] != NULL; ++i) {
+           cred = credentials[i];
+           printf("credential %s <- %s\n",
+                    abac_role_string(abac_credential_head(cred)),
+                    abac_role_string(abac_credential_tail(cred)));
+        }
+    }
+    if(credentials)
+        abac_context_credentials_free(credentials);
+}
+
+    abac_context_t *ctx2 = abac_context_dup(ctx);
+{ /* dump credentials from context */
+    printf("\n\n");
+    credentials = abac_context_credentials(ctx);
+    printf("Dump context credentials, original ctx2 \n");
+    if (credentials != NULL) {
+        puts("context credentials :");
+        for (i = 0; credentials[i] != NULL; ++i) {
+           cred = credentials[i];
+           printf("credential %s <- %s\n",
+                    abac_role_string(abac_credential_head(cred)),
+                    abac_role_string(abac_credential_tail(cred)));
+        }
+    }
+    if(credentials)
+        abac_context_credentials_free(credentials);
+}
+
+    abac_context_free(ctx);
+    abac_context_free(ctx2);
+
+    return 0;
+}
Index: tests/example_scripts/c/loader.c
===================================================================
--- tests/example_scripts/c/loader.c	(revision ec550f769c681cfa831dc724f82ddacd21fc75cd)
+++ tests/example_scripts/c/loader.c	(revision ec550f769c681cfa831dc724f82ddacd21fc75cd)
@@ -0,0 +1,100 @@
+/**
+CAN NOT RUN
+
+   loader.c
+
+   To demonstrate how to use ABAC's api in C to load credentials
+
+   some not implemented yet 
+
+   call:   abac_load 
+
+**/
+
+#include <err.h>
+#include <stdio.h>
+#include <assert.h>
+#include <string.h>
+
+#include <abac.h>
+
+int main(int argc, char **argv) {
+    int i, success=0;
+    abac_credential_t *cred=NULL;
+    abac_credential_t **credentials=NULL;
+
+    abac_context_t *ctx = abac_context_new();
+    int rc;
+
+fprintf(stderr, "\n         --- load from directory\n");
+    if(argc==2)
+        abac_context_load_directory(ctx, argv[1]); 
+        else
+            abac_context_load_directory(ctx, "."); 
+
+fprintf(stderr, "\n         --- load from chunk\n");
+    abac_id_t *tid;
+    abac_id_generate(&tid,"Tim", 0);
+    abac_chunk_t chunk=abac_id_cert_chunk(tid);
+    tid=abac_id_from_chunk(chunk);
+XXX  not implemented yet.. 
+    rc=abac_context_load_id(ctx,tid); 
+
+fprintf(stderr, "\n         --- load from id_gen\n");
+    abac_id_t *id;
+    abac_id_generate(&id,"Mary", 0);
+    abac_id_write_cert_fname(id,"Mary_ID.pem");
+    abac_id_write_privkey_fname(id,"Mary_private.pem");
+fprintf(stderr, "\n         --- load from explicit call\n");
+/*    int rc=abac_context_load_id_id_key_files(ctx,"Mary_ID.pem","Mary_private.pem"); */ 
+    rc=abac_context_load_id(ctx,id); 
+
+   
+fprintf(stderr, "\n         --- load with idkey file\n");
+    abac_id_t *id2;
+    abac_id_generate(&id2,"Tom", 0);
+    abac_id_write_cert_fname(id2,"Tom_IDKEY.pem");
+    abac_id_write_privkey_fname(id2,"Tom_IDKEY.pem");
+    rc=abac_context_load_id_file(ctx,"Tom_IDKEY.pem"); 
+
+{
+    printf("\n\n");
+    credentials = abac_context_credentials(ctx);
+    if (credentials != NULL) {
+        puts("context credentials :");
+        for (i = 0; credentials[i] != NULL; ++i) {
+           cred = credentials[i];
+           abac_print_typed_cred_info(cred,NULL);
+        }
+    }
+    if(credentials)
+        abac_free_credentials(credentials);
+}
+{
+    abac_id_credential_t *id_cred=NULL;
+    abac_id_credential_t **id_credentials=NULL;
+    printf("\n\n");
+    id_credentials = abac_context_principals(ctx);
+    if (id_credentials != NULL) {
+        puts("principal credentials :");
+        for (i = 0; id_credentials[i] != NULL; ++i) {
+           id_cred = id_credentials[i];
+           abac_print_prin_info(id_cred,NULL);
+        }
+    }
+    if(id_credentials)
+        abac_free_principals(id_credentials);
+}
+
+    show_yap_db("yap db");
+
+fprintf(stderr,"\n          --- id free from explicit call\n");
+    abac_id_free(id);
+    abac_id_free(id2);
+
+fprintf(stderr,"\n          --- explicitly free the context \n");
+    abac_context_free(ctx);
+
+fprintf(stderr,"\n          --- that is it \n");
+    return 0;
+}
Index: tests/example_scripts/c/run_prover
===================================================================
--- tests/example_scripts/c/run_prover	(revision ec550f769c681cfa831dc724f82ddacd21fc75cd)
+++ tests/example_scripts/c/run_prover	(revision ec550f769c681cfa831dc724f82ddacd21fc75cd)
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+keystore=`pwd`
+pID=`creddy --keyid --cert ${keystore}/IceCream_ID.pem`
+cID=`creddy --keyid --cert ${keystore}/Chocolate_ID.pem`
+
+role="${pID}.delicious"
+principal="${cID}"
+
+./abac_prover "$keystore" "$role" "$principal"
+
+#echo "$keystore" "$role" "$principal"
+#gdb ./abac_prover
+
+
+
Index: tests/example_scripts/c/run_test
===================================================================
--- tests/example_scripts/c/run_test	(revision ec550f769c681cfa831dc724f82ddacd21fc75cd)
+++ tests/example_scripts/c/run_test	(revision ec550f769c681cfa831dc724f82ddacd21fc75cd)
@@ -0,0 +1,22 @@
+#!/bin/sh 
+
+make -s clean
+
+echo '---running (c) attr script'
+make attr 1>/dev/null 2>& 1
+result=`grep "attr success" attr.log 2>/dev/null`
+if [ "$result" = "" ]; then
+   echo "   ERROR"
+else   
+   echo "   PASSED"
+fi
+
+echo '---running (c) prover script'
+make prove 1>/dev/null 2>& 1
+result=`grep "prover success" prover.log 2>/dev/null`
+if [ "$result" = "" ]; then
+   echo "   ERROR"
+else   
+   echo "   PASSED"
+fi
+
Index: tests/example_scripts/c/tbasic.c
===================================================================
--- tests/example_scripts/c/tbasic.c	(revision ec550f769c681cfa831dc724f82ddacd21fc75cd)
+++ tests/example_scripts/c/tbasic.c	(revision ec550f769c681cfa831dc724f82ddacd21fc75cd)
@@ -0,0 +1,27 @@
+/**
+   tbasic.c
+
+   bring up and taking down a context
+
+**/
+
+#include <err.h>
+#include <stdio.h>
+#include <assert.h>
+
+#include <abac.h>
+
+int main(int argc, char **argv) {
+    int i, success=0;
+    abac_credential_t *cred=NULL;
+    abac_credential_t **credentials=NULL;
+
+    printf("calling main ..\n");
+    abac_context_t *ctxt = abac_context_new();
+    abac_context_t *ctxt2 = abac_context_new();
+    printf("done calling main ..\n");
+
+    abac_context_free(ctxt2);
+
+    return 0;
+}
Index: tests/example_scripts/c/tchunk.c
===================================================================
--- tests/example_scripts/c/tchunk.c	(revision ec550f769c681cfa831dc724f82ddacd21fc75cd)
+++ tests/example_scripts/c/tchunk.c	(revision ec550f769c681cfa831dc724f82ddacd21fc75cd)
@@ -0,0 +1,41 @@
+/**
+CAN NOT RUN
+   tchunk.c
+   chunking test, no ready yet
+
+**/
+
+#include <err.h>
+#include <stdio.h>
+#include <assert.h>
+
+#include <abac.h>
+
+int main(int argc, char **argv) {
+    int rc;
+
+    abac_context_t *ctx = abac_context_new();
+
+    if(argc != 4) return 1;
+
+    /* build up structure */
+    abac_id_t *id =NULL;
+    id = abac_id_from_file(argv[2]);
+/*
+    int rc=abac_id_privkey_from_file(id,argv[3]);
+*/
+
+    int w=atoi(argv[1]);
+    if(w==0) {
+        printf("USING chunk...\n");
+        abac_id_t *nid=abac_id_from_chunk(abac_id_cert_chunk(id));
+        rc=abac_context_load_id_chunk(ctx, abac_id_cert_chunk(nid));
+    } else {
+        printf("USING NO chunk...\n");
+/* no implemented 
+        rc=abac_context_load_id_id(ctx, id);  
+*/
+    }
+    abac_context_free(ctx);
+    return 0;
+}
