stream.go
changeset 116 5c6d6d51d3ba
parent 114 a058e33c1666
child 118 fb9bb98a8d70
equal deleted inserted replaced
115:7c45fc3f524a 116:5c6d6d51d3ba
    77 		}
    77 		}
    78 	}
    78 	}
    79 }
    79 }
    80 
    80 
    81 func readXml(r io.Reader, ch chan<- interface{},
    81 func readXml(r io.Reader, ch chan<- interface{},
    82 extStanza map[string]func(*xml.Name) interface{}) {
    82 	extStanza map[string]func(*xml.Name) interface{}) {
    83 	if _, ok := Debug.(*noLog) ; !ok {
    83 	if _, ok := Debug.(*noLog); !ok {
    84 		pr, pw := io.Pipe()
    84 		pr, pw := io.Pipe()
    85 		go tee(r, pw, "S: ")
    85 		go tee(r, pw, "S: ")
    86 		r = pr
    86 		r = pr
    87 	}
    87 	}
    88 	defer close(ch)
    88 	defer close(ch)
   150 		}
   150 		}
   151 
   151 
   152 		// If it's a Stanza, we try to unmarshal its innerxml
   152 		// If it's a Stanza, we try to unmarshal its innerxml
   153 		// into objects of the appropriate respective
   153 		// into objects of the appropriate respective
   154 		// types. This is specified by our extensions.
   154 		// types. This is specified by our extensions.
   155 		if st, ok := obj.(Stanza) ; ok {
   155 		if st, ok := obj.(Stanza); ok {
   156 			err = parseExtended(st.GetHeader(), extStanza)
   156 			err = parseExtended(st.GetHeader(), extStanza)
   157 			if err != nil {
   157 			if err != nil {
   158 				Warn.Logf("ext unmarshal: %s", err)
   158 				Warn.Logf("ext unmarshal: %s", err)
   159 				break Loop
   159 				break Loop
   160 			}
   160 			}
   196 
   196 
   197 	return nil
   197 	return nil
   198 }
   198 }
   199 
   199 
   200 func writeXml(w io.Writer, ch <-chan interface{}) {
   200 func writeXml(w io.Writer, ch <-chan interface{}) {
   201 	if _, ok := Debug.(*noLog) ; !ok {
   201 	if _, ok := Debug.(*noLog); !ok {
   202 		pr, pw := io.Pipe()
   202 		pr, pw := io.Pipe()
   203 		go tee(pr, w, "C: ")
   203 		go tee(pr, w, "C: ")
   204 		w = pw
   204 		w = pw
   205 	}
   205 	}
   206 	defer func(w io.Writer) {
   206 	defer func(w io.Writer) {
   272 // This loop is paused until resource binding is complete. Otherwise
   272 // This loop is paused until resource binding is complete. Otherwise
   273 // the app might inject something inappropriate into our negotiations
   273 // the app might inject something inappropriate into our negotiations
   274 // with the server. The control channel controls this loop's
   274 // with the server. The control channel controls this loop's
   275 // activity.
   275 // activity.
   276 func writeStream(srvOut chan<- interface{}, cliIn <-chan Stanza,
   276 func writeStream(srvOut chan<- interface{}, cliIn <-chan Stanza,
   277 control <-chan int) {
   277 	control <-chan int) {
   278 	defer close(srvOut)
   278 	defer close(srvOut)
   279 
   279 
   280 	var input <-chan Stanza
   280 	var input <-chan Stanza
   281 Loop:
   281 Loop:
   282 	for {
   282 	for {
   304 }
   304 }
   305 
   305 
   306 // Stanzas from the remote go up through a stack of filters to the
   306 // Stanzas from the remote go up through a stack of filters to the
   307 // app. This function manages the filters.
   307 // app. This function manages the filters.
   308 func filterTop(filterOut <-chan <-chan Stanza, filterIn chan<- <-chan Stanza,
   308 func filterTop(filterOut <-chan <-chan Stanza, filterIn chan<- <-chan Stanza,
   309 topFilter <-chan Stanza, app chan<- Stanza) {
   309 	topFilter <-chan Stanza, app chan<- Stanza) {
   310 	defer close(app)
   310 	defer close(app)
   311 Loop:
   311 Loop:
   312 	for {
   312 	for {
   313 		select {
   313 		select {
   314 		case newFilterOut := <-filterOut:
   314 		case newFilterOut := <-filterOut:
   561 	return strings.Join(terms, ",")
   561 	return strings.Join(terms, ",")
   562 }
   562 }
   563 
   563 
   564 // Computes the response string for digest authentication.
   564 // Computes the response string for digest authentication.
   565 func saslDigestResponse(username, realm, passwd, nonce, cnonceStr,
   565 func saslDigestResponse(username, realm, passwd, nonce, cnonceStr,
   566 authenticate, digestUri, nonceCountStr string) string {
   566 	authenticate, digestUri, nonceCountStr string) string {
   567 	h := func(text string) []byte {
   567 	h := func(text string) []byte {
   568 		h := md5.New()
   568 		h := md5.New()
   569 		h.Write([]byte(text))
   569 		h.Write([]byte(text))
   570 		return h.Sum(nil)
   570 		return h.Sum(nil)
   571 	}
   571 	}