• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

HdrTSOnly.cc

Go to the documentation of this file.
00001 /** @file
00002 
00003   A brief file description
00004 
00005   @section license License
00006 
00007   Licensed to the Apache Software Foundation (ASF) under one
00008   or more contributor license agreements.  See the NOTICE file
00009   distributed with this work for additional information
00010   regarding copyright ownership.  The ASF licenses this file
00011   to you under the Apache License, Version 2.0 (the
00012   "License"); you may not use this file except in compliance
00013   with the License.  You may obtain a copy of the License at
00014 
00015       http://www.apache.org/licenses/LICENSE-2.0
00016 
00017   Unless required by applicable law or agreed to in writing, software
00018   distributed under the License is distributed on an "AS IS" BASIS,
00019   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00020   See the License for the specific language governing permissions and
00021   limitations under the License.
00022  */
00023 
00024 /****************************************************************************
00025 
00026    HdrTSOnly.cc
00027 
00028    Description:
00029       IRIX compiler is rather annoying and likes to use symbols from inline
00030         code that is not called in the file.  Thus to make our libhdrs.a
00031         library link with traffic_manager and test_header, we can't
00032         include IOBuffer.h in any file where the corresponding object file
00033         gets linked in for these two targets.  Thus HdrTSOnly.cc is where
00034         we put the functions that only traffic_server uses since they
00035         need to know about IOBuffers.
00036 
00037 
00038  ****************************************************************************/
00039 
00040 #include "libts.h"
00041 #include "HTTP.h"
00042 #include "P_EventSystem.h"
00043 
00044 /*-------------------------------------------------------------------------
00045   -------------------------------------------------------------------------*/
00046 
00047 MIMEParseResult
00048 HTTPHdr::parse_req(HTTPParser * parser, IOBufferReader * r, int *bytes_used, bool eof)
00049 {
00050 
00051   const char *start;
00052   const char *tmp;
00053   const char *end;
00054   int used;
00055 
00056   ink_assert(valid());
00057   ink_assert(m_http->m_polarity == HTTP_TYPE_REQUEST);
00058 
00059   MIMEParseResult state = PARSE_CONT;
00060   *bytes_used = 0;
00061 
00062 
00063   do {
00064     int64_t b_avail = r->block_read_avail();
00065 
00066     if (b_avail <= 0 && eof == false) {
00067       break;
00068     }
00069 
00070     tmp = start = r->start();
00071     end = start + b_avail;
00072 
00073     int heap_slot = m_heap->attach_block(r->get_current_block(), start);
00074 
00075     m_heap->lock_ronly_str_heap(heap_slot);
00076     state = http_parser_parse_req(parser, m_heap, m_http, &tmp, end, false, eof);
00077     m_heap->set_ronly_str_heap_end(heap_slot, tmp);
00078     m_heap->unlock_ronly_str_heap(heap_slot);
00079 
00080     used = (int) (tmp - start);
00081     r->consume(used);
00082     *bytes_used += used;
00083 
00084   } while (state == PARSE_CONT);
00085 
00086   return state;
00087 }
00088 
00089 MIMEParseResult
00090 HTTPHdr::parse_resp(HTTPParser * parser, IOBufferReader * r, int *bytes_used, bool eof)
00091 {
00092   const char *start;
00093   const char *tmp;
00094   const char *end;
00095   int used;
00096 
00097   ink_assert(valid());
00098   ink_assert(m_http->m_polarity == HTTP_TYPE_RESPONSE);
00099 
00100   MIMEParseResult state = PARSE_CONT;
00101   *bytes_used = 0;
00102 
00103   do {
00104     int64_t b_avail = r->block_read_avail();
00105 
00106     if (b_avail <= 0 && eof == false) {
00107       break;
00108     }
00109 
00110     tmp = start = r->start();
00111     end = start + b_avail;
00112 
00113     int heap_slot = m_heap->attach_block(r->get_current_block(), start);
00114 
00115     m_heap->lock_ronly_str_heap(heap_slot);
00116     state = http_parser_parse_resp(parser, m_heap, m_http, &tmp, end, false, eof);
00117     m_heap->set_ronly_str_heap_end(heap_slot, tmp);
00118     m_heap->unlock_ronly_str_heap(heap_slot);
00119 
00120     used = (int) (tmp - start);
00121     r->consume(used);
00122     *bytes_used += used;
00123 
00124   } while (state == PARSE_CONT);
00125 
00126   return state;
00127 }
00128 
00129 // void HdrHeap::set_ronly_str_heap_end(int slot)
00130 //
00131 //    The end pointer is where the header parser stopped parsing
00132 //      so that we don't get extraneous space in the block
00133 //      that then has to get marshalled (INKqa07409)
00134 //
00135 //    NOTE: the shortening the block relies on the fact that
00136 //      IOBuffers are write once.  It's therefore not possible
00137 //      that a previous call actually used more the block than
00138 //      the current call which would mean we can't shorten the block
00139 //
00140 void
00141 HdrHeap::set_ronly_str_heap_end(int slot, const char *end)
00142 {
00143   ink_assert(m_ronly_heap[slot].m_heap_start != NULL);
00144   ink_assert(m_ronly_heap[slot].m_heap_start <= end);
00145   ink_assert(end <= m_ronly_heap[slot].m_heap_start + m_ronly_heap[slot].m_heap_len);
00146 
00147   m_ronly_heap[slot].m_heap_len = (int) (end - m_ronly_heap[slot].m_heap_start);
00148 }
00149 
00150 
00151 // void HdrHeap::attach_block(IOBufferBlock* b, const char* use_start)
00152 //
00153 //    Attachs data from an IOBuffer block to
00154 //      as a read-only string heap.  Looks through existing
00155 //      to expand an existing string heap entry if necessary
00156 //
00157 //    Because the block may contain data at the front of it that
00158 //      we don't want (and will end up getting marshalled)
00159 //      use_start specificies where we start using the block (INKqa07409)
00160 //
00161 int
00162 HdrHeap::attach_block(IOBufferBlock * b, const char *use_start)
00163 {
00164 
00165   ink_assert(m_writeable);
00166 
00167 RETRY:
00168 
00169   // It's my contention that since heaps are add to the
00170   //   first available slot, one you find an empty slot
00171   //   it's not possible that a heap ptr for this block
00172   //   exists in a later slot
00173   for (int i = 0; i < HDR_BUF_RONLY_HEAPS; i++) {
00174     if (m_ronly_heap[i].m_heap_start == NULL) {
00175       // Add block to heap in this slot
00176       m_ronly_heap[i].m_heap_start = (char *) use_start;
00177       m_ronly_heap[i].m_heap_len = (int) (b->end() - b->start());
00178       m_ronly_heap[i].m_ref_count_ptr = b->data;
00179 //          printf("Attaching block at %X for %d in slot %d\n",
00180 //                 m_ronly_heap[i].m_heap_start,
00181 //                 m_ronly_heap[i].m_heap_len,
00182 //                 i);
00183       return i;
00184     } else if (m_ronly_heap[i].m_heap_start == b->buf()) {
00185       // This block is already on the heap so just extend
00186       //   it's range
00187       m_ronly_heap[i].m_heap_len = (int) (b->end() - b->buf());
00188 //          printf("Extending block at %X to %d in slot %d\n",
00189 //                 m_ronly_heap[i].m_heap_start,
00190 //                 m_ronly_heap[i].m_heap_len,
00191 //                 i);
00192       return i;
00193     }
00194   }
00195 
00196   // We didn't find an open block slot so we'll have to create one
00197   coalesce_str_heaps();
00198   goto RETRY;
00199 }

Generated by  doxygen 1.7.1