コード例 #1
0
ファイル: FileTransfer.cpp プロジェクト: jineshkj/OOD
void FileTransfer::Run()
{
  std::cout << "File Transfer service started" << std::endl;

  while (true)
  {
    Command *cmd = DeQ();

    if (cmd == 0) // termination signal
      break;

    if (cmd->Name() == "PutFile")
    {
      PutFile * pf = dynamic_cast<PutFile*>(cmd);

      std::string newpath = _saveDir + "\\" + pf->_fname;
      (void) DeleteFile(newpath.c_str()); // delete target file just in case
      bool status = MoveFile(pf->_path.c_str(), newpath.c_str()) ? true : false;

      StatusMessage * resp = new StatusMessage(status);
      resp->SetConn(cmd->Msg().Conn());
      Dispatch(resp);

    } else
    {
      std::cout << "Command " << cmd->Name() << " is not known" << std::endl;
    }

    delete cmd;
  }

  std::cout << "File Transfer service stopped" << std::endl;
}
コード例 #2
0
JabberClient::PresenceRequest::~PresenceRequest()
{
    unsigned status = STATUS_UNKNOWN;
    if (m_type == "unavailable"){
        status = STATUS_OFFLINE;
    }else if (m_type.length() == 0){
        status = STATUS_ONLINE;
        if (m_show == "away"){
            status = STATUS_AWAY;
        }else if (m_show == "xa"){
            status = STATUS_NA;
        }else if (m_show == "dnd"){
            status = STATUS_DND;
        }
    }else{
        if (m_type == "subscribe"){
            m_client->auth_request(m_from.c_str(), MessageAuthRequest, m_status.c_str(), true);
        }else if (m_type == "subscribed"){
            m_client->auth_request(m_from.c_str(), MessageAuthGranted, m_status.c_str(), true);
        }else if (m_type == "unsubscribed"){
            m_client->auth_request(m_from.c_str(), MessageRemoved, m_status.c_str(), true);
        }else{
            log(L_DEBUG, "Unsupported presence type %s", m_type.c_str());
        }
    }
    if (status != STATUS_UNKNOWN){
        Contact *contact;
        JabberUserData *data = m_client->findContact(m_from.c_str(), NULL, NULL, false, contact);
        if (data){
            bool bOnLine = false;
            bool bChanged = set_str(&data->AutoReply, m_status.c_str());
            if (data->Status != status){
                time_t now;
                time(&now);
                bChanged = true;
                if ((status == STATUS_ONLINE) &&
                        ((now - m_client->data.owner.OnlineTime > 60) ||
                         (data->Status != STATUS_OFFLINE)))
                    bOnLine = true;
                if (data->Status == STATUS_OFFLINE)
                    data->OnlineTime = now;
                data->Status = status;
                data->StatusTime = now;
            }
            if (bChanged){
                StatusMessage m;
                m.setContact(contact->id());
                m.setClient(m_client->dataName(data).c_str());
                m.setFlags(MESSAGE_RECEIVED);
                m.setStatus(status);
                Event e(EventMessageReceived, &m);
                e.process();
            }
            if (bOnLine){
                Event e(EventContactOnline, contact);
                e.process();
            }
        }
    }
}
コード例 #3
0
void YahooClient::processStatus(unsigned short service, const char *id,
                                const char *_state, const char *_msg,
                                const char *_away, const char *_idle)
{
    Contact *contact;
    YahooUserData *data = findContact(id, NULL, contact);
    if (data == NULL)
        return;
    unsigned state = 0;
    unsigned away  = 0;
    unsigned idle  = 0;
    if (_state)
        state = atol(_state);
    if (_away)
        away  = atol(_away);
    if (_idle)
        idle  = atol(_idle);
    if (service == YAHOO_SERVICE_LOGOFF)
        state = YAHOO_STATUS_OFFLINE;
    if ((state != data->Status.value) ||
            ((state == YAHOO_STATUS_CUSTOM) &&
             (((away != 0) != data->bAway.bValue) || _cmp(_msg, data->AwayMessage.ptr)))) {

        unsigned long old_status = STATUS_UNKNOWN;
        unsigned style  = 0;
        const char *statusIcon = NULL;
        contactInfo(data, old_status, style, statusIcon);

        time_t now;
        time(&now);
        now -= idle;
        if (data->Status.value == YAHOO_STATUS_OFFLINE)
            data->OnlineTime.value = now;
        data->Status.value = state;
        data->bAway.bValue = (away != 0);
        data->StatusTime.value = now;

        unsigned long new_status = STATUS_UNKNOWN;
        contactInfo(data, old_status, style, statusIcon);

        if (old_status != new_status) {
            StatusMessage m;
            m.setContact(contact->id());
            m.setClient(dataName(data).c_str());
            m.setFlags(MESSAGE_RECEIVED);
            m.setStatus(STATUS_OFFLINE);
            Event e(EventMessageReceived, &m);
            e.process();
            if ((new_status == STATUS_ONLINE) && !contact->getIgnore()) {
                Event e(EventContactOnline, contact);
                e.process();
            }
        } else {
            Event e(EventContactStatus, contact);
            e.process();
        }
    }
}
コード例 #4
0
ファイル: stat_main.cpp プロジェクト: alimy/tfs
int family_process(const uint64_t ns_id, map<uint64_t, int32_t>& family_map)
{
  const int32_t num = 1000;
  ShowServerInformationMessage msg;
  SSMScanParameter& param = msg.get_param();
  param.type_ = SSM_TYPE_FAMILY;

  param.should_actual_count_ = (num << 16);
  param.end_flag_ = SSM_SCAN_CUTOVER_FLAG_YES;
  //其余,如param.start_next_position_ 等都初始化为0

  while (!((param.end_flag_ >> 4) & SSM_SCAN_END_FLAG_YES))
  {
    param.data_.clear();
    tbnet::Packet*ret_msg = NULL;
    NewClient* client = NewClientManager::get_instance().create_client();
    int ret = send_msg_to_server(ns_id, client, &msg, ret_msg, DEFAULT_NETWORK_CALL_TIMEOUT, true);
    if (TFS_SUCCESS != ret || ret_msg == NULL)
    {
      TBSYS_LOG(ERROR, "get block info error, ret: %d", ret);
      NewClientManager::get_instance().destroy_client(client);
      return EXIT_TFS_ERROR;
    }
    if(ret_msg->getPCode() != SHOW_SERVER_INFORMATION_MESSAGE)
    {
      if (ret_msg->getPCode() == STATUS_MESSAGE)
      {
        StatusMessage* msg = dynamic_cast<StatusMessage*>(ret_msg);
        TBSYS_LOG(ERROR, "get invalid message type: error: %s", msg->get_error());
      }
      TBSYS_LOG(ERROR, "get invalid message type, pcode: %d", ret_msg->getPCode());
      NewClientManager::get_instance().destroy_client(client);
      return EXIT_TFS_ERROR;
    }
    ShowServerInformationMessage* message = dynamic_cast<ShowServerInformationMessage*>(ret_msg);
    SSMScanParameter& ret_param = message->get_param();

    int32_t data_len = ret_param.data_.getDataLen();
    int32_t offset = 0;
    while (data_len > offset)
    {
      FamilyShow family;
      if (TFS_SUCCESS == family.deserialize(ret_param.data_, data_len, offset))
      {
        family_map.insert(make_pair(family.family_id_, family.family_aid_info_));
      }
    }
    param.start_next_position_ = (ret_param.start_next_position_ << 16) & 0xffff0000;
    param.end_flag_ = ret_param.end_flag_;
    if (param.end_flag_ & SSM_SCAN_CUTOVER_FLAG_NO)
    {
      param.addition_param1_ = ret_param.addition_param2_;//next start family_id to scan
    }
    NewClientManager::get_instance().destroy_client(client);
  }
  return TFS_SUCCESS;
}
コード例 #5
0
void MessageDAO::save(const StatusMessage &statusMsg)
{
    QSettings settings;
    settings.beginGroup(QSETTINGS_MESSAGE_GROUP);
    settings.setValue(STATUS_KEY, statusMsg.status());
    settings.setValue(MESSAGE_KEY, statusMsg.message());
    settings.setValue(CODE_KEY, statusMsg.code());
    settings.endGroup();
}
コード例 #6
0
ファイル: CliManager.cpp プロジェクト: mizobe/datad
CliManager::cli_parse_status CliManager::parse_command(std::string command){
	ActionMessage m;
	m.from_string(command);
	StatusMessage response = LocalCommands::parse_local_command(m);
        std::cout << response.to_string() << std::endl;
	if (response.get_status() == "ok"){
		return  PARSE_OK;
	}
	if (response.get_status() == "command"){
		if (response.get<std::string>("action") == "exit"){
				return PARSE_EXIT;
		}
	}
	return PARSE_ERROR;
}
コード例 #7
0
ファイル: AsyncRequestClient.cpp プロジェクト: mizobe/datad
StatusMessage AsyncRequestClient::send_message(ActionMessage message){
	urdl::istream is;
	is.set_option(urdl::http::request_method("POST"));
	is.set_option(urdl::http::request_content_type("application/x-www-form-urlencoded"));
	is.set_option(urdl::http::request_content(("c=" + message.to_string(max_length)).c_str()));
	is.open("http://" + this -> server + ":8080/command/remote");
	std::string command("");
	std::string output;
	while(is >> output)
		command += output;	
	StatusMessage response;
	response.from_string(command);
        response.put<std::string>("ip-address", this->server);
        return response;
}
コード例 #8
0
ファイル: block_console.cpp プロジェクト: 0huah0/tfs
int TranBlock::write_index()
{
  int ret = TFS_SUCCESS;
  WriteInfoBatchMessage req_wib_msg;
  req_wib_msg.set_block_id(seg_data_.seg_info_.block_id_);
  req_wib_msg.set_offset(0);
  req_wib_msg.set_length(dest_raw_meta_.size());
  req_wib_msg.set_raw_meta_list(&dest_raw_meta_);
  req_wib_msg.set_block_info(&dest_block_info_);
  req_wib_msg.set_cluster(COPY_BETWEEN_CLUSTER);

  NewClient* client = NewClientManager::get_instance().create_client();
  tbnet::Packet* rsp = NULL;
  if(TFS_SUCCESS != send_msg_to_server(dest_ds_id_, client, &req_wib_msg, rsp))
  {
    rsp = NULL;
  }

  if (NULL == rsp)
  {
    TBSYS_LOG(ERROR, "write index failed, blockid: %u, length: %zd, ret: %d",
        seg_data_.seg_info_.block_id_, dest_raw_meta_.size(), ret);
    ret = TFS_ERROR;
  }
  else
  {
    if (STATUS_MESSAGE == rsp->getPCode())
    {
      StatusMessage* sm = dynamic_cast<StatusMessage*>(rsp);
      if (STATUS_MESSAGE_OK != sm->get_status())
      {
        TBSYS_LOG(ERROR, "write raw index to ds: %s fail, blockid: %u, file count: %d, ret: %d",
            tbsys::CNetUtil::addrToString(dest_ds_id_).c_str(), seg_data_.seg_info_.block_id_, static_cast<int32_t>(dest_raw_meta_.size()), sm->get_status());
        ret = TFS_ERROR;
      }
    }
    else
    {
      TBSYS_LOG(ERROR, "write raw index to ds: %s fail, blockid: %u, file count: %d, unkonw msg type",
          tbsys::CNetUtil::addrToString(dest_ds_id_).c_str(), seg_data_.seg_info_.block_id_, static_cast<int32_t>(dest_raw_meta_.size()));
      ret = TFS_ERROR;
    }
  }
  NewClientManager::get_instance().destroy_client(client);

  return ret;
}
コード例 #9
0
ファイル: LocalCommands.cpp プロジェクト: mizobe/datad
StatusMessage LocalCommands::register_peer(ActionMessage& pt){
	ActionMessage m("register-peer");
	std::string ip_address = pt.get<std::string>("ip-address");
	AsyncRequestClient c(ip_address);
	SerializableList<FileInfo> file_list = ConnectionManager::list_files();
	m.push_back(std::make_pair("file-list", file_list.get_ptree()));
	StatusMessage response = c.send_message(m);
	if (response.get_status() == "ok"){
		if (ConnectionManager::registered_peers.find(response.get_peer_id()) == ConnectionManager::registered_peers.end()){
			ConnectionManager::register_peer(response.get_peer_id(), response.get<std::string>("ip-address"));
			boost::property_tree::ptree ptr = response.get_ptree();
			BOOST_FOREACH(const boost::property_tree::ptree::value_type& child, ptr.get_child("file-list")) {
				boost::shared_ptr<FileInfo> f(new FileInfo);
				f -> from_ptree(child.second.get_child(""));
				ConnectionManager::register_extern_file(f);
			}
		}
	}
コード例 #10
0
ファイル: StatusMessage.cpp プロジェクト: MindMil/XCSoar
void
StatusMessageList::LoadFile(TLineReader &reader)
{
  // Init first entry
  StatusMessage current;
  current.Clear();

  /* Read from the file */
  TCHAR *buffer;
  const TCHAR *key, *value;
  while ((buffer = reader.ReadLine()) != NULL) {
    // Check valid line? If not valid, assume next record (primative, but works ok!)
    if (*buffer == _T('#') || !parse_assignment(buffer, key, value)) {
      // Global counter (only if the last entry had some data)
      if (!current.IsEmpty()) {
        list.append(current);
        current.Clear();

        if (list.full())
          break;
      }
    } else {
      if (_tcscmp(key, _T("key")) == 0) {
        if (current.key == NULL)
          current.key = UnescapeBackslash(value);
      } else if (_tcscmp(key, _T("sound")) == 0) {
        if (current.sound == NULL)
          current.sound = UnescapeBackslash(value);
      } else if (_tcscmp(key, _T("delay")) == 0) {
        TCHAR *endptr;
        unsigned ms = ParseUnsigned(value, &endptr);
        if (endptr > value)
          current.delay_ms = ms;
      } else if (_tcscmp(key, _T("hide")) == 0) {
        if (_tcscmp(value, _T("yes")) == 0)
          current.visible = false;
      }
    }
  }

  if (!current.IsEmpty())
    list.append(current);
}
コード例 #11
0
ファイル: block_console.cpp プロジェクト: 0huah0/tfs
int TranBlock::rm_block_from_ns(uint64_t ds_id)
{
  int ret = TFS_SUCCESS;
  ClientCmdMessage req_cc_msg;
  req_cc_msg.set_cmd(CLIENT_CMD_EXPBLK);
  req_cc_msg.set_value1(ds_id);
  req_cc_msg.set_value3(seg_data_.seg_info_.block_id_);

  NewClient* client = NewClientManager::get_instance().create_client();
  tbnet::Packet* rsp = NULL;
  if((ret = send_msg_to_server(Func::get_host_ip(dest_ns_addr_.c_str()), client, &req_cc_msg, rsp)) != TFS_SUCCESS)
  {
    TBSYS_LOG(ERROR, "send remove block from ns command failed. block_id: %u, ret: %d", seg_data_.seg_info_.block_id_, ret);
    rsp = NULL;
  }
  else
  {
    if (rsp != NULL && STATUS_MESSAGE == rsp->getPCode())
    {
      StatusMessage* sm = dynamic_cast<StatusMessage*>(rsp);
      if (STATUS_MESSAGE_OK == sm->get_status())
      {
        TBSYS_LOG(INFO, "remove block from ns success, ds_addr: %s, blockid: %u",
            tbsys::CNetUtil::addrToString(ds_id).c_str(), seg_data_.seg_info_.block_id_);
      }
      else
      {
        TBSYS_LOG(ERROR, "remove block from ns fail, ds_addr: %s, blockid: %u, ret: %d",
            tbsys::CNetUtil::addrToString(ds_id).c_str(), seg_data_.seg_info_.block_id_, sm->get_status());
        ret = TFS_ERROR;
      }
    }
    else
    {
      TBSYS_LOG(ERROR, "remove block from ns: %s fail, blockid: %u, unkonw msg type",
          tbsys::CNetUtil::addrToString(ds_id).c_str(), seg_data_.seg_info_.block_id_);
      ret = TFS_ERROR;
    }
  }
  NewClientManager::get_instance().destroy_client(client);
  return ret;
}
コード例 #12
0
ファイル: TextSearch.cpp プロジェクト: jineshkj/OOD
void TextSearch::ProcessCompletedSearch(SearchString *ss)
{
  if (ss->_completed != ss->_jobs)  // ensure all jobs have been completed
    return;

  //std::cout << "Search Completed" << std::endl;

  StatusMessage * resp = new StatusMessage(true);
  resp->SetConn(ss->Msg().Conn());

  std::chrono::milliseconds ms = 
    std::chrono::duration_cast<std::chrono::milliseconds>(resp->CreateTime() - ss->CreateTime());

  resp->AddHeader("ExecutionTime", ms.count());
  while (ss->_matches.size())
  {
    std::string *match = ss->_matches.deQ();
    resp->WriteData(match->c_str(), match->size());
    resp->WriteData("\n", 1);
    delete match;
  }

  Dispatch(resp);

  delete ss;
}
コード例 #13
0
int rm_no_replicate_block_from_ns(const char* ns_addr, const uint64_t block_id)
{
  int ret = TFS_SUCCESS;
  ClientCmdMessage req_cc_msg;
  req_cc_msg.set_cmd(CLIENT_CMD_EXPBLK);
  req_cc_msg.set_value3(block_id);
  req_cc_msg.set_value4(tfs::nameserver::HANDLE_DELETE_BLOCK_FLAG_ONLY_RELATION);

  NewClient* client = NewClientManager::get_instance().create_client();
  tbnet::Packet* rsp = NULL;
  if((ret = send_msg_to_server(Func::get_host_ip(ns_addr), client, &req_cc_msg, rsp)) != TFS_SUCCESS)
  {
    TBSYS_LOG(ERROR, "send remove block from ns command failed. block_id: %" PRI64_PREFIX "u, ret: %d", block_id, ret);
  }
  else
  {
    assert(NULL != rsp);
    if (STATUS_MESSAGE == rsp->getPCode())
    {
      StatusMessage* sm = dynamic_cast<StatusMessage*>(rsp);
      if (STATUS_MESSAGE_OK == sm->get_status())
      {
        TBSYS_LOG(INFO, "remove block from ns success, ns_addr: %s, blockid: %" PRI64_PREFIX "u", ns_addr, block_id);
      }
      else
      {
        TBSYS_LOG(ERROR, "remove block from ns fail, ns_addr: %s, blockid: %" PRI64_PREFIX "u, ret: %d",
            ns_addr, block_id, sm->get_status());
        ret = sm->get_status();
      }
    }
    else
    {
      TBSYS_LOG(ERROR, "remove block from ns: %s fail, blockid: %" PRI64_PREFIX "u, unkonw msg type", ns_addr, block_id);
      ret = EXIT_UNKNOWN_MSGTYPE;
    }
  }
  NewClientManager::get_instance().destroy_client(client);
  return ret;
}
コード例 #14
0
ファイル: LocalCommands.cpp プロジェクト: mizobe/datad
StatusMessage LocalCommands::get_file_tcp(ActionMessage& pt){
	ActionMessage m("request-download");
	std::string file_name = pt.get<std::string>("file-name");
	boost::shared_ptr<FileInfo> file = ConnectionManager::get_extern_file_by_id(pt.get<std::string>("file-id"));
	if (file){
		boost::shared_ptr<DatadInfo> server = ConnectionManager::get_peer_by_id(file -> get_peer_id());
		if (server){
			m.put<std::string>("file-id", pt.get<std::string>("file-id"));
			boost::shared_ptr<AsyncRequestClient> c = ConnectionManager::get_request_client_by_id(server -> get_id());
			if (c){
				StatusMessage response = c -> send_message(m);
				std::string download_id = response.get<std::string>("download-id");
				if (response.get_status() == "ok"){
					ConnectionManager::tcp_file_client_session(server, file, file_name ,download_id);
					return(response);
				}
			}
		}
	}
	StatusMessage response("error");
	response.put<std::string>("message", "Error starting download");
	return(response);
}
コード例 #15
0
ファイル: aop_manager.cpp プロジェクト: alimy/tfs
    int OpManager::update_block_info(const BlockInfoV2& block_info, const common::UpdateBlockInfoType type)
    {
      int ret = TFS_SUCCESS;
      DsRuntimeGlobalInformation& ds_info = DsRuntimeGlobalInformation::instance();
      create_msg_ref(UpdateBlockInfoMessageV2, req_msg);
      req_msg.set_block_info(block_info);
      req_msg.set_type(type);
      req_msg.set_server_id(ds_info.information_.id_);

      NewClient* client = NewClientManager::get_instance().create_client();
      if (NULL == client)
      {
        ret = EXIT_CLIENT_MANAGER_CREATE_CLIENT_ERROR;
      }
      else
      {
        tbnet::Packet* ret_msg = NULL;
        ret = send_msg_to_server(ds_info.ns_vip_port_, client, &req_msg, ret_msg);
        if (TFS_SUCCESS == ret)
        {
          if (STATUS_MESSAGE == ret_msg->getPCode())
          {
            StatusMessage* smsg = dynamic_cast<StatusMessage*>(ret_msg);
            ret = smsg->get_status();
            TBSYS_LOG(DEBUG, "update block info. blockid: %"PRI64_PREFIX"u, status: %d %s",
                block_info.block_id_, smsg->get_status(), smsg->get_error());
          }
          else
          {
            ret = EXIT_COMMIT_BLOCK_UPDATE_ERROR;
          }
        }
        NewClientManager::get_instance().destroy_client(client);
      }

      return ret;
    }
コード例 #16
0
ファイル: show.cpp プロジェクト: 0huah0/tfs
    int ShowInfo::show_block(const int8_t type, const int32_t num, const uint32_t block_id, const int32_t block_chunk_num, int32_t count, const int32_t interval, const string& filename)
    {
      interrupt_ = false;
      is_loop_ = (count == 0);
      FILE* fp = NULL;
      if (TFS_ERROR == get_file_handle(filename, &fp))
      {
        return TFS_ERROR;
      }

      while ((count > 0 || is_loop_) && !interrupt_)
      {
        StatStruct stat;

        ShowServerInformationMessage msg;
        SSMScanParameter& param = msg.get_param();
        param.type_ = SSM_TYPE_BLOCK;
        param.child_type_ = SSM_CHILD_BLOCK_TYPE_INFO | SSM_CHILD_BLOCK_TYPE_SERVER;

        bool once = false;
        if (block_id > 0)
        {
          param.should_actual_count_ = 0x10000;
          param.end_flag_ = SSM_SCAN_CUTOVER_FLAG_NO;
          param.should_actual_count_ = 0x10000;
          param.start_next_position_ = ((block_id % block_chunk_num) << 16);
          param.addition_param1_ = block_id;
          once = true;
        }
        else
        {
          param.should_actual_count_ = (num << 16);
          param.end_flag_ = SSM_SCAN_CUTOVER_FLAG_YES;
        }

        while ((!((param.end_flag_ >> 4) & SSM_SCAN_END_FLAG_YES)) && !interrupt_)
        {
          param.data_.clear();
          block_set_.clear();
          tbnet::Packet*ret_msg = NULL;
          NewClient* client = NewClientManager::get_instance().create_client();
          int ret = send_msg_to_server(ns_ip_, client, &msg, ret_msg);
          if (TFS_SUCCESS != ret || ret_msg == NULL)
          {
            TBSYS_LOG(ERROR, "get block info error, ret: %d", ret);
            NewClientManager::get_instance().destroy_client(client);
            return TFS_ERROR;
          }
          //TBSYS_LOG(DEBUG, "pCode: %d", ret_msg->get_message_type());
          if(ret_msg->getPCode() != SHOW_SERVER_INFORMATION_MESSAGE)
          {
            if (ret_msg->getPCode() == STATUS_MESSAGE)
            {
              StatusMessage* msg = dynamic_cast<StatusMessage*>(ret_msg);
              TBSYS_LOG(ERROR, "get invalid message type: error: %s", msg->get_error());
            }
            TBSYS_LOG(ERROR, "get invalid message type, pcode: %d", ret_msg->getPCode());
            NewClientManager::get_instance().destroy_client(client);
            return TFS_ERROR;
          }
          ShowServerInformationMessage* message = dynamic_cast<ShowServerInformationMessage*>(ret_msg);
          SSMScanParameter& ret_param = message->get_param();

          int32_t data_len = ret_param.data_.getDataLen();
          int32_t offset = 0;
          if (data_len > 0)
          {
            print_header(BLOCK_TYPE, type, fp);
          }
          while ((data_len > offset) && !interrupt_)
          {
            BlockShow block;
            if (TFS_SUCCESS == block.deserialize(ret_param.data_, data_len, offset, param.child_type_))
            {
              //block.BlockBase::dump();
              if (once && (block.info_.block_id_ != block_id))
              {
                TBSYS_LOG(ERROR, "block(%u)(%u) not exists", block.info_.block_id_, block_id);
                break;
              }
              stat.add(block);
              block_set_.insert(block);
            }
          }
          std::set<BlockShow>::iterator iter = block_set_.begin();
          for (; iter != block_set_.end(); iter++)
          {
             (*iter).dump(type, fp);
          }
          param.start_next_position_ = (ret_param.start_next_position_ << 16) & 0xffff0000;
          param.end_flag_ = ret_param.end_flag_;
          if (param.end_flag_ & SSM_SCAN_CUTOVER_FLAG_NO)
          {
            param.addition_param1_ = ret_param.addition_param2_;
          }
          NewClientManager::get_instance().destroy_client(client);
          if (once)
          {
            break;
          }
        }
        if (!once)
        {
          stat.dump(BLOCK_TYPE, type, fp);
        }
        if (--count)
        {
          sleep(interval);
        }
      }
      if (fp != stdout) fclose(fp);
      return TFS_SUCCESS;
    }
コード例 #17
0
void JabberClient::setStatus(unsigned status, const char *ar)
{
    if (status  != m_status){
        time_t now;
        time(&now);
        data.owner.StatusTime = now;
        if (m_status == STATUS_OFFLINE)
            data.owner.OnlineTime = now;
        m_status = status;
        m_socket->writeBuffer.packetStart();
        const char *priority = "5";
        const char *show = NULL;
        const char *type = NULL;
        if (getInvisible()){
            type = "invisible";
        }else{
            switch (status){
            case STATUS_AWAY:
                show = "away";
                break;
            case STATUS_NA:
                show = "xa";
                break;
            case STATUS_DND:
                show = "dnd";
                break;
            case STATUS_FFC:
                show = "chat";
                break;
            case STATUS_OFFLINE:
                priority = NULL;
                type = "unavailable";
                break;
            }
        }
        m_socket->writeBuffer << "<presence";
        if (type)
            m_socket->writeBuffer << " type=\"" << type << "\"";
        m_socket->writeBuffer << ">\n";
        if (show && *show)
            m_socket->writeBuffer << "<show>" << show << "</show>\n";
        if (ar && *ar){
            m_socket->writeBuffer << "<status>" << ar << "</status>\n";
        }
        if (priority)
            m_socket->writeBuffer << "<priority>" << priority << "</priority>\n";
        m_socket->writeBuffer << "</presence>";
        sendPacket();
        Event e(EventClientChanged, static_cast<Client*>(this));
        e.process();
    }
    if (status == STATUS_OFFLINE){
        if (m_socket){
            m_socket->writeBuffer.packetStart();
            m_socket->writeBuffer
            << "</stream:stream>\n";
            sendPacket();
        }
        Contact *contact;
        ContactList::ContactIterator it;
        time_t now;
        time(&now);
        data.owner.StatusTime = now;
        while ((contact = ++it) != NULL){
            JabberUserData *data;
            ClientDataIterator it(contact->clientData, this);
            while ((data = (JabberUserData*)(++it)) != NULL){
                if (data->Status == STATUS_OFFLINE)
                    continue;
                data->StatusTime = now;
                setOffline(data);
                StatusMessage m;
                m.setContact(contact->id());
                m.setClient(dataName(data).c_str());
                m.setFlags(MESSAGE_RECEIVED);
                m.setStatus(STATUS_OFFLINE);
                Event e(EventMessageReceived, &m);
                e.process();
            }
        }
    }
}
コード例 #18
0
void ICQClient::snac_buddy(unsigned short type, unsigned short)
{
    string screen;
    Contact *contact;
    ICQUserData *data;
    switch (type){
    case ICQ_SNACxBDY_RIGHTSxGRANTED:
        log(L_DEBUG, "Buddy rights granted");
        break;
    case ICQ_SNACxBDY_USEROFFLINE:
        screen = m_socket->readBuffer.unpackScreen();
        data = findContact(screen.c_str(), NULL, false, contact);
        if (data && (data->Status.value != ICQ_STATUS_OFFLINE)){
            setOffline(data);
            StatusMessage m;
            m.setContact(contact->id());
            m.setClient(dataName(data).c_str());
            m.setStatus(STATUS_OFFLINE);
            m.setFlags(MESSAGE_RECEIVED);
            Event e(EventMessageReceived, &m);
            e.process();
        }
        break;
    case ICQ_SNACxBDY_USERONLINE:
        screen = m_socket->readBuffer.unpackScreen();
        data = findContact(screen.c_str(), NULL, false, contact);
        if (data){
            time_t now;
            time(&now);

            bool bChanged     = false;
            bool bAwayChanged = false;
            unsigned long prevStatus = data->Status.value;

            unsigned short level, len;
            m_socket->readBuffer >> level >> len;
            data->WarningLevel.value = level;

            TlvList tlv(m_socket->readBuffer);

            Tlv *tlvClass = tlv(0x0001);
            if (tlvClass){
                unsigned short userClass = *tlvClass;
                if (userClass != data->Class.value){
                    if ((userClass & CLASS_AWAY) != (data->Class.value & CLASS_AWAY)){
                        data->StatusTime.value = (unsigned long)now;
                        bAwayChanged = true;
                    }
                    data->Class.value = userClass;
                    bChanged = true;
                }
                if (data->Uin.value == 0){
                    if (userClass & CLASS_AWAY){
                        fetchAwayMessage(data);
                    }else{
                        set_str(&data->AutoReply.ptr, NULL);
                    }
                }
            }

            // Status TLV
            Tlv *tlvStatus = tlv(0x0006);
            if (tlvStatus){
                unsigned long status = *tlvStatus;
                if (status != data->Status.value){
                    data->Status.value = status;
                    if ((status & 0xFF) == 0)
                        set_str(&data->AutoReply.ptr, NULL);
                    data->StatusTime.value = (unsigned long)now;
                }
            }else if (data->Status.value == ICQ_STATUS_OFFLINE){
                data->Status.value = ICQ_STATUS_ONLINE;
                data->StatusTime.value = (unsigned long)now;
            }

            // Online time TLV
            Tlv *tlvOnlineTime = tlv(0x0003);
            if (tlvOnlineTime){
                unsigned long OnlineTime = *tlvOnlineTime;
                if (OnlineTime != data->OnlineTime.value){
                    data->OnlineTime.value = OnlineTime;
                    bChanged = true;
                }
            }
            Tlv *tlvNATime = tlv(0x0004);
            if (tlvNATime){
                unsigned short na_time = *tlvNATime;
                unsigned long StatusTime = (unsigned long)now - na_time * 60;
                if (StatusTime != data->StatusTime.value){
                    data->StatusTime.value = StatusTime;
                    bChanged = true;
                }
            }

            // IP TLV
            Tlv *tlvIP = tlv(0x000A);
            if (tlvIP)
                bChanged |= set_ip(&data->IP, htonl((unsigned long)(*tlvIP)));

            Tlv *tlvCapability = tlv(0x000D);
            if (tlvCapability){
                data->Caps.value = 0;
                Buffer info(*tlvCapability);
                for (; info.readPos() < info.size(); ){
                    capability cap;
                    info.unpack((char*)cap, sizeof(capability));
                    for (unsigned i = 0;; i++){
                        if (*capabilities[i] == 0) break;
                        unsigned size = sizeof(capability);
                        if (i == CAP_SIMOLD) size--;
                        if ((i == CAP_MICQ) || (i == CAP_LICQ) || (i == CAP_SIM)) size -= 4;
                        if (!memcmp(cap, capabilities[i], size)){
                            if (i == CAP_SIMOLD){
                                unsigned char build = cap[sizeof(capability)-1];
                                if (build && ((build == 0x92) || (build < (1 << 6)))) continue;
                                data->Build.value = build;
                            }
                            if ((i == CAP_MICQ) || (i == CAP_LICQ) || (i == CAP_SIM)){
                                unsigned char *p = (unsigned char*)cap;
                                p += 12;
                                data->Build.value = (p[0] << 24) + (p[1] << 16) + (p[2] << 8) + p[3];
                            }
                            data->Caps.value |= (1 << i);
                            break;
                        }
                    }
                }
            }

            unsigned long infoUpdateTime = 0;
            unsigned long pluginInfoTime = 0;
            unsigned long pluginStatusTime = 0;

            // Direct connection info
            Tlv *tlvDirect = tlv(0x000C);
            if (tlvDirect){
                Buffer info(*tlvDirect);
                unsigned long  realIP;
                unsigned short port;
                char mode, version, junk;
                info >> realIP;
                info.incReadPos(2);
                info >> port;
                if (realIP == 0x7F000001)
                    realIP = 0;
                bChanged |= set_ip(&data->RealIP, htonl(realIP));
                data->Port.value = port;
                unsigned long DCcookie;
                info >> mode >> junk >> version >> DCcookie;
                data->DCcookie.value = DCcookie;
                info.incReadPos(8);
                info
                >> infoUpdateTime
                >> pluginInfoTime
                >> pluginStatusTime;
                if (mode == MODE_DENIED) mode = MODE_INDIRECT;
                if ((mode != MODE_DIRECT) && (mode != MODE_INDIRECT))
                    mode = MODE_INDIRECT;
                data->Mode.value    = mode;
                data->Version.value = version;
            }

            Tlv *tlvPlugin = tlv(0x0011);
            if (tlvPlugin && data->Uin.value){
                Buffer info(*tlvPlugin);
                char type;
                unsigned long time;
                info >> type;
                info.unpack(time);
                plugin p;
                unsigned plugin_index;
                unsigned long plugin_status;
                switch (type){
                case 1:
                    addFullInfoRequest(data->Uin.value);
                    break;
                case 2:
                    info.incReadPos(6);
                    info.unpack((char*)p, sizeof(p));
                    data->PluginInfoTime.value = time;
                    for (plugin_index = 0; plugin_index < PLUGIN_NULL; plugin_index++)
                        if (!memcmp(p, plugins[plugin_index], sizeof(p)))
                            break;
                    switch (plugin_index){
                    case PLUGIN_PHONEBOOK:
                        log(L_DEBUG, "Updated phonebook");
                        addPluginInfoRequest(data->Uin.value, plugin_index);
                        break;
                    case PLUGIN_PICTURE:
                        log(L_DEBUG, "Updated picture");
                        addPluginInfoRequest(data->Uin.value, plugin_index);
                        break;
                    case PLUGIN_QUERYxINFO:
                        log(L_DEBUG, "Updated info plugin list");
                        addPluginInfoRequest(data->Uin.value, plugin_index);
                        break;
                    default:
                        if (plugin_index >= PLUGIN_NULL)
                            log(L_WARN, "Unknown plugin sign");
                    }
                    break;
                case 3:
                    info.incReadPos(6);
                    info.unpack((char*)p, sizeof(p));
                    info.incReadPos(1);
                    info.unpack(plugin_status);
                    data->PluginStatusTime.value = time;
                    for (plugin_index = 0; plugin_index < PLUGIN_NULL; plugin_index++)
                        if (!memcmp(p, plugins[plugin_index], sizeof(p)))
                            break;
                    switch (plugin_index){
                    case PLUGIN_FOLLOWME:
                        if (data->FollowMe.value == plugin_status)
                            break;
                        data->FollowMe.value = plugin_status;
                        bChanged = true;
                        break;
                    case PLUGIN_FILESERVER:
                        if ((data->SharedFiles.value != 0) == (plugin_status != 0))
                            break;
                        data->SharedFiles.value = (plugin_status != 0);
                        bChanged = true;
                        break;
                    case PLUGIN_ICQPHONE:
                        if (data->ICQPhone.value == plugin_status)
                            break;
                        data->ICQPhone.value = plugin_status;
                        bChanged = true;
                        break;
                    default:
                        if (plugin_index >= PLUGIN_NULL)
                            log(L_WARN, "Unknown plugin sign");
                    }
                    break;

                }
            }else{
                data->InfoUpdateTime.value   = infoUpdateTime;
                data->PluginInfoTime.value   = pluginInfoTime;
                data->PluginStatusTime.value = pluginStatusTime;
                if (getAutoUpdate()){
                    if (infoUpdateTime == 0)
                        infoUpdateTime = 1;
                    if (infoUpdateTime != data->InfoFetchTime.value)
                        addFullInfoRequest(data->Uin.value);
                    if ((data->PluginInfoTime.value != data->PluginInfoFetchTime.value)){
                        if (data->PluginInfoTime.value)
                            addPluginInfoRequest(data->Uin.value, PLUGIN_QUERYxINFO);
                    }
                    if ((data->PluginInfoTime.value != data->PluginInfoFetchTime.value) ||
                            (data->PluginStatusTime.value != data->PluginStatusFetchTime.value)){
                        if (data->SharedFiles.bValue){
                            data->SharedFiles.bValue = false;
                            bChanged = true;
                        }
                        if (data->FollowMe.value){
                            data->FollowMe.value = 0;
                            bChanged = true;
                        }
                        if (data->ICQPhone.bValue){
                            data->ICQPhone.bValue = false;
                            bChanged = true;
                        }
                        if (data->PluginStatusTime.value)
                            addPluginInfoRequest(data->Uin.value, PLUGIN_QUERYxSTATUS);
                    }
                }
            }
            if (data->bInvisible.bValue){
                data->bInvisible.bValue = false;
                bChanged = true;
            }
            if (bChanged){
                Event e(EventContactChanged, contact);
                e.process();
            }
            if ((data->Status.value != prevStatus) || bAwayChanged){
                unsigned status = STATUS_OFFLINE;
                if ((data->Status.value & 0xFFFF) != ICQ_STATUS_OFFLINE){
                    status = STATUS_ONLINE;
                    if (data->Status.value & ICQ_STATUS_DND){
                        status = STATUS_DND;
                    }else if (data->Status.value & ICQ_STATUS_OCCUPIED){
                        status = STATUS_OCCUPIED;
                    }else if (data->Status.value & ICQ_STATUS_NA){
                        status = STATUS_NA;
                    }else if (data->Status.value & ICQ_STATUS_AWAY){
                        status = STATUS_AWAY;
                    }else if (data->Status.value & ICQ_STATUS_FFC){
                        status = STATUS_FFC;
                    }
                }
                if ((status == STATUS_ONLINE) && (data->Class.value & CLASS_AWAY))
                    status = STATUS_AWAY;
                StatusMessage m;
                m.setContact(contact->id());
                m.setClient(dataName(data).c_str());
                m.setStatus(status);
                m.setFlags(MESSAGE_RECEIVED);
                Event e(EventMessageReceived, &m);
                e.process();
                if (!contact->getIgnore() &&
                        ((data->Class.value & CLASS_AWAY) == 0) &&
                        (((data->Status.value & 0xFF) == ICQ_STATUS_ONLINE) &&
                         (((prevStatus & 0xFF) != ICQ_STATUS_ONLINE)) || bAwayChanged) &&
                        (((prevStatus & 0xFFFF) != ICQ_STATUS_OFFLINE) ||
                         (data->OnlineTime.value > this->data.owner.OnlineTime.value))){
                    Event e(EventContactOnline, contact);
                    e.process();
                }
                if (getAutoReplyUpdate() && ((data->Status.value & 0xFF) != ICQ_STATUS_ONLINE)){
                    if ((getInvisible() && data->VisibleId.value) ||
                            (!getInvisible() && (data->InvisibleId.value == 0)))
                        addPluginInfoRequest(data->Uin.value, PLUGIN_AR);
                }
            }
        }
コード例 #19
0
ファイル: osd.cpp プロジェクト: BackupTheBerlios/sim-im-svn
void *OSDPlugin::processEvent(Event *e)
{
    OSDRequest osd;
    Contact *contact;
    Message *msg;
    OSDUserData *data;
    switch (e->type()){
    case EventContactOnline:
        contact = (Contact*)(e->param());
        if (contact->getIgnore()) break;
        osd.contact = contact->id();
        osd.type    = OSD_ALERTONLINE;
        queue.push_back(osd);
        processQueue();
        break;
    case EventMessageDeleted:
    case EventMessageRead:
    case EventMessageReceived:
        msg = (Message*)(e->param());
        contact = getContacts()->contact(msg->contact());
        if (contact == NULL)
            break;
        data = (OSDUserData*)(contact->getUserData(user_data_id));
        if (data == NULL)
            break;
        osd.contact = msg->contact();
        if (msg->type() == MessageStatus) {
            StatusMessage *smsg = (StatusMessage*)msg;
            switch (smsg->getStatus()) {
            case STATUS_AWAY:
                osd.type = OSD_ALERTAWAY;
                break;
            case STATUS_NA:
                osd.type = OSD_ALERTNA;
                break;
            case STATUS_DND:
                osd.type = OSD_ALERTDND;
                break;
            case 100:    /* STATUS_OCCUPIED, but defined in icqclient.h ! */
                osd.type = OSD_ALERTOCCUPIED;
                break;
            case STATUS_FFC:
                osd.type = OSD_ALERTFFC;
                break;
            case STATUS_OFFLINE:
                osd.type = OSD_ALERTOFFLINE;
                break;
            case STATUS_ONLINE:
                osd.type = OSD_NONE;
                return NULL;
            default:
                log(L_DEBUG,"OSD: Unknown status %ld",smsg->getStatus());
                osd.type = OSD_NONE;
                return NULL;
            }
            queue.push_back(osd);
            processQueue();
        }else{
            osd.type    = OSD_MESSAGE;
            if ((m_request.type == OSD_MESSAGE) && (m_request.contact == msg->contact())){
                queue.push_front(osd);
                m_timer->stop();
                m_timer->start(100);
            }else{
                queue.push_back(osd);
                processQueue();
            }
        }
        break;
    case EventContactStatus:
        contact = (Contact*)(e->param());
        if (contact->getIgnore()) break;
        data = (OSDUserData*)(contact->getUserData(user_data_id));
        if (data){
            unsigned style = 0;
            string wrkIcons;
            const char *statusIcon = NULL;
            contact->contactInfo(style, statusIcon, &wrkIcons);
            bool bTyping = false;
            while (!wrkIcons.empty()){
                if (getToken(wrkIcons, ',') == "typing"){
                    bTyping = true;
                    break;
                }
            }
            if (bTyping){
                list<unsigned>::iterator it;
                for (it = typing.begin(); it != typing.end(); ++it)
                    if ((*it) == contact->id())
                        break;
                if (it == typing.end()){
                    typing.push_back(contact->id());
                    osd.contact = contact->id();
                    osd.type    = OSD_TYPING;
                    queue.push_back(osd);
                    processQueue();
                }
            }else{
                list<unsigned>::iterator it;
                for (it = typing.begin(); it != typing.end(); ++it)
                    if ((*it) == contact->id())
                        break;
                if (it != typing.end())
                    typing.erase(it);
                if ((m_request.type == OSD_TYPING) && (m_request.contact == contact->id())){
                    m_timer->stop();
                    m_timer->start(100);
                }
            }
        }
        break;
    }
    return NULL;
}
コード例 #20
0
ファイル: sessionclient.cpp プロジェクト: vpilo/tari-exam
void SessionClient::availableMessages()
{
  Message* message;
  while( ( message = receiveMessage() ) != NULL )
  {
    server_->checkSessionStateChange( this, message->type() );

    switch( message->type() )
    {
      case Message::MSG_HELLO:
      {
        // Send the client its initial nickname
        sendMessage( new NicknameMessage( nickName_ ) );
        break;
      }

      case Message::MSG_NICKNAME:
      {
        NicknameMessage* nickNameMessage = dynamic_cast<NicknameMessage*>( message );
        if( ! server_->clientChangedNickName( this, nickNameMessage ) )
        {
          // The nickname could not be changed, report the problem to the client
          sendMessage( new StatusMessage( Errors::Status_NickNameAlreadyRegistered ) );
        }
        else
        {
          // Change the nickname
          setNickName( nickNameMessage->nickName() );
          sendMessage( new NicknameMessage( nickName_ ) );
        }

        break;
      }

      case Message::MSG_STATUS:
      {
        StatusMessage* statusMessage = dynamic_cast<StatusMessage*>( message );
        Common::debug( "The client reports status code %d", statusMessage->statusCode() );

        Errors::StatusCode code = statusMessage->statusCode();
        switch( code )
        {
          case Errors::Status_Ok:
            Common::debug( "Session \"%s\" sent status OK", nickName_ );
            break;

          case Errors::Status_AcceptFileTransfer:
          case Errors::Status_RejectFileTransfer:
            if( ! server_->isFileTransferModeActive() )
            {
              sendMessage( new StatusMessage( Errors::Status_FileTransferCanceled ) );
              break;
            }

            // Save the status
            fileTransferStatus_ = code;

            server_->clientSentFileTransferResponse( this, code == Errors::Status_AcceptFileTransfer );
            break;

          default:
            Common::debug( "Session \"%s\" sent status %d", nickName_, code );
            break;
        }
        break;
      }

      case Message::MSG_CHAT:
      {
        ChatMessage* chatMessage = dynamic_cast<ChatMessage*>( message );
        if( ! server_->clientSentChatMessage( this, chatMessage ) )
        {
          sendMessage( new StatusMessage( Errors::Status_ChattingAlone ) );
        }
        break;
      }

      case Message::MSG_FILE_REQUEST:
      {
        // Deny new file transfers if one is already active
        if( server_->isFileTransferModeActive() )
        {
          sendMessage( new StatusMessage( Errors::Status_FileTransferCanceled ) );
          break;
        }

        FileTransferMessage* fileMessage = dynamic_cast<FileTransferMessage*>( message );
        if( ! server_->clientSentFileTransferRequest( this, fileMessage ) )
        {
          sendMessage( new StatusMessage( Errors::Status_ChattingAlone ) );
          break;
        }

        fileTransferStatus_ = Errors::Status_AcceptFileTransfer;
        break;
      }

      case Message::MSG_FILE_DATA:
      {
        FileDataMessage* dataMessage = dynamic_cast<FileDataMessage*>( message );

        server_->clientSentFileData( this, dataMessage );

        // Reset the file transfer status for the next file
        if( dataMessage->isLastBlock() )
        {
          fileTransferStatus_ = Errors::Status_FileTransferCanceled;
        }
        break;
      }

      default:
        break;
    }

    delete message;
  }
}
コード例 #21
0
QString MsgViewBase::messageText(Message *msg, bool bUnread)
{
    QString options;
    QString info;
    QString status;

    const char *icon = "message";
    const CommandDef *def = CorePlugin::m_plugin->messageTypes.find(msg->type());
    if (def)
        icon = def->icon;
    bool bDirection = false;
    if (msg->type() == MessageStatus){
        icon = "empty";
        StatusMessage *sm = static_cast<StatusMessage*>(msg);
        Client *client = NULL;
        string clientStr;
        if (msg->client())
            clientStr = msg->client();
        int n = clientStr.find_last_of('.');
        if (n >= 0){
            clientStr = clientStr.substr(0, n);
        }else{
            clientStr = "";
        }
        if (!clientStr.empty()){
            for (unsigned i = 0; i < getContacts()->nClients(); i++){
                string n = getContacts()->getClient(i)->name();
                if (n.length() < clientStr.length())
                    continue;
                n = n.substr(0, clientStr.length());
                if (clientStr == n){
                    client = getContacts()->getClient(i);
                    break;
                }
            }
        }
        if ((client == NULL) && getContacts()->nClients())
            client = getContacts()->getClient(0);
        if (client){
            for (def = client->protocol()->statusList(); def->text; def++){
                if (def->id == sm->getStatus()){
                    icon = def->icon;
                    status = i18n(def->text);
                    break;
                }
            }
        }
        options += " direction=\"2\"";
        bDirection = true;
    }else{
        MessageDef *m_def = (MessageDef*)(def->param);
        if (m_def->flags & MESSAGE_INFO){
            options += " direction=\"2\"";
            bDirection = true;
        }
    }
    info = QString("<icon>%1</icon>") .arg(icon);

    QString contactName;
    if (msg->getFlags() & MESSAGE_RECEIVED){
        if (!bDirection)
            options += " direction=\"1\"";
        Contact *contact = getContacts()->contact(msg->contact());
        if (contact){
            contactName = contact->getName();
            if (contactName.isEmpty()){
                Client *client = NULL;
                ClientDataIterator it(contact->clientData);
                void *data;
                while ((data = ++it) != NULL){
                    if (it.client()->dataName(data) == msg->client()){
                        client = it.client();
                        break;
                    }
                }
            }
        }
        if (!bUnread){
            for (list<msg_id>::iterator it = CorePlugin::m_plugin->unread.begin(); it != CorePlugin::m_plugin->unread.end(); ++it){
                msg_id &m = (*it);
                if ((m.id == msg->id()) &&
                        (m.contact == msg->contact()) &&
                        (m.client == msg->client())){
                    bUnread = true;
                    break;
                }
            }
        }
        if (bUnread)
            options += " unread=\"1\"";
    }else{
        if (!bDirection)
            options += " direction=\"0\"";
        contactName = getContacts()->owner()->getName();
    }
    if (contactName.isEmpty())
        contactName = "???";
    info += QString("<from>%1</from>") .arg(quoteString(contactName));
    QString id = QString::number(msg->id());
    id += ",";
    // <hack>
    // Terrible hack to set message bgcolor. We prefer to insert the entire history
    // in one chunk (since it's more efficient and causes less redraws), and there's
    // no way to set block's background color directly in Qt's HTML), so we make a note
    // of it in the HTML and set it retroactively in setBackground.
    if ((msg->getBackground() != 0xFFFFFFFF) && (msg->getForeground() != msg->getBackground()))
        id += QString::number(msg->getBackground());
    // </hack>
    string client_str;
    if (msg->client())
        client_str = msg->client();
    if (!client_str.empty()){
        id += ",";
        id += quoteString(client_str.c_str());
    }
    if (m_cut.size()){
        id += ",";
        id += QString::number(m_cut.size());
    }
    info += "<id>";
    info += id;
    info += "</id>";


    QString icons;
    if (msg->getFlags() & MESSAGE_SECURE)
        options += " encrypted=\"1\"";
    if (msg->getFlags() & MESSAGE_URGENT)
        options += " urgent=\"1\"";
    if (msg->getFlags() & MESSAGE_LIST)
        options += " list=\"1\"";

    QString s;
    QDateTime t;
    t.setTime_t(msg->getTime());
    info += s.sprintf("<time><date>%%1</date><hour>%02u</hour><minute>%02u</minute><second>%02u</second></time>",
                      t.time().hour(), t.time().minute(), t.time().second()) .arg(formatDate(msg->getTime()));

    s = "<?xml version=\"1.0\"?><message";
    s += options;
    s += ">";
    s += info;

    QString msgText;
    if (msg->type() != MessageStatus){
        msgText = msg->presentation();
        if (msgText.isEmpty()){
            unsigned type = msg->baseType();
            CommandDef *cmd = CorePlugin::m_plugin->messageTypes.find(type);
            if (cmd){
                MessageDef *def = (MessageDef*)(cmd->param);
                msgText = i18n(def->singular, def->plural, 1);
                int n = msgText.find("1 ");
                if (n == 0){
                    msgText = msgText.mid(2);
                }else if (n > 0){
                    msgText = msgText.left(n);
                }
                msgText = QString("<p>") + msgText + "</p>";
            }
            QString text = msg->getRichText();
            msgText += text;
        }
    }else{
        msgText = status;
    }

    Event e(EventEncodeText, &msgText);
    e.process();
    ViewParser parser(CorePlugin::m_plugin->getOwnColors(), CorePlugin::m_plugin->getUseSmiles());
    msgText = parser.parse(msgText);
    s += "<body";

    if ((msg->getForeground() != 0xFFFFFFFF) && (msg->getForeground() != msg->getBackground()))
    {
        s += " fgcolor=\"#";
        s += QString::number(msg->getForeground(), 16).rightJustify(6, '0');
        s += "\"";
    }

    // Some bright day might come when one could specify background color from inside Qt's richtext.
    // Meanwhile, this is useless:
    if ((msg->getBackground() != 0xFFFFFFFF) && (msg->getForeground() != msg->getBackground()))
    {
        s += " bgcolor=\"#";
        s += QString::number(msg->getBackground(), 16).rightJustify(6, '0');
        s += "\"";
    }
    s += ">";

    // We pass the rich text quoted, since we're not sure of its' XML validity.
    // The XSL engine should copy it as-is (using xsl:value-of with disable-output-escaping="yes").
    s += quoteString(QString(MSG_BEGIN) + msgText);

    s += "</body>";
    s += "</message>";
    XSL *p = xsl;
    if (p == NULL)
        p = CorePlugin::m_plugin->historyXSL;
    QString res = p->process(s);
    QString anchor = MSG_ANCHOR;
    anchor += id;
    anchor += "\">";
    res = anchor + res;
    int startPos = res.find(MSG_BEGIN);
    int paraPos;
    if (parser.m_bParaStart){
        paraPos = res.find("<p");
        if (paraPos >= 0)
            res = res.left(paraPos) + "</p>" + res.mid(paraPos);
    }
    paraPos = res.findRev("<p", startPos);
    QString dir = " dir=\"";
    dir += parser.RTL ? "rtl" : "ltr";
    dir += "\"";
    if (paraPos >= 0){
        res = res.left(paraPos + 2) + dir + res.mid(paraPos + 2);
    }else{
        res = QString("<p") + dir + ">" + res;
    }
    return res;
}
コード例 #22
0
QString MsgViewBase::messageText(Message *msg)
{
    QString color;
    unsigned long c_sender   = 0x800000;
    unsigned long c_receiver = 0x000080;
    unsigned long c_send     = 0x000000;
    unsigned long c_receive  = 0x000000;
    if (CorePlugin::m_plugin->getOwnColors()) {
        c_send     = (CorePlugin::m_plugin->getColorSend())    & 0xFFFFFF;
        c_receive  = (CorePlugin::m_plugin->getColorReceive()) & 0xFFFFFF;
        c_sender   = (CorePlugin::m_plugin->getColorSender())  & 0xFFFFFF;
        c_receiver = (CorePlugin::m_plugin->getColorReceiver())& 0xFFFFFF;
    }
    color.sprintf(FONT_FORMAT,
                  ((msg->getFlags() & MESSAGE_RECEIVED) ? c_receiver : c_sender));
    const char *icon = "message";
    const CommandDef *def = CorePlugin::m_plugin->messageTypes.find(msg->type());
    if (def)
        icon = def->icon;
    QString contactName;
    Client *client = NULL;
    Contact *contact = getContacts()->contact(msg->contact());
    if (contact) {
        ClientDataIterator it(contact->clientData);
        void *data;
        while ((data = ++it) != NULL) {
            if (it.client()->dataName(data) == msg->client()) {
                client = it.client();
                break;
            }
        }
    }
    if (msg->type() == MessageStatus) {
        icon = "empty";
        StatusMessage *sm = static_cast<StatusMessage*>(msg);
        if (client == NULL)
            client = getContacts()->getClient(0);
        if (client) {
            for (def = client->protocol()->statusList(); def->text; def++) {
                if (def->id == sm->getStatus()) {
                    icon = def->icon;
                    break;
                }
            }
        }
    }
    bool bUnread = false;
    if (msg->getFlags() & MESSAGE_RECEIVED) {
        if (contact)
            contactName = contact->getName();
        for (list<msg_id>::iterator it = CorePlugin::m_plugin->unread.begin(); it != CorePlugin::m_plugin->unread.end(); ++it) {
            msg_id &m = (*it);
            if ((m.id == msg->id()) &&
                    (m.contact == msg->contact()) &&
                    (m.client == msg->client())) {
                bUnread = true;
                break;
            }
        }
    } else {
        if (client)
            contactName = client->ownerName();
        if (contactName.isEmpty())
            contactName = getContacts()->owner()->getName();
    }
    if (contactName.isEmpty())
        contactName = "???";
    QString id = QString::number(msg->id());
    id += ",";
    if (msg->getBackground() != msg->getForeground())
        id += QString::number(msg->getBackground() & 0xFFFFFF);
    string client_str;
    if (msg->client())
        client_str = msg->client();
    if (!client_str.empty()) {
        id += ",";
        id += quoteText(client_str.c_str());
    }
    QString icons;
    if (msg->getFlags() & MESSAGE_SECURE)
        icons += "<img src=\"icon:encrypted\">";
    if (msg->getFlags() & MESSAGE_URGENT)
        icons += "<img src=\"icon:urgentmsg\">";
    if (msg->getFlags() & MESSAGE_LIST)
        icons += "<img src=\"icon:listmsg\">";

    QString s = QString("<p><nobr>"
                        "<a href=\"msg://%1\"><img src=\"icon:%2\"></a>%3"
                        "&nbsp;%4<span style=\"color:#%5\">%6</span> &nbsp;"
                        "<span style=\"font-size:10pt\">%7</span>%8"
                        "</nobr></p>")
                .arg(id)
                .arg(icon)
                .arg(icons)
                .arg(bUnread ? "<b>" : "")
                .arg(color)
                .arg(quoteString(contactName))
                .arg(formatTime(msg->getTime()))
                .arg(bUnread ? "</b>" : "");
    if (msg->type() != MessageStatus) {
        QString msgText = msg->presentation();
        // replace font color if we use own colors
        // some of the incoming messages are saved as html with an extra <font> - tag
        // so we need to replace until no more <font> - tag is found
        // this behaviour should be checked!
        if (CorePlugin::m_plugin->getOwnColors()) {
            int pos = msgText.find("font color=\"#",0);
            while (pos != -1) {
                pos += 13;
                QString color;
                color.sprintf(FONT_FORMAT, (msg->getFlags() & MESSAGE_RECEIVED) ? c_receive : c_send);
                msgText.replace(pos,6,color);
                pos = msgText.find("font color=\"#",pos);
            }
        }
        if (msgText.isEmpty()) {
            unsigned type = msg->type();
            for (;;) {
                CommandDef *cmd = CorePlugin::m_plugin->messageTypes.find(type);
                if (cmd == NULL)
                    break;
                MessageDef *def = (MessageDef*)(cmd->param);
                if (def->base_type) {
                    type = def->base_type;
                    continue;
                }
                msgText += "<p>";
                msgText += i18n(def->singular, def->plural, 1);
                msgText += "</p>";
                break;
            }
            QString text = msg->getRichText();
            msgText += text;
        }
        Event e(EventEncodeText, &msgText);
        e.process();
        msgText = parseText(msgText, false, CorePlugin::m_plugin->getUseSmiles());
        s += msgText;
    }
    return s;
}
コード例 #23
0
ファイル: show.cpp プロジェクト: yinzhigang/tfs
    int ShowInfo::show_family(const int8_t type, const int32_t num, const int64_t family_id, int32_t count, const int32_t interval, const string& filename)
    {
      interrupt_ = false;
      is_loop_ = (count == 0);//count表示循环重复拉取的次数,默认是1,0表示一直按照间间隔循环
      FILE* fp = NULL;
      if (TFS_SUCCESS != get_file_handle(filename, &fp))
      {
        return EXIT_TFS_ERROR;
      }

      while ((count > 0 || is_loop_) && !interrupt_)
      {
        ShowServerInformationMessage msg;
        SSMScanParameter& param = msg.get_param();
        param.type_ = SSM_TYPE_FAMILY;

        uint64_t family_count = 0;
        bool once = false;
        if (family_id > 0)
        {
          param.should_actual_count_ = 0x10000;
          param.end_flag_ = SSM_SCAN_CUTOVER_FLAG_NO;
          param.start_next_position_ = ((family_id % nameserver::MAX_FAMILY_CHUNK_NUM) << 16);
          param.addition_param1_ = family_id;
          once = true;
        }
        else if (family_id == 0)
        {
          if (type & BLOCK_TYPE_SERVER_LIST)
          {
            fprintf(fp, "para error, -s must be used with -d\n");
            put_file_handle(fp);
            return EXIT_PARAMETER_ERROR;
          }
          param.should_actual_count_ = (num << 16);
          param.end_flag_ = SSM_SCAN_CUTOVER_FLAG_YES;
          //其余,如param.start_next_position_ 等都初始化为0
        }
        else
        {
          TBSYS_LOG(ERROR, "get invalid family_id: %"PRI64_PREFIX"d < 0", family_id);
          put_file_handle(fp);
          return EXIT_PARAMETER_ERROR;
        }

        while ((!((param.end_flag_ >> 4) & SSM_SCAN_END_FLAG_YES)) && !interrupt_)
        {
          param.data_.clear();
          tbnet::Packet*ret_msg = NULL;
          NewClient* client = NewClientManager::get_instance().create_client();
          int ret = send_msg_to_server(ns_ip_, client, &msg, ret_msg);
          if (TFS_SUCCESS != ret || ret_msg == NULL)
          {
            TBSYS_LOG(ERROR, "get block info error, ret: %d", ret);
            NewClientManager::get_instance().destroy_client(client);
            put_file_handle(fp);
            return EXIT_TFS_ERROR;
          }
          if(ret_msg->getPCode() != SHOW_SERVER_INFORMATION_MESSAGE)
          {
            if (ret_msg->getPCode() == STATUS_MESSAGE)
            {
              StatusMessage* msg = dynamic_cast<StatusMessage*>(ret_msg);
              TBSYS_LOG(ERROR, "get invalid message type: error: %s", msg->get_error());
            }
            TBSYS_LOG(ERROR, "get invalid message type, pcode: %d", ret_msg->getPCode());
            NewClientManager::get_instance().destroy_client(client);
            put_file_handle(fp);
            return EXIT_TFS_ERROR;
          }
          ShowServerInformationMessage* message = dynamic_cast<ShowServerInformationMessage*>(ret_msg);
          SSMScanParameter& ret_param = message->get_param();

          int32_t data_len = ret_param.data_.getDataLen();
          int32_t offset = 0;
          if (data_len > 0)
          {
            print_header(FAMILY_TYPE, type, fp);
          }
          while ((data_len > offset) && !interrupt_)
          {
            FamilyShow family;
            if (TFS_SUCCESS == family.deserialize(ret_param.data_, data_len, offset))
            {
              if (once && (family.family_id_ != family_id))
              {
                //TBSYS_LOG(ERROR, "only get family: %"PRI64_PREFIX"u, but %"PRI64_PREFIX"u not exists", family.family_id_, family_id);
                break;
              }
              if (once && (type & BLOCK_TYPE_SERVER_LIST))
              {
                ret = family.get_members_ds_list(ns_ip_);
                if (TFS_SUCCESS != ret)
                {
                  put_file_handle(fp);
                  return ret;
                }
              }
              family.dump(type, fp);
              ++family_count;
            }
          }
          param.start_next_position_ = (ret_param.start_next_position_ << 16) & 0xffff0000;
          param.end_flag_ = ret_param.end_flag_;
          if (param.end_flag_ & SSM_SCAN_CUTOVER_FLAG_NO)
          {
            param.addition_param1_ = ret_param.addition_param2_;//next start family_id to scan
          }
          NewClientManager::get_instance().destroy_client(client);
          if (once)
          {
            break;
          }
        }
        if (!once)
        {
          fprintf(fp, "Total Count: %"PRI64_PREFIX"u\n", family_count);
        }
        if (--count)
        {
          sleep(interval);
        }
      }
      put_file_handle(fp);
      return TFS_SUCCESS;
    }
コード例 #24
0
QString MsgViewBase::messageText(Message *msg, bool bUnread)
{
    QString options;
    QString info;
    QString status;

    const char *icon = "message";
    const CommandDef *def = CorePlugin::m_plugin->messageTypes.find(msg->type());
    if (def)
        icon = def->icon;
    bool bDirection = false;
    if (msg->type() == MessageStatus){
        icon = "empty";
        StatusMessage *sm = static_cast<StatusMessage*>(msg);
        Client *client = NULL;
        string clientStr;
        if (msg->client())
            clientStr = msg->client();
        int n = clientStr.find_last_of('.');
        if (n >= 0){
            clientStr = clientStr.substr(0, n);
        }else{
            clientStr = "";
        }
        if (!clientStr.empty()){
            for (unsigned i = 0; i < getContacts()->nClients(); i++){
                string n = getContacts()->getClient(i)->name();
                if (n.length() < clientStr.length())
                    continue;
                n = n.substr(0, clientStr.length());
                if (clientStr == n){
                    client = getContacts()->getClient(i);
                    break;
                }
            }
        }
        if ((client == NULL) && getContacts()->nClients())
            client = getContacts()->getClient(0);
        if (client){
            for (def = client->protocol()->statusList(); def->text; def++){
                if (def->id == sm->getStatus()){
                    icon = def->icon;
                    status = i18n(def->text);
                    break;
                }
            }
        }
        options += " direction=\"2\"";
        bDirection = true;
    }else{
        MessageDef *m_def = (MessageDef*)(def->param);
        if (m_def->flags & MESSAGE_INFO){
            options += " direction=\"2\"";
            bDirection = true;
        }
    }
    info = QString("<icon>%1</icon>") .arg(icon);

    QString contactName;
    if (msg->getFlags() & MESSAGE_RECEIVED){
        if (!bDirection)
            options += " direction=\"1\"";
        Contact *contact = getContacts()->contact(msg->contact());
        if (contact){
            contactName = contact->getName();
            if (contactName.isEmpty()){
                Client *client = NULL;
                ClientDataIterator it(contact->clientData);
                void *data;
                while ((data = ++it) != NULL){
                    if (it.client()->dataName(data) == msg->client()){
                        client = it.client();
                        break;
                    }
                }
            }
        }
        if (!bUnread){
            for (list<msg_id>::iterator it = CorePlugin::m_plugin->unread.begin(); it != CorePlugin::m_plugin->unread.end(); ++it){
                msg_id &m = (*it);
                if ((m.id == msg->id()) &&
                        (m.contact == msg->contact()) &&
                        (m.client == msg->client())){
                    bUnread = true;
                    break;
                }
            }
        }
        if (bUnread)
            options += " unread=\"1\"";
    }else{
        if (!bDirection)
            options += " direction=\"0\"";
        contactName = getContacts()->owner()->getName();
    }
    if (contactName.isEmpty())
        contactName = "???";
    info += QString("<from>%1</from>") .arg(quoteString(contactName));
    QString id = QString::number(msg->id());
    id += ",";
    if (msg->getBackground() != msg->getForeground())
        id += QString::number(msg->getBackground() & 0xFFFFFF);
    string client_str;
    if (msg->client())
        client_str = msg->client();
    if (!client_str.empty()){
        id += ",";
        id += quoteString(client_str.c_str());
    }
    info += "<id>";
    info += id;
    info += "</id>";

    QString icons;
    if (msg->getFlags() & MESSAGE_SECURE)
        options += " encrypted=\"1\"";
    if (msg->getFlags() & MESSAGE_URGENT)
        options += " urgent=\"1\"";
    if (msg->getFlags() & MESSAGE_LIST)
        options += " list=\"1\"";

    QString s;
    QDateTime t;
    t.setTime_t(msg->getTime());
    info += s.sprintf("<time><date>%%1</date><hour>%02u</hour><minute>%02u</minute><second>%02u</second></time>",
                      t.time().hour(), t.time().minute(), t.time().second()) .arg(formatDate(msg->getTime()));

    s = "<?xml version=\"1.0\"?><message";
    s += options;
    s += ">";
    s += info;

    QString msgText;
    if (msg->type() != MessageStatus){
        msgText = msg->presentation();
        if (msgText.isEmpty()){
            unsigned type = msg->baseType();
            CommandDef *cmd = CorePlugin::m_plugin->messageTypes.find(type);
            if (cmd){
                MessageDef *def = (MessageDef*)(cmd->param);
                msgText = i18n(def->singular, def->plural, 1);
                int n = msgText.find("1 ");
                if (n == 0){
                    msgText = msgText.mid(2);
                }else if (n > 0){
                    msgText = msgText.left(n);
                }
                msgText = QString("<p>") + msgText + "</p>";
            }
            QString text = msg->getRichText();
            msgText += text;
        }
    }else{
        msgText = status;
    }

    Event e(EventEncodeText, &msgText);
    e.process();
    msgText = parseText(msgText, CorePlugin::m_plugin->getOwnColors(), CorePlugin::m_plugin->getUseSmiles());
    msgText = QString(MSG_BEGIN) + msgText;
    s += "<body>";
    s += quoteString(msgText);
    s += "</body>";
    s += "</message>";
    XSL *p = xsl;
    if (p == NULL)
        p = CorePlugin::m_plugin->historyXSL;
    QString anchor = MSG_ANCHOR;
    anchor += id;
    anchor += "\">";
    QString res = p->process(s);
    if (res.left(3) == "<p>"){
        res = QString("<p>") + anchor + res.mid(3);
    }else{
        res = anchor + res;
    }
    return res;
}
コード例 #25
0
QString MsgViewBase::messageText(Message *msg)
{
    QString color;
    color.sprintf("%06lX",
                  ((msg->getFlags() & MESSAGE_RECEIVED) ?
                   CorePlugin::m_plugin->getColorReceiver() :
                   CorePlugin::m_plugin->getColorSender()) & 0xFFFFFF);
    const char *icon = "message";
    const CommandDef *def = CorePlugin::m_plugin->messageTypes.find(msg->type());
    if (def)
        icon = def->icon;
    QString contactName;
    Client *client = NULL;
    Contact *contact = getContacts()->contact(msg->contact());
    if (contact){
        ClientDataIterator it(contact->clientData);
        void *data;
        while ((data = ++it) != NULL){
            if (it.client()->dataName(data) == msg->client()){
                client = it.client();
                break;
            }
        }
    }
    if (msg->type() == MessageStatus){
        icon = "empty";
        StatusMessage *sm = static_cast<StatusMessage*>(msg);
        if (client == NULL)
            client = getContacts()->getClient(0);
        if (client){
            for (def = client->protocol()->statusList(); def->text; def++){
                if (def->id == sm->getStatus()){
                    icon = def->icon;
                    break;
                }
            }
        }
    }
    bool bUnread = false;
    if (msg->getFlags() & MESSAGE_RECEIVED){
        if (contact)
            contactName = contact->getName();
        for (list<msg_id>::iterator it = CorePlugin::m_plugin->unread.begin(); it != CorePlugin::m_plugin->unread.end(); ++it){
            msg_id &m = (*it);
            if ((m.id == msg->id()) &&
                    (m.contact == msg->contact()) &&
                    (m.client == msg->client())){
                bUnread = true;
                break;
            }
        }
    }else{
        if (client)
            contactName = client->ownerName();
        if (contactName.isEmpty())
            contactName = getContacts()->owner()->getName();
    }
    if (contactName.isEmpty())
        contactName = "???";
    QString id = QString::number(msg->id());
    id += ",";
    if (msg->getBackground() != msg->getForeground())
        id += QString::number(msg->getBackground() & 0xFFFFFF);
    string client_str;
    if (msg->client())
        client_str = msg->client();
    if (!client_str.empty()){
        id += ",";
        id += quoteText(client_str.c_str());
    }

    QString s = QString("<p><nobr>"
                        "<a href=\"msg://%1\"><img src=\"icon:%2\"></a>%3"
                        "&nbsp;%4<font color=\"#%5\">%6</font> &nbsp;"
                        "<font size=-1>%7</font>%8"
                        "</nobr></p>")
                .arg(id)
                .arg(icon)
				.arg((msg->getFlags() & MESSAGE_SECURE) ? "<img src=\"icon:encrypted\">" : "")
                .arg(bUnread ? "<b>" : "")
                .arg(color)
                .arg(quoteString(contactName))
                .arg(formatTime(msg->getTime()))
                .arg(bUnread ? "</b>" : "");
    if (msg->type() != MessageStatus){
        QString msgText = msg->presentation();
        if (msgText.isEmpty()){
            unsigned type = msg->type();
            for (;;){
                CommandDef *cmd = CorePlugin::m_plugin->messageTypes.find(type);
                if (cmd == NULL)
                    break;
                MessageDef *def = (MessageDef*)(cmd->param);
                if (def->base_type){
                    type = def->base_type;
                    continue;
                }
                msgText += "<p>";
                msgText += i18n(def->singular, def->plural, 1);
                msgText += "</p>";
                break;
            }
            QString text = msg->getRichText();
            if (!text.isEmpty()){
                msgText += "<p>";
                msgText += text;
                msgText += "</p>";
            }
        }
        string msg_text;
        msg_text = msgText.utf8();
        Event e(EventEncodeText, &msg_text);
        e.process();
        s += parseText(msg_text.c_str(), CorePlugin::m_plugin->getOwnColors(), CorePlugin::m_plugin->getUseSmiles());
    }
    return s;
}
コード例 #26
0
JabberClient::PresenceRequest::~PresenceRequest()
{
    unsigned status = STATUS_UNKNOWN;
    /*
        m_type - flags after draft-ietf-xmpp-core-16 / 8.4.1
    */
    if (m_type == "unavailable") {
        status = STATUS_OFFLINE;
    } else if (m_type == "subscribe") {
        m_client->auth_request(m_from.c_str(), MessageAuthRequest, m_status.c_str(), true);
    } else if (m_type == "subscribed") {
        m_client->auth_request(m_from.c_str(), MessageAuthGranted, m_status.c_str(), true);
    } else if (m_type == "unsubscribe") {
        m_client->auth_request(m_from.c_str(), MessageRemoved, m_status.c_str(), true);
    } else if (m_type == "unsubscribed") {
        m_client->auth_request(m_from.c_str(), MessageAuthRefused, m_status.c_str(), true);
    } else if (m_type == "probe") {
        // server want to to know if we're living
        m_client->ping();
    } else if (m_type == "error") {
        log(L_DEBUG, "An error has occurred regarding processing or delivery of a previously-sent presence stanza");
    } else if (m_type.length() == 0) {
        // m_show - flags after draft-ietf-xmpp-im-15 / 4.2
        status = STATUS_ONLINE;
        if (m_show == "away") {
            status = STATUS_AWAY;
        } else if (m_show == "chat") {
            status = STATUS_FFC;
        } else if (m_show == "xa") {
            status = STATUS_NA;
        } else if (m_show == "dnd") {
            status = STATUS_DND;
        } else if (m_show == "online") {
            status = STATUS_ONLINE;
        } else if (m_show.empty()) {
            status = STATUS_ONLINE;
            if (m_status == "Online") {
                status = STATUS_ONLINE;
            } else if (m_status == "Disconnected") {
                status = STATUS_OFFLINE;
            } else if (m_status == "Connected") {
                status = STATUS_ONLINE;
            } else if (!m_status.empty()) {
                log(L_DEBUG, "Unsupported status %s", m_status.c_str());
            }
        } else {
            log(L_DEBUG, "Unsupported available status %s", m_show.c_str());
        }
    } else {
        log(L_DEBUG, "Unsupported presence type %s", m_type.c_str());
    }
    if (status != STATUS_UNKNOWN) {
        Contact *contact;
        JabberUserData *data = m_client->findContact(m_from.c_str(), NULL, false, contact);
        if (data) {
            bool bOnLine = false;
            bool bChanged = set_str(&data->AutoReply, m_status.c_str());
            if (data->Status != status) {
                time_t now;
                time(&now);
                bChanged = true;
                if ((status == STATUS_ONLINE) &&
                        ((now - m_client->data.owner.OnlineTime > 60) ||
                         (data->Status != STATUS_OFFLINE)))
                    bOnLine = true;
                if (data->Status == STATUS_OFFLINE)
                    data->OnlineTime = now;
                data->Status = status;
                data->StatusTime = now;
            }
            if (bChanged) {
                StatusMessage m;
                m.setContact(contact->id());
                m.setClient(m_client->dataName(data).c_str());
                m.setFlags(MESSAGE_RECEIVED);
                m.setStatus(status);
                Event e(EventMessageReceived, &m);
                e.process();
            }
            if (bOnLine && !contact->getIgnore() && !m_client->isAgent(data->ID)) {
                Event e(EventContactOnline, contact);
                e.process();
            }
        }
    }
}
コード例 #27
0
ファイル: block_console.cpp プロジェクト: 0huah0/tfs
int TranBlock::write_data()
{
  int block_len = dest_content_buf_.getDataLen();
  int cur_write_offset = 0;
  int cur_len = 0;
  int ret = TFS_SUCCESS;

  while (block_len > 0)
  {
    int64_t remainder_retrys = RETRY_TIMES;
    while (remainder_retrys > 0)
    {
      cur_len = std::min(static_cast<int64_t>(block_len), TRAN_BUFFER_SIZE);

      WriteRawDataMessage req_wrd_msg;
      req_wrd_msg.set_block_id(seg_data_.seg_info_.block_id_);
      req_wrd_msg.set_offset(cur_write_offset);
      req_wrd_msg.set_length(cur_len);
      req_wrd_msg.set_data(dest_content_buf_.getData());

      //new block
      if (0 == cur_write_offset)
      {
        req_wrd_msg.set_new_block(1);
      }

      NewClient* client = NewClientManager::get_instance().create_client();
      tbnet::Packet* rsp = NULL;
      if(TFS_SUCCESS != send_msg_to_server(dest_ds_id_, client, &req_wrd_msg, rsp))
      {
        rsp = NULL;
      }
      if (NULL == rsp)
      {
        TBSYS_LOG(ERROR, "write data failed, blockid: %u, dest_ds: %s, cur_write_offset: %d, cur_len: %d, ret: %d",
            seg_data_.seg_info_.block_id_, tbsys::CNetUtil::addrToString(dest_ds_id_).c_str(), cur_write_offset, cur_len, ret);
        ret = TFS_ERROR;
      }
      else
      {
        if (STATUS_MESSAGE == rsp->getPCode())
        {
          StatusMessage* sm = dynamic_cast<StatusMessage*>(rsp);
          if (STATUS_MESSAGE_OK != sm->get_status())
          {
            TBSYS_LOG(ERROR, "write raw data to ds: %s fail, blockid: %u, offset: %d, ret: %d",
                tbsys::CNetUtil::addrToString(dest_ds_id_).c_str(), seg_data_.seg_info_.block_id_, cur_write_offset, sm->get_status());
            ret = TFS_ERROR;
          }
        }
        else
        {
          TBSYS_LOG(ERROR, "write raw data to ds: %s fail, blockid: %u, offset: %d, unkonw msg type",
              tbsys::CNetUtil::addrToString(dest_ds_id_).c_str(), seg_data_.seg_info_.block_id_, cur_write_offset);
          ret = TFS_ERROR;
        }

        dest_content_buf_.drainData(cur_len);
        block_len = dest_content_buf_.getDataLen();
        cur_write_offset += cur_len;
        NewClientManager::get_instance().destroy_client(client);

        if (NULL == rsp)
        {
          --remainder_retrys;
          continue;
        }
        else
        {
          if (cur_len != TRAN_BUFFER_SIZE)
          {
            // quit
            block_len = 0;
          }
          TBSYS_LOG(INFO, "write raw data to ds: %s successful, blockid: %u",
              tbsys::CNetUtil::addrToString(dest_ds_id_).c_str(), seg_data_.seg_info_.block_id_);
          break;
        }
      }
    }

    if (TFS_SUCCESS != ret)
    {
      break;
    }
  }

  return ret;
}
コード例 #28
0
ファイル: compare_crc.cpp プロジェクト: 0huah0/tfs
int get_crc_from_block_list(const string& old_tfs_client, const string& new_tfs_client,
    const string& modify_time, int64_t index, int64_t len)
{
  int ret = TFS_ERROR;
  uint32_t block_id = 0;
  int64_t i = 0;

  for (i = 0; i < len; i++)
  {
    block_id = atol(g_input_lines[index+i].c_str());
    VUINT64 ds_list;
    ToolUtil::get_block_ds_list(Func::get_host_ip(old_tfs_client.c_str()), block_id, ds_list);
    if(ds_list.size() > 0)
    {
      uint64_t ds_id = ds_list[0];

      FILE_INFO_LIST file_list;
      GetServerStatusMessage gss_message;
      gss_message.set_status_type(GSS_BLOCK_FILE_INFO);
      gss_message.set_return_row(block_id);

      NewClient* client = NewClientManager::get_instance().create_client();
      tbnet::Packet* ret_message = NULL;
      if (NULL != client)
      {
        if ((ret = send_msg_to_server(ds_id, client, &gss_message, ret_message)) == TFS_SUCCESS)
        {
          if (ret_message->getPCode() == BLOCK_FILE_INFO_MESSAGE)
          {
            BlockFileInfoMessage *bfi_message = (BlockFileInfoMessage*)ret_message;
            FILE_INFO_LIST* file_info_list = bfi_message->get_fileinfo_list();
            FILE_INFO_LIST::iterator vit = file_info_list->begin();
            for ( ; vit != file_info_list->end(); ++vit)
            {
              file_list.push_back(*vit);
            }
          }
          else if (ret_message->getPCode() == STATUS_MESSAGE)
          {
            StatusMessage* sm = reinterpret_cast<StatusMessage*> (ret_message);
            if (sm->get_error() != NULL)
            {
              TBSYS_LOG(ERROR, "%s", sm->get_error());
              ret = TFS_ERROR;
            }
          }
        }
        else
        {
          TBSYS_LOG(ERROR, "send message to server failed. ds_addr: %s, pcode: %d, ret: %d",
              tbsys::CNetUtil::addrToString(ds_id).c_str(), gss_message.getPCode(), ret);
        }
        NewClientManager::get_instance().destroy_client(client);
      }
      else
      {
        TBSYS_LOG(ERROR,"create client error");
      }

      if (ret == TFS_SUCCESS)
      {
        FILE_INFO_LIST::iterator vit = file_list.begin();
        int i = 0;
        for ( ; vit != file_list.end(); ++vit)
        {
          ++i;
          FSName fsname(block_id, vit->id_, g_tfs_client->get_cluster_id(old_tfs_client.c_str()));
          TBSYS_LOG(DEBUG, "gene file i: %d, blockid: %u, fileid: %"PRI64_PREFIX"u, %s",
              i, block_id, (vit)->id_, fsname.get_name());
          get_crc_from_filename(old_tfs_client, new_tfs_client, fsname.get_name(), modify_time);
        }

        file_list.clear();
      }
    }
    else
    {
      TBSYS_LOG(ERROR,"get block info for blockid: %u failure.",block_id);
    }
 }
 return ret;
}
コード例 #29
0
ファイル: show.cpp プロジェクト: yinzhigang/tfs
    int ShowInfo::show_block_common(const int32_t num, const uint64_t block_id, int32_t count,
        const int32_t interval, const string& filename, BaseBlockWorker* worker)
    {
      FILE* fp = NULL;
      if (TFS_SUCCESS != get_file_handle(filename, &fp))
      {
        return EXIT_TFS_ERROR;
      }
      interrupt_ = false;
      is_loop_ = (count == 0);

      while ((count > 0 || is_loop_) && !interrupt_)
      {
        if(TFS_SUCCESS != worker->begin())
        {
          put_file_handle(fp);
          return EXIT_TFS_ERROR;
        }
        ShowServerInformationMessage msg;
        SSMScanParameter& param = msg.get_param();
        param.type_ = SSM_TYPE_BLOCK;//遍历ns上的block数据的类型
        param.child_type_ = SSM_CHILD_BLOCK_TYPE_INFO | SSM_CHILD_BLOCK_TYPE_SERVER;//TYPE_INFO只为取block_id, TYPE_SERVER为ds_list

        bool once = false;
        if (block_id > 0)
        {
          param.should_actual_count_ = 0x10000;
          param.end_flag_ = SSM_SCAN_CUTOVER_FLAG_NO;
          param.start_next_position_ = ((block_id % nameserver::MAX_BLOCK_CHUNK_NUMS) << 16);//start是本次在ns上开始扫描blocks的桶的位置
          param.addition_param1_ = block_id;
          once = true;
        }
        else
        {
          param.should_actual_count_ = (num << 16);
          param.end_flag_ = SSM_SCAN_CUTOVER_FLAG_YES;
        }

        print_header(worker->block_type_, worker->sub_type_, fp);
        while ((!((param.end_flag_ >> 4) & SSM_SCAN_END_FLAG_YES)) && !interrupt_)
        {
          param.data_.clear();
          tbnet::Packet*ret_msg = NULL;
          NewClient* client = NewClientManager::get_instance().create_client();
          int ret = send_msg_to_server(ns_ip_, client, &msg, ret_msg);
          if (TFS_SUCCESS != ret || ret_msg == NULL)
          {
            TBSYS_LOG(ERROR, "get block info error, ret: %d", ret);
            NewClientManager::get_instance().destroy_client(client);
            put_file_handle(fp);
            return EXIT_TFS_ERROR;
          }
          if(ret_msg->getPCode() != SHOW_SERVER_INFORMATION_MESSAGE)
          {
            if (ret_msg->getPCode() == STATUS_MESSAGE)
            {
              StatusMessage* msg = dynamic_cast<StatusMessage*>(ret_msg);
              TBSYS_LOG(ERROR, "get invalid message type: error: %s", msg->get_error());
            }
            TBSYS_LOG(ERROR, "get invalid message type, pcode: %d", ret_msg->getPCode());
            NewClientManager::get_instance().destroy_client(client);
            put_file_handle(fp);
            return EXIT_TFS_ERROR;
          }
          ShowServerInformationMessage* message = dynamic_cast<ShowServerInformationMessage*>(ret_msg);
          SSMScanParameter& ret_param = message->get_param();

          int32_t data_len = ret_param.data_.getDataLen();
          int32_t offset = 0;
          //如果指定的blockid不存在,且block表中[start_next_position_, +00)这些桶内没有block,则拉取block个数为0
          while ((data_len > offset) && !interrupt_)
          {
            BlockBase* base_block = worker->create_block();
            ret = base_block->deserialize(ret_param.data_, data_len, offset, param.child_type_);
            if (TFS_SUCCESS == ret)
            {
              base_block->BlockBase::dump();// log info of each block info
              if (once && (base_block->info_.block_id_ != block_id))
              {
                //TBSYS_LOG(ERROR, "block: %"PRI64_PREFIX"u,%"PRI64_PREFIX"u not exists", base_block->info_.block_id_, block_id);
                break;
              }
              worker->process(base_block, fp);// not sort by block
            }
            else
            {
              TBSYS_LOG(ERROR, "Block deserialize error, ret: %d", ret);
              NewClientManager::get_instance().destroy_client(client);
              put_file_handle(fp);
              return ret;
            }
            tbsys::gDelete(base_block);
          }
          param.start_next_position_ = (ret_param.start_next_position_ << 16) & 0xffff0000;
          param.end_flag_ = ret_param.end_flag_;
          if (param.end_flag_ & SSM_SCAN_CUTOVER_FLAG_NO)
          {
            param.addition_param1_ = ret_param.addition_param2_;
          }
          NewClientManager::get_instance().destroy_client(client);
          if (once)
          {
            break;
          }
        }
        if (!once)
        {
          worker->end(fp);
        }
        if (--count)
        {
          sleep(interval);
        }
      }
      put_file_handle(fp);
      return TFS_SUCCESS;
    }
コード例 #30
0
ファイル: icqbuddy.cpp プロジェクト: BackupTheBerlios/sim-im
bool SnacIcqBuddy::process(unsigned short subtype, ICQBuffer* buf, unsigned short seq)
{
    switch (subtype)
	{
    case ICQ_SNACxBDY_RIGHTSxGRANTED:
        log(L_DEBUG, "Buddy rights granted");
        break;
    case ICQ_SNACxBDY_USEROFFLINE:
		{
			Contact *contact;
			QString screen = buf->unpackScreen();
            log(L_DEBUG, "Buddy offline: %s", qPrintable(screen));
			ICQUserData *data = m_client->findContact(screen, NULL, false, contact);
			if(!data)
				break;
            if(data->getStatus() != ICQ_STATUS_OFFLINE)
			{
				m_client->setOffline(data);
				StatusMessage *m = new StatusMessage;
				m->setContact(contact->id());
				m->setClient(m_client->dataName(data));
				m->setStatus(STATUS_OFFLINE);
				m->setFlags(MESSAGE_RECEIVED);
				EventMessageReceived e(m);
				if(!e.process())
					delete m;
			}
			else
			{
				// hack for trillian
				EventContact e(contact, EventContact::eOnline);
				e.process();
			}
			break;
		}
    case ICQ_SNACxBDY_USERONLINE:
		{
            Contact *contact;
            QString screen = buf->unpackScreen();
            log(L_DEBUG, "Buddy online: %s", qPrintable(screen));
			ICQUserData *data = m_client->findContact(screen, NULL, false, contact);
			if(data)
			{
				bool bChanged     = false;
				bool bAwayChanged = false;
                unsigned long prevStatus = data->getStatus();

				unsigned short level, len;
				(*buf) >> level >> len;
				data->setWarningLevel(level);

				TlvList tlv((*buf));
				Tlv* tlvClass = tlv(TLV_USER_CLASS);
				if(tlvClass)
				{
					unsigned short userClass = *tlvClass;
                    if(userClass != data->getClass())
					{
                        if ((userClass & CLASS_AWAY) != (data->getClass() & CLASS_AWAY))
						{
                            data->setStatusTime((unsigned long)time(NULL));
							bAwayChanged = true;
						}
                        data->setClass(userClass);
						bChanged = true;
					}
                    if(data->getUin() == 0)
					{
						if (userClass & CLASS_AWAY)
						{
							m_client->fetchAwayMessage(data);
						}
						else
						{
                            data->setAutoReply(QString::null);
						}
					}
				}

				// Status TLV
				Tlv *tlvStatus = tlv(TLV_USER_STATUS);
				if(tlvStatus)
				{
					uint32_t status = *tlvStatus;
                    if (status != data->getStatus())
					{
                        data->setStatus(status);
						if ((status & 0xFF) == 0)
                            data->setAutoReply(QString::null);
                        data->setStatusTime((unsigned long)time(NULL));
					}
				}
                else if(data->getStatus() == ICQ_STATUS_OFFLINE)
				{
                    data->setStatus(ICQ_STATUS_ONLINE);
                    data->setStatusTime((unsigned long)time(NULL));
				}

				// Online time TLV
				Tlv *tlvOnlineTime = tlv(TLV_USER_SIGNON_TIME);
				if(tlvOnlineTime)
				{
					uint32_t OnlineTime = *tlvOnlineTime;
					if(OnlineTime != data->getOnlineTime())
					{
						data->setOnlineTime(OnlineTime);
						bChanged = true;
					}
				}
				Tlv *tlvNATime = tlv(0x0004);
				if(tlvNATime)
				{
					unsigned short na_time = *tlvNATime;
					unsigned long StatusTime = (unsigned long)time(NULL) - na_time * 60;
                    if(StatusTime != data->getStatusTime())
					{
                        data->setStatusTime(StatusTime);
						bChanged = true;
					}
				}

				// IP TLV
				Tlv *tlvIP = tlv(TLV_USER_EXT_IP);
                unsigned long oldip = data->getIP();
                data->setIP(htonl((uint32_t)(*tlvIP)));
				if(tlvIP)
                    bChanged |= oldip != data->getIP();

				// short caps tlv
				Tlv *tlvCapShort = tlv(TLV_USER_NEWCAPS);
				if(tlvCapShort)
				{
                    data->setCaps(0);
                    data->setCaps2(0);

					ICQBuffer info(*tlvCapShort);

					for (; info.readPos() < (unsigned)info.size(); )
					{
						unsigned char shortcap[2];
						info.unpack((char*)shortcap, sizeof(shortcap));
						for (unsigned i = 0;; i++)
						{
							if (!memcmp(m_client->capabilities[i],"\x00\x00\x00\x00", 4)) {
                                    log(L_DEBUG, "%lu unknown cap %s", data->getUin(),
                                        makeCapStr(shortcap, sizeof(shortcap)).toLatin1().data());
								break;
							}
							// we don't go through all caps, only the starting with 0x09
							if (*m_client->capabilities[i] != '\x09')
								continue;
							if(!memcmp(&m_client->capabilities[i][2], shortcap, sizeof(shortcap)))
							{
                                m_client->setCap(data, (cap_id_t)i);
								break;
							}
						}
					}
				}
				// normal cap tlv
				Tlv *tlvCapability = tlv(TLV_USER_CAPS);
				if (tlvCapability)
				{
					if(!tlvCapShort)
					{
                        data->setCaps(0);
                        data->setCaps2(0);
					}
					ICQBuffer info(*tlvCapability);
					for(; info.readPos() < (unsigned)info.size(); )
					{
						capability cap;
						info.unpack((char*)cap, sizeof(capability));
						for(unsigned i = 0;; i++)
						{
							unsigned size = sizeof(capability);
							if (i == CAP_SIMOLD)
								size--;

							if (!memcmp(m_client->capabilities[i], "\x00\x00\x00\x00", 4)) 
							{
                                log( L_DEBUG, "%lu unknown cap %s", data->getUin(), qPrintable(makeCapStr( cap, size )) );
								break;
							}
                            if (i == CAP_MICQ || i == CAP_LICQ || i == CAP_SIM || i == CAP_KOPETE || i == CAP_QIP2010)
								size -= 4;
                            if (i == CAP_ANDRQ)
								size -= 7;
                            if (i == CAP_MIRANDA)
								size -= 8;
							if ((i == CAP_JIMM))
								size -= 11;
							if (i == CAP_ICQJP)
								size -= (16 - 4);

							if (!memcmp(cap, m_client->capabilities[i], size))
							{
								if (i == CAP_SIMOLD)
								{
									unsigned char build = cap[sizeof(capability)-1];
                                    if (build && (build == 0x92 || build < (1 << 6))) continue;
                                    data->setBuild(build);
								}
                                if (i == CAP_MICQ || i == CAP_LICQ || i == CAP_SIM || i == CAP_KOPETE)
								{
									unsigned char *p = (unsigned char*)cap;
									p += 12;
                                    data->setBuild((p[0] << 24) + (p[1] << 16) + (p[2] << 8) + p[3]);
								}
                                if (i == CAP_ANDRQ)
								{
									unsigned char *p = (unsigned char*)cap;
									p += 9;
                                    data->setBuild((p[0] << 24) + (p[1] << 16) + (p[2] << 8) + p[3]);
								}
                                if (i == CAP_MIRANDA)
								{
									unsigned char *p = (unsigned char*)cap;
									p += 8;
                                    data->setBuild((p[0] << 24) + (p[1] << 16) + (p[2] << 8) + p[3]);
								}
                                if (i == CAP_JIMM)
								{
									char *p = (char*)cap;
									p += 5;
									const QString str = QString::fromAscii(p, 10);
									const QStringList sl = str.split('.');
									unsigned char maj = 0, min = 0;
									unsigned short rev = 0;
									if(sl.count() > 0)
										maj = sl[0].toUShort();
									if(sl.count() > 1)
										min = sl[1].toUShort();
									if(sl.count() > 2)
										rev = sl[2].toUShort();

                                    data->setBuild((maj << 24) + (min << 16) + rev);
								}
								if (i == CAP_ICQJP)
								{
                                    log(L_DEBUG, "%lu ICQJP cap is set", data->getUin());
                                    data->setBuild(cap[0x4] << 0x18 | cap[0x5] << 0x10 |
                                        cap[0x6] << 8 | cap[0x7]);
								}
								m_client->setCap(data, (cap_id_t)i);
								break;
							}
						}
					}
				}

				// buddy info
				Tlv *tlvBuddy = tlv(TLV_USER_BUDDYINFO);
				if (tlvBuddy)
				{
                    QByteArray ba = data->getBuddyHash();
					unsigned short iconID;
					unsigned char iconFlags, hashSize;
					ICQBuffer info(*tlvBuddy);
					QByteArray hash;
					QString fname = m_client->pictureFile(data);
					QFileInfo fi(fname);

					info >> iconID >> iconFlags >> hashSize;
					hash.resize(hashSize);
					info.unpack(hash.data(), hashSize);
                    if(data->getBuddyID() != iconID ||
							ba != hash ||
							!fi.exists() || fi.size() == 0) {
                        data->setBuddyID(iconID);
                        data->setBuddyHash(hash);
						m_client->requestBuddy(data);
					}
				}

				unsigned long infoUpdateTime = 0;
				unsigned long pluginInfoTime = 0;
				unsigned long pluginStatusTime = 0;

				// Direct connection info
				Tlv *tlvDirect = tlv(TLV_USER_DC_INFO);
				if(tlvDirect)
				{
					ICQBuffer info(*tlvDirect);
					unsigned long  realIP;
					unsigned short port;
					char mode, version, junk;
					info >> realIP;
					info.incReadPos(2);
					info >> port;
					if (realIP == 0x7F000001)
						realIP = 0;
                    unsigned long oldip = data->getRealIP();
                    data->setRealIP(htonl(realIP));
                    bChanged |= oldip != data->getRealIP();
                    data->setPort(port);
					unsigned long DCcookie;
					info >> mode >> junk >> version >> DCcookie;
                    data->setDCcookie(DCcookie);
					info.incReadPos(8);
					info
						>> infoUpdateTime
						>> pluginInfoTime
						>> pluginStatusTime;
                    if (mode == MODE_DENIED || mode != MODE_DIRECT && mode != MODE_INDIRECT)
                        mode = MODE_INDIRECT;
                    data->setMode(mode);
                    data->setVersion(version);
				}

				Tlv *tlvPlugin = tlv(0x0011);
                if(tlvPlugin && data->getUin())
				{
					ICQBuffer info(*tlvPlugin);
					char type;
					unsigned long time;
					info >> type;
					info.unpack(time);
					plugin p;
					unsigned plugin_index;
					unsigned long plugin_status;
					switch (type){
						case 1:
                            m_client->addFullInfoRequest(data->getUin());
							break;
						case 2:
                            if (!m_client->getInvisible() && data->getInvisibleId() == 0 || m_client->getInvisible() && data->getVisibleId()){
								info.incReadPos(6);
								info.unpack((char*)p, sizeof(p));
                                data->setPluginInfoTime(time);
								for (plugin_index = 0; plugin_index < PLUGIN_NULL; plugin_index++)
									if (!memcmp(p, m_client->plugins[plugin_index], sizeof(p)))
										break;
								switch (plugin_index)
								{
									case PLUGIN_PHONEBOOK:
										log(L_DEBUG, "Updated phonebook");
                                        m_client->addPluginInfoRequest(data->getUin(), plugin_index);
										break;
									case PLUGIN_PICTURE:
										log(L_DEBUG, "Updated picture");
										// when buddyID -> new avatar support, no need to ask for old picture plugin
                                        if(data->getBuddyID() == 0 || data->getBuddyHash().size() != 16) {
                                            data->setBuddyID(0);
                                            m_client->addPluginInfoRequest(data->getUin(), plugin_index);
										}
										break;
									case PLUGIN_QUERYxINFO:
										log(L_DEBUG, "Updated info plugin list");
                                        m_client->addPluginInfoRequest(data->getUin(), plugin_index);
										break;
									default:
										if (plugin_index >= PLUGIN_NULL)
											log(L_WARN, "Unknown plugin sign (%04X %04X)",
													type, plugin_index);
								}
							}
							break;
						case 3:
							info.incReadPos(6);
							info.unpack((char*)p, sizeof(p));
							info.incReadPos(1);
							info.unpack(plugin_status);
                            data->setPluginStatusTime(time);
							for (plugin_index = 0; plugin_index < PLUGIN_NULL; plugin_index++)
								if (!memcmp(p, m_client->plugins[plugin_index], sizeof(p)))
									break;
							switch (plugin_index){
								case PLUGIN_FOLLOWME:
                                    if (data->getFollowMe() == plugin_status)
										break;
                                    data->setFollowMe(plugin_status);
									bChanged = true;
									break;
								case PLUGIN_FILESERVER:
                                    if ((data->getSharedFiles() != 0) == (plugin_status != 0))
										break;
                                    data->setSharedFiles(plugin_status != 0);
									bChanged = true;
									break;
								case PLUGIN_ICQPHONE:
                                    if (data->getICQPhone() == plugin_status)
										break;
                                    data->setICQPhone(plugin_status);
									bChanged = true;
									break;
								default:
									if (plugin_index >= PLUGIN_NULL)
										log(L_WARN, "Unknown plugin sign (%04X %04X)", type, plugin_index);
							}
							break;

					}
				}
				else
				{
                    data->setInfoUpdateTime(infoUpdateTime);
                    data->setPluginInfoTime(pluginInfoTime);
                    data->setPluginStatusTime(pluginStatusTime);
                    if (    !m_client->getDisableAutoUpdate() 
                        && (!m_client->getInvisible() || data->getVisibleId())
                        && (m_client->getInvisible()  || data->getInvisibleId() == 0))
                    {
						if (infoUpdateTime == 0)
							infoUpdateTime = 1;
                        if (infoUpdateTime != data->getInfoFetchTime())
                            m_client->addFullInfoRequest(data->getUin());
                        if (   data->getPluginInfoTime() != data->getPluginInfoFetchTime() 
                            && data->getPluginInfoTime())
                            m_client->addPluginInfoRequest(data->getUin(), PLUGIN_QUERYxINFO);
                        if (   data->getPluginInfoTime() != data->getPluginInfoFetchTime() 
                            || data->getPluginStatusTime() != data->getPluginStatusFetchTime()){
                            if (data->getSharedFiles())
                            {
                                data->setSharedFiles(false);
								bChanged = true;
							}
                            if (data->getFollowMe())
                            {
                                data->setFollowMe(0);
								bChanged = true;
							}
                            if (data->getICQPhone())
                            {
                                data->setICQPhone(0);
								bChanged = true;
							}
                            if (data->getPluginStatusTime())
                                m_client->addPluginInfoRequest(data->getUin(), PLUGIN_QUERYxSTATUS);
						}
					}
				}
                if (data->getInvisible())
                {
                    data->setInvisible(false);
					bChanged = true;
				}
                if (bChanged)
                    EventContact(contact, EventContact::eChanged).process();
                if (data->getStatus() != prevStatus || bAwayChanged){
					unsigned status = STATUS_OFFLINE;
                    if ((data->getStatus() & 0xFFFF) != ICQ_STATUS_OFFLINE)
                    {
						status = STATUS_ONLINE;
                        if (data->getStatus() & ICQ_STATUS_DND)
                            status = STATUS_DND;
                        else if (data->getStatus() & ICQ_STATUS_OCCUPIED)
                            status = STATUS_OCCUPIED;
                        else if (data->getStatus() & ICQ_STATUS_NA)
                            status = STATUS_NA;
                        else if (data->getStatus() & ICQ_STATUS_AWAY)
                            status = STATUS_AWAY;
                        else if (data->getStatus() & ICQ_STATUS_FFC)
                            status = STATUS_FFC;
					}
                    if((status == STATUS_ONLINE) && (data->getClass() & CLASS_AWAY))
						status = STATUS_AWAY;
					StatusMessage *m = new StatusMessage();
					m->setContact(contact->id());
					m->setClient(m_client->dataName(data));
					m->setStatus(status);
					m->setFlags(MESSAGE_RECEIVED);
					EventMessageReceived e(m);
					if(!e.process())
						delete m;
                    if (    !contact->getIgnore() 
                        && (data->getClass() & CLASS_AWAY) == 0 
                        && ((data->getStatus() & 0xFF) == ICQ_STATUS_ONLINE && (prevStatus & 0xFF) != ICQ_STATUS_ONLINE || bAwayChanged) 
                        && ((prevStatus & 0xFFFF) != ICQ_STATUS_OFFLINE || data->getOnlineTime() > m_client->data.owner.getOnlineTime())
                        )
                    {
						EventContact e(contact, EventContact::eOnline);
						e.process();
					}
                    if (    !m_client->getDisableAutoReplyUpdate() 
                        && (data->getStatus() & 0xFF) != ICQ_STATUS_ONLINE 
                        && (!m_client->getInvisible() || data->getVisibleId()) 
                        && (m_client->getInvisible() || data->getInvisibleId() == 0)
                        )
                        m_client->addPluginInfoRequest(data->getUin(), PLUGIN_AR);
				}
			}
			break;
		}