av_freep(&c->dec_buf);
c->dec_buf_size = c->dec_buf_offset = 0;
- if (c->tls_shared.tcp)
- ffurl_close(c->tls_shared.tcp);
+ ffurl_closep(&c->tls_shared.tcp);
return 0;
}
TLSContext *c = h->priv_data;
TLSShared *s = &c->tls_shared;
SECURITY_STATUS sspi_ret;
- SecBuffer outbuf[3];
+ SecBuffer outbuf[3] = { 0 };
SecBufferDesc outbuf_desc;
SecBuffer inbuf[2];
SecBufferDesc inbuf_desc;
int size, ret;
int min_enc_buf_size = len + SCHANNEL_FREE_BUFFER_SIZE;
- if (len <= c->dec_buf_offset)
+ /* If we have some left-over data from previous network activity,
+ * return it first in case it is enough. It may contain
+ * data that is required to know whether this connection
+ * is still required or not, esp. in case of HTTP keep-alive
+ * connections. */
+ if (c->dec_buf_offset > 0)
goto cleanup;
if (c->sspi_close_notify)
ret = ffurl_read(s->tcp, c->enc_buf + c->enc_buf_offset,
c->enc_buf_size - c->enc_buf_offset);
- if (ret < 0) {
+ if (ret == AVERROR_EOF) {
+ c->connection_closed = 1;
+ ret = 0;
+ } else if (ret < 0) {
av_log(h, AV_LOG_ERROR, "Unable to read from socket\n");
return ret;
- } else if (ret == 0)
- c->connection_closed = 1;
+ }
c->enc_buf_offset += ret;
}
- while (c->enc_buf_offset > 0 && sspi_ret == SEC_E_OK && c->dec_buf_offset < len) {
+ while (c->enc_buf_offset > 0 && sspi_ret == SEC_E_OK) {
/* input buffer */
init_sec_buffer(&inbuf[0], SECBUFFER_DATA, c->enc_buf, c->enc_buf_offset);
if (ret == 0 && !c->connection_closed)
ret = AVERROR(EAGAIN);
- return ret < 0 ? ret : 0;
+ return ret < 0 ? ret : AVERROR_EOF;
}
static int tls_write(URLContext *h, const uint8_t *buf, int len)
return ffurl_get_file_handle(c->tls_shared.tcp);
}
+static int tls_get_short_seek(URLContext *h)
+{
+ TLSContext *s = h->priv_data;
+ return ffurl_get_short_seek(s->tls_shared.tcp);
+}
+
static const AVOption options[] = {
TLS_COMMON_OPTIONS(TLSContext, tls_shared),
{ NULL }
.url_write = tls_write,
.url_close = tls_close,
.url_get_file_handle = tls_get_file_handle,
+ .url_get_short_seek = tls_get_short_seek,
.priv_data_size = sizeof(TLSContext),
.flags = URL_PROTOCOL_FLAG_NETWORK,
.priv_data_class = &tls_class,