-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow send raw XML #2
Comments
Do you mean Stream.[sS]end()? If so, it's not quite as simple as making send() public as the Stream instance is hidden behind the an XMPP's In and Out channels. I have no real objection to allowing a []byte stanza if it's useful. Do you have a particular use case for it? Note that it does give the application the ability to really mess up the underlying XML stream, but that's the application's fault ;). |
My need is to provide in my component a "console mode" that sends custom XML stanza read from STDIN. Very useful to dev/debug. Here the code to do that in my app: go func() {
fmt.Printf("Console = On\n")
reader := bufio.NewReader(os.Stdin)
lines := []string{}
for {
line, err := reader.ReadString('\n')
if err != nil {
fmt.Printf(err.Error())
lines = []string{}
continue
}
if line == "\n" { // empty line found, sends XML stanza !
stanza := strings.Join(lines, "")
lines = []string{}
if strings.Trim(stanza, "\n") != "" {
go stream.SendRaw([]byte(stanza))
}
} else {
lines = append(lines, line)
}
}
}() With this simple change in go-xmpp/src/xmpp/stream.go func (stream *Stream) SendRaw(b []byte) error {
return stream.send(b)
} I agree with the application's responsibility in case of invalid stanza, but hey, "With great power comes great responsibility" ! :-) |
Sorry for sitting on this for so long. I think you're right - it won't hurt to expose a method to send a complete stanza. However the current code is slightly wrong (mostly in terms of debug logging) at the moment. I'll see what I can do. Just something I noticed about the above example … a XML stream is inherently sequential and xmpp.Stream does nothing to serialise access to the stream, so starting a new goroutine for each stanza - go stream.SendRaw([]byte(stanza)) - could result in things getting mixed up. |
I see. We may change the Below a patch proposal in go-xmpp/src/xmpp/stream.go
Then i could use |
Opened issue for too long. I close it since I do not work with this library any more. |
Currently to send a stanza we can use Stanza.Send(), but it has to be a Struct to be XML encoded and sent.
I see that Stanza.send() can do the job, but it's a private method. It would be nice that it become public.
The text was updated successfully, but these errors were encountered: