105 } |
105 } |
106 |
106 |
107 // Allocate the appropriate structure for this token. |
107 // Allocate the appropriate structure for this token. |
108 var obj interface{} |
108 var obj interface{} |
109 switch se.Name.Space + " " + se.Name.Local { |
109 switch se.Name.Space + " " + se.Name.Local { |
110 case nsStream + " stream": |
110 case NsStream + " stream": |
111 st, err := parseStream(se) |
111 st, err := parseStream(se) |
112 if err != nil { |
112 if err != nil { |
113 log.Printf("unmarshal stream: %v", |
113 log.Printf("unmarshal stream: %v", |
114 err) |
114 err) |
115 break |
115 break |
116 } |
116 } |
117 ch <- st |
117 ch <- st |
118 continue |
118 continue |
119 case "stream error", nsStream + " error": |
119 case "stream error", NsStream + " error": |
120 obj = &streamError{} |
120 obj = &streamError{} |
121 case nsStream + " features": |
121 case NsStream + " features": |
122 obj = &Features{} |
122 obj = &Features{} |
123 case nsTLS + " proceed", nsTLS + " failure": |
123 case NsTLS + " proceed", NsTLS + " failure": |
124 obj = &starttls{} |
124 obj = &starttls{} |
125 case nsSASL + " challenge", nsSASL + " failure", |
125 case NsSASL + " challenge", NsSASL + " failure", |
126 nsSASL + " success": |
126 NsSASL + " success": |
127 obj = &auth{} |
127 obj = &auth{} |
128 case "jabber:client iq": |
128 case "jabber:client iq": |
129 obj = &Iq{} |
129 obj = &Iq{} |
130 case "jabber:client message": |
130 case "jabber:client message": |
131 obj = &Message{} |
131 obj = &Message{} |
432 } |
432 } |
433 |
433 |
434 // Encode the map and send it. |
434 // Encode the map and send it. |
435 clStr := packSasl(clMap) |
435 clStr := packSasl(clMap) |
436 b64 := base64.StdEncoding |
436 b64 := base64.StdEncoding |
437 clObj := &auth{XMLName: xml.Name{Space: nsSASL, Local: |
437 clObj := &auth{XMLName: xml.Name{Space: NsSASL, Local: |
438 "response"}, Chardata: |
438 "response"}, Chardata: |
439 b64.EncodeToString([]byte(clStr))} |
439 b64.EncodeToString([]byte(clStr))} |
440 cl.xmlOut <- clObj |
440 cl.xmlOut <- clObj |
441 } |
441 } |
442 |
442 |
443 func (cl *Client) saslDigest2(srvMap map[string] string) { |
443 func (cl *Client) saslDigest2(srvMap map[string] string) { |
444 if cl.saslExpected == srvMap["rspauth"] { |
444 if cl.saslExpected == srvMap["rspauth"] { |
445 clObj := &auth{XMLName: xml.Name{Space: nsSASL, Local: |
445 clObj := &auth{XMLName: xml.Name{Space: NsSASL, Local: |
446 "response"}} |
446 "response"}} |
447 cl.xmlOut <- clObj |
447 cl.xmlOut <- clObj |
448 } else { |
448 } else { |
449 clObj := &auth{XMLName: xml.Name{Space: nsSASL, Local: |
449 clObj := &auth{XMLName: xml.Name{Space: NsSASL, Local: |
450 "failure"}, Any: |
450 "failure"}, Any: |
451 &Generic{XMLName: xml.Name{Space: nsSASL, |
451 &Generic{XMLName: xml.Name{Space: NsSASL, |
452 Local: "abort"}}} |
452 Local: "abort"}}} |
453 cl.xmlOut <- clObj |
453 cl.xmlOut <- clObj |
454 } |
454 } |
455 } |
455 } |
456 |
456 |
506 |
506 |
507 // Send a request to bind a resource. RFC 3920, section 7. |
507 // Send a request to bind a resource. RFC 3920, section 7. |
508 func (cl *Client) bind(bind *Generic) { |
508 func (cl *Client) bind(bind *Generic) { |
509 res := cl.Jid.Resource |
509 res := cl.Jid.Resource |
510 msg := &Iq{Type: "set", Id: <- cl.Id, Any: |
510 msg := &Iq{Type: "set", Id: <- cl.Id, Any: |
511 &Generic{XMLName: xml.Name{Space: nsBind, Local: |
511 &Generic{XMLName: xml.Name{Space: NsBind, Local: |
512 "bind"}}} |
512 "bind"}}} |
513 if res != "" { |
513 if res != "" { |
514 msg.Any.Any = &Generic{XMLName: xml.Name{Local: |
514 msg.Any.Any = &Generic{XMLName: xml.Name{Local: |
515 "resource"}, Chardata: res} |
515 "resource"}, Chardata: res} |
516 } |
516 } |