Merge remote-tracking branch 'refs/remotes/origin/main'

This commit is contained in:
Mario Stöckl 2025-07-05 21:34:14 +02:00
commit 3878a5fb80

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,71 +77,71 @@ 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);
// //logEntry.remote_addr = parse_remote_address(accessLogLine);
return logEntry;
};
//char* parse_remote_address(char *accessLogLine) {
// char *remote_adress[18];
// regcomp
// return 1;
//}
uint32_t my_strlen(char *s) {
uint32_t counter = 0;
while (s[counter] != '\0') {
counter++;
unsigned int count_lines(FILE *filepointer) {
rewind(filepointer);
unsigned int lines = 0;
char c;
for(c=getc(filepointer); c != EOF; c = getc(filepointer)) {
if(c=='\n'){
lines += 1;
}
return counter;
}
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);
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);
//while (fgets(access_log_buffer, filesize, fp)){
// debugmsg("entered loop\n");
// sprintf(outputline, "LINE %d: %s", counter+1, access_log_buffer);
// fputs(outputline, stdout);
// debugmsg("endloop");
//}
for (int counter = 0; counter < 10 && fgets(access_log_buffer, BUF, fp); counter++) {
//debugmsg("entered loop");
for (int counter = 0; counter < 10 && fgets(access_log_table, BUF, 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;