コード例 #1
0
ファイル: isgw_oper_base.cpp プロジェクト: cytu0911/isgw
int IsgwOperBase::is_auth(QModeMsg& req, char* ack, int& ack_len)
{
    if (1 == cmd_auth_flag_)
    {
        if (cmd_auth_map_[req.get_cmd()] != 1)
        {
            ACE_DEBUG((LM_ERROR, "[%D] IsgwOperBase auth failed"
                       ",cmd %d not allowed\n"
                       , req.get_cmd()
                      ));
            snprintf(ack, ack_len-1,"info=invalid cmd %d", req.get_cmd());
            return -1;
        }
    }
    if (1 == svc_auth_flag_)
    {
        int iSvc = atoi(((*(req.get_map()))[FIELD_NAME_SVC]).c_str());
        if (svc_auth_map_[iSvc] != 1)
        {
            ACE_DEBUG((LM_ERROR, "[%D] IsgwOperBase auth failed"
                       ",svc %d not allowed\n"
                       , iSvc
                      ));
            snprintf(ack, ack_len-1,"info=invalid service %d", iSvc);
            return -1;
        }
    }
    return 0;
}
コード例 #2
0
ファイル: isgw_oper_base.cpp プロジェクト: cytu0911/isgw
int IsgwOperBase::internal_process(QModeMsg& req, char* ack, int& ack_len)
{
    int ret =0;

    switch(req.get_cmd())
    {
    //框架测试指令1
    case CMD_TEST:
    {
        ACE_DEBUG((LM_INFO, "[%D] IsgwOperBase start to process CMD_TEST\n"));
        //调用业务处理逻辑类的相关接口处理请求
#ifdef ISGW_USE_IBC
        int max = 100;
        for(int i=0; i<max; i++)
        {
            char msg[100]="";
            snprintf(msg, sizeof(msg)
                     , "cmd=%d&uin=%u&total=%d&info=%d test|"
                     , req.get_cmd()
                     , req.get_uin()
                     , max
                     , i
                    );

            QModeMsg *new_req = new QModeMsg(msg, req.get_handle()
                                             , req.get_sock_seq(), req.get_msg_seq(), req.get_prot()
                                             , req.get_time(), req.get_sock_ip());

            if (IBCMgrSvc::instance()->putq(new_req) == -1)
            {
                //入队失败回收消息,避免内存泄漏
                delete new_req;
                new_req = NULL;
            }

        }
        //此处不返回消息
        ack_len = -1;
#else
        //memset(ack,'@',ack_len);
        snprintf(ack, ack_len-1, "%s", "info=in test process in test process in test process in test process in test process in test process");
        ack_len = atoi((*(req.get_map()))["ack_len"].c_str());
#endif
        //测试用 awayfang
        //sleep(100);
        ACE_DEBUG((LM_INFO, "[%D] IsgwOperBase process CMD_TEST succ\n"));
    }
    break;
    case CMD_SELF_TEST:
    {
        QMSG_MAP& req_map = *req.get_map();
        int testlevel = 0;
        if(req_map.count("testlevel"))
        {
            testlevel = atoi(req_map["testlevel"].c_str());
        }
        int overproctime = 0;
        std::string errmsg;

        struct timeval start, end;
        ::gettimeofday(&start, NULL);
        ret = self_test(testlevel, errmsg);
        ::gettimeofday(&end, NULL);
        unsigned diff = EASY_UTIL::get_span(&start, &end);

        int self_test_time_threshold = 500;
        SysConf::instance()->get_conf_int("system", "self_test_time_threshold", &self_test_time_threshold);
        overproctime = static_cast<int>(diff) - self_test_time_threshold;
        // ret值不为0, overproctime>0均引起告警
        snprintf(ack, MAX_INNER_MSG_LEN, "overproctime=%d&errmsg=%s", overproctime, errmsg.c_str());
        return ret;
    }
    break;
    case CMD_GET_SERVER_VERSION:
    {
        snprintf(ack, MAX_INNER_MSG_LEN, "ver=%s", SERVER_VERSION);
        return ret;
    }
    break;
    case CMD_SYS_LOAD_CONF:
        ISGWSighdl::instance()->handle_signal(SIGUSR1);
        break;
    case CMD_SYS_GET_CONTRL_STAT:
    {
        ACE_DEBUG((LM_INFO, "[%D] IsgwOperBase start to process CMD_SYS_GET_CONTRL_STAT\n"));
        int cmd_no = atoi((*(req.get_map()))["cmd_no"].c_str());
        ISGWMgrSvc::freq_obj_->get_statiscs(cmd_no, ack, ack_len);
    }
    break;
    case CMD_SYS_SET_CONTRL_STAT:
    {
        int cmd_no = atoi((*(req.get_map()))["cmd_no"].c_str());
        int status = atoi((*(req.get_map()))["status"].c_str());
        ISGWMgrSvc::freq_obj_->set_status(cmd_no, status);
        snprintf(ack, ack_len, "info=succ");
    }
    break;
    case CMD_SYS_SET_CONTRL_SWITCH:
    {
        //运行时设置流量控制功能的开关
        //0 关闭,1打开,2只查询开关状态
        int flag = atoi((*(req.get_map()))["switch"].c_str());
        if(0==flag)
        {
            ISGWMgrSvc::control_flag_ = 0;
        }
        else if(1==flag)
        {
            ISGWMgrSvc::control_flag_ = 1;
        }

        snprintf(ack, ack_len, "switch=%d&info=succ", ISGWMgrSvc::control_flag_);
    }
    break;
    }

    return 0;
}