Line data Source code
1 : /**
2 : r_data.c
3 :
4 :
5 : Copyright (C) 2002-2003, Network Resonance, Inc.
6 : Copyright (C) 2006, Network Resonance, Inc.
7 : All Rights Reserved
8 :
9 : Redistribution and use in source and binary forms, with or without
10 : modification, are permitted provided that the following conditions
11 : are met:
12 :
13 : 1. Redistributions of source code must retain the above copyright
14 : notice, this list of conditions and the following disclaimer.
15 : 2. Redistributions in binary form must reproduce the above copyright
16 : notice, this list of conditions and the following disclaimer in the
17 : documentation and/or other materials provided with the distribution.
18 : 3. Neither the name of Network Resonance, Inc. nor the name of any
19 : contributors to this software may be used to endorse or promote
20 : products derived from this software without specific prior written
21 : permission.
22 :
23 : THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
24 : AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 : IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 : ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 : LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 : CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 : SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 : INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 : CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 : ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 : POSSIBILITY OF SUCH DAMAGE.
34 :
35 :
36 : */
37 :
38 : /**
39 : r_data.c
40 :
41 :
42 : Copyright (C) 1999-2000 RTFM, Inc.
43 : All Rights Reserved
44 :
45 : This package is a SSLv3/TLS protocol analyzer written by Eric Rescorla
46 : <ekr@rtfm.com> and licensed by RTFM, Inc.
47 :
48 : Redistribution and use in source and binary forms, with or without
49 : modification, are permitted provided that the following conditions
50 : are met:
51 : 1. Redistributions of source code must retain the above copyright
52 : notice, this list of conditions and the following disclaimer.
53 : 2. Redistributions in binary form must reproduce the above copyright
54 : notice, this list of conditions and the following disclaimer in the
55 : documentation and/or other materials provided with the distribution.
56 : 3. All advertising materials mentioning features or use of this software
57 : must display the following acknowledgement:
58 :
59 : This product includes software developed by Eric Rescorla for
60 : RTFM, Inc.
61 :
62 : 4. Neither the name of RTFM, Inc. nor the name of Eric Rescorla may be
63 : used to endorse or promote products derived from this
64 : software without specific prior written permission.
65 :
66 : THIS SOFTWARE IS PROVIDED BY ERIC RESCORLA AND RTFM, INC. ``AS IS'' AND
67 : ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
68 : IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
69 : ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
70 : FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
71 : DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
72 : OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
73 : HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
74 : LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
75 : OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY SUCH DAMAGE.
76 :
77 : $Id: r_data.c,v 1.2 2006/08/16 19:39:17 adamcain Exp $
78 :
79 : ekr@rtfm.com Tue Aug 17 15:39:50 1999
80 : */
81 :
82 :
83 : static char *RCSSTRING __UNUSED__ =(char *)"$Id: r_data.c,v 1.2 2006/08/16 19:39:17 adamcain Exp $";
84 :
85 : #include <string.h>
86 : #include <r_common.h>
87 : #include <r_data.h>
88 : #include <string.h>
89 :
90 0 : int r_data_create(dp,d,l)
91 : Data **dp;
92 : const UCHAR *d;
93 : int l;
94 : {
95 0 : Data *d_=0;
96 : int _status;
97 :
98 0 : if(!(d_=(Data *)RCALLOC(sizeof(Data))))
99 0 : ABORT(R_NO_MEMORY);
100 0 : if(!(d_->data=(UCHAR *)RMALLOC(l)))
101 0 : ABORT(R_NO_MEMORY);
102 :
103 0 : memcpy(d_->data,d,l);
104 0 : d_->len=l;
105 :
106 0 : *dp=d_;
107 :
108 0 : _status=0;
109 : abort:
110 0 : if(_status)
111 0 : r_data_destroy(&d_);
112 :
113 0 : return(_status);
114 : }
115 :
116 :
117 0 : int r_data_alloc_mem(d,l)
118 : Data *d;
119 : int l;
120 : {
121 : int _status;
122 :
123 0 : if(!(d->data=(UCHAR *)RMALLOC(l)))
124 0 : ABORT(R_NO_MEMORY);
125 0 : d->len=l;
126 :
127 0 : _status=0;
128 : abort:
129 0 : return(_status);
130 : }
131 :
132 0 : int r_data_alloc(dp,l)
133 : Data **dp;
134 : int l;
135 : {
136 0 : Data *d_=0;
137 : int _status;
138 :
139 0 : if(!(d_=(Data *)RCALLOC(sizeof(Data))))
140 0 : ABORT(R_NO_MEMORY);
141 0 : if(!(d_->data=(UCHAR *)RCALLOC(l)))
142 0 : ABORT(R_NO_MEMORY);
143 :
144 0 : d_->len=l;
145 :
146 0 : *dp=d_;
147 0 : _status=0;
148 : abort:
149 0 : if(_status)
150 0 : r_data_destroy(&d_);
151 :
152 0 : return(_status);
153 : }
154 :
155 0 : int r_data_make(dp,d,l)
156 : Data *dp;
157 : const UCHAR *d;
158 : int l;
159 : {
160 0 : if(!(dp->data=(UCHAR *)RMALLOC(l)))
161 0 : ERETURN(R_NO_MEMORY);
162 :
163 0 : memcpy(dp->data,d,l);
164 0 : dp->len=l;
165 :
166 0 : return(0);
167 : }
168 :
169 0 : int r_data_destroy(dp)
170 : Data **dp;
171 : {
172 0 : if(!dp || !*dp)
173 0 : return(0);
174 :
175 0 : if((*dp)->data)
176 0 : RFREE((*dp)->data);
177 :
178 0 : RFREE(*dp);
179 0 : *dp=0;
180 :
181 0 : return(0);
182 : }
183 :
184 0 : int r_data_destroy_v(v)
185 : void *v;
186 : {
187 : Data *d;
188 :
189 0 : if(!v)
190 0 : return(0);
191 :
192 0 : d=(Data *)v;
193 0 : r_data_zfree(d);
194 :
195 0 : RFREE(d);
196 :
197 0 : return(0);
198 : }
199 :
200 0 : int r_data_destroy_vp(v)
201 : void **v;
202 : {
203 : Data *d;
204 :
205 0 : if(!v || !*v)
206 0 : return(0);
207 :
208 0 : d=(Data *)*v;
209 0 : r_data_zfree(d);
210 :
211 0 : *v=0;
212 0 : RFREE(d);
213 :
214 0 : return(0);
215 : }
216 :
217 0 : int r_data_copy(dst,src)
218 : Data *dst;
219 : Data *src;
220 : {
221 0 : if(!(dst->data=(UCHAR *)RMALLOC(src->len)))
222 0 : ERETURN(R_NO_MEMORY);
223 0 : memcpy(dst->data,src->data,dst->len=src->len);
224 0 : return(0);
225 : }
226 :
227 0 : int r_data_zfree(d)
228 : Data *d;
229 : {
230 0 : if(!d)
231 0 : return(0);
232 0 : if(!d->data)
233 0 : return(0);
234 0 : memset(d->data,0,d->len);
235 0 : RFREE(d->data);
236 0 : return(0);
237 : }
238 :
239 0 : int r_data_compare(d1,d2)
240 : Data *d1;
241 : Data *d2;
242 : {
243 0 : if(d1->len<d2->len)
244 0 : return(-1);
245 0 : if(d2->len<d1->len)
246 0 : return(-1);
247 0 : return(memcmp(d1->data,d2->data,d1->len));
248 : }
249 :
|