Skip to content

Commit 6138e9d

Browse files
committed
Harmonize newlines
Now there should be no more newlines in between any stanza and a newline after every stanza. This should not affect functionality but is looking better if stanzas are printed for debugging.
1 parent 98ff0d4 commit 6138e9d

File tree

5 files changed

+67
-67
lines changed

5 files changed

+67
-67
lines changed

xmpp.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ func (c *Client) init(o *Options) error {
436436
}
437437
clientNonce := cnonce()
438438
clientFirstMessage := "n=" + user + ",r=" + clientNonce
439-
fmt.Fprintf(c.stanzaWriter, "<auth xmlns='%s' mechanism='%s'>%s</auth>",
439+
fmt.Fprintf(c.stanzaWriter, "<auth xmlns='%s' mechanism='%s'>%s</auth>\n",
440440
nsSASL, mechanism, base64.StdEncoding.EncodeToString([]byte("n,,"+
441441
clientFirstMessage)))
442442
var sfm string
@@ -536,7 +536,7 @@ func (c *Client) init(o *Options) error {
536536
}
537537
clientFinalMessage := base64.StdEncoding.EncodeToString([]byte(clientFinalMessageBare +
538538
",p=" + base64.StdEncoding.EncodeToString(clientProof)))
539-
fmt.Fprintf(c.stanzaWriter, "<response xmlns='%s'>%s</response>", nsSASL,
539+
fmt.Fprintf(c.stanzaWriter, "<response xmlns='%s'>%s</response>\n", nsSASL,
540540
clientFinalMessage)
541541
}
542542
if mechanism == "X-OAUTH2" && o.OAuthToken != "" && o.OAuthScope != "" {
@@ -665,11 +665,11 @@ func (c *Client) init(o *Options) error {
665665

666666
if o.Session {
667667
//if server support session, open it
668-
fmt.Fprintf(c.stanzaWriter, "<iq to='%s' type='set' id='%x'><session xmlns='%s'/></iq>", xmlEscape(domain), cookie, nsSession)
668+
fmt.Fprintf(c.stanzaWriter, "<iq to='%s' type='set' id='%x'><session xmlns='%s'/></iq>\n", xmlEscape(domain), cookie, nsSession)
669669
}
670670

671671
// We're connected and can now receive and send messages.
672-
fmt.Fprintf(c.stanzaWriter, "<presence xml:lang='en'><show>%s</show><status>%s</status></presence>", o.Status, o.StatusMessage)
672+
fmt.Fprintf(c.stanzaWriter, "<presence xml:lang='en'><show>%s</show><status>%s</status></presence>\n", o.Status, o.StatusMessage)
673673

674674
return nil
675675
}
@@ -732,7 +732,7 @@ func (c *Client) startStream(o *Options, domain string) (*streamFeatures, error)
732732

733733
_, err := fmt.Fprintf(c.stanzaWriter, "<?xml version='1.0'?>"+
734734
"<stream:stream to='%s' xmlns='%s'"+
735-
" xmlns:stream='%s' version='1.0'>",
735+
" xmlns:stream='%s' version='1.0'>\n",
736736
xmlEscape(domain), nsClient, nsStream)
737737
if err != nil {
738738
return nil, err
@@ -1056,7 +1056,7 @@ func (c *Client) Send(chat Chat) (n int, err error) {
10561056
oobtext += `</x>`
10571057
}
10581058

1059-
stanza := "<message to='%s' type='%s' id='%s' xml:lang='en'>" + subtext + "<body>%s</body>" + oobtext + thdtext + "</message>"
1059+
stanza := "<message to='%s' type='%s' id='%s' xml:lang='en'>" + subtext + "<body>%s</body>" + oobtext + thdtext + "</message>\n"
10601060

10611061
return fmt.Fprintf(c.stanzaWriter, stanza,
10621062
xmlEscape(chat.Remote), xmlEscape(chat.Type), cnonce(), xmlEscape(chat.Text))
@@ -1075,17 +1075,17 @@ func (c *Client) SendOOB(chat Chat) (n int, err error) {
10751075
}
10761076
oobtext += `</x>`
10771077
}
1078-
return fmt.Fprintf(c.stanzaWriter, "<message to='%s' type='%s' id='%s' xml:lang='en'>"+oobtext+thdtext+"</message>",
1078+
return fmt.Fprintf(c.stanzaWriter, "<message to='%s' type='%s' id='%s' xml:lang='en'>"+oobtext+thdtext+"</message>\n",
10791079
xmlEscape(chat.Remote), xmlEscape(chat.Type), cnonce())
10801080
}
10811081

10821082
// SendOrg sends the original text without being wrapped in an XMPP message stanza.
10831083
func (c *Client) SendOrg(org string) (n int, err error) {
1084-
return fmt.Fprint(c.stanzaWriter, org)
1084+
return fmt.Fprint(c.stanzaWriter, org+"\n")
10851085
}
10861086

10871087
func (c *Client) SendPresence(presence Presence) (n int, err error) {
1088-
return fmt.Fprintf(c.stanzaWriter, "<presence from='%s' to='%s'/>", xmlEscape(presence.From), xmlEscape(presence.To))
1088+
return fmt.Fprintf(c.stanzaWriter, "<presence from='%s' to='%s'/>\n", xmlEscape(presence.From), xmlEscape(presence.To))
10891089
}
10901090

10911091
// SendKeepAlive sends a "whitespace keepalive" as described in chapter 4.6.1 of RFC6120.
@@ -1097,7 +1097,7 @@ func (c *Client) SendKeepAlive() (n int, err error) {
10971097
func (c *Client) SendHtml(chat Chat) (n int, err error) {
10981098
return fmt.Fprintf(c.stanzaWriter, "<message to='%s' type='%s' xml:lang='en'>"+
10991099
"<body>%s</body>"+
1100-
"<html xmlns='http://jabber.org/protocol/xhtml-im'><body xmlns='http://www.w3.org/1999/xhtml'>%s</body></html></message>",
1100+
"<html xmlns='http://jabber.org/protocol/xhtml-im'><body xmlns='http://www.w3.org/1999/xhtml'>%s</body></html></message>\n",
11011101
xmlEscape(chat.Remote), xmlEscape(chat.Type), xmlEscape(chat.Text), chat.Text)
11021102
}
11031103

xmpp_information_query.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ func (c *Client) DiscoverEntityItems(jid string) (string, error) {
3434

3535
// RawInformationQuery sends an information query request to the server.
3636
func (c *Client) RawInformationQuery(from, to, id, iqType, requestNamespace, body string) (string, error) {
37-
const xmlIQ = "<iq from='%s' to='%s' id='%s' type='%s'><query xmlns='%s'>%s</query></iq>"
37+
const xmlIQ = "<iq from='%s' to='%s' id='%s' type='%s'><query xmlns='%s'>%s</query></iq>\n"
3838
_, err := fmt.Fprintf(c.stanzaWriter, xmlIQ, xmlEscape(from), xmlEscape(to), id, iqType, requestNamespace, body)
3939
return id, err
4040
}
4141

4242
// rawInformation send a IQ request with the payload body to the server
4343
func (c *Client) RawInformation(from, to, id, iqType, body string) (string, error) {
44-
const xmlIQ = "<iq from='%s' to='%s' id='%s' type='%s'>%s</iq>"
44+
const xmlIQ = "<iq from='%s' to='%s' id='%s' type='%s'>%s</iq>\n"
4545
_, err := fmt.Fprintf(c.stanzaWriter, xmlIQ, xmlEscape(from), xmlEscape(to), id, iqType, body)
4646
return id, err
4747
}

xmpp_muc.go

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const (
2525

2626
// Send sends room topic wrapped inside an XMPP message stanza body.
2727
func (c *Client) SendTopic(chat Chat) (n int, err error) {
28-
return fmt.Fprintf(c.stanzaWriter, "<message to='%s' type='%s' xml:lang='en'>"+"<subject>%s</subject></message>",
28+
return fmt.Fprintf(c.stanzaWriter, "<message to='%s' type='%s' xml:lang='en'>"+"<subject>%s</subject></message>\n",
2929
xmlEscape(chat.Remote), xmlEscape(chat.Type), xmlEscape(chat.Text))
3030
}
3131

@@ -47,34 +47,34 @@ func (c *Client) JoinMUC(jid, nick string, history_type, history int, history_da
4747
}
4848
switch history_type {
4949
case NoHistory:
50-
return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>\n"+
51-
"<x xmlns='%s' />\n"+
52-
"</presence>",
50+
return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>"+
51+
"<x xmlns='%s' />"+
52+
"</presence>\n",
5353
xmlEscape(jid), xmlEscape(nick), nsMUC)
5454
case CharHistory:
55-
return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>\n"+
55+
return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>"+
5656
"<x xmlns='%s'>\n"+
57-
"<history maxchars='%d'/></x>\n"+
58-
"</presence>",
57+
"<history maxchars='%d'/></x>"+
58+
"</presence>\n",
5959
xmlEscape(jid), xmlEscape(nick), nsMUC, history)
6060
case StanzaHistory:
61-
return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>\n"+
62-
"<x xmlns='%s'>\n"+
63-
"<history maxstanzas='%d'/></x>\n"+
64-
"</presence>",
61+
return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>"+
62+
"<x xmlns='%s'>"+
63+
"<history maxstanzas='%d'/></x>"+
64+
"</presence>\n",
6565
xmlEscape(jid), xmlEscape(nick), nsMUC, history)
6666
case SecondsHistory:
67-
return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>\n"+
68-
"<x xmlns='%s'>\n"+
69-
"<history seconds='%d'/></x>\n"+
70-
"</presence>",
67+
return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>"+
68+
"<x xmlns='%s'>"+
69+
"<history seconds='%d'/></x>"+
70+
"</presence>\n",
7171
xmlEscape(jid), xmlEscape(nick), nsMUC, history)
7272
case SinceHistory:
7373
if history_date != nil {
74-
return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>\n"+
75-
"<x xmlns='%s'>\n"+
76-
"<history since='%s'/></x>\n"+
77-
"</presence>",
74+
return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>"+
75+
"<x xmlns='%s'>"+
76+
"<history since='%s'/></x>"+
77+
"</presence>\n",
7878
xmlEscape(jid), xmlEscape(nick), nsMUC, history_date.Format(time.RFC3339))
7979
}
8080
}
@@ -88,40 +88,40 @@ func (c *Client) JoinProtectedMUC(jid, nick string, password string, history_typ
8888
}
8989
switch history_type {
9090
case NoHistory:
91-
return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>\n"+
92-
"<x xmlns='%s'>\n"+
91+
return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>"+
92+
"<x xmlns='%s'>"+
9393
"<password>%s</password>"+
94-
"</x>\n"+
95-
"</presence>",
94+
"</x>"+
95+
"</presence>\n",
9696
xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password))
9797
case CharHistory:
98-
return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>\n"+
99-
"<x xmlns='%s'>\n"+
100-
"<password>%s</password>\n"+
101-
"<history maxchars='%d'/></x>\n"+
102-
"</presence>",
98+
return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>"+
99+
"<x xmlns='%s'>"+
100+
"<password>%s</password>"+
101+
"<history maxchars='%d'/></x>"+
102+
"</presence>\n",
103103
xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password), history)
104104
case StanzaHistory:
105-
return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>\n"+
106-
"<x xmlns='%s'>\n"+
107-
"<password>%s</password>\n"+
108-
"<history maxstanzas='%d'/></x>\n"+
109-
"</presence>",
105+
return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>"+
106+
"<x xmlns='%s'>"+
107+
"<password>%s</password>"+
108+
"<history maxstanzas='%d'/></x>"+
109+
"</presence>\n",
110110
xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password), history)
111111
case SecondsHistory:
112-
return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>\n"+
113-
"<x xmlns='%s'>\n"+
114-
"<password>%s</password>\n"+
115-
"<history seconds='%d'/></x>\n"+
116-
"</presence>",
112+
return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>"+
113+
"<x xmlns='%s'>"+
114+
"<password>%s</password>"+
115+
"<history seconds='%d'/></x>"+
116+
"</presence>\n",
117117
xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password), history)
118118
case SinceHistory:
119119
if history_date != nil {
120-
return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>\n"+
121-
"<x xmlns='%s'>\n"+
122-
"<password>%s</password>\n"+
123-
"<history since='%s'/></x>\n"+
124-
"</presence>",
120+
return fmt.Fprintf(c.stanzaWriter, "<presence to='%s/%s'>"+
121+
"<x xmlns='%s'>"+
122+
"<password>%s</password>"+
123+
"<history since='%s'/></x>"+
124+
"</presence>\n",
125125
xmlEscape(jid), xmlEscape(nick), nsMUC, xmlEscape(password), history_date.Format(time.RFC3339))
126126
}
127127
}
@@ -130,6 +130,6 @@ func (c *Client) JoinProtectedMUC(jid, nick string, password string, history_typ
130130

131131
// xep-0045 7.14
132132
func (c *Client) LeaveMUC(jid string) (n int, err error) {
133-
return fmt.Fprintf(c.stanzaWriter, "<presence from='%s' to='%s' type='unavailable' />",
133+
return fmt.Fprintf(c.stanzaWriter, "<presence from='%s' to='%s' type='unavailable' />\n",
134134
c.jid, xmlEscape(jid))
135135
}

xmpp_ping.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,23 @@ func (c *Client) PingC2S(jid, server string) error {
1111
if server == "" {
1212
server = c.domain
1313
}
14-
_, err := fmt.Fprintf(c.stanzaWriter, "<iq from='%s' to='%s' id='c2s1' type='get'>\n"+
15-
"<ping xmlns='urn:xmpp:ping'/>\n"+
16-
"</iq>",
14+
_, err := fmt.Fprintf(c.stanzaWriter, "<iq from='%s' to='%s' id='c2s1' type='get'>"+
15+
"<ping xmlns='urn:xmpp:ping'/>"+
16+
"</iq>\n",
1717
xmlEscape(jid), xmlEscape(server))
1818
return err
1919
}
2020

2121
func (c *Client) PingS2S(fromServer, toServer string) error {
22-
_, err := fmt.Fprintf(c.stanzaWriter, "<iq from='%s' to='%s' id='s2s1' type='get'>\n"+
23-
"<ping xmlns='urn:xmpp:ping'/>\n"+
24-
"</iq>",
22+
_, err := fmt.Fprintf(c.stanzaWriter, "<iq from='%s' to='%s' id='s2s1' type='get'>"+
23+
"<ping xmlns='urn:xmpp:ping'/>"+
24+
"</iq>\n",
2525
xmlEscape(fromServer), xmlEscape(toServer))
2626
return err
2727
}
2828

2929
func (c *Client) SendResultPing(id, toServer string) error {
30-
_, err := fmt.Fprintf(c.stanzaWriter, "<iq type='result' to='%s' id='%s'/>",
30+
_, err := fmt.Fprintf(c.stanzaWriter, "<iq type='result' to='%s' id='%s'/>\n",
3131
xmlEscape(toServer), xmlEscape(id))
3232
return err
3333
}

xmpp_subscription.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@ import (
55
)
66

77
func (c *Client) ApproveSubscription(jid string) {
8-
fmt.Fprintf(c.stanzaWriter, "<presence to='%s' type='subscribed'/>",
8+
fmt.Fprintf(c.stanzaWriter, "<presence to='%s' type='subscribed'/>\n",
99
xmlEscape(jid))
1010
}
1111

1212
func (c *Client) RevokeSubscription(jid string) {
13-
fmt.Fprintf(c.stanzaWriter, "<presence to='%s' type='unsubscribed'/>",
13+
fmt.Fprintf(c.stanzaWriter, "<presence to='%s' type='unsubscribed'/>\n",
1414
xmlEscape(jid))
1515
}
1616

1717
func (c *Client) RetrieveSubscription(jid string) {
18-
fmt.Fprintf(c.conn, "<presence to='%s' type='unsubscribe'/>",
18+
fmt.Fprintf(c.conn, "<presence to='%s' type='unsubscribe'/>\n",
1919
xmlEscape(jid))
2020
}
2121

2222
func (c *Client) RequestSubscription(jid string) {
23-
fmt.Fprintf(c.stanzaWriter, "<presence to='%s' type='subscribe'/>",
23+
fmt.Fprintf(c.stanzaWriter, "<presence to='%s' type='subscribe'/>\n",
2424
xmlEscape(jid))
2525
}

0 commit comments

Comments
 (0)