int ac_rtld_config::translate(unsigned code, unsigned *result) { if (config_loaded) { if(hash_get_value (hashtable, code, result)==FINE) return 0; } return -1; }
unsigned int hash_table_get_position(hash_table_t *hash_table, char *string) { unsigned long hash_value = hash_get_value(string); unsigned int position = hash_value % (1 << hash_table->exponent); if (position < hash_table->next_split) { position = hash_value % (1 << (hash_table->exponent + 1)); } return position; }
//get the lex_entry_t associated with the word. FRISO_API lex_entry_t friso_dic_get( friso_dic_t dic, friso_lex_t lex, fstring word ) { if ( lex >= 0 && lex < __FRISO_LEXICON_LENGTH__ ) { return ( lex_entry_t ) hash_get_value( dic[lex], word ); } return NULL; }
/** ** DESCRIPTION ** Add hashtable item for each link found in a line from the stream ** if hostname or ip != NULL then checks if link refers to hostname or ip ** includes arguments after '?' as query string ** ** RETURN VALUE ** The number of links found **/ int parse_links( const char * line, const char * hostname, const char * ip, char * curdir ) { struct linkz * lk; char * ptr = NULL; char * linkn = NULL; char * query = NULL; char * tfree = NULL; char * start = NULL; int count = 0; int proto = 0; int match = 0; int found = 0; int updat = 0; if ( line ) ptr = xstrdup(line); else return 0; if ( !ptr ) return 0; tfree = ptr; do { start = ptr ; if ( (ptr = xstrstr( start, HREF )) ) { ptr += strlen ( HREF ); NEXTFIELD( ptr ); found = 1; } else if ( (ptr = xstrstr( start, FRAME )) ) { if ( (ptr += strlen( FRAME )) && (ptr = xstrstr( ptr, SRC )) ) { if ( (ptr += strlen( SRC )) ) { NEXTFIELD( ptr ); found = 1; } } } if ( !ISNULL(ptr) && found ) { found = 0; if ( !strncasecmp( ptr, "http://", 7 )) proto = 7; else if ( !strncasecmp( ptr, "javascript:", 11 )) continue; else if ( !strncasecmp( ptr, "mailto:", 7 )) continue; else if ( !strncasecmp( ptr, "news:", 5 )) continue; else if ( !strncasecmp( ptr, "ftp://", 6 )) continue; else if ( !strncasecmp( ptr, "https://", 8 )) continue; if ( proto ) { ptr += proto; proto = 0; if ( hostname ) { if ( !strncasecmp( ptr, hostname, strlen(hostname)) ) match = 1; } if ( ip ) { if ( !strncasecmp( ptr, ip, strlen(ip)) ) match = 1; } if ( !match && (hostname || ip) ) { continue; } else { ptr = strchr( ptr, '/' ); match = 0; } } if ( !ISNULL(ptr) ) { boolean relative = FALSE; char * p = strpbrk( ptr, "#\" '\t\r\n>" ); linkn = ptr; if ( p ) { ptr = p + 1; *p = 0; } if ( (query = strchr( linkn, '?')) ) *query++ = 0; updat = 0; if ( !linkn[0] || (linkn[0]=='/' && !linkn[2]) ) continue; if ( strpbrk( linkn, "=<>?&" ) ) continue; if ( !EXT_ISALLOWED( linkn ) ) { debug( "Skipping unallowed file type: %s\n", linkn ); continue; } if ( ISRELATIVE( linkn ) ) { relative = TRUE; linkn = fix_relative( linkn, curdir ); } if ( (lk = (struct linkz *)hash_get_value( linkn, HTlinks )) ) { if ( !query || ((query) && (lk->flags & LDYNAMIC)) ) continue; } lk = (struct linkz *)xmalloc(sizeof(struct linkz)); debug( "Link: %s\n", linkn ); if ( query ) { if ( updat ) lk->flags &= ~LVISITED; lk->flags |= LCACHED; lk->flags |= LDYNAMIC; lk->query = xstrdup( query ); debug( "Query: %s\n", query ); } hash_insert( linkn, lk, HTlinks ); if ( relative == TRUE ) xfree( linkn ); updat ^= updat; count++ ; } } } while( ptr ); xfree( tfree ); return count; }
int patch_relocation_section(unsigned int fd, unsigned int size, int rel_type, hash_node **hashtable, unsigned int match_endian) { unsigned int i; unsigned int entry_size = (rel_type == DT_REL) ? sizeof(Elf32_Rel) : sizeof(Elf32_Rela); unsigned int total = size / entry_size; if (rel_type == DT_REL) /* rel relocation type*/ { Elf32_Rel rel; unsigned int new_code, old_code, sym; for (i = 0; i < total; i++) { /* Read it. */ if (read(fd, &rel, sizeof(rel)) != sizeof(rel)) { fprintf(stderr, "Couldn't read REL relocation number %d.\n", i); return ACRELCONVERT_FUNC_ERROR; } /* Patch it. */ old_code = ELF32_R_TYPE(convert_endian(4, rel.r_info, match_endian)); sym = ELF32_R_SYM(convert_endian(4, rel.r_info, match_endian)); if (hash_get_value(hashtable, old_code, &new_code) == ACRELCONVERT_FUNC_ERROR) { fprintf(stderr, "Error: unrecognized relocation code 0x%X (%d), at relocation number %d\n", old_code, old_code, i); return ACRELCONVERT_FUNC_ERROR; } rel.r_info = convert_endian(4, ELF32_R_INFO(sym, new_code), match_endian); /* Write it back, patched. */ lseek(fd, - sizeof(rel), SEEK_CUR); if (write(fd, &rel, sizeof(rel)) != sizeof(rel)) { fprintf(stderr, "Error: couldn't write REL relocation number %d.\n", i); return ACRELCONVERT_FUNC_ERROR; } } } else /* rela relocation type */ { Elf32_Rela rela; unsigned int new_code, old_code, sym; for (i = 0; i < total; i++) { /* Read it. */ if (read(fd, &rela, sizeof(rela)) != sizeof(rela)) { fprintf(stderr, "Couldn't read RELA relocation number %d.\n", i); return ACRELCONVERT_FUNC_ERROR; } /* Patch it. */ old_code = ELF32_R_TYPE(convert_endian(4, rela.r_info, match_endian)); sym = ELF32_R_SYM(convert_endian(4, rela.r_info, match_endian)); if (hash_get_value(hashtable, old_code, &new_code) == ACRELCONVERT_FUNC_ERROR) { fprintf(stderr, "Error: unrecognized relocation code 0x%X (%d), at relocation number %d\n", old_code, old_code, i); return ACRELCONVERT_FUNC_ERROR; } rela.r_info = convert_endian(4, ELF32_R_INFO(sym, new_code), match_endian); /* Write it back, patched. */ lseek(fd, - sizeof(rela), SEEK_CUR); if (write(fd, &rela, sizeof(rela)) != sizeof(rela)) { fprintf(stderr, "Error: couldn't write RELA relocation number %d.\n", i); return ACRELCONVERT_FUNC_ERROR; } } } return ACRELCONVERT_FUNC_OK; }
void load_tests() { /*************************/ /* HANDLE CREATION TESTS */ /*************************/ // create a valid store handle char *valid_handle_args[] ={"VALID",hash_get_value(CONTEXT_KEY_DATA_VIP,context_hash),hash_get_value(CONTEXT_KEY_DATA_VIP_PORT,context_hash), "0","0",hc_itoa(HCERR_OK)}; test_case_t *valid_handle = create_test_case("hcoa.hcoa_store_object_create()[valid]", 6, valid_handle_args, (int (*)(void *, void *,void *))hcoa_store_create_handle); if (add_test_to_list(valid_handle) == NULL) { hc_test_log(LOG_ERROR_LEVEL, "Unable to add %s::%s to testlist\n", valid_handle->name, valid_handle->params); } // create an invalid store handle (NULL PTR for handle) char *invalid_handle_args[] ={"INVALID",hash_get_value(CONTEXT_KEY_DATA_VIP,context_hash),hash_get_value(CONTEXT_KEY_DATA_VIP_PORT,context_hash), "0","0",hc_itoa(HCERR_SESSION_CREATE_FAILED)}; test_case_t *invalid_handle = create_test_case("hcoa.hcoa_store_object_create()[invalid]", 6, invalid_handle_args, (int (*)(void *, void *,void *))hcoa_store_create_handle); invalid_handle->excluded = TRUE; //Exclude due to BUG 6316712 if (add_test_to_list(invalid_handle) == NULL) { hc_test_log(LOG_ERROR_LEVEL, "Unable to add %s::%s to testlist\n", invalid_handle->name, invalid_handle->params); } // create an invalid store handle (NULL PTR for host) char *invalid_host_args[] ={"VALID",NULL,hash_get_value(CONTEXT_KEY_DATA_VIP_PORT,context_hash), "0","0",hc_itoa(HCERR_SESSION_CREATE_FAILED)}; test_case_t *invalid_host = create_test_case("hcoa.hcoa_store_object_create()[invalidHost]", 6, invalid_host_args, (int (*)(void *, void *,void *))hcoa_store_create_handle); invalid_host->excluded = TRUE; //Exclude due to BUG 6316712 if (add_test_to_list(invalid_host) == NULL) { hc_test_log(LOG_ERROR_LEVEL, "Unable to add %s::%s to testlist\n", invalid_host->name, invalid_host->params); } // create an invalid store handle (clearly invalid port #) char *invalid_port_args[] ={"VALID",hash_get_value(CONTEXT_KEY_DATA_VIP,context_hash),"-1", "0","0",hc_itoa(HCERR_SESSION_CREATE_FAILED)}; test_case_t *invalid_handle_port = create_test_case("hcoa.hcoa_store_object_create()[invalidPort]", 6, invalid_port_args, (int (*)(void *, void *,void *))hcoa_store_create_handle); invalid_handle_port->excluded = TRUE; //Exclude due to BUG 6317187 if (add_test_to_list(invalid_handle_port) == NULL) { hc_test_log(LOG_ERROR_LEVEL, "Unable to add %s::%s to testlist\n", invalid_handle_port->name, invalid_handle_port->params); } // create an invalid store handle (negative chunk size) char *invalid_chunk_args[] ={"VALID",hash_get_value(CONTEXT_KEY_DATA_VIP,context_hash),hash_get_value(CONTEXT_KEY_DATA_VIP_PORT,context_hash), "-1","0",hc_itoa(HCERR_SESSION_CREATE_FAILED)}; test_case_t *invalid_handle_chunk = create_test_case("hcoa.hcoa_store_object_create()[invalidChunk]", 6, invalid_chunk_args, (int (*)(void *, void *,void *))hcoa_store_create_handle); invalid_handle_chunk->excluded = TRUE; //Exclude due to BUG 6317187 if (add_test_to_list(invalid_handle_chunk) == NULL) { hc_test_log(LOG_ERROR_LEVEL, "Unable to add %s::%s to testlist\n", invalid_handle_chunk->name, invalid_handle_chunk->params); } // create an invalid store handle (negative window size) char *invalid_window_args[] ={"VALID",hash_get_value(CONTEXT_KEY_DATA_VIP,context_hash),hash_get_value(CONTEXT_KEY_DATA_VIP_PORT,context_hash), "0","-1",hc_itoa(HCERR_SESSION_CREATE_FAILED)}; test_case_t *invalid_handle_window = create_test_case("hcoa.hcoa_store_object_create()[invalidWindow]", 6, invalid_window_args, (int (*)(void *, void *,void *))hcoa_store_create_handle); invalid_handle_window->excluded = TRUE; //Exclude due to BUG 6317187 if (add_test_to_list(invalid_handle_window) == NULL) { hc_test_log(LOG_ERROR_LEVEL, "Unable to add %s::%s to testlist\n", invalid_handle_window->name, invalid_handle_window->params); } /******************/ /* STORE OP TESTS */ /******************/ //store single file of random size char *single_file_args[] ={"1", "-1", "0"}; test_case_t *single_file = create_test_case("hcoa.hcoa_store()", 3, single_file_args, (int (*)(void *, void *,void *))hc_store_multiple_files); if (add_test_to_list(single_file) == NULL) { hc_test_log(LOG_ERROR_LEVEL, "Unable to add %s::%s to testlist\n", single_file->name, single_file->params); } //write multiple files of random with multiple handles char *mfmh_args[] ={"256", "-1", "0"}; test_case_t *multi_file_multi_handle = create_test_case("hcoa.hcoa_store()[multi]", 3, mfmh_args, (int (*)(void *, void *,void *))hc_store_multiple_files); if (add_test_to_list(multi_file_multi_handle) == NULL) { hc_test_log(LOG_ERROR_LEVEL, "Unable to add %s::%s to testlist\n", multi_file_multi_handle->name, multi_file_multi_handle->params); } //write multiple files of random size with a single handle char *mfsh_args[] ={"2", "-1", "1"}; test_case_t *multi_file_single_handle = create_test_case("hcoa.hcoa_store()[multi-reuse]", 3, mfsh_args, (int (*)(void *, void *,void *))hc_store_multiple_files); multi_file_single_handle->excluded = TRUE; if (add_test_to_list(multi_file_single_handle) == NULL) { hc_test_log(LOG_ERROR_LEVEL, "Unable to add %s::%s to testlist\n", multi_file_single_handle->name, multi_file_single_handle->params); } // attempt to write a file of 0 bytes char *empty_file_args[] ={"1", "0", "0"}; test_case_t *empty_file = create_test_case("hcoa.hcoa_store()", 3, empty_file_args, (int (*)(void *, void *,void *))hc_store_multiple_files); if (add_test_to_list(empty_file) == NULL) { hc_test_log(LOG_ERROR_LEVEL, "Unable to add %s::%s to testlist\n", empty_file->name, empty_file->params); } // attempt to write a large file // interestingly, this test works like champ against the emulator // just so-so against the real-deal (fails half the time against dev315) char *file_size = hash_get_value("bfs",context_hash); if (file_size == NULL) { file_size = "1GB"; } char *big_file_args[] ={"1", file_size,"1" }; test_case_t *big_file= create_test_case("hcoa.hcoa_store()[bigFile]", 3, big_file_args, (int (*)(void *, void *,void *))hc_store_multiple_files); if (add_test_to_list(big_file) == NULL) { hc_test_log(LOG_ERROR_LEVEL, "Unable to add %s::%s to testlist\n", big_file->name, big_file->params); } // attempt to write a file with out establishing a handle // attempt to store to an invalid host/port // attempt to write to an HC cluster that is up but can not fulfill the request /**********************/ /* HANDLE CLOSE TESTS */ /**********************/ //close a valid session //perform a close without first doing an open }
int hc_store_multiple_files(int * argc, char ** argv, char *note) { char *test_vip =hash_get_value(CONTEXT_KEY_DATA_VIP,context_hash); int test_vip_port =atoi(hash_get_value(CONTEXT_KEY_DATA_VIP_PORT,context_hash)); int first_time = TRUE; hcoa_store_handle_t *handle = NULL; int reuse_handle = TRUE; int err; hc_long_t size; int iters; if (test_vip == NULL) { hc_test_log(LOG_ERROR_LEVEL, "No data VIP has been provided.\n"); return TEST_ERROR; } if (*argc < 2) { hc_test_log(LOG_ERROR_LEVEL, "you must pass in the number of store operations you want to execute and the max size of each file.\n"); return TEST_ERROR; } iters = atoi(argv[0]); if (strcmp(argv[1], "-1") == 0) { // A -1 value means random size size = -1; } else { size = translate_size(argv[1]); // A -1 value means size is random if (size == -1) { hc_test_log(LOG_ERROR_LEVEL, "Invalid file size %s.\n", argv[1]); return TEST_ERROR; } } if (*argc <= 3) { reuse_handle = atoi(argv[2]); } hc_test_log(LOG_DEBUG_LEVEL, "about to store %d files to %s:%d.\n",iters, test_vip,test_vip_port); if ((err = hc_standalone_init()) != HCERR_OK) { hc_test_log(LOG_ERROR_LEVEL, "hc_standalone_init failed! Return code was %s\n",hc_decode_hcerr(err)); return TEST_ERROR; } else { hc_test_log(LOG_DEBUG_LEVEL, "hc_standalone_init succeeded!\n"); } for (int i = 0; i < iters;i++) { FILE *input_file; char file_name[1024]; hc_long_t sizegend; int in_file_fd = -1; if (first_time == TRUE || reuse_handle != TRUE) { if (handle != NULL) free (handle); if ((err = hcoa_store_object_create(&handle, test_vip, test_vip_port,0,0)) != HCERR_OK) { hc_test_log(LOG_ERROR_LEVEL, "Unable to create store handle! Return code was %s\n",hc_decode_hcerr(err)); return err; } else { hc_test_log(LOG_DEBUG_LEVEL, "hcoa_store_object_create succeeded!\n"); } first_time = FALSE; } if (size == -1) { size = rand(); } if ( ( sizegend=file_generator(size, rand(),file_name, input_file) ) != size) { hc_test_log(LOG_ERROR_LEVEL, "the size of the file generated, %ld, does not match the size requested %ld.\n", (long)sizegend,(long)size); return TEST_ERROR; } if((in_file_fd = open(file_name, O_RDONLY | O_BINARY)) == -1) { hc_test_log(LOG_ERROR_LEVEL, "Failed to open data file '%s' for store: %d\n", file_name, in_file_fd); return TEST_ERROR; } err = test_store (&read_from_file_data_source, (void *)in_file_fd, handle ); close(in_file_fd); remove(file_name); } hc_cleanup(); if (err != HCERR_OK) { hc_test_log(LOG_INFO_LEVEL, "Store operation returned %s.\n", hc_decode_hcerr(err)); return TEST_FAIL; } return TEST_PASS; }