equal
deleted
inserted
replaced
10 "bytes" |
10 "bytes" |
11 "encoding/xml" |
11 "encoding/xml" |
12 "errors" |
12 "errors" |
13 "fmt" |
13 "fmt" |
14 "io" |
14 "io" |
|
15 "log" |
15 "log/syslog" |
16 "log/syslog" |
16 "net" |
17 "net" |
17 "sync" |
18 "sync" |
18 ) |
19 ) |
19 |
20 |
36 ) |
37 ) |
37 |
38 |
38 var ( |
39 var ( |
39 // If non-nil when NewClient() is called, log messages will be |
40 // If non-nil when NewClient() is called, log messages will be |
40 // sent to this writer. |
41 // sent to this writer. |
41 Log *syslog.Writer |
42 Log *log.Logger |
42 // Threshold for which messages are logged. |
43 // Threshold for which messages are logged. |
43 Loglevel syslog.Priority = syslog.LOG_NOTICE |
44 Loglevel syslog.Priority = syslog.LOG_NOTICE |
44 ) |
45 ) |
45 |
46 |
46 // This channel may be used as a convenient way to generate a unique |
47 // This channel may be used as a convenient way to generate a unique |
247 if n == 0 { |
248 if n == 0 { |
248 break |
249 break |
249 } |
250 } |
250 buf.Write(c[:n]) |
251 buf.Write(c[:n]) |
251 if c[0] == '\n' || c[0] == '>' { |
252 if c[0] == '\n' || c[0] == '>' { |
252 Log.Debug(buf.String()) |
253 Log.Println(buf.String()) |
253 buf.Reset() |
254 buf.Reset() |
254 } |
255 } |
255 } |
256 } |
256 leftover := buf.String() |
257 leftover := buf.String() |
257 if leftover != "" { |
258 if leftover != "" { |
258 Log.Debug(buf.String()) |
259 Log.Println(buf.String()) |
259 } |
260 } |
260 } |
261 } |
261 |
262 |
262 // bindDone is called when we've finished resource binding (and all |
263 // bindDone is called when we've finished resource binding (and all |
263 // the negotiations that precede it). Now we can start accepting |
264 // the negotiations that precede it). Now we can start accepting |
276 iq := &Iq{To: cl.Jid.Domain, Id: id, Type: "set", Nested: []interface{}{Generic{XMLName: xml.Name{Space: NsSession, Local: "session"}}}} |
277 iq := &Iq{To: cl.Jid.Domain, Id: id, Type: "set", Nested: []interface{}{Generic{XMLName: xml.Name{Space: NsSession, Local: "session"}}}} |
277 ch := make(chan error) |
278 ch := make(chan error) |
278 f := func(st Stanza) bool { |
279 f := func(st Stanza) bool { |
279 if st.GetType() == "error" { |
280 if st.GetType() == "error" { |
280 if Log != nil { |
281 if Log != nil { |
281 Log.Err(fmt.Sprintf("Can't start session: %v", |
282 Log.Printf("Can't start session: %v", |
282 st)) |
283 st) |
283 } |
284 } |
284 ch <- st.GetError() |
285 ch <- st.GetError() |
285 return false |
286 return false |
286 } |
287 } |
287 ch <- nil |
288 ch <- nil |