xmpp.go
changeset 38 2839fece923e
parent 36 9fe022261dcc
child 41 c8c9e6a7e6c9
equal deleted inserted replaced
37:fbda8e925fdf 38:2839fece923e
    82 // connection has been established, but before XMPP stream negotiation
    82 // connection has been established, but before XMPP stream negotiation
    83 // has completed. The negotiation will occur asynchronously, and any
    83 // has completed. The negotiation will occur asynchronously, and any
    84 // send operation to Client.Out will block until negotiation (resource
    84 // send operation to Client.Out will block until negotiation (resource
    85 // binding) is complete.
    85 // binding) is complete.
    86 func NewClient(jid *JID, password string,
    86 func NewClient(jid *JID, password string,
    87 	extStanza map[string] func(*xml.Name) ExtendedStanza) (*Client, os.Error) {
    87 	extStanza map[string] func(*xml.Name) interface{}) (*Client, os.Error) {
    88 	// Resolve the domain in the JID.
    88 	// Resolve the domain in the JID.
    89 	_, srvs, err := net.LookupSRV(clientSrv, "tcp", jid.Domain)
    89 	_, srvs, err := net.LookupSRV(clientSrv, "tcp", jid.Domain)
    90 	if err != nil {
    90 	if err != nil {
    91 		return nil, os.NewError("LookupSrv " + jid.Domain +
    91 		return nil, os.NewError("LookupSrv " + jid.Domain +
    92 			": " + err.String())
    92 			": " + err.String())
   120 	cl.inputControl = make(chan int)
   120 	cl.inputControl = make(chan int)
   121 	idCh := make(chan string)
   121 	idCh := make(chan string)
   122 	cl.Id = idCh
   122 	cl.Id = idCh
   123 
   123 
   124 	if extStanza == nil {
   124 	if extStanza == nil {
   125 		extStanza = make(map[string] func(*xml.Name) ExtendedStanza)
   125 		extStanza = make(map[string] func(*xml.Name) interface{})
   126 	}
   126 	}
   127 	extStanza[NsRoster] = rosterStanza
   127 	extStanza[NsRoster] = newRosterQuery
   128 
   128 
   129 	// Start the unique id generator.
   129 	// Start the unique id generator.
   130 	go makeIds(idCh)
   130 	go makeIds(idCh)
   131 
   131 
   132 	// Start the transport handler, initially unencrypted.
   132 	// Start the transport handler, initially unencrypted.
   163 	go cl.writeTransport(outr)
   163 	go cl.writeTransport(outr)
   164 	return inr, outw
   164 	return inr, outw
   165 }
   165 }
   166 
   166 
   167 func startXmlReader(r io.Reader,
   167 func startXmlReader(r io.Reader,
   168 	extStanza map[string] func(*xml.Name) ExtendedStanza) <-chan interface{} {
   168 	extStanza map[string] func(*xml.Name) interface{}) <-chan interface{} {
   169 	ch := make(chan interface{})
   169 	ch := make(chan interface{})
   170 	go readXml(r, ch, extStanza)
   170 	go readXml(r, ch, extStanza)
   171 	return ch
   171 	return ch
   172 }
   172 }
   173 
   173