Commit 234c5015 authored by Nick Mathewson's avatar Nick Mathewson 🦀
Browse files

Move protocol-specific functions out of buffers.c

This commit does not change the implementation of any function: it
only moves code and adds new includes as necessary.  Part of #23149.
parent babe31fc
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
  o Code simplifications and refactoring:
    - Split the portions of the buffer.c module that handle particular
      protocols into separate modules. Part of ticket 23149.
+4 −978

File changed.

Preview size limit exceeded, changes collapsed.

+6 −20
Original line number Diff line number Diff line
@@ -39,23 +39,13 @@ int write_to_buf(const char *string, size_t string_len, buf_t *buf);
int write_to_buf_compress(buf_t *buf, tor_compress_state_t *state,
                          const char *data, size_t data_len, int done);
int move_buf_to_buf(buf_t *buf_out, buf_t *buf_in, size_t *buf_flushlen);
void peek_from_buf(char *string, size_t string_len, const buf_t *buf);
void buf_remove_from_front(buf_t *buf, size_t n);
int fetch_from_buf(char *string, size_t string_len, buf_t *buf);
int fetch_var_cell_from_buf(buf_t *buf, var_cell_t **out, int linkproto);
int fetch_from_buf_http(buf_t *buf,
                        char **headers_out, size_t max_headerlen,
                        char **body_out, size_t *body_used, size_t max_bodylen,
                        int force_complete);
socks_request_t *socks_request_new(void);
void socks_request_free(socks_request_t *req);
int fetch_from_buf_socks(buf_t *buf, socks_request_t *req,
                         int log_sockstype, int safe_socks);
int fetch_from_buf_socks_client(buf_t *buf, int state, char **reason);
int fetch_from_buf_line(buf_t *buf, char *data_out, size_t *data_len);

int peek_buf_has_control0_command(buf_t *buf);
#define PEEK_BUF_STARTSWITH_MAX 16
int peek_buf_startswith(const buf_t *buf, const char *cmd);
int peek_buf_has_http_command(const buf_t *buf);

int fetch_ext_or_command_from_buf(buf_t *buf, ext_or_cmd_t **out);

@@ -64,14 +54,15 @@ int buf_set_to_copy(buf_t **output,

void assert_buf_ok(buf_t *buf);

int buf_find_string_offset(const buf_t *buf, const char *s, size_t n);
void buf_pullup(buf_t *buf, size_t bytes);

#ifdef BUFFERS_PRIVATE
STATIC int buf_find_string_offset(const buf_t *buf, const char *s, size_t n);
STATIC void buf_pullup(buf_t *buf, size_t bytes);
#ifdef TOR_UNIT_TESTS
void buf_get_first_chunk_data(const buf_t *buf, const char **cp, size_t *sz);
buf_t *buf_new_with_data(const char *cp, size_t sz);
#endif
STATIC size_t preferred_chunk_size(size_t target);
ATTR_UNUSED STATIC size_t preferred_chunk_size(size_t target);

#define DEBUG_CHUNK_ALLOC
/** A single chunk on a buffer. */
@@ -103,10 +94,5 @@ struct buf_t {
};
#endif

#ifdef BUFFERS_PRIVATE
STATIC int buf_http_find_content_length(const char *headers, size_t headerlen,
                                        size_t *result_out);
#endif

#endif
+2 −0
Original line number Diff line number Diff line
@@ -86,6 +86,8 @@
#include "hs_common.h"
#include "hs_ident.h"
#include "nodelist.h"
#include "proto_http.h"
#include "proto_socks.h"
#include "policies.h"
#include "reasons.h"
#include "relay.h"
+1 −0
Original line number Diff line number Diff line
@@ -82,6 +82,7 @@
#include "main.h"
#include "nodelist.h"
#include "policies.h"
#include "proto_socks.h"
#include "reasons.h"
#include "relay.h"
#include "rendclient.h"
Loading