diff options
author | Nick Mathewson <nickm@torproject.org> | 2003-09-04 16:05:08 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2003-09-04 16:05:08 +0000 |
commit | fd20011c263df7fa843d32a2323bff81357b5a20 (patch) | |
tree | 162072e508db0eea1be73e580752178449f66b94 /src/or | |
parent | 4fb92e5bf7144ec14f664913cfefb045fe813dfa (diff) | |
download | tor-fd20011c263df7fa843d32a2323bff81357b5a20.tar.gz tor-fd20011c263df7fa843d32a2323bff81357b5a20.zip |
Add initial interfaces and code for TLS support. Interfaces are right; code needs work and testing.
svn:r424
Diffstat (limited to 'src/or')
-rw-r--r-- | src/or/buffers.c | 33 | ||||
-rw-r--r-- | src/or/or.h | 8 |
2 files changed, 40 insertions, 1 deletions
diff --git a/src/or/buffers.c b/src/or/buffers.c index 3ea26dbabb..2cf313f10d 100644 --- a/src/or/buffers.c +++ b/src/or/buffers.c @@ -86,6 +86,23 @@ int read_to_buf(int s, int at_most, char **buf, int *buflen, int *buf_datalen, i } } +int read_to_buf_tls(tor_tls *tls, int at_most, char **buf, int *buflen, int *buf_datalen) { + int r; + assert(tls && *buf && buflen && buf_datalen); + + if (at_most > *buflen - *buf_datalen) + at_most = *buflen - *buf_datalen; + + if (at_most == 0) + return 0; + + r = tor_tls_read(tls, *buf+*buf_datalen, at_most); + if (r<0) + return r; + *buf_datalen += r; + return r; +} + int flush_buf(int s, char **buf, int *buflen, int *buf_flushlen, int *buf_datalen) { /* push from buf onto s @@ -127,6 +144,22 @@ int flush_buf(int s, char **buf, int *buflen, int *buf_flushlen, int *buf_datale } } +int flush_buf_tls(tor_tls *tls, char **buf, int *buflen, int *buf_flushlen, int *buf_datalen) +{ + int r; + assert(tls && *buf && buflen && buf_datalen); + if (*buf_flushlen == 0) + return 0; + r = tor_tls_write(tls, *buf, *buf_flushlen); + if (r < 0) { + return r; + } + *buf_datalen -= r; + *buf_flushlen -= r; + memmove(*buf, *buf+r, *buf_datalen); + return r; +} + int write_to_buf(char *string, int string_len, char **buf, int *buflen, int *buf_datalen) { diff --git a/src/or/or.h b/src/or/or.h index 9a8bb36276..7937a8333c 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -90,6 +90,7 @@ #endif #include "../common/crypto.h" +#include "../common/tortls.h" #include "../common/log.h" #include "../common/util.h" @@ -482,11 +483,17 @@ void buf_free(char *buf); int read_to_buf(int s, int at_most, char **buf, int *buflen, int *buf_datalen, int *reached_eof); /* grab from s, put onto buf, return how many bytes read */ +int read_to_buf_tls(tor_tls *tls, int at_most, char **buf, int *buflen, int *buf_datalen); + /* grab from s, put onto buf, return how many bytes read or a TLS + * status (same status codes as tor_tls_read) */ int flush_buf(int s, char **buf, int *buflen, int *buf_flushlen, int *buf_datalen); /* push from buf onto s * then memmove to front of buf * return -1 or how many bytes remain on the buf */ +int flush_buf_tls(tor_tls *tls, char **buf, int *buflen, int *buf_flushlen, int *buf_datalen); + /* As flush_buf, but returns number of bytes written or TLS status + * (same status codes as tor_tls_write) */ int write_to_buf(char *string, int string_len, char **buf, int *buflen, int *buf_datalen); @@ -494,7 +501,6 @@ int write_to_buf(char *string, int string_len, * return total number of bytes on the buf */ - int fetch_from_buf(char *string, int string_len, char **buf, int *buflen, int *buf_datalen); /* if there is string_len bytes in buf, write them onto string, |