]> granicus.if.org Git - apache/blob - modules/proxy/ajp_link.c
Fix format string warnings in proxy_ajp on 64-bit platforms:
[apache] / modules / proxy / ajp_link.c
1 /* Copyright 1999-2004 The Apache Software Foundation
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 #include "ajp.h"
17
18
19 apr_status_t ajp_ilink_send(apr_socket_t *sock, ajp_msg_t *msg)
20 {
21     char         *buf;
22     apr_status_t status;
23     apr_size_t   length;
24
25     if (sock == NULL) {
26         ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL,
27                       "ajp_ilink_send(): NULL socket provided");
28         return AJP_EINVAL;
29     }
30     
31     ajp_msg_end(msg);
32     
33     length = msg->len;
34     buf    = (char *)msg->buf;
35
36     do {
37         apr_size_t written = length;
38
39         status = apr_socket_send(sock, buf, &written);
40         if (status != APR_SUCCESS) {
41             ap_log_error(APLOG_MARK, APLOG_ERR, status, NULL,
42                           "ajp_ilink_send(): send failed");
43             return status;
44         }
45         length -= written;
46         buf    += written;
47     } while (length);
48
49     return APR_SUCCESS;
50 }
51
52
53 static apr_status_t ilink_read(apr_socket_t *sock, char * buf,
54                                apr_size_t len)
55 {
56     apr_size_t   length;
57     apr_status_t status;
58     apr_size_t   rdlen;
59
60     if (sock == NULL) {
61         ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL,
62                       "ajp_ilink_readN(): NULL socket provided");
63         return AJP_EINVAL;
64     }
65
66     rdlen  = 0;
67     length = len;
68     
69     while (rdlen < len) {
70
71         status = apr_socket_recv(sock, buf + rdlen, &length);
72
73         if (status == APR_EOF)
74             return status;          /* socket closed. */
75         else if (APR_STATUS_IS_EAGAIN(status))
76             continue;
77         else if (status != APR_SUCCESS)
78             return status;          /* any error. */
79             
80         rdlen += length;
81         length = len - rdlen;
82     }
83     return APR_SUCCESS;
84 }
85
86
87 apr_status_t ajp_ilink_receive(apr_socket_t *sock, ajp_msg_t *msg)
88 {
89     apr_status_t status;
90     apr_size_t   hlen;
91     apr_size_t   blen;
92
93     if (sock == NULL) {
94         ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL,
95                       "ajp_ilink_receive(): NULL socket provided");
96         return AJP_EINVAL;
97     }
98
99     hlen = msg->header_len;
100     
101     status = ilink_read(sock, msg->buf, hlen);
102     
103     if (status != APR_SUCCESS) {
104         ap_log_error(APLOG_MARK, APLOG_ERR, status, NULL,
105                      "ajp_ilink_receive() can't receive header");
106         return AJP_ENO_HEADER;
107     }
108     
109     status = ajp_msg_check_header(msg, &blen);
110
111     if (status != APR_SUCCESS) {
112         ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL,
113                      "ajp_ilink_receive() received bad header");
114         return AJP_EBAD_HEADER;
115     }
116
117     status = ilink_read(sock, msg->buf + hlen, blen);
118
119     if (status != APR_SUCCESS) {
120         ap_log_error(APLOG_MARK, APLOG_ERR, status, NULL,
121                      "ajp_ilink_receive() error while receiving message body "
122                      "of length %" APR_SIZE_T_FMT,
123                      hlen);
124         return AJP_EBAD_MESSAGE;
125     }
126
127     ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, NULL,
128                  "ajp_ilink_receive() received packet len=%" APR_SIZE_T_FMT
129                  "type=%d\n",
130                   blen, (int)msg->buf[hlen]);
131
132     return APR_SUCCESS;
133 }
134