Added stbbr_send

This commit is contained in:
James Booth
2015-05-24 21:46:26 +01:00
parent dbccbb70a5
commit dda02514df
4 changed files with 31 additions and 0 deletions

View File

@@ -42,6 +42,12 @@ stbbr_verify(char *stanza)
return verify_any(stanza);
}
void
stbbr_send(char *stream)
{
server_send(stream);
}
void
stbbr_stop(void)
{

View File

@@ -23,6 +23,8 @@
#define STREAM_END "</stream:stream>"
static GList *send_queue;
static XMPPClient *client;
static void _shutdown(void);
@@ -69,6 +71,16 @@ read_stream(void)
errno = 0;
while (TRUE) {
// send anything from queue
GList *curr_send = send_queue;
while (curr_send) {
write_stream(curr_send->data);
curr_send = g_list_next(curr_send);
}
g_list_free_full(send_queue, free);
send_queue = NULL;
int read_size = recv(client->sock, buf, 1, 0);
// client disconnect
@@ -216,6 +228,7 @@ _start_server_cb(void* userdata)
int
server_run(int port)
{
send_queue = NULL;
client = NULL;
log_init();
log_println("Starting on port: %d...", port);
@@ -274,6 +287,12 @@ server_run(int port)
return 0;
}
void
server_send(char *stream)
{
send_queue = g_list_append(send_queue, strdup(stream));
}
void
server_stop(void)
{
@@ -295,5 +314,7 @@ _shutdown(void)
prime_free_all();
stanza_free_all();
g_list_free_full(send_queue, free);
send_queue = NULL;
log_close();
}

View File

@@ -4,4 +4,6 @@
int server_run(int port);
void server_stop(void);
void server_send(char *stream);
#endif

View File

@@ -10,4 +10,6 @@ void stbbr_for(char *id, char *stream);
int stbbr_verify(char *stanza);
int stbbr_verify_last(char *stanza);
void stbbr_send(char *stream);
#endif