/* add client with fd to client list */ void storeClientListAdd(StoreEntry * e, void *data) { MemObject *mem = e->mem_obj; store_client **T; store_client *sc; assert(mem); if (storeClientListSearch(mem, data) != NULL) return; e->refcount++; mem->nclients++; sc = memAllocate(MEM_STORE_CLIENT); cbdataAdd(sc, memFree, MEM_STORE_CLIENT); /* sc is callback_data for file_read */ cbdataLock(data); /* locked while we point to it */ sc->callback_data = data; sc->seen_offset = 0; sc->copy_offset = 0; sc->flags.disk_io_pending = 0; sc->entry = e; sc->type = storeClientType(e); if (sc->type == STORE_DISK_CLIENT) /* assert we'll be able to get the data we want */ /* maybe we should open swapin_fd here */ assert(e->swap_file_number > -1 || storeSwapOutAble(e)); for (T = &mem->clients; *T; T = &(*T)->next); *T = sc; #if DELAY_POOLS sc->delay_id = 0; #endif }
void urnStart(request_t * r, StoreEntry * e) { LOCAL_ARRAY(char, urlres, 4096); request_t *urlres_r = NULL; const char *t; char *host; UrnState *urnState; StoreEntry *urlres_e; ErrorState *err; debug(52, 3) ("urnStart: '%s'\n", storeUrl(e)); urnState = xcalloc(1, sizeof(UrnState)); urnState->entry = e; urnState->request = requestLink(r); cbdataAdd(urnState, cbdataXfree, 0); storeLockObject(urnState->entry); if (strncasecmp(strBuf(r->urlpath), "menu.", 5) == 0) { char *new_path = xstrdup(strBuf(r->urlpath) + 5); urnState->flags.force_menu = 1; stringReset(&r->urlpath, new_path); xfree(new_path); } if ((t = strChr(r->urlpath, ':')) != NULL) { strSet(r->urlpath, t, '\0'); host = xstrdup(strBuf(r->urlpath)); strSet(r->urlpath, t, ':'); } else { host = xstrdup(strBuf(r->urlpath)); } snprintf(urlres, 4096, "http://%s/uri-res/N2L?urn:%s", host, strBuf(r->urlpath)); safe_free(host); urlres_r = urlParse(METHOD_GET, urlres); if (urlres_r == NULL) { debug(52, 3) ("urnStart: Bad uri-res URL %s\n", urlres); err = errorCon(ERR_URN_RESOLVE, HTTP_NOT_FOUND); err->url = xstrdup(urlres); errorAppendEntry(e, err); return; } httpHeaderPutStr(&urlres_r->header, HDR_ACCEPT, "text/plain"); if ((urlres_e = storeGetPublic(urlres, METHOD_GET)) == NULL) { urlres_e = storeCreateEntry(urlres, urlres, null_request_flags, METHOD_GET); storeClientListAdd(urlres_e, urnState); fwdStart(-1, urlres_e, urlres_r); } else { storeLockObject(urlres_e); storeClientListAdd(urlres_e, urnState); } urnState->urlres_e = urlres_e; urnState->urlres_r = requestLink(urlres_r); storeClientCopy(urlres_e, 0, 0, 4096, memAllocate(MEM_4K_BUF), urnHandleReply, urnState); }
void start_announce(void *datanotused) { void *junk; if (0 == Config.onoff.announce) return; if (theOutIcpConnection < 0) return; cbdataAdd(junk = xmalloc(1), cbdataXfree, 0); ipcache_nbgethostbyname(Config.Announce.host, send_announce, junk); eventAdd("send_announce", start_announce, NULL, (double) Config.Announce.period, 1); }
/* allocate new peer digest, call Init, and lock everything */ PeerDigest * peerDigestCreate(peer * p) { PeerDigest *pd; assert(p); pd = memAllocate(MEM_PEER_DIGEST); cbdataAdd(pd, memFree, MEM_PEER_DIGEST); peerDigestInit(pd, p); cbdataLock(pd->peer); /* we will use the peer */ return pd; }
void authenticateStart(acl_proxy_auth_user * auth_user, RH * handler, void *data) { authenticateStateData *r = NULL; char buf[8192]; assert(auth_user); assert(handler); debug(29, 5) ("authenticateStart: '%s:%s'\n", auth_user->user, auth_user->passwd); if (Config.Program.authenticate == NULL) { handler(data, NULL); return; } r = xcalloc(1, sizeof(authenticateStateData)); cbdataAdd(r, cbdataXfree, 0); r->handler = handler; cbdataLock(data); r->data = data; r->auth_user = auth_user; snprintf(buf, 8192, "%s %s\n", r->auth_user->user, r->auth_user->passwd); helperSubmit(authenticators, buf, authenticateHandleReply, r); }
/* ask store for a digest */ static void peerDigestRequest(PeerDigest * pd) { peer *p = pd->peer; StoreEntry *e, *old_e; char *url; const cache_key *key; request_t *req; DigestFetchState *fetch = NULL; pd->req_result = NULL; pd->flags.requested = 1; /* compute future request components */ if (p->digest_url) url = xstrdup(p->digest_url); else url = internalRemoteUri(p->host, p->http_port, "/squid-internal-periodic/", StoreDigestFileName); key = storeKeyPublic(url, METHOD_GET); debug(72, 2) ("peerDigestRequest: %s key: %s\n", url, storeKeyText(key)); req = urlParse(METHOD_GET, url); assert(req); /* add custom headers */ assert(!req->header.len); httpHeaderPutStr(&req->header, HDR_ACCEPT, StoreDigestMimeStr); httpHeaderPutStr(&req->header, HDR_ACCEPT, "text/html"); if (p->login) xstrncpy(req->login, p->login, MAX_LOGIN_SZ); /* create fetch state structure */ fetch = memAllocate(MEM_DIGEST_FETCH_STATE); cbdataAdd(fetch, memFree, MEM_DIGEST_FETCH_STATE); fetch->request = requestLink(req); fetch->pd = pd; fetch->offset = 0; /* update timestamps */ fetch->start_time = squid_curtime; pd->times.requested = squid_curtime; pd_last_req_time = squid_curtime; req->flags.cachable = 1; /* the rest is based on clientProcessExpired() */ req->flags.refresh = 1; old_e = fetch->old_entry = storeGet(key); if (old_e) { debug(72, 5) ("peerDigestRequest: found old entry\n"); storeLockObject(old_e); storeCreateMemObject(old_e, url, url); storeClientListAdd(old_e, fetch); } e = fetch->entry = storeCreateEntry(url, url, req->flags, req->method); assert(EBIT_TEST(e->flags, KEY_PRIVATE)); storeClientListAdd(e, fetch); /* set lastmod to trigger IMS request if possible */ if (old_e) e->lastmod = old_e->lastmod; /* push towards peer cache */ debug(72, 3) ("peerDigestRequest: forwarding to fwdStart...\n"); fwdStart(-1, e, req); cbdataLock(fetch); cbdataLock(fetch->pd); storeClientCopy(e, 0, 0, 4096, memAllocate(MEM_4K_BUF), peerDigestFetchReply, fetch); }
void sslStart(int fd, const char *url, request_t * request, size_t * size_ptr) { /* Create state structure. */ SslStateData *sslState = NULL; int sock; ErrorState *err = NULL; debug(26, 3) ("sslStart: '%s %s'\n", RequestMethodStr[request->method], url); Counter.server.all.requests++; Counter.server.other.requests++; /* Create socket. */ sock = comm_open(SOCK_STREAM, 0, Config.Addrs.tcp_outgoing, 0, COMM_NONBLOCKING, url); if (sock == COMM_ERROR) { debug(26, 4) ("sslStart: Failed because we're out of sockets.\n"); err = errorCon(ERR_SOCKET_FAILURE, HTTP_INTERNAL_SERVER_ERROR); err->xerrno = errno; err->request = requestLink(request); errorSend(fd, err); return; } sslState = xcalloc(1, sizeof(SslStateData)); cbdataAdd(sslState, cbdataXfree, 0); #if DELAY_POOLS sslState->delay_id = delayClient(request); delayRegisterDelayIdPtr(&sslState->delay_id); #endif sslState->url = xstrdup(url); sslState->request = requestLink(request); sslState->size_ptr = size_ptr; sslState->client.fd = fd; sslState->server.fd = sock; sslState->server.buf = xmalloc(SQUID_TCP_SO_RCVBUF); sslState->client.buf = xmalloc(SQUID_TCP_SO_RCVBUF); comm_add_close_handler(sslState->server.fd, sslServerClosed, sslState); comm_add_close_handler(sslState->client.fd, sslClientClosed, sslState); commSetTimeout(sslState->client.fd, Config.Timeout.lifetime, sslTimeout, sslState); commSetTimeout(sslState->server.fd, Config.Timeout.connect, sslTimeout, sslState); peerSelect(request, NULL, sslPeerSelectComplete, sslState); /* * Disable the client read handler until peer selection is complete * Take control away from client_side.c. */ commSetSelect(sslState->client.fd, COMM_SELECT_READ, NULL, NULL, 0); }