Added log levels
This commit is contained in:
@@ -28,14 +28,12 @@
|
||||
#include "server/prime.h"
|
||||
#include "server/verify.h"
|
||||
|
||||
typedef struct server_args_t {
|
||||
int port;
|
||||
} StabberArgs;
|
||||
#include "stabber.h"
|
||||
|
||||
int
|
||||
stbbr_start(int port, int httpport)
|
||||
stbbr_start(stbbr_log_t loglevel, int port, int httpport)
|
||||
{
|
||||
return server_run(port, httpport);
|
||||
return server_run(loglevel, port, httpport);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -90,7 +90,7 @@ send_response(struct MHD_Connection* conn, const char* body, int status_code)
|
||||
int connection_cb(void* cls, struct MHD_Connection* conn, const char* url, const char* method,
|
||||
const char* version, const char* data, size_t* size, void** con_cls)
|
||||
{
|
||||
prctl(PR_SET_NAME, "stbbrhttp");
|
||||
prctl(PR_SET_NAME, "http");
|
||||
|
||||
if (*con_cls == NULL) {
|
||||
ConnectionInfo *con_info = create_connection_info();
|
||||
@@ -123,6 +123,7 @@ int connection_cb(void* cls, struct MHD_Connection* conn, const char* url, const
|
||||
switch (con_info->stbbr_op) {
|
||||
|
||||
case STBBR_OP_SEND:
|
||||
log_println("STBBR_OP_SEND");
|
||||
server_send(con_info->body->str);
|
||||
return send_response(conn, NULL, MHD_HTTP_OK);
|
||||
|
||||
|
||||
@@ -29,7 +29,10 @@
|
||||
#include <glib.h>
|
||||
#include <glib/gstdio.h>
|
||||
|
||||
#include "stabber.h"
|
||||
|
||||
static FILE *logp;
|
||||
static stbbr_log_t minlevel;
|
||||
|
||||
gchar *
|
||||
_xdg_get_data_home(void)
|
||||
@@ -102,8 +105,9 @@ _mkdir_recursive(const char *dir)
|
||||
}
|
||||
|
||||
void
|
||||
log_init(void)
|
||||
log_init(stbbr_log_t loglevel)
|
||||
{
|
||||
minlevel = loglevel;
|
||||
gchar *xdg_data = _xdg_get_data_home();
|
||||
GString *log_dir = g_string_new(xdg_data);
|
||||
g_string_append(log_dir, "/stabber/logs");
|
||||
|
||||
@@ -23,7 +23,9 @@
|
||||
#ifndef __H_LOG
|
||||
#define __H_LOG
|
||||
|
||||
void log_init(void);
|
||||
#include "stabber.h"
|
||||
|
||||
void log_init(stbbr_log_t loglevel);
|
||||
void log_close(void);
|
||||
void log_println(const char * const msg, ...);
|
||||
|
||||
|
||||
@@ -298,7 +298,7 @@ _start_server_cb(void* userdata)
|
||||
}
|
||||
|
||||
int
|
||||
server_run(int port, int httpport)
|
||||
server_run(stbbr_log_t loglevel, int port, int httpport)
|
||||
{
|
||||
pthread_mutex_lock(&send_queue_lock);
|
||||
send_queue = NULL;
|
||||
@@ -308,7 +308,7 @@ server_run(int port, int httpport)
|
||||
client = NULL;
|
||||
verify_set_timeout(10);
|
||||
|
||||
log_init();
|
||||
log_init(loglevel);
|
||||
log_println("Starting on port: %d...", port);
|
||||
|
||||
// create listen socket
|
||||
|
||||
@@ -23,7 +23,9 @@
|
||||
#ifndef __H_SERVER
|
||||
#define __H_SERVER
|
||||
|
||||
int server_run(int port, int httpport);
|
||||
#include "stabber.h"
|
||||
|
||||
int server_run(stbbr_log_t loglevel, int port, int httpport);
|
||||
void server_stop(void);
|
||||
|
||||
void server_wait_for(char *id);
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
#include <stabber.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include "stabber.h"
|
||||
|
||||
int
|
||||
main(int argc , char *argv[])
|
||||
{
|
||||
@@ -58,7 +60,7 @@ main(int argc , char *argv[])
|
||||
return 1;
|
||||
}
|
||||
|
||||
stbbr_start(port, httpport);
|
||||
stbbr_start(STBBR_LOGINFO, port, httpport);
|
||||
|
||||
pthread_exit(0);
|
||||
}
|
||||
|
||||
11
stabber.h
11
stabber.h
@@ -23,13 +23,20 @@
|
||||
#ifndef __H_STABBER
|
||||
#define __H_STABBER
|
||||
|
||||
int stbbr_start(int port, int httpport);
|
||||
typedef enum {
|
||||
STBBR_LOGDEBUG,
|
||||
STBBR_LOGINFO,
|
||||
STBBR_LOGWARN,
|
||||
STBBR_LOGERROR
|
||||
} stbbr_log_t;
|
||||
|
||||
int stbbr_start(stbbr_log_t loglevel, int port, int httpport);
|
||||
void stbbr_stop(void);
|
||||
|
||||
void stbbr_set_timeout(int seconds);
|
||||
|
||||
int stbbr_auth_passwd(char *password);
|
||||
void stbbr_for_id(char *id, char *stream);
|
||||
int stbbr_for_id(char *id, char *stream);
|
||||
int stbbr_for_query(char *query, char *stream);
|
||||
|
||||
void stbbr_wait_for(char *id);
|
||||
|
||||
@@ -2,9 +2,11 @@
|
||||
#include <pthread.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "stabber.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
stbbr_start(5230, 5231);
|
||||
stbbr_start(STBBR_LOGDEBUG, 5230, 5231);
|
||||
|
||||
stbbr_auth_passwd("password");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user