-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
61 lines (47 loc) · 1.84 KB
/
Copy pathmain.c
File metadata and controls
61 lines (47 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// --- main.c ---
#include "trie_sparse.h" // Your optimized sparse trie implementation
#include <stdio.h>
#include <string.h>
// Assume extract_indicator_from_log() is defined and working
void process_logs_and_check(TrieNode *root, const char *log_filepath) {
FILE *f = fopen(log_filepath, "r");
if (!f) {
perror("Error opening log file");
return;
}
char line[4096];
int line_num = 0;
printf("\n--- Starting Log Stream Processing ---\n");
while (fgets(line, sizeof(line), f) != NULL) {
line_num++;
// 1. Extract the URI path
char *indicator = extract_indicator_from_log(line);
if (indicator) {
// 2. Perform the high-speed Sparse Trie Lookup
TiResult result = ti_lookup_indicator_sparse(root, indicator);
if (result == MATCH_FOUND) {
// 3. ALERT! Commercial value achieved.
printf("!!! ALERT (Line %d): MATCH FOUND for URI: %s\n", line_num, indicator);
} else {
// For demonstration, show non-matches too
// printf("INFO (Line %d): No match for %s\n", line_num, indicator);
}
free(indicator); // Cleanup memory allocated during extraction
}
}
fclose(f);
}
int main(int argc, char *argv[]) {
// 1. Initialize Trie Root
TrieNode *root = create_sparse_trie_node();
// 2. Load TI Feed (Build the Trie)
if (ti_load_feed(root, "ti_feed.txt") != 0) {
return 1;
}
printf("Trie built successfully from ti_feed.txt.\n");
// 3. Process the Log Stream
process_logs_and_check(root, "access.log");
// 4. Cleanup
// free_trie(root); // Remember to implement and call your recursive free function!
return 0;
}