Merge remote-tracking branch 'refs/remotes/origin/main'
This commit is contained in:
commit
3878a5fb80
87
src/main.c
87
src/main.c
@ -18,6 +18,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <regex.h>
|
#include <regex.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
#define BUF 1024
|
#define BUF 1024
|
||||||
#define DEBUG true
|
#define DEBUG true
|
||||||
@ -53,9 +54,19 @@ struct access_log_entry_t {
|
|||||||
char *http_user_agent;
|
char *http_user_agent;
|
||||||
};
|
};
|
||||||
|
|
||||||
void debugmsg(char *msg) {
|
struct access_log_table_t {
|
||||||
if(DEBUG==true){
|
struct *access_log_entry_t;
|
||||||
printf("DEBUG: %s\n", msg);
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void debugmsg(const char *format, ...) {
|
||||||
|
if(DEBUG == true) {
|
||||||
|
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;
|
struct access_log_entry_t logEntry;
|
||||||
// logEntry.remote_addr = parse_remote_address(accessLogLine);
|
// //logEntry.remote_addr = parse_remote_address(accessLogLine);
|
||||||
return logEntry;
|
return logEntry;
|
||||||
};
|
};
|
||||||
|
|
||||||
//char* parse_remote_address(char *accessLogLine) {
|
//char* parse_remote_address(char *accessLogLine) {
|
||||||
// char *remote_adress[18];
|
// return 1;
|
||||||
// regcomp
|
|
||||||
//}
|
//}
|
||||||
|
|
||||||
uint32_t my_strlen(char *s) {
|
unsigned int count_lines(FILE *filepointer) {
|
||||||
uint32_t counter = 0;
|
rewind(filepointer);
|
||||||
while (s[counter] != '\0') {
|
unsigned int lines = 0;
|
||||||
counter++;
|
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[]) {
|
int main(int argc, char *argv[]) {
|
||||||
debugmsg("START OF PROGRAM");
|
debugmsg("START OF PROGRAM");
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while(i<argc){
|
while(i<argc){
|
||||||
char msg[BUF];
|
debugmsg("Argument %d: %s, Speicheradresse: %p\n", i, argv[i], &argv[i]);
|
||||||
sprintf(msg,"Argument %d: %s, Speicheradresse: %p\n", i, argv[i], &argv[i]);
|
|
||||||
debugmsg(msg);
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
checkparams(&argc, argv);
|
checkparams(&argc, argv);
|
||||||
const char *filepath = argv[1];
|
const char *filepath = argv[1];
|
||||||
FILE *fp = fopen(filepath, "r");
|
FILE *fp = fopen(filepath, "r"); //malloc wird innerhalb fopen durchgeführt
|
||||||
if(fp == NULL) {
|
if(fp == NULL) {
|
||||||
perror("fopen");
|
perror("fopen");
|
||||||
printf("Scheisse gelaufen mit der Datei...\n");
|
printf("Datei konnte nicht geöffnet werden.\n");
|
||||||
return -1;
|
return -1;
|
||||||
}else{
|
}else{
|
||||||
char msg[BUF];
|
unsigned int filesize = calculate_filesize(fp);
|
||||||
fseek(fp, 0L, SEEK_END);
|
unsigned int linecount = count_lines(fp);
|
||||||
int filesize = ftell(fp);
|
debugmsg("Datei %s geöffnet. Speicheradresse %p, Speichergröße %d Byte\n", filepath, &fp, filesize);
|
||||||
sprintf(msg, "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(msg);
|
debugmsg("Speicher erfolgreich für access_logentry alloziert: %d Byte\n", sizeof(access_logentry));
|
||||||
char *access_log_buffer = malloc(BUF);
|
struct access_log_table_t *access_log_table = malloc(sizeof(access_logentry_t)*linecount);
|
||||||
struct access_log_entry_t *access_log_table = malloc(sizeof(struct access_log_entry_t)*BUF);
|
debugmsg("Speicher erfolgreich für _log_tablaccess_log_table alloziert: %d Byte\n", sizeof(access_log_table));
|
||||||
if(access_log_buffer==NULL){
|
if(access_log_table==NULL){
|
||||||
perror("Fuck\n");
|
|
||||||
return -1;
|
return -1;
|
||||||
};
|
};
|
||||||
rewind(fp);
|
rewind(fp);
|
||||||
//while (fgets(access_log_buffer, filesize, fp)){
|
for (int counter = 0; counter < 10 && fgets(access_log_table, BUF, fp); counter++) {
|
||||||
// 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");
|
|
||||||
char outputline[BUF];
|
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);
|
fputs(outputline, stdout);
|
||||||
//debugmsg("endloop");
|
|
||||||
}
|
}
|
||||||
free(access_log_buffer);
|
|
||||||
free(access_log_table);
|
free(access_log_table);
|
||||||
//access_log_buffer = NULL;
|
free(access_logentry);
|
||||||
access_log_table = NULL;
|
access_log_table = NULL;
|
||||||
|
access_logentry = NULL;
|
||||||
}
|
}
|
||||||
debugmsg("END OF PROGRAM");
|
debugmsg("END OF PROGRAM");
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user