source: doc/extract_doc.c @ bac5e14

abac0-leakabac0-meimei-idmei-rt0-nmei_rt0tvf-new-xml
Last change on this file since bac5e14 was e197b65, checked in by Mei <mei@…>, 12 years ago

1) added some doc

  • Property mode set to 100644
File size: 5.1 KB
Line 
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 
8rules:
91) Enclosed lines within slashes with triple stars(/***,***SLASH/) need
10to be extracted
112) line start with 'f', add a new line
123) Enclosed lines with tripple stars and 2 i's (/*ii**. **ii*SLASH/)
13are 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
22char *sstr="/***";
23char *estr="***/";
24char *prestr="/***PRE";
25char *poststr="/***POST";
26
27void 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
60void 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
98int 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
122C++ API
123
124(see bottom for notes on C, Perl, Python and Java)
125
126ABAC::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
135C API
136
137The C API is nearly identical to the C++ API. Due to lack of namespaces,
138all function names are preceeded by abac_. Furthermore, the parameter
139representing the object must be passed explicitly. Each of the C++ calls
140are appended with a matching C routine call. The C function declaration
141can be found in abac.h
142
143Examples:
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
151Instead of copy constructors, the C API uses _dup.  Therefore,
152to copy a role use abac_role_dup(m_role),
153to copy a context use abac_context_dup(m_ctxt),
154to copy a ID use abac_id_dup(m_id)
155and to copy an attribute use abac_attribute_dup(m_attr)
156
157abac_context_query() and abac_context_credentials() return
158NULL-terminated arrays of Credential objects (abac_credential_t * in C).
159When you are done with them, you must free the whole array at once using
160abac_context_credentials_free().
161
162PERL, PYTHON AND JAVA API
163
164The Perl, Python and Java APIs are even more similar to the C++ API. The main
165changes 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***/
Note: See TracBrowser for help on using the repository browser.