コード例 #1
0
ファイル: gssdp-resource-browser.c プロジェクト: GNOME/gssdp
static void
received_announcement (GSSDPResourceBrowser *resource_browser,
                       SoupMessageHeaders   *headers)
{
        const char *header;

        header = soup_message_headers_get_one (headers, "NT");
        if (!header)
                return; /* No target specified */

        if (!check_target_compat (resource_browser, header))
                return; /* Target doesn't match */

        header = soup_message_headers_get_one (headers, "NTS");
        if (!header)
                return; /* No announcement type specified */

        /* Check announcement type */
        if      (strncmp (header,
                          SSDP_ALIVE_NTS,
                          strlen (SSDP_ALIVE_NTS)) == 0)
                resource_available (resource_browser, headers);
        else if (strncmp (header,
                          SSDP_BYEBYE_NTS,
                          strlen (SSDP_BYEBYE_NTS)) == 0)
                resource_unavailable (resource_browser, headers);
        else if (strncmp (header,
                          SSDP_UPDATE_NTS,
                          strlen (SSDP_UPDATE_NTS)) == 0)
                resource_update (resource_browser, headers);
}
コード例 #2
0
/* Server handlers for "*" work but are separate from handlers for
 * all other URIs. #590751
 */
static void
do_star_test (void)
{
	SoupSession *session;
	SoupMessage *msg;
	SoupURI *star_uri;
	const char *handled_by;

	debug_printf (1, "\nOPTIONS *\n");

	session = soup_test_session_new (SOUP_TYPE_SESSION_SYNC, NULL);
	star_uri = soup_uri_copy (base_uri);
	soup_uri_set_path (star_uri, "*");

	debug_printf (1, "  Testing with no handler\n");
	msg = soup_message_new_from_uri ("OPTIONS", star_uri);
	soup_session_send_message (session, msg);

	if (msg->status_code != SOUP_STATUS_NOT_FOUND) {
		debug_printf (1, "    Unexpected response: %d %s\n",
			      msg->status_code, msg->reason_phrase);
		errors++;
	}
	handled_by = soup_message_headers_get_one (msg->response_headers,
						   "X-Handled-By");
	if (handled_by) {
		/* Should have been rejected by SoupServer directly */
		debug_printf (1, "    Message reached handler '%s'\n",
			      handled_by);
		errors++;
	}
	g_object_unref (msg);

	soup_server_add_handler (server, "*", server_star_callback, NULL, NULL);

	debug_printf (1, "  Testing with handler\n");
	msg = soup_message_new_from_uri ("OPTIONS", star_uri);
	soup_session_send_message (session, msg);

	if (msg->status_code != SOUP_STATUS_OK) {
		debug_printf (1, "    Unexpected response: %d %s\n",
			      msg->status_code, msg->reason_phrase);
		errors++;
	}
	handled_by = soup_message_headers_get_one (msg->response_headers,
						   "X-Handled-By");
	if (!handled_by) {
		debug_printf (1, "    Message did not reach handler!\n");
		errors++;
	} else if (strcmp (handled_by, "star_callback") != 0) {
		debug_printf (1, "    Message reached incorrect handler '%s'\n",
			      handled_by);
		errors++;
	}
	g_object_unref (msg);

	soup_test_session_abort_unref (session);
	soup_uri_free (star_uri);
}
コード例 #3
0
ファイル: gssdp-resource-browser.c プロジェクト: GNOME/gssdp
static void
resource_update (GSSDPResourceBrowser *resource_browser,
                 SoupMessageHeaders   *headers)
{
        GSSDPResourceBrowserPrivate *priv;
        const char *usn;
        const char *boot_id_header;
        const char *next_boot_id_header;
        char *canonical_usn;
        guint boot_id;
        guint next_boot_id;
        gint64 out;

        priv = gssdp_resource_browser_get_instance_private (resource_browser);
        usn = soup_message_headers_get_one (headers, "USN");
        boot_id_header = soup_message_headers_get_one (headers, "BOOTID.UPNP.ORG");
        next_boot_id_header = soup_message_headers_get_one (headers, "NEXTBOOTID.UPNP.ORG");

        if (!usn)
                return; /* No USN specified */

        if (!boot_id_header)
                return;

        if (!next_boot_id_header)
                return;

        if (!g_ascii_string_to_signed (boot_id_header, 10, 0, G_MAXINT32, &out, NULL))
                return;
        boot_id = out;

        if (!g_ascii_string_to_signed (next_boot_id_header, 10, 0, G_MAXINT32, &out, NULL))
                return;
        next_boot_id = out;

        if (priv->version > 0) {
                char *version;
                version = g_strrstr (usn, ":");
                canonical_usn = g_strndup (usn, version - usn);
        } else {
                canonical_usn = g_strdup (usn);
        }

        /* Only continue if we know about this. if not, there will be an
         * announcement afterwards anyway */
        if (!g_hash_table_lookup (priv->resources,
                                  canonical_usn))
                goto out;

        g_signal_emit (resource_browser,
                       signals[RESOURCE_UPDATE],
                       0,
                       usn,
                       boot_id,
                       next_boot_id);
out:
        g_free (canonical_usn);

}
コード例 #4
0
ファイル: multipart.c プロジェクト: jbastian/restraint
/*
 *  * We have two headeers we care about, Content-ID which we use as steam_type and
 *   * Status which we read when stream_type equals STREAM_ERROR.
 *    */
static void
multipart_read_headers (MultiPartData *multipart_data)
{
    multipart_data->headers = soup_multipart_input_stream_get_headers (multipart_data->multipart);
    if (multipart_data->headers) {
        multipart_data->method = soup_message_headers_get_one (multipart_data->headers, "rstrnt-method");
        multipart_data->path = soup_message_headers_get_one (multipart_data->headers, "rstrnt-path");
    }
}
コード例 #5
0
ファイル: snra-server-client.c プロジェクト: elisescu/aurena
static gboolean
is_websocket_client (SnraServerClient * client)
{
    /* Check for request headers. Example:
     * Upgrade: websocket
     * Connection: Upgrade, Keep-Alive
     * Sec-WebSocket-Key: XYZABC123
     * Sec-WebSocket-Protocol: aurena
     * Sec-WebSocket-Version: 13
     */
    SoupMessage *msg = client->event_pipe;
    SoupMessageHeaders *req_hdrs = msg->request_headers;
    const gchar *val;
    gint protocol_ver = 0;

    if ((val = soup_message_headers_get_one (req_hdrs, "Upgrade")) == NULL)
        return FALSE;
    if (g_ascii_strcasecmp (val, "websocket") != 0)
        return FALSE;
    if ((val = soup_message_headers_get_list (req_hdrs, "Connection")) == NULL)
        return FALSE;

    /* Connection params list must request upgrade to websocket */
    if (!http_list_contains_value (val, "upgrade"))
        return FALSE;

    if ((val =
                soup_message_headers_get_one (req_hdrs, "Sec-WebSocket-Key")) == NULL)
        return FALSE;
    if ((val =
                soup_message_headers_get_list (req_hdrs,
                        "Sec-WebSocket-Protocol")) == NULL)
        return FALSE;

    if (!http_list_contains_value (val, "aurena"))
        return FALSE;

    /* Requested protocol version must be 13 or 8 */
    if ((val = soup_message_headers_get_list (req_hdrs,
               "Sec-WebSocket-Version")) == NULL)
        return FALSE;

    if (http_list_contains_value (val, "13"))
        protocol_ver = 13;
    else if (http_list_contains_value (val, "8"))
        protocol_ver = 8;

    if (protocol_ver == 0)
        return FALSE;               /* No supported version found */

    g_print ("WebSocket connection with protocol %d\n", protocol_ver);
    client->websocket_protocol = protocol_ver;

    return TRUE;
}
コード例 #6
0
ファイル: cache-test.c プロジェクト: Kharif/libsoup
static void
request_started (SoupSession *session, SoupMessage *msg,
		 SoupSocket *socket)
{
	if (soup_message_headers_get_one (msg->request_headers,
					  "If-Modified-Since") ||
	    soup_message_headers_get_one (msg->request_headers,
					  "If-None-Match")) {
		debug_printf (2, "    Conditional request for %s\n",
			      soup_message_get_uri (msg)->path);
		last_request_validated = TRUE;
	}
}
コード例 #7
0
ファイル: coding-test.c プロジェクト: NEVERMOR/libsoup
static void
check_response (SoupMessage *msg,
		const char *expected_encoding,
		const char *expected_content_type,
		MessageContentStatus status)
{
	const char *coding, *type;

	if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
		debug_printf (1, "    Unexpected status %d %s\n",
			      msg->status_code, msg->reason_phrase);
		errors++;
	}

	coding = soup_message_headers_get_one (msg->response_headers, "Content-Encoding");
	if (expected_encoding) {
		if (!coding || g_ascii_strcasecmp (coding, expected_encoding) != 0) {
			debug_printf (1, "    Unexpected Content-Encoding: %s\n",
				      coding ? coding : "(none)");
			errors++;
		}
	} else {
		if (coding) {
			debug_printf (1, "    Unexpected Content-Encoding: %s\n",
				      coding);
			errors++;
		}
	}

	if (status != NO_CHECK) {
		if (status == EXPECT_DECODED) {
			if (!(soup_message_get_flags (msg) & SOUP_MESSAGE_CONTENT_DECODED)) {
				debug_printf (1, "    SOUP_MESSAGE_CONTENT_DECODED not set!\n");
				errors++;
			}
		} else {
			if (soup_message_get_flags (msg) & SOUP_MESSAGE_CONTENT_DECODED) {
				debug_printf (1, "    SOUP_MESSAGE_CONTENT_DECODED set!\n");
				errors++;
			}
		}
	}

	type = soup_message_headers_get_one (msg->response_headers, "Content-Type");
	if (!type || g_ascii_strcasecmp (type, expected_content_type) != 0) {
		debug_printf (1, "    Unexpected Content-Type: %s\n",
			      type ? type : "(none)");
		errors++;
	}
}
/**
 * soup_message_headers_get_encoding:
 * @hdrs: a #SoupMessageHeaders
 *
 * Gets the message body encoding that @hdrs declare. This may not
 * always correspond to the encoding used on the wire; eg, a HEAD
 * response may declare a Content-Length or Transfer-Encoding, but
 * it will never actually include a body.
 *
 * Return value: the encoding declared by @hdrs.
 **/
SoupEncoding
soup_message_headers_get_encoding (SoupMessageHeaders *hdrs)
{
	const char *header;

	if (hdrs->encoding != -1)
		return hdrs->encoding;

	/* If Transfer-Encoding was set, hdrs->encoding would already
	 * be set. So we don't need to check that possibility.
	 */
	header = soup_message_headers_get_one (hdrs, "Content-Length");
	if (header) {
		content_length_setter (hdrs, header);
		if (hdrs->encoding != -1)
			return hdrs->encoding;
	}

	/* Per RFC 2616 4.4, a response body that doesn't indicate its
	 * encoding otherwise is terminated by connection close, and a
	 * request that doesn't indicate otherwise has no body. Note
	 * that SoupMessage calls soup_message_headers_set_encoding()
	 * to override the response body default for our own
	 * server-side messages.
	 */
	hdrs->encoding = (hdrs->type == SOUP_MESSAGE_HEADERS_RESPONSE) ?
		SOUP_ENCODING_EOF : SOUP_ENCODING_NONE;
	return hdrs->encoding;
}
コード例 #9
0
ファイル: misc-test.c プロジェクト: Kharif/libsoup
static void
do_aliases_test_for_session (SoupSession *session,
			     const char *redirect_protocol)
{
	SoupMessage *msg;
	SoupURI *uri;
	const char *redirected_protocol;

	uri = soup_uri_new_with_base (base_uri, "/alias-redirect");
	msg = soup_message_new_from_uri ("GET", uri);
	if (redirect_protocol)
		soup_message_headers_append (msg->request_headers, "X-Redirect-Protocol", redirect_protocol);
	soup_uri_free (uri);
	soup_session_send_message (session, msg);

	redirected_protocol = soup_message_headers_get_one (msg->response_headers, "X-Redirected-Protocol");

	if (g_strcmp0 (redirect_protocol, redirected_protocol)) {
		debug_printf (1, "    redirect went to %s, should have gone to %s!\n",
			      redirected_protocol ? redirected_protocol : "(none)",
			      redirect_protocol ? redirect_protocol : "(none)");
		errors++;
	} else if (redirect_protocol && !SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
		debug_printf (1, "    msg failed? (%d %s)\n",
			      msg->status_code, msg->reason_phrase);
		errors++;
	} else if (!redirect_protocol && SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
		debug_printf (1, "    msg succeeded? (%d %s)\n",
			      msg->status_code, msg->reason_phrase);
		errors++;
	}

	g_object_unref (msg);
}
コード例 #10
0
ファイル: misc-test.c プロジェクト: Kharif/libsoup
static void
ipv6_server_callback (SoupServer *server, SoupMessage *msg,
		      const char *path, GHashTable *query,
		      SoupClientContext *context, gpointer data)
{
	const char *host;
	char expected_host[128];

	host = soup_message_headers_get_one (msg->request_headers, "Host");
	if (!host) {
		debug_printf (1, "    request has no Host header!\n");
		errors++;
		soup_message_set_status (msg, SOUP_STATUS_BAD_REQUEST);
		return;
	}

	g_snprintf (expected_host, sizeof (expected_host),
		    "[::1]:%d", soup_server_get_port (server));

	if (strcmp (host, expected_host) == 0)
		soup_message_set_status (msg, SOUP_STATUS_OK);
	else {
		debug_printf (1, "    request has incorrect Host header '%s'\n", host);
		errors++;
		soup_message_set_status (msg, SOUP_STATUS_BAD_REQUEST);
	}
}
コード例 #11
0
static void contentSniffedCallback(SoupMessage* msg, const char* sniffedType, GHashTable *params, gpointer data)
{
    if (sniffedType) {
        const char* officialType = soup_message_headers_get_one(msg->response_headers, "Content-Type");

        if (!officialType || strcmp(officialType, sniffedType))
            soup_message_headers_set_content_type(msg->response_headers, sniffedType, params);
    }

    // The 304 status code (SOUP_STATUS_NOT_MODIFIED) needs to be fed
    // into WebCore, as opposed to other kinds of redirections, which
    // are handled by soup directly, so we special-case it here and in
    // gotChunk.
    if (SOUP_STATUS_IS_TRANSPORT_ERROR(msg->status_code)
        || (SOUP_STATUS_IS_REDIRECTION(msg->status_code) && (msg->status_code != SOUP_STATUS_NOT_MODIFIED))
        || (msg->status_code == SOUP_STATUS_UNAUTHORIZED))
        return;

    RefPtr<ResourceHandle> handle = static_cast<ResourceHandle*>(data);
    if (!handle)
        return;
    ResourceHandleInternal* d = handle->getInternal();
    if (d->m_cancelled)
        return;
    ResourceHandleClient* client = handle->client();
    if (!client)
        return;

    fillResponseFromMessage(msg, &d->m_response);
    client->didReceiveResponse(handle.get(), d->m_response);
}
コード例 #12
0
ファイル: soup-auth-digest.c プロジェクト: Distrotech/libsoup
static void
authentication_info_cb (SoupMessage *msg, gpointer data)
{
	SoupAuth *auth = data;
	SoupAuthDigestPrivate *priv = SOUP_AUTH_DIGEST_GET_PRIVATE (auth);
	const char *header;
	GHashTable *auth_params;
	char *nextnonce;

	if (auth != soup_message_get_auth (msg))
		return;

	header = soup_message_headers_get_one (msg->response_headers,
					       soup_auth_is_for_proxy (auth) ?
					       "Proxy-Authentication-Info" :
					       "Authentication-Info");
	g_return_if_fail (header != NULL);

	auth_params = soup_header_parse_param_list (header);
	if (!auth_params)
		return;

	nextnonce = g_strdup (g_hash_table_lookup (auth_params, "nextnonce"));
	if (nextnonce) {
		g_free (priv->nonce);
		priv->nonce = nextnonce;
	}

	soup_header_free_param_list (auth_params);
}
コード例 #13
0
// This callback will not be called if the content sniffer is disabled in startHttp.
static void contentSniffedCallback(SoupMessage* msg, const char* sniffedType, GHashTable *params, gpointer data)
{
    if (sniffedType) {
        const char* officialType = soup_message_headers_get_one(msg->response_headers, "Content-Type");

        if (!officialType || strcmp(officialType, sniffedType))
            soup_message_headers_set_content_type(msg->response_headers, sniffedType, params);
    }

    if (statusWillBeHandledBySoup(msg->status_code))
        return;

    RefPtr<ResourceHandle> handle = static_cast<ResourceHandle*>(data);
    if (!handle)
        return;
    ResourceHandleInternal* d = handle->getInternal();
    if (d->m_cancelled)
        return;
    ResourceHandleClient* client = handle->client();
    if (!client)
        return;

    fillResponseFromMessage(msg, &d->m_response);
    client->didReceiveResponse(handle.get(), d->m_response);
}
コード例 #14
0
ファイル: auth-test.c プロジェクト: Conservatory/quark
static int
identify_auth (SoupMessage *msg)
{
	const char *header;
	int num;

	header = soup_message_headers_get_one (msg->request_headers,
					       "Authorization");
	if (!header)
		return 0;

	if (!g_ascii_strncasecmp (header, "Basic ", 6)) {
		char *token;
		gsize len;

		token = (char *)g_base64_decode (header + 6, &len);
		num = token[len - 1] - '0';
		g_free (token);
	} else {
		const char *user;

		user = strstr (header, "username=\"user");
		if (user)
			num = user[14] - '0';
		else
			num = 0;
	}

	g_assert (num >= 0 && num <= 4);

	return num;
}
コード例 #15
0
ファイル: utils.c プロジェクト: EliVerbrugge/gnome-twitch
GdkPixbuf*
utils_download_picture_if_newer(SoupSession* soup, const gchar* url, gint64 timestamp)
{
    SoupMessage* msg;
    guint soup_status;
    const gchar* last_modified;
    GdkPixbuf* ret;

    msg = soup_message_new(SOUP_METHOD_HEAD, url);
    soup_status = soup_session_send_message(soup, msg);

    if (SOUP_STATUS_IS_SUCCESSFUL(soup_status) &&
        (last_modified = soup_message_headers_get_one(msg->response_headers, "Last-Modified")) != NULL &&
        utils_http_full_date_to_timestamp(last_modified) < timestamp)
    {
        g_info("{Utils} No new content at url '%s'", url);
        ret = NULL;
    }
    else
        ret = utils_download_picture(soup, url);

    g_object_unref(msg);

    return ret;
}
コード例 #16
0
static void serverCallback(SoupServer* server, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, gpointer)
{
    if (message->method != SOUP_METHOD_GET) {
        soup_message_set_status(message, SOUP_STATUS_NOT_IMPLEMENTED);
        return;
    }

    if (g_str_equal(path, "/")) {
        const char* acceptLanguage = soup_message_headers_get_one(message->request_headers, "Accept-Language");
        soup_message_set_status(message, SOUP_STATUS_OK);
        soup_message_body_append(message->response_body, SOUP_MEMORY_COPY, acceptLanguage, strlen(acceptLanguage));
        soup_message_body_complete(message->response_body);
    } else if (g_str_equal(path, "/empty")) {
        const char* emptyHTML = "<html><body></body></html>";
        soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, emptyHTML, strlen(emptyHTML));
        soup_message_body_complete(message->response_body);
        soup_message_set_status(message, SOUP_STATUS_OK);
    } else if (g_str_equal(path, "/appcache")) {
        const char* appcacheHTML = "<html manifest=appcache.manifest><body></body></html>";
        soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, appcacheHTML, strlen(appcacheHTML));
        soup_message_body_complete(message->response_body);
        soup_message_set_status(message, SOUP_STATUS_OK);
    } else if (g_str_equal(path, "/appcache.manifest")) {
        const char* appcacheManifest = "CACHE MANIFEST\nCACHE:\nappcache/foo.txt\n";
        soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, appcacheManifest, strlen(appcacheManifest));
        soup_message_body_complete(message->response_body);
        soup_message_set_status(message, SOUP_STATUS_OK);
    } else if (g_str_equal(path, "/appcache/foo.txt")) {
        soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, "foo", 3);
        soup_message_body_complete(message->response_body);
        soup_message_set_status(message, SOUP_STATUS_OK);
    } else
        soup_message_set_status(message, SOUP_STATUS_NOT_FOUND);
}
コード例 #17
0
ファイル: simple-httpd.c プロジェクト: Distrotech/libsoup
static void
do_put (SoupServer *server, SoupMessage *msg, const char *path)
{
	struct stat st;
	FILE *f;
	gboolean created = TRUE;

	if (stat (path, &st) != -1) {
		const char *match = soup_message_headers_get_one (msg->request_headers, "If-None-Match");
		if (match && !strcmp (match, "*")) {
			soup_message_set_status (msg, SOUP_STATUS_CONFLICT);
			return;
		}

		if (!S_ISREG (st.st_mode)) {
			soup_message_set_status (msg, SOUP_STATUS_FORBIDDEN);
			return;
		}

		created = FALSE;
	}

	f = fopen (path, "w");
	if (!f) {
		soup_message_set_status (msg, SOUP_STATUS_INTERNAL_SERVER_ERROR);
		return;
	}

	fwrite (msg->request_body->data, 1, msg->request_body->length, f);
	fclose (f);

	soup_message_set_status (msg, created ? SOUP_STATUS_CREATED : SOUP_STATUS_OK);
}
コード例 #18
0
void ResourceResponse::updateFromSoupMessage(SoupMessage* soupMessage)
{
    SoupURI* soupURI = soup_message_get_uri(soupMessage);
    GOwnPtr<gchar> uri(soup_uri_to_string(soupURI, FALSE));
    m_url = KURL(KURL(), String::fromUTF8(uri.get()));

    m_httpStatusCode = soupMessage->status_code;

    SoupMessageHeadersIter headersIter;
    const char* headerName;
    const char* headerValue;

    soup_message_headers_iter_init(&headersIter, soupMessage->response_headers);
    while (soup_message_headers_iter_next(&headersIter, &headerName, &headerValue))
        m_httpHeaderFields.set(String::fromUTF8(headerName), String::fromUTF8(headerValue));

    m_soupFlags = soup_message_get_flags(soupMessage);

    String contentType = soup_message_headers_get_one(soupMessage->response_headers, "Content-Type");
    setMimeType(extractMIMETypeFromMediaType(contentType));

    setTextEncodingName(extractCharsetFromMediaType(contentType));
    setExpectedContentLength(soup_message_headers_get_content_length(soupMessage->response_headers));
    setHTTPStatusText(soupMessage->reason_phrase);
    setSuggestedFilename(filenameFromHTTPContentDisposition(httpHeaderField("Content-Disposition")));
}
コード例 #19
0
static gboolean
check_password (SoupAuthDomain *domain,
		SoupMessage    *msg,
		const char     *username,
		const char     *password)
{
	const char *header;
	GHashTable *params;
	const char *msg_username;
	char hex_urp[33];
	gboolean accept;

	header = soup_message_headers_get_one (msg->request_headers,
					       "Authorization");
	if (strncmp (header, "Digest ", 7) != 0)
		return FALSE;

	params = soup_header_parse_param_list (header + 7);
	if (!params)
		return FALSE;

	msg_username = g_hash_table_lookup (params, "username");
	if (!msg_username || strcmp (msg_username, username) != 0) {
		soup_header_free_param_list (params);
		return FALSE;
	}

	soup_auth_digest_compute_hex_urp (username,
					  soup_auth_domain_get_realm (domain),
					  password, hex_urp);
	accept = check_hex_urp (domain, msg, params, username, hex_urp);
	soup_header_free_param_list (params);
	return accept;
}
static void
callback (SoupSession * session, SoupMessage * msg, gpointer user_data)
{
  GstSoupHttpClientSink *souphttpsink = GST_SOUP_HTTP_CLIENT_SINK (user_data);

  GST_DEBUG_OBJECT (souphttpsink, "callback status=%d %s",
      msg->status_code, msg->reason_phrase);

  g_mutex_lock (&souphttpsink->mutex);
  g_cond_signal (&souphttpsink->cond);
  souphttpsink->message = NULL;

  if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
    souphttpsink->failures++;
    if (souphttpsink->retries &&
        (souphttpsink->retries < 0 ||
            souphttpsink->retries >= souphttpsink->failures)) {
      guint64 retry_delay;
      const char *retry_after =
          soup_message_headers_get_one (msg->response_headers,
          "Retry-After");
      if (retry_after) {
        gchar *end = NULL;
        retry_delay = g_ascii_strtoull (retry_after, &end, 10);
        if (end || errno) {
          retry_delay = souphttpsink->retry_delay;
        } else {
          retry_delay = MAX (retry_delay, souphttpsink->retry_delay);
        }
        GST_WARNING_OBJECT (souphttpsink, "Could not write to HTTP URI: "
            "status: %d %s (retrying PUT after %" G_GINT64_FORMAT
            " seconds with Retry-After: %s)", msg->status_code,
            msg->reason_phrase, retry_delay, retry_after);
      } else {
        retry_delay = souphttpsink->retry_delay;
        GST_WARNING_OBJECT (souphttpsink, "Could not write to HTTP URI: "
            "status: %d %s (retrying PUT after %" G_GINT64_FORMAT
            " seconds)", msg->status_code, msg->reason_phrase, retry_delay);
      }
      souphttpsink->timer = g_timeout_source_new_seconds (retry_delay);
      g_source_set_callback (souphttpsink->timer, (GSourceFunc) (send_message),
          souphttpsink, NULL);
      g_source_attach (souphttpsink->timer, souphttpsink->context);
    } else {
      souphttpsink->status_code = msg->status_code;
      souphttpsink->reason_phrase = g_strdup (msg->reason_phrase);
    }
    g_mutex_unlock (&souphttpsink->mutex);
    return;
  }

  g_list_free_full (souphttpsink->sent_buffers,
      (GDestroyNotify) gst_buffer_unref);
  souphttpsink->sent_buffers = NULL;
  souphttpsink->failures = 0;

  send_message_locked (souphttpsink);
  g_mutex_unlock (&souphttpsink->mutex);
}
コード例 #21
0
static void
databases_items_xxx (DMAPShare * share,
		     SoupServer * server,
		     SoupMessage * msg,
		     const char *path,
		     GHashTable * query, SoupClientContext * context)
{
	DMAPDb *db;
	const gchar *transcode_mimetype;
	const gchar *rest_of_path;
	const gchar *id_str;
	guint id;
	const gchar *range_header;
	guint64 filesize;
	guint64 offset = 0;
	DAAPRecord *record;

	rest_of_path = strchr (path + 1, '/');
	id_str = rest_of_path + 9;
	id = strtoul (id_str, NULL, 10);

	g_object_get (share, "db", &db, NULL);
	record = DAAP_RECORD (dmap_db_lookup_by_id (db, id));
	g_object_get (record, "filesize", &filesize, NULL);

	DMAP_SHARE_GET_CLASS (share)->message_add_standard_headers
		(share, msg);
	soup_message_headers_append (msg->response_headers, "Accept-Ranges",
				     "bytes");

	range_header =
		soup_message_headers_get_one (msg->request_headers, "Range");
	if (range_header) {
		const gchar *s;
		gchar *content_range;

		s = range_header + 6;	/* bytes= */
		offset = atoll (s);

		content_range =
			g_strdup_printf ("bytes %" G_GUINT64_FORMAT "-%"
					 G_GUINT64_FORMAT "/%"
					 G_GUINT64_FORMAT, offset, filesize,
					 filesize);
		soup_message_headers_append (msg->response_headers,
					     "Content-Range", content_range);
		g_debug ("Content range is %s.", content_range);
		g_free (content_range);
		soup_message_set_status (msg, SOUP_STATUS_PARTIAL_CONTENT);
	} else {
		soup_message_set_status (msg, SOUP_STATUS_OK);
	}
	g_object_get (share, "transcode-mimetype", &transcode_mimetype, NULL);
	send_chunked_file (server, msg, record, filesize, offset,
			   transcode_mimetype);

	g_object_unref (record);
}
コード例 #22
0
ファイル: net.c プロジェクト: gcampax/liferea
static void
network_process_callback (SoupSession *session, SoupMessage *msg, gpointer user_data)
{
	updateJobPtr	job = (updateJobPtr)user_data;
	SoupDate	*last_modified;
	const gchar	*tmp = NULL;

	job->result->source = soup_uri_to_string (soup_message_get_uri(msg), FALSE);
	if (SOUP_STATUS_IS_TRANSPORT_ERROR (msg->status_code)) {
		job->result->returncode = msg->status_code;
		job->result->httpstatus = 0;
	} else {
		job->result->httpstatus = msg->status_code;
		job->result->returncode = 0;
	}

	debug1 (DEBUG_NET, "download status code: %d", msg->status_code);
	debug1 (DEBUG_NET, "source after download: >>>%s<<<", job->result->source);

	job->result->data = g_memdup (msg->response_body->data, msg->response_body->length+1);
	job->result->size = (size_t)msg->response_body->length;
	debug1 (DEBUG_NET, "%d bytes downloaded", job->result->size);

	job->result->contentType = g_strdup (soup_message_headers_get_content_type (msg->response_headers, NULL));

	/* Update last-modified date */
	tmp = soup_message_headers_get_one (msg->response_headers, "Last-Modified");
	if (tmp) {
		/* The string may be badly formatted, which will make
		 * soup_date_new_from_string() return NULL */
		last_modified = soup_date_new_from_string (tmp);
		if (last_modified) {
			job->result->updateState->lastModified = soup_date_to_time_t (last_modified);
			soup_date_free (last_modified);
		}
	}

	/* Update ETag value */
	tmp = soup_message_headers_get_one (msg->response_headers, "ETag");
	if (tmp) {
		job->result->updateState->etag = g_strdup(tmp);
	}    

	update_process_finished_job (job);
}
コード例 #23
0
ファイル: auth-test.c プロジェクト: simonmiddleton/libsoup
static void
disappear_request_read (SoupServer *server, SoupMessage *msg,
			SoupClientContext *context, gpointer user_data)
{
	/* Remove the WWW-Authenticate header if this was a failed attempt */
	if (soup_message_headers_get_one (msg->request_headers, "Authorization") &&
	    msg->status_code == SOUP_STATUS_UNAUTHORIZED)
		soup_message_headers_remove (msg->response_headers, "WWW-Authenticate");
}
コード例 #24
0
ファイル: snra-server-client.c プロジェクト: elisescu/aurena
SnraServerClient *
snra_server_client_new (SoupServer * soup, SoupMessage * msg,
                        SoupClientContext * context)
{
    SnraServerClient *client = g_object_new (SNRA_TYPE_SERVER_CLIENT, NULL);
    const gchar *accept_challenge;
    gchar *accept_reply;

    client->soup = soup;
    client->event_pipe = msg;
    client->host = g_strdup (soup_client_context_get_host (context));

    client->net_event_sig = g_signal_connect (msg, "network-event",
                            G_CALLBACK (snra_server_client_network_event), client);
    client->disco_sig = g_signal_connect (msg, "finished",
                                          G_CALLBACK (snra_server_client_disconnect), client);

    if (!is_websocket_client (client)) {
        client->type = SNRA_SERVER_CLIENT_CHUNKED;
        client->need_body_complete = TRUE;

        soup_message_headers_set_encoding (msg->response_headers,
                                           SOUP_ENCODING_CHUNKED);
        soup_message_set_status (msg, SOUP_STATUS_OK);
        return client;
    }

    /* Otherwise, it's a websocket client */
    client->type = SNRA_SERVER_CLIENT_WEBSOCKET;
    client->need_body_complete = FALSE;

    client->socket = soup_client_context_get_socket (context);
    client->in_bufptr = client->in_buf = g_new0 (gchar, 1024);
    client->in_bufsize = 1024;
    client->in_bufavail = 0;

    accept_challenge =
        soup_message_headers_get_one (msg->request_headers, "Sec-WebSocket-Key");
    accept_reply = calc_websocket_challenge_reply (accept_challenge);

    soup_message_headers_set_encoding (msg->response_headers, SOUP_ENCODING_EOF);

    soup_message_set_status (msg, SOUP_STATUS_SWITCHING_PROTOCOLS);
    soup_message_headers_replace (msg->response_headers, "Upgrade", "websocket");
    soup_message_headers_replace (msg->response_headers, "Connection", "Upgrade");
    soup_message_headers_replace (msg->response_headers, "Sec-WebSocket-Accept",
                                  accept_reply);
    soup_message_headers_replace (msg->response_headers, "Sec-WebSocket-Protocol",
                                  "aurena");

    g_free (accept_reply);

    client->wrote_info_sig = g_signal_connect (msg, "wrote-informational",
                             G_CALLBACK (snra_server_client_wrote_headers), client);

    return client;
}
コード例 #25
0
ファイル: geoip-update.c プロジェクト: kalev/geoclue
/* local_db_needs_update function returns TRUE on success and FALSE on failure.
 * It sets the parameter needs_update to TRUE if the local database needs
 * to be updated.
 */
static gboolean
local_db_needs_update (SoupSession *session,
                       const char  *db_uri,
                       GFile       *db_local,
                       gboolean    *needs_update,
                       GError     **error)
{
        GFileInfo *db_local_info;
        SoupMessage *msg;
        SoupDate *date;
        const gchar *db_time_str;
        guint64 db_time;
        guint64 db_local_time;
        guint status_code;

        if (g_file_query_exists (db_local, NULL) == FALSE) {
                *needs_update = TRUE;
                return TRUE;
        }

        msg = soup_message_new ("HEAD", db_uri);
        status_code = soup_session_send_message (session, msg);
        if (status_code != SOUP_STATUS_OK) {
                g_set_error_literal (error,
                                     SOUP_HTTP_ERROR,
                                     status_code,
                                     msg->reason_phrase);
                return FALSE;
        }

        db_time_str = soup_message_headers_get_one (msg->response_headers, "Last-Modified");
        date = soup_date_new_from_string (db_time_str);
        db_time = (guint64) soup_date_to_time_t (date);
        soup_date_free (date);
        g_object_unref (msg);

        db_local_info = g_file_query_info (db_local,
                                           "time::modified",
                                           G_FILE_QUERY_INFO_NONE,
                                           NULL,
                                           error);
        if (!db_local_info)
                return FALSE;

        db_local_time = g_file_info_get_attribute_uint64 (db_local_info, "time::modified");
        if (db_time <= db_local_time)
                *needs_update = FALSE;
        else
                *needs_update = TRUE;

        g_object_unref (db_local_info);

        return TRUE;
}
コード例 #26
0
static void
soup_session_cb (SoupSession *session,
                 SoupMessage *msg,
                 gpointer     user_data)
{
  DQTask *task = user_data;

  if (SOUP_STATUS_IS_REDIRECTION (msg->status_code))
    {
      const char *header =
        soup_message_headers_get_one (msg->response_headers, "Location");

      if (header)
        {
          SoupURI *uri;

          uri = soup_uri_new_with_base (soup_message_get_uri (msg), header);
          soup_message_set_uri (msg, uri);
          soup_uri_free (uri);

          soup_session_requeue_message (session, msg);

          return;
        }
    }
  else if (SOUP_STATUS_IS_SUCCESSFUL (msg->status_code))
    {
      void *cache;

      task->any.callback (task->any.queue, task->any.uri,
                          msg->response_body->data,
                          msg->response_body->length,
                          NULL,
                          task->any.userdata);

      /* add the contents to the cache */
      cache = g_memdup (msg->response_body->data, msg->response_body->length);
      mex_download_queue_cache_insert (task->any.queue, task->any.uri, cache,
                                       msg->response_body->length);

    }
  else if (msg->status_code != SOUP_STATUS_CANCELLED)
    {
      /* FIXME: Also create an error on failure */
      task->any.callback (task->any.queue, task->any.uri,
                          NULL, 0, NULL,
                          task->any.userdata);
    }

  /* The message is unref'd by the session */
  task->soup.message = NULL;

  mex_download_queue_free (task);
}
コード例 #27
0
ファイル: ntlm-test.c プロジェクト: BabaNina/libsoup
static void
request_check (SoupMessage *msg, gpointer user_data)
{
	NTLMState *state = user_data;
	const char *header;

	header = soup_message_headers_get_one (msg->request_headers,
					       "Authorization");
	if (header && !strncmp (header, "NTLM " NTLM_REQUEST_START,
				strlen ("NTLM " NTLM_REQUEST_START)))
		state->sent_ntlm_request = TRUE;
}
コード例 #28
0
static void serverCallback(SoupServer* server, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, gpointer)
{
    if (message->method != SOUP_METHOD_GET) {
        soup_message_set_status(message, SOUP_STATUS_NOT_IMPLEMENTED);
        return;
    }

    soup_message_set_status(message, SOUP_STATUS_OK);
    const char* userAgent = soup_message_headers_get_one(message->request_headers, "User-Agent");
    soup_message_body_append(message->response_body, SOUP_MEMORY_COPY, userAgent, strlen(userAgent));
    soup_message_body_complete(message->response_body);
}
コード例 #29
0
ファイル: e-soap-message.c プロジェクト: tivv/evolution-ews
static void
soap_got_headers (SoupMessage *msg,
                  gpointer data)
{
	ESoapMessagePrivate *priv = E_SOAP_MESSAGE_GET_PRIVATE (msg);
	const gchar *size;

	size = soup_message_headers_get_one (msg->response_headers,
					     "Content-Length");

	if (size)
		priv->response_size = strtol (size, NULL, 10);
}
コード例 #30
0
ファイル: coding-test.c プロジェクト: ChingezKhan/libsoup
static void
server_callback (SoupServer *server, SoupMessage *msg,
		 const char *path, GHashTable *query,
		 SoupClientContext *context, gpointer data)
{
	const char *accept_encoding, *junk;
	GSList *codings;
	char *file = NULL, *contents;
	gsize length;

	accept_encoding = soup_message_headers_get_list (msg->request_headers,
							 "Accept-Encoding");
	if (accept_encoding)
		codings = soup_header_parse_quality_list (accept_encoding, NULL);
	else
		codings = NULL;

	if (codings && g_slist_find_custom (codings, "gzip", (GCompareFunc)g_ascii_strcasecmp)) {
		file = g_strdup_printf (SRCDIR "/resources%s.gz", path);
		if (g_file_test (file, G_FILE_TEST_EXISTS)) {
			soup_message_headers_append (msg->response_headers,
						     "Content-Encoding",
						     "gzip");
		} else {
			g_free (file);
			file = NULL;
		}
	}

	if (!file)
		file = g_strdup_printf (SRCDIR "/resources%s", path);
	if (!g_file_get_contents (file, &contents, &length, NULL)) {
		/* If path.gz exists but can't be read, we'll send back
		 * the error with "Content-Encoding: gzip" but there's
		 * no body, so, eh.
		 */
		soup_message_set_status (msg, SOUP_STATUS_NOT_FOUND);
		return;
	}

	soup_message_set_status (msg, SOUP_STATUS_OK);
	soup_message_body_append (msg->response_body,
				  SOUP_MEMORY_TAKE, contents, length);

	junk = soup_message_headers_get_one (msg->request_headers,
					     "X-Trailing-Junk");
	if (junk) {
		soup_message_body_append (msg->response_body, SOUP_MEMORY_COPY,
					  junk, strlen (junk));
	}
}