This commit is contained in:
overcuriousity 2025-07-05 14:02:25 +02:00
parent 287fed9795
commit 98e6aa4d51
2 changed files with 38 additions and 28 deletions

BIN
bin/main

Binary file not shown.

View File

@ -18,6 +18,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
#include <stdbool.h>
#include <stdint.h>
#include <regex.h>
#include <stdarg.h>
#define BUF 1024
#define DEBUG true
@ -53,9 +54,19 @@ struct access_log_entry_t {
char *http_user_agent;
};
void debugmsg(char *msg) {
struct access_log_table_t {
struct *access_log_entry_t;
}
void debugmsg(const char *format, ...) {
if(DEBUG == true) {
printf("DEBUG: %s\n", msg);
va_list args;
va_start(args, format);
printf("DEBUG: ");
vprintf(format, args);
printf("\n");
va_end(args);
}
}
@ -66,7 +77,7 @@ int checkparams(int *argc, char *argv[]) {
};
};
struct access_log_entry_t parseLogline(char *accessLogLine) {
struct access_log_entry_t parse_access_log(char *accessLogLine) {
struct access_log_entry_t logEntry;
//logEntry.remote_addr = parse_remote_address(accessLogLine);
return logEntry;
@ -85,53 +96,52 @@ unsigned int count_lines(FILE *filepointer) {
lines += 1;
}
}
char msg[BUF];
sprintf(msg, "Detected %d Lines in filestream\n", lines);
debugmsg(msg);
debugmsg( "Detected %d Lines in filestream\n", lines);
return lines;
}
unsigned int calculate_filesize(FILE *filepointer){
rewind(filepointer);
fseek(filepointer, 0L, SEEK_END);
int filesize = ftell(filepointer);
return filesize;
}
int main(int argc, char *argv[]) {
debugmsg("START OF PROGRAM");
int i = 0;
while(i<argc){
char msg[BUF];
sprintf(msg,"Argument %d: %s, Speicheradresse: %p\n", i, argv[i], &argv[i]);
debugmsg(msg);
debugmsg("Argument %d: %s, Speicheradresse: %p\n", i, argv[i], &argv[i]);
i++;
}
checkparams(&argc, argv);
const char *filepath = argv[1];
FILE *fp = fopen(filepath, "r");
FILE *fp = fopen(filepath, "r"); //malloc wird innerhalb fopen durchgeführt
if(fp == NULL) {
perror("fopen");
printf("Scheisse gelaufen mit der Datei...\n");
printf("Datei konnte nicht geöffnet werden.\n");
return -1;
}else{
char msg[BUF];
fseek(fp, 0L, SEEK_END);
int filesize = ftell(fp);
sprintf(msg, "Datei %s geöffnet. Speicheradresse %p, Speichergröße %d Byte\n", filepath, &fp, filesize);
debugmsg(msg);
count_lines(fp);
char *access_log_buffer = malloc(BUF);
struct access_log_entry_t *access_log_table = malloc(sizeof(struct access_log_entry_t)*BUF);
if(access_log_buffer==NULL){
perror("Fuck\n");
unsigned int filesize = calculate_filesize(fp);
unsigned int linecount = count_lines(fp);
debugmsg("Datei %s geöffnet. Speicheradresse %p, Speichergröße %d Byte\n", filepath, &fp, filesize);
struct access_log_entry_t *access_logentry = malloc(sizeof(struct access_log_entry_t)*BUF);
debugmsg("Speicher erfolgreich für access_logentry alloziert: %d Byte\n", sizeof(access_logentry));
struct access_log_table_t *access_log_table = malloc(sizeof(access_logentry_t)*linecount);
debugmsg("Speicher erfolgreich für _log_tablaccess_log_table alloziert: %d Byte\n", sizeof(access_log_table));
if(access_log_table==NULL){
return -1;
};
rewind(fp);
for (int counter = 0; counter < 10 && fgets(access_log_buffer, filesize, fp); counter++) {
//debugmsg("entered loop");
for (int counter = 0; counter < 10 && fgets(access_log_table, filesize, fp); counter++) {
char outputline[BUF];
sprintf(outputline, "LINE %d: %s", counter+1, access_log_buffer);
sprintf(outputline, "LINE %d: %s", counter+1, access_log_table);
fputs(outputline, stdout);
//debugmsg("endloop");
}
free(access_log_buffer);
free(access_log_table);
//access_log_buffer = NULL;
free(access_logentry);
access_log_table = NULL;
access_logentry = NULL;
}
debugmsg("END OF PROGRAM");
return 0;