Implements send / send raw

This commit is contained in:
Mickael Remond
2018-01-26 09:55:39 +01:00
parent 2cd8eed765
commit ad6e09a0f6
4 changed files with 39 additions and 8 deletions

View File

@@ -73,11 +73,12 @@ func (c *Component) Connect(connStr string) error {
}
// ReadPacket reads next incoming XMPP packet
// TODO use defined interface Packet
func (c *Component) ReadPacket() (Packet, error) {
// TODO use defined interface Packet
return next(c.decoder)
}
// Send marshalls XMPP stanza and sends it to the server.
func (c *Component) Send(packet Packet) error {
data, err := xml.Marshal(packet)
if err != nil {
@@ -90,6 +91,15 @@ func (c *Component) Send(packet Packet) error {
return nil
}
// SendRaw sends an XMPP stanza as a string to the server.
// It can be invalid XML or XMPP content. In that case, the server will
// disconnect the component. It is up to the user of this method to
// carefully craft the XML content to produce valid XMPP.
func (c *Component) SendRaw(packet string) error {
fmt.Fprintf(c.conn, packet) // TODO handle errors
return nil
}
// handshake generates an authentication token based on StreamID and shared secret.
func (c *Component) handshake(streamId string) string {
// 1. Concatenate the Stream ID received from the server with the shared secret.