-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathloop.cpp
86 lines (69 loc) · 1.77 KB
/
loop.cpp
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
#include <stdio.h>
#include "main.h"
#include "eventlog.h"
int ascii2utf8(char * message, int level);
/* Main eventlog monitoring loop */
int MainLoop()
{
char * output = NULL;
int level;
int log;
/* Gather eventlog names */
if (RegistryGather())
return 1;
/* Open all eventlogs */
if (EventlogsOpen())
return 1;
unsigned int countflags = 0;
/* Loop while service is running */
while (ServiceIsRunning)
{
/* Process records */
for (log = 0; log < EventlogCount; log++)
{
while ((output = EventlogNext( log, &level)))
{
if (output != NULL)
{
countflags++;
if (ascii2utf8(output, level))
{
ServiceIsRunning = FALSE;
break;
}
if (countflags == 10) {
break;
}
}
}
}
printf("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
if (countflags == 10) {
break;
}
Sleep(5000);
}
EventlogsClose();
/* Success */
return 0;
}
// Send a message to the syslog server //
int ascii2utf8(char * message, int level)
{
char error_message[SYSLOG_DEF_SZ]; /*1024*/
WCHAR utf16_message[SYSLOG_DEF_SZ]; /*1024*/
char utf8_message[SYSLOG_DEF_SZ]; /*1024*/
// Write priority level //
_snprintf_s(error_message, sizeof(error_message), _TRUNCATE,
"<%d>%s",
level,
message
);
// convert from ansi/cp850 codepage (local system codepage) to utf8, widely used codepage on unix systems //
MultiByteToWideChar(CP_ACP, 0, error_message, -1, utf16_message, SYSLOG_DEF_SZ);
WideCharToMultiByte(CP_UTF8, 0, utf16_message, -1, utf8_message, SYSLOG_DEF_SZ, NULL, NULL);
printf("---->%s\n", utf8_message);
//print -- utf8_message
// Send result to syslog server //
return 0;
}