Esempio n. 1
0
int
mrb_class_defined(mrb_state *mrb, const char *name)
{
  mrb_value sym = mrb_check_intern_cstr(mrb, name);
  if (mrb_nil_p(sym)) {
    return FALSE;
  }
  return mrb_const_defined(mrb, mrb_obj_value(mrb->object_class), mrb_symbol(sym));
}
static int32_t
compare_break_method( mrb_state *mrb, mrb_debug_breakpoint *bp, struct RClass *class_obj, mrb_sym method_sym, mrb_bool* isCfunc )
{
  const char* class_name;
  const char* method_name;
  struct RProc* m;
  struct RClass* sc;
  const char* sn;
  mrb_sym ssym;
  mrb_debug_methodpoint *method_p;
  mrb_bool is_defined;

  method_name = mrb_sym2name(mrb, method_sym);

  method_p = &bp->point.methodpoint;
  if(strcmp(method_p->method_name, method_name) == 0) {
    class_name = get_class_name(mrb, class_obj);
    if(class_name == NULL) {
      if(method_p->class_name == NULL) {
        return bp->bpno;
      }
    }
    else if(method_p->class_name != NULL) {
      m = mrb_method_search_vm(mrb, &class_obj, method_sym);
      if(m == NULL) {
        return MRB_DEBUG_OK;
      }
      if(MRB_PROC_CFUNC_P(m)) {
        *isCfunc = TRUE;
      }

      is_defined = mrb_class_defined(mrb, method_p->class_name);
      if(is_defined == FALSE) {
        return MRB_DEBUG_OK;
      }

      sc = mrb_class_get(mrb, method_p->class_name);
      ssym = mrb_symbol(mrb_check_intern_cstr(mrb, method_p->method_name));
      m = mrb_method_search_vm(mrb, &sc, ssym);
      if(m == NULL) {
        return MRB_DEBUG_OK;
      }

      class_name = get_class_name(mrb, class_obj);
      sn = get_class_name(mrb, sc);
      if(strcmp(sn, class_name) == 0) {
        return bp->bpno;
      }
    }
  }
  return MRB_DEBUG_OK;
}
Esempio n. 3
0
static mrb_value ngx_mrb_add_listener(mrb_state *mrb, mrb_value self)
{
  // ref: http/ngx_http_core_module.c ngx_http_core_listen
  ngx_http_mruby_srv_conf_t *mscf = mrb->ud;
  ngx_http_core_srv_conf_t *cscf = mscf->cscf;
  ngx_conf_t *cf = mscf->cf;
  ngx_str_t addr;
  ngx_url_t u;
  ngx_http_listen_opt_t lsopt;
  mrb_value listener, address;

  mrb_get_args(mrb, "H", &listener);
  address = mrb_hash_get(mrb, listener, mrb_check_intern_cstr(mrb, "address"));
  addr.data = (u_char *)RSTRING_PTR(address);
  addr.len = RSTRING_LEN(address);

  ngx_memzero(&u, sizeof(ngx_url_t));
  u.url = addr;
  u.listen = 1;
  u.default_port = 80;
  cscf->listen = 1;

  if (ngx_parse_url(cf->pool, &u) != NGX_OK) {
    if (u.err) {
      ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s in \"%V\" of the \"listen\" directive via mruby", u.err, &u.url);
    }

    mrb_raise(mrb, E_RUNTIME_ERROR, "ngx_mrb_add_listener ngx_parse_url failed");
  }

  ngx_memzero(&lsopt, sizeof(ngx_http_listen_opt_t));
  ngx_memcpy(&lsopt.sockaddr.sockaddr, &u.sockaddr, u.socklen);

  lsopt.socklen = u.socklen;
  lsopt.backlog = NGX_LISTEN_BACKLOG;
  lsopt.rcvbuf = -1;
  lsopt.sndbuf = -1;
#if (NGX_HAVE_SETFIB)
  lsopt.setfib = -1;
#endif
#if (NGX_HAVE_TCP_FASTOPEN)
  lsopt.fastopen = -1;
#endif
  lsopt.wildcard = u.wildcard;
#if (NGX_HAVE_INET6)
  lsopt.ipv6only = 1;
#endif
  if (mrb_bool(mrb_hash_get(mrb, listener, mrb_check_intern_cstr(mrb, "ssl")))) {
#if (NGX_HTTP_SSL)
    lsopt.ssl = 1;
#else
    mrb_raise(mrb, E_RUNTIME_ERROR, "the ssl symbol requires ngx_http_ssl_module");
#endif
  }

  if (mrb_bool(mrb_hash_get(mrb, listener, mrb_check_intern_cstr(mrb, "http2")))) {
#if (NGX_HTTP_V2)
    lsopt.http2 = 1;
#else
    mrb_raise(mrb, E_RUNTIME_ERROR, "the http2 symbol requires ngx_http_http2_module");
#endif
  }

  (void)ngx_sock_ntop(&lsopt.sockaddr.sockaddr, lsopt.socklen, lsopt.addr, NGX_SOCKADDR_STRLEN, 1);
  if (ngx_http_add_listen(cf, cscf, &lsopt) == NGX_OK) {
    ngx_conf_log_error(NGX_LOG_INFO, cf, 0, "add listener %V via mruby", &addr);
    return mrb_true_value();
  }

  mrb_raise(mrb, E_RUNTIME_ERROR, "ngx_mrb_add_listener ngx_http_add_listen failed");
}