F. Aydemir
F. Aydemir

Reputation: 2735

Forwarding SIP requests/responses using Resiprocate SIP stack

I need to make a SIP proxy implementation in C++ using Resiprocate SIP stack. The proxy must always sit in between UACs and UAS and simply forward incoming SIP requests and responses bidirectionally.

According to my readings/understanding on SIP protocol, if a SIP proxy wants to sit in between an UAC and an UAS, it has to inject its SIP address into the route field of the SIP messages it is receiving. Can anyone tell me how I can add/manupulate the route field in the incoming SIP messages in my proxy implementation? More precisely what I need to know is to which header files/classes/handle functions I should refer? I am kinda new to SIP and resiprocate and got lost in a way in its source code. Thanks in advance.

P.S: One can wonder why I don't use resiprocate's own proxy implementation. This is because I need to develop a lightweight prototype for a special need simply by using the SIP stack API itself. The prototype should simply act as a forwarder in the SIP traffic, nothing more than that.

Upvotes: 1

Views: 1593

Answers (1)

F. Aydemir
F. Aydemir

Reputation: 2735

Following does the job in the else block.

  void insertRouteField(SipMessage * received)
        {
          ErrLog ( << "***********************************\n");
          NameAddr& to = received->header(h_To);
          ErrLog ( << "To Field: " << to.uri().toString());

          NameAddr& from = received->header(h_From);
          ErrLog ( << "From Field: " << from.uri().toString() );

          ParserContainer<NameAddr>& rRoutes = received->header(h_RecordRoutes);
          if(!rRoutes.empty())
          {
              NameAddr& frontRRoute = rRoutes.front();
              ErrLog ( << "rRoutes: " << frontRRoute.uri().toString());

              ErrLog ( << "***********************************\n");
          }
          else
          {
              NameAddr route;
              route.uri().scheme() = "sip";
              route.uri().user() = "proxy";
              route.uri().host() = SipStack::getHostname();
              route.uri().port() = 5070;
              route.uri().param(p_transport) = Tuple::toData(mTransport);
              rRoutes.push_front(route);

              NameAddr& frontRRoute = rRoutes.front();
              ErrLog ( << "rRoute: " << frontRRoute.uri().toString());
              ErrLog ( << "***********************************");
          } 

        }

Header filers you might wanna look at: "resip/stack/Helper.hxx" "resip/stack/SipMessage.hxx" "resip/stack/Uri.hxx" "resip/stack/SipStack.hxx" "rutil/Logger.hxx" "rutil/ThreadIf.hxx" "resip/stack/ParserContainer.hxx"

Upvotes: 1

Related Questions