static void test_kdc_remove_lookaside_multiple(void **state) { struct entry *e1; krb5_context context = *state; krb5_data req1 = string2data("I'm a test request"); krb5_data rep1 = string2data("I'm a test response"); krb5_data req2 = string2data("I'm a different test request"); e1 = insert_entry(context, &req1, &rep1, 0); insert_entry(context, &req2, NULL, 0); kdc_remove_lookaside(context, &req2); assert_null(k5_hashtab_get(hash_table, req2.data, req2.length)); assert_ptr_equal(k5_hashtab_get(hash_table, req1.data, req1.length), e1); assert_int_equal(num_entries, 1); assert_int_equal(total_size, entry_size(&req1, &rep1)); kdc_remove_lookaside(context, &req1); assert_null(k5_hashtab_get(hash_table, req1.data, req1.length)); assert_int_equal(num_entries, 0); assert_int_equal(total_size, 0); }
/* XXX - still dangerous ... */ static inline int swap_entries(linked_list_t *list, size_t pos1, size_t pos2) { list_entry_t *e1; list_entry_t *e2; if(pos2 > pos1) { e2 = fetch_entry(list, pos2); insert_entry(list, e2, pos1); e1 = fetch_entry(list, pos1+1); insert_entry(list, e1, pos2); } else if(pos1 > pos2) { e1 = fetch_entry(list, pos1); insert_entry(list, e1, pos2); e2 = fetch_entry(list, pos2+1); insert_entry(list, e2, pos1); } else return -1; /* TODO - Unimplemented */ return 0; }
static void test_kdc_check_lookaside_hit_multiple(void **state) { struct entry *e1, *e2; krb5_boolean result; krb5_data *result_data; krb5_context context = *state; krb5_data req1 = string2data("I'm a test request"); krb5_data rep1 = string2data("I'm a test response"); krb5_data req2 = string2data("I'm a different test request"); e1 = insert_entry(context, &req1, &rep1, 0); e2 = insert_entry(context, &req2, NULL, 0); result = kdc_check_lookaside(context, &req1, &result_data); assert_true(result); assert_true(data_eq(rep1, *result_data)); assert_int_equal(hits, 1); assert_int_equal(e1->num_hits, 1); assert_int_equal(e2->num_hits, 0); krb5_free_data(context, result_data); /* Set result_data so we can verify that it is reset to NULL. */ result_data = &req1; result = kdc_check_lookaside(context, &req2, &result_data); assert_true(result); assert_null(result_data); assert_int_equal(hits, 2); assert_int_equal(e1->num_hits, 1); assert_int_equal(e2->num_hits, 1); }
static void test_insert_entry_multiple(void **state) { struct entry *e1, *e2; krb5_context context = *state; krb5_data req1 = string2data("I'm a test request"); krb5_data rep1 = string2data("I'm a test response"); krb5_data req2 = string2data("I'm a different test request"); e1 = insert_entry(context, &req1, &rep1, 20); assert_ptr_equal(k5_hashtab_get(hash_table, req1.data, req1.length), e1); assert_ptr_equal(K5_TAILQ_FIRST(&expiration_queue), e1); assert_true(data_eq(e1->req_packet, req1)); assert_true(data_eq(e1->reply_packet, rep1)); assert_int_equal(e1->timein, 20); e2 = insert_entry(context, &req2, NULL, 30); assert_ptr_equal(k5_hashtab_get(hash_table, req2.data, req2.length), e2); assert_ptr_equal(K5_TAILQ_LAST(&expiration_queue,entry_queue), e2); assert_true(data_eq(e2->req_packet, req2)); assert_int_equal(e2->reply_packet.length, 0); assert_int_equal(e2->timein, 30); }
static void add_keyword (const char *name, hash_table *keywords) { if (name == NULL) default_keywords = false; else { const char *end; int argnum1; int argnum2; const char *colon; if (keywords->table == NULL) init_hash (keywords, 100); split_keywordspec (name, &end, &argnum1, &argnum2); /* The characters between name and end should form a valid C identifier. A colon means an invalid parse in split_keywordspec(). */ colon = strchr (name, ':'); if (colon == NULL || colon >= end) { if (argnum1 == 0) argnum1 = 1; insert_entry (keywords, name, end - name, (void *) (long) (argnum1 + (argnum2 << 10))); } } }
int _stx_dns_cache_getaddrlist(const char *hostname, struct in_addr *addrs, int *num_addrs, st_utime_t timeout, int rotate) { char host[128]; int n, count; if (!_stx_dns_cache) return _stx_dns_getaddrlist(hostname, addrs, num_addrs, timeout); for (n = 0; n < sizeof(host) - 1 && hostname[n]; n++) { host[n] = tolower(hostname[n]); } host[n] = '\0'; if (lookup_entry(host, addrs, num_addrs, rotate)) return 0; count = MAX_HOST_ADDRS; if (_stx_dns_getaddrlist(host, addr_list, &count, timeout) < 0) return -1; n = STX_MIN(*num_addrs, count); memcpy(addrs, addr_list, n * sizeof(*addrs)); *num_addrs = n; insert_entry(host, addr_list, count); return 0; }
int get_args_entries(int opt_idx, int opt, t_lst **lst, char **argv) { int idx; t_blk *blk; int len[6]; int nb_files; idx = 0; nb_files = 0; my_bzero(len, 6 * sizeof(len[0])); while (++idx < opt_idx) { if ((blk = get_entry(argv[idx], opt | O_ARG, len))) { if (insert_entry(lst, blk, opt, argv[idx]) > 0) ++nb_files; free(blk); } else if (blk == (void *)-1) { print_error(argv[idx], strerror(errno)); exit(2); } } return (nb_files > 0 ? nb_files - 1 : 0); }
/////////////////////////////////////////////////////////////////////////////////////////////////// //-- void BPTree::insert(pKey_Attr pPrimKey, _F_FileAddr pRec) { setPath(); Key_Location KeyLoca; if(search(pPrimKey, &KeyLoca)) throw 1024; else insert_entry(KeyLoca.ptr, pPrimKey, pRec); }
/* * Function: Bt_Entry* insert_entry( Bt_Entry* root, Bt_Entry* entry, compare_item cmp ) * Description: insert entry at the left of the root which is less than root, or right if more * Input: root: the root entry * entry: the entry to be inserted * cmp: the item field comparing function * Output: none * Return: Bt_Entry*: the root entry * Others: none */ Bt_Entry* insert_entry( Bt_Entry* root, Bt_Entry* entry, compare_item cmp ) { if( NULL == root ) { root = entry; return root; } if( cmp( entry->item, root->item ) > 0 ) { root->right = insert_entry( root->right, entry, cmp ); }else { root->left = insert_entry( root->left, entry, cmp ); } return root; }
// Adds an entry to the in-memory database, and then writes to the on-disk database seen_entry_t *insert_entry_file (char *nick, unsigned int seen_date) { seen_entry_t *entry = insert_entry (nick, seen_date); entry->offset = lseek (seendb, 0, SEEK_END); write (seendb, entry->nick, 32); write (seendb, &(entry->seen_date), 4); return entry; }
static inline int move_entry(linked_list_t *list, size_t srcPos, size_t dstPos) { list_entry_t *e; e = fetch_entry(list, srcPos); if(e) { if(insert_entry(list, e, dstPos) == 0) return 0; else { if(insert_entry(list, e, srcPos) != 0) { //fprintf(stderr, "Can't restore entry at index %lu while moving to %lu\n", srcPos, dstPos); } } } /* TODO - Unimplemented */ return -1; }
/* * Function: Bt* init_bt( Bt* bt, void** array, int size, compare_item cmp ) * Description: init one bt with the array of two dimensions * Input: bt: the bt to be inited * array: the initial array for bt * size: array size * cmp: item field comparing function * Output: none * Return: the bt that has been inited * Others: none */ Bt* init_bt( Bt* bt, void** array, int size, compare_item cmp ) { int i = 0; Bt_Entry* entry; for( i = 0; i < size; i++ ) { entry = create_entry( array[i] ); bt->root = insert_entry( bt->root, entry, cmp ); } return bt; }
/********************************************************************* * Process message Functions * *********************************************************************/ void process_arp_request(int sockfd, struct arp_msg *msg) { int i; struct arp_cache_entry cache_entry; bzero(&cache_entry, sizeof(cache_entry)); cache_entry.connfd = sockfd; cache_entry.sll_ifindex = my_index; cache_entry.sll_hatype = msg->hrd; strcpy(cache_entry.ip, msg->sender_ip); for (i = 0; i < IF_HADDR; i++){ cache_entry.mac[i] = msg->sender_mac[i]; } cache_entry.isComplete = 1; cache_entry.isValid = 1; cache_entry.isLocal = 0; // Pertains to the request, insert new entry if (strcmp(my_ip, msg->target_ip) == 0 || isDest(msg->target_ip) ) { puts("----->ARP: DESTINATION."); if ((i = search_cache(msg->sender_ip) == -1)) { puts("----->ARP: I DO pertain to this request. Create new entry for this <senderIP, senderMAC>.\n"); if (insert_entry(cache_entry) < 0) { perror("unable to insert cache entry."); } } else { puts("----->ARP: I DO pertain to this request. Update <senderIP, senderMAC>.\n"); update_cache(i, msg); } // Send ARP reply msg->op = ARP_REP; for (i = 0; i < INET_ADDRSTRLEN; i ++) { msg->target_ip[i] = msg->sender_ip[i]; } printf("Target ip:%s\n", msg->target_ip); for (i = 0; i < IF_HADDR; i++){ msg->target_mac[i] = msg->sender_mac[i]; } strcpy(msg->sender_ip, my_ip); for (i = 0; i < IF_HADDR; i++){ msg->sender_mac[i] = if_hwaddr[my_index][i]; } puts("----->ARP: I'm responsible for sending reply..."); send_arp_msg(sockfd, msg->target_mac, msg); puts("----->ARP: Reply sent.\n"); } else if ((i = search_cache(msg->sender_ip) != -1)) { // There is an existing entry, update puts("----->ARP: I'm not pertain to this request, but I have an existing entry, updating...\n"); update_cache(i, msg); } }
int list_insert_value(linked_list_t *list, void *val, size_t pos) { int res; list_entry_t *new_entry = create_entry(); if(!new_entry) return -1; new_entry->value = val; res=insert_entry(list, new_entry, pos); if(res != 0) destroy_entry(new_entry); return res; }
static void test_kdc_remove_lookaside(void **state) { krb5_context context = *state; krb5_data req = string2data("I'm a test request"); krb5_data rep = string2data("I'm a test response"); insert_entry(context, &req, &rep, 0); kdc_remove_lookaside(context, &req); assert_null(k5_hashtab_get(hash_table, req.data, req.length)); assert_int_equal(num_entries, 0); assert_int_equal(total_size, 0); }
static void test_discard_entry_no_response(void **state) { struct entry *e; krb5_context context = *state; krb5_data req = string2data("I'm a test request"); e = insert_entry(context, &req, NULL, 0); discard_entry(context, e); assert_null(k5_hashtab_get(hash_table, req.data, req.length)); assert_int_equal(num_entries, 0); assert_int_equal(total_size, 0); }
void process_un(int sockfd, struct hwaddr *hwaddr_info) { int index; int i; // puts("----->ARP:processing domain sockets..."); if ((index = search_cache(hwaddr_info->sll_ip)) == -1) { puts("----->ARP: domain sockets: no cache entry found..."); struct arp_cache_entry cache_entry; struct arp_msg msg; bzero(&msg, sizeof(msg)); puts("----->ARP: domain sockets: create a new incomplete entry..."); // Insert a temp entry cache_entry.connfd = sockfd; cache_entry.sll_ifindex = my_index; cache_entry.sll_hatype = hwaddr_info->sll_hatype; strcpy(cache_entry.ip, hwaddr_info->sll_ip); cache_entry.isComplete = 0; cache_entry.isValid = 1; cache_entry.isLocal = 0; if (insert_entry(cache_entry) < 0) { perror("unable to insert cache entry."); } puts("----->ARP: domain sockets: broadcast ARP_REQ..."); // Send ARP request msg.op = ARP_REQ; strcpy(msg.sender_ip, my_ip); strcpy(msg.target_ip, hwaddr_info->sll_ip); msg.id = htons(ARP_ID); send_arp_msg(if_sockfd, broadcast_mac, &msg); } else { puts("----->ARP: domain sockets: existing entry found..."); if (cache[index].isComplete == 1){ cache[index].connfd = sockfd; for (i = 0; i < ETH_ALEN; i++){ hwaddr_info->sll_addr[i] = cache[index].mac[i]; } // strcpy(hwaddr_info->sll_addr, cache[index].mac); hwaddr_info->sll_ifindex = cache[index].sll_ifindex; puts("----->ARP: domain sockets: sending reply through domain socket..."); send_un(cache[index].connfd, hwaddr_info); close(cache[index].connfd); un_connfd = -1; puts("----->ARP: domain sockets: sending OK, connection closed."); } } puts("----->ARP:domain sockets processed..."); }
static void test_insert_entry_no_response(void **state) { struct entry *e; krb5_context context = *state; krb5_data req = string2data("I'm a test request"); e = insert_entry(context, &req, NULL, 10); assert_ptr_equal(k5_hashtab_get(hash_table, req.data, req.length), e); assert_ptr_equal(K5_TAILQ_FIRST(&expiration_queue), e); assert_true(data_eq(e->req_packet, req)); assert_int_equal(e->reply_packet.length, 0); assert_int_equal(e->timein, 10); }
/* top-level function for adding a record */ void add_record() { char catalog_number[MAX_STRING]; char cd_title[MAX_STRING]; char cd_type[MAX_STRING]; char cd_artist[MAX_STRING]; char cd_entry[MAX_STRING * 4 + 8]; int screenrow = MESSAGE_LINE; int screencol = 10; clear_all_screen(); // heading mvprintw(screenrow, screencol, "Enter new CD details"); screenrow += 2; // print prompt and get each response mvprintw(screenrow, screencol, " Catalog number: "); get_string(catalog_number); screenrow++; mvprintw(screenrow, screencol, " CD title: "); get_string(cd_title); screenrow++; mvprintw(screenrow, screencol, " CD type: "); get_string(cd_type); screenrow++; mvprintw(screenrow, screencol, " CD artist: "); get_string(cd_artist); screenrow++; // make a single entry string with all the data sprintf(cd_entry, "%s, %s, %s, %s", catalog_number, cd_title, cd_type, cd_artist); // get confirmation before saving mvprintw(PROMPT_LINE - 2, 5, "About to add this new entry:"); mvprintw(PROMPT_LINE, 5, cd_entry); refresh(); move(PROMPT_LINE, 0); if (get_confirm()) { // save in database file, and update global constants to reflect the // 'active' cd. insert_entry(cd_entry); strcpy(current_cd, cd_title); strcpy(current_cat, catalog_number); }; }
/* return old entry at pos */ static inline list_entry_t *subst_entry(linked_list_t *list, uint32_t pos, list_entry_t *entry) { list_entry_t *old; MUTEX_LOCK(&list->lock); old = fetch_entry(list, pos); if(!old) return NULL; insert_entry(list, entry, pos); MUTEX_UNLOCK(&list->lock); /* XXX - NO CHECK ON INSERTION */ return old; }
static struct team_extra * do_get_entry( struct xuser_mongo_cnts_state *state, int user_id) { struct team_extra *extra = NULL; bson *query = NULL; int pos = 0, count = 0; bson **results = NULL; if (user_id <= 0) return NULL; if ((extra = find_entry(state, user_id, &pos))) return extra; query = bson_new(); bson_append_int32(query, "contest_id", state->contest_id); bson_append_int32(query, "user_id", user_id); bson_finish(query); count = state->plugin_state->common->i->query(state->plugin_state->common, "xuser", 0, 1, query, NULL, &results); if (count < 0) goto done; if (count > 1) { err("do_get_entry: multiple entries returned: %d", count); goto done; } if (count == 1) { if (!(extra = team_extra_bson_parse(results[0]))) { goto done; } } if (!extra) { XCALLOC(extra, 1); extra->user_id = user_id; extra->contest_id = state->contest_id; } insert_entry(state, user_id, extra, pos); done: if (query) bson_free(query); if (results) { for (int i = 0; i < count; ++i) { bson_free(results[i]); } xfree(results); } return extra; }
int main(int argc, char *argv[]) { ght_hash_table_t *p_table; ght_iterator_t iterator; const void *p_key; int *p_data; /* Create a new hash table */ if ( !(p_table = ght_create(128)) ) { fprintf(stderr, "Could not create hash table!\n"); return 1; } /* Insert a number of entries */ insert_entry(p_table, 0, "zero"); insert_entry(p_table, 1, "one"); insert_entry(p_table, 2, "two"); insert_entry(p_table, 3, "three"); insert_entry(p_table, 4, "four"); insert_entry(p_table, 5, "five"); insert_entry(p_table, 6, "six"); insert_entry(p_table, 7, "seven"); insert_entry(p_table, 8, "eight"); for (p_data = (int*)ght_first(p_table, &iterator, &p_key); p_data; p_data = (int*)ght_next(p_table, &iterator, &p_key)) { /* Print out the entry */ printf("%s: \t%d\n", (char*)p_key, *p_data); /* Free the data (the meta-data will be removed in ght_finalize below) */ free(p_data); } /* Remove the hash table */ ght_finalize(p_table); return 0; }
void branching(char c) { // branch to different tasks char sname[30]; switch (c) { case 'a': insert_entry(); break; case 'd': remove_entry(); break; case 'p': average(); break; default: printf("Invalid input\n"); } }
int WorkerThread::insert_query(void) { struct row_data data; data.num = __64bit_generator(); data.string_a = __generate_rand_string(256); data.string_b = __generate_rand_string(256); data.sha_digest = sha256(data.string_a + data.string_b + std::to_string(data.num)); // uint64_t num = __64bit_generator(); // std::string str1 = __generate_rand_string(256); // std::string str2 = __generate_rand_string(256); // std::string sha_digest = sha256(str1+str2+std::to_string(num)); //insert_entry(connection_string, num, str1, str2, sha_digest); insert_entry(connection_string, data); return 0; }
void insert_local_hw_cache(char ip[]) { struct arp_cache_entry cache_entry; int i; cache_entry.connfd = -1; strcpy(cache_entry.ip, ip); cache_entry.isComplete = 1; cache_entry.isLocal = 1; cache_entry.isValid = 1; for (i = 0; i < IF_HADDR; i++){ cache_entry.mac[i] = if_hwaddr[my_index][i]; } cache_entry.sll_hatype = HARD_TYPE; cache_entry.sll_ifindex = my_index; insert_entry(cache_entry); }
int list_insert_tagged_value(linked_list_t *list, tagged_value_t *tval, size_t pos) { int res = 0; list_entry_t *new_entry; if(tval) { new_entry = create_entry(); if(new_entry) { new_entry->tagged = 1; new_entry->value = tval; res = insert_entry(list, new_entry, pos); if(res != 0) destroy_entry(new_entry); } } return res; }
void __wrap_syslog(int severity, const char *fmt, ...) { va_list args; char *logmsg; logmsg = malloc(LOGLEN); if (!logmsg) return; memset(logmsg, 0, LOGLEN); va_start(args, fmt); vsnprintf(logmsg + strlen(logmsg), LOGLEN - strlen(logmsg), fmt, args); va_end(args); insert_entry(severity, logmsg, LOGLEN); return; }
static void test_kdc_check_lookaside_no_response(void **state) { struct entry *e; krb5_boolean result; krb5_data *result_data; krb5_context context = *state; krb5_data req = string2data("I'm a test request"); e = insert_entry(context, &req, NULL, 0); /* Set result_data so we can verify that it is reset to NULL. */ result_data = &req; result = kdc_check_lookaside(context, &req, &result_data); assert_true(result); assert_null(result_data); assert_int_equal(hits, 1); assert_int_equal(e->num_hits, 1); }
void init (void) { char nickbuf [32]; char *sdbpath; unsigned int timebuf; seen_entry_t *entp; int i; for (i = 0; i < 128; i++) table [i] = NULL; sdbpath = alloca (9 + strlen (localdir)); sprintf (sdbpath, "%s/seen.db", localdir); seendb = open (sdbpath, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); if (seendb < 0) { eprint (0, "seen: Couldn't open or create database file."); return; } while (1) { if (read (seendb, nickbuf, 32) != 32) break; if (read (seendb, &timebuf, 4) != 4) break; entp = insert_entry (nickbuf, timebuf); entp->offset = lseek (seendb, 0, SEEK_CUR) - 36; } module_registerfunc (&joinListeners, seenJoin, modname); module_registerfunc (&nickListeners, seenNick, modname); module_registerfunc (&partListeners, seenPart, modname); module_registerfunc (&privmsgListeners, seenPrivmsg, modname); module_registerfunc (&quitListeners, seenQuit, modname); return; }
static void test_kdc_check_lookaside_hit(void **state) { struct entry *e; krb5_boolean result; krb5_data *result_data; krb5_context context = *state; krb5_data req = string2data("I'm a test request"); krb5_data rep = string2data("I'm a test response"); e = insert_entry(context, &req, &rep, 0); result = kdc_check_lookaside(context, &req, &result_data); assert_true(result); assert_true(data_eq(rep, *result_data)); assert_int_equal(hits, 1); assert_int_equal(e->num_hits, 1); krb5_free_data(context, result_data); }