static VALUE recursive_eql(VALUE range, VALUE obj, int recur) { if (recur) return Qtrue; /* Subtle! */ if (!rb_eql(RANGE_BEG(range), RANGE_BEG(obj))) return Qfalse; if (!rb_eql(RANGE_END(range), RANGE_END(obj))) return Qfalse; if (EXCL(range) != EXCL(obj)) return Qfalse; return Qtrue; }
/* * Tries to identify if a buffer represents the currently defined packet. It * does this by iterating over all the packet items that were created with * an ID value and checking whether that ID value is present at the correct * location in the buffer. * * Incorrectly sized buffers will still positively identify if there is * enough data to match the ID values. This is to allow incorrectly sized * packets to still be processed as well as possible given the incorrectly * sized data. * * @param buffer [String] Raw buffer of binary data * @return [Boolean] Whether or not the buffer of data is this packet */ static VALUE identify(VALUE self, VALUE buffer) { VALUE id_items = rb_ivar_get(self, id_ivar_id_items); VALUE item = Qnil; VALUE id_value = Qnil; VALUE raw_value = Qnil; long id_items_length = 0; int index = 0; if (!RTEST(buffer)) { return Qfalse; } if (!RTEST(id_items)) { return Qtrue; } id_items_length = RARRAY_LEN(id_items); for (index = 0; index < id_items_length; index++) { item = rb_ary_entry(id_items, index); id_value = rb_ivar_get(item, id_ivar_id_value); raw_value = protected_read_item_internal(self, item, buffer); if (!rb_eql(id_value, raw_value)) { return Qfalse; } } return Qtrue; }
static int eql_i(VALUE key, VALUE val1, VALUE arg) { struct equal_data *data = (struct equal_data *)arg; VALUE val2; if (key == Qundef) { return ST_CONTINUE; } if (!st_lookup(data->tbl, key, &val2)) { data->result = Qfalse; return ST_STOP; } if (data->eql) { if (!rb_eql(val1, val2)) { data->result = Qfalse; return ST_STOP; } } else { if (rb_equal(val1, val2) != Qtrue) { data->result = Qfalse; return ST_STOP; } } return ST_CONTINUE; }
static VALUE hash_equal(VALUE hash1, VALUE hash2, bool eql) { if (hash1 == hash2) { return Qtrue; } if (TYPE(hash2) != T_HASH) { if (!rb_respond_to(hash2, rb_intern("to_hash"))) { return Qfalse; } if (eql) { return rb_eql(hash2, hash1); } else { return rb_equal(hash2, hash1); } } if (RHASH_SIZE(hash1) != RHASH_SIZE(hash2)) { return Qfalse; } if (IS_RHASH(hash2)) { struct equal_data data; data.tbl = RHASH(hash2)->tbl; data.eql = eql; return rb_exec_recursive(recursive_eql, hash1, (VALUE)&data); } else { return CFEqual((CFTypeRef)hash1, (CFTypeRef)hash2) ? Qtrue : Qfalse; } }
static int rb_any_cmp(VALUE a, VALUE b) { if (a == b) { return 0; } return !rb_eql(a, b); }
static VALUE range_eql(VALUE range, VALUE obj) { if (range == obj) return Qtrue; if (!rb_obj_is_instance_of(obj, rb_obj_class(range))) return Qfalse; if (!rb_eql(RANGE_BEG(range), RANGE_BEG(obj))) return Qfalse; if (!rb_eql(RANGE_END(range), RANGE_END(obj))) return Qfalse; if (EXCL(range) != EXCL(obj)) return Qfalse; return Qtrue; }
static VALUE recursive_eql(VALUE s, VALUE s2, int recur) { long i; if (recur) return Qtrue; /* Subtle! */ for (i=0; i<RSTRUCT_LEN(s); i++) { if (!rb_eql(RSTRUCT_PTR(s)[i], RSTRUCT_PTR(s2)[i])) return Qfalse; } return Qtrue; }
static VALUE rb_struct_eql_r(VALUE s, VALUE s2, int recur) { if (recur) { return Qtrue; } for (int i = 0; i < RSTRUCT_LEN(s); i++) { if (!rb_eql(RSTRUCT_PTR(s)[i], RSTRUCT_PTR(s2)[i])) { return Qfalse; } } return Qtrue; }
static VALUE range_eql(VALUE range, SEL sel, VALUE obj) { if (range == obj) { return Qtrue; } if (!rb_obj_is_kind_of(obj, rb_cRange)) { return Qfalse; } if (!rb_eql(RANGE_BEG(range), RANGE_BEG(obj))) { return Qfalse; } if (!rb_eql(RANGE_END(range), RANGE_END(obj))) { return Qfalse; } if (EXCL(range) != EXCL(obj)) { return Qfalse; } return Qtrue; }
static VALUE recursive_eql(VALUE s, VALUE s2, int recur) { VALUE *ptr, *ptr2; long i, len; if (recur) return Qtrue; /* Subtle! */ ptr = RSTRUCT_PTR(s); ptr2 = RSTRUCT_PTR(s2); len = RSTRUCT_LEN(s); for (i=0; i<len; i++) { if (!rb_eql(ptr[i], ptr2[i])) return Qfalse; } return Qtrue; }
static VALUE rb_struct_eql(VALUE s, VALUE s2) { long i; if (s == s2) return Qtrue; if (TYPE(s2) != T_STRUCT) return Qfalse; if (rb_obj_class(s) != rb_obj_class(s2)) return Qfalse; if (RSTRUCT(s)->len != RSTRUCT(s2)->len) { rb_bug("inconsistent struct"); /* should never happen */ } for (i=0; i<RSTRUCT(s)->len; i++) { if (!rb_eql(RSTRUCT(s)->ptr[i], RSTRUCT(s2)->ptr[i])) return Qfalse; } return Qtrue; }
static void ov_http_client_prepare_handle(ov_http_client_object* client_ptr, ov_http_request_object* request_ptr, struct curl_slist** headers, CURL* handle) { VALUE header; VALUE url; int timeout; int connect_timeout; /* Configure sharing of cookies with other handlers created by the client: */ curl_easy_setopt(handle, CURLOPT_SHARE, client_ptr->share); if (client_ptr->cookies != NULL && strlen(client_ptr->cookies) > 0) { curl_easy_setopt(handle, CURLOPT_COOKIEFILE, client_ptr->cookies); curl_easy_setopt(handle, CURLOPT_COOKIEJAR, client_ptr->cookies); } /* Configure TLS parameters: */ if (client_ptr->insecure) { curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0L); curl_easy_setopt(handle, CURLOPT_SSL_VERIFYHOST, 0L); } if (client_ptr->ca_file != NULL) { curl_easy_setopt(handle, CURLOPT_CAINFO, client_ptr->ca_file); } /* Configure the total timeout: */ timeout = client_ptr->timeout; if (!NIL_P(request_ptr->timeout)) { timeout = NUM2INT(request_ptr->timeout); } curl_easy_setopt(handle, CURLOPT_TIMEOUT, timeout); /* Configure the connect timeout: */ connect_timeout = client_ptr->connect_timeout; if (!NIL_P(request_ptr->connect_timeout)) { connect_timeout = NUM2INT(request_ptr->connect_timeout); } curl_easy_setopt(handle, CURLOPT_CONNECTTIMEOUT, connect_timeout); /* Configure compression of responses (setting the value to zero length string means accepting all the compression types that libcurl supports): */ if (client_ptr->compress) { curl_easy_setopt(handle, CURLOPT_ENCODING, ""); } /* Configure debug mode: */ if (client_ptr->debug) { curl_easy_setopt(handle, CURLOPT_VERBOSE, 1L); curl_easy_setopt(handle, CURLOPT_DEBUGFUNCTION, ov_http_client_debug_function); } /* Configure the proxy: */ if (client_ptr->proxy_url != NULL) { curl_easy_setopt(handle, CURLOPT_PROXY, client_ptr->proxy_url); if (client_ptr->proxy_username != NULL && client_ptr->proxy_password != NULL) { curl_easy_setopt(handle, CURLOPT_PROXYUSERNAME, client_ptr->proxy_username); curl_easy_setopt(handle, CURLOPT_PROXYPASSWORD, client_ptr->proxy_password); } } /* Configure callbacks: */ curl_easy_setopt(handle, CURLOPT_READFUNCTION, ov_http_client_read_function); curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, ov_http_client_write_function); curl_easy_setopt(handle, CURLOPT_HEADERFUNCTION, ov_http_client_header_function); /* Build and set the URL: */ url = ov_http_client_build_url(request_ptr->url, request_ptr->query); curl_easy_setopt(handle, CURLOPT_URL, StringValueCStr(url)); /* Set the method: */ if (rb_eql(request_ptr->method, POST_SYMBOL)) { *headers = curl_slist_append(*headers, "Transfer-Encoding: chunked"); *headers = curl_slist_append(*headers, "Expect:"); curl_easy_setopt(handle, CURLOPT_POST, 1L); } else if (rb_eql(request_ptr->method, PUT_SYMBOL)) { *headers = curl_slist_append(*headers, "Expect:"); curl_easy_setopt(handle, CURLOPT_UPLOAD, 1L); curl_easy_setopt(handle, CURLOPT_PUT, 1L); } else if (rb_eql(request_ptr->method, DELETE_SYMBOL)) { curl_easy_setopt(handle, CURLOPT_HTTPGET, 1L); curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "DELETE"); } else if (rb_eql(request_ptr->method, GET_SYMBOL)) { curl_easy_setopt(handle, CURLOPT_HTTPGET, 1L); } /* Set authentication details: */ if (!NIL_P(request_ptr->token)) { header = rb_sprintf("Authorization: Bearer %"PRIsVALUE"", request_ptr->token); *headers = curl_slist_append(*headers, StringValueCStr(header)); } else if (!NIL_P(request_ptr->username) && !NIL_P(request_ptr->password)) { curl_easy_setopt(handle, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_easy_setopt(handle, CURLOPT_USERNAME, StringValueCStr(request_ptr->username)); curl_easy_setopt(handle, CURLOPT_PASSWORD, StringValueCStr(request_ptr->password)); } else if (RTEST(request_ptr->kerberos)) { curl_easy_setopt(handle, CURLOPT_HTTPAUTH, CURLAUTH_NEGOTIATE); } /* Set the headers: */ if (!NIL_P(request_ptr->headers)) { rb_hash_foreach(request_ptr->headers, ov_http_client_add_header, (VALUE) headers); } curl_easy_setopt(handle, CURLOPT_HTTPHEADER, *headers); /* Send a summary of the request to the log: */ ov_http_client_log_info( client_ptr->log, "Sending %"PRIsVALUE" request to URL '%"PRIsVALUE"'.", request_ptr->method, url ); }