Skip to content

Commit

Permalink
Move update command into its own TU and start adding subcommands
Browse files Browse the repository at this point in the history
support;

Add error classes to represent SDP parsing and RTP proxy
communication errors along with generic interface;

Propagate error from delayed processing callback into the
UA callback.
  • Loading branch information
sobomax committed Jan 7, 2025
1 parent 29a4085 commit f2375f0
Show file tree
Hide file tree
Showing 17 changed files with 405 additions and 126 deletions.
40 changes: 40 additions & 0 deletions sippy/exceptions/rtp_proxy_error.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) 2025 Sippy Software, Inc. All rights reserved.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation and/or
// other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

package sippy_exceptions

type RtpProxyError struct {
SdpParseError
}

func NewRtpProxyError(arg string) *RtpProxyError {
return &RtpProxyError{
SdpParseError: SdpParseError{
SipParseError: SipParseError{Arg: arg},
Code: 502,
Msg: "Bad Gateway",
},
}
}
83 changes: 83 additions & 0 deletions sippy/exceptions/sdp_parse_error.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Copyright (c) 2025 Sippy Software, Inc. All rights reserved.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation and/or
// other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

package sippy_exceptions

import (
"strconv"

"github.com/sippy/go-b2bua/sippy/headers"
"github.com/sippy/go-b2bua/sippy/types"
)


type SipParseError struct {
Arg string
SipResponse sippy_types.SipResponse
}

func (e *SipParseError) Error() string {
return e.Arg
}

func (e *SipParseError) GetResponse(req sippy_types.SipRequest) sippy_types.SipResponse {
return e.SipResponse
}

func (e *SipParseError) GetReason() *sippy_header.SipReason {
return nil
}

type SdpParseError struct {
SipParseError
Code int
Msg string
}

func NewSdpParseError(arg string, sipResponse sippy_types.SipResponse) *SdpParseError {
return &SdpParseError{
SipParseError: SipParseError{Arg: arg, SipResponse: sipResponse},
Code: 488,
Msg: "Not Acceptable Here",
}
}

func (e *SdpParseError) GetResponse(req sippy_types.SipRequest) sippy_types.SipResponse {
if e.SipResponse != nil {
return e.SipResponse
}
resp := req.GenResponse(e.Code, e.Msg, nil, nil)
if reason := e.GetReason(); reason != nil {
resp.AppendHeader(reason)
}
return resp
}

func (e *SdpParseError) GetReason() *sippy_header.SipReason {
if e.Arg != "" {
return sippy_header.NewSipReason("SIP", strconv.Itoa(e.Code), e.Arg)
}
return nil
}
29 changes: 9 additions & 20 deletions sippy/rtp_proxy/session/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,12 @@ type Rtp_proxy_session struct {
rtpp_wi chan *rtpp_cmd
}

type rtpproxy_update_result struct {
rtpproxy_address string
rtpproxy_port string
family string
sendonly bool
}

type rtpp_cmd struct {
cmd string
cb func(string)
rtp_proxy_client sippy_types.RtpProxyClient
}

func (self *rtpproxy_update_result) Address() string {
return self.rtpproxy_address
}

func NewRtp_proxy_session(config sippy_conf.Config, rtp_proxy_clients []sippy_types.RtpProxyClient, call_id, from_tag, to_tag, notify_socket, notify_tag string, session_lock sync.Locker) (*Rtp_proxy_session, error) {
self := &Rtp_proxy_session{
notify_socket : notify_socket,
Expand All @@ -91,8 +80,6 @@ func NewRtp_proxy_session(config sippy_conf.Config, rtp_proxy_clients []sippy_ty
}
self.caller.otherside = &self.callee
self.callee.otherside = &self.caller
self.caller.owner = self
self.callee.owner = self
self.caller.session_exists = false
self.callee.session_exists = false
online_clients := []sippy_types.RtpProxyClient{}
Expand Down Expand Up @@ -140,7 +127,7 @@ func NewRtp_proxy_session(config sippy_conf.Config, rtp_proxy_clients []sippy_ty
result_callback(result)
*/
func (self *Rtp_proxy_session) PlayCaller(prompt_name string, times int/*= 1*/, result_callback func(string)/*= nil*/, index int /*= 0*/) {
self.caller._play(prompt_name, times, result_callback, index)
self.caller._play(prompt_name, times, result_callback, index, self)
}

func (self *Rtp_proxy_session) send_command(cmd string, cb func(string)) {
Expand Down Expand Up @@ -175,12 +162,14 @@ func (self *Rtp_proxy_session) cmd_done(res string) {
}

func (self *Rtp_proxy_session) StopPlayCaller(result_callback func(string)/*= nil*/, index int/*= 0*/) {
self.caller._stop_play(result_callback, index)
self.caller._stop_play(result_callback, index, self)
}

func (self *Rtp_proxy_session) StartRecording(rname/*= nil*/ string, result_callback func(string)/*= nil*/, index int/*= 0*/) {
if ! self.caller.session_exists {
self.caller.update("0.0.0.0", "0", func(*rtpproxy_update_result) { self._start_recording(rname, result_callback, index) }, "", index, "IP4")
up_cb := func(*UpdateResult, *Rtp_proxy_session, sippy_types.SipHandlingError) { self._start_recording(rname, result_callback, index) }
up := NewUpdateParams(self, index, up_cb)
self.caller.update(up)
return
}
self._start_recording(rname, result_callback, index)
Expand Down Expand Up @@ -220,12 +209,12 @@ func (self *Rtp_proxy_session) Delete() {
self._rtp_proxy_client = nil
}

func (self *Rtp_proxy_session) OnCallerSdpChange(sdp_body sippy_types.MsgBody, result_callback func(sippy_types.MsgBody)) error {
return self.caller._on_sdp_change(sdp_body, result_callback)
func (self *Rtp_proxy_session) OnCallerSdpChange(sdp_body sippy_types.MsgBody, result_callback sippy_types.OnDelayedCB) error {
return self.caller._on_sdp_change(self, sdp_body, result_callback)
}

func (self *Rtp_proxy_session) OnCalleeSdpChange(sdp_body sippy_types.MsgBody, result_callback func(sippy_types.MsgBody)) error {
return self.callee._on_sdp_change(sdp_body, result_callback)
func (self *Rtp_proxy_session) OnCalleeSdpChange(sdp_body sippy_types.MsgBody, result_callback sippy_types.OnDelayedCB) error {
return self.callee._on_sdp_change(self, sdp_body, result_callback)
}

func rtp_proxy_session_destructor(self *Rtp_proxy_session) {
Expand Down
Loading

0 comments on commit f2375f0

Please sign in to comment.