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