winevt_c 0.9.1 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,149 +1,149 @@
1
- #include <winevt_c.h>
2
-
3
- /* clang-format off */
4
- /*
5
- * Document-class: Winevt::EventLog::Bookmark
6
- *
7
- * Bookmark for querying/subscribing Windows EventLog progress.
8
- *
9
- * @example
10
- * require 'winevt'
11
- *
12
- * @query = Winevt::EventLog::Query.new("Application", "*[System[(Level <= 3) and TimeCreated[timediff(@SystemTime) <= 86400000]]]")
13
- * @bookmark = Winevt::EventLog::Bookmark.new
14
- * @query.each do |xml|
15
- * @bookmark.update(@query)
16
- * end
17
- *
18
- * puts @bookmark.render
19
- */
20
- /* clang-format pn */
21
-
22
- VALUE rb_cBookmark;
23
-
24
- static void bookmark_free(void* ptr);
25
-
26
- static const rb_data_type_t rb_winevt_bookmark_type = { "winevt/bookmark",
27
- {
28
- 0,
29
- bookmark_free,
30
- 0,
31
- },
32
- NULL,
33
- NULL,
34
- RUBY_TYPED_FREE_IMMEDIATELY };
35
-
36
- static void
37
- bookmark_free(void* ptr)
38
- {
39
- struct WinevtBookmark* winevtBookmark = (struct WinevtBookmark*)ptr;
40
- if (winevtBookmark->bookmark)
41
- EvtClose(winevtBookmark->bookmark);
42
-
43
- xfree(ptr);
44
- }
45
-
46
- static VALUE
47
- rb_winevt_bookmark_alloc(VALUE klass)
48
- {
49
- VALUE obj;
50
- struct WinevtBookmark* winevtBookmark;
51
- obj = TypedData_Make_Struct(
52
- klass, struct WinevtBookmark, &rb_winevt_bookmark_type, winevtBookmark);
53
- return obj;
54
- }
55
-
56
- /*
57
- * Initalize Bookmark class. Receive XML string or nil.
58
- *
59
- * @overload initailize(options={})
60
- * @option options [String] XML rendered Bookmark string.
61
- * @return [Bookmark]
62
- *
63
- */
64
- static VALUE
65
- rb_winevt_bookmark_initialize(int argc, VALUE* argv, VALUE self)
66
- {
67
- PWSTR bookmarkXml;
68
- VALUE wbookmarkXmlBuf;
69
- DWORD len;
70
- struct WinevtBookmark* winevtBookmark;
71
-
72
- TypedData_Get_Struct(
73
- self, struct WinevtBookmark, &rb_winevt_bookmark_type, winevtBookmark);
74
-
75
- if (argc == 0) {
76
- winevtBookmark->bookmark = EvtCreateBookmark(NULL);
77
- } else if (argc == 1) {
78
- VALUE rb_bookmarkXml;
79
- rb_scan_args(argc, argv, "10", &rb_bookmarkXml);
80
- Check_Type(rb_bookmarkXml, T_STRING);
81
-
82
- // bookmarkXml : To wide char
83
- len = MultiByteToWideChar(
84
- CP_UTF8, 0, RSTRING_PTR(rb_bookmarkXml), RSTRING_LEN(rb_bookmarkXml), NULL, 0);
85
- bookmarkXml = ALLOCV_N(WCHAR, wbookmarkXmlBuf, len + 1);
86
- MultiByteToWideChar(CP_UTF8,
87
- 0,
88
- RSTRING_PTR(rb_bookmarkXml),
89
- RSTRING_LEN(rb_bookmarkXml),
90
- bookmarkXml,
91
- len);
92
- bookmarkXml[len] = L'\0';
93
- winevtBookmark->bookmark = EvtCreateBookmark(bookmarkXml);
94
- ALLOCV_END(wbookmarkXmlBuf);
95
- }
96
-
97
- return Qnil;
98
- }
99
-
100
- /*
101
- * This method updates bookmark and returns Bookmark instance.
102
- *
103
- * @param event [Query]
104
- * @return [Bookmark]
105
- */
106
- static VALUE
107
- rb_winevt_bookmark_update(VALUE self, VALUE event)
108
- {
109
- struct WinevtQuery* winevtQuery;
110
- struct WinevtBookmark* winevtBookmark;
111
-
112
- winevtQuery = EventQuery(event);
113
-
114
- TypedData_Get_Struct(
115
- self, struct WinevtBookmark, &rb_winevt_bookmark_type, winevtBookmark);
116
-
117
- for (int i = 0; i < winevtQuery->count; i++) {
118
- if (!EvtUpdateBookmark(winevtBookmark->bookmark, winevtQuery->hEvents[i]))
119
- return Qfalse;
120
- }
121
- return Qtrue;
122
- }
123
-
124
- /*
125
- * This method renders bookmark class content.
126
- *
127
- * @return [String]
128
- */
129
- static VALUE
130
- rb_winevt_bookmark_render(VALUE self)
131
- {
132
- struct WinevtBookmark* winevtBookmark;
133
-
134
- TypedData_Get_Struct(
135
- self, struct WinevtBookmark, &rb_winevt_bookmark_type, winevtBookmark);
136
-
137
- return render_to_rb_str(winevtBookmark->bookmark, EvtRenderBookmark);
138
- }
139
-
140
- void
141
- Init_winevt_bookmark(VALUE rb_cEventLog)
142
- {
143
- rb_cBookmark = rb_define_class_under(rb_cEventLog, "Bookmark", rb_cObject);
144
-
145
- rb_define_alloc_func(rb_cBookmark, rb_winevt_bookmark_alloc);
146
- rb_define_method(rb_cBookmark, "initialize", rb_winevt_bookmark_initialize, -1);
147
- rb_define_method(rb_cBookmark, "update", rb_winevt_bookmark_update, 1);
148
- rb_define_method(rb_cBookmark, "render", rb_winevt_bookmark_render, 0);
149
- }
1
+ #include <winevt_c.h>
2
+
3
+ /* clang-format off */
4
+ /*
5
+ * Document-class: Winevt::EventLog::Bookmark
6
+ *
7
+ * Bookmark for querying/subscribing Windows EventLog progress.
8
+ *
9
+ * @example
10
+ * require 'winevt'
11
+ *
12
+ * @query = Winevt::EventLog::Query.new("Application", "*[System[(Level <= 3) and TimeCreated[timediff(@SystemTime) <= 86400000]]]")
13
+ * @bookmark = Winevt::EventLog::Bookmark.new
14
+ * @query.each do |xml|
15
+ * @bookmark.update(@query)
16
+ * end
17
+ *
18
+ * puts @bookmark.render
19
+ */
20
+ /* clang-format pn */
21
+
22
+ VALUE rb_cBookmark;
23
+
24
+ static void bookmark_free(void* ptr);
25
+
26
+ static const rb_data_type_t rb_winevt_bookmark_type = { "winevt/bookmark",
27
+ {
28
+ 0,
29
+ bookmark_free,
30
+ 0,
31
+ },
32
+ NULL,
33
+ NULL,
34
+ RUBY_TYPED_FREE_IMMEDIATELY };
35
+
36
+ static void
37
+ bookmark_free(void* ptr)
38
+ {
39
+ struct WinevtBookmark* winevtBookmark = (struct WinevtBookmark*)ptr;
40
+ if (winevtBookmark->bookmark)
41
+ EvtClose(winevtBookmark->bookmark);
42
+
43
+ xfree(ptr);
44
+ }
45
+
46
+ static VALUE
47
+ rb_winevt_bookmark_alloc(VALUE klass)
48
+ {
49
+ VALUE obj;
50
+ struct WinevtBookmark* winevtBookmark;
51
+ obj = TypedData_Make_Struct(
52
+ klass, struct WinevtBookmark, &rb_winevt_bookmark_type, winevtBookmark);
53
+ return obj;
54
+ }
55
+
56
+ /*
57
+ * Initalize Bookmark class. Receive XML string or nil.
58
+ *
59
+ * @overload initailize(options={})
60
+ * @option options [String] XML rendered Bookmark string.
61
+ * @return [Bookmark]
62
+ *
63
+ */
64
+ static VALUE
65
+ rb_winevt_bookmark_initialize(int argc, VALUE* argv, VALUE self)
66
+ {
67
+ PWSTR bookmarkXml;
68
+ VALUE wbookmarkXmlBuf;
69
+ DWORD len;
70
+ struct WinevtBookmark* winevtBookmark;
71
+
72
+ TypedData_Get_Struct(
73
+ self, struct WinevtBookmark, &rb_winevt_bookmark_type, winevtBookmark);
74
+
75
+ if (argc == 0) {
76
+ winevtBookmark->bookmark = EvtCreateBookmark(NULL);
77
+ } else if (argc == 1) {
78
+ VALUE rb_bookmarkXml;
79
+ rb_scan_args(argc, argv, "10", &rb_bookmarkXml);
80
+ Check_Type(rb_bookmarkXml, T_STRING);
81
+
82
+ // bookmarkXml : To wide char
83
+ len = MultiByteToWideChar(
84
+ CP_UTF8, 0, RSTRING_PTR(rb_bookmarkXml), RSTRING_LEN(rb_bookmarkXml), NULL, 0);
85
+ bookmarkXml = ALLOCV_N(WCHAR, wbookmarkXmlBuf, len + 1);
86
+ MultiByteToWideChar(CP_UTF8,
87
+ 0,
88
+ RSTRING_PTR(rb_bookmarkXml),
89
+ RSTRING_LEN(rb_bookmarkXml),
90
+ bookmarkXml,
91
+ len);
92
+ bookmarkXml[len] = L'\0';
93
+ winevtBookmark->bookmark = EvtCreateBookmark(bookmarkXml);
94
+ ALLOCV_END(wbookmarkXmlBuf);
95
+ }
96
+
97
+ return Qnil;
98
+ }
99
+
100
+ /*
101
+ * This method updates bookmark and returns Bookmark instance.
102
+ *
103
+ * @param event [Query]
104
+ * @return [Bookmark]
105
+ */
106
+ static VALUE
107
+ rb_winevt_bookmark_update(VALUE self, VALUE event)
108
+ {
109
+ struct WinevtQuery* winevtQuery;
110
+ struct WinevtBookmark* winevtBookmark;
111
+
112
+ winevtQuery = EventQuery(event);
113
+
114
+ TypedData_Get_Struct(
115
+ self, struct WinevtBookmark, &rb_winevt_bookmark_type, winevtBookmark);
116
+
117
+ for (int i = 0; i < winevtQuery->count; i++) {
118
+ if (!EvtUpdateBookmark(winevtBookmark->bookmark, winevtQuery->hEvents[i]))
119
+ return Qfalse;
120
+ }
121
+ return Qtrue;
122
+ }
123
+
124
+ /*
125
+ * This method renders bookmark class content.
126
+ *
127
+ * @return [String]
128
+ */
129
+ static VALUE
130
+ rb_winevt_bookmark_render(VALUE self)
131
+ {
132
+ struct WinevtBookmark* winevtBookmark;
133
+
134
+ TypedData_Get_Struct(
135
+ self, struct WinevtBookmark, &rb_winevt_bookmark_type, winevtBookmark);
136
+
137
+ return render_to_rb_str(winevtBookmark->bookmark, EvtRenderBookmark);
138
+ }
139
+
140
+ void
141
+ Init_winevt_bookmark(VALUE rb_cEventLog)
142
+ {
143
+ rb_cBookmark = rb_define_class_under(rb_cEventLog, "Bookmark", rb_cObject);
144
+
145
+ rb_define_alloc_func(rb_cBookmark, rb_winevt_bookmark_alloc);
146
+ rb_define_method(rb_cBookmark, "initialize", rb_winevt_bookmark_initialize, -1);
147
+ rb_define_method(rb_cBookmark, "update", rb_winevt_bookmark_update, 1);
148
+ rb_define_method(rb_cBookmark, "render", rb_winevt_bookmark_render, 0);
149
+ }
@@ -1,132 +1,133 @@
1
- #ifndef _WINEVT_C_H_
2
- #define _WINEVT_C_H_
3
-
4
- #include <ruby.h>
5
- #include <ruby/encoding.h>
6
-
7
- #ifdef __GNUC__
8
- #include <w32api.h>
9
- #define MINIMUM_WINDOWS_VERSION WindowsVista
10
- #else /* __GNUC__ */
11
- #define MINIMUM_WINDOWS_VERSION 0x0600 /* Vista */
12
- #endif /* __GNUC__ */
13
-
14
- #ifdef _WIN32_WINNT
15
- #undef _WIN32_WINNT
16
- #endif /* WIN32_WINNT */
17
- #define _WIN32_WINNT MINIMUM_WINDOWS_VERSION
18
-
19
- #include <time.h>
20
- #include <winevt.h>
21
- #define EventQuery(object) ((struct WinevtQuery*)DATA_PTR(object))
22
- #define EventBookMark(object) ((struct WinevtBookmark*)DATA_PTR(object))
23
- #define EventChannel(object) ((struct WinevtChannel*)DATA_PTR(object))
24
- #define EventSession(object) ((struct WinevtSession*)DATA_PTR(object))
25
-
26
- typedef struct {
27
- LANGID langID;
28
- CHAR* langCode;
29
- CHAR* description;
30
- } LocaleInfo;
31
-
32
- #ifdef __cplusplus
33
- extern "C" {
34
- #endif /* __cplusplus */
35
-
36
- VALUE wstr_to_rb_str(UINT cp, const WCHAR* wstr, int clen);
37
- #if defined(__cplusplus)
38
- [[ noreturn ]]
39
- #endif /* __cplusplus */
40
- void raise_system_error(VALUE error, DWORD errorCode);
41
- VALUE render_to_rb_str(EVT_HANDLE handle, DWORD flags);
42
- EVT_HANDLE connect_to_remote(LPWSTR computerName, LPWSTR domain,
43
- LPWSTR username, LPWSTR password,
44
- EVT_RPC_LOGIN_FLAGS flags);
45
- WCHAR* get_description(EVT_HANDLE handle, LANGID langID, EVT_HANDLE hRemote);
46
- VALUE get_values(EVT_HANDLE handle);
47
- VALUE render_system_event(EVT_HANDLE handle, BOOL preserve_qualifiers);
48
- LocaleInfo* get_locale_info_from_rb_str(VALUE rb_locale_str);
49
-
50
- #ifdef __cplusplus
51
- }
52
- #endif /* __cplusplus */
53
-
54
- extern VALUE rb_cQuery;
55
- extern VALUE rb_cFlag;
56
- extern VALUE rb_cChannel;
57
- extern VALUE rb_cBookmark;
58
- extern VALUE rb_cSubscribe;
59
- extern VALUE rb_eWinevtQueryError;
60
- extern VALUE rb_eRemoteHandlerError;
61
- extern VALUE rb_cLocale;
62
- extern VALUE rb_cSession;
63
-
64
- struct WinevtSession {
65
- LPWSTR server;
66
- LPWSTR domain;
67
- LPWSTR username;
68
- LPWSTR password;
69
- EVT_RPC_LOGIN_FLAGS flags;
70
- };
71
-
72
- extern LocaleInfo localeInfoTable[];
73
- extern LocaleInfo default_locale;
74
-
75
- struct WinevtLocale {};
76
-
77
- struct WinevtChannel
78
- {
79
- EVT_HANDLE channels;
80
- BOOL force_enumerate;
81
- };
82
-
83
- struct WinevtBookmark
84
- {
85
- EVT_HANDLE bookmark;
86
- ULONG count;
87
- };
88
-
89
- #define QUERY_ARRAY_SIZE 10
90
-
91
- struct WinevtQuery
92
- {
93
- EVT_HANDLE query;
94
- EVT_HANDLE hEvents[QUERY_ARRAY_SIZE];
95
- ULONG count;
96
- LONG offset;
97
- LONG timeout;
98
- BOOL renderAsXML;
99
- BOOL preserveQualifiers;
100
- LocaleInfo *localeInfo;
101
- EVT_HANDLE remoteHandle;
102
- };
103
-
104
- #define SUBSCRIBE_ARRAY_SIZE 10
105
- #define SUBSCRIBE_RATE_INFINITE -1
106
-
107
- struct WinevtSubscribe
108
- {
109
- HANDLE signalEvent;
110
- EVT_HANDLE subscription;
111
- EVT_HANDLE bookmark;
112
- EVT_HANDLE hEvents[SUBSCRIBE_ARRAY_SIZE];
113
- DWORD count;
114
- DWORD flags;
115
- BOOL readExistingEvents;
116
- DWORD rateLimit;
117
- time_t lastTime;
118
- DWORD currentRate;
119
- BOOL renderAsXML;
120
- BOOL preserveQualifiers;
121
- LocaleInfo* localeInfo;
122
- EVT_HANDLE remoteHandle;
123
- };
124
-
125
- void Init_winevt_query(VALUE rb_cEventLog);
126
- void Init_winevt_channel(VALUE rb_cEventLog);
127
- void Init_winevt_bookmark(VALUE rb_cEventLog);
128
- void Init_winevt_subscribe(VALUE rb_cEventLog);
129
- void Init_winevt_locale(VALUE rb_cEventLog);
130
- void Init_winevt_session(VALUE rb_cEventLog);
131
-
132
- #endif // _WINEVT_C_H
1
+ #ifndef _WINEVT_C_H_
2
+ #define _WINEVT_C_H_
3
+
4
+ #include <ruby.h>
5
+ #include <ruby/encoding.h>
6
+
7
+ #ifdef __GNUC__
8
+ #include <w32api.h>
9
+ #define MINIMUM_WINDOWS_VERSION WindowsVista
10
+ #else /* __GNUC__ */
11
+ #define MINIMUM_WINDOWS_VERSION 0x0600 /* Vista */
12
+ #endif /* __GNUC__ */
13
+
14
+ #ifdef _WIN32_WINNT
15
+ #undef _WIN32_WINNT
16
+ #endif /* WIN32_WINNT */
17
+ #define _WIN32_WINNT MINIMUM_WINDOWS_VERSION
18
+
19
+ #include <time.h>
20
+ #include <winevt.h>
21
+ #define EventQuery(object) ((struct WinevtQuery*)DATA_PTR(object))
22
+ #define EventBookMark(object) ((struct WinevtBookmark*)DATA_PTR(object))
23
+ #define EventChannel(object) ((struct WinevtChannel*)DATA_PTR(object))
24
+ #define EventSession(object) ((struct WinevtSession*)DATA_PTR(object))
25
+
26
+ typedef struct {
27
+ LANGID langID;
28
+ CHAR* langCode;
29
+ CHAR* description;
30
+ } LocaleInfo;
31
+
32
+ #ifdef __cplusplus
33
+ extern "C" {
34
+ #endif /* __cplusplus */
35
+
36
+ VALUE wstr_to_rb_str(UINT cp, const WCHAR* wstr, int clen);
37
+ #if defined(__cplusplus)
38
+ [[ noreturn ]]
39
+ #endif /* __cplusplus */
40
+ void raise_system_error(VALUE error, DWORD errorCode);
41
+ VALUE render_to_rb_str(EVT_HANDLE handle, DWORD flags);
42
+ EVT_HANDLE connect_to_remote(LPWSTR computerName, LPWSTR domain,
43
+ LPWSTR username, LPWSTR password,
44
+ EVT_RPC_LOGIN_FLAGS flags,
45
+ DWORD *error_code);
46
+ WCHAR* get_description(EVT_HANDLE handle, LANGID langID, EVT_HANDLE hRemote);
47
+ VALUE get_values(EVT_HANDLE handle);
48
+ VALUE render_system_event(EVT_HANDLE handle, BOOL preserve_qualifiers);
49
+ LocaleInfo* get_locale_info_from_rb_str(VALUE rb_locale_str);
50
+
51
+ #ifdef __cplusplus
52
+ }
53
+ #endif /* __cplusplus */
54
+
55
+ extern VALUE rb_cQuery;
56
+ extern VALUE rb_cFlag;
57
+ extern VALUE rb_cChannel;
58
+ extern VALUE rb_cBookmark;
59
+ extern VALUE rb_cSubscribe;
60
+ extern VALUE rb_eWinevtQueryError;
61
+ extern VALUE rb_eRemoteHandlerError;
62
+ extern VALUE rb_cLocale;
63
+ extern VALUE rb_cSession;
64
+
65
+ struct WinevtSession {
66
+ LPWSTR server;
67
+ LPWSTR domain;
68
+ LPWSTR username;
69
+ LPWSTR password;
70
+ EVT_RPC_LOGIN_FLAGS flags;
71
+ };
72
+
73
+ extern LocaleInfo localeInfoTable[];
74
+ extern LocaleInfo default_locale;
75
+
76
+ struct WinevtLocale {};
77
+
78
+ struct WinevtChannel
79
+ {
80
+ EVT_HANDLE channels;
81
+ BOOL force_enumerate;
82
+ };
83
+
84
+ struct WinevtBookmark
85
+ {
86
+ EVT_HANDLE bookmark;
87
+ ULONG count;
88
+ };
89
+
90
+ #define QUERY_ARRAY_SIZE 10
91
+
92
+ struct WinevtQuery
93
+ {
94
+ EVT_HANDLE query;
95
+ EVT_HANDLE hEvents[QUERY_ARRAY_SIZE];
96
+ ULONG count;
97
+ LONG offset;
98
+ LONG timeout;
99
+ BOOL renderAsXML;
100
+ BOOL preserveQualifiers;
101
+ LocaleInfo *localeInfo;
102
+ EVT_HANDLE remoteHandle;
103
+ };
104
+
105
+ #define SUBSCRIBE_ARRAY_SIZE 10
106
+ #define SUBSCRIBE_RATE_INFINITE -1
107
+
108
+ struct WinevtSubscribe
109
+ {
110
+ HANDLE signalEvent;
111
+ EVT_HANDLE subscription;
112
+ EVT_HANDLE bookmark;
113
+ EVT_HANDLE hEvents[SUBSCRIBE_ARRAY_SIZE];
114
+ DWORD count;
115
+ DWORD flags;
116
+ BOOL readExistingEvents;
117
+ DWORD rateLimit;
118
+ time_t lastTime;
119
+ DWORD currentRate;
120
+ BOOL renderAsXML;
121
+ BOOL preserveQualifiers;
122
+ LocaleInfo* localeInfo;
123
+ EVT_HANDLE remoteHandle;
124
+ };
125
+
126
+ void Init_winevt_query(VALUE rb_cEventLog);
127
+ void Init_winevt_channel(VALUE rb_cEventLog);
128
+ void Init_winevt_bookmark(VALUE rb_cEventLog);
129
+ void Init_winevt_subscribe(VALUE rb_cEventLog);
130
+ void Init_winevt_locale(VALUE rb_cEventLog);
131
+ void Init_winevt_session(VALUE rb_cEventLog);
132
+
133
+ #endif // _WINEVT_C_H