2 * Windows event log logging backend.
9 #include "smsd-event.h"
12 gboolean
eventlog_deregister(void)
18 "System\\CurrentControlSet\\Services\\EventLog\\Application\\GammuSMSD"
21 return (ret
== ERROR_SUCCESS
);
24 gboolean
eventlog_register(void)
30 SECURITY_DESCRIPTOR SD
;
31 SECURITY_ATTRIBUTES SA
;
33 char program_name
[MAX_PATH
];
35 if (GetModuleFileName(NULL
, program_name
, sizeof(program_name
)) == 0)
38 if (!InitializeSecurityDescriptor(&SD
, SECURITY_DESCRIPTOR_REVISION
)) {
42 if(!SetSecurityDescriptorDacl(&SD
, TRUE
, 0, FALSE
)) {
46 SA
.nLength
= sizeof(SA
);
47 SA
.lpSecurityDescriptor
= &SD
;
48 SA
.bInheritHandle
= FALSE
;
52 "System\\CurrentControlSet\\Services\\EventLog\\Application\\GammuSMSD",
55 REG_OPTION_NON_VOLATILE
,
61 if (ret
!= ERROR_SUCCESS
) {
62 fprintf(stderr
, "Failed to create registry key!\n");
75 if (ret
!= ERROR_SUCCESS
) {
76 fprintf(stderr
, "Failed to write CategoryCount to registry!\n");
82 "CategoryMessageFile",
86 strlen(program_name
) + 1);
88 if (ret
!= ERROR_SUCCESS
) {
89 fprintf(stderr
, "Failed to write CategoryMessageFile to registry!\n");
99 strlen(program_name
) + 1);
101 if (ret
!= ERROR_SUCCESS
) {
102 fprintf(stderr
, "Failed to write EventMessageFile to registry!\n");
108 "ParameterMessageFile",
111 (BYTE
*)program_name
,
112 strlen(program_name
) + 1);
114 if (ret
!= ERROR_SUCCESS
) {
115 fprintf(stderr
, "Failed to write ParameterMessageFile to registry!\n");
119 data
= EVENTLOG_ERROR_TYPE
| EVENTLOG_INFORMATION_TYPE
| EVENTLOG_WARNING_TYPE
;
128 if (ret
!= ERROR_SUCCESS
) {
129 fprintf(stderr
, "Failed to write TypesSupported to registry!\n");
138 void *eventlog_init(void)
141 handle
= RegisterEventSource(NULL
, "gammu-smsd");
142 if (handle
== NULL
) {
143 fprintf(stderr
, "Error opening event log!\n");
145 return (void *)handle
;
148 void eventlog_log(void *handle
, int level
, const char *message
)
150 LPCTSTR lpstrings
[1];
151 WORD evtype
= EVENTLOG_ERROR_TYPE
;
157 evtype
= EVENTLOG_ERROR_TYPE
;
158 eventid
= EVENT_MSG_ERROR
;
159 eventcat
= EVENT_CAT_SMSD
;
162 evtype
= EVENTLOG_SUCCESS
;
163 eventid
= EVENT_MSG_INFO
;
164 eventcat
= EVENT_CAT_SMSD
;
167 eventid
= EVENT_MSG_NOTICE
;
168 evtype
= EVENTLOG_INFORMATION_TYPE
;
169 eventcat
= EVENT_CAT_SMSD
;
172 eventid
= EVENT_MSG_SQL
;
173 evtype
= EVENTLOG_INFORMATION_TYPE
;
174 eventcat
= EVENT_CAT_SQL
;
177 eventid
= EVENT_MSG_GAMMU
;
178 evtype
= EVENTLOG_INFORMATION_TYPE
;
179 eventcat
= EVENT_CAT_GAMMU
;
182 eventid
= EVENT_MSG_OTHER
;
183 evtype
= EVENTLOG_INFORMATION_TYPE
;
184 eventcat
= EVENT_CAT_SMSD
;
187 lpstrings
[0] = message
;
189 * @todo: 1024 is probably wrong, we should use mc to get proper
192 ReportEvent(handle
, evtype
, eventcat
, eventid
, NULL
, 1, 0,
196 void eventlog_close(void *handle
)
198 DeregisterEventSource(handle
);
201 /* How should editor hadle tabs in this file? Add editor commands here.
202 * vim: noexpandtab sw=8 ts=8 sts=8: