my @this;
my $inside=0;
+ my $base64=0;
# print "Section: $section, part: $part\n";
$inside++;
}
elsif((1 ==$inside) && ($_ =~ /^ *\<$part[ \>]/)) {
+ if($_ =~ /$part .*base64=/) {
+ # attempt to detect base64 encoded parts
+ $base64=1;
+ }
$inside++;
}
elsif((2 ==$inside) && ($_ =~ /^ *\<\/$part/)) {
if(!@this && $warning) {
print STDERR "*** getpart.pm: $section/$part returned empty!\n";
}
+ if($base64) {
+ # decode the whole array before returning it!
+ for(@this) {
+ my $decoded = decode_base64($_);
+ $_ = $decoded;
+ }
+ }
return @this;
}
elsif(2==$inside) {
my $sizefirst=scalar(@$firstref);
my $sizesecond=scalar(@$secondref);
+ my $first;
+ my $second;
+
for(1 .. $sizefirst) {
my $index = $_ - 1;
if($firstref->[$index] ne $secondref->[$index]) {
(my $aa = $firstref->[$index]) =~ s/\r+\n$/\n/;
(my $bb = $secondref->[$index]) =~ s/\r+\n$/\n/;
- if($aa ne $bb) {
- return 1+$index;
- }
+
+ $first .= $firstref->[$index];
+ $second .= $secondref->[$index];
}
}
+
+ # we cannot compare arrays index per index since with the base64 chunks,
+ # they may not be "evenly" distributed
+
+ # NOTE: this no longer strips off carriage returns from the arrays. Is that
+ # really necessary? It ruins the testing of newlines. I believe it was once
+ # added to enable tests on win32.
+
+ if($first ne $second) {
+ return 1;
+ }
+
return 0;
}
/***************************************************************************
- * _ _ ____ _
- * Project ___| | | | _ \| |
- * / __| | | | |_) | |
- * | (__| |_| | _ <| |___
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2004, Daniel Stenberg, <daniel@haxx.se>, et al.
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at http://curl.haxx.se/docs/copyright.html.
- *
+ *
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
#include <stdlib.h>
#include "getpart.h"
+#define _MPRINTF_REPLACE /* use our functions only */
+#include <curl/mprintf.h>
+
+#include "base64.h"
+
+/* include memdebug.h last */
+#include "memdebug.h"
+
#define EAT_SPACE(ptr) while( ptr && *ptr && isspace((int)*ptr) ) ptr++
#define EAT_WORD(ptr) while( ptr && *ptr && !isspace((int)*ptr) && ('>' != *ptr)) ptr++
#define show(x)
#endif
+curl_malloc_callback Curl_cmalloc = (curl_malloc_callback)malloc;
+curl_free_callback Curl_cfree = (curl_free_callback)free;
+curl_realloc_callback Curl_crealloc = (curl_realloc_callback)realloc;
+curl_strdup_callback Curl_cstrdup = (curl_strdup_callback)strdup;
+curl_calloc_callback Curl_ccalloc = (curl_calloc_callback)calloc;
+
static
char *appendstring(char *string, /* original string */
char *buffer, /* to append */
size_t *stringlen, /* length of string */
- size_t *stralloc) /* allocated size */
+ size_t *stralloc, /* allocated size */
+ char base64) /* 1 if base64 encoded */
{
size_t len = strlen(buffer);
size_t needed_len = len + *stringlen;
+ char buf64[256]; /* big enough? */
+
+ if(base64) {
+ /* decode the given buffer first */
+ len = Curl_base64_decode(buffer, buf64); /* updated len */
+ buffer = buf64;
+ needed_len = len + *stringlen; /* recalculate */
+ }
if(needed_len >= *stralloc) {
char *newptr;
else
return NULL;
}
- strcpy(&string[*stringlen], buffer);
+ /* memcpy to support binary blobs */
+ memcpy(&string[*stringlen], buffer, len);
*stringlen += len;
return string;
char *string;
size_t stringlen=0;
size_t stralloc=256;
+ char base64 = 0; /* set to 1 if true */
enum {
STATE_OUTSIDE,
return NULL;
string[0] = 0; /* zero first byte in case of no data */
-
+
while(fgets(buffer, sizeof(buffer), stream)) {
ptr = buffer;
if('<' != *ptr) {
if(display) {
show(("=> %s", buffer));
- string = appendstring(string, buffer, &stringlen, &stralloc);
+ string = appendstring(string, buffer, &stringlen, &stralloc, base64);
show(("* %s\n", buffer));
}
continue;
/* this is the beginning of a section */
end = ptr;
EAT_WORD(end);
-
+
*end = 0;
switch(state) {
case STATE_OUTSIDE:
default:
break;
}
+
+ if(!end[1] != '>') {
+ /* There might be attributes here. Check for those we know of and care
+ about. */
+ if(strstr(&end[1], "base64=")) {
+ /* rought and dirty, but "mostly" functional */
+ /* Treat all data as base64 encoded */
+ base64 = 1;
+ }
+ }
}
if(display) {
- string = appendstring(string, buffer, &stringlen, &stralloc);
+ string = appendstring(string, buffer, &stringlen, &stralloc, base64);
show(("* %s\n", buffer));
}
return string;
}
-#ifdef TEST
+#ifdef GETPART_TEST
int main(int argc, char **argv)
{
if(argc< 3) {
printf("./moo main sub\n");
}
else {
- int size;
- char *buffer = spitout(stdin, argv[1], argv[2], &size);
+ size_t size;
+ const char *buffer = spitout(stdin, argv[1], argv[2], &size);
+ printf("%s", buffer);
}
return 0;
}
/***************************************************************************
- * _ _ ____ _
- * Project ___| | | | _ \| |
- * / __| | | | |_) | |
- * | (__| |_| | _ <| |___
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2004, Daniel Stenberg, <daniel@haxx.se>, et al.
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at http://curl.haxx.se/docs/copyright.html.
- *
+ *
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.