/* * call-seq: * digest_obj.inspect -> string * * Creates a printable version of the digest object. */ static VALUE rb_digest_instance_inspect(VALUE self) { VALUE str; size_t digest_len = 32; /* about this size at least */ const char *cname; cname = rb_obj_classname(self); /* #<Digest::ClassName: xxxxx...xxxx> */ str = rb_str_buf_new(2 + strlen(cname) + 2 + digest_len * 2 + 1); rb_str_buf_cat2(str, "#<"); rb_str_buf_cat2(str, cname); rb_str_buf_cat2(str, ": "); rb_str_buf_append(str, rb_digest_instance_hexdigest(0, 0, self)); rb_str_buf_cat2(str, ">"); return str; }
static int hash_to_json_i(VALUE key, VALUE value, VALUE buf) { VALUE tmp; if (key == Qundef) return ST_CONTINUE; if (RSTRING_LEN(buf) > 1) rb_str_buf_cat2(buf, ","); tmp = rb_funcall(rb_funcall(key, i_to_s, 0), i_to_json, 0); Check_Type(tmp, T_STRING); rb_str_buf_append(buf, tmp); OBJ_INFECT(buf, tmp); rb_str_buf_cat2(buf, ":"); tmp = rb_funcall(value, i_to_json, 0); Check_Type(tmp, T_STRING); rb_str_buf_append(buf, tmp); OBJ_INFECT(buf, tmp); return ST_CONTINUE; }
inline static VALUE mHash_json_transfrom(VALUE self, VALUE Vstate, VALUE Vdepth) { long depth, len = RHASH_SIZE(self); VALUE result; GET_STATE(Vstate); depth = 1 + FIX2LONG(Vdepth); result = rb_str_buf_new(len); state->memo = result; state->depth = LONG2FIX(depth); state->flag = 0; rb_str_buf_cat2(result, "{"); if (RSTRING_LEN(state->object_nl)) rb_str_buf_append(result, state->object_nl); rb_hash_foreach(self, hash_to_json_state_i, Vstate); if (RSTRING_LEN(state->object_nl)) rb_str_buf_append(result, state->object_nl); if (RSTRING_LEN(state->object_nl)) { rb_str_buf_append(result, rb_str_times(state->indent, Vdepth)); } rb_str_buf_cat2(result, "}"); return result; }
/* * call-seq: to_json(state = nil, depth = 0) * * Returns a JSON string containing a JSON array, that is unparsed from * this Array instance. * _state_ is a JSON::State object, that can also be used to configure the * produced JSON string output further. * _depth_ is used to find out nesting depth, to indent accordingly. */ static VALUE mArray_to_json(int argc, VALUE *argv, VALUE self) { VALUE Vstate, Vdepth, result; rb_scan_args(argc, argv, "02", &Vstate, &Vdepth); if (NIL_P(Vstate)) { long i, len = RARRAY_LEN(self); result = rb_str_buf_new(2 + 2 * len); rb_str_buf_cat2(result, "["); for (i = 0; i < len; i++) { VALUE element = RARRAY_PTR(self)[i]; OBJ_INFECT(result, element); if (i > 0) rb_str_buf_cat2(result, ","); rb_str_buf_append(result, rb_funcall(element, i_to_json, 0)); } rb_str_buf_cat2(result, "]"); } else { result = mArray_json_transfrom(self, Vstate, Vdepth); } OBJ_INFECT(result, self); return result; }
static VALUE inspect_hash(VALUE hash, VALUE dummy, int recur) { if (recur) { return rb_usascii_str_new2("{...}"); } VALUE str = rb_str_buf_new2("{"); rhash_foreach(hash, inspect_i, str); rb_str_buf_cat2(str, "}"); OBJ_INFECT(str, hash); return str; }
/* * call-seq: * conn.transaction( ser = nil, ro = nil) { |conn| ... } * * Open and close a transaction block. The isolation level will be * 'serializable' if +ser+ is true, else 'repeatable read'. * +ro+ means 'read only'. * * (In C++ terms, +ro+ is const, and +ser+ is not volatile.) * */ VALUE pgconn_transaction( int argc, VALUE *argv, VALUE self) { struct pgconn_data *c; VALUE ser, ro; VALUE cmd; int p; rb_scan_args( argc, argv, "02", &ser, &ro); cmd = rb_str_buf_new2( "begin"); p = 0; if (!NIL_P( ser)) { rb_str_buf_cat2( cmd, " isolation level "); rb_str_buf_cat2( cmd, RTEST(ser) ? "serializable" : "read committed"); p++; } if (!NIL_P( ro)) { if (p) rb_str_buf_cat2( cmd, ","); rb_str_buf_cat2( cmd, " read "); rb_str_buf_cat2( cmd, (RTEST(ro) ? "only" : "write")); } rb_str_buf_cat2( cmd, ";"); Data_Get_Struct( self, struct pgconn_data, c); if (PQtransactionStatus( c->conn) > PQTRANS_IDLE) rb_raise( rb_ePgConnTrans, "Nested transaction block. Use Conn#subtransaction."); pgresult_clear( pg_statement_exec( self, cmd, Qnil)); return rb_ensure( yield_transaction, self, commit_transaction, self); }
static VALUE attrs_inspect (VALUE self) { VALUE ret; ret = rb_str_new2 ("{"); rb_iterate (rb_each, self, attrs_inspect_cb, ret); rb_str_buf_cat2 (ret, "}"); OBJ_INFECT (ret, self); return ret; }
VALUE rollback_subtransaction( VALUE ary) { VALUE cmd; cmd = rb_str_buf_new2( "rollback to savepoint "); rb_str_buf_append( cmd, rb_ary_entry( ary, 1)); rb_str_buf_cat2( cmd, ";"); pgresult_clear( pg_statement_exec( rb_ary_entry( ary, 0), cmd, Qnil)); rb_ary_store( ary, 1, Qnil); rb_exc_raise( RB_ERRINFO); return Qnil; }
static VALUE append_method(VALUE obj, VALUE str, ID default_method, VALUE default_args) { VALUE method, eargs; method = rb_attr_get(obj, id_method); if (method != Qfalse) { ID mid = default_method; if (!NIL_P(method)) { Check_Type(method, T_SYMBOL); mid = SYM2ID(method); } rb_str_buf_cat2(str, ":"); rb_str_buf_append(str, rb_id2str(mid)); } eargs = rb_attr_get(obj, id_arguments); if (NIL_P(eargs)) { eargs = default_args; } if (eargs != Qfalse) { long argc = RARRAY_LEN(eargs); VALUE *argv = RARRAY_PTR(eargs); if (argc > 0) { rb_str_buf_cat2(str, "("); while (argc--) { VALUE arg = *argv++; rb_str_append(str, rb_inspect(arg)); rb_str_buf_cat2(str, argc > 0 ? ", " : ")"); OBJ_INFECT(str, arg); } } } return str; }
VALUE release_subtransaction( VALUE ary) { VALUE cmd; VALUE n; n = rb_ary_entry( ary, 1); if (!NIL_P( n)) { cmd = rb_str_buf_new2( "release savepoint "); rb_str_buf_append( cmd, n); rb_str_buf_cat2( cmd, ";"); pgresult_clear( pg_statement_exec( rb_ary_entry( ary, 0), cmd, Qnil)); } return Qnil; }
static int inspect_i(VALUE key, VALUE value, VALUE str) { if (key != Qundef) { if (RSTRING_LEN(str) > 1) { rb_str_cat2(str, ", "); } VALUE str2 = rb_inspect(key); rb_str_buf_append(str, str2); rb_str_buf_cat2(str, "=>"); str2 = rb_inspect(value); rb_str_buf_append(str, str2); } return ST_CONTINUE; }
static void printP(int argc, VALUE *argv, const char *convMethod, const char *sep) { VALUE dispString = rb_str_buf_new(128); ID conv = rb_intern(convMethod); for (int i = 0; i < argc; ++i) { VALUE str = rb_funcall2(argv[i], conv, 0, NULL); rb_str_buf_append(dispString, str); if (i < argc) rb_str_buf_cat2(dispString, sep); } showMsg(RSTRING_PTR(dispString)); }
static VALUE method_inspect(VALUE method) { struct METHOD *data; VALUE str; const char *s; char *sharp = "#"; Data_Get_Struct(method, struct METHOD, data); str = rb_str_buf_new2("#<"); s = rb_obj_classname(method); rb_str_buf_cat2(str, s); rb_str_buf_cat2(str, ": "); if (FL_TEST(data->klass, FL_SINGLETON)) { VALUE v = rb_iv_get(data->klass, "__attached__"); if (data->recv == Qundef) { rb_str_buf_append(str, rb_inspect(data->klass)); } else if (data->recv == v) { rb_str_buf_append(str, rb_inspect(v)); sharp = "."; } else { rb_str_buf_append(str, rb_inspect(data->recv)); rb_str_buf_cat2(str, "("); rb_str_buf_append(str, rb_inspect(v)); rb_str_buf_cat2(str, ")"); sharp = "."; } } else { rb_str_buf_cat2(str, rb_class2name(data->rklass)); if (data->rklass != data->klass) { rb_str_buf_cat2(str, "("); rb_str_buf_cat2(str, rb_class2name(data->klass)); rb_str_buf_cat2(str, ")"); } } rb_str_buf_cat2(str, sharp); rb_str_buf_cat2(str, rb_id2name(data->oid)); rb_str_buf_cat2(str, ">"); return str; }
/* Helper to convert return code from libcouchbase to meaningful exception. * Returns nil if the code considering successful and exception object * otherwise. Store given string to exceptions as message, and also * initialize +error+ attribute with given return code. */ VALUE cb_check_error_with_status(lcb_error_t rc, const char *msg, VALUE key, lcb_http_status_t status) { VALUE klass, exc, str; char buf[300]; if ((rc == LCB_SUCCESS && (status == 0 || status / 100 == 2)) || rc == LCB_AUTH_CONTINUE) { return Qnil; } switch (rc) { case LCB_AUTH_ERROR: klass = cb_eAuthError; break; case LCB_DELTA_BADVAL: klass = cb_eDeltaBadvalError; break; case LCB_E2BIG: klass = cb_eTooBigError; break; case LCB_EBUSY: klass = cb_eBusyError; break; case LCB_EINTERNAL: klass = cb_eInternalError; break; case LCB_EINVAL: klass = cb_eInvalidError; break; case LCB_ENOMEM: klass = cb_eNoMemoryError; break; case LCB_ERANGE: klass = cb_eRangeError; break; case LCB_ETMPFAIL: klass = cb_eTmpFailError; break; case LCB_KEY_EEXISTS: klass = cb_eKeyExistsError; break; case LCB_KEY_ENOENT: klass = cb_eNotFoundError; break; case LCB_DLOPEN_FAILED: klass = cb_eDlopenFailedError; break; case LCB_DLSYM_FAILED: klass = cb_eDlsymFailedError; break; case LCB_NETWORK_ERROR: klass = cb_eNetworkError; break; case LCB_NOT_MY_VBUCKET: klass = cb_eNotMyVbucketError; break; case LCB_NOT_STORED: klass = cb_eNotStoredError; break; case LCB_NOT_SUPPORTED: klass = cb_eNotSupportedError; break; case LCB_UNKNOWN_COMMAND: klass = cb_eUnknownCommandError; break; case LCB_UNKNOWN_HOST: klass = cb_eUnknownHostError; break; case LCB_PROTOCOL_ERROR: klass = cb_eProtocolError; break; case LCB_ETIMEDOUT: klass = cb_eTimeoutError; break; case LCB_CONNECT_ERROR: klass = cb_eConnectError; break; case LCB_BUCKET_ENOENT: klass = cb_eBucketNotFoundError; break; case LCB_CLIENT_ENOMEM: klass = cb_eClientNoMemoryError; break; case LCB_CLIENT_ETMPFAIL: klass = cb_eClientTmpFailError; break; case LCB_EBADHANDLE: klass = cb_eBadHandleError; break; case LCB_ERROR: /* fall through */ default: klass = cb_eLibcouchbaseError; } str = rb_str_buf_new2(msg ? msg : ""); rb_str_buf_cat2(str, " ("); if (key != Qnil) { snprintf(buf, 300, "key=\"%s\", ", RSTRING_PTR(key)); rb_str_buf_cat2(str, buf); } if (status > 0) { const char *reason = NULL; klass = cb_eHTTPError; snprintf(buf, 300, "status=\"%d\"", status); rb_str_buf_cat2(str, buf); switch (status) { case LCB_HTTP_STATUS_BAD_REQUEST: reason = " (Bad Request)"; break; case LCB_HTTP_STATUS_UNAUTHORIZED: reason = " (Unauthorized)"; break; case LCB_HTTP_STATUS_PAYMENT_REQUIRED: reason = " (Payment Required)"; break; case LCB_HTTP_STATUS_FORBIDDEN: reason = " (Forbidden)"; break; case LCB_HTTP_STATUS_NOT_FOUND: reason = " (Not Found)"; break; case LCB_HTTP_STATUS_METHOD_NOT_ALLOWED: reason = " (Method Not Allowed)"; break; case LCB_HTTP_STATUS_NOT_ACCEPTABLE: reason = " (Not Acceptable)"; break; case LCB_HTTP_STATUS_PROXY_AUTHENTICATION_REQUIRED: reason = " (Proxy Authentication Required)"; break; case LCB_HTTP_STATUS_REQUEST_TIMEOUT: reason = " (Request Timeout)"; break; case LCB_HTTP_STATUS_CONFLICT: reason = " (Conflict)"; break; case LCB_HTTP_STATUS_GONE: reason = " (Gone)"; break; case LCB_HTTP_STATUS_LENGTH_REQUIRED: reason = " (Length Required)"; break; case LCB_HTTP_STATUS_PRECONDITION_FAILED: reason = " (Precondition Failed)"; break; case LCB_HTTP_STATUS_REQUEST_ENTITY_TOO_LARGE: reason = " (Request Entity Too Large)"; break; case LCB_HTTP_STATUS_REQUEST_URI_TOO_LONG: reason = " (Request Uri Too Long)"; break; case LCB_HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE: reason = " (Unsupported Media Type)"; break; case LCB_HTTP_STATUS_REQUESTED_RANGE_NOT_SATISFIABLE: reason = " (Requested Range Not Satisfiable)"; break; case LCB_HTTP_STATUS_EXPECTATION_FAILED: reason = " (Expectation Failed)"; break; case LCB_HTTP_STATUS_UNPROCESSABLE_ENTITY: reason = " (Unprocessable Entity)"; break; case LCB_HTTP_STATUS_LOCKED: reason = " (Locked)"; break; case LCB_HTTP_STATUS_FAILED_DEPENDENCY: reason = " (Failed Dependency)"; break; case LCB_HTTP_STATUS_INTERNAL_SERVER_ERROR: reason = " (Internal Server Error)"; break; case LCB_HTTP_STATUS_NOT_IMPLEMENTED: reason = " (Not Implemented)"; break; case LCB_HTTP_STATUS_BAD_GATEWAY: reason = " (Bad Gateway)"; break; case LCB_HTTP_STATUS_SERVICE_UNAVAILABLE: reason = " (Service Unavailable)"; break; case LCB_HTTP_STATUS_GATEWAY_TIMEOUT: reason = " (Gateway Timeout)"; break; case LCB_HTTP_STATUS_HTTP_VERSION_NOT_SUPPORTED: reason = " (Http Version Not Supported)"; break; case LCB_HTTP_STATUS_INSUFFICIENT_STORAGE: reason = " (Insufficient Storage)"; break; default: reason = ""; } rb_str_buf_cat2(str, reason); rb_str_buf_cat2(str, ", "); } snprintf(buf, 300, "error=0x%02x)", rc); rb_str_buf_cat2(str, buf); exc = rb_exc_new3(klass, str); rb_ivar_set(exc, cb_id_iv_error, INT2FIX(rc)); rb_ivar_set(exc, cb_id_iv_key, key); rb_ivar_set(exc, cb_id_iv_cas, Qnil); rb_ivar_set(exc, cb_id_iv_operation, Qnil); rb_ivar_set(exc, cb_id_iv_status, status ? INT2FIX(status) : Qnil); return exc; }
/* * Returns a string containing a human-readable representation of the Result. * * @since 1.0.0 * * @return [String] */ VALUE cb_result_inspect(VALUE self) { VALUE str, attr; char buf[100]; str = rb_str_buf_new2("#<"); rb_str_buf_cat2(str, rb_obj_classname(self)); snprintf(buf, 100, ":%p", (void *)self); rb_str_buf_cat2(str, buf); attr = rb_attr_get(self, cb_id_iv_operation); if (RTEST(attr)) { rb_str_buf_cat2(str, " operation="); rb_str_append(str, rb_inspect(attr)); } attr = rb_attr_get(self, cb_id_iv_error); if (RTEST(attr)) { rb_str_buf_cat2(str, " error="); rb_str_append(str, rb_inspect(attr)); } attr = rb_attr_get(self, cb_id_iv_key); if (RTEST(attr)) { rb_str_buf_cat2(str, " key="); rb_str_append(str, rb_inspect(attr)); } attr = rb_attr_get(self, cb_id_iv_status); if (RTEST(attr)) { rb_str_buf_cat2(str, " status="); rb_str_append(str, rb_inspect(attr)); } attr = rb_attr_get(self, cb_id_iv_cas); if (RTEST(attr)) { rb_str_buf_cat2(str, " cas="); rb_str_append(str, rb_inspect(attr)); } attr = rb_attr_get(self, cb_id_iv_flags); if (RTEST(attr)) { rb_str_buf_cat2(str, " flags=0x"); rb_str_append(str, rb_funcall(attr, cb_id_to_s, 1, INT2FIX(16))); } attr = rb_attr_get(self, cb_id_iv_node); if (RTEST(attr)) { rb_str_buf_cat2(str, " node="); rb_str_append(str, rb_inspect(attr)); } attr = rb_attr_get(self, cb_id_iv_from_master); if (attr != Qnil) { rb_str_buf_cat2(str, " from_master="); rb_str_append(str, rb_inspect(attr)); } attr = rb_attr_get(self, cb_id_iv_time_to_persist); if (RTEST(attr)) { rb_str_buf_cat2(str, " time_to_persist="); rb_str_append(str, rb_inspect(attr)); } attr = rb_attr_get(self, cb_id_iv_time_to_replicate); if (RTEST(attr)) { rb_str_buf_cat2(str, " time_to_replicate="); rb_str_append(str, rb_inspect(attr)); } attr = rb_attr_get(self, cb_id_iv_headers); if (RTEST(attr)) { rb_str_buf_cat2(str, " headers="); rb_str_append(str, rb_inspect(attr)); } rb_str_buf_cat2(str, ">"); return str; }
void *oci8_find_symbol(const char *symbol_name) { #if defined _WIN32 /* Windows */ static HMODULE hModule = NULL; if (hModule == NULL) { hModule = LoadLibrary("OCI.DLL"); if (hModule == NULL) { char message[512]; int error = GetLastError(); char *p; memset(message, 0, sizeof(message)); FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), message, sizeof(message), NULL); for (p = message; *p; p++) { if (*p == '\n' || *p == '\r') *p = ' '; } rb_raise(rb_eLoadError, "OCI.DLL: %d(%s)", error, message); } } return GetProcAddress(hModule, symbol_name); #else /* UNIX */ static void *handle = NULL; if (handle == NULL) { static const char * const sonames[] = { #if defined(__CYGWIN__) /* Windows(Cygwin) */ "OCI.DLL", #elif defined(_AIX) /* AIX */ "libclntsh.a(shr.o)", #elif defined(__hppa) /* HP-UX(PA-RISC) */ "libclntsh.sl.11.1", "libclntsh.sl.10.1", "libclntsh.sl.9.0", "libclntsh.sl.8.0", #elif defined(__APPLE__) /* Mac OS X */ "libclntsh.dylib.11.1", "libclntsh.dylib.10.1", #else /* Linux, Solaris and HP-UX(IA64) */ "libclntsh.so.11.1", "libclntsh.so.10.1", "libclntsh.so.9.0", "libclntsh.so.8.0", #endif }; #define NUM_SONAMES (sizeof(sonames)/sizeof(sonames[0])) size_t idx; VALUE err = rb_ary_new(); #ifdef _AIX #define DLOPEN_FLAG (RTLD_LAZY|RTLD_GLOBAL|RTLD_MEMBER) #else #define DLOPEN_FLAG (RTLD_LAZY|RTLD_GLOBAL) #endif for (idx = 0; idx < NUM_SONAMES; idx++) { handle = dlopen(sonames[idx], DLOPEN_FLAG); if (handle != NULL) { break; } rb_ary_push(err, rb_locale_str_new_cstr(dlerror())); } if (handle == NULL) { VALUE msg; msg = rb_str_buf_new(NUM_SONAMES * 50); for (idx = 0; idx < NUM_SONAMES; idx++) { const char *errmsg = RSTRING_PTR(RARRAY_PTR(err)[idx]); if (idx != 0) { rb_str_buf_cat2(msg, " "); } if (strstr(errmsg, sonames[idx]) == NULL) { /* prepend "soname: " if soname is not found in * the error message. */ rb_str_buf_cat2(msg, sonames[idx]); rb_str_buf_cat2(msg, ": "); } rb_str_buf_append(msg, RARRAY_PTR(err)[idx]); rb_str_buf_cat2(msg, ";"); } rb_exc_raise(rb_exc_new3(rb_eLoadError, msg)); } } return dlsym(handle, symbol_name); #endif /* defined _WIN32 */ }
inline static VALUE mArray_json_transfrom(VALUE self, VALUE Vstate, VALUE Vdepth) { long i, len = RARRAY_LEN(self); VALUE shift, result; long depth = NIL_P(Vdepth) ? 0 : FIX2LONG(Vdepth); VALUE delim = rb_str_new2(","); GET_STATE(Vstate); check_max_nesting(state, depth); if (state->check_circular) { VALUE self_id = rb_obj_id(self); rb_hash_aset(state->seen, self_id, Qtrue); result = rb_str_buf_new(len); if (RSTRING_LEN(state->array_nl)) rb_str_append(delim, state->array_nl); shift = rb_str_times(state->indent, LONG2FIX(depth + 1)); rb_str_buf_cat2(result, "["); OBJ_INFECT(result, self); rb_str_buf_append(result, state->array_nl); for (i = 0; i < len; i++) { VALUE element = RARRAY_PTR(self)[i]; if (RTEST(rb_hash_aref(state->seen, rb_obj_id(element)))) { rb_raise(eCircularDatastructure, "circular data structures not supported!"); } OBJ_INFECT(result, element); if (i > 0) rb_str_buf_append(result, delim); rb_str_buf_append(result, shift); element = rb_funcall(element, i_to_json, 2, Vstate, LONG2FIX(depth + 1)); Check_Type(element, T_STRING); rb_str_buf_append(result, element); } if (RSTRING_LEN(state->array_nl)) { rb_str_buf_append(result, state->array_nl); rb_str_buf_append(result, rb_str_times(state->indent, LONG2FIX(depth))); } rb_str_buf_cat2(result, "]"); rb_hash_delete(state->seen, self_id); } else { result = rb_str_buf_new(len); OBJ_INFECT(result, self); if (RSTRING_LEN(state->array_nl)) rb_str_append(delim, state->array_nl); shift = rb_str_times(state->indent, LONG2FIX(depth + 1)); rb_str_buf_cat2(result, "["); rb_str_buf_append(result, state->array_nl); for (i = 0; i < len; i++) { VALUE element = RARRAY_PTR(self)[i]; OBJ_INFECT(result, element); if (i > 0) rb_str_buf_append(result, delim); rb_str_buf_append(result, shift); element = rb_funcall(element, i_to_json, 2, Vstate, LONG2FIX(depth + 1)); Check_Type(element, T_STRING); rb_str_buf_append(result, element); } rb_str_buf_append(result, state->array_nl); if (RSTRING_LEN(state->array_nl)) { rb_str_buf_append(result, rb_str_times(state->indent, LONG2FIX(depth))); } rb_str_buf_cat2(result, "]"); } return result; }
static VALUE inspect_enumerator(VALUE obj, VALUE dummy, int recur) { struct enumerator *e; const char *cname; VALUE eobj, eargs, str, method; int tainted, untrusted; TypedData_Get_Struct(obj, struct enumerator, &enumerator_data_type, e); cname = rb_obj_classname(obj); if (!e || e->obj == Qundef) { return rb_sprintf("#<%s: uninitialized>", cname); } if (recur) { str = rb_sprintf("#<%s: ...>", cname); OBJ_TAINT(str); return str; } eobj = rb_attr_get(obj, id_receiver); if (NIL_P(eobj)) { eobj = e->obj; } tainted = OBJ_TAINTED(eobj); untrusted = OBJ_UNTRUSTED(eobj); /* (1..100).each_cons(2) => "#<Enumerator: 1..100:each_cons(2)>" */ str = rb_sprintf("#<%s: ", cname); rb_str_concat(str, rb_inspect(eobj)); method = rb_attr_get(obj, id_method); if (NIL_P(method)) { rb_str_buf_cat2(str, ":"); rb_str_buf_cat2(str, rb_id2name(e->meth)); } else if (method != Qfalse) { Check_Type(method, T_SYMBOL); rb_str_buf_cat2(str, ":"); rb_str_buf_cat2(str, rb_id2name(SYM2ID(method))); } eargs = rb_attr_get(obj, id_arguments); if (NIL_P(eargs)) { eargs = e->args; } if (eargs != Qfalse) { long argc = RARRAY_LEN(eargs); VALUE *argv = RARRAY_PTR(eargs); if (argc > 0) { rb_str_buf_cat2(str, "("); while (argc--) { VALUE arg = *argv++; rb_str_concat(str, rb_inspect(arg)); rb_str_buf_cat2(str, argc > 0 ? ", " : ")"); if (OBJ_TAINTED(arg)) tainted = TRUE; if (OBJ_UNTRUSTED(arg)) untrusted = TRUE; } } } rb_str_buf_cat2(str, ">"); if (tainted) OBJ_TAINT(str); if (untrusted) OBJ_UNTRUST(str); return str; }
/* * call-seq: * policy.inspect * * A custom inspect method for Policy objects. */ static VALUE rkadm5_policy_inspect(VALUE self){ VALUE v_str; v_str = rb_str_new2("#<"); rb_str_buf_cat2(v_str, rb_obj_classname(self)); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, "policy="); rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@policy"))); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, "min_life="); rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@min_life"))); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, "max_life="); rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@max_life"))); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, "min_length="); rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@min_length"))); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, "min_classes="); rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@min_classes"))); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, "history_num="); rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@history_num"))); rb_str_buf_cat2(v_str, ">"); return v_str; }
void JSON_convert_UTF8_to_JSON(VALUE buffer, VALUE string, ConversionFlags flags) { char buf[7]; const UTF8* source = (UTF8 *) RSTRING_PTR(string); const UTF8* sourceEnd = source + RSTRING_LEN(string); while (source < sourceEnd) { UTF32 ch = 0; unsigned short extraBytesToRead = trailingBytesForUTF8[*source]; if (source + extraBytesToRead >= sourceEnd) { rb_raise(rb_path2class("JSON::GeneratorError"), "partial character in source, but hit end"); } if (!isLegalUTF8(source, extraBytesToRead+1)) { rb_raise(rb_path2class("JSON::GeneratorError"), "source sequence is illegal/malformed"); } /* * The cases all fall through. See "Note A" below. */ switch (extraBytesToRead) { case 5: ch += *source++; ch <<= 6; /* remember, illegal UTF-8 */ case 4: ch += *source++; ch <<= 6; /* remember, illegal UTF-8 */ case 3: ch += *source++; ch <<= 6; case 2: ch += *source++; ch <<= 6; case 1: ch += *source++; ch <<= 6; case 0: ch += *source++; } ch -= offsetsFromUTF8[extraBytesToRead]; if (ch <= UNI_MAX_BMP) { /* Target is a character <= 0xFFFF */ /* UTF-16 surrogate values are illegal in UTF-32 */ if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_LOW_END) { if (flags == strictConversion) { source -= (extraBytesToRead+1); /* return to the illegal value itself */ rb_raise(rb_path2class("JSON::GeneratorError"), "source sequence is illegal/malformed"); } else { unicode_escape(buffer, UNI_REPLACEMENT_CHAR); } } else { /* normal case */ if (ch == '"') { rb_str_buf_cat2(buffer, "\\\""); } else if (ch == '\\') { rb_str_buf_cat2(buffer, "\\\\"); } else if (ch == '/') { rb_str_buf_cat2(buffer, "\\/"); } else if (ch >= 0x20 && ch <= 0x7f) { rb_str_buf_cat(buffer, (char *) source - 1, 1); } else if (ch == '\n') { rb_str_buf_cat2(buffer, "\\n"); } else if (ch == '\r') { rb_str_buf_cat2(buffer, "\\r"); } else if (ch == '\t') { rb_str_buf_cat2(buffer, "\\t"); } else if (ch == '\f') { rb_str_buf_cat2(buffer, "\\f"); } else if (ch == '\b') { rb_str_buf_cat2(buffer, "\\b"); } else if (ch < 0x20) { unicode_escape(buffer, (UTF16) ch); } else { unicode_escape(buffer, (UTF16) ch); } } } else if (ch > UNI_MAX_UTF16) { if (flags == strictConversion) { source -= (extraBytesToRead+1); /* return to the start */ rb_raise(rb_path2class("JSON::GeneratorError"), "source sequence is illegal/malformed"); } else { unicode_escape(buffer, UNI_REPLACEMENT_CHAR); } } else { /* target is a character in range 0xFFFF - 0x10FFFF. */ ch -= halfBase; unicode_escape(buffer, (UTF16)((ch >> halfShift) + UNI_SUR_HIGH_START)); unicode_escape(buffer, (UTF16)((ch & halfMask) + UNI_SUR_LOW_START)); } } }
/* * call-seq: * principal.inspect * * A custom inspect method for the Principal object. */ static VALUE rkrb5_princ_inspect(VALUE self){ RUBY_KRB5_PRINC* ptr; VALUE v_str; Data_Get_Struct(self, RUBY_KRB5_PRINC, ptr); v_str = rb_str_new2("#<"); rb_str_buf_cat2(v_str, rb_obj_classname(self)); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, "attributes="); rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@attributes"))); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, "aux_attributes="); rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@aux_attributes"))); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, "expire_time="); rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@expire_time"))); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, "fail_auth_count="); rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@fail_auth_count"))); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, "kvno="); rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@kvno"))); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, "last_failed="); rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@last_failed"))); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, "last_password_change="); rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@last_password_change"))); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, "last_success="); rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@last_success"))); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, "max_life="); rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@max_life"))); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, "max_renewable_life="); rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@max_renewable_life"))); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, "mod_date="); rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@mod_date"))); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, "mod_name="); rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@mod_name"))); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, "password_expiration="); rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@password_expiration"))); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, "policy="); rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@policy"))); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, "principal="); rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@principal"))); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, ">"); return v_str; }
static VALUE rkadm5_config_inspect(VALUE self){ VALUE v_str; v_str = rb_str_new2("#<"); rb_str_buf_cat2(v_str, rb_obj_classname(self)); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, "acl_file="); rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@acl_file"))); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, "admin_server="); rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@admin_server"))); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, "dict_file="); rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@dict_file"))); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, "enctype="); rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@enctype"))); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, "expiration="); rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@expiration"))); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, "flags="); rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@flags"))); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, "iprop_enabled="); rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@iprop_enabled"))); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, "iprop_logfile="); rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@iprop_logfile"))); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, "iprop_poll_time="); rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@iprop_poll_time"))); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, "iprop_port="); rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@iprop_port"))); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, "kadmind_port="); rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@kadmind_port"))); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, "keysalts="); rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@keysalts"))); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, "kpasswd_port="); rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@kpasswd_port"))); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, "kvno="); rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@kvno"))); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, "mkey_name="); rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@mkey_name"))); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, "mkey_from_kbd="); rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@mkey_from_kbd"))); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, "maxlife="); rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@maxlife"))); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, "maxrlife="); rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@maxrlife"))); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, "num_keysalts="); rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@num_keysalts"))); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, "realm="); rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@realm"))); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, "stash_file="); rb_str_buf_append(v_str, rb_inspect(rb_iv_get(self, "@stash_file"))); rb_str_buf_cat2(v_str, " "); rb_str_buf_cat2(v_str, ">"); return v_str; }