From: rousskov <> Date: Thu, 26 Feb 1998 15:10:52 +0000 (+0000) Subject: Spread HttpBody.h, HttpReply.h, HttpStatusLine.h, and Packer.h among X-Git-Tag: SQUID_3_0_PRE1~3976 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=adba4a64d6e0aa8bc0f8f3df38141f1cce7b8e0c;p=thirdparty%2Fsquid.git Spread HttpBody.h, HttpReply.h, HttpStatusLine.h, and Packer.h among .h monsters. --- diff --git a/ChangeLog b/ChangeLog index 92873ce926..1e440acd42 100644 --- a/ChangeLog +++ b/ChangeLog @@ -40,7 +40,8 @@ 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. diff --git a/src/HttpBody.cc b/src/HttpBody.cc index ce2fa7f707..513ba8db60 100644 --- a/src/HttpBody.cc +++ b/src/HttpBody.cc @@ -1,5 +1,5 @@ /* - * $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 @@ -56,6 +56,7 @@ httpBodyClean(HttpBody *body) 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) { diff --git a/src/HttpReply.cc b/src/HttpReply.cc index 70ac733f64..6a2b6ed6a8 100644 --- a/src/HttpReply.cc +++ b/src/HttpReply.cc @@ -1,5 +1,5 @@ /* - * $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 @@ -175,16 +175,7 @@ httpPacked304Reply(const HttpReply *rep) 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)) @@ -232,6 +223,24 @@ httpReplySetHeaders(HttpReply *reply, double ver, http_status status, const char 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) { diff --git a/src/HttpStatusLine.cc b/src/HttpStatusLine.cc index a7e1f31d9d..0a957f7e85 100644 --- a/src/HttpStatusLine.cc +++ b/src/HttpStatusLine.cc @@ -1,5 +1,5 @@ /* - * $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 @@ -37,6 +37,8 @@ const char *HttpStatusLineFormat = "HTTP/%3.1f %3d %s\r\n"; /* local routines */ static const char *httpStatusString(http_status status); + + void httpStatusLineInit(HttpStatusLine *sline) { httpStatusLineSet(sline, 0.0, 0, NULL); @@ -47,6 +49,7 @@ httpStatusLineClean(HttpStatusLine *sline) { 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; @@ -55,6 +58,7 @@ void httpStatusLineSet(HttpStatusLine *sline, double version, http_status status sline->reason = reason; } +/* parse a 0-terminating buffer and fill internal structires; returns true on success */ void httpStatusLinePackInto(const HttpStatusLine *sline, Packer *p) { @@ -67,6 +71,7 @@ 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); diff --git a/src/Packer.cc b/src/Packer.cc index 462f2b5cca..591f9fc422 100644 --- a/src/Packer.cc +++ b/src/Packer.cc @@ -1,5 +1,5 @@ /* - * $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 @@ -28,7 +28,38 @@ * */ -/* 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: @@ -64,6 +95,9 @@ static void (*const store_vprintf)(StoreEntry *, const char *, va_list ap) = &st 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) { @@ -73,6 +107,7 @@ packerToStoreInit(Packer *p, StoreEntry *e) p->real_handler = e; } +/* init with this to accumulate data in MemBuf */ void packerToMemInit(Packer *p, MemBuf *mb) { @@ -82,6 +117,7 @@ packerToMemInit(Packer *p, MemBuf *mb) p->real_handler = mb; } +/* call this when you are done */ void packerClean(Packer *p) { diff --git a/src/client_side.cc b/src/client_side.cc index c95f445ef6..1af01c947e 100644 --- a/src/client_side.cc +++ b/src/client_side.cc @@ -1,6 +1,6 @@ /* - * $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 @@ -864,6 +864,7 @@ clientAppendReplyHeader(char *hdr, const char *line, size_t * sz, size_t max) *sz = n; } +/* this entire function has to be rewriten using new interfaces @?@ @?@ */ size_t clientBuildReplyHeader(clientHttpRequest * http, char *hdr_in, diff --git a/src/enums.h b/src/enums.h index c82e0c4584..52d9b19cfe 100644 --- a/src/enums.h +++ b/src/enums.h @@ -531,3 +531,12 @@ typedef enum { SWAP_LOG_DEL, SWAP_LOG_MAX } swap_log_op; + + +/* parse state of HttpReply or HttpRequest */ +typedef enum { + psReadyToParseStartLine = 0, + psReadyToParseHeaders, + psParsed, + psError +} HttpMsgParseState; diff --git a/src/protos.h b/src/protos.h index df13188d78..070019ced7 100644 --- a/src/protos.h +++ b/src/protos.h @@ -114,6 +114,17 @@ extern int commSetTimeout(int fd, int, PF *, void *); 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); @@ -218,6 +229,34 @@ extern int httpAnonAllowed(const char *line); 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 */ @@ -246,6 +285,40 @@ int httpHeaderDelFields(HttpHeader *hdr, const char *name); /* 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); diff --git a/src/structs.h b/src/structs.h index 01203a455b..015180085e 100644 --- a/src/structs.h +++ b/src/structs.h @@ -444,6 +444,26 @@ struct _hash_table { 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; @@ -471,8 +491,18 @@ struct _HttpHeader { }; -#include "HttpReply.h" +struct _HttpReply { + /* unsupported, writable, may disappear/change in the future */ + int hdr_sz; /* sums _stored_ status-line, headers, and */ + + /* 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 { @@ -809,6 +839,14 @@ struct _MemBuf { 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; @@ -837,7 +875,6 @@ struct _store_client { struct _store_client *next; }; -#include "Packer.h" /* This structure can be freed while object is purged out from memory */ struct _MemObject { diff --git a/src/typedefs.h b/src/typedefs.h index d8a8b94e96..c70c634764 100644 --- a/src/typedefs.h +++ b/src/typedefs.h @@ -46,11 +46,14 @@ typedef struct _hash_table hash_table; 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; @@ -60,6 +63,7 @@ typedef struct _ipcache_addrs ipcache_addrs; 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; @@ -125,6 +129,15 @@ typedef void STVLDCB(void *, int, int); 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;