diff options
| author | jsing <> | 2014-04-15 16:37:22 +0000 |
|---|---|---|
| committer | jsing <> | 2014-04-15 16:37:22 +0000 |
| commit | 405f0a76509e0e96df735b5b902a28b8ab6c9c55 (patch) | |
| tree | 41dd30d546977ed0c409d7de59564fa1a2e3b100 /src/lib/libcrypto/bio/bio_lib.c | |
| parent | 4e5cf8d1c0be703d2956348c807ab6ac39172547 (diff) | |
| download | openbsd-405f0a76509e0e96df735b5b902a28b8ab6c9c55.tar.gz openbsd-405f0a76509e0e96df735b5b902a28b8ab6c9c55.tar.bz2 openbsd-405f0a76509e0e96df735b5b902a28b8ab6c9c55.zip | |
First pass at applying KNF to the OpenSSL code, which almost makes it
readable. This pass is whitespace only and can readily be verified using
tr and md5.
Diffstat (limited to 'src/lib/libcrypto/bio/bio_lib.c')
| -rw-r--r-- | src/lib/libcrypto/bio/bio_lib.c | 748 |
1 files changed, 390 insertions, 358 deletions
diff --git a/src/lib/libcrypto/bio/bio_lib.c b/src/lib/libcrypto/bio/bio_lib.c index 9c9646afa8..9e8fb7913a 100644 --- a/src/lib/libcrypto/bio/bio_lib.c +++ b/src/lib/libcrypto/bio/bio_lib.c | |||
| @@ -63,539 +63,571 @@ | |||
| 63 | #include <openssl/bio.h> | 63 | #include <openssl/bio.h> |
| 64 | #include <openssl/stack.h> | 64 | #include <openssl/stack.h> |
| 65 | 65 | ||
| 66 | BIO *BIO_new(BIO_METHOD *method) | 66 | BIO |
| 67 | { | 67 | *BIO_new(BIO_METHOD *method) |
| 68 | BIO *ret=NULL; | 68 | { |
| 69 | 69 | BIO *ret = NULL; | |
| 70 | ret=(BIO *)OPENSSL_malloc(sizeof(BIO)); | 70 | |
| 71 | if (ret == NULL) | 71 | ret = (BIO *)OPENSSL_malloc(sizeof(BIO)); |
| 72 | { | 72 | if (ret == NULL) { |
| 73 | BIOerr(BIO_F_BIO_NEW,ERR_R_MALLOC_FAILURE); | 73 | BIOerr(BIO_F_BIO_NEW, ERR_R_MALLOC_FAILURE); |
| 74 | return(NULL); | 74 | return (NULL); |
| 75 | } | 75 | } |
| 76 | if (!BIO_set(ret,method)) | 76 | if (!BIO_set(ret, method)) { |
| 77 | { | ||
| 78 | OPENSSL_free(ret); | 77 | OPENSSL_free(ret); |
| 79 | ret=NULL; | 78 | ret = NULL; |
| 80 | } | ||
| 81 | return(ret); | ||
| 82 | } | 79 | } |
| 80 | return (ret); | ||
| 81 | } | ||
| 83 | 82 | ||
| 84 | int BIO_set(BIO *bio, BIO_METHOD *method) | 83 | int |
| 85 | { | 84 | BIO_set(BIO *bio, BIO_METHOD *method) |
| 86 | bio->method=method; | 85 | { |
| 87 | bio->callback=NULL; | 86 | bio->method = method; |
| 88 | bio->cb_arg=NULL; | 87 | bio->callback = NULL; |
| 89 | bio->init=0; | 88 | bio->cb_arg = NULL; |
| 90 | bio->shutdown=1; | 89 | bio->init = 0; |
| 91 | bio->flags=0; | 90 | bio->shutdown = 1; |
| 92 | bio->retry_reason=0; | 91 | bio->flags = 0; |
| 93 | bio->num=0; | 92 | bio->retry_reason = 0; |
| 94 | bio->ptr=NULL; | 93 | bio->num = 0; |
| 95 | bio->prev_bio=NULL; | 94 | bio->ptr = NULL; |
| 96 | bio->next_bio=NULL; | 95 | bio->prev_bio = NULL; |
| 97 | bio->references=1; | 96 | bio->next_bio = NULL; |
| 98 | bio->num_read=0L; | 97 | bio->references = 1; |
| 99 | bio->num_write=0L; | 98 | bio->num_read = 0L; |
| 99 | bio->num_write = 0L; | ||
| 100 | CRYPTO_new_ex_data(CRYPTO_EX_INDEX_BIO, bio, &bio->ex_data); | 100 | CRYPTO_new_ex_data(CRYPTO_EX_INDEX_BIO, bio, &bio->ex_data); |
| 101 | if (method->create != NULL) | 101 | if (method->create != NULL) |
| 102 | if (!method->create(bio)) | 102 | if (!method->create(bio)) { |
| 103 | { | ||
| 104 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_BIO, bio, | 103 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_BIO, bio, |
| 105 | &bio->ex_data); | 104 | &bio->ex_data); |
| 106 | return(0); | 105 | return (0); |
| 107 | } | 106 | } |
| 108 | return(1); | 107 | return (1); |
| 109 | } | 108 | } |
| 110 | 109 | ||
| 111 | int BIO_free(BIO *a) | 110 | int |
| 112 | { | 111 | BIO_free(BIO *a) |
| 112 | { | ||
| 113 | int i; | 113 | int i; |
| 114 | 114 | ||
| 115 | if (a == NULL) return(0); | 115 | if (a == NULL) |
| 116 | return (0); | ||
| 116 | 117 | ||
| 117 | i=CRYPTO_add(&a->references,-1,CRYPTO_LOCK_BIO); | 118 | i = CRYPTO_add(&a->references, -1, CRYPTO_LOCK_BIO); |
| 118 | #ifdef REF_PRINT | 119 | #ifdef REF_PRINT |
| 119 | REF_PRINT("BIO",a); | 120 | REF_PRINT("BIO", a); |
| 120 | #endif | 121 | #endif |
| 121 | if (i > 0) return(1); | 122 | if (i > 0) |
| 123 | return (1); | ||
| 122 | #ifdef REF_CHECK | 124 | #ifdef REF_CHECK |
| 123 | if (i < 0) | 125 | if (i < 0) { |
| 124 | { | 126 | fprintf(stderr, "BIO_free, bad reference count\n"); |
| 125 | fprintf(stderr,"BIO_free, bad reference count\n"); | ||
| 126 | abort(); | 127 | abort(); |
| 127 | } | 128 | } |
| 128 | #endif | 129 | #endif |
| 129 | if ((a->callback != NULL) && | 130 | if ((a->callback != NULL) && |
| 130 | ((i=(int)a->callback(a,BIO_CB_FREE,NULL,0,0L,1L)) <= 0)) | 131 | ((i = (int)a->callback(a, BIO_CB_FREE, NULL, 0, 0L, 1L)) <= 0)) |
| 131 | return(i); | 132 | return (i); |
| 132 | 133 | ||
| 133 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_BIO, a, &a->ex_data); | 134 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_BIO, a, &a->ex_data); |
| 134 | 135 | ||
| 135 | if ((a->method == NULL) || (a->method->destroy == NULL)) return(1); | 136 | if ((a->method == NULL) || (a->method->destroy == NULL)) |
| 137 | return (1); | ||
| 136 | a->method->destroy(a); | 138 | a->method->destroy(a); |
| 137 | OPENSSL_free(a); | 139 | OPENSSL_free(a); |
| 138 | return(1); | 140 | return (1); |
| 139 | } | 141 | } |
| 140 | 142 | ||
| 141 | void BIO_vfree(BIO *a) | 143 | void |
| 142 | { BIO_free(a); } | 144 | BIO_vfree(BIO *a) |
| 145 | { | ||
| 146 | BIO_free(a); | ||
| 147 | } | ||
| 143 | 148 | ||
| 144 | void BIO_clear_flags(BIO *b, int flags) | 149 | void |
| 145 | { | 150 | BIO_clear_flags(BIO *b, int flags) |
| 151 | { | ||
| 146 | b->flags &= ~flags; | 152 | b->flags &= ~flags; |
| 147 | } | 153 | } |
| 148 | 154 | ||
| 149 | int BIO_test_flags(const BIO *b, int flags) | 155 | int |
| 150 | { | 156 | BIO_test_flags(const BIO *b, int flags) |
| 157 | { | ||
| 151 | return (b->flags & flags); | 158 | return (b->flags & flags); |
| 152 | } | 159 | } |
| 153 | 160 | ||
| 154 | void BIO_set_flags(BIO *b, int flags) | 161 | void |
| 155 | { | 162 | BIO_set_flags(BIO *b, int flags) |
| 163 | { | ||
| 156 | b->flags |= flags; | 164 | b->flags |= flags; |
| 157 | } | 165 | } |
| 158 | 166 | ||
| 159 | long (*BIO_get_callback(const BIO *b))(struct bio_st *,int,const char *,int, long,long) | 167 | long |
| 160 | { | 168 | (*BIO_get_callback(const BIO *b))(struct bio_st *, int, const char *, int, |
| 169 | long, long) | ||
| 170 | { | ||
| 161 | return b->callback; | 171 | return b->callback; |
| 162 | } | 172 | } |
| 163 | 173 | ||
| 164 | void BIO_set_callback(BIO *b, long (*cb)(struct bio_st *,int,const char *,int, long,long)) | 174 | void |
| 165 | { | 175 | BIO_set_callback(BIO *b, long (*cb)(struct bio_st *, int, const char *, int, |
| 176 | long, long)) | ||
| 177 | { | ||
| 166 | b->callback = cb; | 178 | b->callback = cb; |
| 167 | } | 179 | } |
| 168 | 180 | ||
| 169 | void BIO_set_callback_arg(BIO *b, char *arg) | 181 | void |
| 170 | { | 182 | BIO_set_callback_arg(BIO *b, char *arg) |
| 183 | { | ||
| 171 | b->cb_arg = arg; | 184 | b->cb_arg = arg; |
| 172 | } | 185 | } |
| 173 | 186 | ||
| 174 | char * BIO_get_callback_arg(const BIO *b) | 187 | char * |
| 175 | { | 188 | BIO_get_callback_arg(const BIO *b) |
| 189 | { | ||
| 176 | return b->cb_arg; | 190 | return b->cb_arg; |
| 177 | } | 191 | } |
| 178 | 192 | ||
| 179 | const char * BIO_method_name(const BIO *b) | 193 | const char * |
| 180 | { | 194 | BIO_method_name(const BIO *b) |
| 195 | { | ||
| 181 | return b->method->name; | 196 | return b->method->name; |
| 182 | } | 197 | } |
| 183 | 198 | ||
| 184 | int BIO_method_type(const BIO *b) | 199 | int |
| 185 | { | 200 | BIO_method_type(const BIO *b) |
| 201 | { | ||
| 186 | return b->method->type; | 202 | return b->method->type; |
| 187 | } | 203 | } |
| 188 | |||
| 189 | 204 | ||
| 190 | int BIO_read(BIO *b, void *out, int outl) | 205 | int |
| 191 | { | 206 | BIO_read(BIO *b, void *out, int outl) |
| 207 | { | ||
| 192 | int i; | 208 | int i; |
| 193 | long (*cb)(BIO *,int,const char *,int,long,long); | 209 | long (*cb)(BIO *, int, const char *, int, long, long); |
| 194 | 210 | ||
| 195 | if ((b == NULL) || (b->method == NULL) || (b->method->bread == NULL)) | 211 | if ((b == NULL) || (b->method == NULL) || (b->method->bread == NULL)) { |
| 196 | { | 212 | BIOerr(BIO_F_BIO_READ, BIO_R_UNSUPPORTED_METHOD); |
| 197 | BIOerr(BIO_F_BIO_READ,BIO_R_UNSUPPORTED_METHOD); | 213 | return (-2); |
| 198 | return(-2); | 214 | } |
| 199 | } | ||
| 200 | 215 | ||
| 201 | cb=b->callback; | 216 | cb = b->callback; |
| 202 | if ((cb != NULL) && | 217 | if ((cb != NULL) && |
| 203 | ((i=(int)cb(b,BIO_CB_READ,out,outl,0L,1L)) <= 0)) | 218 | ((i = (int)cb(b, BIO_CB_READ, out, outl, 0L, 1L)) <= 0)) |
| 204 | return(i); | 219 | return (i); |
| 205 | 220 | ||
| 206 | if (!b->init) | 221 | if (!b->init) { |
| 207 | { | 222 | BIOerr(BIO_F_BIO_READ, BIO_R_UNINITIALIZED); |
| 208 | BIOerr(BIO_F_BIO_READ,BIO_R_UNINITIALIZED); | 223 | return (-2); |
| 209 | return(-2); | 224 | } |
| 210 | } | ||
| 211 | 225 | ||
| 212 | i=b->method->bread(b,out,outl); | 226 | i = b->method->bread(b, out, outl); |
| 213 | 227 | ||
| 214 | if (i > 0) b->num_read+=(unsigned long)i; | 228 | if (i > 0) |
| 229 | b->num_read += (unsigned long)i; | ||
| 215 | 230 | ||
| 216 | if (cb != NULL) | 231 | if (cb != NULL) |
| 217 | i=(int)cb(b,BIO_CB_READ|BIO_CB_RETURN,out,outl, | 232 | i = (int)cb(b, BIO_CB_READ|BIO_CB_RETURN, out, outl, |
| 218 | 0L,(long)i); | 233 | 0L, (long)i); |
| 219 | return(i); | 234 | return (i); |
| 220 | } | 235 | } |
| 221 | 236 | ||
| 222 | int BIO_write(BIO *b, const void *in, int inl) | 237 | int |
| 223 | { | 238 | BIO_write(BIO *b, const void *in, int inl) |
| 239 | { | ||
| 224 | int i; | 240 | int i; |
| 225 | long (*cb)(BIO *,int,const char *,int,long,long); | 241 | long (*cb)(BIO *, int, const char *, int, long, long); |
| 226 | 242 | ||
| 227 | if (b == NULL) | 243 | if (b == NULL) |
| 228 | return(0); | 244 | return (0); |
| 229 | 245 | ||
| 230 | cb=b->callback; | 246 | cb = b->callback; |
| 231 | if ((b->method == NULL) || (b->method->bwrite == NULL)) | 247 | if ((b->method == NULL) || (b->method->bwrite == NULL)) { |
| 232 | { | 248 | BIOerr(BIO_F_BIO_WRITE, BIO_R_UNSUPPORTED_METHOD); |
| 233 | BIOerr(BIO_F_BIO_WRITE,BIO_R_UNSUPPORTED_METHOD); | 249 | return (-2); |
| 234 | return(-2); | 250 | } |
| 235 | } | ||
| 236 | 251 | ||
| 237 | if ((cb != NULL) && | 252 | if ((cb != NULL) && |
| 238 | ((i=(int)cb(b,BIO_CB_WRITE,in,inl,0L,1L)) <= 0)) | 253 | ((i = (int)cb(b, BIO_CB_WRITE, in, inl, 0L, 1L)) <= 0)) |
| 239 | return(i); | 254 | return (i); |
| 240 | 255 | ||
| 241 | if (!b->init) | 256 | if (!b->init) { |
| 242 | { | 257 | BIOerr(BIO_F_BIO_WRITE, BIO_R_UNINITIALIZED); |
| 243 | BIOerr(BIO_F_BIO_WRITE,BIO_R_UNINITIALIZED); | 258 | return (-2); |
| 244 | return(-2); | 259 | } |
| 245 | } | ||
| 246 | 260 | ||
| 247 | i=b->method->bwrite(b,in,inl); | 261 | i = b->method->bwrite(b, in, inl); |
| 248 | 262 | ||
| 249 | if (i > 0) b->num_write+=(unsigned long)i; | 263 | if (i > 0) |
| 264 | b->num_write += (unsigned long)i; | ||
| 250 | 265 | ||
| 251 | if (cb != NULL) | 266 | if (cb != NULL) |
| 252 | i=(int)cb(b,BIO_CB_WRITE|BIO_CB_RETURN,in,inl, | 267 | i = (int)cb(b, BIO_CB_WRITE|BIO_CB_RETURN, in, inl, |
| 253 | 0L,(long)i); | 268 | 0L, (long)i); |
| 254 | return(i); | 269 | return (i); |
| 255 | } | 270 | } |
| 256 | 271 | ||
| 257 | int BIO_puts(BIO *b, const char *in) | 272 | int |
| 258 | { | 273 | BIO_puts(BIO *b, const char *in) |
| 274 | { | ||
| 259 | int i; | 275 | int i; |
| 260 | long (*cb)(BIO *,int,const char *,int,long,long); | 276 | long (*cb)(BIO *, int, const char *, int, long, long); |
| 261 | 277 | ||
| 262 | if ((b == NULL) || (b->method == NULL) || (b->method->bputs == NULL)) | 278 | if ((b == NULL) || (b->method == NULL) || (b->method->bputs == NULL)) { |
| 263 | { | 279 | BIOerr(BIO_F_BIO_PUTS, BIO_R_UNSUPPORTED_METHOD); |
| 264 | BIOerr(BIO_F_BIO_PUTS,BIO_R_UNSUPPORTED_METHOD); | 280 | return (-2); |
| 265 | return(-2); | 281 | } |
| 266 | } | ||
| 267 | 282 | ||
| 268 | cb=b->callback; | 283 | cb = b->callback; |
| 269 | 284 | ||
| 270 | if ((cb != NULL) && | 285 | if ((cb != NULL) && |
| 271 | ((i=(int)cb(b,BIO_CB_PUTS,in,0,0L,1L)) <= 0)) | 286 | ((i = (int)cb(b, BIO_CB_PUTS, in, 0, 0L, 1L)) <= 0)) |
| 272 | return(i); | 287 | return (i); |
| 273 | 288 | ||
| 274 | if (!b->init) | 289 | if (!b->init) { |
| 275 | { | 290 | BIOerr(BIO_F_BIO_PUTS, BIO_R_UNINITIALIZED); |
| 276 | BIOerr(BIO_F_BIO_PUTS,BIO_R_UNINITIALIZED); | 291 | return (-2); |
| 277 | return(-2); | 292 | } |
| 278 | } | ||
| 279 | 293 | ||
| 280 | i=b->method->bputs(b,in); | 294 | i = b->method->bputs(b, in); |
| 281 | 295 | ||
| 282 | if (i > 0) b->num_write+=(unsigned long)i; | 296 | if (i > 0) |
| 297 | b->num_write += (unsigned long)i; | ||
| 283 | 298 | ||
| 284 | if (cb != NULL) | 299 | if (cb != NULL) |
| 285 | i=(int)cb(b,BIO_CB_PUTS|BIO_CB_RETURN,in,0, | 300 | i = (int)cb(b, BIO_CB_PUTS|BIO_CB_RETURN, in, 0, 0L, (long)i); |
| 286 | 0L,(long)i); | 301 | return (i); |
| 287 | return(i); | 302 | } |
| 288 | } | ||
| 289 | 303 | ||
| 290 | int BIO_gets(BIO *b, char *in, int inl) | 304 | int |
| 291 | { | 305 | BIO_gets(BIO *b, char *in, int inl) |
| 306 | { | ||
| 292 | int i; | 307 | int i; |
| 293 | long (*cb)(BIO *,int,const char *,int,long,long); | 308 | long (*cb)(BIO *, int, const char *, int, long, long); |
| 294 | 309 | ||
| 295 | if ((b == NULL) || (b->method == NULL) || (b->method->bgets == NULL)) | 310 | if ((b == NULL) || (b->method == NULL) || (b->method->bgets == NULL)) { |
| 296 | { | 311 | BIOerr(BIO_F_BIO_GETS, BIO_R_UNSUPPORTED_METHOD); |
| 297 | BIOerr(BIO_F_BIO_GETS,BIO_R_UNSUPPORTED_METHOD); | 312 | return (-2); |
| 298 | return(-2); | 313 | } |
| 299 | } | ||
| 300 | 314 | ||
| 301 | cb=b->callback; | 315 | cb = b->callback; |
| 302 | 316 | ||
| 303 | if ((cb != NULL) && | 317 | if ((cb != NULL) && |
| 304 | ((i=(int)cb(b,BIO_CB_GETS,in,inl,0L,1L)) <= 0)) | 318 | ((i = (int)cb(b, BIO_CB_GETS, in, inl, 0L, 1L)) <= 0)) |
| 305 | return(i); | 319 | return (i); |
| 306 | 320 | ||
| 307 | if (!b->init) | 321 | if (!b->init) { |
| 308 | { | 322 | BIOerr(BIO_F_BIO_GETS, BIO_R_UNINITIALIZED); |
| 309 | BIOerr(BIO_F_BIO_GETS,BIO_R_UNINITIALIZED); | 323 | return (-2); |
| 310 | return(-2); | 324 | } |
| 311 | } | ||
| 312 | 325 | ||
| 313 | i=b->method->bgets(b,in,inl); | 326 | i = b->method->bgets(b, in, inl); |
| 314 | 327 | ||
| 315 | if (cb != NULL) | 328 | if (cb != NULL) |
| 316 | i=(int)cb(b,BIO_CB_GETS|BIO_CB_RETURN,in,inl, | 329 | i = (int)cb(b, BIO_CB_GETS|BIO_CB_RETURN, in, inl, 0L, (long)i); |
| 317 | 0L,(long)i); | 330 | return (i); |
| 318 | return(i); | 331 | } |
| 319 | } | ||
| 320 | 332 | ||
| 321 | int BIO_indent(BIO *b,int indent,int max) | 333 | int |
| 322 | { | 334 | BIO_indent(BIO *b, int indent, int max) |
| 323 | if(indent < 0) | 335 | { |
| 324 | indent=0; | 336 | if (indent < 0) |
| 325 | if(indent > max) | 337 | indent = 0; |
| 326 | indent=max; | 338 | if (indent > max) |
| 327 | while(indent--) | 339 | indent = max; |
| 328 | if(BIO_puts(b," ") != 1) | 340 | while (indent--) |
| 329 | return 0; | 341 | if (BIO_puts(b, " ") != 1) |
| 342 | return 0; | ||
| 330 | return 1; | 343 | return 1; |
| 331 | } | 344 | } |
| 332 | 345 | ||
| 333 | long BIO_int_ctrl(BIO *b, int cmd, long larg, int iarg) | 346 | long |
| 334 | { | 347 | BIO_int_ctrl(BIO *b, int cmd, long larg, int iarg) |
| 348 | { | ||
| 335 | int i; | 349 | int i; |
| 336 | 350 | ||
| 337 | i=iarg; | 351 | i = iarg; |
| 338 | return(BIO_ctrl(b,cmd,larg,(char *)&i)); | 352 | return (BIO_ctrl(b, cmd, larg,(char *)&i)); |
| 339 | } | 353 | } |
| 340 | 354 | ||
| 341 | char *BIO_ptr_ctrl(BIO *b, int cmd, long larg) | 355 | char |
| 342 | { | 356 | *BIO_ptr_ctrl(BIO *b, int cmd, long larg) |
| 343 | char *p=NULL; | 357 | { |
| 358 | char *p = NULL; | ||
| 344 | 359 | ||
| 345 | if (BIO_ctrl(b,cmd,larg,(char *)&p) <= 0) | 360 | if (BIO_ctrl(b, cmd, larg,(char *)&p) <= 0) |
| 346 | return(NULL); | 361 | return (NULL); |
| 347 | else | 362 | else |
| 348 | return(p); | 363 | return (p); |
| 349 | } | 364 | } |
| 350 | 365 | ||
| 351 | long BIO_ctrl(BIO *b, int cmd, long larg, void *parg) | 366 | long |
| 352 | { | 367 | BIO_ctrl(BIO *b, int cmd, long larg, void *parg) |
| 368 | { | ||
| 353 | long ret; | 369 | long ret; |
| 354 | long (*cb)(BIO *,int,const char *,int,long,long); | 370 | long (*cb)(BIO *, int, const char *, int, long, long); |
| 355 | 371 | ||
| 356 | if (b == NULL) return(0); | 372 | if (b == NULL) |
| 373 | return (0); | ||
| 357 | 374 | ||
| 358 | if ((b->method == NULL) || (b->method->ctrl == NULL)) | 375 | if ((b->method == NULL) || (b->method->ctrl == NULL)) { |
| 359 | { | 376 | BIOerr(BIO_F_BIO_CTRL, BIO_R_UNSUPPORTED_METHOD); |
| 360 | BIOerr(BIO_F_BIO_CTRL,BIO_R_UNSUPPORTED_METHOD); | 377 | return (-2); |
| 361 | return(-2); | 378 | } |
| 362 | } | ||
| 363 | 379 | ||
| 364 | cb=b->callback; | 380 | cb = b->callback; |
| 365 | 381 | ||
| 366 | if ((cb != NULL) && | 382 | if ((cb != NULL) && |
| 367 | ((ret=cb(b,BIO_CB_CTRL,parg,cmd,larg,1L)) <= 0)) | 383 | ((ret = cb(b, BIO_CB_CTRL, parg, cmd, larg, 1L)) <= 0)) |
| 368 | return(ret); | 384 | return (ret); |
| 369 | 385 | ||
| 370 | ret=b->method->ctrl(b,cmd,larg,parg); | 386 | ret = b->method->ctrl(b, cmd, larg, parg); |
| 371 | 387 | ||
| 372 | if (cb != NULL) | 388 | if (cb != NULL) |
| 373 | ret=cb(b,BIO_CB_CTRL|BIO_CB_RETURN,parg,cmd, | 389 | ret = cb(b, BIO_CB_CTRL|BIO_CB_RETURN, parg, cmd, larg, ret); |
| 374 | larg,ret); | 390 | return (ret); |
| 375 | return(ret); | 391 | } |
| 376 | } | ||
| 377 | 392 | ||
| 378 | long BIO_callback_ctrl(BIO *b, int cmd, void (*fp)(struct bio_st *, int, const char *, int, long, long)) | 393 | long |
| 379 | { | 394 | BIO_callback_ctrl(BIO *b, int cmd, |
| 395 | void (*fp)(struct bio_st *, int, const char *, int, long, long)) | ||
| 396 | { | ||
| 380 | long ret; | 397 | long ret; |
| 381 | long (*cb)(BIO *,int,const char *,int,long,long); | 398 | long (*cb)(BIO *, int, const char *, int, long, long); |
| 382 | 399 | ||
| 383 | if (b == NULL) return(0); | 400 | if (b == NULL) |
| 401 | return (0); | ||
| 384 | 402 | ||
| 385 | if ((b->method == NULL) || (b->method->callback_ctrl == NULL)) | 403 | if ((b->method == NULL) || (b->method->callback_ctrl == NULL)) { |
| 386 | { | 404 | BIOerr(BIO_F_BIO_CALLBACK_CTRL, BIO_R_UNSUPPORTED_METHOD); |
| 387 | BIOerr(BIO_F_BIO_CALLBACK_CTRL,BIO_R_UNSUPPORTED_METHOD); | 405 | return (-2); |
| 388 | return(-2); | 406 | } |
| 389 | } | ||
| 390 | 407 | ||
| 391 | cb=b->callback; | 408 | cb = b->callback; |
| 392 | 409 | ||
| 393 | if ((cb != NULL) && | 410 | if ((cb != NULL) && |
| 394 | ((ret=cb(b,BIO_CB_CTRL,(void *)&fp,cmd,0,1L)) <= 0)) | 411 | ((ret = cb(b, BIO_CB_CTRL,(void *)&fp, cmd, 0, 1L)) <= 0)) |
| 395 | return(ret); | 412 | return (ret); |
| 396 | 413 | ||
| 397 | ret=b->method->callback_ctrl(b,cmd,fp); | 414 | ret = b->method->callback_ctrl(b, cmd, fp); |
| 398 | 415 | ||
| 399 | if (cb != NULL) | 416 | if (cb != NULL) |
| 400 | ret=cb(b,BIO_CB_CTRL|BIO_CB_RETURN,(void *)&fp,cmd, | 417 | ret = cb(b, BIO_CB_CTRL|BIO_CB_RETURN,(void *)&fp, cmd, 0, ret); |
| 401 | 0,ret); | 418 | return (ret); |
| 402 | return(ret); | 419 | } |
| 403 | } | ||
| 404 | 420 | ||
| 405 | /* It is unfortunate to duplicate in functions what the BIO_(w)pending macros | 421 | /* It is unfortunate to duplicate in functions what the BIO_(w)pending macros |
| 406 | * do; but those macros have inappropriate return type, and for interfacing | 422 | * do; but those macros have inappropriate return type, and for interfacing |
| 407 | * from other programming languages, C macros aren't much of a help anyway. */ | 423 | * from other programming languages, C macros aren't much of a help anyway. */ |
| 408 | size_t BIO_ctrl_pending(BIO *bio) | 424 | size_t |
| 409 | { | 425 | BIO_ctrl_pending(BIO *bio) |
| 426 | { | ||
| 410 | return BIO_ctrl(bio, BIO_CTRL_PENDING, 0, NULL); | 427 | return BIO_ctrl(bio, BIO_CTRL_PENDING, 0, NULL); |
| 411 | } | 428 | } |
| 412 | 429 | ||
| 413 | size_t BIO_ctrl_wpending(BIO *bio) | 430 | size_t |
| 414 | { | 431 | BIO_ctrl_wpending(BIO *bio) |
| 432 | { | ||
| 415 | return BIO_ctrl(bio, BIO_CTRL_WPENDING, 0, NULL); | 433 | return BIO_ctrl(bio, BIO_CTRL_WPENDING, 0, NULL); |
| 416 | } | 434 | } |
| 417 | 435 | ||
| 418 | 436 | ||
| 419 | /* put the 'bio' on the end of b's list of operators */ | 437 | /* put the 'bio' on the end of b's list of operators */ |
| 420 | BIO *BIO_push(BIO *b, BIO *bio) | 438 | BIO |
| 421 | { | 439 | *BIO_push(BIO *b, BIO *bio) |
| 440 | { | ||
| 422 | BIO *lb; | 441 | BIO *lb; |
| 423 | 442 | ||
| 424 | if (b == NULL) return(bio); | 443 | if (b == NULL) |
| 425 | lb=b; | 444 | return (bio); |
| 445 | lb = b; | ||
| 426 | while (lb->next_bio != NULL) | 446 | while (lb->next_bio != NULL) |
| 427 | lb=lb->next_bio; | 447 | lb = lb->next_bio; |
| 428 | lb->next_bio=bio; | 448 | lb->next_bio = bio; |
| 429 | if (bio != NULL) | 449 | if (bio != NULL) |
| 430 | bio->prev_bio=lb; | 450 | bio->prev_bio = lb; |
| 431 | /* called to do internal processing */ | 451 | /* called to do internal processing */ |
| 432 | BIO_ctrl(b,BIO_CTRL_PUSH,0,lb); | 452 | BIO_ctrl(b, BIO_CTRL_PUSH, 0, lb); |
| 433 | return(b); | 453 | return (b); |
| 434 | } | 454 | } |
| 435 | 455 | ||
| 436 | /* Remove the first and return the rest */ | 456 | /* Remove the first and return the rest */ |
| 437 | BIO *BIO_pop(BIO *b) | 457 | BIO |
| 438 | { | 458 | *BIO_pop(BIO *b) |
| 459 | { | ||
| 439 | BIO *ret; | 460 | BIO *ret; |
| 440 | 461 | ||
| 441 | if (b == NULL) return(NULL); | 462 | if (b == NULL) |
| 442 | ret=b->next_bio; | 463 | return (NULL); |
| 464 | ret = b->next_bio; | ||
| 443 | 465 | ||
| 444 | BIO_ctrl(b,BIO_CTRL_POP,0,b); | 466 | BIO_ctrl(b, BIO_CTRL_POP, 0, b); |
| 445 | 467 | ||
| 446 | if (b->prev_bio != NULL) | 468 | if (b->prev_bio != NULL) |
| 447 | b->prev_bio->next_bio=b->next_bio; | 469 | b->prev_bio->next_bio = b->next_bio; |
| 448 | if (b->next_bio != NULL) | 470 | if (b->next_bio != NULL) |
| 449 | b->next_bio->prev_bio=b->prev_bio; | 471 | b->next_bio->prev_bio = b->prev_bio; |
| 450 | 472 | ||
| 451 | b->next_bio=NULL; | 473 | b->next_bio = NULL; |
| 452 | b->prev_bio=NULL; | 474 | b->prev_bio = NULL; |
| 453 | return(ret); | 475 | return (ret); |
| 454 | } | 476 | } |
| 455 | 477 | ||
| 456 | BIO *BIO_get_retry_BIO(BIO *bio, int *reason) | 478 | BIO |
| 457 | { | 479 | *BIO_get_retry_BIO(BIO *bio, int *reason) |
| 458 | BIO *b,*last; | 480 | { |
| 481 | BIO *b, *last; | ||
| 459 | 482 | ||
| 460 | b=last=bio; | 483 | b = last = bio; |
| 461 | for (;;) | 484 | for (;;) { |
| 462 | { | ||
| 463 | if (!BIO_should_retry(b)) break; | 485 | if (!BIO_should_retry(b)) break; |
| 464 | last=b; | 486 | last = b; |
| 465 | b=b->next_bio; | 487 | b = b->next_bio; |
| 466 | if (b == NULL) break; | 488 | if (b == NULL) |
| 467 | } | 489 | break; |
| 468 | if (reason != NULL) *reason=last->retry_reason; | 490 | } |
| 469 | return(last); | 491 | if (reason != NULL) |
| 470 | } | 492 | *reason = last->retry_reason; |
| 493 | return (last); | ||
| 494 | } | ||
| 471 | 495 | ||
| 472 | int BIO_get_retry_reason(BIO *bio) | 496 | int |
| 473 | { | 497 | BIO_get_retry_reason(BIO *bio) |
| 474 | return(bio->retry_reason); | 498 | { |
| 475 | } | 499 | return (bio->retry_reason); |
| 500 | } | ||
| 476 | 501 | ||
| 477 | BIO *BIO_find_type(BIO *bio, int type) | 502 | BIO |
| 478 | { | 503 | *BIO_find_type(BIO *bio, int type) |
| 479 | int mt,mask; | 504 | { |
| 480 | 505 | int mt, mask; | |
| 481 | if(!bio) return NULL; | 506 | |
| 482 | mask=type&0xff; | 507 | if (!bio) |
| 483 | do { | 508 | return NULL; |
| 484 | if (bio->method != NULL) | 509 | mask = type & 0xff; |
| 485 | { | 510 | do { |
| 486 | mt=bio->method->type; | 511 | if (bio->method != NULL) { |
| 487 | 512 | mt = bio->method->type; | |
| 488 | if (!mask) | 513 | if (!mask) { |
| 489 | { | 514 | if (mt & type) |
| 490 | if (mt & type) return(bio); | 515 | return (bio); |
| 491 | } | 516 | } else if (mt == type) |
| 492 | else if (mt == type) | 517 | return (bio); |
| 493 | return(bio); | 518 | } |
| 494 | } | 519 | bio = bio->next_bio; |
| 495 | bio=bio->next_bio; | 520 | } while (bio != NULL); |
| 496 | } while (bio != NULL); | 521 | return (NULL); |
| 497 | return(NULL); | 522 | } |
| 498 | } | ||
| 499 | 523 | ||
| 500 | BIO *BIO_next(BIO *b) | 524 | BIO |
| 501 | { | 525 | *BIO_next(BIO *b) |
| 502 | if(!b) return NULL; | 526 | { |
| 527 | if (!b) | ||
| 528 | return NULL; | ||
| 503 | return b->next_bio; | 529 | return b->next_bio; |
| 504 | } | 530 | } |
| 505 | 531 | ||
| 506 | void BIO_free_all(BIO *bio) | 532 | void |
| 507 | { | 533 | BIO_free_all(BIO *bio) |
| 534 | { | ||
| 508 | BIO *b; | 535 | BIO *b; |
| 509 | int ref; | 536 | int ref; |
| 510 | 537 | ||
| 511 | while (bio != NULL) | 538 | while (bio != NULL) { |
| 512 | { | 539 | b = bio; |
| 513 | b=bio; | 540 | ref = b->references; |
| 514 | ref=b->references; | 541 | bio = bio->next_bio; |
| 515 | bio=bio->next_bio; | ||
| 516 | BIO_free(b); | 542 | BIO_free(b); |
| 517 | /* Since ref count > 1, don't free anyone else. */ | 543 | /* Since ref count > 1, don't free anyone else. */ |
| 518 | if (ref > 1) break; | 544 | if (ref > 1) |
| 519 | } | 545 | break; |
| 520 | } | 546 | } |
| 547 | } | ||
| 521 | 548 | ||
| 522 | BIO *BIO_dup_chain(BIO *in) | 549 | BIO |
| 523 | { | 550 | *BIO_dup_chain(BIO *in) |
| 524 | BIO *ret=NULL,*eoc=NULL,*bio,*new_bio; | 551 | { |
| 552 | BIO *ret = NULL, *eoc = NULL, *bio, *new_bio; | ||
| 525 | 553 | ||
| 526 | for (bio=in; bio != NULL; bio=bio->next_bio) | 554 | for (bio = in; bio != NULL; bio = bio->next_bio) { |
| 527 | { | 555 | if ((new_bio = BIO_new(bio->method)) == NULL) goto err; |
| 528 | if ((new_bio=BIO_new(bio->method)) == NULL) goto err; | 556 | new_bio->callback = bio->callback; |
| 529 | new_bio->callback=bio->callback; | 557 | new_bio->cb_arg = bio->cb_arg; |
| 530 | new_bio->cb_arg=bio->cb_arg; | 558 | new_bio->init = bio->init; |
| 531 | new_bio->init=bio->init; | 559 | new_bio->shutdown = bio->shutdown; |
| 532 | new_bio->shutdown=bio->shutdown; | 560 | new_bio->flags = bio->flags; |
| 533 | new_bio->flags=bio->flags; | ||
| 534 | 561 | ||
| 535 | /* This will let SSL_s_sock() work with stdin/stdout */ | 562 | /* This will let SSL_s_sock() work with stdin/stdout */ |
| 536 | new_bio->num=bio->num; | 563 | new_bio->num = bio->num; |
| 537 | 564 | ||
| 538 | if (!BIO_dup_state(bio,(char *)new_bio)) | 565 | if (!BIO_dup_state(bio,(char *)new_bio)) { |
| 539 | { | ||
| 540 | BIO_free(new_bio); | 566 | BIO_free(new_bio); |
| 541 | goto err; | 567 | goto err; |
| 542 | } | 568 | } |
| 543 | 569 | ||
| 544 | /* copy app data */ | 570 | /* copy app data */ |
| 545 | if (!CRYPTO_dup_ex_data(CRYPTO_EX_INDEX_BIO, &new_bio->ex_data, | 571 | if (!CRYPTO_dup_ex_data(CRYPTO_EX_INDEX_BIO, |
| 546 | &bio->ex_data)) | 572 | &new_bio->ex_data, &bio->ex_data)) |
| 547 | goto err; | 573 | goto err; |
| 548 | 574 | ||
| 549 | if (ret == NULL) | 575 | if (ret == NULL) { |
| 550 | { | 576 | eoc = new_bio; |
| 551 | eoc=new_bio; | 577 | ret = eoc; |
| 552 | ret=eoc; | 578 | } else { |
| 553 | } | 579 | BIO_push(eoc, new_bio); |
| 554 | else | 580 | eoc = new_bio; |
| 555 | { | ||
| 556 | BIO_push(eoc,new_bio); | ||
| 557 | eoc=new_bio; | ||
| 558 | } | ||
| 559 | } | 581 | } |
| 560 | return(ret); | 582 | } |
| 583 | return (ret); | ||
| 561 | err: | 584 | err: |
| 562 | if (ret != NULL) | 585 | if (ret != NULL) |
| 563 | BIO_free(ret); | 586 | BIO_free(ret); |
| 564 | return(NULL); | 587 | return (NULL); |
| 565 | } | ||
| 566 | 588 | ||
| 567 | void BIO_copy_next_retry(BIO *b) | 589 | } |
| 568 | { | ||
| 569 | BIO_set_flags(b,BIO_get_retry_flags(b->next_bio)); | ||
| 570 | b->retry_reason=b->next_bio->retry_reason; | ||
| 571 | } | ||
| 572 | 590 | ||
| 573 | int BIO_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, | 591 | void |
| 574 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func) | 592 | BIO_copy_next_retry(BIO *b) |
| 575 | { | 593 | { |
| 594 | BIO_set_flags(b, BIO_get_retry_flags(b->next_bio)); | ||
| 595 | b->retry_reason = b->next_bio->retry_reason; | ||
| 596 | } | ||
| 597 | |||
| 598 | int | ||
| 599 | BIO_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, | ||
| 600 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func) | ||
| 601 | { | ||
| 576 | return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_BIO, argl, argp, | 602 | return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_BIO, argl, argp, |
| 577 | new_func, dup_func, free_func); | 603 | new_func, dup_func, free_func); |
| 578 | } | 604 | } |
| 579 | 605 | ||
| 580 | int BIO_set_ex_data(BIO *bio, int idx, void *data) | 606 | int |
| 581 | { | 607 | BIO_set_ex_data(BIO *bio, int idx, void *data) |
| 582 | return(CRYPTO_set_ex_data(&(bio->ex_data),idx,data)); | 608 | { |
| 583 | } | 609 | return (CRYPTO_set_ex_data(&(bio->ex_data), idx, data)); |
| 610 | } | ||
| 584 | 611 | ||
| 585 | void *BIO_get_ex_data(BIO *bio, int idx) | 612 | void |
| 586 | { | 613 | *BIO_get_ex_data(BIO *bio, int idx) |
| 587 | return(CRYPTO_get_ex_data(&(bio->ex_data),idx)); | 614 | { |
| 588 | } | 615 | return (CRYPTO_get_ex_data(&(bio->ex_data), idx)); |
| 616 | } | ||
| 589 | 617 | ||
| 590 | unsigned long BIO_number_read(BIO *bio) | 618 | unsigned long |
| 619 | BIO_number_read(BIO *bio) | ||
| 591 | { | 620 | { |
| 592 | if(bio) return bio->num_read; | 621 | if (bio) |
| 622 | return bio->num_read; | ||
| 593 | return 0; | 623 | return 0; |
| 594 | } | 624 | } |
| 595 | 625 | ||
| 596 | unsigned long BIO_number_written(BIO *bio) | 626 | unsigned long |
| 627 | BIO_number_written(BIO *bio) | ||
| 597 | { | 628 | { |
| 598 | if(bio) return bio->num_write; | 629 | if (bio) |
| 630 | return bio->num_write; | ||
| 599 | return 0; | 631 | return 0; |
| 600 | } | 632 | } |
| 601 | 633 | ||
