Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/lib/libcodex/codex.h
1808 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 2003-2011 AT&T Intellectual Property *
5
* and is licensed under the *
6
* Eclipse Public License, Version 1.0 *
7
* by AT&T Intellectual Property *
8
* *
9
* A copy of the License is available at *
10
* http://www.eclipse.org/org/documents/epl-v10.html *
11
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12
* *
13
* Information and Software Systems Research *
14
* AT&T Research *
15
* Florham Park NJ *
16
* *
17
* Glenn Fowler <[email protected]> *
18
* David Korn <[email protected]> *
19
* Phong Vo <[email protected]> *
20
* *
21
***********************************************************************/
22
#pragma prototyped
23
24
/*
25
* codex public interface
26
*/
27
28
#ifndef _CODEX_H
29
#define _CODEX_H 1
30
31
#include <ast.h>
32
#include <error.h>
33
34
#define CODEX_VERSION 20090704L
35
#define CODEX_PLUGIN_VERSION AST_PLUGIN_VERSION(CODEX_VERSION)
36
37
#define CODEX_DECODE 0x0001 /* decode supported */
38
#define CODEX_ENCODE 0x0002 /* encode supported */
39
40
#define CODEX_RETAIN 0x0010 /* initf-donef retain state */
41
#define CODEX_INVERT 0x0020 /* invert composition */
42
#define CODEX_TRACE 0x0040 /* enable trace */
43
#define CODEX_VERBOSE 0x0080 /* enable verbose trace */
44
45
#define CODEX_COMPRESS 0x0100 /* compression */
46
#define CODEX_CRYPT 0x0200 /* encryption */
47
#define CODEX_ICONV 0x0400 /* character code translation */
48
#define CODEX_SUM 0x0800 /* checksum */
49
#define CODEX_UU 0x1000 /* uuencode (ISO text) */
50
51
#define CODEX_CACHED 0x10000000L /* cached entry */
52
#define CODEX_SERIAL 0x20000000L /* serial number assigned */
53
#define CODEX_FLUSH 0x40000000L /* flush-only sync */
54
#define CODEX_ACTIVE 0x80000000L /* active cache entry */
55
56
#define CODEX_IDENT 1024 /* max ident buffer size */
57
#define CODEX_NAME 256 /* max coder name w/args */
58
#define CODEX_ARGS 32 /* max coder args in name */
59
60
#define CODEX(d) ((Codex_t*)(d))
61
62
typedef uint32_t Codexnum_t;
63
64
struct Codex_s; typedef struct Codex_s Codex_t;
65
struct Codexdata_s; typedef struct Codexdata_s Codexdata_t;
66
struct Codexdisc_s; typedef struct Codexdisc_s Codexdisc_t;
67
struct Codexmeth_s; typedef struct Codexmeth_s Codexmeth_t;
68
69
typedef Codexmeth_t* (*Codexlib_f)(const char*);
70
71
struct Codex_s /* coder public state */
72
{
73
Sfdisc_t sfdisc; /* coder sfio discipline */
74
Sfio_t* sp; /* data base stream */
75
Sfio_t* dp; /* optional data delta stream */
76
Sfoff_t size; /* expected size if != -1 */
77
Codexdisc_t* disc; /* coder discipline */
78
Codexmeth_t* meth; /* coder method */
79
Codexnum_t flags; /* CODEX_* flags */
80
Codexnum_t index; /* per-process index */
81
int serial; /* codex() serial number */
82
void* data; /* coder private state */
83
Sfio_t* op; /* original stream */
84
};
85
86
struct Codexdata_s /* codexdata() info */
87
{
88
Codexnum_t size; /* value size */
89
Codexnum_t num; /* value if buf!=0 */
90
void* buf; /* size byte value */
91
};
92
93
struct Codexdisc_s /* coder discipline */
94
{
95
Codexnum_t version; /* CODEX_VERSION */
96
Error_f errorf; /* error message function */
97
ssize_t (*passf)(void*, size_t, Codexdisc_t*, Codexmeth_t*);
98
const char* passphrase; /* passphrase */
99
Sfio_t* identify; /* decode method string if != 0 */
100
};
101
102
struct Codexmeth_s /* coder method */
103
{
104
const char* name; /* coder name */
105
const char* description; /* coder description */
106
const char* options; /* static optget() options */
107
Codexnum_t flags; /* CODEX_* flags */
108
109
int (*optionsf)(Codexmeth_t*, Sfio_t*);
110
int (*identf)(Codexmeth_t*, const void*, size_t, char*, size_t);
111
int (*openf)(Codex_t*, char* const[], Codexnum_t);
112
int (*closef)(Codex_t*);
113
int (*initf)(Codex_t*);
114
int (*donef)(Codex_t*);
115
ssize_t (*readf)(Sfio_t*, void*, size_t, Sfdisc_t*);
116
ssize_t (*writef)(Sfio_t*, const void*, size_t, Sfdisc_t*);
117
int (*syncf)(Codex_t*);
118
Sfoff_t (*seekf)(Codex_t*, Sfoff_t, int);
119
int (*dataf)(Codex_t*, Codexdata_t*);
120
121
void* vcmeth; /* vcodex(3) method */
122
void* data; /* coder private data */
123
Codexmeth_t* next; /* next in list of all coders */
124
};
125
126
#if _BLD_codex && !defined(main)
127
128
#include <codexlib.h>
129
130
#define CODEXLIB(m)
131
#define CODEXNEXT(m) codex_##m##_next
132
133
#else
134
135
#ifdef __STDC__
136
#define CODEXLIB(m) extern Codexmeth_t* codex_lib(const char* name) { return &codex_##m; } unsigned long plugin_version(void) { return CODEX_PLUGIN_VERSION; }
137
#else
138
#define CODEXLIB(m) extern Codexmeth_t* codex_lib(name) char* name; { return &codex_##m; } unsigned long plugin_version() { return CODEX_PLUGIN_VERSION; }
139
#endif
140
141
#define CODEXNEXT(m) 0
142
143
#if defined(__EXPORT__)
144
#define extern __EXPORT__
145
#endif
146
147
extern Codexmeth_t* codex_lib(const char*);
148
149
#undef extern
150
151
#endif
152
153
#define codexinit(d,e) (memset(d,0,sizeof(*(d))),(d)->version=CODEX_VERSION,(d)->errorf=(Error_f)(e))
154
155
#if _BLD_codex && defined(__EXPORT__)
156
#define extern __EXPORT__
157
#endif
158
159
extern int codex(Sfio_t*, Sfio_t*, const char*, Codexnum_t, Codexdisc_t*, Codexmeth_t*);
160
extern int codexpop(Sfio_t*, Sfio_t*, int);
161
extern int codexcmp(const char*, const char*);
162
extern int codexdata(Sfio_t*, Codexdata_t*);
163
extern ssize_t codexgetpass(const char*, void*, size_t);
164
extern Codexmeth_t* codexid(const void*, size_t, char*, size_t);
165
extern Codexmeth_t* codexlist(Codexmeth_t*);
166
extern Codexmeth_t* codexmeth(const char*);
167
extern int codexadd(const char*, Codexmeth_t*);
168
extern Sfio_t* codexnull(void);
169
extern ssize_t codexpass(void*, size_t, Codexdisc_t*, Codexmeth_t*);
170
extern int codexsize(Sfio_t*, Sfoff_t);
171
172
#undef extern
173
174
#endif
175
176