551 nonceCountStr + ":" + cnonceStr + ":auth:" + |
551 nonceCountStr + ":" + cnonceStr + ":auth:" + |
552 hex(h(a2)))) |
552 hex(h(a2)))) |
553 return response |
553 return response |
554 } |
554 } |
555 |
555 |
556 // BUG(cjyar) This should use iq.nested rather than iq.generic. |
|
557 |
|
558 // Send a request to bind a resource. RFC 3920, section 7. |
556 // Send a request to bind a resource. RFC 3920, section 7. |
559 func (cl *Client) bind(bind *Generic) { |
557 func (cl *Client) bind(bindAdv *bindIq) { |
560 res := cl.Jid.Resource |
558 res := cl.Jid.Resource |
561 msg := &Iq{Type: "set", Id: <- cl.Id, Any: |
559 bindReq := &bindIq{} |
562 &Generic{XMLName: xml.Name{Space: NsBind, Local: |
|
563 "bind"}}} |
|
564 if res != "" { |
560 if res != "" { |
565 msg.Any.Any = &Generic{XMLName: xml.Name{Local: |
561 bindReq.Resource = &res |
566 "resource"}, Chardata: res} |
562 } |
567 } |
563 msg := &Iq{Type: "set", Id: <- cl.Id, Nested: &bindReq} |
568 f := func(st Stanza) bool { |
564 f := func(st Stanza) bool { |
569 if st.XType() == "error" { |
565 if st.XType() == "error" { |
570 log.Println("Resource binding failed") |
566 log.Println("Resource binding failed") |
571 return false |
567 return false |
572 } |
568 } |
573 bind := st.generic() |
569 bindRepl, ok := st.XNested().(*bindIq) |
574 if bind == nil { |
570 if !ok { |
575 log.Println("nil resource bind") |
571 log.Printf("bad bind reply: %v", bindRepl) |
576 return false |
572 return false |
577 } |
573 } |
578 jidEle := bind.Any |
574 jidStr := bindRepl.Jid |
579 if jidEle == nil { |
575 if jidStr == nil || *jidStr == "" { |
580 log.Println("nil resource") |
|
581 return false |
|
582 } |
|
583 jidStr := jidEle.Chardata |
|
584 if jidStr == "" { |
|
585 log.Println("empty resource") |
576 log.Println("empty resource") |
586 return false |
577 return false |
587 } |
578 } |
588 jid := new(JID) |
579 jid := new(JID) |
589 if !jid.Set(jidStr) { |
580 if !jid.Set(*jidStr) { |
590 log.Println("Can't parse JID %s", jidStr) |
581 log.Println("Can't parse JID %s", jidStr) |
591 return false |
582 return false |
592 } |
583 } |
593 cl.Jid = *jid |
584 cl.Jid = *jid |
594 log.Printf("Bound resource: %s", cl.Jid.String()) |
585 log.Printf("Bound resource: %s", cl.Jid.String()) |