postfix_status_line 0.1.4 → 0.1.5

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
  SHA1:
3
- metadata.gz: 931d2af96a39af0fb8fa223ec41ea3f90eb32237
4
- data.tar.gz: 7d652ef403719f485738635c9c5073a8c4e643ad
3
+ metadata.gz: acb7606470d80a2813ba8d50eaae1daf882731b0
4
+ data.tar.gz: caa4474fdd96b24c0f1bc16e9572a84424023934
5
5
  SHA512:
6
- metadata.gz: 9756a89c6c9f256ea90e408eaf9f7198e7639a17b3dd0f301b633784602dc6fbc616e09c820e9dd91064b1b42ae3f0030514ec624d8d4426663a220f90189469
7
- data.tar.gz: 0eccdae53fab91c7182fc25767fb484f3a84a553390eec59d73acb5ec96d8c21e5f5890438db279dc4cd40ecf08dc9f609ce0c16d8a2b2eefe9985e7837875cd
6
+ metadata.gz: 6360bdf590686caea775f8ff732e65d2d2ea35e7a808bbdf2a2db3d39eaa6cac032f040c9074b3c5ad3275e60849e43cdc27622bb9ea58757b5b59176d90ca36
7
+ data.tar.gz: f5025a3ff875b364ccd48d8deee65fe0bdc59f620ef1265cea3522f405ff5eef45a53051eb10dde869aa25188723ddbe0333834ffd2e2682f7f3fe36cf460317
data/README.md CHANGED
@@ -38,7 +38,7 @@ PostfixStatusLine.parse(status_line)
38
38
  # "relay" => "gateway-f1.isp.att.net[204.127.217.16]:25",
39
39
  # "status" => "sent",
40
40
  # "status_detail" => "(250 ok ; id=20120227140036M0700qer4ne)",
41
- # "time" => "Feb 27 09:02:37",
41
+ # "time" => 1424995357,
42
42
  # "to" => "<*******@bellsouth.net>",
43
43
  # "domain" => "bellsouth.net"
44
44
  # }
@@ -68,14 +68,14 @@ static int split_p1(char *str, char **time, char **hostname, char **process) {
68
68
  return 0;
69
69
  }
70
70
 
71
- static int split_line1(char buf[], char **time, char **hostname, char **process, char **queue_id, char **attrs) {
71
+ static int split_line1(char buf[], char **tm, char **hostname, char **process, char **queue_id, char **attrs) {
72
72
  char *p1, *p2, *p3;
73
73
 
74
74
  if (split3(buf, &p1, &p2, &p3) != 0) {
75
75
  return -1;
76
76
  }
77
77
 
78
- if (split_p1(p1, time, hostname, process) != 0) {
78
+ if (split_p1(p1, tm, hostname, process) != 0) {
79
79
  return -1;
80
80
  }
81
81
 
@@ -187,6 +187,23 @@ static void split_line2(char *str, int mask, VALUE hash) {
187
187
  }
188
188
  }
189
189
 
190
+ static void put_time(char *str, VALUE hash) {
191
+ time_t now = time(NULL);
192
+ struct tm *t = localtime(&now);
193
+
194
+ if (strptime(str, "%b %d %H:%M:%S", t) == NULL) {
195
+ return;
196
+ }
197
+
198
+ time_t epoch = mktime(t);
199
+
200
+ if (epoch == -1) {
201
+ return;
202
+ }
203
+
204
+ rb_hash_aset(hash, rb_str_new2("time"), LONG2NUM(epoch));
205
+ }
206
+
190
207
  static VALUE rb_postfix_status_line_parse(VALUE self, VALUE v_str, VALUE v_mask) {
191
208
  Check_Type(v_str, T_STRING);
192
209
 
@@ -208,14 +225,14 @@ static VALUE rb_postfix_status_line_parse(VALUE self, VALUE v_str, VALUE v_mask)
208
225
  strncpy(buf, str, len);
209
226
  buf[len] = '\0';
210
227
 
211
- char *time, *hostname, *process, *queue_id, *attrs;
228
+ char *tm, *hostname, *process, *queue_id, *attrs;
212
229
 
213
- if (split_line1(buf, &time, &hostname, &process, &queue_id, &attrs) != 0) {
230
+ if (split_line1(buf, &tm, &hostname, &process, &queue_id, &attrs) != 0) {
214
231
  return Qnil;
215
232
  }
216
233
 
217
234
  VALUE hash = rb_hash_new();
218
- rb_hash_aset(hash, rb_str_new2("time"), rb_str_new2(time));
235
+ put_time(tm, hash);
219
236
  rb_hash_aset(hash, rb_str_new2("hostname"), rb_str_new2(hostname));
220
237
  rb_hash_aset(hash, rb_str_new2("process"), rb_str_new2(process));
221
238
  rb_hash_aset(hash, rb_str_new2("queue_id"), rb_str_new2(queue_id));
@@ -1,3 +1,3 @@
1
1
  module PostfixStatusLine
2
- VERSION = '0.1.4'
2
+ VERSION = '0.1.5'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postfix_status_line
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genki Sugawara