Пример #1
0
int AmSipDialog::reply(const AmSipRequest& req,
		       unsigned int  code,
		       const string& reason,
		       const string& content_type,
		       const string& body,
		       const string& hdrs)
{
  string m_hdrs = hdrs;

  if(hdl)
    hdl->onSendReply(req,code,reason,
		     content_type,body,m_hdrs);

  string reply_sock = "/tmp/" + AmSession::getNewId();
  string code_str = int2str(code);

  string msg = ":t_reply:";

  msg += reply_sock;
  msg += "\n";

  msg += code_str;
  msg += "\n";

  msg += reason;
  msg += "\n";

  msg += req.key;
  msg += "\n";

  msg += local_tag;
  msg += "\n";

  if(!m_hdrs.empty())
    msg += m_hdrs;

  if ((req.method!="CANCEL")&&
      !((req.method=="BYE")&&(code<300)))
    msg += getContactHdr();

  if(!body.empty())
    msg += "Content-Type: " + content_type + "\n";
  if (AmConfig::Signature.length()) 
    msg += "Server: " + AmConfig::Signature + "\n";

  msg += ".\n";

  if(!body.empty())
    msg += body;

  msg += ".\n\n";

  if(updateStatusReply(req,code))
    return -1;

  return AmServer::send_msg(msg,reply_sock, 500);
}
Пример #2
0
int AmBasicSipDialog::sendRequest(const string& method, 
				  const AmMimeBody* body,
				  const string& hdrs,
				  int flags)
{
  AmSipRequest req;

  req.method = method;
  req.r_uri = remote_uri;

  req.from = SIP_HDR_COLSP(SIP_HDR_FROM) + local_party;
  if(!ext_local_tag.empty())
    req.from += ";tag=" + ext_local_tag;
  else if(!local_tag.empty())
    req.from += ";tag=" + local_tag;
    
  req.to = SIP_HDR_COLSP(SIP_HDR_TO) + remote_party;
  if(!remote_tag.empty()) 
    req.to += ";tag=" + remote_tag;
    
  req.cseq = cseq;
  req.callid = callid;
    
  req.hdrs = hdrs;

  req.route = getRoute();

  if(body != NULL) {
    req.body = *body;
  }

  if(onTxRequest(req,flags) < 0)
    return -1;

  if (!(flags & SIP_FLAGS_NOCONTACT)) {
    req.contact = getContactHdr();
  }

  if (!(flags & SIP_FLAGS_VERBATIM)) {
    // add Signature
    if (AmConfig::Signature.length())
      req.hdrs += SIP_HDR_COLSP(SIP_HDR_USER_AGENT) + AmConfig::Signature + CRLF;
  }

  int send_flags = 0;
  if(patch_ruri_next_hop && remote_tag.empty()) {
    send_flags |= TR_FLAG_NEXT_HOP_RURI;
  }

  if((flags & SIP_FLAGS_NOBL) ||
     !remote_tag.empty()) {
    send_flags |= TR_FLAG_DISABLE_BL;
  }

  int res = SipCtrlInterface::send(req, local_tag,
				   remote_tag.empty() || !next_hop_1st_req ?
				   next_hop : "",
				   outbound_interface,
				   send_flags,logger);
  if(res) {
    ERROR("Could not send request: method=%s; call-id=%s; cseq=%i\n",
	  req.method.c_str(),req.callid.c_str(),req.cseq);
    return res;
  }

  onRequestTxed(req);
  return 0;
}
Пример #3
0
int AmBasicSipDialog::reply(const AmSipRequest& req,
			    unsigned int  code,
			    const string& reason,
			    const AmMimeBody* body,
			    const string& hdrs,
			    int flags)
{
  TransMap::const_iterator t_it = uas_trans.find(req.cseq);
  if(t_it == uas_trans.end()){
    ERROR("could not find any transaction matching request cseq\n");
    ERROR("request cseq=%i; reply code=%i; callid=%s; local_tag=%s; "
	  "remote_tag=%s\n",
	  req.cseq,code,callid.c_str(),
	  local_tag.c_str(),remote_tag.c_str());
    log_stacktrace(L_ERR);
    return -1;
  }
  DBG("reply: transaction found!\n");
    
  AmSipReply reply;

  reply.code = code;
  reply.reason = reason;
  reply.tt = req.tt;
  if((code > 100) && !(flags & SIP_FLAGS_NOTAG))
    reply.to_tag = ext_local_tag.empty() ? local_tag : ext_local_tag;
  reply.hdrs = hdrs;
  reply.cseq = req.cseq;
  reply.cseq_method = req.method;

  if(body != NULL)
    reply.body = *body;

  if(onTxReply(req,reply,flags)){
    DBG("onTxReply failed\n");
    return -1;
  }

  if (!(flags & SIP_FLAGS_VERBATIM)) {
    // add Signature
    if (AmConfig::Signature.length())
      reply.hdrs += SIP_HDR_COLSP(SIP_HDR_SERVER) + AmConfig::Signature + CRLF;
  }

  if ((code > 100 && code < 300) && !(flags & SIP_FLAGS_NOCONTACT)) {
    /* if 300<=code<400, explicit contact setting should be done */
    reply.contact = getContactHdr();
  }

  int ret = SipCtrlInterface::send(reply,local_tag,logger);
  if(ret){
    ERROR("Could not send reply: code=%i; reason='%s'; method=%s;"
	  " call-id=%s; cseq=%i\n",
	  reply.code,reply.reason.c_str(),reply.cseq_method.c_str(),
	  callid.c_str(),reply.cseq);

    return ret;
  }
  else {
    onReplyTxed(req,reply);
  }

  return ret;
}
Пример #4
0
int AmSipDialog::sendRequest(const string& method, 
			     const string& content_type,
			     const string& body,
			     const string& hdrs)
{
  string msg,ser_cmd;
  string m_hdrs = hdrs;

  if(hdl)
    hdl->onSendRequest(method,content_type,body,m_hdrs,cseq);

  msg = ":t_uac_dlg:" + AmConfig::ReplySocketName + "\n"
    + method + "\n"
    + remote_uri + "\n";
    
  if(next_hop.empty())
    msg += ".";
  else
    msg += next_hop;
    
  msg += "\n";
    
  msg += "From: " + local_party;
  if(!local_tag.empty())
    msg += ";tag=" + local_tag;
    
  msg += "\n";
    
  msg += "To: " + remote_party;
  if(!remote_tag.empty()) 
    msg += ";tag=" + remote_tag;
    
  msg += "\n";
    
  msg += "CSeq: " + int2str(cseq) + " " + method + "\n"
    + "Call-ID: " + callid + "\n";
    
  if((method!="BYE")&&(method!="CANCEL"))
    msg += getContactHdr();
    
  if(!m_hdrs.empty()){
    msg += m_hdrs;
    if(m_hdrs[m_hdrs.length()-1] != '\n')
      msg += "\n";
  }

  if(!route.empty())
    msg += getRoute();
    
  if(!body.empty())
    msg += "Content-Type: " + content_type + "\n";
    
  msg += "Max-Forwards: "  MAX_FORWARDS "\n";

  if (AmConfig::Signature.length()) 
    msg += "User-Agent: " + AmConfig::Signature + "\n";

  msg += ".\n" // EoH
    + body + ".\n\n";

  if (AmServer::send_msg_replyhandler(msg)) 
    return -1;
    
  uac_trans[cseq] = AmSipTransaction(method,cseq);

  // increment for next request
  cseq++;
    
  return 0;
}