<commit_before>/**
 * Copyright 2010 Voxeo Corporation Licensed under the Apache License, Version
 * 2.0 (the "License"); you may not use this file except in compliance with the
 * License. You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
 * or agreed to in writing, software distributed under the License is
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */

package com.voxeo.moho.sip;

import java.util.Map;

import javax.media.mscontrol.MsControlException;
import javax.media.mscontrol.join.Joinable.Direction;
import javax.servlet.sip.Rel100Exception;
import javax.servlet.sip.SipServletMessage;
import javax.servlet.sip.SipServletRequest;
import javax.servlet.sip.SipServletResponse;

import org.apache.log4j.Logger;

import com.voxeo.moho.Participant.JoinType;
import com.voxeo.moho.event.JoinCompleteEvent;
import com.voxeo.moho.sip.SIPCall.State;

public class DirectAI2NOJoinDelegate extends JoinDelegate {

  private static final Logger LOG = Logger.getLogger(DirectAI2NOJoinDelegate.class);

  protected Direction _direction;

  protected SipServletResponse _response;

  protected SipServletResponse _reliable183Resp;

  protected boolean _reInvited;

  protected SipServletResponse _responseCall1;

  protected SipServletRequest _pendingUpdateCall2;

  protected Object syncLock = new Object();

  protected DirectAI2NOJoinDelegate(final SIPIncomingCall call1, final SIPOutgoingCall call2,
      final Direction direction, final SIPCallImpl peer) {
    _call1 = call1;
    _call2 = call2;
    _direction = direction;
    _peer = peer;
  }

  @Override
  public void doJoin() throws Exception {
    super.doJoin();
    ((SIPOutgoingCall) _call2).setContinueRouting(_call1);
    ((SIPOutgoingCall) _call2).call(null, _call1.getSipSession().getApplicationSession());
  }

  @Override
  protected void doUpdate(SipServletRequest req, SIPCallImpl call, Map<String, String> headers) throws Exception {
    if (SIPHelper.getRawContentWOException(req) == null) {
      req.createResponse(200).send();
    }
    else if (_call2.equals(call)) {
      if (_response != null) {
        LOG.warn("Receive UPDATE after INVITE processed, return peer remote SDP.");
        SipServletResponse resp = req.createResponse(200);
        resp.setContent(_call1.getRemoteSdp(), "application/sdp");
        resp.send();
      }
      else {
        _pendingUpdateCall2 = req;
        reInviteCall1(req);
      }
    }
  }

  @Override
  protected void doInviteResponse(final SipServletResponse res, final SIPCallImpl call,
      final Map<String, String> headers) throws Exception {
    if (SIPHelper.isErrorResponse(res) && _call1.equals(call)) {
      if(_response != null) {<commit_msg>fix:  MOHO-62 - when joining answered incoming call to outgoing call, didn't process ERROR response from outgoing call<commit_after>/**
 * Copyright 2010 Voxeo Corporation Licensed under the Apache License, Version
 * 2.0 (the "License"); you may not use this file except in compliance with the
 * License. You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
 * or agreed to in writing, software distributed under the License is
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */

package com.voxeo.moho.sip;

import java.util.Map;

import javax.media.mscontrol.MsControlException;
import javax.media.mscontrol.join.Joinable.Direction;
import javax.servlet.sip.Rel100Exception;
import javax.servlet.sip.SipServletMessage;
import javax.servlet.sip.SipServletRequest;
import javax.servlet.sip.SipServletResponse;

import org.apache.log4j.Logger;

import com.voxeo.moho.Participant.JoinType;
import com.voxeo.moho.event.JoinCompleteEvent;
import com.voxeo.moho.sip.SIPCall.State;

public class DirectAI2NOJoinDelegate extends JoinDelegate {

  private static final Logger LOG = Logger.getLogger(DirectAI2NOJoinDelegate.class);

  protected Direction _direction;

  protected SipServletResponse _response;

  protected SipServletResponse _reliable183Resp;

  protected boolean _reInvited;

  protected SipServletResponse _responseCall1;

  protected SipServletRequest _pendingUpdateCall2;

  protected Object syncLock = new Object();

  protected DirectAI2NOJoinDelegate(final SIPIncomingCall call1, final SIPOutgoingCall call2,
      final Direction direction, final SIPCallImpl peer) {
    _call1 = call1;
    _call2 = call2;
    _direction = direction;
    _peer = peer;
  }

  @Override
  public void doJoin() throws Exception {
    super.doJoin();
    ((SIPOutgoingCall) _call2).setContinueRouting(_call1);
    ((SIPOutgoingCall) _call2).call(null, _call1.getSipSession().getApplicationSession());
  }

  @Override
  protected void doUpdate(SipServletRequest req, SIPCallImpl call, Map<String, String> headers) throws Exception {
    if (SIPHelper.getRawContentWOException(req) == null) {
      req.createResponse(200).send();
    }
    else if (_call2.equals(call)) {
      if (_response != null) {
        LOG.warn("Receive UPDATE after INVITE processed, return peer remote SDP.");
        SipServletResponse resp = req.createResponse(200);
        resp.setContent(_call1.getRemoteSdp(), "application/sdp");
        resp.send();
      }
      else {
        _pendingUpdateCall2 = req;
        reInviteCall1(req);
      }
    }
  }

  @Override
  protected void doInviteResponse(final SipServletResponse res, final SIPCallImpl call,
      final Map<String, String> headers) throws Exception {
    if (SIPHelper.isErrorResponse(res)) {
      if(_response != null && _call1.equals(call)) {
{'fraction_non_alphanumeric': 0.08699310112737675, 'fraction_numerical': 0.014134275618374558, 'mean_word_length': 4.25552608311229, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6542564', 'n_tokens_mistral': 1792, 'n_tokens_neox': 1715, 'n_words': 486}