int redis_zset::zrange_get(const char* cmd, const char* key, int start, int stop, std::vector<string>* result) { const char* argv[4]; size_t lens[4]; argv[0] = cmd; lens[0] = strlen(cmd); argv[1] = key; lens[1] = strlen(key); char start_s[INTLEN], stop_s[INTLEN]; safe_snprintf(start_s, sizeof(start_s), "%d", start); safe_snprintf(stop_s, sizeof(stop_s), "%d", stop); argv[2] = start_s; lens[2] = strlen(start_s); argv[3] = stop_s; lens[3] = strlen(stop_s); hash_slot(key); build_request(4, argv, lens); return get_strings(result); }
bool redis_list::bpop(const char* cmd, const std::vector<string>& keys, size_t timeout, std::pair<string, string>& result) { size_t argc = 2 + keys.size(); const char** args = (const char**) pool_->dbuf_alloc(argc * sizeof(char*)); size_t* lens = (size_t*) pool_->dbuf_alloc(argc * sizeof(size_t)); args[0] = cmd; lens[0] = strlen(cmd); size_t i = 1; std::vector<string>::const_iterator cit = keys.begin(); for (; cit != keys.end(); ++cit) { args[i] = (*cit).c_str(); lens[i] = strlen(args[i]); i++; } char buf[LONG_LEN]; safe_snprintf(buf, sizeof(buf), "%lu", (unsigned long) timeout); args[i] = buf; lens[i] = strlen(args[i]); build_request(argc, args, lens); return bpop(result); }
bool redis_key::restore(const char* key, const char* value, size_t len, int nttl, bool replace /* = false */) { const char* argv[5]; size_t lens[5]; argv[0] = "RESTORE"; lens[0] = sizeof("RESTORE") - 1; argv[1] = key; lens[1] = strlen(key); char ttl_s[INT_LEN]; safe_snprintf(ttl_s, sizeof(ttl_s), "%d", nttl); argv[2] = ttl_s; lens[2] = strlen(ttl_s); argv[3] = value; lens[3] = len; size_t argc = 4; if (replace) { argv[4] = "REPLACE"; lens[4] = sizeof("REPLACE") - 1; argc++; } hash_slot(key); build_request(argc, argv, lens); return check_status(); }
int redis_string::bitop(const char* op, const char* destkey, const char* keys[], size_t size) { size_t argc = 3 + size; const char** argv = (const char**) pool_->dbuf_alloc(argc * sizeof(char*)); size_t* lens = (size_t*) pool_->dbuf_alloc(argc * sizeof(size_t)); argv[0] = "BITOP"; lens[0] = sizeof("BITOP") - 1; argv[1] = op; lens[1] = strlen(op); argv[2] = destkey; lens[2] = strlen(destkey); for (size_t i = 3, j = 0; j < size; i++, j++) { argv[i] = keys[j]; lens[i] = strlen(argv[i]); } build_request(argc, argv, lens); return get_number(); }
bool redis_string::incoper(const char* cmd, const char* key, long long int* n, long long int* result) { size_t argc = 2; const char* argv[3]; size_t lens[3]; argv[0] = cmd; lens[0] = strlen(cmd); argv[1] = key; lens[1] = strlen(key); char buf[INT64_LEN]; if (n != NULL) { (void) acl_i64toa(*n, buf, sizeof(buf)); argv[2] = buf; lens[2] = strlen(buf); argc++; } hash_slot(key); build_request(argc, argv, lens); bool success; if (result != NULL) *result = get_number64(&success); else (void) get_number64(&success); return success; }
bool redis_string::getrange(const char* key, size_t key_len, int start, int end, string& buf) { const char* argv[4]; size_t lens[4]; argv[0] = "GETRANGE"; lens[0] = sizeof("GETRANGE") - 1; argv[1] = key; lens[1] = key_len; char start_buf[INT_LEN], end_buf[INT_LEN]; (void) safe_snprintf(start_buf, sizeof(start_buf), "%d", start); argv[2] = start_buf; lens[2] = strlen(start_buf); (void) safe_snprintf(end_buf, sizeof(end_buf), "%d", end); argv[3] = end_buf; lens[3] = strlen(end_buf); hash_slot(key, key_len); build_request(4, argv, lens); return get_string(buf) >= 0 ? true : false; }
int redis_string::bitcount(const char* key, size_t len, int start, int end) { const char* argv[4]; size_t lens[4]; argv[0] = "BITCOUNT"; lens[0] = sizeof("BITCOUNT") - 1; argv[1] = key; lens[1] = len; char buf4start[INT_LEN]; (void) safe_snprintf(buf4start, sizeof(buf4start), "%d", start); argv[2] = buf4start; lens[2] = strlen(buf4start); char buf4end[INT_LEN]; (void) safe_snprintf(buf4end, sizeof(buf4end), "%d", end); argv[3] = buf4end; lens[3] = strlen(buf4end); hash_slot(key, len); build_request(4, argv, lens); return get_number(); }
const std::vector<disque_node*>* disque::hello() { free_nodes(); size_t argc = 1; const char* argv[1]; size_t lens[1]; argv[0] = "HELLO"; lens[0] = sizeof("HELLO") - 1; build_request(argc, argv, lens); const redis_result* rr = run(); if (rr == NULL) return NULL; size_t n; const redis_result** children = rr->get_children(&n); if (children == NULL || n < 3) return NULL; if (children[0]->get_type() == REDIS_RESULT_INTEGER) version_ = children[0]->get_integer(); if (children[1]->get_type() == REDIS_RESULT_STRING) children[1]->argv_to_string(myid_); for (size_t i = 2; i < n; i++) { disque_node* node = create_node(children[i]); if (node != NULL) nodes_.push_back(node); } return &nodes_; }
virtual error_code on_connected( proxy_socket<Tag> & socket, endpoint_type const & endpoint, error_code & ec ) { std::cout << "Connected to proxy..." << std::endl; request_t request = build_request(endpoint, ec); if(!ec) { std::cout << "Sending connection request to proxy..." << std::endl; socket.send( boost::asio::buffer(request.bytes), 0, ec); if(!ec) { std::cout << "Reading response from proxy..." << std::endl; boost::array<boost::uint8_t, 8> buffer; size_t bytes_read = socket.read_some(boost::asio::buffer(buffer), ec); if(!ec) { if(bytes_read == 8) { if(buffer[1] == 0x5a) { std::cout << "Connection to remote endpoint granted and established" << std::endl; return (ec = error_code()); } } std::cout << "Connection to remote endpoint denied or invalid response" << std::endl; return (ec = error_code(boost::asio::error::connection_refused)); } } } return ec; }
const disque_job* disque::show(const char* job_id) { if (job_) { delete job_; job_ = NULL; } size_t argc = 2; const char* argv[2]; size_t lens[2]; argv[0] = "SHOW"; lens[0] = sizeof("SHOW") - 1; argv[1] = job_id; lens[1] = strlen(job_id); build_request(argc, argv, lens); const redis_result* rr = run(); if (rr == NULL) return NULL; job_ = NEW disque_job; if (job_->init(*rr) == false) { delete job_; job_ = NULL; return NULL; } return job_; }
bool disque::info(std::map<string, string>& out) { size_t argc = 1; const char* argv[1]; size_t lens[1]; argv[0] = "INFO"; lens[0] = sizeof("INFO") - 1; build_request(argc, argv, lens); string buf; if (get_string(buf) <= 0) return false; string line; while ((buf.scan_line(line)) == true) { const std::vector<string>& tokens = line.split2(":"); if (tokens.size() != 2) { line.clear(); continue; } out[tokens[0]] = tokens[1]; line.clear(); } return true; }
bool redis_zset::zscore(const char* key, const char* member, size_t len, double& result) { const char* argv[3]; size_t lens[3]; argv[0] = "ZSCORE"; lens[0] = sizeof("ZSCORE") - 1; argv[1] = key; lens[1] = strlen(key); argv[2] = member; lens[2] = len; hash_slot(key); build_request(3, argv, lens); char buf[BUFLEN]; int ret = get_string(buf, sizeof(buf)); if (ret <= 0) return false; result = atof(buf); return true; }
int redis_zset::zremrangebyrank(const char* key, int start, int stop) { const char* argv[4]; size_t lens[4]; argv[0] = "ZREMRANGEBYRANK"; lens[0] = sizeof("ZREMRANGEBYRANK") - 1; argv[1] = key; lens[1] = strlen(key); char start_s[INTLEN], stop_s[INTLEN]; safe_snprintf(start_s, sizeof(start_s), "%d", start); safe_snprintf(stop_s, sizeof(stop_s), "%d", stop); argv[2] = start_s; lens[2] = strlen(start_s); argv[3] = stop_s; lens[3] = strlen(stop_s); hash_slot(key); build_request(4, argv, lens); return get_number(); }
int redis_zset::zadd(const char* key, const std::vector<std::pair<string, double> >&members) { size_t argc = 2 + members.size() * 2; const char** argv = (const char**) dbuf_->dbuf_alloc(argc * sizeof(char*)); size_t* lens = (size_t*) dbuf_->dbuf_alloc(argc * sizeof(size_t)); argv[0] = "ZADD"; lens[0] = sizeof("ZADD") - 1; argv[1] = key; lens[1] = strlen(key); char* buf; size_t i = 2; std::vector<std::pair<string, double> >::const_iterator cit; for (cit = members.begin(); cit != members.end(); ++cit) { buf = (char*) dbuf_->dbuf_alloc(BUFLEN); safe_snprintf(buf, BUFLEN, "%.8f", (*cit).second); argv[i] = buf; lens[i] = strlen(buf); i++; argv[i] = (*cit).first.c_str(); lens[i] = (*cit).first.length(); i++; } hash_slot(key); build_request(argc, argv, lens); return get_number(); }
gint gcluster_push_virtual_ns_space_used(addr_info_t * addr, long timeout, GHashTable *space_used, GError ** error) { static struct code_handler_s codes[] = { {200, REPSEQ_FINAL, NULL, NULL}, {0, 0, NULL, NULL} }; struct reply_sequence_data_s data = { NULL, 0, codes }; MESSAGE req = NULL; GByteArray *buf = NULL; GSList *kv_list = NULL; /* send the hashtable in the body */ kv_list = key_value_pairs_convert_from_map(space_used, FALSE, error); if (!kv_list) { GSETERROR(error, "Conversion HashTable->List failure"); return (0); } /*encode the list */ buf = key_value_pairs_marshall_gba(kv_list, error); if (!buf) { GSETERROR(error, "Failed to marshall kv list"); goto error_marshall; } req = build_request(NAME_MSGNAME_CS_PUSH_VNS_SPACE_USED, buf->data, buf->len, error); if (req == NULL) { GSETERROR(error, "Failed to build request %s", NAME_MSGNAME_CS_PUSH_VNS_SPACE_USED); goto error_buildreq; } /*reads the answers */ if (!metaXClient_reply_sequence_run_from_addrinfo(error, req, addr, timeout, &data)) { GSETERROR(error, "Cannot execute the query %s and receive all the responses", NAME_MSGNAME_CS_PUSH_BROKEN_CONT); goto error_reply; } message_destroy(req, NULL); g_byte_array_free(buf, TRUE); if(kv_list) { g_slist_foreach(kv_list, g_free1, NULL); g_slist_free(kv_list); } return (1); error_reply: message_destroy(req, NULL); error_buildreq: g_byte_array_free(buf, TRUE); error_marshall: if(kv_list) { g_slist_foreach(kv_list, g_free1, NULL); g_slist_free(kv_list); } return (0); }
void redis_command::build(const char* cmd, const char* key, const std::map<string, const char*>& attrs) { argc_ = 1 + attrs.size() * 2; if (key != NULL) argc_++; argv_space(argc_); size_t i = 0; argv_[i] = cmd; argv_lens_[i] = strlen(cmd); i++; if (key != NULL) { argv_[i] = key; argv_lens_[i] = strlen(key); i++; } std::map<string, const char*>::const_iterator cit = attrs.begin(); for (; cit != attrs.end(); ++cit) { argv_[i] = cit->first.c_str(); argv_lens_[i] = cit->first.size(); i++; argv_[i] = cit->second; argv_lens_[i] = strlen(argv_[i]); i++; } build_request(argc_, argv_, argv_lens_); }
GSList * gcluster_get_service_types(addr_info_t *addr, long timeout, GError ** error) { static struct code_handler_s codes[] = { {206, REPSEQ_BODYMANDATORY, &container_list_content_handler, NULL}, {200, REPSEQ_FINAL, &container_list_content_handler, NULL}, {0, 0, NULL, NULL}}; GSList *srvtypes = NULL; struct reply_sequence_data_s data = { &srvtypes, 0, codes }; MESSAGE req = NULL; req = build_request(NAME_MSGNAME_CS_GET_SRVNAMES, NULL, 0, error); if (req == NULL) { GSETERROR(error, "Failed to build request %s", NAME_MSGNAME_CS_GET_SRVNAMES); goto error_buildreq; } /*reads the answers */ if (!metaXClient_reply_sequence_run_from_addrinfo(error, req, addr, timeout, &data)) { GSETERROR(error, "Cannot execute the query %s and receive all the responses", NAME_MSGNAME_CS_GET_SRVNAMES); goto error_reply; } message_destroy(req, NULL); return (srvtypes); error_reply: message_destroy(req, NULL); error_buildreq: return (NULL); }
void redis_command::build(const char* cmd, const char* key, const std::vector<const char*>& names) { size_t argc = names.size(); argc_ = 1 + argc; if (key != NULL) argc_++; argv_space(argc_); size_t i = 0; argv_[i] = cmd; argv_lens_[i] = strlen(cmd); i++; if (key != NULL) { argv_[i] = key; argv_lens_[i] = strlen(key); i++; } for (size_t j = 0; j < argc; j++) { argv_[i] = names[j]; argv_lens_[i] = strlen(argv_[i]); i++; } build_request(argc_, argv_, argv_lens_); }
bool redis_string::getbit(const char* key, size_t len, unsigned offset, int& bit) { const char* argv[3]; size_t lens[3]; argv[0] = "GETBIT"; lens[0] = sizeof("GETBIT") - 1; argv[1] = key; lens[1] = len; char buf4off[INT_LEN]; (void) safe_snprintf(buf4off, sizeof(buf4off), "%d", offset); argv[2] = buf4off; lens[2] = strlen(buf4off); hash_slot(key, len); build_request(3, argv, lens); int ret = get_number(); if (ret < 0) return false; bit = ret == 0 ? 0 : 1; return true; }
void redis_command::build(const char* cmd, const char* key, const char* names[], const size_t lens[], size_t argc) { argc_ = 1 + argc; if (key != NULL) argc_++; argv_space(argc_); size_t i = 0; argv_[i] = cmd; argv_lens_[i] = strlen(cmd); i++; if (key != NULL) { argv_[i] = key; argv_lens_[i] = strlen(key); i++; } for (size_t j = 0; j < argc; j++) { argv_[i] = names[j]; argv_lens_[i] = lens[j]; i++; } build_request(argc_, argv_, argv_lens_); }
int redis_string::bitop(const char* op, const char* destkey, const std::vector<const char*>& keys) { size_t argc = 3 + keys.size(); const char** argv = (const char**) pool_->dbuf_alloc(argc * sizeof(char*)); size_t* lens = (size_t*) pool_->dbuf_alloc(argc * sizeof(size_t)); argv[0] = "BITOP"; lens[0] = sizeof("BITOP") - 1; argv[1] = op; lens[1] = strlen(op); argv[2] = destkey; lens[2] = strlen(destkey); std::vector<const char*>::const_iterator cit = keys.begin(); for (size_t i = 3; cit != keys.end(); ++cit, i++) { argv[i] = *cit; lens[i] = strlen(argv[i]); } build_request(argc, argv, lens); return get_number(); }
void redis_command::build(const char* cmd, const char* key, const int names[], size_t argc) { argc_ = 1 + argc; if (key != NULL) argc_++; argv_space(argc_); size_t i = 0; argv_[i] = cmd; argv_lens_[i] = strlen(cmd); i++; if (key != NULL) { argv_[i] = key; argv_lens_[i] = strlen(key); i++; } char* buf4int; for (size_t j = 0; j < argc; j++) { buf4int = (char*) dbuf_->dbuf_alloc(INT_LEN); safe_snprintf(buf4int, INT_LEN, "%d", names[j]); argv_[i] = buf4int; argv_lens_[i] = strlen(argv_[i]); i++; } build_request(argc_, argv_, argv_lens_); }
bool redis_string::incrbyfloat(const char* key, double inc, double* result /* = NULL */) { const char* argv[3]; size_t lens[3]; argv[0] = "INCRBYFLOAT"; lens[0] = sizeof("INCRBYFLOAT") - 1; argv[1] = key; lens[1] = strlen(key); char buf[FLOAT_LEN]; (void) safe_snprintf(buf, sizeof(buf), "%f", inc); argv[2] = buf; lens[2] = strlen(buf); hash_slot(key); build_request(3, argv, lens); if (get_string(buf, sizeof(buf)) == false) return false; if (result != NULL) *result = atof(buf); return true; }
const redis_result* redis_command::request(size_t argc, const char* argv[], size_t lens[], size_t nchild /* = 0 */) { build_request(argc, argv, lens); const redis_result* result = run(nchild); return result; }
t_list_single find_aux(t_list_words l, t_websearch search_engine, t_list_single sites) { if (IS_EMPTY(l)) { return sites; } else { char *results[NBR_WEBSITES]; int count; char *request; int i; INFO("Construction de la requête"); request = build_request(HEAD(l)); INFO("Requête : %s", request); count = websearch(search_engine, request, results, NBR_WEBSITES); INFO("Documents trouvés : %d", count); INFO("Stockage des sites trouvés"); for(i=0;i<count;i++) { if (add_single_sorted(results[i], NBR_WEBSITES-i, &sites) == 0) { free(results[i]); } } INFO("Libération de la requête"); free_request(request); return find_aux(NEXT(l), search_engine, sites); } }
int make_request(int sockfd, char *hostname, char *request_path) { char *request = build_request(hostname, request_path); size_t bytes_sent = 0; size_t total_bytes_sent = 0; size_t bytes_to_send = strlen(request); debug("Bytes to send: %ld", bytes_to_send); while (1) { bytes_sent = send(sockfd, request, strlen(request), 0); total_bytes_sent += bytes_sent; debug("Bytes sent: %ld", bytes_sent); if (total_bytes_sent >= bytes_to_send) { break; } } free(request); return total_bytes_sent; }
void g_vimeo_videos_search (GVimeo *vimeo, const gchar *text, gint page, GVimeoVideoSearchCb callback, gpointer user_data) { GVimeoVideoSearchData *search_data; gchar *request; g_return_if_fail (G_IS_VIMEO (vimeo)); request = build_request (vimeo, text, page); search_data = g_slice_new (GVimeoVideoSearchData); search_data->vimeo = vimeo; search_data->search_cb = callback; search_data->user_data = user_data; grl_net_wc_request_async (vimeo->priv->wc, request, NULL, search_videos_complete_cb, search_data); g_free (request); }
namespace_info_t * gcluster_get_namespace_info(addr_info_t * addr, long timeout, GError ** error) { static struct code_handler_s codes[] = { {200, REPSEQ_FINAL, &namespace_info_handler, NULL}, {0, 0, NULL, NULL} }; namespace_info_t *ns_info = NULL; struct reply_sequence_data_s data = { &ns_info, 0, codes }; MESSAGE req = NULL; req = build_request(NAME_MSGNAME_CS_GETNS, NULL, 0, error); if (req == NULL) { GSETERROR(error, "Failed to build request %s", NAME_MSGNAME_CS_GETNS); goto error_buildreq; } /*reads the answers */ if (!metaXClient_reply_sequence_run_from_addrinfo(error, req, addr, timeout, &data)) { GSETERROR(error, "Cannot execute the query %s and receive all the responses", NAME_MSGNAME_CS_GETNS); goto error_reply; } message_destroy(req, NULL); return (ns_info); error_reply: message_destroy(req, NULL); error_buildreq: return (NULL); }
redis_key_t redis_key::type(const char* key) { const char* argv[2]; size_t lens[2]; argv[0] = "TYPE"; lens[0] = sizeof("TYPE") - 1; argv[1] = key; lens[1] = strlen(key); hash_slot(key); build_request(2, argv, lens); const char* ptr = get_status(); if (ptr == NULL || *ptr == 0 || strcasecmp(ptr, "none") == 0) return REDIS_KEY_NONE; else if (strcasecmp(ptr, "string") == 0) return REDIS_KEY_STRING; else if (strcasecmp(ptr, "hash") == 0) return REDIS_KEY_HASH; else if (strcasecmp(ptr, "list") == 0) return REDIS_KEY_LIST; else if (strcasecmp(ptr, "set") == 0) return REDIS_KEY_SET; else if (strcasecmp(ptr, "zset") == 0) return REDIS_KEY_ZSET; else { logger_error("unknown type: %s, key: %s", ptr, key); return REDIS_KEY_NONE; } }
bool redis_zset::zincrby(const char* key, double inc, const char* member, size_t len, double* result /* = NULL */) { const char* argv[4]; size_t lens[4]; argv[0] = "ZINCRBY"; lens[0] = sizeof("ZINCRBY") - 1; argv[1] = key; lens[1] = strlen(key); char score[BUFLEN]; safe_snprintf(score, sizeof(score), "%.8f", inc); argv[2] = score; lens[2] = strlen(score); argv[3] = member; lens[3] = len; hash_slot(key); build_request(4, argv, lens); int ret = get_string(score, sizeof(score)); if (ret <= 0) return false; if (result) *result = atof(score); return true; }