@@ -29,26 +29,34 @@ struct OutputHandler {
29
29
void process_cmdline_options (int argc , char * argv []);
30
30
noreturn void print_help (bool error , char * program_name );
31
31
void proxallium_main (void );
32
+ bool proxallium_gui_main (void );
33
+ void proxallium_cleanup (void );
34
+ void proxallium_process_line (char * line );
32
35
char * proxallium_gen_torrc ();
33
36
bool tor_start (void );
34
37
bool handler_bootstrap (char * line );
35
38
bool handler_warnings_and_errors (char * line );
36
39
37
40
struct TorInstance * tor_instance ;
38
41
42
+ // Output handlers
43
+ struct OutputHandler handlers [] = {
44
+ {handler_bootstrap , false},
45
+ {handler_warnings_and_errors , false}
46
+ };
47
+ size_t handlers_num = sizeof handlers / sizeof (struct OutputHandler );
48
+
39
49
int main (int argc , char * argv []) {
40
50
// Process command-line arguments
41
51
process_cmdline_options (argc , argv );
42
52
43
-
44
53
// Start Tor
45
54
tor_start ();
46
55
47
56
// Handle main loop
48
57
proxallium_main ();
49
58
50
59
// Clean up and exit
51
- allium_clean (tor_instance );
52
60
free (tor_instance );
53
61
return EXIT_SUCCESS ;
54
62
}
@@ -105,22 +113,24 @@ void noreturn print_help(bool error, char *program_name) {
105
113
}
106
114
107
115
void proxallium_main () {
108
- // Read output and call handlers
109
- struct OutputHandler handlers [] = {
110
- {handler_bootstrap , false},
111
- {handler_warnings_and_errors , false}
112
- };
113
- size_t handlers_num = sizeof handlers / sizeof (struct OutputHandler );
114
-
115
116
// Main event loop
116
- char * output ;
117
- while (output = allium_read_stdout_line (tor_instance )) {
118
- for (int handler = 0 ; handler < handlers_num ; handler ++ ) {
119
- if (!handlers [handler ].finished )
120
- handlers [handler ].finished = handlers [handler ].function (output );
121
- }
117
+ char * line ;
118
+ while (line = allium_read_stdout_line (tor_instance )) {
119
+ proxallium_process_line (line );
122
120
}
121
+ proxallium_cleanup ();
122
+ }
123
+
124
+ void proxallium_cleanup () {
123
125
log_output ("\nFinished reading Tor's output! Tor exited with exit code %i." , allium_get_exit_code (tor_instance ));
126
+ allium_clean (tor_instance );
127
+ }
128
+
129
+ void proxallium_process_line (char * line ) {
130
+ for (int handler = 0 ; handler < handlers_num ; handler ++ ) {
131
+ if (!handlers [handler ].finished )
132
+ handlers [handler ].finished = handlers [handler ].function (line );
133
+ }
124
134
}
125
135
126
136
char * proxallium_gen_torrc () {
0 commit comments