├── .gitignore ├── COPYING ├── Makefile ├── blkid.deps ├── blkid.vapi ├── cookie.vapi ├── encap.vapi ├── fcgi.vapi ├── gdbm.vapi ├── glib.suppression ├── glibusb.c ├── glibusb.deps ├── glibusb.h ├── glibusb.vapi ├── hidapi.vapi ├── introspection.vala ├── jump.vapi ├── libcap.deps ├── libcap.vapi ├── libclang.vapi ├── libelf.deps ├── libelf.vapi ├── libffi.vapi ├── libgit2.vapi ├── libpcap.deps ├── libpcap.vapi ├── libpipeline.deps ├── libpipeline.vapi ├── libqrencode.vapi ├── libssh2.deps ├── libssh2.vapi ├── libtasn1.vapi ├── libudev.deps ├── libudev.vapi ├── libvlc.deps ├── libvlc.vapi ├── llvm.deps ├── llvm.vapi ├── mount.deps ├── mount.vapi ├── opencl.vapi ├── tests ├── Makefile ├── bdbtest.flags ├── bdbtest.vala ├── test-blkid.flags ├── test-blkid.vala ├── test-cookie.flags ├── test-cookie.vala ├── test-fcgi.flags ├── test-fcgi.vala ├── test-hidapi.flags ├── test-hidapi.vala ├── test-libelf.flags ├── test-libelf.vala ├── test-libgit2.flags ├── test-libgit2.vala ├── test-libpcap.flags ├── test-libpcap.vala ├── test-libpipeline.flags ├── test-libpipeline.vala ├── test-libqrencode.flags ├── test-libqrencode.vala ├── test-libssh2.flags ├── test-libssh2.vala ├── test-libudev.flags ├── test-libudev.vala ├── test-libvlc.flags ├── test-libvlc.vala ├── test-mount.flags ├── test-mount.vala ├── test-opencl.flags ├── test-opencl.vala ├── test-tricks.flags └── test-tricks.vala ├── tokyodystopia.deps ├── tokyodystopia.vapi ├── transmission-2.0.vapi ├── tricks.h ├── tricks.vapi ├── u2f-host.vapi └── u2f-server.vapi /.gitignore: -------------------------------------------------------------------------------- 1 | doc 2 | introspection.c 3 | introspection.h 4 | introspection.vapi 5 | *-test 6 | tests/*.c 7 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | Each VAPI file is a derivative product of the header files from the programe from which it came. Therefore, each is licensed under the license of the original library. 2 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | introspection.vapi introspection.h introspection.c: introspection.vala 2 | valac --vapi introspection.vapi -C -H introspection.h introspection.vala 3 | -------------------------------------------------------------------------------- /blkid.deps: -------------------------------------------------------------------------------- 1 | posix 2 | -------------------------------------------------------------------------------- /blkid.vapi: -------------------------------------------------------------------------------- 1 | /** 2 | * Interface for libblkid, a library to identify block devices 3 | */ 4 | [CCode (cheader_filename = "blkid.h")] 5 | namespace BlkId { 6 | [CCode (cname = "int", cprefix = "BLKID_FLTR_", has_type_id = false)] 7 | public enum Filter { 8 | NOTIN, 9 | ONLYIN 10 | } 11 | [CCode (cname = "int", has_type_id = false, cprefix = "BLKID_DEV_")] 12 | [Flags] 13 | public enum Get { 14 | /** 15 | * Create an empty device structure if not found in the cache. 16 | */ 17 | FIND, 18 | /** 19 | * Make sure the device structure corresponds with reality. 20 | */ 21 | CREATE, 22 | /** 23 | * Just look up a device entry, and return null if it is not found. 24 | */ 25 | VERIFY, 26 | /** 27 | * Get a valid device structure, either from the cache or by probing the 28 | * device. 29 | */ 30 | NORMAL 31 | } 32 | [CCode (cname = "unsigned long long", cprefix = "BLKID_PARTS_", has_type_id = false)] 33 | [Flags] 34 | public enum PartInfo { 35 | FORCE_GPT, 36 | ENTRY_DETAILS 37 | } 38 | [CCode (cname = "int", cprefix = "BLKID_SUBLKS_", has_type_id = false)] 39 | [Flags] 40 | public enum SuperBlock { 41 | /** 42 | * Read LABEL from superblock 43 | */ 44 | LABEL, 45 | /** 46 | * Read and define LABEL_RAW result value 47 | */ 48 | LABELRAW, 49 | /** 50 | * Read UUID from superblock 51 | */ 52 | UUID, 53 | /** 54 | * Read and define UUID_RAW result value 55 | */ 56 | UUIDRAW, 57 | /** 58 | * Define TYPE result value 59 | */ 60 | TYPE, 61 | /** 62 | * Define compatible fs type (second type) 63 | */ 64 | SECTYPE, 65 | /** 66 | * Define USAGE result value 67 | */ 68 | USAGE, 69 | /** 70 | * Read FS type from superblock 71 | */ 72 | VERSION, 73 | /** 74 | * Define SBMAGIC and SBMAGIC_OFFSET 75 | */ 76 | MAGIC, 77 | DEFAULT 78 | } 79 | [CCode (cname = "int", cprefix = "BLKID_USAGE_", has_type_id = false)] 80 | [Flags] 81 | public enum Usage { 82 | FILESYSTEM, 83 | RAID, 84 | CRYPTO, 85 | OTHER 86 | } 87 | /** 88 | * Information about all system devices 89 | * 90 | * Block device information is normally kept in a cache file blkid.tab and is verified to still be valid before being returned to the user (if the user has read permission on the raw block device, otherwise not). The cache file also allows unprivileged users (normally anyone other than root, or those not in the "disk" group) to locate devices by label/id. The standard location of the cache file can be overridden by the environment variable BLKID_FILE. 91 | * 92 | * In situations where one is getting information about a single known device, it does not impact performance whether the cache is used or not (unless you are not able to read the block device directly). If you are dealing with multiple devices, use of the cache is highly recommended (even if empty) as devices will be scanned at most one time and the on-disk cache will be updated if possible. There is rarely a reason not to use the cache. 93 | * 94 | * In some cases (modular kernels), block devices are not even visible until after they are accessed the first time, so it is critical that there is some way to locate these devices without enumerating only visible devices, so the use of the cache file is required in this situation. 95 | */ 96 | [CCode (cname = "struct blkid_struct_cache", free_function = "blkid_put_cache", has_type_id = false)] 97 | [Compact] 98 | public class Cache { 99 | /** 100 | * Allocates and initialize librray cache handler. 101 | * @param filename path to the cache file or null for the default path 102 | * @return 0 on success or number less than zero in case of error. 103 | */ 104 | [CCode (cname = "blkid_get_cache")] 105 | public static int open (out Cache? cache, string? filename = null); 106 | /** 107 | * Removes garbage (non-existing devices) from the cache. 108 | */ 109 | [CCode (cname = "blkid_gc_cache")] 110 | public void collect_garbage (); 111 | [CCode (cname = "blkid_find_dev_with_tag")] 112 | public Device? find_dev_with_tag (string type, string @value); 113 | /** 114 | * Find a device in the cache by device name, if available. 115 | * 116 | * If there is no entry with the specified device name, and the create flag 117 | * is set, then create an empty device entry. 118 | */ 119 | [CCode (cname = "blkid_get_dev")] 120 | public unowned Device? get (string devname, Get flags); 121 | /** 122 | * Locate a device name from a token (NAME=value string), or (name, value) 123 | * pair. 124 | * 125 | * In the case of a token, value is ignored. If the "token" is not of the 126 | * form "NAME=value" and there is no value given, then it is assumed to be 127 | * the actual devname and a copy is returned. 128 | */ 129 | [CCode (cname = "blkid_get_devname")] 130 | public string? get_name (string token, string @value); 131 | /** 132 | * Find a tagname (e.g. LABEL or UUID) on a specific device. 133 | */ 134 | [CCode (cname = "blkid_get_tag_value")] 135 | public string? get_tag_value (string tagname, string devname); 136 | [CCode (cname = "blkid_dev_iterate_begin")] 137 | public DevIterate iterator (); 138 | /** 139 | * Probes all block devices. 140 | */ 141 | [CCode (cname = "blkid_probe_all")] 142 | public int probe_all (); 143 | /** 144 | * Probes all new block devices. 145 | */ 146 | [CCode (cname = "blkid_probe_all_new")] 147 | public int probe_all_new (); 148 | /** 149 | * The libblkid probing is based on devices from /proc/partitions by default. This file usually does not contain removable devices (e.g. CDROMs) and this kind of devices are invisible for libblkid. 150 | * 151 | * This function adds removable block devices to cache (probing is based on information from the /sys directory). Don't forget that removable devices (floppies, CDROMs, ...) could be pretty slow. It's very bad idea to call this function by default. 152 | * 153 | * Note that devices which were detected by this function won't be written to blkid.tab cache file. 154 | */ 155 | [CCode (cname = "blkid_probe_all_removable")] 156 | public int probe_all_removable (); 157 | /** 158 | * Verify that the data in dev is consistent with what is on the actual 159 | * block device (using the devname field only). Normally this will be 160 | * called when finding items in the cache, but for long running processes 161 | * is also desirable to revalidate an item before use. 162 | * 163 | * If we are unable to revalidate the data, we return the old data and do 164 | * not set the {@link Get.VERIFY} flag on it. 165 | */ 166 | [CCode (cname = "blkid_verify")] 167 | public Device? verify (owned Device dev); 168 | } 169 | /** 170 | * The device object keeps information about one device 171 | */ 172 | [CCode (cname = "struct blkid_struct_dev", has_type_id = false)] 173 | [Compact] 174 | public class Device { 175 | [CCode (cname = "blkid_dev_has_tag")] 176 | public bool has_tag (string type, string @value); 177 | public string? name { 178 | [CCode (cname = "blkid_dev_devname")] 179 | get; 180 | } 181 | [CCode (cname = "blkid_tag_iterate_begin")] 182 | public TagIterate iterator (); 183 | } 184 | /** 185 | * Devices iterator for high-level API 186 | */ 187 | [CCode (cname = "struct blkid_struct_dev_iterate", free_function = "blkid_dev_iterate_end", has_type_id = false)] 188 | [Compact] 189 | public class DevIterate { 190 | [CCode (cname = "blkid_dev_next")] 191 | public int next (out unowned Device? dev); 192 | public unowned Device? next_value () { 193 | unowned Device? dev; 194 | next (out dev); 195 | return dev; 196 | } 197 | [CCode (cname = "blkid_dev_set_search")] 198 | public int set_search (string search_type, string search_value); 199 | } 200 | /** 201 | * List of all detected partitions and partitions tables 202 | */ 203 | [CCode (cname = "struct blkid_struct_partlist", has_type_id = false)] 204 | [Compact] 205 | public class PartList { 206 | public PartTable table { 207 | [CCode (cname = "blkid_partlist_get_table")] 208 | get; 209 | } 210 | public int size { 211 | [CCode (cname = "blkid_partlist_numof_partitions")] 212 | get; 213 | } 214 | [CCode (cname = "blkid_partlist_get_partition")] 215 | public unowned Partition? get (int n); 216 | [CCode (cname = "blkid_partlist_devno_to_partition")] 217 | public unowned Partition? get_by_dev_no (Posix.dev_t devno); 218 | } 219 | /** 220 | * Information about a partition table 221 | */ 222 | [CCode (cname = "struct blkid_struct_parttable", has_type_id = false)] 223 | [Compact] 224 | public class PartTable { 225 | public int64 offset { 226 | [CCode (cname = "blkid_parttable_get_offset")] 227 | get; 228 | } 229 | public Partition? parent { 230 | [CCode (cname = "blkid_parttable_get_parent")] 231 | get; 232 | } 233 | public string? type { 234 | [CCode (cname = "blkid_parttable_get_type")] 235 | get; 236 | } 237 | } 238 | /** 239 | * Information about a partition 240 | */ 241 | [CCode (cname = "struct blkid_struct_partition", has_type_id = false)] 242 | [Compact] 243 | public class Partition { 244 | public PartInfo flags { 245 | [CCode (cname = "blkid_partition_get_flags")] 246 | get; 247 | } 248 | public bool is_extended { 249 | [CCode (cname = "blkid_partition_is_extended")] 250 | get; 251 | } 252 | public bool is_logical { 253 | [CCode (cname = "blkid_partition_is_logical")] 254 | get; 255 | } 256 | public bool is_primary { 257 | [CCode (cname = "blkid_partition_is_primary")] 258 | get; 259 | } 260 | public string? name { 261 | [CCode (cname = "blkid_partition_get_name")] 262 | get; 263 | } 264 | public int number { 265 | [CCode (cname = "blkid_partition_get_partno")] 266 | get; 267 | } 268 | public int64 size { 269 | [CCode (cname = "blkid_partition_get_size")] 270 | get; 271 | } 272 | public int64 start { 273 | [CCode (cname = "blkid_partition_get_start")] 274 | get; 275 | } 276 | public PartTable table { 277 | [CCode (cname = "blkid_partition_get_table")] 278 | get; 279 | } 280 | public int type { 281 | [CCode (cname = "blkid_partition_get_type")] 282 | get; 283 | } 284 | public string? type_name { 285 | [CCode (cname = "blkid_partition_get_type_string")] 286 | get; 287 | } 288 | public string? uuid { 289 | [CCode (cname = "blkid_partition_get_uuid")] 290 | get; 291 | } 292 | } 293 | [CCode (cname = "struct blkid_struct_probe", free_function = "", has_type_id = false)] 294 | [Compact] 295 | public class PartitionFilter { 296 | public bool enabled { 297 | [CCode (cname = "blkid_probe_enable_partitions")] 298 | set; 299 | } 300 | public PartInfo flags { 301 | [CCode (cname = "blkid_probe_set_partitions_flags")] 302 | set; 303 | } 304 | [CCode (cname = "blkid_probe_invert_partitions_filter")] 305 | public int invert (); 306 | [CCode (cname = "blkid_probe_reset_partitions_filter")] 307 | public int reset (); 308 | [CCode (cname = "blkid_probe_filter_partitions_type")] 309 | public int set (Filter flag, [CCode (array_null_terminated = true)] string[] names); 310 | } 311 | /** 312 | * low-level probing setting 313 | */ 314 | [CCode (cname = "struct blkid_struct_probe", free_function = "blkid_free_probe", has_type_id = false)] 315 | [Compact] 316 | public class Prober { 317 | public Posix.dev_t devno { 318 | [CCode (cname = "blkid_probe_get_devno")] 319 | get; 320 | } 321 | public bool enable_topology { 322 | [CCode (cname = "blkid_probe_enable_topology")] 323 | set; 324 | } 325 | public int fd { 326 | [CCode (cname = "blkid_probe_get_fd")] 327 | get; 328 | } 329 | public bool is_whole_disk { 330 | [CCode (cname = "blkid_probe_is_wholedisk")] 331 | get; 332 | } 333 | public int64 offset { 334 | [CCode (cname = "blkid_probe_get_offset")] 335 | get; 336 | } 337 | public PartitionFilter partition_filter { 338 | [CCode (cname = "")] 339 | get; 340 | } 341 | public PartList partitions { 342 | [CCode (cname = "blkid_probe_get_partitions")] 343 | get; 344 | } 345 | public uint sector_size { 346 | [CCode (cname = "blkid_probe_get_sectorsize")] 347 | get; 348 | } 349 | public int64 sectors { 350 | [CCode (cname = "blkid_probe_get_sectors")] 351 | get; 352 | } 353 | public int64 size { 354 | [CCode (cname = "blkid_probe_get_size")] 355 | get; 356 | } 357 | public SuperblockFilter superblock_filter { 358 | [CCode (cname = "")] 359 | get; 360 | } 361 | /** 362 | * The topology chain provides details about Linux block devices 363 | */ 364 | public Topology? topology { 365 | [CCode (cname = "blkid_probe_get_topology")] 366 | get; 367 | } 368 | public int value_count { 369 | [CCode (cname = "blkid_probe_numof_values")] 370 | get; 371 | } 372 | public Posix.dev_t whole_disk_devno { 373 | [CCode (cname = "blkid_probe_get_wholedisk_devno")] 374 | get; 375 | } 376 | [CCode (cname = "blkid_new_probe")] 377 | public Prober (); 378 | [CCode (cname = "blkid_new_probe_from_filename")] 379 | public static Prober? open (string filename); 380 | [CCode (cname = "blkid_probe_has_value")] 381 | public bool contains (string name); 382 | /** 383 | * This function gathers probing results from all enabled chains. 384 | * 385 | * Same as {@link do_safe_probe} but does not check for collision between probing result. 386 | * 387 | * This is string-based NAME=value interface only. 388 | */ 389 | [CCode (cname = "blkid_do_fullprobe")] 390 | public int do_full_probe (); 391 | /** 392 | * Calls probing functions in all enabled chains. 393 | * 394 | * The superblocks chain is enabled by default. The probe stores result from only one probing function. It's necessary to call this routine in a loop to get results from all probing functions in all chains. The probing is reset by {@link reset} or by filter functions. 395 | * 396 | * This is string-based NAME=value interface only. 397 | */ 398 | [CCode (cname = "blkid_do_probe")] 399 | public int do_probe (); 400 | /** 401 | * This function gathers probing results from all enabled chains and checks for ambivalent results (e.g. more filesystems on the device). 402 | * 403 | * This is string-based NAME=value interface only. 404 | * 405 | * Note about suberblocks chain -- the function does not check for filesystems when a RAID signature is detected. The function also does not check for collision between RAIDs. The first detected RAID is returned. The function checks for collision between partition table and RAID signature -- it's recommended to enable partitions chain together with superblocks chain. 406 | */ 407 | [CCode (cname = "blkid_do_safeprobe")] 408 | public int do_safe_probe (); 409 | [CCode (cname = "blkid_probe_get_value")] 410 | public int get_value (int num, out unowned string name, [CCode (array_length_type = "size_t")] out unowned uint8[]? data); 411 | [CCode (cname = "blkid_probe_lookup_value")] 412 | public int lookup_value (string name, [CCode (array_length_type = "size_t")] out unowned uint8[]? data); 413 | /** 414 | * Zeroize probing results and resets the current probing. 415 | * 416 | * This has impact to {@link do_probe} only). This function does not touch probing filters and keeps assigned device. 417 | */ 418 | [CCode (cname = "blkid_reset_probe")] 419 | public void reset (); 420 | /** 421 | * Assigns the device to probe control struct, resets internal buffers and resets the current probing. 422 | * @param fd device file descriptor 423 | * @param off begin of probing area 424 | * @param size size of probing area (zero means whole device/file) 425 | */ 426 | [CCode (cname = "blkid_probe_set_device")] 427 | public int set_device (int fd, int64 off, int64 size); 428 | } 429 | [CCode (cname = "struct blkid_struct_probe", free_function = "", has_type_id = false)] 430 | [Compact] 431 | public class SuperblockFilter { 432 | public bool enabled { 433 | [CCode (cname = "blkid_probe_enable_superblocks")] 434 | set; 435 | } 436 | public SuperBlock flags { 437 | [CCode (cname = "blkid_probe_set_superblocks_flags")] 438 | set; 439 | } 440 | [CCode (cname = "blkid_probe_invert_superblocks_filter")] 441 | public int invert (); 442 | [CCode (cname = "blkid_probe_reset_superblocks_filter")] 443 | public int reset (); 444 | [CCode (cname = "blkid_probe_filter_superblocks_type")] 445 | public int set_type (Filter flag, [CCode (array_null_terminated = true)] string[] names); 446 | [CCode (cname = "blkid_probe_filter_superblocks_usage")] 447 | public int set_usage (Filter flag, Usage usage); 448 | } 449 | /** 450 | * Tags iterator for high-level API 451 | */ 452 | [CCode (cname = "struct blkid_struct_tag_iterate", free_function = "blkid_tag_iterate_end", has_type_id = false)] 453 | [Compact] 454 | public class TagIterate { 455 | [CCode (cname = "blkid_tag_next")] 456 | public int next_tag (out unowned string? type, out unowned string? @value); 457 | public string[]? next_value () { 458 | unowned string? type; 459 | unowned string? @value; 460 | return next_tag (out type, out @value) == 0? new string[] { 461 | type, @value 462 | } : null; 463 | } 464 | } 465 | /** 466 | * Device topology information 467 | */ 468 | [CCode (cname = "struct blkid_struct_topology", has_type_id = false)] 469 | [Compact] 470 | public class Topology { 471 | /** 472 | * How many bytes the beginning of the device is offset from the disk's natural alignment. 473 | */ 474 | public ulong alignment_offset { 475 | [CCode (cname = "blkid_topology_get_alignment_offset")] 476 | get; 477 | } 478 | /** 479 | * The smallest unit the storage device can address. It is typically 512 bytes. 480 | */ 481 | public ulong logical_sector_size { 482 | [CCode (cname = "blkid_topology_get_logical_sector_size")] 483 | get; 484 | } 485 | /** 486 | * Minimum size which is the device's preferred unit of I/O. For RAID arrays it is often the stripe chunk size. 487 | */ 488 | public ulong minimum_io_size { 489 | [CCode (cname = "blkid_topology_get_minimum_io_size")] 490 | get; 491 | } 492 | /** 493 | * Usually the stripe width for RAID or zero. For RAID arrays it is usually the stripe width or the internal track size. 494 | */ 495 | public ulong optimal_io_size { 496 | [CCode (cname = "blkid_topology_get_optimal_io_size")] 497 | get; 498 | } 499 | /** 500 | * The smallest unit a physical storage device can write atomically. It is usually the same as the logical sector size but may be bigger. 501 | */ 502 | public ulong physical_sector_size { 503 | [CCode (cname = "blkid_topology_get_physical_sector_size")] 504 | get; 505 | } 506 | } 507 | [CCode (cname = "BLKID_DATE")] 508 | public const string DATE; 509 | [CCode (cname = "BLKID_VERSION")] 510 | public const string VERSION; 511 | /** 512 | * This function finds the pathname to a block device with a given device number. 513 | */ 514 | [CCode (cname = "blkid_devno_to_devname")] 515 | public string? devno_to_name (Posix.dev_t devno); 516 | /** 517 | * This function uses sysfs to convert the devno device number to the '''name''' of the whole disk. 518 | * 519 | * The function DOES NOT return full device name. The dev argument could be partition or whole disk -- both are converted. 520 | * @see devno_to_name 521 | */ 522 | [CCode (cname = "blkid_devno_to_wholedisk")] 523 | public int devno_to_wholedisk (Posix.dev_t dev, [CCode (array_length_type = "size_t")] uint8[]? buffer, out Posix.dev_t diskdevno); 524 | /** 525 | * Encode all potentially unsafe characters of a string to the corresponding hex value prefixed by '\x'. 526 | */ 527 | [CCode (cname = "blkid_encode_string")] 528 | public int encode_string (string str, [CCode (array_length_type = "size_t")] uint8[] buffer); 529 | /** 530 | * All returned paths are canonicalized, device-mapper paths are converted to the /dev/mapper/name format. 531 | * @param token an unparsed tag (e.g., LABEL=foo) or path 532 | * @return the device name 533 | */ 534 | [CCode (cname = "blkid_evaluate_spec")] 535 | public string? evaluate_spec (string token, Cache? cache = null); 536 | /** 537 | * Evaluate a tag. 538 | * @param token the token name (e.g., LABEL or UUID) or the unparsed tag (e.g., LABEL=foo) 539 | * @param value the token data 540 | * @return the device name 541 | */ 542 | [CCode (cname = "blkid_evaluate_tag")] 543 | public string? evaluate_tag (string token, string @value, Cache? cache = null); 544 | [CCode (cname = "blkid_get_dev_size")] 545 | public int64 get_dev_size (int fd); 546 | [CCode (cname = "blkid_superblocks_get_name")] 547 | public int get_superblock_name (size_t idx, out unowned string? name, out Usage usage); 548 | /** 549 | * Get the library version. 550 | * @param ver_string the release version (not the SONAME) 551 | * @return release version code 552 | */ 553 | [CCode (cname = "blkid_get_library_version")] 554 | public int get_version (out unowned string ver_string, out unowned string date_string); 555 | [CCode (cname = "blkid_known_fstype")] 556 | public bool is_known_fs_type (string fstype); 557 | [CCode (cname = "blkid_known_pttype")] 558 | public bool is_known_part_type (string pttype); 559 | /** 560 | * Parse a "NAME=value" string. 561 | */ 562 | [CCode (cname = "blkid_parse_tag_string")] 563 | public int parse_tag_string (string token, out string? type, out string? val); 564 | [CCode (cname = "blkid_parse_version_string")] 565 | public int parse_version (string ver_string); 566 | /** 567 | * Allows plain ASCII, hex-escaping and valid utf8. Replaces all whitespaces with '_'. 568 | */ 569 | [CCode (cname = "blkid_safe_string")] 570 | public int safe_string ([CCode (array_length_type = "size_t")] uint8[] buffer); 571 | /** 572 | * Sends a uevent 573 | * @param devname absolute path to the device 574 | * @param action event string 575 | */ 576 | [CCode (cname = "blkid_send_uevent")] 577 | public int send_uevent (string devname, string action); 578 | } 579 | -------------------------------------------------------------------------------- /cookie.vapi: -------------------------------------------------------------------------------- 1 | [CCode (cheader_filename = "stdio.h")] 2 | namespace Cookie { 3 | [CCode (cname = "fopencookie", simple_generics = true)] 4 | private 5 | # if POSIX 6 | Posix.FILE? 7 | # else { 8 | GLib.FileStream? 9 | # endif 10 | _open ([CCode (destroy_notify_pos = -1)] T cookie, string mode, io_functions io_funcs); 11 | } 12 | [CCode (cname = "", simple_generics = true)] 13 | private void _make_reference_disappear (owned T cookie); 14 | /** 15 | * Allows the programmer to create a custom implementation for a standard I/O stream. 16 | * 17 | * This implementation can store the stream's data at a location of its own choosing; for example, it is used to implement {@link open_buffer}, which provides a stream interface to data that is stored in a buffer in memory. 18 | * 19 | * In order to create a custom stream the programmer must: 20 | * * Implement four hook functions that are used internally by the standard I/O library when performing I/O on the stream. 21 | * * Define a "cookie" data type, a structure that provides bookkeeping information (e.g., where to store data) used by the aforementioned hook functions. 22 | * * Call this function to open a new stream and associate the cookie and hook functions with that stream. 23 | * 24 | * The function opens a new stream and returns a pointer to a {@link GLib.FileStream} object that is used to operate on that stream. 25 | */ 26 | [CCode (cname = "_vala_fopencookie")] 27 | public 28 | # if POSIX 29 | Posix.FILE? 30 | # else { 31 | GLib.FileStream? 32 | # endif 33 | open ([CCode (destroy_notify_pos = -1)] owned T cookie, string mode, io_functions io_funcs) { 34 | var result = _open (cookie, mode, io_funcs); 35 | _make_reference_disappear ((owned) cookie); 36 | return result; 37 | } 38 | /** 39 | * Open memory as stream 40 | * 41 | * The function opens a stream that permits the access specified by mode. The stream allows I/O to be performed on the memory buffer. 42 | * 43 | * When a stream that has been opened for writing is flushed or closed, a null byte is written at the end of the buffer if there is space. The caller should ensure that an extra byte is available in the buffer (and that size counts that byte) to allow for this. 44 | * 45 | * Attempts to write more than size bytes to the buffer result in an error. (By default, such errors will only be visible when the stdio buffer is flushed. 46 | * 47 | * In a stream opened for reading, null bytes ('\0') in the buffer do not cause read operations to return an end-of-file indication. A read from the buffer will only indicate end-of-file when the file pointer advances size bytes past the start of the buffer. 48 | * 49 | * @param mode is the same as for {@link GLib.FileStream.open}. If mode specifies an append mode, then the initial file position is set to the location of the first null byte ('\0') in the buffer; otherwise the initial file position is set to the start of the buffer. Since glibc 2.9, the letter 'b' may be specified as the second character in mode. This provides "binary" mode: writes don't implicitly add a terminating null byte, and {@link GLib.FileStream.seek} when {@link GLib.FileSeek.END} is relative to the end of the buffer (i.e., the value specified by the size argument), rather than the current string length. 50 | */ 51 | [CCode (cname = "fmemopen")] 52 | public 53 | # if POSIX 54 | Posix.FILE? 55 | # else { 56 | GLib.FileStream? 57 | # endif open_buffer ([CCode (array_length_type = "size_t")] uint8[] buf, string mode); 58 | } 59 | } 60 | [CCode (cname = "cookie_io_functions_t")] 61 | [SimpleType] 62 | public struct io_functions { 63 | /** 64 | * Cleanup any data associated with the cookie. If null, then no special action is performed when the stream is closed. 65 | */ 66 | CloseFunction? close; 67 | /** 68 | * The read function for this file. If null, then reads from the custom stream always return end of file. 69 | */ 70 | ReadFunction? read; 71 | /** 72 | * The seek function for this file. If null, then it is not possible to perform seek operations on the stream. 73 | */ 74 | SeekFunction? seek; 75 | /** 76 | * The write function for this file. If null, then writes are discarded. 77 | */ 78 | WriteFunction? write; 79 | } 80 | /** 81 | * Closes the stream. 82 | * @return 0 on success, and EOF on error. 83 | */ 84 | [CCode (cname = "cookie_close_function_t", simple_generics = true, has_target = false)] 85 | public delegate int CloseFunction (owned T cookie); 86 | /** 87 | * Implements read operations for the stream. 88 | * 89 | * The read function should update the stream offset appropriately. 90 | * @param buf a buffer into which input data can be placed. 91 | * @return As its function result, the read function should return the number of bytes copied, 0 on end of file, or -1 on error. 92 | */ 93 | [CCode (cname = "cookie_read_function_t", simple_generics = true, has_target = false)] 94 | public delegate ssize_t ReadFunction (T cookie, [CCode (array_length_type = "size_t")] uint8[]? buf); 95 | /** 96 | * Implements seek operations on the stream. 97 | * 98 | * @param offset argument specifies the new file offset. Before returning, the seek function should update *offset to indicate the new stream offset. 99 | * @param whence The point in the stream from where the offset should be counted. 100 | * @return 0 on success, and -1 on error. 101 | */ 102 | [CCode (cname = "cookie_seek_function_t", simple_generics = true, has_target = false)] 103 | public delegate int SeekFunction (T cookie, ref int64 offset, 104 | # if POSIX 105 | int 106 | # else { 107 | GLib.FileSeek 108 | # endif 109 | whence); 110 | } 111 | /** 112 | * Implements write operations for the stream. 113 | * 114 | * The write function should update the stream offset appropriately. 115 | * @param buf a buffer of data to be output to the stream 116 | * @return the number of bytes copied, or -1 on error 117 | */ 118 | [CCode (cname = "cookie_write_function_t", simple_generics = true, has_target = false)] 119 | public delegate ssize_t WriteFunction (T cookie, [CCode (array_length_type = "size_t")] uint8[]? buf); 120 | } 121 | -------------------------------------------------------------------------------- /fcgi.vapi: -------------------------------------------------------------------------------- 1 | /** 2 | * FastCGI server interface library 3 | * 4 | * This library makes it easy to be a server for FastCGI programs so that a web server, like Apache, nginx, or lighthttpd can proxy for this application. 5 | * 6 | * There are three interfaces: a CGI-esque interface available through {@link stdin} and friends, a single-threaded interface available via {@link accept} and a multi-threaded interface available via {@link request}. 7 | */ 8 | [CCode (cheader_filename = "fcgiapp.h")] 9 | namespace FastCGI { 10 | 11 | /** 12 | * FastCGI's abstraction over a file I/O 13 | */ 14 | [CCode (cname = "FCGI_FILE", cheader_filename = "fcgi_stdio.h", free_function = "FCGI_pclose", has_type_id = false)] 15 | public class FileStream { 16 | public int descriptor { 17 | [CCode (cname = "FCGI_fileno")] 18 | get; 19 | } 20 | public GLib.FileStream file_stream { 21 | [CCode (cname = "FCGI_ToFILE")] 22 | get; 23 | } 24 | public Stream stream { 25 | [CCode (cname = "FCGI_ToFcgiStream")] 26 | get; 27 | } 28 | 29 | [CCode (cname = "FCGI_fopen")] 30 | public static FileStream? open (string path, string mode); 31 | [CCode (cname = "FCGI_fdopen")] 32 | public static FileStream? fdopen (int fildes, string mode); 33 | [CCode (cname = "FCGI_tmpfile")] 34 | public static FileStream? tmpfile (); 35 | [CCode (cname = "FCGI_popen")] 36 | public static FileStream? popen (string cmd, string type); 37 | [ReturnsModifiedPointer] 38 | [CCode (cname = "FCGI_freopen", instance_pos = -1)] 39 | public static FileStream? reopen (string path, string mode); 40 | [CCode (cname = "FCGI_clearerr")] 41 | public void clear_error (); 42 | [CCode (cname = "FCGI_feof")] 43 | public bool eof (); 44 | [CCode (cname = "FCGI_fflush")] 45 | public int flush (); 46 | [CCode (cname = "FCGI_fgetc")] 47 | public int getc (); 48 | [CCode (cname = "FCGI_fgets", instance_pos = -1)] 49 | public unowned string? gets (char[] s); 50 | [CCode (cname = "FCGI_ferror")] 51 | public int get_error (); 52 | [CCode (cname = "FCGI_fprintf")] 53 | [PrintfFormat ()] 54 | public void printf (string format, ...); 55 | [CCode (cname = "FCGI_fputc", instance_pos = -1)] 56 | public void putc (char c); 57 | [CCode (cname = "FCGI_fputs", instance_pos = -1)] 58 | public void puts (string s); 59 | [CCode (cname = "FCGI_fread", instance_pos = -1)] 60 | public size_t read ([CCode (array_length_pos = 2.1)] uint8[] buf, size_t size = 1); 61 | [CCode (cname = "FCGI_rewind")] 62 | public void rewind (); 63 | [CCode (cname = "FCGI_fseek")] 64 | public int seek (long offset, GLib.FileSeek whence); 65 | [CCode (cname = "FCGI_ftell")] 66 | public int tell (); 67 | [CCode (cname = "FCGI_ungetc", instance_pos = -1)] 68 | public int ungetc (int c); 69 | [CCode (cname = "FCGI_vfprintf")] 70 | public void vprintf (string format, va_list args); 71 | [CCode (cname = "FCGI_fwrite", instance_pos = -1)] 72 | public size_t write ([CCode (array_length_pos = 2.1)] uint8[] buf, size_t size = 1); 73 | } 74 | /** 75 | * The state of a FastCGI stream. 76 | * 77 | * Streams are modeled after the {@link GLib.FileStream}. 78 | * (We wouldn't need our own if platform vendors provided a 79 | * standard way to subclass theirs.) 80 | * The state of a stream is private and should only be accessed 81 | * by the procedures defined below. 82 | */ 83 | [CCode (cname = "FCGX_Stream", free_function = "FCGX_FClose", has_type_id = false)] 84 | [Compact] 85 | public class Stream { 86 | [CCode (cname = "isReader")] 87 | public bool is_reader; 88 | [CCode (cname = "isClosed")] 89 | public bool is_closed; 90 | 91 | /** 92 | * Create a stream (used by cgi-fcgi). 93 | * 94 | * This shouldn't be needed by a FastCGI application. 95 | */ 96 | [CCode (cname = "FCGX_CreateWriter")] 97 | public static Stream create_writer (int socket, int request_id, int bufflen, int streamType); 98 | 99 | /** 100 | * Clear the stream error code and end-of-file indication. 101 | */ 102 | [CCode (cname = "FCGX_ClearError")] 103 | public void clear_error (); 104 | 105 | /** 106 | * Flushes any buffered output. 107 | * 108 | * Server-push is a legitimate application of this method. 109 | * Otherwise, this method is not very useful, since {@link accept} 110 | * does it implicitly. Calling it in non-push applications 111 | * results in extra writes and therefore reduces performance. 112 | */ 113 | [CCode (cname = "FCGX_FFlush")] 114 | public bool flush (); 115 | 116 | /** 117 | * Return the stream error code. 118 | * @return 0 means no error, > 0 is an errno(2) error, < 0 is an FastCGI error. 119 | */ 120 | [CCode (cname = "FCGX_GetError")] 121 | public int get_error (); 122 | 123 | /** 124 | * Reads a byte from the input stream and returns it. 125 | * 126 | * @return The byte, or {@link GLib.FileStream.EOF} if the end of input has been reached. 127 | */ 128 | [CCode (cname = "FCGX_GetChar")] 129 | public int getc (); 130 | 131 | [CCode (cname = "FCGX_GetLine", instance_pos = 1.2)] 132 | public unowned string? gets (uint8[] buffer); 133 | 134 | /** 135 | * Returns true if end-of-file has been detected while reading from stream. 136 | * 137 | * Note that this may return false, yet an immediately 138 | * following {@link getc} may return EOF. This function, like 139 | * the standard C stdio function {@link GLib.FileStream.eof}, does not provide the 140 | * ability to peek ahead. 141 | */ 142 | [CCode (cname = "FCGX_HasSeenEOF")] 143 | public bool has_seen_eof (); 144 | 145 | /** 146 | * Performs printf-style output formatting and writes the results to the output stream. 147 | * @return Number of bytes written for normal return, or {@link GLib.FileStream.EOF} if an error occurred. 148 | */ 149 | [CCode (cname = "FCGX_FPrintF")] 150 | [PrintfFormat] 151 | public int printf (string format, ...); 152 | 153 | /** 154 | * Writes the buffer into the output stream. 155 | * 156 | * Performs no interpretation of the output bytes. 157 | * 158 | * @return Number of bytes written for normal return, or {@link GLib.FileStream.EOF} if an error occurred. 159 | */ 160 | [CCode (cname = "FCGX_PutStr", instance_pos = 1.3)] 161 | public int put_str (uint8[] buffer); 162 | 163 | /** 164 | * Writes a byte to the output stream. 165 | * 166 | * @return The byte, or {@link GLib.FileStream.EOF} if an error occurred. 167 | */ 168 | [CCode (cname = "FCGX_PutChar", instance_pos = 1.2)] 169 | public int putc (int c); 170 | 171 | /** 172 | * Writes a string to the output stream. 173 | * @return Number of bytes written for normal return, or {@link GLib.FileStream.EOF} if an error occurred. 174 | */ 175 | [CCode (cname = "FCGX_PutS", instance_pos = -1)] 176 | public int puts (string str); 177 | 178 | /** 179 | * Reads up to consecutive bytes from the input stream 180 | * into the character array. 181 | * 182 | * Performs no interpretation of the input bytes. 183 | * @return Number of bytes read. If result is smaller than the buffer size, 184 | * end of input has been reached. 185 | */ 186 | [CCode (cname = "FCGX_GetStr", instance_pos = 1.2)] 187 | public int read (uint8[] buffer); 188 | 189 | /** 190 | * Sets the exit status for stream's request. 191 | * 192 | * The exit status is the status code the request would have exited with, 193 | * had the request been run as a CGI program. You can call this 194 | * several times during a request; the last call before the request ends 195 | * determines the value. 196 | */ 197 | [CCode (cname = "FCGX_SetExitStatus", instance_pos = 1.2)] 198 | public void set_exit_status (int status); 199 | 200 | /** 201 | * Repositions an input stream to the start of FCGI_DATA. 202 | * 203 | * If the preconditions are not met sets the stream error code to 204 | * {@link CALL_SEQ_ERROR}. 205 | * 206 | * @return 0 for a normal return, < 0 for error 207 | */ 208 | [CCode (cname = "FCGX_StartFilterData")] 209 | public int start_filter (); 210 | 211 | /** 212 | * Pushes back the character onto the input stream. 213 | * 214 | * One character of pushback is guaranteed once a character 215 | * has been read. No pushback is possible for EOF. 216 | * 217 | * @return c if the pushback succeeded, {@link GLib.FileStream.EOF} if not. 218 | */ 219 | [CCode (cname = "FCGX_UnGetChar", instance_pos = 1.2)] 220 | public int ungetc (int c); 221 | 222 | [CCode (cname = "FCGX_VFPrintF")] 223 | public int vprintf (string format, va_list arg); 224 | } 225 | 226 | /** 227 | * CGI parameters 228 | */ 229 | [CCode (cname = "FCGX_ParamArray", has_type_id = false)] 230 | [SimpleType] 231 | public struct parameters { 232 | [CCode (cname = "FCGX_GetParam", instance_pos = -1)] 233 | public unowned string? get (string name); 234 | [CCode (array_null_terminated = true, array_length = false)] 235 | public unowned string[] get_all () { 236 | return (string[]) this; 237 | } 238 | } 239 | 240 | /** 241 | * State associated with a request. 242 | * 243 | * This is the API for multi-threaded code. Code should be structured like this: 244 | * {{{ 245 | * int descriptor; 246 | * Mutex mutex; 247 | * void handler() { 248 | * FastCGI.request request; 249 | * assert(FastCGI.request.init(out request, descriptor) == 0); 250 | * while (true) { 251 | * mutex.lock () ; 252 | * var fail = request.accept() < 0; 253 | * mutex.unlock(); 254 | * if (fail) 255 | * break; 256 | * // Process request 257 | * request.finish(); 258 | * } 259 | * request.close(false); 260 | * } 261 | * void main() { 262 | * mutex = new Mutex(); 263 | * assert(FastCGI.init() == 0); 264 | * stderr.printf("I:open_socket path=\"%s\" backlog=%d\n", socket_path, backlog); 265 | * descriptor = FastCGI.open_socket(socket_path, backlog); 266 | * assert(descriptor != -1); 267 | * try { 268 | * while (thread_count > 1) { 269 | * Thread.create(handler, false); 270 | * thread_count--; 271 | * } 272 | * handler(); 273 | * } catch(ThreadError e) { 274 | * // Handle error 275 | * } 276 | * } 277 | * }}} 278 | * It is important that only one thread at a time attempt to call {@link accept}, hence the mutex. The request can be read from the client using {@link environment} and the response can be written to the client using {@link out}. 279 | */ 280 | [CCode (cname = "FCGX_Request", has_type_id = false, destroy_function = "")] 281 | public struct request { 282 | [CCode (cname = "envp")] 283 | public parameters environment; 284 | public Stream err; 285 | public Stream @in; 286 | public Stream @out; 287 | [CCode (cname = "requestId")] 288 | public int request_id; 289 | public int role; 290 | 291 | /** 292 | * Accept a new request 293 | * 294 | * Thread-safe. 295 | * 296 | * Finishes the request accepted by (and frees any 297 | * storage allocated by) the previous call. 298 | * Creates input, output, and error streams and 299 | * assigns them to in, out, and err respectively. 300 | * Creates a parameters data structure. 301 | * 302 | * DO NOT retain pointers to the envp or any strings 303 | * contained in it, since these will be freed 304 | * by the next call or a call to {@link finish}. 305 | * 306 | * @return 0 for successful call, -1 for error. 307 | */ 308 | [CCode (cname = "FCGX_Accept_r")] 309 | public int accept (); 310 | 311 | /** 312 | * Close this stream. 313 | * @param close_descriptor Close the underlying file descriptor. 314 | */ 315 | [CCode (cname = "FCGX_Free")] 316 | [DestroysInstance] 317 | public void close (bool close_descriptor = true); 318 | 319 | /** 320 | * Finish the request 321 | * 322 | * Thread-safe. 323 | * 324 | * Finishes the request accepted by (and frees any 325 | * storage allocated by) the previous call to {@link accept}. 326 | * 327 | * DO NOT retain pointers to the envp array or any strings 328 | * contained in it, since these will be freed. 329 | */ 330 | [CCode (cname = "FCGX_Finish_r")] 331 | public void finish (); 332 | 333 | /** 334 | * Initialize a request. 335 | * 336 | * @param sock is a file descriptor returned by {@link open_socket} or 0 (default). 337 | * 338 | * @return 0 upon success. 339 | */ 340 | [CCode (cname = "FCGX_InitRequest")] 341 | public static int init (out request request, int sock = 0, RequestFlags flags = RequestFlags.NONE); 342 | 343 | /** 344 | * Get a named parameter from the environment. 345 | */ 346 | public unowned string? @get (string name) { 347 | return environment[name]; 348 | } 349 | } 350 | 351 | [CCode (cname = "int", cprefix = "FCGI_", has_type_id = false)] 352 | [Flags] 353 | public enum RequestFlags { 354 | [CCode (cname = "0")] 355 | NONE, 356 | /** 357 | * Do not restart upon being interrupted. 358 | */ 359 | FAIL_ACCEPT_ON_INTR 360 | } 361 | 362 | /** 363 | * Accept a new request 364 | * 365 | * NOT thread-safe. 366 | * 367 | * Finishes the request accepted by (and frees any 368 | * storage allocated by) the previous call. 369 | * Creates input, output, and error streams and 370 | * assigns them to in, out, and err respectively. 371 | * Creates a parameters data structure and assigns it to envp. 372 | * 373 | * DO NOT retain pointers to the envp array or any strings 374 | * contained in it, since these will be freed by 375 | * the next call or a call to {@link finish}. 376 | * 377 | * Code is generally of this form: 378 | * {{{ 379 | * Stream @in; 380 | * Stream @out; 381 | * Stream @err; 382 | * unowned parameters envp; 383 | * while(accept(out @in, out @out, out @err, out envp) == 0) { 384 | * // Process request, writing output to @out. 385 | * finish(); 386 | * } 387 | * }}} 388 | * @return 0 for successful call, -1 for error. 389 | */ 390 | [CCode (cname = "FCGX_Accept")] 391 | public int accept (out Stream @in, out Stream @out, out Stream err, out unowned parameters envp); 392 | 393 | /** 394 | * Finish the current request 395 | * 396 | * NOT thread-safe. 397 | * 398 | * Finishes the request accepted by (and frees any 399 | * storage allocated by) the previous call to {@link accept}. 400 | * 401 | * DO NOT retain pointers to the {@link parameters} or any strings 402 | * contained in it, since these will be freed. 403 | * @see accept 404 | */ 405 | [CCode (cname = "FCGX_Finish")] 406 | public void finish (); 407 | 408 | /** 409 | * Initialize the FCGX library. 410 | * 411 | * Call in multi-threaded apps. 412 | * @return 0 upon success. 413 | */ 414 | [CCode (cname = "FCGX_Init")] 415 | public int init (); 416 | 417 | /** 418 | * Is this process a CGI process rather than a FastCGI process. 419 | */ 420 | [CCode (cname = "FCGX_IsCGI")] 421 | public bool is_cgi (); 422 | 423 | /** 424 | * Create a FastCGI listen socket. 425 | * 426 | * @param path is the Unix domain socket (named pipe for WinNT), or a colon 427 | * followed by a port number. (e.g. "/tmp/fastcgi/mysocket", ":5000") 428 | * @param backlog is the listen queue depth used in the listen() call. 429 | * @return the socket's file descriptor or -1 on error. 430 | */ 431 | [CCode (cname = "FCGX_OpenSocket")] 432 | public int open_socket (string path, int backlog); 433 | 434 | /** 435 | * Prevent the lib from accepting any new requests. 436 | * 437 | * Signal handler safe. 438 | */ 439 | [CCode (cname = "FCGX_ShutdownPending")] 440 | public void shutdown_pending (); 441 | 442 | /** 443 | * Standard error abstraction using FastCGI. 444 | * 445 | * This should be used if you are not using the multi-threaded {@link accept} or {@link request}-based API. 446 | */ 447 | [CCode (cname = "FCGI_stderr", cheader_filename = "fcgi_stdio.h")] 448 | public static FileStream stderr; 449 | /** 450 | * Standard input abstraction using FastCGI. 451 | * 452 | * This should be used if you are not using the multi-threaded {@link accept} or {@link request}-based API. 453 | */ 454 | [CCode (cname = "FCGI_stdin", cheader_filename = "fcgi_stdio.h")] 455 | public static FileStream stdin; 456 | /** 457 | * Standard output abstraction using FastCGI. 458 | * 459 | * This should be used if you are not using the multi-threaded {@link accept} or {@link request}-based API. 460 | */ 461 | [CCode (cname = "FCGI_stdout", cheader_filename = "fcgi_stdio.h")] 462 | public static FileStream stdout; 463 | 464 | [CCode (cname = "FCGX_CALL_SEQ_ERROR")] 465 | public const int CALL_SEQ_ERROR; 466 | [CCode (cname = "FCGX_PARAMS_ERROR")] 467 | public const int PARAMS_ERROR; 468 | [CCode (cname = "FCGX_PROTOCOL_ERROR")] 469 | public const int PROTOCOL_ERROR; 470 | [CCode (cname = "FCGX_UNSUPPORTED_VERSION")] 471 | public const int UNSUPPORTED_VERSION; 472 | } 473 | -------------------------------------------------------------------------------- /gdbm.vapi: -------------------------------------------------------------------------------- 1 | [CCode (cheader_filename = "gdbm.h")] 2 | namespace GDBM { 3 | 4 | /** 5 | * Configuration mode for opening a database. 6 | */ 7 | [Flags] 8 | [CCode (cprefix = "GDBM_", type = "int", has_type_id = false)] 9 | public enum OpenFlag { 10 | /** 11 | * Open file as reader. 12 | */ 13 | READER, 14 | /** 15 | * Open file as writer. 16 | */ 17 | WRITER, 18 | /** 19 | * Open as a writer and create the file if it doesn't exist. 20 | */ 21 | WRCREAT, 22 | /** 23 | * Open as a writer and overwrite any existing file. 24 | */ 25 | NEWDB, 26 | /** 27 | * All database operations should be synchronized to the disk. 28 | */ 29 | SYNC, 30 | /** 31 | * Do not perform any locking on the database file. 32 | */ 33 | NOLOCK, 34 | /** 35 | * No-sync mode (now the default). 36 | */ 37 | [Deprecated] 38 | FAST 39 | } 40 | 41 | [SimpleType] 42 | [CCode (cname = "datum", destroy_function = "", has_type_id = false)] 43 | private struct rdatum { 44 | [CCode (cname = "dptr", array_length_cname = "dsize", array_length_type = "int")] 45 | uint8[] data; 46 | } 47 | 48 | [SimpleType] 49 | [CCode (cname = "datum", has_destroy_function = false, has_type_id = false)] 50 | private struct datum { 51 | [CCode (array_length = false)] 52 | unowned uint8[] dptr; 53 | int dsize; 54 | } 55 | 56 | /** 57 | * The gdbm build release string. 58 | */ 59 | [CCode (cname = "gdbm_version")] 60 | public const string VERSION; 61 | 62 | [CCode (type = "int", cprefix = "GDBM_", has_type_id = false)] 63 | private enum Option { 64 | CACHESIZE, 65 | FASTMODE, 66 | SYNCMODE, 67 | CENTFREE, 68 | COALESCEBLKS 69 | } 70 | 71 | /** 72 | * Delegate for the handler when database opening fails 73 | */ 74 | [CCode (has_target = false, has_type_id = false)] 75 | public delegate void FatalHandler (); 76 | 77 | /** 78 | * Access handle to a gdbm database. 79 | * 80 | * GNU dbm is a library of routines that manages data files that contain key/data pairs. The access provided is that of storing, retrieval, and deletion by key and a non-sorted traversal of all keys. A process is allowed to use multiple data files at the same time. 81 | * A process that opens a gdbm file is designated as a "reader" or a "writer". Only one writer may open a gdbm file and many readers may open the file. Readers and writers can not open the gdbm file at the same time. 82 | */ 83 | [Compact] 84 | [CCode (cname = "void", cprefix = "gdbm_", free_function = "gdbm_close", has_type_id = false)] 85 | public class Database { 86 | 87 | private int @delete (datum key); 88 | private bool exists (datum key); 89 | private rdatum fetch (datum key); 90 | private rdatum firstkey (); 91 | private rdatum nextkey (datum previous); 92 | private int reorganize (); 93 | private int setopt (Option option, int* value, int size); 94 | private int store (datum key, datum content, [CCode (type = "int")] bool replace); 95 | 96 | /** 97 | * Open a database. 98 | * 99 | * @param filename specifies the database file. 100 | * @param block_size is meaningful only when creating a new gdbm database; it is the retrieval block size to be used for the file. If a number less than 256 is given, the system stat page size will be used, but if you are storing large chunks of data in your file, you may want to consider bumping blocksize up. 101 | * @param flag specifies the access mode. There may be only one writer at a time, but an arbitrary number of readers. If a file is open for writing, attempts to open it for reading will fail. 102 | * @param mode specifies the mode of a newly created database file; it takes the same form as for Unix chmod, so for instance 0666 is read-write access for everybody. 103 | * @param handler can be used to assign an error handler; the function should take a single string. If you specify null for this function, gdbm uses a default handler. 104 | */ 105 | public static Database open (string filename, int block_size, OpenFlag flag, int mode = 0644, FatalHandler? handler = null); 106 | 107 | /** 108 | * Compact the database 109 | * 110 | * If you have had a lot of deletions and would like to shrink the space used by the gdbm file, this routine will reorganize the database. Gdbm will not shorten the length of a gdbm file except by using this reorganization. (Deleted file space will be reused.) It should be used very infrequently. 111 | */ 112 | public bool compact () { 113 | return this.reorganize () == 0; 114 | } 115 | 116 | /** 117 | * Search the database without retrieving data. 118 | * 119 | * @param key the data to be searched. 120 | * @return Returns true if the key is within the database. 121 | */ 122 | public bool contains (uint8[] key) { 123 | datum k; 124 | k.dptr = key; 125 | k.dsize = key.length; 126 | return exists (k); 127 | } 128 | 129 | /** 130 | * Retrieve the "first" key in the database. 131 | */ 132 | public uint8[] first_key () { 133 | return this.firstkey ().data; 134 | } 135 | 136 | /** 137 | * Retrieve data from the database 138 | * 139 | * Get data from the database. 140 | * @param key is the key data. 141 | * @return If the return value is null, no data was found. Otherwise the return value is the found data. 142 | */ 143 | public uint8[]? @get (uint8[] key) { 144 | datum k; 145 | k.dptr = key; 146 | k.dsize = key.length; 147 | return (owned) this.fetch (k).data; 148 | } 149 | 150 | /** 151 | * Retrieve the following key in the database. 152 | * 153 | * This access is not key sequential, but it is guaranteed to visit every key in the database once. Key order can be rearrange if the database is modified! 154 | * @param key the preceding key 155 | */ 156 | public uint8[]? next_key (uint8[] key) { 157 | datum k; 158 | k.dptr = key; 159 | k.dsize = key.length; 160 | return this.nextkey (k).data; 161 | } 162 | 163 | /** 164 | * Remove some data from the database 165 | * 166 | * @param key the data to be deleted. 167 | * @return true if the data was deleted, false if the database is a reader or the data does not exist. 168 | */ 169 | public bool remove (uint8[] key) { 170 | datum k; 171 | k.dptr = key; 172 | k.dsize = key.length; 173 | return this.delete (k) == 0; 174 | } 175 | 176 | /** 177 | * Store data in the database. 178 | * 179 | * If you store data for a key that is already in the database, gdbm replaces the old data with the new data if called with replacement. You do not get two data items for the same key and you do not get an error. 180 | * 181 | * The size in gdbm is not restricted like dbm or ndbm. Your data can be as large as you want. 182 | * 183 | * @param key is the key data. 184 | * @param content is the data to be associated with the key. 185 | * @param replace Replace contents if key exists otherwise insert only, generate an error if key exists. 186 | */ 187 | public bool save (uint8[] key, uint8[] content, bool replace) { 188 | datum k; 189 | k.dptr = key; 190 | k.dsize = key.length; 191 | datum c; 192 | c.dptr = content; 193 | c.dsize = content.length; 194 | return this.store (k, c, replace) == 0; 195 | } 196 | 197 | /** 198 | * Update the database overwriting the existing data. 199 | */ 200 | public void @set (uint8[] key, uint8[] content) { 201 | this.save (key, content, true); 202 | } 203 | 204 | /** 205 | * Flush changes to disk. 206 | * 207 | * This will not return until the disk file state is syncronized with the in-memory state of the database. 208 | */ 209 | public void sync (); 210 | 211 | /** 212 | * Set the size of the internal bucket cache. 213 | * 214 | * This option may only be set once on each database descriptor, and is set automatically to 100 upon the first access to the database. 215 | */ 216 | public int CacheSize { 217 | set { 218 | this.setopt (Option.CACHESIZE, &value, (int) sizeof (int)); 219 | } 220 | } 221 | 222 | /** 223 | * Set central free block pool to either on or off. 224 | * 225 | * The default is off, which is how previous versions of gdbm handled free blocks. If set, this option causes all subsequent free blocks to be placed in the global pool, allowing (in theory) more file space to be reused more quickly. 226 | */ 227 | public bool CentralFreeBlocks { 228 | set { 229 | int v = value ? 1 : 0; 230 | this.setopt (Option.CENTFREE, &v, (int) sizeof (int)); 231 | } 232 | } 233 | 234 | /** 235 | * Set free block merging to either on or off. 236 | * 237 | * The default is off, which is how previous versions of gdbm handled free blocks. If set, this option causes adjacent free blocks to be merged. This can become a CPU expensive process with time, though, especially if used in conjunction with CentralFreeBlocks. 238 | */ 239 | public bool CoalesceBlocks { 240 | set { 241 | int v = value ? 1 : 0; 242 | this.setopt (Option.COALESCEBLKS, &v, (int) sizeof (int)); 243 | } 244 | } 245 | /** 246 | * Set fast mode to either on or off. 247 | * 248 | * This allows fast mode to be toggled on an already open and active database. This option is now obsolete. 249 | */ 250 | [Deprecated] 251 | public bool FastMode { 252 | set { 253 | int v = value ? 1 : 0; 254 | this.setopt (Option.FASTMODE, &v, (int) sizeof (int)); 255 | } 256 | } 257 | 258 | /** 259 | * Turn on or off file system synchronization operations. 260 | * 261 | * This setting defaults to off. 262 | */ 263 | public bool SyncMode { 264 | set { 265 | int v = value ? 1 : 0; 266 | this.setopt (Option.SYNCMODE, &v, (int) sizeof (int)); 267 | } 268 | } 269 | 270 | /** 271 | * The file descriptor used by the database. 272 | */ 273 | public int descriptor { 274 | [CCode (cname = "gdbm_fdesc")] 275 | get; 276 | } 277 | } 278 | 279 | /** 280 | * Error codes set by database operations. 281 | */ 282 | [CCode (type = "gdbm_error", cprefix = "GDBM_", has_type_id = false)] 283 | public enum Error { 284 | /** 285 | * No error 286 | */ 287 | NO_ERROR, 288 | /** 289 | * Malloc error 290 | */ 291 | MALLOC_ERROR, 292 | /** 293 | * Block size error 294 | */ 295 | BLOCK_SIZE_ERROR, 296 | /** 297 | * File open error 298 | */ 299 | FILE_OPEN_ERROR, 300 | /** 301 | * File write error 302 | */ 303 | FILE_WRITE_ERROR, 304 | /** 305 | * File seek error 306 | */ 307 | FILE_SEEK_ERROR, 308 | /** 309 | * File read error 310 | */ 311 | FILE_READ_ERROR, 312 | /** 313 | * Bad magic number 314 | */ 315 | BAD_MAGIC_NUMBER, 316 | /** 317 | * Empty database 318 | */ 319 | EMPTY_DATABASE, 320 | /** 321 | * Can't be reader 322 | */ 323 | CANT_BE_READER, 324 | /** 325 | * Can't be writer 326 | */ 327 | CANT_BE_WRITER, 328 | /** 329 | * Reader can't delete 330 | */ 331 | READER_CANT_DELETE, 332 | /** 333 | * Reader can't store 334 | */ 335 | READER_CANT_STORE, 336 | /** 337 | * Reader can't reorganize 338 | */ 339 | READER_CANT_REORGANIZE, 340 | /** 341 | * Unknown update 342 | */ 343 | UNKNOWN_UPDATE, 344 | /** 345 | * Item not found 346 | */ 347 | ITEM_NOT_FOUND, 348 | /** 349 | * Reorganize failed 350 | */ 351 | REORGANIZE_FAILED, 352 | /** 353 | * Cannot replace 354 | */ 355 | CANNOT_REPLACE, 356 | /** 357 | * Illegal data 358 | */ 359 | ILLEGAL_DATA, 360 | /** 361 | * Option already set 362 | */ 363 | OPT_ALREADY_SET, 364 | /** 365 | * Illegal option 366 | */ 367 | OPT_ILLEGAL; 368 | [CCode (cname = "gdbm_strerror")] 369 | public unowned string to_string (); 370 | } 371 | 372 | /** 373 | * Error code of the last database operation. 374 | */ 375 | [CCode (cname = "gdbm_errno")] 376 | public static Error errno; 377 | } 378 | -------------------------------------------------------------------------------- /glibusb.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "glibusb.h" 5 | 6 | typedef struct { 7 | GSource source; 8 | libusb_context *ctx; 9 | GSList *pollfds; 10 | } GUSBSource; 11 | 12 | static void add_fd(int fd, short events, void *user_data) { 13 | GPollFD *pollfd = g_slice_new(GPollFD); 14 | g_message("now monitoring fd %d", fd); 15 | pollfd->fd = fd; 16 | pollfd->events = 0; 17 | pollfd->revents = 0; 18 | if (events & POLLIN) 19 | pollfd->events |= G_IO_IN; 20 | if (events & POLLOUT) 21 | pollfd->events |= G_IO_OUT; 22 | 23 | ((GUSBSource*)user_data)->pollfds = g_slist_prepend(((GUSBSource*)user_data)->pollfds, pollfd); 24 | g_source_add_poll((GSource *) user_data, pollfd); 25 | } 26 | 27 | static void remove_fd(int fd, void *user_data) { 28 | GSList *elem = ((GUSBSource*)user_data)->pollfds; 29 | g_message("no longer monitoring fd %d", fd); 30 | 31 | if (!elem) { 32 | g_warning("cannot remove from list as list is empty?"); 33 | return; 34 | } 35 | 36 | do { 37 | GPollFD *pollfd = elem->data; 38 | if (pollfd->fd != fd) 39 | continue; 40 | 41 | g_source_remove_poll((GSource *) user_data, pollfd); 42 | g_slice_free(GPollFD, pollfd); 43 | ((GUSBSource*)user_data)->pollfds = g_slist_delete_link(((GUSBSource*)user_data)->pollfds, elem); 44 | return; 45 | } while ((elem = g_slist_next(elem))); 46 | 47 | g_error("couldn't find fd %d in list\n", fd); 48 | } 49 | 50 | static gboolean source_prepare(GSource *source, gint *timeout) { 51 | int r; 52 | struct timeval tv; 53 | 54 | r = libusb_get_next_timeout(((GUSBSource*)source)->ctx, &tv); 55 | if (r == 0) { 56 | *timeout = -1; 57 | return FALSE; 58 | } 59 | 60 | if (!timerisset(&tv)) 61 | return TRUE; 62 | 63 | *timeout = (tv.tv_sec * 1000) + (tv.tv_usec / 1000); 64 | return FALSE; 65 | } 66 | 67 | static gboolean source_check(GSource *source) { 68 | GUSBSource *src = (GUSBSource*) source; 69 | GSList *elem = src->pollfds; 70 | struct timeval tv; 71 | int r; 72 | 73 | if (!elem) 74 | return FALSE; 75 | 76 | do { 77 | GPollFD *pollfd = elem->data; 78 | if (pollfd->revents) 79 | return TRUE; 80 | } while ((elem = g_slist_next(elem))); 81 | 82 | r = libusb_get_next_timeout(src->ctx, &tv); 83 | if (r == 1 && !timerisset(&tv)) 84 | return TRUE; 85 | 86 | return FALSE; 87 | } 88 | 89 | static gboolean source_dispatch(GSource *source, GSourceFunc callback, gpointer data) 90 | { 91 | struct timeval zerotimeout = { 92 | .tv_sec = 0, 93 | .tv_usec = 0, 94 | }; 95 | 96 | libusb_handle_events_timeout(((GUSBSource*)source)->ctx, &zerotimeout); 97 | 98 | /* FIXME whats the return value used for? */ 99 | return TRUE; 100 | } 101 | 102 | static void source_finalize(GSource *source) 103 | { 104 | GUSBSource *src = (GUSBSource*) source; 105 | GSList *elem = src->pollfds; 106 | 107 | if (elem) { 108 | do { 109 | GPollFD *pollfd = elem->data; 110 | g_source_remove_poll(source, pollfd); 111 | g_slice_free(GPollFD, pollfd); 112 | src->pollfds = g_slist_delete_link(src->pollfds, elem); 113 | } while ((elem = g_slist_next(elem))); 114 | } 115 | 116 | g_slist_free(src->pollfds); 117 | libusb_exit(src->ctx); 118 | } 119 | 120 | static GSourceFuncs sourcefuncs = { 121 | .prepare = source_prepare, 122 | .check = source_check, 123 | .dispatch = source_dispatch, 124 | .finalize = source_finalize, 125 | }; 126 | 127 | GSource *glibusb_create_gsource(libusb_context *ctx) { 128 | int it; 129 | const struct libusb_pollfd **fds; 130 | GUSBSource *gsource = (GUSBSource*) g_source_new(&sourcefuncs, sizeof(GUSBSource)); 131 | 132 | gsource->ctx = ctx; 133 | gsource->pollfds = NULL; 134 | fds = libusb_get_pollfds(ctx); 135 | if (fds != NULL) { 136 | for(it = 0; fds[it] != NULL; it++) { 137 | add_fd(fds[it]->fd, fds[it]->events, gsource); 138 | } 139 | free(fds); 140 | } 141 | libusb_set_pollfd_notifiers(ctx, add_fd, remove_fd, gsource); 142 | return (GSource*) gsource; 143 | } 144 | 145 | static void callback_func(struct libusb_transfer *transfer) { 146 | g_simple_async_result_complete((GSimpleAsyncResult*)transfer->user_data); 147 | g_object_unref((GSimpleAsyncResult*)transfer->user_data); 148 | } 149 | 150 | static void start_xfer(struct libusb_transfer *xfer) { 151 | GSimpleAsyncResult *async = (GSimpleAsyncResult*)xfer->user_data; 152 | g_simple_async_result_set_op_res_gpointer(async, xfer, (GDestroyNotify)libusb_free_transfer); 153 | if(libusb_submit_transfer(xfer) != 0) { 154 | g_simple_async_result_complete_in_idle(async); 155 | g_object_unref((GObject*)async); 156 | } 157 | } 158 | 159 | #define ASYNC_BLOCK(name) \ 160 | void glibusb_##name##_transfer(libusb_device_handle *dev, ASYNC_PARAMS unsigned int timeout, unsigned char *buffer, int buffer_length, GAsyncReadyCallback callback, gpointer user_data) { \ 161 | struct libusb_transfer *xfer = libusb_alloc_transfer(0); \ 162 | GSimpleAsyncResult *async = g_simple_async_result_new(NULL, callback, user_data, glibusb_##name##_transfer); \ 163 | libusb_fill_##name##_transfer(xfer, dev, ASYNC_ARGS callback_func, async, timeout); \ 164 | start_xfer(xfer);\ 165 | }\ 166 | enum libusb_transfer_status glibusb_##name##_transfer_finish(GAsyncResult *result, int *actual_length) { \ 167 | struct libusb_transfer *xfer = (struct libusb_transfer*) g_simple_async_result_get_op_res_gpointer(G_SIMPLE_ASYNC_RESULT(result)); \ 168 | enum libusb_transfer_status status = xfer->status; \ 169 | if (actual_length) *actual_length = xfer->actual_length; \ 170 | libusb_free_transfer(xfer); \ 171 | return status; \ 172 | } 173 | 174 | #define ASYNC_ARGS buffer, 175 | #define ASYNC_PARAMS 176 | ASYNC_BLOCK(control) 177 | #undef ASYNC_ARGS 178 | #undef ASYNC_PARAMS 179 | #define ASYNC_ARGS endpoint, buffer, buffer_length, 180 | #define ASYNC_PARAMS unsigned char endpoint, 181 | ASYNC_BLOCK(interrupt) 182 | ASYNC_BLOCK(bulk) 183 | -------------------------------------------------------------------------------- /glibusb.deps: -------------------------------------------------------------------------------- 1 | gio-2.0 2 | libusb-1.0 3 | -------------------------------------------------------------------------------- /glibusb.h: -------------------------------------------------------------------------------- 1 | #ifndef GLIB_USB_H 2 | #define GLIB_USB_H 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | GSource *glibusb_create_gsource(libusb_context *ctx); 10 | 11 | void glibusb_control_transfer(libusb_device_handle *dev, unsigned int timeout, unsigned char *buffer, int buffer_length, GAsyncReadyCallback callback, gpointer user_data); 12 | enum libusb_transfer_status glibusb_control_transfer_finish(GAsyncResult *result, int *actual_length); 13 | 14 | void glibusb_interrupt_transfer(libusb_device_handle *dev, unsigned char endpoint, unsigned int timeout, unsigned char *buffer, int buffer_length, GAsyncReadyCallback callback, gpointer user_data); 15 | enum libusb_transfer_status glibusb_interrupt_transfer_finish(GAsyncResult *result, int *actual_length); 16 | 17 | void glibusb_bulk_transfer(libusb_device_handle *dev, unsigned char endpoint, unsigned int timeout, unsigned char *buffer, int buffer_length, GAsyncReadyCallback callback, gpointer user_data); 18 | enum libusb_transfer_status glibusb_bulk_transfer_finish(GAsyncResult *result, int *actual_length); 19 | #endif 20 | -------------------------------------------------------------------------------- /glibusb.vapi: -------------------------------------------------------------------------------- 1 | [CCode (cheader_filename = "glibusb.h")] 2 | namespace LibUSB { 3 | /** 4 | * Create a source so that a context can be monitored using {@link GLib.MainLoop}. 5 | * 6 | * Once created, call {@link GLib.Source.attach} to attach it to a context. 7 | */ 8 | [CCode (cname = "glibusb_create_gsource")] 9 | public GLib.Source create_source (owned Context ctx); 10 | 11 | /** 12 | * Initiate a USB control transfer on a device. 13 | * 14 | * @param dev the device to perform the transfer 15 | * @param timeout return if no data has been provided after the specified number of milliseconds 16 | * @param buffer the data to transfer 17 | * @param actual_length the number of bytes transferred 18 | */ 19 | [CCode (cname = "glibusb_control_transfer")] 20 | public async TransferStatus control_transfer (DeviceHandle dev, uint timeout, uint8[] buffer, out int actual_length); 21 | 22 | /** 23 | * Initiate a USB interrupt transfer on a device. 24 | * 25 | * @param dev the device to perform the transfer 26 | * @param endpoint the target on the device 27 | * @param timeout return if no data has been provided after the specified number of milliseconds 28 | * @param buffer the data to transfer 29 | * @param actual_length the number of bytes transferred 30 | */ 31 | [CCode (cname = "glibusb_interrupt_transfer")] 32 | public async TransferStatus interrupt_transfer (DeviceHandle dev, uint8 endpoint, uint timeout, uint8[] buffer, out int actual_length); 33 | 34 | /** 35 | * Initiate a USB bulk transfer on a device. 36 | * 37 | * @param dev the device to perform the transfer 38 | * @param endpoint the target on the device 39 | * @param timeout return if no data has been provided after the specified number of milliseconds 40 | * @param buffer the data to transfer 41 | * @param actual_length the number of bytes transferred 42 | */ 43 | [CCode (cname = "glibusb_bulk_transfer")] 44 | public async TransferStatus bulk_transfer (DeviceHandle dev, uint8 endpoint, uint timeout, uint8[] buffer, out int actual_length); 45 | } 46 | -------------------------------------------------------------------------------- /hidapi.vapi: -------------------------------------------------------------------------------- 1 | /** 2 | * Multi-Platform library for communication with HID devices. 3 | */ 4 | [CCode (cheader_filename = "hidapi.h")] 5 | namespace HidApi { 6 | [CCode (cname = "hid_device", free_function = "hid_close")] 7 | [Compact] 8 | public class Device { 9 | 10 | /** 11 | * Open a HID device using a Vendor ID (VID), Product ID (PID) and optionally a serial number. 12 | * 13 | * @param vendor_id The Vendor ID (VID) of the device to open. 14 | * @param product_id The Product ID (PID) of the device to open. 15 | * @param serial_number The Serial Number of the device to open. If null, 16 | * the first device with the specified VID and PID is opened. 17 | */ 18 | [CCode (cname = "hid_open")] 19 | public static Device? open (ushort vendor_id, ushort product_id, void* serial_number = null); 20 | 21 | /** 22 | * Open a HID device by its path name. 23 | * 24 | * The path name be determined by calling {@link Info.enumerate}, or a platform-specific path name can be used (e.g., '''/dev/hidraw0''' on Linux). 25 | */ 26 | [CCode (cname = "hid_open_path")] 27 | public static Device? open_path (string path); 28 | 29 | /** 30 | * Get a feature report from a HID device. 31 | * 32 | * Make sure to set the first byte of the data to the Report ID of the 33 | * report to be read. Make sure to allow space for this extra byte. 34 | * 35 | * @param data A buffer to put the read data into, including the Report ID. 36 | * Set the first byte of the data[] to the Report ID of the report to be 37 | * read. The buffer can be longer than the actual report. 38 | * 39 | * @return This function returns the number of bytes read and -1 on error. 40 | */ 41 | [CCode (cname = "hid_get_feature_report")] 42 | public int get_feature_report ([CCode (array_length_type = "size_t")] uint8[] data); 43 | 44 | /** 45 | * Read an Input report from a HID device. 46 | * 47 | * Input reports are returned to the host through the INTERRUPT IN 48 | * endpoint. The first byte will contain the Report number if the device 49 | * uses numbered reports. 50 | * 51 | * @param data A buffer to put the read data into. For devices with 52 | * multiple reports, make sure to read an extra byte for the report 53 | * number. 54 | * 55 | * @return This function returns the actual number of bytes read and -1 56 | * on error. 57 | */ 58 | [CCode (cname = "hid_read")] 59 | public int read ([CCode (array_length_type = "size_t")] uint8[] data); 60 | 61 | /** 62 | * Read an Input report from a HID device with timeout. 63 | * 64 | * Input reports are returned to the host through the INTERRUPT IN 65 | * endpoint. The first byte will contain the Report number if the device 66 | * uses numbered reports. 67 | * 68 | * @param data A buffer to put the read data into. For devices with 69 | * multiple reports, make sure to read an extra byte for the report 70 | * number. 71 | * 72 | * @param milliseconds timeout in milliseconds or -1 for blocking wait. 73 | * 74 | * @return This function returns the actual number of bytes read and -1 75 | * on error. 76 | */ 77 | [CCode (cname = "hid_read_timeout")] 78 | public int read_timeout ([CCode (array_length_type = "size_t")] uint8[] data, int milliseconds); 79 | 80 | /** 81 | * Send a Feature report to the device. 82 | * 83 | * Feature reports are sent over the Control endpoint as a Set_Report 84 | * transfer. The first byte of the data must contain the Report ID. For 85 | * devices which only support a single report, this must be set to 0x0. The 86 | * remaining bytes contain the report data. Since the Report ID is 87 | * mandatory, calls will always contain one more byte than the report 88 | * contains. For example, if a HID report is 16 bytes long, 17 bytes must 89 | * be passed: the Report ID (or 0x0, for devices which do not use numbered 90 | * reports), followed by the report data (16 bytes). In this example, the 91 | * length passed in would be 17. 92 | * 93 | * @param data The data to send, including the report number as the first byte. 94 | * 95 | * @return This function returns the actual number of bytes written and -1 on error. 96 | */ 97 | [CCode (cname = "hid_send_feature_report")] 98 | public int send_feature_report ([CCode (array_length_type = "size_t")] uint8[] data); 99 | 100 | /** 101 | * Set the device handle to be non-blocking. 102 | * 103 | * In non-blocking mode calls to {@link read} will return immediately with 104 | * a value of 0 if there is no data to be read. In blocking mode, 105 | * {@link read} will wait (block) until there is data to read before 106 | * returning. 107 | * 108 | * Nonblocking can be turned on and off at any time. 109 | */ 110 | [CCode (cname = "!hid_set_nonblocking")] 111 | public bool set_nonblocking (bool nonblock); 112 | 113 | /** 114 | * Write an Output report to a HID device. 115 | * 116 | * The first byte of data must contain the Report ID. For devices which 117 | * only support a single report, this must be set to 0x0. The remaining 118 | * bytes contain the report data. Since the Report ID is mandatory, calls 119 | * will always contain one more byte than the report contains. For 120 | * example, if a HID report is 16 bytes long, 17 bytes must be passed, 121 | * the Report ID (or 0x0, for devices with a single report), followed by 122 | * the report data (16 bytes). In this example, the length passed in 123 | * would be 17. 124 | * 125 | * The data will be sent on the first OUT endpoint, if one exists. If it 126 | * does not, it will send the data through the Control Endpoint (Endpoint 127 | * 0). 128 | * 129 | * @return This function returns the actual number of bytes written and 130 | * -1 on error. 131 | */ 132 | [CCode (cname = "hid_write")] 133 | public int write ([CCode (array_length_type = "size_t")] uint8[] data); 134 | 135 | /** 136 | * A string describing the last error which occurred. 137 | */ 138 | public string? error { 139 | owned get { 140 | unowned wchar_t[]? str = get_error (); 141 | if (str == null) { 142 | return null; 143 | } 144 | uint8[] unistr = new uint8[wcstombs (null, str, 0) + 1]; 145 | wcstombs (unistr, str, unistr.length); 146 | return ((string) unistr).dup (); 147 | } 148 | } 149 | [CCode (cname = "hid_error", array_length = false)] 150 | private unowned wchar_t[]? get_error (); 151 | 152 | public string? manufacturer { 153 | owned get { 154 | wchar_t str[127]; 155 | if (get_manufacturer_string (str)) { 156 | uint8[] unistr = new uint8[wcstombs (null, str, 0) + 1]; 157 | wcstombs (unistr, str, unistr.length); 158 | return ((string) unistr).dup (); 159 | } 160 | return null; 161 | } 162 | } 163 | [CCode (cname = "!hid_get_manufacturer_string")] 164 | private bool get_manufacturer_string ([CCode (array_length_type = "size_t")] wchar_t[] str); 165 | 166 | public string? product { 167 | owned get { 168 | wchar_t str[127]; 169 | if (get_product_string (str)) { 170 | uint8[] unistr = new uint8[wcstombs (null, str, 0) + 1]; 171 | wcstombs (unistr, str, unistr.length); 172 | return ((string) unistr).dup (); 173 | } 174 | return null; 175 | } 176 | } 177 | [CCode (cname = "!hid_get_product_string")] 178 | private bool get_product_string ([CCode (array_length_type = "size_t")] wchar_t[] str); 179 | 180 | public string? serial_number { 181 | owned get { 182 | wchar_t str[127]; 183 | if (get_serial_number_string (str)) { 184 | uint8[] unistr = new uint8[wcstombs (null, str, 0) + 1]; 185 | wcstombs (unistr, str, unistr.length); 186 | return ((string) unistr).dup (); 187 | } 188 | return null; 189 | } 190 | } 191 | [CCode (cname = "!hid_get_serial_number_string")] 192 | private bool get_serial_number_string ([CCode (array_length_type = "size_t")] wchar_t[] str); 193 | 194 | /** 195 | * Get a string from a HID device, based on its string index. 196 | */ 197 | public string? get (int index) { 198 | wchar_t str[127]; 199 | if (get_indexed_string (index, str)) { 200 | uint8[] unistr = new uint8[wcstombs (null, str, 0) + 1]; 201 | wcstombs (unistr, str, unistr.length); 202 | return ((string) unistr).dup (); 203 | } 204 | return null; 205 | } 206 | [CCode (cname = "!hid_get_indexed_string")] 207 | private bool get_indexed_string (int index, [CCode (array_length_type = "size_t")] wchar_t[] str); 208 | } 209 | 210 | [CCode (cname = "struct hid_device_info", free_function = "hid_free_enumeration")] 211 | [Compact] 212 | public class Info { 213 | /** 214 | * Platform-specific device path 215 | */ 216 | public string? path; 217 | /** 218 | * Device vendor ID 219 | */ 220 | public ushort vendor_id; 221 | /** 222 | * Device product ID 223 | */ 224 | public ushort product_id; 225 | /** 226 | * Serial number 227 | */ 228 | public void* serial_number; 229 | public string? serial_number_str { 230 | owned get { 231 | if (serial_number == null) { 232 | return null; 233 | } 234 | uint8[] unistr = new uint8[wcstombs (null, (wchar_t[])serial_number, 0) + 1]; 235 | wcstombs (unistr, (wchar_t[])serial_number, unistr.length); 236 | return ((string) unistr).dup (); 237 | } 238 | } /** 239 | * Device release number in binary-coded decimal 240 | * 241 | * Also known as device version number. 242 | */ 243 | public ushort release_number; 244 | /** 245 | * Manufacturer name 246 | */ 247 | public string? manufacturer { 248 | owned get { 249 | if (manufacturer_string == null) { 250 | return null; 251 | } 252 | uint8[] unistr = new uint8[wcstombs (null, manufacturer_string, 0) + 1]; 253 | wcstombs (unistr, manufacturer_string, unistr.length); 254 | return ((string) unistr).dup (); 255 | } 256 | } 257 | [CCode (array_length = false)] 258 | private wchar_t[]? manufacturer_string; 259 | /** 260 | * Product name 261 | */ 262 | public string? product { 263 | owned get { 264 | if (product_string == null) { 265 | return null; 266 | } 267 | uint8[] unistr = new uint8[wcstombs (null, product_string, 0) + 1]; 268 | wcstombs (unistr, product_string, unistr.length); 269 | return ((string) unistr).dup (); 270 | } 271 | } 272 | [CCode (array_length = false)] 273 | private wchar_t[] product_string; 274 | /** 275 | * Usage page for this device/interface (Windows/Mac only). 276 | */ 277 | public ushort usage_page; 278 | /** 279 | * Usage for this device/interface (Windows/Mac only). 280 | */ 281 | public ushort usage; 282 | /** 283 | * The USB interface which this logical device represents. 284 | * 285 | * Valid on both Linux implementations in all cases, and valid on the 286 | * Windows implementation only if the device contains more than one 287 | * interface. 288 | */ 289 | public int interface_number; 290 | 291 | public Info? next; 292 | /** 293 | * Enumerate the HID Devices. 294 | * 295 | * This function returns a linked list of all the HID devices attached to the system which match the provided vendor and product IDs. 296 | * 297 | * @param vendor_id the vendor ID, or 0 to match any vendor. 298 | * @param product_id the product ID, or 0 to match any product. 299 | */ 300 | [CCode (cname = "hid_enumerate")] 301 | public static Info? enumerate (ushort vendor_id = 0, ushort product_id = 0); 302 | 303 | /** 304 | * Open the corresponding HID device. 305 | */ 306 | public Device? open () { 307 | return Device.open (this.vendor_id, this.product_id, this.serial_number); 308 | } 309 | } 310 | 311 | /** 312 | * Initialize the HIDAPI library. 313 | * 314 | * This function initializes the HIDAPI library. Calling it is not strictly 315 | * necessary, as it will be called automatically by {@link Info.enumerate} 316 | * and either {@link Device.open} or {@link Device.open_path} functions if it 317 | * is needed. This function should be called at the beginning of execution 318 | * however, if there is a chance of HIDAPI handles being opened by different 319 | * threads simultaneously. 320 | * 321 | * @return This function returns true on success and false on error. 322 | */ 323 | [CCode (cname = "!hid_init")] 324 | public bool init (); 325 | 326 | /** 327 | * Finalize the HIDAPI library. 328 | * 329 | * This function frees all of the static data associated with HIDAPI. It 330 | * should be called at the end of execution to avoid memory leaks. 331 | * 332 | * @return This function returns true on success and false on error. 333 | */ 334 | [CCode (cname = "!hid_exit")] 335 | public bool exit (); 336 | 337 | [CCode (cname = "wcstombs", cheader_filename = "stdlib.h")] 338 | private size_t wcstombs ([CCode (array_length = false)] uint8[]? dest, [CCode (array_length = false)] wchar_t[] src, size_t n); 339 | 340 | [CCode (cname = "wchar_t")] 341 | [SimpleType] 342 | private struct wchar_t {} 343 | } 344 | -------------------------------------------------------------------------------- /introspection.vala: -------------------------------------------------------------------------------- 1 | public void type_info() { 2 | var type = typeof(T); 3 | TypeQuery query; 4 | type.query(out query); 5 | stdout.printf("%s %c%c%c%C%C%C%C%C%C%C%C size(class = %u instance = %u)\n", type.name(), 6 | type.is_object() ? 'o' : '-', 7 | type.is_abstract() ? 'a' : '-', 8 | type.is_classed() ? 'c' : '-', 9 | type.is_derivable() ? (type.is_deep_derivable() ? 'D' : 'd') : '-', 10 | type.is_derived() ? 'v' : '-', 11 | type.is_fundamental() ? 'F' : '-', 12 | type.is_instantiatable() ? 'N' : '-', 13 | type.is_interface() ? 'i' : '-', 14 | type.is_value_type() ? 's' : '-', 15 | type.is_enum() ? 'e' : '-', 16 | type.is_flags() ? 'f' : '-', 17 | query.class_size, 18 | query.instance_size); 19 | 20 | if (type.is_object()) { 21 | stdout.printf("class %s", type.name()); 22 | for(var parent = type.parent(); parent != Type.INVALID; parent = parent.parent()) { 23 | stdout.printf(" : %s", parent.name()); 24 | } 25 | stdout.printf(" {\n"); 26 | foreach (var property in ((ObjectClass)type.class_ref()).list_properties()) { 27 | stdout.printf("\t%s :: %s -- %s\n", property.name, property.value_type.name(), property.get_blurb()); 28 | } 29 | stdout.printf("}\n"); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /jump.vapi: -------------------------------------------------------------------------------- 1 | namespace Posix { 2 | [CCode (cname = "jmp_buf", cheader_filename = "setjmp.h", has_type_id = false)] 3 | [SimpleType] 4 | public struct jump { 5 | [CCode (cname = "setjmp")] 6 | public int set (); 7 | [CCode (cname = "longjmp")] 8 | [NoReturn] 9 | public void return int val; 10 | } 11 | 12 | [CCode (cname = "sigjmp_buf", cheader_filename = "setjmp.h", has_type_id = false)] 13 | [SimpleType] 14 | public struct sig_jump { 15 | [CCode (cname = "sigsetjmp")] 16 | public int set (bool save_mask); 17 | [CCode (cname = "siglongjmp")] 18 | [NoReturn] 19 | public void return int val; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /libcap.deps: -------------------------------------------------------------------------------- 1 | posix 2 | -------------------------------------------------------------------------------- /libcap.vapi: -------------------------------------------------------------------------------- 1 | [CCode (cheader_filename = "sys/capability.h")] 2 | /** 3 | * Defunct POSIX.1e Standard: 25.2 Capabilities 4 | */ 5 | namespace Posix { 6 | /** 7 | * Capability handle 8 | */ 9 | [CCode (cname = "struct _cap_struct", free_function = "cap_free")] 10 | [Compact] 11 | public class Capability { 12 | [CCode (cname = "cap_flag_t", cprefix = "CAP_")] 13 | public enum Flag { 14 | EFFECTIVE, 15 | PERMITTED, 16 | INHERITABLE; 17 | /** 18 | * Evaluates if the returned status from {@link compare} differs in this flag component. 19 | */ 20 | [CCode (cname = "CAP_DIFFERS", instance_pos = -1)] 21 | public bool differs (int result); 22 | } 23 | [CCode (cname = "cap_value_t", cprefix = "CAP_")] 24 | public enum Value { 25 | /** 26 | * This overrides the restriction of changing file ownership and group ownership. 27 | */ 28 | CHOWN, 29 | /** 30 | * Override all DAC access, including ACL execute access. Excluding DAC access covered by {@link LINUX_IMMUTABLE}. 31 | */ 32 | DAC_OVERRIDE, 33 | /** 34 | * Overrides all DAC restrictions regarding read and search on files and directories, including ACL restrictions. Excluding DAC access covered by {@link LINUX_IMMUTABLE}. 35 | */ 36 | DAC_READ_SEARCH, 37 | /** 38 | * Overrides all restrictions about allowed operations on files, where file owner ID must be equal to the user ID, except where {@link FSETID} is applicable. It doesn't override MAC and DAC restrictions. 39 | */ 40 | FOWNER, 41 | /** 42 | * Overrides the following restrictions that the effective user ID shall match the file owner ID when setting the S_ISUID and S_ISGID bits on that file; that the effective group ID (or one of the supplementary group IDs) shall match the file owner ID when setting the S_ISGID bit on that file; that the S_ISUID and S_ISGID bits are cleared on successful return from chown(2) (not implemented). 43 | */ 44 | FSETID, 45 | /** 46 | * Overrides the restriction that the real or effective user ID of a process sending a signal must match the real or effective user ID of the process receiving the signal. 47 | */ 48 | KILL, 49 | /** 50 | * Allows setgid(2) manipulation, setgroups(2), and forged gids on socket credentials passing. 51 | */ 52 | SETGID, 53 | /** 54 | * Allows set*uid(2) manipulation (including fsuid) and forged pids on socket credentials passing. 55 | */ 56 | SETUID, 57 | /** 58 | * Without VFS support for capabilities: 59 | * Transfer any capability in your permitted set to any pid, 60 | * remove any capability in your permitted set from any pid. 61 | * With VFS support for capabilities (neither of above, but) 62 | * Add any capability from current's capability bounding set 63 | * to the current process' inheritable set, 64 | * Allow taking bits out of capability bounding set, 65 | * Allow modification of the securebits for a process. 66 | */ 67 | SETPCAP, 68 | /** 69 | * Allow modification of S_IMMUTABLE and S_APPEND file attributes. 70 | */ 71 | LINUX_IMMUTABLE, 72 | /** 73 | * Allows binding to TCP/UDP sockets below 1024 and binding to ATM VCIs below 32. 74 | */ 75 | NET_BIND_SERVICE, 76 | /** 77 | * Allow broadcasting, listen to multicast. 78 | */ 79 | NET_BROADCAST, 80 | /** 81 | * Allow interface configuration. 82 | * Allow administration of IP firewall, masquerading and accounting. 83 | * Allow setting debug option on sockets. 84 | * Allow modification of routing tables. 85 | * Allow setting arbitrary process / process group ownership on sockets. 86 | * Allow binding to any address for transparent proxying (also via NET_RAW). 87 | * Allow setting TOS (type of service). 88 | * Allow setting promiscuous mode. 89 | * Allow clearing driver statistics. 90 | * Allow multicasting. 91 | * Allow read/write of device-specific registers. 92 | * Allow activation of ATM control sockets. 93 | */ 94 | NET_ADMIN, 95 | /** 96 | * Allow use of RAW sockets. 97 | * Allow use of PACKET sockets. 98 | * Allow binding to any address for transparent proxying (also via {@link NET_ADMIN}). 99 | */ 100 | NET_RAW, 101 | /** 102 | * Allow locking of shared memory segments and mlock and mlockall (which doesn't really have anything to do with IPC). 103 | */ 104 | IPC_LOCK, 105 | /** 106 | * Override IPC ownership checks 107 | */ 108 | IPC_OWNER, 109 | /** 110 | * Insert and remove kernel modules - modify kernel without limit 111 | */ 112 | SYS_MODULE, 113 | /** 114 | * Allow ioperm/iopl access and sending USB messages to any device via /proc/bus/usb 115 | */ 116 | SYS_RAWIO, 117 | /** 118 | * Allow use of chroot() 119 | */ 120 | SYS_CHROOT, 121 | /** 122 | * Allow ptrace() of any process 123 | */ 124 | SYS_PTRACE, 125 | /** 126 | * Allow configuration of process accounting 127 | */ 128 | SYS_PACCT, 129 | /** 130 | * Allow configuration of the secure attention key. 131 | * Allow administration of the random device. 132 | * Allow examination and configuration of disk quotas. 133 | * Allow setting the domainname. 134 | * Allow setting the hostname. 135 | * Allow calling bdflush(). 136 | * Allow mount() and umount(), setting up new smb connection. 137 | * Allow some autofs root ioctls. 138 | * Allow nfsservctl. 139 | * Allow VM86_REQUEST_IRQ. 140 | * Allow to read/write pci config on alpha. 141 | * Allow irix_prctl on mips (setstacksize). 142 | * Allow flushing all cache on m68k (sys_cacheflush). 143 | * Allow removing semaphores. 144 | * Used instead of {@link Value.CHOWN} to "chown" IPC message queues, semaphores and shared memory. 145 | * Allow locking/unlocking of shared memory segment. 146 | * Allow turning swap on/off. 147 | * Allow forged pids on socket credentials passing. 148 | * Allow setting readahead and flushing buffers on block devices. 149 | * Allow setting geometry in floppy driver. 150 | * Allow turning DMA on/off in xd driver. 151 | * Allow administration of md devices (mostly the above, but some 152 | extra ioctls). 153 | * Allow tuning the ide driver. 154 | * Allow access to the nvram device. 155 | * Allow administration of apm_bios, serial and bttv (TV) device. 156 | * Allow manufacturer commands in isdn CAPI support driver. 157 | * Allow reading non-standardized portions of pci configuration space. 158 | * Allow DDI debug ioctl on sbpcd driver. 159 | * Allow setting up serial ports. 160 | * Allow sending raw qic-117 commands. 161 | * Allow enabling/disabling tagged queuing on SCSI controllers and sending 162 | arbitrary SCSI commands. 163 | * Allow setting encryption key on loopback filesystem. 164 | * Allow setting zone reclaim policy. 165 | */ 166 | SYS_ADMIN, 167 | /** 168 | * Allow use of reboot() 169 | */ 170 | SYS_BOOT, 171 | /** 172 | * Allow raising priority and setting priority on other (different UID) processes, 173 | * the use of FIFO and round-robin (realtime) scheduling on own processes and setting the scheduling algorithm used by another process and setting cpu affinity on other processes. 174 | */ 175 | SYS_NICE, 176 | 177 | /** 178 | * Override resource limits. Set resource limits. 179 | * 180 | * Override quota limits. 181 | * Override reserved space on ext2 filesystem. 182 | * Modify data journaling mode on ext3 filesystem (uses journaling resources). 183 | * NOTE: ext2 honors fsuid when checking for resource overrides, so you can override using fsuid too. 184 | * Override size restrictions on IPC message queues. 185 | * Allow more than 64hz interrupts from the real-time clock. 186 | * Override max number of consoles on console allocation. 187 | * Override max number of keymaps. 188 | */ 189 | SYS_RESOURCE, 190 | /** 191 | * Allow manipulation of system clock, irix_stime on mips, and the real-time clock 192 | */ 193 | SYS_TIME, 194 | /** 195 | * Allow configuration of tty devices and vhangup() of tty 196 | */ 197 | SYS_TTY_CONFIG, 198 | /** 199 | * Allow the privileged aspects of mknod() 200 | */ 201 | MKNOD, 202 | 203 | /** 204 | * Allow taking of leases on files 205 | */ 206 | LEASE, 207 | AUDIT_WRITE, 208 | AUDIT_CONTROL, 209 | SETFCAP, 210 | /** 211 | * Override MAC access. 212 | * 213 | * The base kernel enforces no MAC policy. An LSM may enforce a MAC policy, and if it does and it chooses to implement capability based overrides of that policy, this is the capability it should use to do so. 214 | */ 215 | MAC_OVERRIDE, 216 | /** 217 | * Allow MAC configuration or state changes. 218 | * 219 | * The base kernel requires no MAC configuration. An LSM may enforce a MAC policy, and if it does and it chooses to implement capability based checks on modifications to that policy or the data required to maintain it, this is the capability it should use to do so. 220 | */ 221 | MAC_ADMIN, 222 | /** 223 | * Allow configuring the kernel's syslog (printk behaviour) 224 | */ 225 | SYSLOG, 226 | /** 227 | * Allow triggering something that will wake the system 228 | */ 229 | WAKE_ALARM; 230 | /** 231 | * Converts a text representation of a capability, such as "cap_chown". 232 | * @return whether or not the specified capability can be represented by the library. 233 | */ 234 | [CCode (cname = "0 == cap_from_name")] 235 | public static bool from_name (string name, out Value @value); 236 | /** 237 | * Can be used to lower the specified bounding set capability. 238 | * 239 | * To complete successfully, the prevailing effective capability set must have a raised {@link Value.SETPCAP}. 240 | */ 241 | [CCode (cname = "0 == cap_drop_bound")] 242 | public bool drop_bound (); 243 | /** 244 | * Gets the current value of this bounding set capability flag in effect for the current process. 245 | * 246 | * This operation is unprivileged. 247 | * @return -1 if the requested capability is unknown, otherwise the return value reflects the current state of that capability in the prevailing bounding set. 248 | * @see is_supported 249 | */ 250 | [CCode (cname = "cap_get_bound")] 251 | public int get_bound (); 252 | [CCode (cname = "CAP_IS_SUPPORTED")] 253 | public bool is_supported (); 254 | [CCode (cname = "cap_to_name")] 255 | public string to_string (); 256 | } 257 | /** 258 | * The total length (in bytes) that the capability state in working storage would require when converted by {@link copy}. 259 | * 260 | * This is used primarily to determine the amount of buffer space that must be provided to the {@link copy} function in order to hold the capability data record created. 261 | */ 262 | public ssize_t size { 263 | [CCode (cname = "cap_size")] 264 | get; 265 | } 266 | /** 267 | * Copies a capability state from a capability data record in user-managed space to a new capability state in working storage, allocating any memory necessary, and returning a pointer to the newly created capability state. 268 | * 269 | * The function initializes the capability state and then copies the capability state from the record passed into the capability state, converting, if necessary, the data from a contiguous, persistent format to an undefined, internal format. Once copied into internal format, the object can be manipulated by the capability state manipulation functions. Note that the record must have been obtained from a previous, successful call to {@link copy} for this function to work successfully. 270 | */ 271 | [CCode (cname = "cap_copy_int")] 272 | public static Capability? create ([CCode (array_length = false)] uint8[] buffer); 273 | /** 274 | * Allocates and initializes a capability state in working storage. It then sets the contents of this newly created capability state to the state represented by a human-readable character string. It returns a pointer to the newly created capability state. 275 | * 276 | * @return an null if it cannot parse the contents of the string or does not recognize any '''capability_name''' or flag character as valid. Also returns null if any flag is both set and cleared within a single clause. 277 | */ 278 | [CCode (cname = "cap_from_text")] 279 | public static Capability? from_text (string text); 280 | /** 281 | * Allocate a capability state in working storage and set it to represent the capability state of the path. 282 | * 283 | * The effects of reading the capability state from any file other than a regular file is undefined. 284 | */ 285 | [CCode (cname = "cap_get_fd")] 286 | public static Capability? get_fd (int fd); 287 | /** 288 | * Allocate a capability state in working storage and set it to represent the capability state of the file open on descriptor. 289 | * 290 | * The effects of reading the capability state from any file other than a regular file is undefined. 291 | */ 292 | [CCode (cname = "cap_get_file")] 293 | public static Capability? get_file (string filename); 294 | /** 295 | * Returns cap_d with the process capabilities of the process indicated by pid. 296 | */ 297 | [CCode (cname = "cap_get_pid")] 298 | public static Capability? get_pid (Posix.pid_t pid); 299 | /** 300 | * Allocates a capability state in working storage, sets its state to that of the calling process. 301 | */ 302 | [CCode (cname = "cap_get_proc")] 303 | public static Capability? get_proc (); 304 | /** 305 | * Reset the values for all capability flags for all capabilities for the open file descriptor. 306 | * 307 | * @see set_file 308 | */ 309 | [CCode (cname = "0 == cap_set_fd")] 310 | public static bool reset_fd (int fd, Capability? cap = null); 311 | /** 312 | * Reset the values for all capability flags for all capabilities for a file. 313 | * 314 | * @see set_file 315 | */ 316 | [CCode (cname = "0 == cap_set_file")] 317 | public static bool reset_file (string filename, Capability? cap = null); 318 | [CCode (cname = "cap_init")] 319 | public Capability (); 320 | /** 321 | * Initializes the capability state so that all capability flags are cleared. 322 | */ 323 | [CCode (cname = "0 == cap_clear")] 324 | public bool clear (); 325 | /** 326 | * Clears all of the capabilities of the specified capability flag. 327 | */ 328 | [CCode (cname = "cap_clear_flag")] 329 | public bool clear_flag (Flag flag); 330 | /** 331 | * Compares two full capability sets and, in the spirit of memcmp(), returns zero if the two capability sets are identical. 332 | * 333 | * A positive return value, status, indicates there is a difference between them. The returned value carries further information about which of three sets differ. 334 | * @see Flag.differs 335 | */ 336 | [CCode (cname = "cap_compare")] 337 | public int compare (Capability other); 338 | /** 339 | * Copies a capability state in working storage from system managed space to user-managed space. 340 | * 341 | * The function will do any conversions necessary to convert the capability state from the undefined internal format to an exportable, contiguous, persistent data record. It is the responsibility of the user to allocate a buffer large enough to hold the copied data. 342 | * @return the length of the resulting data record. 343 | * @see size 344 | */ 345 | [CCode (cname = "cap_copy_ext", instance_pos = 1.1)] 346 | public ssize_t copy ([CCode (array_length_pos = 1.2)] uint8[] buffer); 347 | [CCode (cname = "cap_dup")] 348 | public Capability dup (); 349 | /** 350 | * Obtains the current value of the capability flag. 351 | */ 352 | [CCode (cname = "0 == cap_get_flag")] 353 | public bool get_flag (Value val, Flag flag, out bool result); 354 | /** 355 | * Set the values for all capability flags for all capabilities for the open file descriptor. 356 | * 357 | * @see set_file 358 | */ 359 | [CCode (cname = "0 == cap_set_fd", instance_pos = -1)] 360 | public bool set_fd (int fd); 361 | /** 362 | * Set the values for all capability flags for all capabilities for a file. 363 | * 364 | * The new capability state of the file is completely determined by the contents of this object. 365 | * For these functions to succeed, the calling process must have the effective capability, {@link Value.SETFCAP}, enabled and either the effective user ID of the process must match the file owner or the calling process must have the {@link Value.FOWNER} flag in its effective capability set. The effects of writing the capability state to any file type other than a regular file are undefined. 366 | */ 367 | [CCode (cname = "0 == cap_set_file", instance_pos = -1)] 368 | public bool set_file (string filename); 369 | /** 370 | * Sets the flag of each capability in the array caps in the capability state. 371 | */ 372 | [CCode (cname = "0 == cap_set_flag")] 373 | public bool set_flag (Flag flag, [CCode (array_length_pos = 2.1)] Value[] values, bool val); 374 | /** 375 | * Sets the values for all capability flags for all capabilities to this capability state. 376 | * 377 | * The new capability state of the process will be completely determined by the contents of this object upon successful return from this function. If any flag is set for any capability not currently permitted for the calling process, the function will fail, and the capability state of the process will remain unchanged. 378 | */ 379 | [CCode (cname = "0 == cap_set_proc")] 380 | public bool set_proc (); 381 | [CCode (cname = "cap_to_text", array_length_type = "ssize_t")] 382 | public uint8[] to_text (); 383 | } 384 | } 385 | -------------------------------------------------------------------------------- /libelf.deps: -------------------------------------------------------------------------------- 1 | posix 2 | -------------------------------------------------------------------------------- /libffi.vapi: -------------------------------------------------------------------------------- 1 | [CCode (cheader_filename = "ffi.h")] 2 | namespace FFI { 3 | [CCode (cname = "ffi_cif", has_type_id = false)] 4 | public struct call_interface { 5 | [CCode (cname = "ffi_prep_cif")] 6 | public static Status prepare (out call_interface cif, ABI abi, type returntype, [CCode (array_length_type = "unsigned int", array_length_pos = 2.3)] type[] argtypes); 7 | 8 | [CCode (cname = "ffi_call", simple_generics = true)] 9 | public void call (void* fn, out T rvalue, void** avalue); 10 | } 11 | 12 | [CCode (cname = "ffi_type*", cprefix = "ffi_type_", has_type_id = false)] 13 | [SimpleType] 14 | public struct type {} 15 | [CCode (cname = "&ffi_type_void")] 16 | public const type @void; 17 | [CCode (cname = "&ffi_type_uint8")] 18 | public const type @uint8; 19 | [CCode (cname = "&ffi_type_sint8")] 20 | public const type @sint8; 21 | [CCode (cname = "&ffi_type_uint16")] 22 | public const type @uint16; 23 | [CCode (cname = "&ffi_type_sint16")] 24 | public const type @sint16; 25 | [CCode (cname = "&ffi_type_uint32")] 26 | public const type @uint32; 27 | [CCode (cname = "&ffi_type_sint32")] 28 | public const type @sint32; 29 | [CCode (cname = "&ffi_type_uint64")] 30 | public const type @uint64; 31 | [CCode (cname = "&ffi_type_sint64")] 32 | public const type @sint64; 33 | [CCode (cname = "&ffi_type_float")] 34 | public const type @float; 35 | [CCode (cname = "&ffi_type_double")] 36 | public const type @double; 37 | [CCode (cname = "&ffi_type_pointer")] 38 | public const type @pointer; 39 | 40 | [CCode (cname = "ffi_status", cprefix = "FFI_", has_type_id = false)] 41 | public enum Status { 42 | OK, 43 | BAD_TYPEDEF, 44 | BAD_ABI 45 | } 46 | 47 | /** 48 | * The ABI convention for the function being called 49 | * 50 | * This is all possible calling conventions across all platforms. Most will not work, or even be defined, on the current platform. 51 | */ 52 | [CCode (cname = "ffi_abi", cprefix = "FFI_", has_type_id = false)] 53 | public enum ABI { 54 | [CCode (cname = "FFI_DEFAULT_ABI")] 55 | DEFAULT, 56 | AIX, 57 | DARWIN, 58 | EABI, 59 | GCC_SYSV, 60 | LINUX, 61 | LINUX64, 62 | LINUX_SOFT_FLOAT, 63 | N32, 64 | N32_SOFT_FLOAT, 65 | N64, 66 | N64_SOFT_FLOAT, 67 | O32, 68 | O32_SOFT_FLOAT, 69 | OSF, 70 | PA64, 71 | STDCALL, 72 | SYSV, 73 | UNIX, 74 | UNIX64, 75 | V8, 76 | V8PLUS, 77 | V9, 78 | VFP, 79 | WIN64, 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /libpcap.deps: -------------------------------------------------------------------------------- 1 | posix 2 | -------------------------------------------------------------------------------- /libpipeline.deps: -------------------------------------------------------------------------------- 1 | posix 2 | -------------------------------------------------------------------------------- /libpipeline.vapi: -------------------------------------------------------------------------------- 1 | [CCode (cheader_filename = "pipeline.h")] 2 | namespace Pipe { 3 | [CCode (cname = "pipecmd_function_type")] 4 | public delegate void Function (); 5 | /** 6 | * Functions to run pipelines and handle signals. 7 | */ 8 | [CCode (cname = "pipeline_post_fork_fn", has_target = false)] 9 | public delegate void PostFork (); 10 | 11 | /** 12 | * Install a post-fork handler. 13 | * 14 | * This will be run in any child process immediately after it is forked. For 15 | * instance, this may be used for cleaning up application-specific signal 16 | * handlers. Pass null to clear any existing post-fork handler. 17 | */ 18 | [CCode (cname = "pipeline_install_post_fork")] 19 | public void install_post_fork (PostFork? handler); 20 | 21 | /** 22 | * Start a pipeline and wait for it to complete. 23 | */ 24 | [CCode (cname = "pipeline_run")] 25 | public int run (owned Pipe.Line pipe_line); 26 | 27 | [CCode (cname = "pipecmd", free_function = "pipecmd_free")] 28 | [Compact] 29 | public class Command { 30 | /** 31 | * If set, redirect this command's standard error to /dev/null. Otherwise, 32 | * and by default, pass it through. 33 | */ 34 | public bool discard_err { 35 | [CCode (cname = "pipecmd_discard_err")] 36 | set; 37 | } 38 | 39 | /** 40 | * The nice(3) value for this command. 41 | * 42 | * Defaults to 0. Errors while attempting to set the nice value are 43 | * ignored, aside from emitting a debug message. 44 | */ 45 | public int nice { 46 | [CCode (cname = "pipecmd_nice")] 47 | set; 48 | } 49 | 50 | /** 51 | * The number of arguments to this command. 52 | * 53 | * Note that this includes the command name as the first argument, so the 54 | * command 'echo foo bar' is counted as having three arguments. 55 | */ 56 | public int num_args { 57 | [CCode (cname = "pipecmd_get_nargs")] 58 | get; 59 | } 60 | [CCode (cname = "pipecmd_new")] 61 | public Command (string name); 62 | [CCode (cname = "pipecmd_new_argv")] 63 | public Command.argv (string name, va_list argv); 64 | [CCode (cname = "pipecmd_new_args")] 65 | public Command.args (string name, ...); 66 | 67 | /** 68 | * Split on whitespace to construct a command and arguments. 69 | * 70 | * Honours shell-style single-quoting, double-quoting, and backslashes, but 71 | * not other shell evil like wildcards, semicolons, or backquotes. 72 | */ 73 | [Deprecated] 74 | [CCode (cname = "pipecmd_new_argstr")] 75 | public Command.arg_str (string arg_str); 76 | /** 77 | * Construct a new command that calls a given function rather than 78 | * executing a process. 79 | * 80 | * Methods that deal with arguments cannot be used with the command 81 | * returned by this function. 82 | */ 83 | [CCode (cname = "pipecmd_new_function")] 84 | public Command.function (string name, [CCode (target_pos = -1)] owned Function func); 85 | 86 | /** 87 | * Construct a new command that runs a sequence of commands. 88 | * 89 | * The commands will be executed in forked children; if any exits non-zero 90 | * then it will terminate the sequence, as with "&&" in shell. 91 | * 92 | * Methods that deal with arguments cannot be used with the command 93 | * returned by this function. 94 | */ 95 | [CCode (cname = "pipecmd_new_sequence", sentinel = "NULL")] 96 | public Command.sequence (string name, ...); 97 | [CCode (cname = "pipecmd_new_sequencev")] 98 | public Command.sequencev (string name, va_list cmdv); 99 | 100 | /** 101 | * Return a new command that just passes data from its input to its output. 102 | */ 103 | [CCode (cname = "pipecmd_new_passthrough")] 104 | public Command.passthrough (); 105 | 106 | /** 107 | * Return a duplicate of a command. 108 | */ 109 | [CCode (cname = "pipecmd_dup")] 110 | public Command dup (); 111 | 112 | /** 113 | * Add an argument to a command. 114 | */ 115 | [CCode (cname = "pipecmd_arg")] 116 | public void add_arg (string arg); 117 | 118 | /** 119 | * Convenience function to add an argument with printf substitutions. 120 | */ 121 | [CCode (cname = "pipecmd_argf")] 122 | [PrintfFormat] 123 | public void add_argf (string format, ...); 124 | 125 | [CCode (cname = "pipecmd_argv")] 126 | public void add_argv (va_list argv); 127 | [CCode (cname = "pipecmd_args", sentinel = "NULL")] 128 | public void add_args (...); 129 | 130 | /** 131 | * Split on whitespace to add a list of arguments. 132 | * 133 | * Honours shell-style single-quoting, double-quoting, and backslashes, but 134 | * not other shell evil like wildcards, semicolons, or backquotes. 135 | */ 136 | [CCode (cname = "pipecmd_argstr")] 137 | [Deprecated] 138 | public void add_arg_str (string arg_str); 139 | 140 | /** 141 | * Add a command to a sequence. 142 | */ 143 | [CCode (cname = "pipecmd_sequence_command")] 144 | public void append (owned Command child); 145 | /** 146 | * Clear the environment while running this command. 147 | * 148 | * Note that environment operations work in sequence; if this is followed 149 | * by {@link set}, this causes the command to have just a single 150 | * environment variable set. 151 | */ 152 | [CCode (cname = "pipecmd_clearenv")] 153 | public void clear (); 154 | 155 | /** 156 | * Dump a string representation of a command to stream. 157 | */ 158 | [CCode (cname = "pipecmd_dump")] 159 | public void dump ( 160 | # if POSIX 161 | Posix.FILE? 162 | # else { 163 | GLib.FileStream? 164 | # endif 165 | stream); 166 | } 167 | 168 | /** 169 | * Execute a single command, replacing the current process. 170 | * 171 | * Never returns, instead exiting non-zero on failure. 172 | */ 173 | [NoReturn] 174 | [CCode (cname = "pipecmd_exec")] 175 | public void exec (); 176 | 177 | /** 178 | * Set an environment variable while running this command. 179 | */ 180 | [CCode (cname = "pipecmd_setenv")] 181 | public void set (string name, string value); 182 | 183 | /** 184 | * Return a string representation of a command. 185 | */ 186 | [CCode (cname = "pipecmd_tostring")] 187 | public string to_string (); 188 | 189 | /** 190 | * Unset an environment variable while running this command. 191 | */ 192 | [CCode (cname = "pipecmd_unsetenv")] 193 | public void unset (string name); 194 | } 195 | 196 | [CCode (cname = "pipeline", free_function = "pipeline_free")] 197 | [Compact] 198 | public class Line { 199 | /** 200 | * Ignore SIGINT and SIGQUIT while the pipeline is running, like system(). 201 | */ 202 | public bool ignore_signals { 203 | [CCode (cname = "pipeline_ignore_signals")] 204 | set; 205 | } 206 | 207 | /** 208 | * Set file name to open and use as the input of the whole pipeline. 209 | * 210 | * This may be more convenient than supplying file descriptors, and 211 | * guarantees that the files are opened with the same privileges under 212 | * which the pipeline is run. 213 | * 214 | * Setting this (even with null, which returns to the default of leaving 215 | * input as stdin) supersedes any previous setting of {@link want_in}. 216 | * 217 | * The given file will be opened when the pipeline is started. 218 | */ 219 | public string? in_file { 220 | [CCode (cname = "pipeline_want_infile")] 221 | set; 222 | } 223 | 224 | /** 225 | * The stream corresponding to input. 226 | * 227 | * The pipeline must be started. 228 | */ 229 | public 230 | # if POSIX 231 | Posix.FILE? 232 | # else { 233 | GLib.FileStream? 234 | # endif 235 | input { 236 | [CCode (cname = "pipeline_get_infile")] 237 | get; 238 | } 239 | 240 | /** 241 | * Set file name to open and use as the output of the whole pipeline. 242 | * 243 | * This may be more convenient than supplying file descriptors, and 244 | * guarantees that the files are opened with the same privileges under 245 | * which the pipeline is run. 246 | * 247 | * Setting this (even with null, which returns to the default of leaving 248 | * output as stdout) supersedes any previous setting of {@link want_out}. 249 | * 250 | * The given file will be opened when the pipeline is started. If an output 251 | * file does not already exist, it is created (with mode 0666 modified in 252 | * the usual way by umask); if it does exist, then it is truncated. 253 | */ 254 | public string? out_file { 255 | [CCode (cname = "pipeline_want_outfile")] 256 | set; 257 | } 258 | 259 | /** 260 | * The stream corresponding to input. 261 | * 262 | * The pipeline must be started. 263 | */ 264 | public 265 | # if POSIX 266 | Posix.FILE? 267 | # else { 268 | GLib.FileStream? 269 | # endif 270 | output { 271 | [CCode (cname = "pipeline_get_outfile")] 272 | get; 273 | } 274 | 275 | /** 276 | * The number of bytes of data that can be read using {@link read} or 277 | * {@link peek} solely from the peek cache, without having to read from the 278 | * pipeline itself (and thus potentially block). 279 | */ 280 | public size_t peek_size { 281 | [CCode (cname = "pipeline_peek_size")] 282 | get; 283 | } 284 | 285 | /** 286 | * The number of commands in this pipeline. 287 | */ 288 | public int size { 289 | [CCode (cname = "pipeline_get_ncommands")] 290 | get; 291 | } 292 | 293 | /** 294 | * Set file descriptors to use as the input of the whole pipeline. 295 | * 296 | * If non-negative, used directly as a file descriptor. If negative, 297 | * {@link start} will create pipes and store the input writing. The 298 | * default is to leave input and output as stdin unless 299 | * {@link in_file} has been set. 300 | */ 301 | public int want_in { 302 | [CCode (cname = "pipeline_want_in")] 303 | set; 304 | } 305 | /** 306 | * Set file descriptors to use as the output of the whole pipeline. 307 | * 308 | * If non-negative, used directly as a file descriptor. If negative, 309 | * {@link start} will create pipes and store the output reading. The 310 | * default is to leave output as stdout unless {@link out_file} has been 311 | * set. 312 | */ 313 | public int want_out { 314 | [CCode (cname = "pipeline_want_out")] 315 | set; 316 | } 317 | 318 | [CCode (cname = "pipeline_new")] 319 | public Line (); 320 | } 321 | } 322 | 323 | [CCode (cname = "pipeline_new_commandv")] 324 | public Line.commandv (owned Command cmd, va_list cmdv); 325 | [CCode (cname = "pipeline_new_commands", sentinel = "NULL")] 326 | public Line.commands (owned Command cmd1, ...); 327 | 328 | [CCode (cname = "pipeline_new_command_argv")] 329 | public Line.command_argv (string name, va_list argv); 330 | [CCode (cname = "pipeline_new_command_args", sentinel = "NULL")] 331 | public Line.command_args (string name, ...); 332 | 333 | /** 334 | * Joins two pipelines, neither of which are allowed to be started. 335 | * 336 | * Discards output from this instance, and input from the parameter. 337 | */ 338 | [CCode (cname = "pipeline_join")] 339 | public Line join (Line other); 340 | 341 | /** 342 | * Add a command to a pipeline. 343 | */ 344 | [CCode (cname = "pipeline_command")] 345 | public void add (owned Command cmd); 346 | 347 | /** 348 | * Construct a new command and add it to a pipeline in one go. 349 | */ 350 | [CCode (cname = "pipeline_command_argv")] 351 | public void add_argv (string name, va_list argv); 352 | [CCode (cname = "pipeline_command_args", sentinel = "NULL")] 353 | public void add_args (string name, ...); 354 | 355 | /** 356 | * Construct a new command from a shell-quoted string and add it to a 357 | * pipeline in one go. 358 | * @see Command.Command.arg_str 359 | */ 360 | [CCode (cname = "pipeline_command_argstr")] 361 | [Deprecated] 362 | public void add_arg_str (string arg_str); 363 | 364 | /** 365 | * Convenience functions wrapping pipeline_command(). 366 | */ 367 | [CCode (cname = "pipeline_commandv")] 368 | public void add_commandv (va_list cmdv); 369 | [CCode (cname = "pipeline_commands", sentinel = "NULL")] 370 | public void add_commands (...); 371 | 372 | /** 373 | * Connect the input of one or more sink pipelines to the output of a source 374 | * pipeline. 375 | * 376 | * The source pipeline may be started, but in that case {@link want_out} 377 | * must be negative; otherwise, discards {@link want_out} from source. In 378 | * any event, discards {@link want_in} from all sinks, none of which are 379 | * allowed to be started. 380 | * 381 | * This is an application-level connection; data may be intercepted between 382 | * the pipelines by the program before calling {@link pump}, which sets 383 | * data flowing from the source to the sinks. It is primarily useful when 384 | * more than one sink pipeline is involved, in which case the pipelines 385 | * cannot simply be concatenated into one. 386 | */ 387 | [CCode (cname = "pipeline_connect", sentinel = "NULL")] 388 | public void connect (owned Line sink, ...); 389 | 390 | /** 391 | * Dump a string representation to stream. 392 | */ 393 | [CCode (cname = "pipeline_dump")] 394 | public void dump ( 395 | # if POSIX 396 | Posix.FILE? 397 | # else { 398 | GLib.FileStream? 399 | # endif 400 | stream); 401 | } 402 | 403 | /** 404 | * Get a command from this pipeline, counting from zero 405 | * @return null if n is out of range. 406 | */ 407 | [CCode (cname = "pipeline_get_command")] 408 | public unowned Command? get (int n); 409 | 410 | /** 411 | * Return the process ID of a command from this pipeline, counting from 412 | * zero. 413 | * 414 | * The pipeline must be started. Return -1 if n is out of range or if the 415 | * command has already exited and been reaped. 416 | */ 417 | [CCode (cname = "pipeline_get_pid")] 418 | public Posix.pid_t get_pid (int n); 419 | 420 | /** 421 | * Look ahead in the pipeline's output, returning the data block. 422 | * @param len is the number of bytes to read and is updated to the number of bytes read. 423 | */ 424 | [CCode (cname = "pipeline_peek", array_length = false)] 425 | public unowned uint8[] peek (ref size_t len); 426 | 427 | /** 428 | * Look ahead in the pipeline's output for a line of data, returning it. 429 | * 430 | * The starting position of the next read or peek is not affected by this 431 | * call. 432 | */ 433 | [CCode (cname = "pipeline_peekline")] 434 | public unowned string? peek_line (); 435 | 436 | /** 437 | * Pump data among one or more pipelines connected using {@link connect} 438 | * until all source pipelines have reached end-of-file and all data has been 439 | * written to all sinks (or failed). 440 | * 441 | * All relevant pipelines must be supplied: that is, no pipeline that has 442 | * been connected to a source pipeline may be supplied unless that source 443 | * pipeline is also supplied. Automatically starts all pipelines if they are 444 | * not already started, but does not wait for them. 445 | */ 446 | [CCode (cname = "pipeline_pump", sentinel = "NULL")] 447 | public void pump (...); 448 | 449 | /** 450 | * Read bytes of data from the pipeline, returning the data block. 451 | * @param len is the number of bytes to read and is updated to the number of bytes read. 452 | */ 453 | [CCode (cname = "pipeline_read", array_length = false)] 454 | public unowned uint8[] read (ref size_t len); 455 | 456 | /** 457 | * Read a line of data from the pipeline, returning it. 458 | */ 459 | [CCode (cname = "pipeline_readline")] 460 | public unowned string? read_line (); 461 | 462 | /** 463 | * Set a command in this pipeline, counting from zero. 464 | * @return the previous command in that position. 465 | */ 466 | [CCode (cname = "pipeline_set_command")] 467 | public Command? set (int n, owned Command cmd); 468 | 469 | /** 470 | * Skip over and discard bytes of data from the peek cache. 471 | * 472 | * Asserts that enough data is available to skip, so you may want to check 473 | * using {@link peek_size} first. 474 | */ 475 | [CCode (cname = "pipeline_peek_skip")] 476 | public void skip (size_t len); 477 | 478 | /** 479 | * Start the processes in a pipeline. 480 | * 481 | * Installs this library's SIGCHLD handler if not already installed. Calls 482 | * error(FATAL) on error. 483 | */ 484 | [CCode (cname = "pipeline_start")] 485 | public void start (); 486 | 487 | /** 488 | * Return a string representation. 489 | */ 490 | [CCode (cname = "pipeline_tostring")] 491 | public string to_string (); 492 | 493 | /** 494 | * Wait for a pipeline to complete. 495 | * 496 | * @param statuses The return values similar to the exit status that a shell 497 | * would return, with some modifications. 498 | * @return If the last command exits with a signal (other than SIGPIPE, which 499 | * is considered equivalent to exiting zero), then the return value is 128 500 | * plus the signal number; if the last command exits normally but non-zero, 501 | * then the return value is its exit status; if any other command exits 502 | * non-zero, then the return value is 127; otherwise, the return value is 0. 503 | * This means that the return value is only 0 if all commands in the pipeline 504 | * exit successfully. 505 | */ 506 | [CCode (cname = "pipeline_wait_all")] 507 | public int wait_all (out int[] statuses); 508 | 509 | /** 510 | * Wait for a pipeline to complete and return its combined exit status. 511 | * @see wait_all 512 | */ 513 | [CCode (cname = "pipeline_wait")] 514 | public int wait (); 515 | } 516 | } 517 | -------------------------------------------------------------------------------- /libqrencode.vapi: -------------------------------------------------------------------------------- 1 | /** 2 | * A library for encoding data in a QR Code symbol, a kind of 2D symbology. 3 | */ 4 | [CCode (cheader_filename = "qrencode.h")] 5 | namespace QR { 6 | /** 7 | * The state of each module (dot). 8 | * 9 | * Only {@link Dot.BLACK} is useful for usual applications. 10 | */ 11 | [CCode (cname = "unsigned char", has_type_id = false)] 12 | [Flags] 13 | public enum Dot { 14 | [CCode (cname = "1")] 15 | BLACK, 16 | [CCode (cname = "2")] 17 | DATA_AND_ECC, 18 | [CCode (cname = "4")] 19 | FORMAT, 20 | [CCode (cname = "8")] 21 | VERSION, 22 | [CCode (cname = "16")] 23 | TIMING, 24 | [CCode (cname = "32")] 25 | ALIGNMENT, 26 | [CCode (cname = "64")] 27 | FINDER, 28 | [CCode (cname = "128")] 29 | NON_DATA 30 | } 31 | 32 | /** 33 | * Level of error correction. 34 | */ 35 | [CCode (cname = "QRecLevel", cprefix = "QR_ECLEVEL_")] 36 | public enum ECLevel { 37 | /** 38 | * Lowest 39 | */ 40 | L, 41 | M, 42 | Q, 43 | /** 44 | * Highest 45 | */ 46 | H 47 | } 48 | 49 | /** 50 | * Encoding mode. 51 | */ 52 | [CCode (cname = "QRencodeMode", cprefix = "QR_MODE_")] 53 | public enum Mode { 54 | /** 55 | * Numeric mode 56 | */ 57 | NUM, 58 | /** 59 | * Alphabet-numeric mode 60 | */ 61 | AN, 62 | /** 63 | * 8-bit data mode 64 | */ 65 | [CCode (cname = "QR_MODE_8")] 66 | EIGHT_BIT, 67 | /** 68 | * Kanji (shift-jis) mode 69 | */ 70 | KANJI, 71 | /** 72 | * Internal use only 73 | */ 74 | STRUCTURE 75 | } 76 | 77 | /** 78 | * Symbol data is represented as an array contains width*width {@link uint8}. 79 | * 80 | * Each point represents a module (dot). 81 | * described. 82 | */ 83 | [CCode (cname = "QRcode", free_function = "QRcode_free", has_type_id = false)] 84 | [Compact] 85 | public class Code { 86 | public int version; 87 | public int width; 88 | [CCode (array_length = false)] 89 | public Dot[] data; 90 | /** 91 | * Create a symbol from the string. 92 | * 93 | * The library automatically parses the input string and encodes in a QR Code 94 | * symbol. 95 | * This function is THREAD UNSAFE. 96 | * @param str input string. 97 | * @param version version of the symbol. If 0, the library chooses the 98 | * minimum version for the given input data. 99 | * @param level error correction level. 100 | * @param hint tell the library how non-alphanumerical characters should be 101 | * encoded. If {@link Mode.KANJI} is given, kanji characters will be encoded 102 | * as Shif-JIS characters. If {@link Mode.EIGHT_BIT} is given, all of 103 | * non-alphanumerical characters will be encoded as is. If you want to embed 104 | * UTF-8 string, choose this. 105 | * @param casesensitive case-sensitive or not. 106 | * @return The version of the result QRcode may be larger than the designated 107 | * version. On error, null is returned, and errno is set to indicate the 108 | * error. 109 | */ 110 | [CCode (cname = "QRcode_encodeString")] 111 | public static Code? encode_string (string str, int version, ECLevel level, Mode hint, bool casesensitive); 112 | 113 | /** 114 | * Create a symbol from the string encoding the whole data in 8-bit mode. 115 | * @see encode_string 116 | */ 117 | [CCode (cname = "QRcode_encodeString8bit")] 118 | public static Code? encode_string_8bit (string str, int version, ECLevel level); 119 | public bool get (int x, int y) { 120 | if (x < width && y < width) { 121 | return Dot.BLACK in data[x * width + y]; 122 | } else { 123 | return false; 124 | } 125 | } 126 | } 127 | 128 | /** 129 | * The input strings and version and error correction level. 130 | */ 131 | [CCode (cname = "QRinput", free_function = "QRinput_free", has_type_id = false)] 132 | [Compact] 133 | public class Input { 134 | /** 135 | * Instantiate an input data object. 136 | * @param version version number. 137 | * @param level Error correction level. 138 | * @return On error, null is returned and errno is set to indicate the 139 | * error. 140 | */ 141 | [CCode (cname = "QRinput_new2")] 142 | public Input? create (int version, ECLevel level); 143 | 144 | /** 145 | * The current error correction level. 146 | */ 147 | public ECLevel correction { 148 | [CCode (cname = "QRinput_getErrorCorrectionLevel")] 149 | get; 150 | [CCode (cname = "QRinput_setErrorCorrectionLevel")] 151 | set; 152 | } 153 | 154 | /** 155 | * The current version. (Zero for automatic) 156 | */ 157 | public int version { 158 | [CCode (cname = "QRinput_getVersion")] 159 | get; 160 | [CCode (cname = "QRinput_setVersion")] 161 | set; 162 | } 163 | 164 | /** 165 | * Instantiate an input data object. 166 | * 167 | * The version is set to 0 (auto-select) and the error correction level is 168 | * set to {@link ECLevel.L}. 169 | */ 170 | [CCode (cname = "QRinput_new")] 171 | public Input (); 172 | 173 | /** 174 | * Append data to an input object. 175 | * The data is copied and appended to the input object. 176 | * @param mode encoding mode. 177 | * @param data the input data. 178 | * @return false on success 179 | */ 180 | [CCode (cname = "QRinput_append")] 181 | public bool append (Mode mode, [CCode (array_length_pos = 1.1)] uint8[] data); 182 | 183 | /** 184 | * Validate the input data. 185 | * @param mode encoding mode. 186 | * @param data the input data. 187 | * @return false on success 188 | */ 189 | [CCode (cname = "QRinput_check")] 190 | public bool check (Mode mode, [CCode (array_length_pos = 1.1)] uint8[] data); 191 | 192 | /** 193 | * Create a symbol from the input data. 194 | * 195 | * This function is THREAD UNSAFE. 196 | * @return The version of the result QRcode may be larger than the 197 | * designated version. On error, NULL is returned, and errno is set to 198 | * indicate the error. 199 | */ 200 | [CCode (cname = "QRcode_encodeInput")] 201 | public Code? encode (); 202 | 203 | /** 204 | * Split an input. 205 | * 206 | * It calculates a parity, set it, then insert structured-append headers. 207 | * 208 | * Version number and error correction level must be set. 209 | * @return a set of input data. On error, null is returned, and errno is 210 | * set to indicate the error. 211 | */ 212 | [CCode (cname = "QRinput_splitQRinputToStruct")] 213 | public extern StructSym? split (); 214 | } 215 | /** 216 | * Singly-linked list of {@link Code}s. 217 | * 218 | * Used to represent a structured symbols. 219 | */ 220 | [CCode (cname = "QRcode_List", free_function = "QRcode_List_free", has_type_id = false)] 221 | [Compact] 222 | public class List { 223 | public Code code; 224 | public List? next; 225 | 226 | /** 227 | * The number of symbols included. 228 | */ 229 | public int size { 230 | [CCode (cname = "QRcode_List_size")] 231 | get; 232 | } 233 | /** 234 | * Create structured symbols from the string. 235 | * 236 | * The library automatically parses the input string and encodes in a QR Code 237 | * symbol. 238 | * 239 | * This function is THREAD UNSAFE. 240 | * @param str input string. 241 | * @param version version of the symbol. 242 | * @param level error correction level. 243 | * @param hint tell the library how non-alphanumerical characters should be 244 | * encoded. If {@link Mode.KANJI} is given, kanji characters will be 245 | * encoded as Shif-JIS characters. If {@link Mode.EIGHT_BIT} is given, all 246 | * of non-alphanumerical characters will be encoded as is. If you want to 247 | * embed UTF-8 string, choose this. 248 | * @param casesensitive case-sensitive or not. 249 | * @return On error, null is returned, and errno is set to indicate the 250 | * error. 251 | */ 252 | [CCode (cname = "QRcode_encodeStringStructured")] 253 | public static List? encode_string (string str, int version, ECLevel level, Mode hint, bool casesensitive); 254 | 255 | /** 256 | * Create structured symbols from the string encoding whole data in 8-bit mode. 257 | * @see encode_string 258 | */ 259 | [CCode (cname = "QRcode_encodeString8bitStructured")] 260 | public static List? encode_string_8bit (string str, int version, ECLevel level); 261 | } 262 | /** 263 | * Set of {@link Input} for structured symbols. 264 | */ 265 | [CCode (cname = "QRinput_Struct", free_function = "QRinput_Struct_free", has_type_id = false)] 266 | [Compact] 267 | public class StructSym { 268 | /** 269 | * Instantiate a set of input data object. 270 | */ 271 | [CCode (cname = "QRinput_Struct_new")] 272 | public StructSym (); 273 | 274 | /** 275 | * The parity of structured symbols. 276 | */ 277 | public uint8 parity { 278 | [CCode (cname = "QRinput_Struct_setParity")] 279 | set; 280 | } 281 | 282 | /** 283 | * Append a QRinput object to the set. 284 | * 285 | * Never append the same QRinput object twice or more. 286 | * @param input an input object. 287 | * @return number of input objects in the structure or -1 if an error occurred. 288 | */ 289 | [CCode (cname = "QRinput_Struct_appendInput")] 290 | public int append (Input input); 291 | 292 | /** 293 | * Create structured symbols from the input data. 294 | * 295 | * This function is THREAD UNSAFE. 296 | */ 297 | [CCode (cname = "QRcode_encodeInputStructured")] 298 | public List? encode (); 299 | 300 | /** 301 | * Insert structured-append headers to the input structure. 302 | * 303 | * It calculates a parity and set it if the parity is not set yet. 304 | * @return false on success 305 | */ 306 | [CCode (cname = "QRinput_Struct_insertStructuredAppendHeaders")] 307 | public bool insert_headers (); 308 | } 309 | } 310 | -------------------------------------------------------------------------------- /libssh2.deps: -------------------------------------------------------------------------------- 1 | posix 2 | -------------------------------------------------------------------------------- /libtasn1.vapi: -------------------------------------------------------------------------------- 1 | [CCode (cheader_filename = "libtasn1.h>\n#define asn1_element_free(x) asn1_delete_structure(&x)\n#include integer=-1. 296 | * value[0]=0xFF value[1]=0xFF , len=2 -> integer=-1. 297 | * value[0]=0x01 , len=1 -> integer= 1. 298 | * value[0]=0x00 value[1]=0x01 , len=2 -> integer= 1. 299 | * value="123" , len=0 -> integer= 123. 300 | * 301 | * ENUMERATED: As INTEGER (but only with not negative numbers). 302 | * 303 | * BOOLEAN: VALUE must be the null terminated string "TRUE" or "FALSE" and 304 | * LEN != 0. 305 | * 306 | * value="TRUE" , len=1 -> boolean=TRUE. 307 | * value="FALSE" , len=1 -> boolean=FALSE. 308 | * 309 | * OBJECT IDENTIFIER: VALUE must be a null terminated string with each 310 | * number separated by a dot (e.g. "1.2.3.543.1"). LEN != 0. 311 | * 312 | * value="1 2 840 10040 4 3" , len=1 -> OID=dsa-with-sha. 313 | * 314 | * UTCTime: VALUE must be a null terminated string in one of these formats: 315 | * "YYMMDDhhmmssZ", "YYMMDDhhmmssZ", "YYMMDDhhmmss+hh'mm'", 316 | * "YYMMDDhhmmss-hh'mm'", "YYMMDDhhmm+hh'mm'", or "YYMMDDhhmm-hh'mm'". LEN 317 | * != 0. 318 | * 319 | * value="9801011200Z" , len=1 -> time=Jannuary 1st, 1998 320 | * at 12h 00m Greenwich Mean Time 321 | * 322 | * GeneralizedTime: VALUE must be in one of this format: 323 | * "YYYYMMDDhhmmss.sZ", "YYYYMMDDhhmmss.sZ", "YYYYMMDDhhmmss.s+hh'mm'", 324 | * "YYYYMMDDhhmmss.s-hh'mm'", "YYYYMMDDhhmm+hh'mm'", or 325 | * "YYYYMMDDhhmm-hh'mm'" where ss.s indicates the seconds with any 326 | * precision like "10.1" or "01.02". LEN != 0 327 | * 328 | * value="2001010112001.12-0700" , len=1 -> time=Jannuary 329 | * 1st, 2001 at 12h 00m 01.12s Pacific Daylight Time 330 | * 331 | * OCTET STRING: VALUE contains the octet string and LEN is the number of 332 | * octets. 333 | * 334 | * value="$\backslash$x01$\backslash$x02$\backslash$x03" , 335 | * len=3 -> three bytes octet string 336 | * 337 | * GeneralString: VALUE contains the generalstring and LEN is the number of 338 | * octets. 339 | * 340 | * value="$\backslash$x01$\backslash$x02$\backslash$x03" , 341 | * len=3 -> three bytes generalstring 342 | * 343 | * BIT STRING: VALUE contains the bit string organized by bytes and LEN is 344 | * the number of bits. 345 | * 346 | * value="$\backslash$xCF" , len=6 -> bit string="110011" (six 347 | * bits) 348 | * 349 | * CHOICE: if NAME indicates a choice type, VALUE must specify one of the 350 | * alternatives with a null terminated string. LEN != 0. Using "pkix.asn": 351 | * 352 | * result=asn1_write_value(cert, 353 | * "certificate1.tbsCertificate.subject", "rdnSequence", 354 | * 1); 355 | * 356 | * ANY: VALUE indicates the der encoding of a structure. LEN != 0. 357 | * 358 | * SEQUENCE OF: VALUE must be the null terminated string "NEW" and LEN != 359 | * 0. With this instruction another element is appended in the sequence. 360 | * The name of this element will be "?1" if it's the first one, "?2" for 361 | * the second and so on. 362 | * 363 | * Using "pkix.asn"\: 364 | * 365 | * result=asn1_write_value(cert, 366 | * "certificate1.tbsCertificate.subject.rdnSequence", "NEW", 1); 367 | * 368 | * SET OF: the same as SEQUENCE OF. Using "pkix.asn": 369 | * 370 | * result=asn1_write_value(cert, 371 | * "tbsCertificate.subject.rdnSequence.?LAST", "NEW", 1); 372 | * 373 | * @param name the name of the element inside the structure that you want to set. 374 | * @param ivalue vector used to specify the value to set. 375 | */ 376 | [CCode (cname = "asn1_write_value")] 377 | public Code write_value (string name, uint8[]? ivalue); 378 | 379 | /** 380 | * Set the value of one element inside a structure. 381 | * @see write_value 382 | */ 383 | [CCode (cname = "asn1_write_value")] 384 | public Code write_value_str (string name, string ivalue, int length = 0); 385 | } 386 | 387 | /** 388 | * For the on-disk format of ASN.1 trees 389 | */ 390 | [CCode (cname = "ASN1_ARRAY_TYPE", has_type_id = false, destroy_function = "")] 391 | public struct decl { 392 | public string name; 393 | uint type; 394 | [CCode (array_length = false)] 395 | uint8[] @value; 396 | } 397 | 398 | /** 399 | * Maximum number of characters of a name inside a file with ASN1 definitons 400 | */ 401 | [CCode (cname = "ASN1_MAX_NAME_SIZE")] 402 | public const int MAX_NAME_SIZE; 403 | 404 | /** 405 | * Maximum number of characters of a description message 406 | * 407 | * Null character included. 408 | */ 409 | [CCode (cname = "ASN1_MAX_ERROR_DESCRIPTION_SIZE")] 410 | public const int MAX_ERROR_DESCRIPTION_SIZE; 411 | 412 | [CCode (cname = "ASN1_VERSION")] 413 | public const string VERSION; 414 | 415 | /** 416 | * Creates the structures needed to manage the ASN.1 definitions. 417 | * 418 | * @return {@link Code.SUCCESS} if structure was created correctly, 419 | * {@link Code.IDENTIFIER_NOT_FOUND} if in the file there is an identifier 420 | * that is not defined (see //error_description// for more information), 421 | * {@link Code.ARRAY_ERROR} if the array is wrong. 422 | */ 423 | [CCode (cname = "asn1_array2tree")] 424 | public Code array2tree ([CCode (array_length = false)] decl[] array, out Element definitions, [CCode (array_length = false)] char[]? error_description = null); 425 | 426 | /** 427 | * Check that the version of the library is at minimum the requested one and 428 | * return the version string 429 | * 430 | * @param req_version If null, no check is done, but the version string is simply returned. 431 | * @return Version string of run-time library, null if the condition is not satisfied. 432 | */ 433 | [CCode (cname = "asn1_check_version")] 434 | public unowned string? check_version (string? req_version); 435 | 436 | /** 437 | * Function that generates a C structure from an ASN1 file. 438 | * 439 | * Creates a file containing a C vector to use to manage the definitions 440 | * @param output_file_name If null, the file created is "/aa/bb/xx_asn1_tab.c" given the input file was "/aa/bb/xx.yy". 441 | * @param vector_name If null the vector name * will be "xx_asn1_tab" given the input file was "/aa/bb/xx.yy". 442 | * 443 | * @param input_file_name the path and the name of file that contains ASN.1 declarations. 444 | * @param output_file_name the path and the name of file that will contain the C vector definition. 445 | * @param vector_name the name of the C vector. 446 | * @param error_description error description or an empty string if success. 447 | * 448 | * @return {@link Code.SUCCESS} if the file has a correct syntax and every 449 | * identifier is known, {@link Code.FILE_NOT_FOUND} if an error occured while 450 | * opening the input file, {@link Code.SYNTAX_ERROR} if the syntax is not 451 | * correct, {@link Code.IDENTIFIER_NOT_FOUND} if in the file there is an 452 | * identifier that is not defined, {@link Code.NAME_TOO_LONG} if in the file 453 | * there is an identifier whith more than {@link MAX_NAME_SIZE} characters. 454 | */ 455 | [CCode (cname = "asn1_parser2array")] 456 | public Code parser2array (string input_file_name, string? output_file_name, string? vector_name, [CCode (array_length = false)] char[]? error_description = null); 457 | 458 | /** 459 | * Creates the structures needed to manage the definitions included in a file. 460 | * 461 | * @param file_name specify the path and the name of file that contains ASN.1 declarations. 462 | * @param definitions the structure created from "file_name" ASN.1 declarations. 463 | * @param error_description return the error description or an empty string if success. 464 | * @return {@link Code.SUCCESS} if the file has a correct syntax and every 465 | * identifier is known, {@link Code.FILE_NOT_FOUND} if an error occured while 466 | * opening the file, {@link Code.SYNTAX_ERROR} if the syntax is not correct, 467 | * {@link Code.IDENTIFIER_NOT_FOUND} if in the file there is an identifier 468 | * that is not defined, {@link Code.NAME_TOO_LONG} if in the file there is an 469 | * identifier whith more than {@link MAX_NAME_SIZE} characters. 470 | */ 471 | [CCode (cname = "asn1_parser2tree")] 472 | public Code parser2tree (string file_name, out Element? definitions, [CCode (array_length = false)] char[]? error_description = null); 473 | 474 | /** 475 | * DER utility functions 476 | */ 477 | namespace DER { 478 | /** 479 | * Creates the DER coding for a BIT STRING type (length and pad included). 480 | */ 481 | [CCode (cname = "asn1_bit_der")] 482 | public void bit_der (uint8[] str, [CCode (array_length = false)] uint8[] der, out int der_len); 483 | 484 | /** 485 | * Extract a BIT SEQUENCE from DER data. 486 | */ 487 | [CCode (cname = "asn1_get_bit_der")] 488 | public Code get_bit_der (uint8[] der, out int ret_len, uint8[] str, out int bit_len); 489 | 490 | /** 491 | * Extract a length field from BER data. 492 | * 493 | * The difference to {@link get_length_der} is that this function will 494 | * return a length even if the value has indefinite encoding. 495 | * 496 | * @return the decoded length value, or negative value when the value was 497 | * too big. 498 | */ 499 | [CCode (cname = "asn1_get_length_ber")] 500 | public long get_length_ber (uint8[] ber, out int len); 501 | 502 | /** 503 | * Extract a length field from DER data. 504 | * 505 | * @return the decoded length value, or -1 on indefinite length, or -2 506 | * when the value was too big to fit in a int, or -4 when the decoded 507 | * length value plus //len// would exceed the input length. 508 | */ 509 | [CCode (cname = "asn1_get_length_der")] 510 | public long get_length_der (uint8[] der, out int len); 511 | 512 | /** 513 | * Extract an OCTET SEQUENCE from DER data. 514 | */ 515 | [CCode (cname = "asn1_get_octet_der")] 516 | public Code get_octet_der (uint8[] der, out int ret_len, uint8[] str, out int str_len); 517 | 518 | /** 519 | * Decode the class and TAG from DER code. 520 | */ 521 | [CCode (cname = "asn1_get_tag_der")] 522 | public int get_tag_der (uint8[] der, out uint8 cls, out int len, out ulong tag); 523 | 524 | /** 525 | * Creates the DER coding for the LEN parameter (only the length). 526 | * 527 | * @param ans buffer is pre-allocated and must have room for the output. 528 | */ 529 | [CCode (cname = "asn1_length_der")] 530 | public void length_der (ulong len, [CCode (array_length = false)] uint8[] ans, out int ans_len); 531 | 532 | /** 533 | * Creates the DER coding for an OCTET type (length included). 534 | */ 535 | [CCode (cname = "asn1_octet_der")] 536 | public void octet_der (uint8[] str, [CCode (array_length = false)] uint8[] der, out int der_len); 537 | } 538 | } 539 | -------------------------------------------------------------------------------- /libudev.deps: -------------------------------------------------------------------------------- 1 | posix 2 | -------------------------------------------------------------------------------- /libudev.vapi: -------------------------------------------------------------------------------- 1 | [CCode (cheader_filename = "libudev.h")] 2 | namespace UDev { 3 | /** 4 | * Reads the udev config and system environment allows custom logging 5 | */ 6 | [CCode (cname = "struct udev", ref_function = "udev_ref", unref_function = "udev_unref", has_type_id = false)] 7 | public class Context { 8 | /** 9 | * Create udev library context. 10 | * 11 | * This reads the udev configuration file, and fills in the default values. 12 | */ 13 | [CCode (cname = "udev_new")] 14 | public Context (); 15 | /** 16 | * The device directory path. 17 | * 18 | * The default value is "/dev", the actual value may be overridden in the 19 | * udev configuration file. 20 | */ 21 | [CCode (cname = "udev_get_dev_path")] 22 | public string dev_path { 23 | get; 24 | } 25 | public int log_priority { 26 | [CCode (cname = "udev_get_log_priority")] 27 | get; 28 | [CCode (cname = "udev_set_log_priority")] 29 | set; 30 | } 31 | /** 32 | * The udev runtime directory path. 33 | * 34 | * The default is "/run/udev". 35 | */ 36 | [CCode (cname = "udev_get_run_path")] 37 | public string run_path { 38 | get; 39 | } 40 | /** 41 | * The sysfs mount point. 42 | * 43 | * The default is "/sys". For testing purposes, it can be overridden with 44 | * udev_sys= in the udev configuration file. 45 | */ 46 | [CCode (cname = "udev_get_sys_path")] 47 | public string sys_path { 48 | get; 49 | } 50 | public void* user_data { 51 | [CCode (cname = "udev_get_userdata")] 52 | get; 53 | [CCode (cname = "udev_set_userdata")] 54 | set; 55 | } 56 | [CCode (cname = "udev_enumerate_new")] 57 | public Enumerate create_enumerate (); 58 | [CCode (cname = "udev_queue_new")] 59 | public Queue? create_queue (); 60 | /** 61 | * Create new udev monitor and connect to a specified event source. Valid 62 | * sources identifiers are "udev" and "kernel". 63 | * 64 | * Applications should usually not connect directly to the "kernel" events, 65 | * because the devices might not be useable at that time, before udev has 66 | * configured them, and created device nodes. Accessing devices at the same 67 | * time as udev, might result in unpredictable behavior. The "udev" events 68 | * are sent out after udev has finished its event processing, all rules 69 | * have been processed, and needed device nodes are created. 70 | */ 71 | [CCode (cname = "udev_monitor_new_from_netlink")] 72 | public Monitor? monitor_from_netlink (string name = "udev"); 73 | /** 74 | * Create a new udev monitor and connect to a specified socket. 75 | * 76 | * The path to a socket either points to an existing socket file, or if the 77 | * socket path starts with a '@' character, an abstract namespace socket 78 | * will be used. 79 | * 80 | * A socket file will not be created. If it does not already exist, it will 81 | * fall-back and connect to an abstract namespace socket with the given 82 | * path. The permissions adjustment of a socket file, as well as the later 83 | * cleanup, needs to be done by the caller. 84 | */ 85 | [Deprecated] 86 | [CCode (cname = "udev_monitor_new_from_socket")] 87 | public Monitor? monitor_from_socket (string socket_path); 88 | /** 89 | * Create new udev device, and fill in information from the current process 90 | * environment. 91 | * 92 | * This only works reliable if the process is called from a udev rule. It 93 | * is usually used for tools executed from IMPORT= rules. 94 | */ 95 | [CCode (cname = "udev_device_new_from_environment")] 96 | public Device? new_from_environment (); 97 | /** 98 | * Create new udev device, and fill in information from the sys device and 99 | * the udev database entry by its major/minor number and type. 100 | * 101 | * Character and block device numbers are not unique across the two types. 102 | * @param type 'c' for character devices or 'b' for block devices. 103 | */ 104 | [CCode (cname = "udev_device_new_from_devnum")] 105 | public Device? open_devnum (char type, Posix.dev_t devnum); 106 | /** 107 | * Create new udev device, and fill in information from the sys device 108 | * and the udev database entry. The device is looked up by the subsystem 109 | * and name string of the device, like "mem" / "zero", or "block" / "sda". 110 | */ 111 | [CCode (cname = "udev_device_new_from_subsystem_sysname")] 112 | public Device? open_subsystem_sysname (string subsystem, string sysname); 113 | /** 114 | * Create new udev device, and fill in information from the sys device and 115 | * the udev database entry. 116 | * 117 | * The syspath is the absolute path to the device, including the sys mount 118 | * point. 119 | */ 120 | [CCode (cname = "udev_device_new_from_syspath")] 121 | public Device? open_syspath (string syspath); 122 | /** 123 | * Take a reference of the udev library context. 124 | */ 125 | [CCode (cname = "udev_ref")] 126 | public void ref (); 127 | /** 128 | * The error logging function. 129 | * 130 | * The built-in logging writes to stderr. It can be overridden by a custom 131 | * function, to plug log messages into the users' logging functionality. 132 | */ 133 | [CCode (cname = "udev_set_log_fn")] 134 | public void set_logger (Logger logger); 135 | 136 | /** 137 | * Drop a reference of the udev library context. 138 | */ 139 | [CCode (cname = "udev_unref")] 140 | public void unref (); 141 | } 142 | 143 | /** 144 | * Kernel sys devices 145 | * 146 | * Representation of kernel sys devices. Devices are uniquely identified by 147 | * their syspath, every device has exactly one path in the kernel sys 148 | * filesystem. Devices usually belong to a kernel subsystem, and and have a 149 | * unique name inside that subsystem. 150 | */ 151 | [CCode (cname = "struct udev_device", ref_function = "udev_device_ref", unref_function = "udev_device_unref", has_type_id = false)] 152 | public class Device { 153 | /** 154 | * The action if the device was received through a monitor. 155 | * 156 | * Devices read from sys do not have an action string. Usual actions are: add, remove, change, online, offline. 157 | */ 158 | public string? action { 159 | [CCode (cname = "udev_device_get_action")] 160 | get; 161 | } 162 | 163 | /** 164 | * An indexable collection of sys attrs 165 | */ 166 | public SysAttr attr { 167 | [CCode (cname = "")] 168 | get; 169 | } 170 | /** 171 | * The udev library context with which the device was created. 172 | */ 173 | public Context context { 174 | [CCode (cname = "udev_device_get_udev")] 175 | get; 176 | } 177 | /** 178 | * The list of device links pointing to the device file of the udev device. 179 | */ 180 | public List? devlinks { 181 | [CCode (cname = "udev_device_get_devlinks_list_entry")] 182 | get; 183 | } 184 | /** 185 | * Retrieve the device node file name belonging to the udev device. 186 | * 187 | * The path is an absolute path, and starts with the device directory. 188 | */ 189 | public string? devnode { 190 | [CCode (cname = "udev_device_get_devnode")] 191 | get; 192 | } 193 | /** 194 | * The the device major/minor number 195 | */ 196 | public Posix.dev_t devnum { 197 | [CCode (cname = "udev_device_get_devnum")] 198 | get; 199 | } 200 | /** 201 | * Retrieve the kernel devpath value of the udev device. 202 | * 203 | * The path does not contain the sys mount point, and starts with a '/'. 204 | */ 205 | public string devpath { 206 | [CCode (cname = "udev_device_get_devpath")] 207 | get; 208 | } 209 | /** 210 | * The devtype name of the device, if it can be determined. 211 | */ 212 | public string? devtype { 213 | [CCode (cname = "udev_device_get_devtype")] 214 | get; 215 | } 216 | /** 217 | * Get the name of the driver, if one is attached. 218 | */ 219 | public string? driver { 220 | [CCode (cname = "udev_device_get_driver")] 221 | get; 222 | } 223 | /** 224 | * Has already handled the device and has set up device node permissions 225 | * and context, or has renamed a network device? 226 | * 227 | * This is only implemented for devices with a device node or network 228 | * interfaces. All other devices return true. 229 | */ 230 | public bool is_initialized { 231 | [CCode (cname = "udev_device_get_is_initialized")] 232 | get; 233 | } 234 | /** 235 | * Find the next parent device, and fill in information from the sys device 236 | * and the udev database entry. 237 | * 238 | * It is not necessarily just the upper level directory, empty or not 239 | * recognized sys directories are ignored. 240 | */ 241 | public Device? parent { 242 | [CCode (cname = "udev_device_get_parent")] 243 | get; 244 | } 245 | /** 246 | * The list of key/value device properties of the udev device. 247 | */ 248 | public List? properties { 249 | [CCode (cname = "udev_device_get_properties_list_entry")] 250 | get; 251 | } 252 | /** 253 | * The sequence number 254 | * 255 | * This is only valid if the device was received through a monitor. Devices read from sys do not have a sequence number. 256 | */ 257 | public uint64 seqnum { 258 | [CCode (cname = "udev_device_get_seqnum")] 259 | get; 260 | } 261 | /** 262 | * The subsystem string of the device, if it can be determined. 263 | * 264 | * This string will not contain /. 265 | */ 266 | public string? subsystem { 267 | [CCode (cname = "udev_device_get_subsystem")] 268 | get; 269 | } 270 | /** 271 | * The list of available sysattrs, with value being empty. 272 | * 273 | * This just return all available sysfs attributes for a particular device 274 | * without reading their values. 275 | */ 276 | public List sysattr { 277 | [CCode (cname = "udev_device_get_sysattr_list_entry")] 278 | get; 279 | } 280 | /** 281 | * The sys name of the device device 282 | */ 283 | public string sysname { 284 | [CCode (cname = "udev_device_get_sysname")] 285 | get; 286 | } 287 | /** 288 | * The trailing number of of the device name 289 | */ 290 | public string sysnum { 291 | [CCode (cname = "udev_device_get_sysnum")] 292 | get; 293 | } 294 | /** 295 | * Retrieve the absolute sys path of the udev device starting with the sys mount point. 296 | */ 297 | public string syspath { 298 | [CCode (cname = "udev_device_get_syspath")] 299 | get; 300 | } 301 | /** 302 | * The list of tags attached to the udev device 303 | */ 304 | public List? tags { 305 | [CCode (cname = "udev_device_get_tags_list_entry")] 306 | get; 307 | } 308 | /** 309 | * The number of microseconds passed since udev set up the device for the 310 | * first time. 311 | * 312 | * This is only implemented for devices with need to store properties 313 | * in the udev database. All other devices are 0. 314 | */ 315 | public uint64 usec_since_initialized { 316 | [CCode (cname = "udev_device_get_usec_since_initialized")] 317 | get; 318 | } 319 | /** 320 | * Get the value of a device property, if one exists. 321 | */ 322 | [CCode (cname = "udev_device_get_property_value")] 323 | public unowned string? get (string key); 324 | /** 325 | * Find the next parent device, with a matching subsystem and devtype 326 | * value, and fill in information from the sys device and the udev database 327 | * entry. 328 | * 329 | * @param devtype the type of the device, or null to match any. 330 | */ 331 | [CCode (cname = "udev_device_get_parent_with_subsystem_devtype")] 332 | public unowned Device? get_parent (string subsystem, string? devtype = null); 333 | [CCode (cname = "udev_device_has_tag")] 334 | public bool has_tag (string tag); 335 | /** 336 | * Take a reference of a udev device. 337 | */ 338 | [CCode (cname = "udev_device_ref")] 339 | public void ref (); 340 | /** 341 | * Drop a reference of a udev device. 342 | */ 343 | [CCode (cname = "udev_device_unref")] 344 | public void unref (); 345 | } 346 | 347 | /** 348 | * Search sysfs for specific devices and provide a sorted list 349 | */ 350 | [CCode (cname = "struct udev_enumerate", ref_function = "udev_enumerate_ref", unref_function = "udev_enumerate_unref", has_type_id = false)] 351 | public class Enumerate { 352 | /** 353 | * The udev library context. 354 | */ 355 | public Context context { 356 | [CCode (cname = "udev_enumerate_get_udev")] 357 | get; 358 | } 359 | /** 360 | * The sorted list of device paths. 361 | */ 362 | public List? entries { 363 | [CCode (cname = "udev_enumerate_get_list_entry")] 364 | get; 365 | } 366 | /** 367 | * Match only devices which udev has set up already. 368 | * 369 | * This makes sure, that the device node permissions and context are 370 | * properly set and that network devices are fully renamed. 371 | * 372 | * Usually, devices which are found in the kernel but not already handled 373 | * by udev, have still pending events. Services should subscribe to monitor 374 | * events and wait for these devices to become ready, instead of using 375 | * uninitialized devices. 376 | * @return false on success 377 | */ 378 | [CCode (cname = "udev_enumerate_add_match_is_initialized")] 379 | public bool add_match_is_initialized (); 380 | /** 381 | * Return the devices on the subtree of one given device. 382 | * 383 | * The parent itself is included in the list. 384 | * @return false on success 385 | */ 386 | [CCode (cname = "udev_enumerate_add_match_parent")] 387 | public bool add_match_parent (Device parent); 388 | /** 389 | * Filter for a property of the device to include in the list 390 | * @return false on success 391 | */ 392 | [CCode (cname = "udev_enumerate_add_match_property")] 393 | public bool add_match_property (string property, string @value); 394 | /** 395 | * Filter for a subsystem of the device to include in the list 396 | * @return false on success 397 | */ 398 | [CCode (cname = "udev_enumerate_add_match_subsystem")] 399 | public bool add_match_subsystem (string subsystem); 400 | /** 401 | * Filter for a sys attribute at the device to include in the list 402 | * @return false on success 403 | */ 404 | [CCode (cname = "udev_enumerate_add_match_sysattr")] 405 | public bool add_match_sysattr (string sysattr, string @value); 406 | /** 407 | * Filter for the name of the device to include in the list 408 | * @return false on success 409 | */ 410 | [CCode (cname = "udev_enumerate_add_match_sysname")] 411 | public bool add_match_sysname (string sysname); 412 | /** 413 | * Filter for a tag of the device to include in the list 414 | * @return false on success 415 | */ 416 | [CCode (cname = "udev_enumerate_add_match_tag")] 417 | public bool add_match_tag (string tag); 418 | /** 419 | * Filter for a subsystem of the device to exclude from the list 420 | * @return false on success 421 | */ 422 | [CCode (cname = "udev_enumerate_add_nomatch_subsystem")] 423 | public bool add_nomatch_subsystem (string subsystem); 424 | /** 425 | * Filter for a sys attribute at the device to exclude from the list 426 | * @return false on success 427 | */ 428 | [CCode (cname = "udev_enumerate_add_nomatch_sysattr")] 429 | public bool add_nomatch_sysattr (string sysattr, string @value); 430 | /** 431 | * Add a device to the list of devices, to retrieve it back sorted in dependency order. 432 | * @return false on success 433 | */ 434 | [CCode (cname = "udev_enumerate_add_syspath")] 435 | public bool add_syspath (string syspath); 436 | /** 437 | * Take a reference of a enumeration context. 438 | */ 439 | [CCode (cname = "udev_enumerate_ref")] 440 | public void ref (); 441 | /** 442 | * Run enumeration with active filters 443 | * @return false on success 444 | */ 445 | [CCode (cname = "udev_enumerate_scan_devices")] 446 | public bool scan_devices (); 447 | /** 448 | * Run enumeration with active filters 449 | * @return false on success 450 | */ 451 | [CCode (cname = "udev_enumerate_scan_subsystems")] 452 | public bool scan_subsystems (); 453 | /** 454 | * Drop a reference of an enumeration context. 455 | */ 456 | [CCode (cname = "udev_enumerate_unref")] 457 | public void unref (); 458 | } 459 | 460 | [CCode (cname = "struct udev_list_entry", free_function = "")] 461 | [Compact] 462 | public class List { 463 | [CCode (cname = "udev_list_entry_get_by_name")] 464 | public List? get (string name); 465 | public string name { 466 | [CCode (cname = "udev_list_entry_get_name")] 467 | get; 468 | } 469 | public List? next { 470 | [CCode (cname = "udev_list_entry_get_next")] 471 | get; 472 | } 473 | public string @value { 474 | [CCode (cname = "udev_list_entry_get_value")] 475 | get; 476 | } 477 | } 478 | 479 | /** 480 | * Connection to a device event source. 481 | */ 482 | [CCode (cname = "struct udev_monitor", ref_function = "udev_monitor_ref", unref_function = "udev_monitor_unref", has_type_id = false)] 483 | public class Monitor { 484 | /** 485 | * The udev library context with which the monitor was created. 486 | */ 487 | public Context context { 488 | [CCode (cname = "udev_monitor_get_udev")] 489 | get; 490 | } 491 | 492 | /** 493 | * The socket file descriptor associated with the monitor. 494 | */ 495 | public int fd { 496 | [CCode (cname = "udev_monitor_get_fd")] 497 | get; 498 | } 499 | 500 | /** 501 | * This filter is efficiently executed inside the kernel, and libudev 502 | * subscribers will usually not be woken up for devices which do not match. 503 | * 504 | * The filter must be installed before the monitor is switched to listening mode. 505 | * @return false on success 506 | */ 507 | [CCode (cname = "udev_monitor_filter_add_match_subsystem_devtype")] 508 | public bool add_match_subsystem_devtype (string subsystem, string? devtype = null); 509 | /** 510 | * This filter is efficiently executed inside the kernel, and libudev 511 | * subscribers will usually not be woken up for devices which do not match. 512 | * 513 | * The filter must be installed before the monitor is switched to listening mode. 514 | * @return false on success 515 | */ 516 | [CCode (cname = "udev_monitor_filter_add_match_tag")] 517 | public bool add_match_tag (string tag); 518 | /** 519 | * Binds the monitor socket to the event source. 520 | * @return false on success 521 | */ 522 | [CCode (cname = "udev_monitor_enable_receiving")] 523 | public bool enable_receiving (); 524 | /** 525 | * Receive data from the udev monitor socket, allocate a new udev device, 526 | * fill in the received data, and return the device. 527 | * 528 | * Only socket connections with uid=0 are accepted. 529 | * @return a new udev device, or null, in case of an error 530 | */ 531 | [CCode (cname = "udev_monitor_receive_device")] 532 | public Device? receive_device (); 533 | /** 534 | * Take a reference of a udev monitor. 535 | */ 536 | [CCode (cname = "udev_monitor_ref")] 537 | public void ref (); 538 | /** 539 | * Remove all filters from monitor. 540 | * @return false on success 541 | */ 542 | [CCode (cname = "udev_monitor_filter_remove")] 543 | public bool remove_filter (); 544 | /** 545 | * Set the size of the kernel socket buffer. 546 | * 547 | * This call needs the appropriate privileges to succeed. 548 | * @return false on success 549 | */ 550 | [CCode (cname = "udev_monitor_set_receive_buffer_size")] 551 | public bool set_receive_buffer_size (int size); 552 | /** 553 | * Drop a reference of a udev monitor. 554 | */ 555 | [CCode (cname = "udev_monitor_unref")] 556 | public void unref (); 557 | /** 558 | * Update the installed socket filter. 559 | * 560 | * This is only needed, if the filter was removed or changed. 561 | * @return false on success 562 | */ 563 | [CCode (cname = "udev_monitor_filter_update")] 564 | public bool update_filter (); 565 | } 566 | /** 567 | * Access to currently active events 568 | * 569 | * The udev daemon processes events asynchronously. All events which do not 570 | * have interdependencies run in parallel. This exports the current state of 571 | * the event processing queue, and the current event sequence numbers from 572 | * the kernel and the udev daemon. 573 | */ 574 | [CCode (cname = "struct udev_queue", ref_function = "udev_queue_ref", unref_function = "udev_queue_unref", has_type_id = false)] 575 | public class Queue { 576 | /** 577 | * The udev library context with which the queue context was created. 578 | */ 579 | public Context context { 580 | [CCode (cname = "udev_queue_get_udev")] 581 | get; 582 | } 583 | /** 584 | * The list of queued events. 585 | */ 586 | public List? events { 587 | [CCode (cname = "udev_queue_get_queued_list_entry")] 588 | get; 589 | } 590 | public bool is_active { 591 | [CCode (cname = "udev_queue_get_udev_is_active")] 592 | get; 593 | } 594 | public bool is_empty { 595 | [CCode (cname = "udev_queue_get_queue_is_empty")] 596 | get; 597 | } 598 | /** 599 | * The current kernel event sequence number. 600 | */ 601 | public uint64 kernel_seqnum { 602 | [CCode (cname = "udev_queue_get_kernel_seqnum")] 603 | get; 604 | } 605 | /** 606 | * The last known udev event sequence number. 607 | */ 608 | public uint64 udev_seqnum { 609 | [CCode (cname = "udev_queue_get_udev_seqnum")] 610 | get; 611 | } 612 | /** 613 | * Indicates whether the given sequence number is currently active. 614 | */ 615 | [CCode (cname = "udev_queue_get_seqnum_is_finished")] 616 | public bool is_finished (uint64 seqnum); 617 | /** 618 | * Indicates if any of the sequence numbers in the given range is currently active. 619 | */ 620 | [CCode (cname = "udev_queue_get_seqnum_sequence_is_finished")] 621 | public bool is_sequence_finished (uint64 start, uint64 end); 622 | /** 623 | * Take a reference of a udev queue context. 624 | */ 625 | [CCode (cname = "udev_queue_ref")] 626 | public void ref (); 627 | /** 628 | * Drop a reference of a udev queue context. 629 | */ 630 | [CCode (cname = "udev_queue_unref")] 631 | public void unref (); 632 | } 633 | /** 634 | * Internal class to make sysattrs easy to access 635 | */ 636 | [CCode (cname = "struct udev_device", ref_function = "udev_device_ref", unref_function = "udev_device_unref", has_type_id = false)] 637 | public class SysAttr { 638 | /** 639 | * The content of a sys attribute file, null if there is a sys attribute value. 640 | * 641 | * The retrieved value is cached in the device. Repeated calls will return the same 642 | * value and not open the attribute again. 643 | */ 644 | [CCode (cname = "udev_device_get_sysattr_value")] 645 | public unowned string? get (string sysattr); 646 | } 647 | 648 | public delegate void Logger (Context udev, int priority, string file, int line, string fn, string format, va_list args); 649 | 650 | /** 651 | * Encode all potentially unsafe characters of a string to the corresponding 2 char hex value prefixed by '\x'. 652 | * @param buffer the output buffer to store the string which might be four times the length of the input. 653 | * @return true on error 654 | */ 655 | [CCode (cname = "udev_util_encode_string")] 656 | public bool encode_string (string str, char[] buffer); 657 | } 658 | -------------------------------------------------------------------------------- /libvlc.deps: -------------------------------------------------------------------------------- 1 | x11 2 | -------------------------------------------------------------------------------- /llvm.deps: -------------------------------------------------------------------------------- 1 | posix 2 | -------------------------------------------------------------------------------- /mount.deps: -------------------------------------------------------------------------------- 1 | posix 2 | -------------------------------------------------------------------------------- /tests/Makefile: -------------------------------------------------------------------------------- 1 | SOURCES = $(wildcard test-*.vala) 2 | 3 | all: $(patsubst test-%.vala, %-test, $(SOURCES)) 4 | 5 | %-test: test-%.vala test-%.flags ../%.vapi 6 | valac -o $@ --vapidir .. --pkg $* $< --save-temps $(shell cat test-$*.flags) 7 | -------------------------------------------------------------------------------- /tests/bdbtest.flags: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apmasell/vapis/dabbad36957441bd49f8c04738a72b7875d4bfea/tests/bdbtest.flags -------------------------------------------------------------------------------- /tests/bdbtest.vala: -------------------------------------------------------------------------------- 1 | using BerkeleyDB; 2 | 3 | public void main() { 4 | 5 | BerkeleyDB.Environment e; 6 | BerkeleyDB.Environment.create(out e); 7 | } 8 | -------------------------------------------------------------------------------- /tests/test-blkid.flags: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apmasell/vapis/dabbad36957441bd49f8c04738a72b7875d4bfea/tests/test-blkid.flags -------------------------------------------------------------------------------- /tests/test-blkid.vala: -------------------------------------------------------------------------------- 1 | using BlkId; 2 | void main() { 3 | Cache? c; 4 | Cache.open(out c); 5 | c.probe_all(); 6 | foreach (var d in c) { 7 | stdout.printf("%s\n", d.name); 8 | } 9 | 10 | var devname = "/dev/sda1"; 11 | var pr = Prober.open(devname); 12 | if (pr == null) 13 | error("%s: failed to open device", devname); 14 | 15 | pr.partition_filter.enabled = true; 16 | pr.do_full_probe(); 17 | 18 | unowned uint8[] name; 19 | pr.lookup_value("PTTYPE", out name); 20 | stdout.printf("%s partition type detected\n", (string)name); 21 | } 22 | -------------------------------------------------------------------------------- /tests/test-cookie.flags: -------------------------------------------------------------------------------- 1 | -X -D_GNU_SOURCE=1 -X -DGFileSeek=int 2 | -------------------------------------------------------------------------------- /tests/test-cookie.vala: -------------------------------------------------------------------------------- 1 | const int INIT_BUF_SIZE = 4; 2 | 3 | struct memfile_cookie { 4 | public memfile_cookie() { 5 | buf = new uint8[1000]; 6 | endpos = 0; 7 | offset = 0; 8 | } 9 | uint8[] buf; 10 | size_t endpos; 11 | ssize_t offset; 12 | } 13 | 14 | ssize_t memfile_write(memfile_cookie? cookie, [CCode(array_length_type = "size_t")] uint8[]?buf) { 15 | if (buf == null) 16 | return 0; 17 | 18 | /* Buffer too small? Keep doubling size until big enough */ 19 | 20 | while (buf.length + cookie.offset > cookie.buf.length) { 21 | cookie.buf.resize(cookie.buf.length * 2); 22 | if (cookie.buf == null) { 23 | return -1; 24 | } 25 | } 26 | 27 | Memory.copy(&cookie.buf[cookie.offset], buf, buf.length); 28 | cookie.offset += buf.length; 29 | if (cookie.offset > cookie.endpos) 30 | cookie.endpos = cookie.offset; 31 | return buf.length; 32 | } 33 | 34 | ssize_t memfile_read(memfile_cookie? cookie,[CCode(array_length_type = "size_t")] uint8[]?buf) { 35 | ssize_t xbytes; 36 | 37 | if (buf == null) 38 | return 0; 39 | /* Fetch minimum of bytes requested and bytes available */ 40 | 41 | xbytes = buf.length; 42 | if (cookie.offset + buf.length > cookie.endpos) 43 | xbytes = (ssize_t)cookie.endpos - cookie.offset; 44 | if (xbytes < 0) /* offset may be past endpos */ 45 | xbytes = 0; 46 | 47 | Memory.copy(buf, &cookie.buf[cookie.offset], xbytes); 48 | 49 | cookie.offset += xbytes; 50 | return xbytes; 51 | } 52 | 53 | int memfile_seek(memfile_cookie? cookie, ref int64 offset, FileSeek whence) { 54 | int64 new_offset; 55 | 56 | if (whence == FileSeek.SET) 57 | new_offset = offset; 58 | else if (whence == FileSeek.END) 59 | new_offset = cookie.endpos + offset; 60 | else if (whence == FileSeek.CUR) 61 | new_offset = cookie.offset + offset; 62 | else 63 | return -1; 64 | 65 | if (new_offset < 0) 66 | return -1; 67 | 68 | cookie.offset = (ssize_t) new_offset; 69 | offset = new_offset; 70 | return 0; 71 | } 72 | 73 | int memfile_close(owned memfile_cookie? cookie) { 74 | return 0; 75 | } 76 | 77 | int main(string[] args) { 78 | Cookie.io_functions memfile_func = {}; 79 | memfile_func.read = memfile_read; 80 | memfile_func.write = memfile_write; 81 | memfile_func.seek = memfile_seek; 82 | memfile_func.close = memfile_close; 83 | memfile_cookie mycookie = memfile_cookie(); 84 | ssize_t nread; 85 | uint8 buf[1000]; 86 | 87 | var fp = Cookie.open(mycookie, "w+", memfile_func); 88 | if (fp == null) { 89 | return 1; 90 | } 91 | 92 | /* Write command-line arguments to our file */ 93 | 94 | foreach(var arg in args) { 95 | fp.puts(arg); 96 | } 97 | 98 | /* Read two bytes out of every five, until EOF */ 99 | 100 | for (var p = 0; ; p += 5) { 101 | if (fp.seek(p, FileSeek.SET) == -1) { 102 | return 3; 103 | } 104 | nread = (ssize_t) fp.read(buf); 105 | if (nread == -1) { 106 | return 4; 107 | } 108 | if (nread == 0) { 109 | stdout.printf("Reached end of file\n"); 110 | break; 111 | } 112 | 113 | stdout.printf("/%.*s/\n", nread, buf); 114 | } 115 | 116 | return 0; 117 | } 118 | 119 | -------------------------------------------------------------------------------- /tests/test-fcgi.flags: -------------------------------------------------------------------------------- 1 | -X -lfcgi 2 | -------------------------------------------------------------------------------- /tests/test-fcgi.vala: -------------------------------------------------------------------------------- 1 | static void PrintEnv(FastCGI.Stream @out, string label, FastCGI.parameters envp) 2 | { 3 | @out.printf( "%s:
\n
\n", label);
 4 |     foreach(var s in envp.get_all()) {
 5 |         @out.printf("%s\n", s);
 6 |     }
 7 |     @out.printf( "

\n"); 8 | } 9 | 10 | int main () 11 | { 12 | FastCGI.Stream @in; 13 | FastCGI.Stream @out; 14 | FastCGI.Stream @err; 15 | unowned FastCGI.parameters envp; 16 | int count = 0; 17 | 18 | while (FastCGI.accept(out @in, out @out, out @err, out @envp) >= 0) { 19 | string contentLength = envp["CONTENT_LENGTH"]; 20 | 21 | @out.printf( 22 | "Content-type: text/html\r\n\r\nFastCGI echo (fcgiapp version)

FastCGI echo (fcgiapp version)

\nRequest number %d, Process ID: %d

\n", ++count, 3); 23 | 24 | if (contentLength != null) 25 | @out.printf("No data from standard input.

\n"); 26 | 27 | PrintEnv(@out, "Request environment", envp); 28 | } /* while */ 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /tests/test-hidapi.flags: -------------------------------------------------------------------------------- 1 | $(for each in $(pkg-config --cflags --libs hidapi-libusb); do echo -X "$each"; done) 2 | 3 | -------------------------------------------------------------------------------- /tests/test-hidapi.vala: -------------------------------------------------------------------------------- 1 | int main(string[] args) { 2 | int res; 3 | if (!HidApi.init()) 4 | return -1; 5 | 6 | var dev = HidApi.Info.enumerate(0x0, 0x0); 7 | for(; dev != null; dev = (owned) dev.next) { 8 | stdout.printf("Device Found\n type: %04hx %04hx\n path: %s\n serial_number: %s", dev.vendor_id, dev.product_id, dev.path, dev.serial_number_str); 9 | stdout.printf("\n"); 10 | stdout.printf(" Manufacturer: %s\n", dev.manufacturer); 11 | stdout.printf(" Product: %s\n", dev.product); 12 | stdout.printf(" Release: %hx\n", dev.release_number); 13 | stdout.printf(" Interface: %d\n", dev.interface_number); 14 | stdout.printf("\n"); 15 | } 16 | 17 | var handle = HidApi.Device.open(0x0, 0x0, null); 18 | if (handle == null) { 19 | stderr.printf("unable to open device\n"); 20 | HidApi.exit(); 21 | return 1; 22 | } 23 | 24 | stdout.printf("Manufacturer String: %s\n", handle.manufacturer); 25 | stdout.printf("Product String: %s\n", handle.product); 26 | stdout.printf("Serial Number String: %s\n", handle.serial_number); 27 | stdout.printf("Indexed String 1: %s\n", handle[1]); 28 | 29 | handle.set_nonblocking(true); 30 | 31 | uint8 buf[17]; 32 | res = handle.read(buf); 33 | 34 | res = handle.send_feature_report(buf); 35 | if (res < 0) { 36 | stderr.printf("Unable to send a feature report: %s\n", handle.error); 37 | } 38 | 39 | res = handle.get_feature_report(buf); 40 | if (res < 0) { 41 | stderr.printf("Unable to get a feature report: %s\n", handle.error); 42 | } else { 43 | stdout.printf("Feature Report\n "); 44 | for (var i = 0; i < res; i++) 45 | stdout.printf("%02hhx ", buf[i]); 46 | stdout.printf("\n"); 47 | } 48 | 49 | res = handle.write(buf); 50 | if (res < 0) { 51 | stderr.printf("Unable to write(): %s\n", handle.error); 52 | } 53 | 54 | res = 0; 55 | while (res == 0) { 56 | res = handle.read(buf); 57 | if (res == 0) 58 | stderr.printf("Waiting...\n"); 59 | if (res < 0) 60 | stderr.printf("Unable to read(): %s\n", handle.error); 61 | } 62 | 63 | stdout.printf("Data read:\n "); 64 | for (var i = 0; i < res; i++) 65 | stdout.printf("%02hhx ", buf[i]); 66 | stdout.printf("\n"); 67 | 68 | handle = null; 69 | 70 | HidApi.exit(); 71 | return 0; 72 | } 73 | -------------------------------------------------------------------------------- /tests/test-libelf.flags: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apmasell/vapis/dabbad36957441bd49f8c04738a72b7875d4bfea/tests/test-libelf.flags -------------------------------------------------------------------------------- /tests/test-libelf.vala: -------------------------------------------------------------------------------- 1 | void main() { 2 | var f = Posix.open("/bin/ls", Posix.O_RDONLY); 3 | var d = Elf.Desc.open(f, Elf.Command.READ); 4 | } 5 | -------------------------------------------------------------------------------- /tests/test-libgit2.flags: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apmasell/vapis/dabbad36957441bd49f8c04738a72b7875d4bfea/tests/test-libgit2.flags -------------------------------------------------------------------------------- /tests/test-libgit2.vala: -------------------------------------------------------------------------------- 1 | using Git; 2 | string foo(Git.Commit c) { 3 | return c.id.to_string() ?? "?"; 4 | } 5 | 6 | void bar (Git.Object o) { 7 | unowned Git.Commit c = (Git.Commit) o; 8 | Git.Option.set_search_path(ConfigLevel.GLOBAL, "/foo"); 9 | stdout.puts(Git.Option.get_search_path(ConfigLevel.GLOBAL)); 10 | } 11 | 12 | void test(Git.Repository repo) { 13 | string[] attrs = { "crlf", "diff", "foo" }; 14 | string[] res; 15 | repo.attributes.lookup_many(Git.AttrCheck.FILE_THEN_INDEX, "my/fun/file.c", attrs, out res); 16 | } 17 | 18 | 19 | public static int main( string []args ) 20 | { 21 | Repository repo; 22 | Repository.open(out repo, "../.git"); 23 | 24 | repo.for_each_branch(Git.BranchType.LOCAL, callback); 25 | 26 | return 0; 27 | } 28 | public int callback (string branch_name, BranchType branch_type) 29 | { 30 | stdout.puts(branch_name); 31 | return 0; 32 | } 33 | 34 | public void walk_test (Git.Tree tree) { 35 | tree.walk(WalkMode.PRE, (root, entry) => {stdout.printf("root: %s\n", root);return Git.Error.OK;}); 36 | } 37 | -------------------------------------------------------------------------------- /tests/test-libpcap.flags: -------------------------------------------------------------------------------- 1 | $(for each in $(pcap-config --cflags --libs); do echo -X "$each"; done) 2 | -------------------------------------------------------------------------------- /tests/test-libpcap.vala: -------------------------------------------------------------------------------- 1 | PCap.Capture? c; 2 | void main() { 3 | var err = new char[PCap.ERRBUF_SIZE]; 4 | var cap1 = PCap.Capture.create("wlan0", err); 5 | var cap = PCap.Capture.open_live("wlan0", 0, true, 60, err); 6 | if (cap == null) { 7 | stderr.printf("%s\n", (string)err); 8 | return; 9 | } 10 | c = cap; 11 | stderr.printf("Success\n"); 12 | cap.loop(-1, (header, data) => { 13 | stdout.printf("Got packet caplen = %d\n", header.caplen); 14 | }); 15 | var f = FileStream.open("foo", "r"); 16 | if (f == null) return; 17 | var st = PCap.Capture.open_offline_stream((owned) f, err); 18 | c = st; 19 | c = null; 20 | } 21 | -------------------------------------------------------------------------------- /tests/test-libpipeline.flags: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apmasell/vapis/dabbad36957441bd49f8c04738a72b7875d4bfea/tests/test-libpipeline.flags -------------------------------------------------------------------------------- /tests/test-libpipeline.vala: -------------------------------------------------------------------------------- 1 | void main() { 2 | var p = new Pipe.Line.command_args ("true"); 3 | assert(Pipe.run((owned)p) == 0); 4 | p = new Pipe.Line.command_args ("false"); 5 | assert(Pipe.run((owned)p) != 0); 6 | 7 | p = new Pipe.Line.command_args ("echo", "foo"); 8 | p.want_out = -1; 9 | assert (p[0].num_args == 2); 10 | p.start(); 11 | var line = p.read_line(); 12 | assert (line == "foo\n"); 13 | assert (p.wait() == 0); 14 | 15 | p = new Pipe.Line.command_args ("echo", "foo", "bar"); 16 | p.want_out = -1; 17 | assert (p[0].num_args == 3); 18 | p.start(); 19 | line = p.read_line(); 20 | assert (line == "foo bar\n"); 21 | assert(p.wait() == 0); 22 | 23 | p = new Pipe.Line(); 24 | p.add_args("echo", "foo"); 25 | p.add_args("sed", "-e", "s/foo/bar/"); 26 | p.want_out = -1; 27 | p.start(); 28 | line = p.read_line(); 29 | assert (line == "bar\n"); 30 | assert (p.wait() == 0); 31 | 32 | p = new Pipe.Line(); 33 | p.add_args("sh", "-c", "exit 2"); 34 | p.add_args("sh", "-c", "exit 3"); 35 | p.add_args("true"); 36 | p.start(); 37 | int[] statuses; 38 | assert(p.wait_all(out statuses) == 127); 39 | assert(statuses.length == 3); 40 | assert(statuses[0] == 2 * 256); 41 | assert(statuses[1] == 3 * 256); 42 | assert(statuses[2] == 0); 43 | 44 | p = new Pipe.Line.command_args ("sh", "-c", "exit $TEST1"); 45 | p[0]["TEST1"] = "10"; 46 | assert(Pipe.run((owned)p) == 10); 47 | 48 | p = new Pipe.Line.command_args ("sh", "-c", "echo $TEST2"); 49 | p[0]["TEST2"] = "foo"; 50 | p.want_out = -1; 51 | p.start(); 52 | line = p.read_line(); 53 | assert(line == "foo\n"); 54 | p.wait(); 55 | 56 | p = new Pipe.Line.command_args("sh", "-c", "echo $TEST2"); 57 | p[0].unset("TEST2"); 58 | p.want_out = -1; 59 | p.start(); 60 | line = p.read_line(); 61 | assert(line == "\n"); 62 | p.wait(); 63 | 64 | p = new Pipe.Line(); 65 | var cmd1 = new Pipe.Command.args ("echo", "foo"); 66 | var cmd2 = new Pipe.Command.args ("echo", "bar"); 67 | var cmd3 = new Pipe.Command.args ("echo", "baz"); 68 | var seq = new Pipe.Command.sequence ("echo*3", cmd1, cmd2, cmd3); 69 | p.add((owned)seq); 70 | p.add_args("xargs"); 71 | p.want_out = -1; 72 | p.start(); 73 | line = p.read_line(); 74 | assert(line == "foo bar baz\n"); 75 | p.wait(); 76 | } 77 | 78 | -------------------------------------------------------------------------------- /tests/test-libqrencode.flags: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apmasell/vapis/dabbad36957441bd49f8c04738a72b7875d4bfea/tests/test-libqrencode.flags -------------------------------------------------------------------------------- /tests/test-libqrencode.vala: -------------------------------------------------------------------------------- 1 | void main() { 2 | QR.Code? q = QR.Code.encode_string("hello, world", 0, QR.ECLevel.L, QR.Mode.EIGHT_BIT, true); 3 | stdout.printf("Is %snull\n", q == null ? "" : "not "); 4 | stdout.printf("Width: %d\n", q.width); 5 | for (var x = 0; x < q.width; x++) { 6 | for (var y = 0; y < q.width; y++) { 7 | stdout.putc(q[x, y] ? 'X' : ' '); 8 | } 9 | stdout.putc('\n'); 10 | } 11 | 12 | 13 | QR.List? l = QR.List.encode_string("hello, world", 0, QR.ECLevel.L, QR.Mode.EIGHT_BIT, true); 14 | stdout.printf("Is %snull\n", l == null ? "" : "not "); 15 | stdout.printf("Size: %d\n", l.size); 16 | for (unowned QR.List? c = l; c != null; c = c.next) { 17 | stdout.printf("%d\n", c.code.width); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /tests/test-libssh2.flags: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apmasell/vapis/dabbad36957441bd49f8c04738a72b7875d4bfea/tests/test-libssh2.flags -------------------------------------------------------------------------------- /tests/test-libssh2.vala: -------------------------------------------------------------------------------- 1 | /* 2 | * Sample showing how to do SSH2 connect. 3 | * 4 | * The sample code has default values for host name, user name, password 5 | * and path to copy, but you can specify them on the command line like: 6 | * 7 | * "ssh2 host user password [-p|-i|-k]" 8 | */ 9 | string keyfile1; 10 | string keyfile2; 11 | string username; 12 | string password; 13 | 14 | 15 | void kbd_callback(uint8[] name, uint8[]instruction, 16 | SSH2.keyboard_prompt[] prompts, 17 | SSH2.keyboard_response[] responses, 18 | ref bool b) 19 | { 20 | if (prompts.length == 1) { 21 | responses[0].text = password.data; 22 | } 23 | } 24 | 25 | 26 | int main(string[] args) 27 | { 28 | string home=GLib.Environment.get_home_dir(); 29 | keyfile1=home+"/.ssh/id_rsa.pub"; 30 | keyfile2=home+"/.ssh/id_rsa"; 31 | username="username"; 32 | password="password"; 33 | 34 | uint32 hostaddr; 35 | if (args.length > 1) { 36 | hostaddr = Posix.inet_addr(args[1]); 37 | } else { 38 | hostaddr = Posix.htonl(0x7F000001); 39 | } 40 | 41 | if(args.length > 2) { 42 | username = args[2]; 43 | } 44 | if(args.length > 3) { 45 | password = args[3]; 46 | } 47 | 48 | var rc = SSH2.init (0); 49 | if (rc != SSH2.Error.NONE) { 50 | stdout.printf ("libssh2 initialization failed (%d)\n", rc); 51 | return 1; 52 | } 53 | 54 | /* Ultra basic "connect to port 22 on localhost". Your code is 55 | * responsible for creating the socket establishing the connection 56 | */ 57 | var sock = Posix.socket(Posix.AF_INET, Posix.SOCK_STREAM, 0); 58 | 59 | Posix.SockAddrIn sin = Posix.SockAddrIn(); 60 | sin.sin_family = Posix.AF_INET; 61 | sin.sin_port = Posix.htons(22); 62 | sin.sin_addr.s_addr = hostaddr; 63 | if (Posix.connect(sock, &sin, 64 | sizeof(Posix.SockAddrIn)) != 0) { 65 | stderr.printf("failed to connect!\n"); 66 | return -1; 67 | } 68 | 69 | /* Create a session instance and start it up. This will trade welcome 70 | * banners, exchange keys, and setup crypto, compression, and MAC layers 71 | */ 72 | var session = SSH2.Session.create(); 73 | if (session.handshake(sock) != SSH2.Error.NONE) { 74 | stderr.printf("Failure establishing SSH session\n"); 75 | return -1; 76 | } 77 | 78 | /* At this point we havn't authenticated. The first thing to do is check 79 | * the hostkey's fingerprint against our known hosts Your app may have it 80 | * hard coded, may go to a file, may present it to the user, that's your 81 | * call 82 | */ 83 | var fingerprint = session.get_host_key_hash(SSH2.HashType.SHA1); 84 | stdout.printf("Fingerprint: "); 85 | for(var i = 0; i < 20; i++) { 86 | stdout.printf("%02X ", fingerprint[i]); 87 | } 88 | stdout.printf("\n"); 89 | 90 | /* check what authentication methods are available */ 91 | int auth_pw = 0; 92 | var userauthlist = session.list_authentication(username.data); 93 | stdout.printf("Authentication methods: %s\n", userauthlist); 94 | if ( "password" in userauthlist) { 95 | auth_pw |= 1; 96 | } 97 | if ( "keyboard-interactive" in userauthlist) { 98 | auth_pw |= 2; 99 | } 100 | if ( "publickey" in userauthlist) { 101 | auth_pw |= 4; 102 | } 103 | 104 | /* if we got an 4. argument we set this option if supported */ 105 | if(args.length > 4) { 106 | if ((auth_pw & 1) != 0 && args[4] == "-p") { 107 | auth_pw = 1; 108 | } 109 | if ((auth_pw & 2) != 0&& args[4] == "-i") { 110 | auth_pw = 2; 111 | } 112 | if ((auth_pw & 4) != 0 && args[4] == "-k") { 113 | auth_pw = 4; 114 | } 115 | } 116 | 117 | if ((auth_pw & 1)!=0) { 118 | /* We could authenticate via password */ 119 | if (session.auth_password(username, password) != SSH2.Error.NONE) { 120 | stdout.printf("\tAuthentication by password failed!\n"); 121 | session.disconnect( "Normal Shutdown, Thank you for playing"); 122 | session = null; 123 | Posix.close(sock); 124 | return 1; 125 | } else { 126 | stdout.printf("\tAuthentication by password succeeded.\n"); 127 | } 128 | } else if ((auth_pw & 2) != 0) { 129 | /* Or via keyboard-interactive */ 130 | if (session.auth_keyboard_interactive(username, (SSH2.Session.KeyboardInteractiveHandler)kbd_callback) != SSH2.Error.NONE) { 131 | stdout.printf("\tAuthentication by keyboard-interactive failed!\n"); 132 | session.disconnect( "Normal Shutdown, Thank you for playing"); 133 | session = null; 134 | Posix.close(sock); 135 | return 1; 136 | } else { 137 | stdout.printf("\tAuthentication by keyboard-interactive succeeded.\n"); 138 | } 139 | } else if ((auth_pw & 4)!=0) { 140 | /* Or by public key */ 141 | if (session.auth_publickey_from_file(username, keyfile1, keyfile2, password) != SSH2.Error.NONE) { 142 | stdout.printf("\tAuthentication by public key failed!\n"); 143 | session.disconnect( "Normal Shutdown, Thank you for playing"); 144 | session = null; 145 | Posix.close(sock); 146 | return 1; 147 | } else { 148 | stdout.printf("\tAuthentication by public key succeeded.\n"); 149 | } 150 | } else { 151 | stdout.printf("No supported authentication methods found!\n"); 152 | session.disconnect( "Normal Shutdown, Thank you for playing"); 153 | session = null; 154 | Posix.close(sock); return 1; 155 | } 156 | 157 | /* Request a shell */ 158 | SSH2.Channel? channel = null; 159 | if (session.authenticated && (channel = session.open_channel()) == null) { 160 | stderr.printf("Unable to open a session\n"); 161 | } else { 162 | 163 | /* Some environment variables may be set, 164 | * It's up to the server which ones it'll allow though 165 | */ 166 | channel.set_env("FOO", "bar"); 167 | 168 | /* Request a terminal with 'vanilla' terminal emulation 169 | * See /etc/termcap for more options 170 | */ 171 | if (channel.request_pty("vanilla".data) != SSH2.Error.NONE) { 172 | stderr.printf("Failed requesting pty\n"); 173 | session.disconnect( "Normal Shutdown, Thank you for playing"); 174 | session = null; 175 | Posix.close(sock); 176 | } 177 | 178 | /* Open a SHELL on that pty */ 179 | if (channel.start_shell() != SSH2.Error.NONE) { 180 | stderr.printf("Unable to request shell on allocated pty\n"); 181 | session.disconnect( "Normal Shutdown, Thank you for playing"); 182 | session = null; 183 | Posix.close(sock); 184 | } 185 | 186 | /* At this point the shell can be interacted with using 187 | * libssh2_channel_read() 188 | * libssh2_channel_read_stderr() 189 | * libssh2_channel_write() 190 | * libssh2_channel_write_stderr() 191 | * 192 | * Blocking mode may be (en|dis)abled with: libssh2_channel_set_blocking() 193 | * If the server send EOF, libssh2_channel_eof() will return non-0 194 | * To send EOF to the server use: libssh2_channel_send_eof() 195 | * A channel can be closed with: libssh2_channel_close() 196 | * A channel can be freed with: libssh2_channel_free() 197 | */ 198 | 199 | channel = null; 200 | } 201 | /* Other channel types are supported via: 202 | * libssh2_scp_send() 203 | * libssh2_scp_recv() 204 | * libssh2_channel_direct_tcpip() 205 | */ 206 | 207 | session.disconnect( "Normal Shutdown, Thank you for playing"); 208 | session = null; 209 | Posix.close(sock); 210 | stdout.printf("all done!\n"); 211 | 212 | SSH2.exit(); 213 | 214 | return 0; 215 | } 216 | -------------------------------------------------------------------------------- /tests/test-libudev.flags: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apmasell/vapis/dabbad36957441bd49f8c04738a72b7875d4bfea/tests/test-libudev.flags -------------------------------------------------------------------------------- /tests/test-libudev.vala: -------------------------------------------------------------------------------- 1 | void main() { 2 | var ctxt = new UDev.Context(); 3 | var e = ctxt.create_enumerate(); 4 | e.add_match_subsystem("net"); 5 | e.scan_devices(); 6 | for(unowned UDev.List d = e.entries; d != null; d = d.next) { 7 | var path = d.name; 8 | var dev = ctxt.open_syspath(path); 9 | //dev = dev.get_parent("pci", "usb_device"); 10 | if (dev == null) { 11 | stderr.printf("Could not get parent\n"); 12 | return; 13 | } 14 | stdout.printf("VID/PID: %s %s\n", dev.attr["idVendor"], dev.attr["idProduct"]); 15 | stdout.printf(" %s %s\n", dev.attr["manufacturer"], dev.attr["product"]); 16 | stdout.printf(" serial: %s\n", dev.attr["serial"]); 17 | } 18 | 19 | var m = ctxt.monitor_from_netlink(); 20 | 21 | m.add_match_subsystem_devtype("hidraw"); 22 | m.enable_receiving(); 23 | 24 | } 25 | -------------------------------------------------------------------------------- /tests/test-libvlc.flags: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apmasell/vapis/dabbad36957441bd49f8c04738a72b7875d4bfea/tests/test-libvlc.flags -------------------------------------------------------------------------------- /tests/test-libvlc.vala: -------------------------------------------------------------------------------- 1 | using VLC; 2 | 3 | void main() { 4 | var inst = Instance.create(); 5 | var m = inst.open_media_path("http://mycool.movie.com/test.mov"); 6 | var mp = m.create_player(); 7 | 8 | mp.play(); 9 | mp.stop(); 10 | } 11 | -------------------------------------------------------------------------------- /tests/test-mount.flags: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apmasell/vapis/dabbad36957441bd49f8c04738a72b7875d4bfea/tests/test-mount.flags -------------------------------------------------------------------------------- /tests/test-mount.vala: -------------------------------------------------------------------------------- 1 | void main() { 2 | var fstab = new Mount.Table(); 3 | fstab.parse_fstab(); 4 | var it = new Mount.Iter(Mount.Direction.FORWARD); 5 | unowned Mount.FileSystem? fs; 6 | while(fstab.next(it, out fs) == 0) { 7 | stdout.printf("%s → %s : %s\n", fs.source, fs.target, fs.fstype); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /tests/test-opencl.flags: -------------------------------------------------------------------------------- 1 | -X -I/usr/include/nvidia-current -X -L/usr/include/nvidia-current -X -lOpenCL 2 | -------------------------------------------------------------------------------- /tests/test-opencl.vala: -------------------------------------------------------------------------------- 1 | using OpenCL; 2 | public void foo(CommandQueue queue) { 3 | uint8[] buffer; 4 | queue.get_info_auto(CommandQueue.Info.CONTEXT, out buffer); 5 | } 6 | 7 | void main() { 8 | } 9 | -------------------------------------------------------------------------------- /tests/test-tricks.flags: -------------------------------------------------------------------------------- 1 | -X -I.. 2 | -------------------------------------------------------------------------------- /tests/test-tricks.vala: -------------------------------------------------------------------------------- 1 | void main() { 2 | int a = 1; 3 | int b = 2; 4 | 5 | stdout.printf("%d %d\n", a, b); 6 | swap(ref a, ref b); 7 | stdout.printf("%d %d\n", a, b); 8 | double x = 1.1; 9 | double y = 2.1; 10 | 11 | stdout.printf("%f %f\n", x, y); 12 | swap(ref x, ref y); 13 | stdout.printf("%f %f\n", x, y); 14 | } 15 | -------------------------------------------------------------------------------- /tokyodystopia.deps: -------------------------------------------------------------------------------- 1 | tokyocabinet 2 | -------------------------------------------------------------------------------- /tokyodystopia.vapi: -------------------------------------------------------------------------------- 1 | [CCode (cheader_filename = "dystopia.h")] 2 | namespace TokyoDystopia { 3 | [CCode (cname = "uint32_t", cprefix = "IDBX")] 4 | [Flags] 5 | public enum ExOptions { 6 | /** 7 | * No text mode 8 | */ 9 | NOTXT 10 | } 11 | [CCode (cname = "int", cprefix = "IDBO")] 12 | [Flags] 13 | public enum Open { 14 | /** 15 | * Connect as a reader 16 | */ 17 | READER, 18 | /** 19 | * Connect as a writer 20 | */ 21 | WRITER, 22 | /** 23 | * Creates a new database if not exist 24 | * @see WRITER 25 | */ 26 | CREAT, 27 | /** 28 | * Creates a new database regardless if one exists 29 | * @see WRITER 30 | */ 31 | TRUNC, 32 | /** 33 | * Opens the database directory without file locking 34 | */ 35 | NOLCK, 36 | /** 37 | * Locking is performed without blocking 38 | */ 39 | LCKNB 40 | } 41 | 42 | [CCode (cname = "uint8_t", cprefix = "IDBT")] 43 | [Flags] 44 | public enum Options { 45 | /** 46 | * The size of the database can be larger than 2GB by using 64-bit bucket array 47 | */ 48 | LARGE, 49 | /** 50 | * Each page is compressed with Deflate encoding 51 | */ 52 | DEFLATE, 53 | /** 54 | * Each page is compressed with BZIP2 encoding 55 | */ 56 | BZIP, 57 | /** 58 | * Each page is compressed with TCBS encoding 59 | */ 60 | TCBS 61 | } 62 | 63 | [CCode (cname = "int", cprefix = "IDBS")] 64 | [Flags] 65 | public enum Search { 66 | /** 67 | * Substring matching 68 | */ 69 | SUBSTR, 70 | /** 71 | * Prefix matching 72 | */ 73 | PREFIX, 74 | /** 75 | * Suffix matching 76 | */ 77 | SUFFIX, 78 | /** 79 | * Full matching 80 | */ 81 | FULL, 82 | /** 83 | * Token matching 84 | */ 85 | TOKEN, 86 | /** 87 | * Token prefix matching 88 | */ 89 | TOKPRE, 90 | /** 91 | * Token suffix matching 92 | */ 93 | TOKSUF 94 | } 95 | 96 | [CCode (cname = "TCIDB", free_function = "tcidbdel")] 97 | [Compact] 98 | public class Index { 99 | [CCode (cname = "tcidbnew")] 100 | public Index (); 101 | 102 | /** 103 | * The number of records of an indexed database object. 104 | */ 105 | public uint64 count { 106 | [CCode (cname = "tcidbrnum")] 107 | get; 108 | } 109 | /** 110 | * The file descriptor for debugging output. 111 | */ 112 | public int debug_fd { 113 | [CCode (cname = "tcidbsetdbgfd")] 114 | set; 115 | [CCode (cname = "tcidbdbgfd")] 116 | get; 117 | } 118 | /** 119 | * Get the last happened error code of an indexed database object. 120 | */ 121 | public TokyoCabinet.ErrorCode error { 122 | [CCode (cname = "tcidbecode")] 123 | get; 124 | } 125 | /** 126 | * The expert options of an indexed database object. 127 | */ 128 | public ExOptions ex_opts { 129 | [CCode (cname = "tcidbsetexopts")] 130 | get; 131 | } 132 | /** 133 | * The inode number of the database directory of an indexed database object. 134 | */ 135 | public uint64 inode { 136 | [CCode (cname = "tcidbinode")] 137 | get; 138 | } 139 | /** 140 | * The modification time of the database directory of an indexed database object. 141 | */ 142 | public time_t mtime { 143 | [CCode (cname = "tcidbmtime")] 144 | get; 145 | } 146 | /** 147 | * The options of an indexed database object. 148 | */ 149 | public Options opts { 150 | [CCode (cname = "tcidbopts")] 151 | get; 152 | } 153 | /** 154 | * The directory path of an indexed database object. 155 | * 156 | * Null if the object does not connect to any database directory. 157 | */ 158 | public string? path { 159 | [CCode (cname = "tcidbpath")] 160 | get; 161 | } 162 | /** 163 | * Get the total size of the database files of an indexed database object. 164 | */ 165 | public uint64 size { 166 | [CCode (cname = "tcidbfsiz")] 167 | get; 168 | } 169 | /** 170 | * Close an indexed database object. 171 | * 172 | * Update of a database is assured to be written when the database is closed. If a writer opens 173 | a database but does not close it appropriately, the database will be broken. 174 | */ 175 | [CCode (cname = "tcidbclose")] 176 | public bool close (); 177 | /** 178 | * Copy the database directory of an indexed database object. 179 | * 180 | * The database directory is assured to be kept synchronized and not modified while the copying or executing operation is in progress. So, this function is useful to create a backup directory of the database directory. 181 | * @param path specifies the path of the destination directory. If it begins with '''@''', the trailing substring is executed as a command line. 182 | * @return If successful, the return value is true, else, it is false. False is returned if the executed command returns non-zero code. 183 | */ 184 | [CCode (cname = "tcidbcopy")] 185 | public bool copy (string path); 186 | /** 187 | * Initialize the iterator of an indexed database object. 188 | * 189 | * The iterator is used in order to access the ID number of every record stored in a database. 190 | * @return If successful, the return value is true, else, it is false. 191 | */ 192 | [CCode (cname = "tcidbiterinit")] 193 | public bool iter_init (); 194 | /** 195 | * Get the next ID number of the iterator of an indexed database object. 196 | * 197 | * It is possible to access every record by iteration of calling this function. It is allowed to update or remove records whose keys are fetched while the iteration. However, it is not assured if updating the database is occurred while the iteration. Besides, the order of this traversal access method is arbitrary, so it is not assured that the order of storing matches the one of the traversal access. 198 | * @return If successful, the return value is the ID number of the next record, else, it is 0. 0 is returned when no record is to be get out of the iterator. 199 | */ 200 | [CCode (cname = "tcidbiternext")] 201 | public uint64 iter_next (); 202 | /** 203 | * Retrieve a record of an indexed database object. 204 | * @param id specifies the ID number of the record. It should be positive. 205 | * @return If successful, the return value is the string of the corresponding record, else, it is null. 206 | */ 207 | [CCode (cname = "tcidbget")] 208 | public string? get (int64 id); 209 | /** 210 | * Synchronize updating contents on memory of an indexed database object. 211 | * @param level specifies the synchronization lavel; 0 means cache synchronization, 1 means database synchronization, and 2 means file synchronization. 212 | * @return If successful, the return value is true, else, it is false. 213 | */ 214 | [CCode (cname = "tcidbmemsync")] 215 | public bool mem_sync (int level); 216 | /** 217 | * Open an indexed database object. 218 | * @param path specifies the path of the database directory. 219 | * @return If successful, the return value is true, else, it is false. 220 | */ 221 | [CCode (cname = "tcidbopen")] 222 | public bool open (string path, Open mode); 223 | /** 224 | * Optimize the files of an indexed database object. 225 | * 226 | * This function is useful to reduce the size of the database files with data fragmentation by successive updating. 227 | * @return If successful, the return value is true, else, it is false. 228 | */ 229 | [CCode (cname = "tcidboptimize")] 230 | public bool optimize (); 231 | /** 232 | * Remove a record of an indexed database object. 233 | * @param id specifies the ID number of the record. It should be positive. 234 | * @return If successful, the return value is true, else, it is false. 235 | */ 236 | [CCode (cname = "tcidbout")] 237 | public bool remove (int64 id); 238 | /** 239 | * Search an indexed database. 240 | * @param word specifies the string of the word to be matched to. 241 | * @return If successful, the return value is the pointer to an array of ID numbers of the corresponding records. Null is returned on failure. 242 | */ 243 | [CCode (cname = "tcidbsearch")] 244 | public uint64[]? search (string word, Search smode); 245 | /** 246 | * Search an indexed database with a compound expression. 247 | * @param expr specifies the string of the compound expression. 248 | * @return If successful, the return value is the pointer to an array of ID numbers of the corresponding records. Null is returned on failure. 249 | */ 250 | [CCode (cname = "tcidbsearch2")] 251 | public uint64[]? search_expr (string expr); 252 | /** 253 | * Store a record into an indexed database object. 254 | * @param id specifies the ID number of the record. It should be positive. 255 | * @param text specifies the string of the record, whose encoding should be UTF-8. 256 | * @return If successful, true, else, false. 257 | */ 258 | [CCode (cname = "tcidbput")] 259 | bool set (int64 id, string text); 260 | /** 261 | * Set the callback function for sync progression of an indexed database object. 262 | */ 263 | [CCode (cname = "tcidbsetsynccb")] 264 | void set_sync_cb (SyncCallback cb); 265 | /** 266 | * Synchronize updated contents of an indexed database object with the files and the device. 267 | * 268 | * This function is useful when another process connects the same database directory. 269 | * @return If successful, the return value is true, else, it is false. 270 | */ 271 | [CCode (cname = "tcidbsync")] 272 | public bool sync (); 273 | /** 274 | * Set the tuning parameters of an indexed database object. 275 | * 276 | * Note that the tuning parameters should be set before the database is opened. 277 | * @param ernum specifies the expected number of records to be stored. If it is not more than 0, the default value is specified. The default value is 1000000. 278 | * @param etnum specifies the expected number of tokens to be stored. If it is not more than 0, the default value is specified. The default value is 1000000. 279 | * @param iusiz specifies the unit size of each index file. If it is not more than 0, the default value is specified. The default value is 536870912. 280 | * 281 | If successful, the return value is true, else, it is false. 282 | */ 283 | [CCode (cname = "tcidbtune")] 284 | public bool tune (int64 ernum, int64 etnum, int64 iusiz, Options opts); 285 | /** 286 | * Remove all records of an indexed database object. 287 | * @return If successful, the return value is true, else, it is false. 288 | */ 289 | [CCode (cname = "tcidbvanish")] 290 | public bool vanish (); 291 | } 292 | /** 293 | * Get the message string corresponding to an error code. 294 | */ 295 | [CCode (cname = "tcidberrmsg")] 296 | public unowned string err_msg (TokyoCabinet.ErrorCode ecode); 297 | 298 | /** 299 | * Sync progression callback. 300 | * @param num_tokens the number of tokens to be synchronized 301 | * @param num_processed the number of processed tokens 302 | * @param message the message string. 303 | * @return Should be true usually, or false if the sync operation should be terminated. 304 | */ 305 | public delegate bool SyncCallback (int num_tokens, int num_processed, string message); 306 | } 307 | -------------------------------------------------------------------------------- /tricks.h: -------------------------------------------------------------------------------- 1 | #ifndef VALA_BUFFER_H 2 | #define VALA_BUFFER_H 3 | #define BDB_FREE(instance) (instance)->close((instance), 0) 4 | #define TRICKY_MEAN(x,y) (((x) & (y)) + (((x) ^ (y)) >> 1)) 5 | #define TRICK_FUNC() __func__ 6 | #define OBJECT_TO_BUFFER(val,type,size) (*(size) = sizeof(type), (guint8*)val) 7 | #define OBJECT_ARRAY_TO_BUFFER(val,len,type,size) (*(size) = sizeof(type)*(len), (guint8*)val) 8 | #define OBJECT_ARRAY_TO_ARRAY(val,len,typea,typeb,size) (*(size) = sizeof(typea)*(len)/sizeof(typeb), (void*)val) 9 | #define OBJECT_ARRAY_FROM_BUFFER(val,len,type,size) (*(size) = (len)/sizeof(type), (void*)val) 10 | #define BUFFER_SUB_CHUNK(val,len,idx,size) (((idx) < (len)) ? (*(size) = (len) - (idx), &(val)[(idx)]) : (*(size) = 0, NULL)) 11 | 12 | typedef gsize (*InitialisationFunction)(void*); 13 | #define ONCE_MERGE_(a,b) a##b 14 | #define ONCE_LABEL_(a) ONCE_MERGE_(initval__, a) 15 | #define ONCE_UNIQUE_NAME ONCE_LABEL_(__LINE__) 16 | #define ONCE(res,func,data) do { static volatile gsize ONCE_UNIQUE_NAME = 0; if (g_once_init_enter (&ONCE_UNIQUE_NAME)) g_once_init_leave (&ONCE_UNIQUE_NAME, func(data)); *res = ONCE_UNIQUE_NAME; } while (0) 17 | #define STRINGIFY(x) #x 18 | #define VPTR(instance, ...) instance->VPTR_METHOD(instance , ## __VA_ARGS__) 19 | #define VALA_SWAP(a, b, t) do { t _swap_temp = *(a); *(a) = *(b); *(b) = _swap_temp; } while (0) 20 | #endif 21 | -------------------------------------------------------------------------------- /tricks.vapi: -------------------------------------------------------------------------------- 1 | [CCode (cheader_filename = "tricks.h")] 2 | namespace Buffer { 3 | /** 4 | * Create a buffer representation of a particular object. 5 | */ 6 | [CCode (generic_type_pos = 1.1, cname = "OBJECT_TO_BUFFER")] 7 | public unowned uint8[] of (ref T @value); 8 | /** 9 | * Create a buffer representation of an array of objects. 10 | */ 11 | [CCode (generic_type_pos = 1.9, cname = "OBJECT_ARRAY_TO_BUFFER")] 12 | public unowned uint8[] of_array (T[] @value); 13 | /** 14 | * Convert an array of one type to another, where the new array length is the 15 | * maximum number of items that could be stored in the new array given the 16 | * type of the old array. 17 | */ 18 | [CCode (generic_type_pos = 1.9, cname = "OBJECT_ARRAY_TO_ARRAY")] 19 | public unowned U[] change_array (T[] @value); 20 | /** 21 | * Convert an array to a array of objects. 22 | */ 23 | [CCode (generic_type_pos = 1.9, cname = "OBJECT_ARRAY_FROM_BUFFER")] 24 | public unowned T[] from_array (uint8[] @value); 25 | 26 | [CCode (cname = "BUFFER_SUB_CHUNK")] 27 | public unowned uint8[]? index (uint8[] buffer, int index); 28 | } 29 | 30 | [CCode (cname = "InitialisationFunction", cheader_filename = "tricks.h", has_type_id = false)] 31 | public delegate size_t InitialisationFunction (); 32 | 33 | [CCode (cname = "TRICK_FUNC", cheader_filename = "tricks.h")] 34 | public unowned string c_func (); 35 | 36 | /** 37 | * Call a function once and cache the result. 38 | * 39 | * Calls a function once, which returns a non-zero value and caches the 40 | * result. The same once block can be enetered many times, with different 41 | * parameters, and the result will always be the same. 42 | * 43 | * This is thread-safe. 44 | */ 45 | [CCode (cname = "ONCE", cheader_filename = "tricks.h")] 46 | public void once (out size_t @value, InitialisationFunction func); 47 | 48 | /** 49 | * Compute the mean of two numbers without overflow. 50 | * 51 | * For use only with integer types. If you do this with anything else, you're going to have a bad time. 52 | */ 53 | [CCode (cname = "TRICKY_MEAN", cheader_filename = "tricks.h", simple_generics = true)] 54 | public T mean (T x, T y); 55 | 56 | /** 57 | * Swap two values. 58 | */ 59 | [CCode (cname = "VALA_SWAP", cheader_filename = "tricks.h", generic_type_pos = 2.1)] 60 | public void swap (ref T a, ref T b); 61 | -------------------------------------------------------------------------------- /u2f-host.vapi: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2013-2015 Yubico AB 3 | 4 | This program is free software; you can redistribute it and/or modify it 5 | under the terms of the GNU Lesser General Public License as published by 6 | the Free Software Foundation; either version 2.1, or (at your option) any 7 | later version. 8 | 9 | This program is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 12 | General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public License 15 | along with this program; if not, see . 16 | */ 17 | [CCode (cheader_filename = "u2f-host/u2f-host.h")] 18 | namespace U2F.Host { 19 | 20 | namespace Version { 21 | 22 | [CCode (cname = "U2FH_VERSION_STRING")] 23 | public const string STRING; 24 | 25 | [CCode (cname = "U2FH_VERSION_NUMBER")] 26 | public const int NUMBER; 27 | 28 | [CCode (cname = "U2FH_VERSION_MAJOR")] 29 | public const int MAJOR; 30 | 31 | [CCode (cname = "U2FH_VERSION_MINOR")] 32 | public const int MINOR; 33 | 34 | [CCode (cname = "U2FH_VERSION_PATCH")] 35 | public const int PATCH; 36 | 37 | [CCode (cname = "u2fh_check_version")] 38 | public unowned string? check_version (string version = STRING); 39 | } 40 | 41 | [CCode (cname = "u2fh_cmdflags", cprefix = "U2FH_")] 42 | [Flags] 43 | public enum Commands 44 | { 45 | REQUEST_USER_PRESENCE 46 | } 47 | 48 | [CCode (cname = "u2fh_rc", cprefix = "U2FH_")] 49 | public enum Error 50 | { 51 | OK, 52 | MEMORY_ERROR, 53 | TRANSPORT_ERROR, 54 | JSON_ERROR, 55 | BASE64_ERROR, 56 | NO_U2F_DEVICE, 57 | AUTHENTICATOR_ERROR; 58 | [CCode (cname = "u2fh_strerror")] 59 | public unowned string get_message (); 60 | [CCode (cname = "u2fh_strerror_name")] 61 | public unowned string get_name (); 62 | } 63 | [CCode (cname = "u2fh_initflags", cprefix = "U2FH_")] 64 | [Flags] 65 | public enum Init 66 | { 67 | DEBUG 68 | } 69 | 70 | [CCode (cname = "u2fh_global_init")] 71 | public Error init (Init flags); 72 | [CCode (cname = "u2fh_global_done")] 73 | public void done (); 74 | 75 | [CCode (cname = "u2fh_devs", free_function = "u2fh_devs_done")] 76 | [Compact] 77 | public class Devices { 78 | 79 | [CCode (cname = "u2fh_devs_init")] 80 | public Error init (out Devices? devs); 81 | 82 | [CCode (cname = "u2fh_authenticate")] 83 | public Error authenticate (string challenge, string origin, out string? response, Commands flags); 84 | 85 | [CCode (cname = "u2fh_devs_discover")] 86 | public Error discover (out uint max_index); 87 | 88 | public Error get_description ( 89 | uint index, out uint8[] buffer, 90 | size_t max_len) { 91 | var len = max_len; 92 | buffer = new uint8[max_len]; 93 | Error err = _get_description (index, buffer, ref len); 94 | buffer.length = (int) len; 95 | return err; 96 | } 97 | 98 | [CCode (cname = "u2fh_is_alive")] 99 | public bool is_alive (uint index); 100 | 101 | [CCode (cname = "u2fh_register")] 102 | public Error register (string challenge, string origin, char** response, Commands flags); 103 | 104 | [CCode (cname = "u2fh_sendrecv")] 105 | public Error sendrecv (uint index, uint8 cmd, [CCode (array_length_type = "uint16_t")] 106 | uint8[] send, [CCode (array_length_type = "uint16_t")] 107 | uint8[] recv); 108 | 109 | [CCode (cname = "u2fh_get_device_description")] 110 | private Error _get_description (uint index, [CCode (array_length = false)] uint8[] buffer, ref size_t len); 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /u2f-server.vapi: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Yubico AB 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are 7 | * met: 8 | * 9 | * * Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 12 | * * Redistributions in binary form must reproduce the above 13 | * copyright notice, this list of conditions and the following 14 | * disclaimer in the documentation and/or other materials provided 15 | * with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | [CCode (cheader_filename = "u2f-server/u2f-server.h")] 30 | namespace U2F.Server { 31 | namespace Version { 32 | [CCode (cname = "U2FS_VERSION_STRING")] 33 | public const string STRING; 34 | [CCode (cname = "U2FS_VERSION_NUMBER")] 35 | public const int NUMBER; 36 | [CCode (cname = "U2FS_VERSION_MAJOR")] 37 | public const int MAJOR; 38 | [CCode (cname = "U2FS_VERSION_MINOR")] 39 | public const int MINOR; 40 | [CCode (cname = "U2FS_VERSION_PATCH")] 41 | public const int PATCH; 42 | 43 | [CCode (cname = "u2fs_check_version")] 44 | unowned string? check (string req_version = STRING); 45 | } 46 | [CCode (cname = "U2FS_CHALLENGE_RAW_LEN")] 47 | public const int CHALLENGE_RAW_LEN; 48 | [CCode (cname = "U2FS_CHALLENGE_B64U_LEN")] 49 | public const int CHALLENGE_B64U_LEN; 50 | [CCode (cname = "U2FS_PUBLIC_KEY_LEN")] 51 | public const int PUBLIC_KEY_LEN; 52 | [CCode (cname = "U2FS_COUNTER_LEN")] 53 | public const int COUNTER_LEN; 54 | 55 | [CCode (cname = "u2fs_rc", cprefix = "U2FS_")] 56 | public enum Error { 57 | OK, 58 | MEMORY_ERROR, 59 | JSON_ERROR, 60 | BASE64_ERROR, 61 | CRYPTO_ERROR, 62 | ORIGIN_ERROR, 63 | CHALLENGE_ERROR, 64 | SIGNATURE_ERROR, 65 | FORMAT_ERROR; 66 | [CCode (cname = "u2fs_strerror_name")] 67 | public unowned string get_name (); 68 | [CCode (cname = "u2fs_strerror")] 69 | public unowned string get_message (); 70 | } 71 | 72 | [CCode (cname = "u2fs_initflags")] 73 | [Flags] 74 | public enum Init { 75 | U2FS_DEBUG = 1 76 | } 77 | 78 | [CCode (cname = "u2fs_global_init")] 79 | public Error init (Init flags); 80 | [CCode (cname = "u2fs_global_done")] 81 | public void done (); 82 | 83 | [CCode (cname = "u2fs_ctx_t", free_function = "u2fs_done")] 84 | [Compact] 85 | public class Context { 86 | 87 | [CCode (cname = "u2fs_init")] 88 | public static Error init (out Context? ctx); 89 | [CCode (cname = "u2fs_set_origin")] 90 | public Error set_origin (string origin); 91 | [CCode (cname = "u2fs_set_appid")] 92 | public Error set_appid (string appid); 93 | [CCode (cname = "u2fs_set_challenge")] 94 | public Error set_challenge (string challenge); 95 | [CCode (cname = "u2fs_set_keyHandle")] 96 | public Error set_key_handle (string keyHandle); 97 | [CCode (cname = "u2fs_set_publicKey")] 98 | public Error set_publicKey (uint8 publicKey[16]); 99 | 100 | [CCode (cname = "u2fs_registration_challenge")] 101 | public Error registration_challenge (out string? output); 102 | [CCode (cname = "u2fs_registration_verify")] 103 | public Error registration_verify (string response, out RegisterResult? output); 104 | [CCode (cname = "u2fs_authentication_challenge")] 105 | public Error authentication_challenge (out string? output); 106 | 107 | [CCode (cname = "u2fs_authentication_verify")] 108 | public Error u2fs_authentication_verify (string response, out AuthResult? output); 109 | } 110 | [CCode (cname = "u2fs_reg_res_t", free_function = "u2fs_free_reg_res")] 111 | [Compact] 112 | public class RegisterResult { 113 | public string? key_handle { 114 | [CCode (cname = "u2fs_get_registration_keyHandle")] 115 | get; 116 | } 117 | public string? public_key { 118 | [CCode (cname = "u2fs_get_registration_publicKey")] 119 | get; 120 | } 121 | } 122 | [CCode (cname = "u2fs_auth_res_t", free_function = "u2fs_free_auth_res")] 123 | public class AuthResult { 124 | [CCode (cname = "u2fs_get_authentication_result")] 125 | public Error u2fs_get_authentication_result (out Error verified, out uint32 counter, out uint8 user_presence); 126 | } 127 | } 128 | --------------------------------------------------------------------------------