M Makefile => Makefile +2 -1
@@ 28,7 28,8 @@ init:
-@[ ! -f include/cJSON.h ] && ln -s ../libs/cJSON/cJSON.h include/cJSON.h \
|| echo "include/cJSON.h symlink already exists"
-@[ ! -f config.mk ] && \
- echo -e "DEBUG=#-DDEBUG\nLOGGING=-DLOGGING" > config.mk \
+ echo -e "DEBUG1=#-DDEBUG\nDEBUG2=#-DDEBUG2\nDEBUG=\$$(DEBUG1) \$$(DEBUG2)\nLOGGING=-DLOGGING" \
+ > config.mk \
|| echo "config.mk exists, skipping"
-@if [ ! -d libs/cJSON ]; then \
git clone https://github.com/DaveGamble/cJSON libs/cJSON; \
M include/baal.h => include/baal.h +26 -4
@@ 1,6 1,7 @@
// @Author: Skiqqy
// @License: GPL3
+#include <string.h>
#include "baaljlib.h" // Helper lib for sending/handling json
// Represents data used by the server, configs, sockets etc
@@ 28,6 29,20 @@ enum commmands {
COM_LEN, // This must be the final element in the enum.
};
+
+#define CNRM "\x1B[0m"
+#define CRED "\x1B[31m"
+#define CGRN "\x1B[32m"
+#define CYEL "\x1B[33m"
+#define CBLU "\x1B[34m"
+#define CMAG "\x1B[35m"
+#define CCYN "\x1B[36m"
+#define CWHT "\x1B[37m"
+
+#define INFO_COL CGRN
+#define WARN_COL CRED
+#define DEBUG_COL CYEL
+
// So that my compiler wont complain
#ifndef VERSION
#define VERSION ""
@@ 38,18 53,25 @@ enum commmands {
#endif
// Debug prints
-#ifdef DEBUG
- #define dprintf(str, ...) printf("DEBUG: "); printf(str, __VA_ARGS__)
+#if defined(DEBUG) || defined(DEBUG2)
+ #define dprintf(str, ...) \
+ printf("%sDEBUG%s: [ %s:%s():%d ] ", DEBUG_COL, CNRM, strchr(__FILE__, '/') + 1, __func__, __LINE__); \
+ printf(str, __VA_ARGS__)
#else
#define dprintf(str, ...) // No op
#endif
// Logging functions, these provide newlines, TODO. tidy up
-#define bwarn(str, ...) fprintf(stderr, "WARN: "); fprintf(stderr, str, __VA_ARGS__); \
+#define bwarn(str, ...) \
+ fprintf(stderr, "%sWARN%s: ", WARN_COL, CNRM); \
+ fprintf(stderr, str, __VA_ARGS__); \
fprintf(stderr, "\n")
#ifdef LOGGING
-#define binfo(str, ...) printf("INFO: "); printf(str, __VA_ARGS__); printf("\n")
+#define binfo(str, ...) \
+ printf("%sINFO%s: ", INFO_COL, CNRM); \
+ printf(str, __VA_ARGS__); \
+ printf("\n")
#else
#define binfo(str,...) /* no op */
#endif
M src/baal.c => src/baal.c +6 -0
@@ 87,9 87,15 @@ main(int argc, char* argv[])
}
}
+ // Show the format of a debug msg, we could use dprintf, but that would result in a double DEBUG txt
+#ifdef DEBUG
+ printf("Debugging enabled, format: %sDEBUG%s: [ file:function():line ] <MSG>\n", DEBUG_COL, CNRM);
+#endif
+
// Exec commands & pass arguments
if (argc - optind > 0) {
if (!strcmp("server", argv[optind])) {
+ dprintf("Prepping server mode.\n", NULL);
// TODO Tidy up
if (signal(SIGINT, flush_server) == SIG_ERR)
perror("signal");
M src/baaljlib.c => src/baaljlib.c +2 -1
@@ 6,7 6,8 @@
// Header file for this lib
#include "../include/baaljlib.h"
-#ifdef DEBUG
+// Only print on debug level 2
+#ifdef DEBUG2
void
dprintJSON(cJSON *json)
{
M src/baalserver.c => src/baalserver.c +1 -0
@@ 427,6 427,7 @@ server(int argc, char **argv)
handlers[REGISTER_HANDLER] = register_user_handler;
handlers[SEND_MAIL_HANDLER] = send_mail_handler;
+ dprintf("Starting server\n", NULL);
if (argc > 0) dprintf("Arguments:\n", NULL);
for (int i = 0; i < argc; i++) {
dprintf("argv[%d]=%s\n", i, argv[i]);