void redirectStart(clientHttpRequest * http, RH * handler, void *data) { ConnStateData *conn = http->conn; redirectStateData *r = NULL; const char *fqdn; char *urlgroup = conn->port->urlgroup; char buf[8192]; char claddr[20]; char myaddr[20]; assert(http); assert(handler); debug(61, 5) ("redirectStart: '%s'\n", http->uri); if (Config.onoff.redirector_bypass && redirectors->stats.queue_size) { /* Skip redirector if there is one request queued */ n_bypassed++; handler(data, NULL); return; } r = cbdataAlloc(redirectStateData); r->orig_url = xstrdup(http->uri); r->client_addr = conn->log_addr; r->client_ident = NULL; if (http->request->auth_user_request) r->client_ident = authenticateUserRequestUsername(http->request->auth_user_request); else if (http->request->extacl_user) { r->client_ident = http->request->extacl_user; } if (!r->client_ident && conn->rfc931[0]) r->client_ident = conn->rfc931; #if USE_SSL if (!r->client_ident) r->client_ident = sslGetUserEmail(fd_table[conn->fd].ssl); #endif if (!r->client_ident) r->client_ident = dash_str; r->method_s = http->request->method->string; r->handler = handler; r->data = data; cbdataLock(r->data); if ((fqdn = fqdncache_gethostbyaddr(r->client_addr, 0)) == NULL) fqdn = dash_str; xstrncpy(claddr, inet_ntoa(r->client_addr), 20); xstrncpy(myaddr, inet_ntoa(http->request->my_addr), 20); snprintf(buf, 8191, "%s %s/%s %s %s %s myip=%s myport=%d", r->orig_url, claddr, fqdn, r->client_ident[0] ? rfc1738_escape(r->client_ident) : dash_str, r->method_s, urlgroup ? urlgroup : "-", myaddr, http->request->my_port); debug(61, 6) ("redirectStart: sending '%s' to the helper\n", buf); strcat(buf, "\n"); helperSubmit(redirectors, buf, redirectHandleReply, r); }
void redirectStart(clientHttpRequest * http, RH * handler, void *data) { ConnStateData *conn = http->conn; redirectStateData *r = NULL; const char *fqdn; char buf[8192]; assert(http); assert(handler); debug(61, 5) ("redirectStart: '%s'\n", http->uri); if (Config.onoff.redirector_bypass && redirectors->stats.queue_size) { /* Skip redirector if there is one request queued */ n_bypassed++; handler(data, NULL); return; } r = cbdataAlloc(redirectStateData); r->orig_url = xstrdup(http->uri); r->client_addr = conn->log_addr; if (http->request->auth_user_request) r->client_ident = authenticateUserRequestUsername(http->request->auth_user_request); else if (conn->rfc931[0]) { r->client_ident = conn->rfc931; } else { r->client_ident = dash_str; } r->method_s = RequestMethodStr[http->request->method]; r->handler = handler; r->data = data; cbdataLock(r->data); if ((fqdn = fqdncache_gethostbyaddr(r->client_addr, 0)) == NULL) fqdn = dash_str; snprintf(buf, 8192, "%s %s/%s %s %s\n", r->orig_url, inet_ntoa(r->client_addr), fqdn, r->client_ident[0] ? rfc1738_escape(r->client_ident) : dash_str, r->method_s); helperSubmit(redirectors, buf, redirectHandleReply, r); }
static void clientRecvFd(int sock, void *data) { int retval; struct msghdr msg; struct iovec vec; char cmsgbuf[CMSG_SPACE(sizeof(int))]; struct cmsghdr *p_cmsg; char iov_buf[CACHE_WATCH_RECV_MSG_LENGTH]; vec.iov_base = iov_buf; vec.iov_len = CACHE_WATCH_RECV_MSG_LENGTH; msg.msg_name = NULL; msg.msg_namelen = 0; msg.msg_iov = &vec; msg.msg_iovlen = 1; msg.msg_control = cmsgbuf; msg.msg_controllen = sizeof(cmsgbuf); msg.msg_flags = 0; /* In case something goes wrong, set the fd to -1 before the syscall */ retval = recvmsg(sock, &msg, 0); if( retval <= 0 ) { comm_close(sock); return; } if( (p_cmsg = CMSG_FIRSTHDR(&msg)) == NULL ) { comm_close(sock); return; } if (squidWatchReply(sock, &msg, iov_buf) != -1) { comm_close(sock); return; } int fd = *((int*)CMSG_DATA(p_cmsg)); // for keep alive commSetSelect(sock, COMM_SELECT_READ, clientRecvFd, NULL, 0); // omm_close(sock); if(fd < 0) { return; } //comm_accept's jobs struct sockaddr_in peername; struct sockaddr_in sockname; socklen_t socklen; socklen = sizeof(struct sockaddr_in); memset(&peername, '\0', socklen); memset(&sockname, '\0', socklen); getpeername(fd, (struct sockaddr *)&peername, &socklen); getsockname(fd, (struct sockaddr *)&sockname, &socklen); commSetCloseOnExec(fd); fd_open(fd, FD_SOCKET, "HTTP Request"); fde *F = &fd_table[fd]; xstrncpy(F->ipaddr, xinet_ntoa(peername.sin_addr), 16); F->remote_port = htons(peername.sin_port); F->local_port = htons(sockname.sin_port); commSetNonBlocking(fd); //rest of httpAccept's jobs // //int on = 1; //if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *) &on, sizeof(on)) < 0) // debug(191, 0) ("commSetTcpNoDelay: FD %d: %s\n", fd, xstrerror()); //fd_table[fd].flags.nodelay = 1; #ifdef TCP_NODELAY commSetTcpNoDelay(fd); /*Fix tcp use Negale bug while send packet*/ #endif #ifdef CC_FRAMEWORK cc_call_hook_func_private_http_accept(fd); #endif debug(191, 4) ("clientRecvFd: FD %d: accepted port %d client %s:%d\n", fd, F->local_port, F->ipaddr, F->remote_port); fd_note_static(fd, "client http connect"); ConnStateData * connState = cbdataAlloc(ConnStateData); assert(Config.Sockaddr.http); connState->port = Config.Sockaddr.http; cbdataLock(connState->port); connState->peer = peername; connState->log_addr = peername.sin_addr; connState->log_addr.s_addr &= Config.Addrs.client_netmask.s_addr; connState->me = sockname; connState->fd = fd; connState->pinning.fd = -1; connState->in.buf = memAllocBuf(CLIENT_REQ_BUF_SZ, &connState->in.size); comm_add_close_handler(fd, connStateFree, connState); if (Config.onoff.log_fqdn) fqdncache_gethostbyaddr(peername.sin_addr, FQDN_LOOKUP_IF_MISS); commSetTimeout(fd, Config.Timeout.request, requestTimeout, connState); #if USE_IDENT static aclCheck_t identChecklist; identChecklist.src_addr = peername.sin_addr; identChecklist.my_addr = sockname.sin_addr; identChecklist.my_port = ntohs(sockname.sin_port); if (aclCheckFast(Config.accessList.identLookup, &identChecklist)) identStart(&sockname, &peername, clientIdentDone, connState); #endif commSetSelect(fd, COMM_SELECT_READ, clientReadRequest, connState, 0); commSetDefer(fd, clientReadDefer, connState); if (connState->port->tcp_keepalive.enabled) { commSetTcpKeepalive(fd, connState->port->tcp_keepalive.idle, connState->port->tcp_keepalive.interval, connState->port->tcp_keepalive.timeout); } clientdbEstablished(peername.sin_addr, 1); incoming_sockets_accepted++; }