stream.go
changeset 34 7b1f924c75e2
parent 33 571713f49494
child 35 569833f08780
equal deleted inserted replaced
33:571713f49494 34:7b1f924c75e2
   105 		}
   105 		}
   106 
   106 
   107 		// Allocate the appropriate structure for this token.
   107 		// Allocate the appropriate structure for this token.
   108 		var obj interface{}
   108 		var obj interface{}
   109 		switch se.Name.Space + " " + se.Name.Local {
   109 		switch se.Name.Space + " " + se.Name.Local {
   110 		case nsStream + " stream":
   110 		case NsStream + " stream":
   111 			st, err := parseStream(se)
   111 			st, err := parseStream(se)
   112 			if err != nil {
   112 			if err != nil {
   113 				log.Printf("unmarshal stream: %v",
   113 				log.Printf("unmarshal stream: %v",
   114 					err)
   114 					err)
   115 				break
   115 				break
   116 			}
   116 			}
   117 			ch <- st
   117 			ch <- st
   118 			continue
   118 			continue
   119 		case "stream error", nsStream + " error":
   119 		case "stream error", NsStream + " error":
   120 			obj = &streamError{}
   120 			obj = &streamError{}
   121 		case nsStream + " features":
   121 		case NsStream + " features":
   122 			obj = &Features{}
   122 			obj = &Features{}
   123 		case nsTLS + " proceed", nsTLS + " failure":
   123 		case NsTLS + " proceed", NsTLS + " failure":
   124 			obj = &starttls{}
   124 			obj = &starttls{}
   125 		case nsSASL + " challenge", nsSASL + " failure",
   125 		case NsSASL + " challenge", NsSASL + " failure",
   126 			nsSASL + " success":
   126 			NsSASL + " success":
   127 			obj = &auth{}
   127 			obj = &auth{}
   128 		case "jabber:client iq":
   128 		case "jabber:client iq":
   129 			obj = &Iq{}
   129 			obj = &Iq{}
   130 		case "jabber:client message":
   130 		case "jabber:client message":
   131 			obj = &Message{}
   131 			obj = &Message{}
   253 }
   253 }
   254 
   254 
   255 func (cl *Client) handleFeatures(fe *Features) {
   255 func (cl *Client) handleFeatures(fe *Features) {
   256 	cl.Features = fe
   256 	cl.Features = fe
   257 	if fe.Starttls != nil {
   257 	if fe.Starttls != nil {
   258 		start := &starttls{XMLName: xml.Name{Space: nsTLS,
   258 		start := &starttls{XMLName: xml.Name{Space: NsTLS,
   259 			Local: "starttls"}}
   259 			Local: "starttls"}}
   260 		cl.xmlOut <- start
   260 		cl.xmlOut <- start
   261 		return
   261 		return
   262 	}
   262 	}
   263 
   263 
   330 			digestMd5 = true
   330 			digestMd5 = true
   331 		}
   331 		}
   332 	}
   332 	}
   333 
   333 
   334 	if digestMd5 {
   334 	if digestMd5 {
   335 		auth := &auth{XMLName: xml.Name{Space: nsSASL, Local:
   335 		auth := &auth{XMLName: xml.Name{Space: NsSASL, Local:
   336 				"auth"}, Mechanism: "DIGEST-MD5"}
   336 				"auth"}, Mechanism: "DIGEST-MD5"}
   337 		cl.xmlOut <- auth
   337 		cl.xmlOut <- auth
   338 	}
   338 	}
   339 }
   339 }
   340 
   340 
   432 	}
   432 	}
   433 
   433 
   434 	// Encode the map and send it.
   434 	// Encode the map and send it.
   435 	clStr := packSasl(clMap)
   435 	clStr := packSasl(clMap)
   436 	b64 := base64.StdEncoding
   436 	b64 := base64.StdEncoding
   437 	clObj := &auth{XMLName: xml.Name{Space: nsSASL, Local:
   437 	clObj := &auth{XMLName: xml.Name{Space: NsSASL, Local:
   438 			"response"}, Chardata:
   438 			"response"}, Chardata:
   439 		b64.EncodeToString([]byte(clStr))}
   439 		b64.EncodeToString([]byte(clStr))}
   440 	cl.xmlOut <- clObj
   440 	cl.xmlOut <- clObj
   441 }
   441 }
   442 
   442 
   443 func (cl *Client) saslDigest2(srvMap map[string] string) {
   443 func (cl *Client) saslDigest2(srvMap map[string] string) {
   444 	if cl.saslExpected == srvMap["rspauth"] {
   444 	if cl.saslExpected == srvMap["rspauth"] {
   445 		clObj := &auth{XMLName: xml.Name{Space: nsSASL, Local:
   445 		clObj := &auth{XMLName: xml.Name{Space: NsSASL, Local:
   446 				"response"}}
   446 				"response"}}
   447 		cl.xmlOut <- clObj
   447 		cl.xmlOut <- clObj
   448 	} else {
   448 	} else {
   449 		clObj := &auth{XMLName: xml.Name{Space: nsSASL, Local:
   449 		clObj := &auth{XMLName: xml.Name{Space: NsSASL, Local:
   450 				"failure"}, Any:
   450 				"failure"}, Any:
   451 			&Generic{XMLName: xml.Name{Space: nsSASL,
   451 			&Generic{XMLName: xml.Name{Space: NsSASL,
   452 				Local: "abort"}}}
   452 				Local: "abort"}}}
   453 		cl.xmlOut <- clObj
   453 		cl.xmlOut <- clObj
   454 	}
   454 	}
   455 }
   455 }
   456 
   456 
   506 
   506 
   507 // Send a request to bind a resource. RFC 3920, section 7.
   507 // Send a request to bind a resource. RFC 3920, section 7.
   508 func (cl *Client) bind(bind *Generic) {
   508 func (cl *Client) bind(bind *Generic) {
   509 	res := cl.Jid.Resource
   509 	res := cl.Jid.Resource
   510 	msg := &Iq{Type: "set", Id: <- cl.Id, Any:
   510 	msg := &Iq{Type: "set", Id: <- cl.Id, Any:
   511 		&Generic{XMLName: xml.Name{Space: nsBind, Local:
   511 		&Generic{XMLName: xml.Name{Space: NsBind, Local:
   512 					"bind"}}}
   512 					"bind"}}}
   513 	if res != "" {
   513 	if res != "" {
   514 		msg.Any.Any = &Generic{XMLName: xml.Name{Local:
   514 		msg.Any.Any = &Generic{XMLName: xml.Name{Local:
   515 				"resource"}, Chardata: res}
   515 				"resource"}, Chardata: res}
   516 	}
   516 	}