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