Added more functionality to the ADC client test code.

This commit is contained in:
Jan Vidar Krey 2012-10-02 23:59:11 +02:00
parent 5136525abc
commit cb6236691b
3 changed files with 35 additions and 5 deletions

View File

@ -64,6 +64,7 @@ struct ADC_client
char* nick; char* nick;
char* desc; char* desc;
int flags; int flags;
void* ptr;
#ifdef SSL_SUPPORT #ifdef SSL_SUPPORT
const SSL_METHOD* ssl_method; const SSL_METHOD* ssl_method;
SSL_CTX* ssl_ctx; SSL_CTX* ssl_ctx;
@ -81,7 +82,6 @@ static void ADC_client_on_disconnected(struct ADC_client* client);
static void ADC_client_on_login(struct ADC_client* client); static void ADC_client_on_login(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);
static int ADC_client_on_recv_line(struct ADC_client* client, const char* line, size_t length); static int ADC_client_on_recv_line(struct ADC_client* client, const char* line, size_t length);
static void ADC_client_send(struct ADC_client* client, struct adc_message* msg);
static int ADC_client_send_queue(struct ADC_client* client); static int ADC_client_send_queue(struct ADC_client* client);
static void ADC_client_debug(struct ADC_client* client, const char* format, ...) static void ADC_client_debug(struct ADC_client* client, const char* format, ...)
@ -513,7 +513,7 @@ void ADC_client_send_info(struct ADC_client* client)
} }
struct ADC_client* ADC_client_create(const char* nickname, const char* description) struct ADC_client* ADC_client_create(const char* nickname, const char* description, void* ptr)
{ {
ADC_TRACE; ADC_TRACE;
struct ADC_client* client = (struct ADC_client*) hub_malloc_zero(sizeof(struct ADC_client)); struct ADC_client* client = (struct ADC_client*) hub_malloc_zero(sizeof(struct ADC_client));
@ -539,6 +539,7 @@ struct ADC_client* ADC_client_create(const char* nickname, const char* descripti
client->send_queue = ioq_send_create(); client->send_queue = ioq_send_create();
client->recv_queue = ioq_recv_create(); client->recv_queue = ioq_recv_create();
client->ptr = ptr;
return client; return client;
} }
@ -550,6 +551,8 @@ void ADC_client_destroy(struct ADC_client* client)
/* FIXME */ /* FIXME */
net_timer_shutdown(client->timer); net_timer_shutdown(client->timer);
#endif #endif
ioq_send_destroy(client->send_queue);
ioq_recv_destroy(client->recv_queue);
hub_free(client->timer); hub_free(client->timer);
adc_msg_free(client->info); adc_msg_free(client->info);
hub_free(client->nick); hub_free(client->nick);
@ -611,8 +614,9 @@ static void ADC_client_on_connected_ssl(struct ADC_client* client)
{ {
ADC_TRACE; ADC_TRACE;
net_con_update(client->con, NET_EVENT_READ); net_con_update(client->con, NET_EVENT_READ);
client->callback(client, ADC_CLIENT_SSL_OK, 0);
client->callback(client, ADC_CLIENT_CONNECTED, 0); client->callback(client, ADC_CLIENT_CONNECTED, 0);
ADC_client_send(client, ADC_HANDSHAKE); ADC_client_send(client, adc_msg_create(ADC_HANDSHAKE));
ADC_client_set_state(client, ps_protocol); ADC_client_set_state(client, ps_protocol);
} }
#endif #endif
@ -704,3 +708,23 @@ void ADC_client_set_callback(struct ADC_client* client, adc_client_cb cb)
ADC_TRACE; ADC_TRACE;
client->callback = cb; client->callback = cb;
} }
sid_t ADC_client_get_sid(const struct ADC_client* client)
{
return client->sid;
}
const char* ADC_client_get_nick(const struct ADC_client* client)
{
return client->nick;
}
const char* ADC_client_get_description(const struct ADC_client* client)
{
return client->desc;
}
void* ADC_client_get_ptr(const struct ADC_client* client)
{
return client->ptr;
}

View File

@ -105,13 +105,19 @@ struct ADC_client_callback_data
}; };
}; };
sid_t ADC_client_get_sid(const struct ADC_client* client);
const char* ADC_client_get_nick(const struct ADC_client* client);
const char* ADC_client_get_description(const struct ADC_client* client);
void* ADC_client_get_ptr(const struct ADC_client* client);
typedef int (*adc_client_cb)(struct ADC_client*, enum ADC_client_callback_type, struct ADC_client_callback_data* data); typedef int (*adc_client_cb)(struct ADC_client*, enum ADC_client_callback_type, struct ADC_client_callback_data* data);
struct ADC_client* ADC_client_create(const char* nickname, const char* description); struct ADC_client* ADC_client_create(const char* nickname, const char* description, void* ptr);
void ADC_client_set_callback(struct ADC_client* client, adc_client_cb); void ADC_client_set_callback(struct ADC_client* client, adc_client_cb);
void ADC_client_destroy(struct ADC_client* client); void ADC_client_destroy(struct ADC_client* client);
int ADC_client_connect(struct ADC_client* client, const char* address); int ADC_client_connect(struct ADC_client* client, const char* address);
void ADC_client_disconnect(struct ADC_client* client); void ADC_client_disconnect(struct ADC_client* client);
void ADC_client_send(struct ADC_client* client, struct adc_message* msg);
#endif /* HAVE_UHUB_ADC_CLIENT_H */ #endif /* HAVE_UHUB_ADC_CLIENT_H */

View File

@ -168,7 +168,7 @@ int main(int argc, char** argv)
memset(g_usermap, 0, sizeof(g_usermap)); memset(g_usermap, 0, sizeof(g_usermap));
client = ADC_client_create("uhub-admin", "stresstester"); client = ADC_client_create("uhub-admin", "stresstester", NULL);
ADC_client_set_callback(client, handle); ADC_client_set_callback(client, handle);
ADC_client_connect(client, argv[1]); ADC_client_connect(client, argv[1]);