Skip to content

Commit

Permalink
port to compile with MSVC
Browse files Browse the repository at this point in the history
  • Loading branch information
ambrop7 committed Jul 24, 2012
1 parent adec9ec commit a21e23f
Show file tree
Hide file tree
Showing 83 changed files with 1,069 additions and 639 deletions.
16 changes: 10 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,22 @@ if (NOT (SIZE_SIZE GREATER INT_SIZE OR SIZE_SIZE EQUAL INT_SIZE))
message(FATAL_ERROR "size_t must be greater or equal than int")
endif ()

add_definitions(-std=gnu99 -Werror=implicit-function-declaration -Wno-unused-value -Wno-parentheses -Wno-switch-enum -Wno-switch -Wredundant-decls)
if (MSVC)
add_definitions(/TP -D_CRT_SECURE_NO_WARNINGS /wd4065 /wd4018 /wd4533 /wd4244 /wd4102)
else ()
add_definitions(-std=gnu99 -Werror=implicit-function-declaration -Wno-unused-value -Wno-parentheses -Wno-switch-enum -Wno-switch -Wredundant-decls)
endif ()

# platform-specific stuff
if (WIN32)
add_definitions(-DBADVPN_USE_WINAPI -D_WIN32_WINNT=0x600 -DWIN32_LEAN_AND_MEAN)

set(CMAKE_REQUIRED_DEFINITIONS "-D_WIN32_WINNT=0x600")
check_symbol_exists(WSAID_WSASENDMSG "mswsock.h" HAVE_MSW_1)
check_symbol_exists(WSAID_WSARECVMSG "mswsock.h" HAVE_MSW_2)
check_symbol_exists(WSAID_ACCEPTEX "mswsock.h" HAVE_MSW_3)
check_symbol_exists(WSAID_GETACCEPTEXSOCKADDRS "mswsock.h" HAVE_MSW_4)
check_symbol_exists(WSAID_CONNECTEX "mswsock.h" HAVE_MSW_5)
check_symbol_exists(WSAID_WSASENDMSG "winsock2.h;mswsock.h" HAVE_MSW_1)
check_symbol_exists(WSAID_WSARECVMSG "winsock2.h;mswsock.h" HAVE_MSW_2)
check_symbol_exists(WSAID_ACCEPTEX "winsock2.h;mswsock.h" HAVE_MSW_3)
check_symbol_exists(WSAID_GETACCEPTEXSOCKADDRS "winsock2.h;mswsock.h" HAVE_MSW_4)
check_symbol_exists(WSAID_CONNECTEX "winsock2.h;mswsock.h" HAVE_MSW_5)
set(CMAKE_REQUIRED_DEFINITIONS "")
if (NOT (HAVE_MSW_1 AND HAVE_MSW_2 AND HAVE_MSW_3 AND HAVE_MSW_4 AND HAVE_MSW_5))
add_definitions(-DBADVPN_USE_SHIPPED_MSWSOCK)
Expand Down
12 changes: 4 additions & 8 deletions base/BLog.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
*/

#include <stdio.h>
#include <stddef.h>

#include "BLog.h"

Expand All @@ -37,17 +38,12 @@ struct _BLog_channel blog_channel_list[] = {

struct _BLog_global blog_global = {
#ifndef NDEBUG
.initialized = 0,
0
#endif
};

static char *level_names[] = {
[BLOG_ERROR] = "ERROR",
[BLOG_WARNING] = "WARNING",
[BLOG_NOTICE] = "NOTICE",
[BLOG_INFO] = "INFO",
[BLOG_DEBUG] = "DEBUG",
};
// keep in sync with level numbers in BLog.h!
static char *level_names[] = { NULL, "ERROR", "WARNING", "NOTICE", "INFO", "DEBUG" };

static void stdout_log (int channel, int level, const char *msg)
{
Expand Down
1 change: 1 addition & 0 deletions base/BLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
// auto-generated channel numbers and number of channels
#include <generated/blog_channels_defines.h>

// keep in sync with level names in BLog.c!
#define BLOG_ERROR 1
#define BLOG_WARNING 2
#define BLOG_NOTICE 3
Expand Down
2 changes: 1 addition & 1 deletion blog_generator/blog.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function print_help ($name)
EOD;

$channels_list .= <<<EOD
{.name = "{$ch_name[1]}", .loglevel = {$ch_priority[1]}},
{"{$ch_name[1]}", {$ch_priority[1]}},
EOD;

Expand Down
26 changes: 20 additions & 6 deletions bproto/BProto.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,36 +36,50 @@

#include <stdint.h>

#include <misc/packed.h>

#define BPROTO_TYPE_UINT8 1
#define BPROTO_TYPE_UINT16 2
#define BPROTO_TYPE_UINT32 3
#define BPROTO_TYPE_UINT64 4
#define BPROTO_TYPE_DATA 5
#define BPROTO_TYPE_CONSTDATA 6

B_START_PACKED
struct BProto_header_s {
uint16_t id;
uint16_t type;
} __attribute__((packed));
} B_PACKED;
B_END_PACKED

B_START_PACKED
struct BProto_uint8_s {
uint8_t v;
} __attribute__((packed));
} B_PACKED;
B_END_PACKED

B_START_PACKED
struct BProto_uint16_s {
uint16_t v;
} __attribute__((packed));
} B_PACKED;
B_END_PACKED

B_START_PACKED
struct BProto_uint32_s {
uint32_t v;
} __attribute__((packed));
} B_PACKED;
B_END_PACKED

B_START_PACKED
struct BProto_uint64_s {
uint64_t v;
} __attribute__((packed));
} B_PACKED;
B_END_PACKED

B_START_PACKED
struct BProto_data_header_s {
uint32_t len;
} __attribute__((packed));
} B_PACKED;
B_END_PACKED

#endif
2 changes: 1 addition & 1 deletion client/DPRelay.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static struct DPRelay_flow * create_flow (DPRelaySource *src, DPRelaySink *sink,
ASSERT(num_packets > 0)

// allocate structure
struct DPRelay_flow *flow = malloc(sizeof(*flow));
struct DPRelay_flow *flow = (struct DPRelay_flow *)malloc(sizeof(*flow));
if (!flow) {
BLog(BLOG_ERROR, "relay flow %d->%d: malloc failed", (int)src->source_id, (int)sink->dest_id);
goto fail0;
Expand Down
2 changes: 1 addition & 1 deletion client/DataProto.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ int DataProtoFlow_Init (DataProtoFlow *o, DataProtoSource *source, peerid_t sour
o->sink_desired = NULL;

// allocate buffer structure
struct DataProtoFlow_buffer *b = malloc(sizeof(*b));
struct DataProtoFlow_buffer *b = (struct DataProtoFlow_buffer *)malloc(sizeof(*b));
if (!b) {
BLog(BLOG_ERROR, "malloc failed");
goto fail0;
Expand Down
6 changes: 3 additions & 3 deletions client/FragmentProtoAssembler.c
Original file line number Diff line number Diff line change
Expand Up @@ -396,17 +396,17 @@ int FragmentProtoAssembler_Init (FragmentProtoAssembler *o, int input_mtu, Packe
o->time_tolerance = num_frames;

// allocate frames
if (!(o->frames_entries = BAllocArray(num_frames, sizeof(o->frames_entries[0])))) {
if (!(o->frames_entries = (struct FragmentProtoAssembler_frame *)BAllocArray(num_frames, sizeof(o->frames_entries[0])))) {
goto fail1;
}

// allocate chunks
if (!(o->frames_chunks = BAllocArray2(num_frames, o->num_chunks, sizeof(o->frames_chunks[0])))) {
if (!(o->frames_chunks = (struct FragmentProtoAssembler_chunk *)BAllocArray2(num_frames, o->num_chunks, sizeof(o->frames_chunks[0])))) {
goto fail2;
}

// allocate buffers
if (!(o->frames_buffer = BAllocArray(num_frames, o->output_mtu))) {
if (!(o->frames_buffer = (uint8_t *)BAllocArray(num_frames, o->output_mtu))) {
goto fail3;
}

Expand Down
6 changes: 3 additions & 3 deletions client/FrameDecider.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

#include <string.h>
#include <stddef.h>
#include <inttypes.h>

#include <misc/debug.h>
#include <misc/offset.h>
Expand All @@ -39,6 +38,7 @@
#include <misc/igmp_proto.h>
#include <misc/byteorder.h>
#include <misc/compare.h>
#include <misc/print_macros.h>

#include <client/FrameDecider.h>

Expand Down Expand Up @@ -553,13 +553,13 @@ int FrameDeciderPeer_Init (FrameDeciderPeer *o, FrameDecider *d, void *user, BLo
o->logfunc = logfunc;

// allocate MAC entries
if (!(o->mac_entries = BAllocArray(d->max_peer_macs, sizeof(struct _FrameDecider_mac_entry)))) {
if (!(o->mac_entries = (struct _FrameDecider_mac_entry *)BAllocArray(d->max_peer_macs, sizeof(struct _FrameDecider_mac_entry)))) {
PeerLog(o, BLOG_ERROR, "failed to allocate MAC entries");
goto fail0;
}

// allocate group entries
if (!(o->group_entries = BAllocArray(d->max_peer_groups, sizeof(struct _FrameDecider_group_entry)))) {
if (!(o->group_entries = (struct _FrameDecider_group_entry *)BAllocArray(d->max_peer_groups, sizeof(struct _FrameDecider_group_entry)))) {
PeerLog(o, BLOG_ERROR, "failed to allocate group entries");
goto fail1;
}
Expand Down
6 changes: 3 additions & 3 deletions client/PasswordListener.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@ void listener_handler (PasswordListener *l)
LinkedList2_Append(&l->clients_used, &client->list_node);

// allocate sslsocket structure
if (!(client->sock = malloc(sizeof(*client->sock)))) {
if (!(client->sock = (sslsocket *)malloc(sizeof(*client->sock)))) {
BLog(BLOG_ERROR, "malloc failedt");
goto fail0;
}

// accept connection
if (!BConnection_Init(&client->sock->con, BCONNECTION_SOURCE_LISTENER(&l->listener, NULL), l->bsys, client, (BConnection_handler)client_connection_handler)) {
if (!BConnection_Init(&client->sock->con, BConnection_source_listener(&l->listener, NULL), l->bsys, client, (BConnection_handler)client_connection_handler)) {
BLog(BLOG_ERROR, "BConnection_Init failed");
goto fail1;
}
Expand Down Expand Up @@ -257,7 +257,7 @@ int PasswordListener_Init (PasswordListener *l, BReactor *bsys, BAddr listen_add
l->ssl = ssl;

// allocate client entries
if (!(l->clients_data = BAllocArray(max_clients, sizeof(struct PasswordListenerClient)))) {
if (!(l->clients_data = (struct PasswordListenerClient *)BAllocArray(max_clients, sizeof(struct PasswordListenerClient)))) {
BLog(BLOG_ERROR, "BAllocArray failed");
goto fail0;
}
Expand Down
2 changes: 1 addition & 1 deletion client/SPProtoDecoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ int SPProtoDecoder_Init (SPProtoDecoder *o, PacketPassInterface *output, struct
// allocate plaintext buffer
if (SPPROTO_HAVE_ENCRYPTION(o->sp_params)) {
int buf_size = balign_up((SPPROTO_HEADER_LEN(o->sp_params) + o->output_mtu + 1), o->enc_block_size);
if (!(o->buf = malloc(buf_size))) {
if (!(o->buf = (uint8_t *)malloc(buf_size))) {
goto fail0;
}
}
Expand Down
2 changes: 1 addition & 1 deletion client/SPProtoEncoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ int SPProtoEncoder_Init (SPProtoEncoder *o, PacketRecvInterface *input, struct s
// allocate plaintext buffer
if (SPPROTO_HAVE_ENCRYPTION(o->sp_params)) {
int buf_size = balign_up((SPPROTO_HEADER_LEN(o->sp_params) + o->input_mtu + 1), o->enc_block_size);
if (!(o->buf = malloc(buf_size))) {
if (!(o->buf = (uint8_t *)malloc(buf_size))) {
goto fail1;
}
}
Expand Down
2 changes: 1 addition & 1 deletion client/SimpleStreamBuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ int SimpleStreamBuffer_Init (SimpleStreamBuffer *o, int buf_size, BPendingGroup
StreamRecvInterface_Init(&o->output, (StreamRecvInterface_handler_recv)output_handler_recv, o, pg);

// allocate buffer
if (!(o->buf = BAlloc(buf_size))) {
if (!(o->buf = (uint8_t *)BAlloc(buf_size))) {
goto fail1;
}

Expand Down
2 changes: 1 addition & 1 deletion client/StreamPeerIO.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void connector_handler (StreamPeerIO *pio, int is_error)
}

// init connection
if (!BConnection_Init(&pio->connect.sock.con, BCONNECTION_SOURCE_CONNECTOR(&pio->connect.connector), pio->reactor, pio, (BConnection_handler)connection_handler)) {
if (!BConnection_Init(&pio->connect.sock.con, BConnection_source_connector(&pio->connect.connector), pio->reactor, pio, (BConnection_handler)connection_handler)) {
PeerLog(pio, BLOG_ERROR, "BConnection_Init failed");
goto fail0;
}
Expand Down
Loading

0 comments on commit a21e23f

Please sign in to comment.