Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(168)

Side by Side Diff: openssl/crypto/txt_db/txt_db.c

Issue 9254031: Upgrade chrome's OpenSSL to same version Android ships with. (Closed) Base URL: http://src.chromium.org/svn/trunk/deps/third_party/openssl/
Patch Set: '' Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « openssl/crypto/txt_db/txt_db.h ('k') | openssl/crypto/ui/Makefile » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* crypto/txt_db/txt_db.c */ 1 /* crypto/txt_db/txt_db.c */
2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
5 * This package is an SSL implementation written 5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com). 6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL. 7 * The implementation was written so as to conform with Netscapes SSL.
8 * 8 *
9 * This library is free for commercial and non-commercial use as long as 9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions 10 * the following conditions are aheared to. The following conditions
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 70
71 TXT_DB *TXT_DB_read(BIO *in, int num) 71 TXT_DB *TXT_DB_read(BIO *in, int num)
72 { 72 {
73 TXT_DB *ret=NULL; 73 TXT_DB *ret=NULL;
74 int er=1; 74 int er=1;
75 int esc=0; 75 int esc=0;
76 long ln=0; 76 long ln=0;
77 int i,add,n; 77 int i,add,n;
78 int size=BUFSIZE; 78 int size=BUFSIZE;
79 int offset=0; 79 int offset=0;
80 » char *p,**pp,*f; 80 » char *p,*f;
81 » OPENSSL_STRING *pp;
81 BUF_MEM *buf=NULL; 82 BUF_MEM *buf=NULL;
82 83
83 if ((buf=BUF_MEM_new()) == NULL) goto err; 84 if ((buf=BUF_MEM_new()) == NULL) goto err;
84 if (!BUF_MEM_grow(buf,size)) goto err; 85 if (!BUF_MEM_grow(buf,size)) goto err;
85 86
86 » if ((ret=(TXT_DB *)OPENSSL_malloc(sizeof(TXT_DB))) == NULL) 87 » if ((ret=OPENSSL_malloc(sizeof(TXT_DB))) == NULL)
87 goto err; 88 goto err;
88 ret->num_fields=num; 89 ret->num_fields=num;
89 ret->index=NULL; 90 ret->index=NULL;
90 ret->qual=NULL; 91 ret->qual=NULL;
91 » if ((ret->data=sk_new_null()) == NULL) 92 » if ((ret->data=sk_OPENSSL_PSTRING_new_null()) == NULL)
92 goto err; 93 goto err;
93 » if ((ret->index=(LHASH **)OPENSSL_malloc(sizeof(LHASH *)*num)) == NULL) 94 » if ((ret->index=OPENSSL_malloc(sizeof(*ret->index)*num)) == NULL)
94 goto err; 95 goto err;
95 » if ((ret->qual=(int (**)(char **))OPENSSL_malloc(sizeof(int (**)(char ** ))*num)) == NULL) 96 » if ((ret->qual=OPENSSL_malloc(sizeof(*(ret->qual))*num)) == NULL)
96 goto err; 97 goto err;
97 for (i=0; i<num; i++) 98 for (i=0; i<num; i++)
98 { 99 {
99 ret->index[i]=NULL; 100 ret->index[i]=NULL;
100 ret->qual[i]=NULL; 101 ret->qual[i]=NULL;
101 } 102 }
102 103
103 add=(num+1)*sizeof(char *); 104 add=(num+1)*sizeof(char *);
104 buf->data[size-1]='\0'; 105 buf->data[size-1]='\0';
105 offset=0; 106 offset=0;
106 for (;;) 107 for (;;)
107 { 108 {
108 if (offset != 0) 109 if (offset != 0)
109 { 110 {
110 size+=BUFSIZE; 111 size+=BUFSIZE;
111 if (!BUF_MEM_grow_clean(buf,size)) goto err; 112 if (!BUF_MEM_grow_clean(buf,size)) goto err;
112 } 113 }
113 buf->data[offset]='\0'; 114 buf->data[offset]='\0';
114 BIO_gets(in,&(buf->data[offset]),size-offset); 115 BIO_gets(in,&(buf->data[offset]),size-offset);
115 ln++; 116 ln++;
116 if (buf->data[offset] == '\0') break; 117 if (buf->data[offset] == '\0') break;
117 if ((offset == 0) && (buf->data[0] == '#')) continue; 118 if ((offset == 0) && (buf->data[0] == '#')) continue;
118 i=strlen(&(buf->data[offset])); 119 i=strlen(&(buf->data[offset]));
119 offset+=i; 120 offset+=i;
120 if (buf->data[offset-1] != '\n') 121 if (buf->data[offset-1] != '\n')
121 continue; 122 continue;
122 else 123 else
123 { 124 {
124 buf->data[offset-1]='\0'; /* blat the '\n' */ 125 buf->data[offset-1]='\0'; /* blat the '\n' */
125 » » » if (!(p=(char *)OPENSSL_malloc(add+offset))) goto err; 126 » » » if (!(p=OPENSSL_malloc(add+offset))) goto err;
126 offset=0; 127 offset=0;
127 } 128 }
128 pp=(char **)p; 129 pp=(char **)p;
129 p+=add; 130 p+=add;
130 n=0; 131 n=0;
131 pp[n++]=p; 132 pp[n++]=p;
132 i=0; 133 i=0;
133 f=buf->data; 134 f=buf->data;
134 135
135 esc=0; 136 esc=0;
(...skipping 12 matching lines...) Expand all
148 pp[n++]=p; 149 pp[n++]=p;
149 continue; 150 continue;
150 } 151 }
151 } 152 }
152 esc=(*f == '\\'); 153 esc=(*f == '\\');
153 *(p++)= *(f++); 154 *(p++)= *(f++);
154 } 155 }
155 *(p++)='\0'; 156 *(p++)='\0';
156 if ((n != num) || (*f != '\0')) 157 if ((n != num) || (*f != '\0'))
157 { 158 {
158 #if !defined(OPENSSL_NO_STDIO) && !defined(OPENSSL_SYS_WIN16)» /* temporaty fix :-( */ 159 #if !defined(OPENSSL_NO_STDIO) && !defined(OPENSSL_SYS_WIN16)» /* temporary fix :-( */
159 fprintf(stderr,"wrong number of fields on line %ld (look ing for field %d, got %d, '%s' left)\n",ln,num,n,f); 160 fprintf(stderr,"wrong number of fields on line %ld (look ing for field %d, got %d, '%s' left)\n",ln,num,n,f);
160 #endif 161 #endif
161 er=2; 162 er=2;
162 goto err; 163 goto err;
163 } 164 }
164 pp[n]=p; 165 pp[n]=p;
165 » » if (!sk_push(ret->data,(char *)pp)) 166 » » if (!sk_OPENSSL_PSTRING_push(ret->data,pp))
166 { 167 {
167 #if !defined(OPENSSL_NO_STDIO) && !defined(OPENSSL_SYS_WIN16)» /* temporaty fix :-( */ 168 #if !defined(OPENSSL_NO_STDIO) && !defined(OPENSSL_SYS_WIN16)» /* temporary fix :-( */
168 fprintf(stderr,"failure in sk_push\n"); 169 fprintf(stderr,"failure in sk_push\n");
169 #endif 170 #endif
170 er=2; 171 er=2;
171 goto err; 172 goto err;
172 } 173 }
173 } 174 }
174 er=0; 175 er=0;
175 err: 176 err:
176 BUF_MEM_free(buf); 177 BUF_MEM_free(buf);
177 if (er) 178 if (er)
178 { 179 {
179 #if !defined(OPENSSL_NO_STDIO) && !defined(OPENSSL_SYS_WIN16) 180 #if !defined(OPENSSL_NO_STDIO) && !defined(OPENSSL_SYS_WIN16)
180 if (er == 1) fprintf(stderr,"OPENSSL_malloc failure\n"); 181 if (er == 1) fprintf(stderr,"OPENSSL_malloc failure\n");
181 #endif 182 #endif
182 if (ret != NULL) 183 if (ret != NULL)
183 { 184 {
184 » » » if (ret->data != NULL) sk_free(ret->data); 185 » » » if (ret->data != NULL) sk_OPENSSL_PSTRING_free(ret->data );
185 if (ret->index != NULL) OPENSSL_free(ret->index); 186 if (ret->index != NULL) OPENSSL_free(ret->index);
186 if (ret->qual != NULL) OPENSSL_free(ret->qual); 187 if (ret->qual != NULL) OPENSSL_free(ret->qual);
187 if (ret != NULL) OPENSSL_free(ret); 188 if (ret != NULL) OPENSSL_free(ret);
188 } 189 }
189 return(NULL); 190 return(NULL);
190 } 191 }
191 else 192 else
192 return(ret); 193 return(ret);
193 } 194 }
194 195
195 char **TXT_DB_get_by_index(TXT_DB *db, int idx, char **value) 196 OPENSSL_STRING *TXT_DB_get_by_index(TXT_DB *db, int idx, OPENSSL_STRING *value)
196 { 197 {
197 » char **ret; 198 » OPENSSL_STRING *ret;
198 » LHASH *lh; 199 » LHASH_OF(OPENSSL_STRING) *lh;
199 200
200 if (idx >= db->num_fields) 201 if (idx >= db->num_fields)
201 { 202 {
202 db->error=DB_ERROR_INDEX_OUT_OF_RANGE; 203 db->error=DB_ERROR_INDEX_OUT_OF_RANGE;
203 return(NULL); 204 return(NULL);
204 } 205 }
205 lh=db->index[idx]; 206 lh=db->index[idx];
206 if (lh == NULL) 207 if (lh == NULL)
207 { 208 {
208 db->error=DB_ERROR_NO_INDEX; 209 db->error=DB_ERROR_NO_INDEX;
209 return(NULL); 210 return(NULL);
210 } 211 }
211 » ret=(char **)lh_retrieve(lh,value); 212 » ret=lh_OPENSSL_STRING_retrieve(lh,value);
212 db->error=DB_ERROR_OK; 213 db->error=DB_ERROR_OK;
213 return(ret); 214 return(ret);
214 } 215 }
215 216
216 int TXT_DB_create_index(TXT_DB *db, int field, int (*qual)(char **), 217 int TXT_DB_create_index(TXT_DB *db, int field, int (*qual)(OPENSSL_STRING *),
217 » » LHASH_HASH_FN_TYPE hash, LHASH_COMP_FN_TYPE cmp) 218 » » » LHASH_HASH_FN_TYPE hash, LHASH_COMP_FN_TYPE cmp)
218 { 219 {
219 » LHASH *idx; 220 » LHASH_OF(OPENSSL_STRING) *idx;
220 » char **r; 221 » OPENSSL_STRING *r;
221 int i,n; 222 int i,n;
222 223
223 if (field >= db->num_fields) 224 if (field >= db->num_fields)
224 { 225 {
225 db->error=DB_ERROR_INDEX_OUT_OF_RANGE; 226 db->error=DB_ERROR_INDEX_OUT_OF_RANGE;
226 return(0); 227 return(0);
227 } 228 }
228 » if ((idx=lh_new(hash,cmp)) == NULL) 229 » /* FIXME: we lose type checking at this point */
230 » if ((idx=(LHASH_OF(OPENSSL_STRING) *)lh_new(hash,cmp)) == NULL)
229 { 231 {
230 db->error=DB_ERROR_MALLOC; 232 db->error=DB_ERROR_MALLOC;
231 return(0); 233 return(0);
232 } 234 }
233 » n=sk_num(db->data); 235 » n=sk_OPENSSL_PSTRING_num(db->data);
234 for (i=0; i<n; i++) 236 for (i=0; i<n; i++)
235 { 237 {
236 » » r=(char **)sk_value(db->data,i); 238 » » r=sk_OPENSSL_PSTRING_value(db->data,i);
237 if ((qual != NULL) && (qual(r) == 0)) continue; 239 if ((qual != NULL) && (qual(r) == 0)) continue;
238 » » if ((r=lh_insert(idx,r)) != NULL) 240 » » if ((r=lh_OPENSSL_STRING_insert(idx,r)) != NULL)
239 { 241 {
240 db->error=DB_ERROR_INDEX_CLASH; 242 db->error=DB_ERROR_INDEX_CLASH;
241 » » » db->arg1=sk_find(db->data,(char *)r); 243 » » » db->arg1=sk_OPENSSL_PSTRING_find(db->data,r);
242 db->arg2=i; 244 db->arg2=i;
243 » » » lh_free(idx); 245 » » » lh_OPENSSL_STRING_free(idx);
244 return(0); 246 return(0);
245 } 247 }
246 } 248 }
247 » if (db->index[field] != NULL) lh_free(db->index[field]); 249 » if (db->index[field] != NULL) lh_OPENSSL_STRING_free(db->index[field]);
248 db->index[field]=idx; 250 db->index[field]=idx;
249 db->qual[field]=qual; 251 db->qual[field]=qual;
250 return(1); 252 return(1);
251 } 253 }
252 254
253 long TXT_DB_write(BIO *out, TXT_DB *db) 255 long TXT_DB_write(BIO *out, TXT_DB *db)
254 { 256 {
255 long i,j,n,nn,l,tot=0; 257 long i,j,n,nn,l,tot=0;
256 char *p,**pp,*f; 258 char *p,**pp,*f;
257 BUF_MEM *buf=NULL; 259 BUF_MEM *buf=NULL;
258 long ret= -1; 260 long ret= -1;
259 261
260 if ((buf=BUF_MEM_new()) == NULL) 262 if ((buf=BUF_MEM_new()) == NULL)
261 goto err; 263 goto err;
262 » n=sk_num(db->data); 264 » n=sk_OPENSSL_PSTRING_num(db->data);
263 nn=db->num_fields; 265 nn=db->num_fields;
264 for (i=0; i<n; i++) 266 for (i=0; i<n; i++)
265 { 267 {
266 » » pp=(char **)sk_value(db->data,i); 268 » » pp=sk_OPENSSL_PSTRING_value(db->data,i);
267 269
268 l=0; 270 l=0;
269 for (j=0; j<nn; j++) 271 for (j=0; j<nn; j++)
270 { 272 {
271 if (pp[j] != NULL) 273 if (pp[j] != NULL)
272 l+=strlen(pp[j]); 274 l+=strlen(pp[j]);
273 } 275 }
274 if (!BUF_MEM_grow_clean(buf,(int)(l*2+nn))) goto err; 276 if (!BUF_MEM_grow_clean(buf,(int)(l*2+nn))) goto err;
275 277
276 p=buf->data; 278 p=buf->data;
(...skipping 14 matching lines...) Expand all
291 if (BIO_write(out,buf->data,(int)j) != j) 293 if (BIO_write(out,buf->data,(int)j) != j)
292 goto err; 294 goto err;
293 tot+=j; 295 tot+=j;
294 } 296 }
295 ret=tot; 297 ret=tot;
296 err: 298 err:
297 if (buf != NULL) BUF_MEM_free(buf); 299 if (buf != NULL) BUF_MEM_free(buf);
298 return(ret); 300 return(ret);
299 } 301 }
300 302
301 int TXT_DB_insert(TXT_DB *db, char **row) 303 int TXT_DB_insert(TXT_DB *db, OPENSSL_STRING *row)
302 { 304 {
303 int i; 305 int i;
304 » char **r; 306 » OPENSSL_STRING *r;
305 307
306 for (i=0; i<db->num_fields; i++) 308 for (i=0; i<db->num_fields; i++)
307 { 309 {
308 if (db->index[i] != NULL) 310 if (db->index[i] != NULL)
309 { 311 {
310 if ((db->qual[i] != NULL) && 312 if ((db->qual[i] != NULL) &&
311 (db->qual[i](row) == 0)) continue; 313 (db->qual[i](row) == 0)) continue;
312 » » » r=(char **)lh_retrieve(db->index[i],row); 314 » » » r=lh_OPENSSL_STRING_retrieve(db->index[i],row);
313 if (r != NULL) 315 if (r != NULL)
314 { 316 {
315 db->error=DB_ERROR_INDEX_CLASH; 317 db->error=DB_ERROR_INDEX_CLASH;
316 db->arg1=i; 318 db->arg1=i;
317 db->arg_row=r; 319 db->arg_row=r;
318 goto err; 320 goto err;
319 } 321 }
320 } 322 }
321 } 323 }
322 /* We have passed the index checks, now just append and insert */ 324 /* We have passed the index checks, now just append and insert */
323 » if (!sk_push(db->data,(char *)row)) 325 » if (!sk_OPENSSL_PSTRING_push(db->data,row))
324 { 326 {
325 db->error=DB_ERROR_MALLOC; 327 db->error=DB_ERROR_MALLOC;
326 goto err; 328 goto err;
327 } 329 }
328 330
329 for (i=0; i<db->num_fields; i++) 331 for (i=0; i<db->num_fields; i++)
330 { 332 {
331 if (db->index[i] != NULL) 333 if (db->index[i] != NULL)
332 { 334 {
333 if ((db->qual[i] != NULL) && 335 if ((db->qual[i] != NULL) &&
334 (db->qual[i](row) == 0)) continue; 336 (db->qual[i](row) == 0)) continue;
335 » » » lh_insert(db->index[i],row); 337 » » » (void)lh_OPENSSL_STRING_insert(db->index[i],row);
336 } 338 }
337 } 339 }
338 return(1); 340 return(1);
339 err: 341 err:
340 return(0); 342 return(0);
341 } 343 }
342 344
343 void TXT_DB_free(TXT_DB *db) 345 void TXT_DB_free(TXT_DB *db)
344 { 346 {
345 int i,n; 347 int i,n;
346 char **p,*max; 348 char **p,*max;
347 349
348 if(db == NULL) 350 if(db == NULL)
349 return; 351 return;
350 352
351 if (db->index != NULL) 353 if (db->index != NULL)
352 { 354 {
353 for (i=db->num_fields-1; i>=0; i--) 355 for (i=db->num_fields-1; i>=0; i--)
354 » » » if (db->index[i] != NULL) lh_free(db->index[i]); 356 » » » if (db->index[i] != NULL) lh_OPENSSL_STRING_free(db->ind ex[i]);
355 OPENSSL_free(db->index); 357 OPENSSL_free(db->index);
356 } 358 }
357 if (db->qual != NULL) 359 if (db->qual != NULL)
358 OPENSSL_free(db->qual); 360 OPENSSL_free(db->qual);
359 if (db->data != NULL) 361 if (db->data != NULL)
360 { 362 {
361 » » for (i=sk_num(db->data)-1; i>=0; i--) 363 » » for (i=sk_OPENSSL_PSTRING_num(db->data)-1; i>=0; i--)
362 { 364 {
363 /* check if any 'fields' have been allocated 365 /* check if any 'fields' have been allocated
364 * from outside of the initial block */ 366 * from outside of the initial block */
365 » » » p=(char **)sk_value(db->data,i); 367 » » » p=sk_OPENSSL_PSTRING_value(db->data,i);
366 max=p[db->num_fields]; /* last address */ 368 max=p[db->num_fields]; /* last address */
367 if (max == NULL) /* new row */ 369 if (max == NULL) /* new row */
368 { 370 {
369 for (n=0; n<db->num_fields; n++) 371 for (n=0; n<db->num_fields; n++)
370 if (p[n] != NULL) OPENSSL_free(p[n]); 372 if (p[n] != NULL) OPENSSL_free(p[n]);
371 } 373 }
372 else 374 else
373 { 375 {
374 for (n=0; n<db->num_fields; n++) 376 for (n=0; n<db->num_fields; n++)
375 { 377 {
376 if (((p[n] < (char *)p) || (p[n] > max)) 378 if (((p[n] < (char *)p) || (p[n] > max))
377 && (p[n] != NULL)) 379 && (p[n] != NULL))
378 OPENSSL_free(p[n]); 380 OPENSSL_free(p[n]);
379 } 381 }
380 } 382 }
381 » » » OPENSSL_free(sk_value(db->data,i)); 383 » » » OPENSSL_free(sk_OPENSSL_PSTRING_value(db->data,i));
382 } 384 }
383 » » sk_free(db->data); 385 » » sk_OPENSSL_PSTRING_free(db->data);
384 } 386 }
385 OPENSSL_free(db); 387 OPENSSL_free(db);
386 } 388 }
OLDNEW
« no previous file with comments | « openssl/crypto/txt_db/txt_db.h ('k') | openssl/crypto/ui/Makefile » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698