diff options
Diffstat (limited to 'src/lib/libcrypto/stack')
-rw-r--r-- | src/lib/libcrypto/stack/Makefile.ssl | 37 | ||||
-rw-r--r-- | src/lib/libcrypto/stack/safestack.h | 129 | ||||
-rw-r--r-- | src/lib/libcrypto/stack/stack.c | 108 | ||||
-rw-r--r-- | src/lib/libcrypto/stack/stack.h | 33 |
4 files changed, 216 insertions, 91 deletions
diff --git a/src/lib/libcrypto/stack/Makefile.ssl b/src/lib/libcrypto/stack/Makefile.ssl index 0d232c08cf..82b36ca624 100644 --- a/src/lib/libcrypto/stack/Makefile.ssl +++ b/src/lib/libcrypto/stack/Makefile.ssl | |||
@@ -7,9 +7,11 @@ TOP= ../.. | |||
7 | CC= cc | 7 | CC= cc |
8 | INCLUDES= | 8 | INCLUDES= |
9 | CFLAG=-g | 9 | CFLAG=-g |
10 | INSTALL_PREFIX= | ||
11 | OPENSSLDIR= /usr/local/ssl | ||
10 | INSTALLTOP=/usr/local/ssl | 12 | INSTALLTOP=/usr/local/ssl |
11 | MAKE= make -f Makefile.ssl | 13 | MAKE= make -f Makefile.ssl |
12 | MAKEDEPEND= makedepend -f Makefile.ssl | 14 | MAKEDEPEND= $(TOP)/util/domd $(TOP) |
13 | MAKEFILE= Makefile.ssl | 15 | MAKEFILE= Makefile.ssl |
14 | AR= ar r | 16 | AR= ar r |
15 | 17 | ||
@@ -25,7 +27,7 @@ LIBOBJ=stack.o | |||
25 | 27 | ||
26 | SRC= $(LIBSRC) | 28 | SRC= $(LIBSRC) |
27 | 29 | ||
28 | EXHEADER= stack.h | 30 | EXHEADER= stack.h safestack.h |
29 | HEADER= $(EXHEADER) | 31 | HEADER= $(EXHEADER) |
30 | 32 | ||
31 | ALL= $(GENERAL) $(SRC) $(HEADER) | 33 | ALL= $(GENERAL) $(SRC) $(HEADER) |
@@ -37,24 +39,23 @@ all: lib | |||
37 | 39 | ||
38 | lib: $(LIBOBJ) | 40 | lib: $(LIBOBJ) |
39 | $(AR) $(LIB) $(LIBOBJ) | 41 | $(AR) $(LIB) $(LIBOBJ) |
40 | sh $(TOP)/util/ranlib.sh $(LIB) | 42 | $(RANLIB) $(LIB) |
41 | @touch lib | 43 | @touch lib |
42 | 44 | ||
43 | files: | 45 | files: |
44 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | 46 | $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO |
45 | 47 | ||
46 | links: | 48 | links: |
47 | /bin/rm -f Makefile | 49 | @$(TOP)/util/point.sh Makefile.ssl Makefile |
48 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | 50 | @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) |
49 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | 51 | @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) |
50 | $(TOP)/util/mklink.sh ../../test $(TEST) | 52 | @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) |
51 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
52 | 53 | ||
53 | install: | 54 | install: |
54 | @for i in $(EXHEADER) ; \ | 55 | @for i in $(EXHEADER) ; \ |
55 | do \ | 56 | do \ |
56 | (cp $$i $(INSTALLTOP)/include/$$i; \ | 57 | (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ |
57 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | 58 | chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ |
58 | done; | 59 | done; |
59 | 60 | ||
60 | tags: | 61 | tags: |
@@ -66,15 +67,19 @@ lint: | |||
66 | lint -DLINT $(INCLUDES) $(SRC)>fluff | 67 | lint -DLINT $(INCLUDES) $(SRC)>fluff |
67 | 68 | ||
68 | depend: | 69 | depend: |
69 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | 70 | $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC) |
70 | 71 | ||
71 | dclean: | 72 | dclean: |
72 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | 73 | $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new |
73 | mv -f Makefile.new $(MAKEFILE) | 74 | mv -f Makefile.new $(MAKEFILE) |
74 | 75 | ||
75 | clean: | 76 | clean: |
76 | /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | 77 | rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff |
77 | |||
78 | errors: | ||
79 | 78 | ||
80 | # DO NOT DELETE THIS LINE -- make depend depends on it. | 79 | # DO NOT DELETE THIS LINE -- make depend depends on it. |
80 | |||
81 | stack.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | ||
82 | stack.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h | ||
83 | stack.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
84 | stack.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
85 | stack.o: ../../include/openssl/stack.h ../cryptlib.h | ||
diff --git a/src/lib/libcrypto/stack/safestack.h b/src/lib/libcrypto/stack/safestack.h new file mode 100644 index 0000000000..38934981e3 --- /dev/null +++ b/src/lib/libcrypto/stack/safestack.h | |||
@@ -0,0 +1,129 @@ | |||
1 | /* ==================================================================== | ||
2 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
3 | * | ||
4 | * Redistribution and use in source and binary forms, with or without | ||
5 | * modification, are permitted provided that the following conditions | ||
6 | * are met: | ||
7 | * | ||
8 | * 1. Redistributions of source code must retain the above copyright | ||
9 | * notice, this list of conditions and the following disclaimer. | ||
10 | * | ||
11 | * 2. Redistributions in binary form must reproduce the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer in | ||
13 | * the documentation and/or other materials provided with the | ||
14 | * distribution. | ||
15 | * | ||
16 | * 3. All advertising materials mentioning features or use of this | ||
17 | * software must display the following acknowledgment: | ||
18 | * "This product includes software developed by the OpenSSL Project | ||
19 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
20 | * | ||
21 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
22 | * endorse or promote products derived from this software without | ||
23 | * prior written permission. For written permission, please contact | ||
24 | * openssl-core@openssl.org. | ||
25 | * | ||
26 | * 5. Products derived from this software may not be called "OpenSSL" | ||
27 | * nor may "OpenSSL" appear in their names without prior written | ||
28 | * permission of the OpenSSL Project. | ||
29 | * | ||
30 | * 6. Redistributions of any form whatsoever must retain the following | ||
31 | * acknowledgment: | ||
32 | * "This product includes software developed by the OpenSSL Project | ||
33 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
34 | * | ||
35 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
36 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
37 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
38 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
39 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
40 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
41 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
42 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
43 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
44 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
45 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
46 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
47 | * ==================================================================== | ||
48 | * | ||
49 | * This product includes cryptographic software written by Eric Young | ||
50 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
51 | * Hudson (tjh@cryptsoft.com). | ||
52 | * | ||
53 | */ | ||
54 | |||
55 | #ifndef HEADER_SAFESTACK_H | ||
56 | #define HEADER_SAFESTACK_H | ||
57 | |||
58 | #include <openssl/stack.h> | ||
59 | |||
60 | #define STACK_OF(type) STACK_##type | ||
61 | |||
62 | #define DECLARE_STACK_OF(type) \ | ||
63 | typedef struct stack_st_##type \ | ||
64 | { \ | ||
65 | STACK stack; \ | ||
66 | } STACK_OF(type); \ | ||
67 | STACK_OF(type) *sk_##type##_new(int (*cmp)(type **,type **)); \ | ||
68 | STACK_OF(type) *sk_##type##_new_null(void); \ | ||
69 | void sk_##type##_free(STACK_OF(type) *sk); \ | ||
70 | int sk_##type##_num(const STACK_OF(type) *sk); \ | ||
71 | type *sk_##type##_value(const STACK_OF(type) *sk,int n); \ | ||
72 | type *sk_##type##_set(STACK_OF(type) *sk,int n,type *v); \ | ||
73 | void sk_##type##_zero(STACK_OF(type) *sk); \ | ||
74 | int sk_##type##_push(STACK_OF(type) *sk,type *v); \ | ||
75 | int sk_##type##_unshift(STACK_OF(type) *sk,type *v); \ | ||
76 | int sk_##type##_find(STACK_OF(type) *sk,type *v); \ | ||
77 | type *sk_##type##_delete(STACK_OF(type) *sk,int n); \ | ||
78 | void sk_##type##_delete_ptr(STACK_OF(type) *sk,type *v); \ | ||
79 | int sk_##type##_insert(STACK_OF(type) *sk,type *v,int n); \ | ||
80 | int (*sk_##type##_set_cmp_func(STACK_OF(type) *sk, \ | ||
81 | int (*cmp)(type **,type **)))(type **,type **); \ | ||
82 | STACK_OF(type) *sk_##type##_dup(STACK_OF(type) *sk); \ | ||
83 | void sk_##type##_pop_free(STACK_OF(type) *sk,void (*func)(type *)); \ | ||
84 | type *sk_##type##_shift(STACK_OF(type) *sk); \ | ||
85 | type *sk_##type##_pop(STACK_OF(type) *sk); \ | ||
86 | void sk_##type##_sort(STACK_OF(type) *sk); | ||
87 | |||
88 | #define IMPLEMENT_STACK_OF(type) \ | ||
89 | STACK_OF(type) *sk_##type##_new(int (*cmp)(type **,type **)) \ | ||
90 | { return (STACK_OF(type) *)sk_new(cmp); } \ | ||
91 | STACK_OF(type) *sk_##type##_new_null() \ | ||
92 | { return (STACK_OF(type) *)sk_new_null(); } \ | ||
93 | void sk_##type##_free(STACK_OF(type) *sk) \ | ||
94 | { sk_free((STACK *)sk); } \ | ||
95 | int sk_##type##_num(const STACK_OF(type) *sk) \ | ||
96 | { return M_sk_num((const STACK *)sk); } \ | ||
97 | type *sk_##type##_value(const STACK_OF(type) *sk,int n) \ | ||
98 | { return (type *)sk_value((STACK *)sk,n); } \ | ||
99 | type *sk_##type##_set(STACK_OF(type) *sk,int n,type *v) \ | ||
100 | { return (type *)(sk_set((STACK *)sk,n,(char *)v)); } \ | ||
101 | void sk_##type##_zero(STACK_OF(type) *sk) \ | ||
102 | { sk_zero((STACK *)sk); } \ | ||
103 | int sk_##type##_push(STACK_OF(type) *sk,type *v) \ | ||
104 | { return sk_push((STACK *)sk,(char *)v); } \ | ||
105 | int sk_##type##_unshift(STACK_OF(type) *sk,type *v) \ | ||
106 | { return sk_unshift((STACK *)sk,(char *)v); } \ | ||
107 | int sk_##type##_find(STACK_OF(type) *sk,type *v) \ | ||
108 | { return sk_find((STACK *)sk,(char *)v); } \ | ||
109 | type *sk_##type##_delete(STACK_OF(type) *sk,int n) \ | ||
110 | { return (type *)sk_delete((STACK *)sk,n); } \ | ||
111 | void sk_##type##_delete_ptr(STACK_OF(type) *sk,type *v) \ | ||
112 | { sk_delete_ptr((STACK *)sk,(char *)v); } \ | ||
113 | int sk_##type##_insert(STACK_OF(type) *sk,type *v,int n) \ | ||
114 | { return sk_insert((STACK *)sk,(char *)v,n); } \ | ||
115 | int (*sk_##type##_set_cmp_func(STACK_OF(type) *sk, \ | ||
116 | int (*cmp)(type **,type **)))(type **,type **) \ | ||
117 | { return (int (*)(type **,type **))sk_set_cmp_func((STACK *)sk,cmp); } \ | ||
118 | STACK_OF(type) *sk_##type##_dup(STACK_OF(type) *sk) \ | ||
119 | { return (STACK_OF(type) *)sk_dup((STACK *)sk); } \ | ||
120 | void sk_##type##_pop_free(STACK_OF(type) *sk,void (*func)(type *)) \ | ||
121 | { sk_pop_free((STACK *)sk,func); } \ | ||
122 | type *sk_##type##_shift(STACK_OF(type) *sk) \ | ||
123 | { return (type *)sk_shift((STACK *)sk); } \ | ||
124 | type *sk_##type##_pop(STACK_OF(type) *sk) \ | ||
125 | { return (type *)sk_pop((STACK *)sk); } \ | ||
126 | void sk_##type##_sort(STACK_OF(type) *sk) \ | ||
127 | { sk_sort((STACK *)sk); } | ||
128 | |||
129 | #endif /* ndef HEADER_SAFESTACK_H */ | ||
diff --git a/src/lib/libcrypto/stack/stack.c b/src/lib/libcrypto/stack/stack.c index 610ccbb756..8b96713884 100644 --- a/src/lib/libcrypto/stack/stack.c +++ b/src/lib/libcrypto/stack/stack.c | |||
@@ -67,32 +67,28 @@ | |||
67 | */ | 67 | */ |
68 | #include <stdio.h> | 68 | #include <stdio.h> |
69 | #include "cryptlib.h" | 69 | #include "cryptlib.h" |
70 | #include "stack.h" | 70 | #include <openssl/stack.h> |
71 | 71 | ||
72 | #undef MIN_NODES | 72 | #undef MIN_NODES |
73 | #define MIN_NODES 4 | 73 | #define MIN_NODES 4 |
74 | 74 | ||
75 | char *STACK_version="STACK part of SSLeay 0.9.0b 29-Jun-1998"; | 75 | const char *STACK_version="Stack" OPENSSL_VERSION_PTEXT; |
76 | 76 | ||
77 | #ifndef NOPROTO | ||
78 | #define FP_ICC (int (*)(const void *,const void *)) | 77 | #define FP_ICC (int (*)(const void *,const void *)) |
79 | #else | ||
80 | #define FP_ICC | ||
81 | #endif | ||
82 | |||
83 | #include <errno.h> | 78 | #include <errno.h> |
84 | 79 | ||
85 | void sk_set_cmp_func(sk,c) | 80 | int (*sk_set_cmp_func(STACK *sk, int (*c)()))(void) |
86 | STACK *sk; | ||
87 | int (*c)(); | ||
88 | { | 81 | { |
82 | int (*old)()=sk->comp; | ||
83 | |||
89 | if (sk->comp != c) | 84 | if (sk->comp != c) |
90 | sk->sorted=0; | 85 | sk->sorted=0; |
91 | sk->comp=c; | 86 | sk->comp=c; |
87 | |||
88 | return old; | ||
92 | } | 89 | } |
93 | 90 | ||
94 | STACK *sk_dup(sk) | 91 | STACK *sk_dup(STACK *sk) |
95 | STACK *sk; | ||
96 | { | 92 | { |
97 | STACK *ret; | 93 | STACK *ret; |
98 | char **s; | 94 | char **s; |
@@ -113,8 +109,7 @@ err: | |||
113 | return(NULL); | 109 | return(NULL); |
114 | } | 110 | } |
115 | 111 | ||
116 | STACK *sk_new(c) | 112 | STACK *sk_new(int (*c)()) |
117 | int (*c)(); | ||
118 | { | 113 | { |
119 | STACK *ret; | 114 | STACK *ret; |
120 | int i; | 115 | int i; |
@@ -136,13 +131,11 @@ err0: | |||
136 | return(NULL); | 131 | return(NULL); |
137 | } | 132 | } |
138 | 133 | ||
139 | int sk_insert(st,data,loc) | 134 | int sk_insert(STACK *st, char *data, int loc) |
140 | STACK *st; | ||
141 | char *data; | ||
142 | int loc; | ||
143 | { | 135 | { |
144 | char **s; | 136 | char **s; |
145 | 137 | ||
138 | if(st == NULL) return 0; | ||
146 | if (st->num_alloc <= st->num+1) | 139 | if (st->num_alloc <= st->num+1) |
147 | { | 140 | { |
148 | s=(char **)Realloc((char *)st->data, | 141 | s=(char **)Realloc((char *)st->data, |
@@ -161,7 +154,7 @@ int loc; | |||
161 | 154 | ||
162 | f=(char **)st->data; | 155 | f=(char **)st->data; |
163 | t=(char **)&(st->data[1]); | 156 | t=(char **)&(st->data[1]); |
164 | for (i=st->num; i>loc; i--) | 157 | for (i=st->num; i>=loc; i--) |
165 | t[i]=f[i]; | 158 | t[i]=f[i]; |
166 | 159 | ||
167 | #ifdef undef /* no memmove on sunos :-( */ | 160 | #ifdef undef /* no memmove on sunos :-( */ |
@@ -176,9 +169,7 @@ int loc; | |||
176 | return(st->num); | 169 | return(st->num); |
177 | } | 170 | } |
178 | 171 | ||
179 | char *sk_delete_ptr(st,p) | 172 | char *sk_delete_ptr(STACK *st, char *p) |
180 | STACK *st; | ||
181 | char *p; | ||
182 | { | 173 | { |
183 | int i; | 174 | int i; |
184 | 175 | ||
@@ -188,14 +179,13 @@ char *p; | |||
188 | return(NULL); | 179 | return(NULL); |
189 | } | 180 | } |
190 | 181 | ||
191 | char *sk_delete(st,loc) | 182 | char *sk_delete(STACK *st, int loc) |
192 | STACK *st; | ||
193 | int loc; | ||
194 | { | 183 | { |
195 | char *ret; | 184 | char *ret; |
196 | int i,j; | 185 | int i,j; |
197 | 186 | ||
198 | if ((st->num == 0) || (loc < 0) || (loc >= st->num)) return(NULL); | 187 | if ((st == NULL) || (st->num == 0) || (loc < 0) |
188 | || (loc >= st->num)) return(NULL); | ||
199 | 189 | ||
200 | ret=st->data[loc]; | 190 | ret=st->data[loc]; |
201 | if (loc != st->num-1) | 191 | if (loc != st->num-1) |
@@ -213,13 +203,12 @@ int loc; | |||
213 | return(ret); | 203 | return(ret); |
214 | } | 204 | } |
215 | 205 | ||
216 | int sk_find(st,data) | 206 | int sk_find(STACK *st, char *data) |
217 | STACK *st; | ||
218 | char *data; | ||
219 | { | 207 | { |
220 | char **r; | 208 | char **r; |
221 | int i; | 209 | int i; |
222 | int (*comp_func)(); | 210 | int (*comp_func)(); |
211 | if(st == NULL) return -1; | ||
223 | 212 | ||
224 | if (st->comp == NULL) | 213 | if (st->comp == NULL) |
225 | { | 214 | { |
@@ -228,13 +217,9 @@ char *data; | |||
228 | return(i); | 217 | return(i); |
229 | return(-1); | 218 | return(-1); |
230 | } | 219 | } |
231 | comp_func=(int (*)())st->comp; | 220 | sk_sort(st); |
232 | if (!st->sorted) | ||
233 | { | ||
234 | qsort((char *)st->data,st->num,sizeof(char *),FP_ICC comp_func); | ||
235 | st->sorted=1; | ||
236 | } | ||
237 | if (data == NULL) return(-1); | 221 | if (data == NULL) return(-1); |
222 | comp_func=(int (*)())st->comp; | ||
238 | r=(char **)bsearch(&data,(char *)st->data, | 223 | r=(char **)bsearch(&data,(char *)st->data, |
239 | st->num,sizeof(char *),FP_ICC comp_func); | 224 | st->num,sizeof(char *),FP_ICC comp_func); |
240 | if (r == NULL) return(-1); | 225 | if (r == NULL) return(-1); |
@@ -245,38 +230,31 @@ char *data; | |||
245 | return(i); | 230 | return(i); |
246 | } | 231 | } |
247 | 232 | ||
248 | int sk_push(st,data) | 233 | int sk_push(STACK *st, char *data) |
249 | STACK *st; | ||
250 | char *data; | ||
251 | { | 234 | { |
252 | return(sk_insert(st,data,st->num)); | 235 | return(sk_insert(st,data,st->num)); |
253 | } | 236 | } |
254 | 237 | ||
255 | int sk_unshift(st,data) | 238 | int sk_unshift(STACK *st, char *data) |
256 | STACK *st; | ||
257 | char *data; | ||
258 | { | 239 | { |
259 | return(sk_insert(st,data,0)); | 240 | return(sk_insert(st,data,0)); |
260 | } | 241 | } |
261 | 242 | ||
262 | char *sk_shift(st) | 243 | char *sk_shift(STACK *st) |
263 | STACK *st; | ||
264 | { | 244 | { |
265 | if (st == NULL) return(NULL); | 245 | if (st == NULL) return(NULL); |
266 | if (st->num <= 0) return(NULL); | 246 | if (st->num <= 0) return(NULL); |
267 | return(sk_delete(st,0)); | 247 | return(sk_delete(st,0)); |
268 | } | 248 | } |
269 | 249 | ||
270 | char *sk_pop(st) | 250 | char *sk_pop(STACK *st) |
271 | STACK *st; | ||
272 | { | 251 | { |
273 | if (st == NULL) return(NULL); | 252 | if (st == NULL) return(NULL); |
274 | if (st->num <= 0) return(NULL); | 253 | if (st->num <= 0) return(NULL); |
275 | return(sk_delete(st,st->num-1)); | 254 | return(sk_delete(st,st->num-1)); |
276 | } | 255 | } |
277 | 256 | ||
278 | void sk_zero(st) | 257 | void sk_zero(STACK *st) |
279 | STACK *st; | ||
280 | { | 258 | { |
281 | if (st == NULL) return; | 259 | if (st == NULL) return; |
282 | if (st->num <= 0) return; | 260 | if (st->num <= 0) return; |
@@ -284,9 +262,7 @@ STACK *st; | |||
284 | st->num=0; | 262 | st->num=0; |
285 | } | 263 | } |
286 | 264 | ||
287 | void sk_pop_free(st,func) | 265 | void sk_pop_free(STACK *st, void (*func)()) |
288 | STACK *st; | ||
289 | void (*func)(); | ||
290 | { | 266 | { |
291 | int i; | 267 | int i; |
292 | 268 | ||
@@ -297,11 +273,39 @@ void (*func)(); | |||
297 | sk_free(st); | 273 | sk_free(st); |
298 | } | 274 | } |
299 | 275 | ||
300 | void sk_free(st) | 276 | void sk_free(STACK *st) |
301 | STACK *st; | ||
302 | { | 277 | { |
303 | if (st == NULL) return; | 278 | if (st == NULL) return; |
304 | if (st->data != NULL) Free((char *)st->data); | 279 | if (st->data != NULL) Free((char *)st->data); |
305 | Free((char *)st); | 280 | Free((char *)st); |
306 | } | 281 | } |
307 | 282 | ||
283 | int sk_num(STACK *st) | ||
284 | { | ||
285 | if(st == NULL) return -1; | ||
286 | return st->num; | ||
287 | } | ||
288 | |||
289 | char *sk_value(STACK *st, int i) | ||
290 | { | ||
291 | if(st == NULL) return NULL; | ||
292 | return st->data[i]; | ||
293 | } | ||
294 | |||
295 | char *sk_set(STACK *st, int i, char *value) | ||
296 | { | ||
297 | if(st == NULL) return NULL; | ||
298 | return (st->data[i] = value); | ||
299 | } | ||
300 | |||
301 | void sk_sort(STACK *st) | ||
302 | { | ||
303 | if (!st->sorted) | ||
304 | { | ||
305 | int (*comp_func)(); | ||
306 | |||
307 | comp_func=(int (*)())st->comp; | ||
308 | qsort(st->data,st->num,sizeof(char *),FP_ICC comp_func); | ||
309 | st->sorted=1; | ||
310 | } | ||
311 | } | ||
diff --git a/src/lib/libcrypto/stack/stack.h b/src/lib/libcrypto/stack/stack.h index 615eb6ff94..0f825cc0c4 100644 --- a/src/lib/libcrypto/stack/stack.h +++ b/src/lib/libcrypto/stack/stack.h | |||
@@ -73,11 +73,16 @@ typedef struct stack_st | |||
73 | int (*comp)(); | 73 | int (*comp)(); |
74 | } STACK; | 74 | } STACK; |
75 | 75 | ||
76 | #define sk_num(sk) ((sk)->num) | ||
77 | #define sk_value(sk,n) ((sk)->data[n]) | ||
78 | 76 | ||
79 | #define sk_new_null() sk_new(NULL) | 77 | #define sk_new_null() sk_new(NULL) |
80 | #ifndef NOPROTO | 78 | |
79 | #define M_sk_num(sk) ((sk)->num) | ||
80 | #define M_sk_value(sk,n) ((sk)->data[n]) | ||
81 | |||
82 | int sk_num(STACK *); | ||
83 | char *sk_value(STACK *, int); | ||
84 | |||
85 | char *sk_set(STACK *, int, char *); | ||
81 | 86 | ||
82 | STACK *sk_new(int (*cmp)()); | 87 | STACK *sk_new(int (*cmp)()); |
83 | void sk_free(STACK *); | 88 | void sk_free(STACK *); |
@@ -91,27 +96,9 @@ int sk_unshift(STACK *st,char *data); | |||
91 | char *sk_shift(STACK *st); | 96 | char *sk_shift(STACK *st); |
92 | char *sk_pop(STACK *st); | 97 | char *sk_pop(STACK *st); |
93 | void sk_zero(STACK *st); | 98 | void sk_zero(STACK *st); |
94 | void sk_set_cmp_func(STACK *sk, int (*c)()); | 99 | int (*sk_set_cmp_func(STACK *sk, int (*c)()))(); |
95 | STACK *sk_dup(STACK *st); | 100 | STACK *sk_dup(STACK *st); |
96 | 101 | void sk_sort(STACK *st); | |
97 | #else | ||
98 | |||
99 | STACK *sk_new(); | ||
100 | void sk_free(); | ||
101 | void sk_pop_free(); | ||
102 | int sk_insert(); | ||
103 | char *sk_delete(); | ||
104 | char *sk_delete_ptr(); | ||
105 | int sk_find(); | ||
106 | int sk_push(); | ||
107 | int sk_unshift(); | ||
108 | char *sk_shift(); | ||
109 | char *sk_pop(); | ||
110 | void sk_zero(); | ||
111 | void sk_set_cmp_func(); | ||
112 | STACK *sk_dup(); | ||
113 | |||
114 | #endif | ||
115 | 102 | ||
116 | #ifdef __cplusplus | 103 | #ifdef __cplusplus |
117 | } | 104 | } |