Removed XMPPClient args

This commit is contained in:
James Booth
2015-05-16 22:37:38 +01:00
parent 94d1f1e84d
commit 1a28b331a5
3 changed files with 28 additions and 31 deletions

View File

@@ -4,14 +4,12 @@
#include <glib.h> #include <glib.h>
#include "server/parser.h" #include "server/parser.h"
#include "server/xmppclient.h"
#include "server/stanza.h" #include "server/stanza.h"
static int depth = 0; static int depth = 0;
static int do_reset = 0; static int do_reset = 0;
static XML_Parser parser; static XML_Parser parser;
static XMPPClient *xmppclient;
static XMPPStanza *curr_stanza; static XMPPStanza *curr_stanza;
static stream_start_func stream_start_cb = NULL; static stream_start_func stream_start_cb = NULL;
@@ -22,7 +20,7 @@ static void
start_element(void *data, const char *element, const char **attributes) start_element(void *data, const char *element, const char **attributes)
{ {
if (g_strcmp0(element, "stream:stream") == 0) { if (g_strcmp0(element, "stream:stream") == 0) {
stream_start_cb(xmppclient); stream_start_cb();
do_reset = 1; do_reset = 1;
return; return;
} }
@@ -51,11 +49,11 @@ end_element(void *data, const char *element)
} else { } else {
stanza_add(curr_stanza); stanza_add(curr_stanza);
if (stanza_get_child_by_ns(curr_stanza, "jabber:iq:auth")) { if (stanza_get_child_by_ns(curr_stanza, "jabber:iq:auth")) {
auth_cb(curr_stanza, xmppclient); auth_cb(curr_stanza);
} else { } else {
const char *id = stanza_get_id(curr_stanza); const char *id = stanza_get_id(curr_stanza);
if (id) { if (id) {
id_cb(id, xmppclient); id_cb(id);
} }
} }
@@ -74,9 +72,8 @@ handle_data(void *data, const char *content, int length)
} }
void void
parser_init(XMPPClient *client, stream_start_func startcb, auth_func authcb, id_func idcb) parser_init(stream_start_func startcb, auth_func authcb, id_func idcb)
{ {
xmppclient = client;
stream_start_cb = startcb; stream_start_cb = startcb;
auth_cb = authcb; auth_cb = authcb;
id_cb = idcb; id_cb = idcb;
@@ -103,7 +100,7 @@ parser_reset(void)
{ {
if (do_reset == 1) { if (do_reset == 1) {
parser_close(); parser_close();
parser_init(xmppclient, stream_start_cb, auth_cb, id_cb); parser_init(stream_start_cb, auth_cb, id_cb);
do_reset = 0; do_reset = 0;
} }
} }

View File

@@ -4,11 +4,11 @@
#include "server/stanza.h" #include "server/stanza.h"
#include "server/xmppclient.h" #include "server/xmppclient.h"
typedef void (*stream_start_func)(XMPPClient *client); typedef void (*stream_start_func)(void);
typedef void (*auth_func)(XMPPStanza *stanza, XMPPClient *client); typedef void (*auth_func)(XMPPStanza *stanza);
typedef void (*id_func)(const char *id, XMPPClient *client); typedef void (*id_func)(const char *id);
void parser_init(XMPPClient *client, stream_start_func startcb, auth_func authcb, id_func); void parser_init(stream_start_func startcb, auth_func authcb, id_func);
int parser_feed(char *chunk, int len); int parser_feed(char *chunk, int len);
void parser_close(void); void parser_close(void);
void parser_reset(void); void parser_reset(void);

View File

@@ -28,7 +28,7 @@ static void _shutdown(void);
static int listen_socket; static int listen_socket;
int int
listen_for_xmlstart(XMPPClient *client) listen_for_xmlstart(void)
{ {
int read_size; int read_size;
char buf[2]; char buf[2];
@@ -68,7 +68,7 @@ listen_for_xmlstart(XMPPClient *client)
} }
void void
send_to(XMPPClient *client, const char * const stanza) send_to(const char * const stanza)
{ {
int sent = 0; int sent = 0;
int to_send = strlen(stanza); int to_send = strlen(stanza);
@@ -81,15 +81,15 @@ send_to(XMPPClient *client, const char * const stanza)
} }
void void
stream_end(XMPPClient *client) stream_end(void)
{ {
log_print_chars("\n"); log_print_chars("\n");
log_println("--> Stream end callback fired"); log_println("--> Stream end callback fired");
send_to(client, STREAM_END); send_to(STREAM_END);
} }
int int
listen_to(XMPPClient *client) listen_to(void)
{ {
int read_size; int read_size;
char buf[2]; char buf[2];
@@ -103,7 +103,7 @@ listen_to(XMPPClient *client)
parser_reset(); parser_reset();
g_string_append_len(stream, buf, read_size); g_string_append_len(stream, buf, read_size);
if (g_str_has_suffix(stream->str, STREAM_END)) { if (g_str_has_suffix(stream->str, STREAM_END)) {
stream_end(client); stream_end();
break; break;
} }
memset(buf, 0, sizeof(buf)); memset(buf, 0, sizeof(buf));
@@ -132,18 +132,18 @@ listen_to(XMPPClient *client)
} }
void void
stream_start_callback(XMPPClient *client) stream_start_callback(void)
{ {
log_print_chars("\n"); log_print_chars("\n");
log_println("--> Stream start callback fired"); log_println("--> Stream start callback fired");
send_to(client, XML_START); send_to(XML_START);
send_to(client, STREAM_RESP); send_to(STREAM_RESP);
send_to(client, FEATURES); send_to(FEATURES);
log_print("RECV: "); log_print("RECV: ");
} }
void void
auth_callback(XMPPStanza *stanza, XMPPClient *client) auth_callback(XMPPStanza *stanza)
{ {
log_print_chars("\n"); log_print_chars("\n");
log_println("--> Auth callback fired"); log_println("--> Auth callback fired");
@@ -157,23 +157,23 @@ auth_callback(XMPPStanza *stanza, XMPPClient *client)
client->resource = strdup(resource->content->str); client->resource = strdup(resource->content->str);
if (g_strcmp0(client->password, prime_get_passwd()) != 0) { if (g_strcmp0(client->password, prime_get_passwd()) != 0) {
send_to(client, AUTH_FAIL); send_to(AUTH_FAIL);
send_to(client, STREAM_END); send_to(STREAM_END);
exit(0); exit(0);
} }
send_to(client, AUTH_RESP); send_to(AUTH_RESP);
log_print("RECV: "); log_print("RECV: ");
} }
void void
id_callback(const char *id, XMPPClient *client) id_callback(const char *id)
{ {
char *stream = prime_get_for(id); char *stream = prime_get_for(id);
if (stream) { if (stream) {
log_print_chars("\n"); log_print_chars("\n");
log_println("--> ID callback fired for '%s'", id); log_println("--> ID callback fired for '%s'", id);
send_to(client, stream); send_to(stream);
log_print("RECV: "); log_print("RECV: ");
} }
} }
@@ -236,15 +236,15 @@ server_run(int port)
} }
client = xmppclient_new(client_addr, client_socket); client = xmppclient_new(client_addr, client_socket);
parser_init(client, stream_start_callback, auth_callback, id_callback); parser_init(stream_start_callback, auth_callback, id_callback);
log_print("RECV: "); log_print("RECV: ");
int res = listen_for_xmlstart(client); int res = listen_for_xmlstart();
if (res == -1) { if (res == -1) {
return 0; return 0;
} }
log_print("RECV: "); log_print("RECV: ");
listen_to(client); listen_to();
return 1; return 1;
} }