winevt_c 0.9.1 → 0.9.2

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.
data/example/tailing.rb CHANGED
@@ -1,21 +1,21 @@
1
- require 'winevt'
2
-
3
- @session = Winevt::EventLog::Session.new("127.0.0.1") # Or remote box ip
4
- # @session.domain = "<EXAMPLEGROUP>"
5
- # @session.username = "<username>"
6
- # @session.password = "<password>"
7
- @bookmark = Winevt::EventLog::Bookmark.new
8
- @subscribe = Winevt::EventLog::Subscribe.new
9
- @subscribe.read_existing_events = true
10
- @subscribe.preserve_qualifiers = true
11
- @subscribe.render_as_xml = true
12
- @subscribe.subscribe(
13
- "Security", "*[System[(Level <= 4) and TimeCreated[timediff(@SystemTime) <= 86400000]]]",
14
- @bookmark, @session
15
- )
16
- while true do
17
- @subscribe.each do |eventlog, message, string_inserts|
18
- puts ({eventlog: eventlog, data: message})
19
- end
20
- sleep(1)
21
- end
1
+ require 'winevt'
2
+
3
+ @session = Winevt::EventLog::Session.new("127.0.0.1") # Or remote box ip
4
+ # @session.domain = "<EXAMPLEGROUP>"
5
+ # @session.username = "<username>"
6
+ # @session.password = "<password>"
7
+ @bookmark = Winevt::EventLog::Bookmark.new
8
+ @subscribe = Winevt::EventLog::Subscribe.new
9
+ @subscribe.read_existing_events = true
10
+ @subscribe.preserve_qualifiers = true
11
+ @subscribe.render_as_xml = true
12
+ @subscribe.subscribe(
13
+ "Security", "*[System[(Level <= 4) and TimeCreated[timediff(@SystemTime) <= 86400000]]]",
14
+ @bookmark, @session
15
+ )
16
+ while true do
17
+ @subscribe.each do |eventlog, message, string_inserts|
18
+ puts ({eventlog: eventlog, data: message})
19
+ end
20
+ sleep(1)
21
+ end
@@ -1,24 +1,24 @@
1
- require "mkmf"
2
- require "rbconfig"
3
-
4
- if RbConfig::CONFIG['host_os'] =~ /mingw/
5
- $CFLAGS << ' -fno-omit-frame-pointer'
6
- end
7
-
8
- libdir = RbConfig::CONFIG["libdir"]
9
- includedir = RbConfig::CONFIG["includedir"]
10
-
11
- dir_config("winevt", includedir, libdir)
12
-
13
- have_library("wevtapi")
14
- have_func("EvtQuery", "winevt.h")
15
- have_library("advapi32")
16
- have_library("ole32")
17
-
18
- $LDFLAGS << " -lwevtapi -ladvapi32 -lole32"
19
- $CFLAGS << " -Wall -std=c99 -fPIC -fms-extensions "
20
- $CXXFLAGS << " -Wall -std=c++11 -fPIC -fms-extensions "
21
- # $CFLAGS << " -g -O0 -ggdb"
22
- # $CXXFLAGS << " -g -O0 -ggdb"
23
-
24
- create_makefile("winevt/winevt")
1
+ require "mkmf"
2
+ require "rbconfig"
3
+
4
+ if RbConfig::CONFIG['host_os'] =~ /mingw/
5
+ $CFLAGS << ' -fno-omit-frame-pointer'
6
+ end
7
+
8
+ libdir = RbConfig::CONFIG["libdir"]
9
+ includedir = RbConfig::CONFIG["includedir"]
10
+
11
+ dir_config("winevt", includedir, libdir)
12
+
13
+ have_library("wevtapi")
14
+ have_func("EvtQuery", "winevt.h")
15
+ have_library("advapi32")
16
+ have_library("ole32")
17
+
18
+ $LDFLAGS << " -lwevtapi -ladvapi32 -lole32"
19
+ $CFLAGS << " -Wall -std=c99 -fPIC -fms-extensions "
20
+ $CXXFLAGS << " -Wall -std=c++11 -fPIC -fms-extensions "
21
+ # $CFLAGS << " -g -O0 -ggdb"
22
+ # $CXXFLAGS << " -g -O0 -ggdb"
23
+
24
+ create_makefile("winevt/winevt")
data/ext/winevt/winevt.c CHANGED
@@ -1,30 +1,30 @@
1
- #include <winevt_c.h>
2
-
3
- VALUE rb_mWinevt;
4
- VALUE rb_cQuery;
5
- VALUE rb_cEventLog;
6
- VALUE rb_cSubscribe;
7
- VALUE rb_eWinevtQueryError;
8
- VALUE rb_eRemoteHandlerError;
9
-
10
- static ID id_call;
11
-
12
- void
13
- Init_winevt(void)
14
- {
15
- rb_mWinevt = rb_define_module("Winevt");
16
- rb_cEventLog = rb_define_class_under(rb_mWinevt, "EventLog", rb_cObject);
17
- rb_cQuery = rb_define_class_under(rb_cEventLog, "Query", rb_cObject);
18
- rb_cSubscribe = rb_define_class_under(rb_cEventLog, "Subscribe", rb_cObject);
19
- rb_eWinevtQueryError = rb_define_class_under(rb_cQuery, "Error", rb_eStandardError);
20
- rb_eRemoteHandlerError = rb_define_class_under(rb_cSubscribe, "RemoteHandlerError", rb_eRuntimeError);
21
-
22
- Init_winevt_channel(rb_cEventLog);
23
- Init_winevt_bookmark(rb_cEventLog);
24
- Init_winevt_query(rb_cEventLog);
25
- Init_winevt_subscribe(rb_cEventLog);
26
- Init_winevt_locale(rb_cEventLog);
27
- Init_winevt_session(rb_cEventLog);
28
-
29
- id_call = rb_intern("call");
30
- }
1
+ #include <winevt_c.h>
2
+
3
+ VALUE rb_mWinevt;
4
+ VALUE rb_cQuery;
5
+ VALUE rb_cEventLog;
6
+ VALUE rb_cSubscribe;
7
+ VALUE rb_eWinevtQueryError;
8
+ VALUE rb_eRemoteHandlerError;
9
+
10
+ static ID id_call;
11
+
12
+ void
13
+ Init_winevt(void)
14
+ {
15
+ rb_mWinevt = rb_define_module("Winevt");
16
+ rb_cEventLog = rb_define_class_under(rb_mWinevt, "EventLog", rb_cObject);
17
+ rb_cQuery = rb_define_class_under(rb_cEventLog, "Query", rb_cObject);
18
+ rb_cSubscribe = rb_define_class_under(rb_cEventLog, "Subscribe", rb_cObject);
19
+ rb_eWinevtQueryError = rb_define_class_under(rb_cQuery, "Error", rb_eStandardError);
20
+ rb_eRemoteHandlerError = rb_define_class_under(rb_cSubscribe, "RemoteHandlerError", rb_eRuntimeError);
21
+
22
+ Init_winevt_channel(rb_cEventLog);
23
+ Init_winevt_bookmark(rb_cEventLog);
24
+ Init_winevt_query(rb_cEventLog);
25
+ Init_winevt_subscribe(rb_cEventLog);
26
+ Init_winevt_locale(rb_cEventLog);
27
+ Init_winevt_session(rb_cEventLog);
28
+
29
+ id_call = rb_intern("call");
30
+ }
@@ -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
+ }