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