|
Packit |
90a5c9 |
/* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
Packit |
90a5c9 |
* contributor license agreements. See the NOTICE file distributed with
|
|
Packit |
90a5c9 |
* this work for additional information regarding copyright ownership.
|
|
Packit |
90a5c9 |
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
Packit |
90a5c9 |
* (the "License"); you may not use this file except in compliance with
|
|
Packit |
90a5c9 |
* the License. You may obtain a copy of the License at
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* Unless required by applicable law or agreed to in writing, software
|
|
Packit |
90a5c9 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
Packit |
90a5c9 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
Packit |
90a5c9 |
* See the License for the specific language governing permissions and
|
|
Packit |
90a5c9 |
* limitations under the License.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#include "ajp.h"
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
APLOG_USE_MODULE(proxy_ajp);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Handle the CPING/CPONG
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
apr_status_t ajp_handle_cping_cpong(apr_socket_t *sock,
|
|
Packit |
90a5c9 |
request_rec *r,
|
|
Packit |
90a5c9 |
apr_interval_time_t timeout)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
ajp_msg_t *msg;
|
|
Packit |
90a5c9 |
apr_status_t rc, rv;
|
|
Packit |
90a5c9 |
apr_interval_time_t org;
|
|
Packit |
90a5c9 |
apr_byte_t result;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_TRACE8, 0, r,
|
|
Packit |
90a5c9 |
"Into ajp_handle_cping_cpong");
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
rc = ajp_msg_create(r->pool, AJP_PING_PONG_SZ, &msg;;
|
|
Packit |
90a5c9 |
if (rc != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01007)
|
|
Packit |
90a5c9 |
"ajp_handle_cping_cpong: ajp_msg_create failed");
|
|
Packit |
90a5c9 |
return rc;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
rc = ajp_msg_serialize_cping(msg);
|
|
Packit |
90a5c9 |
if (rc != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01008)
|
|
Packit |
90a5c9 |
"ajp_handle_cping_cpong: ajp_marshal_into_msgb failed");
|
|
Packit |
90a5c9 |
return rc;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
rc = ajp_ilink_send(sock, msg);
|
|
Packit |
90a5c9 |
ajp_msg_log(r, msg, "ajp_handle_cping_cpong: ajp_ilink_send packet dump");
|
|
Packit |
90a5c9 |
if (rc != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01009)
|
|
Packit |
90a5c9 |
"ajp_handle_cping_cpong: ajp_ilink_send failed");
|
|
Packit |
90a5c9 |
return rc;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
rc = apr_socket_timeout_get(sock, &org;;
|
|
Packit |
90a5c9 |
if (rc != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01010)
|
|
Packit |
90a5c9 |
"ajp_handle_cping_cpong: apr_socket_timeout_get failed");
|
|
Packit |
90a5c9 |
return rc;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Set CPING/CPONG response timeout */
|
|
Packit |
90a5c9 |
rc = apr_socket_timeout_set(sock, timeout);
|
|
Packit |
90a5c9 |
if (rc != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01011)
|
|
Packit |
90a5c9 |
"ajp_handle_cping_cpong: apr_socket_timeout_set failed");
|
|
Packit |
90a5c9 |
return rc;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
ajp_msg_reuse(msg);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Read CPONG reply */
|
|
Packit |
90a5c9 |
rv = ajp_ilink_receive(sock, msg);
|
|
Packit |
90a5c9 |
if (rv != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01012)
|
|
Packit |
90a5c9 |
"ajp_handle_cping_cpong: ajp_ilink_receive failed");
|
|
Packit |
90a5c9 |
goto cleanup;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ajp_msg_log(r, msg, "ajp_handle_cping_cpong: ajp_ilink_receive packet dump");
|
|
Packit |
90a5c9 |
rv = ajp_msg_get_uint8(msg, &result);
|
|
Packit |
90a5c9 |
if (rv != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01013)
|
|
Packit |
90a5c9 |
"ajp_handle_cping_cpong: invalid CPONG message");
|
|
Packit |
90a5c9 |
goto cleanup;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (result != CMD_AJP13_CPONG) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01014)
|
|
Packit |
90a5c9 |
"ajp_handle_cping_cpong: awaited CPONG, received %d ",
|
|
Packit |
90a5c9 |
result);
|
|
Packit |
90a5c9 |
rv = APR_EGENERAL;
|
|
Packit |
90a5c9 |
goto cleanup;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
cleanup:
|
|
Packit |
90a5c9 |
/* Restore original socket timeout */
|
|
Packit |
90a5c9 |
rc = apr_socket_timeout_set(sock, org);
|
|
Packit |
90a5c9 |
if (rc != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01015)
|
|
Packit |
90a5c9 |
"ajp_handle_cping_cpong: apr_socket_timeout_set failed");
|
|
Packit |
90a5c9 |
return rc;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_TRACE8, 0, r,
|
|
Packit |
90a5c9 |
"ajp_handle_cping_cpong: Done");
|
|
Packit |
90a5c9 |
return rv;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#define case_to_str(x) case CMD_AJP13_##x:\
|
|
Packit |
90a5c9 |
return #x;\
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/**
|
|
Packit |
90a5c9 |
* Convert numeric message type into string
|
|
Packit |
90a5c9 |
* @param type AJP message type
|
|
Packit |
90a5c9 |
* @return AJP message type as a string
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
const char *ajp_type_str(int type)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
switch (type) {
|
|
Packit |
90a5c9 |
case_to_str(FORWARD_REQUEST)
|
|
Packit |
90a5c9 |
case_to_str(SEND_BODY_CHUNK)
|
|
Packit |
90a5c9 |
case_to_str(SEND_HEADERS)
|
|
Packit |
90a5c9 |
case_to_str(END_RESPONSE)
|
|
Packit |
90a5c9 |
case_to_str(GET_BODY_CHUNK)
|
|
Packit |
90a5c9 |
case_to_str(SHUTDOWN)
|
|
Packit |
90a5c9 |
case_to_str(PING)
|
|
Packit |
90a5c9 |
case_to_str(CPONG)
|
|
Packit |
90a5c9 |
case_to_str(CPING)
|
|
Packit |
90a5c9 |
default:
|
|
Packit |
90a5c9 |
return "CMD_AJP13_UNKNOWN";
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
}
|