示例#1
0
文件: bot.go 项目: oxpa/bullxmpp
func main() {
	loadConfig()
	cli, err := client.New(*myjid, *password, "ru", true, true)
	checkError(err)
	xmlencoder.UseExtension(iqversion.NS)
	for {
		p, err := cli.Read()
		checkError(err)
		if p == nil {
			break
		}
		switch p := p.(type) {
		case *client.Iq:
			if _, ok := p.Payload.(*iqversion.Version); ok {
				if p.Type != nil && *p.Type == client.IqTypeGet {
					version := iqversion.New("bull", "0.0001", "Linux")
					typ := client.IqTypeResult
					iq := client.Iq{To: p.From, Id: p.Id, Payload: version, Type: &typ}
					err := cli.Send(&iq)
					checkError(err)
				}
			}
		}
	}
}
示例#2
0
文件: client.go 项目: oxpa/bullxmpp
func NewWithJID(jid_ *jid.JID, password, lang string, secure bool, logging bool) (cli *Client, err error) {
	host, err := jid_.GetIDN()
	if err != nil {
		return
	}
	conn, err := Dial(host)
	if err != nil {
		return
	}

	xmlencoder.UseExtension(stream.NS)
	xmlencoder.UseExtension(starttls.NS)
	xmlencoder.UseExtension(sasl.NS)
	xmlencoder.UseExtension(bind.NS)
	xmlencoder.UseExtension(session.NS)
	xmlencoder.UseExtension(NS)
	xmlencoder.ReplaceExtensionStruct(xml.Name{starttls.NS, "starttls"}, TLSFeature{})
	xmlencoder.ReplaceExtensionStruct(xml.Name{sasl.NS, "mechanisms"}, SASLFeature{})
	xmlencoder.ReplaceExtensionStruct(xml.Name{bind.NS, "bind"}, BindFeature{})
	xmlencoder.ReplaceExtensionStruct(xml.Name{session.NS, "session"}, SessionFeature{})

	var options Options
	options.tlsUse = TLSDisabled
	if secure {
		options.tlsUse = TLSEnabled
	}
	options.password = password
	var knownFeatures []stream.InitiatorStreamFeature
	knownFeatures = append(knownFeatures, &TLSFeature{})
	knownFeatures = append(knownFeatures, &SASLFeature{})
	knownFeatures = append(knownFeatures, &BindFeature{})
	knownFeatures = append(knownFeatures, &SessionFeature{})

	strm := stream.New(conn, jid_, ns_client, lang, logging, options)
	cli = &Client{strm, 0}
	if err = cli.InitiatorSetup(knownFeatures); err != nil {
		return
	}
	return
}