Module: PostfixStatusLine::Core

Defined in:
ext/postfix_status_line_core.c

Class Method Summary collapse

Class Method Details

.parse(v_str, v_mask) ⇒ Object



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
# File 'ext/postfix_status_line_core.c', line 190

static VALUE rb_postfix_status_line_parse(VALUE self, VALUE v_str, VALUE v_mask) {
  Check_Type(v_str, T_STRING);

  char *str = RSTRING_PTR(v_str);
  size_t len = RSTRING_LEN(v_str);
  int mask = 1;

  switch (TYPE(v_mask)) {
  case T_FALSE:
  case T_NIL:
    mask = 0;
  }

  if (len < 1) {
    return Qnil;
  }

  char buf[len + 1];
  strncpy(buf, str, len);
  buf[len] = '\0';

  char *time, *hostname, *process, *queue_id, *attrs;

  if (split_line1(buf, &time, &hostname, &process, &queue_id, &attrs) != 0) {
    return Qnil;
  }

  VALUE hash = rb_hash_new();
  rb_hash_aset(hash, rb_str_new2("time"), rb_str_new2(time));
  rb_hash_aset(hash, rb_str_new2("hostname"), rb_str_new2(hostname));
  rb_hash_aset(hash, rb_str_new2("process"), rb_str_new2(process));
  rb_hash_aset(hash, rb_str_new2("queue_id"), rb_str_new2(queue_id));

  split_line2(attrs, mask, hash);

  return hash;
}