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