-
Notifications
You must be signed in to change notification settings - Fork 3
/
log.c
91 lines (83 loc) · 2.22 KB
/
log.c
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
ClamAV Live Scan
https://github.com/madcoder42/clamAVLiveScan
Copyright 2017 madcoder42
This file is part of ClamAV Live Scan.
ClamAV Live Scan is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ClamAV Live Scan is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ClamAV Live Scan. If not, see <http://www.gnu.org/licenses/>.
*/
#include "common.h"
void addToLogFile(char *str1, char *str2, char *str3)
{
time_t t;
struct tm *tt;
char d[24];
char *tmp = NULL;
int len = 0;
FILE *fp = NULL;
// Check Parameter
if (PARAMS.liveLogEnable == 0 && WIN.hLivelogs == NULL) {
return;
}
// Get String Length
if (str1 != NULL) {
len += strlen(str1);
if (str2 != NULL) {
len += strlen(str2);
if (str3 != NULL) {
len += strlen(str3);
}
}
}
if (len == 0) {
return;
}
// Get Current Date/Time
if ((t = time(NULL)) == -1) {
return;
}
if ((tt = localtime(&t)) == NULL) {
return;
}
memset(d, 0, 24);
sprintf(d, "[%d-%02d-%02d %02d:%02d:%02d]", (tt->tm_year + 1900), (tt->tm_mon + 1), tt->tm_mday, tt->tm_hour, tt->tm_min, tt->tm_sec);
// Get Log Message
if ((tmp = (char *)calloc((len + 32), sizeof(char))) == NULL) {
return;
}
sprintf(tmp, "%s %s", d, str1);
if (str2 != NULL) {
strcat(tmp, str2);
if (str3 != NULL) {
strcat(tmp, str3);
}
}
// Lock
WaitForSingleObject(PARAMS.hMutex, INFINITE);
// Write To File
if (PARAMS.liveLogEnable == 1) {
if ((fp = (FILE *)fopen64(PARAMS.liveLogPath, "a")) != NULL) {
fprintf(fp, "%s\n", tmp);
fclose(fp);
}
}
// Watch Live Scan
if (WIN.hLivelogs != NULL) {
strcat(tmp, "\r\n");
addTextToEdit(WIN.hLivelogs, IDEDITLIVELOGSMSG, tmp);
}
// Unlock
ReleaseMutex(PARAMS.hMutex);
// Free
free(tmp);
return;
}