Bug 458256. Use LoadLibraryW instead of LoadLibrary (patch by DougT). r+sr=vlad
[wine-gecko.git] / netwerk / protocol / http / src / nsHttp.h
blob21a2cbd471c4dd68f2b8216e5fa7ab58fd9b0be6
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 //-----------------------------------------------------------------------------
108 // some default values
109 //-----------------------------------------------------------------------------
111 // hard upper limit on the number of requests that can be pipelined
112 #define NS_HTTP_MAX_PIPELINED_REQUESTS 8
114 #define NS_HTTP_DEFAULT_PORT 80
115 #define NS_HTTPS_DEFAULT_PORT 443
117 #define NS_HTTP_HEADER_SEPS ", \t"
119 //-----------------------------------------------------------------------------
120 // http atoms...
121 //-----------------------------------------------------------------------------
123 struct nsHttpAtom
125 operator const char *() const { return _val; }
126 const char *get() const { return _val; }
128 void operator=(const char *v) { _val = v; }
129 void operator=(const nsHttpAtom &a) { _val = a._val; }
131 // private
132 const char *_val;
135 struct nsHttp
137 static nsresult CreateAtomTable();
138 static void DestroyAtomTable();
140 // will dynamically add atoms to the table if they don't already exist
141 static nsHttpAtom ResolveAtom(const char *);
142 static nsHttpAtom ResolveAtom(const nsACString &s)
144 return ResolveAtom(PromiseFlatCString(s).get());
147 // returns true if the specified token [start,end) is valid per RFC 2616
148 // section 2.2
149 static PRBool IsValidToken(const char *start, const char *end);
151 static inline PRBool IsValidToken(const nsCString &s) {
152 const char *start = s.get();
153 return IsValidToken(start, start + s.Length());
156 // find the first instance (case-insensitive comparison) of the given
157 // |token| in the |input| string. the |token| is bounded by elements of
158 // |separators| and may appear at the beginning or end of the |input|
159 // string. null is returned if the |token| is not found. |input| may be
160 // null, in which case null is returned.
161 static const char *FindToken(const char *input, const char *token,
162 const char *separators);
164 // This function parses a string containing a decimal-valued, non-negative
165 // 64-bit integer. If the value would exceed LL_MAXINT, then PR_FALSE is
166 // returned. Otherwise, this function returns PR_TRUE and stores the
167 // parsed value in |result|. The next unparsed character in |input| is
168 // optionally returned via |next| if |next| is non-null.
170 // TODO(darin): Replace this with something generic.
172 static PRBool ParseInt64(const char *input, const char **next,
173 PRInt64 *result);
175 // Variant on ParseInt64 that expects the input string to contain nothing
176 // more than the value being parsed.
177 static inline PRBool ParseInt64(const char *input, PRInt64 *result) {
178 const char *next;
179 return ParseInt64(input, &next, result) && *next == '\0';
182 // Declare all atoms
184 // The atom names and values are stored in nsHttpAtomList.h and are brought
185 // to you by the magic of C preprocessing. Add new atoms to nsHttpAtomList
186 // and all support logic will be auto-generated.
188 #define HTTP_ATOM(_name, _value) static nsHttpAtom _name;
189 #include "nsHttpAtomList.h"
190 #undef HTTP_ATOM
193 //-----------------------------------------------------------------------------
194 // utilities...
195 //-----------------------------------------------------------------------------
197 static inline PRUint32
198 PRTimeToSeconds(PRTime t_usec)
200 return PRUint32( t_usec / PR_USEC_PER_SEC );
203 #define NowInSeconds() PRTimeToSeconds(PR_Now())
205 // ripped from glib.h
206 #undef CLAMP
207 #define CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
209 // round q-value to one decimal place; return most significant digit as uint.
210 #define QVAL_TO_UINT(q) ((unsigned int) ((q + 0.05) * 10.0))
212 #define HTTP_LWS " \t"
213 #define HTTP_HEADER_VALUE_SEPS HTTP_LWS ","
215 #endif // nsHttp_h__