Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
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
00130
00131
00132
00133
00134
00135
00136
00137
00138
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
00152
00153
00154
00155
00156
00157
00158
00159
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
00170
00171
00172
00173 for (int i = 0; i < HDR_BUF_RONLY_HEAPS; i++) {
00174 if (m_ronly_heap[i].m_heap_start == NULL) {
00175
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
00180
00181
00182
00183 return i;
00184 } else if (m_ronly_heap[i].m_heap_start == b->buf()) {
00185
00186
00187 m_ronly_heap[i].m_heap_len = (int) (b->end() - b->buf());
00188
00189
00190
00191
00192 return i;
00193 }
00194 }
00195
00196
00197 coalesce_str_heaps();
00198 goto RETRY;
00199 }