Example #1
0
gboolean net_io_download_file(GtkWidget *parent, settings_t *settings,
			      char *url, char *filename, const char *title) {
  net_io_request_t *request = g_new0(net_io_request_t, 1);

  printf("net_io: download %s to file %s\n", url, filename);
  request->type = NET_IO_DL_FILE;
  request->url = g_strdup(url);
  request->filename = g_strdup(filename);
  if(settings && settings->proxy)
    request->proxy = settings->proxy;

  gboolean result = net_io_do(parent, request, title);
  if(!result) {

    /* remove the file that may have been written by now. the kernel */
    /* should cope with the fact that the worker thread may still have */
    /* an open reference to this and might thus still write to this file. */
    /* letting the worker delete the file is worse since it may take the */
    /* worker some time to come to the point to delete this file. If the */
    /* user has restarted the download by then, the worker will erase that */
    /* newly written file */

    printf("request failed, deleting %s\n", filename);
    g_remove(filename);
  } else
    printf("request ok\n");

  request_free(request);
  return result;
}
Example #2
0
gboolean net_io_download(GtkWidget *parent, char *url, char **mem) {
  net_io_request_t *request = g_new0(net_io_request_t, 1);

  request->proxy = proxy_config_get();
  request->url = g_strdup(url);

  gboolean result = net_io_do(parent, request);
  if(result) 
    *mem = request->result.data.ptr;
  
  request_free(request);
  return result;
}
Example #3
0
gboolean net_io_download_mem(GtkWidget *parent, settings_t *settings,
			     char *url, char **mem) {
  net_io_request_t *request = g_new0(net_io_request_t, 1);

  printf("net_io: download %s to memory\n", url);
  request->type = NET_IO_DL_MEM;
  request->url = g_strdup(url);
  if(settings && settings->proxy)
    request->proxy = settings->proxy;

  gboolean result = net_io_do(parent, request, NULL);
  if(result) {
    printf("ptr = %p, len = %d\n", request->mem.ptr, request->mem.len);
    *mem = request->mem.ptr;
  }

  request_free(request);
  return result;
}