minor updates on upcoming changelog
[tor.git] / src / or / proto_ext_or.c
blob057cf109ecc9c7a51c37c30c224ab078026b4f50
1 /* Copyright (c) 2001 Matej Pfajfar.
2 * Copyright (c) 2001-2004, Roger Dingledine.
3 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
4 * Copyright (c) 2007-2017, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
7 #include "or.h"
8 #include "buffers.h"
9 #include "ext_orport.h"
10 #include "proto_ext_or.h"
12 /** The size of the header of an Extended ORPort message: 2 bytes for
13 * COMMAND, 2 bytes for BODYLEN */
14 #define EXT_OR_CMD_HEADER_SIZE 4
16 /** Read <b>buf</b>, which should contain an Extended ORPort message
17 * from a transport proxy. If well-formed, create and populate
18 * <b>out</b> with the Extended ORport message. Return 0 if the
19 * buffer was incomplete, 1 if it was well-formed and -1 if we
20 * encountered an error while parsing it. */
21 int
22 fetch_ext_or_command_from_buf(buf_t *buf, ext_or_cmd_t **out)
24 char hdr[EXT_OR_CMD_HEADER_SIZE];
25 uint16_t len;
27 if (buf_datalen(buf) < EXT_OR_CMD_HEADER_SIZE)
28 return 0;
29 buf_peek(buf, hdr, sizeof(hdr));
30 len = ntohs(get_uint16(hdr+2));
31 if (buf_datalen(buf) < (unsigned)len + EXT_OR_CMD_HEADER_SIZE)
32 return 0;
33 *out = ext_or_cmd_new(len);
34 (*out)->cmd = ntohs(get_uint16(hdr));
35 (*out)->len = len;
36 buf_drain(buf, EXT_OR_CMD_HEADER_SIZE);
37 buf_get_bytes(buf, (*out)->body, len);
38 return 1;