Beispiel #1
0
/**
 * curl_download_get_url:
 *  Either hostname and/or uri should be defined
 *
 */
CURL_download_t curl_download_get_url ( const char *hostname, const char *uri, FILE *f, DownloadFileOptions *options, gboolean ftp, CurlDownloadOptions *cdo, void *handle )
{
  gchar *full = NULL;

  if ( hostname && strstr ( hostname, "://" ) != NULL ) {
    if ( uri && strlen ( uri ) > 1 )
      // Simply append them together
      full = g_strdup_printf ( "%s%s", hostname, uri );
    else
      /* Already full url */
      full = (gchar *) hostname;
  }
  else if ( uri && strstr ( uri, "://" ) != NULL )
    /* Already full url */
    full = (gchar *) uri;
  else if ( hostname && uri )
    /* Compose the full url */
    full = g_strdup_printf ( "%s://%s%s", (ftp?"ftp":"http"), hostname, uri );
  else {
    return CURL_DOWNLOAD_ERROR;
  }

  CURL_download_t ret = curl_download_uri ( full, f, options, cdo, handle );
  // Only free newly allocated memory
  if ( hostname != full && uri != full )
    g_free ( full );

  return ret;
}
Beispiel #2
0
/**
 * a_download_url_to_tmp_file:
 * @uri:         The URI (Uniform Resource Identifier)
 * @options:     Download options (maybe NULL)
 *
 * returns name of the temporary file created - NULL if unsuccessful
 *  this string needs to be freed once used
 *  the file needs to be removed once used
 */
gchar *a_download_uri_to_tmp_file ( const gchar *uri, DownloadFileOptions *options )
{
  FILE *tmp_file;
  int tmp_fd;
  gchar *tmpname;

  if ( (tmp_fd = g_file_open_tmp ("viking-download.XXXXXX", &tmpname, NULL)) == -1 ) {
    g_critical (_("couldn't open temp file"));
    return NULL;
  }

  tmp_file = fdopen(tmp_fd, "r+");
  if ( !tmp_file )
    return NULL;

  if ( curl_download_uri ( uri, tmp_file, options, NULL, NULL ) ) {
    // error
    fclose ( tmp_file );
    (void)g_remove ( tmpname );
    g_free ( tmpname );
    return NULL;
  }
  fclose ( tmp_file );

  return tmpname;
}
Beispiel #3
0
int curl_download_get_url ( const char *hostname, const char *uri, FILE *f, DownloadMapOptions *options, gboolean ftp, DownloadFileOptions *file_options, void *handle )
{
  int ret;
  gchar *full = NULL;

  /* Compose the full url */
  full = g_strdup_printf ( "%s://%s%s", (ftp?"ftp":"http"), hostname, uri );
  ret = curl_download_uri ( full, f, options, file_options, handle );
  g_free ( full );
  full = NULL;

  return ret;
}
Beispiel #4
0
int curl_download_get_url ( const char *hostname, const char *uri, FILE *f, DownloadMapOptions *options, gboolean ftp, DownloadFileOptions *file_options, void *handle )
{
  int ret;
  gchar *full = NULL;

  if ( strstr ( hostname, "://" ) != NULL )
    /* Already full url */
    full = (gchar *) hostname;
  else if ( strstr ( uri, "://" ) != NULL )
    /* Already full url */
    full = (gchar *) uri;
  else
    /* Compose the full url */
    full = g_strdup_printf ( "%s://%s%s", (ftp?"ftp":"http"), hostname, uri );
  ret = curl_download_uri ( full, f, options, file_options, handle );
  /* Free newly allocated memory, but do not free uri */
  if ( hostname != full && uri != full )
    g_free ( full );
  full = NULL;

  return ret;
}
Beispiel #5
0
gchar *download_url(gchar *uri)
{
  FILE *tmp_file;
  int tmp_fd;
  gchar *tmpname;

  if ((tmp_fd = g_file_open_tmp ("vikgsearch.XXXXXX", &tmpname, NULL)) == -1) {
    g_critical(_("couldn't open temp file"));
    exit(1);
  }
  tmp_file = fdopen(tmp_fd, "r+");

  // TODO: curl may not be available
  if (curl_download_uri(uri, tmp_file, NULL, 0, NULL)) {  // error
    fclose(tmp_file);
    tmp_file = NULL;
    g_remove(tmpname);
    g_free(tmpname);
    return(NULL);
  }
  fclose(tmp_file);
  tmp_file = NULL;
  return(tmpname);
}