Back to index

tor  0.2.3.19-rc
buffers.h
Go to the documentation of this file.
00001 /* Copyright (c) 2001 Matej Pfajfar.
00002  * Copyright (c) 2001-2004, Roger Dingledine.
00003  * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
00004  * Copyright (c) 2007-2012, The Tor Project, Inc. */
00005 /* See LICENSE for licensing information */
00006 
00012 #ifndef _TOR_BUFFERS_H
00013 #define _TOR_BUFFERS_H
00014 
00015 buf_t *buf_new(void);
00016 buf_t *buf_new_with_capacity(size_t size);
00017 void buf_free(buf_t *buf);
00018 void buf_clear(buf_t *buf);
00019 buf_t *buf_copy(const buf_t *buf);
00020 void buf_shrink(buf_t *buf);
00021 void buf_shrink_freelists(int free_all);
00022 void buf_dump_freelist_sizes(int severity);
00023 
00024 size_t buf_datalen(const buf_t *buf);
00025 size_t buf_allocation(const buf_t *buf);
00026 size_t buf_slack(const buf_t *buf);
00027 
00028 int read_to_buf(tor_socket_t s, size_t at_most, buf_t *buf, int *reached_eof,
00029                 int *socket_error);
00030 int read_to_buf_tls(tor_tls_t *tls, size_t at_most, buf_t *buf);
00031 
00032 int flush_buf(tor_socket_t s, buf_t *buf, size_t sz, size_t *buf_flushlen);
00033 int flush_buf_tls(tor_tls_t *tls, buf_t *buf, size_t sz, size_t *buf_flushlen);
00034 
00035 int write_to_buf(const char *string, size_t string_len, buf_t *buf);
00036 int write_to_buf_zlib(buf_t *buf, tor_zlib_state_t *state,
00037                       const char *data, size_t data_len, int done);
00038 int move_buf_to_buf(buf_t *buf_out, buf_t *buf_in, size_t *buf_flushlen);
00039 int fetch_from_buf(char *string, size_t string_len, buf_t *buf);
00040 int fetch_var_cell_from_buf(buf_t *buf, var_cell_t **out, int linkproto);
00041 int fetch_from_buf_http(buf_t *buf,
00042                         char **headers_out, size_t max_headerlen,
00043                         char **body_out, size_t *body_used, size_t max_bodylen,
00044                         int force_complete);
00045 socks_request_t *socks_request_new(void);
00046 void socks_request_free(socks_request_t *req);
00047 int fetch_from_buf_socks(buf_t *buf, socks_request_t *req,
00048                          int log_sockstype, int safe_socks);
00049 int fetch_from_buf_socks_client(buf_t *buf, int state, char **reason);
00050 int fetch_from_buf_line(buf_t *buf, char *data_out, size_t *data_len);
00051 
00052 int peek_buf_has_control0_command(buf_t *buf);
00053 
00054 #ifdef USE_BUFFEREVENTS
00055 int fetch_var_cell_from_evbuffer(struct evbuffer *buf, var_cell_t **out,
00056                                  int linkproto);
00057 int fetch_from_evbuffer_socks(struct evbuffer *buf, socks_request_t *req,
00058                               int log_sockstype, int safe_socks);
00059 int fetch_from_evbuffer_socks_client(struct evbuffer *buf, int state,
00060                                      char **reason);
00061 int fetch_from_evbuffer_http(struct evbuffer *buf,
00062                         char **headers_out, size_t max_headerlen,
00063                         char **body_out, size_t *body_used, size_t max_bodylen,
00064                         int force_complete);
00065 int peek_evbuffer_has_control0_command(struct evbuffer *buf);
00066 int write_to_evbuffer_zlib(struct evbuffer *buf, tor_zlib_state_t *state,
00067                            const char *data, size_t data_len,
00068                            int done);
00069 #endif
00070 
00071 #ifdef USE_BUFFEREVENTS
00072 #define generic_buffer_new() evbuffer_new()
00073 #define generic_buffer_len(b) evbuffer_get_length((b))
00074 #define generic_buffer_add(b,dat,len) evbuffer_add((b),(dat),(len))
00075 #define generic_buffer_get(b,buf,buflen) evbuffer_remove((b),(buf),(buflen))
00076 #define generic_buffer_clear(b) evbuffer_drain((b), evbuffer_get_length((b)))
00077 #define generic_buffer_free(b) evbuffer_free((b))
00078 #else
00079 #define generic_buffer_new() buf_new()
00080 #define generic_buffer_len(b) buf_datalen((b))
00081 #define generic_buffer_add(b,dat,len) write_to_buf((dat),(len),(b))
00082 #define generic_buffer_get(b,buf,buflen) fetch_from_buf((buf),(buflen),(b))
00083 #define generic_buffer_clear(b) buf_clear((b))
00084 #define generic_buffer_free(b) buf_free((b))
00085 #endif
00086 int generic_buffer_set_to_copy(generic_buffer_t **output,
00087                                const generic_buffer_t *input);
00088 
00089 void assert_buf_ok(buf_t *buf);
00090 
00091 #ifdef BUFFERS_PRIVATE
00092 int buf_find_string_offset(const buf_t *buf, const char *s, size_t n);
00093 #endif
00094 
00095 #endif
00096