2001-05-11 21:04:09 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
|
|
|
* The contents of this file are subject to the Mozilla Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
|
|
|
* Communications. Portions created by Netscape Communications are
|
|
|
|
* Copyright (C) 2001 by Netscape Communications. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Darin Fisher <darin@netscape.com> (original author)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef nsHttp_h__
|
|
|
|
#define nsHttp_h__
|
|
|
|
|
2001-09-28 22:23:26 +00:00
|
|
|
#if defined(MOZ_LOGGING)
|
|
|
|
#define FORCE_PR_LOG
|
|
|
|
#endif
|
|
|
|
|
2001-05-11 21:04:09 +00:00
|
|
|
#include "plstr.h"
|
|
|
|
#include "prlog.h"
|
|
|
|
#include "prtime.h"
|
|
|
|
#include "nsISupportsUtils.h"
|
2002-03-20 22:50:33 +00:00
|
|
|
#include "nsPromiseFlatString.h"
|
2002-05-03 07:49:43 +00:00
|
|
|
#include "netCore.h"
|
2001-05-11 21:04:09 +00:00
|
|
|
|
|
|
|
#if defined(PR_LOGGING)
|
|
|
|
//
|
|
|
|
// Log module for HTTP Protocol logging...
|
|
|
|
//
|
|
|
|
// To enable logging (see prlog.h for full details):
|
|
|
|
//
|
2001-06-13 22:49:56 +00:00
|
|
|
// set NSPR_LOG_MODULES=nsHttp:5
|
2001-05-11 21:04:09 +00:00
|
|
|
// set NSPR_LOG_FILE=http.log
|
|
|
|
//
|
|
|
|
// this enables PR_LOG_ALWAYS level information and places all output in
|
|
|
|
// the file http.log
|
|
|
|
//
|
|
|
|
extern PRLogModuleInfo *gHttpLog;
|
|
|
|
#endif
|
|
|
|
|
2001-08-14 01:03:27 +00:00
|
|
|
// http logging
|
2001-05-11 21:04:09 +00:00
|
|
|
#define LOG1(args) PR_LOG(gHttpLog, 1, args)
|
|
|
|
#define LOG2(args) PR_LOG(gHttpLog, 2, args)
|
|
|
|
#define LOG3(args) PR_LOG(gHttpLog, 3, args)
|
|
|
|
#define LOG4(args) PR_LOG(gHttpLog, 4, args)
|
|
|
|
#define LOG(args) LOG4(args)
|
|
|
|
|
2001-09-28 22:23:26 +00:00
|
|
|
#define LOG1_ENABLED() PR_LOG_TEST(gHttpLog, 1)
|
|
|
|
#define LOG2_ENABLED() PR_LOG_TEST(gHttpLog, 2)
|
|
|
|
#define LOG3_ENABLED() PR_LOG_TEST(gHttpLog, 3)
|
|
|
|
#define LOG4_ENABLED() PR_LOG_TEST(gHttpLog, 4)
|
|
|
|
#define LOG_ENABLED() LOG4_ENABLED()
|
|
|
|
|
2001-08-14 01:03:27 +00:00
|
|
|
// http default buffer geometry
|
2003-01-18 02:15:14 +00:00
|
|
|
#define NS_HTTP_SEGMENT_SIZE 4096
|
|
|
|
#define NS_HTTP_SEGMENT_COUNT 16 // 64k maximum
|
|
|
|
#define NS_HTTP_MAX_ODA_SIZE (NS_HTTP_SEGMENT_SIZE * 4) // 16k
|
2001-05-11 21:04:09 +00:00
|
|
|
|
2001-08-14 01:03:27 +00:00
|
|
|
// http version codes
|
|
|
|
#define NS_HTTP_VERSION_UNKNOWN 0
|
|
|
|
#define NS_HTTP_VERSION_0_9 9
|
|
|
|
#define NS_HTTP_VERSION_1_0 10
|
|
|
|
#define NS_HTTP_VERSION_1_1 11
|
|
|
|
|
|
|
|
typedef PRUint8 nsHttpVersion;
|
|
|
|
|
|
|
|
// http connection capabilities
|
2003-01-18 02:15:14 +00:00
|
|
|
#define NS_HTTP_ALLOW_KEEPALIVE (1<<0)
|
|
|
|
#define NS_HTTP_ALLOW_PIPELINING (1<<1)
|
2002-06-27 06:46:25 +00:00
|
|
|
#define NS_HTTP_DONT_REPORT_PROGRESS (1<<2)
|
2001-05-11 21:04:09 +00:00
|
|
|
|
2002-04-19 22:25:23 +00:00
|
|
|
// hard upper limit on the number of requests that can be pipelined
|
2003-01-18 02:15:14 +00:00
|
|
|
#define NS_HTTP_MAX_PIPELINED_REQUESTS 8
|
2002-04-19 22:25:23 +00:00
|
|
|
|
2003-03-01 02:18:05 +00:00
|
|
|
#define NS_HTTP_DEFAULT_PORT 80
|
|
|
|
#define NS_HTTPS_DEFAULT_PORT 443
|
|
|
|
|
2001-05-11 21:04:09 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// http atoms...
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
struct nsHttpAtom
|
|
|
|
{
|
|
|
|
operator const char *() { return _val; }
|
|
|
|
const char *get() { return _val; }
|
|
|
|
|
2001-09-26 23:30:28 +00:00
|
|
|
void operator=(const char *v) { _val = v; }
|
|
|
|
void operator=(const nsHttpAtom &a) { _val = a._val; }
|
|
|
|
|
2001-05-11 21:04:09 +00:00
|
|
|
// private
|
|
|
|
const char *_val;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct nsHttp
|
|
|
|
{
|
|
|
|
static void DestroyAtomTable();
|
|
|
|
|
|
|
|
// will dynamically add atoms to the table if they don't already exist
|
|
|
|
static nsHttpAtom ResolveAtom(const char *);
|
2002-03-20 22:50:33 +00:00
|
|
|
static nsHttpAtom ResolveAtom(const nsACString &s) { return ResolveAtom(PromiseFlatCString(s).get()); }
|
2001-05-11 21:04:09 +00:00
|
|
|
|
|
|
|
/* Declare all atoms
|
|
|
|
*
|
|
|
|
* The atom names and values are stored in nsHttpAtomList.h and
|
|
|
|
* are brought to you by the magic of C preprocessing
|
|
|
|
*
|
|
|
|
* Add new atoms to nsHttpAtomList and all support logic will be auto-generated
|
|
|
|
*/
|
|
|
|
#define HTTP_ATOM(_name, _value) static nsHttpAtom _name;
|
|
|
|
#include "nsHttpAtomList.h"
|
|
|
|
#undef HTTP_ATOM
|
|
|
|
};
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// utilities...
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
static inline PRUint32
|
|
|
|
PRTimeToSeconds(PRTime t_usec)
|
|
|
|
{
|
|
|
|
PRTime usec_per_sec;
|
|
|
|
PRUint32 t_sec;
|
|
|
|
LL_I2L(usec_per_sec, PR_USEC_PER_SEC);
|
|
|
|
LL_DIV(t_usec, t_usec, usec_per_sec);
|
|
|
|
LL_L2I(t_sec, t_usec);
|
|
|
|
return t_sec;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define NowInSeconds() PRTimeToSeconds(PR_Now())
|
|
|
|
|
2001-08-14 01:03:27 +00:00
|
|
|
// ripped from glib.h
|
|
|
|
#undef CLAMP
|
|
|
|
#define CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
|
|
|
|
|
2001-12-04 23:49:06 +00:00
|
|
|
// nsCRT::strdup likes to convert nsnull to ""
|
|
|
|
#define strdup_if(s) (s ? nsCRT::strdup(s) : nsnull)
|
|
|
|
|
2002-11-20 20:51:12 +00:00
|
|
|
// round q-value to one decimal place; return most significant digit as uint.
|
|
|
|
#define QVAL_TO_UINT(q) ((unsigned int) ((q + 0.05) * 10.0))
|
|
|
|
|
2001-08-14 01:03:27 +00:00
|
|
|
#endif // nsHttp_h__
|