/*
 * call-seq:
 *    conn.notifies()
 *
 * Returns a hash of the unprocessed notifications.
 * If there is no unprocessed notifier, it returns +nil+.
 */
static VALUE
pgconn_notifies(VALUE self)
{
    PGconn* conn = get_pgconn(self);
    PGnotify *notification;
    VALUE hash;
    VALUE sym_relname, sym_be_pid, sym_extra;
    VALUE relname, be_pid, extra;

    sym_relname = ID2SYM(rb_intern("relname"));
    sym_be_pid = ID2SYM(rb_intern("be_pid"));
    sym_extra = ID2SYM(rb_intern("extra"));

    notification = PQnotifies(conn);
    if (notification == NULL) {
        return Qnil;
    }

    hash = rb_hash_new();
    relname = rb_tainted_str_new2(notification->relname);
    be_pid = INT2NUM(notification->be_pid);
    extra = rb_tainted_str_new2(PGNOTIFY_EXTRA(notification));

    rb_hash_aset(hash, sym_relname, relname);
    rb_hash_aset(hash, sym_be_pid, be_pid);
    rb_hash_aset(hash, sym_extra, extra);

    PQfreemem(notification);
    return hash;
}