source: doc/extract_doc.c @ c46b2fe

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

1) upgraded to use strongswan-4.6.4

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