Esempio n. 1
0
void set_db_version(int db_version) {

    /** RESULT  : sets the database version entry in the database

        RETURNS : void

        PURPOSE : to enable database upgrade procedures and error checking

        NOTES   :
    **/

    //check database is open and table exists
    check_db_open(GET_CALL_INFO);
    check_table_exists("GAME_DATA_TABLE", GET_CALL_INFO);

    char *sql="UPDATE GAME_DATA_TABLE SET DB_VERSION = ?";

    sqlite3_stmt *stmt=NULL;

    prepare_query(sql, &stmt, GET_CALL_INFO);

    sqlite3_bind_int(stmt, 1, db_version);

    step_query(sql, &stmt, GET_CALL_INFO);

    destroy_query(sql, &stmt, GET_CALL_INFO);
}
Esempio n. 2
0
void   *
madns_response(MADNS * mp, in_addr_t * ip)
{
    while (1) {
        char    pkt[DNS_PACKET_LEN];
        INADDR  sa;
        socklen_t salen = sizeof sa;
        RESPONSE resp;
        char    ips[99];

        int     len = recvfrom(mp->sock, pkt, sizeof pkt, 0,
                               (SADDR *) & sa, &salen);
        if (len <= 0)
            break;

        if (!parse_response(pkt, len, &resp))
            continue;

        LOG("resp: ip %s ttl %lu tid %hu name %s\n",
            ipstr(resp.ip, ips), resp.ttl, resp.tid, resp.name);

        QUERY  *qp = &mp->queries[(int)resp.tid % mp->qsize];

        if (qp->ctx && qp->tid == resp.tid && qp->server
            && qp->server->ip == sa.sin_addr.s_addr) {

            if (resp.ip != INADDR_ANY && !strcasecmp(resp.name, qp->name))
                update_cache(mp, &resp);
            return destroy_query(mp, qp, *ip = resp.ip);
        }

        log_packet(__LINE__, pkt, len);
        if (qp->server && qp->server->ip != sa.sin_addr.s_addr)
            LOG("resp.addr=%s tid=%hu ttl=%lu serv=%s\n",
                ipstr(sa.sin_addr.s_addr, pkt), resp.tid, resp.ttl,
                ipstr(qp->server->ip, pkt + 33));
    }

    if (!qempty(&mp->active)) {
        QUERY  *qp = link_QUERY(mp->active.next);

        if (qp->expires <= time(0))
            return destroy_query(mp, qp, *ip = INADDR_ANY);
    }

    return NULL;
}
Esempio n. 3
0
static void destroy_lookup(struct resolv_lookup *lookup)
{
	if (lookup->ipv4_query != NULL) {
		g_queue_remove(lookup->resolv->query_queue,
						lookup->ipv4_query);
		destroy_query(lookup->ipv4_query);
	}

	if (lookup->ipv6_query != NULL) {
		g_queue_remove(lookup->resolv->query_queue,
						lookup->ipv6_query);
		destroy_query(lookup->ipv6_query);
	}

	g_free(lookup->results);
	g_free(lookup);
}
Esempio n. 4
0
static void destroy_lookup(struct resolv_lookup *lookup)
{
	debug(lookup->resolv, "lookup %p id %d ipv4 %p ipv6 %p",
		lookup, lookup->id, lookup->ipv4_query, lookup->ipv6_query);

	if (lookup->ipv4_query != NULL) {
		g_queue_remove(lookup->resolv->query_queue,
						lookup->ipv4_query);
		destroy_query(lookup->ipv4_query);
	}

	if (lookup->ipv6_query != NULL) {
		g_queue_remove(lookup->resolv->query_queue,
						lookup->ipv6_query);
		destroy_query(lookup->ipv6_query);
	}

	g_free(lookup->results);
	g_free(lookup);
}
Esempio n. 5
0
void load_db_e3ds(){

    /** public function - see header */

    log_event(EVENT_INITIALISATION, "loading e3d...");

    sqlite3_stmt *stmt;

     //check database is open and table exists
    check_db_open(GET_CALL_INFO);
    check_table_exists("E3D_TABLE", GET_CALL_INFO);

    char *sql="SELECT * FROM E3D_TABLE";

    prepare_query(sql, &stmt, GET_CALL_INFO);

    //read the sql query result into the e3d array
    int i=0;
    int rc=0;

    while ( (rc = sqlite3_step(stmt)) == SQLITE_ROW) {

        //get the object id and check that the value does not exceed the maximum permitted
        int id=sqlite3_column_int(stmt,0);

        if(id>MAX_E3D_TYPES){

            log_event(EVENT_ERROR, "id [%i] exceeds range [%i] in function %s: module %s: line %i", id, MAX_E3D_TYPES, GET_CALL_INFO);
            stop_server();
        }

        //handle null string which would crash strcpy
        if(sqlite3_column_text(stmt, 1)) strcpy(e3ds.e3d[id].e3d_filename, (char*)sqlite3_column_text(stmt, 1));

        e3ds.e3d[id].object_id=sqlite3_column_int(stmt, 2);

        log_event(EVENT_INITIALISATION, "loaded [%i] [%s]", id, e3ds.e3d[id].e3d_filename);

        i++;
    }

    destroy_query(sql, &stmt, GET_CALL_INFO);

    if(i==0){

        log_event(EVENT_ERROR, "no e3ds found in database", i);
        stop_server();
    }
}
void load_db_char_races(){

    /** public function - see header */

     //check database is open and table exists
    check_db_open(GET_CALL_INFO);
    check_table_exists("RACE_TABLE", GET_CALL_INFO);

    log_event(EVENT_INITIALISATION, "loading races...");

    sqlite3_stmt *stmt;
    char *sql="SELECT * FROM RACE_TABLE";

    prepare_query(sql, &stmt, GET_CALL_INFO);

    //read the sql query result into the race array
    int i=0;
    int rc=0;

    while ( (rc = sqlite3_step(stmt)) == SQLITE_ROW) {

        int race_id=sqlite3_column_int(stmt, 0);

        if(race_id>MAX_RACES) {

            log_event(EVENT_ERROR, "race_id [%i] exceeds max [%i] in function %s: module %s: line %i", race_id, MAX_RACES, GET_CALL_INFO);
            stop_server();
        }

        //handle null string which would crash strcpy
        if(sqlite3_column_text(stmt, 1)) strcpy(races.race[race_id].race_name, (char*)sqlite3_column_text(stmt, 1));

        //handle null string which would crash strcpy
        if(sqlite3_column_text(stmt, 2)) strcpy(races.race[race_id].race_description, (char*)sqlite3_column_text(stmt, 2));

        log_event(EVENT_INITIALISATION, "loaded [%i] [%s]", race_id, races.race[race_id].race_name);

        i++;
    }

    destroy_query(sql, &stmt, GET_CALL_INFO);

    if(i==0){

        log_event(EVENT_ERROR, "no races found in database", i);
        stop_server();
    }
}
Esempio n. 7
0
int
madns_cancel(MADNS * mp, const void *context)
{
    QLINK  *lp;

    for (lp = mp->active.next; lp != &mp->active; lp = lp->next) {
        QUERY  *qp = link_QUERY(lp);

        if (qp->ctx == context) {
            int     tid = qp->tid;  // To audit what was cancelled.
            return destroy_query(mp, qp, 0), tid;
        }
    }

    return 0;
}
Esempio n. 8
0
void
madns_destroy(MADNS * mp)
{
    if (!mp)
        return;
    if (mp->sock != -1)
        (void)close(mp->sock);

    int     i;

    for (i = 0; i < mp->limit; ++i)
        free(mp->cachev[i]);

    while (!qempty(&mp->active))
        destroy_query(mp, link_QUERY(mp->active.next), 0);

    free(mp->queries), free(mp->serv), free(mp);
}
Esempio n. 9
0
/* Generate a query string from a collection and query parameters. */
GString*
xmms_collection_get_query (xmms_coll_dag_t *dag, xmmsv_coll_t *coll,
                           guint limit_start, guint limit_len,
                           xmmsv_t *order, xmmsv_t *fetch, xmmsv_t *group)
{
	GString *qstring;
	coll_query_t *query;
	coll_query_params_t params = { limit_start, limit_len, order, fetch, group };

	query = init_query (&params);
	xmms_collection_append_to_query (dag, coll, query);
	add_fetch_group_aliases (query, &params);

	qstring = xmms_collection_gen_query (query);

	destroy_query (query);

	return qstring;
}
Esempio n. 10
0
void batch_add_genders(char *file_name){

    /** public function - see header */

    FILE* file;

    if((file=fopen(file_name, "r"))==NULL){

        log_event(EVENT_ERROR, "file [%s] not found", file_name);
        stop_server();
    }

    char line[160]="";
    int line_counter=0;

    log_event(EVENT_INITIALISATION, "\nAdding genders specified in file [%s]", file_name);
    fprintf(stderr, "\nAdding genders specified in file [%s]\n", file_name);

    //check database is open and table exists
    check_db_open(GET_CALL_INFO);
    check_table_exists("GENDER_TABLE", GET_CALL_INFO);

    sqlite3_stmt *stmt;
    char *sErrMsg = 0;

    char *sql="INSERT INTO GENDER_TABLE("  \
        "GENDER_ID," \
        "GENDER_NAME"  \
        ") VALUES(?, ?)";

    prepare_query(sql, &stmt, GET_CALL_INFO);

    int rc=sqlite3_exec(db, "BEGIN TRANSACTION", NULL, NULL, &sErrMsg);
    if(rc!=SQLITE_OK){

        log_event(EVENT_ERROR, "sqlite3_exec failed", GET_CALL_INFO);
        log_text(EVENT_ERROR, "return code [%i] message [%s] sql [%s]", rc, *&sErrMsg, sql);
    }

    while (fgets(line, sizeof(line), file)) {

        line_counter++;

        sscanf(line, "%*s");

        char output[2][MAX_LST_LINE_LEN];
        memset(&output, 0, sizeof(output));
        parse_line(line, output);

        sqlite3_bind_int(stmt, 1, atoi(output[0]));                 //gender id
        sqlite3_bind_text(stmt, 2, output[1], -1, SQLITE_STATIC);   //gender name

        step_query(sql, &stmt, GET_CALL_INFO);

        sqlite3_clear_bindings(stmt);
        sqlite3_reset(stmt);

        fprintf(stderr, "Gender [%i] [%s] added successfully\n", atoi(output[0]), output[1]);
        log_event(EVENT_SESSION, "Added gender [%i] [%s] to GENDER_TABLE", atoi(output[0]), output[1]);
    }

    rc=sqlite3_exec(db, "END TRANSACTION", NULL, NULL, &sErrMsg);
    if (rc!=SQLITE_OK) {

        log_event(EVENT_ERROR, "sqlite3_exec failed", GET_CALL_INFO);
        log_text(EVENT_ERROR, "return code [%i] message [%s] sql [%s]", rc, *sErrMsg, sql);
    }

    destroy_query(sql, &stmt, GET_CALL_INFO);

    fclose(file);

    //load gender data to memory so this can be used by other functions
    load_db_genders();

    //mark data as loaded
    genders.data_loaded=true;
}
Esempio n. 11
0
int main(int argc, char *argv[])
{
    if (argc<3)
	{
	    printf("Usage: %s <query> <preparsed_file> {<preparsed_file>}\n\n", argv[0]);
	    exit(0);
	}

    int		paramnr;
//    char	*sok = "Clustering \"Used to \" \"the combination\" \"patches whicH\"";
    char	*sok = argv[1];
//    char	*sok = "Magnus Galåen";
    query_array	qa;

    get_query(sok, strlen(sok), &qa);

//    thesaurus		*T = thesaurus_init("../../data/thesaurus.text", "../../data/thesaurus.id");
    thesaurus		*T = thesaurus_init("../../data/mini.thesaurus.text", "../../data/mini.thesaurus.id");

    // Kjør stemming på query:
    thesaurus_expand_query(T, &qa);

    // Print query med innebygd print-funksjon:
    char	buf[1024];
    sprint_expanded_query(buf, 1023, &qa);
//    sprint_query(buf, 1023, &qa);
    printf("\nQuery: %s\n\n", buf);

    for (paramnr = 2; paramnr<argc; paramnr++)
	{
	    FILE	*file = fopen(argv[paramnr], "ro");

	    if (!file)
		{
		    printf("Could not open %s\n", argv[paramnr]);
		    return -1;
		}

	    struct stat	fileinfo;
	    fstat( fileno(file), &fileinfo );

	    int		size = fileinfo.st_size;
	    char	*buf = malloc(size);
	    int		i;

	    for (i=0; i<size;)
		{
		    i+= fread( &(buf[i]), sizeof(char), size-i, file );
		}

	    if (paramnr>2) printf("\n     ---------------\n\n");

	    int		modes[3] = {first_snippet, plain_snippet, db_snippet};
	    for (i=0; i<3; i++)
		{
		    char	*snippet;

		    int		success = generate_snippet( qa, buf, size, &snippet, "\033[1;32m[", "]\033[0m", modes[i], 320, 4, 80 );

		    if (i>0) printf("\n");
		    printf("%s\n", snippet);
		    free(snippet);

		    if (!success)
			printf("FAILURE WHEN PARSING.\n");
		}

	    free(buf);

	    fclose(file);
	}

    destroy_query(&qa);
    thesaurus_destroy(T);
}