StatusLine.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
3  *
4  * Squid software is distributed under GPLv2+ license and includes
5  * contributions from numerous individuals and organizations.
6  * Please see the COPYING and CONTRIBUTORS files for details.
7  */
8 
9 /* DEBUG: section 57 HTTP Status-line */
10 
11 #include "squid.h"
12 #include "base/Packable.h"
13 #include "Debug.h"
14 #include "http/StatusLine.h"
15 
16 void
18 {
20 }
21 
22 void
24 {
26 }
27 
28 /* set values */
29 void
30 Http::StatusLine::set(const AnyP::ProtocolVersion &newVersion, const Http::StatusCode newStatus, const char *newReason)
31 {
32  protocol = AnyP::PROTO_HTTP;
33  version = newVersion;
34  status_ = newStatus;
35  /* Note: no xstrdup for 'reason', assumes constant 'reasons' */
36  reason_ = newReason;
37 }
38 
39 const char *
41 {
42  return reason_ ? reason_ : Http::StatusCodeString(status());
43 }
44 
45 void
47 {
48  assert(p);
49 
50  /* local constants */
51  /* AYJ: see bug 2469 - RFC2616 confirms stating 'SP characters' plural! */
52  static const char *Http1StatusLineFormat = "HTTP/%d.%d %3d %s\r\n";
53  static const char *IcyStatusLineFormat = "ICY %3d %s\r\n";
54 
55  /* handle ICY protocol status line specially. Pass on the bad format. */
56  if (protocol == AnyP::PROTO_ICY) {
57  debugs(57, 9, "packing sline " << this << " using " << p << ":");
58  debugs(57, 9, "FORMAT=" << IcyStatusLineFormat );
59  debugs(57, 9, "ICY " << status() << " " << reason());
60  p->appendf(IcyStatusLineFormat, status(), reason());
61  return;
62  }
63 
64  debugs(57, 9, "packing sline " << this << " using " << p << ":");
65  debugs(57, 9, "FORMAT=" << Http1StatusLineFormat );
66  debugs(57, 9, "HTTP/" << version.major << "." << version.minor << " " << status() << " " << reason());
67  p->appendf(Http1StatusLineFormat, version.major, version.minor, status(), reason());
68 }
69 
70 /*
71  * Parse character string.
72  * XXX: Note 'end' currently unused, so NULL-termination assumed.
73  */
74 bool
75 Http::StatusLine::parse(const String &protoPrefix, const char *start, const char * /*end*/)
76 {
77  status_ = Http::scInvalidHeader; /* Squid header parsing error */
78 
79  // XXX: Http::Message::parse() has a similar check but is using
80  // casesensitive comparison (which is required by HTTP errata?)
81 
82  if (protoPrefix.cmp("ICY", 3) == 0) {
83  debugs(57, 3, "Invalid HTTP identifier. Detected ICY protocol istead.");
84  protocol = AnyP::PROTO_ICY;
85  start += protoPrefix.size();
86  } else if (protoPrefix.caseCmp(start, protoPrefix.size()) == 0) {
87 
88  start += protoPrefix.size();
89 
90  if (!xisdigit(*start))
91  return false;
92 
93  // XXX: HTTPbis have defined this to be single-digit version numbers. no need to sscanf()
94  // XXX: furthermore, only HTTP/1 will be using ASCII format digits
95 
96  if (sscanf(start, "%d.%d", &version.major, &version.minor) != 2) {
97  debugs(57, 7, "Invalid HTTP identifier.");
98  return false;
99  }
100  } else
101  return false;
102 
103  if (!(start = strchr(start, ' ')))
104  return false;
105 
106  // XXX: should we be using xstrtoui() or xatoui() ?
107  status_ = static_cast<Http::StatusCode>(atoi(++start));
108 
109  // XXX check if the given 'reason' is the default status string, if not save to reason_
110 
111  /* we ignore 'reason-phrase' */
112  /* Should assert start < end ? */
113  return true; /* success */
114 }
115 
AnyP::ProtocolVersion ProtocolVersion(unsigned int aMajor, unsigned int aMinor)
HTTP version label information.
int cmp(char const *) const
Definition: String.cc:269
void clean()
reset this status-line back to Internal Server Error state
Definition: StatusLine.cc:23
void packInto(Packable *) const
pack fields into a Packable object
Definition: StatusLine.cc:46
#define assert(EX)
Definition: assert.h:17
const char * StatusCodeString(const Http::StatusCode status)
Definition: StatusCode.cc:14
int caseCmp(char const *) const
Definition: String.cc:299
void set(const AnyP::ProtocolVersion &newVersion, Http::StatusCode newStatus, const char *newReason=NULL)
Definition: StatusLine.cc:30
static int version
const char * reason() const
retrieve the reason string for this status line
Definition: StatusLine.cc:40
char * p
Definition: membanger.c:43
size_type size() const
Definition: SquidString.h:71
void init()
reset this status-line back to empty state
Definition: StatusLine.cc:17
StatusCode
Definition: StatusCode.h:20
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Debug.h:123
bool parse(const String &protoPrefix, const char *start, const char *end)
Definition: StatusLine.cc:75
#define xisdigit(x)
Definition: xis.h:20
void appendf(const char *fmt,...) PRINTF_FORMAT_ARG2
Append operation with printf-style arguments.
Definition: Packable.h:61
#define NULL
Definition: types.h:166

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors