Beispiel #1
0
void rgeo_init_geos_line_string(RGeo_Globals* globals)
{
  VALUE geos_line_string_class = rb_define_class_under(globals->geos_module, "LineStringImpl", globals->geos_geometry);
  globals->geos_line_string = geos_line_string_class;
  globals->feature_line_string = rb_const_get_at(globals->feature_module, rb_intern("LineString"));
  VALUE geos_linear_ring_class = rb_define_class_under(globals->geos_module, "LinearRingImpl", geos_line_string_class);
  globals->geos_linear_ring = geos_linear_ring_class;
  globals->feature_linear_ring = rb_const_get_at(globals->feature_module, rb_intern("LinearRing"));
  VALUE geos_line_class = rb_define_class_under(globals->geos_module, "LineImpl", geos_line_string_class);
  globals->geos_line = geos_line_class;
  globals->feature_line = rb_const_get_at(globals->feature_module, rb_intern("Line"));
  
  rb_define_module_function(geos_line_string_class, "create", cmethod_create_line_string, 2);
  rb_define_module_function(geos_line_string_class, "_copy_from", cmethod_line_string_copy_from, 2);
  rb_define_method(geos_line_string_class, "eql?", method_line_string_eql, 1);
  rb_define_method(geos_line_string_class, "geometry_type", method_line_string_geometry_type, 0);
  rb_define_method(geos_line_string_class, "length", method_line_string_length, 0);
  rb_define_method(geos_line_string_class, "num_points", method_line_string_num_points, 0);
  rb_define_method(geos_line_string_class, "point_n", method_line_string_point_n, 1);
  rb_define_method(geos_line_string_class, "points", method_line_string_points, 0);
  rb_define_method(geos_line_string_class, "start_point", method_line_string_start_point, 0);
  rb_define_method(geos_line_string_class, "end_point", method_line_string_end_point, 0);
  rb_define_method(geos_line_string_class, "is_closed?", method_line_string_is_closed, 0);
  rb_define_method(geos_line_string_class, "is_ring?", method_line_string_is_ring, 0);
  
  rb_define_module_function(geos_linear_ring_class, "create", cmethod_create_linear_ring, 2);
  rb_define_module_function(geos_linear_ring_class, "_copy_from", cmethod_linear_ring_copy_from, 2);
  rb_define_method(geos_linear_ring_class, "geometry_type", method_linear_ring_geometry_type, 0);
  
  rb_define_module_function(geos_line_class, "create", cmethod_create_line, 3);
  rb_define_module_function(geos_line_class, "_copy_from", cmethod_line_copy_from, 2);
  rb_define_method(geos_line_class, "geometry_type", method_line_geometry_type, 0);
}
Beispiel #2
0
/**
 * Make the actual application call, we call the application instance with the
 * method given and pass it ARGV and ENV in that order
 */
VALUE crate_wrap_app( VALUE arg )
{
  crate_app *ca = (crate_app*)arg;
  char *r = "Amalgalite::Requires.new( :dbfile_name => 'lib.db' )\n"\
            "Amalgalite::Requires.new( :dbfile_name => 'app.db' )\n";
  char buf[BUFSIZ];
  char* dot ;

  /* require the class file */

  dot = strchr( ca->file_name, '.');
  if ( NULL != dot ) { *dot = '\0' ; }
  sprintf( buf,"%s\nrequire '%s'", r, ca->file_name);
  rb_eval_string(buf);

  /* get an instance of the application class and pack up the instance and the
   * method 
   */
  ca->app_instance = rb_class_new_instance(0, 0, rb_const_get( rb_cObject, rb_intern( ca->class_name ) ) );
  ca->run_method   = rb_intern( ca->method_name );
 
  return rb_funcall( ca->app_instance, 
                     ca->run_method, 2, 
                     rb_const_get_at( rb_cObject, rb_intern("ARGV") ), 
                     rb_const_get_at( rb_cObject, rb_intern("ENV") ) );
}
void Init_openssl_rsa_pss_verify() {
  fprintf(stderr, "VERSION: %s\n", SSLeay_version(SSLEAY_VERSION));
  rb_mOpenSSL = rb_const_get_at(rb_cObject, rb_intern("OpenSSL"));
  rb_mPKey = rb_const_get_at(rb_mOpenSSL, rb_intern("PKey"));
  rb_cRSA = rb_const_get_at(rb_mPKey, rb_intern("RSA"));
  rb_cRSAError = rb_const_get_at(rb_mPKey, rb_intern("RSAError"));

  rb_define_private_method(rb_cRSA, "__verify_pss_sha1", ORPV__verify_pss_sha1, 4);
}
/* Hook up the ruby methods.  Similar to lua's luaopen_(mod) functions */
void Init_gazelle_ruby_bindings() {
  VALUE Gazelle         = rb_const_get(rb_cObject, rb_intern("Gazelle"));
  VALUE Gazelle_Parser  = rb_const_get_at(Gazelle, rb_intern("Parser"));

  rb_define_method(Gazelle_Parser, "parse?", rb_gazelle_parse_p, 1);
  rb_define_method(Gazelle_Parser, "parse",  rb_gazelle_parse, 1);
}
Beispiel #5
0
VALUE
rb_path2class(const char *path)
{
    const char *pbeg, *p;
    ID id;
    VALUE c = rb_cObject;

    if (path[0] == '#') {
	rb_raise(rb_eArgError, "can't retrieve anonymous class %s", path);
    }
    pbeg = p = path;
    while (*p) {
	while (*p && *p != ':') p++;
	id = rb_intern2(pbeg, p-pbeg);
	if (p[0] == ':') {
	    if (p[1] != ':') goto undefined_class;
	    p += 2;
	    pbeg = p;
	}
	if (!rb_const_defined(c, id)) {
	  undefined_class:
	    rb_raise(rb_eArgError, "undefined class/module %.*s", (int)(p-path), path);
	}
	c = rb_const_get_at(c, id);
	switch (TYPE(c)) {
	  case T_MODULE:
	  case T_CLASS:
	    break;
	  default:
	    rb_raise(rb_eTypeError, "%s does not refer class/module", path);
	}
    }

    return c;
}
Beispiel #6
0
void Init_trenni() {
    id_open_tag_begin = rb_intern("open_tag_begin");
    id_open_tag_end = rb_intern("open_tag_end");
    id_close_tag = rb_intern("close_tag");

    id_cdata = rb_intern("cdata");
    id_attribute = rb_intern("attribute");
    id_comment = rb_intern("comment");
    id_text = rb_intern("text");
    id_doctype = rb_intern("doctype");
    id_instruction = rb_intern("instruction");
    id_expression = rb_intern("expression");

    id_read = rb_intern("read");

    id_key_get = rb_intern("[]");

    rb_Trenni = rb_define_module("Trenni");
    rb_Trenni_Native = rb_define_module_under(rb_Trenni, "Native");

    rb_Trenni_ParseError = rb_const_get_at(rb_Trenni, rb_intern("ParseError"));

    rb_define_module_function(rb_Trenni_Native, "parse_markup", Trenni_Native_parse_markup, 3);
    rb_define_module_function(rb_Trenni_Native, "parse_template", Trenni_Native_parse_template, 2);
}
Beispiel #7
0
VALUE
rb_define_class_under(VALUE outer, const char *name, VALUE super)
{
    VALUE klass;
    ID id;

    id = rb_intern(name);
    if (rb_const_defined_at(outer, id)) {
	klass = rb_const_get_at(outer, id);
	if (TYPE(klass) != T_CLASS) {
	    rb_raise(rb_eTypeError, "%s is not a class", name);
	}
	if (RCLASS_RUBY(klass)) {
	    // Only for pure Ruby classes, as Objective-C classes
	    // might be returned from the dynamic resolver.
	    if (rb_class_real(RCLASS_SUPER(klass), true) != super) {
		rb_name_error(id, "%s is already defined", name);
	    }
	    return klass;
	}
    }
    if (!super) {
	rb_warn("no super class for `%s::%s', Object assumed",
		rb_class2name(outer), name);
    }
    klass = rb_define_class_id(id, super);
    rb_set_class_path(klass, outer, name);
    rb_const_set(outer, id, klass);
    rb_class_inherited(super, klass);

    return klass;
}
Beispiel #8
0
void Init_rcovrt() {
  ID id_rcov = rb_intern("Rcov");
  ID id_coverage__ = rb_intern("RCOV__");
  ID id_script_lines__ = rb_intern("SCRIPT_LINES__");
 
  id_cover = rb_intern("COVER");
  
  if(rb_const_defined(rb_cObject, id_rcov)) 
    mRcov = rb_const_get(rb_cObject, id_rcov);
  else
    mRcov = rb_define_module("Rcov");
  
  if(rb_const_defined(mRcov, id_coverage__))
    mRCOV__ = rb_const_get_at(mRcov, id_coverage__);
  else
    mRCOV__ = rb_define_module_under(mRcov, "RCOV__");
  
  if(rb_const_defined(rb_cObject, id_script_lines__))
    oSCRIPT_LINES__ = rb_const_get(rb_cObject, rb_intern("SCRIPT_LINES__"));
  else {
    oSCRIPT_LINES__ = rb_hash_new();
    rb_const_set(rb_cObject, id_script_lines__, oSCRIPT_LINES__);
  }
  
  coverage_hook_set_p = 0;
  
  rb_define_singleton_method(mRCOV__, "install_coverage_hook", cov_install_coverage_hook, 0);
  rb_define_singleton_method(mRCOV__, "remove_coverage_hook",  cov_remove_coverage_hook, 0);
  rb_define_singleton_method(mRCOV__, "generate_coverage_info", cov_generate_coverage_info, 0);
  rb_define_singleton_method(mRCOV__, "reset_coverage", cov_reset_coverage, 0);
  rb_define_singleton_method(mRCOV__, "ABI", cov_ABI, 0);
  
  Init_rcov_callsite();
}
Beispiel #9
0
static VALUE rb_czmq_ctx_socket(VALUE obj, VALUE type)
{
    VALUE socket;
    int socket_type;
    struct nogvl_socket_args args;
    zmq_sock_wrapper *sock = NULL;
    errno = 0;
    ZmqGetContext(obj);
    if (TYPE(type) != T_FIXNUM && TYPE(type) != T_SYMBOL) rb_raise(rb_eTypeError, "wrong socket type %s (expected Fixnum or Symbol)", RSTRING_PTR(rb_obj_as_string(type)));
    socket_type = FIX2INT((SYMBOL_P(type)) ? rb_const_get_at(rb_mZmq, rb_to_id(type)) : type);

    socket = Data_Make_Struct(rb_czmq_ctx_socket_klass(socket_type), zmq_sock_wrapper, rb_czmq_mark_sock, rb_czmq_free_sock_gc, sock);
    args.ctx = ctx->ctx;
    args.type = socket_type;
    sock->socket = (void*)rb_thread_blocking_region(rb_czmq_nogvl_socket_new, (void *)&args, RUBY_UBF_IO, 0);
    ZmqAssertObjOnAlloc(sock->socket, sock);
#ifndef HAVE_RB_THREAD_BLOCKING_REGION
    sock->str_buffer = zlist_new();
    sock->frame_buffer = zlist_new();
    sock->msg_buffer = zlist_new();
#endif
    sock->handler = Qnil;
    sock->flags = 0;
    sock->ctx = ctx->ctx;
    sock->verbose = FALSE;
    sock->state = ZMQ_SOCKET_PENDING;
    sock->endpoint = Qnil;
    sock->thread = rb_thread_current();
    sock->recv_timeout = ZMQ_SOCKET_DEFAULT_TIMEOUT;
    sock->send_timeout = ZMQ_SOCKET_DEFAULT_TIMEOUT;
    rb_obj_call_init(socket, 0, NULL);
    return socket;
}
Beispiel #10
0
/*!
 * Defines a class under the namespace of \a outer.
 * \param outer  a class which contains the new class.
 * \param id     name of the new class
 * \param super  a class from which the new class will derive.
 *               NULL means \c Object class.
 * \return the created class
 * \throw TypeError if the constant name \a name is already taken but
 *                  the constant is not a \c Class.
 * \throw NameError if the class is already defined but the class can not
 *                  be reopened because its superclass is not \a super.
 * \post top-level constant named \a name refers the returned class.
 *
 * \note if a class named \a name is already defined and its superclass is
 *       \a super, the function just returns the defined class.
 */
VALUE
rb_define_class_id_under(VALUE outer, ID id, VALUE super)
{
    VALUE klass;

    if (rb_const_defined_at(outer, id)) {
	klass = rb_const_get_at(outer, id);
	if (TYPE(klass) != T_CLASS) {
	    rb_raise(rb_eTypeError, "%s is not a class", rb_id2name(id));
	}
	if (rb_class_real(RCLASS_SUPER(klass)) != super) {
	    rb_name_error(id, "%s is already defined", rb_id2name(id));
	}
	return klass;
    }
    if (!super) {
	rb_warn("no super class for `%s::%s', Object assumed",
		rb_class2name(outer), rb_id2name(id));
    }
    klass = rb_define_class_id(id, super);
    rb_set_class_path_string(klass, outer, rb_id2str(id));
    rb_const_set(outer, id, klass);
    rb_class_inherited(super, klass);
    rb_gc_register_mark_object(klass);

    return klass;
}
Beispiel #11
0
VALUE
rb_define_class_under(VALUE outer, const char *name, VALUE super)
{
    VALUE klass;
    ID id;

    id = rb_intern(name);
    if (rb_const_defined_at(outer, id)) {
	klass = rb_const_get_at(outer, id);
	if (TYPE(klass) != T_CLASS) {
	    rb_raise(rb_eTypeError, "%s is not a class", name);
	}
	if (rb_class_real(RCLASS_SUPER(klass)) != super) {
	    rb_name_error(id, "%s is already defined", name);
	}
	return klass;
    }
    if (!super) {
	rb_warn("no super class for `%s::%s', Object assumed",
		rb_class2name(outer), name);
    }
    klass = rb_define_class_id(id, super);
    rb_set_class_path(klass, outer, name);
    rb_const_set(outer, id, klass);
    rb_class_inherited(super, klass);

    return klass;
}
Beispiel #12
0
/*
 * Removes a file or directory, using File.unlink if +self+ is a file, or
 * Dir.unlink as necessary.
 */
static VALUE
path_unlink(VALUE self)
{
    VALUE eENOTDIR = rb_const_get_at(rb_mErrno, rb_intern("ENOTDIR"));
    VALUE str = get_strpath(self);
    return rb_rescue2(unlink_body, str, unlink_rescue, str, eENOTDIR, (VALUE)0);
}
Beispiel #13
0
void
Init_cparse(void)
{
    VALUE Racc, Parser;
    ID id_racc = rb_intern("Racc");

    if (rb_const_defined(rb_cObject, id_racc)) {
        Racc = rb_const_get(rb_cObject, id_racc);
        Parser = rb_const_get_at(Racc, rb_intern("Parser"));
    }
    else {
        Racc = rb_define_module("Racc");
        Parser = rb_define_class_under(Racc, "Parser", rb_cObject);
    }

    rb_define_method(Parser, "initialize", (VALUE(*)(ANYARGS))initialize, 0);

    rb_define_private_method(Parser, "_racc_do_parse_c", racc_cparse, 0);
    rb_define_private_method(Parser, "_racc_yyparse_c", racc_yyparse, 2);
    rb_define_const(Parser, "Racc_Runtime_Core_Version_C",
                    rb_str_new2(RACC_VERSION));
    rb_define_const(Parser, "Racc_Runtime_Core_Id_C",
        rb_str_new2("$originalId: cparse.c,v 1.8 2006/07/06 11:39:46 aamine Exp $"));

    CparseParams = rb_define_class_under(Racc, "CparseParams", rb_cObject);

    RaccBug = rb_eRuntimeError;

    id_yydebug      = rb_intern("@yydebug");
    id_nexttoken    = rb_intern("next_token");
    id_onerror      = rb_intern("on_error");
    id_noreduce     = rb_intern("_reduce_none");
    id_errstatus    = rb_intern("@racc_error_status");

    id_d_shift       = rb_intern("racc_shift");
    id_d_reduce      = rb_intern("racc_reduce");
    id_d_accept      = rb_intern("racc_accept");
    id_d_read_token  = rb_intern("racc_read_token");
    id_d_next_state  = rb_intern("racc_next_state");
    id_d_e_pop       = rb_intern("racc_e_pop");

    id_action_table   = rb_intern("@action_table");
    id_action_check   = rb_intern("@action_check");
    id_action_default = rb_intern("@action_default");
    id_action_pointer = rb_intern("@action_pointer");
    id_goto_table     = rb_intern("@goto_table");
    id_goto_check     = rb_intern("@goto_check");
    id_goto_default   = rb_intern("@goto_default");
    id_goto_pointer   = rb_intern("@goto_pointer");
    id_nt_base        = rb_intern("@nt_base");
    id_reduce_table   = rb_intern("@reduce_table");
    id_token_table    = rb_intern("@token_table");
    id_shift_n        = rb_intern("@shift_n");
    id_reduce_n       = rb_intern("@reduce_n");
    id_use_result     = rb_intern("@use_result");
}
Beispiel #14
0
void Init_cmultibyte() {
  idUnpack = rb_intern("unpack");
  idPack = rb_intern("pack");
  idForceEncoding = rb_intern("force_encoding");

  rb_funcall(rb_cObject, rb_intern("require"), 1, rb_str_new2("active_support/all"));

  ActiveSupport = rb_const_get(rb_cObject, rb_intern("ActiveSupport"));
  Multibyte = rb_const_get_at(ActiveSupport, rb_intern("Multibyte"));
  Unicode = rb_const_get_at(Multibyte, rb_intern("Unicode"));

  VALUE database = rb_funcall(Unicode, rb_intern("database"), 0);
  rb_funcall(database, rb_intern("load"), 0);
  VALUE cp1252_hash = rb_ivar_get(database, rb_intern("@cp1252"));
  cp1252_hash_to_array(cp1252_hash);

  rb_define_singleton_method(Unicode, "tidy_byte", rb_tidy_byte, 1);
  rb_define_singleton_method(Unicode, "tidy_bytes", rb_tidy_bytes, -1);
}
Beispiel #15
0
static VALUE method_factory_write_for_psych(VALUE self, VALUE obj)
{
  RGeo_FactoryData* self_data;
  GEOSContextHandle_t self_context;
  GEOSWKTWriter* wkt_writer;
  const GEOSGeometry* geom;
  VALUE result;
  char* str;
  size_t size;
  char has_3d;
#ifndef RGEO_GEOS_SUPPORTS_SETOUTPUTDIMENSION
  RGeo_Globals* globals;
  VALUE wkt_generator;
#endif

  self_data = RGEO_FACTORY_DATA_PTR(self);
  self_context = self_data->geos_context;
  has_3d = self_data->flags & RGEO_FACTORYFLAGS_SUPPORTS_Z_OR_M;
#ifndef RGEO_GEOS_SUPPORTS_SETOUTPUTDIMENSION
  if (has_3d) {
    globals = self_data->globals;
    wkt_generator = globals->psych_wkt_generator;
    if (NIL_P(wkt_generator)) {
      wkt_generator = rb_funcall(
        rb_const_get_at(globals->geos_module, rb_intern("Utils")),
        rb_intern("psych_wkt_generator"), 0);
      globals->psych_wkt_generator = wkt_generator;
    }
    return rb_funcall(wkt_generator, globals->id_generate, 1, obj);
  }
#endif
  wkt_writer = self_data->psych_wkt_writer;
  if (!wkt_writer) {
    wkt_writer = GEOSWKTWriter_create_r(self_context);
    if (has_3d) {
      GEOSWKTWriter_setOutputDimension_r(self_context, wkt_writer, 3);
    }
    self_data->psych_wkt_writer = wkt_writer;
  }
  result = Qnil;
  if (wkt_writer) {
    geom = rgeo_get_geos_geometry_safe(obj);
    if (geom) {
      str = GEOSWKTWriter_write_r(self_context, wkt_writer, geom);
      if (str) {
        result = rb_str_new2(str);
        GEOSFree_r(self_context, str);
      }
    }
  }
  return result;
}
Beispiel #16
0
/*
 * call-seq:
 *    parser.mark # => #<Psych::Parser::Mark>
 *
 * Returns a Psych::Parser::Mark object that contains line, column, and index
 * information.
 */
static VALUE mark(VALUE self)
{
    VALUE mark_klass;
    VALUE args[3];
    yaml_parser_t * parser;

    Data_Get_Struct(self, yaml_parser_t, parser);
    mark_klass = rb_const_get_at(cPsychParser, rb_intern("Mark"));
    args[0] = INT2NUM(parser->mark.index);
    args[1] = INT2NUM(parser->mark.line);
    args[2] = INT2NUM(parser->mark.column);

    return rb_class_new_instance(3, args, mark_klass);
}
Beispiel #17
0
void
ox_sax_define() {
    VALUE	sax_module = rb_const_get_at(Ox, rb_intern("Sax"));

    ox_sax_value_class = rb_define_class_under(sax_module, "Value", rb_cObject);

    rb_define_method(ox_sax_value_class, "as_s", sax_value_as_s, 0);
    rb_define_method(ox_sax_value_class, "as_sym", sax_value_as_sym, 0);
    rb_define_method(ox_sax_value_class, "as_i", sax_value_as_i, 0);
    rb_define_method(ox_sax_value_class, "as_f", sax_value_as_f, 0);
    rb_define_method(ox_sax_value_class, "as_time", sax_value_as_time, 0);
    rb_define_method(ox_sax_value_class, "as_bool", sax_value_as_bool, 0);
    rb_define_method(ox_sax_value_class, "empty?", sax_value_empty, 0);
}
Beispiel #18
0
void rgeo_init_geos_point(RGeo_Globals* globals)
{
  VALUE geos_point_class = rb_define_class_under(globals->geos_module, "PointImpl", globals->geos_geometry);
  globals->geos_point = geos_point_class;
  globals->feature_point = rb_const_get_at(globals->feature_module, rb_intern("Point"));
  
  rb_define_module_function(geos_point_class, "create", cmethod_create, 4);
  
  rb_define_method(geos_point_class, "eql?", method_point_eql, 1);
  rb_define_method(geos_point_class, "geometry_type", method_point_geometry_type, 0);
  rb_define_method(geos_point_class, "x", method_point_x, 0);
  rb_define_method(geos_point_class, "y", method_point_y, 0);
  rb_define_method(geos_point_class, "z", method_point_z, 0);
  rb_define_method(geos_point_class, "m", method_point_m, 0);
}
Beispiel #19
0
/*
 * call-seq:
 *    parser.external_encoding=(encoding)
 *
 * Set the encoding for this parser to +encoding+
 */
static VALUE set_external_encoding(VALUE self, VALUE encoding)
{
    yaml_parser_t * parser;
    VALUE exception;

    Data_Get_Struct(self, yaml_parser_t, parser);

    if(parser->encoding) {
	exception = rb_const_get_at(mPsych, rb_intern("Exception"));
	rb_raise(exception, "don't set the encoding twice!");
    }

    yaml_parser_set_encoding(parser, NUM2INT(encoding));

    return encoding;
}
Beispiel #20
0
VALUE
rb_define_module_under(VALUE outer, const char *name)
{
    ID id = rb_intern(name);
    if (rb_const_defined_at(outer, id)) {
	VALUE module = rb_const_get_at(outer, id);
	if (TYPE(module) == T_MODULE) {
	    return module;
	}
	rb_raise(rb_eTypeError, "%s::%s:%s is not a module",
		 rb_class2name(outer), name, rb_obj_classname(module));
    }
    VALUE module = rb_define_module_id(id);
    rb_const_set(outer, id, module);
    rb_set_class_path(module, outer, name);
    return module;
}
Beispiel #21
0
void rgeo_init_geos_polygon(RGeo_Globals* globals)
{
  VALUE geos_polygon_class = rb_define_class_under(globals->geos_module, "PolygonImpl", globals->geos_geometry);
  globals->geos_polygon = geos_polygon_class;
  globals->feature_polygon = rb_const_get_at(globals->feature_module, rb_intern("Polygon"));
  
  rb_define_module_function(geos_polygon_class, "create", cmethod_create, 3);
  
  rb_define_method(geos_polygon_class, "eql?", method_polygon_eql, 1);
  rb_define_method(geos_polygon_class, "geometry_type", method_polygon_geometry_type, 0);
  rb_define_method(geos_polygon_class, "area", method_polygon_area, 0);
  rb_define_method(geos_polygon_class, "centroid", method_polygon_centroid, 0);
  rb_define_method(geos_polygon_class, "point_on_surface", method_polygon_point_on_surface, 0);
  rb_define_method(geos_polygon_class, "exterior_ring", method_polygon_exterior_ring, 0);
  rb_define_method(geos_polygon_class, "num_interior_rings", method_polygon_num_interior_rings, 0);
  rb_define_method(geos_polygon_class, "interior_ring_n", method_polygon_interior_ring_n, 1);
  rb_define_method(geos_polygon_class, "interior_rings", method_polygon_interior_rings, 0);
}
Beispiel #22
0
void rgeo_init_geos_geometry(RGeo_Globals* globals)
{
  VALUE geos_geometry_class = rb_define_class_under(globals->geos_module, "GeometryImpl", rb_cObject);
  globals->geos_geometry = geos_geometry_class;
  globals->feature_geometry = rb_const_get_at(globals->feature_module, rb_intern("Geometry"));
  
  rb_define_alloc_func(geos_geometry_class, alloc_geometry);
  rb_define_method(geos_geometry_class, "_set_factory", method_geometry_set_factory, 1);
  rb_define_method(geos_geometry_class, "initialize_copy", method_geometry_initialize_copy, 1);
  rb_define_method(geos_geometry_class, "initialized?", method_geometry_initialized_p, 0);
  rb_define_method(geos_geometry_class, "factory", method_geometry_factory, 0);
  rb_define_method(geos_geometry_class, "dimension", method_geometry_dimension, 0);
  rb_define_method(geos_geometry_class, "geometry_type", method_geometry_geometry_type, 0);
  rb_define_method(geos_geometry_class, "srid", method_geometry_srid, 0);
  rb_define_method(geos_geometry_class, "envelope", method_geometry_envelope, 0);
  rb_define_method(geos_geometry_class, "boundary", method_geometry_boundary, 0);
  rb_define_method(geos_geometry_class, "as_text", method_geometry_as_text, 0);
  rb_define_method(geos_geometry_class, "to_s", method_geometry_as_text, 0);
  rb_define_method(geos_geometry_class, "as_binary", method_geometry_as_binary, 0);
  rb_define_method(geos_geometry_class, "is_empty?", method_geometry_is_empty, 0);
  rb_define_method(geos_geometry_class, "is_simple?", method_geometry_is_simple, 0);
  rb_define_method(geos_geometry_class, "equals?", method_geometry_equals, 1);
  rb_define_method(geos_geometry_class, "==", method_geometry_equals, 1);
  rb_define_method(geos_geometry_class, "eql?", method_geometry_eql, 1);
  rb_define_method(geos_geometry_class, "disjoint?", method_geometry_disjoint, 1);
  rb_define_method(geos_geometry_class, "intersects?", method_geometry_intersects, 1);
  rb_define_method(geos_geometry_class, "touches?", method_geometry_touches, 1);
  rb_define_method(geos_geometry_class, "crosses?", method_geometry_crosses, 1);
  rb_define_method(geos_geometry_class, "within?", method_geometry_within, 1);
  rb_define_method(geos_geometry_class, "contains?", method_geometry_contains, 1);
  rb_define_method(geos_geometry_class, "overlaps?", method_geometry_overlaps, 1);
  rb_define_method(geos_geometry_class, "relate?", method_geometry_relate, 2);
  rb_define_method(geos_geometry_class, "distance", method_geometry_distance, 1);
  rb_define_method(geos_geometry_class, "buffer", method_geometry_buffer, 1);
  rb_define_method(geos_geometry_class, "convex_hull", method_geometry_convex_hull, 0);
  rb_define_method(geos_geometry_class, "intersection", method_geometry_intersection, 1);
  rb_define_method(geos_geometry_class, "*", method_geometry_intersection, 1);
  rb_define_method(geos_geometry_class, "union", method_geometry_union, 1);
  rb_define_method(geos_geometry_class, "+", method_geometry_union, 1);
  rb_define_method(geos_geometry_class, "difference", method_geometry_difference, 1);
  rb_define_method(geos_geometry_class, "-", method_geometry_difference, 1);
  rb_define_method(geos_geometry_class, "sym_difference", method_geometry_sym_difference, 1);
}
Beispiel #23
0
VALUE
rb_define_module_id_under(VALUE outer, ID id)
{
    VALUE module;

    if (rb_const_defined_at(outer, id)) {
	module = rb_const_get_at(outer, id);
	if (TYPE(module) == T_MODULE)
	    return module;
	rb_raise(rb_eTypeError, "%s::%s is not a module",
		 rb_class2name(outer), rb_obj_classname(module));
    }
    module = rb_define_module_id(id);
    rb_const_set(outer, id, module);
    rb_set_class_path_string(module, outer, rb_id2str(id));
    rb_gc_register_mark_object(module);

    return module;
}
Beispiel #24
0
static VALUE cmethod_factory_create(VALUE klass, VALUE flags, VALUE srid, VALUE buffer_resolution,
  VALUE wkt_generator, VALUE wkb_generator, VALUE proj4_obj, VALUE coord_sys_obj)
{
  VALUE result;
  RGeo_FactoryData* data;
  GEOSContextHandle_t context;
  VALUE wrapped_globals;

  result = Qnil;
  data = ALLOC(RGeo_FactoryData);
  if (data) {
    context = initGEOS_r(message_handler, message_handler);
    if (context) {
      wrapped_globals = rb_const_get_at(klass, rb_intern("INTERNAL_CGLOBALS"));
      data->globals = (RGeo_Globals*)DATA_PTR(wrapped_globals);
      data->geos_context = context;
      data->flags = NUM2INT(flags);
      data->srid = NUM2INT(srid);
      data->buffer_resolution = NUM2INT(buffer_resolution);
      data->wkt_reader = NULL;
      data->wkb_reader = NULL;
      data->wkt_writer = NULL;
      data->wkb_writer = NULL;
      data->psych_wkt_reader = NULL;
      data->marshal_wkb_reader = NULL;
      data->psych_wkt_writer = NULL;
      data->marshal_wkb_writer = NULL;
      data->wkrep_wkt_generator = wkt_generator;
      data->wkrep_wkb_generator = wkb_generator;
      data->wkrep_wkt_parser = Qnil;
      data->wkrep_wkb_parser = Qnil;
      data->proj4_obj = proj4_obj;
      data->coord_sys_obj = coord_sys_obj;
      result = Data_Wrap_Struct(klass, mark_factory_func, destroy_factory_func, data);
    }
    else {
      free(data);
    }
  }
  return result;
}
Beispiel #25
0
VALUE
rb_path_to_class(VALUE pathname)
{
    rb_encoding *enc = rb_enc_get(pathname);
    const char *pbeg, *p, *path = RSTRING_PTR(pathname);
    ID id;
    VALUE c = rb_cObject;

    if (!rb_enc_asciicompat(enc)) {
	rb_raise(rb_eArgError, "invalid class path encoding (non ASCII)");
    }
    pbeg = p = path;
    if (path[0] == '#') {
	rb_raise(rb_eArgError, "can't retrieve anonymous class %s", path);
    }
    while (*p) {
	while (*p && *p != ':') p++;
	id = rb_intern3(pbeg, p-pbeg, enc);
	if (p[0] == ':') {
	    if (p[1] != ':') goto undefined_class;
	    p += 2;
	    pbeg = p;
	}
	if (!rb_const_defined(c, id)) {
	  undefined_class:
	    rb_raise(rb_eArgError, "undefined class/module %.*s", (int)(p-path), path);
	}
	c = rb_const_get_at(c, id);
	switch (TYPE(c)) {
	  case T_MODULE:
	  case T_CLASS:
	    break;
	  default:
	    rb_raise(rb_eTypeError, "%s does not refer to class/module", path);
	}
    }

    return c;
}
Beispiel #26
0
RGeo_Globals* rgeo_init_geos_factory()
{
  RGeo_Globals* globals;
  VALUE rgeo_module;
  VALUE geos_factory_class;
  VALUE wrapped_globals;
  VALUE feature_module;

  globals = ALLOC(RGeo_Globals);

  // Cache some modules so we don't have to look them up by name every time
  rgeo_module = rb_define_module("RGeo");
  feature_module = rb_define_module_under(rgeo_module, "Feature");
  globals->feature_module = feature_module;
  globals->geos_module = rb_define_module_under(rgeo_module, "Geos");
  globals->feature_geometry = rb_const_get_at(feature_module, rb_intern("Geometry"));
  globals->feature_point = rb_const_get_at(feature_module, rb_intern("Point"));
  globals->feature_line_string = rb_const_get_at(feature_module, rb_intern("LineString"));
  globals->feature_linear_ring = rb_const_get_at(feature_module, rb_intern("LinearRing"));
  globals->feature_line = rb_const_get_at(feature_module, rb_intern("Line"));
  globals->feature_polygon = rb_const_get_at(feature_module, rb_intern("Polygon"));
  globals->feature_geometry_collection = rb_const_get_at(feature_module, rb_intern("GeometryCollection"));
  globals->feature_multi_point = rb_const_get_at(feature_module, rb_intern("MultiPoint"));
  globals->feature_multi_line_string = rb_const_get_at(feature_module, rb_intern("MultiLineString"));
  globals->feature_multi_polygon = rb_const_get_at(feature_module, rb_intern("MultiPolygon"));

  // Cache some commonly used names
  globals->id_cast = rb_intern("cast");
  globals->id_eql = rb_intern("eql?");
  globals->id_generate = rb_intern("generate");
  globals->id_enum_for = rb_intern("enum_for");
  globals->id_hash = rb_intern("hash");
  globals->sym_force_new = ID2SYM(rb_intern("force_new"));
  globals->sym_keep_subtype = ID2SYM(rb_intern("keep_subtype"));
#ifndef RGEO_GEOS_SUPPORTS_SETOUTPUTDIMENSION
  globals->psych_wkt_generator = Qnil;
  globals->marshal_wkb_generator = Qnil;
#endif

  // Add C methods to the factory.
  geos_factory_class = rb_define_class_under(globals->geos_module, "CAPIFactory", rb_cObject);
  rb_define_alloc_func(geos_factory_class, alloc_factory);
  rb_define_method(geos_factory_class, "initialize_copy", method_factory_initialize_copy, 1);
  rb_define_method(geos_factory_class, "_parse_wkt_impl", method_factory_parse_wkt, 1);
  rb_define_method(geos_factory_class, "_parse_wkb_impl", method_factory_parse_wkb, 1);
  rb_define_method(geos_factory_class, "_srid", method_factory_srid, 0);
  rb_define_method(geos_factory_class, "_buffer_resolution", method_factory_buffer_resolution, 0);
  rb_define_method(geos_factory_class, "_flags", method_factory_flags, 0);
  rb_define_method(geos_factory_class, "_set_wkrep_parsers", method_set_wkrep_parsers, 2);
  rb_define_method(geos_factory_class, "_proj4", method_get_proj4, 0);
  rb_define_method(geos_factory_class, "_coord_sys", method_get_coord_sys, 0);
  rb_define_method(geos_factory_class, "_wkt_generator", method_get_wkt_generator, 0);
  rb_define_method(geos_factory_class, "_wkb_generator", method_get_wkb_generator, 0);
  rb_define_method(geos_factory_class, "_wkt_parser", method_get_wkt_parser, 0);
  rb_define_method(geos_factory_class, "_wkb_parser", method_get_wkb_parser, 0);
  rb_define_method(geos_factory_class, "_read_for_marshal", method_factory_read_for_marshal, 1);
  rb_define_method(geos_factory_class, "_write_for_marshal", method_factory_write_for_marshal, 1);
  rb_define_method(geos_factory_class, "_read_for_psych", method_factory_read_for_psych, 1);
  rb_define_method(geos_factory_class, "_write_for_psych", method_factory_write_for_psych, 1);
  rb_define_module_function(geos_factory_class, "_create", cmethod_factory_create, 7);
  rb_define_module_function(geos_factory_class, "_geos_version", cmethod_factory_geos_version, 0);

  // Pre-define implementation classes and set up allocation methods
  globals->geos_geometry = rb_define_class_under(globals->geos_module, "CAPIGeometryImpl", rb_cObject);
  rb_define_alloc_func(globals->geos_geometry, alloc_geometry);
  globals->geos_point = rb_define_class_under(globals->geos_module, "CAPIPointImpl", rb_cObject);
  rb_define_alloc_func(globals->geos_point, alloc_geometry);
  globals->geos_line_string = rb_define_class_under(globals->geos_module, "CAPILineStringImpl", rb_cObject);
  rb_define_alloc_func(globals->geos_line_string, alloc_geometry);
  globals->geos_linear_ring = rb_define_class_under(globals->geos_module, "CAPILinearRingImpl", rb_cObject);
  rb_define_alloc_func(globals->geos_linear_ring, alloc_geometry);
  globals->geos_line = rb_define_class_under(globals->geos_module, "CAPILineImpl", rb_cObject);
  rb_define_alloc_func(globals->geos_line, alloc_geometry);
  globals->geos_polygon = rb_define_class_under(globals->geos_module, "CAPIPolygonImpl", rb_cObject);
  rb_define_alloc_func(globals->geos_polygon, alloc_geometry);
  globals->geos_geometry_collection = rb_define_class_under(globals->geos_module, "CAPIGeometryCollectionImpl", rb_cObject);
  rb_define_alloc_func(globals->geos_geometry_collection, alloc_geometry);
  globals->geos_multi_point = rb_define_class_under(globals->geos_module, "CAPIMultiPointImpl", rb_cObject);
  rb_define_alloc_func(globals->geos_multi_point, alloc_geometry);
  globals->geos_multi_line_string = rb_define_class_under(globals->geos_module, "CAPIMultiLineStringImpl", rb_cObject);
  rb_define_alloc_func(globals->geos_multi_line_string, alloc_geometry);
  globals->geos_multi_polygon = rb_define_class_under(globals->geos_module, "CAPIMultiPolygonImpl", rb_cObject);
  rb_define_alloc_func(globals->geos_multi_polygon, alloc_geometry);

  // Wrap the globals in a Ruby object and store it off so we have access
  // to it later. Each factory instance will reference it internally.
  wrapped_globals = Data_Wrap_Struct(rb_cObject, mark_globals_func, destroy_globals_func, globals);
  rb_define_const(geos_factory_class, "INTERNAL_CGLOBALS", wrapped_globals);

  return globals;
}
static VALUE ORPV__verify_pss_sha1(VALUE self, VALUE vPubKey, VALUE vSig, VALUE vHashData, VALUE vSaltLen) {
  enum ORPV_errors err = OK;

  BIO * pkey_bio = NULL;
  RSA * rsa_pub_key = NULL;
  EVP_PKEY * pkey = NULL;
  EVP_PKEY_CTX * pkey_ctx = NULL;
  char * pub_key = NULL;
  
  int verify_rval = -1, salt_len;
  char ossl_err_strs[(OSSL_ERR_STR_LEN + 2) * ORPV_MAX_ERRS] = "";

  if (ERR_peek_error()) {
    err = EXTERNAL;
    goto Cleanup;
  }

  vPubKey = StringValue(vPubKey);
  vSig = StringValue(vSig);
  vHashData = StringValue(vHashData);
  salt_len = NUM2INT(vSaltLen);

  if (RSTRING_LEN(vPubKey) > (long)INT_MAX) {
    err = KEY_OVERFLOW;
    goto Cleanup;
  }

  pub_key = malloc(RSTRING_LEN(vPubKey));
  if (! pub_key) {
    err = NOMEM;
    goto Cleanup;
  }
  memcpy(pub_key, StringValuePtr(vPubKey), RSTRING_LEN(vPubKey));

  pkey_bio = BIO_new_mem_buf(pub_key, (int)RSTRING_LEN(vPubKey));
  rsa_pub_key = PEM_read_bio_RSA_PUBKEY(pkey_bio, NULL, NULL, NULL);
  if (! rsa_pub_key) {
    err = PUBKEY_PARSE;
    goto Cleanup;
  }

  pkey = EVP_PKEY_new();
  if (! pkey) {
    err = PKEY_INIT;
    goto Cleanup;
  }

  if (! EVP_PKEY_set1_RSA(pkey, rsa_pub_key)) {
    err = RSA_ASSIGN;
    goto Cleanup;
  }

  pkey_ctx = EVP_PKEY_CTX_new(pkey, ENGINE_get_default_RSA());
  if (! pkey_ctx) {
    err = PKEY_CTX_INIT;
    goto Cleanup;
  }

  if (EVP_PKEY_verify_init(pkey_ctx) <= 0) {
    err = VERIFY_INIT;
    goto Cleanup;
  }

  if (EVP_PKEY_CTX_set_signature_md(pkey_ctx, EVP_sha1()) <= 0) {
    err = SET_SIG_MD;
    goto Cleanup;
  }

  if (EVP_PKEY_CTX_set_rsa_padding(pkey_ctx, RSA_PKCS1_PSS_PADDING) <= 0) {
    err = SET_PADDING;
    goto Cleanup;
  }

  if (EVP_PKEY_CTX_set_rsa_pss_saltlen(pkey_ctx, salt_len) <= 0) {
    err = SET_SALTLEN;
    goto Cleanup;
  }

  verify_rval = EVP_PKEY_verify(pkey_ctx, 
                                (unsigned char*)StringValuePtr(vSig), (size_t)RSTRING_LEN(vSig), 
                                (unsigned char*)StringValuePtr(vHashData), (size_t)RSTRING_LEN(vHashData));

Cleanup:
  /*
   * BIO * pkey_bio = NULL;
   * RSA * rsa_pub_key = NULL;
   * EVP_PKEY * pkey = NULL;
   * EVP_PKEY_CTX * pkey_ctx = NULL;
   * char * pub_key = NULL;
   */
  if (pkey_ctx) EVP_PKEY_CTX_free(pkey_ctx);
  if (pkey) EVP_PKEY_free(pkey);
  if (rsa_pub_key) RSA_free(rsa_pub_key);
  if (pkey_bio) BIO_free(pkey_bio);
  if (pub_key) free(pub_key);

  switch (err) {
    case OK:
      switch (verify_rval) {
        case 1:
          return Qtrue;
        case 0:
          return Qfalse;
        default:
          bind_err_strs(ossl_err_strs, ORPV_MAX_ERRS);
          rb_raise(rb_cRSAError, "An error occurred during validation.\n%s", ossl_err_strs);
      }
      break;

    case EXTERNAL:
      bind_err_strs(ossl_err_strs, ORPV_MAX_ERRS);
      rb_raise(rb_eRuntimeError, "OpenSSL was in an error state prior to invoking this verification.\n%s", ossl_err_strs);
      break;
    case KEY_OVERFLOW:
      rb_raise(rb_cRSAError, "Your public key is too big. How is that even possible?");
      break;
    case NOMEM:
      rb_raise(rb_const_get_at(rb_mErrno, rb_intern("ENOMEM")), "Insufficient memory to allocate pubkey copy. Woof.");
      break;
    case PUBKEY_PARSE:
      bind_err_strs(ossl_err_strs, ORPV_MAX_ERRS);
      rb_raise(rb_cRSAError, "Error parsing public key\n%s", ossl_err_strs);
      break;
    case PKEY_INIT:
      bind_err_strs(ossl_err_strs, ORPV_MAX_ERRS);
      rb_raise(rb_cRSAError, "Failed to initialize PKEY\n%s", ossl_err_strs);
      break;
    case RSA_ASSIGN:
      bind_err_strs(ossl_err_strs, ORPV_MAX_ERRS);
      rb_raise(rb_cRSAError, "Failed to assign RSA object to PKEY\n%s", ossl_err_strs);
      break;
    case PKEY_CTX_INIT:
      bind_err_strs(ossl_err_strs, ORPV_MAX_ERRS);
      rb_raise(rb_cRSAError, "Failed to initialize PKEY context.\n%s", ossl_err_strs);
      break;
    case VERIFY_INIT:
      bind_err_strs(ossl_err_strs, ORPV_MAX_ERRS);
      rb_raise(rb_cRSAError, "Failed to initialize verification process.\n%s", ossl_err_strs);
      break;
    case SET_SIG_MD:
      bind_err_strs(ossl_err_strs, ORPV_MAX_ERRS);
      rb_raise(rb_cRSAError, "Failed to set signature message digest to SHA1.\n%s", ossl_err_strs);
      break;
    case SET_PADDING:
      bind_err_strs(ossl_err_strs, ORPV_MAX_ERRS);
      rb_raise(rb_cRSAError, "Failed to set PSS padding.\n%s", ossl_err_strs);
      break;
    case SET_SALTLEN:
      bind_err_strs(ossl_err_strs, ORPV_MAX_ERRS);
      rb_raise(rb_cRSAError, "Failed to set salt length.\n%s", ossl_err_strs);
      break;
    default:
      bind_err_strs(ossl_err_strs, ORPV_MAX_ERRS);
      rb_raise(rb_eRuntimeError, "Something has gone horribly wrong.\n%s", ossl_err_strs);
  }

  return Qnil;
}
Beispiel #28
0
static VALUE module_specs_const_get_at(VALUE self, VALUE klass, VALUE val) {
  return rb_const_get_at(klass, SYM2ID(val));
}