static int host_init(dig_params_t *params) { // Initialize params with dig defaults. int ret = dig_init(params); if (ret != KNOT_EOK) { return ret; } // Set host specific defaults. free(params->config->port); params->config->port = strdup(DEFAULT_DNS_PORT); params->config->retries = DEFAULT_RETRIES_HOST; params->config->wait = DEFAULT_TIMEOUT_HOST; params->config->servfail_stop = false; params->config->class_num = KNOT_CLASS_IN; params->config->style = DEFAULT_STYLE_HOST; // Check port. if (params->config->port == NULL) { query_free(params->config); return KNOT_ENOMEM; } return KNOT_EOK; }
}END_TEST static p_search_result setup_BLOSUM62_test( int bit_width, int search_type, size_t hit_count ) { init_symbol_translation( AMINOACID, FORWARD_STRAND, 3, 3 ); mat_init_buildin( BLOSUM62 ); p_query query = query_read_from_string( "HPEVYILIIPGFGIISHVVSTYSKKPVFGEISMVYAMASIGLLGFLVWSHHMYIVGLDADTRAYFTSATMIIAIPTGIKI" ); s_init( search_type, bit_width, query ); ssa_db_init( concat( "./tests/testdata/", "short_AA.fas" ) ); gapO = -1; gapE = -1; adp_init( hit_count ); p_search_result res = s_search( &hit_count ); minheap_sort( res->heap ); query_free( query ); ck_assert_int_eq( hit_count, res->heap->count ); return res; }
static VALUE db_search(VALUE self, VALUE database_name, VALUE q_mol, VALUE block) { char * filename; struct CompoundDB db; struct Query query; filename = StringValuePtr(database_name); if(strlen(filename) > 40){ rb_raise(rb_eException, "length of database name must less than 40!"); } query_setup(q_mol, & query); db.mat = db_file_open(filename, ".mat"); db.idx = db_file_open(filename, ".idx"); db.typ = db_file_open(filename, ".typ"); db_load(& db, & query); query_free(& query); fclose(db.mat); fclose(db.idx); fclose(db.typ); }
static VALUE mol_by_mol(VALUE self, VALUE q_mol, VALUE t_mol) { struct Query query; struct Target target; struct State state; VALUE result; target.max_length = 0; state.max_length = 0; query_setup( q_mol, & query ); target_setup( t_mol, & target ); state_allocate(& state, & query, & target); if(rb_block_given_p() == Qtrue){ state_setup_block(& state); } else{ state_setup(& state, & query, & target); } search_by_ullmann(& state, & query, & target); result = state_get_result(& state); query_free(& query); target_free(& target); state_free(& state); return result; }
}END_TEST START_TEST (test_init_search_data5) { init_symbol_translation( AMINOACID, BOTH_STRANDS, 3, 3 ); p_query query = query_read_from_string( "ATGCCCAAGCTGAATAGCGTAGAGGGGTTTTCATCATTTGAGGACGATGTATAA" ); p_search_data sdp = s_create_searchdata( query ); // query data ck_assert_int_eq( 1, sdp->q_count ); seq_buffer_t buf = sdp->queries[0]; ck_assert_str_eq( &query->aa[0].seq, &buf.seq.seq ); ck_assert_int_eq( query->aa[0].len, buf.seq.len ); ck_assert_int_eq( 0, buf.frame ); ck_assert_int_eq( 0, buf.strand ); ck_assert_int_eq( 0, sdp->queries[1].seq.len ); ck_assert_int_eq( 0, sdp->queries[2].seq.len ); ck_assert_int_eq( 0, sdp->queries[3].seq.len ); ck_assert_int_eq( 0, sdp->queries[4].seq.len ); ck_assert_int_eq( 0, sdp->queries[5].seq.len ); ck_assert_int_eq( 54, sdp->maxqlen ); query_free( query ); }END_TEST
static p_search_result setup_searcher_16_test( char * query_string, char * db_file, size_t hit_count ) { set_max_compute_capability( COMPUTE_ON_SSE2 ); mat_init_constant_scoring( 1, -1 ); init_symbol_translation( NUCLEOTIDE, FORWARD_STRAND, 3, 3 ); p_query query = query_read_from_string( query_string ); s_init( NEEDLEMAN_WUNSCH, BIT_WIDTH_16, query ); ssa_db_init( concat( "./tests/testdata/", db_file ) ); gapO = -1; gapE = -1; adp_init( hit_count ); p_search_result res = s_search( &hit_count ); minheap_sort( res->heap ); query_free( query ); return res; }
static int fulltext_query(fulltext_vtab *v, const char *zQuery, DocList **pResult){ Query q; int phrase_start = -1; int i; sqlite3_stmt *pSelect = NULL; DocList *d = NULL; int rc = parse_query(v, zQuery, &q); if( rc!=SQLITE_OK ) return rc; for(i = 0 ; i < q.nTerms ; ++i){ int need_positions = i<q.nTerms-1 && !q.pTerm[i+1].is_phrase; DocList *next = docListNew(need_positions ? DL_POSITIONS : DL_DOCIDS); if( q.pTerm[i].is_phrase ){ phrase_start = i; } rc = query_merge(v, &pSelect, q.pTerm[i].zTerm, d, i - phrase_start, next); if( rc!=SQLITE_OK ) break; if( d!=NULL ){ docListDelete(d); } d = next; } sqlite3_finalize(pSelect); query_free(&q); *pResult = d; return rc; }
}END_TEST static void test_searcher_overflow_to_64bit( int search_type ) { init_constant_scores( 127, -1 ); init_symbol_translation( AMINOACID, FORWARD_STRAND, 3, 3 ); p_query query = query_read_from_file( "./tests/testdata/NP_009305.1.fas" ); s_init( search_type, BIT_WIDTH_8, query ); ssa_db_init( "./tests/testdata/NP_009305.1.fas" ); gapO = -1; gapE = -1; size_t hit_count = 1; adp_init( hit_count ); p_search_result res = s_search( &hit_count ); minheap_sort( res->heap ); query_free( query ); ck_assert_int_eq( hit_count, res->heap->count ); ck_assert_int_eq( 1, res->overflow_8_bit_count ); ck_assert_int_eq( 1, res->overflow_16_bit_count ); int result[2] = { 67818, 0 }; test_result( res, result, 2 ); }
/* Perform a full-text query; return a list of documents in [pResult]. */ static int fulltext_query(fulltext_vtab *v, const char *zQuery, DocList **pResult){ Query q; int phrase_start = -1; int i; sqlite3_stmt *pSelect = NULL; DocList *d = NULL; int rc = parse_query(v, zQuery, &q); if( rc!=SQLITE_OK ) return rc; /* Merge terms. */ for(i = 0 ; i < q.nTerms ; ++i){ /* In each merge step, we need to generate positions whenever we're * processing a phrase which hasn't ended yet. */ int need_positions = i<q.nTerms-1 && !q.pTerm[i+1].is_phrase; DocList *next = docListNew(need_positions ? DL_POSITIONS : DL_DOCIDS); if( q.pTerm[i].is_phrase ){ phrase_start = i; } rc = query_merge(v, &pSelect, q.pTerm[i].zTerm, d, i - phrase_start, next); if( rc!=SQLITE_OK ) break; if( d!=NULL ){ docListDelete(d); } d = next; } sqlite3_finalize(pSelect); query_free(&q); *pResult = d; return rc; }
static void dnscb(struct dns_ctx *ctx, void *result, void *data) { int r = dns_status(ctx); struct query *q = data; struct dns_parse p; struct dns_rr rr; unsigned nrr; unsigned char dn[DNS_MAXDN]; const unsigned char *pkt, *cur, *end; if (!result) { return; } pkt = result; end = pkt + r; cur = dns_payload(pkt); dns_getdn(pkt, &cur, end, dn, sizeof(dn)); dns_initparse(&p, NULL, pkt, cur, end); p.dnsp_qcls = p.dnsp_qtyp = 0; nrr = 0; while((r = dns_nextrr(&p, &rr)) > 0) { if (!dns_dnequal(dn, rr.dnsrr_dn)) continue; if ((qcls == DNS_C_ANY || qcls == rr.dnsrr_cls) && (q->qtyp == DNS_T_ANY || q->qtyp == rr.dnsrr_typ)) ++nrr; else if (rr.dnsrr_typ == DNS_T_CNAME && !nrr) { if (dns_getdn(pkt, &rr.dnsrr_dptr, end, p.dnsp_dnbuf, sizeof(p.dnsp_dnbuf)) <= 0 || rr.dnsrr_dptr != rr.dnsrr_dend) { r = DNS_E_PROTOCOL; break; } else { dns_dntodn(p.dnsp_dnbuf, dn, sizeof(dn)); } } } if (!r && !nrr) r = DNS_E_NODATA; if (r < 0) { free(result); return; } dns_rewind(&p, NULL); p.dnsp_qtyp = q->qtyp == DNS_T_ANY ? 0 : q->qtyp; p.dnsp_qcls = qcls == DNS_C_ANY ? 0 : qcls; while(dns_nextrr(&p, &rr)) { const unsigned char *dptr = rr.dnsrr_dptr; if (rr.dnsrr_dsz == 4) { char *ip = xmalloc(sizeof(char) * 16); sprintf(ip, "%d.%d.%d.%d", dptr[0], dptr[1], dptr[2], dptr[3]); q->callback(ip, q->data, q->g_ape); break; } } free(result); query_free(q); }
pk_err_t cleanup_action(struct db *db, const char *sql, enum pk_log_type logtype, const char *desc) { struct query *qry; int changes; if (!query(&qry, db, sql, NULL)) { sql_log_err(db, "Couldn't clean %s", desc); return PK_IOERR; } query_row(qry, "d", &changes); query_free(qry); if (changes > 0) pk_log(logtype, "Cleaned %d %s", changes, desc); return PK_SUCCESS; }
static p_search_result setup_searcher_test( int bit_width, int search_type, char * query_string, char * db_file, size_t hit_count, int symtype, int strands ) { init_symbol_translation( symtype, strands, 3, 3 ); mat_init_constant_scoring( 1, -1 ); p_query query = query_read_from_string( query_string ); s_init( search_type, bit_width, query ); ssa_db_init( concat( "./tests/testdata/", db_file ) ); gapO = -1; gapE = -1; adp_init( hit_count ); p_search_result res = s_search( &hit_count ); minheap_sort( res->heap ); query_free( query ); return res; }
xc_result_t xCOM_QueryFinish ( xc_handle_t queryHandle ) { query_t *queryPtr; xc_result_t result; TRACE3 (("called with queryHandle=%u", queryHandle)); pthread_mutex_lock (&lock); queryPtr = (query_t *) handle_dir_get (queryHandles, queryHandle); if (queryPtr != NULL) { query_free (queryPtr); result = XC_OK; } else { result = XC_ERR_INVAL; } pthread_mutex_unlock (&lock); TRACE3 (("exiting with result=%d", result)); return result; }
void ape_gethostbyname(char *name, void (*callback)(char *, void *, acetables *), void *data, acetables *g_ape) { struct in_addr addr; struct query *q; unsigned char dn[DNS_MAXDN]; int abs = 0; enum dns_type l_qtyp = 0; if (dns_pton(AF_INET, name, &addr) > 0) { /* We have an IP */ callback(xstrdup(name), data, g_ape); return; } else if (!dns_ptodn(name, strlen(name), dn, sizeof(dn), &abs)) { /* We have an invalid domain name */ return; } else { l_qtyp = DNS_T_A; } q = query_new(name, dn, l_qtyp); q->data = data; q->callback = callback; q->g_ape = g_ape; if (abs) { abs = DNS_NOSRCH; } if (!dns_submit_dn(NULL, dn, qcls, l_qtyp, abs, 0, dnscb, q)) { query_free(q); return; } dns_timeouts(NULL, -1, 0); }
/** * Reads in a query from a file and returns a pointer to a struct holding the * query data. * * @param queryname name of the file containing the query * @return a pointer to the read query */ p_query query_read_from_file( const char * filename ) { FILE * query_fp = 0; if( strcmp( filename, "-" ) == 0 ) { print_error( "Query not specified" ); return 0; } else query_fp = fopen( filename, "r" ); if( !query_fp ) { print_error( "Cannot open query file: %s", filename ); return 0; } p_query query = init(); char query_line[LINE_MAX]; query_line[0] = 0; if( NULL == fgets( query_line, LINE_MAX, query_fp ) ) { print_error( "Could not initialise from query sequence" ); return 0; } // read description size_t len = strlen( query_line ); if( query_line[len - 1] == '\n' ) { query_line[len - 1] = 0; len--; } if( query_line[0] == '>' ) { query->header = xmalloc( len ); strncpy( query->header, query_line + 1, len ); query->headerlen = len - 1; query_line[0] = 0; if( NULL == fgets( query_line, LINE_MAX, query_fp ) ) { print_error( "Could not read first line from query sequence" ); query_free( query ); return 0; } } // read sequence size_t size = LINE_MAX; char * query_sequence = xmalloc( size ); size_t query_length = 0; while( query_line[0] && (query_line[0] != '>') ) { for( int i = 0; query_line[i]; ++i ) { if( query_length + 1 >= size ) { size += LINE_MAX; query_sequence = xrealloc( query_sequence, size ); } query_sequence[query_length++] = query_line[i]; } if( NULL == fgets( query_line, LINE_MAX, query_fp ) ) { break; } } query_sequence[query_length] = 0; fill_and_map_query( query, query_sequence, query_length ); free( query_sequence ); // close the file pointer if( query_fp && (query_fp != stdin) ) fclose( query_fp ); return query; }
int main( int argc, char **argv ) { // Read any command line arguments from our friend the user. arguments(argc, argv); // Catch some signals so can exit cleanly signal(SIGINT, exit_interrupt); #ifndef WIN32 signal(SIGHUP, exit_interrupt); signal(SIGTERM, exit_interrupt); signal(SIGPIPE, SIG_IGN); if (debug_on) setvbuf(stdout, NULL, _IONBF, 0); #endif printf("%s - Jorgen Lundman v%s %s %s\n\n", argv ? argv[0] : "llink", VERSION, VERSION_STRING, #if WITH_DVDREAD "(libdvdread)" #else #if HAVE_CLINKC "(libdvdnav, ClinkC)" #else "(libdvdnav)" #endif #endif ); lion_buffersize(conf_buffersize); //lion_buffersize(2352); if (lion_init()) { printf("Failed to initialize lion/networking\n"); exit(-1); } debugf("\n"); // Read configuration file, if any // Warning, calls lion_poll until done. conf_init(); debugf("[main] initialising...\n"); // Warning, calls lion_poll until done. mime_init(); // Warning, calls lion_poll until done. skin_init(); ssdp_init(); httpd_init(); request_init(); root_init(); llrar_init(); visited_init(); cgicmd_init(); #ifdef EXTERNAL external_init(); #endif printf("[main] ready!\n"); // Background? #ifndef WIN32 if (!foreground) { if (fork()) exit(0); setsid(); if (conf_pidfile) { FILE *fd; if ((fd = fopen(conf_pidfile, "w"))) { fprintf(fd, "%u\r\n", getpid()); fclose(fd); } } } #endif cupnp_init(); // Scan for media if (conf_xmlscan) { signal(SIGINT, SIG_DFL); xmlscan_run(); do_exit = 1; } query_init(); #ifdef WIN32 SetPriorityClass(GetCurrentProcess(), ABOVE_NORMAL_PRIORITY_CLASS); #endif // The main loop while ( !do_exit ) { // Was 250,0 - we should probably let users control this in // conf settings. if (lion_poll(0, 1)<0) do_exit=1; request_events(); #ifdef EXTERNAL external_resume(); #endif } printf("\n[main] releasing resources...\n"); query_free(); cupnp_free(); #ifdef EXTERNAL external_free(); #endif root_free(); cgicmd_free(); visited_free(); llrar_free(); request_free(); httpd_free(); ssdp_free(); skin_free(); mime_free(); conf_free(); #ifndef WIN32 // Crashed when releasing spawned processes, until i can fix: lion_free(); #endif debugf("[main] done.\n"); return 0; }
/* * plugin_unregister() * * od³±cza wtyczkê. * * 0/-1 */ int plugin_unregister(plugin_t *p) { /* XXX eXtreme HACK warning * (mp) na razie jest tak. docelowo: wyladowywac pluginy tylko z * glownego programu (queriesami?) * to cos segfaultowalo (wczesniej czy pozniej), jesli bylo wywolane z * ncurses. niestety, problem pozostaje dla innych pluginow i takiego * np. rc. sie zrobi nast razem */ /* j/w If any plugin has backtrace here, and we try to remove it from memory. * ekg2 do SEGV. */ struct timer *t; session_t *s; query_t **ll; variable_t *v; command_t *c; list_t l; if (!p) return -1; /* XXX think about sequence of unloading....: currently: watches, timers, sessions, queries, variables, commands */ for (l = watches; l; l = l->next) { watch_t *w = l->data; if (w && w->plugin == p) watch_free(w); } for (t = timers; t; t = t->next) { if (t->plugin == p) t = timers_removei(t); } for (s = sessions; s; ) { session_t *next = s->next; if (s->plugin == p) session_remove(s->uid); s = next; } for (ll = queries; ll <= &queries[QUERY_EXTERNAL]; ll++) { query_t *q; for (q = *ll; q; ) { query_t *next = q->next; if (q->plugin == p) query_free(q); q = next; } } for (v = variables; v; v = v->next) { if (v->plugin == p) v = variables_removei(v); } for (c = commands; c; c = c->next) { if (c->plugin == p) c = commands_removei(c); } plugins_unlink(p); return 0; }
DAAP_BLOCK *daap_response_songlist(char* metaStr, char* query) { DAAP_BLOCK *root; int g=1; DAAP_BLOCK *mlcl; DAAP_BLOCK *mlit; ENUMHANDLE henum; MP3FILE *current; MetaField_t meta; query_node_t* filter = 0; int songs = 0; DPRINTF(E_DBG,L_DAAP,"enter daap_response_songlist\n"); // if the meta tag is specified, encode it, if it's not specified // we're given the latitude to select our own subset, for // simplicity we just include everything. if(0 == metaStr) meta = (MetaField_t) -1ll; else meta = encodeMetaRequest(metaStr, gSongMetaDataMap); if(0 != query) { filter = query_build(query, song_fields); DPRINTF(E_INF,L_DAAP|L_QRY,"query: %s\n", query); if(err_debuglevel >= E_INF) /* this is broken */ query_dump(stderr,filter, 0); } DPRINTF(E_DBG,L_DAAP|L_DB,"Preparing to send db items\n"); henum=db_enum_begin(); if((!henum) && (db_get_song_count())) { DPRINTF(E_DBG,L_DAAP|L_DB,"Can't get enum handle - exiting daap_response_songlist\n"); return NULL; } root=daap_add_empty(NULL,"adbs"); if(root) { g = (int)daap_add_int(root,"mstt",200); g = g && daap_add_char(root,"muty",0); g = g && daap_add_int(root,"mtco",0); g = g && daap_add_int(root,"mrco",0); mlcl=daap_add_empty(root,"mlcl"); if(mlcl) { while(g && (current=db_enum(&henum))) { if(filter == 0 || query_test(filter, current)) { DPRINTF(E_DBG,L_DAAP|L_DB,"Got entry for %s\n",current->fname); // song entry generation extracted for usage with // playlists as well g = 0 != daap_add_song_entry(mlcl, current, meta); songs++; } } } else g=0; } db_enum_end(henum); if(filter != 0) query_free(filter); if(!g) { DPRINTF(E_DBG,L_DAAP|L_DB,"Error enumerating db - exiting daap_response_songlist\n"); daap_free(root); return NULL; } DPRINTF(E_DBG,L_DAAP|L_DB,"Successfully enumerated database - %d items\n",songs); daap_set_int(root, "mtco", songs); daap_set_int(root, "mrco", songs); DPRINTF(E_DBG,L_DAAP,"Exiting daap_response_songlist\n"); return root; }
xc_result_t query_new ( xc_handle_t componentHandle, const char *portName, const char *interfaceName, unsigned int interfaceMajorVersion, unsigned int interfaceMinorVersion, const char *queriedComponentName, const char *queriedPortName, unsigned int queryFlags, xc_handle_t *queryHandlePtr, unsigned int *matchCountPtr ) { query_t *queryPtr; xc_result_t result = XC_OK; TRACE3 (( "called with componentHandle=%u, portName='%s', interfaceName='%s', " "interfaceMajorVersion=%u, interfaceMinorVersion=%u, queriedComponentName='%s', " "queriedPortName='%s', queryFlags=0x%x, queryHandlePtr=%p, matchCountPtr=%p", componentHandle, portName, interfaceName, interfaceMajorVersion, interfaceMinorVersion, queriedComponentName, queriedPortName, queryFlags, queryHandlePtr, matchCountPtr )); assert (interfaceName != NULL); assert (queryHandlePtr != NULL); pthread_mutex_lock (&lock); queryPtr = (query_t *) malloc (sizeof (*queryPtr)); if (queryPtr != NULL) { /* Initialize things to be allocated to sane values. */ queryPtr->queryHandle = XC_INVALID_HANDLE; queryPtr->queriedComponent = NULL; queryPtr->queriedPort = NULL; queryPtr->componentPtr = NULL; queryPtr->firstImportPtr = NULL; queryPtr->lastImportPtr = NULL; queryPtr->importPtr = NULL; queryPtr->clientPortName = NULL; XC_CLIST_INIT (&queryPtr->imports); queryPtr->componentHandle = componentHandle; queryPtr->queriedInterface.vmajor = interfaceMajorVersion; queryPtr->queriedInterface.vminor = interfaceMinorVersion; /* Resolve component handle */ if (componentHandle != XC_INVALID_HANDLE) { queryPtr->componentPtr = component_ref (componentHandle); if (queryPtr->componentPtr == NULL) { TRACE1 (("invalid component handle %u", componentHandle)); result = XC_ERR_NOENT; } } /* Copy client port name. */ if (portName != NULL) { queryPtr->clientPortName = strdup (portName); if (queryPtr->clientPortName == NULL) { TRACE1 (("Out of memory!")); result = XC_ERR_NOMEM; } } /* Copy interface name. */ if (result == XC_OK) { queryPtr->queriedInterface.name = strdup (interfaceName); if (queryPtr->queriedInterface.name == NULL) { TRACE1 (("Out of memory!")); result = XC_ERR_NOMEM; } } /* Copy queried component name if specified. */ if ((result == XC_OK) && (queriedComponentName != NULL)) { queryPtr->queriedComponent = strdup (queriedComponentName); if (queryPtr->queriedComponent == NULL) { TRACE1 (("Out of memory!")); result = XC_ERR_NOMEM; } } /* Copy queried port name if specified. */ if ((result == XC_OK) && (queriedPortName != NULL)) { queryPtr->queriedPort = strdup (queriedPortName); if (queryPtr->queriedPort == NULL) { TRACE1 (("Out of memory!")); result = XC_ERR_NOMEM; } } /* Get a handle for this query. */ if (result == XC_OK) { queryPtr->queryHandle = handle_dir_push (queryHandles, queryPtr); } else { TRACE1 (("Out of memory!")); result = XC_ERR_NOMEM; } if (result == XC_OK) { result = query_get_candidates (queryPtr, matchCountPtr); } if (result == XC_OK) { *queryHandlePtr = queryPtr->queryHandle; } else { query_free (queryPtr); } } pthread_mutex_unlock (&lock); TRACE3 (("exiting with result=%d", result)); return result; }