Exemple #1
0
/**
 * Delayed RPC start.
 */
static void
soap_rpc_launch(cqueue_t *unused_cq, gpointer obj)
{
	soap_rpc_t *sr = obj;
	http_post_data_t post;

	(void) unused_cq;
	soap_rpc_check(sr);

	sr->delay_ev = NULL;

	if (GNET_PROPERTY(soap_debug) > 4) {
		g_debug("SOAP \"%s\" at \"%s\": launching (%s)",
			sr->action, sr->url, sr->retry ? "retry" : "initial");
	}

	sr->reply_len = 0;		/* In case we retry, clear out older data */

	/*
	 * Launch the asynchronous POST request.
	 */

	post.content_type = SOAP_CONTENT_TYPE;
	post.data = pmsg_start(sr->mb);
	post.datalen = pmsg_size(sr->mb);
	post.data_free = NULL;
	post.data_free_arg = NULL;

	sr->ha = http_async_post(sr->url, &post, soap_header_ind,
				soap_data_ind, soap_error_ind);

	/*
	 * If we cannot create the HTTP request, it can be the URL is wrong,
	 * or no connection can be established to the host.  Hence it's a
	 * contacting error, not an I/O error at this stage.
	 */

	if (sr->ha == NULL) {
		if (GNET_PROPERTY(soap_debug)) {
			g_warning("SOAP cannot contact \"%s\": %s",
				sr->url, http_async_strerror(http_async_errno));
		}
		soap_error(sr, SOAP_E_CONTACT);
		return;
	}

	/*
	 * Customize the HTTP layer.
	 */

	http_async_set_opaque(sr->ha, sr, NULL);
	http_async_set_op_post_request(sr->ha, soap_build_request);
	http_async_set_op_headsent(sr->ha, soap_sent_head);
	http_async_set_op_datasent(sr->ha, soap_sent_data);
	http_async_set_op_gotreply(sr->ha, soap_got_reply);
	http_async_option_ctl(sr->ha, HTTP_O_READ_REPLY, HTTP_CTL_ADD);
}
Exemple #2
0
/**
 * Retrieve more hosts from web cache, asynchronously.
 */
void
gwc_get_hosts(void)
{
    void *handle;
    char *url;
    const char *msg;
    static time_t last_called = 0;
    time_t now = tm_time();

    /*
     * Make sure we don't probe more than one webcache at a time.
     * Ancient versions should rely on their hostcache to be connected.
     */

    if (gwc_get_running || GNET_PROPERTY(ancient_version))
        return;

    /*
     * This routine is called each time we run out of hosts to try in our
     * cache, so we have absolutely no guarantee about the frequency at which
     * it will be called.
     *
     * Force picking up a new cache (well, randomly) if we were called less
     * than an hour ago.  Note that we don't remember whether it was THIS
     * particular current cache that was accessed last time we were called.
     * We only care about the calling frequency, and bet on the high number
     * of available web caches and the random selection process to behave.
     * properly.
     *		--RAM, 24/11/2003
     */

    if (delta_time(now, last_called) < REUSE_PERIOD)
        gwc_clear_current_url(FALSE);

    last_called = now;

    if (!gwc_check_current_url())
        return;

    /*
     * Give some GUI feedback.
     */

    msg = str_smsg(_("Connecting to web cache %s"), gwc_current_url);
    gcu_statusbar_message(msg);

    if (GNET_PROPERTY(bootstrap_debug))
        g_message("BOOT connecting to web cache %s", gwc_current_url);

    /*
     * Launch the asynchronous request and attach parsing information.
     */

    msg = str_smsg("%s?get=1&net=gnutella2&%s", gwc_current_url, CLIENT_INFO);
    url = h_strdup(msg);

    if (GNET_PROPERTY(bootstrap_debug) > 2)
        g_message("GWC host request: %s", url);

    handle = http_async_get(url, NULL, gwc_host_data_ind, gwc_host_error_ind);

    if (NULL == handle) {
        g_warning("could not launch a \"GET %s\" request: %s",
                  url, http_async_strerror(http_async_errno));
        gwc_clear_current_url(TRUE);
    } else {
        http_async_set_op_gotreply(handle, gwc_got_reply);
        gwc_parse_context_set(handle, MAX_IP_LINES);
        gwc_get_running = TRUE;
    }

    hfree(url);
}