xmpp/layer3.go
changeset 178 ccfebbd9f49b
parent 163 3f891f7fe817
equal deleted inserted replaced
177:63f33bb8fa33 178:ccfebbd9f49b
   134 
   134 
   135 	cl.setStatus(StatusConnectedTls)
   135 	cl.setStatus(StatusConnectedTls)
   136 
   136 
   137 	// Now re-send the initial handshake message to start the new
   137 	// Now re-send the initial handshake message to start the new
   138 	// session.
   138 	// session.
   139 	cl.sendRaw <- &stream{To: cl.Jid.Domain, Version: XMPPVersion}
   139 	cl.sendRaw <- &stream{To: cl.Jid.Domain(), Version: XMPPVersion}
   140 }
   140 }
   141 
   141 
   142 // Send a request to bind a resource. RFC 3920, section 7.
   142 // Send a request to bind a resource. RFC 3920, section 7.
   143 func (cl *Client) bind() {
   143 func (cl *Client) bind() {
   144 	res := cl.Jid.Resource
   144 	res := cl.Jid.Resource()
   145 	bindReq := &bindIq{}
   145 	bindReq := &bindIq{}
   146 	if res != "" {
   146 	if res != "" {
   147 		bindReq.Resource = &res
   147 		bindReq.Resource = &res
   148 	}
   148 	}
   149 	msg := &Iq{Header: Header{Type: "set", Id: NextId(),
   149 	msg := &Iq{Header: Header{Type: "set", Id: NextId(),
   168 		}
   168 		}
   169 		if bindRepl == nil {
   169 		if bindRepl == nil {
   170 			cl.setError(fmt.Errorf("Bad bind reply: %#v", iq))
   170 			cl.setError(fmt.Errorf("Bad bind reply: %#v", iq))
   171 			return
   171 			return
   172 		}
   172 		}
   173 		jidStr := bindRepl.Jid
   173 		jid := bindRepl.Jid
   174 		if jidStr == nil || *jidStr == "" {
   174 		if jid == nil || *jid == "" {
   175 			cl.setError(fmt.Errorf("empty resource in bind %#v",
   175 			cl.setError(fmt.Errorf("empty resource in bind %#v",
   176 				iq))
   176 				iq))
   177 			return
   177 			return
   178 		}
   178 		}
   179 		jid := new(JID)
   179 		cl.Jid = JID(*jid)
   180 		if err := jid.Set(*jidStr); err != nil {
       
   181 			cl.setError(fmt.Errorf("bind: an't parse JID %s: %v",
       
   182 				*jidStr, err))
       
   183 			return
       
   184 		}
       
   185 		cl.Jid = *jid
       
   186 		cl.setStatus(StatusBound)
   180 		cl.setStatus(StatusBound)
   187 	}
   181 	}
   188 	cl.SetCallback(msg.Id, f)
   182 	cl.SetCallback(msg.Id, f)
   189 	cl.sendRaw <- msg
   183 	cl.sendRaw <- msg
   190 }
   184 }