static int test_cipher_option (FILE * test_fd, const char *cipher_suite, int proto_version) { int ret; struct MHD_Daemon *d; d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_TLS | MHD_USE_DEBUG, 4233, NULL, NULL, &http_ahc, NULL, MHD_OPTION_HTTPS_MEM_KEY, srv_key_pem, MHD_OPTION_HTTPS_MEM_CERT, srv_self_signed_cert_pem, MHD_OPTION_END); if (d == NULL) { fprintf (stderr, MHD_E_SERVER_INIT); return -1; } ret = test_https_transfer (test_fd, cipher_suite, proto_version); MHD_stop_daemon (d); return ret; }
void ApiServerMHD::stop() { if(mDaemon == 0) return; MHD_stop_daemon(mDaemon); mDaemon = 0; }
static int testLongUrlGet () { struct MHD_Daemon *d; CURL *c; char buf[2048]; struct CBC cbc; char *url; int i; cbc.buf = buf; cbc.size = 2048; cbc.pos = 0; d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */ , 11080, &apc_all, NULL, &ahc_echo, "GET", MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t) (VERY_LONG / 2), MHD_OPTION_END); if (d == NULL) return 1; zzuf_socat_start (); for (i = 0; i < LOOP_COUNT; i++) { fprintf (stderr, "."); c = curl_easy_init (); url = malloc (VERY_LONG); memset (url, 'a', VERY_LONG); url[VERY_LONG - 1] = '\0'; memcpy (url, "http://localhost:11081/", strlen ("http://localhost:11081/")); curl_easy_setopt (c, CURLOPT_URL, url); curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); if (oneone) curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); else curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); // NOTE: use of CONNECTTIMEOUT without also // setting NOSIGNAL results in really weird // crashes on my system! curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1); curl_easy_perform (c); curl_easy_cleanup (c); } fprintf (stderr, "\n"); zzuf_socat_stop (); MHD_stop_daemon (d); free (url); return 0; }
/** * Entry point to demo. Note: this HTTP server will make all * files in the current directory and its subdirectories available * to anyone. Press ENTER to stop the server once it has started. * * @param argc number of arguments in argv * @param argv first and only argument should be the port number * @return 0 on success */ int main (int argc, char *const *argv) { struct MHD_Daemon *d; unsigned int port; if ( (argc != 2) || (1 != sscanf (argv[1], "%u", &port)) || (UINT16_MAX < port) ) { fprintf (stderr, "%s PORT\n", argv[0]); return 1; } #ifndef MINGW ignore_sigpipe (); #endif magic = magic_open (MAGIC_MIME_TYPE); (void) magic_load (magic, NULL); (void) pthread_mutex_init (&mutex, NULL); file_not_found_response = MHD_create_response_from_buffer (strlen (FILE_NOT_FOUND_PAGE), (void *) FILE_NOT_FOUND_PAGE, MHD_RESPMEM_PERSISTENT); mark_as_html (file_not_found_response); request_refused_response = MHD_create_response_from_buffer (strlen (REQUEST_REFUSED_PAGE), (void *) REQUEST_REFUSED_PAGE, MHD_RESPMEM_PERSISTENT); mark_as_html (request_refused_response); internal_error_response = MHD_create_response_from_buffer (strlen (INTERNAL_ERROR_PAGE), (void *) INTERNAL_ERROR_PAGE, MHD_RESPMEM_PERSISTENT); mark_as_html (internal_error_response); update_directory (); d = MHD_start_daemon (MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, port, NULL, NULL, &generate_page, NULL, MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t) (256 * 1024), #if PRODUCTION MHD_OPTION_PER_IP_CONNECTION_LIMIT, (unsigned int) (64), #endif MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) (120 /* seconds */), MHD_OPTION_THREAD_POOL_SIZE, (unsigned int) NUMBER_OF_THREADS, MHD_OPTION_NOTIFY_COMPLETED, &response_completed_callback, NULL, MHD_OPTION_END); if (NULL == d) return 1; fprintf (stderr, "HTTP server running. Press ENTER to stop the server\n"); (void) getc (stdin); MHD_stop_daemon (d); MHD_destroy_response (file_not_found_response); MHD_destroy_response (request_refused_response); MHD_destroy_response (internal_error_response); update_cached_response (NULL); (void) pthread_mutex_destroy (&mutex); magic_close (magic); return 0; }
void MicroHttpd::stop() { if(_d->mhd) { logger::info() << "stopping microhttpd"; MHD_stop_daemon(_d->mhd); _d->mhd = 0; } }
void MicroHttpd::stop() { if(_d->mhd) { qInfo("Stopping microhttpd"); MHD_stop_daemon(_d->mhd); _d->mhd = 0; } }
/** * Test daemon initialization with the MHD_OPTION_SOCK_ADDR option */ static int test_ip_addr_option () { struct MHD_Daemon *d; struct sockaddr_in daemon_ip_addr; #if HAVE_INET6 struct sockaddr_in6 daemon_ip_addr6; #endif memset (&daemon_ip_addr, 0, sizeof (struct sockaddr_in)); daemon_ip_addr.sin_family = AF_INET; daemon_ip_addr.sin_port = htons (42433); #if HAVE_INET6 memset (&daemon_ip_addr6, 0, sizeof (struct sockaddr_in6)); daemon_ip_addr6.sin6_family = AF_INET6; daemon_ip_addr6.sin6_port = htons (42433); #endif inet_pton (AF_INET, "127.0.0.1", &daemon_ip_addr.sin_addr); #if HAVE_INET6 inet_pton (AF_INET6, "::ffff:127.0.0.1", &daemon_ip_addr6.sin6_addr); #endif d = MHD_start_daemon (MHD_USE_DEBUG, 42433, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_SOCK_ADDR, &daemon_ip_addr, MHD_OPTION_END); if (d == 0) return -1; MHD_stop_daemon (d); #if HAVE_INET6 d = MHD_start_daemon (MHD_USE_DEBUG | MHD_USE_IPv6, 42433, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_SOCK_ADDR, &daemon_ip_addr6, MHD_OPTION_END); if (d == 0) return -1; MHD_stop_daemon (d); #endif return 0; }
void httpd_proc_destroy(void) { #ifdef LIBMICROHTTPD LM_DBG("destroying module ...\n"); MHD_stop_daemon (dmn); #endif return; }
bool CWebServer::Stop() { if (!m_running) return true; if (m_daemon_ip6 != nullptr) MHD_stop_daemon(m_daemon_ip6); if (m_daemon_ip4 != nullptr) MHD_stop_daemon(m_daemon_ip4); m_running = false; CLog::Log(LOGNOTICE, "CWebServer[%hu]: Stopped", m_port); m_port = 0; return true; }
Webserver::~Webserver () { if (wdata != NULL) { MHD_stop_daemon((MHD_Daemon *)wdata); wdata = NULL; ready = false; } }
/** * Call with the port number as the only argument. * Never terminates (other than by signals, such as CTRL-C). */ int main (int argc, char *const *argv) { struct MHD_Daemon *d; struct timeval tv; struct timeval *tvp; fd_set rs; fd_set ws; fd_set es; int max; MHD_UNSIGNED_LONG_LONG mhd_timeout; if (argc != 2) { printf ("%s PORT\n", argv[0]); return 1; } /* initialize PRNG */ srand ((unsigned int) time (NULL)); d = MHD_start_daemon (MHD_USE_DEBUG, atoi (argv[1]), NULL, NULL, &create_response, NULL, MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 15, MHD_OPTION_NOTIFY_COMPLETED, &request_completed_callback, NULL, MHD_OPTION_END); if (NULL == d) return 1; while (1) { expire_sessions (); max = 0; FD_ZERO (&rs); FD_ZERO (&ws); FD_ZERO (&es); if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max)) break; /* fatal internal error */ if (MHD_get_timeout (d, &mhd_timeout) == MHD_YES) { tv.tv_sec = mhd_timeout / 1000; tv.tv_usec = (mhd_timeout - (tv.tv_sec * 1000)) * 1000; tvp = &tv; } else tvp = NULL; if (-1 == select (max + 1, &rs, &ws, &es, tvp)) { if (EINTR != errno) fprintf (stderr, "Aborting due to error during select: %s\n", strerror (errno)); break; } MHD_run (d); } MHD_stop_daemon (d); return 0; }
/** Destructor. */ WebServer::~WebServer() { MHD_stop_daemon(__daemon); __daemon = NULL; __dispatcher = NULL; if (__ssl_key_mem) free(__ssl_key_mem); if (__ssl_cert_mem) free(__ssl_cert_mem); }
bool CWebServer::Stop() { if (m_running) { if (m_daemon_ip6 != NULL) MHD_stop_daemon(m_daemon_ip6); if (m_daemon_ip4 != NULL) MHD_stop_daemon(m_daemon_ip4); m_running = false; CLog::Log(LOGNOTICE, "WebServer: Stopped the webserver"); } else CLog::Log(LOGNOTICE, "WebServer: Stopped failed because its not running"); return !m_running; }
/** * Stop the daemon **/ CmdManager::~CmdManager() { Cmd* c; while (work.trypop(c)) { c->cancel(); } MHD_stop_daemon(daemon); }
void httpsrv_stop() { if (!httpsrv) return; applog(LOG_DEBUG, "Stopping HTTP server"); MHD_stop_daemon(httpsrv); httpsrv = NULL; }
static void * ServeOneRequest(void *param) { struct MHD_Daemon *d; fd_set rs; fd_set ws; fd_set es; MHD_socket fd, max; time_t start; struct timeval tv; int done = 0; fd = (MHD_socket) (intptr_t) param; d = MHD_start_daemon (MHD_USE_DEBUG, 1082, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_LISTEN_SOCKET, fd, MHD_OPTION_NOTIFY_COMPLETED, &request_completed, &done, MHD_OPTION_END); if (d == NULL) return "MHD_start_daemon() failed"; start = time (NULL); while ((time (NULL) - start < 5) && done == 0) { max = 0; FD_ZERO (&rs); FD_ZERO (&ws); FD_ZERO (&es); if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max)) { MHD_stop_daemon (d); MHD_socket_close_(fd); return "MHD_get_fdset() failed"; } tv.tv_sec = 0; tv.tv_usec = 1000; MHD_SYS_select_ (max + 1, &rs, &ws, &es, &tv); MHD_run (d); } MHD_stop_daemon (d); MHD_socket_close_(fd); return NULL; }
void DSPServer::stop() { if (fDaemon) { // Faire un truc pour arrêter la boucle ? pthread_cancel(fThread); pthread_join(fThread, NULL); MHD_stop_daemon(fDaemon); fDaemon = 0; } }
/** * Test daemon initialization with the MHD_OPTION_SOCK_ADDR option */ static int test_ip_addr_option () { struct MHD_Daemon *d; struct sockaddr_in daemon_ip_addr; #if HAVE_INET6 struct sockaddr_in6 daemon_ip_addr6; #endif memset (&daemon_ip_addr, 0, sizeof (struct sockaddr_in)); daemon_ip_addr.sin_family = AF_INET; daemon_ip_addr.sin_port = htons (4233); daemon_ip_addr.sin_addr.s_addr = htonl (INADDR_LOOPBACK); #if HAVE_INET6 memset (&daemon_ip_addr6, 0, sizeof (struct sockaddr_in6)); daemon_ip_addr6.sin6_family = AF_INET6; daemon_ip_addr6.sin6_port = htons (4233); daemon_ip_addr6.sin6_addr = in6addr_loopback; #endif d = MHD_start_daemon (MHD_USE_DEBUG, 4233, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_SOCK_ADDR, &daemon_ip_addr, MHD_OPTION_END); if (d == 0) return -1; MHD_stop_daemon (d); #if HAVE_INET6 d = MHD_start_daemon (MHD_USE_DEBUG | MHD_USE_IPv6, 4233, NULL, NULL, &ahc_echo, NULL, MHD_OPTION_SOCK_ADDR, &daemon_ip_addr6, MHD_OPTION_END); if (d == 0) return -1; MHD_stop_daemon (d); #endif return 0; }
int HTTPServer::stop(){ if(daemon != NULL){ MHD_stop_daemon (daemon); Logging::getInstance()->Log(Logging::INFO, "MHD Daemon is stopped!"); return 1; }else{ Logging::getInstance()->Log(Logging::WARNING, "MHD Daemon is not stopped!"); return 0; } }
/** * Stop the MHD web server and the AVAHI server and free the associated services * * @return A HPD error code */ int stop_unsecure_server() { assert(d); free_unsecure_server_services(); MHD_stop_daemon (d); return HPD_E_SUCCESS; }
static int testMultithreadedGet () { struct MHD_Daemon *d; CURL *c; char buf[2048]; struct CBC cbc; CURLcode errornum; cbc.buf = buf; cbc.size = 2048; cbc.pos = 0; d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG, 1081, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); if (d == NULL) return 16; c = curl_easy_init (); curl_easy_setopt (c, CURLOPT_URL, "http://localhost:1081/hello_world"); curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 15L); // NOTE: use of CONNECTTIMEOUT without also // setting NOSIGNAL results in really weird // crashes on my system! curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1); if (CURLE_OK != (errornum = curl_easy_perform (c))) { fprintf (stderr, "curl_easy_perform failed: `%s'\n", curl_easy_strerror (errornum)); curl_easy_cleanup (c); MHD_stop_daemon (d); return 32; } curl_easy_cleanup (c); MHD_stop_daemon (d); return validate (cbc, 64); }
int main () { struct MHD_Daemon *daemon; daemon = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY, PORT, NULL, NULL, &answer, NULL, MHD_OPTION_THREAD_POOL_SIZE, N_THREADS, MHD_OPTION_END); if (NULL == daemon) return 1; getchar (); MHD_stop_daemon (daemon); return 0; }
static int testExternalGet () { struct MHD_Daemon *d; d = MHD_start_daemon (MHD_USE_DEBUG, 1082, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); if (d == NULL) return 8; MHD_stop_daemon (d); return 0; }
static int testMultithreadedGet (int poll_flag) { struct MHD_Daemon *d; d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG | poll_flag, 1081, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); if (d == NULL) return 2; MHD_stop_daemon (d); return 0; }
static int testInternalGet (int poll_flag) { struct MHD_Daemon *d; d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG | poll_flag, 11080, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); if (d == NULL) return 1; MHD_stop_daemon (d); return 0; }
/* perform a HTTP GET request via SSL/TLS */ static int test_secure_get (FILE * test_fd, const char *cipher_suite, int proto_version) { int ret; struct MHD_Daemon *d; int port; if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) port = 0; else port = 3041; d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS | MHD_USE_ERROR_LOG, port, NULL, NULL, &http_ahc, NULL, MHD_OPTION_HTTPS_MEM_KEY, srv_signed_key_pem, MHD_OPTION_HTTPS_MEM_CERT, srv_signed_cert_pem, MHD_OPTION_END); if (d == NULL) { fprintf (stderr, MHD_E_SERVER_INIT); return -1; } if (0 == port) { const union MHD_DaemonInfo *dinfo; dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); if (NULL == dinfo || 0 == dinfo->port) { MHD_stop_daemon (d); return -1; } port = (int)dinfo->port; } ret = test_https_transfer (test_fd, port, cipher_suite, proto_version); MHD_stop_daemon (d); return ret; }
int main () { struct MHD_Daemon *daemon; daemon = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY, PORT, NULL, NULL, &answer_to_connection, NULL, MHD_OPTION_END); if (NULL == daemon) return 1; getchar (); MHD_stop_daemon (daemon); return 0; }
static int testMultithreadedPoolGet (int poll_flag) { struct MHD_Daemon *d; d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG | poll_flag, 1081, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_THREAD_POOL_SIZE, CPU_COUNT, MHD_OPTION_END); if (d == NULL) return 4; MHD_stop_daemon (d); return 0; }
static int testStartStop () { struct MHD_Daemon *d; d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG, 1080, &apc_nothing, NULL, &ahc_nothing, NULL, MHD_OPTION_END); if (d == NULL) return 2; MHD_stop_daemon (d); return 0; }
static int testMultithreadedPut () { struct MHD_Daemon *d; CURL *c; char buf[2048]; struct CBC cbc; unsigned int pos = 0; int done_flag = 0; int i; cbc.buf = buf; cbc.size = 2048; cbc.pos = 0; d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */ , 11080, NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END); if (d == NULL) return 16; zzuf_socat_start (); for (i = 0; i < LOOP_COUNT; i++) { fprintf (stderr, "."); c = curl_easy_init (); curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1:11081/hello_world"); curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); curl_easy_setopt (c, CURLOPT_READDATA, &pos); curl_easy_setopt (c, CURLOPT_UPLOAD, 1L); curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L); curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); if (oneone) curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); else curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); /* NOTE: use of CONNECTTIMEOUT without also * setting NOSIGNAL results in really weird * crashes on my system! */ curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); curl_easy_perform (c); curl_easy_cleanup (c); } fprintf (stderr, "\n"); zzuf_socat_stop (); MHD_stop_daemon (d); return 0; }