]> git.saurik.com Git - apple/security.git/blob - SecuritySNACCRuntime/c-lib/inc/exp-buf.h
Security-30.1.tar.gz
[apple/security.git] / SecuritySNACCRuntime / c-lib / inc / exp-buf.h
1 /*
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
3 *
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
8 * using this file.
9 *
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
16 */
17
18
19 /*
20 * exp_buf.h - read/write/alloc/free routines for a simple buffer structure
21 *
22 * MACROS are gross but execution speed is important
23 *
24 * NOTE: replacing the malloc and free with a allocs/frees
25 * from/to buffer pools or similar tuned/fixed size
26 * mem mgmt will improve performance.
27 *
28 * You should tune the buffer management to your environment
29 * for best results
30 *
31 * MS 91
32 * Copyright (C) 1992 Michael Sample and the University of British Columbia
33 *
34 * This library is free software; you can redistribute it and/or
35 * modify it provided that this copyright/license information is retained
36 * in original form.
37 *
38 * If you modify this file, you must clearly indicate your changes.
39 *
40 * This source code is distributed in the hope that it will be
41 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
42 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
43 *
44 * $Header: /cvs/Darwin/Security/SecuritySNACCRuntime/c-lib/inc/exp-buf.h,v 1.1.1.1 2001/05/18 23:14:08 mb Exp $
45 * $Log: exp-buf.h,v $
46 * Revision 1.1.1.1 2001/05/18 23:14:08 mb
47 * Move from private repository to open source repository
48 *
49 * Revision 1.2 2001/05/05 00:59:23 rmurphy
50 * Adding darwin license headers
51 *
52 * Revision 1.1.1.1 1999/03/16 18:06:21 aram
53 * Originals from SMIME Free Library.
54 *
55 * Revision 1.2 1995/07/27 08:54:45 rj
56 * functions used by gen-bufs or type tables merged.
57 *
58 * changed `_' to `-' in file names.
59 *
60 * Revision 1.1 1994/08/28 09:21:40 rj
61 * first check-in. for a list of changes to the snacc-1.1 distribution please refer to the ChangeLog.
62 *
63 */
64
65 #ifndef _exp_buf_h_
66 #define _exp_buf_h_
67
68 typedef struct ExpBuf
69 {
70 char *dataStart; /* points to first valid data byte */
71 /* when empty, 1 byte past blk end (rvs write)*/
72 char *dataEnd; /* pts to first byte AFTER last valid data byte*/
73 char *curr; /* current location to read form */
74 /* points to next byte to read */
75 struct ExpBuf *next; /* next buf (NULL if no next buffer)*/
76 struct ExpBuf *prev; /* prev buf (NULL if no prev buffer)*/
77 char *blkStart; /* points to first byte of the blk */
78 char *blkEnd; /* points the first byte AFTER blks last byte */
79 int readError; /* non-zero is attempt to read past end of data*/
80 int writeError;/* non-zero is attempt write fails (no mor bufs)*/
81 } ExpBuf;
82
83
84
85 /* init, alloc and free routines */
86 #if defined (DEBUG) /* use fcns when debugging/macros later */ || defined (USE_GEN_BUF)
87
88 #ifdef USE_GEN_BUF
89 void PutExpBufInGenBuf PROTO ((ExpBuf *eb,GenBuf *gb));
90 #endif
91
92 void ExpBufInit PROTO ((unsigned long dataBlkSize));
93 ExpBuf *ExpBufAllocBuf();
94 void ExpBufFreeBuf PROTO ((ExpBuf *ptr));
95 char *ExpBufAllocData();
96 void ExpBufFreeData PROTO ((char *ptr));
97 void ExpBufFreeBufAndData PROTO (( ExpBuf *b));
98
99 ExpBuf *ExpBufNext PROTO ((ExpBuf *b));
100 ExpBuf *ExpBufPrev PROTO ((ExpBuf *b));
101 void ExpBufResetInReadMode PROTO ((ExpBuf *b));
102 void ExpBufResetInWriteRvsMode PROTO ((ExpBuf *b));
103
104 int ExpBufAtEod PROTO ((ExpBuf *b));
105 int ExpBufFull PROTO ((ExpBuf *b));
106 int ExpBufHasNoData PROTO ((ExpBuf *b));
107 unsigned long ExpBufDataSize PROTO ((ExpBuf *b));
108 unsigned long ExpBufDataBlkSize PROTO ((ExpBuf *b));
109 char *ExpBufDataPtr PROTO ((ExpBuf *b));
110
111 #else
112
113 extern unsigned long expBufDataBlkSizeG;
114
115 #define ExpBufInit( size) expBufDataBlkSizeG = size;
116 #define ExpBufAllocBuf() ((ExpBuf *)malloc (sizeof (ExpBuf)))
117 #define ExpBufFreeBuf( ptr) free (ptr)
118 #define ExpBufAllocData() ((void *)malloc (expBufDataBlkSizeG))
119 #define ExpBufFreeData( ptr) free (ptr)
120 #define ExpBufFreeBufAndData( b) { ExpBufFreeData ((b)->blkStart); ExpBufFreeBuf (b); }
121 #define ExpBufNext( b) ((b)->next)
122 #define ExpBufPrev( b) ((b)->prev)
123 #define ExpBufResetInReadMode( b) { (b)->curr = (b)->dataStart; (b)->readError = 0; (b)->writeError = 1; }
124 #define ExpBufResetInWriteRvsMode( b) { (b)->dataStart = (b)->dataEnd = (b)->blkEnd; (b)->writeError = 0; (b)->readError = 1; }
125
126 /* ExpBufAtEod only valid during reads (fwd) */
127 #define ExpBufAtEod( b) ((b)->curr == (b)->dataEnd)
128
129 /* ExpBufFull only valid during write (reverse) */
130 #define ExpBufFull( b) ((b)->dataStart == (b)->blkStart)
131 #define ExpBufHasNoData( b) ((b)->dataStart == (b)->dataEnd)
132 #define ExpBufDataSize( b) ((b)->dataEnd - (b)->dataStart)
133 #define ExpBufDataBlkSize( b) ((b)->blkEnd - (b)->blkStart)
134 #define ExpBufDataPtr( b) (ExpBufHasNoData (b)? NULL: (b)->dataStart)
135
136 #endif /* DEBUG || USE_GEN_BUF */
137
138 #ifdef USE_GEN_BUF
139 int ExpBufReadError PROTO ((ExpBuf **b));
140 int ExpBufWriteError PROTO ((ExpBuf **b));
141 #else
142 #define ExpBufReadError( b) ((*b)->readError)
143 #define ExpBufWriteError( b) ((*b)->writeError)
144 #endif
145
146 ExpBuf *ExpBufAllocBufAndData();
147 void ExpBufInstallDataInBuf PROTO ((ExpBuf *b, char *data, unsigned long int len));
148 void ExpBufFreeBufAndDataList PROTO (( ExpBuf *b));
149 ExpBuf *ExpBufListLastBuf PROTO ((ExpBuf *b));
150 ExpBuf *ExpBufListFirstBuf PROTO ((ExpBuf *b));
151
152 void ExpBufCopyToFile PROTO ((ExpBuf *b, FILE *f));
153
154 /* reading and writing routines */
155
156 void ExpBufSkip PROTO (( ExpBuf**, unsigned long len));
157 int ExpBufCopy PROTO (( char *dst, ExpBuf **b, unsigned long len));
158 unsigned char ExpBufPeekByte PROTO (( ExpBuf **b));
159 #if TTBL
160 int ExpBufPeekCopy PROTO ((char *dst, ExpBuf **b, unsigned long len));
161 char *ExpBufPeekSeg PROTO ((ExpBuf **b, unsigned long *len));
162 #endif
163 char *ExpBufGetSeg PROTO ((ExpBuf **b, unsigned long *len));
164 void ExpBufPutSegRvs PROTO ((ExpBuf **b, char *data, unsigned long len));
165 unsigned char ExpBufGetByte PROTO ((ExpBuf **b));
166 void ExpBufPutByteRvs PROTO ((ExpBuf **b, unsigned char byte));
167
168 #endif /* conditional include */