Beispiel #1
0
static apr_status_t vt_db_fetch(apr_dbm_t *dbm, apr_datum_t key,
                                apr_datum_t * pvalue)
{
    DBT ckey = { 0 };
    DBT rd = { 0 };
    int dberr;

    ckey.data = key.dptr;
    ckey.size = key.dsize;

    dberr = do_fetch(GET_BDB(dbm->file), ckey, rd);

    /* "not found" is not an error. return zero'd value. */
    if (dberr ==
#if DB_VER == 1
        RET_SPECIAL
#else
        DB_NOTFOUND
#endif
        ) {
        memset(&rd, 0, sizeof(rd));
        dberr = 0;
    }

    pvalue->dptr = rd.data;
    pvalue->dsize = rd.size;

    /* store the error info into DBM, and return a status code. Also, note
       that *pvalue should have been cleared on error. */
    return set_error(dbm, db2s(dberr));
}
Beispiel #2
0
CS_RETCODE
do_results(CS_COMMAND * cmd, CS_INT * results)
{
int result_num;
CS_RETCODE results_ret, result_type;

	result_num = 0;
	while ((results_ret = ct_results(cmd, &result_type)) == CS_SUCCEED) {
		printf("result_ret %d result_type %d\n", results_ret, result_type);
		if (result_type == CS_STATUS_RESULT)
			continue;
		if (result_type != results[result_num]) {
			fprintf(stderr, "ct_results() expected %d received %d\n", results[result_num], result_type);
			return CS_FAIL;
		}
		switch ((int) result_type) {
		case CS_ROW_RESULT:
			if (do_fetch(cmd)) {
				return CS_FAIL;
			}
			break;
		}
		result_num++;
	}
	return results_ret;
}
	update_group_qqnumber_op(boost::shared_ptr<WebQQ> webqq,
		boost::shared_ptr<qqGroup> group, Handler handler)
		: m_webqq(webqq)
		, m_this_group(group)
		, m_handler(handler)
	{
		do_fetch();
	}
Beispiel #4
0
static int fetch_one(struct remote *remote, int argc, const char **argv)
{
	int i;
	static const char **refs = NULL;
	int ref_nr = 0;
	int exit_code;

	if (!remote)
		die("Where do you want to fetch from today?");

	transport = transport_get(remote, NULL);
	transport_set_verbosity(transport, verbosity, progress);
	if (upload_pack)
		set_option(TRANS_OPT_UPLOADPACK, upload_pack);
	if (keep)
		set_option(TRANS_OPT_KEEP, "yes");
	if (depth)
		set_option(TRANS_OPT_DEPTH, depth);

	if (argc > 0) {
		int j = 0;
		refs = xcalloc(argc + 1, sizeof(const char *));
		for (i = 0; i < argc; i++) {
			if (!strcmp(argv[i], "tag")) {
				char *ref;
				i++;
				if (i >= argc)
					die("You need to specify a tag name.");
				ref = xmalloc(strlen(argv[i]) * 2 + 22);
				strcpy(ref, "refs/tags/");
				strcat(ref, argv[i]);
				strcat(ref, ":refs/tags/");
				strcat(ref, argv[i]);
				refs[j++] = ref;
			} else
				refs[j++] = argv[i];
		}
		refs[j] = NULL;
		ref_nr = j;
	}

	sigchain_push_common(unlock_pack_on_signal);
	atexit(unlock_pack);
	exit_code = do_fetch(transport,
			parse_fetch_refspec(ref_nr, refs), ref_nr);
	transport_disconnect(transport);
	transport = NULL;
	return exit_code;
}
Beispiel #5
0
int main(int argc, const char *argv[])
{
        int 	c;

        char
	    	*fetch		= NULL,
	    	*convert	= NULL;

	poptContext pc;

	struct poptOption options[] = {
		USERLAND_RESERVED_OPTIONS
		{"fetch", 'f', POPT_ARG_STRING, &fetch, 0, "Fetch all wav files or specified wav file from the Palm", "[file|all]"},
		{"convert", 'c', POPT_ARG_STRING, &convert, 0, "Convert <file>.wav.pdb file to wav", "file"},
		POPT_TABLEEND
	};

	pc = poptGetContext("pilot-wav", argc, argv, options, 0);
	poptSetOtherOptionHelp(pc,"\n\n"
	"   Decodes Palm Voice Memo files to wav files you can read\n\n"
	"   Example arguments: \n"
	"      pilot-wav -p /dev/pilot -f MyVoiceMemo.wav.pdb\n"
	"      pilot-wav -c MyVoiceMemo.wav.pdb\n\n");

	if (argc < 2 ) {
		poptPrintUsage(pc,stderr,0);
		return 1;
	}


	while ((c = poptGetNextOpt(pc)) >= 0) {
		fprintf(stderr,"   ERROR: Unhandled option %d.\n",c);
		return 1;
        }

	if (c < -1) {
		plu_badoption(pc,c);
	}

	if(convert != NULL)
		pdb_to_wav(convert);

	if(fetch != NULL)
		do_fetch(fetch);

        return 0;
}
Beispiel #6
0
static int vt_db_exists(apr_dbm_t *dbm, apr_datum_t key)
{
    DBT ckey = { 0 };   /* converted key */
    DBT data = { 0 };
    int dberr;

    ckey.data = key.dptr;
    ckey.size = key.dsize;

    dberr = do_fetch(GET_BDB(dbm->file), ckey, data);

    /* note: the result data is "loaned" to us; we don't need to free it */

    /* DB returns DB_NOTFOUND if it doesn't exist. but we want to say
       that *any* error means it doesn't exist. */
    return dberr == 0;
}
Beispiel #7
0
CS_RETCODE
do_results(CS_COMMAND * cmd, CS_INT * results)
{
int result_num;
CS_RETCODE results_ret, result_type;
int done = 0;

	result_num = 0;
	while ((results_ret = ct_results(cmd, &result_type)) == CS_SUCCEED) {
		printf("result_ret %d result_type %d\n", results_ret, result_type);
		if (result_type == CS_STATUS_RESULT)
			continue;
        if (done) {
            fputs("No further results were expected\n", stderr);
            return CS_FAIL;
        }
		if (result_type != results[result_num]) {
			fprintf(stderr, "ct_results() expected %d received %d\n", results[result_num], result_type);
			return CS_FAIL;
		}
		switch ((int) result_type) {
		case CS_ROW_RESULT:
			if (do_fetch(cmd)) {
				return CS_FAIL;
			}
			break;
        case CS_CMD_DONE:
            done = 1;
		}
		result_num++;
	}
    if ( !done ) {
        fputs("Never saw CS_CMD_DONE\n", stderr);
        return CS_FAIL;
    }
	return results_ret;
}
Beispiel #8
0
void test_online_fetch__no_tags_http(void)
{
	do_fetch("http://github.com/libgit2/TestGitRepository.git", GIT_REMOTE_DOWNLOAD_TAGS_NONE, 3);
}
Beispiel #9
0
void test_online_fetch__default_https(void)
{
	do_fetch("https://github.com/libgit2/TestGitRepository.git", GIT_REMOTE_DOWNLOAD_TAGS_AUTO, 5);
}
Beispiel #10
0
int cmd_fetch(int argc, const char **argv, const char *prefix)
{
	struct remote *remote;
	int i;
	static const char **refs = NULL;
	int ref_nr = 0;
	int exit_code;

	/* Record the command line for the reflog */
	strbuf_addstr(&default_rla, "fetch");
	for (i = 1; i < argc; i++)
		strbuf_addf(&default_rla, " %s", argv[i]);

	argc = parse_options(argc, argv, prefix,
			     builtin_fetch_options, builtin_fetch_usage, 0);

	if (argc == 0)
		remote = remote_get(NULL);
	else
		remote = remote_get(argv[0]);

	if (!remote)
		die("Where do you want to fetch from today?");

	transport = transport_get(remote, remote->url[0]);
	if (verbosity >= 2)
		transport->verbose = 1;
	if (verbosity < 0)
		transport->verbose = -1;
	if (upload_pack)
		set_option(TRANS_OPT_UPLOADPACK, upload_pack);
	if (keep)
		set_option(TRANS_OPT_KEEP, "yes");
	if (depth)
		set_option(TRANS_OPT_DEPTH, depth);

	if (argc > 1) {
		int j = 0;
		refs = xcalloc(argc + 1, sizeof(const char *));
		for (i = 1; i < argc; i++) {
			if (!strcmp(argv[i], "tag")) {
				char *ref;
				i++;
				if (i >= argc)
					die("You need to specify a tag name.");
				ref = xmalloc(strlen(argv[i]) * 2 + 22);
				strcpy(ref, "refs/tags/");
				strcat(ref, argv[i]);
				strcat(ref, ":refs/tags/");
				strcat(ref, argv[i]);
				refs[j++] = ref;
			} else
				refs[j++] = argv[i];
		}
		refs[j] = NULL;
		ref_nr = j;
	}

	sigchain_push_common(unlock_pack_on_signal);
	atexit(unlock_pack);
	exit_code = do_fetch(transport,
			parse_fetch_refspec(ref_nr, refs), ref_nr);
	transport_disconnect(transport);
	transport = NULL;
	return exit_code;
}
Beispiel #11
0
/* Testing: Test asynchronous ct_cancel() */
int
main(int argc, char **argv)
{
    CS_CONTEXT *ctx;
    CS_CONNECTION *conn;
    CS_COMMAND *cmd;
    int i, verbose = 0, cnt = 0;

    CS_RETCODE ret;
    CS_INT result_type;

    struct itimerval timer;
    char query[1024];

    unsigned clock = 200000;

    fprintf(stdout, "%s: Check asynchronous called ct_cancel()\n", __FILE__);
    if (verbose) {
        fprintf(stdout, "Trying login\n");
    }
    ret = try_ctlogin(&ctx, &conn, &cmd, verbose);
    if (ret != CS_SUCCEED) {
        fprintf(stderr, "Login failed\n");
        return 1;
    }

    /* Create needed tables */
    ret = run_command(cmd, "CREATE TABLE #t0010 (id int, col1 varchar(255))");
    if (ret != CS_SUCCEED)
        return 1;

    for (i = 0; i < 10; i++) {
        sprintf(query, "INSERT #t0010 (id, col1) values (%d, 'This is field no %d')", i, i);

        ret = run_command(cmd, query);
        if (ret != CS_SUCCEED)
            return 1;
    }

    /* Set SIGALRM signal handler */
    signal(SIGALRM, catch_alrm);

    for (;;) {
        /* TODO better to use alarm AFTER ct_send ?? */
        /* Set timer */
        timer.it_interval.tv_sec = 0;
        timer.it_interval.tv_usec = clock;
        timer.it_value.tv_sec = 0;
        timer.it_value.tv_usec = clock;
        if (0 != setitimer(ITIMER_REAL, &timer, NULL)) {
            fprintf(stderr, "Could not set realtime timer.\n");
            return 1;
        }

        /* Issue a command returning many rows */
        ret = ct_command(cmd, CS_LANG_CMD, "SELECT * FROM #t0010 t1, #t0010 t2, #t0010 t3, #t0010 t4", CS_NULLTERM, CS_UNUSED);
        if (ret != CS_SUCCEED) {
            fprintf(stderr, "ct_command() failed.\n");
            return 1;
        }

        ret = ct_send(cmd);
        if (ret != CS_SUCCEED) {
            fprintf(stderr, "first ct_send() failed.\n");
            return 1;
        }

        /* Save a global reference for the interrupt handler */
        g_cmd = cmd;

        while ((ret = ct_results(cmd, &result_type)) == CS_SUCCEED) {
            printf("More results?...\n");
            if (result_type == CS_STATUS_RESULT)
                continue;

            switch ((int) result_type) {
            case CS_ROW_RESULT:
                printf("do_fetch() returned: %d\n", do_fetch(cmd, &cnt));
                break;
            }
        }

        /* We should not have received all rows, as the alarm signal cancelled it... */
        if (cnt < 10000)
            break;

        if (clock <= 5000) {
            fprintf(stderr, "All rows read, this may not occur.\n");
            return 1;
        }
        g_cmd = NULL;
        clock /= 2;
    }

    /* Remove timer */
    timer.it_interval.tv_sec = 0;
    timer.it_interval.tv_usec = 0;
    timer.it_value.tv_sec = 0;
    timer.it_value.tv_usec = 0;
    if (0 != setitimer(ITIMER_REAL, &timer, NULL)) {
        fprintf(stderr, "Could not remove realtime timer.\n");
        return 1;
    }

    /*
     * Issue another command, this will be executed after a ct_cancel,
     * to test if wire state is consistent
     */
    ret = ct_command(cmd, CS_LANG_CMD, "SELECT * FROM #t0010 t1, #t0010 t2, #t0010 t3", CS_NULLTERM, CS_UNUSED);
    if (ret != CS_SUCCEED) {
        fprintf(stderr, "ct_command() failed.\n");
        return 1;
    }

    ret = ct_send(cmd);
    if (ret != CS_SUCCEED) {
        fprintf(stderr, "second ct_send() failed.\n");
        return 1;
    }

    while ((ret = ct_results(cmd, &result_type)) == CS_SUCCEED) {
        printf("More results?...\n");
        if (result_type == CS_STATUS_RESULT)
            continue;

        switch ((int) result_type) {
        case CS_ROW_RESULT:
            printf("do_fetch() returned: %d\n", do_fetch(cmd, &cnt));
            break;
        }
    }

    if (1000 != cnt) {
        /* This time, all rows must have been received */
        fprintf(stderr, "Incorrect number of rows read.\n");
        return 1;
    }

    if (verbose) {
        fprintf(stdout, "Trying logout\n");
    }
    ret = try_ctlogout(ctx, conn, cmd, verbose);
    if (ret != CS_SUCCEED) {
        fprintf(stderr, "Logout failed\n");
        return 1;
    }

    printf("%s: asynchronous cancel test: PASSED\n", __FILE__);

    return 0;
}
Beispiel #12
0
char *do_fetch_all(SOCKET sock, doit_ctx *ctx, int *len)
{
    return do_fetch(sock, ctx, 0, len);
}
Beispiel #13
0
char *do_fetch_line(SOCKET sock, doit_ctx *ctx)
{
    int len;
    return do_fetch(sock, ctx, 1, &len);
}