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