2024-11-13 14:39:08 -05:00
|
|
|
package gosam
|
2014-02-10 21:01:55 +01:00
|
|
|
|
2022-02-01 20:03:13 -05:00
|
|
|
// CreateSession creates a new Session of type style, with an optional destination.
|
|
|
|
// an empty destination is interpreted as "TRANSIENT"
|
|
|
|
// Returns the destination for the new Client or an error.
|
2021-04-15 17:21:41 -04:00
|
|
|
func (c *Client) CreateSession(style, dest string) (string, error) {
|
2014-02-10 21:01:55 +01:00
|
|
|
if dest == "" {
|
|
|
|
dest = "TRANSIENT"
|
|
|
|
}
|
2021-04-15 17:21:41 -04:00
|
|
|
// c.id = id
|
2019-02-24 23:08:01 -05:00
|
|
|
r, err := c.sendCmd(
|
2021-04-15 17:21:41 -04:00
|
|
|
"SESSION CREATE STYLE=%s ID=%s DESTINATION=%s %s %s %s %s \n",
|
2021-02-24 23:04:55 -05:00
|
|
|
style,
|
2021-04-15 17:21:41 -04:00
|
|
|
c.ID(),
|
2020-09-13 01:32:22 -04:00
|
|
|
dest,
|
2019-04-25 23:45:24 -04:00
|
|
|
c.from(),
|
|
|
|
c.to(),
|
2019-02-24 23:08:01 -05:00
|
|
|
c.sigtype(),
|
|
|
|
c.allOptions(),
|
|
|
|
)
|
2014-02-10 21:01:55 +01:00
|
|
|
if err != nil {
|
2019-02-27 20:25:36 -05:00
|
|
|
return "", err
|
2014-02-10 21:01:55 +01:00
|
|
|
}
|
|
|
|
|
2025-03-07 01:35:21 +00:00
|
|
|
if !r.IsOk() {
|
2019-02-27 20:25:36 -05:00
|
|
|
return "", ReplyError{ResultKeyNotFound, r}
|
2014-02-10 21:01:55 +01:00
|
|
|
}
|
2019-04-20 23:27:47 -04:00
|
|
|
c.destination = r.Pairs["DESTINATION"]
|
|
|
|
return c.destination, nil
|
2014-02-10 21:01:55 +01:00
|
|
|
}
|
2021-02-24 23:04:55 -05:00
|
|
|
|
|
|
|
// CreateStreamSession creates a new STREAM Session.
|
|
|
|
// Returns the Id for the new Client.
|
2021-04-15 17:21:41 -04:00
|
|
|
func (c *Client) CreateStreamSession(dest string) (string, error) {
|
|
|
|
return c.CreateSession("STREAM", dest)
|
2021-02-24 23:04:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// CreateDatagramSession creates a new DATAGRAM Session.
|
|
|
|
// Returns the Id for the new Client.
|
2021-04-15 17:21:41 -04:00
|
|
|
func (c *Client) CreateDatagramSession(dest string) (string, error) {
|
|
|
|
return c.CreateSession("DATAGRAM", dest)
|
2021-02-24 23:04:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// CreateRawSession creates a new RAW Session.
|
|
|
|
// Returns the Id for the new Client.
|
2021-04-15 17:21:41 -04:00
|
|
|
func (c *Client) CreateRawSession(dest string) (string, error) {
|
|
|
|
return c.CreateSession("RAW", dest)
|
2021-02-24 23:04:55 -05:00
|
|
|
}
|