1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 APLOG_USE_MODULE(proxy_ajp);
22 * Handle the CPING/CPONG
24 apr_status_t ajp_handle_cping_cpong(apr_socket_t *sock,
26 apr_interval_time_t timeout)
30 apr_interval_time_t org;
33 ap_log_rerror(APLOG_MARK, APLOG_TRACE8, 0, r,
34 "Into ajp_handle_cping_cpong");
36 rc = ajp_msg_create(r->pool, AJP_PING_PONG_SZ, &msg);
37 if (rc != APR_SUCCESS) {
38 ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01007)
39 "ajp_handle_cping_cpong: ajp_msg_create failed");
43 rc = ajp_msg_serialize_cping(msg);
44 if (rc != APR_SUCCESS) {
45 ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01008)
46 "ajp_handle_cping_cpong: ajp_marshal_into_msgb failed");
50 rc = ajp_ilink_send(sock, msg);
51 ajp_msg_log(r, msg, "ajp_handle_cping_cpong: ajp_ilink_send packet dump");
52 if (rc != APR_SUCCESS) {
53 ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01009)
54 "ajp_handle_cping_cpong: ajp_ilink_send failed");
58 rc = apr_socket_timeout_get(sock, &org);
59 if (rc != APR_SUCCESS) {
60 ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01010)
61 "ajp_handle_cping_cpong: apr_socket_timeout_get failed");
65 /* Set CPING/CPONG response timeout */
66 rc = apr_socket_timeout_set(sock, timeout);
67 if (rc != APR_SUCCESS) {
68 ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01011)
69 "ajp_handle_cping_cpong: apr_socket_timeout_set failed");
74 /* Read CPONG reply */
75 rv = ajp_ilink_receive(sock, msg);
76 if (rv != APR_SUCCESS) {
77 ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01012)
78 "ajp_handle_cping_cpong: ajp_ilink_receive failed");
82 ajp_msg_log(r, msg, "ajp_handle_cping_cpong: ajp_ilink_receive packet dump");
83 rv = ajp_msg_get_uint8(msg, &result);
84 if (rv != APR_SUCCESS) {
85 ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01013)
86 "ajp_handle_cping_cpong: invalid CPONG message");
89 if (result != CMD_AJP13_CPONG) {
90 ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01014)
91 "ajp_handle_cping_cpong: awaited CPONG, received %d ",
98 /* Restore original socket timeout */
99 rc = apr_socket_timeout_set(sock, org);
100 if (rc != APR_SUCCESS) {
101 ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01015)
102 "ajp_handle_cping_cpong: apr_socket_timeout_set failed");
106 ap_log_rerror(APLOG_MARK, APLOG_TRACE8, 0, r,
107 "ajp_handle_cping_cpong: Done");
112 #define case_to_str(x) case CMD_AJP13_##x:\
117 * Convert numeric message type into string
118 * @param type AJP message type
119 * @return AJP message type as a string
121 const char *ajp_type_str(int type)
124 case_to_str(FORWARD_REQUEST)
125 case_to_str(SEND_BODY_CHUNK)
126 case_to_str(SEND_HEADERS)
127 case_to_str(END_RESPONSE)
128 case_to_str(GET_BODY_CHUNK)
129 case_to_str(SHUTDOWN)
134 return "CMD_AJP13_UNKNOWN";