--------------------- PatchSet 2193 Date: 2001/05/03 14:09:29 Author: rbcollins Branch: newhttp Tag: (none) Log: another step. cleaner code Members: src/cbdata.c:1.1.1.2.12.4.4.2->1.1.1.2.12.4.4.2.2.1 src/enums.h:1.1.1.3.8.8.4.7->1.1.1.3.8.8.4.7.2.1 src/forward.c:1.1.1.3.8.7.2.3.2.2->1.1.1.3.8.7.2.3.2.3 src/http.c:1.1.1.3.4.1.4.12.2.16.2.3->1.1.1.3.4.1.4.12.2.16.2.4 src/peer_select.c:1.1.1.3.8.4.4.4.2.1->1.1.1.3.8.4.4.4.2.2 src/structs.h:1.1.1.3.4.1.4.12.2.26.2.3->1.1.1.3.4.1.4.12.2.26.2.4 Index: squid/src/cbdata.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/cbdata.c,v retrieving revision 1.1.1.2.12.4.4.2 retrieving revision 1.1.1.2.12.4.4.2.2.1 diff -u -r1.1.1.2.12.4.4.2 -r1.1.1.2.12.4.4.2.2.1 --- squid/src/cbdata.c 31 Mar 2001 11:28:54 -0000 1.1.1.2.12.4.4.2 +++ squid/src/cbdata.c 3 May 2001 14:09:29 -0000 1.1.1.2.12.4.4.2.2.1 @@ -1,6 +1,6 @@ /* - * $Id: cbdata.c,v 1.1.1.2.12.4.4.2 2001/03/31 11:28:54 rbcollins Exp $ + * $Id: cbdata.c,v 1.1.1.2.12.4.4.2.2.1 2001/05/03 14:09:29 rbcollins Exp $ * * DEBUG: section 45 Callback Data Registry * ORIGINAL AUTHOR: Duane Wessels @@ -143,7 +143,6 @@ CREATE_CBDATA(helper_server); CREATE_CBDATA(statefulhelper); CREATE_CBDATA(helper_stateful_server); - CREATE_CBDATA(HttpStateData); CREATE_CBDATA_FREE(peer, peerDestroy); CREATE_CBDATA(ps_state); CREATE_CBDATA(RemovalPolicy); Index: squid/src/enums.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/enums.h,v retrieving revision 1.1.1.3.8.8.4.7 retrieving revision 1.1.1.3.8.8.4.7.2.1 diff -u -r1.1.1.3.8.8.4.7 -r1.1.1.3.8.8.4.7.2.1 --- squid/src/enums.h 27 Apr 2001 14:38:38 -0000 1.1.1.3.8.8.4.7 +++ squid/src/enums.h 3 May 2001 14:09:29 -0000 1.1.1.3.8.8.4.7.2.1 @@ -1,6 +1,6 @@ /* - * $Id: enums.h,v 1.1.1.3.8.8.4.7 2001/04/27 14:38:38 rbcollins Exp $ + * $Id: enums.h,v 1.1.1.3.8.8.4.7.2.1 2001/05/03 14:09:29 rbcollins Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -689,7 +689,6 @@ CBDATA_helper_server, CBDATA_statefulhelper, CBDATA_helper_stateful_server, - CBDATA_HttpStateData, CBDATA_peer, CBDATA_ps_state, CBDATA_RemovalPolicy, Index: squid/src/forward.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/forward.c,v retrieving revision 1.1.1.3.8.7.2.3.2.2 retrieving revision 1.1.1.3.8.7.2.3.2.3 diff -u -r1.1.1.3.8.7.2.3.2.2 -r1.1.1.3.8.7.2.3.2.3 --- squid/src/forward.c 2 May 2001 09:28:27 -0000 1.1.1.3.8.7.2.3.2.2 +++ squid/src/forward.c 3 May 2001 14:09:29 -0000 1.1.1.3.8.7.2.3.2.3 @@ -1,6 +1,6 @@ /* - * $Id: forward.c,v 1.1.1.3.8.7.2.3.2.2 2001/05/02 09:28:27 rbcollins Exp $ + * $Id: forward.c,v 1.1.1.3.8.7.2.3.2.3 2001/05/03 14:09:29 rbcollins Exp $ * * DEBUG: section 17 Request Forwarding * AUTHOR: Duane Wessels @@ -287,14 +287,14 @@ port = fs->peer->http_port; ctimeout = fs->peer->connect_timeout > 0 ? fs->peer->connect_timeout : Config.Timeout.peer_connect; - } else if (fwdState->request->flags.accelerated && + } else if (fwdState->http->request->flags.accelerated && Config.Accel.single_host && Config.Accel.host) { host = Config.Accel.host; port = Config.Accel.port; ctimeout = Config.Timeout.connect; } else { - host = fwdState->request->host; - port = fwdState->request->port; + host = fwdState->http->request->host; + port = fwdState->http->request->port; ctimeout = Config.Timeout.connect; } if ((fd = pconnPop(host, port)) >= 0) { @@ -315,7 +315,7 @@ debug(50, 4) ("fwdConnectStart: %s\n", xstrerror()); err = errorCon(ERR_SOCKET_FAILURE, HTTP_INTERNAL_SERVER_ERROR); err->xerrno = errno; - err->request = requestLink(fwdState->request); + err->request = requestLink(fwdState->http->request); fwdFail(fwdState, err); fwdStateFree(fwdState); return; @@ -449,11 +449,16 @@ fwdStateFree(fwdState); } +extern DATAFILTER_HDR http_server_req; +extern void *http_server_reqstate(FwdState *); + /* handoff to the server side protocol */ static void fwdDispatch(FwdState * fwdState) { + FILTER_list * temp_filter; + unsigned int rvflags; peer *p = NULL; request_t *request = fwdState->http->request; // StoreEntry *entry = fwdState->entry; @@ -473,15 +478,28 @@ * is closed. */ assert(fwdState->server_fd > -1); + /* a hierarchy request (note: assumes http peer) */ if (fwdState->servers && (p = fwdState->servers->peer)) { p->stats.fetches++; request->peer_login = p->login; httpStart(fwdState); } else { + /* a particular protocol peer */ request->peer_login = NULL; switch (request->protocol) { case PROTO_HTTP: - httpStart(fwdState); +// httpStart(fwdState); +/* MORE BROKENESS! fwdState is passed out of forward.c! in the old code */ + /* add the actual protocol to the chain */ + filterChainAddTail(&fwdState->http->reqfilters, identity_body, http_server_req, NULL, http_server_reqstate(fwdState)); + /* now call the http code */ + temp_filter = fwdState->filters->node.next->data; + rvflags = temp_filter->filter_hdr(fwdState->rep, fwdState->http, fwdState->filter_list, temp_filter, fwdState->filterflags, temp_filter->data); + /* we stay in the chain until a successful forward occurs or the request is canned/permanent faiure occurs */ + debug (17,2)("http filter returned %0x flags\n",rvflags); + /* CHECKME: we are finished with fwdState - if a proto needs it they lock it */ + cbdataUnlock(fwdState); + break; case PROTO_GOPHER: gopherStart(fwdState); Index: squid/src/http.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/http.c,v retrieving revision 1.1.1.3.4.1.4.12.2.16.2.3 retrieving revision 1.1.1.3.4.1.4.12.2.16.2.4 diff -u -r1.1.1.3.4.1.4.12.2.16.2.3 -r1.1.1.3.4.1.4.12.2.16.2.4 --- squid/src/http.c 2 May 2001 08:22:05 -0000 1.1.1.3.4.1.4.12.2.16.2.3 +++ squid/src/http.c 3 May 2001 14:09:30 -0000 1.1.1.3.4.1.4.12.2.16.2.4 @@ -1,6 +1,6 @@ /* - * $Id: http.c,v 1.1.1.3.4.1.4.12.2.16.2.3 2001/05/02 08:22:05 rbcollins Exp $ + * $Id: http.c,v 1.1.1.3.4.1.4.12.2.16.2.4 2001/05/03 14:09:30 rbcollins Exp $ * * DEBUG: section 11 Hypertext Transfer Protocol (HTTP) * AUTHOR: Harvest Derived @@ -55,6 +55,31 @@ static int httpCachableReply(HttpStateData *); static void httpMaybeRemovePublic(StoreEntry *, http_status); +/* this will go in a header when this file becomes a module */ +struct _HttpStateData { + StoreEntry *entry; + request_t *request; + char *reply_hdr; + size_t reply_hdr_size; + int reply_hdr_state; + size_t written; + size_t bodysize; + peer *peer; /* peer request made to */ + int eof; /* reached end-of-object? */ + request_t *orig_request; + int fd; + http_state_flags flags; + FwdState *fwd; + dlink_list filters; + /* How far into the network object are we? */ + size_t read_offset; + /* this should be for the ReplyHeaders filter */ + char *headerstore; + size_t headerlength; +}; + +CBDATA_TYPE(HttpStateData); + /* temporary function */ void serverHttpInit(void) @@ -1305,6 +1330,76 @@ comm_write_mbuf(httpState->fd, mb, sendHeaderDone, httpState); } +/* we're attached to an fd, and have a request to make */ +unsigned int +http_server_req(HttpReply *rep, httpClientRequest *request, + dlink_list * filter_list,FILTER_list * filters, unsigned int flags, + void *data) +{ + cfd=-1; + /* todo: + build a request + if we expect a body, attach the body filter, otherwise attach a dummy spitting + filter. + write the request + remove us from the list (we've done our bit). + -->the header function only get called once.. duh! + */ + fatal("end of code! (about to send request \n"); + } + + +/* create a HttpStateData variable for the server side functions to reference. */ +void * +http_server_reqstate(FwdState * fwd) +{ + HttpStateData *httpState; + CBDATA_INIT_TYPE(HttpStateData); + httpState=cbdataAlloc(HttpStateData); + httpState->fwd = fwd; + httpState->fd = fwd->server_fd; + httpState->read_offset=-1; /*-1 means we are waiting for a response, or in headers */ + httpState->peer = fwd->servers ? fwd->servers->peer : NULL; /* might be NULL */ + httpState->flags.proxying = httpState->peer ? 1 : 0; + /* + * Is keep-alive okay for all request methods? + */ + /* global */ + if (!Config.onoff.server_pconns) + httpState->flags.keepalive = 0; + /* "proxying" mean hierachy - keep alive non hierarchy requests always */ + else if (httpState->flags.proxying == 0) + httpState->flags.keepalive = 1; + /* for this peer, less that 10, always keep alive */ + else if (httpState->peer->stats.n_keepalives_sent < 10) + httpState->flags.keepalive = 1; + /* whats this magic for. I no understand - robert C */ + else if ((double) httpState->peer->stats.n_keepalives_recv / (double) httpState->peer->stats.n_keepalives_sent > 0.50) + httpState->flags.keepalive = 1; + if (httpState->peer && + (neighborType(httpState->peer, httpState->request) == PEER_SIBLING && + !httpState->peer->options.allow_miss) + httpState->flags.only_if_cached = 1; + + /* old code created a separate server-side request. uck. what we want is a clean + * two level structure - client side stuff in a list of attached clients, and server + * side stuff in the server request. + * It _looks_ like that was done to avoid having a peer host and port struct ! + * -Rob + */ + /* + * register the handler to free HTTP state data when the FD closes + */ + /* + * This may not be correct anymore: thanks to filters, one cancel should percolate + * through anyway. FIXME + */ + comm_add_close_handler(fd, httpStateFree, httpState); + statCounter.server.all.requests++; + statCounter.server.http.requests++; + return httpState; +} + void httpStart(FwdState * fwd) { Index: squid/src/peer_select.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/peer_select.c,v retrieving revision 1.1.1.3.8.4.4.4.2.1 retrieving revision 1.1.1.3.8.4.4.4.2.2 diff -u -r1.1.1.3.8.4.4.4.2.1 -r1.1.1.3.8.4.4.4.2.2 --- squid/src/peer_select.c 2 May 2001 08:22:05 -0000 1.1.1.3.8.4.4.4.2.1 +++ squid/src/peer_select.c 3 May 2001 14:09:30 -0000 1.1.1.3.8.4.4.4.2.2 @@ -1,6 +1,6 @@ /* - * $Id: peer_select.c,v 1.1.1.3.8.4.4.4.2.1 2001/05/02 08:22:05 rbcollins Exp $ + * $Id: peer_select.c,v 1.1.1.3.8.4.4.4.2.2 2001/05/03 14:09:30 rbcollins Exp $ * * DEBUG: section 44 Peer Selection Algorithm * AUTHOR: Duane Wessels @@ -538,15 +538,18 @@ /* * peerGetSomeDirect * - * Simply adds a 'direct' entry to the FwdServers list if this + * Added a 'direct' entry to the FwdServers list if this * request can be forwarded directly to the origin server + * + * However, this is protocol dependent! The caller should provide a protocol entry + * point for this function. - Robert */ static void peerGetSomeDirect(ps_state * ps) { if (ps->direct == DIRECT_NO) return; - if (ps->request->protocol == PROTO_WAIS) + if (ps->http->request->protocol == PROTO_WAIS) /* Its not really DIRECT, now is it? */ peerAddFwdServer(&ps->servers, Config.Wais.peer, DIRECT); else Index: squid/src/structs.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/structs.h,v retrieving revision 1.1.1.3.4.1.4.12.2.26.2.3 retrieving revision 1.1.1.3.4.1.4.12.2.26.2.4 diff -u -r1.1.1.3.4.1.4.12.2.26.2.3 -r1.1.1.3.4.1.4.12.2.26.2.4 --- squid/src/structs.h 2 May 2001 08:22:05 -0000 1.1.1.3.4.1.4.12.2.26.2.3 +++ squid/src/structs.h 3 May 2001 14:09:30 -0000 1.1.1.3.4.1.4.12.2.26.2.4 @@ -1,6 +1,6 @@ /* - * $Id: structs.h,v 1.1.1.3.4.1.4.12.2.26.2.3 2001/05/02 08:22:05 rbcollins Exp $ + * $Id: structs.h,v 1.1.1.3.4.1.4.12.2.26.2.4 2001/05/03 14:09:30 rbcollins Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -926,28 +926,6 @@ unsigned int only_if_cached:1; }; -struct _HttpStateData { - StoreEntry *entry; - request_t *request; - char *reply_hdr; - size_t reply_hdr_size; - int reply_hdr_state; - size_t written; - size_t bodysize; - peer *peer; /* peer request made to */ - int eof; /* reached end-of-object? */ - request_t *orig_request; - int fd; - http_state_flags flags; - FwdState *fwd; - dlink_list filters; - /* How far into the network object are we? */ - size_t read_offset; - /* this should be for the ReplyHeaders filter */ - char *headerstore; - size_t headerlength; -}; - struct _icpUdpData { struct sockaddr_in address; void *msg;