Skip to content

Commit

Permalink
fix: docs cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
emiago committed Jun 28, 2024
1 parent cbd22c0 commit 958400d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 33 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,6 @@ Content-Length: 0
If you find this project interesting for bigger support or consulting, you can contact me on
[mail]([email protected])

*You can buy me a coffee in meantime on* [ko-fi.com/emiasupport](https://ko-fi.com/emiasupport)

For bugs features pls create [issue](https://github.com/emiago/sipgo/issues).


Expand Down
49 changes: 23 additions & 26 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,13 @@ func (c *Client) GetHostname() string {

// TransactionRequest uses transaction layer to send request and returns transaction
//
// NOTE: By default request will not be cloned and it will populate request with missing headers unless options are used
// By default request will not be cloned and it will populate request with missing headers unless options are used
// In most cases you want this as you will retry with additional headers
//
// Following header fields will be added if not exist to have correct SIP request:
// To, From, CSeq, Call-ID, Max-Forwards, Via
//
// Passing options will override this behavior, that is it is expected
// that you have request fully built
// This is useful when using client handle in proxy building as request are already parsed
// Passing options will override this behavior, that is, it is expected that your request is already prebuild
// This is mostly the case when creating proxy
func (c *Client) TransactionRequest(ctx context.Context, req *sip.Request, options ...ClientRequestOption) (sip.ClientTransaction, error) {
if req.IsAck() {
return nil, fmt.Errorf("ACK request must be sent directly through transport. Use WriteRequest")
Expand All @@ -145,12 +143,10 @@ func (c *Client) TransactionRequest(ctx context.Context, req *sip.Request, optio
return c.tx.Request(ctx, req)
}

// Experimental
//
// Do request is HTTP client like Do request/response
// Do request is HTTP client like Do request/response.
// It returns on final response.
// Canceling ctx sends Cancel Request but it still returns ctx error
// For more control use TransactionRequest
// For more lower API use TransactionRequest directly
func (c *Client) Do(ctx context.Context, req *sip.Request) (*sip.Response, error) {
tx, err := c.TransactionRequest(ctx, req)
if err != nil {
Expand All @@ -170,7 +166,8 @@ func (c *Client) Do(ctx context.Context, req *sip.Request) (*sip.Response, error
return nil, tx.Err()

case <-ctx.Done():
return nil, errors.Join(ctx.Err(), tx.Cancel())
err := tx.Cancel()
return nil, errors.Join(ctx.Err(), err)
}
}
}
Expand Down Expand Up @@ -210,21 +207,7 @@ func (c *Client) digestTransactionRequest(ctx context.Context, req *sip.Request,
cseq.SeqNo++

req.RemoveHeader("Via")
tx, err := c.TransactionRequest(context.TODO(), req, ClientRequestAddVia)
return tx, err
}

// digestProxyAuthRequest does basic digest auth with proxy header
func digestProxyAuthRequest(ctx context.Context, client *Client, req *sip.Request, res *sip.Response, opts digest.Options) (sip.ClientTransaction, error) {
if err := digestProxyAuthApply(req, res, opts); err != nil {
return nil, err
}

cseq := req.CSeq()
cseq.SeqNo++

req.RemoveHeader("Via")
tx, err := client.TransactionRequest(ctx, req, ClientRequestAddVia)
tx, err := c.TransactionRequest(ctx, req, ClientRequestAddVia)
return tx, err
}

Expand Down Expand Up @@ -403,7 +386,7 @@ func ClientRequestDecreaseMaxForward(c *Client, r *sip.Request) error {
maxfwd.Dec()

if maxfwd.Val() <= 0 {
return fmt.Errorf("Max forwards reached")
return fmt.Errorf("max forwards reached")
}
return nil
}
Expand Down Expand Up @@ -443,3 +426,17 @@ func digestAuthApply(req *sip.Request, res *sip.Response, opts digest.Options) e
req.AppendHeader(sip.NewHeader("Authorization", cred.String()))
return nil
}

// digestProxyAuthRequest does basic digest auth with proxy header
func digestProxyAuthRequest(ctx context.Context, client *Client, req *sip.Request, res *sip.Response, opts digest.Options) (sip.ClientTransaction, error) {
if err := digestProxyAuthApply(req, res, opts); err != nil {
return nil, err
}

cseq := req.CSeq()
cseq.SeqNo++

req.RemoveHeader("Via")
tx, err := client.TransactionRequest(ctx, req, ClientRequestAddVia)
return tx, err
}
5 changes: 0 additions & 5 deletions dialog_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,6 @@ func (s *DialogServerSession) WriteRequest(req *sip.Request) error {
// Close is always good to call for cleanup or terminating dialog state
func (s *DialogServerSession) Close() error {
s.s.dialogs.Delete(s.ID)
// s.setState(sip.DialogStateEnded)
// ctx, _ := context.WithTimeout(context.Background(), transaction.Timer_B)
// return s.Bye(ctx)
return nil
}

Expand Down Expand Up @@ -407,8 +404,6 @@ func (s *DialogServerSession) Bye(ctx context.Context) error {
}
defer tx.Terminate() // Terminates current transaction

// s.setState(sip.DialogStateEnded)

// Wait 200
select {
case res := <-tx.Responses():
Expand Down
3 changes: 3 additions & 0 deletions ua.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ func WithUserAgenTLSConfig(c *tls.Config) UserAgentOption {
}
}

// WithUserAgentParser allows removing default behavior of parser
// You can define and remove default headers parser map and pass here.
// Only use if your benchmarks are better than default
func WithUserAgentParser(p *sip.Parser) UserAgentOption {
return func(s *UserAgent) error {
s.parser = p
Expand Down

0 comments on commit 958400d

Please sign in to comment.