source: doc/extract_doc.c @ 1bf0f03

abac0-leakabac0-mei
Last change on this file since 1bf0f03 was 3c30b59, checked in by Mei <mei@…>, 11 years ago

1) add in new refactored regression testing directory
2) undo the abac.hh/ABAC.hh api changes
3) merged with Ted's changes to attribute format/nickname/issuer processing

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