Module: PostfixStatusLine::Core

Defined in:
ext/postfix_status_line_core.c

Class Method Summary collapse

Class Method Details

.parse(v_str, v_mask) ⇒ Object



169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'ext/postfix_status_line_core.c', line 169

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;
}