Example #1
0
/******************************************************************************
 **函数名称: frwd_conf_load_comm
 **功    能: 加载通用配置
 **输入参数: 
 **     xml: XML树
 **输出参数:
 **     conf: 发送配置
 **返    回: 0:成功 !0:失败
 **实现描述: 
 **注意事项: 
 **作    者: # Qifeng.zou # 2015.06.10 11:38:57 #
 ******************************************************************************/
static int frwd_conf_load_comm(xml_tree_t *xml, frwd_conf_t *conf)
{
    xml_node_t *node;

    /* > 结点名 */
    node = xml_query(xml, ".FRWDER.NAME");
    if (NULL == node
        || 0 == node->value.len)
    {
        return -1;
    }

    snprintf(conf->name, sizeof(conf->name), "%s", node->value.str);

    /* > 发送至Agentd */
    node = xml_query(xml, ".FRWDER.LISTEND.NAME");
    if (NULL == node
        || 0 == node->value.len)
    {
        fprintf(stderr, "Didn't find .FRWDER.LISTEND.NAME!\n");
        return -1;
    }

    snprintf(conf->lsnd_name, sizeof(conf->lsnd_name), "%s", node->value.str);

    return 0;
}
Example #2
0
/******************************************************************************
 **函数名称: lwsd_conf_load_comm
 **功    能: 加载公共配置
 **输入参数: 
 **     path: 配置文件路径
 **     log: 日志对象
 **输出参数:
 **     conf: 配置信息
 **返    回: 0:成功 !0:失败
 **实现描述: 提取配置文件中的数据
 **注意事项: 
 **作    者: # Qifeng.zou # 2015-06-25 22:43:12 #
 ******************************************************************************/
static int lwsd_conf_load_comm(xml_tree_t *xml, lwsd_conf_t *conf, log_cycle_t *log)
{
    xml_node_t *node, *fix;

    /* > 加载结点ID */
    node = xml_query(xml, ".LISTEND.ID");
    if (NULL == node
        || 0 == node->value.len)
    {
        log_error(log, "Get node id failed!");
        return -1;
    }

    conf->nid = str_to_num(node->value.str);

    /* > 加载工作路径 */
    node = xml_query(xml, ".LISTEND.WORKDIR");
    if (NULL == node
        || 0 == node->value.len)
    {
        log_error(log, "Get work directory failed!");
        return -1;
    }

    snprintf(conf->wdir, sizeof(conf->wdir), "%s/%d", node->value.str, conf->nid);  /* 工作路径 */

    /* > 分发队列配置 */
    fix = xml_query(xml, ".LISTEND.DISTQ");
    if (NULL == fix) {
        log_error(log, "Get distribute queue failed!");
        return -1;
    }

    node = xml_search(xml, fix, "NUM");
    if (NULL == node) {
        log_error(log, "Get number of distribue queue failed!");
        return -1;
    }

    conf->distq.num = str_to_num(node->value.str);

    node = xml_search(xml, fix, "MAX");
    if (NULL == node) {
        log_error(log, "Get the max container of distribue queue failed!");
        return -1;
    }

    conf->distq.max = str_to_num(node->value.str);

    node = xml_search(xml, fix, "SIZE");
    if (NULL == node) {
        log_error(log, "Get the size of distribue queue failed!");
        return -1;
    }

    conf->distq.size = str_to_num(node->value.str);

    return 0;
}
Example #3
0
/******************************************************************************
 **函数名称: invtd_search_parse
 **功    能: 解析搜索请求
 **输入参数:
 **     ctx: 全局对象
 **     buff: 搜索请求(报头+报体)
 **     len: 数据长度
 **输出参数:
 **     req: 搜索请求
 **返    回: 0:成功 !0:失败
 **实现描述:
 **注意事项:
 **作    者: # Qifeng.zou # 2015.12.27 03:39:00 #
 ******************************************************************************/
static int invtd_search_parse(invtd_cntx_t *ctx,
        char *buf, size_t len, mesg_search_req_t *req)
{
    xml_opt_t opt;
    xml_tree_t *xml;
    xml_node_t *node;
    mesg_header_t *head = (mesg_header_t *)buf;
    const char *xml_str = (const char *)(head + 1);

    /* > 字节序转换 */
    MESG_HEAD_NTOH(head, head);

    /* > 校验合法性 */
    if (!MESG_CHKSUM_ISVALID(head)
        ||  (len != MESG_TOTAL_LEN(head->length)))
    {
        log_error(ctx->log, "sid:%lu serial:%lu type:%u flag:%u chksum:0x%X len:%d body:%s",
                head->sid, head->serial, head->type,
                head->flag, head->chksum, head->length, xml_str);
        return -1;
    }

    log_trace(ctx->log, "sid:%lu serial:%lu type:%u flag:%u chksum:0x%X len:%d body:%s",
            head->sid, head->serial, head->type,
            head->flag, head->chksum, head->length, xml_str);

    /* > 构建XML树 */
    memset(&opt, 0, sizeof(opt));

    opt.log = ctx->log;
    opt.pool = NULL;
    opt.alloc = mem_alloc;
    opt.dealloc = mem_dealloc;

    xml = xml_screat(xml_str, head->length, &opt);
    if (NULL == xml) {
        log_error(ctx->log, "Parse xml failed!");
        return -1;
    }

    do {
        /* > 提取搜索关键字 */
        node = xml_query(xml, ".SEARCH.WORDS");
        if (NULL == node) {
            log_error(ctx->log, "Get search words failed!");
            break;
        }

        snprintf(req->words, sizeof(req->words), "%s", node->value.str);

        log_trace(ctx->log, "words:%s", req->words);

        /* > 释放内存空间 */
        xml_destroy(xml);
        return 0;
    } while (0);

    xml_destroy(xml);
    return -1;
}
Example #4
0
char *libvirtGetDefaultEmulator(char *uri, char *type)
{
	char *caps = NULL;
	char *ret = NULL;
	char xp[1024] = { 0 };

	if (type == NULL)
		return NULL;

	if (cp == NULL) {
		cp = libvirtConnect(uri);
		if (cp == NULL) {
			DPRINTF("Connection to %s failed\n", uri);
			return NULL;
		}
	}

	if ((caps = virConnectGetCapabilities(cp)) == NULL)
		return NULL;

	snprintf(xp, sizeof(xp), "//capabilities/guest/arch/domain[@type='%s']/emulator", type);
	ret = xml_query(caps, xp);
	free(caps);

	return ret;
}
Example #5
0
/******************************************************************************
 **函数名称: invtd_search_word_parse
 **功    能: 解析搜索请求
 **输入参数:
 **     ctx: 全局对象
 **     buff: 搜索请求(报头+报体)
 **     len: 数据长度
 **输出参数:
 **     req: 搜索请求
 **返    回: 0:成功 !0:失败
 **实现描述: 
 **注意事项:
 **作    者: # Qifeng.zou # 2015.12.27 03:39:00 #
 ******************************************************************************/
static int invtd_search_word_parse(invtd_cntx_t *ctx,
        char *buf, size_t len, mesg_search_word_req_t *req)
{
    xml_opt_t opt;
    xml_tree_t *xml;
    xml_node_t *node;
    agent_header_t *head = (agent_header_t *)buf;
    const char *xml_str = (const char *)(head + 1);

    memset(&opt, 0, sizeof(opt));

    /* > 字节序转换 */
    head->type = ntohl(head->type);
    head->flag = ntohl(head->flag);
    head->length = ntohl(head->length);
    head->mark = ntohl(head->mark);
    head->serial = ntoh64(head->serial);

    req->serial = head->serial;

    log_trace(ctx->log, "serial:%lu type:%u flag:%u mark:0X%x len:%d body:%s",
            head->serial, head->type, head->flag, head->mark, head->length, xml_str);

    /* > 构建XML树 */
    opt.pool = NULL;
    opt.alloc = mem_alloc;
    opt.dealloc = mem_dealloc;

    xml = xml_screat(xml_str, head->length, &opt);
    if (NULL == xml) {
        log_error(ctx->log, "Parse xml failed!");
        return -1;
    }

    /* > 解析XML树 */
    node = xml_query(xml, ".SEARCH.WORDS");
    if (NULL == node) {
        log_error(ctx->log, "Get search words failed!");
    }
    else {
        snprintf(req->words, sizeof(req->words), "%s", node->value.str);
    }

    xml_destroy(xml);

    log_trace(ctx->log, "words:%s", req->words);

    return 0;
}
Example #6
0
/******************************************************************************
 **函数名称: lwsd_conf_load_lws
 **功    能: 加载LWS配置
 **输入参数: 
 **     path: 配置文件路径
 **     log: 日志对象
 **输出参数:
 **     lcf: 配置信息
 **返    回: 0:成功 !0:失败
 **实现描述: 提取配置文件中的数据
 **注意事项: 
 **作    者: # Qifeng.zou # 2015-06-25 22:43:12 #
 ******************************************************************************/
static int lwsd_conf_load_lws(xml_tree_t *xml, lwsd_conf_t *lcf, log_cycle_t *log)
{
    xml_node_t *node, *lws;
    lws_conf_t *conf = &lcf->lws;

    /* > 定位队列标签 */
    lws = xml_query(xml, ".LISTEND.LWS");
    if (NULL == lws) {
        log_error(log, "Query lws configuration failed!");
        return -1;
    }

    /* > 获取IFACE */
    node = xml_search(xml, lws, "IFACE");
    if (NULL == node
        || 0 == node->value.len)
    {
        snprintf(conf->iface, sizeof(conf->iface), ".");
    }
    else {
        snprintf(conf->iface, sizeof(conf->iface), "%s", node->value.str);
    }

    /* > 加载连接配置 */
    if (lwsd_conf_parse_lws_connections(xml, conf, log)) {
        log_error(log, "Parse connections of lws configuration failed!");
        return -1;
    }

    /* > 加载队列配置 */
    if (lwsd_conf_parse_lws_queue(xml, conf, log)) {
        log_error(log, "Parse queue of lws configuration failed!");
        return -1;
    }

    /* > 加载路径配置 */
    if (lwsd_conf_parse_lws_path(xml, conf, log)) {
        log_error(log, "Parse path of lws configuration failed!");
        return -1;
    }

    return 0;
}
Example #7
0
/******************************************************************************
 **函数名称: mon_conf_load
 **功    能: 加载配置信息
 **输入参数:
 **     path: 配置路径
 **输出参数: NONE
 **返    回: 0:成功 !0:失败
 **实现描述: 
 **注意事项: 
 **作    者: # Qifeng.zou # 2015.04.11 #
 ******************************************************************************/
static int mon_conf_load_menu(xml_tree_t *xml, mon_conf_t *conf)
{
    xml_node_t *node, *nail;

    nail = xml_query(xml, ".MONITOR.MENU");
    if (NULL == nail) {
        return -1;
    }

    node = xml_search(xml, nail, ".WIDTH");
    if (NULL == node) {
        conf->menu.width = MON_MENU_WIDTH;
    }
    else
    {
        conf->menu.width = atoi(node->value.str);
    }

    return 0;
}
Example #8
0
char *libvirtGetHostArchitecture(char *uri)
{
	char *caps = NULL;
	char *ret = NULL;

	if (cp == NULL) {
		cp = libvirtConnect(uri);
		if (cp == NULL) {
			DPRINTF("Connection to %s failed\n", uri);
			return NULL;
		}
	}

	if ((caps = virConnectGetCapabilities(cp)) == NULL)
		return NULL;

	ret = xml_query(caps, "//capabilities/host/cpu/arch");
	free(caps);
	return ret;
}
Example #9
0
/******************************************************************************
 **函数名称: lwsd_conf_parse_lws_queue
 **功    能: 解析LWS各队列配置
 **输入参数: 
 **     path: 配置文件路径
 **     log: 日志对象
 **输出参数:
 **     conf: 配置信息
 **返    回: 0:成功 !0:失败
 **实现描述: 提取配置文件中的数据
 **注意事项: 
 **作    者: # Qifeng.zou # 2015-06-25 22:43:12 #
 ******************************************************************************/
static int lwsd_conf_parse_lws_queue(xml_tree_t *xml, lws_conf_t *conf, log_cycle_t *log)
{
    xml_node_t *node, *fix;

    /* 加载队列信息 */
#define LWSD_LOAD_QUEUE(xml, fix,  _path, conf) {\
        char node_path[FILE_PATH_MAX_LEN]; \
        \
        snprintf(node_path, sizeof(node_path), "%s.MAX", _path); \
        \
        node = xml_search(xml, fix, node_path); \
        if (NULL == node) { \
            return -1; \
        } \
        \
        (conf)->max = str_to_num(node->value.str); \
        \
        snprintf(node_path, sizeof(node_path), "%s.SIZE", _path); \
        \
        node = xml_search(xml, fix, node_path); \
        if (NULL == node) { \
            return -1; \
        } \
        \
        (conf)->size = str_to_num(node->value.str); \
    }

    /* > 定位队列标签 */
    fix = xml_query(xml, ".LISTEND.LWS.QUEUE");
    if (NULL == fix) {
        log_error(log, "Get queue configuration failed!");
        return -1;
    }

    /* > 获取队列配置 */
    LWSD_LOAD_QUEUE(xml, fix, ".SENDQ", &conf->sendq);

    return 0;
}
Example #10
0
/******************************************************************************
 **函数名称: lwsd_conf_parse_lws_connections
 **功    能: 解析LWS并发配置
 **输入参数: 
 **     path: 配置文件路径
 **     log: 日志对象
 **输出参数:
 **     conf: 配置信息
 **返    回: 0:成功 !0:失败
 **实现描述: 提取配置文件中的数据
 **注意事项: 
 **作    者: # Qifeng.zou # 2015-06-25 22:43:12 #
 ******************************************************************************/
static int lwsd_conf_parse_lws_connections(xml_tree_t *xml, lws_conf_t *conf, log_cycle_t *log)
{
    xml_node_t *fix, *node;

    /* > 定位并发配置 */
    fix = xml_query(xml, ".LISTEND.LWS.CONNECTIONS");
    if (NULL == fix) {
        log_error(log, "Didn't configure connections!");
        return -1;
    }

    node = xml_search(xml, fix, "MAX");         /* > 获取最大并发数 */
    if (NULL == node) {
        log_error(log, "Get max number of connections failed!");
        return -1;
    }

    conf->connections.max = str_to_num(node->value.str);

    node = xml_search(xml, fix, "TIMEOUT");     /* > 获取连接超时时间 */
    if (NULL == node) {
        log_error(log, "Get timeout of connection failed!");
        return -1;
    }

    conf->connections.timeout = str_to_num(node->value.str);

    /* > 获取侦听端口 */
    node = xml_search(xml, fix, "PORT");
    if (NULL == node) {
        log_error(log, "Get port of connection failed!");
        return -1;
    }

    conf->connections.port = str_to_num(node->value.str);

    return 0;
}
Example #11
0
/******************************************************************************
 **函数名称: lwsd_conf_load_frwder
 **功    能: 加载转发配置
 **输入参数: 
 **     path: 配置文件路径
 **     log: 日志对象
 **输出参数:
 **     conf: 配置信息
 **返    回: 0:成功 !0:失败
 **实现描述: 提取配置文件中的数据
 **注意事项: 
 **作    者: # Qifeng.zou # 2015-06-25 22:43:12 #
 ******************************************************************************/
static int lwsd_conf_load_frwder(xml_tree_t *xml, lwsd_conf_t *lcf, log_cycle_t *log)
{
    xml_node_t *parent, *node;
    rtmq_proxy_conf_t *conf = &lcf->frwder;

    parent = xml_query(xml, ".LISTEND.FRWDER");
    if (NULL == parent) {
        log_error(log, "Didn't find invertd configuation!");
        return -1;
    }

    /* > 设置结点ID */
    conf->nid = lcf->nid;
    snprintf(conf->path, sizeof(conf->path), "%s", lcf->wdir);

    /* > 服务端IP */
    node = xml_search(xml, parent, "SERVER.IP");
    if (NULL == node
        || 0 == node->value.len)
    {
        log_error(log, "Didn't find SERVER.IP!");
        return -1;
    }

    snprintf(conf->ipaddr, sizeof(conf->ipaddr), "%s", node->value.str);

    node = xml_search(xml, parent, "SERVER.PORT");
    if (NULL == node
        || 0 == node->value.len)
    {
        log_error(log, "Didn't find SERVER.PORT!");
        return -1;
    }

    conf->port = str_to_num(node->value.str);

    /* > 鉴权信息 */
    node = xml_search(xml, parent, "AUTH.USR");
    if (NULL == node
        || 0 == node->value.len)
    {
        log_error(log, "Didn't find AUTH.USR!");
        return -1;
    }

    snprintf(conf->auth.usr, sizeof(conf->auth.usr), "%s", node->value.str);

    node = xml_search(xml, parent, "AUTH.PASSWD");
    if (NULL == node
        || 0 == node->value.len)
    {
        log_error(log, "Didn't find AUTH.PASSWD!");
        return -1;
    }

    snprintf(conf->auth.passwd, sizeof(conf->auth.passwd), "%s", node->value.str);

    /* > 线程数目 */
    node = xml_search(xml, parent, "THREAD-POOL.SEND_THD_NUM");  /* 发送线程数 */
    if (NULL == node
        || 0 == node->value.len)
    {
        log_error(log, "Didn't find THREAD-POOL.SEND_THD_NUM!");
        return -1;
    }

    conf->send_thd_num = str_to_num(node->value.str);
    if (0 == conf->send_thd_num) {
        log_error(log, "THREAD-POOL.SEND_THD_NUM is zero!");
        return -1;
    }

    node = xml_search(xml, parent, "THREAD-POOL.WORK_THD_NUM");  /* 工作线程数 */
    if (NULL == node
        || 0 == node->value.len)
    {
        log_error(log, "Didn't find THREAD-POOL.WORK_THD_NUM!");
        return -1;
    }

    conf->work_thd_num = str_to_num(node->value.str);
    if (0 == conf->work_thd_num) {
        log_error(log, "THREAD-POOL.WORK_THD_NUM is zero!");
        return -1;
    }

    /* > 缓存大小配置 */
    node = xml_search(xml, parent, "BUFFER-POOL-SIZE.RECV");  /* 接收缓存(MB) */
    if (NULL == node
        || 0 == node->value.len)
    {
        log_error(log, "Didn't find BUFFER-POOL-SIZE.RECV!");
        return -1;
    }

    conf->recv_buff_size = str_to_num(node->value.str) * MB;
    if (0 == conf->recv_buff_size) {
        return -1;
    }

    /* > 接收队列 */
    node = xml_search(xml, parent, "RECVQ.MAX");
    if (NULL == node
        || 0 == node->value.len)
    {
        log_error(log, "Didn't find RECVQ.MAX!");
        return -1;
    }

    conf->recvq.max = str_to_num(node->value.str);
    if (0 == conf->recvq.max) {
        log_error(log, "RECVQ.MAX is zero!");
        return -1;
    }

    node = xml_search(xml, parent, "RECVQ.SIZE");
    if (NULL == node
        || 0 == node->value.len)
    {
        log_error(log, "Didn't find RECVQ.SIZE!");
        return -1;
    }

    conf->recvq.size = str_to_num(node->value.str);
    if (0 == conf->recvq.size) {
        log_error(log, "RECVQ.SIZE is zero!");
        return -1;
    }

    /* > 发送队列 */
    node = xml_search(xml, parent, "SENDQ.MAX");
    if (NULL == node
        || 0 == node->value.len)
    {
        log_error(log, "Didn't find SENDQ.MAX!");
        return -1;
    }

    conf->sendq.max = str_to_num(node->value.str);
    if (0 == conf->sendq.max) {
        log_error(log, "SENDQ.MAX is zero!");
        return -1;
    }

    node = xml_search(xml, parent, "SENDQ.SIZE");
    if (NULL == node
        || 0 == node->value.len)
    {
        log_error(log, "Didn't find SENDQ.SIZE!");
        return -1;
    }

    conf->sendq.size = str_to_num(node->value.str);
    if (0 == conf->sendq.size) {
        log_error(log, "SENDQ.SIZE is zero!");
        return -1;
    }

    return 0;
}
Example #12
0
/******************************************************************************
 **函数名称: lwsd_conf_parse_lws_path
 **功    能: 加载路径配置
 **输入参数: 
 **     path: 配置文件路径
 **     log: 日志对象
 **输出参数:
 **     conf: 配置信息
 **返    回: 0:成功 !0:失败
 **实现描述: 提取配置文件中的数据
 **注意事项: 
 **作    者: # Qifeng.zou # 2015-06-25 22:43:12 #
 ******************************************************************************/
static int lwsd_conf_parse_lws_path(xml_tree_t *xml, lws_conf_t *conf, log_cycle_t *log)
{
    xml_node_t *node, *lws;

    /* > 定位队列标签 */
    lws = xml_query(xml, ".LISTEND.LWS");
    if (NULL == lws) {
        log_error(log, "Get queue configuration failed!");
        return -1;
    }

    /* > 获取RESOURCE-PATH */
    node = xml_search(xml, lws, "RESOURCE_PATH");
    if (NULL == node
        || 0 == node->value.len)
    {
        snprintf(conf->resource_path, sizeof(conf->resource_path), ".");
    }
    else {
        snprintf(conf->resource_path, sizeof(conf->resource_path), "%s", node->value.str);
    }

    /* > 获取SSL配置 */
    node = xml_search(xml, lws, "SSL.USE");
    if (NULL == node
        || 0 == node->value.len)
    {
        conf->is_use_ssl = false;
    }
    else {
        if (!strcasecmp(node->value.str, "on")) {
            conf->is_use_ssl = true;
        }
        else {
            conf->is_use_ssl = false;
        }
    }

    if (conf->is_use_ssl) {
        /* > 获取KEY-PATH */
        node = xml_search(xml, lws, "KEY_PATH");
        if (NULL == node
            || 0 == node->value.len)
        {
            snprintf(conf->key_path, sizeof(conf->key_path), "%s", conf->resource_path);
        }
        else {
            snprintf(conf->key_path, sizeof(conf->key_path), "%s/%s",
                    conf->resource_path, node->value.str);
        }

        /* > 获取CERT-PATH */
        node = xml_search(xml, lws, "CERT_PATH");
        if (NULL == node
            || 0 == node->value.len)
        {
            snprintf(conf->cert_path, sizeof(conf->cert_path), "%s", conf->resource_path);
        }
        else {
            snprintf(conf->cert_path, sizeof(conf->cert_path), "%s/%s",
                    conf->resource_path, node->value.str);
        }
    }

    return 0;
}
Example #13
0
/******************************************************************************
 **函数名称: mon_srch_recv_rsp
 **功    能: 接收搜索应答信息
 **输入参数:
 **     fd: 文件描述符
 **输出参数: NONE
 **返    回: 0:成功 !0:失败
 **实现描述: 
 **注意事项: 
 **作    者: # Qifeng.zou # 2015.06.05 17:01:04 #
 ******************************************************************************/
static int mon_srch_recv_rsp(mon_cntx_t *ctx, mon_srch_conn_t *conn)
{
    int idx;
    ssize_t n;
    char addr[8192];
    serial_t serial;
    xml_opt_t opt;
    xml_tree_t *xml;
    xml_node_t *node, *attr;
    struct timeval ctm;
    int sec, msec, usec;
    agent_header_t head;
    mesg_data_t *rsp;

    memset(addr, 0, sizeof(addr));

    /* > 接收应答数据 */
    n = read(conn->fd, (void *)&head, sizeof(head));
    gettimeofday(&ctm, NULL);
    if (n <= 0) {
        fprintf(stderr, "    errmsg:[%d] %s!\n", errno, strerror(errno));
        return -1;
    }
    else if (0 == conn->wrtm.tv_sec) {
        fprintf(stderr, "    Didn't send search request but received response!\n");
    }

    /* > 字节序转换 */
    head.type = ntohl(head.type);
    head.flag = ntohl(head.flag);
    head.length = ntohl(head.length);
    head.mark = ntohl(head.mark);
    head.serial = ntoh64(head.serial);

    n = read(conn->fd, addr, head.length);

    /* > 显示查询结果 */
    fprintf(stderr, "    ============================================\n");
    rsp = (mesg_data_t *)addr;

    rsp->serial = ntoh64(rsp->serial);

    serial.serial = head.serial;
    fprintf(stderr, "    >Serial: %lu [nid(%u) sid(%u) seq(%u)]\n",
            head.serial, serial.nid, serial.sid, serial.seq);
    fprintf(stderr, "    >Serial: %lu:%lu\n",
            rsp->serial, head.serial);

    memset(&opt, 0, sizeof(opt));

    opt.pool = NULL;
    opt.alloc = mem_alloc;
    opt.dealloc = mem_dealloc;

    xml = xml_screat(rsp->body, head.length, &opt);
    if (NULL == xml) { 
        fprintf(stderr, "    Format isn't right! body:%s\n", rsp->body);
        return -1;
    }
    
    node = xml_query(xml, ".SEARCH-RSP.ITEM");
    for (idx=1; NULL != node; node = xml_brother(node), ++idx) {
        attr = xml_search(xml, node, "URL");
        fprintf(stderr, "        [%02d] URL:%s", idx, attr->value.str);

        attr = xml_search(xml, node, "FREQ");
        fprintf(stderr, "    FREQ:%s\n", attr->value.str);
    }

    xml_destroy(xml);

    /* > 打印统计信息 */
    sec = ctm.tv_sec - conn->wrtm.tv_sec;
    msec = (ctm.tv_usec - conn->wrtm.tv_usec)/1000;
    if (msec < 0) {
        sec -= 1;
        msec += 1000;
    }
    usec = (ctm.tv_usec - conn->wrtm.tv_usec)%1000;
    if (usec < 0) {
        usec += 1000;
        msec -= 1;
        if (msec < 0) {
            sec -= 1;
            msec += 1000;
        }
    }
    if (msec < 0) {
        msec += 1000;
        sec -= 1;
    }

    fprintf(stderr, "    >Spend: %d(s).%03d(ms).%03d(us)\n", sec, msec, usec);
    fprintf(stderr, "    ============================================\n");

    return 0;
}
Example #14
0
/******************************************************************************
 **函数名称: frwd_conf_load_frwder
 **功    能: 加载转发配置
 **输入参数: 
 **     xml: XML树
 **     path: 结点路径
 **输出参数:
 **     conf: 发送配置
 **返    回: 0:成功 !0:失败
 **实现描述: 
 **注意事项: 
 **作    者: # Qifeng.zou # 2015.06.09 #
 ******************************************************************************/
static int frwd_conf_load_frwder(xml_tree_t *xml, const char *path, rtsd_conf_t *conf)
{
    xml_node_t *parent, *node;

    parent = xml_query(xml, path);
    if (NULL == parent) {
        fprintf(stderr, "Didn't find %s!\n", path);
        return -1;
    }

    /* > 结点ID */
    node = xml_search(xml, parent, "NODE");
    if (NULL == node
        || 0 == node->value.len)
    {
        fprintf(stderr, "Didn't find %s.NODE!\n", path);
        return -1;
    }

    conf->nodeid = atoi(node->value.str);

    /* > 工作路径 */
    node = xml_search(xml, parent, "PATH");
    if (NULL == node
        || 0 == node->value.len)
    {
        fprintf(stderr, "Didn't find %s.PATH!\n", path);
        return -1;
    }

    snprintf(conf->path, sizeof(conf->path), "%s", node->value.str);

    /* > 服务端IP */
    node = xml_search(xml, parent, "SERVER.IP");
    if (NULL == node
        || 0 == node->value.len)
    {
        fprintf(stderr, "Didn't find %s.SERVER.IP!\n", path);
        return -1;
    }

    snprintf(conf->ipaddr, sizeof(conf->ipaddr), "%s", node->value.str);

    node = xml_search(xml, parent, "SERVER.PORT");
    if (NULL == node
        || 0 == node->value.len)
    {
        fprintf(stderr, "Didn't find %s.SERVER.PORT!\n", path);
        return -1;
    }

    conf->port = atoi(node->value.str);

    /* > 鉴权信息 */
    node = xml_search(xml, parent, "AUTH.USR");
    if (NULL == node
        || 0 == node->value.len)
    {
        fprintf(stderr, "Didn't find %s.AUTH.USR!\n", path);
        return -1;
    }

    snprintf(conf->auth.usr, sizeof(conf->auth.usr), "%s", node->value.str);

    node = xml_search(xml, parent, "AUTH.PASSWD");
    if (NULL == node
        || 0 == node->value.len)
    {
        fprintf(stderr, "Didn't find %s.AUTH.PASSWD!\n", path);
        return -1;
    }

    snprintf(conf->auth.passwd, sizeof(conf->auth.passwd), "%s", node->value.str);

    /* > 线程数目 */
    node = xml_search(xml, parent, "THREAD-POOL.SEND_THD_NUM");  /* 发送线程数 */
    if (NULL == node
        || 0 == node->value.len)
    {
        fprintf(stderr, "Didn't find %s.THREAD-POOL.SEND_THD_NUM!\n", path);
        return -1;
    }

    conf->send_thd_num = atoi(node->value.str);
    if (0 == conf->send_thd_num) {
        fprintf(stderr, "%s.THREAD-POOL.SEND_THD_NUM is zero!\n", path);
        return -1;
    }

    node = xml_search(xml, parent, "THREAD-POOL.WORK_THD_NUM");  /* 工作线程数 */
    if (NULL == node
        || 0 == node->value.len)
    {
        fprintf(stderr, "Didn't find %s.THREAD-POOL.WORK_THD_NUM!\n", path);
        return -1;
    }

    conf->work_thd_num = atoi(node->value.str);
    if (0 == conf->work_thd_num) {
        fprintf(stderr, "%s.THREAD-POOL.WORK_THD_NUM is zero!\n", path);
        return -1;
    }

    /* > 缓存大小配置 */
    node = xml_search(xml, parent, "BUFFER-POOL-SIZE.RECV");  /* 接收缓存(MB) */
    if (NULL == node
        || 0 == node->value.len)
    {
        fprintf(stderr, "Didn't find %s.BUFFER-POOL-SIZE.RECV!\n", path);
        return -1;
    }

    conf->recv_buff_size = atoi(node->value.str) * MB;
    if (0 == conf->recv_buff_size) {
        return -1;
    }

    /* > 接收队列 */
    node = xml_search(xml, parent, "RECVQ.MAX");
    if (NULL == node
        || 0 == node->value.len)
    {
        fprintf(stderr, "Didn't find %s.RECVQ.MAX!\n", path);
        return -1;
    }

    conf->recvq.max = atoi(node->value.str);
    if (0 == conf->recvq.max) {
        fprintf(stderr, "%s.RECVQ.MAX is zero!\n", path);
        return -1;
    }

    node = xml_search(xml, parent, "RECVQ.SIZE");
    if (NULL == node
        || 0 == node->value.len)
    {
        fprintf(stderr, "Didn't find %s.RECVQ.SIZE!\n", path);
        return -1;
    }

    conf->recvq.size = atoi(node->value.str);
    if (0 == conf->recvq.size) {
        fprintf(stderr, "%s.RECVQ.SIZE is zero!\n", path);
        return -1;
    }

    /* > 发送队列 */
    node = xml_search(xml, parent, "SENDQ.MAX");
    if (NULL == node
        || 0 == node->value.len)
    {
        fprintf(stderr, "Didn't find %s.SENDQ.MAX!\n", path);
        return -1;
    }

    conf->sendq.max = atoi(node->value.str);
    if (0 == conf->sendq.max) {
        fprintf(stderr, "%s.SENDQ.MAX is zero!\n", path);
        return -1;
    }

    node = xml_search(xml, parent, "SENDQ.SIZE");
    if (NULL == node
        || 0 == node->value.len)
    {
        fprintf(stderr, "Didn't find %s.SENDQ.SIZE!\n", path);
        return -1;
    }

    conf->sendq.size = atoi(node->value.str);
    if (0 == conf->sendq.size) {
        fprintf(stderr, "%s.SENDQ.SIZE is zero!\n", path);
        return -1;
    }

    return 0;
}
Example #15
0
int startDomain(char *xml, char *uri)
{
	int id, tries, res = 0;
	char *port = NULL;
	char *xmldesc = NULL;
	virDomainPtr dp = NULL;

	if (cp == NULL) {
		cp = libvirtConnect(uri);
		if (cp == NULL) {
			DPRINTF("Connection to %s failed\n", uri);
			return -EIO;
		}
	}

	DPRINTF("Starting domain\n");
	dp = virDomainCreateXML(cp, xml, 0);
	if (dp == NULL) {
		DPRINTF("virDomainCreateXML call failed\n");
		DPRINTF("XML File data:\n%s\n", xml);
		return -EINVAL;
	}

	DPRINTF("Domain started\n");

	tries = 0;
	xmldesc = virDomainGetXMLDesc(dp, 0);
	if (xmldesc == NULL) {
		if (tries > 5) {
			DPRINTF("Cannot get domain XML description\n");
			virDomainFree(dp);
			return -EIO;
		}

		sleep(1);
		tries++;
	}

	port = xml_query(xmldesc, "//domain/devices/graphics/@port");
	free(xmldesc);

	if (port == NULL) {
		DPRINTF("Port lookup failed, node not accessible\n");
		virDomainFree(dp);
		return -ENOENT;
	}

	DPRINTF("Graphics port number: %s\n", port);

	id = virDomainGetID(dp);
	DPRINTF("Domain created with ID %d\n", id);
#ifdef USE_HACK
	if (startVNCViewer(NULL, NULL, 1) != VNC_STATUS_UNSUPPORTED) {
		char path[1024] = { 0 };
		char buf[2048] = { 0 };
		char cmd[4096] = { 0 };

		snprintf(path, sizeof(path), "/proc/%d/exe", getpid());
		readlink(path, buf, sizeof(buf));
		snprintf(cmd, sizeof(cmd), "%s -v localhost:%s -f -l console 2> /dev/null", buf, port);
		DPRINTF("About to run '%s'\n", cmd);
		res = WEXITSTATUS(system(cmd));
	}
	else
		res = VNC_STATUS_NO_CONNECTION;
#else
	res = startVNCViewer("localhost", port, 1);
#endif
	if (((virDomainIsActive(dp)) && (!domainIsOff))
		|| (res != VNC_STATUS_SHUTDOWN)) {
		DPRINTF("Domain is active, destroying...\n");
		virDomainDestroy(dp);
	}

	DPRINTF("Domain %d done.\n", id);
	virDomainFree(dp);

	DPRINTF("Returning with %d\n", lastErrorCode);
	return lastErrorCode;
}
Example #16
0
/******************************************************************************
 **函数名称: 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;
}