third-party libs
This commit is contained in:
parent
f836927d3a
commit
b154ee9266
3667 changed files with 854591 additions and 0 deletions
6
third-party/curl-7.21.4/tests/server/.gitignore
vendored
Normal file
6
third-party/curl-7.21.4/tests/server/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
getpart
|
||||
resolve
|
||||
rtspd
|
||||
sockfilt
|
||||
sws
|
||||
tftpd
|
||||
71
third-party/curl-7.21.4/tests/server/CMakeLists.txt
vendored
Normal file
71
third-party/curl-7.21.4/tests/server/CMakeLists.txt
vendored
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
set(TARGET_LABEL_PREFIX "Test server ")
|
||||
|
||||
function(SETUP_EXECUTABLE TEST_NAME) # ARGN are the files in the test
|
||||
add_executable( ${TEST_NAME} ${ARGN} )
|
||||
string(TOUPPER ${TEST_NAME} UPPER_TEST_NAME)
|
||||
|
||||
include_directories(
|
||||
${CURL_SOURCE_DIR}/lib # To be able to reach "setup_once.h"
|
||||
${CURL_BINARY_DIR}/lib # To be able to reach "curl_config.h"
|
||||
${CURL_BINARY_DIR}/include # To be able to reach "curl/curlbuild.h"
|
||||
)
|
||||
if(CURL_USE_ARES)
|
||||
include_directories(${CARES_INCLUDE_DIR})
|
||||
endif()
|
||||
# resolve test needs this
|
||||
setup_curl_dependencies(${TEST_NAME})
|
||||
#TARGET_LINK_LIBRARIES( ${TEST_NAME} libcurl )
|
||||
|
||||
# Test servers simply are standalone programs that do not use libcurl
|
||||
# library. For convinience and to ease portability of these servers,
|
||||
# some source code files from the libcurl subdirectory are also used
|
||||
# to build the servers. In order to achieve proper linkage of these
|
||||
# files on Win32 targets it is necessary to build the test servers
|
||||
# with CURL_STATICLIB defined, independently of how libcurl is built.
|
||||
if(NOT CURL_STATICLIB)
|
||||
set_target_properties(${TEST_NAME} PROPERTIES
|
||||
COMPILE_DEFINITIONS CURL_STATICLIB) # ${UPPER_TEST_NAME}
|
||||
endif()
|
||||
set_target_properties(${TEST_NAME} PROPERTIES
|
||||
PROJECT_LABEL "${TARGET_LABEL_PREFIX}${TEST_NAME}")
|
||||
|
||||
# Add the postfix to the executable since it is not added
|
||||
# automatically as for modules and shared libraries
|
||||
set_target_properties(${TEST_NAME} PROPERTIES
|
||||
DEBUG_POSTFIX "${CMAKE_DEBUG_POSTFIX}")
|
||||
|
||||
if(MSVC)
|
||||
if(NOT BUILD_RELEASE_DEBUG_DIRS)
|
||||
# Ugly workaround to remove the "/debug" or "/release" in each output
|
||||
set_target_properties(${TEST_NAME} PROPERTIES PREFIX "../")
|
||||
set_target_properties(${TEST_NAME} PROPERTIES IMPORT_PREFIX "../")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
endfunction()
|
||||
|
||||
|
||||
transform_makefile_inc("Makefile.inc"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
|
||||
include(${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake)
|
||||
|
||||
foreach(EXECUTABLE_NAME ${noinst_PROGRAMS})
|
||||
setup_executable(${EXECUTABLE_NAME} ${${EXECUTABLE_NAME}_SOURCES})
|
||||
endforeach()
|
||||
|
||||
|
||||
# SET(useful
|
||||
# getpart.c getpart.h
|
||||
# ${CURL_SOURCE_DIR}/lib/strequal.c
|
||||
# ${CURL_SOURCE_DIR}/lib/base64.c
|
||||
# ${CURL_SOURCE_DIR}/lib/mprintf.c
|
||||
# ${CURL_SOURCE_DIR}/lib/memdebug.c
|
||||
# ${CURL_SOURCE_DIR}/lib/timeval.c
|
||||
# )
|
||||
|
||||
# SETUP_EXECUTABLE(sws sws.c util.c util.h ${useful})
|
||||
# SETUP_EXECUTABLE(resolve resolve.c util.c util.h ${useful})
|
||||
# SETUP_EXECUTABLE(sockfilt sockfilt.c util.c util.h ${useful} ${CURL_SOURCE_DIR}/lib/inet_pton.c)
|
||||
# SETUP_EXECUTABLE(getpart testpart.c ${useful})
|
||||
# SETUP_EXECUTABLE(tftpd tftpd.c util.c util.h ${useful} tftp.h)
|
||||
|
||||
57
third-party/curl-7.21.4/tests/server/Makefile.am
vendored
Normal file
57
third-party/curl-7.21.4/tests/server/Makefile.am
vendored
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
#***************************************************************************
|
||||
# _ _ ____ _
|
||||
# Project ___| | | | _ \| |
|
||||
# / __| | | | |_) | |
|
||||
# | (__| |_| | _ <| |___
|
||||
# \___|\___/|_| \_\_____|
|
||||
#
|
||||
# Copyright (C) 1998 - 2009, 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.
|
||||
#
|
||||
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
# KIND, either express or implied.
|
||||
#
|
||||
###########################################################################
|
||||
AUTOMAKE_OPTIONS = foreign nostdinc
|
||||
|
||||
# Specify our include paths here, and do it relative to $(top_srcdir) and
|
||||
# $(top_builddir), to ensure that these paths which belong to the library
|
||||
# being currently built and tested are searched before the library which
|
||||
# might possibly already be installed in the system.
|
||||
#
|
||||
# $(top_builddir)/include/curl for generated curlbuild.h included from curl.h
|
||||
# $(top_builddir)/include for generated curlbuild.h included from lib/setup.h
|
||||
# $(top_srcdir)/include is for libcurl's external include files
|
||||
# $(top_builddir)/lib is for libcurl's generated lib/curl_config.h file
|
||||
# $(top_srcdir)/lib is for libcurl's lib/setup.h and other "borrowed" files
|
||||
# $(top_builddir)/ares is for in-tree c-ares's generated ares_build.h file
|
||||
# $(top_srcdir)/ares is for in-tree c-ares's external include files
|
||||
|
||||
if USE_EMBEDDED_ARES
|
||||
INCLUDES = -I$(top_builddir)/include/curl \
|
||||
-I$(top_builddir)/include \
|
||||
-I$(top_srcdir)/include \
|
||||
-I$(top_builddir)/lib \
|
||||
-I$(top_srcdir)/lib \
|
||||
-I$(top_builddir)/ares \
|
||||
-I$(top_srcdir)/ares
|
||||
else
|
||||
INCLUDES = -I$(top_builddir)/include/curl \
|
||||
-I$(top_builddir)/include \
|
||||
-I$(top_srcdir)/include \
|
||||
-I$(top_builddir)/lib \
|
||||
-I$(top_srcdir)/lib
|
||||
endif
|
||||
|
||||
# Makefile.inc provides the source defines (noinst_PROGRAMS, useful, *_SOURCES, and *_LDADD)
|
||||
include Makefile.inc
|
||||
|
||||
extra_DIST = base64.pl Makefile.inc
|
||||
|
||||
65
third-party/curl-7.21.4/tests/server/Makefile.inc
vendored
Normal file
65
third-party/curl-7.21.4/tests/server/Makefile.inc
vendored
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
noinst_PROGRAMS = getpart resolve rtspd sockfilt sws tftpd
|
||||
|
||||
CURLX_SRCS = \
|
||||
$(top_srcdir)/lib/mprintf.c \
|
||||
$(top_srcdir)/lib/nonblock.c \
|
||||
$(top_srcdir)/lib/strequal.c \
|
||||
$(top_srcdir)/lib/strtoofft.c \
|
||||
$(top_srcdir)/lib/timeval.c \
|
||||
$(top_srcdir)/lib/warnless.c
|
||||
|
||||
CURLX_HDRS = \
|
||||
$(top_srcdir)/lib/curlx.h \
|
||||
$(top_srcdir)/lib/nonblock.h \
|
||||
$(top_srcdir)/lib/strequal.h \
|
||||
$(top_srcdir)/lib/strtoofft.h \
|
||||
$(top_srcdir)/lib/timeval.h \
|
||||
$(top_srcdir)/lib/warnless.h
|
||||
|
||||
USEFUL = \
|
||||
getpart.c \
|
||||
getpart.h \
|
||||
$(top_srcdir)/lib/base64.c \
|
||||
$(top_srcdir)/lib/curl_base64.h \
|
||||
$(top_srcdir)/lib/memdebug.c \
|
||||
$(top_srcdir)/lib/memdebug.h
|
||||
|
||||
UTIL = \
|
||||
util.c \
|
||||
util.h
|
||||
|
||||
getpart_SOURCES = $(CURLX_SRCS) $(CURLX_HDRS) $(USEFUL) \
|
||||
testpart.c
|
||||
getpart_LDADD = @TEST_SERVER_LIBS@
|
||||
getpart_CFLAGS = $(AM_CFLAGS)
|
||||
|
||||
resolve_SOURCES = $(CURLX_SRCS) $(CURLX_HDRS) $(USEFUL) $(UTIL) \
|
||||
resolve.c
|
||||
resolve_LDADD = @TEST_SERVER_LIBS@
|
||||
resolve_CFLAGS = $(AM_CFLAGS)
|
||||
|
||||
rtspd_SOURCES = $(CURLX_SRCS) $(CURLX_HDRS) $(USEFUL) $(UTIL) \
|
||||
server_sockaddr.h \
|
||||
rtspd.c
|
||||
rtspd_LDADD = @TEST_SERVER_LIBS@
|
||||
rtspd_CFLAGS = $(AM_CFLAGS)
|
||||
|
||||
sockfilt_SOURCES = $(CURLX_SRCS) $(CURLX_HDRS) $(USEFUL) $(UTIL) \
|
||||
server_sockaddr.h \
|
||||
sockfilt.c \
|
||||
$(top_srcdir)/lib/inet_pton.c
|
||||
sockfilt_LDADD = @TEST_SERVER_LIBS@
|
||||
sockfilt_CFLAGS = $(AM_CFLAGS)
|
||||
|
||||
sws_SOURCES = $(CURLX_SRCS) $(CURLX_HDRS) $(USEFUL) $(UTIL) \
|
||||
server_sockaddr.h \
|
||||
sws.c
|
||||
sws_LDADD = @TEST_SERVER_LIBS@
|
||||
sws_CFLAGS = $(AM_CFLAGS)
|
||||
|
||||
tftpd_SOURCES = $(CURLX_SRCS) $(CURLX_HDRS) $(USEFUL) $(UTIL) \
|
||||
server_sockaddr.h \
|
||||
tftpd.c \
|
||||
tftp.h
|
||||
tftpd_LDADD = @TEST_SERVER_LIBS@
|
||||
tftpd_CFLAGS = $(AM_CFLAGS)
|
||||
9
third-party/curl-7.21.4/tests/server/base64.pl
vendored
Normal file
9
third-party/curl-7.21.4/tests/server/base64.pl
vendored
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
use MIME::Base64 qw(encode_base64);
|
||||
|
||||
my $buf;
|
||||
while(read(STDIN, $buf, 60*57)) {
|
||||
my $enc = encode_base64($buf);
|
||||
print "$enc";
|
||||
}
|
||||
422
third-party/curl-7.21.4/tests/server/getpart.c
vendored
Normal file
422
third-party/curl-7.21.4/tests/server/getpart.c
vendored
Normal file
|
|
@ -0,0 +1,422 @@
|
|||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2010, 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.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
#define CURL_NO_OLDIES
|
||||
|
||||
#include "setup.h"
|
||||
|
||||
#include "getpart.h"
|
||||
|
||||
#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 */
|
||||
|
||||
/* just to please base64.h we create a fake struct */
|
||||
struct SessionHandle {
|
||||
int fake;
|
||||
};
|
||||
|
||||
#include "curl_base64.h"
|
||||
#include "curl_memory.h"
|
||||
|
||||
/* include memdebug.h last */
|
||||
#include "memdebug.h"
|
||||
|
||||
#define EAT_SPACE(p) while(*(p) && ISSPACE(*(p))) (p)++
|
||||
|
||||
#define EAT_WORD(p) while(*(p) && !ISSPACE(*(p)) && ('>' != *(p))) (p)++
|
||||
|
||||
#ifdef DEBUG_GETPART
|
||||
#define show(x) printf x
|
||||
#else
|
||||
#define show(x)
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER) && defined(_DLL)
|
||||
# pragma warning(disable:4232) /* MSVC extension, dllimport identity */
|
||||
#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;
|
||||
|
||||
#if defined(_MSC_VER) && defined(_DLL)
|
||||
# pragma warning(default:4232) /* MSVC extension, dllimport identity */
|
||||
#endif
|
||||
|
||||
/*
|
||||
* 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(;;) {
|
||||
int bytestoread = curlx_uztosi(*bufsize - offset);
|
||||
|
||||
if(!fgets(*buffer + offset, bytestoread, stream))
|
||||
return (offset != 0) ? GPE_OK : GPE_END_OF_FILE ;
|
||||
|
||||
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 */
|
||||
{
|
||||
size_t need_alloc, src_len;
|
||||
union {
|
||||
unsigned char *as_uchar;
|
||||
char *as_char;
|
||||
} buf64;
|
||||
|
||||
src_len = strlen(src_buf);
|
||||
if(!src_len)
|
||||
return GPE_OK;
|
||||
|
||||
buf64.as_char = NULL;
|
||||
|
||||
if(src_b64) {
|
||||
/* base64 decode the given buffer */
|
||||
src_len = Curl_base64_decode(src_buf, &buf64.as_uchar);
|
||||
src_buf = buf64.as_char;
|
||||
if(!src_len || !src_buf) {
|
||||
/*
|
||||
** 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.
|
||||
*/
|
||||
if(buf64.as_char)
|
||||
free(buf64.as_char);
|
||||
return GPE_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
need_alloc = src_len + *dst_len + 1;
|
||||
|
||||
/* enlarge destination buffer if required */
|
||||
if(need_alloc > *dst_alloc) {
|
||||
size_t newsize = need_alloc * 2;
|
||||
char *newptr = realloc(*dst_buf, newsize);
|
||||
if(!newptr) {
|
||||
if(buf64.as_char)
|
||||
free(buf64.as_char);
|
||||
return GPE_OUT_OF_MEMORY;
|
||||
}
|
||||
*dst_alloc = newsize;
|
||||
*dst_buf = newptr;
|
||||
}
|
||||
|
||||
/* memcpy to support binary blobs */
|
||||
memcpy(*dst_buf + *dst_len, src_buf, src_len);
|
||||
*dst_len += src_len;
|
||||
*(*dst_buf + *dst_len) = '\0';
|
||||
|
||||
if(buf64.as_char)
|
||||
free(buf64.as_char);
|
||||
|
||||
return GPE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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)
|
||||
{
|
||||
# define MAX_TAG_LEN 79
|
||||
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 */
|
||||
char *buffer = NULL;
|
||||
char *ptr;
|
||||
char *end;
|
||||
union {
|
||||
ssize_t sig;
|
||||
size_t uns;
|
||||
} len;
|
||||
size_t bufsize = 0;
|
||||
size_t outalloc = 256;
|
||||
int in_wanted_part = 0;
|
||||
int base64 = 0;
|
||||
int error;
|
||||
|
||||
enum {
|
||||
STATE_OUTSIDE = 0,
|
||||
STATE_OUTER = 1,
|
||||
STATE_INMAIN = 2,
|
||||
STATE_INSUB = 3,
|
||||
STATE_ILLEGAL = 4
|
||||
} state = STATE_OUTSIDE;
|
||||
|
||||
*outlen = 0;
|
||||
*outbuf = malloc(outalloc);
|
||||
if(!*outbuf)
|
||||
return GPE_OUT_OF_MEMORY;
|
||||
*(*outbuf) = '\0';
|
||||
|
||||
couter[0] = cmain[0] = csub[0] = ptag[0] = patt[0] = '\0';
|
||||
|
||||
while((error = readline(&buffer, &bufsize, stream)) == GPE_OK) {
|
||||
|
||||
ptr = buffer;
|
||||
EAT_SPACE(ptr);
|
||||
|
||||
if('<' != *ptr) {
|
||||
if(in_wanted_part) {
|
||||
show(("=> %s", buffer));
|
||||
error = appenddata(outbuf, outlen, &outalloc, buffer, base64);
|
||||
if(error)
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
ptr++;
|
||||
|
||||
if('/' == *ptr) {
|
||||
/*
|
||||
** closing section tag
|
||||
*/
|
||||
|
||||
ptr++;
|
||||
end = ptr;
|
||||
EAT_WORD(end);
|
||||
if((len.sig = end - ptr) > MAX_TAG_LEN) {
|
||||
error = GPE_NO_BUFFER_SPACE;
|
||||
break;
|
||||
}
|
||||
memcpy(ptag, ptr, len.uns);
|
||||
ptag[len.uns] = '\0';
|
||||
|
||||
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;
|
||||
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;
|
||||
break;
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else if(!in_wanted_part) {
|
||||
/*
|
||||
** opening section tag
|
||||
*/
|
||||
|
||||
/* get potential tag */
|
||||
end = ptr;
|
||||
EAT_WORD(end);
|
||||
if((len.sig = end - ptr) > MAX_TAG_LEN) {
|
||||
error = GPE_NO_BUFFER_SPACE;
|
||||
break;
|
||||
}
|
||||
memcpy(ptag, ptr, len.uns);
|
||||
ptag[len.uns] = '\0';
|
||||
|
||||
/* 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++;
|
||||
if((len.sig = end - ptr) > MAX_TAG_LEN) {
|
||||
error = GPE_NO_BUFFER_SPACE;
|
||||
break;
|
||||
}
|
||||
memcpy(patt, ptr, len.uns);
|
||||
patt[len.uns] = '\0';
|
||||
|
||||
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;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(in_wanted_part) {
|
||||
show(("=> %s", buffer));
|
||||
error = appenddata(outbuf, outlen, &outalloc, buffer, base64);
|
||||
if(error)
|
||||
break;
|
||||
}
|
||||
|
||||
} /* while */
|
||||
|
||||
if(buffer)
|
||||
free(buffer);
|
||||
|
||||
if(error != GPE_OK) {
|
||||
if(error == GPE_END_OF_FILE)
|
||||
error = GPE_OK;
|
||||
else {
|
||||
if(*outbuf)
|
||||
free(*outbuf);
|
||||
*outbuf = NULL;
|
||||
*outlen = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
33
third-party/curl-7.21.4/tests/server/getpart.h
vendored
Normal file
33
third-party/curl-7.21.4/tests/server/getpart.h
vendored
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
#ifndef HEADER_SERVER_GETPART_H
|
||||
#define HEADER_SERVER_GETPART_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2010, 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.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
#define GPE_NO_BUFFER_SPACE -2
|
||||
#define GPE_OUT_OF_MEMORY -1
|
||||
#define GPE_OK 0
|
||||
#define GPE_END_OF_FILE 1
|
||||
|
||||
int getpart(char **outbuf, size_t *outlen,
|
||||
const char *main, const char *sub, FILE *stream);
|
||||
|
||||
#endif /* HEADER_SERVER_GETPART_H */
|
||||
164
third-party/curl-7.21.4/tests/server/resolve.c
vendored
Normal file
164
third-party/curl-7.21.4/tests/server/resolve.c
vendored
Normal file
|
|
@ -0,0 +1,164 @@
|
|||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2010, 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.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/* Purpose
|
||||
*
|
||||
* Resolve the given name, using system name resolve functions (NOT any
|
||||
* function provided by libcurl). Used to see if the name exists and thus if
|
||||
* we can allow a test case to use it for testing.
|
||||
*
|
||||
* Like if 'localhost' actual exists etc.
|
||||
*
|
||||
*/
|
||||
|
||||
#define CURL_NO_OLDIES
|
||||
|
||||
#include "setup.h" /* portability help from the lib directory */
|
||||
|
||||
#ifdef HAVE_SIGNAL_H
|
||||
#include <signal.h>
|
||||
#endif
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_SOCKET_H
|
||||
#include <sys/socket.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETINET_IN_H
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
#ifdef _XOPEN_SOURCE_EXTENDED
|
||||
/* This define is "almost" required to build on HPUX 11 */
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETDB_H
|
||||
#include <netdb.h>
|
||||
#endif
|
||||
|
||||
#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 */
|
||||
#include "util.h"
|
||||
|
||||
/* include memdebug.h last */
|
||||
#include "memdebug.h"
|
||||
|
||||
static bool use_ipv6 = FALSE;
|
||||
static const char *ipv_inuse = "IPv4";
|
||||
|
||||
const char *serverlogfile=""; /* for a util.c function we don't use */
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int arg=1;
|
||||
const char *host = NULL;
|
||||
int rc = 0;
|
||||
|
||||
while(argc>arg) {
|
||||
if(!strcmp("--version", argv[arg])) {
|
||||
printf("resolve IPv4%s\n",
|
||||
#ifdef ENABLE_IPV6
|
||||
"/IPv6"
|
||||
#else
|
||||
""
|
||||
#endif
|
||||
);
|
||||
return 0;
|
||||
}
|
||||
else if(!strcmp("--ipv6", argv[arg])) {
|
||||
ipv_inuse = "IPv6";
|
||||
use_ipv6 = TRUE;
|
||||
arg++;
|
||||
}
|
||||
else if(!strcmp("--ipv4", argv[arg])) {
|
||||
/* for completeness, we support this option as well */
|
||||
ipv_inuse = "IPv4";
|
||||
use_ipv6 = FALSE;
|
||||
arg++;
|
||||
}
|
||||
else {
|
||||
host = argv[arg++];
|
||||
}
|
||||
}
|
||||
if(!host) {
|
||||
puts("Usage: resolve [option] <host>\n"
|
||||
" --version\n"
|
||||
" --ipv4"
|
||||
#ifdef ENABLE_IPV6
|
||||
"\n --ipv6"
|
||||
#endif
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
win32_init();
|
||||
atexit(win32_cleanup);
|
||||
#endif
|
||||
|
||||
if(!use_ipv6) {
|
||||
/* gethostbyname() resolve */
|
||||
struct hostent *he;
|
||||
|
||||
he = gethostbyname(host);
|
||||
|
||||
rc = !he;
|
||||
}
|
||||
else {
|
||||
#ifdef ENABLE_IPV6
|
||||
/* Check that the system has IPv6 enabled before checking the resolver */
|
||||
curl_socket_t s = socket(PF_INET6, SOCK_DGRAM, 0);
|
||||
if(s == CURL_SOCKET_BAD)
|
||||
/* an ipv6 address was requested and we can't get/use one */
|
||||
rc = -1;
|
||||
else {
|
||||
sclose(s);
|
||||
}
|
||||
|
||||
if (rc == 0) {
|
||||
/* getaddrinfo() resolve */
|
||||
struct addrinfo *ai;
|
||||
struct addrinfo hints;
|
||||
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
hints.ai_family = PF_INET6;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
hints.ai_flags = AI_CANONNAME;
|
||||
/* Use parenthesis around function to stop it from being replaced by
|
||||
the macro in memdebug.h */
|
||||
rc = (getaddrinfo)(host, "80", &hints, &ai);
|
||||
}
|
||||
|
||||
#else
|
||||
puts("IPv6 support has been disabled in this program");
|
||||
return 1;
|
||||
#endif
|
||||
}
|
||||
if(rc)
|
||||
printf("Resolving %s '%s' didn't work\n", ipv_inuse, host);
|
||||
|
||||
return !!rc;
|
||||
}
|
||||
1469
third-party/curl-7.21.4/tests/server/rtspd.c
vendored
Normal file
1469
third-party/curl-7.21.4/tests/server/rtspd.c
vendored
Normal file
File diff suppressed because it is too large
Load diff
33
third-party/curl-7.21.4/tests/server/server_sockaddr.h
vendored
Normal file
33
third-party/curl-7.21.4/tests/server/server_sockaddr.h
vendored
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
#ifndef HEADER_SERVER_SOCKADDR_H
|
||||
#define HEADER_SERVER_SOCKADDR_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2010, 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.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
typedef union {
|
||||
struct sockaddr sa;
|
||||
struct sockaddr_in sa4;
|
||||
#ifdef ENABLE_IPV6
|
||||
struct sockaddr_in6 sa6;
|
||||
#endif
|
||||
} srvr_sockaddr_union_t;
|
||||
|
||||
#endif /* HEADER_SERVER_SOCKADDR_H */
|
||||
1042
third-party/curl-7.21.4/tests/server/sockfilt.c
vendored
Normal file
1042
third-party/curl-7.21.4/tests/server/sockfilt.c
vendored
Normal file
File diff suppressed because it is too large
Load diff
1456
third-party/curl-7.21.4/tests/server/sws.c
vendored
Normal file
1456
third-party/curl-7.21.4/tests/server/sws.c
vendored
Normal file
File diff suppressed because it is too large
Load diff
54
third-party/curl-7.21.4/tests/server/testpart.c
vendored
Normal file
54
third-party/curl-7.21.4/tests/server/testpart.c
vendored
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2010, 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.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
#define CURL_NO_OLDIES
|
||||
|
||||
#include "setup.h"
|
||||
|
||||
#include "getpart.h"
|
||||
|
||||
#define _MPRINTF_REPLACE /* use our functions only */
|
||||
#include <curl/mprintf.h>
|
||||
|
||||
/* include memdebug.h last */
|
||||
#include "memdebug.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int rc;
|
||||
char *part;
|
||||
size_t partlen, i;
|
||||
|
||||
if(argc< 3) {
|
||||
printf("./testpart main sub\n");
|
||||
}
|
||||
else {
|
||||
rc = getpart(&part, &partlen, argv[1], argv[2], stdin);
|
||||
if(rc)
|
||||
return(rc);
|
||||
for(i = 0; i < partlen; i++)
|
||||
printf("%c", part[i]);
|
||||
free(part);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
57
third-party/curl-7.21.4/tests/server/tftp.h
vendored
Normal file
57
third-party/curl-7.21.4/tests/server/tftp.h
vendored
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
#ifndef __SERVER_TFTP_H
|
||||
#define __SERVER_TFTP_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2008, 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.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
/* This file is a rewrite/clone of the arpa/tftp.h file for systems without
|
||||
it. */
|
||||
|
||||
#define SEGSIZE 512 /* data segment size */
|
||||
|
||||
#ifndef __GNUC__
|
||||
#define __attribute__(x)
|
||||
#endif
|
||||
|
||||
/* Using a packed struct as binary in a program is begging for problems, but
|
||||
the tftpd server was written like this so we have this struct here to make
|
||||
things build. */
|
||||
|
||||
struct tftphdr {
|
||||
short th_opcode; /* packet type */
|
||||
unsigned short th_block; /* all sorts of things */
|
||||
char th_data[1]; /* data or error string */
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
#define th_stuff th_block
|
||||
#define th_code th_block
|
||||
#define th_msg th_data
|
||||
|
||||
#define EUNDEF 0
|
||||
#define ENOTFOUND 1
|
||||
#define EACCESS 2
|
||||
#define ENOSPACE 3
|
||||
#define EBADOP 4
|
||||
#define EBADID 5
|
||||
#define EEXISTS 6
|
||||
#define ENOUSER 7
|
||||
|
||||
#endif /* __SERVER_TFTP_H */
|
||||
1302
third-party/curl-7.21.4/tests/server/tftpd.c
vendored
Normal file
1302
third-party/curl-7.21.4/tests/server/tftpd.c
vendored
Normal file
File diff suppressed because it is too large
Load diff
283
third-party/curl-7.21.4/tests/server/util.c
vendored
Normal file
283
third-party/curl-7.21.4/tests/server/util.c
vendored
Normal file
|
|
@ -0,0 +1,283 @@
|
|||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2010, 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.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
#define CURL_NO_OLDIES
|
||||
|
||||
#include "setup.h" /* portability help from the lib directory */
|
||||
|
||||
#ifdef HAVE_SIGNAL_H
|
||||
#include <signal.h>
|
||||
#endif
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_SOCKET_H
|
||||
#include <sys/socket.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETINET_IN_H
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
#ifdef _XOPEN_SOURCE_EXTENDED
|
||||
/* This define is "almost" required to build on HPUX 11 */
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETDB_H
|
||||
#include <netdb.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_POLL_H
|
||||
#include <sys/poll.h>
|
||||
#elif defined(HAVE_POLL_H)
|
||||
#include <poll.h>
|
||||
#endif
|
||||
|
||||
#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 */
|
||||
#include "getpart.h"
|
||||
#include "util.h"
|
||||
#include "timeval.h"
|
||||
|
||||
#if defined(ENABLE_IPV6) && defined(__MINGW32__)
|
||||
const struct in6_addr in6addr_any = {{ IN6ADDR_ANY_INIT }};
|
||||
#endif
|
||||
|
||||
void logmsg(const char *msg, ...)
|
||||
{
|
||||
va_list ap;
|
||||
char buffer[2048 + 1];
|
||||
FILE *logfp;
|
||||
int error;
|
||||
struct timeval tv;
|
||||
time_t sec;
|
||||
struct tm *now;
|
||||
char timebuf[20];
|
||||
static time_t epoch_offset;
|
||||
static int known_offset;
|
||||
|
||||
if (!serverlogfile) {
|
||||
fprintf(stderr, "Error: serverlogfile not set\n");
|
||||
return;
|
||||
}
|
||||
|
||||
tv = curlx_tvnow();
|
||||
if(!known_offset) {
|
||||
epoch_offset = time(NULL) - tv.tv_sec;
|
||||
known_offset = 1;
|
||||
}
|
||||
sec = epoch_offset + tv.tv_sec;
|
||||
now = localtime(&sec); /* not thread safe but we don't care */
|
||||
|
||||
snprintf(timebuf, sizeof(timebuf), "%02d:%02d:%02d.%06ld",
|
||||
(int)now->tm_hour, (int)now->tm_min, (int)now->tm_sec, (long)tv.tv_usec);
|
||||
|
||||
va_start(ap, msg);
|
||||
vsnprintf(buffer, sizeof(buffer), msg, ap);
|
||||
va_end(ap);
|
||||
|
||||
logfp = fopen(serverlogfile, "ab");
|
||||
if(logfp) {
|
||||
fprintf(logfp, "%s %s\n", timebuf, buffer);
|
||||
fclose(logfp);
|
||||
}
|
||||
else {
|
||||
error = ERRNO;
|
||||
fprintf(stderr, "fopen() failed with error: %d %s\n",
|
||||
error, strerror(error));
|
||||
fprintf(stderr, "Error opening file: %s\n", serverlogfile);
|
||||
fprintf(stderr, "Msg not logged: %s %s\n", timebuf, buffer);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
/* use instead of perror() on generic windows */
|
||||
void win32_perror (const char *msg)
|
||||
{
|
||||
char buf[512];
|
||||
DWORD err = SOCKERRNO;
|
||||
|
||||
if (!FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err,
|
||||
LANG_NEUTRAL, buf, sizeof(buf), NULL))
|
||||
snprintf(buf, sizeof(buf), "Unknown error %lu (%#lx)", err, err);
|
||||
if (msg)
|
||||
fprintf(stderr, "%s: ", msg);
|
||||
fprintf(stderr, "%s\n", buf);
|
||||
}
|
||||
#endif /* WIN32 */
|
||||
|
||||
#ifdef USE_WINSOCK
|
||||
void win32_init(void)
|
||||
{
|
||||
WORD wVersionRequested;
|
||||
WSADATA wsaData;
|
||||
int err;
|
||||
wVersionRequested = MAKEWORD(USE_WINSOCK, USE_WINSOCK);
|
||||
|
||||
err = WSAStartup(wVersionRequested, &wsaData);
|
||||
|
||||
if (err != 0) {
|
||||
perror("Winsock init failed");
|
||||
logmsg("Error initialising winsock -- aborting");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if ( LOBYTE( wsaData.wVersion ) != USE_WINSOCK ||
|
||||
HIBYTE( wsaData.wVersion ) != USE_WINSOCK ) {
|
||||
|
||||
WSACleanup();
|
||||
perror("Winsock init failed");
|
||||
logmsg("No suitable winsock.dll found -- aborting");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
void win32_cleanup(void)
|
||||
{
|
||||
WSACleanup();
|
||||
}
|
||||
#endif /* USE_WINSOCK */
|
||||
|
||||
/* set by the main code to point to where the test dir is */
|
||||
const char *path=".";
|
||||
|
||||
char *test2file(long testno)
|
||||
{
|
||||
static char filename[256];
|
||||
snprintf(filename, sizeof(filename), TEST_DATA_PATH, path, testno);
|
||||
return filename;
|
||||
}
|
||||
|
||||
/*
|
||||
* Portable function used for waiting a specific amount of ms.
|
||||
* Waiting indefinitely with this function is not allowed, a
|
||||
* zero or negative timeout value will return immediately.
|
||||
*
|
||||
* Return values:
|
||||
* -1 = system call error, or invalid timeout value
|
||||
* 0 = specified timeout has elapsed
|
||||
*/
|
||||
int wait_ms(int timeout_ms)
|
||||
{
|
||||
#if !defined(MSDOS) && !defined(USE_WINSOCK)
|
||||
#ifndef HAVE_POLL_FINE
|
||||
struct timeval pending_tv;
|
||||
#endif
|
||||
struct timeval initial_tv;
|
||||
int pending_ms;
|
||||
int error;
|
||||
#endif
|
||||
int r = 0;
|
||||
|
||||
if(!timeout_ms)
|
||||
return 0;
|
||||
if(timeout_ms < 0) {
|
||||
SET_SOCKERRNO(EINVAL);
|
||||
return -1;
|
||||
}
|
||||
#if defined(MSDOS)
|
||||
delay(timeout_ms);
|
||||
#elif defined(USE_WINSOCK)
|
||||
Sleep(timeout_ms);
|
||||
#else
|
||||
pending_ms = timeout_ms;
|
||||
initial_tv = curlx_tvnow();
|
||||
do {
|
||||
#if defined(HAVE_POLL_FINE)
|
||||
r = poll(NULL, 0, pending_ms);
|
||||
#else
|
||||
pending_tv.tv_sec = pending_ms / 1000;
|
||||
pending_tv.tv_usec = (pending_ms % 1000) * 1000;
|
||||
r = select(0, NULL, NULL, NULL, &pending_tv);
|
||||
#endif /* HAVE_POLL_FINE */
|
||||
if(r != -1)
|
||||
break;
|
||||
error = SOCKERRNO;
|
||||
if(error && (error != EINTR))
|
||||
break;
|
||||
pending_ms = timeout_ms - (int)curlx_tvdiff(curlx_tvnow(), initial_tv);
|
||||
if(pending_ms <= 0)
|
||||
break;
|
||||
} while(r == -1);
|
||||
#endif /* USE_WINSOCK */
|
||||
if(r)
|
||||
r = -1;
|
||||
return r;
|
||||
}
|
||||
|
||||
int write_pidfile(const char *filename)
|
||||
{
|
||||
FILE *pidfile;
|
||||
long pid;
|
||||
|
||||
pid = (long)getpid();
|
||||
pidfile = fopen(filename, "wb");
|
||||
if(!pidfile) {
|
||||
logmsg("Couldn't write pid file: %s %s", filename, strerror(ERRNO));
|
||||
return 0; /* fail */
|
||||
}
|
||||
fprintf(pidfile, "%ld\n", pid);
|
||||
fclose(pidfile);
|
||||
logmsg("Wrote pid %ld to %s", pid, filename);
|
||||
return 1; /* success */
|
||||
}
|
||||
|
||||
void set_advisor_read_lock(const char *filename)
|
||||
{
|
||||
FILE *lockfile;
|
||||
int error = 0;
|
||||
int res;
|
||||
|
||||
do {
|
||||
lockfile = fopen(filename, "wb");
|
||||
} while((lockfile == NULL) && ((error = ERRNO) == EINTR));
|
||||
if(lockfile == NULL) {
|
||||
logmsg("Error creating lock file %s error: %d %s",
|
||||
filename, error, strerror(error));
|
||||
return;
|
||||
}
|
||||
|
||||
do {
|
||||
res = fclose(lockfile);
|
||||
} while(res && ((error = ERRNO) == EINTR));
|
||||
if(res)
|
||||
logmsg("Error closing lock file %s error: %d %s",
|
||||
filename, error, strerror(error));
|
||||
}
|
||||
|
||||
void clear_advisor_read_lock(const char *filename)
|
||||
{
|
||||
int error = 0;
|
||||
int res;
|
||||
|
||||
/*
|
||||
** Log all removal failures. Even those due to file not existing.
|
||||
** This allows to detect if unexpectedly the file has already been
|
||||
** removed by a process different than the one that should do this.
|
||||
*/
|
||||
|
||||
do {
|
||||
res = unlink(filename);
|
||||
} while(res && ((error = ERRNO) == EINTR));
|
||||
if(res)
|
||||
logmsg("Error removing lock file %s error: %d %s",
|
||||
filename, error, strerror(error));
|
||||
}
|
||||
64
third-party/curl-7.21.4/tests/server/util.h
vendored
Normal file
64
third-party/curl-7.21.4/tests/server/util.h
vendored
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
#ifndef __SERVER_UTIL_H
|
||||
#define __SERVER_UTIL_H
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 1998 - 2008, 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.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
void logmsg(const char *msg, ...);
|
||||
|
||||
#define TEST_DATA_PATH "%s/data/test%ld"
|
||||
|
||||
#define SERVERLOGS_LOCK "log/serverlogs.lock"
|
||||
|
||||
/* global variable, where to find the 'data' dir */
|
||||
extern const char *path;
|
||||
|
||||
/* global variable, log file name */
|
||||
extern const char *serverlogfile;
|
||||
|
||||
#ifdef WIN32
|
||||
#include <process.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#define sleep(sec) Sleep ((sec)*1000)
|
||||
|
||||
#undef perror
|
||||
#define perror(m) win32_perror(m)
|
||||
void win32_perror (const char *msg);
|
||||
#endif /* WIN32 */
|
||||
|
||||
#ifdef USE_WINSOCK
|
||||
void win32_init(void);
|
||||
void win32_cleanup(void);
|
||||
#endif /* USE_WINSOCK */
|
||||
|
||||
/* returns the path name to the test case file */
|
||||
char *test2file(long testno);
|
||||
|
||||
int wait_ms(int timeout_ms);
|
||||
|
||||
int write_pidfile(const char *filename);
|
||||
|
||||
void set_advisor_read_lock(const char *filename);
|
||||
|
||||
void clear_advisor_read_lock(const char *filename);
|
||||
|
||||
#endif /* __SERVER_UTIL_H */
|
||||
Loading…
Add table
Add a link
Reference in a new issue