Logo Search packages:      
Sourcecode: yate version File versions  Download package

void SIPMessage::complete ( SIPEngine engine,
const char *  user = 0,
const char *  domain = 0,
const char *  dlgTag = 0 
)

Complete missing fields with defaults taken from a SIP engine

Definition at line 218 of file message.cpp.

References addHeader(), TelEngine::ObjList::append(), TelEngine::SIPEngine::buildParty(), TelEngine::Debug(), TelEngine::SIPEngine::getAllowed(), getHeader(), TelEngine::SIPEngine::getMaxForwards(), TelEngine::SIPEngine::getNextCSeq(), getParty(), TelEngine::SIPEngine::getUserAgent(), header, isACK(), isAnswer(), isOutgoing(), method, TelEngine::String::null(), uri, and version.

Referenced by TelEngine::SIPEngine::addMessage(), and TelEngine::SIPTransaction::setLatestMessage().

{
    Debug("SIPMessage",DebugAll,"complete(%p,'%s','%s','%s')%s%s%s [%p]",
      engine,user,domain,dlgTag,
      isACK() ? " ACK" : "",
      isOutgoing() ? " OUT" : "",
      isAnswer() ? " ANS" : "",
      this);
    if (!engine)
      return;

    if (isOutgoing() && !getParty())
      engine->buildParty(this);

    // don't complete incoming messages
    if (!isOutgoing())
      return;

    // only set the dialog tag on ACK
    if (isACK()) {
      HeaderLine* hl = const_cast<HeaderLine*>(getHeader("To"));
      if (dlgTag && hl && !hl->getParam("tag"))
          hl->setParam("tag",dlgTag);
      return;
    }

    if (!user)
      user = "anonymous";
    if (!domain)
      domain = getParty()->getLocalAddr();

    HeaderLine* hl = const_cast<HeaderLine*>(getHeader("Via"));
    if (!hl) {
      String tmp;
      tmp << version << "/" << getParty()->getProtoName();
      tmp << " " << getParty()->getLocalAddr() << ":" << getParty()->getLocalPort();
      hl = new HeaderLine("Via",tmp);
      header.append(hl);
    }
    if (!(isAnswer() || hl->getParam("branch"))) {
      String tmp("z9hG4bK");
      tmp << (int)::random();
      hl->setParam("branch",tmp);
    }
    if (isAnswer()) {
      hl->setParam("received",getParty()->getPartyAddr());
      hl->setParam("rport",String(getParty()->getPartyPort()));
    }

    hl = const_cast<HeaderLine*>(getHeader("From"));
    if (!hl) {
      String tmp;
      tmp << "<sip:" << user << "@" << domain << ">";
      hl = new HeaderLine("From",tmp);
      header.append(hl);
    }
    if (!(isAnswer() || hl->getParam("tag")))
      hl->setParam("tag",String((int)::random()));

    hl = const_cast<HeaderLine*>(getHeader("To"));
    if (!hl) {
      String tmp;
      tmp << "<" << uri << ">";
      hl = new HeaderLine("To",tmp);
      header.append(hl);
    }
    if (dlgTag && !hl->getParam("tag"))
      hl->setParam("tag",dlgTag);

    if (!getHeader("Call-ID")) {
      String tmp;
      tmp << (int)::random() << "@" << domain;
      addHeader("Call-ID",tmp);
    }

    if (!getHeader("CSeq")) {
      String tmp;
      m_cseq = engine->getNextCSeq();
      tmp << m_cseq << " " << method;
      addHeader("CSeq",tmp);
    }

    if (!(isAnswer() || getHeader("Max-Forwards"))) {
      String tmp(engine->getMaxForwards());
      addHeader("Max-Forwards",tmp);
    }

    if (!getHeader("Contact")) {
      String tmp;
      if (isAnswer())
          tmp = *getHeader("To");
      if (tmp.null()) {
          tmp << "<sip:" << user << "@" << getParty()->getLocalAddr();
          if (getParty()->getLocalPort() != 5060)
            tmp << ":" << getParty()->getLocalPort();
          tmp << ">";
      }
      addHeader("Contact",tmp);
    }

    if (!(getHeader("User-Agent") || engine->getUserAgent().null()))
      addHeader("User-Agent",engine->getUserAgent());

    if (!getHeader("Allow"))
      addHeader("Allow",engine->getAllowed());
}


Generated by  Doxygen 1.6.0   Back to index