⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cache_cf.c

📁 -
💻 C
📖 第 1 页 / 共 3 页
字号:
    if (!cfg->pools)	return;    for (i = 0; i < cfg->pools; i++) {	if (cfg->class[i]) {	    delayFreeDelayPool(i);	    safe_free(cfg->rates[i]);	}	aclDestroyAccessList(&cfg->access[i]);    }    delayFreeDelayData();    xfree(cfg->class);    xfree(cfg->rates);    xfree(cfg->access);    memset(cfg, 0, sizeof(*cfg));}static voiddump_delay_pool_count(StoreEntry * entry, const char *name, delayConfig cfg){    int i;    LOCAL_ARRAY(char, nom, 32);    if (!cfg.pools) {	storeAppendPrintf(entry, "%s 0\n", name);	return;    }    storeAppendPrintf(entry, "%s %d\n", name, cfg.pools);    for (i = 0; i < cfg.pools; i++) {	storeAppendPrintf(entry, "delay_class %d %d\n", i + 1, cfg.class[i]);	snprintf(nom, 32, "delay_access %d", i + 1);	dump_acl_access(entry, nom, cfg.access[i]);	if (cfg.class[i] >= 1)	    storeAppendPrintf(entry, "delay_parameters %d %d/%d", i + 1,		cfg.rates[i]->aggregate.restore_bps,		cfg.rates[i]->aggregate.max_bytes);	if (cfg.class[i] >= 3)	    storeAppendPrintf(entry, " %d/%d",		cfg.rates[i]->network.restore_bps,		cfg.rates[i]->network.max_bytes);	if (cfg.class[i] >= 2)	    storeAppendPrintf(entry, " %d/%d",		cfg.rates[i]->individual.restore_bps,		cfg.rates[i]->individual.max_bytes);	if (cfg.class[i] >= 1)	    storeAppendPrintf(entry, "\n");    }}static voidparse_delay_pool_count(delayConfig * cfg){    if (cfg->pools) {	debug(3, 0) ("parse_delay_pool_count: multiple delay_pools lines, aborting all previous delay_pools config\n");	free_delay_pool_count(cfg);    }    parse_ushort(&cfg->pools);    delayInitDelayData(cfg->pools);    cfg->class = xcalloc(cfg->pools, sizeof(u_char));    cfg->rates = xcalloc(cfg->pools, sizeof(delaySpecSet *));    cfg->access = xcalloc(cfg->pools, sizeof(acl_access *));}static voidparse_delay_pool_class(delayConfig * cfg){    ushort pool, class;    parse_ushort(&pool);    if (pool < 1 || pool > cfg->pools) {	debug(3, 0) ("parse_delay_pool_class: Ignoring pool %d not in 1 .. %d\n", pool, cfg->pools);	return;    }    parse_ushort(&class);    if (class < 1 || class > 3) {	debug(3, 0) ("parse_delay_pool_class: Ignoring pool %d class %d not in 1 .. 3\n", pool, class);	return;    }    pool--;    if (cfg->class[pool]) {	delayFreeDelayPool(pool);	safe_free(cfg->rates[pool]);    }    cfg->rates[pool] = xmalloc(class * sizeof(delaySpec));    cfg->class[pool] = class;    cfg->rates[pool]->aggregate.restore_bps = cfg->rates[pool]->aggregate.max_bytes = -1;    if (cfg->class[pool] >= 3)	cfg->rates[pool]->network.restore_bps = cfg->rates[pool]->network.max_bytes = -1;    if (cfg->class[pool] >= 2)	cfg->rates[pool]->individual.restore_bps = cfg->rates[pool]->individual.max_bytes = -1;    delayCreateDelayPool(pool, class);}static voidparse_delay_pool_rates(delayConfig * cfg){    ushort pool, class;    int i;    delaySpec *ptr;    char *token;    parse_ushort(&pool);    if (pool < 1 || pool > cfg->pools) {	debug(3, 0) ("parse_delay_pool_rates: Ignoring pool %d not in 1 .. %d\n", pool, cfg->pools);	return;    }    pool--;    class = cfg->class[pool];    if (class == 0) {	debug(3, 0) ("parse_delay_pool_rates: Ignoring pool %d attempt to set rates with class not set\n", pool + 1);	return;    }    ptr = (delaySpec *) cfg->rates[pool];    /* read in "class" sets of restore,max pairs */    while (class--) {	token = strtok(NULL, "/");	if (token == NULL)	    self_destruct();	if (sscanf(token, "%d", &i) != 1)	    self_destruct();	ptr->restore_bps = i;	GetInteger(i);	ptr->max_bytes = i;	ptr++;    }    class = cfg->class[pool];    /* if class is 3, swap around network and individual */    if (class == 3) {	delaySpec tmp;	tmp = cfg->rates[pool]->individual;	cfg->rates[pool]->individual = cfg->rates[pool]->network;	cfg->rates[pool]->network = tmp;    }    /* initialize the delay pools */    delayInitDelayPool(pool, class, cfg->rates[pool]);}static voidparse_delay_pool_access(delayConfig * cfg){    ushort pool;    parse_ushort(&pool);    if (pool < 1 || pool > cfg->pools) {	debug(3, 0) ("parse_delay_pool_rates: Ignoring pool %d not in 1 .. %d\n", pool, cfg->pools);	return;    }    aclParseAccessLine(&cfg->access[pool - 1]);}#endifstatic voiddump_http_header(StoreEntry * entry, const char *name, HttpHeaderMask header){    storeAppendPrintf(entry, "%s\n", name);}static voidparse_http_header(HttpHeaderMask * header){    int allowed, id;    char *t = NULL;    if ((t = strtok(NULL, w_space)) == NULL) {	debug(3, 0) ("%s line %d: %s\n",	    cfg_filename, config_lineno, config_input_line);	debug(3, 0) ("parse_http_header: missing 'allow' or 'deny'.\n");	return;    }    if (!strcmp(t, "allow"))	allowed = 1;    else if (!strcmp(t, "deny"))	allowed = 0;    else {	debug(3, 0) ("%s line %d: %s\n",	    cfg_filename, config_lineno, config_input_line);	debug(3, 0) ("parse_http_header: expecting 'allow' or 'deny', got '%s'.\n", t);	return;    }    if (!http_header_first) {	http_header_first = 1;	if (allowed)	    httpHeaderMaskInit(header, 0xFF);    }    while ((t = strtok(NULL, w_space))) {	if ((id = httpHeaderIdByNameDef(t, strlen(t))) == -1)	    id = HDR_OTHER;	if (allowed)	    CBIT_CLR(*header, id);	else	    CBIT_SET(*header, id);    }}static voidfree_http_header(HttpHeaderMask * header){    httpHeaderMaskInit(header, 0);}static voiddump_cachedir(StoreEntry * entry, const char *name, cacheSwap swap){    SwapDir *s;    int i;    for (i = 0; i < swap.n_configured; i++) {	s = swap.swapDirs + i;	storeAppendPrintf(entry, "%s %s %d %d %d\n",	    name,	    s->path,	    s->max_size >> 10,	    s->l1,	    s->l2);    }}static intcheck_null_cachedir(cacheSwap swap){    return swap.swapDirs == NULL;}static intcheck_null_string(char *s){    return s == NULL;}static voidparse_cachedir(cacheSwap * swap){    char *token;    char *path;    int i;    int size;    int l1;    int l2;    unsigned int read_only = 0;    SwapDir *tmp = NULL;    if ((path = strtok(NULL, w_space)) == NULL)	self_destruct();    GetInteger(i);    size = i << 10;		/* Mbytes to kbytes */    if (size <= 0)	fatal("parse_cachedir: invalid size value");    GetInteger(i);    l1 = i;    if (l1 <= 0)	fatal("parse_cachedir: invalid level 1 directories value");    GetInteger(i);    l2 = i;    if (l2 <= 0)	fatal("parse_cachedir: invalid level 2 directories value");    if ((token = strtok(NULL, w_space)))	if (!strcasecmp(token, "read-only"))	    read_only = 1;    for (i = 0; i < swap->n_configured; i++) {	tmp = swap->swapDirs + i;	if (!strcmp(path, tmp->path)) {	    /* just reconfigure it */	    if (size == tmp->max_size)		debug(3, 1) ("Cache dir '%s' size remains unchanged at %d KB\n",		    path, size);	    else		debug(3, 1) ("Cache dir '%s' size changed to %d KB\n",		    path, size);	    tmp->max_size = size;	    if (tmp->flags.read_only != read_only)		debug(3, 1) ("Cache dir '%s' now %s\n",		    path, read_only ? "Read-Only" : "Read-Write");	    tmp->flags.read_only = read_only;	    return;	}    }    if (swap->swapDirs == NULL) {	swap->n_allocated = 4;	swap->swapDirs = xcalloc(swap->n_allocated, sizeof(SwapDir));    }    if (swap->n_allocated == swap->n_configured) {	swap->n_allocated <<= 1;	tmp = xcalloc(swap->n_allocated, sizeof(SwapDir));	xmemcpy(tmp, swap->swapDirs, swap->n_configured * sizeof(SwapDir));	xfree(swap->swapDirs);	swap->swapDirs = tmp;    }    tmp = swap->swapDirs + swap->n_configured;    tmp->path = xstrdup(path);    tmp->max_size = size;    tmp->l1 = l1;    tmp->l2 = l2;    tmp->flags.read_only = read_only;    tmp->swaplog_fd = -1;    swap->n_configured++;}static voidfree_cachedir(cacheSwap * swap){    SwapDir *s;    int i;    /* DON'T FREE THESE FOR RECONFIGURE */    if (reconfiguring)	return;    for (i = 0; i < swap->n_configured; i++) {	s = swap->swapDirs + i;	if (s->swaplog_fd > -1) {	    file_close(s->swaplog_fd);	    s->swaplog_fd = -1;	}	xfree(s->path);	filemapFreeMemory(s->map);    }    safe_free(swap->swapDirs);    swap->swapDirs = NULL;    swap->n_allocated = 0;    swap->n_configured = 0;}const char *peer_type_str(const peer_t type){    switch (type) {    case PEER_PARENT:	return "parent";	break;    case PEER_SIBLING:	return "sibling";	break;    case PEER_MULTICAST:	return "multicast";	break;    default:	return "unknown";	break;    }}static voiddump_peer(StoreEntry * entry, const char *name, peer * p){    domain_ping *d;    acl_access *a;    domain_type *t;    LOCAL_ARRAY(char, xname, 128);    while (p != NULL) {	storeAppendPrintf(entry, "%s %s %s %d %d",	    name,	    p->host,	    neighborTypeStr(p),	    p->http_port,	    p->icp.port);	dump_peer_options(entry, p);	for (d = p->peer_domain; d; d = d->next) {	    storeAppendPrintf(entry, "cache_peer_domain %s %s%s\n",		p->host,		d->do_ping ? null_string : "!",		d->domain);	}	if ((a = p->access)) {	    snprintf(xname, 128, "cache_peer_access %s", p->host);	    dump_acl_access(entry, xname, p->access);	}	for (t = p->typelist; t; t = t->next) {	    storeAppendPrintf(entry, "neighbor_type_domain %s %s %s\n",		p->host,		peer_type_str(t->type),		t->domain);	}	p = p->next;    }}static voidparse_peer(peer ** head){    char *token = NULL;    peer *p;    int i;    ushortlist *u;    const char *me = null_string;	/* XXX */    p = memAllocate(MEM_PEER);    p->http_port = CACHE_HTTP_PORT;    p->icp.port = CACHE_ICP_PORT;    p->weight = 1;    p->stats.logged_state = PEER_ALIVE;    if ((token = strtok(NULL, w_space)) == NULL)	self_destruct();    p->host = xstrdup(token);    if ((token = strtok(NULL, w_space)) == NULL)	self_destruct();    p->type = parseNeighborType(token);    GetInteger(i);    p->http_port = (u_short) i;    GetInteger(i);    p->icp.port = (u_short) i;    if (strcmp(p->host, me) == 0) {	for (u = Config.Port.http; u; u = u->next) {	    if (p->http_port != u->i)		continue;	    debug(15, 0) ("parse_peer: Peer looks like myself: %s %s/%d/%d\n",		p->type, p->host, p->http_port, p->icp.port);	    self_destruct();	}    }    while ((token = strtok(NULL, w_space))) {	if (!strcasecmp(token, "proxy-only")) {	    p->options.proxy_only = 1;	} else if (!strcasecmp(token, "no-query")) {	    p->options.no_query = 1;	} else if (!strcasecmp(token, "no-digest")) {	    p->options.no_digest = 1;	} else if (!strcasecmp(token, "multicast-responder")) {	    p->options.mcast_responder = 1;	} else if (!strncasecmp(token, "weight=", 7)) {	    p->weight = atoi(token + 7);	} else if (!strcasecmp(token, "closest-only")) {	    p->options.closest_only = 1;	} else if (!strncasecmp(token, "ttl=", 4)) {	    p->mcast.ttl = atoi(token + 4);	    if (p->mcast.ttl < 0)		p->mcast.ttl = 0;	    if (p->mcast.ttl > 128)		p->mcast.ttl = 128;	} else if (!strcasecmp(token, "default")) {	    p->options.default_parent = 1;	} else if (!strcasecmp(token, "round-robin")) {	    p->options.roundrobin = 1;#if USE_HTCP	} else if (!strcasecmp(token, "htcp")) {	    p->options.htcp = 1;#endif	} else if (!strcasecmp(token, "no-netdb-exchange")) {	    p->options.no_netdb_exchange = 1;#if USE_CARP	} else if (!strncasecmp(token, "carp-load-factor=", 17)) {	    if (p->type != PEER_PARENT)		debug(3, 0) ("parse_peer: Ignoring carp-load-factor for non-parent %s/%d\n", p->host, p->http_port);	    else		p->carp.load_factor = atof(token + 17);#endif#if DELAY_POOLS	} else if (!strcasecmp(token, "no-delay")) {	    p->options.no_delay = 1;#endif	} else if (!strncasecmp(token, "login=", 6)) {	    p->login = xstrdup(token + 6);	} else {	    debug(3, 0) ("parse_peer: token='%s'\n", token);	    self_destruct();	}    }    if (p->weight < 1)	p->weight = 1;    p->icp.version = ICP_VERSION_CURRENT;    p->tcp_up = PEER_TCP_MAGIC_COUNT;#if USE_CARP    if (p->carp.load_factor) {	/* calculate this peers hash for use in CARP */	p->carp.hash = 0;	for (token = p->host; *token != 0; token++)	    p->carp.hash += (p->carp.hash << 19) + *token;    }#endif    /* This must preceed peerDigestCreate */    cbdataAdd(p, peerDestroy, MEM_PEER);#if USE_CACHE_DIGESTS    if (!p->options.no_digest) {	p->digest = peerDigestCreate(p);	cbdataLock(p->digest);	/* so we know when/if digest disappears */    }#endif    while (*head != NULL)	head = &(*head)->next;    *head = p;    Config.npeers++;}static voidfree_peer(peer ** P){    peer *p;    while ((p = *P) != NULL) {	*P = p->next;#if USE_CACHE_DIGESTS	if (p->digest)	    cbdataUnlock(p->digest);	p->digest = NULL;#endif	cbdataFree(p);    }    Config.npeers = 0;}static voiddump_cachemgrpasswd(StoreEntry * entry, const char *name, cachemgr_passwd * list){    wordlist *w;    while (list != NULL) {	if (strcmp(list->passwd, "none") && strcmp(list->passwd, "disable"))	    storeAppendPrintf(entry, "%s XXXXXXXXXX", name);	else	    storeAppendPrintf(entry, "%s %s", name, list->passwd);	for (w = list->actions; w != NULL; w = w->next) {	    storeAppendPrintf(entry, " %s", w->key);	}	storeAppendPrintf(entry, "\n");	list = list->next;    }}static voidparse_cachemgrpasswd(cachemgr_passwd ** head){    char *passwd = NULL;    wordlist *actions = NULL;    cachemgr_passwd *p;    cachemgr_passwd **P;    parse_string(&passwd);    parse_wordlist(&actions);    p = xcalloc(1, sizeof(cachemgr_passwd));    p->passwd = passwd;    p->actions = actions;    for (P = head; *P; P = &(*P)->next);    *P = p;}static voidfree_cachemgrpasswd(cachemgr_passwd ** head){    cachemgr_passwd *p;    while ((p = *head) != NULL) {	*head = p->next;	xfree(p->passwd);	wordlistDestroy(&p->actions);	xfree(p);    }}static voiddump_denyinfo(StoreEntry * entry, const char *name, acl_deny_info_list * var){    acl_name_list *a;    while (var != NULL) {	storeAppendPrintf(entry, "%s %s", name, var->err_page_name);	for (a = var->acl_list; a != NULL; a = a->next)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -