Пример #1
0
Файл: util.c Проект: vifino/dwb
/* dwb_quickmark_new(const char *uri, const char *title,  const char *key)  {{{*/
Quickmark *
dwb_quickmark_new(const char *uri, const char *title, const char *key) 
{
    Quickmark *q = dwb_malloc(sizeof(Quickmark));
    q->key = key ? g_strdup(key) : NULL;
    q->nav = dwb_navigation_new(uri, title);
    return q;
}/* }}} */
Пример #2
0
Файл: util.c Проект: vifino/dwb
/* dwb_navigation_new_from_line(const char *text){{{*/
Navigation * 
dwb_navigation_new_from_line(const char *text) 
{
    char **line;
    Navigation *nv = NULL;
    if (text == NULL)
        return NULL;
    while (g_ascii_isspace(*text))
        text++;

    if (*text != '\0') 
    {
        line = g_strsplit(text, " ", 2);
        nv = dwb_navigation_new(line[0], line[1]);
        g_strfreev(line);
    }
    return nv;
}/*}}}*/
Пример #3
0
Файл: util.c Проект: vifino/dwb
/* dwb_navigation_new(const char *uri, const char *title) {{{*/
Navigation *
dwb_navigation_new(const char *uri, const char *title) 
{
    Navigation *nv = dwb_malloc(sizeof(Navigation)); 
    nv->first = uri ? g_strdup(uri) : NULL;
    nv->second = title ? g_strdup(title) : NULL;
    return nv;
}/*}}}*/
Navigation * 
dwb_navigation_dup(Navigation *n) 
{
    return dwb_navigation_new(n->first, n->second);
}
Пример #4
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;
}