postfix_status_line 0.2.6 → 0.2.7

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
  SHA1:
3
- metadata.gz: 789a0f356de63f37d382c9df9bc2e52cc3410ccf
4
- data.tar.gz: 515db09f1244be59e58c9f3cccd947ff6e07dc47
3
+ metadata.gz: 94a439a7c52803281aed989326452482635a1a51
4
+ data.tar.gz: 879309fe801021f6ca9405d3f999b3787f1a0626
5
5
  SHA512:
6
- metadata.gz: ff4a32767875dade98f09c49589b7de5c28a4673139cef350d66b769b59e2643209fcf71b4f1fb588c1ecdf47042ee72542a032ea624e04dfba710f5ec48ab4e
7
- data.tar.gz: f9a4cacfb6a05e7a38740e70cd60126fe147ece783bbbbe7f1db93b5f154292d24074e0ae4cedef4037608e201217853e7599929d8431ce7b39206c6f461b3d6
6
+ metadata.gz: 92907958f1605d908366b9d032f8a8b98ded4175f5b6dfdc35dd5f08f0829b2df2586d76d2e5fa50c4e8e2d8fcf0d9815294e6f0733dda30ab5f28ada1ee7cfd
7
+ data.tar.gz: c58b95c85fe2b700e4c69027cb5c99205db1e8dda75a02a992dfabb1b049ce5428f271f4dd52e82e6e5819f5cc4401610496516960a96846cbbb16e1544be5be
data/.travis.yml CHANGED
@@ -1,9 +1,10 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 2.0.0
4
- - 2.1
5
- - 2.2
6
- - 2.3.0
4
+ - 2.1.10
5
+ - 2.2.6
6
+ - 2.3.3
7
+ - 2.4.0
7
8
  before_install:
8
9
  - gem update bundler
9
10
  before_script:
data/README.md CHANGED
@@ -63,6 +63,26 @@ PostfixStatusLine.parse(status_line, hash: true, sha_algorithm: 256)
63
63
  PostfixStatusLine.parse(status_line, parse_time: true)
64
64
  ```
65
65
 
66
+ ### Parse Header Checks Warning
67
+
68
+ see http://www.postfix.org/header_checks.5.html
69
+
70
+ ```ruby
71
+ warning = "Mar 4 14:44:19 P788 postfix/cleanup[7426]: E80A9DF6F7E: warning: header Subject: test from local; from=<sugawara@P788.local> to=<sgwr_dts@yahoo.co.jp>"
72
+
73
+ PostfixStatusLine.parse_header_checks_warning(warning)
74
+ # => {
75
+ # "time"=>"Mar 4 14:44:19",
76
+ # "hostname"=>"P788",
77
+ # "process"=>"postfix/cleanup[7426]",
78
+ # "queue_id"=>"E80A9DF6F7E",
79
+ # "to"=>"********@yahoo.co.jp",
80
+ # "domain"=>"yahoo.co.jp",
81
+ # "from"=>"********@P788.local",
82
+ # "Subject"=>"test from local;"
83
+ # }
84
+ ```
85
+
66
86
  ## Benchmark (on EC2/t2.micro)
67
87
 
68
88
  ### Script
@@ -273,6 +273,52 @@ static void split_line2(char *str, bool mask, VALUE hash, bool include_hash, cha
273
273
  }
274
274
  }
275
275
 
276
+ static void put_header(char *str, VALUE hash, bool mask) {
277
+ if (strncmp(str, "warning: header ", 16) != 0) {
278
+ return;
279
+ }
280
+
281
+ str += 16;
282
+ char *value = strchr(str, ':');
283
+
284
+ if (value == NULL || *(value + 1) == '\0') {
285
+ return;
286
+ }
287
+
288
+ if (mask) {
289
+ mask_email(value);
290
+ }
291
+
292
+ *value = '\0';
293
+ value += 2;
294
+
295
+ VALUE v_key = rb_str_new2(str);
296
+ VALUE v_value = rb_str_new2(value);
297
+ rb_hash_aset(hash, v_key, v_value);
298
+ }
299
+
300
+ static void split_line3(char *str, bool mask, VALUE hash, bool include_hash, char *salt, size_t salt_len, DIGEST_SHA digest_sha_func) {
301
+ char *ptr = str;
302
+ size_t len = strlen(str);
303
+ int i;
304
+
305
+ for (i = (int) len - 1; i >= 0; i--) {
306
+ if (ptr[i] == ' ') {
307
+ char *chunk = ptr + i + 1;
308
+
309
+ if (strncmp(chunk, "to=", 3) == 0) {
310
+ put_attr(chunk, hash, mask, include_hash, salt, salt_len, digest_sha_func);
311
+ ptr[i] = '\0';
312
+ } else if (strncmp(chunk, "from=", 5) == 0) {
313
+ put_attr(chunk, hash, mask, include_hash, salt, salt_len, digest_sha_func);
314
+ ptr[i] = '\0';
315
+ put_header(ptr, hash, mask);
316
+ break;
317
+ }
318
+ }
319
+ }
320
+ }
321
+
276
322
  static int get_year() {
277
323
  time_t now = time(NULL);
278
324
 
@@ -315,78 +361,82 @@ static void put_epoch(char *time_str, VALUE hash) {
315
361
  rb_hash_aset(hash, rb_str_new2("epoch"), LONG2NUM(ts));
316
362
  }
317
363
 
318
- static VALUE rb_postfix_status_line_parse(VALUE self, VALUE v_str, VALUE v_mask, VALUE v_hash, VALUE v_salt, VALUE v_parse_time, VALUE v_sha_algo) {
364
+ static bool parse_init(
365
+ VALUE v_str, VALUE v_mask, VALUE v_parse_time, VALUE v_hash, VALUE v_salt, VALUE v_sha_algo,
366
+ char **str, size_t *len, bool *mask, bool *parse_time, bool *include_hash, char **salt, size_t *salt_len, int *sha_algo, DIGEST_SHA *digest_sha_func) {
319
367
  Check_Type(v_str, T_STRING);
368
+ *str = RSTRING_PTR(v_str);
369
+ *len = RSTRING_LEN(v_str);
320
370
 
321
- char *str = RSTRING_PTR(v_str);
322
- size_t len = RSTRING_LEN(v_str);
323
-
324
- if (len < 1) {
325
- return Qnil;
371
+ if (*len < 1) {
372
+ return false;
326
373
  }
327
374
 
328
- bool mask = rb_value_to_bool(v_mask);
329
- bool parse_time = rb_value_to_bool(v_parse_time);
375
+ *mask = rb_value_to_bool(v_mask);
376
+ *parse_time = rb_value_to_bool(v_parse_time);
330
377
 
331
- bool include_hash = false;
332
- char *salt = NULL;
333
- size_t salt_len = -1;
378
+ *include_hash = false;
379
+ *salt = NULL;
380
+ *salt_len = -1;
334
381
 
335
382
  if (rb_value_to_bool(v_hash)) {
336
383
  #ifdef HAVE_OPENSSL_SHA_H
337
- include_hash = true;
384
+ *include_hash = true;
338
385
 
339
386
  if (!NIL_P(v_salt)) {
340
387
  Check_Type(v_salt, T_STRING);
341
- salt = RSTRING_PTR(v_salt);
342
- salt_len = RSTRING_LEN(v_salt);
388
+ *salt = RSTRING_PTR(v_salt);
389
+ *salt_len = RSTRING_LEN(v_salt);
343
390
  }
344
391
  #else
345
392
  rb_raise(rb_eArgError, "OpenSSL is not linked");
346
393
  #endif // HAVE_OPENSSL_SHA_H
347
394
  }
348
395
 
349
- int sha_algo = 512;
396
+ *sha_algo = 512;
350
397
 
351
398
  if (!NIL_P(v_sha_algo)) {
352
399
  #ifdef HAVE_OPENSSL_SHA_H
353
- sha_algo = NUM2INT(v_sha_algo);
400
+ *sha_algo = NUM2INT(v_sha_algo);
354
401
  #else
355
402
  rb_raise(rb_eArgError, "OpenSSL is not linked");
356
403
  #endif // HAVE_OPENSSL_SHA_H
357
404
  }
358
405
 
359
- DIGEST_SHA digest_sha_func = NULL;
406
+ *digest_sha_func = NULL;
360
407
 
361
408
  #ifdef HAVE_OPENSSL_SHA_H
362
- switch (sha_algo) {
409
+ switch (*sha_algo) {
363
410
  case 1:
364
- digest_sha_func = digest_sha1;
411
+ *digest_sha_func = digest_sha1;
365
412
  break;
366
413
  case 224:
367
- digest_sha_func = digest_sha224;
414
+ *digest_sha_func = digest_sha224;
368
415
  break;
369
416
  case 256:
370
- digest_sha_func = digest_sha256;
417
+ *digest_sha_func = digest_sha256;
371
418
  break;
372
419
  case 384:
373
- digest_sha_func = digest_sha384;
420
+ *digest_sha_func = digest_sha384;
374
421
  break;
375
422
  case 512:
376
- digest_sha_func = digest_sha512;
423
+ *digest_sha_func = digest_sha512;
377
424
  break;
378
425
  default:
379
426
  rb_raise(rb_eArgError, "Invalid SHA algorithm");
380
427
  }
381
428
  #endif // HAVE_OPENSSL_SHA_H
382
429
 
383
- char buf[len + 1];
430
+ return true;
431
+ }
432
+
433
+ static VALUE pre_parse(char *str, size_t len, char *buf, bool parse_time, char **attrs) {
384
434
  strncpy(buf, str, len);
385
435
  buf[len] = '\0';
386
436
 
387
- char *tm, *hostname, *process, *queue_id, *attrs;
437
+ char *tm, *hostname, *process, *queue_id;
388
438
 
389
- if (!split_line1(buf, &tm, &hostname, &process, &queue_id, &attrs)) {
439
+ if (!split_line1(buf, &tm, &hostname, &process, &queue_id, attrs)) {
390
440
  return Qnil;
391
441
  }
392
442
 
@@ -400,13 +450,72 @@ static VALUE rb_postfix_status_line_parse(VALUE self, VALUE v_str, VALUE v_mask,
400
450
  put_epoch(tm, hash);
401
451
  }
402
452
 
453
+ return hash;
454
+ }
455
+
456
+ static VALUE rb_postfix_status_line_parse(VALUE self, VALUE v_str, VALUE v_mask, VALUE v_hash, VALUE v_salt, VALUE v_parse_time, VALUE v_sha_algo) {
457
+ char *str;
458
+ size_t len;
459
+ bool mask;
460
+ bool parse_time;
461
+ bool include_hash;
462
+ char *salt;
463
+ size_t salt_len;
464
+ int sha_algo;
465
+ DIGEST_SHA digest_sha_func;
466
+
467
+ if (!parse_init(v_str, v_mask, v_parse_time, v_hash, v_salt, v_sha_algo,
468
+ &str, &len, &mask, &parse_time, &include_hash, &salt, &salt_len, &sha_algo, &digest_sha_func)) {
469
+ return Qnil;
470
+ }
471
+
472
+ char buf[len + 1];
473
+ char *attrs;
474
+
475
+ VALUE hash = pre_parse(str, len, buf, parse_time, &attrs);
476
+
477
+ if (NIL_P(hash)) {
478
+ return Qnil;
479
+ }
480
+
403
481
  split_line2(attrs, mask, hash, include_hash, salt, salt_len, digest_sha_func);
404
482
 
405
483
  return hash;
406
484
  }
407
485
 
486
+ static VALUE rb_postfix_status_line_parse_header_checks_warning(VALUE self, VALUE v_str, VALUE v_mask, VALUE v_hash, VALUE v_salt, VALUE v_parse_time, VALUE v_sha_algo) {
487
+ char *str;
488
+ size_t len;
489
+ bool mask;
490
+ bool parse_time;
491
+ bool include_hash;
492
+ char *salt;
493
+ size_t salt_len;
494
+ int sha_algo;
495
+ DIGEST_SHA digest_sha_func;
496
+
497
+ if (!parse_init(v_str, v_mask, v_parse_time, v_hash, v_salt, v_sha_algo,
498
+ &str, &len, &mask, &parse_time, &include_hash, &salt, &salt_len, &sha_algo, &digest_sha_func)) {
499
+ return Qnil;
500
+ }
501
+
502
+ char buf[len + 1];
503
+ char *attrs;
504
+
505
+ VALUE hash = pre_parse(str, len, buf, parse_time, &attrs);
506
+
507
+ if (NIL_P(hash)) {
508
+ return Qnil;
509
+ }
510
+
511
+ split_line3(attrs, mask, hash, include_hash, salt, salt_len, digest_sha_func);
512
+
513
+ return hash;
514
+ }
515
+
408
516
  void Init_postfix_status_line_core() {
409
517
  VALUE rb_mPostfixStatusLine = rb_define_module("PostfixStatusLine");
410
518
  VALUE rb_mPostfixStatusLineCore = rb_define_module_under(rb_mPostfixStatusLine, "Core");
411
519
  rb_define_module_function(rb_mPostfixStatusLineCore, "parse", rb_postfix_status_line_parse, 6);
520
+ rb_define_module_function(rb_mPostfixStatusLineCore, "parse_header_checks_warning", rb_postfix_status_line_parse_header_checks_warning, 6);
412
521
  }
@@ -1,3 +1,3 @@
1
1
  module PostfixStatusLine
2
- VERSION = '0.2.6'
2
+ VERSION = '0.2.7'
3
3
  end
@@ -13,4 +13,14 @@ module PostfixStatusLine
13
13
  PostfixStatusLine::Core.parse(str, mask, hash, salt, parse_time, sha_algo)
14
14
  end
15
15
  module_function :parse
16
+
17
+ def parse_header_checks_warning(str, options = {})
18
+ mask = options.has_key?(:mask) ? options[:mask] : true
19
+ hash = options[:hash]
20
+ salt = options[:salt]
21
+ parse_time = options[:parse_time]
22
+ sha_algo = options[:sha_algorithm]
23
+ PostfixStatusLine::Core.parse_header_checks_warning(str, mask, hash, salt, parse_time, sha_algo)
24
+ end
25
+ module_function :parse_header_checks_warning
16
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postfix_status_line
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genki Sugawara
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-01-23 00:00:00.000000000 Z
11
+ date: 2017-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -90,7 +90,6 @@ files:
90
90
  - lib/postfix_status_line.rb
91
91
  - lib/postfix_status_line/version.rb
92
92
  - postfix_status_line.gemspec
93
- - test.txt
94
93
  homepage: https://github.com/winebarrel/postfix_status_line
95
94
  licenses:
96
95
  - MIT
data/test.txt DELETED
File without changes