equal
deleted
inserted
replaced
11 "flag" |
11 "flag" |
12 "fmt" |
12 "fmt" |
13 "io" |
13 "io" |
14 "os" |
14 "os" |
15 "regexp" |
15 "regexp" |
|
16 "strings" |
16 "xml" |
17 "xml" |
17 ) |
18 ) |
18 |
19 |
19 const ( |
20 const ( |
20 // Version of RFC 3920 that we implement. |
21 // Version of RFC 3920 that we implement. |
60 Lang string |
61 Lang string |
61 text string `xml:"chardata"` |
62 text string `xml:"chardata"` |
62 } |
63 } |
63 var _ xml.Marshaler = &errText{} |
64 var _ xml.Marshaler = &errText{} |
64 |
65 |
|
66 type Unrecognized struct { |
|
67 XMLName xml.Name |
|
68 } |
|
69 |
65 func (jid *JID) String() string { |
70 func (jid *JID) String() string { |
66 result := jid.Domain |
71 result := jid.Domain |
67 if jid.Node != nil { |
72 if jid.Node != nil { |
68 result = *jid.Node + "@" + result |
73 result = *jid.Node + "@" + result |
69 } |
74 } |
104 buf.WriteString(">") |
109 buf.WriteString(">") |
105 // We never write </stream:stream> |
110 // We never write </stream:stream> |
106 return buf.Bytes(), nil |
111 return buf.Bytes(), nil |
107 } |
112 } |
108 |
113 |
|
114 func parseStream(se xml.StartElement) (*Stream, os.Error) { |
|
115 s := &Stream{} |
|
116 se = se.Copy() |
|
117 for _, attr := range se.Attr { |
|
118 switch strings.ToLower(attr.Name.Local) { |
|
119 case "to": |
|
120 s.to = attr.Value |
|
121 case "from": |
|
122 s.from = attr.Value |
|
123 case "id": |
|
124 s.id = attr.Value |
|
125 case "lang": |
|
126 s.lang = attr.Value |
|
127 case "version": |
|
128 s.version = attr.Value |
|
129 } |
|
130 } |
|
131 return s, nil |
|
132 } |
|
133 |
109 func (s *StreamError) MarshalXML() ([]byte, os.Error) { |
134 func (s *StreamError) MarshalXML() ([]byte, os.Error) { |
110 buf := bytes.NewBuffer(nil) |
135 buf := bytes.NewBuffer(nil) |
111 buf.WriteString("<stream:error>") |
136 buf.WriteString("<stream:error>") |
112 xml.Marshal(buf, s.cond) |
137 xml.Marshal(buf, s.cond) |
113 if s.text != nil { |
138 if s.text != nil { |