source: doc/extract_doc.c @ da045c2

mei_rt2
Last change on this file since da045c2 was 2e9455f, checked in by Mei <mei@…>, 12 years ago

1) added namespace
2) tweak ?This,
3) allowing linking role/oset as constraining conditions
4) adding access_tests regression testing that uses GENI's access policy
5) added couple multi contexts regression tests
6) add compression/uncompression calls to abac_encode_string/abac_decode_string
(libstrongwan only allows 512 char for attribute rule storage)
7) add attribute_now option to creddy that takes a whole char string for attribute
rule

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