pprogress
This commit is contained in:
parent
a7a34db884
commit
76b8da4685
33
src/main.c
33
src/main.c
@ -15,19 +15,22 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <dirent.h>
|
||||
#include <sys/stat.h>
|
||||
#include <dirent.h> // library für Interaktion mit Ordnerstrukturen
|
||||
#include <sys/stat.h> // library für is_directory: Unterscheidung zwischen Dateien und Ordnern
|
||||
|
||||
#define MAX_LINE 2048
|
||||
#define INITIAL_ENTRIES 1000
|
||||
#define GROWTH_FACTOR 2
|
||||
#define MAX_LINE_LENGTH_BUF 2048
|
||||
#define INITIAL_ENTRIES 1000 // globale Variable zur initialen Speicherallokation in allocate_initial_memory(). Wird falls nötig um GROWTH_FACTOR erweitert
|
||||
#define GROWTH_FACTOR 2 // wird in expand_memory_if_needed() genutzt, um den Speicher zu vergrößern
|
||||
#define MAX_FILTERS 100
|
||||
#define MAX_URL_PATH_LENGTH 512
|
||||
|
||||
// definiert Variablen für den Filtermodus. FILTER_INCLUDE=0, FILTER_EXCLUDE=1. Verbessert die Lesbarkeit des Codes.
|
||||
typedef enum {
|
||||
FILTER_INCLUDE,
|
||||
FILTER_EXCLUDE
|
||||
} filter_mode_t;
|
||||
|
||||
// struct für die Darstellung von Timestamps. Die granulare Trennung in verschiedene int-Werte macht die spätere Verarbeitung modular anpassbar/erweiterbar und erleichtert die Verarbeitung.
|
||||
struct simple_time {
|
||||
int day;
|
||||
int month;
|
||||
@ -37,31 +40,36 @@ struct simple_time {
|
||||
int second;
|
||||
};
|
||||
|
||||
// Struktur für die Darstellung eines Standard-NGINX-Logeintrags.
|
||||
struct log_entry {
|
||||
char ip_address[50];
|
||||
char request_method[10];
|
||||
char url_path[200];
|
||||
char ip_address[50]; // ausreichende Längenbegrenzung für IP-Adressen. Könnte theoretisch auch ipv6 (ungetestet)
|
||||
char request_method[10]; // GET, POST, PUT, DELETE, PROPFIND ...
|
||||
char url_path[MAX_URL_PATH_LENGTH]; // Pfade können lang werden, insbesodere bei base64-Strings wie oft in modernen Applikationen oder Malware verwendet
|
||||
int status_code;
|
||||
int bytes_sent;
|
||||
struct simple_time time;
|
||||
};
|
||||
|
||||
// Struktur für einen Status-Filtereintrag mit Inhalt & Modus
|
||||
struct status_filter {
|
||||
int code;
|
||||
filter_mode_t mode;
|
||||
};
|
||||
|
||||
// für IP-Adressen
|
||||
struct ip_filter {
|
||||
char ip_address[50];
|
||||
filter_mode_t mode;
|
||||
};
|
||||
|
||||
// für Zeit, Start- und Endzeit
|
||||
struct time_filter {
|
||||
struct simple_time start_time;
|
||||
struct simple_time end_time;
|
||||
filter_mode_t mode;
|
||||
};
|
||||
|
||||
// Struktur zum erhalten aller Filtereinträge, kann im Dialogbetrieb bearbeitet werden. Mit Zähler.
|
||||
struct filter_system {
|
||||
struct status_filter status_filters[MAX_FILTERS];
|
||||
int status_count;
|
||||
@ -72,18 +80,21 @@ struct filter_system {
|
||||
struct time_filter time_filters[MAX_FILTERS];
|
||||
int time_count;
|
||||
|
||||
int combination_mode;
|
||||
int combination_mode; // 0=AND-Filter oder 1=OR-Filter
|
||||
};
|
||||
|
||||
// Initialisierung eines Arrays für die Logeinträge und weiterer Startvariablen
|
||||
struct log_entry *all_entries = NULL;
|
||||
int max_entries = 0;
|
||||
int total_entries = 0;
|
||||
struct filter_system filters = {0};
|
||||
|
||||
// Helper für die Erkennung von Leerzeichen
|
||||
int is_space(char c) {
|
||||
return (c == ' ' || c == '\t');
|
||||
}
|
||||
|
||||
// Helper zum Überspringen von Leerzeichen, gibt den Pointer für das nächste nicht-Leerzeichen zurück. Nötig für strtok-Parser.
|
||||
char* skip_spaces(char* str) {
|
||||
while (is_space(*str)) {
|
||||
str++;
|
||||
@ -91,6 +102,7 @@ char* skip_spaces(char* str) {
|
||||
return str;
|
||||
}
|
||||
|
||||
// TODO
|
||||
void copy_until_space(char* destination, char* source, int max_length) {
|
||||
int i = 0;
|
||||
while (source[i] != ' ' && source[i] != '\0' && i < max_length - 1) {
|
||||
@ -100,6 +112,7 @@ void copy_until_space(char* destination, char* source, int max_length) {
|
||||
destination[i] = '\0';
|
||||
}
|
||||
|
||||
// NGINX speichert Timestamps mit Monatskürzel. Umwandlung in Zahlen für maschinelle Verarbeitung.
|
||||
int month_name_to_number(char* month_name) {
|
||||
if (strncmp(month_name, "Jan", 3) == 0) return 1;
|
||||
if (strncmp(month_name, "Feb", 3) == 0) return 2;
|
||||
@ -343,7 +356,7 @@ void load_regular_file(char* filename) {
|
||||
}
|
||||
|
||||
printf("Lade Datei: %s\n", filename);
|
||||
char line[MAX_LINE];
|
||||
char line[MAX_LINE_LENGTH_BUF];
|
||||
int loaded_from_this_file = 0;
|
||||
|
||||
while (fgets(line, sizeof(line), file) != NULL) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user