Class: Winevt::EventLog::Channel
- Inherits:
-
Object
- Object
- Winevt::EventLog::Channel
- Defined in:
- ext/winevt/winevt_channel.c,
ext/winevt/winevt_channel.c
Overview
Retrieve Windows EventLog channel name.
Instance Method Summary collapse
-
#each {|String| ... } ⇒ Object
Enumerate Windows EventLog channels.
-
#force_enumerate ⇒ Boolean
This method returns whether forcing to enumerate channel which type is Debug and Analytical or not.
-
#force_enumerate=(rb_force_enumerate_p) ⇒ Object
This method specifies whether forcing to enumerate channel which type is Debug and Analytical or not.
-
#initialize ⇒ Channel
constructor
Initalize Channel class.
Constructor Details
#initialize ⇒ Channel
Initalize Channel class.
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'ext/winevt/winevt_channel.c', line 64
static VALUE
rb_winevt_channel_initialize(VALUE self)
{
struct WinevtChannel* winevtChannel;
TypedData_Get_Struct(
self, struct WinevtChannel, &rb_winevt_channel_type, winevtChannel);
winevtChannel->force_enumerate = FALSE;
return Qnil;
}
|
Instance Method Details
#each {|String| ... } ⇒ Object
Enumerate Windows EventLog channels
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
# File 'ext/winevt/winevt_channel.c', line 190
static VALUE
rb_winevt_channel_each(VALUE self)
{
EVT_HANDLE hChannels;
EVT_HANDLE hChannelConfig = NULL;
struct WinevtChannel* winevtChannel;
char errBuf[256];
LPWSTR buffer = NULL;
DWORD bufferSize = 0;
DWORD bufferUsed = 0;
DWORD status = ERROR_SUCCESS;
VALUE utf8str;
RETURN_ENUMERATOR(self, 0, 0);
TypedData_Get_Struct(
self, struct WinevtChannel, &rb_winevt_channel_type, winevtChannel);
hChannels = EvtOpenChannelEnum(NULL, 0);
if (hChannels) {
winevtChannel->channels = hChannels;
} else {
_snprintf_s(errBuf,
_countof(errBuf),
_TRUNCATE,
"Failed to enumerate channels with %lu\n",
GetLastError());
rb_raise(rb_eRuntimeError, errBuf);
}
while (1) {
if (!EvtNextChannelPath(winevtChannel->channels, bufferSize, buffer, &bufferUsed)) {
status = GetLastError();
if (ERROR_NO_MORE_ITEMS == status) {
break;
} else if (ERROR_INSUFFICIENT_BUFFER == status) {
bufferSize = bufferUsed;
buffer = (LPWSTR)malloc(bufferSize * sizeof(WCHAR));
if (buffer) {
continue;
} else {
free(buffer);
EvtClose(winevtChannel->channels);
winevtChannel->channels = NULL;
rb_raise(rb_eRuntimeError, "realloc failed");
}
} else {
free(buffer);
EvtClose(winevtChannel->channels);
winevtChannel->channels = NULL;
_snprintf_s(errBuf,
_countof(errBuf),
_TRUNCATE,
"EvtNextChannelPath failed with %lu.\n",
status);
rb_raise(rb_eRuntimeError, errBuf);
}
}
hChannelConfig = EvtOpenChannelConfig(NULL, buffer, 0);
if (NULL == hChannelConfig) {
_snprintf_s(errBuf,
_countof(errBuf),
_TRUNCATE,
"EvtOpenChannelConfig failed with %lu.\n",
GetLastError());
EvtClose(winevtChannel->channels);
winevtChannel->channels = NULL;
free(buffer);
buffer = NULL;
bufferSize = 0;
rb_raise(rb_eRuntimeError, errBuf);
}
status = is_subscribable_channel_p(hChannelConfig, winevtChannel->force_enumerate);
EvtClose(hChannelConfig);
if (status == ERROR_INVALID_DATA) {
free(buffer);
buffer = NULL;
bufferSize = 0;
continue;
}
if (status == ERROR_OUTOFMEMORY) {
EvtClose(winevtChannel->channels);
winevtChannel->channels = NULL;
free(buffer);
buffer = NULL;
bufferSize = 0;
rb_raise(rb_eRuntimeError, "realloc failed\n");
} else if (status != ERROR_SUCCESS) {
EvtClose(winevtChannel->channels);
winevtChannel->channels = NULL;
free(buffer);
buffer = NULL;
bufferSize = 0;
rb_raise(rb_eRuntimeError, "is_subscribe_channel_p is failed with %ld\n", status);
}
utf8str = wstr_to_rb_str(CP_UTF8, buffer, -1);
free(buffer);
buffer = NULL;
bufferSize = 0;
rb_yield(utf8str);
}
if (winevtChannel->channels) {
EvtClose(winevtChannel->channels);
winevtChannel->channels = NULL;
}
free(buffer);
return Qnil;
}
|
#force_enumerate ⇒ Boolean
This method returns whether forcing to enumerate channel which type is Debug and Analytical or not.
104 105 106 107 108 109 110 111 112 113 |
# File 'ext/winevt/winevt_channel.c', line 104
static VALUE
rb_winevt_channel_get_force_enumerate(VALUE self)
{
struct WinevtChannel* winevtChannel;
TypedData_Get_Struct(
self, struct WinevtChannel, &rb_winevt_channel_type, winevtChannel);
return winevtChannel->force_enumerate ? Qtrue : Qfalse;
}
|
#force_enumerate=(rb_force_enumerate_p) ⇒ Object
This method specifies whether forcing to enumerate channel which type is Debug and Analytical or not.
84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'ext/winevt/winevt_channel.c', line 84
static VALUE
rb_winevt_channel_set_force_enumerate(VALUE self, VALUE rb_force_enumerate_p)
{
struct WinevtChannel* winevtChannel;
TypedData_Get_Struct(
self, struct WinevtChannel, &rb_winevt_channel_type, winevtChannel);
winevtChannel->force_enumerate = RTEST(rb_force_enumerate_p);
return Qnil;
}
|