예제 #1
0
  /** 开始保持在线 */
  public void startKeepAlive() {
    int keepAliveInterval = FetionConfig.getInteger("fetion.sip.keep-alive-interval") * 1000;
    this.context
        .getFetionTimer()
        .scheduleTask(this.keepAliveTask, keepAliveInterval, keepAliveInterval);

    int keepConnectionInterval =
        FetionConfig.getInteger("fetion.sip.keep-connection-interval") * 1000;
    this.context
        .getFetionTimer()
        .scheduleTask(this.keepConnectionTask, keepConnectionInterval, keepConnectionInterval);
  }
예제 #2
0
  /**
   * 用户登录验证
   *
   * @return
   */
  public SipcRequest createUserAuthRequest(
      SipcHeader wwwHeader, int presence, boolean isSupportedMutiConnection, StoreVersion version) {
    SipcRequest req = this.createDefaultSipcRequest(SipcMethod.REGISTER);

    Pattern pt =
        Pattern.compile(
            "Digest algorithm=\"SHA1-sess-v4\",nonce=\"(.*?)\",key=\"(.*?)\",signature=\"(.*?)\"");
    Matcher mc = pt.matcher(wwwHeader.getValue());
    if (mc.matches()) {
      String passHex =
          PasswordEncrypterV4.encryptV4(this.user.getUserId(), this.user.getPassword());
      AuthGeneratorV4 auth = new AuthGeneratorV4();
      String aeskey = ConvertHelper.byte2HexStringWithoutSpace(user.getAesKey());
      String response = auth.generate(mc.group(2), passHex, mc.group(1), aeskey);
      String authString = "Digest response=\"" + response + "\",algorithm=\"SHA1-sess-v4\"";
      req.addHeader(SipcHeader.AUTHORIZATION, authString);
      req.addHeader("AK", "ak-value");

      String body = MessageTemplate.TMPL_USER_AUTH;
      body = body.replace("{machineCode}", FetionConfig.getString("fetion.sip.machine-code"));
      body = body.replace("{sid}", Integer.toString(this.user.getFetionId()));
      body = body.replace("{userId}", Integer.toString(this.user.getUserId()));
      body = body.replace("{presence}", Integer.toString(presence));
      body = body.replace("{personalVersion}", Integer.toString(version.getPersonalVersion()));
      body = body.replace("{contactVersion}", Integer.toString(version.getContactVersion()));
      req.setBody(new SipcBody(body));

    } else {
      throw new IllegalStateException("parse wwwHeader failed. wwwHeader=" + wwwHeader.getValue());
    }

    return req;
  }
예제 #3
0
  /**
   * 建立处理链
   *
   * @throws FetionException
   */
  public void buildProcessorChain() throws FetionException {
    this.processorChain = new ProcessorChain();
    this.processorChain.addLast(new ServerMessageDispatcher(context, this, this)); // 消息分发服务
    if (FetionConfig.getBoolean("log.sipc.enable")) {
      this.processorChain.addLast(
          new SipcLogger("ServerDialog-" + this.context.getFetionUser().getFetionId())); // 日志记录
    }
    this.processorChain.addLast(new TransferService(this.context)); // 传输服务
    this.processorChain.addLast(new SipcParser()); // 信令解析器
    this.processorChain.addLast(
        this.context.getTransferFactory().createDefaultTransfer()); // 信令传输对象

    this.processorChain.startProcessorChain();
  }
예제 #4
0
 /**
  * 创建默认的SipcRequest
  *
  * @param m
  * @return
  */
 public SipcRequest createDefaultSipcRequest(String m) {
   SipcRequest req = new SipcRequest(m, this.user.getDomain());
   req.addHeader(SipcHeader.FROM, Integer.toString(this.user.getFetionId()));
   if (m.equals(this.lastMethod)) {
     req.addHeader(SipcHeader.CALLID, Integer.toString(this.globalCallId));
     req.addHeader(SipcHeader.SEQUENCE, Integer.toString(this.getNextSequence()) + " " + m);
   } else {
     req.addHeader(SipcHeader.CALLID, Integer.toString(this.getNextCallID()));
     req.addHeader(SipcHeader.SEQUENCE, "1 " + m);
     this.gloalSequence = 1;
   }
   req.setAliveTime(
       (int)
           (FetionConfig.getInteger("fetion.sip.default-alive-time")
               + System.currentTimeMillis() / 1000));
   this.lastMethod = m;
   return req;
 }