Moved logging, added log level paramater to standalone runner
This commit is contained in:
@@ -27,7 +27,6 @@
|
|||||||
#include "server/server.h"
|
#include "server/server.h"
|
||||||
#include "server/prime.h"
|
#include "server/prime.h"
|
||||||
#include "server/verify.h"
|
#include "server/verify.h"
|
||||||
#include "server/log.h"
|
|
||||||
|
|
||||||
#include "stabber.h"
|
#include "stabber.h"
|
||||||
|
|
||||||
@@ -40,14 +39,12 @@ stbbr_start(stbbr_log_t loglevel, int port, int httpport)
|
|||||||
void
|
void
|
||||||
stbbr_set_timeout(int seconds)
|
stbbr_set_timeout(int seconds)
|
||||||
{
|
{
|
||||||
log_println(STBBR_LOGDEBUG, "Setting timeout: %d seconds", seconds);
|
|
||||||
verify_set_timeout(seconds);
|
verify_set_timeout(seconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
stbbr_auth_passwd(char *password)
|
stbbr_auth_passwd(char *password)
|
||||||
{
|
{
|
||||||
log_println(STBBR_LOGDEBUG, "Setting auth password: %s", password);
|
|
||||||
prime_required_passwd(password);
|
prime_required_passwd(password);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -55,7 +52,6 @@ stbbr_auth_passwd(char *password)
|
|||||||
int
|
int
|
||||||
stbbr_for_id(char *id, char *stream)
|
stbbr_for_id(char *id, char *stream)
|
||||||
{
|
{
|
||||||
log_println(STBBR_LOGDEBUG, "Stubbing for id: %s, stanza: %s", id, stream);
|
|
||||||
prime_for_id(id, stream);
|
prime_for_id(id, stream);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -63,7 +59,6 @@ stbbr_for_id(char *id, char *stream)
|
|||||||
int
|
int
|
||||||
stbbr_for_query(char *query, char *stream)
|
stbbr_for_query(char *query, char *stream)
|
||||||
{
|
{
|
||||||
log_println(STBBR_LOGDEBUG, "Stubbing for query: %s, stanza: %s", query, stream);
|
|
||||||
prime_for_query(query, stream);
|
prime_for_query(query, stream);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -71,34 +66,29 @@ stbbr_for_query(char *query, char *stream)
|
|||||||
void
|
void
|
||||||
stbbr_wait_for(char *id)
|
stbbr_wait_for(char *id)
|
||||||
{
|
{
|
||||||
log_println(STBBR_LOGDEBUG, "Waiting for id: %s", id);
|
|
||||||
server_wait_for(id);
|
server_wait_for(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
stbbr_last_received(char *stanza)
|
stbbr_last_received(char *stanza)
|
||||||
{
|
{
|
||||||
log_println(STBBR_LOGDEBUG, "verifying last: %s", stanza);
|
|
||||||
return verify_last(stanza);
|
return verify_last(stanza);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
stbbr_received(char *stanza)
|
stbbr_received(char *stanza)
|
||||||
{
|
{
|
||||||
log_println(STBBR_LOGDEBUG, "verifying: %s", stanza);
|
|
||||||
return verify_any(stanza);
|
return verify_any(stanza);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
stbbr_send(char *stream)
|
stbbr_send(char *stream)
|
||||||
{
|
{
|
||||||
log_println(STBBR_LOGDEBUG, "Sending: %s", stream);
|
|
||||||
server_send(stream);
|
server_send(stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
stbbr_stop(void)
|
stbbr_stop(void)
|
||||||
{
|
{
|
||||||
log_println(STBBR_LOGDEBUG, "Stopping stabber");
|
|
||||||
server_stop();
|
server_stop();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -131,10 +131,10 @@ static char*
|
|||||||
_levelstr(stbbr_log_t loglevel)
|
_levelstr(stbbr_log_t loglevel)
|
||||||
{
|
{
|
||||||
switch (loglevel) {
|
switch (loglevel) {
|
||||||
case STBBR_LOGERROR: return "ERROR";
|
case STBBR_LOGERROR: return "ERR";
|
||||||
case STBBR_LOGWARN: return "WARN";
|
case STBBR_LOGWARN: return "WRN";
|
||||||
case STBBR_LOGINFO: return "INFO";
|
case STBBR_LOGINFO: return "INF";
|
||||||
case STBBR_LOGDEBUG: return "DEBUG";
|
case STBBR_LOGDEBUG: return "DBG";
|
||||||
default: return "";
|
default: return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
#include "server/stanza.h"
|
#include "server/stanza.h"
|
||||||
#include "server/stanzas.h"
|
#include "server/stanzas.h"
|
||||||
|
#include "server/log.h"
|
||||||
|
|
||||||
static char *required_passwd = NULL;
|
static char *required_passwd = NULL;
|
||||||
static GHashTable *idstubs = NULL;
|
static GHashTable *idstubs = NULL;
|
||||||
@@ -60,6 +61,8 @@ prime_free_all(void)
|
|||||||
void
|
void
|
||||||
prime_required_passwd(char *password)
|
prime_required_passwd(char *password)
|
||||||
{
|
{
|
||||||
|
log_println(STBBR_LOGDEBUG, "Received auth password: %s", password);
|
||||||
|
|
||||||
free(required_passwd);
|
free(required_passwd);
|
||||||
required_passwd = strdup(password);
|
required_passwd = strdup(password);
|
||||||
}
|
}
|
||||||
@@ -74,6 +77,8 @@ void
|
|||||||
prime_for_id(const char *id, char *stream)
|
prime_for_id(const char *id, char *stream)
|
||||||
{
|
{
|
||||||
if (idstubs) {
|
if (idstubs) {
|
||||||
|
log_println(STBBR_LOGDEBUG, "Received stub for id: %s, stanza: %s", id, stream);
|
||||||
|
|
||||||
g_hash_table_insert(idstubs, strdup(id), strdup(stream));
|
g_hash_table_insert(idstubs, strdup(id), strdup(stream));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -88,6 +93,8 @@ void
|
|||||||
prime_for_query(const char *query, char *stream)
|
prime_for_query(const char *query, char *stream)
|
||||||
{
|
{
|
||||||
if (querystubs) {
|
if (querystubs) {
|
||||||
|
log_println(STBBR_LOGDEBUG, "Received stub for query: %s, stanza: %s", query, stream);
|
||||||
|
|
||||||
XMPPStanza *stanza = stanza_parse(stream);
|
XMPPStanza *stanza = stanza_parse(stream);
|
||||||
g_hash_table_insert(querystubs, strdup(query), stanza);
|
g_hash_table_insert(querystubs, strdup(query), stanza);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -241,7 +241,7 @@ query_callback(const char *query, const char *id)
|
|||||||
void
|
void
|
||||||
server_wait_for(char *id)
|
server_wait_for(char *id)
|
||||||
{
|
{
|
||||||
log_println(STBBR_LOGINFO, "WAIT for stanza with id: %s", id);
|
log_println(STBBR_LOGINFO, "Received wait for stanza with id: %s", id);
|
||||||
while (TRUE) {
|
while (TRUE) {
|
||||||
int res = stanzas_contains_id(id);
|
int res = stanzas_contains_id(id);
|
||||||
if (res) {
|
if (res) {
|
||||||
@@ -376,6 +376,8 @@ server_run(stbbr_log_t loglevel, int port, int httpport)
|
|||||||
void
|
void
|
||||||
server_send(char *stream)
|
server_send(char *stream)
|
||||||
{
|
{
|
||||||
|
log_println(STBBR_LOGDEBUG, "Received send: %s", stream);
|
||||||
|
|
||||||
pthread_mutex_lock(&send_queue_lock);
|
pthread_mutex_lock(&send_queue_lock);
|
||||||
send_queue = g_list_append(send_queue, strdup(stream));
|
send_queue = g_list_append(send_queue, strdup(stream));
|
||||||
pthread_mutex_unlock(&send_queue_lock);
|
pthread_mutex_unlock(&send_queue_lock);
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ static int timeoutsecs = 0;
|
|||||||
void
|
void
|
||||||
verify_set_timeout(int seconds)
|
verify_set_timeout(int seconds)
|
||||||
{
|
{
|
||||||
|
log_println(STBBR_LOGDEBUG, "Setting timeout: %d seconds", seconds);
|
||||||
|
|
||||||
if (seconds <= 0) {
|
if (seconds <= 0) {
|
||||||
timeoutsecs = 0;
|
timeoutsecs = 0;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
18
stabber.c
18
stabber.c
@@ -33,11 +33,14 @@ main(int argc , char *argv[])
|
|||||||
{
|
{
|
||||||
int port = 0;
|
int port = 0;
|
||||||
int httpport = 0;
|
int httpport = 0;
|
||||||
|
char *loglevelarg = "INFO";
|
||||||
|
stbbr_log_t loglevel = STBBR_LOGINFO;
|
||||||
|
|
||||||
GOptionEntry entries[] =
|
GOptionEntry entries[] =
|
||||||
{
|
{
|
||||||
{ "port", 'p', 0, G_OPTION_ARG_INT, &port, "Listen port", NULL },
|
{ "port", 'p', 0, G_OPTION_ARG_INT, &port, "Listen port", NULL },
|
||||||
{ "http", 'h', 0, G_OPTION_ARG_INT, &httpport, "HTTP Listen port", NULL },
|
{ "http", 'h', 0, G_OPTION_ARG_INT, &httpport, "HTTP Listen port", NULL },
|
||||||
|
{ "log",'l', 0, G_OPTION_ARG_STRING, &loglevelarg, "Set logging levels, DEBUG, INFO (default), WARN, ERROR", "LEVEL" },
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -60,7 +63,20 @@ main(int argc , char *argv[])
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
stbbr_start(STBBR_LOGINFO, port, httpport);
|
if (g_strcmp0(loglevelarg, "INFO") == 0) {
|
||||||
|
loglevel = STBBR_LOGINFO;
|
||||||
|
} else if (g_strcmp0(loglevelarg, "DEBUG") == 0) {
|
||||||
|
loglevel = STBBR_LOGDEBUG;
|
||||||
|
} else if (g_strcmp0(loglevelarg, "WARN") == 0) {
|
||||||
|
loglevel = STBBR_LOGWARN;
|
||||||
|
} else if (g_strcmp0(loglevelarg, "ERROR") == 0) {
|
||||||
|
loglevel = STBBR_LOGERROR;
|
||||||
|
} else {
|
||||||
|
printf("Invalid log level supplied, must be one of DEBUG, INFO, WARN, ERROR.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
stbbr_start(loglevel, port, httpport);
|
||||||
|
|
||||||
pthread_exit(0);
|
pthread_exit(0);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user