stream.go
changeset 21 8f6ae5cfc9b9
parent 20 e119444a1119
child 22 d6b7b4cbf50d
equal deleted inserted replaced
20:e119444a1119 21:8f6ae5cfc9b9
   130 		case "jabber:client message":
   130 		case "jabber:client message":
   131 			obj = &Message{}
   131 			obj = &Message{}
   132 		case "jabber:client presence":
   132 		case "jabber:client presence":
   133 			obj = &Presence{}
   133 			obj = &Presence{}
   134 		default:
   134 		default:
   135 			obj = &Unrecognized{}
   135 			obj = &Generic{}
   136 			log.Printf("Ignoring unrecognized: %s %s\n",
   136 			log.Printf("Ignoring unrecognized: %s %s\n",
   137 				se.Name.Space, se.Name.Local)
   137 				se.Name.Space, se.Name.Local)
   138 		}
   138 		}
   139 
   139 
   140 		// Read the complete XML stanza.
   140 		// Read the complete XML stanza.
   143 			log.Printf("unmarshal: %v", err)
   143 			log.Printf("unmarshal: %v", err)
   144 			break
   144 			break
   145 		}
   145 		}
   146 
   146 
   147 		// BUG(cjyar) If it's a Stanza, use reflection to
   147 		// BUG(cjyar) If it's a Stanza, use reflection to
   148 		// search for any Unrecognized elements and fill in
   148 		// search for any Generic elements and fill in
   149 		// their attributes.
   149 		// their attributes.
   150 
   150 
   151 		// Put it on the channel.
   151 		// Put it on the channel.
   152 		ch <- obj
   152 		ch <- obj
   153 	}
   153 	}
   431 				"response"}}
   431 				"response"}}
   432 		cl.xmlOut <- clObj
   432 		cl.xmlOut <- clObj
   433 	} else {
   433 	} else {
   434 		clObj := &auth{XMLName: xml.Name{Space: nsSASL, Local:
   434 		clObj := &auth{XMLName: xml.Name{Space: nsSASL, Local:
   435 				"failure"}, Any:
   435 				"failure"}, Any:
   436 			&Unrecognized{XMLName: xml.Name{Space: nsSASL,
   436 			&Generic{XMLName: xml.Name{Space: nsSASL,
   437 				Local: "abort"}}}
   437 				Local: "abort"}}}
   438 		cl.xmlOut <- clObj
   438 		cl.xmlOut <- clObj
   439 	}
   439 	}
   440 }
   440 }
   441 
   441 
   488 		hex(h(a2))))
   488 		hex(h(a2))))
   489 	return response
   489 	return response
   490 }
   490 }
   491 
   491 
   492 // Send a request to bind a resource. RFC 3920, section 7.
   492 // Send a request to bind a resource. RFC 3920, section 7.
   493 func (cl *Client) bind(bind *Unrecognized) {
   493 func (cl *Client) bind(bind *Generic) {
   494 	res := cl.Jid.Resource
   494 	res := cl.Jid.Resource
   495 	msg := &Iq{Type: "set", Id: cl.NextId(), Any:
   495 	msg := &Iq{Type: "set", Id: cl.NextId(), Any:
   496 		&Unrecognized{XMLName: xml.Name{Space: nsBind, Local:
   496 		&Generic{XMLName: xml.Name{Space: nsBind, Local:
   497 					"bind"}}}
   497 					"bind"}}}
   498 	if res != "" {
   498 	if res != "" {
   499 		msg.Any.Any = &Unrecognized{XMLName: xml.Name{Local:
   499 		msg.Any.Any = &Generic{XMLName: xml.Name{Local:
   500 				"resource"}, Chardata: res}
   500 				"resource"}, Chardata: res}
   501 	}
   501 	}
   502 	f := func(st Stanza) bool {
   502 	f := func(st Stanza) bool {
   503 		if st.XType() == "error" {
   503 		if st.XType() == "error" {
   504 			log.Println("Resource binding failed")
   504 			log.Println("Resource binding failed")