91 // is non-nil, connection progress information will be sent on it. |
91 // is non-nil, connection progress information will be sent on it. |
92 func NewClient(jid *JID, password string, tlsconf tls.Config, exts []Extension, |
92 func NewClient(jid *JID, password string, tlsconf tls.Config, exts []Extension, |
93 pr Presence, status chan<- Status) (*Client, error) { |
93 pr Presence, status chan<- Status) (*Client, error) { |
94 |
94 |
95 // Resolve the domain in the JID. |
95 // Resolve the domain in the JID. |
96 _, srvs, err := net.LookupSRV(clientSrv, "tcp", jid.Domain) |
96 _, srvs, err := net.LookupSRV(clientSrv, "tcp", jid.Domain()) |
97 if err != nil { |
97 if err != nil { |
98 return nil, fmt.Errorf("LookupSrv %s: %v", jid.Domain, err) |
98 return nil, fmt.Errorf("LookupSrv %s: %v", jid.Domain, err) |
99 } |
99 } |
100 if len(srvs) == 0 { |
100 if len(srvs) == 0 { |
101 return nil, fmt.Errorf("LookupSrv %s: no results", jid.Domain) |
101 return nil, fmt.Errorf("LookupSrv %s: no results", jid.Domain) |
209 cl.AddRecvFilter(ext.RecvFilter) |
209 cl.AddRecvFilter(ext.RecvFilter) |
210 cl.AddSendFilter(ext.SendFilter) |
210 cl.AddSendFilter(ext.SendFilter) |
211 } |
211 } |
212 |
212 |
213 // Initial handshake. |
213 // Initial handshake. |
214 hsOut := &stream{To: jid.Domain, Version: XMPPVersion} |
214 hsOut := &stream{To: jid.Domain(), Version: XMPPVersion} |
215 cl.sendRaw <- hsOut |
215 cl.sendRaw <- hsOut |
216 |
216 |
217 // Wait until resource binding is complete. |
217 // Wait until resource binding is complete. |
218 if err := cl.statmgr.awaitStatus(StatusBound); err != nil { |
218 if err := cl.statmgr.awaitStatus(StatusBound); err != nil { |
219 return nil, cl.getError(err) |
219 return nil, cl.getError(err) |
222 // Forget about the password, for paranoia's sake. |
222 // Forget about the password, for paranoia's sake. |
223 cl.password = "" |
223 cl.password = "" |
224 |
224 |
225 // Initialize the session. |
225 // Initialize the session. |
226 id := NextId() |
226 id := NextId() |
227 iq := &Iq{Header: Header{To: cl.Jid.Domain, Id: id, Type: "set", |
227 iq := &Iq{Header: Header{To: cl.Jid.Domain(), Id: id, Type: "set", |
228 Nested: []interface{}{Generic{XMLName: xml.Name{Space: NsSession, Local: "session"}}}}} |
228 Nested: []interface{}{Generic{XMLName: xml.Name{Space: NsSession, Local: "session"}}}}} |
229 ch := make(chan error) |
229 ch := make(chan error) |
230 f := func(st Stanza) { |
230 f := func(st Stanza) { |
231 iq, ok := st.(*Iq) |
231 iq, ok := st.(*Iq) |
232 if !ok { |
232 if !ok { |