ajp_msg.c revision cfc1ba216dbcc0af93b427d41e16717a772f09be
6de8046f8f7e07cd83895a528df25d977e502c76nd/* Licensed to the Apache Software Foundation (ASF) under one or more
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * contributor license agreements. See the NOTICE file distributed with
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * this work for additional information regarding copyright ownership.
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * The ASF licenses this file to You under the Apache License, Version 2.0
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * (the "License"); you may not use this file except in compliance with
2d2eda71267231c2526be701fe655db125852c1ffielding * the License. You may obtain a copy of the License at
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * Unless required by applicable law or agreed to in writing, software
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * distributed under the License is distributed on an "AS IS" BASIS,
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * See the License for the specific language governing permissions and
2d2eda71267231c2526be701fe655db125852c1ffielding * limitations under the License.
92f3af936ce61f25358a3ee4f28df2f6d62040dfdreid/* 2 hex digits plus space plus one char per dumped byte */
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbb/* plus prefix plus separator plus '\0' */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * Dump the given number of bytes on an AJP Message
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * @param pool pool to allocate from
52de7a47876ce1748910cf3a0ee97f78842fab54rederpj * @param msg AJP Message to dump
52de7a47876ce1748910cf3a0ee97f78842fab54rederpj * @param err error string to display
52de7a47876ce1748910cf3a0ee97f78842fab54rederpj * @param count the number of bytes to dump
52de7a47876ce1748910cf3a0ee97f78842fab54rederpj * @param buf buffer pointer for dump message
52de7a47876ce1748910cf3a0ee97f78842fab54rederpj * @return APR_SUCCESS or error
52de7a47876ce1748910cf3a0ee97f78842fab54rederpjapr_status_t ajp_msg_dump(apr_pool_t *pool, ajp_msg_t *msg, char *err,
2d2eda71267231c2526be701fe655db125852c1ffielding /* Display only first "count" bytes */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb /* First the space needed for the first line */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb /* Now for the data lines */
50e60f30bdc074fbc887f0b98f4d570457ac97c9brianp " len=%" APR_SIZE_T_FMT " max=%" APR_SIZE_T_FMT "\n",
50e60f30bdc074fbc887f0b98f4d570457ac97c9brianp for (i = 0; i < len; i += AJP_MSG_DUMP_BYTES_PER_LINE) {
50e60f30bdc074fbc887f0b98f4d570457ac97c9brianp /* Safety check: do we have enough buffer for another line? */
8af88bd6958b80c224e964892b8237720b13ab1ajerenkrantz apr_snprintf(current, rl, "%.4lx ", (unsigned long)i);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb for (j = 0; j < line_len; j++) {
61fd0cab072a05b855cbef9c585702401ac5ae29rbb for (j = 0; j < line_len; j++) {
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * Log an AJP message
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * @param request The current request
7bdef86e15d47d16dcbe7a5611683191774bd5fbgstein * @param msg AJP Message to dump
7bdef86e15d47d16dcbe7a5611683191774bd5fbgstein * @param err error string to display
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * @return APR_SUCCESS or error
61fd0cab072a05b855cbef9c585702401ac5ae29rbbapr_status_t ajp_msg_log(request_rec *r, ajp_msg_t *msg, char *err)
d82d78a97558238d16c52ec5278fe921bb7d7ec3brianp * Check a new AJP Message by looking at signature and return its size
d82d78a97558238d16c52ec5278fe921bb7d7ec3brianp * @param msg AJP Message to check
d82d78a97558238d16c52ec5278fe921bb7d7ec3brianp * @param len Pointer to returned len
d82d78a97558238d16c52ec5278fe921bb7d7ec3brianp * @return APR_SUCCESS or error
d82d78a97558238d16c52ec5278fe921bb7d7ec3brianpapr_status_t ajp_msg_check_header(ajp_msg_t *msg, apr_size_t *len)
61fd0cab072a05b855cbef9c585702401ac5ae29rbb ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL, APLOGNO(01080)
61fd0cab072a05b855cbef9c585702401ac5ae29rbb "ajp_msg_check_header() got bad signature %02x%02x",
61fd0cab072a05b855cbef9c585702401ac5ae29rbb ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL, APLOGNO(01081)
61fd0cab072a05b855cbef9c585702401ac5ae29rbb "ajp_msg_check_header() incoming message is "
3d96ee83babeec32482c9082c9426340cee8c44dwrowe "too big %" APR_SIZE_T_FMT ", max is %" APR_SIZE_T_FMT,
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * Reset an AJP Message
78ae1cbba5a848a24ca551629bbf0a90d2b931f0stas * @param msg AJP Message to reset
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * @return APR_SUCCESS or error
2d2eda71267231c2526be701fe655db125852c1ffielding * Reuse an AJP Message
2d2eda71267231c2526be701fe655db125852c1ffielding * @param msg AJP Message to reuse
2d2eda71267231c2526be701fe655db125852c1ffielding * @return APR_SUCCESS or error
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * Mark the end of an AJP Message
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * @param msg AJP Message to end
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * @return APR_SUCCESS or error
62db15de4c1f335a64d45821796ae197cff94ef8rbbstatic APR_INLINE int ajp_log_overflow(ajp_msg_t *msg, const char *context)
62db15de4c1f335a64d45821796ae197cff94ef8rbb * Add an unsigned 32bits value to AJP Message
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar * @param msg AJP Message to get value from
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar * @param value value to add to AJP Message
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar * @return APR_SUCCESS or error
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coarapr_status_t ajp_msg_append_uint32(ajp_msg_t *msg, apr_uint32_t value)
3d96ee83babeec32482c9082c9426340cee8c44dwrowe return ajp_log_overflow(msg, "ajp_msg_append_uint32");
a19698aebe10b9d41574e4a73794ba7d4cecd78btrawick msg->buf[len + 1] = (apr_byte_t)((value >> 16) & 0xFF);
a19698aebe10b9d41574e4a73794ba7d4cecd78btrawick msg->buf[len + 2] = (apr_byte_t)((value >> 8) & 0xFF);
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar * Add an unsigned 16bits value to AJP Message
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar * @param msg AJP Message to get value from
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar * @param value value to add to AJP Message
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar * @return APR_SUCCESS or error
3d96ee83babeec32482c9082c9426340cee8c44dwroweapr_status_t ajp_msg_append_uint16(ajp_msg_t *msg, apr_uint16_t value)
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar * Add an unsigned 8bits value to AJP Message
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar * @param msg AJP Message to get value from
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar * @param value value to add to AJP Message
3d96ee83babeec32482c9082c9426340cee8c44dwrowe * @return APR_SUCCESS or error
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coarapr_status_t ajp_msg_append_uint8(ajp_msg_t *msg, apr_byte_t value)
bf648cbfa4a723c9c02fe8444103cd41ed8642d0wrowe * Add a String in AJP message, and transform the String in ASCII
bf648cbfa4a723c9c02fe8444103cd41ed8642d0wrowe * if convert is set and we're on an EBCDIC machine
db08da9ddcd65c31f9ea44b823898b72a1b24fbestoddard * @param msg AJP Message to get value from
2864362ca8266097928e84f101010bdf814ffa08stoddard * @param value Pointer to String
2d2eda71267231c2526be701fe655db125852c1ffielding * @param convert When set told to convert String to ASCII
2d2eda71267231c2526be701fe655db125852c1ffielding * @return APR_SUCCESS or error
2d2eda71267231c2526be701fe655db125852c1ffieldingapr_status_t ajp_msg_append_string_ex(ajp_msg_t *msg, const char *value,
61fd0cab072a05b855cbef9c585702401ac5ae29rbb return ajp_log_overflow(msg, "ajp_msg_append_cvt_string");
61fd0cab072a05b855cbef9c585702401ac5ae29rbb /* ignore error - we checked once */
aecb17a45c6d3ee4729ed5f68dc4270f211ee7a8fielding /* We checked for space !! */
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgstein memcpy(msg->buf + msg->len, value, len + 1); /* including \0 */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb /* convert from EBCDIC if needed */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb ap_xlate_proto_to_ascii((char *)msg->buf + msg->len, len + 1);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * Add a Byte array to AJP Message
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * @param msg AJP Message to get value from
aecb17a45c6d3ee4729ed5f68dc4270f211ee7a8fielding * @param value Pointer to Byte array
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * @param valuelen Byte array len
aecb17a45c6d3ee4729ed5f68dc4270f211ee7a8fielding * @return APR_SUCCESS or error
61fd0cab072a05b855cbef9c585702401ac5ae29rbbapr_status_t ajp_msg_append_bytes(ajp_msg_t *msg, const apr_byte_t *value,
61fd0cab072a05b855cbef9c585702401ac5ae29rbb return APR_SUCCESS; /* Shouldn't we indicate an error ? */
aecb17a45c6d3ee4729ed5f68dc4270f211ee7a8fielding return ajp_log_overflow(msg, "ajp_msg_append_bytes");
61fd0cab072a05b855cbef9c585702401ac5ae29rbb /* We checked for space !! */
2d2eda71267231c2526be701fe655db125852c1ffielding * Get a 32bits unsigned value from AJP Message
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * @param msg AJP Message to get value from
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * @param rvalue Pointer where value will be returned
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * @return APR_SUCCESS or error
61fd0cab072a05b855cbef9c585702401ac5ae29rbbapr_status_t ajp_msg_get_uint32(ajp_msg_t *msg, apr_uint32_t *rvalue)
2d2eda71267231c2526be701fe655db125852c1ffielding return ajp_log_overflow(msg, "ajp_msg_get_uint32");
d839a9822ee53ce00da24c15f2d9fe054233d342gstein * Get a 16bits unsigned value from AJP Message
d839a9822ee53ce00da24c15f2d9fe054233d342gstein * @param msg AJP Message to get value from
2d2eda71267231c2526be701fe655db125852c1ffielding * @param rvalue Pointer where value will be returned
2d2eda71267231c2526be701fe655db125852c1ffielding * @return APR_SUCCESS or error
61fd0cab072a05b855cbef9c585702401ac5ae29rbbapr_status_t ajp_msg_get_uint16(ajp_msg_t *msg, apr_uint16_t *rvalue)
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * Peek a 16bits unsigned value from AJP Message, position in message
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * is not updated
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * @param msg AJP Message to get value from
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * @param rvalue Pointer where value will be returned
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * @return APR_SUCCESS or error
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgsteinapr_status_t ajp_msg_peek_uint16(ajp_msg_t *msg, apr_uint16_t *rvalue)
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * Peek a 8bits unsigned value from AJP Message, position in message
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * is not updated
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * @param msg AJP Message to get value from
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * @param rvalue Pointer where value will be returned
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * @return APR_SUCCESS or error
61fd0cab072a05b855cbef9c585702401ac5ae29rbbapr_status_t ajp_msg_peek_uint8(ajp_msg_t *msg, apr_byte_t *rvalue)
3d96ee83babeec32482c9082c9426340cee8c44dwrowe * Get a 8bits unsigned value from AJP Message
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * @param msg AJP Message to get value from
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * @param rvalue Pointer where value will be returned
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * @return APR_SUCCESS or error
61fd0cab072a05b855cbef9c585702401ac5ae29rbbapr_status_t ajp_msg_get_uint8(ajp_msg_t *msg, apr_byte_t *rvalue)
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgstein * Get a String value from AJP Message
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * @param msg AJP Message to get value from
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * @param rvalue Pointer where value will be returned
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * @return APR_SUCCESS or error
94d240fc213d4a96160d7014633374cc22a204d8trawickapr_status_t ajp_msg_get_string(ajp_msg_t *msg, const char **rvalue)
2d2eda71267231c2526be701fe655db125852c1ffielding if ((status != APR_SUCCESS) || (size + start > msg->max_size)) {
2d2eda71267231c2526be701fe655db125852c1ffielding * Get a Byte array from AJP Message
fd8b91502bc200ed4cca3810560a2a570522b3debrianp * @param msg AJP Message to get value from
fd8b91502bc200ed4cca3810560a2a570522b3debrianp * @param rvalue Pointer where value will be returned
fd8b91502bc200ed4cca3810560a2a570522b3debrianp * @param rvalueLen Pointer where Byte array len will be returned
fd8b91502bc200ed4cca3810560a2a570522b3debrianp * @return APR_SUCCESS or error
fd8b91502bc200ed4cca3810560a2a570522b3debrianpapr_status_t ajp_msg_get_bytes(ajp_msg_t *msg, apr_byte_t **rvalue,
fd8b91502bc200ed4cca3810560a2a570522b3debrianp /* save the current position */
4111de96e9f75c58e77c2bdda23be83b8ebf81ccgregames if ((status != APR_SUCCESS) || (size + start > msg->max_size)) {
4111de96e9f75c58e77c2bdda23be83b8ebf81ccgregames msg->pos += (apr_size_t)size; /* only bytes, no trailer */
50e60f30bdc074fbc887f0b98f4d570457ac97c9brianp * Create an AJP Message from pool
45613d36b9466a48def0498cffa07f48980720f8jerenkrantz * @param pool memory pool to allocate AJP message from
45613d36b9466a48def0498cffa07f48980720f8jerenkrantz * @param size size of the buffer to create
fd8b91502bc200ed4cca3810560a2a570522b3debrianp * @param rmsg Pointer to newly created AJP message
4111de96e9f75c58e77c2bdda23be83b8ebf81ccgregames * @return APR_SUCCESS or error
4111de96e9f75c58e77c2bdda23be83b8ebf81ccgregamesapr_status_t ajp_msg_create(apr_pool_t *pool, apr_size_t size, ajp_msg_t **rmsg)
50e60f30bdc074fbc887f0b98f4d570457ac97c9brianp ajp_msg_t *msg = (ajp_msg_t *)apr_pcalloc(pool, sizeof(ajp_msg_t));
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * Recopy an AJP Message to another
3d96ee83babeec32482c9082c9426340cee8c44dwrowe * @param smsg source AJP message
2d2eda71267231c2526be701fe655db125852c1ffielding * @param dmsg destination AJP message
344f3bc38dfccf6261d5bb8d689794cde113b3d6coar * @return APR_SUCCESS or error
344f3bc38dfccf6261d5bb8d689794cde113b3d6coarapr_status_t ajp_msg_copy(ajp_msg_t *smsg, ajp_msg_t *dmsg)
344f3bc38dfccf6261d5bb8d689794cde113b3d6coar ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL, APLOGNO(01082)
344f3bc38dfccf6261d5bb8d689794cde113b3d6coar "ajp_msg_copy(): destination buffer too "
5a9667916c79d8c699b069068e5570aa1c331c80gstein "small %" APR_SIZE_T_FMT ", max size is %" APR_SIZE_T_FMT,
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * Serialize in an AJP Message a PING command
42ce672c516baf6e4eaed18ccc1647de2d456d8edougm * +-----------------------+
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgstein * | PING CMD (1 byte) |
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * +-----------------------+
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * @param smsg AJP message to put serialized message
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * @return APR_SUCCESS or error
61fd0cab072a05b855cbef9c585702401ac5ae29rbb if ((rc = ajp_msg_append_uint8(msg, CMD_AJP13_PING)) != APR_SUCCESS)
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgstein * Serialize in an AJP Message a CPING command
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * +-----------------------+
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * | CPING CMD (1 byte) |
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * +-----------------------+
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * @param smsg AJP message to put serialized message
42ce672c516baf6e4eaed18ccc1647de2d456d8edougm * @return APR_SUCCESS or error