source: doc/extract_doc.c @ 669b481

mei_rt2mei_rt2_fix_1
Last change on this file since 669b481 was 669b481, checked in by Mei <mei@…>, 12 years ago

1) finish test conversion from creddy-prover to python
2) update the abac.hh/API doc more, adding more intermediate calls

to make abac.hh more uniform

3) found out why a very long attribute rule can not survive in/out of

ietf_attribute_t call (m64 en/decoding - abac_verifier, alice_rt1)

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