github.com/BurntSushi/xgb@v0.0.0-20210121224620-deaf085860bc/xselinux/xselinux.go (about) 1 // Package xselinux is the X client API for the SELinux extension. 2 package xselinux 3 4 // This file is automatically generated from xselinux.xml. Edit at your peril! 5 6 import ( 7 "github.com/BurntSushi/xgb" 8 9 "github.com/BurntSushi/xgb/xproto" 10 ) 11 12 // Init must be called before using the SELinux extension. 13 func Init(c *xgb.Conn) error { 14 reply, err := xproto.QueryExtension(c, 7, "SELinux").Reply() 15 switch { 16 case err != nil: 17 return err 18 case !reply.Present: 19 return xgb.Errorf("No extension named SELinux could be found on on the server.") 20 } 21 22 c.ExtLock.Lock() 23 c.Extensions["SELinux"] = reply.MajorOpcode 24 c.ExtLock.Unlock() 25 for evNum, fun := range xgb.NewExtEventFuncs["SELinux"] { 26 xgb.NewEventFuncs[int(reply.FirstEvent)+evNum] = fun 27 } 28 for errNum, fun := range xgb.NewExtErrorFuncs["SELinux"] { 29 xgb.NewErrorFuncs[int(reply.FirstError)+errNum] = fun 30 } 31 return nil 32 } 33 34 func init() { 35 xgb.NewExtEventFuncs["SELinux"] = make(map[int]xgb.NewEventFun) 36 xgb.NewExtErrorFuncs["SELinux"] = make(map[int]xgb.NewErrorFun) 37 } 38 39 type ListItem struct { 40 Name xproto.Atom 41 ObjectContextLen uint32 42 DataContextLen uint32 43 ObjectContext string // size: xgb.Pad((int(ObjectContextLen) * 1)) 44 DataContext string // size: xgb.Pad((int(DataContextLen) * 1)) 45 } 46 47 // ListItemRead reads a byte slice into a ListItem value. 48 func ListItemRead(buf []byte, v *ListItem) int { 49 b := 0 50 51 v.Name = xproto.Atom(xgb.Get32(buf[b:])) 52 b += 4 53 54 v.ObjectContextLen = xgb.Get32(buf[b:]) 55 b += 4 56 57 v.DataContextLen = xgb.Get32(buf[b:]) 58 b += 4 59 60 { 61 byteString := make([]byte, v.ObjectContextLen) 62 copy(byteString[:v.ObjectContextLen], buf[b:]) 63 v.ObjectContext = string(byteString) 64 b += int(v.ObjectContextLen) 65 } 66 67 { 68 byteString := make([]byte, v.DataContextLen) 69 copy(byteString[:v.DataContextLen], buf[b:]) 70 v.DataContext = string(byteString) 71 b += int(v.DataContextLen) 72 } 73 74 return b 75 } 76 77 // ListItemReadList reads a byte slice into a list of ListItem values. 78 func ListItemReadList(buf []byte, dest []ListItem) int { 79 b := 0 80 for i := 0; i < len(dest); i++ { 81 dest[i] = ListItem{} 82 b += ListItemRead(buf[b:], &dest[i]) 83 } 84 return xgb.Pad(b) 85 } 86 87 // Bytes writes a ListItem value to a byte slice. 88 func (v ListItem) Bytes() []byte { 89 buf := make([]byte, ((12 + xgb.Pad((int(v.ObjectContextLen) * 1))) + xgb.Pad((int(v.DataContextLen) * 1)))) 90 b := 0 91 92 xgb.Put32(buf[b:], uint32(v.Name)) 93 b += 4 94 95 xgb.Put32(buf[b:], v.ObjectContextLen) 96 b += 4 97 98 xgb.Put32(buf[b:], v.DataContextLen) 99 b += 4 100 101 copy(buf[b:], v.ObjectContext[:v.ObjectContextLen]) 102 b += int(v.ObjectContextLen) 103 104 copy(buf[b:], v.DataContext[:v.DataContextLen]) 105 b += int(v.DataContextLen) 106 107 return buf[:b] 108 } 109 110 // ListItemListBytes writes a list of ListItem values to a byte slice. 111 func ListItemListBytes(buf []byte, list []ListItem) int { 112 b := 0 113 var structBytes []byte 114 for _, item := range list { 115 structBytes = item.Bytes() 116 copy(buf[b:], structBytes) 117 b += len(structBytes) 118 } 119 return xgb.Pad(b) 120 } 121 122 // ListItemListSize computes the size (bytes) of a list of ListItem values. 123 func ListItemListSize(list []ListItem) int { 124 size := 0 125 for _, item := range list { 126 size += ((12 + xgb.Pad((int(item.ObjectContextLen) * 1))) + xgb.Pad((int(item.DataContextLen) * 1))) 127 } 128 return size 129 } 130 131 // Skipping definition for base type 'Bool' 132 133 // Skipping definition for base type 'Byte' 134 135 // Skipping definition for base type 'Card8' 136 137 // Skipping definition for base type 'Char' 138 139 // Skipping definition for base type 'Void' 140 141 // Skipping definition for base type 'Double' 142 143 // Skipping definition for base type 'Float' 144 145 // Skipping definition for base type 'Int16' 146 147 // Skipping definition for base type 'Int32' 148 149 // Skipping definition for base type 'Int8' 150 151 // Skipping definition for base type 'Card16' 152 153 // Skipping definition for base type 'Card32' 154 155 // GetClientContextCookie is a cookie used only for GetClientContext requests. 156 type GetClientContextCookie struct { 157 *xgb.Cookie 158 } 159 160 // GetClientContext sends a checked request. 161 // If an error occurs, it will be returned with the reply by calling GetClientContextCookie.Reply() 162 func GetClientContext(c *xgb.Conn, Resource uint32) GetClientContextCookie { 163 c.ExtLock.RLock() 164 defer c.ExtLock.RUnlock() 165 if _, ok := c.Extensions["SELinux"]; !ok { 166 panic("Cannot issue request 'GetClientContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") 167 } 168 cookie := c.NewCookie(true, true) 169 c.NewRequest(getClientContextRequest(c, Resource), cookie) 170 return GetClientContextCookie{cookie} 171 } 172 173 // GetClientContextUnchecked sends an unchecked request. 174 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 175 func GetClientContextUnchecked(c *xgb.Conn, Resource uint32) GetClientContextCookie { 176 c.ExtLock.RLock() 177 defer c.ExtLock.RUnlock() 178 if _, ok := c.Extensions["SELinux"]; !ok { 179 panic("Cannot issue request 'GetClientContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") 180 } 181 cookie := c.NewCookie(false, true) 182 c.NewRequest(getClientContextRequest(c, Resource), cookie) 183 return GetClientContextCookie{cookie} 184 } 185 186 // GetClientContextReply represents the data returned from a GetClientContext request. 187 type GetClientContextReply struct { 188 Sequence uint16 // sequence number of the request for this reply 189 Length uint32 // number of bytes in this reply 190 // padding: 1 bytes 191 ContextLen uint32 192 // padding: 20 bytes 193 Context string // size: xgb.Pad((int(ContextLen) * 1)) 194 } 195 196 // Reply blocks and returns the reply data for a GetClientContext request. 197 func (cook GetClientContextCookie) Reply() (*GetClientContextReply, error) { 198 buf, err := cook.Cookie.Reply() 199 if err != nil { 200 return nil, err 201 } 202 if buf == nil { 203 return nil, nil 204 } 205 return getClientContextReply(buf), nil 206 } 207 208 // getClientContextReply reads a byte slice into a GetClientContextReply value. 209 func getClientContextReply(buf []byte) *GetClientContextReply { 210 v := new(GetClientContextReply) 211 b := 1 // skip reply determinant 212 213 b += 1 // padding 214 215 v.Sequence = xgb.Get16(buf[b:]) 216 b += 2 217 218 v.Length = xgb.Get32(buf[b:]) // 4-byte units 219 b += 4 220 221 v.ContextLen = xgb.Get32(buf[b:]) 222 b += 4 223 224 b += 20 // padding 225 226 { 227 byteString := make([]byte, v.ContextLen) 228 copy(byteString[:v.ContextLen], buf[b:]) 229 v.Context = string(byteString) 230 b += int(v.ContextLen) 231 } 232 233 return v 234 } 235 236 // Write request to wire for GetClientContext 237 // getClientContextRequest writes a GetClientContext request to a byte slice. 238 func getClientContextRequest(c *xgb.Conn, Resource uint32) []byte { 239 size := 8 240 b := 0 241 buf := make([]byte, size) 242 243 c.ExtLock.RLock() 244 buf[b] = c.Extensions["SELinux"] 245 c.ExtLock.RUnlock() 246 b += 1 247 248 buf[b] = 22 // request opcode 249 b += 1 250 251 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 252 b += 2 253 254 xgb.Put32(buf[b:], Resource) 255 b += 4 256 257 return buf 258 } 259 260 // GetDeviceContextCookie is a cookie used only for GetDeviceContext requests. 261 type GetDeviceContextCookie struct { 262 *xgb.Cookie 263 } 264 265 // GetDeviceContext sends a checked request. 266 // If an error occurs, it will be returned with the reply by calling GetDeviceContextCookie.Reply() 267 func GetDeviceContext(c *xgb.Conn, Device uint32) GetDeviceContextCookie { 268 c.ExtLock.RLock() 269 defer c.ExtLock.RUnlock() 270 if _, ok := c.Extensions["SELinux"]; !ok { 271 panic("Cannot issue request 'GetDeviceContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") 272 } 273 cookie := c.NewCookie(true, true) 274 c.NewRequest(getDeviceContextRequest(c, Device), cookie) 275 return GetDeviceContextCookie{cookie} 276 } 277 278 // GetDeviceContextUnchecked sends an unchecked request. 279 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 280 func GetDeviceContextUnchecked(c *xgb.Conn, Device uint32) GetDeviceContextCookie { 281 c.ExtLock.RLock() 282 defer c.ExtLock.RUnlock() 283 if _, ok := c.Extensions["SELinux"]; !ok { 284 panic("Cannot issue request 'GetDeviceContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") 285 } 286 cookie := c.NewCookie(false, true) 287 c.NewRequest(getDeviceContextRequest(c, Device), cookie) 288 return GetDeviceContextCookie{cookie} 289 } 290 291 // GetDeviceContextReply represents the data returned from a GetDeviceContext request. 292 type GetDeviceContextReply struct { 293 Sequence uint16 // sequence number of the request for this reply 294 Length uint32 // number of bytes in this reply 295 // padding: 1 bytes 296 ContextLen uint32 297 // padding: 20 bytes 298 Context string // size: xgb.Pad((int(ContextLen) * 1)) 299 } 300 301 // Reply blocks and returns the reply data for a GetDeviceContext request. 302 func (cook GetDeviceContextCookie) Reply() (*GetDeviceContextReply, error) { 303 buf, err := cook.Cookie.Reply() 304 if err != nil { 305 return nil, err 306 } 307 if buf == nil { 308 return nil, nil 309 } 310 return getDeviceContextReply(buf), nil 311 } 312 313 // getDeviceContextReply reads a byte slice into a GetDeviceContextReply value. 314 func getDeviceContextReply(buf []byte) *GetDeviceContextReply { 315 v := new(GetDeviceContextReply) 316 b := 1 // skip reply determinant 317 318 b += 1 // padding 319 320 v.Sequence = xgb.Get16(buf[b:]) 321 b += 2 322 323 v.Length = xgb.Get32(buf[b:]) // 4-byte units 324 b += 4 325 326 v.ContextLen = xgb.Get32(buf[b:]) 327 b += 4 328 329 b += 20 // padding 330 331 { 332 byteString := make([]byte, v.ContextLen) 333 copy(byteString[:v.ContextLen], buf[b:]) 334 v.Context = string(byteString) 335 b += int(v.ContextLen) 336 } 337 338 return v 339 } 340 341 // Write request to wire for GetDeviceContext 342 // getDeviceContextRequest writes a GetDeviceContext request to a byte slice. 343 func getDeviceContextRequest(c *xgb.Conn, Device uint32) []byte { 344 size := 8 345 b := 0 346 buf := make([]byte, size) 347 348 c.ExtLock.RLock() 349 buf[b] = c.Extensions["SELinux"] 350 c.ExtLock.RUnlock() 351 b += 1 352 353 buf[b] = 4 // request opcode 354 b += 1 355 356 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 357 b += 2 358 359 xgb.Put32(buf[b:], Device) 360 b += 4 361 362 return buf 363 } 364 365 // GetDeviceCreateContextCookie is a cookie used only for GetDeviceCreateContext requests. 366 type GetDeviceCreateContextCookie struct { 367 *xgb.Cookie 368 } 369 370 // GetDeviceCreateContext sends a checked request. 371 // If an error occurs, it will be returned with the reply by calling GetDeviceCreateContextCookie.Reply() 372 func GetDeviceCreateContext(c *xgb.Conn) GetDeviceCreateContextCookie { 373 c.ExtLock.RLock() 374 defer c.ExtLock.RUnlock() 375 if _, ok := c.Extensions["SELinux"]; !ok { 376 panic("Cannot issue request 'GetDeviceCreateContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") 377 } 378 cookie := c.NewCookie(true, true) 379 c.NewRequest(getDeviceCreateContextRequest(c), cookie) 380 return GetDeviceCreateContextCookie{cookie} 381 } 382 383 // GetDeviceCreateContextUnchecked sends an unchecked request. 384 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 385 func GetDeviceCreateContextUnchecked(c *xgb.Conn) GetDeviceCreateContextCookie { 386 c.ExtLock.RLock() 387 defer c.ExtLock.RUnlock() 388 if _, ok := c.Extensions["SELinux"]; !ok { 389 panic("Cannot issue request 'GetDeviceCreateContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") 390 } 391 cookie := c.NewCookie(false, true) 392 c.NewRequest(getDeviceCreateContextRequest(c), cookie) 393 return GetDeviceCreateContextCookie{cookie} 394 } 395 396 // GetDeviceCreateContextReply represents the data returned from a GetDeviceCreateContext request. 397 type GetDeviceCreateContextReply struct { 398 Sequence uint16 // sequence number of the request for this reply 399 Length uint32 // number of bytes in this reply 400 // padding: 1 bytes 401 ContextLen uint32 402 // padding: 20 bytes 403 Context string // size: xgb.Pad((int(ContextLen) * 1)) 404 } 405 406 // Reply blocks and returns the reply data for a GetDeviceCreateContext request. 407 func (cook GetDeviceCreateContextCookie) Reply() (*GetDeviceCreateContextReply, error) { 408 buf, err := cook.Cookie.Reply() 409 if err != nil { 410 return nil, err 411 } 412 if buf == nil { 413 return nil, nil 414 } 415 return getDeviceCreateContextReply(buf), nil 416 } 417 418 // getDeviceCreateContextReply reads a byte slice into a GetDeviceCreateContextReply value. 419 func getDeviceCreateContextReply(buf []byte) *GetDeviceCreateContextReply { 420 v := new(GetDeviceCreateContextReply) 421 b := 1 // skip reply determinant 422 423 b += 1 // padding 424 425 v.Sequence = xgb.Get16(buf[b:]) 426 b += 2 427 428 v.Length = xgb.Get32(buf[b:]) // 4-byte units 429 b += 4 430 431 v.ContextLen = xgb.Get32(buf[b:]) 432 b += 4 433 434 b += 20 // padding 435 436 { 437 byteString := make([]byte, v.ContextLen) 438 copy(byteString[:v.ContextLen], buf[b:]) 439 v.Context = string(byteString) 440 b += int(v.ContextLen) 441 } 442 443 return v 444 } 445 446 // Write request to wire for GetDeviceCreateContext 447 // getDeviceCreateContextRequest writes a GetDeviceCreateContext request to a byte slice. 448 func getDeviceCreateContextRequest(c *xgb.Conn) []byte { 449 size := 4 450 b := 0 451 buf := make([]byte, size) 452 453 c.ExtLock.RLock() 454 buf[b] = c.Extensions["SELinux"] 455 c.ExtLock.RUnlock() 456 b += 1 457 458 buf[b] = 2 // request opcode 459 b += 1 460 461 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 462 b += 2 463 464 return buf 465 } 466 467 // GetPropertyContextCookie is a cookie used only for GetPropertyContext requests. 468 type GetPropertyContextCookie struct { 469 *xgb.Cookie 470 } 471 472 // GetPropertyContext sends a checked request. 473 // If an error occurs, it will be returned with the reply by calling GetPropertyContextCookie.Reply() 474 func GetPropertyContext(c *xgb.Conn, Window xproto.Window, Property xproto.Atom) GetPropertyContextCookie { 475 c.ExtLock.RLock() 476 defer c.ExtLock.RUnlock() 477 if _, ok := c.Extensions["SELinux"]; !ok { 478 panic("Cannot issue request 'GetPropertyContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") 479 } 480 cookie := c.NewCookie(true, true) 481 c.NewRequest(getPropertyContextRequest(c, Window, Property), cookie) 482 return GetPropertyContextCookie{cookie} 483 } 484 485 // GetPropertyContextUnchecked sends an unchecked request. 486 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 487 func GetPropertyContextUnchecked(c *xgb.Conn, Window xproto.Window, Property xproto.Atom) GetPropertyContextCookie { 488 c.ExtLock.RLock() 489 defer c.ExtLock.RUnlock() 490 if _, ok := c.Extensions["SELinux"]; !ok { 491 panic("Cannot issue request 'GetPropertyContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") 492 } 493 cookie := c.NewCookie(false, true) 494 c.NewRequest(getPropertyContextRequest(c, Window, Property), cookie) 495 return GetPropertyContextCookie{cookie} 496 } 497 498 // GetPropertyContextReply represents the data returned from a GetPropertyContext request. 499 type GetPropertyContextReply struct { 500 Sequence uint16 // sequence number of the request for this reply 501 Length uint32 // number of bytes in this reply 502 // padding: 1 bytes 503 ContextLen uint32 504 // padding: 20 bytes 505 Context string // size: xgb.Pad((int(ContextLen) * 1)) 506 } 507 508 // Reply blocks and returns the reply data for a GetPropertyContext request. 509 func (cook GetPropertyContextCookie) Reply() (*GetPropertyContextReply, error) { 510 buf, err := cook.Cookie.Reply() 511 if err != nil { 512 return nil, err 513 } 514 if buf == nil { 515 return nil, nil 516 } 517 return getPropertyContextReply(buf), nil 518 } 519 520 // getPropertyContextReply reads a byte slice into a GetPropertyContextReply value. 521 func getPropertyContextReply(buf []byte) *GetPropertyContextReply { 522 v := new(GetPropertyContextReply) 523 b := 1 // skip reply determinant 524 525 b += 1 // padding 526 527 v.Sequence = xgb.Get16(buf[b:]) 528 b += 2 529 530 v.Length = xgb.Get32(buf[b:]) // 4-byte units 531 b += 4 532 533 v.ContextLen = xgb.Get32(buf[b:]) 534 b += 4 535 536 b += 20 // padding 537 538 { 539 byteString := make([]byte, v.ContextLen) 540 copy(byteString[:v.ContextLen], buf[b:]) 541 v.Context = string(byteString) 542 b += int(v.ContextLen) 543 } 544 545 return v 546 } 547 548 // Write request to wire for GetPropertyContext 549 // getPropertyContextRequest writes a GetPropertyContext request to a byte slice. 550 func getPropertyContextRequest(c *xgb.Conn, Window xproto.Window, Property xproto.Atom) []byte { 551 size := 12 552 b := 0 553 buf := make([]byte, size) 554 555 c.ExtLock.RLock() 556 buf[b] = c.Extensions["SELinux"] 557 c.ExtLock.RUnlock() 558 b += 1 559 560 buf[b] = 12 // request opcode 561 b += 1 562 563 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 564 b += 2 565 566 xgb.Put32(buf[b:], uint32(Window)) 567 b += 4 568 569 xgb.Put32(buf[b:], uint32(Property)) 570 b += 4 571 572 return buf 573 } 574 575 // GetPropertyCreateContextCookie is a cookie used only for GetPropertyCreateContext requests. 576 type GetPropertyCreateContextCookie struct { 577 *xgb.Cookie 578 } 579 580 // GetPropertyCreateContext sends a checked request. 581 // If an error occurs, it will be returned with the reply by calling GetPropertyCreateContextCookie.Reply() 582 func GetPropertyCreateContext(c *xgb.Conn) GetPropertyCreateContextCookie { 583 c.ExtLock.RLock() 584 defer c.ExtLock.RUnlock() 585 if _, ok := c.Extensions["SELinux"]; !ok { 586 panic("Cannot issue request 'GetPropertyCreateContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") 587 } 588 cookie := c.NewCookie(true, true) 589 c.NewRequest(getPropertyCreateContextRequest(c), cookie) 590 return GetPropertyCreateContextCookie{cookie} 591 } 592 593 // GetPropertyCreateContextUnchecked sends an unchecked request. 594 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 595 func GetPropertyCreateContextUnchecked(c *xgb.Conn) GetPropertyCreateContextCookie { 596 c.ExtLock.RLock() 597 defer c.ExtLock.RUnlock() 598 if _, ok := c.Extensions["SELinux"]; !ok { 599 panic("Cannot issue request 'GetPropertyCreateContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") 600 } 601 cookie := c.NewCookie(false, true) 602 c.NewRequest(getPropertyCreateContextRequest(c), cookie) 603 return GetPropertyCreateContextCookie{cookie} 604 } 605 606 // GetPropertyCreateContextReply represents the data returned from a GetPropertyCreateContext request. 607 type GetPropertyCreateContextReply struct { 608 Sequence uint16 // sequence number of the request for this reply 609 Length uint32 // number of bytes in this reply 610 // padding: 1 bytes 611 ContextLen uint32 612 // padding: 20 bytes 613 Context string // size: xgb.Pad((int(ContextLen) * 1)) 614 } 615 616 // Reply blocks and returns the reply data for a GetPropertyCreateContext request. 617 func (cook GetPropertyCreateContextCookie) Reply() (*GetPropertyCreateContextReply, error) { 618 buf, err := cook.Cookie.Reply() 619 if err != nil { 620 return nil, err 621 } 622 if buf == nil { 623 return nil, nil 624 } 625 return getPropertyCreateContextReply(buf), nil 626 } 627 628 // getPropertyCreateContextReply reads a byte slice into a GetPropertyCreateContextReply value. 629 func getPropertyCreateContextReply(buf []byte) *GetPropertyCreateContextReply { 630 v := new(GetPropertyCreateContextReply) 631 b := 1 // skip reply determinant 632 633 b += 1 // padding 634 635 v.Sequence = xgb.Get16(buf[b:]) 636 b += 2 637 638 v.Length = xgb.Get32(buf[b:]) // 4-byte units 639 b += 4 640 641 v.ContextLen = xgb.Get32(buf[b:]) 642 b += 4 643 644 b += 20 // padding 645 646 { 647 byteString := make([]byte, v.ContextLen) 648 copy(byteString[:v.ContextLen], buf[b:]) 649 v.Context = string(byteString) 650 b += int(v.ContextLen) 651 } 652 653 return v 654 } 655 656 // Write request to wire for GetPropertyCreateContext 657 // getPropertyCreateContextRequest writes a GetPropertyCreateContext request to a byte slice. 658 func getPropertyCreateContextRequest(c *xgb.Conn) []byte { 659 size := 4 660 b := 0 661 buf := make([]byte, size) 662 663 c.ExtLock.RLock() 664 buf[b] = c.Extensions["SELinux"] 665 c.ExtLock.RUnlock() 666 b += 1 667 668 buf[b] = 9 // request opcode 669 b += 1 670 671 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 672 b += 2 673 674 return buf 675 } 676 677 // GetPropertyDataContextCookie is a cookie used only for GetPropertyDataContext requests. 678 type GetPropertyDataContextCookie struct { 679 *xgb.Cookie 680 } 681 682 // GetPropertyDataContext sends a checked request. 683 // If an error occurs, it will be returned with the reply by calling GetPropertyDataContextCookie.Reply() 684 func GetPropertyDataContext(c *xgb.Conn, Window xproto.Window, Property xproto.Atom) GetPropertyDataContextCookie { 685 c.ExtLock.RLock() 686 defer c.ExtLock.RUnlock() 687 if _, ok := c.Extensions["SELinux"]; !ok { 688 panic("Cannot issue request 'GetPropertyDataContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") 689 } 690 cookie := c.NewCookie(true, true) 691 c.NewRequest(getPropertyDataContextRequest(c, Window, Property), cookie) 692 return GetPropertyDataContextCookie{cookie} 693 } 694 695 // GetPropertyDataContextUnchecked sends an unchecked request. 696 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 697 func GetPropertyDataContextUnchecked(c *xgb.Conn, Window xproto.Window, Property xproto.Atom) GetPropertyDataContextCookie { 698 c.ExtLock.RLock() 699 defer c.ExtLock.RUnlock() 700 if _, ok := c.Extensions["SELinux"]; !ok { 701 panic("Cannot issue request 'GetPropertyDataContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") 702 } 703 cookie := c.NewCookie(false, true) 704 c.NewRequest(getPropertyDataContextRequest(c, Window, Property), cookie) 705 return GetPropertyDataContextCookie{cookie} 706 } 707 708 // GetPropertyDataContextReply represents the data returned from a GetPropertyDataContext request. 709 type GetPropertyDataContextReply struct { 710 Sequence uint16 // sequence number of the request for this reply 711 Length uint32 // number of bytes in this reply 712 // padding: 1 bytes 713 ContextLen uint32 714 // padding: 20 bytes 715 Context string // size: xgb.Pad((int(ContextLen) * 1)) 716 } 717 718 // Reply blocks and returns the reply data for a GetPropertyDataContext request. 719 func (cook GetPropertyDataContextCookie) Reply() (*GetPropertyDataContextReply, error) { 720 buf, err := cook.Cookie.Reply() 721 if err != nil { 722 return nil, err 723 } 724 if buf == nil { 725 return nil, nil 726 } 727 return getPropertyDataContextReply(buf), nil 728 } 729 730 // getPropertyDataContextReply reads a byte slice into a GetPropertyDataContextReply value. 731 func getPropertyDataContextReply(buf []byte) *GetPropertyDataContextReply { 732 v := new(GetPropertyDataContextReply) 733 b := 1 // skip reply determinant 734 735 b += 1 // padding 736 737 v.Sequence = xgb.Get16(buf[b:]) 738 b += 2 739 740 v.Length = xgb.Get32(buf[b:]) // 4-byte units 741 b += 4 742 743 v.ContextLen = xgb.Get32(buf[b:]) 744 b += 4 745 746 b += 20 // padding 747 748 { 749 byteString := make([]byte, v.ContextLen) 750 copy(byteString[:v.ContextLen], buf[b:]) 751 v.Context = string(byteString) 752 b += int(v.ContextLen) 753 } 754 755 return v 756 } 757 758 // Write request to wire for GetPropertyDataContext 759 // getPropertyDataContextRequest writes a GetPropertyDataContext request to a byte slice. 760 func getPropertyDataContextRequest(c *xgb.Conn, Window xproto.Window, Property xproto.Atom) []byte { 761 size := 12 762 b := 0 763 buf := make([]byte, size) 764 765 c.ExtLock.RLock() 766 buf[b] = c.Extensions["SELinux"] 767 c.ExtLock.RUnlock() 768 b += 1 769 770 buf[b] = 13 // request opcode 771 b += 1 772 773 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 774 b += 2 775 776 xgb.Put32(buf[b:], uint32(Window)) 777 b += 4 778 779 xgb.Put32(buf[b:], uint32(Property)) 780 b += 4 781 782 return buf 783 } 784 785 // GetPropertyUseContextCookie is a cookie used only for GetPropertyUseContext requests. 786 type GetPropertyUseContextCookie struct { 787 *xgb.Cookie 788 } 789 790 // GetPropertyUseContext sends a checked request. 791 // If an error occurs, it will be returned with the reply by calling GetPropertyUseContextCookie.Reply() 792 func GetPropertyUseContext(c *xgb.Conn) GetPropertyUseContextCookie { 793 c.ExtLock.RLock() 794 defer c.ExtLock.RUnlock() 795 if _, ok := c.Extensions["SELinux"]; !ok { 796 panic("Cannot issue request 'GetPropertyUseContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") 797 } 798 cookie := c.NewCookie(true, true) 799 c.NewRequest(getPropertyUseContextRequest(c), cookie) 800 return GetPropertyUseContextCookie{cookie} 801 } 802 803 // GetPropertyUseContextUnchecked sends an unchecked request. 804 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 805 func GetPropertyUseContextUnchecked(c *xgb.Conn) GetPropertyUseContextCookie { 806 c.ExtLock.RLock() 807 defer c.ExtLock.RUnlock() 808 if _, ok := c.Extensions["SELinux"]; !ok { 809 panic("Cannot issue request 'GetPropertyUseContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") 810 } 811 cookie := c.NewCookie(false, true) 812 c.NewRequest(getPropertyUseContextRequest(c), cookie) 813 return GetPropertyUseContextCookie{cookie} 814 } 815 816 // GetPropertyUseContextReply represents the data returned from a GetPropertyUseContext request. 817 type GetPropertyUseContextReply struct { 818 Sequence uint16 // sequence number of the request for this reply 819 Length uint32 // number of bytes in this reply 820 // padding: 1 bytes 821 ContextLen uint32 822 // padding: 20 bytes 823 Context string // size: xgb.Pad((int(ContextLen) * 1)) 824 } 825 826 // Reply blocks and returns the reply data for a GetPropertyUseContext request. 827 func (cook GetPropertyUseContextCookie) Reply() (*GetPropertyUseContextReply, error) { 828 buf, err := cook.Cookie.Reply() 829 if err != nil { 830 return nil, err 831 } 832 if buf == nil { 833 return nil, nil 834 } 835 return getPropertyUseContextReply(buf), nil 836 } 837 838 // getPropertyUseContextReply reads a byte slice into a GetPropertyUseContextReply value. 839 func getPropertyUseContextReply(buf []byte) *GetPropertyUseContextReply { 840 v := new(GetPropertyUseContextReply) 841 b := 1 // skip reply determinant 842 843 b += 1 // padding 844 845 v.Sequence = xgb.Get16(buf[b:]) 846 b += 2 847 848 v.Length = xgb.Get32(buf[b:]) // 4-byte units 849 b += 4 850 851 v.ContextLen = xgb.Get32(buf[b:]) 852 b += 4 853 854 b += 20 // padding 855 856 { 857 byteString := make([]byte, v.ContextLen) 858 copy(byteString[:v.ContextLen], buf[b:]) 859 v.Context = string(byteString) 860 b += int(v.ContextLen) 861 } 862 863 return v 864 } 865 866 // Write request to wire for GetPropertyUseContext 867 // getPropertyUseContextRequest writes a GetPropertyUseContext request to a byte slice. 868 func getPropertyUseContextRequest(c *xgb.Conn) []byte { 869 size := 4 870 b := 0 871 buf := make([]byte, size) 872 873 c.ExtLock.RLock() 874 buf[b] = c.Extensions["SELinux"] 875 c.ExtLock.RUnlock() 876 b += 1 877 878 buf[b] = 11 // request opcode 879 b += 1 880 881 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 882 b += 2 883 884 return buf 885 } 886 887 // GetSelectionContextCookie is a cookie used only for GetSelectionContext requests. 888 type GetSelectionContextCookie struct { 889 *xgb.Cookie 890 } 891 892 // GetSelectionContext sends a checked request. 893 // If an error occurs, it will be returned with the reply by calling GetSelectionContextCookie.Reply() 894 func GetSelectionContext(c *xgb.Conn, Selection xproto.Atom) GetSelectionContextCookie { 895 c.ExtLock.RLock() 896 defer c.ExtLock.RUnlock() 897 if _, ok := c.Extensions["SELinux"]; !ok { 898 panic("Cannot issue request 'GetSelectionContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") 899 } 900 cookie := c.NewCookie(true, true) 901 c.NewRequest(getSelectionContextRequest(c, Selection), cookie) 902 return GetSelectionContextCookie{cookie} 903 } 904 905 // GetSelectionContextUnchecked sends an unchecked request. 906 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 907 func GetSelectionContextUnchecked(c *xgb.Conn, Selection xproto.Atom) GetSelectionContextCookie { 908 c.ExtLock.RLock() 909 defer c.ExtLock.RUnlock() 910 if _, ok := c.Extensions["SELinux"]; !ok { 911 panic("Cannot issue request 'GetSelectionContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") 912 } 913 cookie := c.NewCookie(false, true) 914 c.NewRequest(getSelectionContextRequest(c, Selection), cookie) 915 return GetSelectionContextCookie{cookie} 916 } 917 918 // GetSelectionContextReply represents the data returned from a GetSelectionContext request. 919 type GetSelectionContextReply struct { 920 Sequence uint16 // sequence number of the request for this reply 921 Length uint32 // number of bytes in this reply 922 // padding: 1 bytes 923 ContextLen uint32 924 // padding: 20 bytes 925 Context string // size: xgb.Pad((int(ContextLen) * 1)) 926 } 927 928 // Reply blocks and returns the reply data for a GetSelectionContext request. 929 func (cook GetSelectionContextCookie) Reply() (*GetSelectionContextReply, error) { 930 buf, err := cook.Cookie.Reply() 931 if err != nil { 932 return nil, err 933 } 934 if buf == nil { 935 return nil, nil 936 } 937 return getSelectionContextReply(buf), nil 938 } 939 940 // getSelectionContextReply reads a byte slice into a GetSelectionContextReply value. 941 func getSelectionContextReply(buf []byte) *GetSelectionContextReply { 942 v := new(GetSelectionContextReply) 943 b := 1 // skip reply determinant 944 945 b += 1 // padding 946 947 v.Sequence = xgb.Get16(buf[b:]) 948 b += 2 949 950 v.Length = xgb.Get32(buf[b:]) // 4-byte units 951 b += 4 952 953 v.ContextLen = xgb.Get32(buf[b:]) 954 b += 4 955 956 b += 20 // padding 957 958 { 959 byteString := make([]byte, v.ContextLen) 960 copy(byteString[:v.ContextLen], buf[b:]) 961 v.Context = string(byteString) 962 b += int(v.ContextLen) 963 } 964 965 return v 966 } 967 968 // Write request to wire for GetSelectionContext 969 // getSelectionContextRequest writes a GetSelectionContext request to a byte slice. 970 func getSelectionContextRequest(c *xgb.Conn, Selection xproto.Atom) []byte { 971 size := 8 972 b := 0 973 buf := make([]byte, size) 974 975 c.ExtLock.RLock() 976 buf[b] = c.Extensions["SELinux"] 977 c.ExtLock.RUnlock() 978 b += 1 979 980 buf[b] = 19 // request opcode 981 b += 1 982 983 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 984 b += 2 985 986 xgb.Put32(buf[b:], uint32(Selection)) 987 b += 4 988 989 return buf 990 } 991 992 // GetSelectionCreateContextCookie is a cookie used only for GetSelectionCreateContext requests. 993 type GetSelectionCreateContextCookie struct { 994 *xgb.Cookie 995 } 996 997 // GetSelectionCreateContext sends a checked request. 998 // If an error occurs, it will be returned with the reply by calling GetSelectionCreateContextCookie.Reply() 999 func GetSelectionCreateContext(c *xgb.Conn) GetSelectionCreateContextCookie { 1000 c.ExtLock.RLock() 1001 defer c.ExtLock.RUnlock() 1002 if _, ok := c.Extensions["SELinux"]; !ok { 1003 panic("Cannot issue request 'GetSelectionCreateContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") 1004 } 1005 cookie := c.NewCookie(true, true) 1006 c.NewRequest(getSelectionCreateContextRequest(c), cookie) 1007 return GetSelectionCreateContextCookie{cookie} 1008 } 1009 1010 // GetSelectionCreateContextUnchecked sends an unchecked request. 1011 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 1012 func GetSelectionCreateContextUnchecked(c *xgb.Conn) GetSelectionCreateContextCookie { 1013 c.ExtLock.RLock() 1014 defer c.ExtLock.RUnlock() 1015 if _, ok := c.Extensions["SELinux"]; !ok { 1016 panic("Cannot issue request 'GetSelectionCreateContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") 1017 } 1018 cookie := c.NewCookie(false, true) 1019 c.NewRequest(getSelectionCreateContextRequest(c), cookie) 1020 return GetSelectionCreateContextCookie{cookie} 1021 } 1022 1023 // GetSelectionCreateContextReply represents the data returned from a GetSelectionCreateContext request. 1024 type GetSelectionCreateContextReply struct { 1025 Sequence uint16 // sequence number of the request for this reply 1026 Length uint32 // number of bytes in this reply 1027 // padding: 1 bytes 1028 ContextLen uint32 1029 // padding: 20 bytes 1030 Context string // size: xgb.Pad((int(ContextLen) * 1)) 1031 } 1032 1033 // Reply blocks and returns the reply data for a GetSelectionCreateContext request. 1034 func (cook GetSelectionCreateContextCookie) Reply() (*GetSelectionCreateContextReply, error) { 1035 buf, err := cook.Cookie.Reply() 1036 if err != nil { 1037 return nil, err 1038 } 1039 if buf == nil { 1040 return nil, nil 1041 } 1042 return getSelectionCreateContextReply(buf), nil 1043 } 1044 1045 // getSelectionCreateContextReply reads a byte slice into a GetSelectionCreateContextReply value. 1046 func getSelectionCreateContextReply(buf []byte) *GetSelectionCreateContextReply { 1047 v := new(GetSelectionCreateContextReply) 1048 b := 1 // skip reply determinant 1049 1050 b += 1 // padding 1051 1052 v.Sequence = xgb.Get16(buf[b:]) 1053 b += 2 1054 1055 v.Length = xgb.Get32(buf[b:]) // 4-byte units 1056 b += 4 1057 1058 v.ContextLen = xgb.Get32(buf[b:]) 1059 b += 4 1060 1061 b += 20 // padding 1062 1063 { 1064 byteString := make([]byte, v.ContextLen) 1065 copy(byteString[:v.ContextLen], buf[b:]) 1066 v.Context = string(byteString) 1067 b += int(v.ContextLen) 1068 } 1069 1070 return v 1071 } 1072 1073 // Write request to wire for GetSelectionCreateContext 1074 // getSelectionCreateContextRequest writes a GetSelectionCreateContext request to a byte slice. 1075 func getSelectionCreateContextRequest(c *xgb.Conn) []byte { 1076 size := 4 1077 b := 0 1078 buf := make([]byte, size) 1079 1080 c.ExtLock.RLock() 1081 buf[b] = c.Extensions["SELinux"] 1082 c.ExtLock.RUnlock() 1083 b += 1 1084 1085 buf[b] = 16 // request opcode 1086 b += 1 1087 1088 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 1089 b += 2 1090 1091 return buf 1092 } 1093 1094 // GetSelectionDataContextCookie is a cookie used only for GetSelectionDataContext requests. 1095 type GetSelectionDataContextCookie struct { 1096 *xgb.Cookie 1097 } 1098 1099 // GetSelectionDataContext sends a checked request. 1100 // If an error occurs, it will be returned with the reply by calling GetSelectionDataContextCookie.Reply() 1101 func GetSelectionDataContext(c *xgb.Conn, Selection xproto.Atom) GetSelectionDataContextCookie { 1102 c.ExtLock.RLock() 1103 defer c.ExtLock.RUnlock() 1104 if _, ok := c.Extensions["SELinux"]; !ok { 1105 panic("Cannot issue request 'GetSelectionDataContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") 1106 } 1107 cookie := c.NewCookie(true, true) 1108 c.NewRequest(getSelectionDataContextRequest(c, Selection), cookie) 1109 return GetSelectionDataContextCookie{cookie} 1110 } 1111 1112 // GetSelectionDataContextUnchecked sends an unchecked request. 1113 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 1114 func GetSelectionDataContextUnchecked(c *xgb.Conn, Selection xproto.Atom) GetSelectionDataContextCookie { 1115 c.ExtLock.RLock() 1116 defer c.ExtLock.RUnlock() 1117 if _, ok := c.Extensions["SELinux"]; !ok { 1118 panic("Cannot issue request 'GetSelectionDataContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") 1119 } 1120 cookie := c.NewCookie(false, true) 1121 c.NewRequest(getSelectionDataContextRequest(c, Selection), cookie) 1122 return GetSelectionDataContextCookie{cookie} 1123 } 1124 1125 // GetSelectionDataContextReply represents the data returned from a GetSelectionDataContext request. 1126 type GetSelectionDataContextReply struct { 1127 Sequence uint16 // sequence number of the request for this reply 1128 Length uint32 // number of bytes in this reply 1129 // padding: 1 bytes 1130 ContextLen uint32 1131 // padding: 20 bytes 1132 Context string // size: xgb.Pad((int(ContextLen) * 1)) 1133 } 1134 1135 // Reply blocks and returns the reply data for a GetSelectionDataContext request. 1136 func (cook GetSelectionDataContextCookie) Reply() (*GetSelectionDataContextReply, error) { 1137 buf, err := cook.Cookie.Reply() 1138 if err != nil { 1139 return nil, err 1140 } 1141 if buf == nil { 1142 return nil, nil 1143 } 1144 return getSelectionDataContextReply(buf), nil 1145 } 1146 1147 // getSelectionDataContextReply reads a byte slice into a GetSelectionDataContextReply value. 1148 func getSelectionDataContextReply(buf []byte) *GetSelectionDataContextReply { 1149 v := new(GetSelectionDataContextReply) 1150 b := 1 // skip reply determinant 1151 1152 b += 1 // padding 1153 1154 v.Sequence = xgb.Get16(buf[b:]) 1155 b += 2 1156 1157 v.Length = xgb.Get32(buf[b:]) // 4-byte units 1158 b += 4 1159 1160 v.ContextLen = xgb.Get32(buf[b:]) 1161 b += 4 1162 1163 b += 20 // padding 1164 1165 { 1166 byteString := make([]byte, v.ContextLen) 1167 copy(byteString[:v.ContextLen], buf[b:]) 1168 v.Context = string(byteString) 1169 b += int(v.ContextLen) 1170 } 1171 1172 return v 1173 } 1174 1175 // Write request to wire for GetSelectionDataContext 1176 // getSelectionDataContextRequest writes a GetSelectionDataContext request to a byte slice. 1177 func getSelectionDataContextRequest(c *xgb.Conn, Selection xproto.Atom) []byte { 1178 size := 8 1179 b := 0 1180 buf := make([]byte, size) 1181 1182 c.ExtLock.RLock() 1183 buf[b] = c.Extensions["SELinux"] 1184 c.ExtLock.RUnlock() 1185 b += 1 1186 1187 buf[b] = 20 // request opcode 1188 b += 1 1189 1190 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 1191 b += 2 1192 1193 xgb.Put32(buf[b:], uint32(Selection)) 1194 b += 4 1195 1196 return buf 1197 } 1198 1199 // GetSelectionUseContextCookie is a cookie used only for GetSelectionUseContext requests. 1200 type GetSelectionUseContextCookie struct { 1201 *xgb.Cookie 1202 } 1203 1204 // GetSelectionUseContext sends a checked request. 1205 // If an error occurs, it will be returned with the reply by calling GetSelectionUseContextCookie.Reply() 1206 func GetSelectionUseContext(c *xgb.Conn) GetSelectionUseContextCookie { 1207 c.ExtLock.RLock() 1208 defer c.ExtLock.RUnlock() 1209 if _, ok := c.Extensions["SELinux"]; !ok { 1210 panic("Cannot issue request 'GetSelectionUseContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") 1211 } 1212 cookie := c.NewCookie(true, true) 1213 c.NewRequest(getSelectionUseContextRequest(c), cookie) 1214 return GetSelectionUseContextCookie{cookie} 1215 } 1216 1217 // GetSelectionUseContextUnchecked sends an unchecked request. 1218 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 1219 func GetSelectionUseContextUnchecked(c *xgb.Conn) GetSelectionUseContextCookie { 1220 c.ExtLock.RLock() 1221 defer c.ExtLock.RUnlock() 1222 if _, ok := c.Extensions["SELinux"]; !ok { 1223 panic("Cannot issue request 'GetSelectionUseContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") 1224 } 1225 cookie := c.NewCookie(false, true) 1226 c.NewRequest(getSelectionUseContextRequest(c), cookie) 1227 return GetSelectionUseContextCookie{cookie} 1228 } 1229 1230 // GetSelectionUseContextReply represents the data returned from a GetSelectionUseContext request. 1231 type GetSelectionUseContextReply struct { 1232 Sequence uint16 // sequence number of the request for this reply 1233 Length uint32 // number of bytes in this reply 1234 // padding: 1 bytes 1235 ContextLen uint32 1236 // padding: 20 bytes 1237 Context string // size: xgb.Pad((int(ContextLen) * 1)) 1238 } 1239 1240 // Reply blocks and returns the reply data for a GetSelectionUseContext request. 1241 func (cook GetSelectionUseContextCookie) Reply() (*GetSelectionUseContextReply, error) { 1242 buf, err := cook.Cookie.Reply() 1243 if err != nil { 1244 return nil, err 1245 } 1246 if buf == nil { 1247 return nil, nil 1248 } 1249 return getSelectionUseContextReply(buf), nil 1250 } 1251 1252 // getSelectionUseContextReply reads a byte slice into a GetSelectionUseContextReply value. 1253 func getSelectionUseContextReply(buf []byte) *GetSelectionUseContextReply { 1254 v := new(GetSelectionUseContextReply) 1255 b := 1 // skip reply determinant 1256 1257 b += 1 // padding 1258 1259 v.Sequence = xgb.Get16(buf[b:]) 1260 b += 2 1261 1262 v.Length = xgb.Get32(buf[b:]) // 4-byte units 1263 b += 4 1264 1265 v.ContextLen = xgb.Get32(buf[b:]) 1266 b += 4 1267 1268 b += 20 // padding 1269 1270 { 1271 byteString := make([]byte, v.ContextLen) 1272 copy(byteString[:v.ContextLen], buf[b:]) 1273 v.Context = string(byteString) 1274 b += int(v.ContextLen) 1275 } 1276 1277 return v 1278 } 1279 1280 // Write request to wire for GetSelectionUseContext 1281 // getSelectionUseContextRequest writes a GetSelectionUseContext request to a byte slice. 1282 func getSelectionUseContextRequest(c *xgb.Conn) []byte { 1283 size := 4 1284 b := 0 1285 buf := make([]byte, size) 1286 1287 c.ExtLock.RLock() 1288 buf[b] = c.Extensions["SELinux"] 1289 c.ExtLock.RUnlock() 1290 b += 1 1291 1292 buf[b] = 18 // request opcode 1293 b += 1 1294 1295 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 1296 b += 2 1297 1298 return buf 1299 } 1300 1301 // GetWindowContextCookie is a cookie used only for GetWindowContext requests. 1302 type GetWindowContextCookie struct { 1303 *xgb.Cookie 1304 } 1305 1306 // GetWindowContext sends a checked request. 1307 // If an error occurs, it will be returned with the reply by calling GetWindowContextCookie.Reply() 1308 func GetWindowContext(c *xgb.Conn, Window xproto.Window) GetWindowContextCookie { 1309 c.ExtLock.RLock() 1310 defer c.ExtLock.RUnlock() 1311 if _, ok := c.Extensions["SELinux"]; !ok { 1312 panic("Cannot issue request 'GetWindowContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") 1313 } 1314 cookie := c.NewCookie(true, true) 1315 c.NewRequest(getWindowContextRequest(c, Window), cookie) 1316 return GetWindowContextCookie{cookie} 1317 } 1318 1319 // GetWindowContextUnchecked sends an unchecked request. 1320 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 1321 func GetWindowContextUnchecked(c *xgb.Conn, Window xproto.Window) GetWindowContextCookie { 1322 c.ExtLock.RLock() 1323 defer c.ExtLock.RUnlock() 1324 if _, ok := c.Extensions["SELinux"]; !ok { 1325 panic("Cannot issue request 'GetWindowContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") 1326 } 1327 cookie := c.NewCookie(false, true) 1328 c.NewRequest(getWindowContextRequest(c, Window), cookie) 1329 return GetWindowContextCookie{cookie} 1330 } 1331 1332 // GetWindowContextReply represents the data returned from a GetWindowContext request. 1333 type GetWindowContextReply struct { 1334 Sequence uint16 // sequence number of the request for this reply 1335 Length uint32 // number of bytes in this reply 1336 // padding: 1 bytes 1337 ContextLen uint32 1338 // padding: 20 bytes 1339 Context string // size: xgb.Pad((int(ContextLen) * 1)) 1340 } 1341 1342 // Reply blocks and returns the reply data for a GetWindowContext request. 1343 func (cook GetWindowContextCookie) Reply() (*GetWindowContextReply, error) { 1344 buf, err := cook.Cookie.Reply() 1345 if err != nil { 1346 return nil, err 1347 } 1348 if buf == nil { 1349 return nil, nil 1350 } 1351 return getWindowContextReply(buf), nil 1352 } 1353 1354 // getWindowContextReply reads a byte slice into a GetWindowContextReply value. 1355 func getWindowContextReply(buf []byte) *GetWindowContextReply { 1356 v := new(GetWindowContextReply) 1357 b := 1 // skip reply determinant 1358 1359 b += 1 // padding 1360 1361 v.Sequence = xgb.Get16(buf[b:]) 1362 b += 2 1363 1364 v.Length = xgb.Get32(buf[b:]) // 4-byte units 1365 b += 4 1366 1367 v.ContextLen = xgb.Get32(buf[b:]) 1368 b += 4 1369 1370 b += 20 // padding 1371 1372 { 1373 byteString := make([]byte, v.ContextLen) 1374 copy(byteString[:v.ContextLen], buf[b:]) 1375 v.Context = string(byteString) 1376 b += int(v.ContextLen) 1377 } 1378 1379 return v 1380 } 1381 1382 // Write request to wire for GetWindowContext 1383 // getWindowContextRequest writes a GetWindowContext request to a byte slice. 1384 func getWindowContextRequest(c *xgb.Conn, Window xproto.Window) []byte { 1385 size := 8 1386 b := 0 1387 buf := make([]byte, size) 1388 1389 c.ExtLock.RLock() 1390 buf[b] = c.Extensions["SELinux"] 1391 c.ExtLock.RUnlock() 1392 b += 1 1393 1394 buf[b] = 7 // request opcode 1395 b += 1 1396 1397 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 1398 b += 2 1399 1400 xgb.Put32(buf[b:], uint32(Window)) 1401 b += 4 1402 1403 return buf 1404 } 1405 1406 // GetWindowCreateContextCookie is a cookie used only for GetWindowCreateContext requests. 1407 type GetWindowCreateContextCookie struct { 1408 *xgb.Cookie 1409 } 1410 1411 // GetWindowCreateContext sends a checked request. 1412 // If an error occurs, it will be returned with the reply by calling GetWindowCreateContextCookie.Reply() 1413 func GetWindowCreateContext(c *xgb.Conn) GetWindowCreateContextCookie { 1414 c.ExtLock.RLock() 1415 defer c.ExtLock.RUnlock() 1416 if _, ok := c.Extensions["SELinux"]; !ok { 1417 panic("Cannot issue request 'GetWindowCreateContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") 1418 } 1419 cookie := c.NewCookie(true, true) 1420 c.NewRequest(getWindowCreateContextRequest(c), cookie) 1421 return GetWindowCreateContextCookie{cookie} 1422 } 1423 1424 // GetWindowCreateContextUnchecked sends an unchecked request. 1425 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 1426 func GetWindowCreateContextUnchecked(c *xgb.Conn) GetWindowCreateContextCookie { 1427 c.ExtLock.RLock() 1428 defer c.ExtLock.RUnlock() 1429 if _, ok := c.Extensions["SELinux"]; !ok { 1430 panic("Cannot issue request 'GetWindowCreateContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") 1431 } 1432 cookie := c.NewCookie(false, true) 1433 c.NewRequest(getWindowCreateContextRequest(c), cookie) 1434 return GetWindowCreateContextCookie{cookie} 1435 } 1436 1437 // GetWindowCreateContextReply represents the data returned from a GetWindowCreateContext request. 1438 type GetWindowCreateContextReply struct { 1439 Sequence uint16 // sequence number of the request for this reply 1440 Length uint32 // number of bytes in this reply 1441 // padding: 1 bytes 1442 ContextLen uint32 1443 // padding: 20 bytes 1444 Context string // size: xgb.Pad((int(ContextLen) * 1)) 1445 } 1446 1447 // Reply blocks and returns the reply data for a GetWindowCreateContext request. 1448 func (cook GetWindowCreateContextCookie) Reply() (*GetWindowCreateContextReply, error) { 1449 buf, err := cook.Cookie.Reply() 1450 if err != nil { 1451 return nil, err 1452 } 1453 if buf == nil { 1454 return nil, nil 1455 } 1456 return getWindowCreateContextReply(buf), nil 1457 } 1458 1459 // getWindowCreateContextReply reads a byte slice into a GetWindowCreateContextReply value. 1460 func getWindowCreateContextReply(buf []byte) *GetWindowCreateContextReply { 1461 v := new(GetWindowCreateContextReply) 1462 b := 1 // skip reply determinant 1463 1464 b += 1 // padding 1465 1466 v.Sequence = xgb.Get16(buf[b:]) 1467 b += 2 1468 1469 v.Length = xgb.Get32(buf[b:]) // 4-byte units 1470 b += 4 1471 1472 v.ContextLen = xgb.Get32(buf[b:]) 1473 b += 4 1474 1475 b += 20 // padding 1476 1477 { 1478 byteString := make([]byte, v.ContextLen) 1479 copy(byteString[:v.ContextLen], buf[b:]) 1480 v.Context = string(byteString) 1481 b += int(v.ContextLen) 1482 } 1483 1484 return v 1485 } 1486 1487 // Write request to wire for GetWindowCreateContext 1488 // getWindowCreateContextRequest writes a GetWindowCreateContext request to a byte slice. 1489 func getWindowCreateContextRequest(c *xgb.Conn) []byte { 1490 size := 4 1491 b := 0 1492 buf := make([]byte, size) 1493 1494 c.ExtLock.RLock() 1495 buf[b] = c.Extensions["SELinux"] 1496 c.ExtLock.RUnlock() 1497 b += 1 1498 1499 buf[b] = 6 // request opcode 1500 b += 1 1501 1502 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 1503 b += 2 1504 1505 return buf 1506 } 1507 1508 // ListPropertiesCookie is a cookie used only for ListProperties requests. 1509 type ListPropertiesCookie struct { 1510 *xgb.Cookie 1511 } 1512 1513 // ListProperties sends a checked request. 1514 // If an error occurs, it will be returned with the reply by calling ListPropertiesCookie.Reply() 1515 func ListProperties(c *xgb.Conn, Window xproto.Window) ListPropertiesCookie { 1516 c.ExtLock.RLock() 1517 defer c.ExtLock.RUnlock() 1518 if _, ok := c.Extensions["SELinux"]; !ok { 1519 panic("Cannot issue request 'ListProperties' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") 1520 } 1521 cookie := c.NewCookie(true, true) 1522 c.NewRequest(listPropertiesRequest(c, Window), cookie) 1523 return ListPropertiesCookie{cookie} 1524 } 1525 1526 // ListPropertiesUnchecked sends an unchecked request. 1527 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 1528 func ListPropertiesUnchecked(c *xgb.Conn, Window xproto.Window) ListPropertiesCookie { 1529 c.ExtLock.RLock() 1530 defer c.ExtLock.RUnlock() 1531 if _, ok := c.Extensions["SELinux"]; !ok { 1532 panic("Cannot issue request 'ListProperties' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") 1533 } 1534 cookie := c.NewCookie(false, true) 1535 c.NewRequest(listPropertiesRequest(c, Window), cookie) 1536 return ListPropertiesCookie{cookie} 1537 } 1538 1539 // ListPropertiesReply represents the data returned from a ListProperties request. 1540 type ListPropertiesReply struct { 1541 Sequence uint16 // sequence number of the request for this reply 1542 Length uint32 // number of bytes in this reply 1543 // padding: 1 bytes 1544 PropertiesLen uint32 1545 // padding: 20 bytes 1546 Properties []ListItem // size: ListItemListSize(Properties) 1547 } 1548 1549 // Reply blocks and returns the reply data for a ListProperties request. 1550 func (cook ListPropertiesCookie) Reply() (*ListPropertiesReply, error) { 1551 buf, err := cook.Cookie.Reply() 1552 if err != nil { 1553 return nil, err 1554 } 1555 if buf == nil { 1556 return nil, nil 1557 } 1558 return listPropertiesReply(buf), nil 1559 } 1560 1561 // listPropertiesReply reads a byte slice into a ListPropertiesReply value. 1562 func listPropertiesReply(buf []byte) *ListPropertiesReply { 1563 v := new(ListPropertiesReply) 1564 b := 1 // skip reply determinant 1565 1566 b += 1 // padding 1567 1568 v.Sequence = xgb.Get16(buf[b:]) 1569 b += 2 1570 1571 v.Length = xgb.Get32(buf[b:]) // 4-byte units 1572 b += 4 1573 1574 v.PropertiesLen = xgb.Get32(buf[b:]) 1575 b += 4 1576 1577 b += 20 // padding 1578 1579 v.Properties = make([]ListItem, v.PropertiesLen) 1580 b += ListItemReadList(buf[b:], v.Properties) 1581 1582 return v 1583 } 1584 1585 // Write request to wire for ListProperties 1586 // listPropertiesRequest writes a ListProperties request to a byte slice. 1587 func listPropertiesRequest(c *xgb.Conn, Window xproto.Window) []byte { 1588 size := 8 1589 b := 0 1590 buf := make([]byte, size) 1591 1592 c.ExtLock.RLock() 1593 buf[b] = c.Extensions["SELinux"] 1594 c.ExtLock.RUnlock() 1595 b += 1 1596 1597 buf[b] = 14 // request opcode 1598 b += 1 1599 1600 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 1601 b += 2 1602 1603 xgb.Put32(buf[b:], uint32(Window)) 1604 b += 4 1605 1606 return buf 1607 } 1608 1609 // ListSelectionsCookie is a cookie used only for ListSelections requests. 1610 type ListSelectionsCookie struct { 1611 *xgb.Cookie 1612 } 1613 1614 // ListSelections sends a checked request. 1615 // If an error occurs, it will be returned with the reply by calling ListSelectionsCookie.Reply() 1616 func ListSelections(c *xgb.Conn) ListSelectionsCookie { 1617 c.ExtLock.RLock() 1618 defer c.ExtLock.RUnlock() 1619 if _, ok := c.Extensions["SELinux"]; !ok { 1620 panic("Cannot issue request 'ListSelections' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") 1621 } 1622 cookie := c.NewCookie(true, true) 1623 c.NewRequest(listSelectionsRequest(c), cookie) 1624 return ListSelectionsCookie{cookie} 1625 } 1626 1627 // ListSelectionsUnchecked sends an unchecked request. 1628 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 1629 func ListSelectionsUnchecked(c *xgb.Conn) ListSelectionsCookie { 1630 c.ExtLock.RLock() 1631 defer c.ExtLock.RUnlock() 1632 if _, ok := c.Extensions["SELinux"]; !ok { 1633 panic("Cannot issue request 'ListSelections' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") 1634 } 1635 cookie := c.NewCookie(false, true) 1636 c.NewRequest(listSelectionsRequest(c), cookie) 1637 return ListSelectionsCookie{cookie} 1638 } 1639 1640 // ListSelectionsReply represents the data returned from a ListSelections request. 1641 type ListSelectionsReply struct { 1642 Sequence uint16 // sequence number of the request for this reply 1643 Length uint32 // number of bytes in this reply 1644 // padding: 1 bytes 1645 SelectionsLen uint32 1646 // padding: 20 bytes 1647 Selections []ListItem // size: ListItemListSize(Selections) 1648 } 1649 1650 // Reply blocks and returns the reply data for a ListSelections request. 1651 func (cook ListSelectionsCookie) Reply() (*ListSelectionsReply, error) { 1652 buf, err := cook.Cookie.Reply() 1653 if err != nil { 1654 return nil, err 1655 } 1656 if buf == nil { 1657 return nil, nil 1658 } 1659 return listSelectionsReply(buf), nil 1660 } 1661 1662 // listSelectionsReply reads a byte slice into a ListSelectionsReply value. 1663 func listSelectionsReply(buf []byte) *ListSelectionsReply { 1664 v := new(ListSelectionsReply) 1665 b := 1 // skip reply determinant 1666 1667 b += 1 // padding 1668 1669 v.Sequence = xgb.Get16(buf[b:]) 1670 b += 2 1671 1672 v.Length = xgb.Get32(buf[b:]) // 4-byte units 1673 b += 4 1674 1675 v.SelectionsLen = xgb.Get32(buf[b:]) 1676 b += 4 1677 1678 b += 20 // padding 1679 1680 v.Selections = make([]ListItem, v.SelectionsLen) 1681 b += ListItemReadList(buf[b:], v.Selections) 1682 1683 return v 1684 } 1685 1686 // Write request to wire for ListSelections 1687 // listSelectionsRequest writes a ListSelections request to a byte slice. 1688 func listSelectionsRequest(c *xgb.Conn) []byte { 1689 size := 4 1690 b := 0 1691 buf := make([]byte, size) 1692 1693 c.ExtLock.RLock() 1694 buf[b] = c.Extensions["SELinux"] 1695 c.ExtLock.RUnlock() 1696 b += 1 1697 1698 buf[b] = 21 // request opcode 1699 b += 1 1700 1701 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 1702 b += 2 1703 1704 return buf 1705 } 1706 1707 // QueryVersionCookie is a cookie used only for QueryVersion requests. 1708 type QueryVersionCookie struct { 1709 *xgb.Cookie 1710 } 1711 1712 // QueryVersion sends a checked request. 1713 // If an error occurs, it will be returned with the reply by calling QueryVersionCookie.Reply() 1714 func QueryVersion(c *xgb.Conn, ClientMajor byte, ClientMinor byte) QueryVersionCookie { 1715 c.ExtLock.RLock() 1716 defer c.ExtLock.RUnlock() 1717 if _, ok := c.Extensions["SELinux"]; !ok { 1718 panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") 1719 } 1720 cookie := c.NewCookie(true, true) 1721 c.NewRequest(queryVersionRequest(c, ClientMajor, ClientMinor), cookie) 1722 return QueryVersionCookie{cookie} 1723 } 1724 1725 // QueryVersionUnchecked sends an unchecked request. 1726 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 1727 func QueryVersionUnchecked(c *xgb.Conn, ClientMajor byte, ClientMinor byte) QueryVersionCookie { 1728 c.ExtLock.RLock() 1729 defer c.ExtLock.RUnlock() 1730 if _, ok := c.Extensions["SELinux"]; !ok { 1731 panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") 1732 } 1733 cookie := c.NewCookie(false, true) 1734 c.NewRequest(queryVersionRequest(c, ClientMajor, ClientMinor), cookie) 1735 return QueryVersionCookie{cookie} 1736 } 1737 1738 // QueryVersionReply represents the data returned from a QueryVersion request. 1739 type QueryVersionReply struct { 1740 Sequence uint16 // sequence number of the request for this reply 1741 Length uint32 // number of bytes in this reply 1742 // padding: 1 bytes 1743 ServerMajor uint16 1744 ServerMinor uint16 1745 } 1746 1747 // Reply blocks and returns the reply data for a QueryVersion request. 1748 func (cook QueryVersionCookie) Reply() (*QueryVersionReply, error) { 1749 buf, err := cook.Cookie.Reply() 1750 if err != nil { 1751 return nil, err 1752 } 1753 if buf == nil { 1754 return nil, nil 1755 } 1756 return queryVersionReply(buf), nil 1757 } 1758 1759 // queryVersionReply reads a byte slice into a QueryVersionReply value. 1760 func queryVersionReply(buf []byte) *QueryVersionReply { 1761 v := new(QueryVersionReply) 1762 b := 1 // skip reply determinant 1763 1764 b += 1 // padding 1765 1766 v.Sequence = xgb.Get16(buf[b:]) 1767 b += 2 1768 1769 v.Length = xgb.Get32(buf[b:]) // 4-byte units 1770 b += 4 1771 1772 v.ServerMajor = xgb.Get16(buf[b:]) 1773 b += 2 1774 1775 v.ServerMinor = xgb.Get16(buf[b:]) 1776 b += 2 1777 1778 return v 1779 } 1780 1781 // Write request to wire for QueryVersion 1782 // queryVersionRequest writes a QueryVersion request to a byte slice. 1783 func queryVersionRequest(c *xgb.Conn, ClientMajor byte, ClientMinor byte) []byte { 1784 size := 8 1785 b := 0 1786 buf := make([]byte, size) 1787 1788 c.ExtLock.RLock() 1789 buf[b] = c.Extensions["SELinux"] 1790 c.ExtLock.RUnlock() 1791 b += 1 1792 1793 buf[b] = 0 // request opcode 1794 b += 1 1795 1796 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 1797 b += 2 1798 1799 buf[b] = ClientMajor 1800 b += 1 1801 1802 buf[b] = ClientMinor 1803 b += 1 1804 1805 return buf 1806 } 1807 1808 // SetDeviceContextCookie is a cookie used only for SetDeviceContext requests. 1809 type SetDeviceContextCookie struct { 1810 *xgb.Cookie 1811 } 1812 1813 // SetDeviceContext sends an unchecked request. 1814 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 1815 func SetDeviceContext(c *xgb.Conn, Device uint32, ContextLen uint32, Context string) SetDeviceContextCookie { 1816 c.ExtLock.RLock() 1817 defer c.ExtLock.RUnlock() 1818 if _, ok := c.Extensions["SELinux"]; !ok { 1819 panic("Cannot issue request 'SetDeviceContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") 1820 } 1821 cookie := c.NewCookie(false, false) 1822 c.NewRequest(setDeviceContextRequest(c, Device, ContextLen, Context), cookie) 1823 return SetDeviceContextCookie{cookie} 1824 } 1825 1826 // SetDeviceContextChecked sends a checked request. 1827 // If an error occurs, it can be retrieved using SetDeviceContextCookie.Check() 1828 func SetDeviceContextChecked(c *xgb.Conn, Device uint32, ContextLen uint32, Context string) SetDeviceContextCookie { 1829 c.ExtLock.RLock() 1830 defer c.ExtLock.RUnlock() 1831 if _, ok := c.Extensions["SELinux"]; !ok { 1832 panic("Cannot issue request 'SetDeviceContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") 1833 } 1834 cookie := c.NewCookie(true, false) 1835 c.NewRequest(setDeviceContextRequest(c, Device, ContextLen, Context), cookie) 1836 return SetDeviceContextCookie{cookie} 1837 } 1838 1839 // Check returns an error if one occurred for checked requests that are not expecting a reply. 1840 // This cannot be called for requests expecting a reply, nor for unchecked requests. 1841 func (cook SetDeviceContextCookie) Check() error { 1842 return cook.Cookie.Check() 1843 } 1844 1845 // Write request to wire for SetDeviceContext 1846 // setDeviceContextRequest writes a SetDeviceContext request to a byte slice. 1847 func setDeviceContextRequest(c *xgb.Conn, Device uint32, ContextLen uint32, Context string) []byte { 1848 size := xgb.Pad((12 + xgb.Pad((int(ContextLen) * 1)))) 1849 b := 0 1850 buf := make([]byte, size) 1851 1852 c.ExtLock.RLock() 1853 buf[b] = c.Extensions["SELinux"] 1854 c.ExtLock.RUnlock() 1855 b += 1 1856 1857 buf[b] = 3 // request opcode 1858 b += 1 1859 1860 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 1861 b += 2 1862 1863 xgb.Put32(buf[b:], Device) 1864 b += 4 1865 1866 xgb.Put32(buf[b:], ContextLen) 1867 b += 4 1868 1869 copy(buf[b:], Context[:ContextLen]) 1870 b += int(ContextLen) 1871 1872 return buf 1873 } 1874 1875 // SetDeviceCreateContextCookie is a cookie used only for SetDeviceCreateContext requests. 1876 type SetDeviceCreateContextCookie struct { 1877 *xgb.Cookie 1878 } 1879 1880 // SetDeviceCreateContext sends an unchecked request. 1881 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 1882 func SetDeviceCreateContext(c *xgb.Conn, ContextLen uint32, Context string) SetDeviceCreateContextCookie { 1883 c.ExtLock.RLock() 1884 defer c.ExtLock.RUnlock() 1885 if _, ok := c.Extensions["SELinux"]; !ok { 1886 panic("Cannot issue request 'SetDeviceCreateContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") 1887 } 1888 cookie := c.NewCookie(false, false) 1889 c.NewRequest(setDeviceCreateContextRequest(c, ContextLen, Context), cookie) 1890 return SetDeviceCreateContextCookie{cookie} 1891 } 1892 1893 // SetDeviceCreateContextChecked sends a checked request. 1894 // If an error occurs, it can be retrieved using SetDeviceCreateContextCookie.Check() 1895 func SetDeviceCreateContextChecked(c *xgb.Conn, ContextLen uint32, Context string) SetDeviceCreateContextCookie { 1896 c.ExtLock.RLock() 1897 defer c.ExtLock.RUnlock() 1898 if _, ok := c.Extensions["SELinux"]; !ok { 1899 panic("Cannot issue request 'SetDeviceCreateContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") 1900 } 1901 cookie := c.NewCookie(true, false) 1902 c.NewRequest(setDeviceCreateContextRequest(c, ContextLen, Context), cookie) 1903 return SetDeviceCreateContextCookie{cookie} 1904 } 1905 1906 // Check returns an error if one occurred for checked requests that are not expecting a reply. 1907 // This cannot be called for requests expecting a reply, nor for unchecked requests. 1908 func (cook SetDeviceCreateContextCookie) Check() error { 1909 return cook.Cookie.Check() 1910 } 1911 1912 // Write request to wire for SetDeviceCreateContext 1913 // setDeviceCreateContextRequest writes a SetDeviceCreateContext request to a byte slice. 1914 func setDeviceCreateContextRequest(c *xgb.Conn, ContextLen uint32, Context string) []byte { 1915 size := xgb.Pad((8 + xgb.Pad((int(ContextLen) * 1)))) 1916 b := 0 1917 buf := make([]byte, size) 1918 1919 c.ExtLock.RLock() 1920 buf[b] = c.Extensions["SELinux"] 1921 c.ExtLock.RUnlock() 1922 b += 1 1923 1924 buf[b] = 1 // request opcode 1925 b += 1 1926 1927 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 1928 b += 2 1929 1930 xgb.Put32(buf[b:], ContextLen) 1931 b += 4 1932 1933 copy(buf[b:], Context[:ContextLen]) 1934 b += int(ContextLen) 1935 1936 return buf 1937 } 1938 1939 // SetPropertyCreateContextCookie is a cookie used only for SetPropertyCreateContext requests. 1940 type SetPropertyCreateContextCookie struct { 1941 *xgb.Cookie 1942 } 1943 1944 // SetPropertyCreateContext sends an unchecked request. 1945 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 1946 func SetPropertyCreateContext(c *xgb.Conn, ContextLen uint32, Context string) SetPropertyCreateContextCookie { 1947 c.ExtLock.RLock() 1948 defer c.ExtLock.RUnlock() 1949 if _, ok := c.Extensions["SELinux"]; !ok { 1950 panic("Cannot issue request 'SetPropertyCreateContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") 1951 } 1952 cookie := c.NewCookie(false, false) 1953 c.NewRequest(setPropertyCreateContextRequest(c, ContextLen, Context), cookie) 1954 return SetPropertyCreateContextCookie{cookie} 1955 } 1956 1957 // SetPropertyCreateContextChecked sends a checked request. 1958 // If an error occurs, it can be retrieved using SetPropertyCreateContextCookie.Check() 1959 func SetPropertyCreateContextChecked(c *xgb.Conn, ContextLen uint32, Context string) SetPropertyCreateContextCookie { 1960 c.ExtLock.RLock() 1961 defer c.ExtLock.RUnlock() 1962 if _, ok := c.Extensions["SELinux"]; !ok { 1963 panic("Cannot issue request 'SetPropertyCreateContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") 1964 } 1965 cookie := c.NewCookie(true, false) 1966 c.NewRequest(setPropertyCreateContextRequest(c, ContextLen, Context), cookie) 1967 return SetPropertyCreateContextCookie{cookie} 1968 } 1969 1970 // Check returns an error if one occurred for checked requests that are not expecting a reply. 1971 // This cannot be called for requests expecting a reply, nor for unchecked requests. 1972 func (cook SetPropertyCreateContextCookie) Check() error { 1973 return cook.Cookie.Check() 1974 } 1975 1976 // Write request to wire for SetPropertyCreateContext 1977 // setPropertyCreateContextRequest writes a SetPropertyCreateContext request to a byte slice. 1978 func setPropertyCreateContextRequest(c *xgb.Conn, ContextLen uint32, Context string) []byte { 1979 size := xgb.Pad((8 + xgb.Pad((int(ContextLen) * 1)))) 1980 b := 0 1981 buf := make([]byte, size) 1982 1983 c.ExtLock.RLock() 1984 buf[b] = c.Extensions["SELinux"] 1985 c.ExtLock.RUnlock() 1986 b += 1 1987 1988 buf[b] = 8 // request opcode 1989 b += 1 1990 1991 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 1992 b += 2 1993 1994 xgb.Put32(buf[b:], ContextLen) 1995 b += 4 1996 1997 copy(buf[b:], Context[:ContextLen]) 1998 b += int(ContextLen) 1999 2000 return buf 2001 } 2002 2003 // SetPropertyUseContextCookie is a cookie used only for SetPropertyUseContext requests. 2004 type SetPropertyUseContextCookie struct { 2005 *xgb.Cookie 2006 } 2007 2008 // SetPropertyUseContext sends an unchecked request. 2009 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 2010 func SetPropertyUseContext(c *xgb.Conn, ContextLen uint32, Context string) SetPropertyUseContextCookie { 2011 c.ExtLock.RLock() 2012 defer c.ExtLock.RUnlock() 2013 if _, ok := c.Extensions["SELinux"]; !ok { 2014 panic("Cannot issue request 'SetPropertyUseContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") 2015 } 2016 cookie := c.NewCookie(false, false) 2017 c.NewRequest(setPropertyUseContextRequest(c, ContextLen, Context), cookie) 2018 return SetPropertyUseContextCookie{cookie} 2019 } 2020 2021 // SetPropertyUseContextChecked sends a checked request. 2022 // If an error occurs, it can be retrieved using SetPropertyUseContextCookie.Check() 2023 func SetPropertyUseContextChecked(c *xgb.Conn, ContextLen uint32, Context string) SetPropertyUseContextCookie { 2024 c.ExtLock.RLock() 2025 defer c.ExtLock.RUnlock() 2026 if _, ok := c.Extensions["SELinux"]; !ok { 2027 panic("Cannot issue request 'SetPropertyUseContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") 2028 } 2029 cookie := c.NewCookie(true, false) 2030 c.NewRequest(setPropertyUseContextRequest(c, ContextLen, Context), cookie) 2031 return SetPropertyUseContextCookie{cookie} 2032 } 2033 2034 // Check returns an error if one occurred for checked requests that are not expecting a reply. 2035 // This cannot be called for requests expecting a reply, nor for unchecked requests. 2036 func (cook SetPropertyUseContextCookie) Check() error { 2037 return cook.Cookie.Check() 2038 } 2039 2040 // Write request to wire for SetPropertyUseContext 2041 // setPropertyUseContextRequest writes a SetPropertyUseContext request to a byte slice. 2042 func setPropertyUseContextRequest(c *xgb.Conn, ContextLen uint32, Context string) []byte { 2043 size := xgb.Pad((8 + xgb.Pad((int(ContextLen) * 1)))) 2044 b := 0 2045 buf := make([]byte, size) 2046 2047 c.ExtLock.RLock() 2048 buf[b] = c.Extensions["SELinux"] 2049 c.ExtLock.RUnlock() 2050 b += 1 2051 2052 buf[b] = 10 // request opcode 2053 b += 1 2054 2055 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 2056 b += 2 2057 2058 xgb.Put32(buf[b:], ContextLen) 2059 b += 4 2060 2061 copy(buf[b:], Context[:ContextLen]) 2062 b += int(ContextLen) 2063 2064 return buf 2065 } 2066 2067 // SetSelectionCreateContextCookie is a cookie used only for SetSelectionCreateContext requests. 2068 type SetSelectionCreateContextCookie struct { 2069 *xgb.Cookie 2070 } 2071 2072 // SetSelectionCreateContext sends an unchecked request. 2073 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 2074 func SetSelectionCreateContext(c *xgb.Conn, ContextLen uint32, Context string) SetSelectionCreateContextCookie { 2075 c.ExtLock.RLock() 2076 defer c.ExtLock.RUnlock() 2077 if _, ok := c.Extensions["SELinux"]; !ok { 2078 panic("Cannot issue request 'SetSelectionCreateContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") 2079 } 2080 cookie := c.NewCookie(false, false) 2081 c.NewRequest(setSelectionCreateContextRequest(c, ContextLen, Context), cookie) 2082 return SetSelectionCreateContextCookie{cookie} 2083 } 2084 2085 // SetSelectionCreateContextChecked sends a checked request. 2086 // If an error occurs, it can be retrieved using SetSelectionCreateContextCookie.Check() 2087 func SetSelectionCreateContextChecked(c *xgb.Conn, ContextLen uint32, Context string) SetSelectionCreateContextCookie { 2088 c.ExtLock.RLock() 2089 defer c.ExtLock.RUnlock() 2090 if _, ok := c.Extensions["SELinux"]; !ok { 2091 panic("Cannot issue request 'SetSelectionCreateContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") 2092 } 2093 cookie := c.NewCookie(true, false) 2094 c.NewRequest(setSelectionCreateContextRequest(c, ContextLen, Context), cookie) 2095 return SetSelectionCreateContextCookie{cookie} 2096 } 2097 2098 // Check returns an error if one occurred for checked requests that are not expecting a reply. 2099 // This cannot be called for requests expecting a reply, nor for unchecked requests. 2100 func (cook SetSelectionCreateContextCookie) Check() error { 2101 return cook.Cookie.Check() 2102 } 2103 2104 // Write request to wire for SetSelectionCreateContext 2105 // setSelectionCreateContextRequest writes a SetSelectionCreateContext request to a byte slice. 2106 func setSelectionCreateContextRequest(c *xgb.Conn, ContextLen uint32, Context string) []byte { 2107 size := xgb.Pad((8 + xgb.Pad((int(ContextLen) * 1)))) 2108 b := 0 2109 buf := make([]byte, size) 2110 2111 c.ExtLock.RLock() 2112 buf[b] = c.Extensions["SELinux"] 2113 c.ExtLock.RUnlock() 2114 b += 1 2115 2116 buf[b] = 15 // request opcode 2117 b += 1 2118 2119 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 2120 b += 2 2121 2122 xgb.Put32(buf[b:], ContextLen) 2123 b += 4 2124 2125 copy(buf[b:], Context[:ContextLen]) 2126 b += int(ContextLen) 2127 2128 return buf 2129 } 2130 2131 // SetSelectionUseContextCookie is a cookie used only for SetSelectionUseContext requests. 2132 type SetSelectionUseContextCookie struct { 2133 *xgb.Cookie 2134 } 2135 2136 // SetSelectionUseContext sends an unchecked request. 2137 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 2138 func SetSelectionUseContext(c *xgb.Conn, ContextLen uint32, Context string) SetSelectionUseContextCookie { 2139 c.ExtLock.RLock() 2140 defer c.ExtLock.RUnlock() 2141 if _, ok := c.Extensions["SELinux"]; !ok { 2142 panic("Cannot issue request 'SetSelectionUseContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") 2143 } 2144 cookie := c.NewCookie(false, false) 2145 c.NewRequest(setSelectionUseContextRequest(c, ContextLen, Context), cookie) 2146 return SetSelectionUseContextCookie{cookie} 2147 } 2148 2149 // SetSelectionUseContextChecked sends a checked request. 2150 // If an error occurs, it can be retrieved using SetSelectionUseContextCookie.Check() 2151 func SetSelectionUseContextChecked(c *xgb.Conn, ContextLen uint32, Context string) SetSelectionUseContextCookie { 2152 c.ExtLock.RLock() 2153 defer c.ExtLock.RUnlock() 2154 if _, ok := c.Extensions["SELinux"]; !ok { 2155 panic("Cannot issue request 'SetSelectionUseContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") 2156 } 2157 cookie := c.NewCookie(true, false) 2158 c.NewRequest(setSelectionUseContextRequest(c, ContextLen, Context), cookie) 2159 return SetSelectionUseContextCookie{cookie} 2160 } 2161 2162 // Check returns an error if one occurred for checked requests that are not expecting a reply. 2163 // This cannot be called for requests expecting a reply, nor for unchecked requests. 2164 func (cook SetSelectionUseContextCookie) Check() error { 2165 return cook.Cookie.Check() 2166 } 2167 2168 // Write request to wire for SetSelectionUseContext 2169 // setSelectionUseContextRequest writes a SetSelectionUseContext request to a byte slice. 2170 func setSelectionUseContextRequest(c *xgb.Conn, ContextLen uint32, Context string) []byte { 2171 size := xgb.Pad((8 + xgb.Pad((int(ContextLen) * 1)))) 2172 b := 0 2173 buf := make([]byte, size) 2174 2175 c.ExtLock.RLock() 2176 buf[b] = c.Extensions["SELinux"] 2177 c.ExtLock.RUnlock() 2178 b += 1 2179 2180 buf[b] = 17 // request opcode 2181 b += 1 2182 2183 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 2184 b += 2 2185 2186 xgb.Put32(buf[b:], ContextLen) 2187 b += 4 2188 2189 copy(buf[b:], Context[:ContextLen]) 2190 b += int(ContextLen) 2191 2192 return buf 2193 } 2194 2195 // SetWindowCreateContextCookie is a cookie used only for SetWindowCreateContext requests. 2196 type SetWindowCreateContextCookie struct { 2197 *xgb.Cookie 2198 } 2199 2200 // SetWindowCreateContext sends an unchecked request. 2201 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 2202 func SetWindowCreateContext(c *xgb.Conn, ContextLen uint32, Context string) SetWindowCreateContextCookie { 2203 c.ExtLock.RLock() 2204 defer c.ExtLock.RUnlock() 2205 if _, ok := c.Extensions["SELinux"]; !ok { 2206 panic("Cannot issue request 'SetWindowCreateContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") 2207 } 2208 cookie := c.NewCookie(false, false) 2209 c.NewRequest(setWindowCreateContextRequest(c, ContextLen, Context), cookie) 2210 return SetWindowCreateContextCookie{cookie} 2211 } 2212 2213 // SetWindowCreateContextChecked sends a checked request. 2214 // If an error occurs, it can be retrieved using SetWindowCreateContextCookie.Check() 2215 func SetWindowCreateContextChecked(c *xgb.Conn, ContextLen uint32, Context string) SetWindowCreateContextCookie { 2216 c.ExtLock.RLock() 2217 defer c.ExtLock.RUnlock() 2218 if _, ok := c.Extensions["SELinux"]; !ok { 2219 panic("Cannot issue request 'SetWindowCreateContext' using the uninitialized extension 'SELinux'. xselinux.Init(connObj) must be called first.") 2220 } 2221 cookie := c.NewCookie(true, false) 2222 c.NewRequest(setWindowCreateContextRequest(c, ContextLen, Context), cookie) 2223 return SetWindowCreateContextCookie{cookie} 2224 } 2225 2226 // Check returns an error if one occurred for checked requests that are not expecting a reply. 2227 // This cannot be called for requests expecting a reply, nor for unchecked requests. 2228 func (cook SetWindowCreateContextCookie) Check() error { 2229 return cook.Cookie.Check() 2230 } 2231 2232 // Write request to wire for SetWindowCreateContext 2233 // setWindowCreateContextRequest writes a SetWindowCreateContext request to a byte slice. 2234 func setWindowCreateContextRequest(c *xgb.Conn, ContextLen uint32, Context string) []byte { 2235 size := xgb.Pad((8 + xgb.Pad((int(ContextLen) * 1)))) 2236 b := 0 2237 buf := make([]byte, size) 2238 2239 c.ExtLock.RLock() 2240 buf[b] = c.Extensions["SELinux"] 2241 c.ExtLock.RUnlock() 2242 b += 1 2243 2244 buf[b] = 5 // request opcode 2245 b += 1 2246 2247 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 2248 b += 2 2249 2250 xgb.Put32(buf[b:], ContextLen) 2251 b += 4 2252 2253 copy(buf[b:], Context[:ContextLen]) 2254 b += int(ContextLen) 2255 2256 return buf 2257 }