Esempio n. 1
0
HTTP_HDR_REQ *http_hdr_req_new(void)
{
	HTTP_HDR_REQ *hh;
	ACL_ARRAY *pool;

	if (var_http_tls_cache <= 0) {
		hh = (HTTP_HDR_REQ *) http_hdr_new(sizeof(HTTP_HDR_REQ));
		__hdr_init(hh);
		return hh;
	}

#ifdef	USE_TLS_EX
	pool = (ACL_ARRAY*) acl_pthread_tls_get(&cache_key);
	if (pool == NULL) {
		pool = acl_array_create(100);
		acl_pthread_tls_set(cache_key, pool,
			(void (*)(void*)) thread_cache_free);
	}

	pool = (ACL_ARRAY*) acl_pthread_tls_get(&cache_key);
	hh = (HTTP_HDR_REQ*) pool->pop_back(pool);
	if (hh) {
		__hdr_reset(hh, 1);
		http_hdr_reset((HTTP_HDR *) hh);
		return hh;
	}
#else
	acl_pthread_once(&once_control, cache_init);
	pool = (ACL_ARRAY*) acl_pthread_getspecific(cache_key);
	if (pool == NULL) {
		pool = acl_array_create(100);
		acl_pthread_setspecific(cache_key, pool);
		if ((unsigned long) acl_pthread_self() == acl_main_thread_self()) {
			cache_pool = pool;
			atexit(main_cache_free);
		}
	}
	hh = (HTTP_HDR_REQ*) pool->pop_back(pool);
	if (hh) {
		__hdr_reset(hh, 1);
		http_hdr_reset((HTTP_HDR *) hh);
		return hh;
	}
#endif

	hh = (HTTP_HDR_REQ *) http_hdr_new(sizeof(HTTP_HDR_REQ));
	__hdr_init(hh);
	return hh;
}
Esempio n. 2
0
int acl_cfg_parser_append(ACL_CFG_PARSER *parser, ACL_CFG_LINE *cfg_line)
{
	char  myname[] = "acl_cfg_parser_append";
	char  tbuf[256];

	if (parser == NULL || cfg_line == NULL) {
		printf("%s: input error\n", myname);
		return (-1);
	}

	if (parser->_cfg_array == NULL) {
		parser->_cfg_array = acl_array_create(10);
		if (parser->_cfg_array == NULL) {
			printf("%s: can't create array, errmsg=%s",
					myname, acl_last_strerror(tbuf, sizeof(tbuf)));
			return (-1);
		}
		parser->total_line = 0;
		parser->valid_line = 0;
	}

	if (acl_array_append(parser->_cfg_array, (void *) cfg_line) < 0) {
		printf("%s: can't add ACL_CFG_LINE to array, errmsg=%s",
			myname, acl_last_strerror(tbuf, sizeof(tbuf)));
		return (-1);
	}
	parser->total_line++;
	if (cfg_line->pdata == NULL && cfg_line->value != NULL)
		parser->valid_line++;
	cfg_line->line_number = parser->total_line;

	return (0);
}
Esempio n. 3
0
ACL_DNS_DB *acl_netdb_new(const char *domain)
{
	const char *myname = "acl_netdb_new";
	ACL_DNS_DB *dns_db;
	char  buf[256];

	dns_db = acl_mycalloc(1, sizeof(ACL_DNS_DB));
	if (dns_db == NULL) {
		acl_msg_error("%s, %s(%d): calloc error(%s)",
			__FILE__, myname, __LINE__,
			acl_last_strerror(buf, sizeof(buf)));
		return (NULL);
	}

	dns_db->h_db = acl_array_create(5);
	if (dns_db->h_db == NULL) {
		acl_msg_error("%s, %s(%d): create array error(%s)",
			__FILE__, myname, __LINE__,
			acl_last_strerror(buf, sizeof(buf)));
		acl_myfree(dns_db);
		return (NULL);
	}

	snprintf(dns_db->name, sizeof(dns_db->name), "%s", domain);
	acl_lowercase(dns_db->name);

	dns_db->iter_head = netdb_iter_head;
	dns_db->iter_next = netdb_iter_next;
	dns_db->iter_tail = netdb_iter_tail;
	dns_db->iter_prev = netdb_iter_prev;
	dns_db->iter_info = netdb_iter_info;

	return (dns_db);
}
Esempio n. 4
0
/*----------------------------------------------------------------------------*/
ACL_DB_POOL *acl_dbpool_mysql_create(const ACL_DB_INFO *db_info)
{
	char  myname[] = "acl_dbpool_mysql_create";
	ACL_DB_POOL_MYSQL *mysql_pool;

	mysql_pool = (ACL_DB_POOL_MYSQL *) acl_mycalloc(1, sizeof(ACL_DB_POOL_MYSQL));
	if (mysql_pool == NULL) {
		char  tbuf[256];
		acl_msg_fatal("%s, %s(%d): calloc error=%s",
			__FILE__, myname, __LINE__, acl_last_strerror(tbuf, sizeof(tbuf)));
	}

	mysql_pool->db_pool.dbh_peek    = &__dbpool_mysql_peek;
	mysql_pool->db_pool.dbh_check   = &__dbpool_mysql_check;
	mysql_pool->db_pool.dbh_release = &__dbpool_mysql_release;
	mysql_pool->db_pool.dbh_export  = &__dbpool_mysql_export;
	mysql_pool->db_pool.dbh_close   = &__dbpool_mysql_close;

	mysql_pool->db_pool.destroy     = &__dbpool_mysql_destroy;

	mysql_pool->handles  = acl_array_create(db_info->db_max);
	acl_pthread_mutex_init(&mysql_pool->mutex, NULL);

	return ((ACL_DB_POOL *) mysql_pool);
}
Esempio n. 5
0
ACL_ARRAY *acl_xml_getElementsByTagName(ACL_XML *xml, const char *tag)
{
	ACL_ITER iter;
	ACL_ARRAY *a = acl_array_create(10);

	acl_foreach(iter, xml) {
		ACL_XML_NODE *node = (ACL_XML_NODE*) iter.data;
		if (strcasecmp(tag, STR(node->ltag)) == 0) {
			acl_array_append(a, node);
		}
	}
Esempio n. 6
0
void acl_xml_cache(ACL_XML *xml, int max_cache)
{
    if (xml->node_cache != NULL) {
        acl_array_free(xml->node_cache,
                       (void (*)(void*)) acl_xml_node_free);
        xml->node_cache = NULL;
        xml->max_cache = 0;
    }
    if (max_cache > 0) {
        xml->node_cache = acl_array_create(max_cache);
        xml->max_cache = max_cache;
    }
}
Esempio n. 7
0
void aut_register(const AUT_FN_ITEM test_fn_tab[])
{
	int   i;

	if (__all_callback_fn == NULL)
		__all_callback_fn = acl_array_create(10);

	/* 先增加注册内部用命令 */
	for (i = 0; __inner_fn_tab[i].cmd_name != NULL; i++)
		__add_fn_item(__all_callback_fn, &__inner_fn_tab[i], 1);

	/* 再注册外部传来的命令任务 */
	for (i = 0; test_fn_tab[i].cmd_name != NULL; i++)
		__add_fn_item(__all_callback_fn, &test_fn_tab[i], 0);
}
Esempio n. 8
0
/* 初始化 */
static void __init(void)
{
	const char *myname = "__init";

	if (var_aut_line_array != NULL)
		return;

	var_aut_line_array = acl_array_create(10);
	if (var_aut_line_array == NULL) {
		char tbuf[256];
		aut_log_fatal("%s: acl_array_create error(%s)",
			myname, acl_last_strerror(tbuf, sizeof(tbuf)));
	}
	var_aut_valid_line_idx = 0;
}
Esempio n. 9
0
void proctl_service_init()
{
	const char *myname = "proctl_service_init";
	char  ebuf[256];

	__services = acl_array_create(10);
	__services_wait = acl_fifo_new();
	acl_pthread_mutex_init(&__mutex_running_service, NULL);
	acl_pthread_mutex_init(&__mutex_waiting_service, NULL);
	handles_init();

	__sem_handle = CreateSemaphore(NULL, 0, 1024, NULL);
	if (__sem_handle == NULL)
		acl_msg_fatal("%s(%d): CreateSemaphore error(%s)",
			myname, __LINE__, acl_last_strerror(ebuf, sizeof(ebuf)));
	handles_add(__sem_handle);
}
Esempio n. 10
0
ACL_DNS_DB *acl_netdb_new(const char *domain)
{
	ACL_DNS_DB *db;

	db = acl_mycalloc(1, sizeof(ACL_DNS_DB));
	db->h_db = acl_array_create(5);

	snprintf(db->name, sizeof(db->name), "%s", domain);
	acl_lowercase(db->name);

	db->iter_head = netdb_iter_head;
	db->iter_next = netdb_iter_next;
	db->iter_tail = netdb_iter_tail;
	db->iter_prev = netdb_iter_prev;
	db->iter_info = netdb_iter_info;

	return db;
}
Esempio n. 11
0
ACL_XML_NODE *acl_xml_node_alloc(ACL_XML *xml)
{
    ACL_XML_NODE *node;

    if (xml->node_cache) {
        node = (ACL_XML_NODE*)
               xml->node_cache->pop_back(xml->node_cache);
        if (node) {
            acl_xml_node_reset(node);
            node->xml = xml;
            xml->node_cnt++;
            return (node);
        }
    }

    if (xml->slice)
        node = (ACL_XML_NODE*) acl_slice_pool_calloc(__FILE__, __LINE__,
                xml->slice, 1, sizeof(ACL_XML_NODE));
    else
        node = (ACL_XML_NODE*) acl_mycalloc(1, sizeof(ACL_XML_NODE));
    acl_ring_init(&node->children);
    acl_ring_init(&node->node);

    node->xml = xml;
    node->status = ACL_XML_S_NXT;
    node->ltag = acl_vstring_slice_alloc(xml->slice, 16);
    node->rtag = acl_vstring_slice_alloc(xml->slice, 16);
    node->text = acl_vstring_slice_alloc(xml->slice, 16);
    node->attr_list = acl_array_create(5);
    xml->node_cnt++;

    node->iter_head = node_iter_head;
    node->iter_next = node_iter_next;
    node->iter_tail = node_iter_tail;
    node->iter_prev = node_iter_prev;
    return (node);
}
Esempio n. 12
0
static ACL_CFG_LINE *_create_cfg_line(char *data, const char *delimiter)
{
	ACL_CFG_LINE *cfg_line = NULL;
	ACL_ARRAY *a = NULL;
	int   i, n;
	char *ptr, *pdata, *pitem;

#undef	ERETURN
#define	ERETURN(x) do {                                                      \
	if (a)                                                               \
		acl_array_destroy(a, acl_myfree_fn);                         \
	if (cfg_line) {                                                      \
		if (cfg_line->value)                                         \
			acl_myfree(cfg_line);                                    \
		acl_myfree(cfg_line);                                            \
	}                                                                    \
	return (x);                                                          \
} while (0);

	if (data == NULL)
		return (NULL);

	pdata = data;

	cfg_line = (ACL_CFG_LINE *) acl_mycalloc(1, sizeof(ACL_CFG_LINE));
	if (cfg_line == NULL)
		return (NULL);

	a = acl_array_create(10);
	while (1) {
		ptr = acl_mystrtok(&pdata, delimiter);
		if (ptr == NULL)
			break;
		pitem = acl_mystrdup(ptr);
		if (pitem == NULL) {
			ERETURN (NULL);
		}
		if (acl_array_append(a, (void *) pitem) < 0) {
			ERETURN (NULL);
		}
	}

	cfg_line->ncount = 0;
	cfg_line->pdata = NULL;
	n = acl_array_size(a);
	if (n > 0) {
		cfg_line->value = (char **) acl_mycalloc(1 + n, sizeof(char *));
		if (cfg_line->value == NULL) {
			ERETURN (NULL);
		}
		for (i = 0; i < n; i++) {
			pitem = (char *) acl_array_index(a, i);
			if (pitem == NULL)
				break;
			cfg_line->value[i] = pitem;
			if (cfg_line->value[i] == NULL)
				ERETURN (NULL);
			cfg_line->ncount++;
		}
	}

	/* NOTICE: in acl_array_destroy, please don't input acl_myfree, but
	 * NULL as the second parameter, because the mystrup's result
	 * set are stored in cfg_line->value now:)
	 */
	acl_array_destroy(a, NULL);

	return (cfg_line);
}
Esempio n. 13
0
ACL_CFG_PARSER *acl_cfg_parser_load(const char *pathname, const char *delimiter)
{
	char  myname[] = "acl_cfg_parse_load";
	ACL_CFG_PARSER *parser = NULL;
	ACL_CFG_LINE *cfg_line;
	struct stat stat_buf;
	int   buf_size;
	char *content_buf = NULL, *ptr;
	char *pline_begin;
	ACL_FILE_HANDLE   filefd = ACL_FILE_INVALID;
	char  tbuf[256];
	
#undef	ERETURN
#define	ERETURN(x) do { \
	if (content_buf != NULL) \
		acl_myfree(content_buf); \
	if (filefd != ACL_FILE_INVALID) \
		acl_file_close(filefd); \
	if (parser != NULL) { \
		acl_array_destroy(parser->_cfg_array, NULL); \
		acl_myfree(parser); \
	} \
	return (x); \
} while (0);

#undef	RETURN
#define	RETURN(x) do { \
	if (content_buf != NULL) \
		acl_myfree(content_buf); \
	if (filefd != ACL_FILE_INVALID) \
		acl_file_close(filefd); \
	return (x); \
} while (0);

	if (pathname == NULL || *pathname == 0) {
		printf("%s: invalid pathname\n", myname);
		return (NULL);
	}

	if (stat(pathname, &stat_buf) < 0) {
		printf("%s: can't stat, pathname=%s, errmsg=%s\n",
			myname, pathname, acl_last_strerror(tbuf, sizeof(tbuf)));
		ERETURN (NULL);
	}

	parser = (ACL_CFG_PARSER *) acl_mycalloc(1, sizeof(*parser));
	if (parser == NULL) {
		printf("%s: can't calloc ACL_CFG_PARSER, pathname=%s, errmsg=%s",
			myname, pathname, acl_last_strerror(tbuf, sizeof(tbuf)));
		ERETURN (NULL);
	}

	parser->_cfg_array = acl_array_create(10);
	if (parser->_cfg_array == NULL) {
		printf("%s: can't create array, pathname=%s, errmsg=%s",
			myname, pathname, acl_last_strerror(tbuf, sizeof(tbuf)));
		ERETURN (NULL);
	}
	parser->total_line = 0;
	parser->valid_line = 0;

	buf_size = (int) stat_buf.st_size + 256;
	content_buf = (char *) acl_mycalloc(1, buf_size);
	if (content_buf == NULL) {
		printf("%s: can't calloc, pathname=%s, errmsg=%s\n",
			myname, pathname, acl_last_strerror(tbuf, sizeof(tbuf)));
		ERETURN (NULL);
	}
	
#ifdef ACL_UNIX
# ifdef ACL_ANDROID
	filefd = acl_file_open(pathname, O_RDWR, 0644);
# else
	filefd = acl_file_open(pathname, O_RDWR, S_IREAD | S_IWRITE | S_IRGRP);
# endif
#elif defined(ACL_WINDOWS)
	filefd = acl_file_open(pathname, O_RDWR, S_IREAD | S_IWRITE);
#else
# error "unknown OS"
#endif

	if (filefd == ACL_FILE_INVALID) {
		printf("%s: can't open, pathname=%s, errmsg=%s\n",
			myname, pathname, acl_last_strerror(tbuf, sizeof(tbuf)));

		ERETURN (NULL);
	}

	if (_cfg_file_load(filefd, content_buf, buf_size) < 0) {
		printf("%s: can't read, pathname=%s, errmsg=%s\n",
			myname, pathname, acl_last_strerror(tbuf, sizeof(tbuf)));
		ERETURN (NULL);
	}

#undef	SKIP
#define SKIP(var, cond) \
        for (; *var && (cond); var++) {}

	ptr = content_buf;
	while (*ptr) {
		pline_begin = ptr;  /* keep the line header */
		/* first, skip all ' ' and '\t' */
		SKIP(ptr, (*ptr == ' ' || *ptr == '\t'));

		if  (*ptr == '#') {  /* the comment line */
			SKIP(ptr, *ptr != '\n'); /* find the line's end */
			if (*ptr) {  /* this must be '\n' */
				*ptr++ = 0;  /* set '\0' and skip one byte */
			}

			cfg_line = _backup_junk_line(pline_begin);
			if (cfg_line == NULL)
				ERETURN (NULL);
			if (acl_array_append(parser->_cfg_array,
					(void *) cfg_line) < 0) {
				printf("%s: can't add ACL_CFG_LINE to array, "
					"errmsg=%s", myname, acl_last_strerror(tbuf, sizeof(tbuf)));
				ERETURN (NULL);
			}
			parser->total_line++;
			cfg_line->line_number = parser->total_line;
			continue;
		} else if (*ptr == '\r' || *ptr == '\n') {
			/* SKIP(ptr, (*ptr == '\r' || *ptr == '\n')); */
			if (*ptr == '\r' && *(ptr + 1) == '\n') {
				*ptr = 0; /* set '\0' first and go on */
				ptr += 2;
			} else if (*ptr == '\n') {
				*ptr = 0; /* set '\0' first and go on */
				ptr++;
			}

			cfg_line = _backup_junk_line(pline_begin);
			if (cfg_line == NULL)
				ERETURN (NULL);
			if (acl_array_append(parser->_cfg_array,
					(void *) cfg_line) < 0) {
				printf("%s: can't add ACL_CFG_LINE to array, "
					"errmsg=%s", myname, acl_last_strerror(tbuf, sizeof(tbuf)));
				ERETURN (NULL);
			}
			parser->total_line++;
			cfg_line->line_number = parser->total_line;
			continue;
		}

		pline_begin = ptr;  /* reset the line header */

		/* find the line's end */
		SKIP(ptr, (*ptr != '\n' && *ptr != '\r'));
		if (*ptr) {  /* this must be '\r' or '\n' */
			if (*ptr == '\r' && *(ptr + 1) == '\n') {
				*ptr = 0; /* set '\0' first and go on */
				ptr += 2;
			} else if (*ptr == '\n') {
				*ptr = 0; /* set '\0' first and go on */
				ptr++;
			}
		}

		/* make ptr to the next line's beginning */
		/* SKIP(ptr, (*ptr == '\r' || *ptr == '\n')); */

		cfg_line = _create_cfg_line(pline_begin, delimiter);
		if (cfg_line == NULL)
			ERETURN (NULL);
		if (acl_array_append(parser->_cfg_array, (void *) cfg_line) < 0) {
			printf("%s: can't add ACL_CFG_LINE to array, errmsg=%s",
				myname, acl_last_strerror(tbuf, sizeof(tbuf)));
			ERETURN (NULL);
		}
		parser->total_line++;
		parser->valid_line++;
		cfg_line->line_number = parser->total_line;
	}

	if (parser->total_line != acl_array_size(parser->_cfg_array)) {
		printf("%s: total_line=%d, acl_array_size=%d, errmsg=not equal\n",
			myname, parser->total_line,
			acl_array_size(parser->_cfg_array));
	}

	RETURN (parser);
#ifdef ACL_BCB_COMPILER
	return (NULL);
#endif
}
Esempio n. 14
0
File: zdb.c Progetto: lunlun1992/acl
static ZDB_DISK *zdb_disks_load(const char *dbname, const char *dbpath)
{
    const char *myname = "zdb_disks_load";
    ACL_VSTRING *buf = acl_vstring_alloc(256);
    ACL_FILE *fp = NULL;
    char  disk_info[INFO_LEN + 1];
    ZDB_DISK *disk, *disks;
    ACL_ARRAY *a = NULL;
    ACL_ITER iter;
    int   n, i;

#undef	RETURN
#define	RETURN(x) do {  \
	if (fp)  \
		acl_fclose(fp);  \
	acl_vstring_free(buf);  \
	if (a)  \
		acl_array_destroy(a, free_disk);  \
	return (x);  \
} while (0)

    acl_vstring_sprintf(buf, "%s/.%s.disk", dbpath, dbname);
    fp = acl_fopen(STR(buf), "r");
    if (fp == NULL) {
        acl_msg_error("%s(%d): fopen(%s) error(%s)",
                      myname, __LINE__, STR(buf), acl_last_serror());
        RETURN (NULL);
    }

    a = acl_array_create(10);
    while (1) {
        ACL_ARGV *argv;

        if (acl_fgets_nonl(disk_info, sizeof(disk_info), fp) == NULL)
            break;
        argv = acl_argv_split(disk_info, "|");
        if (argv->argc != ITEM_CNT) {
            acl_msg_error("%s(%d): invalid line(%s)",
                          myname, __LINE__, disk_info);
            acl_argv_free(argv);
            continue;
        }
        disk = (ZDB_DISK*) acl_mycalloc(1, sizeof(ZDB_DISK));
        disk->path = acl_mystrdup(argv->argv[0]);
        disk->idisk = atoi(argv->argv[1]);
        disk->priority = atoi(argv->argv[2]);
        disk->limit = acl_atoui64(argv->argv[3]);
        disk->count = acl_atoui64(argv->argv[4]);
        if (acl_array_append(a, disk) < 0)
            acl_msg_fatal("%s(%d): add disk error(%s)",
                          myname, __LINE__, acl_last_serror());
        acl_argv_free(argv);
    }

    n = acl_array_size(a);
    if (n <= 0) {
        acl_msg_error("%s(%d): empty array of ZDB_DISK", myname, __LINE__);
        RETURN (NULL);
    }

    disks = (ZDB_DISK*) acl_mycalloc(n + 1, sizeof(ZDB_DISK));
    i = 0;
    acl_foreach(iter, a) {
        disk = (ZDB_DISK*) iter.data;
        disks[i].limit = disk->limit;
        disks[i].count = disk->count;
        disks[i].path = acl_mystrdup(disk->path);
        disks[i].idisk = disk->idisk;
        disks[i].priority = disk->priority;
        disks[i].dat_ifiles = NULL;
        disks[i].dat_ifiles_size = 0;
        if (disks[i].idisk != i) {
            acl_msg_error("%s(%d): idisk(%d) != %d invalid for %s",
                          myname, __LINE__, disks[i].idisk, i, disks[i].path);
            acl_myfree(disks);
            RETURN (NULL);
        }
        i++;
    }
Esempio n. 15
0
/* 分析配置文件中的第四个参数, 将其进行分解并存入动态数组之中 */
ACL_ARRAY *aut_parse_args_list(const char *str_in)
{
	const char *myname = "aut_parse_args_list";
	ACL_ARRAY *argvs_array = NULL;
	AUT_ARG_ITEM *arg_item = NULL;
	char *ptr_item, *pstr, *pstr_saved, *pname, *pvalue;
	char *ptr;
	int   len;
	char  tbuf[256];

	argvs_array = acl_array_create(10);
	pstr = acl_mystrdup(str_in);
	pstr_saved = pstr;

#define	SKIP_WHILE(_cond, _ptr) { while (*_ptr && (_cond)) _ptr++; }
#define	SKIP_WHILE_DEC(_cond, _ptr) { while (*_ptr && (_cond)) _ptr--; }

	len = strlen("=");
	while (1) {
		/* 找到每一参数项, 分隔符为逗号 */
		ptr_item = acl_mystrtok(&pstr, ",");
		if (ptr_item == NULL)
			break;

		/* 删除变量名前的空格和 tab */
		SKIP_WHILE((*ptr_item == ' ' || *ptr_item == '\t'), ptr_item);
		pname = ptr_item;

		/* 先找到等于号分隔符 */
		pvalue = strstr(ptr_item, "=");
		if (pvalue == NULL) /* not found '=' */
			continue;

		ptr = pvalue;

		/* 删除等号左边的空格或 tab */
		SKIP_WHILE_DEC((*ptr == ' ' || *ptr == '\t'), ptr);
		if (ptr < pvalue)
			*(++ptr) = 0;

		*pvalue = 0;
		pvalue += len; /* skip '=' */

		/* 删除等号右边的空格和ab */
		SKIP_WHILE((*pvalue == ' ' || *pvalue == '\t'), pvalue);
		if (*pvalue == 0)
			continue;

		/* 分配一个参数项 */
		arg_item = (AUT_ARG_ITEM *) acl_mycalloc(1, sizeof(AUT_ARG_ITEM));
		arg_item->name = acl_mystrdup(pname);
		arg_item->value = acl_mystrdup(pvalue);

		/* 把该参数项加入到动态数组之中 */
		if (acl_array_append(argvs_array, (void *) arg_item) < 0)
			aut_log_fatal("%s(%d): append to array error(%s)",
				myname, __LINE__, acl_last_strerror(tbuf, sizeof(tbuf)));
	}

	acl_myfree(pstr_saved);

	return (argvs_array);
}