winevt_c 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fd29b4664130c80249811fb66df434aaa9219d6d375bcdaa7adfdd3fe72dd25e
4
- data.tar.gz: 2a1e3ec7cb528269ebb65f4b1df72d6045f882d865956fb85def8bcb925d6944
3
+ metadata.gz: d691ef9954d626041b79d1d63a4258537ded33c0f9c07c9551fd40b6aa211f12
4
+ data.tar.gz: fbe964ae721b310ca9c9adcf092b0f5ab4f0207e154c41287c17b2a6275932db
5
5
  SHA512:
6
- metadata.gz: 0f80978e4268c233d2e309c0e9556f38386b35300381c04f4d84226ce239a85ccb48b20a2c2a3c59c3d0557347e95ff11e0ca11945eaa128ba2c78c67ebc9250
7
- data.tar.gz: a8ff4fae4995b41910352186898d54c929a918f86a6a4efe29c0a5c93433d9c95d91be5c9f81fdb52ff5f2307cbb2e2e61790a22fe076b7221ba03c89aed48d5
6
+ metadata.gz: 90059826d6c9ab0efdce70b7d4c5c4490c69e522fbcaef284e3616aa043b4de63731fe3805c9c4b8837842e44da04f376d8a813b750f926c3ab474c88c332b8c
7
+ data.tar.gz: 4c75263c161461089b754d512c5d7eaaa9aec9d8e7debeff1d9e0c98c73639f4157f332b5c32ad805b6e3df08e8a330e2e5d76fa85902dc70f133c4e4180ea87
@@ -32,19 +32,31 @@ static const rb_data_type_t rb_winevt_query_type = { "winevt/query",
32
32
  RUBY_TYPED_FREE_IMMEDIATELY };
33
33
 
34
34
  static void
35
- query_free(void* ptr)
35
+ close_handles(struct WinevtQuery* winevtQuery)
36
36
  {
37
- struct WinevtQuery* winevtQuery = (struct WinevtQuery*)ptr;
38
- if (winevtQuery->query)
37
+ if (winevtQuery->query) {
39
38
  EvtClose(winevtQuery->query);
39
+ winevtQuery->query = NULL;
40
+ }
40
41
 
41
42
  for (int i = 0; i < winevtQuery->count; i++) {
42
- if (winevtQuery->hEvents[i])
43
+ if (winevtQuery->hEvents[i]) {
43
44
  EvtClose(winevtQuery->hEvents[i]);
45
+ winevtQuery->hEvents[i] = NULL;
46
+ }
44
47
  }
45
48
 
46
- if (winevtQuery->remoteHandle)
49
+ if (winevtQuery->remoteHandle) {
47
50
  EvtClose(winevtQuery->remoteHandle);
51
+ winevtQuery->remoteHandle = NULL;
52
+ }
53
+ }
54
+
55
+ static void
56
+ query_free(void* ptr)
57
+ {
58
+ struct WinevtQuery* winevtQuery = (struct WinevtQuery*)ptr;
59
+ close_handles(winevtQuery);
48
60
 
49
61
  xfree(ptr);
50
62
  }
@@ -219,6 +231,9 @@ rb_winevt_query_next(VALUE self)
219
231
 
220
232
  if (!EvtNext(winevtQuery->query, QUERY_ARRAY_SIZE, hEvents, INFINITE, 0, &count)) {
221
233
  status = GetLastError();
234
+ if (ERROR_CANCELLED == status) {
235
+ return Qfalse;
236
+ }
222
237
  if (ERROR_NO_MORE_ITEMS != status) {
223
238
  return Qfalse;
224
239
  }
@@ -507,6 +522,50 @@ rb_winevt_query_get_locale(VALUE self)
507
522
  }
508
523
  }
509
524
 
525
+ /*
526
+ * This method cancels channel query.
527
+ *
528
+ * @return [Boolean]
529
+ * @since 0.9.1
530
+ */
531
+ static VALUE
532
+ rb_winevt_query_cancel(VALUE self)
533
+ {
534
+ struct WinevtQuery* winevtQuery;
535
+ BOOL result = FALSE;
536
+
537
+ TypedData_Get_Struct(
538
+ self, struct WinevtQuery, &rb_winevt_query_type, winevtQuery);
539
+
540
+ if (winevtQuery->query) {
541
+ result = EvtCancel(winevtQuery->query);
542
+ }
543
+
544
+ if (result) {
545
+ return Qtrue;
546
+ } else {
547
+ return Qfalse;
548
+ }
549
+ }
550
+
551
+ /*
552
+ * This method closes channel handles forcibly.
553
+ *
554
+ * @since 0.9.1
555
+ */
556
+ static VALUE
557
+ rb_winevt_query_close(VALUE self)
558
+ {
559
+ struct WinevtQuery* winevtQuery;
560
+
561
+ TypedData_Get_Struct(
562
+ self, struct WinevtQuery, &rb_winevt_query_type, winevtQuery);
563
+
564
+ close_handles(winevtQuery);
565
+
566
+ return Qnil;
567
+ }
568
+
510
569
  void
511
570
  Init_winevt_query(VALUE rb_cEventLog)
512
571
  {
@@ -580,4 +639,12 @@ Init_winevt_query(VALUE rb_cEventLog)
580
639
  * @since 0.8.0
581
640
  */
582
641
  rb_define_method(rb_cQuery, "locale=", rb_winevt_query_set_locale, 1);
642
+ /*
643
+ * @since 0.9.1
644
+ */
645
+ rb_define_method(rb_cQuery, "cancel", rb_winevt_query_cancel, 0);
646
+ /*
647
+ * @since 0.9.1
648
+ */
649
+ rb_define_method(rb_cQuery, "close", rb_winevt_query_close, 0);
583
650
  }
@@ -39,26 +39,42 @@ static const rb_data_type_t rb_winevt_subscribe_type = { "winevt/subscribe",
39
39
  RUBY_TYPED_FREE_IMMEDIATELY };
40
40
 
41
41
  static void
42
- subscribe_free(void* ptr)
42
+ close_handles(struct WinevtSubscribe* winevtSubscribe)
43
43
  {
44
- struct WinevtSubscribe* winevtSubscribe = (struct WinevtSubscribe*)ptr;
45
- if (winevtSubscribe->signalEvent)
44
+ if (winevtSubscribe->signalEvent) {
46
45
  CloseHandle(winevtSubscribe->signalEvent);
46
+ winevtSubscribe->signalEvent = NULL;
47
+ }
47
48
 
48
- if (winevtSubscribe->subscription)
49
+ if (winevtSubscribe->subscription) {
49
50
  EvtClose(winevtSubscribe->subscription);
51
+ winevtSubscribe->subscription = NULL;
52
+ }
50
53
 
51
- if (winevtSubscribe->bookmark)
54
+ if (winevtSubscribe->bookmark) {
52
55
  EvtClose(winevtSubscribe->bookmark);
56
+ winevtSubscribe->bookmark = NULL;
57
+ }
53
58
 
54
59
  for (int i = 0; i < winevtSubscribe->count; i++) {
55
60
  if (winevtSubscribe->hEvents[i]) {
56
61
  EvtClose(winevtSubscribe->hEvents[i]);
62
+ winevtSubscribe->hEvents[i] = NULL;
57
63
  }
58
64
  }
65
+ winevtSubscribe->count = 0;
59
66
 
60
- if (winevtSubscribe->remoteHandle)
67
+ if (winevtSubscribe->remoteHandle) {
61
68
  EvtClose(winevtSubscribe->remoteHandle);
69
+ winevtSubscribe->remoteHandle = NULL;
70
+ }
71
+ }
72
+
73
+ static void
74
+ subscribe_free(void* ptr)
75
+ {
76
+ struct WinevtSubscribe* winevtSubscribe = (struct WinevtSubscribe*)ptr;
77
+ close_handles(winevtSubscribe);
62
78
 
63
79
  xfree(ptr);
64
80
  }
@@ -328,6 +344,11 @@ rb_winevt_subscribe_next(VALUE self)
328
344
  return Qfalse;
329
345
  }
330
346
 
347
+ /* If subscription handle is NULL, it should return false. */
348
+ if (!winevtSubscribe->subscription) {
349
+ return Qfalse;
350
+ }
351
+
331
352
  if (!EvtNext(winevtSubscribe->subscription,
332
353
  SUBSCRIBE_ARRAY_SIZE,
333
354
  hEvents,
@@ -335,6 +356,9 @@ rb_winevt_subscribe_next(VALUE self)
335
356
  0,
336
357
  &count)) {
337
358
  status = GetLastError();
359
+ if (ERROR_CANCELLED == status) {
360
+ return Qfalse;
361
+ }
338
362
  if (ERROR_NO_MORE_ITEMS != status) {
339
363
  return Qfalse;
340
364
  }
@@ -623,6 +647,51 @@ rb_winevt_subscribe_get_locale(VALUE self)
623
647
  }
624
648
  }
625
649
 
650
+ /*
651
+ * This method cancels channel subscription.
652
+ *
653
+ * @return [Boolean]
654
+ * @since 0.9.1
655
+ */
656
+ static VALUE
657
+ rb_winevt_subscribe_cancel(VALUE self)
658
+ {
659
+ struct WinevtSubscribe* winevtSubscribe;
660
+ BOOL result = FALSE;
661
+
662
+ TypedData_Get_Struct(
663
+ self, struct WinevtSubscribe, &rb_winevt_subscribe_type, winevtSubscribe);
664
+
665
+ if (winevtSubscribe->subscription) {
666
+ result = EvtCancel(winevtSubscribe->subscription);
667
+ }
668
+
669
+ if (result) {
670
+ return Qtrue;
671
+ } else {
672
+ return Qfalse;
673
+ }
674
+ }
675
+
676
+ /*
677
+ * This method closes channel handles forcibly.
678
+ *
679
+ * @since 0.9.1
680
+ */
681
+ static VALUE
682
+ rb_winevt_subscribe_close(VALUE self)
683
+ {
684
+ struct WinevtSubscribe* winevtSubscribe;
685
+
686
+ TypedData_Get_Struct(
687
+ self, struct WinevtSubscribe, &rb_winevt_subscribe_type, winevtSubscribe);
688
+
689
+ close_handles(winevtSubscribe);
690
+
691
+ return Qnil;
692
+ }
693
+
694
+
626
695
  void
627
696
  Init_winevt_subscribe(VALUE rb_cEventLog)
628
697
  {
@@ -675,4 +744,14 @@ Init_winevt_subscribe(VALUE rb_cEventLog)
675
744
  */
676
745
  rb_define_method(
677
746
  rb_cSubscribe, "locale=", rb_winevt_subscribe_set_locale, 1);
747
+ /*
748
+ * @since 0.9.1
749
+ */
750
+ rb_define_method(
751
+ rb_cSubscribe, "cancel", rb_winevt_subscribe_cancel, 0);
752
+ /*
753
+ * @since 0.9.1
754
+ */
755
+ rb_define_method(
756
+ rb_cSubscribe, "close", rb_winevt_subscribe_close, 0);
678
757
  }
@@ -1,3 +1,3 @@
1
1
  module Winevt
2
- VERSION = "0.9.0"
2
+ VERSION = "0.9.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: winevt_c
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hiroshi Hatake
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-09-10 00:00:00.000000000 Z
11
+ date: 2020-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler