]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/ntp/libntp/log.c
This commit was generated by cvs2svn to compensate for changes in r147013,
[FreeBSD/FreeBSD.git] / contrib / ntp / libntp / log.c
1 /* Microsoft Developer Support Copyright (c) 1993 Microsoft Corporation. */
2
3 /* Skip asynch rpc inclusion */
4 #ifndef __RPCASYNC_H__
5 #define __RPCASYNC_H__
6 #endif
7
8 #include <windows.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12
13 #include "messages.h"
14 #include "log.h"
15
16 #define PERR(bSuccess, api) {if(!(bSuccess)) printf("%s: Error %d from %s \
17     on line %d\n", __FILE__, GetLastError(), api, __LINE__);}
18
19
20 /*********************************************************************
21 * FUNCTION: addSourceToRegistry(LPSTR pszAppname, LPSTR pszMsgDLL)   *
22 *                                                                    *
23 * PURPOSE: Add a source name key, message DLL name value, and        *
24 *          message type supported value to the registry              *
25 *                                                                    *
26 * INPUT: source name, path of message DLL                            *
27 *                                                                    *
28 * RETURNS: none                                                      *
29 *********************************************************************/
30
31 void addSourceToRegistry(LPSTR pszAppname, LPSTR pszMsgDLL)
32 {
33   HKEY hk;                      /* registry key handle */
34   DWORD dwData;
35   BOOL bSuccess;
36   char   regarray[200];
37   char *lpregarray = regarray;
38
39   /* When an application uses the RegisterEventSource or OpenEventLog
40      function to get a handle of an event log, the event loggging service
41      searches for the specified source name in the registry. You can add a
42      new source name to the registry by opening a new registry subkey
43      under the Application key and adding registry values to the new
44      subkey. */
45
46   strcpy(lpregarray, "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\");
47   strcat(lpregarray, pszAppname);
48
49   /* Create a new key for our application */
50   bSuccess = RegCreateKey(HKEY_LOCAL_MACHINE,lpregarray, &hk);
51   PERR(bSuccess == ERROR_SUCCESS, "RegCreateKey");
52
53   /* Add the Event-ID message-file name to the subkey. */
54   bSuccess = RegSetValueEx(hk,  /* subkey handle         */
55       "EventMessageFile",       /* value name            */
56       0,                        /* must be zero          */
57       REG_EXPAND_SZ,            /* value type            */
58       (LPBYTE) pszMsgDLL,       /* address of value data */
59       strlen(pszMsgDLL) + 1);   /* length of value data  */
60   PERR(bSuccess == ERROR_SUCCESS, "RegSetValueEx");
61
62   /* Set the supported types flags and addit to the subkey. */
63   dwData = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE |
64       EVENTLOG_INFORMATION_TYPE;
65   bSuccess = RegSetValueEx(hk,  /* subkey handle                */
66       "TypesSupported",         /* value name                   */
67       0,                        /* must be zero                 */
68       REG_DWORD,                /* value type                   */
69       (LPBYTE) &dwData,         /* address of value data        */
70       sizeof(DWORD));           /* length of value data         */
71   PERR(bSuccess == ERROR_SUCCESS, "RegSetValueEx");
72   RegCloseKey(hk);
73   return;
74 }
75
76 /*********************************************************************
77 * FUNCTION: reportAnEvent(DWORD dwIdEvent, WORD cStrings,            *
78 *                         LPTSTR *ppszStrings);                      *
79 *                                                                    *
80 * PURPOSE: add the event to the event log                            *
81 *                                                                    *
82 * INPUT: the event ID to report in the log, the number of insert     *
83 *        strings, and an array of null-terminated insert strings     *
84 *                                                                    *
85 * RETURNS: none                                                      *
86 *********************************************************************/
87
88 void reportAnIEvent(DWORD dwIdEvent, WORD cStrings, LPTSTR *pszStrings)
89 {
90   HANDLE hAppLog;
91   BOOL bSuccess;
92
93   /* Get a handle to the Application event log */
94   hAppLog = RegisterEventSource(NULL,   /* use local machine      */
95       "NTP");                   /* source name                 */
96   PERR(hAppLog, "RegisterEventSource");
97
98   /* Now report the event, which will add this event to the event log */
99   bSuccess = ReportEvent(hAppLog,       /* event-log handle            */
100       EVENTLOG_INFORMATION_TYPE,      /* event type                  */
101       0,                        /* category zero               */
102       dwIdEvent,                /* event ID                    */
103       NULL,                     /* no user SID                 */
104       cStrings,                 /* number of substitution strings     */
105       0,                        /* no binary data              */
106       pszStrings,               /* string array                */
107       NULL);                    /* address of data             */
108   PERR(bSuccess, "ReportEvent");
109   DeregisterEventSource(hAppLog);
110   return;
111 }
112
113 void reportAnWEvent(DWORD dwIdEvent, WORD cStrings, LPTSTR *pszStrings)
114 {
115   HANDLE hAppLog;
116   BOOL bSuccess;
117
118   /* Get a handle to the Application event log */
119   hAppLog = RegisterEventSource(NULL,   /* use local machine      */
120       "NTP");                   /* source name                 */
121   PERR(hAppLog, "RegisterEventSource");
122
123   /* Now report the event, which will add this event to the event log */
124   bSuccess = ReportEvent(hAppLog,       /* event-log handle            */
125       EVENTLOG_WARNING_TYPE,      /* event type                  */
126       0,                        /* category zero               */
127       dwIdEvent,                /* event ID                    */
128       NULL,                     /* no user SID                 */
129       cStrings,                 /* number of substitution strings     */
130       0,                        /* no binary data              */
131       pszStrings,               /* string array                */
132       NULL);                    /* address of data             */
133   PERR(bSuccess, "ReportEvent");
134   DeregisterEventSource(hAppLog);
135   return;
136 }
137
138 void reportAnEEvent(DWORD dwIdEvent, WORD cStrings, LPTSTR *pszStrings)
139 {
140   HANDLE hAppLog;
141   BOOL bSuccess;
142
143   /* Get a handle to the Application event log */
144   hAppLog = RegisterEventSource(NULL,   /* use local machine      */
145       "NTP");                   /* source name                 */
146   PERR(hAppLog, "RegisterEventSource");
147
148   /* Now report the event, which will add this event to the event log */
149   bSuccess = ReportEvent(hAppLog,       /* event-log handle            */
150       EVENTLOG_ERROR_TYPE,      /* event type                  */
151       0,                        /* category zero               */
152       dwIdEvent,                /* event ID                    */
153       NULL,                     /* no user SID                 */
154       cStrings,                 /* number of substitution strings     */
155       0,                        /* no binary data              */
156       pszStrings,               /* string array                */
157       NULL);                    /* address of data             */
158   PERR(bSuccess, "ReportEvent");
159   DeregisterEventSource(hAppLog);
160   return;
161 }