winevt_c 0.7.4 → 0.8.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6e72ff331d8ba4dc17ec931ae052992a175e109c80b9354e824dea45cf0d9f62
4
- data.tar.gz: dbe0186774a155a29b0437f172c0f5479204d26c6174a6b9240e1eba28a23bd9
3
+ metadata.gz: 1971f2d9fdcbd76e480acada73e61689c28eda9499c3c4e19170a8465d62cfe4
4
+ data.tar.gz: a54692008698865f129c84ac206cd5bffc08daa49fee5012d34679d99fdc6080
5
5
  SHA512:
6
- metadata.gz: 5cc4229d2df4c1f6c66400914844b6b87a375ff6b841ca312351517ca1dd9c4bb30679d0ee1ea21f2b9593121ae3acdc4d4b23e79cf996c50bc5eed20be062cc
7
- data.tar.gz: cb59a8e132a07d5628f9c0a1a4b7ffc615b432fc67ec3679a36b82cc94e705f6075b86b1037437a95f277cb4f97163db4fcf1cad30d26e05ed26d2d3c79d296b
6
+ metadata.gz: a0091ec0d64ba252b39dc927504049c88b648f5c4bec0ce43dd4d00967bf8c0475e872da2286f7e757a9f16889209373c5e30998c534704105a2d973671a49d7
7
+ data.tar.gz: 65480a5c5d43e484d5755ed1f1935f41bc26c507769563f6c5a181eabf986cf7d7bad376da798150f1215063cc226477efac6f6e3d4007a96e213bbeba1ae874
@@ -22,6 +22,11 @@
22
22
  #define EventBookMark(object) ((struct WinevtBookmark*)DATA_PTR(object))
23
23
  #define EventChannel(object) ((struct WinevtChannel*)DATA_PTR(object))
24
24
 
25
+ typedef struct {
26
+ LANGID langID;
27
+ CHAR* langCode;
28
+ } LocaleInfo;
29
+
25
30
  #ifdef __cplusplus
26
31
  extern "C" {
27
32
  #endif /* __cplusplus */
@@ -32,9 +37,10 @@ VALUE wstr_to_rb_str(UINT cp, const WCHAR* wstr, int clen);
32
37
  #endif /* __cplusplus */
33
38
  void raise_system_error(VALUE error, DWORD errorCode);
34
39
  VALUE render_to_rb_str(EVT_HANDLE handle, DWORD flags);
35
- WCHAR* get_description(EVT_HANDLE handle);
40
+ WCHAR* get_description(EVT_HANDLE handle, LANGID langID);
36
41
  VALUE get_values(EVT_HANDLE handle);
37
42
  VALUE render_system_event(EVT_HANDLE handle, BOOL preserve_qualifiers);
43
+ LocaleInfo* get_locale_from_rb_str(VALUE rb_locale_str);
38
44
 
39
45
  #ifdef __cplusplus
40
46
  }
@@ -47,6 +53,8 @@ extern VALUE rb_cBookmark;
47
53
  extern VALUE rb_cSubscribe;
48
54
  extern VALUE rb_eWinevtQueryError;
49
55
 
56
+ extern LocaleInfo default_locale;
57
+
50
58
  struct WinevtChannel
51
59
  {
52
60
  EVT_HANDLE channels;
@@ -70,6 +78,7 @@ struct WinevtQuery
70
78
  LONG timeout;
71
79
  BOOL renderAsXML;
72
80
  BOOL preserveQualifiers;
81
+ LocaleInfo *localeInfo;
73
82
  };
74
83
 
75
84
  #define SUBSCRIBE_ARRAY_SIZE 10
@@ -89,6 +98,7 @@ struct WinevtSubscribe
89
98
  DWORD currentRate;
90
99
  BOOL renderAsXML;
91
100
  BOOL preserveQualifiers;
101
+ LocaleInfo* localeInfo;
92
102
  };
93
103
 
94
104
  void Init_winevt_query(VALUE rb_cEventLog);
@@ -0,0 +1,68 @@
1
+ #include <winevt_c.h>
2
+
3
+ static LocaleInfo localeInfoTable [] = {
4
+ { MAKELANGID(LANG_BULGARIAN, SUBLANG_DEFAULT), "bg_BG"},
5
+ { MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED), "zh_CN"},
6
+ { MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_TRADITIONAL), "zh_TW"},
7
+ { MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_HONGKONG), "zh_HK"},
8
+ { MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SINGAPORE), "zh_SG"},
9
+ { MAKELANGID(LANG_CROATIAN, SUBLANG_DEFAULT), "hr_HR"},
10
+ { MAKELANGID(LANG_CZECH, SUBLANG_DEFAULT), "cs_CZ"},
11
+ { MAKELANGID(LANG_DANISH, SUBLANG_DEFAULT), "da_DK"},
12
+ { MAKELANGID(LANG_DUTCH, SUBLANG_DUTCH), "nl_NL"},
13
+ { MAKELANGID(LANG_DUTCH, SUBLANG_DUTCH_BELGIAN), "nl_BE"},
14
+ { MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT), "en_US"},
15
+ { MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_UK), "en_GB"},
16
+ { MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_AUS), "en_AU"},
17
+ { MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_CAN), "en_CA"},
18
+ { MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_NZ), "en_NZ"},
19
+ { MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_EIRE), "en_IE"},
20
+ { MAKELANGID(LANG_FINNISH, SUBLANG_DEFAULT), "fi_FI"},
21
+ { MAKELANGID(LANG_FRENCH, SUBLANG_FRENCH), "fr_FR"},
22
+ { MAKELANGID(LANG_FRENCH, SUBLANG_FRENCH_BELGIAN), "fr_BE"},
23
+ { MAKELANGID(LANG_FRENCH, SUBLANG_FRENCH_CANADIAN), "fr_CA"},
24
+ { MAKELANGID(LANG_FRENCH, SUBLANG_FRENCH_SWISS), "fr_CH"},
25
+ { MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN), "de_DE"},
26
+ { MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN_SWISS), "de_CH"},
27
+ { MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN_AUSTRIAN), "de_AT"},
28
+ { MAKELANGID(LANG_GREEK, SUBLANG_DEFAULT), "el_GR"},
29
+ { MAKELANGID(LANG_HUNGARIAN, SUBLANG_DEFAULT), "hu_HU"},
30
+ { MAKELANGID(LANG_ICELANDIC, SUBLANG_DEFAULT), "is_IS"},
31
+ { MAKELANGID(LANG_ITALIAN, SUBLANG_ITALIAN), "it_IT"},
32
+ { MAKELANGID(LANG_ITALIAN, SUBLANG_ITALIAN_SWISS), "it_CH"},
33
+ { MAKELANGID(LANG_JAPANESE, SUBLANG_DEFAULT), "ja_JP"},
34
+ { MAKELANGID(LANG_KOREAN, SUBLANG_DEFAULT), "ko_KO"},
35
+ { MAKELANGID(LANG_NORWEGIAN, SUBLANG_NORWEGIAN_BOKMAL), "no_NO"},
36
+ { MAKELANGID(LANG_NORWEGIAN, SUBLANG_NORWEGIAN_BOKMAL), "nb_NO"},
37
+ { MAKELANGID(LANG_NORWEGIAN, SUBLANG_NORWEGIAN_NYNORSK), "nn_NO"},
38
+ { MAKELANGID(LANG_POLISH, SUBLANG_DEFAULT), "pl_PL"},
39
+ { MAKELANGID(LANG_PORTUGUESE, SUBLANG_PORTUGUESE), "pt_PT"},
40
+ { MAKELANGID(LANG_PORTUGUESE, SUBLANG_PORTUGUESE_BRAZILIAN), "pt_BR"},
41
+ { MAKELANGID(LANG_ROMANIAN, SUBLANG_DEFAULT), "ro_RO"},
42
+ { MAKELANGID(LANG_RUSSIAN, SUBLANG_DEFAULT), "ru_RU"},
43
+ { MAKELANGID(LANG_SLOVAK, SUBLANG_DEFAULT), "sk_SK"},
44
+ { MAKELANGID(LANG_SLOVENIAN, SUBLANG_DEFAULT), "sl_SI"},
45
+ { MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH), "es_ES"},
46
+ { MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH), "es_ES_T"},
47
+ { MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH_MEXICAN), "es_MX"},
48
+ { MAKELANGID(LANG_SPANISH, SUBLANG_SPANISH_MODERN), "es_ES_M"},
49
+ { MAKELANGID(LANG_SWEDISH, SUBLANG_DEFAULT), "sv_SE"},
50
+ { MAKELANGID(LANG_TURKISH, SUBLANG_DEFAULT), "tr_TR"},
51
+ { 0, NULL}
52
+ };
53
+
54
+ LocaleInfo default_locale = {MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), "neutral"};
55
+
56
+ LocaleInfo*
57
+ get_locale_from_rb_str(VALUE rb_locale_str)
58
+ {
59
+ CHAR* locale_str = StringValuePtr(rb_locale_str);
60
+
61
+ for (int i = 0; localeInfoTable[i].langCode != NULL; i++) {
62
+ if (stricmp(localeInfoTable[i].langCode, locale_str) == 0) {
63
+ return &localeInfoTable[i];
64
+ }
65
+ }
66
+
67
+ rb_raise(rb_eArgError, "Unknown locale: %s", locale_str);
68
+ }
@@ -96,6 +96,7 @@ rb_winevt_query_initialize(VALUE self, VALUE channel, VALUE xpath)
96
96
  winevtQuery->timeout = 0L;
97
97
  winevtQuery->renderAsXML = TRUE;
98
98
  winevtQuery->preserveQualifiers = FALSE;
99
+ winevtQuery->localeInfo = &default_locale;
99
100
 
100
101
  ALLOCV_END(wchannelBuf);
101
102
  ALLOCV_END(wpathBuf);
@@ -219,12 +220,12 @@ rb_winevt_query_render(VALUE self, EVT_HANDLE event)
219
220
  }
220
221
 
221
222
  static VALUE
222
- rb_winevt_query_message(EVT_HANDLE event)
223
+ rb_winevt_query_message(EVT_HANDLE event, LocaleInfo* localeInfo)
223
224
  {
224
225
  WCHAR* wResult;
225
226
  VALUE utf8str;
226
227
 
227
- wResult = get_description(event);
228
+ wResult = get_description(event, localeInfo->langID);
228
229
  utf8str = wstr_to_rb_str(CP_UTF8, wResult, -1);
229
230
  free(wResult);
230
231
 
@@ -336,7 +337,7 @@ rb_winevt_query_each_yield(VALUE self)
336
337
  for (int i = 0; i < winevtQuery->count; i++) {
337
338
  rb_yield_values(3,
338
339
  rb_winevt_query_render(self, winevtQuery->hEvents[i]),
339
- rb_winevt_query_message(winevtQuery->hEvents[i]),
340
+ rb_winevt_query_message(winevtQuery->hEvents[i], winevtQuery->localeInfo),
340
341
  rb_winevt_query_string_inserts(winevtQuery->hEvents[i]));
341
342
  }
342
343
  return Qnil;
@@ -432,6 +433,48 @@ rb_winevt_query_get_preserve_qualifiers_p(VALUE self)
432
433
  return winevtQuery->preserveQualifiers ? Qtrue : Qfalse;
433
434
  }
434
435
 
436
+ /*
437
+ * This method specifies locale with [String].
438
+ *
439
+ * @since 0.8.0
440
+ * @param rb_locale_str [String]
441
+ */
442
+ static VALUE
443
+ rb_winevt_query_set_locale(VALUE self, VALUE rb_locale_str)
444
+ {
445
+ struct WinevtQuery* winevtQuery;
446
+ LocaleInfo* locale_info = &default_locale;
447
+
448
+ TypedData_Get_Struct(
449
+ self, struct WinevtQuery, &rb_winevt_query_type, winevtQuery);
450
+
451
+ locale_info = get_locale_from_rb_str(rb_locale_str);
452
+
453
+ winevtQuery->localeInfo = locale_info;
454
+
455
+ return Qnil;
456
+ }
457
+
458
+ /*
459
+ * This method obtains specified locale with [String].
460
+ *
461
+ * @since 0.8.0
462
+ */
463
+ static VALUE
464
+ rb_winevt_query_get_locale(VALUE self)
465
+ {
466
+ struct WinevtQuery* winevtQuery;
467
+
468
+ TypedData_Get_Struct(
469
+ self, struct WinevtQuery, &rb_winevt_query_type, winevtQuery);
470
+
471
+ if (winevtQuery->localeInfo->langCode) {
472
+ return rb_str_new2(winevtQuery->localeInfo->langCode);
473
+ } else {
474
+ return rb_str_new2(default_locale.langCode);
475
+ }
476
+ }
477
+
435
478
  void
436
479
  Init_winevt_query(VALUE rb_cEventLog)
437
480
  {
@@ -497,4 +540,12 @@ Init_winevt_query(VALUE rb_cEventLog)
497
540
  * @since 0.7.3
498
541
  */
499
542
  rb_define_method(rb_cQuery, "preserve_qualifiers=", rb_winevt_query_set_preserve_qualifiers, 1);
543
+ /*
544
+ * @since 0.8.0
545
+ */
546
+ rb_define_method(rb_cQuery, "locale", rb_winevt_query_get_locale, 0);
547
+ /*
548
+ * @since 0.8.0
549
+ */
550
+ rb_define_method(rb_cQuery, "locale=", rb_winevt_query_set_locale, 1);
500
551
  }
@@ -90,6 +90,7 @@ rb_winevt_subscribe_initialize(VALUE self)
90
90
  winevtSubscribe->renderAsXML = TRUE;
91
91
  winevtSubscribe->readExistingEvents = TRUE;
92
92
  winevtSubscribe->preserveQualifiers = FALSE;
93
+ winevtSubscribe->localeInfo = &default_locale;
93
94
 
94
95
  return Qnil;
95
96
  }
@@ -345,12 +346,12 @@ rb_winevt_subscribe_render(VALUE self, EVT_HANDLE event)
345
346
  }
346
347
 
347
348
  static VALUE
348
- rb_winevt_subscribe_message(EVT_HANDLE event)
349
+ rb_winevt_subscribe_message(EVT_HANDLE event, LocaleInfo* localeInfo)
349
350
  {
350
351
  WCHAR* wResult;
351
352
  VALUE utf8str;
352
353
 
353
- wResult = get_description(event);
354
+ wResult = get_description(event, localeInfo->langID);
354
355
  utf8str = wstr_to_rb_str(CP_UTF8, wResult, -1);
355
356
  free(wResult);
356
357
 
@@ -393,7 +394,7 @@ rb_winevt_subscribe_each_yield(VALUE self)
393
394
  for (int i = 0; i < winevtSubscribe->count; i++) {
394
395
  rb_yield_values(3,
395
396
  rb_winevt_subscribe_render(self, winevtSubscribe->hEvents[i]),
396
- rb_winevt_subscribe_message(winevtSubscribe->hEvents[i]),
397
+ rb_winevt_subscribe_message(winevtSubscribe->hEvents[i], winevtSubscribe->localeInfo),
397
398
  rb_winevt_subscribe_string_inserts(winevtSubscribe->hEvents[i]));
398
399
  }
399
400
 
@@ -554,6 +555,48 @@ rb_winevt_subscribe_get_preserve_qualifiers_p(VALUE self)
554
555
  return winevtSubscribe->preserveQualifiers ? Qtrue : Qfalse;
555
556
  }
556
557
 
558
+ /*
559
+ * This method specifies locale with [String].
560
+ *
561
+ * @since 0.8.0
562
+ * @param rb_locale_str [String]
563
+ */
564
+ static VALUE
565
+ rb_winevt_subscribe_set_locale(VALUE self, VALUE rb_locale_str)
566
+ {
567
+ struct WinevtSubscribe* winevtSubscribe;
568
+ LocaleInfo* locale_info = &default_locale;
569
+
570
+ TypedData_Get_Struct(
571
+ self, struct WinevtSubscribe, &rb_winevt_subscribe_type, winevtSubscribe);
572
+
573
+ locale_info = get_locale_from_rb_str(rb_locale_str);
574
+
575
+ winevtSubscribe->localeInfo = locale_info;
576
+
577
+ return Qnil;
578
+ }
579
+
580
+ /*
581
+ * This method obtains specified locale with [String].
582
+ *
583
+ * @since 0.8.0
584
+ */
585
+ static VALUE
586
+ rb_winevt_subscribe_get_locale(VALUE self)
587
+ {
588
+ struct WinevtSubscribe* winevtSubscribe;
589
+
590
+ TypedData_Get_Struct(
591
+ self, struct WinevtSubscribe, &rb_winevt_subscribe_type, winevtSubscribe);
592
+
593
+ if (winevtSubscribe->localeInfo->langCode) {
594
+ return rb_str_new2(winevtSubscribe->localeInfo->langCode);
595
+ } else {
596
+ return rb_str_new2(default_locale.langCode);
597
+ }
598
+ }
599
+
557
600
  void
558
601
  Init_winevt_subscribe(VALUE rb_cEventLog)
559
602
  {
@@ -596,4 +639,14 @@ Init_winevt_subscribe(VALUE rb_cEventLog)
596
639
  */
597
640
  rb_define_method(
598
641
  rb_cSubscribe, "preserve_qualifiers=", rb_winevt_subscribe_set_preserve_qualifiers, 1);
642
+ /*
643
+ * @since 0.8.0
644
+ */
645
+ rb_define_method(
646
+ rb_cSubscribe, "locale", rb_winevt_subscribe_get_locale, 0);
647
+ /*
648
+ * @since 0.8.0
649
+ */
650
+ rb_define_method(
651
+ rb_cSubscribe, "locale=", rb_winevt_subscribe_set_locale, 1);
599
652
  }
@@ -433,7 +433,7 @@ cleanup:
433
433
  }
434
434
 
435
435
  WCHAR*
436
- get_description(EVT_HANDLE handle)
436
+ get_description(EVT_HANDLE handle, LANGID langID)
437
437
  {
438
438
  #define BUFSIZE 4096
439
439
  std::vector<WCHAR> buffer(BUFSIZE);
@@ -473,7 +473,7 @@ get_description(EVT_HANDLE handle)
473
473
  nullptr,
474
474
  values[0].StringVal,
475
475
  nullptr,
476
- MAKELCID(MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), SORT_DEFAULT),
476
+ MAKELCID(langID, SORT_DEFAULT),
477
477
  0);
478
478
  if (hMetadata == nullptr) {
479
479
  // When winevt_c cannot open metadata, then give up to obtain
@@ -1,3 +1,3 @@
1
1
  module Winevt
2
- VERSION = "0.7.4"
2
+ VERSION = "0.8.0"
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.7.4
4
+ version: 0.8.0
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-05-19 00:00:00.000000000 Z
11
+ date: 2020-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -128,6 +128,7 @@ files:
128
128
  - ext/winevt/winevt_bookmark.c
129
129
  - ext/winevt/winevt_c.h
130
130
  - ext/winevt/winevt_channel.c
131
+ - ext/winevt/winevt_locale.c
131
132
  - ext/winevt/winevt_query.c
132
133
  - ext/winevt/winevt_subscribe.c
133
134
  - ext/winevt/winevt_utils.cpp