80 handlers chan *stanzaHandler |
80 handlers chan *stanzaHandler |
81 inputControl chan int |
81 inputControl chan int |
82 // Incoming XMPP stanzas from the server will be published on |
82 // Incoming XMPP stanzas from the server will be published on |
83 // this channel. Information which is only used by this |
83 // this channel. Information which is only used by this |
84 // library to set up the XMPP stream will not appear here. |
84 // library to set up the XMPP stream will not appear here. |
85 In <-chan interface{} |
85 In <-chan Stanza |
86 // Outgoing XMPP stanzas to the server should be sent to this |
86 // Outgoing XMPP stanzas to the server should be sent to this |
87 // channel. |
87 // channel. |
88 Out chan<- interface{} |
88 Out chan<- Stanza |
89 xmlOut chan<- interface{} |
89 xmlOut chan<- interface{} |
90 // Features advertised by the remote. This will be updated |
90 // Features advertised by the remote. This will be updated |
91 // asynchronously as new features are received throughout the |
91 // asynchronously as new features are received throughout the |
92 // connection process. It should not be updated once |
92 // connection process. It should not be updated once |
93 // StartSession() returns. |
93 // StartSession() returns. |
94 Features *Features |
94 Features *Features |
95 filterOut chan<- <-chan interface{} |
95 filterOut chan<- <-chan Stanza |
96 filterIn <-chan <-chan interface{} |
96 filterIn <-chan <-chan Stanza |
97 } |
97 } |
98 |
98 |
99 // Connect to the appropriate server and authenticate as the given JID |
99 // Connect to the appropriate server and authenticate as the given JID |
100 // with the given password. This function will return as soon as a TCP |
100 // with the given password. This function will return as soon as a TCP |
101 // connection has been established, but before XMPP stream negotiation |
101 // connection has been established, but before XMPP stream negotiation |
198 ch := make(chan interface{}) |
198 ch := make(chan interface{}) |
199 go writeXml(w, ch) |
199 go writeXml(w, ch) |
200 return ch |
200 return ch |
201 } |
201 } |
202 |
202 |
203 func (cl *Client) startStreamReader(xmlIn <-chan interface{}, srvOut chan<- interface{}) <-chan interface{} { |
203 func (cl *Client) startStreamReader(xmlIn <-chan interface{}, srvOut chan<- interface{}) <-chan Stanza { |
204 ch := make(chan interface{}) |
204 ch := make(chan Stanza) |
205 go cl.readStream(xmlIn, ch) |
205 go cl.readStream(xmlIn, ch) |
206 return ch |
206 return ch |
207 } |
207 } |
208 |
208 |
209 func (cl *Client) startStreamWriter(xmlOut chan<- interface{}) chan<- interface{} { |
209 func (cl *Client) startStreamWriter(xmlOut chan<- interface{}) chan<- Stanza { |
210 ch := make(chan interface{}) |
210 ch := make(chan Stanza) |
211 go writeStream(xmlOut, ch, cl.inputControl) |
211 go writeStream(xmlOut, ch, cl.inputControl) |
212 return ch |
212 return ch |
213 } |
213 } |
214 |
214 |
215 func (cl *Client) startFilter(srvIn <-chan interface{}) <-chan interface{} { |
215 func (cl *Client) startFilter(srvIn <-chan Stanza) <-chan Stanza { |
216 cliIn := make(chan interface{}) |
216 cliIn := make(chan Stanza) |
217 filterOut := make(chan (<-chan interface{})) |
217 filterOut := make(chan (<-chan Stanza)) |
218 filterIn := make(chan (<-chan interface{})) |
218 filterIn := make(chan (<-chan Stanza)) |
219 nullFilter := make(chan interface{}) |
219 nullFilter := make(chan Stanza) |
220 go filterBottom(srvIn, nullFilter) |
220 go filterBottom(srvIn, nullFilter) |
221 go filterTop(filterOut, filterIn, nullFilter, cliIn) |
221 go filterTop(filterOut, filterIn, nullFilter, cliIn) |
222 cl.filterOut = filterOut |
222 cl.filterOut = filterOut |
223 cl.filterIn = filterIn |
223 cl.filterIn = filterIn |
224 return cliIn |
224 return cliIn |
270 id := <-Id |
270 id := <-Id |
271 iq := &Iq{Header: Header{To: cl.Jid.Domain, Id: id, Type: "set", |
271 iq := &Iq{Header: Header{To: cl.Jid.Domain, Id: id, Type: "set", |
272 Nested: []interface{}{Generic{XMLName: |
272 Nested: []interface{}{Generic{XMLName: |
273 xml.Name{Space: NsSession, Local: "session"}}}}} |
273 xml.Name{Space: NsSession, Local: "session"}}}}} |
274 ch := make(chan error) |
274 ch := make(chan error) |
275 f := func(st interface{}) bool { |
275 f := func(st Stanza) bool { |
276 iq, ok := st.(*Iq) |
276 iq, ok := st.(*Iq) |
277 if !ok { |
277 if !ok { |
278 Warn.Log("iq reply not iq; can't start session") |
278 Warn.Log("iq reply not iq; can't start session") |
279 ch <- errors.New("bad session start reply") |
279 ch <- errors.New("bad session start reply") |
280 return false |
280 return false |
309 // AddFilter adds a new filter to the top of the stack through which |
309 // AddFilter adds a new filter to the top of the stack through which |
310 // incoming stanzas travel on their way up to the client. The new |
310 // incoming stanzas travel on their way up to the client. The new |
311 // filter's output channel is given to this function, and it returns a |
311 // filter's output channel is given to this function, and it returns a |
312 // new input channel which the filter should read from. When its input |
312 // new input channel which the filter should read from. When its input |
313 // channel closes, the filter should close its output channel. |
313 // channel closes, the filter should close its output channel. |
314 func (cl *Client) AddFilter(out <-chan interface{}) <-chan interface{} { |
314 func (cl *Client) AddFilter(out <-chan Stanza) <-chan Stanza { |
315 cl.filterOut <- out |
315 cl.filterOut <- out |
316 return <-cl.filterIn |
316 return <-cl.filterIn |
317 } |
317 } |