Various build fixes.

This commit is contained in:
Jan Vidar Krey 2009-08-28 16:04:45 +02:00
parent 52cbec24b6
commit 11b288a669
6 changed files with 42 additions and 69 deletions

8
.gitignore vendored
View File

@ -1,2 +1,8 @@
*~ *~
*.o *.[oa]
*.exe
*.gch
uhub-admin
adcrush
uhub

View File

@ -8,7 +8,6 @@ LD := $(CC)
MV := mv MV := mv
RANLIB := ranlib RANLIB := ranlib
CFLAGS += -pipe -Wall CFLAGS += -pipe -Wall
USE_PCH ?= YES
USE_SSL ?= NO USE_SSL ?= NO
USE_BIGENDIAN ?= AUTO USE_BIGENDIAN ?= AUTO
BITS ?= AUTO BITS ?= AUTO
@ -47,19 +46,16 @@ endif
ifeq ($(SILENT),YES) ifeq ($(SILENT),YES)
MSG_CC=@echo " CC:" $(notdir $^) && MSG_CC=@echo " CC:" $(notdir $^) &&
MSG_PCH=@echo " PCH:" $(notdir $@) &&
MSG_LD=@echo " LD:" $(notdir $@) && MSG_LD=@echo " LD:" $(notdir $@) &&
MSG_AR=@echo " AR:" $(notdir $@) && MSG_AR=@echo " AR:" $(notdir $@) &&
else else
MSG_CC= MSG_CC=
MSG_PCH=
MSG_LD= MSG_LD=
MSG_AR= MSG_AR=
endif endif
ifeq ($(TERSE), YES) ifeq ($(TERSE), YES)
MSG_CC=@ MSG_CC=@
MSG_PCH=@
MSG_LD=@ MSG_LD=@
MSG_AR=@ MSG_AR=@
MSG_CLEAN=-n "" MSG_CLEAN=-n ""
@ -67,8 +63,8 @@ else
MSG_CLEAN="Clean as a whistle" MSG_CLEAN="Clean as a whistle"
endif endif
CFLAGS += -I/source/libevent # CFLAGS += -I/source/libevent
LDFLAGS += -L/source/libevent # LDFLAGS += -L/source/libevent
ifeq ($(RELEASE),YES) ifeq ($(RELEASE),YES)
CFLAGS += -O3 -DNDEBUG CFLAGS += -O3 -DNDEBUG
@ -93,13 +89,6 @@ CFLAGS += -finstrument-functions
CFLAGS += -DDEBUG_FUNCTION_TRACE CFLAGS += -DDEBUG_FUNCTION_TRACE
endif endif
ifeq ($(USE_PCH),YES)
PCHSRC=src/uhub.h
PCH=src/uhub.h.gch
else
PCH=
endif
ifneq ($(BITS), AUTO) ifneq ($(BITS), AUTO)
ifeq ($(BITS), 64) ifeq ($(BITS), 64)
CFLAGS += -m64 CFLAGS += -m64
@ -230,27 +219,16 @@ autotest_BINARY=autotest/test$(BIN_EXT)
%.o: %.c %.o: %.c
$(MSG_CC) $(CC) -c $(CFLAGS) -o $@ $^ $(MSG_CC) $(CC) -c $(CFLAGS) -o $@ $^
all: $(uhub_BINARY) $(PCH) all: $(uhub_BINARY)
$(adcrush_BINARY): $(PCH) $(LIBUHUB) $(adcrush_OBJECTS) $(adcrush_BINARY): $(LIBUHUB) $(adcrush_OBJECTS)
$(MSG_LD) $(CC) -o $@ $(adcrush_OBJECTS) $(LIBUHUB) $(LDFLAGS) $(LDLIBS) $(MSG_LD) $(CC) -o $@ $^ $(LDFLAGS) $(LDLIBS)
$(admin_BINARY): $(PCH) $(LIBUCADC) $(LIBUHUB) $(admin_OBJECTS) $(admin_BINARY): $(admin_OBJECTS) $(libucadc_OBJECTS) $(libuhub_OBJECTS)
$(MSG_LD) $(CC) -o $@ $(admin_OBJECTS) $(LIBUCADC) $(LIBUHUB) $(LDFLAGS) $(LDLIBS) $(MSG_LD) $(CC) -o $@ $^ $(LDFLAGS) $(LDLIBS)
$(uhub_BINARY): $(PCH) $(LIBUHUB) $(uhub_OBJECTS) $(uhub_BINARY): $(libuhub_OBJECTS) $(uhub_OBJECTS)
$(MSG_LD) $(CC) -o $@ $(uhub_OBJECTS) $(LIBUHUB) $(LDFLAGS) $(LDLIBS) $(MSG_LD) $(CC) -o $@ $^ $(LDFLAGS) $(LDLIBS)
$(LIBUHUB): $(libuhub_OBJECTS)
$(MSG_AR) $(AR) rc $@ $^ && $(RANLIB) $@
$(LIBUCADC): $(libucadc_OBJECTS)
$(MSG_AR) $(AR) rc $@ $^ && $(RANLIB) $@
ifeq ($(USE_PCH),YES)
$(PCH): $(uhub_HEADERS)
$(MSG_PCH) $(CC) $(CFLAGS) -o $@ $(PCHSRC)
endif
autotest.c: $(autotest_SOURCES) autotest.c: $(autotest_SOURCES)
$(shell exotic --standalone $(autotest_SOURCES) > $@) $(shell exotic --standalone $(autotest_SOURCES) > $@)
@ -258,7 +236,7 @@ autotest.c: $(autotest_SOURCES)
$(autotest_OBJECTS): autotest.c $(autotest_OBJECTS): autotest.c
$(MSG_CC) $(CC) -c $(CFLAGS) -Isrc -o $@ $< $(MSG_CC) $(CC) -c $(CFLAGS) -Isrc -o $@ $<
$(autotest_BINARY): $(autotest_OBJECTS) $(LIBUHUB) $(autotest_BINARY): $(autotest_OBJECTS) $(libuhub_OBJECTS)
$(MSG_LD) $(CC) -o $@ $^ $(LDFLAGS) $(LDLIBS) $(MSG_LD) $(CC) -o $@ $^ $(LDFLAGS) $(LDLIBS)
autotest: $(autotest_BINARY) autotest: $(autotest_BINARY)
@ -279,10 +257,10 @@ install: $(uhub_BINARY)
endif endif
dist-clean: dist-clean:
@rm -rf $(all_OBJECTS) $(PCH) *~ core @rm -rf $(all_OBJECTS) *~ core
clean: clean:
@rm -rf $(libuhub_OBJECTS) $(PCH) *~ core $(uhub_BINARY) $(LIBUHUB) $(all_OBJECTS) && \ @rm -rf $(libuhub_OBJECTS) *~ core $(uhub_BINARY) $(admin_BINARY) $(autotest_BINARY) $(adcrush_BINARY) $(LIBUHUB) $(all_OBJECTS) && \
echo $(MSG_CLEAN) echo $(MSG_CLEAN)

View File

@ -17,11 +17,10 @@
* *
*/ */
#include "adcclient.h" #include "tools/adcclient.h"
#define ADC_HANDSHAKE "HSUP ADBASE ADTIGR\n" #define ADC_HANDSHAKE "HSUP ADBASE ADTIGR\n"
#define ADC_CID_SIZE 39 #define ADC_CID_SIZE 39
#define BIG_BUFSIZE 32768 #define BIG_BUFSIZE 32768
#define TIGERSIZE 24 #define TIGERSIZE 24
@ -83,6 +82,8 @@ static void timer_callback(struct net_timer* t, void* arg)
static void event_callback(struct net_connection* con, int events, void *arg) static void event_callback(struct net_connection* con, int events, void *arg)
{ {
struct ADC_client* client = (struct ADC_client*) arg; struct ADC_client* client = (struct ADC_client*) arg;
ADC_client_debug(client, "event_callback. events=%d", events);
if (events == NET_EVENT_SOCKERROR || events == NET_EVENT_CLOSED) if (events == NET_EVENT_SOCKERROR || events == NET_EVENT_CLOSED)
{ {
client->callbacks.connection(client, -1, "Closed/socket error"); client->callbacks.connection(client, -1, "Closed/socket error");
@ -269,6 +270,7 @@ void ADC_client_send_info(struct ADC_client* client)
int ADC_client_create(struct ADC_client* client, const char* nickname, const char* description) int ADC_client_create(struct ADC_client* client, const char* nickname, const char* description)
{ {
ADC_client_debug(client, "ADC_client_create: %s", nickname);
memset(client, 0, sizeof(struct ADC_client)); memset(client, 0, sizeof(struct ADC_client));
int sd = net_socket_create(PF_INET, SOCK_STREAM, IPPROTO_TCP); int sd = net_socket_create(PF_INET, SOCK_STREAM, IPPROTO_TCP);
@ -302,7 +304,6 @@ int ADC_client_connect(struct ADC_client* client, const char* address)
{ {
if (!ADC_client_parse_address(client, address)) if (!ADC_client_parse_address(client, address))
return 0; return 0;
client->hub_address = hub_strdup(address);
} }
int ret = net_connect(client->con->sd, (struct sockaddr*) &client->addr, sizeof(struct sockaddr_in)); int ret = net_connect(client->con->sd, (struct sockaddr*) &client->addr, sizeof(struct sockaddr_in));
@ -362,22 +363,29 @@ void ADC_client_disconnect(struct ADC_client* client)
static int ADC_client_parse_address(struct ADC_client* client, const char* arg) static int ADC_client_parse_address(struct ADC_client* client, const char* arg)
{ {
char* split; char* split;
int ssl = 0;
struct hostent* dns; struct hostent* dns;
struct in_addr* addr; struct in_addr* addr;
if (!arg) if (!arg)
return 0; return 0;
client->hub_address = hub_strdup(arg);
/* Minimum length of a valid address */ /* Minimum length of a valid address */
if (strlen(arg) < 9) if (strlen(arg) < 9)
return 0; return 0;
/* Check for ADC or ADCS */ /* Check for ADC or ADCS */
if (strncmp(arg, "adc://", 6) != 0 && strncmp(arg, "adcs://", 7) != 0) if (!strncmp(arg, "adc://", 6))
ssl = 0;
else if (!strncmp(arg, "adcs://", 7))
ssl = 1;
else
return 0; return 0;
/* Split hostname and port (if possible) */ /* Split hostname and port (if possible) */
split = strrchr(arg+6, ':'); split = strrchr(client->hub_address + 6 + ssl, ':');
if (split == 0 || strlen(split) < 2 || strlen(split) > 6) if (split == 0 || strlen(split) < 2 || strlen(split) > 6)
return 0; return 0;
@ -389,7 +397,7 @@ static int ADC_client_parse_address(struct ADC_client* client, const char* arg)
split[0] = 0; split[0] = 0;
/* Resolve IP address (FIXME: blocking call) */ /* Resolve IP address (FIXME: blocking call) */
dns = gethostbyname(arg+6); dns = gethostbyname(client->hub_address + 6 + ssl);
if (dns) if (dns)
{ {
addr = (struct in_addr*) dns->h_addr_list[0]; addr = (struct in_addr*) dns->h_addr_list[0];

View File

@ -20,8 +20,9 @@
#ifndef HAVE_UHUB_ADC_CLIENT_H #ifndef HAVE_UHUB_ADC_CLIENT_H
#define HAVE_UHUB_ADC_CLIENT_H #define HAVE_UHUB_ADC_CLIENT_H
#include "uhub.h"
#define ADC_BUFSIZE 16384 #define ADC_BUFSIZE 16384
#define ADC_SIDSIZE 4
enum ADC_client_state enum ADC_client_state
{ {
@ -65,27 +66,11 @@ struct ADC_client
char* desc; char* desc;
}; };
int ADC_client_create(struct ADC_client* client, const char* nickname, const char* description);
void ADC_client_destroy(struct ADC_client* client);
/** int ADC_client_connect(struct ADC_client* client, const char* address);
* Create/Allocate/Initialize an ADC_client struct void ADC_client_disconnect(struct ADC_client* client);
* NOTE: If this is successful, one must call ADC_client_destroy to cleanup afterwards. void ADC_client_send(struct ADC_client* client, char* msg);
*/
extern int ADC_client_create(struct ADC_client* client, const char* nickname, const char* description);
/**
* Destroy an ADC_client struct.
*/
extern void ADC_client_destroy(struct ADC_client* client);
extern int ADC_client_connect(struct ADC_client* client, const char* address);
extern void ADC_client_disconnect(struct ADC_client* client);
/**
* Send a message (ADC command)
*/
extern void ADC_client_send(struct ADC_client* client, char* msg);
#endif /* HAVE_UHUB_ADC_CLIENT_H */ #endif /* HAVE_UHUB_ADC_CLIENT_H */

View File

@ -6,12 +6,9 @@
#define ADC_CLIENTS_DEFAULT 100 #define ADC_CLIENTS_DEFAULT 100
#define ADC_MAX_CLIENTS 25000 #define ADC_MAX_CLIENTS 25000
#define ADC_CID_SIZE 39 #define ADC_CID_SIZE 39
#define BIG_BUFSIZE 32768 #define BIG_BUFSIZE 32768
#define TIGERSIZE 24 #define TIGERSIZE 24
#define ADCRUSH "adcrush/0.2" #define ADCRUSH "adcrush/0.2"
#define ADC_NICK "[BOT]adcrush" #define ADC_NICK "[BOT]adcrush"
#define ADC_DESC "crash\\stest\\sdummy" #define ADC_DESC "crash\\stest\\sdummy"

View File

@ -2,10 +2,7 @@
* A remote uhub admin client. * A remote uhub admin client.
*/ */
#include "uhub.h"
#include "adcclient.h" #include "adcclient.h"
#include "network/connection.h"
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
@ -15,7 +12,9 @@ int main(int argc, char** argv)
ADC_client_create(&client, "uhub-admin", "stresstester"); ADC_client_create(&client, "uhub-admin", "stresstester");
ADC_client_connect(&client, "adc://adc.extatic.org:1511"); ADC_client_connect(&client, "adc://adc.extatic.org:1511");
printf("START\n");
event_dispatch(); event_dispatch();
printf("STOP\n");
ADC_client_destroy(&client); ADC_client_destroy(&client);
net_destroy(); net_destroy();