2004-02-20 02:19:18 -05:00
|
|
|
/***************************************************************************
|
2004-11-29 07:10:09 -05:00
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
2004-02-20 02:19:18 -05:00
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2017-09-09 17:55:08 -04:00
|
|
|
* Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
|
2004-02-20 02:19:18 -05:00
|
|
|
*
|
|
|
|
* This software is licensed as described in the file COPYING, which
|
|
|
|
* you should have received as part of this distribution. The terms
|
2016-02-02 18:19:02 -05:00
|
|
|
* are also available at https://curl.haxx.se/docs/copyright.html.
|
2004-11-29 07:10:09 -05:00
|
|
|
*
|
2004-02-20 02:19:18 -05:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
***************************************************************************/
|
2012-04-10 11:32:06 -04:00
|
|
|
#include "server_setup.h"
|
2004-11-29 16:44:23 -05:00
|
|
|
|
2004-02-20 02:19:18 -05:00
|
|
|
#include "getpart.h"
|
2002-02-07 04:39:15 -05:00
|
|
|
|
2010-02-26 11:42:33 -05:00
|
|
|
#define ENABLE_CURLX_PRINTF
|
|
|
|
/* make the curlx header define all printf() functions to use the curlx_*
|
|
|
|
versions instead */
|
|
|
|
#include "curlx.h" /* from the private lib dir */
|
2004-11-29 07:10:09 -05:00
|
|
|
|
2011-04-06 01:30:09 -04:00
|
|
|
/* just to please curl_base64.h we create a fake struct */
|
2016-06-21 09:47:12 -04:00
|
|
|
struct Curl_easy {
|
2007-01-04 18:04:50 -05:00
|
|
|
int fake;
|
|
|
|
};
|
|
|
|
|
2008-08-16 20:25:38 -04:00
|
|
|
#include "curl_base64.h"
|
2009-04-21 07:46:16 -04:00
|
|
|
#include "curl_memory.h"
|
2004-11-29 07:10:09 -05:00
|
|
|
|
2013-01-03 20:50:28 -05:00
|
|
|
/* include memdebug.h last */
|
|
|
|
#include "memdebug.h"
|
2004-11-29 07:10:09 -05:00
|
|
|
|
2010-02-14 08:14:17 -05:00
|
|
|
#define EAT_SPACE(p) while(*(p) && ISSPACE(*(p))) (p)++
|
2002-02-07 04:39:15 -05:00
|
|
|
|
2010-02-14 08:14:17 -05:00
|
|
|
#define EAT_WORD(p) while(*(p) && !ISSPACE(*(p)) && ('>' != *(p))) (p)++
|
|
|
|
|
|
|
|
#ifdef DEBUG_GETPART
|
2002-02-22 05:40:05 -05:00
|
|
|
#define show(x) printf x
|
|
|
|
#else
|
2011-09-03 10:06:10 -04:00
|
|
|
#define show(x) Curl_nop_stmt
|
2002-02-22 05:40:05 -05:00
|
|
|
#endif
|
|
|
|
|
2008-10-23 10:07:28 -04:00
|
|
|
#if defined(_MSC_VER) && defined(_DLL)
|
|
|
|
# pragma warning(disable:4232) /* MSVC extension, dllimport identity */
|
|
|
|
#endif
|
|
|
|
|
2004-11-29 07:10:09 -05:00
|
|
|
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;
|
2013-07-19 00:44:46 -04:00
|
|
|
#if defined(WIN32) && defined(UNICODE)
|
|
|
|
curl_wcsdup_callback Curl_cwcsdup = (curl_wcsdup_callback)_wcsdup;
|
2013-07-18 14:04:02 -04:00
|
|
|
#endif
|
2004-11-29 07:10:09 -05:00
|
|
|
|
2008-10-23 10:07:28 -04:00
|
|
|
#if defined(_MSC_VER) && defined(_DLL)
|
|
|
|
# pragma warning(default:4232) /* MSVC extension, dllimport identity */
|
|
|
|
#endif
|
|
|
|
|
2017-09-08 03:33:22 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Curl_convert_clone() returns a malloced copy of the source string (if
|
|
|
|
* returning CURLE_OK), with the data converted to network format. This
|
|
|
|
* function is used by base64 code in libcurl built to support data
|
|
|
|
* conversion. This is a DUMMY VERSION that returns data unmodified - for
|
|
|
|
* use by the test server only.
|
|
|
|
*/
|
|
|
|
CURLcode Curl_convert_clone(struct Curl_easy *data,
|
|
|
|
const char *indata,
|
|
|
|
size_t insize,
|
|
|
|
char **outbuf);
|
|
|
|
CURLcode Curl_convert_clone(struct Curl_easy *data,
|
|
|
|
const char *indata,
|
|
|
|
size_t insize,
|
|
|
|
char **outbuf)
|
|
|
|
{
|
|
|
|
char *convbuf;
|
|
|
|
(void)data;
|
|
|
|
|
|
|
|
convbuf = malloc(insize);
|
|
|
|
if(!convbuf)
|
|
|
|
return CURLE_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
memcpy(convbuf, indata, insize);
|
|
|
|
*outbuf = convbuf;
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
2010-02-14 08:14:17 -05:00
|
|
|
/*
|
|
|
|
* readline()
|
|
|
|
*
|
|
|
|
* Reads a complete line from a file into a dynamically allocated buffer.
|
|
|
|
*
|
|
|
|
* Calling function may call this multiple times with same 'buffer'
|
|
|
|
* and 'bufsize' pointers to avoid multiple buffer allocations. Buffer
|
|
|
|
* will be reallocated and 'bufsize' increased until whole line fits in
|
|
|
|
* buffer before returning it.
|
|
|
|
*
|
|
|
|
* Calling function is responsible to free allocated buffer.
|
|
|
|
*
|
|
|
|
* This function may return:
|
|
|
|
* GPE_OUT_OF_MEMORY
|
|
|
|
* GPE_END_OF_FILE
|
|
|
|
* GPE_OK
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int readline(char **buffer, size_t *bufsize, FILE *stream)
|
|
|
|
{
|
|
|
|
size_t offset = 0;
|
|
|
|
size_t length;
|
|
|
|
char *newptr;
|
|
|
|
|
|
|
|
if(!*buffer) {
|
|
|
|
*buffer = malloc(128);
|
|
|
|
if(!*buffer)
|
|
|
|
return GPE_OUT_OF_MEMORY;
|
|
|
|
*bufsize = 128;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(;;) {
|
2010-02-26 11:42:33 -05:00
|
|
|
int bytestoread = curlx_uztosi(*bufsize - offset);
|
|
|
|
|
|
|
|
if(!fgets(*buffer + offset, bytestoread, stream))
|
2016-04-03 16:35:43 -04:00
|
|
|
return (offset != 0) ? GPE_OK : GPE_END_OF_FILE;
|
2010-02-14 08:14:17 -05:00
|
|
|
|
|
|
|
length = offset + strlen(*buffer + offset);
|
|
|
|
if(*(*buffer + length - 1) == '\n')
|
|
|
|
break;
|
|
|
|
offset = length;
|
|
|
|
if(length < *bufsize - 1)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
newptr = realloc(*buffer, *bufsize * 2);
|
|
|
|
if(!newptr)
|
|
|
|
return GPE_OUT_OF_MEMORY;
|
|
|
|
*buffer = newptr;
|
|
|
|
*bufsize *= 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return GPE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* appenddata()
|
|
|
|
*
|
|
|
|
* This appends data from a given source buffer to the end of the used part of
|
|
|
|
* a destination buffer. Arguments relative to the destination buffer are, the
|
|
|
|
* address of a pointer to the destination buffer 'dst_buf', the length of data
|
|
|
|
* in destination buffer excluding potential null string termination 'dst_len',
|
|
|
|
* the allocated size of destination buffer 'dst_alloc'. All three destination
|
|
|
|
* buffer arguments may be modified by this function. Arguments relative to the
|
|
|
|
* source buffer are, a pointer to the source buffer 'src_buf' and indication
|
|
|
|
* whether the source buffer is base64 encoded or not 'src_b64'.
|
|
|
|
*
|
|
|
|
* If the source buffer is indicated to be base64 encoded, this appends the
|
|
|
|
* decoded data, binary or whatever, to the destination. The source buffer
|
|
|
|
* may not hold binary data, only a null terminated string is valid content.
|
|
|
|
*
|
|
|
|
* Destination buffer will be enlarged and relocated as needed.
|
|
|
|
*
|
|
|
|
* Calling function is responsible to provide preallocated destination
|
|
|
|
* buffer and also to deallocate it when no longer needed.
|
|
|
|
*
|
|
|
|
* This function may return:
|
|
|
|
* GPE_OUT_OF_MEMORY
|
|
|
|
* GPE_OK
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int appenddata(char **dst_buf, /* dest buffer */
|
|
|
|
size_t *dst_len, /* dest buffer data length */
|
|
|
|
size_t *dst_alloc, /* dest buffer allocated size */
|
|
|
|
char *src_buf, /* source buffer */
|
|
|
|
int src_b64) /* != 0 if source is base64 encoded */
|
2002-02-18 20:04:46 -05:00
|
|
|
{
|
2013-11-02 13:00:00 -04:00
|
|
|
size_t need_alloc = 0;
|
|
|
|
size_t src_len = strlen(src_buf);
|
2008-10-02 10:44:18 -04:00
|
|
|
|
2010-02-14 08:14:17 -05:00
|
|
|
if(!src_len)
|
|
|
|
return GPE_OK;
|
2008-10-02 10:44:18 -04:00
|
|
|
|
2013-11-02 13:00:00 -04:00
|
|
|
need_alloc = src_len + *dst_len + 1;
|
2004-11-29 07:10:09 -05:00
|
|
|
|
2010-02-14 08:14:17 -05:00
|
|
|
if(src_b64) {
|
2013-11-02 13:00:00 -04:00
|
|
|
if(src_buf[src_len - 1] == '\r')
|
|
|
|
src_len--;
|
2002-02-18 20:04:46 -05:00
|
|
|
|
2013-11-02 13:00:00 -04:00
|
|
|
if(src_buf[src_len - 1] == '\n')
|
|
|
|
src_len--;
|
|
|
|
}
|
2003-09-03 11:37:30 -04:00
|
|
|
|
2010-02-14 08:14:17 -05:00
|
|
|
/* enlarge destination buffer if required */
|
|
|
|
if(need_alloc > *dst_alloc) {
|
|
|
|
size_t newsize = need_alloc * 2;
|
|
|
|
char *newptr = realloc(*dst_buf, newsize);
|
|
|
|
if(!newptr) {
|
|
|
|
return GPE_OUT_OF_MEMORY;
|
2005-02-24 13:54:23 -05:00
|
|
|
}
|
2010-02-14 08:14:17 -05:00
|
|
|
*dst_alloc = newsize;
|
|
|
|
*dst_buf = newptr;
|
2002-02-18 20:04:46 -05:00
|
|
|
}
|
2010-02-14 08:14:17 -05:00
|
|
|
|
2004-11-29 07:10:09 -05:00
|
|
|
/* memcpy to support binary blobs */
|
2010-02-14 08:14:17 -05:00
|
|
|
memcpy(*dst_buf + *dst_len, src_buf, src_len);
|
|
|
|
*dst_len += src_len;
|
|
|
|
*(*dst_buf + *dst_len) = '\0';
|
2002-02-18 20:04:46 -05:00
|
|
|
|
2013-11-02 13:00:00 -04:00
|
|
|
return GPE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int decodedata(char **buf, /* dest buffer */
|
|
|
|
size_t *len) /* dest buffer data length */
|
|
|
|
{
|
2017-05-01 07:17:57 -04:00
|
|
|
CURLcode error = CURLE_OK;
|
2013-11-03 07:25:07 -05:00
|
|
|
unsigned char *buf64 = NULL;
|
2013-11-02 13:00:00 -04:00
|
|
|
size_t src_len = 0;
|
|
|
|
|
|
|
|
if(!*len)
|
|
|
|
return GPE_OK;
|
|
|
|
|
|
|
|
/* base64 decode the given buffer */
|
2017-05-01 07:17:57 -04:00
|
|
|
error = Curl_base64_decode(*buf, &buf64, &src_len);
|
2013-11-02 13:00:00 -04:00
|
|
|
if(error)
|
|
|
|
return GPE_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
if(!src_len) {
|
|
|
|
/*
|
|
|
|
** currently there is no way to tell apart an OOM condition in
|
|
|
|
** Curl_base64_decode() from zero length decoded data. For now,
|
|
|
|
** let's just assume it is an OOM condition, currently we have
|
|
|
|
** no input for this function that decodes to zero length data.
|
|
|
|
*/
|
2015-03-11 12:41:01 -04:00
|
|
|
free(buf64);
|
2013-11-02 13:00:00 -04:00
|
|
|
|
|
|
|
return GPE_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* memcpy to support binary blobs */
|
|
|
|
memcpy(*buf, buf64, src_len);
|
|
|
|
*len = src_len;
|
|
|
|
*(*buf + src_len) = '\0';
|
|
|
|
|
|
|
|
free(buf64);
|
2005-02-22 07:10:30 -05:00
|
|
|
|
2010-02-14 08:14:17 -05:00
|
|
|
return GPE_OK;
|
2002-02-18 20:04:46 -05:00
|
|
|
}
|
|
|
|
|
2010-02-14 08:14:17 -05:00
|
|
|
/*
|
|
|
|
* getpart()
|
|
|
|
*
|
|
|
|
* This returns whole contents of specified XML-like section and subsection
|
|
|
|
* from the given file. This is mostly used to retrieve a specific part from
|
|
|
|
* a test definition file for consumption by test suite servers.
|
|
|
|
*
|
|
|
|
* Data is returned in a dynamically allocated buffer, a pointer to this data
|
|
|
|
* and the size of the data is stored at the addresses that caller specifies.
|
|
|
|
*
|
|
|
|
* If the returned data is a string the returned size will be the length of
|
|
|
|
* the string excluding null termination. Otherwise it will just be the size
|
|
|
|
* of the returned binary data.
|
|
|
|
*
|
|
|
|
* Calling function is responsible to free returned buffer.
|
|
|
|
*
|
|
|
|
* This function may return:
|
|
|
|
* GPE_NO_BUFFER_SPACE
|
|
|
|
* GPE_OUT_OF_MEMORY
|
|
|
|
* GPE_OK
|
|
|
|
*/
|
|
|
|
|
|
|
|
int getpart(char **outbuf, size_t *outlen,
|
|
|
|
const char *main, const char *sub, FILE *stream)
|
2002-02-07 04:39:15 -05:00
|
|
|
{
|
2010-02-14 08:14:17 -05:00
|
|
|
# define MAX_TAG_LEN 79
|
2017-09-09 17:55:08 -04:00
|
|
|
char couter[MAX_TAG_LEN + 1]; /* current outermost section */
|
|
|
|
char cmain[MAX_TAG_LEN + 1]; /* current main section */
|
|
|
|
char csub[MAX_TAG_LEN + 1]; /* current sub section */
|
|
|
|
char ptag[MAX_TAG_LEN + 1]; /* potential tag */
|
|
|
|
char patt[MAX_TAG_LEN + 1]; /* potential attributes */
|
2010-02-14 08:14:17 -05:00
|
|
|
char *buffer = NULL;
|
2002-02-07 04:39:15 -05:00
|
|
|
char *ptr;
|
|
|
|
char *end;
|
2010-02-15 11:18:52 -05:00
|
|
|
union {
|
|
|
|
ssize_t sig;
|
|
|
|
size_t uns;
|
|
|
|
} len;
|
2010-02-14 08:14:17 -05:00
|
|
|
size_t bufsize = 0;
|
|
|
|
size_t outalloc = 256;
|
|
|
|
int in_wanted_part = 0;
|
|
|
|
int base64 = 0;
|
|
|
|
int error;
|
2002-02-07 04:39:15 -05:00
|
|
|
|
|
|
|
enum {
|
2010-02-14 08:14:17 -05:00
|
|
|
STATE_OUTSIDE = 0,
|
|
|
|
STATE_OUTER = 1,
|
|
|
|
STATE_INMAIN = 2,
|
|
|
|
STATE_INSUB = 3,
|
|
|
|
STATE_ILLEGAL = 4
|
2002-02-07 04:39:15 -05:00
|
|
|
} state = STATE_OUTSIDE;
|
|
|
|
|
2010-02-14 08:14:17 -05:00
|
|
|
*outlen = 0;
|
|
|
|
*outbuf = malloc(outalloc);
|
|
|
|
if(!*outbuf)
|
|
|
|
return GPE_OUT_OF_MEMORY;
|
|
|
|
*(*outbuf) = '\0';
|
2003-09-03 11:37:30 -04:00
|
|
|
|
2010-02-14 08:14:17 -05:00
|
|
|
couter[0] = cmain[0] = csub[0] = ptag[0] = patt[0] = '\0';
|
2004-11-29 07:10:09 -05:00
|
|
|
|
2010-02-14 08:14:17 -05:00
|
|
|
while((error = readline(&buffer, &bufsize, stream)) == GPE_OK) {
|
2002-02-07 04:39:15 -05:00
|
|
|
|
|
|
|
ptr = buffer;
|
|
|
|
EAT_SPACE(ptr);
|
|
|
|
|
|
|
|
if('<' != *ptr) {
|
2010-02-14 08:14:17 -05:00
|
|
|
if(in_wanted_part) {
|
2002-02-22 05:40:05 -05:00
|
|
|
show(("=> %s", buffer));
|
2010-02-14 08:14:17 -05:00
|
|
|
error = appenddata(outbuf, outlen, &outalloc, buffer, base64);
|
|
|
|
if(error)
|
|
|
|
break;
|
2002-02-07 04:39:15 -05:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
ptr++;
|
|
|
|
|
|
|
|
if('/' == *ptr) {
|
2010-02-14 08:14:17 -05:00
|
|
|
/*
|
|
|
|
** closing section tag
|
|
|
|
*/
|
2002-02-07 04:39:15 -05:00
|
|
|
|
2010-02-14 08:14:17 -05:00
|
|
|
ptr++;
|
2002-02-07 04:39:15 -05:00
|
|
|
end = ptr;
|
|
|
|
EAT_WORD(end);
|
2016-12-13 19:29:44 -05:00
|
|
|
len.sig = end - ptr;
|
|
|
|
if(len.sig > MAX_TAG_LEN) {
|
2010-02-14 08:14:17 -05:00
|
|
|
error = GPE_NO_BUFFER_SPACE;
|
|
|
|
break;
|
2002-02-07 04:39:15 -05:00
|
|
|
}
|
2010-02-15 11:18:52 -05:00
|
|
|
memcpy(ptag, ptr, len.uns);
|
|
|
|
ptag[len.uns] = '\0';
|
2010-02-14 08:14:17 -05:00
|
|
|
|
|
|
|
if((STATE_INSUB == state) && !strcmp(csub, ptag)) {
|
|
|
|
/* end of current sub section */
|
|
|
|
state = STATE_INMAIN;
|
|
|
|
csub[0] = '\0';
|
|
|
|
if(in_wanted_part) {
|
|
|
|
/* end of wanted part */
|
|
|
|
in_wanted_part = 0;
|
2013-11-02 13:00:00 -04:00
|
|
|
|
|
|
|
/* Do we need to base64 decode the data? */
|
|
|
|
if(base64) {
|
|
|
|
error = decodedata(outbuf, outlen);
|
|
|
|
if(error)
|
|
|
|
return error;
|
|
|
|
}
|
2010-02-14 08:14:17 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if((STATE_INMAIN == state) && !strcmp(cmain, ptag)) {
|
|
|
|
/* end of current main section */
|
|
|
|
state = STATE_OUTER;
|
|
|
|
cmain[0] = '\0';
|
|
|
|
if(in_wanted_part) {
|
|
|
|
/* end of wanted part */
|
|
|
|
in_wanted_part = 0;
|
2013-11-02 13:00:00 -04:00
|
|
|
|
|
|
|
/* Do we need to base64 decode the data? */
|
|
|
|
if(base64) {
|
|
|
|
error = decodedata(outbuf, outlen);
|
|
|
|
if(error)
|
|
|
|
return error;
|
|
|
|
}
|
2010-02-14 08:14:17 -05:00
|
|
|
break;
|
|
|
|
}
|
2002-02-07 04:39:15 -05:00
|
|
|
}
|
2010-02-14 08:14:17 -05:00
|
|
|
else if((STATE_OUTER == state) && !strcmp(couter, ptag)) {
|
|
|
|
/* end of outermost file section */
|
|
|
|
state = STATE_OUTSIDE;
|
|
|
|
couter[0] = '\0';
|
|
|
|
if(in_wanted_part) {
|
|
|
|
/* end of wanted part */
|
|
|
|
in_wanted_part = 0;
|
|
|
|
break;
|
|
|
|
}
|
2007-01-22 21:25:56 -05:00
|
|
|
}
|
2010-02-14 08:14:17 -05:00
|
|
|
|
2002-02-07 04:39:15 -05:00
|
|
|
}
|
2010-02-14 08:14:17 -05:00
|
|
|
else if(!in_wanted_part) {
|
|
|
|
/*
|
|
|
|
** opening section tag
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* get potential tag */
|
2002-02-07 04:39:15 -05:00
|
|
|
end = ptr;
|
|
|
|
EAT_WORD(end);
|
2016-12-13 19:29:44 -05:00
|
|
|
len.sig = end - ptr;
|
|
|
|
if(len.sig > MAX_TAG_LEN) {
|
2010-02-14 08:14:17 -05:00
|
|
|
error = GPE_NO_BUFFER_SPACE;
|
2002-02-07 04:39:15 -05:00
|
|
|
break;
|
2010-02-14 08:14:17 -05:00
|
|
|
}
|
2010-02-15 11:18:52 -05:00
|
|
|
memcpy(ptag, ptr, len.uns);
|
|
|
|
ptag[len.uns] = '\0';
|
2010-02-14 08:14:17 -05:00
|
|
|
|
|
|
|
/* ignore comments, doctypes and xml declarations */
|
|
|
|
if(('!' == ptag[0]) || ('?' == ptag[0])) {
|
|
|
|
show(("* ignoring (%s)", buffer));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get all potential attributes */
|
|
|
|
ptr = end;
|
|
|
|
EAT_SPACE(ptr);
|
|
|
|
end = ptr;
|
|
|
|
while(*end && ('>' != *end))
|
|
|
|
end++;
|
2016-12-13 19:29:44 -05:00
|
|
|
len.sig = end - ptr;
|
|
|
|
if(len.sig > MAX_TAG_LEN) {
|
2010-02-14 08:14:17 -05:00
|
|
|
error = GPE_NO_BUFFER_SPACE;
|
2003-01-23 07:00:15 -05:00
|
|
|
break;
|
2002-02-07 04:39:15 -05:00
|
|
|
}
|
2010-02-15 11:18:52 -05:00
|
|
|
memcpy(patt, ptr, len.uns);
|
|
|
|
patt[len.uns] = '\0';
|
2004-11-29 07:10:09 -05:00
|
|
|
|
2010-02-14 08:14:17 -05:00
|
|
|
if(STATE_OUTSIDE == state) {
|
|
|
|
/* outermost element (<testcase>) */
|
|
|
|
strcpy(couter, ptag);
|
|
|
|
state = STATE_OUTER;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if(STATE_OUTER == state) {
|
|
|
|
/* start of a main section */
|
|
|
|
strcpy(cmain, ptag);
|
|
|
|
state = STATE_INMAIN;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if(STATE_INMAIN == state) {
|
|
|
|
/* start of a sub section */
|
|
|
|
strcpy(csub, ptag);
|
|
|
|
state = STATE_INSUB;
|
|
|
|
if(!strcmp(cmain, main) && !strcmp(csub, sub)) {
|
|
|
|
/* start of wanted part */
|
|
|
|
in_wanted_part = 1;
|
|
|
|
if(strstr(patt, "base64="))
|
|
|
|
/* bit rough test, but "mostly" functional, */
|
|
|
|
/* treat wanted part data as base64 encoded */
|
|
|
|
base64 = 1;
|
2004-11-29 07:10:09 -05:00
|
|
|
}
|
2010-02-14 08:14:17 -05:00
|
|
|
continue;
|
2004-11-29 07:10:09 -05:00
|
|
|
}
|
2002-02-07 04:39:15 -05:00
|
|
|
|
|
|
|
}
|
2010-02-14 08:14:17 -05:00
|
|
|
|
|
|
|
if(in_wanted_part) {
|
|
|
|
show(("=> %s", buffer));
|
|
|
|
error = appenddata(outbuf, outlen, &outalloc, buffer, base64);
|
|
|
|
if(error)
|
|
|
|
break;
|
2007-01-22 21:25:56 -05:00
|
|
|
}
|
2010-02-14 08:14:17 -05:00
|
|
|
|
|
|
|
} /* while */
|
|
|
|
|
2015-03-11 12:41:01 -04:00
|
|
|
free(buffer);
|
2010-02-14 08:14:17 -05:00
|
|
|
|
|
|
|
if(error != GPE_OK) {
|
|
|
|
if(error == GPE_END_OF_FILE)
|
|
|
|
error = GPE_OK;
|
2002-02-07 04:39:15 -05:00
|
|
|
else {
|
2015-03-11 12:41:01 -04:00
|
|
|
free(*outbuf);
|
2010-02-14 08:14:17 -05:00
|
|
|
*outbuf = NULL;
|
|
|
|
*outlen = 0;
|
2002-02-07 04:39:15 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-14 08:14:17 -05:00
|
|
|
return error;
|
2002-02-07 04:39:15 -05:00
|
|
|
}
|