[669b481] | 1 | |
---|
[137b55f] | 2 | |
---|
| 3 | /*** |
---|
| 4 | extract_doc.c, |
---|
| 5 | |
---|
| 6 | This program extract API doc file from libabac/abac.hh |
---|
| 7 | This program assume abac.hh is local or linked locally |
---|
| 8 | |
---|
| 9 | ***/ |
---|
[669b481] | 10 | #include <stdio.h> |
---|
| 11 | #include <stdlib.h> |
---|
| 12 | #include <string.h> |
---|
| 13 | |
---|
| 14 | char *sstr="/***"; |
---|
| 15 | char *estr="***/"; |
---|
| 16 | char *prestr="/***PRE"; |
---|
| 17 | char *poststr="/***POST"; |
---|
| 18 | |
---|
| 19 | void extract_p(FILE *in, FILE* out, char *match) |
---|
| 20 | { |
---|
| 21 | rewind(in); |
---|
| 22 | int yes=0; |
---|
| 23 | char *line=NULL; |
---|
| 24 | size_t num=0; |
---|
| 25 | int n=strlen(match); |
---|
| 26 | int nn=strlen(estr); |
---|
| 27 | while(getline(&line,&num,in) != -1) { |
---|
| 28 | if(!yes) { |
---|
| 29 | if(strncmp(match,line,n)==0) { |
---|
| 30 | yes=1; |
---|
| 31 | free(line); line=NULL; |
---|
| 32 | continue; |
---|
| 33 | } else { |
---|
| 34 | free(line); |
---|
| 35 | line=NULL; |
---|
| 36 | } |
---|
| 37 | }else { |
---|
| 38 | if(strncmp(estr,line, nn)==0) { |
---|
| 39 | yes=0; |
---|
| 40 | free(line); |
---|
| 41 | line=NULL; |
---|
| 42 | break; |
---|
| 43 | } else { |
---|
| 44 | fprintf(out,"%s",line); |
---|
| 45 | free(line); |
---|
| 46 | line=NULL; |
---|
| 47 | } |
---|
| 48 | } |
---|
| 49 | } |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | void extract(FILE* in, FILE* out, FILE *cout) |
---|
| 53 | { |
---|
| 54 | int yes=0; |
---|
| 55 | char *line=NULL; |
---|
| 56 | size_t num=0; |
---|
| 57 | int n=strlen(sstr); |
---|
| 58 | int nn=strlen(estr); |
---|
| 59 | while(getline(&line,&num,in) != -1) { |
---|
| 60 | if(!yes) { |
---|
| 61 | if(strncmp(sstr,line, n)==0) { |
---|
| 62 | yes=1; |
---|
| 63 | free(line); line=NULL; |
---|
| 64 | continue; |
---|
| 65 | } else { |
---|
| 66 | fprintf(cout,"%s",line); |
---|
| 67 | free(line); |
---|
| 68 | line=NULL; |
---|
| 69 | } |
---|
| 70 | }else { |
---|
| 71 | if(strncmp(estr,line, nn)==0) { |
---|
| 72 | yes=0; |
---|
| 73 | free(line); |
---|
| 74 | line=NULL; |
---|
| 75 | continue; |
---|
| 76 | } else { |
---|
| 77 | if(line[0]=='f') { |
---|
| 78 | line[0]=' '; |
---|
| 79 | fprintf(out,"\n"); |
---|
| 80 | } |
---|
| 81 | if(line[0]=='A') fprintf(out,"\n"); |
---|
| 82 | fprintf(out,"%s",line); |
---|
| 83 | free(line); |
---|
| 84 | line=NULL; |
---|
| 85 | } |
---|
| 86 | } |
---|
| 87 | } |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | int main() |
---|
| 91 | { |
---|
| 92 | char *selfname="extract_doc.c"; |
---|
| 93 | char *filename="abac.hh"; |
---|
| 94 | char *docname="API"; |
---|
| 95 | char *codename="ABAC_HH"; |
---|
| 96 | |
---|
| 97 | FILE *dfp=fopen(selfname,"r"); |
---|
| 98 | FILE *fp=fopen(filename,"r"); |
---|
| 99 | FILE *ofp=fopen(docname,"w"); |
---|
| 100 | FILE *cfp=fopen(codename,"w"); |
---|
| 101 | if(fp && dfp && ofp && cfp ) { |
---|
| 102 | extract_p(dfp,ofp,prestr); |
---|
| 103 | extract(fp,ofp,cfp); |
---|
| 104 | extract_p(dfp,ofp,poststr); |
---|
| 105 | fclose(fp); |
---|
| 106 | fclose(dfp); |
---|
| 107 | fclose(ofp); |
---|
| 108 | fclose(cfp); |
---|
| 109 | } |
---|
| 110 | return 0; |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | /***PRE |
---|
| 114 | C++ API |
---|
| 115 | |
---|
[4a72b30] | 116 | (see bottom for notes on C, Perl, Python and Java) |
---|
[669b481] | 117 | |
---|
| 118 | ABAC::abac_chunk_t |
---|
| 119 | Structure, represents a blob of memory |
---|
| 120 | used to load/return DER-encoded X509 certificates |
---|
| 121 | -unsigned char *data |
---|
| 122 | -int len |
---|
| 123 | ***/ |
---|
| 124 | |
---|
| 125 | |
---|
| 126 | /***POST |
---|
| 127 | C API |
---|
| 128 | |
---|
| 129 | The C API is nearly identical to the C++ API. Due to lack of namespaces, |
---|
| 130 | all function names are preceeded by abac_. Furthermore, the parameter |
---|
| 131 | representing the object must be passed explicitly. Each of the C++ calls |
---|
| 132 | are appended with a matching C routine call. The C function declaration |
---|
| 133 | can be found in abac.h |
---|
| 134 | |
---|
| 135 | Examples: |
---|
| 136 | |
---|
| 137 | C++: head.role_name() |
---|
| 138 | C: abac_role_name(head) |
---|
| 139 | or |
---|
| 140 | C++: ctxt.load_attribute_file("test_attr.der") |
---|
| 141 | C: abac_context_load_attribute_file(ctx, "test_attr.der") |
---|
| 142 | |
---|
| 143 | Instead of copy constructors, the C API uses _dup. Therefore, |
---|
| 144 | to copy a role use abac_aspect_dup(m_role), |
---|
| 145 | to copy a oset use abac_aspect_dup(m_oset), |
---|
| 146 | to copy a context use abac_context_dup(m_ctx), |
---|
| 147 | to copy a constraint use abac_condition_dup(m_constraint), |
---|
| 148 | to copy a data term use abac_term_dup(m_term), |
---|
| 149 | to copy a ID use abac_id_dup(m_id) |
---|
| 150 | and to copy an attribute use abac_attribute_dup(m_attr) |
---|
| 151 | |
---|
| 152 | Various flavors of abac_context_query() and abac_context_credentials() |
---|
| 153 | return NULL-terminated arrays of Attribute objects (abac_credential_t * in C). |
---|
| 154 | abac_context_principals() returns NULL-terminated array of ID objects |
---|
| 155 | (abac_id_credential_t * in C) |
---|
| 156 | |
---|
| 157 | When you are done with them, you must free the whole array at once using |
---|
| 158 | abac_context_credentials_free() and abac_context_principals_free() respectively. |
---|
| 159 | |
---|
[4a72b30] | 160 | PERL, PYTHON AND JAVA API |
---|
[669b481] | 161 | |
---|
[4a72b30] | 162 | The Perl, Python and Java APIs are even more similar to the C++ API. The main |
---|
[669b481] | 163 | changes are the use of native types instead of C/C++ types. |
---|
| 164 | |
---|
| 165 | - native strings instead of char * |
---|
| 166 | |
---|
[4a72b30] | 167 | Java: |
---|
| 168 | - String instead of char * |
---|
| 169 | - Context::query returns a vector of Credentials: |
---|
| 170 | credentials = ctx.query(role, principal) |
---|
| 171 | success if credentials' size is > 0 |
---|
| 172 | |
---|
[669b481] | 173 | Perl: |
---|
| 174 | - arrayref instead of vector |
---|
| 175 | - string instead of chunk_t |
---|
| 176 | - Context::query returns a list of two elements: |
---|
[4a72b30] | 177 | my ($success, $credentials) = $ctx->query($role, $principal) |
---|
[669b481] | 178 | $success is a boolean |
---|
| 179 | $credentials is an arrayref of Credential objects |
---|
| 180 | |
---|
| 181 | Python: |
---|
| 182 | - tuple instead of vector |
---|
| 183 | - bytearray instead of chunk_t (>= 2.6) |
---|
| 184 | - string instead of chunk_t (< 2.6) |
---|
| 185 | - Context::query returns a tuple with two elements: |
---|
| 186 | (success, credentials) = ctx.query(role, principal) |
---|
| 187 | success is a boolean |
---|
| 188 | credentials is a tuple of Credential objects |
---|
[4a72b30] | 189 | |
---|
[669b481] | 190 | ***/ |
---|