2012-05-11 02:06:22 +02:00
|
|
|
// Package xselinux is the X client API for the SELinux extension.
|
2012-05-10 23:01:42 +02:00
|
|
|
package xselinux
|
|
|
|
|
|
|
|
/*
|
2012-05-12 05:58:52 +02:00
|
|
|
This file was generated by xselinux.xml on May 11 2012 11:57:20pm EDT.
|
2012-05-10 23:01:42 +02:00
|
|
|
This file is automatically generated. Edit at your peril!
|
|
|
|
*/
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/BurntSushi/xgb"
|
|
|
|
|
|
|
|
"github.com/BurntSushi/xgb/xproto"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Init must be called before using the SELinux extension.
|
|
|
|
func Init(c *xgb.Conn) error {
|
|
|
|
reply, err := xproto.QueryExtension(c, 7, "SELinux").Reply()
|
|
|
|
switch {
|
|
|
|
case err != nil:
|
|
|
|
return err
|
|
|
|
case !reply.Present:
|
|
|
|
return xgb.Errorf("No extension named SELinux could be found on on the server.")
|
|
|
|
}
|
|
|
|
|
|
|
|
xgb.ExtLock.Lock()
|
|
|
|
c.Extensions["SELinux"] = reply.MajorOpcode
|
|
|
|
for evNum, fun := range xgb.NewExtEventFuncs["SELinux"] {
|
|
|
|
xgb.NewEventFuncs[int(reply.FirstEvent)+evNum] = fun
|
|
|
|
}
|
|
|
|
for errNum, fun := range xgb.NewExtErrorFuncs["SELinux"] {
|
|
|
|
xgb.NewErrorFuncs[int(reply.FirstError)+errNum] = fun
|
|
|
|
}
|
|
|
|
xgb.ExtLock.Unlock()
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
xgb.NewExtEventFuncs["SELinux"] = make(map[int]xgb.NewEventFun)
|
|
|
|
xgb.NewExtErrorFuncs["SELinux"] = make(map[int]xgb.NewErrorFun)
|
|
|
|
}
|
|
|
|
|
2012-05-12 05:58:52 +02:00
|
|
|
// Skipping definition for base type 'Int32'
|
|
|
|
|
|
|
|
// Skipping definition for base type 'Void'
|
|
|
|
|
|
|
|
// Skipping definition for base type 'Byte'
|
|
|
|
|
|
|
|
// Skipping definition for base type 'Int8'
|
|
|
|
|
2012-05-10 23:01:42 +02:00
|
|
|
// Skipping definition for base type 'Card16'
|
|
|
|
|
|
|
|
// Skipping definition for base type 'Char'
|
|
|
|
|
|
|
|
// Skipping definition for base type 'Card32'
|
|
|
|
|
|
|
|
// Skipping definition for base type 'Double'
|
|
|
|
|
|
|
|
// Skipping definition for base type 'Bool'
|
|
|
|
|
|
|
|
// Skipping definition for base type 'Float'
|
|
|
|
|
|
|
|
// Skipping definition for base type 'Card8'
|
|
|
|
|
2012-05-11 02:06:22 +02:00
|
|
|
// Skipping definition for base type 'Int16'
|
|
|
|
|
2012-05-10 23:01:42 +02:00
|
|
|
type ListItem struct {
|
|
|
|
Name xproto.Atom
|
|
|
|
ObjectContextLen uint32
|
|
|
|
DataContextLen uint32
|
|
|
|
ObjectContext string // size: xgb.Pad((int(ObjectContextLen) * 1))
|
|
|
|
DataContext string // size: xgb.Pad((int(DataContextLen) * 1))
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// ListItemRead reads a byte slice into a ListItem value.
|
2012-05-10 23:01:42 +02:00
|
|
|
func ListItemRead(buf []byte, v *ListItem) int {
|
|
|
|
b := 0
|
|
|
|
|
|
|
|
v.Name = xproto.Atom(xgb.Get32(buf[b:]))
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
v.ObjectContextLen = xgb.Get32(buf[b:])
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
v.DataContextLen = xgb.Get32(buf[b:])
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
{
|
|
|
|
byteString := make([]byte, v.ObjectContextLen)
|
|
|
|
copy(byteString[:v.ObjectContextLen], buf[b:])
|
|
|
|
v.ObjectContext = string(byteString)
|
|
|
|
b += xgb.Pad(int(v.ObjectContextLen))
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
byteString := make([]byte, v.DataContextLen)
|
|
|
|
copy(byteString[:v.DataContextLen], buf[b:])
|
|
|
|
v.DataContext = string(byteString)
|
|
|
|
b += xgb.Pad(int(v.DataContextLen))
|
|
|
|
}
|
|
|
|
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// ListItemReadList reads a byte slice into a list of ListItem values.
|
2012-05-10 23:01:42 +02:00
|
|
|
func ListItemReadList(buf []byte, dest []ListItem) int {
|
|
|
|
b := 0
|
|
|
|
for i := 0; i < len(dest); i++ {
|
|
|
|
dest[i] = ListItem{}
|
|
|
|
b += ListItemRead(buf[b:], &dest[i])
|
|
|
|
}
|
|
|
|
return xgb.Pad(b)
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// Bytes writes a ListItem value to a byte slice.
|
2012-05-10 23:01:42 +02:00
|
|
|
func (v ListItem) Bytes() []byte {
|
|
|
|
buf := make([]byte, ((12 + xgb.Pad((int(v.ObjectContextLen) * 1))) + xgb.Pad((int(v.DataContextLen) * 1))))
|
|
|
|
b := 0
|
|
|
|
|
|
|
|
xgb.Put32(buf[b:], uint32(v.Name))
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
xgb.Put32(buf[b:], v.ObjectContextLen)
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
xgb.Put32(buf[b:], v.DataContextLen)
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
copy(buf[b:], v.ObjectContext[:v.ObjectContextLen])
|
|
|
|
b += xgb.Pad(int(v.ObjectContextLen))
|
|
|
|
|
|
|
|
copy(buf[b:], v.DataContext[:v.DataContextLen])
|
|
|
|
b += xgb.Pad(int(v.DataContextLen))
|
|
|
|
|
|
|
|
return buf
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// ListItemListBytes writes a list of %s(MISSING) values to a byte slice.
|
2012-05-10 23:01:42 +02:00
|
|
|
func ListItemListBytes(buf []byte, list []ListItem) int {
|
|
|
|
b := 0
|
|
|
|
var structBytes []byte
|
|
|
|
for _, item := range list {
|
|
|
|
structBytes = item.Bytes()
|
|
|
|
copy(buf[b:], structBytes)
|
|
|
|
b += xgb.Pad(len(structBytes))
|
|
|
|
}
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// ListItemListSize computes the size (bytes) of a list of ListItem values.
|
2012-05-10 23:01:42 +02:00
|
|
|
func ListItemListSize(list []ListItem) int {
|
|
|
|
size := 0
|
|
|
|
for _, item := range list {
|
|
|
|
size += ((12 + xgb.Pad((int(item.ObjectContextLen) * 1))) + xgb.Pad((int(item.DataContextLen) * 1)))
|
|
|
|
}
|
|
|
|
return size
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// QueryVersionCookie is a cookie used only for QueryVersion requests.
|
2012-05-10 23:01:42 +02:00
|
|
|
type QueryVersionCookie struct {
|
|
|
|
*xgb.Cookie
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// QueryVersion sends a checked request.
|
|
|
|
// If an error occurs, it will be returned with the reply by calling QueryVersionCookie.Reply()
|
2012-05-10 23:01:42 +02:00
|
|
|
func QueryVersion(c *xgb.Conn, ClientMajor byte, ClientMinor byte) QueryVersionCookie {
|
2012-05-12 05:58:52 +02:00
|
|
|
if _, ok := c.Extensions["SELINUX"]; !ok {
|
|
|
|
panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.")
|
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(true, true)
|
|
|
|
c.NewRequest(queryVersionRequest(c, ClientMajor, ClientMinor), cookie)
|
|
|
|
return QueryVersionCookie{cookie}
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// QueryVersionUnchecked sends an unchecked request.
|
|
|
|
// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
|
2012-05-10 23:01:42 +02:00
|
|
|
func QueryVersionUnchecked(c *xgb.Conn, ClientMajor byte, ClientMinor byte) QueryVersionCookie {
|
2012-05-12 05:58:52 +02:00
|
|
|
if _, ok := c.Extensions["SELINUX"]; !ok {
|
|
|
|
panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.")
|
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(false, true)
|
|
|
|
c.NewRequest(queryVersionRequest(c, ClientMajor, ClientMinor), cookie)
|
|
|
|
return QueryVersionCookie{cookie}
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// QueryVersionReply represents the data returned from a QueryVersion request.
|
2012-05-10 23:01:42 +02:00
|
|
|
type QueryVersionReply struct {
|
2012-05-11 05:57:34 +02:00
|
|
|
Sequence uint16 // sequence number of the request for this reply
|
|
|
|
Length uint32 // number of bytes in this reply
|
2012-05-10 23:01:42 +02:00
|
|
|
// padding: 1 bytes
|
|
|
|
ServerMajor uint16
|
|
|
|
ServerMinor uint16
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// Reply blocks and returns the reply data for a QueryVersion request.
|
2012-05-10 23:01:42 +02:00
|
|
|
func (cook QueryVersionCookie) Reply() (*QueryVersionReply, error) {
|
|
|
|
buf, err := cook.Cookie.Reply()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if buf == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
return queryVersionReply(buf), nil
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// queryVersionReply reads a byte slice into a QueryVersionReply value.
|
2012-05-10 23:01:42 +02:00
|
|
|
func queryVersionReply(buf []byte) *QueryVersionReply {
|
|
|
|
v := new(QueryVersionReply)
|
|
|
|
b := 1 // skip reply determinant
|
|
|
|
|
|
|
|
b += 1 // padding
|
|
|
|
|
|
|
|
v.Sequence = xgb.Get16(buf[b:])
|
|
|
|
b += 2
|
|
|
|
|
|
|
|
v.Length = xgb.Get32(buf[b:]) // 4-byte units
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
v.ServerMajor = xgb.Get16(buf[b:])
|
|
|
|
b += 2
|
|
|
|
|
|
|
|
v.ServerMinor = xgb.Get16(buf[b:])
|
|
|
|
b += 2
|
|
|
|
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write request to wire for QueryVersion
|
2012-05-11 05:57:34 +02:00
|
|
|
// queryVersionRequest writes a QueryVersion request to a byte slice.
|
2012-05-10 23:01:42 +02:00
|
|
|
func queryVersionRequest(c *xgb.Conn, ClientMajor byte, ClientMinor byte) []byte {
|
|
|
|
size := 8
|
|
|
|
b := 0
|
|
|
|
buf := make([]byte, size)
|
|
|
|
|
|
|
|
buf[b] = c.Extensions["SELINUX"]
|
|
|
|
b += 1
|
|
|
|
|
|
|
|
buf[b] = 0 // request opcode
|
|
|
|
b += 1
|
|
|
|
|
|
|
|
xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
|
|
|
|
b += 2
|
|
|
|
|
|
|
|
buf[b] = ClientMajor
|
|
|
|
b += 1
|
|
|
|
|
|
|
|
buf[b] = ClientMinor
|
|
|
|
b += 1
|
|
|
|
|
|
|
|
return buf
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// SetDeviceCreateContextCookie is a cookie used only for SetDeviceCreateContext requests.
|
2012-05-10 23:01:42 +02:00
|
|
|
type SetDeviceCreateContextCookie struct {
|
|
|
|
*xgb.Cookie
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// SetDeviceCreateContext sends an unchecked request.
|
|
|
|
// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
|
2012-05-10 23:01:42 +02:00
|
|
|
func SetDeviceCreateContext(c *xgb.Conn, ContextLen uint32, Context string) SetDeviceCreateContextCookie {
|
2012-05-12 05:58:52 +02:00
|
|
|
if _, ok := c.Extensions["SELINUX"]; !ok {
|
|
|
|
panic("Cannot issue request 'SetDeviceCreateContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.")
|
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(false, false)
|
|
|
|
c.NewRequest(setDeviceCreateContextRequest(c, ContextLen, Context), cookie)
|
|
|
|
return SetDeviceCreateContextCookie{cookie}
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// SetDeviceCreateContextChecked sends a checked request.
|
|
|
|
// If an error occurs, it can be retrieved using SetDeviceCreateContextCookie.Check()
|
2012-05-10 23:01:42 +02:00
|
|
|
func SetDeviceCreateContextChecked(c *xgb.Conn, ContextLen uint32, Context string) SetDeviceCreateContextCookie {
|
2012-05-12 05:58:52 +02:00
|
|
|
if _, ok := c.Extensions["SELINUX"]; !ok {
|
|
|
|
panic("Cannot issue request 'SetDeviceCreateContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.")
|
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(true, false)
|
|
|
|
c.NewRequest(setDeviceCreateContextRequest(c, ContextLen, Context), cookie)
|
|
|
|
return SetDeviceCreateContextCookie{cookie}
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// Check returns an error if one occurred for checked requests that are not expecting a reply.
|
|
|
|
// This cannot be called for requests expecting a reply, nor for unchecked requests.
|
2012-05-10 23:01:42 +02:00
|
|
|
func (cook SetDeviceCreateContextCookie) Check() error {
|
|
|
|
return cook.Cookie.Check()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write request to wire for SetDeviceCreateContext
|
2012-05-11 05:57:34 +02:00
|
|
|
// setDeviceCreateContextRequest writes a SetDeviceCreateContext request to a byte slice.
|
2012-05-10 23:01:42 +02:00
|
|
|
func setDeviceCreateContextRequest(c *xgb.Conn, ContextLen uint32, Context string) []byte {
|
|
|
|
size := xgb.Pad((8 + xgb.Pad((int(ContextLen) * 1))))
|
|
|
|
b := 0
|
|
|
|
buf := make([]byte, size)
|
|
|
|
|
|
|
|
buf[b] = c.Extensions["SELINUX"]
|
|
|
|
b += 1
|
|
|
|
|
|
|
|
buf[b] = 1 // request opcode
|
|
|
|
b += 1
|
|
|
|
|
|
|
|
xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
|
|
|
|
b += 2
|
|
|
|
|
|
|
|
xgb.Put32(buf[b:], ContextLen)
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
copy(buf[b:], Context[:ContextLen])
|
|
|
|
b += xgb.Pad(int(ContextLen))
|
|
|
|
|
|
|
|
return buf
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// GetDeviceCreateContextCookie is a cookie used only for GetDeviceCreateContext requests.
|
2012-05-10 23:01:42 +02:00
|
|
|
type GetDeviceCreateContextCookie struct {
|
|
|
|
*xgb.Cookie
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// GetDeviceCreateContext sends a checked request.
|
|
|
|
// If an error occurs, it will be returned with the reply by calling GetDeviceCreateContextCookie.Reply()
|
2012-05-10 23:01:42 +02:00
|
|
|
func GetDeviceCreateContext(c *xgb.Conn) GetDeviceCreateContextCookie {
|
2012-05-12 05:58:52 +02:00
|
|
|
if _, ok := c.Extensions["SELINUX"]; !ok {
|
|
|
|
panic("Cannot issue request 'GetDeviceCreateContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.")
|
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(true, true)
|
|
|
|
c.NewRequest(getDeviceCreateContextRequest(c), cookie)
|
|
|
|
return GetDeviceCreateContextCookie{cookie}
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// GetDeviceCreateContextUnchecked sends an unchecked request.
|
|
|
|
// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
|
2012-05-10 23:01:42 +02:00
|
|
|
func GetDeviceCreateContextUnchecked(c *xgb.Conn) GetDeviceCreateContextCookie {
|
2012-05-12 05:58:52 +02:00
|
|
|
if _, ok := c.Extensions["SELINUX"]; !ok {
|
|
|
|
panic("Cannot issue request 'GetDeviceCreateContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.")
|
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(false, true)
|
|
|
|
c.NewRequest(getDeviceCreateContextRequest(c), cookie)
|
|
|
|
return GetDeviceCreateContextCookie{cookie}
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// GetDeviceCreateContextReply represents the data returned from a GetDeviceCreateContext request.
|
2012-05-10 23:01:42 +02:00
|
|
|
type GetDeviceCreateContextReply struct {
|
2012-05-11 05:57:34 +02:00
|
|
|
Sequence uint16 // sequence number of the request for this reply
|
|
|
|
Length uint32 // number of bytes in this reply
|
2012-05-10 23:01:42 +02:00
|
|
|
// padding: 1 bytes
|
|
|
|
ContextLen uint32
|
|
|
|
// padding: 20 bytes
|
|
|
|
Context string // size: xgb.Pad((int(ContextLen) * 1))
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// Reply blocks and returns the reply data for a GetDeviceCreateContext request.
|
2012-05-10 23:01:42 +02:00
|
|
|
func (cook GetDeviceCreateContextCookie) Reply() (*GetDeviceCreateContextReply, error) {
|
|
|
|
buf, err := cook.Cookie.Reply()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if buf == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
return getDeviceCreateContextReply(buf), nil
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// getDeviceCreateContextReply reads a byte slice into a GetDeviceCreateContextReply value.
|
2012-05-10 23:01:42 +02:00
|
|
|
func getDeviceCreateContextReply(buf []byte) *GetDeviceCreateContextReply {
|
|
|
|
v := new(GetDeviceCreateContextReply)
|
|
|
|
b := 1 // skip reply determinant
|
|
|
|
|
|
|
|
b += 1 // padding
|
|
|
|
|
|
|
|
v.Sequence = xgb.Get16(buf[b:])
|
|
|
|
b += 2
|
|
|
|
|
|
|
|
v.Length = xgb.Get32(buf[b:]) // 4-byte units
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
v.ContextLen = xgb.Get32(buf[b:])
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
b += 20 // padding
|
|
|
|
|
|
|
|
{
|
|
|
|
byteString := make([]byte, v.ContextLen)
|
|
|
|
copy(byteString[:v.ContextLen], buf[b:])
|
|
|
|
v.Context = string(byteString)
|
|
|
|
b += xgb.Pad(int(v.ContextLen))
|
|
|
|
}
|
|
|
|
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write request to wire for GetDeviceCreateContext
|
2012-05-11 05:57:34 +02:00
|
|
|
// getDeviceCreateContextRequest writes a GetDeviceCreateContext request to a byte slice.
|
2012-05-10 23:01:42 +02:00
|
|
|
func getDeviceCreateContextRequest(c *xgb.Conn) []byte {
|
|
|
|
size := 4
|
|
|
|
b := 0
|
|
|
|
buf := make([]byte, size)
|
|
|
|
|
|
|
|
buf[b] = c.Extensions["SELINUX"]
|
|
|
|
b += 1
|
|
|
|
|
|
|
|
buf[b] = 2 // request opcode
|
|
|
|
b += 1
|
|
|
|
|
|
|
|
xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
|
|
|
|
b += 2
|
|
|
|
|
|
|
|
return buf
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// SetDeviceContextCookie is a cookie used only for SetDeviceContext requests.
|
2012-05-10 23:01:42 +02:00
|
|
|
type SetDeviceContextCookie struct {
|
|
|
|
*xgb.Cookie
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// SetDeviceContext sends an unchecked request.
|
|
|
|
// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
|
2012-05-10 23:01:42 +02:00
|
|
|
func SetDeviceContext(c *xgb.Conn, Device uint32, ContextLen uint32, Context string) SetDeviceContextCookie {
|
2012-05-12 05:58:52 +02:00
|
|
|
if _, ok := c.Extensions["SELINUX"]; !ok {
|
|
|
|
panic("Cannot issue request 'SetDeviceContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.")
|
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(false, false)
|
|
|
|
c.NewRequest(setDeviceContextRequest(c, Device, ContextLen, Context), cookie)
|
|
|
|
return SetDeviceContextCookie{cookie}
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// SetDeviceContextChecked sends a checked request.
|
|
|
|
// If an error occurs, it can be retrieved using SetDeviceContextCookie.Check()
|
2012-05-10 23:01:42 +02:00
|
|
|
func SetDeviceContextChecked(c *xgb.Conn, Device uint32, ContextLen uint32, Context string) SetDeviceContextCookie {
|
2012-05-12 05:58:52 +02:00
|
|
|
if _, ok := c.Extensions["SELINUX"]; !ok {
|
|
|
|
panic("Cannot issue request 'SetDeviceContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.")
|
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(true, false)
|
|
|
|
c.NewRequest(setDeviceContextRequest(c, Device, ContextLen, Context), cookie)
|
|
|
|
return SetDeviceContextCookie{cookie}
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// Check returns an error if one occurred for checked requests that are not expecting a reply.
|
|
|
|
// This cannot be called for requests expecting a reply, nor for unchecked requests.
|
2012-05-10 23:01:42 +02:00
|
|
|
func (cook SetDeviceContextCookie) Check() error {
|
|
|
|
return cook.Cookie.Check()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write request to wire for SetDeviceContext
|
2012-05-11 05:57:34 +02:00
|
|
|
// setDeviceContextRequest writes a SetDeviceContext request to a byte slice.
|
2012-05-10 23:01:42 +02:00
|
|
|
func setDeviceContextRequest(c *xgb.Conn, Device uint32, ContextLen uint32, Context string) []byte {
|
|
|
|
size := xgb.Pad((12 + xgb.Pad((int(ContextLen) * 1))))
|
|
|
|
b := 0
|
|
|
|
buf := make([]byte, size)
|
|
|
|
|
|
|
|
buf[b] = c.Extensions["SELINUX"]
|
|
|
|
b += 1
|
|
|
|
|
|
|
|
buf[b] = 3 // request opcode
|
|
|
|
b += 1
|
|
|
|
|
|
|
|
xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
|
|
|
|
b += 2
|
|
|
|
|
|
|
|
xgb.Put32(buf[b:], Device)
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
xgb.Put32(buf[b:], ContextLen)
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
copy(buf[b:], Context[:ContextLen])
|
|
|
|
b += xgb.Pad(int(ContextLen))
|
|
|
|
|
|
|
|
return buf
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// GetDeviceContextCookie is a cookie used only for GetDeviceContext requests.
|
2012-05-10 23:01:42 +02:00
|
|
|
type GetDeviceContextCookie struct {
|
|
|
|
*xgb.Cookie
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// GetDeviceContext sends a checked request.
|
|
|
|
// If an error occurs, it will be returned with the reply by calling GetDeviceContextCookie.Reply()
|
2012-05-10 23:01:42 +02:00
|
|
|
func GetDeviceContext(c *xgb.Conn, Device uint32) GetDeviceContextCookie {
|
2012-05-12 05:58:52 +02:00
|
|
|
if _, ok := c.Extensions["SELINUX"]; !ok {
|
|
|
|
panic("Cannot issue request 'GetDeviceContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.")
|
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(true, true)
|
|
|
|
c.NewRequest(getDeviceContextRequest(c, Device), cookie)
|
|
|
|
return GetDeviceContextCookie{cookie}
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// GetDeviceContextUnchecked sends an unchecked request.
|
|
|
|
// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
|
2012-05-10 23:01:42 +02:00
|
|
|
func GetDeviceContextUnchecked(c *xgb.Conn, Device uint32) GetDeviceContextCookie {
|
2012-05-12 05:58:52 +02:00
|
|
|
if _, ok := c.Extensions["SELINUX"]; !ok {
|
|
|
|
panic("Cannot issue request 'GetDeviceContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.")
|
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(false, true)
|
|
|
|
c.NewRequest(getDeviceContextRequest(c, Device), cookie)
|
|
|
|
return GetDeviceContextCookie{cookie}
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// GetDeviceContextReply represents the data returned from a GetDeviceContext request.
|
2012-05-10 23:01:42 +02:00
|
|
|
type GetDeviceContextReply struct {
|
2012-05-11 05:57:34 +02:00
|
|
|
Sequence uint16 // sequence number of the request for this reply
|
|
|
|
Length uint32 // number of bytes in this reply
|
2012-05-10 23:01:42 +02:00
|
|
|
// padding: 1 bytes
|
|
|
|
ContextLen uint32
|
|
|
|
// padding: 20 bytes
|
|
|
|
Context string // size: xgb.Pad((int(ContextLen) * 1))
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// Reply blocks and returns the reply data for a GetDeviceContext request.
|
2012-05-10 23:01:42 +02:00
|
|
|
func (cook GetDeviceContextCookie) Reply() (*GetDeviceContextReply, error) {
|
|
|
|
buf, err := cook.Cookie.Reply()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if buf == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
return getDeviceContextReply(buf), nil
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// getDeviceContextReply reads a byte slice into a GetDeviceContextReply value.
|
2012-05-10 23:01:42 +02:00
|
|
|
func getDeviceContextReply(buf []byte) *GetDeviceContextReply {
|
|
|
|
v := new(GetDeviceContextReply)
|
|
|
|
b := 1 // skip reply determinant
|
|
|
|
|
|
|
|
b += 1 // padding
|
|
|
|
|
|
|
|
v.Sequence = xgb.Get16(buf[b:])
|
|
|
|
b += 2
|
|
|
|
|
|
|
|
v.Length = xgb.Get32(buf[b:]) // 4-byte units
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
v.ContextLen = xgb.Get32(buf[b:])
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
b += 20 // padding
|
|
|
|
|
|
|
|
{
|
|
|
|
byteString := make([]byte, v.ContextLen)
|
|
|
|
copy(byteString[:v.ContextLen], buf[b:])
|
|
|
|
v.Context = string(byteString)
|
|
|
|
b += xgb.Pad(int(v.ContextLen))
|
|
|
|
}
|
|
|
|
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write request to wire for GetDeviceContext
|
2012-05-11 05:57:34 +02:00
|
|
|
// getDeviceContextRequest writes a GetDeviceContext request to a byte slice.
|
2012-05-10 23:01:42 +02:00
|
|
|
func getDeviceContextRequest(c *xgb.Conn, Device uint32) []byte {
|
|
|
|
size := 8
|
|
|
|
b := 0
|
|
|
|
buf := make([]byte, size)
|
|
|
|
|
|
|
|
buf[b] = c.Extensions["SELINUX"]
|
|
|
|
b += 1
|
|
|
|
|
|
|
|
buf[b] = 4 // request opcode
|
|
|
|
b += 1
|
|
|
|
|
|
|
|
xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
|
|
|
|
b += 2
|
|
|
|
|
|
|
|
xgb.Put32(buf[b:], Device)
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
return buf
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// SetWindowCreateContextCookie is a cookie used only for SetWindowCreateContext requests.
|
2012-05-10 23:01:42 +02:00
|
|
|
type SetWindowCreateContextCookie struct {
|
|
|
|
*xgb.Cookie
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// SetWindowCreateContext sends an unchecked request.
|
|
|
|
// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
|
2012-05-10 23:01:42 +02:00
|
|
|
func SetWindowCreateContext(c *xgb.Conn, ContextLen uint32, Context string) SetWindowCreateContextCookie {
|
2012-05-12 05:58:52 +02:00
|
|
|
if _, ok := c.Extensions["SELINUX"]; !ok {
|
|
|
|
panic("Cannot issue request 'SetWindowCreateContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.")
|
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(false, false)
|
|
|
|
c.NewRequest(setWindowCreateContextRequest(c, ContextLen, Context), cookie)
|
|
|
|
return SetWindowCreateContextCookie{cookie}
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// SetWindowCreateContextChecked sends a checked request.
|
|
|
|
// If an error occurs, it can be retrieved using SetWindowCreateContextCookie.Check()
|
2012-05-10 23:01:42 +02:00
|
|
|
func SetWindowCreateContextChecked(c *xgb.Conn, ContextLen uint32, Context string) SetWindowCreateContextCookie {
|
2012-05-12 05:58:52 +02:00
|
|
|
if _, ok := c.Extensions["SELINUX"]; !ok {
|
|
|
|
panic("Cannot issue request 'SetWindowCreateContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.")
|
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(true, false)
|
|
|
|
c.NewRequest(setWindowCreateContextRequest(c, ContextLen, Context), cookie)
|
|
|
|
return SetWindowCreateContextCookie{cookie}
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// Check returns an error if one occurred for checked requests that are not expecting a reply.
|
|
|
|
// This cannot be called for requests expecting a reply, nor for unchecked requests.
|
2012-05-10 23:01:42 +02:00
|
|
|
func (cook SetWindowCreateContextCookie) Check() error {
|
|
|
|
return cook.Cookie.Check()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write request to wire for SetWindowCreateContext
|
2012-05-11 05:57:34 +02:00
|
|
|
// setWindowCreateContextRequest writes a SetWindowCreateContext request to a byte slice.
|
2012-05-10 23:01:42 +02:00
|
|
|
func setWindowCreateContextRequest(c *xgb.Conn, ContextLen uint32, Context string) []byte {
|
|
|
|
size := xgb.Pad((8 + xgb.Pad((int(ContextLen) * 1))))
|
|
|
|
b := 0
|
|
|
|
buf := make([]byte, size)
|
|
|
|
|
|
|
|
buf[b] = c.Extensions["SELINUX"]
|
|
|
|
b += 1
|
|
|
|
|
|
|
|
buf[b] = 5 // request opcode
|
|
|
|
b += 1
|
|
|
|
|
|
|
|
xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
|
|
|
|
b += 2
|
|
|
|
|
|
|
|
xgb.Put32(buf[b:], ContextLen)
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
copy(buf[b:], Context[:ContextLen])
|
|
|
|
b += xgb.Pad(int(ContextLen))
|
|
|
|
|
|
|
|
return buf
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// GetWindowCreateContextCookie is a cookie used only for GetWindowCreateContext requests.
|
2012-05-10 23:01:42 +02:00
|
|
|
type GetWindowCreateContextCookie struct {
|
|
|
|
*xgb.Cookie
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// GetWindowCreateContext sends a checked request.
|
|
|
|
// If an error occurs, it will be returned with the reply by calling GetWindowCreateContextCookie.Reply()
|
2012-05-10 23:01:42 +02:00
|
|
|
func GetWindowCreateContext(c *xgb.Conn) GetWindowCreateContextCookie {
|
2012-05-12 05:58:52 +02:00
|
|
|
if _, ok := c.Extensions["SELINUX"]; !ok {
|
|
|
|
panic("Cannot issue request 'GetWindowCreateContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.")
|
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(true, true)
|
|
|
|
c.NewRequest(getWindowCreateContextRequest(c), cookie)
|
|
|
|
return GetWindowCreateContextCookie{cookie}
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// GetWindowCreateContextUnchecked sends an unchecked request.
|
|
|
|
// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
|
2012-05-10 23:01:42 +02:00
|
|
|
func GetWindowCreateContextUnchecked(c *xgb.Conn) GetWindowCreateContextCookie {
|
2012-05-12 05:58:52 +02:00
|
|
|
if _, ok := c.Extensions["SELINUX"]; !ok {
|
|
|
|
panic("Cannot issue request 'GetWindowCreateContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.")
|
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(false, true)
|
|
|
|
c.NewRequest(getWindowCreateContextRequest(c), cookie)
|
|
|
|
return GetWindowCreateContextCookie{cookie}
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// GetWindowCreateContextReply represents the data returned from a GetWindowCreateContext request.
|
2012-05-10 23:01:42 +02:00
|
|
|
type GetWindowCreateContextReply struct {
|
2012-05-11 05:57:34 +02:00
|
|
|
Sequence uint16 // sequence number of the request for this reply
|
|
|
|
Length uint32 // number of bytes in this reply
|
2012-05-10 23:01:42 +02:00
|
|
|
// padding: 1 bytes
|
|
|
|
ContextLen uint32
|
|
|
|
// padding: 20 bytes
|
|
|
|
Context string // size: xgb.Pad((int(ContextLen) * 1))
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// Reply blocks and returns the reply data for a GetWindowCreateContext request.
|
2012-05-10 23:01:42 +02:00
|
|
|
func (cook GetWindowCreateContextCookie) Reply() (*GetWindowCreateContextReply, error) {
|
|
|
|
buf, err := cook.Cookie.Reply()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if buf == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
return getWindowCreateContextReply(buf), nil
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// getWindowCreateContextReply reads a byte slice into a GetWindowCreateContextReply value.
|
2012-05-10 23:01:42 +02:00
|
|
|
func getWindowCreateContextReply(buf []byte) *GetWindowCreateContextReply {
|
|
|
|
v := new(GetWindowCreateContextReply)
|
|
|
|
b := 1 // skip reply determinant
|
|
|
|
|
|
|
|
b += 1 // padding
|
|
|
|
|
|
|
|
v.Sequence = xgb.Get16(buf[b:])
|
|
|
|
b += 2
|
|
|
|
|
|
|
|
v.Length = xgb.Get32(buf[b:]) // 4-byte units
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
v.ContextLen = xgb.Get32(buf[b:])
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
b += 20 // padding
|
|
|
|
|
|
|
|
{
|
|
|
|
byteString := make([]byte, v.ContextLen)
|
|
|
|
copy(byteString[:v.ContextLen], buf[b:])
|
|
|
|
v.Context = string(byteString)
|
|
|
|
b += xgb.Pad(int(v.ContextLen))
|
|
|
|
}
|
|
|
|
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write request to wire for GetWindowCreateContext
|
2012-05-11 05:57:34 +02:00
|
|
|
// getWindowCreateContextRequest writes a GetWindowCreateContext request to a byte slice.
|
2012-05-10 23:01:42 +02:00
|
|
|
func getWindowCreateContextRequest(c *xgb.Conn) []byte {
|
|
|
|
size := 4
|
|
|
|
b := 0
|
|
|
|
buf := make([]byte, size)
|
|
|
|
|
|
|
|
buf[b] = c.Extensions["SELINUX"]
|
|
|
|
b += 1
|
|
|
|
|
|
|
|
buf[b] = 6 // request opcode
|
|
|
|
b += 1
|
|
|
|
|
|
|
|
xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
|
|
|
|
b += 2
|
|
|
|
|
|
|
|
return buf
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// GetWindowContextCookie is a cookie used only for GetWindowContext requests.
|
2012-05-10 23:01:42 +02:00
|
|
|
type GetWindowContextCookie struct {
|
|
|
|
*xgb.Cookie
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// GetWindowContext sends a checked request.
|
|
|
|
// If an error occurs, it will be returned with the reply by calling GetWindowContextCookie.Reply()
|
2012-05-10 23:01:42 +02:00
|
|
|
func GetWindowContext(c *xgb.Conn, Window xproto.Window) GetWindowContextCookie {
|
2012-05-12 05:58:52 +02:00
|
|
|
if _, ok := c.Extensions["SELINUX"]; !ok {
|
|
|
|
panic("Cannot issue request 'GetWindowContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.")
|
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(true, true)
|
|
|
|
c.NewRequest(getWindowContextRequest(c, Window), cookie)
|
|
|
|
return GetWindowContextCookie{cookie}
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// GetWindowContextUnchecked sends an unchecked request.
|
|
|
|
// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
|
2012-05-10 23:01:42 +02:00
|
|
|
func GetWindowContextUnchecked(c *xgb.Conn, Window xproto.Window) GetWindowContextCookie {
|
2012-05-12 05:58:52 +02:00
|
|
|
if _, ok := c.Extensions["SELINUX"]; !ok {
|
|
|
|
panic("Cannot issue request 'GetWindowContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.")
|
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(false, true)
|
|
|
|
c.NewRequest(getWindowContextRequest(c, Window), cookie)
|
|
|
|
return GetWindowContextCookie{cookie}
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// GetWindowContextReply represents the data returned from a GetWindowContext request.
|
2012-05-10 23:01:42 +02:00
|
|
|
type GetWindowContextReply struct {
|
2012-05-11 05:57:34 +02:00
|
|
|
Sequence uint16 // sequence number of the request for this reply
|
|
|
|
Length uint32 // number of bytes in this reply
|
2012-05-10 23:01:42 +02:00
|
|
|
// padding: 1 bytes
|
|
|
|
ContextLen uint32
|
|
|
|
// padding: 20 bytes
|
|
|
|
Context string // size: xgb.Pad((int(ContextLen) * 1))
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// Reply blocks and returns the reply data for a GetWindowContext request.
|
2012-05-10 23:01:42 +02:00
|
|
|
func (cook GetWindowContextCookie) Reply() (*GetWindowContextReply, error) {
|
|
|
|
buf, err := cook.Cookie.Reply()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if buf == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
return getWindowContextReply(buf), nil
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// getWindowContextReply reads a byte slice into a GetWindowContextReply value.
|
2012-05-10 23:01:42 +02:00
|
|
|
func getWindowContextReply(buf []byte) *GetWindowContextReply {
|
|
|
|
v := new(GetWindowContextReply)
|
|
|
|
b := 1 // skip reply determinant
|
|
|
|
|
|
|
|
b += 1 // padding
|
|
|
|
|
|
|
|
v.Sequence = xgb.Get16(buf[b:])
|
|
|
|
b += 2
|
|
|
|
|
|
|
|
v.Length = xgb.Get32(buf[b:]) // 4-byte units
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
v.ContextLen = xgb.Get32(buf[b:])
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
b += 20 // padding
|
|
|
|
|
|
|
|
{
|
|
|
|
byteString := make([]byte, v.ContextLen)
|
|
|
|
copy(byteString[:v.ContextLen], buf[b:])
|
|
|
|
v.Context = string(byteString)
|
|
|
|
b += xgb.Pad(int(v.ContextLen))
|
|
|
|
}
|
|
|
|
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write request to wire for GetWindowContext
|
2012-05-11 05:57:34 +02:00
|
|
|
// getWindowContextRequest writes a GetWindowContext request to a byte slice.
|
2012-05-10 23:01:42 +02:00
|
|
|
func getWindowContextRequest(c *xgb.Conn, Window xproto.Window) []byte {
|
|
|
|
size := 8
|
|
|
|
b := 0
|
|
|
|
buf := make([]byte, size)
|
|
|
|
|
|
|
|
buf[b] = c.Extensions["SELINUX"]
|
|
|
|
b += 1
|
|
|
|
|
|
|
|
buf[b] = 7 // request opcode
|
|
|
|
b += 1
|
|
|
|
|
|
|
|
xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
|
|
|
|
b += 2
|
|
|
|
|
|
|
|
xgb.Put32(buf[b:], uint32(Window))
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
return buf
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// SetPropertyCreateContextCookie is a cookie used only for SetPropertyCreateContext requests.
|
2012-05-10 23:01:42 +02:00
|
|
|
type SetPropertyCreateContextCookie struct {
|
|
|
|
*xgb.Cookie
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// SetPropertyCreateContext sends an unchecked request.
|
|
|
|
// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
|
2012-05-10 23:01:42 +02:00
|
|
|
func SetPropertyCreateContext(c *xgb.Conn, ContextLen uint32, Context string) SetPropertyCreateContextCookie {
|
2012-05-12 05:58:52 +02:00
|
|
|
if _, ok := c.Extensions["SELINUX"]; !ok {
|
|
|
|
panic("Cannot issue request 'SetPropertyCreateContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.")
|
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(false, false)
|
|
|
|
c.NewRequest(setPropertyCreateContextRequest(c, ContextLen, Context), cookie)
|
|
|
|
return SetPropertyCreateContextCookie{cookie}
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// SetPropertyCreateContextChecked sends a checked request.
|
|
|
|
// If an error occurs, it can be retrieved using SetPropertyCreateContextCookie.Check()
|
2012-05-10 23:01:42 +02:00
|
|
|
func SetPropertyCreateContextChecked(c *xgb.Conn, ContextLen uint32, Context string) SetPropertyCreateContextCookie {
|
2012-05-12 05:58:52 +02:00
|
|
|
if _, ok := c.Extensions["SELINUX"]; !ok {
|
|
|
|
panic("Cannot issue request 'SetPropertyCreateContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.")
|
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(true, false)
|
|
|
|
c.NewRequest(setPropertyCreateContextRequest(c, ContextLen, Context), cookie)
|
|
|
|
return SetPropertyCreateContextCookie{cookie}
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// Check returns an error if one occurred for checked requests that are not expecting a reply.
|
|
|
|
// This cannot be called for requests expecting a reply, nor for unchecked requests.
|
2012-05-10 23:01:42 +02:00
|
|
|
func (cook SetPropertyCreateContextCookie) Check() error {
|
|
|
|
return cook.Cookie.Check()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write request to wire for SetPropertyCreateContext
|
2012-05-11 05:57:34 +02:00
|
|
|
// setPropertyCreateContextRequest writes a SetPropertyCreateContext request to a byte slice.
|
2012-05-10 23:01:42 +02:00
|
|
|
func setPropertyCreateContextRequest(c *xgb.Conn, ContextLen uint32, Context string) []byte {
|
|
|
|
size := xgb.Pad((8 + xgb.Pad((int(ContextLen) * 1))))
|
|
|
|
b := 0
|
|
|
|
buf := make([]byte, size)
|
|
|
|
|
|
|
|
buf[b] = c.Extensions["SELINUX"]
|
|
|
|
b += 1
|
|
|
|
|
|
|
|
buf[b] = 8 // request opcode
|
|
|
|
b += 1
|
|
|
|
|
|
|
|
xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
|
|
|
|
b += 2
|
|
|
|
|
|
|
|
xgb.Put32(buf[b:], ContextLen)
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
copy(buf[b:], Context[:ContextLen])
|
|
|
|
b += xgb.Pad(int(ContextLen))
|
|
|
|
|
|
|
|
return buf
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// GetPropertyCreateContextCookie is a cookie used only for GetPropertyCreateContext requests.
|
2012-05-10 23:01:42 +02:00
|
|
|
type GetPropertyCreateContextCookie struct {
|
|
|
|
*xgb.Cookie
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// GetPropertyCreateContext sends a checked request.
|
|
|
|
// If an error occurs, it will be returned with the reply by calling GetPropertyCreateContextCookie.Reply()
|
2012-05-10 23:01:42 +02:00
|
|
|
func GetPropertyCreateContext(c *xgb.Conn) GetPropertyCreateContextCookie {
|
2012-05-12 05:58:52 +02:00
|
|
|
if _, ok := c.Extensions["SELINUX"]; !ok {
|
|
|
|
panic("Cannot issue request 'GetPropertyCreateContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.")
|
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(true, true)
|
|
|
|
c.NewRequest(getPropertyCreateContextRequest(c), cookie)
|
|
|
|
return GetPropertyCreateContextCookie{cookie}
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// GetPropertyCreateContextUnchecked sends an unchecked request.
|
|
|
|
// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
|
2012-05-10 23:01:42 +02:00
|
|
|
func GetPropertyCreateContextUnchecked(c *xgb.Conn) GetPropertyCreateContextCookie {
|
2012-05-12 05:58:52 +02:00
|
|
|
if _, ok := c.Extensions["SELINUX"]; !ok {
|
|
|
|
panic("Cannot issue request 'GetPropertyCreateContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.")
|
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(false, true)
|
|
|
|
c.NewRequest(getPropertyCreateContextRequest(c), cookie)
|
|
|
|
return GetPropertyCreateContextCookie{cookie}
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// GetPropertyCreateContextReply represents the data returned from a GetPropertyCreateContext request.
|
2012-05-10 23:01:42 +02:00
|
|
|
type GetPropertyCreateContextReply struct {
|
2012-05-11 05:57:34 +02:00
|
|
|
Sequence uint16 // sequence number of the request for this reply
|
|
|
|
Length uint32 // number of bytes in this reply
|
2012-05-10 23:01:42 +02:00
|
|
|
// padding: 1 bytes
|
|
|
|
ContextLen uint32
|
|
|
|
// padding: 20 bytes
|
|
|
|
Context string // size: xgb.Pad((int(ContextLen) * 1))
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// Reply blocks and returns the reply data for a GetPropertyCreateContext request.
|
2012-05-10 23:01:42 +02:00
|
|
|
func (cook GetPropertyCreateContextCookie) Reply() (*GetPropertyCreateContextReply, error) {
|
|
|
|
buf, err := cook.Cookie.Reply()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if buf == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
return getPropertyCreateContextReply(buf), nil
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// getPropertyCreateContextReply reads a byte slice into a GetPropertyCreateContextReply value.
|
2012-05-10 23:01:42 +02:00
|
|
|
func getPropertyCreateContextReply(buf []byte) *GetPropertyCreateContextReply {
|
|
|
|
v := new(GetPropertyCreateContextReply)
|
|
|
|
b := 1 // skip reply determinant
|
|
|
|
|
|
|
|
b += 1 // padding
|
|
|
|
|
|
|
|
v.Sequence = xgb.Get16(buf[b:])
|
|
|
|
b += 2
|
|
|
|
|
|
|
|
v.Length = xgb.Get32(buf[b:]) // 4-byte units
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
v.ContextLen = xgb.Get32(buf[b:])
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
b += 20 // padding
|
|
|
|
|
|
|
|
{
|
|
|
|
byteString := make([]byte, v.ContextLen)
|
|
|
|
copy(byteString[:v.ContextLen], buf[b:])
|
|
|
|
v.Context = string(byteString)
|
|
|
|
b += xgb.Pad(int(v.ContextLen))
|
|
|
|
}
|
|
|
|
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write request to wire for GetPropertyCreateContext
|
2012-05-11 05:57:34 +02:00
|
|
|
// getPropertyCreateContextRequest writes a GetPropertyCreateContext request to a byte slice.
|
2012-05-10 23:01:42 +02:00
|
|
|
func getPropertyCreateContextRequest(c *xgb.Conn) []byte {
|
|
|
|
size := 4
|
|
|
|
b := 0
|
|
|
|
buf := make([]byte, size)
|
|
|
|
|
|
|
|
buf[b] = c.Extensions["SELINUX"]
|
|
|
|
b += 1
|
|
|
|
|
|
|
|
buf[b] = 9 // request opcode
|
|
|
|
b += 1
|
|
|
|
|
|
|
|
xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
|
|
|
|
b += 2
|
|
|
|
|
|
|
|
return buf
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// SetPropertyUseContextCookie is a cookie used only for SetPropertyUseContext requests.
|
2012-05-10 23:01:42 +02:00
|
|
|
type SetPropertyUseContextCookie struct {
|
|
|
|
*xgb.Cookie
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// SetPropertyUseContext sends an unchecked request.
|
|
|
|
// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
|
2012-05-10 23:01:42 +02:00
|
|
|
func SetPropertyUseContext(c *xgb.Conn, ContextLen uint32, Context string) SetPropertyUseContextCookie {
|
2012-05-12 05:58:52 +02:00
|
|
|
if _, ok := c.Extensions["SELINUX"]; !ok {
|
|
|
|
panic("Cannot issue request 'SetPropertyUseContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.")
|
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(false, false)
|
|
|
|
c.NewRequest(setPropertyUseContextRequest(c, ContextLen, Context), cookie)
|
|
|
|
return SetPropertyUseContextCookie{cookie}
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// SetPropertyUseContextChecked sends a checked request.
|
|
|
|
// If an error occurs, it can be retrieved using SetPropertyUseContextCookie.Check()
|
2012-05-10 23:01:42 +02:00
|
|
|
func SetPropertyUseContextChecked(c *xgb.Conn, ContextLen uint32, Context string) SetPropertyUseContextCookie {
|
2012-05-12 05:58:52 +02:00
|
|
|
if _, ok := c.Extensions["SELINUX"]; !ok {
|
|
|
|
panic("Cannot issue request 'SetPropertyUseContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.")
|
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(true, false)
|
|
|
|
c.NewRequest(setPropertyUseContextRequest(c, ContextLen, Context), cookie)
|
|
|
|
return SetPropertyUseContextCookie{cookie}
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// Check returns an error if one occurred for checked requests that are not expecting a reply.
|
|
|
|
// This cannot be called for requests expecting a reply, nor for unchecked requests.
|
2012-05-10 23:01:42 +02:00
|
|
|
func (cook SetPropertyUseContextCookie) Check() error {
|
|
|
|
return cook.Cookie.Check()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write request to wire for SetPropertyUseContext
|
2012-05-11 05:57:34 +02:00
|
|
|
// setPropertyUseContextRequest writes a SetPropertyUseContext request to a byte slice.
|
2012-05-10 23:01:42 +02:00
|
|
|
func setPropertyUseContextRequest(c *xgb.Conn, ContextLen uint32, Context string) []byte {
|
|
|
|
size := xgb.Pad((8 + xgb.Pad((int(ContextLen) * 1))))
|
|
|
|
b := 0
|
|
|
|
buf := make([]byte, size)
|
|
|
|
|
|
|
|
buf[b] = c.Extensions["SELINUX"]
|
|
|
|
b += 1
|
|
|
|
|
|
|
|
buf[b] = 10 // request opcode
|
|
|
|
b += 1
|
|
|
|
|
|
|
|
xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
|
|
|
|
b += 2
|
|
|
|
|
|
|
|
xgb.Put32(buf[b:], ContextLen)
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
copy(buf[b:], Context[:ContextLen])
|
|
|
|
b += xgb.Pad(int(ContextLen))
|
|
|
|
|
|
|
|
return buf
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// GetPropertyUseContextCookie is a cookie used only for GetPropertyUseContext requests.
|
2012-05-10 23:01:42 +02:00
|
|
|
type GetPropertyUseContextCookie struct {
|
|
|
|
*xgb.Cookie
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// GetPropertyUseContext sends a checked request.
|
|
|
|
// If an error occurs, it will be returned with the reply by calling GetPropertyUseContextCookie.Reply()
|
2012-05-10 23:01:42 +02:00
|
|
|
func GetPropertyUseContext(c *xgb.Conn) GetPropertyUseContextCookie {
|
2012-05-12 05:58:52 +02:00
|
|
|
if _, ok := c.Extensions["SELINUX"]; !ok {
|
|
|
|
panic("Cannot issue request 'GetPropertyUseContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.")
|
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(true, true)
|
|
|
|
c.NewRequest(getPropertyUseContextRequest(c), cookie)
|
|
|
|
return GetPropertyUseContextCookie{cookie}
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// GetPropertyUseContextUnchecked sends an unchecked request.
|
|
|
|
// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
|
2012-05-10 23:01:42 +02:00
|
|
|
func GetPropertyUseContextUnchecked(c *xgb.Conn) GetPropertyUseContextCookie {
|
2012-05-12 05:58:52 +02:00
|
|
|
if _, ok := c.Extensions["SELINUX"]; !ok {
|
|
|
|
panic("Cannot issue request 'GetPropertyUseContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.")
|
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(false, true)
|
|
|
|
c.NewRequest(getPropertyUseContextRequest(c), cookie)
|
|
|
|
return GetPropertyUseContextCookie{cookie}
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// GetPropertyUseContextReply represents the data returned from a GetPropertyUseContext request.
|
2012-05-10 23:01:42 +02:00
|
|
|
type GetPropertyUseContextReply struct {
|
2012-05-11 05:57:34 +02:00
|
|
|
Sequence uint16 // sequence number of the request for this reply
|
|
|
|
Length uint32 // number of bytes in this reply
|
2012-05-10 23:01:42 +02:00
|
|
|
// padding: 1 bytes
|
|
|
|
ContextLen uint32
|
|
|
|
// padding: 20 bytes
|
|
|
|
Context string // size: xgb.Pad((int(ContextLen) * 1))
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// Reply blocks and returns the reply data for a GetPropertyUseContext request.
|
2012-05-10 23:01:42 +02:00
|
|
|
func (cook GetPropertyUseContextCookie) Reply() (*GetPropertyUseContextReply, error) {
|
|
|
|
buf, err := cook.Cookie.Reply()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if buf == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
return getPropertyUseContextReply(buf), nil
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// getPropertyUseContextReply reads a byte slice into a GetPropertyUseContextReply value.
|
2012-05-10 23:01:42 +02:00
|
|
|
func getPropertyUseContextReply(buf []byte) *GetPropertyUseContextReply {
|
|
|
|
v := new(GetPropertyUseContextReply)
|
|
|
|
b := 1 // skip reply determinant
|
|
|
|
|
|
|
|
b += 1 // padding
|
|
|
|
|
|
|
|
v.Sequence = xgb.Get16(buf[b:])
|
|
|
|
b += 2
|
|
|
|
|
|
|
|
v.Length = xgb.Get32(buf[b:]) // 4-byte units
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
v.ContextLen = xgb.Get32(buf[b:])
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
b += 20 // padding
|
|
|
|
|
|
|
|
{
|
|
|
|
byteString := make([]byte, v.ContextLen)
|
|
|
|
copy(byteString[:v.ContextLen], buf[b:])
|
|
|
|
v.Context = string(byteString)
|
|
|
|
b += xgb.Pad(int(v.ContextLen))
|
|
|
|
}
|
|
|
|
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write request to wire for GetPropertyUseContext
|
2012-05-11 05:57:34 +02:00
|
|
|
// getPropertyUseContextRequest writes a GetPropertyUseContext request to a byte slice.
|
2012-05-10 23:01:42 +02:00
|
|
|
func getPropertyUseContextRequest(c *xgb.Conn) []byte {
|
|
|
|
size := 4
|
|
|
|
b := 0
|
|
|
|
buf := make([]byte, size)
|
|
|
|
|
|
|
|
buf[b] = c.Extensions["SELINUX"]
|
|
|
|
b += 1
|
|
|
|
|
|
|
|
buf[b] = 11 // request opcode
|
|
|
|
b += 1
|
|
|
|
|
|
|
|
xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
|
|
|
|
b += 2
|
|
|
|
|
|
|
|
return buf
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// GetPropertyContextCookie is a cookie used only for GetPropertyContext requests.
|
2012-05-10 23:01:42 +02:00
|
|
|
type GetPropertyContextCookie struct {
|
|
|
|
*xgb.Cookie
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// GetPropertyContext sends a checked request.
|
|
|
|
// If an error occurs, it will be returned with the reply by calling GetPropertyContextCookie.Reply()
|
2012-05-10 23:01:42 +02:00
|
|
|
func GetPropertyContext(c *xgb.Conn, Window xproto.Window, Property xproto.Atom) GetPropertyContextCookie {
|
2012-05-12 05:58:52 +02:00
|
|
|
if _, ok := c.Extensions["SELINUX"]; !ok {
|
|
|
|
panic("Cannot issue request 'GetPropertyContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.")
|
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(true, true)
|
|
|
|
c.NewRequest(getPropertyContextRequest(c, Window, Property), cookie)
|
|
|
|
return GetPropertyContextCookie{cookie}
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// GetPropertyContextUnchecked sends an unchecked request.
|
|
|
|
// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
|
2012-05-10 23:01:42 +02:00
|
|
|
func GetPropertyContextUnchecked(c *xgb.Conn, Window xproto.Window, Property xproto.Atom) GetPropertyContextCookie {
|
2012-05-12 05:58:52 +02:00
|
|
|
if _, ok := c.Extensions["SELINUX"]; !ok {
|
|
|
|
panic("Cannot issue request 'GetPropertyContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.")
|
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(false, true)
|
|
|
|
c.NewRequest(getPropertyContextRequest(c, Window, Property), cookie)
|
|
|
|
return GetPropertyContextCookie{cookie}
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// GetPropertyContextReply represents the data returned from a GetPropertyContext request.
|
2012-05-10 23:01:42 +02:00
|
|
|
type GetPropertyContextReply struct {
|
2012-05-11 05:57:34 +02:00
|
|
|
Sequence uint16 // sequence number of the request for this reply
|
|
|
|
Length uint32 // number of bytes in this reply
|
2012-05-10 23:01:42 +02:00
|
|
|
// padding: 1 bytes
|
|
|
|
ContextLen uint32
|
|
|
|
// padding: 20 bytes
|
|
|
|
Context string // size: xgb.Pad((int(ContextLen) * 1))
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// Reply blocks and returns the reply data for a GetPropertyContext request.
|
2012-05-10 23:01:42 +02:00
|
|
|
func (cook GetPropertyContextCookie) Reply() (*GetPropertyContextReply, error) {
|
|
|
|
buf, err := cook.Cookie.Reply()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if buf == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
return getPropertyContextReply(buf), nil
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// getPropertyContextReply reads a byte slice into a GetPropertyContextReply value.
|
2012-05-10 23:01:42 +02:00
|
|
|
func getPropertyContextReply(buf []byte) *GetPropertyContextReply {
|
|
|
|
v := new(GetPropertyContextReply)
|
|
|
|
b := 1 // skip reply determinant
|
|
|
|
|
|
|
|
b += 1 // padding
|
|
|
|
|
|
|
|
v.Sequence = xgb.Get16(buf[b:])
|
|
|
|
b += 2
|
|
|
|
|
|
|
|
v.Length = xgb.Get32(buf[b:]) // 4-byte units
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
v.ContextLen = xgb.Get32(buf[b:])
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
b += 20 // padding
|
|
|
|
|
|
|
|
{
|
|
|
|
byteString := make([]byte, v.ContextLen)
|
|
|
|
copy(byteString[:v.ContextLen], buf[b:])
|
|
|
|
v.Context = string(byteString)
|
|
|
|
b += xgb.Pad(int(v.ContextLen))
|
|
|
|
}
|
|
|
|
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write request to wire for GetPropertyContext
|
2012-05-11 05:57:34 +02:00
|
|
|
// getPropertyContextRequest writes a GetPropertyContext request to a byte slice.
|
2012-05-10 23:01:42 +02:00
|
|
|
func getPropertyContextRequest(c *xgb.Conn, Window xproto.Window, Property xproto.Atom) []byte {
|
|
|
|
size := 12
|
|
|
|
b := 0
|
|
|
|
buf := make([]byte, size)
|
|
|
|
|
|
|
|
buf[b] = c.Extensions["SELINUX"]
|
|
|
|
b += 1
|
|
|
|
|
|
|
|
buf[b] = 12 // request opcode
|
|
|
|
b += 1
|
|
|
|
|
|
|
|
xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
|
|
|
|
b += 2
|
|
|
|
|
|
|
|
xgb.Put32(buf[b:], uint32(Window))
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
xgb.Put32(buf[b:], uint32(Property))
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
return buf
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// GetPropertyDataContextCookie is a cookie used only for GetPropertyDataContext requests.
|
2012-05-10 23:01:42 +02:00
|
|
|
type GetPropertyDataContextCookie struct {
|
|
|
|
*xgb.Cookie
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// GetPropertyDataContext sends a checked request.
|
|
|
|
// If an error occurs, it will be returned with the reply by calling GetPropertyDataContextCookie.Reply()
|
2012-05-10 23:01:42 +02:00
|
|
|
func GetPropertyDataContext(c *xgb.Conn, Window xproto.Window, Property xproto.Atom) GetPropertyDataContextCookie {
|
2012-05-12 05:58:52 +02:00
|
|
|
if _, ok := c.Extensions["SELINUX"]; !ok {
|
|
|
|
panic("Cannot issue request 'GetPropertyDataContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.")
|
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(true, true)
|
|
|
|
c.NewRequest(getPropertyDataContextRequest(c, Window, Property), cookie)
|
|
|
|
return GetPropertyDataContextCookie{cookie}
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// GetPropertyDataContextUnchecked sends an unchecked request.
|
|
|
|
// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
|
2012-05-10 23:01:42 +02:00
|
|
|
func GetPropertyDataContextUnchecked(c *xgb.Conn, Window xproto.Window, Property xproto.Atom) GetPropertyDataContextCookie {
|
2012-05-12 05:58:52 +02:00
|
|
|
if _, ok := c.Extensions["SELINUX"]; !ok {
|
|
|
|
panic("Cannot issue request 'GetPropertyDataContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.")
|
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(false, true)
|
|
|
|
c.NewRequest(getPropertyDataContextRequest(c, Window, Property), cookie)
|
|
|
|
return GetPropertyDataContextCookie{cookie}
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// GetPropertyDataContextReply represents the data returned from a GetPropertyDataContext request.
|
2012-05-10 23:01:42 +02:00
|
|
|
type GetPropertyDataContextReply struct {
|
2012-05-11 05:57:34 +02:00
|
|
|
Sequence uint16 // sequence number of the request for this reply
|
|
|
|
Length uint32 // number of bytes in this reply
|
2012-05-10 23:01:42 +02:00
|
|
|
// padding: 1 bytes
|
|
|
|
ContextLen uint32
|
|
|
|
// padding: 20 bytes
|
|
|
|
Context string // size: xgb.Pad((int(ContextLen) * 1))
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// Reply blocks and returns the reply data for a GetPropertyDataContext request.
|
2012-05-10 23:01:42 +02:00
|
|
|
func (cook GetPropertyDataContextCookie) Reply() (*GetPropertyDataContextReply, error) {
|
|
|
|
buf, err := cook.Cookie.Reply()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if buf == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
return getPropertyDataContextReply(buf), nil
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// getPropertyDataContextReply reads a byte slice into a GetPropertyDataContextReply value.
|
2012-05-10 23:01:42 +02:00
|
|
|
func getPropertyDataContextReply(buf []byte) *GetPropertyDataContextReply {
|
|
|
|
v := new(GetPropertyDataContextReply)
|
|
|
|
b := 1 // skip reply determinant
|
|
|
|
|
|
|
|
b += 1 // padding
|
|
|
|
|
|
|
|
v.Sequence = xgb.Get16(buf[b:])
|
|
|
|
b += 2
|
|
|
|
|
|
|
|
v.Length = xgb.Get32(buf[b:]) // 4-byte units
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
v.ContextLen = xgb.Get32(buf[b:])
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
b += 20 // padding
|
|
|
|
|
|
|
|
{
|
|
|
|
byteString := make([]byte, v.ContextLen)
|
|
|
|
copy(byteString[:v.ContextLen], buf[b:])
|
|
|
|
v.Context = string(byteString)
|
|
|
|
b += xgb.Pad(int(v.ContextLen))
|
|
|
|
}
|
|
|
|
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write request to wire for GetPropertyDataContext
|
2012-05-11 05:57:34 +02:00
|
|
|
// getPropertyDataContextRequest writes a GetPropertyDataContext request to a byte slice.
|
2012-05-10 23:01:42 +02:00
|
|
|
func getPropertyDataContextRequest(c *xgb.Conn, Window xproto.Window, Property xproto.Atom) []byte {
|
|
|
|
size := 12
|
|
|
|
b := 0
|
|
|
|
buf := make([]byte, size)
|
|
|
|
|
|
|
|
buf[b] = c.Extensions["SELINUX"]
|
|
|
|
b += 1
|
|
|
|
|
|
|
|
buf[b] = 13 // request opcode
|
|
|
|
b += 1
|
|
|
|
|
|
|
|
xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
|
|
|
|
b += 2
|
|
|
|
|
|
|
|
xgb.Put32(buf[b:], uint32(Window))
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
xgb.Put32(buf[b:], uint32(Property))
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
return buf
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// ListPropertiesCookie is a cookie used only for ListProperties requests.
|
2012-05-10 23:01:42 +02:00
|
|
|
type ListPropertiesCookie struct {
|
|
|
|
*xgb.Cookie
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// ListProperties sends a checked request.
|
|
|
|
// If an error occurs, it will be returned with the reply by calling ListPropertiesCookie.Reply()
|
2012-05-10 23:01:42 +02:00
|
|
|
func ListProperties(c *xgb.Conn, Window xproto.Window) ListPropertiesCookie {
|
2012-05-12 05:58:52 +02:00
|
|
|
if _, ok := c.Extensions["SELINUX"]; !ok {
|
|
|
|
panic("Cannot issue request 'ListProperties' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.")
|
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(true, true)
|
|
|
|
c.NewRequest(listPropertiesRequest(c, Window), cookie)
|
|
|
|
return ListPropertiesCookie{cookie}
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// ListPropertiesUnchecked sends an unchecked request.
|
|
|
|
// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
|
2012-05-10 23:01:42 +02:00
|
|
|
func ListPropertiesUnchecked(c *xgb.Conn, Window xproto.Window) ListPropertiesCookie {
|
2012-05-12 05:58:52 +02:00
|
|
|
if _, ok := c.Extensions["SELINUX"]; !ok {
|
|
|
|
panic("Cannot issue request 'ListProperties' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.")
|
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(false, true)
|
|
|
|
c.NewRequest(listPropertiesRequest(c, Window), cookie)
|
|
|
|
return ListPropertiesCookie{cookie}
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// ListPropertiesReply represents the data returned from a ListProperties request.
|
2012-05-10 23:01:42 +02:00
|
|
|
type ListPropertiesReply struct {
|
2012-05-11 05:57:34 +02:00
|
|
|
Sequence uint16 // sequence number of the request for this reply
|
|
|
|
Length uint32 // number of bytes in this reply
|
2012-05-10 23:01:42 +02:00
|
|
|
// padding: 1 bytes
|
|
|
|
PropertiesLen uint32
|
|
|
|
// padding: 20 bytes
|
|
|
|
Properties []ListItem // size: ListItemListSize(Properties)
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// Reply blocks and returns the reply data for a ListProperties request.
|
2012-05-10 23:01:42 +02:00
|
|
|
func (cook ListPropertiesCookie) Reply() (*ListPropertiesReply, error) {
|
|
|
|
buf, err := cook.Cookie.Reply()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if buf == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
return listPropertiesReply(buf), nil
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// listPropertiesReply reads a byte slice into a ListPropertiesReply value.
|
2012-05-10 23:01:42 +02:00
|
|
|
func listPropertiesReply(buf []byte) *ListPropertiesReply {
|
|
|
|
v := new(ListPropertiesReply)
|
|
|
|
b := 1 // skip reply determinant
|
|
|
|
|
|
|
|
b += 1 // padding
|
|
|
|
|
|
|
|
v.Sequence = xgb.Get16(buf[b:])
|
|
|
|
b += 2
|
|
|
|
|
|
|
|
v.Length = xgb.Get32(buf[b:]) // 4-byte units
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
v.PropertiesLen = xgb.Get32(buf[b:])
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
b += 20 // padding
|
|
|
|
|
|
|
|
v.Properties = make([]ListItem, v.PropertiesLen)
|
|
|
|
b += ListItemReadList(buf[b:], v.Properties)
|
|
|
|
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write request to wire for ListProperties
|
2012-05-11 05:57:34 +02:00
|
|
|
// listPropertiesRequest writes a ListProperties request to a byte slice.
|
2012-05-10 23:01:42 +02:00
|
|
|
func listPropertiesRequest(c *xgb.Conn, Window xproto.Window) []byte {
|
|
|
|
size := 8
|
|
|
|
b := 0
|
|
|
|
buf := make([]byte, size)
|
|
|
|
|
|
|
|
buf[b] = c.Extensions["SELINUX"]
|
|
|
|
b += 1
|
|
|
|
|
|
|
|
buf[b] = 14 // request opcode
|
|
|
|
b += 1
|
|
|
|
|
|
|
|
xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
|
|
|
|
b += 2
|
|
|
|
|
|
|
|
xgb.Put32(buf[b:], uint32(Window))
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
return buf
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// SetSelectionCreateContextCookie is a cookie used only for SetSelectionCreateContext requests.
|
2012-05-10 23:01:42 +02:00
|
|
|
type SetSelectionCreateContextCookie struct {
|
|
|
|
*xgb.Cookie
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// SetSelectionCreateContext sends an unchecked request.
|
|
|
|
// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
|
2012-05-10 23:01:42 +02:00
|
|
|
func SetSelectionCreateContext(c *xgb.Conn, ContextLen uint32, Context string) SetSelectionCreateContextCookie {
|
2012-05-12 05:58:52 +02:00
|
|
|
if _, ok := c.Extensions["SELINUX"]; !ok {
|
|
|
|
panic("Cannot issue request 'SetSelectionCreateContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.")
|
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(false, false)
|
|
|
|
c.NewRequest(setSelectionCreateContextRequest(c, ContextLen, Context), cookie)
|
|
|
|
return SetSelectionCreateContextCookie{cookie}
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// SetSelectionCreateContextChecked sends a checked request.
|
|
|
|
// If an error occurs, it can be retrieved using SetSelectionCreateContextCookie.Check()
|
2012-05-10 23:01:42 +02:00
|
|
|
func SetSelectionCreateContextChecked(c *xgb.Conn, ContextLen uint32, Context string) SetSelectionCreateContextCookie {
|
2012-05-12 05:58:52 +02:00
|
|
|
if _, ok := c.Extensions["SELINUX"]; !ok {
|
|
|
|
panic("Cannot issue request 'SetSelectionCreateContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.")
|
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(true, false)
|
|
|
|
c.NewRequest(setSelectionCreateContextRequest(c, ContextLen, Context), cookie)
|
|
|
|
return SetSelectionCreateContextCookie{cookie}
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// Check returns an error if one occurred for checked requests that are not expecting a reply.
|
|
|
|
// This cannot be called for requests expecting a reply, nor for unchecked requests.
|
2012-05-10 23:01:42 +02:00
|
|
|
func (cook SetSelectionCreateContextCookie) Check() error {
|
|
|
|
return cook.Cookie.Check()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write request to wire for SetSelectionCreateContext
|
2012-05-11 05:57:34 +02:00
|
|
|
// setSelectionCreateContextRequest writes a SetSelectionCreateContext request to a byte slice.
|
2012-05-10 23:01:42 +02:00
|
|
|
func setSelectionCreateContextRequest(c *xgb.Conn, ContextLen uint32, Context string) []byte {
|
|
|
|
size := xgb.Pad((8 + xgb.Pad((int(ContextLen) * 1))))
|
|
|
|
b := 0
|
|
|
|
buf := make([]byte, size)
|
|
|
|
|
|
|
|
buf[b] = c.Extensions["SELINUX"]
|
|
|
|
b += 1
|
|
|
|
|
|
|
|
buf[b] = 15 // request opcode
|
|
|
|
b += 1
|
|
|
|
|
|
|
|
xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
|
|
|
|
b += 2
|
|
|
|
|
|
|
|
xgb.Put32(buf[b:], ContextLen)
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
copy(buf[b:], Context[:ContextLen])
|
|
|
|
b += xgb.Pad(int(ContextLen))
|
|
|
|
|
|
|
|
return buf
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// GetSelectionCreateContextCookie is a cookie used only for GetSelectionCreateContext requests.
|
2012-05-10 23:01:42 +02:00
|
|
|
type GetSelectionCreateContextCookie struct {
|
|
|
|
*xgb.Cookie
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// GetSelectionCreateContext sends a checked request.
|
|
|
|
// If an error occurs, it will be returned with the reply by calling GetSelectionCreateContextCookie.Reply()
|
2012-05-10 23:01:42 +02:00
|
|
|
func GetSelectionCreateContext(c *xgb.Conn) GetSelectionCreateContextCookie {
|
2012-05-12 05:58:52 +02:00
|
|
|
if _, ok := c.Extensions["SELINUX"]; !ok {
|
|
|
|
panic("Cannot issue request 'GetSelectionCreateContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.")
|
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(true, true)
|
|
|
|
c.NewRequest(getSelectionCreateContextRequest(c), cookie)
|
|
|
|
return GetSelectionCreateContextCookie{cookie}
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// GetSelectionCreateContextUnchecked sends an unchecked request.
|
|
|
|
// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
|
2012-05-10 23:01:42 +02:00
|
|
|
func GetSelectionCreateContextUnchecked(c *xgb.Conn) GetSelectionCreateContextCookie {
|
2012-05-12 05:58:52 +02:00
|
|
|
if _, ok := c.Extensions["SELINUX"]; !ok {
|
|
|
|
panic("Cannot issue request 'GetSelectionCreateContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.")
|
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(false, true)
|
|
|
|
c.NewRequest(getSelectionCreateContextRequest(c), cookie)
|
|
|
|
return GetSelectionCreateContextCookie{cookie}
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// GetSelectionCreateContextReply represents the data returned from a GetSelectionCreateContext request.
|
2012-05-10 23:01:42 +02:00
|
|
|
type GetSelectionCreateContextReply struct {
|
2012-05-11 05:57:34 +02:00
|
|
|
Sequence uint16 // sequence number of the request for this reply
|
|
|
|
Length uint32 // number of bytes in this reply
|
2012-05-10 23:01:42 +02:00
|
|
|
// padding: 1 bytes
|
|
|
|
ContextLen uint32
|
|
|
|
// padding: 20 bytes
|
|
|
|
Context string // size: xgb.Pad((int(ContextLen) * 1))
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// Reply blocks and returns the reply data for a GetSelectionCreateContext request.
|
2012-05-10 23:01:42 +02:00
|
|
|
func (cook GetSelectionCreateContextCookie) Reply() (*GetSelectionCreateContextReply, error) {
|
|
|
|
buf, err := cook.Cookie.Reply()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if buf == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
return getSelectionCreateContextReply(buf), nil
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// getSelectionCreateContextReply reads a byte slice into a GetSelectionCreateContextReply value.
|
2012-05-10 23:01:42 +02:00
|
|
|
func getSelectionCreateContextReply(buf []byte) *GetSelectionCreateContextReply {
|
|
|
|
v := new(GetSelectionCreateContextReply)
|
|
|
|
b := 1 // skip reply determinant
|
|
|
|
|
|
|
|
b += 1 // padding
|
|
|
|
|
|
|
|
v.Sequence = xgb.Get16(buf[b:])
|
|
|
|
b += 2
|
|
|
|
|
|
|
|
v.Length = xgb.Get32(buf[b:]) // 4-byte units
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
v.ContextLen = xgb.Get32(buf[b:])
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
b += 20 // padding
|
|
|
|
|
|
|
|
{
|
|
|
|
byteString := make([]byte, v.ContextLen)
|
|
|
|
copy(byteString[:v.ContextLen], buf[b:])
|
|
|
|
v.Context = string(byteString)
|
|
|
|
b += xgb.Pad(int(v.ContextLen))
|
|
|
|
}
|
|
|
|
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write request to wire for GetSelectionCreateContext
|
2012-05-11 05:57:34 +02:00
|
|
|
// getSelectionCreateContextRequest writes a GetSelectionCreateContext request to a byte slice.
|
2012-05-10 23:01:42 +02:00
|
|
|
func getSelectionCreateContextRequest(c *xgb.Conn) []byte {
|
|
|
|
size := 4
|
|
|
|
b := 0
|
|
|
|
buf := make([]byte, size)
|
|
|
|
|
|
|
|
buf[b] = c.Extensions["SELINUX"]
|
|
|
|
b += 1
|
|
|
|
|
|
|
|
buf[b] = 16 // request opcode
|
|
|
|
b += 1
|
|
|
|
|
|
|
|
xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
|
|
|
|
b += 2
|
|
|
|
|
|
|
|
return buf
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// SetSelectionUseContextCookie is a cookie used only for SetSelectionUseContext requests.
|
2012-05-10 23:01:42 +02:00
|
|
|
type SetSelectionUseContextCookie struct {
|
|
|
|
*xgb.Cookie
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// SetSelectionUseContext sends an unchecked request.
|
|
|
|
// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
|
2012-05-10 23:01:42 +02:00
|
|
|
func SetSelectionUseContext(c *xgb.Conn, ContextLen uint32, Context string) SetSelectionUseContextCookie {
|
2012-05-12 05:58:52 +02:00
|
|
|
if _, ok := c.Extensions["SELINUX"]; !ok {
|
|
|
|
panic("Cannot issue request 'SetSelectionUseContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.")
|
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(false, false)
|
|
|
|
c.NewRequest(setSelectionUseContextRequest(c, ContextLen, Context), cookie)
|
|
|
|
return SetSelectionUseContextCookie{cookie}
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// SetSelectionUseContextChecked sends a checked request.
|
|
|
|
// If an error occurs, it can be retrieved using SetSelectionUseContextCookie.Check()
|
2012-05-10 23:01:42 +02:00
|
|
|
func SetSelectionUseContextChecked(c *xgb.Conn, ContextLen uint32, Context string) SetSelectionUseContextCookie {
|
2012-05-12 05:58:52 +02:00
|
|
|
if _, ok := c.Extensions["SELINUX"]; !ok {
|
|
|
|
panic("Cannot issue request 'SetSelectionUseContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.")
|
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(true, false)
|
|
|
|
c.NewRequest(setSelectionUseContextRequest(c, ContextLen, Context), cookie)
|
|
|
|
return SetSelectionUseContextCookie{cookie}
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// Check returns an error if one occurred for checked requests that are not expecting a reply.
|
|
|
|
// This cannot be called for requests expecting a reply, nor for unchecked requests.
|
2012-05-10 23:01:42 +02:00
|
|
|
func (cook SetSelectionUseContextCookie) Check() error {
|
|
|
|
return cook.Cookie.Check()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write request to wire for SetSelectionUseContext
|
2012-05-11 05:57:34 +02:00
|
|
|
// setSelectionUseContextRequest writes a SetSelectionUseContext request to a byte slice.
|
2012-05-10 23:01:42 +02:00
|
|
|
func setSelectionUseContextRequest(c *xgb.Conn, ContextLen uint32, Context string) []byte {
|
|
|
|
size := xgb.Pad((8 + xgb.Pad((int(ContextLen) * 1))))
|
|
|
|
b := 0
|
|
|
|
buf := make([]byte, size)
|
|
|
|
|
|
|
|
buf[b] = c.Extensions["SELINUX"]
|
|
|
|
b += 1
|
|
|
|
|
|
|
|
buf[b] = 17 // request opcode
|
|
|
|
b += 1
|
|
|
|
|
|
|
|
xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
|
|
|
|
b += 2
|
|
|
|
|
|
|
|
xgb.Put32(buf[b:], ContextLen)
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
copy(buf[b:], Context[:ContextLen])
|
|
|
|
b += xgb.Pad(int(ContextLen))
|
|
|
|
|
|
|
|
return buf
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// GetSelectionUseContextCookie is a cookie used only for GetSelectionUseContext requests.
|
2012-05-10 23:01:42 +02:00
|
|
|
type GetSelectionUseContextCookie struct {
|
|
|
|
*xgb.Cookie
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// GetSelectionUseContext sends a checked request.
|
|
|
|
// If an error occurs, it will be returned with the reply by calling GetSelectionUseContextCookie.Reply()
|
2012-05-10 23:01:42 +02:00
|
|
|
func GetSelectionUseContext(c *xgb.Conn) GetSelectionUseContextCookie {
|
2012-05-12 05:58:52 +02:00
|
|
|
if _, ok := c.Extensions["SELINUX"]; !ok {
|
|
|
|
panic("Cannot issue request 'GetSelectionUseContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.")
|
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(true, true)
|
|
|
|
c.NewRequest(getSelectionUseContextRequest(c), cookie)
|
|
|
|
return GetSelectionUseContextCookie{cookie}
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// GetSelectionUseContextUnchecked sends an unchecked request.
|
|
|
|
// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
|
2012-05-10 23:01:42 +02:00
|
|
|
func GetSelectionUseContextUnchecked(c *xgb.Conn) GetSelectionUseContextCookie {
|
2012-05-12 05:58:52 +02:00
|
|
|
if _, ok := c.Extensions["SELINUX"]; !ok {
|
|
|
|
panic("Cannot issue request 'GetSelectionUseContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.")
|
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(false, true)
|
|
|
|
c.NewRequest(getSelectionUseContextRequest(c), cookie)
|
|
|
|
return GetSelectionUseContextCookie{cookie}
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// GetSelectionUseContextReply represents the data returned from a GetSelectionUseContext request.
|
2012-05-10 23:01:42 +02:00
|
|
|
type GetSelectionUseContextReply struct {
|
2012-05-11 05:57:34 +02:00
|
|
|
Sequence uint16 // sequence number of the request for this reply
|
|
|
|
Length uint32 // number of bytes in this reply
|
2012-05-10 23:01:42 +02:00
|
|
|
// padding: 1 bytes
|
|
|
|
ContextLen uint32
|
|
|
|
// padding: 20 bytes
|
|
|
|
Context string // size: xgb.Pad((int(ContextLen) * 1))
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// Reply blocks and returns the reply data for a GetSelectionUseContext request.
|
2012-05-10 23:01:42 +02:00
|
|
|
func (cook GetSelectionUseContextCookie) Reply() (*GetSelectionUseContextReply, error) {
|
|
|
|
buf, err := cook.Cookie.Reply()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if buf == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
return getSelectionUseContextReply(buf), nil
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// getSelectionUseContextReply reads a byte slice into a GetSelectionUseContextReply value.
|
2012-05-10 23:01:42 +02:00
|
|
|
func getSelectionUseContextReply(buf []byte) *GetSelectionUseContextReply {
|
|
|
|
v := new(GetSelectionUseContextReply)
|
|
|
|
b := 1 // skip reply determinant
|
|
|
|
|
|
|
|
b += 1 // padding
|
|
|
|
|
|
|
|
v.Sequence = xgb.Get16(buf[b:])
|
|
|
|
b += 2
|
|
|
|
|
|
|
|
v.Length = xgb.Get32(buf[b:]) // 4-byte units
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
v.ContextLen = xgb.Get32(buf[b:])
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
b += 20 // padding
|
|
|
|
|
|
|
|
{
|
|
|
|
byteString := make([]byte, v.ContextLen)
|
|
|
|
copy(byteString[:v.ContextLen], buf[b:])
|
|
|
|
v.Context = string(byteString)
|
|
|
|
b += xgb.Pad(int(v.ContextLen))
|
|
|
|
}
|
|
|
|
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write request to wire for GetSelectionUseContext
|
2012-05-11 05:57:34 +02:00
|
|
|
// getSelectionUseContextRequest writes a GetSelectionUseContext request to a byte slice.
|
2012-05-10 23:01:42 +02:00
|
|
|
func getSelectionUseContextRequest(c *xgb.Conn) []byte {
|
|
|
|
size := 4
|
|
|
|
b := 0
|
|
|
|
buf := make([]byte, size)
|
|
|
|
|
|
|
|
buf[b] = c.Extensions["SELINUX"]
|
|
|
|
b += 1
|
|
|
|
|
|
|
|
buf[b] = 18 // request opcode
|
|
|
|
b += 1
|
|
|
|
|
|
|
|
xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
|
|
|
|
b += 2
|
|
|
|
|
|
|
|
return buf
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// GetSelectionContextCookie is a cookie used only for GetSelectionContext requests.
|
2012-05-10 23:01:42 +02:00
|
|
|
type GetSelectionContextCookie struct {
|
|
|
|
*xgb.Cookie
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// GetSelectionContext sends a checked request.
|
|
|
|
// If an error occurs, it will be returned with the reply by calling GetSelectionContextCookie.Reply()
|
2012-05-10 23:01:42 +02:00
|
|
|
func GetSelectionContext(c *xgb.Conn, Selection xproto.Atom) GetSelectionContextCookie {
|
2012-05-12 05:58:52 +02:00
|
|
|
if _, ok := c.Extensions["SELINUX"]; !ok {
|
|
|
|
panic("Cannot issue request 'GetSelectionContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.")
|
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(true, true)
|
|
|
|
c.NewRequest(getSelectionContextRequest(c, Selection), cookie)
|
|
|
|
return GetSelectionContextCookie{cookie}
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// GetSelectionContextUnchecked sends an unchecked request.
|
|
|
|
// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
|
2012-05-10 23:01:42 +02:00
|
|
|
func GetSelectionContextUnchecked(c *xgb.Conn, Selection xproto.Atom) GetSelectionContextCookie {
|
2012-05-12 05:58:52 +02:00
|
|
|
if _, ok := c.Extensions["SELINUX"]; !ok {
|
|
|
|
panic("Cannot issue request 'GetSelectionContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.")
|
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(false, true)
|
|
|
|
c.NewRequest(getSelectionContextRequest(c, Selection), cookie)
|
|
|
|
return GetSelectionContextCookie{cookie}
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// GetSelectionContextReply represents the data returned from a GetSelectionContext request.
|
2012-05-10 23:01:42 +02:00
|
|
|
type GetSelectionContextReply struct {
|
2012-05-11 05:57:34 +02:00
|
|
|
Sequence uint16 // sequence number of the request for this reply
|
|
|
|
Length uint32 // number of bytes in this reply
|
2012-05-10 23:01:42 +02:00
|
|
|
// padding: 1 bytes
|
|
|
|
ContextLen uint32
|
|
|
|
// padding: 20 bytes
|
|
|
|
Context string // size: xgb.Pad((int(ContextLen) * 1))
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// Reply blocks and returns the reply data for a GetSelectionContext request.
|
2012-05-10 23:01:42 +02:00
|
|
|
func (cook GetSelectionContextCookie) Reply() (*GetSelectionContextReply, error) {
|
|
|
|
buf, err := cook.Cookie.Reply()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if buf == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
return getSelectionContextReply(buf), nil
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// getSelectionContextReply reads a byte slice into a GetSelectionContextReply value.
|
2012-05-10 23:01:42 +02:00
|
|
|
func getSelectionContextReply(buf []byte) *GetSelectionContextReply {
|
|
|
|
v := new(GetSelectionContextReply)
|
|
|
|
b := 1 // skip reply determinant
|
|
|
|
|
|
|
|
b += 1 // padding
|
|
|
|
|
|
|
|
v.Sequence = xgb.Get16(buf[b:])
|
|
|
|
b += 2
|
|
|
|
|
|
|
|
v.Length = xgb.Get32(buf[b:]) // 4-byte units
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
v.ContextLen = xgb.Get32(buf[b:])
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
b += 20 // padding
|
|
|
|
|
|
|
|
{
|
|
|
|
byteString := make([]byte, v.ContextLen)
|
|
|
|
copy(byteString[:v.ContextLen], buf[b:])
|
|
|
|
v.Context = string(byteString)
|
|
|
|
b += xgb.Pad(int(v.ContextLen))
|
|
|
|
}
|
|
|
|
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write request to wire for GetSelectionContext
|
2012-05-11 05:57:34 +02:00
|
|
|
// getSelectionContextRequest writes a GetSelectionContext request to a byte slice.
|
2012-05-10 23:01:42 +02:00
|
|
|
func getSelectionContextRequest(c *xgb.Conn, Selection xproto.Atom) []byte {
|
|
|
|
size := 8
|
|
|
|
b := 0
|
|
|
|
buf := make([]byte, size)
|
|
|
|
|
|
|
|
buf[b] = c.Extensions["SELINUX"]
|
|
|
|
b += 1
|
|
|
|
|
|
|
|
buf[b] = 19 // request opcode
|
|
|
|
b += 1
|
|
|
|
|
|
|
|
xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
|
|
|
|
b += 2
|
|
|
|
|
|
|
|
xgb.Put32(buf[b:], uint32(Selection))
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
return buf
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// GetSelectionDataContextCookie is a cookie used only for GetSelectionDataContext requests.
|
2012-05-10 23:01:42 +02:00
|
|
|
type GetSelectionDataContextCookie struct {
|
|
|
|
*xgb.Cookie
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// GetSelectionDataContext sends a checked request.
|
|
|
|
// If an error occurs, it will be returned with the reply by calling GetSelectionDataContextCookie.Reply()
|
2012-05-10 23:01:42 +02:00
|
|
|
func GetSelectionDataContext(c *xgb.Conn, Selection xproto.Atom) GetSelectionDataContextCookie {
|
2012-05-12 05:58:52 +02:00
|
|
|
if _, ok := c.Extensions["SELINUX"]; !ok {
|
|
|
|
panic("Cannot issue request 'GetSelectionDataContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.")
|
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(true, true)
|
|
|
|
c.NewRequest(getSelectionDataContextRequest(c, Selection), cookie)
|
|
|
|
return GetSelectionDataContextCookie{cookie}
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// GetSelectionDataContextUnchecked sends an unchecked request.
|
|
|
|
// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
|
2012-05-10 23:01:42 +02:00
|
|
|
func GetSelectionDataContextUnchecked(c *xgb.Conn, Selection xproto.Atom) GetSelectionDataContextCookie {
|
2012-05-12 05:58:52 +02:00
|
|
|
if _, ok := c.Extensions["SELINUX"]; !ok {
|
|
|
|
panic("Cannot issue request 'GetSelectionDataContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.")
|
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(false, true)
|
|
|
|
c.NewRequest(getSelectionDataContextRequest(c, Selection), cookie)
|
|
|
|
return GetSelectionDataContextCookie{cookie}
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// GetSelectionDataContextReply represents the data returned from a GetSelectionDataContext request.
|
2012-05-10 23:01:42 +02:00
|
|
|
type GetSelectionDataContextReply struct {
|
2012-05-11 05:57:34 +02:00
|
|
|
Sequence uint16 // sequence number of the request for this reply
|
|
|
|
Length uint32 // number of bytes in this reply
|
2012-05-10 23:01:42 +02:00
|
|
|
// padding: 1 bytes
|
|
|
|
ContextLen uint32
|
|
|
|
// padding: 20 bytes
|
|
|
|
Context string // size: xgb.Pad((int(ContextLen) * 1))
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// Reply blocks and returns the reply data for a GetSelectionDataContext request.
|
2012-05-10 23:01:42 +02:00
|
|
|
func (cook GetSelectionDataContextCookie) Reply() (*GetSelectionDataContextReply, error) {
|
|
|
|
buf, err := cook.Cookie.Reply()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if buf == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
return getSelectionDataContextReply(buf), nil
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// getSelectionDataContextReply reads a byte slice into a GetSelectionDataContextReply value.
|
2012-05-10 23:01:42 +02:00
|
|
|
func getSelectionDataContextReply(buf []byte) *GetSelectionDataContextReply {
|
|
|
|
v := new(GetSelectionDataContextReply)
|
|
|
|
b := 1 // skip reply determinant
|
|
|
|
|
|
|
|
b += 1 // padding
|
|
|
|
|
|
|
|
v.Sequence = xgb.Get16(buf[b:])
|
|
|
|
b += 2
|
|
|
|
|
|
|
|
v.Length = xgb.Get32(buf[b:]) // 4-byte units
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
v.ContextLen = xgb.Get32(buf[b:])
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
b += 20 // padding
|
|
|
|
|
|
|
|
{
|
|
|
|
byteString := make([]byte, v.ContextLen)
|
|
|
|
copy(byteString[:v.ContextLen], buf[b:])
|
|
|
|
v.Context = string(byteString)
|
|
|
|
b += xgb.Pad(int(v.ContextLen))
|
|
|
|
}
|
|
|
|
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write request to wire for GetSelectionDataContext
|
2012-05-11 05:57:34 +02:00
|
|
|
// getSelectionDataContextRequest writes a GetSelectionDataContext request to a byte slice.
|
2012-05-10 23:01:42 +02:00
|
|
|
func getSelectionDataContextRequest(c *xgb.Conn, Selection xproto.Atom) []byte {
|
|
|
|
size := 8
|
|
|
|
b := 0
|
|
|
|
buf := make([]byte, size)
|
|
|
|
|
|
|
|
buf[b] = c.Extensions["SELINUX"]
|
|
|
|
b += 1
|
|
|
|
|
|
|
|
buf[b] = 20 // request opcode
|
|
|
|
b += 1
|
|
|
|
|
|
|
|
xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
|
|
|
|
b += 2
|
|
|
|
|
|
|
|
xgb.Put32(buf[b:], uint32(Selection))
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
return buf
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// ListSelectionsCookie is a cookie used only for ListSelections requests.
|
2012-05-10 23:01:42 +02:00
|
|
|
type ListSelectionsCookie struct {
|
|
|
|
*xgb.Cookie
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// ListSelections sends a checked request.
|
|
|
|
// If an error occurs, it will be returned with the reply by calling ListSelectionsCookie.Reply()
|
2012-05-10 23:01:42 +02:00
|
|
|
func ListSelections(c *xgb.Conn) ListSelectionsCookie {
|
2012-05-12 05:58:52 +02:00
|
|
|
if _, ok := c.Extensions["SELINUX"]; !ok {
|
|
|
|
panic("Cannot issue request 'ListSelections' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.")
|
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(true, true)
|
|
|
|
c.NewRequest(listSelectionsRequest(c), cookie)
|
|
|
|
return ListSelectionsCookie{cookie}
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// ListSelectionsUnchecked sends an unchecked request.
|
|
|
|
// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
|
2012-05-10 23:01:42 +02:00
|
|
|
func ListSelectionsUnchecked(c *xgb.Conn) ListSelectionsCookie {
|
2012-05-12 05:58:52 +02:00
|
|
|
if _, ok := c.Extensions["SELINUX"]; !ok {
|
|
|
|
panic("Cannot issue request 'ListSelections' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.")
|
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(false, true)
|
|
|
|
c.NewRequest(listSelectionsRequest(c), cookie)
|
|
|
|
return ListSelectionsCookie{cookie}
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// ListSelectionsReply represents the data returned from a ListSelections request.
|
2012-05-10 23:01:42 +02:00
|
|
|
type ListSelectionsReply struct {
|
2012-05-11 05:57:34 +02:00
|
|
|
Sequence uint16 // sequence number of the request for this reply
|
|
|
|
Length uint32 // number of bytes in this reply
|
2012-05-10 23:01:42 +02:00
|
|
|
// padding: 1 bytes
|
|
|
|
SelectionsLen uint32
|
|
|
|
// padding: 20 bytes
|
|
|
|
Selections []ListItem // size: ListItemListSize(Selections)
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// Reply blocks and returns the reply data for a ListSelections request.
|
2012-05-10 23:01:42 +02:00
|
|
|
func (cook ListSelectionsCookie) Reply() (*ListSelectionsReply, error) {
|
|
|
|
buf, err := cook.Cookie.Reply()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if buf == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
return listSelectionsReply(buf), nil
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// listSelectionsReply reads a byte slice into a ListSelectionsReply value.
|
2012-05-10 23:01:42 +02:00
|
|
|
func listSelectionsReply(buf []byte) *ListSelectionsReply {
|
|
|
|
v := new(ListSelectionsReply)
|
|
|
|
b := 1 // skip reply determinant
|
|
|
|
|
|
|
|
b += 1 // padding
|
|
|
|
|
|
|
|
v.Sequence = xgb.Get16(buf[b:])
|
|
|
|
b += 2
|
|
|
|
|
|
|
|
v.Length = xgb.Get32(buf[b:]) // 4-byte units
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
v.SelectionsLen = xgb.Get32(buf[b:])
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
b += 20 // padding
|
|
|
|
|
|
|
|
v.Selections = make([]ListItem, v.SelectionsLen)
|
|
|
|
b += ListItemReadList(buf[b:], v.Selections)
|
|
|
|
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write request to wire for ListSelections
|
2012-05-11 05:57:34 +02:00
|
|
|
// listSelectionsRequest writes a ListSelections request to a byte slice.
|
2012-05-10 23:01:42 +02:00
|
|
|
func listSelectionsRequest(c *xgb.Conn) []byte {
|
|
|
|
size := 4
|
|
|
|
b := 0
|
|
|
|
buf := make([]byte, size)
|
|
|
|
|
|
|
|
buf[b] = c.Extensions["SELINUX"]
|
|
|
|
b += 1
|
|
|
|
|
|
|
|
buf[b] = 21 // request opcode
|
|
|
|
b += 1
|
|
|
|
|
|
|
|
xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
|
|
|
|
b += 2
|
|
|
|
|
|
|
|
return buf
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// GetClientContextCookie is a cookie used only for GetClientContext requests.
|
2012-05-10 23:01:42 +02:00
|
|
|
type GetClientContextCookie struct {
|
|
|
|
*xgb.Cookie
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// GetClientContext sends a checked request.
|
|
|
|
// If an error occurs, it will be returned with the reply by calling GetClientContextCookie.Reply()
|
2012-05-10 23:01:42 +02:00
|
|
|
func GetClientContext(c *xgb.Conn, Resource uint32) GetClientContextCookie {
|
2012-05-12 05:58:52 +02:00
|
|
|
if _, ok := c.Extensions["SELINUX"]; !ok {
|
|
|
|
panic("Cannot issue request 'GetClientContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.")
|
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(true, true)
|
|
|
|
c.NewRequest(getClientContextRequest(c, Resource), cookie)
|
|
|
|
return GetClientContextCookie{cookie}
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// GetClientContextUnchecked sends an unchecked request.
|
|
|
|
// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
|
2012-05-10 23:01:42 +02:00
|
|
|
func GetClientContextUnchecked(c *xgb.Conn, Resource uint32) GetClientContextCookie {
|
2012-05-12 05:58:52 +02:00
|
|
|
if _, ok := c.Extensions["SELINUX"]; !ok {
|
|
|
|
panic("Cannot issue request 'GetClientContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.")
|
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(false, true)
|
|
|
|
c.NewRequest(getClientContextRequest(c, Resource), cookie)
|
|
|
|
return GetClientContextCookie{cookie}
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// GetClientContextReply represents the data returned from a GetClientContext request.
|
2012-05-10 23:01:42 +02:00
|
|
|
type GetClientContextReply struct {
|
2012-05-11 05:57:34 +02:00
|
|
|
Sequence uint16 // sequence number of the request for this reply
|
|
|
|
Length uint32 // number of bytes in this reply
|
2012-05-10 23:01:42 +02:00
|
|
|
// padding: 1 bytes
|
|
|
|
ContextLen uint32
|
|
|
|
// padding: 20 bytes
|
|
|
|
Context string // size: xgb.Pad((int(ContextLen) * 1))
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// Reply blocks and returns the reply data for a GetClientContext request.
|
2012-05-10 23:01:42 +02:00
|
|
|
func (cook GetClientContextCookie) Reply() (*GetClientContextReply, error) {
|
|
|
|
buf, err := cook.Cookie.Reply()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if buf == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
return getClientContextReply(buf), nil
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// getClientContextReply reads a byte slice into a GetClientContextReply value.
|
2012-05-10 23:01:42 +02:00
|
|
|
func getClientContextReply(buf []byte) *GetClientContextReply {
|
|
|
|
v := new(GetClientContextReply)
|
|
|
|
b := 1 // skip reply determinant
|
|
|
|
|
|
|
|
b += 1 // padding
|
|
|
|
|
|
|
|
v.Sequence = xgb.Get16(buf[b:])
|
|
|
|
b += 2
|
|
|
|
|
|
|
|
v.Length = xgb.Get32(buf[b:]) // 4-byte units
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
v.ContextLen = xgb.Get32(buf[b:])
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
b += 20 // padding
|
|
|
|
|
|
|
|
{
|
|
|
|
byteString := make([]byte, v.ContextLen)
|
|
|
|
copy(byteString[:v.ContextLen], buf[b:])
|
|
|
|
v.Context = string(byteString)
|
|
|
|
b += xgb.Pad(int(v.ContextLen))
|
|
|
|
}
|
|
|
|
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write request to wire for GetClientContext
|
2012-05-11 05:57:34 +02:00
|
|
|
// getClientContextRequest writes a GetClientContext request to a byte slice.
|
2012-05-10 23:01:42 +02:00
|
|
|
func getClientContextRequest(c *xgb.Conn, Resource uint32) []byte {
|
|
|
|
size := 8
|
|
|
|
b := 0
|
|
|
|
buf := make([]byte, size)
|
|
|
|
|
|
|
|
buf[b] = c.Extensions["SELINUX"]
|
|
|
|
b += 1
|
|
|
|
|
|
|
|
buf[b] = 22 // request opcode
|
|
|
|
b += 1
|
|
|
|
|
|
|
|
xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
|
|
|
|
b += 2
|
|
|
|
|
|
|
|
xgb.Put32(buf[b:], Resource)
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
return buf
|
|
|
|
}
|