Ejemplo n.º 1
0
Archivo: WServer.C Proyecto: ReWeb3D/wt
  void startSharedProcess()
  {
    Configuration& conf = server_.configuration();
    
    if (!Server::bindUDStoStdin(conf.runDirectory() + "/server-"
				+ boost::lexical_cast<std::string>(getpid()),
				server_))
      exit(1);

    try {
      FCGIStream fcgiStream;
      webMainInstance = webMain_ = new WebMain(&server_, &fcgiStream);
      webMain_->run();

      delete webMain_;
      webMainInstance = webMain_ = 0;
    } catch (std::exception& e) {
      LOG_ERROR_S(&server_,
		  "fatal: shared session process: caught unhandled exception: "
		  << e.what());

      throw;
    } catch (...) {
      LOG_ERROR_S(&server_,
		  "fatal: shared session process: caught unknown, unhandled "
		  "exception.");

      throw;
    }
  }
Ejemplo n.º 2
0
static ret_t
match (cherokee_rule_request_t *rule,
       cherokee_connection_t   *conn,
       cherokee_config_entry_t *ret_conf)
{
	int                     re;
	ret_t                   ret;
	cherokee_regex_table_t *regexs = CONN_SRV(conn)->regexs;

	UNUSED(ret_conf);

	/* Sanity checks
	 */
	if (unlikely (regexs == NULL)) {
		LOG_ERROR_S (CHEROKEE_ERROR_RULE_REQUEST_NO_TABLE);
		return ret_error;
	}

	if (unlikely (rule->pcre == NULL)) {
		LOG_ERROR_S (CHEROKEE_ERROR_RULE_REQUEST_NO_PCRE_PTR);
		return ret_error;
	}

        /* Build the request string
         */
        if (! cherokee_buffer_is_empty (&conn->query_string)) {
                cherokee_buffer_add_str (&conn->request, "?");
                cherokee_buffer_add_buffer (&conn->request, &conn->query_string);
        }

	/* Evaluate the pcre
	 */
	re = pcre_exec (rule->pcre, NULL,
			conn->request.buf,
			conn->request.len,
			0, 0,
			conn->regex_ovector, OVECTOR_LEN);

	if (re < 0) {
		TRACE (ENTRIES, "Request \"%s\" didn't match with \"%s\"\n",
		       conn->request.buf, rule->pattern.buf);

		ret = ret_not_found;
		goto restore;
	}

	conn->regex_ovecsize = re;

	TRACE (ENTRIES, "Request \"%s\" matches with \"%s\", ovecsize=%d\n",
	       conn->request.buf, rule->pattern.buf, conn->regex_ovecsize);

	ret = ret_ok;

restore:
        if (! cherokee_buffer_is_empty (&conn->query_string)) {
                cherokee_buffer_drop_ending (&conn->request, conn->query_string.len + 1);
        }

	return ret;
}
Ejemplo n.º 3
0
Archivo: WServer.C Proyecto: ReWeb3D/wt
  void runSession()
  {
    Configuration& conf = server_.configuration();

    if (!Server::bindUDStoStdin(conf.runDirectory() + "/" + sessionId_,
				server_))
      exit(1);

    try {
      FCGIStream fcgiStream;
      webMainInstance = webMain_
	= new WebMain(&server_, &fcgiStream, sessionId_);
      webMain_->run();

      sleep(1);

      delete webMain_;
      webMainInstance = webMain_ = 0;

    } catch (std::exception& e) {
      LOG_ERROR_S(&server_,
		  "fatal: dedicated session process for " << sessionId_ <<
		  ": caught unhandled exception: " << e.what());

      throw;
    } catch (...) {
      LOG_ERROR_S(&server_,
		  "fatal: dedicated session process for " << sessionId_ <<
		  ": caught unkown, unhandled exception.");

      throw;
    }
  }
Ejemplo n.º 4
0
Archivo: WServer.C Proyecto: ReWeb3D/wt
bool WServer::start()
{
  if (isRunning()) {
    LOG_ERROR_S(this, "start(): server already started!");
    return false;
  }

  LOG_INFO_S(this, "initializing " <<
	     (impl_->sessionId_.empty() ? "shared" : "dedicated") <<
	     " wtfcgi session process");

  if (configuration().webSockets()) {
    LOG_ERROR_S(this, "FastCGI does not support web-sockets, disabling");
    configuration().setWebSockets(false);
  }

  configuration().setNeedReadBodyBeforeResponse(true);

  if (signal(SIGTERM, Wt::handleSigTerm) == SIG_ERR)
    LOG_ERROR_S(this, "cannot catch SIGTERM: signal(): " << strerror(errno));
  if (signal(SIGUSR1, Wt::handleSigUsr1) == SIG_ERR) 
    LOG_ERROR_S(this, "cannot catch SIGUSR1: signal(): " << strerror(errno));
  if (signal(SIGHUP, Wt::handleSigHup) == SIG_ERR) 
    LOG_ERROR_S(this, "cannot catch SIGHUP: signal(): " << strerror(errno));

  webController_ = new Wt::WebController(*this, impl_->sessionId_, false);

  impl_->run();

  return false;
}
Ejemplo n.º 5
0
static ret_t
node_check (http2d_avl_generic_node_t *node)
{
	cint_t                       left_height;
	cint_t                       right_height;
	cint_t                       balance;
	http2d_avl_generic_node_t *tmp;

	if (node == NULL)
		return ret_ok;

	if (node->left_child) {
		tmp = node_prev (node);
		if (tmp->right != node) {
			LOG_ERROR_S (HTTP2D_ERROR_AVL_PREVIOUS);
			return ret_error;
		}
	}

	if (node->right_child) {
		tmp = node_next (node);
		if (tmp->left != node) {
			LOG_ERROR_S (HTTP2D_ERROR_AVL_NEXT);
			return ret_error;
		}
	}

	left_height  = 0;
	right_height = 0;

	if (node->left_child)
		left_height  = node_height (node->left);
	if (node->right_child)
		right_height = node_height (node->right);

	balance = right_height - left_height;
	if (balance != node->balance) {
		LOG_ERROR_S (HTTP2D_ERROR_AVL_BALANCE);
		return ret_error;
	}

	if (node->left_child)
		node_check (node->left);
	if (node->right_child)
		node_check (node->right);

	return ret_ok;
}
Ejemplo n.º 6
0
static ret_t
config_read_type (cherokee_config_node_t         *config,
                  cherokee_logger_writer_types_t *type)
{
	ret_t              ret;
	cherokee_buffer_t *tmp = NULL;

	ret = cherokee_config_node_read (config, "type", &tmp);
	if (ret != ret_ok) {
		LOG_ERROR_S (CHEROKEE_ERROR_LOGGER_NO_WRITER);
		return ret_error;
	}

	if (equal_buf_str (tmp, "syslog")) {
		*type = cherokee_logger_writer_syslog;
	} else if (equal_buf_str (tmp, "stderr")) {
		*type = cherokee_logger_writer_stderr;
	} else if (equal_buf_str (tmp, "file")) {
		*type = cherokee_logger_writer_file;
	} else if (equal_buf_str (tmp, "exec")) {
		*type = cherokee_logger_writer_pipe;
	} else {
		LOG_CRITICAL (CHEROKEE_ERROR_LOGGER_WRITER_UNKNOWN, tmp->buf);
		return ret_error;
	}

	return ret_ok;
}
Ejemplo n.º 7
0
Archivo: WServer.C Proyecto: ReWeb3D/wt
void WServer::resume()
{
  if (!isRunning()) {
    LOG_ERROR_S(this, "resume(): server not yet started!");
    return;
  }
}
Ejemplo n.º 8
0
ret_t
cherokee_init (void)
{
	ret_t ret;

	if (_cherokee_init)
		return ret_ok;

#ifdef _WIN32
	init_win32();
#endif

	/* Init the tracing facility
	 */
	cherokee_trace_init();

	/* Init the bogotime mechanism
	 */
	cherokee_bogotime_init();
	cherokee_bogotime_update();

	/* Init threading stuff
	 */
	cherokee_threading_init();

	/* Get the CPU number
	 */
	dcc_ncpus (&cherokee_cpu_number);
	if (cherokee_cpu_number < 1) {
		LOG_WARNING (CHEROKEE_ERROR_INIT_CPU_NUMBER, cherokee_cpu_number);
		cherokee_cpu_number = 1;
	}

	/* Try to figure the L2 cache line size
	 */
	cherokee_cacheline_size_get (&cherokee_cacheline_size);

	/* Get the file descriptor number limit
	 */
	ret = cherokee_sys_fdlimit_get (&cherokee_fdlimit);
	if (ret < ret_ok) {
		LOG_ERROR_S (CHEROKEE_ERROR_INIT_GET_FD_LIMIT);
		return ret;
	}

	/* Temp directory
	 */
	ret = init_tmp_dir();
	if (ret != ret_ok) {
		return ret;
	}

	cherokee_admin_child     = false;
	cherokee_readable_errors = NULLB_NULL;

	_cherokee_init = true;
	return ret_ok;
}
Ejemplo n.º 9
0
Archivo: Server.C Proyecto: bend/wt
void Server::expireSessions(boost::system::error_code ec)
{
  if (!ec) {
    wt_.expireSessions();
    expireSessionsTimer_.expires_from_now(boost::posix_time::seconds(SESSION_EXPIRE_INTERVAL));
    expireSessionsTimer_.async_wait(boost::bind(&Server::expireSessions, this,
	  asio::placeholders::error));
  } else if (ec != asio::error::operation_aborted) {
    LOG_ERROR_S(&wt_, "session expiration timer got an error: " << ec.message());
  }
}
Ejemplo n.º 10
0
Archivo: Server.C Proyecto: bend/wt
void Server::handleConnected(const boost::shared_ptr<asio::ip::tcp::socket>& socket,
			     const asio_error_code& err)
{
  if (!err) {
    boost::shared_ptr<std::string> buf(new std::string(
      boost::lexical_cast<std::string>(tcp_acceptor_.local_endpoint().port())));
    socket->async_send(asio::buffer(*buf),
      boost::bind(&Server::handlePortSent, this, socket, err, buf));
  } else {
    LOG_ERROR_S(&wt_, "child process couldn't connect to parent to send listening port: " << err.message());
  }
}
Ejemplo n.º 11
0
Archivo: Server.C Proyecto: bend/wt
void Server::handlePortSent(const boost::shared_ptr<asio::ip::tcp::socket>& socket,
			    const asio_error_code& err, const boost::shared_ptr<std::string>& /*buf*/)
{
  if (err) {
    LOG_ERROR_S(&wt_, "child process couldn't send listening port: " << err.message());
  }
  boost::system::error_code ignored_ec;
  if(socket.get()) {
	socket->shutdown(boost::asio::ip::tcp::socket::shutdown_both, ignored_ec);
	socket->close();
  }

}
Ejemplo n.º 12
0
ret_t
cherokee_x_real_ip_configure (cherokee_x_real_ip_t   *real_ip,
			      cherokee_config_node_t *config)
{
	ret_t                   ret;
	cherokee_config_node_t *subconf;

	cherokee_config_node_read_bool (config, "x_real_ip_enabled",    &real_ip->enabled);
	cherokee_config_node_read_bool (config, "x_real_ip_access_all", &real_ip->access_all);

	ret = cherokee_config_node_get (config, "x_real_ip_access", &subconf);
	if (ret == ret_ok) {
		ret = cherokee_config_node_read_list (subconf, NULL, add_access, real_ip);
		if (ret != ret_ok) {
			LOG_ERROR_S (CHEROKEE_ERROR_LOGGER_X_REAL_IP_PARSE);
			return ret_error;
		}
	}

	return ret_ok;
}
Ejemplo n.º 13
0
Archivo: WServer.C Proyecto: ReWeb3D/wt
int WRun(int argc, char *argv[], ApplicationCreator createApplication)
{
  try {
    WServer server(argv[0], "");

    try {
      server.setServerConfiguration(argc, argv);
      server.addEntryPoint(Application, createApplication);
      server.start();

      return 0;
    } catch (std::exception& e) {
      LOG_ERROR_S(&server, "fatal: " << e.what());
      return 1;
    }
  } catch (Wt::WServer::Exception& e) {
    LOG_ERROR("fatal: " << e.what());
    return 1;
  } catch (std::exception& e) {
    LOG_ERROR("fatal exception: " << e.what());
    return 1;
  }
}
/* Methods implementation
 */
static ret_t
process_package (cherokee_handler_fcgi_t *hdl, cherokee_buffer_t *inbuf, cherokee_buffer_t *outbuf)
{
	FCGI_Header *header;
	cuint_t      len;
	char        *data;
	cuint_t      type;
	cuint_t      id;
	cuint_t      padding;

	/* Is there enough information?
	 */
	if (inbuf->len < sizeof(FCGI_Header))
		return ret_ok;

	/* At least there is a header
	 */
	header = (FCGI_Header *)inbuf->buf;

	if (header->version != 1) {
		cherokee_buffer_print_debug (inbuf, -1);
		LOG_ERROR_S (CHEROKEE_ERROR_HANDLER_FCGI_VERSION);
		return ret_error;
	}

	if (header->type != FCGI_STDERR &&
	    header->type != FCGI_STDOUT &&
	    header->type != FCGI_END_REQUEST) {
		cherokee_buffer_print_debug (inbuf, -1);
		LOG_ERROR_S (CHEROKEE_ERROR_HANDLER_FCGI_PARSING);
		return ret_error;
	}

	/* Read the header
	 */
	type    =  header->type;
	padding =  header->paddingLength;
	id      = (header->requestIdB0     | (header->requestIdB1 << 8));
	len     = (header->contentLengthB0 | (header->contentLengthB1 << 8));
	data    = inbuf->buf +  FCGI_HEADER_LEN;

/*	printf ("have %d, hdr=%d exp_len=%d pad=%d\n", inbuf->len, FCGI_HEADER_LEN, len, padding); */

	/* Is the package complete?
	 */
	if (len + padding > inbuf->len - FCGI_HEADER_LEN) {
/*		printf ("Incomplete: %d < %d\n", len + padding, inbuf->len - FCGI_HEADER_LEN); */
		return ret_ok;
	}

	/* It has received the full package content
	 */
	switch (type) {
	case FCGI_STDERR:
/*		printf ("READ:STDERR (%d): %s", len, data?data:""); */

		LOG_ERROR (CHEROKEE_ERROR_HANDLER_FCGI_STDERR, data);

		/* Debug mode */
		if (SOURCE_INT(hdl->src_ref)->debug) {
			PRINT_MSG ("%.*s\n", len, data);
		}

		break;

	case FCGI_STDOUT:
/*		printf ("READ:STDOUT eof=%d: %d", HDL_CGI_BASE(hdl)->got_eof, len); */
		cherokee_buffer_add (outbuf, data, len);
		break;

	case FCGI_END_REQUEST:
/*		printf ("READ:END"); */
		HDL_CGI_BASE(hdl)->got_eof = true;
		break;

	default:
		SHOULDNT_HAPPEN;
	}

	cherokee_buffer_move_to_begin (inbuf, len + FCGI_HEADER_LEN + padding);
/*	printf ("- FCGI left %d\n", inbuf->len); */
	return ret_eagain;
}