Index: libabac/abac.hh
===================================================================
--- libabac/abac.hh	(revision ca729633d149b3b9965cc136a8352969ce25c876)
+++ libabac/abac.hh	(revision 5110d428b9de9f6ec063a033dfe605950456dc4f)
@@ -11,5 +11,4 @@
 
     static int debug=0;
-
 
     class Role;
@@ -267,8 +266,11 @@
             Oset(abac_aspect_t *oset): m_oset(abac_aspect_dup(oset)) 
               { }
-            Oset(char *oset_name) : m_oset(abac_aspect_role_principal_create(oset_name)) 
+            Oset(char *oset_name) : m_oset(abac_aspect_oset_principal_create(oset_name)) 
               { }
             Oset(char *principal_name, char *oset_name) : 
                m_oset(abac_aspect_oset_create(principal_name, oset_name)) 
+              { }
+            Oset(DataTerm& d) :
+               m_oset(abac_aspect_oset_object_create(d.term())) 
               { }
             Oset(const Oset &oset) { 
@@ -352,4 +354,9 @@
             ID(abac_id_t *id): m_id(abac_id_dup(id)) 
               { }
+            ID(abac_id_credential_t *idcred) {
+                if(idcred)
+                  m_id=abac_id_dup(abac_id_credential_id(idcred));
+                else m_id=NULL;
+              }
             ID(const ID &id) { m_id =abac_id_dup(id.m_id); }
             ~ID() { if(m_id) abac_id_free(m_id); }
@@ -374,5 +381,5 @@
    will throw an exception if the key cannot be loaded */
             void load_privkey(char *filename) {
-                int rt=abac_id_load_privkey(m_id, filename);
+                int rt=abac_id_load_privkey_file(m_id, filename);
                 if(rt != 1) 
                   abac_errx(1, "Failed to load private key");
@@ -382,6 +389,5 @@
 /* returns the SHA1 keyid of the cert */
             char *keyid() { return abac_id_keyid(m_id); }
-/* returns the CN (the parameter passed to the constructor or the
-   CN of the cert). */
+/* returns the CN */
             char *name() { return abac_id_cn(m_id); }
 /* returns true if the ID has an associated private key */
@@ -395,5 +401,5 @@
 /* writes a PEM-encoded cert to a file named out */
             void write_cert(char *filename) {
-                FILE *out = fopen(filename, "w");
+                FILE *out = fopen(filename, "a");
                 write_cert(out);
                 fclose(out);
@@ -409,5 +415,5 @@
    throws an exception if no private key is loaded */
             void write_privkey(char *filename) {
-                FILE *out = fopen(filename, "w");
+                FILE *out = fopen(filename, "a");
                 write_privkey(out);
                 fclose(out);
@@ -418,4 +424,11 @@
             abac_chunk_t cert_chunk() {
                 return abac_id_cert_chunk(m_id);
+              }
+            char *string() {
+                char *tmp=NULL;
+                if(has_privkey())
+                  asprintf(&tmp,"(%s,%s,y)",abac_id_name(m_id),abac_id_idtype_string(m_id));
+                  else asprintf(&tmp,"(%s,%s,n)",abac_id_name(m_id),abac_id_idtype_string(m_id));
+                return tmp;
               }
         public:
@@ -613,6 +626,9 @@
                 return abac_context_load_id_id(m_ctx, id.id());
               }
+            int load_id_file(char *filename) {
+                return abac_context_load_id_idkey_file(m_ctx, filename);
+              }
             int load_id_file(char *filename, char *keyfilename) {
-                return abac_context_load_id_file(m_ctx, filename, keyfilename);
+                return abac_context_load_id_id_file_key_file(m_ctx, filename, keyfilename);
               }
             int load_id_chunk(abac_chunk_t cert) { 
@@ -641,4 +657,6 @@
    returns true/false in success
    returns a proof upon success, partial proof on failure */
+/* the string version is for query that is composed by hand with SHA or
+   in non ABAC_CN mode  */
             std::vector<Attribute> query(char *role, char *principal, bool &success) {
                  abac_credential_t **creds, **end;
@@ -653,7 +671,64 @@
                  end = &creds[i];
                  std::vector<Attribute> attributes = std::vector<Attribute>(creds, end);
-                 if(debug) printf("rules, got (%d)\n", i);
+                 if(debug) printf("query, got rules(%d)\n", i);
 
                  abac_context_credentials_free(creds);
+
+                 return attributes;
+              }
+
+/* another way */
+            std::vector<Attribute> query(Role &role, Role &p_role, bool &success) {
+                 abac_credential_t **creds, **end;
+                 int i, success_int;
+
+                 /* make sure retrieving SHA not CN embedded string */
+                 ABAC_IN_QUERY=1;
+                 char *role_str=role.typed_string();
+                 char *p_role_str=p_role.typed_string();
+                 ABAC_IN_QUERY=0;
+                 if(debug) { 
+                     printf("query with %s\n",role_str);
+                     printf("    and %s\n",p_role_str);
+                 }
+                 creds = abac_context_query(m_ctx, role_str, p_role_str, &success_int);
+                 success = success_int;
+
+                 for (i = 0; creds[i] != NULL; ++i)
+                    ;
+
+                 end = &creds[i];
+                 std::vector<Attribute> attributes = std::vector<Attribute>(creds, end);
+
+                 abac_context_credentials_free(creds);
+                 free(role_str);
+                 free(p_role_str);
+
+                 return attributes;
+              }
+
+            std::vector<Attribute> query(Oset &oset, Oset &p_oset, bool &success) {
+                 abac_credential_t **creds, **end;
+                 int i, success_int;
+                 /* make sure retrieving SHA not CN embedded string */
+              
+                 ABAC_IN_QUERY++;
+                 char *oset_str=oset.typed_string();
+                 char *p_oset_str=p_oset.typed_string();
+                 ABAC_IN_QUERY--;
+
+                 creds = abac_context_query(m_ctx, oset_str, p_oset_str, &success_int);
+                 success = success_int;
+
+                 for (i = 0; creds[i] != NULL; ++i)
+                    ;
+
+                 end = &creds[i];
+                 std::vector<Attribute> attributes = std::vector<Attribute>(creds, end);
+                 if(debug) printf("query, returning rules(%d)\n", i);
+
+                 abac_context_credentials_free(creds);
+                 free(oset_str);
+                 free(p_oset_str);
 
                  return attributes;
@@ -678,4 +753,22 @@
                 return attributes;
               }
+
+/* returns a vector of all the principals loaded in the context */
+            std::vector<ID> context_principals(bool &success) {
+                abac_id_credential_t **ids, **end;
+                int i;
+                success = 1;
+
+                ids = abac_context_principals(m_ctx);
+                for (i = 0; ids[i] != NULL; ++i)
+                    ;
+
+                end = &ids[i];
+                std::vector<ID> principals = std::vector<ID>(ids, end);
+                if(debug) printf("principals, got (%d)\n", i);
+
+                abac_context_principals_free(ids);
+                return principals;
+              }
             
             char *version() const { return m_abac_version; }
