Пример #1
0
static void
test_webkit_download_create(void)
{
    WebKitNetworkRequest* request;
    WebKitDownload* download;
    const gchar* uri = "http://example.com";
    gchar* tmpDir;

    request = webkit_network_request_new(uri);
    download = webkit_download_new(request);
    g_object_unref(request);
    g_assert_cmpstr(webkit_download_get_uri(download), ==, uri);
    g_assert(webkit_download_get_network_request(download) == request);
    g_assert(g_strrstr(uri, webkit_download_get_suggested_filename(download)));
    g_assert(webkit_download_get_status(download) == WEBKIT_DOWNLOAD_STATUS_CREATED);
    g_assert(!webkit_download_get_total_size(download));
    g_assert(!webkit_download_get_current_size(download));
    g_assert(!webkit_download_get_progress(download));
    g_assert(!webkit_download_get_elapsed_time(download));
    tmpDir = g_filename_to_uri(g_get_tmp_dir(), NULL, NULL);
    webkit_download_set_destination_uri(download, tmpDir);
    g_assert_cmpstr(tmpDir, ==, webkit_download_get_destination_uri(download));;
    g_free(tmpDir);
    g_object_unref(download);
}
Пример #2
0
static gboolean
download_spawn_external(const char *uri, const char *filename, WebKitDownload *download)
{
    char **argv;
    int argc;
    gboolean ret = true;
    GError *error = NULL;
    char *newcommand = NULL;

    char *command = g_strdup(GET_CHAR("download-external-command"));
    WebKitNetworkRequest *request = webkit_download_get_network_request(download);
    const char *referer = soup_get_header_from_request(request, "Referer");
    const char *user_agent = soup_get_header_from_request(request, "User-Agent");

    char *proxy = GET_CHAR("proxy-url");
    gboolean has_proxy = GET_BOOL("proxy");

    GSList *list = g_slist_prepend(NULL, dwb_navigation_new("DWB_URI", uri));
    list = g_slist_prepend(list, dwb_navigation_new("DWB_FILENAME", filename));
    list = g_slist_prepend(list, dwb_navigation_new("DWB_COOKIES", dwb.files[FILES_COOKIES]));


    if ( (newcommand = util_string_replace(command, "dwb_uri", uri)) )
    {
        g_free(command);
        command = newcommand;
    }
    if ( (newcommand = util_string_replace(command, "dwb_cookies", dwb.files[FILES_COOKIES])) )
    {
        g_free(command);
        command = newcommand;
    }
    if ( (newcommand = util_string_replace(command, "dwb_output", filename)) )
    {
        g_free(command);
        command = newcommand;
    }
    if (referer != NULL)
    {
        list = g_slist_prepend(list, dwb_navigation_new("DWB_REFERER", referer));
    }
    if ( (newcommand = util_string_replace(command, "dwb_referer", referer == NULL ? "" : referer)) )
    {
        g_free(command);
        command = newcommand;
    }
    if ( (newcommand = util_string_replace(command, "dwb_proxy", proxy == NULL && has_proxy ? "" : proxy)) )
    {
        g_free(command);
        command = newcommand;
    }
    if (user_agent != NULL)
        list = g_slist_prepend(list, dwb_navigation_new("DWB_USER_AGENT", user_agent));

    list = g_slist_prepend(list, dwb_navigation_new("DWB_MIME_TYPE", dwb.state.mimetype_request));
    if (proxy != NULL && has_proxy)
        list = g_slist_prepend(list, dwb_navigation_new("DWB_PROXY", proxy));


    g_shell_parse_argv(command, &argc, &argv, NULL);
    g_free(command);
    if (!g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, (GSpawnChildSetupFunc)dwb_setup_environment, list, NULL, &error))
    {
        perror(error->message);
        ret = false;
    }
    g_strfreev(argv);
    return ret;
}