Exemplo n.º 1
0
int
main (int argc, char **argv)
{
	ret_t            ret;
	struct sigaction act;

	ret = check_for_python();
	if (ret != ret_ok) {
		PRINT_MSG ("ERROR: Couldn't find python.\n");
		exit (EXIT_ERROR);
	}

	/* Signal handling */
	act.sa_handler = SIG_IGN;
	sigaction (SIGPIPE, &act, NULL);

	memset(&act, 0, sizeof(act));
	act.sa_sigaction = signals_handler;
	act.sa_flags     = SA_SIGINFO;
	sigaction (SIGCHLD, &act, NULL);
	sigaction (SIGINT,  &act, NULL);
	sigaction (SIGTERM, &act, NULL);

	/* Initialize the embedded server */
	cherokee_init();
	cherokee_spawner_set_active (false);
	process_parameters (argc, argv);

	ret = cherokee_server_new (&srv);
	if (ret != ret_ok)
		exit (EXIT_ERROR);

	ret = config_server (srv);
	if (ret != ret_ok)
		exit (EXIT_ERROR);

	ret = cherokee_server_initialize (srv);
	if (ret != ret_ok)
		exit (EXIT_ERROR);

	print_connection_info();

	ret = cherokee_server_unlock_threads (srv);
	if (ret != ret_ok)
		exit (EXIT_ERROR);

	do {
		ret = cherokee_server_step (srv);
	} while (ret == ret_eagain);

	cherokee_server_stop (srv);
	cherokee_server_free (srv);

	cherokee_mrproper();
	return EXIT_OK;
}
Exemplo n.º 2
0
int
main (int argc, char **argv)
{
	ret_t ret;

	config_file = strdup (DEFAULT_CONFIG_FILE);
	if (config_file == NULL) {
		PRINT_MSG ("ERROR: Couldn't allocate memory.\n");
		exit (EXIT_ERROR);
	}

	cherokee_init();

	ret = cherokee_server_new (&srv);
	if (ret < ret_ok) {
		exit (EXIT_ERROR_FATAL);
	}

	ret = process_parameters (argc, argv);
	if (ret != ret_ok) {
		exit (EXIT_ERROR_FATAL);
	}

	if (print_modules) {
		cherokee_info_build_print (srv);
		exit (EXIT_OK_ONCE);
	}

	if (just_test) {
		ret = test_configuration_file();
		if (ret != ret_ok) {
			exit (EXIT_ERROR);
		}
		exit (EXIT_OK_ONCE);
	}

	ret = common_server_initialization (srv);
	if (ret < ret_ok) {
		exit (EXIT_ERROR_FATAL);
	}

	do {
		ret = cherokee_server_step (srv);
	} while (ret == ret_eagain);

	cherokee_server_stop (srv);
	cherokee_server_free (srv);

	free (config_file);
	cherokee_mrproper();

	return EXIT_OK;
}
Exemplo n.º 3
0
int
main (int argc, char **argv)
{
	ret_t ret;

	cherokee_init();

	ret = cherokee_server_new (&srv);
	if (ret < ret_ok) return 1;

	ret = process_parameters (argc, argv);
	if (ret != ret_ok)
		exit (EXIT_OK_ONCE);

	if (print_modules) {
		cherokee_info_build_print (srv);
		exit (EXIT_OK_ONCE);
	}

	if (just_test) {
		ret = test_configuration_file();
		if (ret != ret_ok)
			exit(EXIT_ERROR);
		exit (EXIT_OK_ONCE);
	}

	ret = common_server_initialization (srv);
	if (ret < ret_ok) return 2;

	do {
		ret = cherokee_server_step (srv);
	} while (ret == ret_eagain);

	cherokee_server_stop (srv);
	cherokee_server_free (srv);

	if (config_file)
		free (config_file);

	cherokee_mrproper();
	return EXIT_OK;
}
Exemplo n.º 4
0
int
main (int argc, char **argv)
{
    int                    re;
    ret_t                  ret;
    cint_t                 val;
    cint_t                 param_num;
    cint_t                 long_index;
    cherokee_downloader_t *downloader;
    cherokee_buffer_t      proxy       = CHEROKEE_BUF_INIT;
    cuint_t                proxy_port;

    struct option long_options[] = {
        /* Options without arguments */
        {"help",          no_argument,       NULL, 'h'},
        {"version",       no_argument,       NULL, 'V'},
        {"quiet",         no_argument,       NULL, 'q'},
        {"save-headers",  no_argument,       NULL, 's'},
        {"header",        required_argument, NULL,  0 },
        {NULL, 0, NULL, 0}
    };

    /* Parse known parameters
     */
    while ((val = getopt_long (argc, argv, "VshqO:", long_options, &long_index)) != -1) {
        switch (val) {
        case 'V':
            printf ("Cherokee Downloader %s\n"
                    "Written by Alvaro Lopez Ortega <*****@*****.**>\n\n"
                    "Copyright (C) 2001-2014 Alvaro Lopez Ortega.\n"
                    "This is free software; see the source for copying conditions.  There is NO\n"
                    "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n",
                    PACKAGE_VERSION);
            return EXIT_OK;

        case 'O':
            if (global_fd != UNSET_FD) {
                close (global_fd);
            }

            if ((strlen(optarg) == 1) && (optarg[0] == '-')) {
                global_fd = fileno(stdout);
            } else {
                global_fd = open (optarg, O_WRONLY | O_CREAT, 0644);
            }

            if (global_fd < 0) {
                PRINT_MSG ("ERROR: Can not open %s\n", optarg);
                return EXIT_ERROR;
            }
            break;

        case 0:
            break;

        case 'q':
            quiet = true;
            break;

        case 's':
            save_headers = true;
            break;

        case 'h':
        case '?':
        default:
            print_help();
            return EXIT_OK;
        }
    }

    /* The rest..
     */
    param_num = argc - optind;

    if (param_num <= 0) {
        print_usage();
        return EXIT_OK;
    }

    /* Tracing and proxy discovering..
     */
    cherokee_init();
    cget_find_proxy (&proxy, &proxy_port);

    for (val=optind; val<optind+param_num; val++) {
        cherokee_buffer_t url = CHEROKEE_BUF_INIT;

        /* Build the url buffer
         */
        ret = cherokee_buffer_add_va (&url, "%s", argv[val]);
        if (ret != ret_ok)
            exit (EXIT_ERROR);

        /* Create the downloader object..
         */
        ret = cherokee_downloader_new (&downloader);
        if (ret != ret_ok)
            exit (EXIT_ERROR);

        ret = cherokee_downloader_init(downloader);
        if (ret != ret_ok)
            exit (EXIT_ERROR);

        if (! cherokee_buffer_is_empty (&proxy)) {
            ret = cherokee_downloader_set_proxy (downloader, &proxy, proxy_port);
            if (ret != ret_ok)
                exit (EXIT_ERROR);
        }

        ret = cherokee_downloader_set_url (downloader, &url);
        if (ret != ret_ok)
            exit (EXIT_ERROR);

        ret = cherokee_downloader_connect (downloader);
        if (ret != ret_ok)
            exit (EXIT_ERROR);

        /* Download it!
         */
        ret = do_download (downloader);
        if ((ret != ret_ok) && (ret != ret_eof)) {
            exit (EXIT_ERROR);
        }

        /* Free the objects..
         */
        cherokee_buffer_mrproper (&url);
        cherokee_downloader_free (downloader);
    }

    /* Close the output file
     */
    re = close (output_fd);
    if (re != 0)
        exit (EXIT_ERROR);

    cherokee_mrproper();
    return EXIT_OK;
}
Exemplo n.º 5
0
int
main (int argc, char **argv)
{
	ret_t            ret;
	struct sigaction act;

	/* Globals */
	document_root = strdup (DEFAULT_DOCUMENTROOT);
	config_file   = strdup (DEFAULT_CONFIG_FILE);
	bind_to       = strdup (DEFAULT_BIND);

	if ((!bind_to) || (!config_file) || (!document_root)) {
		PRINT_MSG ("ERROR: Couldn't allocate memory.\n");
		exit (EXIT_ERROR);
	}

	/* Python */
	ret = check_for_python();
	if (ret != ret_ok) {
		PRINT_MSG ("ERROR: Couldn't find python.\n");
		exit (EXIT_ERROR);
	}

	/* Signal handling */
	act.sa_handler = SIG_IGN;
	sigaction (SIGPIPE, &act, NULL);

	memset(&act, 0, sizeof(act));
	act.sa_sigaction = signals_handler;
	act.sa_flags     = SA_SIGINFO;
	sigaction (SIGCHLD, &act, NULL);
	sigaction (SIGINT,  &act, NULL);
	sigaction (SIGTERM, &act, NULL);

	/* Initialize the embedded server */
	cherokee_init();

	/* Seed random numbers
	 */
	cherokee_random_seed();

	cherokee_spawner_set_active (false);
	process_parameters (argc, argv);

	ret = cherokee_server_new (&srv);
	if (ret != ret_ok)
		exit (EXIT_ERROR);

	ret = config_server (srv);
	if (ret != ret_ok)
		exit (EXIT_ERROR);

	ret = cherokee_server_initialize (srv);
	if (ret != ret_ok)
		exit (EXIT_ERROR);

	print_connection_info();

	ret = cherokee_server_unlock_threads (srv);
	if (ret != ret_ok)
		exit (EXIT_ERROR);

	do {
		ret = cherokee_server_step (srv);
	} while (ret == ret_eagain);

	cherokee_server_stop (srv);
	cherokee_server_free (srv);

	cherokee_mrproper();
	return EXIT_OK;
}