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 *
2d2eda71267231c2526be701fe655db125852c1ffielding * http://www.apache.org/licenses/LICENSE-2.0
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd *
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.
2d2eda71267231c2526be701fe655db125852c1ffielding */
2d2eda71267231c2526be701fe655db125852c1ffielding
2d2eda71267231c2526be701fe655db125852c1ffielding#include "ajp.h"
2d2eda71267231c2526be701fe655db125852c1ffielding
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbbAPLOG_USE_MODULE(proxy_ajp);
b980ad7fdc218b4855cde9f75a747527f50c554dwrowe
ab5581cc78e9d865b0a6ab1404c53347b3276968rbb#define AJP_MSG_DUMP_BYTES_PER_LINE 16
92f3af936ce61f25358a3ee4f28df2f6d62040dfdreid/* 2 hex digits plus space plus one char per dumped byte */
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbb/* plus prefix plus separator plus '\0' */
c9a95767fbf0f5fb0976a06b97a256033925e433rbb#define AJP_MSG_DUMP_LINE_LENGTH (strlen("XX .") + \
fd0edaa8e3d4dd67d0604ccef2e96b071db96643fielding strlen("XXXX ") + \
2d2eda71267231c2526be701fe655db125852c1ffielding strlen(" - ") + 1)
2d2eda71267231c2526be701fe655db125852c1ffielding
2d2eda71267231c2526be701fe655db125852c1ffieldingstatic char *hex_table = "0123456789ABCDEF";
2d2eda71267231c2526be701fe655db125852c1ffielding
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/**
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * Dump the given number of bytes on an AJP Message
61fd0cab072a05b855cbef9c585702401ac5ae29rbb *
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
52de7a47876ce1748910cf3a0ee97f78842fab54rederpj */
52de7a47876ce1748910cf3a0ee97f78842fab54rederpjapr_status_t ajp_msg_dump(apr_pool_t *pool, ajp_msg_t *msg, char *err,
fd492f9543f14fb5bae78e04b135c3448eb9cc56rbb apr_size_t count, char **buf)
fd492f9543f14fb5bae78e04b135c3448eb9cc56rbb{
fd492f9543f14fb5bae78e04b135c3448eb9cc56rbb apr_size_t i, j;
fd492f9543f14fb5bae78e04b135c3448eb9cc56rbb char *current;
fd492f9543f14fb5bae78e04b135c3448eb9cc56rbb apr_size_t bl, rl;
2d2eda71267231c2526be701fe655db125852c1ffielding apr_byte_t x;
2d2eda71267231c2526be701fe655db125852c1ffielding apr_size_t len = msg->len;
2d2eda71267231c2526be701fe655db125852c1ffielding apr_size_t line_len;
2d2eda71267231c2526be701fe655db125852c1ffielding
2d2eda71267231c2526be701fe655db125852c1ffielding /* Display only first "count" bytes */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb if (len > count)
61fd0cab072a05b855cbef9c585702401ac5ae29rbb len = count;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb /* First the space needed for the first line */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb bl = strlen(err) + 3 * (strlen(" XXX=") + 20) + 1 +
61fd0cab072a05b855cbef9c585702401ac5ae29rbb /* Now for the data lines */
2d2eda71267231c2526be701fe655db125852c1ffielding (len + 15) / 16 * AJP_MSG_DUMP_LINE_LENGTH;
2d2eda71267231c2526be701fe655db125852c1ffielding *buf = apr_palloc(pool, bl);
8af88bd6958b80c224e964892b8237720b13ab1ajerenkrantz if (!*buf)
8af88bd6958b80c224e964892b8237720b13ab1ajerenkrantz return APR_ENOMEM;
8af88bd6958b80c224e964892b8237720b13ab1ajerenkrantz apr_snprintf(*buf, bl,
8af88bd6958b80c224e964892b8237720b13ab1ajerenkrantz "%s pos=%" APR_SIZE_T_FMT
50e60f30bdc074fbc887f0b98f4d570457ac97c9brianp " len=%" APR_SIZE_T_FMT " max=%" APR_SIZE_T_FMT "\n",
50e60f30bdc074fbc887f0b98f4d570457ac97c9brianp err, msg->pos, msg->len, msg->max_size);
50e60f30bdc074fbc887f0b98f4d570457ac97c9brianp current = *buf + strlen(*buf);
50e60f30bdc074fbc887f0b98f4d570457ac97c9brianp for (i = 0; i < len; i += AJP_MSG_DUMP_BYTES_PER_LINE) {
50e60f30bdc074fbc887f0b98f4d570457ac97c9brianp /* Safety check: do we have enough buffer for another line? */
50e60f30bdc074fbc887f0b98f4d570457ac97c9brianp rl = bl - (current - *buf);
50e60f30bdc074fbc887f0b98f4d570457ac97c9brianp if (AJP_MSG_DUMP_LINE_LENGTH > rl) {
50e60f30bdc074fbc887f0b98f4d570457ac97c9brianp *(current - 1) = '\0';
50e60f30bdc074fbc887f0b98f4d570457ac97c9brianp return APR_ENOMEM;
50e60f30bdc074fbc887f0b98f4d570457ac97c9brianp }
8af88bd6958b80c224e964892b8237720b13ab1ajerenkrantz apr_snprintf(current, rl, "%.4lx ", (unsigned long)i);
bfb62a96023822c56c9120e4ee627d4091cc59c2rbb line_len = len - i;
bfb62a96023822c56c9120e4ee627d4091cc59c2rbb if (line_len > AJP_MSG_DUMP_BYTES_PER_LINE) {
61fd0cab072a05b855cbef9c585702401ac5ae29rbb line_len = AJP_MSG_DUMP_BYTES_PER_LINE;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb }
61fd0cab072a05b855cbef9c585702401ac5ae29rbb for (j = 0; j < line_len; j++) {
61fd0cab072a05b855cbef9c585702401ac5ae29rbb x = msg->buf[i + j];
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb *current++ = hex_table[x >> 4];
3d96ee83babeec32482c9082c9426340cee8c44dwrowe *current++ = hex_table[x & 0x0f];
2d2eda71267231c2526be701fe655db125852c1ffielding *current++ = ' ';
61fd0cab072a05b855cbef9c585702401ac5ae29rbb }
61fd0cab072a05b855cbef9c585702401ac5ae29rbb *current++ = ' ';
61fd0cab072a05b855cbef9c585702401ac5ae29rbb *current++ = '-';
61fd0cab072a05b855cbef9c585702401ac5ae29rbb *current++ = ' ';
61fd0cab072a05b855cbef9c585702401ac5ae29rbb for (j = 0; j < line_len; j++) {
61fd0cab072a05b855cbef9c585702401ac5ae29rbb x = msg->buf[i + j];
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb if (x > 0x20 && x < 0x7F) {
61fd0cab072a05b855cbef9c585702401ac5ae29rbb *current++ = x;
2d2eda71267231c2526be701fe655db125852c1ffielding }
3d96ee83babeec32482c9082c9426340cee8c44dwrowe else {
2d2eda71267231c2526be701fe655db125852c1ffielding *current++ = '.';
2d2eda71267231c2526be701fe655db125852c1ffielding }
2d2eda71267231c2526be701fe655db125852c1ffielding }
2d2eda71267231c2526be701fe655db125852c1ffielding *current++ = '\n';
000b67449410515eac43e76ef6667915bfd4d2abgstein }
2d2eda71267231c2526be701fe655db125852c1ffielding *(current - 1) = '\0';
2d2eda71267231c2526be701fe655db125852c1ffielding
2d2eda71267231c2526be701fe655db125852c1ffielding return APR_SUCCESS;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb}
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/**
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * Log an AJP message
7bdef86e15d47d16dcbe7a5611683191774bd5fbgstein *
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
61fd0cab072a05b855cbef9c585702401ac5ae29rbb */
61fd0cab072a05b855cbef9c585702401ac5ae29rbbapr_status_t ajp_msg_log(request_rec *r, ajp_msg_t *msg, char *err)
61fd0cab072a05b855cbef9c585702401ac5ae29rbb{
61fd0cab072a05b855cbef9c585702401ac5ae29rbb int level;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb apr_size_t count;
3d96ee83babeec32482c9082c9426340cee8c44dwrowe char *buf, *next;
7bdef86e15d47d16dcbe7a5611683191774bd5fbgstein apr_status_t rc = APR_SUCCESS;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb if (APLOGrtrace7(r)) {
61fd0cab072a05b855cbef9c585702401ac5ae29rbb level = APLOG_TRACE7;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb count = 1024;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb if (APLOGrtrace8(r)) {
61fd0cab072a05b855cbef9c585702401ac5ae29rbb level = APLOG_TRACE8;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb count = AJP_MAX_BUFFER_SZ;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb }
3d96ee83babeec32482c9082c9426340cee8c44dwrowe rc = ajp_msg_dump(r->pool, msg, err, count, &buf);
7bdef86e15d47d16dcbe7a5611683191774bd5fbgstein if (rc == APR_SUCCESS) {
c9a95767fbf0f5fb0976a06b97a256033925e433rbb while ((next = ap_strchr(buf, '\n'))) {
c9a95767fbf0f5fb0976a06b97a256033925e433rbb *next = '\0';
c9a95767fbf0f5fb0976a06b97a256033925e433rbb ap_log_rerror(APLOG_MARK, level, 0, r, "%s", buf);
c9a95767fbf0f5fb0976a06b97a256033925e433rbb buf = next + 1;
c9a95767fbf0f5fb0976a06b97a256033925e433rbb }
c9a95767fbf0f5fb0976a06b97a256033925e433rbb ap_log_rerror(APLOG_MARK, level, 0, r, "%s", buf);
c9a95767fbf0f5fb0976a06b97a256033925e433rbb }
c9a95767fbf0f5fb0976a06b97a256033925e433rbb }
c9a95767fbf0f5fb0976a06b97a256033925e433rbb return rc;
c9a95767fbf0f5fb0976a06b97a256033925e433rbb}
c9a95767fbf0f5fb0976a06b97a256033925e433rbb
d82d78a97558238d16c52ec5278fe921bb7d7ec3brianp/**
d82d78a97558238d16c52ec5278fe921bb7d7ec3brianp * Check a new AJP Message by looking at signature and return its size
d82d78a97558238d16c52ec5278fe921bb7d7ec3brianp *
d82d78a97558238d16c52ec5278fe921bb7d7ec3brianp * @param msg AJP Message to check
d82d78a97558238d16c52ec5278fe921bb7d7ec3brianp * @param len Pointer to returned len
d82d78a97558238d16c52ec5278fe921bb7d7ec3brianp * @return APR_SUCCESS or error
d82d78a97558238d16c52ec5278fe921bb7d7ec3brianp */
d82d78a97558238d16c52ec5278fe921bb7d7ec3brianpapr_status_t ajp_msg_check_header(ajp_msg_t *msg, apr_size_t *len)
d82d78a97558238d16c52ec5278fe921bb7d7ec3brianp{
d82d78a97558238d16c52ec5278fe921bb7d7ec3brianp apr_byte_t *head = msg->buf;
d82d78a97558238d16c52ec5278fe921bb7d7ec3brianp apr_size_t msglen;
c9a95767fbf0f5fb0976a06b97a256033925e433rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb if (!((head[0] == 0x41 && head[1] == 0x42) ||
61fd0cab072a05b855cbef9c585702401ac5ae29rbb (head[0] == 0x12 && head[1] == 0x34))) {
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL, APLOGNO(01080)
61fd0cab072a05b855cbef9c585702401ac5ae29rbb "ajp_msg_check_header() got bad signature %02x%02x",
61fd0cab072a05b855cbef9c585702401ac5ae29rbb head[0], head[1]);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb return AJP_EBAD_SIGNATURE;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb }
3d96ee83babeec32482c9082c9426340cee8c44dwrowe
7bdef86e15d47d16dcbe7a5611683191774bd5fbgstein msglen = ((head[2] & 0xff) << 8);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb msglen += (head[3] & 0xFF);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb if (msglen > msg->max_size) {
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,
7bdef86e15d47d16dcbe7a5611683191774bd5fbgstein msglen, msg->max_size);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb return AJP_ETOBIG;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb }
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb msg->len = msglen + AJP_HEADER_LEN;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb msg->pos = AJP_HEADER_LEN;
3d96ee83babeec32482c9082c9426340cee8c44dwrowe *len = msglen;
7bdef86e15d47d16dcbe7a5611683191774bd5fbgstein
61fd0cab072a05b855cbef9c585702401ac5ae29rbb return APR_SUCCESS;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb}
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/**
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * Reset an AJP Message
78ae1cbba5a848a24ca551629bbf0a90d2b931f0stas *
78ae1cbba5a848a24ca551629bbf0a90d2b931f0stas * @param msg AJP Message to reset
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * @return APR_SUCCESS or error
61fd0cab072a05b855cbef9c585702401ac5ae29rbb */
3d96ee83babeec32482c9082c9426340cee8c44dwroweapr_status_t ajp_msg_reset(ajp_msg_t *msg)
2d2eda71267231c2526be701fe655db125852c1ffielding{
2d2eda71267231c2526be701fe655db125852c1ffielding msg->len = AJP_HEADER_LEN;
2d2eda71267231c2526be701fe655db125852c1ffielding msg->pos = AJP_HEADER_LEN;
2d2eda71267231c2526be701fe655db125852c1ffielding
2d2eda71267231c2526be701fe655db125852c1ffielding return APR_SUCCESS;
2d2eda71267231c2526be701fe655db125852c1ffielding}
2d2eda71267231c2526be701fe655db125852c1ffielding
2d2eda71267231c2526be701fe655db125852c1ffielding/**
2d2eda71267231c2526be701fe655db125852c1ffielding * Reuse an AJP Message
2d2eda71267231c2526be701fe655db125852c1ffielding *
2d2eda71267231c2526be701fe655db125852c1ffielding * @param msg AJP Message to reuse
2d2eda71267231c2526be701fe655db125852c1ffielding * @return APR_SUCCESS or error
61fd0cab072a05b855cbef9c585702401ac5ae29rbb */
61fd0cab072a05b855cbef9c585702401ac5ae29rbbapr_status_t ajp_msg_reuse(ajp_msg_t *msg)
61fd0cab072a05b855cbef9c585702401ac5ae29rbb{
61fd0cab072a05b855cbef9c585702401ac5ae29rbb apr_byte_t *buf;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb apr_size_t max_size;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb buf = msg->buf;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb max_size = msg->max_size;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb memset(msg, 0, sizeof(ajp_msg_t));
61fd0cab072a05b855cbef9c585702401ac5ae29rbb msg->buf = buf;
3d96ee83babeec32482c9082c9426340cee8c44dwrowe msg->max_size = max_size;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm msg->header_len = AJP_HEADER_LEN;
7bdef86e15d47d16dcbe7a5611683191774bd5fbgstein ajp_msg_reset(msg);
23ff73a56371e21f16744cb94d06399b877829f1rbb return APR_SUCCESS;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb}
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/**
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * Mark the end of an AJP Message
61fd0cab072a05b855cbef9c585702401ac5ae29rbb *
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * @param msg AJP Message to end
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * @return APR_SUCCESS or error
61fd0cab072a05b855cbef9c585702401ac5ae29rbb */
61fd0cab072a05b855cbef9c585702401ac5ae29rbbapr_status_t ajp_msg_end(ajp_msg_t *msg)
3d96ee83babeec32482c9082c9426340cee8c44dwrowe{
2d2eda71267231c2526be701fe655db125852c1ffielding apr_size_t len = msg->len - AJP_HEADER_LEN;
23ff73a56371e21f16744cb94d06399b877829f1rbb
2d2eda71267231c2526be701fe655db125852c1ffielding if (msg->server_side) {
62db15de4c1f335a64d45821796ae197cff94ef8rbb msg->buf[0] = 0x41;
62db15de4c1f335a64d45821796ae197cff94ef8rbb msg->buf[1] = 0x42;
62db15de4c1f335a64d45821796ae197cff94ef8rbb }
62db15de4c1f335a64d45821796ae197cff94ef8rbb else {
62db15de4c1f335a64d45821796ae197cff94ef8rbb msg->buf[0] = 0x12;
62db15de4c1f335a64d45821796ae197cff94ef8rbb msg->buf[1] = 0x34;
62db15de4c1f335a64d45821796ae197cff94ef8rbb }
62db15de4c1f335a64d45821796ae197cff94ef8rbb
62db15de4c1f335a64d45821796ae197cff94ef8rbb msg->buf[2] = (apr_byte_t)((len >> 8) & 0xFF);
48d2edbfb84e5559b5da0f8d614ccab805cc67a8rbb msg->buf[3] = (apr_byte_t)(len & 0xFF);
62db15de4c1f335a64d45821796ae197cff94ef8rbb
62db15de4c1f335a64d45821796ae197cff94ef8rbb return APR_SUCCESS;
62db15de4c1f335a64d45821796ae197cff94ef8rbb}
62db15de4c1f335a64d45821796ae197cff94ef8rbb
62db15de4c1f335a64d45821796ae197cff94ef8rbbstatic APR_INLINE int ajp_log_overflow(ajp_msg_t *msg, const char *context)
62db15de4c1f335a64d45821796ae197cff94ef8rbb{
62db15de4c1f335a64d45821796ae197cff94ef8rbb ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL,
62db15de4c1f335a64d45821796ae197cff94ef8rbb "%s(): BufferOverflowException %" APR_SIZE_T_FMT
62db15de4c1f335a64d45821796ae197cff94ef8rbb " %" APR_SIZE_T_FMT,
62db15de4c1f335a64d45821796ae197cff94ef8rbb context, msg->pos, msg->len);
62db15de4c1f335a64d45821796ae197cff94ef8rbb return AJP_EOVERFLOW;
62db15de4c1f335a64d45821796ae197cff94ef8rbb}
48d2edbfb84e5559b5da0f8d614ccab805cc67a8rbb
48d2edbfb84e5559b5da0f8d614ccab805cc67a8rbb/**
62db15de4c1f335a64d45821796ae197cff94ef8rbb * Add an unsigned 32bits value to AJP Message
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar *
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar * @param msg AJP Message to get value from
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar * @param value value to add to AJP Message
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar * @return APR_SUCCESS or error
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar */
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coarapr_status_t ajp_msg_append_uint32(ajp_msg_t *msg, apr_uint32_t value)
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar{
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar apr_size_t len = msg->len;
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar if ((len + 4) > msg->max_size) {
3d96ee83babeec32482c9082c9426340cee8c44dwrowe return ajp_log_overflow(msg, "ajp_msg_append_uint32");
3d96ee83babeec32482c9082c9426340cee8c44dwrowe }
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar
3d96ee83babeec32482c9082c9426340cee8c44dwrowe msg->buf[len] = (apr_byte_t)((value >> 24) & 0xFF);
a19698aebe10b9d41574e4a73794ba7d4cecd78btrawick msg->buf[len + 1] = (apr_byte_t)((value >> 16) & 0xFF);
a19698aebe10b9d41574e4a73794ba7d4cecd78btrawick msg->buf[len + 2] = (apr_byte_t)((value >> 8) & 0xFF);
a19698aebe10b9d41574e4a73794ba7d4cecd78btrawick msg->buf[len + 3] = (apr_byte_t)(value & 0xFF);
3d96ee83babeec32482c9082c9426340cee8c44dwrowe
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar msg->len += 4;
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar return APR_SUCCESS;
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar}
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar/**
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar * Add an unsigned 16bits value to AJP Message
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar *
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar * @param msg AJP Message to get value from
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar * @param value value to add to AJP Message
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar * @return APR_SUCCESS or error
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar */
3d96ee83babeec32482c9082c9426340cee8c44dwroweapr_status_t ajp_msg_append_uint16(ajp_msg_t *msg, apr_uint16_t value)
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar{
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar apr_size_t len = msg->len;
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar if ((len + 2) > msg->max_size) {
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar return ajp_log_overflow(msg, "ajp_msg_append_uint16");
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar }
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar msg->buf[len] = (apr_byte_t)((value >> 8) & 0xFF);
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar msg->buf[len + 1] = (apr_byte_t)(value & 0xFF);
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar
3d96ee83babeec32482c9082c9426340cee8c44dwrowe msg->len += 2;
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar return APR_SUCCESS;
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar}
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar/**
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar * Add an unsigned 8bits value to AJP Message
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar *
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar * @param msg AJP Message to get value from
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar * @param value value to add to AJP Message
3d96ee83babeec32482c9082c9426340cee8c44dwrowe * @return APR_SUCCESS or error
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar */
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coarapr_status_t ajp_msg_append_uint8(ajp_msg_t *msg, apr_byte_t value)
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar{
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar apr_size_t len = msg->len;
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar if ((len + 1) > msg->max_size) {
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar return ajp_log_overflow(msg, "ajp_msg_append_uint8");
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar }
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar
3d96ee83babeec32482c9082c9426340cee8c44dwrowe msg->buf[len] = value;
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar msg->len += 1;
2864362ca8266097928e84f101010bdf814ffa08stoddard
db08da9ddcd65c31f9ea44b823898b72a1b24fbestoddard return APR_SUCCESS;
db08da9ddcd65c31f9ea44b823898b72a1b24fbestoddard}
bf648cbfa4a723c9c02fe8444103cd41ed8642d0wrowe
db08da9ddcd65c31f9ea44b823898b72a1b24fbestoddard/**
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
2864362ca8266097928e84f101010bdf814ffa08stoddard *
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
2d2eda71267231c2526be701fe655db125852c1ffielding */
2d2eda71267231c2526be701fe655db125852c1ffieldingapr_status_t ajp_msg_append_string_ex(ajp_msg_t *msg, const char *value,
61fd0cab072a05b855cbef9c585702401ac5ae29rbb int convert)
61fd0cab072a05b855cbef9c585702401ac5ae29rbb{
61fd0cab072a05b855cbef9c585702401ac5ae29rbb apr_size_t len;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb if (value == NULL) {
61fd0cab072a05b855cbef9c585702401ac5ae29rbb return(ajp_msg_append_uint16(msg, 0xFFFF));
61fd0cab072a05b855cbef9c585702401ac5ae29rbb }
3d96ee83babeec32482c9082c9426340cee8c44dwrowe
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgstein len = strlen(value);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb if ((msg->len + len + 3) > msg->max_size) {
61fd0cab072a05b855cbef9c585702401ac5ae29rbb return ajp_log_overflow(msg, "ajp_msg_append_cvt_string");
61fd0cab072a05b855cbef9c585702401ac5ae29rbb }
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb /* ignore error - we checked once */
aecb17a45c6d3ee4729ed5f68dc4270f211ee7a8fielding ajp_msg_append_uint16(msg, (apr_uint16_t)len);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
aecb17a45c6d3ee4729ed5f68dc4270f211ee7a8fielding /* We checked for space !! */
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgstein memcpy(msg->buf + msg->len, value, len + 1); /* including \0 */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb if (convert) {
61fd0cab072a05b855cbef9c585702401ac5ae29rbb /* convert from EBCDIC if needed */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb ap_xlate_proto_to_ascii((char *)msg->buf + msg->len, len + 1);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb }
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb msg->len += len + 1;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
3d96ee83babeec32482c9082c9426340cee8c44dwrowe return APR_SUCCESS;
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgstein}
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/**
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * Add a Byte array to AJP Message
61fd0cab072a05b855cbef9c585702401ac5ae29rbb *
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
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgstein */
61fd0cab072a05b855cbef9c585702401ac5ae29rbbapr_status_t ajp_msg_append_bytes(ajp_msg_t *msg, const apr_byte_t *value,
61fd0cab072a05b855cbef9c585702401ac5ae29rbb apr_size_t valuelen)
61fd0cab072a05b855cbef9c585702401ac5ae29rbb{
61fd0cab072a05b855cbef9c585702401ac5ae29rbb if (! valuelen) {
61fd0cab072a05b855cbef9c585702401ac5ae29rbb return APR_SUCCESS; /* Shouldn't we indicate an error ? */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb }
aecb17a45c6d3ee4729ed5f68dc4270f211ee7a8fielding
61fd0cab072a05b855cbef9c585702401ac5ae29rbb if ((msg->len + valuelen) > msg->max_size) {
aecb17a45c6d3ee4729ed5f68dc4270f211ee7a8fielding return ajp_log_overflow(msg, "ajp_msg_append_bytes");
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgstein }
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb /* We checked for space !! */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb memcpy(msg->buf + msg->len, value, valuelen);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb msg->len += valuelen;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb return APR_SUCCESS;
aecb17a45c6d3ee4729ed5f68dc4270f211ee7a8fielding}
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
aecb17a45c6d3ee4729ed5f68dc4270f211ee7a8fielding/**
2d2eda71267231c2526be701fe655db125852c1ffielding * Get a 32bits unsigned value from AJP Message
61fd0cab072a05b855cbef9c585702401ac5ae29rbb *
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * @param msg AJP Message to get value from
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * @param rvalue Pointer where value will be returned
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * @return APR_SUCCESS or error
61fd0cab072a05b855cbef9c585702401ac5ae29rbb */
61fd0cab072a05b855cbef9c585702401ac5ae29rbbapr_status_t ajp_msg_get_uint32(ajp_msg_t *msg, apr_uint32_t *rvalue)
3d96ee83babeec32482c9082c9426340cee8c44dwrowe{
2d2eda71267231c2526be701fe655db125852c1ffielding apr_uint32_t value;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
2d2eda71267231c2526be701fe655db125852c1ffielding if ((msg->pos + 3) > msg->len) {
2d2eda71267231c2526be701fe655db125852c1ffielding return ajp_log_overflow(msg, "ajp_msg_get_uint32");
61fd0cab072a05b855cbef9c585702401ac5ae29rbb }
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb value = ((msg->buf[(msg->pos++)] & 0xFF) << 24);
2d2eda71267231c2526be701fe655db125852c1ffielding value |= ((msg->buf[(msg->pos++)] & 0xFF) << 16);
3d96ee83babeec32482c9082c9426340cee8c44dwrowe value |= ((msg->buf[(msg->pos++)] & 0xFF) << 8);
2d2eda71267231c2526be701fe655db125852c1ffielding value |= ((msg->buf[(msg->pos++)] & 0xFF));
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
d839a9822ee53ce00da24c15f2d9fe054233d342gstein *rvalue = value;
d839a9822ee53ce00da24c15f2d9fe054233d342gstein return APR_SUCCESS;
d839a9822ee53ce00da24c15f2d9fe054233d342gstein}
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/**
d839a9822ee53ce00da24c15f2d9fe054233d342gstein * Get a 16bits unsigned value from AJP Message
3d96ee83babeec32482c9082c9426340cee8c44dwrowe *
d839a9822ee53ce00da24c15f2d9fe054233d342gstein * @param msg AJP Message to get value from
2d2eda71267231c2526be701fe655db125852c1ffielding * @param rvalue Pointer where value will be returned
2d2eda71267231c2526be701fe655db125852c1ffielding * @return APR_SUCCESS or error
61fd0cab072a05b855cbef9c585702401ac5ae29rbb */
61fd0cab072a05b855cbef9c585702401ac5ae29rbbapr_status_t ajp_msg_get_uint16(ajp_msg_t *msg, apr_uint16_t *rvalue)
61fd0cab072a05b855cbef9c585702401ac5ae29rbb{
61fd0cab072a05b855cbef9c585702401ac5ae29rbb apr_uint16_t value;
346029f34d03eb20d84fc35664426d3874b00f9ewrowe
61fd0cab072a05b855cbef9c585702401ac5ae29rbb if ((msg->pos + 1) > msg->len) {
61fd0cab072a05b855cbef9c585702401ac5ae29rbb return ajp_log_overflow(msg, "ajp_msg_get_uint16");
61fd0cab072a05b855cbef9c585702401ac5ae29rbb }
346029f34d03eb20d84fc35664426d3874b00f9ewrowe
61fd0cab072a05b855cbef9c585702401ac5ae29rbb value = ((msg->buf[(msg->pos++)] & 0xFF) << 8);
eda25307d712abd132e100e2b40ae1de5497d3e2trawick value += ((msg->buf[(msg->pos++)] & 0xFF));
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
3d96ee83babeec32482c9082c9426340cee8c44dwrowe *rvalue = value;
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgstein return APR_SUCCESS;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb}
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
face099b681c052cb1f52176a5499661c44b2982trawick/**
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * Peek a 16bits unsigned value from AJP Message, position in message
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * is not updated
61fd0cab072a05b855cbef9c585702401ac5ae29rbb *
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * @param msg AJP Message to get value from
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * @param rvalue Pointer where value will be returned
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * @return APR_SUCCESS or error
3d96ee83babeec32482c9082c9426340cee8c44dwrowe */
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgsteinapr_status_t ajp_msg_peek_uint16(ajp_msg_t *msg, apr_uint16_t *rvalue)
61fd0cab072a05b855cbef9c585702401ac5ae29rbb{
61fd0cab072a05b855cbef9c585702401ac5ae29rbb apr_uint16_t value;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb if ((msg->pos + 1) > msg->len) {
61fd0cab072a05b855cbef9c585702401ac5ae29rbb return ajp_log_overflow(msg, "ajp_msg_peek_uint16");
61fd0cab072a05b855cbef9c585702401ac5ae29rbb }
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb value = ((msg->buf[(msg->pos)] & 0xFF) << 8);
aecb17a45c6d3ee4729ed5f68dc4270f211ee7a8fielding value += ((msg->buf[(msg->pos + 1)] & 0xFF));
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
aecb17a45c6d3ee4729ed5f68dc4270f211ee7a8fielding *rvalue = value;
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgstein return APR_SUCCESS;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb}
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/**
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * Peek a 8bits unsigned value from AJP Message, position in message
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * is not updated
61fd0cab072a05b855cbef9c585702401ac5ae29rbb *
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * @param msg AJP Message to get value from
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * @param rvalue Pointer where value will be returned
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * @return APR_SUCCESS or error
61fd0cab072a05b855cbef9c585702401ac5ae29rbb */
61fd0cab072a05b855cbef9c585702401ac5ae29rbbapr_status_t ajp_msg_peek_uint8(ajp_msg_t *msg, apr_byte_t *rvalue)
3d96ee83babeec32482c9082c9426340cee8c44dwrowe{
2d2eda71267231c2526be701fe655db125852c1ffielding if (msg->pos > msg->len) {
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgstein return ajp_log_overflow(msg, "ajp_msg_peek_uint8");
61fd0cab072a05b855cbef9c585702401ac5ae29rbb }
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb *rvalue = msg->buf[msg->pos];
61fd0cab072a05b855cbef9c585702401ac5ae29rbb return APR_SUCCESS;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb}
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/**
3d96ee83babeec32482c9082c9426340cee8c44dwrowe * Get a 8bits unsigned value from AJP Message
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgstein *
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * @param msg AJP Message to get value from
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * @param rvalue Pointer where value will be returned
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * @return APR_SUCCESS or error
61fd0cab072a05b855cbef9c585702401ac5ae29rbb */
61fd0cab072a05b855cbef9c585702401ac5ae29rbbapr_status_t ajp_msg_get_uint8(ajp_msg_t *msg, apr_byte_t *rvalue)
61fd0cab072a05b855cbef9c585702401ac5ae29rbb{
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
3d96ee83babeec32482c9082c9426340cee8c44dwrowe if (msg->pos > msg->len) {
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgstein return ajp_log_overflow(msg, "ajp_msg_get_uint8");
61fd0cab072a05b855cbef9c585702401ac5ae29rbb }
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb *rvalue = msg->buf[msg->pos++];
61fd0cab072a05b855cbef9c585702401ac5ae29rbb return APR_SUCCESS;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb}
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
3d96ee83babeec32482c9082c9426340cee8c44dwrowe/**
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgstein * Get a String value from AJP Message
61fd0cab072a05b855cbef9c585702401ac5ae29rbb *
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * @param msg AJP Message to get value from
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * @param rvalue Pointer where value will be returned
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * @return APR_SUCCESS or error
61fd0cab072a05b855cbef9c585702401ac5ae29rbb */
94d240fc213d4a96160d7014633374cc22a204d8trawickapr_status_t ajp_msg_get_string(ajp_msg_t *msg, const char **rvalue)
61fd0cab072a05b855cbef9c585702401ac5ae29rbb{
61fd0cab072a05b855cbef9c585702401ac5ae29rbb apr_uint16_t size;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb apr_size_t start;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb apr_status_t status;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb status = ajp_msg_get_uint16(msg, &size);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb start = msg->pos;
3d96ee83babeec32482c9082c9426340cee8c44dwrowe
2d2eda71267231c2526be701fe655db125852c1ffielding if ((status != APR_SUCCESS) || (size + start > msg->max_size)) {
61fd0cab072a05b855cbef9c585702401ac5ae29rbb return ajp_log_overflow(msg, "ajp_msg_get_string");
61fd0cab072a05b855cbef9c585702401ac5ae29rbb }
346029f34d03eb20d84fc35664426d3874b00f9ewrowe
61fd0cab072a05b855cbef9c585702401ac5ae29rbb msg->pos += (apr_size_t)size;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb msg->pos++; /* a String in AJP is NULL terminated */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
346029f34d03eb20d84fc35664426d3874b00f9ewrowe *rvalue = (const char *)(msg->buf + start);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb return APR_SUCCESS;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb}
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
3d96ee83babeec32482c9082c9426340cee8c44dwrowe/**
2d2eda71267231c2526be701fe655db125852c1ffielding * Get a Byte array from AJP Message
fd8b91502bc200ed4cca3810560a2a570522b3debrianp *
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
fd8b91502bc200ed4cca3810560a2a570522b3debrianp */
fd8b91502bc200ed4cca3810560a2a570522b3debrianpapr_status_t ajp_msg_get_bytes(ajp_msg_t *msg, apr_byte_t **rvalue,
fd8b91502bc200ed4cca3810560a2a570522b3debrianp apr_size_t *rvalue_len)
fd8b91502bc200ed4cca3810560a2a570522b3debrianp{
fd8b91502bc200ed4cca3810560a2a570522b3debrianp apr_uint16_t size;
fd8b91502bc200ed4cca3810560a2a570522b3debrianp apr_size_t start;
aa4af3da5c68fe5dbd9d2c3fd7b2fe7103daa2b7dougm apr_status_t status;
e351a4349a3dcc2e8d9c27bcdf72414bdde0942frbb
fd8b91502bc200ed4cca3810560a2a570522b3debrianp status = ajp_msg_get_uint16(msg, &size);
fd8b91502bc200ed4cca3810560a2a570522b3debrianp /* save the current position */
4111de96e9f75c58e77c2bdda23be83b8ebf81ccgregames start = msg->pos;
4111de96e9f75c58e77c2bdda23be83b8ebf81ccgregames
4111de96e9f75c58e77c2bdda23be83b8ebf81ccgregames if ((status != APR_SUCCESS) || (size + start > msg->max_size)) {
4111de96e9f75c58e77c2bdda23be83b8ebf81ccgregames return ajp_log_overflow(msg, "ajp_msg_get_bytes");
4111de96e9f75c58e77c2bdda23be83b8ebf81ccgregames }
4111de96e9f75c58e77c2bdda23be83b8ebf81ccgregames msg->pos += (apr_size_t)size; /* only bytes, no trailer */
4111de96e9f75c58e77c2bdda23be83b8ebf81ccgregames
4111de96e9f75c58e77c2bdda23be83b8ebf81ccgregames *rvalue = msg->buf + start;
fd8b91502bc200ed4cca3810560a2a570522b3debrianp *rvalue_len = size;
fd8b91502bc200ed4cca3810560a2a570522b3debrianp
fd8b91502bc200ed4cca3810560a2a570522b3debrianp return APR_SUCCESS;
fd8b91502bc200ed4cca3810560a2a570522b3debrianp}
45613d36b9466a48def0498cffa07f48980720f8jerenkrantz
fd8b91502bc200ed4cca3810560a2a570522b3debrianp
fd8b91502bc200ed4cca3810560a2a570522b3debrianp/**
50e60f30bdc074fbc887f0b98f4d570457ac97c9brianp * Create an AJP Message from pool
45613d36b9466a48def0498cffa07f48980720f8jerenkrantz *
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
4111de96e9f75c58e77c2bdda23be83b8ebf81ccgregames */
4111de96e9f75c58e77c2bdda23be83b8ebf81ccgregamesapr_status_t ajp_msg_create(apr_pool_t *pool, apr_size_t size, ajp_msg_t **rmsg)
50e60f30bdc074fbc887f0b98f4d570457ac97c9brianp{
50e60f30bdc074fbc887f0b98f4d570457ac97c9brianp ajp_msg_t *msg = (ajp_msg_t *)apr_pcalloc(pool, sizeof(ajp_msg_t));
4111de96e9f75c58e77c2bdda23be83b8ebf81ccgregames
50e60f30bdc074fbc887f0b98f4d570457ac97c9brianp msg->server_side = 0;
50e60f30bdc074fbc887f0b98f4d570457ac97c9brianp
4111de96e9f75c58e77c2bdda23be83b8ebf81ccgregames msg->buf = (apr_byte_t *)apr_palloc(pool, size);
4111de96e9f75c58e77c2bdda23be83b8ebf81ccgregames msg->len = 0;
4111de96e9f75c58e77c2bdda23be83b8ebf81ccgregames msg->header_len = AJP_HEADER_LEN;
50e60f30bdc074fbc887f0b98f4d570457ac97c9brianp msg->max_size = size;
50e60f30bdc074fbc887f0b98f4d570457ac97c9brianp *rmsg = msg;
5a9667916c79d8c699b069068e5570aa1c331c80gstein
61fd0cab072a05b855cbef9c585702401ac5ae29rbb return APR_SUCCESS;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb}
2d2eda71267231c2526be701fe655db125852c1ffielding
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/**
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * Recopy an AJP Message to another
2d2eda71267231c2526be701fe655db125852c1ffielding *
3d96ee83babeec32482c9082c9426340cee8c44dwrowe * @param smsg source AJP message
2d2eda71267231c2526be701fe655db125852c1ffielding * @param dmsg destination AJP message
344f3bc38dfccf6261d5bb8d689794cde113b3d6coar * @return APR_SUCCESS or error
344f3bc38dfccf6261d5bb8d689794cde113b3d6coar */
344f3bc38dfccf6261d5bb8d689794cde113b3d6coarapr_status_t ajp_msg_copy(ajp_msg_t *smsg, ajp_msg_t *dmsg)
5a9667916c79d8c699b069068e5570aa1c331c80gstein{
344f3bc38dfccf6261d5bb8d689794cde113b3d6coar if (smsg->len > smsg->max_size) {
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,
344f3bc38dfccf6261d5bb8d689794cde113b3d6coar smsg->len, smsg->max_size);
d5df46b7972c0c4a5ca0ba5068e238f6053c2e6ftrawick return AJP_ETOSMALL;
fd0edaa8e3d4dd67d0604ccef2e96b071db96643fielding }
fd0edaa8e3d4dd67d0604ccef2e96b071db96643fielding
fd0edaa8e3d4dd67d0604ccef2e96b071db96643fielding memcpy(dmsg->buf, smsg->buf, smsg->len);
fd0edaa8e3d4dd67d0604ccef2e96b071db96643fielding dmsg->len = smsg->len;
fd0edaa8e3d4dd67d0604ccef2e96b071db96643fielding dmsg->pos = smsg->pos;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb return APR_SUCCESS;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb}
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/**
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * Serialize in an AJP Message a PING command
61fd0cab072a05b855cbef9c585702401ac5ae29rbb *
42ce672c516baf6e4eaed18ccc1647de2d456d8edougm * +-----------------------+
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgstein * | PING CMD (1 byte) |
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * +-----------------------+
61fd0cab072a05b855cbef9c585702401ac5ae29rbb *
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * @param smsg AJP message to put serialized message
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * @return APR_SUCCESS or error
61fd0cab072a05b855cbef9c585702401ac5ae29rbb */
61fd0cab072a05b855cbef9c585702401ac5ae29rbbapr_status_t ajp_msg_serialize_ping(ajp_msg_t *msg)
61fd0cab072a05b855cbef9c585702401ac5ae29rbb{
42ce672c516baf6e4eaed18ccc1647de2d456d8edougm apr_status_t rc;
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgstein ajp_msg_reset(msg);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb if ((rc = ajp_msg_append_uint8(msg, CMD_AJP13_PING)) != APR_SUCCESS)
61fd0cab072a05b855cbef9c585702401ac5ae29rbb return rc;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb return APR_SUCCESS;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb}
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
42ce672c516baf6e4eaed18ccc1647de2d456d8edougm/**
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgstein * Serialize in an AJP Message a CPING command
61fd0cab072a05b855cbef9c585702401ac5ae29rbb *
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * +-----------------------+
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * | CPING CMD (1 byte) |
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * +-----------------------+
dad234382d8424e1c5a30af2838e172aec9d6d1bdreid *
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * @param smsg AJP message to put serialized message
42ce672c516baf6e4eaed18ccc1647de2d456d8edougm * @return APR_SUCCESS or error
fd0edaa8e3d4dd67d0604ccef2e96b071db96643fielding */
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbbapr_status_t ajp_msg_serialize_cping(ajp_msg_t *msg)
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgstein{
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbb apr_status_t rc;
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbb ajp_msg_reset(msg);
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbb
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbb if ((rc = ajp_msg_append_uint8(msg, CMD_AJP13_CPING)) != APR_SUCCESS)
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbb return rc;
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbb
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbb return APR_SUCCESS;
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbb}
0de8f88b22d24dd57ed10b96fb594e69b6aa0072jwoolley