Skip to content

Commit

Permalink
add CyaSSL_peek()
Browse files Browse the repository at this point in the history
  • Loading branch information
toddouska committed Nov 16, 2012
1 parent 5d912d4 commit dd259b1
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cyassl/internal.h
Expand Up @@ -1516,7 +1516,7 @@ CYASSL_LOCAL int SendCertificate(CYASSL*);
CYASSL_LOCAL int SendCertificateRequest(CYASSL*);
CYASSL_LOCAL int SendServerKeyExchange(CYASSL*);
CYASSL_LOCAL int SendBuffered(CYASSL*);
CYASSL_LOCAL int ReceiveData(CYASSL*, byte*, int);
CYASSL_LOCAL int ReceiveData(CYASSL*, byte*, int, int);
CYASSL_LOCAL int SendFinished(CYASSL*);
CYASSL_LOCAL int SendAlert(CYASSL*, int, int);
CYASSL_LOCAL int ProcessReply(CYASSL*);
Expand Down
1 change: 1 addition & 0 deletions cyassl/openssl/ssl.h
Expand Up @@ -116,6 +116,7 @@ typedef CYASSL_X509_STORE_CTX X509_STORE_CTX;

#define SSL_write CyaSSL_write
#define SSL_read CyaSSL_read
#define SSL_peek CyaSSL_peek
#define SSL_accept CyaSSL_accept
#define SSL_CTX_free CyaSSL_CTX_free
#define SSL_free CyaSSL_free
Expand Down
1 change: 1 addition & 0 deletions cyassl/ssl.h
Expand Up @@ -190,6 +190,7 @@ CYASSL_API int CyaSSL_connect(CYASSL*); /* please see note at top of README
if you get an error from connect */
CYASSL_API int CyaSSL_write(CYASSL*, const void*, int);
CYASSL_API int CyaSSL_read(CYASSL*, void*, int);
CYASSL_API int CyaSSL_peek(CYASSL*, void*, int);
CYASSL_API int CyaSSL_accept(CYASSL*);
CYASSL_API void CyaSSL_CTX_free(CYASSL_CTX*);
CYASSL_API void CyaSSL_free(CYASSL*);
Expand Down
9 changes: 6 additions & 3 deletions src/internal.c
Expand Up @@ -4065,7 +4065,7 @@ int SendData(CYASSL* ssl, const void* data, int sz)
}

/* process input data */
int ReceiveData(CYASSL* ssl, byte* output, int sz)
int ReceiveData(CYASSL* ssl, byte* output, int sz, int peek)
{
int size;

Expand Down Expand Up @@ -4104,8 +4104,11 @@ int ReceiveData(CYASSL* ssl, byte* output, int sz)
size = ssl->buffers.clearOutputBuffer.length;

XMEMCPY(output, ssl->buffers.clearOutputBuffer.buffer, size);
ssl->buffers.clearOutputBuffer.length -= size;
ssl->buffers.clearOutputBuffer.buffer += size;

if (peek == 0) {
ssl->buffers.clearOutputBuffer.length -= size;
ssl->buffers.clearOutputBuffer.buffer += size;
}

if (ssl->buffers.clearOutputBuffer.length == 0 &&
ssl->buffers.inputBuffer.dynamicFlag)
Expand Down
24 changes: 20 additions & 4 deletions src/ssl.c
Expand Up @@ -380,19 +380,19 @@ int CyaSSL_write(CYASSL* ssl, const void* data, int sz)
}


int CyaSSL_read(CYASSL* ssl, void* data, int sz)
static int CyaSSL_read_internal(CYASSL* ssl, void* data, int sz, int peek)
{
int ret;

CYASSL_ENTER("SSL_read()");
CYASSL_ENTER("CyaSSL_read_internal()");

#ifdef HAVE_ERRNO_H
errno = 0;
#endif

ret = ReceiveData(ssl, (byte*)data, min(sz, OUTPUT_RECORD_SIZE));
ret = ReceiveData(ssl, (byte*)data, min(sz, OUTPUT_RECORD_SIZE), peek);

CYASSL_LEAVE("SSL_read()", ret);
CYASSL_LEAVE("CyaSSL_read_internal()", ret);

if (ret < 0)
return SSL_FATAL_ERROR;
Expand All @@ -401,6 +401,22 @@ int CyaSSL_read(CYASSL* ssl, void* data, int sz)
}


int CyaSSL_peek(CYASSL* ssl, void* data, int sz)
{
CYASSL_ENTER("CyaSSL_peek()");

return CyaSSL_read_internal(ssl, data, sz, TRUE);
}


int CyaSSL_read(CYASSL* ssl, void* data, int sz)
{
CYASSL_ENTER("CyaSSL_read()");

return CyaSSL_read_internal(ssl, data, sz, FALSE);
}


int CyaSSL_send(CYASSL* ssl, const void* data, int sz, int flags)
{
int ret;
Expand Down

0 comments on commit dd259b1

Please sign in to comment.