Index: libabac/abac_pl_gen.c
===================================================================
--- libabac/abac_pl_gen.c	(revision abf8d5d6db95faab21303e9aef5e16dd7d6d2b03)
+++ libabac/abac_pl_gen.c	(revision 2e9455f11fea0205b8b4b1306b5d0804cda72e10)
@@ -12,7 +12,12 @@
 #include <stdlib.h>
 
+#include "abac_pl_gen.h"
 #include "abac_internal.h"
-#include "abac_set.h"
+#include "abac_list.h"
 #include "abac_util.h"
+#include "abac_context.h"
+#include "abac_aspect.h"
+#include "abac_term.h"
+#include "abac_verifier.h"
 
 #include "uthash.h"
@@ -30,33 +35,51 @@
     char *principalname;
     int type; /* keyidtype */
-    char *clause;
 } abac_id_cert_t;
 abac_list_t *abac_pl_id_certs = NULL;
 
-extern int using_this;
-
-extern char* abac_yyfptr_encoded;
-
-void generate_pl_set_abac_yyfptr_encoded(char *string)
-{
-   abac_yyfptr_encoded=abac_xstrdup(string);
-}
-
-char *generate_pl_type_clause(char *principalname, int type);
-
-
+static int gg_using_this=0;
+char* yyfptr_encode=NULL;
+
+
+/* local */
+char *generate_pl_type_clause(abac_context_t *,char *, int);
 /***********************************************************************/
-char *prologIt(char *str)
-{
-    char *tmp=NULL;
-    asprintf(&tmp,"p%s",str);
-    return tmp;
-}
-
+/* this is called by creddy as a shortcut */
+int generate_pl_clauses_dump(abac_context_t *ctxt, abac_aspect_t *head_aspect, 
+abac_aspect_t *tail_aspect, char *attr_string, char *encoded_attr_string, 
+char *filename, int using_this)
+{
+    FILE *out;
+    abac_list_t *clauses = generate_pl_clauses(ctxt,head_aspect, tail_aspect, encoded_attr_string,using_this);
+
+    int cnt=abac_list_size(clauses);
+    out = fopen(filename, "a+");
+    char *cur=NULL;
+    fprintf(out,"##########################################\n");
+    fprintf(out,"## %s <- %s\n", abac_aspect_string_with_condition(head_aspect),
+                                         abac_aspect_string_with_condition(tail_aspect));
+    fprintf(out,"## %s\n",attr_string);
+    abac_list_foreach(clauses, cur,
+        fprintf(out,"##\n%s\n",cur);
+        if(cur) free(cur);
+    );
+    fprintf(out,"\n");
+    fclose(out);
+    abac_list_free(clauses);
+    return cnt;
+}
+
+/***********************************************************************/
+static void _set_yyfptr_encode(char *string)
+{
+   yyfptr_encode=abac_xstrdup(string);
+}
+
+/***********************************************************************/
 static char* isX()
 {
-    static char x_string[2]="X";
-    static char this_string[5]="This";
-    if(using_this)
+static char x_string[2]="X";
+static char this_string[5]="This";
+    if(gg_using_this)
         return this_string;
         else 
@@ -156,5 +179,4 @@
         if(id) 
             free(id->principalname);
-            free(id->clause);
             free(id);
     );
@@ -168,16 +190,15 @@
 }
 
-char *abac_pl_string_id_certs()
-{
-    int first=1;
+char *abac_pl_string_id_certs(abac_context_t *ctxt)
+{
     char *tmp=NULL;
     abac_id_cert_t *cur;
     abac_list_foreach(abac_pl_id_certs, cur,
         if(cur) 
-            if(first) {
-                tmp=abac_xstrdup(cur->clause);
-                first=0;
+            if(tmp==NULL) {
+                tmp=generate_pl_type_clause(ctxt,cur->principalname,cur->type);
                 } else {
-                    int cnt=asprintf(&tmp,"%s,%s", tmp, cur->clause);
+                    asprintf(&tmp,"%s,%s", tmp,
+                        generate_pl_type_clause(ctxt,cur->principalname,cur->type));
             }
     );
@@ -213,5 +234,4 @@
             id_cert->principalname=abac_xstrdup(principalname);
             id_cert->type=type;
-            id_cert->clause=generate_pl_type_clause(principalname,type);
             abac_list_add(abac_pl_id_certs, id_cert);
     }
@@ -221,4 +241,5 @@
 /* generate role(p_name, r_name, param..)                              */
 /*          or oset(p_name, r_name, param..)                           */
+/* mainly for aspect that is if A.R <- B format                        */
 static char* generate_pl_head_string(abac_aspect_t *ptr)
 {
@@ -255,8 +276,9 @@
 /* generate role(p_name, r_name, param..) with isMember call ?? */
 /* generate oset(p_name, r_name, param..) with isMember call ?? */
-static char* generate_pl_tail_string(abac_aspect_t *ptr)
-{
-
+/* for aspect that could also be with linked role               */
+static char* generate_pl_tail_string(abac_context_t *ctxt,abac_aspect_t *ptr, char *varX)
+{
      char *tmp=NULL;
+     char *namespace=abac_context_namespace(ctxt);
 
 /* for oset case,
@@ -298,32 +320,24 @@
              if(linked_param_string !=NULL) {
                  if (param_string != NULL) {
-                     cnt=asprintf(&tmp,"isMember(Y,role(%s,%s,%s),C%d),isMember(%s,%s(Y,%s,%s),C%d)",
-                            principalname,
-                            linkedname,linked_param_string,fst,
-                            isX(), typestring,
-                            aspectname,param_string,snd);
+                     cnt=asprintf(&tmp,"isMember(%s,Y,role(%s,%s,%s),C%d),isMember(%s,%s,%s(Y,%s,%s),C%d)",
+                            namespace, principalname, linkedname,linked_param_string,fst,
+                            namespace,varX, typestring, aspectname,param_string,snd);
                      free(param_string);
                      } else {
-                         cnt=asprintf(&tmp,"isMember(Y,role(%s,%s,%s),C%d),isMember(%s,%s(Y,%s),C%d)",
-                            principalname,
-                            linkedname,linked_param_string,fst,
-                            isX(), typestring,
-                            aspectname,snd);
+                         cnt=asprintf(&tmp,"isMember(%s,Y,role(%s,%s,%s),C%d),isMember(%s,%s,%s(Y,%s),C%d)",
+                            namespace, principalname, linkedname,linked_param_string,fst,
+                            namespace, varX, typestring, aspectname,snd);
                  }
                  free(linked_param_string);
                  } else {
                      if (aspect_params != NULL) {
-                         cnt=asprintf(&tmp,"isMember(Y,role(%s,%s),C%d),isMember(%s,%s(Y,%s,%s),C%d)",
-                            principalname,
-                            linkedname,fst,
-                            isX(),typestring,
-                            aspectname,param_string,snd);
+                         cnt=asprintf(&tmp,"isMember(%s,Y,role(%s,%s),C%d),isMember(%s,%s,%s(Y,%s,%s),C%d)",
+                            namespace, principalname,linkedname,fst,
+                            namespace, varX,typestring, aspectname,param_string,snd);
                          free(param_string);
                          } else {
-                             cnt=asprintf(&tmp,"isMember(Y,role(%s,%s),C%d),isMember(%s,%s(Y,%s),C%d)",
-                                principalname,
-                                linkedname,fst,
-                                isX(),typestring,
-                                aspectname,snd);
+                             cnt=asprintf(&tmp,"isMember(%s,Y,role(%s,%s),C%d),isMember(%s,%s,%s(Y,%s),C%d)",
+                                namespace, principalname, linkedname,fst,
+                                namespace, varX,typestring, aspectname,snd);
                    }
              }
@@ -337,11 +351,11 @@
              int fst=_get_next_cred_idx();
              if(param_string != NULL) {
-                 cnt=asprintf(&tmp,"isMember(%s,%s(%s,%s,%s),C%d)",
-                              isX(),typestring,
+                 cnt=asprintf(&tmp,"isMember(%s,%s,%s(%s,%s,%s),C%d)",
+                              namespace,varX,typestring,
                               principalname, aspectname, param_string, fst);
                  free(param_string);
                  } else {
-                     cnt=asprintf(&tmp,"isMember(%s,%s(%s,%s),C%d)",
-                              isX(), typestring,
+                     cnt=asprintf(&tmp,"isMember(%s,%s,%s(%s,%s),C%d)",
+                              namespace,varX, typestring,
                               principalname, aspectname, fst);
              }
@@ -365,36 +379,38 @@
 /********************************************************************************/
 
-static char *_build_constraint_rule_clause(char *head_string, char *tail_string)
-{
-    /*only,  A.R <- B */
+static char *_build_constraint_rule_clause(abac_context_t *ctxt,char *head_string, char *tail_string)
+{
+    /*for  A.R <- B */
     if(debug) 
          fprintf(stderr,"calling _build_constraint_rule_clause (%s)(%s)\n", head_string, tail_string);
     char *tmp;
     int idx=_get_next_cred_idx();
-    asprintf(&tmp, "isMember(%s,%s,C%d)", tail_string,head_string,idx);
-    return tmp;
-}
-
-static char *_build_rule_clause(char *aspectname, char *head_string,
-char *tail_string, char *id_string, char *constraint_string)
+    asprintf(&tmp, "isMember(%s,%s,%s,C%d)", 
+              abac_context_namespace(ctxt),tail_string,head_string,idx);
+    return tmp;
+}
+
+static char *_build_rule_clause(abac_context_t *ctxt, char *aspectname, char *head_string,
+char *tail_string, char *id_string, char *constraint_string, char *varX)
 {
     char *tmp=NULL;
+    char *namespace=abac_context_namespace(ctxt);
 
     if(aspectname == NULL) {
         /* A.R <- B */
         if(id_string == NULL && constraint_string == NULL) {
-            asprintf(&tmp, "isMember(%s,%s,['%s'])",
-                     tail_string,head_string,abac_yyfptr_encoded);
+            asprintf(&tmp, "isMember(%s,%s,%s,['%s'])",
+                     namespace, tail_string,head_string,yyfptr_encode);
             } else {
                 if(id_string == NULL) {
-                    asprintf(&tmp, "isMember(%s,%s,['%s']) :- %s",
-                         tail_string,head_string,abac_yyfptr_encoded,
+                    asprintf(&tmp, "isMember(%s,%s,%s,['%s']) :- %s",
+                         namespace, tail_string,head_string,yyfptr_encode,
                          constraint_string);
                 } else if(constraint_string == NULL) {
-                    asprintf(&tmp, "isMember(%s,%s,['%s']) :- %s",
-                         tail_string,head_string,abac_yyfptr_encoded,
+                    asprintf(&tmp, "isMember(%s,%s,%s,['%s']) :- %s",
+                         namespace, tail_string,head_string,yyfptr_encode,
                          id_string);
-                } else { asprintf(&tmp, "isMember(%s,%s,['%s']) :- %s,%s",
-                         tail_string,head_string,abac_yyfptr_encoded,
+                } else { asprintf(&tmp, "isMember(%s,%s,%s,['%s']) :- %s,%s",
+                         namespace, tail_string,head_string,yyfptr_encode,
                          id_string, constraint_string);
                 }
@@ -405,22 +421,22 @@
              if (cred_count==0) {
                  if(id_string == NULL && constraint_string == NULL) {
-                     asprintf(&tmp,"isMember(%s,%s,['%s']):-%s",
-                           isX(),
-                           head_string, abac_yyfptr_encoded, tail_string);
+                     asprintf(&tmp,"isMember(%s,%s,%s,['%s']):-%s",
+                           namespace,varX,
+                           head_string, yyfptr_encode, tail_string);
                      } else {
                          if(id_string == NULL) {
-                             asprintf(&tmp,"isMember(%s,%s,['%s']):-%s,%s",
-                                 isX(),
-                                 head_string, abac_yyfptr_encoded, tail_string,
+                             asprintf(&tmp,"isMember(%s,%s,%s,['%s']):-%s,%s",
+                                 namespace,varX,
+                                 head_string, yyfptr_encode, tail_string,
                                  constraint_string);
                          } else if(constraint_string == NULL) {
-                             asprintf(&tmp,"isMember(%s,%s,['%s']):-%s,%s",
-                                 isX(),
-                                 head_string, abac_yyfptr_encoded, id_string,
+                             asprintf(&tmp,"isMember(%s,%s,%s,['%s']):-%s,%s",
+                                 namespace,varX,
+                                 head_string, yyfptr_encode, id_string,
                                  tail_string);
                          } else { 
-                             asprintf(&tmp,"isMember(%s,%s,['%s']):-%s,%s,%s",
-                                 isX(),
-                                 head_string, abac_yyfptr_encoded, id_string,
+                             asprintf(&tmp,"isMember(%s,%s,%s,['%s']):-%s,%s,%s",
+                                 namespace,varX,
+                                 head_string, yyfptr_encode, id_string,
                                  tail_string, constraint_string);
                          }
@@ -429,25 +445,25 @@
                      char *tmp_cred_list=_compose_cred_list();
                      if(id_string == NULL && constraint_string == NULL) {
-                         asprintf(&tmp,"isMember(%s,%s,L):-%s, appendL([['%s'],%s],L)",
-                                  isX(),
+                         asprintf(&tmp,"isMember(%s,%s,%s,L):-%s, appendL([['%s'],%s],L)",
+                                  namespace,varX,
                                   head_string, tail_string,
-                                  abac_yyfptr_encoded, tmp_cred_list);
+                                  yyfptr_encode, tmp_cred_list);
                          } else {
                             if(id_string == NULL) {
-                               asprintf(&tmp,"isMember(%s,%s,L):-%s, %s, appendL([['%s'],%s],L)",
-                                  isX(),
+                               asprintf(&tmp,"isMember(%s,%s,%s,L):-%s, %s, appendL([['%s'],%s],L)",
+                                  namespace,varX,
                                   head_string, tail_string, constraint_string,
-                                  abac_yyfptr_encoded, tmp_cred_list);
+                                  yyfptr_encode, tmp_cred_list);
                             } else if(constraint_string == NULL) {
-                               asprintf(&tmp,"isMember(%s,%s,L):-%s, %s, appendL([['%s'],%s],L)",
-                                  isX(),
+                               asprintf(&tmp,"isMember(%s,%s,%s,L):-%s, %s, appendL([['%s'],%s],L)",
+                                  namespace,varX,
                                   head_string, id_string, tail_string,
-                                  abac_yyfptr_encoded, tmp_cred_list);
+                                  yyfptr_encode, tmp_cred_list);
                             } else { 
-                               asprintf(&tmp,"isMember(%s,%s,L):-%s, %s, %s, appendL([['%s'],%s],L)",
-                                  isX(),
+                               asprintf(&tmp,"isMember(%s,%s,%s,L):-%s, %s, %s, appendL([['%s'],%s],L)",
+                                  namespace,varX,
                                   head_string, id_string, tail_string,
                                   constraint_string,
-                                  abac_yyfptr_encoded, tmp_cred_list);
+                                  yyfptr_encode, tmp_cred_list);
                             }
                      }
@@ -460,13 +476,13 @@
 
 
-static char *generate_pl_rule_clause(char *head_rule_string,
-abac_aspect_t *tail_rule, char *id_string, char *constraint_string)
+static char *generate_pl_rule_clause(abac_context_t *ctxt,char *head_rule_string,
+abac_aspect_t *tail_rule, char *id_string, char *constraint_string, char* varX)
 {
     char *aspectname=abac_aspect_aspect_name(tail_rule);
-    char *tail_rule_string=generate_pl_tail_string(tail_rule);
+    char *tail_rule_string=generate_pl_tail_string(ctxt,tail_rule,varX);
     if(aspectname == NULL && tail_rule_string == NULL) 
         goto error;
-    char *tmp=_build_rule_clause(aspectname,head_rule_string, tail_rule_string,
-                                          id_string, constraint_string);
+    char *tmp=_build_rule_clause(ctxt,aspectname,
+                head_rule_string, tail_rule_string, id_string, constraint_string, varX);
     if(tail_rule_string) free(tail_rule_string);
     return tmp;
@@ -492,29 +508,31 @@
 }
 
-static char *_build_intersecting_clause(char *head_role_string,
-char *tail_role_string, char* id_string, char* constraint_string)
+static char *_build_intersecting_clause(abac_context_t *ctxt, 
+char *head_role_string, char *tail_role_string, char* id_string,
+char* constraint_string,char *varX)
 {
     char *tmp;
+    char *namespace=abac_context_namespace(ctxt);
 
     if (cred_count==0) {
         if(id_string == NULL && constraint_string == NULL) {
-            asprintf(&tmp,"isMember(%s,%s,['%s']):-%s",
-                   isX(),
-                   head_role_string, abac_yyfptr_encoded, tail_role_string);
+            asprintf(&tmp,"isMember(%s,%s,%s,['%s']):-%s",
+                   namespace,varX,
+                   head_role_string, yyfptr_encode, tail_role_string);
             } else {
              if(id_string == NULL) {
-                asprintf(&tmp,"isMember(%s,%s,['%s']):-%s, %s",
-                       isX(),
-                       head_role_string, abac_yyfptr_encoded, 
+                asprintf(&tmp,"isMember(%s,%s,%s,['%s']):-%s, %s",
+                       namespace,varX,
+                       head_role_string, yyfptr_encode, 
                        tail_role_string, constraint_string);
              } else if(constraint_string == NULL) {
-                asprintf(&tmp,"isMember(%s,%s,['%s']):-%s, %s",
-                       isX(),
-                       head_role_string, abac_yyfptr_encoded, 
+                asprintf(&tmp,"isMember(%s,%s,%s,['%s']):-%s, %s",
+                       namespace,varX,
+                       head_role_string, yyfptr_encode, 
                        id_string, tail_role_string);
              } else {    
-                asprintf(&tmp,"isMember(%s,%s,['%s']):-%s, %s, %s",
-                       isX(),
-                       head_role_string, abac_yyfptr_encoded, 
+                asprintf(&tmp,"isMember(%s,%s,%s,['%s']):-%s, %s, %s",
+                       namespace,varX,
+                       head_role_string, yyfptr_encode, 
                        id_string, tail_role_string, constraint_string);
              }           
@@ -523,24 +541,24 @@
             char *tmp_cred_list=_compose_cred_list();
             if(id_string == NULL && constraint_string == NULL) {
-                asprintf(&tmp,"isMember(%s,%s,L):-%s, appendL([['%s'],%s],L)",
-                                isX(),
+                asprintf(&tmp,"isMember(%s,%s,%s,L):-%s, appendL([['%s'],%s],L)",
+                                namespace,varX,
                                 head_role_string, tail_role_string,
-                                abac_yyfptr_encoded, tmp_cred_list);
+                                yyfptr_encode, tmp_cred_list);
                 } else {
                     if(id_string == NULL) {
-                        asprintf(&tmp,"isMember(%s,%s,L):-%s, %s, appendL([['%s'],%s],L)",
-                            isX(),
+                        asprintf(&tmp,"isMember(%s,%s,%s,L):-%s, %s, appendL([['%s'],%s],L)",
+                            namespace,varX,
                             head_role_string, tail_role_string, constraint_string,
-                            abac_yyfptr_encoded, tmp_cred_list);
+                            yyfptr_encode, tmp_cred_list);
                     } else if(constraint_string == NULL) {
-                        asprintf(&tmp,"isMember(%s,%s,L):-%s, %s, appendL([['%s'],%s],L)",
-                            isX(),
+                        asprintf(&tmp,"isMember(%s,%s,%s,L):-%s, %s, appendL([['%s'],%s],L)",
+                            namespace,varX,
                             head_role_string, id_string, tail_role_string,
-                            abac_yyfptr_encoded, tmp_cred_list);
+                            yyfptr_encode, tmp_cred_list);
                     } else {    
-                        asprintf(&tmp,"isMember(%s,%s,L):-%s, %s, %s, appendL([['%s'],%s],L)",
-                            isX(),
+                        asprintf(&tmp,"isMember(%s,%s,%s,L):-%s, %s, %s, appendL([['%s'],%s],L)",
+                            namespace,varX,
                             head_role_string, id_string, tail_role_string, constraint_string,
-                            abac_yyfptr_encoded, tmp_cred_list);
+                            yyfptr_encode, tmp_cred_list);
                     }           
             }
@@ -551,6 +569,7 @@
 }
 
-static char *generate_pl_intersecting_clause(char *head_role_string,
-abac_aspect_t *tail_role, char* id_string, char* constraint_string)
+static char *generate_pl_intersecting_clause(abac_context_t *ctxt,
+char *head_role_string, abac_aspect_t *tail_role, char* id_string,
+char* constraint_string, char *varX)
 {
     char *tmp=NULL;
@@ -563,5 +582,5 @@
         abac_aspect_t *cur;
         abac_list_foreach(list, cur,
-            char *ntmp=generate_pl_tail_string(cur);
+            char *ntmp=generate_pl_tail_string(ctxt,cur,varX);
             if(debug) fprintf(stderr,"  intersecting tail: (%s)\n",ntmp);
             if(tail_role_string==NULL) {
@@ -578,11 +597,15 @@
 
     if(debug) fprintf(stderr,"      final intersecting tail: (%s)\n",tail_role_string);
-    tmp=_build_intersecting_clause(head_role_string, tail_role_string, id_string,constraint_string);
+    tmp=_build_intersecting_clause(ctxt,head_role_string, tail_role_string,
+                                                 id_string,constraint_string, varX);
     if(tail_role_string) free(tail_role_string);
     return tmp;
 }
 
+/**** THIS NEEDS TO BE LOCKED *****/
+/* XXXX */
 /* generate the prolog isMember rule clause for the credential stmt */
-abac_list_t *generate_pl_clauses(abac_aspect_t *head_aspect, abac_aspect_t *tail_aspect)
+abac_list_t *generate_pl_clauses(abac_context_t *ctxt,abac_aspect_t *head_aspect,
+abac_aspect_t *tail_aspect,char *encoded_attr_string, int using_this)
 {
    char *tmp=NULL;
@@ -590,8 +613,17 @@
    char *constraint_clauses_string=NULL;
    abac_list_t *clauses=abac_list_new();
-  
+ 
+   gg_using_this=using_this;
+
+   if(encoded_attr_string!=NULL)
+       _set_yyfptr_encode(encoded_attr_string);
+
+   /* preprocess both sides first */
+   preprocess_pl_head(ctxt,head_aspect);
+   preprocess_pl_tail(ctxt,tail_aspect);
+
    int cnt=abac_pl_cnt_id_certs();
    if(cnt > 0) { /* string it up */
-       id_clauses_string=abac_pl_string_id_certs();
+       id_clauses_string=abac_pl_string_id_certs(ctxt);
        abac_pl_free_id_certs();
    }
@@ -611,9 +643,9 @@
 /* tail side */
     if(abac_aspect_is_intersection(tail_aspect)) {
-       tmp=generate_pl_intersecting_clause(head_string, tail_aspect,
-                    id_clauses_string, constraint_clauses_string);
+       tmp=generate_pl_intersecting_clause(ctxt,head_string, tail_aspect,
+                    id_clauses_string, constraint_clauses_string, isX());
        } else {
-           tmp=generate_pl_rule_clause(head_string, tail_aspect,
-                    id_clauses_string, constraint_clauses_string);
+           tmp=generate_pl_rule_clause(ctxt,head_string, tail_aspect,
+                    id_clauses_string, constraint_clauses_string, isX());
     }
     if(tmp==NULL)
@@ -630,22 +662,26 @@
 }
 
-/* should be just 1 */
-char *generate_pl_constraint_clause(abac_aspect_t *head_aspect, char *tail_string)
-{
-/* generate head's role or oset string */
-    char *head_string=generate_pl_head_string(head_aspect);
-    if(head_string == NULL)
-        goto error;
-
-/* tail side */
-    char *tmp=_build_constraint_rule_clause(head_string, tail_string);
-    if(tmp==NULL)
-        goto error;
-
-    return tmp;
+char *generate_pl_constraint_clause(abac_context_t *ctxt,abac_aspect_t *head_aspect, char *tail_string)
+{
+    char *tmp=NULL;
+    char *head_string=NULL;
+
+    if(abac_aspect_is_linking(head_aspect)) { /* leverage on its b.r.r gen code */
+        tmp= generate_pl_tail_string(ctxt,head_aspect,tail_string); 
+        } else {
+            /* generate head's role or oset string */
+            char *head_string=generate_pl_head_string(head_aspect);
+            if(head_string == NULL)
+                goto error;
+
+            /* tail side */
+           tmp=_build_constraint_rule_clause(ctxt,head_string, tail_string);
+           if(tmp==NULL) goto error;
+           if(head_string) free(head_string);
+    }
 
 error:
     if(head_string) free(head_string);
-    return NULL;
+    return tmp;
 }
 
@@ -671,6 +707,6 @@
 
 /* generate the prolog isType rule clause for the type,
-   isType(Acme, keyid); */
-char *generate_pl_type_clause(char *principalname, int type)
+   isType(namespace,Acme, keyid); */
+char *generate_pl_type_clause(abac_context_t *ctxt,char *principalname, int type)
 {
     char *tmp=NULL;
@@ -680,7 +716,7 @@
     if(debug)
         fprintf(stderr,"generate type clause, (%s)\n", principalname);
-    int cnt=asprintf(&tmp,"isType(%s,%s)",
-                                principalname, typeid);
-    return tmp;
-}
-
+    int cnt=asprintf(&tmp,"isType(%s,%s,%s)",
+                 abac_context_namespace(ctxt),principalname, typeid);
+    return tmp;
+}
+
