Lines Matching defs:rctx
112 void OCSP_REQ_CTX_free(OCSP_REQ_CTX *rctx)
114 if (rctx->mem)
115 BIO_free(rctx->mem);
116 if (rctx->iobuf)
117 OPENSSL_free(rctx->iobuf);
118 OPENSSL_free(rctx);
121 int OCSP_REQ_CTX_set1_req(OCSP_REQ_CTX *rctx, OCSP_REQUEST *req)
126 if (BIO_printf(rctx->mem, req_hdr, i2d_OCSP_REQUEST(req, NULL)) <= 0)
128 if (i2d_OCSP_REQUEST_bio(rctx->mem, req) <= 0)
130 rctx->state = OHS_ASN1_WRITE;
131 rctx->asn1_len = BIO_get_mem_data(rctx->mem, NULL);
135 int OCSP_REQ_CTX_add1_header(OCSP_REQ_CTX *rctx,
140 if (BIO_puts(rctx->mem, name) <= 0)
144 if (BIO_write(rctx->mem, ": ", 2) != 2)
146 if (BIO_puts(rctx->mem, value) <= 0)
149 if (BIO_write(rctx->mem, "\r\n", 2) != 2)
159 OCSP_REQ_CTX *rctx;
160 rctx = OPENSSL_malloc(sizeof(OCSP_REQ_CTX));
161 rctx->state = OHS_ERROR;
162 rctx->mem = BIO_new(BIO_s_mem());
163 rctx->io = io;
164 rctx->asn1_len = 0;
166 rctx->iobuflen = maxline;
168 rctx->iobuflen = OCSP_MAX_LINE_LEN;
169 rctx->iobuf = OPENSSL_malloc(rctx->iobuflen);
170 if (!rctx->iobuf)
175 if (BIO_printf(rctx->mem, post_hdr, path) <= 0)
178 if (req && !OCSP_REQ_CTX_set1_req(rctx, req))
181 return rctx;
263 int OCSP_sendreq_nbio(OCSP_RESPONSE **presp, OCSP_REQ_CTX *rctx)
268 if (!(rctx->state & OHS_NOREAD))
270 n = BIO_read(rctx->io, rctx->iobuf, rctx->iobuflen);
274 if (BIO_should_retry(rctx->io))
281 if (BIO_write(rctx->mem, rctx->iobuf, n) != n)
285 switch(rctx->state)
289 n = BIO_get_mem_data(rctx->mem, &p);
291 i = BIO_write(rctx->io,
292 p + (n - rctx->asn1_len), rctx->asn1_len);
296 if (BIO_should_retry(rctx->io))
298 rctx->state = OHS_ERROR;
302 rctx->asn1_len -= i;
304 if (rctx->asn1_len > 0)
307 rctx->state = OHS_ASN1_FLUSH;
309 (void)BIO_reset(rctx->mem);
313 i = BIO_flush(rctx->io);
317 rctx->state = OHS_FIRSTLINE;
321 if (BIO_should_retry(rctx->io))
324 rctx->state = OHS_ERROR;
340 n = BIO_get_mem_data(rctx->mem, &p);
343 if (n >= rctx->iobuflen)
345 rctx->state = OHS_ERROR;
350 n = BIO_gets(rctx->mem, (char *)rctx->iobuf, rctx->iobuflen);
354 if (BIO_should_retry(rctx->mem))
356 rctx->state = OHS_ERROR;
361 if (n == rctx->iobuflen)
363 rctx->state = OHS_ERROR;
368 if (rctx->state == OHS_FIRSTLINE)
370 if (parse_http_line1((char *)rctx->iobuf))
372 rctx->state = OHS_HEADERS;
377 rctx->state = OHS_ERROR;
384 for (p = rctx->iobuf; *p; p++)
392 rctx->state = OHS_ASN1_HEADER;
404 n = BIO_get_mem_data(rctx->mem, &p);
411 rctx->state = OHS_ERROR;
427 rctx->state = OHS_ERROR;
431 rctx->asn1_len = 0;
434 rctx->asn1_len <<= 8;
435 rctx->asn1_len |= *p++;
438 if (rctx->asn1_len > OCSP_MAX_REQUEST_LENGTH)
440 rctx->state = OHS_ERROR;
444 rctx->asn1_len += n + 2;
447 rctx->asn1_len = *p + 2;
449 rctx->state = OHS_ASN1_CONTENT;
454 n = BIO_get_mem_data(rctx->mem, &p);
455 if (n < (int)rctx->asn1_len)
459 *presp = d2i_OCSP_RESPONSE(NULL, &p, rctx->asn1_len);
462 rctx->state = OHS_DONE;
466 rctx->state = OHS_ERROR;