@@ -54,7 +54,7 @@ int SendFile(int write_fd, FILE *read_fd) {
54
54
if ((n = fread (buffer , sizeof (char ), SEND_BUFFER_SIZE , read_fd )) == -1 ) {
55
55
return -1 ;
56
56
}
57
- // printf ("send_buffer: |%s| %zu %zu\n", buffer, n, strlen(buffer));
57
+ // log_ut ("send_buffer: |%s| %zu %zu\n", buffer, n, strlen(buffer));
58
58
if (send (write_fd , buffer , (size_t ) n , 0 ) == -1 ) {
59
59
return -2 ;
60
60
}
@@ -67,7 +67,7 @@ int SendFile(int write_fd, FILE *read_fd) {
67
67
FILE * sendFileToClient (int fd ) {
68
68
//FILE *fp = fopen(pathFilename, "rb");
69
69
FILE * fp = fdopen (fd , "rb" );
70
- printf ("sono qui" );
70
+ log_ut ("sono qui" );
71
71
if (fp == NULL ) {
72
72
fprintf (stderr , "Error opening file --> %s" , strerror (errno ));
73
73
exit (EXIT_FAILURE );
@@ -167,7 +167,7 @@ void clean_request(char *path, char *buf, struct ThreadArgs *args) {
167
167
* Wrapper for protocol.resolve_selector, control errors and clean the request
168
168
* */
169
169
void socket_resolve_selector (struct ThreadArgs * args , char * buf , char * * path ) {
170
- //printf ("Selector string: %s\n", buf);
170
+ //log_ut ("Selector string: %s\n", buf);
171
171
//char *path;
172
172
int ret_resolve_relector = resolve_selector (args -> configs .root_dir , path , buf );
173
173
if (ret_resolve_relector == NO_FREE ) {
@@ -212,7 +212,7 @@ int socket_read_request(struct ThreadArgs *args, char **buf) {
212
212
}
213
213
ptr += got_bytes ;
214
214
if (ptr >= BUFFER_SIZE ) {
215
- printf ("%s %d\n" , "effettuo il drain" , ptr );
215
+ log_ut ("%s %d\n" , "effettuo il drain" , ptr );
216
216
217
217
// DOS_PROTECTION is a switcher used in socket.c, when it is true we close the connection immediately without read the whole message, else we read the entire message and we response with error.
218
218
if (DOS_PROTECTION ) clean_request (NULL , * buf , args );
@@ -247,7 +247,7 @@ void socket_read_request2(struct ThreadArgs *args, char **buf) {
247
247
(* buf )[ptr ] = 0 ; // Terminate string
248
248
}
249
249
250
- // printf ("socket/socket_read_request %d %d |%s|\n", (*buf)[got_bytes - 1], (*buf)[got_bytes - 2], *buf);
250
+ // log_ut ("socket/socket_read_request %d %d |%s|\n", (*buf)[got_bytes - 1], (*buf)[got_bytes - 2], *buf);
251
251
252
252
for (int i = 2 ; 0 <= i ; i -- ) {
253
253
if (0 != got_bytes && ((* buf )[got_bytes - i ] == '\r' || (* buf )[got_bytes - i ] == '\n' )) {
@@ -258,7 +258,7 @@ void socket_read_request2(struct ThreadArgs *args, char **buf) {
258
258
259
259
socket_drain_tcp (args -> fd );
260
260
261
- printf ("socket/socket_read_request %ld %ld |%s|\n" , got_bytes , strlen (* buf ), * buf );
261
+ log_ut ("socket/socket_read_request %ld %ld |%s|\n" , got_bytes , strlen (* buf ), * buf );
262
262
}
263
263
264
264
@@ -272,7 +272,7 @@ int socket_drain_tcp(int fd_client) {
272
272
if (errno == EINTR ) {
273
273
continue ;
274
274
}
275
- printf ("%d \t %s\n" , drain_recv , "generic error" );
275
+ log_ut ("%d \t %s\n" , drain_recv , "generic error" );
276
276
return -1 ;
277
277
} else if (drain_recv == 0 ) {
278
278
break ;
@@ -294,7 +294,7 @@ int socket_drain_tcp2(int fd_client) {
294
294
295
295
if (drain_recv == EAGAIN ) {
296
296
} else {
297
- printf ("%d \t %s\n" , drain_recv , "gemneric error" );
297
+ log_ut ("%d \t %s\n" , drain_recv , "gemneric error" );
298
298
}
299
299
return -1 ;
300
300
}
@@ -303,7 +303,7 @@ int socket_drain_tcp2(int fd_client) {
303
303
304
304
int socket_send_message (int fd , char * message_string ) {
305
305
306
- // printf ("socket_send_message: %d, %s", fd, message_string);
306
+ // log_ut ("socket_send_message: %d, %s", fd, message_string);
307
307
int ret = send (fd , message_string , sizeof (char ) * strlen (message_string ), 0 );
308
308
if (0 > ret ) {
309
309
perror ("socket.c/socket_send_message: send failed" );
@@ -319,7 +319,7 @@ int socket_send_error_to_client(char *path, char *buf, struct ThreadArgs *args)
319
319
clean_request (path , buf , args );
320
320
} else {
321
321
322
- printf ("%s" , m );
322
+ log_ut ("%s" , m );
323
323
//send(args->fd, m, sizeof(char) * strlen(m), 0);
324
324
socket_send_message (args -> fd , m );
325
325
if (m != NULL ) {
@@ -336,7 +336,7 @@ void socket_manage_files(char *path, char *buf, struct ThreadArgs *args) {
336
336
if (FILES_NOT_EXIST == type_file || type_file == FILES_NOT_PERMITTED ) {
337
337
args -> type_Request = 1 ;
338
338
339
- printf ("socket_manage_files: Il file non esiste" );
339
+ log_ut ("socket_manage_files: Il file non esiste" );
340
340
341
341
socket_send_error_to_client (path , buf , args );
342
342
}
@@ -350,12 +350,12 @@ void socket_manage_files(char *path, char *buf, struct ThreadArgs *args) {
350
350
args -> type_Request = 1 ;
351
351
352
352
// it's a directory
353
- printf ("%s\n" , "Sending Directory" );
353
+ log_ut ("%s\n" , "Sending Directory" );
354
354
// TODO che for exit code of print_directory
355
355
print_directory (path , & socket_send_message , args -> fd , args -> configs .port_number );
356
356
} else if (FILES_IS_REG_FILE == type_file ) { // FILES_IS_FILE
357
357
// it's some kind of files
358
- printf ("%s\n" , "Sending File" );
358
+ log_ut ("%s\n" , "Sending File" );
359
359
360
360
args -> type_Request = 0 ;
361
361
@@ -394,7 +394,7 @@ void socket_manage_files(char *path, char *buf, struct ThreadArgs *args) {
394
394
395
395
396
396
397
- printf ("End createProcess" );
397
+ log_ut ("End createProcess" );
398
398
#endif
399
399
#if defined(__unix__ ) || defined(__APPLE__ )
400
400
@@ -405,7 +405,7 @@ void socket_manage_files(char *path, char *buf, struct ThreadArgs *args) {
405
405
memory_mapping_args .mode_concurrency = args -> configs .mode_concurrency ;
406
406
memory_mapping_args .fd = args -> fd ;
407
407
408
- printf ("going to linux_memory_mapping\n" );
408
+ log_ut ("going to linux_memory_mapping\n" );
409
409
int map_size = linux_memory_mapping ((void * ) & memory_mapping_args );
410
410
411
411
if (map_size < 0 ) {
@@ -430,11 +430,11 @@ void socket_manage_files(char *path, char *buf, struct ThreadArgs *args) {
430
430
int write_to_log (struct PipeArgs * data ) {
431
431
FILE * fp_log = fopen ("../gopher_log_file.txt" , "a" );
432
432
if (fp_log == NULL ) {
433
- printf ("%s" , "PERCHÉÉÉÉÉÉÉÉÉÉÉÉÉÉÉÉÉÉÉÉÉÉÉÉÉÉ" );
433
+ log_ut ("%s" , "PERCHÉÉÉÉÉÉÉÉÉÉÉÉÉÉÉÉÉÉÉÉÉÉÉÉÉÉ" );
434
434
return -1 ;
435
435
}
436
436
fprintf (fp_log , "%s" , "ciaoo" );
437
- printf ("sono dentro la funzionee" );
437
+ log_ut ("sono dentro la funzionee" );
438
438
fclose (fp_log );
439
439
440
440
return 0 ;
@@ -471,44 +471,44 @@ int vecchiafork(char *path, char *ip_client, int dim_file_to_send) {
471
471
close(fd_pipe[1]);
472
472
} else if (child == 0) {
473
473
close(fd_pipe[1]);
474
- printf ("---- child process wrote\n");
474
+ write_log ("---- child process wrote\n");
475
475
//FILE* fp_fileLog = fopen(LOG_PATH, "w");
476
476
int fd_log = open(LOG_PATH, O_WRONLY | O_APPEND);
477
477
//FILE* fp_filelog= fdopen(fd_log, "a");
478
- printf ("---- child process open\n");
478
+ write_log ("---- child process open\n");
479
479
if (fd_log == -1) {
480
480
//if (fp_fileLog == NULL){
481
- printf ("sono bloccato");
481
+ write_log ("sono bloccato");
482
482
exit(-1);
483
483
}
484
484
//int n;
485
485
struct PipeArgs data;
486
486
487
487
//ssize_t nread = read(fd_pipe[0], &data, sizeof(data));
488
488
ssize_t nread = read(fd_pipe[0], &data, sizeof(data));
489
- printf ("%zu", nread);
489
+ write_log ("%zu", nread);
490
490
491
491
492
- printf ("%zu", nread);
492
+ write_log ("%zu", nread);
493
493
494
- printf ("---- child process read\n");
494
+ write_log ("---- child process read\n");
495
495
496
496
497
- //printf ("\n sono figlio :-> %s\n", data->ip_client);
498
- printf ("FileName: %s\n", data.path);
499
- printf ("%d Byte \n", data.dim_file);
500
- printf ("IP Client: %s\n", data.ip_client);
497
+ //write_log ("\n sono figlio :-> %s\n", data->ip_client);
498
+ write_log ("FileName: %s\n", data.path);
499
+ write_log ("%d Byte \n", data.dim_file);
500
+ log_ut ("IP Client: %s\n", data.ip_client);
501
501
502
- dprintf (fd_log, "FileName: %s\t%d Byte \t IP Client: %s\n", data.path, data.dim_file,
502
+ dwrite_log (fd_log, "FileName: %s\t%d Byte \t IP Client: %s\n", data.path, data.dim_file,
503
503
data.ip_client);
504
- //int err = fprintf (fp_filelog, "FileName: %s\t%d Byte \t IP Client: %s\n", data->path, data->dim_file, data->ip_client);
505
- perror("dprintf ");
504
+ //int err = fwrite_log (fp_filelog, "FileName: %s\t%d Byte \t IP Client: %s\n", data->path, data->dim_file, data->ip_client);
505
+ perror("dwrite_log ");
506
506
//write(fd_log, "cia", sizeof("cia"));
507
507
508
- //printf ("SONO N %d \n", n);
508
+ //write_log ("SONO N %d \n", n);
509
509
close(fd_pipe[0]);
510
510
511
- printf ("---- child process close\n");
511
+ write_log ("---- child process close\n");
512
512
exit(0);
513
513
}
514
514
return 0;
0 commit comments