[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [obfsproxy/master] Consistently don't use 'struct' with protocol_t, protocol_params_t.
commit 8ef4ccd9209a1ca4f946e7c82932cf28d7f95ba0
Author: Zack Weinberg <zackw@xxxxxxxxx>
Date: Sun Jul 24 16:30:58 2011 -0700
Consistently don't use 'struct' with protocol_t, protocol_params_t.
---
src/protocol.c | 12 ++++++------
src/protocol.h | 16 ++++++++--------
src/protocols/dummy.c | 25 ++++++++++++-------------
src/protocols/obfs2.h | 2 +-
src/test/unittest_dummy.c | 10 +++++-----
src/test/unittest_obfs2.c | 15 +++++++--------
6 files changed, 39 insertions(+), 41 deletions(-)
diff --git a/src/protocol.c b/src/protocol.c
index 212ddaa..a010d16 100644
--- a/src/protocol.c
+++ b/src/protocol.c
@@ -31,7 +31,7 @@ const size_t n_supported_protocols =
This function is called once for every listener through the runtime
of obfsproxy.
*/
-struct protocol_params_t *
+protocol_params_t *
proto_params_init(int n_options, const char *const *options)
{
size_t i;
@@ -73,7 +73,7 @@ proto_params_free(protocol_params_t *params)
Return a 'protocol_t' if successful, NULL otherwise.
*/
-struct protocol_t *
+protocol_t *
proto_create(protocol_params_t *params)
{
obfs_assert(params);
@@ -87,7 +87,7 @@ proto_create(protocol_params_t *params)
Not all protocols have a handshake.
*/
int
-proto_handshake(struct protocol_t *proto, void *buf) {
+proto_handshake(protocol_t *proto, void *buf) {
obfs_assert(proto);
obfs_assert(proto->vtable);
obfs_assert(proto->vtable->handshake);
@@ -98,7 +98,7 @@ proto_handshake(struct protocol_t *proto, void *buf) {
This function is responsible for sending protocol data.
*/
int
-proto_send(struct protocol_t *proto, void *source, void *dest) {
+proto_send(protocol_t *proto, void *source, void *dest) {
obfs_assert(proto);
obfs_assert(proto->vtable);
obfs_assert(proto->vtable->send);
@@ -109,7 +109,7 @@ proto_send(struct protocol_t *proto, void *source, void *dest) {
This function is responsible for receiving protocol data.
*/
enum recv_ret
-proto_recv(struct protocol_t *proto, void *source, void *dest) {
+proto_recv(protocol_t *proto, void *source, void *dest) {
obfs_assert(proto);
obfs_assert(proto->vtable);
obfs_assert(proto->vtable->recv);
@@ -121,7 +121,7 @@ proto_recv(struct protocol_t *proto, void *source, void *dest) {
It's called everytime we close a connection.
*/
void
-proto_destroy(struct protocol_t *proto) {
+proto_destroy(protocol_t *proto) {
obfs_assert(proto);
obfs_assert(proto->vtable);
obfs_assert(proto->vtable->destroy);
diff --git a/src/protocol.h b/src/protocol.h
index c1189ea..c023720 100644
--- a/src/protocol.h
+++ b/src/protocol.h
@@ -74,7 +74,7 @@ typedef struct protocol_vtable
struct evbuffer *dest);
/** Receive data from 'source' and pass it upstream to 'dest'. */
- enum recv_ret (*recv)(struct protocol_t *state,
+ enum recv_ret (*recv)(protocol_t *state,
struct evbuffer *source,
struct evbuffer *dest);
@@ -93,16 +93,16 @@ typedef struct protocol_vtable
name##_handshake, name##_send, name##_recv \
}
-struct protocol_params_t *proto_params_init(int n_options,
- const char *const *options);
+protocol_params_t *proto_params_init(int n_options,
+ const char *const *options);
void proto_params_free(protocol_params_t *params);
-struct protocol_t *proto_create(struct protocol_params_t *params);
-void proto_destroy(struct protocol_t *proto);
+protocol_t *proto_create(protocol_params_t *params);
+void proto_destroy(protocol_t *proto);
-int proto_handshake(struct protocol_t *proto, void *buf);
-int proto_send(struct protocol_t *proto, void *source, void *dest);
-enum recv_ret proto_recv(struct protocol_t *proto, void *source, void *dest);
+int proto_handshake(protocol_t *proto, void *buf);
+int proto_send(protocol_t *proto, void *source, void *dest);
+enum recv_ret proto_recv(protocol_t *proto, void *source, void *dest);
extern const protocol_vtable *const supported_protocols[];
extern const size_t n_supported_protocols;
diff --git a/src/protocols/dummy.c b/src/protocols/dummy.c
index 8646889..26fe525 100644
--- a/src/protocols/dummy.c
+++ b/src/protocols/dummy.c
@@ -15,7 +15,7 @@
static void usage(void);
static int parse_and_set_options(int n_options,
const char *const *options,
- struct protocol_params_t *params);
+ protocol_params_t *params);
/**
This function populates 'params' according to 'options' and sets up
@@ -24,11 +24,10 @@ static int parse_and_set_options(int n_options,
'options' is an array like this:
{"dummy","socks","127.0.0.1:6666"}
*/
-static struct protocol_params_t *
+static protocol_params_t *
dummy_init(int n_options, const char *const *options)
{
- struct protocol_params_t *params
- = xzalloc(sizeof(struct protocol_params_t));
+ protocol_params_t *params = xzalloc(sizeof(protocol_params_t));
params->vtable = &dummy_vtable;
if (parse_and_set_options(n_options, options, params) < 0) {
@@ -45,7 +44,7 @@ dummy_init(int n_options, const char *const *options)
*/
static int
parse_and_set_options(int n_options, const char *const *options,
- struct protocol_params_t *params)
+ protocol_params_t *params)
{
const char* defport;
@@ -100,7 +99,7 @@ usage(void)
}
static void
-dummy_fini(struct protocol_params_t *params)
+dummy_fini(protocol_params_t *params)
{
free(params);
}
@@ -110,17 +109,17 @@ dummy_fini(struct protocol_params_t *params)
protocol.
*/
-static struct protocol_t *
-dummy_create(struct protocol_params_t *params)
+static protocol_t *
+dummy_create(protocol_params_t *params)
{
/* Dummy needs no per-connection protocol-specific state. */
- struct protocol_t *proto = xzalloc(sizeof(struct protocol_t));
+ protocol_t *proto = xzalloc(sizeof(protocol_t));
proto->vtable = &dummy_vtable;
return proto;
}
static void
-dummy_destroy(struct protocol_t *proto)
+dummy_destroy(protocol_t *proto)
{
free(proto);
}
@@ -131,13 +130,13 @@ dummy_destroy(struct protocol_t *proto)
The dummy protocol just puts the data of 'source' in 'dest'.
*/
static int
-dummy_handshake(struct protocol_t *proto, struct evbuffer *buf)
+dummy_handshake(protocol_t *proto, struct evbuffer *buf)
{
return 0;
}
static int
-dummy_send(struct protocol_t *proto,
+dummy_send(protocol_t *proto,
struct evbuffer *source, struct evbuffer *dest)
{
return evbuffer_add_buffer(dest,source);
@@ -149,7 +148,7 @@ dummy_send(struct protocol_t *proto,
The dummy protocol just puts the data of 'source' into 'dest'.
*/
static enum recv_ret
-dummy_recv(struct protocol_t *proto,
+dummy_recv(protocol_t *proto,
struct evbuffer *source, struct evbuffer *dest)
{
if (evbuffer_add_buffer(dest,source)<0)
diff --git a/src/protocols/obfs2.h b/src/protocols/obfs2.h
index eb55a9f..107d15a 100644
--- a/src/protocols/obfs2.h
+++ b/src/protocols/obfs2.h
@@ -40,7 +40,7 @@ typedef struct obfs2_params_t {
} obfs2_params_t;
typedef struct obfs2_protocol_t {
- struct protocol_t super;
+ protocol_t super;
/** Current protocol state. We start out waiting for key information. Then
we have a key and wait for padding to arrive. Finally, we are sending
diff --git a/src/test/unittest_dummy.c b/src/test/unittest_dummy.c
index 4a2316d..aaeafa9 100644
--- a/src/test/unittest_dummy.c
+++ b/src/test/unittest_dummy.c
@@ -12,7 +12,7 @@ static void
test_dummy_option_parsing(void *unused)
{
struct option_parsing_case {
- struct protocol_params_t *result;
+ protocol_params_t *result;
short should_succeed;
short n_opts;
const char *const opts[4];
@@ -64,10 +64,10 @@ test_dummy_option_parsing(void *unused)
/* All the tests below use this test environment: */
struct test_dummy_state
{
- struct protocol_params_t *proto_params_client;
- struct protocol_params_t *proto_params_server;
- struct protocol_t *client_proto;
- struct protocol_t *server_proto;
+ protocol_params_t *proto_params_client;
+ protocol_params_t *proto_params_server;
+ protocol_t *client_proto;
+ protocol_t *server_proto;
struct evbuffer *output_buffer;
struct evbuffer *dummy_buffer;
};
diff --git a/src/test/unittest_obfs2.c b/src/test/unittest_obfs2.c
index 00fc12e..6767769 100644
--- a/src/test/unittest_obfs2.c
+++ b/src/test/unittest_obfs2.c
@@ -15,17 +15,16 @@
#define ALEN(x) (sizeof x/sizeof x[0])
static inline obfs2_protocol_t *
-downcast(struct protocol_t *proto)
+downcast(protocol_t *proto)
{
- return (obfs2_protocol_t *)
- ((char *)proto - offsetof(obfs2_protocol_t, super));
+ return DOWNCAST(obfs2_protocol_t, super, proto);
}
static void
test_obfs2_option_parsing(void *unused)
{
struct option_parsing_case {
- struct protocol_params_t *result;
+ protocol_params_t *result;
short should_succeed;
short n_opts;
const char *const opts[6];
@@ -78,10 +77,10 @@ test_obfs2_option_parsing(void *unused)
/* All the tests below use this test environment: */
struct test_obfs2_state
{
- struct protocol_params_t *proto_params_client;
- struct protocol_params_t *proto_params_server;
- struct protocol_t *client_proto;
- struct protocol_t *server_proto;
+ protocol_params_t *proto_params_client;
+ protocol_params_t *proto_params_server;
+ protocol_t *client_proto;
+ protocol_t *server_proto;
struct evbuffer *output_buffer;
struct evbuffer *dummy_buffer;
};
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits