Exemplo n.º 1
0
func (strm *Stream) handleInitiatorFeatures(sf *Features, knownFeatures []InitiatorStreamFeature) error {
	var newknownFeatures []InitiatorStreamFeature
	for i, k := range knownFeatures {
		kType := reflect.TypeOf(k)
		for _, x := range *sf {
			if kType == reflect.TypeOf(x) {
				f := x.(InitiatorStreamFeature)
				if i < len(knownFeatures)-1 {
					newknownFeatures = append(newknownFeatures, knownFeatures[i+1:]...)
				}
				if err := f.Negotate(strm); err != nil {
					return err
				}
				if f.NeedRestart() {
					if strm.logging {
						wr := logger.New(strm.Conn, strm.Conn)
						strm.decoder = xmlencoder.NewDecoder(wr)
						strm.encoder = xmlencoder.NewEncoder(wr)
					} else {
						strm.decoder = xmlencoder.NewDecoder(strm.Conn)
						strm.encoder = xmlencoder.NewEncoder(strm.Conn)
					}
					return strm.InitiatorSetup(newknownFeatures)
				} else {
					return strm.handleInitiatorFeatures(sf, newknownFeatures)
				}
			}
		}
		if k.IsMandatory(strm) {
			return errors.New("Unable to negotate mandatory feature")
		}
		newknownFeatures = append(newknownFeatures, k)
	}
	return nil
}
Exemplo n.º 2
0
func New(conn net.Conn, jid *jid.JID, content_namespace string,
	lang string, logging bool, userdata interface{}) *Stream {
	strm := Stream{
		UData:             userdata,
		Jid:               jid,
		Conn:              conn,
		lang:              lang,
		logging:           logging,
		content_namespace: content_namespace,
	}
	if strm.logging {
		wr := logger.New(conn, conn)
		strm.encoder = xmlencoder.NewEncoder(wr)
		strm.decoder = xmlencoder.NewDecoder(wr)
	} else {
		strm.encoder = xmlencoder.NewEncoder(conn)
		strm.decoder = xmlencoder.NewDecoder(conn)
	}
	return &strm
}