Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / netwerk / protocol / http / src / nsHttp.h
blobab167e75fa71c89a97306e7784acfc3f698570ba
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* vim:set ts=4 sw=4 sts=4 et cin: */
3 /* ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
16 * The Original Code is Mozilla.
18 * The Initial Developer of the Original Code is
19 * Netscape Communications.
20 * Portions created by the Initial Developer are Copyright (C) 2001
21 * the Initial Developer. All Rights Reserved.
23 * Contributor(s):
24 * Darin Fisher <darin@netscape.com> (original author)
26 * Alternatively, the contents of this file may be used under the terms of
27 * either the GNU General Public License Version 2 or later (the "GPL"), or
28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
40 #ifndef nsHttp_h__
41 #define nsHttp_h__
43 #if defined(MOZ_LOGGING)
44 #define FORCE_PR_LOG
45 #endif
47 #include "plstr.h"
48 #include "prlog.h"
49 #include "prtime.h"
50 #include "nsISupportsUtils.h"
51 #include "nsPromiseFlatString.h"
52 #include "nsURLHelper.h"
53 #include "netCore.h"
55 #if defined(PR_LOGGING)
57 // Log module for HTTP Protocol logging...
59 // To enable logging (see prlog.h for full details):
61 // set NSPR_LOG_MODULES=nsHttp:5
62 // set NSPR_LOG_FILE=http.log
64 // this enables PR_LOG_ALWAYS level information and places all output in
65 // the file http.log
67 extern PRLogModuleInfo *gHttpLog;
68 #endif
70 // http logging
71 #define LOG1(args) PR_LOG(gHttpLog, 1, args)
72 #define LOG2(args) PR_LOG(gHttpLog, 2, args)
73 #define LOG3(args) PR_LOG(gHttpLog, 3, args)
74 #define LOG4(args) PR_LOG(gHttpLog, 4, args)
75 #define LOG(args) LOG4(args)
77 #define LOG1_ENABLED() PR_LOG_TEST(gHttpLog, 1)
78 #define LOG2_ENABLED() PR_LOG_TEST(gHttpLog, 2)
79 #define LOG3_ENABLED() PR_LOG_TEST(gHttpLog, 3)
80 #define LOG4_ENABLED() PR_LOG_TEST(gHttpLog, 4)
81 #define LOG_ENABLED() LOG4_ENABLED()
83 // http default buffer geometry
84 #define NS_HTTP_SEGMENT_SIZE 4096
85 #define NS_HTTP_SEGMENT_COUNT 16 // 64k maximum
86 #define NS_HTTP_MAX_ODA_SIZE (NS_HTTP_SEGMENT_SIZE * 4) // 16k
88 // http version codes
89 #define NS_HTTP_VERSION_UNKNOWN 0
90 #define NS_HTTP_VERSION_0_9 9
91 #define NS_HTTP_VERSION_1_0 10
92 #define NS_HTTP_VERSION_1_1 11
94 typedef PRUint8 nsHttpVersion;
96 //-----------------------------------------------------------------------------
97 // http connection capabilities
98 //-----------------------------------------------------------------------------
100 #define NS_HTTP_ALLOW_KEEPALIVE (1<<0)
101 #define NS_HTTP_ALLOW_PIPELINING (1<<1)
103 // a transaction with this caps flag will continue to own the connection,
104 // preventing it from being reclaimed, even after the transaction completes.
105 #define NS_HTTP_STICKY_CONNECTION (1<<2)
107 // a transaction with this caps flag will, upon opening a new connection,
108 // bypass the local DNS cache
109 #define NS_HTTP_REFRESH_DNS (1<<3)
111 //-----------------------------------------------------------------------------
112 // some default values
113 //-----------------------------------------------------------------------------
115 // hard upper limit on the number of requests that can be pipelined
116 #define NS_HTTP_MAX_PIPELINED_REQUESTS 8
118 #define NS_HTTP_DEFAULT_PORT 80
119 #define NS_HTTPS_DEFAULT_PORT 443
121 #define NS_HTTP_HEADER_SEPS ", \t"
123 //-----------------------------------------------------------------------------
124 // http atoms...
125 //-----------------------------------------------------------------------------
127 struct nsHttpAtom
129 operator const char *() const { return _val; }
130 const char *get() const { return _val; }
132 void operator=(const char *v) { _val = v; }
133 void operator=(const nsHttpAtom &a) { _val = a._val; }
135 // private
136 const char *_val;
139 struct nsHttp
141 static nsresult CreateAtomTable();
142 static void DestroyAtomTable();
144 // will dynamically add atoms to the table if they don't already exist
145 static nsHttpAtom ResolveAtom(const char *);
146 static nsHttpAtom ResolveAtom(const nsACString &s)
148 return ResolveAtom(PromiseFlatCString(s).get());
151 // returns true if the specified token [start,end) is valid per RFC 2616
152 // section 2.2
153 static PRBool IsValidToken(const char *start, const char *end);
155 static inline PRBool IsValidToken(const nsCString &s) {
156 const char *start = s.get();
157 return IsValidToken(start, start + s.Length());
160 // find the first instance (case-insensitive comparison) of the given
161 // |token| in the |input| string. the |token| is bounded by elements of
162 // |separators| and may appear at the beginning or end of the |input|
163 // string. null is returned if the |token| is not found. |input| may be
164 // null, in which case null is returned.
165 static const char *FindToken(const char *input, const char *token,
166 const char *separators);
168 // This function parses a string containing a decimal-valued, non-negative
169 // 64-bit integer. If the value would exceed LL_MAXINT, then PR_FALSE is
170 // returned. Otherwise, this function returns PR_TRUE and stores the
171 // parsed value in |result|. The next unparsed character in |input| is
172 // optionally returned via |next| if |next| is non-null.
174 // TODO(darin): Replace this with something generic.
176 static PRBool ParseInt64(const char *input, const char **next,
177 PRInt64 *result);
179 // Variant on ParseInt64 that expects the input string to contain nothing
180 // more than the value being parsed.
181 static inline PRBool ParseInt64(const char *input, PRInt64 *result) {
182 const char *next;
183 return ParseInt64(input, &next, result) && *next == '\0';
186 // Declare all atoms
188 // The atom names and values are stored in nsHttpAtomList.h and are brought
189 // to you by the magic of C preprocessing. Add new atoms to nsHttpAtomList
190 // and all support logic will be auto-generated.
192 #define HTTP_ATOM(_name, _value) static nsHttpAtom _name;
193 #include "nsHttpAtomList.h"
194 #undef HTTP_ATOM
197 //-----------------------------------------------------------------------------
198 // utilities...
199 //-----------------------------------------------------------------------------
201 static inline PRUint32
202 PRTimeToSeconds(PRTime t_usec)
204 return PRUint32( t_usec / PR_USEC_PER_SEC );
207 #define NowInSeconds() PRTimeToSeconds(PR_Now())
209 // ripped from glib.h
210 #undef CLAMP
211 #define CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
213 // round q-value to one decimal place; return most significant digit as uint.
214 #define QVAL_TO_UINT(q) ((unsigned int) ((q + 0.05) * 10.0))
216 #define HTTP_LWS " \t"
217 #define HTTP_HEADER_VALUE_SEPS HTTP_LWS ","
219 #endif // nsHttp_h__