.h monsters.
as argument. Debugging equal-to or less-than the argument
will be written to stderr.
- Removed unused urlClean() function from url.c.
- - Fixed a bug that allow '?' parts of urls to be recorded in
+
+ - Fixed a bug that allowed '?' parts of urls to be recorded in
store.log. Logged urls are now "clean".
- Cache Manager got new Web interface (cachemgr.cgi). New .cgi
script forwards basic authentication from browser to squid.
/*
- * $Id: HttpBody.cc,v 1.3 1998/02/21 18:46:32 rousskov Exp $
+ * $Id: HttpBody.cc,v 1.4 1998/02/26 08:10:53 rousskov Exp $
*
* DEBUG: section 56 HTTP Message Body
* AUTHOR: Alex Rousskov
body->size = 0;
}
+/* set body, if freefunc is NULL the content will be copied, otherwise not */
void
httpBodySet(HttpBody *body, const char *buf, int size, FREE *freefunc)
{
/*
- * $Id: HttpReply.cc,v 1.4 1998/02/22 07:45:16 rousskov Exp $
+ * $Id: HttpReply.cc,v 1.5 1998/02/26 08:10:54 rousskov Exp $
*
* DEBUG: section 58 HTTP Reply (Response)
* AUTHOR: Alex Rousskov
MemBuf mb;
assert(rep);
-#if 0
- /* construct reply */
- assert(0); /* implement: rep304 = httpReply304Create(rep); */
-
- mb = httpReplyPack(rep304);
- httpReplyDestroy(rep304);
-#endif
-
memBufDefInit(&mb);
-
memBufPrintf(&mb, "%s", "HTTP/1.0 304 Not Modified\r\n");
if (httpHeaderHas(&rep->hdr, HDR_DATE))
httpHeaderSetTime(hdr, HDR_LAST_MODIFIED, lmt);
}
+/*
+ * header manipulation
+ *
+ * never go to header directly if you can use these:
+ *
+ * our interpretation of headers often changes and you may get into trouble
+ * if you, for example, assume that HDR_EXPIRES contains expire info
+ *
+ * if you think about it, in most cases, you are not looking for the information
+ * in the header, but rather for current state of the reply, which may or maynot
+ * depend on headers.
+ *
+ * For example, the _real_ question is
+ * "when does this object expire?"
+ * not
+ * "what is the value of the 'Expires:' header?"
+ */
+
void
httpReplyUpdateOnNotModified(HttpReply *rep, HttpReply *freshRep)
{
/*
- * $Id: HttpStatusLine.cc,v 1.3 1998/02/21 18:46:34 rousskov Exp $
+ * $Id: HttpStatusLine.cc,v 1.4 1998/02/26 08:10:55 rousskov Exp $
*
* DEBUG: section 57 HTTP Status-line
* AUTHOR: Alex Rousskov
/* local routines */
static const char *httpStatusString(http_status status);
+
+
void
httpStatusLineInit(HttpStatusLine *sline) {
httpStatusLineSet(sline, 0.0, 0, NULL);
httpStatusLineSet(sline, 0.0, 500, NULL);
}
+/* set values */
void httpStatusLineSet(HttpStatusLine *sline, double version, http_status status, const char *reason) {
assert(sline);
sline->version = version;
sline->reason = reason;
}
+/* parse a 0-terminating buffer and fill internal structires; returns true on success */
void
httpStatusLinePackInto(const HttpStatusLine *sline, Packer *p)
{
sline->reason ? sline->reason : httpStatusString(sline->status));
}
+/* pack fields using Packer */
int
httpStatusLineParse(HttpStatusLine *sline, const char *start, const char *end) {
assert(sline);
/*
- * $Id: Packer.cc,v 1.3 1998/02/21 18:46:35 rousskov Exp $
+ * $Id: Packer.cc,v 1.4 1998/02/26 08:10:55 rousskov Exp $
*
* DEBUG: section 60 Packer: A uniform interface to store-like modules
* AUTHOR: Alex Rousskov
*
*/
-/* see Packer.h for documentation */
+/*
+ Rationale:
+ ----------
+
+ OK, we have to major interfaces comm.c and store.c.
+
+ Store.c has a nice storeAppend[Printf] capability which makes "storing"
+ things easy and painless.
+
+ Comm.c lacks commAppend[Printf] because comm does not handle its own
+ buffers (no mem_obj equivalent for comm.c).
+
+ Thus, if one wants to be able to store _and_ comm_write an object, s/he
+ has to implement two almost identical functions.
+
+ Packer
+ ------
+
+ Packer provides for a more uniform interface to store and comm modules.
+ Packer has its own append and printf routines that "know" where to send
+ incoming data. In case of store interface, Packer sends data to
+ storeAppend. Otherwise, Packer uses a MemBuf that can be flushed later to
+ comm_write.
+
+ Thus, one can write just one function that will either "pack" things for
+ comm_write or "append" things to store, depending on actual packer
+ supplied.
+
+ It is amasing how much work a tiny object can save. :)
+
+*/
+
/*
* To-Do:
static void (*const memBuf_vprintf)(MemBuf *, const char *, va_list ap) = &memBufVPrintf;
+/* init/clean */
+
+/* init with this to forward data to StoreEntry */
void
packerToStoreInit(Packer *p, StoreEntry *e)
{
p->real_handler = e;
}
+/* init with this to accumulate data in MemBuf */
void
packerToMemInit(Packer *p, MemBuf *mb)
{
p->real_handler = mb;
}
+/* call this when you are done */
void
packerClean(Packer *p)
{
/*
- * $Id: client_side.cc,v 1.216 1998/02/26 06:42:29 rousskov Exp $
+ * $Id: client_side.cc,v 1.217 1998/02/26 08:10:57 rousskov Exp $
*
* DEBUG: section 33 Client-side Routines
* AUTHOR: Duane Wessels
*sz = n;
}
+/* this entire function has to be rewriten using new interfaces @?@ @?@ */
size_t
clientBuildReplyHeader(clientHttpRequest * http,
char *hdr_in,
SWAP_LOG_DEL,
SWAP_LOG_MAX
} swap_log_op;
+
+
+/* parse state of HttpReply or HttpRequest */
+typedef enum {
+ psReadyToParseStartLine = 0,
+ psReadyToParseHeaders,
+ psParsed,
+ psError
+} HttpMsgParseState;
extern void commSetDefer(int fd, DEFER * func, void *);
extern int ignoreErrno(int);
+extern void packerToStoreInit(Packer *p, StoreEntry *e);
+extern void packerToMemInit(Packer *p, MemBuf *mb);
+extern void packerClean(Packer *p);
+extern void packerAppend(Packer *p, const char *buf, int size);
+#ifdef __STDC__
+extern void packerPrintf(Packer *p, const char *fmt, ...);
+#else
+extern void packerPrintf();
+#endif
+
+
/* see debug.c for info on context-based debugging */
extern Ctx ctx_enter(const char *descr);
extern void ctx_exit(Ctx ctx);
extern int httpAnonDenied(const char *line);
extern void httpInit(void);
+/* Http Status Line */
+/* init/clean */
+extern void httpStatusLineInit(HttpStatusLine *sline);
+extern void httpStatusLineClean(HttpStatusLine *sline);
+/* set values */
+extern void httpStatusLineSet(HttpStatusLine *sline, double version,
+ http_status status, const char *reason);
+/* parse/pack */
+/* parse a 0-terminating buffer and fill internal structires; returns true on success */
+extern int httpStatusLineParse(HttpStatusLine *sline, const char *start,
+ const char *end);
+/* pack fields using Packer */
+extern void httpStatusLinePackInto(const HttpStatusLine *sline, Packer *p);
+
+/* Http Body */
+/* init/clean */
+extern void httpBodyInit(HttpBody *body);
+extern void httpBodyClean(HttpBody *body);
+/* get body ptr (always use this) */
+extern const char *httpBodyPtr(const HttpBody *body);
+/* set body, if freefunc is NULL the content will be copied, otherwise not */
+extern void httpBodySet(HttpBody *body, const char *content, int size,
+ FREE *freefunc);
+
+/* pack */
+extern void httpBodyPackInto(const HttpBody *body, Packer *p);
+
+
/* Http Header */
extern void httpHeaderInitModule();
/* create/init/clean/destroy */
/* store report about current header usage and other stats */
extern void httpHeaderStoreReport(StoreEntry *e);
+/* Http Reply */
+extern HttpReply *httpReplyCreate();
+extern void httpReplyInit(HttpReply *rep);
+extern void httpReplyClean(HttpReply *rep);
+extern void httpReplyDestroy(HttpReply *rep);
+/* reset: clean, then init */
+void httpReplyReset(HttpReply *rep);
+/* absorb: copy the contents of a new reply to the old one, destroy new one */
+void httpReplyAbsorb(HttpReply *rep, HttpReply *new_rep);
+/* parse returns -1,0,+1 on error,need-more-data,success */
+extern int httpReplyParse(HttpReply *rep, const char *buf); /*, int atEnd); */
+extern void httpReplyPackInto(const HttpReply *rep, Packer *p);
+/* ez-routines */
+/* mem-pack: returns a ready to use mem buffer with a packed reply */
+extern MemBuf httpReplyPack(const HttpReply *rep);
+/* swap: create swap-based packer, pack, destroy packer */
+extern void httpReplySwapOut(const HttpReply *rep, StoreEntry *e);
+/* set commonly used info with one call */
+extern void httpReplySetHeaders(HttpReply *rep, double ver, http_status status,
+ const char *reason, const char *ctype, int clen, time_t lmt, time_t expires);
+/* do everything in one call: init, set, pack, clean, return MemBuf */
+extern MemBuf httpPackedReply(double ver, http_status status, const char *ctype,
+ int clen, time_t lmt, time_t expires);
+/* construct 304 reply and pack it into MemBuf, return MemBuf */
+extern MemBuf httpPacked304Reply(const HttpReply *rep);
+/* update when 304 reply is received for a cached object */
+extern void httpReplyUpdateOnNotModified(HttpReply *rep, HttpReply *freshRep);
+/* header manipulation, see HttpReply.c for caveats */
+extern int httpReplyContentLen(const HttpReply *rep);
+extern const char *httpReplyContentType(const HttpReply *rep);
+extern time_t httpReplyExpires(const HttpReply *rep);
+extern int httpReplyHasScc(const HttpReply *rep, http_scc_type type);
+
+
extern void icmpOpen(void);
extern void icmpClose(void);
extern void icmpPing(struct in_addr to);
hash_link *current_ptr;
};
+/* http status line */
+struct _HttpStatusLine {
+ /* public, read only */
+ double version;
+ const char *reason; /* points to a _constant_ string (default or supplied), never free()d */
+ http_status status;
+};
+
+/*
+ * Note: HttpBody is used only for messages with a small text content that is
+ * known a priory (e.g., error messages).
+ */
+struct _HttpBody {
+ /* private, never dereference these */
+ char *buf; /* null terminating _text_ buffer, not for binary stuff */
+ FREE *freefunc; /* used to free() .buf */
+ int size;
+};
+
+
/* server cache control */
struct _HttpScc {
int mask;
};
-#include "HttpReply.h"
+struct _HttpReply {
+ /* unsupported, writable, may disappear/change in the future */
+ int hdr_sz; /* sums _stored_ status-line, headers, and <CRLF> */
+
+ /* public, readable */
+ HttpMsgParseState pstate; /* the current parsing state */
+ /* public, writable, but use interfaces below when possible */
+ HttpStatusLine sline;
+ HttpHeader hdr;
+ HttpBody body; /* used for small constant memory-resident text bodies only */
+};
struct _HttpStateData {
FREE *freefunc; /* what to use to free the buffer, NULL after memBufFreeFunc() is called */
};
+/* see Packer.c for description */
+struct _Packer {
+ /* protected, use interface functions instead */
+ append_f append;
+ vprintf_f vprintf;
+ void *real_handler; /* first parameter to real append and vprintf */
+};
+
struct _mem_node {
char *data;
struct _store_client *next;
};
-#include "Packer.h"
/* This structure can be freed while object is purged out from memory */
struct _MemObject {
typedef struct _http_reply http_reply;
#else
typedef struct _HttpReply http_reply;
+typedef struct _HttpStatusLine HttpStatusLine;
typedef struct _HttpHeader HttpHeader;
typedef struct _HttpScc HttpScc;
typedef struct _HttpHeaderExtField HttpHeaderExtField;
typedef struct _HttpHeaderEntry HttpHeaderEntry;
typedef union _field_store field_store;
+typedef struct _HttpBody HttpBody;
+typedef struct _HttpReply HttpReply;
#endif
typedef struct _HttpStateData HttpStateData;
typedef struct _icpUdpData icpUdpData;
typedef struct _ipcache_entry ipcache_entry;
typedef struct _domain_ping domain_ping;
typedef struct _domain_type domain_type;
+typedef struct _Packer Packer;
typedef struct _peer peer;
typedef struct _net_db_name net_db_name;
typedef struct _net_db_peer net_db_peer;
typedef double (*hbase_f)(double);
typedef void (*StatHistBinDumper)(StoreEntry *, int idx, double val, double size, int count);
+
+/* append/vprintf's for Packer */
+typedef void (*append_f)(void *, const char *buf, int size);
+#ifdef __STDC__
+typedef void (*vprintf_f)(void *, const char *fmt, ...);
+#else
+typedef void (*vprintf_f)();
+#endif
+
/* MD5 cache keys */
typedef unsigned char cache_key;