forked from chteufleur/go-xmpp
Add Ad-Hoc command
This commit is contained in:
parent
e82f10fe48
commit
e0e253ce4b
|
|
@ -0,0 +1,68 @@
|
|||
package xmpp
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
)
|
||||
|
||||
const (
|
||||
NodeAdHocCommand = "http://jabber.org/protocol/commands"
|
||||
|
||||
ActionAdHocExecute = "execute"
|
||||
ActionAdHocNext = "next"
|
||||
ActionAdHocCancel = "cancel"
|
||||
|
||||
StatusAdHocExecute = "execute"
|
||||
StatusAdHocCompleted = "completed"
|
||||
StatusAdHocCanceled = "canceled"
|
||||
|
||||
TypeAdHocForm = "form"
|
||||
TypeAdHocResult = "result"
|
||||
TypeAdHocSubmit = "submit"
|
||||
|
||||
TypeAdHocListSingle = "list-single"
|
||||
TypeAdHocListMulti = "list-multi"
|
||||
|
||||
TypeAdHocNoteInfo = "info"
|
||||
TypeAdHocNoteWarning = "warn"
|
||||
TypeAdHocNoteError = "error"
|
||||
|
||||
TypeAdHocFieldListMulti = "list-multi"
|
||||
TypeAdHocFieldListSingle = "list-single"
|
||||
TypeAdHocFieldTextSingle = "text-single"
|
||||
TypeAdHocFieldJidSingle = "jid-single"
|
||||
)
|
||||
|
||||
type AdHocCommand struct {
|
||||
XMLName xml.Name `xml:"http://jabber.org/protocol/commands command"`
|
||||
Node string `xml:"node,attr"`
|
||||
Action string `xml:"action,attr"`
|
||||
SessionId string `xml:"sessionid,attr"`
|
||||
Status string `xml:"status,attr"`
|
||||
XForm AdHocXForm `xml:"x"`
|
||||
Note AdHocNote `xml:"note,omitempty"`
|
||||
}
|
||||
|
||||
type AdHocXForm struct {
|
||||
XMLName xml.Name `xml:"jabber:x:data x"`
|
||||
Type string `xml:"type,attr"`
|
||||
Title string `xml:"title"`
|
||||
Instructions string `xml:"instructions"`
|
||||
Fields []AdHocField `xml:"field"`
|
||||
}
|
||||
|
||||
type AdHocField struct {
|
||||
Var string `xml:"var,attr"`
|
||||
Label string `xml:"label,attr"`
|
||||
Type string `xml:"type,attr"`
|
||||
Options []AdHocFieldOption `xml:"option"`
|
||||
Value string `xml:"value,omitempty"`
|
||||
}
|
||||
|
||||
type AdHocFieldOption struct {
|
||||
Value string `xml:"value"`
|
||||
}
|
||||
|
||||
type AdHocNote struct {
|
||||
Type string `xml:"type,attr"`
|
||||
Value string `xml:",innerxml"`
|
||||
}
|
||||
|
|
@ -15,3 +15,16 @@ func UUID4() string {
|
|||
uuid[8] = (uuid[8] &^ 0x40) | 0x80
|
||||
return fmt.Sprintf("%x-%x-%x-%x-%x", uuid[:4], uuid[4:6], uuid[6:8], uuid[8:10], uuid[10:])
|
||||
}
|
||||
|
||||
func SessionId() string {
|
||||
var strSize = 15
|
||||
var dictionary string
|
||||
dictionary = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
|
||||
|
||||
var bytes = make([]byte, strSize)
|
||||
rand.Read(bytes)
|
||||
for k, v := range bytes {
|
||||
bytes[k] = dictionary[v%byte(len(dictionary))]
|
||||
}
|
||||
return string(bytes)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue