void hyph_done(void) { if (hwdict) dict_free(hwdict); if (hydict) dict_free(hydict); if (hcodedict) dict_free(hcodedict); }
void conf_free(conf_t * self) { assert(self != NULL); free(self->post_pkgadd); list_free(self->repositories_hierarchy, free); dict_free(self->favourite_repositories, NULL); dict_free(self->locked_versions, free); aliases_free(self->aliases); dict_free(self->pkgmk_confs, free); free(self); }
static int megahal_reply(brain_t brain, list_t *input, list_t **output) { dict_t *keywords; list_t *current; struct timespec start; double surprise; double max_surprise; int ret; *output = NULL; ret = megahal_keywords(brain, input, &keywords); if (ret) return ret; ret = megahal_generate(brain, NULL, output); if (ret) { dict_free(&keywords); return ret; } if (!list_equal(input, *output)) list_free(output); ret = clock_gettime(CLOCK_MONOTONIC, &start); if (ret) { ret = -ECLOCK; goto fail; } max_surprise = -1.0; do { ret = megahal_generate(brain, keywords, ¤t); if (ret) goto fail; ret = megahal_evaluate(brain, keywords, current, &surprise); if (ret) goto fail; if (surprise > max_surprise && !list_equal(input, current)) { max_surprise = surprise; list_free(output); *output = current; } else { list_free(¤t); } } while(!megahal_timeout(start)); dict_free(&keywords); return OK; fail: list_free(output); dict_free(&keywords); return ret; }
int main(int argc, char *argv[]) { bin_mdef_t *mdef; dict_t *dict; cmd_ln_t *config; int i; char buf[100]; TEST_ASSERT(config = cmd_ln_init(NULL, NULL, FALSE, "-dict", MODELDIR "/en-us/cmudict-en-us.dict", "-fdict", MODELDIR "/en-us/en-us/noisedict", NULL)); /* Test dictionary in standard fashion. */ TEST_ASSERT(mdef = bin_mdef_read(NULL, MODELDIR "/en-us/en-us/mdef")); TEST_ASSERT(dict = dict_init(config, mdef, NULL)); printf("Word ID (CARNEGIE) = %d\n", dict_wordid(dict, "CARNEGIE")); printf("Word ID (ASDFASFASSD) = %d\n", dict_wordid(dict, "ASDFASFASSD")); TEST_EQUAL(0, dict_write(dict, "_cmu07a.dic", NULL)); TEST_EQUAL(0, system("diff -uw " MODELDIR "/en-us/cmudict-en-us.dict _cmu07a.dic")); dict_free(dict); bin_mdef_free(mdef); /* Now test an empty dictionary. */ TEST_ASSERT(dict = dict_init(NULL, NULL, NULL)); printf("Word ID(<s>) = %d\n", dict_wordid(dict, "<s>")); TEST_ASSERT(BAD_S3WID != dict_add_word(dict, "FOOBIE", NULL, 0)); TEST_ASSERT(BAD_S3WID != dict_add_word(dict, "BLETCH", NULL, 0)); printf("Word ID(FOOBIE) = %d\n", dict_wordid(dict, "FOOBIE")); printf("Word ID(BLETCH) = %d\n", dict_wordid(dict, "BLETCH")); TEST_ASSERT(dict_real_word(dict, dict_wordid(dict, "FOOBIE"))); TEST_ASSERT(dict_real_word(dict, dict_wordid(dict, "BLETCH"))); TEST_ASSERT(!dict_real_word(dict, dict_wordid(dict, "</s>"))); dict_free(dict); /* Test to add 500k words. */ TEST_ASSERT(dict = dict_init(NULL, NULL, NULL)); for (i = 0; i < 500000; i++) { sprintf(buf, "word_%d", i); TEST_ASSERT(BAD_S3WID != dict_add_word(dict, buf, NULL, 0)); } dict_free(dict); cmd_ln_free_r(config); return 0; }
extern void ini_free(ini_t * self) { unsigned i; assert(self); free(self->filepath); for (i = 0; i < self->sections->length; i++) dict_free(self->sections->elements[i]->value, free); dict_free(self->sections, NULL); free(self); }
int main(int argc, char **argv) { if(argc < 3) { printf("usage: %s <encrypted_file> <dict1> [dict2] ...\n",argv[0]); printf(" <encrypted_file> : encrypted password file, one per line\n"); printf(" <dict1> : dictionary to try for passwords for word 1\n"); printf(" [dict2] : additional dictionary to try for word 2\n"); printf(" : further dictionaries may be specified for more words\n"); return 0; } //check env variable for number of threads int nthreads = 4; char *nthreads_str = getenv("PASSCRACK_NUMTHREADS"); if(nthreads_str != NULL){ nthreads = atoi(nthreads_str); } // Load the passwords from a file dict_t *passwords = dict_load(argv[1]); printf("found %d passwords to crack\n",dict_get_word_count(passwords)); // Load all dictionaries of words char **dict_files = &(argv[2]); int dicts_len = argc-2; dict_t **dicts = dict_load_dicts(dict_files, dicts_len); // Show information on loaded dictionaries and compute the maximum // length of the temporary buffer required to accomodate all // possible passwords. int buflen = 0; for(int i=0; i<dicts_len; i++){ printf("dict %d: %d words\n",i,dict_get_word_count(dicts[i])); buflen += dict_get_longest_word_length(dicts[i]); } char *buf = malloc(buflen * sizeof(char)); // Loop through each password in the password file and attempt to // crack it. int successes = 0; for(int i=0; i<dict_get_word_count(passwords); i++){ // int i = 0; char *encrypted = dict_get_word(passwords,i); int success = try_crackpthread(encrypted, dicts, dicts_len, 0, buf, buflen, 0,nthreads); if(success == 1){ printf("%3d: SUCCES: %s <-- %s\n",i,encrypted,buf); successes++; } else{ printf("%3d: FAILED: %s <-- %s\n",i,encrypted,"???"); } } printf("%d / %d passwords cracked\n",successes,dict_get_word_count(passwords)); // Free up memory and bail out dict_free(passwords); dict_free_dicts(dicts, dicts_len); free(buf); return 0; }
// Remove a single obj void pdf_obj_delete(pdf_obj *o) { if (!o) return; switch(o->t) { case eDict: dict_free(o->value.d.dict); break; case eString: case eHexString: pdf_free(o->value.s.buf); break; case eName: #ifndef HASHMAP pdf_free(o->value.k); #endif break; case eArray: free_array(o); break; default: break; } }
void tr_done(void) { int i; for (i = 0; i < cdef_n; i++) free(cdef_dst[i]); dict_free(cmap); }
int main(int argc, char *argv[]) { int ret = 0; DICT_STR *my_dict_str = NULL; ret = dict_init(&my_dict_str, argc, argv); if (ERRNO_INIT == ret) { /* 如果没有初始化此结构体,说明用户执行 --help , * 并没有出错,所有此处不打印出错信息,直接返回。 * 而对于程序来说,--help或者错误的参数也是程序 * 没有正确执行的一部分,所以main仍返回错误。*/ if (NULL != my_dict_str) printf("[DICT]%s: Initialization Failed.", __func__); return ret; } ret = dict_exec(my_dict_str); if (ERRNO_EXEC == ret) printf("[DICT]%s: Execution Failed.", __func__); dict_free(my_dict_str); return ret; }
static dict_t *search_with_bm25_score(fts_t *fts, robj *query) { int i, len, nonstopwords; sds *terms; /* dict of (title, fts_doc_score_t) */ dict_t *scores = dict_create(); dict_set_freecb(scores, dict_doc_score_free); dict_t *queried_terms = dict_create(); terms = sds_tokenize(query->ptr, &len, &nonstopwords); if (!terms) return scores; for (i = 0; i < len; i++) { sds term = terms[i]; list *idx; if (sdslen(term) == 0) { sdsfree(term); continue; } if (dict_contains(queried_terms, term)) goto free_term; dict_set(queried_terms, term, (void *)1); idx = dict_get(fts->index, term); if (!idx) goto free_term; calculate_bm25(fts, idx, scores); free_term: sdsfree(term); } dict_free(queried_terms); rr_free(terms); return scores; }
/////////////////////// //test <test.dict> int main(int argc, char * argv[]) { struct mg_server * server; // if(argc < 2) { printf("demo: %s <test.dict>\n", argv[0]); exit(0); } // dbox = dict_init(); dict_load(dbox, argv[1]); // server = mg_create_server(NULL, ev_handler); // mg_set_option(server, "listening_port", "8089"); // for(;;) { mg_poll_server(server, 1000); } // mg_destroy_server(&server); // dict_free(dbox); // return 0; }
static void dict_db_close(DICT *dict) { DICT_DB *dict_db = (DICT_DB *) dict; #if DB_VERSION_MAJOR > 1 if (dict_db->cursor) dict_db->cursor->c_close(dict_db->cursor); #endif if (DICT_DB_SYNC(dict_db->db, 0) < 0) msg_fatal("flush database %s: %m", dict_db->dict.name); /* * With some Berkeley DB implementations, close fails with a bogus ENOENT * error, while it reports no errors with put+sync, no errors with * del+sync, and no errors with the sync operation just before this * comment. This happens in programs that never fork and that never share * the database with other processes. The bogus close error has been * reported for programs that use the first/next iterator. Instead of * making Postfix look bad because it reports errors that other programs * ignore, I'm going to report the bogus error as a non-error. */ if (DICT_DB_CLOSE(dict_db->db) < 0) msg_info("close database %s: %m (possible Berkeley DB bug)", dict_db->dict.name); if (dict_db->key_buf) vstring_free(dict_db->key_buf); if (dict_db->val_buf) vstring_free(dict_db->val_buf); if (dict->fold_buf) vstring_free(dict->fold_buf); dict_free(dict); }
void testDictErrorHandling() { struct dict *d = NULL; int e = dict_set(d, "hallo", "1"); assert(e == -1); e = dict_del(d, "hallo"); assert(e == -1); e = dict_has(d, "halo"); assert(e == 0); const char *item = dict_get(d, "hallo"); assert(item == NULL); d = dict_create(); dict_set(d, "hallo", "1"); dict_set(d, "hallo2", "1"); dict_set(d, "hallo3", "2"); e = dict_del(d, "halo"); assert(e == -1); item = dict_get(d, "halo"); assert(item == NULL); dict_free(d); }
void testDict() { struct dict *d = dict_create(NULL); dict_set(d, "name", "drmaa2"); dict_set(d, "language", "c"); dict_set(d, "version", "2"); dict_set(d, "age", "2 weeks"); assert(dict_has(d, "language") != 0); dict_del(d, "age"); dict_del(d, "language"); assert(dict_has(d, "version") != 0); dict_del(d, "name"); dict_set(d, "version", "3"); const char *v = dict_get(d, "version"); assert(strcmp(v, "3") == 0); dict_del(d, "version"); dict_set(d, "new_version", "4"); assert(dict_has(d, "version") == 0); assert(dict_has(d, "new_version") != 0); dict_free(d); }
/* Test to insert a large number of elements in the dict. */ static void test_readelements(const char *fname) { DICT *dict; char buf[80]; FILE *fp; void *val; const char **keys; int i; /* initialize */ dict=dict_new(); /* read file and insert all entries */ fp=fopen(fname,"r"); assert(fp!=NULL); while (fgets(buf,sizeof(buf),fp)!=NULL) { /* strip newline */ buf[strlen(buf)-1]='\0'; dict_put(dict,buf,&buf); } fclose(fp); /* loop over dictionary contents */ keys=dict_keys(dict); for (i=0;keys[i]!=NULL;i++) { val=dict_get(dict,keys[i]); assert(val==buf); } /* free stuff */ dict_free(dict); free(keys); }
/* * Free the configuration. Called only when the server is exiting. */ int free_mainconfig(void) { cached_config_t *cc, *next; virtual_servers_free(0); /* * Clean up the configuration data * structures. */ clients_free(NULL); realms_free(); listen_free(&mainconfig.listen); /* * Free all of the cached configurations. */ for (cc = cs_cache; cc != NULL; cc = next) { next = cc->next; cf_file_free(cc->cs); free(cc); } dict_free(); return 0; }
int dict2pid_free(dict2pid_t * d2p) { if (d2p == NULL) return 0; if (--d2p->refcount > 0) return d2p->refcount; if (d2p->ldiph_lc) ckd_free_3d((void ***) d2p->ldiph_lc); if (d2p->lrdiph_rc) ckd_free_3d((void ***) d2p->lrdiph_rc); if (d2p->rssid) free_compress_map(d2p->rssid, bin_mdef_n_ciphone(d2p->mdef)); if (d2p->lrssid) free_compress_map(d2p->lrssid, bin_mdef_n_ciphone(d2p->mdef)); bin_mdef_free(d2p->mdef); dict_free(d2p->dict); ckd_free(d2p); return 0; }
void case_dict_iter() { struct dict *dict = dict(); char *key1 = "key1"; size_t len1 = 4; char *key2 = "key2"; size_t len2 = 4; char *key3 = "key3"; size_t len3 = 4; char *key4 = "key4"; size_t len4 = 4; char *key5 = "key5"; size_t len5 = 4; char *key6 = "key6"; size_t len6 = 4; assert(dict_set(dict, key1, len1, "val1") == DICT_OK); assert(dict_set(dict, key2, len2, "val2") == DICT_OK); assert(dict_set(dict, key3, len3, "val3") == DICT_OK); assert(dict_set(dict, key4, len4, "val4") == DICT_OK); assert(dict_set(dict, key5, len5, "val5") == DICT_OK); assert(dict_set(dict, key6, len6, "val6") == DICT_OK); struct dict_iter *iter = dict_iter(dict); assert(dict_iter_next(iter) != NULL); assert(dict_iter_next(iter) != NULL); assert(dict_iter_next(iter) != NULL); assert(dict_iter_next(iter) != NULL); assert(dict_iter_next(iter) != NULL); assert(dict_iter_next(iter) != NULL); assert(dict_iter_next(iter) == NULL); dict_iter_free(iter); dict_free(dict); }
dict_t *ports_dict_init(list_t * ports_list, list_t * packages, conf_t * conf) { dict_t *self, *pkgmk_confs_exploded; port_t *port, *found, *package; unsigned i; int cmp; char *locked_version, *pkgmk_conf; assert(ports_list != NULL && packages != NULL && conf != NULL); pkgmk_confs_exploded = pkgmk_confs_explode(conf->pkgmk_confs, ports_list); self = dict_new(); for (i = 0; i < ports_list->length; i++) { port = list_get(ports_list, i); if ((pkgmk_conf = dict_get(pkgmk_confs_exploded, port->name)) != NULL) port->pkgmk_conf = xstrdup(pkgmk_conf); if ((locked_version = dict_get(conf->locked_versions, port->name))) { if (!strcmp(port->version, locked_version)) dict_add(self, port->name, port); } else if (locked_version == NULL && (found = dict_get(conf->favourite_repositories, port->name)) != NULL) { if (strcmp(found->repository->name, port->repository->name) == 0) dict_add(self, port->name, port); } else if (!locked_version && !(found = dict_get(self, port->name))) dict_add(self, port->name, port); else if (!locked_version && port->repository->priority > found->repository->priority) dict_add(self, port->name, port); else if (!locked_version && port->repository->priority == found->repository->priority && strverscmp(port->version, found->version) > 0) dict_add(self, port->name, port); } for (i = 0; i < packages->length; i++) { package = list_get(packages, i); if (!(port = dict_get(self, package->name))) { dict_add(self, package->name, package); continue; } if ((cmp = strverscmp(port->version, package->version)) > 0) port->status = PRT_OUTDATED; else if (cmp < 0) port->status = PRT_DIFF; else port->status = PRT_INSTALLED; } dict_free(pkgmk_confs_exploded, free); return self; }
int ddb_update (const dict_t *config, const char *startup, const char *name, compat_flags_t flags) { int result = RET_OK; const char *disc_db = dict_lookup (config, CONFIG_DISC_DATABASE_FILE); dict_t *list = dict_restore (NULL, disc_db); if (list != NULL) { char tmp[500]; compat_flags_t dummy; result = ddb_lookup (config, startup, tmp, &dummy); if (result != RET_DDB_INCOMPATIBLE) { /* do not overwrite entries, marked as incompatible */ sprintf (tmp, "%s;0x%02x", name, flags); (void) dict_put (list, startup, tmp); result = dict_store (list, disc_db); } dict_free (list), list = NULL; } else result = RET_NO_DISC_DB; return (result); }
static void dict_mysql_close(DICT *dict) { DICT_MYSQL *dict_mysql = (DICT_MYSQL *) dict; plmysql_dealloc(dict_mysql->pldb); cfg_parser_free(dict_mysql->parser); myfree(dict_mysql->username); myfree(dict_mysql->password); myfree(dict_mysql->dbname); myfree(dict_mysql->query); myfree(dict_mysql->result_format); if (dict_mysql->option_file) myfree(dict_mysql->option_file); if (dict_mysql->option_group) myfree(dict_mysql->option_group); #if defined(MYSQL_VERSION_ID) && MYSQL_VERSION_ID >= 40000 if (dict_mysql->tls_key_file) myfree(dict_mysql->tls_key_file); if (dict_mysql->tls_cert_file) myfree(dict_mysql->tls_cert_file); if (dict_mysql->tls_CAfile) myfree(dict_mysql->tls_CAfile); if (dict_mysql->tls_CApath) myfree(dict_mysql->tls_CApath); if (dict_mysql->tls_ciphers) myfree(dict_mysql->tls_ciphers); #endif if (dict_mysql->hosts) argv_free(dict_mysql->hosts); if (dict_mysql->ctx) db_common_free_ctx(dict_mysql->ctx); if (dict->fold_buf) vstring_free(dict->fold_buf); dict_free(dict); }
void RP_mapping::clear() { if ( NULL == mapping ) return; dict_free(mapping); }
static void dict_random_close(DICT *dict) { DICT_RANDOM *dict_random = (DICT_RANDOM *) dict; argv_free(dict_random->replies); dict_free(dict); }
int http_receive_request(int sockfd, struct HttpRequest **received_request) { debug("http_receive_request"); *received_request = NULL; char *method = NULL; char *resource = NULL; struct dict *headers = dict_create(); int content_length = -1; char *payload = NULL; int http_error = HTTP_SUCCESS; char *line = NULL; if ((http_error = http_read_line(sockfd, &line)) != HTTP_SUCCESS) { goto error; } if ((http_error = http_parse_request_line(line, &method, &resource)) != HTTP_SUCCESS) { goto error; } free(line); if ((http_error = http_receive_headers(sockfd, headers)) != HTTP_SUCCESS) { goto error; } const char *l = dict_get_case(headers, "Content-Length"); if (l != 0) { content_length = atoi(l); } if (content_length == -1 || content_length == 0) { debug("No or 0 content-length."); content_length = 0; } else { if ((http_error = http_receive_payload(sockfd, &payload, content_length)) != HTTP_SUCCESS) { goto error; } } // create and fill return object struct HttpRequest *request = (struct HttpRequest *)malloc(sizeof(struct HttpRequest)); check_mem(request); request->method = method; request->resource = resource; request->headers = headers; request->content_length = content_length; request->payload = payload; *received_request = request; return HTTP_SUCCESS; error: dict_free(headers); //TODO free entries free(method); free(resource); free(payload); free(line); assert(http_error != HTTP_SUCCESS); return http_error; }
void tr_hpf(char **args) { /* reseting the patterns */ hypats_len = 0; hy_n = 0; dict_free(hydict); /* reseting the dictionary */ hwword_len = 0; hw_n = 0; dict_free(hwdict); /* reseting hcode mappings */ hcode_n = 0; dict_free(hcodedict); /* reading */ hyph_init(); tr_hpfa(args); }
void layout_free (void *layout) { tp_layout *l = (tp_layout*)layout; box_free (l->box); dict_free(l->nodes); free (l); pthread_mutex_destroy (&mutex); }
static void models_free(void) { fillpen_free(fpen); lmset_free(lmset); dict_free(dict); mdef_free(mdef); }
/* Free the dynamic symbols block. */ static void free_class_block (struct symtab *symtab) { struct blockvector *bv = BLOCKVECTOR (symtab); struct block *bl = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); dict_free (BLOCK_DICT (bl)); }
void aliases_free(dict_t * self) { unsigned i; assert(self != NULL); for (i = 0; i < self->length; i++) list_free((list_t *) self->elements[i]->value, free); dict_free(self, NULL); }
int main(){ struct dictionary *d; int i; d = dict_new(1,0); int min; int nums[7]; int keys[7]; keys[0] = 9; nums[0] = 14; keys[1] = 4; nums[1] = 7; keys[2] = 12; nums[2] = 5; keys[3] = 0; nums[3] = 15; keys[4] = 2; nums[4] = 3; keys[5] = 14; nums[5] = 4; keys[6] = 5; nums[6] = 2; printf("new\n"); //~ printHash(d); for(i = 0; i < 7; i++){ //~ printf("Inserting %d...\n",nums[i]); dict_set(d,keys[i],nums[i]); //~ printHash(d); } printHash(d); dict_set(d,2,8); printf("set key 2 con 8\n"); printf("get key 2 = %d\n",dict_get(d,2)); printf("delete key 2\n"); dict_delete(d,2); printHash(d); printf("delete key 9\n"); dict_delete(d,9); printHash(d); dict_free(d); }