本文整理汇总了C++中rb_secure函数的典型用法代码示例。如果您正苦于以下问题:C++ rb_secure函数的具体用法?C++ rb_secure怎么用?C++ rb_secure使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rb_secure函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: check_dirname
static void
check_dirname(volatile VALUE *dir)
{
char *path, *pend;
rb_secure(2);
FilePathValue(*dir);
path = RSTRING_PTR(*dir);
if (path && *(pend = rb_path_end(rb_path_skip_prefix(path)))) {
*dir = rb_str_new(path, pend - path);
}
}
示例2: bsock_setsockopt
/*
* Document-method: setsockopt
* call-seq:
* setsockopt(level, optname, optval)
* setsockopt(socketoption)
*
* Sets a socket option. These are protocol and system specific, see your
* local system documentation for details.
*
* === Parameters
* * +level+ is an integer, usually one of the SOL_ constants such as
* Socket::SOL_SOCKET, or a protocol level.
* A string or symbol of the name, possibly without prefix, is also
* accepted.
* * +optname+ is an integer, usually one of the SO_ constants, such
* as Socket::SO_REUSEADDR.
* A string or symbol of the name, possibly without prefix, is also
* accepted.
* * +optval+ is the value of the option, it is passed to the underlying
* setsockopt() as a pointer to a certain number of bytes. How this is
* done depends on the type:
* - Fixnum: value is assigned to an int, and a pointer to the int is
* passed, with length of sizeof(int).
* - true or false: 1 or 0 (respectively) is assigned to an int, and the
* int is passed as for a Fixnum. Note that +false+ must be passed,
* not +nil+.
* - String: the string's data and length is passed to the socket.
* * +socketoption+ is an instance of Socket::Option
*
* === Examples
*
* Some socket options are integers with boolean values, in this case
* #setsockopt could be called like this:
* sock.setsockopt(:SOCKET, :REUSEADDR, true)
* sock.setsockopt(Socket::SOL_SOCKET,Socket::SO_REUSEADDR, true)
* sock.setsockopt(Socket::Option.bool(:INET, :SOCKET, :REUSEADDR, true))
*
* Some socket options are integers with numeric values, in this case
* #setsockopt could be called like this:
* sock.setsockopt(:IP, :TTL, 255)
* sock.setsockopt(Socket::IPPROTO_IP, Socket::IP_TTL, 255)
* sock.setsockopt(Socket::Option.int(:INET, :IP, :TTL, 255))
*
* Option values may be structs. Passing them can be complex as it involves
* examining your system headers to determine the correct definition. An
* example is an +ip_mreq+, which may be defined in your system headers as:
* struct ip_mreq {
* struct in_addr imr_multiaddr;
* struct in_addr imr_interface;
* };
*
* In this case #setsockopt could be called like this:
* optval = IPAddr.new("224.0.0.251").hton +
* IPAddr.new(Socket::INADDR_ANY, Socket::AF_INET).hton
* sock.setsockopt(Socket::IPPROTO_IP, Socket::IP_ADD_MEMBERSHIP, optval)
*
*/
static VALUE
bsock_setsockopt(int argc, VALUE *argv, VALUE sock)
{
UNRUBBY_SOCKET_HACK;
VALUE lev, optname, val;
int family, level, option;
rb_io_t *fptr;
int i;
char *v;
int vlen;
if (argc == 1) {
lev = rb_funcall(argv[0], rb_intern("level"), 0);
optname = rb_funcall(argv[0], rb_intern("optname"), 0);
val = rb_funcall(argv[0], rb_intern("data"), 0);
}
else {
rb_scan_args(argc, argv, "30", &lev, &optname, &val);
}
rb_secure(2);
GetOpenFile(sock, fptr);
family = rsock_getfamily(fptr->fd);
level = rsock_level_arg(family, lev);
option = rsock_optname_arg(family, level, optname);
switch (TYPE(val)) {
case T_FIXNUM:
i = FIX2INT(val);
goto numval;
case T_FALSE:
i = 0;
goto numval;
case T_TRUE:
i = 1;
numval:
v = (char*)&i; vlen = (int)sizeof(i);
break;
default:
StringValue(val);
v = RSTRING_PTR(val);
vlen = RSTRING_LENINT(val);
break;
//.........这里部分代码省略.........
示例3: env_size
static VALUE
env_size(VALUE rcv, SEL sel)
{
rb_secure(4);
char **env = GET_ENVIRON();
int i = 0;
while (env[i] != NULL) {
i++;
}
return INT2FIX(i);
}
示例4: fcgi_stream_write
static VALUE fcgi_stream_write(VALUE self, VALUE str)
{
FCGX_Stream *stream;
int len;
rb_secure(4);
Data_Get_Struct(self, FCGX_Stream, stream);
str = rb_obj_as_string(str);
len = FCGX_PutStr(RSTRING_PTR(str), RSTRING_LEN(str), stream);
if (len == EOF) CHECK_STREAM_ERROR(stream);
return INT2NUM(len);
}
示例5: dir_s_getwd
/*
* call-seq:
* Dir.getwd => string
* Dir.pwd => string
*
* Returns the path to the current working directory of this process as
* a string.
*
* Dir.chdir("/tmp") #=> 0
* Dir.getwd #=> "/tmp"
*/
static VALUE
dir_s_getwd(VALUE dir)
{
char *path;
VALUE cwd;
rb_secure(4);
path = my_getcwd();
cwd = rb_tainted_str_new2(path);
xfree(path);
return cwd;
}
示例6: Surface_s_load
static VALUE Surface_s_load(VALUE klass, VALUE filename)
{
SDL_Surface *surface;
rb_secure(4);
ExportFilenameStringValue(filename);
surface = IMG_Load(RSTRING_PTR(filename));
if(surface == NULL)
rb_raise(eSDLError,"Couldn't load %s: %s",
RSTRING_PTR(filename), SDL_GetError());
return Surface_create(surface);
}
示例7: env_has_key
static VALUE
env_has_key(VALUE env, SEL sel, VALUE key)
{
rb_secure(4);
const char *s = StringValuePtr(key);
if (strlen(s) != RSTRING_LEN(key)) {
rb_raise(rb_eArgError, "bad environment variable name");
}
if (getenv(s) != NULL) {
return Qtrue;
}
return Qfalse;
}
示例8: __rho_compile
static VALUE
__rho_compile( VALUE obj, VALUE src)
{
VALUE result;
rb_thread_t *th = GET_THREAD();
rb_secure(1);
th->parse_in_eval++;
result = rb_iseq_compile(src, rb_str_new2("(eval)"), INT2FIX(1));
th->parse_in_eval--;
return result;
}
示例9: rb_undef
void
rb_undef(VALUE klass, ID id)
{
VALUE origin;
NODE *body;
if (rb_vm_cbase() == rb_cObject && klass == rb_cObject) {
rb_secure(4);
}
if (rb_safe_level() >= 4 && !OBJ_TAINTED(klass)) {
rb_raise(rb_eSecurityError, "Insecure: can't undef `%s'",
rb_id2name(id));
}
rb_frozen_class_p(klass);
if (id == object_id || id == __send__ || id == idInitialize) {
rb_warn("undefining `%s' may cause serious problem", rb_id2name(id));
}
body = search_method(klass, id, &origin);
if (!body || !body->nd_body) {
const char *s0 = " class";
VALUE c = klass;
if (FL_TEST(c, FL_SINGLETON)) {
VALUE obj = rb_iv_get(klass, "__attached__");
switch (TYPE(obj)) {
case T_MODULE:
case T_CLASS:
c = obj;
s0 = "";
}
}
else if (TYPE(c) == T_MODULE) {
s0 = " module";
}
rb_name_error(id, "undefined method `%s' for%s `%s'",
rb_id2name(id), s0, rb_class2name(c));
}
rb_add_method(klass, id, 0, NOEX_PUBLIC);
if (FL_TEST(klass, FL_SINGLETON)) {
rb_funcall(rb_iv_get(klass, "__attached__"),
singleton_undefined, 1, ID2SYM(id));
}
else {
rb_funcall(klass, undefined, 1, ID2SYM(id));
}
}
示例10: bsock_do_not_reverse_lookup_set
/*
* call-seq:
* basicsocket.do_not_reverse_lookup = bool
*
* Sets the do_not_reverse_lookup flag of _basicsocket_.
*
* BasicSocket.do_not_reverse_lookup = false
* p TCPSocket.new("127.0.0.1", 80).do_not_reverse_lookup #=> false
* BasicSocket.do_not_reverse_lookup = true
* p TCPSocket.new("127.0.0.1", 80).do_not_reverse_lookup #=> true
*
*/
static VALUE
bsock_do_not_reverse_lookup_set(VALUE sock, VALUE state)
{
rb_io_t *fptr;
rb_secure(4);
GetOpenFile(sock, fptr);
if (RTEST(state)) {
fptr->mode |= FMODE_NOREVLOOKUP;
}
else {
fptr->mode &= ~FMODE_NOREVLOOKUP;
}
return sock;
}
示例11: etc_getgrnam
/* Returns information about the group with specified String name, as found
* in /etc/group.
*
* The information is returned as a Struct::Group; see getgrent above for
* details.
*
* e.g. Etc.getgrnam('users') -> #<struct Struct::Group name="users",
* passwd="x", gid=100, mem=["meta", "root"]>
*
*/
static VALUE
etc_getgrnam(VALUE obj, VALUE nam)
{
#ifdef HAVE_GETGRENT
struct group *grp;
rb_secure(4);
SafeStringValue(nam);
grp = getgrnam(RSTRING_PTR(nam));
if (grp == 0) rb_raise(rb_eArgError, "can't find group for %s", RSTRING_PTR(nam));
return setup_group(grp);
#else
return Qnil;
#endif
}
示例12: top_include
static VALUE
top_include(VALUE self, SEL sel, int argc, VALUE *argv)
{
#if 0
rb_thread_t *th = GET_THREAD();
rb_secure(4);
if (th->top_wrapper) {
rb_warning
("main#include in the wrapped load is effective only in wrapper module");
return rb_mod_include(argc, argv, th->top_wrapper);
}
#endif
return rb_mod_include(rb_cObject, 0, argc, argv);
}
示例13: env_assoc
static VALUE
env_assoc(VALUE env, SEL sel, VALUE key)
{
rb_secure(4);
const char *s = StringValuePtr(key);
if (strlen(s) != RSTRING_LEN(key)) {
rb_raise(rb_eArgError, "bad environment variable name");
}
const char *e = getenv(s);
if (e != NULL) {
return rb_assoc_new(key, rb_tainted_str_new2(e));
}
return Qnil;
}
示例14: rb_dlptr_new2
VALUE
rb_dlptr_new2(VALUE klass, void *ptr, long size, freefunc_t func)
{
struct ptr_data *data;
VALUE val;
rb_secure(4);
val = TypedData_Make_Struct(klass, struct ptr_data, &dlptr_data_type, data);
data->ptr = ptr;
data->free = func;
data->size = size;
OBJ_TAINT(val);
return val;
}
示例15: udp_connect
/*
* call-seq:
* udpsocket.connect(host, port) => 0
*
* Connects _udpsocket_ to _host_:_port_.
*
* This makes possible to send without destination address.
*
* u1 = UDPSocket.new
* u1.bind("127.0.0.1", 4913)
* u2 = UDPSocket.new
* u2.connect("127.0.0.1", 4913)
* u2.send "uuuu", 0
* p u1.recvfrom(10) #=> ["uuuu", ["AF_INET", 33230, "localhost", "127.0.0.1"]]
*
*/
static VALUE
udp_connect(VALUE sock, VALUE host, VALUE port)
{
rb_io_t *fptr;
struct udp_arg arg;
VALUE ret;
rb_secure(3);
arg.res = rsock_addrinfo(host, port, SOCK_DGRAM, 0);
GetOpenFile(sock, fptr);
arg.fd = fptr->fd;
ret = rb_ensure(udp_connect_internal, (VALUE)&arg,
rsock_freeaddrinfo, (VALUE)arg.res);
if (!ret) rsock_sys_fail_host_port("connect(2)", host, port);
return INT2FIX(0);
}