void Run() { KeyObject start(Slice(), KV, dbid); KeyObject end(Slice(), KV, dbid + 1); Buffer sbuf, ebuf; encode_key(sbuf, start); encode_key(ebuf, end); adb->GetEngine()->CompactRange(sbuf.AsString(), ebuf.AsString()); delete this; }
void Run() { adb->GetEngine()->BeginBatchWrite(); adb->VisitDB(dbid, this); adb->GetEngine()->CommitBatchWrite(); KeyObject start(Slice(), KV, dbid); KeyObject end(Slice(), KV, dbid + 1); Buffer sbuf, ebuf; encode_key(sbuf, start); encode_key(ebuf, end); adb->GetEngine()->CompactRange(sbuf.AsString(), ebuf.AsString()); delete this; }
void PersistentSyncLogQueue::put(const Synclog &log){ Locking l(&mutex); int idx = this->index(this->size); std::string key_buf = encode_key(idx); leveldb::Slice b(log.data(), log.size()); leveldb::Status s; s = meta_db->Put(write_options, key_buf, b); if(!s.ok()){ log_error("meta_db set error: %s", s.ToString().c_str()); }else{ if(this->size < this->total){ if(this->size == 0){ this->seq_min = log.seq(); } this->size ++; }else{ this->seq_min ++; this->start = this->index(+1); } } this->seq_max = log.seq(); log_trace("start: %d, size: %d, min: %llu, max: %llu", start, size, seq_min, seq_max); }
void compile_key(const char *key) { unsigned char b = 0; if (!set_pedal_type(KEY_TYPE)) { fprintf(stderr, "Invalid combination of options\n"); usage(); } if (!encode_key(key, &b)) { fprintf(stderr, "Cannot encode key '%s'\n", key); exit(1); } curr_pedal->data[3] = b; }
void compile_string_key(const char *key) { unsigned char b; if (!set_pedal_type(STRING_TYPE)) { fprintf(stderr, "Invalid combination of options\n"); usage(); } if (!encode_key(key, &b)) { fprintf(stderr, "Cannot encode key '%s'\n", key); exit(1); } compile_string_data(&b, 1); }
int PersistentSyncLogQueue::find_by_pos(int pos, Synclog *log){ leveldb::ReadOptions read_options; std::string val; //log_debug("get pos: %d", pos); std::string key_buf = encode_key(pos); leveldb::Status s = meta_db->Get(read_options, key_buf, &val); if(s.IsNotFound()){ return 0; } if(s.ok()){ if(val.size() < Synclog::MIN_SIZE){ return 0; } *log = Synclog(val); return 1; } return 0; }
static bool set_counter( KVector *v, const uint32_t pos, const uint8_t max_q, const uint8_t nread, const uint8_t dimer, const uint8_t gc, const uint8_t hp, const uint8_t qual, bool mismatch ) { bool res = false; counter_union u; uint64_t key = encode_key( pos, max_q, nread, dimer, gc, hp, qual ); if ( KVectorGetU64 ( v, key, &(u.value) ) == 0 ) { u.counters.total++; if ( mismatch ) { u.counters.mismatch++; } } else { u.counters.total = 1; res = true; if ( mismatch ) { u.counters.mismatch = 1; } else { u.counters.mismatch = 0; } } KVectorSetU64 ( v, key, u.value ); return res; }
int l_search_do(struct ldapsearch *s, const char *lookupkey, int (*callback_func)(const char *utf8_name, const char *address, void *callback_arg), void *callback_arg) { char *k; const char *filter; int rc_code; int found; k=encode_key(lookupkey); if (!k) return -1; filter=getenv("LDAP_SEARCH_FILTER_EXACT"); if (!filter) filter="(|(uid=@)(sn=@)(cn=@))"; rc_code=l_search_do_filter(s, callback_func, callback_arg, filter, k, &found); if (rc_code == 0 && !found) { filter=getenv("LDAP_SEARCH_FILTER_APPROX"); if (!filter) filter="(|(uid=@*)(sn=@*)(mail=@*)(cn=@*))"; rc_code=l_search_do_filter(s, callback_func, callback_arg, filter, k, &found); } free(k); return rc_code; }
static void get_counter( KVector *v, const uint32_t pos, const uint8_t max_q, const uint8_t nread, const uint8_t dimer, const uint8_t gc, const uint8_t hp, const uint8_t qual, uint32_t *total, uint32_t *mismatch ) { counter_union u; uint64_t key = encode_key( pos, max_q, nread, dimer, gc, hp, qual ); if ( KVectorGetU64 ( v, key, &(u.value) ) == 0 ) { *total = u.counters.total; *mismatch = u.counters.mismatch; } else { *total = 0; *mismatch = 0; } }
void request_perform(const RequestParams *params, S3RequestContext *context) { Request *request; S3Status status; #define return_status(status) \ (*(params->completeCallback))(status, 0, params->callbackData); \ return // These will hold the computed values RequestComputedValues computed; // Validate the bucket name if (params->bucketContext.bucketName && ((status = S3_validate_bucket_name (params->bucketContext.bucketName, params->bucketContext.uriStyle)) != S3StatusOK)) { return_status(status); } // Compose the amz headers if ((status = compose_amz_headers(params, &computed)) != S3StatusOK) { return_status(status); } // Compose standard headers if ((status = compose_standard_headers (params, &computed)) != S3StatusOK) { return_status(status); } // URL encode the key if ((status = encode_key(params, &computed)) != S3StatusOK) { return_status(status); } // Compute the canonicalized amz headers canonicalize_amz_headers(&computed); // Compute the canonicalized resource canonicalize_resource(params->bucketContext.bucketName, params->subResource, computed.urlEncodedKey, computed.canonicalizedResource); // Compose Authorization header if ((status = compose_auth_header(params, &computed)) != S3StatusOK) { return_status(status); } // Get an initialized Request structure now if ((status = request_get(params, &computed, &request)) != S3StatusOK) { return_status(status); } // If a RequestContext was provided, add the request to the curl multi if (context) { CURLMcode code = curl_multi_add_handle(context->curlm, request->curl); if (code == CURLM_OK) { if (context->requests) { request->prev = context->requests->prev; request->next = context->requests; context->requests->prev->next = request; context->requests->prev = request; } else { context->requests = request->next = request->prev = request; } } else { if (request->status == S3StatusOK) { request->status = (code == CURLM_OUT_OF_MEMORY) ? S3StatusOutOfMemory : S3StatusInternalError; } request_finish(request); } } // Else, perform the request immediately else { CURLcode code = curl_easy_perform(request->curl); if ((code != CURLE_OK) && (request->status == S3StatusOK)) { request->status = request_curl_code_to_status(code); } // Finish the request, ensuring that all callbacks have been made, and // also releases the request request_finish(request); } }
static int sdp_encode (session_desc_t *sptr, sdp_encode_t *se) { int temp, temp1; media_desc_t *mptr; char buffer[80]; if (sptr->create_addr_type == NULL || sptr->create_addr == NULL) { return (ESDP_ORIGIN); } ADD_STR_TO_ENCODE_WITH_RETURN(se, "v=0\no="); ADD_STR_TO_ENCODE_WITH_RETURN(se, sptr->orig_username == NULL ? "-" : sptr->orig_username); sprintf(buffer, " "D64" "D64" IN ", sptr->session_id, sptr->session_version); ADD_STR_TO_ENCODE_WITH_RETURN(se, buffer); ADD_STR_TO_ENCODE_WITH_RETURN(se, sptr->create_addr_type); ADD_STR_TO_ENCODE_WITH_RETURN(se, " "); ADD_STR_TO_ENCODE_WITH_RETURN(se, sptr->create_addr); ADD_STR_TO_ENCODE_WITH_RETURN(se, "\ns="); ADD_STR_TO_ENCODE_WITH_RETURN(se, sptr->session_name); ADD_STR_TO_ENCODE_WITH_RETURN(se, "\n"); if (sptr->session_desc != NULL) { ADD_STR_TO_ENCODE_WITH_RETURN(se, "i="); ADD_STR_TO_ENCODE_WITH_RETURN(se, sptr->session_desc); ADD_STR_TO_ENCODE_WITH_RETURN(se, "\n"); } if (sptr->uri != NULL) { ADD_STR_TO_ENCODE_WITH_RETURN(se, "u="); ADD_STR_TO_ENCODE_WITH_RETURN(se, sptr->uri); ADD_STR_TO_ENCODE_WITH_RETURN(se, "\n"); } CHECK_RETURN(encode_string_list(sptr->admin_email, se, "e=", &temp)); CHECK_RETURN(encode_string_list(sptr->admin_phone, se, "p=", &temp1)); if (temp + temp1 == 0) { ADD_STR_TO_ENCODE_WITH_RETURN(se, "e=NONE\n"); } if (sptr->session_connect.used) { CHECK_RETURN(encode_connect(&sptr->session_connect, se)); } CHECK_RETURN(encode_bandwidth(sptr->session_bandwidth, se)); CHECK_RETURN(encode_time(sptr->time_desc, se)); CHECK_RETURN(encode_time_adj(sptr->time_adj_desc, se)); CHECK_RETURN(encode_key(&sptr->key, se)); if (sptr->control_string) { ADD_STR_TO_ENCODE_WITH_RETURN(se, "a=control:"); ADD_STR_TO_ENCODE_WITH_RETURN(se, sptr->control_string); ADD_STR_TO_ENCODE_WITH_RETURN(se, "\n"); } CHECK_RETURN(encode_category(sptr->category_list, se)); if (sptr->keywds) { ADD_STR_TO_ENCODE_WITH_RETURN(se, "u="); ADD_STR_TO_ENCODE_WITH_RETURN(se, sptr->uri); ADD_STR_TO_ENCODE_WITH_RETURN(se, "\n"); } CHECK_RETURN(encode_conf_type(sptr, se)); if (sptr->tool) { ADD_STR_TO_ENCODE_WITH_RETURN(se, "a=tool:"); ADD_STR_TO_ENCODE_WITH_RETURN(se, sptr->tool); ADD_STR_TO_ENCODE_WITH_RETURN(se, "\n"); } if (sptr->charset) { ADD_STR_TO_ENCODE_WITH_RETURN(se, "a=charset:"); ADD_STR_TO_ENCODE_WITH_RETURN(se, sptr->charset); ADD_STR_TO_ENCODE_WITH_RETURN(se, "\n"); } if (sptr->sdplang) { ADD_STR_TO_ENCODE_WITH_RETURN(se, "a=sdplang:"); ADD_STR_TO_ENCODE_WITH_RETURN(se, sptr->sdplang); ADD_STR_TO_ENCODE_WITH_RETURN(se, "\n"); } if (sptr->lang) { ADD_STR_TO_ENCODE_WITH_RETURN(se, "a=lang:"); ADD_STR_TO_ENCODE_WITH_RETURN(se, sptr->lang); ADD_STR_TO_ENCODE_WITH_RETURN(se, "\n"); } if (sptr->etag) { ADD_STR_TO_ENCODE_WITH_RETURN(se, "a=etag:"); ADD_STR_TO_ENCODE_WITH_RETURN(se, sptr->etag); ADD_STR_TO_ENCODE_WITH_RETURN(se, "\n"); } CHECK_RETURN(encode_range(&sptr->session_range, se)); CHECK_RETURN(encode_a_ints(sptr->recvonly, sptr->sendrecv, sptr->sendonly, se)); CHECK_RETURN(encode_string_list(sptr->unparsed_a_lines, se, "", NULL)); mptr = sptr->media; while (mptr != NULL) { CHECK_RETURN(encode_media(mptr, se)); mptr = mptr->next; } return (0); }
static int encode_media (media_desc_t *mptr, sdp_encode_t *se) { format_list_t *fptr; char buffer[80]; ADD_STR_TO_ENCODE_WITH_RETURN(se, "m="); ADD_STR_TO_ENCODE_WITH_RETURN(se, mptr->media); sprintf(buffer, " %u", mptr->port); ADD_STR_TO_ENCODE_WITH_RETURN(se, buffer); if (mptr->num_ports) { sprintf(buffer,"/%u", mptr->num_ports); ADD_STR_TO_ENCODE_WITH_RETURN(se, buffer); } ADD_STR_TO_ENCODE_WITH_RETURN(se, " "); ADD_STR_TO_ENCODE_WITH_RETURN(se, mptr->proto); fptr = mptr->fmt; while (fptr != NULL) { ADD_STR_TO_ENCODE_WITH_RETURN(se, " "); ADD_STR_TO_ENCODE_WITH_RETURN(se, fptr->fmt); fptr = fptr->next; } ADD_STR_TO_ENCODE_WITH_RETURN(se, "\n"); if (mptr->media_desc) { ADD_STR_TO_ENCODE_WITH_RETURN(se, "i="); ADD_STR_TO_ENCODE_WITH_RETURN(se, mptr->media_desc); ADD_STR_TO_ENCODE_WITH_RETURN(se, "\n"); } if (mptr->media_connect.used) { CHECK_RETURN(encode_connect(&mptr->media_connect, se)); } CHECK_RETURN(encode_bandwidth(mptr->media_bandwidth, se)); CHECK_RETURN(encode_key(&mptr->key, se)); if (mptr->ptime_present) { ADD_STR_TO_ENCODE_WITH_RETURN(se, "a=ptime:"); sprintf(buffer, "%u\n", mptr->ptime); ADD_STR_TO_ENCODE_WITH_RETURN(se, buffer); } if (mptr->quality_present) { ADD_STR_TO_ENCODE_WITH_RETURN(se, "a=quality:"); sprintf(buffer, "%u\n", mptr->quality); ADD_STR_TO_ENCODE_WITH_RETURN(se, buffer); } if (mptr->framerate_present) { ADD_STR_TO_ENCODE_WITH_RETURN(se, "a=framerate:"); // 2005.04.12 Sky modify : change the type of double to the string type #if 0 sprintf(buffer, "%g\n", mptr->framerate); ADD_STR_TO_ENCODE_WITH_RETURN(se, buffer); #else ADD_STR_TO_ENCODE_WITH_RETURN(se, mptr->framerate); ADD_STR_TO_ENCODE_WITH_RETURN(se, "\n"); #endif // 2005.04.12 End of modification } if (mptr->control_string) { ADD_STR_TO_ENCODE_WITH_RETURN(se, "a=control:"); ADD_STR_TO_ENCODE_WITH_RETURN(se, mptr->control_string); ADD_STR_TO_ENCODE_WITH_RETURN(se, "\n"); } if (mptr->sdplang) { ADD_STR_TO_ENCODE_WITH_RETURN(se, "a=sdplang:"); ADD_STR_TO_ENCODE_WITH_RETURN(se, mptr->sdplang); ADD_STR_TO_ENCODE_WITH_RETURN(se, "\n"); } if (mptr->lang) { ADD_STR_TO_ENCODE_WITH_RETURN(se, "a=lang:"); ADD_STR_TO_ENCODE_WITH_RETURN(se, mptr->lang); ADD_STR_TO_ENCODE_WITH_RETURN(se, "\n"); } fptr = mptr->fmt; while (fptr != NULL) { if (fptr->rtpmap != NULL) { ADD_STR_TO_ENCODE_WITH_RETURN(se, "a=rtpmap:"); ADD_STR_TO_ENCODE_WITH_RETURN(se, fptr->fmt); ADD_STR_TO_ENCODE_WITH_RETURN(se, " "); ADD_STR_TO_ENCODE_WITH_RETURN(se, fptr->rtpmap->encode_name); sprintf(buffer, "/%u", fptr->rtpmap->clock_rate); ADD_STR_TO_ENCODE_WITH_RETURN(se, buffer); if (fptr->rtpmap->encode_param != 0) { sprintf(buffer, "/%u", fptr->rtpmap->encode_param); ADD_STR_TO_ENCODE_WITH_RETURN(se, buffer); } ADD_STR_TO_ENCODE_WITH_RETURN(se, "\n"); } if (fptr->fmt_param != NULL) { ADD_STR_TO_ENCODE_WITH_RETURN(se, "a=fmtp:"); ADD_STR_TO_ENCODE_WITH_RETURN(se, fptr->fmt); ADD_STR_TO_ENCODE_WITH_RETURN(se, " "); ADD_STR_TO_ENCODE_WITH_RETURN(se, fptr->fmt_param); ADD_STR_TO_ENCODE_WITH_RETURN(se, "\n"); } fptr = fptr->next; } CHECK_RETURN(encode_a_ints(mptr->recvonly, mptr->sendrecv, mptr->sendonly, se)); CHECK_RETURN(encode_orient(mptr, se)); CHECK_RETURN(encode_range(&mptr->media_range, se)); CHECK_RETURN(encode_string_list(mptr->unparsed_a_lines, se, "", NULL)); return (0); }