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