equal
deleted
inserted
replaced
61 In <-chan Stanza |
61 In <-chan Stanza |
62 // Outgoing XMPP stanzas to the server should be sent to this |
62 // Outgoing XMPP stanzas to the server should be sent to this |
63 // channel. |
63 // channel. |
64 Out chan<- Stanza |
64 Out chan<- Stanza |
65 xmlOut chan<- interface{} |
65 xmlOut chan<- interface{} |
66 // BUG(cjyar) Remove this. Make a Stanza parser method |
|
67 // available for use by interact.go and similar applications. |
|
68 TextOut chan<- *string |
|
69 } |
66 } |
70 var _ io.Closer = &Client{} |
67 var _ io.Closer = &Client{} |
71 |
68 |
72 // Connect to the appropriate server and authenticate as the given JID |
69 // Connect to the appropriate server and authenticate as the given JID |
73 // with the given password. This function will return as soon as a TCP |
70 // with the given password. This function will return as soon as a TCP |
112 tlsr, tlsw := cl.startTransport() |
109 tlsr, tlsw := cl.startTransport() |
113 |
110 |
114 // Start the reader and writers that convert to and from XML. |
111 // Start the reader and writers that convert to and from XML. |
115 xmlIn := startXmlReader(tlsr) |
112 xmlIn := startXmlReader(tlsr) |
116 cl.xmlOut = startXmlWriter(tlsw) |
113 cl.xmlOut = startXmlWriter(tlsw) |
117 textOut := startTextWriter(tlsw) |
|
118 |
114 |
119 // Start the XMPP stream handler which filters stream-level |
115 // Start the XMPP stream handler which filters stream-level |
120 // events and responds to them. |
116 // events and responds to them. |
121 clIn := cl.startStreamReader(xmlIn, cl.xmlOut) |
117 clIn := cl.startStreamReader(xmlIn, cl.xmlOut) |
122 clOut := startStreamWriter(cl.xmlOut) |
118 clOut := startStreamWriter(cl.xmlOut) |
125 hsOut := &stream{To: jid.Domain, Version: Version} |
121 hsOut := &stream{To: jid.Domain, Version: Version} |
126 cl.xmlOut <- hsOut |
122 cl.xmlOut <- hsOut |
127 |
123 |
128 cl.In = clIn |
124 cl.In = clIn |
129 cl.Out = clOut |
125 cl.Out = clOut |
130 cl.TextOut = textOut |
|
131 |
126 |
132 return cl, nil |
127 return cl, nil |
133 } |
128 } |
134 |
129 |
135 func (c *Client) Close() os.Error { |
130 func (c *Client) Close() os.Error { |
136 tryClose(c.In, c.Out, c.TextOut) |
131 tryClose(c.In, c.Out) |
137 return nil |
132 return nil |
138 } |
133 } |
139 |
134 |
140 func (cl *Client) startTransport() (io.Reader, io.Writer) { |
135 func (cl *Client) startTransport() (io.Reader, io.Writer) { |
141 inr, inw := io.Pipe() |
136 inr, inw := io.Pipe() |
152 } |
147 } |
153 |
148 |
154 func startXmlWriter(w io.Writer) chan<- interface{} { |
149 func startXmlWriter(w io.Writer) chan<- interface{} { |
155 ch := make(chan interface{}) |
150 ch := make(chan interface{}) |
156 go writeXml(w, ch) |
151 go writeXml(w, ch) |
157 return ch |
|
158 } |
|
159 |
|
160 func startTextWriter(w io.Writer) chan<- *string { |
|
161 ch := make(chan *string) |
|
162 go writeText(w, ch) |
|
163 return ch |
152 return ch |
164 } |
153 } |
165 |
154 |
166 func (cl *Client) startStreamReader(xmlIn <-chan interface{}, srvOut chan<- interface{}) <-chan Stanza { |
155 func (cl *Client) startStreamReader(xmlIn <-chan interface{}, srvOut chan<- interface{}) <-chan Stanza { |
167 ch := make(chan Stanza) |
156 ch := make(chan Stanza) |