Fix logging, start fleshing out redirect profile API

Signed-off-by: Ikey Doherty <ikey@solus-project.com>
This commit is contained in:
Ikey Doherty
2017-10-22 02:39:47 +01:00
parent 1f73dd3e0b
commit e45340973a
6 changed files with 48 additions and 4 deletions
+11 -4
View File
@@ -19,6 +19,13 @@
#include "log.h"
#include "nica/util.h"
static const char *_log_id = "__init__";
void lsi_log_set_id(const char *id)
{
_log_id = id;
}
void lsi_log_debug(const char *format, ...)
{
if (!getenv("LSI_DEBUG")) {
@@ -35,7 +42,7 @@ void lsi_log_debug(const char *format, ...)
goto end;
}
fprintf(stderr, "\033[32;1m[lsi:debug]\033[0m %s\n", p);
fprintf(stderr, "\033[32;1m[lsi:%s]\033[0m %s\n", _log_id, p);
end:
va_end(va);
@@ -53,7 +60,7 @@ void lsi_log_info(const char *format, ...)
goto end;
}
fprintf(stderr, "\033[34;1m[lsi:info]\033[0m %s\n", p);
fprintf(stderr, "\033[34;1m[lsi:%s]\033[0m %s\n", _log_id, p);
end:
va_end(va);
@@ -71,7 +78,7 @@ void lsi_log_warn(const char *format, ...)
goto end;
}
fprintf(stderr, "\033[33;1m[lsi:warn]\033[0m %s\n", p);
fprintf(stderr, "\033[33;1m[lsi:%s]\033[0m %s\n", _log_id, p);
end:
va_end(va);
@@ -89,7 +96,7 @@ void lsi_log_error(const char *format, ...)
goto end;
}
fprintf(stderr, "\033[31;1m[lsi:error]\033[0m %s\n", p);
fprintf(stderr, "\033[31;1m[lsi:%s]\033[0m %s\n", _log_id, p);
end:
va_end(va);
+5
View File
@@ -15,6 +15,11 @@
#include <stdlib.h>
/**
* Set the ID used in all log output
*/
void lsi_log_set_id(const char *id);
/**
* Emit some debug information if LSI_DEBUG is set
*/
+1
View File
@@ -161,6 +161,7 @@ static void check_is_intercept_candidate(void)
work_mode = INTERCEPT_MODE_VENDOR_OFFENDER;
matched_process = "vendor_offender";
}
lsi_log_set_id(matched_process);
}
/**
+1
View File
@@ -153,6 +153,7 @@ __attribute__((constructor)) static void lsi_redirect_init(void)
/* Temporary hack, we'll make this more generic later */
if (strcmp(process_name, "ShooterGame") == 0) {
lsi_log_set_id("ShooterGame");
lsi_profile = lsi_redirect_profile_new("ARK Survival Evolved");
}
+22
View File
@@ -14,6 +14,7 @@
#include <stdlib.h>
#include <string.h>
#include "../common/log.h"
#include "redirect.h"
LsiRedirectProfile *lsi_redirect_profile_new(const char *name)
@@ -41,6 +42,27 @@ void lsi_redirect_profile_free(LsiRedirectProfile *self)
free(self);
}
void lsi_redirect_profile_insert_rule(LsiRedirectProfile *self, LsiRedirect *redirect)
{
LsiRedirectOperation op;
switch (redirect->type) {
case LSI_REDIRECT_PATH:
op = LSI_OPERATION_OPEN;
break;
default:
lsi_log_error("Attempted insert of unknown rule into '%s'", self->name);
break;
}
/* Set head or prepend the rule */
if (self->op_table[op]) {
self->op_table[op] = redirect->next = self->op_table[op];
} else {
self->op_table[op] = redirect;
}
}
/*
* Editor modelines - https://www.wireshark.org/tools/modelines.html
*
+8
View File
@@ -71,6 +71,14 @@ LsiRedirectProfile *lsi_redirect_profile_new(const char *name);
*/
void lsi_redirect_profile_free(LsiRedirectProfile *profile);
/**
* Attempt insert of a redirect rule into this profile
*
* @param profile Pointer to a valid LsiRedirectProfile
* @param redirect Pointer to an allocated LsiRedirect
*/
void lsi_redirect_profile_insert_rule(LsiRedirectProfile *self, LsiRedirect *redirect);
/*
* Editor modelines - https://www.wireshark.org/tools/modelines.html
*