forked from jshiffer/go-xmpp
commit
12d98ae2dc
21
xmpp.go
21
xmpp.go
@ -115,6 +115,9 @@ type Options struct {
|
|||||||
// NoTLS disables TLS and specifies that a plain old unencrypted TCP connection should
|
// NoTLS disables TLS and specifies that a plain old unencrypted TCP connection should
|
||||||
// be used.
|
// be used.
|
||||||
NoTLS bool
|
NoTLS bool
|
||||||
|
|
||||||
|
// Debug output
|
||||||
|
Debug bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewClient establishes a new Client connection based on a set of Options.
|
// NewClient establishes a new Client connection based on a set of Options.
|
||||||
@ -153,21 +156,23 @@ func (o Options) NewClient() (*Client, error) {
|
|||||||
// NewClient creates a new connection to a host given as "hostname" or "hostname:port".
|
// NewClient creates a new connection to a host given as "hostname" or "hostname:port".
|
||||||
// If host is not specified, the DNS SRV should be used to find the host from the domainpart of the JID.
|
// If host is not specified, the DNS SRV should be used to find the host from the domainpart of the JID.
|
||||||
// Default the port to 5222.
|
// Default the port to 5222.
|
||||||
func NewClient(host, user, passwd string) (*Client, error) {
|
func NewClient(host, user, passwd string, debug bool) (*Client, error) {
|
||||||
opts := Options{
|
opts := Options{
|
||||||
Host: host,
|
Host: host,
|
||||||
User: user,
|
User: user,
|
||||||
Password: passwd,
|
Password: passwd,
|
||||||
|
Debug: debug,
|
||||||
}
|
}
|
||||||
return opts.NewClient()
|
return opts.NewClient()
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewClientNoTLS(host, user, passwd string) (*Client, error) {
|
func NewClientNoTLS(host, user, passwd string, debug bool) (*Client, error) {
|
||||||
opts := Options{
|
opts := Options{
|
||||||
Host: host,
|
Host: host,
|
||||||
User: user,
|
User: user,
|
||||||
Password: passwd,
|
Password: passwd,
|
||||||
NoTLS: true,
|
NoTLS: true,
|
||||||
|
Debug: debug,
|
||||||
}
|
}
|
||||||
return opts.NewClient()
|
return opts.NewClient()
|
||||||
}
|
}
|
||||||
@ -210,9 +215,11 @@ func cnonce() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) init(o *Options) error {
|
func (c *Client) init(o *Options) error {
|
||||||
// For debugging: the following causes the plaintext of the connection to be duplicated to stdout.
|
|
||||||
//c.p = xml.NewDecoder(tee{c.conn, os.Stdout})
|
|
||||||
c.p = xml.NewDecoder(c.conn)
|
c.p = xml.NewDecoder(c.conn)
|
||||||
|
// For debugging: the following causes the plaintext of the connection to be duplicated to stdout.
|
||||||
|
if o.Debug {
|
||||||
|
c.p = xml.NewDecoder(tee{c.conn, os.Stdout})
|
||||||
|
}
|
||||||
|
|
||||||
a := strings.SplitN(o.User, "@", 2)
|
a := strings.SplitN(o.User, "@", 2)
|
||||||
if len(a) != 2 {
|
if len(a) != 2 {
|
||||||
@ -393,6 +400,11 @@ func (c *Client) Send(chat Chat) {
|
|||||||
xmlEscape(chat.Remote), xmlEscape(chat.Type), xmlEscape(chat.Text))
|
xmlEscape(chat.Remote), xmlEscape(chat.Type), xmlEscape(chat.Text))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Send origin
|
||||||
|
func (c *Client) SendOrg(org string) {
|
||||||
|
fmt.Fprint(c.conn, org)
|
||||||
|
}
|
||||||
|
|
||||||
// RFC 3920 C.1 Streams name space
|
// RFC 3920 C.1 Streams name space
|
||||||
type streamFeatures struct {
|
type streamFeatures struct {
|
||||||
XMLName xml.Name `xml:"http://etherx.jabber.org/streams features"`
|
XMLName xml.Name `xml:"http://etherx.jabber.org/streams features"`
|
||||||
@ -617,6 +629,7 @@ func (t tee) Read(p []byte) (n int, err error) {
|
|||||||
n, err = t.r.Read(p)
|
n, err = t.r.Read(p)
|
||||||
if n > 0 {
|
if n > 0 {
|
||||||
t.w.Write(p[0:n])
|
t.w.Write(p[0:n])
|
||||||
|
t.w.Write([]byte("\n"))
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user