~ubuntu-branches/ubuntu/wily/trafficserver/wily

« back to all changes in this revision

Viewing changes to proxy/hdrs/HTTP.cc

  • Committer: Package Import Robot
  • Author(s): Adam Conrad
  • Date: 2012-12-17 22:28:16 UTC
  • mfrom: (5.1.8 raring-proposed)
  • Revision ID: package-import@ubuntu.com-20121217222816-7xwjsx5k76zkb63d
Tags: 3.2.0-1ubuntu1
* Revert FreeBSD strerror_r() fixes that give errors with glibc 2.16.
* Apply patch from Konstantinos Margaritis to define barriers on ARM.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
  limitations under the License.
22
22
 */
23
23
 
 
24
#include "ink_port.h"
24
25
#include "libts.h"
25
26
#include <assert.h>
26
27
#include <stdio.h>
162
163
 ***********************************************************************/
163
164
 
164
165
void
165
 
http_hdr_adjust(HTTPHdrImpl * hdrp, int32_t offset, int32_t length, int32_t delta)
 
166
http_hdr_adjust(HTTPHdrImpl *hdrp, int32_t offset, int32_t length, int32_t delta)
166
167
{
167
168
  NOWARN_UNUSED(hdrp);
168
169
  NOWARN_UNUSED(offset);
294
295
  -------------------------------------------------------------------------*/
295
296
 
296
297
HTTPHdrImpl *
297
 
http_hdr_create(HdrHeap * heap, HTTPType polarity)
 
298
http_hdr_create(HdrHeap *heap, HTTPType polarity)
298
299
{
299
300
  HTTPHdrImpl *hh;
300
301
 
307
308
  -------------------------------------------------------------------------*/
308
309
 
309
310
void
310
 
http_hdr_init(HdrHeap * heap, HTTPHdrImpl * hh, HTTPType polarity)
 
311
http_hdr_init(HdrHeap *heap, HTTPHdrImpl *hh, HTTPType polarity)
311
312
{
312
313
  memset(&(hh->u), 0, sizeof(hh->u));
313
314
  hh->m_polarity = polarity;
323
324
  -------------------------------------------------------------------------*/
324
325
 
325
326
void
326
 
http_hdr_copy_onto(HTTPHdrImpl * s_hh, HdrHeap * s_heap, HTTPHdrImpl * d_hh, HdrHeap * d_heap, bool inherit_strs)
 
327
http_hdr_copy_onto(HTTPHdrImpl *s_hh, HdrHeap *s_heap, HTTPHdrImpl *d_hh, HdrHeap *d_heap, bool inherit_strs)
327
328
{
328
329
  MIMEHdrImpl *s_mh, *d_mh;
329
330
  URLImpl *s_url, *d_url;
363
364
  -------------------------------------------------------------------------*/
364
365
 
365
366
HTTPHdrImpl *
366
 
http_hdr_clone(HTTPHdrImpl * s_hh, HdrHeap * s_heap, HdrHeap * d_heap)
 
367
http_hdr_clone(HTTPHdrImpl *s_hh, HdrHeap *s_heap, HdrHeap *d_heap)
367
368
{
368
369
  HTTPHdrImpl *d_hh;
369
370
 
418
419
  -------------------------------------------------------------------------*/
419
420
 
420
421
int
421
 
http_hdr_print(HdrHeap * heap, HTTPHdrImpl * hdr, char *buf, int bufsize, int *bufindex, int *dumpoffset)
 
422
http_hdr_print(HdrHeap *heap, HTTPHdrImpl *hdr, char *buf, int bufsize, int *bufindex, int *dumpoffset)
422
423
{
423
424
#define TRY(x)  if (!x) return 0
424
425
 
559
560
  -------------------------------------------------------------------------*/
560
561
 
561
562
void
562
 
http_hdr_describe(HdrHeapObjImpl * raw, bool recurse)
 
563
http_hdr_describe(HdrHeapObjImpl *raw, bool recurse)
563
564
{
564
565
  HTTPHdrImpl *obj = (HTTPHdrImpl *) raw;
565
566
 
566
567
  if (obj->m_polarity == HTTP_TYPE_REQUEST) {
567
 
    Debug("http", "[TYPE: REQ, V: %04X, URL: 0x%04X, METHOD: \"%.*s\", METHOD_LEN: %d, FIELDS: 0x%04X]\n",
 
568
    Debug("http", "[TYPE: REQ, V: %04X, URL: %p, METHOD: \"%.*s\", METHOD_LEN: %d, FIELDS: %p]\n",
568
569
          obj->m_version, obj->u.req.m_url_impl,
569
570
          obj->u.req.m_len_method, (obj->u.req.m_ptr_method ? obj->u.req.m_ptr_method : "NULL"),
570
571
          obj->u.req.m_len_method, obj->m_fields_impl);
575
576
        obj_describe(obj->m_fields_impl, recurse);
576
577
    }
577
578
  } else {
578
 
    Debug("http", "[TYPE: RSP, V: %04X, STATUS: %d, REASON: \"%.*s\", REASON_LEN: %d, FIELDS: 0x%04X]\n",
 
579
    Debug("http", "[TYPE: RSP, V: %04X, STATUS: %d, REASON: \"%.*s\", REASON_LEN: %d, FIELDS: %p]\n",
579
580
          obj->m_version, obj->u.resp.m_status,
580
581
          obj->u.resp.m_len_reason, (obj->u.resp.m_ptr_reason ? obj->u.resp.m_ptr_reason : "NULL"),
581
582
          obj->u.resp.m_len_reason, obj->m_fields_impl);
590
591
  -------------------------------------------------------------------------*/
591
592
 
592
593
int
593
 
http_hdr_length_get(HTTPHdrImpl * hdr)
 
594
http_hdr_length_get(HTTPHdrImpl *hdr)
594
595
{
595
596
  int length = 0;
596
597
 
641
642
  -------------------------------------------------------------------------*/
642
643
 
643
644
void
644
 
http_hdr_type_set(HTTPHdrImpl * hh, HTTPType type)
 
645
http_hdr_type_set(HTTPHdrImpl *hh, HTTPType type)
645
646
{
646
647
  hh->m_polarity = type;
647
648
}
650
651
  -------------------------------------------------------------------------*/
651
652
 
652
653
void
653
 
http_hdr_version_set(HTTPHdrImpl * hh, int32_t ver)
 
654
http_hdr_version_set(HTTPHdrImpl *hh, int32_t ver)
654
655
{
655
656
  hh->m_version = ver;
656
657
}
659
660
  -------------------------------------------------------------------------*/
660
661
 
661
662
const char *
662
 
http_hdr_method_get(HTTPHdrImpl * hh, int *length)
 
663
http_hdr_method_get(HTTPHdrImpl *hh, int *length)
663
664
{
664
665
  const char *str;
665
666
 
680
681
  -------------------------------------------------------------------------*/
681
682
 
682
683
void
683
 
http_hdr_method_set(HdrHeap * heap,
684
 
                    HTTPHdrImpl * hh, const char *method, int16_t method_wks_idx, int method_length, bool must_copy)
 
684
http_hdr_method_set(HdrHeap *heap, HTTPHdrImpl *hh, const char *method, int16_t method_wks_idx, int method_length,
 
685
                    bool must_copy)
685
686
{
686
687
  ink_debug_assert(hh->m_polarity == HTTP_TYPE_REQUEST);
687
688
 
693
694
  -------------------------------------------------------------------------*/
694
695
 
695
696
void
696
 
http_hdr_url_set(HdrHeap * heap, HTTPHdrImpl * hh, URLImpl * url)
 
697
http_hdr_url_set(HdrHeap *heap, HTTPHdrImpl *hh, URLImpl *url)
697
698
{
698
699
  ink_debug_assert(hh->m_polarity == HTTP_TYPE_REQUEST);
699
700
  if (hh->u.req.m_url_impl != url) {
709
710
  -------------------------------------------------------------------------*/
710
711
 
711
712
void
712
 
http_hdr_status_set(HTTPHdrImpl * hh, HTTPStatus status)
 
713
http_hdr_status_set(HTTPHdrImpl *hh, HTTPStatus status)
713
714
{
714
715
  ink_debug_assert(hh->m_polarity == HTTP_TYPE_RESPONSE);
715
716
  hh->u.resp.m_status = status;
719
720
  -------------------------------------------------------------------------*/
720
721
 
721
722
const char *
722
 
http_hdr_reason_get(HTTPHdrImpl * hh, int *length)
 
723
http_hdr_reason_get(HTTPHdrImpl *hh, int *length)
723
724
{
724
725
  ink_debug_assert(hh->m_polarity == HTTP_TYPE_RESPONSE);
725
726
  *length = hh->u.resp.m_len_reason;
730
731
  -------------------------------------------------------------------------*/
731
732
 
732
733
void
733
 
http_hdr_reason_set(HdrHeap * heap, HTTPHdrImpl * hh, const char *value, int length, bool must_copy)
 
734
http_hdr_reason_set(HdrHeap *heap, HTTPHdrImpl *hh, const char *value, int length, bool must_copy)
734
735
{
735
736
  ink_debug_assert(hh->m_polarity == HTTP_TYPE_RESPONSE);
736
737
  mime_str_u16_set(heap, value, length, &(hh->u.resp.m_ptr_reason), &(hh->u.resp.m_len_reason), must_copy);
740
741
  -------------------------------------------------------------------------*/
741
742
 
742
743
const char *
743
 
http_hdr_reason_lookup(HTTPStatus status)
 
744
http_hdr_reason_lookup(unsigned status)
744
745
{
 
746
#define HTTP_STATUS_ENTRY(value, reason) \
 
747
    case value: return #reason
 
748
 
745
749
  switch (status) {
746
 
  case HTTP_STATUS_NONE:
747
 
    return "None";
748
 
  case HTTP_STATUS_CONTINUE:
749
 
    return "Continue";
750
 
  case HTTP_STATUS_SWITCHING_PROTOCOL:
751
 
    return "Switching Protocol";
752
 
  case HTTP_STATUS_OK:
753
 
    return "Ok";
754
 
  case HTTP_STATUS_CREATED:
755
 
    return "Created";
756
 
  case HTTP_STATUS_ACCEPTED:
757
 
    return "Accepted";
758
 
  case HTTP_STATUS_NON_AUTHORITATIVE_INFORMATION:
759
 
    return "Non Authoritative Information";
760
 
  case HTTP_STATUS_NO_CONTENT:
761
 
    return "No Content";
762
 
  case HTTP_STATUS_RESET_CONTENT:
763
 
    return "Reset Content";
764
 
  case HTTP_STATUS_PARTIAL_CONTENT:
765
 
    return "Partial Content";
766
 
  case HTTP_STATUS_MULTIPLE_CHOICES:
767
 
    return "Multiple Choices";
768
 
  case HTTP_STATUS_MOVED_PERMANENTLY:
769
 
    return "Moved Permanently";
770
 
  case HTTP_STATUS_MOVED_TEMPORARILY:
771
 
    return "Moved Temporarily";
772
 
  case HTTP_STATUS_SEE_OTHER:
773
 
    return "See Other";
774
 
  case HTTP_STATUS_NOT_MODIFIED:
775
 
    return "Not Modified";
776
 
  case HTTP_STATUS_USE_PROXY:
777
 
    return "Use Proxy";
778
 
  case HTTP_STATUS_TEMPORARY_REDIRECT:
779
 
    return "Temporary Redirect";
780
 
  case HTTP_STATUS_BAD_REQUEST:
781
 
    return "Bad Request";
782
 
  case HTTP_STATUS_UNAUTHORIZED:
783
 
    return "Unauthorized";
784
 
  case HTTP_STATUS_PAYMENT_REQUIRED:
785
 
    return "Payment Required";
786
 
  case HTTP_STATUS_FORBIDDEN:
787
 
    return "Forbidden";
788
 
  case HTTP_STATUS_NOT_FOUND:
789
 
    return "Not Found";
790
 
  case HTTP_STATUS_METHOD_NOT_ALLOWED:
791
 
    return "Method Not Allowed";
792
 
  case HTTP_STATUS_NOT_ACCEPTABLE:
793
 
    return "Not Acceptable";
794
 
  case HTTP_STATUS_PROXY_AUTHENTICATION_REQUIRED:
795
 
    return "Proxy Authentication Required";
796
 
  case HTTP_STATUS_REQUEST_TIMEOUT:
797
 
    return "Request Timeout";
798
 
  case HTTP_STATUS_CONFLICT:
799
 
    return "Conflict";
800
 
  case HTTP_STATUS_GONE:
801
 
    return "Gone";
802
 
  case HTTP_STATUS_LENGTH_REQUIRED:
803
 
    return "Length Required";
804
 
  case HTTP_STATUS_PRECONDITION_FAILED:
805
 
    return "Precondition Failed";
806
 
  case HTTP_STATUS_RANGE_NOT_SATISFIABLE:
807
 
    return "Requested Range Not Satisfiable";
808
 
  case HTTP_STATUS_REQUEST_ENTITY_TOO_LARGE:
809
 
    return "Request Entity Too Large";
810
 
  case HTTP_STATUS_REQUEST_URI_TOO_LONG:
811
 
    return "Request URI Too Long";
812
 
  case HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE:
813
 
    return "Unsupported Media Type";
814
 
  case HTTP_STATUS_INTERNAL_SERVER_ERROR:
815
 
    return "Internal Server Error";
816
 
  case HTTP_STATUS_NOT_IMPLEMENTED:
817
 
    return "Not Implemented";
818
 
  case HTTP_STATUS_BAD_GATEWAY:
819
 
    return "Bad Gateway";
820
 
  case HTTP_STATUS_SERVICE_UNAVAILABLE:
821
 
    return "Service Unavailable";
822
 
  case HTTP_STATUS_GATEWAY_TIMEOUT:
823
 
    return "Gateway Timeout";
824
 
  case HTTP_STATUS_HTTPVER_NOT_SUPPORTED:
825
 
    return "HTTP Version Not Supported";
 
750
    HTTP_STATUS_ENTRY(0, None);                                       // TS_HTTP_STATUS_NONE
 
751
    HTTP_STATUS_ENTRY(100, Continue);                                 // [RFC2616]
 
752
    HTTP_STATUS_ENTRY(101, Switching Protocols);                      // [RFC2616]
 
753
    HTTP_STATUS_ENTRY(102, Processing);                               // [RFC2518]
 
754
    // 103-199 Unassigned
 
755
    HTTP_STATUS_ENTRY(200, OK);                                       // [RFC2616]
 
756
    HTTP_STATUS_ENTRY(201, Created);                                  // [RFC2616]
 
757
    HTTP_STATUS_ENTRY(202, Accepted);                                 // [RFC2616]
 
758
    HTTP_STATUS_ENTRY(203, Non-Authoritative Information);            // [RFC2616]
 
759
    HTTP_STATUS_ENTRY(204, No Content);                               // [RFC2616]
 
760
    HTTP_STATUS_ENTRY(205, Reset Content);                            // [RFC2616]
 
761
    HTTP_STATUS_ENTRY(206, Partial Content);                          // [RFC2616]
 
762
    HTTP_STATUS_ENTRY(207, Multi-Status);                             // [RFC4918]
 
763
    HTTP_STATUS_ENTRY(208, Already Reported);                         // [RFC5842]
 
764
    // 209-225 Unassigned
 
765
    HTTP_STATUS_ENTRY(226, IM Used);                                  // [RFC3229]
 
766
    // 227-299 Unassigned
 
767
    HTTP_STATUS_ENTRY(300, Multiple Choices);                         // [RFC2616]
 
768
    HTTP_STATUS_ENTRY(301, Moved Permanently);                        // [RFC2616]
 
769
    HTTP_STATUS_ENTRY(302, Found);                                    // [RFC2616]
 
770
    HTTP_STATUS_ENTRY(303, See Other);                                // [RFC2616]
 
771
    HTTP_STATUS_ENTRY(304, Not Modified);                             // [RFC2616]
 
772
    HTTP_STATUS_ENTRY(305, Use Proxy);                                // [RFC2616]
 
773
    // 306 Reserved                                                   // [RFC2616]
 
774
    HTTP_STATUS_ENTRY(307, Temporary Redirect);                       // [RFC2616]
 
775
    HTTP_STATUS_ENTRY(308, Permanent Redirect);                       // [RFC-reschke-http-status-308-07]
 
776
    // 309-399 Unassigned
 
777
    HTTP_STATUS_ENTRY(400, Bad Request);                              // [RFC2616]
 
778
    HTTP_STATUS_ENTRY(401, Unauthorized);                             // [RFC2616]
 
779
    HTTP_STATUS_ENTRY(402, Payment Required);                         // [RFC2616]
 
780
    HTTP_STATUS_ENTRY(403, Forbidden);                                // [RFC2616]
 
781
    HTTP_STATUS_ENTRY(404, Not Found);                                // [RFC2616]
 
782
    HTTP_STATUS_ENTRY(405, Method Not Allowed);                       // [RFC2616]
 
783
    HTTP_STATUS_ENTRY(406, Not Acceptable);                           // [RFC2616]
 
784
    HTTP_STATUS_ENTRY(407, Proxy Authentication Required);            // [RFC2616]
 
785
    HTTP_STATUS_ENTRY(408, Request Timeout);                          // [RFC2616]
 
786
    HTTP_STATUS_ENTRY(409, Conflict);                                 // [RFC2616]
 
787
    HTTP_STATUS_ENTRY(410, Gone);                                     // [RFC2616]
 
788
    HTTP_STATUS_ENTRY(411, Length Required);                          // [RFC2616]
 
789
    HTTP_STATUS_ENTRY(412, Precondition Failed);                      // [RFC2616]
 
790
    HTTP_STATUS_ENTRY(413, Request Entity Too Large);                 // [RFC2616]
 
791
    HTTP_STATUS_ENTRY(414, Request-URI Too Long);                     // [RFC2616]
 
792
    HTTP_STATUS_ENTRY(415, Unsupported Media Type);                   // [RFC2616]
 
793
    HTTP_STATUS_ENTRY(416, Requested Range Not Satisfiable);          // [RFC2616]
 
794
    HTTP_STATUS_ENTRY(417, Expectation Failed);                       // [RFC2616]
 
795
    HTTP_STATUS_ENTRY(422, Unprocessable Entity);                     // [RFC4918]
 
796
    HTTP_STATUS_ENTRY(423, Locked);                                   // [RFC4918]
 
797
    HTTP_STATUS_ENTRY(424, Failed Dependency);                        // [RFC4918]
 
798
    // 425 Reserved                                                   // [RFC2817]
 
799
    HTTP_STATUS_ENTRY(426, Upgrade Required);                         // [RFC2817]
 
800
    // 427 Unassigned
 
801
    HTTP_STATUS_ENTRY(428, Precondition Required);                    // [RFC6585]
 
802
    HTTP_STATUS_ENTRY(429, Too Many Requests);                        // [RFC6585]
 
803
    // 430 Unassigned
 
804
    HTTP_STATUS_ENTRY(431, Request Header Fields Too Large);          // [RFC6585]
 
805
    // 432-499 Unassigned
 
806
    HTTP_STATUS_ENTRY(500, Internal Server Error);                    // [RFC2616]
 
807
    HTTP_STATUS_ENTRY(501, Not Implemented);                          // [RFC2616]
 
808
    HTTP_STATUS_ENTRY(502, Bad Gateway);                              // [RFC2616]
 
809
    HTTP_STATUS_ENTRY(503, Service Unavailable);                      // [RFC2616]
 
810
    HTTP_STATUS_ENTRY(504, Gateway Timeout);                          // [RFC2616]
 
811
    HTTP_STATUS_ENTRY(505, HTTP Version Not Supported);               // [RFC2616]
 
812
    HTTP_STATUS_ENTRY(506, Variant Also Negotiates);                  // [RFC2295]
 
813
    HTTP_STATUS_ENTRY(507, Insufficient Storage);                     // [RFC4918]
 
814
    HTTP_STATUS_ENTRY(508, Loop Detected);                            // [RFC5842]
 
815
    // 509 Unassigned
 
816
    HTTP_STATUS_ENTRY(510, Not Extended);                             // [RFC2774]
 
817
    HTTP_STATUS_ENTRY(511, Network Authentication Required);          // [RFC6585]
 
818
    // 512-599 Unassigned
826
819
  }
827
820
 
828
 
  return (NULL);
 
821
#undef HTTP_STATUS_ENTRY
 
822
 
 
823
  return NULL;
829
824
}
830
825
 
831
826
/*-------------------------------------------------------------------------
832
827
  -------------------------------------------------------------------------*/
833
828
 
834
829
void
835
 
_http_parser_init(HTTPParser * parser)
 
830
_http_parser_init(HTTPParser *parser)
836
831
{
837
832
  parser->m_parsing_http = true;
838
833
}
843
838
//////////////////////////////////////////////////////
844
839
 
845
840
void
846
 
http_parser_init(HTTPParser * parser)
 
841
http_parser_init(HTTPParser *parser)
847
842
{
848
843
  _http_parser_init(parser);
849
844
  mime_parser_init(&parser->m_mime_parser);
850
845
}
851
846
 
852
847
void
853
 
http_parser_clear(HTTPParser * parser)
 
848
http_parser_clear(HTTPParser *parser)
854
849
{
855
850
  _http_parser_init(parser);
856
851
  mime_parser_clear(&parser->m_mime_parser);
876
871
// NOTE: end is ONE CHARACTER PAST end of string!
877
872
 
878
873
MIMEParseResult
879
 
http_parser_parse_req(HTTPParser * parser,
880
 
                      HdrHeap * heap,
881
 
                      HTTPHdrImpl * hh, const char **start, const char *end, bool must_copy_strings, bool eof)
 
874
http_parser_parse_req(HTTPParser *parser, HdrHeap *heap, HTTPHdrImpl *hh, const char **start, const char *end,
 
875
                      bool must_copy_strings, bool eof)
882
876
{
883
877
  if (parser->m_parsing_http) {
884
878
    MIMEScanner *scanner = &parser->m_mime_parser.m_scanner;
901
895
  start:
902
896
    hh->m_polarity = HTTP_TYPE_REQUEST;
903
897
 
 
898
    // Make sure the line is not longer than 64K
 
899
    if (scanner->m_line_length >= UINT16_MAX)
 
900
      return PARSE_ERROR;
 
901
 
904
902
    err = mime_scanner_get(scanner, start, real_end, &line_start, &end, &line_is_real, eof, MIME_SCANNER_TYPE_LINE);
905
903
    if (err < 0)
906
904
      return err;
912
910
      return err;
913
911
 
914
912
    cur = line_start;
 
913
    ink_assert((end - cur) >= 0);
 
914
    ink_assert((end - cur) < UINT16_MAX);
 
915
 
915
916
    must_copy_strings = (must_copy_strings || (!line_is_real));
916
917
 
 
918
#if ENABLE_SAVE_ORIGINAL_REQUEST
 
919
    mime_str_u16_set(heap, line_start, strlen(line_start),
 
920
                     &(hh->u.req.m_url_impl->the_request),
 
921
                     &(hh->u.req.m_url_impl->the_request_len),
 
922
                     must_copy_strings);
 
923
#endif
 
924
 
917
925
#if (ENABLE_PARSER_FAST_PATHS)
918
926
    // first try fast path
919
927
    if (end - cur >= 16) {
1086
1094
  -------------------------------------------------------------------------*/
1087
1095
 
1088
1096
MIMEParseResult
1089
 
http_parser_parse_resp(HTTPParser * parser,
1090
 
                       HdrHeap * heap,
1091
 
                       HTTPHdrImpl * hh, const char **start, const char *end, bool must_copy_strings, bool eof)
 
1097
http_parser_parse_resp(HTTPParser *parser, HdrHeap *heap, HTTPHdrImpl *hh, const char **start, const char *end,
 
1098
                       bool must_copy_strings, bool eof)
1092
1099
{
1093
1100
  if (parser->m_parsing_http) {
1094
1101
    MIMEScanner *scanner = &parser->m_mime_parser.m_scanner;
1111
1118
 
1112
1119
    hh->m_polarity = HTTP_TYPE_RESPONSE;
1113
1120
 
 
1121
    // Make sure the line is not longer than 64K
 
1122
    if (scanner->m_line_length >= UINT16_MAX)
 
1123
      return PARSE_ERROR;
 
1124
 
1114
1125
    err = mime_scanner_get(scanner, start, real_end, &line_start, &end, &line_is_real, eof, MIME_SCANNER_TYPE_LINE);
1115
1126
    if (err < 0)
1116
1127
      return err;
1118
1129
      return err;
1119
1130
 
1120
1131
    cur = line_start;
 
1132
    ink_assert((end - cur) >= 0);
 
1133
    ink_assert((end - cur) < UINT16_MAX);
 
1134
 
1121
1135
    must_copy_strings = (must_copy_strings || (!line_is_real));
1122
1136
 
1123
1137
#if (ENABLE_PARSER_FAST_PATHS)
1320
1334
  -------------------------------------------------------------------------*/
1321
1335
 
1322
1336
static char *
1323
 
http_str_store(Arena * arena, const char *str, int length)
 
1337
http_str_store(Arena *arena, const char *str, int length)
1324
1338
{
1325
1339
  const char *wks;
1326
1340
  int idx = hdrtoken_tokenize(str, length, &wks);
1423
1437
  -------------------------------------------------------------------------*/
1424
1438
 
1425
1439
HTTPValTE *
1426
 
http_parse_te(const char *buf, int len, Arena * arena)
 
1440
http_parse_te(const char *buf, int len, Arena *arena)
1427
1441
{
1428
1442
  HTTPValTE *val;
1429
1443
  const char *s;
1448
1462
HTTPHdr::_fill_target_cache() const
1449
1463
{
1450
1464
  URL* url = this->url_get();
 
1465
  char const* port_ptr;
 
1466
 
1451
1467
  m_target_in_url = false;
1452
1468
  m_port_in_header = false;
 
1469
  m_host_mime = NULL;
1453
1470
  // Check in the URL first, then the HOST field.
1454
 
  if (0 != (m_host = url->host_get(&m_host_length))) {
 
1471
  if (0 != url->host_get(&m_host_length)) {
1455
1472
    m_target_in_url = true;
1456
1473
    m_port = url->port_get();
1457
1474
    m_port_in_header = 0 != url->port_get_raw();
1458
 
  } else if (0 != (m_host = const_cast<HTTPHdr*>(this)->value_get(MIME_FIELD_HOST, MIME_LEN_HOST, &m_host_length))) {
1459
 
    // Check for port in the host.
1460
 
    char const* colon = static_cast<char const*>(memchr(m_host, ':', m_host_length));
1461
 
    
1462
 
    if (colon) {
1463
 
      m_host_length = colon - m_host; // Length of just the host in the value.
 
1475
    m_host_mime = NULL;
 
1476
  } else if (0 != (m_host_mime = const_cast<HTTPHdr*>(this)->get_host_port_values(0, &m_host_length, &port_ptr, 0))) {
 
1477
    if (port_ptr) {
1464
1478
      m_port = 0;
1465
 
      for ( ++colon ; is_digit(*colon) ; ++colon )
1466
 
        m_port = m_port * 10 + *colon - '0';
1467
 
      m_port_in_header = 0 != m_port;
 
1479
      for ( ; is_digit(*port_ptr) ; ++port_ptr )
 
1480
        m_port = m_port * 10 + *port_ptr - '0';
 
1481
      m_port_in_header = (0 != m_port);
1468
1482
    }
1469
1483
    m_port = url_canonicalize_port(url->m_url_impl->m_url_type, m_port);
1470
 
  } else {
1471
 
    m_host_length = 0; // reset in case any earlier check corrupted it
1472
1484
  }
 
1485
 
1473
1486
  m_target_cached = true;
1474
1487
}
1475
1488
 
1480
1493
  if (!url) {
1481
1494
    // Use local cached URL and don't copy if the target
1482
1495
    // is already there.
1483
 
    if (!m_target_in_url && m_host_length) {
1484
 
      m_url_cached.host_set(m_host, m_host_length);
 
1496
    if (!m_target_in_url && m_host_mime && m_host_length) {
 
1497
      m_url_cached.host_set(m_host_mime->m_ptr_value, m_host_length);
1485
1498
      if (m_port_in_header) m_url_cached.port_set(m_port);
1486
1499
      m_target_in_url = true; // it's there now.
1487
1500
    }
1488
1501
  } else {
1489
 
    url->host_set(m_host, m_host_length);
 
1502
    int host_len = 0;
 
1503
    char const *host = NULL;
 
1504
    host = host_get(&host_len);
 
1505
    url->host_set(host, host_len);
1490
1506
    if (m_port_in_header) url->port_set(m_port);
1491
1507
  }
1492
1508
}
1516
1532
       2) The values were in a HTTP header field.
1517
1533
    */
1518
1534
 
1519
 
    if (!m_target_in_url && m_host_length) {
 
1535
    if (!m_target_in_url && m_host_length && m_host_mime) {
1520
1536
      assert(0 == ui->m_ptr_host); // shouldn't be non-zero if not in URL.
1521
 
      ui->m_ptr_host = m_host;
 
1537
      ui->m_ptr_host = m_host_mime->m_ptr_value;
1522
1538
      ui->m_len_host = m_host_length;
1523
1539
      should_reset_host = true;
1524
1540
    }
1545
1561
 ***********************************************************************/
1546
1562
 
1547
1563
int
1548
 
HTTPHdr::unmarshal(char *buf, int len, RefCountObj * block_ref)
 
1564
HTTPHdr::unmarshal(char *buf, int len, RefCountObj *block_ref)
1549
1565
{
1550
 
  m_heap = (HdrHeap *) buf;
 
1566
  m_heap = (HdrHeap *)buf;
1551
1567
 
1552
 
  int res = m_heap->unmarshal(len,
1553
 
                              HDR_HEAP_OBJ_HTTP_HEADER,
1554
 
                              (HdrHeapObjImpl **) & m_http,
1555
 
                              block_ref);
 
1568
  int res = m_heap->unmarshal(len, HDR_HEAP_OBJ_HTTP_HEADER, (HdrHeapObjImpl **) & m_http, block_ref);
1556
1569
 
1557
1570
  if (res > 0) {
1558
1571
    m_mime = m_http->m_fields_impl;
1564
1577
}
1565
1578
 
1566
1579
int
1567
 
HTTPHdrImpl::marshal(MarshalXlate * ptr_xlate, int num_ptr, MarshalXlate * str_xlate, int num_str)
 
1580
HTTPHdrImpl::marshal(MarshalXlate *ptr_xlate, int num_ptr, MarshalXlate *str_xlate, int num_str)
1568
1581
{
1569
1582
 
1570
1583
  if (m_polarity == HTTP_TYPE_REQUEST) {
1600
1613
 
1601
1614
 
1602
1615
void
1603
 
HTTPHdrImpl::move_strings(HdrStrHeap * new_heap)
 
1616
HTTPHdrImpl::move_strings(HdrStrHeap *new_heap)
1604
1617
{
1605
1618
  if (m_polarity == HTTP_TYPE_REQUEST) {
1606
1619
    HDR_MOVE_STR(u.req.m_ptr_method, u.req.m_len_method);
1612
1625
}
1613
1626
 
1614
1627
void
1615
 
HTTPHdrImpl::check_strings(HeapCheck * heaps, int num_heaps)
 
1628
HTTPHdrImpl::check_strings(HeapCheck *heaps, int num_heaps)
1616
1629
{
1617
1630
 
1618
1631
  if (m_polarity == HTTP_TYPE_REQUEST) {
1656
1669
}
1657
1670
 
1658
1671
void
1659
 
HTTPCacheAlt::copy(HTTPCacheAlt * to_copy)
 
1672
HTTPCacheAlt::copy(HTTPCacheAlt *to_copy)
1660
1673
{
1661
1674
 
1662
1675
  m_magic = to_copy->m_magic;
1692
1705
}
1693
1706
 
1694
1707
void
1695
 
HTTPInfo::copy(HTTPInfo * hi)
 
1708
HTTPInfo::copy(HTTPInfo *hi)
1696
1709
{
1697
1710
 
1698
1711
  if (m_alt && m_alt->m_writeable) {
1777
1790
}
1778
1791
 
1779
1792
int
1780
 
HTTPInfo::unmarshal(char *buf, int len, RefCountObj * block_ref)
 
1793
HTTPInfo::unmarshal(char *buf, int len, RefCountObj *block_ref)
1781
1794
{
1782
1795
  HTTPCacheAlt *alt = (HTTPCacheAlt *) buf;
1783
1796
  int orig_len = len;
1899
1912
//     to set up the reference
1900
1913
//
1901
1914
void
1902
 
HTTPInfo::set_buffer_reference(RefCountObj * block_ref)
 
1915
HTTPInfo::set_buffer_reference(RefCountObj *block_ref)
1903
1916
{
1904
1917
  ink_assert(m_alt->m_magic == CACHE_ALT_MAGIC_ALIVE);
1905
1918