RemovalPolicy * createRemovalPolicy_lru(wordlist * args) { RemovalPolicy *policy; LruPolicyData *lru_data; /* no arguments expected or understood */ assert(!args); /* Initialize */ if (!lru_node_pool) lru_node_pool = memPoolCreate("LRU policy node", sizeof(LruNode)); /* Allocate the needed structures */ lru_data = xcalloc(1, sizeof(*lru_data)); policy = cbdataAlloc(RemovalPolicy); /* Initialize the URL data */ lru_data->policy = policy; /* Populate the policy structure */ policy->_type = "lru"; policy->_data = lru_data; policy->Free = lru_free; policy->Add = lru_add; policy->Remove = lru_remove; policy->Referenced = lru_referenced; policy->Dereferenced = lru_referenced; policy->WalkInit = lru_walkInit; policy->PurgeInit = lru_purgeInit; policy->Stats = lru_stats; /* Increase policy usage count */ nr_lru_policies += 0; return policy; }
/*parse config line*/ static int func_sys_parse_param(char *cfg_line) { struct mod_conf_param *data = NULL; char* token = NULL; int flag = 0; int temp; if ((token = strtok(cfg_line, w_space)) != NULL) { if(strcmp(token, "mod_no_cache_if_http_code")) goto err; } else { debug(190, 3)("(mod_no_cache_if_http_code) -> parse line error\n"); goto err; } if(NULL == mod_config_pool) { mod_config_pool = memPoolCreate("mod_no_cache_if_http_code config_struct", sizeof(struct mod_conf_param)); } data = memPoolAlloc(mod_config_pool); data->count = 0; while (NULL != (token = strtok(NULL, w_space))) { if(0 != strcmp(token, "allow") || 0 != strcmp(token, "deny")) { if(49 == data->count) { debug(190, 3)("mod_no_cache_if_http_code : there are 49 values of squid`s http_code totally.\n"); flag = 1; break; } if((temp = atoi(token)) >= 0) { data->http_code[data->count++] = temp; } else { flag = 1; debug(190, 3)("mod_no_cache_if_http_code : there is something wrong during parsing the http code in config line\n"); break; } } else { flag = 0; break; } } if(1 == flag) goto err; cc_register_mod_param(mod, data, free_callback); return 0; err: free_callback(data); return -1; }
static void authenticateAuthUserRequestLinkIp(auth_user_request_t * auth_user_request, const struct in_addr ipaddr, request_t * request) { auth_user_request_ip_hash_t *hash_entry; if (!Config.authenticateIpShortcircuitTTL) return; #ifdef CC_FRAMEWORK acl_access * acl = cc_get_acl_access_by_token_and_host("authenticate_ip_shortcircuit_access",request->host); if (acl && !aclCheckFastRequest(acl, request)) #else if (Config.accessList.auth_ip_shortcircuit && !aclCheckFastRequest(Config.accessList.auth_ip_shortcircuit, request)) #endif return; if (!auth_user_request_ip_hash) { auth_user_request_ip_hash = hash_create((HASHCMP *) cmp_in_addr, 7921, hash_in_addr); auth_user_request_ip_pool = memPoolCreate("auth_user_request_ip_hash_t", sizeof(auth_user_request_ip_hash_t)); } authenticateAuthUserRequestUnlinkIp(ipaddr); hash_entry = memPoolAlloc(auth_user_request_ip_pool); hash_entry->ipaddr = ipaddr; hash_entry->hash.key = &hash_entry->ipaddr; hash_entry->auth_user_request = auth_user_request; authenticateAuthUserRequestLock(hash_entry->auth_user_request); hash_entry->last_seen = squid_curtime; hash_join(auth_user_request_ip_hash, &hash_entry->hash); }
static void * mod_config_pool_alloc(void) { void * obj = NULL; if (NULL == mod_config_pool) { mod_config_pool = memPoolCreate("mod_check_response config_struct", sizeof(struct mod_conf_param)); } return obj = memPoolAlloc(mod_config_pool); }
static void *mod_config_pool_alloc(void) { void * obj = NULL; if (NULL == mod_config_pool) { mod_config_pool = memPoolCreate("mod_m3u8_prefetch config_struct", sizeof(mod_config)); } return obj = memPoolAlloc(mod_config_pool); }
static void * action_part_pool_alloc(void) { void * obj = NULL; if (NULL == action_part_pool) { action_part_pool = memPoolCreate("mod_header config_struct action_part", sizeof(struct action_part)); } return obj = memPoolAlloc(action_part_pool); }
static void * header_info_pool_alloc(void) { void * obj = NULL; if (NULL == header_info_pool) { header_info_pool = memPoolCreate("mod_header config_struct header_info", sizeof(struct header_info)); } return obj = memPoolAlloc(header_info_pool); }
static void * mod_config_pool_alloc(void) { void * obj = NULL; if(NULL == mod_config_pool) { mod_config_pool = memPoolCreate("mod_srv_side_errpage config_struct", sizeof(mod_config)); } return obj = memPoolAlloc(mod_config_pool); }
static void * text_mb_pool_alloc(void) { void * obj = NULL; if(NULL == text_mb_pool) { text_mb_pool = memPoolCreate("mod_srv_side_errpage private_data text", sizeof(MemBuf)); } return obj = memPoolAlloc(text_mb_pool); }
static void * timeout_pool_alloc(void) { void * obj = NULL; if(NULL == timeout_pool) { timeout_pool = memPoolCreate("mod_srv_side_errpage private_data timeout", sizeof(int)); } return obj = memPoolAlloc(timeout_pool); }
static void * error_page_private_data_pool_alloc(void) { void * obj = NULL; if (NULL == error_page_private_data_pool) { error_page_private_data_pool = memPoolCreate("mod_srv_side_errpage private_data error_page_private_data", sizeof(error_page_private_data)); } return obj = memPoolAlloc(error_page_private_data_pool); }
static void * request_param_pool_alloc(void) { void * obj = NULL; if (NULL == request_param_pool) { request_param_pool = memPoolCreate("mod_m3u8_prefetch private_data request_param", sizeof(request_param)); } return obj = memPoolAlloc(request_param_pool); }
static void * mod_config_pool_alloc(void) { void * obj = NULL; if (NULL == mod_config_pool) { mod_config_pool = memPoolCreate("mod_modify_s2o_header_name config_struct", sizeof(struct mod_conf_param)); } return obj = memPoolAlloc(mod_config_pool); }
void pconnInit(void) { int i; assert(table == NULL); table = hash_create((HASHCMP *) strcmp, 229, hash_string); for (i = 0; i < PCONN_HIST_SZ; i++) { client_pconn_hist[i] = 0; server_pconn_hist[i] = 0; } pconn_data_pool = memPoolCreate("pconn_data", sizeof(struct _pconn)); pconn_fds_pool = memPoolCreate("pconn_fds", PCONN_FDS_SZ * sizeof(int)); cachemgrRegister("pconn", "Persistent Connection Utilization Histograms", pconnHistDump, 0, 1); debug(48, 3) ("persistent connection module initialized\n"); }
static void * is_defer_func_pool_alloc(void) { void * obj = NULL; if (NULL == is_defer_func_pool) { is_defer_func_pool = memPoolCreate("mod_helper_defer other_data link_node", sizeof(is_defer_func)); } return obj = memPoolAlloc(is_defer_func_pool); }
void aioInit(void) { if (initialised) return; squidaio_ctrl_pool = memPoolCreate("aio_ctrl", sizeof(squidaio_ctrl_t)); cachemgrRegister("squidaio_counts", "Async IO Function Counters", aioStats, 0, 1); initialised = 1; }
static auth_user_request_t * authenticateAuthUserRequestNew(void) { auth_user_request_t *temp_request; if (!auth_user_request_pool) auth_user_request_pool = memPoolCreate("Authenticate Request Data", sizeof(auth_user_request_t)); temp_request = memPoolAlloc(auth_user_request_pool); assert(temp_request != NULL); memset(temp_request, '\0', sizeof(auth_user_request_t)); return temp_request; }
static void authenticateDigestNonceSetup(void) { if (!digest_nonce_pool) digest_nonce_pool = memPoolCreate("Digest Scheme nonce's", sizeof(digest_nonce_h)); if (!digest_nonce_cache) { digest_nonce_cache = hash_create((HASHCMP *) strcmp, 7921, hash_string); assert(digest_nonce_cache); eventAdd("Digest none cache maintenance", authenticateDigestNonceCacheCleanup, NULL, digestConfig->nonceGCInterval, 1); } }
/* Initialize helpers and the like for this auth scheme. Called AFTER parsing the * config file */ static void authNegotiateInit(authScheme * scheme) { static int negotiateinit = 0; if (negotiateConfig->authenticate) { /* * disable client side request pipelining. There is a race with * Negotiate when the client sends a second request on an Negotiate * connection before the authenticate challenge is sent. With * this patch, the client may fail to authenticate, but squid's * state will be preserved. */ if (negotiateConfig->authenticate && Config.onoff.pipeline_prefetch != 0) { debug(29, 1) ("pipeline prefetching incompatile with Negotiate authentication. Disabling pipeline_prefetch\n"); Config.onoff.pipeline_prefetch = 0; } if (!negotiate_user_pool) negotiate_user_pool = memPoolCreate("Negotiate Scheme User Data", sizeof(negotiate_user_t)); if (!negotiate_request_pool) negotiate_request_pool = memPoolCreate("Negotiate Scheme Request Data", sizeof(negotiate_request_t)); authnegotiate_initialised = 1; if (negotiateauthenticators == NULL) negotiateauthenticators = helperStatefulCreate("negotiateauthenticator"); negotiateauthenticators->cmdline = negotiateConfig->authenticate; negotiateauthenticators->n_to_start = negotiateConfig->authenticateChildren; negotiateauthenticators->ipc_type = IPC_STREAM; helperStatefulOpenServers(negotiateauthenticators); if (!negotiateinit) { cachemgrRegister("negotiateauthenticator", "Negotiate User Authenticator Stats", authenticateNegotiateStats, 0, 1); negotiateinit++; } CBDATA_INIT_TYPE(authenticateStateData); } }
void cbdataInitType(cbdata_type type, const char *name, int size, FREE * free_func) { char *label; if (type >= cbdata_types) { cbdata_index = xrealloc(cbdata_index, (type + 1) * sizeof(*cbdata_index)); memset(&cbdata_index[cbdata_types], 0, (type + 1 - cbdata_types) * sizeof(*cbdata_index)); cbdata_types = type + 1; } if (cbdata_index[type].pool) return; label = xmalloc(strlen(name) + 20); snprintf(label, strlen(name) + 20, "cbdata %s (%d)", name, (int) type); assert(OFFSET_OF(cbdata, data) == (sizeof(cbdata) - sizeof(((cbdata *) NULL)->data))); cbdata_index[type].pool = memPoolCreate(label, size + OFFSET_OF(cbdata, data)); cbdata_index[type].free_func = free_func; }
/* Initialize helpers and the like for this auth scheme. Called AFTER parsing the * config file */ static void authBasicInit(authScheme * scheme) { static int init = 0; if (basicConfig->authenticate) { if (!basic_data_pool) basic_data_pool = memPoolCreate("Basic Scheme User Data", sizeof(basic_data)); authbasic_initialised = 1; if (basicauthenticators == NULL) basicauthenticators = helperCreate("basicauthenticator"); basicauthenticators->cmdline = basicConfig->authenticate; basicauthenticators->n_to_start = basicConfig->authenticateChildren; basicauthenticators->concurrency = basicConfig->authenticateConcurrency; basicauthenticators->ipc_type = IPC_STREAM; helperOpenServers(basicauthenticators); if (!init) { cachemgrRegister("basicauthenticator", "Basic User Authenticator Stats", authenticateBasicStats, 0, 1); init++; } CBDATA_INIT_TYPE(authenticateStateData); } }
void squidaio_init(void) { int i; int done_pipe[2]; squidaio_thread_t *threadp; if (squidaio_initialised) return; if (!DuplicateHandle(GetCurrentProcess(), /* pseudo handle, don't close */ GetCurrentThread(), /* pseudo handle to copy */ GetCurrentProcess(), /* pseudo handle, don't close */ &main_thread, 0, /* required access */ FALSE, /* child process's don't inherit the handle */ DUPLICATE_SAME_ACCESS)) { /* spit errors */ fatal("couldn't get current thread handle\n"); } /* Initialize request queue */ if ((request_queue.mutex = CreateMutex(NULL, /* no inheritance */ FALSE, /* start unowned (as per mutex_init) */ NULL) /* no name */ ) == NULL) { fatal("failed to create mutex\n"); } if ((request_queue.cond = CreateEvent(NULL, /* no inheritance */ FALSE, /* auto signal reset - which I think is pthreads like ? */ FALSE, /* start non signaled */ NULL) /* no name */ ) == NULL) { fatal("failed to create condition event variable.\n"); } request_queue.head = NULL; request_queue.tailp = &request_queue.head; request_queue.requests = 0; request_queue.blocked = 0; /* Initialize done queue */ if ((done_queue.mutex = CreateMutex(NULL, /* no inheritance */ FALSE, /* start unowned (as per mutex_init) */ NULL) /* no name */ ) == NULL) { fatal("failed to create mutex\n"); } if ((done_queue.cond = CreateEvent(NULL, /* no inheritance */ TRUE, /* manually signaled - which I think is pthreads like ? */ FALSE, /* start non signaled */ NULL) /* no name */ ) == NULL) { fatal("failed to create condition event variable.\n"); } done_queue.head = NULL; done_queue.tailp = &done_queue.head; done_queue.requests = 0; done_queue.blocked = 0; /* Initialize done pipe signal */ pipe(done_pipe); done_fd = done_pipe[1]; done_fd_read = done_pipe[0]; fd_open(done_fd_read, FD_PIPE, "async-io completion event: main"); fd_open(done_fd, FD_PIPE, "async-io completion event: threads"); commSetNonBlocking(done_pipe[0]); commSetNonBlocking(done_pipe[1]); commSetCloseOnExec(done_pipe[0]); commSetCloseOnExec(done_pipe[1]); commSetSelect(done_pipe[0], COMM_SELECT_READ, squidaio_fdhandler, NULL, 0); /* Create threads and get them to sit in their wait loop */ squidaio_thread_pool = memPoolCreate("aio_thread", sizeof(squidaio_thread_t)); if (squidaio_nthreads == 0) { int j = 16; for (i = 0; i < n_asyncufs_dirs; i++) { squidaio_nthreads += j; j = j * 2 / 3; if (j < 4) j = 4; } #if USE_AUFSOPS j = 6; for (i = 0; i < n_coss_dirs; i++) { squidaio_nthreads += j; j = 3; } #endif } if (squidaio_nthreads == 0) squidaio_nthreads = 16; squidaio_magic1 = squidaio_nthreads * MAGIC1_FACTOR; squidaio_magic2 = squidaio_nthreads * MAGIC2_FACTOR; for (i = 0; i < squidaio_nthreads; i++) { threadp = memPoolAlloc(squidaio_thread_pool); threadp->status = _THREAD_STARTING; threadp->current_req = NULL; threadp->requests = 0; threadp->next = threads; threads = threadp; if ((threadp->thread = CreateThread(NULL, /* no security attributes */ 0, /* use default stack size */ squidaio_thread_loop, /* thread function */ threadp, /* argument to thread function */ 0, /* use default creation flags */ &(threadp->dwThreadId)) /* returns the thread identifier */ ) == NULL) { fprintf(stderr, "Thread creation failed\n"); threadp->status = _THREAD_FAILED; continue; } /* Set the new thread priority above parent process */ SetThreadPriority(threadp->thread, THREAD_PRIORITY_ABOVE_NORMAL); } /* Create request pool */ squidaio_request_pool = memPoolCreate("aio_request", sizeof(squidaio_request_t)); squidaio_large_bufs = memPoolCreate("squidaio_large_bufs", AIO_LARGE_BUFS); squidaio_medium_bufs = memPoolCreate("squidaio_medium_bufs", AIO_MEDIUM_BUFS); squidaio_small_bufs = memPoolCreate("squidaio_small_bufs", AIO_SMALL_BUFS); squidaio_tiny_bufs = memPoolCreate("squidaio_tiny_bufs", AIO_TINY_BUFS); squidaio_micro_bufs = memPoolCreate("squidaio_micro_bufs", AIO_MICRO_BUFS); squidaio_initialised = 1; }
static void authDigestUserSetup(void) { if (!digest_user_pool) digest_user_pool = memPoolCreate("Digest Scheme User Data", sizeof(digest_user_h)); }
void memInit(void) { int i; memInitModule(); /* set all pointers to null */ memset(MemPools, '\0', sizeof(MemPools)); /* * it does not hurt much to have a lot of pools since sizeof(MemPool) is * small; someday we will figure out what to do with all the entries here * that are never used or used only once; perhaps we should simply use * malloc() for those? @?@ */ memDataInit(MEM_2K_BUF, "2K Buffer", 2048, 10); memDataInit(MEM_4K_BUF, "4K Buffer", 4096, 10); memDataInit(MEM_8K_BUF, "8K Buffer", 8192, 10); memDataInit(MEM_16K_BUF, "16K Buffer", 16384, 10); memDataInit(MEM_32K_BUF, "32K Buffer", 32768, 10); memDataInit(MEM_64K_BUF, "64K Buffer", 65536, 10); memDataInit(MEM_CLIENT_SOCK_BUF, "Client Socket Buffer", CLIENT_SOCK_SZ, 0); memDataInit(MEM_ACL, "acl", sizeof(acl), 0); memDataInit(MEM_ACL_DENY_INFO_LIST, "acl_deny_info_list", sizeof(acl_deny_info_list), 0); memDataInit(MEM_ACL_IP_DATA, "acl_ip_data", sizeof(acl_ip_data), 0); memDataInit(MEM_ACL_LIST, "acl_list", sizeof(acl_list), 0); memDataInit(MEM_ACL_NAME_LIST, "acl_name_list", sizeof(acl_name_list), 0); #if USE_SSL memDataInit(MEM_ACL_CERT_DATA, "acl_cert_data", sizeof(acl_cert_data), 0); #endif memDataInit(MEM_ACL_TIME_DATA, "acl_time_data", sizeof(acl_time_data), 0); memDataInit(MEM_ACL_REQUEST_TYPE, "acl_request_type", sizeof(acl_request_type), 0); memDataInit(MEM_AUTH_USER_T, "auth_user_t", sizeof(auth_user_t), 0); memDataInit(MEM_AUTH_USER_HASH, "auth_user_hash_pointer", sizeof(auth_user_hash_pointer), 0); memDataInit(MEM_ACL_PROXY_AUTH_MATCH, "acl_proxy_auth_match_cache", sizeof(acl_proxy_auth_match_cache), 0); memDataInit(MEM_ACL_USER_DATA, "acl_user_data", sizeof(acl_user_data), 0); #if USE_CACHE_DIGESTS memDataInit(MEM_CACHE_DIGEST, "CacheDigest", sizeof(CacheDigest), 0); #endif memDataInit(MEM_LINK_LIST, "link_list", sizeof(link_list), 10); memDataInit(MEM_DLINK_NODE, "dlink_node", sizeof(dlink_node), 10); memDataInit(MEM_DREAD_CTRL, "dread_ctrl", sizeof(dread_ctrl), 0); memDataInit(MEM_DWRITE_Q, "dwrite_q", sizeof(dwrite_q), 0); memDataInit(MEM_FWD_SERVER, "FwdServer", sizeof(FwdServer), 0); memDataInit(MEM_HTTP_REPLY, "HttpReply", sizeof(HttpReply), 0); memDataInit(MEM_HTTP_HDR_ENTRY, "HttpHeaderEntry", sizeof(HttpHeaderEntry), 0); memDataInit(MEM_HTTP_HDR_CC, "HttpHdrCc", sizeof(HttpHdrCc), 0); memDataInit(MEM_HTTP_HDR_RANGE_SPEC, "HttpHdrRangeSpec", sizeof(HttpHdrRangeSpec), 0); memDataInit(MEM_HTTP_HDR_RANGE, "HttpHdrRange", sizeof(HttpHdrRange), 0); memDataInit(MEM_HTTP_HDR_CONTENT_RANGE, "HttpHdrContRange", sizeof(HttpHdrContRange), 0); memDataInit(MEM_INTLIST, "intlist", sizeof(intlist), 0); memDataInit(MEM_MEMOBJECT, "MemObject", sizeof(MemObject), Squid_MaxFD >> 3); memDataInit(MEM_MEM_NODE, "mem_node", sizeof(mem_node), 0); memDataInit(MEM_NETDBENTRY, "netdbEntry", sizeof(netdbEntry), 0); memDataInit(MEM_NET_DB_NAME, "net_db_name", sizeof(net_db_name), 0); memDataInit(MEM_RELIST, "relist", sizeof(relist), 0); memDataInit(MEM_REQUEST_T, "request_t", sizeof(request_t), Squid_MaxFD >> 3); memDataInit(MEM_STOREENTRY, "StoreEntry", sizeof(StoreEntry), 0); memDataInit(MEM_WORDLIST, "wordlist", sizeof(wordlist), 0); memDataInit(MEM_CLIENT_INFO, "ClientInfo", sizeof(ClientInfo), 0); memDataInit(MEM_MD5_DIGEST, "MD5 digest", MD5_DIGEST_CHARS, 0); memDataInit(MEM_HELPER_REQUEST, "helper_request", sizeof(helper_request), 0); memDataInit(MEM_HELPER_STATEFUL_REQUEST, "helper_stateful_request", sizeof(helper_stateful_request), 0); memDataInit(MEM_TLV, "storeSwapTLV", sizeof(tlv), 0); memDataInit(MEM_SWAP_LOG_DATA, "storeSwapLogData", sizeof(storeSwapLogData), 0); /* init string pools */ for (i = 0; i < mem_str_pool_count; i++) { StrPools[i].pool = memPoolCreate(StrPoolsAttrs[i].name, StrPoolsAttrs[i].obj_size); } cachemgrRegister("mem", "Memory Utilization", memStats, 0, 1); }
/* * we have a limit on _total_ amount of idle memory so we ignore * max_pages for now */ void memDataInit(mem_type type, const char *name, size_t size, int max_pages_notused) { assert(name && size); MemPools[type] = memPoolCreate(name, size); }
static void authDigestRequestSetup(void) { if (!digest_request_pool) digest_request_pool = memPoolCreate("Digest Scheme Request Data", sizeof(digest_request_h)); }