stream.go
changeset 111 36287f2cf06e
parent 110 7696e6a01709
child 112 bd56fb741f69
equal deleted inserted replaced
110:7696e6a01709 111:36287f2cf06e
   146 		}
   146 		}
   147 
   147 
   148 		// If it's a Stanza, we try to unmarshal its innerxml
   148 		// If it's a Stanza, we try to unmarshal its innerxml
   149 		// into objects of the appropriate respective
   149 		// into objects of the appropriate respective
   150 		// types. This is specified by our extensions.
   150 		// types. This is specified by our extensions.
   151 		if st := getStanza(obj) ; st != nil {
   151 		if st, ok := obj.(Stanzer) ; ok {
   152 			err = parseExtended(st, extStanza)
   152 			err = parseExtended(st.GetHeader(), extStanza)
   153 			if err != nil {
   153 			if err != nil {
   154 				Warn.Logf("ext unmarshal: %s", err)
   154 				Warn.Logf("ext unmarshal: %s", err)
   155 				break Loop
   155 				break Loop
   156 			}
   156 			}
   157 		}
   157 		}
   159 		// Put it on the channel.
   159 		// Put it on the channel.
   160 		ch <- obj
   160 		ch <- obj
   161 	}
   161 	}
   162 }
   162 }
   163 
   163 
   164 func parseExtended(st *Stanza, extStanza map[string]func(*xml.Name) interface{}) error {
   164 func parseExtended(st *Header, extStanza map[string]func(*xml.Name) interface{}) error {
   165 	// Now parse the stanza's innerxml to find the string that we
   165 	// Now parse the stanza's innerxml to find the string that we
   166 	// can unmarshal this nested element from.
   166 	// can unmarshal this nested element from.
   167 	reader := strings.NewReader(st.Innerxml)
   167 	reader := strings.NewReader(st.Innerxml)
   168 	p := xml.NewDecoder(reader)
   168 	p := xml.NewDecoder(reader)
   169 	for {
   169 	for {
   236 			handlers[h.id] = h.f
   236 			handlers[h.id] = h.f
   237 		case x, ok := <-srvIn:
   237 		case x, ok := <-srvIn:
   238 			if !ok {
   238 			if !ok {
   239 				break Loop
   239 				break Loop
   240 			}
   240 			}
   241 			var st *Stanza
   241 			var st *Header
   242 			switch obj := x.(type) {
   242 			switch obj := x.(type) {
   243 			case *stream:
   243 			case *stream:
   244 				handleStream(obj)
   244 				handleStream(obj)
   245 			case *streamError:
   245 			case *streamError:
   246 				cl.handleStreamError(obj)
   246 				cl.handleStreamError(obj)
   248 				cl.handleFeatures(obj)
   248 				cl.handleFeatures(obj)
   249 			case *starttls:
   249 			case *starttls:
   250 				cl.handleTls(obj)
   250 				cl.handleTls(obj)
   251 			case *auth:
   251 			case *auth:
   252 				cl.handleSasl(obj)
   252 				cl.handleSasl(obj)
   253 			case *Iq, *Message, *Presence:
   253 			case Stanzer:
   254 				st = getStanza(obj)
   254 				st = obj.GetHeader()
   255 			default:
   255 			default:
   256 				Warn.Logf("Unhandled non-stanza: %T %#v", x, x)
   256 				Warn.Logf("Unhandled non-stanza: %T %#v", x, x)
   257 			}
   257 			}
   258 
   258 
   259 			if st == nil {
   259 			if st == nil {
   594 	res := cl.Jid.Resource
   594 	res := cl.Jid.Resource
   595 	bindReq := &bindIq{}
   595 	bindReq := &bindIq{}
   596 	if res != "" {
   596 	if res != "" {
   597 		bindReq.Resource = &res
   597 		bindReq.Resource = &res
   598 	}
   598 	}
   599 	msg := &Iq{Stanza: Stanza{Type: "set", Id: <-Id,
   599 	msg := &Iq{Header: Header{Type: "set", Id: <-Id,
   600 		Nested: []interface{}{bindReq}}}
   600 		Nested: []interface{}{bindReq}}}
   601 	f := func(st interface{}) bool {
   601 	f := func(st interface{}) bool {
   602 		iq, ok := st.(*Iq)
   602 		iq, ok := st.(*Iq)
   603 		if !ok {
   603 		if !ok {
   604 			Warn.Log("non-iq response")
   604 			Warn.Log("non-iq response")