Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Web update: encode special characters in filenames

  • Loading branch information...
commit 31d6e7edab26c39a8690de62f21437f39642491f 1 parent fd8b55d
Sébastien Bourdeauducq authored July 03, 2011

Showing 1 changed file with 33 additions and 2 deletions. Show diff stats Hide diff stats

  1. 35  src/flash.c
35  src/flash.c
@@ -422,12 +422,42 @@ static void download_images()
422 422
 	}
423 423
 }
424 424
 
  425
+/* As often, standard adoration does a lot of damage and prevents people from
  426
+ * writing software that just works by default.
  427
+ * (http://curl.haxx.se/mail/lib-2009-08/0176.html)
  428
+ */
  429
+static char *curl_author_needs_to_take_a_dump(char *s)
  430
+{
  431
+	CURL *curl;
  432
+	char *ret, *ret2;
  433
+	
  434
+	curl = curl_easy_init();
  435
+	if(!curl) return NULL;
  436
+	ret = curl_easy_escape(curl, s, 0);
  437
+	if(!ret) {
  438
+		curl_easy_cleanup(curl);
  439
+		return NULL;
  440
+	}
  441
+	/* I'm not sure if the pointer is still valid after curl_easy_cleanup(),
  442
+	 * and the curl doc doesn't say that.
  443
+	 */
  444
+	ret2 = strdup(ret);
  445
+	curl_free(ret);
  446
+	if(!ret2) {
  447
+		curl_easy_cleanup(curl);
  448
+		return NULL;
  449
+	}
  450
+	curl_easy_cleanup(curl);
  451
+	return ret2;
  452
+}
  453
+
425 454
 static void download_patches(struct patchpool *pp)
426 455
 {
427 456
 	int done, total;
428 457
 	int i;
429 458
 	char url[384];
430 459
 	char target[384];
  460
+	char *encoded;
431 461
 	
432 462
 	/* TODO: ensure that the patch pool directory exists. Issue #25 precludes a simple mkdir(). */
433 463
 	
@@ -437,9 +467,10 @@ static void download_patches(struct patchpool *pp)
437 467
 	total = patchpool_count(pp);
438 468
 	for(i=0;i<pp->alloc_size;i++) {
439 469
 		if(pp->names[i] != NULL) {
440  
-			snprintf(url, sizeof(url), BASE_URL "patches/%s", pp->names[i]);
  470
+			encoded = curl_author_needs_to_take_a_dump(pp->names[i]);
  471
+			snprintf(url, sizeof(url), BASE_URL "patches/%s", encoded);
  472
+			free(encoded);
441 473
 			snprintf(target, sizeof(target), SIMPLE_PATCHES_FOLDER "%s", pp->names[i]);
442  
-			printf("Downloading: %s -> %s\n", url, target);
443 474
 			download(url, target, 0);
444 475
 			done++;
445 476
 		}

0 notes on commit 31d6e7e

Please sign in to comment.
Something went wrong with that request. Please try again.