/****************************************************************************** **函数名称: frwd_load_conf **功 能: 加载配置信息 **输入参数: ** path: 配置路径 ** log: 日志对象 **输出参数: ** conf: 配置信息 **返 回: 0:成功 !0:失败 **实现描述: 载入配置文件,再依次解析各标签内容 **注意事项: **作 者: # Qifeng.zou # 2015.06.10 # ******************************************************************************/ int frwd_load_conf(const char *path, frwd_conf_t *conf, log_cycle_t *log) { xml_opt_t opt; xml_tree_t *xml; memset(&opt, 0, sizeof(opt)); memset(conf, 0, sizeof(frwd_conf_t)); /* > 加载配置 */ opt.log = log; opt.pool = (void *)NULL; opt.alloc = (mem_alloc_cb_t)mem_alloc; opt.dealloc = (mem_dealloc_cb_t)mem_dealloc; xml = xml_creat(path, &opt); if (NULL == xml) { return -1; } /* > 提取通用配置 */ if (frwd_conf_load_comm(xml, conf)) { xml_destroy(xml); return -1; } /* > 提取发送配置 */ if (frwd_conf_load_frwder(xml, ".FRWDER.CONN-INVTD", &conf->conn_invtd)) { xml_destroy(xml); return -1; } xml_destroy(xml); return 0; }
/****************************************************************************** **函数名称: mon_conf_load **功 能: 加载配置信息 **输入参数: ** path: 配置路径 **输出参数: NONE **返 回: 0:成功 !0:失败 **实现描述: **注意事项: **作 者: # Qifeng.zou # 2015.03.15 # ******************************************************************************/ mon_conf_t *mon_conf_load(const char *path) { xml_opt_t opt; xml_tree_t *xml; mon_conf_t *conf; mem_pool_t *pool; /* > 创建配置对象 */ conf = (mon_conf_t *)calloc(1, sizeof(mon_conf_t)); if (NULL == conf) { return NULL; } /* > 构建XML树 */ pool = mem_pool_creat(4 * KB); if (NULL == pool) { free(conf); return NULL; } do { /* > 加载XML树 */ memset(&opt, 0, sizeof(opt)); opt.pool = pool; opt.alloc = (mem_alloc_cb_t)mem_pool_alloc; opt.dealloc = (mem_dealloc_cb_t)mem_pool_dealloc; xml = xml_creat(path, &opt); if (NULL == xml) { break; } /* > 提取配置信息 */ if (mon_conf_load_menu(xml, conf)) { break; } MON_LOAD_CONF(xml, ".MONITOR.CRAWLER", &conf->crwl); MON_LOAD_CONF(xml, ".MONITOR.FILTER", &conf->filter); MON_LOAD_CONF(xml, ".MONITOR.SEARCH", &conf->search); /* > 释放XML树 */ xml_destroy(xml); mem_pool_destroy(pool); return conf; } while(0); /* > 异常处理 */ free(conf); xml_destroy(xml); mem_pool_destroy(pool); return NULL; }
/****************************************************************************** **函数名称: lwsd_load_conf **功 能: 加载配置信息 **输入参数: ** path: 配置文件路径 ** log: 日志对象 **输出参数: ** conf: 配置信息 **返 回: 0:成功 !0:失败 **实现描述: 载入配置文件, 并提取其中的数据 **注意事项: **作 者: # Qifeng.zou # 2015-06-25 22:43:12 # ******************************************************************************/ int lwsd_load_conf(const char *path, lwsd_conf_t *conf, log_cycle_t *log) { xml_opt_t opt; xml_tree_t *xml = NULL; memset(conf, 0, sizeof(lwsd_conf_t)); do { /* > 构建XML树 */ memset(&opt, 0, sizeof(opt)); opt.log = log; opt.pool = (void *)NULL; opt.alloc = (mem_alloc_cb_t)mem_alloc; opt.dealloc = (mem_dealloc_cb_t)mem_dealloc; xml = xml_creat(path, &opt); if (NULL == xml) { log_error(log, "Create xml failed! path:%s", path); break; } /* > 加载通用配置 */ if (lwsd_conf_load_comm(xml, conf, log)) { log_error(log, "Load common configuration failed!"); break; } /* > 加载LWS配置 */ if (lwsd_conf_load_lws(xml, conf, log)) { log_error(log, "Load lws conf failed! path:%s", path); break; } /* > 加载转发配置 */ if (lwsd_conf_load_frwder(xml, conf, log)) { log_error(log, "Load frwder conf failed! path:%s", path); break; } /* > 释放XML树 */ xml_destroy(xml); return 0; } while(0); /* 异常处理 */ if (NULL != xml) { xml_destroy(xml); } return -1; }
/****************************************************************************** **函数名称: flt_worker_get_webpage_info **功 能: 获取网页信息 **输入参数: ** path: 网页信息文件 **输出参数: ** info: 网页信息 **返 回: 0:成功 !0:失败 **实现描述: **注意事项: **作 者: # Qifeng.zou # 2015.03.11 # ******************************************************************************/ static int flt_worker_get_webpage_info( const char *path, flt_webpage_info_t *info, log_cycle_t *log) { xml_opt_t opt; xml_tree_t *xml; mem_pool_t *pool; xml_node_t *node, *fix; memset(&opt, 0, sizeof(opt)); /* 1. 新建内存池 */ pool = mem_pool_creat(4 * KB); if (NULL == pool) { log_error(log, "errmsg:[%d] %s!", errno, strerror(errno)); return FLT_ERR; } /* 2. 新建XML树 */ opt.log = log; opt.pool = pool; opt.alloc = (mem_alloc_cb_t)mem_pool_alloc; opt.dealloc = (mem_dealloc_cb_t)mem_pool_dealloc; xml = xml_creat(path, &opt); if (NULL == xml) { mem_pool_destroy(pool); log_error(log, "Create XML failed! path:%s", path); return FLT_ERR; } /* 2. 提取网页信息 */ do { fix = xml_query(xml, ".WPI"); if (NULL == fix) { log_error(log, "Get WPI mark failed!"); break; } /* 获取URI字段 */ node = xml_search(xml, fix, "URI"); if (NULL == node) { log_error(log, "Get URI mark failed!"); break; } snprintf(info->uri, sizeof(info->uri), "%s", node->value.str); /* 获取DEPTH字段 */ node = xml_search(xml, fix, "URI.DEPTH"); if (NULL == node) { log_error(log, "Get DEPTH mark failed!"); break; } info->depth = atoi(node->value.str); /* 获取IP字段 */ node = xml_search(xml, fix, "URI.IP"); if (NULL == node) { log_error(log, "Get IP mark failed!"); break; } snprintf(info->ip, sizeof(info->ip), "%s", node->value.str); /* 获取PORT字段 */ node = xml_search(xml, fix, "URI.PORT"); if (NULL == node) { log_error(log, "Get PORT mark failed!"); break; } info->port = atoi(node->value.str); /* 获取HTML字段 */ node = xml_search(xml, fix, "HTML"); if (NULL == node) { log_error(log, "Get HTML mark failed!"); break; } snprintf(info->html, sizeof(info->html), "%s", node->value.str); /* 获取HTML.SIZE字段 */ node = xml_search(xml, fix, "HTML.SIZE"); if (NULL == node) { log_error(log, "Get HTML.SIZE mark failed!"); break; } info->size = atoi(node->value.str); if (info->size <= 0) { log_info(log, "Html size is zero!"); break; } snprintf(info->fname, sizeof(info->fname), "%s", path); xml_destroy(xml); mem_pool_destroy(pool); return FLT_OK; } while(0); /* 3. 释放XML树 */ xml_destroy(xml); mem_pool_destroy(pool); return FLT_ERR; }