This commit is contained in:
overcuriousity 2025-06-22 17:09:53 +02:00
parent b9576101ce
commit 48dcb7155e
2 changed files with 37 additions and 20 deletions

BIN
bin/main

Binary file not shown.

View File

@ -17,6 +17,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>
#include <regex.h>
#define BUF 1024
#define DEBUG true
@ -42,14 +43,14 @@ struct errorLogEntry_t {
// https://nginx.org/en/docs/http/ngx_http_log_module.html
struct access_log_entry_t {
char remote_addr;
char remote_user;
char *remote_addr;
char *remote_user;
struct datetime_t time_local;
char request;
char *request;
unsigned int status;
unsigned int body_bytes_sent;
char http_referer;
char http_user_agent;
char *http_referer;
char *http_user_agent;
};
void debugmsg(char *msg) {
@ -65,11 +66,17 @@ int checkparams(int *argc, char *argv[]) {
};
};
struct errorLogEntry_t parseLogline(char *logLine) {
struct errorLogEntry_t logEntry;
struct access_log_entry_t parseLogline(char *accessLogLine) {
struct access_log_entry_t logEntry;
logEntry.remote_addr = parse_remote_address(accessLogLine);
return logEntry;
};
char parse_remote_address(char *accessLogLine) {
char *remote_adress[18];
regcomp
}
uint32_t my_strlen(char *s) {
uint32_t counter = 0;
while (s[counter] != '\0') {
@ -88,7 +95,7 @@ int main(int argc, char *argv[]) {
i++;
}
checkparams(&argc, argv);
char *filepath = argv[1];
const char *filepath = argv[1];
FILE *fp = fopen(filepath, "r");
if(fp == NULL) {
perror("fopen");
@ -97,23 +104,33 @@ int main(int argc, char *argv[]) {
}else{
char msg[BUF];
fseek(fp, 0L, SEEK_END);
long filesize = ftell(fp);
sprintf(msg, "Datei %s geöffnet. Speicheradresse %p, Speichergröße %ld\n", filepath, &fp, filesize);
int filesize = ftell(fp);
sprintf(msg, "Datei %s geöffnet. Speicheradresse %p, Speichergröße %d Byte\n", filepath, &fp, filesize);
debugmsg(msg);
//char filebuffer[BUF];
struct access_log_entry_t *access_log_storage = malloc(sizeof(struct access_log_entry_t)*BUF)
if(access_log_storage==NULL){
perror("Fuck\n")
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");
return -1;
};
rewind(fp);
while (fgets(filebuffer, BUF, fp)){
debugmsg("entered loop\n");
fputs(filebuffer, stdout);
debugmsg("endloop");
//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, filesize, fp); counter++) {
//debugmsg("entered loop");
char outputline[BUF];
sprintf(outputline, "LINE %d: %s", counter+1, access_log_buffer);
fputs(outputline, stdout);
//debugmsg("endloop");
}
free(access_log_storage);
access_log_storage = NULL;
free(access_log_buffer);
free(access_log_table);
//access_log_buffer = NULL;
access_log_table = NULL;
}
debugmsg("END OF PROGRAM");
return 0;