Esempio n. 1
0
func (self *RosterElement) Handle(request_id *iq.IQElement, stream stream.Stream) error {
	// FIXME(goxmpp): 2014-04-03: auth check, state presence check, bind etc
	var state *RosterState
	stream.State().Get(&state)

	log.Printf("Roster request received")

	ri := RosterElement{}
	ri.Ver = "1.0"
	ri.Items = append(ri.Items, RosterItemElement{
		JID:          "test@localhost",
		Name:         "Tester",
		Subscription: "both",
	})
	ri.Items[0].Groups = append(ri.Items[0].Groups, "TestGroup")

	// TODO(goxmpp): 2014-04-03: might be easier to just use original IQ?
	response_iq := iq.NewIQElement()
	response_iq.Type = "result"
	response_iq.ID = request_id.ID
	response_iq.AddElement(&ri)
	if err := stream.WriteElement(response_iq); err != nil {
		return err
	}

	return nil
}
Esempio n. 2
0
func DecodeBase64(data string, strm stream.Stream) ([]byte, error) {
	raw_data, err := base64.StdEncoding.DecodeString(data)

	if err != nil {
		log.Println("Could not decode Base64 in DigestMD5 handler:", err)
		if err := strm.WriteElement(NewFailute(mechanisms.IncorrectEncoding{})); err != nil {
			return raw_data, err
		}
	}

	return raw_data, err
}
Esempio n. 3
0
func ReadResponse(strm stream.Stream) (*ResponseElement, error) {
	el, err := strm.ReadElement()
	if err != nil {
		return nil, err
	}

	resp, ok := el.(*ResponseElement)
	if !ok {
		// Need to send meaningful error to other side
		return nil, errors.New("Wrong response received")
	}

	return resp, nil
}
Esempio n. 4
0
func swapStreamRW(strm stream.Stream, compressor Compressor) error {
	return strm.UpdateRW(
		func(srwc io.ReadWriteCloser) (io.ReadWriteCloser, error) {
			writer := compressor.GetWriter(srwc)
			reader, err := compressor.GetReader(srwc)
			if err != nil {
				log.Println("Could not create compressed reader", err)
				if err := strm.WriteElement(&SetupFailedError{}); err != nil {
					return nil, err
				}
				return nil, err
			}

			return NewCompressionReadWriter(srwc, reader, writer), nil
		})
}
Esempio n. 5
0
func (self *PrivateElement) Handle(request_id *iq.IQElement, stream stream.Stream) error {
	log.Printf("Private storage request received")

	response_iq := iq.NewIQElement()
	response_iq.Type = "error"
	response_iq.ID = request_id.ID
	if err := stream.WriteElement(response_iq); err != nil {
		return err
	}

	return nil
}