]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Spread HttpBody.h, HttpReply.h, HttpStatusLine.h, and Packer.h among
authorrousskov <>
Thu, 26 Feb 1998 15:10:52 +0000 (15:10 +0000)
committerrousskov <>
Thu, 26 Feb 1998 15:10:52 +0000 (15:10 +0000)
 .h monsters.

ChangeLog
src/HttpBody.cc
src/HttpReply.cc
src/HttpStatusLine.cc
src/Packer.cc
src/client_side.cc
src/enums.h
src/protos.h
src/structs.h
src/typedefs.h

index 92873ce926c347e77d354ccb32ce5a5d2848f1bc..1e440acd42221ba73ffe11282baa6b251293199b 100644 (file)
--- 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.
index ce2fa7f707d4971b3492ebffea5794d4103cdd3b..513ba8db6031f55c7dc6c40eb84208e4997c7d68 100644 (file)
@@ -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)
 {
index 70ac733f646c7cd2e2a193bd1911f6caa18db435..6a2b6ed6a8b7f6168d7c9715365258a46b808869 100644 (file)
@@ -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)
 {
index a7e1f31d9d241e85a4079296f74b8c1c103f5674..0a957f7e85b26f08740a78fe0b6aa36e70e83171 100644 (file)
@@ -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);
index 462f2b5cca32660b03659760f49a21ca44b9d455..591f9fc422bc7cc8972f95900c74be1ba96fce6e 100644 (file)
@@ -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
  *  
  */
 
-/* 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)
 {
index c95f445ef68068181d3201d2606c5673cd9bcf58..1af01c947e814e5e9679f74409f48fe95f3d7a19 100644 (file)
@@ -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,
index c82e0c4584808fce5fd5eea85d4093ad47522bdf..52d9b19cfef92916ab89a312eea04b42faa9deb0 100644 (file)
@@ -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;
index df13188d784c0d486846d6ea6f1de33d0d9fea07..070019ced7e2228fa0f5410e519839c66eccabf5 100644 (file)
@@ -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);
index 01203a455b220665d417f92856a356f1c79d6289..015180085e047d43f83c07be6eeca386fdf84007 100644 (file)
@@ -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 <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 {
@@ -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 {
index d8a8b94e9668a75c7295e96cf0be5f655e2c1dcb..c70c6347647df4f5877ae33a8162dc73a7ac9174 100644 (file)
@@ -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;