Esempio n. 1
0
static struct _pconn *
pconnNew(const char *key)
{
    struct _pconn *p = memPoolAlloc(pconn_data_pool);
    p->hash.key = xstrdup(key);
    p->nfds_alloc = PCONN_FDS_SZ;
    p->fds = memPoolAlloc(pconn_fds_pool);
    debug(48, 3) ("pconnNew: adding %s\n", hashKeyStr(&p->hash));
    hash_join(table, &p->hash);
    return p;
}
Esempio n. 2
0
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);
}
Esempio n. 3
0
/*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;
}
Esempio n. 4
0
void
aioStat(char *path, struct stat *sb, AIOCB * callback, void *callback_data)
{
    aio_ctrl_t *ctrlp;

    assert(initialised);
    aio_counts.stat++;
    ctrlp = memPoolAlloc(aio_ctrl_pool);
    ctrlp->fd = -2;
    ctrlp->done_handler = callback;
    ctrlp->done_handler_data = callback_data;
    ctrlp->operation = _AIO_STAT;
    cbdataLock(callback_data);
    if (aio_stat(path, sb, &ctrlp->result) < 0) {
	if (errno == ENOMEM || errno == EAGAIN || errno == EINVAL)
	    errno = EWOULDBLOCK;
	if (callback)
	    (callback) (ctrlp->fd, callback_data, -1, errno);
	cbdataUnlock(callback_data);
	memPoolFree(aio_ctrl_pool, ctrlp);
	return;
    }
    ctrlp->next = used_list;
    used_list = ctrlp;
    return;
}				/* aioStat */
Esempio n. 5
0
void
aioOpen(const char *path, int oflag, mode_t mode, AIOCB * callback, void *callback_data)
{
    aio_ctrl_t *ctrlp;
    int ret;

    assert(initialised);
    aio_counts.open++;
    ctrlp = memPoolAlloc(aio_ctrl_pool);
    ctrlp->fd = -2;
    ctrlp->done_handler = callback;
    ctrlp->done_handler_data = callback_data;
    ctrlp->operation = _AIO_OPEN;
    cbdataLock(callback_data);
    if (aio_open(path, oflag, mode, &ctrlp->result) < 0) {
	ret = open(path, oflag, mode);
	if (callback)
	    (callback) (ctrlp->fd, callback_data, ret, errno);
	cbdataUnlock(callback_data);
	memPoolFree(aio_ctrl_pool, ctrlp);
	return;
    }
    ctrlp->next = used_list;
    used_list = ctrlp;
    return;
}
void
aioWrite(int fd, int offset, char *bufp, int len, AIOCB * callback, void *callback_data, FREE * free_func)
{
    squidaio_ctrl_t *ctrlp;
    int seekmode;

    assert(initialised);
    squidaio_counts.write++;
    ctrlp = memPoolAlloc(squidaio_ctrl_pool);
    ctrlp->fd = fd;
    ctrlp->done_handler = callback;
    ctrlp->done_handler_data = callback_data;
    ctrlp->operation = _AIO_WRITE;
    ctrlp->bufp = bufp;
    ctrlp->free_func = free_func;
    if (offset >= 0)
        seekmode = SEEK_SET;
    else {
        seekmode = SEEK_END;
        offset = 0;
    }
    cbdataLock(callback_data);
    ctrlp->result.data = ctrlp;
    squidaio_write(fd, bufp, len, offset, seekmode, &ctrlp->result);
    dlinkAdd(ctrlp, &ctrlp->node, &used_list);
}				/* aioWrite */
void
aioRead(int fd, int offset, int len, AIOCB * callback, void *callback_data)
{
    squidaio_ctrl_t *ctrlp;
    int seekmode;

    assert(initialised);
    squidaio_counts.read++;
    ctrlp = memPoolAlloc(squidaio_ctrl_pool);
    ctrlp->fd = fd;
    ctrlp->done_handler = callback;
    ctrlp->done_handler_data = callback_data;
    ctrlp->operation = _AIO_READ;
    ctrlp->len = len;
    ctrlp->bufp = squidaio_xmalloc(len);
    if (offset >= 0)
        seekmode = SEEK_SET;
    else {
        seekmode = SEEK_CUR;
        offset = 0;
    }
    cbdataLock(callback_data);
    ctrlp->result.data = ctrlp;
    squidaio_read(fd, ctrlp->bufp, len, offset, seekmode, &ctrlp->result);
    dlinkAdd(ctrlp, &ctrlp->node, &used_list);
    return;
}				/* aioRead */
Esempio n. 8
0
void
aioUnlink(const char *pathname, AIOCB * callback, void *callback_data)
{
    aio_ctrl_t *ctrlp;
    char *path;
    assert(initialised);
    aio_counts.unlink++;
    ctrlp = memPoolAlloc(aio_ctrl_pool);
    ctrlp->fd = -2;
    ctrlp->done_handler = callback;
    ctrlp->done_handler_data = callback_data;
    ctrlp->operation = _AIO_UNLINK;
    path = xstrdup(pathname);
    cbdataLock(callback_data);
    if (aio_unlink(path, &ctrlp->result) < 0) {
	int ret = unlink(path);
	(callback) (ctrlp->fd, callback_data, ret, errno);
	cbdataUnlock(callback_data);
	memPoolFree(aio_ctrl_pool, ctrlp);
	xfree(path);
	return;
    }
    ctrlp->next = used_list;
    used_list = ctrlp;
    xfree(path);
}				/* aioUnlink */
Esempio n. 9
0
ChunkedBuffer *chunkedBufferAlloc(size_t length)
{
   error_t error;
   ChunkedBuffer *buffer;

   //Allocate memory to hold the multi-part buffer
   buffer = memPoolAlloc(MEM_POOL_BUFFER_SIZE);
   //Failed to allocate memory?
   if(!buffer) return NULL;

   //The multi-part buffer consists of a single chunk
   buffer->chunkCount = 1;
   buffer->maxChunkCount = MAX_CHUNK_COUNT;
   buffer->chunk[0].address = (uint8_t *) buffer + MAX_CHUNK_COUNT * sizeof(ChunkDesc);
   buffer->chunk[0].length = MEM_POOL_BUFFER_SIZE - MAX_CHUNK_COUNT * sizeof(ChunkDesc);
   buffer->chunk[0].size = 0;

   //Adjust the length of the buffer
   error = chunkedBufferSetLength(buffer, length);
   //Any error to report?
   if(error)
   {
      //Clean up side effects
      chunkedBufferFree(buffer);
      //Report an failure
      return NULL;
   }

   //Successful memory allocation
   return buffer;
}
Esempio n. 10
0
storeIOState *
storeDiskdCreate(SwapDir * SD, StoreEntry * e, STFNCB * file_callback,
    STIOCB * callback, void *callback_data)
{
    sfileno f;
    int x;
    storeIOState *sio;
    char *buf;
    int shm_offset;
    diskdinfo_t *diskdinfo = SD->fsdata;
    diskdstate_t *diskdstate;
    /*
     * Fail on open() if there are too many requests queued.
     */
    if (diskdinfo->away > diskdinfo->magic1) {
	diskd_stats.open_fail_queue_len++;
	return NULL;
    }
    /* Allocate a number */
    f = storeDiskdDirMapBitAllocate(SD);
    debug(79, 3) ("storeDiskdCreate: fileno %08X\n", f);

    CBDATA_INIT_TYPE_FREECB(storeIOState, storeDiskdIOFreeEntry);
    sio = cbdataAlloc(storeIOState);
    sio->fsstate = diskdstate = memPoolAlloc(diskd_state_pool);

    sio->swap_filen = f;
    sio->swap_dirn = SD->index;
    sio->mode = O_WRONLY | O_CREAT | O_TRUNC;
    sio->callback = callback;
    sio->callback_data = callback_data;
    sio->e = e;
    cbdataLock(callback_data);

    diskdstate->flags.writing = 0;
    diskdstate->flags.reading = 0;
    diskdstate->flags.close_request = 0;
    diskdstate->id = diskd_stats.sio_id++;

    buf = storeDiskdShmGet(SD, &shm_offset);
    xstrncpy(buf, storeDiskdDirFullPath(SD, f, NULL), SHMBUF_BLKSZ);
    x = storeDiskdSend(_MQD_OPEN,
	SD,
	diskdstate->id,
	sio,
	strlen(buf) + 1,
	sio->mode,
	shm_offset);
    if (x < 0) {
	debug(79, 1) ("storeDiskdSend OPEN: %s\n", xstrerror());
	storeDiskdShmPut(SD, shm_offset);
	cbdataUnlock(sio->callback_data);
	cbdataFree(sio);
	return NULL;
    }
    storeDiskdDirReplAdd(SD, e);
    diskd_stats.create.ops++;
    return sio;
}
Esempio n. 11
0
static digest_request_h *
authDigestRequestNew(void)
{
    digest_request_h *tmp;
    tmp = memPoolAlloc(digest_request_pool);
    assert(tmp != NULL);
    return tmp;
}
Esempio n. 12
0
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);
}
Esempio n. 13
0
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);
}
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);
}
Esempio n. 15
0
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);
}
Esempio n. 16
0
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);
}
Esempio n. 17
0
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);
}
Esempio n. 20
0
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 * 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);
}
int
squidaio_opendir(const char *path, squidaio_result_t * resultp)
{
    squidaio_request_t *requestp;
    int len;

    requestp = memPoolAlloc(squidaio_request_pool);
    return -1;
}
Esempio n. 23
0
/* open for creating */
storeIOState *
storeAufsCreate(SwapDir * SD, StoreEntry * e, STFNCB * file_callback, STIOCB * callback, void *callback_data)
{
    char *path;
    storeIOState *sio;
    sfileno filn;
    sdirno dirn;
#if !ASYNC_CREATE
    int fd;
#endif

    /* Allocate a number */
    dirn = SD->index;
    filn = storeAufsDirMapBitAllocate(SD);
    path = storeAufsDirFullPath(SD, filn, NULL);

    debug(79, 3) ("storeAufsCreate: fileno %08X\n", filn);
    /*
     * we should detect some 'too many files open' condition and return
     * NULL here.
     */
#ifdef MAGIC2
    if (aioQueueSize() > MAGIC2)
	return NULL;
#endif
#if !ASYNC_CREATE
    fd = file_open(path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY);
    if (fd < 0) {
	debug(79, 3) ("storeAufsCreate: got failure (%d)\n", errno);
	return NULL;
    }
#endif
    CBDATA_INIT_TYPE_FREECB(storeIOState, storeAufsIOFreeEntry);
    sio = cbdataAlloc(storeIOState);
    sio->fsstate = memPoolAlloc(squidaio_state_pool);
    ((squidaiostate_t *) (sio->fsstate))->fd = -1;
    ((squidaiostate_t *) (sio->fsstate))->flags.opening = 1;
    sio->swap_filen = filn;
    sio->swap_dirn = dirn;
    sio->mode = O_WRONLY | O_BINARY;
    sio->callback = callback;
    sio->callback_data = callback_data;
    sio->e = (StoreEntry *) e;
    cbdataLock(callback_data);
    Opening_FD++;
    statCounter.syscalls.disk.opens++;
#if ASYNC_CREATE
    aioOpen(path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644, storeAufsOpenDone, sio, INDEX_OF_SD(SD));
#else
    storeAufsOpenDone(fd, sio, fd, 0);
#endif

    /* now insert into the replacement policy */
    storeAufsDirReplAdd(SD, e);
    return sio;

}
Esempio n. 24
0
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);  
}
Esempio n. 25
0
static basic_data *
authBasicDataNew(void)
{
    basic_data *temp;
    temp = memPoolAlloc(basic_data_pool);
    assert(temp != NULL);
    temp->username = NULL;
    temp->passwd = NULL;
    temp->auth_queue = NULL;
    return temp;
}
Esempio n. 26
0
static void
authenticateDecodeNegotiateAuth(auth_user_request_t * auth_user_request, const char *proxy_auth)
{
    dlink_node *node;
    assert(auth_user_request->auth_user == NULL);
    auth_user_request->auth_user = authenticateAuthUserNew("negotiate");
    auth_user_request->auth_user->auth_type = AUTH_NEGOTIATE;
    auth_user_request->auth_user->scheme_data = memPoolAlloc(negotiate_user_pool);
    auth_user_request->scheme_data = memPoolAlloc(negotiate_request_pool);
    memset(auth_user_request->scheme_data, '\0', sizeof(negotiate_request_t));
    /* lock for the auth_user_request link */
    authenticateAuthUserLock(auth_user_request->auth_user);
    node = dlinkNodeNew();
    dlinkAdd(auth_user_request, node, &auth_user_request->auth_user->requests);

    /* the helper does the rest, with data collected in
     * authenticateNegotiateAuthenticateUser */
    debug(29, 9) ("authenticateDecodeNegotiateAuth: Negotiate authentication\n");
    return;
}
Esempio n. 27
0
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;
}
Esempio n. 28
0
static void
lru_add(RemovalPolicy * policy, StoreEntry * entry, RemovalPolicyNode * node)
{
    LruPolicyData *lru = policy->_data;
    LruNode *lru_node;
    assert(!node->data);
    node->data = lru_node = memPoolAlloc(lru_node_pool);
    dlinkAddTail(entry, &lru_node->node, &lru->list);
    lru->count += 1;
    if (!lru->type)
	lru->type = repl_guessType(entry, node);
}
Esempio n. 29
0
/* Write */
void
storeAufsWrite(SwapDir * SD, storeIOState * sio, char *buf, size_t size, squid_off_t offset, FREE * free_func)
{
    squidaiostate_t *aiostate = (squidaiostate_t *) sio->fsstate;
    debug(79, 3) ("storeAufsWrite: dirno %d, fileno %08X, FD %d\n",
	sio->swap_dirn, sio->swap_filen, aiostate->fd);
    if (aiostate->fd < 0) {
	/* disk file not opened yet */
	struct _queued_write *q;
	assert(aiostate->flags.opening);
	q = memPoolAlloc(aufs_qwrite_pool);
	q->buf = buf;
	q->size = size;
	q->offset = (off_t) offset;
	q->free_func = free_func;
	linklistPush(&(aiostate->pending_writes), q);
	return;
    }
#if ASYNC_WRITE
    if (aiostate->flags.writing) {
	struct _queued_write *q;
	debug(79, 3) ("storeAufsWrite: queuing write\n");
	q = memPoolAlloc(aufs_qwrite_pool);
	q->buf = buf;
	q->size = size;
	q->offset = (off_t) offset;
	q->free_func = free_func;
	linklistPush(&(aiostate->pending_writes), q);
	return;
    }
    aiostate->flags.writing = 1;
    aioWrite(aiostate->fd, (off_t) offset, buf, size, storeAufsWriteDone, sio,
	free_func, INDEX_OF_SD(SD));
    statCounter.syscalls.disk.writes++;
#else
    file_write(aiostate->fd, (off_t) offset, buf, size, storeAufsWriteDone, sio,
	free_func);
    /* file_write() increments syscalls.disk.writes */
#endif
}
void *
squidaio_xmalloc(int size)
{
    void *p;
    MemPool *pool;

    if ((pool = squidaio_get_pool(size)) != NULL) {
	p = memPoolAlloc(pool);
    } else
	p = xmalloc(size);

    return p;
}