mod_proxy_wstunnel.c revision bc53c76f019e33f53dffe280fbe71324b400ead2
/* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "mod_proxy.h"
#include "ap_mpm.h"
typedef struct {
signed char is_async;
typedef struct ws_baton_t {
request_rec *r;
char *scheme; /* required to release the proxy connection */
} ws_baton_t;
static void proxy_wstunnel_callback(void *b);
request_rec *r = baton->r;
conn_rec *c = r->connection;
const apr_pollfd_t *signalled;
while(1) {
!= APR_SUCCESS) {
if (APR_STATUS_IS_EINTR(rv)) {
continue;
}
else if (APR_STATUS_IS_TIMEUP(rv)) {
if (try_async) {
return SUSPENDED;
}
else {
return HTTP_REQUEST_TIME_OUT;
}
}
else {
return HTTP_INTERNAL_SERVER_ERROR;
}
}
"woke from poll(), i=%d", pollcnt);
"sock was readable");
}
else if (pollevent & APR_POLLERR) {
"error on backconn");
}
else {
rv = APR_EGENERAL;
"unknown event on backconn %d", pollevent);
}
}
"client was readable");
}
else if (pollevent & APR_POLLERR) {
c->aborted = 1;
"error on client conn");
}
else {
rv = APR_EGENERAL;
"unknown event on client conn %d", pollevent);
}
}
else {
"unknown socket in pollset");
}
}
if (rv != APR_SUCCESS) {
break;
}
}
"finished with poll() - cleaning up");
return OK;
}
}
/* If neither socket becomes readable in the specified timeout,
* this callback will kill the request. We do not have to worry about
* having a cancel and a IO both queued.
*/
static void proxy_wstunnel_cancel_callback(void *b)
{
ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, baton->r, "proxy_wstunnel_cancel_callback, IO timed out");
return;
}
/* Invoked by the event loop when data is ready on either end.
* Pump both ends until they'd block and then start over again
* We don't need the invoke_mtx, since we never put multiple callback events
* in the queue.
*/
static void proxy_wstunnel_callback(void *b) {
int status;
}
else {
}
}
/*
* Canonicalise http-like URLs.
* scheme is the scheme for the URL
* url is the URL starting with the first '/'
* def_port is the default port for this scheme.
*/
{
const char *err;
char *scheme;
/* ap_port_of_scheme() */
url += 3;
scheme = "ws:";
}
url += 4;
scheme = "wss:";
}
else {
return DECLINED;
}
/*
* do syntactic check.
* We break the URL into host, port, path, search
*/
if (err) {
return HTTP_BAD_REQUEST;
}
/*
* process the path. With proxy-nocanon set (by
* mod_proxy) we use the raw, unparsed uri
*/
}
else {
r->proxyreq);
}
return HTTP_BAD_REQUEST;
/* if literal IPv6 address */
}
return OK;
}
{
#ifdef DEBUGGING
#endif
do {
if (rv == APR_SUCCESS) {
return APR_EPIPE;
}
if (APR_BRIGADE_EMPTY(bb)) {
break;
}
#ifdef DEBUGGING
len = -1;
"read %" APR_OFF_T_FMT
#endif
if (rv == APR_SUCCESS) {
}
else {
"error on %s - ap_pass_brigade",
name);
}
"error on %s - ap_get_brigade",
name);
}
} while (rv == APR_SUCCESS);
if (APR_STATUS_IS_EAGAIN(rv)) {
rv = APR_SUCCESS;
}
return rv;
}
/* Search thru the input filters and remove the reqtimeout one */
{
if (!filter) {
return;
}
while (next) {
break;
}
}
if (reqto) {
}
}
/*
* process the request and write the response.
*/
{
conn_rec *c = r->connection;
char *buf;
apr_bucket *e;
char *old_cl_val = NULL;
char *old_te_val = NULL;
int status;
&old_cl_val, &old_te_val);
return rv;
}
return rv;
"error apr_pollset_create()");
return HTTP_INTERNAL_SERVER_ERROR;
}
#if 0
#endif
pollfd.p = p;
r->output_filters = c->output_filters;
r->proto_output_filters = c->output_filters;
r->input_filters = c->input_filters;
r->proto_input_filters = c->input_filters;
/* This handler should take care of the entire connection; make it so that
* nothing else is attempted on the connection after returning. */
c->keepalive = AP_CONN_CLOSE;
baton->r = r;
}
else {
if (rv == APR_SUCCESS) {
return SUSPENDED;
}
else if (APR_STATUS_IS_ENOTIMPL(rv)) {
}
else {
return HTTP_INTERNAL_SERVER_ERROR;
}
}
}
/* Avoid sending error pages down an upgraded connection */
if (status != HTTP_REQUEST_TIME_OUT) {
}
}
return status;
}
/*
*/
{
int status;
char server_portstr[32];
char *scheme;
int retry;
conn_rec *c = r->connection;
apr_pool_t *p = r->pool;
int is_ssl = 0;
scheme = "WSS";
is_ssl = 1;
}
scheme = "WS";
}
else {
return DECLINED;
}
/* create space for state information */
r->server);
if (backend) {
}
return status;
}
retry = 0;
while (retry < 2) {
/* Step One: Determine Who To Connect To */
sizeof(server_portstr));
break;
/* Step Two: Make the Connection */
"failed to make connection to backend: %s",
break;
}
/* Step Three: Create conn_rec */
if (!backend->connection) {
break;
}
/* Step Three: Process the Request */
break;
}
/* Do not close the socket */
}
return status;
}
{
return (void *) new;
}
{
return "ProxyWebsocketIdleTimeout timeout has wrong format";
return NULL;
}
{
return "ProxyWebsocketAsyncDelay timeout has wrong format";
return NULL;
}
static const command_rec ws_proxy_cmds[] =
{
AP_INIT_FLAG("ProxyWebsocketAsync", ap_set_flag_slot_char, (void*)APR_OFFSETOF(proxyws_dir_conf, is_async),
"on if idle websockets connections should be monitored asyncronously"),
"timeout for activity in either direction, unlimited by default"),
"amount of time to poll before going asyncronous"),
{NULL}
};
static void ap_proxy_http_register_hook(apr_pool_t *p)
{
}
create_proxyws_dir_config, /* create per-directory config structure */
NULL, /* merge per-directory config structures */
NULL, /* create per-server config structure */
NULL, /* merge per-server config structures */
ws_proxy_cmds, /* command apr_table_t */
ap_proxy_http_register_hook /* register hooks */
};