void http_hdr_build_request(const HTTP_HDR_REQ *hdr_req, ACL_VSTRING *strbuf) { ACL_ARRAY *entries; HTTP_HDR_ENTRY *entry; int i, n; entries = hdr_req->hdr.entry_lnk; n = acl_array_size(entries); entry = (HTTP_HDR_ENTRY *) acl_array_index(entries, 0); #if 0 acl_vstring_sprintf(strbuf, "%s %s\r\n", entry->name, entry->value); #else acl_vstring_sprintf(strbuf, "%s %s HTTP/%d.%d\r\n", entry->name, acl_vstring_str(hdr_req->url_part), hdr_req->hdr.version.major, hdr_req->hdr.version.minor); #endif for (i = 1; i < n; i++) { entry = (HTTP_HDR_ENTRY *) acl_array_index(entries, i); if (entry == NULL) break; if (entry->off) continue; acl_vstring_sprintf_append(strbuf, "%s: %s\r\n", entry->name, entry->value); } acl_vstring_strcat(strbuf, "\r\n"); }
bool CMsnContactManager::ParseAddresses(ACL_XML* body) { /////////////////////////////////////////////////////////////////////// // 分析 soap:Body/ABFindAllResponse/ABFindAllResult const char* tag_ABFindAllResult = "soap:Body/ABFindAllResponse/ABFindAllResult"; ACL_ARRAY* a_ABFindAllResult = acl_xml_getElementsByTags(body, tag_ABFindAllResult); if (a_ABFindAllResult == NULL) { logger("tag(%s) not found", tag_ABFindAllResult); return (true); } ACL_XML_NODE* ABFindAllResult = (ACL_XML_NODE*) acl_array_index(a_ABFindAllResult, 0); ACL_XML xml; acl_xml_foreach_init(&xml, ABFindAllResult); // 分析所有的组 ACL_ARRAY* a_group = acl_xml_getElementsByTags(&xml, "groups/Group"); if (a_group != NULL) { // 创建组集合对象 groups_ = CMsnGroups::Create(a_group); acl_xml_free_array(a_group); groups_->Out(); } // 分析所有的联系人 ACL_ARRAY* a_contacts = acl_xml_getElementsByTags(&xml, "contacts/Contact"); if (a_contacts != NULL) { // 创建联系人集合对象 contacts_ = CMsnContacts::Create(a_contacts, groups_); acl_xml_free_array(a_contacts); contacts_->Out(); } ACL_ARRAY* a_addressAb = acl_xml_getElementsByTags(&xml, "ab"); if (a_addressAb != NULL) { ACL_XML_NODE* node = (ACL_XML_NODE* ) acl_array_index(a_addressAb, 0); acl_xml_foreach_init(&xml, node); addressAb_ = NEW CMsnAddressBookAb(&xml); acl_xml_free_array(a_addressAb); } acl_xml_free_array(a_ABFindAllResult); return (true); }
const ACL_HOSTNAME *acl_netdb_index(const ACL_DNS_DB *h_dns_db, int n) { const char *myname = "acl_netdb_index"; ACL_HOSTNAME *h_hostname; if (h_dns_db == NULL || n < 0) { acl_msg_error("%s, %s(%d): input error", __FILE__, myname, __LINE__); return (NULL); } if (h_dns_db->size == 0) { acl_msg_error("%s, %s(%d): dns db size is 0", __FILE__, myname, __LINE__); return (NULL); } if (n >= h_dns_db->size) { acl_msg_error("%s, %s(%d): index(%d) > size(%d)", __FILE__, myname, __LINE__, n, h_dns_db->size); return (NULL); } h_hostname = (ACL_HOSTNAME *) acl_array_index(h_dns_db->h_db, n); return (h_hostname); }
void acl_netdb_refer_oper(ACL_DNS_DB *h_dns_db, int idx, int value) { const char *myname = "acl_netdb_refer_oper"; ACL_HOSTNAME *h_hostname; if (h_dns_db == NULL || idx < 0) { acl_msg_error("%s, %s(%d): input error", __FILE__, myname, __LINE__); return; } if (h_dns_db->size == 0) { acl_msg_error("%s, %s(%d): dns db size is 0", __FILE__, myname, __LINE__); return; } if (idx >= h_dns_db->size) { acl_msg_error("%s, %s(%d): index(%d) > size(%d)", __FILE__, myname, __LINE__, idx, h_dns_db->size); return; } h_hostname = (ACL_HOSTNAME *) acl_array_index(h_dns_db->h_db, idx); h_hostname->nrefer += value; }
ACL_DNS_DB *acl_netdb_clone(const ACL_DNS_DB *db) { ACL_DNS_DB *dbp; ACL_HOSTNAME *phost, *h_host; int i, n; if (db == NULL || db->h_db == NULL) return NULL; n = acl_array_size(db->h_db); if (n <= 0) { acl_msg_error("%s, %s(%d): h_db's size(%d) <= 0", __FILE__, __FUNCTION__, __LINE__, n); return NULL; } dbp = acl_netdb_new(db->name); for (i = 0; i < n; i++) { phost = (ACL_HOSTNAME *) acl_array_index(db->h_db, i); acl_assert(phost); h_host = acl_mycalloc(1, sizeof(ACL_HOSTNAME)); memcpy(&h_host->saddr, &phost->saddr, sizeof(h_host->saddr)); ACL_SAFE_STRNCPY(h_host->ip, phost->ip, sizeof(h_host->ip)); h_host->hport = phost->hport; (void) acl_array_append(dbp->h_db, h_host); dbp->size++; } return dbp; }
int acl_cfg_parser_dump(const ACL_CFG_PARSER *parser, const char *pathname, const char *delimiter) { char myname[] = "acl_cfg_parser_dump"; ACL_CFG_LINE *cfg_line; ACL_FILE_HANDLE filefd = ACL_FILE_INVALID; int i, n, ret; char tbuf[256]; #undef RETURN #define RETURN(x) do { \ if (filefd != ACL_FILE_INVALID) \ acl_file_close(filefd); \ return (x); \ } while (0); if (parser == NULL || pathname == NULL || *pathname == 0) return (-1); #ifdef ACL_UNIX # ifdef ACL_ANDROID filefd = acl_file_open(pathname, O_CREAT | O_TRUNC | O_APPEND | O_WRONLY, 0644); # else filefd = acl_file_open(pathname, O_CREAT | O_TRUNC | O_APPEND | O_WRONLY, S_IREAD | S_IWRITE | S_IRGRP); # endif #elif defined(ACL_WINDOWS) filefd = acl_file_open(pathname, O_CREAT | O_TRUNC | O_APPEND | O_WRONLY, 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))); RETURN(-1); } n = acl_array_size(parser->_cfg_array); for (i = 0; i < n; i++) { cfg_line = (ACL_CFG_LINE *) acl_array_index(parser->_cfg_array, i); if (cfg_line == NULL) break; ret = _cfg_line_dump(filefd, cfg_line, delimiter); if (ret < 0) { RETURN (-1); } } RETURN (0); #ifdef ACL_BCB_COMPILER return (0); #endif }
int acl_cfg_parser_delete(ACL_CFG_PARSER *parser, const char *name) { char myname[] = "acl_cfg_parser_delete"; ACL_CFG_LINE *cfg_line = NULL; int i, n, ok = 0, j; if (parser == NULL || name == NULL || *name == 0) { printf("%s: input error\n", myname); return (-1); } if (parser->_cfg_array == NULL) { return (0); } n = acl_array_size(parser->_cfg_array); for (i = 0; i < n; i++) { cfg_line = (ACL_CFG_LINE *) acl_array_index(parser->_cfg_array, i); if (cfg_line == NULL) return (0); if (cfg_line->ncount < 1) continue; if (strcmp(cfg_line->value[0], name) == 0) { ok = 1; break; } } if (ok) { if (cfg_line->pdata == NULL && cfg_line->value != NULL) parser->valid_line--; parser->total_line--; acl_array_delete_idx(parser->_cfg_array, i, _cfg_line_free); n = acl_array_size(parser->_cfg_array); for (j = i; j < n; j++) { cfg_line = (ACL_CFG_LINE *) acl_array_index(parser->_cfg_array, j); if (cfg_line == NULL) break; cfg_line->line_number--; } } return (0); }
ACL_DNS_DB *acl_netdb_clone(const ACL_DNS_DB *h_dns_db) { const char *myname = "acl_netdb_clone"; char buf[256]; ACL_DNS_DB *dns_db; ACL_HOSTNAME *phost, *h_host; int i, n; if (h_dns_db == NULL || h_dns_db->h_db == NULL) return (NULL); n = acl_array_size(h_dns_db->h_db); if (n <= 0) { acl_msg_error("%s, %s(%d): h_db's size(%d) <= 0", __FILE__, myname, __LINE__, n); return (NULL); } dns_db = acl_netdb_new(h_dns_db->name); if (dns_db == NULL) { acl_msg_error("%s, %s(%d): acl_netdb_new error(%s)", __FILE__, myname, __LINE__, acl_last_strerror(buf, sizeof(buf))); return (NULL); } for (i = 0; i < n; i++) { phost = (ACL_HOSTNAME *) acl_array_index(h_dns_db->h_db, i); acl_assert(phost); h_host = acl_mycalloc(1, sizeof(ACL_HOSTNAME)); if (h_host == NULL) { acl_msg_error("%s, %s(%d): calloc error(%s)", __FILE__, myname, __LINE__, acl_last_strerror(buf, sizeof(buf))); acl_netdb_free(dns_db); return (NULL); } h_host->saddr.sin_addr.s_addr = phost->saddr.sin_addr.s_addr; ACL_SAFE_STRNCPY(h_host->ip, phost->ip, sizeof(h_host->ip)); h_host->hport = phost->hport; if (acl_array_append(dns_db->h_db, h_host) < 0) { acl_msg_error("%s, %s(%d): array append error(%s)", __FILE__, myname, __LINE__, acl_last_strerror(buf, sizeof(buf))); acl_netdb_free(dns_db); return (NULL); } dns_db->size++; } return (dns_db); }
ACL_CFG_LINE *acl_cfg_parser_index(const ACL_CFG_PARSER *parser, int idx) { ACL_CFG_LINE *cfg_line; if (parser == NULL || idx < 0) return (NULL); cfg_line = (ACL_CFG_LINE *) acl_array_index(parser->_cfg_array, idx); return (cfg_line); }
/* 打印输出配置文件中的有效配置行 */ int aut_cfg_print(void) { const char *myname = "aut_cfg_print"; AUT_LINE *line = NULL; AUT_ARG_ITEM *arg; int i, j, n, m, first_line_arg; if (var_aut_line_array == NULL) { printf("%s: var_aut_line_array=NULL\n", myname); return (-1); } n = acl_array_size(var_aut_line_array); for (i = 0; i < n; i++) { line = (AUT_LINE *) acl_array_index(var_aut_line_array, i); if (line == NULL) break; printf("%s|%d|%d|", line->cmd_name, line->result, line->argc); m = acl_array_size(line->argv); first_line_arg = 1; for (j = 0; j < m; j++) { arg = (AUT_ARG_ITEM *) acl_array_index(line->argv, j); if (arg == NULL) break; /* 判断是否是第一个参数项 */ if (first_line_arg) { printf("%s=%s", arg->name, arg->value); first_line_arg = 0; } else { printf(",%s=%s", arg->name, arg->value); } } printf("\n"); } return (0); }
void http_hdr_build(const HTTP_HDR *hdr, ACL_VSTRING *strbuf) { ACL_ARRAY *entries; HTTP_HDR_ENTRY *entry; int i, n; entries = hdr->entry_lnk; n = acl_array_size(entries); entry = (HTTP_HDR_ENTRY *) acl_array_index(entries, 0); acl_vstring_sprintf(strbuf, "%s %s\r\n", entry->name, entry->value); for (i = 1; i < n; i++) { entry = (HTTP_HDR_ENTRY *) acl_array_index(entries, i); if (entry == NULL) break; if (entry->off) continue; acl_vstring_sprintf_append(strbuf, "%s: %s\r\n", entry->name, entry->value); } acl_vstring_strcat(strbuf, "\r\n"); }
int http_hdr_res_parse(HTTP_HDR_RES *hdr_res) { const char *myname = "http_hdr_res_parse"; HTTP_HDR *hdr = (HTTP_HDR *) hdr_res; HTTP_HDR_ENTRY *entry; char *ptr; char buf[32]; /* 2xx, 3xx, 4xx, 5xx */ int n; if (hdr == NULL) acl_msg_fatal("%s: hdr_res null", myname); if (hdr->entry_lnk == NULL) acl_msg_fatal("%s: entry_lnk null", myname); n = acl_array_size(hdr->entry_lnk); if (n <= 0) { acl_msg_error("%s: entry_lnk's size %d invalid", myname, n); return (-1); } /* data format: xxx info */ entry = (HTTP_HDR_ENTRY *) acl_array_index(hdr->entry_lnk, 0); ptr = entry->value; while (*ptr == ' ' || *ptr == '\t') ptr++; if (*ptr == 0) { acl_msg_error("%s: status empty", myname); return (-1); } snprintf(buf, sizeof(buf), "%s", ptr); ptr = buf; while (*ptr) { if (*ptr == ' ' || *ptr == '\t') { *ptr = 0; break; } ptr++; } hdr_res->reply_status = atoi(buf); if (hdr_res->reply_status < 100 || hdr_res->reply_status >= 600) { acl_msg_error("%s: status(%s) invalid", myname, buf); return (-1); } return (http_hdr_parse(hdr)); }
void acl_cfg_parser_walk(ACL_CFG_PARSER *parser, ACL_CFG_WALK_FN walk_fn) { int i, n; ACL_CFG_LINE *cfg_line; if (parser) { n = acl_array_size(parser->_cfg_array); for (i = 0; i < n; i++) { cfg_line = (ACL_CFG_LINE *) acl_array_index(parser->_cfg_array, i); if (cfg_line == NULL) break; walk_fn((void *) cfg_line); } } }
static AUT_LINE *__mkcmd_endif(const ACL_CFG_LINE *line) { char myname[] = "__mkcmd_endif"; AUT_LINE *test_line, *test_line_peer; AUT_CMD_TOKEN *if_token = NULL, *if_token_peer; int n, i; __if_nested_count--; if_token = (AUT_CMD_TOKEN *) acl_mycalloc(1, sizeof(*if_token)); if_token->flag = AUT_FLAG_ENDIF; if_token->match_number = ++__endif_count; if_token->peer = NULL; test_line = aut_line_new(line); test_line->arg_inner = (void *) if_token; test_line->free_arg_inner = acl_myfree_fn; n = acl_array_size(var_aut_line_array); for (i = 0; i < n; i++) { test_line_peer = (AUT_LINE *) acl_array_index(var_aut_line_array, i); if (test_line_peer->arg_inner == NULL) continue; if_token_peer = (AUT_CMD_TOKEN *) test_line_peer->arg_inner; if (if_token_peer->flag != AUT_FLAG_IF) continue; if (if_token_peer->match_number != if_token->match_number) continue; /* 找到匹配的循环开始对等结点 */ if_token_peer->peer = test_line; if_token->peer = test_line_peer; } if (if_token->peer == NULL) { aut_log_fatal("%s: line_number=%d, cmd=%s, " "if_nested=%d, if_count=%d, " "endif_count=%d, please check configure, " "err_msg=not found peer loop begin", myname, test_line->line_number, test_line->cmd_name, __if_nested_count, __if_count, __endif_count); } return (test_line); }
AUT_LINE *aut_loop_make_break(const ACL_CFG_LINE *cfg_line) { const char *myname = "aut_loop_make_break"; AUT_LINE *break_line, *tmp_line, *begin_line; AUT_CMD_TOKEN *break_token, *tmp_token, *begin_token; int i, n; break_line = aut_line_new(cfg_line); break_line->obj_type = AUT_OBJ_INNER; break_token = (AUT_CMD_TOKEN *) acl_mycalloc(1, sizeof(AUT_CMD_TOKEN)); break_token->flag = AUT_FLAG_LOOP_BREAK; /* 将 breaktoken 作为内部参数存储在 break_line->arg_inner 中 */ break_line->arg_inner = (void *) break_token; break_line->free_arg_inner = acl_myfree_fn; n = acl_array_size(var_aut_line_array); begin_line = NULL; begin_token = NULL; for (i = n - 1; i >= 0; i--) { tmp_line = (AUT_LINE *) acl_array_index(var_aut_line_array, i); if (tmp_line == NULL) aut_log_fatal("%s(%d): loop_begin null", myname, __LINE__); if (tmp_line->obj_type != AUT_OBJ_INNER) continue; if (tmp_line->arg_inner == NULL) continue; tmp_token = (AUT_CMD_TOKEN *) tmp_line->arg_inner; if (tmp_token->flag != AUT_FLAG_LOOP_BEGIN) continue; begin_line = tmp_line; begin_token = tmp_token; break; } if (begin_line == NULL || begin_token == NULL) aut_log_fatal("%s(%d): no LOOP_BEGIN before LOOP_BREAK", myname, __LINE__); break_token->peer = begin_line; return (break_line); }
int proctl_service_exist(const char *filepath) { PROCTL_SERVICE *service; int i, n; LOCK_RUNNING_SERVICE; n = acl_array_size(__services); for (i = 0; i < n; i++) { service = (PROCTL_SERVICE*) acl_array_index(__services, i); if (strcasecmp(service->filepath, filepath) == 0) break; } UNLOCK_RUNNING_SERVICE; if (n <= 0 || i == n) return (0); return (1); }
static AUT_FN_ITEM *__lookup_fn_item(const AUT_LINE *test_line) { char myname[] = "__lookup_fn_item"; int i, n; AUT_FN_ITEM *item = NULL, *tmp; n = acl_array_size(__all_callback_fn); for (i = 0; i < n; i++) { tmp = (AUT_FN_ITEM *) acl_array_index(__all_callback_fn, i); if (tmp == NULL) aut_log_fatal("%s(%d): idx=%d, null rebuild from array", myname, __LINE__, i); if (aut_line_cmdcmp(test_line, tmp->cmd_name) == 0) { item = tmp; break; } } return (item); }
static PROCTL_SERVICE *proctl_service_find(HANDLE handle) { const char *myname = "proctl_service_find"; PROCTL_SERVICE *service; int i, n; LOCK_RUNNING_SERVICE; n = acl_array_size(__services); for (i = 0; i < n; i++) { service = (PROCTL_SERVICE*) acl_array_index(__services, i); if (service->hProcess == handle) { UNLOCK_RUNNING_SERVICE; return (service); } } UNLOCK_RUNNING_SERVICE; return (NULL); }
ACL_ARGV *proctl_serivce_get_all() { ACL_ARGV *argv = acl_argv_alloc(10); PROCTL_SERVICE *service; int i, n; LOCK_RUNNING_SERVICE; n = acl_array_size(__services); for (i = 0; i < n; i++) { service = (PROCTL_SERVICE*) acl_array_index(__services, i); acl_argv_add(argv, service->filepath, NULL); } UNLOCK_RUNNING_SERVICE; if (argv->argc == 0) { acl_argv_free(argv); return (NULL); } return (argv); }
const char *acl_netdb_index_ip(const ACL_DNS_DB *db, int n) { ACL_HOSTNAME *h_hostname; if (db == NULL || n < 0) { acl_msg_error("%s, %s(%d): input error", __FILE__, __FUNCTION__, __LINE__); return NULL; } if (db->size == 0) { acl_msg_error("%s, %s(%d): dns db size is 0", __FILE__, __FUNCTION__, __LINE__); return NULL; } if (n >= db->size) { acl_msg_error("%s, %s(%d): index(%d) > size(%d)", __FILE__, __FUNCTION__, __LINE__, n, db->size); return NULL; } h_hostname = (ACL_HOSTNAME *) acl_array_index(db->h_db, n); return h_hostname->ip; }
/*----------------------------------------------------------------------------*/ static void __dbpool_mysql_destroy(ACL_DB_POOL *db_pool) { ACL_DB_POOL_MYSQL *mysql_pool; ACL_DB_HANDLE_MYSQL *mysql_handle; int i, n; mysql_pool = (ACL_DB_POOL_MYSQL *) db_pool; n = acl_array_size(mysql_pool->handles); for (i = 0; i < n; i++) { mysql_handle = (ACL_DB_HANDLE_MYSQL *) acl_array_index(mysql_pool->handles, i); if (mysql_handle == NULL) continue; __close_mysql_handle(mysql_handle); acl_myfree(mysql_handle); } acl_pthread_mutex_destroy(&mysql_pool->mutex); acl_array_destroy(mysql_pool->handles, NULL); acl_myfree(mysql_pool); mysql_library_end(); }
int acl_iplink_list(const ACL_IPLINK *plink) { int i, n; ACL_IPITEM *item; char buf[64]; unsigned ip_begin, ip_end; n = acl_array_size(plink->parray); for (i = 0; i < n; i++) { item = (ACL_IPITEM *) acl_array_index(plink->parray, i); if (item == NULL) break; ip_begin = (unsigned) item->begin; ip_end = (unsigned) item->end; __sane_inet_ntoa(ip_begin, buf, sizeof(buf)); printf("ipbegin=%s", buf); __sane_inet_ntoa(ip_end, buf, sizeof(buf)); printf(", ipend=%s\n", buf); } return n; }
/*----------------------------------------------------------------------------*/ static void __dbpool_mysql_check(ACL_DB_POOL *db_pool) { ACL_DB_POOL_MYSQL *mysql_pool = (ACL_DB_POOL_MYSQL*) db_pool; ACL_DB_HANDLE_MYSQL *mysql_handle; int i, n, ping_inter; time_t now = time(NULL); ping_inter = mysql_pool->db_pool.db_info.ping_inter; n = acl_array_size(mysql_pool->handles); for (i = 0; i < n; i++) { mysql_handle = (ACL_DB_HANDLE_MYSQL *) acl_array_index(mysql_pool->handles, i); if (mysql_handle == NULL) continue; if (mysql_handle->handle.status != ACL_DBH_STATUS_READY) continue; /* if the connecion is idle timeout ? */ if (now > mysql_handle->handle.timeout) { __close_mysql_handle(mysql_handle); mysql_pool->db_pool.db_ready--; continue; } /* has the ping time reached ? */ if (now <= mysql_handle->handle.ping) continue; if (mysql_ping(mysql_handle->connection) == 0) { mysql_handle->handle.ping = time(NULL) + ping_inter; } else { __close_mysql_handle(mysql_handle); mysql_pool->db_pool.db_ready--; } } }
void acl_netdb_refer_oper(ACL_DNS_DB *db, int idx, int value) { ACL_HOSTNAME *h_hostname; if (db == NULL || idx < 0) { acl_msg_error("%s, %s(%d): input error", __FILE__, __FUNCTION__, __LINE__); return; } if (db->size == 0) { acl_msg_error("%s, %s(%d): dns db size is 0", __FILE__, __FUNCTION__, __LINE__); return; } if (idx >= db->size) { acl_msg_error("%s, %s(%d): index(%d) > size(%d)", __FILE__, __FUNCTION__, __LINE__, idx, db->size); return; } h_hostname = (ACL_HOSTNAME *) acl_array_index(db->h_db, idx); h_hostname->nrefer += value; }
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); }
/*----------------------------------------------------------------------------*/ static ACL_DB_HANDLE *__dbpool_mysql_peek(ACL_DB_POOL *db_pool) { char myname[] = "__dbpool_mysql_peek"; ACL_DB_POOL_MYSQL *mysql_pool = (ACL_DB_POOL_MYSQL *) db_pool; ACL_DB_HANDLE_MYSQL *mysql_handle, *mysql_handle_slot = NULL; int i, n; time_t now; static time_t last_time; /* 因为在调用此函数时已经上锁, * 所以此处声明一静态变量是线程安全的. */ #undef RETURN #define RETURN(_x_) do { \ now = time(NULL); \ if (acl_msg_verbose && now - last_time > 5) { \ acl_msg_info("Database status: max = %d, idle = %d, busy = %d", \ db_pool->db_max, db_pool->db_ready, db_pool->db_inuse); \ last_time = now; \ } \ DB_UNLOCK(mysql_pool->mutex); \ return (_x_); \ } while (0) DB_LOCK(mysql_pool->mutex); if (time(NULL) >= mysql_pool->when_check) { int inter = db_pool->db_info.ping_inter > db_pool->db_info.timeout_inter ? db_pool->db_info.timeout_inter : db_pool->db_info.ping_inter; db_pool->dbh_check(db_pool); mysql_pool->when_check = time(NULL) + inter; } if (db_pool->db_inuse >= db_pool->db_max) { acl_msg_warn("%s, %s(%d): all connections be used, reached db_max(%d)", __FILE__, myname, __LINE__, db_pool->db_max); RETURN (NULL); } n = acl_array_size(mysql_pool->handles); /* lookup mysql connection from pool */ for (i = 0; i < n; i++) { mysql_handle = (ACL_DB_HANDLE_MYSQL *) acl_array_index(mysql_pool->handles, i); if (mysql_handle == NULL) continue; if (mysql_handle->handle.status == ACL_DBH_STATUS_READY) { mysql_handle->handle.status = ACL_DBH_STATUS_INUSE; db_pool->db_inuse++; db_pool->db_ready--; RETURN ((ACL_DB_HANDLE *) mysql_handle); } else if (mysql_handle->handle.status == ACL_DBH_STATUS_NULL && mysql_handle_slot == NULL) mysql_handle_slot = mysql_handle; } /* create new mysql connection */ mysql_handle = __open_mysql_handle(mysql_pool, mysql_handle_slot, &db_pool->db_info); if (mysql_handle == NULL) RETURN (NULL); mysql_handle->handle.status = ACL_DBH_STATUS_INUSE; db_pool->db_inuse++; RETURN ((ACL_DB_HANDLE *) mysql_handle); }
AUT_LINE *aut_loop_make_end(const ACL_CFG_LINE *cfg_line) { const char *myname = "aut_loop_make_end"; AUT_LINE *test_line, *test_line_peer; AUT_CMD_TOKEN *loop_token = NULL, *loop_token_peer; int n, i; /* 记数器, 对 loop_end 标记记数减 1 */ __loop_end_count++; loop_token = (AUT_CMD_TOKEN *) acl_mycalloc(1, sizeof(*loop_token)); loop_token->flag = AUT_FLAG_LOOP_END; loop_token->status = AUT_STAT_BUSY; /* 与前面的 loop_begin 相匹配 */ loop_token->match_number = __loop_nested_count; loop_token->peer = NULL; /* 循环对嵌套减 1 */ __loop_nested_count--; test_line = aut_line_new(cfg_line); test_line->obj_type = AUT_OBJ_INNER; /* 将 loop_token 作为内部参数存储在 test_line->arg_inner 中 */ test_line->arg_inner = (void *) loop_token; test_line->free_arg_inner = acl_myfree_fn; n = acl_array_size(var_aut_line_array); /* 查找与循环结束标志相配对的循环开始对象 */ for (i = 0; i < n; i++) { test_line_peer = (AUT_LINE *) acl_array_index(var_aut_line_array, i); /* xxx: 不应该发生此种情况, 除非动态数组出了故障 */ if (test_line_peer == NULL) break; /* 先判断是否是内部对象 */ if (test_line_peer->obj_type != AUT_OBJ_INNER) continue; /* 先查看是否有内部数据参数存储在 test_line_peer 中 */ if (test_line_peer->arg_inner == NULL) continue; loop_token_peer = (AUT_CMD_TOKEN *) test_line_peer->arg_inner; /* 看该 loopbegin 对象是否已经被 一个 loopend 对象给匹配了 */ if (loop_token_peer->status == AUT_STAT_BUSY) continue; /* 是否是 循环开始标志, 以判断是否是一个循环的开始 */ if (loop_token_peer->flag != AUT_FLAG_LOOP_BEGIN) continue; /* 比较匹配行号是否相等 */ if (loop_token_peer->match_number != loop_token->match_number) continue; /* 找到匹配的循环开始对等结点 */ loop_token_peer->peer = test_line; loop_token_peer->status = AUT_STAT_BUSY; loop_token->peer = test_line_peer; } if (loop_token->peer == NULL) { aut_log_fatal("%s(%d)->%s: line_number=%d, cmd=%s, " "loop_nested=%d, loop_begin=%d, " "loop_end=%d, please check configure, " "err_msg=not found peer loop begin", __FILE__, __LINE__, myname, test_line->line_number, test_line->cmd_name, __loop_nested_count, __loop_begin_count, __loop_end_count); } return (test_line); }