|
Packit |
875988 |
/*
|
|
Packit |
875988 |
This file is part of libmicrohttpd
|
|
Packit |
875988 |
Copyright (C) 2007 Christian Grothoff
|
|
Packit |
875988 |
|
|
Packit |
875988 |
libmicrohttpd is free software; you can redistribute it and/or modify
|
|
Packit |
875988 |
it under the terms of the GNU General Public License as published
|
|
Packit |
875988 |
by the Free Software Foundation; either version 2, or (at your
|
|
Packit |
875988 |
option) any later version.
|
|
Packit |
875988 |
|
|
Packit |
875988 |
libmicrohttpd is distributed in the hope that it will be useful, but
|
|
Packit |
875988 |
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
875988 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
875988 |
General Public License for more details.
|
|
Packit |
875988 |
|
|
Packit |
875988 |
You should have received a copy of the GNU General Public License
|
|
Packit |
875988 |
along with libmicrohttpd; see the file COPYING. If not, write to the
|
|
Packit |
875988 |
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
Packit |
875988 |
Boston, MA 02110-1301, USA.
|
|
Packit |
875988 |
*/
|
|
Packit |
875988 |
|
|
Packit |
875988 |
/**
|
|
Packit |
875988 |
* @file mhds_get_test.c
|
|
Packit |
875988 |
* @brief Testcase for libmicrohttpd HTTPS GET operations
|
|
Packit |
875988 |
* @author Sagie Amir
|
|
Packit |
875988 |
*/
|
|
Packit |
875988 |
|
|
Packit |
875988 |
#include "platform.h"
|
|
Packit |
875988 |
#include "microhttpd.h"
|
|
Packit |
875988 |
#include "mhd_sockets.h"
|
|
Packit |
875988 |
|
|
Packit |
875988 |
#define MHD_E_MEM "Error: memory error\n"
|
|
Packit |
875988 |
#define MHD_E_SERVER_INIT "Error: failed to start server\n"
|
|
Packit |
875988 |
|
|
Packit |
875988 |
const int DEBUG_GNUTLS_LOG_LEVEL = 0;
|
|
Packit |
875988 |
const char *test_file_name = "https_test_file";
|
|
Packit |
875988 |
const char test_file_data[] = "Hello World\n";
|
|
Packit |
875988 |
|
|
Packit |
875988 |
static int
|
|
Packit |
875988 |
ahc_echo (void *cls,
|
|
Packit |
875988 |
struct MHD_Connection *connection,
|
|
Packit |
875988 |
const char *url,
|
|
Packit |
875988 |
const char *method,
|
|
Packit |
875988 |
const char *version,
|
|
Packit |
875988 |
const char *upload_data, size_t *upload_data_size,
|
|
Packit |
875988 |
void **unused)
|
|
Packit |
875988 |
{
|
|
Packit |
875988 |
(void)cls;
|
|
Packit |
875988 |
(void)connection;
|
|
Packit |
875988 |
(void)url;
|
|
Packit |
875988 |
(void)method;
|
|
Packit |
875988 |
(void)version;
|
|
Packit |
875988 |
(void)upload_data;
|
|
Packit |
875988 |
(void)upload_data_size;
|
|
Packit |
875988 |
(void)unused;
|
|
Packit |
875988 |
|
|
Packit |
875988 |
return 0;
|
|
Packit |
875988 |
}
|
|
Packit |
875988 |
|
|
Packit |
875988 |
static int
|
|
Packit |
875988 |
test_wrap_loc (char *test_name, int (*test) (void))
|
|
Packit |
875988 |
{
|
|
Packit |
875988 |
int ret;
|
|
Packit |
875988 |
|
|
Packit |
875988 |
fprintf (stdout, "running test: %s ", test_name);
|
|
Packit |
875988 |
ret = test ();
|
|
Packit |
875988 |
if (ret == 0)
|
|
Packit |
875988 |
{
|
|
Packit |
875988 |
fprintf (stdout, "[pass]\n");
|
|
Packit |
875988 |
}
|
|
Packit |
875988 |
else
|
|
Packit |
875988 |
{
|
|
Packit |
875988 |
fprintf (stdout, "[fail]\n");
|
|
Packit |
875988 |
}
|
|
Packit |
875988 |
return ret;
|
|
Packit |
875988 |
}
|
|
Packit |
875988 |
|
|
Packit |
875988 |
|
|
Packit |
875988 |
/**
|
|
Packit |
875988 |
* Test daemon initialization with the MHD_OPTION_SOCK_ADDR option
|
|
Packit |
875988 |
*/
|
|
Packit |
875988 |
static int
|
|
Packit |
875988 |
test_ip_addr_option ()
|
|
Packit |
875988 |
{
|
|
Packit |
875988 |
struct MHD_Daemon *d;
|
|
Packit |
875988 |
struct sockaddr_in daemon_ip_addr;
|
|
Packit |
875988 |
#if HAVE_INET6
|
|
Packit |
875988 |
struct sockaddr_in6 daemon_ip_addr6;
|
|
Packit |
875988 |
#endif
|
|
Packit |
875988 |
|
|
Packit |
875988 |
memset (&daemon_ip_addr, 0, sizeof (struct sockaddr_in));
|
|
Packit |
875988 |
daemon_ip_addr.sin_family = AF_INET;
|
|
Packit |
875988 |
daemon_ip_addr.sin_port = 0;
|
|
Packit |
875988 |
daemon_ip_addr.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
|
|
Packit |
875988 |
|
|
Packit |
875988 |
#if HAVE_INET6
|
|
Packit |
875988 |
memset (&daemon_ip_addr6, 0, sizeof (struct sockaddr_in6));
|
|
Packit |
875988 |
daemon_ip_addr6.sin6_family = AF_INET6;
|
|
Packit |
875988 |
daemon_ip_addr6.sin6_port = 0;
|
|
Packit |
875988 |
daemon_ip_addr6.sin6_addr = in6addr_loopback;
|
|
Packit |
875988 |
#endif
|
|
Packit |
875988 |
|
|
Packit |
875988 |
d = MHD_start_daemon (MHD_USE_ERROR_LOG, 0,
|
|
Packit |
875988 |
NULL, NULL, &ahc_echo, NULL, MHD_OPTION_SOCK_ADDR,
|
|
Packit |
875988 |
&daemon_ip_addr, MHD_OPTION_END);
|
|
Packit |
875988 |
|
|
Packit |
875988 |
if (d == 0)
|
|
Packit |
875988 |
return -1;
|
|
Packit |
875988 |
|
|
Packit |
875988 |
MHD_stop_daemon (d);
|
|
Packit |
875988 |
|
|
Packit |
875988 |
#if HAVE_INET6
|
|
Packit |
875988 |
d = MHD_start_daemon (MHD_USE_ERROR_LOG | MHD_USE_IPv6, 0,
|
|
Packit |
875988 |
NULL, NULL, &ahc_echo, NULL, MHD_OPTION_SOCK_ADDR,
|
|
Packit |
875988 |
&daemon_ip_addr6, MHD_OPTION_END);
|
|
Packit |
875988 |
|
|
Packit |
875988 |
if (d == 0)
|
|
Packit |
875988 |
return -1;
|
|
Packit |
875988 |
|
|
Packit |
875988 |
MHD_stop_daemon (d);
|
|
Packit |
875988 |
#endif
|
|
Packit |
875988 |
|
|
Packit |
875988 |
return 0;
|
|
Packit |
875988 |
}
|
|
Packit |
875988 |
|
|
Packit |
875988 |
/* setup a temporary transfer test file */
|
|
Packit |
875988 |
int
|
|
Packit |
875988 |
main (int argc, char *const *argv)
|
|
Packit |
875988 |
{
|
|
Packit |
875988 |
unsigned int errorCount = 0;
|
|
Packit |
875988 |
(void)argc; (void)argv; /* Unused. Silent compiler warning. */
|
|
Packit |
875988 |
|
|
Packit |
875988 |
errorCount += test_wrap_loc ("ip addr option", &test_ip_addr_option);
|
|
Packit |
875988 |
|
|
Packit |
875988 |
return errorCount != 0;
|
|
Packit |
875988 |
}
|