aboutsummaryrefslogtreecommitdiffstats
path: root/src/dma/vendor
diff options
context:
space:
mode:
Diffstat (limited to 'src/dma/vendor')
-rw-r--r--src/dma/vendor/github.com/BurntSushi/toml/.gitignore5
-rw-r--r--src/dma/vendor/github.com/BurntSushi/toml/.travis.yml15
-rw-r--r--src/dma/vendor/github.com/BurntSushi/toml/COMPATIBLE3
-rw-r--r--src/dma/vendor/github.com/BurntSushi/toml/COPYING14
-rw-r--r--src/dma/vendor/github.com/BurntSushi/toml/Makefile19
-rw-r--r--src/dma/vendor/github.com/BurntSushi/toml/README.md218
-rw-r--r--src/dma/vendor/github.com/BurntSushi/toml/cmd/toml-test-decoder/COPYING14
-rw-r--r--src/dma/vendor/github.com/BurntSushi/toml/cmd/toml-test-encoder/COPYING14
-rw-r--r--src/dma/vendor/github.com/BurntSushi/toml/cmd/tomlv/COPYING14
-rw-r--r--src/dma/vendor/github.com/BurntSushi/toml/decode.go509
-rw-r--r--src/dma/vendor/github.com/BurntSushi/toml/decode_meta.go121
-rw-r--r--src/dma/vendor/github.com/BurntSushi/toml/doc.go27
-rw-r--r--src/dma/vendor/github.com/BurntSushi/toml/encode.go568
-rw-r--r--src/dma/vendor/github.com/BurntSushi/toml/encoding_types.go19
-rw-r--r--src/dma/vendor/github.com/BurntSushi/toml/encoding_types_1.1.go18
-rw-r--r--src/dma/vendor/github.com/BurntSushi/toml/lex.go953
-rw-r--r--src/dma/vendor/github.com/BurntSushi/toml/parse.go592
-rw-r--r--src/dma/vendor/github.com/BurntSushi/toml/session.vim1
-rw-r--r--src/dma/vendor/github.com/BurntSushi/toml/type_check.go91
-rw-r--r--src/dma/vendor/github.com/BurntSushi/toml/type_fields.go242
-rw-r--r--src/dma/vendor/github.com/go-redis/redis/.gitignore2
-rw-r--r--src/dma/vendor/github.com/go-redis/redis/.travis.yml20
-rw-r--r--src/dma/vendor/github.com/go-redis/redis/CHANGELOG.md12
-rw-r--r--src/dma/vendor/github.com/go-redis/redis/LICENSE25
-rw-r--r--src/dma/vendor/github.com/go-redis/redis/Makefile20
-rw-r--r--src/dma/vendor/github.com/go-redis/redis/README.md146
-rw-r--r--src/dma/vendor/github.com/go-redis/redis/cluster.go1624
-rw-r--r--src/dma/vendor/github.com/go-redis/redis/cluster_commands.go22
-rw-r--r--src/dma/vendor/github.com/go-redis/redis/command.go1225
-rw-r--r--src/dma/vendor/github.com/go-redis/redis/commands.go2337
-rw-r--r--src/dma/vendor/github.com/go-redis/redis/doc.go4
-rw-r--r--src/dma/vendor/github.com/go-redis/redis/internal/consistenthash/consistenthash.go81
-rw-r--r--src/dma/vendor/github.com/go-redis/redis/internal/error.go83
-rw-r--r--src/dma/vendor/github.com/go-redis/redis/internal/hashtag/hashtag.go77
-rw-r--r--src/dma/vendor/github.com/go-redis/redis/internal/internal.go24
-rw-r--r--src/dma/vendor/github.com/go-redis/redis/internal/log.go15
-rw-r--r--src/dma/vendor/github.com/go-redis/redis/internal/once.go60
-rw-r--r--src/dma/vendor/github.com/go-redis/redis/internal/pool/conn.go80
-rw-r--r--src/dma/vendor/github.com/go-redis/redis/internal/pool/pool.go416
-rw-r--r--src/dma/vendor/github.com/go-redis/redis/internal/pool/pool_single.go53
-rw-r--r--src/dma/vendor/github.com/go-redis/redis/internal/pool/pool_sticky.go109
-rw-r--r--src/dma/vendor/github.com/go-redis/redis/internal/proto/reader.go316
-rw-r--r--src/dma/vendor/github.com/go-redis/redis/internal/proto/scan.go166
-rw-r--r--src/dma/vendor/github.com/go-redis/redis/internal/proto/write_buffer.go113
-rw-r--r--src/dma/vendor/github.com/go-redis/redis/internal/singleflight/singleflight.go64
-rw-r--r--src/dma/vendor/github.com/go-redis/redis/internal/util.go29
-rw-r--r--src/dma/vendor/github.com/go-redis/redis/internal/util/safe.go7
-rw-r--r--src/dma/vendor/github.com/go-redis/redis/internal/util/strconv.go19
-rw-r--r--src/dma/vendor/github.com/go-redis/redis/internal/util/unsafe.go12
-rw-r--r--src/dma/vendor/github.com/go-redis/redis/iterator.go73
-rw-r--r--src/dma/vendor/github.com/go-redis/redis/options.go203
-rw-r--r--src/dma/vendor/github.com/go-redis/redis/parser.go394
-rw-r--r--src/dma/vendor/github.com/go-redis/redis/pipeline.go113
-rw-r--r--src/dma/vendor/github.com/go-redis/redis/pubsub.go460
-rw-r--r--src/dma/vendor/github.com/go-redis/redis/redis.go501
-rw-r--r--src/dma/vendor/github.com/go-redis/redis/result.go140
-rw-r--r--src/dma/vendor/github.com/go-redis/redis/ring.go622
-rw-r--r--src/dma/vendor/github.com/go-redis/redis/script.go62
-rw-r--r--src/dma/vendor/github.com/go-redis/redis/sentinel.go343
-rw-r--r--src/dma/vendor/github.com/go-redis/redis/tx.go110
-rw-r--r--src/dma/vendor/github.com/go-redis/redis/universal.go151
-rw-r--r--src/dma/vendor/github.com/labstack/echo/.editorconfig25
-rw-r--r--src/dma/vendor/github.com/labstack/echo/.gitattributes20
-rw-r--r--src/dma/vendor/github.com/labstack/echo/.gitignore7
-rw-r--r--src/dma/vendor/github.com/labstack/echo/.travis.yml14
-rw-r--r--src/dma/vendor/github.com/labstack/echo/Gopkg.lock75
-rw-r--r--src/dma/vendor/github.com/labstack/echo/Gopkg.toml42
-rw-r--r--src/dma/vendor/github.com/labstack/echo/LICENSE21
-rw-r--r--src/dma/vendor/github.com/labstack/echo/Makefile17
-rw-r--r--src/dma/vendor/github.com/labstack/echo/README.md99
-rw-r--r--src/dma/vendor/github.com/labstack/echo/bind.go261
-rw-r--r--src/dma/vendor/github.com/labstack/echo/context.go576
-rw-r--r--src/dma/vendor/github.com/labstack/echo/echo.go781
-rw-r--r--src/dma/vendor/github.com/labstack/echo/group.go120
-rw-r--r--src/dma/vendor/github.com/labstack/echo/log.go40
-rw-r--r--src/dma/vendor/github.com/labstack/echo/response.go110
-rw-r--r--src/dma/vendor/github.com/labstack/echo/router.go434
-rw-r--r--src/dma/vendor/github.com/labstack/gommon/LICENSE22
-rw-r--r--src/dma/vendor/github.com/labstack/gommon/color/README.md86
-rw-r--r--src/dma/vendor/github.com/labstack/gommon/color/color.go407
-rw-r--r--src/dma/vendor/github.com/labstack/gommon/log/README.md5
-rw-r--r--src/dma/vendor/github.com/labstack/gommon/log/color.go13
-rw-r--r--src/dma/vendor/github.com/labstack/gommon/log/log.go415
-rw-r--r--src/dma/vendor/github.com/labstack/gommon/log/white.go12
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/.gitignore7
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/.gitpublish4
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/.travis.yml42
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/FAQ.md19
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/LICENSE21
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/README.md136
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/callbacks.go102
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/callbacks_wrapper.go39
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/callbacks_wrapper.h32
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/connect.go2998
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/connect_compat.h200
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/connect_wrapper.go1766
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/connect_wrapper.h730
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/doc.go141
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/domain.go4766
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/domain_compat.h914
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/domain_events.go1633
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/domain_events_wrapper.go259
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/domain_events_wrapper.h207
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/domain_snapshot.go240
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/domain_snapshot_wrapper.go215
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/domain_snapshot_wrapper.h102
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/domain_wrapper.go2330
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/domain_wrapper.h986
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/error.go604
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/error_compat.h166
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/events.go258
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/events_wrapper.go193
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/events_wrapper.h82
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/interface.go145
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/interface_wrapper.go158
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/interface_wrapper.h76
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/libvirtd.conf6
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/libvirtd.sasl2
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/lxc.go155
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/lxc_wrapper.go101
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/lxc_wrapper.h63
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/network.go335
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/network_compat.h86
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/network_events.go125
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/network_events_wrapper.go79
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/network_events_wrapper.h55
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/network_wrapper.go267
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/network_wrapper.h119
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/node_device.go192
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/node_device_compat.h55
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/node_device_events.go156
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/node_device_events_wrapper.go88
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/node_device_events_wrapper.h60
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/node_device_wrapper.go184
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/node_device_wrapper.h88
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/nwfilter.go118
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/nwfilter_binding.go125
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/nwfilter_binding_compat.h33
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/nwfilter_binding_wrapper.go132
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/nwfilter_binding_wrapper.h60
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/nwfilter_wrapper.go122
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/nwfilter_wrapper.h65
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/qemu.go189
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/qemu_compat.h57
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/qemu_wrapper.go133
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/qemu_wrapper.h78
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/secret.go184
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/secret_compat.h61
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/secret_events.go159
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/secret_events_wrapper.go88
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/secret_events_wrapper.h58
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/secret_wrapper.go175
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/secret_wrapper.h86
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/storage_pool.go394
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/storage_pool_compat.h92
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/storage_pool_events.go174
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/storage_pool_events_wrapper.go89
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/storage_pool_events_wrapper.h59
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/storage_pool_wrapper.go343
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/storage_pool_wrapper.h150
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/storage_volume.go290
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/storage_volume_compat.h78
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/storage_volume_wrapper.go249
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/storage_volume_wrapper.h116
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/stream.go418
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/stream_compat.h36
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/stream_wrapper.go331
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/stream_wrapper.h120
-rw-r--r--src/dma/vendor/github.com/libvirt/libvirt-go/typedparams.go262
-rw-r--r--src/dma/vendor/github.com/mattn/go-colorable/.travis.yml9
-rw-r--r--src/dma/vendor/github.com/mattn/go-colorable/LICENSE21
-rw-r--r--src/dma/vendor/github.com/mattn/go-colorable/README.md48
-rw-r--r--src/dma/vendor/github.com/mattn/go-colorable/colorable_appengine.go29
-rw-r--r--src/dma/vendor/github.com/mattn/go-colorable/colorable_others.go30
-rw-r--r--src/dma/vendor/github.com/mattn/go-colorable/colorable_windows.go884
-rw-r--r--src/dma/vendor/github.com/mattn/go-colorable/noncolorable.go55
-rw-r--r--src/dma/vendor/github.com/mattn/go-isatty/.travis.yml9
-rw-r--r--src/dma/vendor/github.com/mattn/go-isatty/LICENSE9
-rw-r--r--src/dma/vendor/github.com/mattn/go-isatty/README.md50
-rw-r--r--src/dma/vendor/github.com/mattn/go-isatty/doc.go2
-rw-r--r--src/dma/vendor/github.com/mattn/go-isatty/isatty_appengine.go15
-rw-r--r--src/dma/vendor/github.com/mattn/go-isatty/isatty_bsd.go18
-rw-r--r--src/dma/vendor/github.com/mattn/go-isatty/isatty_linux.go18
-rw-r--r--src/dma/vendor/github.com/mattn/go-isatty/isatty_linux_ppc64x.go19
-rw-r--r--src/dma/vendor/github.com/mattn/go-isatty/isatty_others.go10
-rw-r--r--src/dma/vendor/github.com/mattn/go-isatty/isatty_solaris.go16
-rw-r--r--src/dma/vendor/github.com/mattn/go-isatty/isatty_windows.go94
-rw-r--r--src/dma/vendor/github.com/streadway/amqp/.gitignore4
-rw-r--r--src/dma/vendor/github.com/streadway/amqp/.travis.yml18
-rw-r--r--src/dma/vendor/github.com/streadway/amqp/CONTRIBUTING.md35
-rw-r--r--src/dma/vendor/github.com/streadway/amqp/LICENSE23
-rw-r--r--src/dma/vendor/github.com/streadway/amqp/README.md93
-rw-r--r--src/dma/vendor/github.com/streadway/amqp/allocator.go106
-rw-r--r--src/dma/vendor/github.com/streadway/amqp/auth.go46
-rwxr-xr-xsrc/dma/vendor/github.com/streadway/amqp/certs.sh159
-rw-r--r--src/dma/vendor/github.com/streadway/amqp/channel.go1587
-rw-r--r--src/dma/vendor/github.com/streadway/amqp/confirms.go94
-rw-r--r--src/dma/vendor/github.com/streadway/amqp/connection.go842
-rw-r--r--src/dma/vendor/github.com/streadway/amqp/consumers.go142
-rw-r--r--src/dma/vendor/github.com/streadway/amqp/delivery.go173
-rw-r--r--src/dma/vendor/github.com/streadway/amqp/doc.go108
-rw-r--r--src/dma/vendor/github.com/streadway/amqp/fuzz.go17
-rwxr-xr-xsrc/dma/vendor/github.com/streadway/amqp/gen.sh2
-rwxr-xr-xsrc/dma/vendor/github.com/streadway/amqp/pre-commit29
-rw-r--r--src/dma/vendor/github.com/streadway/amqp/read.go456
-rw-r--r--src/dma/vendor/github.com/streadway/amqp/return.go64
-rw-r--r--src/dma/vendor/github.com/streadway/amqp/spec091.go3306
-rw-r--r--src/dma/vendor/github.com/streadway/amqp/types.go427
-rw-r--r--src/dma/vendor/github.com/streadway/amqp/uri.go167
-rw-r--r--src/dma/vendor/github.com/streadway/amqp/write.go411
-rw-r--r--src/dma/vendor/github.com/valyala/bytebufferpool/.travis.yml15
-rw-r--r--src/dma/vendor/github.com/valyala/bytebufferpool/LICENSE22
-rw-r--r--src/dma/vendor/github.com/valyala/bytebufferpool/README.md21
-rw-r--r--src/dma/vendor/github.com/valyala/bytebufferpool/bytebuffer.go111
-rw-r--r--src/dma/vendor/github.com/valyala/bytebufferpool/doc.go7
-rw-r--r--src/dma/vendor/github.com/valyala/bytebufferpool/pool.go151
-rw-r--r--src/dma/vendor/github.com/valyala/fasttemplate/LICENSE22
-rw-r--r--src/dma/vendor/github.com/valyala/fasttemplate/README.md85
-rw-r--r--src/dma/vendor/github.com/valyala/fasttemplate/template.go317
-rw-r--r--src/dma/vendor/github.com/valyala/fasttemplate/unsafe.go22
-rw-r--r--src/dma/vendor/github.com/valyala/fasttemplate/unsafe_gae.go11
-rw-r--r--src/dma/vendor/golang.org/x/crypto/AUTHORS3
-rw-r--r--src/dma/vendor/golang.org/x/crypto/CONTRIBUTORS3
-rw-r--r--src/dma/vendor/golang.org/x/crypto/LICENSE27
-rw-r--r--src/dma/vendor/golang.org/x/crypto/PATENTS22
-rw-r--r--src/dma/vendor/golang.org/x/crypto/acme/acme.go922
-rw-r--r--src/dma/vendor/golang.org/x/crypto/acme/autocert/autocert.go1139
-rw-r--r--src/dma/vendor/golang.org/x/crypto/acme/autocert/cache.go130
-rw-r--r--src/dma/vendor/golang.org/x/crypto/acme/autocert/listener.go157
-rw-r--r--src/dma/vendor/golang.org/x/crypto/acme/autocert/renewal.go141
-rw-r--r--src/dma/vendor/golang.org/x/crypto/acme/http.go281
-rw-r--r--src/dma/vendor/golang.org/x/crypto/acme/jws.go153
-rw-r--r--src/dma/vendor/golang.org/x/crypto/acme/types.go329
233 files changed, 58039 insertions, 0 deletions
diff --git a/src/dma/vendor/github.com/BurntSushi/toml/.gitignore b/src/dma/vendor/github.com/BurntSushi/toml/.gitignore
new file mode 100644
index 00000000..0cd38003
--- /dev/null
+++ b/src/dma/vendor/github.com/BurntSushi/toml/.gitignore
@@ -0,0 +1,5 @@
+TAGS
+tags
+.*.swp
+tomlcheck/tomlcheck
+toml.test
diff --git a/src/dma/vendor/github.com/BurntSushi/toml/.travis.yml b/src/dma/vendor/github.com/BurntSushi/toml/.travis.yml
new file mode 100644
index 00000000..8b8afc4f
--- /dev/null
+++ b/src/dma/vendor/github.com/BurntSushi/toml/.travis.yml
@@ -0,0 +1,15 @@
+language: go
+go:
+ - 1.1
+ - 1.2
+ - 1.3
+ - 1.4
+ - 1.5
+ - 1.6
+ - tip
+install:
+ - go install ./...
+ - go get github.com/BurntSushi/toml-test
+script:
+ - export PATH="$PATH:$HOME/gopath/bin"
+ - make test
diff --git a/src/dma/vendor/github.com/BurntSushi/toml/COMPATIBLE b/src/dma/vendor/github.com/BurntSushi/toml/COMPATIBLE
new file mode 100644
index 00000000..6efcfd0c
--- /dev/null
+++ b/src/dma/vendor/github.com/BurntSushi/toml/COMPATIBLE
@@ -0,0 +1,3 @@
+Compatible with TOML version
+[v0.4.0](https://github.com/toml-lang/toml/blob/v0.4.0/versions/en/toml-v0.4.0.md)
+
diff --git a/src/dma/vendor/github.com/BurntSushi/toml/COPYING b/src/dma/vendor/github.com/BurntSushi/toml/COPYING
new file mode 100644
index 00000000..5a8e3325
--- /dev/null
+++ b/src/dma/vendor/github.com/BurntSushi/toml/COPYING
@@ -0,0 +1,14 @@
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+ Version 2, December 2004
+
+ Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
+
+ Everyone is permitted to copy and distribute verbatim or modified
+ copies of this license document, and changing it is allowed as long
+ as the name is changed.
+
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. You just DO WHAT THE FUCK YOU WANT TO.
+
diff --git a/src/dma/vendor/github.com/BurntSushi/toml/Makefile b/src/dma/vendor/github.com/BurntSushi/toml/Makefile
new file mode 100644
index 00000000..3600848d
--- /dev/null
+++ b/src/dma/vendor/github.com/BurntSushi/toml/Makefile
@@ -0,0 +1,19 @@
+install:
+ go install ./...
+
+test: install
+ go test -v
+ toml-test toml-test-decoder
+ toml-test -encoder toml-test-encoder
+
+fmt:
+ gofmt -w *.go */*.go
+ colcheck *.go */*.go
+
+tags:
+ find ./ -name '*.go' -print0 | xargs -0 gotags > TAGS
+
+push:
+ git push origin master
+ git push github master
+
diff --git a/src/dma/vendor/github.com/BurntSushi/toml/README.md b/src/dma/vendor/github.com/BurntSushi/toml/README.md
new file mode 100644
index 00000000..7c1b37ec
--- /dev/null
+++ b/src/dma/vendor/github.com/BurntSushi/toml/README.md
@@ -0,0 +1,218 @@
+## TOML parser and encoder for Go with reflection
+
+TOML stands for Tom's Obvious, Minimal Language. This Go package provides a
+reflection interface similar to Go's standard library `json` and `xml`
+packages. This package also supports the `encoding.TextUnmarshaler` and
+`encoding.TextMarshaler` interfaces so that you can define custom data
+representations. (There is an example of this below.)
+
+Spec: https://github.com/toml-lang/toml
+
+Compatible with TOML version
+[v0.4.0](https://github.com/toml-lang/toml/blob/master/versions/en/toml-v0.4.0.md)
+
+Documentation: https://godoc.org/github.com/BurntSushi/toml
+
+Installation:
+
+```bash
+go get github.com/BurntSushi/toml
+```
+
+Try the toml validator:
+
+```bash
+go get github.com/BurntSushi/toml/cmd/tomlv
+tomlv some-toml-file.toml
+```
+
+[![Build Status](https://travis-ci.org/BurntSushi/toml.svg?branch=master)](https://travis-ci.org/BurntSushi/toml) [![GoDoc](https://godoc.org/github.com/BurntSushi/toml?status.svg)](https://godoc.org/github.com/BurntSushi/toml)
+
+### Testing
+
+This package passes all tests in
+[toml-test](https://github.com/BurntSushi/toml-test) for both the decoder
+and the encoder.
+
+### Examples
+
+This package works similarly to how the Go standard library handles `XML`
+and `JSON`. Namely, data is loaded into Go values via reflection.
+
+For the simplest example, consider some TOML file as just a list of keys
+and values:
+
+```toml
+Age = 25
+Cats = [ "Cauchy", "Plato" ]
+Pi = 3.14
+Perfection = [ 6, 28, 496, 8128 ]
+DOB = 1987-07-05T05:45:00Z
+```
+
+Which could be defined in Go as:
+
+```go
+type Config struct {
+ Age int
+ Cats []string
+ Pi float64
+ Perfection []int
+ DOB time.Time // requires `import time`
+}
+```
+
+And then decoded with:
+
+```go
+var conf Config
+if _, err := toml.Decode(tomlData, &conf); err != nil {
+ // handle error
+}
+```
+
+You can also use struct tags if your struct field name doesn't map to a TOML
+key value directly:
+
+```toml
+some_key_NAME = "wat"
+```
+
+```go
+type TOML struct {
+ ObscureKey string `toml:"some_key_NAME"`
+}
+```
+
+### Using the `encoding.TextUnmarshaler` interface
+
+Here's an example that automatically parses duration strings into
+`time.Duration` values:
+
+```toml
+[[song]]
+name = "Thunder Road"
+duration = "4m49s"
+
+[[song]]
+name = "Stairway to Heaven"
+duration = "8m03s"
+```
+
+Which can be decoded with:
+
+```go
+type song struct {
+ Name string
+ Duration duration
+}
+type songs struct {
+ Song []song
+}
+var favorites songs
+if _, err := toml.Decode(blob, &favorites); err != nil {
+ log.Fatal(err)
+}
+
+for _, s := range favorites.Song {
+ fmt.Printf("%s (%s)\n", s.Name, s.Duration)
+}
+```
+
+And you'll also need a `duration` type that satisfies the
+`encoding.TextUnmarshaler` interface:
+
+```go
+type duration struct {
+ time.Duration
+}
+
+func (d *duration) UnmarshalText(text []byte) error {
+ var err error
+ d.Duration, err = time.ParseDuration(string(text))
+ return err
+}
+```
+
+### More complex usage
+
+Here's an example of how to load the example from the official spec page:
+
+```toml
+# This is a TOML document. Boom.
+
+title = "TOML Example"
+
+[owner]
+name = "Tom Preston-Werner"
+organization = "GitHub"
+bio = "GitHub Cofounder & CEO\nLikes tater tots and beer."
+dob = 1979-05-27T07:32:00Z # First class dates? Why not?
+
+[database]
+server = "192.168.1.1"
+ports = [ 8001, 8001, 8002 ]
+connection_max = 5000
+enabled = true
+
+[servers]
+
+ # You can indent as you please. Tabs or spaces. TOML don't care.
+ [servers.alpha]
+ ip = "10.0.0.1"
+ dc = "eqdc10"
+
+ [servers.beta]
+ ip = "10.0.0.2"
+ dc = "eqdc10"
+
+[clients]
+data = [ ["gamma", "delta"], [1, 2] ] # just an update to make sure parsers support it
+
+# Line breaks are OK when inside arrays
+hosts = [
+ "alpha",
+ "omega"
+]
+```
+
+And the corresponding Go types are:
+
+```go
+type tomlConfig struct {
+ Title string
+ Owner ownerInfo
+ DB database `toml:"database"`
+ Servers map[string]server
+ Clients clients
+}
+
+type ownerInfo struct {
+ Name string
+ Org string `toml:"organization"`
+ Bio string
+ DOB time.Time
+}
+
+type database struct {
+ Server string
+ Ports []int
+ ConnMax int `toml:"connection_max"`
+ Enabled bool
+}
+
+type server struct {
+ IP string
+ DC string
+}
+
+type clients struct {
+ Data [][]interface{}
+ Hosts []string
+}
+```
+
+Note that a case insensitive match will be tried if an exact match can't be
+found.
+
+A working example of the above can be found in `_examples/example.{go,toml}`.
diff --git a/src/dma/vendor/github.com/BurntSushi/toml/cmd/toml-test-decoder/COPYING b/src/dma/vendor/github.com/BurntSushi/toml/cmd/toml-test-decoder/COPYING
new file mode 100644
index 00000000..5a8e3325
--- /dev/null
+++ b/src/dma/vendor/github.com/BurntSushi/toml/cmd/toml-test-decoder/COPYING
@@ -0,0 +1,14 @@
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+ Version 2, December 2004
+
+ Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
+
+ Everyone is permitted to copy and distribute verbatim or modified
+ copies of this license document, and changing it is allowed as long
+ as the name is changed.
+
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. You just DO WHAT THE FUCK YOU WANT TO.
+
diff --git a/src/dma/vendor/github.com/BurntSushi/toml/cmd/toml-test-encoder/COPYING b/src/dma/vendor/github.com/BurntSushi/toml/cmd/toml-test-encoder/COPYING
new file mode 100644
index 00000000..5a8e3325
--- /dev/null
+++ b/src/dma/vendor/github.com/BurntSushi/toml/cmd/toml-test-encoder/COPYING
@@ -0,0 +1,14 @@
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+ Version 2, December 2004
+
+ Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
+
+ Everyone is permitted to copy and distribute verbatim or modified
+ copies of this license document, and changing it is allowed as long
+ as the name is changed.
+
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. You just DO WHAT THE FUCK YOU WANT TO.
+
diff --git a/src/dma/vendor/github.com/BurntSushi/toml/cmd/tomlv/COPYING b/src/dma/vendor/github.com/BurntSushi/toml/cmd/tomlv/COPYING
new file mode 100644
index 00000000..5a8e3325
--- /dev/null
+++ b/src/dma/vendor/github.com/BurntSushi/toml/cmd/tomlv/COPYING
@@ -0,0 +1,14 @@
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+ Version 2, December 2004
+
+ Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
+
+ Everyone is permitted to copy and distribute verbatim or modified
+ copies of this license document, and changing it is allowed as long
+ as the name is changed.
+
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. You just DO WHAT THE FUCK YOU WANT TO.
+
diff --git a/src/dma/vendor/github.com/BurntSushi/toml/decode.go b/src/dma/vendor/github.com/BurntSushi/toml/decode.go
new file mode 100644
index 00000000..b0fd51d5
--- /dev/null
+++ b/src/dma/vendor/github.com/BurntSushi/toml/decode.go
@@ -0,0 +1,509 @@
+package toml
+
+import (
+ "fmt"
+ "io"
+ "io/ioutil"
+ "math"
+ "reflect"
+ "strings"
+ "time"
+)
+
+func e(format string, args ...interface{}) error {
+ return fmt.Errorf("toml: "+format, args...)
+}
+
+// Unmarshaler is the interface implemented by objects that can unmarshal a
+// TOML description of themselves.
+type Unmarshaler interface {
+ UnmarshalTOML(interface{}) error
+}
+
+// Unmarshal decodes the contents of `p` in TOML format into a pointer `v`.
+func Unmarshal(p []byte, v interface{}) error {
+ _, err := Decode(string(p), v)
+ return err
+}
+
+// Primitive is a TOML value that hasn't been decoded into a Go value.
+// When using the various `Decode*` functions, the type `Primitive` may
+// be given to any value, and its decoding will be delayed.
+//
+// A `Primitive` value can be decoded using the `PrimitiveDecode` function.
+//
+// The underlying representation of a `Primitive` value is subject to change.
+// Do not rely on it.
+//
+// N.B. Primitive values are still parsed, so using them will only avoid
+// the overhead of reflection. They can be useful when you don't know the
+// exact type of TOML data until run time.
+type Primitive struct {
+ undecoded interface{}
+ context Key
+}
+
+// DEPRECATED!
+//
+// Use MetaData.PrimitiveDecode instead.
+func PrimitiveDecode(primValue Primitive, v interface{}) error {
+ md := MetaData{decoded: make(map[string]bool)}
+ return md.unify(primValue.undecoded, rvalue(v))
+}
+
+// PrimitiveDecode is just like the other `Decode*` functions, except it
+// decodes a TOML value that has already been parsed. Valid primitive values
+// can *only* be obtained from values filled by the decoder functions,
+// including this method. (i.e., `v` may contain more `Primitive`
+// values.)
+//
+// Meta data for primitive values is included in the meta data returned by
+// the `Decode*` functions with one exception: keys returned by the Undecoded
+// method will only reflect keys that were decoded. Namely, any keys hidden
+// behind a Primitive will be considered undecoded. Executing this method will
+// update the undecoded keys in the meta data. (See the example.)
+func (md *MetaData) PrimitiveDecode(primValue Primitive, v interface{}) error {
+ md.context = primValue.context
+ defer func() { md.context = nil }()
+ return md.unify(primValue.undecoded, rvalue(v))
+}
+
+// Decode will decode the contents of `data` in TOML format into a pointer
+// `v`.
+//
+// TOML hashes correspond to Go structs or maps. (Dealer's choice. They can be
+// used interchangeably.)
+//
+// TOML arrays of tables correspond to either a slice of structs or a slice
+// of maps.
+//
+// TOML datetimes correspond to Go `time.Time` values.
+//
+// All other TOML types (float, string, int, bool and array) correspond
+// to the obvious Go types.
+//
+// An exception to the above rules is if a type implements the
+// encoding.TextUnmarshaler interface. In this case, any primitive TOML value
+// (floats, strings, integers, booleans and datetimes) will be converted to
+// a byte string and given to the value's UnmarshalText method. See the
+// Unmarshaler example for a demonstration with time duration strings.
+//
+// Key mapping
+//
+// TOML keys can map to either keys in a Go map or field names in a Go
+// struct. The special `toml` struct tag may be used to map TOML keys to
+// struct fields that don't match the key name exactly. (See the example.)
+// A case insensitive match to struct names will be tried if an exact match
+// can't be found.
+//
+// The mapping between TOML values and Go values is loose. That is, there
+// may exist TOML values that cannot be placed into your representation, and
+// there may be parts of your representation that do not correspond to
+// TOML values. This loose mapping can be made stricter by using the IsDefined
+// and/or Undecoded methods on the MetaData returned.
+//
+// This decoder will not handle cyclic types. If a cyclic type is passed,
+// `Decode` will not terminate.
+func Decode(data string, v interface{}) (MetaData, error) {
+ rv := reflect.ValueOf(v)
+ if rv.Kind() != reflect.Ptr {
+ return MetaData{}, e("Decode of non-pointer %s", reflect.TypeOf(v))
+ }
+ if rv.IsNil() {
+ return MetaData{}, e("Decode of nil %s", reflect.TypeOf(v))
+ }
+ p, err := parse(data)
+ if err != nil {
+ return MetaData{}, err
+ }
+ md := MetaData{
+ p.mapping, p.types, p.ordered,
+ make(map[string]bool, len(p.ordered)), nil,
+ }
+ return md, md.unify(p.mapping, indirect(rv))
+}
+
+// DecodeFile is just like Decode, except it will automatically read the
+// contents of the file at `fpath` and decode it for you.
+func DecodeFile(fpath string, v interface{}) (MetaData, error) {
+ bs, err := ioutil.ReadFile(fpath)
+ if err != nil {
+ return MetaData{}, err
+ }
+ return Decode(string(bs), v)
+}
+
+// DecodeReader is just like Decode, except it will consume all bytes
+// from the reader and decode it for you.
+func DecodeReader(r io.Reader, v interface{}) (MetaData, error) {
+ bs, err := ioutil.ReadAll(r)
+ if err != nil {
+ return MetaData{}, err
+ }
+ return Decode(string(bs), v)
+}
+
+// unify performs a sort of type unification based on the structure of `rv`,
+// which is the client representation.
+//
+// Any type mismatch produces an error. Finding a type that we don't know
+// how to handle produces an unsupported type error.
+func (md *MetaData) unify(data interface{}, rv reflect.Value) error {
+
+ // Special case. Look for a `Primitive` value.
+ if rv.Type() == reflect.TypeOf((*Primitive)(nil)).Elem() {
+ // Save the undecoded data and the key context into the primitive
+ // value.
+ context := make(Key, len(md.context))
+ copy(context, md.context)
+ rv.Set(reflect.ValueOf(Primitive{
+ undecoded: data,
+ context: context,
+ }))
+ return nil
+ }
+
+ // Special case. Unmarshaler Interface support.
+ if rv.CanAddr() {
+ if v, ok := rv.Addr().Interface().(Unmarshaler); ok {
+ return v.UnmarshalTOML(data)
+ }
+ }
+
+ // Special case. Handle time.Time values specifically.
+ // TODO: Remove this code when we decide to drop support for Go 1.1.
+ // This isn't necessary in Go 1.2 because time.Time satisfies the encoding
+ // interfaces.
+ if rv.Type().AssignableTo(rvalue(time.Time{}).Type()) {
+ return md.unifyDatetime(data, rv)
+ }
+
+ // Special case. Look for a value satisfying the TextUnmarshaler interface.
+ if v, ok := rv.Interface().(TextUnmarshaler); ok {
+ return md.unifyText(data, v)
+ }
+ // BUG(burntsushi)
+ // The behavior here is incorrect whenever a Go type satisfies the
+ // encoding.TextUnmarshaler interface but also corresponds to a TOML
+ // hash or array. In particular, the unmarshaler should only be applied
+ // to primitive TOML values. But at this point, it will be applied to
+ // all kinds of values and produce an incorrect error whenever those values
+ // are hashes or arrays (including arrays of tables).
+
+ k := rv.Kind()
+
+ // laziness
+ if k >= reflect.Int && k <= reflect.Uint64 {
+ return md.unifyInt(data, rv)
+ }
+ switch k {
+ case reflect.Ptr:
+ elem := reflect.New(rv.Type().Elem())
+ err := md.unify(data, reflect.Indirect(elem))
+ if err != nil {
+ return err
+ }
+ rv.Set(elem)
+ return nil
+ case reflect.Struct:
+ return md.unifyStruct(data, rv)
+ case reflect.Map:
+ return md.unifyMap(data, rv)
+ case reflect.Array:
+ return md.unifyArray(data, rv)
+ case reflect.Slice:
+ return md.unifySlice(data, rv)
+ case reflect.String:
+ return md.unifyString(data, rv)
+ case reflect.Bool:
+ return md.unifyBool(data, rv)
+ case reflect.Interface:
+ // we only support empty interfaces.
+ if rv.NumMethod() > 0 {
+ return e("unsupported type %s", rv.Type())
+ }
+ return md.unifyAnything(data, rv)
+ case reflect.Float32:
+ fallthrough
+ case reflect.Float64:
+ return md.unifyFloat64(data, rv)
+ }
+ return e("unsupported type %s", rv.Kind())
+}
+
+func (md *MetaData) unifyStruct(mapping interface{}, rv reflect.Value) error {
+ tmap, ok := mapping.(map[string]interface{})
+ if !ok {
+ if mapping == nil {
+ return nil
+ }
+ return e("type mismatch for %s: expected table but found %T",
+ rv.Type().String(), mapping)
+ }
+
+ for key, datum := range tmap {
+ var f *field
+ fields := cachedTypeFields(rv.Type())
+ for i := range fields {
+ ff := &fields[i]
+ if ff.name == key {
+ f = ff
+ break
+ }
+ if f == nil && strings.EqualFold(ff.name, key) {
+ f = ff
+ }
+ }
+ if f != nil {
+ subv := rv
+ for _, i := range f.index {
+ subv = indirect(subv.Field(i))
+ }
+ if isUnifiable(subv) {
+ md.decoded[md.context.add(key).String()] = true
+ md.context = append(md.context, key)
+ if err := md.unify(datum, subv); err != nil {
+ return err
+ }
+ md.context = md.context[0 : len(md.context)-1]
+ } else if f.name != "" {
+ // Bad user! No soup for you!
+ return e("cannot write unexported field %s.%s",
+ rv.Type().String(), f.name)
+ }
+ }
+ }
+ return nil
+}
+
+func (md *MetaData) unifyMap(mapping interface{}, rv reflect.Value) error {
+ tmap, ok := mapping.(map[string]interface{})
+ if !ok {
+ if tmap == nil {
+ return nil
+ }
+ return badtype("map", mapping)
+ }
+ if rv.IsNil() {
+ rv.Set(reflect.MakeMap(rv.Type()))
+ }
+ for k, v := range tmap {
+ md.decoded[md.context.add(k).String()] = true
+ md.context = append(md.context, k)
+
+ rvkey := indirect(reflect.New(rv.Type().Key()))
+ rvval := reflect.Indirect(reflect.New(rv.Type().Elem()))
+ if err := md.unify(v, rvval); err != nil {
+ return err
+ }
+ md.context = md.context[0 : len(md.context)-1]
+
+ rvkey.SetString(k)
+ rv.SetMapIndex(rvkey, rvval)
+ }
+ return nil
+}
+
+func (md *MetaData) unifyArray(data interface{}, rv reflect.Value) error {
+ datav := reflect.ValueOf(data)
+ if datav.Kind() != reflect.Slice {
+ if !datav.IsValid() {
+ return nil
+ }
+ return badtype("slice", data)
+ }
+ sliceLen := datav.Len()
+ if sliceLen != rv.Len() {
+ return e("expected array length %d; got TOML array of length %d",
+ rv.Len(), sliceLen)
+ }
+ return md.unifySliceArray(datav, rv)
+}
+
+func (md *MetaData) unifySlice(data interface{}, rv reflect.Value) error {
+ datav := reflect.ValueOf(data)
+ if datav.Kind() != reflect.Slice {
+ if !datav.IsValid() {
+ return nil
+ }
+ return badtype("slice", data)
+ }
+ n := datav.Len()
+ if rv.IsNil() || rv.Cap() < n {
+ rv.Set(reflect.MakeSlice(rv.Type(), n, n))
+ }
+ rv.SetLen(n)
+ return md.unifySliceArray(datav, rv)
+}
+
+func (md *MetaData) unifySliceArray(data, rv reflect.Value) error {
+ sliceLen := data.Len()
+ for i := 0; i < sliceLen; i++ {
+ v := data.Index(i).Interface()
+ sliceval := indirect(rv.Index(i))
+ if err := md.unify(v, sliceval); err != nil {
+ return err
+ }
+ }
+ return nil
+}
+
+func (md *MetaData) unifyDatetime(data interface{}, rv reflect.Value) error {
+ if _, ok := data.(time.Time); ok {
+ rv.Set(reflect.ValueOf(data))
+ return nil
+ }
+ return badtype("time.Time", data)
+}
+
+func (md *MetaData) unifyString(data interface{}, rv reflect.Value) error {
+ if s, ok := data.(string); ok {
+ rv.SetString(s)
+ return nil
+ }
+ return badtype("string", data)
+}
+
+func (md *MetaData) unifyFloat64(data interface{}, rv reflect.Value) error {
+ if num, ok := data.(float64); ok {
+ switch rv.Kind() {
+ case reflect.Float32:
+ fallthrough
+ case reflect.Float64:
+ rv.SetFloat(num)
+ default:
+ panic("bug")
+ }
+ return nil
+ }
+ return badtype("float", data)
+}
+
+func (md *MetaData) unifyInt(data interface{}, rv reflect.Value) error {
+ if num, ok := data.(int64); ok {
+ if rv.Kind() >= reflect.Int && rv.Kind() <= reflect.Int64 {
+ switch rv.Kind() {
+ case reflect.Int, reflect.Int64:
+ // No bounds checking necessary.
+ case reflect.Int8:
+ if num < math.MinInt8 || num > math.MaxInt8 {
+ return e("value %d is out of range for int8", num)
+ }
+ case reflect.Int16:
+ if num < math.MinInt16 || num > math.MaxInt16 {
+ return e("value %d is out of range for int16", num)
+ }
+ case reflect.Int32:
+ if num < math.MinInt32 || num > math.MaxInt32 {
+ return e("value %d is out of range for int32", num)
+ }
+ }
+ rv.SetInt(num)
+ } else if rv.Kind() >= reflect.Uint && rv.Kind() <= reflect.Uint64 {
+ unum := uint64(num)
+ switch rv.Kind() {
+ case reflect.Uint, reflect.Uint64:
+ // No bounds checking necessary.
+ case reflect.Uint8:
+ if num < 0 || unum > math.MaxUint8 {
+ return e("value %d is out of range for uint8", num)
+ }
+ case reflect.Uint16:
+ if num < 0 || unum > math.MaxUint16 {
+ return e("value %d is out of range for uint16", num)
+ }
+ case reflect.Uint32:
+ if num < 0 || unum > math.MaxUint32 {
+ return e("value %d is out of range for uint32", num)
+ }
+ }
+ rv.SetUint(unum)
+ } else {
+ panic("unreachable")
+ }
+ return nil
+ }
+ return badtype("integer", data)
+}
+
+func (md *MetaData) unifyBool(data interface{}, rv reflect.Value) error {
+ if b, ok := data.(bool); ok {
+ rv.SetBool(b)
+ return nil
+ }
+ return badtype("boolean", data)
+}
+
+func (md *MetaData) unifyAnything(data interface{}, rv reflect.Value) error {
+ rv.Set(reflect.ValueOf(data))
+ return nil
+}
+
+func (md *MetaData) unifyText(data interface{}, v TextUnmarshaler) error {
+ var s string
+ switch sdata := data.(type) {
+ case TextMarshaler:
+ text, err := sdata.MarshalText()
+ if err != nil {
+ return err
+ }
+ s = string(text)
+ case fmt.Stringer:
+ s = sdata.String()
+ case string:
+ s = sdata
+ case bool:
+ s = fmt.Sprintf("%v", sdata)
+ case int64:
+ s = fmt.Sprintf("%d", sdata)
+ case float64:
+ s = fmt.Sprintf("%f", sdata)
+ default:
+ return badtype("primitive (string-like)", data)
+ }
+ if err := v.UnmarshalText([]byte(s)); err != nil {
+ return err
+ }
+ return nil
+}
+
+// rvalue returns a reflect.Value of `v`. All pointers are resolved.
+func rvalue(v interface{}) reflect.Value {
+ return indirect(reflect.ValueOf(v))
+}
+
+// indirect returns the value pointed to by a pointer.
+// Pointers are followed until the value is not a pointer.
+// New values are allocated for each nil pointer.
+//
+// An exception to this rule is if the value satisfies an interface of
+// interest to us (like encoding.TextUnmarshaler).
+func indirect(v reflect.Value) reflect.Value {
+ if v.Kind() != reflect.Ptr {
+ if v.CanSet() {
+ pv := v.Addr()
+ if _, ok := pv.Interface().(TextUnmarshaler); ok {
+ return pv
+ }
+ }
+ return v
+ }
+ if v.IsNil() {
+ v.Set(reflect.New(v.Type().Elem()))
+ }
+ return indirect(reflect.Indirect(v))
+}
+
+func isUnifiable(rv reflect.Value) bool {
+ if rv.CanSet() {
+ return true
+ }
+ if _, ok := rv.Interface().(TextUnmarshaler); ok {
+ return true
+ }
+ return false
+}
+
+func badtype(expected string, data interface{}) error {
+ return e("cannot load TOML value of type %T into a Go %s", data, expected)
+}
diff --git a/src/dma/vendor/github.com/BurntSushi/toml/decode_meta.go b/src/dma/vendor/github.com/BurntSushi/toml/decode_meta.go
new file mode 100644
index 00000000..b9914a67
--- /dev/null
+++ b/src/dma/vendor/github.com/BurntSushi/toml/decode_meta.go
@@ -0,0 +1,121 @@
+package toml
+
+import "strings"
+
+// MetaData allows access to meta information about TOML data that may not
+// be inferrable via reflection. In particular, whether a key has been defined
+// and the TOML type of a key.
+type MetaData struct {
+ mapping map[string]interface{}
+ types map[string]tomlType
+ keys []Key
+ decoded map[string]bool
+ context Key // Used only during decoding.
+}
+
+// IsDefined returns true if the key given exists in the TOML data. The key
+// should be specified hierarchially. e.g.,
+//
+// // access the TOML key 'a.b.c'
+// IsDefined("a", "b", "c")
+//
+// IsDefined will return false if an empty key given. Keys are case sensitive.
+func (md *MetaData) IsDefined(key ...string) bool {
+ if len(key) == 0 {
+ return false
+ }
+
+ var hash map[string]interface{}
+ var ok bool
+ var hashOrVal interface{} = md.mapping
+ for _, k := range key {
+ if hash, ok = hashOrVal.(map[string]interface{}); !ok {
+ return false
+ }
+ if hashOrVal, ok = hash[k]; !ok {
+ return false
+ }
+ }
+ return true
+}
+
+// Type returns a string representation of the type of the key specified.
+//
+// Type will return the empty string if given an empty key or a key that
+// does not exist. Keys are case sensitive.
+func (md *MetaData) Type(key ...string) string {
+ fullkey := strings.Join(key, ".")
+ if typ, ok := md.types[fullkey]; ok {
+ return typ.typeString()
+ }
+ return ""
+}
+
+// Key is the type of any TOML key, including key groups. Use (MetaData).Keys
+// to get values of this type.
+type Key []string
+
+func (k Key) String() string {
+ return strings.Join(k, ".")
+}
+
+func (k Key) maybeQuotedAll() string {
+ var ss []string
+ for i := range k {
+ ss = append(ss, k.maybeQuoted(i))
+ }
+ return strings.Join(ss, ".")
+}
+
+func (k Key) maybeQuoted(i int) string {
+ quote := false
+ for _, c := range k[i] {
+ if !isBareKeyChar(c) {
+ quote = true
+ break
+ }
+ }
+ if quote {
+ return "\"" + strings.Replace(k[i], "\"", "\\\"", -1) + "\""
+ }
+ return k[i]
+}
+
+func (k Key) add(piece string) Key {
+ newKey := make(Key, len(k)+1)
+ copy(newKey, k)
+ newKey[len(k)] = piece
+ return newKey
+}
+
+// Keys returns a slice of every key in the TOML data, including key groups.
+// Each key is itself a slice, where the first element is the top of the
+// hierarchy and the last is the most specific.
+//
+// The list will have the same order as the keys appeared in the TOML data.
+//
+// All keys returned are non-empty.
+func (md *MetaData) Keys() []Key {
+ return md.keys
+}
+
+// Undecoded returns all keys that have not been decoded in the order in which
+// they appear in the original TOML document.
+//
+// This includes keys that haven't been decoded because of a Primitive value.
+// Once the Primitive value is decoded, the keys will be considered decoded.
+//
+// Also note that decoding into an empty interface will result in no decoding,
+// and so no keys will be considered decoded.
+//
+// In this sense, the Undecoded keys correspond to keys in the TOML document
+// that do not have a concrete type in your representation.
+func (md *MetaData) Undecoded() []Key {
+ undecoded := make([]Key, 0, len(md.keys))
+ for _, key := range md.keys {
+ if !md.decoded[key.String()] {
+ undecoded = append(undecoded, key)
+ }
+ }
+ return undecoded
+}
diff --git a/src/dma/vendor/github.com/BurntSushi/toml/doc.go b/src/dma/vendor/github.com/BurntSushi/toml/doc.go
new file mode 100644
index 00000000..b371f396
--- /dev/null
+++ b/src/dma/vendor/github.com/BurntSushi/toml/doc.go
@@ -0,0 +1,27 @@
+/*
+Package toml provides facilities for decoding and encoding TOML configuration
+files via reflection. There is also support for delaying decoding with
+the Primitive type, and querying the set of keys in a TOML document with the
+MetaData type.
+
+The specification implemented: https://github.com/toml-lang/toml
+
+The sub-command github.com/BurntSushi/toml/cmd/tomlv can be used to verify
+whether a file is a valid TOML document. It can also be used to print the
+type of each key in a TOML document.
+
+Testing
+
+There are two important types of tests used for this package. The first is
+contained inside '*_test.go' files and uses the standard Go unit testing
+framework. These tests are primarily devoted to holistically testing the
+decoder and encoder.
+
+The second type of testing is used to verify the implementation's adherence
+to the TOML specification. These tests have been factored into their own
+project: https://github.com/BurntSushi/toml-test
+
+The reason the tests are in a separate project is so that they can be used by
+any implementation of TOML. Namely, it is language agnostic.
+*/
+package toml
diff --git a/src/dma/vendor/github.com/BurntSushi/toml/encode.go b/src/dma/vendor/github.com/BurntSushi/toml/encode.go
new file mode 100644
index 00000000..d905c21a
--- /dev/null
+++ b/src/dma/vendor/github.com/BurntSushi/toml/encode.go
@@ -0,0 +1,568 @@
+package toml
+
+import (
+ "bufio"
+ "errors"
+ "fmt"
+ "io"
+ "reflect"
+ "sort"
+ "strconv"
+ "strings"
+ "time"
+)
+
+type tomlEncodeError struct{ error }
+
+var (
+ errArrayMixedElementTypes = errors.New(
+ "toml: cannot encode array with mixed element types")
+ errArrayNilElement = errors.New(
+ "toml: cannot encode array with nil element")
+ errNonString = errors.New(
+ "toml: cannot encode a map with non-string key type")
+ errAnonNonStruct = errors.New(
+ "toml: cannot encode an anonymous field that is not a struct")
+ errArrayNoTable = errors.New(
+ "toml: TOML array element cannot contain a table")
+ errNoKey = errors.New(
+ "toml: top-level values must be Go maps or structs")
+ errAnything = errors.New("") // used in testing
+)
+
+var quotedReplacer = strings.NewReplacer(
+ "\t", "\\t",
+ "\n", "\\n",
+ "\r", "\\r",
+ "\"", "\\\"",
+ "\\", "\\\\",
+)
+
+// Encoder controls the encoding of Go values to a TOML document to some
+// io.Writer.
+//
+// The indentation level can be controlled with the Indent field.
+type Encoder struct {
+ // A single indentation level. By default it is two spaces.
+ Indent string
+
+ // hasWritten is whether we have written any output to w yet.
+ hasWritten bool
+ w *bufio.Writer
+}
+
+// NewEncoder returns a TOML encoder that encodes Go values to the io.Writer
+// given. By default, a single indentation level is 2 spaces.
+func NewEncoder(w io.Writer) *Encoder {
+ return &Encoder{
+ w: bufio.NewWriter(w),
+ Indent: " ",
+ }
+}
+
+// Encode writes a TOML representation of the Go value to the underlying
+// io.Writer. If the value given cannot be encoded to a valid TOML document,
+// then an error is returned.
+//
+// The mapping between Go values and TOML values should be precisely the same
+// as for the Decode* functions. Similarly, the TextMarshaler interface is
+// supported by encoding the resulting bytes as strings. (If you want to write
+// arbitrary binary data then you will need to use something like base64 since
+// TOML does not have any binary types.)
+//
+// When encoding TOML hashes (i.e., Go maps or structs), keys without any
+// sub-hashes are encoded first.
+//
+// If a Go map is encoded, then its keys are sorted alphabetically for
+// deterministic output. More control over this behavior may be provided if
+// there is demand for it.
+//
+// Encoding Go values without a corresponding TOML representation---like map
+// types with non-string keys---will cause an error to be returned. Similarly
+// for mixed arrays/slices, arrays/slices with nil elements, embedded
+// non-struct types and nested slices containing maps or structs.
+// (e.g., [][]map[string]string is not allowed but []map[string]string is OK
+// and so is []map[string][]string.)
+func (enc *Encoder) Encode(v interface{}) error {
+ rv := eindirect(reflect.ValueOf(v))
+ if err := enc.safeEncode(Key([]string{}), rv); err != nil {
+ return err
+ }
+ return enc.w.Flush()
+}
+
+func (enc *Encoder) safeEncode(key Key, rv reflect.Value) (err error) {
+ defer func() {
+ if r := recover(); r != nil {
+ if terr, ok := r.(tomlEncodeError); ok {
+ err = terr.error
+ return
+ }
+ panic(r)
+ }
+ }()
+ enc.encode(key, rv)
+ return nil
+}
+
+func (enc *Encoder) encode(key Key, rv reflect.Value) {
+ // Special case. Time needs to be in ISO8601 format.
+ // Special case. If we can marshal the type to text, then we used that.
+ // Basically, this prevents the encoder for handling these types as
+ // generic structs (or whatever the underlying type of a TextMarshaler is).
+ switch rv.Interface().(type) {
+ case time.Time, TextMarshaler:
+ enc.keyEqElement(key, rv)
+ return
+ }
+
+ k := rv.Kind()
+ switch k {
+ case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32,
+ reflect.Int64,
+ reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32,
+ reflect.Uint64,
+ reflect.Float32, reflect.Float64, reflect.String, reflect.Bool:
+ enc.keyEqElement(key, rv)
+ case reflect.Array, reflect.Slice:
+ if typeEqual(tomlArrayHash, tomlTypeOfGo(rv)) {
+ enc.eArrayOfTables(key, rv)
+ } else {
+ enc.keyEqElement(key, rv)
+ }
+ case reflect.Interface:
+ if rv.IsNil() {
+ return
+ }
+ enc.encode(key, rv.Elem())
+ case reflect.Map:
+ if rv.IsNil() {
+ return
+ }
+ enc.eTable(key, rv)
+ case reflect.Ptr:
+ if rv.IsNil() {
+ return
+ }
+ enc.encode(key, rv.Elem())
+ case reflect.Struct:
+ enc.eTable(key, rv)
+ default:
+ panic(e("unsupported type for key '%s': %s", key, k))
+ }
+}
+
+// eElement encodes any value that can be an array element (primitives and
+// arrays).
+func (enc *Encoder) eElement(rv reflect.Value) {
+ switch v := rv.Interface().(type) {
+ case time.Time:
+ // Special case time.Time as a primitive. Has to come before
+ // TextMarshaler below because time.Time implements
+ // encoding.TextMarshaler, but we need to always use UTC.
+ enc.wf(v.UTC().Format("2006-01-02T15:04:05Z"))
+ return
+ case TextMarshaler:
+ // Special case. Use text marshaler if it's available for this value.
+ if s, err := v.MarshalText(); err != nil {
+ encPanic(err)
+ } else {
+ enc.writeQuoted(string(s))
+ }
+ return
+ }
+ switch rv.Kind() {
+ case reflect.Bool:
+ enc.wf(strconv.FormatBool(rv.Bool()))
+ case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32,
+ reflect.Int64:
+ enc.wf(strconv.FormatInt(rv.Int(), 10))
+ case reflect.Uint, reflect.Uint8, reflect.Uint16,
+ reflect.Uint32, reflect.Uint64:
+ enc.wf(strconv.FormatUint(rv.Uint(), 10))
+ case reflect.Float32:
+ enc.wf(floatAddDecimal(strconv.FormatFloat(rv.Float(), 'f', -1, 32)))
+ case reflect.Float64:
+ enc.wf(floatAddDecimal(strconv.FormatFloat(rv.Float(), 'f', -1, 64)))
+ case reflect.Array, reflect.Slice:
+ enc.eArrayOrSliceElement(rv)
+ case reflect.Interface:
+ enc.eElement(rv.Elem())
+ case reflect.String:
+ enc.writeQuoted(rv.String())
+ default:
+ panic(e("unexpected primitive type: %s", rv.Kind()))
+ }
+}
+
+// By the TOML spec, all floats must have a decimal with at least one
+// number on either side.
+func floatAddDecimal(fstr string) string {
+ if !strings.Contains(fstr, ".") {
+ return fstr + ".0"
+ }
+ return fstr
+}
+
+func (enc *Encoder) writeQuoted(s string) {
+ enc.wf("\"%s\"", quotedReplacer.Replace(s))
+}
+
+func (enc *Encoder) eArrayOrSliceElement(rv reflect.Value) {
+ length := rv.Len()
+ enc.wf("[")
+ for i := 0; i < length; i++ {
+ elem := rv.Index(i)
+ enc.eElement(elem)
+ if i != length-1 {
+ enc.wf(", ")
+ }
+ }
+ enc.wf("]")
+}
+
+func (enc *Encoder) eArrayOfTables(key Key, rv reflect.Value) {
+ if len(key) == 0 {
+ encPanic(errNoKey)
+ }
+ for i := 0; i < rv.Len(); i++ {
+ trv := rv.Index(i)
+ if isNil(trv) {
+ continue
+ }
+ panicIfInvalidKey(key)
+ enc.newline()
+ enc.wf("%s[[%s]]", enc.indentStr(key), key.maybeQuotedAll())
+ enc.newline()
+ enc.eMapOrStruct(key, trv)
+ }
+}
+
+func (enc *Encoder) eTable(key Key, rv reflect.Value) {
+ panicIfInvalidKey(key)
+ if len(key) == 1 {
+ // Output an extra newline between top-level tables.
+ // (The newline isn't written if nothing else has been written though.)
+ enc.newline()
+ }
+ if len(key) > 0 {
+ enc.wf("%s[%s]", enc.indentStr(key), key.maybeQuotedAll())
+ enc.newline()
+ }
+ enc.eMapOrStruct(key, rv)
+}
+
+func (enc *Encoder) eMapOrStruct(key Key, rv reflect.Value) {
+ switch rv := eindirect(rv); rv.Kind() {
+ case reflect.Map:
+ enc.eMap(key, rv)
+ case reflect.Struct:
+ enc.eStruct(key, rv)
+ default:
+ panic("eTable: unhandled reflect.Value Kind: " + rv.Kind().String())
+ }
+}
+
+func (enc *Encoder) eMap(key Key, rv reflect.Value) {
+ rt := rv.Type()
+ if rt.Key().Kind() != reflect.String {
+ encPanic(errNonString)
+ }
+
+ // Sort keys so that we have deterministic output. And write keys directly
+ // underneath this key first, before writing sub-structs or sub-maps.
+ var mapKeysDirect, mapKeysSub []string
+ for _, mapKey := range rv.MapKeys() {
+ k := mapKey.String()
+ if typeIsHash(tomlTypeOfGo(rv.MapIndex(mapKey))) {
+ mapKeysSub = append(mapKeysSub, k)
+ } else {
+ mapKeysDirect = append(mapKeysDirect, k)
+ }
+ }
+
+ var writeMapKeys = func(mapKeys []string) {
+ sort.Strings(mapKeys)
+ for _, mapKey := range mapKeys {
+ mrv := rv.MapIndex(reflect.ValueOf(mapKey))
+ if isNil(mrv) {
+ // Don't write anything for nil fields.
+ continue
+ }
+ enc.encode(key.add(mapKey), mrv)
+ }
+ }
+ writeMapKeys(mapKeysDirect)
+ writeMapKeys(mapKeysSub)
+}
+
+func (enc *Encoder) eStruct(key Key, rv reflect.Value) {
+ // Write keys for fields directly under this key first, because if we write
+ // a field that creates a new table, then all keys under it will be in that
+ // table (not the one we're writing here).
+ rt := rv.Type()
+ var fieldsDirect, fieldsSub [][]int
+ var addFields func(rt reflect.Type, rv reflect.Value, start []int)
+ addFields = func(rt reflect.Type, rv reflect.Value, start []int) {
+ for i := 0; i < rt.NumField(); i++ {
+ f := rt.Field(i)
+ // skip unexported fields
+ if f.PkgPath != "" && !f.Anonymous {
+ continue
+ }
+ frv := rv.Field(i)
+ if f.Anonymous {
+ t := f.Type
+ switch t.Kind() {
+ case reflect.Struct:
+ // Treat anonymous struct fields with
+ // tag names as though they are not
+ // anonymous, like encoding/json does.
+ if getOptions(f.Tag).name == "" {
+ addFields(t, frv, f.Index)
+ continue
+ }
+ case reflect.Ptr:
+ if t.Elem().Kind() == reflect.Struct &&
+ getOptions(f.Tag).name == "" {
+ if !frv.IsNil() {
+ addFields(t.Elem(), frv.Elem(), f.Index)
+ }
+ continue
+ }
+ // Fall through to the normal field encoding logic below
+ // for non-struct anonymous fields.
+ }
+ }
+
+ if typeIsHash(tomlTypeOfGo(frv)) {
+ fieldsSub = append(fieldsSub, append(start, f.Index...))
+ } else {
+ fieldsDirect = append(fieldsDirect, append(start, f.Index...))
+ }
+ }
+ }
+ addFields(rt, rv, nil)
+
+ var writeFields = func(fields [][]int) {
+ for _, fieldIndex := range fields {
+ sft := rt.FieldByIndex(fieldIndex)
+ sf := rv.FieldByIndex(fieldIndex)
+ if isNil(sf) {
+ // Don't write anything for nil fields.
+ continue
+ }
+
+ opts := getOptions(sft.Tag)
+ if opts.skip {
+ continue
+ }
+ keyName := sft.Name
+ if opts.name != "" {
+ keyName = opts.name
+ }
+ if opts.omitempty && isEmpty(sf) {
+ continue
+ }
+ if opts.omitzero && isZero(sf) {
+ continue
+ }
+
+ enc.encode(key.add(keyName), sf)
+ }
+ }
+ writeFields(fieldsDirect)
+ writeFields(fieldsSub)
+}
+
+// tomlTypeName returns the TOML type name of the Go value's type. It is
+// used to determine whether the types of array elements are mixed (which is
+// forbidden). If the Go value is nil, then it is illegal for it to be an array
+// element, and valueIsNil is returned as true.
+
+// Returns the TOML type of a Go value. The type may be `nil`, which means
+// no concrete TOML type could be found.
+func tomlTypeOfGo(rv reflect.Value) tomlType {
+ if isNil(rv) || !rv.IsValid() {
+ return nil
+ }
+ switch rv.Kind() {
+ case reflect.Bool:
+ return tomlBool
+ case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32,
+ reflect.Int64,
+ reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32,
+ reflect.Uint64:
+ return tomlInteger
+ case reflect.Float32, reflect.Float64:
+ return tomlFloat
+ case reflect.Array, reflect.Slice:
+ if typeEqual(tomlHash, tomlArrayType(rv)) {
+ return tomlArrayHash
+ }
+ return tomlArray
+ case reflect.Ptr, reflect.Interface:
+ return tomlTypeOfGo(rv.Elem())
+ case reflect.String:
+ return tomlString
+ case reflect.Map:
+ return tomlHash
+ case reflect.Struct:
+ switch rv.Interface().(type) {
+ case time.Time:
+ return tomlDatetime
+ case TextMarshaler:
+ return tomlString
+ default:
+ return tomlHash
+ }
+ default:
+ panic("unexpected reflect.Kind: " + rv.Kind().String())
+ }
+}
+
+// tomlArrayType returns the element type of a TOML array. The type returned
+// may be nil if it cannot be determined (e.g., a nil slice or a zero length
+// slize). This function may also panic if it finds a type that cannot be
+// expressed in TOML (such as nil elements, heterogeneous arrays or directly
+// nested arrays of tables).
+func tomlArrayType(rv reflect.Value) tomlType {
+ if isNil(rv) || !rv.IsValid() || rv.Len() == 0 {
+ return nil
+ }
+ firstType := tomlTypeOfGo(rv.Index(0))
+ if firstType == nil {
+ encPanic(errArrayNilElement)
+ }
+
+ rvlen := rv.Len()
+ for i := 1; i < rvlen; i++ {
+ elem := rv.Index(i)
+ switch elemType := tomlTypeOfGo(elem); {
+ case elemType == nil:
+ encPanic(errArrayNilElement)
+ case !typeEqual(firstType, elemType):
+ encPanic(errArrayMixedElementTypes)
+ }
+ }
+ // If we have a nested array, then we must make sure that the nested
+ // array contains ONLY primitives.
+ // This checks arbitrarily nested arrays.
+ if typeEqual(firstType, tomlArray) || typeEqual(firstType, tomlArrayHash) {
+ nest := tomlArrayType(eindirect(rv.Index(0)))
+ if typeEqual(nest, tomlHash) || typeEqual(nest, tomlArrayHash) {
+ encPanic(errArrayNoTable)
+ }
+ }
+ return firstType
+}
+
+type tagOptions struct {
+ skip bool // "-"
+ name string
+ omitempty bool
+ omitzero bool
+}
+
+func getOptions(tag reflect.StructTag) tagOptions {
+ t := tag.Get("toml")
+ if t == "-" {
+ return tagOptions{skip: true}
+ }
+ var opts tagOptions
+ parts := strings.Split(t, ",")
+ opts.name = parts[0]
+ for _, s := range parts[1:] {
+ switch s {
+ case "omitempty":
+ opts.omitempty = true
+ case "omitzero":
+ opts.omitzero = true
+ }
+ }
+ return opts
+}
+
+func isZero(rv reflect.Value) bool {
+ switch rv.Kind() {
+ case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
+ return rv.Int() == 0
+ case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
+ return rv.Uint() == 0
+ case reflect.Float32, reflect.Float64:
+ return rv.Float() == 0.0
+ }
+ return false
+}
+
+func isEmpty(rv reflect.Value) bool {
+ switch rv.Kind() {
+ case reflect.Array, reflect.Slice, reflect.Map, reflect.String:
+ return rv.Len() == 0
+ case reflect.Bool:
+ return !rv.Bool()
+ }
+ return false
+}
+
+func (enc *Encoder) newline() {
+ if enc.hasWritten {
+ enc.wf("\n")
+ }
+}
+
+func (enc *Encoder) keyEqElement(key Key, val reflect.Value) {
+ if len(key) == 0 {
+ encPanic(errNoKey)
+ }
+ panicIfInvalidKey(key)
+ enc.wf("%s%s = ", enc.indentStr(key), key.maybeQuoted(len(key)-1))
+ enc.eElement(val)
+ enc.newline()
+}
+
+func (enc *Encoder) wf(format string, v ...interface{}) {
+ if _, err := fmt.Fprintf(enc.w, format, v...); err != nil {
+ encPanic(err)
+ }
+ enc.hasWritten = true
+}
+
+func (enc *Encoder) indentStr(key Key) string {
+ return strings.Repeat(enc.Indent, len(key)-1)
+}
+
+func encPanic(err error) {
+ panic(tomlEncodeError{err})
+}
+
+func eindirect(v reflect.Value) reflect.Value {
+ switch v.Kind() {
+ case reflect.Ptr, reflect.Interface:
+ return eindirect(v.Elem())
+ default:
+ return v
+ }
+}
+
+func isNil(rv reflect.Value) bool {
+ switch rv.Kind() {
+ case reflect.Interface, reflect.Map, reflect.Ptr, reflect.Slice:
+ return rv.IsNil()
+ default:
+ return false
+ }
+}
+
+func panicIfInvalidKey(key Key) {
+ for _, k := range key {
+ if len(k) == 0 {
+ encPanic(e("Key '%s' is not a valid table name. Key names "+
+ "cannot be empty.", key.maybeQuotedAll()))
+ }
+ }
+}
+
+func isValidKeyName(s string) bool {
+ return len(s) != 0
+}
diff --git a/src/dma/vendor/github.com/BurntSushi/toml/encoding_types.go b/src/dma/vendor/github.com/BurntSushi/toml/encoding_types.go
new file mode 100644
index 00000000..d36e1dd6
--- /dev/null
+++ b/src/dma/vendor/github.com/BurntSushi/toml/encoding_types.go
@@ -0,0 +1,19 @@
+// +build go1.2
+
+package toml
+
+// In order to support Go 1.1, we define our own TextMarshaler and
+// TextUnmarshaler types. For Go 1.2+, we just alias them with the
+// standard library interfaces.
+
+import (
+ "encoding"
+)
+
+// TextMarshaler is a synonym for encoding.TextMarshaler. It is defined here
+// so that Go 1.1 can be supported.
+type TextMarshaler encoding.TextMarshaler
+
+// TextUnmarshaler is a synonym for encoding.TextUnmarshaler. It is defined
+// here so that Go 1.1 can be supported.
+type TextUnmarshaler encoding.TextUnmarshaler
diff --git a/src/dma/vendor/github.com/BurntSushi/toml/encoding_types_1.1.go b/src/dma/vendor/github.com/BurntSushi/toml/encoding_types_1.1.go
new file mode 100644
index 00000000..e8d503d0
--- /dev/null
+++ b/src/dma/vendor/github.com/BurntSushi/toml/encoding_types_1.1.go
@@ -0,0 +1,18 @@
+// +build !go1.2
+
+package toml
+
+// These interfaces were introduced in Go 1.2, so we add them manually when
+// compiling for Go 1.1.
+
+// TextMarshaler is a synonym for encoding.TextMarshaler. It is defined here
+// so that Go 1.1 can be supported.
+type TextMarshaler interface {
+ MarshalText() (text []byte, err error)
+}
+
+// TextUnmarshaler is a synonym for encoding.TextUnmarshaler. It is defined
+// here so that Go 1.1 can be supported.
+type TextUnmarshaler interface {
+ UnmarshalText(text []byte) error
+}
diff --git a/src/dma/vendor/github.com/BurntSushi/toml/lex.go b/src/dma/vendor/github.com/BurntSushi/toml/lex.go
new file mode 100644
index 00000000..6dee7fc7
--- /dev/null
+++ b/src/dma/vendor/github.com/BurntSushi/toml/lex.go
@@ -0,0 +1,953 @@
+package toml
+
+import (
+ "fmt"
+ "strings"
+ "unicode"
+ "unicode/utf8"
+)
+
+type itemType int
+
+const (
+ itemError itemType = iota
+ itemNIL // used in the parser to indicate no type
+ itemEOF
+ itemText
+ itemString
+ itemRawString
+ itemMultilineString
+ itemRawMultilineString
+ itemBool
+ itemInteger
+ itemFloat
+ itemDatetime
+ itemArray // the start of an array
+ itemArrayEnd
+ itemTableStart
+ itemTableEnd
+ itemArrayTableStart
+ itemArrayTableEnd
+ itemKeyStart
+ itemCommentStart
+ itemInlineTableStart
+ itemInlineTableEnd
+)
+
+const (
+ eof = 0
+ comma = ','
+ tableStart = '['
+ tableEnd = ']'
+ arrayTableStart = '['
+ arrayTableEnd = ']'
+ tableSep = '.'
+ keySep = '='
+ arrayStart = '['
+ arrayEnd = ']'
+ commentStart = '#'
+ stringStart = '"'
+ stringEnd = '"'
+ rawStringStart = '\''
+ rawStringEnd = '\''
+ inlineTableStart = '{'
+ inlineTableEnd = '}'
+)
+
+type stateFn func(lx *lexer) stateFn
+
+type lexer struct {
+ input string
+ start int
+ pos int
+ line int
+ state stateFn
+ items chan item
+
+ // Allow for backing up up to three runes.
+ // This is necessary because TOML contains 3-rune tokens (""" and ''').
+ prevWidths [3]int
+ nprev int // how many of prevWidths are in use
+ // If we emit an eof, we can still back up, but it is not OK to call
+ // next again.
+ atEOF bool
+
+ // A stack of state functions used to maintain context.
+ // The idea is to reuse parts of the state machine in various places.
+ // For example, values can appear at the top level or within arbitrarily
+ // nested arrays. The last state on the stack is used after a value has
+ // been lexed. Similarly for comments.
+ stack []stateFn
+}
+
+type item struct {
+ typ itemType
+ val string
+ line int
+}
+
+func (lx *lexer) nextItem() item {
+ for {
+ select {
+ case item := <-lx.items:
+ return item
+ default:
+ lx.state = lx.state(lx)
+ }
+ }
+}
+
+func lex(input string) *lexer {
+ lx := &lexer{
+ input: input,
+ state: lexTop,
+ line: 1,
+ items: make(chan item, 10),
+ stack: make([]stateFn, 0, 10),
+ }
+ return lx
+}
+
+func (lx *lexer) push(state stateFn) {
+ lx.stack = append(lx.stack, state)
+}
+
+func (lx *lexer) pop() stateFn {
+ if len(lx.stack) == 0 {
+ return lx.errorf("BUG in lexer: no states to pop")
+ }
+ last := lx.stack[len(lx.stack)-1]
+ lx.stack = lx.stack[0 : len(lx.stack)-1]
+ return last
+}
+
+func (lx *lexer) current() string {
+ return lx.input[lx.start:lx.pos]
+}
+
+func (lx *lexer) emit(typ itemType) {
+ lx.items <- item{typ, lx.current(), lx.line}
+ lx.start = lx.pos
+}
+
+func (lx *lexer) emitTrim(typ itemType) {
+ lx.items <- item{typ, strings.TrimSpace(lx.current()), lx.line}
+ lx.start = lx.pos
+}
+
+func (lx *lexer) next() (r rune) {
+ if lx.atEOF {
+ panic("next called after EOF")
+ }
+ if lx.pos >= len(lx.input) {
+ lx.atEOF = true
+ return eof
+ }
+
+ if lx.input[lx.pos] == '\n' {
+ lx.line++
+ }
+ lx.prevWidths[2] = lx.prevWidths[1]
+ lx.prevWidths[1] = lx.prevWidths[0]
+ if lx.nprev < 3 {
+ lx.nprev++
+ }
+ r, w := utf8.DecodeRuneInString(lx.input[lx.pos:])
+ lx.prevWidths[0] = w
+ lx.pos += w
+ return r
+}
+
+// ignore skips over the pending input before this point.
+func (lx *lexer) ignore() {
+ lx.start = lx.pos
+}
+
+// backup steps back one rune. Can be called only twice between calls to next.
+func (lx *lexer) backup() {
+ if lx.atEOF {
+ lx.atEOF = false
+ return
+ }
+ if lx.nprev < 1 {
+ panic("backed up too far")
+ }
+ w := lx.prevWidths[0]
+ lx.prevWidths[0] = lx.prevWidths[1]
+ lx.prevWidths[1] = lx.prevWidths[2]
+ lx.nprev--
+ lx.pos -= w
+ if lx.pos < len(lx.input) && lx.input[lx.pos] == '\n' {
+ lx.line--
+ }
+}
+
+// accept consumes the next rune if it's equal to `valid`.
+func (lx *lexer) accept(valid rune) bool {
+ if lx.next() == valid {
+ return true
+ }
+ lx.backup()
+ return false
+}
+
+// peek returns but does not consume the next rune in the input.
+func (lx *lexer) peek() rune {
+ r := lx.next()
+ lx.backup()
+ return r
+}
+
+// skip ignores all input that matches the given predicate.
+func (lx *lexer) skip(pred func(rune) bool) {
+ for {
+ r := lx.next()
+ if pred(r) {
+ continue
+ }
+ lx.backup()
+ lx.ignore()
+ return
+ }
+}
+
+// errorf stops all lexing by emitting an error and returning `nil`.
+// Note that any value that is a character is escaped if it's a special
+// character (newlines, tabs, etc.).
+func (lx *lexer) errorf(format string, values ...interface{}) stateFn {
+ lx.items <- item{
+ itemError,
+ fmt.Sprintf(format, values...),
+ lx.line,
+ }
+ return nil
+}
+
+// lexTop consumes elements at the top level of TOML data.
+func lexTop(lx *lexer) stateFn {
+ r := lx.next()
+ if isWhitespace(r) || isNL(r) {
+ return lexSkip(lx, lexTop)
+ }
+ switch r {
+ case commentStart:
+ lx.push(lexTop)
+ return lexCommentStart
+ case tableStart:
+ return lexTableStart
+ case eof:
+ if lx.pos > lx.start {
+ return lx.errorf("unexpected EOF")
+ }
+ lx.emit(itemEOF)
+ return nil
+ }
+
+ // At this point, the only valid item can be a key, so we back up
+ // and let the key lexer do the rest.
+ lx.backup()
+ lx.push(lexTopEnd)
+ return lexKeyStart
+}
+
+// lexTopEnd is entered whenever a top-level item has been consumed. (A value
+// or a table.) It must see only whitespace, and will turn back to lexTop
+// upon a newline. If it sees EOF, it will quit the lexer successfully.
+func lexTopEnd(lx *lexer) stateFn {
+ r := lx.next()
+ switch {
+ case r == commentStart:
+ // a comment will read to a newline for us.
+ lx.push(lexTop)
+ return lexCommentStart
+ case isWhitespace(r):
+ return lexTopEnd
+ case isNL(r):
+ lx.ignore()
+ return lexTop
+ case r == eof:
+ lx.emit(itemEOF)
+ return nil
+ }
+ return lx.errorf("expected a top-level item to end with a newline, "+
+ "comment, or EOF, but got %q instead", r)
+}
+
+// lexTable lexes the beginning of a table. Namely, it makes sure that
+// it starts with a character other than '.' and ']'.
+// It assumes that '[' has already been consumed.
+// It also handles the case that this is an item in an array of tables.
+// e.g., '[[name]]'.
+func lexTableStart(lx *lexer) stateFn {
+ if lx.peek() == arrayTableStart {
+ lx.next()
+ lx.emit(itemArrayTableStart)
+ lx.push(lexArrayTableEnd)
+ } else {
+ lx.emit(itemTableStart)
+ lx.push(lexTableEnd)
+ }
+ return lexTableNameStart
+}
+
+func lexTableEnd(lx *lexer) stateFn {
+ lx.emit(itemTableEnd)
+ return lexTopEnd
+}
+
+func lexArrayTableEnd(lx *lexer) stateFn {
+ if r := lx.next(); r != arrayTableEnd {
+ return lx.errorf("expected end of table array name delimiter %q, "+
+ "but got %q instead", arrayTableEnd, r)
+ }
+ lx.emit(itemArrayTableEnd)
+ return lexTopEnd
+}
+
+func lexTableNameStart(lx *lexer) stateFn {
+ lx.skip(isWhitespace)
+ switch r := lx.peek(); {
+ case r == tableEnd || r == eof:
+ return lx.errorf("unexpected end of table name " +
+ "(table names cannot be empty)")
+ case r == tableSep:
+ return lx.errorf("unexpected table separator " +
+ "(table names cannot be empty)")
+ case r == stringStart || r == rawStringStart:
+ lx.ignore()
+ lx.push(lexTableNameEnd)
+ return lexValue // reuse string lexing
+ default:
+ return lexBareTableName
+ }
+}
+
+// lexBareTableName lexes the name of a table. It assumes that at least one
+// valid character for the table has already been read.
+func lexBareTableName(lx *lexer) stateFn {
+ r := lx.next()
+ if isBareKeyChar(r) {
+ return lexBareTableName
+ }
+ lx.backup()
+ lx.emit(itemText)
+ return lexTableNameEnd
+}
+
+// lexTableNameEnd reads the end of a piece of a table name, optionally
+// consuming whitespace.
+func lexTableNameEnd(lx *lexer) stateFn {
+ lx.skip(isWhitespace)
+ switch r := lx.next(); {
+ case isWhitespace(r):
+ return lexTableNameEnd
+ case r == tableSep:
+ lx.ignore()
+ return lexTableNameStart
+ case r == tableEnd:
+ return lx.pop()
+ default:
+ return lx.errorf("expected '.' or ']' to end table name, "+
+ "but got %q instead", r)
+ }
+}
+
+// lexKeyStart consumes a key name up until the first non-whitespace character.
+// lexKeyStart will ignore whitespace.
+func lexKeyStart(lx *lexer) stateFn {
+ r := lx.peek()
+ switch {
+ case r == keySep:
+ return lx.errorf("unexpected key separator %q", keySep)
+ case isWhitespace(r) || isNL(r):
+ lx.next()
+ return lexSkip(lx, lexKeyStart)
+ case r == stringStart || r == rawStringStart:
+ lx.ignore()
+ lx.emit(itemKeyStart)
+ lx.push(lexKeyEnd)
+ return lexValue // reuse string lexing
+ default:
+ lx.ignore()
+ lx.emit(itemKeyStart)
+ return lexBareKey
+ }
+}
+
+// lexBareKey consumes the text of a bare key. Assumes that the first character
+// (which is not whitespace) has not yet been consumed.
+func lexBareKey(lx *lexer) stateFn {
+ switch r := lx.next(); {
+ case isBareKeyChar(r):
+ return lexBareKey
+ case isWhitespace(r):
+ lx.backup()
+ lx.emit(itemText)
+ return lexKeyEnd
+ case r == keySep:
+ lx.backup()
+ lx.emit(itemText)
+ return lexKeyEnd
+ default:
+ return lx.errorf("bare keys cannot contain %q", r)
+ }
+}
+
+// lexKeyEnd consumes the end of a key and trims whitespace (up to the key
+// separator).
+func lexKeyEnd(lx *lexer) stateFn {
+ switch r := lx.next(); {
+ case r == keySep:
+ return lexSkip(lx, lexValue)
+ case isWhitespace(r):
+ return lexSkip(lx, lexKeyEnd)
+ default:
+ return lx.errorf("expected key separator %q, but got %q instead",
+ keySep, r)
+ }
+}
+
+// lexValue starts the consumption of a value anywhere a value is expected.
+// lexValue will ignore whitespace.
+// After a value is lexed, the last state on the next is popped and returned.
+func lexValue(lx *lexer) stateFn {
+ // We allow whitespace to precede a value, but NOT newlines.
+ // In array syntax, the array states are responsible for ignoring newlines.
+ r := lx.next()
+ switch {
+ case isWhitespace(r):
+ return lexSkip(lx, lexValue)
+ case isDigit(r):
+ lx.backup() // avoid an extra state and use the same as above
+ return lexNumberOrDateStart
+ }
+ switch r {
+ case arrayStart:
+ lx.ignore()
+ lx.emit(itemArray)
+ return lexArrayValue
+ case inlineTableStart:
+ lx.ignore()
+ lx.emit(itemInlineTableStart)
+ return lexInlineTableValue
+ case stringStart:
+ if lx.accept(stringStart) {
+ if lx.accept(stringStart) {
+ lx.ignore() // Ignore """
+ return lexMultilineString
+ }
+ lx.backup()
+ }
+ lx.ignore() // ignore the '"'
+ return lexString
+ case rawStringStart:
+ if lx.accept(rawStringStart) {
+ if lx.accept(rawStringStart) {
+ lx.ignore() // Ignore """
+ return lexMultilineRawString
+ }
+ lx.backup()
+ }
+ lx.ignore() // ignore the "'"
+ return lexRawString
+ case '+', '-':
+ return lexNumberStart
+ case '.': // special error case, be kind to users
+ return lx.errorf("floats must start with a digit, not '.'")
+ }
+ if unicode.IsLetter(r) {
+ // Be permissive here; lexBool will give a nice error if the
+ // user wrote something like
+ // x = foo
+ // (i.e. not 'true' or 'false' but is something else word-like.)
+ lx.backup()
+ return lexBool
+ }
+ return lx.errorf("expected value but found %q instead", r)
+}
+
+// lexArrayValue consumes one value in an array. It assumes that '[' or ','
+// have already been consumed. All whitespace and newlines are ignored.
+func lexArrayValue(lx *lexer) stateFn {
+ r := lx.next()
+ switch {
+ case isWhitespace(r) || isNL(r):
+ return lexSkip(lx, lexArrayValue)
+ case r == commentStart:
+ lx.push(lexArrayValue)
+ return lexCommentStart
+ case r == comma:
+ return lx.errorf("unexpected comma")
+ case r == arrayEnd:
+ // NOTE(caleb): The spec isn't clear about whether you can have
+ // a trailing comma or not, so we'll allow it.
+ return lexArrayEnd
+ }
+
+ lx.backup()
+ lx.push(lexArrayValueEnd)
+ return lexValue
+}
+
+// lexArrayValueEnd consumes everything between the end of an array value and
+// the next value (or the end of the array): it ignores whitespace and newlines
+// and expects either a ',' or a ']'.
+func lexArrayValueEnd(lx *lexer) stateFn {
+ r := lx.next()
+ switch {
+ case isWhitespace(r) || isNL(r):
+ return lexSkip(lx, lexArrayValueEnd)
+ case r == commentStart:
+ lx.push(lexArrayValueEnd)
+ return lexCommentStart
+ case r == comma:
+ lx.ignore()
+ return lexArrayValue // move on to the next value
+ case r == arrayEnd:
+ return lexArrayEnd
+ }
+ return lx.errorf(
+ "expected a comma or array terminator %q, but got %q instead",
+ arrayEnd, r,
+ )
+}
+
+// lexArrayEnd finishes the lexing of an array.
+// It assumes that a ']' has just been consumed.
+func lexArrayEnd(lx *lexer) stateFn {
+ lx.ignore()
+ lx.emit(itemArrayEnd)
+ return lx.pop()
+}
+
+// lexInlineTableValue consumes one key/value pair in an inline table.
+// It assumes that '{' or ',' have already been consumed. Whitespace is ignored.
+func lexInlineTableValue(lx *lexer) stateFn {
+ r := lx.next()
+ switch {
+ case isWhitespace(r):
+ return lexSkip(lx, lexInlineTableValue)
+ case isNL(r):
+ return lx.errorf("newlines not allowed within inline tables")
+ case r == commentStart:
+ lx.push(lexInlineTableValue)
+ return lexCommentStart
+ case r == comma:
+ return lx.errorf("unexpected comma")
+ case r == inlineTableEnd:
+ return lexInlineTableEnd
+ }
+ lx.backup()
+ lx.push(lexInlineTableValueEnd)
+ return lexKeyStart
+}
+
+// lexInlineTableValueEnd consumes everything between the end of an inline table
+// key/value pair and the next pair (or the end of the table):
+// it ignores whitespace and expects either a ',' or a '}'.
+func lexInlineTableValueEnd(lx *lexer) stateFn {
+ r := lx.next()
+ switch {
+ case isWhitespace(r):
+ return lexSkip(lx, lexInlineTableValueEnd)
+ case isNL(r):
+ return lx.errorf("newlines not allowed within inline tables")
+ case r == commentStart:
+ lx.push(lexInlineTableValueEnd)
+ return lexCommentStart
+ case r == comma:
+ lx.ignore()
+ return lexInlineTableValue
+ case r == inlineTableEnd:
+ return lexInlineTableEnd
+ }
+ return lx.errorf("expected a comma or an inline table terminator %q, "+
+ "but got %q instead", inlineTableEnd, r)
+}
+
+// lexInlineTableEnd finishes the lexing of an inline table.
+// It assumes that a '}' has just been consumed.
+func lexInlineTableEnd(lx *lexer) stateFn {
+ lx.ignore()
+ lx.emit(itemInlineTableEnd)
+ return lx.pop()
+}
+
+// lexString consumes the inner contents of a string. It assumes that the
+// beginning '"' has already been consumed and ignored.
+func lexString(lx *lexer) stateFn {
+ r := lx.next()
+ switch {
+ case r == eof:
+ return lx.errorf("unexpected EOF")
+ case isNL(r):
+ return lx.errorf("strings cannot contain newlines")
+ case r == '\\':
+ lx.push(lexString)
+ return lexStringEscape
+ case r == stringEnd:
+ lx.backup()
+ lx.emit(itemString)
+ lx.next()
+ lx.ignore()
+ return lx.pop()
+ }
+ return lexString
+}
+
+// lexMultilineString consumes the inner contents of a string. It assumes that
+// the beginning '"""' has already been consumed and ignored.
+func lexMultilineString(lx *lexer) stateFn {
+ switch lx.next() {
+ case eof:
+ return lx.errorf("unexpected EOF")
+ case '\\':
+ return lexMultilineStringEscape
+ case stringEnd:
+ if lx.accept(stringEnd) {
+ if lx.accept(stringEnd) {
+ lx.backup()
+ lx.backup()
+ lx.backup()
+ lx.emit(itemMultilineString)
+ lx.next()
+ lx.next()
+ lx.next()
+ lx.ignore()
+ return lx.pop()
+ }
+ lx.backup()
+ }
+ }
+ return lexMultilineString
+}
+
+// lexRawString consumes a raw string. Nothing can be escaped in such a string.
+// It assumes that the beginning "'" has already been consumed and ignored.
+func lexRawString(lx *lexer) stateFn {
+ r := lx.next()
+ switch {
+ case r == eof:
+ return lx.errorf("unexpected EOF")
+ case isNL(r):
+ return lx.errorf("strings cannot contain newlines")
+ case r == rawStringEnd:
+ lx.backup()
+ lx.emit(itemRawString)
+ lx.next()
+ lx.ignore()
+ return lx.pop()
+ }
+ return lexRawString
+}
+
+// lexMultilineRawString consumes a raw string. Nothing can be escaped in such
+// a string. It assumes that the beginning "'''" has already been consumed and
+// ignored.
+func lexMultilineRawString(lx *lexer) stateFn {
+ switch lx.next() {
+ case eof:
+ return lx.errorf("unexpected EOF")
+ case rawStringEnd:
+ if lx.accept(rawStringEnd) {
+ if lx.accept(rawStringEnd) {
+ lx.backup()
+ lx.backup()
+ lx.backup()
+ lx.emit(itemRawMultilineString)
+ lx.next()
+ lx.next()
+ lx.next()
+ lx.ignore()
+ return lx.pop()
+ }
+ lx.backup()
+ }
+ }
+ return lexMultilineRawString
+}
+
+// lexMultilineStringEscape consumes an escaped character. It assumes that the
+// preceding '\\' has already been consumed.
+func lexMultilineStringEscape(lx *lexer) stateFn {
+ // Handle the special case first:
+ if isNL(lx.next()) {
+ return lexMultilineString
+ }
+ lx.backup()
+ lx.push(lexMultilineString)
+ return lexStringEscape(lx)
+}
+
+func lexStringEscape(lx *lexer) stateFn {
+ r := lx.next()
+ switch r {
+ case 'b':
+ fallthrough
+ case 't':
+ fallthrough
+ case 'n':
+ fallthrough
+ case 'f':
+ fallthrough
+ case 'r':
+ fallthrough
+ case '"':
+ fallthrough
+ case '\\':
+ return lx.pop()
+ case 'u':
+ return lexShortUnicodeEscape
+ case 'U':
+ return lexLongUnicodeEscape
+ }
+ return lx.errorf("invalid escape character %q; only the following "+
+ "escape characters are allowed: "+
+ `\b, \t, \n, \f, \r, \", \\, \uXXXX, and \UXXXXXXXX`, r)
+}
+
+func lexShortUnicodeEscape(lx *lexer) stateFn {
+ var r rune
+ for i := 0; i < 4; i++ {
+ r = lx.next()
+ if !isHexadecimal(r) {
+ return lx.errorf(`expected four hexadecimal digits after '\u', `+
+ "but got %q instead", lx.current())
+ }
+ }
+ return lx.pop()
+}
+
+func lexLongUnicodeEscape(lx *lexer) stateFn {
+ var r rune
+ for i := 0; i < 8; i++ {
+ r = lx.next()
+ if !isHexadecimal(r) {
+ return lx.errorf(`expected eight hexadecimal digits after '\U', `+
+ "but got %q instead", lx.current())
+ }
+ }
+ return lx.pop()
+}
+
+// lexNumberOrDateStart consumes either an integer, a float, or datetime.
+func lexNumberOrDateStart(lx *lexer) stateFn {
+ r := lx.next()
+ if isDigit(r) {
+ return lexNumberOrDate
+ }
+ switch r {
+ case '_':
+ return lexNumber
+ case 'e', 'E':
+ return lexFloat
+ case '.':
+ return lx.errorf("floats must start with a digit, not '.'")
+ }
+ return lx.errorf("expected a digit but got %q", r)
+}
+
+// lexNumberOrDate consumes either an integer, float or datetime.
+func lexNumberOrDate(lx *lexer) stateFn {
+ r := lx.next()
+ if isDigit(r) {
+ return lexNumberOrDate
+ }
+ switch r {
+ case '-':
+ return lexDatetime
+ case '_':
+ return lexNumber
+ case '.', 'e', 'E':
+ return lexFloat
+ }
+
+ lx.backup()
+ lx.emit(itemInteger)
+ return lx.pop()
+}
+
+// lexDatetime consumes a Datetime, to a first approximation.
+// The parser validates that it matches one of the accepted formats.
+func lexDatetime(lx *lexer) stateFn {
+ r := lx.next()
+ if isDigit(r) {
+ return lexDatetime
+ }
+ switch r {
+ case '-', 'T', ':', '.', 'Z':
+ return lexDatetime
+ }
+
+ lx.backup()
+ lx.emit(itemDatetime)
+ return lx.pop()
+}
+
+// lexNumberStart consumes either an integer or a float. It assumes that a sign
+// has already been read, but that *no* digits have been consumed.
+// lexNumberStart will move to the appropriate integer or float states.
+func lexNumberStart(lx *lexer) stateFn {
+ // We MUST see a digit. Even floats have to start with a digit.
+ r := lx.next()
+ if !isDigit(r) {
+ if r == '.' {
+ return lx.errorf("floats must start with a digit, not '.'")
+ }
+ return lx.errorf("expected a digit but got %q", r)
+ }
+ return lexNumber
+}
+
+// lexNumber consumes an integer or a float after seeing the first digit.
+func lexNumber(lx *lexer) stateFn {
+ r := lx.next()
+ if isDigit(r) {
+ return lexNumber
+ }
+ switch r {
+ case '_':
+ return lexNumber
+ case '.', 'e', 'E':
+ return lexFloat
+ }
+
+ lx.backup()
+ lx.emit(itemInteger)
+ return lx.pop()
+}
+
+// lexFloat consumes the elements of a float. It allows any sequence of
+// float-like characters, so floats emitted by the lexer are only a first
+// approximation and must be validated by the parser.
+func lexFloat(lx *lexer) stateFn {
+ r := lx.next()
+ if isDigit(r) {
+ return lexFloat
+ }
+ switch r {
+ case '_', '.', '-', '+', 'e', 'E':
+ return lexFloat
+ }
+
+ lx.backup()
+ lx.emit(itemFloat)
+ return lx.pop()
+}
+
+// lexBool consumes a bool string: 'true' or 'false.
+func lexBool(lx *lexer) stateFn {
+ var rs []rune
+ for {
+ r := lx.next()
+ if !unicode.IsLetter(r) {
+ lx.backup()
+ break
+ }
+ rs = append(rs, r)
+ }
+ s := string(rs)
+ switch s {
+ case "true", "false":
+ lx.emit(itemBool)
+ return lx.pop()
+ }
+ return lx.errorf("expected value but found %q instead", s)
+}
+
+// lexCommentStart begins the lexing of a comment. It will emit
+// itemCommentStart and consume no characters, passing control to lexComment.
+func lexCommentStart(lx *lexer) stateFn {
+ lx.ignore()
+ lx.emit(itemCommentStart)
+ return lexComment
+}
+
+// lexComment lexes an entire comment. It assumes that '#' has been consumed.
+// It will consume *up to* the first newline character, and pass control
+// back to the last state on the stack.
+func lexComment(lx *lexer) stateFn {
+ r := lx.peek()
+ if isNL(r) || r == eof {
+ lx.emit(itemText)
+ return lx.pop()
+ }
+ lx.next()
+ return lexComment
+}
+
+// lexSkip ignores all slurped input and moves on to the next state.
+func lexSkip(lx *lexer, nextState stateFn) stateFn {
+ return func(lx *lexer) stateFn {
+ lx.ignore()
+ return nextState
+ }
+}
+
+// isWhitespace returns true if `r` is a whitespace character according
+// to the spec.
+func isWhitespace(r rune) bool {
+ return r == '\t' || r == ' '
+}
+
+func isNL(r rune) bool {
+ return r == '\n' || r == '\r'
+}
+
+func isDigit(r rune) bool {
+ return r >= '0' && r <= '9'
+}
+
+func isHexadecimal(r rune) bool {
+ return (r >= '0' && r <= '9') ||
+ (r >= 'a' && r <= 'f') ||
+ (r >= 'A' && r <= 'F')
+}
+
+func isBareKeyChar(r rune) bool {
+ return (r >= 'A' && r <= 'Z') ||
+ (r >= 'a' && r <= 'z') ||
+ (r >= '0' && r <= '9') ||
+ r == '_' ||
+ r == '-'
+}
+
+func (itype itemType) String() string {
+ switch itype {
+ case itemError:
+ return "Error"
+ case itemNIL:
+ return "NIL"
+ case itemEOF:
+ return "EOF"
+ case itemText:
+ return "Text"
+ case itemString, itemRawString, itemMultilineString, itemRawMultilineString:
+ return "String"
+ case itemBool:
+ return "Bool"
+ case itemInteger:
+ return "Integer"
+ case itemFloat:
+ return "Float"
+ case itemDatetime:
+ return "DateTime"
+ case itemTableStart:
+ return "TableStart"
+ case itemTableEnd:
+ return "TableEnd"
+ case itemKeyStart:
+ return "KeyStart"
+ case itemArray:
+ return "Array"
+ case itemArrayEnd:
+ return "ArrayEnd"
+ case itemCommentStart:
+ return "CommentStart"
+ }
+ panic(fmt.Sprintf("BUG: Unknown type '%d'.", int(itype)))
+}
+
+func (item item) String() string {
+ return fmt.Sprintf("(%s, %s)", item.typ.String(), item.val)
+}
diff --git a/src/dma/vendor/github.com/BurntSushi/toml/parse.go b/src/dma/vendor/github.com/BurntSushi/toml/parse.go
new file mode 100644
index 00000000..50869ef9
--- /dev/null
+++ b/src/dma/vendor/github.com/BurntSushi/toml/parse.go
@@ -0,0 +1,592 @@
+package toml
+
+import (
+ "fmt"
+ "strconv"
+ "strings"
+ "time"
+ "unicode"
+ "unicode/utf8"
+)
+
+type parser struct {
+ mapping map[string]interface{}
+ types map[string]tomlType
+ lx *lexer
+
+ // A list of keys in the order that they appear in the TOML data.
+ ordered []Key
+
+ // the full key for the current hash in scope
+ context Key
+
+ // the base key name for everything except hashes
+ currentKey string
+
+ // rough approximation of line number
+ approxLine int
+
+ // A map of 'key.group.names' to whether they were created implicitly.
+ implicits map[string]bool
+}
+
+type parseError string
+
+func (pe parseError) Error() string {
+ return string(pe)
+}
+
+func parse(data string) (p *parser, err error) {
+ defer func() {
+ if r := recover(); r != nil {
+ var ok bool
+ if err, ok = r.(parseError); ok {
+ return
+ }
+ panic(r)
+ }
+ }()
+
+ p = &parser{
+ mapping: make(map[string]interface{}),
+ types: make(map[string]tomlType),
+ lx: lex(data),
+ ordered: make([]Key, 0),
+ implicits: make(map[string]bool),
+ }
+ for {
+ item := p.next()
+ if item.typ == itemEOF {
+ break
+ }
+ p.topLevel(item)
+ }
+
+ return p, nil
+}
+
+func (p *parser) panicf(format string, v ...interface{}) {
+ msg := fmt.Sprintf("Near line %d (last key parsed '%s'): %s",
+ p.approxLine, p.current(), fmt.Sprintf(format, v...))
+ panic(parseError(msg))
+}
+
+func (p *parser) next() item {
+ it := p.lx.nextItem()
+ if it.typ == itemError {
+ p.panicf("%s", it.val)
+ }
+ return it
+}
+
+func (p *parser) bug(format string, v ...interface{}) {
+ panic(fmt.Sprintf("BUG: "+format+"\n\n", v...))
+}
+
+func (p *parser) expect(typ itemType) item {
+ it := p.next()
+ p.assertEqual(typ, it.typ)
+ return it
+}
+
+func (p *parser) assertEqual(expected, got itemType) {
+ if expected != got {
+ p.bug("Expected '%s' but got '%s'.", expected, got)
+ }
+}
+
+func (p *parser) topLevel(item item) {
+ switch item.typ {
+ case itemCommentStart:
+ p.approxLine = item.line
+ p.expect(itemText)
+ case itemTableStart:
+ kg := p.next()
+ p.approxLine = kg.line
+
+ var key Key
+ for ; kg.typ != itemTableEnd && kg.typ != itemEOF; kg = p.next() {
+ key = append(key, p.keyString(kg))
+ }
+ p.assertEqual(itemTableEnd, kg.typ)
+
+ p.establishContext(key, false)
+ p.setType("", tomlHash)
+ p.ordered = append(p.ordered, key)
+ case itemArrayTableStart:
+ kg := p.next()
+ p.approxLine = kg.line
+
+ var key Key
+ for ; kg.typ != itemArrayTableEnd && kg.typ != itemEOF; kg = p.next() {
+ key = append(key, p.keyString(kg))
+ }
+ p.assertEqual(itemArrayTableEnd, kg.typ)
+
+ p.establishContext(key, true)
+ p.setType("", tomlArrayHash)
+ p.ordered = append(p.ordered, key)
+ case itemKeyStart:
+ kname := p.next()
+ p.approxLine = kname.line
+ p.currentKey = p.keyString(kname)
+
+ val, typ := p.value(p.next())
+ p.setValue(p.currentKey, val)
+ p.setType(p.currentKey, typ)
+ p.ordered = append(p.ordered, p.context.add(p.currentKey))
+ p.currentKey = ""
+ default:
+ p.bug("Unexpected type at top level: %s", item.typ)
+ }
+}
+
+// Gets a string for a key (or part of a key in a table name).
+func (p *parser) keyString(it item) string {
+ switch it.typ {
+ case itemText:
+ return it.val
+ case itemString, itemMultilineString,
+ itemRawString, itemRawMultilineString:
+ s, _ := p.value(it)
+ return s.(string)
+ default:
+ p.bug("Unexpected key type: %s", it.typ)
+ panic("unreachable")
+ }
+}
+
+// value translates an expected value from the lexer into a Go value wrapped
+// as an empty interface.
+func (p *parser) value(it item) (interface{}, tomlType) {
+ switch it.typ {
+ case itemString:
+ return p.replaceEscapes(it.val), p.typeOfPrimitive(it)
+ case itemMultilineString:
+ trimmed := stripFirstNewline(stripEscapedWhitespace(it.val))
+ return p.replaceEscapes(trimmed), p.typeOfPrimitive(it)
+ case itemRawString:
+ return it.val, p.typeOfPrimitive(it)
+ case itemRawMultilineString:
+ return stripFirstNewline(it.val), p.typeOfPrimitive(it)
+ case itemBool:
+ switch it.val {
+ case "true":
+ return true, p.typeOfPrimitive(it)
+ case "false":
+ return false, p.typeOfPrimitive(it)
+ }
+ p.bug("Expected boolean value, but got '%s'.", it.val)
+ case itemInteger:
+ if !numUnderscoresOK(it.val) {
+ p.panicf("Invalid integer %q: underscores must be surrounded by digits",
+ it.val)
+ }
+ val := strings.Replace(it.val, "_", "", -1)
+ num, err := strconv.ParseInt(val, 10, 64)
+ if err != nil {
+ // Distinguish integer values. Normally, it'd be a bug if the lexer
+ // provides an invalid integer, but it's possible that the number is
+ // out of range of valid values (which the lexer cannot determine).
+ // So mark the former as a bug but the latter as a legitimate user
+ // error.
+ if e, ok := err.(*strconv.NumError); ok &&
+ e.Err == strconv.ErrRange {
+
+ p.panicf("Integer '%s' is out of the range of 64-bit "+
+ "signed integers.", it.val)
+ } else {
+ p.bug("Expected integer value, but got '%s'.", it.val)
+ }
+ }
+ return num, p.typeOfPrimitive(it)
+ case itemFloat:
+ parts := strings.FieldsFunc(it.val, func(r rune) bool {
+ switch r {
+ case '.', 'e', 'E':
+ return true
+ }
+ return false
+ })
+ for _, part := range parts {
+ if !numUnderscoresOK(part) {
+ p.panicf("Invalid float %q: underscores must be "+
+ "surrounded by digits", it.val)
+ }
+ }
+ if !numPeriodsOK(it.val) {
+ // As a special case, numbers like '123.' or '1.e2',
+ // which are valid as far as Go/strconv are concerned,
+ // must be rejected because TOML says that a fractional
+ // part consists of '.' followed by 1+ digits.
+ p.panicf("Invalid float %q: '.' must be followed "+
+ "by one or more digits", it.val)
+ }
+ val := strings.Replace(it.val, "_", "", -1)
+ num, err := strconv.ParseFloat(val, 64)
+ if err != nil {
+ if e, ok := err.(*strconv.NumError); ok &&
+ e.Err == strconv.ErrRange {
+
+ p.panicf("Float '%s' is out of the range of 64-bit "+
+ "IEEE-754 floating-point numbers.", it.val)
+ } else {
+ p.panicf("Invalid float value: %q", it.val)
+ }
+ }
+ return num, p.typeOfPrimitive(it)
+ case itemDatetime:
+ var t time.Time
+ var ok bool
+ var err error
+ for _, format := range []string{
+ "2006-01-02T15:04:05Z07:00",
+ "2006-01-02T15:04:05",
+ "2006-01-02",
+ } {
+ t, err = time.ParseInLocation(format, it.val, time.Local)
+ if err == nil {
+ ok = true
+ break
+ }
+ }
+ if !ok {
+ p.panicf("Invalid TOML Datetime: %q.", it.val)
+ }
+ return t, p.typeOfPrimitive(it)
+ case itemArray:
+ array := make([]interface{}, 0)
+ types := make([]tomlType, 0)
+
+ for it = p.next(); it.typ != itemArrayEnd; it = p.next() {
+ if it.typ == itemCommentStart {
+ p.expect(itemText)
+ continue
+ }
+
+ val, typ := p.value(it)
+ array = append(array, val)
+ types = append(types, typ)
+ }
+ return array, p.typeOfArray(types)
+ case itemInlineTableStart:
+ var (
+ hash = make(map[string]interface{})
+ outerContext = p.context
+ outerKey = p.currentKey
+ )
+
+ p.context = append(p.context, p.currentKey)
+ p.currentKey = ""
+ for it := p.next(); it.typ != itemInlineTableEnd; it = p.next() {
+ if it.typ != itemKeyStart {
+ p.bug("Expected key start but instead found %q, around line %d",
+ it.val, p.approxLine)
+ }
+ if it.typ == itemCommentStart {
+ p.expect(itemText)
+ continue
+ }
+
+ // retrieve key
+ k := p.next()
+ p.approxLine = k.line
+ kname := p.keyString(k)
+
+ // retrieve value
+ p.currentKey = kname
+ val, typ := p.value(p.next())
+ // make sure we keep metadata up to date
+ p.setType(kname, typ)
+ p.ordered = append(p.ordered, p.context.add(p.currentKey))
+ hash[kname] = val
+ }
+ p.context = outerContext
+ p.currentKey = outerKey
+ return hash, tomlHash
+ }
+ p.bug("Unexpected value type: %s", it.typ)
+ panic("unreachable")
+}
+
+// numUnderscoresOK checks whether each underscore in s is surrounded by
+// characters that are not underscores.
+func numUnderscoresOK(s string) bool {
+ accept := false
+ for _, r := range s {
+ if r == '_' {
+ if !accept {
+ return false
+ }
+ accept = false
+ continue
+ }
+ accept = true
+ }
+ return accept
+}
+
+// numPeriodsOK checks whether every period in s is followed by a digit.
+func numPeriodsOK(s string) bool {
+ period := false
+ for _, r := range s {
+ if period && !isDigit(r) {
+ return false
+ }
+ period = r == '.'
+ }
+ return !period
+}
+
+// establishContext sets the current context of the parser,
+// where the context is either a hash or an array of hashes. Which one is
+// set depends on the value of the `array` parameter.
+//
+// Establishing the context also makes sure that the key isn't a duplicate, and
+// will create implicit hashes automatically.
+func (p *parser) establishContext(key Key, array bool) {
+ var ok bool
+
+ // Always start at the top level and drill down for our context.
+ hashContext := p.mapping
+ keyContext := make(Key, 0)
+
+ // We only need implicit hashes for key[0:-1]
+ for _, k := range key[0 : len(key)-1] {
+ _, ok = hashContext[k]
+ keyContext = append(keyContext, k)
+
+ // No key? Make an implicit hash and move on.
+ if !ok {
+ p.addImplicit(keyContext)
+ hashContext[k] = make(map[string]interface{})
+ }
+
+ // If the hash context is actually an array of tables, then set
+ // the hash context to the last element in that array.
+ //
+ // Otherwise, it better be a table, since this MUST be a key group (by
+ // virtue of it not being the last element in a key).
+ switch t := hashContext[k].(type) {
+ case []map[string]interface{}:
+ hashContext = t[len(t)-1]
+ case map[string]interface{}:
+ hashContext = t
+ default:
+ p.panicf("Key '%s' was already created as a hash.", keyContext)
+ }
+ }
+
+ p.context = keyContext
+ if array {
+ // If this is the first element for this array, then allocate a new
+ // list of tables for it.
+ k := key[len(key)-1]
+ if _, ok := hashContext[k]; !ok {
+ hashContext[k] = make([]map[string]interface{}, 0, 5)
+ }
+
+ // Add a new table. But make sure the key hasn't already been used
+ // for something else.
+ if hash, ok := hashContext[k].([]map[string]interface{}); ok {
+ hashContext[k] = append(hash, make(map[string]interface{}))
+ } else {
+ p.panicf("Key '%s' was already created and cannot be used as "+
+ "an array.", keyContext)
+ }
+ } else {
+ p.setValue(key[len(key)-1], make(map[string]interface{}))
+ }
+ p.context = append(p.context, key[len(key)-1])
+}
+
+// setValue sets the given key to the given value in the current context.
+// It will make sure that the key hasn't already been defined, account for
+// implicit key groups.
+func (p *parser) setValue(key string, value interface{}) {
+ var tmpHash interface{}
+ var ok bool
+
+ hash := p.mapping
+ keyContext := make(Key, 0)
+ for _, k := range p.context {
+ keyContext = append(keyContext, k)
+ if tmpHash, ok = hash[k]; !ok {
+ p.bug("Context for key '%s' has not been established.", keyContext)
+ }
+ switch t := tmpHash.(type) {
+ case []map[string]interface{}:
+ // The context is a table of hashes. Pick the most recent table
+ // defined as the current hash.
+ hash = t[len(t)-1]
+ case map[string]interface{}:
+ hash = t
+ default:
+ p.bug("Expected hash to have type 'map[string]interface{}', but "+
+ "it has '%T' instead.", tmpHash)
+ }
+ }
+ keyContext = append(keyContext, key)
+
+ if _, ok := hash[key]; ok {
+ // Typically, if the given key has already been set, then we have
+ // to raise an error since duplicate keys are disallowed. However,
+ // it's possible that a key was previously defined implicitly. In this
+ // case, it is allowed to be redefined concretely. (See the
+ // `tests/valid/implicit-and-explicit-after.toml` test in `toml-test`.)
+ //
+ // But we have to make sure to stop marking it as an implicit. (So that
+ // another redefinition provokes an error.)
+ //
+ // Note that since it has already been defined (as a hash), we don't
+ // want to overwrite it. So our business is done.
+ if p.isImplicit(keyContext) {
+ p.removeImplicit(keyContext)
+ return
+ }
+
+ // Otherwise, we have a concrete key trying to override a previous
+ // key, which is *always* wrong.
+ p.panicf("Key '%s' has already been defined.", keyContext)
+ }
+ hash[key] = value
+}
+
+// setType sets the type of a particular value at a given key.
+// It should be called immediately AFTER setValue.
+//
+// Note that if `key` is empty, then the type given will be applied to the
+// current context (which is either a table or an array of tables).
+func (p *parser) setType(key string, typ tomlType) {
+ keyContext := make(Key, 0, len(p.context)+1)
+ for _, k := range p.context {
+ keyContext = append(keyContext, k)
+ }
+ if len(key) > 0 { // allow type setting for hashes
+ keyContext = append(keyContext, key)
+ }
+ p.types[keyContext.String()] = typ
+}
+
+// addImplicit sets the given Key as having been created implicitly.
+func (p *parser) addImplicit(key Key) {
+ p.implicits[key.String()] = true
+}
+
+// removeImplicit stops tagging the given key as having been implicitly
+// created.
+func (p *parser) removeImplicit(key Key) {
+ p.implicits[key.String()] = false
+}
+
+// isImplicit returns true if the key group pointed to by the key was created
+// implicitly.
+func (p *parser) isImplicit(key Key) bool {
+ return p.implicits[key.String()]
+}
+
+// current returns the full key name of the current context.
+func (p *parser) current() string {
+ if len(p.currentKey) == 0 {
+ return p.context.String()
+ }
+ if len(p.context) == 0 {
+ return p.currentKey
+ }
+ return fmt.Sprintf("%s.%s", p.context, p.currentKey)
+}
+
+func stripFirstNewline(s string) string {
+ if len(s) == 0 || s[0] != '\n' {
+ return s
+ }
+ return s[1:]
+}
+
+func stripEscapedWhitespace(s string) string {
+ esc := strings.Split(s, "\\\n")
+ if len(esc) > 1 {
+ for i := 1; i < len(esc); i++ {
+ esc[i] = strings.TrimLeftFunc(esc[i], unicode.IsSpace)
+ }
+ }
+ return strings.Join(esc, "")
+}
+
+func (p *parser) replaceEscapes(str string) string {
+ var replaced []rune
+ s := []byte(str)
+ r := 0
+ for r < len(s) {
+ if s[r] != '\\' {
+ c, size := utf8.DecodeRune(s[r:])
+ r += size
+ replaced = append(replaced, c)
+ continue
+ }
+ r += 1
+ if r >= len(s) {
+ p.bug("Escape sequence at end of string.")
+ return ""
+ }
+ switch s[r] {
+ default:
+ p.bug("Expected valid escape code after \\, but got %q.", s[r])
+ return ""
+ case 'b':
+ replaced = append(replaced, rune(0x0008))
+ r += 1
+ case 't':
+ replaced = append(replaced, rune(0x0009))
+ r += 1
+ case 'n':
+ replaced = append(replaced, rune(0x000A))
+ r += 1
+ case 'f':
+ replaced = append(replaced, rune(0x000C))
+ r += 1
+ case 'r':
+ replaced = append(replaced, rune(0x000D))
+ r += 1
+ case '"':
+ replaced = append(replaced, rune(0x0022))
+ r += 1
+ case '\\':
+ replaced = append(replaced, rune(0x005C))
+ r += 1
+ case 'u':
+ // At this point, we know we have a Unicode escape of the form
+ // `uXXXX` at [r, r+5). (Because the lexer guarantees this
+ // for us.)
+ escaped := p.asciiEscapeToUnicode(s[r+1 : r+5])
+ replaced = append(replaced, escaped)
+ r += 5
+ case 'U':
+ // At this point, we know we have a Unicode escape of the form
+ // `uXXXX` at [r, r+9). (Because the lexer guarantees this
+ // for us.)
+ escaped := p.asciiEscapeToUnicode(s[r+1 : r+9])
+ replaced = append(replaced, escaped)
+ r += 9
+ }
+ }
+ return string(replaced)
+}
+
+func (p *parser) asciiEscapeToUnicode(bs []byte) rune {
+ s := string(bs)
+ hex, err := strconv.ParseUint(strings.ToLower(s), 16, 32)
+ if err != nil {
+ p.bug("Could not parse '%s' as a hexadecimal number, but the "+
+ "lexer claims it's OK: %s", s, err)
+ }
+ if !utf8.ValidRune(rune(hex)) {
+ p.panicf("Escaped character '\\u%s' is not valid UTF-8.", s)
+ }
+ return rune(hex)
+}
+
+func isStringType(ty itemType) bool {
+ return ty == itemString || ty == itemMultilineString ||
+ ty == itemRawString || ty == itemRawMultilineString
+}
diff --git a/src/dma/vendor/github.com/BurntSushi/toml/session.vim b/src/dma/vendor/github.com/BurntSushi/toml/session.vim
new file mode 100644
index 00000000..562164be
--- /dev/null
+++ b/src/dma/vendor/github.com/BurntSushi/toml/session.vim
@@ -0,0 +1 @@
+au BufWritePost *.go silent!make tags > /dev/null 2>&1
diff --git a/src/dma/vendor/github.com/BurntSushi/toml/type_check.go b/src/dma/vendor/github.com/BurntSushi/toml/type_check.go
new file mode 100644
index 00000000..c73f8afc
--- /dev/null
+++ b/src/dma/vendor/github.com/BurntSushi/toml/type_check.go
@@ -0,0 +1,91 @@
+package toml
+
+// tomlType represents any Go type that corresponds to a TOML type.
+// While the first draft of the TOML spec has a simplistic type system that
+// probably doesn't need this level of sophistication, we seem to be militating
+// toward adding real composite types.
+type tomlType interface {
+ typeString() string
+}
+
+// typeEqual accepts any two types and returns true if they are equal.
+func typeEqual(t1, t2 tomlType) bool {
+ if t1 == nil || t2 == nil {
+ return false
+ }
+ return t1.typeString() == t2.typeString()
+}
+
+func typeIsHash(t tomlType) bool {
+ return typeEqual(t, tomlHash) || typeEqual(t, tomlArrayHash)
+}
+
+type tomlBaseType string
+
+func (btype tomlBaseType) typeString() string {
+ return string(btype)
+}
+
+func (btype tomlBaseType) String() string {
+ return btype.typeString()
+}
+
+var (
+ tomlInteger tomlBaseType = "Integer"
+ tomlFloat tomlBaseType = "Float"
+ tomlDatetime tomlBaseType = "Datetime"
+ tomlString tomlBaseType = "String"
+ tomlBool tomlBaseType = "Bool"
+ tomlArray tomlBaseType = "Array"
+ tomlHash tomlBaseType = "Hash"
+ tomlArrayHash tomlBaseType = "ArrayHash"
+)
+
+// typeOfPrimitive returns a tomlType of any primitive value in TOML.
+// Primitive values are: Integer, Float, Datetime, String and Bool.
+//
+// Passing a lexer item other than the following will cause a BUG message
+// to occur: itemString, itemBool, itemInteger, itemFloat, itemDatetime.
+func (p *parser) typeOfPrimitive(lexItem item) tomlType {
+ switch lexItem.typ {
+ case itemInteger:
+ return tomlInteger
+ case itemFloat:
+ return tomlFloat
+ case itemDatetime:
+ return tomlDatetime
+ case itemString:
+ return tomlString
+ case itemMultilineString:
+ return tomlString
+ case itemRawString:
+ return tomlString
+ case itemRawMultilineString:
+ return tomlString
+ case itemBool:
+ return tomlBool
+ }
+ p.bug("Cannot infer primitive type of lex item '%s'.", lexItem)
+ panic("unreachable")
+}
+
+// typeOfArray returns a tomlType for an array given a list of types of its
+// values.
+//
+// In the current spec, if an array is homogeneous, then its type is always
+// "Array". If the array is not homogeneous, an error is generated.
+func (p *parser) typeOfArray(types []tomlType) tomlType {
+ // Empty arrays are cool.
+ if len(types) == 0 {
+ return tomlArray
+ }
+
+ theType := types[0]
+ for _, t := range types[1:] {
+ if !typeEqual(theType, t) {
+ p.panicf("Array contains values of type '%s' and '%s', but "+
+ "arrays must be homogeneous.", theType, t)
+ }
+ }
+ return tomlArray
+}
diff --git a/src/dma/vendor/github.com/BurntSushi/toml/type_fields.go b/src/dma/vendor/github.com/BurntSushi/toml/type_fields.go
new file mode 100644
index 00000000..608997c2
--- /dev/null
+++ b/src/dma/vendor/github.com/BurntSushi/toml/type_fields.go
@@ -0,0 +1,242 @@
+package toml
+
+// Struct field handling is adapted from code in encoding/json:
+//
+// Copyright 2010 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the Go distribution.
+
+import (
+ "reflect"
+ "sort"
+ "sync"
+)
+
+// A field represents a single field found in a struct.
+type field struct {
+ name string // the name of the field (`toml` tag included)
+ tag bool // whether field has a `toml` tag
+ index []int // represents the depth of an anonymous field
+ typ reflect.Type // the type of the field
+}
+
+// byName sorts field by name, breaking ties with depth,
+// then breaking ties with "name came from toml tag", then
+// breaking ties with index sequence.
+type byName []field
+
+func (x byName) Len() int { return len(x) }
+
+func (x byName) Swap(i, j int) { x[i], x[j] = x[j], x[i] }
+
+func (x byName) Less(i, j int) bool {
+ if x[i].name != x[j].name {
+ return x[i].name < x[j].name
+ }
+ if len(x[i].index) != len(x[j].index) {
+ return len(x[i].index) < len(x[j].index)
+ }
+ if x[i].tag != x[j].tag {
+ return x[i].tag
+ }
+ return byIndex(x).Less(i, j)
+}
+
+// byIndex sorts field by index sequence.
+type byIndex []field
+
+func (x byIndex) Len() int { return len(x) }
+
+func (x byIndex) Swap(i, j int) { x[i], x[j] = x[j], x[i] }
+
+func (x byIndex) Less(i, j int) bool {
+ for k, xik := range x[i].index {
+ if k >= len(x[j].index) {
+ return false
+ }
+ if xik != x[j].index[k] {
+ return xik < x[j].index[k]
+ }
+ }
+ return len(x[i].index) < len(x[j].index)
+}
+
+// typeFields returns a list of fields that TOML should recognize for the given
+// type. The algorithm is breadth-first search over the set of structs to
+// include - the top struct and then any reachable anonymous structs.
+func typeFields(t reflect.Type) []field {
+ // Anonymous fields to explore at the current level and the next.
+ current := []field{}
+ next := []field{{typ: t}}
+
+ // Count of queued names for current level and the next.
+ count := map[reflect.Type]int{}
+ nextCount := map[reflect.Type]int{}
+
+ // Types already visited at an earlier level.
+ visited := map[reflect.Type]bool{}
+
+ // Fields found.
+ var fields []field
+
+ for len(next) > 0 {
+ current, next = next, current[:0]
+ count, nextCount = nextCount, map[reflect.Type]int{}
+
+ for _, f := range current {
+ if visited[f.typ] {
+ continue
+ }
+ visited[f.typ] = true
+
+ // Scan f.typ for fields to include.
+ for i := 0; i < f.typ.NumField(); i++ {
+ sf := f.typ.Field(i)
+ if sf.PkgPath != "" && !sf.Anonymous { // unexported
+ continue
+ }
+ opts := getOptions(sf.Tag)
+ if opts.skip {
+ continue
+ }
+ index := make([]int, len(f.index)+1)
+ copy(index, f.index)
+ index[len(f.index)] = i
+
+ ft := sf.Type
+ if ft.Name() == "" && ft.Kind() == reflect.Ptr {
+ // Follow pointer.
+ ft = ft.Elem()
+ }
+
+ // Record found field and index sequence.
+ if opts.name != "" || !sf.Anonymous || ft.Kind() != reflect.Struct {
+ tagged := opts.name != ""
+ name := opts.name
+ if name == "" {
+ name = sf.Name
+ }
+ fields = append(fields, field{name, tagged, index, ft})
+ if count[f.typ] > 1 {
+ // If there were multiple instances, add a second,
+ // so that the annihilation code will see a duplicate.
+ // It only cares about the distinction between 1 or 2,
+ // so don't bother generating any more copies.
+ fields = append(fields, fields[len(fields)-1])
+ }
+ continue
+ }
+
+ // Record new anonymous struct to explore in next round.
+ nextCount[ft]++
+ if nextCount[ft] == 1 {
+ f := field{name: ft.Name(), index: index, typ: ft}
+ next = append(next, f)
+ }
+ }
+ }
+ }
+
+ sort.Sort(byName(fields))
+
+ // Delete all fields that are hidden by the Go rules for embedded fields,
+ // except that fields with TOML tags are promoted.
+
+ // The fields are sorted in primary order of name, secondary order
+ // of field index length. Loop over names; for each name, delete
+ // hidden fields by choosing the one dominant field that survives.
+ out := fields[:0]
+ for advance, i := 0, 0; i < len(fields); i += advance {
+ // One iteration per name.
+ // Find the sequence of fields with the name of this first field.
+ fi := fields[i]
+ name := fi.name
+ for advance = 1; i+advance < len(fields); advance++ {
+ fj := fields[i+advance]
+ if fj.name != name {
+ break
+ }
+ }
+ if advance == 1 { // Only one field with this name
+ out = append(out, fi)
+ continue
+ }
+ dominant, ok := dominantField(fields[i : i+advance])
+ if ok {
+ out = append(out, dominant)
+ }
+ }
+
+ fields = out
+ sort.Sort(byIndex(fields))
+
+ return fields
+}
+
+// dominantField looks through the fields, all of which are known to
+// have the same name, to find the single field that dominates the
+// others using Go's embedding rules, modified by the presence of
+// TOML tags. If there are multiple top-level fields, the boolean
+// will be false: This condition is an error in Go and we skip all
+// the fields.
+func dominantField(fields []field) (field, bool) {
+ // The fields are sorted in increasing index-length order. The winner
+ // must therefore be one with the shortest index length. Drop all
+ // longer entries, which is easy: just truncate the slice.
+ length := len(fields[0].index)
+ tagged := -1 // Index of first tagged field.
+ for i, f := range fields {
+ if len(f.index) > length {
+ fields = fields[:i]
+ break
+ }
+ if f.tag {
+ if tagged >= 0 {
+ // Multiple tagged fields at the same level: conflict.
+ // Return no field.
+ return field{}, false
+ }
+ tagged = i
+ }
+ }
+ if tagged >= 0 {
+ return fields[tagged], true
+ }
+ // All remaining fields have the same length. If there's more than one,
+ // we have a conflict (two fields named "X" at the same level) and we
+ // return no field.
+ if len(fields) > 1 {
+ return field{}, false
+ }
+ return fields[0], true
+}
+
+var fieldCache struct {
+ sync.RWMutex
+ m map[reflect.Type][]field
+}
+
+// cachedTypeFields is like typeFields but uses a cache to avoid repeated work.
+func cachedTypeFields(t reflect.Type) []field {
+ fieldCache.RLock()
+ f := fieldCache.m[t]
+ fieldCache.RUnlock()
+ if f != nil {
+ return f
+ }
+
+ // Compute fields without lock.
+ // Might duplicate effort but won't hold other computations back.
+ f = typeFields(t)
+ if f == nil {
+ f = []field{}
+ }
+
+ fieldCache.Lock()
+ if fieldCache.m == nil {
+ fieldCache.m = map[reflect.Type][]field{}
+ }
+ fieldCache.m[t] = f
+ fieldCache.Unlock()
+ return f
+}
diff --git a/src/dma/vendor/github.com/go-redis/redis/.gitignore b/src/dma/vendor/github.com/go-redis/redis/.gitignore
new file mode 100644
index 00000000..ebfe903b
--- /dev/null
+++ b/src/dma/vendor/github.com/go-redis/redis/.gitignore
@@ -0,0 +1,2 @@
+*.rdb
+testdata/*/
diff --git a/src/dma/vendor/github.com/go-redis/redis/.travis.yml b/src/dma/vendor/github.com/go-redis/redis/.travis.yml
new file mode 100644
index 00000000..39ffc2be
--- /dev/null
+++ b/src/dma/vendor/github.com/go-redis/redis/.travis.yml
@@ -0,0 +1,20 @@
+sudo: false
+language: go
+
+services:
+ - redis-server
+
+go:
+ - 1.7.x
+ - 1.8.x
+ - 1.9.x
+ - 1.10.x
+ - tip
+
+matrix:
+ allow_failures:
+ - go: tip
+
+install:
+ - go get github.com/onsi/ginkgo
+ - go get github.com/onsi/gomega
diff --git a/src/dma/vendor/github.com/go-redis/redis/CHANGELOG.md b/src/dma/vendor/github.com/go-redis/redis/CHANGELOG.md
new file mode 100644
index 00000000..cb0e1b8e
--- /dev/null
+++ b/src/dma/vendor/github.com/go-redis/redis/CHANGELOG.md
@@ -0,0 +1,12 @@
+# Changelog
+
+## v6.13
+
+- Ring got new options called `HashReplicas` and `Hash`. It is recommended to set `HashReplicas = 1000` for better keys distribution between shards.
+- Cluster client was optimized to use much less memory when reloading cluster state.
+- PubSub.ReceiveMessage is re-worked to not use ReceiveTimeout so it does not lose data when timeout occurres. In most cases it is recommended to use PubSub.Channel instead.
+- Dialer.KeepAlive is set to 5 minutes by default.
+
+## v6.12
+
+- ClusterClient got new option called `ClusterSlots` which allows to build cluster of normal Redis Servers that don't have cluster mode enabled. See https://godoc.org/github.com/go-redis/redis#example-NewClusterClient--ManualSetup
diff --git a/src/dma/vendor/github.com/go-redis/redis/LICENSE b/src/dma/vendor/github.com/go-redis/redis/LICENSE
new file mode 100644
index 00000000..298bed9b
--- /dev/null
+++ b/src/dma/vendor/github.com/go-redis/redis/LICENSE
@@ -0,0 +1,25 @@
+Copyright (c) 2013 The github.com/go-redis/redis Authors.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+ * Redistributions of source code must retain the above copyright
+notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above
+copyright notice, this list of conditions and the following disclaimer
+in the documentation and/or other materials provided with the
+distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/src/dma/vendor/github.com/go-redis/redis/Makefile b/src/dma/vendor/github.com/go-redis/redis/Makefile
new file mode 100644
index 00000000..1fbdac91
--- /dev/null
+++ b/src/dma/vendor/github.com/go-redis/redis/Makefile
@@ -0,0 +1,20 @@
+all: testdeps
+ go test ./...
+ go test ./... -short -race
+ env GOOS=linux GOARCH=386 go test ./...
+ go vet
+
+testdeps: testdata/redis/src/redis-server
+
+bench: testdeps
+ go test ./... -test.run=NONE -test.bench=. -test.benchmem
+
+.PHONY: all test testdeps bench
+
+testdata/redis:
+ mkdir -p $@
+ wget -qO- https://github.com/antirez/redis/archive/unstable.tar.gz | tar xvz --strip-components=1 -C $@
+
+testdata/redis/src/redis-server: testdata/redis
+ sed -i.bak 's/libjemalloc.a/libjemalloc.a -lrt/g' $</src/Makefile
+ cd $< && make all
diff --git a/src/dma/vendor/github.com/go-redis/redis/README.md b/src/dma/vendor/github.com/go-redis/redis/README.md
new file mode 100644
index 00000000..7d05b446
--- /dev/null
+++ b/src/dma/vendor/github.com/go-redis/redis/README.md
@@ -0,0 +1,146 @@
+# Redis client for Golang
+
+[![Build Status](https://travis-ci.org/go-redis/redis.png?branch=master)](https://travis-ci.org/go-redis/redis)
+[![GoDoc](https://godoc.org/github.com/go-redis/redis?status.svg)](https://godoc.org/github.com/go-redis/redis)
+[![Airbrake](https://img.shields.io/badge/kudos-airbrake.io-orange.svg)](https://airbrake.io)
+
+Supports:
+
+- Redis 3 commands except QUIT, MONITOR, SLOWLOG and SYNC.
+- Automatic connection pooling with [circuit breaker](https://en.wikipedia.org/wiki/Circuit_breaker_design_pattern) support.
+- [Pub/Sub](https://godoc.org/github.com/go-redis/redis#PubSub).
+- [Transactions](https://godoc.org/github.com/go-redis/redis#Multi).
+- [Pipeline](https://godoc.org/github.com/go-redis/redis#example-Client-Pipeline) and [TxPipeline](https://godoc.org/github.com/go-redis/redis#example-Client-TxPipeline).
+- [Scripting](https://godoc.org/github.com/go-redis/redis#Script).
+- [Timeouts](https://godoc.org/github.com/go-redis/redis#Options).
+- [Redis Sentinel](https://godoc.org/github.com/go-redis/redis#NewFailoverClient).
+- [Redis Cluster](https://godoc.org/github.com/go-redis/redis#NewClusterClient).
+- [Cluster of Redis Servers](https://godoc.org/github.com/go-redis/redis#example-NewClusterClient--ManualSetup) without using cluster mode and Redis Sentinel.
+- [Ring](https://godoc.org/github.com/go-redis/redis#NewRing).
+- [Instrumentation](https://godoc.org/github.com/go-redis/redis#ex-package--Instrumentation).
+- [Cache friendly](https://github.com/go-redis/cache).
+- [Rate limiting](https://github.com/go-redis/redis_rate).
+- [Distributed Locks](https://github.com/bsm/redis-lock).
+
+API docs: https://godoc.org/github.com/go-redis/redis.
+Examples: https://godoc.org/github.com/go-redis/redis#pkg-examples.
+
+## Installation
+
+Install:
+
+```shell
+go get -u github.com/go-redis/redis
+```
+
+Import:
+
+```go
+import "github.com/go-redis/redis"
+```
+
+## Quickstart
+
+```go
+func ExampleNewClient() {
+ client := redis.NewClient(&redis.Options{
+ Addr: "localhost:6379",
+ Password: "", // no password set
+ DB: 0, // use default DB
+ })
+
+ pong, err := client.Ping().Result()
+ fmt.Println(pong, err)
+ // Output: PONG <nil>
+}
+
+func ExampleClient() {
+ err := client.Set("key", "value", 0).Err()
+ if err != nil {
+ panic(err)
+ }
+
+ val, err := client.Get("key").Result()
+ if err != nil {
+ panic(err)
+ }
+ fmt.Println("key", val)
+
+ val2, err := client.Get("key2").Result()
+ if err == redis.Nil {
+ fmt.Println("key2 does not exist")
+ } else if err != nil {
+ panic(err)
+ } else {
+ fmt.Println("key2", val2)
+ }
+ // Output: key value
+ // key2 does not exist
+}
+```
+
+## Howto
+
+Please go through [examples](https://godoc.org/github.com/go-redis/redis#pkg-examples) to get an idea how to use this package.
+
+## Look and feel
+
+Some corner cases:
+
+```go
+// SET key value EX 10 NX
+set, err := client.SetNX("key", "value", 10*time.Second).Result()
+
+// SORT list LIMIT 0 2 ASC
+vals, err := client.Sort("list", redis.Sort{Offset: 0, Count: 2, Order: "ASC"}).Result()
+
+// ZRANGEBYSCORE zset -inf +inf WITHSCORES LIMIT 0 2
+vals, err := client.ZRangeByScoreWithScores("zset", redis.ZRangeBy{
+ Min: "-inf",
+ Max: "+inf",
+ Offset: 0,
+ Count: 2,
+}).Result()
+
+// ZINTERSTORE out 2 zset1 zset2 WEIGHTS 2 3 AGGREGATE SUM
+vals, err := client.ZInterStore("out", redis.ZStore{Weights: []int64{2, 3}}, "zset1", "zset2").Result()
+
+// EVAL "return {KEYS[1],ARGV[1]}" 1 "key" "hello"
+vals, err := client.Eval("return {KEYS[1],ARGV[1]}", []string{"key"}, "hello").Result()
+```
+
+## Benchmark
+
+go-redis vs redigo:
+
+```
+BenchmarkSetGoRedis10Conns64Bytes-4 200000 7621 ns/op 210 B/op 6 allocs/op
+BenchmarkSetGoRedis100Conns64Bytes-4 200000 7554 ns/op 210 B/op 6 allocs/op
+BenchmarkSetGoRedis10Conns1KB-4 200000 7697 ns/op 210 B/op 6 allocs/op
+BenchmarkSetGoRedis100Conns1KB-4 200000 7688 ns/op 210 B/op 6 allocs/op
+BenchmarkSetGoRedis10Conns10KB-4 200000 9214 ns/op 210 B/op 6 allocs/op
+BenchmarkSetGoRedis100Conns10KB-4 200000 9181 ns/op 210 B/op 6 allocs/op
+BenchmarkSetGoRedis10Conns1MB-4 2000 583242 ns/op 2337 B/op 6 allocs/op
+BenchmarkSetGoRedis100Conns1MB-4 2000 583089 ns/op 2338 B/op 6 allocs/op
+BenchmarkSetRedigo10Conns64Bytes-4 200000 7576 ns/op 208 B/op 7 allocs/op
+BenchmarkSetRedigo100Conns64Bytes-4 200000 7782 ns/op 208 B/op 7 allocs/op
+BenchmarkSetRedigo10Conns1KB-4 200000 7958 ns/op 208 B/op 7 allocs/op
+BenchmarkSetRedigo100Conns1KB-4 200000 7725 ns/op 208 B/op 7 allocs/op
+BenchmarkSetRedigo10Conns10KB-4 100000 18442 ns/op 208 B/op 7 allocs/op
+BenchmarkSetRedigo100Conns10KB-4 100000 18818 ns/op 208 B/op 7 allocs/op
+BenchmarkSetRedigo10Conns1MB-4 2000 668829 ns/op 226 B/op 7 allocs/op
+BenchmarkSetRedigo100Conns1MB-4 2000 679542 ns/op 226 B/op 7 allocs/op
+```
+
+Redis Cluster:
+
+```
+BenchmarkRedisPing-4 200000 6983 ns/op 116 B/op 4 allocs/op
+BenchmarkRedisClusterPing-4 100000 11535 ns/op 117 B/op 4 allocs/op
+```
+
+## See also
+
+- [Golang PostgreSQL ORM](https://github.com/go-pg/pg)
+- [Golang msgpack](https://github.com/vmihailenco/msgpack)
+- [Golang message task queue](https://github.com/go-msgqueue/msgqueue)
diff --git a/src/dma/vendor/github.com/go-redis/redis/cluster.go b/src/dma/vendor/github.com/go-redis/redis/cluster.go
new file mode 100644
index 00000000..7a1af143
--- /dev/null
+++ b/src/dma/vendor/github.com/go-redis/redis/cluster.go
@@ -0,0 +1,1624 @@
+package redis
+
+import (
+ "context"
+ "crypto/tls"
+ "errors"
+ "fmt"
+ "math"
+ "math/rand"
+ "net"
+ "sort"
+ "sync"
+ "sync/atomic"
+ "time"
+
+ "github.com/go-redis/redis/internal"
+ "github.com/go-redis/redis/internal/hashtag"
+ "github.com/go-redis/redis/internal/pool"
+ "github.com/go-redis/redis/internal/proto"
+ "github.com/go-redis/redis/internal/singleflight"
+)
+
+var errClusterNoNodes = fmt.Errorf("redis: cluster has no nodes")
+
+// ClusterOptions are used to configure a cluster client and should be
+// passed to NewClusterClient.
+type ClusterOptions struct {
+ // A seed list of host:port addresses of cluster nodes.
+ Addrs []string
+
+ // The maximum number of retries before giving up. Command is retried
+ // on network errors and MOVED/ASK redirects.
+ // Default is 8 retries.
+ MaxRedirects int
+
+ // Enables read-only commands on slave nodes.
+ ReadOnly bool
+ // Allows routing read-only commands to the closest master or slave node.
+ // It automatically enables ReadOnly.
+ RouteByLatency bool
+ // Allows routing read-only commands to the random master or slave node.
+ // It automatically enables ReadOnly.
+ RouteRandomly bool
+
+ // Optional function that returns cluster slots information.
+ // It is useful to manually create cluster of standalone Redis servers
+ // and load-balance read/write operations between master and slaves.
+ // It can use service like ZooKeeper to maintain configuration information
+ // and Cluster.ReloadState to manually trigger state reloading.
+ ClusterSlots func() ([]ClusterSlot, error)
+
+ // Following options are copied from Options struct.
+
+ OnConnect func(*Conn) error
+
+ MaxRetries int
+ MinRetryBackoff time.Duration
+ MaxRetryBackoff time.Duration
+ Password string
+
+ DialTimeout time.Duration
+ ReadTimeout time.Duration
+ WriteTimeout time.Duration
+
+ // PoolSize applies per cluster node and not for the whole cluster.
+ PoolSize int
+ PoolTimeout time.Duration
+ IdleTimeout time.Duration
+ IdleCheckFrequency time.Duration
+
+ TLSConfig *tls.Config
+}
+
+func (opt *ClusterOptions) init() {
+ if opt.MaxRedirects == -1 {
+ opt.MaxRedirects = 0
+ } else if opt.MaxRedirects == 0 {
+ opt.MaxRedirects = 8
+ }
+
+ if opt.RouteByLatency || opt.RouteRandomly {
+ opt.ReadOnly = true
+ }
+
+ switch opt.ReadTimeout {
+ case -1:
+ opt.ReadTimeout = 0
+ case 0:
+ opt.ReadTimeout = 3 * time.Second
+ }
+ switch opt.WriteTimeout {
+ case -1:
+ opt.WriteTimeout = 0
+ case 0:
+ opt.WriteTimeout = opt.ReadTimeout
+ }
+
+ switch opt.MinRetryBackoff {
+ case -1:
+ opt.MinRetryBackoff = 0
+ case 0:
+ opt.MinRetryBackoff = 8 * time.Millisecond
+ }
+ switch opt.MaxRetryBackoff {
+ case -1:
+ opt.MaxRetryBackoff = 0
+ case 0:
+ opt.MaxRetryBackoff = 512 * time.Millisecond
+ }
+}
+
+func (opt *ClusterOptions) clientOptions() *Options {
+ const disableIdleCheck = -1
+
+ return &Options{
+ OnConnect: opt.OnConnect,
+
+ MaxRetries: opt.MaxRetries,
+ MinRetryBackoff: opt.MinRetryBackoff,
+ MaxRetryBackoff: opt.MaxRetryBackoff,
+ Password: opt.Password,
+ readOnly: opt.ReadOnly,
+
+ DialTimeout: opt.DialTimeout,
+ ReadTimeout: opt.ReadTimeout,
+ WriteTimeout: opt.WriteTimeout,
+
+ PoolSize: opt.PoolSize,
+ PoolTimeout: opt.PoolTimeout,
+ IdleTimeout: opt.IdleTimeout,
+
+ IdleCheckFrequency: disableIdleCheck,
+
+ TLSConfig: opt.TLSConfig,
+ }
+}
+
+//------------------------------------------------------------------------------
+
+type clusterNode struct {
+ Client *Client
+
+ latency uint32 // atomic
+ generation uint32 // atomic
+ loading uint32 // atomic
+}
+
+func newClusterNode(clOpt *ClusterOptions, addr string) *clusterNode {
+ opt := clOpt.clientOptions()
+ opt.Addr = addr
+ node := clusterNode{
+ Client: NewClient(opt),
+ }
+
+ node.latency = math.MaxUint32
+ if clOpt.RouteByLatency {
+ go node.updateLatency()
+ }
+
+ return &node
+}
+
+func (n *clusterNode) String() string {
+ return n.Client.String()
+}
+
+func (n *clusterNode) Close() error {
+ return n.Client.Close()
+}
+
+func (n *clusterNode) updateLatency() {
+ const probes = 10
+
+ var latency uint32
+ for i := 0; i < probes; i++ {
+ start := time.Now()
+ n.Client.Ping()
+ probe := uint32(time.Since(start) / time.Microsecond)
+ latency = (latency + probe) / 2
+ }
+ atomic.StoreUint32(&n.latency, latency)
+}
+
+func (n *clusterNode) Latency() time.Duration {
+ latency := atomic.LoadUint32(&n.latency)
+ return time.Duration(latency) * time.Microsecond
+}
+
+func (n *clusterNode) MarkAsLoading() {
+ atomic.StoreUint32(&n.loading, uint32(time.Now().Unix()))
+}
+
+func (n *clusterNode) Loading() bool {
+ const minute = int64(time.Minute / time.Second)
+
+ loading := atomic.LoadUint32(&n.loading)
+ if loading == 0 {
+ return false
+ }
+ if time.Now().Unix()-int64(loading) < minute {
+ return true
+ }
+ atomic.StoreUint32(&n.loading, 0)
+ return false
+}
+
+func (n *clusterNode) Generation() uint32 {
+ return atomic.LoadUint32(&n.generation)
+}
+
+func (n *clusterNode) SetGeneration(gen uint32) {
+ for {
+ v := atomic.LoadUint32(&n.generation)
+ if gen < v || atomic.CompareAndSwapUint32(&n.generation, v, gen) {
+ break
+ }
+ }
+}
+
+//------------------------------------------------------------------------------
+
+type clusterNodes struct {
+ opt *ClusterOptions
+
+ mu sync.RWMutex
+ allAddrs []string
+ allNodes map[string]*clusterNode
+ clusterAddrs []string
+ closed bool
+
+ nodeCreateGroup singleflight.Group
+
+ _generation uint32 // atomic
+}
+
+func newClusterNodes(opt *ClusterOptions) *clusterNodes {
+ return &clusterNodes{
+ opt: opt,
+
+ allAddrs: opt.Addrs,
+ allNodes: make(map[string]*clusterNode),
+ }
+}
+
+func (c *clusterNodes) Close() error {
+ c.mu.Lock()
+ defer c.mu.Unlock()
+
+ if c.closed {
+ return nil
+ }
+ c.closed = true
+
+ var firstErr error
+ for _, node := range c.allNodes {
+ if err := node.Client.Close(); err != nil && firstErr == nil {
+ firstErr = err
+ }
+ }
+
+ c.allNodes = nil
+ c.clusterAddrs = nil
+
+ return firstErr
+}
+
+func (c *clusterNodes) Addrs() ([]string, error) {
+ var addrs []string
+ c.mu.RLock()
+ closed := c.closed
+ if !closed {
+ if len(c.clusterAddrs) > 0 {
+ addrs = c.clusterAddrs
+ } else {
+ addrs = c.allAddrs
+ }
+ }
+ c.mu.RUnlock()
+
+ if closed {
+ return nil, pool.ErrClosed
+ }
+ if len(addrs) == 0 {
+ return nil, errClusterNoNodes
+ }
+ return addrs, nil
+}
+
+func (c *clusterNodes) NextGeneration() uint32 {
+ return atomic.AddUint32(&c._generation, 1)
+}
+
+// GC removes unused nodes.
+func (c *clusterNodes) GC(generation uint32) {
+ var collected []*clusterNode
+ c.mu.Lock()
+ for addr, node := range c.allNodes {
+ if node.Generation() >= generation {
+ continue
+ }
+
+ c.clusterAddrs = remove(c.clusterAddrs, addr)
+ delete(c.allNodes, addr)
+ collected = append(collected, node)
+ }
+ c.mu.Unlock()
+
+ for _, node := range collected {
+ _ = node.Client.Close()
+ }
+}
+
+func (c *clusterNodes) Get(addr string) (*clusterNode, error) {
+ var node *clusterNode
+ var err error
+ c.mu.RLock()
+ if c.closed {
+ err = pool.ErrClosed
+ } else {
+ node = c.allNodes[addr]
+ }
+ c.mu.RUnlock()
+ return node, err
+}
+
+func (c *clusterNodes) GetOrCreate(addr string) (*clusterNode, error) {
+ node, err := c.Get(addr)
+ if err != nil {
+ return nil, err
+ }
+ if node != nil {
+ return node, nil
+ }
+
+ v, err := c.nodeCreateGroup.Do(addr, func() (interface{}, error) {
+ node := newClusterNode(c.opt, addr)
+ return node, nil
+ })
+
+ c.mu.Lock()
+ defer c.mu.Unlock()
+
+ if c.closed {
+ return nil, pool.ErrClosed
+ }
+
+ node, ok := c.allNodes[addr]
+ if ok {
+ _ = v.(*clusterNode).Close()
+ return node, err
+ }
+ node = v.(*clusterNode)
+
+ c.allAddrs = appendIfNotExists(c.allAddrs, addr)
+ if err == nil {
+ c.clusterAddrs = append(c.clusterAddrs, addr)
+ }
+ c.allNodes[addr] = node
+
+ return node, err
+}
+
+func (c *clusterNodes) All() ([]*clusterNode, error) {
+ c.mu.RLock()
+ defer c.mu.RUnlock()
+
+ if c.closed {
+ return nil, pool.ErrClosed
+ }
+
+ cp := make([]*clusterNode, 0, len(c.allNodes))
+ for _, node := range c.allNodes {
+ cp = append(cp, node)
+ }
+ return cp, nil
+}
+
+func (c *clusterNodes) Random() (*clusterNode, error) {
+ addrs, err := c.Addrs()
+ if err != nil {
+ return nil, err
+ }
+
+ n := rand.Intn(len(addrs))
+ return c.GetOrCreate(addrs[n])
+}
+
+//------------------------------------------------------------------------------
+
+type clusterSlot struct {
+ start, end int
+ nodes []*clusterNode
+}
+
+type clusterSlotSlice []*clusterSlot
+
+func (p clusterSlotSlice) Len() int {
+ return len(p)
+}
+
+func (p clusterSlotSlice) Less(i, j int) bool {
+ return p[i].start < p[j].start
+}
+
+func (p clusterSlotSlice) Swap(i, j int) {
+ p[i], p[j] = p[j], p[i]
+}
+
+type clusterState struct {
+ nodes *clusterNodes
+ Masters []*clusterNode
+ Slaves []*clusterNode
+
+ slots []*clusterSlot
+
+ generation uint32
+ createdAt time.Time
+}
+
+func newClusterState(
+ nodes *clusterNodes, slots []ClusterSlot, origin string,
+) (*clusterState, error) {
+ c := clusterState{
+ nodes: nodes,
+
+ slots: make([]*clusterSlot, 0, len(slots)),
+
+ generation: nodes.NextGeneration(),
+ createdAt: time.Now(),
+ }
+
+ isLoopbackOrigin := isLoopbackAddr(origin)
+ for _, slot := range slots {
+ var nodes []*clusterNode
+ for i, slotNode := range slot.Nodes {
+ addr := slotNode.Addr
+ if !isLoopbackOrigin && useOriginAddr(origin, addr) {
+ addr = origin
+ }
+
+ node, err := c.nodes.GetOrCreate(addr)
+ if err != nil {
+ return nil, err
+ }
+
+ node.SetGeneration(c.generation)
+ nodes = append(nodes, node)
+
+ if i == 0 {
+ c.Masters = appendUniqueNode(c.Masters, node)
+ } else {
+ c.Slaves = appendUniqueNode(c.Slaves, node)
+ }
+ }
+
+ c.slots = append(c.slots, &clusterSlot{
+ start: slot.Start,
+ end: slot.End,
+ nodes: nodes,
+ })
+ }
+
+ sort.Sort(clusterSlotSlice(c.slots))
+
+ time.AfterFunc(time.Minute, func() {
+ nodes.GC(c.generation)
+ })
+
+ return &c, nil
+}
+
+func (c *clusterState) slotMasterNode(slot int) (*clusterNode, error) {
+ nodes := c.slotNodes(slot)
+ if len(nodes) > 0 {
+ return nodes[0], nil
+ }
+ return c.nodes.Random()
+}
+
+func (c *clusterState) slotSlaveNode(slot int) (*clusterNode, error) {
+ nodes := c.slotNodes(slot)
+ switch len(nodes) {
+ case 0:
+ return c.nodes.Random()
+ case 1:
+ return nodes[0], nil
+ case 2:
+ if slave := nodes[1]; !slave.Loading() {
+ return slave, nil
+ }
+ return nodes[0], nil
+ default:
+ var slave *clusterNode
+ for i := 0; i < 10; i++ {
+ n := rand.Intn(len(nodes)-1) + 1
+ slave = nodes[n]
+ if !slave.Loading() {
+ break
+ }
+ }
+ return slave, nil
+ }
+}
+
+func (c *clusterState) slotClosestNode(slot int) (*clusterNode, error) {
+ const threshold = time.Millisecond
+
+ nodes := c.slotNodes(slot)
+ if len(nodes) == 0 {
+ return c.nodes.Random()
+ }
+
+ var node *clusterNode
+ for _, n := range nodes {
+ if n.Loading() {
+ continue
+ }
+ if node == nil || node.Latency()-n.Latency() > threshold {
+ node = n
+ }
+ }
+ return node, nil
+}
+
+func (c *clusterState) slotRandomNode(slot int) *clusterNode {
+ nodes := c.slotNodes(slot)
+ n := rand.Intn(len(nodes))
+ return nodes[n]
+}
+
+func (c *clusterState) slotNodes(slot int) []*clusterNode {
+ i := sort.Search(len(c.slots), func(i int) bool {
+ return c.slots[i].end >= slot
+ })
+ if i >= len(c.slots) {
+ return nil
+ }
+ x := c.slots[i]
+ if slot >= x.start && slot <= x.end {
+ return x.nodes
+ }
+ return nil
+}
+
+func (c *clusterState) IsConsistent() bool {
+ if c.nodes.opt.ClusterSlots != nil {
+ return true
+ }
+ return len(c.Masters) <= len(c.Slaves)
+}
+
+//------------------------------------------------------------------------------
+
+type clusterStateHolder struct {
+ load func() (*clusterState, error)
+
+ state atomic.Value
+
+ firstErrMu sync.RWMutex
+ firstErr error
+
+ reloading uint32 // atomic
+}
+
+func newClusterStateHolder(fn func() (*clusterState, error)) *clusterStateHolder {
+ return &clusterStateHolder{
+ load: fn,
+ }
+}
+
+func (c *clusterStateHolder) Reload() (*clusterState, error) {
+ state, err := c.reload()
+ if err != nil {
+ return nil, err
+ }
+ if !state.IsConsistent() {
+ time.AfterFunc(time.Second, c.LazyReload)
+ }
+ return state, nil
+}
+
+func (c *clusterStateHolder) reload() (*clusterState, error) {
+ state, err := c.load()
+ if err != nil {
+ c.firstErrMu.Lock()
+ if c.firstErr == nil {
+ c.firstErr = err
+ }
+ c.firstErrMu.Unlock()
+ return nil, err
+ }
+ c.state.Store(state)
+ return state, nil
+}
+
+func (c *clusterStateHolder) LazyReload() {
+ if !atomic.CompareAndSwapUint32(&c.reloading, 0, 1) {
+ return
+ }
+ go func() {
+ defer atomic.StoreUint32(&c.reloading, 0)
+
+ for {
+ state, err := c.reload()
+ if err != nil {
+ return
+ }
+ time.Sleep(100 * time.Millisecond)
+ if state.IsConsistent() {
+ return
+ }
+ }
+ }()
+}
+
+func (c *clusterStateHolder) Get() (*clusterState, error) {
+ v := c.state.Load()
+ if v != nil {
+ state := v.(*clusterState)
+ if time.Since(state.createdAt) > time.Minute {
+ c.LazyReload()
+ }
+ return state, nil
+ }
+
+ c.firstErrMu.RLock()
+ err := c.firstErr
+ c.firstErrMu.RUnlock()
+ if err != nil {
+ return nil, err
+ }
+
+ return nil, errors.New("redis: cluster has no state")
+}
+
+func (c *clusterStateHolder) ReloadOrGet() (*clusterState, error) {
+ state, err := c.Reload()
+ if err == nil {
+ return state, nil
+ }
+ return c.Get()
+}
+
+//------------------------------------------------------------------------------
+
+// ClusterClient is a Redis Cluster client representing a pool of zero
+// or more underlying connections. It's safe for concurrent use by
+// multiple goroutines.
+type ClusterClient struct {
+ cmdable
+
+ ctx context.Context
+
+ opt *ClusterOptions
+ nodes *clusterNodes
+ state *clusterStateHolder
+ cmdsInfoCache *cmdsInfoCache
+
+ process func(Cmder) error
+ processPipeline func([]Cmder) error
+ processTxPipeline func([]Cmder) error
+}
+
+// NewClusterClient returns a Redis Cluster client as described in
+// http://redis.io/topics/cluster-spec.
+func NewClusterClient(opt *ClusterOptions) *ClusterClient {
+ opt.init()
+
+ c := &ClusterClient{
+ opt: opt,
+ nodes: newClusterNodes(opt),
+ }
+ c.state = newClusterStateHolder(c.loadState)
+ c.cmdsInfoCache = newCmdsInfoCache(c.cmdsInfo)
+
+ c.process = c.defaultProcess
+ c.processPipeline = c.defaultProcessPipeline
+ c.processTxPipeline = c.defaultProcessTxPipeline
+
+ c.init()
+
+ _, _ = c.state.Reload()
+ _, _ = c.cmdsInfoCache.Get()
+
+ if opt.IdleCheckFrequency > 0 {
+ go c.reaper(opt.IdleCheckFrequency)
+ }
+
+ return c
+}
+
+// ReloadState reloads cluster state. It calls ClusterSlots func
+// to get cluster slots information.
+func (c *ClusterClient) ReloadState() error {
+ _, err := c.state.Reload()
+ return err
+}
+
+func (c *ClusterClient) init() {
+ c.cmdable.setProcessor(c.Process)
+}
+
+func (c *ClusterClient) Context() context.Context {
+ if c.ctx != nil {
+ return c.ctx
+ }
+ return context.Background()
+}
+
+func (c *ClusterClient) WithContext(ctx context.Context) *ClusterClient {
+ if ctx == nil {
+ panic("nil context")
+ }
+ c2 := c.copy()
+ c2.ctx = ctx
+ return c2
+}
+
+func (c *ClusterClient) copy() *ClusterClient {
+ cp := *c
+ cp.init()
+ return &cp
+}
+
+// Options returns read-only Options that were used to create the client.
+func (c *ClusterClient) Options() *ClusterOptions {
+ return c.opt
+}
+
+func (c *ClusterClient) retryBackoff(attempt int) time.Duration {
+ return internal.RetryBackoff(attempt, c.opt.MinRetryBackoff, c.opt.MaxRetryBackoff)
+}
+
+func (c *ClusterClient) cmdsInfo() (map[string]*CommandInfo, error) {
+ addrs, err := c.nodes.Addrs()
+ if err != nil {
+ return nil, err
+ }
+
+ var firstErr error
+ for _, addr := range addrs {
+ node, err := c.nodes.Get(addr)
+ if err != nil {
+ return nil, err
+ }
+ if node == nil {
+ continue
+ }
+
+ info, err := node.Client.Command().Result()
+ if err == nil {
+ return info, nil
+ }
+ if firstErr == nil {
+ firstErr = err
+ }
+ }
+ return nil, firstErr
+}
+
+func (c *ClusterClient) cmdInfo(name string) *CommandInfo {
+ cmdsInfo, err := c.cmdsInfoCache.Get()
+ if err != nil {
+ return nil
+ }
+
+ info := cmdsInfo[name]
+ if info == nil {
+ internal.Logf("info for cmd=%s not found", name)
+ }
+ return info
+}
+
+func cmdSlot(cmd Cmder, pos int) int {
+ if pos == 0 {
+ return hashtag.RandomSlot()
+ }
+ firstKey := cmd.stringArg(pos)
+ return hashtag.Slot(firstKey)
+}
+
+func (c *ClusterClient) cmdSlot(cmd Cmder) int {
+ cmdInfo := c.cmdInfo(cmd.Name())
+ return cmdSlot(cmd, cmdFirstKeyPos(cmd, cmdInfo))
+}
+
+func (c *ClusterClient) cmdSlotAndNode(cmd Cmder) (int, *clusterNode, error) {
+ state, err := c.state.Get()
+ if err != nil {
+ return 0, nil, err
+ }
+
+ cmdInfo := c.cmdInfo(cmd.Name())
+ slot := cmdSlot(cmd, cmdFirstKeyPos(cmd, cmdInfo))
+
+ if cmdInfo != nil && cmdInfo.ReadOnly && c.opt.ReadOnly {
+ if c.opt.RouteByLatency {
+ node, err := state.slotClosestNode(slot)
+ return slot, node, err
+ }
+
+ if c.opt.RouteRandomly {
+ node := state.slotRandomNode(slot)
+ return slot, node, nil
+ }
+
+ node, err := state.slotSlaveNode(slot)
+ return slot, node, err
+ }
+
+ node, err := state.slotMasterNode(slot)
+ return slot, node, err
+}
+
+func (c *ClusterClient) slotMasterNode(slot int) (*clusterNode, error) {
+ state, err := c.state.Get()
+ if err != nil {
+ return nil, err
+ }
+
+ nodes := state.slotNodes(slot)
+ if len(nodes) > 0 {
+ return nodes[0], nil
+ }
+ return c.nodes.Random()
+}
+
+func (c *ClusterClient) Watch(fn func(*Tx) error, keys ...string) error {
+ if len(keys) == 0 {
+ return fmt.Errorf("redis: Watch requires at least one key")
+ }
+
+ slot := hashtag.Slot(keys[0])
+ for _, key := range keys[1:] {
+ if hashtag.Slot(key) != slot {
+ err := fmt.Errorf("redis: Watch requires all keys to be in the same slot")
+ return err
+ }
+ }
+
+ node, err := c.slotMasterNode(slot)
+ if err != nil {
+ return err
+ }
+
+ for attempt := 0; attempt <= c.opt.MaxRedirects; attempt++ {
+ if attempt > 0 {
+ time.Sleep(c.retryBackoff(attempt))
+ }
+
+ err = node.Client.Watch(fn, keys...)
+ if err == nil {
+ break
+ }
+
+ if internal.IsRetryableError(err, true) {
+ c.state.LazyReload()
+ continue
+ }
+
+ moved, ask, addr := internal.IsMovedError(err)
+ if moved || ask {
+ c.state.LazyReload()
+ node, err = c.nodes.GetOrCreate(addr)
+ if err != nil {
+ return err
+ }
+ continue
+ }
+
+ if err == pool.ErrClosed {
+ node, err = c.slotMasterNode(slot)
+ if err != nil {
+ return err
+ }
+ continue
+ }
+
+ return err
+ }
+
+ return err
+}
+
+// Close closes the cluster client, releasing any open resources.
+//
+// It is rare to Close a ClusterClient, as the ClusterClient is meant
+// to be long-lived and shared between many goroutines.
+func (c *ClusterClient) Close() error {
+ return c.nodes.Close()
+}
+
+func (c *ClusterClient) WrapProcess(
+ fn func(oldProcess func(Cmder) error) func(Cmder) error,
+) {
+ c.process = fn(c.process)
+}
+
+func (c *ClusterClient) Process(cmd Cmder) error {
+ return c.process(cmd)
+}
+
+func (c *ClusterClient) defaultProcess(cmd Cmder) error {
+ var node *clusterNode
+ var ask bool
+ for attempt := 0; attempt <= c.opt.MaxRedirects; attempt++ {
+ if attempt > 0 {
+ time.Sleep(c.retryBackoff(attempt))
+ }
+
+ if node == nil {
+ var err error
+ _, node, err = c.cmdSlotAndNode(cmd)
+ if err != nil {
+ cmd.setErr(err)
+ break
+ }
+ }
+
+ var err error
+ if ask {
+ pipe := node.Client.Pipeline()
+ _ = pipe.Process(NewCmd("ASKING"))
+ _ = pipe.Process(cmd)
+ _, err = pipe.Exec()
+ _ = pipe.Close()
+ ask = false
+ } else {
+ err = node.Client.Process(cmd)
+ }
+
+ // If there is no error - we are done.
+ if err == nil {
+ break
+ }
+
+ // If slave is loading - read from master.
+ if c.opt.ReadOnly && internal.IsLoadingError(err) {
+ node.MarkAsLoading()
+ continue
+ }
+
+ if internal.IsRetryableError(err, true) {
+ c.state.LazyReload()
+
+ // First retry the same node.
+ if attempt == 0 {
+ continue
+ }
+
+ // Second try random node.
+ node, err = c.nodes.Random()
+ if err != nil {
+ break
+ }
+ continue
+ }
+
+ var moved bool
+ var addr string
+ moved, ask, addr = internal.IsMovedError(err)
+ if moved || ask {
+ c.state.LazyReload()
+
+ node, err = c.nodes.GetOrCreate(addr)
+ if err != nil {
+ break
+ }
+ continue
+ }
+
+ if err == pool.ErrClosed {
+ node = nil
+ continue
+ }
+
+ break
+ }
+
+ return cmd.Err()
+}
+
+// ForEachMaster concurrently calls the fn on each master node in the cluster.
+// It returns the first error if any.
+func (c *ClusterClient) ForEachMaster(fn func(client *Client) error) error {
+ state, err := c.state.ReloadOrGet()
+ if err != nil {
+ return err
+ }
+
+ var wg sync.WaitGroup
+ errCh := make(chan error, 1)
+ for _, master := range state.Masters {
+ wg.Add(1)
+ go func(node *clusterNode) {
+ defer wg.Done()
+ err := fn(node.Client)
+ if err != nil {
+ select {
+ case errCh <- err:
+ default:
+ }
+ }
+ }(master)
+ }
+ wg.Wait()
+
+ select {
+ case err := <-errCh:
+ return err
+ default:
+ return nil
+ }
+}
+
+// ForEachSlave concurrently calls the fn on each slave node in the cluster.
+// It returns the first error if any.
+func (c *ClusterClient) ForEachSlave(fn func(client *Client) error) error {
+ state, err := c.state.ReloadOrGet()
+ if err != nil {
+ return err
+ }
+
+ var wg sync.WaitGroup
+ errCh := make(chan error, 1)
+ for _, slave := range state.Slaves {
+ wg.Add(1)
+ go func(node *clusterNode) {
+ defer wg.Done()
+ err := fn(node.Client)
+ if err != nil {
+ select {
+ case errCh <- err:
+ default:
+ }
+ }
+ }(slave)
+ }
+ wg.Wait()
+
+ select {
+ case err := <-errCh:
+ return err
+ default:
+ return nil
+ }
+}
+
+// ForEachNode concurrently calls the fn on each known node in the cluster.
+// It returns the first error if any.
+func (c *ClusterClient) ForEachNode(fn func(client *Client) error) error {
+ state, err := c.state.ReloadOrGet()
+ if err != nil {
+ return err
+ }
+
+ var wg sync.WaitGroup
+ errCh := make(chan error, 1)
+ worker := func(node *clusterNode) {
+ defer wg.Done()
+ err := fn(node.Client)
+ if err != nil {
+ select {
+ case errCh <- err:
+ default:
+ }
+ }
+ }
+
+ for _, node := range state.Masters {
+ wg.Add(1)
+ go worker(node)
+ }
+ for _, node := range state.Slaves {
+ wg.Add(1)
+ go worker(node)
+ }
+
+ wg.Wait()
+ select {
+ case err := <-errCh:
+ return err
+ default:
+ return nil
+ }
+}
+
+// PoolStats returns accumulated connection pool stats.
+func (c *ClusterClient) PoolStats() *PoolStats {
+ var acc PoolStats
+
+ state, _ := c.state.Get()
+ if state == nil {
+ return &acc
+ }
+
+ for _, node := range state.Masters {
+ s := node.Client.connPool.Stats()
+ acc.Hits += s.Hits
+ acc.Misses += s.Misses
+ acc.Timeouts += s.Timeouts
+
+ acc.TotalConns += s.TotalConns
+ acc.FreeConns += s.FreeConns
+ acc.StaleConns += s.StaleConns
+ }
+
+ for _, node := range state.Slaves {
+ s := node.Client.connPool.Stats()
+ acc.Hits += s.Hits
+ acc.Misses += s.Misses
+ acc.Timeouts += s.Timeouts
+
+ acc.TotalConns += s.TotalConns
+ acc.FreeConns += s.FreeConns
+ acc.StaleConns += s.StaleConns
+ }
+
+ return &acc
+}
+
+func (c *ClusterClient) loadState() (*clusterState, error) {
+ if c.opt.ClusterSlots != nil {
+ slots, err := c.opt.ClusterSlots()
+ if err != nil {
+ return nil, err
+ }
+ return newClusterState(c.nodes, slots, "")
+ }
+
+ addrs, err := c.nodes.Addrs()
+ if err != nil {
+ return nil, err
+ }
+
+ var firstErr error
+ for _, addr := range addrs {
+ node, err := c.nodes.GetOrCreate(addr)
+ if err != nil {
+ if firstErr == nil {
+ firstErr = err
+ }
+ continue
+ }
+
+ slots, err := node.Client.ClusterSlots().Result()
+ if err != nil {
+ if firstErr == nil {
+ firstErr = err
+ }
+ continue
+ }
+
+ return newClusterState(c.nodes, slots, node.Client.opt.Addr)
+ }
+
+ return nil, firstErr
+}
+
+// reaper closes idle connections to the cluster.
+func (c *ClusterClient) reaper(idleCheckFrequency time.Duration) {
+ ticker := time.NewTicker(idleCheckFrequency)
+ defer ticker.Stop()
+
+ for range ticker.C {
+ nodes, err := c.nodes.All()
+ if err != nil {
+ break
+ }
+
+ for _, node := range nodes {
+ _, err := node.Client.connPool.(*pool.ConnPool).ReapStaleConns()
+ if err != nil {
+ internal.Logf("ReapStaleConns failed: %s", err)
+ }
+ }
+ }
+}
+
+func (c *ClusterClient) Pipeline() Pipeliner {
+ pipe := Pipeline{
+ exec: c.processPipeline,
+ }
+ pipe.statefulCmdable.setProcessor(pipe.Process)
+ return &pipe
+}
+
+func (c *ClusterClient) Pipelined(fn func(Pipeliner) error) ([]Cmder, error) {
+ return c.Pipeline().Pipelined(fn)
+}
+
+func (c *ClusterClient) WrapProcessPipeline(
+ fn func(oldProcess func([]Cmder) error) func([]Cmder) error,
+) {
+ c.processPipeline = fn(c.processPipeline)
+}
+
+func (c *ClusterClient) defaultProcessPipeline(cmds []Cmder) error {
+ cmdsMap, err := c.mapCmdsByNode(cmds)
+ if err != nil {
+ setCmdsErr(cmds, err)
+ return err
+ }
+
+ for attempt := 0; attempt <= c.opt.MaxRedirects; attempt++ {
+ if attempt > 0 {
+ time.Sleep(c.retryBackoff(attempt))
+ }
+
+ failedCmds := make(map[*clusterNode][]Cmder)
+
+ for node, cmds := range cmdsMap {
+ cn, err := node.Client.getConn()
+ if err != nil {
+ if err == pool.ErrClosed {
+ c.remapCmds(cmds, failedCmds)
+ } else {
+ setCmdsErr(cmds, err)
+ }
+ continue
+ }
+
+ err = c.pipelineProcessCmds(node, cn, cmds, failedCmds)
+ if err == nil || internal.IsRedisError(err) {
+ node.Client.connPool.Put(cn)
+ } else {
+ node.Client.connPool.Remove(cn)
+ }
+ }
+
+ if len(failedCmds) == 0 {
+ break
+ }
+ cmdsMap = failedCmds
+ }
+
+ return firstCmdsErr(cmds)
+}
+
+func (c *ClusterClient) mapCmdsByNode(cmds []Cmder) (map[*clusterNode][]Cmder, error) {
+ state, err := c.state.Get()
+ if err != nil {
+ setCmdsErr(cmds, err)
+ return nil, err
+ }
+
+ cmdsMap := make(map[*clusterNode][]Cmder)
+ cmdsAreReadOnly := c.cmdsAreReadOnly(cmds)
+ for _, cmd := range cmds {
+ var node *clusterNode
+ var err error
+ if cmdsAreReadOnly {
+ _, node, err = c.cmdSlotAndNode(cmd)
+ } else {
+ slot := c.cmdSlot(cmd)
+ node, err = state.slotMasterNode(slot)
+ }
+ if err != nil {
+ return nil, err
+ }
+ cmdsMap[node] = append(cmdsMap[node], cmd)
+ }
+ return cmdsMap, nil
+}
+
+func (c *ClusterClient) cmdsAreReadOnly(cmds []Cmder) bool {
+ for _, cmd := range cmds {
+ cmdInfo := c.cmdInfo(cmd.Name())
+ if cmdInfo == nil || !cmdInfo.ReadOnly {
+ return false
+ }
+ }
+ return true
+}
+
+func (c *ClusterClient) remapCmds(cmds []Cmder, failedCmds map[*clusterNode][]Cmder) {
+ remappedCmds, err := c.mapCmdsByNode(cmds)
+ if err != nil {
+ setCmdsErr(cmds, err)
+ return
+ }
+
+ for node, cmds := range remappedCmds {
+ failedCmds[node] = cmds
+ }
+}
+
+func (c *ClusterClient) pipelineProcessCmds(
+ node *clusterNode, cn *pool.Conn, cmds []Cmder, failedCmds map[*clusterNode][]Cmder,
+) error {
+ cn.SetWriteTimeout(c.opt.WriteTimeout)
+
+ err := writeCmd(cn, cmds...)
+ if err != nil {
+ setCmdsErr(cmds, err)
+ failedCmds[node] = cmds
+ return err
+ }
+
+ // Set read timeout for all commands.
+ cn.SetReadTimeout(c.opt.ReadTimeout)
+
+ return c.pipelineReadCmds(cn, cmds, failedCmds)
+}
+
+func (c *ClusterClient) pipelineReadCmds(
+ cn *pool.Conn, cmds []Cmder, failedCmds map[*clusterNode][]Cmder,
+) error {
+ for _, cmd := range cmds {
+ err := cmd.readReply(cn)
+ if err == nil {
+ continue
+ }
+
+ if c.checkMovedErr(cmd, err, failedCmds) {
+ continue
+ }
+
+ if internal.IsRedisError(err) {
+ continue
+ }
+
+ return err
+ }
+ return nil
+}
+
+func (c *ClusterClient) checkMovedErr(
+ cmd Cmder, err error, failedCmds map[*clusterNode][]Cmder,
+) bool {
+ moved, ask, addr := internal.IsMovedError(err)
+
+ if moved {
+ c.state.LazyReload()
+
+ node, err := c.nodes.GetOrCreate(addr)
+ if err != nil {
+ return false
+ }
+
+ failedCmds[node] = append(failedCmds[node], cmd)
+ return true
+ }
+
+ if ask {
+ node, err := c.nodes.GetOrCreate(addr)
+ if err != nil {
+ return false
+ }
+
+ failedCmds[node] = append(failedCmds[node], NewCmd("ASKING"), cmd)
+ return true
+ }
+
+ return false
+}
+
+// TxPipeline acts like Pipeline, but wraps queued commands with MULTI/EXEC.
+func (c *ClusterClient) TxPipeline() Pipeliner {
+ pipe := Pipeline{
+ exec: c.processTxPipeline,
+ }
+ pipe.statefulCmdable.setProcessor(pipe.Process)
+ return &pipe
+}
+
+func (c *ClusterClient) TxPipelined(fn func(Pipeliner) error) ([]Cmder, error) {
+ return c.TxPipeline().Pipelined(fn)
+}
+
+func (c *ClusterClient) defaultProcessTxPipeline(cmds []Cmder) error {
+ state, err := c.state.Get()
+ if err != nil {
+ return err
+ }
+
+ cmdsMap := c.mapCmdsBySlot(cmds)
+ for slot, cmds := range cmdsMap {
+ node, err := state.slotMasterNode(slot)
+ if err != nil {
+ setCmdsErr(cmds, err)
+ continue
+ }
+ cmdsMap := map[*clusterNode][]Cmder{node: cmds}
+
+ for attempt := 0; attempt <= c.opt.MaxRedirects; attempt++ {
+ if attempt > 0 {
+ time.Sleep(c.retryBackoff(attempt))
+ }
+
+ failedCmds := make(map[*clusterNode][]Cmder)
+
+ for node, cmds := range cmdsMap {
+ cn, err := node.Client.getConn()
+ if err != nil {
+ if err == pool.ErrClosed {
+ c.remapCmds(cmds, failedCmds)
+ } else {
+ setCmdsErr(cmds, err)
+ }
+ continue
+ }
+
+ err = c.txPipelineProcessCmds(node, cn, cmds, failedCmds)
+ if err == nil || internal.IsRedisError(err) {
+ node.Client.connPool.Put(cn)
+ } else {
+ node.Client.connPool.Remove(cn)
+ }
+ }
+
+ if len(failedCmds) == 0 {
+ break
+ }
+ cmdsMap = failedCmds
+ }
+ }
+
+ return firstCmdsErr(cmds)
+}
+
+func (c *ClusterClient) mapCmdsBySlot(cmds []Cmder) map[int][]Cmder {
+ cmdsMap := make(map[int][]Cmder)
+ for _, cmd := range cmds {
+ slot := c.cmdSlot(cmd)
+ cmdsMap[slot] = append(cmdsMap[slot], cmd)
+ }
+ return cmdsMap
+}
+
+func (c *ClusterClient) txPipelineProcessCmds(
+ node *clusterNode, cn *pool.Conn, cmds []Cmder, failedCmds map[*clusterNode][]Cmder,
+) error {
+ cn.SetWriteTimeout(c.opt.WriteTimeout)
+ if err := txPipelineWriteMulti(cn, cmds); err != nil {
+ setCmdsErr(cmds, err)
+ failedCmds[node] = cmds
+ return err
+ }
+
+ // Set read timeout for all commands.
+ cn.SetReadTimeout(c.opt.ReadTimeout)
+
+ if err := c.txPipelineReadQueued(cn, cmds, failedCmds); err != nil {
+ setCmdsErr(cmds, err)
+ return err
+ }
+
+ return pipelineReadCmds(cn, cmds)
+}
+
+func (c *ClusterClient) txPipelineReadQueued(
+ cn *pool.Conn, cmds []Cmder, failedCmds map[*clusterNode][]Cmder,
+) error {
+ // Parse queued replies.
+ var statusCmd StatusCmd
+ if err := statusCmd.readReply(cn); err != nil {
+ return err
+ }
+
+ for _, cmd := range cmds {
+ err := statusCmd.readReply(cn)
+ if err == nil {
+ continue
+ }
+
+ if c.checkMovedErr(cmd, err, failedCmds) || internal.IsRedisError(err) {
+ continue
+ }
+
+ return err
+ }
+
+ // Parse number of replies.
+ line, err := cn.Rd.ReadLine()
+ if err != nil {
+ if err == Nil {
+ err = TxFailedErr
+ }
+ return err
+ }
+
+ switch line[0] {
+ case proto.ErrorReply:
+ err := proto.ParseErrorReply(line)
+ for _, cmd := range cmds {
+ if !c.checkMovedErr(cmd, err, failedCmds) {
+ break
+ }
+ }
+ return err
+ case proto.ArrayReply:
+ // ok
+ default:
+ err := fmt.Errorf("redis: expected '*', but got line %q", line)
+ return err
+ }
+
+ return nil
+}
+
+func (c *ClusterClient) pubSub(channels []string) *PubSub {
+ var node *clusterNode
+ pubsub := &PubSub{
+ opt: c.opt.clientOptions(),
+
+ newConn: func(channels []string) (*pool.Conn, error) {
+ if node == nil {
+ var slot int
+ if len(channels) > 0 {
+ slot = hashtag.Slot(channels[0])
+ } else {
+ slot = -1
+ }
+
+ masterNode, err := c.slotMasterNode(slot)
+ if err != nil {
+ return nil, err
+ }
+ node = masterNode
+ }
+ return node.Client.newConn()
+ },
+ closeConn: func(cn *pool.Conn) error {
+ return node.Client.connPool.CloseConn(cn)
+ },
+ }
+ pubsub.init()
+ return pubsub
+}
+
+// Subscribe subscribes the client to the specified channels.
+// Channels can be omitted to create empty subscription.
+func (c *ClusterClient) Subscribe(channels ...string) *PubSub {
+ pubsub := c.pubSub(channels)
+ if len(channels) > 0 {
+ _ = pubsub.Subscribe(channels...)
+ }
+ return pubsub
+}
+
+// PSubscribe subscribes the client to the given patterns.
+// Patterns can be omitted to create empty subscription.
+func (c *ClusterClient) PSubscribe(channels ...string) *PubSub {
+ pubsub := c.pubSub(channels)
+ if len(channels) > 0 {
+ _ = pubsub.PSubscribe(channels...)
+ }
+ return pubsub
+}
+
+func useOriginAddr(originAddr, nodeAddr string) bool {
+ nodeHost, nodePort, err := net.SplitHostPort(nodeAddr)
+ if err != nil {
+ return false
+ }
+
+ nodeIP := net.ParseIP(nodeHost)
+ if nodeIP == nil {
+ return false
+ }
+
+ if !nodeIP.IsLoopback() {
+ return false
+ }
+
+ _, originPort, err := net.SplitHostPort(originAddr)
+ if err != nil {
+ return false
+ }
+
+ return nodePort == originPort
+}
+
+func isLoopbackAddr(addr string) bool {
+ host, _, err := net.SplitHostPort(addr)
+ if err != nil {
+ return false
+ }
+
+ ip := net.ParseIP(host)
+ if ip == nil {
+ return false
+ }
+
+ return ip.IsLoopback()
+}
+
+func appendUniqueNode(nodes []*clusterNode, node *clusterNode) []*clusterNode {
+ for _, n := range nodes {
+ if n == node {
+ return nodes
+ }
+ }
+ return append(nodes, node)
+}
+
+func appendIfNotExists(ss []string, es ...string) []string {
+loop:
+ for _, e := range es {
+ for _, s := range ss {
+ if s == e {
+ continue loop
+ }
+ }
+ ss = append(ss, e)
+ }
+ return ss
+}
+
+func remove(ss []string, es ...string) []string {
+ if len(es) == 0 {
+ return ss[:0]
+ }
+ for _, e := range es {
+ for i, s := range ss {
+ if s == e {
+ ss = append(ss[:i], ss[i+1:]...)
+ break
+ }
+ }
+ }
+ return ss
+}
diff --git a/src/dma/vendor/github.com/go-redis/redis/cluster_commands.go b/src/dma/vendor/github.com/go-redis/redis/cluster_commands.go
new file mode 100644
index 00000000..dff62c90
--- /dev/null
+++ b/src/dma/vendor/github.com/go-redis/redis/cluster_commands.go
@@ -0,0 +1,22 @@
+package redis
+
+import "sync/atomic"
+
+func (c *ClusterClient) DBSize() *IntCmd {
+ cmd := NewIntCmd("dbsize")
+ var size int64
+ err := c.ForEachMaster(func(master *Client) error {
+ n, err := master.DBSize().Result()
+ if err != nil {
+ return err
+ }
+ atomic.AddInt64(&size, n)
+ return nil
+ })
+ if err != nil {
+ cmd.setErr(err)
+ return cmd
+ }
+ cmd.val = size
+ return cmd
+}
diff --git a/src/dma/vendor/github.com/go-redis/redis/command.go b/src/dma/vendor/github.com/go-redis/redis/command.go
new file mode 100644
index 00000000..11472bec
--- /dev/null
+++ b/src/dma/vendor/github.com/go-redis/redis/command.go
@@ -0,0 +1,1225 @@
+package redis
+
+import (
+ "bytes"
+ "fmt"
+ "strconv"
+ "strings"
+ "time"
+
+ "github.com/go-redis/redis/internal"
+ "github.com/go-redis/redis/internal/pool"
+ "github.com/go-redis/redis/internal/proto"
+ "github.com/go-redis/redis/internal/util"
+)
+
+type Cmder interface {
+ Name() string
+ Args() []interface{}
+ stringArg(int) string
+
+ readReply(*pool.Conn) error
+ setErr(error)
+
+ readTimeout() *time.Duration
+
+ Err() error
+ fmt.Stringer
+}
+
+func setCmdsErr(cmds []Cmder, e error) {
+ for _, cmd := range cmds {
+ if cmd.Err() == nil {
+ cmd.setErr(e)
+ }
+ }
+}
+
+func firstCmdsErr(cmds []Cmder) error {
+ for _, cmd := range cmds {
+ if err := cmd.Err(); err != nil {
+ return err
+ }
+ }
+ return nil
+}
+
+func writeCmd(cn *pool.Conn, cmds ...Cmder) error {
+ cn.Wb.Reset()
+ for _, cmd := range cmds {
+ if err := cn.Wb.Append(cmd.Args()); err != nil {
+ return err
+ }
+ }
+
+ _, err := cn.Write(cn.Wb.Bytes())
+ return err
+}
+
+func cmdString(cmd Cmder, val interface{}) string {
+ var ss []string
+ for _, arg := range cmd.Args() {
+ ss = append(ss, fmt.Sprint(arg))
+ }
+ s := strings.Join(ss, " ")
+ if err := cmd.Err(); err != nil {
+ return s + ": " + err.Error()
+ }
+ if val != nil {
+ switch vv := val.(type) {
+ case []byte:
+ return s + ": " + string(vv)
+ default:
+ return s + ": " + fmt.Sprint(val)
+ }
+ }
+ return s
+
+}
+
+func cmdFirstKeyPos(cmd Cmder, info *CommandInfo) int {
+ switch cmd.Name() {
+ case "eval", "evalsha":
+ if cmd.stringArg(2) != "0" {
+ return 3
+ }
+
+ return 0
+ case "publish":
+ return 1
+ }
+ if info == nil {
+ return 0
+ }
+ return int(info.FirstKeyPos)
+}
+
+//------------------------------------------------------------------------------
+
+type baseCmd struct {
+ _args []interface{}
+ err error
+
+ _readTimeout *time.Duration
+}
+
+var _ Cmder = (*Cmd)(nil)
+
+func (cmd *baseCmd) Err() error {
+ return cmd.err
+}
+
+func (cmd *baseCmd) Args() []interface{} {
+ return cmd._args
+}
+
+func (cmd *baseCmd) stringArg(pos int) string {
+ if pos < 0 || pos >= len(cmd._args) {
+ return ""
+ }
+ s, _ := cmd._args[pos].(string)
+ return s
+}
+
+func (cmd *baseCmd) Name() string {
+ if len(cmd._args) > 0 {
+ // Cmd name must be lower cased.
+ s := internal.ToLower(cmd.stringArg(0))
+ cmd._args[0] = s
+ return s
+ }
+ return ""
+}
+
+func (cmd *baseCmd) readTimeout() *time.Duration {
+ return cmd._readTimeout
+}
+
+func (cmd *baseCmd) setReadTimeout(d time.Duration) {
+ cmd._readTimeout = &d
+}
+
+func (cmd *baseCmd) setErr(e error) {
+ cmd.err = e
+}
+
+//------------------------------------------------------------------------------
+
+type Cmd struct {
+ baseCmd
+
+ val interface{}
+}
+
+func NewCmd(args ...interface{}) *Cmd {
+ return &Cmd{
+ baseCmd: baseCmd{_args: args},
+ }
+}
+
+func (cmd *Cmd) Val() interface{} {
+ return cmd.val
+}
+
+func (cmd *Cmd) Result() (interface{}, error) {
+ return cmd.val, cmd.err
+}
+
+func (cmd *Cmd) String() string {
+ return cmdString(cmd, cmd.val)
+}
+
+func (cmd *Cmd) readReply(cn *pool.Conn) error {
+ cmd.val, cmd.err = cn.Rd.ReadReply(sliceParser)
+ if cmd.err != nil {
+ return cmd.err
+ }
+ if b, ok := cmd.val.([]byte); ok {
+ // Bytes must be copied, because underlying memory is reused.
+ cmd.val = string(b)
+ }
+ return nil
+}
+
+//------------------------------------------------------------------------------
+
+type SliceCmd struct {
+ baseCmd
+
+ val []interface{}
+}
+
+var _ Cmder = (*SliceCmd)(nil)
+
+func NewSliceCmd(args ...interface{}) *SliceCmd {
+ return &SliceCmd{
+ baseCmd: baseCmd{_args: args},
+ }
+}
+
+func (cmd *SliceCmd) Val() []interface{} {
+ return cmd.val
+}
+
+func (cmd *SliceCmd) Result() ([]interface{}, error) {
+ return cmd.val, cmd.err
+}
+
+func (cmd *SliceCmd) String() string {
+ return cmdString(cmd, cmd.val)
+}
+
+func (cmd *SliceCmd) readReply(cn *pool.Conn) error {
+ var v interface{}
+ v, cmd.err = cn.Rd.ReadArrayReply(sliceParser)
+ if cmd.err != nil {
+ return cmd.err
+ }
+ cmd.val = v.([]interface{})
+ return nil
+}
+
+//------------------------------------------------------------------------------
+
+type StatusCmd struct {
+ baseCmd
+
+ val string
+}
+
+var _ Cmder = (*StatusCmd)(nil)
+
+func NewStatusCmd(args ...interface{}) *StatusCmd {
+ return &StatusCmd{
+ baseCmd: baseCmd{_args: args},
+ }
+}
+
+func (cmd *StatusCmd) Val() string {
+ return cmd.val
+}
+
+func (cmd *StatusCmd) Result() (string, error) {
+ return cmd.val, cmd.err
+}
+
+func (cmd *StatusCmd) String() string {
+ return cmdString(cmd, cmd.val)
+}
+
+func (cmd *StatusCmd) readReply(cn *pool.Conn) error {
+ cmd.val, cmd.err = cn.Rd.ReadStringReply()
+ return cmd.err
+}
+
+//------------------------------------------------------------------------------
+
+type IntCmd struct {
+ baseCmd
+
+ val int64
+}
+
+var _ Cmder = (*IntCmd)(nil)
+
+func NewIntCmd(args ...interface{}) *IntCmd {
+ return &IntCmd{
+ baseCmd: baseCmd{_args: args},
+ }
+}
+
+func (cmd *IntCmd) Val() int64 {
+ return cmd.val
+}
+
+func (cmd *IntCmd) Result() (int64, error) {
+ return cmd.val, cmd.err
+}
+
+func (cmd *IntCmd) String() string {
+ return cmdString(cmd, cmd.val)
+}
+
+func (cmd *IntCmd) readReply(cn *pool.Conn) error {
+ cmd.val, cmd.err = cn.Rd.ReadIntReply()
+ return cmd.err
+}
+
+//------------------------------------------------------------------------------
+
+type DurationCmd struct {
+ baseCmd
+
+ val time.Duration
+ precision time.Duration
+}
+
+var _ Cmder = (*DurationCmd)(nil)
+
+func NewDurationCmd(precision time.Duration, args ...interface{}) *DurationCmd {
+ return &DurationCmd{
+ baseCmd: baseCmd{_args: args},
+ precision: precision,
+ }
+}
+
+func (cmd *DurationCmd) Val() time.Duration {
+ return cmd.val
+}
+
+func (cmd *DurationCmd) Result() (time.Duration, error) {
+ return cmd.val, cmd.err
+}
+
+func (cmd *DurationCmd) String() string {
+ return cmdString(cmd, cmd.val)
+}
+
+func (cmd *DurationCmd) readReply(cn *pool.Conn) error {
+ var n int64
+ n, cmd.err = cn.Rd.ReadIntReply()
+ if cmd.err != nil {
+ return cmd.err
+ }
+ cmd.val = time.Duration(n) * cmd.precision
+ return nil
+}
+
+//------------------------------------------------------------------------------
+
+type TimeCmd struct {
+ baseCmd
+
+ val time.Time
+}
+
+var _ Cmder = (*TimeCmd)(nil)
+
+func NewTimeCmd(args ...interface{}) *TimeCmd {
+ return &TimeCmd{
+ baseCmd: baseCmd{_args: args},
+ }
+}
+
+func (cmd *TimeCmd) Val() time.Time {
+ return cmd.val
+}
+
+func (cmd *TimeCmd) Result() (time.Time, error) {
+ return cmd.val, cmd.err
+}
+
+func (cmd *TimeCmd) String() string {
+ return cmdString(cmd, cmd.val)
+}
+
+func (cmd *TimeCmd) readReply(cn *pool.Conn) error {
+ var v interface{}
+ v, cmd.err = cn.Rd.ReadArrayReply(timeParser)
+ if cmd.err != nil {
+ return cmd.err
+ }
+ cmd.val = v.(time.Time)
+ return nil
+}
+
+//------------------------------------------------------------------------------
+
+type BoolCmd struct {
+ baseCmd
+
+ val bool
+}
+
+var _ Cmder = (*BoolCmd)(nil)
+
+func NewBoolCmd(args ...interface{}) *BoolCmd {
+ return &BoolCmd{
+ baseCmd: baseCmd{_args: args},
+ }
+}
+
+func (cmd *BoolCmd) Val() bool {
+ return cmd.val
+}
+
+func (cmd *BoolCmd) Result() (bool, error) {
+ return cmd.val, cmd.err
+}
+
+func (cmd *BoolCmd) String() string {
+ return cmdString(cmd, cmd.val)
+}
+
+var ok = []byte("OK")
+
+func (cmd *BoolCmd) readReply(cn *pool.Conn) error {
+ var v interface{}
+ v, cmd.err = cn.Rd.ReadReply(nil)
+ // `SET key value NX` returns nil when key already exists. But
+ // `SETNX key value` returns bool (0/1). So convert nil to bool.
+ // TODO: is this okay?
+ if cmd.err == Nil {
+ cmd.val = false
+ cmd.err = nil
+ return nil
+ }
+ if cmd.err != nil {
+ return cmd.err
+ }
+ switch v := v.(type) {
+ case int64:
+ cmd.val = v == 1
+ return nil
+ case []byte:
+ cmd.val = bytes.Equal(v, ok)
+ return nil
+ default:
+ cmd.err = fmt.Errorf("got %T, wanted int64 or string", v)
+ return cmd.err
+ }
+}
+
+//------------------------------------------------------------------------------
+
+type StringCmd struct {
+ baseCmd
+
+ val []byte
+}
+
+var _ Cmder = (*StringCmd)(nil)
+
+func NewStringCmd(args ...interface{}) *StringCmd {
+ return &StringCmd{
+ baseCmd: baseCmd{_args: args},
+ }
+}
+
+func (cmd *StringCmd) Val() string {
+ return util.BytesToString(cmd.val)
+}
+
+func (cmd *StringCmd) Result() (string, error) {
+ return cmd.Val(), cmd.err
+}
+
+func (cmd *StringCmd) Bytes() ([]byte, error) {
+ return cmd.val, cmd.err
+}
+
+func (cmd *StringCmd) Int64() (int64, error) {
+ if cmd.err != nil {
+ return 0, cmd.err
+ }
+ return strconv.ParseInt(cmd.Val(), 10, 64)
+}
+
+func (cmd *StringCmd) Uint64() (uint64, error) {
+ if cmd.err != nil {
+ return 0, cmd.err
+ }
+ return strconv.ParseUint(cmd.Val(), 10, 64)
+}
+
+func (cmd *StringCmd) Float64() (float64, error) {
+ if cmd.err != nil {
+ return 0, cmd.err
+ }
+ return strconv.ParseFloat(cmd.Val(), 64)
+}
+
+func (cmd *StringCmd) Scan(val interface{}) error {
+ if cmd.err != nil {
+ return cmd.err
+ }
+ return proto.Scan(cmd.val, val)
+}
+
+func (cmd *StringCmd) String() string {
+ return cmdString(cmd, cmd.val)
+}
+
+func (cmd *StringCmd) readReply(cn *pool.Conn) error {
+ cmd.val, cmd.err = cn.Rd.ReadBytesReply()
+ return cmd.err
+}
+
+//------------------------------------------------------------------------------
+
+type FloatCmd struct {
+ baseCmd
+
+ val float64
+}
+
+var _ Cmder = (*FloatCmd)(nil)
+
+func NewFloatCmd(args ...interface{}) *FloatCmd {
+ return &FloatCmd{
+ baseCmd: baseCmd{_args: args},
+ }
+}
+
+func (cmd *FloatCmd) Val() float64 {
+ return cmd.val
+}
+
+func (cmd *FloatCmd) Result() (float64, error) {
+ return cmd.Val(), cmd.Err()
+}
+
+func (cmd *FloatCmd) String() string {
+ return cmdString(cmd, cmd.val)
+}
+
+func (cmd *FloatCmd) readReply(cn *pool.Conn) error {
+ cmd.val, cmd.err = cn.Rd.ReadFloatReply()
+ return cmd.err
+}
+
+//------------------------------------------------------------------------------
+
+type StringSliceCmd struct {
+ baseCmd
+
+ val []string
+}
+
+var _ Cmder = (*StringSliceCmd)(nil)
+
+func NewStringSliceCmd(args ...interface{}) *StringSliceCmd {
+ return &StringSliceCmd{
+ baseCmd: baseCmd{_args: args},
+ }
+}
+
+func (cmd *StringSliceCmd) Val() []string {
+ return cmd.val
+}
+
+func (cmd *StringSliceCmd) Result() ([]string, error) {
+ return cmd.Val(), cmd.Err()
+}
+
+func (cmd *StringSliceCmd) String() string {
+ return cmdString(cmd, cmd.val)
+}
+
+func (cmd *StringSliceCmd) ScanSlice(container interface{}) error {
+ return proto.ScanSlice(cmd.Val(), container)
+}
+
+func (cmd *StringSliceCmd) readReply(cn *pool.Conn) error {
+ var v interface{}
+ v, cmd.err = cn.Rd.ReadArrayReply(stringSliceParser)
+ if cmd.err != nil {
+ return cmd.err
+ }
+ cmd.val = v.([]string)
+ return nil
+}
+
+//------------------------------------------------------------------------------
+
+type BoolSliceCmd struct {
+ baseCmd
+
+ val []bool
+}
+
+var _ Cmder = (*BoolSliceCmd)(nil)
+
+func NewBoolSliceCmd(args ...interface{}) *BoolSliceCmd {
+ return &BoolSliceCmd{
+ baseCmd: baseCmd{_args: args},
+ }
+}
+
+func (cmd *BoolSliceCmd) Val() []bool {
+ return cmd.val
+}
+
+func (cmd *BoolSliceCmd) Result() ([]bool, error) {
+ return cmd.val, cmd.err
+}
+
+func (cmd *BoolSliceCmd) String() string {
+ return cmdString(cmd, cmd.val)
+}
+
+func (cmd *BoolSliceCmd) readReply(cn *pool.Conn) error {
+ var v interface{}
+ v, cmd.err = cn.Rd.ReadArrayReply(boolSliceParser)
+ if cmd.err != nil {
+ return cmd.err
+ }
+ cmd.val = v.([]bool)
+ return nil
+}
+
+//------------------------------------------------------------------------------
+
+type StringStringMapCmd struct {
+ baseCmd
+
+ val map[string]string
+}
+
+var _ Cmder = (*StringStringMapCmd)(nil)
+
+func NewStringStringMapCmd(args ...interface{}) *StringStringMapCmd {
+ return &StringStringMapCmd{
+ baseCmd: baseCmd{_args: args},
+ }
+}
+
+func (cmd *StringStringMapCmd) Val() map[string]string {
+ return cmd.val
+}
+
+func (cmd *StringStringMapCmd) Result() (map[string]string, error) {
+ return cmd.val, cmd.err
+}
+
+func (cmd *StringStringMapCmd) String() string {
+ return cmdString(cmd, cmd.val)
+}
+
+func (cmd *StringStringMapCmd) readReply(cn *pool.Conn) error {
+ var v interface{}
+ v, cmd.err = cn.Rd.ReadArrayReply(stringStringMapParser)
+ if cmd.err != nil {
+ return cmd.err
+ }
+ cmd.val = v.(map[string]string)
+ return nil
+}
+
+//------------------------------------------------------------------------------
+
+type StringIntMapCmd struct {
+ baseCmd
+
+ val map[string]int64
+}
+
+var _ Cmder = (*StringIntMapCmd)(nil)
+
+func NewStringIntMapCmd(args ...interface{}) *StringIntMapCmd {
+ return &StringIntMapCmd{
+ baseCmd: baseCmd{_args: args},
+ }
+}
+
+func (cmd *StringIntMapCmd) Val() map[string]int64 {
+ return cmd.val
+}
+
+func (cmd *StringIntMapCmd) Result() (map[string]int64, error) {
+ return cmd.val, cmd.err
+}
+
+func (cmd *StringIntMapCmd) String() string {
+ return cmdString(cmd, cmd.val)
+}
+
+func (cmd *StringIntMapCmd) readReply(cn *pool.Conn) error {
+ var v interface{}
+ v, cmd.err = cn.Rd.ReadArrayReply(stringIntMapParser)
+ if cmd.err != nil {
+ return cmd.err
+ }
+ cmd.val = v.(map[string]int64)
+ return nil
+}
+
+//------------------------------------------------------------------------------
+
+type StringStructMapCmd struct {
+ baseCmd
+
+ val map[string]struct{}
+}
+
+var _ Cmder = (*StringStructMapCmd)(nil)
+
+func NewStringStructMapCmd(args ...interface{}) *StringStructMapCmd {
+ return &StringStructMapCmd{
+ baseCmd: baseCmd{_args: args},
+ }
+}
+
+func (cmd *StringStructMapCmd) Val() map[string]struct{} {
+ return cmd.val
+}
+
+func (cmd *StringStructMapCmd) Result() (map[string]struct{}, error) {
+ return cmd.val, cmd.err
+}
+
+func (cmd *StringStructMapCmd) String() string {
+ return cmdString(cmd, cmd.val)
+}
+
+func (cmd *StringStructMapCmd) readReply(cn *pool.Conn) error {
+ var v interface{}
+ v, cmd.err = cn.Rd.ReadArrayReply(stringStructMapParser)
+ if cmd.err != nil {
+ return cmd.err
+ }
+ cmd.val = v.(map[string]struct{})
+ return nil
+}
+
+//------------------------------------------------------------------------------
+
+type XStream struct {
+ Stream string
+ Messages []*XMessage
+}
+
+type XMessage struct {
+ ID string
+ Values map[string]interface{}
+}
+
+//------------------------------------------------------------------------------
+
+type XStreamSliceCmd struct {
+ baseCmd
+
+ val []*XStream
+}
+
+var _ Cmder = (*XStreamSliceCmd)(nil)
+
+func NewXStreamSliceCmd(args ...interface{}) *XStreamSliceCmd {
+ return &XStreamSliceCmd{
+ baseCmd: baseCmd{_args: args},
+ }
+}
+
+func (cmd *XStreamSliceCmd) Val() []*XStream {
+ return cmd.val
+}
+
+func (cmd *XStreamSliceCmd) Result() ([]*XStream, error) {
+ return cmd.val, cmd.err
+}
+
+func (cmd *XStreamSliceCmd) String() string {
+ return cmdString(cmd, cmd.val)
+}
+
+func (cmd *XStreamSliceCmd) readReply(cn *pool.Conn) error {
+ var v interface{}
+ v, cmd.err = cn.Rd.ReadArrayReply(xStreamSliceParser)
+ if cmd.err != nil {
+ return cmd.err
+ }
+ cmd.val = v.([]*XStream)
+ return nil
+}
+
+// Implements proto.MultiBulkParse
+func xStreamSliceParser(rd *proto.Reader, n int64) (interface{}, error) {
+ xx := make([]*XStream, n)
+ for i := int64(0); i < n; i++ {
+ v, err := rd.ReadArrayReply(xStreamParser)
+ if err != nil {
+ return nil, err
+ }
+ xx[i] = v.(*XStream)
+ }
+ return xx, nil
+}
+
+// Implements proto.MultiBulkParse
+func xStreamParser(rd *proto.Reader, n int64) (interface{}, error) {
+ if n != 2 {
+ return nil, fmt.Errorf("got %d, wanted 2", n)
+ }
+
+ stream, err := rd.ReadStringReply()
+ if err != nil {
+ return nil, err
+ }
+
+ v, err := rd.ReadArrayReply(xMessageSliceParser)
+ if err != nil {
+ return nil, err
+ }
+
+ return &XStream{
+ Stream: stream,
+ Messages: v.([]*XMessage),
+ }, nil
+}
+
+//------------------------------------------------------------------------------
+
+type XMessageSliceCmd struct {
+ baseCmd
+
+ val []*XMessage
+}
+
+var _ Cmder = (*XMessageSliceCmd)(nil)
+
+func NewXMessageSliceCmd(args ...interface{}) *XMessageSliceCmd {
+ return &XMessageSliceCmd{
+ baseCmd: baseCmd{_args: args},
+ }
+}
+
+func (cmd *XMessageSliceCmd) Val() []*XMessage {
+ return cmd.val
+}
+
+func (cmd *XMessageSliceCmd) Result() ([]*XMessage, error) {
+ return cmd.val, cmd.err
+}
+
+func (cmd *XMessageSliceCmd) String() string {
+ return cmdString(cmd, cmd.val)
+}
+
+func (cmd *XMessageSliceCmd) readReply(cn *pool.Conn) error {
+ var v interface{}
+ v, cmd.err = cn.Rd.ReadArrayReply(xMessageSliceParser)
+ if cmd.err != nil {
+ return cmd.err
+ }
+ cmd.val = v.([]*XMessage)
+ return nil
+}
+
+// Implements proto.MultiBulkParse
+func xMessageSliceParser(rd *proto.Reader, n int64) (interface{}, error) {
+ msgs := make([]*XMessage, n)
+ for i := int64(0); i < n; i++ {
+ v, err := rd.ReadArrayReply(xMessageParser)
+ if err != nil {
+ return nil, err
+ }
+ msgs[i] = v.(*XMessage)
+ }
+ return msgs, nil
+}
+
+// Implements proto.MultiBulkParse
+func xMessageParser(rd *proto.Reader, n int64) (interface{}, error) {
+ id, err := rd.ReadStringReply()
+ if err != nil {
+ return nil, err
+ }
+
+ v, err := rd.ReadArrayReply(xKeyValueParser)
+ if err != nil {
+ return nil, err
+ }
+
+ return &XMessage{
+ ID: id,
+ Values: v.(map[string]interface{}),
+ }, nil
+}
+
+// Implements proto.MultiBulkParse
+func xKeyValueParser(rd *proto.Reader, n int64) (interface{}, error) {
+ values := make(map[string]interface{}, n)
+ for i := int64(0); i < n; i += 2 {
+ key, err := rd.ReadStringReply()
+ if err != nil {
+ return nil, err
+ }
+
+ value, err := rd.ReadStringReply()
+ if err != nil {
+ return nil, err
+ }
+
+ values[key] = value
+ }
+ return values, nil
+}
+
+//------------------------------------------------------------------------------
+
+type ZSliceCmd struct {
+ baseCmd
+
+ val []Z
+}
+
+var _ Cmder = (*ZSliceCmd)(nil)
+
+func NewZSliceCmd(args ...interface{}) *ZSliceCmd {
+ return &ZSliceCmd{
+ baseCmd: baseCmd{_args: args},
+ }
+}
+
+func (cmd *ZSliceCmd) Val() []Z {
+ return cmd.val
+}
+
+func (cmd *ZSliceCmd) Result() ([]Z, error) {
+ return cmd.val, cmd.err
+}
+
+func (cmd *ZSliceCmd) String() string {
+ return cmdString(cmd, cmd.val)
+}
+
+func (cmd *ZSliceCmd) readReply(cn *pool.Conn) error {
+ var v interface{}
+ v, cmd.err = cn.Rd.ReadArrayReply(zSliceParser)
+ if cmd.err != nil {
+ return cmd.err
+ }
+ cmd.val = v.([]Z)
+ return nil
+}
+
+//------------------------------------------------------------------------------
+
+type ScanCmd struct {
+ baseCmd
+
+ page []string
+ cursor uint64
+
+ process func(cmd Cmder) error
+}
+
+var _ Cmder = (*ScanCmd)(nil)
+
+func NewScanCmd(process func(cmd Cmder) error, args ...interface{}) *ScanCmd {
+ return &ScanCmd{
+ baseCmd: baseCmd{_args: args},
+ process: process,
+ }
+}
+
+func (cmd *ScanCmd) Val() (keys []string, cursor uint64) {
+ return cmd.page, cmd.cursor
+}
+
+func (cmd *ScanCmd) Result() (keys []string, cursor uint64, err error) {
+ return cmd.page, cmd.cursor, cmd.err
+}
+
+func (cmd *ScanCmd) String() string {
+ return cmdString(cmd, cmd.page)
+}
+
+func (cmd *ScanCmd) readReply(cn *pool.Conn) error {
+ cmd.page, cmd.cursor, cmd.err = cn.Rd.ReadScanReply()
+ return cmd.err
+}
+
+// Iterator creates a new ScanIterator.
+func (cmd *ScanCmd) Iterator() *ScanIterator {
+ return &ScanIterator{
+ cmd: cmd,
+ }
+}
+
+//------------------------------------------------------------------------------
+
+type ClusterNode struct {
+ Id string
+ Addr string
+}
+
+type ClusterSlot struct {
+ Start int
+ End int
+ Nodes []ClusterNode
+}
+
+type ClusterSlotsCmd struct {
+ baseCmd
+
+ val []ClusterSlot
+}
+
+var _ Cmder = (*ClusterSlotsCmd)(nil)
+
+func NewClusterSlotsCmd(args ...interface{}) *ClusterSlotsCmd {
+ return &ClusterSlotsCmd{
+ baseCmd: baseCmd{_args: args},
+ }
+}
+
+func (cmd *ClusterSlotsCmd) Val() []ClusterSlot {
+ return cmd.val
+}
+
+func (cmd *ClusterSlotsCmd) Result() ([]ClusterSlot, error) {
+ return cmd.Val(), cmd.Err()
+}
+
+func (cmd *ClusterSlotsCmd) String() string {
+ return cmdString(cmd, cmd.val)
+}
+
+func (cmd *ClusterSlotsCmd) readReply(cn *pool.Conn) error {
+ var v interface{}
+ v, cmd.err = cn.Rd.ReadArrayReply(clusterSlotsParser)
+ if cmd.err != nil {
+ return cmd.err
+ }
+ cmd.val = v.([]ClusterSlot)
+ return nil
+}
+
+//------------------------------------------------------------------------------
+
+// GeoLocation is used with GeoAdd to add geospatial location.
+type GeoLocation struct {
+ Name string
+ Longitude, Latitude, Dist float64
+ GeoHash int64
+}
+
+// GeoRadiusQuery is used with GeoRadius to query geospatial index.
+type GeoRadiusQuery struct {
+ Radius float64
+ // Can be m, km, ft, or mi. Default is km.
+ Unit string
+ WithCoord bool
+ WithDist bool
+ WithGeoHash bool
+ Count int
+ // Can be ASC or DESC. Default is no sort order.
+ Sort string
+ Store string
+ StoreDist string
+}
+
+type GeoLocationCmd struct {
+ baseCmd
+
+ q *GeoRadiusQuery
+ locations []GeoLocation
+}
+
+var _ Cmder = (*GeoLocationCmd)(nil)
+
+func NewGeoLocationCmd(q *GeoRadiusQuery, args ...interface{}) *GeoLocationCmd {
+ args = append(args, q.Radius)
+ if q.Unit != "" {
+ args = append(args, q.Unit)
+ } else {
+ args = append(args, "km")
+ }
+ if q.WithCoord {
+ args = append(args, "withcoord")
+ }
+ if q.WithDist {
+ args = append(args, "withdist")
+ }
+ if q.WithGeoHash {
+ args = append(args, "withhash")
+ }
+ if q.Count > 0 {
+ args = append(args, "count", q.Count)
+ }
+ if q.Sort != "" {
+ args = append(args, q.Sort)
+ }
+ if q.Store != "" {
+ args = append(args, "store")
+ args = append(args, q.Store)
+ }
+ if q.StoreDist != "" {
+ args = append(args, "storedist")
+ args = append(args, q.StoreDist)
+ }
+ return &GeoLocationCmd{
+ baseCmd: baseCmd{_args: args},
+ q: q,
+ }
+}
+
+func (cmd *GeoLocationCmd) Val() []GeoLocation {
+ return cmd.locations
+}
+
+func (cmd *GeoLocationCmd) Result() ([]GeoLocation, error) {
+ return cmd.locations, cmd.err
+}
+
+func (cmd *GeoLocationCmd) String() string {
+ return cmdString(cmd, cmd.locations)
+}
+
+func (cmd *GeoLocationCmd) readReply(cn *pool.Conn) error {
+ var v interface{}
+ v, cmd.err = cn.Rd.ReadArrayReply(newGeoLocationSliceParser(cmd.q))
+ if cmd.err != nil {
+ return cmd.err
+ }
+ cmd.locations = v.([]GeoLocation)
+ return nil
+}
+
+//------------------------------------------------------------------------------
+
+type GeoPos struct {
+ Longitude, Latitude float64
+}
+
+type GeoPosCmd struct {
+ baseCmd
+
+ positions []*GeoPos
+}
+
+var _ Cmder = (*GeoPosCmd)(nil)
+
+func NewGeoPosCmd(args ...interface{}) *GeoPosCmd {
+ return &GeoPosCmd{
+ baseCmd: baseCmd{_args: args},
+ }
+}
+
+func (cmd *GeoPosCmd) Val() []*GeoPos {
+ return cmd.positions
+}
+
+func (cmd *GeoPosCmd) Result() ([]*GeoPos, error) {
+ return cmd.Val(), cmd.Err()
+}
+
+func (cmd *GeoPosCmd) String() string {
+ return cmdString(cmd, cmd.positions)
+}
+
+func (cmd *GeoPosCmd) readReply(cn *pool.Conn) error {
+ var v interface{}
+ v, cmd.err = cn.Rd.ReadArrayReply(geoPosSliceParser)
+ if cmd.err != nil {
+ return cmd.err
+ }
+ cmd.positions = v.([]*GeoPos)
+ return nil
+}
+
+//------------------------------------------------------------------------------
+
+type CommandInfo struct {
+ Name string
+ Arity int8
+ Flags []string
+ FirstKeyPos int8
+ LastKeyPos int8
+ StepCount int8
+ ReadOnly bool
+}
+
+type CommandsInfoCmd struct {
+ baseCmd
+
+ val map[string]*CommandInfo
+}
+
+var _ Cmder = (*CommandsInfoCmd)(nil)
+
+func NewCommandsInfoCmd(args ...interface{}) *CommandsInfoCmd {
+ return &CommandsInfoCmd{
+ baseCmd: baseCmd{_args: args},
+ }
+}
+
+func (cmd *CommandsInfoCmd) Val() map[string]*CommandInfo {
+ return cmd.val
+}
+
+func (cmd *CommandsInfoCmd) Result() (map[string]*CommandInfo, error) {
+ return cmd.Val(), cmd.Err()
+}
+
+func (cmd *CommandsInfoCmd) String() string {
+ return cmdString(cmd, cmd.val)
+}
+
+func (cmd *CommandsInfoCmd) readReply(cn *pool.Conn) error {
+ var v interface{}
+ v, cmd.err = cn.Rd.ReadArrayReply(commandInfoSliceParser)
+ if cmd.err != nil {
+ return cmd.err
+ }
+ cmd.val = v.(map[string]*CommandInfo)
+ return nil
+}
+
+//------------------------------------------------------------------------------
+
+type cmdsInfoCache struct {
+ fn func() (map[string]*CommandInfo, error)
+
+ once internal.Once
+ cmds map[string]*CommandInfo
+}
+
+func newCmdsInfoCache(fn func() (map[string]*CommandInfo, error)) *cmdsInfoCache {
+ return &cmdsInfoCache{
+ fn: fn,
+ }
+}
+
+func (c *cmdsInfoCache) Get() (map[string]*CommandInfo, error) {
+ err := c.once.Do(func() error {
+ cmds, err := c.fn()
+ if err != nil {
+ return err
+ }
+ c.cmds = cmds
+ return nil
+ })
+ return c.cmds, err
+}
diff --git a/src/dma/vendor/github.com/go-redis/redis/commands.go b/src/dma/vendor/github.com/go-redis/redis/commands.go
new file mode 100644
index 00000000..dddf8acd
--- /dev/null
+++ b/src/dma/vendor/github.com/go-redis/redis/commands.go
@@ -0,0 +1,2337 @@
+package redis
+
+import (
+ "errors"
+ "io"
+ "time"
+
+ "github.com/go-redis/redis/internal"
+)
+
+func readTimeout(timeout time.Duration) time.Duration {
+ if timeout == 0 {
+ return 0
+ }
+ return timeout + 10*time.Second
+}
+
+func usePrecise(dur time.Duration) bool {
+ return dur < time.Second || dur%time.Second != 0
+}
+
+func formatMs(dur time.Duration) int64 {
+ if dur > 0 && dur < time.Millisecond {
+ internal.Logf(
+ "specified duration is %s, but minimal supported value is %s",
+ dur, time.Millisecond,
+ )
+ }
+ return int64(dur / time.Millisecond)
+}
+
+func formatSec(dur time.Duration) int64 {
+ if dur > 0 && dur < time.Second {
+ internal.Logf(
+ "specified duration is %s, but minimal supported value is %s",
+ dur, time.Second,
+ )
+ }
+ return int64(dur / time.Second)
+}
+
+func appendArgs(dst, src []interface{}) []interface{} {
+ if len(src) == 1 {
+ if ss, ok := src[0].([]string); ok {
+ for _, s := range ss {
+ dst = append(dst, s)
+ }
+ return dst
+ }
+ }
+
+ for _, v := range src {
+ dst = append(dst, v)
+ }
+ return dst
+}
+
+type Cmdable interface {
+ Pipeline() Pipeliner
+ Pipelined(fn func(Pipeliner) error) ([]Cmder, error)
+
+ TxPipelined(fn func(Pipeliner) error) ([]Cmder, error)
+ TxPipeline() Pipeliner
+
+ Command() *CommandsInfoCmd
+ ClientGetName() *StringCmd
+ Echo(message interface{}) *StringCmd
+ Ping() *StatusCmd
+ Quit() *StatusCmd
+ Del(keys ...string) *IntCmd
+ Unlink(keys ...string) *IntCmd
+ Dump(key string) *StringCmd
+ Exists(keys ...string) *IntCmd
+ Expire(key string, expiration time.Duration) *BoolCmd
+ ExpireAt(key string, tm time.Time) *BoolCmd
+ Keys(pattern string) *StringSliceCmd
+ Migrate(host, port, key string, db int64, timeout time.Duration) *StatusCmd
+ Move(key string, db int64) *BoolCmd
+ ObjectRefCount(key string) *IntCmd
+ ObjectEncoding(key string) *StringCmd
+ ObjectIdleTime(key string) *DurationCmd
+ Persist(key string) *BoolCmd
+ PExpire(key string, expiration time.Duration) *BoolCmd
+ PExpireAt(key string, tm time.Time) *BoolCmd
+ PTTL(key string) *DurationCmd
+ RandomKey() *StringCmd
+ Rename(key, newkey string) *StatusCmd
+ RenameNX(key, newkey string) *BoolCmd
+ Restore(key string, ttl time.Duration, value string) *StatusCmd
+ RestoreReplace(key string, ttl time.Duration, value string) *StatusCmd
+ Sort(key string, sort *Sort) *StringSliceCmd
+ SortStore(key, store string, sort *Sort) *IntCmd
+ SortInterfaces(key string, sort *Sort) *SliceCmd
+ Touch(keys ...string) *IntCmd
+ TTL(key string) *DurationCmd
+ Type(key string) *StatusCmd
+ Scan(cursor uint64, match string, count int64) *ScanCmd
+ SScan(key string, cursor uint64, match string, count int64) *ScanCmd
+ HScan(key string, cursor uint64, match string, count int64) *ScanCmd
+ ZScan(key string, cursor uint64, match string, count int64) *ScanCmd
+ Append(key, value string) *IntCmd
+ BitCount(key string, bitCount *BitCount) *IntCmd
+ BitOpAnd(destKey string, keys ...string) *IntCmd
+ BitOpOr(destKey string, keys ...string) *IntCmd
+ BitOpXor(destKey string, keys ...string) *IntCmd
+ BitOpNot(destKey string, key string) *IntCmd
+ BitPos(key string, bit int64, pos ...int64) *IntCmd
+ Decr(key string) *IntCmd
+ DecrBy(key string, decrement int64) *IntCmd
+ Get(key string) *StringCmd
+ GetBit(key string, offset int64) *IntCmd
+ GetRange(key string, start, end int64) *StringCmd
+ GetSet(key string, value interface{}) *StringCmd
+ Incr(key string) *IntCmd
+ IncrBy(key string, value int64) *IntCmd
+ IncrByFloat(key string, value float64) *FloatCmd
+ MGet(keys ...string) *SliceCmd
+ MSet(pairs ...interface{}) *StatusCmd
+ MSetNX(pairs ...interface{}) *BoolCmd
+ Set(key string, value interface{}, expiration time.Duration) *StatusCmd
+ SetBit(key string, offset int64, value int) *IntCmd
+ SetNX(key string, value interface{}, expiration time.Duration) *BoolCmd
+ SetXX(key string, value interface{}, expiration time.Duration) *BoolCmd
+ SetRange(key string, offset int64, value string) *IntCmd
+ StrLen(key string) *IntCmd
+ HDel(key string, fields ...string) *IntCmd
+ HExists(key, field string) *BoolCmd
+ HGet(key, field string) *StringCmd
+ HGetAll(key string) *StringStringMapCmd
+ HIncrBy(key, field string, incr int64) *IntCmd
+ HIncrByFloat(key, field string, incr float64) *FloatCmd
+ HKeys(key string) *StringSliceCmd
+ HLen(key string) *IntCmd
+ HMGet(key string, fields ...string) *SliceCmd
+ HMSet(key string, fields map[string]interface{}) *StatusCmd
+ HSet(key, field string, value interface{}) *BoolCmd
+ HSetNX(key, field string, value interface{}) *BoolCmd
+ HVals(key string) *StringSliceCmd
+ BLPop(timeout time.Duration, keys ...string) *StringSliceCmd
+ BRPop(timeout time.Duration, keys ...string) *StringSliceCmd
+ BRPopLPush(source, destination string, timeout time.Duration) *StringCmd
+ LIndex(key string, index int64) *StringCmd
+ LInsert(key, op string, pivot, value interface{}) *IntCmd
+ LInsertBefore(key string, pivot, value interface{}) *IntCmd
+ LInsertAfter(key string, pivot, value interface{}) *IntCmd
+ LLen(key string) *IntCmd
+ LPop(key string) *StringCmd
+ LPush(key string, values ...interface{}) *IntCmd
+ LPushX(key string, value interface{}) *IntCmd
+ LRange(key string, start, stop int64) *StringSliceCmd
+ LRem(key string, count int64, value interface{}) *IntCmd
+ LSet(key string, index int64, value interface{}) *StatusCmd
+ LTrim(key string, start, stop int64) *StatusCmd
+ RPop(key string) *StringCmd
+ RPopLPush(source, destination string) *StringCmd
+ RPush(key string, values ...interface{}) *IntCmd
+ RPushX(key string, value interface{}) *IntCmd
+ SAdd(key string, members ...interface{}) *IntCmd
+ SCard(key string) *IntCmd
+ SDiff(keys ...string) *StringSliceCmd
+ SDiffStore(destination string, keys ...string) *IntCmd
+ SInter(keys ...string) *StringSliceCmd
+ SInterStore(destination string, keys ...string) *IntCmd
+ SIsMember(key string, member interface{}) *BoolCmd
+ SMembers(key string) *StringSliceCmd
+ SMembersMap(key string) *StringStructMapCmd
+ SMove(source, destination string, member interface{}) *BoolCmd
+ SPop(key string) *StringCmd
+ SPopN(key string, count int64) *StringSliceCmd
+ SRandMember(key string) *StringCmd
+ SRandMemberN(key string, count int64) *StringSliceCmd
+ SRem(key string, members ...interface{}) *IntCmd
+ SUnion(keys ...string) *StringSliceCmd
+ SUnionStore(destination string, keys ...string) *IntCmd
+ XAdd(stream, id string, els map[string]interface{}) *StringCmd
+ XAddExt(opt *XAddExt) *StringCmd
+ XLen(key string) *IntCmd
+ XRange(stream, start, stop string) *XMessageSliceCmd
+ XRangeN(stream, start, stop string, count int64) *XMessageSliceCmd
+ XRevRange(stream string, start, stop string) *XMessageSliceCmd
+ XRevRangeN(stream string, start, stop string, count int64) *XMessageSliceCmd
+ XRead(streams ...string) *XStreamSliceCmd
+ XReadN(count int64, streams ...string) *XStreamSliceCmd
+ XReadExt(opt *XReadExt) *XStreamSliceCmd
+ ZAdd(key string, members ...Z) *IntCmd
+ ZAddNX(key string, members ...Z) *IntCmd
+ ZAddXX(key string, members ...Z) *IntCmd
+ ZAddCh(key string, members ...Z) *IntCmd
+ ZAddNXCh(key string, members ...Z) *IntCmd
+ ZAddXXCh(key string, members ...Z) *IntCmd
+ ZIncr(key string, member Z) *FloatCmd
+ ZIncrNX(key string, member Z) *FloatCmd
+ ZIncrXX(key string, member Z) *FloatCmd
+ ZCard(key string) *IntCmd
+ ZCount(key, min, max string) *IntCmd
+ ZLexCount(key, min, max string) *IntCmd
+ ZIncrBy(key string, increment float64, member string) *FloatCmd
+ ZInterStore(destination string, store ZStore, keys ...string) *IntCmd
+ ZRange(key string, start, stop int64) *StringSliceCmd
+ ZRangeWithScores(key string, start, stop int64) *ZSliceCmd
+ ZRangeByScore(key string, opt ZRangeBy) *StringSliceCmd
+ ZRangeByLex(key string, opt ZRangeBy) *StringSliceCmd
+ ZRangeByScoreWithScores(key string, opt ZRangeBy) *ZSliceCmd
+ ZRank(key, member string) *IntCmd
+ ZRem(key string, members ...interface{}) *IntCmd
+ ZRemRangeByRank(key string, start, stop int64) *IntCmd
+ ZRemRangeByScore(key, min, max string) *IntCmd
+ ZRemRangeByLex(key, min, max string) *IntCmd
+ ZRevRange(key string, start, stop int64) *StringSliceCmd
+ ZRevRangeWithScores(key string, start, stop int64) *ZSliceCmd
+ ZRevRangeByScore(key string, opt ZRangeBy) *StringSliceCmd
+ ZRevRangeByLex(key string, opt ZRangeBy) *StringSliceCmd
+ ZRevRangeByScoreWithScores(key string, opt ZRangeBy) *ZSliceCmd
+ ZRevRank(key, member string) *IntCmd
+ ZScore(key, member string) *FloatCmd
+ ZUnionStore(dest string, store ZStore, keys ...string) *IntCmd
+ PFAdd(key string, els ...interface{}) *IntCmd
+ PFCount(keys ...string) *IntCmd
+ PFMerge(dest string, keys ...string) *StatusCmd
+ BgRewriteAOF() *StatusCmd
+ BgSave() *StatusCmd
+ ClientKill(ipPort string) *StatusCmd
+ ClientKillByFilter(keys ...string) *IntCmd
+ ClientList() *StringCmd
+ ClientPause(dur time.Duration) *BoolCmd
+ ConfigGet(parameter string) *SliceCmd
+ ConfigResetStat() *StatusCmd
+ ConfigSet(parameter, value string) *StatusCmd
+ ConfigRewrite() *StatusCmd
+ DBSize() *IntCmd
+ FlushAll() *StatusCmd
+ FlushAllAsync() *StatusCmd
+ FlushDB() *StatusCmd
+ FlushDBAsync() *StatusCmd
+ Info(section ...string) *StringCmd
+ LastSave() *IntCmd
+ Save() *StatusCmd
+ Shutdown() *StatusCmd
+ ShutdownSave() *StatusCmd
+ ShutdownNoSave() *StatusCmd
+ SlaveOf(host, port string) *StatusCmd
+ Time() *TimeCmd
+ Eval(script string, keys []string, args ...interface{}) *Cmd
+ EvalSha(sha1 string, keys []string, args ...interface{}) *Cmd
+ ScriptExists(hashes ...string) *BoolSliceCmd
+ ScriptFlush() *StatusCmd
+ ScriptKill() *StatusCmd
+ ScriptLoad(script string) *StringCmd
+ DebugObject(key string) *StringCmd
+ Publish(channel string, message interface{}) *IntCmd
+ PubSubChannels(pattern string) *StringSliceCmd
+ PubSubNumSub(channels ...string) *StringIntMapCmd
+ PubSubNumPat() *IntCmd
+ ClusterSlots() *ClusterSlotsCmd
+ ClusterNodes() *StringCmd
+ ClusterMeet(host, port string) *StatusCmd
+ ClusterForget(nodeID string) *StatusCmd
+ ClusterReplicate(nodeID string) *StatusCmd
+ ClusterResetSoft() *StatusCmd
+ ClusterResetHard() *StatusCmd
+ ClusterInfo() *StringCmd
+ ClusterKeySlot(key string) *IntCmd
+ ClusterCountFailureReports(nodeID string) *IntCmd
+ ClusterCountKeysInSlot(slot int) *IntCmd
+ ClusterDelSlots(slots ...int) *StatusCmd
+ ClusterDelSlotsRange(min, max int) *StatusCmd
+ ClusterSaveConfig() *StatusCmd
+ ClusterSlaves(nodeID string) *StringSliceCmd
+ ClusterFailover() *StatusCmd
+ ClusterAddSlots(slots ...int) *StatusCmd
+ ClusterAddSlotsRange(min, max int) *StatusCmd
+ GeoAdd(key string, geoLocation ...*GeoLocation) *IntCmd
+ GeoPos(key string, members ...string) *GeoPosCmd
+ GeoRadius(key string, longitude, latitude float64, query *GeoRadiusQuery) *GeoLocationCmd
+ GeoRadiusRO(key string, longitude, latitude float64, query *GeoRadiusQuery) *GeoLocationCmd
+ GeoRadiusByMember(key, member string, query *GeoRadiusQuery) *GeoLocationCmd
+ GeoRadiusByMemberRO(key, member string, query *GeoRadiusQuery) *GeoLocationCmd
+ GeoDist(key string, member1, member2, unit string) *FloatCmd
+ GeoHash(key string, members ...string) *StringSliceCmd
+ ReadOnly() *StatusCmd
+ ReadWrite() *StatusCmd
+ MemoryUsage(key string, samples ...int) *IntCmd
+}
+
+type StatefulCmdable interface {
+ Cmdable
+ Auth(password string) *StatusCmd
+ Select(index int) *StatusCmd
+ SwapDB(index1, index2 int) *StatusCmd
+ ClientSetName(name string) *BoolCmd
+}
+
+var _ Cmdable = (*Client)(nil)
+var _ Cmdable = (*Tx)(nil)
+var _ Cmdable = (*Ring)(nil)
+var _ Cmdable = (*ClusterClient)(nil)
+
+type cmdable struct {
+ process func(cmd Cmder) error
+}
+
+func (c *cmdable) setProcessor(fn func(Cmder) error) {
+ c.process = fn
+}
+
+type statefulCmdable struct {
+ cmdable
+ process func(cmd Cmder) error
+}
+
+func (c *statefulCmdable) setProcessor(fn func(Cmder) error) {
+ c.process = fn
+ c.cmdable.setProcessor(fn)
+}
+
+//------------------------------------------------------------------------------
+
+func (c *statefulCmdable) Auth(password string) *StatusCmd {
+ cmd := NewStatusCmd("auth", password)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) Echo(message interface{}) *StringCmd {
+ cmd := NewStringCmd("echo", message)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) Ping() *StatusCmd {
+ cmd := NewStatusCmd("ping")
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) Wait(numSlaves int, timeout time.Duration) *IntCmd {
+ cmd := NewIntCmd("wait", numSlaves, int(timeout/time.Millisecond))
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) Quit() *StatusCmd {
+ panic("not implemented")
+}
+
+func (c *statefulCmdable) Select(index int) *StatusCmd {
+ cmd := NewStatusCmd("select", index)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *statefulCmdable) SwapDB(index1, index2 int) *StatusCmd {
+ cmd := NewStatusCmd("swapdb", index1, index2)
+ c.process(cmd)
+ return cmd
+}
+
+//------------------------------------------------------------------------------
+
+func (c *cmdable) Command() *CommandsInfoCmd {
+ cmd := NewCommandsInfoCmd("command")
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) Del(keys ...string) *IntCmd {
+ args := make([]interface{}, 1+len(keys))
+ args[0] = "del"
+ for i, key := range keys {
+ args[1+i] = key
+ }
+ cmd := NewIntCmd(args...)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) Unlink(keys ...string) *IntCmd {
+ args := make([]interface{}, 1+len(keys))
+ args[0] = "unlink"
+ for i, key := range keys {
+ args[1+i] = key
+ }
+ cmd := NewIntCmd(args...)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) Dump(key string) *StringCmd {
+ cmd := NewStringCmd("dump", key)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) Exists(keys ...string) *IntCmd {
+ args := make([]interface{}, 1+len(keys))
+ args[0] = "exists"
+ for i, key := range keys {
+ args[1+i] = key
+ }
+ cmd := NewIntCmd(args...)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) Expire(key string, expiration time.Duration) *BoolCmd {
+ cmd := NewBoolCmd("expire", key, formatSec(expiration))
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) ExpireAt(key string, tm time.Time) *BoolCmd {
+ cmd := NewBoolCmd("expireat", key, tm.Unix())
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) Keys(pattern string) *StringSliceCmd {
+ cmd := NewStringSliceCmd("keys", pattern)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) Migrate(host, port, key string, db int64, timeout time.Duration) *StatusCmd {
+ cmd := NewStatusCmd(
+ "migrate",
+ host,
+ port,
+ key,
+ db,
+ formatMs(timeout),
+ )
+ cmd.setReadTimeout(timeout)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) Move(key string, db int64) *BoolCmd {
+ cmd := NewBoolCmd("move", key, db)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) ObjectRefCount(key string) *IntCmd {
+ cmd := NewIntCmd("object", "refcount", key)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) ObjectEncoding(key string) *StringCmd {
+ cmd := NewStringCmd("object", "encoding", key)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) ObjectIdleTime(key string) *DurationCmd {
+ cmd := NewDurationCmd(time.Second, "object", "idletime", key)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) Persist(key string) *BoolCmd {
+ cmd := NewBoolCmd("persist", key)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) PExpire(key string, expiration time.Duration) *BoolCmd {
+ cmd := NewBoolCmd("pexpire", key, formatMs(expiration))
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) PExpireAt(key string, tm time.Time) *BoolCmd {
+ cmd := NewBoolCmd(
+ "pexpireat",
+ key,
+ tm.UnixNano()/int64(time.Millisecond),
+ )
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) PTTL(key string) *DurationCmd {
+ cmd := NewDurationCmd(time.Millisecond, "pttl", key)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) RandomKey() *StringCmd {
+ cmd := NewStringCmd("randomkey")
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) Rename(key, newkey string) *StatusCmd {
+ cmd := NewStatusCmd("rename", key, newkey)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) RenameNX(key, newkey string) *BoolCmd {
+ cmd := NewBoolCmd("renamenx", key, newkey)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) Restore(key string, ttl time.Duration, value string) *StatusCmd {
+ cmd := NewStatusCmd(
+ "restore",
+ key,
+ formatMs(ttl),
+ value,
+ )
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) RestoreReplace(key string, ttl time.Duration, value string) *StatusCmd {
+ cmd := NewStatusCmd(
+ "restore",
+ key,
+ formatMs(ttl),
+ value,
+ "replace",
+ )
+ c.process(cmd)
+ return cmd
+}
+
+type Sort struct {
+ By string
+ Offset, Count int64
+ Get []string
+ Order string
+ Alpha bool
+}
+
+func (sort *Sort) args(key string) []interface{} {
+ args := []interface{}{"sort", key}
+ if sort.By != "" {
+ args = append(args, "by", sort.By)
+ }
+ if sort.Offset != 0 || sort.Count != 0 {
+ args = append(args, "limit", sort.Offset, sort.Count)
+ }
+ for _, get := range sort.Get {
+ args = append(args, "get", get)
+ }
+ if sort.Order != "" {
+ args = append(args, sort.Order)
+ }
+ if sort.Alpha {
+ args = append(args, "alpha")
+ }
+ return args
+}
+
+func (c *cmdable) Sort(key string, sort *Sort) *StringSliceCmd {
+ cmd := NewStringSliceCmd(sort.args(key)...)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) SortStore(key, store string, sort *Sort) *IntCmd {
+ args := sort.args(key)
+ if store != "" {
+ args = append(args, "store", store)
+ }
+ cmd := NewIntCmd(args...)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) SortInterfaces(key string, sort *Sort) *SliceCmd {
+ cmd := NewSliceCmd(sort.args(key)...)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) Touch(keys ...string) *IntCmd {
+ args := make([]interface{}, len(keys)+1)
+ args[0] = "touch"
+ for i, key := range keys {
+ args[i+1] = key
+ }
+ cmd := NewIntCmd(args...)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) TTL(key string) *DurationCmd {
+ cmd := NewDurationCmd(time.Second, "ttl", key)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) Type(key string) *StatusCmd {
+ cmd := NewStatusCmd("type", key)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) Scan(cursor uint64, match string, count int64) *ScanCmd {
+ args := []interface{}{"scan", cursor}
+ if match != "" {
+ args = append(args, "match", match)
+ }
+ if count > 0 {
+ args = append(args, "count", count)
+ }
+ cmd := NewScanCmd(c.process, args...)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) SScan(key string, cursor uint64, match string, count int64) *ScanCmd {
+ args := []interface{}{"sscan", key, cursor}
+ if match != "" {
+ args = append(args, "match", match)
+ }
+ if count > 0 {
+ args = append(args, "count", count)
+ }
+ cmd := NewScanCmd(c.process, args...)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) HScan(key string, cursor uint64, match string, count int64) *ScanCmd {
+ args := []interface{}{"hscan", key, cursor}
+ if match != "" {
+ args = append(args, "match", match)
+ }
+ if count > 0 {
+ args = append(args, "count", count)
+ }
+ cmd := NewScanCmd(c.process, args...)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) ZScan(key string, cursor uint64, match string, count int64) *ScanCmd {
+ args := []interface{}{"zscan", key, cursor}
+ if match != "" {
+ args = append(args, "match", match)
+ }
+ if count > 0 {
+ args = append(args, "count", count)
+ }
+ cmd := NewScanCmd(c.process, args...)
+ c.process(cmd)
+ return cmd
+}
+
+//------------------------------------------------------------------------------
+
+func (c *cmdable) Append(key, value string) *IntCmd {
+ cmd := NewIntCmd("append", key, value)
+ c.process(cmd)
+ return cmd
+}
+
+type BitCount struct {
+ Start, End int64
+}
+
+func (c *cmdable) BitCount(key string, bitCount *BitCount) *IntCmd {
+ args := []interface{}{"bitcount", key}
+ if bitCount != nil {
+ args = append(
+ args,
+ bitCount.Start,
+ bitCount.End,
+ )
+ }
+ cmd := NewIntCmd(args...)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) bitOp(op, destKey string, keys ...string) *IntCmd {
+ args := make([]interface{}, 3+len(keys))
+ args[0] = "bitop"
+ args[1] = op
+ args[2] = destKey
+ for i, key := range keys {
+ args[3+i] = key
+ }
+ cmd := NewIntCmd(args...)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) BitOpAnd(destKey string, keys ...string) *IntCmd {
+ return c.bitOp("and", destKey, keys...)
+}
+
+func (c *cmdable) BitOpOr(destKey string, keys ...string) *IntCmd {
+ return c.bitOp("or", destKey, keys...)
+}
+
+func (c *cmdable) BitOpXor(destKey string, keys ...string) *IntCmd {
+ return c.bitOp("xor", destKey, keys...)
+}
+
+func (c *cmdable) BitOpNot(destKey string, key string) *IntCmd {
+ return c.bitOp("not", destKey, key)
+}
+
+func (c *cmdable) BitPos(key string, bit int64, pos ...int64) *IntCmd {
+ args := make([]interface{}, 3+len(pos))
+ args[0] = "bitpos"
+ args[1] = key
+ args[2] = bit
+ switch len(pos) {
+ case 0:
+ case 1:
+ args[3] = pos[0]
+ case 2:
+ args[3] = pos[0]
+ args[4] = pos[1]
+ default:
+ panic("too many arguments")
+ }
+ cmd := NewIntCmd(args...)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) Decr(key string) *IntCmd {
+ cmd := NewIntCmd("decr", key)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) DecrBy(key string, decrement int64) *IntCmd {
+ cmd := NewIntCmd("decrby", key, decrement)
+ c.process(cmd)
+ return cmd
+}
+
+// Redis `GET key` command. It returns redis.Nil error when key does not exist.
+func (c *cmdable) Get(key string) *StringCmd {
+ cmd := NewStringCmd("get", key)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) GetBit(key string, offset int64) *IntCmd {
+ cmd := NewIntCmd("getbit", key, offset)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) GetRange(key string, start, end int64) *StringCmd {
+ cmd := NewStringCmd("getrange", key, start, end)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) GetSet(key string, value interface{}) *StringCmd {
+ cmd := NewStringCmd("getset", key, value)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) Incr(key string) *IntCmd {
+ cmd := NewIntCmd("incr", key)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) IncrBy(key string, value int64) *IntCmd {
+ cmd := NewIntCmd("incrby", key, value)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) IncrByFloat(key string, value float64) *FloatCmd {
+ cmd := NewFloatCmd("incrbyfloat", key, value)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) MGet(keys ...string) *SliceCmd {
+ args := make([]interface{}, 1+len(keys))
+ args[0] = "mget"
+ for i, key := range keys {
+ args[1+i] = key
+ }
+ cmd := NewSliceCmd(args...)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) MSet(pairs ...interface{}) *StatusCmd {
+ args := make([]interface{}, 1, 1+len(pairs))
+ args[0] = "mset"
+ args = appendArgs(args, pairs)
+ cmd := NewStatusCmd(args...)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) MSetNX(pairs ...interface{}) *BoolCmd {
+ args := make([]interface{}, 1, 1+len(pairs))
+ args[0] = "msetnx"
+ args = appendArgs(args, pairs)
+ cmd := NewBoolCmd(args...)
+ c.process(cmd)
+ return cmd
+}
+
+// Redis `SET key value [expiration]` command.
+//
+// Use expiration for `SETEX`-like behavior.
+// Zero expiration means the key has no expiration time.
+func (c *cmdable) Set(key string, value interface{}, expiration time.Duration) *StatusCmd {
+ args := make([]interface{}, 3, 4)
+ args[0] = "set"
+ args[1] = key
+ args[2] = value
+ if expiration > 0 {
+ if usePrecise(expiration) {
+ args = append(args, "px", formatMs(expiration))
+ } else {
+ args = append(args, "ex", formatSec(expiration))
+ }
+ }
+ cmd := NewStatusCmd(args...)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) SetBit(key string, offset int64, value int) *IntCmd {
+ cmd := NewIntCmd(
+ "setbit",
+ key,
+ offset,
+ value,
+ )
+ c.process(cmd)
+ return cmd
+}
+
+// Redis `SET key value [expiration] NX` command.
+//
+// Zero expiration means the key has no expiration time.
+func (c *cmdable) SetNX(key string, value interface{}, expiration time.Duration) *BoolCmd {
+ var cmd *BoolCmd
+ if expiration == 0 {
+ // Use old `SETNX` to support old Redis versions.
+ cmd = NewBoolCmd("setnx", key, value)
+ } else {
+ if usePrecise(expiration) {
+ cmd = NewBoolCmd("set", key, value, "px", formatMs(expiration), "nx")
+ } else {
+ cmd = NewBoolCmd("set", key, value, "ex", formatSec(expiration), "nx")
+ }
+ }
+ c.process(cmd)
+ return cmd
+}
+
+// Redis `SET key value [expiration] XX` command.
+//
+// Zero expiration means the key has no expiration time.
+func (c *cmdable) SetXX(key string, value interface{}, expiration time.Duration) *BoolCmd {
+ var cmd *BoolCmd
+ if expiration == 0 {
+ cmd = NewBoolCmd("set", key, value, "xx")
+ } else {
+ if usePrecise(expiration) {
+ cmd = NewBoolCmd("set", key, value, "px", formatMs(expiration), "xx")
+ } else {
+ cmd = NewBoolCmd("set", key, value, "ex", formatSec(expiration), "xx")
+ }
+ }
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) SetRange(key string, offset int64, value string) *IntCmd {
+ cmd := NewIntCmd("setrange", key, offset, value)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) StrLen(key string) *IntCmd {
+ cmd := NewIntCmd("strlen", key)
+ c.process(cmd)
+ return cmd
+}
+
+//------------------------------------------------------------------------------
+
+func (c *cmdable) HDel(key string, fields ...string) *IntCmd {
+ args := make([]interface{}, 2+len(fields))
+ args[0] = "hdel"
+ args[1] = key
+ for i, field := range fields {
+ args[2+i] = field
+ }
+ cmd := NewIntCmd(args...)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) HExists(key, field string) *BoolCmd {
+ cmd := NewBoolCmd("hexists", key, field)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) HGet(key, field string) *StringCmd {
+ cmd := NewStringCmd("hget", key, field)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) HGetAll(key string) *StringStringMapCmd {
+ cmd := NewStringStringMapCmd("hgetall", key)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) HIncrBy(key, field string, incr int64) *IntCmd {
+ cmd := NewIntCmd("hincrby", key, field, incr)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) HIncrByFloat(key, field string, incr float64) *FloatCmd {
+ cmd := NewFloatCmd("hincrbyfloat", key, field, incr)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) HKeys(key string) *StringSliceCmd {
+ cmd := NewStringSliceCmd("hkeys", key)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) HLen(key string) *IntCmd {
+ cmd := NewIntCmd("hlen", key)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) HMGet(key string, fields ...string) *SliceCmd {
+ args := make([]interface{}, 2+len(fields))
+ args[0] = "hmget"
+ args[1] = key
+ for i, field := range fields {
+ args[2+i] = field
+ }
+ cmd := NewSliceCmd(args...)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) HMSet(key string, fields map[string]interface{}) *StatusCmd {
+ args := make([]interface{}, 2+len(fields)*2)
+ args[0] = "hmset"
+ args[1] = key
+ i := 2
+ for k, v := range fields {
+ args[i] = k
+ args[i+1] = v
+ i += 2
+ }
+ cmd := NewStatusCmd(args...)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) HSet(key, field string, value interface{}) *BoolCmd {
+ cmd := NewBoolCmd("hset", key, field, value)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) HSetNX(key, field string, value interface{}) *BoolCmd {
+ cmd := NewBoolCmd("hsetnx", key, field, value)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) HVals(key string) *StringSliceCmd {
+ cmd := NewStringSliceCmd("hvals", key)
+ c.process(cmd)
+ return cmd
+}
+
+//------------------------------------------------------------------------------
+
+func (c *cmdable) BLPop(timeout time.Duration, keys ...string) *StringSliceCmd {
+ args := make([]interface{}, 1+len(keys)+1)
+ args[0] = "blpop"
+ for i, key := range keys {
+ args[1+i] = key
+ }
+ args[len(args)-1] = formatSec(timeout)
+ cmd := NewStringSliceCmd(args...)
+ cmd.setReadTimeout(timeout)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) BRPop(timeout time.Duration, keys ...string) *StringSliceCmd {
+ args := make([]interface{}, 1+len(keys)+1)
+ args[0] = "brpop"
+ for i, key := range keys {
+ args[1+i] = key
+ }
+ args[len(keys)+1] = formatSec(timeout)
+ cmd := NewStringSliceCmd(args...)
+ cmd.setReadTimeout(timeout)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) BRPopLPush(source, destination string, timeout time.Duration) *StringCmd {
+ cmd := NewStringCmd(
+ "brpoplpush",
+ source,
+ destination,
+ formatSec(timeout),
+ )
+ cmd.setReadTimeout(timeout)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) LIndex(key string, index int64) *StringCmd {
+ cmd := NewStringCmd("lindex", key, index)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) LInsert(key, op string, pivot, value interface{}) *IntCmd {
+ cmd := NewIntCmd("linsert", key, op, pivot, value)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) LInsertBefore(key string, pivot, value interface{}) *IntCmd {
+ cmd := NewIntCmd("linsert", key, "before", pivot, value)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) LInsertAfter(key string, pivot, value interface{}) *IntCmd {
+ cmd := NewIntCmd("linsert", key, "after", pivot, value)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) LLen(key string) *IntCmd {
+ cmd := NewIntCmd("llen", key)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) LPop(key string) *StringCmd {
+ cmd := NewStringCmd("lpop", key)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) LPush(key string, values ...interface{}) *IntCmd {
+ args := make([]interface{}, 2, 2+len(values))
+ args[0] = "lpush"
+ args[1] = key
+ args = appendArgs(args, values)
+ cmd := NewIntCmd(args...)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) LPushX(key string, value interface{}) *IntCmd {
+ cmd := NewIntCmd("lpushx", key, value)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) LRange(key string, start, stop int64) *StringSliceCmd {
+ cmd := NewStringSliceCmd(
+ "lrange",
+ key,
+ start,
+ stop,
+ )
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) LRem(key string, count int64, value interface{}) *IntCmd {
+ cmd := NewIntCmd("lrem", key, count, value)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) LSet(key string, index int64, value interface{}) *StatusCmd {
+ cmd := NewStatusCmd("lset", key, index, value)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) LTrim(key string, start, stop int64) *StatusCmd {
+ cmd := NewStatusCmd(
+ "ltrim",
+ key,
+ start,
+ stop,
+ )
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) RPop(key string) *StringCmd {
+ cmd := NewStringCmd("rpop", key)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) RPopLPush(source, destination string) *StringCmd {
+ cmd := NewStringCmd("rpoplpush", source, destination)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) RPush(key string, values ...interface{}) *IntCmd {
+ args := make([]interface{}, 2, 2+len(values))
+ args[0] = "rpush"
+ args[1] = key
+ args = appendArgs(args, values)
+ cmd := NewIntCmd(args...)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) RPushX(key string, value interface{}) *IntCmd {
+ cmd := NewIntCmd("rpushx", key, value)
+ c.process(cmd)
+ return cmd
+}
+
+//------------------------------------------------------------------------------
+
+func (c *cmdable) SAdd(key string, members ...interface{}) *IntCmd {
+ args := make([]interface{}, 2, 2+len(members))
+ args[0] = "sadd"
+ args[1] = key
+ args = appendArgs(args, members)
+ cmd := NewIntCmd(args...)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) SCard(key string) *IntCmd {
+ cmd := NewIntCmd("scard", key)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) SDiff(keys ...string) *StringSliceCmd {
+ args := make([]interface{}, 1+len(keys))
+ args[0] = "sdiff"
+ for i, key := range keys {
+ args[1+i] = key
+ }
+ cmd := NewStringSliceCmd(args...)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) SDiffStore(destination string, keys ...string) *IntCmd {
+ args := make([]interface{}, 2+len(keys))
+ args[0] = "sdiffstore"
+ args[1] = destination
+ for i, key := range keys {
+ args[2+i] = key
+ }
+ cmd := NewIntCmd(args...)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) SInter(keys ...string) *StringSliceCmd {
+ args := make([]interface{}, 1+len(keys))
+ args[0] = "sinter"
+ for i, key := range keys {
+ args[1+i] = key
+ }
+ cmd := NewStringSliceCmd(args...)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) SInterStore(destination string, keys ...string) *IntCmd {
+ args := make([]interface{}, 2+len(keys))
+ args[0] = "sinterstore"
+ args[1] = destination
+ for i, key := range keys {
+ args[2+i] = key
+ }
+ cmd := NewIntCmd(args...)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) SIsMember(key string, member interface{}) *BoolCmd {
+ cmd := NewBoolCmd("sismember", key, member)
+ c.process(cmd)
+ return cmd
+}
+
+// Redis `SMEMBERS key` command output as a slice
+func (c *cmdable) SMembers(key string) *StringSliceCmd {
+ cmd := NewStringSliceCmd("smembers", key)
+ c.process(cmd)
+ return cmd
+}
+
+// Redis `SMEMBERS key` command output as a map
+func (c *cmdable) SMembersMap(key string) *StringStructMapCmd {
+ cmd := NewStringStructMapCmd("smembers", key)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) SMove(source, destination string, member interface{}) *BoolCmd {
+ cmd := NewBoolCmd("smove", source, destination, member)
+ c.process(cmd)
+ return cmd
+}
+
+// Redis `SPOP key` command.
+func (c *cmdable) SPop(key string) *StringCmd {
+ cmd := NewStringCmd("spop", key)
+ c.process(cmd)
+ return cmd
+}
+
+// Redis `SPOP key count` command.
+func (c *cmdable) SPopN(key string, count int64) *StringSliceCmd {
+ cmd := NewStringSliceCmd("spop", key, count)
+ c.process(cmd)
+ return cmd
+}
+
+// Redis `SRANDMEMBER key` command.
+func (c *cmdable) SRandMember(key string) *StringCmd {
+ cmd := NewStringCmd("srandmember", key)
+ c.process(cmd)
+ return cmd
+}
+
+// Redis `SRANDMEMBER key count` command.
+func (c *cmdable) SRandMemberN(key string, count int64) *StringSliceCmd {
+ cmd := NewStringSliceCmd("srandmember", key, count)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) SRem(key string, members ...interface{}) *IntCmd {
+ args := make([]interface{}, 2, 2+len(members))
+ args[0] = "srem"
+ args[1] = key
+ args = appendArgs(args, members)
+ cmd := NewIntCmd(args...)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) SUnion(keys ...string) *StringSliceCmd {
+ args := make([]interface{}, 1+len(keys))
+ args[0] = "sunion"
+ for i, key := range keys {
+ args[1+i] = key
+ }
+ cmd := NewStringSliceCmd(args...)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) SUnionStore(destination string, keys ...string) *IntCmd {
+ args := make([]interface{}, 2+len(keys))
+ args[0] = "sunionstore"
+ args[1] = destination
+ for i, key := range keys {
+ args[2+i] = key
+ }
+ cmd := NewIntCmd(args...)
+ c.process(cmd)
+ return cmd
+}
+
+//------------------------------------------------------------------------------
+
+type XAddExt struct {
+ Stream string
+ MaxLen int64 // MAXLEN N
+ MaxLenApprox int64 // MAXLEN ~ N
+ ID string
+ Values map[string]interface{}
+}
+
+func (c *cmdable) XAddExt(opt *XAddExt) *StringCmd {
+ a := make([]interface{}, 0, 6+len(opt.Values)*2)
+ a = append(a, "xadd")
+ a = append(a, opt.Stream)
+ if opt.MaxLen > 0 {
+ a = append(a, "maxlen", opt.MaxLen)
+ } else if opt.MaxLenApprox > 0 {
+ a = append(a, "maxlen", "~", opt.MaxLenApprox)
+ }
+ if opt.ID != "" {
+ a = append(a, opt.ID)
+ } else {
+ a = append(a, "*")
+ }
+ for k, v := range opt.Values {
+ a = append(a, k)
+ a = append(a, v)
+ }
+
+ cmd := NewStringCmd(a...)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) XAdd(stream, id string, values map[string]interface{}) *StringCmd {
+ return c.XAddExt(&XAddExt{
+ Stream: stream,
+ ID: id,
+ Values: values,
+ })
+}
+
+func (c *cmdable) XLen(key string) *IntCmd {
+ cmd := NewIntCmd("xlen", key)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) XRange(stream, start, stop string) *XMessageSliceCmd {
+ cmd := NewXMessageSliceCmd("xrange", stream, start, stop)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) XRangeN(stream, start, stop string, count int64) *XMessageSliceCmd {
+ cmd := NewXMessageSliceCmd("xrange", stream, start, stop, "count", count)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) XRevRange(stream, start, stop string) *XMessageSliceCmd {
+ cmd := NewXMessageSliceCmd("xrevrange", stream, start, stop)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) XRevRangeN(stream, start, stop string, count int64) *XMessageSliceCmd {
+ cmd := NewXMessageSliceCmd("xrevrange", stream, start, stop, "count", count)
+ c.process(cmd)
+ return cmd
+}
+
+type XReadExt struct {
+ Streams []string
+ Count int64
+ Block time.Duration
+}
+
+func (c *cmdable) XReadExt(opt *XReadExt) *XStreamSliceCmd {
+ a := make([]interface{}, 0, 5+len(opt.Streams))
+ a = append(a, "xread")
+ if opt != nil {
+ if opt.Count > 0 {
+ a = append(a, "count")
+ a = append(a, opt.Count)
+ }
+ if opt.Block >= 0 {
+ a = append(a, "block")
+ a = append(a, int64(opt.Block/time.Millisecond))
+ }
+ }
+ a = append(a, "streams")
+ for _, s := range opt.Streams {
+ a = append(a, s)
+ }
+
+ cmd := NewXStreamSliceCmd(a...)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) XRead(streams ...string) *XStreamSliceCmd {
+ return c.XReadExt(&XReadExt{
+ Streams: streams,
+ Block: -1,
+ })
+}
+
+func (c *cmdable) XReadN(count int64, streams ...string) *XStreamSliceCmd {
+ return c.XReadExt(&XReadExt{
+ Streams: streams,
+ Count: count,
+ Block: -1,
+ })
+}
+
+func (c *cmdable) XReadBlock(block time.Duration, streams ...string) *XStreamSliceCmd {
+ return c.XReadExt(&XReadExt{
+ Streams: streams,
+ Block: block,
+ })
+}
+
+//------------------------------------------------------------------------------
+
+// Z represents sorted set member.
+type Z struct {
+ Score float64
+ Member interface{}
+}
+
+// ZStore is used as an arg to ZInterStore and ZUnionStore.
+type ZStore struct {
+ Weights []float64
+ // Can be SUM, MIN or MAX.
+ Aggregate string
+}
+
+func (c *cmdable) zAdd(a []interface{}, n int, members ...Z) *IntCmd {
+ for i, m := range members {
+ a[n+2*i] = m.Score
+ a[n+2*i+1] = m.Member
+ }
+ cmd := NewIntCmd(a...)
+ c.process(cmd)
+ return cmd
+}
+
+// Redis `ZADD key score member [score member ...]` command.
+func (c *cmdable) ZAdd(key string, members ...Z) *IntCmd {
+ const n = 2
+ a := make([]interface{}, n+2*len(members))
+ a[0], a[1] = "zadd", key
+ return c.zAdd(a, n, members...)
+}
+
+// Redis `ZADD key NX score member [score member ...]` command.
+func (c *cmdable) ZAddNX(key string, members ...Z) *IntCmd {
+ const n = 3
+ a := make([]interface{}, n+2*len(members))
+ a[0], a[1], a[2] = "zadd", key, "nx"
+ return c.zAdd(a, n, members...)
+}
+
+// Redis `ZADD key XX score member [score member ...]` command.
+func (c *cmdable) ZAddXX(key string, members ...Z) *IntCmd {
+ const n = 3
+ a := make([]interface{}, n+2*len(members))
+ a[0], a[1], a[2] = "zadd", key, "xx"
+ return c.zAdd(a, n, members...)
+}
+
+// Redis `ZADD key CH score member [score member ...]` command.
+func (c *cmdable) ZAddCh(key string, members ...Z) *IntCmd {
+ const n = 3
+ a := make([]interface{}, n+2*len(members))
+ a[0], a[1], a[2] = "zadd", key, "ch"
+ return c.zAdd(a, n, members...)
+}
+
+// Redis `ZADD key NX CH score member [score member ...]` command.
+func (c *cmdable) ZAddNXCh(key string, members ...Z) *IntCmd {
+ const n = 4
+ a := make([]interface{}, n+2*len(members))
+ a[0], a[1], a[2], a[3] = "zadd", key, "nx", "ch"
+ return c.zAdd(a, n, members...)
+}
+
+// Redis `ZADD key XX CH score member [score member ...]` command.
+func (c *cmdable) ZAddXXCh(key string, members ...Z) *IntCmd {
+ const n = 4
+ a := make([]interface{}, n+2*len(members))
+ a[0], a[1], a[2], a[3] = "zadd", key, "xx", "ch"
+ return c.zAdd(a, n, members...)
+}
+
+func (c *cmdable) zIncr(a []interface{}, n int, members ...Z) *FloatCmd {
+ for i, m := range members {
+ a[n+2*i] = m.Score
+ a[n+2*i+1] = m.Member
+ }
+ cmd := NewFloatCmd(a...)
+ c.process(cmd)
+ return cmd
+}
+
+// Redis `ZADD key INCR score member` command.
+func (c *cmdable) ZIncr(key string, member Z) *FloatCmd {
+ const n = 3
+ a := make([]interface{}, n+2)
+ a[0], a[1], a[2] = "zadd", key, "incr"
+ return c.zIncr(a, n, member)
+}
+
+// Redis `ZADD key NX INCR score member` command.
+func (c *cmdable) ZIncrNX(key string, member Z) *FloatCmd {
+ const n = 4
+ a := make([]interface{}, n+2)
+ a[0], a[1], a[2], a[3] = "zadd", key, "incr", "nx"
+ return c.zIncr(a, n, member)
+}
+
+// Redis `ZADD key XX INCR score member` command.
+func (c *cmdable) ZIncrXX(key string, member Z) *FloatCmd {
+ const n = 4
+ a := make([]interface{}, n+2)
+ a[0], a[1], a[2], a[3] = "zadd", key, "incr", "xx"
+ return c.zIncr(a, n, member)
+}
+
+func (c *cmdable) ZCard(key string) *IntCmd {
+ cmd := NewIntCmd("zcard", key)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) ZCount(key, min, max string) *IntCmd {
+ cmd := NewIntCmd("zcount", key, min, max)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) ZLexCount(key, min, max string) *IntCmd {
+ cmd := NewIntCmd("zlexcount", key, min, max)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) ZIncrBy(key string, increment float64, member string) *FloatCmd {
+ cmd := NewFloatCmd("zincrby", key, increment, member)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) ZInterStore(destination string, store ZStore, keys ...string) *IntCmd {
+ args := make([]interface{}, 3+len(keys))
+ args[0] = "zinterstore"
+ args[1] = destination
+ args[2] = len(keys)
+ for i, key := range keys {
+ args[3+i] = key
+ }
+ if len(store.Weights) > 0 {
+ args = append(args, "weights")
+ for _, weight := range store.Weights {
+ args = append(args, weight)
+ }
+ }
+ if store.Aggregate != "" {
+ args = append(args, "aggregate", store.Aggregate)
+ }
+ cmd := NewIntCmd(args...)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) zRange(key string, start, stop int64, withScores bool) *StringSliceCmd {
+ args := []interface{}{
+ "zrange",
+ key,
+ start,
+ stop,
+ }
+ if withScores {
+ args = append(args, "withscores")
+ }
+ cmd := NewStringSliceCmd(args...)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) ZRange(key string, start, stop int64) *StringSliceCmd {
+ return c.zRange(key, start, stop, false)
+}
+
+func (c *cmdable) ZRangeWithScores(key string, start, stop int64) *ZSliceCmd {
+ cmd := NewZSliceCmd("zrange", key, start, stop, "withscores")
+ c.process(cmd)
+ return cmd
+}
+
+type ZRangeBy struct {
+ Min, Max string
+ Offset, Count int64
+}
+
+func (c *cmdable) zRangeBy(zcmd, key string, opt ZRangeBy, withScores bool) *StringSliceCmd {
+ args := []interface{}{zcmd, key, opt.Min, opt.Max}
+ if withScores {
+ args = append(args, "withscores")
+ }
+ if opt.Offset != 0 || opt.Count != 0 {
+ args = append(
+ args,
+ "limit",
+ opt.Offset,
+ opt.Count,
+ )
+ }
+ cmd := NewStringSliceCmd(args...)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) ZRangeByScore(key string, opt ZRangeBy) *StringSliceCmd {
+ return c.zRangeBy("zrangebyscore", key, opt, false)
+}
+
+func (c *cmdable) ZRangeByLex(key string, opt ZRangeBy) *StringSliceCmd {
+ return c.zRangeBy("zrangebylex", key, opt, false)
+}
+
+func (c *cmdable) ZRangeByScoreWithScores(key string, opt ZRangeBy) *ZSliceCmd {
+ args := []interface{}{"zrangebyscore", key, opt.Min, opt.Max, "withscores"}
+ if opt.Offset != 0 || opt.Count != 0 {
+ args = append(
+ args,
+ "limit",
+ opt.Offset,
+ opt.Count,
+ )
+ }
+ cmd := NewZSliceCmd(args...)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) ZRank(key, member string) *IntCmd {
+ cmd := NewIntCmd("zrank", key, member)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) ZRem(key string, members ...interface{}) *IntCmd {
+ args := make([]interface{}, 2, 2+len(members))
+ args[0] = "zrem"
+ args[1] = key
+ args = appendArgs(args, members)
+ cmd := NewIntCmd(args...)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) ZRemRangeByRank(key string, start, stop int64) *IntCmd {
+ cmd := NewIntCmd(
+ "zremrangebyrank",
+ key,
+ start,
+ stop,
+ )
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) ZRemRangeByScore(key, min, max string) *IntCmd {
+ cmd := NewIntCmd("zremrangebyscore", key, min, max)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) ZRemRangeByLex(key, min, max string) *IntCmd {
+ cmd := NewIntCmd("zremrangebylex", key, min, max)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) ZRevRange(key string, start, stop int64) *StringSliceCmd {
+ cmd := NewStringSliceCmd("zrevrange", key, start, stop)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) ZRevRangeWithScores(key string, start, stop int64) *ZSliceCmd {
+ cmd := NewZSliceCmd("zrevrange", key, start, stop, "withscores")
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) zRevRangeBy(zcmd, key string, opt ZRangeBy) *StringSliceCmd {
+ args := []interface{}{zcmd, key, opt.Max, opt.Min}
+ if opt.Offset != 0 || opt.Count != 0 {
+ args = append(
+ args,
+ "limit",
+ opt.Offset,
+ opt.Count,
+ )
+ }
+ cmd := NewStringSliceCmd(args...)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) ZRevRangeByScore(key string, opt ZRangeBy) *StringSliceCmd {
+ return c.zRevRangeBy("zrevrangebyscore", key, opt)
+}
+
+func (c *cmdable) ZRevRangeByLex(key string, opt ZRangeBy) *StringSliceCmd {
+ return c.zRevRangeBy("zrevrangebylex", key, opt)
+}
+
+func (c *cmdable) ZRevRangeByScoreWithScores(key string, opt ZRangeBy) *ZSliceCmd {
+ args := []interface{}{"zrevrangebyscore", key, opt.Max, opt.Min, "withscores"}
+ if opt.Offset != 0 || opt.Count != 0 {
+ args = append(
+ args,
+ "limit",
+ opt.Offset,
+ opt.Count,
+ )
+ }
+ cmd := NewZSliceCmd(args...)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) ZRevRank(key, member string) *IntCmd {
+ cmd := NewIntCmd("zrevrank", key, member)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) ZScore(key, member string) *FloatCmd {
+ cmd := NewFloatCmd("zscore", key, member)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) ZUnionStore(dest string, store ZStore, keys ...string) *IntCmd {
+ args := make([]interface{}, 3+len(keys))
+ args[0] = "zunionstore"
+ args[1] = dest
+ args[2] = len(keys)
+ for i, key := range keys {
+ args[3+i] = key
+ }
+ if len(store.Weights) > 0 {
+ args = append(args, "weights")
+ for _, weight := range store.Weights {
+ args = append(args, weight)
+ }
+ }
+ if store.Aggregate != "" {
+ args = append(args, "aggregate", store.Aggregate)
+ }
+ cmd := NewIntCmd(args...)
+ c.process(cmd)
+ return cmd
+}
+
+//------------------------------------------------------------------------------
+
+func (c *cmdable) PFAdd(key string, els ...interface{}) *IntCmd {
+ args := make([]interface{}, 2, 2+len(els))
+ args[0] = "pfadd"
+ args[1] = key
+ args = appendArgs(args, els)
+ cmd := NewIntCmd(args...)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) PFCount(keys ...string) *IntCmd {
+ args := make([]interface{}, 1+len(keys))
+ args[0] = "pfcount"
+ for i, key := range keys {
+ args[1+i] = key
+ }
+ cmd := NewIntCmd(args...)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) PFMerge(dest string, keys ...string) *StatusCmd {
+ args := make([]interface{}, 2+len(keys))
+ args[0] = "pfmerge"
+ args[1] = dest
+ for i, key := range keys {
+ args[2+i] = key
+ }
+ cmd := NewStatusCmd(args...)
+ c.process(cmd)
+ return cmd
+}
+
+//------------------------------------------------------------------------------
+
+func (c *cmdable) BgRewriteAOF() *StatusCmd {
+ cmd := NewStatusCmd("bgrewriteaof")
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) BgSave() *StatusCmd {
+ cmd := NewStatusCmd("bgsave")
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) ClientKill(ipPort string) *StatusCmd {
+ cmd := NewStatusCmd("client", "kill", ipPort)
+ c.process(cmd)
+ return cmd
+}
+
+// ClientKillByFilter is new style synx, while the ClientKill is old
+// CLIENT KILL <option> [value] ... <option> [value]
+func (c *cmdable) ClientKillByFilter(keys ...string) *IntCmd {
+ args := make([]interface{}, 2+len(keys))
+ args[0] = "client"
+ args[1] = "kill"
+ for i, key := range keys {
+ args[2+i] = key
+ }
+ cmd := NewIntCmd(args...)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) ClientList() *StringCmd {
+ cmd := NewStringCmd("client", "list")
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) ClientPause(dur time.Duration) *BoolCmd {
+ cmd := NewBoolCmd("client", "pause", formatMs(dur))
+ c.process(cmd)
+ return cmd
+}
+
+// ClientSetName assigns a name to the connection.
+func (c *statefulCmdable) ClientSetName(name string) *BoolCmd {
+ cmd := NewBoolCmd("client", "setname", name)
+ c.process(cmd)
+ return cmd
+}
+
+// ClientGetName returns the name of the connection.
+func (c *cmdable) ClientGetName() *StringCmd {
+ cmd := NewStringCmd("client", "getname")
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) ConfigGet(parameter string) *SliceCmd {
+ cmd := NewSliceCmd("config", "get", parameter)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) ConfigResetStat() *StatusCmd {
+ cmd := NewStatusCmd("config", "resetstat")
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) ConfigSet(parameter, value string) *StatusCmd {
+ cmd := NewStatusCmd("config", "set", parameter, value)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) ConfigRewrite() *StatusCmd {
+ cmd := NewStatusCmd("config", "rewrite")
+ c.process(cmd)
+ return cmd
+}
+
+// Deperecated. Use DBSize instead.
+func (c *cmdable) DbSize() *IntCmd {
+ return c.DBSize()
+}
+
+func (c *cmdable) DBSize() *IntCmd {
+ cmd := NewIntCmd("dbsize")
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) FlushAll() *StatusCmd {
+ cmd := NewStatusCmd("flushall")
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) FlushAllAsync() *StatusCmd {
+ cmd := NewStatusCmd("flushall", "async")
+ c.process(cmd)
+ return cmd
+}
+
+// Deprecated. Use FlushDB instead.
+func (c *cmdable) FlushDb() *StatusCmd {
+ return c.FlushDB()
+}
+
+func (c *cmdable) FlushDB() *StatusCmd {
+ cmd := NewStatusCmd("flushdb")
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) FlushDBAsync() *StatusCmd {
+ cmd := NewStatusCmd("flushdb", "async")
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) Info(section ...string) *StringCmd {
+ args := []interface{}{"info"}
+ if len(section) > 0 {
+ args = append(args, section[0])
+ }
+ cmd := NewStringCmd(args...)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) LastSave() *IntCmd {
+ cmd := NewIntCmd("lastsave")
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) Save() *StatusCmd {
+ cmd := NewStatusCmd("save")
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) shutdown(modifier string) *StatusCmd {
+ var args []interface{}
+ if modifier == "" {
+ args = []interface{}{"shutdown"}
+ } else {
+ args = []interface{}{"shutdown", modifier}
+ }
+ cmd := NewStatusCmd(args...)
+ c.process(cmd)
+ if err := cmd.Err(); err != nil {
+ if err == io.EOF {
+ // Server quit as expected.
+ cmd.err = nil
+ }
+ } else {
+ // Server did not quit. String reply contains the reason.
+ cmd.err = errors.New(cmd.val)
+ cmd.val = ""
+ }
+ return cmd
+}
+
+func (c *cmdable) Shutdown() *StatusCmd {
+ return c.shutdown("")
+}
+
+func (c *cmdable) ShutdownSave() *StatusCmd {
+ return c.shutdown("save")
+}
+
+func (c *cmdable) ShutdownNoSave() *StatusCmd {
+ return c.shutdown("nosave")
+}
+
+func (c *cmdable) SlaveOf(host, port string) *StatusCmd {
+ cmd := NewStatusCmd("slaveof", host, port)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) SlowLog() {
+ panic("not implemented")
+}
+
+func (c *cmdable) Sync() {
+ panic("not implemented")
+}
+
+func (c *cmdable) Time() *TimeCmd {
+ cmd := NewTimeCmd("time")
+ c.process(cmd)
+ return cmd
+}
+
+//------------------------------------------------------------------------------
+
+func (c *cmdable) Eval(script string, keys []string, args ...interface{}) *Cmd {
+ cmdArgs := make([]interface{}, 3+len(keys), 3+len(keys)+len(args))
+ cmdArgs[0] = "eval"
+ cmdArgs[1] = script
+ cmdArgs[2] = len(keys)
+ for i, key := range keys {
+ cmdArgs[3+i] = key
+ }
+ cmdArgs = appendArgs(cmdArgs, args)
+ cmd := NewCmd(cmdArgs...)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) EvalSha(sha1 string, keys []string, args ...interface{}) *Cmd {
+ cmdArgs := make([]interface{}, 3+len(keys), 3+len(keys)+len(args))
+ cmdArgs[0] = "evalsha"
+ cmdArgs[1] = sha1
+ cmdArgs[2] = len(keys)
+ for i, key := range keys {
+ cmdArgs[3+i] = key
+ }
+ cmdArgs = appendArgs(cmdArgs, args)
+ cmd := NewCmd(cmdArgs...)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) ScriptExists(hashes ...string) *BoolSliceCmd {
+ args := make([]interface{}, 2+len(hashes))
+ args[0] = "script"
+ args[1] = "exists"
+ for i, hash := range hashes {
+ args[2+i] = hash
+ }
+ cmd := NewBoolSliceCmd(args...)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) ScriptFlush() *StatusCmd {
+ cmd := NewStatusCmd("script", "flush")
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) ScriptKill() *StatusCmd {
+ cmd := NewStatusCmd("script", "kill")
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) ScriptLoad(script string) *StringCmd {
+ cmd := NewStringCmd("script", "load", script)
+ c.process(cmd)
+ return cmd
+}
+
+//------------------------------------------------------------------------------
+
+func (c *cmdable) DebugObject(key string) *StringCmd {
+ cmd := NewStringCmd("debug", "object", key)
+ c.process(cmd)
+ return cmd
+}
+
+//------------------------------------------------------------------------------
+
+// Publish posts the message to the channel.
+func (c *cmdable) Publish(channel string, message interface{}) *IntCmd {
+ cmd := NewIntCmd("publish", channel, message)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) PubSubChannels(pattern string) *StringSliceCmd {
+ args := []interface{}{"pubsub", "channels"}
+ if pattern != "*" {
+ args = append(args, pattern)
+ }
+ cmd := NewStringSliceCmd(args...)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) PubSubNumSub(channels ...string) *StringIntMapCmd {
+ args := make([]interface{}, 2+len(channels))
+ args[0] = "pubsub"
+ args[1] = "numsub"
+ for i, channel := range channels {
+ args[2+i] = channel
+ }
+ cmd := NewStringIntMapCmd(args...)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) PubSubNumPat() *IntCmd {
+ cmd := NewIntCmd("pubsub", "numpat")
+ c.process(cmd)
+ return cmd
+}
+
+//------------------------------------------------------------------------------
+
+func (c *cmdable) ClusterSlots() *ClusterSlotsCmd {
+ cmd := NewClusterSlotsCmd("cluster", "slots")
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) ClusterNodes() *StringCmd {
+ cmd := NewStringCmd("cluster", "nodes")
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) ClusterMeet(host, port string) *StatusCmd {
+ cmd := NewStatusCmd("cluster", "meet", host, port)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) ClusterForget(nodeID string) *StatusCmd {
+ cmd := NewStatusCmd("cluster", "forget", nodeID)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) ClusterReplicate(nodeID string) *StatusCmd {
+ cmd := NewStatusCmd("cluster", "replicate", nodeID)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) ClusterResetSoft() *StatusCmd {
+ cmd := NewStatusCmd("cluster", "reset", "soft")
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) ClusterResetHard() *StatusCmd {
+ cmd := NewStatusCmd("cluster", "reset", "hard")
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) ClusterInfo() *StringCmd {
+ cmd := NewStringCmd("cluster", "info")
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) ClusterKeySlot(key string) *IntCmd {
+ cmd := NewIntCmd("cluster", "keyslot", key)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) ClusterCountFailureReports(nodeID string) *IntCmd {
+ cmd := NewIntCmd("cluster", "count-failure-reports", nodeID)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) ClusterCountKeysInSlot(slot int) *IntCmd {
+ cmd := NewIntCmd("cluster", "countkeysinslot", slot)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) ClusterDelSlots(slots ...int) *StatusCmd {
+ args := make([]interface{}, 2+len(slots))
+ args[0] = "cluster"
+ args[1] = "delslots"
+ for i, slot := range slots {
+ args[2+i] = slot
+ }
+ cmd := NewStatusCmd(args...)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) ClusterDelSlotsRange(min, max int) *StatusCmd {
+ size := max - min + 1
+ slots := make([]int, size)
+ for i := 0; i < size; i++ {
+ slots[i] = min + i
+ }
+ return c.ClusterDelSlots(slots...)
+}
+
+func (c *cmdable) ClusterSaveConfig() *StatusCmd {
+ cmd := NewStatusCmd("cluster", "saveconfig")
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) ClusterSlaves(nodeID string) *StringSliceCmd {
+ cmd := NewStringSliceCmd("cluster", "slaves", nodeID)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) ReadOnly() *StatusCmd {
+ cmd := NewStatusCmd("readonly")
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) ReadWrite() *StatusCmd {
+ cmd := NewStatusCmd("readwrite")
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) ClusterFailover() *StatusCmd {
+ cmd := NewStatusCmd("cluster", "failover")
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) ClusterAddSlots(slots ...int) *StatusCmd {
+ args := make([]interface{}, 2+len(slots))
+ args[0] = "cluster"
+ args[1] = "addslots"
+ for i, num := range slots {
+ args[2+i] = num
+ }
+ cmd := NewStatusCmd(args...)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) ClusterAddSlotsRange(min, max int) *StatusCmd {
+ size := max - min + 1
+ slots := make([]int, size)
+ for i := 0; i < size; i++ {
+ slots[i] = min + i
+ }
+ return c.ClusterAddSlots(slots...)
+}
+
+//------------------------------------------------------------------------------
+
+func (c *cmdable) GeoAdd(key string, geoLocation ...*GeoLocation) *IntCmd {
+ args := make([]interface{}, 2+3*len(geoLocation))
+ args[0] = "geoadd"
+ args[1] = key
+ for i, eachLoc := range geoLocation {
+ args[2+3*i] = eachLoc.Longitude
+ args[2+3*i+1] = eachLoc.Latitude
+ args[2+3*i+2] = eachLoc.Name
+ }
+ cmd := NewIntCmd(args...)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) GeoRadius(key string, longitude, latitude float64, query *GeoRadiusQuery) *GeoLocationCmd {
+ cmd := NewGeoLocationCmd(query, "georadius", key, longitude, latitude)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) GeoRadiusRO(key string, longitude, latitude float64, query *GeoRadiusQuery) *GeoLocationCmd {
+ cmd := NewGeoLocationCmd(query, "georadius_ro", key, longitude, latitude)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) GeoRadiusByMember(key, member string, query *GeoRadiusQuery) *GeoLocationCmd {
+ cmd := NewGeoLocationCmd(query, "georadiusbymember", key, member)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) GeoRadiusByMemberRO(key, member string, query *GeoRadiusQuery) *GeoLocationCmd {
+ cmd := NewGeoLocationCmd(query, "georadiusbymember_ro", key, member)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) GeoDist(key string, member1, member2, unit string) *FloatCmd {
+ if unit == "" {
+ unit = "km"
+ }
+ cmd := NewFloatCmd("geodist", key, member1, member2, unit)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) GeoHash(key string, members ...string) *StringSliceCmd {
+ args := make([]interface{}, 2+len(members))
+ args[0] = "geohash"
+ args[1] = key
+ for i, member := range members {
+ args[2+i] = member
+ }
+ cmd := NewStringSliceCmd(args...)
+ c.process(cmd)
+ return cmd
+}
+
+func (c *cmdable) GeoPos(key string, members ...string) *GeoPosCmd {
+ args := make([]interface{}, 2+len(members))
+ args[0] = "geopos"
+ args[1] = key
+ for i, member := range members {
+ args[2+i] = member
+ }
+ cmd := NewGeoPosCmd(args...)
+ c.process(cmd)
+ return cmd
+}
+
+//------------------------------------------------------------------------------
+
+func (c *cmdable) MemoryUsage(key string, samples ...int) *IntCmd {
+ args := []interface{}{"memory", "usage", key}
+ if len(samples) > 0 {
+ if len(samples) != 1 {
+ panic("MemoryUsage expects single sample count")
+ }
+ args = append(args, "SAMPLES", samples[0])
+ }
+ cmd := NewIntCmd(args...)
+ c.process(cmd)
+ return cmd
+}
diff --git a/src/dma/vendor/github.com/go-redis/redis/doc.go b/src/dma/vendor/github.com/go-redis/redis/doc.go
new file mode 100644
index 00000000..55262533
--- /dev/null
+++ b/src/dma/vendor/github.com/go-redis/redis/doc.go
@@ -0,0 +1,4 @@
+/*
+Package redis implements a Redis client.
+*/
+package redis
diff --git a/src/dma/vendor/github.com/go-redis/redis/internal/consistenthash/consistenthash.go b/src/dma/vendor/github.com/go-redis/redis/internal/consistenthash/consistenthash.go
new file mode 100644
index 00000000..a9c56f07
--- /dev/null
+++ b/src/dma/vendor/github.com/go-redis/redis/internal/consistenthash/consistenthash.go
@@ -0,0 +1,81 @@
+/*
+Copyright 2013 Google Inc.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+// Package consistenthash provides an implementation of a ring hash.
+package consistenthash
+
+import (
+ "hash/crc32"
+ "sort"
+ "strconv"
+)
+
+type Hash func(data []byte) uint32
+
+type Map struct {
+ hash Hash
+ replicas int
+ keys []int // Sorted
+ hashMap map[int]string
+}
+
+func New(replicas int, fn Hash) *Map {
+ m := &Map{
+ replicas: replicas,
+ hash: fn,
+ hashMap: make(map[int]string),
+ }
+ if m.hash == nil {
+ m.hash = crc32.ChecksumIEEE
+ }
+ return m
+}
+
+// Returns true if there are no items available.
+func (m *Map) IsEmpty() bool {
+ return len(m.keys) == 0
+}
+
+// Adds some keys to the hash.
+func (m *Map) Add(keys ...string) {
+ for _, key := range keys {
+ for i := 0; i < m.replicas; i++ {
+ hash := int(m.hash([]byte(strconv.Itoa(i) + key)))
+ m.keys = append(m.keys, hash)
+ m.hashMap[hash] = key
+ }
+ }
+ sort.Ints(m.keys)
+}
+
+// Gets the closest item in the hash to the provided key.
+func (m *Map) Get(key string) string {
+ if m.IsEmpty() {
+ return ""
+ }
+
+ hash := int(m.hash([]byte(key)))
+
+ // Binary search for appropriate replica.
+ idx := sort.Search(len(m.keys), func(i int) bool { return m.keys[i] >= hash })
+
+ // Means we have cycled back to the first replica.
+ if idx == len(m.keys) {
+ idx = 0
+ }
+
+ return m.hashMap[m.keys[idx]]
+}
diff --git a/src/dma/vendor/github.com/go-redis/redis/internal/error.go b/src/dma/vendor/github.com/go-redis/redis/internal/error.go
new file mode 100644
index 00000000..e0ff8632
--- /dev/null
+++ b/src/dma/vendor/github.com/go-redis/redis/internal/error.go
@@ -0,0 +1,83 @@
+package internal
+
+import (
+ "io"
+ "net"
+ "strings"
+
+ "github.com/go-redis/redis/internal/proto"
+)
+
+func IsRetryableError(err error, retryNetError bool) bool {
+ if IsNetworkError(err) {
+ return retryNetError
+ }
+ s := err.Error()
+ if s == "ERR max number of clients reached" {
+ return true
+ }
+ if strings.HasPrefix(s, "LOADING ") {
+ return true
+ }
+ if strings.HasPrefix(s, "READONLY ") {
+ return true
+ }
+ if strings.HasPrefix(s, "CLUSTERDOWN ") {
+ return true
+ }
+ return false
+}
+
+func IsRedisError(err error) bool {
+ _, ok := err.(proto.RedisError)
+ return ok
+}
+
+func IsNetworkError(err error) bool {
+ if err == io.EOF {
+ return true
+ }
+ _, ok := err.(net.Error)
+ return ok
+}
+
+func IsBadConn(err error, allowTimeout bool) bool {
+ if err == nil {
+ return false
+ }
+ if IsRedisError(err) {
+ return strings.HasPrefix(err.Error(), "READONLY ")
+ }
+ if allowTimeout {
+ if netErr, ok := err.(net.Error); ok && netErr.Timeout() {
+ return false
+ }
+ }
+ return true
+}
+
+func IsMovedError(err error) (moved bool, ask bool, addr string) {
+ if !IsRedisError(err) {
+ return
+ }
+
+ s := err.Error()
+ if strings.HasPrefix(s, "MOVED ") {
+ moved = true
+ } else if strings.HasPrefix(s, "ASK ") {
+ ask = true
+ } else {
+ return
+ }
+
+ ind := strings.LastIndex(s, " ")
+ if ind == -1 {
+ return false, false, ""
+ }
+ addr = s[ind+1:]
+ return
+}
+
+func IsLoadingError(err error) bool {
+ return strings.HasPrefix(err.Error(), "LOADING ")
+}
diff --git a/src/dma/vendor/github.com/go-redis/redis/internal/hashtag/hashtag.go b/src/dma/vendor/github.com/go-redis/redis/internal/hashtag/hashtag.go
new file mode 100644
index 00000000..22f5b398
--- /dev/null
+++ b/src/dma/vendor/github.com/go-redis/redis/internal/hashtag/hashtag.go
@@ -0,0 +1,77 @@
+package hashtag
+
+import (
+ "math/rand"
+ "strings"
+)
+
+const slotNumber = 16384
+
+// CRC16 implementation according to CCITT standards.
+// Copyright 2001-2010 Georges Menie (www.menie.org)
+// Copyright 2013 The Go Authors. All rights reserved.
+// http://redis.io/topics/cluster-spec#appendix-a-crc16-reference-implementation-in-ansi-c
+var crc16tab = [256]uint16{
+ 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
+ 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,
+ 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6,
+ 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de,
+ 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485,
+ 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d,
+ 0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4,
+ 0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc,
+ 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823,
+ 0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b,
+ 0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12,
+ 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a,
+ 0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41,
+ 0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49,
+ 0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70,
+ 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78,
+ 0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f,
+ 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067,
+ 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e,
+ 0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256,
+ 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d,
+ 0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
+ 0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c,
+ 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634,
+ 0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab,
+ 0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3,
+ 0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a,
+ 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92,
+ 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9,
+ 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1,
+ 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8,
+ 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0,
+}
+
+func Key(key string) string {
+ if s := strings.IndexByte(key, '{'); s > -1 {
+ if e := strings.IndexByte(key[s+1:], '}'); e > 0 {
+ return key[s+1 : s+e+1]
+ }
+ }
+ return key
+}
+
+func RandomSlot() int {
+ return rand.Intn(slotNumber)
+}
+
+// hashSlot returns a consistent slot number between 0 and 16383
+// for any given string key.
+func Slot(key string) int {
+ if key == "" {
+ return RandomSlot()
+ }
+ key = Key(key)
+ return int(crc16sum(key)) % slotNumber
+}
+
+func crc16sum(key string) (crc uint16) {
+ for i := 0; i < len(key); i++ {
+ crc = (crc << 8) ^ crc16tab[(byte(crc>>8)^key[i])&0x00ff]
+ }
+ return
+}
diff --git a/src/dma/vendor/github.com/go-redis/redis/internal/internal.go b/src/dma/vendor/github.com/go-redis/redis/internal/internal.go
new file mode 100644
index 00000000..ad3fc3c9
--- /dev/null
+++ b/src/dma/vendor/github.com/go-redis/redis/internal/internal.go
@@ -0,0 +1,24 @@
+package internal
+
+import (
+ "math/rand"
+ "time"
+)
+
+// Retry backoff with jitter sleep to prevent overloaded conditions during intervals
+// https://www.awsarchitectureblog.com/2015/03/backoff.html
+func RetryBackoff(retry int, minBackoff, maxBackoff time.Duration) time.Duration {
+ if retry < 0 {
+ retry = 0
+ }
+
+ backoff := minBackoff << uint(retry)
+ if backoff > maxBackoff || backoff < minBackoff {
+ backoff = maxBackoff
+ }
+
+ if backoff == 0 {
+ return 0
+ }
+ return time.Duration(rand.Int63n(int64(backoff)))
+}
diff --git a/src/dma/vendor/github.com/go-redis/redis/internal/log.go b/src/dma/vendor/github.com/go-redis/redis/internal/log.go
new file mode 100644
index 00000000..fd14222e
--- /dev/null
+++ b/src/dma/vendor/github.com/go-redis/redis/internal/log.go
@@ -0,0 +1,15 @@
+package internal
+
+import (
+ "fmt"
+ "log"
+)
+
+var Logger *log.Logger
+
+func Logf(s string, args ...interface{}) {
+ if Logger == nil {
+ return
+ }
+ Logger.Output(2, fmt.Sprintf(s, args...))
+}
diff --git a/src/dma/vendor/github.com/go-redis/redis/internal/once.go b/src/dma/vendor/github.com/go-redis/redis/internal/once.go
new file mode 100644
index 00000000..64f46272
--- /dev/null
+++ b/src/dma/vendor/github.com/go-redis/redis/internal/once.go
@@ -0,0 +1,60 @@
+/*
+Copyright 2014 The Camlistore Authors
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package internal
+
+import (
+ "sync"
+ "sync/atomic"
+)
+
+// A Once will perform a successful action exactly once.
+//
+// Unlike a sync.Once, this Once's func returns an error
+// and is re-armed on failure.
+type Once struct {
+ m sync.Mutex
+ done uint32
+}
+
+// Do calls the function f if and only if Do has not been invoked
+// without error for this instance of Once. In other words, given
+// var once Once
+// if once.Do(f) is called multiple times, only the first call will
+// invoke f, even if f has a different value in each invocation unless
+// f returns an error. A new instance of Once is required for each
+// function to execute.
+//
+// Do is intended for initialization that must be run exactly once. Since f
+// is niladic, it may be necessary to use a function literal to capture the
+// arguments to a function to be invoked by Do:
+// err := config.once.Do(func() error { return config.init(filename) })
+func (o *Once) Do(f func() error) error {
+ if atomic.LoadUint32(&o.done) == 1 {
+ return nil
+ }
+ // Slow-path.
+ o.m.Lock()
+ defer o.m.Unlock()
+ var err error
+ if o.done == 0 {
+ err = f()
+ if err == nil {
+ atomic.StoreUint32(&o.done, 1)
+ }
+ }
+ return err
+}
diff --git a/src/dma/vendor/github.com/go-redis/redis/internal/pool/conn.go b/src/dma/vendor/github.com/go-redis/redis/internal/pool/conn.go
new file mode 100644
index 00000000..acaf3665
--- /dev/null
+++ b/src/dma/vendor/github.com/go-redis/redis/internal/pool/conn.go
@@ -0,0 +1,80 @@
+package pool
+
+import (
+ "net"
+ "sync/atomic"
+ "time"
+
+ "github.com/go-redis/redis/internal/proto"
+)
+
+var noDeadline = time.Time{}
+
+type Conn struct {
+ netConn net.Conn
+
+ Rd *proto.Reader
+ Wb *proto.WriteBuffer
+
+ Inited bool
+ usedAt atomic.Value
+}
+
+func NewConn(netConn net.Conn) *Conn {
+ cn := &Conn{
+ netConn: netConn,
+ Wb: proto.NewWriteBuffer(),
+ }
+ cn.Rd = proto.NewReader(cn.netConn)
+ cn.SetUsedAt(time.Now())
+ return cn
+}
+
+func (cn *Conn) UsedAt() time.Time {
+ return cn.usedAt.Load().(time.Time)
+}
+
+func (cn *Conn) SetUsedAt(tm time.Time) {
+ cn.usedAt.Store(tm)
+}
+
+func (cn *Conn) SetNetConn(netConn net.Conn) {
+ cn.netConn = netConn
+ cn.Rd.Reset(netConn)
+}
+
+func (cn *Conn) IsStale(timeout time.Duration) bool {
+ return timeout > 0 && time.Since(cn.UsedAt()) > timeout
+}
+
+func (cn *Conn) SetReadTimeout(timeout time.Duration) {
+ now := time.Now()
+ cn.SetUsedAt(now)
+ if timeout > 0 {
+ cn.netConn.SetReadDeadline(now.Add(timeout))
+ } else {
+ cn.netConn.SetReadDeadline(noDeadline)
+ }
+}
+
+func (cn *Conn) SetWriteTimeout(timeout time.Duration) {
+ now := time.Now()
+ cn.SetUsedAt(now)
+ if timeout > 0 {
+ cn.netConn.SetWriteDeadline(now.Add(timeout))
+ } else {
+ cn.netConn.SetWriteDeadline(noDeadline)
+ }
+}
+
+func (cn *Conn) Write(b []byte) (int, error) {
+ return cn.netConn.Write(b)
+}
+
+func (cn *Conn) RemoteAddr() net.Addr {
+ return cn.netConn.RemoteAddr()
+}
+
+func (cn *Conn) Close() error {
+ return cn.netConn.Close()
+}
diff --git a/src/dma/vendor/github.com/go-redis/redis/internal/pool/pool.go b/src/dma/vendor/github.com/go-redis/redis/internal/pool/pool.go
new file mode 100644
index 00000000..cab66904
--- /dev/null
+++ b/src/dma/vendor/github.com/go-redis/redis/internal/pool/pool.go
@@ -0,0 +1,416 @@
+package pool
+
+import (
+ "errors"
+ "net"
+ "sync"
+ "sync/atomic"
+ "time"
+
+ "github.com/go-redis/redis/internal"
+)
+
+var ErrClosed = errors.New("redis: client is closed")
+var ErrPoolTimeout = errors.New("redis: connection pool timeout")
+
+var timers = sync.Pool{
+ New: func() interface{} {
+ t := time.NewTimer(time.Hour)
+ t.Stop()
+ return t
+ },
+}
+
+// Stats contains pool state information and accumulated stats.
+type Stats struct {
+ Hits uint32 // number of times free connection was found in the pool
+ Misses uint32 // number of times free connection was NOT found in the pool
+ Timeouts uint32 // number of times a wait timeout occurred
+
+ TotalConns uint32 // number of total connections in the pool
+ FreeConns uint32 // deprecated - use IdleConns
+ IdleConns uint32 // number of idle connections in the pool
+ StaleConns uint32 // number of stale connections removed from the pool
+}
+
+type Pooler interface {
+ NewConn() (*Conn, error)
+ CloseConn(*Conn) error
+
+ Get() (*Conn, error)
+ Put(*Conn)
+ Remove(*Conn)
+
+ Len() int
+ IdleLen() int
+ Stats() *Stats
+
+ Close() error
+}
+
+type Options struct {
+ Dialer func() (net.Conn, error)
+ OnClose func(*Conn) error
+
+ PoolSize int
+ PoolTimeout time.Duration
+ IdleTimeout time.Duration
+ IdleCheckFrequency time.Duration
+}
+
+type ConnPool struct {
+ opt *Options
+
+ dialErrorsNum uint32 // atomic
+
+ lastDialError error
+ lastDialErrorMu sync.RWMutex
+
+ queue chan struct{}
+
+ connsMu sync.Mutex
+ conns []*Conn
+
+ idleConnsMu sync.RWMutex
+ idleConns []*Conn
+
+ stats Stats
+
+ _closed uint32 // atomic
+}
+
+var _ Pooler = (*ConnPool)(nil)
+
+func NewConnPool(opt *Options) *ConnPool {
+ p := &ConnPool{
+ opt: opt,
+
+ queue: make(chan struct{}, opt.PoolSize),
+ conns: make([]*Conn, 0, opt.PoolSize),
+ idleConns: make([]*Conn, 0, opt.PoolSize),
+ }
+
+ if opt.IdleTimeout > 0 && opt.IdleCheckFrequency > 0 {
+ go p.reaper(opt.IdleCheckFrequency)
+ }
+
+ return p
+}
+
+func (p *ConnPool) NewConn() (*Conn, error) {
+ cn, err := p.newConn()
+ if err != nil {
+ return nil, err
+ }
+
+ p.connsMu.Lock()
+ p.conns = append(p.conns, cn)
+ p.connsMu.Unlock()
+ return cn, nil
+}
+
+func (p *ConnPool) newConn() (*Conn, error) {
+ if p.closed() {
+ return nil, ErrClosed
+ }
+
+ if atomic.LoadUint32(&p.dialErrorsNum) >= uint32(p.opt.PoolSize) {
+ return nil, p.getLastDialError()
+ }
+
+ netConn, err := p.opt.Dialer()
+ if err != nil {
+ p.setLastDialError(err)
+ if atomic.AddUint32(&p.dialErrorsNum, 1) == uint32(p.opt.PoolSize) {
+ go p.tryDial()
+ }
+ return nil, err
+ }
+
+ return NewConn(netConn), nil
+}
+
+func (p *ConnPool) tryDial() {
+ for {
+ if p.closed() {
+ return
+ }
+
+ conn, err := p.opt.Dialer()
+ if err != nil {
+ p.setLastDialError(err)
+ time.Sleep(time.Second)
+ continue
+ }
+
+ atomic.StoreUint32(&p.dialErrorsNum, 0)
+ _ = conn.Close()
+ return
+ }
+}
+
+func (p *ConnPool) setLastDialError(err error) {
+ p.lastDialErrorMu.Lock()
+ p.lastDialError = err
+ p.lastDialErrorMu.Unlock()
+}
+
+func (p *ConnPool) getLastDialError() error {
+ p.lastDialErrorMu.RLock()
+ err := p.lastDialError
+ p.lastDialErrorMu.RUnlock()
+ return err
+}
+
+// Get returns existed connection from the pool or creates a new one.
+func (p *ConnPool) Get() (*Conn, error) {
+ if p.closed() {
+ return nil, ErrClosed
+ }
+
+ err := p.waitTurn()
+ if err != nil {
+ return nil, err
+ }
+
+ for {
+ p.idleConnsMu.Lock()
+ cn := p.popIdle()
+ p.idleConnsMu.Unlock()
+
+ if cn == nil {
+ break
+ }
+
+ if cn.IsStale(p.opt.IdleTimeout) {
+ p.CloseConn(cn)
+ continue
+ }
+
+ atomic.AddUint32(&p.stats.Hits, 1)
+ return cn, nil
+ }
+
+ atomic.AddUint32(&p.stats.Misses, 1)
+
+ newcn, err := p.NewConn()
+ if err != nil {
+ p.freeTurn()
+ return nil, err
+ }
+
+ return newcn, nil
+}
+
+func (p *ConnPool) getTurn() {
+ p.queue <- struct{}{}
+}
+
+func (p *ConnPool) waitTurn() error {
+ select {
+ case p.queue <- struct{}{}:
+ return nil
+ default:
+ timer := timers.Get().(*time.Timer)
+ timer.Reset(p.opt.PoolTimeout)
+
+ select {
+ case p.queue <- struct{}{}:
+ if !timer.Stop() {
+ <-timer.C
+ }
+ timers.Put(timer)
+ return nil
+ case <-timer.C:
+ timers.Put(timer)
+ atomic.AddUint32(&p.stats.Timeouts, 1)
+ return ErrPoolTimeout
+ }
+ }
+}
+
+func (p *ConnPool) freeTurn() {
+ <-p.queue
+}
+
+func (p *ConnPool) popIdle() *Conn {
+ if len(p.idleConns) == 0 {
+ return nil
+ }
+
+ idx := len(p.idleConns) - 1
+ cn := p.idleConns[idx]
+ p.idleConns = p.idleConns[:idx]
+
+ return cn
+}
+
+func (p *ConnPool) Put(cn *Conn) {
+ buf := cn.Rd.PeekBuffered()
+ if buf != nil {
+ internal.Logf("connection has unread data: %.100q", buf)
+ p.Remove(cn)
+ return
+ }
+
+ p.idleConnsMu.Lock()
+ p.idleConns = append(p.idleConns, cn)
+ p.idleConnsMu.Unlock()
+ p.freeTurn()
+}
+
+func (p *ConnPool) Remove(cn *Conn) {
+ p.removeConn(cn)
+ p.freeTurn()
+ _ = p.closeConn(cn)
+}
+
+func (p *ConnPool) CloseConn(cn *Conn) error {
+ p.removeConn(cn)
+ return p.closeConn(cn)
+}
+
+func (p *ConnPool) removeConn(cn *Conn) {
+ p.connsMu.Lock()
+ for i, c := range p.conns {
+ if c == cn {
+ p.conns = append(p.conns[:i], p.conns[i+1:]...)
+ break
+ }
+ }
+ p.connsMu.Unlock()
+}
+
+func (p *ConnPool) closeConn(cn *Conn) error {
+ if p.opt.OnClose != nil {
+ _ = p.opt.OnClose(cn)
+ }
+ return cn.Close()
+}
+
+// Len returns total number of connections.
+func (p *ConnPool) Len() int {
+ p.connsMu.Lock()
+ l := len(p.conns)
+ p.connsMu.Unlock()
+ return l
+}
+
+// FreeLen returns number of idle connections.
+func (p *ConnPool) IdleLen() int {
+ p.idleConnsMu.RLock()
+ l := len(p.idleConns)
+ p.idleConnsMu.RUnlock()
+ return l
+}
+
+func (p *ConnPool) Stats() *Stats {
+ idleLen := p.IdleLen()
+ return &Stats{
+ Hits: atomic.LoadUint32(&p.stats.Hits),
+ Misses: atomic.LoadUint32(&p.stats.Misses),
+ Timeouts: atomic.LoadUint32(&p.stats.Timeouts),
+
+ TotalConns: uint32(p.Len()),
+ FreeConns: uint32(idleLen),
+ IdleConns: uint32(idleLen),
+ StaleConns: atomic.LoadUint32(&p.stats.StaleConns),
+ }
+}
+
+func (p *ConnPool) closed() bool {
+ return atomic.LoadUint32(&p._closed) == 1
+}
+
+func (p *ConnPool) Filter(fn func(*Conn) bool) error {
+ var firstErr error
+ p.connsMu.Lock()
+ for _, cn := range p.conns {
+ if fn(cn) {
+ if err := p.closeConn(cn); err != nil && firstErr == nil {
+ firstErr = err
+ }
+ }
+ }
+ p.connsMu.Unlock()
+ return firstErr
+}
+
+func (p *ConnPool) Close() error {
+ if !atomic.CompareAndSwapUint32(&p._closed, 0, 1) {
+ return ErrClosed
+ }
+
+ var firstErr error
+ p.connsMu.Lock()
+ for _, cn := range p.conns {
+ if err := p.closeConn(cn); err != nil && firstErr == nil {
+ firstErr = err
+ }
+ }
+ p.conns = nil
+ p.connsMu.Unlock()
+
+ p.idleConnsMu.Lock()
+ p.idleConns = nil
+ p.idleConnsMu.Unlock()
+
+ return firstErr
+}
+
+func (p *ConnPool) reapStaleConn() *Conn {
+ if len(p.idleConns) == 0 {
+ return nil
+ }
+
+ cn := p.idleConns[0]
+ if !cn.IsStale(p.opt.IdleTimeout) {
+ return nil
+ }
+
+ p.idleConns = append(p.idleConns[:0], p.idleConns[1:]...)
+
+ return cn
+}
+
+func (p *ConnPool) ReapStaleConns() (int, error) {
+ var n int
+ for {
+ p.getTurn()
+
+ p.idleConnsMu.Lock()
+ cn := p.reapStaleConn()
+ p.idleConnsMu.Unlock()
+
+ if cn != nil {
+ p.removeConn(cn)
+ }
+
+ p.freeTurn()
+
+ if cn != nil {
+ p.closeConn(cn)
+ n++
+ } else {
+ break
+ }
+ }
+ return n, nil
+}
+
+func (p *ConnPool) reaper(frequency time.Duration) {
+ ticker := time.NewTicker(frequency)
+ defer ticker.Stop()
+
+ for range ticker.C {
+ if p.closed() {
+ break
+ }
+ n, err := p.ReapStaleConns()
+ if err != nil {
+ internal.Logf("ReapStaleConns failed: %s", err)
+ continue
+ }
+ atomic.AddUint32(&p.stats.StaleConns, uint32(n))
+ }
+}
diff --git a/src/dma/vendor/github.com/go-redis/redis/internal/pool/pool_single.go b/src/dma/vendor/github.com/go-redis/redis/internal/pool/pool_single.go
new file mode 100644
index 00000000..b35b78af
--- /dev/null
+++ b/src/dma/vendor/github.com/go-redis/redis/internal/pool/pool_single.go
@@ -0,0 +1,53 @@
+package pool
+
+type SingleConnPool struct {
+ cn *Conn
+}
+
+var _ Pooler = (*SingleConnPool)(nil)
+
+func NewSingleConnPool(cn *Conn) *SingleConnPool {
+ return &SingleConnPool{
+ cn: cn,
+ }
+}
+
+func (p *SingleConnPool) NewConn() (*Conn, error) {
+ panic("not implemented")
+}
+
+func (p *SingleConnPool) CloseConn(*Conn) error {
+ panic("not implemented")
+}
+
+func (p *SingleConnPool) Get() (*Conn, error) {
+ return p.cn, nil
+}
+
+func (p *SingleConnPool) Put(cn *Conn) {
+ if p.cn != cn {
+ panic("p.cn != cn")
+ }
+}
+
+func (p *SingleConnPool) Remove(cn *Conn) {
+ if p.cn != cn {
+ panic("p.cn != cn")
+ }
+}
+
+func (p *SingleConnPool) Len() int {
+ return 1
+}
+
+func (p *SingleConnPool) IdleLen() int {
+ return 0
+}
+
+func (p *SingleConnPool) Stats() *Stats {
+ return nil
+}
+
+func (p *SingleConnPool) Close() error {
+ return nil
+}
diff --git a/src/dma/vendor/github.com/go-redis/redis/internal/pool/pool_sticky.go b/src/dma/vendor/github.com/go-redis/redis/internal/pool/pool_sticky.go
new file mode 100644
index 00000000..91bd9133
--- /dev/null
+++ b/src/dma/vendor/github.com/go-redis/redis/internal/pool/pool_sticky.go
@@ -0,0 +1,109 @@
+package pool
+
+import "sync"
+
+type StickyConnPool struct {
+ pool *ConnPool
+ reusable bool
+
+ cn *Conn
+ closed bool
+ mu sync.Mutex
+}
+
+var _ Pooler = (*StickyConnPool)(nil)
+
+func NewStickyConnPool(pool *ConnPool, reusable bool) *StickyConnPool {
+ return &StickyConnPool{
+ pool: pool,
+ reusable: reusable,
+ }
+}
+
+func (p *StickyConnPool) NewConn() (*Conn, error) {
+ panic("not implemented")
+}
+
+func (p *StickyConnPool) CloseConn(*Conn) error {
+ panic("not implemented")
+}
+
+func (p *StickyConnPool) Get() (*Conn, error) {
+ p.mu.Lock()
+ defer p.mu.Unlock()
+
+ if p.closed {
+ return nil, ErrClosed
+ }
+ if p.cn != nil {
+ return p.cn, nil
+ }
+
+ cn, err := p.pool.Get()
+ if err != nil {
+ return nil, err
+ }
+
+ p.cn = cn
+ return cn, nil
+}
+
+func (p *StickyConnPool) putUpstream() {
+ p.pool.Put(p.cn)
+ p.cn = nil
+}
+
+func (p *StickyConnPool) Put(cn *Conn) {}
+
+func (p *StickyConnPool) removeUpstream() {
+ p.pool.Remove(p.cn)
+ p.cn = nil
+}
+
+func (p *StickyConnPool) Remove(cn *Conn) {
+ p.removeUpstream()
+}
+
+func (p *StickyConnPool) Len() int {
+ p.mu.Lock()
+ defer p.mu.Unlock()
+
+ if p.cn == nil {
+ return 0
+ }
+ return 1
+}
+
+func (p *StickyConnPool) IdleLen() int {
+ p.mu.Lock()
+ defer p.mu.Unlock()
+
+ if p.cn == nil {
+ return 1
+ }
+ return 0
+}
+
+func (p *StickyConnPool) Stats() *Stats {
+ return nil
+}
+
+func (p *StickyConnPool) Close() error {
+ p.mu.Lock()
+ defer p.mu.Unlock()
+
+ if p.closed {
+ return ErrClosed
+ }
+ p.closed = true
+
+ if p.cn != nil {
+ if p.reusable {
+ p.putUpstream()
+ } else {
+ p.removeUpstream()
+ }
+ }
+
+ return nil
+}
diff --git a/src/dma/vendor/github.com/go-redis/redis/internal/proto/reader.go b/src/dma/vendor/github.com/go-redis/redis/internal/proto/reader.go
new file mode 100644
index 00000000..8c28c7b7
--- /dev/null
+++ b/src/dma/vendor/github.com/go-redis/redis/internal/proto/reader.go
@@ -0,0 +1,316 @@
+package proto
+
+import (
+ "bufio"
+ "fmt"
+ "io"
+ "strconv"
+
+ "github.com/go-redis/redis/internal/util"
+)
+
+const bytesAllocLimit = 1024 * 1024 // 1mb
+
+const (
+ ErrorReply = '-'
+ StatusReply = '+'
+ IntReply = ':'
+ StringReply = '$'
+ ArrayReply = '*'
+)
+
+//------------------------------------------------------------------------------
+
+const Nil = RedisError("redis: nil")
+
+type RedisError string
+
+func (e RedisError) Error() string { return string(e) }
+
+//------------------------------------------------------------------------------
+
+type MultiBulkParse func(*Reader, int64) (interface{}, error)
+
+type Reader struct {
+ src *bufio.Reader
+ buf []byte
+}
+
+func NewReader(rd io.Reader) *Reader {
+ return &Reader{
+ src: bufio.NewReader(rd),
+ buf: make([]byte, 4096),
+ }
+}
+
+func (r *Reader) Reset(rd io.Reader) {
+ r.src.Reset(rd)
+}
+
+func (r *Reader) PeekBuffered() []byte {
+ if n := r.src.Buffered(); n != 0 {
+ b, _ := r.src.Peek(n)
+ return b
+ }
+ return nil
+}
+
+func (r *Reader) ReadN(n int) ([]byte, error) {
+ b, err := readN(r.src, r.buf, n)
+ if err != nil {
+ return nil, err
+ }
+ r.buf = b
+ return b, nil
+}
+
+func (r *Reader) ReadLine() ([]byte, error) {
+ line, isPrefix, err := r.src.ReadLine()
+ if err != nil {
+ return nil, err
+ }
+ if isPrefix {
+ return nil, bufio.ErrBufferFull
+ }
+ if len(line) == 0 {
+ return nil, fmt.Errorf("redis: reply is empty")
+ }
+ if isNilReply(line) {
+ return nil, Nil
+ }
+ return line, nil
+}
+
+func (r *Reader) ReadReply(m MultiBulkParse) (interface{}, error) {
+ line, err := r.ReadLine()
+ if err != nil {
+ return nil, err
+ }
+
+ switch line[0] {
+ case ErrorReply:
+ return nil, ParseErrorReply(line)
+ case StatusReply:
+ return parseTmpStatusReply(line), nil
+ case IntReply:
+ return util.ParseInt(line[1:], 10, 64)
+ case StringReply:
+ return r.readTmpBytesReply(line)
+ case ArrayReply:
+ n, err := parseArrayLen(line)
+ if err != nil {
+ return nil, err
+ }
+ return m(r, n)
+ }
+ return nil, fmt.Errorf("redis: can't parse %.100q", line)
+}
+
+func (r *Reader) ReadIntReply() (int64, error) {
+ line, err := r.ReadLine()
+ if err != nil {
+ return 0, err
+ }
+ switch line[0] {
+ case ErrorReply:
+ return 0, ParseErrorReply(line)
+ case IntReply:
+ return util.ParseInt(line[1:], 10, 64)
+ default:
+ return 0, fmt.Errorf("redis: can't parse int reply: %.100q", line)
+ }
+}
+
+func (r *Reader) ReadTmpBytesReply() ([]byte, error) {
+ line, err := r.ReadLine()
+ if err != nil {
+ return nil, err
+ }
+ switch line[0] {
+ case ErrorReply:
+ return nil, ParseErrorReply(line)
+ case StringReply:
+ return r.readTmpBytesReply(line)
+ case StatusReply:
+ return parseTmpStatusReply(line), nil
+ default:
+ return nil, fmt.Errorf("redis: can't parse string reply: %.100q", line)
+ }
+}
+
+func (r *Reader) ReadBytesReply() ([]byte, error) {
+ b, err := r.ReadTmpBytesReply()
+ if err != nil {
+ return nil, err
+ }
+ cp := make([]byte, len(b))
+ copy(cp, b)
+ return cp, nil
+}
+
+func (r *Reader) ReadStringReply() (string, error) {
+ b, err := r.ReadTmpBytesReply()
+ if err != nil {
+ return "", err
+ }
+ return string(b), nil
+}
+
+func (r *Reader) ReadFloatReply() (float64, error) {
+ b, err := r.ReadTmpBytesReply()
+ if err != nil {
+ return 0, err
+ }
+ return util.ParseFloat(b, 64)
+}
+
+func (r *Reader) ReadArrayReply(m MultiBulkParse) (interface{}, error) {
+ line, err := r.ReadLine()
+ if err != nil {
+ return nil, err
+ }
+ switch line[0] {
+ case ErrorReply:
+ return nil, ParseErrorReply(line)
+ case ArrayReply:
+ n, err := parseArrayLen(line)
+ if err != nil {
+ return nil, err
+ }
+ return m(r, n)
+ default:
+ return nil, fmt.Errorf("redis: can't parse array reply: %.100q", line)
+ }
+}
+
+func (r *Reader) ReadArrayLen() (int64, error) {
+ line, err := r.ReadLine()
+ if err != nil {
+ return 0, err
+ }
+ switch line[0] {
+ case ErrorReply:
+ return 0, ParseErrorReply(line)
+ case ArrayReply:
+ return parseArrayLen(line)
+ default:
+ return 0, fmt.Errorf("redis: can't parse array reply: %.100q", line)
+ }
+}
+
+func (r *Reader) ReadScanReply() ([]string, uint64, error) {
+ n, err := r.ReadArrayLen()
+ if err != nil {
+ return nil, 0, err
+ }
+ if n != 2 {
+ return nil, 0, fmt.Errorf("redis: got %d elements in scan reply, expected 2", n)
+ }
+
+ cursor, err := r.ReadUint()
+ if err != nil {
+ return nil, 0, err
+ }
+
+ n, err = r.ReadArrayLen()
+ if err != nil {
+ return nil, 0, err
+ }
+
+ keys := make([]string, n)
+ for i := int64(0); i < n; i++ {
+ key, err := r.ReadStringReply()
+ if err != nil {
+ return nil, 0, err
+ }
+ keys[i] = key
+ }
+
+ return keys, cursor, err
+}
+
+func (r *Reader) readTmpBytesReply(line []byte) ([]byte, error) {
+ if isNilReply(line) {
+ return nil, Nil
+ }
+
+ replyLen, err := strconv.Atoi(string(line[1:]))
+ if err != nil {
+ return nil, err
+ }
+
+ b, err := r.ReadN(replyLen + 2)
+ if err != nil {
+ return nil, err
+ }
+ return b[:replyLen], nil
+}
+
+func (r *Reader) ReadInt() (int64, error) {
+ b, err := r.ReadTmpBytesReply()
+ if err != nil {
+ return 0, err
+ }
+ return util.ParseInt(b, 10, 64)
+}
+
+func (r *Reader) ReadUint() (uint64, error) {
+ b, err := r.ReadTmpBytesReply()
+ if err != nil {
+ return 0, err
+ }
+ return util.ParseUint(b, 10, 64)
+}
+
+// --------------------------------------------------------------------
+
+func readN(r io.Reader, b []byte, n int) ([]byte, error) {
+ if n == 0 && b == nil {
+ return make([]byte, 0), nil
+ }
+
+ if cap(b) >= n {
+ b = b[:n]
+ _, err := io.ReadFull(r, b)
+ return b, err
+ }
+ b = b[:cap(b)]
+
+ pos := 0
+ for pos < n {
+ diff := n - len(b)
+ if diff > bytesAllocLimit {
+ diff = bytesAllocLimit
+ }
+ b = append(b, make([]byte, diff)...)
+
+ nn, err := io.ReadFull(r, b[pos:])
+ if err != nil {
+ return nil, err
+ }
+ pos += nn
+ }
+
+ return b, nil
+}
+
+func isNilReply(b []byte) bool {
+ return len(b) == 3 &&
+ (b[0] == StringReply || b[0] == ArrayReply) &&
+ b[1] == '-' && b[2] == '1'
+}
+
+func ParseErrorReply(line []byte) error {
+ return RedisError(string(line[1:]))
+}
+
+func parseTmpStatusReply(line []byte) []byte {
+ return line[1:]
+}
+
+func parseArrayLen(line []byte) (int64, error) {
+ if isNilReply(line) {
+ return 0, Nil
+ }
+ return util.ParseInt(line[1:], 10, 64)
+}
diff --git a/src/dma/vendor/github.com/go-redis/redis/internal/proto/scan.go b/src/dma/vendor/github.com/go-redis/redis/internal/proto/scan.go
new file mode 100644
index 00000000..3bdb33f9
--- /dev/null
+++ b/src/dma/vendor/github.com/go-redis/redis/internal/proto/scan.go
@@ -0,0 +1,166 @@
+package proto
+
+import (
+ "encoding"
+ "fmt"
+ "reflect"
+
+ "github.com/go-redis/redis/internal/util"
+)
+
+func Scan(b []byte, v interface{}) error {
+ switch v := v.(type) {
+ case nil:
+ return fmt.Errorf("redis: Scan(nil)")
+ case *string:
+ *v = util.BytesToString(b)
+ return nil
+ case *[]byte:
+ *v = b
+ return nil
+ case *int:
+ var err error
+ *v, err = util.Atoi(b)
+ return err
+ case *int8:
+ n, err := util.ParseInt(b, 10, 8)
+ if err != nil {
+ return err
+ }
+ *v = int8(n)
+ return nil
+ case *int16:
+ n, err := util.ParseInt(b, 10, 16)
+ if err != nil {
+ return err
+ }
+ *v = int16(n)
+ return nil
+ case *int32:
+ n, err := util.ParseInt(b, 10, 32)
+ if err != nil {
+ return err
+ }
+ *v = int32(n)
+ return nil
+ case *int64:
+ n, err := util.ParseInt(b, 10, 64)
+ if err != nil {
+ return err
+ }
+ *v = n
+ return nil
+ case *uint:
+ n, err := util.ParseUint(b, 10, 64)
+ if err != nil {
+ return err
+ }
+ *v = uint(n)
+ return nil
+ case *uint8:
+ n, err := util.ParseUint(b, 10, 8)
+ if err != nil {
+ return err
+ }
+ *v = uint8(n)
+ return nil
+ case *uint16:
+ n, err := util.ParseUint(b, 10, 16)
+ if err != nil {
+ return err
+ }
+ *v = uint16(n)
+ return nil
+ case *uint32:
+ n, err := util.ParseUint(b, 10, 32)
+ if err != nil {
+ return err
+ }
+ *v = uint32(n)
+ return nil
+ case *uint64:
+ n, err := util.ParseUint(b, 10, 64)
+ if err != nil {
+ return err
+ }
+ *v = n
+ return nil
+ case *float32:
+ n, err := util.ParseFloat(b, 32)
+ if err != nil {
+ return err
+ }
+ *v = float32(n)
+ return err
+ case *float64:
+ var err error
+ *v, err = util.ParseFloat(b, 64)
+ return err
+ case *bool:
+ *v = len(b) == 1 && b[0] == '1'
+ return nil
+ case encoding.BinaryUnmarshaler:
+ return v.UnmarshalBinary(b)
+ default:
+ return fmt.Errorf(
+ "redis: can't unmarshal %T (consider implementing BinaryUnmarshaler)", v)
+ }
+}
+
+func ScanSlice(data []string, slice interface{}) error {
+ v := reflect.ValueOf(slice)
+ if !v.IsValid() {
+ return fmt.Errorf("redis: ScanSlice(nil)")
+ }
+ if v.Kind() != reflect.Ptr {
+ return fmt.Errorf("redis: ScanSlice(non-pointer %T)", slice)
+ }
+ v = v.Elem()
+ if v.Kind() != reflect.Slice {
+ return fmt.Errorf("redis: ScanSlice(non-slice %T)", slice)
+ }
+
+ next := makeSliceNextElemFunc(v)
+ for i, s := range data {
+ elem := next()
+ if err := Scan([]byte(s), elem.Addr().Interface()); err != nil {
+ err = fmt.Errorf("redis: ScanSlice index=%d value=%q failed: %s", i, s, err)
+ return err
+ }
+ }
+
+ return nil
+}
+
+func makeSliceNextElemFunc(v reflect.Value) func() reflect.Value {
+ elemType := v.Type().Elem()
+
+ if elemType.Kind() == reflect.Ptr {
+ elemType = elemType.Elem()
+ return func() reflect.Value {
+ if v.Len() < v.Cap() {
+ v.Set(v.Slice(0, v.Len()+1))
+ elem := v.Index(v.Len() - 1)
+ if elem.IsNil() {
+ elem.Set(reflect.New(elemType))
+ }
+ return elem.Elem()
+ }
+
+ elem := reflect.New(elemType)
+ v.Set(reflect.Append(v, elem))
+ return elem.Elem()
+ }
+ }
+
+ zero := reflect.Zero(elemType)
+ return func() reflect.Value {
+ if v.Len() < v.Cap() {
+ v.Set(v.Slice(0, v.Len()+1))
+ return v.Index(v.Len() - 1)
+ }
+
+ v.Set(reflect.Append(v, zero))
+ return v.Index(v.Len() - 1)
+ }
+}
diff --git a/src/dma/vendor/github.com/go-redis/redis/internal/proto/write_buffer.go b/src/dma/vendor/github.com/go-redis/redis/internal/proto/write_buffer.go
new file mode 100644
index 00000000..664f4c33
--- /dev/null
+++ b/src/dma/vendor/github.com/go-redis/redis/internal/proto/write_buffer.go
@@ -0,0 +1,113 @@
+package proto
+
+import (
+ "encoding"
+ "fmt"
+ "strconv"
+)
+
+type WriteBuffer struct {
+ b []byte
+}
+
+func NewWriteBuffer() *WriteBuffer {
+ return &WriteBuffer{
+ b: make([]byte, 0, 4096),
+ }
+}
+
+func (w *WriteBuffer) Len() int { return len(w.b) }
+func (w *WriteBuffer) Bytes() []byte { return w.b }
+func (w *WriteBuffer) Reset() { w.b = w.b[:0] }
+
+func (w *WriteBuffer) Append(args []interface{}) error {
+ w.b = append(w.b, ArrayReply)
+ w.b = strconv.AppendUint(w.b, uint64(len(args)), 10)
+ w.b = append(w.b, '\r', '\n')
+
+ for _, arg := range args {
+ if err := w.append(arg); err != nil {
+ return err
+ }
+ }
+ return nil
+}
+
+func (w *WriteBuffer) append(val interface{}) error {
+ switch v := val.(type) {
+ case nil:
+ w.AppendString("")
+ case string:
+ w.AppendString(v)
+ case []byte:
+ w.AppendBytes(v)
+ case int:
+ w.AppendString(formatInt(int64(v)))
+ case int8:
+ w.AppendString(formatInt(int64(v)))
+ case int16:
+ w.AppendString(formatInt(int64(v)))
+ case int32:
+ w.AppendString(formatInt(int64(v)))
+ case int64:
+ w.AppendString(formatInt(v))
+ case uint:
+ w.AppendString(formatUint(uint64(v)))
+ case uint8:
+ w.AppendString(formatUint(uint64(v)))
+ case uint16:
+ w.AppendString(formatUint(uint64(v)))
+ case uint32:
+ w.AppendString(formatUint(uint64(v)))
+ case uint64:
+ w.AppendString(formatUint(v))
+ case float32:
+ w.AppendString(formatFloat(float64(v)))
+ case float64:
+ w.AppendString(formatFloat(v))
+ case bool:
+ if v {
+ w.AppendString("1")
+ } else {
+ w.AppendString("0")
+ }
+ case encoding.BinaryMarshaler:
+ b, err := v.MarshalBinary()
+ if err != nil {
+ return err
+ }
+ w.AppendBytes(b)
+ default:
+ return fmt.Errorf(
+ "redis: can't marshal %T (consider implementing encoding.BinaryMarshaler)", val)
+ }
+ return nil
+}
+
+func (w *WriteBuffer) AppendString(s string) {
+ w.b = append(w.b, StringReply)
+ w.b = strconv.AppendUint(w.b, uint64(len(s)), 10)
+ w.b = append(w.b, '\r', '\n')
+ w.b = append(w.b, s...)
+ w.b = append(w.b, '\r', '\n')
+}
+
+func (w *WriteBuffer) AppendBytes(p []byte) {
+ w.b = append(w.b, StringReply)
+ w.b = strconv.AppendUint(w.b, uint64(len(p)), 10)
+ w.b = append(w.b, '\r', '\n')
+ w.b = append(w.b, p...)
+ w.b = append(w.b, '\r', '\n')
+}
+
+func formatInt(n int64) string {
+ return strconv.FormatInt(n, 10)
+}
+
+func formatUint(u uint64) string {
+ return strconv.FormatUint(u, 10)
+}
+
+func formatFloat(f float64) string {
+ return strconv.FormatFloat(f, 'f', -1, 64)
+}
diff --git a/src/dma/vendor/github.com/go-redis/redis/internal/singleflight/singleflight.go b/src/dma/vendor/github.com/go-redis/redis/internal/singleflight/singleflight.go
new file mode 100644
index 00000000..3b174172
--- /dev/null
+++ b/src/dma/vendor/github.com/go-redis/redis/internal/singleflight/singleflight.go
@@ -0,0 +1,64 @@
+/*
+Copyright 2013 Google Inc.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+// Package singleflight provides a duplicate function call suppression
+// mechanism.
+package singleflight
+
+import "sync"
+
+// call is an in-flight or completed Do call
+type call struct {
+ wg sync.WaitGroup
+ val interface{}
+ err error
+}
+
+// Group represents a class of work and forms a namespace in which
+// units of work can be executed with duplicate suppression.
+type Group struct {
+ mu sync.Mutex // protects m
+ m map[string]*call // lazily initialized
+}
+
+// Do executes and returns the results of the given function, making
+// sure that only one execution is in-flight for a given key at a
+// time. If a duplicate comes in, the duplicate caller waits for the
+// original to complete and receives the same results.
+func (g *Group) Do(key string, fn func() (interface{}, error)) (interface{}, error) {
+ g.mu.Lock()
+ if g.m == nil {
+ g.m = make(map[string]*call)
+ }
+ if c, ok := g.m[key]; ok {
+ g.mu.Unlock()
+ c.wg.Wait()
+ return c.val, c.err
+ }
+ c := new(call)
+ c.wg.Add(1)
+ g.m[key] = c
+ g.mu.Unlock()
+
+ c.val, c.err = fn()
+ c.wg.Done()
+
+ g.mu.Lock()
+ delete(g.m, key)
+ g.mu.Unlock()
+
+ return c.val, c.err
+}
diff --git a/src/dma/vendor/github.com/go-redis/redis/internal/util.go b/src/dma/vendor/github.com/go-redis/redis/internal/util.go
new file mode 100644
index 00000000..ffd2353e
--- /dev/null
+++ b/src/dma/vendor/github.com/go-redis/redis/internal/util.go
@@ -0,0 +1,29 @@
+package internal
+
+import "github.com/go-redis/redis/internal/util"
+
+func ToLower(s string) string {
+ if isLower(s) {
+ return s
+ }
+
+ b := make([]byte, len(s))
+ for i := range b {
+ c := s[i]
+ if c >= 'A' && c <= 'Z' {
+ c += 'a' - 'A'
+ }
+ b[i] = c
+ }
+ return util.BytesToString(b)
+}
+
+func isLower(s string) bool {
+ for i := 0; i < len(s); i++ {
+ c := s[i]
+ if c >= 'A' && c <= 'Z' {
+ return false
+ }
+ }
+ return true
+}
diff --git a/src/dma/vendor/github.com/go-redis/redis/internal/util/safe.go b/src/dma/vendor/github.com/go-redis/redis/internal/util/safe.go
new file mode 100644
index 00000000..cd891833
--- /dev/null
+++ b/src/dma/vendor/github.com/go-redis/redis/internal/util/safe.go
@@ -0,0 +1,7 @@
+// +build appengine
+
+package util
+
+func BytesToString(b []byte) string {
+ return string(b)
+}
diff --git a/src/dma/vendor/github.com/go-redis/redis/internal/util/strconv.go b/src/dma/vendor/github.com/go-redis/redis/internal/util/strconv.go
new file mode 100644
index 00000000..db503380
--- /dev/null
+++ b/src/dma/vendor/github.com/go-redis/redis/internal/util/strconv.go
@@ -0,0 +1,19 @@
+package util
+
+import "strconv"
+
+func Atoi(b []byte) (int, error) {
+ return strconv.Atoi(BytesToString(b))
+}
+
+func ParseInt(b []byte, base int, bitSize int) (int64, error) {
+ return strconv.ParseInt(BytesToString(b), base, bitSize)
+}
+
+func ParseUint(b []byte, base int, bitSize int) (uint64, error) {
+ return strconv.ParseUint(BytesToString(b), base, bitSize)
+}
+
+func ParseFloat(b []byte, bitSize int) (float64, error) {
+ return strconv.ParseFloat(BytesToString(b), bitSize)
+}
diff --git a/src/dma/vendor/github.com/go-redis/redis/internal/util/unsafe.go b/src/dma/vendor/github.com/go-redis/redis/internal/util/unsafe.go
new file mode 100644
index 00000000..93a89c55
--- /dev/null
+++ b/src/dma/vendor/github.com/go-redis/redis/internal/util/unsafe.go
@@ -0,0 +1,12 @@
+// +build !appengine
+
+package util
+
+import (
+ "unsafe"
+)
+
+// BytesToString converts byte slice to string.
+func BytesToString(b []byte) string {
+ return *(*string)(unsafe.Pointer(&b))
+}
diff --git a/src/dma/vendor/github.com/go-redis/redis/iterator.go b/src/dma/vendor/github.com/go-redis/redis/iterator.go
new file mode 100644
index 00000000..5d4bedfe
--- /dev/null
+++ b/src/dma/vendor/github.com/go-redis/redis/iterator.go
@@ -0,0 +1,73 @@
+package redis
+
+import "sync"
+
+// ScanIterator is used to incrementally iterate over a collection of elements.
+// It's safe for concurrent use by multiple goroutines.
+type ScanIterator struct {
+ mu sync.Mutex // protects Scanner and pos
+ cmd *ScanCmd
+ pos int
+}
+
+// Err returns the last iterator error, if any.
+func (it *ScanIterator) Err() error {
+ it.mu.Lock()
+ err := it.cmd.Err()
+ it.mu.Unlock()
+ return err
+}
+
+// Next advances the cursor and returns true if more values can be read.
+func (it *ScanIterator) Next() bool {
+ it.mu.Lock()
+ defer it.mu.Unlock()
+
+ // Instantly return on errors.
+ if it.cmd.Err() != nil {
+ return false
+ }
+
+ // Advance cursor, check if we are still within range.
+ if it.pos < len(it.cmd.page) {
+ it.pos++
+ return true
+ }
+
+ for {
+ // Return if there is no more data to fetch.
+ if it.cmd.cursor == 0 {
+ return false
+ }
+
+ // Fetch next page.
+ if it.cmd._args[0] == "scan" {
+ it.cmd._args[1] = it.cmd.cursor
+ } else {
+ it.cmd._args[2] = it.cmd.cursor
+ }
+
+ err := it.cmd.process(it.cmd)
+ if err != nil {
+ return false
+ }
+
+ it.pos = 1
+
+ // Redis can occasionally return empty page.
+ if len(it.cmd.page) > 0 {
+ return true
+ }
+ }
+}
+
+// Val returns the key/field at the current cursor position.
+func (it *ScanIterator) Val() string {
+ var v string
+ it.mu.Lock()
+ if it.cmd.Err() == nil && it.pos > 0 && it.pos <= len(it.cmd.page) {
+ v = it.cmd.page[it.pos-1]
+ }
+ it.mu.Unlock()
+ return v
+}
diff --git a/src/dma/vendor/github.com/go-redis/redis/options.go b/src/dma/vendor/github.com/go-redis/redis/options.go
new file mode 100644
index 00000000..8a82d590
--- /dev/null
+++ b/src/dma/vendor/github.com/go-redis/redis/options.go
@@ -0,0 +1,203 @@
+package redis
+
+import (
+ "crypto/tls"
+ "errors"
+ "fmt"
+ "net"
+ "net/url"
+ "runtime"
+ "strconv"
+ "strings"
+ "time"
+
+ "github.com/go-redis/redis/internal/pool"
+)
+
+type Options struct {
+ // The network type, either tcp or unix.
+ // Default is tcp.
+ Network string
+ // host:port address.
+ Addr string
+
+ // Dialer creates new network connection and has priority over
+ // Network and Addr options.
+ Dialer func() (net.Conn, error)
+
+ // Hook that is called when new connection is established.
+ OnConnect func(*Conn) error
+
+ // Optional password. Must match the password specified in the
+ // requirepass server configuration option.
+ Password string
+ // Database to be selected after connecting to the server.
+ DB int
+
+ // Maximum number of retries before giving up.
+ // Default is to not retry failed commands.
+ MaxRetries int
+ // Minimum backoff between each retry.
+ // Default is 8 milliseconds; -1 disables backoff.
+ MinRetryBackoff time.Duration
+ // Maximum backoff between each retry.
+ // Default is 512 milliseconds; -1 disables backoff.
+ MaxRetryBackoff time.Duration
+
+ // Dial timeout for establishing new connections.
+ // Default is 5 seconds.
+ DialTimeout time.Duration
+ // Timeout for socket reads. If reached, commands will fail
+ // with a timeout instead of blocking.
+ // Default is 3 seconds.
+ ReadTimeout time.Duration
+ // Timeout for socket writes. If reached, commands will fail
+ // with a timeout instead of blocking.
+ // Default is ReadTimeout.
+ WriteTimeout time.Duration
+
+ // Maximum number of socket connections.
+ // Default is 10 connections per every CPU as reported by runtime.NumCPU.
+ PoolSize int
+ // Amount of time client waits for connection if all connections
+ // are busy before returning an error.
+ // Default is ReadTimeout + 1 second.
+ PoolTimeout time.Duration
+ // Amount of time after which client closes idle connections.
+ // Should be less than server's timeout.
+ // Default is 5 minutes. -1 disables idle timeout check.
+ IdleTimeout time.Duration
+ // Frequency of idle checks made by idle connections reaper.
+ // Default is 1 minute. -1 disables idle connections reaper,
+ // but idle connections are still discarded by the client.
+ IdleCheckFrequency time.Duration
+
+ // Enables read only queries on slave nodes.
+ readOnly bool
+
+ // TLS Config to use. When set TLS will be negotiated.
+ TLSConfig *tls.Config
+}
+
+func (opt *Options) init() {
+ if opt.Network == "" {
+ opt.Network = "tcp"
+ }
+ if opt.Dialer == nil {
+ opt.Dialer = func() (net.Conn, error) {
+ netDialer := &net.Dialer{
+ Timeout: opt.DialTimeout,
+ KeepAlive: 5 * time.Minute,
+ }
+ if opt.TLSConfig == nil {
+ return netDialer.Dial(opt.Network, opt.Addr)
+ } else {
+ return tls.DialWithDialer(netDialer, opt.Network, opt.Addr, opt.TLSConfig)
+ }
+ }
+ }
+ if opt.PoolSize == 0 {
+ opt.PoolSize = 10 * runtime.NumCPU()
+ }
+ if opt.DialTimeout == 0 {
+ opt.DialTimeout = 5 * time.Second
+ }
+ switch opt.ReadTimeout {
+ case -1:
+ opt.ReadTimeout = 0
+ case 0:
+ opt.ReadTimeout = 3 * time.Second
+ }
+ switch opt.WriteTimeout {
+ case -1:
+ opt.WriteTimeout = 0
+ case 0:
+ opt.WriteTimeout = opt.ReadTimeout
+ }
+ if opt.PoolTimeout == 0 {
+ opt.PoolTimeout = opt.ReadTimeout + time.Second
+ }
+ if opt.IdleTimeout == 0 {
+ opt.IdleTimeout = 5 * time.Minute
+ }
+ if opt.IdleCheckFrequency == 0 {
+ opt.IdleCheckFrequency = time.Minute
+ }
+
+ switch opt.MinRetryBackoff {
+ case -1:
+ opt.MinRetryBackoff = 0
+ case 0:
+ opt.MinRetryBackoff = 8 * time.Millisecond
+ }
+ switch opt.MaxRetryBackoff {
+ case -1:
+ opt.MaxRetryBackoff = 0
+ case 0:
+ opt.MaxRetryBackoff = 512 * time.Millisecond
+ }
+}
+
+// ParseURL parses an URL into Options that can be used to connect to Redis.
+func ParseURL(redisURL string) (*Options, error) {
+ o := &Options{Network: "tcp"}
+ u, err := url.Parse(redisURL)
+ if err != nil {
+ return nil, err
+ }
+
+ if u.Scheme != "redis" && u.Scheme != "rediss" {
+ return nil, errors.New("invalid redis URL scheme: " + u.Scheme)
+ }
+
+ if u.User != nil {
+ if p, ok := u.User.Password(); ok {
+ o.Password = p
+ }
+ }
+
+ if len(u.Query()) > 0 {
+ return nil, errors.New("no options supported")
+ }
+
+ h, p, err := net.SplitHostPort(u.Host)
+ if err != nil {
+ h = u.Host
+ }
+ if h == "" {
+ h = "localhost"
+ }
+ if p == "" {
+ p = "6379"
+ }
+ o.Addr = net.JoinHostPort(h, p)
+
+ f := strings.FieldsFunc(u.Path, func(r rune) bool {
+ return r == '/'
+ })
+ switch len(f) {
+ case 0:
+ o.DB = 0
+ case 1:
+ if o.DB, err = strconv.Atoi(f[0]); err != nil {
+ return nil, fmt.Errorf("invalid redis database number: %q", f[0])
+ }
+ default:
+ return nil, errors.New("invalid redis URL path: " + u.Path)
+ }
+
+ if u.Scheme == "rediss" {
+ o.TLSConfig = &tls.Config{ServerName: h}
+ }
+ return o, nil
+}
+
+func newConnPool(opt *Options) *pool.ConnPool {
+ return pool.NewConnPool(&pool.Options{
+ Dialer: opt.Dialer,
+ PoolSize: opt.PoolSize,
+ PoolTimeout: opt.PoolTimeout,
+ IdleTimeout: opt.IdleTimeout,
+ IdleCheckFrequency: opt.IdleCheckFrequency,
+ })
+}
diff --git a/src/dma/vendor/github.com/go-redis/redis/parser.go b/src/dma/vendor/github.com/go-redis/redis/parser.go
new file mode 100644
index 00000000..f0dc67f0
--- /dev/null
+++ b/src/dma/vendor/github.com/go-redis/redis/parser.go
@@ -0,0 +1,394 @@
+package redis
+
+import (
+ "fmt"
+ "net"
+ "strconv"
+ "time"
+
+ "github.com/go-redis/redis/internal/proto"
+)
+
+// Implements proto.MultiBulkParse
+func sliceParser(rd *proto.Reader, n int64) (interface{}, error) {
+ vals := make([]interface{}, 0, n)
+ for i := int64(0); i < n; i++ {
+ v, err := rd.ReadReply(sliceParser)
+ if err != nil {
+ if err == Nil {
+ vals = append(vals, nil)
+ continue
+ }
+ if err, ok := err.(proto.RedisError); ok {
+ vals = append(vals, err)
+ continue
+ }
+ return nil, err
+ }
+
+ switch v := v.(type) {
+ case []byte:
+ vals = append(vals, string(v))
+ default:
+ vals = append(vals, v)
+ }
+ }
+ return vals, nil
+}
+
+// Implements proto.MultiBulkParse
+func boolSliceParser(rd *proto.Reader, n int64) (interface{}, error) {
+ bools := make([]bool, 0, n)
+ for i := int64(0); i < n; i++ {
+ n, err := rd.ReadIntReply()
+ if err != nil {
+ return nil, err
+ }
+ bools = append(bools, n == 1)
+ }
+ return bools, nil
+}
+
+// Implements proto.MultiBulkParse
+func stringSliceParser(rd *proto.Reader, n int64) (interface{}, error) {
+ ss := make([]string, 0, n)
+ for i := int64(0); i < n; i++ {
+ s, err := rd.ReadStringReply()
+ if err == Nil {
+ ss = append(ss, "")
+ } else if err != nil {
+ return nil, err
+ } else {
+ ss = append(ss, s)
+ }
+ }
+ return ss, nil
+}
+
+// Implements proto.MultiBulkParse
+func stringStringMapParser(rd *proto.Reader, n int64) (interface{}, error) {
+ m := make(map[string]string, n/2)
+ for i := int64(0); i < n; i += 2 {
+ key, err := rd.ReadStringReply()
+ if err != nil {
+ return nil, err
+ }
+
+ value, err := rd.ReadStringReply()
+ if err != nil {
+ return nil, err
+ }
+
+ m[key] = value
+ }
+ return m, nil
+}
+
+// Implements proto.MultiBulkParse
+func stringIntMapParser(rd *proto.Reader, n int64) (interface{}, error) {
+ m := make(map[string]int64, n/2)
+ for i := int64(0); i < n; i += 2 {
+ key, err := rd.ReadStringReply()
+ if err != nil {
+ return nil, err
+ }
+
+ n, err := rd.ReadIntReply()
+ if err != nil {
+ return nil, err
+ }
+
+ m[key] = n
+ }
+ return m, nil
+}
+
+// Implements proto.MultiBulkParse
+func stringStructMapParser(rd *proto.Reader, n int64) (interface{}, error) {
+ m := make(map[string]struct{}, n)
+ for i := int64(0); i < n; i++ {
+ key, err := rd.ReadStringReply()
+ if err != nil {
+ return nil, err
+ }
+
+ m[key] = struct{}{}
+ }
+ return m, nil
+}
+
+// Implements proto.MultiBulkParse
+func zSliceParser(rd *proto.Reader, n int64) (interface{}, error) {
+ zz := make([]Z, n/2)
+ for i := int64(0); i < n; i += 2 {
+ var err error
+
+ z := &zz[i/2]
+
+ z.Member, err = rd.ReadStringReply()
+ if err != nil {
+ return nil, err
+ }
+
+ z.Score, err = rd.ReadFloatReply()
+ if err != nil {
+ return nil, err
+ }
+ }
+ return zz, nil
+}
+
+// Implements proto.MultiBulkParse
+func clusterSlotsParser(rd *proto.Reader, n int64) (interface{}, error) {
+ slots := make([]ClusterSlot, n)
+ for i := 0; i < len(slots); i++ {
+ n, err := rd.ReadArrayLen()
+ if err != nil {
+ return nil, err
+ }
+ if n < 2 {
+ err := fmt.Errorf("redis: got %d elements in cluster info, expected at least 2", n)
+ return nil, err
+ }
+
+ start, err := rd.ReadIntReply()
+ if err != nil {
+ return nil, err
+ }
+
+ end, err := rd.ReadIntReply()
+ if err != nil {
+ return nil, err
+ }
+
+ nodes := make([]ClusterNode, n-2)
+ for j := 0; j < len(nodes); j++ {
+ n, err := rd.ReadArrayLen()
+ if err != nil {
+ return nil, err
+ }
+ if n != 2 && n != 3 {
+ err := fmt.Errorf("got %d elements in cluster info address, expected 2 or 3", n)
+ return nil, err
+ }
+
+ ip, err := rd.ReadStringReply()
+ if err != nil {
+ return nil, err
+ }
+
+ port, err := rd.ReadIntReply()
+ if err != nil {
+ return nil, err
+ }
+ nodes[j].Addr = net.JoinHostPort(ip, strconv.FormatInt(port, 10))
+
+ if n == 3 {
+ id, err := rd.ReadStringReply()
+ if err != nil {
+ return nil, err
+ }
+ nodes[j].Id = id
+ }
+ }
+
+ slots[i] = ClusterSlot{
+ Start: int(start),
+ End: int(end),
+ Nodes: nodes,
+ }
+ }
+ return slots, nil
+}
+
+func newGeoLocationParser(q *GeoRadiusQuery) proto.MultiBulkParse {
+ return func(rd *proto.Reader, n int64) (interface{}, error) {
+ var loc GeoLocation
+ var err error
+
+ loc.Name, err = rd.ReadStringReply()
+ if err != nil {
+ return nil, err
+ }
+ if q.WithDist {
+ loc.Dist, err = rd.ReadFloatReply()
+ if err != nil {
+ return nil, err
+ }
+ }
+ if q.WithGeoHash {
+ loc.GeoHash, err = rd.ReadIntReply()
+ if err != nil {
+ return nil, err
+ }
+ }
+ if q.WithCoord {
+ n, err := rd.ReadArrayLen()
+ if err != nil {
+ return nil, err
+ }
+ if n != 2 {
+ return nil, fmt.Errorf("got %d coordinates, expected 2", n)
+ }
+
+ loc.Longitude, err = rd.ReadFloatReply()
+ if err != nil {
+ return nil, err
+ }
+ loc.Latitude, err = rd.ReadFloatReply()
+ if err != nil {
+ return nil, err
+ }
+ }
+
+ return &loc, nil
+ }
+}
+
+func newGeoLocationSliceParser(q *GeoRadiusQuery) proto.MultiBulkParse {
+ return func(rd *proto.Reader, n int64) (interface{}, error) {
+ locs := make([]GeoLocation, 0, n)
+ for i := int64(0); i < n; i++ {
+ v, err := rd.ReadReply(newGeoLocationParser(q))
+ if err != nil {
+ return nil, err
+ }
+ switch vv := v.(type) {
+ case []byte:
+ locs = append(locs, GeoLocation{
+ Name: string(vv),
+ })
+ case *GeoLocation:
+ locs = append(locs, *vv)
+ default:
+ return nil, fmt.Errorf("got %T, expected string or *GeoLocation", v)
+ }
+ }
+ return locs, nil
+ }
+}
+
+func geoPosParser(rd *proto.Reader, n int64) (interface{}, error) {
+ var pos GeoPos
+ var err error
+
+ pos.Longitude, err = rd.ReadFloatReply()
+ if err != nil {
+ return nil, err
+ }
+
+ pos.Latitude, err = rd.ReadFloatReply()
+ if err != nil {
+ return nil, err
+ }
+
+ return &pos, nil
+}
+
+func geoPosSliceParser(rd *proto.Reader, n int64) (interface{}, error) {
+ positions := make([]*GeoPos, 0, n)
+ for i := int64(0); i < n; i++ {
+ v, err := rd.ReadReply(geoPosParser)
+ if err != nil {
+ if err == Nil {
+ positions = append(positions, nil)
+ continue
+ }
+ return nil, err
+ }
+ switch v := v.(type) {
+ case *GeoPos:
+ positions = append(positions, v)
+ default:
+ return nil, fmt.Errorf("got %T, expected *GeoPos", v)
+ }
+ }
+ return positions, nil
+}
+
+func commandInfoParser(rd *proto.Reader, n int64) (interface{}, error) {
+ var cmd CommandInfo
+ var err error
+
+ if n != 6 {
+ return nil, fmt.Errorf("redis: got %d elements in COMMAND reply, wanted 6", n)
+ }
+
+ cmd.Name, err = rd.ReadStringReply()
+ if err != nil {
+ return nil, err
+ }
+
+ arity, err := rd.ReadIntReply()
+ if err != nil {
+ return nil, err
+ }
+ cmd.Arity = int8(arity)
+
+ flags, err := rd.ReadReply(stringSliceParser)
+ if err != nil {
+ return nil, err
+ }
+ cmd.Flags = flags.([]string)
+
+ firstKeyPos, err := rd.ReadIntReply()
+ if err != nil {
+ return nil, err
+ }
+ cmd.FirstKeyPos = int8(firstKeyPos)
+
+ lastKeyPos, err := rd.ReadIntReply()
+ if err != nil {
+ return nil, err
+ }
+ cmd.LastKeyPos = int8(lastKeyPos)
+
+ stepCount, err := rd.ReadIntReply()
+ if err != nil {
+ return nil, err
+ }
+ cmd.StepCount = int8(stepCount)
+
+ for _, flag := range cmd.Flags {
+ if flag == "readonly" {
+ cmd.ReadOnly = true
+ break
+ }
+ }
+
+ return &cmd, nil
+}
+
+// Implements proto.MultiBulkParse
+func commandInfoSliceParser(rd *proto.Reader, n int64) (interface{}, error) {
+ m := make(map[string]*CommandInfo, n)
+ for i := int64(0); i < n; i++ {
+ v, err := rd.ReadReply(commandInfoParser)
+ if err != nil {
+ return nil, err
+ }
+ vv := v.(*CommandInfo)
+ m[vv.Name] = vv
+
+ }
+ return m, nil
+}
+
+// Implements proto.MultiBulkParse
+func timeParser(rd *proto.Reader, n int64) (interface{}, error) {
+ if n != 2 {
+ return nil, fmt.Errorf("got %d elements, expected 2", n)
+ }
+
+ sec, err := rd.ReadInt()
+ if err != nil {
+ return nil, err
+ }
+
+ microsec, err := rd.ReadInt()
+ if err != nil {
+ return nil, err
+ }
+
+ return time.Unix(sec, microsec*1000), nil
+}
diff --git a/src/dma/vendor/github.com/go-redis/redis/pipeline.go b/src/dma/vendor/github.com/go-redis/redis/pipeline.go
new file mode 100644
index 00000000..ba852283
--- /dev/null
+++ b/src/dma/vendor/github.com/go-redis/redis/pipeline.go
@@ -0,0 +1,113 @@
+package redis
+
+import (
+ "sync"
+
+ "github.com/go-redis/redis/internal/pool"
+)
+
+type pipelineExecer func([]Cmder) error
+
+type Pipeliner interface {
+ StatefulCmdable
+ Process(cmd Cmder) error
+ Close() error
+ Discard() error
+ Exec() ([]Cmder, error)
+}
+
+var _ Pipeliner = (*Pipeline)(nil)
+
+// Pipeline implements pipelining as described in
+// http://redis.io/topics/pipelining. It's safe for concurrent use
+// by multiple goroutines.
+type Pipeline struct {
+ statefulCmdable
+
+ exec pipelineExecer
+
+ mu sync.Mutex
+ cmds []Cmder
+ closed bool
+}
+
+// Process queues the cmd for later execution.
+func (c *Pipeline) Process(cmd Cmder) error {
+ c.mu.Lock()
+ c.cmds = append(c.cmds, cmd)
+ c.mu.Unlock()
+ return nil
+}
+
+// Close closes the pipeline, releasing any open resources.
+func (c *Pipeline) Close() error {
+ c.mu.Lock()
+ c.discard()
+ c.closed = true
+ c.mu.Unlock()
+ return nil
+}
+
+// Discard resets the pipeline and discards queued commands.
+func (c *Pipeline) Discard() error {
+ c.mu.Lock()
+ err := c.discard()
+ c.mu.Unlock()
+ return err
+}
+
+func (c *Pipeline) discard() error {
+ if c.closed {
+ return pool.ErrClosed
+ }
+ c.cmds = c.cmds[:0]
+ return nil
+}
+
+// Exec executes all previously queued commands using one
+// client-server roundtrip.
+//
+// Exec always returns list of commands and error of the first failed
+// command if any.
+func (c *Pipeline) Exec() ([]Cmder, error) {
+ c.mu.Lock()
+ defer c.mu.Unlock()
+
+ if c.closed {
+ return nil, pool.ErrClosed
+ }
+
+ if len(c.cmds) == 0 {
+ return nil, nil
+ }
+
+ cmds := c.cmds
+ c.cmds = nil
+
+ return cmds, c.exec(cmds)
+}
+
+func (c *Pipeline) pipelined(fn func(Pipeliner) error) ([]Cmder, error) {
+ if err := fn(c); err != nil {
+ return nil, err
+ }
+ cmds, err := c.Exec()
+ _ = c.Close()
+ return cmds, err
+}
+
+func (c *Pipeline) Pipelined(fn func(Pipeliner) error) ([]Cmder, error) {
+ return c.pipelined(fn)
+}
+
+func (c *Pipeline) Pipeline() Pipeliner {
+ return c
+}
+
+func (c *Pipeline) TxPipelined(fn func(Pipeliner) error) ([]Cmder, error) {
+ return c.pipelined(fn)
+}
+
+func (c *Pipeline) TxPipeline() Pipeliner {
+ return c
+}
diff --git a/src/dma/vendor/github.com/go-redis/redis/pubsub.go b/src/dma/vendor/github.com/go-redis/redis/pubsub.go
new file mode 100644
index 00000000..2cfcd150
--- /dev/null
+++ b/src/dma/vendor/github.com/go-redis/redis/pubsub.go
@@ -0,0 +1,460 @@
+package redis
+
+import (
+ "fmt"
+ "sync"
+ "time"
+
+ "github.com/go-redis/redis/internal"
+ "github.com/go-redis/redis/internal/pool"
+)
+
+// PubSub implements Pub/Sub commands as described in
+// http://redis.io/topics/pubsub. Message receiving is NOT safe
+// for concurrent use by multiple goroutines.
+//
+// PubSub automatically reconnects to Redis Server and resubscribes
+// to the channels in case of network errors.
+type PubSub struct {
+ opt *Options
+
+ newConn func([]string) (*pool.Conn, error)
+ closeConn func(*pool.Conn) error
+
+ mu sync.Mutex
+ cn *pool.Conn
+ channels map[string]struct{}
+ patterns map[string]struct{}
+ closed bool
+ exit chan struct{}
+
+ cmd *Cmd
+
+ chOnce sync.Once
+ ch chan *Message
+ ping chan struct{}
+}
+
+func (c *PubSub) init() {
+ c.exit = make(chan struct{})
+}
+
+func (c *PubSub) conn() (*pool.Conn, error) {
+ c.mu.Lock()
+ cn, err := c._conn(nil)
+ c.mu.Unlock()
+ return cn, err
+}
+
+func (c *PubSub) _conn(channels []string) (*pool.Conn, error) {
+ if c.closed {
+ return nil, pool.ErrClosed
+ }
+
+ if c.cn != nil {
+ return c.cn, nil
+ }
+
+ cn, err := c.newConn(channels)
+ if err != nil {
+ return nil, err
+ }
+
+ if err := c.resubscribe(cn); err != nil {
+ _ = c.closeConn(cn)
+ return nil, err
+ }
+
+ c.cn = cn
+ return cn, nil
+}
+
+func (c *PubSub) resubscribe(cn *pool.Conn) error {
+ var firstErr error
+
+ if len(c.channels) > 0 {
+ channels := mapKeys(c.channels)
+ err := c._subscribe(cn, "subscribe", channels...)
+ if err != nil && firstErr == nil {
+ firstErr = err
+ }
+ }
+
+ if len(c.patterns) > 0 {
+ patterns := mapKeys(c.patterns)
+ err := c._subscribe(cn, "psubscribe", patterns...)
+ if err != nil && firstErr == nil {
+ firstErr = err
+ }
+ }
+
+ return firstErr
+}
+
+func mapKeys(m map[string]struct{}) []string {
+ s := make([]string, len(m))
+ i := 0
+ for k := range m {
+ s[i] = k
+ i++
+ }
+ return s
+}
+
+func (c *PubSub) _subscribe(cn *pool.Conn, redisCmd string, channels ...string) error {
+ args := make([]interface{}, 1+len(channels))
+ args[0] = redisCmd
+ for i, channel := range channels {
+ args[1+i] = channel
+ }
+ cmd := NewSliceCmd(args...)
+
+ cn.SetWriteTimeout(c.opt.WriteTimeout)
+ return writeCmd(cn, cmd)
+}
+
+func (c *PubSub) releaseConn(cn *pool.Conn, err error) {
+ c.mu.Lock()
+ c._releaseConn(cn, err)
+ c.mu.Unlock()
+}
+
+func (c *PubSub) _releaseConn(cn *pool.Conn, err error) {
+ if c.cn != cn {
+ return
+ }
+ if internal.IsBadConn(err, true) {
+ c._reconnect()
+ }
+}
+
+func (c *PubSub) _closeTheCn() error {
+ var err error
+ if c.cn != nil {
+ err = c.closeConn(c.cn)
+ c.cn = nil
+ }
+ return err
+}
+
+func (c *PubSub) reconnect() {
+ c.mu.Lock()
+ c._reconnect()
+ c.mu.Unlock()
+}
+
+func (c *PubSub) _reconnect() {
+ _ = c._closeTheCn()
+ _, _ = c._conn(nil)
+}
+
+func (c *PubSub) Close() error {
+ c.mu.Lock()
+ defer c.mu.Unlock()
+
+ if c.closed {
+ return pool.ErrClosed
+ }
+ c.closed = true
+ close(c.exit)
+
+ err := c._closeTheCn()
+ return err
+}
+
+// Subscribe the client to the specified channels. It returns
+// empty subscription if there are no channels.
+func (c *PubSub) Subscribe(channels ...string) error {
+ c.mu.Lock()
+ defer c.mu.Unlock()
+
+ err := c.subscribe("subscribe", channels...)
+ if c.channels == nil {
+ c.channels = make(map[string]struct{})
+ }
+ for _, channel := range channels {
+ c.channels[channel] = struct{}{}
+ }
+ return err
+}
+
+// PSubscribe the client to the given patterns. It returns
+// empty subscription if there are no patterns.
+func (c *PubSub) PSubscribe(patterns ...string) error {
+ c.mu.Lock()
+ defer c.mu.Unlock()
+
+ err := c.subscribe("psubscribe", patterns...)
+ if c.patterns == nil {
+ c.patterns = make(map[string]struct{})
+ }
+ for _, pattern := range patterns {
+ c.patterns[pattern] = struct{}{}
+ }
+ return err
+}
+
+// Unsubscribe the client from the given channels, or from all of
+// them if none is given.
+func (c *PubSub) Unsubscribe(channels ...string) error {
+ c.mu.Lock()
+ defer c.mu.Unlock()
+
+ err := c.subscribe("unsubscribe", channels...)
+ for _, channel := range channels {
+ delete(c.channels, channel)
+ }
+ return err
+}
+
+// PUnsubscribe the client from the given patterns, or from all of
+// them if none is given.
+func (c *PubSub) PUnsubscribe(patterns ...string) error {
+ c.mu.Lock()
+ defer c.mu.Unlock()
+
+ err := c.subscribe("punsubscribe", patterns...)
+ for _, pattern := range patterns {
+ delete(c.patterns, pattern)
+ }
+ return err
+}
+
+func (c *PubSub) subscribe(redisCmd string, channels ...string) error {
+ cn, err := c._conn(channels)
+ if err != nil {
+ return err
+ }
+
+ err = c._subscribe(cn, redisCmd, channels...)
+ c._releaseConn(cn, err)
+ return err
+}
+
+func (c *PubSub) Ping(payload ...string) error {
+ args := []interface{}{"ping"}
+ if len(payload) == 1 {
+ args = append(args, payload[0])
+ }
+ cmd := NewCmd(args...)
+
+ cn, err := c.conn()
+ if err != nil {
+ return err
+ }
+
+ cn.SetWriteTimeout(c.opt.WriteTimeout)
+ err = writeCmd(cn, cmd)
+ c.releaseConn(cn, err)
+ return err
+}
+
+// Subscription received after a successful subscription to channel.
+type Subscription struct {
+ // Can be "subscribe", "unsubscribe", "psubscribe" or "punsubscribe".
+ Kind string
+ // Channel name we have subscribed to.
+ Channel string
+ // Number of channels we are currently subscribed to.
+ Count int
+}
+
+func (m *Subscription) String() string {
+ return fmt.Sprintf("%s: %s", m.Kind, m.Channel)
+}
+
+// Message received as result of a PUBLISH command issued by another client.
+type Message struct {
+ Channel string
+ Pattern string
+ Payload string
+}
+
+func (m *Message) String() string {
+ return fmt.Sprintf("Message<%s: %s>", m.Channel, m.Payload)
+}
+
+// Pong received as result of a PING command issued by another client.
+type Pong struct {
+ Payload string
+}
+
+func (p *Pong) String() string {
+ if p.Payload != "" {
+ return fmt.Sprintf("Pong<%s>", p.Payload)
+ }
+ return "Pong"
+}
+
+func (c *PubSub) newMessage(reply interface{}) (interface{}, error) {
+ switch reply := reply.(type) {
+ case string:
+ return &Pong{
+ Payload: reply,
+ }, nil
+ case []interface{}:
+ switch kind := reply[0].(string); kind {
+ case "subscribe", "unsubscribe", "psubscribe", "punsubscribe":
+ return &Subscription{
+ Kind: kind,
+ Channel: reply[1].(string),
+ Count: int(reply[2].(int64)),
+ }, nil
+ case "message":
+ return &Message{
+ Channel: reply[1].(string),
+ Payload: reply[2].(string),
+ }, nil
+ case "pmessage":
+ return &Message{
+ Pattern: reply[1].(string),
+ Channel: reply[2].(string),
+ Payload: reply[3].(string),
+ }, nil
+ case "pong":
+ return &Pong{
+ Payload: reply[1].(string),
+ }, nil
+ default:
+ return nil, fmt.Errorf("redis: unsupported pubsub message: %q", kind)
+ }
+ default:
+ return nil, fmt.Errorf("redis: unsupported pubsub message: %#v", reply)
+ }
+}
+
+// ReceiveTimeout acts like Receive but returns an error if message
+// is not received in time. This is low-level API and in most cases
+// Channel should be used instead.
+func (c *PubSub) ReceiveTimeout(timeout time.Duration) (interface{}, error) {
+ if c.cmd == nil {
+ c.cmd = NewCmd()
+ }
+
+ cn, err := c.conn()
+ if err != nil {
+ return nil, err
+ }
+
+ cn.SetReadTimeout(timeout)
+ err = c.cmd.readReply(cn)
+ c.releaseConn(cn, err)
+ if err != nil {
+ return nil, err
+ }
+
+ return c.newMessage(c.cmd.Val())
+}
+
+// Receive returns a message as a Subscription, Message, Pong or error.
+// See PubSub example for details. This is low-level API and in most cases
+// Channel should be used instead.
+func (c *PubSub) Receive() (interface{}, error) {
+ return c.ReceiveTimeout(0)
+}
+
+// ReceiveMessage returns a Message or error ignoring Subscription and Pong
+// messages. This is low-level API and in most cases Channel should be used
+// instead.
+func (c *PubSub) ReceiveMessage() (*Message, error) {
+ for {
+ msg, err := c.Receive()
+ if err != nil {
+ return nil, err
+ }
+
+ switch msg := msg.(type) {
+ case *Subscription:
+ // Ignore.
+ case *Pong:
+ // Ignore.
+ case *Message:
+ return msg, nil
+ default:
+ err := fmt.Errorf("redis: unknown message: %T", msg)
+ return nil, err
+ }
+ }
+}
+
+// Channel returns a Go channel for concurrently receiving messages.
+// It periodically sends Ping messages to test connection health.
+// The channel is closed with PubSub. Receive* APIs can not be used
+// after channel is created.
+func (c *PubSub) Channel() <-chan *Message {
+ c.chOnce.Do(c.initChannel)
+ return c.ch
+}
+
+func (c *PubSub) initChannel() {
+ c.ch = make(chan *Message, 100)
+ c.ping = make(chan struct{}, 10)
+
+ go func() {
+ var errCount int
+ for {
+ msg, err := c.Receive()
+ if err != nil {
+ if err == pool.ErrClosed {
+ close(c.ch)
+ return
+ }
+ if errCount > 0 {
+ time.Sleep(c.retryBackoff(errCount))
+ }
+ errCount++
+ continue
+ }
+ errCount = 0
+
+ // Any message is as good as a ping.
+ select {
+ case c.ping <- struct{}{}:
+ default:
+ }
+
+ switch msg := msg.(type) {
+ case *Subscription:
+ // Ignore.
+ case *Pong:
+ // Ignore.
+ case *Message:
+ c.ch <- msg
+ default:
+ internal.Logf("redis: unknown message: %T", msg)
+ }
+ }
+ }()
+
+ go func() {
+ const timeout = 5 * time.Second
+
+ timer := time.NewTimer(timeout)
+ timer.Stop()
+
+ var hasPing bool
+ for {
+ timer.Reset(timeout)
+ select {
+ case <-c.ping:
+ hasPing = true
+ if !timer.Stop() {
+ <-timer.C
+ }
+ case <-timer.C:
+ if hasPing {
+ hasPing = false
+ _ = c.Ping()
+ } else {
+ c.reconnect()
+ }
+ case <-c.exit:
+ return
+ }
+ }
+ }()
+}
+
+func (c *PubSub) retryBackoff(attempt int) time.Duration {
+ return internal.RetryBackoff(attempt, c.opt.MinRetryBackoff, c.opt.MaxRetryBackoff)
+}
diff --git a/src/dma/vendor/github.com/go-redis/redis/redis.go b/src/dma/vendor/github.com/go-redis/redis/redis.go
new file mode 100644
index 00000000..c0f142cc
--- /dev/null
+++ b/src/dma/vendor/github.com/go-redis/redis/redis.go
@@ -0,0 +1,501 @@
+package redis
+
+import (
+ "context"
+ "fmt"
+ "log"
+ "os"
+ "time"
+
+ "github.com/go-redis/redis/internal"
+ "github.com/go-redis/redis/internal/pool"
+ "github.com/go-redis/redis/internal/proto"
+)
+
+// Nil reply Redis returns when key does not exist.
+const Nil = proto.Nil
+
+func init() {
+ SetLogger(log.New(os.Stderr, "redis: ", log.LstdFlags|log.Lshortfile))
+}
+
+func SetLogger(logger *log.Logger) {
+ internal.Logger = logger
+}
+
+type baseClient struct {
+ opt *Options
+ connPool pool.Pooler
+
+ process func(Cmder) error
+ processPipeline func([]Cmder) error
+ processTxPipeline func([]Cmder) error
+
+ onClose func() error // hook called when client is closed
+}
+
+func (c *baseClient) init() {
+ c.process = c.defaultProcess
+ c.processPipeline = c.defaultProcessPipeline
+ c.processTxPipeline = c.defaultProcessTxPipeline
+}
+
+func (c *baseClient) String() string {
+ return fmt.Sprintf("Redis<%s db:%d>", c.getAddr(), c.opt.DB)
+}
+
+func (c *baseClient) newConn() (*pool.Conn, error) {
+ cn, err := c.connPool.NewConn()
+ if err != nil {
+ return nil, err
+ }
+
+ if !cn.Inited {
+ if err := c.initConn(cn); err != nil {
+ _ = c.connPool.CloseConn(cn)
+ return nil, err
+ }
+ }
+
+ return cn, nil
+}
+
+func (c *baseClient) getConn() (*pool.Conn, error) {
+ cn, err := c.connPool.Get()
+ if err != nil {
+ return nil, err
+ }
+
+ if !cn.Inited {
+ err := c.initConn(cn)
+ if err != nil {
+ c.connPool.Remove(cn)
+ return nil, err
+ }
+ }
+
+ return cn, nil
+}
+
+func (c *baseClient) releaseConn(cn *pool.Conn, err error) bool {
+ if internal.IsBadConn(err, false) {
+ c.connPool.Remove(cn)
+ return false
+ }
+
+ c.connPool.Put(cn)
+ return true
+}
+
+func (c *baseClient) initConn(cn *pool.Conn) error {
+ cn.Inited = true
+
+ if c.opt.Password == "" &&
+ c.opt.DB == 0 &&
+ !c.opt.readOnly &&
+ c.opt.OnConnect == nil {
+ return nil
+ }
+
+ conn := newConn(c.opt, cn)
+ _, err := conn.Pipelined(func(pipe Pipeliner) error {
+ if c.opt.Password != "" {
+ pipe.Auth(c.opt.Password)
+ }
+
+ if c.opt.DB > 0 {
+ pipe.Select(c.opt.DB)
+ }
+
+ if c.opt.readOnly {
+ pipe.ReadOnly()
+ }
+
+ return nil
+ })
+ if err != nil {
+ return err
+ }
+
+ if c.opt.OnConnect != nil {
+ return c.opt.OnConnect(conn)
+ }
+ return nil
+}
+
+// WrapProcess wraps function that processes Redis commands.
+func (c *baseClient) WrapProcess(fn func(oldProcess func(cmd Cmder) error) func(cmd Cmder) error) {
+ c.process = fn(c.process)
+}
+
+func (c *baseClient) Process(cmd Cmder) error {
+ return c.process(cmd)
+}
+
+func (c *baseClient) defaultProcess(cmd Cmder) error {
+ for attempt := 0; attempt <= c.opt.MaxRetries; attempt++ {
+ if attempt > 0 {
+ time.Sleep(c.retryBackoff(attempt))
+ }
+
+ cn, err := c.getConn()
+ if err != nil {
+ cmd.setErr(err)
+ if internal.IsRetryableError(err, true) {
+ continue
+ }
+ return err
+ }
+
+ cn.SetWriteTimeout(c.opt.WriteTimeout)
+ if err := writeCmd(cn, cmd); err != nil {
+ c.releaseConn(cn, err)
+ cmd.setErr(err)
+ if internal.IsRetryableError(err, true) {
+ continue
+ }
+ return err
+ }
+
+ cn.SetReadTimeout(c.cmdTimeout(cmd))
+ err = cmd.readReply(cn)
+ c.releaseConn(cn, err)
+ if err != nil && internal.IsRetryableError(err, cmd.readTimeout() == nil) {
+ continue
+ }
+
+ return err
+ }
+
+ return cmd.Err()
+}
+
+func (c *baseClient) retryBackoff(attempt int) time.Duration {
+ return internal.RetryBackoff(attempt, c.opt.MinRetryBackoff, c.opt.MaxRetryBackoff)
+}
+
+func (c *baseClient) cmdTimeout(cmd Cmder) time.Duration {
+ if timeout := cmd.readTimeout(); timeout != nil {
+ return readTimeout(*timeout)
+ }
+ return c.opt.ReadTimeout
+}
+
+// Close closes the client, releasing any open resources.
+//
+// It is rare to Close a Client, as the Client is meant to be
+// long-lived and shared between many goroutines.
+func (c *baseClient) Close() error {
+ var firstErr error
+ if c.onClose != nil {
+ if err := c.onClose(); err != nil && firstErr == nil {
+ firstErr = err
+ }
+ }
+ if err := c.connPool.Close(); err != nil && firstErr == nil {
+ firstErr = err
+ }
+ return firstErr
+}
+
+func (c *baseClient) getAddr() string {
+ return c.opt.Addr
+}
+
+func (c *baseClient) WrapProcessPipeline(
+ fn func(oldProcess func([]Cmder) error) func([]Cmder) error,
+) {
+ c.processPipeline = fn(c.processPipeline)
+ c.processTxPipeline = fn(c.processTxPipeline)
+}
+
+func (c *baseClient) defaultProcessPipeline(cmds []Cmder) error {
+ return c.generalProcessPipeline(cmds, c.pipelineProcessCmds)
+}
+
+func (c *baseClient) defaultProcessTxPipeline(cmds []Cmder) error {
+ return c.generalProcessPipeline(cmds, c.txPipelineProcessCmds)
+}
+
+type pipelineProcessor func(*pool.Conn, []Cmder) (bool, error)
+
+func (c *baseClient) generalProcessPipeline(cmds []Cmder, p pipelineProcessor) error {
+ for attempt := 0; attempt <= c.opt.MaxRetries; attempt++ {
+ if attempt > 0 {
+ time.Sleep(c.retryBackoff(attempt))
+ }
+
+ cn, err := c.getConn()
+ if err != nil {
+ setCmdsErr(cmds, err)
+ return err
+ }
+
+ canRetry, err := p(cn, cmds)
+
+ if err == nil || internal.IsRedisError(err) {
+ c.connPool.Put(cn)
+ break
+ }
+ c.connPool.Remove(cn)
+
+ if !canRetry || !internal.IsRetryableError(err, true) {
+ break
+ }
+ }
+ return firstCmdsErr(cmds)
+}
+
+func (c *baseClient) pipelineProcessCmds(cn *pool.Conn, cmds []Cmder) (bool, error) {
+ cn.SetWriteTimeout(c.opt.WriteTimeout)
+ if err := writeCmd(cn, cmds...); err != nil {
+ setCmdsErr(cmds, err)
+ return true, err
+ }
+
+ // Set read timeout for all commands.
+ cn.SetReadTimeout(c.opt.ReadTimeout)
+ return true, pipelineReadCmds(cn, cmds)
+}
+
+func pipelineReadCmds(cn *pool.Conn, cmds []Cmder) error {
+ for _, cmd := range cmds {
+ err := cmd.readReply(cn)
+ if err != nil && !internal.IsRedisError(err) {
+ return err
+ }
+ }
+ return nil
+}
+
+func (c *baseClient) txPipelineProcessCmds(cn *pool.Conn, cmds []Cmder) (bool, error) {
+ cn.SetWriteTimeout(c.opt.WriteTimeout)
+ if err := txPipelineWriteMulti(cn, cmds); err != nil {
+ setCmdsErr(cmds, err)
+ return true, err
+ }
+
+ // Set read timeout for all commands.
+ cn.SetReadTimeout(c.opt.ReadTimeout)
+
+ if err := c.txPipelineReadQueued(cn, cmds); err != nil {
+ setCmdsErr(cmds, err)
+ return false, err
+ }
+
+ return false, pipelineReadCmds(cn, cmds)
+}
+
+func txPipelineWriteMulti(cn *pool.Conn, cmds []Cmder) error {
+ multiExec := make([]Cmder, 0, len(cmds)+2)
+ multiExec = append(multiExec, NewStatusCmd("MULTI"))
+ multiExec = append(multiExec, cmds...)
+ multiExec = append(multiExec, NewSliceCmd("EXEC"))
+ return writeCmd(cn, multiExec...)
+}
+
+func (c *baseClient) txPipelineReadQueued(cn *pool.Conn, cmds []Cmder) error {
+ // Parse queued replies.
+ var statusCmd StatusCmd
+ if err := statusCmd.readReply(cn); err != nil {
+ return err
+ }
+
+ for _ = range cmds {
+ err := statusCmd.readReply(cn)
+ if err != nil && !internal.IsRedisError(err) {
+ return err
+ }
+ }
+
+ // Parse number of replies.
+ line, err := cn.Rd.ReadLine()
+ if err != nil {
+ if err == Nil {
+ err = TxFailedErr
+ }
+ return err
+ }
+
+ switch line[0] {
+ case proto.ErrorReply:
+ return proto.ParseErrorReply(line)
+ case proto.ArrayReply:
+ // ok
+ default:
+ err := fmt.Errorf("redis: expected '*', but got line %q", line)
+ return err
+ }
+
+ return nil
+}
+
+//------------------------------------------------------------------------------
+
+// Client is a Redis client representing a pool of zero or more
+// underlying connections. It's safe for concurrent use by multiple
+// goroutines.
+type Client struct {
+ baseClient
+ cmdable
+
+ ctx context.Context
+}
+
+// NewClient returns a client to the Redis Server specified by Options.
+func NewClient(opt *Options) *Client {
+ opt.init()
+
+ c := Client{
+ baseClient: baseClient{
+ opt: opt,
+ connPool: newConnPool(opt),
+ },
+ }
+ c.baseClient.init()
+ c.init()
+
+ return &c
+}
+
+func (c *Client) init() {
+ c.cmdable.setProcessor(c.Process)
+}
+
+func (c *Client) Context() context.Context {
+ if c.ctx != nil {
+ return c.ctx
+ }
+ return context.Background()
+}
+
+func (c *Client) WithContext(ctx context.Context) *Client {
+ if ctx == nil {
+ panic("nil context")
+ }
+ c2 := c.copy()
+ c2.ctx = ctx
+ return c2
+}
+
+func (c *Client) copy() *Client {
+ cp := *c
+ cp.init()
+ return &cp
+}
+
+// Options returns read-only Options that were used to create the client.
+func (c *Client) Options() *Options {
+ return c.opt
+}
+
+type PoolStats pool.Stats
+
+// PoolStats returns connection pool stats.
+func (c *Client) PoolStats() *PoolStats {
+ stats := c.connPool.Stats()
+ return (*PoolStats)(stats)
+}
+
+func (c *Client) Pipelined(fn func(Pipeliner) error) ([]Cmder, error) {
+ return c.Pipeline().Pipelined(fn)
+}
+
+func (c *Client) Pipeline() Pipeliner {
+ pipe := Pipeline{
+ exec: c.processPipeline,
+ }
+ pipe.statefulCmdable.setProcessor(pipe.Process)
+ return &pipe
+}
+
+func (c *Client) TxPipelined(fn func(Pipeliner) error) ([]Cmder, error) {
+ return c.TxPipeline().Pipelined(fn)
+}
+
+// TxPipeline acts like Pipeline, but wraps queued commands with MULTI/EXEC.
+func (c *Client) TxPipeline() Pipeliner {
+ pipe := Pipeline{
+ exec: c.processTxPipeline,
+ }
+ pipe.statefulCmdable.setProcessor(pipe.Process)
+ return &pipe
+}
+
+func (c *Client) pubSub() *PubSub {
+ pubsub := &PubSub{
+ opt: c.opt,
+
+ newConn: func(channels []string) (*pool.Conn, error) {
+ return c.newConn()
+ },
+ closeConn: c.connPool.CloseConn,
+ }
+ pubsub.init()
+ return pubsub
+}
+
+// Subscribe subscribes the client to the specified channels.
+// Channels can be omitted to create empty subscription.
+func (c *Client) Subscribe(channels ...string) *PubSub {
+ pubsub := c.pubSub()
+ if len(channels) > 0 {
+ _ = pubsub.Subscribe(channels...)
+ }
+ return pubsub
+}
+
+// PSubscribe subscribes the client to the given patterns.
+// Patterns can be omitted to create empty subscription.
+func (c *Client) PSubscribe(channels ...string) *PubSub {
+ pubsub := c.pubSub()
+ if len(channels) > 0 {
+ _ = pubsub.PSubscribe(channels...)
+ }
+ return pubsub
+}
+
+//------------------------------------------------------------------------------
+
+// Conn is like Client, but its pool contains single connection.
+type Conn struct {
+ baseClient
+ statefulCmdable
+}
+
+func newConn(opt *Options, cn *pool.Conn) *Conn {
+ c := Conn{
+ baseClient: baseClient{
+ opt: opt,
+ connPool: pool.NewSingleConnPool(cn),
+ },
+ }
+ c.baseClient.init()
+ c.statefulCmdable.setProcessor(c.Process)
+ return &c
+}
+
+func (c *Conn) Pipelined(fn func(Pipeliner) error) ([]Cmder, error) {
+ return c.Pipeline().Pipelined(fn)
+}
+
+func (c *Conn) Pipeline() Pipeliner {
+ pipe := Pipeline{
+ exec: c.processPipeline,
+ }
+ pipe.statefulCmdable.setProcessor(pipe.Process)
+ return &pipe
+}
+
+func (c *Conn) TxPipelined(fn func(Pipeliner) error) ([]Cmder, error) {
+ return c.TxPipeline().Pipelined(fn)
+}
+
+// TxPipeline acts like Pipeline, but wraps queued commands with MULTI/EXEC.
+func (c *Conn) TxPipeline() Pipeliner {
+ pipe := Pipeline{
+ exec: c.processTxPipeline,
+ }
+ pipe.statefulCmdable.setProcessor(pipe.Process)
+ return &pipe
+}
diff --git a/src/dma/vendor/github.com/go-redis/redis/result.go b/src/dma/vendor/github.com/go-redis/redis/result.go
new file mode 100644
index 00000000..e086e8e3
--- /dev/null
+++ b/src/dma/vendor/github.com/go-redis/redis/result.go
@@ -0,0 +1,140 @@
+package redis
+
+import "time"
+
+// NewCmdResult returns a Cmd initialised with val and err for testing
+func NewCmdResult(val interface{}, err error) *Cmd {
+ var cmd Cmd
+ cmd.val = val
+ cmd.setErr(err)
+ return &cmd
+}
+
+// NewSliceResult returns a SliceCmd initialised with val and err for testing
+func NewSliceResult(val []interface{}, err error) *SliceCmd {
+ var cmd SliceCmd
+ cmd.val = val
+ cmd.setErr(err)
+ return &cmd
+}
+
+// NewStatusResult returns a StatusCmd initialised with val and err for testing
+func NewStatusResult(val string, err error) *StatusCmd {
+ var cmd StatusCmd
+ cmd.val = val
+ cmd.setErr(err)
+ return &cmd
+}
+
+// NewIntResult returns an IntCmd initialised with val and err for testing
+func NewIntResult(val int64, err error) *IntCmd {
+ var cmd IntCmd
+ cmd.val = val
+ cmd.setErr(err)
+ return &cmd
+}
+
+// NewDurationResult returns a DurationCmd initialised with val and err for testing
+func NewDurationResult(val time.Duration, err error) *DurationCmd {
+ var cmd DurationCmd
+ cmd.val = val
+ cmd.setErr(err)
+ return &cmd
+}
+
+// NewBoolResult returns a BoolCmd initialised with val and err for testing
+func NewBoolResult(val bool, err error) *BoolCmd {
+ var cmd BoolCmd
+ cmd.val = val
+ cmd.setErr(err)
+ return &cmd
+}
+
+// NewStringResult returns a StringCmd initialised with val and err for testing
+func NewStringResult(val string, err error) *StringCmd {
+ var cmd StringCmd
+ cmd.val = []byte(val)
+ cmd.setErr(err)
+ return &cmd
+}
+
+// NewFloatResult returns a FloatCmd initialised with val and err for testing
+func NewFloatResult(val float64, err error) *FloatCmd {
+ var cmd FloatCmd
+ cmd.val = val
+ cmd.setErr(err)
+ return &cmd
+}
+
+// NewStringSliceResult returns a StringSliceCmd initialised with val and err for testing
+func NewStringSliceResult(val []string, err error) *StringSliceCmd {
+ var cmd StringSliceCmd
+ cmd.val = val
+ cmd.setErr(err)
+ return &cmd
+}
+
+// NewBoolSliceResult returns a BoolSliceCmd initialised with val and err for testing
+func NewBoolSliceResult(val []bool, err error) *BoolSliceCmd {
+ var cmd BoolSliceCmd
+ cmd.val = val
+ cmd.setErr(err)
+ return &cmd
+}
+
+// NewStringStringMapResult returns a StringStringMapCmd initialised with val and err for testing
+func NewStringStringMapResult(val map[string]string, err error) *StringStringMapCmd {
+ var cmd StringStringMapCmd
+ cmd.val = val
+ cmd.setErr(err)
+ return &cmd
+}
+
+// NewStringIntMapCmdResult returns a StringIntMapCmd initialised with val and err for testing
+func NewStringIntMapCmdResult(val map[string]int64, err error) *StringIntMapCmd {
+ var cmd StringIntMapCmd
+ cmd.val = val
+ cmd.setErr(err)
+ return &cmd
+}
+
+// NewZSliceCmdResult returns a ZSliceCmd initialised with val and err for testing
+func NewZSliceCmdResult(val []Z, err error) *ZSliceCmd {
+ var cmd ZSliceCmd
+ cmd.val = val
+ cmd.setErr(err)
+ return &cmd
+}
+
+// NewScanCmdResult returns a ScanCmd initialised with val and err for testing
+func NewScanCmdResult(keys []string, cursor uint64, err error) *ScanCmd {
+ var cmd ScanCmd
+ cmd.page = keys
+ cmd.cursor = cursor
+ cmd.setErr(err)
+ return &cmd
+}
+
+// NewClusterSlotsCmdResult returns a ClusterSlotsCmd initialised with val and err for testing
+func NewClusterSlotsCmdResult(val []ClusterSlot, err error) *ClusterSlotsCmd {
+ var cmd ClusterSlotsCmd
+ cmd.val = val
+ cmd.setErr(err)
+ return &cmd
+}
+
+// NewGeoLocationCmdResult returns a GeoLocationCmd initialised with val and err for testing
+func NewGeoLocationCmdResult(val []GeoLocation, err error) *GeoLocationCmd {
+ var cmd GeoLocationCmd
+ cmd.locations = val
+ cmd.setErr(err)
+ return &cmd
+}
+
+// NewCommandsInfoCmdResult returns a CommandsInfoCmd initialised with val and err for testing
+func NewCommandsInfoCmdResult(val map[string]*CommandInfo, err error) *CommandsInfoCmd {
+ var cmd CommandsInfoCmd
+ cmd.val = val
+ cmd.setErr(err)
+ return &cmd
+}
diff --git a/src/dma/vendor/github.com/go-redis/redis/ring.go b/src/dma/vendor/github.com/go-redis/redis/ring.go
new file mode 100644
index 00000000..ef855115
--- /dev/null
+++ b/src/dma/vendor/github.com/go-redis/redis/ring.go
@@ -0,0 +1,622 @@
+package redis
+
+import (
+ "context"
+ "errors"
+ "fmt"
+ "math/rand"
+ "strconv"
+ "sync"
+ "sync/atomic"
+ "time"
+
+ "github.com/go-redis/redis/internal"
+ "github.com/go-redis/redis/internal/consistenthash"
+ "github.com/go-redis/redis/internal/hashtag"
+ "github.com/go-redis/redis/internal/pool"
+)
+
+// Hash is type of hash function used in consistent hash.
+type Hash consistenthash.Hash
+
+var errRingShardsDown = errors.New("redis: all ring shards are down")
+
+// RingOptions are used to configure a ring client and should be
+// passed to NewRing.
+type RingOptions struct {
+ // Map of name => host:port addresses of ring shards.
+ Addrs map[string]string
+
+ // Frequency of PING commands sent to check shards availability.
+ // Shard is considered down after 3 subsequent failed checks.
+ HeartbeatFrequency time.Duration
+
+ // Hash function used in consistent hash.
+ // Default is crc32.ChecksumIEEE.
+ Hash Hash
+
+ // Number of replicas in consistent hash.
+ // Default is 100 replicas.
+ //
+ // Higher number of replicas will provide less deviation, that is keys will be
+ // distributed to nodes more evenly.
+ //
+ // Following is deviation for common nreplicas:
+ // --------------------------------------------------------
+ // | nreplicas | standard error | 99% confidence interval |
+ // | 10 | 0.3152 | (0.37, 1.98) |
+ // | 100 | 0.0997 | (0.76, 1.28) |
+ // | 1000 | 0.0316 | (0.92, 1.09) |
+ // --------------------------------------------------------
+ //
+ // See https://arxiv.org/abs/1406.2294 for reference
+ HashReplicas int
+
+ // Following options are copied from Options struct.
+
+ OnConnect func(*Conn) error
+
+ DB int
+ Password string
+
+ MaxRetries int
+ MinRetryBackoff time.Duration
+ MaxRetryBackoff time.Duration
+
+ DialTimeout time.Duration
+ ReadTimeout time.Duration
+ WriteTimeout time.Duration
+
+ PoolSize int
+ PoolTimeout time.Duration
+ IdleTimeout time.Duration
+ IdleCheckFrequency time.Duration
+}
+
+func (opt *RingOptions) init() {
+ if opt.HeartbeatFrequency == 0 {
+ opt.HeartbeatFrequency = 500 * time.Millisecond
+ }
+
+ if opt.HashReplicas == 0 {
+ opt.HashReplicas = 100
+ }
+
+ switch opt.MinRetryBackoff {
+ case -1:
+ opt.MinRetryBackoff = 0
+ case 0:
+ opt.MinRetryBackoff = 8 * time.Millisecond
+ }
+ switch opt.MaxRetryBackoff {
+ case -1:
+ opt.MaxRetryBackoff = 0
+ case 0:
+ opt.MaxRetryBackoff = 512 * time.Millisecond
+ }
+}
+
+func (opt *RingOptions) clientOptions() *Options {
+ return &Options{
+ OnConnect: opt.OnConnect,
+
+ DB: opt.DB,
+ Password: opt.Password,
+
+ DialTimeout: opt.DialTimeout,
+ ReadTimeout: opt.ReadTimeout,
+ WriteTimeout: opt.WriteTimeout,
+
+ PoolSize: opt.PoolSize,
+ PoolTimeout: opt.PoolTimeout,
+ IdleTimeout: opt.IdleTimeout,
+ IdleCheckFrequency: opt.IdleCheckFrequency,
+ }
+}
+
+//------------------------------------------------------------------------------
+
+type ringShard struct {
+ Client *Client
+ down int32
+}
+
+func (shard *ringShard) String() string {
+ var state string
+ if shard.IsUp() {
+ state = "up"
+ } else {
+ state = "down"
+ }
+ return fmt.Sprintf("%s is %s", shard.Client, state)
+}
+
+func (shard *ringShard) IsDown() bool {
+ const threshold = 3
+ return atomic.LoadInt32(&shard.down) >= threshold
+}
+
+func (shard *ringShard) IsUp() bool {
+ return !shard.IsDown()
+}
+
+// Vote votes to set shard state and returns true if state was changed.
+func (shard *ringShard) Vote(up bool) bool {
+ if up {
+ changed := shard.IsDown()
+ atomic.StoreInt32(&shard.down, 0)
+ return changed
+ }
+
+ if shard.IsDown() {
+ return false
+ }
+
+ atomic.AddInt32(&shard.down, 1)
+ return shard.IsDown()
+}
+
+//------------------------------------------------------------------------------
+
+type ringShards struct {
+ opt *RingOptions
+
+ mu sync.RWMutex
+ hash *consistenthash.Map
+ shards map[string]*ringShard // read only
+ list []*ringShard // read only
+ len int
+ closed bool
+}
+
+func newRingShards(opt *RingOptions) *ringShards {
+ return &ringShards{
+ opt: opt,
+
+ hash: newConsistentHash(opt),
+ shards: make(map[string]*ringShard),
+ }
+}
+
+func (c *ringShards) Add(name string, cl *Client) {
+ shard := &ringShard{Client: cl}
+ c.hash.Add(name)
+ c.shards[name] = shard
+ c.list = append(c.list, shard)
+}
+
+func (c *ringShards) List() []*ringShard {
+ c.mu.RLock()
+ list := c.list
+ c.mu.RUnlock()
+ return list
+}
+
+func (c *ringShards) Hash(key string) string {
+ c.mu.RLock()
+ hash := c.hash.Get(key)
+ c.mu.RUnlock()
+ return hash
+}
+
+func (c *ringShards) GetByKey(key string) (*ringShard, error) {
+ key = hashtag.Key(key)
+
+ c.mu.RLock()
+
+ if c.closed {
+ c.mu.RUnlock()
+ return nil, pool.ErrClosed
+ }
+
+ hash := c.hash.Get(key)
+ if hash == "" {
+ c.mu.RUnlock()
+ return nil, errRingShardsDown
+ }
+
+ shard := c.shards[hash]
+ c.mu.RUnlock()
+
+ return shard, nil
+}
+
+func (c *ringShards) GetByHash(name string) (*ringShard, error) {
+ if name == "" {
+ return c.Random()
+ }
+
+ c.mu.RLock()
+ shard := c.shards[name]
+ c.mu.RUnlock()
+ return shard, nil
+}
+
+func (c *ringShards) Random() (*ringShard, error) {
+ return c.GetByKey(strconv.Itoa(rand.Int()))
+}
+
+// heartbeat monitors state of each shard in the ring.
+func (c *ringShards) Heartbeat(frequency time.Duration) {
+ ticker := time.NewTicker(frequency)
+ defer ticker.Stop()
+ for range ticker.C {
+ var rebalance bool
+
+ c.mu.RLock()
+
+ if c.closed {
+ c.mu.RUnlock()
+ break
+ }
+
+ shards := c.list
+ c.mu.RUnlock()
+
+ for _, shard := range shards {
+ err := shard.Client.Ping().Err()
+ if shard.Vote(err == nil || err == pool.ErrPoolTimeout) {
+ internal.Logf("ring shard state changed: %s", shard)
+ rebalance = true
+ }
+ }
+
+ if rebalance {
+ c.rebalance()
+ }
+ }
+}
+
+// rebalance removes dead shards from the Ring.
+func (c *ringShards) rebalance() {
+ hash := newConsistentHash(c.opt)
+ var shardsNum int
+ for name, shard := range c.shards {
+ if shard.IsUp() {
+ hash.Add(name)
+ shardsNum++
+ }
+ }
+
+ c.mu.Lock()
+ c.hash = hash
+ c.len = shardsNum
+ c.mu.Unlock()
+}
+
+func (c *ringShards) Len() int {
+ c.mu.RLock()
+ l := c.len
+ c.mu.RUnlock()
+ return l
+}
+
+func (c *ringShards) Close() error {
+ c.mu.Lock()
+ defer c.mu.Unlock()
+
+ if c.closed {
+ return nil
+ }
+ c.closed = true
+
+ var firstErr error
+ for _, shard := range c.shards {
+ if err := shard.Client.Close(); err != nil && firstErr == nil {
+ firstErr = err
+ }
+ }
+ c.hash = nil
+ c.shards = nil
+ c.list = nil
+
+ return firstErr
+}
+
+//------------------------------------------------------------------------------
+
+// Ring is a Redis client that uses constistent hashing to distribute
+// keys across multiple Redis servers (shards). It's safe for
+// concurrent use by multiple goroutines.
+//
+// Ring monitors the state of each shard and removes dead shards from
+// the ring. When shard comes online it is added back to the ring. This
+// gives you maximum availability and partition tolerance, but no
+// consistency between different shards or even clients. Each client
+// uses shards that are available to the client and does not do any
+// coordination when shard state is changed.
+//
+// Ring should be used when you need multiple Redis servers for caching
+// and can tolerate losing data when one of the servers dies.
+// Otherwise you should use Redis Cluster.
+type Ring struct {
+ cmdable
+
+ ctx context.Context
+
+ opt *RingOptions
+ shards *ringShards
+ cmdsInfoCache *cmdsInfoCache
+
+ processPipeline func([]Cmder) error
+}
+
+func NewRing(opt *RingOptions) *Ring {
+ opt.init()
+
+ ring := &Ring{
+ opt: opt,
+ shards: newRingShards(opt),
+ }
+ ring.cmdsInfoCache = newCmdsInfoCache(ring.cmdsInfo)
+
+ ring.processPipeline = ring.defaultProcessPipeline
+ ring.cmdable.setProcessor(ring.Process)
+
+ for name, addr := range opt.Addrs {
+ clopt := opt.clientOptions()
+ clopt.Addr = addr
+ ring.shards.Add(name, NewClient(clopt))
+ }
+
+ go ring.shards.Heartbeat(opt.HeartbeatFrequency)
+
+ return ring
+}
+
+func (c *Ring) Context() context.Context {
+ if c.ctx != nil {
+ return c.ctx
+ }
+ return context.Background()
+}
+
+func (c *Ring) WithContext(ctx context.Context) *Ring {
+ if ctx == nil {
+ panic("nil context")
+ }
+ c2 := c.copy()
+ c2.ctx = ctx
+ return c2
+}
+
+func (c *Ring) copy() *Ring {
+ cp := *c
+ return &cp
+}
+
+// Options returns read-only Options that were used to create the client.
+func (c *Ring) Options() *RingOptions {
+ return c.opt
+}
+
+func (c *Ring) retryBackoff(attempt int) time.Duration {
+ return internal.RetryBackoff(attempt, c.opt.MinRetryBackoff, c.opt.MaxRetryBackoff)
+}
+
+// PoolStats returns accumulated connection pool stats.
+func (c *Ring) PoolStats() *PoolStats {
+ shards := c.shards.List()
+ var acc PoolStats
+ for _, shard := range shards {
+ s := shard.Client.connPool.Stats()
+ acc.Hits += s.Hits
+ acc.Misses += s.Misses
+ acc.Timeouts += s.Timeouts
+ acc.TotalConns += s.TotalConns
+ acc.FreeConns += s.FreeConns
+ }
+ return &acc
+}
+
+// Len returns the current number of shards in the ring.
+func (c *Ring) Len() int {
+ return c.shards.Len()
+}
+
+// Subscribe subscribes the client to the specified channels.
+func (c *Ring) Subscribe(channels ...string) *PubSub {
+ if len(channels) == 0 {
+ panic("at least one channel is required")
+ }
+
+ shard, err := c.shards.GetByKey(channels[0])
+ if err != nil {
+ // TODO: return PubSub with sticky error
+ panic(err)
+ }
+ return shard.Client.Subscribe(channels...)
+}
+
+// PSubscribe subscribes the client to the given patterns.
+func (c *Ring) PSubscribe(channels ...string) *PubSub {
+ if len(channels) == 0 {
+ panic("at least one channel is required")
+ }
+
+ shard, err := c.shards.GetByKey(channels[0])
+ if err != nil {
+ // TODO: return PubSub with sticky error
+ panic(err)
+ }
+ return shard.Client.PSubscribe(channels...)
+}
+
+// ForEachShard concurrently calls the fn on each live shard in the ring.
+// It returns the first error if any.
+func (c *Ring) ForEachShard(fn func(client *Client) error) error {
+ shards := c.shards.List()
+ var wg sync.WaitGroup
+ errCh := make(chan error, 1)
+ for _, shard := range shards {
+ if shard.IsDown() {
+ continue
+ }
+
+ wg.Add(1)
+ go func(shard *ringShard) {
+ defer wg.Done()
+ err := fn(shard.Client)
+ if err != nil {
+ select {
+ case errCh <- err:
+ default:
+ }
+ }
+ }(shard)
+ }
+ wg.Wait()
+
+ select {
+ case err := <-errCh:
+ return err
+ default:
+ return nil
+ }
+}
+
+func (c *Ring) cmdsInfo() (map[string]*CommandInfo, error) {
+ shards := c.shards.List()
+ firstErr := errRingShardsDown
+ for _, shard := range shards {
+ cmdsInfo, err := shard.Client.Command().Result()
+ if err == nil {
+ return cmdsInfo, nil
+ }
+ if firstErr == nil {
+ firstErr = err
+ }
+ }
+ return nil, firstErr
+}
+
+func (c *Ring) cmdInfo(name string) *CommandInfo {
+ cmdsInfo, err := c.cmdsInfoCache.Get()
+ if err != nil {
+ return nil
+ }
+ info := cmdsInfo[name]
+ if info == nil {
+ internal.Logf("info for cmd=%s not found", name)
+ }
+ return info
+}
+
+func (c *Ring) cmdShard(cmd Cmder) (*ringShard, error) {
+ cmdInfo := c.cmdInfo(cmd.Name())
+ pos := cmdFirstKeyPos(cmd, cmdInfo)
+ if pos == 0 {
+ return c.shards.Random()
+ }
+ firstKey := cmd.stringArg(pos)
+ return c.shards.GetByKey(firstKey)
+}
+
+func (c *Ring) WrapProcess(fn func(oldProcess func(cmd Cmder) error) func(cmd Cmder) error) {
+ c.ForEachShard(func(c *Client) error {
+ c.WrapProcess(fn)
+ return nil
+ })
+}
+
+func (c *Ring) Process(cmd Cmder) error {
+ shard, err := c.cmdShard(cmd)
+ if err != nil {
+ cmd.setErr(err)
+ return err
+ }
+ return shard.Client.Process(cmd)
+}
+
+func (c *Ring) Pipeline() Pipeliner {
+ pipe := Pipeline{
+ exec: c.processPipeline,
+ }
+ pipe.cmdable.setProcessor(pipe.Process)
+ return &pipe
+}
+
+func (c *Ring) Pipelined(fn func(Pipeliner) error) ([]Cmder, error) {
+ return c.Pipeline().Pipelined(fn)
+}
+
+func (c *Ring) WrapProcessPipeline(
+ fn func(oldProcess func([]Cmder) error) func([]Cmder) error,
+) {
+ c.processPipeline = fn(c.processPipeline)
+}
+
+func (c *Ring) defaultProcessPipeline(cmds []Cmder) error {
+ cmdsMap := make(map[string][]Cmder)
+ for _, cmd := range cmds {
+ cmdInfo := c.cmdInfo(cmd.Name())
+ hash := cmd.stringArg(cmdFirstKeyPos(cmd, cmdInfo))
+ if hash != "" {
+ hash = c.shards.Hash(hashtag.Key(hash))
+ }
+ cmdsMap[hash] = append(cmdsMap[hash], cmd)
+ }
+
+ for attempt := 0; attempt <= c.opt.MaxRetries; attempt++ {
+ if attempt > 0 {
+ time.Sleep(c.retryBackoff(attempt))
+ }
+
+ var failedCmdsMap map[string][]Cmder
+
+ for hash, cmds := range cmdsMap {
+ shard, err := c.shards.GetByHash(hash)
+ if err != nil {
+ setCmdsErr(cmds, err)
+ continue
+ }
+
+ cn, err := shard.Client.getConn()
+ if err != nil {
+ setCmdsErr(cmds, err)
+ continue
+ }
+
+ canRetry, err := shard.Client.pipelineProcessCmds(cn, cmds)
+ if err == nil || internal.IsRedisError(err) {
+ shard.Client.connPool.Put(cn)
+ continue
+ }
+ shard.Client.connPool.Remove(cn)
+
+ if canRetry && internal.IsRetryableError(err, true) {
+ if failedCmdsMap == nil {
+ failedCmdsMap = make(map[string][]Cmder)
+ }
+ failedCmdsMap[hash] = cmds
+ }
+ }
+
+ if len(failedCmdsMap) == 0 {
+ break
+ }
+ cmdsMap = failedCmdsMap
+ }
+
+ return firstCmdsErr(cmds)
+}
+
+func (c *Ring) TxPipeline() Pipeliner {
+ panic("not implemented")
+}
+
+func (c *Ring) TxPipelined(fn func(Pipeliner) error) ([]Cmder, error) {
+ panic("not implemented")
+}
+
+// Close closes the ring client, releasing any open resources.
+//
+// It is rare to Close a Ring, as the Ring is meant to be long-lived
+// and shared between many goroutines.
+func (c *Ring) Close() error {
+ return c.shards.Close()
+}
+
+func newConsistentHash(opt *RingOptions) *consistenthash.Map {
+ return consistenthash.New(opt.HashReplicas, consistenthash.Hash(opt.Hash))
+}
diff --git a/src/dma/vendor/github.com/go-redis/redis/script.go b/src/dma/vendor/github.com/go-redis/redis/script.go
new file mode 100644
index 00000000..09f36d93
--- /dev/null
+++ b/src/dma/vendor/github.com/go-redis/redis/script.go
@@ -0,0 +1,62 @@
+package redis
+
+import (
+ "crypto/sha1"
+ "encoding/hex"
+ "io"
+ "strings"
+)
+
+type scripter interface {
+ Eval(script string, keys []string, args ...interface{}) *Cmd
+ EvalSha(sha1 string, keys []string, args ...interface{}) *Cmd
+ ScriptExists(hashes ...string) *BoolSliceCmd
+ ScriptLoad(script string) *StringCmd
+}
+
+var _ scripter = (*Client)(nil)
+var _ scripter = (*Ring)(nil)
+var _ scripter = (*ClusterClient)(nil)
+
+type Script struct {
+ src, hash string
+}
+
+func NewScript(src string) *Script {
+ h := sha1.New()
+ io.WriteString(h, src)
+ return &Script{
+ src: src,
+ hash: hex.EncodeToString(h.Sum(nil)),
+ }
+}
+
+func (s *Script) Hash() string {
+ return s.hash
+}
+
+func (s *Script) Load(c scripter) *StringCmd {
+ return c.ScriptLoad(s.src)
+}
+
+func (s *Script) Exists(c scripter) *BoolSliceCmd {
+ return c.ScriptExists(s.hash)
+}
+
+func (s *Script) Eval(c scripter, keys []string, args ...interface{}) *Cmd {
+ return c.Eval(s.src, keys, args...)
+}
+
+func (s *Script) EvalSha(c scripter, keys []string, args ...interface{}) *Cmd {
+ return c.EvalSha(s.hash, keys, args...)
+}
+
+// Run optimistically uses EVALSHA to run the script. If script does not exist
+// it is retried using EVAL.
+func (s *Script) Run(c scripter, keys []string, args ...interface{}) *Cmd {
+ r := s.EvalSha(c, keys, args...)
+ if err := r.Err(); err != nil && strings.HasPrefix(err.Error(), "NOSCRIPT ") {
+ return s.Eval(c, keys, args...)
+ }
+ return r
+}
diff --git a/src/dma/vendor/github.com/go-redis/redis/sentinel.go b/src/dma/vendor/github.com/go-redis/redis/sentinel.go
new file mode 100644
index 00000000..12c29a71
--- /dev/null
+++ b/src/dma/vendor/github.com/go-redis/redis/sentinel.go
@@ -0,0 +1,343 @@
+package redis
+
+import (
+ "crypto/tls"
+ "errors"
+ "net"
+ "strings"
+ "sync"
+ "time"
+
+ "github.com/go-redis/redis/internal"
+ "github.com/go-redis/redis/internal/pool"
+)
+
+//------------------------------------------------------------------------------
+
+// FailoverOptions are used to configure a failover client and should
+// be passed to NewFailoverClient.
+type FailoverOptions struct {
+ // The master name.
+ MasterName string
+ // A seed list of host:port addresses of sentinel nodes.
+ SentinelAddrs []string
+
+ // Following options are copied from Options struct.
+
+ OnConnect func(*Conn) error
+
+ Password string
+ DB int
+
+ MaxRetries int
+
+ DialTimeout time.Duration
+ ReadTimeout time.Duration
+ WriteTimeout time.Duration
+
+ PoolSize int
+ PoolTimeout time.Duration
+ IdleTimeout time.Duration
+ IdleCheckFrequency time.Duration
+
+ TLSConfig *tls.Config
+}
+
+func (opt *FailoverOptions) options() *Options {
+ return &Options{
+ Addr: "FailoverClient",
+
+ OnConnect: opt.OnConnect,
+
+ DB: opt.DB,
+ Password: opt.Password,
+
+ MaxRetries: opt.MaxRetries,
+
+ DialTimeout: opt.DialTimeout,
+ ReadTimeout: opt.ReadTimeout,
+ WriteTimeout: opt.WriteTimeout,
+
+ PoolSize: opt.PoolSize,
+ PoolTimeout: opt.PoolTimeout,
+ IdleTimeout: opt.IdleTimeout,
+ IdleCheckFrequency: opt.IdleCheckFrequency,
+
+ TLSConfig: opt.TLSConfig,
+ }
+}
+
+// NewFailoverClient returns a Redis client that uses Redis Sentinel
+// for automatic failover. It's safe for concurrent use by multiple
+// goroutines.
+func NewFailoverClient(failoverOpt *FailoverOptions) *Client {
+ opt := failoverOpt.options()
+ opt.init()
+
+ failover := &sentinelFailover{
+ masterName: failoverOpt.MasterName,
+ sentinelAddrs: failoverOpt.SentinelAddrs,
+
+ opt: opt,
+ }
+
+ c := Client{
+ baseClient: baseClient{
+ opt: opt,
+ connPool: failover.Pool(),
+
+ onClose: func() error {
+ return failover.Close()
+ },
+ },
+ }
+ c.baseClient.init()
+ c.setProcessor(c.Process)
+
+ return &c
+}
+
+//------------------------------------------------------------------------------
+
+type SentinelClient struct {
+ baseClient
+}
+
+func NewSentinelClient(opt *Options) *SentinelClient {
+ opt.init()
+ c := &SentinelClient{
+ baseClient: baseClient{
+ opt: opt,
+ connPool: newConnPool(opt),
+ },
+ }
+ c.baseClient.init()
+ return c
+}
+
+func (c *SentinelClient) PubSub() *PubSub {
+ pubsub := &PubSub{
+ opt: c.opt,
+
+ newConn: func(channels []string) (*pool.Conn, error) {
+ return c.newConn()
+ },
+ closeConn: c.connPool.CloseConn,
+ }
+ pubsub.init()
+ return pubsub
+}
+
+func (c *SentinelClient) GetMasterAddrByName(name string) *StringSliceCmd {
+ cmd := NewStringSliceCmd("SENTINEL", "get-master-addr-by-name", name)
+ c.Process(cmd)
+ return cmd
+}
+
+func (c *SentinelClient) Sentinels(name string) *SliceCmd {
+ cmd := NewSliceCmd("SENTINEL", "sentinels", name)
+ c.Process(cmd)
+ return cmd
+}
+
+type sentinelFailover struct {
+ sentinelAddrs []string
+
+ opt *Options
+
+ pool *pool.ConnPool
+ poolOnce sync.Once
+
+ mu sync.RWMutex
+ masterName string
+ _masterAddr string
+ sentinel *SentinelClient
+}
+
+func (d *sentinelFailover) Close() error {
+ return d.resetSentinel()
+}
+
+func (d *sentinelFailover) Pool() *pool.ConnPool {
+ d.poolOnce.Do(func() {
+ d.opt.Dialer = d.dial
+ d.pool = newConnPool(d.opt)
+ })
+ return d.pool
+}
+
+func (d *sentinelFailover) dial() (net.Conn, error) {
+ addr, err := d.MasterAddr()
+ if err != nil {
+ return nil, err
+ }
+ return net.DialTimeout("tcp", addr, d.opt.DialTimeout)
+}
+
+func (d *sentinelFailover) MasterAddr() (string, error) {
+ d.mu.Lock()
+ defer d.mu.Unlock()
+
+ addr, err := d.masterAddr()
+ if err != nil {
+ return "", err
+ }
+ d._switchMaster(addr)
+
+ return addr, nil
+}
+
+func (d *sentinelFailover) masterAddr() (string, error) {
+ // Try last working sentinel.
+ if d.sentinel != nil {
+ addr, err := d.sentinel.GetMasterAddrByName(d.masterName).Result()
+ if err == nil {
+ addr := net.JoinHostPort(addr[0], addr[1])
+ return addr, nil
+ }
+
+ internal.Logf("sentinel: GetMasterAddrByName name=%q failed: %s",
+ d.masterName, err)
+ d._resetSentinel()
+ }
+
+ for i, sentinelAddr := range d.sentinelAddrs {
+ sentinel := NewSentinelClient(&Options{
+ Addr: sentinelAddr,
+
+ DialTimeout: d.opt.DialTimeout,
+ ReadTimeout: d.opt.ReadTimeout,
+ WriteTimeout: d.opt.WriteTimeout,
+
+ PoolSize: d.opt.PoolSize,
+ PoolTimeout: d.opt.PoolTimeout,
+ IdleTimeout: d.opt.IdleTimeout,
+ })
+
+ masterAddr, err := sentinel.GetMasterAddrByName(d.masterName).Result()
+ if err != nil {
+ internal.Logf("sentinel: GetMasterAddrByName master=%q failed: %s",
+ d.masterName, err)
+ sentinel.Close()
+ continue
+ }
+
+ // Push working sentinel to the top.
+ d.sentinelAddrs[0], d.sentinelAddrs[i] = d.sentinelAddrs[i], d.sentinelAddrs[0]
+ d.setSentinel(sentinel)
+
+ addr := net.JoinHostPort(masterAddr[0], masterAddr[1])
+ return addr, nil
+ }
+
+ return "", errors.New("redis: all sentinels are unreachable")
+}
+
+func (c *sentinelFailover) switchMaster(addr string) {
+ c.mu.Lock()
+ c._switchMaster(addr)
+ c.mu.Unlock()
+}
+
+func (c *sentinelFailover) _switchMaster(addr string) {
+ if c._masterAddr == addr {
+ return
+ }
+
+ internal.Logf("sentinel: new master=%q addr=%q",
+ c.masterName, addr)
+ _ = c.Pool().Filter(func(cn *pool.Conn) bool {
+ return cn.RemoteAddr().String() != addr
+ })
+ c._masterAddr = addr
+}
+
+func (d *sentinelFailover) setSentinel(sentinel *SentinelClient) {
+ d.discoverSentinels(sentinel)
+ d.sentinel = sentinel
+ go d.listen(sentinel)
+}
+
+func (d *sentinelFailover) resetSentinel() error {
+ var err error
+ d.mu.Lock()
+ if d.sentinel != nil {
+ err = d._resetSentinel()
+ }
+ d.mu.Unlock()
+ return err
+}
+
+func (d *sentinelFailover) _resetSentinel() error {
+ err := d.sentinel.Close()
+ d.sentinel = nil
+ return err
+}
+
+func (d *sentinelFailover) discoverSentinels(sentinel *SentinelClient) {
+ sentinels, err := sentinel.Sentinels(d.masterName).Result()
+ if err != nil {
+ internal.Logf("sentinel: Sentinels master=%q failed: %s", d.masterName, err)
+ return
+ }
+ for _, sentinel := range sentinels {
+ vals := sentinel.([]interface{})
+ for i := 0; i < len(vals); i += 2 {
+ key := vals[i].(string)
+ if key == "name" {
+ sentinelAddr := vals[i+1].(string)
+ if !contains(d.sentinelAddrs, sentinelAddr) {
+ internal.Logf(
+ "sentinel: discovered new sentinel=%q for master=%q",
+ sentinelAddr, d.masterName,
+ )
+ d.sentinelAddrs = append(d.sentinelAddrs, sentinelAddr)
+ }
+ }
+ }
+ }
+}
+
+func (d *sentinelFailover) listen(sentinel *SentinelClient) {
+ pubsub := sentinel.PubSub()
+ defer pubsub.Close()
+
+ err := pubsub.Subscribe("+switch-master")
+ if err != nil {
+ internal.Logf("sentinel: Subscribe failed: %s", err)
+ d.resetSentinel()
+ return
+ }
+
+ for {
+ msg, err := pubsub.ReceiveMessage()
+ if err != nil {
+ if err == pool.ErrClosed {
+ d.resetSentinel()
+ return
+ }
+ internal.Logf("sentinel: ReceiveMessage failed: %s", err)
+ continue
+ }
+
+ switch msg.Channel {
+ case "+switch-master":
+ parts := strings.Split(msg.Payload, " ")
+ if parts[0] != d.masterName {
+ internal.Logf("sentinel: ignore addr for master=%q", parts[0])
+ continue
+ }
+ addr := net.JoinHostPort(parts[3], parts[4])
+ d.switchMaster(addr)
+ }
+ }
+}
+
+func contains(slice []string, str string) bool {
+ for _, s := range slice {
+ if s == str {
+ return true
+ }
+ }
+ return false
+}
diff --git a/src/dma/vendor/github.com/go-redis/redis/tx.go b/src/dma/vendor/github.com/go-redis/redis/tx.go
new file mode 100644
index 00000000..6a7da99d
--- /dev/null
+++ b/src/dma/vendor/github.com/go-redis/redis/tx.go
@@ -0,0 +1,110 @@
+package redis
+
+import (
+ "github.com/go-redis/redis/internal/pool"
+ "github.com/go-redis/redis/internal/proto"
+)
+
+// TxFailedErr transaction redis failed.
+const TxFailedErr = proto.RedisError("redis: transaction failed")
+
+// Tx implements Redis transactions as described in
+// http://redis.io/topics/transactions. It's NOT safe for concurrent use
+// by multiple goroutines, because Exec resets list of watched keys.
+// If you don't need WATCH it is better to use Pipeline.
+type Tx struct {
+ statefulCmdable
+ baseClient
+}
+
+func (c *Client) newTx() *Tx {
+ tx := Tx{
+ baseClient: baseClient{
+ opt: c.opt,
+ connPool: pool.NewStickyConnPool(c.connPool.(*pool.ConnPool), true),
+ },
+ }
+ tx.baseClient.init()
+ tx.statefulCmdable.setProcessor(tx.Process)
+ return &tx
+}
+
+// Watch prepares a transcaction and marks the keys to be watched
+// for conditional execution if there are any keys.
+//
+// The transaction is automatically closed when the fn exits.
+func (c *Client) Watch(fn func(*Tx) error, keys ...string) error {
+ tx := c.newTx()
+ if len(keys) > 0 {
+ if err := tx.Watch(keys...).Err(); err != nil {
+ _ = tx.Close()
+ return err
+ }
+ }
+
+ err := fn(tx)
+ _ = tx.Close()
+ return err
+}
+
+// Close closes the transaction, releasing any open resources.
+func (c *Tx) Close() error {
+ _ = c.Unwatch().Err()
+ return c.baseClient.Close()
+}
+
+// Watch marks the keys to be watched for conditional execution
+// of a transaction.
+func (c *Tx) Watch(keys ...string) *StatusCmd {
+ args := make([]interface{}, 1+len(keys))
+ args[0] = "watch"
+ for i, key := range keys {
+ args[1+i] = key
+ }
+ cmd := NewStatusCmd(args...)
+ c.Process(cmd)
+ return cmd
+}
+
+// Unwatch flushes all the previously watched keys for a transaction.
+func (c *Tx) Unwatch(keys ...string) *StatusCmd {
+ args := make([]interface{}, 1+len(keys))
+ args[0] = "unwatch"
+ for i, key := range keys {
+ args[1+i] = key
+ }
+ cmd := NewStatusCmd(args...)
+ c.Process(cmd)
+ return cmd
+}
+
+// Pipeline creates a new pipeline. It is more convenient to use Pipelined.
+func (c *Tx) Pipeline() Pipeliner {
+ pipe := Pipeline{
+ exec: c.processTxPipeline,
+ }
+ pipe.statefulCmdable.setProcessor(pipe.Process)
+ return &pipe
+}
+
+// Pipelined executes commands queued in the fn in a transaction.
+//
+// When using WATCH, EXEC will execute commands only if the watched keys
+// were not modified, allowing for a check-and-set mechanism.
+//
+// Exec always returns list of commands. If transaction fails
+// TxFailedErr is returned. Otherwise Exec returns an error of the first
+// failed command or nil.
+func (c *Tx) Pipelined(fn func(Pipeliner) error) ([]Cmder, error) {
+ return c.Pipeline().Pipelined(fn)
+}
+
+// TxPipelined is an alias for Pipelined.
+func (c *Tx) TxPipelined(fn func(Pipeliner) error) ([]Cmder, error) {
+ return c.Pipelined(fn)
+}
+
+// TxPipeline is an alias for Pipeline.
+func (c *Tx) TxPipeline() Pipeliner {
+ return c.Pipeline()
+}
diff --git a/src/dma/vendor/github.com/go-redis/redis/universal.go b/src/dma/vendor/github.com/go-redis/redis/universal.go
new file mode 100644
index 00000000..9e30c81d
--- /dev/null
+++ b/src/dma/vendor/github.com/go-redis/redis/universal.go
@@ -0,0 +1,151 @@
+package redis
+
+import (
+ "crypto/tls"
+ "time"
+)
+
+// UniversalOptions information is required by UniversalClient to establish
+// connections.
+type UniversalOptions struct {
+ // Either a single address or a seed list of host:port addresses
+ // of cluster/sentinel nodes.
+ Addrs []string
+
+ // The sentinel master name.
+ // Only failover clients.
+ MasterName string
+
+ // Database to be selected after connecting to the server.
+ // Only single-node and failover clients.
+ DB int
+
+ // Only cluster clients.
+
+ // Enables read only queries on slave nodes.
+ ReadOnly bool
+
+ MaxRedirects int
+ RouteByLatency bool
+
+ // Common options
+
+ OnConnect func(*Conn) error
+ MaxRetries int
+ Password string
+ DialTimeout time.Duration
+ ReadTimeout time.Duration
+ WriteTimeout time.Duration
+ PoolSize int
+ PoolTimeout time.Duration
+ IdleTimeout time.Duration
+ IdleCheckFrequency time.Duration
+ TLSConfig *tls.Config
+}
+
+func (o *UniversalOptions) cluster() *ClusterOptions {
+ if len(o.Addrs) == 0 {
+ o.Addrs = []string{"127.0.0.1:6379"}
+ }
+
+ return &ClusterOptions{
+ Addrs: o.Addrs,
+ MaxRedirects: o.MaxRedirects,
+ RouteByLatency: o.RouteByLatency,
+ ReadOnly: o.ReadOnly,
+
+ OnConnect: o.OnConnect,
+ MaxRetries: o.MaxRetries,
+ Password: o.Password,
+ DialTimeout: o.DialTimeout,
+ ReadTimeout: o.ReadTimeout,
+ WriteTimeout: o.WriteTimeout,
+ PoolSize: o.PoolSize,
+ PoolTimeout: o.PoolTimeout,
+ IdleTimeout: o.IdleTimeout,
+ IdleCheckFrequency: o.IdleCheckFrequency,
+ TLSConfig: o.TLSConfig,
+ }
+}
+
+func (o *UniversalOptions) failover() *FailoverOptions {
+ if len(o.Addrs) == 0 {
+ o.Addrs = []string{"127.0.0.1:26379"}
+ }
+
+ return &FailoverOptions{
+ SentinelAddrs: o.Addrs,
+ MasterName: o.MasterName,
+ DB: o.DB,
+
+ OnConnect: o.OnConnect,
+ MaxRetries: o.MaxRetries,
+ Password: o.Password,
+ DialTimeout: o.DialTimeout,
+ ReadTimeout: o.ReadTimeout,
+ WriteTimeout: o.WriteTimeout,
+ PoolSize: o.PoolSize,
+ PoolTimeout: o.PoolTimeout,
+ IdleTimeout: o.IdleTimeout,
+ IdleCheckFrequency: o.IdleCheckFrequency,
+ TLSConfig: o.TLSConfig,
+ }
+}
+
+func (o *UniversalOptions) simple() *Options {
+ addr := "127.0.0.1:6379"
+ if len(o.Addrs) > 0 {
+ addr = o.Addrs[0]
+ }
+
+ return &Options{
+ Addr: addr,
+ DB: o.DB,
+
+ OnConnect: o.OnConnect,
+ MaxRetries: o.MaxRetries,
+ Password: o.Password,
+ DialTimeout: o.DialTimeout,
+ ReadTimeout: o.ReadTimeout,
+ WriteTimeout: o.WriteTimeout,
+ PoolSize: o.PoolSize,
+ PoolTimeout: o.PoolTimeout,
+ IdleTimeout: o.IdleTimeout,
+ IdleCheckFrequency: o.IdleCheckFrequency,
+ TLSConfig: o.TLSConfig,
+ }
+}
+
+// --------------------------------------------------------------------
+
+// UniversalClient is an abstract client which - based on the provided options -
+// can connect to either clusters, or sentinel-backed failover instances or simple
+// single-instance servers. This can be useful for testing cluster-specific
+// applications locally.
+type UniversalClient interface {
+ Cmdable
+ Watch(fn func(*Tx) error, keys ...string) error
+ Process(cmd Cmder) error
+ WrapProcess(fn func(oldProcess func(cmd Cmder) error) func(cmd Cmder) error)
+ Subscribe(channels ...string) *PubSub
+ PSubscribe(channels ...string) *PubSub
+ Close() error
+}
+
+var _ UniversalClient = (*Client)(nil)
+var _ UniversalClient = (*ClusterClient)(nil)
+
+// NewUniversalClient returns a new multi client. The type of client returned depends
+// on the following three conditions:
+//
+// 1. if a MasterName is passed a sentinel-backed FailoverClient will be returned
+// 2. if the number of Addrs is two or more, a ClusterClient will be returned
+// 3. otherwise, a single-node redis Client will be returned.
+func NewUniversalClient(opts *UniversalOptions) UniversalClient {
+ if opts.MasterName != "" {
+ return NewFailoverClient(opts.failover())
+ } else if len(opts.Addrs) > 1 {
+ return NewClusterClient(opts.cluster())
+ }
+ return NewClient(opts.simple())
+}
diff --git a/src/dma/vendor/github.com/labstack/echo/.editorconfig b/src/dma/vendor/github.com/labstack/echo/.editorconfig
new file mode 100644
index 00000000..17ae50dd
--- /dev/null
+++ b/src/dma/vendor/github.com/labstack/echo/.editorconfig
@@ -0,0 +1,25 @@
+# EditorConfig coding styles definitions. For more information about the
+# properties used in this file, please see the EditorConfig documentation:
+# http://editorconfig.org/
+
+# indicate this is the root of the project
+root = true
+
+[*]
+charset = utf-8
+
+end_of_line = LF
+insert_final_newline = true
+trim_trailing_whitespace = true
+
+indent_style = space
+indent_size = 2
+
+[Makefile]
+indent_style = tab
+
+[*.md]
+trim_trailing_whitespace = false
+
+[*.go]
+indent_style = tab
diff --git a/src/dma/vendor/github.com/labstack/echo/.gitattributes b/src/dma/vendor/github.com/labstack/echo/.gitattributes
new file mode 100644
index 00000000..49b63e52
--- /dev/null
+++ b/src/dma/vendor/github.com/labstack/echo/.gitattributes
@@ -0,0 +1,20 @@
+# Automatically normalize line endings for all text-based files
+# http://git-scm.com/docs/gitattributes#_end_of_line_conversion
+* text=auto
+
+# For the following file types, normalize line endings to LF on checking and
+# prevent conversion to CRLF when they are checked out (this is required in
+# order to prevent newline related issues)
+.* text eol=lf
+*.go text eol=lf
+*.yml text eol=lf
+*.html text eol=lf
+*.css text eol=lf
+*.js text eol=lf
+*.json text eol=lf
+LICENSE text eol=lf
+
+# Exclude `website` and `cookbook` from GitHub's language statistics
+# https://github.com/github/linguist#using-gitattributes
+cookbook/* linguist-documentation
+website/* linguist-documentation
diff --git a/src/dma/vendor/github.com/labstack/echo/.gitignore b/src/dma/vendor/github.com/labstack/echo/.gitignore
new file mode 100644
index 00000000..dd74acca
--- /dev/null
+++ b/src/dma/vendor/github.com/labstack/echo/.gitignore
@@ -0,0 +1,7 @@
+.DS_Store
+coverage.txt
+_test
+vendor
+.idea
+*.iml
+*.out
diff --git a/src/dma/vendor/github.com/labstack/echo/.travis.yml b/src/dma/vendor/github.com/labstack/echo/.travis.yml
new file mode 100644
index 00000000..05e53b16
--- /dev/null
+++ b/src/dma/vendor/github.com/labstack/echo/.travis.yml
@@ -0,0 +1,14 @@
+language: go
+go:
+ - 1.9.x
+ - 1.10.x
+ - tip
+install:
+ - make dependency
+script:
+ - make test
+after_success:
+ - bash <(curl -s https://codecov.io/bash)
+matrix:
+ allow_failures:
+ - go: tip
diff --git a/src/dma/vendor/github.com/labstack/echo/Gopkg.lock b/src/dma/vendor/github.com/labstack/echo/Gopkg.lock
new file mode 100644
index 00000000..f3c3b8d2
--- /dev/null
+++ b/src/dma/vendor/github.com/labstack/echo/Gopkg.lock
@@ -0,0 +1,75 @@
+# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
+
+
+[[projects]]
+ name = "github.com/davecgh/go-spew"
+ packages = ["spew"]
+ revision = "346938d642f2ec3594ed81d874461961cd0faa76"
+ version = "v1.1.0"
+
+[[projects]]
+ name = "github.com/dgrijalva/jwt-go"
+ packages = ["."]
+ revision = "06ea1031745cb8b3dab3f6a236daf2b0aa468b7e"
+ version = "v3.2.0"
+
+[[projects]]
+ name = "github.com/labstack/gommon"
+ packages = ["bytes","color","log","random"]
+ revision = "6fe1405d73ec4bd4cd8a4ac8e2a2b2bf95d03954"
+ version = "0.2.4"
+
+[[projects]]
+ name = "github.com/mattn/go-colorable"
+ packages = ["."]
+ revision = "167de6bfdfba052fa6b2d3664c8f5272e23c9072"
+ version = "v0.0.9"
+
+[[projects]]
+ name = "github.com/mattn/go-isatty"
+ packages = ["."]
+ revision = "0360b2af4f38e8d38c7fce2a9f4e702702d73a39"
+ version = "v0.0.3"
+
+[[projects]]
+ name = "github.com/pmezard/go-difflib"
+ packages = ["difflib"]
+ revision = "792786c7400a136282c1664665ae0a8db921c6c2"
+ version = "v1.0.0"
+
+[[projects]]
+ name = "github.com/stretchr/testify"
+ packages = ["assert"]
+ revision = "12b6f73e6084dad08a7c6e575284b177ecafbc71"
+ version = "v1.2.1"
+
+[[projects]]
+ branch = "master"
+ name = "github.com/valyala/bytebufferpool"
+ packages = ["."]
+ revision = "e746df99fe4a3986f4d4f79e13c1e0117ce9c2f7"
+
+[[projects]]
+ branch = "master"
+ name = "github.com/valyala/fasttemplate"
+ packages = ["."]
+ revision = "dcecefd839c4193db0d35b88ec65b4c12d360ab0"
+
+[[projects]]
+ branch = "master"
+ name = "golang.org/x/crypto"
+ packages = ["acme","acme/autocert"]
+ revision = "182114d582623c1caa54f73de9c7224e23a48487"
+
+[[projects]]
+ branch = "master"
+ name = "golang.org/x/sys"
+ packages = ["unix"]
+ revision = "c28acc882ebcbfbe8ce9f0f14b9ac26ee138dd51"
+
+[solve-meta]
+ analyzer-name = "dep"
+ analyzer-version = 1
+ inputs-digest = "9c7b45e80fe353405800cf01f429b3a203cfb8d4468a04c64a908e11a98ea764"
+ solver-name = "gps-cdcl"
+ solver-version = 1
diff --git a/src/dma/vendor/github.com/labstack/echo/Gopkg.toml b/src/dma/vendor/github.com/labstack/echo/Gopkg.toml
new file mode 100644
index 00000000..61de60cb
--- /dev/null
+++ b/src/dma/vendor/github.com/labstack/echo/Gopkg.toml
@@ -0,0 +1,42 @@
+
+# Gopkg.toml example
+#
+# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
+# for detailed Gopkg.toml documentation.
+#
+# required = ["github.com/user/thing/cmd/thing"]
+# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
+#
+# [[constraint]]
+# name = "github.com/user/project"
+# version = "1.0.0"
+#
+# [[constraint]]
+# name = "github.com/user/project2"
+# branch = "dev"
+# source = "github.com/myfork/project2"
+#
+# [[override]]
+# name = "github.com/x/y"
+# version = "2.4.0"
+
+
+[[constraint]]
+ name = "github.com/dgrijalva/jwt-go"
+ version = "3.2.0"
+
+[[constraint]]
+ name = "github.com/labstack/gommon"
+ version = "0.2.4"
+
+[[constraint]]
+ name = "github.com/stretchr/testify"
+ version = "1.2.1"
+
+[[constraint]]
+ branch = "master"
+ name = "github.com/valyala/fasttemplate"
+
+[[constraint]]
+ branch = "master"
+ name = "golang.org/x/crypto" \ No newline at end of file
diff --git a/src/dma/vendor/github.com/labstack/echo/LICENSE b/src/dma/vendor/github.com/labstack/echo/LICENSE
new file mode 100644
index 00000000..b5b006b4
--- /dev/null
+++ b/src/dma/vendor/github.com/labstack/echo/LICENSE
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) 2017 LabStack
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/src/dma/vendor/github.com/labstack/echo/Makefile b/src/dma/vendor/github.com/labstack/echo/Makefile
new file mode 100644
index 00000000..494667d8
--- /dev/null
+++ b/src/dma/vendor/github.com/labstack/echo/Makefile
@@ -0,0 +1,17 @@
+DEP_VERSION=0.4.1
+
+dependency:
+ curl -fsSL -o ${GOPATH}/bin/dep https://github.com/golang/dep/releases/download/v${DEP_VERSION}/dep-linux-amd64
+ chmod +x ${GOPATH}/bin/dep
+ dep ensure
+
+test:
+ echo "" > coverage.txt
+ for d in $(shell go list ./... | grep -v vendor); do \
+ go test -race -coverprofile=profile.out -covermode=atomic $$d || exit 1; \
+ [ -f profile.out ] && cat profile.out >> coverage.txt && rm profile.out; \
+ done
+
+tag:
+ @git tag `grep -P '^\tversion = ' echo.go|cut -f2 -d'"'`
+ @git tag|grep -v ^v
diff --git a/src/dma/vendor/github.com/labstack/echo/README.md b/src/dma/vendor/github.com/labstack/echo/README.md
new file mode 100644
index 00000000..0f609df4
--- /dev/null
+++ b/src/dma/vendor/github.com/labstack/echo/README.md
@@ -0,0 +1,99 @@
+<a href="https://echo.labstack.com"><img height="80" src="https://cdn.labstack.com/images/echo-logo.svg"></a>
+
+[![Sourcegraph](https://sourcegraph.com/github.com/labstack/echo/-/badge.svg?style=flat-square)](https://sourcegraph.com/github.com/labstack/echo?badge)
+[![GoDoc](http://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)](http://godoc.org/github.com/labstack/echo)
+[![Go Report Card](https://goreportcard.com/badge/github.com/labstack/echo?style=flat-square)](https://goreportcard.com/report/github.com/labstack/echo)
+[![Build Status](http://img.shields.io/travis/labstack/echo.svg?style=flat-square)](https://travis-ci.org/labstack/echo)
+[![Codecov](https://img.shields.io/codecov/c/github/labstack/echo.svg?style=flat-square)](https://codecov.io/gh/labstack/echo)
+[![Join the chat at https://gitter.im/labstack/echo](https://img.shields.io/badge/gitter-join%20chat-brightgreen.svg?style=flat-square)](https://gitter.im/labstack/echo)
+[![Forum](https://img.shields.io/badge/community-forum-00afd1.svg?style=flat-square)](https://forum.labstack.com)
+[![Twitter](https://img.shields.io/badge/twitter-@labstack-55acee.svg?style=flat-square)](https://twitter.com/labstack)
+[![License](http://img.shields.io/badge/license-mit-blue.svg?style=flat-square)](https://raw.githubusercontent.com/labstack/echo/master/LICENSE)
+
+## Feature Overview
+
+- Optimized HTTP router which smartly prioritize routes
+- Build robust and scalable RESTful APIs
+- Group APIs
+- Extensible middleware framework
+- Define middleware at root, group or route level
+- Data binding for JSON, XML and form payload
+- Handy functions to send variety of HTTP responses
+- Centralized HTTP error handling
+- Template rendering with any template engine
+- Define your format for the logger
+- Highly customizable
+- Automatic TLS via Let’s Encrypt
+- HTTP/2 support
+
+## Benchmarks
+
+Date: 2018/03/15<br>
+Source: https://github.com/vishr/web-framework-benchmark<br>
+Lower is better!
+
+<img src="https://api.labstack.com/chart/bar?values=37223,55382,2985,5265|42013,59865,3350,6424&labels=Static,GitHub%20API,Parse%20API,Gplus%20API&titles=Echo,Gin&colors=lightseagreen,goldenrod&x_title=Routes&y_title=ns/op">
+
+## [Guide](https://echo.labstack.com/guide)
+
+### Example
+
+```go
+package main
+
+import (
+ "net/http"
+
+ "github.com/labstack/echo"
+ "github.com/labstack/echo/middleware"
+)
+
+func main() {
+ // Echo instance
+ e := echo.New()
+
+ // Middleware
+ e.Use(middleware.Logger())
+ e.Use(middleware.Recover())
+
+ // Routes
+ e.GET("/", hello)
+
+ // Start server
+ e.Logger.Fatal(e.Start(":1323"))
+}
+
+// Handler
+func hello(c echo.Context) error {
+ return c.String(http.StatusOK, "Hello, World!")
+}
+```
+
+## Help
+
+- [Forum](https://forum.labstack.com)
+- [Chat](https://gitter.im/labstack/echo)
+
+## Contribute
+
+**Use issues for everything**
+
+- For a small change, just send a PR.
+- For bigger changes open an issue for discussion before sending a PR.
+- PR should have:
+ - Test case
+ - Documentation
+ - Example (If it makes sense)
+- You can also contribute by:
+ - Reporting issues
+ - Suggesting new features or enhancements
+ - Improve/fix documentation
+
+## Credits
+- [Vishal Rana](https://github.com/vishr) - Author
+- [Nitin Rana](https://github.com/nr17) - Consultant
+- [Contributors](https://github.com/labstack/echo/graphs/contributors)
+
+## License
+
+[MIT](https://github.com/labstack/echo/blob/master/LICENSE)
diff --git a/src/dma/vendor/github.com/labstack/echo/bind.go b/src/dma/vendor/github.com/labstack/echo/bind.go
new file mode 100644
index 00000000..38e07150
--- /dev/null
+++ b/src/dma/vendor/github.com/labstack/echo/bind.go
@@ -0,0 +1,261 @@
+package echo
+
+import (
+ "encoding/json"
+ "encoding/xml"
+ "errors"
+ "fmt"
+ "net/http"
+ "reflect"
+ "strconv"
+ "strings"
+)
+
+type (
+ // Binder is the interface that wraps the Bind method.
+ Binder interface {
+ Bind(i interface{}, c Context) error
+ }
+
+ // DefaultBinder is the default implementation of the Binder interface.
+ DefaultBinder struct{}
+
+ // BindUnmarshaler is the interface used to wrap the UnmarshalParam method.
+ BindUnmarshaler interface {
+ // UnmarshalParam decodes and assigns a value from an form or query param.
+ UnmarshalParam(param string) error
+ }
+)
+
+// Bind implements the `Binder#Bind` function.
+func (b *DefaultBinder) Bind(i interface{}, c Context) (err error) {
+ req := c.Request()
+ if req.ContentLength == 0 {
+ if req.Method == GET || req.Method == DELETE {
+ if err = b.bindData(i, c.QueryParams(), "query"); err != nil {
+ return NewHTTPError(http.StatusBadRequest, err.Error())
+ }
+ return
+ }
+ return NewHTTPError(http.StatusBadRequest, "Request body can't be empty")
+ }
+ ctype := req.Header.Get(HeaderContentType)
+ switch {
+ case strings.HasPrefix(ctype, MIMEApplicationJSON):
+ if err = json.NewDecoder(req.Body).Decode(i); err != nil {
+ if ute, ok := err.(*json.UnmarshalTypeError); ok {
+ return NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Unmarshal type error: expected=%v, got=%v, offset=%v", ute.Type, ute.Value, ute.Offset))
+ } else if se, ok := err.(*json.SyntaxError); ok {
+ return NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Syntax error: offset=%v, error=%v", se.Offset, se.Error()))
+ } else {
+ return NewHTTPError(http.StatusBadRequest, err.Error())
+ }
+ }
+ case strings.HasPrefix(ctype, MIMEApplicationXML), strings.HasPrefix(ctype, MIMETextXML):
+ if err = xml.NewDecoder(req.Body).Decode(i); err != nil {
+ if ute, ok := err.(*xml.UnsupportedTypeError); ok {
+ return NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Unsupported type error: type=%v, error=%v", ute.Type, ute.Error()))
+ } else if se, ok := err.(*xml.SyntaxError); ok {
+ return NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Syntax error: line=%v, error=%v", se.Line, se.Error()))
+ } else {
+ return NewHTTPError(http.StatusBadRequest, err.Error())
+ }
+ }
+ case strings.HasPrefix(ctype, MIMEApplicationForm), strings.HasPrefix(ctype, MIMEMultipartForm):
+ params, err := c.FormParams()
+ if err != nil {
+ return NewHTTPError(http.StatusBadRequest, err.Error())
+ }
+ if err = b.bindData(i, params, "form"); err != nil {
+ return NewHTTPError(http.StatusBadRequest, err.Error())
+ }
+ default:
+ return ErrUnsupportedMediaType
+ }
+ return
+}
+
+func (b *DefaultBinder) bindData(ptr interface{}, data map[string][]string, tag string) error {
+ typ := reflect.TypeOf(ptr).Elem()
+ val := reflect.ValueOf(ptr).Elem()
+
+ if typ.Kind() != reflect.Struct {
+ return errors.New("binding element must be a struct")
+ }
+
+ for i := 0; i < typ.NumField(); i++ {
+ typeField := typ.Field(i)
+ structField := val.Field(i)
+ if !structField.CanSet() {
+ continue
+ }
+ structFieldKind := structField.Kind()
+ inputFieldName := typeField.Tag.Get(tag)
+
+ if inputFieldName == "" {
+ inputFieldName = typeField.Name
+ // If tag is nil, we inspect if the field is a struct.
+ if _, ok := bindUnmarshaler(structField); !ok && structFieldKind == reflect.Struct {
+ err := b.bindData(structField.Addr().Interface(), data, tag)
+ if err != nil {
+ return err
+ }
+ continue
+ }
+ }
+ inputValue, exists := data[inputFieldName]
+ if !exists {
+ continue
+ }
+
+ // Call this first, in case we're dealing with an alias to an array type
+ if ok, err := unmarshalField(typeField.Type.Kind(), inputValue[0], structField); ok {
+ if err != nil {
+ return err
+ }
+ continue
+ }
+
+ numElems := len(inputValue)
+ if structFieldKind == reflect.Slice && numElems > 0 {
+ sliceOf := structField.Type().Elem().Kind()
+ slice := reflect.MakeSlice(structField.Type(), numElems, numElems)
+ for j := 0; j < numElems; j++ {
+ if err := setWithProperType(sliceOf, inputValue[j], slice.Index(j)); err != nil {
+ return err
+ }
+ }
+ val.Field(i).Set(slice)
+ } else {
+ if err := setWithProperType(typeField.Type.Kind(), inputValue[0], structField); err != nil {
+ return err
+ }
+ }
+ }
+ return nil
+}
+
+func setWithProperType(valueKind reflect.Kind, val string, structField reflect.Value) error {
+ // But also call it here, in case we're dealing with an array of BindUnmarshalers
+ if ok, err := unmarshalField(valueKind, val, structField); ok {
+ return err
+ }
+
+ switch valueKind {
+ case reflect.Ptr:
+ return setWithProperType(structField.Elem().Kind(), val, structField.Elem())
+ case reflect.Int:
+ return setIntField(val, 0, structField)
+ case reflect.Int8:
+ return setIntField(val, 8, structField)
+ case reflect.Int16:
+ return setIntField(val, 16, structField)
+ case reflect.Int32:
+ return setIntField(val, 32, structField)
+ case reflect.Int64:
+ return setIntField(val, 64, structField)
+ case reflect.Uint:
+ return setUintField(val, 0, structField)
+ case reflect.Uint8:
+ return setUintField(val, 8, structField)
+ case reflect.Uint16:
+ return setUintField(val, 16, structField)
+ case reflect.Uint32:
+ return setUintField(val, 32, structField)
+ case reflect.Uint64:
+ return setUintField(val, 64, structField)
+ case reflect.Bool:
+ return setBoolField(val, structField)
+ case reflect.Float32:
+ return setFloatField(val, 32, structField)
+ case reflect.Float64:
+ return setFloatField(val, 64, structField)
+ case reflect.String:
+ structField.SetString(val)
+ default:
+ return errors.New("unknown type")
+ }
+ return nil
+}
+
+func unmarshalField(valueKind reflect.Kind, val string, field reflect.Value) (bool, error) {
+ switch valueKind {
+ case reflect.Ptr:
+ return unmarshalFieldPtr(val, field)
+ default:
+ return unmarshalFieldNonPtr(val, field)
+ }
+}
+
+// bindUnmarshaler attempts to unmarshal a reflect.Value into a BindUnmarshaler
+func bindUnmarshaler(field reflect.Value) (BindUnmarshaler, bool) {
+ ptr := reflect.New(field.Type())
+ if ptr.CanInterface() {
+ iface := ptr.Interface()
+ if unmarshaler, ok := iface.(BindUnmarshaler); ok {
+ return unmarshaler, ok
+ }
+ }
+ return nil, false
+}
+
+func unmarshalFieldNonPtr(value string, field reflect.Value) (bool, error) {
+ if unmarshaler, ok := bindUnmarshaler(field); ok {
+ err := unmarshaler.UnmarshalParam(value)
+ field.Set(reflect.ValueOf(unmarshaler).Elem())
+ return true, err
+ }
+ return false, nil
+}
+
+func unmarshalFieldPtr(value string, field reflect.Value) (bool, error) {
+ if field.IsNil() {
+ // Initialize the pointer to a nil value
+ field.Set(reflect.New(field.Type().Elem()))
+ }
+ return unmarshalFieldNonPtr(value, field.Elem())
+}
+
+func setIntField(value string, bitSize int, field reflect.Value) error {
+ if value == "" {
+ value = "0"
+ }
+ intVal, err := strconv.ParseInt(value, 10, bitSize)
+ if err == nil {
+ field.SetInt(intVal)
+ }
+ return err
+}
+
+func setUintField(value string, bitSize int, field reflect.Value) error {
+ if value == "" {
+ value = "0"
+ }
+ uintVal, err := strconv.ParseUint(value, 10, bitSize)
+ if err == nil {
+ field.SetUint(uintVal)
+ }
+ return err
+}
+
+func setBoolField(value string, field reflect.Value) error {
+ if value == "" {
+ value = "false"
+ }
+ boolVal, err := strconv.ParseBool(value)
+ if err == nil {
+ field.SetBool(boolVal)
+ }
+ return err
+}
+
+func setFloatField(value string, bitSize int, field reflect.Value) error {
+ if value == "" {
+ value = "0.0"
+ }
+ floatVal, err := strconv.ParseFloat(value, bitSize)
+ if err == nil {
+ field.SetFloat(floatVal)
+ }
+ return err
+}
diff --git a/src/dma/vendor/github.com/labstack/echo/context.go b/src/dma/vendor/github.com/labstack/echo/context.go
new file mode 100644
index 00000000..cf780c51
--- /dev/null
+++ b/src/dma/vendor/github.com/labstack/echo/context.go
@@ -0,0 +1,576 @@
+package echo
+
+import (
+ "bytes"
+ "encoding/json"
+ "encoding/xml"
+ "fmt"
+ "io"
+ "mime/multipart"
+ "net"
+ "net/http"
+ "net/url"
+ "os"
+ "path/filepath"
+ "strings"
+)
+
+type (
+ // Context represents the context of the current HTTP request. It holds request and
+ // response objects, path, path parameters, data and registered handler.
+ Context interface {
+ // Request returns `*http.Request`.
+ Request() *http.Request
+
+ // SetRequest sets `*http.Request`.
+ SetRequest(r *http.Request)
+
+ // Response returns `*Response`.
+ Response() *Response
+
+ // IsTLS returns true if HTTP connection is TLS otherwise false.
+ IsTLS() bool
+
+ // IsWebSocket returns true if HTTP connection is WebSocket otherwise false.
+ IsWebSocket() bool
+
+ // Scheme returns the HTTP protocol scheme, `http` or `https`.
+ Scheme() string
+
+ // RealIP returns the client's network address based on `X-Forwarded-For`
+ // or `X-Real-IP` request header.
+ RealIP() string
+
+ // Path returns the registered path for the handler.
+ Path() string
+
+ // SetPath sets the registered path for the handler.
+ SetPath(p string)
+
+ // Param returns path parameter by name.
+ Param(name string) string
+
+ // ParamNames returns path parameter names.
+ ParamNames() []string
+
+ // SetParamNames sets path parameter names.
+ SetParamNames(names ...string)
+
+ // ParamValues returns path parameter values.
+ ParamValues() []string
+
+ // SetParamValues sets path parameter values.
+ SetParamValues(values ...string)
+
+ // QueryParam returns the query param for the provided name.
+ QueryParam(name string) string
+
+ // QueryParams returns the query parameters as `url.Values`.
+ QueryParams() url.Values
+
+ // QueryString returns the URL query string.
+ QueryString() string
+
+ // FormValue returns the form field value for the provided name.
+ FormValue(name string) string
+
+ // FormParams returns the form parameters as `url.Values`.
+ FormParams() (url.Values, error)
+
+ // FormFile returns the multipart form file for the provided name.
+ FormFile(name string) (*multipart.FileHeader, error)
+
+ // MultipartForm returns the multipart form.
+ MultipartForm() (*multipart.Form, error)
+
+ // Cookie returns the named cookie provided in the request.
+ Cookie(name string) (*http.Cookie, error)
+
+ // SetCookie adds a `Set-Cookie` header in HTTP response.
+ SetCookie(cookie *http.Cookie)
+
+ // Cookies returns the HTTP cookies sent with the request.
+ Cookies() []*http.Cookie
+
+ // Get retrieves data from the context.
+ Get(key string) interface{}
+
+ // Set saves data in the context.
+ Set(key string, val interface{})
+
+ // Bind binds the request body into provided type `i`. The default binder
+ // does it based on Content-Type header.
+ Bind(i interface{}) error
+
+ // Validate validates provided `i`. It is usually called after `Context#Bind()`.
+ // Validator must be registered using `Echo#Validator`.
+ Validate(i interface{}) error
+
+ // Render renders a template with data and sends a text/html response with status
+ // code. Renderer must be registered using `Echo.Renderer`.
+ Render(code int, name string, data interface{}) error
+
+ // HTML sends an HTTP response with status code.
+ HTML(code int, html string) error
+
+ // HTMLBlob sends an HTTP blob response with status code.
+ HTMLBlob(code int, b []byte) error
+
+ // String sends a string response with status code.
+ String(code int, s string) error
+
+ // JSON sends a JSON response with status code.
+ JSON(code int, i interface{}) error
+
+ // JSONPretty sends a pretty-print JSON with status code.
+ JSONPretty(code int, i interface{}, indent string) error
+
+ // JSONBlob sends a JSON blob response with status code.
+ JSONBlob(code int, b []byte) error
+
+ // JSONP sends a JSONP response with status code. It uses `callback` to construct
+ // the JSONP payload.
+ JSONP(code int, callback string, i interface{}) error
+
+ // JSONPBlob sends a JSONP blob response with status code. It uses `callback`
+ // to construct the JSONP payload.
+ JSONPBlob(code int, callback string, b []byte) error
+
+ // XML sends an XML response with status code.
+ XML(code int, i interface{}) error
+
+ // XMLPretty sends a pretty-print XML with status code.
+ XMLPretty(code int, i interface{}, indent string) error
+
+ // XMLBlob sends an XML blob response with status code.
+ XMLBlob(code int, b []byte) error
+
+ // Blob sends a blob response with status code and content type.
+ Blob(code int, contentType string, b []byte) error
+
+ // Stream sends a streaming response with status code and content type.
+ Stream(code int, contentType string, r io.Reader) error
+
+ // File sends a response with the content of the file.
+ File(file string) error
+
+ // Attachment sends a response as attachment, prompting client to save the
+ // file.
+ Attachment(file string, name string) error
+
+ // Inline sends a response as inline, opening the file in the browser.
+ Inline(file string, name string) error
+
+ // NoContent sends a response with no body and a status code.
+ NoContent(code int) error
+
+ // Redirect redirects the request to a provided URL with status code.
+ Redirect(code int, url string) error
+
+ // Error invokes the registered HTTP error handler. Generally used by middleware.
+ Error(err error)
+
+ // Handler returns the matched handler by router.
+ Handler() HandlerFunc
+
+ // SetHandler sets the matched handler by router.
+ SetHandler(h HandlerFunc)
+
+ // Logger returns the `Logger` instance.
+ Logger() Logger
+
+ // Echo returns the `Echo` instance.
+ Echo() *Echo
+
+ // Reset resets the context after request completes. It must be called along
+ // with `Echo#AcquireContext()` and `Echo#ReleaseContext()`.
+ // See `Echo#ServeHTTP()`
+ Reset(r *http.Request, w http.ResponseWriter)
+ }
+
+ context struct {
+ request *http.Request
+ response *Response
+ path string
+ pnames []string
+ pvalues []string
+ query url.Values
+ handler HandlerFunc
+ store Map
+ echo *Echo
+ }
+)
+
+const (
+ defaultMemory = 32 << 20 // 32 MB
+ indexPage = "index.html"
+)
+
+func (c *context) writeContentType(value string) {
+ header := c.Response().Header()
+ if header.Get(HeaderContentType) == "" {
+ header.Set(HeaderContentType, value)
+ }
+}
+
+func (c *context) Request() *http.Request {
+ return c.request
+}
+
+func (c *context) SetRequest(r *http.Request) {
+ c.request = r
+}
+
+func (c *context) Response() *Response {
+ return c.response
+}
+
+func (c *context) IsTLS() bool {
+ return c.request.TLS != nil
+}
+
+func (c *context) IsWebSocket() bool {
+ upgrade := c.request.Header.Get(HeaderUpgrade)
+ return upgrade == "websocket" || upgrade == "Websocket"
+}
+
+func (c *context) Scheme() string {
+ // Can't use `r.Request.URL.Scheme`
+ // See: https://groups.google.com/forum/#!topic/golang-nuts/pMUkBlQBDF0
+ if c.IsTLS() {
+ return "https"
+ }
+ if scheme := c.request.Header.Get(HeaderXForwardedProto); scheme != "" {
+ return scheme
+ }
+ if scheme := c.request.Header.Get(HeaderXForwardedProtocol); scheme != "" {
+ return scheme
+ }
+ if ssl := c.request.Header.Get(HeaderXForwardedSsl); ssl == "on" {
+ return "https"
+ }
+ if scheme := c.request.Header.Get(HeaderXUrlScheme); scheme != "" {
+ return scheme
+ }
+ return "http"
+}
+
+func (c *context) RealIP() string {
+ ra := c.request.RemoteAddr
+ if ip := c.request.Header.Get(HeaderXForwardedFor); ip != "" {
+ ra = strings.Split(ip, ", ")[0]
+ } else if ip := c.request.Header.Get(HeaderXRealIP); ip != "" {
+ ra = ip
+ } else {
+ ra, _, _ = net.SplitHostPort(ra)
+ }
+ return ra
+}
+
+func (c *context) Path() string {
+ return c.path
+}
+
+func (c *context) SetPath(p string) {
+ c.path = p
+}
+
+func (c *context) Param(name string) string {
+ for i, n := range c.pnames {
+ if i < len(c.pvalues) {
+ if n == name {
+ return c.pvalues[i]
+ }
+ }
+ }
+ return ""
+}
+
+func (c *context) ParamNames() []string {
+ return c.pnames
+}
+
+func (c *context) SetParamNames(names ...string) {
+ c.pnames = names
+}
+
+func (c *context) ParamValues() []string {
+ return c.pvalues[:len(c.pnames)]
+}
+
+func (c *context) SetParamValues(values ...string) {
+ c.pvalues = values
+}
+
+func (c *context) QueryParam(name string) string {
+ if c.query == nil {
+ c.query = c.request.URL.Query()
+ }
+ return c.query.Get(name)
+}
+
+func (c *context) QueryParams() url.Values {
+ if c.query == nil {
+ c.query = c.request.URL.Query()
+ }
+ return c.query
+}
+
+func (c *context) QueryString() string {
+ return c.request.URL.RawQuery
+}
+
+func (c *context) FormValue(name string) string {
+ return c.request.FormValue(name)
+}
+
+func (c *context) FormParams() (url.Values, error) {
+ if strings.HasPrefix(c.request.Header.Get(HeaderContentType), MIMEMultipartForm) {
+ if err := c.request.ParseMultipartForm(defaultMemory); err != nil {
+ return nil, err
+ }
+ } else {
+ if err := c.request.ParseForm(); err != nil {
+ return nil, err
+ }
+ }
+ return c.request.Form, nil
+}
+
+func (c *context) FormFile(name string) (*multipart.FileHeader, error) {
+ _, fh, err := c.request.FormFile(name)
+ return fh, err
+}
+
+func (c *context) MultipartForm() (*multipart.Form, error) {
+ err := c.request.ParseMultipartForm(defaultMemory)
+ return c.request.MultipartForm, err
+}
+
+func (c *context) Cookie(name string) (*http.Cookie, error) {
+ return c.request.Cookie(name)
+}
+
+func (c *context) SetCookie(cookie *http.Cookie) {
+ http.SetCookie(c.Response(), cookie)
+}
+
+func (c *context) Cookies() []*http.Cookie {
+ return c.request.Cookies()
+}
+
+func (c *context) Get(key string) interface{} {
+ return c.store[key]
+}
+
+func (c *context) Set(key string, val interface{}) {
+ if c.store == nil {
+ c.store = make(Map)
+ }
+ c.store[key] = val
+}
+
+func (c *context) Bind(i interface{}) error {
+ return c.echo.Binder.Bind(i, c)
+}
+
+func (c *context) Validate(i interface{}) error {
+ if c.echo.Validator == nil {
+ return ErrValidatorNotRegistered
+ }
+ return c.echo.Validator.Validate(i)
+}
+
+func (c *context) Render(code int, name string, data interface{}) (err error) {
+ if c.echo.Renderer == nil {
+ return ErrRendererNotRegistered
+ }
+ buf := new(bytes.Buffer)
+ if err = c.echo.Renderer.Render(buf, name, data, c); err != nil {
+ return
+ }
+ return c.HTMLBlob(code, buf.Bytes())
+}
+
+func (c *context) HTML(code int, html string) (err error) {
+ return c.HTMLBlob(code, []byte(html))
+}
+
+func (c *context) HTMLBlob(code int, b []byte) (err error) {
+ return c.Blob(code, MIMETextHTMLCharsetUTF8, b)
+}
+
+func (c *context) String(code int, s string) (err error) {
+ return c.Blob(code, MIMETextPlainCharsetUTF8, []byte(s))
+}
+
+func (c *context) JSON(code int, i interface{}) (err error) {
+ _, pretty := c.QueryParams()["pretty"]
+ if c.echo.Debug || pretty {
+ return c.JSONPretty(code, i, " ")
+ }
+ b, err := json.Marshal(i)
+ if err != nil {
+ return
+ }
+ return c.JSONBlob(code, b)
+}
+
+func (c *context) JSONPretty(code int, i interface{}, indent string) (err error) {
+ b, err := json.MarshalIndent(i, "", indent)
+ if err != nil {
+ return
+ }
+ return c.JSONBlob(code, b)
+}
+
+func (c *context) JSONBlob(code int, b []byte) (err error) {
+ return c.Blob(code, MIMEApplicationJSONCharsetUTF8, b)
+}
+
+func (c *context) JSONP(code int, callback string, i interface{}) (err error) {
+ b, err := json.Marshal(i)
+ if err != nil {
+ return
+ }
+ return c.JSONPBlob(code, callback, b)
+}
+
+func (c *context) JSONPBlob(code int, callback string, b []byte) (err error) {
+ c.writeContentType(MIMEApplicationJavaScriptCharsetUTF8)
+ c.response.WriteHeader(code)
+ if _, err = c.response.Write([]byte(callback + "(")); err != nil {
+ return
+ }
+ if _, err = c.response.Write(b); err != nil {
+ return
+ }
+ _, err = c.response.Write([]byte(");"))
+ return
+}
+
+func (c *context) XML(code int, i interface{}) (err error) {
+ _, pretty := c.QueryParams()["pretty"]
+ if c.echo.Debug || pretty {
+ return c.XMLPretty(code, i, " ")
+ }
+ b, err := xml.Marshal(i)
+ if err != nil {
+ return
+ }
+ return c.XMLBlob(code, b)
+}
+
+func (c *context) XMLPretty(code int, i interface{}, indent string) (err error) {
+ b, err := xml.MarshalIndent(i, "", indent)
+ if err != nil {
+ return
+ }
+ return c.XMLBlob(code, b)
+}
+
+func (c *context) XMLBlob(code int, b []byte) (err error) {
+ c.writeContentType(MIMEApplicationXMLCharsetUTF8)
+ c.response.WriteHeader(code)
+ if _, err = c.response.Write([]byte(xml.Header)); err != nil {
+ return
+ }
+ _, err = c.response.Write(b)
+ return
+}
+
+func (c *context) Blob(code int, contentType string, b []byte) (err error) {
+ c.writeContentType(contentType)
+ c.response.WriteHeader(code)
+ _, err = c.response.Write(b)
+ return
+}
+
+func (c *context) Stream(code int, contentType string, r io.Reader) (err error) {
+ c.writeContentType(contentType)
+ c.response.WriteHeader(code)
+ _, err = io.Copy(c.response, r)
+ return
+}
+
+func (c *context) File(file string) (err error) {
+ f, err := os.Open(file)
+ if err != nil {
+ return NotFoundHandler(c)
+ }
+ defer f.Close()
+
+ fi, _ := f.Stat()
+ if fi.IsDir() {
+ file = filepath.Join(file, indexPage)
+ f, err = os.Open(file)
+ if err != nil {
+ return NotFoundHandler(c)
+ }
+ defer f.Close()
+ if fi, err = f.Stat(); err != nil {
+ return
+ }
+ }
+ http.ServeContent(c.Response(), c.Request(), fi.Name(), fi.ModTime(), f)
+ return
+}
+
+func (c *context) Attachment(file, name string) error {
+ return c.contentDisposition(file, name, "attachment")
+}
+
+func (c *context) Inline(file, name string) error {
+ return c.contentDisposition(file, name, "inline")
+}
+
+func (c *context) contentDisposition(file, name, dispositionType string) error {
+ c.response.Header().Set(HeaderContentDisposition, fmt.Sprintf("%s; filename=%q", dispositionType, name))
+ return c.File(file)
+}
+
+func (c *context) NoContent(code int) error {
+ c.response.WriteHeader(code)
+ return nil
+}
+
+func (c *context) Redirect(code int, url string) error {
+ if code < 300 || code > 308 {
+ return ErrInvalidRedirectCode
+ }
+ c.response.Header().Set(HeaderLocation, url)
+ c.response.WriteHeader(code)
+ return nil
+}
+
+func (c *context) Error(err error) {
+ c.echo.HTTPErrorHandler(err, c)
+}
+
+func (c *context) Echo() *Echo {
+ return c.echo
+}
+
+func (c *context) Handler() HandlerFunc {
+ return c.handler
+}
+
+func (c *context) SetHandler(h HandlerFunc) {
+ c.handler = h
+}
+
+func (c *context) Logger() Logger {
+ return c.echo.Logger
+}
+
+func (c *context) Reset(r *http.Request, w http.ResponseWriter) {
+ c.request = r
+ c.response.reset(w)
+ c.query = nil
+ c.handler = NotFoundHandler
+ c.store = nil
+ c.path = ""
+ c.pnames = nil
+ // NOTE: Don't reset because it has to have length c.echo.maxParam at all times
+ // c.pvalues = nil
+}
diff --git a/src/dma/vendor/github.com/labstack/echo/echo.go b/src/dma/vendor/github.com/labstack/echo/echo.go
new file mode 100644
index 00000000..41ac6b5e
--- /dev/null
+++ b/src/dma/vendor/github.com/labstack/echo/echo.go
@@ -0,0 +1,781 @@
+/*
+Package echo implements high performance, minimalist Go web framework.
+
+Example:
+
+ package main
+
+ import (
+ "net/http"
+
+ "github.com/labstack/echo"
+ "github.com/labstack/echo/middleware"
+ )
+
+ // Handler
+ func hello(c echo.Context) error {
+ return c.String(http.StatusOK, "Hello, World!")
+ }
+
+ func main() {
+ // Echo instance
+ e := echo.New()
+
+ // Middleware
+ e.Use(middleware.Logger())
+ e.Use(middleware.Recover())
+
+ // Routes
+ e.GET("/", hello)
+
+ // Start server
+ e.Logger.Fatal(e.Start(":1323"))
+ }
+
+Learn more at https://echo.labstack.com
+*/
+package echo
+
+import (
+ "bytes"
+ stdContext "context"
+ "crypto/tls"
+ "errors"
+ "fmt"
+ "io"
+ stdLog "log"
+ "net"
+ "net/http"
+ "net/url"
+ "path"
+ "path/filepath"
+ "reflect"
+ "runtime"
+ "sync"
+ "time"
+
+ "github.com/labstack/gommon/color"
+ "github.com/labstack/gommon/log"
+ "golang.org/x/crypto/acme/autocert"
+)
+
+type (
+ // Echo is the top-level framework instance.
+ Echo struct {
+ stdLogger *stdLog.Logger
+ colorer *color.Color
+ premiddleware []MiddlewareFunc
+ middleware []MiddlewareFunc
+ maxParam *int
+ router *Router
+ notFoundHandler HandlerFunc
+ pool sync.Pool
+ Server *http.Server
+ TLSServer *http.Server
+ Listener net.Listener
+ TLSListener net.Listener
+ AutoTLSManager autocert.Manager
+ DisableHTTP2 bool
+ Debug bool
+ HideBanner bool
+ HidePort bool
+ HTTPErrorHandler HTTPErrorHandler
+ Binder Binder
+ Validator Validator
+ Renderer Renderer
+ Logger Logger
+ }
+
+ // Route contains a handler and information for matching against requests.
+ Route struct {
+ Method string `json:"method"`
+ Path string `json:"path"`
+ Name string `json:"name"`
+ }
+
+ // HTTPError represents an error that occurred while handling a request.
+ HTTPError struct {
+ Code int
+ Message interface{}
+ Internal error // Stores the error returned by an external dependency
+ }
+
+ // MiddlewareFunc defines a function to process middleware.
+ MiddlewareFunc func(HandlerFunc) HandlerFunc
+
+ // HandlerFunc defines a function to server HTTP requests.
+ HandlerFunc func(Context) error
+
+ // HTTPErrorHandler is a centralized HTTP error handler.
+ HTTPErrorHandler func(error, Context)
+
+ // Validator is the interface that wraps the Validate function.
+ Validator interface {
+ Validate(i interface{}) error
+ }
+
+ // Renderer is the interface that wraps the Render function.
+ Renderer interface {
+ Render(io.Writer, string, interface{}, Context) error
+ }
+
+ // Map defines a generic map of type `map[string]interface{}`.
+ Map map[string]interface{}
+
+ // i is the interface for Echo and Group.
+ i interface {
+ GET(string, HandlerFunc, ...MiddlewareFunc) *Route
+ }
+)
+
+// HTTP methods
+const (
+ CONNECT = "CONNECT"
+ DELETE = "DELETE"
+ GET = "GET"
+ HEAD = "HEAD"
+ OPTIONS = "OPTIONS"
+ PATCH = "PATCH"
+ POST = "POST"
+ PROPFIND = "PROPFIND"
+ PUT = "PUT"
+ TRACE = "TRACE"
+)
+
+// MIME types
+const (
+ MIMEApplicationJSON = "application/json"
+ MIMEApplicationJSONCharsetUTF8 = MIMEApplicationJSON + "; " + charsetUTF8
+ MIMEApplicationJavaScript = "application/javascript"
+ MIMEApplicationJavaScriptCharsetUTF8 = MIMEApplicationJavaScript + "; " + charsetUTF8
+ MIMEApplicationXML = "application/xml"
+ MIMEApplicationXMLCharsetUTF8 = MIMEApplicationXML + "; " + charsetUTF8
+ MIMETextXML = "text/xml"
+ MIMETextXMLCharsetUTF8 = MIMETextXML + "; " + charsetUTF8
+ MIMEApplicationForm = "application/x-www-form-urlencoded"
+ MIMEApplicationProtobuf = "application/protobuf"
+ MIMEApplicationMsgpack = "application/msgpack"
+ MIMETextHTML = "text/html"
+ MIMETextHTMLCharsetUTF8 = MIMETextHTML + "; " + charsetUTF8
+ MIMETextPlain = "text/plain"
+ MIMETextPlainCharsetUTF8 = MIMETextPlain + "; " + charsetUTF8
+ MIMEMultipartForm = "multipart/form-data"
+ MIMEOctetStream = "application/octet-stream"
+)
+
+const (
+ charsetUTF8 = "charset=UTF-8"
+)
+
+// Headers
+const (
+ HeaderAccept = "Accept"
+ HeaderAcceptEncoding = "Accept-Encoding"
+ HeaderAllow = "Allow"
+ HeaderAuthorization = "Authorization"
+ HeaderContentDisposition = "Content-Disposition"
+ HeaderContentEncoding = "Content-Encoding"
+ HeaderContentLength = "Content-Length"
+ HeaderContentType = "Content-Type"
+ HeaderCookie = "Cookie"
+ HeaderSetCookie = "Set-Cookie"
+ HeaderIfModifiedSince = "If-Modified-Since"
+ HeaderLastModified = "Last-Modified"
+ HeaderLocation = "Location"
+ HeaderUpgrade = "Upgrade"
+ HeaderVary = "Vary"
+ HeaderWWWAuthenticate = "WWW-Authenticate"
+ HeaderXForwardedFor = "X-Forwarded-For"
+ HeaderXForwardedProto = "X-Forwarded-Proto"
+ HeaderXForwardedProtocol = "X-Forwarded-Protocol"
+ HeaderXForwardedSsl = "X-Forwarded-Ssl"
+ HeaderXUrlScheme = "X-Url-Scheme"
+ HeaderXHTTPMethodOverride = "X-HTTP-Method-Override"
+ HeaderXRealIP = "X-Real-IP"
+ HeaderXRequestID = "X-Request-ID"
+ HeaderXRequestedWith = "X-Requested-With"
+ HeaderServer = "Server"
+ HeaderOrigin = "Origin"
+
+ // Access control
+ HeaderAccessControlRequestMethod = "Access-Control-Request-Method"
+ HeaderAccessControlRequestHeaders = "Access-Control-Request-Headers"
+ HeaderAccessControlAllowOrigin = "Access-Control-Allow-Origin"
+ HeaderAccessControlAllowMethods = "Access-Control-Allow-Methods"
+ HeaderAccessControlAllowHeaders = "Access-Control-Allow-Headers"
+ HeaderAccessControlAllowCredentials = "Access-Control-Allow-Credentials"
+ HeaderAccessControlExposeHeaders = "Access-Control-Expose-Headers"
+ HeaderAccessControlMaxAge = "Access-Control-Max-Age"
+
+ // Security
+ HeaderStrictTransportSecurity = "Strict-Transport-Security"
+ HeaderXContentTypeOptions = "X-Content-Type-Options"
+ HeaderXXSSProtection = "X-XSS-Protection"
+ HeaderXFrameOptions = "X-Frame-Options"
+ HeaderContentSecurityPolicy = "Content-Security-Policy"
+ HeaderXCSRFToken = "X-CSRF-Token"
+)
+
+const (
+ Version = "3.3.5"
+ website = "https://echo.labstack.com"
+ // http://patorjk.com/software/taag/#p=display&f=Small%20Slant&t=Echo
+ banner = `
+ ____ __
+ / __/___/ / ___
+ / _// __/ _ \/ _ \
+/___/\__/_//_/\___/ %s
+High performance, minimalist Go web framework
+%s
+____________________________________O/_______
+ O\
+`
+)
+
+var (
+ methods = [...]string{
+ CONNECT,
+ DELETE,
+ GET,
+ HEAD,
+ OPTIONS,
+ PATCH,
+ POST,
+ PROPFIND,
+ PUT,
+ TRACE,
+ }
+)
+
+// Errors
+var (
+ ErrUnsupportedMediaType = NewHTTPError(http.StatusUnsupportedMediaType)
+ ErrNotFound = NewHTTPError(http.StatusNotFound)
+ ErrUnauthorized = NewHTTPError(http.StatusUnauthorized)
+ ErrForbidden = NewHTTPError(http.StatusForbidden)
+ ErrMethodNotAllowed = NewHTTPError(http.StatusMethodNotAllowed)
+ ErrStatusRequestEntityTooLarge = NewHTTPError(http.StatusRequestEntityTooLarge)
+ ErrValidatorNotRegistered = errors.New("validator not registered")
+ ErrRendererNotRegistered = errors.New("renderer not registered")
+ ErrInvalidRedirectCode = errors.New("invalid redirect status code")
+ ErrCookieNotFound = errors.New("cookie not found")
+)
+
+// Error handlers
+var (
+ NotFoundHandler = func(c Context) error {
+ return ErrNotFound
+ }
+
+ MethodNotAllowedHandler = func(c Context) error {
+ return ErrMethodNotAllowed
+ }
+)
+
+// New creates an instance of Echo.
+func New() (e *Echo) {
+ e = &Echo{
+ Server: new(http.Server),
+ TLSServer: new(http.Server),
+ AutoTLSManager: autocert.Manager{
+ Prompt: autocert.AcceptTOS,
+ },
+ Logger: log.New("echo"),
+ colorer: color.New(),
+ maxParam: new(int),
+ }
+ e.Server.Handler = e
+ e.TLSServer.Handler = e
+ e.HTTPErrorHandler = e.DefaultHTTPErrorHandler
+ e.Binder = &DefaultBinder{}
+ e.Logger.SetLevel(log.ERROR)
+ e.stdLogger = stdLog.New(e.Logger.Output(), e.Logger.Prefix()+": ", 0)
+ e.pool.New = func() interface{} {
+ return e.NewContext(nil, nil)
+ }
+ e.router = NewRouter(e)
+ return
+}
+
+// NewContext returns a Context instance.
+func (e *Echo) NewContext(r *http.Request, w http.ResponseWriter) Context {
+ return &context{
+ request: r,
+ response: NewResponse(w, e),
+ store: make(Map),
+ echo: e,
+ pvalues: make([]string, *e.maxParam),
+ handler: NotFoundHandler,
+ }
+}
+
+// Router returns router.
+func (e *Echo) Router() *Router {
+ return e.router
+}
+
+// DefaultHTTPErrorHandler is the default HTTP error handler. It sends a JSON response
+// with status code.
+func (e *Echo) DefaultHTTPErrorHandler(err error, c Context) {
+ var (
+ code = http.StatusInternalServerError
+ msg interface{}
+ )
+
+ if he, ok := err.(*HTTPError); ok {
+ code = he.Code
+ msg = he.Message
+ if he.Internal != nil {
+ msg = fmt.Sprintf("%v, %v", err, he.Internal)
+ }
+ } else if e.Debug {
+ msg = err.Error()
+ } else {
+ msg = http.StatusText(code)
+ }
+ if _, ok := msg.(string); ok {
+ msg = Map{"message": msg}
+ }
+
+ e.Logger.Error(err)
+
+ // Send response
+ if !c.Response().Committed {
+ if c.Request().Method == HEAD { // Issue #608
+ err = c.NoContent(code)
+ } else {
+ err = c.JSON(code, msg)
+ }
+ if err != nil {
+ e.Logger.Error(err)
+ }
+ }
+}
+
+// Pre adds middleware to the chain which is run before router.
+func (e *Echo) Pre(middleware ...MiddlewareFunc) {
+ e.premiddleware = append(e.premiddleware, middleware...)
+}
+
+// Use adds middleware to the chain which is run after router.
+func (e *Echo) Use(middleware ...MiddlewareFunc) {
+ e.middleware = append(e.middleware, middleware...)
+}
+
+// CONNECT registers a new CONNECT route for a path with matching handler in the
+// router with optional route-level middleware.
+func (e *Echo) CONNECT(path string, h HandlerFunc, m ...MiddlewareFunc) *Route {
+ return e.Add(CONNECT, path, h, m...)
+}
+
+// DELETE registers a new DELETE route for a path with matching handler in the router
+// with optional route-level middleware.
+func (e *Echo) DELETE(path string, h HandlerFunc, m ...MiddlewareFunc) *Route {
+ return e.Add(DELETE, path, h, m...)
+}
+
+// GET registers a new GET route for a path with matching handler in the router
+// with optional route-level middleware.
+func (e *Echo) GET(path string, h HandlerFunc, m ...MiddlewareFunc) *Route {
+ return e.Add(GET, path, h, m...)
+}
+
+// HEAD registers a new HEAD route for a path with matching handler in the
+// router with optional route-level middleware.
+func (e *Echo) HEAD(path string, h HandlerFunc, m ...MiddlewareFunc) *Route {
+ return e.Add(HEAD, path, h, m...)
+}
+
+// OPTIONS registers a new OPTIONS route for a path with matching handler in the
+// router with optional route-level middleware.
+func (e *Echo) OPTIONS(path string, h HandlerFunc, m ...MiddlewareFunc) *Route {
+ return e.Add(OPTIONS, path, h, m...)
+}
+
+// PATCH registers a new PATCH route for a path with matching handler in the
+// router with optional route-level middleware.
+func (e *Echo) PATCH(path string, h HandlerFunc, m ...MiddlewareFunc) *Route {
+ return e.Add(PATCH, path, h, m...)
+}
+
+// POST registers a new POST route for a path with matching handler in the
+// router with optional route-level middleware.
+func (e *Echo) POST(path string, h HandlerFunc, m ...MiddlewareFunc) *Route {
+ return e.Add(POST, path, h, m...)
+}
+
+// PUT registers a new PUT route for a path with matching handler in the
+// router with optional route-level middleware.
+func (e *Echo) PUT(path string, h HandlerFunc, m ...MiddlewareFunc) *Route {
+ return e.Add(PUT, path, h, m...)
+}
+
+// TRACE registers a new TRACE route for a path with matching handler in the
+// router with optional route-level middleware.
+func (e *Echo) TRACE(path string, h HandlerFunc, m ...MiddlewareFunc) *Route {
+ return e.Add(TRACE, path, h, m...)
+}
+
+// Any registers a new route for all HTTP methods and path with matching handler
+// in the router with optional route-level middleware.
+func (e *Echo) Any(path string, handler HandlerFunc, middleware ...MiddlewareFunc) []*Route {
+ routes := make([]*Route, len(methods))
+ for i, m := range methods {
+ routes[i] = e.Add(m, path, handler, middleware...)
+ }
+ return routes
+}
+
+// Match registers a new route for multiple HTTP methods and path with matching
+// handler in the router with optional route-level middleware.
+func (e *Echo) Match(methods []string, path string, handler HandlerFunc, middleware ...MiddlewareFunc) []*Route {
+ routes := make([]*Route, len(methods))
+ for i, m := range methods {
+ routes[i] = e.Add(m, path, handler, middleware...)
+ }
+ return routes
+}
+
+// Static registers a new route with path prefix to serve static files from the
+// provided root directory.
+func (e *Echo) Static(prefix, root string) *Route {
+ if root == "" {
+ root = "." // For security we want to restrict to CWD.
+ }
+ return static(e, prefix, root)
+}
+
+func static(i i, prefix, root string) *Route {
+ h := func(c Context) error {
+ p, err := url.PathUnescape(c.Param("*"))
+ if err != nil {
+ return err
+ }
+ name := filepath.Join(root, path.Clean("/"+p)) // "/"+ for security
+ return c.File(name)
+ }
+ i.GET(prefix, h)
+ if prefix == "/" {
+ return i.GET(prefix+"*", h)
+ }
+
+ return i.GET(prefix+"/*", h)
+}
+
+// File registers a new route with path to serve a static file.
+func (e *Echo) File(path, file string) *Route {
+ return e.GET(path, func(c Context) error {
+ return c.File(file)
+ })
+}
+
+// Add registers a new route for an HTTP method and path with matching handler
+// in the router with optional route-level middleware.
+func (e *Echo) Add(method, path string, handler HandlerFunc, middleware ...MiddlewareFunc) *Route {
+ name := handlerName(handler)
+ e.router.Add(method, path, func(c Context) error {
+ h := handler
+ // Chain middleware
+ for i := len(middleware) - 1; i >= 0; i-- {
+ h = middleware[i](h)
+ }
+ return h(c)
+ })
+ r := &Route{
+ Method: method,
+ Path: path,
+ Name: name,
+ }
+ e.router.routes[method+path] = r
+ return r
+}
+
+// Group creates a new router group with prefix and optional group-level middleware.
+func (e *Echo) Group(prefix string, m ...MiddlewareFunc) (g *Group) {
+ g = &Group{prefix: prefix, echo: e}
+ g.Use(m...)
+ return
+}
+
+// URI generates a URI from handler.
+func (e *Echo) URI(handler HandlerFunc, params ...interface{}) string {
+ name := handlerName(handler)
+ return e.Reverse(name, params...)
+}
+
+// URL is an alias for `URI` function.
+func (e *Echo) URL(h HandlerFunc, params ...interface{}) string {
+ return e.URI(h, params...)
+}
+
+// Reverse generates an URL from route name and provided parameters.
+func (e *Echo) Reverse(name string, params ...interface{}) string {
+ uri := new(bytes.Buffer)
+ ln := len(params)
+ n := 0
+ for _, r := range e.router.routes {
+ if r.Name == name {
+ for i, l := 0, len(r.Path); i < l; i++ {
+ if r.Path[i] == ':' && n < ln {
+ for ; i < l && r.Path[i] != '/'; i++ {
+ }
+ uri.WriteString(fmt.Sprintf("%v", params[n]))
+ n++
+ }
+ if i < l {
+ uri.WriteByte(r.Path[i])
+ }
+ }
+ break
+ }
+ }
+ return uri.String()
+}
+
+// Routes returns the registered routes.
+func (e *Echo) Routes() []*Route {
+ routes := make([]*Route, 0, len(e.router.routes))
+ for _, v := range e.router.routes {
+ routes = append(routes, v)
+ }
+ return routes
+}
+
+// AcquireContext returns an empty `Context` instance from the pool.
+// You must return the context by calling `ReleaseContext()`.
+func (e *Echo) AcquireContext() Context {
+ return e.pool.Get().(Context)
+}
+
+// ReleaseContext returns the `Context` instance back to the pool.
+// You must call it after `AcquireContext()`.
+func (e *Echo) ReleaseContext(c Context) {
+ e.pool.Put(c)
+}
+
+// ServeHTTP implements `http.Handler` interface, which serves HTTP requests.
+func (e *Echo) ServeHTTP(w http.ResponseWriter, r *http.Request) {
+ // Acquire context
+ c := e.pool.Get().(*context)
+ c.Reset(r, w)
+
+ m := r.Method
+ h := NotFoundHandler
+
+ if e.premiddleware == nil {
+ path := r.URL.RawPath
+ if path == "" {
+ path = r.URL.Path
+ }
+ e.router.Find(m, getPath(r), c)
+ h = c.Handler()
+ for i := len(e.middleware) - 1; i >= 0; i-- {
+ h = e.middleware[i](h)
+ }
+ } else {
+ h = func(c Context) error {
+ path := r.URL.RawPath
+ if path == "" {
+ path = r.URL.Path
+ }
+ e.router.Find(m, getPath(r), c)
+ h := c.Handler()
+ for i := len(e.middleware) - 1; i >= 0; i-- {
+ h = e.middleware[i](h)
+ }
+ return h(c)
+ }
+ for i := len(e.premiddleware) - 1; i >= 0; i-- {
+ h = e.premiddleware[i](h)
+ }
+ }
+
+ // Execute chain
+ if err := h(c); err != nil {
+ e.HTTPErrorHandler(err, c)
+ }
+
+ // Release context
+ e.pool.Put(c)
+}
+
+// Start starts an HTTP server.
+func (e *Echo) Start(address string) error {
+ e.Server.Addr = address
+ return e.StartServer(e.Server)
+}
+
+// StartTLS starts an HTTPS server.
+func (e *Echo) StartTLS(address string, certFile, keyFile string) (err error) {
+ if certFile == "" || keyFile == "" {
+ return errors.New("invalid tls configuration")
+ }
+ s := e.TLSServer
+ s.TLSConfig = new(tls.Config)
+ s.TLSConfig.Certificates = make([]tls.Certificate, 1)
+ s.TLSConfig.Certificates[0], err = tls.LoadX509KeyPair(certFile, keyFile)
+ if err != nil {
+ return
+ }
+ return e.startTLS(address)
+}
+
+// StartAutoTLS starts an HTTPS server using certificates automatically installed from https://letsencrypt.org.
+func (e *Echo) StartAutoTLS(address string) error {
+ if e.Listener == nil {
+ go http.ListenAndServe(":http", e.AutoTLSManager.HTTPHandler(nil))
+ }
+
+ s := e.TLSServer
+ s.TLSConfig = new(tls.Config)
+ s.TLSConfig.GetCertificate = e.AutoTLSManager.GetCertificate
+ return e.startTLS(address)
+}
+
+func (e *Echo) startTLS(address string) error {
+ s := e.TLSServer
+ s.Addr = address
+ if !e.DisableHTTP2 {
+ s.TLSConfig.NextProtos = append(s.TLSConfig.NextProtos, "h2")
+ }
+ return e.StartServer(e.TLSServer)
+}
+
+// StartServer starts a custom http server.
+func (e *Echo) StartServer(s *http.Server) (err error) {
+ // Setup
+ e.colorer.SetOutput(e.Logger.Output())
+ s.ErrorLog = e.stdLogger
+ s.Handler = e
+ if e.Debug {
+ e.Logger.SetLevel(log.DEBUG)
+ }
+
+ if !e.HideBanner {
+ e.colorer.Printf(banner, e.colorer.Red("v"+Version), e.colorer.Blue(website))
+ }
+
+ if s.TLSConfig == nil {
+ if e.Listener == nil {
+ e.Listener, err = newListener(s.Addr)
+ if err != nil {
+ return err
+ }
+ }
+ if !e.HidePort {
+ e.colorer.Printf("⇨ http server started on %s\n", e.colorer.Green(e.Listener.Addr()))
+ }
+ return s.Serve(e.Listener)
+ }
+ if e.TLSListener == nil {
+ l, err := newListener(s.Addr)
+ if err != nil {
+ return err
+ }
+ e.TLSListener = tls.NewListener(l, s.TLSConfig)
+ }
+ if !e.HidePort {
+ e.colorer.Printf("⇨ https server started on %s\n", e.colorer.Green(e.TLSListener.Addr()))
+ }
+ return s.Serve(e.TLSListener)
+}
+
+// Close immediately stops the server.
+// It internally calls `http.Server#Close()`.
+func (e *Echo) Close() error {
+ if err := e.TLSServer.Close(); err != nil {
+ return err
+ }
+ return e.Server.Close()
+}
+
+// Shutdown stops server the gracefully.
+// It internally calls `http.Server#Shutdown()`.
+func (e *Echo) Shutdown(ctx stdContext.Context) error {
+ if err := e.TLSServer.Shutdown(ctx); err != nil {
+ return err
+ }
+ return e.Server.Shutdown(ctx)
+}
+
+// NewHTTPError creates a new HTTPError instance.
+func NewHTTPError(code int, message ...interface{}) *HTTPError {
+ he := &HTTPError{Code: code, Message: http.StatusText(code)}
+ if len(message) > 0 {
+ he.Message = message[0]
+ }
+ return he
+}
+
+// Error makes it compatible with `error` interface.
+func (he *HTTPError) Error() string {
+ return fmt.Sprintf("code=%d, message=%v", he.Code, he.Message)
+}
+
+// WrapHandler wraps `http.Handler` into `echo.HandlerFunc`.
+func WrapHandler(h http.Handler) HandlerFunc {
+ return func(c Context) error {
+ h.ServeHTTP(c.Response(), c.Request())
+ return nil
+ }
+}
+
+// WrapMiddleware wraps `func(http.Handler) http.Handler` into `echo.MiddlewareFunc`
+func WrapMiddleware(m func(http.Handler) http.Handler) MiddlewareFunc {
+ return func(next HandlerFunc) HandlerFunc {
+ return func(c Context) (err error) {
+ m(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ c.SetRequest(r)
+ err = next(c)
+ })).ServeHTTP(c.Response(), c.Request())
+ return
+ }
+ }
+}
+
+func getPath(r *http.Request) string {
+ path := r.URL.RawPath
+ if path == "" {
+ path = r.URL.Path
+ }
+ return path
+}
+
+func handlerName(h HandlerFunc) string {
+ t := reflect.ValueOf(h).Type()
+ if t.Kind() == reflect.Func {
+ return runtime.FuncForPC(reflect.ValueOf(h).Pointer()).Name()
+ }
+ return t.String()
+}
+
+// // PathUnescape is wraps `url.PathUnescape`
+// func PathUnescape(s string) (string, error) {
+// return url.PathUnescape(s)
+// }
+
+// tcpKeepAliveListener sets TCP keep-alive timeouts on accepted
+// connections. It's used by ListenAndServe and ListenAndServeTLS so
+// dead TCP connections (e.g. closing laptop mid-download) eventually
+// go away.
+type tcpKeepAliveListener struct {
+ *net.TCPListener
+}
+
+func (ln tcpKeepAliveListener) Accept() (c net.Conn, err error) {
+ tc, err := ln.AcceptTCP()
+ if err != nil {
+ return
+ }
+ tc.SetKeepAlive(true)
+ tc.SetKeepAlivePeriod(3 * time.Minute)
+ return tc, nil
+}
+
+func newListener(address string) (*tcpKeepAliveListener, error) {
+ l, err := net.Listen("tcp", address)
+ if err != nil {
+ return nil, err
+ }
+ return &tcpKeepAliveListener{l.(*net.TCPListener)}, nil
+}
diff --git a/src/dma/vendor/github.com/labstack/echo/group.go b/src/dma/vendor/github.com/labstack/echo/group.go
new file mode 100644
index 00000000..5257e83c
--- /dev/null
+++ b/src/dma/vendor/github.com/labstack/echo/group.go
@@ -0,0 +1,120 @@
+package echo
+
+import (
+ "path"
+)
+
+type (
+ // Group is a set of sub-routes for a specified route. It can be used for inner
+ // routes that share a common middleware or functionality that should be separate
+ // from the parent echo instance while still inheriting from it.
+ Group struct {
+ prefix string
+ middleware []MiddlewareFunc
+ echo *Echo
+ }
+)
+
+// Use implements `Echo#Use()` for sub-routes within the Group.
+func (g *Group) Use(middleware ...MiddlewareFunc) {
+ g.middleware = append(g.middleware, middleware...)
+ // Allow all requests to reach the group as they might get dropped if router
+ // doesn't find a match, making none of the group middleware process.
+ for _, p := range []string{"", "/*"} {
+ g.echo.Any(path.Clean(g.prefix+p), func(c Context) error {
+ return NotFoundHandler(c)
+ }, g.middleware...)
+ }
+}
+
+// CONNECT implements `Echo#CONNECT()` for sub-routes within the Group.
+func (g *Group) CONNECT(path string, h HandlerFunc, m ...MiddlewareFunc) *Route {
+ return g.Add(CONNECT, path, h, m...)
+}
+
+// DELETE implements `Echo#DELETE()` for sub-routes within the Group.
+func (g *Group) DELETE(path string, h HandlerFunc, m ...MiddlewareFunc) *Route {
+ return g.Add(DELETE, path, h, m...)
+}
+
+// GET implements `Echo#GET()` for sub-routes within the Group.
+func (g *Group) GET(path string, h HandlerFunc, m ...MiddlewareFunc) *Route {
+ return g.Add(GET, path, h, m...)
+}
+
+// HEAD implements `Echo#HEAD()` for sub-routes within the Group.
+func (g *Group) HEAD(path string, h HandlerFunc, m ...MiddlewareFunc) *Route {
+ return g.Add(HEAD, path, h, m...)
+}
+
+// OPTIONS implements `Echo#OPTIONS()` for sub-routes within the Group.
+func (g *Group) OPTIONS(path string, h HandlerFunc, m ...MiddlewareFunc) *Route {
+ return g.Add(OPTIONS, path, h, m...)
+}
+
+// PATCH implements `Echo#PATCH()` for sub-routes within the Group.
+func (g *Group) PATCH(path string, h HandlerFunc, m ...MiddlewareFunc) *Route {
+ return g.Add(PATCH, path, h, m...)
+}
+
+// POST implements `Echo#POST()` for sub-routes within the Group.
+func (g *Group) POST(path string, h HandlerFunc, m ...MiddlewareFunc) *Route {
+ return g.Add(POST, path, h, m...)
+}
+
+// PUT implements `Echo#PUT()` for sub-routes within the Group.
+func (g *Group) PUT(path string, h HandlerFunc, m ...MiddlewareFunc) *Route {
+ return g.Add(PUT, path, h, m...)
+}
+
+// TRACE implements `Echo#TRACE()` for sub-routes within the Group.
+func (g *Group) TRACE(path string, h HandlerFunc, m ...MiddlewareFunc) *Route {
+ return g.Add(TRACE, path, h, m...)
+}
+
+// Any implements `Echo#Any()` for sub-routes within the Group.
+func (g *Group) Any(path string, handler HandlerFunc, middleware ...MiddlewareFunc) []*Route {
+ routes := make([]*Route, len(methods))
+ for i, m := range methods {
+ routes[i] = g.Add(m, path, handler, middleware...)
+ }
+ return routes
+}
+
+// Match implements `Echo#Match()` for sub-routes within the Group.
+func (g *Group) Match(methods []string, path string, handler HandlerFunc, middleware ...MiddlewareFunc) []*Route {
+ routes := make([]*Route, len(methods))
+ for i, m := range methods {
+ routes[i] = g.Add(m, path, handler, middleware...)
+ }
+ return routes
+}
+
+// Group creates a new sub-group with prefix and optional sub-group-level middleware.
+func (g *Group) Group(prefix string, middleware ...MiddlewareFunc) *Group {
+ m := make([]MiddlewareFunc, 0, len(g.middleware)+len(middleware))
+ m = append(m, g.middleware...)
+ m = append(m, middleware...)
+ return g.echo.Group(g.prefix+prefix, m...)
+}
+
+// Static implements `Echo#Static()` for sub-routes within the Group.
+func (g *Group) Static(prefix, root string) {
+ static(g, prefix, root)
+}
+
+// File implements `Echo#File()` for sub-routes within the Group.
+func (g *Group) File(path, file string) {
+ g.echo.File(g.prefix+path, file)
+}
+
+// Add implements `Echo#Add()` for sub-routes within the Group.
+func (g *Group) Add(method, path string, handler HandlerFunc, middleware ...MiddlewareFunc) *Route {
+ // Combine into a new slice to avoid accidentally passing the same slice for
+ // multiple routes, which would lead to later add() calls overwriting the
+ // middleware from earlier calls.
+ m := make([]MiddlewareFunc, 0, len(g.middleware)+len(middleware))
+ m = append(m, g.middleware...)
+ m = append(m, middleware...)
+ return g.echo.Add(method, g.prefix+path, handler, m...)
+}
diff --git a/src/dma/vendor/github.com/labstack/echo/log.go b/src/dma/vendor/github.com/labstack/echo/log.go
new file mode 100644
index 00000000..b194c39c
--- /dev/null
+++ b/src/dma/vendor/github.com/labstack/echo/log.go
@@ -0,0 +1,40 @@
+package echo
+
+import (
+ "io"
+
+ "github.com/labstack/gommon/log"
+)
+
+type (
+ // Logger defines the logging interface.
+ Logger interface {
+ Output() io.Writer
+ SetOutput(w io.Writer)
+ Prefix() string
+ SetPrefix(p string)
+ Level() log.Lvl
+ SetLevel(v log.Lvl)
+ Print(i ...interface{})
+ Printf(format string, args ...interface{})
+ Printj(j log.JSON)
+ Debug(i ...interface{})
+ Debugf(format string, args ...interface{})
+ Debugj(j log.JSON)
+ Info(i ...interface{})
+ Infof(format string, args ...interface{})
+ Infoj(j log.JSON)
+ Warn(i ...interface{})
+ Warnf(format string, args ...interface{})
+ Warnj(j log.JSON)
+ Error(i ...interface{})
+ Errorf(format string, args ...interface{})
+ Errorj(j log.JSON)
+ Fatal(i ...interface{})
+ Fatalj(j log.JSON)
+ Fatalf(format string, args ...interface{})
+ Panic(i ...interface{})
+ Panicj(j log.JSON)
+ Panicf(format string, args ...interface{})
+ }
+)
diff --git a/src/dma/vendor/github.com/labstack/echo/response.go b/src/dma/vendor/github.com/labstack/echo/response.go
new file mode 100644
index 00000000..6244783b
--- /dev/null
+++ b/src/dma/vendor/github.com/labstack/echo/response.go
@@ -0,0 +1,110 @@
+package echo
+
+import (
+ "bufio"
+ "net"
+ "net/http"
+)
+
+type (
+ // Response wraps an http.ResponseWriter and implements its interface to be used
+ // by an HTTP handler to construct an HTTP response.
+ // See: https://golang.org/pkg/net/http/#ResponseWriter
+ Response struct {
+ echo *Echo
+ beforeFuncs []func()
+ afterFuncs []func()
+ Writer http.ResponseWriter
+ Status int
+ Size int64
+ Committed bool
+ }
+)
+
+// NewResponse creates a new instance of Response.
+func NewResponse(w http.ResponseWriter, e *Echo) (r *Response) {
+ return &Response{Writer: w, echo: e}
+}
+
+// Header returns the header map for the writer that will be sent by
+// WriteHeader. Changing the header after a call to WriteHeader (or Write) has
+// no effect unless the modified headers were declared as trailers by setting
+// the "Trailer" header before the call to WriteHeader (see example)
+// To suppress implicit response headers, set their value to nil.
+// Example: https://golang.org/pkg/net/http/#example_ResponseWriter_trailers
+func (r *Response) Header() http.Header {
+ return r.Writer.Header()
+}
+
+// Before registers a function which is called just before the response is written.
+func (r *Response) Before(fn func()) {
+ r.beforeFuncs = append(r.beforeFuncs, fn)
+}
+
+// After registers a function which is called just after the response is written.
+// If the `Content-Length` is unknown, none of the after function is executed.
+func (r *Response) After(fn func()) {
+ r.afterFuncs = append(r.afterFuncs, fn)
+}
+
+// WriteHeader sends an HTTP response header with status code. If WriteHeader is
+// not called explicitly, the first call to Write will trigger an implicit
+// WriteHeader(http.StatusOK). Thus explicit calls to WriteHeader are mainly
+// used to send error codes.
+func (r *Response) WriteHeader(code int) {
+ if r.Committed {
+ r.echo.Logger.Warn("response already committed")
+ return
+ }
+ for _, fn := range r.beforeFuncs {
+ fn()
+ }
+ r.Status = code
+ r.Writer.WriteHeader(code)
+ r.Committed = true
+}
+
+// Write writes the data to the connection as part of an HTTP reply.
+func (r *Response) Write(b []byte) (n int, err error) {
+ if !r.Committed {
+ r.WriteHeader(http.StatusOK)
+ }
+ n, err = r.Writer.Write(b)
+ r.Size += int64(n)
+ for _, fn := range r.afterFuncs {
+ fn()
+ }
+ return
+}
+
+// Flush implements the http.Flusher interface to allow an HTTP handler to flush
+// buffered data to the client.
+// See [http.Flusher](https://golang.org/pkg/net/http/#Flusher)
+func (r *Response) Flush() {
+ r.Writer.(http.Flusher).Flush()
+}
+
+// Hijack implements the http.Hijacker interface to allow an HTTP handler to
+// take over the connection.
+// See [http.Hijacker](https://golang.org/pkg/net/http/#Hijacker)
+func (r *Response) Hijack() (net.Conn, *bufio.ReadWriter, error) {
+ return r.Writer.(http.Hijacker).Hijack()
+}
+
+// CloseNotify implements the http.CloseNotifier interface to allow detecting
+// when the underlying connection has gone away.
+// This mechanism can be used to cancel long operations on the server if the
+// client has disconnected before the response is ready.
+// See [http.CloseNotifier](https://golang.org/pkg/net/http/#CloseNotifier)
+func (r *Response) CloseNotify() <-chan bool {
+ return r.Writer.(http.CloseNotifier).CloseNotify()
+}
+
+func (r *Response) reset(w http.ResponseWriter) {
+ r.beforeFuncs = nil
+ r.afterFuncs = nil
+ r.Writer = w
+ r.Size = 0
+ r.Status = http.StatusOK
+ r.Committed = false
+}
diff --git a/src/dma/vendor/github.com/labstack/echo/router.go b/src/dma/vendor/github.com/labstack/echo/router.go
new file mode 100644
index 00000000..ff53da87
--- /dev/null
+++ b/src/dma/vendor/github.com/labstack/echo/router.go
@@ -0,0 +1,434 @@
+package echo
+
+type (
+ // Router is the registry of all registered routes for an `Echo` instance for
+ // request matching and URL path parameter parsing.
+ Router struct {
+ tree *node
+ routes map[string]*Route
+ echo *Echo
+ }
+ node struct {
+ kind kind
+ label byte
+ prefix string
+ parent *node
+ children children
+ ppath string
+ pnames []string
+ methodHandler *methodHandler
+ }
+ kind uint8
+ children []*node
+ methodHandler struct {
+ connect HandlerFunc
+ delete HandlerFunc
+ get HandlerFunc
+ head HandlerFunc
+ options HandlerFunc
+ patch HandlerFunc
+ post HandlerFunc
+ propfind HandlerFunc
+ put HandlerFunc
+ trace HandlerFunc
+ }
+)
+
+const (
+ skind kind = iota
+ pkind
+ akind
+)
+
+// NewRouter returns a new Router instance.
+func NewRouter(e *Echo) *Router {
+ return &Router{
+ tree: &node{
+ methodHandler: new(methodHandler),
+ },
+ routes: map[string]*Route{},
+ echo: e,
+ }
+}
+
+// Add registers a new route for method and path with matching handler.
+func (r *Router) Add(method, path string, h HandlerFunc) {
+ // Validate path
+ if path == "" {
+ panic("echo: path cannot be empty")
+ }
+ if path[0] != '/' {
+ path = "/" + path
+ }
+ pnames := []string{} // Param names
+ ppath := path // Pristine path
+
+ for i, l := 0, len(path); i < l; i++ {
+ if path[i] == ':' {
+ j := i + 1
+
+ r.insert(method, path[:i], nil, skind, "", nil)
+ for ; i < l && path[i] != '/'; i++ {
+ }
+
+ pnames = append(pnames, path[j:i])
+ path = path[:j] + path[i:]
+ i, l = j, len(path)
+
+ if i == l {
+ r.insert(method, path[:i], h, pkind, ppath, pnames)
+ return
+ }
+ r.insert(method, path[:i], nil, pkind, ppath, pnames)
+ } else if path[i] == '*' {
+ r.insert(method, path[:i], nil, skind, "", nil)
+ pnames = append(pnames, "*")
+ r.insert(method, path[:i+1], h, akind, ppath, pnames)
+ return
+ }
+ }
+
+ r.insert(method, path, h, skind, ppath, pnames)
+}
+
+func (r *Router) insert(method, path string, h HandlerFunc, t kind, ppath string, pnames []string) {
+ // Adjust max param
+ l := len(pnames)
+ if *r.echo.maxParam < l {
+ *r.echo.maxParam = l
+ }
+
+ cn := r.tree // Current node as root
+ if cn == nil {
+ panic("echo: invalid method")
+ }
+ search := path
+
+ for {
+ sl := len(search)
+ pl := len(cn.prefix)
+ l := 0
+
+ // LCP
+ max := pl
+ if sl < max {
+ max = sl
+ }
+ for ; l < max && search[l] == cn.prefix[l]; l++ {
+ }
+
+ if l == 0 {
+ // At root node
+ cn.label = search[0]
+ cn.prefix = search
+ if h != nil {
+ cn.kind = t
+ cn.addHandler(method, h)
+ cn.ppath = ppath
+ cn.pnames = pnames
+ }
+ } else if l < pl {
+ // Split node
+ n := newNode(cn.kind, cn.prefix[l:], cn, cn.children, cn.methodHandler, cn.ppath, cn.pnames)
+
+ // Reset parent node
+ cn.kind = skind
+ cn.label = cn.prefix[0]
+ cn.prefix = cn.prefix[:l]
+ cn.children = nil
+ cn.methodHandler = new(methodHandler)
+ cn.ppath = ""
+ cn.pnames = nil
+
+ cn.addChild(n)
+
+ if l == sl {
+ // At parent node
+ cn.kind = t
+ cn.addHandler(method, h)
+ cn.ppath = ppath
+ cn.pnames = pnames
+ } else {
+ // Create child node
+ n = newNode(t, search[l:], cn, nil, new(methodHandler), ppath, pnames)
+ n.addHandler(method, h)
+ cn.addChild(n)
+ }
+ } else if l < sl {
+ search = search[l:]
+ c := cn.findChildWithLabel(search[0])
+ if c != nil {
+ // Go deeper
+ cn = c
+ continue
+ }
+ // Create child node
+ n := newNode(t, search, cn, nil, new(methodHandler), ppath, pnames)
+ n.addHandler(method, h)
+ cn.addChild(n)
+ } else {
+ // Node already exists
+ if h != nil {
+ cn.addHandler(method, h)
+ cn.ppath = ppath
+ if len(cn.pnames) == 0 { // Issue #729
+ cn.pnames = pnames
+ }
+ }
+ }
+ return
+ }
+}
+
+func newNode(t kind, pre string, p *node, c children, mh *methodHandler, ppath string, pnames []string) *node {
+ return &node{
+ kind: t,
+ label: pre[0],
+ prefix: pre,
+ parent: p,
+ children: c,
+ ppath: ppath,
+ pnames: pnames,
+ methodHandler: mh,
+ }
+}
+
+func (n *node) addChild(c *node) {
+ n.children = append(n.children, c)
+}
+
+func (n *node) findChild(l byte, t kind) *node {
+ for _, c := range n.children {
+ if c.label == l && c.kind == t {
+ return c
+ }
+ }
+ return nil
+}
+
+func (n *node) findChildWithLabel(l byte) *node {
+ for _, c := range n.children {
+ if c.label == l {
+ return c
+ }
+ }
+ return nil
+}
+
+func (n *node) findChildByKind(t kind) *node {
+ for _, c := range n.children {
+ if c.kind == t {
+ return c
+ }
+ }
+ return nil
+}
+
+func (n *node) addHandler(method string, h HandlerFunc) {
+ switch method {
+ case CONNECT:
+ n.methodHandler.connect = h
+ case DELETE:
+ n.methodHandler.delete = h
+ case GET:
+ n.methodHandler.get = h
+ case HEAD:
+ n.methodHandler.head = h
+ case OPTIONS:
+ n.methodHandler.options = h
+ case PATCH:
+ n.methodHandler.patch = h
+ case POST:
+ n.methodHandler.post = h
+ case PROPFIND:
+ n.methodHandler.propfind = h
+ case PUT:
+ n.methodHandler.put = h
+ case TRACE:
+ n.methodHandler.trace = h
+ }
+}
+
+func (n *node) findHandler(method string) HandlerFunc {
+ switch method {
+ case CONNECT:
+ return n.methodHandler.connect
+ case DELETE:
+ return n.methodHandler.delete
+ case GET:
+ return n.methodHandler.get
+ case HEAD:
+ return n.methodHandler.head
+ case OPTIONS:
+ return n.methodHandler.options
+ case PATCH:
+ return n.methodHandler.patch
+ case POST:
+ return n.methodHandler.post
+ case PROPFIND:
+ return n.methodHandler.propfind
+ case PUT:
+ return n.methodHandler.put
+ case TRACE:
+ return n.methodHandler.trace
+ default:
+ return nil
+ }
+}
+
+func (n *node) checkMethodNotAllowed() HandlerFunc {
+ for _, m := range methods {
+ if h := n.findHandler(m); h != nil {
+ return MethodNotAllowedHandler
+ }
+ }
+ return NotFoundHandler
+}
+
+// Find lookup a handler registered for method and path. It also parses URL for path
+// parameters and load them into context.
+//
+// For performance:
+//
+// - Get context from `Echo#AcquireContext()`
+// - Reset it `Context#Reset()`
+// - Return it `Echo#ReleaseContext()`.
+func (r *Router) Find(method, path string, c Context) {
+ ctx := c.(*context)
+ ctx.path = path
+ cn := r.tree // Current node as root
+
+ var (
+ search = path
+ child *node // Child node
+ n int // Param counter
+ nk kind // Next kind
+ nn *node // Next node
+ ns string // Next search
+ pvalues = ctx.pvalues // Use the internal slice so the interface can keep the illusion of a dynamic slice
+ )
+
+ // Search order static > param > any
+ for {
+ if search == "" {
+ goto End
+ }
+
+ pl := 0 // Prefix length
+ l := 0 // LCP length
+
+ if cn.label != ':' {
+ sl := len(search)
+ pl = len(cn.prefix)
+
+ // LCP
+ max := pl
+ if sl < max {
+ max = sl
+ }
+ for ; l < max && search[l] == cn.prefix[l]; l++ {
+ }
+ }
+
+ if l == pl {
+ // Continue search
+ search = search[l:]
+ } else {
+ cn = nn
+ search = ns
+ if nk == pkind {
+ goto Param
+ } else if nk == akind {
+ goto Any
+ }
+ // Not found
+ return
+ }
+
+ if search == "" {
+ goto End
+ }
+
+ // Static node
+ if child = cn.findChild(search[0], skind); child != nil {
+ // Save next
+ if cn.prefix[len(cn.prefix)-1] == '/' { // Issue #623
+ nk = pkind
+ nn = cn
+ ns = search
+ }
+ cn = child
+ continue
+ }
+
+ // Param node
+ Param:
+ if child = cn.findChildByKind(pkind); child != nil {
+ // Issue #378
+ if len(pvalues) == n {
+ continue
+ }
+
+ // Save next
+ if cn.prefix[len(cn.prefix)-1] == '/' { // Issue #623
+ nk = akind
+ nn = cn
+ ns = search
+ }
+
+ cn = child
+ i, l := 0, len(search)
+ for ; i < l && search[i] != '/'; i++ {
+ }
+ pvalues[n] = search[:i]
+ n++
+ search = search[i:]
+ continue
+ }
+
+ // Any node
+ Any:
+ if cn = cn.findChildByKind(akind); cn == nil {
+ if nn != nil {
+ cn = nn
+ nn = cn.parent // Next (Issue #954)
+ search = ns
+ if nk == pkind {
+ goto Param
+ } else if nk == akind {
+ goto Any
+ }
+ }
+ // Not found
+ return
+ }
+ pvalues[len(cn.pnames)-1] = search
+ goto End
+ }
+
+End:
+ ctx.handler = cn.findHandler(method)
+ ctx.path = cn.ppath
+ ctx.pnames = cn.pnames
+
+ // NOTE: Slow zone...
+ if ctx.handler == nil {
+ ctx.handler = cn.checkMethodNotAllowed()
+
+ // Dig further for any, might have an empty value for *, e.g.
+ // serving a directory. Issue #207.
+ if cn = cn.findChildByKind(akind); cn == nil {
+ return
+ }
+ if h := cn.findHandler(method); h != nil {
+ ctx.handler = h
+ } else {
+ ctx.handler = cn.checkMethodNotAllowed()
+ }
+ ctx.path = cn.ppath
+ ctx.pnames = cn.pnames
+ pvalues[len(cn.pnames)-1] = ""
+ }
+
+ return
+}
diff --git a/src/dma/vendor/github.com/labstack/gommon/LICENSE b/src/dma/vendor/github.com/labstack/gommon/LICENSE
new file mode 100644
index 00000000..d2ae3edf
--- /dev/null
+++ b/src/dma/vendor/github.com/labstack/gommon/LICENSE
@@ -0,0 +1,22 @@
+The MIT License (MIT)
+
+Copyright (c) 2015 labstack
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+
diff --git a/src/dma/vendor/github.com/labstack/gommon/color/README.md b/src/dma/vendor/github.com/labstack/gommon/color/README.md
new file mode 100644
index 00000000..297c3518
--- /dev/null
+++ b/src/dma/vendor/github.com/labstack/gommon/color/README.md
@@ -0,0 +1,86 @@
+# Color
+
+Style terminal text.
+
+## Installation
+
+```sh
+go get github.com/labstack/gommon/color
+```
+
+## Windows?
+
+Try [cmder](http://bliker.github.io/cmder) or https://github.com/mattn/go-colorable
+
+## [Usage](https://github.com/labstack/gommon/blob/master/color/color_test.go)
+
+```sh
+import github.com/labstack/gommon/color
+```
+
+### Colored text
+
+```go
+color.Println(color.Black("black"))
+color.Println(color.Red("red"))
+color.Println(color.Green("green"))
+color.Println(color.Yellow("yellow"))
+color.Println(color.Blue("blue"))
+color.Println(color.Magenta("magenta"))
+color.Println(color.Cyan("cyan"))
+color.Println(color.White("white"))
+color.Println(color.Grey("grey"))
+```
+![Colored Text](http://i.imgur.com/8RtY1QR.png)
+
+### Colored background
+
+```go
+color.Println(color.BlackBg("black background", color.Wht))
+color.Println(color.RedBg("red background"))
+color.Println(color.GreenBg("green background"))
+color.Println(color.YellowBg("yellow background"))
+color.Println(color.BlueBg("blue background"))
+color.Println(color.MagentaBg("magenta background"))
+color.Println(color.CyanBg("cyan background"))
+color.Println(color.WhiteBg("white background"))
+```
+![Colored Background](http://i.imgur.com/SrrS6lw.png)
+
+### Emphasis
+
+```go
+color.Println(color.Bold("bold"))
+color.Println(color.Dim("dim"))
+color.Println(color.Italic("italic"))
+color.Println(color.Underline("underline"))
+color.Println(color.Inverse("inverse"))
+color.Println(color.Hidden("hidden"))
+color.Println(color.Strikeout("strikeout"))
+```
+![Emphasis](http://i.imgur.com/3RSJBbc.png)
+
+### Mix and match
+
+```go
+color.Println(color.Green("bold green with white background", color.B, color.WhtBg))
+color.Println(color.Red("underline red", color.U))
+color.Println(color.Yellow("dim yellow", color.D))
+color.Println(color.Cyan("inverse cyan", color.In))
+color.Println(color.Blue("bold underline dim blue", color.B, color.U, color.D))
+```
+![Mix and match](http://i.imgur.com/jWGq9Ca.png)
+
+### Enable/Disable the package
+
+```go
+color.Disable()
+color.Enable()
+```
+
+### New instance
+
+```go
+c := New()
+c.Green("green")
+```
diff --git a/src/dma/vendor/github.com/labstack/gommon/color/color.go b/src/dma/vendor/github.com/labstack/gommon/color/color.go
new file mode 100644
index 00000000..4131dcf3
--- /dev/null
+++ b/src/dma/vendor/github.com/labstack/gommon/color/color.go
@@ -0,0 +1,407 @@
+package color
+
+import (
+ "bytes"
+ "fmt"
+ "io"
+ "os"
+
+ "github.com/mattn/go-colorable"
+ "github.com/mattn/go-isatty"
+)
+
+type (
+ inner func(interface{}, []string, *Color) string
+)
+
+// Color styles
+const (
+ // Blk Black text style
+ Blk = "30"
+ // Rd red text style
+ Rd = "31"
+ // Grn green text style
+ Grn = "32"
+ // Yel yellow text style
+ Yel = "33"
+ // Blu blue text style
+ Blu = "34"
+ // Mgn magenta text style
+ Mgn = "35"
+ // Cyn cyan text style
+ Cyn = "36"
+ // Wht white text style
+ Wht = "37"
+ // Gry grey text style
+ Gry = "90"
+
+ // BlkBg black background style
+ BlkBg = "40"
+ // RdBg red background style
+ RdBg = "41"
+ // GrnBg green background style
+ GrnBg = "42"
+ // YelBg yellow background style
+ YelBg = "43"
+ // BluBg blue background style
+ BluBg = "44"
+ // MgnBg magenta background style
+ MgnBg = "45"
+ // CynBg cyan background style
+ CynBg = "46"
+ // WhtBg white background style
+ WhtBg = "47"
+
+ // R reset emphasis style
+ R = "0"
+ // B bold emphasis style
+ B = "1"
+ // D dim emphasis style
+ D = "2"
+ // I italic emphasis style
+ I = "3"
+ // U underline emphasis style
+ U = "4"
+ // In inverse emphasis style
+ In = "7"
+ // H hidden emphasis style
+ H = "8"
+ // S strikeout emphasis style
+ S = "9"
+)
+
+var (
+ black = outer(Blk)
+ red = outer(Rd)
+ green = outer(Grn)
+ yellow = outer(Yel)
+ blue = outer(Blu)
+ magenta = outer(Mgn)
+ cyan = outer(Cyn)
+ white = outer(Wht)
+ grey = outer(Gry)
+
+ blackBg = outer(BlkBg)
+ redBg = outer(RdBg)
+ greenBg = outer(GrnBg)
+ yellowBg = outer(YelBg)
+ blueBg = outer(BluBg)
+ magentaBg = outer(MgnBg)
+ cyanBg = outer(CynBg)
+ whiteBg = outer(WhtBg)
+
+ reset = outer(R)
+ bold = outer(B)
+ dim = outer(D)
+ italic = outer(I)
+ underline = outer(U)
+ inverse = outer(In)
+ hidden = outer(H)
+ strikeout = outer(S)
+
+ global = New()
+)
+
+func outer(n string) inner {
+ return func(msg interface{}, styles []string, c *Color) string {
+ // TODO: Drop fmt to boost performance?
+ if c.disabled {
+ return fmt.Sprintf("%v", msg)
+ }
+
+ b := new(bytes.Buffer)
+ b.WriteString("\x1b[")
+ b.WriteString(n)
+ for _, s := range styles {
+ b.WriteString(";")
+ b.WriteString(s)
+ }
+ b.WriteString("m")
+ return fmt.Sprintf("%s%v\x1b[0m", b.String(), msg)
+ }
+}
+
+type (
+ Color struct {
+ output io.Writer
+ disabled bool
+ }
+)
+
+// New creates a Color instance.
+func New() (c *Color) {
+ c = new(Color)
+ c.SetOutput(colorable.NewColorableStdout())
+ return
+}
+
+// Output returns the output.
+func (c *Color) Output() io.Writer {
+ return c.output
+}
+
+// SetOutput sets the output.
+func (c *Color) SetOutput(w io.Writer) {
+ c.output = w
+ if w, ok := w.(*os.File); !ok || !isatty.IsTerminal(w.Fd()) {
+ c.disabled = true
+ }
+}
+
+// Disable disables the colors and styles.
+func (c *Color) Disable() {
+ c.disabled = true
+}
+
+// Enable enables the colors and styles.
+func (c *Color) Enable() {
+ c.disabled = false
+}
+
+// Print is analogous to `fmt.Print` with termial detection.
+func (c *Color) Print(args ...interface{}) {
+ fmt.Fprint(c.output, args...)
+}
+
+// Println is analogous to `fmt.Println` with termial detection.
+func (c *Color) Println(args ...interface{}) {
+ fmt.Fprintln(c.output, args...)
+}
+
+// Printf is analogous to `fmt.Printf` with termial detection.
+func (c *Color) Printf(format string, args ...interface{}) {
+ fmt.Fprintf(c.output, format, args...)
+}
+
+func (c *Color) Black(msg interface{}, styles ...string) string {
+ return black(msg, styles, c)
+}
+
+func (c *Color) Red(msg interface{}, styles ...string) string {
+ return red(msg, styles, c)
+}
+
+func (c *Color) Green(msg interface{}, styles ...string) string {
+ return green(msg, styles, c)
+}
+
+func (c *Color) Yellow(msg interface{}, styles ...string) string {
+ return yellow(msg, styles, c)
+}
+
+func (c *Color) Blue(msg interface{}, styles ...string) string {
+ return blue(msg, styles, c)
+}
+
+func (c *Color) Magenta(msg interface{}, styles ...string) string {
+ return magenta(msg, styles, c)
+}
+
+func (c *Color) Cyan(msg interface{}, styles ...string) string {
+ return cyan(msg, styles, c)
+}
+
+func (c *Color) White(msg interface{}, styles ...string) string {
+ return white(msg, styles, c)
+}
+
+func (c *Color) Grey(msg interface{}, styles ...string) string {
+ return grey(msg, styles, c)
+}
+
+func (c *Color) BlackBg(msg interface{}, styles ...string) string {
+ return blackBg(msg, styles, c)
+}
+
+func (c *Color) RedBg(msg interface{}, styles ...string) string {
+ return redBg(msg, styles, c)
+}
+
+func (c *Color) GreenBg(msg interface{}, styles ...string) string {
+ return greenBg(msg, styles, c)
+}
+
+func (c *Color) YellowBg(msg interface{}, styles ...string) string {
+ return yellowBg(msg, styles, c)
+}
+
+func (c *Color) BlueBg(msg interface{}, styles ...string) string {
+ return blueBg(msg, styles, c)
+}
+
+func (c *Color) MagentaBg(msg interface{}, styles ...string) string {
+ return magentaBg(msg, styles, c)
+}
+
+func (c *Color) CyanBg(msg interface{}, styles ...string) string {
+ return cyanBg(msg, styles, c)
+}
+
+func (c *Color) WhiteBg(msg interface{}, styles ...string) string {
+ return whiteBg(msg, styles, c)
+}
+
+func (c *Color) Reset(msg interface{}, styles ...string) string {
+ return reset(msg, styles, c)
+}
+
+func (c *Color) Bold(msg interface{}, styles ...string) string {
+ return bold(msg, styles, c)
+}
+
+func (c *Color) Dim(msg interface{}, styles ...string) string {
+ return dim(msg, styles, c)
+}
+
+func (c *Color) Italic(msg interface{}, styles ...string) string {
+ return italic(msg, styles, c)
+}
+
+func (c *Color) Underline(msg interface{}, styles ...string) string {
+ return underline(msg, styles, c)
+}
+
+func (c *Color) Inverse(msg interface{}, styles ...string) string {
+ return inverse(msg, styles, c)
+}
+
+func (c *Color) Hidden(msg interface{}, styles ...string) string {
+ return hidden(msg, styles, c)
+}
+
+func (c *Color) Strikeout(msg interface{}, styles ...string) string {
+ return strikeout(msg, styles, c)
+}
+
+// Output returns the output.
+func Output() io.Writer {
+ return global.output
+}
+
+// SetOutput sets the output.
+func SetOutput(w io.Writer) {
+ global.SetOutput(w)
+}
+
+func Disable() {
+ global.Disable()
+}
+
+func Enable() {
+ global.Enable()
+}
+
+// Print is analogous to `fmt.Print` with termial detection.
+func Print(args ...interface{}) {
+ global.Print(args...)
+}
+
+// Println is analogous to `fmt.Println` with termial detection.
+func Println(args ...interface{}) {
+ global.Println(args...)
+}
+
+// Printf is analogous to `fmt.Printf` with termial detection.
+func Printf(format string, args ...interface{}) {
+ global.Printf(format, args...)
+}
+
+func Black(msg interface{}, styles ...string) string {
+ return global.Black(msg, styles...)
+}
+
+func Red(msg interface{}, styles ...string) string {
+ return global.Red(msg, styles...)
+}
+
+func Green(msg interface{}, styles ...string) string {
+ return global.Green(msg, styles...)
+}
+
+func Yellow(msg interface{}, styles ...string) string {
+ return global.Yellow(msg, styles...)
+}
+
+func Blue(msg interface{}, styles ...string) string {
+ return global.Blue(msg, styles...)
+}
+
+func Magenta(msg interface{}, styles ...string) string {
+ return global.Magenta(msg, styles...)
+}
+
+func Cyan(msg interface{}, styles ...string) string {
+ return global.Cyan(msg, styles...)
+}
+
+func White(msg interface{}, styles ...string) string {
+ return global.White(msg, styles...)
+}
+
+func Grey(msg interface{}, styles ...string) string {
+ return global.Grey(msg, styles...)
+}
+
+func BlackBg(msg interface{}, styles ...string) string {
+ return global.BlackBg(msg, styles...)
+}
+
+func RedBg(msg interface{}, styles ...string) string {
+ return global.RedBg(msg, styles...)
+}
+
+func GreenBg(msg interface{}, styles ...string) string {
+ return global.GreenBg(msg, styles...)
+}
+
+func YellowBg(msg interface{}, styles ...string) string {
+ return global.YellowBg(msg, styles...)
+}
+
+func BlueBg(msg interface{}, styles ...string) string {
+ return global.BlueBg(msg, styles...)
+}
+
+func MagentaBg(msg interface{}, styles ...string) string {
+ return global.MagentaBg(msg, styles...)
+}
+
+func CyanBg(msg interface{}, styles ...string) string {
+ return global.CyanBg(msg, styles...)
+}
+
+func WhiteBg(msg interface{}, styles ...string) string {
+ return global.WhiteBg(msg, styles...)
+}
+
+func Reset(msg interface{}, styles ...string) string {
+ return global.Reset(msg, styles...)
+}
+
+func Bold(msg interface{}, styles ...string) string {
+ return global.Bold(msg, styles...)
+}
+
+func Dim(msg interface{}, styles ...string) string {
+ return global.Dim(msg, styles...)
+}
+
+func Italic(msg interface{}, styles ...string) string {
+ return global.Italic(msg, styles...)
+}
+
+func Underline(msg interface{}, styles ...string) string {
+ return global.Underline(msg, styles...)
+}
+
+func Inverse(msg interface{}, styles ...string) string {
+ return global.Inverse(msg, styles...)
+}
+
+func Hidden(msg interface{}, styles ...string) string {
+ return global.Hidden(msg, styles...)
+}
+
+func Strikeout(msg interface{}, styles ...string) string {
+ return global.Strikeout(msg, styles...)
+}
diff --git a/src/dma/vendor/github.com/labstack/gommon/log/README.md b/src/dma/vendor/github.com/labstack/gommon/log/README.md
new file mode 100644
index 00000000..d5b9e9f0
--- /dev/null
+++ b/src/dma/vendor/github.com/labstack/gommon/log/README.md
@@ -0,0 +1,5 @@
+## WORK IN PROGRESS
+
+### Usage
+
+[log_test.go](log_test.go)
diff --git a/src/dma/vendor/github.com/labstack/gommon/log/color.go b/src/dma/vendor/github.com/labstack/gommon/log/color.go
new file mode 100644
index 00000000..7351b39c
--- /dev/null
+++ b/src/dma/vendor/github.com/labstack/gommon/log/color.go
@@ -0,0 +1,13 @@
+// +build !appengine
+
+package log
+
+import (
+ "io"
+
+ "github.com/mattn/go-colorable"
+)
+
+func output() io.Writer {
+ return colorable.NewColorableStdout()
+}
diff --git a/src/dma/vendor/github.com/labstack/gommon/log/log.go b/src/dma/vendor/github.com/labstack/gommon/log/log.go
new file mode 100644
index 00000000..0d77a87a
--- /dev/null
+++ b/src/dma/vendor/github.com/labstack/gommon/log/log.go
@@ -0,0 +1,415 @@
+package log
+
+import (
+ "bytes"
+ "encoding/json"
+ "fmt"
+ "io"
+ "os"
+ "path"
+ "runtime"
+ "strconv"
+ "sync"
+ "time"
+
+ "github.com/mattn/go-isatty"
+ "github.com/valyala/fasttemplate"
+
+ "github.com/labstack/gommon/color"
+)
+
+type (
+ Logger struct {
+ prefix string
+ level Lvl
+ skip int
+ output io.Writer
+ template *fasttemplate.Template
+ levels []string
+ color *color.Color
+ bufferPool sync.Pool
+ mutex sync.Mutex
+ }
+
+ Lvl uint8
+
+ JSON map[string]interface{}
+)
+
+const (
+ DEBUG Lvl = iota + 1
+ INFO
+ WARN
+ ERROR
+ OFF
+ panicLevel
+ fatalLevel
+)
+
+var (
+ global = New("-")
+ defaultHeader = `{"time":"${time_rfc3339_nano}","level":"${level}","prefix":"${prefix}",` +
+ `"file":"${short_file}","line":"${line}"}`
+)
+
+func init() {
+ global.skip = 3
+}
+
+func New(prefix string) (l *Logger) {
+ l = &Logger{
+ level: INFO,
+ skip: 2,
+ prefix: prefix,
+ template: l.newTemplate(defaultHeader),
+ color: color.New(),
+ bufferPool: sync.Pool{
+ New: func() interface{} {
+ return bytes.NewBuffer(make([]byte, 256))
+ },
+ },
+ }
+ l.initLevels()
+ l.SetOutput(output())
+ return
+}
+
+func (l *Logger) initLevels() {
+ l.levels = []string{
+ "-",
+ l.color.Blue("DEBUG"),
+ l.color.Green("INFO"),
+ l.color.Yellow("WARN"),
+ l.color.Red("ERROR"),
+ "",
+ l.color.Yellow("PANIC", color.U),
+ l.color.Red("FATAL", color.U),
+ }
+}
+
+func (l *Logger) newTemplate(format string) *fasttemplate.Template {
+ return fasttemplate.New(format, "${", "}")
+}
+
+func (l *Logger) DisableColor() {
+ l.color.Disable()
+ l.initLevels()
+}
+
+func (l *Logger) EnableColor() {
+ l.color.Enable()
+ l.initLevels()
+}
+
+func (l *Logger) Prefix() string {
+ return l.prefix
+}
+
+func (l *Logger) SetPrefix(p string) {
+ l.prefix = p
+}
+
+func (l *Logger) Level() Lvl {
+ return l.level
+}
+
+func (l *Logger) SetLevel(v Lvl) {
+ l.level = v
+}
+
+func (l *Logger) Output() io.Writer {
+ return l.output
+}
+
+func (l *Logger) SetOutput(w io.Writer) {
+ l.output = w
+ if w, ok := w.(*os.File); !ok || !isatty.IsTerminal(w.Fd()) {
+ l.DisableColor()
+ }
+}
+
+func (l *Logger) Color() *color.Color {
+ return l.color
+}
+
+func (l *Logger) SetHeader(h string) {
+ l.template = l.newTemplate(h)
+}
+
+func (l *Logger) Print(i ...interface{}) {
+ l.log(0, "", i...)
+ // fmt.Fprintln(l.output, i...)
+}
+
+func (l *Logger) Printf(format string, args ...interface{}) {
+ l.log(0, format, args...)
+}
+
+func (l *Logger) Printj(j JSON) {
+ l.log(0, "json", j)
+}
+
+func (l *Logger) Debug(i ...interface{}) {
+ l.log(DEBUG, "", i...)
+}
+
+func (l *Logger) Debugf(format string, args ...interface{}) {
+ l.log(DEBUG, format, args...)
+}
+
+func (l *Logger) Debugj(j JSON) {
+ l.log(DEBUG, "json", j)
+}
+
+func (l *Logger) Info(i ...interface{}) {
+ l.log(INFO, "", i...)
+}
+
+func (l *Logger) Infof(format string, args ...interface{}) {
+ l.log(INFO, format, args...)
+}
+
+func (l *Logger) Infoj(j JSON) {
+ l.log(INFO, "json", j)
+}
+
+func (l *Logger) Warn(i ...interface{}) {
+ l.log(WARN, "", i...)
+}
+
+func (l *Logger) Warnf(format string, args ...interface{}) {
+ l.log(WARN, format, args...)
+}
+
+func (l *Logger) Warnj(j JSON) {
+ l.log(WARN, "json", j)
+}
+
+func (l *Logger) Error(i ...interface{}) {
+ l.log(ERROR, "", i...)
+}
+
+func (l *Logger) Errorf(format string, args ...interface{}) {
+ l.log(ERROR, format, args...)
+}
+
+func (l *Logger) Errorj(j JSON) {
+ l.log(ERROR, "json", j)
+}
+
+func (l *Logger) Fatal(i ...interface{}) {
+ l.log(fatalLevel, "", i...)
+ os.Exit(1)
+}
+
+func (l *Logger) Fatalf(format string, args ...interface{}) {
+ l.log(fatalLevel, format, args...)
+ os.Exit(1)
+}
+
+func (l *Logger) Fatalj(j JSON) {
+ l.log(fatalLevel, "json", j)
+ os.Exit(1)
+}
+
+func (l *Logger) Panic(i ...interface{}) {
+ l.log(panicLevel, "", i...)
+ panic(fmt.Sprint(i...))
+}
+
+func (l *Logger) Panicf(format string, args ...interface{}) {
+ l.log(panicLevel, format, args...)
+ panic(fmt.Sprintf(format, args))
+}
+
+func (l *Logger) Panicj(j JSON) {
+ l.log(panicLevel, "json", j)
+ panic(j)
+}
+
+func DisableColor() {
+ global.DisableColor()
+}
+
+func EnableColor() {
+ global.EnableColor()
+}
+
+func Prefix() string {
+ return global.Prefix()
+}
+
+func SetPrefix(p string) {
+ global.SetPrefix(p)
+}
+
+func Level() Lvl {
+ return global.Level()
+}
+
+func SetLevel(v Lvl) {
+ global.SetLevel(v)
+}
+
+func Output() io.Writer {
+ return global.Output()
+}
+
+func SetOutput(w io.Writer) {
+ global.SetOutput(w)
+}
+
+func SetHeader(h string) {
+ global.SetHeader(h)
+}
+
+func Print(i ...interface{}) {
+ global.Print(i...)
+}
+
+func Printf(format string, args ...interface{}) {
+ global.Printf(format, args...)
+}
+
+func Printj(j JSON) {
+ global.Printj(j)
+}
+
+func Debug(i ...interface{}) {
+ global.Debug(i...)
+}
+
+func Debugf(format string, args ...interface{}) {
+ global.Debugf(format, args...)
+}
+
+func Debugj(j JSON) {
+ global.Debugj(j)
+}
+
+func Info(i ...interface{}) {
+ global.Info(i...)
+}
+
+func Infof(format string, args ...interface{}) {
+ global.Infof(format, args...)
+}
+
+func Infoj(j JSON) {
+ global.Infoj(j)
+}
+
+func Warn(i ...interface{}) {
+ global.Warn(i...)
+}
+
+func Warnf(format string, args ...interface{}) {
+ global.Warnf(format, args...)
+}
+
+func Warnj(j JSON) {
+ global.Warnj(j)
+}
+
+func Error(i ...interface{}) {
+ global.Error(i...)
+}
+
+func Errorf(format string, args ...interface{}) {
+ global.Errorf(format, args...)
+}
+
+func Errorj(j JSON) {
+ global.Errorj(j)
+}
+
+func Fatal(i ...interface{}) {
+ global.Fatal(i...)
+}
+
+func Fatalf(format string, args ...interface{}) {
+ global.Fatalf(format, args...)
+}
+
+func Fatalj(j JSON) {
+ global.Fatalj(j)
+}
+
+func Panic(i ...interface{}) {
+ global.Panic(i...)
+}
+
+func Panicf(format string, args ...interface{}) {
+ global.Panicf(format, args...)
+}
+
+func Panicj(j JSON) {
+ global.Panicj(j)
+}
+
+func (l *Logger) log(v Lvl, format string, args ...interface{}) {
+ l.mutex.Lock()
+ defer l.mutex.Unlock()
+ buf := l.bufferPool.Get().(*bytes.Buffer)
+ buf.Reset()
+ defer l.bufferPool.Put(buf)
+ _, file, line, _ := runtime.Caller(l.skip)
+
+ if v >= l.level || v == 0 {
+ message := ""
+ if format == "" {
+ message = fmt.Sprint(args...)
+ } else if format == "json" {
+ b, err := json.Marshal(args[0])
+ if err != nil {
+ panic(err)
+ }
+ message = string(b)
+ } else {
+ message = fmt.Sprintf(format, args...)
+ }
+
+ _, err := l.template.ExecuteFunc(buf, func(w io.Writer, tag string) (int, error) {
+ switch tag {
+ case "time_rfc3339":
+ return w.Write([]byte(time.Now().Format(time.RFC3339)))
+ case "time_rfc3339_nano":
+ return w.Write([]byte(time.Now().Format(time.RFC3339Nano)))
+ case "level":
+ return w.Write([]byte(l.levels[v]))
+ case "prefix":
+ return w.Write([]byte(l.prefix))
+ case "long_file":
+ return w.Write([]byte(file))
+ case "short_file":
+ return w.Write([]byte(path.Base(file)))
+ case "line":
+ return w.Write([]byte(strconv.Itoa(line)))
+ }
+ return 0, nil
+ })
+
+ if err == nil {
+ s := buf.String()
+ i := buf.Len() - 1
+ if s[i] == '}' {
+ // JSON header
+ buf.Truncate(i)
+ buf.WriteByte(',')
+ if format == "json" {
+ buf.WriteString(message[1:])
+ } else {
+ buf.WriteString(`"message":`)
+ buf.WriteString(strconv.Quote(message))
+ buf.WriteString(`}`)
+ }
+ } else {
+ // Text header
+ buf.WriteByte(' ')
+ buf.WriteString(message)
+ }
+ buf.WriteByte('\n')
+ l.output.Write(buf.Bytes())
+ }
+ }
+}
diff --git a/src/dma/vendor/github.com/labstack/gommon/log/white.go b/src/dma/vendor/github.com/labstack/gommon/log/white.go
new file mode 100644
index 00000000..746cc562
--- /dev/null
+++ b/src/dma/vendor/github.com/labstack/gommon/log/white.go
@@ -0,0 +1,12 @@
+// +build appengine
+
+package log
+
+import (
+ "io"
+ "os"
+)
+
+func output() io.Writer {
+ return os.Stdout
+}
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/.gitignore b/src/dma/vendor/github.com/libvirt/libvirt-go/.gitignore
new file mode 100644
index 00000000..3624e1cf
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/.gitignore
@@ -0,0 +1,7 @@
+*.sublime-workspace
+*.sublime-project
+.vagrant
+/libvirt-go.test
+*~
+.#*
+\#*
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/.gitpublish b/src/dma/vendor/github.com/libvirt/libvirt-go/.gitpublish
new file mode 100644
index 00000000..567c1398
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/.gitpublish
@@ -0,0 +1,4 @@
+[gitpublishprofile "default"]
+base = master
+to = libvir-list@redhat.com
+prefix = go PATCH
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/.travis.yml b/src/dma/vendor/github.com/libvirt/libvirt-go/.travis.yml
new file mode 100644
index 00000000..1bdb48f9
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/.travis.yml
@@ -0,0 +1,42 @@
+language: go
+os: linux
+dist: trusty
+sudo: require
+
+go:
+ - 1.5
+ - 1.6
+ - 1.7
+ - 1.8
+ - 1.9
+
+env:
+ - LIBVIRT=1.2.0 EXT=gz
+ - LIBVIRT=1.2.10 EXT=gz
+ - LIBVIRT=1.2.20 EXT=gz
+ - LIBVIRT=2.5.0 EXT=xz
+ - LIBVIRT=3.6.0 EXT=xz
+
+install:
+ - sudo apt-get -qqy build-dep libvirt
+ - sudo apt-get -qqy install curl qemu-system-x86 sasl2-bin
+ - sudo mkdir -p /usr/src && sudo chown $(id -u) /usr/src
+ - curl -O -s https://libvirt.org/sources/libvirt-${LIBVIRT}.tar.${EXT}
+ - tar -C /usr/src -xf libvirt-${LIBVIRT}.tar.${EXT}
+ - pushd /usr/src/libvirt-${LIBVIRT}
+ - |
+ ./configure --prefix=/usr --localstatedir=/var --sysconfdir=/etc \
+ --without-polkit \
+ --without-esx --without-vbox --without-xen --without-libxl \
+ --with-qemu --with-lxc
+ - make
+ - sudo make install
+ - popd
+ - sudo cp libvirtd.sasl /etc/sasl2/libvirt.conf
+ - sudo libvirtd -d -l -f libvirtd.conf
+ - sudo virtlogd -d || true
+ - sudo chmod a+rwx /var/run/libvirt/libvirt-sock*
+ - echo "pass" | sudo saslpasswd2 -p -a libvirt user
+
+script:
+ go test -timeout 1m -tags "integration" -v
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/FAQ.md b/src/dma/vendor/github.com/libvirt/libvirt-go/FAQ.md
new file mode 100644
index 00000000..0e731817
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/FAQ.md
@@ -0,0 +1,19 @@
+#libvirt-go
+
+##FAQ - Frequently asked questions
+
+If your question is a good one, please ask it as a well-formatted patch to this
+repository, and we'll merge it along with the answer.
+
+###Why does this fail when added to my project in travis?
+
+This lib requires a newish version of the libvirt-dev library to compile. These
+are only available in the newer travis environment. You can add:
+
+```
+sudo: true
+dist: trusty
+install: sudo apt-get install -y libvirt-dev
+```
+
+to your `.travis.yaml` file to avoid these errors.
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/LICENSE b/src/dma/vendor/github.com/libvirt/libvirt-go/LICENSE
new file mode 100644
index 00000000..202f5fce
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/LICENSE
@@ -0,0 +1,21 @@
+The MIT License
+
+Copyright (c) 2013 Alex Zorin
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE. \ No newline at end of file
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/README.md b/src/dma/vendor/github.com/libvirt/libvirt-go/README.md
new file mode 100644
index 00000000..326d6a06
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/README.md
@@ -0,0 +1,136 @@
+# libvirt-go [![Build Status](https://travis-ci.org/libvirt/libvirt-go.svg?branch=master)](https://travis-ci.org/libvirt/libvirt-go) [![GoDoc](https://godoc.org/github.com/libvirt/libvirt-go?status.svg)](https://godoc.org/github.com/libvirt/libvirt-go)
+
+Go bindings for libvirt.
+
+Make sure to have `libvirt-dev` package (or the development files otherwise somewhere in your include path)
+
+## Version Support
+
+The libvirt go package provides API coverage for libvirt versions
+from 1.2.0 onwards, through conditional compilation of newer APIs.
+
+By default the binding will support APIs in libvirt.so, libvirt-qemu.so
+and libvirt-lxc.so. Coverage for the latter two libraries can be dropped
+from the build using build tags 'without_qemu' or 'without_lxc'
+respectively.
+
+## Development status
+
+The Go API is considered to be production ready and aims to be kept
+stable across future versions. Note, however, that the following
+changes may apply to future versions:
+
+* Existing structs can be augmented with new fields, but no existing
+ fields will be changed / removed. New fields are needed when libvirt
+ defines new typed parameters for various methods
+
+* Any method with an 'flags uint32' parameter will have its parameter
+ type changed to a specific typedef, if & when the libvirt API defines
+ constants for the flags. To avoid breakage, always pass a literal
+ '0' to any 'flags uint32' parameter, since this will auto-cast to
+ any future typedef that is introduced.
+
+## Documentation
+
+* [api documentation for the bindings](https://godoc.org/github.com/libvirt/libvirt-go)
+* [api documentation for libvirt](http://libvirt.org/html/libvirt-libvirt.html)
+
+## Contributing
+
+The libvirt project aims to add support for new APIs to libvirt-go
+as soon as they are added to the main libvirt C library. If you
+are submitting changes to the libvirt C library API, please submit
+a libvirt-go change at the same time.
+
+Bug fixes and other improvements to the libvirt-go library are
+welcome at any time. The preferred submission method is to use
+git send-email to submit patches to the libvir-list@redhat.com
+mailing list. eg. to send a single patch
+
+ git send-email --to libvir-list@redhat.com --subject-prefix "PATCH go" \
+ --smtp-server=$HOSTNAME -1
+
+Or to send all patches on the current branch, against master
+
+ git send-email --to libvir-list@redhat.com --subject-prefix "PATCH go" \
+ --smtp-server=$HOSTNAME --no-chain-reply-to --cover-letter --annotate \
+ master..
+
+Note the master GIT repository is at
+
+* http://libvirt.org/git/?p=libvirt-go.git;a=summary
+
+The following automatic read-only mirrors are available as a
+convenience to allow contributors to "fork" the repository:
+
+* https://gitlab.com/libvirt/libvirt-go
+* https://github.com/libvirt/libvirt-go
+
+While you can send pull-requests to these mirrors, they will be
+re-submitted via emai to the mailing list for review before
+being merged, unless they are trivial/obvious bug fixes.
+
+## Testing
+
+The core API unit tests are all written to use the built-in
+test driver (test:///default), so they have no interaction
+with the host OS environment.
+
+Coverage of libvirt C library APIs / constants is verified
+using automated tests. These can be run by passing the 'api'
+build tag. eg go test -tags api
+
+For areas where the test driver lacks functionality, it is
+possible to use the QEMU or LXC drivers to exercise code.
+Such tests must be part of the 'integration_test.go' file
+though, which is only run when passing the 'integration'
+build tag. eg go test -tags integration
+
+In order to run the unit tests, libvirtd should be configured
+to allow your user account read-write access with no passwords.
+This can be easily done using polkit config files
+
+```
+# cat > /etc/polkit-1/localauthority/50-local.d/50-libvirt.pkla <<EOF
+[Passwordless libvirt access]
+Identity=unix-group:berrange
+Action=org.libvirt.unix.manage
+ResultAny=yes
+ResultInactive=yes
+ResultActive=yes
+EOF
+```
+
+(Replace 'berrange' with your UNIX user name).
+
+One of the integration tests also requires that libvirtd is
+listening for TCP connections on localhost, with sasl auth
+This can be setup by editing /etc/libvirt/libvirtd.conf to
+set
+
+```
+ listen_tls=0
+ listen_tcp=1
+ auth_tcp=sasl
+ listen_addr="127.0.0.1"
+```
+
+and then start libvirtd with the --listen flag (this can
+be set in /etc/sysconfig/libvirtd to make it persistent).
+
+Then create a sasl user
+
+```
+ saslpasswd2 -a libvirt user
+```
+
+and enter "pass" as the password.
+
+Alternatively a `Vagrantfile`, requiring use of virtualbox,
+is included to run the integration tests:
+
+* `cd ./vagrant`
+* `vagrant up` to provision the virtual machine
+* `vagrant ssh` to login to the virtual machine
+
+Once inside, `sudo su -` and `go test -tags integration libvirt`.
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/callbacks.go b/src/dma/vendor/github.com/libvirt/libvirt-go/callbacks.go
new file mode 100644
index 00000000..7b2d11ba
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/callbacks.go
@@ -0,0 +1,102 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+package libvirt
+
+// Helpers functions to register a Go callback function to a C
+// function. For a simple example, look at how SetErrorFunc works in
+// error.go.
+//
+// - Create a struct that will contain at least the Go callback to
+// invoke (errorContext).
+//
+// - Create an exported Golang function whose job will be to retrieve
+// the context and execute the callback in it
+// (connErrCallback). Such a function should receive a callback ID
+// and will use it to retrive the context.
+//
+// - Create a CGO function similar to the above function but with the
+// appropriate signature to be registered as a callback in C code
+// (connErrCallbackHelper). Notably, it will have a void* argument
+// that should be cast to long to retrieve the callback ID. It
+// should be just a thin wrapper to transform the opaque argument to
+// a callback ID.
+//
+// - Create a CGO function which will be a wrapper around the C
+// function to register the callback (virConnSetErrorFuncWrapper). Its
+// only role is to transform a callback ID (long) to an opaque (void*)
+// and call the C function.
+//
+// - When setting up a callback (SetErrorFunc), register the struct from first step
+// with registerCallbackId and invoke the CGO function from the
+// previous step with the appropriate ID.
+//
+// - When unregistering the callback, don't forget to call freecallbackId.
+//
+// If you need to associate some additional data with the connection,
+// look at saveConnectionData, getConnectionData and
+// releaseConnectionData.
+
+import "C"
+
+import (
+ "sync"
+)
+
+const firstGoCallbackId int = 100 // help catch some additional errors during test
+var goCallbackLock sync.RWMutex
+var goCallbacks = make(map[int]interface{})
+var nextGoCallbackId int = firstGoCallbackId
+
+//export freeCallbackId
+func freeCallbackId(goCallbackId int) {
+ goCallbackLock.Lock()
+ delete(goCallbacks, goCallbackId)
+ goCallbackLock.Unlock()
+}
+
+func getCallbackId(goCallbackId int) interface{} {
+ goCallbackLock.RLock()
+ ctx := goCallbacks[goCallbackId]
+ goCallbackLock.RUnlock()
+ if ctx == nil {
+ // If this happens there must be a bug in libvirt
+ panic("Callback arrived after freeCallbackId was called")
+ }
+ return ctx
+}
+
+func registerCallbackId(ctx interface{}) int {
+ goCallbackLock.Lock()
+ goCallBackId := nextGoCallbackId
+ nextGoCallbackId++
+ for goCallbacks[nextGoCallbackId] != nil {
+ nextGoCallbackId++
+ }
+ goCallbacks[goCallBackId] = ctx
+ goCallbackLock.Unlock()
+ return goCallBackId
+}
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/callbacks_wrapper.go b/src/dma/vendor/github.com/libvirt/libvirt-go/callbacks_wrapper.go
new file mode 100644
index 00000000..9716bb10
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/callbacks_wrapper.go
@@ -0,0 +1,39 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+package libvirt
+
+/*
+#cgo pkg-config: libvirt
+#include "callbacks_wrapper.h"
+
+extern void freeCallbackId(long);
+void freeGoCallbackHelper(void* goCallbackId) {
+ freeCallbackId((long)goCallbackId);
+}
+
+*/
+import "C"
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/callbacks_wrapper.h b/src/dma/vendor/github.com/libvirt/libvirt-go/callbacks_wrapper.h
new file mode 100644
index 00000000..4b91f7a7
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/callbacks_wrapper.h
@@ -0,0 +1,32 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+#ifndef LIBVIRT_GO_CALLBACKS_WRAPPER_H__
+#define LIBVIRT_GO_CALLBACKS_WRAPPER_H__
+
+void freeGoCallbackHelper(void* goCallbackId);
+
+#endif /* LIBVIRT_GO_CALLBACKS_WRAPPER_H__ */
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/connect.go b/src/dma/vendor/github.com/libvirt/libvirt-go/connect.go
new file mode 100644
index 00000000..8cc7cc77
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/connect.go
@@ -0,0 +1,2998 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+package libvirt
+
+import (
+ "fmt"
+ "os"
+ "reflect"
+ "sync"
+ "unsafe"
+)
+
+/*
+#cgo pkg-config: libvirt
+#include <stdlib.h>
+#include "connect_wrapper.h"
+*/
+import "C"
+
+func init() {
+ C.virInitialize()
+}
+
+const (
+ VERSION_NUMBER = uint32(C.LIBVIR_VERSION_NUMBER)
+)
+
+type ConnectCloseReason int
+
+const (
+ CONNECT_CLOSE_REASON_ERROR = ConnectCloseReason(C.VIR_CONNECT_CLOSE_REASON_ERROR)
+ CONNECT_CLOSE_REASON_EOF = ConnectCloseReason(C.VIR_CONNECT_CLOSE_REASON_EOF)
+ CONNECT_CLOSE_REASON_KEEPALIVE = ConnectCloseReason(C.VIR_CONNECT_CLOSE_REASON_KEEPALIVE)
+ CONNECT_CLOSE_REASON_CLIENT = ConnectCloseReason(C.VIR_CONNECT_CLOSE_REASON_CLIENT)
+)
+
+type ConnectListAllDomainsFlags int
+
+const (
+ CONNECT_LIST_DOMAINS_ACTIVE = ConnectListAllDomainsFlags(C.VIR_CONNECT_LIST_DOMAINS_ACTIVE)
+ CONNECT_LIST_DOMAINS_INACTIVE = ConnectListAllDomainsFlags(C.VIR_CONNECT_LIST_DOMAINS_INACTIVE)
+ CONNECT_LIST_DOMAINS_PERSISTENT = ConnectListAllDomainsFlags(C.VIR_CONNECT_LIST_DOMAINS_PERSISTENT)
+ CONNECT_LIST_DOMAINS_TRANSIENT = ConnectListAllDomainsFlags(C.VIR_CONNECT_LIST_DOMAINS_TRANSIENT)
+ CONNECT_LIST_DOMAINS_RUNNING = ConnectListAllDomainsFlags(C.VIR_CONNECT_LIST_DOMAINS_RUNNING)
+ CONNECT_LIST_DOMAINS_PAUSED = ConnectListAllDomainsFlags(C.VIR_CONNECT_LIST_DOMAINS_PAUSED)
+ CONNECT_LIST_DOMAINS_SHUTOFF = ConnectListAllDomainsFlags(C.VIR_CONNECT_LIST_DOMAINS_SHUTOFF)
+ CONNECT_LIST_DOMAINS_OTHER = ConnectListAllDomainsFlags(C.VIR_CONNECT_LIST_DOMAINS_OTHER)
+ CONNECT_LIST_DOMAINS_MANAGEDSAVE = ConnectListAllDomainsFlags(C.VIR_CONNECT_LIST_DOMAINS_MANAGEDSAVE)
+ CONNECT_LIST_DOMAINS_NO_MANAGEDSAVE = ConnectListAllDomainsFlags(C.VIR_CONNECT_LIST_DOMAINS_NO_MANAGEDSAVE)
+ CONNECT_LIST_DOMAINS_AUTOSTART = ConnectListAllDomainsFlags(C.VIR_CONNECT_LIST_DOMAINS_AUTOSTART)
+ CONNECT_LIST_DOMAINS_NO_AUTOSTART = ConnectListAllDomainsFlags(C.VIR_CONNECT_LIST_DOMAINS_NO_AUTOSTART)
+ CONNECT_LIST_DOMAINS_HAS_SNAPSHOT = ConnectListAllDomainsFlags(C.VIR_CONNECT_LIST_DOMAINS_HAS_SNAPSHOT)
+ CONNECT_LIST_DOMAINS_NO_SNAPSHOT = ConnectListAllDomainsFlags(C.VIR_CONNECT_LIST_DOMAINS_NO_SNAPSHOT)
+)
+
+type ConnectListAllNetworksFlags int
+
+const (
+ CONNECT_LIST_NETWORKS_INACTIVE = ConnectListAllNetworksFlags(C.VIR_CONNECT_LIST_NETWORKS_INACTIVE)
+ CONNECT_LIST_NETWORKS_ACTIVE = ConnectListAllNetworksFlags(C.VIR_CONNECT_LIST_NETWORKS_ACTIVE)
+ CONNECT_LIST_NETWORKS_PERSISTENT = ConnectListAllNetworksFlags(C.VIR_CONNECT_LIST_NETWORKS_PERSISTENT)
+ CONNECT_LIST_NETWORKS_TRANSIENT = ConnectListAllNetworksFlags(C.VIR_CONNECT_LIST_NETWORKS_TRANSIENT)
+ CONNECT_LIST_NETWORKS_AUTOSTART = ConnectListAllNetworksFlags(C.VIR_CONNECT_LIST_NETWORKS_AUTOSTART)
+ CONNECT_LIST_NETWORKS_NO_AUTOSTART = ConnectListAllNetworksFlags(C.VIR_CONNECT_LIST_NETWORKS_NO_AUTOSTART)
+)
+
+type ConnectListAllStoragePoolsFlags int
+
+const (
+ CONNECT_LIST_STORAGE_POOLS_INACTIVE = ConnectListAllStoragePoolsFlags(C.VIR_CONNECT_LIST_STORAGE_POOLS_INACTIVE)
+ CONNECT_LIST_STORAGE_POOLS_ACTIVE = ConnectListAllStoragePoolsFlags(C.VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE)
+ CONNECT_LIST_STORAGE_POOLS_PERSISTENT = ConnectListAllStoragePoolsFlags(C.VIR_CONNECT_LIST_STORAGE_POOLS_PERSISTENT)
+ CONNECT_LIST_STORAGE_POOLS_TRANSIENT = ConnectListAllStoragePoolsFlags(C.VIR_CONNECT_LIST_STORAGE_POOLS_TRANSIENT)
+ CONNECT_LIST_STORAGE_POOLS_AUTOSTART = ConnectListAllStoragePoolsFlags(C.VIR_CONNECT_LIST_STORAGE_POOLS_AUTOSTART)
+ CONNECT_LIST_STORAGE_POOLS_NO_AUTOSTART = ConnectListAllStoragePoolsFlags(C.VIR_CONNECT_LIST_STORAGE_POOLS_NO_AUTOSTART)
+ CONNECT_LIST_STORAGE_POOLS_DIR = ConnectListAllStoragePoolsFlags(C.VIR_CONNECT_LIST_STORAGE_POOLS_DIR)
+ CONNECT_LIST_STORAGE_POOLS_FS = ConnectListAllStoragePoolsFlags(C.VIR_CONNECT_LIST_STORAGE_POOLS_FS)
+ CONNECT_LIST_STORAGE_POOLS_NETFS = ConnectListAllStoragePoolsFlags(C.VIR_CONNECT_LIST_STORAGE_POOLS_NETFS)
+ CONNECT_LIST_STORAGE_POOLS_LOGICAL = ConnectListAllStoragePoolsFlags(C.VIR_CONNECT_LIST_STORAGE_POOLS_LOGICAL)
+ CONNECT_LIST_STORAGE_POOLS_DISK = ConnectListAllStoragePoolsFlags(C.VIR_CONNECT_LIST_STORAGE_POOLS_DISK)
+ CONNECT_LIST_STORAGE_POOLS_ISCSI = ConnectListAllStoragePoolsFlags(C.VIR_CONNECT_LIST_STORAGE_POOLS_ISCSI)
+ CONNECT_LIST_STORAGE_POOLS_SCSI = ConnectListAllStoragePoolsFlags(C.VIR_CONNECT_LIST_STORAGE_POOLS_SCSI)
+ CONNECT_LIST_STORAGE_POOLS_MPATH = ConnectListAllStoragePoolsFlags(C.VIR_CONNECT_LIST_STORAGE_POOLS_MPATH)
+ CONNECT_LIST_STORAGE_POOLS_RBD = ConnectListAllStoragePoolsFlags(C.VIR_CONNECT_LIST_STORAGE_POOLS_RBD)
+ CONNECT_LIST_STORAGE_POOLS_SHEEPDOG = ConnectListAllStoragePoolsFlags(C.VIR_CONNECT_LIST_STORAGE_POOLS_SHEEPDOG)
+ CONNECT_LIST_STORAGE_POOLS_GLUSTER = ConnectListAllStoragePoolsFlags(C.VIR_CONNECT_LIST_STORAGE_POOLS_GLUSTER)
+ CONNECT_LIST_STORAGE_POOLS_ZFS = ConnectListAllStoragePoolsFlags(C.VIR_CONNECT_LIST_STORAGE_POOLS_ZFS)
+ CONNECT_LIST_STORAGE_POOLS_VSTORAGE = ConnectListAllStoragePoolsFlags(C.VIR_CONNECT_LIST_STORAGE_POOLS_VSTORAGE)
+)
+
+type ConnectBaselineCPUFlags int
+
+const (
+ CONNECT_BASELINE_CPU_EXPAND_FEATURES = ConnectBaselineCPUFlags(C.VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES)
+ CONNECT_BASELINE_CPU_MIGRATABLE = ConnectBaselineCPUFlags(C.VIR_CONNECT_BASELINE_CPU_MIGRATABLE)
+)
+
+type ConnectCompareCPUFlags int
+
+const (
+ CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE = ConnectCompareCPUFlags(C.VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE)
+)
+
+type ConnectListAllInterfacesFlags int
+
+const (
+ CONNECT_LIST_INTERFACES_INACTIVE = ConnectListAllInterfacesFlags(C.VIR_CONNECT_LIST_INTERFACES_INACTIVE)
+ CONNECT_LIST_INTERFACES_ACTIVE = ConnectListAllInterfacesFlags(C.VIR_CONNECT_LIST_INTERFACES_ACTIVE)
+)
+
+type ConnectListAllNodeDeviceFlags int
+
+const (
+ CONNECT_LIST_NODE_DEVICES_CAP_SYSTEM = ConnectListAllNodeDeviceFlags(C.VIR_CONNECT_LIST_NODE_DEVICES_CAP_SYSTEM)
+ CONNECT_LIST_NODE_DEVICES_CAP_PCI_DEV = ConnectListAllNodeDeviceFlags(C.VIR_CONNECT_LIST_NODE_DEVICES_CAP_PCI_DEV)
+ CONNECT_LIST_NODE_DEVICES_CAP_USB_DEV = ConnectListAllNodeDeviceFlags(C.VIR_CONNECT_LIST_NODE_DEVICES_CAP_USB_DEV)
+ CONNECT_LIST_NODE_DEVICES_CAP_USB_INTERFACE = ConnectListAllNodeDeviceFlags(C.VIR_CONNECT_LIST_NODE_DEVICES_CAP_USB_INTERFACE)
+ CONNECT_LIST_NODE_DEVICES_CAP_NET = ConnectListAllNodeDeviceFlags(C.VIR_CONNECT_LIST_NODE_DEVICES_CAP_NET)
+ CONNECT_LIST_NODE_DEVICES_CAP_SCSI_HOST = ConnectListAllNodeDeviceFlags(C.VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_HOST)
+ CONNECT_LIST_NODE_DEVICES_CAP_SCSI_TARGET = ConnectListAllNodeDeviceFlags(C.VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_TARGET)
+ CONNECT_LIST_NODE_DEVICES_CAP_SCSI = ConnectListAllNodeDeviceFlags(C.VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI)
+ CONNECT_LIST_NODE_DEVICES_CAP_STORAGE = ConnectListAllNodeDeviceFlags(C.VIR_CONNECT_LIST_NODE_DEVICES_CAP_STORAGE)
+ CONNECT_LIST_NODE_DEVICES_CAP_FC_HOST = ConnectListAllNodeDeviceFlags(C.VIR_CONNECT_LIST_NODE_DEVICES_CAP_FC_HOST)
+ CONNECT_LIST_NODE_DEVICES_CAP_VPORTS = ConnectListAllNodeDeviceFlags(C.VIR_CONNECT_LIST_NODE_DEVICES_CAP_VPORTS)
+ CONNECT_LIST_NODE_DEVICES_CAP_SCSI_GENERIC = ConnectListAllNodeDeviceFlags(C.VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_GENERIC)
+ CONNECT_LIST_NODE_DEVICES_CAP_DRM = ConnectListAllNodeDeviceFlags(C.VIR_CONNECT_LIST_NODE_DEVICES_CAP_DRM)
+ CONNECT_LIST_NODE_DEVICES_CAP_MDEV = ConnectListAllNodeDeviceFlags(C.VIR_CONNECT_LIST_NODE_DEVICES_CAP_MDEV)
+ CONNECT_LIST_NODE_DEVICES_CAP_MDEV_TYPES = ConnectListAllNodeDeviceFlags(C.VIR_CONNECT_LIST_NODE_DEVICES_CAP_MDEV_TYPES)
+ CONNECT_LIST_NODE_DEVICES_CAP_CCW_DEV = ConnectListAllNodeDeviceFlags(C.VIR_CONNECT_LIST_NODE_DEVICES_CAP_CCW_DEV)
+)
+
+type ConnectListAllSecretsFlags int
+
+const (
+ CONNECT_LIST_SECRETS_EPHEMERAL = ConnectListAllSecretsFlags(C.VIR_CONNECT_LIST_SECRETS_EPHEMERAL)
+ CONNECT_LIST_SECRETS_NO_EPHEMERAL = ConnectListAllSecretsFlags(C.VIR_CONNECT_LIST_SECRETS_NO_EPHEMERAL)
+ CONNECT_LIST_SECRETS_PRIVATE = ConnectListAllSecretsFlags(C.VIR_CONNECT_LIST_SECRETS_PRIVATE)
+ CONNECT_LIST_SECRETS_NO_PRIVATE = ConnectListAllSecretsFlags(C.VIR_CONNECT_LIST_SECRETS_NO_PRIVATE)
+)
+
+type ConnectGetAllDomainStatsFlags int
+
+const (
+ CONNECT_GET_ALL_DOMAINS_STATS_ACTIVE = ConnectGetAllDomainStatsFlags(C.VIR_CONNECT_GET_ALL_DOMAINS_STATS_ACTIVE)
+ CONNECT_GET_ALL_DOMAINS_STATS_INACTIVE = ConnectGetAllDomainStatsFlags(C.VIR_CONNECT_GET_ALL_DOMAINS_STATS_INACTIVE)
+ CONNECT_GET_ALL_DOMAINS_STATS_PERSISTENT = ConnectGetAllDomainStatsFlags(C.VIR_CONNECT_GET_ALL_DOMAINS_STATS_PERSISTENT)
+ CONNECT_GET_ALL_DOMAINS_STATS_TRANSIENT = ConnectGetAllDomainStatsFlags(C.VIR_CONNECT_GET_ALL_DOMAINS_STATS_TRANSIENT)
+ CONNECT_GET_ALL_DOMAINS_STATS_RUNNING = ConnectGetAllDomainStatsFlags(C.VIR_CONNECT_GET_ALL_DOMAINS_STATS_RUNNING)
+ CONNECT_GET_ALL_DOMAINS_STATS_PAUSED = ConnectGetAllDomainStatsFlags(C.VIR_CONNECT_GET_ALL_DOMAINS_STATS_PAUSED)
+ CONNECT_GET_ALL_DOMAINS_STATS_SHUTOFF = ConnectGetAllDomainStatsFlags(C.VIR_CONNECT_GET_ALL_DOMAINS_STATS_SHUTOFF)
+ CONNECT_GET_ALL_DOMAINS_STATS_OTHER = ConnectGetAllDomainStatsFlags(C.VIR_CONNECT_GET_ALL_DOMAINS_STATS_OTHER)
+ CONNECT_GET_ALL_DOMAINS_STATS_NOWAIT = ConnectGetAllDomainStatsFlags(C.VIR_CONNECT_GET_ALL_DOMAINS_STATS_NOWAIT)
+ CONNECT_GET_ALL_DOMAINS_STATS_BACKING = ConnectGetAllDomainStatsFlags(C.VIR_CONNECT_GET_ALL_DOMAINS_STATS_BACKING)
+ CONNECT_GET_ALL_DOMAINS_STATS_ENFORCE_STATS = ConnectGetAllDomainStatsFlags(C.VIR_CONNECT_GET_ALL_DOMAINS_STATS_ENFORCE_STATS)
+)
+
+type ConnectFlags int
+
+const (
+ CONNECT_RO = ConnectFlags(C.VIR_CONNECT_RO)
+ CONNECT_NO_ALIASES = ConnectFlags(C.VIR_CONNECT_NO_ALIASES)
+)
+
+type ConnectDomainEventAgentLifecycleState int
+
+const (
+ CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_STATE_CONNECTED = ConnectDomainEventAgentLifecycleState(C.VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_STATE_CONNECTED)
+ CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_STATE_DISCONNECTED = ConnectDomainEventAgentLifecycleState(C.VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_STATE_DISCONNECTED)
+)
+
+type ConnectDomainEventAgentLifecycleReason int
+
+const (
+ CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_REASON_UNKNOWN = ConnectDomainEventAgentLifecycleReason(C.VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_REASON_UNKNOWN)
+ CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_REASON_DOMAIN_STARTED = ConnectDomainEventAgentLifecycleReason(C.VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_REASON_DOMAIN_STARTED)
+ CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_REASON_CHANNEL = ConnectDomainEventAgentLifecycleReason(C.VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_REASON_CHANNEL)
+)
+
+type CPUCompareResult int
+
+const (
+ CPU_COMPARE_ERROR = CPUCompareResult(C.VIR_CPU_COMPARE_ERROR)
+ CPU_COMPARE_INCOMPATIBLE = CPUCompareResult(C.VIR_CPU_COMPARE_INCOMPATIBLE)
+ CPU_COMPARE_IDENTICAL = CPUCompareResult(C.VIR_CPU_COMPARE_IDENTICAL)
+ CPU_COMPARE_SUPERSET = CPUCompareResult(C.VIR_CPU_COMPARE_SUPERSET)
+)
+
+type NodeAllocPagesFlags int
+
+const (
+ NODE_ALLOC_PAGES_ADD = NodeAllocPagesFlags(C.VIR_NODE_ALLOC_PAGES_ADD)
+ NODE_ALLOC_PAGES_SET = NodeAllocPagesFlags(C.VIR_NODE_ALLOC_PAGES_SET)
+)
+
+type NodeSuspendTarget int
+
+const (
+ NODE_SUSPEND_TARGET_MEM = NodeSuspendTarget(C.VIR_NODE_SUSPEND_TARGET_MEM)
+ NODE_SUSPEND_TARGET_DISK = NodeSuspendTarget(C.VIR_NODE_SUSPEND_TARGET_DISK)
+ NODE_SUSPEND_TARGET_HYBRID = NodeSuspendTarget(C.VIR_NODE_SUSPEND_TARGET_HYBRID)
+)
+
+type NodeGetCPUStatsAllCPUs int
+
+const (
+ NODE_CPU_STATS_ALL_CPUS = NodeGetCPUStatsAllCPUs(C.VIR_NODE_CPU_STATS_ALL_CPUS)
+)
+
+const (
+ NODE_MEMORY_STATS_ALL_CELLS = int(C.VIR_NODE_MEMORY_STATS_ALL_CELLS)
+)
+
+type ConnectCredentialType int
+
+const (
+ CRED_USERNAME = ConnectCredentialType(C.VIR_CRED_USERNAME)
+ CRED_AUTHNAME = ConnectCredentialType(C.VIR_CRED_AUTHNAME)
+ CRED_LANGUAGE = ConnectCredentialType(C.VIR_CRED_LANGUAGE)
+ CRED_CNONCE = ConnectCredentialType(C.VIR_CRED_CNONCE)
+ CRED_PASSPHRASE = ConnectCredentialType(C.VIR_CRED_PASSPHRASE)
+ CRED_ECHOPROMPT = ConnectCredentialType(C.VIR_CRED_ECHOPROMPT)
+ CRED_NOECHOPROMPT = ConnectCredentialType(C.VIR_CRED_NOECHOPROMPT)
+ CRED_REALM = ConnectCredentialType(C.VIR_CRED_REALM)
+ CRED_EXTERNAL = ConnectCredentialType(C.VIR_CRED_EXTERNAL)
+)
+
+type Connect struct {
+ ptr C.virConnectPtr
+}
+
+type NodeInfo struct {
+ Model string
+ Memory uint64
+ Cpus uint
+ MHz uint
+ Nodes uint32
+ Sockets uint32
+ Cores uint32
+ Threads uint32
+}
+
+// Additional data associated to the connection.
+type virConnectionData struct {
+ errCallbackId *int
+ closeCallbackId *int
+}
+
+var connections map[C.virConnectPtr]*virConnectionData
+var connectionsLock sync.RWMutex
+
+func init() {
+ connections = make(map[C.virConnectPtr]*virConnectionData)
+}
+
+func saveConnectionData(c *Connect, d *virConnectionData) {
+ if c.ptr == nil {
+ return // Or panic?
+ }
+ connectionsLock.Lock()
+ defer connectionsLock.Unlock()
+ connections[c.ptr] = d
+}
+
+func getConnectionData(c *Connect) *virConnectionData {
+ connectionsLock.RLock()
+ d := connections[c.ptr]
+ connectionsLock.RUnlock()
+ if d != nil {
+ return d
+ }
+ d = &virConnectionData{}
+ saveConnectionData(c, d)
+ return d
+}
+
+func releaseConnectionData(c *Connect) {
+ if c.ptr == nil {
+ return
+ }
+ connectionsLock.Lock()
+ defer connectionsLock.Unlock()
+ delete(connections, c.ptr)
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-host.html#virGetVersion
+func GetVersion() (uint32, error) {
+ var version C.ulong
+ var err C.virError
+ ret := C.virGetVersionWrapper(&version, nil, nil, &err)
+ if ret < 0 {
+ return 0, makeError(&err)
+ }
+ return uint32(version), nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-host.html#virConnectOpen
+func NewConnect(uri string) (*Connect, error) {
+ var cUri *C.char
+ if uri != "" {
+ cUri = C.CString(uri)
+ defer C.free(unsafe.Pointer(cUri))
+ }
+ var err C.virError
+ ptr := C.virConnectOpenWrapper(cUri, &err)
+ if ptr == nil {
+ return nil, makeError(&err)
+ }
+ return &Connect{ptr: ptr}, nil
+}
+
+type ConnectCredential struct {
+ Type ConnectCredentialType
+ Prompt string
+ Challenge string
+ DefResult string
+ Result string
+ ResultLen int
+}
+
+type ConnectAuthCallback func(creds []*ConnectCredential)
+
+type ConnectAuth struct {
+ CredType []ConnectCredentialType
+ Callback ConnectAuthCallback
+}
+
+//export connectAuthCallback
+func connectAuthCallback(ccredlist C.virConnectCredentialPtr, ncred C.uint, callbackID C.int) C.int {
+ cred := make([]*ConnectCredential, int(ncred))
+
+ for i := 0; i < int(ncred); i++ {
+ ccred := (C.virConnectCredentialPtr)(unsafe.Pointer((uintptr)(unsafe.Pointer(ccredlist)) + (unsafe.Sizeof(*ccredlist) * uintptr(i))))
+ cred[i] = &ConnectCredential{
+ Type: ConnectCredentialType(ccred._type),
+ Prompt: C.GoString(ccred.prompt),
+ Challenge: C.GoString(ccred.challenge),
+ DefResult: C.GoString(ccred.defresult),
+ ResultLen: -1,
+ }
+ }
+ callbackEntry := getCallbackId(int(callbackID))
+ callback, ok := callbackEntry.(ConnectAuthCallback)
+ if !ok {
+ panic("Unexpected callback type")
+ }
+
+ callback(cred)
+
+ for i := 0; i < int(ncred); i++ {
+ ccred := (C.virConnectCredentialPtr)(unsafe.Pointer((uintptr)(unsafe.Pointer(ccredlist)) + (unsafe.Sizeof(*ccredlist) * uintptr(i))))
+ if cred[i].ResultLen >= 0 {
+ ccred.result = C.CString(cred[i].Result)
+ ccred.resultlen = C.uint(cred[i].ResultLen)
+ }
+ }
+
+ return 0
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-host.html#virConnectOpenAuth
+func NewConnectWithAuth(uri string, auth *ConnectAuth, flags ConnectFlags) (*Connect, error) {
+ var cUri *C.char
+
+ ccredtype := make([]C.int, len(auth.CredType))
+
+ for i := 0; i < len(auth.CredType); i++ {
+ ccredtype[i] = C.int(auth.CredType[i])
+ }
+
+ if uri != "" {
+ cUri = C.CString(uri)
+ defer C.free(unsafe.Pointer(cUri))
+ }
+
+ callbackID := registerCallbackId(auth.Callback)
+
+ var err C.virError
+ ptr := C.virConnectOpenAuthWrapper(cUri, &ccredtype[0], C.uint(len(auth.CredType)), C.int(callbackID), C.uint(flags), &err)
+ freeCallbackId(callbackID)
+ if ptr == nil {
+ return nil, makeError(&err)
+ }
+ return &Connect{ptr: ptr}, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-host.html#virConnectOpenReadOnly
+func NewConnectReadOnly(uri string) (*Connect, error) {
+ var cUri *C.char
+ if uri != "" {
+ cUri = C.CString(uri)
+ defer C.free(unsafe.Pointer(cUri))
+ }
+ var err C.virError
+ ptr := C.virConnectOpenReadOnlyWrapper(cUri, &err)
+ if ptr == nil {
+ return nil, makeError(&err)
+ }
+ return &Connect{ptr: ptr}, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-host.html#virConnectClose
+func (c *Connect) Close() (int, error) {
+ var err C.virError
+ result := int(C.virConnectCloseWrapper(c.ptr, &err))
+ if result == -1 {
+ return result, makeError(&err)
+ }
+ if result == 0 {
+ // No more reference to this connection, release data.
+ releaseConnectionData(c)
+ c.ptr = nil
+ }
+ return result, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-host.html#virConnectRef
+func (c *Connect) Ref() error {
+ var err C.virError
+ ret := C.virConnectRefWrapper(c.ptr, &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+type CloseCallback func(conn *Connect, reason ConnectCloseReason)
+
+// Register a close callback for the given destination. Only one
+// callback per connection is allowed. Setting a callback will remove
+// the previous one.
+// See also https://libvirt.org/html/libvirt-libvirt-host.html#virConnectRegisterCloseCallback
+func (c *Connect) RegisterCloseCallback(callback CloseCallback) error {
+ c.UnregisterCloseCallback()
+ goCallbackId := registerCallbackId(callback)
+ var err C.virError
+ res := C.virConnectRegisterCloseCallbackWrapper(c.ptr, C.long(goCallbackId), &err)
+ if res != 0 {
+ freeCallbackId(goCallbackId)
+ return makeError(&err)
+ }
+ connData := getConnectionData(c)
+ connData.closeCallbackId = &goCallbackId
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-host.html#virConnectUnregisterCloseCallback
+func (c *Connect) UnregisterCloseCallback() error {
+ connData := getConnectionData(c)
+ if connData.closeCallbackId == nil {
+ return nil
+ }
+ var err C.virError
+ res := C.virConnectUnregisterCloseCallbackWrapper(c.ptr, &err)
+ if res != 0 {
+ return makeError(&err)
+ }
+ connData.closeCallbackId = nil
+ return nil
+}
+
+//export closeCallback
+func closeCallback(conn C.virConnectPtr, reason ConnectCloseReason, goCallbackId int) {
+ callbackFunc := getCallbackId(goCallbackId)
+ callback, ok := callbackFunc.(CloseCallback)
+ if !ok {
+ panic("Inappropriate callback type called")
+ }
+ callback(&Connect{ptr: conn}, reason)
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-host.html#virConnectGetCapabilities
+func (c *Connect) GetCapabilities() (string, error) {
+ var err C.virError
+ str := C.virConnectGetCapabilitiesWrapper(c.ptr, &err)
+ if str == nil {
+ return "", makeError(&err)
+ }
+ capabilities := C.GoString(str)
+ C.free(unsafe.Pointer(str))
+ return capabilities, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-host.html#virNodeGetInfo
+func (c *Connect) GetNodeInfo() (*NodeInfo, error) {
+ var cinfo C.virNodeInfo
+ var err C.virError
+ result := C.virNodeGetInfoWrapper(c.ptr, &cinfo, &err)
+ if result == -1 {
+ return nil, makeError(&err)
+ }
+ return &NodeInfo{
+ Model: C.GoString((*C.char)(unsafe.Pointer(&cinfo.model[0]))),
+ Memory: uint64(cinfo.memory),
+ Cpus: uint(cinfo.cpus),
+ MHz: uint(cinfo.mhz),
+ Nodes: uint32(cinfo.nodes),
+ Sockets: uint32(cinfo.sockets),
+ Cores: uint32(cinfo.cores),
+ Threads: uint32(cinfo.threads),
+ }, nil
+}
+
+func (ni *NodeInfo) GetMaxCPUs() uint32 {
+ return ni.Nodes * ni.Sockets * ni.Cores * ni.Threads
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-host.html#virConnectGetHostname
+func (c *Connect) GetHostname() (string, error) {
+ var err C.virError
+ str := C.virConnectGetHostnameWrapper(c.ptr, &err)
+ if str == nil {
+ return "", makeError(&err)
+ }
+ hostname := C.GoString(str)
+ C.free(unsafe.Pointer(str))
+ return hostname, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-host.html#virConnectGetLibVersion
+func (c *Connect) GetLibVersion() (uint32, error) {
+ var version C.ulong
+ var err C.virError
+ ret := C.virConnectGetLibVersionWrapper(c.ptr, &version, &err)
+ if ret < 0 {
+ return 0, makeError(&err)
+ }
+ return uint32(version), nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-host.html#virConnectGetType
+func (c *Connect) GetType() (string, error) {
+ var err C.virError
+ str := C.virConnectGetTypeWrapper(c.ptr, &err)
+ if str == nil {
+ return "", makeError(&err)
+ }
+ hypDriver := C.GoString(str)
+ return hypDriver, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-host.html#virConnectIsAlive
+func (c *Connect) IsAlive() (bool, error) {
+ var err C.virError
+ result := C.virConnectIsAliveWrapper(c.ptr, &err)
+ if result == -1 {
+ return false, makeError(&err)
+ }
+ if result == 1 {
+ return true, nil
+ }
+ return false, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-host.html#virConnectIsEncrypted
+func (c *Connect) IsEncrypted() (bool, error) {
+ var err C.virError
+ result := C.virConnectIsEncryptedWrapper(c.ptr, &err)
+ if result == -1 {
+ return false, makeError(&err)
+ }
+ if result == 1 {
+ return true, nil
+ }
+ return false, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-host.html#virConnectIsSecure
+func (c *Connect) IsSecure() (bool, error) {
+ var err C.virError
+ result := C.virConnectIsSecureWrapper(c.ptr, &err)
+ if result == -1 {
+ return false, makeError(&err)
+ }
+ if result == 1 {
+ return true, nil
+ }
+ return false, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virConnectListDefinedDomains
+func (c *Connect) ListDefinedDomains() ([]string, error) {
+ var names [1024](*C.char)
+ namesPtr := unsafe.Pointer(&names)
+ var err C.virError
+ numDomains := C.virConnectListDefinedDomainsWrapper(
+ c.ptr,
+ (**C.char)(namesPtr),
+ 1024, &err)
+ if numDomains == -1 {
+ return nil, makeError(&err)
+ }
+ goNames := make([]string, numDomains)
+ for k := 0; k < int(numDomains); k++ {
+ goNames[k] = C.GoString(names[k])
+ C.free(unsafe.Pointer(names[k]))
+ }
+ return goNames, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virConnectListDomains
+func (c *Connect) ListDomains() ([]uint32, error) {
+ var cDomainsIds [512](uint32)
+ cDomainsPointer := unsafe.Pointer(&cDomainsIds)
+ var err C.virError
+ numDomains := C.virConnectListDomainsWrapper(c.ptr, (*C.int)(cDomainsPointer), 512, &err)
+ if numDomains == -1 {
+ return nil, makeError(&err)
+ }
+
+ return cDomainsIds[:numDomains], nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-interface.html#virConnectListInterfaces
+func (c *Connect) ListInterfaces() ([]string, error) {
+ const maxIfaces = 1024
+ var names [maxIfaces](*C.char)
+ namesPtr := unsafe.Pointer(&names)
+ var err C.virError
+ numIfaces := C.virConnectListInterfacesWrapper(
+ c.ptr,
+ (**C.char)(namesPtr),
+ maxIfaces, &err)
+ if numIfaces == -1 {
+ return nil, makeError(&err)
+ }
+ goNames := make([]string, numIfaces)
+ for k := 0; k < int(numIfaces); k++ {
+ goNames[k] = C.GoString(names[k])
+ C.free(unsafe.Pointer(names[k]))
+ }
+ return goNames, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-network.html#virConnectListNetworks
+func (c *Connect) ListNetworks() ([]string, error) {
+ const maxNets = 1024
+ var names [maxNets](*C.char)
+ namesPtr := unsafe.Pointer(&names)
+ var err C.virError
+ numNetworks := C.virConnectListNetworksWrapper(
+ c.ptr,
+ (**C.char)(namesPtr),
+ maxNets, &err)
+ if numNetworks == -1 {
+ return nil, makeError(&err)
+ }
+ goNames := make([]string, numNetworks)
+ for k := 0; k < int(numNetworks); k++ {
+ goNames[k] = C.GoString(names[k])
+ C.free(unsafe.Pointer(names[k]))
+ }
+ return goNames, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-nwfilter.html#virConnectListNWFilters
+func (c *Connect) ListNWFilters() ([]string, error) {
+ const maxFilters = 1024
+ var names [maxFilters](*C.char)
+ namesPtr := unsafe.Pointer(&names)
+ var err C.virError
+ numNWFilters := C.virConnectListNWFiltersWrapper(
+ c.ptr,
+ (**C.char)(namesPtr),
+ maxFilters, &err)
+ if numNWFilters == -1 {
+ return nil, makeError(&err)
+ }
+ goNames := make([]string, numNWFilters)
+ for k := 0; k < int(numNWFilters); k++ {
+ goNames[k] = C.GoString(names[k])
+ C.free(unsafe.Pointer(names[k]))
+ }
+ return goNames, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-storage.html#virConnectListStoragePools
+func (c *Connect) ListStoragePools() ([]string, error) {
+ const maxPools = 1024
+ var names [maxPools](*C.char)
+ namesPtr := unsafe.Pointer(&names)
+ var err C.virError
+ numStoragePools := C.virConnectListStoragePoolsWrapper(
+ c.ptr,
+ (**C.char)(namesPtr),
+ maxPools, &err)
+ if numStoragePools == -1 {
+ return nil, makeError(&err)
+ }
+ goNames := make([]string, numStoragePools)
+ for k := 0; k < int(numStoragePools); k++ {
+ goNames[k] = C.GoString(names[k])
+ C.free(unsafe.Pointer(names[k]))
+ }
+ return goNames, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-secret.html#virConnectListSecrets
+func (c *Connect) ListSecrets() ([]string, error) {
+ const maxSecrets = 1024
+ var uuids [maxSecrets](*C.char)
+ uuidsPtr := unsafe.Pointer(&uuids)
+ var err C.virError
+ numSecrets := C.virConnectListSecretsWrapper(
+ c.ptr,
+ (**C.char)(uuidsPtr),
+ maxSecrets, &err)
+ if numSecrets == -1 {
+ return nil, makeError(&err)
+ }
+ goUuids := make([]string, numSecrets)
+ for k := 0; k < int(numSecrets); k++ {
+ goUuids[k] = C.GoString(uuids[k])
+ C.free(unsafe.Pointer(uuids[k]))
+ }
+ return goUuids, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeListDevices
+func (c *Connect) ListDevices(cap string, flags uint32) ([]string, error) {
+ ccap := C.CString(cap)
+ defer C.free(unsafe.Pointer(ccap))
+ const maxNodeDevices = 1024
+ var uuids [maxNodeDevices](*C.char)
+ uuidsPtr := unsafe.Pointer(&uuids)
+ var err C.virError
+ numNodeDevices := C.virNodeListDevicesWrapper(
+ c.ptr, ccap,
+ (**C.char)(uuidsPtr),
+ maxNodeDevices, C.uint(flags), &err)
+ if numNodeDevices == -1 {
+ return nil, makeError(&err)
+ }
+ goUuids := make([]string, numNodeDevices)
+ for k := 0; k < int(numNodeDevices); k++ {
+ goUuids[k] = C.GoString(uuids[k])
+ C.free(unsafe.Pointer(uuids[k]))
+ }
+ return goUuids, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainLookupByID
+func (c *Connect) LookupDomainById(id uint32) (*Domain, error) {
+ var err C.virError
+ ptr := C.virDomainLookupByIDWrapper(c.ptr, C.int(id), &err)
+ if ptr == nil {
+ return nil, makeError(&err)
+ }
+ return &Domain{ptr: ptr}, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainLookupByName
+func (c *Connect) LookupDomainByName(id string) (*Domain, error) {
+ cName := C.CString(id)
+ defer C.free(unsafe.Pointer(cName))
+ var err C.virError
+ ptr := C.virDomainLookupByNameWrapper(c.ptr, cName, &err)
+ if ptr == nil {
+ return nil, makeError(&err)
+ }
+ return &Domain{ptr: ptr}, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainLookupByUUIDString
+func (c *Connect) LookupDomainByUUIDString(uuid string) (*Domain, error) {
+ cUuid := C.CString(uuid)
+ defer C.free(unsafe.Pointer(cUuid))
+ var err C.virError
+ ptr := C.virDomainLookupByUUIDStringWrapper(c.ptr, cUuid, &err)
+ if ptr == nil {
+ return nil, makeError(&err)
+ }
+ return &Domain{ptr: ptr}, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainLookupByUUID
+func (c *Connect) LookupDomainByUUID(uuid []byte) (*Domain, error) {
+ if len(uuid) != C.VIR_UUID_BUFLEN {
+ return nil, fmt.Errorf("UUID must be exactly %d bytes in size",
+ int(C.VIR_UUID_BUFLEN))
+ }
+ cUuid := make([]C.uchar, C.VIR_UUID_BUFLEN)
+ for i := 0; i < C.VIR_UUID_BUFLEN; i++ {
+ cUuid[i] = C.uchar(uuid[i])
+ }
+ var err C.virError
+ ptr := C.virDomainLookupByUUIDWrapper(c.ptr, &cUuid[0], &err)
+ if ptr == nil {
+ return nil, makeError(&err)
+ }
+ return &Domain{ptr: ptr}, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainCreateXML
+func (c *Connect) DomainCreateXML(xmlConfig string, flags DomainCreateFlags) (*Domain, error) {
+ cXml := C.CString(string(xmlConfig))
+ defer C.free(unsafe.Pointer(cXml))
+ var err C.virError
+ ptr := C.virDomainCreateXMLWrapper(c.ptr, cXml, C.uint(flags), &err)
+ if ptr == nil {
+ return nil, makeError(&err)
+ }
+ return &Domain{ptr: ptr}, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainCreateXMLWithFiles
+func (c *Connect) DomainCreateXMLWithFiles(xmlConfig string, files []os.File, flags DomainCreateFlags) (*Domain, error) {
+ cXml := C.CString(string(xmlConfig))
+ defer C.free(unsafe.Pointer(cXml))
+ cfiles := make([]C.int, len(files))
+ for i := 0; i < len(files); i++ {
+ cfiles[i] = C.int(files[i].Fd())
+ }
+ var err C.virError
+ ptr := C.virDomainCreateXMLWithFilesWrapper(c.ptr, cXml, C.uint(len(files)), (&cfiles[0]), C.uint(flags), &err)
+ if ptr == nil {
+ return nil, makeError(&err)
+ }
+ return &Domain{ptr: ptr}, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainDefineXML
+func (c *Connect) DomainDefineXML(xmlConfig string) (*Domain, error) {
+ cXml := C.CString(string(xmlConfig))
+ defer C.free(unsafe.Pointer(cXml))
+ var err C.virError
+ ptr := C.virDomainDefineXMLWrapper(c.ptr, cXml, &err)
+ if ptr == nil {
+ return nil, makeError(&err)
+ }
+ return &Domain{ptr: ptr}, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainDefineXMLFlags
+func (c *Connect) DomainDefineXMLFlags(xmlConfig string, flags DomainDefineFlags) (*Domain, error) {
+ if C.LIBVIR_VERSION_NUMBER < 1002012 {
+ return nil, makeNotImplementedError("virDomainDefineXMLFlags")
+ }
+ cXml := C.CString(string(xmlConfig))
+ defer C.free(unsafe.Pointer(cXml))
+ var err C.virError
+ ptr := C.virDomainDefineXMLFlagsWrapper(c.ptr, cXml, C.uint(flags), &err)
+ if ptr == nil {
+ return nil, makeError(&err)
+ }
+ return &Domain{ptr: ptr}, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-interface.html#virConnectListDefinedInterfaces
+func (c *Connect) ListDefinedInterfaces() ([]string, error) {
+ const maxIfaces = 1024
+ var names [maxIfaces](*C.char)
+ namesPtr := unsafe.Pointer(&names)
+ var err C.virError
+ numIfaces := C.virConnectListDefinedInterfacesWrapper(
+ c.ptr,
+ (**C.char)(namesPtr),
+ maxIfaces, &err)
+ if numIfaces == -1 {
+ return nil, makeError(&err)
+ }
+ goNames := make([]string, numIfaces)
+ for k := 0; k < int(numIfaces); k++ {
+ goNames[k] = C.GoString(names[k])
+ C.free(unsafe.Pointer(names[k]))
+ }
+ return goNames, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-network.html#virConnectListDefinedNetworks
+func (c *Connect) ListDefinedNetworks() ([]string, error) {
+ const maxNets = 1024
+ var names [maxNets](*C.char)
+ namesPtr := unsafe.Pointer(&names)
+ var err C.virError
+ numNetworks := C.virConnectListDefinedNetworksWrapper(
+ c.ptr,
+ (**C.char)(namesPtr),
+ maxNets, &err)
+ if numNetworks == -1 {
+ return nil, makeError(&err)
+ }
+ goNames := make([]string, numNetworks)
+ for k := 0; k < int(numNetworks); k++ {
+ goNames[k] = C.GoString(names[k])
+ C.free(unsafe.Pointer(names[k]))
+ }
+ return goNames, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-storage.html#virConnectListDefinedStoragePools
+func (c *Connect) ListDefinedStoragePools() ([]string, error) {
+ const maxPools = 1024
+ var names [maxPools](*C.char)
+ namesPtr := unsafe.Pointer(&names)
+ var err C.virError
+ numStoragePools := C.virConnectListDefinedStoragePoolsWrapper(
+ c.ptr,
+ (**C.char)(namesPtr),
+ maxPools, &err)
+ if numStoragePools == -1 {
+ return nil, makeError(&err)
+ }
+ goNames := make([]string, numStoragePools)
+ for k := 0; k < int(numStoragePools); k++ {
+ goNames[k] = C.GoString(names[k])
+ C.free(unsafe.Pointer(names[k]))
+ }
+ return goNames, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virConnectNumOfDefinedDomains
+func (c *Connect) NumOfDefinedDomains() (int, error) {
+ var err C.virError
+ result := int(C.virConnectNumOfDefinedDomainsWrapper(c.ptr, &err))
+ if result == -1 {
+ return 0, makeError(&err)
+ }
+ return result, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-interface.html#virConnectNumOfDefinedInterfaces
+func (c *Connect) NumOfDefinedInterfaces() (int, error) {
+ var err C.virError
+ result := int(C.virConnectNumOfDefinedInterfacesWrapper(c.ptr, &err))
+ if result == -1 {
+ return 0, makeError(&err)
+ }
+ return result, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-network.html#virConnectNumOfDefinedNetworks
+func (c *Connect) NumOfDefinedNetworks() (int, error) {
+ var err C.virError
+ result := int(C.virConnectNumOfDefinedNetworksWrapper(c.ptr, &err))
+ if result == -1 {
+ return 0, makeError(&err)
+ }
+ return result, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-storage.html#virConnectNumOfDefinedStoragePools
+func (c *Connect) NumOfDefinedStoragePools() (int, error) {
+ var err C.virError
+ result := int(C.virConnectNumOfDefinedStoragePoolsWrapper(c.ptr, &err))
+ if result == -1 {
+ return 0, makeError(&err)
+ }
+ return result, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virConnectNumOfDomains
+func (c *Connect) NumOfDomains() (int, error) {
+ var err C.virError
+ result := int(C.virConnectNumOfDomainsWrapper(c.ptr, &err))
+ if result == -1 {
+ return 0, makeError(&err)
+ }
+ return result, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-storage.html#virConnectNumOfStoragePools
+func (c *Connect) NumOfStoragePools() (int, error) {
+ var err C.virError
+ result := int(C.virConnectNumOfStoragePoolsWrapper(c.ptr, &err))
+ if result == -1 {
+ return 0, makeError(&err)
+ }
+ return result, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-interface.html#virConnectNumOfInterfaces
+func (c *Connect) NumOfInterfaces() (int, error) {
+ var err C.virError
+ result := int(C.virConnectNumOfInterfacesWrapper(c.ptr, &err))
+ if result == -1 {
+ return 0, makeError(&err)
+ }
+ return result, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-network.html#virConnectNumOfNetworks
+func (c *Connect) NumOfNetworks() (int, error) {
+ var err C.virError
+ result := int(C.virConnectNumOfNetworksWrapper(c.ptr, &err))
+ if result == -1 {
+ return 0, makeError(&err)
+ }
+ return result, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-nwfilter.html#virConnectNumOfNWFilters
+func (c *Connect) NumOfNWFilters() (int, error) {
+ var err C.virError
+ result := int(C.virConnectNumOfNWFiltersWrapper(c.ptr, &err))
+ if result == -1 {
+ return 0, makeError(&err)
+ }
+ return result, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-secret.html#virConnectNumOfSecrets
+func (c *Connect) NumOfSecrets() (int, error) {
+ var err C.virError
+ result := int(C.virConnectNumOfSecretsWrapper(c.ptr, &err))
+ if result == -1 {
+ return 0, makeError(&err)
+ }
+ return result, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeNumOfDevices
+func (c *Connect) NumOfDevices(cap string, flags uint32) (int, error) {
+ ccap := C.CString(cap)
+ defer C.free(unsafe.Pointer(ccap))
+ var err C.virError
+ result := int(C.virNodeNumOfDevicesWrapper(c.ptr, ccap, C.uint(flags), &err))
+ if result == -1 {
+ return 0, makeError(&err)
+ }
+ return result, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkDefineXML
+func (c *Connect) NetworkDefineXML(xmlConfig string) (*Network, error) {
+ cXml := C.CString(string(xmlConfig))
+ defer C.free(unsafe.Pointer(cXml))
+ var err C.virError
+ ptr := C.virNetworkDefineXMLWrapper(c.ptr, cXml, &err)
+ if ptr == nil {
+ return nil, makeError(&err)
+ }
+ return &Network{ptr: ptr}, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkCreateXML
+func (c *Connect) NetworkCreateXML(xmlConfig string) (*Network, error) {
+ cXml := C.CString(string(xmlConfig))
+ defer C.free(unsafe.Pointer(cXml))
+ var err C.virError
+ ptr := C.virNetworkCreateXMLWrapper(c.ptr, cXml, &err)
+ if ptr == nil {
+ return nil, makeError(&err)
+ }
+ return &Network{ptr: ptr}, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkLookupByName
+func (c *Connect) LookupNetworkByName(name string) (*Network, error) {
+ cName := C.CString(name)
+ defer C.free(unsafe.Pointer(cName))
+ var err C.virError
+ ptr := C.virNetworkLookupByNameWrapper(c.ptr, cName, &err)
+ if ptr == nil {
+ return nil, makeError(&err)
+ }
+ return &Network{ptr: ptr}, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkLookupByUUIDString
+func (c *Connect) LookupNetworkByUUIDString(uuid string) (*Network, error) {
+ cUuid := C.CString(uuid)
+ defer C.free(unsafe.Pointer(cUuid))
+ var err C.virError
+ ptr := C.virNetworkLookupByUUIDStringWrapper(c.ptr, cUuid, &err)
+ if ptr == nil {
+ return nil, makeError(&err)
+ }
+ return &Network{ptr: ptr}, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkLookupByUUID
+func (c *Connect) LookupNetworkByUUID(uuid []byte) (*Network, error) {
+ if len(uuid) != C.VIR_UUID_BUFLEN {
+ return nil, fmt.Errorf("UUID must be exactly %d bytes in size",
+ int(C.VIR_UUID_BUFLEN))
+ }
+ cUuid := make([]C.uchar, C.VIR_UUID_BUFLEN)
+ for i := 0; i < C.VIR_UUID_BUFLEN; i++ {
+ cUuid[i] = C.uchar(uuid[i])
+ }
+ var err C.virError
+ ptr := C.virNetworkLookupByUUIDWrapper(c.ptr, &cUuid[0], &err)
+ if ptr == nil {
+ return nil, makeError(&err)
+ }
+ return &Network{ptr: ptr}, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-host.html#virConnectSetKeepAlive
+func (c *Connect) SetKeepAlive(interval int, count uint) error {
+ var err C.virError
+ res := int(C.virConnectSetKeepAliveWrapper(c.ptr, C.int(interval), C.uint(count), &err))
+ switch res {
+ case 0:
+ return nil
+ default:
+ return makeError(&err)
+ }
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-host.html#virConnectGetSysinfo
+func (c *Connect) GetSysinfo(flags uint32) (string, error) {
+ var err C.virError
+ cStr := C.virConnectGetSysinfoWrapper(c.ptr, C.uint(flags), &err)
+ if cStr == nil {
+ return "", makeError(&err)
+ }
+ info := C.GoString(cStr)
+ C.free(unsafe.Pointer(cStr))
+ return info, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-host.html#virConnectGetURI
+func (c *Connect) GetURI() (string, error) {
+ var err C.virError
+ cStr := C.virConnectGetURIWrapper(c.ptr, &err)
+ if cStr == nil {
+ return "", makeError(&err)
+ }
+ uri := C.GoString(cStr)
+ C.free(unsafe.Pointer(cStr))
+ return uri, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-host.html#virConnectGetMaxVcpus
+func (c *Connect) GetMaxVcpus(typeAttr string) (int, error) {
+ var cTypeAttr *C.char
+ if typeAttr != "" {
+ cTypeAttr = C.CString(typeAttr)
+ defer C.free(unsafe.Pointer(cTypeAttr))
+ }
+ var err C.virError
+ result := int(C.virConnectGetMaxVcpusWrapper(c.ptr, cTypeAttr, &err))
+ if result == -1 {
+ return 0, makeError(&err)
+ }
+ return result, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceDefineXML
+func (c *Connect) InterfaceDefineXML(xmlConfig string, flags uint32) (*Interface, error) {
+ cXml := C.CString(string(xmlConfig))
+ defer C.free(unsafe.Pointer(cXml))
+ var err C.virError
+ ptr := C.virInterfaceDefineXMLWrapper(c.ptr, cXml, C.uint(flags), &err)
+ if ptr == nil {
+ return nil, makeError(&err)
+ }
+ return &Interface{ptr: ptr}, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceLookupByName
+func (c *Connect) LookupInterfaceByName(name string) (*Interface, error) {
+ cName := C.CString(name)
+ defer C.free(unsafe.Pointer(cName))
+ var err C.virError
+ ptr := C.virInterfaceLookupByNameWrapper(c.ptr, cName, &err)
+ if ptr == nil {
+ return nil, makeError(&err)
+ }
+ return &Interface{ptr: ptr}, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceLookupByMACString
+func (c *Connect) LookupInterfaceByMACString(mac string) (*Interface, error) {
+ cName := C.CString(mac)
+ defer C.free(unsafe.Pointer(cName))
+ var err C.virError
+ ptr := C.virInterfaceLookupByMACStringWrapper(c.ptr, cName, &err)
+ if ptr == nil {
+ return nil, makeError(&err)
+ }
+ return &Interface{ptr: ptr}, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolDefineXML
+func (c *Connect) StoragePoolDefineXML(xmlConfig string, flags uint32) (*StoragePool, error) {
+ cXml := C.CString(string(xmlConfig))
+ defer C.free(unsafe.Pointer(cXml))
+ var err C.virError
+ ptr := C.virStoragePoolDefineXMLWrapper(c.ptr, cXml, C.uint(flags), &err)
+ if ptr == nil {
+ return nil, makeError(&err)
+ }
+ return &StoragePool{ptr: ptr}, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolCreateXML
+func (c *Connect) StoragePoolCreateXML(xmlConfig string, flags StoragePoolCreateFlags) (*StoragePool, error) {
+ cXml := C.CString(string(xmlConfig))
+ defer C.free(unsafe.Pointer(cXml))
+ var err C.virError
+ ptr := C.virStoragePoolCreateXMLWrapper(c.ptr, cXml, C.uint(flags), &err)
+ if ptr == nil {
+ return nil, makeError(&err)
+ }
+ return &StoragePool{ptr: ptr}, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolLookupByName
+func (c *Connect) LookupStoragePoolByName(name string) (*StoragePool, error) {
+ cName := C.CString(name)
+ defer C.free(unsafe.Pointer(cName))
+ var err C.virError
+ ptr := C.virStoragePoolLookupByNameWrapper(c.ptr, cName, &err)
+ if ptr == nil {
+ return nil, makeError(&err)
+ }
+ return &StoragePool{ptr: ptr}, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolLookupByUUIDString
+func (c *Connect) LookupStoragePoolByUUIDString(uuid string) (*StoragePool, error) {
+ cUuid := C.CString(uuid)
+ defer C.free(unsafe.Pointer(cUuid))
+ var err C.virError
+ ptr := C.virStoragePoolLookupByUUIDStringWrapper(c.ptr, cUuid, &err)
+ if ptr == nil {
+ return nil, makeError(&err)
+ }
+ return &StoragePool{ptr: ptr}, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolLookupByUUID
+func (c *Connect) LookupStoragePoolByUUID(uuid []byte) (*StoragePool, error) {
+ if len(uuid) != C.VIR_UUID_BUFLEN {
+ return nil, fmt.Errorf("UUID must be exactly %d bytes in size",
+ int(C.VIR_UUID_BUFLEN))
+ }
+ cUuid := make([]C.uchar, C.VIR_UUID_BUFLEN)
+ for i := 0; i < C.VIR_UUID_BUFLEN; i++ {
+ cUuid[i] = C.uchar(uuid[i])
+ }
+ var err C.virError
+ ptr := C.virStoragePoolLookupByUUIDWrapper(c.ptr, &cUuid[0], &err)
+ if ptr == nil {
+ return nil, makeError(&err)
+ }
+ return &StoragePool{ptr: ptr}, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolLookupByTargetPath
+func (c *Connect) LookupStoragePoolByTargetPath(path string) (*StoragePool, error) {
+ if C.LIBVIR_VERSION_NUMBER < 4001000 {
+ return nil, makeNotImplementedError("virStoragePoolLookupByTargetPath")
+ }
+ cPath := C.CString(path)
+ defer C.free(unsafe.Pointer(cPath))
+ var err C.virError
+ ptr := C.virStoragePoolLookupByTargetPathWrapper(c.ptr, cPath, &err)
+ if ptr == nil {
+ return nil, makeError(&err)
+ }
+ return &StoragePool{ptr: ptr}, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-nwfilter.html#virNWFilterDefineXML
+func (c *Connect) NWFilterDefineXML(xmlConfig string) (*NWFilter, error) {
+ cXml := C.CString(string(xmlConfig))
+ defer C.free(unsafe.Pointer(cXml))
+ var err C.virError
+ ptr := C.virNWFilterDefineXMLWrapper(c.ptr, cXml, &err)
+ if ptr == nil {
+ return nil, makeError(&err)
+ }
+ return &NWFilter{ptr: ptr}, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-nwfilter.html#virNWFilterLookupByName
+func (c *Connect) LookupNWFilterByName(name string) (*NWFilter, error) {
+ cName := C.CString(name)
+ defer C.free(unsafe.Pointer(cName))
+ var err C.virError
+ ptr := C.virNWFilterLookupByNameWrapper(c.ptr, cName, &err)
+ if ptr == nil {
+ return nil, makeError(&err)
+ }
+ return &NWFilter{ptr: ptr}, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-nwfilter.html#virNWFilterLookupByUUIDString
+func (c *Connect) LookupNWFilterByUUIDString(uuid string) (*NWFilter, error) {
+ cUuid := C.CString(uuid)
+ defer C.free(unsafe.Pointer(cUuid))
+ var err C.virError
+ ptr := C.virNWFilterLookupByUUIDStringWrapper(c.ptr, cUuid, &err)
+ if ptr == nil {
+ return nil, makeError(&err)
+ }
+ return &NWFilter{ptr: ptr}, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-nwfilter.html#virNWFilterLookupByUUID
+func (c *Connect) LookupNWFilterByUUID(uuid []byte) (*NWFilter, error) {
+ if len(uuid) != C.VIR_UUID_BUFLEN {
+ return nil, fmt.Errorf("UUID must be exactly %d bytes in size",
+ int(C.VIR_UUID_BUFLEN))
+ }
+ cUuid := make([]C.uchar, C.VIR_UUID_BUFLEN)
+ for i := 0; i < C.VIR_UUID_BUFLEN; i++ {
+ cUuid[i] = C.uchar(uuid[i])
+ }
+ var err C.virError
+ ptr := C.virNWFilterLookupByUUIDWrapper(c.ptr, &cUuid[0], &err)
+ if ptr == nil {
+ return nil, makeError(&err)
+ }
+ return &NWFilter{ptr: ptr}, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-nwfilter.html#virNWFilterBindingLookupByPortDev
+func (c *Connect) LookupNWFilterBindingByPortDev(name string) (*NWFilterBinding, error) {
+ if C.LIBVIR_VERSION_NUMBER < 4005000 {
+ return nil, makeNotImplementedError("virNWFilterBindingLookupByPortDev")
+ }
+ cName := C.CString(name)
+ defer C.free(unsafe.Pointer(cName))
+ var err C.virError
+ ptr := C.virNWFilterBindingLookupByPortDevWrapper(c.ptr, cName, &err)
+ if ptr == nil {
+ return nil, makeError(&err)
+ }
+ return &NWFilterBinding{ptr: ptr}, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolLookupByKey
+func (c *Connect) LookupStorageVolByKey(key string) (*StorageVol, error) {
+ cKey := C.CString(key)
+ defer C.free(unsafe.Pointer(cKey))
+ var err C.virError
+ ptr := C.virStorageVolLookupByKeyWrapper(c.ptr, cKey, &err)
+ if ptr == nil {
+ return nil, makeError(&err)
+ }
+ return &StorageVol{ptr: ptr}, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolLookupByPath
+func (c *Connect) LookupStorageVolByPath(path string) (*StorageVol, error) {
+ cPath := C.CString(path)
+ defer C.free(unsafe.Pointer(cPath))
+ var err C.virError
+ ptr := C.virStorageVolLookupByPathWrapper(c.ptr, cPath, &err)
+ if ptr == nil {
+ return nil, makeError(&err)
+ }
+ return &StorageVol{ptr: ptr}, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-secret.html#virSecretDefineXML
+func (c *Connect) SecretDefineXML(xmlConfig string, flags uint32) (*Secret, error) {
+ cXml := C.CString(string(xmlConfig))
+ defer C.free(unsafe.Pointer(cXml))
+ var err C.virError
+ ptr := C.virSecretDefineXMLWrapper(c.ptr, cXml, C.uint(flags), &err)
+ if ptr == nil {
+ return nil, makeError(&err)
+ }
+ return &Secret{ptr: ptr}, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-secret.html#virSecretLookupByUUID
+func (c *Connect) LookupSecretByUUID(uuid []byte) (*Secret, error) {
+ if len(uuid) != C.VIR_UUID_BUFLEN {
+ return nil, fmt.Errorf("UUID must be exactly %d bytes in size",
+ int(C.VIR_UUID_BUFLEN))
+ }
+ cUuid := make([]C.uchar, C.VIR_UUID_BUFLEN)
+ for i := 0; i < C.VIR_UUID_BUFLEN; i++ {
+ cUuid[i] = C.uchar(uuid[i])
+ }
+ var err C.virError
+ ptr := C.virSecretLookupByUUIDWrapper(c.ptr, &cUuid[0], &err)
+ if ptr == nil {
+ return nil, makeError(&err)
+ }
+ return &Secret{ptr: ptr}, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-secret.html#virSecretLookupByUUIDString
+func (c *Connect) LookupSecretByUUIDString(uuid string) (*Secret, error) {
+ cUuid := C.CString(uuid)
+ defer C.free(unsafe.Pointer(cUuid))
+ var err C.virError
+ ptr := C.virSecretLookupByUUIDStringWrapper(c.ptr, cUuid, &err)
+ if ptr == nil {
+ return nil, makeError(&err)
+ }
+ return &Secret{ptr: ptr}, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-secret.html#virSecretLookupByUsage
+func (c *Connect) LookupSecretByUsage(usageType SecretUsageType, usageID string) (*Secret, error) {
+ cUsageID := C.CString(usageID)
+ defer C.free(unsafe.Pointer(cUsageID))
+ var err C.virError
+ ptr := C.virSecretLookupByUsageWrapper(c.ptr, C.int(usageType), cUsageID, &err)
+ if ptr == nil {
+ return nil, makeError(&err)
+ }
+ return &Secret{ptr: ptr}, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceLookupByName
+func (c *Connect) LookupDeviceByName(id string) (*NodeDevice, error) {
+ cName := C.CString(id)
+ defer C.free(unsafe.Pointer(cName))
+ var err C.virError
+ ptr := C.virNodeDeviceLookupByNameWrapper(c.ptr, cName, &err)
+ if ptr == nil {
+ return nil, makeError(&err)
+ }
+ return &NodeDevice{ptr: ptr}, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceLookupSCSIHostByWWN
+func (c *Connect) LookupDeviceSCSIHostByWWN(wwnn, wwpn string, flags uint32) (*NodeDevice, error) {
+ cWwnn := C.CString(wwnn)
+ cWwpn := C.CString(wwpn)
+ defer C.free(unsafe.Pointer(cWwnn))
+ defer C.free(unsafe.Pointer(cWwpn))
+ var err C.virError
+ ptr := C.virNodeDeviceLookupSCSIHostByWWNWrapper(c.ptr, cWwnn, cWwpn, C.uint(flags), &err)
+ if ptr == nil {
+ return nil, makeError(&err)
+ }
+ return &NodeDevice{ptr: ptr}, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceCreateXML
+func (c *Connect) DeviceCreateXML(xmlConfig string, flags uint32) (*NodeDevice, error) {
+ cXml := C.CString(string(xmlConfig))
+ defer C.free(unsafe.Pointer(cXml))
+ var err C.virError
+ ptr := C.virNodeDeviceCreateXMLWrapper(c.ptr, cXml, C.uint(flags), &err)
+ if ptr == nil {
+ return nil, makeError(&err)
+ }
+ return &NodeDevice{ptr: ptr}, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-interface.html#virConnectListAllInterfaces
+func (c *Connect) ListAllInterfaces(flags ConnectListAllInterfacesFlags) ([]Interface, error) {
+ var cList *C.virInterfacePtr
+ var err C.virError
+ numIfaces := C.virConnectListAllInterfacesWrapper(c.ptr, (**C.virInterfacePtr)(&cList), C.uint(flags), &err)
+ if numIfaces == -1 {
+ return nil, makeError(&err)
+ }
+ hdr := reflect.SliceHeader{
+ Data: uintptr(unsafe.Pointer(cList)),
+ Len: int(numIfaces),
+ Cap: int(numIfaces),
+ }
+ var ifaces []Interface
+ slice := *(*[]C.virInterfacePtr)(unsafe.Pointer(&hdr))
+ for _, ptr := range slice {
+ ifaces = append(ifaces, Interface{ptr})
+ }
+ C.free(unsafe.Pointer(cList))
+ return ifaces, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-network.html#virConnectListAllNetworks
+func (c *Connect) ListAllNetworks(flags ConnectListAllNetworksFlags) ([]Network, error) {
+ var cList *C.virNetworkPtr
+ var err C.virError
+ numNets := C.virConnectListAllNetworksWrapper(c.ptr, (**C.virNetworkPtr)(&cList), C.uint(flags), &err)
+ if numNets == -1 {
+ return nil, makeError(&err)
+ }
+ hdr := reflect.SliceHeader{
+ Data: uintptr(unsafe.Pointer(cList)),
+ Len: int(numNets),
+ Cap: int(numNets),
+ }
+ var nets []Network
+ slice := *(*[]C.virNetworkPtr)(unsafe.Pointer(&hdr))
+ for _, ptr := range slice {
+ nets = append(nets, Network{ptr})
+ }
+ C.free(unsafe.Pointer(cList))
+ return nets, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virConnectListAllDomains
+func (c *Connect) ListAllDomains(flags ConnectListAllDomainsFlags) ([]Domain, error) {
+ var cList *C.virDomainPtr
+ var err C.virError
+ numDomains := C.virConnectListAllDomainsWrapper(c.ptr, (**C.virDomainPtr)(&cList), C.uint(flags), &err)
+ if numDomains == -1 {
+ return nil, makeError(&err)
+ }
+ hdr := reflect.SliceHeader{
+ Data: uintptr(unsafe.Pointer(cList)),
+ Len: int(numDomains),
+ Cap: int(numDomains),
+ }
+ var domains []Domain
+ slice := *(*[]C.virDomainPtr)(unsafe.Pointer(&hdr))
+ for _, ptr := range slice {
+ domains = append(domains, Domain{ptr})
+ }
+ C.free(unsafe.Pointer(cList))
+ return domains, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-nwfilter.html#virConnectListAllNWFilters
+func (c *Connect) ListAllNWFilters(flags uint32) ([]NWFilter, error) {
+ var cList *C.virNWFilterPtr
+ var err C.virError
+ numNWFilters := C.virConnectListAllNWFiltersWrapper(c.ptr, (**C.virNWFilterPtr)(&cList), C.uint(flags), &err)
+ if numNWFilters == -1 {
+ return nil, makeError(&err)
+ }
+ hdr := reflect.SliceHeader{
+ Data: uintptr(unsafe.Pointer(cList)),
+ Len: int(numNWFilters),
+ Cap: int(numNWFilters),
+ }
+ var filters []NWFilter
+ slice := *(*[]C.virNWFilterPtr)(unsafe.Pointer(&hdr))
+ for _, ptr := range slice {
+ filters = append(filters, NWFilter{ptr})
+ }
+ C.free(unsafe.Pointer(cList))
+ return filters, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-nwfilter.html#virConnectListAllNWFilterBindings
+func (c *Connect) ListAllNWFilterBindings(flags uint32) ([]NWFilterBinding, error) {
+ var cList *C.virNWFilterBindingPtr
+ if C.LIBVIR_VERSION_NUMBER < 4005000 {
+ return []NWFilterBinding{}, makeNotImplementedError("virConnectListAllNWFilterBindings")
+ }
+ var err C.virError
+ numNWFilters := C.virConnectListAllNWFilterBindingsWrapper(c.ptr, (**C.virNWFilterBindingPtr)(&cList), C.uint(flags), &err)
+ if numNWFilters == -1 {
+ return nil, makeError(&err)
+ }
+ hdr := reflect.SliceHeader{
+ Data: uintptr(unsafe.Pointer(cList)),
+ Len: int(numNWFilters),
+ Cap: int(numNWFilters),
+ }
+ var filters []NWFilterBinding
+ slice := *(*[]C.virNWFilterBindingPtr)(unsafe.Pointer(&hdr))
+ for _, ptr := range slice {
+ filters = append(filters, NWFilterBinding{ptr})
+ }
+ C.free(unsafe.Pointer(cList))
+ return filters, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-storage.html#virConnectListAllStoragePools
+func (c *Connect) ListAllStoragePools(flags ConnectListAllStoragePoolsFlags) ([]StoragePool, error) {
+ var cList *C.virStoragePoolPtr
+ var err C.virError
+ numPools := C.virConnectListAllStoragePoolsWrapper(c.ptr, (**C.virStoragePoolPtr)(&cList), C.uint(flags), &err)
+ if numPools == -1 {
+ return nil, makeError(&err)
+ }
+ hdr := reflect.SliceHeader{
+ Data: uintptr(unsafe.Pointer(cList)),
+ Len: int(numPools),
+ Cap: int(numPools),
+ }
+ var pools []StoragePool
+ slice := *(*[]C.virStoragePoolPtr)(unsafe.Pointer(&hdr))
+ for _, ptr := range slice {
+ pools = append(pools, StoragePool{ptr})
+ }
+ C.free(unsafe.Pointer(cList))
+ return pools, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-secret.html#virConnectListAllSecrets
+func (c *Connect) ListAllSecrets(flags ConnectListAllSecretsFlags) ([]Secret, error) {
+ var cList *C.virSecretPtr
+ var err C.virError
+ numPools := C.virConnectListAllSecretsWrapper(c.ptr, (**C.virSecretPtr)(&cList), C.uint(flags), &err)
+ if numPools == -1 {
+ return nil, makeError(&err)
+ }
+ hdr := reflect.SliceHeader{
+ Data: uintptr(unsafe.Pointer(cList)),
+ Len: int(numPools),
+ Cap: int(numPools),
+ }
+ var pools []Secret
+ slice := *(*[]C.virSecretPtr)(unsafe.Pointer(&hdr))
+ for _, ptr := range slice {
+ pools = append(pools, Secret{ptr})
+ }
+ C.free(unsafe.Pointer(cList))
+ return pools, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-nodedev.html#virConnectListAllNodeDevices
+func (c *Connect) ListAllNodeDevices(flags ConnectListAllNodeDeviceFlags) ([]NodeDevice, error) {
+ var cList *C.virNodeDevicePtr
+ var err C.virError
+ numPools := C.virConnectListAllNodeDevicesWrapper(c.ptr, (**C.virNodeDevicePtr)(&cList), C.uint(flags), &err)
+ if numPools == -1 {
+ return nil, makeError(&err)
+ }
+ hdr := reflect.SliceHeader{
+ Data: uintptr(unsafe.Pointer(cList)),
+ Len: int(numPools),
+ Cap: int(numPools),
+ }
+ var pools []NodeDevice
+ slice := *(*[]C.virNodeDevicePtr)(unsafe.Pointer(&hdr))
+ for _, ptr := range slice {
+ pools = append(pools, NodeDevice{ptr})
+ }
+ C.free(unsafe.Pointer(cList))
+ return pools, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceChangeBegin
+func (c *Connect) InterfaceChangeBegin(flags uint32) error {
+ var err C.virError
+ ret := C.virInterfaceChangeBeginWrapper(c.ptr, C.uint(flags), &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceChangeCommit
+func (c *Connect) InterfaceChangeCommit(flags uint32) error {
+ var err C.virError
+ ret := C.virInterfaceChangeCommitWrapper(c.ptr, C.uint(flags), &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceChangeRollback
+func (c *Connect) InterfaceChangeRollback(flags uint32) error {
+ var err C.virError
+ ret := C.virInterfaceChangeRollbackWrapper(c.ptr, C.uint(flags), &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-host.html#virNodeAllocPages
+func (c *Connect) AllocPages(pageSizes map[int]int64, startCell int, cellCount uint, flags NodeAllocPagesFlags) (int, error) {
+ if C.LIBVIR_VERSION_NUMBER < 1002009 {
+ return 0, makeNotImplementedError("virNodeAllocPages")
+ }
+ cpages := make([]C.uint, len(pageSizes))
+ ccounts := make([]C.ulonglong, len(pageSizes))
+
+ i := 0
+ for key, val := range pageSizes {
+ cpages[i] = C.uint(key)
+ ccounts[i] = C.ulonglong(val)
+ i++
+ }
+
+ var err C.virError
+ ret := C.virNodeAllocPagesWrapper(c.ptr, C.uint(len(pageSizes)), (*C.uint)(unsafe.Pointer(&cpages)),
+ (*C.ulonglong)(unsafe.Pointer(&ccounts)), C.int(startCell), C.uint(cellCount), C.uint(flags), &err)
+ if ret == -1 {
+ return 0, makeError(&err)
+ }
+
+ return int(ret), nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-host.html#virNodeGetCPUMap
+func (c *Connect) GetCPUMap(flags uint32) (map[int]bool, uint, error) {
+ var ccpumap *C.uchar
+ var conline C.uint
+ var err C.virError
+ ret := C.virNodeGetCPUMapWrapper(c.ptr, &ccpumap, &conline, C.uint(flags), &err)
+ if ret == -1 {
+ return map[int]bool{}, 0, makeError(&err)
+ }
+ defer C.free(unsafe.Pointer(ccpumap))
+
+ cpumapbytes := C.GoBytes(unsafe.Pointer(ccpumap), C.int(ret/8))
+
+ cpumap := make(map[int]bool, 0)
+ for i := 0; i < int(ret); i++ {
+ idx := int(i / 8)
+ val := byte(cpumapbytes[idx])
+ shift := i % 8
+ cpumap[i] = (val & (1 << uint(shift))) == 1
+ }
+
+ return cpumap, uint(conline), nil
+}
+
+type NodeCPUStats struct {
+ KernelSet bool
+ Kernel uint64
+ UserSet bool
+ User uint64
+ IdleSet bool
+ Idle uint64
+ IowaitSet bool
+ Iowait uint64
+ IntrSet bool
+ Intr uint64
+ UtilizationSet bool
+ Utilization uint64
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-host.html#virNodeGetCPUStats
+func (c *Connect) GetCPUStats(cpuNum int, flags uint32) (*NodeCPUStats, error) {
+ var nparams C.int
+
+ var err C.virError
+ ret := C.virNodeGetCPUStatsWrapper(c.ptr, C.int(cpuNum), nil, &nparams, C.uint(0), &err)
+ if ret == -1 {
+ return nil, makeError(&err)
+ }
+
+ params := make([]C.virNodeCPUStats, nparams)
+ ret = C.virNodeGetCPUStatsWrapper(c.ptr, C.int(cpuNum), (*C.virNodeCPUStats)(unsafe.Pointer(&params[0])), &nparams, C.uint(flags), &err)
+ if ret == -1 {
+ return nil, makeError(&err)
+ }
+
+ stats := &NodeCPUStats{}
+ for i := 0; i < int(nparams); i++ {
+ param := params[i]
+ field := C.GoString((*C.char)(unsafe.Pointer(&param.field)))
+ switch field {
+ case C.VIR_NODE_CPU_STATS_KERNEL:
+ stats.KernelSet = true
+ stats.Kernel = uint64(param.value)
+ case C.VIR_NODE_CPU_STATS_USER:
+ stats.UserSet = true
+ stats.User = uint64(param.value)
+ case C.VIR_NODE_CPU_STATS_IDLE:
+ stats.IdleSet = true
+ stats.Idle = uint64(param.value)
+ case C.VIR_NODE_CPU_STATS_IOWAIT:
+ stats.IowaitSet = true
+ stats.Iowait = uint64(param.value)
+ case C.VIR_NODE_CPU_STATS_INTR:
+ stats.IntrSet = true
+ stats.Intr = uint64(param.value)
+ case C.VIR_NODE_CPU_STATS_UTILIZATION:
+ stats.UtilizationSet = true
+ stats.Utilization = uint64(param.value)
+ }
+ }
+
+ return stats, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-host.html#virNodeGetCellsFreeMemory
+func (c *Connect) GetCellsFreeMemory(startCell int, maxCells int) ([]uint64, error) {
+ cmem := make([]C.ulonglong, maxCells)
+ var err C.virError
+ ret := C.virNodeGetCellsFreeMemoryWrapper(c.ptr, (*C.ulonglong)(unsafe.Pointer(&cmem[0])), C.int(startCell), C.int(maxCells), &err)
+ if ret == -1 {
+ return []uint64{}, makeError(&err)
+ }
+
+ mem := make([]uint64, ret)
+ for i := 0; i < int(ret); i++ {
+ mem[i] = uint64(cmem[i])
+ }
+
+ return mem, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-host.html#virNodeGetFreeMemory
+func (c *Connect) GetFreeMemory() (uint64, error) {
+ var err C.virError
+ ret := C.virNodeGetFreeMemoryWrapper(c.ptr, &err)
+ if ret == 0 {
+ return 0, makeError(&err)
+ }
+
+ return (uint64)(ret), nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-host.html#virNodeGetFreePages
+func (c *Connect) GetFreePages(pageSizes []uint64, startCell int, maxCells uint, flags uint32) ([]uint64, error) {
+ if C.LIBVIR_VERSION_NUMBER < 1002006 {
+ return []uint64{}, makeNotImplementedError("virNodeGetFreePages")
+ }
+ cpageSizes := make([]C.uint, len(pageSizes))
+ ccounts := make([]C.ulonglong, len(pageSizes)*int(maxCells))
+
+ for i := 0; i < len(pageSizes); i++ {
+ cpageSizes[i] = C.uint(pageSizes[i])
+ }
+
+ var err C.virError
+ ret := C.virNodeGetFreePagesWrapper(c.ptr, C.uint(len(pageSizes)), (*C.uint)(unsafe.Pointer(&cpageSizes)), C.int(startCell),
+ C.uint(maxCells), (*C.ulonglong)(unsafe.Pointer(&ccounts)), C.uint(flags), &err)
+ if ret == -1 {
+ return []uint64{}, makeError(&err)
+ }
+
+ counts := make([]uint64, ret)
+ for i := 0; i < int(ret); i++ {
+ counts[i] = uint64(ccounts[i])
+ }
+
+ return counts, nil
+}
+
+type NodeMemoryParameters struct {
+ ShmPagesToScanSet bool
+ ShmPagesToScan uint
+ ShmSleepMillisecsSet bool
+ ShmSleepMillisecs uint
+ ShmPagesSharedSet bool
+ ShmPagesShared uint64
+ ShmPagesSharingSet bool
+ ShmPagesSharing uint64
+ ShmPagesUnsharedSet bool
+ ShmPagesUnshared uint64
+ ShmPagesVolatileSet bool
+ ShmPagesVolatile uint64
+ ShmFullScansSet bool
+ ShmFullScans uint64
+ ShmMergeAcrossNodesSet bool
+ ShmMergeAcrossNodes uint
+}
+
+func getMemoryParameterFieldInfo(params *NodeMemoryParameters) map[string]typedParamsFieldInfo {
+ return map[string]typedParamsFieldInfo{
+ C.VIR_NODE_MEMORY_SHARED_PAGES_TO_SCAN: typedParamsFieldInfo{
+ set: &params.ShmPagesToScanSet,
+ ui: &params.ShmPagesToScan,
+ },
+ C.VIR_NODE_MEMORY_SHARED_SLEEP_MILLISECS: typedParamsFieldInfo{
+ set: &params.ShmSleepMillisecsSet,
+ ui: &params.ShmSleepMillisecs,
+ },
+ C.VIR_NODE_MEMORY_SHARED_MERGE_ACROSS_NODES: typedParamsFieldInfo{
+ set: &params.ShmMergeAcrossNodesSet,
+ ui: &params.ShmMergeAcrossNodes,
+ },
+ C.VIR_NODE_MEMORY_SHARED_PAGES_SHARED: typedParamsFieldInfo{
+ set: &params.ShmPagesSharedSet,
+ ul: &params.ShmPagesShared,
+ },
+ C.VIR_NODE_MEMORY_SHARED_PAGES_SHARING: typedParamsFieldInfo{
+ set: &params.ShmPagesSharingSet,
+ ul: &params.ShmPagesSharing,
+ },
+ C.VIR_NODE_MEMORY_SHARED_PAGES_UNSHARED: typedParamsFieldInfo{
+ set: &params.ShmPagesUnsharedSet,
+ ul: &params.ShmPagesUnshared,
+ },
+ C.VIR_NODE_MEMORY_SHARED_PAGES_VOLATILE: typedParamsFieldInfo{
+ set: &params.ShmPagesVolatileSet,
+ ul: &params.ShmPagesVolatile,
+ },
+ C.VIR_NODE_MEMORY_SHARED_FULL_SCANS: typedParamsFieldInfo{
+ set: &params.ShmFullScansSet,
+ ul: &params.ShmFullScans,
+ },
+ }
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-host.html#virNodeGetMemoryParameters
+func (c *Connect) GetMemoryParameters(flags uint32) (*NodeMemoryParameters, error) {
+ params := &NodeMemoryParameters{}
+ info := getMemoryParameterFieldInfo(params)
+
+ var nparams C.int
+
+ var err C.virError
+ ret := C.virNodeGetMemoryParametersWrapper(c.ptr, nil, &nparams, C.uint(0), &err)
+ if ret == -1 {
+ return nil, makeError(&err)
+ }
+
+ cparams := make([]C.virTypedParameter, nparams)
+ ret = C.virNodeGetMemoryParametersWrapper(c.ptr, (*C.virTypedParameter)(unsafe.Pointer(&cparams[0])), &nparams, C.uint(flags), &err)
+ if ret == -1 {
+ return nil, makeError(&err)
+ }
+
+ defer C.virTypedParamsClear((*C.virTypedParameter)(unsafe.Pointer(&cparams[0])), nparams)
+
+ _, gerr := typedParamsUnpack(cparams, info)
+ if gerr != nil {
+ return nil, gerr
+ }
+
+ return params, nil
+}
+
+type NodeMemoryStats struct {
+ TotalSet bool
+ Total uint64
+ FreeSet bool
+ Free uint64
+ BuffersSet bool
+ Buffers uint64
+ CachedSet bool
+ Cached uint64
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-host.html#virNodeGetMemoryStats
+func (c *Connect) GetMemoryStats(cellNum int, flags uint32) (*NodeMemoryStats, error) {
+ var nparams C.int
+
+ var err C.virError
+ ret := C.virNodeGetMemoryStatsWrapper(c.ptr, C.int(cellNum), nil, &nparams, 0, &err)
+ if ret == -1 {
+ return nil, makeError(&err)
+ }
+
+ params := make([]C.virNodeMemoryStats, nparams)
+ ret = C.virNodeGetMemoryStatsWrapper(c.ptr, C.int(cellNum), (*C.virNodeMemoryStats)(unsafe.Pointer(&params[0])), &nparams, C.uint(flags), &err)
+ if ret == -1 {
+ return nil, makeError(&err)
+ }
+
+ stats := &NodeMemoryStats{}
+ for i := 0; i < int(nparams); i++ {
+ param := params[i]
+ field := C.GoString((*C.char)(unsafe.Pointer(&param.field)))
+ switch field {
+ case C.VIR_NODE_MEMORY_STATS_TOTAL:
+ stats.TotalSet = true
+ stats.Total = uint64(param.value)
+ case C.VIR_NODE_MEMORY_STATS_FREE:
+ stats.FreeSet = true
+ stats.Free = uint64(param.value)
+ case C.VIR_NODE_MEMORY_STATS_BUFFERS:
+ stats.BuffersSet = true
+ stats.Buffers = uint64(param.value)
+ case C.VIR_NODE_MEMORY_STATS_CACHED:
+ stats.CachedSet = true
+ stats.Cached = uint64(param.value)
+ }
+ }
+
+ return stats, nil
+}
+
+type NodeSecurityModel struct {
+ Model string
+ Doi string
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-host.html#virNodeGetSecurityModel
+func (c *Connect) GetSecurityModel() (*NodeSecurityModel, error) {
+ var cmodel C.virSecurityModel
+ var err C.virError
+ ret := C.virNodeGetSecurityModelWrapper(c.ptr, &cmodel, &err)
+ if ret == -1 {
+ return nil, makeError(&err)
+ }
+
+ return &NodeSecurityModel{
+ Model: C.GoString((*C.char)(unsafe.Pointer(&cmodel.model))),
+ Doi: C.GoString((*C.char)(unsafe.Pointer(&cmodel.doi))),
+ }, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-host.html#virNodeSetMemoryParameters
+func (c *Connect) SetMemoryParameters(params *NodeMemoryParameters, flags uint32) error {
+ info := getMemoryParameterFieldInfo(params)
+
+ var nparams C.int
+
+ var err C.virError
+ ret := C.virNodeGetMemoryParametersWrapper(c.ptr, nil, &nparams, 0, &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+
+ cparams := make([]C.virTypedParameter, nparams)
+ ret = C.virNodeGetMemoryParametersWrapper(c.ptr, (*C.virTypedParameter)(unsafe.Pointer(&cparams[0])), &nparams, 0, &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+
+ defer C.virTypedParamsClear((*C.virTypedParameter)(unsafe.Pointer(&cparams[0])), nparams)
+
+ gerr := typedParamsPack(cparams, info)
+ if gerr != nil {
+ return gerr
+ }
+
+ ret = C.virNodeSetMemoryParametersWrapper(c.ptr, (*C.virTypedParameter)(unsafe.Pointer(&cparams[0])), nparams, C.uint(flags), &err)
+
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-host.html#virNodeSuspendForDuration
+func (c *Connect) SuspendForDuration(target NodeSuspendTarget, duration uint64, flags uint32) error {
+ var err C.virError
+ ret := C.virNodeSuspendForDurationWrapper(c.ptr, C.uint(target), C.ulonglong(duration), C.uint(flags), &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSaveImageDefineXML
+func (c *Connect) DomainSaveImageDefineXML(file string, xml string, flags DomainSaveRestoreFlags) error {
+ cfile := C.CString(file)
+ defer C.free(unsafe.Pointer(cfile))
+ cxml := C.CString(xml)
+ defer C.free(unsafe.Pointer(cxml))
+
+ var err C.virError
+ ret := C.virDomainSaveImageDefineXMLWrapper(c.ptr, cfile, cxml, C.uint(flags), &err)
+
+ if ret == -1 {
+ return makeError(&err)
+ }
+
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSaveImageGetXMLDesc
+func (c *Connect) DomainSaveImageGetXMLDesc(file string, flags DomainXMLFlags) (string, error) {
+ cfile := C.CString(file)
+ defer C.free(unsafe.Pointer(cfile))
+
+ var err C.virError
+ ret := C.virDomainSaveImageGetXMLDescWrapper(c.ptr, cfile, C.uint(flags), &err)
+
+ if ret == nil {
+ return "", makeError(&err)
+ }
+
+ defer C.free(unsafe.Pointer(ret))
+
+ return C.GoString(ret), nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-host.html#virConnectBaselineCPU
+func (c *Connect) BaselineCPU(xmlCPUs []string, flags ConnectBaselineCPUFlags) (string, error) {
+ cxmlCPUs := make([]*C.char, len(xmlCPUs))
+ for i := 0; i < len(xmlCPUs); i++ {
+ cxmlCPUs[i] = C.CString(xmlCPUs[i])
+ defer C.free(unsafe.Pointer(cxmlCPUs[i]))
+ }
+
+ var err C.virError
+ ret := C.virConnectBaselineCPUWrapper(c.ptr, &cxmlCPUs[0], C.uint(len(xmlCPUs)), C.uint(flags), &err)
+ if ret == nil {
+ return "", makeError(&err)
+ }
+
+ defer C.free(unsafe.Pointer(ret))
+
+ return C.GoString(ret), nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-host.html#virConnectBaselineHypervisorCPU
+func (c *Connect) BaselineHypervisorCPU(emulator string, arch string, machine string, virttype string, xmlCPUs []string, flags ConnectBaselineCPUFlags) (string, error) {
+ if C.LIBVIR_VERSION_NUMBER < 4004000 {
+ return "", makeNotImplementedError("virConnectBaselineHypervisorCPU")
+ }
+
+ var cemulator, carch, cmachine, cvirttype *C.char
+ if emulator != "" {
+ cemulator = C.CString(emulator)
+ defer C.free(unsafe.Pointer(cemulator))
+ }
+ if arch != "" {
+ carch = C.CString(arch)
+ defer C.free(unsafe.Pointer(carch))
+ }
+ if machine != "" {
+ cmachine = C.CString(machine)
+ defer C.free(unsafe.Pointer(cmachine))
+ }
+ if virttype != "" {
+ cvirttype = C.CString(virttype)
+ defer C.free(unsafe.Pointer(cvirttype))
+ }
+ cxmlCPUs := make([]*C.char, len(xmlCPUs))
+ for i := 0; i < len(xmlCPUs); i++ {
+ cxmlCPUs[i] = C.CString(xmlCPUs[i])
+ defer C.free(unsafe.Pointer(cxmlCPUs[i]))
+ }
+
+ var err C.virError
+ ret := C.virConnectBaselineHypervisorCPUWrapper(c.ptr, cemulator, carch, cmachine, cvirttype,
+ &cxmlCPUs[0], C.uint(len(xmlCPUs)), C.uint(flags), &err)
+ if ret == nil {
+ return "", makeError(&err)
+ }
+
+ defer C.free(unsafe.Pointer(ret))
+
+ return C.GoString(ret), nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-host.html#virConnectCompareCPU
+func (c *Connect) CompareCPU(xmlDesc string, flags ConnectCompareCPUFlags) (CPUCompareResult, error) {
+ cxmlDesc := C.CString(xmlDesc)
+ defer C.free(unsafe.Pointer(cxmlDesc))
+
+ var err C.virError
+ ret := C.virConnectCompareCPUWrapper(c.ptr, cxmlDesc, C.uint(flags), &err)
+ if ret == C.VIR_CPU_COMPARE_ERROR {
+ return CPU_COMPARE_ERROR, makeError(&err)
+ }
+
+ return CPUCompareResult(ret), nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-host.html#virConnectCompareHypervisorCPU
+func (c *Connect) CompareHypervisorCPU(emulator string, arch string, machine string, virttype string, xmlDesc string, flags ConnectCompareCPUFlags) (CPUCompareResult, error) {
+ if C.LIBVIR_VERSION_NUMBER < 4004000 {
+ return CPU_COMPARE_ERROR, makeNotImplementedError("virConnectCompareHypervisorCPU")
+ }
+
+ var cemulator, carch, cmachine, cvirttype *C.char
+ if emulator != "" {
+ cemulator = C.CString(emulator)
+ defer C.free(unsafe.Pointer(cemulator))
+ }
+ if arch != "" {
+ carch = C.CString(arch)
+ defer C.free(unsafe.Pointer(carch))
+ }
+ if machine != "" {
+ cmachine = C.CString(machine)
+ defer C.free(unsafe.Pointer(cmachine))
+ }
+ if virttype != "" {
+ cvirttype = C.CString(virttype)
+ defer C.free(unsafe.Pointer(cvirttype))
+ }
+
+ cxmlDesc := C.CString(xmlDesc)
+ defer C.free(unsafe.Pointer(cxmlDesc))
+
+ var err C.virError
+ ret := C.virConnectCompareHypervisorCPUWrapper(c.ptr, cemulator, carch, cmachine, cvirttype, cxmlDesc, C.uint(flags), &err)
+ if ret == C.VIR_CPU_COMPARE_ERROR {
+ return CPU_COMPARE_ERROR, makeError(&err)
+ }
+
+ return CPUCompareResult(ret), nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virConnectDomainXMLFromNative
+func (c *Connect) DomainXMLFromNative(nativeFormat string, nativeConfig string, flags uint32) (string, error) {
+ cnativeFormat := C.CString(nativeFormat)
+ defer C.free(unsafe.Pointer(cnativeFormat))
+ cnativeConfig := C.CString(nativeConfig)
+ defer C.free(unsafe.Pointer(cnativeConfig))
+
+ var err C.virError
+ ret := C.virConnectDomainXMLFromNativeWrapper(c.ptr, cnativeFormat, cnativeConfig, C.uint(flags), &err)
+ if ret == nil {
+ return "", makeError(&err)
+ }
+
+ defer C.free(unsafe.Pointer(ret))
+
+ return C.GoString(ret), nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virConnectDomainXMLToNative
+func (c *Connect) DomainXMLToNative(nativeFormat string, domainXml string, flags uint32) (string, error) {
+ cnativeFormat := C.CString(nativeFormat)
+ defer C.free(unsafe.Pointer(cnativeFormat))
+ cdomainXml := C.CString(domainXml)
+ defer C.free(unsafe.Pointer(cdomainXml))
+
+ var err C.virError
+ ret := C.virConnectDomainXMLToNativeWrapper(c.ptr, cnativeFormat, cdomainXml, C.uint(flags), &err)
+ if ret == nil {
+ return "", makeError(&err)
+ }
+
+ defer C.free(unsafe.Pointer(ret))
+
+ return C.GoString(ret), nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-host.html#virConnectGetCPUModelNames
+func (c *Connect) GetCPUModelNames(arch string, flags uint32) ([]string, error) {
+ carch := C.CString(arch)
+ defer C.free(unsafe.Pointer(carch))
+
+ var cmodels **C.char
+ var err C.virError
+ ret := C.virConnectGetCPUModelNamesWrapper(c.ptr, carch, &cmodels, C.uint(flags), &err)
+ if ret == -1 {
+ return []string{}, makeError(&err)
+ }
+
+ models := make([]string, int(ret))
+ for i := 0; i < int(ret); i++ {
+ cmodel := *(**C.char)(unsafe.Pointer(uintptr(unsafe.Pointer(cmodels)) + (unsafe.Sizeof(*cmodels) * uintptr(i))))
+
+ defer C.free(unsafe.Pointer(cmodel))
+ models[i] = C.GoString(cmodel)
+ }
+ defer C.free(unsafe.Pointer(cmodels))
+
+ return models, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virConnectGetDomainCapabilities
+func (c *Connect) GetDomainCapabilities(emulatorbin string, arch string, machine string, virttype string, flags uint32) (string, error) {
+ if C.LIBVIR_VERSION_NUMBER < 1002007 {
+ return "", makeNotImplementedError("virConnectGetDomainCapabilities")
+ }
+ var cemulatorbin *C.char
+ if emulatorbin != "" {
+ cemulatorbin = C.CString(emulatorbin)
+ defer C.free(unsafe.Pointer(cemulatorbin))
+ }
+ var carch *C.char
+ if arch != "" {
+ carch = C.CString(arch)
+ defer C.free(unsafe.Pointer(carch))
+ }
+ var cmachine *C.char
+ if machine != "" {
+ cmachine = C.CString(machine)
+ defer C.free(unsafe.Pointer(cmachine))
+ }
+ var cvirttype *C.char
+ if virttype != "" {
+ cvirttype = C.CString(virttype)
+ defer C.free(unsafe.Pointer(cvirttype))
+ }
+
+ var err C.virError
+ ret := C.virConnectGetDomainCapabilitiesWrapper(c.ptr, cemulatorbin, carch, cmachine, cvirttype, C.uint(flags), &err)
+ if ret == nil {
+ return "", makeError(&err)
+ }
+
+ defer C.free(unsafe.Pointer(ret))
+
+ return C.GoString(ret), nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-host.html#virConnectGetVersion
+func (c *Connect) GetVersion() (uint32, error) {
+ var hvVer C.ulong
+ var err C.virError
+ ret := C.virConnectGetVersionWrapper(c.ptr, &hvVer, &err)
+ if ret == -1 {
+ return 0, makeError(&err)
+ }
+
+ return uint32(hvVer), nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-storage.html#virConnectFindStoragePoolSources
+func (c *Connect) FindStoragePoolSources(pooltype string, srcSpec string, flags uint32) (string, error) {
+ cpooltype := C.CString(pooltype)
+ defer C.free(unsafe.Pointer(cpooltype))
+ var csrcSpec *C.char
+ if srcSpec != "" {
+ csrcSpec := C.CString(srcSpec)
+ defer C.free(unsafe.Pointer(csrcSpec))
+ }
+ var err C.virError
+ ret := C.virConnectFindStoragePoolSourcesWrapper(c.ptr, cpooltype, csrcSpec, C.uint(flags), &err)
+ if ret == nil {
+ return "", makeError(&err)
+ }
+
+ defer C.free(unsafe.Pointer(ret))
+
+ return C.GoString(ret), nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainRestore
+func (c *Connect) DomainRestore(srcFile string) error {
+ cPath := C.CString(srcFile)
+ defer C.free(unsafe.Pointer(cPath))
+ var err C.virError
+ if result := C.virDomainRestoreWrapper(c.ptr, cPath, &err); result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainRestoreFlags
+func (c *Connect) DomainRestoreFlags(srcFile, xmlConf string, flags DomainSaveRestoreFlags) error {
+ cPath := C.CString(srcFile)
+ defer C.free(unsafe.Pointer(cPath))
+ var cXmlConf *C.char
+ if xmlConf != "" {
+ cXmlConf = C.CString(xmlConf)
+ defer C.free(unsafe.Pointer(cXmlConf))
+ }
+ var err C.virError
+ if result := C.virDomainRestoreFlagsWrapper(c.ptr, cPath, cXmlConf, C.uint(flags), &err); result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-stream.html#virStreamNew
+func (c *Connect) NewStream(flags StreamFlags) (*Stream, error) {
+ var err C.virError
+ virStream := C.virStreamNewWrapper(c.ptr, C.uint(flags), &err)
+ if virStream == nil {
+ return nil, makeError(&err)
+ }
+
+ return &Stream{
+ ptr: virStream,
+ }, nil
+}
+
+type DomainStatsState struct {
+ StateSet bool
+ State DomainState
+ ReasonSet bool
+ Reason int
+}
+
+func getDomainStatsStateFieldInfo(params *DomainStatsState) map[string]typedParamsFieldInfo {
+ return map[string]typedParamsFieldInfo{
+ "state.state": typedParamsFieldInfo{
+ set: &params.StateSet,
+ i: (*int)(unsafe.Pointer(&params.State)),
+ },
+ "state.reason": typedParamsFieldInfo{
+ set: &params.ReasonSet,
+ i: &params.Reason,
+ },
+ }
+}
+
+type DomainStatsCPU struct {
+ TimeSet bool
+ Time uint64
+ UserSet bool
+ User uint64
+ SystemSet bool
+ System uint64
+}
+
+func getDomainStatsCPUFieldInfo(params *DomainStatsCPU) map[string]typedParamsFieldInfo {
+ return map[string]typedParamsFieldInfo{
+ "cpu.time": typedParamsFieldInfo{
+ set: &params.TimeSet,
+ ul: &params.Time,
+ },
+ "cpu.user": typedParamsFieldInfo{
+ set: &params.UserSet,
+ ul: &params.User,
+ },
+ "cpu.system": typedParamsFieldInfo{
+ set: &params.SystemSet,
+ ul: &params.System,
+ },
+ }
+}
+
+type DomainStatsBalloon struct {
+ CurrentSet bool
+ Current uint64
+ MaximumSet bool
+ Maximum uint64
+}
+
+func getDomainStatsBalloonFieldInfo(params *DomainStatsBalloon) map[string]typedParamsFieldInfo {
+ return map[string]typedParamsFieldInfo{
+ "balloon.current": typedParamsFieldInfo{
+ set: &params.CurrentSet,
+ ul: &params.Current,
+ },
+ "balloon.maximum": typedParamsFieldInfo{
+ set: &params.MaximumSet,
+ ul: &params.Maximum,
+ },
+ }
+}
+
+type DomainStatsVcpu struct {
+ StateSet bool
+ State VcpuState
+ TimeSet bool
+ Time uint64
+}
+
+func getDomainStatsVcpuFieldInfo(idx int, params *DomainStatsVcpu) map[string]typedParamsFieldInfo {
+ return map[string]typedParamsFieldInfo{
+ fmt.Sprintf("vcpu.%d.state", idx): typedParamsFieldInfo{
+ set: &params.StateSet,
+ i: (*int)(unsafe.Pointer(&params.State)),
+ },
+ fmt.Sprintf("vcpu.%d.time", idx): typedParamsFieldInfo{
+ set: &params.TimeSet,
+ ul: &params.Time,
+ },
+ }
+}
+
+type DomainStatsNet struct {
+ NameSet bool
+ Name string
+ RxBytesSet bool
+ RxBytes uint64
+ RxPktsSet bool
+ RxPkts uint64
+ RxErrsSet bool
+ RxErrs uint64
+ RxDropSet bool
+ RxDrop uint64
+ TxBytesSet bool
+ TxBytes uint64
+ TxPktsSet bool
+ TxPkts uint64
+ TxErrsSet bool
+ TxErrs uint64
+ TxDropSet bool
+ TxDrop uint64
+}
+
+func getDomainStatsNetFieldInfo(idx int, params *DomainStatsNet) map[string]typedParamsFieldInfo {
+ return map[string]typedParamsFieldInfo{
+ fmt.Sprintf("net.%d.name", idx): typedParamsFieldInfo{
+ set: &params.NameSet,
+ s: &params.Name,
+ },
+ fmt.Sprintf("net.%d.rx.bytes", idx): typedParamsFieldInfo{
+ set: &params.RxBytesSet,
+ ul: &params.RxBytes,
+ },
+ fmt.Sprintf("net.%d.rx.pkts", idx): typedParamsFieldInfo{
+ set: &params.RxPktsSet,
+ ul: &params.RxPkts,
+ },
+ fmt.Sprintf("net.%d.rx.errs", idx): typedParamsFieldInfo{
+ set: &params.RxErrsSet,
+ ul: &params.RxErrs,
+ },
+ fmt.Sprintf("net.%d.rx.drop", idx): typedParamsFieldInfo{
+ set: &params.RxDropSet,
+ ul: &params.RxDrop,
+ },
+ fmt.Sprintf("net.%d.tx.bytes", idx): typedParamsFieldInfo{
+ set: &params.TxBytesSet,
+ ul: &params.TxBytes,
+ },
+ fmt.Sprintf("net.%d.tx.pkts", idx): typedParamsFieldInfo{
+ set: &params.TxPktsSet,
+ ul: &params.TxPkts,
+ },
+ fmt.Sprintf("net.%d.tx.errs", idx): typedParamsFieldInfo{
+ set: &params.TxErrsSet,
+ ul: &params.TxErrs,
+ },
+ fmt.Sprintf("net.%d.tx.drop", idx): typedParamsFieldInfo{
+ set: &params.TxDropSet,
+ ul: &params.TxDrop,
+ },
+ }
+}
+
+type DomainStatsBlock struct {
+ NameSet bool
+ Name string
+ BackingIndexSet bool
+ BackingIndex uint
+ PathSet bool
+ Path string
+ RdReqsSet bool
+ RdReqs uint64
+ RdBytesSet bool
+ RdBytes uint64
+ RdTimesSet bool
+ RdTimes uint64
+ WrReqsSet bool
+ WrReqs uint64
+ WrBytesSet bool
+ WrBytes uint64
+ WrTimesSet bool
+ WrTimes uint64
+ FlReqsSet bool
+ FlReqs uint64
+ FlTimesSet bool
+ FlTimes uint64
+ ErrorsSet bool
+ Errors uint64
+ AllocationSet bool
+ Allocation uint64
+ CapacitySet bool
+ Capacity uint64
+ PhysicalSet bool
+ Physical uint64
+}
+
+func getDomainStatsBlockFieldInfo(idx int, params *DomainStatsBlock) map[string]typedParamsFieldInfo {
+ return map[string]typedParamsFieldInfo{
+ fmt.Sprintf("block.%d.name", idx): typedParamsFieldInfo{
+ set: &params.NameSet,
+ s: &params.Name,
+ },
+ fmt.Sprintf("block.%d.backingIndex", idx): typedParamsFieldInfo{
+ set: &params.BackingIndexSet,
+ ui: &params.BackingIndex,
+ },
+ fmt.Sprintf("block.%d.path", idx): typedParamsFieldInfo{
+ set: &params.PathSet,
+ s: &params.Path,
+ },
+ fmt.Sprintf("block.%d.rd.reqs", idx): typedParamsFieldInfo{
+ set: &params.RdReqsSet,
+ ul: &params.RdReqs,
+ },
+ fmt.Sprintf("block.%d.rd.bytes", idx): typedParamsFieldInfo{
+ set: &params.RdBytesSet,
+ ul: &params.RdBytes,
+ },
+ fmt.Sprintf("block.%d.rd.times", idx): typedParamsFieldInfo{
+ set: &params.RdTimesSet,
+ ul: &params.RdTimes,
+ },
+ fmt.Sprintf("block.%d.wr.reqs", idx): typedParamsFieldInfo{
+ set: &params.WrReqsSet,
+ ul: &params.WrReqs,
+ },
+ fmt.Sprintf("block.%d.wr.bytes", idx): typedParamsFieldInfo{
+ set: &params.WrBytesSet,
+ ul: &params.WrBytes,
+ },
+ fmt.Sprintf("block.%d.wr.times", idx): typedParamsFieldInfo{
+ set: &params.WrTimesSet,
+ ul: &params.WrTimes,
+ },
+ fmt.Sprintf("block.%d.fl.reqs", idx): typedParamsFieldInfo{
+ set: &params.FlReqsSet,
+ ul: &params.FlReqs,
+ },
+ fmt.Sprintf("block.%d.fl.times", idx): typedParamsFieldInfo{
+ set: &params.FlTimesSet,
+ ul: &params.FlTimes,
+ },
+ fmt.Sprintf("block.%d.errors", idx): typedParamsFieldInfo{
+ set: &params.ErrorsSet,
+ ul: &params.Errors,
+ },
+ fmt.Sprintf("block.%d.allocation", idx): typedParamsFieldInfo{
+ set: &params.AllocationSet,
+ ul: &params.Allocation,
+ },
+ fmt.Sprintf("block.%d.capacity", idx): typedParamsFieldInfo{
+ set: &params.CapacitySet,
+ ul: &params.Capacity,
+ },
+ fmt.Sprintf("block.%d.physical", idx): typedParamsFieldInfo{
+ set: &params.PhysicalSet,
+ ul: &params.Physical,
+ },
+ }
+}
+
+type DomainStatsPerf struct {
+ CmtSet bool
+ Cmt uint64
+ MbmtSet bool
+ Mbmt uint64
+ MbmlSet bool
+ Mbml uint64
+ CacheMissesSet bool
+ CacheMisses uint64
+ CacheReferencesSet bool
+ CacheReferences uint64
+ InstructionsSet bool
+ Instructions uint64
+ CpuCyclesSet bool
+ CpuCycles uint64
+ BranchInstructionsSet bool
+ BranchInstructions uint64
+ BranchMissesSet bool
+ BranchMisses uint64
+ BusCyclesSet bool
+ BusCycles uint64
+ StalledCyclesFrontendSet bool
+ StalledCyclesFrontend uint64
+ StalledCyclesBackendSet bool
+ StalledCyclesBackend uint64
+ RefCpuCyclesSet bool
+ RefCpuCycles uint64
+ CpuClockSet bool
+ CpuClock uint64
+ TaskClockSet bool
+ TaskClock uint64
+ PageFaultsSet bool
+ PageFaults uint64
+ ContextSwitchesSet bool
+ ContextSwitches uint64
+ CpuMigrationsSet bool
+ CpuMigrations uint64
+ PageFaultsMinSet bool
+ PageFaultsMin uint64
+ PageFaultsMajSet bool
+ PageFaultsMaj uint64
+ AlignmentFaultsSet bool
+ AlignmentFaults uint64
+ EmulationFaultsSet bool
+ EmulationFaults uint64
+}
+
+func getDomainStatsPerfFieldInfo(params *DomainStatsPerf) map[string]typedParamsFieldInfo {
+ return map[string]typedParamsFieldInfo{
+ "perf.cmt": typedParamsFieldInfo{
+ set: &params.CmtSet,
+ ul: &params.Cmt,
+ },
+ "perf.mbmt": typedParamsFieldInfo{
+ set: &params.MbmtSet,
+ ul: &params.Mbmt,
+ },
+ "perf.mbml": typedParamsFieldInfo{
+ set: &params.MbmlSet,
+ ul: &params.Mbml,
+ },
+ "perf.cache_misses": typedParamsFieldInfo{
+ set: &params.CacheMissesSet,
+ ul: &params.CacheMisses,
+ },
+ "perf.cache_references": typedParamsFieldInfo{
+ set: &params.CacheReferencesSet,
+ ul: &params.CacheReferences,
+ },
+ "perf.instructions": typedParamsFieldInfo{
+ set: &params.InstructionsSet,
+ ul: &params.Instructions,
+ },
+ "perf.cpu_cycles": typedParamsFieldInfo{
+ set: &params.CpuCyclesSet,
+ ul: &params.CpuCycles,
+ },
+ "perf.branch_instructions": typedParamsFieldInfo{
+ set: &params.BranchInstructionsSet,
+ ul: &params.BranchInstructions,
+ },
+ "perf.branch_misses": typedParamsFieldInfo{
+ set: &params.BranchMissesSet,
+ ul: &params.BranchMisses,
+ },
+ "perf.bus_cycles": typedParamsFieldInfo{
+ set: &params.BusCyclesSet,
+ ul: &params.BusCycles,
+ },
+ "perf.stalled_cycles_frontend": typedParamsFieldInfo{
+ set: &params.StalledCyclesFrontendSet,
+ ul: &params.StalledCyclesFrontend,
+ },
+ "perf.stalled_cycles_backend": typedParamsFieldInfo{
+ set: &params.StalledCyclesBackendSet,
+ ul: &params.StalledCyclesBackend,
+ },
+ "perf.ref_cpu_cycles": typedParamsFieldInfo{
+ set: &params.RefCpuCyclesSet,
+ ul: &params.RefCpuCycles,
+ },
+ "perf.cpu_clock": typedParamsFieldInfo{
+ set: &params.CpuClockSet,
+ ul: &params.CpuClock,
+ },
+ "perf.task_clock": typedParamsFieldInfo{
+ set: &params.TaskClockSet,
+ ul: &params.TaskClock,
+ },
+ "perf.page_faults": typedParamsFieldInfo{
+ set: &params.PageFaultsSet,
+ ul: &params.PageFaults,
+ },
+ "perf.context_switches": typedParamsFieldInfo{
+ set: &params.ContextSwitchesSet,
+ ul: &params.ContextSwitches,
+ },
+ "perf.cpu_migrations": typedParamsFieldInfo{
+ set: &params.CpuMigrationsSet,
+ ul: &params.CpuMigrations,
+ },
+ "perf.page_faults_min": typedParamsFieldInfo{
+ set: &params.PageFaultsMinSet,
+ ul: &params.PageFaultsMin,
+ },
+ "perf.page_faults_maj": typedParamsFieldInfo{
+ set: &params.PageFaultsMajSet,
+ ul: &params.PageFaultsMaj,
+ },
+ "perf.alignment_faults": typedParamsFieldInfo{
+ set: &params.AlignmentFaultsSet,
+ ul: &params.AlignmentFaults,
+ },
+ "perf.emulation_faults": typedParamsFieldInfo{
+ set: &params.EmulationFaultsSet,
+ ul: &params.EmulationFaults,
+ },
+ }
+}
+
+type DomainStats struct {
+ Domain *Domain
+ State *DomainStatsState
+ Cpu *DomainStatsCPU
+ Balloon *DomainStatsBalloon
+ Vcpu []DomainStatsVcpu
+ Net []DomainStatsNet
+ Block []DomainStatsBlock
+ Perf *DomainStatsPerf
+}
+
+type domainStatsLengths struct {
+ VcpuCurrentSet bool
+ VcpuCurrent uint
+ VcpuMaximumSet bool
+ VcpuMaximum uint
+ NetCountSet bool
+ NetCount uint
+ BlockCountSet bool
+ BlockCount uint
+}
+
+func getDomainStatsLengthsFieldInfo(params *domainStatsLengths) map[string]typedParamsFieldInfo {
+ return map[string]typedParamsFieldInfo{
+ "vcpu.current": typedParamsFieldInfo{
+ set: &params.VcpuCurrentSet,
+ ui: &params.VcpuCurrent,
+ },
+ "vcpu.maximum": typedParamsFieldInfo{
+ set: &params.VcpuMaximumSet,
+ ui: &params.VcpuMaximum,
+ },
+ "net.count": typedParamsFieldInfo{
+ set: &params.NetCountSet,
+ ui: &params.NetCount,
+ },
+ "block.count": typedParamsFieldInfo{
+ set: &params.BlockCountSet,
+ ui: &params.BlockCount,
+ },
+ }
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virConnectGetAllDomainStats
+func (c *Connect) GetAllDomainStats(doms []*Domain, statsTypes DomainStatsTypes, flags ConnectGetAllDomainStatsFlags) ([]DomainStats, error) {
+ if C.LIBVIR_VERSION_NUMBER < 1002008 {
+ return []DomainStats{}, makeNotImplementedError("virConnectGetAllDomainStats")
+ }
+ var ret C.int
+ var cstats *C.virDomainStatsRecordPtr
+ var err C.virError
+ if len(doms) > 0 {
+ cdoms := make([]C.virDomainPtr, len(doms)+1)
+ for i := 0; i < len(doms); i++ {
+ cdoms[i] = doms[i].ptr
+ }
+
+ ret = C.virDomainListGetStatsWrapper(&cdoms[0], C.uint(statsTypes), &cstats, C.uint(flags), &err)
+ } else {
+ ret = C.virConnectGetAllDomainStatsWrapper(c.ptr, C.uint(statsTypes), &cstats, C.uint(flags), &err)
+ }
+ if ret == -1 {
+ return []DomainStats{}, makeError(&err)
+ }
+
+ defer C.virDomainStatsRecordListFreeWrapper(cstats)
+
+ stats := make([]DomainStats, ret)
+ for i := 0; i < int(ret); i++ {
+ cdomstats := *(*C.virDomainStatsRecordPtr)(unsafe.Pointer(uintptr(unsafe.Pointer(cstats)) + (unsafe.Sizeof(*cstats) * uintptr(i))))
+
+ domstats := DomainStats{
+ Domain: &Domain{ptr: cdomstats.dom},
+ }
+
+ state := &DomainStatsState{}
+ stateInfo := getDomainStatsStateFieldInfo(state)
+
+ count, gerr := typedParamsUnpackLen(cdomstats.params, int(cdomstats.nparams), stateInfo)
+ if gerr != nil {
+ return []DomainStats{}, gerr
+ }
+ if count != 0 {
+ domstats.State = state
+ }
+
+ cpu := &DomainStatsCPU{}
+ cpuInfo := getDomainStatsCPUFieldInfo(cpu)
+
+ count, gerr = typedParamsUnpackLen(cdomstats.params, int(cdomstats.nparams), cpuInfo)
+ if gerr != nil {
+ return []DomainStats{}, gerr
+ }
+ if count != 0 {
+ domstats.Cpu = cpu
+ }
+
+ balloon := &DomainStatsBalloon{}
+ balloonInfo := getDomainStatsBalloonFieldInfo(balloon)
+
+ count, gerr = typedParamsUnpackLen(cdomstats.params, int(cdomstats.nparams), balloonInfo)
+ if gerr != nil {
+ return []DomainStats{}, gerr
+ }
+ if count != 0 {
+ domstats.Balloon = balloon
+ }
+
+ perf := &DomainStatsPerf{}
+ perfInfo := getDomainStatsPerfFieldInfo(perf)
+
+ count, gerr = typedParamsUnpackLen(cdomstats.params, int(cdomstats.nparams), perfInfo)
+ if gerr != nil {
+ return []DomainStats{}, gerr
+ }
+ if count != 0 {
+ domstats.Perf = perf
+ }
+
+ lengths := domainStatsLengths{}
+ lengthsInfo := getDomainStatsLengthsFieldInfo(&lengths)
+
+ count, gerr = typedParamsUnpackLen(cdomstats.params, int(cdomstats.nparams), lengthsInfo)
+ if gerr != nil {
+ return []DomainStats{}, gerr
+ }
+
+ if !lengths.VcpuMaximumSet && lengths.VcpuCurrentSet {
+ lengths.VcpuMaximum = lengths.VcpuCurrent
+ }
+
+ if lengths.VcpuMaximum > 0 {
+
+ domstats.Vcpu = make([]DomainStatsVcpu, lengths.VcpuMaximum)
+ for j := 0; j < int(lengths.VcpuMaximum); j++ {
+ vcpu := DomainStatsVcpu{}
+ vcpuInfo := getDomainStatsVcpuFieldInfo(j, &vcpu)
+
+ count, gerr = typedParamsUnpackLen(cdomstats.params, int(cdomstats.nparams), vcpuInfo)
+ if gerr != nil {
+ return []DomainStats{}, gerr
+ }
+ if count == 0 {
+ vcpu.StateSet = true
+ vcpu.State = VCPU_OFFLINE
+ }
+ domstats.Vcpu[j] = vcpu
+ }
+ }
+
+ if lengths.BlockCountSet && lengths.BlockCount > 0 {
+ domstats.Block = make([]DomainStatsBlock, lengths.BlockCount)
+ for j := 0; j < int(lengths.BlockCount); j++ {
+ block := DomainStatsBlock{}
+ blockInfo := getDomainStatsBlockFieldInfo(j, &block)
+
+ count, gerr = typedParamsUnpackLen(cdomstats.params, int(cdomstats.nparams), blockInfo)
+ if gerr != nil {
+ return []DomainStats{}, gerr
+ }
+ if count != 0 {
+ domstats.Block[j] = block
+ }
+ }
+ }
+
+ if lengths.NetCountSet && lengths.NetCount > 0 {
+ domstats.Net = make([]DomainStatsNet, lengths.NetCount)
+ for j := 0; j < int(lengths.NetCount); j++ {
+ net := DomainStatsNet{}
+ netInfo := getDomainStatsNetFieldInfo(j, &net)
+
+ count, gerr = typedParamsUnpackLen(cdomstats.params, int(cdomstats.nparams), netInfo)
+ if gerr != nil {
+ return []DomainStats{}, gerr
+ }
+ if count != 0 {
+ domstats.Net[j] = net
+ }
+ }
+ }
+
+ stats[i] = domstats
+ }
+
+ for i := 0; i < len(stats); i++ {
+ C.virDomainRef(stats[i].Domain.ptr)
+ }
+
+ return stats, nil
+}
+
+type NodeSEVParameters struct {
+ PDHSet bool
+ PDH string
+ CertChainSet bool
+ CertChain string
+ CBitPosSet bool
+ CBitPos uint
+ ReducedPhysBitsSet bool
+ ReducedPhysBits uint
+}
+
+func getNodeSEVFieldInfo(params *NodeSEVParameters) map[string]typedParamsFieldInfo {
+ return map[string]typedParamsFieldInfo{
+ C.VIR_NODE_SEV_PDH: typedParamsFieldInfo{
+ set: &params.PDHSet,
+ s: &params.PDH,
+ },
+ C.VIR_NODE_SEV_CERT_CHAIN: typedParamsFieldInfo{
+ set: &params.CertChainSet,
+ s: &params.CertChain,
+ },
+ C.VIR_NODE_SEV_CBITPOS: typedParamsFieldInfo{
+ set: &params.CBitPosSet,
+ ui: &params.CBitPos,
+ },
+ C.VIR_NODE_SEV_REDUCED_PHYS_BITS: typedParamsFieldInfo{
+ set: &params.ReducedPhysBitsSet,
+ ui: &params.ReducedPhysBits,
+ },
+ }
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-host.html#virNodeGetSEVInfo
+func (c *Connect) GetSEVInfo(flags uint32) (*NodeSEVParameters, error) {
+ if C.LIBVIR_VERSION_NUMBER < 4005000 {
+ return nil, makeNotImplementedError("virNodeGetSEVInfo")
+ }
+
+ params := &NodeSEVParameters{}
+ info := getNodeSEVFieldInfo(params)
+
+ var cparams *C.virTypedParameter
+ var nparams C.int
+
+ var err C.virError
+ ret := C.virNodeGetSEVInfoWrapper(c.ptr, (*C.virTypedParameterPtr)(unsafe.Pointer(&cparams)), &nparams, C.uint(flags), &err)
+ if ret == -1 {
+ return nil, makeError(&err)
+ }
+
+ defer C.virTypedParamsFree(cparams, nparams)
+
+ _, gerr := typedParamsUnpackLen(cparams, int(nparams), info)
+ if gerr != nil {
+ return nil, gerr
+ }
+
+ return params, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virNWFilterBindingCreateXML
+func (c *Connect) NWFilterBindingCreateXML(xmlConfig string, flags uint32) (*NWFilterBinding, error) {
+ if C.LIBVIR_VERSION_NUMBER < 4005000 {
+ return nil, makeNotImplementedError("virNWFilterBindingCreateXML")
+ }
+ cXml := C.CString(string(xmlConfig))
+ defer C.free(unsafe.Pointer(cXml))
+ var err C.virError
+ ptr := C.virNWFilterBindingCreateXMLWrapper(c.ptr, cXml, C.uint(flags), &err)
+ if ptr == nil {
+ return nil, makeError(&err)
+ }
+ return &NWFilterBinding{ptr: ptr}, nil
+}
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/connect_compat.h b/src/dma/vendor/github.com/libvirt/libvirt-go/connect_compat.h
new file mode 100644
index 00000000..924b07dd
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/connect_compat.h
@@ -0,0 +1,200 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+#ifndef LIBVIRT_GO_CONNECT_COMPAT_H__
+#define LIBVIRT_GO_CONNECT_COMPAT_H__
+
+/* 1.2.1 */
+
+#ifndef VIR_CONNECT_LIST_STORAGE_POOLS_GLUSTER
+#define VIR_CONNECT_LIST_STORAGE_POOLS_GLUSTER 1 << 16
+#endif
+
+
+/* 1.2.2 */
+
+#ifndef VIR_NODE_CPU_STATS_INTR
+#define VIR_NODE_CPU_STATS_INTR "intr"
+#endif
+
+
+/* 1.2.6 */
+
+#ifndef VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE
+#define VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE 1 << 0
+#endif
+
+
+/* 1.2.8 */
+
+#ifndef VIR_CONNECT_GET_ALL_DOMAINS_STATS_ACTIVE
+#define VIR_CONNECT_GET_ALL_DOMAINS_STATS_ACTIVE 1 << 0
+#endif
+
+#ifndef VIR_CONNECT_GET_ALL_DOMAINS_STATS_INACTIVE
+#define VIR_CONNECT_GET_ALL_DOMAINS_STATS_INACTIVE 1 << 1
+#endif
+
+#ifndef VIR_CONNECT_GET_ALL_DOMAINS_STATS_PERSISTENT
+#define VIR_CONNECT_GET_ALL_DOMAINS_STATS_PERSISTENT 1 << 2
+#endif
+
+#ifndef VIR_CONNECT_GET_ALL_DOMAINS_STATS_TRANSIENT
+#define VIR_CONNECT_GET_ALL_DOMAINS_STATS_TRANSIENT 1 << 3
+#endif
+
+#ifndef VIR_CONNECT_GET_ALL_DOMAINS_STATS_RUNNING
+#define VIR_CONNECT_GET_ALL_DOMAINS_STATS_RUNNING 1 << 4
+#endif
+
+#ifndef VIR_CONNECT_GET_ALL_DOMAINS_STATS_PAUSED
+#define VIR_CONNECT_GET_ALL_DOMAINS_STATS_PAUSED 1 << 5
+#endif
+
+#ifndef VIR_CONNECT_GET_ALL_DOMAINS_STATS_SHUTOFF
+#define VIR_CONNECT_GET_ALL_DOMAINS_STATS_SHUTOFF 1 << 6
+#endif
+
+#ifndef VIR_CONNECT_GET_ALL_DOMAINS_STATS_OTHER
+#define VIR_CONNECT_GET_ALL_DOMAINS_STATS_OTHER 1 << 7
+#endif
+
+#ifndef VIR_CONNECT_GET_ALL_DOMAINS_STATS_ENFORCE_STATS
+#define VIR_CONNECT_GET_ALL_DOMAINS_STATS_ENFORCE_STATS 1U << 31
+#endif
+
+#ifndef VIR_CONNECT_LIST_STORAGE_POOLS_ZFS
+#define VIR_CONNECT_LIST_STORAGE_POOLS_ZFS 1 << 17
+#endif
+
+#if LIBVIR_VERSION_NUMBER < 1002008
+typedef struct _virDomainStatsRecord virDomainStatsRecord;
+typedef virDomainStatsRecord *virDomainStatsRecordPtr;
+struct _virDomainStatsRecord {
+ virDomainPtr dom;
+ virTypedParameterPtr params;
+ int nparams;
+};
+#endif
+
+
+/* 1.2.9 */
+#ifndef VIR_NODE_ALLOC_PAGES_ADD
+#define VIR_NODE_ALLOC_PAGES_ADD 0
+#endif
+
+#ifndef VIR_NODE_ALLOC_PAGES_SET
+#define VIR_NODE_ALLOC_PAGES_SET 1 << 0
+#endif
+
+
+/* 1.2.11 */
+
+#ifndef VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_STATE_CONNECTED
+#define VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_STATE_CONNECTED 1
+#endif
+
+#ifndef VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_STATE_DISCONNECTED
+#define VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_STATE_DISCONNECTED 2
+#endif
+
+#ifndef VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_REASON_UNKNOWN
+#define VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_REASON_UNKNOWN 0
+#endif
+
+#ifndef VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_REASON_DOMAIN_STARTED
+#define VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_REASON_DOMAIN_STARTED 1
+#endif
+
+#ifndef VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_REASON_CHANNEL
+#define VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_REASON_CHANNEL 2
+#endif
+
+
+/* 1.2.12 */
+
+#ifndef VIR_CONNECT_GET_ALL_DOMAINS_STATS_BACKING
+#define VIR_CONNECT_GET_ALL_DOMAINS_STATS_BACKING 1 << 30
+#endif
+
+/* 1.2.14 */
+
+#ifndef VIR_CONNECT_BASELINE_CPU_MIGRATABLE
+#define VIR_CONNECT_BASELINE_CPU_MIGRATABLE 1 << 1
+#endif
+
+/* 3.1.0 */
+
+#ifndef VIR_CONNECT_LIST_STORAGE_POOLS_VSTORAGE
+#define VIR_CONNECT_LIST_STORAGE_POOLS_VSTORAGE 1 << 18
+#endif
+
+#ifndef VIR_CONNECT_LIST_NODE_DEVICES_CAP_DRM
+#define VIR_CONNECT_LIST_NODE_DEVICES_CAP_DRM 1 << 12
+#endif
+
+/* 3.4.0 */
+
+#ifndef VIR_CONNECT_LIST_NODE_DEVICES_CAP_MDEV_TYPES
+#define VIR_CONNECT_LIST_NODE_DEVICES_CAP_MDEV_TYPES 1 << 13
+#endif
+
+#ifndef VIR_CONNECT_LIST_NODE_DEVICES_CAP_MDEV
+#define VIR_CONNECT_LIST_NODE_DEVICES_CAP_MDEV 1 << 14
+#endif
+
+#ifndef VIR_CONNECT_LIST_NODE_DEVICES_CAP_CCW_DEV
+#define VIR_CONNECT_LIST_NODE_DEVICES_CAP_CCW_DEV 1 << 15
+#endif
+
+
+/* 4.5.0 */
+
+#ifndef VIR_NODE_SEV_CBITPOS
+#define VIR_NODE_SEV_CBITPOS "cbitpos"
+#endif
+
+#ifndef VIR_NODE_SEV_REDUCED_PHYS_BITS
+#define VIR_NODE_SEV_REDUCED_PHYS_BITS "reduced-phys-bits"
+#endif
+
+#ifndef VIR_NODE_SEV_PDH
+#define VIR_NODE_SEV_PDH "pdh"
+#endif
+
+#ifndef VIR_NODE_SEV_CERT_CHAIN
+#define VIR_NODE_SEV_CERT_CHAIN "cert-chain"
+#endif
+
+#if LIBVIR_VERSION_NUMBER < 4005000
+typedef struct _virNWFilterBinding *virNWFilterBindingPtr;
+#endif
+
+#ifndef VIR_CONNECT_GET_ALL_DOMAINS_STATS_NOWAIT
+#define VIR_CONNECT_GET_ALL_DOMAINS_STATS_NOWAIT 1 << 29
+#endif
+
+#endif /* LIBVIRT_GO_CONNECT_COMPAT_H__ */
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/connect_wrapper.go b/src/dma/vendor/github.com/libvirt/libvirt-go/connect_wrapper.go
new file mode 100644
index 00000000..89727d04
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/connect_wrapper.go
@@ -0,0 +1,1766 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+package libvirt
+
+/*
+#cgo pkg-config: libvirt
+#include <assert.h>
+#include <stdio.h>
+#include "connect_wrapper.h"
+#include "callbacks_wrapper.h"
+
+extern void closeCallback(virConnectPtr, int, long);
+void closeCallbackHelper(virConnectPtr conn, int reason, void *opaque)
+{
+ closeCallback(conn, reason, (long)opaque);
+}
+
+extern int connectAuthCallback(virConnectCredentialPtr, unsigned int, int);
+int connectAuthCallbackHelper(virConnectCredentialPtr cred, unsigned int ncred, void *cbdata)
+{
+ int *callbackID = cbdata;
+
+ return connectAuthCallback(cred, ncred, *callbackID);
+}
+
+
+char *
+virConnectBaselineCPUWrapper(virConnectPtr conn,
+ const char **xmlCPUs,
+ unsigned int ncpus,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ char * ret = virConnectBaselineCPU(conn, xmlCPUs, ncpus, flags);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+char *
+virConnectBaselineHypervisorCPUWrapper(virConnectPtr conn,
+ const char *emulator,
+ const char *arch,
+ const char *machine,
+ const char *virttype,
+ const char **xmlCPUs,
+ unsigned int ncpus,
+ unsigned int flags,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 4004000
+ assert(0); // Caller should have checked version
+#else
+ char * ret = virConnectBaselineHypervisorCPU(conn, emulator, arch, machine, virttype, xmlCPUs, ncpus, flags);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+int
+virConnectCloseWrapper(virConnectPtr conn,
+ virErrorPtr err)
+{
+ int ret = virConnectClose(conn);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virConnectCompareCPUWrapper(virConnectPtr conn,
+ const char *xmlDesc,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virConnectCompareCPU(conn, xmlDesc, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virConnectCompareHypervisorCPUWrapper(virConnectPtr conn,
+ const char *emulator,
+ const char *arch,
+ const char *machine,
+ const char *virttype,
+ const char *xmlCPU,
+ unsigned int flags,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 4004000
+ assert(0); // Caller should have checked version
+#else
+ int ret = virConnectCompareHypervisorCPU(conn, emulator, arch, machine, virttype, xmlCPU, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+char *
+virConnectDomainXMLFromNativeWrapper(virConnectPtr conn,
+ const char *nativeFormat,
+ const char *nativeConfig,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ char * ret = virConnectDomainXMLFromNative(conn, nativeFormat, nativeConfig, flags);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+char *
+virConnectDomainXMLToNativeWrapper(virConnectPtr conn,
+ const char *nativeFormat,
+ const char *domainXml,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ char * ret = virConnectDomainXMLToNative(conn, nativeFormat, domainXml, flags);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+char *
+virConnectFindStoragePoolSourcesWrapper(virConnectPtr conn,
+ const char *type,
+ const char *srcSpec,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ char * ret = virConnectFindStoragePoolSources(conn, type, srcSpec, flags);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virConnectGetAllDomainStatsWrapper(virConnectPtr conn,
+ unsigned int stats,
+ virDomainStatsRecordPtr **retStats,
+ unsigned int flags,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 1002008
+ assert(0); // Caller should have checked version
+#else
+ int ret = virConnectGetAllDomainStats(conn, stats, retStats, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+int
+virConnectGetCPUModelNamesWrapper(virConnectPtr conn,
+ const char *arch,
+ char ** *models,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virConnectGetCPUModelNames(conn, arch, models, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+char *
+virConnectGetCapabilitiesWrapper(virConnectPtr conn,
+ virErrorPtr err)
+{
+ char * ret = virConnectGetCapabilities(conn);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+char *
+virConnectGetDomainCapabilitiesWrapper(virConnectPtr conn,
+ const char *emulatorbin,
+ const char *arch,
+ const char *machine,
+ const char *virttype,
+ unsigned int flags,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 1002007
+ assert(0); // Caller should have checked version
+#else
+ char * ret = virConnectGetDomainCapabilities(conn, emulatorbin, arch, machine, virttype, flags);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+char *
+virConnectGetHostnameWrapper(virConnectPtr conn,
+ virErrorPtr err)
+{
+ char * ret = virConnectGetHostname(conn);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virConnectGetLibVersionWrapper(virConnectPtr conn,
+ unsigned long *libVer,
+ virErrorPtr err)
+{
+ int ret = virConnectGetLibVersion(conn, libVer);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virConnectGetMaxVcpusWrapper(virConnectPtr conn,
+ const char *type,
+ virErrorPtr err)
+{
+ int ret = virConnectGetMaxVcpus(conn, type);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+char *
+virConnectGetSysinfoWrapper(virConnectPtr conn,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ char * ret = virConnectGetSysinfo(conn, flags);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+const char *
+virConnectGetTypeWrapper(virConnectPtr conn,
+ virErrorPtr err)
+{
+ const char * ret = virConnectGetType(conn);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+char *
+virConnectGetURIWrapper(virConnectPtr conn,
+ virErrorPtr err)
+{
+ char * ret = virConnectGetURI(conn);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virConnectGetVersionWrapper(virConnectPtr conn,
+ unsigned long *hvVer,
+ virErrorPtr err)
+{
+ int ret = virConnectGetVersion(conn, hvVer);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virConnectIsAliveWrapper(virConnectPtr conn,
+ virErrorPtr err)
+{
+ int ret = virConnectIsAlive(conn);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virConnectIsEncryptedWrapper(virConnectPtr conn,
+ virErrorPtr err)
+{
+ int ret = virConnectIsEncrypted(conn);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virConnectIsSecureWrapper(virConnectPtr conn,
+ virErrorPtr err)
+{
+ int ret = virConnectIsSecure(conn);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virConnectListAllDomainsWrapper(virConnectPtr conn,
+ virDomainPtr **domains,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virConnectListAllDomains(conn, domains, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virConnectListAllInterfacesWrapper(virConnectPtr conn,
+ virInterfacePtr **ifaces,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virConnectListAllInterfaces(conn, ifaces, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virConnectListAllNWFilterBindingsWrapper(virConnectPtr conn,
+ virNWFilterBindingPtr **bindings,
+ unsigned int flags,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 4005000
+ assert(0); // Caller should have checked version
+#else
+ int ret = virConnectListAllNWFilterBindings(conn, bindings, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+int
+virConnectListAllNWFiltersWrapper(virConnectPtr conn,
+ virNWFilterPtr **filters,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virConnectListAllNWFilters(conn, filters, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virConnectListAllNetworksWrapper(virConnectPtr conn,
+ virNetworkPtr **nets,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virConnectListAllNetworks(conn, nets, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virConnectListAllNodeDevicesWrapper(virConnectPtr conn,
+ virNodeDevicePtr **devices,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virConnectListAllNodeDevices(conn, devices, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virConnectListAllSecretsWrapper(virConnectPtr conn,
+ virSecretPtr **secrets,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virConnectListAllSecrets(conn, secrets, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virConnectListAllStoragePoolsWrapper(virConnectPtr conn,
+ virStoragePoolPtr **pools,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virConnectListAllStoragePools(conn, pools, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virConnectListDefinedDomainsWrapper(virConnectPtr conn,
+ char ** const names,
+ int maxnames,
+ virErrorPtr err)
+{
+ int ret = virConnectListDefinedDomains(conn, names, maxnames);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virConnectListDefinedInterfacesWrapper(virConnectPtr conn,
+ char ** const names,
+ int maxnames,
+ virErrorPtr err)
+{
+ int ret = virConnectListDefinedInterfaces(conn, names, maxnames);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virConnectListDefinedNetworksWrapper(virConnectPtr conn,
+ char ** const names,
+ int maxnames,
+ virErrorPtr err)
+{
+ int ret = virConnectListDefinedNetworks(conn, names, maxnames);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virConnectListDefinedStoragePoolsWrapper(virConnectPtr conn,
+ char ** const names,
+ int maxnames,
+ virErrorPtr err)
+{
+ int ret = virConnectListDefinedStoragePools(conn, names, maxnames);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virConnectListDomainsWrapper(virConnectPtr conn,
+ int *ids,
+ int maxids,
+ virErrorPtr err)
+{
+ int ret = virConnectListDomains(conn, ids, maxids);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virConnectListInterfacesWrapper(virConnectPtr conn,
+ char ** const names,
+ int maxnames,
+ virErrorPtr err)
+{
+ int ret = virConnectListInterfaces(conn, names, maxnames);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virConnectListNWFiltersWrapper(virConnectPtr conn,
+ char ** const names,
+ int maxnames,
+ virErrorPtr err)
+{
+ int ret = virConnectListNWFilters(conn, names, maxnames);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virConnectListNetworksWrapper(virConnectPtr conn,
+ char ** const names,
+ int maxnames,
+ virErrorPtr err)
+{
+ int ret = virConnectListNetworks(conn, names, maxnames);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virConnectListSecretsWrapper(virConnectPtr conn,
+ char **uuids,
+ int maxuuids,
+ virErrorPtr err)
+{
+ int ret = virConnectListSecrets(conn, uuids, maxuuids);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virConnectListStoragePoolsWrapper(virConnectPtr conn,
+ char ** const names,
+ int maxnames,
+ virErrorPtr err)
+{
+ int ret = virConnectListStoragePools(conn, names, maxnames);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virConnectNumOfDefinedDomainsWrapper(virConnectPtr conn,
+ virErrorPtr err)
+{
+ int ret = virConnectNumOfDefinedDomains(conn);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virConnectNumOfDefinedInterfacesWrapper(virConnectPtr conn,
+ virErrorPtr err)
+{
+ int ret = virConnectNumOfDefinedInterfaces(conn);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virConnectNumOfDefinedNetworksWrapper(virConnectPtr conn,
+ virErrorPtr err)
+{
+ int ret = virConnectNumOfDefinedNetworks(conn);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virConnectNumOfDefinedStoragePoolsWrapper(virConnectPtr conn,
+ virErrorPtr err)
+{
+ int ret = virConnectNumOfDefinedStoragePools(conn);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virConnectNumOfDomainsWrapper(virConnectPtr conn,
+ virErrorPtr err)
+{
+ int ret = virConnectNumOfDomains(conn);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virConnectNumOfInterfacesWrapper(virConnectPtr conn,
+ virErrorPtr err)
+{
+ int ret = virConnectNumOfInterfaces(conn);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virConnectNumOfNWFiltersWrapper(virConnectPtr conn,
+ virErrorPtr err)
+{
+ int ret = virConnectNumOfNWFilters(conn);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virConnectNumOfNetworksWrapper(virConnectPtr conn,
+ virErrorPtr err)
+{
+ int ret = virConnectNumOfNetworks(conn);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virConnectNumOfSecretsWrapper(virConnectPtr conn,
+ virErrorPtr err)
+{
+ int ret = virConnectNumOfSecrets(conn);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virConnectNumOfStoragePoolsWrapper(virConnectPtr conn,
+ virErrorPtr err)
+{
+ int ret = virConnectNumOfStoragePools(conn);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+virConnectPtr
+virConnectOpenWrapper(const char *name,
+ virErrorPtr err)
+{
+ virConnectPtr ret = virConnectOpen(name);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+virConnectPtr
+virConnectOpenAuthWrapper(const char *name,
+ int *credtype,
+ unsigned int ncredtype,
+ int callbackID,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ virConnectAuth auth = {
+ .credtype = credtype,
+ .ncredtype = ncredtype,
+ .cb = connectAuthCallbackHelper,
+ .cbdata = &callbackID,
+ };
+
+ virConnectPtr ret = virConnectOpenAuth(name, &auth, flags);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+virConnectPtr
+virConnectOpenReadOnlyWrapper(const char *name,
+ virErrorPtr err)
+{
+ virConnectPtr ret = virConnectOpenReadOnly(name);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virConnectRefWrapper(virConnectPtr conn,
+ virErrorPtr err)
+{
+ int ret = virConnectRef(conn);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virConnectRegisterCloseCallbackWrapper(virConnectPtr conn,
+ long goCallbackId,
+ virErrorPtr err)
+{
+ void *id = (void*)goCallbackId;
+ int ret = virConnectRegisterCloseCallback(conn, closeCallbackHelper, id, freeGoCallbackHelper);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virConnectSetKeepAliveWrapper(virConnectPtr conn,
+ int interval,
+ unsigned int count,
+ virErrorPtr err)
+{
+ int ret = virConnectSetKeepAlive(conn, interval, count);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virConnectUnregisterCloseCallbackWrapper(virConnectPtr conn,
+ virErrorPtr err)
+{
+ int ret = virConnectUnregisterCloseCallback(conn, closeCallbackHelper);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+virDomainPtr
+virDomainCreateLinuxWrapper(virConnectPtr conn,
+ const char *xmlDesc,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ virDomainPtr ret = virDomainCreateLinux(conn, xmlDesc, flags);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+virDomainPtr
+virDomainCreateXMLWrapper(virConnectPtr conn,
+ const char *xmlDesc,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ virDomainPtr ret = virDomainCreateXML(conn, xmlDesc, flags);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+virDomainPtr
+virDomainCreateXMLWithFilesWrapper(virConnectPtr conn,
+ const char *xmlDesc,
+ unsigned int nfiles,
+ int *files,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ virDomainPtr ret = virDomainCreateXMLWithFiles(conn, xmlDesc, nfiles, files, flags);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+virDomainPtr
+virDomainDefineXMLWrapper(virConnectPtr conn,
+ const char *xml,
+ virErrorPtr err)
+{
+ virDomainPtr ret = virDomainDefineXML(conn, xml);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+virDomainPtr
+virDomainDefineXMLFlagsWrapper(virConnectPtr conn,
+ const char *xml,
+ unsigned int flags,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 1002012
+ assert(0); // Caller should have checked version
+#else
+ virDomainPtr ret = virDomainDefineXMLFlags(conn, xml, flags);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+int
+virDomainListGetStatsWrapper(virDomainPtr *doms,
+ unsigned int stats,
+ virDomainStatsRecordPtr **retStats,
+ unsigned int flags,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 1002008
+ assert(0); // Caller should have checked version
+#else
+ int ret = virDomainListGetStats(doms, stats, retStats, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+virDomainPtr
+virDomainLookupByIDWrapper(virConnectPtr conn,
+ int id,
+ virErrorPtr err)
+{
+ virDomainPtr ret = virDomainLookupByID(conn, id);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+virDomainPtr
+virDomainLookupByNameWrapper(virConnectPtr conn,
+ const char *name,
+ virErrorPtr err)
+{
+ virDomainPtr ret = virDomainLookupByName(conn, name);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+virDomainPtr
+virDomainLookupByUUIDWrapper(virConnectPtr conn,
+ const unsigned char *uuid,
+ virErrorPtr err)
+{
+ virDomainPtr ret = virDomainLookupByUUID(conn, uuid);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+virDomainPtr
+virDomainLookupByUUIDStringWrapper(virConnectPtr conn,
+ const char *uuidstr,
+ virErrorPtr err)
+{
+ virDomainPtr ret = virDomainLookupByUUIDString(conn, uuidstr);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainRestoreWrapper(virConnectPtr conn,
+ const char *from,
+ virErrorPtr err)
+{
+ int ret = virDomainRestore(conn, from);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainRestoreFlagsWrapper(virConnectPtr conn,
+ const char *from,
+ const char *dxml,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainRestoreFlags(conn, from, dxml, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainSaveImageDefineXMLWrapper(virConnectPtr conn,
+ const char *file,
+ const char *dxml,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainSaveImageDefineXML(conn, file, dxml, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+char *
+virDomainSaveImageGetXMLDescWrapper(virConnectPtr conn,
+ const char *file,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ char * ret = virDomainSaveImageGetXMLDesc(conn, file, flags);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+void
+virDomainStatsRecordListFreeWrapper(virDomainStatsRecordPtr *stats)
+{
+#if LIBVIR_VERSION_NUMBER < 1002008
+ assert(0); // Caller should have checked version
+#else
+ virDomainStatsRecordListFree(stats);
+#endif
+}
+
+
+int
+virGetVersionWrapper(unsigned long *libVer,
+ const char *type,
+ unsigned long *typeVer,
+ virErrorPtr err)
+{
+ int ret = virGetVersion(libVer, type, typeVer);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virInterfaceChangeBeginWrapper(virConnectPtr conn,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virInterfaceChangeBegin(conn, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virInterfaceChangeCommitWrapper(virConnectPtr conn,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virInterfaceChangeCommit(conn, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virInterfaceChangeRollbackWrapper(virConnectPtr conn,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virInterfaceChangeRollback(conn, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+virInterfacePtr
+virInterfaceDefineXMLWrapper(virConnectPtr conn,
+ const char *xml,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ virInterfacePtr ret = virInterfaceDefineXML(conn, xml, flags);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+virInterfacePtr
+virInterfaceLookupByMACStringWrapper(virConnectPtr conn,
+ const char *macstr,
+ virErrorPtr err)
+{
+ virInterfacePtr ret = virInterfaceLookupByMACString(conn, macstr);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+virInterfacePtr
+virInterfaceLookupByNameWrapper(virConnectPtr conn,
+ const char *name,
+ virErrorPtr err)
+{
+ virInterfacePtr ret = virInterfaceLookupByName(conn, name);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+virNWFilterBindingPtr
+virNWFilterBindingCreateXMLWrapper(virConnectPtr conn,
+ const char *xml,
+ unsigned int flags,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 4005000
+ assert(0); // Caller should have checked version
+#else
+ virNWFilterBindingPtr ret = virNWFilterBindingCreateXML(conn, xml, flags);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+virNWFilterBindingPtr
+virNWFilterBindingLookupByPortDevWrapper(virConnectPtr conn,
+ const char *portdev,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 4005000
+ assert(0); // Caller should have checked version
+#else
+ virNWFilterBindingPtr ret = virNWFilterBindingLookupByPortDev(conn, portdev);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+virNWFilterPtr
+virNWFilterDefineXMLWrapper(virConnectPtr conn,
+ const char *xmlDesc,
+ virErrorPtr err)
+{
+ virNWFilterPtr ret = virNWFilterDefineXML(conn, xmlDesc);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+virNWFilterPtr
+virNWFilterLookupByNameWrapper(virConnectPtr conn,
+ const char *name,
+ virErrorPtr err)
+{
+ virNWFilterPtr ret = virNWFilterLookupByName(conn, name);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+virNWFilterPtr
+virNWFilterLookupByUUIDWrapper(virConnectPtr conn,
+ const unsigned char *uuid,
+ virErrorPtr err)
+{
+ virNWFilterPtr ret = virNWFilterLookupByUUID(conn, uuid);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+virNWFilterPtr
+virNWFilterLookupByUUIDStringWrapper(virConnectPtr conn,
+ const char *uuidstr,
+ virErrorPtr err)
+{
+ virNWFilterPtr ret = virNWFilterLookupByUUIDString(conn, uuidstr);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+virNetworkPtr
+virNetworkCreateXMLWrapper(virConnectPtr conn,
+ const char *xmlDesc,
+ virErrorPtr err)
+{
+ virNetworkPtr ret = virNetworkCreateXML(conn, xmlDesc);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+virNetworkPtr
+virNetworkDefineXMLWrapper(virConnectPtr conn,
+ const char *xml,
+ virErrorPtr err)
+{
+ virNetworkPtr ret = virNetworkDefineXML(conn, xml);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+virNetworkPtr
+virNetworkLookupByNameWrapper(virConnectPtr conn,
+ const char *name,
+ virErrorPtr err)
+{
+ virNetworkPtr ret = virNetworkLookupByName(conn, name);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+virNetworkPtr
+virNetworkLookupByUUIDWrapper(virConnectPtr conn,
+ const unsigned char *uuid,
+ virErrorPtr err)
+{
+ virNetworkPtr ret = virNetworkLookupByUUID(conn, uuid);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+virNetworkPtr
+virNetworkLookupByUUIDStringWrapper(virConnectPtr conn,
+ const char *uuidstr,
+ virErrorPtr err)
+{
+ virNetworkPtr ret = virNetworkLookupByUUIDString(conn, uuidstr);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virNodeAllocPagesWrapper(virConnectPtr conn,
+ unsigned int npages,
+ unsigned int *pageSizes,
+ unsigned long long *pageCounts,
+ int startCell,
+ unsigned int cellCount,
+ unsigned int flags,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 1002009
+ assert(0); // Caller should have checked version
+#else
+ int ret = virNodeAllocPages(conn, npages, pageSizes, pageCounts, startCell, cellCount, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+virNodeDevicePtr
+virNodeDeviceCreateXMLWrapper(virConnectPtr conn,
+ const char *xmlDesc,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ virNodeDevicePtr ret = virNodeDeviceCreateXML(conn, xmlDesc, flags);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+virNodeDevicePtr
+virNodeDeviceLookupByNameWrapper(virConnectPtr conn,
+ const char *name,
+ virErrorPtr err)
+{
+ virNodeDevicePtr ret = virNodeDeviceLookupByName(conn, name);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+virNodeDevicePtr
+virNodeDeviceLookupSCSIHostByWWNWrapper(virConnectPtr conn,
+ const char *wwnn,
+ const char *wwpn,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ virNodeDevicePtr ret = virNodeDeviceLookupSCSIHostByWWN(conn, wwnn, wwpn, flags);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virNodeGetCPUMapWrapper(virConnectPtr conn,
+ unsigned char **cpumap,
+ unsigned int *online,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virNodeGetCPUMap(conn, cpumap, online, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virNodeGetCPUStatsWrapper(virConnectPtr conn,
+ int cpuNum,
+ virNodeCPUStatsPtr params,
+ int *nparams,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virNodeGetCPUStats(conn, cpuNum, params, nparams, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virNodeGetCellsFreeMemoryWrapper(virConnectPtr conn,
+ unsigned long long *freeMems,
+ int startCell,
+ int maxCells,
+ virErrorPtr err)
+{
+ int ret = virNodeGetCellsFreeMemory(conn, freeMems, startCell, maxCells);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+unsigned long long
+virNodeGetFreeMemoryWrapper(virConnectPtr conn,
+ virErrorPtr err)
+{
+ unsigned long long ret = virNodeGetFreeMemory(conn);
+ if (ret == 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virNodeGetFreePagesWrapper(virConnectPtr conn,
+ unsigned int npages,
+ unsigned int *pages,
+ int startCell,
+ unsigned int cellCount,
+ unsigned long long *counts,
+ unsigned int flags,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 1002006
+ assert(0); // Caller should have checked version
+#else
+ int ret = virNodeGetFreePages(conn, npages, pages, startCell, cellCount, counts, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+int
+virNodeGetInfoWrapper(virConnectPtr conn,
+ virNodeInfoPtr info,
+ virErrorPtr err)
+{
+ int ret = virNodeGetInfo(conn, info);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virNodeGetMemoryParametersWrapper(virConnectPtr conn,
+ virTypedParameterPtr params,
+ int *nparams,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virNodeGetMemoryParameters(conn, params, nparams, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virNodeGetMemoryStatsWrapper(virConnectPtr conn,
+ int cellNum,
+ virNodeMemoryStatsPtr params,
+ int *nparams,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virNodeGetMemoryStats(conn, cellNum, params, nparams, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virNodeGetSEVInfoWrapper(virConnectPtr conn,
+ virTypedParameterPtr *params,
+ int *nparams,
+ unsigned int flags,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 4005000
+ assert(0); // Caller should have checked version
+#else
+ int ret = virNodeGetSEVInfo(conn, params, nparams, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+int
+virNodeGetSecurityModelWrapper(virConnectPtr conn,
+ virSecurityModelPtr secmodel,
+ virErrorPtr err)
+{
+ int ret = virNodeGetSecurityModel(conn, secmodel);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virNodeListDevicesWrapper(virConnectPtr conn,
+ const char *cap,
+ char ** const names,
+ int maxnames,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virNodeListDevices(conn, cap, names, maxnames, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virNodeNumOfDevicesWrapper(virConnectPtr conn,
+ const char *cap,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virNodeNumOfDevices(conn, cap, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virNodeSetMemoryParametersWrapper(virConnectPtr conn,
+ virTypedParameterPtr params,
+ int nparams,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virNodeSetMemoryParameters(conn, params, nparams, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virNodeSuspendForDurationWrapper(virConnectPtr conn,
+ unsigned int target,
+ unsigned long long duration,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virNodeSuspendForDuration(conn, target, duration, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+virSecretPtr
+virSecretDefineXMLWrapper(virConnectPtr conn,
+ const char *xml,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ virSecretPtr ret = virSecretDefineXML(conn, xml, flags);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+virSecretPtr
+virSecretLookupByUUIDWrapper(virConnectPtr conn,
+ const unsigned char *uuid,
+ virErrorPtr err)
+{
+ virSecretPtr ret = virSecretLookupByUUID(conn, uuid);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+virSecretPtr
+virSecretLookupByUUIDStringWrapper(virConnectPtr conn,
+ const char *uuidstr,
+ virErrorPtr err)
+{
+ virSecretPtr ret = virSecretLookupByUUIDString(conn, uuidstr);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+virSecretPtr
+virSecretLookupByUsageWrapper(virConnectPtr conn,
+ int usageType,
+ const char *usageID,
+ virErrorPtr err)
+{
+ virSecretPtr ret = virSecretLookupByUsage(conn, usageType, usageID);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+virStoragePoolPtr
+virStoragePoolCreateXMLWrapper(virConnectPtr conn,
+ const char *xmlDesc,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ virStoragePoolPtr ret = virStoragePoolCreateXML(conn, xmlDesc, flags);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+virStoragePoolPtr
+virStoragePoolDefineXMLWrapper(virConnectPtr conn,
+ const char *xml,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ virStoragePoolPtr ret = virStoragePoolDefineXML(conn, xml, flags);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+virStoragePoolPtr
+virStoragePoolLookupByNameWrapper(virConnectPtr conn,
+ const char *name,
+ virErrorPtr err)
+{
+ virStoragePoolPtr ret = virStoragePoolLookupByName(conn, name);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+virStoragePoolPtr
+virStoragePoolLookupByTargetPathWrapper(virConnectPtr conn,
+ const char *path,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 4001000
+ assert(0); // Caller should have checked version
+#else
+ virStoragePoolPtr ret = virStoragePoolLookupByTargetPath(conn, path);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+virStoragePoolPtr
+virStoragePoolLookupByUUIDWrapper(virConnectPtr conn,
+ const unsigned char *uuid,
+ virErrorPtr err)
+{
+ virStoragePoolPtr ret = virStoragePoolLookupByUUID(conn, uuid);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+virStoragePoolPtr
+virStoragePoolLookupByUUIDStringWrapper(virConnectPtr conn,
+ const char *uuidstr,
+ virErrorPtr err)
+{
+ virStoragePoolPtr ret = virStoragePoolLookupByUUIDString(conn, uuidstr);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+virStorageVolPtr
+virStorageVolLookupByKeyWrapper(virConnectPtr conn,
+ const char *key,
+ virErrorPtr err)
+{
+ virStorageVolPtr ret = virStorageVolLookupByKey(conn, key);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+virStorageVolPtr
+virStorageVolLookupByPathWrapper(virConnectPtr conn,
+ const char *path,
+ virErrorPtr err)
+{
+ virStorageVolPtr ret = virStorageVolLookupByPath(conn, path);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+virStreamPtr
+virStreamNewWrapper(virConnectPtr conn,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ virStreamPtr ret = virStreamNew(conn, flags);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+////////////////////////////////////////////////
+*/
+import "C"
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/connect_wrapper.h b/src/dma/vendor/github.com/libvirt/libvirt-go/connect_wrapper.h
new file mode 100644
index 00000000..5c282d21
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/connect_wrapper.h
@@ -0,0 +1,730 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+#ifndef LIBVIRT_GO_CONNECT_WRAPPER_H__
+#define LIBVIRT_GO_CONNECT_WRAPPER_H__
+
+#include <libvirt/libvirt.h>
+#include <libvirt/virterror.h>
+#include "connect_compat.h"
+
+void
+closeCallbackHelper(virConnectPtr conn,
+ int reason,
+ void *opaque);
+
+int
+virConnectRegisterCloseCallbackHelper(virConnectPtr c,
+ virConnectCloseFunc cb,
+ long goCallbackId);
+
+char *
+virConnectBaselineCPUWrapper(virConnectPtr conn,
+ const char **xmlCPUs,
+ unsigned int ncpus,
+ unsigned int flags,
+ virErrorPtr err);
+
+char *
+virConnectBaselineHypervisorCPUWrapper(virConnectPtr conn,
+ const char *emulator,
+ const char *arch,
+ const char *machine,
+ const char *virttype,
+ const char **xmlCPUs,
+ unsigned int ncpus,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virConnectCloseWrapper(virConnectPtr conn,
+ virErrorPtr err);
+
+int
+virConnectCompareCPUWrapper(virConnectPtr conn,
+ const char *xmlDesc,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virConnectCompareHypervisorCPUWrapper(virConnectPtr conn,
+ const char *emulator,
+ const char *arch,
+ const char *machine,
+ const char *virttype,
+ const char *xmlCPU,
+ unsigned int flags,
+ virErrorPtr err);
+
+char *
+virConnectDomainXMLFromNativeWrapper(virConnectPtr conn,
+ const char *nativeFormat,
+ const char *nativeConfig,
+ unsigned int flags,
+ virErrorPtr err);
+
+char *
+virConnectDomainXMLToNativeWrapper(virConnectPtr conn,
+ const char *nativeFormat,
+ const char *domainXml,
+ unsigned int flags,
+ virErrorPtr err);
+
+char *
+virConnectFindStoragePoolSourcesWrapper(virConnectPtr conn,
+ const char *type,
+ const char *srcSpec,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virConnectGetAllDomainStatsWrapper(virConnectPtr conn,
+ unsigned int stats,
+ virDomainStatsRecordPtr **retStats,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virConnectGetCPUModelNamesWrapper(virConnectPtr conn,
+ const char *arch,
+ char ***models,
+ unsigned int flags,
+ virErrorPtr err);
+
+char *
+virConnectGetCapabilitiesWrapper(virConnectPtr conn,
+ virErrorPtr err);
+
+char *
+virConnectGetDomainCapabilitiesWrapper(virConnectPtr conn,
+ const char *emulatorbin,
+ const char *arch,
+ const char *machine,
+ const char *virttype,
+ unsigned int flags,
+ virErrorPtr err);
+
+char *
+virConnectGetHostnameWrapper(virConnectPtr conn,
+ virErrorPtr err);
+
+int
+virConnectGetLibVersionWrapper(virConnectPtr conn,
+ unsigned long *libVer,
+ virErrorPtr err);
+
+int
+virConnectGetMaxVcpusWrapper(virConnectPtr conn,
+ const char *type,
+ virErrorPtr err);
+
+char *
+virConnectGetSysinfoWrapper(virConnectPtr conn,
+ unsigned int flags,
+ virErrorPtr err);
+
+const char *
+virConnectGetTypeWrapper(virConnectPtr conn,
+ virErrorPtr err);
+
+char *
+virConnectGetURIWrapper(virConnectPtr conn,
+ virErrorPtr err);
+
+int
+virConnectGetVersionWrapper(virConnectPtr conn,
+ unsigned long *hvVer,
+ virErrorPtr err);
+
+int
+virConnectIsAliveWrapper(virConnectPtr conn,
+ virErrorPtr err);
+
+int
+virConnectIsEncryptedWrapper(virConnectPtr conn,
+ virErrorPtr err);
+
+int
+virConnectIsSecureWrapper(virConnectPtr conn,
+ virErrorPtr err);
+
+int
+virConnectListAllDomainsWrapper(virConnectPtr conn,
+ virDomainPtr **domains,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virConnectListAllInterfacesWrapper(virConnectPtr conn,
+ virInterfacePtr **ifaces,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virConnectListAllNWFilterBindingsWrapper(virConnectPtr conn,
+ virNWFilterBindingPtr **bindings,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virConnectListAllNWFiltersWrapper(virConnectPtr conn,
+ virNWFilterPtr **filters,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virConnectListAllNetworksWrapper(virConnectPtr conn,
+ virNetworkPtr **nets,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virConnectListAllNodeDevicesWrapper(virConnectPtr conn,
+ virNodeDevicePtr **devices,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virConnectListAllSecretsWrapper(virConnectPtr conn,
+ virSecretPtr **secrets,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virConnectListAllStoragePoolsWrapper(virConnectPtr conn,
+ virStoragePoolPtr **pools,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virConnectListDefinedDomainsWrapper(virConnectPtr conn,
+ char **const names,
+ int maxnames,
+ virErrorPtr err);
+
+int
+virConnectListDefinedInterfacesWrapper(virConnectPtr conn,
+ char **const names,
+ int maxnames,
+ virErrorPtr err);
+
+int
+virConnectListDefinedNetworksWrapper(virConnectPtr conn,
+ char **const names,
+ int maxnames,
+ virErrorPtr err);
+
+int
+virConnectListDefinedStoragePoolsWrapper(virConnectPtr conn,
+ char **const names,
+ int maxnames,
+ virErrorPtr err);
+
+int
+virConnectListDomainsWrapper(virConnectPtr conn,
+ int *ids,
+ int maxids,
+ virErrorPtr err);
+
+int
+virConnectListInterfacesWrapper(virConnectPtr conn,
+ char **const names,
+ int maxnames,
+ virErrorPtr err);
+
+int
+virConnectListNWFiltersWrapper(virConnectPtr conn,
+ char **const names,
+ int maxnames,
+ virErrorPtr err);
+
+int
+virConnectListNetworksWrapper(virConnectPtr conn,
+ char **const names,
+ int maxnames,
+ virErrorPtr err);
+
+int
+virConnectListSecretsWrapper(virConnectPtr conn,
+ char **uuids,
+ int maxuuids,
+ virErrorPtr err);
+
+int
+virConnectListStoragePoolsWrapper(virConnectPtr conn,
+ char **const names,
+ int maxnames,
+ virErrorPtr err);
+
+int
+virConnectNumOfDefinedDomainsWrapper(virConnectPtr conn,
+ virErrorPtr err);
+
+int
+virConnectNumOfDefinedInterfacesWrapper(virConnectPtr conn,
+ virErrorPtr err);
+
+int
+virConnectNumOfDefinedNetworksWrapper(virConnectPtr conn,
+ virErrorPtr err);
+
+int
+virConnectNumOfDefinedStoragePoolsWrapper(virConnectPtr conn,
+ virErrorPtr err);
+
+int
+virConnectNumOfDomainsWrapper(virConnectPtr conn,
+ virErrorPtr err);
+
+int
+virConnectNumOfInterfacesWrapper(virConnectPtr conn,
+ virErrorPtr err);
+
+int
+virConnectNumOfNWFiltersWrapper(virConnectPtr conn,
+ virErrorPtr err);
+
+int
+virConnectNumOfNetworksWrapper(virConnectPtr conn,
+ virErrorPtr err);
+
+int
+virConnectNumOfSecretsWrapper(virConnectPtr conn,
+ virErrorPtr err);
+
+int
+virConnectNumOfStoragePoolsWrapper(virConnectPtr conn,
+ virErrorPtr err);
+
+virConnectPtr
+virConnectOpenWrapper(const char *name,
+ virErrorPtr err);
+
+virConnectPtr
+virConnectOpenAuthWrapper(const char *name,
+ int *credtype,
+ unsigned int ncredtype,
+ int callbackID,
+ unsigned int flags,
+ virErrorPtr err);
+
+virConnectPtr
+virConnectOpenReadOnlyWrapper(const char *name,
+ virErrorPtr err);
+
+int
+virConnectRefWrapper(virConnectPtr conn,
+ virErrorPtr err);
+
+int
+virConnectRegisterCloseCallbackWrapper(virConnectPtr conn,
+ long goCallbackId,
+ virErrorPtr err);
+
+int
+virConnectSetKeepAliveWrapper(virConnectPtr conn,
+ int interval,
+ unsigned int count,
+ virErrorPtr err);
+
+int
+virConnectUnregisterCloseCallbackWrapper(virConnectPtr conn,
+ virErrorPtr err);
+
+virDomainPtr
+virDomainCreateLinuxWrapper(virConnectPtr conn,
+ const char *xmlDesc,
+ unsigned int flags,
+ virErrorPtr err);
+
+virDomainPtr
+virDomainCreateXMLWrapper(virConnectPtr conn,
+ const char *xmlDesc,
+ unsigned int flags,
+ virErrorPtr err);
+
+virDomainPtr
+virDomainCreateXMLWithFilesWrapper(virConnectPtr conn,
+ const char *xmlDesc,
+ unsigned int nfiles,
+ int *files,
+ unsigned int flags,
+ virErrorPtr err);
+
+virDomainPtr
+virDomainDefineXMLWrapper(virConnectPtr conn,
+ const char *xml,
+ virErrorPtr err);
+
+virDomainPtr
+virDomainDefineXMLFlagsWrapper(virConnectPtr conn,
+ const char *xml,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainListGetStatsWrapper(virDomainPtr *doms,
+ unsigned int stats,
+ virDomainStatsRecordPtr **retStats,
+ unsigned int flags,
+ virErrorPtr err);
+
+virDomainPtr
+virDomainLookupByIDWrapper(virConnectPtr conn,
+ int id,
+ virErrorPtr err);
+
+virDomainPtr
+virDomainLookupByNameWrapper(virConnectPtr conn,
+ const char *name,
+ virErrorPtr err);
+
+virDomainPtr
+virDomainLookupByUUIDWrapper(virConnectPtr conn,
+ const unsigned char *uuid,
+ virErrorPtr err);
+
+virDomainPtr
+virDomainLookupByUUIDStringWrapper(virConnectPtr conn,
+ const char *uuidstr,
+ virErrorPtr err);
+
+int
+virDomainRestoreWrapper(virConnectPtr conn,
+ const char *from,
+ virErrorPtr err);
+
+int
+virDomainRestoreFlagsWrapper(virConnectPtr conn,
+ const char *from,
+ const char *dxml,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainSaveImageDefineXMLWrapper(virConnectPtr conn,
+ const char *file,
+ const char *dxml,
+ unsigned int flags,
+ virErrorPtr err);
+
+char *
+virDomainSaveImageGetXMLDescWrapper(virConnectPtr conn,
+ const char *file,
+ unsigned int flags,
+ virErrorPtr err);
+
+void
+virDomainStatsRecordListFreeWrapper(virDomainStatsRecordPtr *stats);
+
+int
+virGetVersionWrapper(unsigned long *libVer,
+ const char *type,
+ unsigned long *typeVer,
+ virErrorPtr err);
+
+int
+virInterfaceChangeBeginWrapper(virConnectPtr conn,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virInterfaceChangeCommitWrapper(virConnectPtr conn,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virInterfaceChangeRollbackWrapper(virConnectPtr conn,
+ unsigned int flags,
+ virErrorPtr err);
+
+virInterfacePtr
+virInterfaceDefineXMLWrapper(virConnectPtr conn,
+ const char *xml,
+ unsigned int flags,
+ virErrorPtr err);
+
+virInterfacePtr
+virInterfaceLookupByMACStringWrapper(virConnectPtr conn,
+ const char *macstr,
+ virErrorPtr err);
+
+virInterfacePtr
+virInterfaceLookupByNameWrapper(virConnectPtr conn,
+ const char *name,
+ virErrorPtr err);
+
+virNWFilterBindingPtr
+virNWFilterBindingCreateXMLWrapper(virConnectPtr conn,
+ const char *xml,
+ unsigned int flags,
+ virErrorPtr err);
+
+virNWFilterBindingPtr
+virNWFilterBindingLookupByPortDevWrapper(virConnectPtr conn,
+ const char *portdev,
+ virErrorPtr err);
+
+virNWFilterPtr
+virNWFilterDefineXMLWrapper(virConnectPtr conn,
+ const char *xmlDesc,
+ virErrorPtr err);
+
+virNWFilterPtr
+virNWFilterLookupByNameWrapper(virConnectPtr conn,
+ const char *name,
+ virErrorPtr err);
+
+virNWFilterPtr
+virNWFilterLookupByUUIDWrapper(virConnectPtr conn,
+ const unsigned char *uuid,
+ virErrorPtr err);
+
+virNWFilterPtr
+virNWFilterLookupByUUIDStringWrapper(virConnectPtr conn,
+ const char *uuidstr,
+ virErrorPtr err);
+
+virNetworkPtr
+virNetworkCreateXMLWrapper(virConnectPtr conn,
+ const char *xmlDesc,
+ virErrorPtr err);
+
+virNetworkPtr
+virNetworkDefineXMLWrapper(virConnectPtr conn,
+ const char *xml,
+ virErrorPtr err);
+
+virNetworkPtr
+virNetworkLookupByNameWrapper(virConnectPtr conn,
+ const char *name,
+ virErrorPtr err);
+
+virNetworkPtr
+virNetworkLookupByUUIDWrapper(virConnectPtr conn,
+ const unsigned char *uuid,
+ virErrorPtr err);
+
+virNetworkPtr
+virNetworkLookupByUUIDStringWrapper(virConnectPtr conn,
+ const char *uuidstr,
+ virErrorPtr err);
+
+int
+virNodeAllocPagesWrapper(virConnectPtr conn,
+ unsigned int npages,
+ unsigned int *pageSizes,
+ unsigned long long *pageCounts,
+ int startCell,
+ unsigned int cellCount,
+ unsigned int flags,
+ virErrorPtr err);
+
+virNodeDevicePtr
+virNodeDeviceCreateXMLWrapper(virConnectPtr conn,
+ const char *xmlDesc,
+ unsigned int flags,
+ virErrorPtr err);
+
+virNodeDevicePtr
+virNodeDeviceLookupByNameWrapper(virConnectPtr conn,
+ const char *name,
+ virErrorPtr err);
+
+virNodeDevicePtr
+virNodeDeviceLookupSCSIHostByWWNWrapper(virConnectPtr conn,
+ const char *wwnn,
+ const char *wwpn,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virNodeGetCPUMapWrapper(virConnectPtr conn,
+ unsigned char **cpumap,
+ unsigned int *online,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virNodeGetCPUStatsWrapper(virConnectPtr conn,
+ int cpuNum,
+ virNodeCPUStatsPtr params,
+ int *nparams,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virNodeGetCellsFreeMemoryWrapper(virConnectPtr conn,
+ unsigned long long *freeMems,
+ int startCell,
+ int maxCells,
+ virErrorPtr err);
+
+unsigned long long
+virNodeGetFreeMemoryWrapper(virConnectPtr conn,
+ virErrorPtr err);
+
+int
+virNodeGetFreePagesWrapper(virConnectPtr conn,
+ unsigned int npages,
+ unsigned int *pages,
+ int startCell,
+ unsigned int cellCount,
+ unsigned long long *counts,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virNodeGetInfoWrapper(virConnectPtr conn,
+ virNodeInfoPtr info,
+ virErrorPtr err);
+
+int
+virNodeGetMemoryParametersWrapper(virConnectPtr conn,
+ virTypedParameterPtr params,
+ int *nparams,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virNodeGetMemoryStatsWrapper(virConnectPtr conn,
+ int cellNum,
+ virNodeMemoryStatsPtr params,
+ int *nparams,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virNodeGetSEVInfoWrapper(virConnectPtr conn,
+ virTypedParameterPtr *params,
+ int *nparams,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virNodeGetSecurityModelWrapper(virConnectPtr conn,
+ virSecurityModelPtr secmodel,
+ virErrorPtr err);
+
+int
+virNodeListDevicesWrapper(virConnectPtr conn,
+ const char *cap,
+ char **const names,
+ int maxnames,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virNodeNumOfDevicesWrapper(virConnectPtr conn,
+ const char *cap,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virNodeSetMemoryParametersWrapper(virConnectPtr conn,
+ virTypedParameterPtr params,
+ int nparams,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virNodeSuspendForDurationWrapper(virConnectPtr conn,
+ unsigned int target,
+ unsigned long long duration,
+ unsigned int flags,
+ virErrorPtr err);
+
+virSecretPtr
+virSecretDefineXMLWrapper(virConnectPtr conn,
+ const char *xml,
+ unsigned int flags,
+ virErrorPtr err);
+
+virSecretPtr
+virSecretLookupByUUIDWrapper(virConnectPtr conn,
+ const unsigned char *uuid,
+ virErrorPtr err);
+
+virSecretPtr
+virSecretLookupByUUIDStringWrapper(virConnectPtr conn,
+ const char *uuidstr,
+ virErrorPtr err);
+
+virSecretPtr
+virSecretLookupByUsageWrapper(virConnectPtr conn,
+ int usageType,
+ const char *usageID,
+ virErrorPtr err);
+
+virStoragePoolPtr
+virStoragePoolCreateXMLWrapper(virConnectPtr conn,
+ const char *xmlDesc,
+ unsigned int flags,
+ virErrorPtr err);
+
+virStoragePoolPtr
+virStoragePoolDefineXMLWrapper(virConnectPtr conn,
+ const char *xml,
+ unsigned int flags,
+ virErrorPtr err);
+
+virStoragePoolPtr
+virStoragePoolLookupByNameWrapper(virConnectPtr conn,
+ const char *name,
+ virErrorPtr err);
+
+virStoragePoolPtr
+virStoragePoolLookupByTargetPathWrapper(virConnectPtr conn,
+ const char *path,
+ virErrorPtr err);
+
+virStoragePoolPtr
+virStoragePoolLookupByUUIDWrapper(virConnectPtr conn,
+ const unsigned char *uuid,
+ virErrorPtr err);
+
+virStoragePoolPtr
+virStoragePoolLookupByUUIDStringWrapper(virConnectPtr conn,
+ const char *uuidstr,
+ virErrorPtr err);
+
+virStorageVolPtr
+virStorageVolLookupByKeyWrapper(virConnectPtr conn,
+ const char *key,
+ virErrorPtr err);
+
+virStorageVolPtr
+virStorageVolLookupByPathWrapper(virConnectPtr conn,
+ const char *path,
+ virErrorPtr err);
+
+virStreamPtr
+virStreamNewWrapper(virConnectPtr conn,
+ unsigned int flags,
+ virErrorPtr err);
+
+
+#endif /* LIBVIRT_GO_CONNECT_WRAPPER_H__ */
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/doc.go b/src/dma/vendor/github.com/libvirt/libvirt-go/doc.go
new file mode 100644
index 00000000..55d75b0c
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/doc.go
@@ -0,0 +1,141 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+// Package libvirt provides a Go binding to the libvirt C library
+//
+// Through conditional compilation it supports libvirt versions 1.2.0 onwards.
+// This is done automatically, with no requirement to use magic Go build tags.
+// If an API was not available in the particular version of libvirt this package
+// was built against, an error will be returned with a code of ERR_NO_SUPPORT.
+// This is the same code seen if using a new libvirt library to talk to an old
+// libvirtd lacking the API, or if a hypervisor does not support a given feature,
+// so an application can easily handle all scenarios together.
+//
+// The Go binding is a fairly direct mapping of the underling C API which seeks
+// to maximise the use of the Go type system to allow strong compiler type
+// checking. The following rules describe how APIs/constants are mapped from C
+// to Go
+//
+// For structs, the 'vir' prefix and 'Ptr' suffix are removed from the name.
+// e.g. virConnectPtr in C becomes 'Connect' in Go.
+//
+// For structs which are reference counted at the C level, it is neccessary to
+// explicitly release the reference at the Go level. e.g. if a Go method returns
+// a '* Domain' struct, it is neccessary to call 'Free' on this when no longer
+// required. The use of 'defer' is recommended for this purpose
+//
+// dom, err := conn.LookupDomainByName("myguest")
+// if err != nil {
+// ...
+// }
+// defer dom.Free()
+//
+// If multiple goroutines are using the same libvirt object struct, it may
+// not be possible to determine which goroutine should call 'Free'. In such
+// scenarios each new goroutine should call 'Ref' to obtain a private reference
+// on the underlying C struct. All goroutines can call 'Free' unconditionally
+// with the final one causing the release of the C object.
+//
+// For methods, the 'vir' prefix and object name prefix are remove from the name.
+// The C functions become methods with an object receiver. e.g.
+// 'virDomainScreenshot' in C becomes 'Screenshot' with a 'Domain *' receiver.
+//
+// For methods which accept a 'unsigned int flags' parameter in the C level,
+// the corresponding Go parameter will be a named type corresponding to the
+// C enum that defines the valid flags. For example, the ListAllDomains
+// method takes a 'flags ConnectListAllDomainsFlags' parameter. If there are
+// not currently any flags defined for a method in the C API, then the Go
+// method parameter will be declared as a "flags uint32". Callers should always
+// pass the literal integer value 0 for such parameters, without forcing any
+// specific type. This will allow compatibility with future updates to the
+// libvirt-go binding which may replace the 'uint32' type with a enum type
+// at a later date.
+//
+// For enums, the VIR_ prefix is removed from the name. The enums get a dedicated
+// type defined in Go. e.g. the VIR_NODE_SUSPEND_TARGET_MEM enum constant in C,
+// becomes NODE_SUSPEND_TARGET_MEM with a type of NodeSuspendTarget.
+//
+// Methods accepting or returning virTypedParameter arrays in C will map the
+// parameters into a Go struct. The struct will contain two fields for each
+// possible parameter. One boolean field with a suffix of 'Set' indicates whether
+// the parameter has a value set, and the other custom typed field provides the
+// parameter value. This makes it possible to distinguish a parameter with a
+// default value of '0' from a parameter which is 0 because it isn't supported by
+// the hypervisor. If the C API defines additional typed parameters, then the
+// corresponding Go struct will be extended to have further fields.
+// e.g. the GetMemoryStats method in Go (which is backed by
+// virNodeGetMemoryStats in C) will return a NodeMemoryStats struct containing
+// the typed parameter values.
+//
+// stats, err := conn.GetMemoryParameters()
+// if err != nil {
+// ....
+// }
+// if stats.TotalSet {
+// fmt.Printf("Total memory: %d KB", stats.Total)
+// }
+//
+// Every method that can fail will include an 'error' object as the last return
+// value. This will be an instance of the Error struct if an error occurred. To
+// check for specific libvirt error codes, it is neccessary to cast the error.
+//
+// err := storage_vol.Wipe(0)
+// if err != nil {
+// lverr, ok := err.(libvirt.Error)
+// if ok && lverr.Code == libvirt.ERR_NO_SUPPORT {
+// fmt.Println("Wiping storage volumes is not supported");
+// } else {
+// fmt.Println("Error wiping storage volume: %s", err)
+// }
+// }
+//
+// Example usage
+//
+// To connect to libvirt
+//
+// import (
+// libvirt "github.com/libvirt/libvirt-go"
+// )
+// conn, err := libvirt.NewConnect("qemu:///system")
+// if err != nil {
+// ...
+// }
+// defer conn.Close()
+//
+// doms, err := conn.ListAllDomains(libvirt.CONNECT_LIST_DOMAINS_ACTIVE)
+// if err != nil {
+// ...
+// }
+//
+// fmt.Printf("%d running domains:\n", len(doms))
+// for _, dom := range doms {
+// name, err := dom.GetName()
+// if err == nil {
+// fmt.Printf(" %s\n", name)
+// }
+// dom.Free()
+// }
+//
+package libvirt
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/domain.go b/src/dma/vendor/github.com/libvirt/libvirt-go/domain.go
new file mode 100644
index 00000000..3a3ef5b7
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/domain.go
@@ -0,0 +1,4766 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+package libvirt
+
+/*
+#cgo pkg-config: libvirt
+#include <stdlib.h>
+#include "domain_wrapper.h"
+#include "connect_wrapper.h"
+*/
+import "C"
+
+import (
+ "fmt"
+ "os"
+ "reflect"
+ "strconv"
+ "strings"
+ "unsafe"
+)
+
+const (
+ DOMAIN_SEND_KEY_MAX_KEYS = uint32(C.VIR_DOMAIN_SEND_KEY_MAX_KEYS)
+)
+
+type DomainState int
+
+const (
+ DOMAIN_NOSTATE = DomainState(C.VIR_DOMAIN_NOSTATE)
+ DOMAIN_RUNNING = DomainState(C.VIR_DOMAIN_RUNNING)
+ DOMAIN_BLOCKED = DomainState(C.VIR_DOMAIN_BLOCKED)
+ DOMAIN_PAUSED = DomainState(C.VIR_DOMAIN_PAUSED)
+ DOMAIN_SHUTDOWN = DomainState(C.VIR_DOMAIN_SHUTDOWN)
+ DOMAIN_CRASHED = DomainState(C.VIR_DOMAIN_CRASHED)
+ DOMAIN_PMSUSPENDED = DomainState(C.VIR_DOMAIN_PMSUSPENDED)
+ DOMAIN_SHUTOFF = DomainState(C.VIR_DOMAIN_SHUTOFF)
+)
+
+type DomainMetadataType int
+
+const (
+ DOMAIN_METADATA_DESCRIPTION = DomainMetadataType(C.VIR_DOMAIN_METADATA_DESCRIPTION)
+ DOMAIN_METADATA_TITLE = DomainMetadataType(C.VIR_DOMAIN_METADATA_TITLE)
+ DOMAIN_METADATA_ELEMENT = DomainMetadataType(C.VIR_DOMAIN_METADATA_ELEMENT)
+)
+
+type DomainVcpuFlags int
+
+const (
+ DOMAIN_VCPU_CONFIG = DomainVcpuFlags(C.VIR_DOMAIN_VCPU_CONFIG)
+ DOMAIN_VCPU_CURRENT = DomainVcpuFlags(C.VIR_DOMAIN_VCPU_CURRENT)
+ DOMAIN_VCPU_LIVE = DomainVcpuFlags(C.VIR_DOMAIN_VCPU_LIVE)
+ DOMAIN_VCPU_MAXIMUM = DomainVcpuFlags(C.VIR_DOMAIN_VCPU_MAXIMUM)
+ DOMAIN_VCPU_GUEST = DomainVcpuFlags(C.VIR_DOMAIN_VCPU_GUEST)
+ DOMAIN_VCPU_HOTPLUGGABLE = DomainVcpuFlags(C.VIR_DOMAIN_VCPU_HOTPLUGGABLE)
+)
+
+type DomainModificationImpact int
+
+const (
+ DOMAIN_AFFECT_CONFIG = DomainModificationImpact(C.VIR_DOMAIN_AFFECT_CONFIG)
+ DOMAIN_AFFECT_CURRENT = DomainModificationImpact(C.VIR_DOMAIN_AFFECT_CURRENT)
+ DOMAIN_AFFECT_LIVE = DomainModificationImpact(C.VIR_DOMAIN_AFFECT_LIVE)
+)
+
+type DomainMemoryModFlags int
+
+const (
+ DOMAIN_MEM_CONFIG = DomainMemoryModFlags(C.VIR_DOMAIN_MEM_CONFIG)
+ DOMAIN_MEM_CURRENT = DomainMemoryModFlags(C.VIR_DOMAIN_MEM_CURRENT)
+ DOMAIN_MEM_LIVE = DomainMemoryModFlags(C.VIR_DOMAIN_MEM_LIVE)
+ DOMAIN_MEM_MAXIMUM = DomainMemoryModFlags(C.VIR_DOMAIN_MEM_MAXIMUM)
+)
+
+type DomainDestroyFlags int
+
+const (
+ DOMAIN_DESTROY_DEFAULT = DomainDestroyFlags(C.VIR_DOMAIN_DESTROY_DEFAULT)
+ DOMAIN_DESTROY_GRACEFUL = DomainDestroyFlags(C.VIR_DOMAIN_DESTROY_GRACEFUL)
+)
+
+type DomainShutdownFlags int
+
+const (
+ DOMAIN_SHUTDOWN_DEFAULT = DomainShutdownFlags(C.VIR_DOMAIN_SHUTDOWN_DEFAULT)
+ DOMAIN_SHUTDOWN_ACPI_POWER_BTN = DomainShutdownFlags(C.VIR_DOMAIN_SHUTDOWN_ACPI_POWER_BTN)
+ DOMAIN_SHUTDOWN_GUEST_AGENT = DomainShutdownFlags(C.VIR_DOMAIN_SHUTDOWN_GUEST_AGENT)
+ DOMAIN_SHUTDOWN_INITCTL = DomainShutdownFlags(C.VIR_DOMAIN_SHUTDOWN_INITCTL)
+ DOMAIN_SHUTDOWN_SIGNAL = DomainShutdownFlags(C.VIR_DOMAIN_SHUTDOWN_SIGNAL)
+ DOMAIN_SHUTDOWN_PARAVIRT = DomainShutdownFlags(C.VIR_DOMAIN_SHUTDOWN_PARAVIRT)
+)
+
+type DomainUndefineFlagsValues int
+
+const (
+ DOMAIN_UNDEFINE_MANAGED_SAVE = DomainUndefineFlagsValues(C.VIR_DOMAIN_UNDEFINE_MANAGED_SAVE) // Also remove any managed save
+ DOMAIN_UNDEFINE_SNAPSHOTS_METADATA = DomainUndefineFlagsValues(C.VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA) // If last use of domain, then also remove any snapshot metadata
+ DOMAIN_UNDEFINE_NVRAM = DomainUndefineFlagsValues(C.VIR_DOMAIN_UNDEFINE_NVRAM) // Also remove any nvram file
+ DOMAIN_UNDEFINE_KEEP_NVRAM = DomainUndefineFlagsValues(C.VIR_DOMAIN_UNDEFINE_KEEP_NVRAM) // Keep nvram file
+)
+
+type DomainDeviceModifyFlags int
+
+const (
+ DOMAIN_DEVICE_MODIFY_CONFIG = DomainDeviceModifyFlags(C.VIR_DOMAIN_DEVICE_MODIFY_CONFIG)
+ DOMAIN_DEVICE_MODIFY_CURRENT = DomainDeviceModifyFlags(C.VIR_DOMAIN_DEVICE_MODIFY_CURRENT)
+ DOMAIN_DEVICE_MODIFY_LIVE = DomainDeviceModifyFlags(C.VIR_DOMAIN_DEVICE_MODIFY_LIVE)
+ DOMAIN_DEVICE_MODIFY_FORCE = DomainDeviceModifyFlags(C.VIR_DOMAIN_DEVICE_MODIFY_FORCE)
+)
+
+type DomainCreateFlags int
+
+const (
+ DOMAIN_NONE = DomainCreateFlags(C.VIR_DOMAIN_NONE)
+ DOMAIN_START_PAUSED = DomainCreateFlags(C.VIR_DOMAIN_START_PAUSED)
+ DOMAIN_START_AUTODESTROY = DomainCreateFlags(C.VIR_DOMAIN_START_AUTODESTROY)
+ DOMAIN_START_BYPASS_CACHE = DomainCreateFlags(C.VIR_DOMAIN_START_BYPASS_CACHE)
+ DOMAIN_START_FORCE_BOOT = DomainCreateFlags(C.VIR_DOMAIN_START_FORCE_BOOT)
+ DOMAIN_START_VALIDATE = DomainCreateFlags(C.VIR_DOMAIN_START_VALIDATE)
+)
+
+const DOMAIN_MEMORY_PARAM_UNLIMITED = C.VIR_DOMAIN_MEMORY_PARAM_UNLIMITED
+
+type DomainEventType int
+
+const (
+ DOMAIN_EVENT_DEFINED = DomainEventType(C.VIR_DOMAIN_EVENT_DEFINED)
+ DOMAIN_EVENT_UNDEFINED = DomainEventType(C.VIR_DOMAIN_EVENT_UNDEFINED)
+ DOMAIN_EVENT_STARTED = DomainEventType(C.VIR_DOMAIN_EVENT_STARTED)
+ DOMAIN_EVENT_SUSPENDED = DomainEventType(C.VIR_DOMAIN_EVENT_SUSPENDED)
+ DOMAIN_EVENT_RESUMED = DomainEventType(C.VIR_DOMAIN_EVENT_RESUMED)
+ DOMAIN_EVENT_STOPPED = DomainEventType(C.VIR_DOMAIN_EVENT_STOPPED)
+ DOMAIN_EVENT_SHUTDOWN = DomainEventType(C.VIR_DOMAIN_EVENT_SHUTDOWN)
+ DOMAIN_EVENT_PMSUSPENDED = DomainEventType(C.VIR_DOMAIN_EVENT_PMSUSPENDED)
+ DOMAIN_EVENT_CRASHED = DomainEventType(C.VIR_DOMAIN_EVENT_CRASHED)
+)
+
+type DomainEventWatchdogAction int
+
+// The action that is to be taken due to the watchdog device firing
+const (
+ // No action, watchdog ignored
+ DOMAIN_EVENT_WATCHDOG_NONE = DomainEventWatchdogAction(C.VIR_DOMAIN_EVENT_WATCHDOG_NONE)
+
+ // Guest CPUs are paused
+ DOMAIN_EVENT_WATCHDOG_PAUSE = DomainEventWatchdogAction(C.VIR_DOMAIN_EVENT_WATCHDOG_PAUSE)
+
+ // Guest CPUs are reset
+ DOMAIN_EVENT_WATCHDOG_RESET = DomainEventWatchdogAction(C.VIR_DOMAIN_EVENT_WATCHDOG_RESET)
+
+ // Guest is forcibly powered off
+ DOMAIN_EVENT_WATCHDOG_POWEROFF = DomainEventWatchdogAction(C.VIR_DOMAIN_EVENT_WATCHDOG_POWEROFF)
+
+ // Guest is requested to gracefully shutdown
+ DOMAIN_EVENT_WATCHDOG_SHUTDOWN = DomainEventWatchdogAction(C.VIR_DOMAIN_EVENT_WATCHDOG_SHUTDOWN)
+
+ // No action, a debug message logged
+ DOMAIN_EVENT_WATCHDOG_DEBUG = DomainEventWatchdogAction(C.VIR_DOMAIN_EVENT_WATCHDOG_DEBUG)
+
+ // Inject a non-maskable interrupt into guest
+ DOMAIN_EVENT_WATCHDOG_INJECTNMI = DomainEventWatchdogAction(C.VIR_DOMAIN_EVENT_WATCHDOG_INJECTNMI)
+)
+
+type DomainEventIOErrorAction int
+
+// The action that is to be taken due to an IO error occurring
+const (
+ // No action, IO error ignored
+ DOMAIN_EVENT_IO_ERROR_NONE = DomainEventIOErrorAction(C.VIR_DOMAIN_EVENT_IO_ERROR_NONE)
+
+ // Guest CPUs are paused
+ DOMAIN_EVENT_IO_ERROR_PAUSE = DomainEventIOErrorAction(C.VIR_DOMAIN_EVENT_IO_ERROR_PAUSE)
+
+ // IO error reported to guest OS
+ DOMAIN_EVENT_IO_ERROR_REPORT = DomainEventIOErrorAction(C.VIR_DOMAIN_EVENT_IO_ERROR_REPORT)
+)
+
+type DomainEventGraphicsPhase int
+
+// The phase of the graphics client connection
+const (
+ // Initial socket connection established
+ DOMAIN_EVENT_GRAPHICS_CONNECT = DomainEventGraphicsPhase(C.VIR_DOMAIN_EVENT_GRAPHICS_CONNECT)
+
+ // Authentication & setup completed
+ DOMAIN_EVENT_GRAPHICS_INITIALIZE = DomainEventGraphicsPhase(C.VIR_DOMAIN_EVENT_GRAPHICS_INITIALIZE)
+
+ // Final socket disconnection
+ DOMAIN_EVENT_GRAPHICS_DISCONNECT = DomainEventGraphicsPhase(C.VIR_DOMAIN_EVENT_GRAPHICS_DISCONNECT)
+)
+
+type DomainEventGraphicsAddressType int
+
+const (
+ // IPv4 address
+ DOMAIN_EVENT_GRAPHICS_ADDRESS_IPV4 = DomainEventGraphicsAddressType(C.VIR_DOMAIN_EVENT_GRAPHICS_ADDRESS_IPV4)
+
+ // IPv6 address
+ DOMAIN_EVENT_GRAPHICS_ADDRESS_IPV6 = DomainEventGraphicsAddressType(C.VIR_DOMAIN_EVENT_GRAPHICS_ADDRESS_IPV6)
+
+ // UNIX socket path
+ DOMAIN_EVENT_GRAPHICS_ADDRESS_UNIX = DomainEventGraphicsAddressType(C.VIR_DOMAIN_EVENT_GRAPHICS_ADDRESS_UNIX)
+)
+
+type DomainBlockJobType int
+
+const (
+ // Placeholder
+ DOMAIN_BLOCK_JOB_TYPE_UNKNOWN = DomainBlockJobType(C.VIR_DOMAIN_BLOCK_JOB_TYPE_UNKNOWN)
+
+ // Block Pull (virDomainBlockPull, or virDomainBlockRebase without
+ // flags), job ends on completion
+ DOMAIN_BLOCK_JOB_TYPE_PULL = DomainBlockJobType(C.VIR_DOMAIN_BLOCK_JOB_TYPE_PULL)
+
+ // Block Copy (virDomainBlockCopy, or virDomainBlockRebase with
+ // flags), job exists as long as mirroring is active
+ DOMAIN_BLOCK_JOB_TYPE_COPY = DomainBlockJobType(C.VIR_DOMAIN_BLOCK_JOB_TYPE_COPY)
+
+ // Block Commit (virDomainBlockCommit without flags), job ends on
+ // completion
+ DOMAIN_BLOCK_JOB_TYPE_COMMIT = DomainBlockJobType(C.VIR_DOMAIN_BLOCK_JOB_TYPE_COMMIT)
+
+ // Active Block Commit (virDomainBlockCommit with flags), job
+ // exists as long as sync is active
+ DOMAIN_BLOCK_JOB_TYPE_ACTIVE_COMMIT = DomainBlockJobType(C.VIR_DOMAIN_BLOCK_JOB_TYPE_ACTIVE_COMMIT)
+)
+
+type DomainRunningReason int
+
+const (
+ DOMAIN_RUNNING_UNKNOWN = DomainRunningReason(C.VIR_DOMAIN_RUNNING_UNKNOWN)
+ DOMAIN_RUNNING_BOOTED = DomainRunningReason(C.VIR_DOMAIN_RUNNING_BOOTED) /* normal startup from boot */
+ DOMAIN_RUNNING_MIGRATED = DomainRunningReason(C.VIR_DOMAIN_RUNNING_MIGRATED) /* migrated from another host */
+ DOMAIN_RUNNING_RESTORED = DomainRunningReason(C.VIR_DOMAIN_RUNNING_RESTORED) /* restored from a state file */
+ DOMAIN_RUNNING_FROM_SNAPSHOT = DomainRunningReason(C.VIR_DOMAIN_RUNNING_FROM_SNAPSHOT) /* restored from snapshot */
+ DOMAIN_RUNNING_UNPAUSED = DomainRunningReason(C.VIR_DOMAIN_RUNNING_UNPAUSED) /* returned from paused state */
+ DOMAIN_RUNNING_MIGRATION_CANCELED = DomainRunningReason(C.VIR_DOMAIN_RUNNING_MIGRATION_CANCELED) /* returned from migration */
+ DOMAIN_RUNNING_SAVE_CANCELED = DomainRunningReason(C.VIR_DOMAIN_RUNNING_SAVE_CANCELED) /* returned from failed save process */
+ DOMAIN_RUNNING_WAKEUP = DomainRunningReason(C.VIR_DOMAIN_RUNNING_WAKEUP) /* returned from pmsuspended due to wakeup event */
+ DOMAIN_RUNNING_CRASHED = DomainRunningReason(C.VIR_DOMAIN_RUNNING_CRASHED) /* resumed from crashed */
+ DOMAIN_RUNNING_POSTCOPY = DomainRunningReason(C.VIR_DOMAIN_RUNNING_POSTCOPY) /* running in post-copy migration mode */
+)
+
+type DomainPausedReason int
+
+const (
+ DOMAIN_PAUSED_UNKNOWN = DomainPausedReason(C.VIR_DOMAIN_PAUSED_UNKNOWN) /* the reason is unknown */
+ DOMAIN_PAUSED_USER = DomainPausedReason(C.VIR_DOMAIN_PAUSED_USER) /* paused on user request */
+ DOMAIN_PAUSED_MIGRATION = DomainPausedReason(C.VIR_DOMAIN_PAUSED_MIGRATION) /* paused for offline migration */
+ DOMAIN_PAUSED_SAVE = DomainPausedReason(C.VIR_DOMAIN_PAUSED_SAVE) /* paused for save */
+ DOMAIN_PAUSED_DUMP = DomainPausedReason(C.VIR_DOMAIN_PAUSED_DUMP) /* paused for offline core dump */
+ DOMAIN_PAUSED_IOERROR = DomainPausedReason(C.VIR_DOMAIN_PAUSED_IOERROR) /* paused due to a disk I/O error */
+ DOMAIN_PAUSED_WATCHDOG = DomainPausedReason(C.VIR_DOMAIN_PAUSED_WATCHDOG) /* paused due to a watchdog event */
+ DOMAIN_PAUSED_FROM_SNAPSHOT = DomainPausedReason(C.VIR_DOMAIN_PAUSED_FROM_SNAPSHOT) /* paused after restoring from snapshot */
+ DOMAIN_PAUSED_SHUTTING_DOWN = DomainPausedReason(C.VIR_DOMAIN_PAUSED_SHUTTING_DOWN) /* paused during shutdown process */
+ DOMAIN_PAUSED_SNAPSHOT = DomainPausedReason(C.VIR_DOMAIN_PAUSED_SNAPSHOT) /* paused while creating a snapshot */
+ DOMAIN_PAUSED_CRASHED = DomainPausedReason(C.VIR_DOMAIN_PAUSED_CRASHED) /* paused due to a guest crash */
+ DOMAIN_PAUSED_STARTING_UP = DomainPausedReason(C.VIR_DOMAIN_PAUSED_STARTING_UP) /* the domainis being started */
+ DOMAIN_PAUSED_POSTCOPY = DomainPausedReason(C.VIR_DOMAIN_PAUSED_POSTCOPY) /* paused for post-copy migration */
+ DOMAIN_PAUSED_POSTCOPY_FAILED = DomainPausedReason(C.VIR_DOMAIN_PAUSED_POSTCOPY_FAILED) /* paused after failed post-copy */
+)
+
+type DomainXMLFlags int
+
+const (
+ DOMAIN_XML_SECURE = DomainXMLFlags(C.VIR_DOMAIN_XML_SECURE) /* dump security sensitive information too */
+ DOMAIN_XML_INACTIVE = DomainXMLFlags(C.VIR_DOMAIN_XML_INACTIVE) /* dump inactive domain information */
+ DOMAIN_XML_UPDATE_CPU = DomainXMLFlags(C.VIR_DOMAIN_XML_UPDATE_CPU) /* update guest CPU requirements according to host CPU */
+ DOMAIN_XML_MIGRATABLE = DomainXMLFlags(C.VIR_DOMAIN_XML_MIGRATABLE) /* dump XML suitable for migration */
+)
+
+type DomainEventDefinedDetailType int
+
+const (
+ DOMAIN_EVENT_DEFINED_ADDED = DomainEventDefinedDetailType(C.VIR_DOMAIN_EVENT_DEFINED_ADDED)
+ DOMAIN_EVENT_DEFINED_UPDATED = DomainEventDefinedDetailType(C.VIR_DOMAIN_EVENT_DEFINED_UPDATED)
+ DOMAIN_EVENT_DEFINED_RENAMED = DomainEventDefinedDetailType(C.VIR_DOMAIN_EVENT_DEFINED_RENAMED)
+ DOMAIN_EVENT_DEFINED_FROM_SNAPSHOT = DomainEventDefinedDetailType(C.VIR_DOMAIN_EVENT_DEFINED_FROM_SNAPSHOT)
+)
+
+type DomainEventUndefinedDetailType int
+
+const (
+ DOMAIN_EVENT_UNDEFINED_REMOVED = DomainEventUndefinedDetailType(C.VIR_DOMAIN_EVENT_UNDEFINED_REMOVED)
+ DOMAIN_EVENT_UNDEFINED_RENAMED = DomainEventUndefinedDetailType(C.VIR_DOMAIN_EVENT_UNDEFINED_RENAMED)
+)
+
+type DomainEventStartedDetailType int
+
+const (
+ DOMAIN_EVENT_STARTED_BOOTED = DomainEventStartedDetailType(C.VIR_DOMAIN_EVENT_STARTED_BOOTED)
+ DOMAIN_EVENT_STARTED_MIGRATED = DomainEventStartedDetailType(C.VIR_DOMAIN_EVENT_STARTED_MIGRATED)
+ DOMAIN_EVENT_STARTED_RESTORED = DomainEventStartedDetailType(C.VIR_DOMAIN_EVENT_STARTED_RESTORED)
+ DOMAIN_EVENT_STARTED_FROM_SNAPSHOT = DomainEventStartedDetailType(C.VIR_DOMAIN_EVENT_STARTED_FROM_SNAPSHOT)
+ DOMAIN_EVENT_STARTED_WAKEUP = DomainEventStartedDetailType(C.VIR_DOMAIN_EVENT_STARTED_WAKEUP)
+)
+
+type DomainEventSuspendedDetailType int
+
+const (
+ DOMAIN_EVENT_SUSPENDED_PAUSED = DomainEventSuspendedDetailType(C.VIR_DOMAIN_EVENT_SUSPENDED_PAUSED)
+ DOMAIN_EVENT_SUSPENDED_MIGRATED = DomainEventSuspendedDetailType(C.VIR_DOMAIN_EVENT_SUSPENDED_MIGRATED)
+ DOMAIN_EVENT_SUSPENDED_IOERROR = DomainEventSuspendedDetailType(C.VIR_DOMAIN_EVENT_SUSPENDED_IOERROR)
+ DOMAIN_EVENT_SUSPENDED_WATCHDOG = DomainEventSuspendedDetailType(C.VIR_DOMAIN_EVENT_SUSPENDED_WATCHDOG)
+ DOMAIN_EVENT_SUSPENDED_RESTORED = DomainEventSuspendedDetailType(C.VIR_DOMAIN_EVENT_SUSPENDED_RESTORED)
+ DOMAIN_EVENT_SUSPENDED_FROM_SNAPSHOT = DomainEventSuspendedDetailType(C.VIR_DOMAIN_EVENT_SUSPENDED_FROM_SNAPSHOT)
+ DOMAIN_EVENT_SUSPENDED_API_ERROR = DomainEventSuspendedDetailType(C.VIR_DOMAIN_EVENT_SUSPENDED_API_ERROR)
+ DOMAIN_EVENT_SUSPENDED_POSTCOPY = DomainEventSuspendedDetailType(C.VIR_DOMAIN_EVENT_SUSPENDED_POSTCOPY)
+ DOMAIN_EVENT_SUSPENDED_POSTCOPY_FAILED = DomainEventSuspendedDetailType(C.VIR_DOMAIN_EVENT_SUSPENDED_POSTCOPY_FAILED)
+)
+
+type DomainEventResumedDetailType int
+
+const (
+ DOMAIN_EVENT_RESUMED_UNPAUSED = DomainEventResumedDetailType(C.VIR_DOMAIN_EVENT_RESUMED_UNPAUSED)
+ DOMAIN_EVENT_RESUMED_MIGRATED = DomainEventResumedDetailType(C.VIR_DOMAIN_EVENT_RESUMED_MIGRATED)
+ DOMAIN_EVENT_RESUMED_FROM_SNAPSHOT = DomainEventResumedDetailType(C.VIR_DOMAIN_EVENT_RESUMED_FROM_SNAPSHOT)
+ DOMAIN_EVENT_RESUMED_POSTCOPY = DomainEventResumedDetailType(C.VIR_DOMAIN_EVENT_RESUMED_POSTCOPY)
+)
+
+type DomainEventStoppedDetailType int
+
+const (
+ DOMAIN_EVENT_STOPPED_SHUTDOWN = DomainEventStoppedDetailType(C.VIR_DOMAIN_EVENT_STOPPED_SHUTDOWN)
+ DOMAIN_EVENT_STOPPED_DESTROYED = DomainEventStoppedDetailType(C.VIR_DOMAIN_EVENT_STOPPED_DESTROYED)
+ DOMAIN_EVENT_STOPPED_CRASHED = DomainEventStoppedDetailType(C.VIR_DOMAIN_EVENT_STOPPED_CRASHED)
+ DOMAIN_EVENT_STOPPED_MIGRATED = DomainEventStoppedDetailType(C.VIR_DOMAIN_EVENT_STOPPED_MIGRATED)
+ DOMAIN_EVENT_STOPPED_SAVED = DomainEventStoppedDetailType(C.VIR_DOMAIN_EVENT_STOPPED_SAVED)
+ DOMAIN_EVENT_STOPPED_FAILED = DomainEventStoppedDetailType(C.VIR_DOMAIN_EVENT_STOPPED_FAILED)
+ DOMAIN_EVENT_STOPPED_FROM_SNAPSHOT = DomainEventStoppedDetailType(C.VIR_DOMAIN_EVENT_STOPPED_FROM_SNAPSHOT)
+)
+
+type DomainEventShutdownDetailType int
+
+const (
+ DOMAIN_EVENT_SHUTDOWN_FINISHED = DomainEventShutdownDetailType(C.VIR_DOMAIN_EVENT_SHUTDOWN_FINISHED)
+ DOMAIN_EVENT_SHUTDOWN_GUEST = DomainEventShutdownDetailType(C.VIR_DOMAIN_EVENT_SHUTDOWN_GUEST)
+ DOMAIN_EVENT_SHUTDOWN_HOST = DomainEventShutdownDetailType(C.VIR_DOMAIN_EVENT_SHUTDOWN_HOST)
+)
+
+type DomainMemoryStatTags int
+
+const (
+ DOMAIN_MEMORY_STAT_LAST = DomainMemoryStatTags(C.VIR_DOMAIN_MEMORY_STAT_NR)
+ DOMAIN_MEMORY_STAT_SWAP_IN = DomainMemoryStatTags(C.VIR_DOMAIN_MEMORY_STAT_SWAP_IN)
+ DOMAIN_MEMORY_STAT_SWAP_OUT = DomainMemoryStatTags(C.VIR_DOMAIN_MEMORY_STAT_SWAP_OUT)
+ DOMAIN_MEMORY_STAT_MAJOR_FAULT = DomainMemoryStatTags(C.VIR_DOMAIN_MEMORY_STAT_MAJOR_FAULT)
+ DOMAIN_MEMORY_STAT_MINOR_FAULT = DomainMemoryStatTags(C.VIR_DOMAIN_MEMORY_STAT_MINOR_FAULT)
+ DOMAIN_MEMORY_STAT_UNUSED = DomainMemoryStatTags(C.VIR_DOMAIN_MEMORY_STAT_UNUSED)
+ DOMAIN_MEMORY_STAT_AVAILABLE = DomainMemoryStatTags(C.VIR_DOMAIN_MEMORY_STAT_AVAILABLE)
+ DOMAIN_MEMORY_STAT_ACTUAL_BALLOON = DomainMemoryStatTags(C.VIR_DOMAIN_MEMORY_STAT_ACTUAL_BALLOON)
+ DOMAIN_MEMORY_STAT_RSS = DomainMemoryStatTags(C.VIR_DOMAIN_MEMORY_STAT_RSS)
+ DOMAIN_MEMORY_STAT_USABLE = DomainMemoryStatTags(C.VIR_DOMAIN_MEMORY_STAT_USABLE)
+ DOMAIN_MEMORY_STAT_LAST_UPDATE = DomainMemoryStatTags(C.VIR_DOMAIN_MEMORY_STAT_LAST_UPDATE)
+ DOMAIN_MEMORY_STAT_DISK_CACHES = DomainMemoryStatTags(C.VIR_DOMAIN_MEMORY_STAT_DISK_CACHES)
+ DOMAIN_MEMORY_STAT_NR = DomainMemoryStatTags(C.VIR_DOMAIN_MEMORY_STAT_NR)
+)
+
+type DomainCPUStatsTags string
+
+const (
+ DOMAIN_CPU_STATS_CPUTIME = DomainCPUStatsTags(C.VIR_DOMAIN_CPU_STATS_CPUTIME)
+ DOMAIN_CPU_STATS_SYSTEMTIME = DomainCPUStatsTags(C.VIR_DOMAIN_CPU_STATS_SYSTEMTIME)
+ DOMAIN_CPU_STATS_USERTIME = DomainCPUStatsTags(C.VIR_DOMAIN_CPU_STATS_USERTIME)
+ DOMAIN_CPU_STATS_VCPUTIME = DomainCPUStatsTags(C.VIR_DOMAIN_CPU_STATS_VCPUTIME)
+)
+
+type DomainInterfaceAddressesSource int
+
+const (
+ DOMAIN_INTERFACE_ADDRESSES_SRC_LEASE = DomainInterfaceAddressesSource(C.VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_LEASE)
+ DOMAIN_INTERFACE_ADDRESSES_SRC_AGENT = DomainInterfaceAddressesSource(C.VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_AGENT)
+ DOMAIN_INTERFACE_ADDRESSES_SRC_ARP = DomainInterfaceAddressesSource(C.VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_ARP)
+)
+
+type KeycodeSet int
+
+const (
+ KEYCODE_SET_LINUX = KeycodeSet(C.VIR_KEYCODE_SET_LINUX)
+ KEYCODE_SET_XT = KeycodeSet(C.VIR_KEYCODE_SET_XT)
+ KEYCODE_SET_ATSET1 = KeycodeSet(C.VIR_KEYCODE_SET_ATSET1)
+ KEYCODE_SET_ATSET2 = KeycodeSet(C.VIR_KEYCODE_SET_ATSET2)
+ KEYCODE_SET_ATSET3 = KeycodeSet(C.VIR_KEYCODE_SET_ATSET3)
+ KEYCODE_SET_OSX = KeycodeSet(C.VIR_KEYCODE_SET_OSX)
+ KEYCODE_SET_XT_KBD = KeycodeSet(C.VIR_KEYCODE_SET_XT_KBD)
+ KEYCODE_SET_USB = KeycodeSet(C.VIR_KEYCODE_SET_USB)
+ KEYCODE_SET_WIN32 = KeycodeSet(C.VIR_KEYCODE_SET_WIN32)
+ KEYCODE_SET_RFB = KeycodeSet(C.VIR_KEYCODE_SET_RFB)
+ KEYCODE_SET_QNUM = KeycodeSet(C.VIR_KEYCODE_SET_QNUM)
+)
+
+type ConnectDomainEventBlockJobStatus int
+
+const (
+ DOMAIN_BLOCK_JOB_COMPLETED = ConnectDomainEventBlockJobStatus(C.VIR_DOMAIN_BLOCK_JOB_COMPLETED)
+ DOMAIN_BLOCK_JOB_FAILED = ConnectDomainEventBlockJobStatus(C.VIR_DOMAIN_BLOCK_JOB_FAILED)
+ DOMAIN_BLOCK_JOB_CANCELED = ConnectDomainEventBlockJobStatus(C.VIR_DOMAIN_BLOCK_JOB_CANCELED)
+ DOMAIN_BLOCK_JOB_READY = ConnectDomainEventBlockJobStatus(C.VIR_DOMAIN_BLOCK_JOB_READY)
+)
+
+type ConnectDomainEventDiskChangeReason int
+
+const (
+ // OldSrcPath is set
+ DOMAIN_EVENT_DISK_CHANGE_MISSING_ON_START = ConnectDomainEventDiskChangeReason(C.VIR_DOMAIN_EVENT_DISK_CHANGE_MISSING_ON_START)
+ DOMAIN_EVENT_DISK_DROP_MISSING_ON_START = ConnectDomainEventDiskChangeReason(C.VIR_DOMAIN_EVENT_DISK_DROP_MISSING_ON_START)
+)
+
+type ConnectDomainEventTrayChangeReason int
+
+const (
+ DOMAIN_EVENT_TRAY_CHANGE_OPEN = ConnectDomainEventTrayChangeReason(C.VIR_DOMAIN_EVENT_TRAY_CHANGE_OPEN)
+ DOMAIN_EVENT_TRAY_CHANGE_CLOSE = ConnectDomainEventTrayChangeReason(C.VIR_DOMAIN_EVENT_TRAY_CHANGE_CLOSE)
+)
+
+type DomainProcessSignal int
+
+const (
+ DOMAIN_PROCESS_SIGNAL_NOP = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_NOP)
+ DOMAIN_PROCESS_SIGNAL_HUP = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_HUP)
+ DOMAIN_PROCESS_SIGNAL_INT = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_INT)
+ DOMAIN_PROCESS_SIGNAL_QUIT = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_QUIT)
+ DOMAIN_PROCESS_SIGNAL_ILL = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_ILL)
+ DOMAIN_PROCESS_SIGNAL_TRAP = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_TRAP)
+ DOMAIN_PROCESS_SIGNAL_ABRT = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_ABRT)
+ DOMAIN_PROCESS_SIGNAL_BUS = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_BUS)
+ DOMAIN_PROCESS_SIGNAL_FPE = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_FPE)
+ DOMAIN_PROCESS_SIGNAL_KILL = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_KILL)
+
+ DOMAIN_PROCESS_SIGNAL_USR1 = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_USR1)
+ DOMAIN_PROCESS_SIGNAL_SEGV = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_SEGV)
+ DOMAIN_PROCESS_SIGNAL_USR2 = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_USR2)
+ DOMAIN_PROCESS_SIGNAL_PIPE = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_PIPE)
+ DOMAIN_PROCESS_SIGNAL_ALRM = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_ALRM)
+ DOMAIN_PROCESS_SIGNAL_TERM = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_TERM)
+ DOMAIN_PROCESS_SIGNAL_STKFLT = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_STKFLT)
+ DOMAIN_PROCESS_SIGNAL_CHLD = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_CHLD)
+ DOMAIN_PROCESS_SIGNAL_CONT = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_CONT)
+ DOMAIN_PROCESS_SIGNAL_STOP = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_STOP)
+
+ DOMAIN_PROCESS_SIGNAL_TSTP = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_TSTP)
+ DOMAIN_PROCESS_SIGNAL_TTIN = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_TTIN)
+ DOMAIN_PROCESS_SIGNAL_TTOU = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_TTOU)
+ DOMAIN_PROCESS_SIGNAL_URG = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_URG)
+ DOMAIN_PROCESS_SIGNAL_XCPU = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_XCPU)
+ DOMAIN_PROCESS_SIGNAL_XFSZ = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_XFSZ)
+ DOMAIN_PROCESS_SIGNAL_VTALRM = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_VTALRM)
+ DOMAIN_PROCESS_SIGNAL_PROF = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_PROF)
+ DOMAIN_PROCESS_SIGNAL_WINCH = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_WINCH)
+ DOMAIN_PROCESS_SIGNAL_POLL = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_POLL)
+
+ DOMAIN_PROCESS_SIGNAL_PWR = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_PWR)
+ DOMAIN_PROCESS_SIGNAL_SYS = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_SYS)
+ DOMAIN_PROCESS_SIGNAL_RT0 = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_RT0)
+ DOMAIN_PROCESS_SIGNAL_RT1 = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_RT1)
+ DOMAIN_PROCESS_SIGNAL_RT2 = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_RT2)
+ DOMAIN_PROCESS_SIGNAL_RT3 = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_RT3)
+ DOMAIN_PROCESS_SIGNAL_RT4 = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_RT4)
+ DOMAIN_PROCESS_SIGNAL_RT5 = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_RT5)
+ DOMAIN_PROCESS_SIGNAL_RT6 = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_RT6)
+ DOMAIN_PROCESS_SIGNAL_RT7 = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_RT7)
+
+ DOMAIN_PROCESS_SIGNAL_RT8 = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_RT8)
+ DOMAIN_PROCESS_SIGNAL_RT9 = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_RT9)
+ DOMAIN_PROCESS_SIGNAL_RT10 = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_RT10)
+ DOMAIN_PROCESS_SIGNAL_RT11 = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_RT11)
+ DOMAIN_PROCESS_SIGNAL_RT12 = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_RT12)
+ DOMAIN_PROCESS_SIGNAL_RT13 = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_RT13)
+ DOMAIN_PROCESS_SIGNAL_RT14 = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_RT14)
+ DOMAIN_PROCESS_SIGNAL_RT15 = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_RT15)
+ DOMAIN_PROCESS_SIGNAL_RT16 = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_RT16)
+ DOMAIN_PROCESS_SIGNAL_RT17 = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_RT17)
+ DOMAIN_PROCESS_SIGNAL_RT18 = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_RT18)
+
+ DOMAIN_PROCESS_SIGNAL_RT19 = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_RT19)
+ DOMAIN_PROCESS_SIGNAL_RT20 = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_RT20)
+ DOMAIN_PROCESS_SIGNAL_RT21 = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_RT21)
+ DOMAIN_PROCESS_SIGNAL_RT22 = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_RT22)
+ DOMAIN_PROCESS_SIGNAL_RT23 = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_RT23)
+ DOMAIN_PROCESS_SIGNAL_RT24 = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_RT24)
+ DOMAIN_PROCESS_SIGNAL_RT25 = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_RT25)
+ DOMAIN_PROCESS_SIGNAL_RT26 = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_RT26)
+ DOMAIN_PROCESS_SIGNAL_RT27 = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_RT27)
+
+ DOMAIN_PROCESS_SIGNAL_RT28 = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_RT28)
+ DOMAIN_PROCESS_SIGNAL_RT29 = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_RT29)
+ DOMAIN_PROCESS_SIGNAL_RT30 = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_RT30)
+ DOMAIN_PROCESS_SIGNAL_RT31 = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_RT31)
+ DOMAIN_PROCESS_SIGNAL_RT32 = DomainProcessSignal(C.VIR_DOMAIN_PROCESS_SIGNAL_RT32)
+)
+
+type DomainBlockedReason int
+
+const (
+ DOMAIN_BLOCKED_UNKNOWN = DomainBlockedReason(C.VIR_DOMAIN_BLOCKED_UNKNOWN)
+)
+
+type DomainControlState int
+
+const (
+ DOMAIN_CONTROL_OK = DomainControlState(C.VIR_DOMAIN_CONTROL_OK)
+ DOMAIN_CONTROL_JOB = DomainControlState(C.VIR_DOMAIN_CONTROL_JOB)
+ DOMAIN_CONTROL_OCCUPIED = DomainControlState(C.VIR_DOMAIN_CONTROL_OCCUPIED)
+ DOMAIN_CONTROL_ERROR = DomainControlState(C.VIR_DOMAIN_CONTROL_ERROR)
+)
+
+type DomainControlErrorReason int
+
+const (
+ DOMAIN_CONTROL_ERROR_REASON_NONE = DomainControlErrorReason(C.VIR_DOMAIN_CONTROL_ERROR_REASON_NONE)
+ DOMAIN_CONTROL_ERROR_REASON_UNKNOWN = DomainControlErrorReason(C.VIR_DOMAIN_CONTROL_ERROR_REASON_UNKNOWN)
+ DOMAIN_CONTROL_ERROR_REASON_MONITOR = DomainControlErrorReason(C.VIR_DOMAIN_CONTROL_ERROR_REASON_MONITOR)
+ DOMAIN_CONTROL_ERROR_REASON_INTERNAL = DomainControlErrorReason(C.VIR_DOMAIN_CONTROL_ERROR_REASON_INTERNAL)
+)
+
+type DomainCrashedReason int
+
+const (
+ DOMAIN_CRASHED_UNKNOWN = DomainCrashedReason(C.VIR_DOMAIN_CRASHED_UNKNOWN)
+ DOMAIN_CRASHED_PANICKED = DomainCrashedReason(C.VIR_DOMAIN_CRASHED_PANICKED)
+)
+
+type DomainEventCrashedDetailType int
+
+const (
+ DOMAIN_EVENT_CRASHED_PANICKED = DomainEventCrashedDetailType(C.VIR_DOMAIN_EVENT_CRASHED_PANICKED)
+)
+
+type DomainEventPMSuspendedDetailType int
+
+const (
+ DOMAIN_EVENT_PMSUSPENDED_MEMORY = DomainEventPMSuspendedDetailType(C.VIR_DOMAIN_EVENT_PMSUSPENDED_MEMORY)
+ DOMAIN_EVENT_PMSUSPENDED_DISK = DomainEventPMSuspendedDetailType(C.VIR_DOMAIN_EVENT_PMSUSPENDED_DISK)
+)
+
+type DomainNostateReason int
+
+const (
+ DOMAIN_NOSTATE_UNKNOWN = DomainNostateReason(C.VIR_DOMAIN_NOSTATE_UNKNOWN)
+)
+
+type DomainPMSuspendedReason int
+
+const (
+ DOMAIN_PMSUSPENDED_UNKNOWN = DomainPMSuspendedReason(C.VIR_DOMAIN_PMSUSPENDED_UNKNOWN)
+)
+
+type DomainPMSuspendedDiskReason int
+
+const (
+ DOMAIN_PMSUSPENDED_DISK_UNKNOWN = DomainPMSuspendedDiskReason(C.VIR_DOMAIN_PMSUSPENDED_DISK_UNKNOWN)
+)
+
+type DomainShutdownReason int
+
+const (
+ DOMAIN_SHUTDOWN_UNKNOWN = DomainShutdownReason(C.VIR_DOMAIN_SHUTDOWN_UNKNOWN)
+ DOMAIN_SHUTDOWN_USER = DomainShutdownReason(C.VIR_DOMAIN_SHUTDOWN_USER)
+)
+
+type DomainShutoffReason int
+
+const (
+ DOMAIN_SHUTOFF_UNKNOWN = DomainShutoffReason(C.VIR_DOMAIN_SHUTOFF_UNKNOWN)
+ DOMAIN_SHUTOFF_SHUTDOWN = DomainShutoffReason(C.VIR_DOMAIN_SHUTOFF_SHUTDOWN)
+ DOMAIN_SHUTOFF_DESTROYED = DomainShutoffReason(C.VIR_DOMAIN_SHUTOFF_DESTROYED)
+ DOMAIN_SHUTOFF_CRASHED = DomainShutoffReason(C.VIR_DOMAIN_SHUTOFF_CRASHED)
+ DOMAIN_SHUTOFF_MIGRATED = DomainShutoffReason(C.VIR_DOMAIN_SHUTOFF_MIGRATED)
+ DOMAIN_SHUTOFF_SAVED = DomainShutoffReason(C.VIR_DOMAIN_SHUTOFF_SAVED)
+ DOMAIN_SHUTOFF_FAILED = DomainShutoffReason(C.VIR_DOMAIN_SHUTOFF_FAILED)
+ DOMAIN_SHUTOFF_FROM_SNAPSHOT = DomainShutoffReason(C.VIR_DOMAIN_SHUTOFF_FROM_SNAPSHOT)
+)
+
+type DomainBlockCommitFlags int
+
+const (
+ DOMAIN_BLOCK_COMMIT_SHALLOW = DomainBlockCommitFlags(C.VIR_DOMAIN_BLOCK_COMMIT_SHALLOW)
+ DOMAIN_BLOCK_COMMIT_DELETE = DomainBlockCommitFlags(C.VIR_DOMAIN_BLOCK_COMMIT_DELETE)
+ DOMAIN_BLOCK_COMMIT_ACTIVE = DomainBlockCommitFlags(C.VIR_DOMAIN_BLOCK_COMMIT_ACTIVE)
+ DOMAIN_BLOCK_COMMIT_RELATIVE = DomainBlockCommitFlags(C.VIR_DOMAIN_BLOCK_COMMIT_RELATIVE)
+ DOMAIN_BLOCK_COMMIT_BANDWIDTH_BYTES = DomainBlockCommitFlags(C.VIR_DOMAIN_BLOCK_COMMIT_BANDWIDTH_BYTES)
+)
+
+type DomainBlockCopyFlags int
+
+const (
+ DOMAIN_BLOCK_COPY_SHALLOW = DomainBlockCopyFlags(C.VIR_DOMAIN_BLOCK_COPY_SHALLOW)
+ DOMAIN_BLOCK_COPY_REUSE_EXT = DomainBlockCopyFlags(C.VIR_DOMAIN_BLOCK_COPY_REUSE_EXT)
+ DOMAIN_BLOCK_COPY_TRANSIENT_JOB = DomainBlockCopyFlags(C.VIR_DOMAIN_BLOCK_COPY_TRANSIENT_JOB)
+)
+
+type DomainBlockRebaseFlags int
+
+const (
+ DOMAIN_BLOCK_REBASE_SHALLOW = DomainBlockRebaseFlags(C.VIR_DOMAIN_BLOCK_REBASE_SHALLOW)
+ DOMAIN_BLOCK_REBASE_REUSE_EXT = DomainBlockRebaseFlags(C.VIR_DOMAIN_BLOCK_REBASE_REUSE_EXT)
+ DOMAIN_BLOCK_REBASE_COPY_RAW = DomainBlockRebaseFlags(C.VIR_DOMAIN_BLOCK_REBASE_COPY_RAW)
+ DOMAIN_BLOCK_REBASE_COPY = DomainBlockRebaseFlags(C.VIR_DOMAIN_BLOCK_REBASE_COPY)
+ DOMAIN_BLOCK_REBASE_RELATIVE = DomainBlockRebaseFlags(C.VIR_DOMAIN_BLOCK_REBASE_RELATIVE)
+ DOMAIN_BLOCK_REBASE_COPY_DEV = DomainBlockRebaseFlags(C.VIR_DOMAIN_BLOCK_REBASE_COPY_DEV)
+ DOMAIN_BLOCK_REBASE_BANDWIDTH_BYTES = DomainBlockRebaseFlags(C.VIR_DOMAIN_BLOCK_REBASE_BANDWIDTH_BYTES)
+)
+
+type DomainBlockJobAbortFlags int
+
+const (
+ DOMAIN_BLOCK_JOB_ABORT_ASYNC = DomainBlockJobAbortFlags(C.VIR_DOMAIN_BLOCK_JOB_ABORT_ASYNC)
+ DOMAIN_BLOCK_JOB_ABORT_PIVOT = DomainBlockJobAbortFlags(C.VIR_DOMAIN_BLOCK_JOB_ABORT_PIVOT)
+)
+
+type DomainBlockJobInfoFlags int
+
+const (
+ DOMAIN_BLOCK_JOB_INFO_BANDWIDTH_BYTES = DomainBlockJobInfoFlags(C.VIR_DOMAIN_BLOCK_JOB_INFO_BANDWIDTH_BYTES)
+)
+
+type DomainBlockJobSetSpeedFlags int
+
+const (
+ DOMAIN_BLOCK_JOB_SPEED_BANDWIDTH_BYTES = DomainBlockJobSetSpeedFlags(C.VIR_DOMAIN_BLOCK_JOB_SPEED_BANDWIDTH_BYTES)
+)
+
+type DomainBlockPullFlags int
+
+const (
+ DOMAIN_BLOCK_PULL_BANDWIDTH_BYTES = DomainBlockPullFlags(C.VIR_DOMAIN_BLOCK_PULL_BANDWIDTH_BYTES)
+)
+
+type DomainBlockResizeFlags int
+
+const (
+ DOMAIN_BLOCK_RESIZE_BYTES = DomainBlockResizeFlags(C.VIR_DOMAIN_BLOCK_RESIZE_BYTES)
+)
+
+type Domain struct {
+ ptr C.virDomainPtr
+}
+
+type DomainChannelFlags int
+
+const (
+ DOMAIN_CHANNEL_FORCE = DomainChannelFlags(C.VIR_DOMAIN_CHANNEL_FORCE)
+)
+
+type DomainConsoleFlags int
+
+const (
+ DOMAIN_CONSOLE_FORCE = DomainConsoleFlags(C.VIR_DOMAIN_CONSOLE_FORCE)
+ DOMAIN_CONSOLE_SAFE = DomainConsoleFlags(C.VIR_DOMAIN_CONSOLE_SAFE)
+)
+
+type DomainCoreDumpFormat int
+
+const (
+ DOMAIN_CORE_DUMP_FORMAT_RAW = DomainCoreDumpFormat(C.VIR_DOMAIN_CORE_DUMP_FORMAT_RAW)
+ DOMAIN_CORE_DUMP_FORMAT_KDUMP_ZLIB = DomainCoreDumpFormat(C.VIR_DOMAIN_CORE_DUMP_FORMAT_KDUMP_ZLIB)
+ DOMAIN_CORE_DUMP_FORMAT_KDUMP_LZO = DomainCoreDumpFormat(C.VIR_DOMAIN_CORE_DUMP_FORMAT_KDUMP_LZO)
+ DOMAIN_CORE_DUMP_FORMAT_KDUMP_SNAPPY = DomainCoreDumpFormat(C.VIR_DOMAIN_CORE_DUMP_FORMAT_KDUMP_SNAPPY)
+)
+
+type DomainDefineFlags int
+
+const (
+ DOMAIN_DEFINE_VALIDATE = DomainDefineFlags(C.VIR_DOMAIN_DEFINE_VALIDATE)
+)
+
+type DomainJobType int
+
+const (
+ DOMAIN_JOB_NONE = DomainJobType(C.VIR_DOMAIN_JOB_NONE)
+ DOMAIN_JOB_BOUNDED = DomainJobType(C.VIR_DOMAIN_JOB_BOUNDED)
+ DOMAIN_JOB_UNBOUNDED = DomainJobType(C.VIR_DOMAIN_JOB_UNBOUNDED)
+ DOMAIN_JOB_COMPLETED = DomainJobType(C.VIR_DOMAIN_JOB_COMPLETED)
+ DOMAIN_JOB_FAILED = DomainJobType(C.VIR_DOMAIN_JOB_FAILED)
+ DOMAIN_JOB_CANCELLED = DomainJobType(C.VIR_DOMAIN_JOB_CANCELLED)
+)
+
+type DomainGetJobStatsFlags int
+
+const (
+ DOMAIN_JOB_STATS_COMPLETED = DomainGetJobStatsFlags(C.VIR_DOMAIN_JOB_STATS_COMPLETED)
+)
+
+type DomainNumatuneMemMode int
+
+const (
+ DOMAIN_NUMATUNE_MEM_STRICT = DomainNumatuneMemMode(C.VIR_DOMAIN_NUMATUNE_MEM_STRICT)
+ DOMAIN_NUMATUNE_MEM_PREFERRED = DomainNumatuneMemMode(C.VIR_DOMAIN_NUMATUNE_MEM_PREFERRED)
+ DOMAIN_NUMATUNE_MEM_INTERLEAVE = DomainNumatuneMemMode(C.VIR_DOMAIN_NUMATUNE_MEM_INTERLEAVE)
+)
+
+type DomainOpenGraphicsFlags int
+
+const (
+ DOMAIN_OPEN_GRAPHICS_SKIPAUTH = DomainOpenGraphicsFlags(C.VIR_DOMAIN_OPEN_GRAPHICS_SKIPAUTH)
+)
+
+type DomainSetUserPasswordFlags int
+
+const (
+ DOMAIN_PASSWORD_ENCRYPTED = DomainSetUserPasswordFlags(C.VIR_DOMAIN_PASSWORD_ENCRYPTED)
+)
+
+type DomainRebootFlagValues int
+
+const (
+ DOMAIN_REBOOT_DEFAULT = DomainRebootFlagValues(C.VIR_DOMAIN_REBOOT_DEFAULT)
+ DOMAIN_REBOOT_ACPI_POWER_BTN = DomainRebootFlagValues(C.VIR_DOMAIN_REBOOT_ACPI_POWER_BTN)
+ DOMAIN_REBOOT_GUEST_AGENT = DomainRebootFlagValues(C.VIR_DOMAIN_REBOOT_GUEST_AGENT)
+ DOMAIN_REBOOT_INITCTL = DomainRebootFlagValues(C.VIR_DOMAIN_REBOOT_INITCTL)
+ DOMAIN_REBOOT_SIGNAL = DomainRebootFlagValues(C.VIR_DOMAIN_REBOOT_SIGNAL)
+ DOMAIN_REBOOT_PARAVIRT = DomainRebootFlagValues(C.VIR_DOMAIN_REBOOT_PARAVIRT)
+)
+
+type DomainSaveRestoreFlags int
+
+const (
+ DOMAIN_SAVE_BYPASS_CACHE = DomainSaveRestoreFlags(C.VIR_DOMAIN_SAVE_BYPASS_CACHE)
+ DOMAIN_SAVE_RUNNING = DomainSaveRestoreFlags(C.VIR_DOMAIN_SAVE_RUNNING)
+ DOMAIN_SAVE_PAUSED = DomainSaveRestoreFlags(C.VIR_DOMAIN_SAVE_PAUSED)
+)
+
+type DomainSetTimeFlags int
+
+const (
+ DOMAIN_TIME_SYNC = DomainSetTimeFlags(C.VIR_DOMAIN_TIME_SYNC)
+)
+
+type DomainDiskErrorCode int
+
+const (
+ DOMAIN_DISK_ERROR_NONE = DomainDiskErrorCode(C.VIR_DOMAIN_DISK_ERROR_NONE)
+ DOMAIN_DISK_ERROR_UNSPEC = DomainDiskErrorCode(C.VIR_DOMAIN_DISK_ERROR_UNSPEC)
+ DOMAIN_DISK_ERROR_NO_SPACE = DomainDiskErrorCode(C.VIR_DOMAIN_DISK_ERROR_NO_SPACE)
+)
+
+type DomainStatsTypes int
+
+const (
+ DOMAIN_STATS_STATE = DomainStatsTypes(C.VIR_DOMAIN_STATS_STATE)
+ DOMAIN_STATS_CPU_TOTAL = DomainStatsTypes(C.VIR_DOMAIN_STATS_CPU_TOTAL)
+ DOMAIN_STATS_BALLOON = DomainStatsTypes(C.VIR_DOMAIN_STATS_BALLOON)
+ DOMAIN_STATS_VCPU = DomainStatsTypes(C.VIR_DOMAIN_STATS_VCPU)
+ DOMAIN_STATS_INTERFACE = DomainStatsTypes(C.VIR_DOMAIN_STATS_INTERFACE)
+ DOMAIN_STATS_BLOCK = DomainStatsTypes(C.VIR_DOMAIN_STATS_BLOCK)
+ DOMAIN_STATS_PERF = DomainStatsTypes(C.VIR_DOMAIN_STATS_PERF)
+)
+
+type DomainCoreDumpFlags int
+
+const (
+ DUMP_CRASH = DomainCoreDumpFlags(C.VIR_DUMP_CRASH)
+ DUMP_LIVE = DomainCoreDumpFlags(C.VIR_DUMP_LIVE)
+ DUMP_BYPASS_CACHE = DomainCoreDumpFlags(C.VIR_DUMP_BYPASS_CACHE)
+ DUMP_RESET = DomainCoreDumpFlags(C.VIR_DUMP_RESET)
+ DUMP_MEMORY_ONLY = DomainCoreDumpFlags(C.VIR_DUMP_MEMORY_ONLY)
+)
+
+type DomainMemoryFlags int
+
+const (
+ MEMORY_VIRTUAL = DomainMemoryFlags(C.VIR_MEMORY_VIRTUAL)
+ MEMORY_PHYSICAL = DomainMemoryFlags(C.VIR_MEMORY_PHYSICAL)
+)
+
+type DomainMigrateFlags int
+
+const (
+ MIGRATE_LIVE = DomainMigrateFlags(C.VIR_MIGRATE_LIVE)
+ MIGRATE_PEER2PEER = DomainMigrateFlags(C.VIR_MIGRATE_PEER2PEER)
+ MIGRATE_TUNNELLED = DomainMigrateFlags(C.VIR_MIGRATE_TUNNELLED)
+ MIGRATE_PERSIST_DEST = DomainMigrateFlags(C.VIR_MIGRATE_PERSIST_DEST)
+ MIGRATE_UNDEFINE_SOURCE = DomainMigrateFlags(C.VIR_MIGRATE_UNDEFINE_SOURCE)
+ MIGRATE_PAUSED = DomainMigrateFlags(C.VIR_MIGRATE_PAUSED)
+ MIGRATE_NON_SHARED_DISK = DomainMigrateFlags(C.VIR_MIGRATE_NON_SHARED_DISK)
+ MIGRATE_NON_SHARED_INC = DomainMigrateFlags(C.VIR_MIGRATE_NON_SHARED_INC)
+ MIGRATE_CHANGE_PROTECTION = DomainMigrateFlags(C.VIR_MIGRATE_CHANGE_PROTECTION)
+ MIGRATE_UNSAFE = DomainMigrateFlags(C.VIR_MIGRATE_UNSAFE)
+ MIGRATE_OFFLINE = DomainMigrateFlags(C.VIR_MIGRATE_OFFLINE)
+ MIGRATE_COMPRESSED = DomainMigrateFlags(C.VIR_MIGRATE_COMPRESSED)
+ MIGRATE_ABORT_ON_ERROR = DomainMigrateFlags(C.VIR_MIGRATE_ABORT_ON_ERROR)
+ MIGRATE_AUTO_CONVERGE = DomainMigrateFlags(C.VIR_MIGRATE_AUTO_CONVERGE)
+ MIGRATE_RDMA_PIN_ALL = DomainMigrateFlags(C.VIR_MIGRATE_RDMA_PIN_ALL)
+ MIGRATE_POSTCOPY = DomainMigrateFlags(C.VIR_MIGRATE_POSTCOPY)
+ MIGRATE_TLS = DomainMigrateFlags(C.VIR_MIGRATE_TLS)
+)
+
+type VcpuState int
+
+const (
+ VCPU_OFFLINE = VcpuState(C.VIR_VCPU_OFFLINE)
+ VCPU_RUNNING = VcpuState(C.VIR_VCPU_RUNNING)
+ VCPU_BLOCKED = VcpuState(C.VIR_VCPU_BLOCKED)
+)
+
+type DomainJobOperationType int
+
+const (
+ DOMAIN_JOB_OPERATION_UNKNOWN = DomainJobOperationType(C.VIR_DOMAIN_JOB_OPERATION_UNKNOWN)
+ DOMAIN_JOB_OPERATION_START = DomainJobOperationType(C.VIR_DOMAIN_JOB_OPERATION_START)
+ DOMAIN_JOB_OPERATION_SAVE = DomainJobOperationType(C.VIR_DOMAIN_JOB_OPERATION_SAVE)
+ DOMAIN_JOB_OPERATION_RESTORE = DomainJobOperationType(C.VIR_DOMAIN_JOB_OPERATION_RESTORE)
+ DOMAIN_JOB_OPERATION_MIGRATION_IN = DomainJobOperationType(C.VIR_DOMAIN_JOB_OPERATION_MIGRATION_IN)
+ DOMAIN_JOB_OPERATION_MIGRATION_OUT = DomainJobOperationType(C.VIR_DOMAIN_JOB_OPERATION_MIGRATION_OUT)
+ DOMAIN_JOB_OPERATION_SNAPSHOT = DomainJobOperationType(C.VIR_DOMAIN_JOB_OPERATION_SNAPSHOT)
+ DOMAIN_JOB_OPERATION_SNAPSHOT_REVERT = DomainJobOperationType(C.VIR_DOMAIN_JOB_OPERATION_SNAPSHOT_REVERT)
+ DOMAIN_JOB_OPERATION_DUMP = DomainJobOperationType(C.VIR_DOMAIN_JOB_OPERATION_DUMP)
+)
+
+type DomainBlockInfo struct {
+ Capacity uint64
+ Allocation uint64
+ Physical uint64
+}
+
+type DomainInfo struct {
+ State DomainState
+ MaxMem uint64
+ Memory uint64
+ NrVirtCpu uint
+ CpuTime uint64
+}
+
+type DomainMemoryStat struct {
+ Tag int32
+ Val uint64
+}
+
+type DomainVcpuInfo struct {
+ Number uint32
+ State int32
+ CpuTime uint64
+ Cpu int32
+ CpuMap []bool
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainFree
+func (d *Domain) Free() error {
+ var err C.virError
+ ret := C.virDomainFreeWrapper(d.ptr, &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainRef
+func (c *Domain) Ref() error {
+ var err C.virError
+ ret := C.virDomainRefWrapper(c.ptr, &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainCreate
+func (d *Domain) Create() error {
+ var err C.virError
+ result := C.virDomainCreateWrapper(d.ptr, &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainCreateWithFlags
+func (d *Domain) CreateWithFlags(flags DomainCreateFlags) error {
+ var err C.virError
+ result := C.virDomainCreateWithFlagsWrapper(d.ptr, C.uint(flags), &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainCreateWithFiles
+func (d *Domain) CreateWithFiles(files []os.File, flags DomainCreateFlags) error {
+ cfiles := make([]C.int, len(files))
+ for i := 0; i < len(files); i++ {
+ cfiles[i] = C.int(files[i].Fd())
+ }
+ var err C.virError
+ result := C.virDomainCreateWithFilesWrapper(d.ptr, C.uint(len(files)), &cfiles[0], C.uint(flags), &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainDestroy
+func (d *Domain) Destroy() error {
+ var err C.virError
+ result := C.virDomainDestroyWrapper(d.ptr, &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainShutdown
+func (d *Domain) Shutdown() error {
+ var err C.virError
+ result := C.virDomainShutdownWrapper(d.ptr, &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainReboot
+func (d *Domain) Reboot(flags DomainRebootFlagValues) error {
+ var err C.virError
+ result := C.virDomainRebootWrapper(d.ptr, C.uint(flags), &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainIsActive
+func (d *Domain) IsActive() (bool, error) {
+ var err C.virError
+ result := C.virDomainIsActiveWrapper(d.ptr, &err)
+ if result == -1 {
+ return false, makeError(&err)
+ }
+ if result == 1 {
+ return true, nil
+ }
+ return false, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainIsPersistent
+func (d *Domain) IsPersistent() (bool, error) {
+ var err C.virError
+ result := C.virDomainIsPersistentWrapper(d.ptr, &err)
+ if result == -1 {
+ return false, makeError(&err)
+ }
+ if result == 1 {
+ return true, nil
+ }
+ return false, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainIsUpdated
+func (d *Domain) IsUpdated() (bool, error) {
+ var err C.virError
+ result := C.virDomainIsUpdatedWrapper(d.ptr, &err)
+ if result == -1 {
+ return false, makeError(&err)
+ }
+ if result == 1 {
+ return true, nil
+ }
+ return false, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSetAutostart
+func (d *Domain) SetAutostart(autostart bool) error {
+ var cAutostart C.int
+ switch autostart {
+ case true:
+ cAutostart = 1
+ default:
+ cAutostart = 0
+ }
+ var err C.virError
+ result := C.virDomainSetAutostartWrapper(d.ptr, cAutostart, &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetAutostart
+func (d *Domain) GetAutostart() (bool, error) {
+ var out C.int
+ var err C.virError
+ result := C.virDomainGetAutostartWrapper(d.ptr, (*C.int)(unsafe.Pointer(&out)), &err)
+ if result == -1 {
+ return false, makeError(&err)
+ }
+ switch out {
+ case 1:
+ return true, nil
+ default:
+ return false, nil
+ }
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetBlockInfo
+func (d *Domain) GetBlockInfo(disk string, flag uint) (*DomainBlockInfo, error) {
+ var cinfo C.virDomainBlockInfo
+ cDisk := C.CString(disk)
+ defer C.free(unsafe.Pointer(cDisk))
+ var err C.virError
+ result := C.virDomainGetBlockInfoWrapper(d.ptr, cDisk, &cinfo, C.uint(flag), &err)
+ if result == -1 {
+ return nil, makeError(&err)
+ }
+
+ return &DomainBlockInfo{
+ Capacity: uint64(cinfo.capacity),
+ Allocation: uint64(cinfo.allocation),
+ Physical: uint64(cinfo.physical),
+ }, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetName
+func (d *Domain) GetName() (string, error) {
+ var err C.virError
+ name := C.virDomainGetNameWrapper(d.ptr, &err)
+ if name == nil {
+ return "", makeError(&err)
+ }
+ return C.GoString(name), nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetState
+func (d *Domain) GetState() (DomainState, int, error) {
+ var cState C.int
+ var cReason C.int
+ var err C.virError
+ result := C.virDomainGetStateWrapper(d.ptr,
+ (*C.int)(unsafe.Pointer(&cState)),
+ (*C.int)(unsafe.Pointer(&cReason)),
+ 0, &err)
+ if int(result) == -1 {
+ return 0, 0, makeError(&err)
+ }
+ return DomainState(cState), int(cReason), nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetID
+func (d *Domain) GetID() (uint, error) {
+ var err C.virError
+ id := uint(C.virDomainGetIDWrapper(d.ptr, &err))
+ if id == ^uint(0) {
+ return id, makeError(&err)
+ }
+ return id, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetUUID
+func (d *Domain) GetUUID() ([]byte, error) {
+ var cUuid [C.VIR_UUID_BUFLEN](byte)
+ cuidPtr := unsafe.Pointer(&cUuid)
+ var err C.virError
+ result := C.virDomainGetUUIDWrapper(d.ptr, (*C.uchar)(cuidPtr), &err)
+ if result != 0 {
+ return []byte{}, makeError(&err)
+ }
+ return C.GoBytes(cuidPtr, C.VIR_UUID_BUFLEN), nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetUUIDString
+func (d *Domain) GetUUIDString() (string, error) {
+ var cUuid [C.VIR_UUID_STRING_BUFLEN](C.char)
+ cuidPtr := unsafe.Pointer(&cUuid)
+ var err C.virError
+ result := C.virDomainGetUUIDStringWrapper(d.ptr, (*C.char)(cuidPtr), &err)
+ if result != 0 {
+ return "", makeError(&err)
+ }
+ return C.GoString((*C.char)(cuidPtr)), nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetInfo
+func (d *Domain) GetInfo() (*DomainInfo, error) {
+ var cinfo C.virDomainInfo
+ var err C.virError
+ result := C.virDomainGetInfoWrapper(d.ptr, &cinfo, &err)
+ if result == -1 {
+ return nil, makeError(&err)
+ }
+ return &DomainInfo{
+ State: DomainState(cinfo.state),
+ MaxMem: uint64(cinfo.maxMem),
+ Memory: uint64(cinfo.memory),
+ NrVirtCpu: uint(cinfo.nrVirtCpu),
+ CpuTime: uint64(cinfo.cpuTime),
+ }, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetXMLDesc
+func (d *Domain) GetXMLDesc(flags DomainXMLFlags) (string, error) {
+ var err C.virError
+ result := C.virDomainGetXMLDescWrapper(d.ptr, C.uint(flags), &err)
+ if result == nil {
+ return "", makeError(&err)
+ }
+ xml := C.GoString(result)
+ C.free(unsafe.Pointer(result))
+ return xml, nil
+}
+
+type DomainCPUStats struct {
+ CpuTimeSet bool
+ CpuTime uint64
+ UserTimeSet bool
+ UserTime uint64
+ SystemTimeSet bool
+ SystemTime uint64
+ VcpuTimeSet bool
+ VcpuTime uint64
+}
+
+func getCPUStatsFieldInfo(params *DomainCPUStats) map[string]typedParamsFieldInfo {
+ return map[string]typedParamsFieldInfo{
+ C.VIR_DOMAIN_CPU_STATS_CPUTIME: typedParamsFieldInfo{
+ set: &params.CpuTimeSet,
+ ul: &params.CpuTime,
+ },
+ C.VIR_DOMAIN_CPU_STATS_USERTIME: typedParamsFieldInfo{
+ set: &params.UserTimeSet,
+ ul: &params.UserTime,
+ },
+ C.VIR_DOMAIN_CPU_STATS_SYSTEMTIME: typedParamsFieldInfo{
+ set: &params.SystemTimeSet,
+ ul: &params.SystemTime,
+ },
+ C.VIR_DOMAIN_CPU_STATS_VCPUTIME: typedParamsFieldInfo{
+ set: &params.VcpuTimeSet,
+ ul: &params.VcpuTime,
+ },
+ }
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetCPUStats
+func (d *Domain) GetCPUStats(startCpu int, nCpus uint, flags uint32) ([]DomainCPUStats, error) {
+ var err C.virError
+ if nCpus == 0 {
+ if startCpu == -1 {
+ nCpus = 1
+ } else {
+ ret := C.virDomainGetCPUStatsWrapper(d.ptr, nil, 0, 0, 0, 0, &err)
+ if ret == -1 {
+ return []DomainCPUStats{}, makeError(&err)
+ }
+ nCpus = uint(ret)
+ }
+ }
+
+ ret := C.virDomainGetCPUStatsWrapper(d.ptr, nil, 0, C.int(startCpu), C.uint(nCpus), 0, &err)
+ if ret == -1 {
+ return []DomainCPUStats{}, makeError(&err)
+ }
+ nparams := uint(ret)
+
+ var cparams []C.virTypedParameter
+ var nallocparams uint
+ if startCpu == -1 {
+ nallocparams = nparams
+ } else {
+ nallocparams = nparams * nCpus
+ }
+ cparams = make([]C.virTypedParameter, nallocparams)
+ ret = C.virDomainGetCPUStatsWrapper(d.ptr, (*C.virTypedParameter)(unsafe.Pointer(&cparams[0])), C.uint(nparams), C.int(startCpu), C.uint(nCpus), C.uint(flags), &err)
+ if ret == -1 {
+ return []DomainCPUStats{}, makeError(&err)
+ }
+
+ defer C.virTypedParamsClear((*C.virTypedParameter)(unsafe.Pointer(&cparams[0])), C.int(nallocparams))
+
+ stats := make([]DomainCPUStats, nCpus)
+ for i := 0; i < int(nCpus); i++ {
+ offset := i * int(nparams)
+ info := getCPUStatsFieldInfo(&stats[i])
+ cparamscpu := cparams[offset : offset+int(ret)]
+ _, gerr := typedParamsUnpack(cparamscpu, info)
+ if gerr != nil {
+ return []DomainCPUStats{}, gerr
+ }
+ }
+ return stats, nil
+}
+
+type DomainInterfaceParameters struct {
+ BandwidthInAverageSet bool
+ BandwidthInAverage uint
+ BandwidthInPeakSet bool
+ BandwidthInPeak uint
+ BandwidthInBurstSet bool
+ BandwidthInBurst uint
+ BandwidthInFloorSet bool
+ BandwidthInFloor uint
+ BandwidthOutAverageSet bool
+ BandwidthOutAverage uint
+ BandwidthOutPeakSet bool
+ BandwidthOutPeak uint
+ BandwidthOutBurstSet bool
+ BandwidthOutBurst uint
+}
+
+func getInterfaceParameterFieldInfo(params *DomainInterfaceParameters) map[string]typedParamsFieldInfo {
+ return map[string]typedParamsFieldInfo{
+ C.VIR_DOMAIN_BANDWIDTH_IN_AVERAGE: typedParamsFieldInfo{
+ set: &params.BandwidthInAverageSet,
+ ui: &params.BandwidthInAverage,
+ },
+ C.VIR_DOMAIN_BANDWIDTH_IN_PEAK: typedParamsFieldInfo{
+ set: &params.BandwidthInPeakSet,
+ ui: &params.BandwidthInPeak,
+ },
+ C.VIR_DOMAIN_BANDWIDTH_IN_BURST: typedParamsFieldInfo{
+ set: &params.BandwidthInBurstSet,
+ ui: &params.BandwidthInBurst,
+ },
+ C.VIR_DOMAIN_BANDWIDTH_IN_FLOOR: typedParamsFieldInfo{
+ set: &params.BandwidthInFloorSet,
+ ui: &params.BandwidthInFloor,
+ },
+ C.VIR_DOMAIN_BANDWIDTH_OUT_AVERAGE: typedParamsFieldInfo{
+ set: &params.BandwidthOutAverageSet,
+ ui: &params.BandwidthOutAverage,
+ },
+ C.VIR_DOMAIN_BANDWIDTH_OUT_PEAK: typedParamsFieldInfo{
+ set: &params.BandwidthOutPeakSet,
+ ui: &params.BandwidthOutPeak,
+ },
+ C.VIR_DOMAIN_BANDWIDTH_OUT_BURST: typedParamsFieldInfo{
+ set: &params.BandwidthOutBurstSet,
+ ui: &params.BandwidthOutBurst,
+ },
+ }
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetInterfaceParameters
+func (d *Domain) GetInterfaceParameters(device string, flags DomainModificationImpact) (*DomainInterfaceParameters, error) {
+ params := &DomainInterfaceParameters{}
+ info := getInterfaceParameterFieldInfo(params)
+
+ var nparams C.int
+
+ cdevice := C.CString(device)
+ defer C.free(unsafe.Pointer(cdevice))
+ var err C.virError
+ ret := C.virDomainGetInterfaceParametersWrapper(d.ptr, cdevice, nil, &nparams, C.uint(0), &err)
+ if ret == -1 {
+ return nil, makeError(&err)
+ }
+
+ cparams := make([]C.virTypedParameter, nparams)
+ ret = C.virDomainGetInterfaceParametersWrapper(d.ptr, cdevice, (*C.virTypedParameter)(unsafe.Pointer(&cparams[0])), &nparams, C.uint(flags), &err)
+ if ret == -1 {
+ return nil, makeError(&err)
+ }
+
+ defer C.virTypedParamsClear((*C.virTypedParameter)(unsafe.Pointer(&cparams[0])), nparams)
+
+ _, gerr := typedParamsUnpack(cparams, info)
+ if gerr != nil {
+ return nil, gerr
+ }
+
+ return params, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSetInterfaceParameters
+func (d *Domain) SetInterfaceParameters(device string, params *DomainInterfaceParameters, flags DomainModificationImpact) error {
+ info := getInterfaceParameterFieldInfo(params)
+
+ var nparams C.int
+
+ cdevice := C.CString(device)
+ defer C.free(unsafe.Pointer(cdevice))
+ var err C.virError
+ ret := C.virDomainGetInterfaceParametersWrapper(d.ptr, cdevice, nil, &nparams, 0, &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+
+ cparams := make([]C.virTypedParameter, nparams)
+ ret = C.virDomainGetInterfaceParametersWrapper(d.ptr, cdevice, (*C.virTypedParameter)(unsafe.Pointer(&cparams[0])), &nparams, 0, &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+
+ defer C.virTypedParamsClear((*C.virTypedParameter)(unsafe.Pointer(&cparams[0])), nparams)
+
+ gerr := typedParamsPack(cparams, info)
+ if gerr != nil {
+ return gerr
+ }
+
+ ret = C.virDomainSetInterfaceParametersWrapper(d.ptr, cdevice, (*C.virTypedParameter)(unsafe.Pointer(&cparams[0])), nparams, C.uint(flags), &err)
+
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetMetadata
+func (d *Domain) GetMetadata(tipus DomainMetadataType, uri string, flags DomainModificationImpact) (string, error) {
+ var cUri *C.char
+ if uri != "" {
+ cUri = C.CString(uri)
+ defer C.free(unsafe.Pointer(cUri))
+ }
+
+ var err C.virError
+ result := C.virDomainGetMetadataWrapper(d.ptr, C.int(tipus), cUri, C.uint(flags), &err)
+ if result == nil {
+ return "", makeError(&err)
+
+ }
+ defer C.free(unsafe.Pointer(result))
+ return C.GoString(result), nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSetMetadata
+func (d *Domain) SetMetadata(metaDataType DomainMetadataType, metaDataCont, uriKey, uri string, flags DomainModificationImpact) error {
+ var cMetaDataCont *C.char
+ var cUriKey *C.char
+ var cUri *C.char
+
+ if metaDataCont != "" {
+ cMetaDataCont = C.CString(metaDataCont)
+ defer C.free(unsafe.Pointer(cMetaDataCont))
+ }
+
+ if metaDataType == DOMAIN_METADATA_ELEMENT {
+ if uriKey != "" {
+ cUriKey = C.CString(uriKey)
+ defer C.free(unsafe.Pointer(cUriKey))
+ }
+ cUri = C.CString(uri)
+ defer C.free(unsafe.Pointer(cUri))
+ }
+ var err C.virError
+ result := C.virDomainSetMetadataWrapper(d.ptr, C.int(metaDataType), cMetaDataCont, cUriKey, cUri, C.uint(flags), &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainUndefine
+func (d *Domain) Undefine() error {
+ var err C.virError
+ result := C.virDomainUndefineWrapper(d.ptr, &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainUndefineFlags
+func (d *Domain) UndefineFlags(flags DomainUndefineFlagsValues) error {
+ var err C.virError
+ result := C.virDomainUndefineFlagsWrapper(d.ptr, C.uint(flags), &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSetMaxMemory
+func (d *Domain) SetMaxMemory(memory uint) error {
+ var err C.virError
+ result := C.virDomainSetMaxMemoryWrapper(d.ptr, C.ulong(memory), &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSetMemory
+func (d *Domain) SetMemory(memory uint64) error {
+ var err C.virError
+ result := C.virDomainSetMemoryWrapper(d.ptr, C.ulong(memory), &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSetMemoryFlags
+func (d *Domain) SetMemoryFlags(memory uint64, flags DomainMemoryModFlags) error {
+ var err C.virError
+ result := C.virDomainSetMemoryFlagsWrapper(d.ptr, C.ulong(memory), C.uint(flags), &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSetMemoryStatsPeriod
+func (d *Domain) SetMemoryStatsPeriod(period int, flags DomainMemoryModFlags) error {
+ var err C.virError
+ result := C.virDomainSetMemoryStatsPeriodWrapper(d.ptr, C.int(period), C.uint(flags), &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSetVcpus
+func (d *Domain) SetVcpus(vcpu uint) error {
+ var err C.virError
+ result := C.virDomainSetVcpusWrapper(d.ptr, C.uint(vcpu), &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSetVcpusFlags
+func (d *Domain) SetVcpusFlags(vcpu uint, flags DomainVcpuFlags) error {
+ var err C.virError
+ result := C.virDomainSetVcpusFlagsWrapper(d.ptr, C.uint(vcpu), C.uint(flags), &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSuspend
+func (d *Domain) Suspend() error {
+ var err C.virError
+ result := C.virDomainSuspendWrapper(d.ptr, &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainResume
+func (d *Domain) Resume() error {
+ var err C.virError
+ result := C.virDomainResumeWrapper(d.ptr, &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainAbortJob
+func (d *Domain) AbortJob() error {
+ var err C.virError
+ result := C.virDomainAbortJobWrapper(d.ptr, &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainDestroyFlags
+func (d *Domain) DestroyFlags(flags DomainDestroyFlags) error {
+ var err C.virError
+ result := C.virDomainDestroyFlagsWrapper(d.ptr, C.uint(flags), &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainShutdownFlags
+func (d *Domain) ShutdownFlags(flags DomainShutdownFlags) error {
+ var err C.virError
+ result := C.virDomainShutdownFlagsWrapper(d.ptr, C.uint(flags), &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainAttachDevice
+func (d *Domain) AttachDevice(xml string) error {
+ cXml := C.CString(xml)
+ defer C.free(unsafe.Pointer(cXml))
+ var err C.virError
+ result := C.virDomainAttachDeviceWrapper(d.ptr, cXml, &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainAttachDeviceFlags
+func (d *Domain) AttachDeviceFlags(xml string, flags DomainDeviceModifyFlags) error {
+ cXml := C.CString(xml)
+ defer C.free(unsafe.Pointer(cXml))
+ var err C.virError
+ result := C.virDomainAttachDeviceFlagsWrapper(d.ptr, cXml, C.uint(flags), &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainDetachDevice
+func (d *Domain) DetachDevice(xml string) error {
+ cXml := C.CString(xml)
+ defer C.free(unsafe.Pointer(cXml))
+ var err C.virError
+ result := C.virDomainDetachDeviceWrapper(d.ptr, cXml, &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainDetachDeviceFlags
+func (d *Domain) DetachDeviceFlags(xml string, flags DomainDeviceModifyFlags) error {
+ cXml := C.CString(xml)
+ defer C.free(unsafe.Pointer(cXml))
+ var err C.virError
+ result := C.virDomainDetachDeviceFlagsWrapper(d.ptr, cXml, C.uint(flags), &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainDetachDeviceAlias
+func (d *Domain) DetachDeviceAlias(alias string, flags DomainDeviceModifyFlags) error {
+ if C.LIBVIR_VERSION_NUMBER < 4004000 {
+ return makeNotImplementedError("virDomainDetachDeviceAlias")
+ }
+
+ cAlias := C.CString(alias)
+ defer C.free(unsafe.Pointer(cAlias))
+ var err C.virError
+ result := C.virDomainDetachDeviceAliasWrapper(d.ptr, cAlias, C.uint(flags), &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainUpdateDeviceFlags
+func (d *Domain) UpdateDeviceFlags(xml string, flags DomainDeviceModifyFlags) error {
+ cXml := C.CString(xml)
+ defer C.free(unsafe.Pointer(cXml))
+ var err C.virError
+ result := C.virDomainUpdateDeviceFlagsWrapper(d.ptr, cXml, C.uint(flags), &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainScreenshot
+func (d *Domain) Screenshot(stream *Stream, screen, flags uint32) (string, error) {
+ var err C.virError
+ cType := C.virDomainScreenshotWrapper(d.ptr, stream.ptr, C.uint(screen), C.uint(flags), &err)
+ if cType == nil {
+ return "", makeError(&err)
+ }
+ defer C.free(unsafe.Pointer(cType))
+
+ mimeType := C.GoString(cType)
+ return mimeType, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSendKey
+func (d *Domain) SendKey(codeset, holdtime uint, keycodes []uint, flags uint32) error {
+ var err C.virError
+ result := C.virDomainSendKeyWrapper(d.ptr, C.uint(codeset), C.uint(holdtime), (*C.uint)(unsafe.Pointer(&keycodes[0])), C.int(len(keycodes)), C.uint(flags), &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+
+ return nil
+}
+
+type DomainBlockStats struct {
+ RdBytesSet bool
+ RdBytes int64
+ RdReqSet bool
+ RdReq int64
+ RdTotalTimesSet bool
+ RdTotalTimes int64
+ WrBytesSet bool
+ WrBytes int64
+ WrReqSet bool
+ WrReq int64
+ WrTotalTimesSet bool
+ WrTotalTimes int64
+ FlushReqSet bool
+ FlushReq int64
+ FlushTotalTimesSet bool
+ FlushTotalTimes int64
+ ErrsSet bool
+ Errs int64
+}
+
+func getBlockStatsFieldInfo(params *DomainBlockStats) map[string]typedParamsFieldInfo {
+ return map[string]typedParamsFieldInfo{
+ C.VIR_DOMAIN_BLOCK_STATS_READ_BYTES: typedParamsFieldInfo{
+ set: &params.RdBytesSet,
+ l: &params.RdBytes,
+ },
+ C.VIR_DOMAIN_BLOCK_STATS_READ_REQ: typedParamsFieldInfo{
+ set: &params.RdReqSet,
+ l: &params.RdReq,
+ },
+ C.VIR_DOMAIN_BLOCK_STATS_READ_TOTAL_TIMES: typedParamsFieldInfo{
+ set: &params.RdTotalTimesSet,
+ l: &params.RdTotalTimes,
+ },
+ C.VIR_DOMAIN_BLOCK_STATS_WRITE_BYTES: typedParamsFieldInfo{
+ set: &params.WrBytesSet,
+ l: &params.WrBytes,
+ },
+ C.VIR_DOMAIN_BLOCK_STATS_WRITE_REQ: typedParamsFieldInfo{
+ set: &params.WrReqSet,
+ l: &params.WrReq,
+ },
+ C.VIR_DOMAIN_BLOCK_STATS_WRITE_TOTAL_TIMES: typedParamsFieldInfo{
+ set: &params.WrTotalTimesSet,
+ l: &params.WrTotalTimes,
+ },
+ C.VIR_DOMAIN_BLOCK_STATS_FLUSH_REQ: typedParamsFieldInfo{
+ set: &params.FlushReqSet,
+ l: &params.FlushReq,
+ },
+ C.VIR_DOMAIN_BLOCK_STATS_FLUSH_TOTAL_TIMES: typedParamsFieldInfo{
+ set: &params.FlushTotalTimesSet,
+ l: &params.FlushTotalTimes,
+ },
+ C.VIR_DOMAIN_BLOCK_STATS_ERRS: typedParamsFieldInfo{
+ set: &params.ErrsSet,
+ l: &params.Errs,
+ },
+ }
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainBlockStatsFlags
+func (d *Domain) BlockStatsFlags(disk string, flags uint32) (*DomainBlockStats, error) {
+ params := &DomainBlockStats{}
+ info := getBlockStatsFieldInfo(params)
+
+ var nparams C.int
+
+ cdisk := C.CString(disk)
+ defer C.free(unsafe.Pointer(cdisk))
+ var err C.virError
+ ret := C.virDomainBlockStatsFlagsWrapper(d.ptr, cdisk, nil, &nparams, C.uint(0), &err)
+ if ret == -1 {
+ return nil, makeError(&err)
+ }
+
+ cparams := make([]C.virTypedParameter, nparams)
+ ret = C.virDomainBlockStatsFlagsWrapper(d.ptr, cdisk, (*C.virTypedParameter)(unsafe.Pointer(&cparams[0])), &nparams, C.uint(flags), &err)
+ if ret == -1 {
+ return nil, makeError(&err)
+ }
+
+ defer C.virTypedParamsClear((*C.virTypedParameter)(unsafe.Pointer(&cparams[0])), nparams)
+
+ _, gerr := typedParamsUnpack(cparams, info)
+ if gerr != nil {
+ return nil, gerr
+ }
+
+ return params, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainBlockStats
+func (d *Domain) BlockStats(path string) (*DomainBlockStats, error) {
+ cPath := C.CString(path)
+ defer C.free(unsafe.Pointer(cPath))
+
+ size := C.size_t(unsafe.Sizeof(C.struct__virDomainBlockStats{}))
+
+ cStats := (C.virDomainBlockStatsPtr)(C.malloc(size))
+ defer C.free(unsafe.Pointer(cStats))
+
+ var err C.virError
+ result := C.virDomainBlockStatsWrapper(d.ptr, cPath, (C.virDomainBlockStatsPtr)(cStats), size, &err)
+
+ if result != 0 {
+ return nil, makeError(&err)
+ }
+ return &DomainBlockStats{
+ WrReqSet: true,
+ WrReq: int64(cStats.wr_req),
+ RdReqSet: true,
+ RdReq: int64(cStats.rd_req),
+ RdBytesSet: true,
+ RdBytes: int64(cStats.rd_bytes),
+ WrBytesSet: true,
+ WrBytes: int64(cStats.wr_bytes),
+ }, nil
+}
+
+type DomainInterfaceStats struct {
+ RxBytesSet bool
+ RxBytes int64
+ RxPacketsSet bool
+ RxPackets int64
+ RxErrsSet bool
+ RxErrs int64
+ RxDropSet bool
+ RxDrop int64
+ TxBytesSet bool
+ TxBytes int64
+ TxPacketsSet bool
+ TxPackets int64
+ TxErrsSet bool
+ TxErrs int64
+ TxDropSet bool
+ TxDrop int64
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainInterfaceStats
+func (d *Domain) InterfaceStats(path string) (*DomainInterfaceStats, error) {
+ cPath := C.CString(path)
+ defer C.free(unsafe.Pointer(cPath))
+
+ size := C.size_t(unsafe.Sizeof(C.struct__virDomainInterfaceStats{}))
+
+ cStats := (C.virDomainInterfaceStatsPtr)(C.malloc(size))
+ defer C.free(unsafe.Pointer(cStats))
+
+ var err C.virError
+ result := C.virDomainInterfaceStatsWrapper(d.ptr, cPath, (C.virDomainInterfaceStatsPtr)(cStats), size, &err)
+
+ if result != 0 {
+ return nil, makeError(&err)
+ }
+ return &DomainInterfaceStats{
+ RxBytesSet: true,
+ RxBytes: int64(cStats.rx_bytes),
+ RxPacketsSet: true,
+ RxPackets: int64(cStats.rx_packets),
+ RxErrsSet: true,
+ RxErrs: int64(cStats.rx_errs),
+ RxDropSet: true,
+ RxDrop: int64(cStats.rx_drop),
+ TxBytesSet: true,
+ TxBytes: int64(cStats.tx_bytes),
+ TxPacketsSet: true,
+ TxPackets: int64(cStats.tx_packets),
+ TxErrsSet: true,
+ TxErrs: int64(cStats.tx_errs),
+ TxDropSet: true,
+ TxDrop: int64(cStats.tx_drop),
+ }, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainMemoryStats
+func (d *Domain) MemoryStats(nrStats uint32, flags uint32) ([]DomainMemoryStat, error) {
+ ptr := make([]C.virDomainMemoryStatStruct, nrStats)
+
+ var err C.virError
+ result := C.virDomainMemoryStatsWrapper(
+ d.ptr, (C.virDomainMemoryStatPtr)(unsafe.Pointer(&ptr[0])),
+ C.uint(nrStats), C.uint(flags), &err)
+
+ if result == -1 {
+ return []DomainMemoryStat{}, makeError(&err)
+ }
+
+ out := make([]DomainMemoryStat, 0)
+ for i := 0; i < int(result); i++ {
+ out = append(out, DomainMemoryStat{
+ Tag: int32(ptr[i].tag),
+ Val: uint64(ptr[i].val),
+ })
+ }
+ return out, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetConnect
+//
+// Contrary to the native C API behaviour, the Go API will
+// acquire a reference on the returned Connect, which must
+// be released by calling Close()
+func (d *Domain) DomainGetConnect() (*Connect, error) {
+ var err C.virError
+ ptr := C.virDomainGetConnectWrapper(d.ptr, &err)
+ if ptr == nil {
+ return nil, makeError(&err)
+ }
+
+ ret := C.virConnectRefWrapper(ptr, &err)
+ if ret == -1 {
+ return nil, makeError(&err)
+ }
+
+ return &Connect{ptr: ptr}, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetVcpus
+func (d *Domain) GetVcpus() ([]DomainVcpuInfo, error) {
+ var cnodeinfo C.virNodeInfo
+ var err C.virError
+ ret := C.virNodeGetInfoWrapper(C.virDomainGetConnect(d.ptr), &cnodeinfo, &err)
+ if ret == -1 {
+ return []DomainVcpuInfo{}, makeError(&err)
+ }
+
+ var cdominfo C.virDomainInfo
+ ret = C.virDomainGetInfoWrapper(d.ptr, &cdominfo, &err)
+ if ret == -1 {
+ return []DomainVcpuInfo{}, makeError(&err)
+ }
+
+ nvcpus := int(cdominfo.nrVirtCpu)
+ npcpus := int(cnodeinfo.nodes * cnodeinfo.sockets * cnodeinfo.cores * cnodeinfo.threads)
+ maplen := ((npcpus + 7) / 8)
+ ccpumaps := make([]C.uchar, maplen*nvcpus)
+ cinfo := make([]C.virVcpuInfo, nvcpus)
+
+ ret = C.virDomainGetVcpusWrapper(d.ptr, &cinfo[0], C.int(nvcpus), &ccpumaps[0], C.int(maplen), &err)
+ if ret == -1 {
+ return []DomainVcpuInfo{}, makeError(&err)
+ }
+
+ info := make([]DomainVcpuInfo, int(ret))
+ for i := 0; i < int(ret); i++ {
+ affinity := make([]bool, npcpus)
+ for j := 0; j < npcpus; j++ {
+ byte := (i * maplen) + (j / 8)
+ bit := j % 8
+
+ affinity[j] = (ccpumaps[byte] & (1 << uint(bit))) != 0
+ }
+
+ info[i] = DomainVcpuInfo{
+ Number: uint32(cinfo[i].number),
+ State: int32(cinfo[i].state),
+ CpuTime: uint64(cinfo[i].cpuTime),
+ Cpu: int32(cinfo[i].cpu),
+ CpuMap: affinity,
+ }
+ }
+
+ return info, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetVcpusFlags
+func (d *Domain) GetVcpusFlags(flags DomainVcpuFlags) (int32, error) {
+ var err C.virError
+ result := C.virDomainGetVcpusFlagsWrapper(d.ptr, C.uint(flags), &err)
+ if result == -1 {
+ return 0, makeError(&err)
+ }
+ return int32(result), nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainPinVcpu
+func (d *Domain) PinVcpu(vcpu uint, cpuMap []bool) error {
+ maplen := (len(cpuMap) + 7) / 8
+ ccpumap := make([]C.uchar, maplen)
+ for i := 0; i < len(cpuMap); i++ {
+ if cpuMap[i] {
+ byte := i / 8
+ bit := i % 8
+ ccpumap[byte] |= (1 << uint(bit))
+ }
+ }
+
+ var err C.virError
+ result := C.virDomainPinVcpuWrapper(d.ptr, C.uint(vcpu), &ccpumap[0], C.int(maplen), &err)
+
+ if result == -1 {
+ return makeError(&err)
+ }
+
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainPinVcpuFlags
+func (d *Domain) PinVcpuFlags(vcpu uint, cpuMap []bool, flags DomainModificationImpact) error {
+ maplen := (len(cpuMap) + 7) / 8
+ ccpumap := make([]C.uchar, maplen)
+ for i := 0; i < len(cpuMap); i++ {
+ if cpuMap[i] {
+ byte := i / 8
+ bit := i % 8
+ ccpumap[byte] |= (1 << uint(bit))
+ }
+ }
+
+ var err C.virError
+ result := C.virDomainPinVcpuFlagsWrapper(d.ptr, C.uint(vcpu), &ccpumap[0], C.int(maplen), C.uint(flags), &err)
+
+ if result == -1 {
+ return makeError(&err)
+ }
+
+ return nil
+}
+
+type DomainIPAddress struct {
+ Type int
+ Addr string
+ Prefix uint
+}
+
+type DomainInterface struct {
+ Name string
+ Hwaddr string
+ Addrs []DomainIPAddress
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainInterfaceAddresses
+func (d *Domain) ListAllInterfaceAddresses(src DomainInterfaceAddressesSource) ([]DomainInterface, error) {
+ if C.LIBVIR_VERSION_NUMBER < 1002014 {
+ return []DomainInterface{}, makeNotImplementedError("virDomainInterfaceAddresses")
+ }
+
+ var cList *C.virDomainInterfacePtr
+ var err C.virError
+ numIfaces := int(C.virDomainInterfaceAddressesWrapper(d.ptr, (**C.virDomainInterfacePtr)(&cList), C.uint(src), 0, &err))
+ if numIfaces == -1 {
+ return nil, makeError(&err)
+ }
+
+ ifaces := make([]DomainInterface, numIfaces)
+
+ for i := 0; i < numIfaces; i++ {
+ var ciface *C.virDomainInterface
+ ciface = *(**C.virDomainInterface)(unsafe.Pointer(uintptr(unsafe.Pointer(cList)) + (unsafe.Sizeof(ciface) * uintptr(i))))
+
+ ifaces[i].Name = C.GoString(ciface.name)
+ ifaces[i].Hwaddr = C.GoString(ciface.hwaddr)
+
+ numAddr := int(ciface.naddrs)
+
+ ifaces[i].Addrs = make([]DomainIPAddress, numAddr)
+
+ for k := 0; k < numAddr; k++ {
+ var caddr *C.virDomainIPAddress
+ caddr = (*C.virDomainIPAddress)(unsafe.Pointer(uintptr(unsafe.Pointer(ciface.addrs)) + (unsafe.Sizeof(*caddr) * uintptr(k))))
+ ifaces[i].Addrs[k] = DomainIPAddress{}
+ ifaces[i].Addrs[k].Type = int(caddr._type)
+ ifaces[i].Addrs[k].Addr = C.GoString(caddr.addr)
+ ifaces[i].Addrs[k].Prefix = uint(caddr.prefix)
+
+ }
+ C.virDomainInterfaceFreeWrapper(ciface)
+ }
+ C.free(unsafe.Pointer(cList))
+ return ifaces, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain-snapshot.html#virDomainSnapshotCurrent
+func (d *Domain) SnapshotCurrent(flags uint32) (*DomainSnapshot, error) {
+ var err C.virError
+ result := C.virDomainSnapshotCurrentWrapper(d.ptr, C.uint(flags), &err)
+ if result == nil {
+ return nil, makeError(&err)
+ }
+ return &DomainSnapshot{ptr: result}, nil
+
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain-snapshot.html#virDomainSnapshotNum
+func (d *Domain) SnapshotNum(flags DomainSnapshotListFlags) (int, error) {
+ var err C.virError
+ result := int(C.virDomainSnapshotNumWrapper(d.ptr, C.uint(flags), &err))
+ if result == -1 {
+ return 0, makeError(&err)
+ }
+ return result, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain-snapshot.html#virDomainSnapshotLookupByName
+func (d *Domain) SnapshotLookupByName(name string, flags uint32) (*DomainSnapshot, error) {
+ cName := C.CString(name)
+ defer C.free(unsafe.Pointer(cName))
+ var err C.virError
+ ptr := C.virDomainSnapshotLookupByNameWrapper(d.ptr, cName, C.uint(flags), &err)
+ if ptr == nil {
+ return nil, makeError(&err)
+ }
+ return &DomainSnapshot{ptr: ptr}, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain-snapshot.html#virDomainSnapshotListNames
+func (d *Domain) SnapshotListNames(flags DomainSnapshotListFlags) ([]string, error) {
+ const maxNames = 1024
+ var names [maxNames](*C.char)
+ namesPtr := unsafe.Pointer(&names)
+ var err C.virError
+ numNames := C.virDomainSnapshotListNamesWrapper(
+ d.ptr,
+ (**C.char)(namesPtr),
+ maxNames, C.uint(flags), &err)
+ if numNames == -1 {
+ return nil, makeError(&err)
+ }
+ goNames := make([]string, numNames)
+ for k := 0; k < int(numNames); k++ {
+ goNames[k] = C.GoString(names[k])
+ C.free(unsafe.Pointer(names[k]))
+ }
+ return goNames, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain-snapshot.html#virDomainListAllSnapshots
+func (d *Domain) ListAllSnapshots(flags DomainSnapshotListFlags) ([]DomainSnapshot, error) {
+ var cList *C.virDomainSnapshotPtr
+ var err C.virError
+ numVols := C.virDomainListAllSnapshotsWrapper(d.ptr, (**C.virDomainSnapshotPtr)(&cList), C.uint(flags), &err)
+ if numVols == -1 {
+ return nil, makeError(&err)
+ }
+ hdr := reflect.SliceHeader{
+ Data: uintptr(unsafe.Pointer(cList)),
+ Len: int(numVols),
+ Cap: int(numVols),
+ }
+ var pools []DomainSnapshot
+ slice := *(*[]C.virDomainSnapshotPtr)(unsafe.Pointer(&hdr))
+ for _, ptr := range slice {
+ pools = append(pools, DomainSnapshot{ptr})
+ }
+ C.free(unsafe.Pointer(cList))
+ return pools, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainBlockCommit
+func (d *Domain) BlockCommit(disk string, base string, top string, bandwidth uint64, flags DomainBlockCommitFlags) error {
+ cdisk := C.CString(disk)
+ defer C.free(unsafe.Pointer(cdisk))
+ var cbase *C.char
+ if base != "" {
+ cbase = C.CString(base)
+ defer C.free(unsafe.Pointer(cbase))
+ }
+ var ctop *C.char
+ if top != "" {
+ ctop = C.CString(top)
+ defer C.free(unsafe.Pointer(ctop))
+ }
+ var err C.virError
+ ret := C.virDomainBlockCommitWrapper(d.ptr, cdisk, cbase, ctop, C.ulong(bandwidth), C.uint(flags), &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+type DomainBlockCopyParameters struct {
+ BandwidthSet bool
+ Bandwidth uint64
+ GranularitySet bool
+ Granularity uint
+ BufSizeSet bool
+ BufSize uint64
+}
+
+func getBlockCopyParameterFieldInfo(params *DomainBlockCopyParameters) map[string]typedParamsFieldInfo {
+ return map[string]typedParamsFieldInfo{
+ C.VIR_DOMAIN_BLOCK_COPY_BANDWIDTH: typedParamsFieldInfo{
+ set: &params.BandwidthSet,
+ ul: &params.Bandwidth,
+ },
+ C.VIR_DOMAIN_BLOCK_COPY_GRANULARITY: typedParamsFieldInfo{
+ set: &params.GranularitySet,
+ ui: &params.Granularity,
+ },
+ C.VIR_DOMAIN_BLOCK_COPY_BUF_SIZE: typedParamsFieldInfo{
+ set: &params.BufSizeSet,
+ ul: &params.BufSize,
+ },
+ }
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainBlockCopy
+func (d *Domain) BlockCopy(disk string, destxml string, params *DomainBlockCopyParameters, flags DomainBlockCopyFlags) error {
+ if C.LIBVIR_VERSION_NUMBER < 1002008 {
+ return makeNotImplementedError("virDomainBlockCopy")
+ }
+ cdisk := C.CString(disk)
+ defer C.free(unsafe.Pointer(cdisk))
+ cdestxml := C.CString(destxml)
+ defer C.free(unsafe.Pointer(cdestxml))
+
+ info := getBlockCopyParameterFieldInfo(params)
+
+ cparams, gerr := typedParamsPackNew(info)
+ if gerr != nil {
+ return gerr
+ }
+ nparams := len(*cparams)
+
+ defer C.virTypedParamsClear((*C.virTypedParameter)(unsafe.Pointer(&(*cparams)[0])), C.int(nparams))
+
+ var err C.virError
+ ret := C.virDomainBlockCopyWrapper(d.ptr, cdisk, cdestxml, (*C.virTypedParameter)(unsafe.Pointer(&(*cparams)[0])), C.int(nparams), C.uint(flags), &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainBlockJobAbort
+func (d *Domain) BlockJobAbort(disk string, flags DomainBlockJobAbortFlags) error {
+ cdisk := C.CString(disk)
+ defer C.free(unsafe.Pointer(cdisk))
+ var err C.virError
+ ret := C.virDomainBlockJobAbortWrapper(d.ptr, cdisk, C.uint(flags), &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainBlockJobSetSpeed
+func (d *Domain) BlockJobSetSpeed(disk string, bandwidth uint64, flags DomainBlockJobSetSpeedFlags) error {
+ cdisk := C.CString(disk)
+ defer C.free(unsafe.Pointer(cdisk))
+ var err C.virError
+ ret := C.virDomainBlockJobSetSpeedWrapper(d.ptr, cdisk, C.ulong(bandwidth), C.uint(flags), &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainBlockPull
+func (d *Domain) BlockPull(disk string, bandwidth uint64, flags DomainBlockPullFlags) error {
+ cdisk := C.CString(disk)
+ defer C.free(unsafe.Pointer(cdisk))
+ var err C.virError
+ ret := C.virDomainBlockPullWrapper(d.ptr, cdisk, C.ulong(bandwidth), C.uint(flags), &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainBlockRebase
+func (d *Domain) BlockRebase(disk string, base string, bandwidth uint64, flags DomainBlockRebaseFlags) error {
+ cdisk := C.CString(disk)
+ defer C.free(unsafe.Pointer(cdisk))
+ var cbase *C.char
+ if base != "" {
+ cbase := C.CString(base)
+ defer C.free(unsafe.Pointer(cbase))
+ }
+ var err C.virError
+ ret := C.virDomainBlockRebaseWrapper(d.ptr, cdisk, cbase, C.ulong(bandwidth), C.uint(flags), &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainBlockResize
+func (d *Domain) BlockResize(disk string, size uint64, flags DomainBlockResizeFlags) error {
+ cdisk := C.CString(disk)
+ defer C.free(unsafe.Pointer(cdisk))
+ var err C.virError
+ ret := C.virDomainBlockResizeWrapper(d.ptr, cdisk, C.ulonglong(size), C.uint(flags), &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainBlockPeek
+func (d *Domain) BlockPeek(disk string, offset uint64, size uint64, flags uint32) ([]byte, error) {
+ cdisk := C.CString(disk)
+ defer C.free(unsafe.Pointer(cdisk))
+ data := make([]byte, size)
+ var err C.virError
+ ret := C.virDomainBlockPeekWrapper(d.ptr, cdisk, C.ulonglong(offset), C.size_t(size),
+ unsafe.Pointer(&data[0]), C.uint(flags), &err)
+ if ret == -1 {
+ return []byte{}, makeError(&err)
+ }
+
+ return data, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainMemoryPeek
+func (d *Domain) MemoryPeek(start uint64, size uint64, flags DomainMemoryFlags) ([]byte, error) {
+ data := make([]byte, size)
+ var err C.virError
+ ret := C.virDomainMemoryPeekWrapper(d.ptr, C.ulonglong(start), C.size_t(size),
+ unsafe.Pointer(&data[0]), C.uint(flags), &err)
+ if ret == -1 {
+ return []byte{}, makeError(&err)
+ }
+
+ return data, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainMigrate
+func (d *Domain) Migrate(dconn *Connect, flags DomainMigrateFlags, dname string, uri string, bandwidth uint64) (*Domain, error) {
+ var cdname *C.char
+ if dname != "" {
+ cdname = C.CString(dname)
+ defer C.free(unsafe.Pointer(cdname))
+ }
+ var curi *C.char
+ if uri != "" {
+ curi = C.CString(uri)
+ defer C.free(unsafe.Pointer(curi))
+ }
+
+ var err C.virError
+ ret := C.virDomainMigrateWrapper(d.ptr, dconn.ptr, C.ulong(flags), cdname, curi, C.ulong(bandwidth), &err)
+ if ret == nil {
+ return nil, makeError(&err)
+ }
+
+ return &Domain{
+ ptr: ret,
+ }, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainMigrate2
+func (d *Domain) Migrate2(dconn *Connect, dxml string, flags DomainMigrateFlags, dname string, uri string, bandwidth uint64) (*Domain, error) {
+ var cdxml *C.char
+ if dxml != "" {
+ cdxml = C.CString(dxml)
+ defer C.free(unsafe.Pointer(cdxml))
+ }
+ var cdname *C.char
+ if dname != "" {
+ cdname = C.CString(dname)
+ defer C.free(unsafe.Pointer(cdname))
+ }
+ var curi *C.char
+ if uri != "" {
+ curi = C.CString(uri)
+ defer C.free(unsafe.Pointer(curi))
+ }
+
+ var err C.virError
+ ret := C.virDomainMigrate2Wrapper(d.ptr, dconn.ptr, cdxml, C.ulong(flags), cdname, curi, C.ulong(bandwidth), &err)
+ if ret == nil {
+ return nil, makeError(&err)
+ }
+
+ return &Domain{
+ ptr: ret,
+ }, nil
+}
+
+type DomainMigrateParameters struct {
+ URISet bool
+ URI string
+ DestNameSet bool
+ DestName string
+ DestXMLSet bool
+ DestXML string
+ PersistXMLSet bool
+ PersistXML string
+ BandwidthSet bool
+ Bandwidth uint64
+ GraphicsURISet bool
+ GraphicsURI string
+ ListenAddressSet bool
+ ListenAddress string
+ MigrateDisksSet bool
+ MigrateDisks []string
+ DisksPortSet bool
+ DisksPort int
+ CompressionSet bool
+ Compression string
+ CompressionMTLevelSet bool
+ CompressionMTLevel int
+ CompressionMTThreadsSet bool
+ CompressionMTThreads int
+ CompressionMTDThreadsSet bool
+ CompressionMTDThreads int
+ CompressionXBZRLECacheSet bool
+ CompressionXBZRLECache uint64
+ AutoConvergeInitialSet bool
+ AutoConvergeInitial int
+ AutoConvergeIncrementSet bool
+ AutoConvergeIncrement int
+}
+
+func getMigrateParameterFieldInfo(params *DomainMigrateParameters) map[string]typedParamsFieldInfo {
+ return map[string]typedParamsFieldInfo{
+ C.VIR_MIGRATE_PARAM_URI: typedParamsFieldInfo{
+ set: &params.URISet,
+ s: &params.URI,
+ },
+ C.VIR_MIGRATE_PARAM_DEST_NAME: typedParamsFieldInfo{
+ set: &params.DestNameSet,
+ s: &params.DestName,
+ },
+ C.VIR_MIGRATE_PARAM_DEST_XML: typedParamsFieldInfo{
+ set: &params.DestXMLSet,
+ s: &params.DestXML,
+ },
+ C.VIR_MIGRATE_PARAM_PERSIST_XML: typedParamsFieldInfo{
+ set: &params.PersistXMLSet,
+ s: &params.PersistXML,
+ },
+ C.VIR_MIGRATE_PARAM_BANDWIDTH: typedParamsFieldInfo{
+ set: &params.BandwidthSet,
+ ul: &params.Bandwidth,
+ },
+ C.VIR_MIGRATE_PARAM_GRAPHICS_URI: typedParamsFieldInfo{
+ set: &params.GraphicsURISet,
+ s: &params.GraphicsURI,
+ },
+ C.VIR_MIGRATE_PARAM_LISTEN_ADDRESS: typedParamsFieldInfo{
+ set: &params.ListenAddressSet,
+ s: &params.ListenAddress,
+ },
+ C.VIR_MIGRATE_PARAM_MIGRATE_DISKS: typedParamsFieldInfo{
+ set: &params.MigrateDisksSet,
+ sl: &params.MigrateDisks,
+ },
+ C.VIR_MIGRATE_PARAM_DISKS_PORT: typedParamsFieldInfo{
+ set: &params.DisksPortSet,
+ i: &params.DisksPort,
+ },
+ C.VIR_MIGRATE_PARAM_COMPRESSION: typedParamsFieldInfo{
+ set: &params.CompressionSet,
+ s: &params.Compression,
+ },
+ C.VIR_MIGRATE_PARAM_COMPRESSION_MT_LEVEL: typedParamsFieldInfo{
+ set: &params.CompressionMTLevelSet,
+ i: &params.CompressionMTLevel,
+ },
+ C.VIR_MIGRATE_PARAM_COMPRESSION_MT_THREADS: typedParamsFieldInfo{
+ set: &params.CompressionMTThreadsSet,
+ i: &params.CompressionMTThreads,
+ },
+ C.VIR_MIGRATE_PARAM_COMPRESSION_MT_DTHREADS: typedParamsFieldInfo{
+ set: &params.CompressionMTDThreadsSet,
+ i: &params.CompressionMTDThreads,
+ },
+ C.VIR_MIGRATE_PARAM_COMPRESSION_XBZRLE_CACHE: typedParamsFieldInfo{
+ set: &params.CompressionXBZRLECacheSet,
+ ul: &params.CompressionXBZRLECache,
+ },
+ C.VIR_MIGRATE_PARAM_AUTO_CONVERGE_INITIAL: typedParamsFieldInfo{
+ set: &params.AutoConvergeInitialSet,
+ i: &params.AutoConvergeInitial,
+ },
+ C.VIR_MIGRATE_PARAM_AUTO_CONVERGE_INCREMENT: typedParamsFieldInfo{
+ set: &params.AutoConvergeIncrementSet,
+ i: &params.AutoConvergeIncrement,
+ },
+ }
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainMigrate3
+func (d *Domain) Migrate3(dconn *Connect, params *DomainMigrateParameters, flags DomainMigrateFlags) (*Domain, error) {
+
+ info := getMigrateParameterFieldInfo(params)
+ cparams, gerr := typedParamsPackNew(info)
+ if gerr != nil {
+ return nil, gerr
+ }
+ nparams := len(*cparams)
+
+ defer C.virTypedParamsClear((*C.virTypedParameter)(unsafe.Pointer(&(*cparams)[0])), C.int(nparams))
+
+ var err C.virError
+ ret := C.virDomainMigrate3Wrapper(d.ptr, dconn.ptr, (*C.virTypedParameter)(unsafe.Pointer(&(*cparams)[0])), C.uint(nparams), C.uint(flags), &err)
+ if ret == nil {
+ return nil, makeError(&err)
+ }
+
+ return &Domain{
+ ptr: ret,
+ }, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainMigrateToURI
+func (d *Domain) MigrateToURI(duri string, flags DomainMigrateFlags, dname string, bandwidth uint64) error {
+ cduri := C.CString(duri)
+ defer C.free(unsafe.Pointer(cduri))
+
+ var cdname *C.char
+ if dname != "" {
+ cdname = C.CString(dname)
+ defer C.free(unsafe.Pointer(cdname))
+ }
+
+ var err C.virError
+ ret := C.virDomainMigrateToURIWrapper(d.ptr, cduri, C.ulong(flags), cdname, C.ulong(bandwidth), &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainMigrateToURI2
+func (d *Domain) MigrateToURI2(dconnuri string, miguri string, dxml string, flags DomainMigrateFlags, dname string, bandwidth uint64) error {
+ var cdconnuri *C.char
+ if dconnuri != "" {
+ cdconnuri = C.CString(dconnuri)
+ defer C.free(unsafe.Pointer(cdconnuri))
+ }
+ var cmiguri *C.char
+ if miguri != "" {
+ cmiguri = C.CString(miguri)
+ defer C.free(unsafe.Pointer(cmiguri))
+ }
+ var cdxml *C.char
+ if dxml != "" {
+ cdxml = C.CString(dxml)
+ defer C.free(unsafe.Pointer(cdxml))
+ }
+ var cdname *C.char
+ if dname != "" {
+ cdname = C.CString(dname)
+ defer C.free(unsafe.Pointer(cdname))
+ }
+
+ var err C.virError
+ ret := C.virDomainMigrateToURI2Wrapper(d.ptr, cdconnuri, cmiguri, cdxml, C.ulong(flags), cdname, C.ulong(bandwidth), &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainMigrateToURI3
+func (d *Domain) MigrateToURI3(dconnuri string, params *DomainMigrateParameters, flags DomainMigrateFlags) error {
+ var cdconnuri *C.char
+ if dconnuri != "" {
+ cdconnuri = C.CString(dconnuri)
+ defer C.free(unsafe.Pointer(cdconnuri))
+ }
+
+ info := getMigrateParameterFieldInfo(params)
+ cparams, gerr := typedParamsPackNew(info)
+ if gerr != nil {
+ return gerr
+ }
+ nparams := len(*cparams)
+
+ defer C.virTypedParamsClear((*C.virTypedParameter)(unsafe.Pointer(&(*cparams)[0])), C.int(nparams))
+
+ var err C.virError
+ ret := C.virDomainMigrateToURI3Wrapper(d.ptr, cdconnuri, (*C.virTypedParameter)(unsafe.Pointer(&(*cparams)[0])), C.uint(nparams), C.uint(flags), &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainMigrateGetCompressionCache
+func (d *Domain) MigrateGetCompressionCache(flags uint32) (uint64, error) {
+ var cacheSize C.ulonglong
+
+ var err C.virError
+ ret := C.virDomainMigrateGetCompressionCacheWrapper(d.ptr, &cacheSize, C.uint(flags), &err)
+ if ret == -1 {
+ return 0, makeError(&err)
+ }
+
+ return uint64(cacheSize), nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainMigrateSetCompressionCache
+func (d *Domain) MigrateSetCompressionCache(size uint64, flags uint32) error {
+ var err C.virError
+ ret := C.virDomainMigrateSetCompressionCacheWrapper(d.ptr, C.ulonglong(size), C.uint(flags), &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainMigrateGetMaxSpeed
+func (d *Domain) MigrateGetMaxSpeed(flags uint32) (uint64, error) {
+ var maxSpeed C.ulong
+
+ var err C.virError
+ ret := C.virDomainMigrateGetMaxSpeedWrapper(d.ptr, &maxSpeed, C.uint(flags), &err)
+ if ret == -1 {
+ return 0, makeError(&err)
+ }
+
+ return uint64(maxSpeed), nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainMigrateSetMaxSpeed
+func (d *Domain) MigrateSetMaxSpeed(speed uint64, flags uint32) error {
+ var err C.virError
+ ret := C.virDomainMigrateSetMaxSpeedWrapper(d.ptr, C.ulong(speed), C.uint(flags), &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainMigrateSetMaxDowntime
+func (d *Domain) MigrateSetMaxDowntime(downtime uint64, flags uint32) error {
+ var err C.virError
+ ret := C.virDomainMigrateSetMaxDowntimeWrapper(d.ptr, C.ulonglong(downtime), C.uint(flags), &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainMigrateGetMaxDowntime
+func (d *Domain) MigrateGetMaxDowntime(flags uint32) (uint64, error) {
+ var downtimeLen C.ulonglong
+
+ if C.LIBVIR_VERSION_NUMBER < 3007000 {
+ return 0, makeNotImplementedError("virDomainMigrateGetMaxDowntime")
+ }
+
+ var err C.virError
+ ret := C.virDomainMigrateGetMaxDowntimeWrapper(d.ptr, &downtimeLen, C.uint(flags), &err)
+ if ret == -1 {
+ return 0, makeError(&err)
+ }
+
+ return uint64(downtimeLen), nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainMigrateStartPostCopy
+func (d *Domain) MigrateStartPostCopy(flags uint32) error {
+ if C.LIBVIR_VERSION_NUMBER < 1003003 {
+ return makeNotImplementedError("virDomainMigrateStartPostCopy")
+ }
+
+ var err C.virError
+ ret := C.virDomainMigrateStartPostCopyWrapper(d.ptr, C.uint(flags), &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+
+ return nil
+}
+
+type DomainBlkioParameters struct {
+ WeightSet bool
+ Weight uint
+ DeviceWeightSet bool
+ DeviceWeight string
+ DeviceReadIopsSet bool
+ DeviceReadIops string
+ DeviceWriteIopsSet bool
+ DeviceWriteIops string
+ DeviceReadBpsSet bool
+ DeviceReadBps string
+ DeviceWriteBpsSet bool
+ DeviceWriteBps string
+}
+
+func getBlkioParametersFieldInfo(params *DomainBlkioParameters) map[string]typedParamsFieldInfo {
+ return map[string]typedParamsFieldInfo{
+ C.VIR_DOMAIN_BLKIO_WEIGHT: typedParamsFieldInfo{
+ set: &params.WeightSet,
+ ui: &params.Weight,
+ },
+ C.VIR_DOMAIN_BLKIO_DEVICE_WEIGHT: typedParamsFieldInfo{
+ set: &params.DeviceWeightSet,
+ s: &params.DeviceWeight,
+ },
+ C.VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS: typedParamsFieldInfo{
+ set: &params.DeviceReadIopsSet,
+ s: &params.DeviceReadIops,
+ },
+ C.VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS: typedParamsFieldInfo{
+ set: &params.DeviceWriteIopsSet,
+ s: &params.DeviceWriteIops,
+ },
+ C.VIR_DOMAIN_BLKIO_DEVICE_READ_BPS: typedParamsFieldInfo{
+ set: &params.DeviceReadBpsSet,
+ s: &params.DeviceReadBps,
+ },
+ C.VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS: typedParamsFieldInfo{
+ set: &params.DeviceWriteBpsSet,
+ s: &params.DeviceWriteBps,
+ },
+ }
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetBlkioParameters
+func (d *Domain) GetBlkioParameters(flags DomainModificationImpact) (*DomainBlkioParameters, error) {
+ params := &DomainBlkioParameters{}
+ info := getBlkioParametersFieldInfo(params)
+
+ var nparams C.int
+ var err C.virError
+ ret := C.virDomainGetBlkioParametersWrapper(d.ptr, nil, &nparams, 0, &err)
+ if ret == -1 {
+ return nil, makeError(&err)
+ }
+
+ cparams := make([]C.virTypedParameter, nparams)
+ ret = C.virDomainGetBlkioParametersWrapper(d.ptr, (*C.virTypedParameter)(unsafe.Pointer(&cparams[0])), &nparams, C.uint(flags), &err)
+ if ret == -1 {
+ return nil, makeError(&err)
+ }
+
+ defer C.virTypedParamsClear((*C.virTypedParameter)(unsafe.Pointer(&cparams[0])), nparams)
+
+ _, gerr := typedParamsUnpack(cparams, info)
+ if gerr != nil {
+ return nil, gerr
+ }
+
+ return params, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSetBlkioParameters
+func (d *Domain) SetBlkioParameters(params *DomainBlkioParameters, flags DomainModificationImpact) error {
+ info := getBlkioParametersFieldInfo(params)
+
+ var nparams C.int
+
+ var err C.virError
+ ret := C.virDomainGetBlkioParametersWrapper(d.ptr, nil, &nparams, 0, &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+
+ cparams := make([]C.virTypedParameter, nparams)
+ ret = C.virDomainGetBlkioParametersWrapper(d.ptr, (*C.virTypedParameter)(unsafe.Pointer(&cparams[0])), &nparams, 0, &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+
+ defer C.virTypedParamsClear((*C.virTypedParameter)(unsafe.Pointer(&cparams[0])), nparams)
+
+ gerr := typedParamsPack(cparams, info)
+ if gerr != nil {
+ return gerr
+ }
+
+ ret = C.virDomainSetBlkioParametersWrapper(d.ptr, (*C.virTypedParameter)(unsafe.Pointer(&cparams[0])), nparams, C.uint(flags), &err)
+
+ return nil
+}
+
+type DomainBlockIoTuneParameters struct {
+ TotalBytesSecSet bool
+ TotalBytesSec uint64
+ ReadBytesSecSet bool
+ ReadBytesSec uint64
+ WriteBytesSecSet bool
+ WriteBytesSec uint64
+ TotalIopsSecSet bool
+ TotalIopsSec uint64
+ ReadIopsSecSet bool
+ ReadIopsSec uint64
+ WriteIopsSecSet bool
+ WriteIopsSec uint64
+ TotalBytesSecMaxSet bool
+ TotalBytesSecMax uint64
+ ReadBytesSecMaxSet bool
+ ReadBytesSecMax uint64
+ WriteBytesSecMaxSet bool
+ WriteBytesSecMax uint64
+ TotalIopsSecMaxSet bool
+ TotalIopsSecMax uint64
+ ReadIopsSecMaxSet bool
+ ReadIopsSecMax uint64
+ WriteIopsSecMaxSet bool
+ WriteIopsSecMax uint64
+ TotalBytesSecMaxLengthSet bool
+ TotalBytesSecMaxLength uint64
+ ReadBytesSecMaxLengthSet bool
+ ReadBytesSecMaxLength uint64
+ WriteBytesSecMaxLengthSet bool
+ WriteBytesSecMaxLength uint64
+ TotalIopsSecMaxLengthSet bool
+ TotalIopsSecMaxLength uint64
+ ReadIopsSecMaxLengthSet bool
+ ReadIopsSecMaxLength uint64
+ WriteIopsSecMaxLengthSet bool
+ WriteIopsSecMaxLength uint64
+ SizeIopsSecSet bool
+ SizeIopsSec uint64
+ GroupNameSet bool
+ GroupName string
+}
+
+func getBlockIoTuneParametersFieldInfo(params *DomainBlockIoTuneParameters) map[string]typedParamsFieldInfo {
+ return map[string]typedParamsFieldInfo{
+ C.VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_BYTES_SEC: typedParamsFieldInfo{
+ set: &params.TotalBytesSecSet,
+ ul: &params.TotalBytesSec,
+ },
+ C.VIR_DOMAIN_BLOCK_IOTUNE_READ_BYTES_SEC: typedParamsFieldInfo{
+ set: &params.ReadBytesSecSet,
+ ul: &params.ReadBytesSec,
+ },
+ C.VIR_DOMAIN_BLOCK_IOTUNE_WRITE_BYTES_SEC: typedParamsFieldInfo{
+ set: &params.WriteBytesSecSet,
+ ul: &params.WriteBytesSec,
+ },
+ C.VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_IOPS_SEC: typedParamsFieldInfo{
+ set: &params.TotalIopsSecSet,
+ ul: &params.TotalIopsSec,
+ },
+ C.VIR_DOMAIN_BLOCK_IOTUNE_READ_IOPS_SEC: typedParamsFieldInfo{
+ set: &params.ReadIopsSecSet,
+ ul: &params.ReadIopsSec,
+ },
+ C.VIR_DOMAIN_BLOCK_IOTUNE_WRITE_IOPS_SEC: typedParamsFieldInfo{
+ set: &params.WriteIopsSecSet,
+ ul: &params.WriteIopsSec,
+ },
+ C.VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_BYTES_SEC_MAX: typedParamsFieldInfo{
+ set: &params.TotalBytesSecMaxSet,
+ ul: &params.TotalBytesSecMax,
+ },
+ C.VIR_DOMAIN_BLOCK_IOTUNE_READ_BYTES_SEC_MAX: typedParamsFieldInfo{
+ set: &params.ReadBytesSecMaxSet,
+ ul: &params.ReadBytesSecMax,
+ },
+ C.VIR_DOMAIN_BLOCK_IOTUNE_WRITE_BYTES_SEC_MAX: typedParamsFieldInfo{
+ set: &params.WriteBytesSecMaxSet,
+ ul: &params.WriteBytesSecMax,
+ },
+ C.VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_IOPS_SEC_MAX: typedParamsFieldInfo{
+ set: &params.TotalIopsSecMaxSet,
+ ul: &params.TotalIopsSecMax,
+ },
+ C.VIR_DOMAIN_BLOCK_IOTUNE_READ_IOPS_SEC_MAX: typedParamsFieldInfo{
+ set: &params.ReadIopsSecMaxSet,
+ ul: &params.ReadIopsSecMax,
+ },
+ C.VIR_DOMAIN_BLOCK_IOTUNE_WRITE_IOPS_SEC_MAX: typedParamsFieldInfo{
+ set: &params.WriteIopsSecMaxSet,
+ ul: &params.WriteIopsSecMax,
+ },
+ C.VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_BYTES_SEC_MAX_LENGTH: typedParamsFieldInfo{
+ set: &params.TotalBytesSecMaxLengthSet,
+ ul: &params.TotalBytesSecMaxLength,
+ },
+ C.VIR_DOMAIN_BLOCK_IOTUNE_READ_BYTES_SEC_MAX_LENGTH: typedParamsFieldInfo{
+ set: &params.ReadBytesSecMaxLengthSet,
+ ul: &params.ReadBytesSecMaxLength,
+ },
+ C.VIR_DOMAIN_BLOCK_IOTUNE_WRITE_BYTES_SEC_MAX_LENGTH: typedParamsFieldInfo{
+ set: &params.WriteBytesSecMaxLengthSet,
+ ul: &params.WriteBytesSecMaxLength,
+ },
+ C.VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_IOPS_SEC_MAX_LENGTH: typedParamsFieldInfo{
+ set: &params.TotalIopsSecMaxLengthSet,
+ ul: &params.TotalIopsSecMaxLength,
+ },
+ C.VIR_DOMAIN_BLOCK_IOTUNE_READ_IOPS_SEC_MAX_LENGTH: typedParamsFieldInfo{
+ set: &params.ReadIopsSecMaxLengthSet,
+ ul: &params.ReadIopsSecMaxLength,
+ },
+ C.VIR_DOMAIN_BLOCK_IOTUNE_WRITE_IOPS_SEC_MAX_LENGTH: typedParamsFieldInfo{
+ set: &params.WriteIopsSecMaxLengthSet,
+ ul: &params.WriteIopsSecMaxLength,
+ },
+ C.VIR_DOMAIN_BLOCK_IOTUNE_SIZE_IOPS_SEC: typedParamsFieldInfo{
+ set: &params.SizeIopsSecSet,
+ ul: &params.SizeIopsSec,
+ },
+ C.VIR_DOMAIN_BLOCK_IOTUNE_GROUP_NAME: typedParamsFieldInfo{
+ set: &params.GroupNameSet,
+ s: &params.GroupName,
+ },
+ }
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetBlockIoTune
+func (d *Domain) GetBlockIoTune(disk string, flags DomainModificationImpact) (*DomainBlockIoTuneParameters, error) {
+ cdisk := C.CString(disk)
+ defer C.free(unsafe.Pointer(cdisk))
+
+ params := &DomainBlockIoTuneParameters{}
+ info := getBlockIoTuneParametersFieldInfo(params)
+
+ var nparams C.int
+ var err C.virError
+ ret := C.virDomainGetBlockIoTuneWrapper(d.ptr, cdisk, nil, &nparams, 0, &err)
+ if ret == -1 {
+ return nil, makeError(&err)
+ }
+
+ cparams := make([]C.virTypedParameter, nparams)
+ ret = C.virDomainGetBlockIoTuneWrapper(d.ptr, cdisk, (*C.virTypedParameter)(unsafe.Pointer(&cparams[0])), &nparams, C.uint(flags), &err)
+ if ret == -1 {
+ return nil, makeError(&err)
+ }
+
+ defer C.virTypedParamsClear((*C.virTypedParameter)(unsafe.Pointer(&cparams[0])), nparams)
+
+ _, gerr := typedParamsUnpack(cparams, info)
+ if gerr != nil {
+ return nil, gerr
+ }
+
+ return params, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSetBlockIoTune
+func (d *Domain) SetBlockIoTune(disk string, params *DomainBlockIoTuneParameters, flags DomainModificationImpact) error {
+ cdisk := C.CString(disk)
+ defer C.free(unsafe.Pointer(cdisk))
+
+ info := getBlockIoTuneParametersFieldInfo(params)
+
+ var nparams C.int
+
+ var err C.virError
+ ret := C.virDomainGetBlockIoTuneWrapper(d.ptr, cdisk, nil, &nparams, 0, &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+
+ cparams := make([]C.virTypedParameter, nparams)
+ ret = C.virDomainGetBlockIoTuneWrapper(d.ptr, cdisk, (*C.virTypedParameter)(unsafe.Pointer(&cparams[0])), &nparams, 0, &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+
+ defer C.virTypedParamsClear((*C.virTypedParameter)(unsafe.Pointer(&cparams[0])), nparams)
+
+ gerr := typedParamsPack(cparams, info)
+ if gerr != nil {
+ return gerr
+ }
+
+ ret = C.virDomainSetBlockIoTuneWrapper(d.ptr, cdisk, (*C.virTypedParameter)(unsafe.Pointer(&cparams[0])), nparams, C.uint(flags), &err)
+
+ return nil
+}
+
+type DomainBlockJobInfo struct {
+ Type DomainBlockJobType
+ Bandwidth uint64
+ Cur uint64
+ End uint64
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetBlockJobInfo
+func (d *Domain) GetBlockJobInfo(disk string, flags DomainBlockJobInfoFlags) (*DomainBlockJobInfo, error) {
+ cdisk := C.CString(disk)
+ defer C.free(unsafe.Pointer(cdisk))
+
+ var cinfo C.virDomainBlockJobInfo
+
+ var err C.virError
+ ret := C.virDomainGetBlockJobInfoWrapper(d.ptr, cdisk, &cinfo, C.uint(flags), &err)
+
+ if ret == -1 {
+ return nil, makeError(&err)
+ }
+
+ return &DomainBlockJobInfo{
+ Type: DomainBlockJobType(cinfo._type),
+ Bandwidth: uint64(cinfo.bandwidth),
+ Cur: uint64(cinfo.cur),
+ End: uint64(cinfo.end),
+ }, nil
+}
+
+type DomainControlInfo struct {
+ State DomainControlState
+ Details int
+ StateTime uint64
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetControlInfo
+func (d *Domain) GetControlInfo(flags uint32) (*DomainControlInfo, error) {
+
+ var cinfo C.virDomainControlInfo
+
+ var err C.virError
+ ret := C.virDomainGetControlInfoWrapper(d.ptr, &cinfo, C.uint(flags), &err)
+ if ret == -1 {
+ return nil, makeError(&err)
+ }
+
+ return &DomainControlInfo{
+ State: DomainControlState(cinfo.state),
+ Details: int(cinfo.details),
+ StateTime: uint64(cinfo.stateTime),
+ }, nil
+}
+
+type DomainDiskError struct {
+ Disk string
+ Error DomainDiskErrorCode
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetDiskErrors
+func (d *Domain) GetDiskErrors(flags uint32) ([]DomainDiskError, error) {
+ var err C.virError
+ ret := C.virDomainGetDiskErrorsWrapper(d.ptr, nil, 0, 0, &err)
+ if ret == -1 {
+ return []DomainDiskError{}, makeError(&err)
+ }
+
+ maxerrors := ret
+ cerrors := make([]C.virDomainDiskError, maxerrors)
+
+ ret = C.virDomainGetDiskErrorsWrapper(d.ptr, (*C.virDomainDiskError)(unsafe.Pointer(&cerrors[0])), C.uint(maxerrors), C.uint(flags), &err)
+ if ret == -1 {
+ return []DomainDiskError{}, makeError(&err)
+ }
+
+ errors := make([]DomainDiskError, maxerrors)
+
+ for i, cerror := range cerrors {
+ errors[i] = DomainDiskError{
+ Disk: C.GoString(cerror.disk),
+ Error: DomainDiskErrorCode(cerror.error),
+ }
+ C.free(unsafe.Pointer(cerror.disk))
+ }
+
+ return errors, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetHostname
+func (d *Domain) GetHostname(flags uint32) (string, error) {
+ var err C.virError
+ ret := C.virDomainGetHostnameWrapper(d.ptr, C.uint(flags), &err)
+ if ret == nil {
+ return "", makeError(&err)
+ }
+
+ defer C.free(unsafe.Pointer(ret))
+
+ return C.GoString(ret), nil
+}
+
+type DomainJobInfo struct {
+ Type DomainJobType
+ TimeElapsedSet bool
+ TimeElapsed uint64
+ TimeElapsedNetSet bool
+ TimeElapsedNet uint64
+ TimeRemainingSet bool
+ TimeRemaining uint64
+ DowntimeSet bool
+ Downtime uint64
+ DowntimeNetSet bool
+ DowntimeNet uint64
+ SetupTimeSet bool
+ SetupTime uint64
+ DataTotalSet bool
+ DataTotal uint64
+ DataProcessedSet bool
+ DataProcessed uint64
+ DataRemainingSet bool
+ DataRemaining uint64
+ MemTotalSet bool
+ MemTotal uint64
+ MemProcessedSet bool
+ MemProcessed uint64
+ MemRemainingSet bool
+ MemRemaining uint64
+ MemConstantSet bool
+ MemConstant uint64
+ MemNormalSet bool
+ MemNormal uint64
+ MemNormalBytesSet bool
+ MemNormalBytes uint64
+ MemBpsSet bool
+ MemBps uint64
+ MemDirtyRateSet bool
+ MemDirtyRate uint64
+ MemPageSizeSet bool
+ MemPageSize uint64
+ MemIterationSet bool
+ MemIteration uint64
+ DiskTotalSet bool
+ DiskTotal uint64
+ DiskProcessedSet bool
+ DiskProcessed uint64
+ DiskRemainingSet bool
+ DiskRemaining uint64
+ DiskBpsSet bool
+ DiskBps uint64
+ CompressionCacheSet bool
+ CompressionCache uint64
+ CompressionBytesSet bool
+ CompressionBytes uint64
+ CompressionPagesSet bool
+ CompressionPages uint64
+ CompressionCacheMissesSet bool
+ CompressionCacheMisses uint64
+ CompressionOverflowSet bool
+ CompressionOverflow uint64
+ AutoConvergeThrottleSet bool
+ AutoConvergeThrottle int
+ OperationSet bool
+ Operation DomainJobOperationType
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetJobInfo
+func (d *Domain) GetJobInfo() (*DomainJobInfo, error) {
+ var cinfo C.virDomainJobInfo
+
+ var err C.virError
+ ret := C.virDomainGetJobInfoWrapper(d.ptr, &cinfo, &err)
+ if ret == -1 {
+ return nil, makeError(&err)
+ }
+
+ return &DomainJobInfo{
+ Type: DomainJobType(cinfo._type),
+ TimeElapsedSet: true,
+ TimeElapsed: uint64(cinfo.timeElapsed),
+ TimeRemainingSet: true,
+ TimeRemaining: uint64(cinfo.timeRemaining),
+ DataTotalSet: true,
+ DataTotal: uint64(cinfo.dataTotal),
+ DataProcessedSet: true,
+ DataProcessed: uint64(cinfo.dataProcessed),
+ DataRemainingSet: true,
+ DataRemaining: uint64(cinfo.dataRemaining),
+ MemTotalSet: true,
+ MemTotal: uint64(cinfo.memTotal),
+ MemProcessedSet: true,
+ MemProcessed: uint64(cinfo.memProcessed),
+ MemRemainingSet: true,
+ MemRemaining: uint64(cinfo.memRemaining),
+ DiskTotalSet: true,
+ DiskTotal: uint64(cinfo.fileTotal),
+ DiskProcessedSet: true,
+ DiskProcessed: uint64(cinfo.fileProcessed),
+ DiskRemainingSet: true,
+ DiskRemaining: uint64(cinfo.fileRemaining),
+ }, nil
+}
+
+func getDomainJobInfoFieldInfo(params *DomainJobInfo) map[string]typedParamsFieldInfo {
+ return map[string]typedParamsFieldInfo{
+ C.VIR_DOMAIN_JOB_TIME_ELAPSED: typedParamsFieldInfo{
+ set: &params.TimeElapsedSet,
+ ul: &params.TimeElapsed,
+ },
+ C.VIR_DOMAIN_JOB_TIME_ELAPSED_NET: typedParamsFieldInfo{
+ set: &params.TimeElapsedNetSet,
+ ul: &params.TimeElapsedNet,
+ },
+ C.VIR_DOMAIN_JOB_TIME_REMAINING: typedParamsFieldInfo{
+ set: &params.TimeRemainingSet,
+ ul: &params.TimeRemaining,
+ },
+ C.VIR_DOMAIN_JOB_DOWNTIME: typedParamsFieldInfo{
+ set: &params.DowntimeSet,
+ ul: &params.Downtime,
+ },
+ C.VIR_DOMAIN_JOB_DOWNTIME_NET: typedParamsFieldInfo{
+ set: &params.DowntimeNetSet,
+ ul: &params.DowntimeNet,
+ },
+ C.VIR_DOMAIN_JOB_SETUP_TIME: typedParamsFieldInfo{
+ set: &params.SetupTimeSet,
+ ul: &params.SetupTime,
+ },
+ C.VIR_DOMAIN_JOB_DATA_TOTAL: typedParamsFieldInfo{
+ set: &params.DataTotalSet,
+ ul: &params.DataTotal,
+ },
+ C.VIR_DOMAIN_JOB_DATA_PROCESSED: typedParamsFieldInfo{
+ set: &params.DataProcessedSet,
+ ul: &params.DataProcessed,
+ },
+ C.VIR_DOMAIN_JOB_DATA_REMAINING: typedParamsFieldInfo{
+ set: &params.DataRemainingSet,
+ ul: &params.DataRemaining,
+ },
+ C.VIR_DOMAIN_JOB_MEMORY_TOTAL: typedParamsFieldInfo{
+ set: &params.MemTotalSet,
+ ul: &params.MemTotal,
+ },
+ C.VIR_DOMAIN_JOB_MEMORY_PROCESSED: typedParamsFieldInfo{
+ set: &params.MemProcessedSet,
+ ul: &params.MemProcessed,
+ },
+ C.VIR_DOMAIN_JOB_MEMORY_REMAINING: typedParamsFieldInfo{
+ set: &params.MemRemainingSet,
+ ul: &params.MemRemaining,
+ },
+ C.VIR_DOMAIN_JOB_MEMORY_CONSTANT: typedParamsFieldInfo{
+ set: &params.MemConstantSet,
+ ul: &params.MemConstant,
+ },
+ C.VIR_DOMAIN_JOB_MEMORY_NORMAL: typedParamsFieldInfo{
+ set: &params.MemNormalSet,
+ ul: &params.MemNormal,
+ },
+ C.VIR_DOMAIN_JOB_MEMORY_NORMAL_BYTES: typedParamsFieldInfo{
+ set: &params.MemNormalBytesSet,
+ ul: &params.MemNormalBytes,
+ },
+ C.VIR_DOMAIN_JOB_MEMORY_BPS: typedParamsFieldInfo{
+ set: &params.MemBpsSet,
+ ul: &params.MemBps,
+ },
+ C.VIR_DOMAIN_JOB_MEMORY_DIRTY_RATE: typedParamsFieldInfo{
+ set: &params.MemDirtyRateSet,
+ ul: &params.MemDirtyRate,
+ },
+ C.VIR_DOMAIN_JOB_MEMORY_PAGE_SIZE: typedParamsFieldInfo{
+ set: &params.MemPageSizeSet,
+ ul: &params.MemPageSize,
+ },
+ C.VIR_DOMAIN_JOB_MEMORY_ITERATION: typedParamsFieldInfo{
+ set: &params.MemIterationSet,
+ ul: &params.MemIteration,
+ },
+ C.VIR_DOMAIN_JOB_DISK_TOTAL: typedParamsFieldInfo{
+ set: &params.DiskTotalSet,
+ ul: &params.DiskTotal,
+ },
+ C.VIR_DOMAIN_JOB_DISK_PROCESSED: typedParamsFieldInfo{
+ set: &params.DiskProcessedSet,
+ ul: &params.DiskProcessed,
+ },
+ C.VIR_DOMAIN_JOB_DISK_REMAINING: typedParamsFieldInfo{
+ set: &params.DiskRemainingSet,
+ ul: &params.DiskRemaining,
+ },
+ C.VIR_DOMAIN_JOB_DISK_BPS: typedParamsFieldInfo{
+ set: &params.DiskBpsSet,
+ ul: &params.DiskBps,
+ },
+ C.VIR_DOMAIN_JOB_COMPRESSION_CACHE: typedParamsFieldInfo{
+ set: &params.CompressionCacheSet,
+ ul: &params.CompressionCache,
+ },
+ C.VIR_DOMAIN_JOB_COMPRESSION_BYTES: typedParamsFieldInfo{
+ set: &params.CompressionBytesSet,
+ ul: &params.CompressionBytes,
+ },
+ C.VIR_DOMAIN_JOB_COMPRESSION_PAGES: typedParamsFieldInfo{
+ set: &params.CompressionPagesSet,
+ ul: &params.CompressionPages,
+ },
+ C.VIR_DOMAIN_JOB_COMPRESSION_CACHE_MISSES: typedParamsFieldInfo{
+ set: &params.CompressionCacheMissesSet,
+ ul: &params.CompressionCacheMisses,
+ },
+ C.VIR_DOMAIN_JOB_COMPRESSION_OVERFLOW: typedParamsFieldInfo{
+ set: &params.CompressionOverflowSet,
+ ul: &params.CompressionOverflow,
+ },
+ C.VIR_DOMAIN_JOB_AUTO_CONVERGE_THROTTLE: typedParamsFieldInfo{
+ set: &params.AutoConvergeThrottleSet,
+ i: &params.AutoConvergeThrottle,
+ },
+ C.VIR_DOMAIN_JOB_OPERATION: typedParamsFieldInfo{
+ set: &params.OperationSet,
+ i: (*int)(&params.Operation),
+ },
+ }
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetJobStats
+func (d *Domain) GetJobStats(flags DomainGetJobStatsFlags) (*DomainJobInfo, error) {
+ var cparams *C.virTypedParameter
+ var nparams C.int
+ var jobtype C.int
+ var err C.virError
+ ret := C.virDomainGetJobStatsWrapper(d.ptr, &jobtype, (*C.virTypedParameterPtr)(unsafe.Pointer(&cparams)), &nparams, C.uint(flags), &err)
+ if ret == -1 {
+ return nil, makeError(&err)
+ }
+ defer C.virTypedParamsFree(cparams, nparams)
+
+ params := DomainJobInfo{}
+ info := getDomainJobInfoFieldInfo(&params)
+
+ _, gerr := typedParamsUnpackLen(cparams, int(nparams), info)
+ if gerr != nil {
+ return nil, gerr
+ }
+
+ return &params, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetMaxMemory
+func (d *Domain) GetMaxMemory() (uint64, error) {
+ var err C.virError
+ ret := C.virDomainGetMaxMemoryWrapper(d.ptr, &err)
+ if ret == 0 {
+ return 0, makeError(&err)
+ }
+
+ return uint64(ret), nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetMaxVcpus
+func (d *Domain) GetMaxVcpus() (uint, error) {
+ var err C.virError
+ ret := C.virDomainGetMaxVcpusWrapper(d.ptr, &err)
+ if ret == -1 {
+ return 0, makeError(&err)
+ }
+
+ return uint(ret), nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetOSType
+func (d *Domain) GetOSType() (string, error) {
+ var err C.virError
+ ret := C.virDomainGetOSTypeWrapper(d.ptr, &err)
+ if ret == nil {
+ return "", makeError(&err)
+ }
+
+ defer C.free(unsafe.Pointer(ret))
+
+ return C.GoString(ret), nil
+}
+
+type DomainMemoryParameters struct {
+ HardLimitSet bool
+ HardLimit uint64
+ SoftLimitSet bool
+ SoftLimit uint64
+ MinGuaranteeSet bool
+ MinGuarantee uint64
+ SwapHardLimitSet bool
+ SwapHardLimit uint64
+}
+
+func getDomainMemoryParametersFieldInfo(params *DomainMemoryParameters) map[string]typedParamsFieldInfo {
+ return map[string]typedParamsFieldInfo{
+ C.VIR_DOMAIN_MEMORY_HARD_LIMIT: typedParamsFieldInfo{
+ set: &params.HardLimitSet,
+ ul: &params.HardLimit,
+ },
+ C.VIR_DOMAIN_MEMORY_SOFT_LIMIT: typedParamsFieldInfo{
+ set: &params.SoftLimitSet,
+ ul: &params.SoftLimit,
+ },
+ C.VIR_DOMAIN_MEMORY_MIN_GUARANTEE: typedParamsFieldInfo{
+ set: &params.MinGuaranteeSet,
+ ul: &params.MinGuarantee,
+ },
+ C.VIR_DOMAIN_MEMORY_SWAP_HARD_LIMIT: typedParamsFieldInfo{
+ set: &params.SwapHardLimitSet,
+ ul: &params.SwapHardLimit,
+ },
+ }
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetMemoryParameters
+func (d *Domain) GetMemoryParameters(flags DomainModificationImpact) (*DomainMemoryParameters, error) {
+ params := &DomainMemoryParameters{}
+ info := getDomainMemoryParametersFieldInfo(params)
+
+ var nparams C.int
+ var err C.virError
+ ret := C.virDomainGetMemoryParametersWrapper(d.ptr, nil, &nparams, 0, &err)
+ if ret == -1 {
+ return nil, makeError(&err)
+ }
+
+ cparams := make([]C.virTypedParameter, nparams)
+ ret = C.virDomainGetMemoryParametersWrapper(d.ptr, (*C.virTypedParameter)(unsafe.Pointer(&cparams[0])), &nparams, C.uint(flags), &err)
+ if ret == -1 {
+ return nil, makeError(&err)
+ }
+
+ defer C.virTypedParamsClear((*C.virTypedParameter)(unsafe.Pointer(&cparams[0])), nparams)
+
+ _, gerr := typedParamsUnpack(cparams, info)
+ if gerr != nil {
+ return nil, gerr
+ }
+
+ return params, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSetMemoryParameters
+func (d *Domain) SetMemoryParameters(params *DomainMemoryParameters, flags DomainModificationImpact) error {
+ info := getDomainMemoryParametersFieldInfo(params)
+
+ var nparams C.int
+
+ var err C.virError
+ ret := C.virDomainGetMemoryParametersWrapper(d.ptr, nil, &nparams, 0, &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+
+ cparams := make([]C.virTypedParameter, nparams)
+ ret = C.virDomainGetMemoryParametersWrapper(d.ptr, (*C.virTypedParameter)(unsafe.Pointer(&cparams[0])), &nparams, 0, &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+
+ defer C.virTypedParamsClear((*C.virTypedParameter)(unsafe.Pointer(&cparams[0])), nparams)
+
+ gerr := typedParamsPack(cparams, info)
+ if gerr != nil {
+ return gerr
+ }
+
+ ret = C.virDomainSetMemoryParametersWrapper(d.ptr, (*C.virTypedParameter)(unsafe.Pointer(&cparams[0])), nparams, C.uint(flags), &err)
+
+ return nil
+}
+
+type DomainNumaParameters struct {
+ NodesetSet bool
+ Nodeset string
+ ModeSet bool
+ Mode DomainNumatuneMemMode
+}
+
+func getDomainNumaParametersFieldInfo(params *DomainNumaParameters) map[string]typedParamsFieldInfo {
+ return map[string]typedParamsFieldInfo{
+ C.VIR_DOMAIN_NUMA_NODESET: typedParamsFieldInfo{
+ set: &params.NodesetSet,
+ s: &params.Nodeset,
+ },
+ C.VIR_DOMAIN_NUMA_MODE: typedParamsFieldInfo{
+ set: &params.ModeSet,
+ i: (*int)(&params.Mode),
+ },
+ }
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetNumaParameters
+func (d *Domain) GetNumaParameters(flags DomainModificationImpact) (*DomainNumaParameters, error) {
+ params := &DomainNumaParameters{}
+ info := getDomainNumaParametersFieldInfo(params)
+
+ var nparams C.int
+ var err C.virError
+ ret := C.virDomainGetNumaParametersWrapper(d.ptr, nil, &nparams, 0, &err)
+ if ret == -1 {
+ return nil, makeError(&err)
+ }
+
+ cparams := make([]C.virTypedParameter, nparams)
+ ret = C.virDomainGetNumaParametersWrapper(d.ptr, (*C.virTypedParameter)(unsafe.Pointer(&cparams[0])), &nparams, C.uint(flags), &err)
+ if ret == -1 {
+ return nil, makeError(&err)
+ }
+
+ defer C.virTypedParamsClear((*C.virTypedParameter)(unsafe.Pointer(&cparams[0])), nparams)
+
+ _, gerr := typedParamsUnpack(cparams, info)
+ if gerr != nil {
+ return nil, gerr
+ }
+
+ return params, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSetNumaParameters
+func (d *Domain) SetNumaParameters(params *DomainNumaParameters, flags DomainModificationImpact) error {
+ info := getDomainNumaParametersFieldInfo(params)
+
+ var nparams C.int
+
+ var err C.virError
+ ret := C.virDomainGetNumaParametersWrapper(d.ptr, nil, &nparams, 0, &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+
+ cparams := make([]C.virTypedParameter, nparams)
+ ret = C.virDomainGetNumaParametersWrapper(d.ptr, (*C.virTypedParameter)(unsafe.Pointer(&cparams[0])), &nparams, 0, &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+
+ defer C.virTypedParamsClear((*C.virTypedParameter)(unsafe.Pointer(&cparams[0])), nparams)
+
+ gerr := typedParamsPack(cparams, info)
+ if gerr != nil {
+ return gerr
+ }
+
+ ret = C.virDomainSetNumaParametersWrapper(d.ptr, (*C.virTypedParameter)(unsafe.Pointer(&cparams[0])), nparams, C.uint(flags), &err)
+
+ return nil
+}
+
+type DomainPerfEvents struct {
+ CmtSet bool
+ Cmt bool
+ MbmtSet bool
+ Mbmt bool
+ MbmlSet bool
+ Mbml bool
+ CacheMissesSet bool
+ CacheMisses bool
+ CacheReferencesSet bool
+ CacheReferences bool
+ InstructionsSet bool
+ Instructions bool
+ CpuCyclesSet bool
+ CpuCycles bool
+ BranchInstructionsSet bool
+ BranchInstructions bool
+ BranchMissesSet bool
+ BranchMisses bool
+ BusCyclesSet bool
+ BusCycles bool
+ StalledCyclesFrontendSet bool
+ StalledCyclesFrontend bool
+ StalledCyclesBackendSet bool
+ StalledCyclesBackend bool
+ RefCpuCyclesSet bool
+ RefCpuCycles bool
+ CpuClockSet bool
+ CpuClock bool
+ TaskClockSet bool
+ TaskClock bool
+ PageFaultsSet bool
+ PageFaults bool
+ ContextSwitchesSet bool
+ ContextSwitches bool
+ CpuMigrationsSet bool
+ CpuMigrations bool
+ PageFaultsMinSet bool
+ PageFaultsMin bool
+ PageFaultsMajSet bool
+ PageFaultsMaj bool
+ AlignmentFaultsSet bool
+ AlignmentFaults bool
+ EmulationFaultsSet bool
+ EmulationFaults bool
+}
+
+/* Remember to also update DomainStatsPerf in connect.go when adding to the stuct above */
+
+func getDomainPerfEventsFieldInfo(params *DomainPerfEvents) map[string]typedParamsFieldInfo {
+ return map[string]typedParamsFieldInfo{
+ C.VIR_PERF_PARAM_CMT: typedParamsFieldInfo{
+ set: &params.CmtSet,
+ b: &params.Cmt,
+ },
+ C.VIR_PERF_PARAM_MBMT: typedParamsFieldInfo{
+ set: &params.MbmtSet,
+ b: &params.Mbmt,
+ },
+ C.VIR_PERF_PARAM_MBML: typedParamsFieldInfo{
+ set: &params.MbmlSet,
+ b: &params.Mbml,
+ },
+ C.VIR_PERF_PARAM_CACHE_MISSES: typedParamsFieldInfo{
+ set: &params.CacheMissesSet,
+ b: &params.CacheMisses,
+ },
+ C.VIR_PERF_PARAM_CACHE_REFERENCES: typedParamsFieldInfo{
+ set: &params.CacheReferencesSet,
+ b: &params.CacheReferences,
+ },
+ C.VIR_PERF_PARAM_INSTRUCTIONS: typedParamsFieldInfo{
+ set: &params.InstructionsSet,
+ b: &params.Instructions,
+ },
+ C.VIR_PERF_PARAM_CPU_CYCLES: typedParamsFieldInfo{
+ set: &params.CpuCyclesSet,
+ b: &params.CpuCycles,
+ },
+ C.VIR_PERF_PARAM_BRANCH_INSTRUCTIONS: typedParamsFieldInfo{
+ set: &params.BranchInstructionsSet,
+ b: &params.BranchInstructions,
+ },
+ C.VIR_PERF_PARAM_BRANCH_MISSES: typedParamsFieldInfo{
+ set: &params.BranchMissesSet,
+ b: &params.BranchMisses,
+ },
+ C.VIR_PERF_PARAM_BUS_CYCLES: typedParamsFieldInfo{
+ set: &params.BusCyclesSet,
+ b: &params.BusCycles,
+ },
+ C.VIR_PERF_PARAM_STALLED_CYCLES_FRONTEND: typedParamsFieldInfo{
+ set: &params.StalledCyclesFrontendSet,
+ b: &params.StalledCyclesFrontend,
+ },
+ C.VIR_PERF_PARAM_STALLED_CYCLES_BACKEND: typedParamsFieldInfo{
+ set: &params.StalledCyclesBackendSet,
+ b: &params.StalledCyclesBackend,
+ },
+ C.VIR_PERF_PARAM_REF_CPU_CYCLES: typedParamsFieldInfo{
+ set: &params.RefCpuCyclesSet,
+ b: &params.RefCpuCycles,
+ },
+ C.VIR_PERF_PARAM_CPU_CLOCK: typedParamsFieldInfo{
+ set: &params.CpuClockSet,
+ b: &params.CpuClock,
+ },
+ C.VIR_PERF_PARAM_TASK_CLOCK: typedParamsFieldInfo{
+ set: &params.TaskClockSet,
+ b: &params.TaskClock,
+ },
+ C.VIR_PERF_PARAM_PAGE_FAULTS: typedParamsFieldInfo{
+ set: &params.PageFaultsSet,
+ b: &params.PageFaults,
+ },
+ C.VIR_PERF_PARAM_CONTEXT_SWITCHES: typedParamsFieldInfo{
+ set: &params.ContextSwitchesSet,
+ b: &params.ContextSwitches,
+ },
+ C.VIR_PERF_PARAM_CPU_MIGRATIONS: typedParamsFieldInfo{
+ set: &params.CpuMigrationsSet,
+ b: &params.CpuMigrations,
+ },
+ C.VIR_PERF_PARAM_PAGE_FAULTS_MIN: typedParamsFieldInfo{
+ set: &params.PageFaultsMinSet,
+ b: &params.PageFaultsMin,
+ },
+ C.VIR_PERF_PARAM_PAGE_FAULTS_MAJ: typedParamsFieldInfo{
+ set: &params.PageFaultsMajSet,
+ b: &params.PageFaultsMaj,
+ },
+ C.VIR_PERF_PARAM_ALIGNMENT_FAULTS: typedParamsFieldInfo{
+ set: &params.AlignmentFaultsSet,
+ b: &params.AlignmentFaults,
+ },
+ C.VIR_PERF_PARAM_EMULATION_FAULTS: typedParamsFieldInfo{
+ set: &params.EmulationFaultsSet,
+ b: &params.EmulationFaults,
+ },
+ }
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetPerfEvents
+func (d *Domain) GetPerfEvents(flags DomainModificationImpact) (*DomainPerfEvents, error) {
+ if C.LIBVIR_VERSION_NUMBER < 1003003 {
+ return nil, makeNotImplementedError("virDomainGetPerfEvents")
+ }
+
+ params := &DomainPerfEvents{}
+ info := getDomainPerfEventsFieldInfo(params)
+
+ var cparams *C.virTypedParameter
+ var nparams C.int
+ var err C.virError
+ ret := C.virDomainGetPerfEventsWrapper(d.ptr, (*C.virTypedParameterPtr)(unsafe.Pointer(&cparams)), &nparams, C.uint(flags), &err)
+ if ret == -1 {
+ return nil, makeError(&err)
+ }
+
+ defer C.virTypedParamsFree(cparams, nparams)
+
+ _, gerr := typedParamsUnpackLen(cparams, int(nparams), info)
+ if gerr != nil {
+ return nil, gerr
+ }
+
+ return params, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSetPerfEvents
+func (d *Domain) SetPerfEvents(params *DomainPerfEvents, flags DomainModificationImpact) error {
+ if C.LIBVIR_VERSION_NUMBER < 1003003 {
+ return makeNotImplementedError("virDomainSetPerfEvents")
+ }
+
+ info := getDomainPerfEventsFieldInfo(params)
+
+ var cparams *C.virTypedParameter
+ var nparams C.int
+ var err C.virError
+ ret := C.virDomainGetPerfEventsWrapper(d.ptr, (*C.virTypedParameterPtr)(unsafe.Pointer(&cparams)), &nparams, C.uint(flags), &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+
+ defer C.virTypedParamsFree(cparams, nparams)
+
+ gerr := typedParamsPackLen(cparams, int(nparams), info)
+ if gerr != nil {
+ return gerr
+ }
+
+ ret = C.virDomainSetPerfEventsWrapper(d.ptr, cparams, nparams, C.uint(flags), &err)
+
+ return nil
+}
+
+type DomainSchedulerParameters struct {
+ Type string
+ CpuSharesSet bool
+ CpuShares uint64
+ GlobalPeriodSet bool
+ GlobalPeriod uint64
+ GlobalQuotaSet bool
+ GlobalQuota int64
+ VcpuPeriodSet bool
+ VcpuPeriod uint64
+ VcpuQuotaSet bool
+ VcpuQuota int64
+ EmulatorPeriodSet bool
+ EmulatorPeriod uint64
+ EmulatorQuotaSet bool
+ EmulatorQuota int64
+ IothreadPeriodSet bool
+ IothreadPeriod uint64
+ IothreadQuotaSet bool
+ IothreadQuota int64
+ WeightSet bool
+ Weight uint
+ CapSet bool
+ Cap uint
+ ReservationSet bool
+ Reservation int64
+ LimitSet bool
+ Limit int64
+ SharesSet bool
+ Shares int
+}
+
+func getDomainSchedulerParametersFieldInfo(params *DomainSchedulerParameters) map[string]typedParamsFieldInfo {
+ return map[string]typedParamsFieldInfo{
+ C.VIR_DOMAIN_SCHEDULER_CPU_SHARES: typedParamsFieldInfo{
+ set: &params.CpuSharesSet,
+ ul: &params.CpuShares,
+ },
+ C.VIR_DOMAIN_SCHEDULER_GLOBAL_PERIOD: typedParamsFieldInfo{
+ set: &params.GlobalPeriodSet,
+ ul: &params.GlobalPeriod,
+ },
+ C.VIR_DOMAIN_SCHEDULER_GLOBAL_QUOTA: typedParamsFieldInfo{
+ set: &params.GlobalQuotaSet,
+ l: &params.GlobalQuota,
+ },
+ C.VIR_DOMAIN_SCHEDULER_EMULATOR_PERIOD: typedParamsFieldInfo{
+ set: &params.EmulatorPeriodSet,
+ ul: &params.EmulatorPeriod,
+ },
+ C.VIR_DOMAIN_SCHEDULER_EMULATOR_QUOTA: typedParamsFieldInfo{
+ set: &params.EmulatorQuotaSet,
+ l: &params.EmulatorQuota,
+ },
+ C.VIR_DOMAIN_SCHEDULER_VCPU_PERIOD: typedParamsFieldInfo{
+ set: &params.VcpuPeriodSet,
+ ul: &params.VcpuPeriod,
+ },
+ C.VIR_DOMAIN_SCHEDULER_VCPU_QUOTA: typedParamsFieldInfo{
+ set: &params.VcpuQuotaSet,
+ l: &params.VcpuQuota,
+ },
+ C.VIR_DOMAIN_SCHEDULER_IOTHREAD_PERIOD: typedParamsFieldInfo{
+ set: &params.IothreadPeriodSet,
+ ul: &params.IothreadPeriod,
+ },
+ C.VIR_DOMAIN_SCHEDULER_IOTHREAD_QUOTA: typedParamsFieldInfo{
+ set: &params.IothreadQuotaSet,
+ l: &params.IothreadQuota,
+ },
+ C.VIR_DOMAIN_SCHEDULER_WEIGHT: typedParamsFieldInfo{
+ set: &params.WeightSet,
+ ui: &params.Weight,
+ },
+ C.VIR_DOMAIN_SCHEDULER_CAP: typedParamsFieldInfo{
+ set: &params.CapSet,
+ ui: &params.Cap,
+ },
+ C.VIR_DOMAIN_SCHEDULER_RESERVATION: typedParamsFieldInfo{
+ set: &params.ReservationSet,
+ l: &params.Reservation,
+ },
+ C.VIR_DOMAIN_SCHEDULER_LIMIT: typedParamsFieldInfo{
+ set: &params.LimitSet,
+ l: &params.Limit,
+ },
+ C.VIR_DOMAIN_SCHEDULER_SHARES: typedParamsFieldInfo{
+ set: &params.SharesSet,
+ i: &params.Shares,
+ },
+ }
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetSchedulerParameters
+func (d *Domain) GetSchedulerParameters() (*DomainSchedulerParameters, error) {
+ params := &DomainSchedulerParameters{}
+ info := getDomainSchedulerParametersFieldInfo(params)
+
+ var nparams C.int
+ var err C.virError
+ schedtype := C.virDomainGetSchedulerTypeWrapper(d.ptr, &nparams, &err)
+ if schedtype == nil {
+ return nil, makeError(&err)
+ }
+
+ defer C.free(unsafe.Pointer(schedtype))
+ if nparams == 0 {
+ return &DomainSchedulerParameters{
+ Type: C.GoString(schedtype),
+ }, nil
+ }
+
+ cparams := make([]C.virTypedParameter, nparams)
+ ret := C.virDomainGetSchedulerParametersWrapper(d.ptr, (*C.virTypedParameter)(unsafe.Pointer(&cparams[0])), &nparams, &err)
+ if ret == -1 {
+ return nil, makeError(&err)
+ }
+ defer C.virTypedParamsClear((*C.virTypedParameter)(unsafe.Pointer(&cparams[0])), nparams)
+
+ _, gerr := typedParamsUnpack(cparams, info)
+ if gerr != nil {
+ return nil, gerr
+ }
+
+ return params, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetSchedulerParametersFlags
+func (d *Domain) GetSchedulerParametersFlags(flags DomainModificationImpact) (*DomainSchedulerParameters, error) {
+ params := &DomainSchedulerParameters{}
+ info := getDomainSchedulerParametersFieldInfo(params)
+
+ var nparams C.int
+ var err C.virError
+ schedtype := C.virDomainGetSchedulerTypeWrapper(d.ptr, &nparams, &err)
+ if schedtype == nil {
+ return nil, makeError(&err)
+ }
+
+ defer C.free(unsafe.Pointer(schedtype))
+ if nparams == 0 {
+ return &DomainSchedulerParameters{
+ Type: C.GoString(schedtype),
+ }, nil
+ }
+
+ cparams := make([]C.virTypedParameter, nparams)
+ ret := C.virDomainGetSchedulerParametersFlagsWrapper(d.ptr, (*C.virTypedParameter)(unsafe.Pointer(&cparams[0])), &nparams, C.uint(flags), &err)
+ if ret == -1 {
+ return nil, makeError(&err)
+ }
+ defer C.virTypedParamsClear((*C.virTypedParameter)(unsafe.Pointer(&cparams[0])), nparams)
+
+ _, gerr := typedParamsUnpack(cparams, info)
+ if gerr != nil {
+ return nil, gerr
+ }
+
+ return params, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSetSchedulerParameters
+func (d *Domain) SetSchedulerParameters(params *DomainSchedulerParameters) error {
+ info := getDomainSchedulerParametersFieldInfo(params)
+
+ var nparams C.int
+ var err C.virError
+ schedtype := C.virDomainGetSchedulerTypeWrapper(d.ptr, &nparams, &err)
+ if schedtype == nil {
+ return makeError(&err)
+ }
+
+ defer C.free(unsafe.Pointer(schedtype))
+ if nparams == 0 {
+ return nil
+ }
+
+ cparams := make([]C.virTypedParameter, nparams)
+ ret := C.virDomainGetSchedulerParametersWrapper(d.ptr, (*C.virTypedParameter)(unsafe.Pointer(&cparams[0])), &nparams, &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+ defer C.virTypedParamsClear((*C.virTypedParameter)(unsafe.Pointer(&cparams[0])), nparams)
+
+ gerr := typedParamsPack(cparams, info)
+ if gerr != nil {
+ return gerr
+ }
+
+ ret = C.virDomainSetSchedulerParametersWrapper(d.ptr, (*C.virTypedParameter)(unsafe.Pointer(&cparams[0])), nparams, &err)
+
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSetSchedulerParametersFlags
+func (d *Domain) SetSchedulerParametersFlags(params *DomainSchedulerParameters, flags DomainModificationImpact) error {
+ info := getDomainSchedulerParametersFieldInfo(params)
+
+ var nparams C.int
+ var err C.virError
+ schedtype := C.virDomainGetSchedulerTypeWrapper(d.ptr, &nparams, &err)
+ if schedtype == nil {
+ return makeError(&err)
+ }
+
+ defer C.free(unsafe.Pointer(schedtype))
+ if nparams == 0 {
+ return nil
+ }
+
+ cparams := make([]C.virTypedParameter, nparams)
+ ret := C.virDomainGetSchedulerParametersFlagsWrapper(d.ptr, (*C.virTypedParameter)(unsafe.Pointer(&cparams[0])), &nparams, 0, &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+ defer C.virTypedParamsClear((*C.virTypedParameter)(unsafe.Pointer(&cparams[0])), nparams)
+
+ gerr := typedParamsPack(cparams, info)
+ if gerr != nil {
+ return gerr
+ }
+
+ ret = C.virDomainSetSchedulerParametersFlagsWrapper(d.ptr, (*C.virTypedParameter)(unsafe.Pointer(&cparams[0])), nparams, C.uint(flags), &err)
+
+ return nil
+}
+
+type SecurityLabel struct {
+ Label string
+ Enforcing bool
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetSecurityLabel
+func (d *Domain) GetSecurityLabel() (*SecurityLabel, error) {
+ var clabel C.virSecurityLabel
+
+ var err C.virError
+ ret := C.virDomainGetSecurityLabelWrapper(d.ptr, &clabel, &err)
+ if ret == -1 {
+ return nil, makeError(&err)
+ }
+
+ return &SecurityLabel{
+ Label: C.GoString((*C.char)(unsafe.Pointer(&clabel.label))),
+ Enforcing: clabel.enforcing == 1,
+ }, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetSecurityLabelList
+func (d *Domain) GetSecurityLabelList() ([]SecurityLabel, error) {
+ var clabels *C.virSecurityLabel
+
+ var err C.virError
+ ret := C.virDomainGetSecurityLabelListWrapper(d.ptr, (*C.virSecurityLabelPtr)(unsafe.Pointer(&clabels)), &err)
+ if ret == -1 {
+ return []SecurityLabel{}, makeError(&err)
+ }
+
+ labels := make([]SecurityLabel, ret)
+ for i := 0; i < int(ret); i++ {
+ var clabel *C.virSecurityLabel
+ clabel = (*C.virSecurityLabel)(unsafe.Pointer(uintptr(unsafe.Pointer(clabels)) + (unsafe.Sizeof(*clabel) * uintptr(i))))
+ labels[i] = SecurityLabel{
+ Label: C.GoString((*C.char)(unsafe.Pointer(&clabel.label))),
+ Enforcing: clabel.enforcing == 1,
+ }
+ }
+
+ return labels, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetTime
+func (d *Domain) GetTime(flags uint32) (int64, uint, error) {
+ if C.LIBVIR_VERSION_NUMBER < 1002005 {
+ return 0, 0, makeNotImplementedError("virDomainGetTime")
+ }
+ var secs C.longlong
+ var nsecs C.uint
+ var err C.virError
+ ret := C.virDomainGetTimeWrapper(d.ptr, &secs, &nsecs, C.uint(flags), &err)
+ if ret == -1 {
+ return 0, 0, makeError(&err)
+ }
+
+ return int64(secs), uint(nsecs), nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSetTime
+func (d *Domain) SetTime(secs int64, nsecs uint, flags DomainSetTimeFlags) error {
+ if C.LIBVIR_VERSION_NUMBER < 1002005 {
+ return makeNotImplementedError("virDomainSetTime")
+ }
+
+ var err C.virError
+ ret := C.virDomainSetTimeWrapper(d.ptr, C.longlong(secs), C.uint(nsecs), C.uint(flags), &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSetUserPassword
+func (d *Domain) SetUserPassword(user string, password string, flags DomainSetUserPasswordFlags) error {
+ if C.LIBVIR_VERSION_NUMBER < 1002015 {
+ return makeNotImplementedError("virDomainSetUserPassword")
+ }
+ cuser := C.CString(user)
+ cpassword := C.CString(password)
+
+ defer C.free(unsafe.Pointer(cuser))
+ defer C.free(unsafe.Pointer(cpassword))
+
+ var err C.virError
+ ret := C.virDomainSetUserPasswordWrapper(d.ptr, cuser, cpassword, C.uint(flags), &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainManagedSave
+func (d *Domain) ManagedSave(flags DomainSaveRestoreFlags) error {
+ var err C.virError
+ ret := C.virDomainManagedSaveWrapper(d.ptr, C.uint(flags), &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainHasManagedSaveImage
+func (d *Domain) HasManagedSaveImage(flags uint32) (bool, error) {
+ var err C.virError
+ result := C.virDomainHasManagedSaveImageWrapper(d.ptr, C.uint(flags), &err)
+ if result == -1 {
+ return false, makeError(&err)
+ }
+ if result == 1 {
+ return true, nil
+ }
+ return false, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainManagedSaveRemove
+func (d *Domain) ManagedSaveRemove(flags uint32) error {
+ var err C.virError
+ ret := C.virDomainManagedSaveRemoveWrapper(d.ptr, C.uint(flags), &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainRename
+func (d *Domain) Rename(name string, flags uint32) error {
+ if C.LIBVIR_VERSION_NUMBER < 1002019 {
+ return makeNotImplementedError("virDomainRename")
+ }
+ cname := C.CString(name)
+ defer C.free(unsafe.Pointer(cname))
+ var err C.virError
+ ret := C.virDomainRenameWrapper(d.ptr, cname, C.uint(flags), &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainReset
+func (d *Domain) Reset(flags uint32) error {
+ var err C.virError
+ ret := C.virDomainResetWrapper(d.ptr, C.uint(flags), &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSendProcessSignal
+func (d *Domain) SendProcessSignal(pid int64, signum DomainProcessSignal, flags uint32) error {
+ var err C.virError
+ ret := C.virDomainSendProcessSignalWrapper(d.ptr, C.longlong(pid), C.uint(signum), C.uint(flags), &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainInjectNMI
+func (d *Domain) InjectNMI(flags uint32) error {
+ var err C.virError
+ ret := C.virDomainInjectNMIWrapper(d.ptr, C.uint(flags), &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainCoreDump
+func (d *Domain) CoreDump(to string, flags DomainCoreDumpFlags) error {
+ cto := C.CString(to)
+ defer C.free(unsafe.Pointer(cto))
+
+ var err C.virError
+ ret := C.virDomainCoreDumpWrapper(d.ptr, cto, C.uint(flags), &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainCoreDumpWithFormat
+func (d *Domain) CoreDumpWithFormat(to string, format DomainCoreDumpFormat, flags DomainCoreDumpFlags) error {
+ if C.LIBVIR_VERSION_NUMBER < 1002003 {
+ makeNotImplementedError("virDomainCoreDumpWithFormat")
+ }
+ cto := C.CString(to)
+ defer C.free(unsafe.Pointer(cto))
+
+ var err C.virError
+ ret := C.virDomainCoreDumpWithFormatWrapper(d.ptr, cto, C.uint(format), C.uint(flags), &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain-snapshot.html#virDomainHasCurrentSnapshot
+func (d *Domain) HasCurrentSnapshot(flags uint32) (bool, error) {
+ var err C.virError
+ result := C.virDomainHasCurrentSnapshotWrapper(d.ptr, C.uint(flags), &err)
+ if result == -1 {
+ return false, makeError(&err)
+ }
+ if result == 1 {
+ return true, nil
+ }
+ return false, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainFSFreeze
+func (d *Domain) FSFreeze(mounts []string, flags uint32) error {
+ if C.LIBVIR_VERSION_NUMBER < 1002005 {
+ return makeNotImplementedError("virDomainFSFreeze")
+ }
+ cmounts := make([](*C.char), len(mounts))
+
+ for i := 0; i < len(mounts); i++ {
+ cmounts[i] = C.CString(mounts[i])
+ defer C.free(unsafe.Pointer(cmounts[i]))
+ }
+
+ nmounts := len(mounts)
+ var err C.virError
+ ret := C.virDomainFSFreezeWrapper(d.ptr, (**C.char)(unsafe.Pointer(&cmounts[0])), C.uint(nmounts), C.uint(flags), &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainFSThaw
+func (d *Domain) FSThaw(mounts []string, flags uint32) error {
+ if C.LIBVIR_VERSION_NUMBER < 1002005 {
+ return makeNotImplementedError("virDomainFSThaw")
+ }
+ cmounts := make([](*C.char), len(mounts))
+
+ for i := 0; i < len(mounts); i++ {
+ cmounts[i] = C.CString(mounts[i])
+ defer C.free(unsafe.Pointer(cmounts[i]))
+ }
+
+ nmounts := len(mounts)
+ var err C.virError
+ ret := C.virDomainFSThawWrapper(d.ptr, (**C.char)(unsafe.Pointer(&cmounts[0])), C.uint(nmounts), C.uint(flags), &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainFSTrim
+func (d *Domain) FSTrim(mount string, minimum uint64, flags uint32) error {
+ var cmount *C.char
+ if mount != "" {
+ cmount := C.CString(mount)
+ defer C.free(unsafe.Pointer(cmount))
+ }
+
+ var err C.virError
+ ret := C.virDomainFSTrimWrapper(d.ptr, cmount, C.ulonglong(minimum), C.uint(flags), &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+
+ return nil
+}
+
+type DomainFSInfo struct {
+ MountPoint string
+ Name string
+ FSType string
+ DevAlias []string
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetFSInfo
+func (d *Domain) GetFSInfo(flags uint32) ([]DomainFSInfo, error) {
+ if C.LIBVIR_VERSION_NUMBER < 1002011 {
+ return []DomainFSInfo{}, makeNotImplementedError("virDomainGetFSInfo")
+ }
+ var cfsinfolist **C.virDomainFSInfo
+
+ var err C.virError
+ ret := C.virDomainGetFSInfoWrapper(d.ptr, (**C.virDomainFSInfoPtr)(unsafe.Pointer(&cfsinfolist)), C.uint(flags), &err)
+ if ret == -1 {
+ return []DomainFSInfo{}, makeError(&err)
+ }
+
+ fsinfo := make([]DomainFSInfo, int(ret))
+
+ for i := 0; i < int(ret); i++ {
+ cfsinfo := (*C.virDomainFSInfo)(*(**C.virDomainFSInfo)(unsafe.Pointer(uintptr(unsafe.Pointer(cfsinfolist)) + (unsafe.Sizeof(*cfsinfolist) * uintptr(i)))))
+
+ aliases := make([]string, int(cfsinfo.ndevAlias))
+ for j := 0; j < int(cfsinfo.ndevAlias); j++ {
+ calias := (*C.char)(*(**C.char)(unsafe.Pointer(uintptr(unsafe.Pointer(cfsinfo.devAlias)) + (unsafe.Sizeof(*cfsinfo) * uintptr(j)))))
+ aliases[j] = C.GoString(calias)
+ }
+ fsinfo[i] = DomainFSInfo{
+ MountPoint: C.GoString(cfsinfo.mountpoint),
+ Name: C.GoString(cfsinfo.name),
+ FSType: C.GoString(cfsinfo.fstype),
+ DevAlias: aliases,
+ }
+
+ C.virDomainFSInfoFreeWrapper(cfsinfo)
+ }
+ C.free(unsafe.Pointer(cfsinfolist))
+
+ return fsinfo, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainPMSuspendForDuration
+func (d *Domain) PMSuspendForDuration(target NodeSuspendTarget, duration uint64, flags uint32) error {
+ var err C.virError
+ ret := C.virDomainPMSuspendForDurationWrapper(d.ptr, C.uint(target), C.ulonglong(duration), C.uint(flags), &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainPMWakeup
+func (d *Domain) PMWakeup(flags uint32) error {
+ var err C.virError
+ ret := C.virDomainPMWakeupWrapper(d.ptr, C.uint(flags), &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainAddIOThread
+func (d *Domain) AddIOThread(id uint, flags DomainModificationImpact) error {
+ if C.LIBVIR_VERSION_NUMBER < 1002015 {
+ return makeNotImplementedError("virDomainAddIOThread")
+ }
+ var err C.virError
+ ret := C.virDomainAddIOThreadWrapper(d.ptr, C.uint(id), C.uint(flags), &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainDelIOThread
+func (d *Domain) DelIOThread(id uint, flags DomainModificationImpact) error {
+ if C.LIBVIR_VERSION_NUMBER < 1002015 {
+ return makeNotImplementedError("virDomainDelIOThread")
+ }
+ var err C.virError
+ ret := C.virDomainDelIOThreadWrapper(d.ptr, C.uint(id), C.uint(flags), &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetEmulatorPinInfo
+func (d *Domain) GetEmulatorPinInfo(flags DomainModificationImpact) ([]bool, error) {
+ var cnodeinfo C.virNodeInfo
+ var err C.virError
+ ret := C.virNodeGetInfoWrapper(C.virDomainGetConnect(d.ptr), &cnodeinfo, &err)
+ if ret == -1 {
+ return []bool{}, makeError(&err)
+ }
+
+ ncpus := cnodeinfo.nodes * cnodeinfo.sockets * cnodeinfo.cores * cnodeinfo.threads
+ maplen := int((ncpus + 7) / 8)
+ ccpumaps := make([]C.uchar, maplen)
+ ret = C.virDomainGetEmulatorPinInfoWrapper(d.ptr, &ccpumaps[0], C.int(maplen), C.uint(flags), &err)
+ if ret == -1 {
+ return []bool{}, makeError(&err)
+ }
+
+ cpumaps := make([]bool, ncpus)
+ for i := 0; i < int(ncpus); i++ {
+ byte := i / 8
+ bit := i % 8
+ cpumaps[i] = (ccpumaps[byte] & (1 << uint(bit))) != 0
+ }
+
+ return cpumaps, nil
+}
+
+type DomainIOThreadInfo struct {
+ IOThreadID uint
+ CpuMap []bool
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetIOThreadInfo
+func (d *Domain) GetIOThreadInfo(flags DomainModificationImpact) ([]DomainIOThreadInfo, error) {
+ if C.LIBVIR_VERSION_NUMBER < 1002014 {
+ return []DomainIOThreadInfo{}, makeNotImplementedError("virDomaingetIOThreadInfo")
+ }
+ var cinfolist **C.virDomainIOThreadInfo
+
+ var err C.virError
+ ret := C.virDomainGetIOThreadInfoWrapper(d.ptr, (**C.virDomainIOThreadInfoPtr)(unsafe.Pointer(&cinfolist)), C.uint(flags), &err)
+ if ret == -1 {
+ return []DomainIOThreadInfo{}, makeError(&err)
+ }
+
+ info := make([]DomainIOThreadInfo, int(ret))
+
+ for i := 0; i < int(ret); i++ {
+ cinfo := (*(**C.virDomainIOThreadInfo)(unsafe.Pointer(uintptr(unsafe.Pointer(cinfolist)) + (unsafe.Sizeof(*cinfolist) * uintptr(i)))))
+
+ ncpus := int(cinfo.cpumaplen * 8)
+ cpumap := make([]bool, ncpus)
+ for j := 0; j < ncpus; j++ {
+ byte := j / 8
+ bit := j % 8
+
+ cpumapbyte := *(*C.uchar)(unsafe.Pointer(uintptr(unsafe.Pointer(cinfo.cpumap)) + (unsafe.Sizeof(*cinfo.cpumap) * uintptr(byte))))
+ cpumap[j] = (cpumapbyte & (1 << uint(bit))) != 0
+ }
+
+ info[i] = DomainIOThreadInfo{
+ IOThreadID: uint(cinfo.iothread_id),
+ CpuMap: cpumap,
+ }
+
+ C.virDomainIOThreadInfoFreeWrapper(cinfo)
+ }
+ C.free(unsafe.Pointer(cinfolist))
+
+ return info, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetVcpuPinInfo
+func (d *Domain) GetVcpuPinInfo(flags DomainModificationImpact) ([][]bool, error) {
+ var cnodeinfo C.virNodeInfo
+ var err C.virError
+ ret := C.virNodeGetInfoWrapper(C.virDomainGetConnect(d.ptr), &cnodeinfo, &err)
+ if ret == -1 {
+ return [][]bool{}, makeError(&err)
+ }
+
+ var cdominfo C.virDomainInfo
+ ret = C.virDomainGetInfoWrapper(d.ptr, &cdominfo, &err)
+ if ret == -1 {
+ return [][]bool{}, makeError(&err)
+ }
+
+ nvcpus := int(cdominfo.nrVirtCpu)
+ npcpus := int(cnodeinfo.nodes * cnodeinfo.sockets * cnodeinfo.cores * cnodeinfo.threads)
+ maplen := ((npcpus + 7) / 8)
+ ccpumaps := make([]C.uchar, maplen*nvcpus)
+
+ ret = C.virDomainGetVcpuPinInfoWrapper(d.ptr, C.int(nvcpus), &ccpumaps[0], C.int(maplen), C.uint(flags), &err)
+ if ret == -1 {
+ return [][]bool{}, makeError(&err)
+ }
+
+ cpumaps := make([][]bool, nvcpus)
+ for i := 0; i < nvcpus; i++ {
+ cpumaps[i] = make([]bool, npcpus)
+ for j := 0; j < npcpus; j++ {
+ byte := (i * maplen) + (j / 8)
+ bit := j % 8
+
+ if (ccpumaps[byte] & (1 << uint(bit))) != 0 {
+ cpumaps[i][j] = true
+ }
+ }
+ }
+
+ return cpumaps, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainPinEmulator
+func (d *Domain) PinEmulator(cpumap []bool, flags DomainModificationImpact) error {
+
+ maplen := (len(cpumap) + 7) / 8
+ ccpumaps := make([]C.uchar, maplen)
+ for i := 0; i < len(cpumap); i++ {
+ if cpumap[i] {
+ byte := i / 8
+ bit := i % 8
+
+ ccpumaps[byte] |= (1 << uint(bit))
+ }
+ }
+
+ var err C.virError
+ ret := C.virDomainPinEmulatorWrapper(d.ptr, &ccpumaps[0], C.int(maplen), C.uint(flags), &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainPinIOThread
+func (d *Domain) PinIOThread(iothreadid uint, cpumap []bool, flags DomainModificationImpact) error {
+ if C.LIBVIR_VERSION_NUMBER < 1002014 {
+ return makeNotImplementedError("virDomainPinIOThread")
+ }
+
+ maplen := (len(cpumap) + 7) / 8
+ ccpumaps := make([]C.uchar, maplen)
+ for i := 0; i < len(cpumap); i++ {
+ if cpumap[i] {
+ byte := i / 8
+ bit := i % 8
+
+ ccpumaps[byte] |= (1 << uint(bit))
+ }
+ }
+
+ var err C.virError
+ ret := C.virDomainPinIOThreadWrapper(d.ptr, C.uint(iothreadid), &ccpumaps[0], C.int(maplen), C.uint(flags), &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainOpenChannel
+func (d *Domain) OpenChannel(name string, stream *Stream, flags DomainChannelFlags) error {
+ cname := C.CString(name)
+ defer C.free(unsafe.Pointer(cname))
+
+ var err C.virError
+ ret := C.virDomainOpenChannelWrapper(d.ptr, cname, stream.ptr, C.uint(flags), &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainOpenConsole
+func (d *Domain) OpenConsole(devname string, stream *Stream, flags DomainConsoleFlags) error {
+ var cdevname *C.char
+ if devname != "" {
+ cdevname = C.CString(devname)
+ defer C.free(unsafe.Pointer(cdevname))
+ }
+
+ var err C.virError
+ ret := C.virDomainOpenConsoleWrapper(d.ptr, cdevname, stream.ptr, C.uint(flags), &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainOpenGraphics
+func (d *Domain) OpenGraphics(idx uint, file os.File, flags DomainOpenGraphicsFlags) error {
+ var err C.virError
+ ret := C.virDomainOpenGraphicsWrapper(d.ptr, C.uint(idx), C.int(file.Fd()), C.uint(flags), &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainOpenGraphicsFD
+func (d *Domain) OpenGraphicsFD(idx uint, flags DomainOpenGraphicsFlags) (*os.File, error) {
+ if C.LIBVIR_VERSION_NUMBER < 1002008 {
+ return nil, makeNotImplementedError("virDomainOpenGraphicsFD")
+ }
+ var err C.virError
+ ret := C.virDomainOpenGraphicsFDWrapper(d.ptr, C.uint(idx), C.uint(flags), &err)
+ if ret == -1 {
+ return nil, makeError(&err)
+ }
+
+ return os.NewFile(uintptr(ret), "graphics"), nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain-snapshot.html#virDomainSnapshotCreateXML
+func (d *Domain) CreateSnapshotXML(xml string, flags DomainSnapshotCreateFlags) (*DomainSnapshot, error) {
+ cXml := C.CString(xml)
+ defer C.free(unsafe.Pointer(cXml))
+ var err C.virError
+ result := C.virDomainSnapshotCreateXMLWrapper(d.ptr, cXml, C.uint(flags), &err)
+ if result == nil {
+ return nil, makeError(&err)
+ }
+ return &DomainSnapshot{ptr: result}, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSave
+func (d *Domain) Save(destFile string) error {
+ cPath := C.CString(destFile)
+ defer C.free(unsafe.Pointer(cPath))
+ var err C.virError
+ result := C.virDomainSaveWrapper(d.ptr, cPath, &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSaveFlags
+func (d *Domain) SaveFlags(destFile string, destXml string, flags DomainSaveRestoreFlags) error {
+ cDestFile := C.CString(destFile)
+ cDestXml := C.CString(destXml)
+ defer C.free(unsafe.Pointer(cDestXml))
+ defer C.free(unsafe.Pointer(cDestFile))
+ var err C.virError
+ result := C.virDomainSaveFlagsWrapper(d.ptr, cDestFile, cDestXml, C.uint(flags), &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+type DomainGuestVcpus struct {
+ Vcpus []bool
+ Online []bool
+ Offlinable []bool
+}
+
+func getDomainGuestVcpusParametersFieldInfo(VcpusSet *bool, Vcpus *string, OnlineSet *bool, Online *string, OfflinableSet *bool, Offlinable *string) map[string]typedParamsFieldInfo {
+ return map[string]typedParamsFieldInfo{
+ "vcpus": typedParamsFieldInfo{
+ set: VcpusSet,
+ s: Vcpus,
+ },
+ "online": typedParamsFieldInfo{
+ set: OnlineSet,
+ s: Online,
+ },
+ "offlinable": typedParamsFieldInfo{
+ set: OfflinableSet,
+ s: Offlinable,
+ },
+ }
+}
+
+func parseCPUString(cpumapstr string) ([]bool, error) {
+ pieces := strings.Split(cpumapstr, ",")
+ var cpumap []bool
+ for _, piece := range pieces {
+ if len(piece) < 1 {
+ return []bool{}, fmt.Errorf("Malformed cpu map string %s", cpumapstr)
+ }
+ invert := false
+ if piece[0] == '^' {
+ invert = true
+ piece = piece[1:]
+ }
+ pair := strings.Split(piece, "-")
+ var start, end int
+ var err error
+ if len(pair) == 1 {
+ start, err = strconv.Atoi(pair[0])
+ if err != nil {
+ return []bool{}, fmt.Errorf("Malformed cpu map string %s", cpumapstr)
+ }
+ end, err = strconv.Atoi(pair[0])
+ if err != nil {
+ return []bool{}, fmt.Errorf("Malformed cpu map string %s", cpumapstr)
+ }
+ } else if len(pair) == 2 {
+ start, err = strconv.Atoi(pair[0])
+ if err != nil {
+ return []bool{}, fmt.Errorf("Malformed cpu map string %s", cpumapstr)
+ }
+ end, err = strconv.Atoi(pair[1])
+ if err != nil {
+ return []bool{}, fmt.Errorf("Malformed cpu map string %s", cpumapstr)
+ }
+ } else {
+ return []bool{}, fmt.Errorf("Malformed cpu map string %s", cpumapstr)
+ }
+ if start > end {
+ return []bool{}, fmt.Errorf("Malformed cpu map string %s", cpumapstr)
+ }
+ if (end + 1) > len(cpumap) {
+ newcpumap := make([]bool, end+1)
+ copy(newcpumap, cpumap)
+ cpumap = newcpumap
+ }
+
+ for i := start; i <= end; i++ {
+ if invert {
+ cpumap[i] = false
+ } else {
+ cpumap[i] = true
+ }
+ }
+ }
+
+ return cpumap, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetGuestVcpus
+func (d *Domain) GetGuestVcpus(flags uint32) (*DomainGuestVcpus, error) {
+ if C.LIBVIR_VERSION_NUMBER < 2000000 {
+ return nil, makeNotImplementedError("virDomainGetGuestVcpus")
+ }
+
+ var VcpusSet, OnlineSet, OfflinableSet bool
+ var VcpusStr, OnlineStr, OfflinableStr string
+ info := getDomainGuestVcpusParametersFieldInfo(&VcpusSet, &VcpusStr, &OnlineSet, &OnlineStr, &OfflinableSet, &OfflinableStr)
+
+ var cparams C.virTypedParameterPtr
+ var nparams C.uint
+ var err C.virError
+ ret := C.virDomainGetGuestVcpusWrapper(d.ptr, &cparams, &nparams, C.uint(flags), &err)
+ if ret == -1 {
+ return nil, makeError(&err)
+ }
+
+ defer C.virTypedParamsFree(cparams, C.int(nparams))
+
+ _, gerr := typedParamsUnpackLen(cparams, int(nparams), info)
+ if gerr != nil {
+ return nil, gerr
+ }
+
+ return &DomainGuestVcpus{}, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSetGuestVcpus
+func (d *Domain) SetGuestVcpus(cpus []bool, state bool, flags uint32) error {
+ if C.LIBVIR_VERSION_NUMBER < 2000000 {
+ return makeNotImplementedError("virDomainSetGuestVcpus")
+ }
+
+ cpumap := ""
+ for i := 0; i < len(cpus); i++ {
+ if cpus[i] {
+ if cpumap == "" {
+ cpumap = string(i)
+ } else {
+ cpumap += "," + string(i)
+ }
+ }
+ }
+
+ var cstate C.int
+ if state {
+ cstate = 1
+ } else {
+ cstate = 0
+ }
+ ccpumap := C.CString(cpumap)
+ defer C.free(unsafe.Pointer(ccpumap))
+ var err C.virError
+ ret := C.virDomainSetGuestVcpusWrapper(d.ptr, ccpumap, cstate, C.uint(flags), &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSetVcpu
+func (d *Domain) SetVcpu(cpus []bool, state bool, flags uint32) error {
+ if C.LIBVIR_VERSION_NUMBER < 3001000 {
+ return makeNotImplementedError("virDomainSetVcpu")
+ }
+
+ cpumap := ""
+ for i := 0; i < len(cpus); i++ {
+ if cpus[i] {
+ if cpumap == "" {
+ cpumap = string(i)
+ } else {
+ cpumap += "," + string(i)
+ }
+ }
+ }
+
+ var cstate C.int
+ if state {
+ cstate = 1
+ } else {
+ cstate = 0
+ }
+ ccpumap := C.CString(cpumap)
+ defer C.free(unsafe.Pointer(ccpumap))
+ var err C.virError
+ ret := C.virDomainSetVcpuWrapper(d.ptr, ccpumap, cstate, C.uint(flags), &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSetBlockThreshold
+func (d *Domain) SetBlockThreshold(dev string, threshold uint64, flags uint32) error {
+ if C.LIBVIR_VERSION_NUMBER < 3002000 {
+ return makeNotImplementedError("virDomainSetBlockThreshold")
+ }
+
+ cdev := C.CString(dev)
+ defer C.free(unsafe.Pointer(cdev))
+ var err C.virError
+ ret := C.virDomainSetBlockThresholdWrapper(d.ptr, cdev, C.ulonglong(threshold), C.uint(flags), &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainManagedSaveDefineXML
+func (d *Domain) ManagedSaveDefineXML(xml string, flags uint32) error {
+ if C.LIBVIR_VERSION_NUMBER < 3007000 {
+ return makeNotImplementedError("virDomainManagedSaveDefineXML")
+ }
+
+ cxml := C.CString(xml)
+ defer C.free(unsafe.Pointer(cxml))
+ var err C.virError
+ ret := C.virDomainManagedSaveDefineXMLWrapper(d.ptr, cxml, C.uint(flags), &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainManagedSaveGetXMLDesc
+func (d *Domain) ManagedSaveGetXMLDesc(flags uint32) (string, error) {
+ if C.LIBVIR_VERSION_NUMBER < 3007000 {
+ return "", makeNotImplementedError("virDomainManagedSaveGetXMLDesc")
+ }
+
+ var err C.virError
+ ret := C.virDomainManagedSaveGetXMLDescWrapper(d.ptr, C.uint(flags), &err)
+ if ret == nil {
+ return "", makeError(&err)
+ }
+
+ xml := C.GoString(ret)
+ C.free(unsafe.Pointer(ret))
+ return xml, nil
+}
+
+type DomainLifecycle int
+
+const (
+ DOMAIN_LIFECYCLE_POWEROFF = DomainLifecycle(C.VIR_DOMAIN_LIFECYCLE_POWEROFF)
+ DOMAIN_LIFECYCLE_REBOOT = DomainLifecycle(C.VIR_DOMAIN_LIFECYCLE_REBOOT)
+ DOMAIN_LIFECYCLE_CRASH = DomainLifecycle(C.VIR_DOMAIN_LIFECYCLE_CRASH)
+)
+
+type DomainLifecycleAction int
+
+const (
+ DOMAIN_LIFECYCLE_ACTION_DESTROY = DomainLifecycleAction(C.VIR_DOMAIN_LIFECYCLE_ACTION_DESTROY)
+ DOMAIN_LIFECYCLE_ACTION_RESTART = DomainLifecycleAction(C.VIR_DOMAIN_LIFECYCLE_ACTION_RESTART)
+ DOMAIN_LIFECYCLE_ACTION_RESTART_RENAME = DomainLifecycleAction(C.VIR_DOMAIN_LIFECYCLE_ACTION_RESTART_RENAME)
+ DOMAIN_LIFECYCLE_ACTION_PRESERVE = DomainLifecycleAction(C.VIR_DOMAIN_LIFECYCLE_ACTION_PRESERVE)
+ DOMAIN_LIFECYCLE_ACTION_COREDUMP_DESTROY = DomainLifecycleAction(C.VIR_DOMAIN_LIFECYCLE_ACTION_COREDUMP_DESTROY)
+ DOMAIN_LIFECYCLE_ACTION_COREDUMP_RESTART = DomainLifecycleAction(C.VIR_DOMAIN_LIFECYCLE_ACTION_COREDUMP_RESTART)
+)
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSetLifecycleAction
+func (d *Domain) SetLifecycleAction(lifecycleType uint32, action uint32, flags uint32) error {
+ if C.LIBVIR_VERSION_NUMBER < 3009000 {
+ return makeNotImplementedError("virDomainSetLifecycleAction")
+ }
+
+ var err C.virError
+ ret := C.virDomainSetLifecycleActionWrapper(d.ptr, C.uint(lifecycleType), C.uint(action), C.uint(flags), &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+
+ return nil
+}
+
+type DomainLaunchSecurityParameters struct {
+ SEVMeasurementSet bool
+ SEVMeasurement string
+}
+
+func getDomainLaunchSecurityFieldInfo(params *DomainLaunchSecurityParameters) map[string]typedParamsFieldInfo {
+ return map[string]typedParamsFieldInfo{
+ C.VIR_DOMAIN_LAUNCH_SECURITY_SEV_MEASUREMENT: typedParamsFieldInfo{
+ set: &params.SEVMeasurementSet,
+ s: &params.SEVMeasurement,
+ },
+ }
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetLaunchSecurityInfo
+func (d *Domain) GetLaunchSecurityInfo(flags uint32) (*DomainLaunchSecurityParameters, error) {
+ if C.LIBVIR_VERSION_NUMBER < 4005000 {
+ return nil, makeNotImplementedError("virDomainGetLaunchSecurityInfo")
+ }
+
+ params := &DomainLaunchSecurityParameters{}
+ info := getDomainLaunchSecurityFieldInfo(params)
+
+ var cparams *C.virTypedParameter
+ var nparams C.int
+
+ var err C.virError
+ ret := C.virDomainGetLaunchSecurityInfoWrapper(d.ptr, (*C.virTypedParameterPtr)(unsafe.Pointer(&cparams)), &nparams, C.uint(flags), &err)
+ if ret == -1 {
+ return nil, makeError(&err)
+ }
+
+ defer C.virTypedParamsFree(cparams, nparams)
+
+ _, gerr := typedParamsUnpackLen(cparams, int(nparams), info)
+ if gerr != nil {
+ return nil, gerr
+ }
+
+ return params, nil
+}
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/domain_compat.h b/src/dma/vendor/github.com/libvirt/libvirt-go/domain_compat.h
new file mode 100644
index 00000000..d20631fc
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/domain_compat.h
@@ -0,0 +1,914 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+#ifndef LIBVIRT_GO_DOMAIN_COMPAT_H__
+#define LIBVIRT_GO_DOMAIN_COMPAT_H__
+
+/* 1.2.2 */
+
+#ifndef VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS
+#define VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS "device_read_iops_sec"
+#endif
+
+#ifndef VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS
+#define VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS "device_write_iops_sec"
+#endif
+
+#ifndef VIR_DOMAIN_BLKIO_DEVICE_READ_BPS
+#define VIR_DOMAIN_BLKIO_DEVICE_READ_BPS "device_read_bytes_sec"
+#endif
+
+#ifndef VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS
+#define VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS "device_write_bytes_sec"
+#endif
+
+
+/* 1.2.3 */
+
+#ifndef VIR_DOMAIN_CORE_DUMP_FORMAT_RAW
+#define VIR_DOMAIN_CORE_DUMP_FORMAT_RAW 0
+#endif
+
+#ifndef VIR_DOMAIN_CORE_DUMP_FORMAT_KDUMP_ZLIB
+#define VIR_DOMAIN_CORE_DUMP_FORMAT_KDUMP_ZLIB 1
+#endif
+
+#ifndef VIR_DOMAIN_CORE_DUMP_FORMAT_KDUMP_LZO
+#define VIR_DOMAIN_CORE_DUMP_FORMAT_KDUMP_LZO 2
+#endif
+
+#ifndef VIR_DOMAIN_CORE_DUMP_FORMAT_KDUMP_SNAPPY
+#define VIR_DOMAIN_CORE_DUMP_FORMAT_KDUMP_SNAPPY 3
+#endif
+
+#ifndef VIR_MIGRATE_AUTO_CONVERGE
+#define VIR_MIGRATE_AUTO_CONVERGE 1 << 13
+#endif
+
+
+/* 1.2.5 */
+
+#ifndef VIR_DOMAIN_REBOOT_PARAVIRT
+#define VIR_DOMAIN_REBOOT_PARAVIRT 1 << 4
+#endif
+
+#ifndef VIR_DOMAIN_SHUTDOWN_PARAVIRT
+#define VIR_DOMAIN_SHUTDOWN_PARAVIRT 1 << 4
+#endif
+
+#ifndef VIR_DOMAIN_TIME_SYNC
+#define VIR_DOMAIN_TIME_SYNC 1 << 0
+#endif
+
+/* 1.2.6 */
+
+#ifndef VIR_DOMAIN_BLOCK_COMMIT_ACTIVE
+#define VIR_DOMAIN_BLOCK_COMMIT_ACTIVE 1 << 2
+#endif
+
+#ifndef VIR_DOMAIN_BLOCK_JOB_TYPE_ACTIVE_COMMIT
+#define VIR_DOMAIN_BLOCK_JOB_TYPE_ACTIVE_COMMIT 4
+#endif
+
+#ifndef VIR_DOMAIN_EVENT_ID_BLOCK_JOB_2
+#define VIR_DOMAIN_EVENT_ID_BLOCK_JOB_2 16
+#endif
+
+
+/* 1.2.7 */
+
+#ifndef VIR_DOMAIN_BLOCK_COMMIT_RELATIVE
+#define VIR_DOMAIN_BLOCK_COMMIT_RELATIVE 1 << 3
+#endif
+
+#ifndef VIR_DOMAIN_BLOCK_REBASE_RELATIVE
+#define VIR_DOMAIN_BLOCK_REBASE_RELATIVE 1 << 4
+#endif
+
+
+/* 1.2.8 */
+
+#ifndef VIR_DOMAIN_BLOCK_COPY_SHALLOW
+#define VIR_DOMAIN_BLOCK_COPY_SHALLOW 1 << 0
+#endif
+
+#ifndef VIR_DOMAIN_BLOCK_COPY_REUSE_EXT
+#define VIR_DOMAIN_BLOCK_COPY_REUSE_EXT 1 << 1
+#endif
+
+#ifndef VIR_DOMAIN_BLOCK_COPY_BANDWIDTH
+#define VIR_DOMAIN_BLOCK_COPY_BANDWIDTH "bandwidth"
+#endif
+
+#ifndef VIR_DOMAIN_BLOCK_COPY_GRANULARITY
+#define VIR_DOMAIN_BLOCK_COPY_GRANULARITY "granularity"
+#endif
+
+#ifndef VIR_DOMAIN_BLOCK_COPY_BUF_SIZE
+#define VIR_DOMAIN_BLOCK_COPY_BUF_SIZE "buf-size"
+#endif
+
+#ifndef VIR_DOMAIN_STATS_STATE
+#define VIR_DOMAIN_STATS_STATE 1 << 0
+#endif
+
+/* 1.2.9 */
+
+#ifndef VIR_DOMAIN_BLOCK_COMMIT_BANDWIDTH_BYTES
+#define VIR_DOMAIN_BLOCK_COMMIT_BANDWIDTH_BYTES 1 << 4
+#endif
+
+#ifndef VIR_DOMAIN_BLOCK_JOB_INFO_BANDWIDTH_BYTES
+#define VIR_DOMAIN_BLOCK_JOB_INFO_BANDWIDTH_BYTES 1 << 0
+#endif
+
+#ifndef VIR_DOMAIN_BLOCK_JOB_SPEED_BANDWIDTH_BYTES
+#define VIR_DOMAIN_BLOCK_JOB_SPEED_BANDWIDTH_BYTES 1 << 0
+#endif
+
+#ifndef VIR_DOMAIN_BLOCK_PULL_BANDWIDTH_BYTES
+#define VIR_DOMAIN_BLOCK_PULL_BANDWIDTH_BYTES 1 << 6
+#endif
+
+#ifndef VIR_DOMAIN_BLOCK_REBASE_COPY_DEV
+#define VIR_DOMAIN_BLOCK_REBASE_COPY_DEV 1 << 5
+#endif
+
+#ifndef VIR_DOMAIN_BLOCK_REBASE_BANDWIDTH_BYTES
+#define VIR_DOMAIN_BLOCK_REBASE_BANDWIDTH_BYTES 1 << 6
+#endif
+
+#ifndef VIR_DOMAIN_JOB_DISK_BPS
+#define VIR_DOMAIN_JOB_DISK_BPS "disk_bps"
+#endif
+
+#ifndef VIR_DOMAIN_JOB_MEMORY_BPS
+#define VIR_DOMAIN_JOB_MEMORY_BPS "memory_bps"
+#endif
+
+#ifndef VIR_DOMAIN_JOB_SETUP_TIME
+#define VIR_DOMAIN_JOB_SETUP_TIME "setup_time"
+#endif
+
+#ifndef VIR_DOMAIN_JOB_STATS_COMPLETED
+#define VIR_DOMAIN_JOB_STATS_COMPLETED 1 << 0
+#endif
+
+#ifndef VIR_DOMAIN_STATS_CPU_TOTAL
+#define VIR_DOMAIN_STATS_CPU_TOTAL 1 << 1
+#endif
+
+#ifndef VIR_DOMAIN_STATS_BALLOON
+#define VIR_DOMAIN_STATS_BALLOON 1 << 2
+#endif
+
+#ifndef VIR_DOMAIN_STATS_VCPU
+#define VIR_DOMAIN_STATS_VCPU 1 << 3
+#endif
+
+#ifndef VIR_DOMAIN_STATS_INTERFACE
+#define VIR_DOMAIN_STATS_INTERFACE 1 << 4
+#endif
+
+#ifndef VIR_DOMAIN_STATS_BLOCK
+#define VIR_DOMAIN_STATS_BLOCK 1 << 5
+#endif
+
+#ifndef VIR_DOMAIN_UNDEFINE_NVRAM
+#define VIR_DOMAIN_UNDEFINE_NVRAM 1 << 2
+#endif
+
+#ifndef VIR_MIGRATE_RDMA_PIN_ALL
+#define VIR_MIGRATE_RDMA_PIN_ALL 1 << 14
+#endif
+
+#ifndef VIR_DOMAIN_EVENT_ID_TUNABLE
+#define VIR_DOMAIN_EVENT_ID_TUNABLE 17
+#endif
+
+#ifndef VIR_DOMAIN_TUNABLE_BLKDEV_DISK
+#define VIR_DOMAIN_TUNABLE_BLKDEV_DISK "blkdeviotune.disk"
+#endif
+
+#ifndef VIR_DOMAIN_TUNABLE_BLKDEV_TOTAL_BYTES_SEC
+#define VIR_DOMAIN_TUNABLE_BLKDEV_TOTAL_BYTES_SEC "blkdeviotune.total_bytes_sec"
+#endif
+
+#ifndef VIR_DOMAIN_TUNABLE_BLKDEV_READ_BYTES_SEC
+#define VIR_DOMAIN_TUNABLE_BLKDEV_READ_BYTES_SEC "blkdeviotune.read_bytes_sec"
+#endif
+
+#ifndef VIR_DOMAIN_TUNABLE_BLKDEV_WRITE_BYTES_SEC
+#define VIR_DOMAIN_TUNABLE_BLKDEV_WRITE_BYTES_SEC "blkdeviotune.write_bytes_sec"
+#endif
+
+#ifndef VIR_DOMAIN_TUNABLE_BLKDEV_TOTAL_IOPS_SEC
+#define VIR_DOMAIN_TUNABLE_BLKDEV_TOTAL_IOPS_SEC "blkdeviotune.total_iops_sec"
+#endif
+
+#ifndef VIR_DOMAIN_TUNABLE_BLKDEV_READ_IOPS_SEC
+#define VIR_DOMAIN_TUNABLE_BLKDEV_READ_IOPS_SEC "blkdeviotune.read_iops_sec"
+#endif
+
+#ifndef VIR_DOMAIN_TUNABLE_BLKDEV_WRITE_IOPS_SEC
+#define VIR_DOMAIN_TUNABLE_BLKDEV_WRITE_IOPS_SEC "blkdeviotune.write_iops_sec"
+#endif
+
+#ifndef VIR_DOMAIN_TUNABLE_CPU_CPU_SHARES
+#define VIR_DOMAIN_TUNABLE_CPU_CPU_SHARES "cputune.cpu_shares"
+#endif
+
+#ifndef VIR_DOMAIN_TUNABLE_CPU_EMULATORPIN
+#define VIR_DOMAIN_TUNABLE_CPU_EMULATORPIN "cputune.emulatorpin"
+#endif
+
+#ifndef VIR_DOMAIN_TUNABLE_CPU_EMULATOR_PERIOD
+#define VIR_DOMAIN_TUNABLE_CPU_EMULATOR_PERIOD "cputune.emulator_period"
+#endif
+
+#ifndef VIR_DOMAIN_TUNABLE_CPU_EMULATOR_QUOTA
+#define VIR_DOMAIN_TUNABLE_CPU_EMULATOR_QUOTA "cputune.emulator_quota"
+#endif
+
+#ifndef VIR_DOMAIN_TUNABLE_CPU_VCPU_PERIOD
+#define VIR_DOMAIN_TUNABLE_CPU_VCPU_PERIOD "cputune.vcpu_period"
+#endif
+
+#ifndef VIR_DOMAIN_TUNABLE_CPU_VCPU_QUOTA
+#define VIR_DOMAIN_TUNABLE_CPU_VCPU_QUOTA "cputune.vcpu_quota"
+#endif
+
+
+
+/* 1.2.11 */
+
+#ifndef VIR_DOMAIN_TUNABLE_BLKDEV_TOTAL_BYTES_SEC_MAX
+#define VIR_DOMAIN_TUNABLE_BLKDEV_TOTAL_BYTES_SEC_MAX "blkdeviotune.total_bytes_sec_max"
+#endif
+
+#ifndef VIR_DOMAIN_TUNABLE_BLKDEV_READ_BYTES_SEC_MAX
+#define VIR_DOMAIN_TUNABLE_BLKDEV_READ_BYTES_SEC_MAX "blkdeviotune.read_bytes_sec_max"
+#endif
+
+#ifndef VIR_DOMAIN_TUNABLE_BLKDEV_WRITE_BYTES_SEC_MAX
+#define VIR_DOMAIN_TUNABLE_BLKDEV_WRITE_BYTES_SEC_MAX "blkdeviotune.write_bytes_sec_max"
+#endif
+
+#ifndef VIR_DOMAIN_TUNABLE_BLKDEV_TOTAL_IOPS_SEC_MAX
+#define VIR_DOMAIN_TUNABLE_BLKDEV_TOTAL_IOPS_SEC_MAX "blkdeviotune.total_iops_sec_max"
+#endif
+
+#ifndef VIR_DOMAIN_TUNABLE_BLKDEV_READ_IOPS_SEC_MAX
+#define VIR_DOMAIN_TUNABLE_BLKDEV_READ_IOPS_SEC_MAX "blkdeviotune.read_iops_sec_max"
+#endif
+
+#ifndef VIR_DOMAIN_TUNABLE_BLKDEV_WRITE_IOPS_SEC_MAX
+#define VIR_DOMAIN_TUNABLE_BLKDEV_WRITE_IOPS_SEC_MAX "blkdeviotune.write_iops_sec_max"
+#endif
+
+#ifndef VIR_DOMAIN_TUNABLE_BLKDEV_SIZE_IOPS_SEC
+#define VIR_DOMAIN_TUNABLE_BLKDEV_SIZE_IOPS_SEC "blkdeviotune.size_iops_sec"
+#endif
+
+#ifndef VIR_DOMAIN_EVENT_ID_AGENT_LIFECYCLE
+#define VIR_DOMAIN_EVENT_ID_AGENT_LIFECYCLE 18
+#endif
+
+#ifndef VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_BYTES_SEC_MAX
+#define VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_BYTES_SEC_MAX "total_bytes_sec_max"
+#endif
+
+#ifndef VIR_DOMAIN_BLOCK_IOTUNE_READ_BYTES_SEC_MAX
+#define VIR_DOMAIN_BLOCK_IOTUNE_READ_BYTES_SEC_MAX "read_bytes_sec_max"
+#endif
+
+#ifndef VIR_DOMAIN_BLOCK_IOTUNE_WRITE_BYTES_SEC_MAX
+#define VIR_DOMAIN_BLOCK_IOTUNE_WRITE_BYTES_SEC_MAX "write_bytes_sec_max"
+#endif
+
+#ifndef VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_IOPS_SEC_MAX
+#define VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_IOPS_SEC_MAX "total_iops_sec_max"
+#endif
+
+#ifndef VIR_DOMAIN_BLOCK_IOTUNE_READ_IOPS_SEC_MAX
+#define VIR_DOMAIN_BLOCK_IOTUNE_READ_IOPS_SEC_MAX "read_iops_sec_max"
+#endif
+
+#ifndef VIR_DOMAIN_BLOCK_IOTUNE_WRITE_IOPS_SEC_MAX
+#define VIR_DOMAIN_BLOCK_IOTUNE_WRITE_IOPS_SEC_MAX "write_iops_sec_max"
+#endif
+
+#ifndef VIR_DOMAIN_BLOCK_IOTUNE_SIZE_IOPS_SEC
+#define VIR_DOMAIN_BLOCK_IOTUNE_SIZE_IOPS_SEC "size_iops_sec"
+#endif
+
+#if LIBVIR_VERSION_NUMBER < 1002011
+typedef struct _virDomainFSInfo virDomainFSInfo;
+typedef virDomainFSInfo *virDomainFSInfoPtr;
+struct _virDomainFSInfo {
+ char *mountpoint; /* path to mount point */
+ char *name; /* device name in the guest (e.g. "sda1") */
+ char *fstype; /* filesystem type */
+ size_t ndevAlias; /* number of elements in devAlias */
+ char **devAlias; /* array of disk device aliases */
+};
+#endif
+
+/* 1.2.12 */
+
+#ifndef VIR_DOMAIN_DEFINE_VALIDATE
+#define VIR_DOMAIN_DEFINE_VALIDATE 1 << 0
+#endif
+
+#ifndef VIR_DOMAIN_START_VALIDATE
+#define VIR_DOMAIN_START_VALIDATE 1 << 4
+#endif
+
+
+/* 1.2.14 */
+
+#ifndef VIR_DOMAIN_CONTROL_ERROR_REASON_NONE
+#define VIR_DOMAIN_CONTROL_ERROR_REASON_NONE 0
+#endif
+
+#ifndef VIR_DOMAIN_CONTROL_ERROR_REASON_UNKNOWN
+#define VIR_DOMAIN_CONTROL_ERROR_REASON_UNKNOWN 1
+#endif
+
+#ifndef VIR_DOMAIN_CONTROL_ERROR_REASON_MONITOR
+#define VIR_DOMAIN_CONTROL_ERROR_REASON_MONITOR 2
+#endif
+
+#ifndef VIR_DOMAIN_CONTROL_ERROR_REASON_INTERNAL
+#define VIR_DOMAIN_CONTROL_ERROR_REASON_INTERNAL 3
+#endif
+
+#ifndef VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_LEASE
+#define VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_LEASE 0
+#endif
+
+#ifndef VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_AGENT
+#define VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_AGENT 1
+#endif
+
+#ifndef VIR_DOMAIN_PAUSED_STARTING_UP
+#define VIR_DOMAIN_PAUSED_STARTING_UP 11
+#endif
+
+#if LIBVIR_VERSION_NUMBER < 1002014
+typedef struct _virDomainIOThreadInfo virDomainIOThreadInfo;
+typedef virDomainIOThreadInfo *virDomainIOThreadInfoPtr;
+struct _virDomainIOThreadInfo {
+ unsigned int iothread_id; /* IOThread ID */
+ unsigned char *cpumap; /* CPU map for thread. A pointer to an */
+ /* array of real CPUs (in 8-bit bytes) */
+ int cpumaplen; /* cpumap size */
+};
+
+typedef struct _virDomainInterfaceIPAddress virDomainIPAddress;
+typedef virDomainIPAddress *virDomainIPAddressPtr;
+struct _virDomainInterfaceIPAddress {
+ int type; /* virIPAddrType */
+ char *addr; /* IP address */
+ unsigned int prefix; /* IP address prefix */
+};
+
+typedef struct _virDomainInterface virDomainInterface;
+typedef virDomainInterface *virDomainInterfacePtr;
+struct _virDomainInterface {
+ char *name; /* interface name */
+ char *hwaddr; /* hardware address, may be NULL */
+ unsigned int naddrs; /* number of items in @addrs */
+ virDomainIPAddressPtr addrs; /* array of IP addresses */
+};
+#endif
+
+
+/* 1.2.15 */
+
+#ifndef VIR_DOMAIN_JOB_DOWNTIME_NET
+#define VIR_DOMAIN_JOB_DOWNTIME_NET "downtime_net"
+#endif
+
+#ifndef VIR_DOMAIN_JOB_TIME_ELAPSED_NET
+#define VIR_DOMAIN_JOB_TIME_ELAPSED_NET "time_elapsed_net"
+#endif
+
+#ifndef VIR_DOMAIN_EVENT_ID_DEVICE_ADDED
+#define VIR_DOMAIN_EVENT_ID_DEVICE_ADDED 19
+#endif
+
+
+/* 1.2.16 */
+
+#ifndef VIR_DOMAIN_PASSWORD_ENCRYPTED
+#define VIR_DOMAIN_PASSWORD_ENCRYPTED 1 << 0
+#endif
+
+
+/* 1.2.17 */
+
+#ifndef VIR_DOMAIN_EVENT_WATCHDOG_INJECTNMI
+#define VIR_DOMAIN_EVENT_WATCHDOG_INJECTNMI 6
+#endif
+
+#ifndef VIR_MIGRATE_PARAM_MIGRATE_DISKS
+#define VIR_MIGRATE_PARAM_MIGRATE_DISKS "migrate_disks"
+#endif
+
+
+/* 1.2.19 */
+
+#ifndef VIR_DOMAIN_BANDWIDTH_IN_FLOOR
+#define VIR_DOMAIN_BANDWIDTH_IN_FLOOR "inbound.floor"
+#endif
+
+#ifndef VIR_DOMAIN_EVENT_DEFINED_RENAMED
+#define VIR_DOMAIN_EVENT_DEFINED_RENAMED 2
+#endif
+
+#ifndef VIR_DOMAIN_EVENT_UNDEFINED_RENAMED
+#define VIR_DOMAIN_EVENT_UNDEFINED_RENAMED 1
+#endif
+
+
+/* 1.3.1 */
+
+#ifndef VIR_DOMAIN_JOB_MEMORY_DIRTY_RATE
+#define VIR_DOMAIN_JOB_MEMORY_DIRTY_RATE "memory_dirty_rate"
+#endif
+
+#ifndef VIR_DOMAIN_JOB_MEMORY_ITERATION
+#define VIR_DOMAIN_JOB_MEMORY_ITERATION "memory_iteration"
+#endif
+
+
+/* 1.3.2 */
+
+#ifndef VIR_DOMAIN_EVENT_ID_MIGRATION_ITERATION
+#define VIR_DOMAIN_EVENT_ID_MIGRATION_ITERATION 20
+#endif
+
+
+/* 1.3.3 */
+
+#ifndef VIR_DOMAIN_EVENT_DEFINED_FROM_SNAPSHOT
+#define VIR_DOMAIN_EVENT_DEFINED_FROM_SNAPSHOT 3
+#endif
+
+#ifndef VIR_DOMAIN_EVENT_RESUMED_POSTCOPY
+#define VIR_DOMAIN_EVENT_RESUMED_POSTCOPY 3
+#endif
+
+#ifndef VIR_DOMAIN_EVENT_SUSPENDED_POSTCOPY
+#define VIR_DOMAIN_EVENT_SUSPENDED_POSTCOPY 7
+#endif
+
+#ifndef VIR_DOMAIN_EVENT_SUSPENDED_POSTCOPY_FAILED
+#define VIR_DOMAIN_EVENT_SUSPENDED_POSTCOPY_FAILED 8
+#endif
+
+#ifndef VIR_DOMAIN_PAUSED_POSTCOPY
+#define VIR_DOMAIN_PAUSED_POSTCOPY 12
+#endif
+
+#ifndef VIR_DOMAIN_PAUSED_POSTCOPY_FAILED
+#define VIR_DOMAIN_PAUSED_POSTCOPY_FAILED 13
+#endif
+
+#ifndef VIR_DOMAIN_RUNNING_POSTCOPY
+#define VIR_DOMAIN_RUNNING_POSTCOPY 10
+#endif
+
+#ifndef VIR_DOMAIN_SCHEDULER_GLOBAL_PERIOD
+#define VIR_DOMAIN_SCHEDULER_GLOBAL_PERIOD "global_period"
+#endif
+
+#ifndef VIR_DOMAIN_SCHEDULER_GLOBAL_QUOTA
+#define VIR_DOMAIN_SCHEDULER_GLOBAL_QUOTA "global_quota"
+#endif
+
+#ifndef VIR_DOMAIN_STATS_PERF
+#define VIR_DOMAIN_STATS_PERF (1 << 6)
+#endif
+
+#ifndef VIR_MIGRATE_PARAM_DISKS_PORT
+#define VIR_MIGRATE_PARAM_DISKS_PORT "disks_port"
+#endif
+
+#ifndef VIR_PERF_PARAM_CMT
+#define VIR_PERF_PARAM_CMT "cmt"
+#endif
+
+#ifndef VIR_MIGRATE_POSTCOPY
+#define VIR_MIGRATE_POSTCOPY (1 << 15)
+#endif
+
+#ifndef VIR_DOMAIN_EVENT_ID_JOB_COMPLETED
+#define VIR_DOMAIN_EVENT_ID_JOB_COMPLETED 21
+#endif
+
+#ifndef VIR_DOMAIN_TUNABLE_CPU_GLOBAL_PERIOD
+#define VIR_DOMAIN_TUNABLE_CPU_GLOBAL_PERIOD "cputune.global_period"
+#endif
+
+#ifndef VIR_DOMAIN_TUNABLE_CPU_GLOBAL_QUOTA
+#define VIR_DOMAIN_TUNABLE_CPU_GLOBAL_QUOTA "cputune.global_quota"
+#endif
+
+/* 1.3.4 */
+
+#ifndef VIR_MIGRATE_PARAM_COMPRESSION
+#define VIR_MIGRATE_PARAM_COMPRESSION "compression"
+#endif
+
+#ifndef VIR_MIGRATE_PARAM_COMPRESSION_MT_THREADS
+#define VIR_MIGRATE_PARAM_COMPRESSION_MT_THREADS "compression.mt.threads"
+#endif
+
+#ifndef VIR_MIGRATE_PARAM_COMPRESSION_MT_DTHREADS
+#define VIR_MIGRATE_PARAM_COMPRESSION_MT_DTHREADS "compression.mt.dthreads"
+#endif
+
+#ifndef VIR_MIGRATE_PARAM_COMPRESSION_MT_LEVEL
+#define VIR_MIGRATE_PARAM_COMPRESSION_MT_LEVEL "compression.mt.level"
+#endif
+
+#ifndef VIR_MIGRATE_PARAM_COMPRESSION_XBZRLE_CACHE
+#define VIR_MIGRATE_PARAM_COMPRESSION_XBZRLE_CACHE "compression.xbzrle.cache"
+#endif
+
+#ifndef VIR_MIGRATE_PARAM_PERSIST_XML
+#define VIR_MIGRATE_PARAM_PERSIST_XML "persistent_xml"
+#endif
+
+#ifndef VIR_DOMAIN_EVENT_ID_DEVICE_REMOVAL_FAILED
+#define VIR_DOMAIN_EVENT_ID_DEVICE_REMOVAL_FAILED 22
+#endif
+
+
+/* 1.3.5 */
+
+#ifndef VIR_PERF_PARAM_MBML
+#define VIR_PERF_PARAM_MBML "mbml"
+#endif
+
+#ifndef VIR_PERF_PARAM_MBMT
+#define VIR_PERF_PARAM_MBMT "mbmt"
+#endif
+
+
+/* 2.0.0 */
+
+#ifndef VIR_DOMAIN_JOB_AUTO_CONVERGE_THROTTLE
+#define VIR_DOMAIN_JOB_AUTO_CONVERGE_THROTTLE "auto_converge_throttle"
+#endif
+
+#ifndef VIR_MIGRATE_PARAM_AUTO_CONVERGE_INITIAL
+#define VIR_MIGRATE_PARAM_AUTO_CONVERGE_INITIAL "auto_converge.initial"
+#endif
+
+#ifndef VIR_MIGRATE_PARAM_AUTO_CONVERGE_INCREMENT
+#define VIR_MIGRATE_PARAM_AUTO_CONVERGE_INCREMENT "auto_converge.increment"
+#endif
+
+/* 2.1.0 */
+
+#ifndef VIR_DOMAIN_MEMORY_STAT_USABLE
+#define VIR_DOMAIN_MEMORY_STAT_USABLE 8
+#endif
+
+#ifndef VIR_DOMAIN_MEMORY_STAT_LAST_UPDATE
+#define VIR_DOMAIN_MEMORY_STAT_LAST_UPDATE 9
+#endif
+
+/* 2.2.0 */
+
+#ifndef VIR_DOMAIN_SCHEDULER_IOTHREAD_PERIOD
+#define VIR_DOMAIN_SCHEDULER_IOTHREAD_PERIOD "iothread_period"
+#endif
+
+#ifndef VIR_DOMAIN_SCHEDULER_IOTHREAD_QUOTA
+#define VIR_DOMAIN_SCHEDULER_IOTHREAD_QUOTA "iothread_quota"
+#endif
+
+#ifndef VIR_DOMAIN_TUNABLE_CPU_IOTHREAD_PERIOD
+#define VIR_DOMAIN_TUNABLE_CPU_IOTHREAD_PERIOD "cputune.iothread_period"
+#endif
+
+#ifndef VIR_DOMAIN_TUNABLE_CPU_IOTHREAD_QUOTA
+# define VIR_DOMAIN_TUNABLE_CPU_IOTHREAD_QUOTA "cputune.iothread_quota"
+#endif
+
+
+/* 2.3.0 */
+
+#ifndef VIR_DOMAIN_UNDEFINE_KEEP_NVRAM
+#define VIR_DOMAIN_UNDEFINE_KEEP_NVRAM (1 << 3)
+#endif
+
+#ifndef VIR_PERF_PARAM_CACHE_MISSES
+#define VIR_PERF_PARAM_CACHE_MISSES "cache_misses"
+#endif
+
+#ifndef VIR_PERF_PARAM_CACHE_REFERENCES
+#define VIR_PERF_PARAM_CACHE_REFERENCES "cache_references"
+#endif
+
+#ifndef VIR_PERF_PARAM_INSTRUCTIONS
+#define VIR_PERF_PARAM_INSTRUCTIONS "instructions"
+#endif
+
+#ifndef VIR_PERF_PARAM_CPU_CYCLES
+#define VIR_PERF_PARAM_CPU_CYCLES "cpu_cycles"
+#endif
+
+
+/* 2.4.0 */
+
+#ifndef VIR_DOMAIN_BLOCK_IOTUNE_READ_BYTES_SEC_MAX_LENGTH
+#define VIR_DOMAIN_BLOCK_IOTUNE_READ_BYTES_SEC_MAX_LENGTH "read_bytes_sec_max_length"
+#endif
+
+#ifndef VIR_DOMAIN_BLOCK_IOTUNE_READ_IOPS_SEC_MAX_LENGTH
+#define VIR_DOMAIN_BLOCK_IOTUNE_READ_IOPS_SEC_MAX_LENGTH "read_iops_sec_max_length"
+#endif
+
+#ifndef VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_BYTES_SEC_MAX_LENGTH
+#define VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_BYTES_SEC_MAX_LENGTH "total_bytes_sec_max_length"
+#endif
+
+#ifndef VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_IOPS_SEC_MAX_LENGTH
+#define VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_IOPS_SEC_MAX_LENGTH "total_iops_sec_max_length"
+#endif
+
+#ifndef VIR_DOMAIN_BLOCK_IOTUNE_WRITE_BYTES_SEC_MAX_LENGTH
+#define VIR_DOMAIN_BLOCK_IOTUNE_WRITE_BYTES_SEC_MAX_LENGTH "write_bytes_sec_max_length"
+#endif
+
+#ifndef VIR_DOMAIN_BLOCK_IOTUNE_WRITE_IOPS_SEC_MAX_LENGTH
+#define VIR_DOMAIN_BLOCK_IOTUNE_WRITE_IOPS_SEC_MAX_LENGTH "write_iopcs_sec_max_length"
+#endif
+
+#ifndef VIR_DOMAIN_TUNABLE_BLKDEV_TOTAL_BYTES_SEC_MAX_LENGTH
+#define VIR_DOMAIN_TUNABLE_BLKDEV_TOTAL_BYTES_SEC_MAX_LENGTH "blkdeviotune.total_bytes_sec_max_length"
+#endif
+
+#ifndef VIR_DOMAIN_TUNABLE_BLKDEV_READ_BYTES_SEC_MAX_LENGTH
+#define VIR_DOMAIN_TUNABLE_BLKDEV_READ_BYTES_SEC_MAX_LENGTH "blkdeviotune.read_bytes_sec_max_length"
+#endif
+
+#ifndef VIR_DOMAIN_TUNABLE_BLKDEV_WRITE_BYTES_SEC_MAX_LENGTH
+#define VIR_DOMAIN_TUNABLE_BLKDEV_WRITE_BYTES_SEC_MAX_LENGTH "blkdeviotune.write_bytes_sec_max_length"
+#endif
+
+#ifndef VIR_DOMAIN_TUNABLE_BLKDEV_TOTAL_IOPS_SEC_MAX_LENGTH
+#define VIR_DOMAIN_TUNABLE_BLKDEV_TOTAL_IOPS_SEC_MAX_LENGTH "blkdeviotune.total_iops_sec_max_length"
+#endif
+
+#ifndef VIR_DOMAIN_TUNABLE_BLKDEV_READ_IOPS_SEC_MAX_LENGTH
+#define VIR_DOMAIN_TUNABLE_BLKDEV_READ_IOPS_SEC_MAX_LENGTH "blkdeviotune.read_iops_sec_max_length"
+#endif
+
+#ifndef VIR_DOMAIN_TUNABLE_BLKDEV_WRITE_IOPS_SEC_MAX_LENGTH
+#define VIR_DOMAIN_TUNABLE_BLKDEV_WRITE_IOPS_SEC_MAX_LENGTH "blkdeviotune.write_iops_sec_max_length"
+#endif
+
+#ifndef VIR_DOMAIN_VCPU_HOTPLUGGABLE
+#define VIR_DOMAIN_VCPU_HOTPLUGGABLE (1 << 4)
+#endif
+
+/* 3.0.0 */
+
+#ifndef VIR_PERF_PARAM_BRANCH_INSTRUCTIONS
+#define VIR_PERF_PARAM_BRANCH_INSTRUCTIONS "branch_instructions"
+#endif
+
+#ifndef VIR_PERF_PARAM_BRANCH_MISSES
+#define VIR_PERF_PARAM_BRANCH_MISSES "branch_misses"
+#endif
+
+#ifndef VIR_PERF_PARAM_BUS_CYCLES
+#define VIR_PERF_PARAM_BUS_CYCLES "bus_cycles"
+#endif
+
+#ifndef VIR_PERF_PARAM_STALLED_CYCLES_FRONTEND
+#define VIR_PERF_PARAM_STALLED_CYCLES_FRONTEND "stalled_cycles_frontend"
+#endif
+
+#ifndef VIR_PERF_PARAM_STALLED_CYCLES_BACKEND
+#define VIR_PERF_PARAM_STALLED_CYCLES_BACKEND "stalled_cycles_backend"
+#endif
+
+#ifndef VIR_PERF_PARAM_REF_CPU_CYCLES
+#define VIR_PERF_PARAM_REF_CPU_CYCLES "ref_cpu_cycles"
+#endif
+
+#ifndef VIR_PERF_PARAM_CPU_CLOCK
+#define VIR_PERF_PARAM_CPU_CLOCK "cpu_clock"
+#endif
+
+#ifndef VIR_PERF_PARAM_TASK_CLOCK
+#define VIR_PERF_PARAM_TASK_CLOCK "task_clock"
+#endif
+
+#ifndef VIR_PERF_PARAM_PAGE_FAULTS
+#define VIR_PERF_PARAM_PAGE_FAULTS "page_faults"
+#endif
+
+#ifndef VIR_PERF_PARAM_CONTEXT_SWITCHES
+#define VIR_PERF_PARAM_CONTEXT_SWITCHES "context_switches"
+#endif
+
+#ifndef VIR_PERF_PARAM_CPU_MIGRATIONS
+#define VIR_PERF_PARAM_CPU_MIGRATIONS "cpu_migrations"
+#endif
+
+#ifndef VIR_PERF_PARAM_PAGE_FAULTS_MIN
+#define VIR_PERF_PARAM_PAGE_FAULTS_MIN "page_faults_min"
+#endif
+
+#ifndef VIR_PERF_PARAM_PAGE_FAULTS_MAJ
+#define VIR_PERF_PARAM_PAGE_FAULTS_MAJ "page_faults_maj"
+#endif
+
+#ifndef VIR_PERF_PARAM_ALIGNMENT_FAULTS
+#define VIR_PERF_PARAM_ALIGNMENT_FAULTS "alignment_faults"
+#endif
+
+#ifndef VIR_PERF_PARAM_EMULATION_FAULTS
+#define VIR_PERF_PARAM_EMULATION_FAULTS "emulation_faults"
+#endif
+
+#ifndef VIR_DOMAIN_EVENT_ID_METADATA_CHANGE
+#define VIR_DOMAIN_EVENT_ID_METADATA_CHANGE 23
+#endif
+
+#ifndef VIR_DOMAIN_BLOCK_IOTUNE_GROUP_NAME
+#define VIR_DOMAIN_BLOCK_IOTUNE_GROUP_NAME "group_name"
+#endif
+
+#ifndef VIR_DOMAIN_TUNABLE_BLKDEV_GROUP_NAME
+#define VIR_DOMAIN_TUNABLE_BLKDEV_GROUP_NAME "blkdeviotune.group_name"
+#endif
+
+/* 3.2.0 */
+
+#ifndef VIR_MIGRATE_TLS
+#define VIR_MIGRATE_TLS 1 << 16
+#endif
+
+#ifndef VIR_DOMAIN_EVENT_ID_BLOCK_THRESHOLD
+#define VIR_DOMAIN_EVENT_ID_BLOCK_THRESHOLD 24
+#endif
+
+/* 3.3.0 */
+
+#ifndef VIR_DOMAIN_JOB_OPERATION
+#define VIR_DOMAIN_JOB_OPERATION "operation"
+#endif
+
+#ifndef VIR_DOMAIN_JOB_OPERATION_UNKNOWN
+#define VIR_DOMAIN_JOB_OPERATION_UNKNOWN 0
+#endif
+
+#ifndef VIR_DOMAIN_JOB_OPERATION_START
+#define VIR_DOMAIN_JOB_OPERATION_START 1
+#endif
+
+#ifndef VIR_DOMAIN_JOB_OPERATION_SAVE
+#define VIR_DOMAIN_JOB_OPERATION_SAVE 2
+#endif
+
+#ifndef VIR_DOMAIN_JOB_OPERATION_RESTORE
+#define VIR_DOMAIN_JOB_OPERATION_RESTORE 3
+#endif
+
+#ifndef VIR_DOMAIN_JOB_OPERATION_MIGRATION_IN
+#define VIR_DOMAIN_JOB_OPERATION_MIGRATION_IN 4
+#endif
+
+#ifndef VIR_DOMAIN_JOB_OPERATION_MIGRATION_OUT
+#define VIR_DOMAIN_JOB_OPERATION_MIGRATION_OUT 5
+#endif
+
+#ifndef VIR_DOMAIN_JOB_OPERATION_SNAPSHOT
+#define VIR_DOMAIN_JOB_OPERATION_SNAPSHOT 6
+#endif
+
+#ifndef VIR_DOMAIN_JOB_OPERATION_SNAPSHOT_REVERT
+#define VIR_DOMAIN_JOB_OPERATION_SNAPSHOT_REVERT 7
+#endif
+
+#ifndef VIR_DOMAIN_JOB_OPERATION_DUMP
+#define VIR_DOMAIN_JOB_OPERATION_DUMP 8
+#endif
+
+
+/* 3.4.0 */
+
+#ifndef VIR_DOMAIN_EVENT_SHUTDOWN_GUEST
+#define VIR_DOMAIN_EVENT_SHUTDOWN_GUEST 1
+#endif
+
+#ifndef VIR_DOMAIN_EVENT_SHUTDOWN_HOST
+#define VIR_DOMAIN_EVENT_SHUTDOWN_HOST 2
+#endif
+
+
+/* 3.5.0 */
+
+#ifndef VIR_DOMAIN_BLOCK_COPY_TRANSIENT_JOB
+#define VIR_DOMAIN_BLOCK_COPY_TRANSIENT_JOB 1 << 2
+#endif
+
+
+/* 3.9.0 */
+
+#ifndef VIR_DOMAIN_JOB_MEMORY_PAGE_SIZE
+#define VIR_DOMAIN_JOB_MEMORY_PAGE_SIZE "memory_page_size"
+#endif
+
+#ifndef VIR_DOMAIN_LIFECYCLE_POWEROFF
+#define VIR_DOMAIN_LIFECYCLE_POWEROFF 0
+#endif
+
+#ifndef VIR_DOMAIN_LIFECYCLE_REBOOT
+#define VIR_DOMAIN_LIFECYCLE_REBOOT 1
+#endif
+
+#ifndef VIR_DOMAIN_LIFECYCLE_CRASH
+#define VIR_DOMAIN_LIFECYCLE_CRASH 2
+#endif
+
+#ifndef VIR_DOMAIN_LIFECYCLE_ACTION_DESTROY
+#define VIR_DOMAIN_LIFECYCLE_ACTION_DESTROY 0
+#endif
+
+#ifndef VIR_DOMAIN_LIFECYCLE_ACTION_RESTART
+#define VIR_DOMAIN_LIFECYCLE_ACTION_RESTART 1
+#endif
+
+#ifndef VIR_DOMAIN_LIFECYCLE_ACTION_RESTART_RENAME
+#define VIR_DOMAIN_LIFECYCLE_ACTION_RESTART_RENAME 2
+#endif
+
+#ifndef VIR_DOMAIN_LIFECYCLE_ACTION_PRESERVE
+#define VIR_DOMAIN_LIFECYCLE_ACTION_PRESERVE 3
+#endif
+
+#ifndef VIR_DOMAIN_LIFECYCLE_ACTION_COREDUMP_DESTROY
+#define VIR_DOMAIN_LIFECYCLE_ACTION_COREDUMP_DESTROY 4
+#endif
+
+#ifndef VIR_DOMAIN_LIFECYCLE_ACTION_COREDUMP_RESTART
+#define VIR_DOMAIN_LIFECYCLE_ACTION_COREDUMP_RESTART 5
+#endif
+
+/* 4.2.0 */
+
+#ifndef VIR_KEYCODE_SET_QNUM
+#define VIR_KEYCODE_SET_QNUM 9
+#endif
+
+#ifndef VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_ARP
+#define VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_ARP 1
+#endif
+
+/* 4.5.0 */
+
+
+#ifndef VIR_DOMAIN_LAUNCH_SECURITY_SEV_MEASUREMENT
+#define VIR_DOMAIN_LAUNCH_SECURITY_SEV_MEASUREMENT "sev-measurement"
+#endif
+
+/* 4.6.0 */
+
+#ifndef VIR_DOMAIN_MEMORY_STAT_DISK_CACHES
+#define VIR_DOMAIN_MEMORY_STAT_DISK_CACHES 10
+#endif
+
+#endif /* LIBVIRT_GO_DOMAIN_COMPAT_H__ */
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/domain_events.go b/src/dma/vendor/github.com/libvirt/libvirt-go/domain_events.go
new file mode 100644
index 00000000..fe46c5e2
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/domain_events.go
@@ -0,0 +1,1633 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+package libvirt
+
+import (
+ "fmt"
+ "unsafe"
+)
+
+/*
+#cgo pkg-config: libvirt
+#include "domain_events_wrapper.h"
+*/
+import "C"
+
+type DomainEventGenericCallback func(c *Connect, d *Domain)
+
+type DomainEventLifecycle struct {
+ Event DomainEventType
+ // TODO: we can make Detail typesafe somehow ?
+ Detail int
+}
+
+type DomainEventLifecycleCallback func(c *Connect, d *Domain, event *DomainEventLifecycle)
+
+type DomainEventRTCChange struct {
+ Utcoffset int64
+}
+
+type DomainEventRTCChangeCallback func(c *Connect, d *Domain, event *DomainEventRTCChange)
+
+type DomainEventWatchdog struct {
+ Action DomainEventWatchdogAction
+}
+
+type DomainEventWatchdogCallback func(c *Connect, d *Domain, event *DomainEventWatchdog)
+
+type DomainEventIOError struct {
+ SrcPath string
+ DevAlias string
+ Action DomainEventIOErrorAction
+}
+
+type DomainEventIOErrorCallback func(c *Connect, d *Domain, event *DomainEventIOError)
+
+type DomainEventGraphicsAddress struct {
+ Family DomainEventGraphicsAddressType
+ Node string
+ Service string
+}
+
+type DomainEventGraphicsSubjectIdentity struct {
+ Type string
+ Name string
+}
+
+type DomainEventGraphics struct {
+ Phase DomainEventGraphicsPhase
+ Local DomainEventGraphicsAddress
+ Remote DomainEventGraphicsAddress
+ AuthScheme string
+ Subject []DomainEventGraphicsSubjectIdentity
+}
+
+type DomainEventGraphicsCallback func(c *Connect, d *Domain, event *DomainEventGraphics)
+
+type DomainEventIOErrorReason struct {
+ SrcPath string
+ DevAlias string
+ Action DomainEventIOErrorAction
+ Reason string
+}
+
+type DomainEventIOErrorReasonCallback func(c *Connect, d *Domain, event *DomainEventIOErrorReason)
+
+type DomainEventBlockJob struct {
+ Disk string
+ Type DomainBlockJobType
+ Status ConnectDomainEventBlockJobStatus
+}
+
+type DomainEventBlockJobCallback func(c *Connect, d *Domain, event *DomainEventBlockJob)
+
+type DomainEventDiskChange struct {
+ OldSrcPath string
+ NewSrcPath string
+ DevAlias string
+ Reason ConnectDomainEventDiskChangeReason
+}
+
+type DomainEventDiskChangeCallback func(c *Connect, d *Domain, event *DomainEventDiskChange)
+
+type DomainEventTrayChange struct {
+ DevAlias string
+ Reason ConnectDomainEventTrayChangeReason
+}
+
+type DomainEventTrayChangeCallback func(c *Connect, d *Domain, event *DomainEventTrayChange)
+
+type DomainEventPMSuspend struct {
+ Reason int
+}
+
+type DomainEventPMSuspendCallback func(c *Connect, d *Domain, event *DomainEventPMSuspend)
+
+type DomainEventPMWakeup struct {
+ Reason int
+}
+
+type DomainEventPMWakeupCallback func(c *Connect, d *Domain, event *DomainEventPMWakeup)
+
+type DomainEventPMSuspendDisk struct {
+ Reason int
+}
+
+type DomainEventPMSuspendDiskCallback func(c *Connect, d *Domain, event *DomainEventPMSuspendDisk)
+
+type DomainEventBalloonChange struct {
+ Actual uint64
+}
+
+type DomainEventBalloonChangeCallback func(c *Connect, d *Domain, event *DomainEventBalloonChange)
+
+type DomainEventDeviceRemoved struct {
+ DevAlias string
+}
+
+type DomainEventDeviceRemovedCallback func(c *Connect, d *Domain, event *DomainEventDeviceRemoved)
+
+type DomainEventTunableCpuPin struct {
+ VcpuPinSet bool
+ VcpuPin [][]bool
+ EmulatorPinSet bool
+ EmulatorPin []bool
+ IOThreadPinSet bool
+ IOThreadPin [][]bool
+}
+
+type DomainEventTunable struct {
+ CpuSched *DomainSchedulerParameters
+ CpuPin *DomainEventTunableCpuPin
+ BlkdevDiskSet bool
+ BlkdevDisk string
+ BlkdevTune *DomainBlockIoTuneParameters
+}
+
+type DomainEventTunableCallback func(c *Connect, d *Domain, event *DomainEventTunable)
+
+type DomainEventAgentLifecycle struct {
+ State ConnectDomainEventAgentLifecycleState
+ Reason ConnectDomainEventAgentLifecycleReason
+}
+
+type DomainEventAgentLifecycleCallback func(c *Connect, d *Domain, event *DomainEventAgentLifecycle)
+
+type DomainEventDeviceAdded struct {
+ DevAlias string
+}
+
+type DomainEventDeviceAddedCallback func(c *Connect, d *Domain, event *DomainEventDeviceAdded)
+
+type DomainEventMigrationIteration struct {
+ Iteration int
+}
+
+type DomainEventMigrationIterationCallback func(c *Connect, d *Domain, event *DomainEventMigrationIteration)
+
+type DomainEventJobCompleted struct {
+ Info DomainJobInfo
+}
+
+type DomainEventJobCompletedCallback func(c *Connect, d *Domain, event *DomainEventJobCompleted)
+
+type DomainEventDeviceRemovalFailed struct {
+ DevAlias string
+}
+
+type DomainEventDeviceRemovalFailedCallback func(c *Connect, d *Domain, event *DomainEventDeviceRemovalFailed)
+
+type DomainEventMetadataChange struct {
+ Type int
+ NSURI string
+}
+
+type DomainEventMetadataChangeCallback func(c *Connect, d *Domain, event *DomainEventMetadataChange)
+
+type DomainEventBlockThreshold struct {
+ Dev string
+ Path string
+ Threshold uint64
+ Excess uint64
+}
+
+type DomainEventBlockThresholdCallback func(c *Connect, d *Domain, event *DomainEventBlockThreshold)
+
+//export domainEventLifecycleCallback
+func domainEventLifecycleCallback(c C.virConnectPtr, d C.virDomainPtr,
+ event int, detail int,
+ goCallbackId int) {
+
+ domain := &Domain{ptr: d}
+ connection := &Connect{ptr: c}
+
+ eventDetails := &DomainEventLifecycle{
+ Event: DomainEventType(event),
+ Detail: detail,
+ }
+
+ callbackFunc := getCallbackId(goCallbackId)
+ callback, ok := callbackFunc.(DomainEventLifecycleCallback)
+ if !ok {
+ panic("Inappropriate callback type called")
+ }
+ callback(connection, domain, eventDetails)
+}
+
+//export domainEventGenericCallback
+func domainEventGenericCallback(c C.virConnectPtr, d C.virDomainPtr,
+ goCallbackId int) {
+
+ domain := &Domain{ptr: d}
+ connection := &Connect{ptr: c}
+
+ callbackFunc := getCallbackId(goCallbackId)
+ callback, ok := callbackFunc.(DomainEventGenericCallback)
+ if !ok {
+ panic("Inappropriate callback type called")
+ }
+ callback(connection, domain)
+}
+
+//export domainEventRTCChangeCallback
+func domainEventRTCChangeCallback(c C.virConnectPtr, d C.virDomainPtr,
+ utcoffset int64, goCallbackId int) {
+
+ domain := &Domain{ptr: d}
+ connection := &Connect{ptr: c}
+
+ eventDetails := &DomainEventRTCChange{
+ Utcoffset: utcoffset,
+ }
+
+ callbackFunc := getCallbackId(goCallbackId)
+ callback, ok := callbackFunc.(DomainEventRTCChangeCallback)
+ if !ok {
+ panic("Inappropriate callback type called")
+ }
+ callback(connection, domain, eventDetails)
+
+}
+
+//export domainEventWatchdogCallback
+func domainEventWatchdogCallback(c C.virConnectPtr, d C.virDomainPtr,
+ action int, goCallbackId int) {
+
+ domain := &Domain{ptr: d}
+ connection := &Connect{ptr: c}
+
+ eventDetails := &DomainEventWatchdog{
+ Action: DomainEventWatchdogAction(action),
+ }
+
+ callbackFunc := getCallbackId(goCallbackId)
+ callback, ok := callbackFunc.(DomainEventWatchdogCallback)
+ if !ok {
+ panic("Inappropriate callback type called")
+ }
+ callback(connection, domain, eventDetails)
+
+}
+
+//export domainEventIOErrorCallback
+func domainEventIOErrorCallback(c C.virConnectPtr, d C.virDomainPtr,
+ srcPath *C.char, devAlias *C.char, action int, goCallbackId int) {
+
+ domain := &Domain{ptr: d}
+ connection := &Connect{ptr: c}
+
+ eventDetails := &DomainEventIOError{
+ SrcPath: C.GoString(srcPath),
+ DevAlias: C.GoString(devAlias),
+ Action: DomainEventIOErrorAction(action),
+ }
+
+ callbackFunc := getCallbackId(goCallbackId)
+ callback, ok := callbackFunc.(DomainEventIOErrorCallback)
+ if !ok {
+ panic("Inappropriate callback type called")
+ }
+ callback(connection, domain, eventDetails)
+
+}
+
+//export domainEventGraphicsCallback
+func domainEventGraphicsCallback(c C.virConnectPtr, d C.virDomainPtr,
+ phase int,
+ local C.virDomainEventGraphicsAddressPtr,
+ remote C.virDomainEventGraphicsAddressPtr,
+ authScheme *C.char,
+ subject C.virDomainEventGraphicsSubjectPtr,
+ goCallbackId int) {
+
+ domain := &Domain{ptr: d}
+ connection := &Connect{ptr: c}
+
+ subjectGo := make([]DomainEventGraphicsSubjectIdentity, 0)
+ nidentities := int(subject.nidentity)
+ identities := (*[1 << 30]C.virDomainEventGraphicsSubjectIdentity)(unsafe.Pointer(&subject.identities))[:nidentities:nidentities]
+ for _, identity := range identities {
+ subjectGo = append(subjectGo,
+ DomainEventGraphicsSubjectIdentity{
+ Type: C.GoString(identity._type),
+ Name: C.GoString(identity.name),
+ },
+ )
+ }
+
+ eventDetails := &DomainEventGraphics{
+ Phase: DomainEventGraphicsPhase(phase),
+ Local: DomainEventGraphicsAddress{
+ Family: DomainEventGraphicsAddressType(local.family),
+ Node: C.GoString(local.node),
+ Service: C.GoString(local.service),
+ },
+ Remote: DomainEventGraphicsAddress{
+ Family: DomainEventGraphicsAddressType(remote.family),
+ Node: C.GoString(remote.node),
+ Service: C.GoString(remote.service),
+ },
+ AuthScheme: C.GoString(authScheme),
+ Subject: subjectGo,
+ }
+
+ callbackFunc := getCallbackId(goCallbackId)
+ callback, ok := callbackFunc.(DomainEventGraphicsCallback)
+ if !ok {
+ panic("Inappropriate callback type called")
+ }
+ callback(connection, domain, eventDetails)
+
+}
+
+//export domainEventIOErrorReasonCallback
+func domainEventIOErrorReasonCallback(c C.virConnectPtr, d C.virDomainPtr,
+ srcPath *C.char, devAlias *C.char, action int, reason *C.char,
+ goCallbackId int) {
+
+ domain := &Domain{ptr: d}
+ connection := &Connect{ptr: c}
+
+ eventDetails := &DomainEventIOErrorReason{
+ SrcPath: C.GoString(srcPath),
+ DevAlias: C.GoString(devAlias),
+ Action: DomainEventIOErrorAction(action),
+ Reason: C.GoString(reason),
+ }
+
+ callbackFunc := getCallbackId(goCallbackId)
+ callback, ok := callbackFunc.(DomainEventIOErrorReasonCallback)
+ if !ok {
+ panic("Inappropriate callback type called")
+ }
+ callback(connection, domain, eventDetails)
+
+}
+
+//export domainEventBlockJobCallback
+func domainEventBlockJobCallback(c C.virConnectPtr, d C.virDomainPtr,
+ disk *C.char, _type int, status int, goCallbackId int) {
+
+ domain := &Domain{ptr: d}
+ connection := &Connect{ptr: c}
+
+ eventDetails := &DomainEventBlockJob{
+ Disk: C.GoString(disk),
+ Type: DomainBlockJobType(_type),
+ Status: ConnectDomainEventBlockJobStatus(status),
+ }
+
+ callbackFunc := getCallbackId(goCallbackId)
+ callback, ok := callbackFunc.(DomainEventBlockJobCallback)
+ if !ok {
+ panic("Inappropriate callback type called")
+ }
+ callback(connection, domain, eventDetails)
+
+}
+
+//export domainEventDiskChangeCallback
+func domainEventDiskChangeCallback(c C.virConnectPtr, d C.virDomainPtr,
+ oldSrcPath *C.char, newSrcPath *C.char, devAlias *C.char,
+ reason int, goCallbackId int) {
+
+ domain := &Domain{ptr: d}
+ connection := &Connect{ptr: c}
+
+ eventDetails := &DomainEventDiskChange{
+ OldSrcPath: C.GoString(oldSrcPath),
+ NewSrcPath: C.GoString(newSrcPath),
+ DevAlias: C.GoString(devAlias),
+ Reason: ConnectDomainEventDiskChangeReason(reason),
+ }
+
+ callbackFunc := getCallbackId(goCallbackId)
+ callback, ok := callbackFunc.(DomainEventDiskChangeCallback)
+ if !ok {
+ panic("Inappropriate callback type called")
+ }
+ callback(connection, domain, eventDetails)
+
+}
+
+//export domainEventTrayChangeCallback
+func domainEventTrayChangeCallback(c C.virConnectPtr, d C.virDomainPtr,
+ devAlias *C.char, reason int, goCallbackId int) {
+
+ domain := &Domain{ptr: d}
+ connection := &Connect{ptr: c}
+
+ eventDetails := &DomainEventTrayChange{
+ DevAlias: C.GoString(devAlias),
+ Reason: ConnectDomainEventTrayChangeReason(reason),
+ }
+
+ callbackFunc := getCallbackId(goCallbackId)
+ callback, ok := callbackFunc.(DomainEventTrayChangeCallback)
+ if !ok {
+ panic("Inappropriate callback type called")
+ }
+ callback(connection, domain, eventDetails)
+
+}
+
+//export domainEventPMSuspendCallback
+func domainEventPMSuspendCallback(c C.virConnectPtr, d C.virDomainPtr,
+ reason int, goCallbackId int) {
+
+ domain := &Domain{ptr: d}
+ connection := &Connect{ptr: c}
+
+ eventDetails := &DomainEventPMSuspend{
+ Reason: reason,
+ }
+
+ callbackFunc := getCallbackId(goCallbackId)
+ callback, ok := callbackFunc.(DomainEventPMSuspendCallback)
+ if !ok {
+ panic("Inappropriate callback type called")
+ }
+ callback(connection, domain, eventDetails)
+
+}
+
+//export domainEventPMWakeupCallback
+func domainEventPMWakeupCallback(c C.virConnectPtr, d C.virDomainPtr,
+ reason int, goCallbackId int) {
+
+ domain := &Domain{ptr: d}
+ connection := &Connect{ptr: c}
+
+ eventDetails := &DomainEventPMWakeup{
+ Reason: reason,
+ }
+
+ callbackFunc := getCallbackId(goCallbackId)
+ callback, ok := callbackFunc.(DomainEventPMWakeupCallback)
+ if !ok {
+ panic("Inappropriate callback type called")
+ }
+ callback(connection, domain, eventDetails)
+
+}
+
+//export domainEventPMSuspendDiskCallback
+func domainEventPMSuspendDiskCallback(c C.virConnectPtr, d C.virDomainPtr,
+ reason int, goCallbackId int) {
+
+ domain := &Domain{ptr: d}
+ connection := &Connect{ptr: c}
+
+ eventDetails := &DomainEventPMSuspendDisk{
+ Reason: reason,
+ }
+
+ callbackFunc := getCallbackId(goCallbackId)
+ callback, ok := callbackFunc.(DomainEventPMSuspendDiskCallback)
+ if !ok {
+ panic("Inappropriate callback type called")
+ }
+ callback(connection, domain, eventDetails)
+
+}
+
+//export domainEventBalloonChangeCallback
+func domainEventBalloonChangeCallback(c C.virConnectPtr, d C.virDomainPtr,
+ actual uint64, goCallbackId int) {
+
+ domain := &Domain{ptr: d}
+ connection := &Connect{ptr: c}
+
+ eventDetails := &DomainEventBalloonChange{
+ Actual: actual,
+ }
+
+ callbackFunc := getCallbackId(goCallbackId)
+ callback, ok := callbackFunc.(DomainEventBalloonChangeCallback)
+ if !ok {
+ panic("Inappropriate callback type called")
+ }
+ callback(connection, domain, eventDetails)
+
+}
+
+//export domainEventDeviceRemovedCallback
+func domainEventDeviceRemovedCallback(c C.virConnectPtr, d C.virDomainPtr,
+ devAlias *C.char, goCallbackId int) {
+
+ domain := &Domain{ptr: d}
+ connection := &Connect{ptr: c}
+
+ eventDetails := &DomainEventDeviceRemoved{
+ DevAlias: C.GoString(devAlias),
+ }
+ callbackFunc := getCallbackId(goCallbackId)
+ callback, ok := callbackFunc.(DomainEventDeviceRemovedCallback)
+ if !ok {
+ panic("Inappropriate callback type called")
+ }
+ callback(connection, domain, eventDetails)
+
+}
+
+//export domainEventMetadataChangeCallback
+func domainEventMetadataChangeCallback(c C.virConnectPtr, d C.virDomainPtr,
+ mtype int, nsuri *C.char, goCallbackId int) {
+
+ domain := &Domain{ptr: d}
+ connection := &Connect{ptr: c}
+
+ eventDetails := &DomainEventMetadataChange{
+ Type: (int)(mtype),
+ NSURI: C.GoString(nsuri),
+ }
+ callbackFunc := getCallbackId(goCallbackId)
+ callback, ok := callbackFunc.(DomainEventMetadataChangeCallback)
+ if !ok {
+ panic("Inappropriate callback type called")
+ }
+ callback(connection, domain, eventDetails)
+
+}
+
+func getDomainTuneSchedulerParametersFieldInfo(params *DomainSchedulerParameters) map[string]typedParamsFieldInfo {
+ return map[string]typedParamsFieldInfo{
+ C.VIR_DOMAIN_TUNABLE_CPU_CPU_SHARES: typedParamsFieldInfo{
+ set: &params.CpuSharesSet,
+ ul: &params.CpuShares,
+ },
+ C.VIR_DOMAIN_TUNABLE_CPU_GLOBAL_PERIOD: typedParamsFieldInfo{
+ set: &params.GlobalPeriodSet,
+ ul: &params.GlobalPeriod,
+ },
+ C.VIR_DOMAIN_TUNABLE_CPU_GLOBAL_QUOTA: typedParamsFieldInfo{
+ set: &params.GlobalQuotaSet,
+ l: &params.GlobalQuota,
+ },
+ C.VIR_DOMAIN_TUNABLE_CPU_EMULATOR_PERIOD: typedParamsFieldInfo{
+ set: &params.EmulatorPeriodSet,
+ ul: &params.EmulatorPeriod,
+ },
+ C.VIR_DOMAIN_TUNABLE_CPU_EMULATOR_QUOTA: typedParamsFieldInfo{
+ set: &params.EmulatorQuotaSet,
+ l: &params.EmulatorQuota,
+ },
+ C.VIR_DOMAIN_TUNABLE_CPU_VCPU_PERIOD: typedParamsFieldInfo{
+ set: &params.VcpuPeriodSet,
+ ul: &params.VcpuPeriod,
+ },
+ C.VIR_DOMAIN_TUNABLE_CPU_VCPU_QUOTA: typedParamsFieldInfo{
+ set: &params.VcpuQuotaSet,
+ l: &params.VcpuQuota,
+ },
+ C.VIR_DOMAIN_TUNABLE_CPU_IOTHREAD_PERIOD: typedParamsFieldInfo{
+ set: &params.IothreadPeriodSet,
+ ul: &params.IothreadPeriod,
+ },
+ C.VIR_DOMAIN_TUNABLE_CPU_IOTHREAD_QUOTA: typedParamsFieldInfo{
+ set: &params.IothreadQuotaSet,
+ l: &params.IothreadQuota,
+ },
+ }
+}
+
+func getTuneBlockIoTuneParametersFieldInfo(params *DomainBlockIoTuneParameters) map[string]typedParamsFieldInfo {
+ return map[string]typedParamsFieldInfo{
+ C.VIR_DOMAIN_TUNABLE_BLKDEV_TOTAL_BYTES_SEC: typedParamsFieldInfo{
+ set: &params.TotalBytesSecSet,
+ ul: &params.TotalBytesSec,
+ },
+ C.VIR_DOMAIN_TUNABLE_BLKDEV_READ_BYTES_SEC: typedParamsFieldInfo{
+ set: &params.ReadBytesSecSet,
+ ul: &params.ReadBytesSec,
+ },
+ C.VIR_DOMAIN_TUNABLE_BLKDEV_WRITE_BYTES_SEC: typedParamsFieldInfo{
+ set: &params.WriteBytesSecSet,
+ ul: &params.WriteBytesSec,
+ },
+ C.VIR_DOMAIN_TUNABLE_BLKDEV_TOTAL_IOPS_SEC: typedParamsFieldInfo{
+ set: &params.TotalIopsSecSet,
+ ul: &params.TotalIopsSec,
+ },
+ C.VIR_DOMAIN_TUNABLE_BLKDEV_READ_IOPS_SEC: typedParamsFieldInfo{
+ set: &params.ReadIopsSecSet,
+ ul: &params.ReadIopsSec,
+ },
+ C.VIR_DOMAIN_TUNABLE_BLKDEV_WRITE_IOPS_SEC: typedParamsFieldInfo{
+ set: &params.WriteIopsSecSet,
+ ul: &params.WriteIopsSec,
+ },
+ C.VIR_DOMAIN_TUNABLE_BLKDEV_TOTAL_BYTES_SEC_MAX: typedParamsFieldInfo{
+ set: &params.TotalBytesSecMaxSet,
+ ul: &params.TotalBytesSecMax,
+ },
+ C.VIR_DOMAIN_TUNABLE_BLKDEV_READ_BYTES_SEC_MAX: typedParamsFieldInfo{
+ set: &params.ReadBytesSecMaxSet,
+ ul: &params.ReadBytesSecMax,
+ },
+ C.VIR_DOMAIN_TUNABLE_BLKDEV_WRITE_BYTES_SEC_MAX: typedParamsFieldInfo{
+ set: &params.WriteBytesSecMaxSet,
+ ul: &params.WriteBytesSecMax,
+ },
+ C.VIR_DOMAIN_TUNABLE_BLKDEV_TOTAL_IOPS_SEC_MAX: typedParamsFieldInfo{
+ set: &params.TotalIopsSecMaxSet,
+ ul: &params.TotalIopsSecMax,
+ },
+ C.VIR_DOMAIN_TUNABLE_BLKDEV_READ_IOPS_SEC_MAX: typedParamsFieldInfo{
+ set: &params.ReadIopsSecMaxSet,
+ ul: &params.ReadIopsSecMax,
+ },
+ C.VIR_DOMAIN_TUNABLE_BLKDEV_WRITE_IOPS_SEC_MAX: typedParamsFieldInfo{
+ set: &params.WriteIopsSecMaxSet,
+ ul: &params.WriteIopsSecMax,
+ },
+ C.VIR_DOMAIN_TUNABLE_BLKDEV_TOTAL_BYTES_SEC_MAX_LENGTH: typedParamsFieldInfo{
+ set: &params.TotalBytesSecMaxLengthSet,
+ ul: &params.TotalBytesSecMaxLength,
+ },
+ C.VIR_DOMAIN_TUNABLE_BLKDEV_READ_BYTES_SEC_MAX_LENGTH: typedParamsFieldInfo{
+ set: &params.ReadBytesSecMaxLengthSet,
+ ul: &params.ReadBytesSecMaxLength,
+ },
+ C.VIR_DOMAIN_TUNABLE_BLKDEV_WRITE_BYTES_SEC_MAX_LENGTH: typedParamsFieldInfo{
+ set: &params.WriteBytesSecMaxLengthSet,
+ ul: &params.WriteBytesSecMaxLength,
+ },
+ C.VIR_DOMAIN_TUNABLE_BLKDEV_TOTAL_IOPS_SEC_MAX_LENGTH: typedParamsFieldInfo{
+ set: &params.TotalIopsSecMaxLengthSet,
+ ul: &params.TotalIopsSecMaxLength,
+ },
+ C.VIR_DOMAIN_TUNABLE_BLKDEV_READ_IOPS_SEC_MAX_LENGTH: typedParamsFieldInfo{
+ set: &params.ReadIopsSecMaxLengthSet,
+ ul: &params.ReadIopsSecMaxLength,
+ },
+ C.VIR_DOMAIN_TUNABLE_BLKDEV_WRITE_IOPS_SEC_MAX_LENGTH: typedParamsFieldInfo{
+ set: &params.WriteIopsSecMaxLengthSet,
+ ul: &params.WriteIopsSecMaxLength,
+ },
+ C.VIR_DOMAIN_TUNABLE_BLKDEV_SIZE_IOPS_SEC: typedParamsFieldInfo{
+ set: &params.SizeIopsSecSet,
+ ul: &params.SizeIopsSec,
+ },
+ C.VIR_DOMAIN_TUNABLE_BLKDEV_GROUP_NAME: typedParamsFieldInfo{
+ set: &params.GroupNameSet,
+ s: &params.GroupName,
+ },
+ }
+}
+
+type domainEventTunablePinTemp struct {
+ VcpuPinSet bool
+ VcpuPin []string
+ EmulatorPinSet bool
+ EmulatorPin string
+ IOThreadPinSet bool
+ IOThreadPin []string
+}
+
+func getDomainPinTempFieldInfo(numvcpu int, numiothread int, params *domainEventTunablePinTemp) map[string]typedParamsFieldInfo {
+ ret := map[string]typedParamsFieldInfo{
+ C.VIR_DOMAIN_TUNABLE_CPU_EMULATORPIN: typedParamsFieldInfo{
+ set: &params.EmulatorPinSet,
+ s: &params.EmulatorPin,
+ },
+ }
+ for i := 0; i < numvcpu; i++ {
+ ret[fmt.Sprintf("cputune.vcpupin%d", i)] = typedParamsFieldInfo{
+ s: &params.VcpuPin[i],
+ }
+ }
+ for i := 0; i < numiothread; i++ {
+ ret[fmt.Sprintf("cputune.iothreadpin%d", i)] = typedParamsFieldInfo{
+ s: &params.IOThreadPin[i],
+ }
+ }
+
+ return ret
+}
+
+func countPinInfo(cparams C.virTypedParameterPtr, nparams C.int) (int, int) {
+ maxvcpus := 0
+ maxiothreads := 0
+ for i := 0; i < int(nparams); i++ {
+ var cparam *C.virTypedParameter
+ cparam = (*C.virTypedParameter)(unsafe.Pointer(uintptr(unsafe.Pointer(cparams)) + unsafe.Sizeof(*cparam)*uintptr(i)))
+ name := C.GoString((*C.char)(unsafe.Pointer(&cparam.field)))
+
+ var vcpu int
+ _, err := fmt.Scanf(name, "cputune.vcpupin%d", &vcpu)
+ if err == nil {
+ if vcpu > maxvcpus {
+ maxvcpus = vcpu
+ }
+ }
+
+ var iothread int
+ _, err = fmt.Scanf(name, "cputune.iothreadpin%d", &iothread)
+ if err == nil {
+ if iothread > maxiothreads {
+ maxiothreads = iothread
+ }
+ }
+ }
+
+ return maxvcpus + 1, maxiothreads + 1
+}
+
+func domainEventTunableGetPin(params C.virTypedParameterPtr, nparams C.int) *DomainEventTunableCpuPin {
+ var pin domainEventTunablePinTemp
+ numvcpus, numiothreads := countPinInfo(params, nparams)
+ pinInfo := getDomainPinTempFieldInfo(numvcpus, numiothreads, &pin)
+
+ num, err := typedParamsUnpackLen(params, int(nparams), pinInfo)
+ if num == 0 || err != nil {
+ return nil
+ }
+
+ info := &DomainEventTunableCpuPin{}
+
+ if pin.VcpuPinSet {
+ info.VcpuPinSet = true
+ info.VcpuPin = make([][]bool, len(pin.VcpuPin))
+
+ for i := 0; i < len(pin.VcpuPin); i++ {
+ bits, err := parseCPUString(pin.VcpuPin[i])
+ if err == nil {
+ info.VcpuPin[i] = bits
+ }
+ }
+ }
+
+ if pin.EmulatorPinSet {
+ bits, err := parseCPUString(pin.EmulatorPin)
+ if err == nil {
+ info.EmulatorPinSet = true
+ info.EmulatorPin = bits
+ }
+ }
+
+ if pin.IOThreadPinSet {
+ info.IOThreadPinSet = true
+ info.IOThreadPin = make([][]bool, len(pin.IOThreadPin))
+
+ for i := 0; i < len(pin.IOThreadPin); i++ {
+ bits, err := parseCPUString(pin.IOThreadPin[i])
+ if err == nil {
+ info.IOThreadPin[i] = bits
+ }
+ }
+ }
+
+ return info
+}
+
+//export domainEventTunableCallback
+func domainEventTunableCallback(c C.virConnectPtr, d C.virDomainPtr, params C.virTypedParameterPtr, nparams C.int, goCallbackId int) {
+ domain := &Domain{ptr: d}
+ connection := &Connect{ptr: c}
+
+ eventDetails := &DomainEventTunable{}
+
+ pin := domainEventTunableGetPin(params, nparams)
+ if pin != nil {
+ eventDetails.CpuPin = pin
+ }
+
+ var sched DomainSchedulerParameters
+ schedInfo := getDomainTuneSchedulerParametersFieldInfo(&sched)
+
+ num, _ := typedParamsUnpackLen(params, int(nparams), schedInfo)
+ if num > 0 {
+ eventDetails.CpuSched = &sched
+ }
+
+ blknameInfo := map[string]typedParamsFieldInfo{
+ C.VIR_DOMAIN_TUNABLE_BLKDEV_DISK: typedParamsFieldInfo{
+ set: &eventDetails.BlkdevDiskSet,
+ s: &eventDetails.BlkdevDisk,
+ },
+ }
+ typedParamsUnpackLen(params, int(nparams), blknameInfo)
+
+ var blktune DomainBlockIoTuneParameters
+ blktuneInfo := getTuneBlockIoTuneParametersFieldInfo(&blktune)
+
+ num, _ = typedParamsUnpackLen(params, int(nparams), blktuneInfo)
+ if num > 0 {
+ eventDetails.BlkdevTune = &blktune
+ }
+
+ callbackFunc := getCallbackId(goCallbackId)
+ callback, ok := callbackFunc.(DomainEventTunableCallback)
+ if !ok {
+ panic("Inappropriate callback type called")
+ }
+ callback(connection, domain, eventDetails)
+
+}
+
+//export domainEventAgentLifecycleCallback
+func domainEventAgentLifecycleCallback(c C.virConnectPtr, d C.virDomainPtr, state C.int, reason C.int, goCallbackId int) {
+ domain := &Domain{ptr: d}
+ connection := &Connect{ptr: c}
+
+ eventDetails := &DomainEventAgentLifecycle{
+ State: ConnectDomainEventAgentLifecycleState(state),
+ Reason: ConnectDomainEventAgentLifecycleReason(reason),
+ }
+ callbackFunc := getCallbackId(goCallbackId)
+ callback, ok := callbackFunc.(DomainEventAgentLifecycleCallback)
+ if !ok {
+ panic("Inappropriate callback type called")
+ }
+ callback(connection, domain, eventDetails)
+
+}
+
+//export domainEventDeviceAddedCallback
+func domainEventDeviceAddedCallback(c C.virConnectPtr, d C.virDomainPtr, devalias *C.char, goCallbackId int) {
+ domain := &Domain{ptr: d}
+ connection := &Connect{ptr: c}
+
+ eventDetails := &DomainEventDeviceAdded{
+ DevAlias: C.GoString(devalias),
+ }
+ callbackFunc := getCallbackId(goCallbackId)
+ callback, ok := callbackFunc.(DomainEventDeviceAddedCallback)
+ if !ok {
+ panic("Inappropriate callback type called")
+ }
+ callback(connection, domain, eventDetails)
+
+}
+
+//export domainEventMigrationIterationCallback
+func domainEventMigrationIterationCallback(c C.virConnectPtr, d C.virDomainPtr, iteration C.int, goCallbackId int) {
+ domain := &Domain{ptr: d}
+ connection := &Connect{ptr: c}
+
+ eventDetails := &DomainEventMigrationIteration{
+ Iteration: int(iteration),
+ }
+ callbackFunc := getCallbackId(goCallbackId)
+ callback, ok := callbackFunc.(DomainEventMigrationIterationCallback)
+ if !ok {
+ panic("Inappropriate callback type called")
+ }
+ callback(connection, domain, eventDetails)
+
+}
+
+//export domainEventJobCompletedCallback
+func domainEventJobCompletedCallback(c C.virConnectPtr, d C.virDomainPtr, params C.virTypedParameterPtr, nparams C.int, goCallbackId int) {
+ domain := &Domain{ptr: d}
+ connection := &Connect{ptr: c}
+
+ eventDetails := &DomainEventJobCompleted{}
+ info := getDomainJobInfoFieldInfo(&eventDetails.Info)
+
+ typedParamsUnpackLen(params, int(nparams), info)
+
+ callbackFunc := getCallbackId(goCallbackId)
+ callback, ok := callbackFunc.(DomainEventJobCompletedCallback)
+ if !ok {
+ panic("Inappropriate callback type called")
+ }
+ callback(connection, domain, eventDetails)
+
+}
+
+//export domainEventDeviceRemovalFailedCallback
+func domainEventDeviceRemovalFailedCallback(c C.virConnectPtr, d C.virDomainPtr, devalias *C.char, goCallbackId int) {
+ domain := &Domain{ptr: d}
+ connection := &Connect{ptr: c}
+
+ eventDetails := &DomainEventDeviceRemovalFailed{
+ DevAlias: C.GoString(devalias),
+ }
+ callbackFunc := getCallbackId(goCallbackId)
+ callback, ok := callbackFunc.(DomainEventDeviceRemovalFailedCallback)
+ if !ok {
+ panic("Inappropriate callback type called")
+ }
+ callback(connection, domain, eventDetails)
+
+}
+
+//export domainEventBlockThresholdCallback
+func domainEventBlockThresholdCallback(c C.virConnectPtr, d C.virDomainPtr, dev *C.char, path *C.char, threshold C.ulonglong, excess C.ulonglong, goCallbackId int) {
+ domain := &Domain{ptr: d}
+ connection := &Connect{ptr: c}
+
+ eventDetails := &DomainEventBlockThreshold{
+ Dev: C.GoString(dev),
+ Path: C.GoString(path),
+ Threshold: uint64(threshold),
+ Excess: uint64(excess),
+ }
+ callbackFunc := getCallbackId(goCallbackId)
+ callback, ok := callbackFunc.(DomainEventBlockThresholdCallback)
+ if !ok {
+ panic("Inappropriate callback type called")
+ }
+ callback(connection, domain, eventDetails)
+
+}
+
+func (c *Connect) DomainEventLifecycleRegister(dom *Domain, callback DomainEventLifecycleCallback) (int, error) {
+ goCallBackId := registerCallbackId(callback)
+
+ callbackPtr := unsafe.Pointer(C.domainEventLifecycleCallbackHelper)
+ var cdom C.virDomainPtr
+ if dom != nil {
+ cdom = dom.ptr
+ }
+ var err C.virError
+ ret := C.virConnectDomainEventRegisterAnyWrapper(c.ptr, cdom,
+ C.VIR_DOMAIN_EVENT_ID_LIFECYCLE,
+ C.virConnectDomainEventGenericCallback(callbackPtr),
+ C.long(goCallBackId), &err)
+ if ret == -1 {
+ freeCallbackId(goCallBackId)
+ return 0, makeError(&err)
+ }
+ return int(ret), nil
+}
+
+func (c *Connect) DomainEventRebootRegister(dom *Domain, callback DomainEventGenericCallback) (int, error) {
+ goCallBackId := registerCallbackId(callback)
+
+ callbackPtr := unsafe.Pointer(C.domainEventGenericCallbackHelper)
+ var cdom C.virDomainPtr
+ if dom != nil {
+ cdom = dom.ptr
+ }
+ var err C.virError
+ ret := C.virConnectDomainEventRegisterAnyWrapper(c.ptr, cdom,
+ C.VIR_DOMAIN_EVENT_ID_REBOOT,
+ C.virConnectDomainEventGenericCallback(callbackPtr),
+ C.long(goCallBackId), &err)
+ if ret == -1 {
+ freeCallbackId(goCallBackId)
+ return 0, makeError(&err)
+ }
+ return int(ret), nil
+}
+
+func (c *Connect) DomainEventRTCChangeRegister(dom *Domain, callback DomainEventRTCChangeCallback) (int, error) {
+ goCallBackId := registerCallbackId(callback)
+
+ callbackPtr := unsafe.Pointer(C.domainEventRTCChangeCallbackHelper)
+ var cdom C.virDomainPtr
+ if dom != nil {
+ cdom = dom.ptr
+ }
+ var err C.virError
+ ret := C.virConnectDomainEventRegisterAnyWrapper(c.ptr, cdom,
+ C.VIR_DOMAIN_EVENT_ID_RTC_CHANGE,
+ C.virConnectDomainEventGenericCallback(callbackPtr),
+ C.long(goCallBackId), &err)
+ if ret == -1 {
+ freeCallbackId(goCallBackId)
+ return 0, makeError(&err)
+ }
+ return int(ret), nil
+}
+
+func (c *Connect) DomainEventWatchdogRegister(dom *Domain, callback DomainEventWatchdogCallback) (int, error) {
+ goCallBackId := registerCallbackId(callback)
+
+ callbackPtr := unsafe.Pointer(C.domainEventWatchdogCallbackHelper)
+ var cdom C.virDomainPtr
+ if dom != nil {
+ cdom = dom.ptr
+ }
+ var err C.virError
+ ret := C.virConnectDomainEventRegisterAnyWrapper(c.ptr, cdom,
+ C.VIR_DOMAIN_EVENT_ID_WATCHDOG,
+ C.virConnectDomainEventGenericCallback(callbackPtr),
+ C.long(goCallBackId), &err)
+ if ret == -1 {
+ freeCallbackId(goCallBackId)
+ return 0, makeError(&err)
+ }
+ return int(ret), nil
+}
+
+func (c *Connect) DomainEventIOErrorRegister(dom *Domain, callback DomainEventIOErrorCallback) (int, error) {
+ goCallBackId := registerCallbackId(callback)
+
+ callbackPtr := unsafe.Pointer(C.domainEventIOErrorCallbackHelper)
+ var cdom C.virDomainPtr
+ if dom != nil {
+ cdom = dom.ptr
+ }
+ var err C.virError
+ ret := C.virConnectDomainEventRegisterAnyWrapper(c.ptr, cdom,
+ C.VIR_DOMAIN_EVENT_ID_IO_ERROR,
+ C.virConnectDomainEventGenericCallback(callbackPtr),
+ C.long(goCallBackId), &err)
+ if ret == -1 {
+ freeCallbackId(goCallBackId)
+ return 0, makeError(&err)
+ }
+ return int(ret), nil
+}
+
+func (c *Connect) DomainEventGraphicsRegister(dom *Domain, callback DomainEventGraphicsCallback) (int, error) {
+ goCallBackId := registerCallbackId(callback)
+
+ callbackPtr := unsafe.Pointer(C.domainEventGraphicsCallbackHelper)
+ var cdom C.virDomainPtr
+ if dom != nil {
+ cdom = dom.ptr
+ }
+ var err C.virError
+ ret := C.virConnectDomainEventRegisterAnyWrapper(c.ptr, cdom,
+ C.VIR_DOMAIN_EVENT_ID_GRAPHICS,
+ C.virConnectDomainEventGenericCallback(callbackPtr),
+ C.long(goCallBackId), &err)
+ if ret == -1 {
+ freeCallbackId(goCallBackId)
+ return 0, makeError(&err)
+ }
+ return int(ret), nil
+}
+
+func (c *Connect) DomainEventIOErrorReasonRegister(dom *Domain, callback DomainEventIOErrorReasonCallback) (int, error) {
+ goCallBackId := registerCallbackId(callback)
+
+ callbackPtr := unsafe.Pointer(C.domainEventIOErrorReasonCallbackHelper)
+ var cdom C.virDomainPtr
+ if dom != nil {
+ cdom = dom.ptr
+ }
+ var err C.virError
+ ret := C.virConnectDomainEventRegisterAnyWrapper(c.ptr, cdom,
+ C.VIR_DOMAIN_EVENT_ID_IO_ERROR_REASON,
+ C.virConnectDomainEventGenericCallback(callbackPtr),
+ C.long(goCallBackId), &err)
+ if ret == -1 {
+ freeCallbackId(goCallBackId)
+ return 0, makeError(&err)
+ }
+ return int(ret), nil
+}
+
+func (c *Connect) DomainEventControlErrorRegister(dom *Domain, callback DomainEventGenericCallback) (int, error) {
+ goCallBackId := registerCallbackId(callback)
+
+ callbackPtr := unsafe.Pointer(C.domainEventGenericCallbackHelper)
+ var cdom C.virDomainPtr
+ if dom != nil {
+ cdom = dom.ptr
+ }
+ var err C.virError
+ ret := C.virConnectDomainEventRegisterAnyWrapper(c.ptr, cdom,
+ C.VIR_DOMAIN_EVENT_ID_CONTROL_ERROR,
+ C.virConnectDomainEventGenericCallback(callbackPtr),
+ C.long(goCallBackId), &err)
+ if ret == -1 {
+ freeCallbackId(goCallBackId)
+ return 0, makeError(&err)
+ }
+ return int(ret), nil
+}
+
+func (c *Connect) DomainEventBlockJobRegister(dom *Domain, callback DomainEventBlockJobCallback) (int, error) {
+ goCallBackId := registerCallbackId(callback)
+
+ callbackPtr := unsafe.Pointer(C.domainEventBlockJobCallbackHelper)
+ var cdom C.virDomainPtr
+ if dom != nil {
+ cdom = dom.ptr
+ }
+ var err C.virError
+ ret := C.virConnectDomainEventRegisterAnyWrapper(c.ptr, cdom,
+ C.VIR_DOMAIN_EVENT_ID_BLOCK_JOB,
+ C.virConnectDomainEventGenericCallback(callbackPtr),
+ C.long(goCallBackId), &err)
+ if ret == -1 {
+ freeCallbackId(goCallBackId)
+ return 0, makeError(&err)
+ }
+ return int(ret), nil
+}
+
+func (c *Connect) DomainEventDiskChangeRegister(dom *Domain, callback DomainEventDiskChangeCallback) (int, error) {
+ goCallBackId := registerCallbackId(callback)
+
+ callbackPtr := unsafe.Pointer(C.domainEventDiskChangeCallbackHelper)
+ var cdom C.virDomainPtr
+ if dom != nil {
+ cdom = dom.ptr
+ }
+ var err C.virError
+ ret := C.virConnectDomainEventRegisterAnyWrapper(c.ptr, cdom,
+ C.VIR_DOMAIN_EVENT_ID_DISK_CHANGE,
+ C.virConnectDomainEventGenericCallback(callbackPtr),
+ C.long(goCallBackId), &err)
+ if ret == -1 {
+ freeCallbackId(goCallBackId)
+ return 0, makeError(&err)
+ }
+ return int(ret), nil
+}
+
+func (c *Connect) DomainEventTrayChangeRegister(dom *Domain, callback DomainEventTrayChangeCallback) (int, error) {
+ goCallBackId := registerCallbackId(callback)
+
+ callbackPtr := unsafe.Pointer(C.domainEventTrayChangeCallbackHelper)
+ var cdom C.virDomainPtr
+ if dom != nil {
+ cdom = dom.ptr
+ }
+ var err C.virError
+ ret := C.virConnectDomainEventRegisterAnyWrapper(c.ptr, cdom,
+ C.VIR_DOMAIN_EVENT_ID_TRAY_CHANGE,
+ C.virConnectDomainEventGenericCallback(callbackPtr),
+ C.long(goCallBackId), &err)
+ if ret == -1 {
+ freeCallbackId(goCallBackId)
+ return 0, makeError(&err)
+ }
+ return int(ret), nil
+}
+
+func (c *Connect) DomainEventPMWakeupRegister(dom *Domain, callback DomainEventPMWakeupCallback) (int, error) {
+ goCallBackId := registerCallbackId(callback)
+
+ callbackPtr := unsafe.Pointer(C.domainEventPMWakeupCallbackHelper)
+ var cdom C.virDomainPtr
+ if dom != nil {
+ cdom = dom.ptr
+ }
+ var err C.virError
+ ret := C.virConnectDomainEventRegisterAnyWrapper(c.ptr, cdom,
+ C.VIR_DOMAIN_EVENT_ID_PMWAKEUP,
+ C.virConnectDomainEventGenericCallback(callbackPtr),
+ C.long(goCallBackId), &err)
+ if ret == -1 {
+ freeCallbackId(goCallBackId)
+ return 0, makeError(&err)
+ }
+ return int(ret), nil
+}
+
+func (c *Connect) DomainEventPMSuspendRegister(dom *Domain, callback DomainEventPMSuspendCallback) (int, error) {
+ goCallBackId := registerCallbackId(callback)
+
+ callbackPtr := unsafe.Pointer(C.domainEventPMSuspendCallbackHelper)
+ var cdom C.virDomainPtr
+ if dom != nil {
+ cdom = dom.ptr
+ }
+ var err C.virError
+ ret := C.virConnectDomainEventRegisterAnyWrapper(c.ptr, cdom,
+ C.VIR_DOMAIN_EVENT_ID_PMSUSPEND,
+ C.virConnectDomainEventGenericCallback(callbackPtr),
+ C.long(goCallBackId), &err)
+ if ret == -1 {
+ freeCallbackId(goCallBackId)
+ return 0, makeError(&err)
+ }
+ return int(ret), nil
+}
+
+func (c *Connect) DomainEventBalloonChangeRegister(dom *Domain, callback DomainEventBalloonChangeCallback) (int, error) {
+ goCallBackId := registerCallbackId(callback)
+
+ callbackPtr := unsafe.Pointer(C.domainEventBalloonChangeCallbackHelper)
+ var cdom C.virDomainPtr
+ if dom != nil {
+ cdom = dom.ptr
+ }
+ var err C.virError
+ ret := C.virConnectDomainEventRegisterAnyWrapper(c.ptr, cdom,
+ C.VIR_DOMAIN_EVENT_ID_BALLOON_CHANGE,
+ C.virConnectDomainEventGenericCallback(callbackPtr),
+ C.long(goCallBackId), &err)
+ if ret == -1 {
+ freeCallbackId(goCallBackId)
+ return 0, makeError(&err)
+ }
+ return int(ret), nil
+}
+
+func (c *Connect) DomainEventPMSuspendDiskRegister(dom *Domain, callback DomainEventPMSuspendDiskCallback) (int, error) {
+ goCallBackId := registerCallbackId(callback)
+
+ callbackPtr := unsafe.Pointer(C.domainEventPMSuspendDiskCallbackHelper)
+ var cdom C.virDomainPtr
+ if dom != nil {
+ cdom = dom.ptr
+ }
+ var err C.virError
+ ret := C.virConnectDomainEventRegisterAnyWrapper(c.ptr, cdom,
+ C.VIR_DOMAIN_EVENT_ID_PMSUSPEND_DISK,
+ C.virConnectDomainEventGenericCallback(callbackPtr),
+ C.long(goCallBackId), &err)
+ if ret == -1 {
+ freeCallbackId(goCallBackId)
+ return 0, makeError(&err)
+ }
+ return int(ret), nil
+}
+
+func (c *Connect) DomainEventDeviceRemovedRegister(dom *Domain, callback DomainEventDeviceRemovedCallback) (int, error) {
+ goCallBackId := registerCallbackId(callback)
+
+ callbackPtr := unsafe.Pointer(C.domainEventDeviceRemovedCallbackHelper)
+ var cdom C.virDomainPtr
+ if dom != nil {
+ cdom = dom.ptr
+ }
+ var err C.virError
+ ret := C.virConnectDomainEventRegisterAnyWrapper(c.ptr, cdom,
+ C.VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED,
+ C.virConnectDomainEventGenericCallback(callbackPtr),
+ C.long(goCallBackId), &err)
+ if ret == -1 {
+ freeCallbackId(goCallBackId)
+ return 0, makeError(&err)
+ }
+ return int(ret), nil
+}
+
+func (c *Connect) DomainEventBlockJob2Register(dom *Domain, callback DomainEventBlockJobCallback) (int, error) {
+ goCallBackId := registerCallbackId(callback)
+
+ callbackPtr := unsafe.Pointer(C.domainEventBlockJobCallbackHelper)
+ var cdom C.virDomainPtr
+ if dom != nil {
+ cdom = dom.ptr
+ }
+ var err C.virError
+ ret := C.virConnectDomainEventRegisterAnyWrapper(c.ptr, cdom,
+ C.VIR_DOMAIN_EVENT_ID_BLOCK_JOB_2,
+ C.virConnectDomainEventGenericCallback(callbackPtr),
+ C.long(goCallBackId), &err)
+ if ret == -1 {
+ freeCallbackId(goCallBackId)
+ return 0, makeError(&err)
+ }
+ return int(ret), nil
+}
+
+func (c *Connect) DomainEventTunableRegister(dom *Domain, callback DomainEventTunableCallback) (int, error) {
+ goCallBackId := registerCallbackId(callback)
+
+ callbackPtr := unsafe.Pointer(C.domainEventTunableCallbackHelper)
+ var cdom C.virDomainPtr
+ if dom != nil {
+ cdom = dom.ptr
+ }
+ var err C.virError
+ ret := C.virConnectDomainEventRegisterAnyWrapper(c.ptr, cdom,
+ C.VIR_DOMAIN_EVENT_ID_TUNABLE,
+ C.virConnectDomainEventGenericCallback(callbackPtr),
+ C.long(goCallBackId), &err)
+ if ret == -1 {
+ freeCallbackId(goCallBackId)
+ return 0, makeError(&err)
+ }
+ return int(ret), nil
+}
+
+func (c *Connect) DomainEventAgentLifecycleRegister(dom *Domain, callback DomainEventAgentLifecycleCallback) (int, error) {
+ goCallBackId := registerCallbackId(callback)
+
+ callbackPtr := unsafe.Pointer(C.domainEventAgentLifecycleCallbackHelper)
+ var cdom C.virDomainPtr
+ if dom != nil {
+ cdom = dom.ptr
+ }
+ var err C.virError
+ ret := C.virConnectDomainEventRegisterAnyWrapper(c.ptr, cdom,
+ C.VIR_DOMAIN_EVENT_ID_AGENT_LIFECYCLE,
+ C.virConnectDomainEventGenericCallback(callbackPtr),
+ C.long(goCallBackId), &err)
+ if ret == -1 {
+ freeCallbackId(goCallBackId)
+ return 0, makeError(&err)
+ }
+ return int(ret), nil
+}
+
+func (c *Connect) DomainEventDeviceAddedRegister(dom *Domain, callback DomainEventDeviceAddedCallback) (int, error) {
+ goCallBackId := registerCallbackId(callback)
+
+ callbackPtr := unsafe.Pointer(C.domainEventDeviceAddedCallbackHelper)
+ var cdom C.virDomainPtr
+ if dom != nil {
+ cdom = dom.ptr
+ }
+ var err C.virError
+ ret := C.virConnectDomainEventRegisterAnyWrapper(c.ptr, cdom,
+ C.VIR_DOMAIN_EVENT_ID_DEVICE_ADDED,
+ C.virConnectDomainEventGenericCallback(callbackPtr),
+ C.long(goCallBackId), &err)
+ if ret == -1 {
+ freeCallbackId(goCallBackId)
+ return 0, makeError(&err)
+ }
+ return int(ret), nil
+}
+
+func (c *Connect) DomainEventMigrationIterationRegister(dom *Domain, callback DomainEventMigrationIterationCallback) (int, error) {
+ goCallBackId := registerCallbackId(callback)
+
+ callbackPtr := unsafe.Pointer(C.domainEventMigrationIterationCallbackHelper)
+ var cdom C.virDomainPtr
+ if dom != nil {
+ cdom = dom.ptr
+ }
+ var err C.virError
+ ret := C.virConnectDomainEventRegisterAnyWrapper(c.ptr, cdom,
+ C.VIR_DOMAIN_EVENT_ID_MIGRATION_ITERATION,
+ C.virConnectDomainEventGenericCallback(callbackPtr),
+ C.long(goCallBackId), &err)
+ if ret == -1 {
+ freeCallbackId(goCallBackId)
+ return 0, makeError(&err)
+ }
+ return int(ret), nil
+}
+
+func (c *Connect) DomainEventJobCompletedRegister(dom *Domain, callback DomainEventJobCompletedCallback) (int, error) {
+ goCallBackId := registerCallbackId(callback)
+
+ callbackPtr := unsafe.Pointer(C.domainEventJobCompletedCallbackHelper)
+ var cdom C.virDomainPtr
+ if dom != nil {
+ cdom = dom.ptr
+ }
+ var err C.virError
+ ret := C.virConnectDomainEventRegisterAnyWrapper(c.ptr, cdom,
+ C.VIR_DOMAIN_EVENT_ID_JOB_COMPLETED,
+ C.virConnectDomainEventGenericCallback(callbackPtr),
+ C.long(goCallBackId), &err)
+ if ret == -1 {
+ freeCallbackId(goCallBackId)
+ return 0, makeError(&err)
+ }
+ return int(ret), nil
+}
+
+func (c *Connect) DomainEventDeviceRemovalFailedRegister(dom *Domain, callback DomainEventDeviceRemovalFailedCallback) (int, error) {
+ goCallBackId := registerCallbackId(callback)
+
+ callbackPtr := unsafe.Pointer(C.domainEventDeviceRemovalFailedCallbackHelper)
+ var cdom C.virDomainPtr
+ if dom != nil {
+ cdom = dom.ptr
+ }
+ var err C.virError
+ ret := C.virConnectDomainEventRegisterAnyWrapper(c.ptr, cdom,
+ C.VIR_DOMAIN_EVENT_ID_DEVICE_REMOVAL_FAILED,
+ C.virConnectDomainEventGenericCallback(callbackPtr),
+ C.long(goCallBackId), &err)
+ if ret == -1 {
+ freeCallbackId(goCallBackId)
+ return 0, makeError(&err)
+ }
+ return int(ret), nil
+}
+
+func (c *Connect) DomainEventMetadataChangeRegister(dom *Domain, callback DomainEventMetadataChangeCallback) (int, error) {
+ goCallBackId := registerCallbackId(callback)
+
+ callbackPtr := unsafe.Pointer(C.domainEventMetadataChangeCallbackHelper)
+ var cdom C.virDomainPtr
+ if dom != nil {
+ cdom = dom.ptr
+ }
+ var err C.virError
+ ret := C.virConnectDomainEventRegisterAnyWrapper(c.ptr, cdom,
+ C.VIR_DOMAIN_EVENT_ID_METADATA_CHANGE,
+ C.virConnectDomainEventGenericCallback(callbackPtr),
+ C.long(goCallBackId), &err)
+ if ret == -1 {
+ freeCallbackId(goCallBackId)
+ return 0, makeError(&err)
+ }
+ return int(ret), nil
+}
+
+func (c *Connect) DomainEventBlockThresholdRegister(dom *Domain, callback DomainEventBlockThresholdCallback) (int, error) {
+ goCallBackId := registerCallbackId(callback)
+
+ callbackPtr := unsafe.Pointer(C.domainEventBlockThresholdCallbackHelper)
+ var cdom C.virDomainPtr
+ if dom != nil {
+ cdom = dom.ptr
+ }
+ var err C.virError
+ ret := C.virConnectDomainEventRegisterAnyWrapper(c.ptr, cdom,
+ C.VIR_DOMAIN_EVENT_ID_BLOCK_THRESHOLD,
+ C.virConnectDomainEventGenericCallback(callbackPtr),
+ C.long(goCallBackId), &err)
+ if ret == -1 {
+ freeCallbackId(goCallBackId)
+ return 0, makeError(&err)
+ }
+ return int(ret), nil
+}
+
+func (c *Connect) DomainEventDeregister(callbackId int) error {
+ // Deregister the callback
+ var err C.virError
+ ret := int(C.virConnectDomainEventDeregisterAnyWrapper(c.ptr, C.int(callbackId), &err))
+ if ret < 0 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+func (e DomainEventLifecycle) String() string {
+ var detail, event string
+ switch e.Event {
+ case DOMAIN_EVENT_DEFINED:
+ event = "defined"
+ switch DomainEventDefinedDetailType(e.Detail) {
+ case DOMAIN_EVENT_DEFINED_ADDED:
+ detail = "added"
+ case DOMAIN_EVENT_DEFINED_UPDATED:
+ detail = "updated"
+ default:
+ detail = "unknown"
+ }
+
+ case DOMAIN_EVENT_UNDEFINED:
+ event = "undefined"
+ switch DomainEventUndefinedDetailType(e.Detail) {
+ case DOMAIN_EVENT_UNDEFINED_REMOVED:
+ detail = "removed"
+ default:
+ detail = "unknown"
+ }
+
+ case DOMAIN_EVENT_STARTED:
+ event = "started"
+ switch DomainEventStartedDetailType(e.Detail) {
+ case DOMAIN_EVENT_STARTED_BOOTED:
+ detail = "booted"
+ case DOMAIN_EVENT_STARTED_MIGRATED:
+ detail = "migrated"
+ case DOMAIN_EVENT_STARTED_RESTORED:
+ detail = "restored"
+ case DOMAIN_EVENT_STARTED_FROM_SNAPSHOT:
+ detail = "snapshot"
+ default:
+ detail = "unknown"
+ }
+
+ case DOMAIN_EVENT_SUSPENDED:
+ event = "suspended"
+ switch DomainEventSuspendedDetailType(e.Detail) {
+ case DOMAIN_EVENT_SUSPENDED_PAUSED:
+ detail = "paused"
+ case DOMAIN_EVENT_SUSPENDED_MIGRATED:
+ detail = "migrated"
+ case DOMAIN_EVENT_SUSPENDED_IOERROR:
+ detail = "I/O error"
+ case DOMAIN_EVENT_SUSPENDED_WATCHDOG:
+ detail = "watchdog"
+ case DOMAIN_EVENT_SUSPENDED_RESTORED:
+ detail = "restored"
+ case DOMAIN_EVENT_SUSPENDED_FROM_SNAPSHOT:
+ detail = "snapshot"
+ default:
+ detail = "unknown"
+ }
+
+ case DOMAIN_EVENT_RESUMED:
+ event = "resumed"
+ switch DomainEventResumedDetailType(e.Detail) {
+ case DOMAIN_EVENT_RESUMED_UNPAUSED:
+ detail = "unpaused"
+ case DOMAIN_EVENT_RESUMED_MIGRATED:
+ detail = "migrated"
+ case DOMAIN_EVENT_RESUMED_FROM_SNAPSHOT:
+ detail = "snapshot"
+ default:
+ detail = "unknown"
+ }
+
+ case DOMAIN_EVENT_STOPPED:
+ event = "stopped"
+ switch DomainEventStoppedDetailType(e.Detail) {
+ case DOMAIN_EVENT_STOPPED_SHUTDOWN:
+ detail = "shutdown"
+ case DOMAIN_EVENT_STOPPED_DESTROYED:
+ detail = "destroyed"
+ case DOMAIN_EVENT_STOPPED_CRASHED:
+ detail = "crashed"
+ case DOMAIN_EVENT_STOPPED_MIGRATED:
+ detail = "migrated"
+ case DOMAIN_EVENT_STOPPED_SAVED:
+ detail = "saved"
+ case DOMAIN_EVENT_STOPPED_FAILED:
+ detail = "failed"
+ case DOMAIN_EVENT_STOPPED_FROM_SNAPSHOT:
+ detail = "snapshot"
+ default:
+ detail = "unknown"
+ }
+
+ case DOMAIN_EVENT_SHUTDOWN:
+ event = "shutdown"
+ switch DomainEventShutdownDetailType(e.Detail) {
+ case DOMAIN_EVENT_SHUTDOWN_FINISHED:
+ detail = "finished"
+ default:
+ detail = "unknown"
+ }
+
+ default:
+ event = "unknown"
+ }
+
+ return fmt.Sprintf("Domain event=%q detail=%q", event, detail)
+}
+
+func (e DomainEventRTCChange) String() string {
+ return fmt.Sprintf("RTC change offset=%d", e.Utcoffset)
+}
+
+func (e DomainEventWatchdog) String() string {
+ return fmt.Sprintf("Watchdog action=%d", e.Action)
+}
+
+func (e DomainEventIOError) String() string {
+ return fmt.Sprintf("I/O error path=%q alias=%q action=%d",
+ e.SrcPath, e.DevAlias, e.Action)
+}
+
+func (e DomainEventGraphics) String() string {
+ var phase string
+ switch e.Phase {
+ case DOMAIN_EVENT_GRAPHICS_CONNECT:
+ phase = "connected"
+ case DOMAIN_EVENT_GRAPHICS_INITIALIZE:
+ phase = "initialized"
+ case DOMAIN_EVENT_GRAPHICS_DISCONNECT:
+ phase = "disconnected"
+ default:
+ phase = "unknown"
+ }
+
+ return fmt.Sprintf("Graphics phase=%q", phase)
+}
+
+func (e DomainEventIOErrorReason) String() string {
+ return fmt.Sprintf("IO error path=%q alias=%q action=%d reason=%q",
+ e.SrcPath, e.DevAlias, e.Action, e.Reason)
+}
+
+func (e DomainEventBlockJob) String() string {
+ return fmt.Sprintf("Block job disk=%q status=%d type=%d",
+ e.Disk, e.Status, e.Type)
+}
+
+func (e DomainEventDiskChange) String() string {
+ return fmt.Sprintf("Disk change old=%q new=%q alias=%q reason=%d",
+ e.OldSrcPath, e.NewSrcPath, e.DevAlias, e.Reason)
+}
+
+func (e DomainEventTrayChange) String() string {
+ return fmt.Sprintf("Tray change dev=%q reason=%d",
+ e.DevAlias, e.Reason)
+}
+
+func (e DomainEventBalloonChange) String() string {
+ return fmt.Sprintf("Ballon change %d", e.Actual)
+}
+
+func (e DomainEventDeviceRemoved) String() string {
+ return fmt.Sprintf("Device %q removed ", e.DevAlias)
+}
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/domain_events_wrapper.go b/src/dma/vendor/github.com/libvirt/libvirt-go/domain_events_wrapper.go
new file mode 100644
index 00000000..5d74feed
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/domain_events_wrapper.go
@@ -0,0 +1,259 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+package libvirt
+
+/*
+#cgo pkg-config: libvirt
+#include "domain_events_wrapper.h"
+#include "callbacks_wrapper.h"
+#include <stdint.h>
+
+extern void domainEventLifecycleCallback(virConnectPtr, virDomainPtr, int, int, int);
+void domainEventLifecycleCallbackHelper(virConnectPtr c, virDomainPtr d,
+ int event, int detail, void *data)
+{
+ domainEventLifecycleCallback(c, d, event, detail, (int)(intptr_t)data);
+}
+
+extern void domainEventGenericCallback(virConnectPtr, virDomainPtr, int);
+void domainEventGenericCallbackHelper(virConnectPtr c, virDomainPtr d, void *data)
+{
+ domainEventGenericCallback(c, d, (int)(intptr_t)data);
+}
+
+extern void domainEventRTCChangeCallback(virConnectPtr, virDomainPtr, long long, int);
+void domainEventRTCChangeCallbackHelper(virConnectPtr c, virDomainPtr d,
+ long long utcoffset, void *data)
+{
+ domainEventRTCChangeCallback(c, d, utcoffset, (int)(intptr_t)data);
+}
+
+extern void domainEventWatchdogCallback(virConnectPtr, virDomainPtr, int, int);
+void domainEventWatchdogCallbackHelper(virConnectPtr c, virDomainPtr d,
+ int action, void *data)
+{
+ domainEventWatchdogCallback(c, d, action, (int)(intptr_t)data);
+}
+
+extern void domainEventIOErrorCallback(virConnectPtr, virDomainPtr, const char *, const char *, int, int);
+void domainEventIOErrorCallbackHelper(virConnectPtr c, virDomainPtr d,
+ const char *srcPath, const char *devAlias,
+ int action, void *data)
+{
+ domainEventIOErrorCallback(c, d, srcPath, devAlias, action, (int)(intptr_t)data);
+}
+
+extern void domainEventGraphicsCallback(virConnectPtr, virDomainPtr, int, const virDomainEventGraphicsAddress *,
+ const virDomainEventGraphicsAddress *, const char *,
+ const virDomainEventGraphicsSubject *, int);
+void domainEventGraphicsCallbackHelper(virConnectPtr c, virDomainPtr d,
+ int phase, const virDomainEventGraphicsAddress *local,
+ const virDomainEventGraphicsAddress *remote,
+ const char *authScheme,
+ const virDomainEventGraphicsSubject *subject, void *data)
+{
+ domainEventGraphicsCallback(c, d, phase, local, remote, authScheme, subject, (int)(intptr_t)data);
+}
+
+extern void domainEventIOErrorReasonCallback(virConnectPtr, virDomainPtr, const char *, const char *,
+ int, const char *, int);
+void domainEventIOErrorReasonCallbackHelper(virConnectPtr c, virDomainPtr d,
+ const char *srcPath, const char *devAlias,
+ int action, const char *reason, void *data)
+{
+ domainEventIOErrorReasonCallback(c, d, srcPath, devAlias, action, reason, (int)(intptr_t)data);
+}
+
+extern void domainEventBlockJobCallback(virConnectPtr, virDomainPtr, const char *, int, int, int);
+void domainEventBlockJobCallbackHelper(virConnectPtr c, virDomainPtr d,
+ const char *disk, int type, int status, void *data)
+{
+ domainEventBlockJobCallback(c, d, disk, type, status, (int)(intptr_t)data);
+}
+
+extern void domainEventDiskChangeCallback(virConnectPtr, virDomainPtr, const char *, const char *,
+ const char *, int, int);
+void domainEventDiskChangeCallbackHelper(virConnectPtr c, virDomainPtr d,
+ const char *oldSrcPath, const char *newSrcPath,
+ const char *devAlias, int reason, void *data)
+{
+ domainEventDiskChangeCallback(c, d, oldSrcPath, newSrcPath, devAlias, reason, (int)(intptr_t)data);
+}
+
+extern void domainEventTrayChangeCallback(virConnectPtr, virDomainPtr, const char *, int, int);
+void domainEventTrayChangeCallbackHelper(virConnectPtr c, virDomainPtr d,
+ const char *devAlias, int reason, void *data)
+{
+ domainEventTrayChangeCallback(c, d, devAlias, reason, (int)(intptr_t)data);
+}
+
+extern void domainEventPMSuspendCallback(virConnectPtr, virDomainPtr, int, int);
+void domainEventPMSuspendCallbackHelper(virConnectPtr c, virDomainPtr d,
+ int reason, void *data)
+{
+ domainEventPMSuspendCallback(c, d, reason, (int)(intptr_t)data);
+}
+
+extern void domainEventPMWakeupCallback(virConnectPtr, virDomainPtr, int, int);
+void domainEventPMWakeupCallbackHelper(virConnectPtr c, virDomainPtr d,
+ int reason, void *data)
+{
+ domainEventPMWakeupCallback(c, d, reason, (int)(intptr_t)data);
+}
+
+extern void domainEventPMSuspendDiskCallback(virConnectPtr, virDomainPtr, int, int);
+void domainEventPMSuspendDiskCallbackHelper(virConnectPtr c, virDomainPtr d,
+ int reason, void *data)
+{
+ domainEventPMSuspendDiskCallback(c, d, reason, (int)(intptr_t)data);
+}
+
+extern void domainEventBalloonChangeCallback(virConnectPtr, virDomainPtr, unsigned long long, int);
+void domainEventBalloonChangeCallbackHelper(virConnectPtr c, virDomainPtr d,
+ unsigned long long actual, void *data)
+{
+ domainEventBalloonChangeCallback(c, d, actual, (int)(intptr_t)data);
+}
+
+extern void domainEventDeviceRemovedCallback(virConnectPtr, virDomainPtr, const char *, int);
+void domainEventDeviceRemovedCallbackHelper(virConnectPtr c, virDomainPtr d,
+ const char *devAlias, void *data)
+{
+ domainEventDeviceRemovedCallback(c, d, devAlias, (int)(intptr_t)data);
+}
+
+extern void domainEventTunableCallback(virConnectPtr, virDomainPtr, virTypedParameterPtr, int, int);
+void domainEventTunableCallbackHelper(virConnectPtr conn,
+ virDomainPtr dom,
+ virTypedParameterPtr params,
+ int nparams,
+ void *opaque)
+{
+ domainEventTunableCallback(conn, dom, params, nparams, (int)(intptr_t)opaque);
+}
+
+extern void domainEventAgentLifecycleCallback(virConnectPtr, virDomainPtr, int, int, int);
+void domainEventAgentLifecycleCallbackHelper(virConnectPtr conn,
+ virDomainPtr dom,
+ int state,
+ int reason,
+ void *opaque)
+{
+ domainEventAgentLifecycleCallback(conn, dom, state, reason, (int)(intptr_t)opaque);
+}
+
+extern void domainEventDeviceAddedCallback(virConnectPtr, virDomainPtr, const char *, int);
+void domainEventDeviceAddedCallbackHelper(virConnectPtr conn,
+ virDomainPtr dom,
+ const char *devAlias,
+ void *opaque)
+{
+ domainEventDeviceAddedCallback(conn, dom, devAlias, (int)(intptr_t)opaque);
+}
+
+extern void domainEventMigrationIterationCallback(virConnectPtr, virDomainPtr, int, int);
+void domainEventMigrationIterationCallbackHelper(virConnectPtr conn,
+ virDomainPtr dom,
+ int iteration,
+ void *opaque)
+{
+ domainEventMigrationIterationCallback(conn, dom, iteration, (int)(intptr_t)opaque);
+}
+
+extern void domainEventJobCompletedCallback(virConnectPtr, virDomainPtr, virTypedParameterPtr, int, int);
+void domainEventJobCompletedCallbackHelper(virConnectPtr conn,
+ virDomainPtr dom,
+ virTypedParameterPtr params,
+ int nparams,
+ void *opaque)
+{
+ domainEventJobCompletedCallback(conn, dom, params, nparams, (int)(intptr_t)opaque);
+}
+
+extern void domainEventDeviceRemovalFailedCallback(virConnectPtr, virDomainPtr, const char *, int);
+void domainEventDeviceRemovalFailedCallbackHelper(virConnectPtr conn,
+ virDomainPtr dom,
+ const char *devAlias,
+ void *opaque)
+{
+ domainEventDeviceRemovalFailedCallback(conn, dom, devAlias, (int)(intptr_t)opaque);
+}
+
+extern void domainEventMetadataChangeCallback(virConnectPtr, virDomainPtr, int, const char *, int);
+void domainEventMetadataChangeCallbackHelper(virConnectPtr conn,
+ virDomainPtr dom,
+ int type,
+ const char *nsuri,
+ void *opaque)
+{
+ domainEventMetadataChangeCallback(conn, dom, type, nsuri, (int)(intptr_t)opaque);
+}
+
+extern void domainEventBlockThresholdCallback(virConnectPtr, virDomainPtr, const char *, const char *, unsigned long long, unsigned long long, int);
+void domainEventBlockThresholdCallbackHelper(virConnectPtr conn,
+ virDomainPtr dom,
+ const char *dev,
+ const char *path,
+ unsigned long long threshold,
+ unsigned long long excess,
+ void *opaque)
+{
+ domainEventBlockThresholdCallback(conn, dom, dev, path, threshold, excess, (int)(intptr_t)opaque);
+}
+
+int
+virConnectDomainEventRegisterAnyWrapper(virConnectPtr c,
+ virDomainPtr d,
+ int eventID,
+ virConnectDomainEventGenericCallback cb,
+ long goCallbackId,
+ virErrorPtr err)
+{
+ void *id = (void*)goCallbackId;
+ int ret = virConnectDomainEventRegisterAny(c, d, eventID, cb, id, freeGoCallbackHelper);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virConnectDomainEventDeregisterAnyWrapper(virConnectPtr conn,
+ int callbackID,
+ virErrorPtr err)
+{
+ int ret = virConnectDomainEventDeregisterAny(conn, callbackID);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+*/
+import "C"
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/domain_events_wrapper.h b/src/dma/vendor/github.com/libvirt/libvirt-go/domain_events_wrapper.h
new file mode 100644
index 00000000..1670acdd
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/domain_events_wrapper.h
@@ -0,0 +1,207 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+#ifndef LIBVIRT_GO_DOMAIN_EVENTS_WRAPPER_H__
+#define LIBVIRT_GO_DOMAIN_EVENTS_WRAPPER_H__
+
+#include <libvirt/libvirt.h>
+#include <libvirt/virterror.h>
+#include "domain_compat.h"
+
+void
+domainEventLifecycleCallbackHelper(virConnectPtr c,
+ virDomainPtr d,
+ int event,
+ int detail,
+ void *data);
+
+void
+domainEventGenericCallbackHelper(virConnectPtr c,
+ virDomainPtr d,
+ void *data);
+
+void
+domainEventRTCChangeCallbackHelper(virConnectPtr c,
+ virDomainPtr d,
+ long long utcoffset,
+ void *data);
+
+void
+domainEventWatchdogCallbackHelper(virConnectPtr c,
+ virDomainPtr d,
+ int action,
+ void *data);
+
+void
+domainEventIOErrorCallbackHelper(virConnectPtr c,
+ virDomainPtr d,
+ const char *srcPath,
+ const char *devAlias,
+ int action,
+ void *data);
+
+void
+domainEventGraphicsCallbackHelper(virConnectPtr c,
+ virDomainPtr d,
+ int phase,
+ const virDomainEventGraphicsAddress *local,
+ const virDomainEventGraphicsAddress *remote,
+ const char *authScheme,
+ const virDomainEventGraphicsSubject *subject,
+ void *data);
+
+void
+domainEventIOErrorReasonCallbackHelper(virConnectPtr c,
+ virDomainPtr d,
+ const char *srcPath,
+ const char *devAlias,
+ int action,
+ const char *reason,
+ void *data);
+
+void
+domainEventBlockJobCallbackHelper(virConnectPtr c,
+ virDomainPtr d,
+ const char *disk,
+ int type,
+ int status,
+ void *data);
+
+void
+domainEventDiskChangeCallbackHelper(virConnectPtr c,
+ virDomainPtr d,
+ const char *oldSrcPath,
+ const char *newSrcPath,
+ const char *devAlias,
+ int reason,
+ void *data);
+
+void
+domainEventTrayChangeCallbackHelper(virConnectPtr c,
+ virDomainPtr d,
+ const char *devAlias,
+ int reason,
+ void *data);
+
+void
+domainEventPMSuspendCallbackHelper(virConnectPtr c,
+ virDomainPtr d,
+ int reason,
+ void *data);
+
+void
+domainEventPMWakeupCallbackHelper(virConnectPtr c,
+ virDomainPtr d,
+ int reason,
+ void *data);
+
+void
+domainEventPMSuspendDiskCallbackHelper(virConnectPtr c,
+ virDomainPtr d,
+ int reason,
+ void *data);
+
+void
+domainEventBalloonChangeCallbackHelper(virConnectPtr c,
+ virDomainPtr d,
+ unsigned long long actual,
+ void *data);
+
+void
+domainEventDeviceRemovedCallbackHelper(virConnectPtr c,
+ virDomainPtr d,
+ const char *devAlias,
+ void *data);
+
+void
+domainEventTunableCallbackHelper(virConnectPtr conn,
+ virDomainPtr dom,
+ virTypedParameterPtr params,
+ int nparams,
+ void *opaque);
+
+void
+domainEventAgentLifecycleCallbackHelper(virConnectPtr conn,
+ virDomainPtr dom,
+ int state,
+ int reason,
+ void *opaque);
+
+void
+domainEventDeviceAddedCallbackHelper(virConnectPtr conn,
+ virDomainPtr dom,
+ const char *devAlias,
+ void *opaque);
+
+void
+domainEventMigrationIterationCallbackHelper(virConnectPtr conn,
+ virDomainPtr dom,
+ int iteration,
+ void *opaque);
+
+void
+domainEventJobCompletedCallbackHelper(virConnectPtr conn,
+ virDomainPtr dom,
+ virTypedParameterPtr params,
+ int nparams,
+ void *opaque);
+
+void
+domainEventDeviceRemovalFailedCallbackHelper(virConnectPtr conn,
+ virDomainPtr dom,
+ const char *devAlias,
+ void *opaque);
+
+void
+domainEventMetadataChangeCallbackHelper(virConnectPtr conn,
+ virDomainPtr dom,
+ int type,
+ const char *nsuri,
+ void *opaque);
+
+void
+domainEventBlockThresholdCallbackHelper(virConnectPtr conn,
+ virDomainPtr dom,
+ const char *dev,
+ const char *path,
+ unsigned long long threshold,
+ unsigned long long excess,
+ void *opaque);
+
+int
+virConnectDomainEventRegisterAnyWrapper(virConnectPtr c,
+ virDomainPtr d,
+ int eventID,
+ virConnectDomainEventGenericCallback cb,
+ long goCallbackId,
+ virErrorPtr err);
+int
+virConnectDomainEventDeregisterAnyWrapper(virConnectPtr conn,
+ int callbackID,
+ virErrorPtr err);
+
+
+#endif /* LIBVIRT_GO_DOMAIN_EVENTS_WRAPPER_H__ */
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/domain_snapshot.go b/src/dma/vendor/github.com/libvirt/libvirt-go/domain_snapshot.go
new file mode 100644
index 00000000..65fbbb5c
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/domain_snapshot.go
@@ -0,0 +1,240 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+package libvirt
+
+/*
+#cgo pkg-config: libvirt
+#include <stdlib.h>
+#include "domain_snapshot_wrapper.h"
+*/
+import "C"
+
+import (
+ "reflect"
+ "unsafe"
+)
+
+type DomainSnapshotCreateFlags int
+
+const (
+ DOMAIN_SNAPSHOT_CREATE_REDEFINE = DomainSnapshotCreateFlags(C.VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE)
+ DOMAIN_SNAPSHOT_CREATE_CURRENT = DomainSnapshotCreateFlags(C.VIR_DOMAIN_SNAPSHOT_CREATE_CURRENT)
+ DOMAIN_SNAPSHOT_CREATE_NO_METADATA = DomainSnapshotCreateFlags(C.VIR_DOMAIN_SNAPSHOT_CREATE_NO_METADATA)
+ DOMAIN_SNAPSHOT_CREATE_HALT = DomainSnapshotCreateFlags(C.VIR_DOMAIN_SNAPSHOT_CREATE_HALT)
+ DOMAIN_SNAPSHOT_CREATE_DISK_ONLY = DomainSnapshotCreateFlags(C.VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY)
+ DOMAIN_SNAPSHOT_CREATE_REUSE_EXT = DomainSnapshotCreateFlags(C.VIR_DOMAIN_SNAPSHOT_CREATE_REUSE_EXT)
+ DOMAIN_SNAPSHOT_CREATE_QUIESCE = DomainSnapshotCreateFlags(C.VIR_DOMAIN_SNAPSHOT_CREATE_QUIESCE)
+ DOMAIN_SNAPSHOT_CREATE_ATOMIC = DomainSnapshotCreateFlags(C.VIR_DOMAIN_SNAPSHOT_CREATE_ATOMIC)
+ DOMAIN_SNAPSHOT_CREATE_LIVE = DomainSnapshotCreateFlags(C.VIR_DOMAIN_SNAPSHOT_CREATE_LIVE)
+)
+
+type DomainSnapshotListFlags int
+
+const (
+ DOMAIN_SNAPSHOT_LIST_ROOTS = DomainSnapshotListFlags(C.VIR_DOMAIN_SNAPSHOT_LIST_ROOTS)
+ DOMAIN_SNAPSHOT_LIST_DESCENDANTS = DomainSnapshotListFlags(C.VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS)
+ DOMAIN_SNAPSHOT_LIST_LEAVES = DomainSnapshotListFlags(C.VIR_DOMAIN_SNAPSHOT_LIST_LEAVES)
+ DOMAIN_SNAPSHOT_LIST_NO_LEAVES = DomainSnapshotListFlags(C.VIR_DOMAIN_SNAPSHOT_LIST_NO_LEAVES)
+ DOMAIN_SNAPSHOT_LIST_METADATA = DomainSnapshotListFlags(C.VIR_DOMAIN_SNAPSHOT_LIST_METADATA)
+ DOMAIN_SNAPSHOT_LIST_NO_METADATA = DomainSnapshotListFlags(C.VIR_DOMAIN_SNAPSHOT_LIST_NO_METADATA)
+ DOMAIN_SNAPSHOT_LIST_INACTIVE = DomainSnapshotListFlags(C.VIR_DOMAIN_SNAPSHOT_LIST_INACTIVE)
+ DOMAIN_SNAPSHOT_LIST_ACTIVE = DomainSnapshotListFlags(C.VIR_DOMAIN_SNAPSHOT_LIST_ACTIVE)
+ DOMAIN_SNAPSHOT_LIST_DISK_ONLY = DomainSnapshotListFlags(C.VIR_DOMAIN_SNAPSHOT_LIST_DISK_ONLY)
+ DOMAIN_SNAPSHOT_LIST_INTERNAL = DomainSnapshotListFlags(C.VIR_DOMAIN_SNAPSHOT_LIST_INTERNAL)
+ DOMAIN_SNAPSHOT_LIST_EXTERNAL = DomainSnapshotListFlags(C.VIR_DOMAIN_SNAPSHOT_LIST_EXTERNAL)
+)
+
+type DomainSnapshotRevertFlags int
+
+const (
+ DOMAIN_SNAPSHOT_REVERT_RUNNING = DomainSnapshotRevertFlags(C.VIR_DOMAIN_SNAPSHOT_REVERT_RUNNING)
+ DOMAIN_SNAPSHOT_REVERT_PAUSED = DomainSnapshotRevertFlags(C.VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED)
+ DOMAIN_SNAPSHOT_REVERT_FORCE = DomainSnapshotRevertFlags(C.VIR_DOMAIN_SNAPSHOT_REVERT_FORCE)
+)
+
+type DomainSnapshotDeleteFlags int
+
+const (
+ DOMAIN_SNAPSHOT_DELETE_CHILDREN = DomainSnapshotDeleteFlags(C.VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN)
+ DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY = DomainSnapshotDeleteFlags(C.VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY)
+ DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY = DomainSnapshotDeleteFlags(C.VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY)
+)
+
+type DomainSnapshot struct {
+ ptr C.virDomainSnapshotPtr
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain-snapshot.html#virDomainSnapshotFree
+func (s *DomainSnapshot) Free() error {
+ var err C.virError
+ ret := C.virDomainSnapshotFreeWrapper(s.ptr, &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain-snapshot.html#virDomainSnapshotRef
+func (c *DomainSnapshot) Ref() error {
+ var err C.virError
+ ret := C.virDomainSnapshotRefWrapper(c.ptr, &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain-snapshot.html#virDomainSnapshotDelete
+func (s *DomainSnapshot) Delete(flags DomainSnapshotDeleteFlags) error {
+ var err C.virError
+ result := C.virDomainSnapshotDeleteWrapper(s.ptr, C.uint(flags), &err)
+ if result != 0 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain-snapshot.html#virDomainRevertToSnapshot
+func (s *DomainSnapshot) RevertToSnapshot(flags DomainSnapshotRevertFlags) error {
+ var err C.virError
+ result := C.virDomainRevertToSnapshotWrapper(s.ptr, C.uint(flags), &err)
+ if result != 0 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain-snapshot.html#virDomainSnapshotIsCurrent
+func (s *DomainSnapshot) IsCurrent(flags uint32) (bool, error) {
+ var err C.virError
+ result := C.virDomainSnapshotIsCurrentWrapper(s.ptr, C.uint(flags), &err)
+ if result == -1 {
+ return false, makeError(&err)
+ }
+ if result == 1 {
+ return true, nil
+ }
+ return false, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain-snapshot.html#virDomainSnapshotHasMetadata
+func (s *DomainSnapshot) HasMetadata(flags uint32) (bool, error) {
+ var err C.virError
+ result := C.virDomainSnapshotHasMetadataWrapper(s.ptr, C.uint(flags), &err)
+ if result == -1 {
+ return false, makeError(&err)
+ }
+ if result == 1 {
+ return true, nil
+ }
+ return false, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain-snapshot.html#virDomainSnapshotGetXMLDesc
+func (s *DomainSnapshot) GetXMLDesc(flags DomainXMLFlags) (string, error) {
+ var err C.virError
+ result := C.virDomainSnapshotGetXMLDescWrapper(s.ptr, C.uint(flags), &err)
+ if result == nil {
+ return "", makeError(&err)
+ }
+ xml := C.GoString(result)
+ C.free(unsafe.Pointer(result))
+ return xml, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain-snapshot.html#virDomainSnapshotGetName
+func (s *DomainSnapshot) GetName() (string, error) {
+ var err C.virError
+ name := C.virDomainSnapshotGetNameWrapper(s.ptr, &err)
+ if name == nil {
+ return "", makeError(&err)
+ }
+ return C.GoString(name), nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain-snapshot.html#virDomainSnapshotGetParent
+func (s *DomainSnapshot) GetParent(flags uint32) (*DomainSnapshot, error) {
+ var err C.virError
+ ptr := C.virDomainSnapshotGetParentWrapper(s.ptr, C.uint(flags), &err)
+ if ptr == nil {
+ return nil, makeError(&err)
+ }
+ return &DomainSnapshot{ptr: ptr}, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain-snapshot.html#virDomainSnapshotNumChildren
+func (s *DomainSnapshot) NumChildren(flags DomainSnapshotListFlags) (int, error) {
+ var err C.virError
+ result := int(C.virDomainSnapshotNumChildrenWrapper(s.ptr, C.uint(flags), &err))
+ if result == -1 {
+ return 0, makeError(&err)
+ }
+ return result, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain-snapshot.html#virDomainSnapshotListChildrenNames
+func (s *DomainSnapshot) ListChildrenNames(flags DomainSnapshotListFlags) ([]string, error) {
+ const maxNames = 1024
+ var names [maxNames](*C.char)
+ namesPtr := unsafe.Pointer(&names)
+ var err C.virError
+ numNames := C.virDomainSnapshotListChildrenNamesWrapper(
+ s.ptr,
+ (**C.char)(namesPtr),
+ maxNames, C.uint(flags), &err)
+ if numNames == -1 {
+ return nil, makeError(&err)
+ }
+ goNames := make([]string, numNames)
+ for k := 0; k < int(numNames); k++ {
+ goNames[k] = C.GoString(names[k])
+ C.free(unsafe.Pointer(names[k]))
+ }
+ return goNames, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-domain-snapshot.html#virDomainSnapshotListAllChildren
+func (d *DomainSnapshot) ListAllChildren(flags DomainSnapshotListFlags) ([]DomainSnapshot, error) {
+ var cList *C.virDomainSnapshotPtr
+ var err C.virError
+ numVols := C.virDomainSnapshotListAllChildrenWrapper(d.ptr, (**C.virDomainSnapshotPtr)(&cList), C.uint(flags), &err)
+ if numVols == -1 {
+ return nil, makeError(&err)
+ }
+ hdr := reflect.SliceHeader{
+ Data: uintptr(unsafe.Pointer(cList)),
+ Len: int(numVols),
+ Cap: int(numVols),
+ }
+ var pools []DomainSnapshot
+ slice := *(*[]C.virDomainSnapshotPtr)(unsafe.Pointer(&hdr))
+ for _, ptr := range slice {
+ pools = append(pools, DomainSnapshot{ptr})
+ }
+ C.free(unsafe.Pointer(cList))
+ return pools, nil
+}
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/domain_snapshot_wrapper.go b/src/dma/vendor/github.com/libvirt/libvirt-go/domain_snapshot_wrapper.go
new file mode 100644
index 00000000..a061dee0
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/domain_snapshot_wrapper.go
@@ -0,0 +1,215 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (C) 2018 Red Hat, Inc.
+ *
+ */
+
+package libvirt
+
+/*
+#cgo pkg-config: libvirt
+#include <assert.h>
+#include "domain_snapshot_wrapper.h"
+
+
+int
+virDomainRevertToSnapshotWrapper(virDomainSnapshotPtr snapshot,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainRevertToSnapshot(snapshot, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainSnapshotDeleteWrapper(virDomainSnapshotPtr snapshot,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainSnapshotDelete(snapshot, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainSnapshotFreeWrapper(virDomainSnapshotPtr snapshot,
+ virErrorPtr err)
+{
+ int ret = virDomainSnapshotFree(snapshot);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+virConnectPtr
+virDomainSnapshotGetConnectWrapper(virDomainSnapshotPtr snapshot,
+ virErrorPtr err)
+{
+ virConnectPtr ret = virDomainSnapshotGetConnect(snapshot);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+virDomainPtr
+virDomainSnapshotGetDomainWrapper(virDomainSnapshotPtr snapshot,
+ virErrorPtr err)
+{
+ virDomainPtr ret = virDomainSnapshotGetDomain(snapshot);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+const char *
+virDomainSnapshotGetNameWrapper(virDomainSnapshotPtr snapshot,
+ virErrorPtr err)
+{
+ const char * ret = virDomainSnapshotGetName(snapshot);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+virDomainSnapshotPtr
+virDomainSnapshotGetParentWrapper(virDomainSnapshotPtr snapshot,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ virDomainSnapshotPtr ret = virDomainSnapshotGetParent(snapshot, flags);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+char *
+virDomainSnapshotGetXMLDescWrapper(virDomainSnapshotPtr snapshot,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ char * ret = virDomainSnapshotGetXMLDesc(snapshot, flags);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainSnapshotHasMetadataWrapper(virDomainSnapshotPtr snapshot,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainSnapshotHasMetadata(snapshot, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainSnapshotIsCurrentWrapper(virDomainSnapshotPtr snapshot,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainSnapshotIsCurrent(snapshot, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainSnapshotListAllChildrenWrapper(virDomainSnapshotPtr snapshot,
+ virDomainSnapshotPtr **snaps,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainSnapshotListAllChildren(snapshot, snaps, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainSnapshotListChildrenNamesWrapper(virDomainSnapshotPtr snapshot,
+ char **names,
+ int nameslen,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainSnapshotListChildrenNames(snapshot, names, nameslen, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainSnapshotNumChildrenWrapper(virDomainSnapshotPtr snapshot,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainSnapshotNumChildren(snapshot, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainSnapshotRefWrapper(virDomainSnapshotPtr snapshot,
+ virErrorPtr err)
+{
+ int ret = virDomainSnapshotRef(snapshot);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+*/
+import "C"
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/domain_snapshot_wrapper.h b/src/dma/vendor/github.com/libvirt/libvirt-go/domain_snapshot_wrapper.h
new file mode 100644
index 00000000..fcf8036b
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/domain_snapshot_wrapper.h
@@ -0,0 +1,102 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (C) 2018 Red Hat, Inc.
+ *
+ */
+
+#ifndef LIBVIRT_GO_DOMAIN_SNAPSHOT_WRAPPER_H__
+#define LIBVIRT_GO_DOMAIN_SNAPSHOT_WRAPPER_H__
+
+#include <libvirt/libvirt.h>
+#include <libvirt/virterror.h>
+
+
+int
+virDomainRevertToSnapshotWrapper(virDomainSnapshotPtr snapshot,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainSnapshotDeleteWrapper(virDomainSnapshotPtr snapshot,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainSnapshotFreeWrapper(virDomainSnapshotPtr snapshot,
+ virErrorPtr err);
+
+virConnectPtr
+virDomainSnapshotGetConnectWrapper(virDomainSnapshotPtr snapshot,
+ virErrorPtr err);
+
+virDomainPtr
+virDomainSnapshotGetDomainWrapper(virDomainSnapshotPtr snapshot,
+ virErrorPtr err);
+
+const char *
+virDomainSnapshotGetNameWrapper(virDomainSnapshotPtr snapshot,
+ virErrorPtr err);
+
+virDomainSnapshotPtr
+virDomainSnapshotGetParentWrapper(virDomainSnapshotPtr snapshot,
+ unsigned int flags,
+ virErrorPtr err);
+
+char *
+virDomainSnapshotGetXMLDescWrapper(virDomainSnapshotPtr snapshot,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainSnapshotHasMetadataWrapper(virDomainSnapshotPtr snapshot,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainSnapshotIsCurrentWrapper(virDomainSnapshotPtr snapshot,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainSnapshotListAllChildrenWrapper(virDomainSnapshotPtr snapshot,
+ virDomainSnapshotPtr **snaps,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainSnapshotListChildrenNamesWrapper(virDomainSnapshotPtr snapshot,
+ char **names,
+ int nameslen,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainSnapshotNumChildrenWrapper(virDomainSnapshotPtr snapshot,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainSnapshotRefWrapper(virDomainSnapshotPtr snapshot,
+ virErrorPtr err);
+
+
+#endif /* LIBVIRT_GO_DOMAIN_SNAPSHOT_WRAPPER_H__ */
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/domain_wrapper.go b/src/dma/vendor/github.com/libvirt/libvirt-go/domain_wrapper.go
new file mode 100644
index 00000000..b42dd42f
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/domain_wrapper.go
@@ -0,0 +1,2330 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+package libvirt
+
+/*
+#cgo pkg-config: libvirt
+#include <assert.h>
+#include "domain_wrapper.h"
+
+int
+virDomainAbortJobWrapper(virDomainPtr domain,
+ virErrorPtr err)
+{
+ int ret = virDomainAbortJob(domain);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainAddIOThreadWrapper(virDomainPtr domain,
+ unsigned int iothread_id,
+ unsigned int flags,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 1002015
+ assert(0); // Caller should have checked version
+#else
+ int ret = virDomainAddIOThread(domain, iothread_id, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+int
+virDomainAttachDeviceWrapper(virDomainPtr domain,
+ const char *xml,
+ virErrorPtr err)
+{
+ int ret = virDomainAttachDevice(domain, xml);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainAttachDeviceFlagsWrapper(virDomainPtr domain,
+ const char *xml,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainAttachDeviceFlags(domain, xml, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainBlockCommitWrapper(virDomainPtr dom,
+ const char *disk,
+ const char *base,
+ const char *top,
+ unsigned long bandwidth,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainBlockCommit(dom, disk, base, top, bandwidth, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainBlockCopyWrapper(virDomainPtr dom,
+ const char *disk,
+ const char *destxml,
+ virTypedParameterPtr params,
+ int nparams,
+ unsigned int flags,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 1002008
+ assert(0); // Caller should have checked version
+#else
+ int ret = virDomainBlockCopy(dom, disk, destxml, params, nparams, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+int
+virDomainBlockJobAbortWrapper(virDomainPtr dom,
+ const char *disk,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainBlockJobAbort(dom, disk, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainBlockJobSetSpeedWrapper(virDomainPtr dom,
+ const char *disk,
+ unsigned long bandwidth,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainBlockJobSetSpeed(dom, disk, bandwidth, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainBlockPeekWrapper(virDomainPtr dom,
+ const char *disk,
+ unsigned long long offset,
+ size_t size,
+ void *buffer,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainBlockPeek(dom, disk, offset, size, buffer, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainBlockPullWrapper(virDomainPtr dom,
+ const char *disk,
+ unsigned long bandwidth,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainBlockPull(dom, disk, bandwidth, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainBlockRebaseWrapper(virDomainPtr dom,
+ const char *disk,
+ const char *base,
+ unsigned long bandwidth,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainBlockRebase(dom, disk, base, bandwidth, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainBlockResizeWrapper(virDomainPtr dom,
+ const char *disk,
+ unsigned long long size,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainBlockResize(dom, disk, size, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainBlockStatsWrapper(virDomainPtr dom,
+ const char *disk,
+ virDomainBlockStatsPtr stats,
+ size_t size,
+ virErrorPtr err)
+{
+ int ret = virDomainBlockStats(dom, disk, stats, size);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainBlockStatsFlagsWrapper(virDomainPtr dom,
+ const char *disk,
+ virTypedParameterPtr params,
+ int *nparams,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainBlockStatsFlags(dom, disk, params, nparams, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainCoreDumpWrapper(virDomainPtr domain,
+ const char *to,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainCoreDump(domain, to, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainCoreDumpWithFormatWrapper(virDomainPtr domain,
+ const char *to,
+ unsigned int dumpformat,
+ unsigned int flags,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 1002003
+ assert(0); // Caller should have checked version
+#else
+ int ret = virDomainCoreDumpWithFormat(domain, to, dumpformat, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+int
+virDomainCreateWrapper(virDomainPtr domain,
+ virErrorPtr err)
+{
+ int ret = virDomainCreate(domain);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainCreateWithFilesWrapper(virDomainPtr domain,
+ unsigned int nfiles,
+ int *files,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainCreateWithFiles(domain, nfiles, files, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainCreateWithFlagsWrapper(virDomainPtr domain,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainCreateWithFlags(domain, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainDelIOThreadWrapper(virDomainPtr domain,
+ unsigned int iothread_id,
+ unsigned int flags,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 1002015
+ assert(0); // Caller should have checked version
+#else
+ int ret = virDomainDelIOThread(domain, iothread_id, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+int
+virDomainDestroyWrapper(virDomainPtr domain,
+ virErrorPtr err)
+{
+ int ret = virDomainDestroy(domain);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainDestroyFlagsWrapper(virDomainPtr domain,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainDestroyFlags(domain, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainDetachDeviceWrapper(virDomainPtr domain,
+ const char *xml,
+ virErrorPtr err)
+{
+ int ret = virDomainDetachDevice(domain, xml);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainDetachDeviceAliasWrapper(virDomainPtr domain,
+ const char *alias,
+ unsigned int flags,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 4004000
+ assert(0); // Caller should have checked version
+#else
+ int ret = virDomainDetachDeviceAlias(domain, alias, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+int
+virDomainDetachDeviceFlagsWrapper(virDomainPtr domain,
+ const char *xml,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainDetachDeviceFlags(domain, xml, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainFSFreezeWrapper(virDomainPtr dom,
+ const char **mountpoints,
+ unsigned int nmountpoints,
+ unsigned int flags,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 1002005
+ assert(0); // Caller should have checked version
+#else
+ int ret = virDomainFSFreeze(dom, mountpoints, nmountpoints, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+void
+virDomainFSInfoFreeWrapper(virDomainFSInfoPtr info)
+{
+#if LIBVIR_VERSION_NUMBER < 1002011
+ assert(0); // Caller should have checked version
+#else
+ virDomainFSInfoFree(info);
+#endif
+}
+
+
+int
+virDomainFSThawWrapper(virDomainPtr dom,
+ const char **mountpoints,
+ unsigned int nmountpoints,
+ unsigned int flags,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 1002005
+ assert(0); // Caller should have checked version
+#else
+ int ret = virDomainFSThaw(dom, mountpoints, nmountpoints, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+int
+virDomainFSTrimWrapper(virDomainPtr dom,
+ const char *mountPoint,
+ unsigned long long minimum,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainFSTrim(dom, mountPoint, minimum, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainFreeWrapper(virDomainPtr domain,
+ virErrorPtr err)
+{
+ int ret = virDomainFree(domain);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainGetAutostartWrapper(virDomainPtr domain,
+ int *autostart,
+ virErrorPtr err)
+{
+ int ret = virDomainGetAutostart(domain, autostart);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainGetBlkioParametersWrapper(virDomainPtr domain,
+ virTypedParameterPtr params,
+ int *nparams,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainGetBlkioParameters(domain, params, nparams, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainGetBlockInfoWrapper(virDomainPtr domain,
+ const char *disk,
+ virDomainBlockInfoPtr info,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainGetBlockInfo(domain, disk, info, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainGetBlockIoTuneWrapper(virDomainPtr dom,
+ const char *disk,
+ virTypedParameterPtr params,
+ int *nparams,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainGetBlockIoTune(dom, disk, params, nparams, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainGetBlockJobInfoWrapper(virDomainPtr dom,
+ const char *disk,
+ virDomainBlockJobInfoPtr info,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainGetBlockJobInfo(dom, disk, info, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainGetCPUStatsWrapper(virDomainPtr domain,
+ virTypedParameterPtr params,
+ unsigned int nparams,
+ int start_cpu,
+ unsigned int ncpus,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainGetCPUStats(domain, params, nparams, start_cpu, ncpus, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+virConnectPtr
+virDomainGetConnectWrapper(virDomainPtr dom,
+ virErrorPtr err)
+{
+ virConnectPtr ret = virDomainGetConnect(dom);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainGetControlInfoWrapper(virDomainPtr domain,
+ virDomainControlInfoPtr info,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainGetControlInfo(domain, info, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainGetDiskErrorsWrapper(virDomainPtr dom,
+ virDomainDiskErrorPtr errors,
+ unsigned int maxerrors,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainGetDiskErrors(dom, errors, maxerrors, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainGetEmulatorPinInfoWrapper(virDomainPtr domain,
+ unsigned char *cpumap,
+ int maplen,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainGetEmulatorPinInfo(domain, cpumap, maplen, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainGetFSInfoWrapper(virDomainPtr dom,
+ virDomainFSInfoPtr **info,
+ unsigned int flags,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 1002011
+ assert(0); // Caller should have checked version
+#else
+ int ret = virDomainGetFSInfo(dom, info, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+int
+virDomainGetGuestVcpusWrapper(virDomainPtr domain,
+ virTypedParameterPtr *params,
+ unsigned int *nparams,
+ unsigned int flags,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 2000000
+ assert(0); // Caller should have checked version
+#else
+ int ret = virDomainGetGuestVcpus(domain, params, nparams, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+char *
+virDomainGetHostnameWrapper(virDomainPtr domain,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ char * ret = virDomainGetHostname(domain, flags);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+unsigned int
+virDomainGetIDWrapper(virDomainPtr domain,
+ virErrorPtr err)
+{
+ unsigned int ret = virDomainGetID(domain);
+ if (ret == (unsigned int)-1) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainGetIOThreadInfoWrapper(virDomainPtr dom,
+ virDomainIOThreadInfoPtr **info,
+ unsigned int flags,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 1002014
+ assert(0); // Caller should have checked version
+#else
+ int ret = virDomainGetIOThreadInfo(dom, info, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+int
+virDomainGetInfoWrapper(virDomainPtr domain,
+ virDomainInfoPtr info,
+ virErrorPtr err)
+{
+ int ret = virDomainGetInfo(domain, info);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainGetInterfaceParametersWrapper(virDomainPtr domain,
+ const char *device,
+ virTypedParameterPtr params,
+ int *nparams,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainGetInterfaceParameters(domain, device, params, nparams, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainGetJobInfoWrapper(virDomainPtr domain,
+ virDomainJobInfoPtr info,
+ virErrorPtr err)
+{
+ int ret = virDomainGetJobInfo(domain, info);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainGetJobStatsWrapper(virDomainPtr domain,
+ int *type,
+ virTypedParameterPtr *params,
+ int *nparams,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainGetJobStats(domain, type, params, nparams, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainGetLaunchSecurityInfoWrapper(virDomainPtr domain,
+ virTypedParameterPtr *params,
+ int *nparams,
+ unsigned int flags,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 4005000
+ assert(0); // Caller should have checked version
+#else
+ int ret = virDomainGetLaunchSecurityInfo(domain, params, nparams, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+unsigned long
+virDomainGetMaxMemoryWrapper(virDomainPtr domain,
+ virErrorPtr err)
+{
+ unsigned long ret = virDomainGetMaxMemory(domain);
+ if (ret == 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainGetMaxVcpusWrapper(virDomainPtr domain,
+ virErrorPtr err)
+{
+ int ret = virDomainGetMaxVcpus(domain);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainGetMemoryParametersWrapper(virDomainPtr domain,
+ virTypedParameterPtr params,
+ int *nparams,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainGetMemoryParameters(domain, params, nparams, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+char *
+virDomainGetMetadataWrapper(virDomainPtr domain,
+ int type,
+ const char *uri,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ char * ret = virDomainGetMetadata(domain, type, uri, flags);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+const char *
+virDomainGetNameWrapper(virDomainPtr domain,
+ virErrorPtr err)
+{
+ const char * ret = virDomainGetName(domain);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainGetNumaParametersWrapper(virDomainPtr domain,
+ virTypedParameterPtr params,
+ int *nparams,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainGetNumaParameters(domain, params, nparams, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+char *
+virDomainGetOSTypeWrapper(virDomainPtr domain,
+ virErrorPtr err)
+{
+ char * ret = virDomainGetOSType(domain);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainGetPerfEventsWrapper(virDomainPtr domain,
+ virTypedParameterPtr *params,
+ int *nparams,
+ unsigned int flags,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 1003003
+ assert(0); // Caller should have checked version
+#else
+ int ret = virDomainGetPerfEvents(domain, params, nparams, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+int
+virDomainGetSchedulerParametersWrapper(virDomainPtr domain,
+ virTypedParameterPtr params,
+ int *nparams,
+ virErrorPtr err)
+{
+ int ret = virDomainGetSchedulerParameters(domain, params, nparams);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainGetSchedulerParametersFlagsWrapper(virDomainPtr domain,
+ virTypedParameterPtr params,
+ int *nparams,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainGetSchedulerParametersFlags(domain, params, nparams, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+char *
+virDomainGetSchedulerTypeWrapper(virDomainPtr domain,
+ int *nparams,
+ virErrorPtr err)
+{
+ char * ret = virDomainGetSchedulerType(domain, nparams);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainGetSecurityLabelWrapper(virDomainPtr domain,
+ virSecurityLabelPtr seclabel,
+ virErrorPtr err)
+{
+ int ret = virDomainGetSecurityLabel(domain, seclabel);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainGetSecurityLabelListWrapper(virDomainPtr domain,
+ virSecurityLabelPtr *seclabels,
+ virErrorPtr err)
+{
+ int ret = virDomainGetSecurityLabelList(domain, seclabels);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainGetStateWrapper(virDomainPtr domain,
+ int *state,
+ int *reason,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainGetState(domain, state, reason, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainGetTimeWrapper(virDomainPtr dom,
+ long long *seconds,
+ unsigned int *nseconds,
+ unsigned int flags,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 1002005
+ assert(0); // Caller should have checked version
+#else
+ int ret = virDomainGetTime(dom, seconds, nseconds, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+int
+virDomainGetUUIDWrapper(virDomainPtr domain,
+ unsigned char *uuid,
+ virErrorPtr err)
+{
+ int ret = virDomainGetUUID(domain, uuid);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainGetUUIDStringWrapper(virDomainPtr domain,
+ char *buf,
+ virErrorPtr err)
+{
+ int ret = virDomainGetUUIDString(domain, buf);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainGetVcpuPinInfoWrapper(virDomainPtr domain,
+ int ncpumaps,
+ unsigned char *cpumaps,
+ int maplen,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainGetVcpuPinInfo(domain, ncpumaps, cpumaps, maplen, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainGetVcpusWrapper(virDomainPtr domain,
+ virVcpuInfoPtr info,
+ int maxinfo,
+ unsigned char *cpumaps,
+ int maplen,
+ virErrorPtr err)
+{
+ int ret = virDomainGetVcpus(domain, info, maxinfo, cpumaps, maplen);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainGetVcpusFlagsWrapper(virDomainPtr domain,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainGetVcpusFlags(domain, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+char *
+virDomainGetXMLDescWrapper(virDomainPtr domain,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ char * ret = virDomainGetXMLDesc(domain, flags);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainHasCurrentSnapshotWrapper(virDomainPtr domain,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainHasCurrentSnapshot(domain, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainHasManagedSaveImageWrapper(virDomainPtr dom,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainHasManagedSaveImage(dom, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainInjectNMIWrapper(virDomainPtr domain,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainInjectNMI(domain, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainInterfaceAddressesWrapper(virDomainPtr dom,
+ virDomainInterfacePtr **ifaces,
+ unsigned int source,
+ unsigned int flags,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 1002014
+ assert(0); // Caller should have checked version
+#else
+ int ret = virDomainInterfaceAddresses(dom, ifaces, source, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+void
+virDomainInterfaceFreeWrapper(virDomainInterfacePtr iface)
+{
+#if LIBVIR_VERSION_NUMBER < 1002014
+ assert(0); // Caller should have checked version
+#else
+ virDomainInterfaceFree(iface);
+#endif
+}
+
+
+int
+virDomainInterfaceStatsWrapper(virDomainPtr dom,
+ const char *device,
+ virDomainInterfaceStatsPtr stats,
+ size_t size,
+ virErrorPtr err)
+{
+ int ret = virDomainInterfaceStats(dom, device, stats, size);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+void
+virDomainIOThreadInfoFreeWrapper(virDomainIOThreadInfoPtr info)
+{
+#if LIBVIR_VERSION_NUMBER < 1002014
+ assert(0); // Caller should have checked version
+#else
+ virDomainIOThreadInfoFree(info);
+#endif
+}
+
+
+int
+virDomainIsActiveWrapper(virDomainPtr dom,
+ virErrorPtr err)
+{
+ int ret = virDomainIsActive(dom);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainIsPersistentWrapper(virDomainPtr dom,
+ virErrorPtr err)
+{
+ int ret = virDomainIsPersistent(dom);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainIsUpdatedWrapper(virDomainPtr dom,
+ virErrorPtr err)
+{
+ int ret = virDomainIsUpdated(dom);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainListAllSnapshotsWrapper(virDomainPtr domain,
+ virDomainSnapshotPtr **snaps,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainListAllSnapshots(domain, snaps, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainManagedSaveWrapper(virDomainPtr dom,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainManagedSave(dom, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainManagedSaveDefineXMLWrapper(virDomainPtr domain,
+ const char *dxml,
+ unsigned int flags,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 3007000
+ assert(0); // Caller should have checked version
+#else
+ int ret = virDomainManagedSaveDefineXML(domain, dxml, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+char *
+virDomainManagedSaveGetXMLDescWrapper(virDomainPtr domain,
+ unsigned int flags,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 3007000
+ assert(0); // Caller should have checked version
+#else
+ char * ret = virDomainManagedSaveGetXMLDesc(domain, flags);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+int
+virDomainManagedSaveRemoveWrapper(virDomainPtr dom,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainManagedSaveRemove(dom, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainMemoryPeekWrapper(virDomainPtr dom,
+ unsigned long long start,
+ size_t size,
+ void *buffer,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainMemoryPeek(dom, start, size, buffer, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainMemoryStatsWrapper(virDomainPtr dom,
+ virDomainMemoryStatPtr stats,
+ unsigned int nr_stats,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainMemoryStats(dom, stats, nr_stats, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+virDomainPtr
+virDomainMigrateWrapper(virDomainPtr domain,
+ virConnectPtr dconn,
+ unsigned long flags,
+ const char *dname,
+ const char *uri,
+ unsigned long bandwidth,
+ virErrorPtr err)
+{
+ virDomainPtr ret = virDomainMigrate(domain, dconn, flags, dname, uri, bandwidth);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+virDomainPtr
+virDomainMigrate2Wrapper(virDomainPtr domain,
+ virConnectPtr dconn,
+ const char *dxml,
+ unsigned long flags,
+ const char *dname,
+ const char *uri,
+ unsigned long bandwidth,
+ virErrorPtr err)
+{
+ virDomainPtr ret = virDomainMigrate2(domain, dconn, dxml, flags, dname, uri, bandwidth);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+virDomainPtr
+virDomainMigrate3Wrapper(virDomainPtr domain,
+ virConnectPtr dconn,
+ virTypedParameterPtr params,
+ unsigned int nparams,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ virDomainPtr ret = virDomainMigrate3(domain, dconn, params, nparams, flags);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainMigrateGetCompressionCacheWrapper(virDomainPtr domain,
+ unsigned long long *cacheSize,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainMigrateGetCompressionCache(domain, cacheSize, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainMigrateGetMaxDowntimeWrapper(virDomainPtr domain,
+ unsigned long long *downtime,
+ unsigned int flags,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 3007000
+ assert(0); // Caller should have checked version
+#else
+ int ret = virDomainMigrateGetMaxDowntime(domain, downtime, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+int
+virDomainMigrateGetMaxSpeedWrapper(virDomainPtr domain,
+ unsigned long *bandwidth,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainMigrateGetMaxSpeed(domain, bandwidth, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainMigrateSetCompressionCacheWrapper(virDomainPtr domain,
+ unsigned long long cacheSize,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainMigrateSetCompressionCache(domain, cacheSize, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainMigrateSetMaxDowntimeWrapper(virDomainPtr domain,
+ unsigned long long downtime,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainMigrateSetMaxDowntime(domain, downtime, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainMigrateSetMaxSpeedWrapper(virDomainPtr domain,
+ unsigned long bandwidth,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainMigrateSetMaxSpeed(domain, bandwidth, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainMigrateStartPostCopyWrapper(virDomainPtr domain,
+ unsigned int flags,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 1003003
+ assert(0); // Caller should have checked version
+#else
+ int ret = virDomainMigrateStartPostCopy(domain, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+int
+virDomainMigrateToURIWrapper(virDomainPtr domain,
+ const char *duri,
+ unsigned long flags,
+ const char *dname,
+ unsigned long bandwidth,
+ virErrorPtr err)
+{
+ int ret = virDomainMigrateToURI(domain, duri, flags, dname, bandwidth);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainMigrateToURI2Wrapper(virDomainPtr domain,
+ const char *dconnuri,
+ const char *miguri,
+ const char *dxml,
+ unsigned long flags,
+ const char *dname,
+ unsigned long bandwidth,
+ virErrorPtr err)
+{
+ int ret = virDomainMigrateToURI2(domain, dconnuri, miguri, dxml, flags, dname, bandwidth);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainMigrateToURI3Wrapper(virDomainPtr domain,
+ const char *dconnuri,
+ virTypedParameterPtr params,
+ unsigned int nparams,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainMigrateToURI3(domain, dconnuri, params, nparams, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainOpenChannelWrapper(virDomainPtr dom,
+ const char *name,
+ virStreamPtr st,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainOpenChannel(dom, name, st, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainOpenConsoleWrapper(virDomainPtr dom,
+ const char *dev_name,
+ virStreamPtr st,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainOpenConsole(dom, dev_name, st, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainOpenGraphicsWrapper(virDomainPtr dom,
+ unsigned int idx,
+ int fd,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainOpenGraphics(dom, idx, fd, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainOpenGraphicsFDWrapper(virDomainPtr dom,
+ unsigned int idx,
+ unsigned int flags,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 1002008
+ assert(0); // Caller should have checked version
+#else
+ int ret = virDomainOpenGraphicsFD(dom, idx, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+int
+virDomainPMSuspendForDurationWrapper(virDomainPtr dom,
+ unsigned int target,
+ unsigned long long duration,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainPMSuspendForDuration(dom, target, duration, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainPMWakeupWrapper(virDomainPtr dom,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainPMWakeup(dom, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainPinEmulatorWrapper(virDomainPtr domain,
+ unsigned char *cpumap,
+ int maplen,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainPinEmulator(domain, cpumap, maplen, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainPinIOThreadWrapper(virDomainPtr domain,
+ unsigned int iothread_id,
+ unsigned char *cpumap,
+ int maplen,
+ unsigned int flags,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 1002014
+ assert(0); // Caller should have checked version
+#else
+ int ret = virDomainPinIOThread(domain, iothread_id, cpumap, maplen, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+int
+virDomainPinVcpuWrapper(virDomainPtr domain,
+ unsigned int vcpu,
+ unsigned char *cpumap,
+ int maplen,
+ virErrorPtr err)
+{
+ int ret = virDomainPinVcpu(domain, vcpu, cpumap, maplen);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainPinVcpuFlagsWrapper(virDomainPtr domain,
+ unsigned int vcpu,
+ unsigned char *cpumap,
+ int maplen,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainPinVcpuFlags(domain, vcpu, cpumap, maplen, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainRebootWrapper(virDomainPtr domain,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainReboot(domain, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainRefWrapper(virDomainPtr domain,
+ virErrorPtr err)
+{
+ int ret = virDomainRef(domain);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainRenameWrapper(virDomainPtr dom,
+ const char *new_name,
+ unsigned int flags,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 1002019
+ assert(0); // Caller should have checked version
+#else
+ int ret = virDomainRename(dom, new_name, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+int
+virDomainResetWrapper(virDomainPtr domain,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainReset(domain, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainResumeWrapper(virDomainPtr domain,
+ virErrorPtr err)
+{
+ int ret = virDomainResume(domain);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainSaveWrapper(virDomainPtr domain,
+ const char *to,
+ virErrorPtr err)
+{
+ int ret = virDomainSave(domain, to);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainSaveFlagsWrapper(virDomainPtr domain,
+ const char *to,
+ const char *dxml,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainSaveFlags(domain, to, dxml, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+char *
+virDomainScreenshotWrapper(virDomainPtr domain,
+ virStreamPtr stream,
+ unsigned int screen,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ char * ret = virDomainScreenshot(domain, stream, screen, flags);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainSendKeyWrapper(virDomainPtr domain,
+ unsigned int codeset,
+ unsigned int holdtime,
+ unsigned int *keycodes,
+ int nkeycodes,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainSendKey(domain, codeset, holdtime, keycodes, nkeycodes, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainSendProcessSignalWrapper(virDomainPtr domain,
+ long long pid_value,
+ unsigned int signum,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainSendProcessSignal(domain, pid_value, signum, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainSetAutostartWrapper(virDomainPtr domain,
+ int autostart,
+ virErrorPtr err)
+{
+ int ret = virDomainSetAutostart(domain, autostart);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainSetBlkioParametersWrapper(virDomainPtr domain,
+ virTypedParameterPtr params,
+ int nparams,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainSetBlkioParameters(domain, params, nparams, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainSetBlockIoTuneWrapper(virDomainPtr dom,
+ const char *disk,
+ virTypedParameterPtr params,
+ int nparams,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainSetBlockIoTune(dom, disk, params, nparams, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainSetBlockThresholdWrapper(virDomainPtr domain,
+ const char *dev,
+ unsigned long long threshold,
+ unsigned int flags,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 3002000
+ assert(0); // Caller should have checked version
+#else
+ int ret = virDomainSetBlockThreshold(domain, dev, threshold, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+int
+virDomainSetGuestVcpusWrapper(virDomainPtr domain,
+ const char *cpumap,
+ int state,
+ unsigned int flags,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 2000000
+ assert(0); // Caller should have checked version
+#else
+ int ret = virDomainSetGuestVcpus(domain, cpumap, state, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+int
+virDomainSetInterfaceParametersWrapper(virDomainPtr domain,
+ const char *device,
+ virTypedParameterPtr params,
+ int nparams,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainSetInterfaceParameters(domain, device, params, nparams, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainSetLifecycleActionWrapper(virDomainPtr domain,
+ unsigned int type,
+ unsigned int action,
+ unsigned int flags,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 3009000
+ assert(0); // Caller should have checked version
+#else
+ int ret = virDomainSetLifecycleAction(domain, type, action, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+int
+virDomainSetMaxMemoryWrapper(virDomainPtr domain,
+ unsigned long memory,
+ virErrorPtr err)
+{
+ int ret = virDomainSetMaxMemory(domain, memory);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainSetMemoryWrapper(virDomainPtr domain,
+ unsigned long memory,
+ virErrorPtr err)
+{
+ int ret = virDomainSetMemory(domain, memory);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainSetMemoryFlagsWrapper(virDomainPtr domain,
+ unsigned long memory,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainSetMemoryFlags(domain, memory, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainSetMemoryParametersWrapper(virDomainPtr domain,
+ virTypedParameterPtr params,
+ int nparams,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainSetMemoryParameters(domain, params, nparams, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainSetMemoryStatsPeriodWrapper(virDomainPtr domain,
+ int period,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainSetMemoryStatsPeriod(domain, period, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainSetMetadataWrapper(virDomainPtr domain,
+ int type,
+ const char *metadata,
+ const char *key,
+ const char *uri,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainSetMetadata(domain, type, metadata, key, uri, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainSetNumaParametersWrapper(virDomainPtr domain,
+ virTypedParameterPtr params,
+ int nparams,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainSetNumaParameters(domain, params, nparams, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainSetPerfEventsWrapper(virDomainPtr domain,
+ virTypedParameterPtr params,
+ int nparams,
+ unsigned int flags,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 1003003
+ assert(0); // Caller should have checked version
+#else
+ int ret = virDomainSetPerfEvents(domain, params, nparams, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+int
+virDomainSetSchedulerParametersWrapper(virDomainPtr domain,
+ virTypedParameterPtr params,
+ int nparams,
+ virErrorPtr err)
+{
+ int ret = virDomainSetSchedulerParameters(domain, params, nparams);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainSetSchedulerParametersFlagsWrapper(virDomainPtr domain,
+ virTypedParameterPtr params,
+ int nparams,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainSetSchedulerParametersFlags(domain, params, nparams, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainSetTimeWrapper(virDomainPtr dom,
+ long long seconds,
+ unsigned int nseconds,
+ unsigned int flags,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 1002005
+ assert(0); // Caller should have checked version
+#else
+ int ret = virDomainSetTime(dom, seconds, nseconds, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+int
+virDomainSetUserPasswordWrapper(virDomainPtr dom,
+ const char *user,
+ const char *password,
+ unsigned int flags,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 1002016
+ assert(0); // Caller should have checked version
+#else
+ int ret = virDomainSetUserPassword(dom, user, password, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+int
+virDomainSetVcpuWrapper(virDomainPtr domain,
+ const char *vcpumap,
+ int state,
+ unsigned int flags,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 3001000
+ assert(0); // Caller should have checked version
+#else
+ int ret = virDomainSetVcpu(domain, vcpumap, state, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+int
+virDomainSetVcpusWrapper(virDomainPtr domain,
+ unsigned int nvcpus,
+ virErrorPtr err)
+{
+ int ret = virDomainSetVcpus(domain, nvcpus);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainSetVcpusFlagsWrapper(virDomainPtr domain,
+ unsigned int nvcpus,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainSetVcpusFlags(domain, nvcpus, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainShutdownWrapper(virDomainPtr domain,
+ virErrorPtr err)
+{
+ int ret = virDomainShutdown(domain);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainShutdownFlagsWrapper(virDomainPtr domain,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainShutdownFlags(domain, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+virDomainSnapshotPtr
+virDomainSnapshotCreateXMLWrapper(virDomainPtr domain,
+ const char *xmlDesc,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ virDomainSnapshotPtr ret = virDomainSnapshotCreateXML(domain, xmlDesc, flags);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+virDomainSnapshotPtr
+virDomainSnapshotCurrentWrapper(virDomainPtr domain,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ virDomainSnapshotPtr ret = virDomainSnapshotCurrent(domain, flags);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainSnapshotListNamesWrapper(virDomainPtr domain,
+ char **names,
+ int nameslen,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainSnapshotListNames(domain, names, nameslen, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+virDomainSnapshotPtr
+virDomainSnapshotLookupByNameWrapper(virDomainPtr domain,
+ const char *name,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ virDomainSnapshotPtr ret = virDomainSnapshotLookupByName(domain, name, flags);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainSnapshotNumWrapper(virDomainPtr domain,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainSnapshotNum(domain, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainSuspendWrapper(virDomainPtr domain,
+ virErrorPtr err)
+{
+ int ret = virDomainSuspend(domain);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainUndefineWrapper(virDomainPtr domain,
+ virErrorPtr err)
+{
+ int ret = virDomainUndefine(domain);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainUndefineFlagsWrapper(virDomainPtr domain,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainUndefineFlags(domain, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainUpdateDeviceFlagsWrapper(virDomainPtr domain,
+ const char *xml,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainUpdateDeviceFlags(domain, xml, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+*/
+import "C"
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/domain_wrapper.h b/src/dma/vendor/github.com/libvirt/libvirt-go/domain_wrapper.h
new file mode 100644
index 00000000..7bd82826
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/domain_wrapper.h
@@ -0,0 +1,986 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+#ifndef LIBVIRT_GO_DOMAIN_WRAPPER_H__
+#define LIBVIRT_GO_DOMAIN_WRAPPER_H__
+
+#include <libvirt/libvirt.h>
+#include <libvirt/virterror.h>
+#include "domain_compat.h"
+
+int
+virDomainAbortJobWrapper(virDomainPtr domain,
+ virErrorPtr err);
+
+int
+virDomainAddIOThreadWrapper(virDomainPtr domain,
+ unsigned int iothread_id,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainAttachDeviceWrapper(virDomainPtr domain,
+ const char *xml,
+ virErrorPtr err);
+
+int
+virDomainAttachDeviceFlagsWrapper(virDomainPtr domain,
+ const char *xml,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainBlockCommitWrapper(virDomainPtr dom,
+ const char *disk,
+ const char *base,
+ const char *top,
+ unsigned long bandwidth,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainBlockCopyWrapper(virDomainPtr dom,
+ const char *disk,
+ const char *destxml,
+ virTypedParameterPtr params,
+ int nparams,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainBlockJobAbortWrapper(virDomainPtr dom,
+ const char *disk,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainBlockJobSetSpeedWrapper(virDomainPtr dom,
+ const char *disk,
+ unsigned long bandwidth,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainBlockPeekWrapper(virDomainPtr dom,
+ const char *disk,
+ unsigned long long offset,
+ size_t size,
+ void *buffer,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainBlockPullWrapper(virDomainPtr dom,
+ const char *disk,
+ unsigned long bandwidth,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainBlockRebaseWrapper(virDomainPtr dom,
+ const char *disk,
+ const char *base,
+ unsigned long bandwidth,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainBlockResizeWrapper(virDomainPtr dom,
+ const char *disk,
+ unsigned long long size,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainBlockStatsWrapper(virDomainPtr dom,
+ const char *disk,
+ virDomainBlockStatsPtr stats,
+ size_t size,
+ virErrorPtr err);
+
+int
+virDomainBlockStatsFlagsWrapper(virDomainPtr dom,
+ const char *disk,
+ virTypedParameterPtr params,
+ int *nparams,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainCoreDumpWrapper(virDomainPtr domain,
+ const char *to,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainCoreDumpWithFormatWrapper(virDomainPtr domain,
+ const char *to,
+ unsigned int dumpformat,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainCreateWrapper(virDomainPtr domain,
+ virErrorPtr err);
+
+int
+virDomainCreateWithFilesWrapper(virDomainPtr domain,
+ unsigned int nfiles,
+ int *files,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainCreateWithFlagsWrapper(virDomainPtr domain,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainDelIOThreadWrapper(virDomainPtr domain,
+ unsigned int iothread_id,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainDestroyWrapper(virDomainPtr domain,
+ virErrorPtr err);
+
+int
+virDomainDestroyFlagsWrapper(virDomainPtr domain,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainDetachDeviceWrapper(virDomainPtr domain,
+ const char *xml,
+ virErrorPtr err);
+
+int
+virDomainDetachDeviceAliasWrapper(virDomainPtr domain,
+ const char *alias,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainDetachDeviceFlagsWrapper(virDomainPtr domain,
+ const char *xml,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainFSFreezeWrapper(virDomainPtr dom,
+ const char **mountpoints,
+ unsigned int nmountpoints,
+ unsigned int flags,
+ virErrorPtr err);
+
+void
+virDomainFSInfoFreeWrapper(virDomainFSInfoPtr info);
+
+int
+virDomainFSThawWrapper(virDomainPtr dom,
+ const char **mountpoints,
+ unsigned int nmountpoints,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainFSTrimWrapper(virDomainPtr dom,
+ const char *mountPoint,
+ unsigned long long minimum,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainFreeWrapper(virDomainPtr domain,
+ virErrorPtr err);
+
+int
+virDomainGetAutostartWrapper(virDomainPtr domain,
+ int *autostart,
+ virErrorPtr err);
+
+int
+virDomainGetBlkioParametersWrapper(virDomainPtr domain,
+ virTypedParameterPtr params,
+ int *nparams,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainGetBlockInfoWrapper(virDomainPtr domain,
+ const char *disk,
+ virDomainBlockInfoPtr info,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainGetBlockIoTuneWrapper(virDomainPtr dom,
+ const char *disk,
+ virTypedParameterPtr params,
+ int *nparams,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainGetBlockJobInfoWrapper(virDomainPtr dom,
+ const char *disk,
+ virDomainBlockJobInfoPtr info,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainGetCPUStatsWrapper(virDomainPtr domain,
+ virTypedParameterPtr params,
+ unsigned int nparams,
+ int start_cpu,
+ unsigned int ncpus,
+ unsigned int flags,
+ virErrorPtr err);
+
+virConnectPtr
+virDomainGetConnectWrapper(virDomainPtr dom,
+ virErrorPtr err);
+
+int
+virDomainGetControlInfoWrapper(virDomainPtr domain,
+ virDomainControlInfoPtr info,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainGetDiskErrorsWrapper(virDomainPtr dom,
+ virDomainDiskErrorPtr errors,
+ unsigned int maxerrors,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainGetEmulatorPinInfoWrapper(virDomainPtr domain,
+ unsigned char *cpumap,
+ int maplen,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainGetFSInfoWrapper(virDomainPtr dom,
+ virDomainFSInfoPtr **info,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainGetGuestVcpusWrapper(virDomainPtr domain,
+ virTypedParameterPtr *params,
+ unsigned int *nparams,
+ unsigned int flags,
+ virErrorPtr err);
+
+char *
+virDomainGetHostnameWrapper(virDomainPtr domain,
+ unsigned int flags,
+ virErrorPtr err);
+
+unsigned int
+virDomainGetIDWrapper(virDomainPtr domain,
+ virErrorPtr err);
+
+int
+virDomainGetIOThreadInfoWrapper(virDomainPtr dom,
+ virDomainIOThreadInfoPtr **info,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainGetInfoWrapper(virDomainPtr domain,
+ virDomainInfoPtr info,
+ virErrorPtr err);
+
+int
+virDomainGetInterfaceParametersWrapper(virDomainPtr domain,
+ const char *device,
+ virTypedParameterPtr params,
+ int *nparams,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainGetJobInfoWrapper(virDomainPtr domain,
+ virDomainJobInfoPtr info,
+ virErrorPtr err);
+
+int
+virDomainGetJobStatsWrapper(virDomainPtr domain,
+ int *type,
+ virTypedParameterPtr *params,
+ int *nparams,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainGetLaunchSecurityInfoWrapper(virDomainPtr domain,
+ virTypedParameterPtr *params,
+ int *nparams,
+ unsigned int flags,
+ virErrorPtr err);
+
+unsigned long
+virDomainGetMaxMemoryWrapper(virDomainPtr domain,
+ virErrorPtr err);
+
+int
+virDomainGetMaxVcpusWrapper(virDomainPtr domain,
+ virErrorPtr err);
+
+int
+virDomainGetMemoryParametersWrapper(virDomainPtr domain,
+ virTypedParameterPtr params,
+ int *nparams,
+ unsigned int flags,
+ virErrorPtr err);
+
+char *
+virDomainGetMetadataWrapper(virDomainPtr domain,
+ int type,
+ const char *uri,
+ unsigned int flags,
+ virErrorPtr err);
+
+const char *
+virDomainGetNameWrapper(virDomainPtr domain,
+ virErrorPtr err);
+
+int
+virDomainGetNumaParametersWrapper(virDomainPtr domain,
+ virTypedParameterPtr params,
+ int *nparams,
+ unsigned int flags,
+ virErrorPtr err);
+
+char *
+virDomainGetOSTypeWrapper(virDomainPtr domain,
+ virErrorPtr err);
+
+int
+virDomainGetPerfEventsWrapper(virDomainPtr domain,
+ virTypedParameterPtr *params,
+ int *nparams,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainGetSchedulerParametersWrapper(virDomainPtr domain,
+ virTypedParameterPtr params,
+ int *nparams,
+ virErrorPtr err);
+
+int
+virDomainGetSchedulerParametersFlagsWrapper(virDomainPtr domain,
+ virTypedParameterPtr params,
+ int *nparams,
+ unsigned int flags,
+ virErrorPtr err);
+
+char *
+virDomainGetSchedulerTypeWrapper(virDomainPtr domain,
+ int *nparams,
+ virErrorPtr err);
+
+int
+virDomainGetSecurityLabelWrapper(virDomainPtr domain,
+ virSecurityLabelPtr seclabel,
+ virErrorPtr err);
+
+int
+virDomainGetSecurityLabelListWrapper(virDomainPtr domain,
+ virSecurityLabelPtr *seclabels,
+ virErrorPtr err);
+
+int
+virDomainGetStateWrapper(virDomainPtr domain,
+ int *state,
+ int *reason,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainGetTimeWrapper(virDomainPtr dom,
+ long long *seconds,
+ unsigned int *nseconds,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainGetUUIDWrapper(virDomainPtr domain,
+ unsigned char *uuid,
+ virErrorPtr err);
+
+int
+virDomainGetUUIDStringWrapper(virDomainPtr domain,
+ char *buf,
+ virErrorPtr err);
+
+int
+virDomainGetVcpuPinInfoWrapper(virDomainPtr domain,
+ int ncpumaps,
+ unsigned char *cpumaps,
+ int maplen,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainGetVcpusWrapper(virDomainPtr domain,
+ virVcpuInfoPtr info,
+ int maxinfo,
+ unsigned char *cpumaps,
+ int maplen,
+ virErrorPtr err);
+
+int
+virDomainGetVcpusFlagsWrapper(virDomainPtr domain,
+ unsigned int flags,
+ virErrorPtr err);
+
+char *
+virDomainGetXMLDescWrapper(virDomainPtr domain,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainHasCurrentSnapshotWrapper(virDomainPtr domain,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainHasManagedSaveImageWrapper(virDomainPtr dom,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainInjectNMIWrapper(virDomainPtr domain,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainInterfaceAddressesWrapper(virDomainPtr dom,
+ virDomainInterfacePtr **ifaces,
+ unsigned int source,
+ unsigned int flags,
+ virErrorPtr err);
+
+void
+virDomainInterfaceFreeWrapper(virDomainInterfacePtr iface);
+
+int
+virDomainInterfaceStatsWrapper(virDomainPtr dom,
+ const char *device,
+ virDomainInterfaceStatsPtr stats,
+ size_t size,
+ virErrorPtr err);
+
+void
+virDomainIOThreadInfoFreeWrapper(virDomainIOThreadInfoPtr info);
+
+int
+virDomainIsActiveWrapper(virDomainPtr dom,
+ virErrorPtr err);
+
+int
+virDomainIsPersistentWrapper(virDomainPtr dom,
+ virErrorPtr err);
+
+int
+virDomainIsUpdatedWrapper(virDomainPtr dom,
+ virErrorPtr err);
+
+int
+virDomainListAllSnapshotsWrapper(virDomainPtr domain,
+ virDomainSnapshotPtr **snaps,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainManagedSaveWrapper(virDomainPtr dom,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainManagedSaveDefineXMLWrapper(virDomainPtr domain,
+ const char *dxml,
+ unsigned int flags,
+ virErrorPtr err);
+
+char *
+virDomainManagedSaveGetXMLDescWrapper(virDomainPtr domain,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainManagedSaveRemoveWrapper(virDomainPtr dom,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainMemoryPeekWrapper(virDomainPtr dom,
+ unsigned long long start,
+ size_t size,
+ void *buffer,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainMemoryStatsWrapper(virDomainPtr dom,
+ virDomainMemoryStatPtr stats,
+ unsigned int nr_stats,
+ unsigned int flags,
+ virErrorPtr err);
+
+virDomainPtr
+virDomainMigrateWrapper(virDomainPtr domain,
+ virConnectPtr dconn,
+ unsigned long flags,
+ const char *dname,
+ const char *uri,
+ unsigned long bandwidth,
+ virErrorPtr err);
+
+virDomainPtr
+virDomainMigrate2Wrapper(virDomainPtr domain,
+ virConnectPtr dconn,
+ const char *dxml,
+ unsigned long flags,
+ const char *dname,
+ const char *uri,
+ unsigned long bandwidth,
+ virErrorPtr err);
+
+virDomainPtr
+virDomainMigrate3Wrapper(virDomainPtr domain,
+ virConnectPtr dconn,
+ virTypedParameterPtr params,
+ unsigned int nparams,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainMigrateGetCompressionCacheWrapper(virDomainPtr domain,
+ unsigned long long *cacheSize,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainMigrateGetMaxDowntimeWrapper(virDomainPtr domain,
+ unsigned long long *downtime,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainMigrateGetMaxSpeedWrapper(virDomainPtr domain,
+ unsigned long *bandwidth,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainMigrateSetCompressionCacheWrapper(virDomainPtr domain,
+ unsigned long long cacheSize,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainMigrateSetMaxDowntimeWrapper(virDomainPtr domain,
+ unsigned long long downtime,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainMigrateSetMaxSpeedWrapper(virDomainPtr domain,
+ unsigned long bandwidth,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainMigrateStartPostCopyWrapper(virDomainPtr domain,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainMigrateToURIWrapper(virDomainPtr domain,
+ const char *duri,
+ unsigned long flags,
+ const char *dname,
+ unsigned long bandwidth,
+ virErrorPtr err);
+
+int
+virDomainMigrateToURI2Wrapper(virDomainPtr domain,
+ const char *dconnuri,
+ const char *miguri,
+ const char *dxml,
+ unsigned long flags,
+ const char *dname,
+ unsigned long bandwidth,
+ virErrorPtr err);
+
+int
+virDomainMigrateToURI3Wrapper(virDomainPtr domain,
+ const char *dconnuri,
+ virTypedParameterPtr params,
+ unsigned int nparams,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainOpenChannelWrapper(virDomainPtr dom,
+ const char *name,
+ virStreamPtr st,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainOpenConsoleWrapper(virDomainPtr dom,
+ const char *dev_name,
+ virStreamPtr st,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainOpenGraphicsWrapper(virDomainPtr dom,
+ unsigned int idx,
+ int fd,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainOpenGraphicsFDWrapper(virDomainPtr dom,
+ unsigned int idx,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainPMSuspendForDurationWrapper(virDomainPtr dom,
+ unsigned int target,
+ unsigned long long duration,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainPMWakeupWrapper(virDomainPtr dom,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainPinEmulatorWrapper(virDomainPtr domain,
+ unsigned char *cpumap,
+ int maplen,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainPinIOThreadWrapper(virDomainPtr domain,
+ unsigned int iothread_id,
+ unsigned char *cpumap,
+ int maplen,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainPinVcpuWrapper(virDomainPtr domain,
+ unsigned int vcpu,
+ unsigned char *cpumap,
+ int maplen,
+ virErrorPtr err);
+
+int
+virDomainPinVcpuFlagsWrapper(virDomainPtr domain,
+ unsigned int vcpu,
+ unsigned char *cpumap,
+ int maplen,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainRebootWrapper(virDomainPtr domain,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainRefWrapper(virDomainPtr domain,
+ virErrorPtr err);
+
+int
+virDomainRenameWrapper(virDomainPtr dom,
+ const char *new_name,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainResetWrapper(virDomainPtr domain,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainResumeWrapper(virDomainPtr domain,
+ virErrorPtr err);
+
+int
+virDomainSaveWrapper(virDomainPtr domain,
+ const char *to,
+ virErrorPtr err);
+
+int
+virDomainSaveFlagsWrapper(virDomainPtr domain,
+ const char *to,
+ const char *dxml,
+ unsigned int flags,
+ virErrorPtr err);
+
+char *
+virDomainScreenshotWrapper(virDomainPtr domain,
+ virStreamPtr stream,
+ unsigned int screen,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainSendKeyWrapper(virDomainPtr domain,
+ unsigned int codeset,
+ unsigned int holdtime,
+ unsigned int *keycodes,
+ int nkeycodes,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainSendProcessSignalWrapper(virDomainPtr domain,
+ long long pid_value,
+ unsigned int signum,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainSetAutostartWrapper(virDomainPtr domain,
+ int autostart,
+ virErrorPtr err);
+
+int
+virDomainSetBlkioParametersWrapper(virDomainPtr domain,
+ virTypedParameterPtr params,
+ int nparams,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainSetBlockIoTuneWrapper(virDomainPtr dom,
+ const char *disk,
+ virTypedParameterPtr params,
+ int nparams,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainSetBlockThresholdWrapper(virDomainPtr domain,
+ const char *dev,
+ unsigned long long threshold,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainSetGuestVcpusWrapper(virDomainPtr domain,
+ const char *cpumap,
+ int state,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainSetInterfaceParametersWrapper(virDomainPtr domain,
+ const char *device,
+ virTypedParameterPtr params,
+ int nparams,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainSetLifecycleActionWrapper(virDomainPtr domain,
+ unsigned int type,
+ unsigned int action,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainSetMaxMemoryWrapper(virDomainPtr domain,
+ unsigned long memory,
+ virErrorPtr err);
+
+int
+virDomainSetMemoryWrapper(virDomainPtr domain,
+ unsigned long memory,
+ virErrorPtr err);
+
+int
+virDomainSetMemoryFlagsWrapper(virDomainPtr domain,
+ unsigned long memory,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainSetMemoryParametersWrapper(virDomainPtr domain,
+ virTypedParameterPtr params,
+ int nparams,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainSetMemoryStatsPeriodWrapper(virDomainPtr domain,
+ int period,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainSetMetadataWrapper(virDomainPtr domain,
+ int type,
+ const char *metadata,
+ const char *key,
+ const char *uri,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainSetNumaParametersWrapper(virDomainPtr domain,
+ virTypedParameterPtr params,
+ int nparams,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainSetPerfEventsWrapper(virDomainPtr domain,
+ virTypedParameterPtr params,
+ int nparams,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainSetSchedulerParametersWrapper(virDomainPtr domain,
+ virTypedParameterPtr params,
+ int nparams,
+ virErrorPtr err);
+
+int
+virDomainSetSchedulerParametersFlagsWrapper(virDomainPtr domain,
+ virTypedParameterPtr params,
+ int nparams,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainSetTimeWrapper(virDomainPtr dom,
+ long long seconds,
+ unsigned int nseconds,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainSetUserPasswordWrapper(virDomainPtr dom,
+ const char *user,
+ const char *password,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainSetVcpuWrapper(virDomainPtr domain,
+ const char *vcpumap,
+ int state,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainSetVcpusWrapper(virDomainPtr domain,
+ unsigned int nvcpus,
+ virErrorPtr err);
+
+int
+virDomainSetVcpusFlagsWrapper(virDomainPtr domain,
+ unsigned int nvcpus,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainShutdownWrapper(virDomainPtr domain,
+ virErrorPtr err);
+
+int
+virDomainShutdownFlagsWrapper(virDomainPtr domain,
+ unsigned int flags,
+ virErrorPtr err);
+
+virDomainSnapshotPtr
+virDomainSnapshotCreateXMLWrapper(virDomainPtr domain,
+ const char *xmlDesc,
+ unsigned int flags,
+ virErrorPtr err);
+
+virDomainSnapshotPtr
+virDomainSnapshotCurrentWrapper(virDomainPtr domain,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainSnapshotListNamesWrapper(virDomainPtr domain,
+ char **names,
+ int nameslen,
+ unsigned int flags,
+ virErrorPtr err);
+
+virDomainSnapshotPtr
+virDomainSnapshotLookupByNameWrapper(virDomainPtr domain,
+ const char *name,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainSnapshotNumWrapper(virDomainPtr domain,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainSuspendWrapper(virDomainPtr domain,
+ virErrorPtr err);
+
+int
+virDomainUndefineWrapper(virDomainPtr domain,
+ virErrorPtr err);
+
+int
+virDomainUndefineFlagsWrapper(virDomainPtr domain,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainUpdateDeviceFlagsWrapper(virDomainPtr domain,
+ const char *xml,
+ unsigned int flags,
+ virErrorPtr err);
+
+
+#endif /* LIBVIRT_GO_DOMAIN_WRAPPER_H__ */
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/error.go b/src/dma/vendor/github.com/libvirt/libvirt-go/error.go
new file mode 100644
index 00000000..1cfdf922
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/error.go
@@ -0,0 +1,604 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+package libvirt
+
+/*
+#cgo pkg-config: libvirt
+#include <libvirt/libvirt.h>
+#include <libvirt/virterror.h>
+#include "error_compat.h"
+
+void ignoreErrorFunc(void *userData, virErrorPtr error) {
+ // no-op
+}
+*/
+import "C"
+
+import (
+ "fmt"
+)
+
+func init() {
+ C.virSetErrorFunc(nil, (C.virErrorFunc)(C.ignoreErrorFunc))
+ C.virInitialize()
+}
+
+type ErrorLevel int
+
+const (
+ ERR_NONE = ErrorLevel(C.VIR_ERR_NONE)
+ ERR_WARNING = ErrorLevel(C.VIR_ERR_WARNING)
+ ERR_ERROR = ErrorLevel(C.VIR_ERR_ERROR)
+)
+
+type ErrorNumber int
+
+const (
+ ERR_OK = ErrorNumber(C.VIR_ERR_OK)
+
+ // internal error
+ ERR_INTERNAL_ERROR = ErrorNumber(C.VIR_ERR_INTERNAL_ERROR)
+
+ // memory allocation failure
+ ERR_NO_MEMORY = ErrorNumber(C.VIR_ERR_NO_MEMORY)
+
+ // no support for this function
+ ERR_NO_SUPPORT = ErrorNumber(C.VIR_ERR_NO_SUPPORT)
+
+ // could not resolve hostname
+ ERR_UNKNOWN_HOST = ErrorNumber(C.VIR_ERR_UNKNOWN_HOST)
+
+ // can't connect to hypervisor
+ ERR_NO_CONNECT = ErrorNumber(C.VIR_ERR_NO_CONNECT)
+
+ // invalid connection object
+ ERR_INVALID_CONN = ErrorNumber(C.VIR_ERR_INVALID_CONN)
+
+ // invalid domain object
+ ERR_INVALID_DOMAIN = ErrorNumber(C.VIR_ERR_INVALID_DOMAIN)
+
+ // invalid function argument
+ ERR_INVALID_ARG = ErrorNumber(C.VIR_ERR_INVALID_ARG)
+
+ // a command to hypervisor failed
+ ERR_OPERATION_FAILED = ErrorNumber(C.VIR_ERR_OPERATION_FAILED)
+
+ // a HTTP GET command to failed
+ ERR_GET_FAILED = ErrorNumber(C.VIR_ERR_GET_FAILED)
+
+ // a HTTP POST command to failed
+ ERR_POST_FAILED = ErrorNumber(C.VIR_ERR_POST_FAILED)
+
+ // unexpected HTTP error code
+ ERR_HTTP_ERROR = ErrorNumber(C.VIR_ERR_HTTP_ERROR)
+
+ // failure to serialize an S-Expr
+ ERR_SEXPR_SERIAL = ErrorNumber(C.VIR_ERR_SEXPR_SERIAL)
+
+ // could not open Xen hypervisor control
+ ERR_NO_XEN = ErrorNumber(C.VIR_ERR_NO_XEN)
+
+ // failure doing an hypervisor call
+ ERR_XEN_CALL = ErrorNumber(C.VIR_ERR_XEN_CALL)
+
+ // unknown OS type
+ ERR_OS_TYPE = ErrorNumber(C.VIR_ERR_OS_TYPE)
+
+ // missing kernel information
+ ERR_NO_KERNEL = ErrorNumber(C.VIR_ERR_NO_KERNEL)
+
+ // missing root device information
+ ERR_NO_ROOT = ErrorNumber(C.VIR_ERR_NO_ROOT)
+
+ // missing source device information
+ ERR_NO_SOURCE = ErrorNumber(C.VIR_ERR_NO_SOURCE)
+
+ // missing target device information
+ ERR_NO_TARGET = ErrorNumber(C.VIR_ERR_NO_TARGET)
+
+ // missing domain name information
+ ERR_NO_NAME = ErrorNumber(C.VIR_ERR_NO_NAME)
+
+ // missing domain OS information
+ ERR_NO_OS = ErrorNumber(C.VIR_ERR_NO_OS)
+
+ // missing domain devices information
+ ERR_NO_DEVICE = ErrorNumber(C.VIR_ERR_NO_DEVICE)
+
+ // could not open Xen Store control
+ ERR_NO_XENSTORE = ErrorNumber(C.VIR_ERR_NO_XENSTORE)
+
+ // too many drivers registered
+ ERR_DRIVER_FULL = ErrorNumber(C.VIR_ERR_DRIVER_FULL)
+
+ // not supported by the drivers (DEPRECATED)
+ ERR_CALL_FAILED = ErrorNumber(C.VIR_ERR_CALL_FAILED)
+
+ // an XML description is not well formed or broken
+ ERR_XML_ERROR = ErrorNumber(C.VIR_ERR_XML_ERROR)
+
+ // the domain already exist
+ ERR_DOM_EXIST = ErrorNumber(C.VIR_ERR_DOM_EXIST)
+
+ // operation forbidden on read-only connections
+ ERR_OPERATION_DENIED = ErrorNumber(C.VIR_ERR_OPERATION_DENIED)
+
+ // failed to open a conf file
+ ERR_OPEN_FAILED = ErrorNumber(C.VIR_ERR_OPEN_FAILED)
+
+ // failed to read a conf file
+ ERR_READ_FAILED = ErrorNumber(C.VIR_ERR_READ_FAILED)
+
+ // failed to parse a conf file
+ ERR_PARSE_FAILED = ErrorNumber(C.VIR_ERR_PARSE_FAILED)
+
+ // failed to parse the syntax of a conf file
+ ERR_CONF_SYNTAX = ErrorNumber(C.VIR_ERR_CONF_SYNTAX)
+
+ // failed to write a conf file
+ ERR_WRITE_FAILED = ErrorNumber(C.VIR_ERR_WRITE_FAILED)
+
+ // detail of an XML error
+ ERR_XML_DETAIL = ErrorNumber(C.VIR_ERR_XML_DETAIL)
+
+ // invalid network object
+ ERR_INVALID_NETWORK = ErrorNumber(C.VIR_ERR_INVALID_NETWORK)
+
+ // the network already exist
+ ERR_NETWORK_EXIST = ErrorNumber(C.VIR_ERR_NETWORK_EXIST)
+
+ // general system call failure
+ ERR_SYSTEM_ERROR = ErrorNumber(C.VIR_ERR_SYSTEM_ERROR)
+
+ // some sort of RPC error
+ ERR_RPC = ErrorNumber(C.VIR_ERR_RPC)
+
+ // error from a GNUTLS call
+ ERR_GNUTLS_ERROR = ErrorNumber(C.VIR_ERR_GNUTLS_ERROR)
+
+ // failed to start network
+ WAR_NO_NETWORK = ErrorNumber(C.VIR_WAR_NO_NETWORK)
+
+ // domain not found or unexpectedly disappeared
+ ERR_NO_DOMAIN = ErrorNumber(C.VIR_ERR_NO_DOMAIN)
+
+ // network not found
+ ERR_NO_NETWORK = ErrorNumber(C.VIR_ERR_NO_NETWORK)
+
+ // invalid MAC address
+ ERR_INVALID_MAC = ErrorNumber(C.VIR_ERR_INVALID_MAC)
+
+ // authentication failed
+ ERR_AUTH_FAILED = ErrorNumber(C.VIR_ERR_AUTH_FAILED)
+
+ // invalid storage pool object
+ ERR_INVALID_STORAGE_POOL = ErrorNumber(C.VIR_ERR_INVALID_STORAGE_POOL)
+
+ // invalid storage vol object
+ ERR_INVALID_STORAGE_VOL = ErrorNumber(C.VIR_ERR_INVALID_STORAGE_VOL)
+
+ // failed to start storage
+ WAR_NO_STORAGE = ErrorNumber(C.VIR_WAR_NO_STORAGE)
+
+ // storage pool not found
+ ERR_NO_STORAGE_POOL = ErrorNumber(C.VIR_ERR_NO_STORAGE_POOL)
+
+ // storage volume not found
+ ERR_NO_STORAGE_VOL = ErrorNumber(C.VIR_ERR_NO_STORAGE_VOL)
+
+ // failed to start node driver
+ WAR_NO_NODE = ErrorNumber(C.VIR_WAR_NO_NODE)
+
+ // invalid node device object
+ ERR_INVALID_NODE_DEVICE = ErrorNumber(C.VIR_ERR_INVALID_NODE_DEVICE)
+
+ // node device not found
+ ERR_NO_NODE_DEVICE = ErrorNumber(C.VIR_ERR_NO_NODE_DEVICE)
+
+ // security model not found
+ ERR_NO_SECURITY_MODEL = ErrorNumber(C.VIR_ERR_NO_SECURITY_MODEL)
+
+ // operation is not applicable at this time
+ ERR_OPERATION_INVALID = ErrorNumber(C.VIR_ERR_OPERATION_INVALID)
+
+ // failed to start interface driver
+ WAR_NO_INTERFACE = ErrorNumber(C.VIR_WAR_NO_INTERFACE)
+
+ // interface driver not running
+ ERR_NO_INTERFACE = ErrorNumber(C.VIR_ERR_NO_INTERFACE)
+
+ // invalid interface object
+ ERR_INVALID_INTERFACE = ErrorNumber(C.VIR_ERR_INVALID_INTERFACE)
+
+ // more than one matching interface found
+ ERR_MULTIPLE_INTERFACES = ErrorNumber(C.VIR_ERR_MULTIPLE_INTERFACES)
+
+ // failed to start nwfilter driver
+ WAR_NO_NWFILTER = ErrorNumber(C.VIR_WAR_NO_NWFILTER)
+
+ // invalid nwfilter object
+ ERR_INVALID_NWFILTER = ErrorNumber(C.VIR_ERR_INVALID_NWFILTER)
+
+ // nw filter pool not found
+ ERR_NO_NWFILTER = ErrorNumber(C.VIR_ERR_NO_NWFILTER)
+
+ // nw filter pool not found
+ ERR_BUILD_FIREWALL = ErrorNumber(C.VIR_ERR_BUILD_FIREWALL)
+
+ // failed to start secret storage
+ WAR_NO_SECRET = ErrorNumber(C.VIR_WAR_NO_SECRET)
+
+ // invalid secret
+ ERR_INVALID_SECRET = ErrorNumber(C.VIR_ERR_INVALID_SECRET)
+
+ // secret not found
+ ERR_NO_SECRET = ErrorNumber(C.VIR_ERR_NO_SECRET)
+
+ // unsupported configuration construct
+ ERR_CONFIG_UNSUPPORTED = ErrorNumber(C.VIR_ERR_CONFIG_UNSUPPORTED)
+
+ // timeout occurred during operation
+ ERR_OPERATION_TIMEOUT = ErrorNumber(C.VIR_ERR_OPERATION_TIMEOUT)
+
+ // a migration worked, but making the VM persist on the dest host failed
+ ERR_MIGRATE_PERSIST_FAILED = ErrorNumber(C.VIR_ERR_MIGRATE_PERSIST_FAILED)
+
+ // a synchronous hook script failed
+ ERR_HOOK_SCRIPT_FAILED = ErrorNumber(C.VIR_ERR_HOOK_SCRIPT_FAILED)
+
+ // invalid domain snapshot
+ ERR_INVALID_DOMAIN_SNAPSHOT = ErrorNumber(C.VIR_ERR_INVALID_DOMAIN_SNAPSHOT)
+
+ // domain snapshot not found
+ ERR_NO_DOMAIN_SNAPSHOT = ErrorNumber(C.VIR_ERR_NO_DOMAIN_SNAPSHOT)
+
+ // stream pointer not valid
+ ERR_INVALID_STREAM = ErrorNumber(C.VIR_ERR_INVALID_STREAM)
+
+ // valid API use but unsupported by the given driver
+ ERR_ARGUMENT_UNSUPPORTED = ErrorNumber(C.VIR_ERR_ARGUMENT_UNSUPPORTED)
+
+ // storage pool probe failed
+ ERR_STORAGE_PROBE_FAILED = ErrorNumber(C.VIR_ERR_STORAGE_PROBE_FAILED)
+
+ // storage pool already built
+ ERR_STORAGE_POOL_BUILT = ErrorNumber(C.VIR_ERR_STORAGE_POOL_BUILT)
+
+ // force was not requested for a risky domain snapshot revert
+ ERR_SNAPSHOT_REVERT_RISKY = ErrorNumber(C.VIR_ERR_SNAPSHOT_REVERT_RISKY)
+
+ // operation on a domain was canceled/aborted by user
+ ERR_OPERATION_ABORTED = ErrorNumber(C.VIR_ERR_OPERATION_ABORTED)
+
+ // authentication cancelled
+ ERR_AUTH_CANCELLED = ErrorNumber(C.VIR_ERR_AUTH_CANCELLED)
+
+ // The metadata is not present
+ ERR_NO_DOMAIN_METADATA = ErrorNumber(C.VIR_ERR_NO_DOMAIN_METADATA)
+
+ // Migration is not safe
+ ERR_MIGRATE_UNSAFE = ErrorNumber(C.VIR_ERR_MIGRATE_UNSAFE)
+
+ // integer overflow
+ ERR_OVERFLOW = ErrorNumber(C.VIR_ERR_OVERFLOW)
+
+ // action prevented by block copy job
+ ERR_BLOCK_COPY_ACTIVE = ErrorNumber(C.VIR_ERR_BLOCK_COPY_ACTIVE)
+
+ // The requested operation is not supported
+ ERR_OPERATION_UNSUPPORTED = ErrorNumber(C.VIR_ERR_OPERATION_UNSUPPORTED)
+
+ // error in ssh transport driver
+ ERR_SSH = ErrorNumber(C.VIR_ERR_SSH)
+
+ // guest agent is unresponsive, not running or not usable
+ ERR_AGENT_UNRESPONSIVE = ErrorNumber(C.VIR_ERR_AGENT_UNRESPONSIVE)
+
+ // resource is already in use
+ ERR_RESOURCE_BUSY = ErrorNumber(C.VIR_ERR_RESOURCE_BUSY)
+
+ // operation on the object/resource was denied
+ ERR_ACCESS_DENIED = ErrorNumber(C.VIR_ERR_ACCESS_DENIED)
+
+ // error from a dbus service
+ ERR_DBUS_SERVICE = ErrorNumber(C.VIR_ERR_DBUS_SERVICE)
+
+ // the storage vol already exists
+ ERR_STORAGE_VOL_EXIST = ErrorNumber(C.VIR_ERR_STORAGE_VOL_EXIST)
+
+ // given CPU is incompatible with host CPU
+ ERR_CPU_INCOMPATIBLE = ErrorNumber(C.VIR_ERR_CPU_INCOMPATIBLE)
+
+ // XML document doesn't validate against schema
+ ERR_XML_INVALID_SCHEMA = ErrorNumber(C.VIR_ERR_XML_INVALID_SCHEMA)
+
+ // Finish API succeeded but it is expected to return NULL */
+ ERR_MIGRATE_FINISH_OK = ErrorNumber(C.VIR_ERR_MIGRATE_FINISH_OK)
+
+ // authentication unavailable
+ ERR_AUTH_UNAVAILABLE = ErrorNumber(C.VIR_ERR_AUTH_UNAVAILABLE)
+
+ // Server was not found
+ ERR_NO_SERVER = ErrorNumber(C.VIR_ERR_NO_SERVER)
+
+ // Client was not found
+ ERR_NO_CLIENT = ErrorNumber(C.VIR_ERR_NO_CLIENT)
+
+ // guest agent replies with wrong id to guest sync command
+ ERR_AGENT_UNSYNCED = ErrorNumber(C.VIR_ERR_AGENT_UNSYNCED)
+
+ // error in libssh transport driver
+ ERR_LIBSSH = ErrorNumber(C.VIR_ERR_LIBSSH)
+
+ // libvirt fail to find the desired device
+ ERR_DEVICE_MISSING = ErrorNumber(C.VIR_ERR_DEVICE_MISSING)
+
+ // Invalid nwfilter binding object
+ ERR_INVALID_NWFILTER_BINDING = ErrorNumber(C.VIR_ERR_INVALID_NWFILTER_BINDING)
+
+ // Requested nwfilter binding does not exist
+ ERR_NO_NWFILTER_BINDING = ErrorNumber(C.VIR_ERR_NO_NWFILTER_BINDING)
+)
+
+type ErrorDomain int
+
+const (
+ FROM_NONE = ErrorDomain(C.VIR_FROM_NONE)
+
+ // Error at Xen hypervisor layer
+ FROM_XEN = ErrorDomain(C.VIR_FROM_XEN)
+
+ // Error at connection with xend daemon
+ FROM_XEND = ErrorDomain(C.VIR_FROM_XEND)
+
+ // Error at connection with xen store
+ FROM_XENSTORE = ErrorDomain(C.VIR_FROM_XENSTORE)
+
+ // Error in the S-Expression code
+ FROM_SEXPR = ErrorDomain(C.VIR_FROM_SEXPR)
+
+ // Error in the XML code
+ FROM_XML = ErrorDomain(C.VIR_FROM_XML)
+
+ // Error when operating on a domain
+ FROM_DOM = ErrorDomain(C.VIR_FROM_DOM)
+
+ // Error in the XML-RPC code
+ FROM_RPC = ErrorDomain(C.VIR_FROM_RPC)
+
+ // Error in the proxy code; unused since 0.8.6
+ FROM_PROXY = ErrorDomain(C.VIR_FROM_PROXY)
+
+ // Error in the configuration file handling
+ FROM_CONF = ErrorDomain(C.VIR_FROM_CONF)
+
+ // Error at the QEMU daemon
+ FROM_QEMU = ErrorDomain(C.VIR_FROM_QEMU)
+
+ // Error when operating on a network
+ FROM_NET = ErrorDomain(C.VIR_FROM_NET)
+
+ // Error from test driver
+ FROM_TEST = ErrorDomain(C.VIR_FROM_TEST)
+
+ // Error from remote driver
+ FROM_REMOTE = ErrorDomain(C.VIR_FROM_REMOTE)
+
+ // Error from OpenVZ driver
+ FROM_OPENVZ = ErrorDomain(C.VIR_FROM_OPENVZ)
+
+ // Error at Xen XM layer
+ FROM_XENXM = ErrorDomain(C.VIR_FROM_XENXM)
+
+ // Error in the Linux Stats code
+ FROM_STATS_LINUX = ErrorDomain(C.VIR_FROM_STATS_LINUX)
+
+ // Error from Linux Container driver
+ FROM_LXC = ErrorDomain(C.VIR_FROM_LXC)
+
+ // Error from storage driver
+ FROM_STORAGE = ErrorDomain(C.VIR_FROM_STORAGE)
+
+ // Error from network config
+ FROM_NETWORK = ErrorDomain(C.VIR_FROM_NETWORK)
+
+ // Error from domain config
+ FROM_DOMAIN = ErrorDomain(C.VIR_FROM_DOMAIN)
+
+ // Error at the UML driver
+ FROM_UML = ErrorDomain(C.VIR_FROM_UML)
+
+ // Error from node device monitor
+ FROM_NODEDEV = ErrorDomain(C.VIR_FROM_NODEDEV)
+
+ // Error from xen inotify layer
+ FROM_XEN_INOTIFY = ErrorDomain(C.VIR_FROM_XEN_INOTIFY)
+
+ // Error from security framework
+ FROM_SECURITY = ErrorDomain(C.VIR_FROM_SECURITY)
+
+ // Error from VirtualBox driver
+ FROM_VBOX = ErrorDomain(C.VIR_FROM_VBOX)
+
+ // Error when operating on an interface
+ FROM_INTERFACE = ErrorDomain(C.VIR_FROM_INTERFACE)
+
+ // The OpenNebula driver no longer exists. Retained for ABI/API compat only
+ FROM_ONE = ErrorDomain(C.VIR_FROM_ONE)
+
+ // Error from ESX driver
+ FROM_ESX = ErrorDomain(C.VIR_FROM_ESX)
+
+ // Error from IBM power hypervisor
+ FROM_PHYP = ErrorDomain(C.VIR_FROM_PHYP)
+
+ // Error from secret storage
+ FROM_SECRET = ErrorDomain(C.VIR_FROM_SECRET)
+
+ // Error from CPU driver
+ FROM_CPU = ErrorDomain(C.VIR_FROM_CPU)
+
+ // Error from XenAPI
+ FROM_XENAPI = ErrorDomain(C.VIR_FROM_XENAPI)
+
+ // Error from network filter driver
+ FROM_NWFILTER = ErrorDomain(C.VIR_FROM_NWFILTER)
+
+ // Error from Synchronous hooks
+ FROM_HOOK = ErrorDomain(C.VIR_FROM_HOOK)
+
+ // Error from domain snapshot
+ FROM_DOMAIN_SNAPSHOT = ErrorDomain(C.VIR_FROM_DOMAIN_SNAPSHOT)
+
+ // Error from auditing subsystem
+ FROM_AUDIT = ErrorDomain(C.VIR_FROM_AUDIT)
+
+ // Error from sysinfo/SMBIOS
+ FROM_SYSINFO = ErrorDomain(C.VIR_FROM_SYSINFO)
+
+ // Error from I/O streams
+ FROM_STREAMS = ErrorDomain(C.VIR_FROM_STREAMS)
+
+ // Error from VMware driver
+ FROM_VMWARE = ErrorDomain(C.VIR_FROM_VMWARE)
+
+ // Error from event loop impl
+ FROM_EVENT = ErrorDomain(C.VIR_FROM_EVENT)
+
+ // Error from libxenlight driver
+ FROM_LIBXL = ErrorDomain(C.VIR_FROM_LIBXL)
+
+ // Error from lock manager
+ FROM_LOCKING = ErrorDomain(C.VIR_FROM_LOCKING)
+
+ // Error from Hyper-V driver
+ FROM_HYPERV = ErrorDomain(C.VIR_FROM_HYPERV)
+
+ // Error from capabilities
+ FROM_CAPABILITIES = ErrorDomain(C.VIR_FROM_CAPABILITIES)
+
+ // Error from URI handling
+ FROM_URI = ErrorDomain(C.VIR_FROM_URI)
+
+ // Error from auth handling
+ FROM_AUTH = ErrorDomain(C.VIR_FROM_AUTH)
+
+ // Error from DBus
+ FROM_DBUS = ErrorDomain(C.VIR_FROM_DBUS)
+
+ // Error from Parallels
+ FROM_PARALLELS = ErrorDomain(C.VIR_FROM_PARALLELS)
+
+ // Error from Device
+ FROM_DEVICE = ErrorDomain(C.VIR_FROM_DEVICE)
+
+ // Error from libssh2 connection transport
+ FROM_SSH = ErrorDomain(C.VIR_FROM_SSH)
+
+ // Error from lockspace
+ FROM_LOCKSPACE = ErrorDomain(C.VIR_FROM_LOCKSPACE)
+
+ // Error from initctl device communication
+ FROM_INITCTL = ErrorDomain(C.VIR_FROM_INITCTL)
+
+ // Error from identity code
+ FROM_IDENTITY = ErrorDomain(C.VIR_FROM_IDENTITY)
+
+ // Error from cgroups
+ FROM_CGROUP = ErrorDomain(C.VIR_FROM_CGROUP)
+
+ // Error from access control manager
+ FROM_ACCESS = ErrorDomain(C.VIR_FROM_ACCESS)
+
+ // Error from systemd code
+ FROM_SYSTEMD = ErrorDomain(C.VIR_FROM_SYSTEMD)
+
+ // Error from bhyve driver
+ FROM_BHYVE = ErrorDomain(C.VIR_FROM_BHYVE)
+
+ // Error from crypto code
+ FROM_CRYPTO = ErrorDomain(C.VIR_FROM_CRYPTO)
+
+ // Error from firewall
+ FROM_FIREWALL = ErrorDomain(C.VIR_FROM_FIREWALL)
+
+ // Erorr from polkit code
+ FROM_POLKIT = ErrorDomain(C.VIR_FROM_POLKIT)
+
+ // Error from thread utils
+ FROM_THREAD = ErrorDomain(C.VIR_FROM_THREAD)
+
+ // Error from admin backend
+ FROM_ADMIN = ErrorDomain(C.VIR_FROM_ADMIN)
+
+ // Error from log manager
+ FROM_LOGGING = ErrorDomain(C.VIR_FROM_LOGGING)
+
+ // Error from Xen xl config code
+ FROM_XENXL = ErrorDomain(C.VIR_FROM_XENXL)
+
+ // Error from perf
+ FROM_PERF = ErrorDomain(C.VIR_FROM_PERF)
+
+ // Error from libssh
+ FROM_LIBSSH = ErrorDomain(C.VIR_FROM_LIBSSH)
+
+ // Error from resoruce control
+ FROM_RESCTRL = ErrorDomain(C.VIR_FROM_RESCTRL)
+)
+
+type Error struct {
+ Code ErrorNumber
+ Domain ErrorDomain
+ Message string
+ Level ErrorLevel
+}
+
+func (err Error) Error() string {
+ return fmt.Sprintf("virError(Code=%d, Domain=%d, Message='%s')",
+ err.Code, err.Domain, err.Message)
+}
+
+func makeError(err *C.virError) Error {
+ ret := Error{
+ Code: ErrorNumber(err.code),
+ Domain: ErrorDomain(err.domain),
+ Message: C.GoString(err.message),
+ Level: ErrorLevel(err.level),
+ }
+ C.virResetError(err)
+ return ret
+}
+
+func makeNotImplementedError(apiname string) Error {
+ return Error{
+ Code: ERR_NO_SUPPORT,
+ Domain: FROM_NONE,
+ Message: fmt.Sprintf("Function '%s' not available in the libvirt library used during Go build", apiname),
+ Level: ERR_ERROR,
+ }
+}
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/error_compat.h b/src/dma/vendor/github.com/libvirt/libvirt-go/error_compat.h
new file mode 100644
index 00000000..0e416803
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/error_compat.h
@@ -0,0 +1,166 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+#ifndef LIBVIRT_GO_ERROR_COMPAT_H__
+#define LIBVIRT_GO_ERROR_COMPAT_H__
+
+/* 1.2.2 */
+
+#ifndef VIR_FROM_BHYVE
+#define VIR_FROM_BHYVE 57
+#endif
+
+
+/* 1.2.3 */
+
+#ifndef VIR_FROM_CRYPTO
+#define VIR_FROM_CRYPTO 58
+#endif
+
+
+/* 1.2.4 */
+
+#ifndef VIR_FROM_FIREWALL
+#define VIR_FROM_FIREWALL 59
+#endif
+
+
+/* 1.2.6 */
+
+#ifndef VIR_ERR_CPU_INCOMPATIBLE
+#define VIR_ERR_CPU_INCOMPATIBLE 91
+#endif
+
+
+/* 1.2.9 */
+
+#ifndef VIR_FROM_POLKIT
+#define VIR_FROM_POLKIT 60
+#endif
+
+
+/* 1.2.12 */
+
+#ifndef VIR_ERR_XML_INVALID_SCHEMA
+#define VIR_ERR_XML_INVALID_SCHEMA 92
+#endif
+
+
+/* 1.2.14 */
+
+#ifndef VIR_FROM_THREAD
+#define VIR_FROM_THREAD 61
+#endif
+
+
+/* 1.2.17 */
+
+#ifndef VIR_FROM_ADMIN
+#define VIR_FROM_ADMIN 62
+#endif
+
+
+/* 1.2.18 */
+
+#ifndef VIR_ERR_MIGRATE_FINISH_OK
+#define VIR_ERR_MIGRATE_FINISH_OK 93
+#endif
+
+
+/* 1.3.0 */
+
+#ifndef VIR_FROM_LOGGING
+#define VIR_FROM_LOGGING 63
+#endif
+
+/* 1.3.2 */
+
+#ifndef VIR_FROM_XENXL
+#define VIR_FROM_XENXL 64
+#endif
+
+
+/* 1.3.3 */
+
+#ifndef VIR_FROM_PERF
+#define VIR_FROM_PERF 65
+#endif
+
+#ifndef VIR_ERR_AUTH_UNAVAILABLE
+#define VIR_ERR_AUTH_UNAVAILABLE 94
+#endif
+
+#ifndef VIR_ERR_NO_SERVER
+#define VIR_ERR_NO_SERVER 95
+#endif
+
+
+/* 1.3.5 */
+
+#ifndef VIR_ERR_NO_CLIENT
+#define VIR_ERR_NO_CLIENT 96
+#endif
+
+
+/* 2.3.0 */
+
+#ifndef VIR_ERR_AGENT_UNSYNCED
+#define VIR_ERR_AGENT_UNSYNCED 97
+#endif
+
+/* 2.5.0 */
+
+#ifndef VIR_ERR_LIBSSH
+#define VIR_ERR_LIBSSH 98
+#endif
+
+#ifndef VIR_FROM_LIBSSH
+#define VIR_FROM_LIBSSH 66
+#endif
+
+/* 3.7.0 */
+
+#ifndef VIR_FROM_RESCTRL
+#define VIR_FROM_RESCTRL 67
+#endif
+
+/* 4.1.0 */
+
+#ifndef VIR_ERR_DEVICE_MISSING
+#define VIR_ERR_DEVICE_MISSING 99
+#endif
+
+/* 4.5.0 */
+
+#ifndef VIR_ERR_INVALID_NWFILTER_BINDING
+#define VIR_ERR_INVALID_NWFILTER_BINDING 100
+#endif
+
+#ifndef VIR_ERR_NO_NWFILTER_BINDING
+#define VIR_ERR_NO_NWFILTER_BINDING 101
+#endif
+
+#endif /* LIBVIRT_GO_ERROR_COMPAT_H__ */
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/events.go b/src/dma/vendor/github.com/libvirt/libvirt-go/events.go
new file mode 100644
index 00000000..bf2c1f4e
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/events.go
@@ -0,0 +1,258 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+package libvirt
+
+/*
+#cgo pkg-config: libvirt
+#include <stdint.h>
+#include "events_wrapper.h"
+*/
+import "C"
+
+type EventHandleType int
+
+const (
+ EVENT_HANDLE_READABLE = EventHandleType(C.VIR_EVENT_HANDLE_READABLE)
+ EVENT_HANDLE_WRITABLE = EventHandleType(C.VIR_EVENT_HANDLE_WRITABLE)
+ EVENT_HANDLE_ERROR = EventHandleType(C.VIR_EVENT_HANDLE_ERROR)
+ EVENT_HANDLE_HANGUP = EventHandleType(C.VIR_EVENT_HANDLE_HANGUP)
+)
+
+// See also https://libvirt.org/html/libvirt-libvirt-event.html#virEventRegisterDefaultImpl
+func EventRegisterDefaultImpl() error {
+ var err C.virError
+ if i := int(C.virEventRegisterDefaultImplWrapper(&err)); i != 0 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-event.html#virEventRunDefaultImpl
+func EventRunDefaultImpl() error {
+ var err C.virError
+ if i := int(C.virEventRunDefaultImplWrapper(&err)); i != 0 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+type EventHandleCallback func(watch int, file int, events EventHandleType)
+
+//export eventHandleCallback
+func eventHandleCallback(watch int, fd int, events int, callbackID int) {
+ callbackFunc := getCallbackId(callbackID)
+
+ callback, ok := callbackFunc.(EventHandleCallback)
+ if !ok {
+ panic("Incorrect event handle callback data")
+ }
+
+ callback(watch, fd, (EventHandleType)(events))
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-event.html#virEventAddHandle
+func EventAddHandle(fd int, events EventHandleType, callback EventHandleCallback) (int, error) {
+ callbackID := registerCallbackId(callback)
+
+ var err C.virError
+ ret := C.virEventAddHandleWrapper((C.int)(fd), (C.int)(events), (C.int)(callbackID), &err)
+ if ret == -1 {
+ return 0, makeError(&err)
+ }
+
+ return int(ret), nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-event.html#virEventUpdateHandle
+func EventUpdateHandle(watch int, events EventHandleType) {
+ C.virEventUpdateHandle((C.int)(watch), (C.int)(events))
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-event.html#virEventRemoveHandle
+func EventRemoveHandle(watch int) error {
+ var err C.virError
+ ret := C.virEventRemoveHandleWrapper((C.int)(watch), &err)
+ if ret < 0 {
+ return makeError(&err)
+ }
+
+ return nil
+}
+
+type EventTimeoutCallback func(timer int)
+
+//export eventTimeoutCallback
+func eventTimeoutCallback(timer int, callbackID int) {
+ callbackFunc := getCallbackId(callbackID)
+
+ callback, ok := callbackFunc.(EventTimeoutCallback)
+ if !ok {
+ panic("Incorrect event timeout callback data")
+ }
+
+ callback(timer)
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-event.html#virEventAddTimeout
+func EventAddTimeout(freq int, callback EventTimeoutCallback) (int, error) {
+ callbackID := registerCallbackId(callback)
+
+ var err C.virError
+ ret := C.virEventAddTimeoutWrapper((C.int)(freq), (C.int)(callbackID), &err)
+ if ret == -1 {
+ return 0, makeError(&err)
+ }
+
+ return int(ret), nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-event.html#virEventUpdateTimeout
+func EventUpdateTimeout(timer int, freq int) {
+ C.virEventUpdateTimeout((C.int)(timer), (C.int)(freq))
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-event.html#virEventRemoveTimeout
+func EventRemoveTimeout(timer int) error {
+ var err C.virError
+ ret := C.virEventRemoveTimeoutWrapper((C.int)(timer), &err)
+ if ret < 0 {
+ return makeError(&err)
+ }
+
+ return nil
+}
+
+type EventHandleCallbackInfo struct {
+ callback uintptr
+ opaque uintptr
+ free uintptr
+}
+
+type EventTimeoutCallbackInfo struct {
+ callback uintptr
+ opaque uintptr
+ free uintptr
+}
+
+func (i *EventHandleCallbackInfo) Invoke(watch int, fd int, event EventHandleType) {
+ C.eventHandleCallbackInvoke(C.int(watch), C.int(fd), C.int(event), C.uintptr_t(i.callback), C.uintptr_t(i.opaque))
+}
+
+func (i *EventTimeoutCallbackInfo) Invoke(timer int) {
+ C.eventTimeoutCallbackInvoke(C.int(timer), C.uintptr_t(i.callback), C.uintptr_t(i.opaque))
+}
+
+func (i *EventHandleCallbackInfo) Free() {
+ C.eventHandleCallbackFree(C.uintptr_t(i.free), C.uintptr_t(i.opaque))
+}
+
+func (i *EventTimeoutCallbackInfo) Free() {
+ C.eventTimeoutCallbackFree(C.uintptr_t(i.free), C.uintptr_t(i.opaque))
+}
+
+type EventLoop interface {
+ AddHandleFunc(fd int, event EventHandleType, callback *EventHandleCallbackInfo) int
+ UpdateHandleFunc(watch int, event EventHandleType)
+ RemoveHandleFunc(watch int) int
+ AddTimeoutFunc(freq int, callback *EventTimeoutCallbackInfo) int
+ UpdateTimeoutFunc(timer int, freq int)
+ RemoveTimeoutFunc(timer int) int
+}
+
+var eventLoopImpl EventLoop
+
+// See also https://libvirt.org/html/libvirt-libvirt-event.html#virEventRegisterImpl
+func EventRegisterImpl(impl EventLoop) {
+ eventLoopImpl = impl
+ C.virEventRegisterImplWrapper()
+}
+
+//export eventAddHandleFunc
+func eventAddHandleFunc(fd C.int, event C.int, callback uintptr, opaque uintptr, free uintptr) C.int {
+ if eventLoopImpl == nil {
+ panic("Event loop impl is missing")
+ }
+
+ cbinfo := &EventHandleCallbackInfo{
+ callback: callback,
+ opaque: opaque,
+ free: free,
+ }
+
+ return C.int(eventLoopImpl.AddHandleFunc(int(fd), EventHandleType(event), cbinfo))
+}
+
+//export eventUpdateHandleFunc
+func eventUpdateHandleFunc(watch C.int, event C.int) {
+ if eventLoopImpl == nil {
+ panic("Event loop impl is missing")
+ }
+
+ eventLoopImpl.UpdateHandleFunc(int(watch), EventHandleType(event))
+}
+
+//export eventRemoveHandleFunc
+func eventRemoveHandleFunc(watch C.int) {
+ if eventLoopImpl == nil {
+ panic("Event loop impl is missing")
+ }
+
+ eventLoopImpl.RemoveHandleFunc(int(watch))
+}
+
+//export eventAddTimeoutFunc
+func eventAddTimeoutFunc(freq C.int, callback uintptr, opaque uintptr, free uintptr) C.int {
+ if eventLoopImpl == nil {
+ panic("Event loop impl is missing")
+ }
+
+ cbinfo := &EventTimeoutCallbackInfo{
+ callback: callback,
+ opaque: opaque,
+ free: free,
+ }
+
+ return C.int(eventLoopImpl.AddTimeoutFunc(int(freq), cbinfo))
+}
+
+//export eventUpdateTimeoutFunc
+func eventUpdateTimeoutFunc(timer C.int, freq C.int) {
+ if eventLoopImpl == nil {
+ panic("Event loop impl is missing")
+ }
+
+ eventLoopImpl.UpdateTimeoutFunc(int(timer), int(freq))
+}
+
+//export eventRemoveTimeoutFunc
+func eventRemoveTimeoutFunc(timer C.int) {
+ if eventLoopImpl == nil {
+ panic("Event loop impl is missing")
+ }
+
+ eventLoopImpl.RemoveTimeoutFunc(int(timer))
+}
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/events_wrapper.go b/src/dma/vendor/github.com/libvirt/libvirt-go/events_wrapper.go
new file mode 100644
index 00000000..68145893
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/events_wrapper.go
@@ -0,0 +1,193 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+package libvirt
+
+/*
+#cgo pkg-config: libvirt
+#include <stdint.h>
+#include <stdlib.h>
+#include "events_wrapper.h"
+
+void eventHandleCallback(int watch, int fd, int events, int callbackID);
+
+static void eventAddHandleHelper(int watch, int fd, int events, void *opaque)
+{
+ eventHandleCallback(watch, fd, events, (int)(intptr_t)opaque);
+}
+
+void eventTimeoutCallback(int timer, int callbackID);
+
+static void eventAddTimeoutHelper(int timer, void *opaque)
+{
+ eventTimeoutCallback(timer, (int)(intptr_t)opaque);
+}
+
+int eventAddHandleFunc(int fd, int event, uintptr_t callback, uintptr_t opaque, uintptr_t freecb);
+void eventUpdateHandleFunc(int watch, int event);
+int eventRemoveHandleFunc(int watch);
+int eventAddTimeoutFunc(int freq, uintptr_t callback, uintptr_t opaque, uintptr_t freecb);
+void eventUpdateTimeoutFunc(int timer, int freq);
+int eventRemoveTimeoutFunc(int timer);
+
+int eventAddHandleFuncHelper(int fd, int event, virEventHandleCallback callback, void *opaque, virFreeCallback freecb)
+{
+ return eventAddHandleFunc(fd, event, (uintptr_t)callback, (uintptr_t)opaque, (uintptr_t)freecb);
+}
+
+void eventUpdateHandleFuncHelper(int watch, int event)
+{
+ eventUpdateHandleFunc(watch, event);
+}
+
+int eventRemoveHandleFuncHelper(int watch)
+{
+ return eventRemoveHandleFunc(watch);
+}
+
+int eventAddTimeoutFuncHelper(int freq, virEventTimeoutCallback callback, void *opaque, virFreeCallback freecb)
+{
+ return eventAddTimeoutFunc(freq, (uintptr_t)callback, (uintptr_t)opaque, (uintptr_t)freecb);
+}
+
+void eventUpdateTimeoutFuncHelper(int timer, int freq)
+{
+ eventUpdateTimeoutFunc(timer, freq);
+}
+
+int eventRemoveTimeoutFuncHelper(int timer)
+{
+ return eventRemoveTimeoutFunc(timer);
+}
+
+
+void virEventRegisterImplWrapper(void)
+{
+ virEventRegisterImpl(eventAddHandleFuncHelper,
+ eventUpdateHandleFuncHelper,
+ eventRemoveHandleFuncHelper,
+ eventAddTimeoutFuncHelper,
+ eventUpdateTimeoutFuncHelper,
+ eventRemoveTimeoutFuncHelper);
+}
+
+void eventHandleCallbackInvoke(int watch, int fd, int events, uintptr_t callback, uintptr_t opaque)
+{
+ ((virEventHandleCallback)callback)(watch, fd, events, (void *)opaque);
+}
+
+void eventTimeoutCallbackInvoke(int timer, uintptr_t callback, uintptr_t opaque)
+{
+ ((virEventTimeoutCallback)callback)(timer, (void *)opaque);
+}
+
+
+void eventHandleCallbackFree(uintptr_t callback, uintptr_t opaque)
+{
+ ((virFreeCallback)callback)((void *)opaque);
+}
+
+void eventTimeoutCallbackFree(uintptr_t callback, uintptr_t opaque)
+{
+ ((virFreeCallback)callback)((void *)opaque);
+}
+
+
+int
+virEventAddHandleWrapper(int fd,
+ int events,
+ int callbackID,
+ virErrorPtr err)
+{
+ int ret = virEventAddHandle(fd, events, eventAddHandleHelper, (void *)(intptr_t)callbackID, NULL);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virEventAddTimeoutWrapper(int timeout,
+ int callbackID,
+ virErrorPtr err)
+{
+ int ret = virEventAddTimeout(timeout, eventAddTimeoutHelper, (void *)(intptr_t)callbackID, NULL);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virEventRegisterDefaultImplWrapper(virErrorPtr err)
+{
+ int ret = virEventRegisterDefaultImpl();
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virEventRemoveHandleWrapper(int watch,
+ virErrorPtr err)
+{
+ int ret = virEventRemoveHandle(watch);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virEventRemoveTimeoutWrapper(int timer,
+ virErrorPtr err)
+{
+ int ret = virEventRemoveTimeout(timer);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virEventRunDefaultImplWrapper(virErrorPtr err)
+{
+ int ret = virEventRunDefaultImpl();
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+*/
+import "C"
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/events_wrapper.h b/src/dma/vendor/github.com/libvirt/libvirt-go/events_wrapper.h
new file mode 100644
index 00000000..62ea9c8a
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/events_wrapper.h
@@ -0,0 +1,82 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+#ifndef LIBVIRT_GO_EVENTS_WRAPPER_H__
+#define LIBVIRT_GO_EVENTS_WRAPPER_H__
+
+#include <libvirt/libvirt.h>
+#include <libvirt/virterror.h>
+
+void
+virEventRegisterImplWrapper(void);
+
+void
+eventHandleCallbackInvoke(int watch,
+ int fd,
+ int events,
+ uintptr_t callback,
+ uintptr_t opaque);
+
+void
+eventTimeoutCallbackInvoke(int timer,
+ uintptr_t callback,
+ uintptr_t opaque);
+
+void
+eventHandleCallbackFree(uintptr_t callback,
+ uintptr_t opaque);
+
+void
+eventTimeoutCallbackFree(uintptr_t callback,
+ uintptr_t opaque);
+
+int
+virEventAddHandleWrapper(int fd,
+ int events,
+ int callbackID,
+ virErrorPtr err);
+
+int
+virEventAddTimeoutWrapper(int timeout,
+ int callbackID,
+ virErrorPtr err);
+
+int
+virEventRegisterDefaultImplWrapper(virErrorPtr err);
+
+int
+virEventRemoveHandleWrapper(int watch,
+ virErrorPtr err);
+
+int
+virEventRemoveTimeoutWrapper(int timer,
+ virErrorPtr err);
+
+int
+virEventRunDefaultImplWrapper(virErrorPtr err);
+
+
+#endif /* LIBVIRT_GO_EVENTS_WRAPPER_H__ */
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/interface.go b/src/dma/vendor/github.com/libvirt/libvirt-go/interface.go
new file mode 100644
index 00000000..9b6ebb2b
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/interface.go
@@ -0,0 +1,145 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+package libvirt
+
+/*
+#cgo pkg-config: libvirt
+#include <stdlib.h>
+#include "interface_wrapper.h"
+*/
+import "C"
+
+import (
+ "unsafe"
+)
+
+type InterfaceXMLFlags int
+
+const (
+ INTERFACE_XML_INACTIVE = InterfaceXMLFlags(C.VIR_INTERFACE_XML_INACTIVE)
+)
+
+type Interface struct {
+ ptr C.virInterfacePtr
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceCreate
+func (n *Interface) Create(flags uint32) error {
+ var err C.virError
+ result := C.virInterfaceCreateWrapper(n.ptr, C.uint(flags), &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceDestroy
+func (n *Interface) Destroy(flags uint32) error {
+ var err C.virError
+ result := C.virInterfaceDestroyWrapper(n.ptr, C.uint(flags), &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceIsActive
+func (n *Interface) IsActive() (bool, error) {
+ var err C.virError
+ result := C.virInterfaceIsActiveWrapper(n.ptr, &err)
+ if result == -1 {
+ return false, makeError(&err)
+ }
+ if result == 1 {
+ return true, nil
+ }
+ return false, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceGetMACString
+func (n *Interface) GetMACString() (string, error) {
+ var err C.virError
+ result := C.virInterfaceGetMACStringWrapper(n.ptr, &err)
+ if result == nil {
+ return "", makeError(&err)
+ }
+ mac := C.GoString(result)
+ return mac, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceGetName
+func (n *Interface) GetName() (string, error) {
+ var err C.virError
+ result := C.virInterfaceGetNameWrapper(n.ptr, &err)
+ if result == nil {
+ return "", makeError(&err)
+ }
+ name := C.GoString(result)
+ return name, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceGetXMLDesc
+func (n *Interface) GetXMLDesc(flags InterfaceXMLFlags) (string, error) {
+ var err C.virError
+ result := C.virInterfaceGetXMLDescWrapper(n.ptr, C.uint(flags), &err)
+ if result == nil {
+ return "", makeError(&err)
+ }
+ xml := C.GoString(result)
+ C.free(unsafe.Pointer(result))
+ return xml, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceUndefine
+func (n *Interface) Undefine() error {
+ var err C.virError
+ result := C.virInterfaceUndefineWrapper(n.ptr, &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceFree
+func (n *Interface) Free() error {
+ var err C.virError
+ ret := C.virInterfaceFreeWrapper(n.ptr, &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceRef
+func (c *Interface) Ref() error {
+ var err C.virError
+ ret := C.virInterfaceRefWrapper(c.ptr, &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/interface_wrapper.go b/src/dma/vendor/github.com/libvirt/libvirt-go/interface_wrapper.go
new file mode 100644
index 00000000..a33aea9e
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/interface_wrapper.go
@@ -0,0 +1,158 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (C) 2018 Red Hat, Inc.
+ *
+ */
+
+package libvirt
+
+/*
+#cgo pkg-config: libvirt
+#include <assert.h>
+#include "interface_wrapper.h"
+
+
+int
+virInterfaceCreateWrapper(virInterfacePtr iface,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virInterfaceCreate(iface, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virInterfaceDestroyWrapper(virInterfacePtr iface,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virInterfaceDestroy(iface, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virInterfaceFreeWrapper(virInterfacePtr iface,
+ virErrorPtr err)
+{
+ int ret = virInterfaceFree(iface);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+virConnectPtr
+virInterfaceGetConnectWrapper(virInterfacePtr iface,
+ virErrorPtr err)
+{
+ virConnectPtr ret = virInterfaceGetConnect(iface);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+const char *
+virInterfaceGetMACStringWrapper(virInterfacePtr iface,
+ virErrorPtr err)
+{
+ const char * ret = virInterfaceGetMACString(iface);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+const char *
+virInterfaceGetNameWrapper(virInterfacePtr iface,
+ virErrorPtr err)
+{
+ const char * ret = virInterfaceGetName(iface);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+char *
+virInterfaceGetXMLDescWrapper(virInterfacePtr iface,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ char * ret = virInterfaceGetXMLDesc(iface, flags);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virInterfaceIsActiveWrapper(virInterfacePtr iface,
+ virErrorPtr err)
+{
+ int ret = virInterfaceIsActive(iface);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virInterfaceRefWrapper(virInterfacePtr iface,
+ virErrorPtr err)
+{
+ int ret = virInterfaceRef(iface);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virInterfaceUndefineWrapper(virInterfacePtr iface,
+ virErrorPtr err)
+{
+ int ret = virInterfaceUndefine(iface);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+*/
+import "C"
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/interface_wrapper.h b/src/dma/vendor/github.com/libvirt/libvirt-go/interface_wrapper.h
new file mode 100644
index 00000000..b7cef761
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/interface_wrapper.h
@@ -0,0 +1,76 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (C) 2018 Red Hat, Inc.
+ *
+ */
+
+#ifndef LIBVIRT_GO_INTERFACE_WRAPPER_H__
+#define LIBVIRT_GO_INTERFACE_WRAPPER_H__
+
+#include <libvirt/libvirt.h>
+#include <libvirt/virterror.h>
+
+int
+virInterfaceCreateWrapper(virInterfacePtr iface,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virInterfaceDestroyWrapper(virInterfacePtr iface,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virInterfaceFreeWrapper(virInterfacePtr iface,
+ virErrorPtr err);
+
+virConnectPtr
+virInterfaceGetConnectWrapper(virInterfacePtr iface,
+ virErrorPtr err);
+
+const char *
+virInterfaceGetMACStringWrapper(virInterfacePtr iface,
+ virErrorPtr err);
+
+const char *
+virInterfaceGetNameWrapper(virInterfacePtr iface,
+ virErrorPtr err);
+
+char *
+virInterfaceGetXMLDescWrapper(virInterfacePtr iface,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virInterfaceIsActiveWrapper(virInterfacePtr iface,
+ virErrorPtr err);
+
+int
+virInterfaceRefWrapper(virInterfacePtr iface,
+ virErrorPtr err);
+
+int
+virInterfaceUndefineWrapper(virInterfacePtr iface,
+ virErrorPtr err);
+
+
+#endif /* LIBVIRT_GO_INTERFACE_WRAPPER_H__ */
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/libvirtd.conf b/src/dma/vendor/github.com/libvirt/libvirt-go/libvirtd.conf
new file mode 100644
index 00000000..1c31a241
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/libvirtd.conf
@@ -0,0 +1,6 @@
+listen_tls = 0
+listen_tcp = 1
+tcp_port = "16509"
+listen_addr = "127.0.0.1"
+auth_unix_rw = "none"
+auth_tcp = "sasl"
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/libvirtd.sasl b/src/dma/vendor/github.com/libvirt/libvirt-go/libvirtd.sasl
new file mode 100644
index 00000000..9275a70d
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/libvirtd.sasl
@@ -0,0 +1,2 @@
+mech_list: digest-md5
+sasldb_path: /etc/libvirt/passwd.db
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/lxc.go b/src/dma/vendor/github.com/libvirt/libvirt-go/lxc.go
new file mode 100644
index 00000000..1578cab9
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/lxc.go
@@ -0,0 +1,155 @@
+// +build !without_lxc
+
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+package libvirt
+
+/*
+#cgo pkg-config: libvirt
+// Can't rely on pkg-config for libvirt-lxc since it was not
+// installed until 2.6.0 onwards
+#cgo LDFLAGS: -lvirt-lxc
+#include <stdlib.h>
+#include <string.h>
+#include "lxc_wrapper.h"
+*/
+import "C"
+
+import (
+ "os"
+ "unsafe"
+)
+
+func (d *Domain) LxcOpenNamespace(flags uint32) ([]os.File, error) {
+ var cfdlist *C.int
+
+ var err C.virError
+ ret := C.virDomainLxcOpenNamespaceWrapper(d.ptr, &cfdlist, C.uint(flags), &err)
+ if ret == -1 {
+ return []os.File{}, makeError(&err)
+ }
+ fdlist := make([]os.File, ret)
+ for i := 0; i < int(ret); i++ {
+ var cfd C.int
+ cfd = *(*C.int)(unsafe.Pointer(uintptr(unsafe.Pointer(cfdlist)) + (unsafe.Sizeof(cfd) * uintptr(i))))
+ fdlist[i] = *os.NewFile(uintptr(cfd), "namespace")
+ }
+ defer C.free(unsafe.Pointer(cfdlist))
+ return fdlist, nil
+}
+
+func (d *Domain) LxcEnterNamespace(fdlist []os.File, flags uint32) ([]os.File, error) {
+ var coldfdlist *C.int
+ var ncoldfdlist C.uint
+ cfdlist := make([]C.int, len(fdlist))
+ for i := 0; i < len(fdlist); i++ {
+ cfdlist[i] = C.int(fdlist[i].Fd())
+ }
+
+ var err C.virError
+ ret := C.virDomainLxcEnterNamespaceWrapper(d.ptr, C.uint(len(fdlist)), &cfdlist[0], &ncoldfdlist, &coldfdlist, C.uint(flags), &err)
+ if ret == -1 {
+ return []os.File{}, makeError(&err)
+ }
+ oldfdlist := make([]os.File, ncoldfdlist)
+ for i := 0; i < int(ncoldfdlist); i++ {
+ var cfd C.int
+ cfd = *(*C.int)(unsafe.Pointer(uintptr(unsafe.Pointer(coldfdlist)) + (unsafe.Sizeof(cfd) * uintptr(i))))
+ oldfdlist[i] = *os.NewFile(uintptr(cfd), "namespace")
+ }
+ defer C.free(unsafe.Pointer(coldfdlist))
+ return oldfdlist, nil
+}
+
+func DomainLxcEnterSecurityLabel(model *NodeSecurityModel, label *SecurityLabel, flags uint32) (*SecurityLabel, error) {
+ var cmodel C.virSecurityModel
+ var clabel C.virSecurityLabel
+ var coldlabel C.virSecurityLabel
+
+ cmodelstrlen := len(model.Model)
+ if cmodelstrlen > (C.VIR_SECURITY_MODEL_BUFLEN - 1) {
+ cmodelstrlen = C.VIR_SECURITY_MODEL_BUFLEN - 1
+ }
+ cmodelstr := C.CString(model.Model)
+ defer C.free(unsafe.Pointer(cmodelstr))
+
+ cdoistrlen := len(model.Doi)
+ if cdoistrlen >= (C.VIR_SECURITY_DOI_BUFLEN - 1) {
+ cdoistrlen = C.VIR_SECURITY_DOI_BUFLEN - 1
+ }
+ cdoistr := C.CString(model.Doi)
+ defer C.free(unsafe.Pointer(cdoistr))
+
+ C.memcpy(unsafe.Pointer(&cmodel.model), unsafe.Pointer(cmodelstr), C.size_t(cmodelstrlen))
+ C.memcpy(unsafe.Pointer(&cmodel.doi), unsafe.Pointer(cdoistr), C.size_t(cdoistrlen))
+
+ clabelstrlen := len(label.Label)
+ if clabelstrlen > (C.VIR_SECURITY_LABEL_BUFLEN - 1) {
+ clabelstrlen = C.VIR_SECURITY_LABEL_BUFLEN - 1
+ }
+ clabelstr := C.CString(label.Label)
+ defer C.free(unsafe.Pointer(clabelstr))
+
+ C.memcpy(unsafe.Pointer(&clabel.label), unsafe.Pointer(clabelstr), C.size_t(clabelstrlen))
+ if label.Enforcing {
+ clabel.enforcing = 1
+ } else {
+ clabel.enforcing = 0
+ }
+
+ var err C.virError
+ ret := C.virDomainLxcEnterSecurityLabelWrapper(&cmodel, &clabel, &coldlabel, C.uint(flags), &err)
+ if ret == -1 {
+ return nil, makeError(&err)
+ }
+
+ var oldlabel SecurityLabel
+
+ oldlabel.Label = C.GoString((*C.char)(unsafe.Pointer(&coldlabel.label)))
+ if coldlabel.enforcing != 0 {
+ oldlabel.Enforcing = true
+ } else {
+ oldlabel.Enforcing = false
+ }
+
+ return &oldlabel, nil
+}
+
+func (d *Domain) DomainLxcEnterCGroup(flags uint32) error {
+ if C.LIBVIR_VERSION_NUMBER < 2000000 {
+ return makeNotImplementedError("virDomainLxcEnterCGroup")
+ }
+
+ var err C.virError
+ ret := C.virDomainLxcEnterCGroupWrapper(d.ptr, C.uint(flags), &err)
+
+ if ret == -1 {
+ return makeError(&err)
+ }
+
+ return nil
+}
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/lxc_wrapper.go b/src/dma/vendor/github.com/libvirt/libvirt-go/lxc_wrapper.go
new file mode 100644
index 00000000..fa3d9103
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/lxc_wrapper.go
@@ -0,0 +1,101 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+package libvirt
+
+/*
+#cgo pkg-config: libvirt
+// Can't rely on pkg-config for libvirt-lxc since it was not
+// installed until 2.6.0 onwards
+#cgo LDFLAGS: -lvirt-lxc
+#include <assert.h>
+#include "lxc_wrapper.h"
+
+int
+virDomainLxcEnterCGroupWrapper(virDomainPtr domain,
+ unsigned int flags,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 2000000
+ assert(0); // Caller should have checked version
+#else
+ int ret = virDomainLxcEnterCGroup(domain, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+int
+virDomainLxcEnterNamespaceWrapper(virDomainPtr domain,
+ unsigned int nfdlist,
+ int *fdlist,
+ unsigned int *noldfdlist,
+ int **oldfdlist,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainLxcEnterNamespace(domain, nfdlist, fdlist, noldfdlist, oldfdlist, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainLxcEnterSecurityLabelWrapper(virSecurityModelPtr model,
+ virSecurityLabelPtr label,
+ virSecurityLabelPtr oldlabel,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainLxcEnterSecurityLabel(model, label, oldlabel, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainLxcOpenNamespaceWrapper(virDomainPtr domain,
+ int **fdlist,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainLxcOpenNamespace(domain, fdlist, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+*/
+import "C"
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/lxc_wrapper.h b/src/dma/vendor/github.com/libvirt/libvirt-go/lxc_wrapper.h
new file mode 100644
index 00000000..b3afd6e5
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/lxc_wrapper.h
@@ -0,0 +1,63 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+#ifndef LIBVIRT_GO_LXC_COMPAT_H__
+#define LIBVIRT_GO_LXC_COMPAT_H__
+
+#include <libvirt/libvirt.h>
+#include <libvirt/libvirt-lxc.h>
+#include <libvirt/virterror.h>
+
+
+int
+virDomainLxcEnterCGroupWrapper(virDomainPtr domain,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainLxcEnterNamespaceWrapper(virDomainPtr domain,
+ unsigned int nfdlist,
+ int *fdlist,
+ unsigned int *noldfdlist,
+ int **oldfdlist,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainLxcEnterSecurityLabelWrapper(virSecurityModelPtr model,
+ virSecurityLabelPtr label,
+ virSecurityLabelPtr oldlabel,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainLxcOpenNamespaceWrapper(virDomainPtr domain,
+ int **fdlist,
+ unsigned int flags,
+ virErrorPtr err);
+
+
+#endif /* LIBVIRT_GO_LXC_COMPAT_H__ */
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/network.go b/src/dma/vendor/github.com/libvirt/libvirt-go/network.go
new file mode 100644
index 00000000..99954aa5
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/network.go
@@ -0,0 +1,335 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+package libvirt
+
+/*
+#cgo pkg-config: libvirt
+#include <stdlib.h>
+#include "network_wrapper.h"
+*/
+import "C"
+
+import (
+ "reflect"
+ "time"
+ "unsafe"
+)
+
+type IPAddrType int
+
+const (
+ IP_ADDR_TYPE_IPV4 = IPAddrType(C.VIR_IP_ADDR_TYPE_IPV4)
+ IP_ADDR_TYPE_IPV6 = IPAddrType(C.VIR_IP_ADDR_TYPE_IPV6)
+)
+
+type NetworkXMLFlags int
+
+const (
+ NETWORK_XML_INACTIVE = NetworkXMLFlags(C.VIR_NETWORK_XML_INACTIVE)
+)
+
+type NetworkUpdateCommand int
+
+const (
+ NETWORK_UPDATE_COMMAND_NONE = NetworkUpdateCommand(C.VIR_NETWORK_UPDATE_COMMAND_NONE)
+ NETWORK_UPDATE_COMMAND_MODIFY = NetworkUpdateCommand(C.VIR_NETWORK_UPDATE_COMMAND_MODIFY)
+ NETWORK_UPDATE_COMMAND_DELETE = NetworkUpdateCommand(C.VIR_NETWORK_UPDATE_COMMAND_DELETE)
+ NETWORK_UPDATE_COMMAND_ADD_LAST = NetworkUpdateCommand(C.VIR_NETWORK_UPDATE_COMMAND_ADD_LAST)
+ NETWORK_UPDATE_COMMAND_ADD_FIRST = NetworkUpdateCommand(C.VIR_NETWORK_UPDATE_COMMAND_ADD_FIRST)
+)
+
+type NetworkUpdateSection int
+
+const (
+ NETWORK_SECTION_NONE = NetworkUpdateSection(C.VIR_NETWORK_SECTION_NONE)
+ NETWORK_SECTION_BRIDGE = NetworkUpdateSection(C.VIR_NETWORK_SECTION_BRIDGE)
+ NETWORK_SECTION_DOMAIN = NetworkUpdateSection(C.VIR_NETWORK_SECTION_DOMAIN)
+ NETWORK_SECTION_IP = NetworkUpdateSection(C.VIR_NETWORK_SECTION_IP)
+ NETWORK_SECTION_IP_DHCP_HOST = NetworkUpdateSection(C.VIR_NETWORK_SECTION_IP_DHCP_HOST)
+ NETWORK_SECTION_IP_DHCP_RANGE = NetworkUpdateSection(C.VIR_NETWORK_SECTION_IP_DHCP_RANGE)
+ NETWORK_SECTION_FORWARD = NetworkUpdateSection(C.VIR_NETWORK_SECTION_FORWARD)
+ NETWORK_SECTION_FORWARD_INTERFACE = NetworkUpdateSection(C.VIR_NETWORK_SECTION_FORWARD_INTERFACE)
+ NETWORK_SECTION_FORWARD_PF = NetworkUpdateSection(C.VIR_NETWORK_SECTION_FORWARD_PF)
+ NETWORK_SECTION_PORTGROUP = NetworkUpdateSection(C.VIR_NETWORK_SECTION_PORTGROUP)
+ NETWORK_SECTION_DNS_HOST = NetworkUpdateSection(C.VIR_NETWORK_SECTION_DNS_HOST)
+ NETWORK_SECTION_DNS_TXT = NetworkUpdateSection(C.VIR_NETWORK_SECTION_DNS_TXT)
+ NETWORK_SECTION_DNS_SRV = NetworkUpdateSection(C.VIR_NETWORK_SECTION_DNS_SRV)
+)
+
+type NetworkUpdateFlags int
+
+const (
+ NETWORK_UPDATE_AFFECT_CURRENT = NetworkUpdateFlags(C.VIR_NETWORK_UPDATE_AFFECT_CURRENT)
+ NETWORK_UPDATE_AFFECT_LIVE = NetworkUpdateFlags(C.VIR_NETWORK_UPDATE_AFFECT_LIVE)
+ NETWORK_UPDATE_AFFECT_CONFIG = NetworkUpdateFlags(C.VIR_NETWORK_UPDATE_AFFECT_CONFIG)
+)
+
+type NetworkEventLifecycleType int
+
+const (
+ NETWORK_EVENT_DEFINED = NetworkEventLifecycleType(C.VIR_NETWORK_EVENT_DEFINED)
+ NETWORK_EVENT_UNDEFINED = NetworkEventLifecycleType(C.VIR_NETWORK_EVENT_UNDEFINED)
+ NETWORK_EVENT_STARTED = NetworkEventLifecycleType(C.VIR_NETWORK_EVENT_STARTED)
+ NETWORK_EVENT_STOPPED = NetworkEventLifecycleType(C.VIR_NETWORK_EVENT_STOPPED)
+)
+
+type NetworkEventID int
+
+const (
+ NETWORK_EVENT_ID_LIFECYCLE = NetworkEventID(C.VIR_NETWORK_EVENT_ID_LIFECYCLE)
+)
+
+type Network struct {
+ ptr C.virNetworkPtr
+}
+
+type NetworkDHCPLease struct {
+ Iface string
+ ExpiryTime time.Time
+ Type IPAddrType
+ Mac string
+ Iaid string
+ IPaddr string
+ Prefix uint
+ Hostname string
+ Clientid string
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkFree
+func (n *Network) Free() error {
+ var err C.virError
+ ret := C.virNetworkFreeWrapper(n.ptr, &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkRef
+func (c *Network) Ref() error {
+ var err C.virError
+ ret := C.virNetworkRefWrapper(c.ptr, &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkCreate
+func (n *Network) Create() error {
+ var err C.virError
+ result := C.virNetworkCreateWrapper(n.ptr, &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkDestroy
+func (n *Network) Destroy() error {
+ var err C.virError
+ result := C.virNetworkDestroyWrapper(n.ptr, &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkIsActive
+func (n *Network) IsActive() (bool, error) {
+ var err C.virError
+ result := C.virNetworkIsActiveWrapper(n.ptr, &err)
+ if result == -1 {
+ return false, makeError(&err)
+ }
+ if result == 1 {
+ return true, nil
+ }
+ return false, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkIsPersistent
+func (n *Network) IsPersistent() (bool, error) {
+ var err C.virError
+ result := C.virNetworkIsPersistentWrapper(n.ptr, &err)
+ if result == -1 {
+ return false, makeError(&err)
+ }
+ if result == 1 {
+ return true, nil
+ }
+ return false, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkGetAutostart
+func (n *Network) GetAutostart() (bool, error) {
+ var out C.int
+ var err C.virError
+ result := C.virNetworkGetAutostartWrapper(n.ptr, (*C.int)(unsafe.Pointer(&out)), &err)
+ if result == -1 {
+ return false, makeError(&err)
+ }
+ switch out {
+ case 1:
+ return true, nil
+ default:
+ return false, nil
+ }
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkSetAutostart
+func (n *Network) SetAutostart(autostart bool) error {
+ var cAutostart C.int
+ switch autostart {
+ case true:
+ cAutostart = 1
+ default:
+ cAutostart = 0
+ }
+ var err C.virError
+ result := C.virNetworkSetAutostartWrapper(n.ptr, cAutostart, &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkGetName
+func (n *Network) GetName() (string, error) {
+ var err C.virError
+ name := C.virNetworkGetNameWrapper(n.ptr, &err)
+ if name == nil {
+ return "", makeError(&err)
+ }
+ return C.GoString(name), nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkGetUUID
+func (n *Network) GetUUID() ([]byte, error) {
+ var cUuid [C.VIR_UUID_BUFLEN](byte)
+ cuidPtr := unsafe.Pointer(&cUuid)
+ var err C.virError
+ result := C.virNetworkGetUUIDWrapper(n.ptr, (*C.uchar)(cuidPtr), &err)
+ if result != 0 {
+ return []byte{}, makeError(&err)
+ }
+ return C.GoBytes(cuidPtr, C.VIR_UUID_BUFLEN), nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkGetUUIDString
+func (n *Network) GetUUIDString() (string, error) {
+ var cUuid [C.VIR_UUID_STRING_BUFLEN](C.char)
+ cuidPtr := unsafe.Pointer(&cUuid)
+ var err C.virError
+ result := C.virNetworkGetUUIDStringWrapper(n.ptr, (*C.char)(cuidPtr), &err)
+ if result != 0 {
+ return "", makeError(&err)
+ }
+ return C.GoString((*C.char)(cuidPtr)), nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkGetBridgeName
+func (n *Network) GetBridgeName() (string, error) {
+ var err C.virError
+ result := C.virNetworkGetBridgeNameWrapper(n.ptr, &err)
+ if result == nil {
+ return "", makeError(&err)
+ }
+ bridge := C.GoString(result)
+ C.free(unsafe.Pointer(result))
+ return bridge, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkGetXMLDesc
+func (n *Network) GetXMLDesc(flags NetworkXMLFlags) (string, error) {
+ var err C.virError
+ result := C.virNetworkGetXMLDescWrapper(n.ptr, C.uint(flags), &err)
+ if result == nil {
+ return "", makeError(&err)
+ }
+ xml := C.GoString(result)
+ C.free(unsafe.Pointer(result))
+ return xml, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkUndefine
+func (n *Network) Undefine() error {
+ var err C.virError
+ result := C.virNetworkUndefineWrapper(n.ptr, &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkUpdate
+func (n *Network) Update(cmd NetworkUpdateCommand, section NetworkUpdateSection, parentIndex int, xml string, flags NetworkUpdateFlags) error {
+ cxml := C.CString(xml)
+ defer C.free(unsafe.Pointer(cxml))
+ var err C.virError
+ result := C.virNetworkUpdateWrapper(n.ptr, C.uint(cmd), C.uint(section), C.int(parentIndex), cxml, C.uint(flags), &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkGetDHCPLeases
+func (n *Network) GetDHCPLeases() ([]NetworkDHCPLease, error) {
+ if C.LIBVIR_VERSION_NUMBER < 1002006 {
+ return []NetworkDHCPLease{}, makeNotImplementedError("virNetworkGetDHCPLeases")
+ }
+ var cLeases *C.virNetworkDHCPLeasePtr
+ var err C.virError
+ numLeases := C.virNetworkGetDHCPLeasesWrapper(n.ptr, nil, (**C.virNetworkDHCPLeasePtr)(&cLeases), C.uint(0), &err)
+ if numLeases == -1 {
+ return nil, makeError(&err)
+ }
+ hdr := reflect.SliceHeader{
+ Data: uintptr(unsafe.Pointer(cLeases)),
+ Len: int(numLeases),
+ Cap: int(numLeases),
+ }
+ var leases []NetworkDHCPLease
+ slice := *(*[]C.virNetworkDHCPLeasePtr)(unsafe.Pointer(&hdr))
+ for _, clease := range slice {
+ leases = append(leases, NetworkDHCPLease{
+ Iface: C.GoString(clease.iface),
+ ExpiryTime: time.Unix(int64(clease.expirytime), 0),
+ Type: IPAddrType(clease._type),
+ Mac: C.GoString(clease.mac),
+ Iaid: C.GoString(clease.iaid),
+ IPaddr: C.GoString(clease.ipaddr),
+ Prefix: uint(clease.prefix),
+ Hostname: C.GoString(clease.hostname),
+ Clientid: C.GoString(clease.clientid),
+ })
+ C.virNetworkDHCPLeaseFreeWrapper(clease)
+ }
+ C.free(unsafe.Pointer(cLeases))
+ return leases, nil
+}
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/network_compat.h b/src/dma/vendor/github.com/libvirt/libvirt-go/network_compat.h
new file mode 100644
index 00000000..08f0778a
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/network_compat.h
@@ -0,0 +1,86 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+#ifndef LIBVIRT_GO_NETWORK_COMPAT_H__
+#define LIBVIRT_GO_NETWORK_COMPAT_H__
+
+/* 1.2.1 */
+
+#ifndef VIR_NETWORK_EVENT_DEFINED
+#define VIR_NETWORK_EVENT_DEFINED 0
+#endif
+
+#ifndef VIR_NETWORK_EVENT_UNDEFINED
+#define VIR_NETWORK_EVENT_UNDEFINED 1
+#endif
+
+#ifndef VIR_NETWORK_EVENT_STARTED
+#define VIR_NETWORK_EVENT_STARTED 2
+#endif
+
+#ifndef VIR_NETWORK_EVENT_STOPPED
+#define VIR_NETWORK_EVENT_STOPPED 3
+#endif
+
+#ifndef VIR_NETWORK_EVENT_ID_LIFECYCLE
+#define VIR_NETWORK_EVENT_ID_LIFECYCLE 0
+#endif
+
+
+#if LIBVIR_VERSION_NUMBER < 1002001
+typedef void (*virConnectNetworkEventGenericCallback)(virConnectPtr conn,
+ virNetworkPtr net,
+ void *opaque);
+#endif
+
+
+/* 1.2.5 */
+
+#ifndef VIR_IP_ADDR_TYPE_IPV4
+#define VIR_IP_ADDR_TYPE_IPV4 0
+#endif
+
+#ifndef VIR_IP_ADDR_TYPE_IPV6
+#define VIR_IP_ADDR_TYPE_IPV6 1
+#endif
+
+#if LIBVIR_VERSION_NUMBER < 1002006
+typedef struct _virNetworkDHCPLease virNetworkDHCPLease;
+typedef virNetworkDHCPLease *virNetworkDHCPLeasePtr;
+struct _virNetworkDHCPLease {
+ char *iface; /* Network interface name */
+ long long expirytime; /* Seconds since epoch */
+ int type; /* virIPAddrType */
+ char *mac; /* MAC address */
+ char *iaid; /* IAID */
+ char *ipaddr; /* IP address */
+ unsigned int prefix; /* IP address prefix */
+ char *hostname; /* Hostname */
+ char *clientid; /* Client ID or DUID */
+};
+#endif
+
+#endif /* LIBVIRT_GO_NETWORK_COMPAT_H__ */
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/network_events.go b/src/dma/vendor/github.com/libvirt/libvirt-go/network_events.go
new file mode 100644
index 00000000..2d9bddc3
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/network_events.go
@@ -0,0 +1,125 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+package libvirt
+
+import (
+ "fmt"
+ "unsafe"
+)
+
+/*
+#cgo pkg-config: libvirt
+#include "network_events_wrapper.h"
+*/
+import "C"
+
+type NetworkEventLifecycle struct {
+ Event NetworkEventLifecycleType
+ // TODO: we can make Detail typesafe somehow ?
+ Detail int
+}
+
+type NetworkEventLifecycleCallback func(c *Connect, n *Network, event *NetworkEventLifecycle)
+
+//export networkEventLifecycleCallback
+func networkEventLifecycleCallback(c C.virConnectPtr, n C.virNetworkPtr,
+ event int, detail int,
+ goCallbackId int) {
+
+ network := &Network{ptr: n}
+ connection := &Connect{ptr: c}
+
+ eventDetails := &NetworkEventLifecycle{
+ Event: NetworkEventLifecycleType(event),
+ Detail: detail,
+ }
+
+ callbackFunc := getCallbackId(goCallbackId)
+ callback, ok := callbackFunc.(NetworkEventLifecycleCallback)
+ if !ok {
+ panic("Inappropriate callback type called")
+ }
+ callback(connection, network, eventDetails)
+}
+
+func (c *Connect) NetworkEventLifecycleRegister(net *Network, callback NetworkEventLifecycleCallback) (int, error) {
+ goCallBackId := registerCallbackId(callback)
+ if C.LIBVIR_VERSION_NUMBER < 1002001 {
+ return 0, makeNotImplementedError("virConnectNetworkEventRegisterAny")
+ }
+
+ callbackPtr := unsafe.Pointer(C.networkEventLifecycleCallbackHelper)
+ var cnet C.virNetworkPtr
+ if net != nil {
+ cnet = net.ptr
+ }
+ var err C.virError
+ ret := C.virConnectNetworkEventRegisterAnyWrapper(c.ptr, cnet,
+ C.VIR_NETWORK_EVENT_ID_LIFECYCLE,
+ C.virConnectNetworkEventGenericCallback(callbackPtr),
+ C.long(goCallBackId), &err)
+ if ret == -1 {
+ freeCallbackId(goCallBackId)
+ return 0, makeError(&err)
+ }
+ return int(ret), nil
+}
+
+func (c *Connect) NetworkEventDeregister(callbackId int) error {
+ if C.LIBVIR_VERSION_NUMBER < 1002001 {
+ return makeNotImplementedError("virConnectNetworkEventDeregisterAny")
+ }
+ // Deregister the callback
+ var err C.virError
+ ret := int(C.virConnectNetworkEventDeregisterAnyWrapper(c.ptr, C.int(callbackId), &err))
+ if ret < 0 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+func (e NetworkEventLifecycle) String() string {
+ var event string
+ switch e.Event {
+ case NETWORK_EVENT_DEFINED:
+ event = "defined"
+
+ case NETWORK_EVENT_UNDEFINED:
+ event = "undefined"
+
+ case NETWORK_EVENT_STARTED:
+ event = "started"
+
+ case NETWORK_EVENT_STOPPED:
+ event = "stopped"
+
+ default:
+ event = "unknown"
+ }
+
+ return fmt.Sprintf("Network event=%q", event)
+}
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/network_events_wrapper.go b/src/dma/vendor/github.com/libvirt/libvirt-go/network_events_wrapper.go
new file mode 100644
index 00000000..4e424baa
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/network_events_wrapper.go
@@ -0,0 +1,79 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+package libvirt
+
+/*
+#cgo pkg-config: libvirt
+#include <assert.h>
+#include <stdint.h>
+#include "network_events_wrapper.h"
+#include "callbacks_wrapper.h"
+
+extern void networkEventLifecycleCallback(virConnectPtr, virNetworkPtr, int, int, int);
+void networkEventLifecycleCallbackHelper(virConnectPtr c, virNetworkPtr d,
+ int event, int detail, void *data)
+{
+ networkEventLifecycleCallback(c, d, event, detail, (int)(intptr_t)data);
+}
+
+int
+virConnectNetworkEventRegisterAnyWrapper(virConnectPtr c,
+ virNetworkPtr d,
+ int eventID,
+ virConnectNetworkEventGenericCallback cb,
+ long goCallbackId,
+ virErrorPtr err)
+{
+ void* id = (void*)goCallbackId;
+#if LIBVIR_VERSION_NUMBER < 1002001
+ assert(0); // Caller should have checked version
+#else
+ int ret = virConnectNetworkEventRegisterAny(c, d, eventID, cb, id, freeGoCallbackHelper);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+int virConnectNetworkEventDeregisterAnyWrapper(virConnectPtr conn,
+ int callbackID,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 1002001
+ assert(0); // Caller should have checked version
+#else
+ int ret = virConnectNetworkEventDeregisterAny(conn, callbackID);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+*/
+import "C"
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/network_events_wrapper.h b/src/dma/vendor/github.com/libvirt/libvirt-go/network_events_wrapper.h
new file mode 100644
index 00000000..789837a1
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/network_events_wrapper.h
@@ -0,0 +1,55 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+#ifndef LIBVIRT_GO_NETWORK_EVENTS_WRAPPER_H__
+#define LIBVIRT_GO_NETWORK_EVENTS_WRAPPER_H__
+
+#include <libvirt/libvirt.h>
+#include <libvirt/virterror.h>
+#include "network_compat.h"
+
+void
+networkEventLifecycleCallbackHelper(virConnectPtr c,
+ virNetworkPtr d,
+ int event,
+ int detail,
+ void* data);
+
+int
+virConnectNetworkEventRegisterAnyWrapper(virConnectPtr c,
+ virNetworkPtr d,
+ int eventID,
+ virConnectNetworkEventGenericCallback cb,
+ long goCallbackId,
+ virErrorPtr err);
+
+int
+virConnectNetworkEventDeregisterAnyWrapper(virConnectPtr conn,
+ int callbackID,
+ virErrorPtr err);
+
+
+#endif /* LIBVIRT_GO_NETWORK_EVENTS_WRAPPER_H__ */
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/network_wrapper.go b/src/dma/vendor/github.com/libvirt/libvirt-go/network_wrapper.go
new file mode 100644
index 00000000..2fc443f2
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/network_wrapper.go
@@ -0,0 +1,267 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+package libvirt
+
+/*
+#cgo pkg-config: libvirt
+#include <assert.h>
+#include "network_wrapper.h"
+
+int
+virNetworkCreateWrapper(virNetworkPtr network,
+ virErrorPtr err)
+{
+ int ret = virNetworkCreate(network);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+void
+virNetworkDHCPLeaseFreeWrapper(virNetworkDHCPLeasePtr lease)
+{
+#if LIBVIR_VERSION_NUMBER < 1002006
+ assert(0); // Caller should have checked version
+#else
+ virNetworkDHCPLeaseFree(lease);
+#endif
+}
+
+
+int
+virNetworkDestroyWrapper(virNetworkPtr network,
+ virErrorPtr err)
+{
+ int ret = virNetworkDestroy(network);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virNetworkFreeWrapper(virNetworkPtr network,
+ virErrorPtr err)
+{
+ int ret = virNetworkFree(network);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virNetworkGetAutostartWrapper(virNetworkPtr network,
+ int *autostart,
+ virErrorPtr err)
+{
+ int ret = virNetworkGetAutostart(network, autostart);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+char *
+virNetworkGetBridgeNameWrapper(virNetworkPtr network,
+ virErrorPtr err)
+{
+ char * ret = virNetworkGetBridgeName(network);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+virConnectPtr
+virNetworkGetConnectWrapper(virNetworkPtr net,
+ virErrorPtr err)
+{
+ virConnectPtr ret = virNetworkGetConnect(net);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virNetworkGetDHCPLeasesWrapper(virNetworkPtr network,
+ const char *mac,
+ virNetworkDHCPLeasePtr **leases,
+ unsigned int flags,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 1002006
+ assert(0); // Caller should have checked version
+#else
+ int ret = virNetworkGetDHCPLeases(network, mac, leases, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+const char *
+virNetworkGetNameWrapper(virNetworkPtr network,
+ virErrorPtr err)
+{
+ const char * ret = virNetworkGetName(network);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virNetworkGetUUIDWrapper(virNetworkPtr network,
+ unsigned char *uuid,
+ virErrorPtr err)
+{
+ int ret = virNetworkGetUUID(network, uuid);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virNetworkGetUUIDStringWrapper(virNetworkPtr network,
+ char *buf,
+ virErrorPtr err)
+{
+ int ret = virNetworkGetUUIDString(network, buf);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+char *
+virNetworkGetXMLDescWrapper(virNetworkPtr network,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ char * ret = virNetworkGetXMLDesc(network, flags);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virNetworkIsActiveWrapper(virNetworkPtr net,
+ virErrorPtr err)
+{
+ int ret = virNetworkIsActive(net);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virNetworkIsPersistentWrapper(virNetworkPtr net,
+ virErrorPtr err)
+{
+ int ret = virNetworkIsPersistent(net);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virNetworkRefWrapper(virNetworkPtr network,
+ virErrorPtr err)
+{
+ int ret = virNetworkRef(network);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virNetworkSetAutostartWrapper(virNetworkPtr network,
+ int autostart,
+ virErrorPtr err)
+{
+ int ret = virNetworkSetAutostart(network, autostart);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virNetworkUndefineWrapper(virNetworkPtr network,
+ virErrorPtr err)
+{
+ int ret = virNetworkUndefine(network);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virNetworkUpdateWrapper(virNetworkPtr network,
+ unsigned int command,
+ unsigned int section,
+ int parentIndex,
+ const char *xml,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virNetworkUpdate(network, command, section, parentIndex, xml, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+*/
+import "C"
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/network_wrapper.h b/src/dma/vendor/github.com/libvirt/libvirt-go/network_wrapper.h
new file mode 100644
index 00000000..405bf89a
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/network_wrapper.h
@@ -0,0 +1,119 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+#ifndef LIBVIRT_GO_NETWORK_WRAPPER_H__
+#define LIBVIRT_GO_NETWORK_WRAPPER_H__
+
+#include <libvirt/libvirt.h>
+#include <libvirt/virterror.h>
+#include "network_compat.h"
+
+int
+virNetworkCreateWrapper(virNetworkPtr network,
+ virErrorPtr err);
+
+void
+virNetworkDHCPLeaseFreeWrapper(virNetworkDHCPLeasePtr lease);
+
+int
+virNetworkDestroyWrapper(virNetworkPtr network,
+ virErrorPtr err);
+
+int
+virNetworkFreeWrapper(virNetworkPtr network,
+ virErrorPtr err);
+
+int
+virNetworkGetAutostartWrapper(virNetworkPtr network,
+ int *autostart,
+ virErrorPtr err);
+
+char *
+virNetworkGetBridgeNameWrapper(virNetworkPtr network,
+ virErrorPtr err);
+
+virConnectPtr
+virNetworkGetConnectWrapper(virNetworkPtr net,
+ virErrorPtr err);
+
+int
+virNetworkGetDHCPLeasesWrapper(virNetworkPtr network,
+ const char *mac,
+ virNetworkDHCPLeasePtr **leases,
+ unsigned int flags,
+ virErrorPtr err);
+
+const char *
+virNetworkGetNameWrapper(virNetworkPtr network,
+ virErrorPtr err);
+
+int
+virNetworkGetUUIDWrapper(virNetworkPtr network,
+ unsigned char *uuid,
+ virErrorPtr err);
+
+int
+virNetworkGetUUIDStringWrapper(virNetworkPtr network,
+ char *buf,
+ virErrorPtr err);
+
+char *
+virNetworkGetXMLDescWrapper(virNetworkPtr network,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virNetworkIsActiveWrapper(virNetworkPtr net,
+ virErrorPtr err);
+
+int
+virNetworkIsPersistentWrapper(virNetworkPtr net,
+ virErrorPtr err);
+
+int
+virNetworkRefWrapper(virNetworkPtr network,
+ virErrorPtr err);
+
+int
+virNetworkSetAutostartWrapper(virNetworkPtr network,
+ int autostart,
+ virErrorPtr err);
+
+int
+virNetworkUndefineWrapper(virNetworkPtr network,
+ virErrorPtr err);
+
+int
+virNetworkUpdateWrapper(virNetworkPtr network,
+ unsigned int command,
+ unsigned int section,
+ int parentIndex,
+ const char *xml,
+ unsigned int flags,
+ virErrorPtr err);
+
+
+#endif /* LIBVIRT_GO_NETWORK_WRAPPER_H__ */
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/node_device.go b/src/dma/vendor/github.com/libvirt/libvirt-go/node_device.go
new file mode 100644
index 00000000..474f288c
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/node_device.go
@@ -0,0 +1,192 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+package libvirt
+
+/*
+#cgo pkg-config: libvirt
+#include <stdlib.h>
+#include "node_device_wrapper.h"
+*/
+import "C"
+
+import (
+ "unsafe"
+)
+
+type NodeDeviceEventID int
+
+const (
+ NODE_DEVICE_EVENT_ID_LIFECYCLE = NodeDeviceEventID(C.VIR_NODE_DEVICE_EVENT_ID_LIFECYCLE)
+ NODE_DEVICE_EVENT_ID_UPDATE = NodeDeviceEventID(C.VIR_NODE_DEVICE_EVENT_ID_UPDATE)
+)
+
+type NodeDeviceEventLifecycleType int
+
+const (
+ NODE_DEVICE_EVENT_CREATED = NodeDeviceEventLifecycleType(C.VIR_NODE_DEVICE_EVENT_CREATED)
+ NODE_DEVICE_EVENT_DELETED = NodeDeviceEventLifecycleType(C.VIR_NODE_DEVICE_EVENT_DELETED)
+)
+
+type NodeDevice struct {
+ ptr C.virNodeDevicePtr
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceFree
+func (n *NodeDevice) Free() error {
+ var err C.virError
+ ret := C.virNodeDeviceFreeWrapper(n.ptr, &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceRef
+func (c *NodeDevice) Ref() error {
+ var err C.virError
+ ret := C.virNodeDeviceRefWrapper(c.ptr, &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceDestroy
+func (n *NodeDevice) Destroy() error {
+ var err C.virError
+ result := C.virNodeDeviceDestroyWrapper(n.ptr, &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceReset
+func (n *NodeDevice) Reset() error {
+ var err C.virError
+ result := C.virNodeDeviceResetWrapper(n.ptr, &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceDettach
+func (n *NodeDevice) Detach() error {
+ var err C.virError
+ result := C.virNodeDeviceDettachWrapper(n.ptr, &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceDetachFlags
+func (n *NodeDevice) DetachFlags(driverName string, flags uint32) error {
+ cDriverName := C.CString(driverName)
+ defer C.free(unsafe.Pointer(cDriverName))
+ var err C.virError
+ result := C.virNodeDeviceDetachFlagsWrapper(n.ptr, cDriverName, C.uint(flags), &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceReAttach
+func (n *NodeDevice) ReAttach() error {
+ var err C.virError
+ result := C.virNodeDeviceReAttachWrapper(n.ptr, &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceGetName
+func (n *NodeDevice) GetName() (string, error) {
+ var err C.virError
+ name := C.virNodeDeviceGetNameWrapper(n.ptr, &err)
+ if name == nil {
+ return "", makeError(&err)
+ }
+ return C.GoString(name), nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceGetXMLDesc
+func (n *NodeDevice) GetXMLDesc(flags uint32) (string, error) {
+ var err C.virError
+ result := C.virNodeDeviceGetXMLDescWrapper(n.ptr, C.uint(flags), &err)
+ if result == nil {
+ return "", makeError(&err)
+ }
+ xml := C.GoString(result)
+ C.free(unsafe.Pointer(result))
+ return xml, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceGetParent
+func (n *NodeDevice) GetParent() (string, error) {
+ var err C.virError
+ result := C.virNodeDeviceGetParentWrapper(n.ptr, &err)
+ if result == nil {
+ return "", makeError(&err)
+ }
+ defer C.free(unsafe.Pointer(result))
+ return C.GoString(result), nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceNumOfCaps
+func (p *NodeDevice) NumOfCaps() (int, error) {
+ var err C.virError
+ result := int(C.virNodeDeviceNumOfCapsWrapper(p.ptr, &err))
+ if result == -1 {
+ return 0, makeError(&err)
+ }
+ return result, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceListCaps
+func (p *NodeDevice) ListCaps() ([]string, error) {
+ const maxCaps = 1024
+ var names [maxCaps](*C.char)
+ namesPtr := unsafe.Pointer(&names)
+ var err C.virError
+ numCaps := C.virNodeDeviceListCapsWrapper(
+ p.ptr,
+ (**C.char)(namesPtr),
+ maxCaps, &err)
+ if numCaps == -1 {
+ return nil, makeError(&err)
+ }
+ goNames := make([]string, numCaps)
+ for k := 0; k < int(numCaps); k++ {
+ goNames[k] = C.GoString(names[k])
+ C.free(unsafe.Pointer(names[k]))
+ }
+ return goNames, nil
+}
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/node_device_compat.h b/src/dma/vendor/github.com/libvirt/libvirt-go/node_device_compat.h
new file mode 100644
index 00000000..32020397
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/node_device_compat.h
@@ -0,0 +1,55 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+#ifndef LIBVIRT_GO_NODE_DEVICE_COMPAT_H__
+#define LIBVIRT_GO_NODE_DEVICE_COMPAT_H__
+
+/* 2.2.0 */
+
+#ifndef VIR_NODE_DEVICE_EVENT_ID_LIFECYCLE
+#define VIR_NODE_DEVICE_EVENT_ID_LIFECYCLE 0
+#endif
+
+#ifndef VIR_NODE_DEVICE_EVENT_ID_UPDATE
+#define VIR_NODE_DEVICE_EVENT_ID_UPDATE 1
+#endif
+
+#ifndef VIR_NODE_DEVICE_EVENT_CREATED
+#define VIR_NODE_DEVICE_EVENT_CREATED 0
+#endif
+
+#ifndef VIR_NODE_DEVICE_EVENT_DELETED
+#define VIR_NODE_DEVICE_EVENT_DELETED 1
+#endif
+
+#if LIBVIR_VERSION_NUMBER < 2002000
+typedef void (*virConnectNodeDeviceEventGenericCallback)(virConnectPtr conn,
+ virNodeDevicePtr dev,
+ void *opaque);
+#endif
+
+
+#endif /* LIBVIRT_GO_NODE_DEVICE_COMPAT_H__ */
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/node_device_events.go b/src/dma/vendor/github.com/libvirt/libvirt-go/node_device_events.go
new file mode 100644
index 00000000..7920a424
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/node_device_events.go
@@ -0,0 +1,156 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+package libvirt
+
+import (
+ "fmt"
+ "unsafe"
+)
+
+/*
+#cgo pkg-config: libvirt
+#include "node_device_events_wrapper.h"
+*/
+import "C"
+
+type NodeDeviceEventGenericCallback func(c *Connect, d *NodeDevice)
+
+type NodeDeviceEventLifecycle struct {
+ Event NodeDeviceEventLifecycleType
+ // TODO: we can make Detail typesafe somehow ?
+ Detail int
+}
+
+type NodeDeviceEventLifecycleCallback func(c *Connect, n *NodeDevice, event *NodeDeviceEventLifecycle)
+
+//export nodeDeviceEventLifecycleCallback
+func nodeDeviceEventLifecycleCallback(c C.virConnectPtr, s C.virNodeDevicePtr,
+ event int, detail int,
+ goCallbackId int) {
+
+ node_device := &NodeDevice{ptr: s}
+ connection := &Connect{ptr: c}
+
+ eventDetails := &NodeDeviceEventLifecycle{
+ Event: NodeDeviceEventLifecycleType(event),
+ Detail: detail,
+ }
+
+ callbackFunc := getCallbackId(goCallbackId)
+ callback, ok := callbackFunc.(NodeDeviceEventLifecycleCallback)
+ if !ok {
+ panic("Inappropriate callback type called")
+ }
+ callback(connection, node_device, eventDetails)
+}
+
+//export nodeDeviceEventGenericCallback
+func nodeDeviceEventGenericCallback(c C.virConnectPtr, d C.virNodeDevicePtr,
+ goCallbackId int) {
+
+ node_device := &NodeDevice{ptr: d}
+ connection := &Connect{ptr: c}
+
+ callbackFunc := getCallbackId(goCallbackId)
+ callback, ok := callbackFunc.(NodeDeviceEventGenericCallback)
+ if !ok {
+ panic("Inappropriate callback type called")
+ }
+ callback(connection, node_device)
+}
+
+func (c *Connect) NodeDeviceEventLifecycleRegister(device *NodeDevice, callback NodeDeviceEventLifecycleCallback) (int, error) {
+ if C.LIBVIR_VERSION_NUMBER < 2002000 {
+ return 0, makeNotImplementedError("virConnectNodeDeviceEventRegisterAny")
+ }
+ goCallBackId := registerCallbackId(callback)
+
+ callbackPtr := unsafe.Pointer(C.nodeDeviceEventLifecycleCallbackHelper)
+ var cdevice C.virNodeDevicePtr
+ if device != nil {
+ cdevice = device.ptr
+ }
+ var err C.virError
+ ret := C.virConnectNodeDeviceEventRegisterAnyWrapper(c.ptr, cdevice,
+ C.VIR_NODE_DEVICE_EVENT_ID_LIFECYCLE,
+ C.virConnectNodeDeviceEventGenericCallback(callbackPtr),
+ C.long(goCallBackId), &err)
+ if ret == -1 {
+ freeCallbackId(goCallBackId)
+ return 0, makeError(&err)
+ }
+ return int(ret), nil
+}
+
+func (c *Connect) NodeDeviceEventUpdateRegister(device *NodeDevice, callback NodeDeviceEventGenericCallback) (int, error) {
+ goCallBackId := registerCallbackId(callback)
+
+ callbackPtr := unsafe.Pointer(C.nodeDeviceEventGenericCallbackHelper)
+ var cdevice C.virNodeDevicePtr
+ if device != nil {
+ cdevice = device.ptr
+ }
+ var err C.virError
+ ret := C.virConnectNodeDeviceEventRegisterAnyWrapper(c.ptr, cdevice,
+ C.VIR_NODE_DEVICE_EVENT_ID_UPDATE,
+ C.virConnectNodeDeviceEventGenericCallback(callbackPtr),
+ C.long(goCallBackId), &err)
+ if ret == -1 {
+ freeCallbackId(goCallBackId)
+ return 0, makeError(&err)
+ }
+ return int(ret), nil
+}
+
+func (c *Connect) NodeDeviceEventDeregister(callbackId int) error {
+ if C.LIBVIR_VERSION_NUMBER < 2002000 {
+ return makeNotImplementedError("virConnectNodeDeviceEventDeregisterAny")
+ }
+ // Deregister the callback
+ var err C.virError
+ ret := int(C.virConnectNodeDeviceEventDeregisterAnyWrapper(c.ptr, C.int(callbackId), &err))
+ if ret < 0 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+func (e NodeDeviceEventLifecycle) String() string {
+ var event string
+ switch e.Event {
+ case NODE_DEVICE_EVENT_CREATED:
+ event = "created"
+
+ case NODE_DEVICE_EVENT_DELETED:
+ event = "deleted"
+
+ default:
+ event = "unknown"
+ }
+
+ return fmt.Sprintf("NodeDevice event=%q", event)
+}
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/node_device_events_wrapper.go b/src/dma/vendor/github.com/libvirt/libvirt-go/node_device_events_wrapper.go
new file mode 100644
index 00000000..8b2e624e
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/node_device_events_wrapper.go
@@ -0,0 +1,88 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+package libvirt
+
+/*
+#cgo pkg-config: libvirt
+#include <assert.h>
+#include <stdint.h>
+#include "node_device_events_wrapper.h"
+#include "callbacks_wrapper.h"
+
+extern void nodeDeviceEventLifecycleCallback(virConnectPtr, virNodeDevicePtr, int, int, int);
+void nodeDeviceEventLifecycleCallbackHelper(virConnectPtr c, virNodeDevicePtr d,
+ int event, int detail, void *data)
+{
+ nodeDeviceEventLifecycleCallback(c, d, event, detail, (int)(intptr_t)data);
+}
+
+extern void nodeDeviceEventGenericCallback(virConnectPtr, virNodeDevicePtr, int);
+void nodeDeviceEventGenericCallbackHelper(virConnectPtr c, virNodeDevicePtr d, void *data)
+{
+ nodeDeviceEventGenericCallback(c, d, (int)(intptr_t)data);
+}
+
+
+int
+virConnectNodeDeviceEventRegisterAnyWrapper(virConnectPtr c,
+ virNodeDevicePtr d,
+ int eventID,
+ virConnectNodeDeviceEventGenericCallback cb,
+ long goCallbackId,
+ virErrorPtr err)
+{
+ void* id = (void*)goCallbackId;
+#if LIBVIR_VERSION_NUMBER < 2002000
+ assert(0); // Caller should have checked version
+#else
+ int ret = virConnectNodeDeviceEventRegisterAny(c, d, eventID, cb, id, freeGoCallbackHelper);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+int
+virConnectNodeDeviceEventDeregisterAnyWrapper(virConnectPtr conn,
+ int callbackID,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 2002000
+ assert(0); // Caller should have checked version
+#else
+ int ret = virConnectNodeDeviceEventDeregisterAny(conn, callbackID);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+*/
+import "C"
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/node_device_events_wrapper.h b/src/dma/vendor/github.com/libvirt/libvirt-go/node_device_events_wrapper.h
new file mode 100644
index 00000000..fb691d2c
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/node_device_events_wrapper.h
@@ -0,0 +1,60 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+#ifndef LIBVIRT_GO_NODE_DEVICE_EVENTS_WRAPPER_H__
+#define LIBVIRT_GO_NODE_DEVICE_EVENTS_WRAPPER_H__
+
+#include <libvirt/libvirt.h>
+#include <libvirt/virterror.h>
+#include "node_device_compat.h"
+
+void
+nodeDeviceEventLifecycleCallbackHelper(virConnectPtr c,
+ virNodeDevicePtr d,
+ int event,
+ int detail,
+ void* data);
+
+void
+nodeDeviceEventGenericCallbackHelper(virConnectPtr c,
+ virNodeDevicePtr d,
+ void* data);
+
+int
+virConnectNodeDeviceEventRegisterAnyWrapper(virConnectPtr c,
+ virNodeDevicePtr d,
+ int eventID,
+ virConnectNodeDeviceEventGenericCallback cb,
+ long goCallbackId,
+ virErrorPtr err);
+
+int
+virConnectNodeDeviceEventDeregisterAnyWrapper(virConnectPtr conn,
+ int callbackID,
+ virErrorPtr err);
+
+
+#endif /* LIBVIRT_GO_NODE_DEVICE_EVENTS_WRAPPER_H__ */
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/node_device_wrapper.go b/src/dma/vendor/github.com/libvirt/libvirt-go/node_device_wrapper.go
new file mode 100644
index 00000000..c4e173a3
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/node_device_wrapper.go
@@ -0,0 +1,184 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (C) 2018 Red Hat, Inc.
+ *
+ */
+
+package libvirt
+
+/*
+#cgo pkg-config: libvirt
+#include <assert.h>
+#include "node_device_wrapper.h"
+
+
+int
+virNodeDeviceDestroyWrapper(virNodeDevicePtr dev,
+ virErrorPtr err)
+{
+ int ret = virNodeDeviceDestroy(dev);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virNodeDeviceDetachFlagsWrapper(virNodeDevicePtr dev,
+ const char *driverName,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virNodeDeviceDetachFlags(dev, driverName, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virNodeDeviceDettachWrapper(virNodeDevicePtr dev,
+ virErrorPtr err)
+{
+ int ret = virNodeDeviceDettach(dev);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virNodeDeviceFreeWrapper(virNodeDevicePtr dev,
+ virErrorPtr err)
+{
+ int ret = virNodeDeviceFree(dev);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+const char *
+virNodeDeviceGetNameWrapper(virNodeDevicePtr dev,
+ virErrorPtr err)
+{
+ const char * ret = virNodeDeviceGetName(dev);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+const char *
+virNodeDeviceGetParentWrapper(virNodeDevicePtr dev,
+ virErrorPtr err)
+{
+ const char * ret = virNodeDeviceGetParent(dev);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+char *
+virNodeDeviceGetXMLDescWrapper(virNodeDevicePtr dev,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ char * ret = virNodeDeviceGetXMLDesc(dev, flags);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virNodeDeviceListCapsWrapper(virNodeDevicePtr dev,
+ char ** const names,
+ int maxnames,
+ virErrorPtr err)
+{
+ int ret = virNodeDeviceListCaps(dev, names, maxnames);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virNodeDeviceNumOfCapsWrapper(virNodeDevicePtr dev,
+ virErrorPtr err)
+{
+ int ret = virNodeDeviceNumOfCaps(dev);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virNodeDeviceReAttachWrapper(virNodeDevicePtr dev,
+ virErrorPtr err)
+{
+ int ret = virNodeDeviceReAttach(dev);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virNodeDeviceRefWrapper(virNodeDevicePtr dev,
+ virErrorPtr err)
+{
+ int ret = virNodeDeviceRef(dev);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virNodeDeviceResetWrapper(virNodeDevicePtr dev,
+ virErrorPtr err)
+{
+ int ret = virNodeDeviceReset(dev);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+*/
+import "C"
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/node_device_wrapper.h b/src/dma/vendor/github.com/libvirt/libvirt-go/node_device_wrapper.h
new file mode 100644
index 00000000..7670415c
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/node_device_wrapper.h
@@ -0,0 +1,88 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (C) 2018 Red Hat, Inc.
+ *
+ */
+
+#ifndef LIBVIRT_GO_NODE_DEVICE_WRAPPER_H__
+#define LIBVIRT_GO_NODE_DEVICE_WRAPPER_H__
+
+#include <libvirt/libvirt.h>
+#include <libvirt/virterror.h>
+#include "node_device_compat.h"
+
+
+int
+virNodeDeviceDestroyWrapper(virNodeDevicePtr dev,
+ virErrorPtr err);
+
+int
+virNodeDeviceDetachFlagsWrapper(virNodeDevicePtr dev,
+ const char *driverName,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virNodeDeviceDettachWrapper(virNodeDevicePtr dev,
+ virErrorPtr err);
+
+int
+virNodeDeviceFreeWrapper(virNodeDevicePtr dev,
+ virErrorPtr err);
+
+const char *
+virNodeDeviceGetNameWrapper(virNodeDevicePtr dev,
+ virErrorPtr err);
+
+const char *
+virNodeDeviceGetParentWrapper(virNodeDevicePtr dev,
+ virErrorPtr err);
+
+char *
+virNodeDeviceGetXMLDescWrapper(virNodeDevicePtr dev,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virNodeDeviceListCapsWrapper(virNodeDevicePtr dev,
+ char **const names,
+ int maxnames,
+ virErrorPtr err);
+
+int
+virNodeDeviceNumOfCapsWrapper(virNodeDevicePtr dev,
+ virErrorPtr err);
+
+int
+virNodeDeviceReAttachWrapper(virNodeDevicePtr dev,
+ virErrorPtr err);
+
+int
+virNodeDeviceRefWrapper(virNodeDevicePtr dev,
+ virErrorPtr err);
+
+int
+virNodeDeviceResetWrapper(virNodeDevicePtr dev,
+ virErrorPtr err);
+
+
+#endif /* LIBVIRT_GO_NODE_DEVICE_WRAPPER_H__ */
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/nwfilter.go b/src/dma/vendor/github.com/libvirt/libvirt-go/nwfilter.go
new file mode 100644
index 00000000..0b55c412
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/nwfilter.go
@@ -0,0 +1,118 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+package libvirt
+
+/*
+#cgo pkg-config: libvirt
+#include <stdlib.h>
+#include "nwfilter_wrapper.h"
+*/
+import "C"
+
+import (
+ "unsafe"
+)
+
+type NWFilter struct {
+ ptr C.virNWFilterPtr
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-nwfilter.html#virNWFilterFree
+func (f *NWFilter) Free() error {
+ var err C.virError
+ ret := C.virNWFilterFreeWrapper(f.ptr, &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-nwfilter.html#virNWFilterRef
+func (c *NWFilter) Ref() error {
+ var err C.virError
+ ret := C.virNWFilterRefWrapper(c.ptr, &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-nwfilter.html#virNWFilterGetName
+func (f *NWFilter) GetName() (string, error) {
+ var err C.virError
+ name := C.virNWFilterGetNameWrapper(f.ptr, &err)
+ if name == nil {
+ return "", makeError(&err)
+ }
+ return C.GoString(name), nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-nwfilter.html#virNWFilterUndefine
+func (f *NWFilter) Undefine() error {
+ var err C.virError
+ result := C.virNWFilterUndefineWrapper(f.ptr, &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-nwfilter.html#virNWFilterGetUUID
+func (f *NWFilter) GetUUID() ([]byte, error) {
+ var cUuid [C.VIR_UUID_BUFLEN](byte)
+ cuidPtr := unsafe.Pointer(&cUuid)
+ var err C.virError
+ result := C.virNWFilterGetUUIDWrapper(f.ptr, (*C.uchar)(cuidPtr), &err)
+ if result != 0 {
+ return []byte{}, makeError(&err)
+ }
+ return C.GoBytes(cuidPtr, C.VIR_UUID_BUFLEN), nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-nwfilter.html#virNWFilterGetUUIDString
+func (f *NWFilter) GetUUIDString() (string, error) {
+ var cUuid [C.VIR_UUID_STRING_BUFLEN](C.char)
+ cuidPtr := unsafe.Pointer(&cUuid)
+ var err C.virError
+ result := C.virNWFilterGetUUIDStringWrapper(f.ptr, (*C.char)(cuidPtr), &err)
+ if result != 0 {
+ return "", makeError(&err)
+ }
+ return C.GoString((*C.char)(cuidPtr)), nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-nwfilter.html#virNWFilterGetXMLDesc
+func (f *NWFilter) GetXMLDesc(flags uint32) (string, error) {
+ var err C.virError
+ result := C.virNWFilterGetXMLDescWrapper(f.ptr, C.uint(flags), &err)
+ if result == nil {
+ return "", makeError(&err)
+ }
+ xml := C.GoString(result)
+ C.free(unsafe.Pointer(result))
+ return xml, nil
+}
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/nwfilter_binding.go b/src/dma/vendor/github.com/libvirt/libvirt-go/nwfilter_binding.go
new file mode 100644
index 00000000..e36c1de2
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/nwfilter_binding.go
@@ -0,0 +1,125 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (C) 2018 Red Hat, Inc.
+ *
+ */
+
+package libvirt
+
+/*
+#cgo pkg-config: libvirt
+#include <stdlib.h>
+#include "nwfilter_binding_wrapper.h"
+*/
+import "C"
+
+import (
+ "unsafe"
+)
+
+type NWFilterBinding struct {
+ ptr C.virNWFilterBindingPtr
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-nwfilter.html#virNWFilterBindingFree
+func (f *NWFilterBinding) Free() error {
+ if C.LIBVIR_VERSION_NUMBER < 4005000 {
+ return makeNotImplementedError("virNWFilterBindingFree")
+ }
+ var err C.virError
+ ret := C.virNWFilterBindingFreeWrapper(f.ptr, &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-nwfilter.html#virNWFilterBindingRef
+func (c *NWFilterBinding) Ref() error {
+ if C.LIBVIR_VERSION_NUMBER < 4005000 {
+ return makeNotImplementedError("virNWFilterBindingRef")
+ }
+ var err C.virError
+ ret := C.virNWFilterBindingRefWrapper(c.ptr, &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-nwfilter.html#virNWFilterBindingDelete
+func (f *NWFilterBinding) Delete() error {
+ if C.LIBVIR_VERSION_NUMBER < 4005000 {
+ return makeNotImplementedError("virNWFilterBindingDelete")
+ }
+ var err C.virError
+ result := C.virNWFilterBindingDeleteWrapper(f.ptr, &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-nwfilter.html#virNWFilterBindingGetPortDev
+func (f *NWFilterBinding) GetPortDev() (string, error) {
+ if C.LIBVIR_VERSION_NUMBER < 4005000 {
+ return "", makeNotImplementedError("virNWFilterBindingGetPortDev")
+ }
+ var err C.virError
+ result := C.virNWFilterBindingGetPortDevWrapper(f.ptr, &err)
+ if result == nil {
+ return "", makeError(&err)
+ }
+ name := C.GoString(result)
+ C.free(unsafe.Pointer(result))
+ return name, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-nwfilter.html#virNWFilterBindingGetFilterName
+func (f *NWFilterBinding) GetFilterName() (string, error) {
+ if C.LIBVIR_VERSION_NUMBER < 4005000 {
+ return "", makeNotImplementedError("virNWFilterBindingGetFilterName")
+ }
+ var err C.virError
+ result := C.virNWFilterBindingGetFilterNameWrapper(f.ptr, &err)
+ if result == nil {
+ return "", makeError(&err)
+ }
+ name := C.GoString(result)
+ C.free(unsafe.Pointer(result))
+ return name, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-nwfilter.html#virNWFilterBindingGetXMLDesc
+func (f *NWFilterBinding) GetXMLDesc(flags uint32) (string, error) {
+ if C.LIBVIR_VERSION_NUMBER < 4005000 {
+ return "", makeNotImplementedError("virNWFilterBindingGetXMLDesc")
+ }
+ var err C.virError
+ result := C.virNWFilterBindingGetXMLDescWrapper(f.ptr, C.uint(flags), &err)
+ if result == nil {
+ return "", makeError(&err)
+ }
+ xml := C.GoString(result)
+ C.free(unsafe.Pointer(result))
+ return xml, nil
+}
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/nwfilter_binding_compat.h b/src/dma/vendor/github.com/libvirt/libvirt-go/nwfilter_binding_compat.h
new file mode 100644
index 00000000..1d6fd161
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/nwfilter_binding_compat.h
@@ -0,0 +1,33 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (C) 2018 Red Hat, Inc.
+ *
+ */
+
+#ifndef LIBVIRT_GO_NWFILTER_BINDING_COMPAT_H__
+#define LIBVIRT_GO_NWFILTER_BINDING_COMPAT_H__
+
+#if LIBVIR_VERSION_NUMBER < 4005000
+typedef struct _virNWFilterBinding *virNWFilterBindingPtr;
+#endif
+
+#endif /* LIBVIRT_GO_NWFILTER_BINDING_COMPAT_H__ */
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/nwfilter_binding_wrapper.go b/src/dma/vendor/github.com/libvirt/libvirt-go/nwfilter_binding_wrapper.go
new file mode 100644
index 00000000..b0950b5d
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/nwfilter_binding_wrapper.go
@@ -0,0 +1,132 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (C) 2018 Red Hat, Inc.
+ *
+ */
+
+package libvirt
+
+/*
+#cgo pkg-config: libvirt
+#include <assert.h>
+#include "nwfilter_binding_wrapper.h"
+
+
+int
+virNWFilterBindingDeleteWrapper(virNWFilterBindingPtr binding,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 4005000
+ assert(0); // Caller should have checked version
+#else
+ int ret = virNWFilterBindingDelete(binding);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+int
+virNWFilterBindingFreeWrapper(virNWFilterBindingPtr binding,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 4005000
+ assert(0); // Caller should have checked version
+#else
+ int ret = virNWFilterBindingFree(binding);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+const char *
+virNWFilterBindingGetFilterNameWrapper(virNWFilterBindingPtr binding,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 4005000
+ assert(0); // Caller should have checked version
+#else
+ const char * ret = virNWFilterBindingGetFilterName(binding);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+const char *
+virNWFilterBindingGetPortDevWrapper(virNWFilterBindingPtr binding,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 4005000
+ assert(0); // Caller should have checked version
+#else
+ const char * ret = virNWFilterBindingGetPortDev(binding);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+char *
+virNWFilterBindingGetXMLDescWrapper(virNWFilterBindingPtr binding,
+ unsigned int flags,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 4005000
+ assert(0); // Caller should have checked version
+#else
+ char * ret = virNWFilterBindingGetXMLDesc(binding, flags);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+int
+virNWFilterBindingRefWrapper(virNWFilterBindingPtr binding,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 4005000
+ assert(0); // Caller should have checked version
+#else
+ int ret = virNWFilterBindingRef(binding);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+*/
+import "C"
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/nwfilter_binding_wrapper.h b/src/dma/vendor/github.com/libvirt/libvirt-go/nwfilter_binding_wrapper.h
new file mode 100644
index 00000000..0bcbfb70
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/nwfilter_binding_wrapper.h
@@ -0,0 +1,60 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (C) 2018 Red Hat, Inc.
+ *
+ */
+
+#ifndef LIBVIRT_GO_NWFILTER_BINDING_WRAPPER_H__
+#define LIBVIRT_GO_NWFILTER_BINDING_WRAPPER_H__
+
+#include <libvirt/libvirt.h>
+#include <libvirt/virterror.h>
+#include "nwfilter_binding_compat.h"
+
+
+int
+virNWFilterBindingDeleteWrapper(virNWFilterBindingPtr binding,
+ virErrorPtr err);
+
+int
+virNWFilterBindingFreeWrapper(virNWFilterBindingPtr binding,
+ virErrorPtr err);
+
+const char *
+virNWFilterBindingGetFilterNameWrapper(virNWFilterBindingPtr binding,
+ virErrorPtr err);
+
+const char *
+virNWFilterBindingGetPortDevWrapper(virNWFilterBindingPtr binding,
+ virErrorPtr err);
+
+char *
+virNWFilterBindingGetXMLDescWrapper(virNWFilterBindingPtr binding,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virNWFilterBindingRefWrapper(virNWFilterBindingPtr binding,
+ virErrorPtr err);
+
+
+#endif /* LIBVIRT_GO_NWFILTER_BINDING_WRAPPER_H__ */
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/nwfilter_wrapper.go b/src/dma/vendor/github.com/libvirt/libvirt-go/nwfilter_wrapper.go
new file mode 100644
index 00000000..809e5278
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/nwfilter_wrapper.go
@@ -0,0 +1,122 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (C) 2018 Red Hat, Inc.
+ *
+ */
+
+package libvirt
+
+/*
+#cgo pkg-config: libvirt
+#include <assert.h>
+#include "nwfilter_wrapper.h"
+
+
+int
+virNWFilterFreeWrapper(virNWFilterPtr nwfilter,
+ virErrorPtr err)
+{
+ int ret = virNWFilterFree(nwfilter);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+const char *
+virNWFilterGetNameWrapper(virNWFilterPtr nwfilter,
+ virErrorPtr err)
+{
+ const char * ret = virNWFilterGetName(nwfilter);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virNWFilterGetUUIDWrapper(virNWFilterPtr nwfilter,
+ unsigned char *uuid,
+ virErrorPtr err)
+{
+ int ret = virNWFilterGetUUID(nwfilter, uuid);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virNWFilterGetUUIDStringWrapper(virNWFilterPtr nwfilter,
+ char *buf,
+ virErrorPtr err)
+{
+ int ret = virNWFilterGetUUIDString(nwfilter, buf);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+char *
+virNWFilterGetXMLDescWrapper(virNWFilterPtr nwfilter,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ char * ret = virNWFilterGetXMLDesc(nwfilter, flags);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virNWFilterRefWrapper(virNWFilterPtr nwfilter,
+ virErrorPtr err)
+{
+ int ret = virNWFilterRef(nwfilter);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virNWFilterUndefineWrapper(virNWFilterPtr nwfilter,
+ virErrorPtr err)
+{
+ int ret = virNWFilterUndefine(nwfilter);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+*/
+import "C"
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/nwfilter_wrapper.h b/src/dma/vendor/github.com/libvirt/libvirt-go/nwfilter_wrapper.h
new file mode 100644
index 00000000..9a0651cc
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/nwfilter_wrapper.h
@@ -0,0 +1,65 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (C) 2018 Red Hat, Inc.
+ *
+ */
+
+#ifndef LIBVIRT_GO_NWFILTER_WRAPPER_H__
+#define LIBVIRT_GO_NWFILTER_WRAPPER_H__
+
+#include <libvirt/libvirt.h>
+#include <libvirt/virterror.h>
+
+
+int
+virNWFilterFreeWrapper(virNWFilterPtr nwfilter,
+ virErrorPtr err);
+
+const char *
+virNWFilterGetNameWrapper(virNWFilterPtr nwfilter,
+ virErrorPtr err);
+
+int
+virNWFilterGetUUIDWrapper(virNWFilterPtr nwfilter,
+ unsigned char *uuid,
+ virErrorPtr err);
+
+int
+virNWFilterGetUUIDStringWrapper(virNWFilterPtr nwfilter,
+ char *buf,
+ virErrorPtr err);
+
+char *
+virNWFilterGetXMLDescWrapper(virNWFilterPtr nwfilter,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virNWFilterRefWrapper(virNWFilterPtr nwfilter,
+ virErrorPtr err);
+
+int
+virNWFilterUndefineWrapper(virNWFilterPtr nwfilter,
+ virErrorPtr err);
+
+
+#endif /* LIBVIRT_GO_NWFILTER_WRAPPER_H__ */
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/qemu.go b/src/dma/vendor/github.com/libvirt/libvirt-go/qemu.go
new file mode 100644
index 00000000..a2f8507f
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/qemu.go
@@ -0,0 +1,189 @@
+// +build !without_qemu
+
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+package libvirt
+
+/*
+#cgo pkg-config: libvirt
+// Can't rely on pkg-config for libvirt-qemu since it was not
+// installed until 2.6.0 onwards
+#cgo LDFLAGS: -lvirt-qemu
+#include <stdlib.h>
+#include "qemu_wrapper.h"
+*/
+import "C"
+
+import (
+ "unsafe"
+)
+
+/*
+ * QMP has two different kinds of ways to talk to QEMU. One is legacy (HMP,
+ * or 'human' monitor protocol. The default is QMP, which is all-JSON.
+ *
+ * QMP json commands are of the format:
+ * {"execute" : "query-cpus"}
+ *
+ * whereas the same command in 'HMP' would be:
+ * 'info cpus'
+ */
+
+type DomainQemuMonitorCommandFlags int
+
+const (
+ DOMAIN_QEMU_MONITOR_COMMAND_DEFAULT = DomainQemuMonitorCommandFlags(C.VIR_DOMAIN_QEMU_MONITOR_COMMAND_DEFAULT)
+ DOMAIN_QEMU_MONITOR_COMMAND_HMP = DomainQemuMonitorCommandFlags(C.VIR_DOMAIN_QEMU_MONITOR_COMMAND_HMP)
+)
+
+type DomainQemuAgentCommandTimeout int
+
+const (
+ DOMAIN_QEMU_AGENT_COMMAND_MIN = DomainQemuAgentCommandTimeout(C.VIR_DOMAIN_QEMU_AGENT_COMMAND_MIN)
+ DOMAIN_QEMU_AGENT_COMMAND_BLOCK = DomainQemuAgentCommandTimeout(C.VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK)
+ DOMAIN_QEMU_AGENT_COMMAND_DEFAULT = DomainQemuAgentCommandTimeout(C.VIR_DOMAIN_QEMU_AGENT_COMMAND_DEFAULT)
+ DOMAIN_QEMU_AGENT_COMMAND_NOWAIT = DomainQemuAgentCommandTimeout(C.VIR_DOMAIN_QEMU_AGENT_COMMAND_NOWAIT)
+ DOMAIN_QEMU_AGENT_COMMAND_SHUTDOWN = DomainQemuAgentCommandTimeout(C.VIR_DOMAIN_QEMU_AGENT_COMMAND_SHUTDOWN)
+)
+
+type DomainQemuMonitorEventFlags int
+
+const (
+ CONNECT_DOMAIN_QEMU_MONITOR_EVENT_REGISTER_REGEX = DomainQemuMonitorEventFlags(C.VIR_CONNECT_DOMAIN_QEMU_MONITOR_EVENT_REGISTER_REGEX)
+ CONNECT_DOMAIN_QEMU_MONITOR_EVENT_REGISTER_NOCASE = DomainQemuMonitorEventFlags(C.VIR_CONNECT_DOMAIN_QEMU_MONITOR_EVENT_REGISTER_NOCASE)
+)
+
+func (d *Domain) QemuMonitorCommand(command string, flags DomainQemuMonitorCommandFlags) (string, error) {
+ var cResult *C.char
+ cCommand := C.CString(command)
+ defer C.free(unsafe.Pointer(cCommand))
+ var err C.virError
+ result := C.virDomainQemuMonitorCommandWrapper(d.ptr, cCommand, &cResult, C.uint(flags), &err)
+
+ if result != 0 {
+ return "", makeError(&err)
+ }
+
+ rstring := C.GoString(cResult)
+ C.free(unsafe.Pointer(cResult))
+ return rstring, nil
+}
+
+func (d *Domain) QemuAgentCommand(command string, timeout DomainQemuAgentCommandTimeout, flags uint32) (string, error) {
+ cCommand := C.CString(command)
+ defer C.free(unsafe.Pointer(cCommand))
+ var err C.virError
+ result := C.virDomainQemuAgentCommandWrapper(d.ptr, cCommand, C.int(timeout), C.uint(flags), &err)
+
+ if result == nil {
+ return "", makeError(&err)
+ }
+
+ rstring := C.GoString(result)
+ C.free(unsafe.Pointer(result))
+ return rstring, nil
+}
+
+func (c *Connect) DomainQemuAttach(pid uint32, flags uint32) (*Domain, error) {
+ var err C.virError
+ ptr := C.virDomainQemuAttachWrapper(c.ptr, C.uint(pid), C.uint(flags), &err)
+ if ptr == nil {
+ return nil, makeError(&err)
+ }
+ return &Domain{ptr: ptr}, nil
+}
+
+type DomainQemuMonitorEvent struct {
+ Event string
+ Seconds int64
+ Micros uint
+ Details string
+}
+
+type DomainQemuMonitorEventCallback func(c *Connect, d *Domain, event *DomainQemuMonitorEvent)
+
+//export domainQemuMonitorEventCallback
+func domainQemuMonitorEventCallback(c C.virConnectPtr, d C.virDomainPtr,
+ event *C.char, seconds C.longlong, micros C.uint, details *C.char, goCallbackId int) {
+
+ domain := &Domain{ptr: d}
+ connection := &Connect{ptr: c}
+
+ eventDetails := &DomainQemuMonitorEvent{
+ Event: C.GoString(event),
+ Seconds: int64(seconds),
+ Micros: uint(micros),
+ Details: C.GoString(details),
+ }
+
+ callbackFunc := getCallbackId(goCallbackId)
+ callback, ok := callbackFunc.(DomainQemuMonitorEventCallback)
+ if !ok {
+ panic("Inappropriate callback type called")
+ }
+ callback(connection, domain, eventDetails)
+
+}
+
+func (c *Connect) DomainQemuMonitorEventRegister(dom *Domain, event string, callback DomainQemuMonitorEventCallback, flags DomainQemuMonitorEventFlags) (int, error) {
+ if C.LIBVIR_VERSION_NUMBER < 1002003 {
+ return 0, makeNotImplementedError("virConnectDomainQemuMonitorEventRegister")
+ }
+
+ cEvent := C.CString(event)
+ defer C.free(unsafe.Pointer(cEvent))
+ goCallBackId := registerCallbackId(callback)
+
+ var cdom C.virDomainPtr
+ if dom != nil {
+ cdom = dom.ptr
+ }
+ var err C.virError
+ ret := C.virConnectDomainQemuMonitorEventRegisterWrapper(c.ptr, cdom,
+ cEvent,
+ C.long(goCallBackId),
+ C.uint(flags), &err)
+ if ret < 0 {
+ freeCallbackId(goCallBackId)
+ return 0, makeError(&err)
+ }
+ return int(ret), nil
+}
+
+func (c *Connect) DomainQemuEventDeregister(callbackId int) error {
+ if C.LIBVIR_VERSION_NUMBER < 1002003 {
+ return makeNotImplementedError("virConnectDomainQemuMonitorEventDeregister")
+ }
+
+ // Deregister the callback
+ var err C.virError
+ ret := int(C.virConnectDomainQemuMonitorEventDeregisterWrapper(c.ptr, C.int(callbackId), &err))
+ if ret < 0 {
+ return makeError(&err)
+ }
+ return nil
+}
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/qemu_compat.h b/src/dma/vendor/github.com/libvirt/libvirt-go/qemu_compat.h
new file mode 100644
index 00000000..7756d7f8
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/qemu_compat.h
@@ -0,0 +1,57 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+#ifndef LIBVIRT_GO_QEMU_COMPAT_H__
+#define LIBVIRT_GO_QEMU_COMPAT_H__
+
+/* 1.2.3 */
+
+#if LIBVIR_VERSION_NUMBER < 1002003
+typedef void (*virConnectDomainQemuMonitorEventCallback)(virConnectPtr conn,
+ virDomainPtr dom,
+ const char *event,
+ long long seconds,
+ unsigned int micros,
+ const char *details,
+ void *opaque);
+#endif
+
+#ifndef VIR_CONNECT_DOMAIN_QEMU_MONITOR_EVENT_REGISTER_REGEX
+#define VIR_CONNECT_DOMAIN_QEMU_MONITOR_EVENT_REGISTER_REGEX (1 << 0)
+#endif
+
+#ifndef VIR_CONNECT_DOMAIN_QEMU_MONITOR_EVENT_REGISTER_NOCASE
+#define VIR_CONNECT_DOMAIN_QEMU_MONITOR_EVENT_REGISTER_NOCASE (1 << 1)
+#endif
+
+/* 1.2.15 */
+
+#ifndef VIR_DOMAIN_QEMU_AGENT_COMMAND_SHUTDOWN
+#define VIR_DOMAIN_QEMU_AGENT_COMMAND_SHUTDOWN 60
+#endif
+
+
+#endif /* LIBVIRT_GO_QEMU_COMPAT_H__ */
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/qemu_wrapper.go b/src/dma/vendor/github.com/libvirt/libvirt-go/qemu_wrapper.go
new file mode 100644
index 00000000..20089d22
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/qemu_wrapper.go
@@ -0,0 +1,133 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+package libvirt
+
+/*
+#cgo pkg-config: libvirt
+// Can't rely on pkg-config for libvirt-qemu since it was not
+// installed until 2.6.0 onwards
+#cgo LDFLAGS: -lvirt-qemu
+#include <assert.h>
+#include <stdint.h>
+#include "qemu_wrapper.h"
+#include "callbacks_wrapper.h"
+
+
+extern void domainQemuMonitorEventCallback(virConnectPtr, virDomainPtr, const char *, long long, unsigned int, const char *, int);
+void domainQemuMonitorEventCallbackHelper(virConnectPtr c, virDomainPtr d,
+ const char *event, long long secs,
+ unsigned int micros, const char *details, void *data)
+{
+ domainQemuMonitorEventCallback(c, d, event, secs, micros, details, (int)(intptr_t)data);
+}
+
+
+int
+virConnectDomainQemuMonitorEventDeregisterWrapper(virConnectPtr conn,
+ int callbackID,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 1002003
+ assert(0); // Caller should have checked version
+#else
+ int ret = virConnectDomainQemuMonitorEventDeregister(conn, callbackID);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+int
+virConnectDomainQemuMonitorEventRegisterWrapper(virConnectPtr conn,
+ virDomainPtr dom,
+ const char *event,
+ long goCallbackId,
+ unsigned int flags,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 1002003
+ assert(0); // Caller should have checked version
+#else
+ void *id = (void*)goCallbackId;
+ int ret = virConnectDomainQemuMonitorEventRegister(conn, dom, event, domainQemuMonitorEventCallbackHelper,
+ id, freeGoCallbackHelper, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+char *
+virDomainQemuAgentCommandWrapper(virDomainPtr domain,
+ const char *cmd,
+ int timeout,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ char * ret = virDomainQemuAgentCommand(domain, cmd, timeout, flags);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+virDomainPtr
+virDomainQemuAttachWrapper(virConnectPtr conn,
+ unsigned int pid_value,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ virDomainPtr ret = virDomainQemuAttach(conn, pid_value, flags);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virDomainQemuMonitorCommandWrapper(virDomainPtr domain,
+ const char *cmd,
+ char **result,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virDomainQemuMonitorCommand(domain, cmd, result, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+*/
+import "C"
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/qemu_wrapper.h b/src/dma/vendor/github.com/libvirt/libvirt-go/qemu_wrapper.h
new file mode 100644
index 00000000..df389c4f
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/qemu_wrapper.h
@@ -0,0 +1,78 @@
+ /*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+#ifndef LIBVIRT_GO_DOMAIN_EVENTS_WRAPPER_H__
+#define LIBVIRT_GO_DOMAIN_EVENTS_WRAPPER_H__
+
+#include <libvirt/libvirt.h>
+#include <libvirt/libvirt-qemu.h>
+#include <libvirt/virterror.h>
+#include "qemu_compat.h"
+
+void
+domainQemuMonitorEventCallbackHelper(virConnectPtr c,
+ virDomainPtr d,
+ const char *event,
+ long long secs,
+ unsigned int micros,
+ const char *details,
+ void *data);
+
+int
+virConnectDomainQemuMonitorEventDeregisterWrapper(virConnectPtr conn,
+ int callbackID,
+ virErrorPtr err);
+
+int
+virConnectDomainQemuMonitorEventRegisterWrapper(virConnectPtr conn,
+ virDomainPtr dom,
+ const char *event,
+ long goCallbackId,
+ unsigned int flags,
+ virErrorPtr err);
+
+char *
+virDomainQemuAgentCommandWrapper(virDomainPtr domain,
+ const char *cmd,
+ int timeout,
+ unsigned int flags,
+ virErrorPtr err);
+
+virDomainPtr
+virDomainQemuAttachWrapper(virConnectPtr conn,
+ unsigned int pid_value,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virDomainQemuMonitorCommandWrapper(virDomainPtr domain,
+ const char *cmd,
+ char **result,
+ unsigned int flags,
+ virErrorPtr err);
+
+
+#endif /* LIBVIRT_GO_DOMAIN_EVENTS_WRAPPER_H__ */
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/secret.go b/src/dma/vendor/github.com/libvirt/libvirt-go/secret.go
new file mode 100644
index 00000000..c4ef44bd
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/secret.go
@@ -0,0 +1,184 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+package libvirt
+
+/*
+#cgo pkg-config: libvirt
+#include <stdlib.h>
+#include "secret_wrapper.h"
+*/
+import "C"
+
+import (
+ "unsafe"
+)
+
+type SecretUsageType int
+
+const (
+ SECRET_USAGE_TYPE_NONE = SecretUsageType(C.VIR_SECRET_USAGE_TYPE_NONE)
+ SECRET_USAGE_TYPE_VOLUME = SecretUsageType(C.VIR_SECRET_USAGE_TYPE_VOLUME)
+ SECRET_USAGE_TYPE_CEPH = SecretUsageType(C.VIR_SECRET_USAGE_TYPE_CEPH)
+ SECRET_USAGE_TYPE_ISCSI = SecretUsageType(C.VIR_SECRET_USAGE_TYPE_ISCSI)
+ SECRET_USAGE_TYPE_TLS = SecretUsageType(C.VIR_SECRET_USAGE_TYPE_TLS)
+)
+
+type SecretEventLifecycleType int
+
+const (
+ SECRET_EVENT_DEFINED = SecretEventLifecycleType(C.VIR_SECRET_EVENT_DEFINED)
+ SECRET_EVENT_UNDEFINED = SecretEventLifecycleType(C.VIR_SECRET_EVENT_UNDEFINED)
+)
+
+type SecretEventID int
+
+const (
+ SECRET_EVENT_ID_LIFECYCLE = SecretEventID(C.VIR_SECRET_EVENT_ID_LIFECYCLE)
+ SECRET_EVENT_ID_VALUE_CHANGED = SecretEventID(C.VIR_SECRET_EVENT_ID_VALUE_CHANGED)
+)
+
+type Secret struct {
+ ptr C.virSecretPtr
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-secret.html#virSecretFree
+func (s *Secret) Free() error {
+ var err C.virError
+ ret := C.virSecretFreeWrapper(s.ptr, &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-secret.html#virSecretRef
+func (c *Secret) Ref() error {
+ var err C.virError
+ ret := C.virSecretRefWrapper(c.ptr, &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-secret.html#virSecretUndefine
+func (s *Secret) Undefine() error {
+ var err C.virError
+ result := C.virSecretUndefineWrapper(s.ptr, &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-secret.html#virSecretGetUUID
+func (s *Secret) GetUUID() ([]byte, error) {
+ var cUuid [C.VIR_UUID_BUFLEN](byte)
+ cuidPtr := unsafe.Pointer(&cUuid)
+ var err C.virError
+ result := C.virSecretGetUUIDWrapper(s.ptr, (*C.uchar)(cuidPtr), &err)
+ if result != 0 {
+ return []byte{}, makeError(&err)
+ }
+ return C.GoBytes(cuidPtr, C.VIR_UUID_BUFLEN), nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-secret.html#virSecretGetUUIDString
+func (s *Secret) GetUUIDString() (string, error) {
+ var cUuid [C.VIR_UUID_STRING_BUFLEN](C.char)
+ cuidPtr := unsafe.Pointer(&cUuid)
+ var err C.virError
+ result := C.virSecretGetUUIDStringWrapper(s.ptr, (*C.char)(cuidPtr), &err)
+ if result != 0 {
+ return "", makeError(&err)
+ }
+ return C.GoString((*C.char)(cuidPtr)), nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-secret.html#virSecretGetUsageID
+func (s *Secret) GetUsageID() (string, error) {
+ var err C.virError
+ result := C.virSecretGetUsageIDWrapper(s.ptr, &err)
+ if result == nil {
+ return "", makeError(&err)
+ }
+ return C.GoString(result), nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-secret.html#virSecretGetUsageType
+func (s *Secret) GetUsageType() (SecretUsageType, error) {
+ var err C.virError
+ result := SecretUsageType(C.virSecretGetUsageTypeWrapper(s.ptr, &err))
+ if result == -1 {
+ return 0, makeError(&err)
+ }
+ return result, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-secret.html#virSecretGetXMLDesc
+func (s *Secret) GetXMLDesc(flags uint32) (string, error) {
+ var err C.virError
+ result := C.virSecretGetXMLDescWrapper(s.ptr, C.uint(flags), &err)
+ if result == nil {
+ return "", makeError(&err)
+ }
+ xml := C.GoString(result)
+ C.free(unsafe.Pointer(result))
+ return xml, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-secret.html#virSecretGetValue
+func (s *Secret) GetValue(flags uint32) ([]byte, error) {
+ var cvalue_size C.size_t
+
+ var err C.virError
+ cvalue := C.virSecretGetValueWrapper(s.ptr, &cvalue_size, C.uint(flags), &err)
+ if cvalue == nil {
+ return nil, makeError(&err)
+ }
+ defer C.free(unsafe.Pointer(cvalue))
+ ret := C.GoBytes(unsafe.Pointer(cvalue), C.int(cvalue_size))
+ return ret, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-secret.html#virSecretSetValue
+func (s *Secret) SetValue(value []byte, flags uint32) error {
+ cvalue := make([]C.uchar, len(value))
+
+ for i := 0; i < len(value); i++ {
+ cvalue[i] = C.uchar(value[i])
+ }
+
+ var err C.virError
+ result := C.virSecretSetValueWrapper(s.ptr, &cvalue[0], C.size_t(len(value)), C.uint(flags), &err)
+
+ if result == -1 {
+ return makeError(&err)
+ }
+
+ return nil
+}
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/secret_compat.h b/src/dma/vendor/github.com/libvirt/libvirt-go/secret_compat.h
new file mode 100644
index 00000000..ba38c68d
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/secret_compat.h
@@ -0,0 +1,61 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+#ifndef LIBVIRT_GO_SECRET_COMPAT_H__
+#define LIBVIRT_GO_SECRET_COMPAT_H__
+
+/* 3.0.0 */
+
+#ifndef VIR_SECRET_EVENT_DEFINED
+#define VIR_SECRET_EVENT_DEFINED 0
+#endif
+
+#ifndef VIR_SECRET_EVENT_UNDEFINED
+#define VIR_SECRET_EVENT_UNDEFINED 1
+#endif
+
+#ifndef VIR_SECRET_EVENT_ID_LIFECYCLE
+#define VIR_SECRET_EVENT_ID_LIFECYCLE 0
+#endif
+
+#ifndef VIR_SECRET_EVENT_ID_VALUE_CHANGED
+#define VIR_SECRET_EVENT_ID_VALUE_CHANGED 1
+#endif
+
+
+#if LIBVIR_VERSION_NUMBER < 3000000
+typedef void (*virConnectSecretEventGenericCallback)(virConnectPtr conn,
+ virSecretPtr secret,
+ void *opaque);
+#endif
+
+/* 2.2.1 */
+
+#ifndef VIR_SECRET_USAGE_TYPE_TLS
+#define VIR_SECRET_USAGE_TYPE_TLS 4
+#endif
+
+#endif /* LIBVIRT_GO_SECRET_COMPAT_H__ */
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/secret_events.go b/src/dma/vendor/github.com/libvirt/libvirt-go/secret_events.go
new file mode 100644
index 00000000..d928e985
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/secret_events.go
@@ -0,0 +1,159 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+package libvirt
+
+import (
+ "fmt"
+ "unsafe"
+)
+
+/*
+#cgo pkg-config: libvirt
+#include "secret_events_wrapper.h"
+*/
+import "C"
+
+type SecretEventLifecycle struct {
+ Event SecretEventLifecycleType
+ // TODO: we can make Detail typesafe somehow ?
+ Detail int
+}
+
+type SecretEventLifecycleCallback func(c *Connect, n *Secret, event *SecretEventLifecycle)
+
+type SecretEventGenericCallback func(c *Connect, n *Secret)
+
+//export secretEventLifecycleCallback
+func secretEventLifecycleCallback(c C.virConnectPtr, n C.virSecretPtr,
+ event int, detail int,
+ goCallbackId int) {
+
+ secret := &Secret{ptr: n}
+ connection := &Connect{ptr: c}
+
+ eventDetails := &SecretEventLifecycle{
+ Event: SecretEventLifecycleType(event),
+ Detail: detail,
+ }
+
+ callbackFunc := getCallbackId(goCallbackId)
+ callback, ok := callbackFunc.(SecretEventLifecycleCallback)
+ if !ok {
+ panic("Inappropriate callback type called")
+ }
+ callback(connection, secret, eventDetails)
+}
+
+//export secretEventGenericCallback
+func secretEventGenericCallback(c C.virConnectPtr, n C.virSecretPtr,
+ goCallbackId int) {
+
+ secret := &Secret{ptr: n}
+ connection := &Connect{ptr: c}
+
+ callbackFunc := getCallbackId(goCallbackId)
+ callback, ok := callbackFunc.(SecretEventGenericCallback)
+ if !ok {
+ panic("Inappropriate callback type called")
+ }
+ callback(connection, secret)
+}
+
+func (c *Connect) SecretEventLifecycleRegister(secret *Secret, callback SecretEventLifecycleCallback) (int, error) {
+ goCallBackId := registerCallbackId(callback)
+ if C.LIBVIR_VERSION_NUMBER < 3000000 {
+ return 0, makeNotImplementedError("virConnectSecretEventRegisterAny")
+ }
+
+ callbackPtr := unsafe.Pointer(C.secretEventLifecycleCallbackHelper)
+ var csecret C.virSecretPtr
+ if secret != nil {
+ csecret = secret.ptr
+ }
+ var err C.virError
+ ret := C.virConnectSecretEventRegisterAnyWrapper(c.ptr, csecret,
+ C.VIR_SECRET_EVENT_ID_LIFECYCLE,
+ C.virConnectSecretEventGenericCallback(callbackPtr),
+ C.long(goCallBackId), &err)
+ if ret == -1 {
+ freeCallbackId(goCallBackId)
+ return 0, makeError(&err)
+ }
+ return int(ret), nil
+}
+
+func (c *Connect) SecretEventValueChangedRegister(secret *Secret, callback SecretEventGenericCallback) (int, error) {
+ goCallBackId := registerCallbackId(callback)
+ if C.LIBVIR_VERSION_NUMBER < 3000000 {
+ return 0, makeNotImplementedError("virConnectSecretEventRegisterAny")
+ }
+
+ callbackPtr := unsafe.Pointer(C.secretEventGenericCallbackHelper)
+ var csecret C.virSecretPtr
+ if secret != nil {
+ csecret = secret.ptr
+ }
+ var err C.virError
+ ret := C.virConnectSecretEventRegisterAnyWrapper(c.ptr, csecret,
+ C.VIR_SECRET_EVENT_ID_VALUE_CHANGED,
+ C.virConnectSecretEventGenericCallback(callbackPtr),
+ C.long(goCallBackId), &err)
+ if ret == -1 {
+ freeCallbackId(goCallBackId)
+ return 0, makeError(&err)
+ }
+ return int(ret), nil
+}
+
+func (c *Connect) SecretEventDeregister(callbackId int) error {
+ if C.LIBVIR_VERSION_NUMBER < 3000000 {
+ return makeNotImplementedError("virConnectSecretEventDeregisterAny")
+ }
+ // Deregister the callback
+ var err C.virError
+ ret := int(C.virConnectSecretEventDeregisterAnyWrapper(c.ptr, C.int(callbackId), &err))
+ if ret < 0 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+func (e SecretEventLifecycle) String() string {
+ var event string
+ switch e.Event {
+ case SECRET_EVENT_DEFINED:
+ event = "defined"
+
+ case SECRET_EVENT_UNDEFINED:
+ event = "undefined"
+
+ default:
+ event = "unknown"
+ }
+
+ return fmt.Sprintf("Secret event=%q", event)
+}
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/secret_events_wrapper.go b/src/dma/vendor/github.com/libvirt/libvirt-go/secret_events_wrapper.go
new file mode 100644
index 00000000..a543e7f5
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/secret_events_wrapper.go
@@ -0,0 +1,88 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+package libvirt
+
+/*
+#cgo pkg-config: libvirt
+#include <assert.h>
+#include <stdint.h>
+#include "secret_events_wrapper.h"
+#include "callbacks_wrapper.h"
+
+extern void secretEventLifecycleCallback(virConnectPtr, virSecretPtr, int, int, int);
+void secretEventLifecycleCallbackHelper(virConnectPtr c, virSecretPtr d,
+ int event, int detail, void *data)
+{
+ secretEventLifecycleCallback(c, d, event, detail, (int)(intptr_t)data);
+}
+
+extern void secretEventGenericCallback(virConnectPtr, virSecretPtr, int);
+void secretEventGenericCallbackHelper(virConnectPtr c, virSecretPtr d,
+ void *data)
+{
+ secretEventGenericCallback(c, d, (int)(intptr_t)data);
+}
+
+
+int
+virConnectSecretEventRegisterAnyWrapper(virConnectPtr c,
+ virSecretPtr d,
+ int eventID,
+ virConnectSecretEventGenericCallback cb,
+ long goCallbackId,
+ virErrorPtr err)
+{
+ void* id = (void*)goCallbackId;
+#if LIBVIR_VERSION_NUMBER < 3000000
+ assert(0); // Caller should have checked version
+#else
+ int ret = virConnectSecretEventRegisterAny(c, d, eventID, cb, id, freeGoCallbackHelper);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+int virConnectSecretEventDeregisterAnyWrapper(virConnectPtr conn,
+ int callbackID,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 3000000
+ assert(0); // Caller should have checked version
+#else
+ int ret = virConnectSecretEventDeregisterAny(conn, callbackID);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+*/
+import "C"
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/secret_events_wrapper.h b/src/dma/vendor/github.com/libvirt/libvirt-go/secret_events_wrapper.h
new file mode 100644
index 00000000..5101bc0b
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/secret_events_wrapper.h
@@ -0,0 +1,58 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+#ifndef LIBVIRT_GO_SECRET_EVENTS_WRAPPER_H__
+#define LIBVIRT_GO_SECRET_EVENTS_WRAPPER_H__
+
+#include <libvirt/libvirt.h>
+#include <libvirt/virterror.h>
+#include "secret_compat.h"
+
+void
+secretEventLifecycleCallbackHelper(virConnectPtr c,
+ virSecretPtr d,
+ int event,
+ int detail,
+ void* data);
+
+void secretEventGenericCallbackHelper(virConnectPtr c,
+ virSecretPtr d,
+ void* data);
+
+int
+virConnectSecretEventRegisterAnyWrapper(virConnectPtr c,
+ virSecretPtr d,
+ int eventID,
+ virConnectSecretEventGenericCallback cb,
+ long goCallbackId,
+ virErrorPtr err);
+
+int
+virConnectSecretEventDeregisterAnyWrapper(virConnectPtr conn,
+ int callbackID,
+ virErrorPtr err);
+
+#endif /* LIBVIRT_GO_SECRET_EVENTS_WRAPPER_H__ */
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/secret_wrapper.go b/src/dma/vendor/github.com/libvirt/libvirt-go/secret_wrapper.go
new file mode 100644
index 00000000..96f60f6f
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/secret_wrapper.go
@@ -0,0 +1,175 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (C) 2018 Red Hat, Inc.
+ *
+ */
+
+package libvirt
+
+/*
+#cgo pkg-config: libvirt
+#include <assert.h>
+#include "secret_wrapper.h"
+
+
+int
+virSecretFreeWrapper(virSecretPtr secret,
+ virErrorPtr err)
+{
+ int ret = virSecretFree(secret);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+virConnectPtr
+virSecretGetConnectWrapper(virSecretPtr secret,
+ virErrorPtr err)
+{
+ virConnectPtr ret = virSecretGetConnect(secret);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virSecretGetUUIDWrapper(virSecretPtr secret,
+ unsigned char *uuid,
+ virErrorPtr err)
+{
+ int ret = virSecretGetUUID(secret, uuid);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virSecretGetUUIDStringWrapper(virSecretPtr secret,
+ char *buf,
+ virErrorPtr err)
+{
+ int ret = virSecretGetUUIDString(secret, buf);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+const char *
+virSecretGetUsageIDWrapper(virSecretPtr secret,
+ virErrorPtr err)
+{
+ const char * ret = virSecretGetUsageID(secret);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virSecretGetUsageTypeWrapper(virSecretPtr secret,
+ virErrorPtr err)
+{
+ int ret = virSecretGetUsageType(secret);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+unsigned char *
+virSecretGetValueWrapper(virSecretPtr secret,
+ size_t *value_size,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ unsigned char * ret = virSecretGetValue(secret, value_size, flags);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+char *
+virSecretGetXMLDescWrapper(virSecretPtr secret,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ char * ret = virSecretGetXMLDesc(secret, flags);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virSecretRefWrapper(virSecretPtr secret,
+ virErrorPtr err)
+{
+ int ret = virSecretRef(secret);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virSecretSetValueWrapper(virSecretPtr secret,
+ const unsigned char *value,
+ size_t value_size,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virSecretSetValue(secret, value, value_size, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virSecretUndefineWrapper(virSecretPtr secret,
+ virErrorPtr err)
+{
+ int ret = virSecretUndefine(secret);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+*/
+import "C"
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/secret_wrapper.h b/src/dma/vendor/github.com/libvirt/libvirt-go/secret_wrapper.h
new file mode 100644
index 00000000..eca6f0a4
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/secret_wrapper.h
@@ -0,0 +1,86 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (C) 2018 Red Hat, Inc.
+ *
+ */
+
+#ifndef LIBVIRT_GO_SECRET_WRAPPER_H__
+#define LIBVIRT_GO_SECRET_WRAPPER_H__
+
+#include <libvirt/libvirt.h>
+#include <libvirt/virterror.h>
+#include "secret_compat.h"
+
+int
+virSecretFreeWrapper(virSecretPtr secret,
+ virErrorPtr err);
+
+virConnectPtr
+virSecretGetConnectWrapper(virSecretPtr secret,
+ virErrorPtr err);
+
+int
+virSecretGetUUIDWrapper(virSecretPtr secret,
+ unsigned char *uuid,
+ virErrorPtr err);
+
+int
+virSecretGetUUIDStringWrapper(virSecretPtr secret,
+ char *buf,
+ virErrorPtr err);
+
+const char *
+virSecretGetUsageIDWrapper(virSecretPtr secret,
+ virErrorPtr err);
+
+int
+virSecretGetUsageTypeWrapper(virSecretPtr secret,
+ virErrorPtr err);
+
+unsigned char *
+virSecretGetValueWrapper(virSecretPtr secret,
+ size_t *value_size,
+ unsigned int flags,
+ virErrorPtr err);
+
+char *
+virSecretGetXMLDescWrapper(virSecretPtr secret,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virSecretRefWrapper(virSecretPtr secret,
+ virErrorPtr err);
+
+int
+virSecretSetValueWrapper(virSecretPtr secret,
+ const unsigned char *value,
+ size_t value_size,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virSecretUndefineWrapper(virSecretPtr secret,
+ virErrorPtr err);
+
+
+#endif /* LIBVIRT_GO_SECRET_WRAPPER_H__ */
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/storage_pool.go b/src/dma/vendor/github.com/libvirt/libvirt-go/storage_pool.go
new file mode 100644
index 00000000..9bfcc79a
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/storage_pool.go
@@ -0,0 +1,394 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+package libvirt
+
+/*
+#cgo pkg-config: libvirt
+#include <stdlib.h>
+#include "storage_pool_wrapper.h"
+*/
+import "C"
+
+import (
+ "reflect"
+ "unsafe"
+)
+
+type StoragePoolState int
+
+const (
+ STORAGE_POOL_INACTIVE = StoragePoolState(C.VIR_STORAGE_POOL_INACTIVE) // Not running
+ STORAGE_POOL_BUILDING = StoragePoolState(C.VIR_STORAGE_POOL_BUILDING) // Initializing pool,not available
+ STORAGE_POOL_RUNNING = StoragePoolState(C.VIR_STORAGE_POOL_RUNNING) // Running normally
+ STORAGE_POOL_DEGRADED = StoragePoolState(C.VIR_STORAGE_POOL_DEGRADED) // Running degraded
+ STORAGE_POOL_INACCESSIBLE = StoragePoolState(C.VIR_STORAGE_POOL_INACCESSIBLE) // Running,but not accessible
+)
+
+type StoragePoolBuildFlags int
+
+const (
+ STORAGE_POOL_BUILD_NEW = StoragePoolBuildFlags(C.VIR_STORAGE_POOL_BUILD_NEW) // Regular build from scratch
+ STORAGE_POOL_BUILD_REPAIR = StoragePoolBuildFlags(C.VIR_STORAGE_POOL_BUILD_REPAIR) // Repair / reinitialize
+ STORAGE_POOL_BUILD_RESIZE = StoragePoolBuildFlags(C.VIR_STORAGE_POOL_BUILD_RESIZE) // Extend existing pool
+ STORAGE_POOL_BUILD_NO_OVERWRITE = StoragePoolBuildFlags(C.VIR_STORAGE_POOL_BUILD_NO_OVERWRITE) // Do not overwrite existing pool
+ STORAGE_POOL_BUILD_OVERWRITE = StoragePoolBuildFlags(C.VIR_STORAGE_POOL_BUILD_OVERWRITE) // Overwrite data
+)
+
+type StoragePoolCreateFlags int
+
+const (
+ STORAGE_POOL_CREATE_NORMAL = StoragePoolCreateFlags(C.VIR_STORAGE_POOL_CREATE_NORMAL)
+ STORAGE_POOL_CREATE_WITH_BUILD = StoragePoolCreateFlags(C.VIR_STORAGE_POOL_CREATE_WITH_BUILD)
+ STORAGE_POOL_CREATE_WITH_BUILD_OVERWRITE = StoragePoolCreateFlags(C.VIR_STORAGE_POOL_CREATE_WITH_BUILD_OVERWRITE)
+ STORAGE_POOL_CREATE_WITH_BUILD_NO_OVERWRITE = StoragePoolCreateFlags(C.VIR_STORAGE_POOL_CREATE_WITH_BUILD_NO_OVERWRITE)
+)
+
+type StoragePoolDeleteFlags int
+
+const (
+ STORAGE_POOL_DELETE_NORMAL = StoragePoolDeleteFlags(C.VIR_STORAGE_POOL_DELETE_NORMAL)
+ STORAGE_POOL_DELETE_ZEROED = StoragePoolDeleteFlags(C.VIR_STORAGE_POOL_DELETE_ZEROED)
+)
+
+type StoragePoolEventID int
+
+const (
+ STORAGE_POOL_EVENT_ID_LIFECYCLE = StoragePoolEventID(C.VIR_STORAGE_POOL_EVENT_ID_LIFECYCLE)
+ STORAGE_POOL_EVENT_ID_REFRESH = StoragePoolEventID(C.VIR_STORAGE_POOL_EVENT_ID_REFRESH)
+)
+
+type StoragePoolEventLifecycleType int
+
+const (
+ STORAGE_POOL_EVENT_DEFINED = StoragePoolEventLifecycleType(C.VIR_STORAGE_POOL_EVENT_DEFINED)
+ STORAGE_POOL_EVENT_UNDEFINED = StoragePoolEventLifecycleType(C.VIR_STORAGE_POOL_EVENT_UNDEFINED)
+ STORAGE_POOL_EVENT_STARTED = StoragePoolEventLifecycleType(C.VIR_STORAGE_POOL_EVENT_STARTED)
+ STORAGE_POOL_EVENT_STOPPED = StoragePoolEventLifecycleType(C.VIR_STORAGE_POOL_EVENT_STOPPED)
+ STORAGE_POOL_EVENT_CREATED = StoragePoolEventLifecycleType(C.VIR_STORAGE_POOL_EVENT_CREATED)
+ STORAGE_POOL_EVENT_DELETED = StoragePoolEventLifecycleType(C.VIR_STORAGE_POOL_EVENT_DELETED)
+)
+
+type StoragePool struct {
+ ptr C.virStoragePoolPtr
+}
+
+type StoragePoolInfo struct {
+ State StoragePoolState
+ Capacity uint64
+ Allocation uint64
+ Available uint64
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolBuild
+func (p *StoragePool) Build(flags StoragePoolBuildFlags) error {
+ var err C.virError
+ result := C.virStoragePoolBuildWrapper(p.ptr, C.uint(flags), &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolCreate
+func (p *StoragePool) Create(flags StoragePoolCreateFlags) error {
+ var err C.virError
+ result := C.virStoragePoolCreateWrapper(p.ptr, C.uint(flags), &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolDelete
+func (p *StoragePool) Delete(flags StoragePoolDeleteFlags) error {
+ var err C.virError
+ result := C.virStoragePoolDeleteWrapper(p.ptr, C.uint(flags), &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolDestroy
+func (p *StoragePool) Destroy() error {
+ var err C.virError
+ result := C.virStoragePoolDestroyWrapper(p.ptr, &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolFree
+func (p *StoragePool) Free() error {
+ var err C.virError
+ ret := C.virStoragePoolFreeWrapper(p.ptr, &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolRef
+func (c *StoragePool) Ref() error {
+ var err C.virError
+ ret := C.virStoragePoolRefWrapper(c.ptr, &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolGetAutostart
+func (p *StoragePool) GetAutostart() (bool, error) {
+ var out C.int
+ var err C.virError
+ result := C.virStoragePoolGetAutostartWrapper(p.ptr, (*C.int)(unsafe.Pointer(&out)), &err)
+ if result == -1 {
+ return false, makeError(&err)
+ }
+ switch out {
+ case 1:
+ return true, nil
+ default:
+ return false, nil
+ }
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolGetInfo
+func (p *StoragePool) GetInfo() (*StoragePoolInfo, error) {
+ var cinfo C.virStoragePoolInfo
+ var err C.virError
+ result := C.virStoragePoolGetInfoWrapper(p.ptr, &cinfo, &err)
+ if result == -1 {
+ return nil, makeError(&err)
+ }
+ return &StoragePoolInfo{
+ State: StoragePoolState(cinfo.state),
+ Capacity: uint64(cinfo.capacity),
+ Allocation: uint64(cinfo.allocation),
+ Available: uint64(cinfo.available),
+ }, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolGetName
+func (p *StoragePool) GetName() (string, error) {
+ var err C.virError
+ name := C.virStoragePoolGetNameWrapper(p.ptr, &err)
+ if name == nil {
+ return "", makeError(&err)
+ }
+ return C.GoString(name), nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolGetUUID
+func (p *StoragePool) GetUUID() ([]byte, error) {
+ var cUuid [C.VIR_UUID_BUFLEN](byte)
+ cuidPtr := unsafe.Pointer(&cUuid)
+ var err C.virError
+ result := C.virStoragePoolGetUUIDWrapper(p.ptr, (*C.uchar)(cuidPtr), &err)
+ if result != 0 {
+ return []byte{}, makeError(&err)
+ }
+ return C.GoBytes(cuidPtr, C.VIR_UUID_BUFLEN), nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolGetUUIDString
+func (p *StoragePool) GetUUIDString() (string, error) {
+ var cUuid [C.VIR_UUID_STRING_BUFLEN](C.char)
+ cuidPtr := unsafe.Pointer(&cUuid)
+ var err C.virError
+ result := C.virStoragePoolGetUUIDStringWrapper(p.ptr, (*C.char)(cuidPtr), &err)
+ if result != 0 {
+ return "", makeError(&err)
+ }
+ return C.GoString((*C.char)(cuidPtr)), nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolGetXMLDesc
+func (p *StoragePool) GetXMLDesc(flags StorageXMLFlags) (string, error) {
+ var err C.virError
+ result := C.virStoragePoolGetXMLDescWrapper(p.ptr, C.uint(flags), &err)
+ if result == nil {
+ return "", makeError(&err)
+ }
+ xml := C.GoString(result)
+ C.free(unsafe.Pointer(result))
+ return xml, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolIsActive
+func (p *StoragePool) IsActive() (bool, error) {
+ var err C.virError
+ result := C.virStoragePoolIsActiveWrapper(p.ptr, &err)
+ if result == -1 {
+ return false, makeError(&err)
+ }
+ if result == 1 {
+ return true, nil
+ }
+ return false, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolIsPersistent
+func (p *StoragePool) IsPersistent() (bool, error) {
+ var err C.virError
+ result := C.virStoragePoolIsPersistentWrapper(p.ptr, &err)
+ if result == -1 {
+ return false, makeError(&err)
+ }
+ if result == 1 {
+ return true, nil
+ }
+ return false, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolSetAutostart
+func (p *StoragePool) SetAutostart(autostart bool) error {
+ var cAutostart C.int
+ switch autostart {
+ case true:
+ cAutostart = 1
+ default:
+ cAutostart = 0
+ }
+ var err C.virError
+ result := C.virStoragePoolSetAutostartWrapper(p.ptr, cAutostart, &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolRefresh
+func (p *StoragePool) Refresh(flags uint32) error {
+ var err C.virError
+ result := C.virStoragePoolRefreshWrapper(p.ptr, C.uint(flags), &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolUndefine
+func (p *StoragePool) Undefine() error {
+ var err C.virError
+ result := C.virStoragePoolUndefineWrapper(p.ptr, &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolCreateXML
+func (p *StoragePool) StorageVolCreateXML(xmlConfig string, flags StorageVolCreateFlags) (*StorageVol, error) {
+ cXml := C.CString(string(xmlConfig))
+ defer C.free(unsafe.Pointer(cXml))
+ var err C.virError
+ ptr := C.virStorageVolCreateXMLWrapper(p.ptr, cXml, C.uint(flags), &err)
+ if ptr == nil {
+ return nil, makeError(&err)
+ }
+ return &StorageVol{ptr: ptr}, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolCreateXMLFrom
+func (p *StoragePool) StorageVolCreateXMLFrom(xmlConfig string, clonevol *StorageVol, flags StorageVolCreateFlags) (*StorageVol, error) {
+ cXml := C.CString(string(xmlConfig))
+ defer C.free(unsafe.Pointer(cXml))
+ var err C.virError
+ ptr := C.virStorageVolCreateXMLFromWrapper(p.ptr, cXml, clonevol.ptr, C.uint(flags), &err)
+ if ptr == nil {
+ return nil, makeError(&err)
+ }
+ return &StorageVol{ptr: ptr}, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolLookupByName
+func (p *StoragePool) LookupStorageVolByName(name string) (*StorageVol, error) {
+ cName := C.CString(name)
+ defer C.free(unsafe.Pointer(cName))
+ var err C.virError
+ ptr := C.virStorageVolLookupByNameWrapper(p.ptr, cName, &err)
+ if ptr == nil {
+ return nil, makeError(&err)
+ }
+ return &StorageVol{ptr: ptr}, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolNumOfVolumes
+func (p *StoragePool) NumOfStorageVolumes() (int, error) {
+ var err C.virError
+ result := int(C.virStoragePoolNumOfVolumesWrapper(p.ptr, &err))
+ if result == -1 {
+ return 0, makeError(&err)
+ }
+ return result, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolListVolumes
+func (p *StoragePool) ListStorageVolumes() ([]string, error) {
+ const maxVols = 1024
+ var names [maxVols](*C.char)
+ namesPtr := unsafe.Pointer(&names)
+ var err C.virError
+ numStorageVols := C.virStoragePoolListVolumesWrapper(
+ p.ptr,
+ (**C.char)(namesPtr),
+ maxVols, &err)
+ if numStorageVols == -1 {
+ return nil, makeError(&err)
+ }
+ goNames := make([]string, numStorageVols)
+ for k := 0; k < int(numStorageVols); k++ {
+ goNames[k] = C.GoString(names[k])
+ C.free(unsafe.Pointer(names[k]))
+ }
+ return goNames, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolListAllVolumes
+func (p *StoragePool) ListAllStorageVolumes(flags uint32) ([]StorageVol, error) {
+ var cList *C.virStorageVolPtr
+ var err C.virError
+ numVols := C.virStoragePoolListAllVolumesWrapper(p.ptr, (**C.virStorageVolPtr)(&cList), C.uint(flags), &err)
+ if numVols == -1 {
+ return nil, makeError(&err)
+ }
+ hdr := reflect.SliceHeader{
+ Data: uintptr(unsafe.Pointer(cList)),
+ Len: int(numVols),
+ Cap: int(numVols),
+ }
+ var pools []StorageVol
+ slice := *(*[]C.virStorageVolPtr)(unsafe.Pointer(&hdr))
+ for _, ptr := range slice {
+ pools = append(pools, StorageVol{ptr})
+ }
+ C.free(unsafe.Pointer(cList))
+ return pools, nil
+}
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/storage_pool_compat.h b/src/dma/vendor/github.com/libvirt/libvirt-go/storage_pool_compat.h
new file mode 100644
index 00000000..4df1a0d7
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/storage_pool_compat.h
@@ -0,0 +1,92 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+#ifndef LIBVIRT_GO_STORAGE_POOL_COMPAT_H__
+#define LIBVIRT_GO_STORAGE_POOL_COMPAT_H__
+
+/* 1.3.1 */
+
+#ifndef VIR_STORAGE_POOL_CREATE_NORMAL
+#define VIR_STORAGE_POOL_CREATE_NORMAL 0
+#endif
+
+#ifndef VIR_STORAGE_POOL_CREATE_WITH_BUILD
+#define VIR_STORAGE_POOL_CREATE_WITH_BUILD 1 << 0
+#endif
+
+#ifndef VIR_STORAGE_POOL_CREATE_WITH_BUILD_OVERWRITE
+#define VIR_STORAGE_POOL_CREATE_WITH_BUILD_OVERWRITE 1 << 1
+#endif
+
+#ifndef VIR_STORAGE_POOL_CREATE_WITH_BUILD_NO_OVERWRITE
+#define VIR_STORAGE_POOL_CREATE_WITH_BUILD_NO_OVERWRITE 1 << 2
+#endif
+
+
+/* 2.0.0 */
+
+#ifndef VIVIR_STORAGE_POOL_EVENT_DEFINED
+#define VIR_STORAGE_POOL_EVENT_DEFINED 0
+#endif
+
+#ifndef VIR_STORAGE_POOL_EVENT_UNDEFINED
+#define VIR_STORAGE_POOL_EVENT_UNDEFINED 1
+#endif
+
+#ifndef VIR_STORAGE_POOL_EVENT_STARTED
+#define VIR_STORAGE_POOL_EVENT_STARTED 2
+#endif
+
+#ifndef VIR_STORAGE_POOL_EVENT_STOPPED
+#define VIR_STORAGE_POOL_EVENT_STOPPED 3
+#endif
+
+#ifndef VIR_STORAGE_POOL_EVENT_ID_LIFECYCLE
+#define VIR_STORAGE_POOL_EVENT_ID_LIFECYCLE 0
+#endif
+
+#ifndef VIR_STORAGE_POOL_EVENT_ID_REFRESH
+#define VIR_STORAGE_POOL_EVENT_ID_REFRESH 1
+#endif
+
+#if LIBVIR_VERSION_NUMBER < 2000000
+typedef void (*virConnectStoragePoolEventGenericCallback)(virConnectPtr conn,
+ virStoragePoolPtr pool,
+ void *opaque);
+#endif
+
+/* 3.8.0 */
+
+#ifndef VIR_STORAGE_POOL_EVENT_CREATED
+#define VIR_STORAGE_POOL_EVENT_CREATED 4
+#endif
+
+#ifndef VIR_STORAGE_POOL_EVENT_DELETED
+#define VIR_STORAGE_POOL_EVENT_DELETED 5
+#endif
+
+
+#endif /* LIBVIRT_GO_STORAGE_POOL_COMPAT_H__ */
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/storage_pool_events.go b/src/dma/vendor/github.com/libvirt/libvirt-go/storage_pool_events.go
new file mode 100644
index 00000000..fd1b9979
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/storage_pool_events.go
@@ -0,0 +1,174 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+package libvirt
+
+import (
+ "fmt"
+ "unsafe"
+)
+
+/*
+#cgo pkg-config: libvirt
+#include "storage_pool_events_wrapper.h"
+*/
+import "C"
+
+type StoragePoolEventLifecycle struct {
+ Event StoragePoolEventLifecycleType
+ // TODO: we can make Detail typesafe somehow ?
+ Detail int
+}
+
+type StoragePoolEventLifecycleCallback func(c *Connect, n *StoragePool, event *StoragePoolEventLifecycle)
+
+type StoragePoolEventGenericCallback func(c *Connect, n *StoragePool)
+
+//export storagePoolEventLifecycleCallback
+func storagePoolEventLifecycleCallback(c C.virConnectPtr, s C.virStoragePoolPtr,
+ event int, detail int,
+ goCallbackId int) {
+
+ storage_pool := &StoragePool{ptr: s}
+ connection := &Connect{ptr: c}
+
+ eventDetails := &StoragePoolEventLifecycle{
+ Event: StoragePoolEventLifecycleType(event),
+ Detail: detail,
+ }
+
+ callbackFunc := getCallbackId(goCallbackId)
+ callback, ok := callbackFunc.(StoragePoolEventLifecycleCallback)
+ if !ok {
+ panic("Inappropriate callback type called")
+ }
+ callback(connection, storage_pool, eventDetails)
+}
+
+//export storagePoolEventGenericCallback
+func storagePoolEventGenericCallback(c C.virConnectPtr, s C.virStoragePoolPtr,
+ goCallbackId int) {
+
+ storage_pool := &StoragePool{ptr: s}
+ connection := &Connect{ptr: c}
+
+ callbackFunc := getCallbackId(goCallbackId)
+ callback, ok := callbackFunc.(StoragePoolEventGenericCallback)
+ if !ok {
+ panic("Inappropriate callback type called")
+ }
+ callback(connection, storage_pool)
+}
+
+func (c *Connect) StoragePoolEventLifecycleRegister(pool *StoragePool, callback StoragePoolEventLifecycleCallback) (int, error) {
+ if C.LIBVIR_VERSION_NUMBER < 2000000 {
+ return 0, makeNotImplementedError("virConnectStoragePoolEventRegisterAny")
+ }
+
+ goCallBackId := registerCallbackId(callback)
+
+ callbackPtr := unsafe.Pointer(C.storagePoolEventLifecycleCallbackHelper)
+ var cpool C.virStoragePoolPtr
+ if pool != nil {
+ cpool = pool.ptr
+ }
+ var err C.virError
+ ret := C.virConnectStoragePoolEventRegisterAnyWrapper(c.ptr, cpool,
+ C.VIR_STORAGE_POOL_EVENT_ID_LIFECYCLE,
+ C.virConnectStoragePoolEventGenericCallback(callbackPtr),
+ C.long(goCallBackId), &err)
+ if ret == -1 {
+ freeCallbackId(goCallBackId)
+ return 0, makeError(&err)
+ }
+ return int(ret), nil
+}
+
+func (c *Connect) StoragePoolEventRefreshRegister(pool *StoragePool, callback StoragePoolEventGenericCallback) (int, error) {
+ if C.LIBVIR_VERSION_NUMBER < 2000000 {
+ return 0, makeNotImplementedError("virConnectStoragePoolEventRegisterAny")
+ }
+
+ goCallBackId := registerCallbackId(callback)
+
+ callbackPtr := unsafe.Pointer(C.storagePoolEventGenericCallbackHelper)
+ var cpool C.virStoragePoolPtr
+ if pool != nil {
+ cpool = pool.ptr
+ }
+ var err C.virError
+ ret := C.virConnectStoragePoolEventRegisterAnyWrapper(c.ptr, cpool,
+ C.VIR_STORAGE_POOL_EVENT_ID_REFRESH,
+ C.virConnectStoragePoolEventGenericCallback(callbackPtr),
+ C.long(goCallBackId), &err)
+ if ret == -1 {
+ freeCallbackId(goCallBackId)
+ return 0, makeError(&err)
+ }
+ return int(ret), nil
+}
+
+func (c *Connect) StoragePoolEventDeregister(callbackId int) error {
+ if C.LIBVIR_VERSION_NUMBER < 2000000 {
+ return makeNotImplementedError("virConnectStoragePoolEventDeregisterAny")
+ }
+
+ // Deregister the callback
+ var err C.virError
+ ret := int(C.virConnectStoragePoolEventDeregisterAnyWrapper(c.ptr, C.int(callbackId), &err))
+ if ret < 0 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+func (e StoragePoolEventLifecycle) String() string {
+ var event string
+ switch e.Event {
+ case STORAGE_POOL_EVENT_DEFINED:
+ event = "defined"
+
+ case STORAGE_POOL_EVENT_UNDEFINED:
+ event = "undefined"
+
+ case STORAGE_POOL_EVENT_STARTED:
+ event = "started"
+
+ case STORAGE_POOL_EVENT_STOPPED:
+ event = "stopped"
+
+ case STORAGE_POOL_EVENT_CREATED:
+ event = "created"
+
+ case STORAGE_POOL_EVENT_DELETED:
+ event = "deleted"
+
+ default:
+ event = "unknown"
+ }
+
+ return fmt.Sprintf("StoragePool event=%q", event)
+}
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/storage_pool_events_wrapper.go b/src/dma/vendor/github.com/libvirt/libvirt-go/storage_pool_events_wrapper.go
new file mode 100644
index 00000000..c5510381
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/storage_pool_events_wrapper.go
@@ -0,0 +1,89 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+package libvirt
+
+/*
+#cgo pkg-config: libvirt
+#include <assert.h>
+#include "storage_pool_events_wrapper.h"
+#include "callbacks_wrapper.h"
+#include <stdint.h>
+
+extern void storagePoolEventLifecycleCallback(virConnectPtr, virStoragePoolPtr, int, int, int);
+void storagePoolEventLifecycleCallbackHelper(virConnectPtr c, virStoragePoolPtr d,
+ int event, int detail, void *data)
+{
+ storagePoolEventLifecycleCallback(c, d, event, detail, (int)(intptr_t)data);
+}
+
+extern void storagePoolEventGenericCallback(virConnectPtr, virStoragePoolPtr, int);
+void storagePoolEventGenericCallbackHelper(virConnectPtr c, virStoragePoolPtr d,
+ void *data)
+{
+ storagePoolEventGenericCallback(c, d, (int)(intptr_t)data);
+}
+
+
+int
+virConnectStoragePoolEventRegisterAnyWrapper(virConnectPtr c,
+ virStoragePoolPtr d,
+ int eventID,
+ virConnectStoragePoolEventGenericCallback cb,
+ long goCallbackId,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 2000000
+ assert(0); // Caller should have checked version
+#else
+ void* id = (void*)goCallbackId;
+ int ret = virConnectStoragePoolEventRegisterAny(c, d, eventID, cb, id, freeGoCallbackHelper);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+int
+virConnectStoragePoolEventDeregisterAnyWrapper(virConnectPtr conn,
+ int callbackID,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 2000000
+ assert(0); // Caller shouuld have checked version
+#else
+ int ret = virConnectStoragePoolEventDeregisterAny(conn, callbackID);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+*/
+import "C"
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/storage_pool_events_wrapper.h b/src/dma/vendor/github.com/libvirt/libvirt-go/storage_pool_events_wrapper.h
new file mode 100644
index 00000000..7007f1c0
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/storage_pool_events_wrapper.h
@@ -0,0 +1,59 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+#ifndef LIBVIRT_GO_STORAGE_POOL_EVENTS_WRAPPER_H__
+#define LIBVIRT_GO_STORAGE_POOL_EVENTS_WRAPPER_H__
+
+#include <libvirt/libvirt.h>
+#include <libvirt/virterror.h>
+#include "storage_pool_compat.h"
+
+void
+storagePoolEventLifecycleCallbackHelper(virConnectPtr c,
+ virStoragePoolPtr d,
+ int event,
+ int detail,
+ void* data);
+
+void
+storagePoolEventGenericCallbackHelper(virConnectPtr c,
+ virStoragePoolPtr d,
+ void* data);
+
+int
+virConnectStoragePoolEventRegisterAnyWrapper(virConnectPtr c,
+ virStoragePoolPtr d,
+ int eventID,
+ virConnectStoragePoolEventGenericCallback cb,
+ long goCallbackId,
+ virErrorPtr err);
+
+int
+virConnectStoragePoolEventDeregisterAnyWrapper(virConnectPtr conn,
+ int callbackID,
+ virErrorPtr err);
+
+#endif /* LIBVIRT_GO_STORAGE_POOL_EVENTS_WRAPPER_H__ */
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/storage_pool_wrapper.go b/src/dma/vendor/github.com/libvirt/libvirt-go/storage_pool_wrapper.go
new file mode 100644
index 00000000..8534f7c8
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/storage_pool_wrapper.go
@@ -0,0 +1,343 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (C) 2018 Red Hat, Inc.
+ *
+ */
+
+package libvirt
+
+/*
+#cgo pkg-config: libvirt
+#include <assert.h>
+#include "storage_pool_wrapper.h"
+
+int
+virStoragePoolBuildWrapper(virStoragePoolPtr pool,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virStoragePoolBuild(pool, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virStoragePoolCreateWrapper(virStoragePoolPtr pool,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virStoragePoolCreate(pool, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virStoragePoolDeleteWrapper(virStoragePoolPtr pool,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virStoragePoolDelete(pool, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virStoragePoolDestroyWrapper(virStoragePoolPtr pool,
+ virErrorPtr err)
+{
+ int ret = virStoragePoolDestroy(pool);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virStoragePoolFreeWrapper(virStoragePoolPtr pool,
+ virErrorPtr err)
+{
+ int ret = virStoragePoolFree(pool);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virStoragePoolGetAutostartWrapper(virStoragePoolPtr pool,
+ int *autostart,
+ virErrorPtr err)
+{
+ int ret = virStoragePoolGetAutostart(pool, autostart);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+virConnectPtr
+virStoragePoolGetConnectWrapper(virStoragePoolPtr pool,
+ virErrorPtr err)
+{
+ virConnectPtr ret = virStoragePoolGetConnect(pool);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virStoragePoolGetInfoWrapper(virStoragePoolPtr pool,
+ virStoragePoolInfoPtr info,
+ virErrorPtr err)
+{
+ int ret = virStoragePoolGetInfo(pool, info);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+const char *
+virStoragePoolGetNameWrapper(virStoragePoolPtr pool,
+ virErrorPtr err)
+{
+ const char * ret = virStoragePoolGetName(pool);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virStoragePoolGetUUIDWrapper(virStoragePoolPtr pool,
+ unsigned char *uuid,
+ virErrorPtr err)
+{
+ int ret = virStoragePoolGetUUID(pool, uuid);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virStoragePoolGetUUIDStringWrapper(virStoragePoolPtr pool,
+ char *buf,
+ virErrorPtr err)
+{
+ int ret = virStoragePoolGetUUIDString(pool, buf);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+char *
+virStoragePoolGetXMLDescWrapper(virStoragePoolPtr pool,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ char * ret = virStoragePoolGetXMLDesc(pool, flags);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virStoragePoolIsActiveWrapper(virStoragePoolPtr pool,
+ virErrorPtr err)
+{
+ int ret = virStoragePoolIsActive(pool);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virStoragePoolIsPersistentWrapper(virStoragePoolPtr pool,
+ virErrorPtr err)
+{
+ int ret = virStoragePoolIsPersistent(pool);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virStoragePoolListAllVolumesWrapper(virStoragePoolPtr pool,
+ virStorageVolPtr **vols,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virStoragePoolListAllVolumes(pool, vols, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virStoragePoolListVolumesWrapper(virStoragePoolPtr pool,
+ char ** const names,
+ int maxnames,
+ virErrorPtr err)
+{
+ int ret = virStoragePoolListVolumes(pool, names, maxnames);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virStoragePoolNumOfVolumesWrapper(virStoragePoolPtr pool,
+ virErrorPtr err)
+{
+ int ret = virStoragePoolNumOfVolumes(pool);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virStoragePoolRefWrapper(virStoragePoolPtr pool,
+ virErrorPtr err)
+{
+ int ret = virStoragePoolRef(pool);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virStoragePoolRefreshWrapper(virStoragePoolPtr pool,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virStoragePoolRefresh(pool, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virStoragePoolSetAutostartWrapper(virStoragePoolPtr pool,
+ int autostart,
+ virErrorPtr err)
+{
+ int ret = virStoragePoolSetAutostart(pool, autostart);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virStoragePoolUndefineWrapper(virStoragePoolPtr pool,
+ virErrorPtr err)
+{
+ int ret = virStoragePoolUndefine(pool);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+virStorageVolPtr
+virStorageVolCreateXMLWrapper(virStoragePoolPtr pool,
+ const char *xmlDesc,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ virStorageVolPtr ret = virStorageVolCreateXML(pool, xmlDesc, flags);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+virStorageVolPtr
+virStorageVolCreateXMLFromWrapper(virStoragePoolPtr pool,
+ const char *xmlDesc,
+ virStorageVolPtr clonevol,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ virStorageVolPtr ret = virStorageVolCreateXMLFrom(pool, xmlDesc, clonevol, flags);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+virStorageVolPtr
+virStorageVolLookupByNameWrapper(virStoragePoolPtr pool,
+ const char *name,
+ virErrorPtr err)
+{
+ virStorageVolPtr ret = virStorageVolLookupByName(pool, name);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+
+*/
+import "C"
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/storage_pool_wrapper.h b/src/dma/vendor/github.com/libvirt/libvirt-go/storage_pool_wrapper.h
new file mode 100644
index 00000000..acd121bf
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/storage_pool_wrapper.h
@@ -0,0 +1,150 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (C) 2018 Red Hat, Inc.
+ *
+ */
+
+#ifndef LIBVIRT_GO_STORAGE_POOL_WRAPPER_H__
+#define LIBVIRT_GO_STORAGE_POOL_WRAPPER_H__
+
+#include <libvirt/libvirt.h>
+#include <libvirt/virterror.h>
+#include "storage_pool_compat.h"
+
+int
+virStoragePoolBuildWrapper(virStoragePoolPtr pool,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virStoragePoolCreateWrapper(virStoragePoolPtr pool,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virStoragePoolDeleteWrapper(virStoragePoolPtr pool,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virStoragePoolDestroyWrapper(virStoragePoolPtr pool,
+ virErrorPtr err);
+
+int
+virStoragePoolFreeWrapper(virStoragePoolPtr pool,
+ virErrorPtr err);
+
+int
+virStoragePoolGetAutostartWrapper(virStoragePoolPtr pool,
+ int *autostart,
+ virErrorPtr err);
+
+virConnectPtr
+virStoragePoolGetConnectWrapper(virStoragePoolPtr pool,
+ virErrorPtr err);
+
+int
+virStoragePoolGetInfoWrapper(virStoragePoolPtr pool,
+ virStoragePoolInfoPtr info,
+ virErrorPtr err);
+
+const char *
+virStoragePoolGetNameWrapper(virStoragePoolPtr pool,
+ virErrorPtr err);
+
+int
+virStoragePoolGetUUIDWrapper(virStoragePoolPtr pool,
+ unsigned char *uuid,
+ virErrorPtr err);
+
+int
+virStoragePoolGetUUIDStringWrapper(virStoragePoolPtr pool,
+ char *buf,
+ virErrorPtr err);
+
+char *
+virStoragePoolGetXMLDescWrapper(virStoragePoolPtr pool,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virStoragePoolIsActiveWrapper(virStoragePoolPtr pool,
+ virErrorPtr err);
+
+int
+virStoragePoolIsPersistentWrapper(virStoragePoolPtr pool,
+ virErrorPtr err);
+
+int
+virStoragePoolListAllVolumesWrapper(virStoragePoolPtr pool,
+ virStorageVolPtr **vols,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virStoragePoolListVolumesWrapper(virStoragePoolPtr pool,
+ char **const names,
+ int maxnames,
+ virErrorPtr err);
+
+int
+virStoragePoolNumOfVolumesWrapper(virStoragePoolPtr pool,
+ virErrorPtr err);
+
+int
+virStoragePoolRefWrapper(virStoragePoolPtr pool,
+ virErrorPtr err);
+
+int
+virStoragePoolRefreshWrapper(virStoragePoolPtr pool,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virStoragePoolSetAutostartWrapper(virStoragePoolPtr pool,
+ int autostart,
+ virErrorPtr err);
+
+int
+virStoragePoolUndefineWrapper(virStoragePoolPtr pool,
+ virErrorPtr err);
+
+virStorageVolPtr
+virStorageVolCreateXMLWrapper(virStoragePoolPtr pool,
+ const char *xmlDesc,
+ unsigned int flags,
+ virErrorPtr err);
+
+virStorageVolPtr
+virStorageVolCreateXMLFromWrapper(virStoragePoolPtr pool,
+ const char *xmlDesc,
+ virStorageVolPtr clonevol,
+ unsigned int flags,
+ virErrorPtr err);
+
+virStorageVolPtr
+virStorageVolLookupByNameWrapper(virStoragePoolPtr pool,
+ const char *name,
+ virErrorPtr err);
+
+
+#endif /* LIBVIRT_GO_STORAGE_POOL_WRAPPER_H__ */
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/storage_volume.go b/src/dma/vendor/github.com/libvirt/libvirt-go/storage_volume.go
new file mode 100644
index 00000000..bb10813d
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/storage_volume.go
@@ -0,0 +1,290 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+package libvirt
+
+/*
+#cgo pkg-config: libvirt
+#include <stdlib.h>
+#include "storage_volume_wrapper.h"
+*/
+import "C"
+
+import (
+ "unsafe"
+)
+
+type StorageVolCreateFlags int
+
+const (
+ STORAGE_VOL_CREATE_PREALLOC_METADATA = StorageVolCreateFlags(C.VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA)
+ STORAGE_VOL_CREATE_REFLINK = StorageVolCreateFlags(C.VIR_STORAGE_VOL_CREATE_REFLINK)
+)
+
+type StorageVolDeleteFlags int
+
+const (
+ STORAGE_VOL_DELETE_NORMAL = StorageVolDeleteFlags(C.VIR_STORAGE_VOL_DELETE_NORMAL) // Delete metadata only (fast)
+ STORAGE_VOL_DELETE_ZEROED = StorageVolDeleteFlags(C.VIR_STORAGE_VOL_DELETE_ZEROED) // Clear all data to zeros (slow)
+ STORAGE_VOL_DELETE_WITH_SNAPSHOTS = StorageVolDeleteFlags(C.VIR_STORAGE_VOL_DELETE_WITH_SNAPSHOTS) // Force removal of volume, even if in use
+)
+
+type StorageVolResizeFlags int
+
+const (
+ STORAGE_VOL_RESIZE_ALLOCATE = StorageVolResizeFlags(C.VIR_STORAGE_VOL_RESIZE_ALLOCATE) // force allocation of new size
+ STORAGE_VOL_RESIZE_DELTA = StorageVolResizeFlags(C.VIR_STORAGE_VOL_RESIZE_DELTA) // size is relative to current
+ STORAGE_VOL_RESIZE_SHRINK = StorageVolResizeFlags(C.VIR_STORAGE_VOL_RESIZE_SHRINK) // allow decrease in capacity
+)
+
+type StorageVolType int
+
+const (
+ STORAGE_VOL_FILE = StorageVolType(C.VIR_STORAGE_VOL_FILE) // Regular file based volumes
+ STORAGE_VOL_BLOCK = StorageVolType(C.VIR_STORAGE_VOL_BLOCK) // Block based volumes
+ STORAGE_VOL_DIR = StorageVolType(C.VIR_STORAGE_VOL_DIR) // Directory-passthrough based volume
+ STORAGE_VOL_NETWORK = StorageVolType(C.VIR_STORAGE_VOL_NETWORK) //Network volumes like RBD (RADOS Block Device)
+ STORAGE_VOL_NETDIR = StorageVolType(C.VIR_STORAGE_VOL_NETDIR) // Network accessible directory that can contain other network volumes
+ STORAGE_VOL_PLOOP = StorageVolType(C.VIR_STORAGE_VOL_PLOOP) // Ploop directory based volumes
+)
+
+type StorageVolWipeAlgorithm int
+
+const (
+ STORAGE_VOL_WIPE_ALG_ZERO = StorageVolWipeAlgorithm(C.VIR_STORAGE_VOL_WIPE_ALG_ZERO) // 1-pass, all zeroes
+ STORAGE_VOL_WIPE_ALG_NNSA = StorageVolWipeAlgorithm(C.VIR_STORAGE_VOL_WIPE_ALG_NNSA) // 4-pass NNSA Policy Letter NAP-14.1-C (XVI-8)
+ STORAGE_VOL_WIPE_ALG_DOD = StorageVolWipeAlgorithm(C.VIR_STORAGE_VOL_WIPE_ALG_DOD) // 4-pass DoD 5220.22-M section 8-306 procedure
+ STORAGE_VOL_WIPE_ALG_BSI = StorageVolWipeAlgorithm(C.VIR_STORAGE_VOL_WIPE_ALG_BSI) // 9-pass method recommended by the German Center of Security in Information Technologies
+ STORAGE_VOL_WIPE_ALG_GUTMANN = StorageVolWipeAlgorithm(C.VIR_STORAGE_VOL_WIPE_ALG_GUTMANN) // The canonical 35-pass sequence
+ STORAGE_VOL_WIPE_ALG_SCHNEIER = StorageVolWipeAlgorithm(C.VIR_STORAGE_VOL_WIPE_ALG_SCHNEIER) // 7-pass method described by Bruce Schneier in "Applied Cryptography" (1996)
+ STORAGE_VOL_WIPE_ALG_PFITZNER7 = StorageVolWipeAlgorithm(C.VIR_STORAGE_VOL_WIPE_ALG_PFITZNER7) // 7-pass random
+ STORAGE_VOL_WIPE_ALG_PFITZNER33 = StorageVolWipeAlgorithm(C.VIR_STORAGE_VOL_WIPE_ALG_PFITZNER33) // 33-pass random
+ STORAGE_VOL_WIPE_ALG_RANDOM = StorageVolWipeAlgorithm(C.VIR_STORAGE_VOL_WIPE_ALG_RANDOM) // 1-pass random
+ STORAGE_VOL_WIPE_ALG_TRIM = StorageVolWipeAlgorithm(C.VIR_STORAGE_VOL_WIPE_ALG_TRIM) // Trim the underlying storage
+)
+
+type StorageXMLFlags int
+
+const (
+ STORAGE_XML_INACTIVE = StorageXMLFlags(C.VIR_STORAGE_XML_INACTIVE)
+)
+
+type StorageVolInfoFlags int
+
+const (
+ STORAGE_VOL_USE_ALLOCATION = StorageVolInfoFlags(C.VIR_STORAGE_VOL_USE_ALLOCATION)
+ STORAGE_VOL_GET_PHYSICAL = StorageVolInfoFlags(C.VIR_STORAGE_VOL_GET_PHYSICAL)
+)
+
+type StorageVolUploadFlags int
+
+const (
+ STORAGE_VOL_UPLOAD_SPARSE_STREAM = StorageVolUploadFlags(C.VIR_STORAGE_VOL_UPLOAD_SPARSE_STREAM)
+)
+
+type StorageVolDownloadFlags int
+
+const (
+ STORAGE_VOL_DOWNLOAD_SPARSE_STREAM = StorageVolDownloadFlags(C.VIR_STORAGE_VOL_DOWNLOAD_SPARSE_STREAM)
+)
+
+type StorageVol struct {
+ ptr C.virStorageVolPtr
+}
+
+type StorageVolInfo struct {
+ Type StorageVolType
+ Capacity uint64
+ Allocation uint64
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolDelete
+func (v *StorageVol) Delete(flags StorageVolDeleteFlags) error {
+ var err C.virError
+ result := C.virStorageVolDeleteWrapper(v.ptr, C.uint(flags), &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolFree
+func (v *StorageVol) Free() error {
+ var err C.virError
+ ret := C.virStorageVolFreeWrapper(v.ptr, &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolRef
+func (c *StorageVol) Ref() error {
+ var err C.virError
+ ret := C.virStorageVolRefWrapper(c.ptr, &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolGetInfo
+func (v *StorageVol) GetInfo() (*StorageVolInfo, error) {
+ var cinfo C.virStorageVolInfo
+ var err C.virError
+ result := C.virStorageVolGetInfoWrapper(v.ptr, &cinfo, &err)
+ if result == -1 {
+ return nil, makeError(&err)
+ }
+ return &StorageVolInfo{
+ Type: StorageVolType(cinfo._type),
+ Capacity: uint64(cinfo.capacity),
+ Allocation: uint64(cinfo.allocation),
+ }, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolGetInfoFlags
+func (v *StorageVol) GetInfoFlags(flags StorageVolInfoFlags) (*StorageVolInfo, error) {
+ if C.LIBVIR_VERSION_NUMBER < 3000000 {
+ return nil, makeNotImplementedError("virStorageVolGetInfoFlags")
+ }
+
+ var cinfo C.virStorageVolInfo
+ var err C.virError
+ result := C.virStorageVolGetInfoFlagsWrapper(v.ptr, &cinfo, C.uint(flags), &err)
+ if result == -1 {
+ return nil, makeError(&err)
+ }
+ return &StorageVolInfo{
+ Type: StorageVolType(cinfo._type),
+ Capacity: uint64(cinfo.capacity),
+ Allocation: uint64(cinfo.allocation),
+ }, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolGetKey
+func (v *StorageVol) GetKey() (string, error) {
+ var err C.virError
+ key := C.virStorageVolGetKeyWrapper(v.ptr, &err)
+ if key == nil {
+ return "", makeError(&err)
+ }
+ return C.GoString(key), nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolGetName
+func (v *StorageVol) GetName() (string, error) {
+ var err C.virError
+ name := C.virStorageVolGetNameWrapper(v.ptr, &err)
+ if name == nil {
+ return "", makeError(&err)
+ }
+ return C.GoString(name), nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolGetPath
+func (v *StorageVol) GetPath() (string, error) {
+ var err C.virError
+ result := C.virStorageVolGetPathWrapper(v.ptr, &err)
+ if result == nil {
+ return "", makeError(&err)
+ }
+ path := C.GoString(result)
+ C.free(unsafe.Pointer(result))
+ return path, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolGetXMLDesc
+func (v *StorageVol) GetXMLDesc(flags uint32) (string, error) {
+ var err C.virError
+ result := C.virStorageVolGetXMLDescWrapper(v.ptr, C.uint(flags), &err)
+ if result == nil {
+ return "", makeError(&err)
+ }
+ xml := C.GoString(result)
+ C.free(unsafe.Pointer(result))
+ return xml, nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolResize
+func (v *StorageVol) Resize(capacity uint64, flags StorageVolResizeFlags) error {
+ var err C.virError
+ result := C.virStorageVolResizeWrapper(v.ptr, C.ulonglong(capacity), C.uint(flags), &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolWipe
+func (v *StorageVol) Wipe(flags uint32) error {
+ var err C.virError
+ result := C.virStorageVolWipeWrapper(v.ptr, C.uint(flags), &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolWipePattern
+func (v *StorageVol) WipePattern(algorithm StorageVolWipeAlgorithm, flags uint32) error {
+ var err C.virError
+ result := C.virStorageVolWipePatternWrapper(v.ptr, C.uint(algorithm), C.uint(flags), &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolUpload
+func (v *StorageVol) Upload(stream *Stream, offset, length uint64, flags StorageVolUploadFlags) error {
+ var err C.virError
+ if C.virStorageVolUploadWrapper(v.ptr, stream.ptr, C.ulonglong(offset),
+ C.ulonglong(length), C.uint(flags), &err) == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolDownload
+func (v *StorageVol) Download(stream *Stream, offset, length uint64, flags StorageVolDownloadFlags) error {
+ var err C.virError
+ if C.virStorageVolDownloadWrapper(v.ptr, stream.ptr, C.ulonglong(offset),
+ C.ulonglong(length), C.uint(flags), &err) == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolLookupByVolume
+func (v *StorageVol) LookupPoolByVolume() (*StoragePool, error) {
+ var err C.virError
+ poolPtr := C.virStoragePoolLookupByVolumeWrapper(v.ptr, &err)
+ if poolPtr == nil {
+ return nil, makeError(&err)
+ }
+ return &StoragePool{ptr: poolPtr}, nil
+}
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/storage_volume_compat.h b/src/dma/vendor/github.com/libvirt/libvirt-go/storage_volume_compat.h
new file mode 100644
index 00000000..bd3cee9a
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/storage_volume_compat.h
@@ -0,0 +1,78 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+#ifndef LIBVIRT_GO_STORAGE_VOLUME_COMPAT_H__
+#define LIBVIRT_GO_STORAGE_VOLUME_COMPAT_H__
+
+/* 3.0.0 */
+
+#ifndef VIR_STORAGE_VOL_USE_ALLOCATION
+#define VIR_STORAGE_VOL_USE_ALLOCATION 0
+#endif
+
+#ifndef VIR_STORAGE_VOL_GET_PHYSICAL
+#define VIR_STORAGE_VOL_GET_PHYSICAL 1 << 0
+#endif
+
+
+/* 1.2.13 */
+
+#ifndef VIR_STORAGE_VOL_CREATE_REFLINK
+#define VIR_STORAGE_VOL_CREATE_REFLINK 1<< 1
+#endif
+
+
+/* 1.2.21 */
+
+#ifndef VIR_STORAGE_VOL_DELETE_WITH_SNAPSHOTS
+#define VIR_STORAGE_VOL_DELETE_WITH_SNAPSHOTS 1 << 1
+#endif
+
+
+/* 1.3.2 */
+
+#ifndef VIR_STORAGE_VOL_WIPE_ALG_TRIM
+#define VIR_STORAGE_VOL_WIPE_ALG_TRIM 9
+#endif
+
+
+/* 1.3.4 */
+
+#ifndef VIR_STORAGE_VOL_PLOOP
+#define VIR_STORAGE_VOL_PLOOP 5
+#endif
+
+/* 3.4.0 */
+
+#ifndef VIR_STORAGE_VOL_UPLOAD_SPARSE_STREAM
+#define VIR_STORAGE_VOL_UPLOAD_SPARSE_STREAM (1 << 0)
+#endif
+
+#ifndef VIR_STORAGE_VOL_DOWNLOAD_SPARSE_STREAM
+#define VIR_STORAGE_VOL_DOWNLOAD_SPARSE_STREAM (1 << 0)
+#endif
+
+#endif /* LIBVIRT_GO_STORAGE_VOLUME_COMPAT_H__ */
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/storage_volume_wrapper.go b/src/dma/vendor/github.com/libvirt/libvirt-go/storage_volume_wrapper.go
new file mode 100644
index 00000000..d41a8a7c
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/storage_volume_wrapper.go
@@ -0,0 +1,249 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+package libvirt
+
+/*
+#cgo pkg-config: libvirt
+#include <assert.h>
+#include "storage_volume_wrapper.h"
+
+virStoragePoolPtr
+virStoragePoolLookupByVolumeWrapper(virStorageVolPtr vol,
+ virErrorPtr err)
+{
+ virStoragePoolPtr ret = virStoragePoolLookupByVolume(vol);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virStorageVolDeleteWrapper(virStorageVolPtr vol,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virStorageVolDelete(vol, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virStorageVolDownloadWrapper(virStorageVolPtr vol,
+ virStreamPtr stream,
+ unsigned long long offset,
+ unsigned long long length,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virStorageVolDownload(vol, stream, offset, length, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virStorageVolFreeWrapper(virStorageVolPtr vol,
+ virErrorPtr err)
+{
+ int ret = virStorageVolFree(vol);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+virConnectPtr
+virStorageVolGetConnectWrapper(virStorageVolPtr vol,
+ virErrorPtr err)
+{
+ virConnectPtr ret = virStorageVolGetConnect(vol);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virStorageVolGetInfoWrapper(virStorageVolPtr vol,
+ virStorageVolInfoPtr info,
+ virErrorPtr err)
+{
+ int ret = virStorageVolGetInfo(vol, info);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virStorageVolGetInfoFlagsWrapper(virStorageVolPtr vol,
+ virStorageVolInfoPtr info,
+ unsigned int flags,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 3000000
+ assert(0); // Caller should have checked version
+#else
+ int ret = virStorageVolGetInfoFlags(vol, info, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+const char *
+virStorageVolGetKeyWrapper(virStorageVolPtr vol,
+ virErrorPtr err)
+{
+ const char *ret = virStorageVolGetKey(vol);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+const char *
+virStorageVolGetNameWrapper(virStorageVolPtr vol,
+ virErrorPtr err)
+{
+ const char *ret = virStorageVolGetName(vol);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+char *
+virStorageVolGetPathWrapper(virStorageVolPtr vol,
+ virErrorPtr err)
+{
+ char *ret = virStorageVolGetPath(vol);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+char *
+virStorageVolGetXMLDescWrapper(virStorageVolPtr vol,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ char *ret = virStorageVolGetXMLDesc(vol, flags);
+ if (!ret) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virStorageVolRefWrapper(virStorageVolPtr vol,
+ virErrorPtr err)
+{
+ int ret = virStorageVolRef(vol);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virStorageVolResizeWrapper(virStorageVolPtr vol,
+ unsigned long long capacity,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virStorageVolResize(vol, capacity, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virStorageVolUploadWrapper(virStorageVolPtr vol,
+ virStreamPtr stream,
+ unsigned long long offset,
+ unsigned long long length,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virStorageVolUpload(vol, stream, offset, length, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virStorageVolWipeWrapper(virStorageVolPtr vol,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virStorageVolWipe(vol, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virStorageVolWipePatternWrapper(virStorageVolPtr vol,
+ unsigned int algorithm,
+ unsigned int flags,
+ virErrorPtr err)
+{
+ int ret = virStorageVolWipePattern(vol, algorithm, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+*/
+import "C"
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/storage_volume_wrapper.h b/src/dma/vendor/github.com/libvirt/libvirt-go/storage_volume_wrapper.h
new file mode 100644
index 00000000..b3ed2a9f
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/storage_volume_wrapper.h
@@ -0,0 +1,116 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+#ifndef LIBVIRT_GO_STORAGE_VOLUME_WRAPPER_H__
+#define LIBVIRT_GO_STORAGE_VOLUME_WRAPPER_H__
+
+#include <libvirt/libvirt.h>
+#include <libvirt/virterror.h>
+#include "storage_volume_compat.h"
+
+virStoragePoolPtr
+virStoragePoolLookupByVolumeWrapper(virStorageVolPtr vol,
+ virErrorPtr err);
+
+int
+virStorageVolDeleteWrapper(virStorageVolPtr vol,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virStorageVolDownloadWrapper(virStorageVolPtr vol,
+ virStreamPtr stream,
+ unsigned long long offset,
+ unsigned long long length,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virStorageVolFreeWrapper(virStorageVolPtr vol,
+ virErrorPtr err);
+
+virConnectPtr
+virStorageVolGetConnectWrapper(virStorageVolPtr vol,
+ virErrorPtr err);
+
+int
+virStorageVolGetInfoWrapper(virStorageVolPtr vol,
+ virStorageVolInfoPtr info,
+ virErrorPtr err);
+
+int
+virStorageVolGetInfoFlagsWrapper(virStorageVolPtr vol,
+ virStorageVolInfoPtr info,
+ unsigned int flags,
+ virErrorPtr err);
+
+const char *
+virStorageVolGetKeyWrapper(virStorageVolPtr vol,
+ virErrorPtr err);
+
+const char *
+virStorageVolGetNameWrapper(virStorageVolPtr vol,
+ virErrorPtr err);
+
+char *
+virStorageVolGetPathWrapper(virStorageVolPtr vol,
+ virErrorPtr err);
+
+char *
+virStorageVolGetXMLDescWrapper(virStorageVolPtr vol,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virStorageVolRefWrapper(virStorageVolPtr vol,
+ virErrorPtr err);
+
+int
+virStorageVolResizeWrapper(virStorageVolPtr vol,
+ unsigned long long capacity,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virStorageVolUploadWrapper(virStorageVolPtr vol,
+ virStreamPtr stream,
+ unsigned long long offset,
+ unsigned long long length,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virStorageVolWipeWrapper(virStorageVolPtr vol,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virStorageVolWipePatternWrapper(virStorageVolPtr vol,
+ unsigned int algorithm,
+ unsigned int flags,
+ virErrorPtr err);
+
+#endif /* LIBVIRT_GO_STORAGE_VOLUME_WRAPPER_H__ */
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/stream.go b/src/dma/vendor/github.com/libvirt/libvirt-go/stream.go
new file mode 100644
index 00000000..4010b11c
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/stream.go
@@ -0,0 +1,418 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+package libvirt
+
+/*
+#cgo pkg-config: libvirt
+#include <stdlib.h>
+#include "stream_wrapper.h"
+*/
+import "C"
+import (
+ "io"
+ "unsafe"
+)
+
+type StreamFlags int
+
+const (
+ STREAM_NONBLOCK = StreamFlags(C.VIR_STREAM_NONBLOCK)
+)
+
+type StreamEventType int
+
+const (
+ STREAM_EVENT_READABLE = StreamEventType(C.VIR_STREAM_EVENT_READABLE)
+ STREAM_EVENT_WRITABLE = StreamEventType(C.VIR_STREAM_EVENT_WRITABLE)
+ STREAM_EVENT_ERROR = StreamEventType(C.VIR_STREAM_EVENT_ERROR)
+ STREAM_EVENT_HANGUP = StreamEventType(C.VIR_STREAM_EVENT_HANGUP)
+)
+
+type StreamRecvFlagsValues int
+
+const (
+ STREAM_RECV_STOP_AT_HOLE = StreamRecvFlagsValues(C.VIR_STREAM_RECV_STOP_AT_HOLE)
+)
+
+type Stream struct {
+ ptr C.virStreamPtr
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-stream.html#virStreamAbort
+func (v *Stream) Abort() error {
+ var err C.virError
+ result := C.virStreamAbortWrapper(v.ptr, &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-stream.html#virStreamFinish
+func (v *Stream) Finish() error {
+ var err C.virError
+ result := C.virStreamFinishWrapper(v.ptr, &err)
+ if result == -1 {
+ return makeError(&err)
+ }
+
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-stream.html#virStreamFree
+func (v *Stream) Free() error {
+ var err C.virError
+ ret := C.virStreamFreeWrapper(v.ptr, &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-stream.html#virStreamRef
+func (c *Stream) Ref() error {
+ var err C.virError
+ ret := C.virStreamRefWrapper(c.ptr, &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-stream.html#virStreamRecv
+func (v *Stream) Recv(p []byte) (int, error) {
+ var err C.virError
+ n := C.virStreamRecvWrapper(v.ptr, (*C.char)(unsafe.Pointer(&p[0])), C.size_t(len(p)), &err)
+ if n < 0 {
+ return 0, makeError(&err)
+ }
+ if n == 0 {
+ return 0, io.EOF
+ }
+
+ return int(n), nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-stream.html#virStreamRecvFlags
+func (v *Stream) RecvFlags(p []byte, flags StreamRecvFlagsValues) (int, error) {
+ if C.LIBVIR_VERSION_NUMBER < 3004000 {
+ return 0, makeNotImplementedError("virStreamRecvFlags")
+ }
+
+ var err C.virError
+ n := C.virStreamRecvFlagsWrapper(v.ptr, (*C.char)(unsafe.Pointer(&p[0])), C.size_t(len(p)), C.uint(flags), &err)
+ if n < 0 {
+ return 0, makeError(&err)
+ }
+ if n == 0 {
+ return 0, io.EOF
+ }
+
+ return int(n), nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-stream.html#virStreamRecvHole
+func (v *Stream) RecvHole(flags uint) (int64, error) {
+ if C.LIBVIR_VERSION_NUMBER < 3004000 {
+ return 0, makeNotImplementedError("virStreamSparseRecvHole")
+ }
+
+ var len C.longlong
+ var err C.virError
+ ret := C.virStreamRecvHoleWrapper(v.ptr, &len, C.uint(flags), &err)
+ if ret < 0 {
+ return 0, makeError(&err)
+ }
+
+ return int64(len), nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-stream.html#virStreamSend
+func (v *Stream) Send(p []byte) (int, error) {
+ var err C.virError
+ n := C.virStreamSendWrapper(v.ptr, (*C.char)(unsafe.Pointer(&p[0])), C.size_t(len(p)), &err)
+ if n < 0 {
+ return 0, makeError(&err)
+ }
+ if n == 0 {
+ return 0, io.EOF
+ }
+
+ return int(n), nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-stream.html#virStreamSendHole
+func (v *Stream) SendHole(len int64, flags uint32) error {
+ if C.LIBVIR_VERSION_NUMBER < 3004000 {
+ return makeNotImplementedError("virStreamSendHole")
+ }
+
+ var err C.virError
+ ret := C.virStreamSendHoleWrapper(v.ptr, C.longlong(len), C.uint(flags), &err)
+ if ret < 0 {
+ return makeError(&err)
+ }
+
+ return nil
+}
+
+type StreamSinkFunc func(*Stream, []byte) (int, error)
+type StreamSinkHoleFunc func(*Stream, int64) error
+
+//export streamSinkCallback
+func streamSinkCallback(stream C.virStreamPtr, cdata *C.char, nbytes C.size_t, callbackID int) int {
+ callbackFunc := getCallbackId(callbackID)
+
+ callback, ok := callbackFunc.(StreamSinkFunc)
+ if !ok {
+ panic("Incorrect stream sink func callback")
+ }
+
+ data := make([]byte, int(nbytes))
+ for i := 0; i < int(nbytes); i++ {
+ cdatabyte := (*C.char)(unsafe.Pointer(uintptr(unsafe.Pointer(cdata)) + (unsafe.Sizeof(*cdata) * uintptr(i))))
+ data[i] = (byte)(*cdatabyte)
+ }
+
+ retnbytes, err := callback(&Stream{ptr: stream}, data)
+ if err != nil {
+ return -1
+ }
+
+ return retnbytes
+}
+
+//export streamSinkHoleCallback
+func streamSinkHoleCallback(stream C.virStreamPtr, length C.longlong, callbackID int) int {
+ callbackFunc := getCallbackId(callbackID)
+
+ callback, ok := callbackFunc.(StreamSinkHoleFunc)
+ if !ok {
+ panic("Incorrect stream sink hole func callback")
+ }
+
+ err := callback(&Stream{ptr: stream}, int64(length))
+ if err != nil {
+ return -1
+ }
+
+ return 0
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-stream.html#virStreamRecvAll
+func (v *Stream) RecvAll(handler StreamSinkFunc) error {
+
+ callbackID := registerCallbackId(handler)
+
+ var err C.virError
+ ret := C.virStreamRecvAllWrapper(v.ptr, (C.int)(callbackID), &err)
+ freeCallbackId(callbackID)
+ if ret == -1 {
+ return makeError(&err)
+ }
+
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-stream.html#virStreamSparseRecvAll
+func (v *Stream) SparseRecvAll(handler StreamSinkFunc, holeHandler StreamSinkHoleFunc) error {
+ if C.LIBVIR_VERSION_NUMBER < 3004000 {
+ return makeNotImplementedError("virStreamSparseSendAll")
+ }
+
+ callbackID := registerCallbackId(handler)
+ holeCallbackID := registerCallbackId(holeHandler)
+
+ var err C.virError
+ ret := C.virStreamSparseRecvAllWrapper(v.ptr, (C.int)(callbackID), (C.int)(holeCallbackID), &err)
+ freeCallbackId(callbackID)
+ freeCallbackId(holeCallbackID)
+ if ret == -1 {
+ return makeError(&err)
+ }
+
+ return nil
+}
+
+type StreamSourceFunc func(*Stream, int) ([]byte, error)
+type StreamSourceHoleFunc func(*Stream) (bool, int64, error)
+type StreamSourceSkipFunc func(*Stream, int64) error
+
+//export streamSourceCallback
+func streamSourceCallback(stream C.virStreamPtr, cdata *C.char, nbytes C.size_t, callbackID int) int {
+ callbackFunc := getCallbackId(callbackID)
+
+ callback, ok := callbackFunc.(StreamSourceFunc)
+ if !ok {
+ panic("Incorrect stream sink func callback")
+ }
+
+ data, err := callback(&Stream{ptr: stream}, (int)(nbytes))
+ if err != nil {
+ return -1
+ }
+
+ nretbytes := int(nbytes)
+ if len(data) < nretbytes {
+ nretbytes = len(data)
+ }
+
+ for i := 0; i < nretbytes; i++ {
+ cdatabyte := (*C.char)(unsafe.Pointer(uintptr(unsafe.Pointer(cdata)) + (unsafe.Sizeof(*cdata) * uintptr(i))))
+ *cdatabyte = (C.char)(data[i])
+ }
+
+ return nretbytes
+}
+
+//export streamSourceHoleCallback
+func streamSourceHoleCallback(stream C.virStreamPtr, cinData *C.int, clength *C.longlong, callbackID int) int {
+ callbackFunc := getCallbackId(callbackID)
+
+ callback, ok := callbackFunc.(StreamSourceHoleFunc)
+ if !ok {
+ panic("Incorrect stream sink hole func callback")
+ }
+
+ inData, length, err := callback(&Stream{ptr: stream})
+ if err != nil {
+ return -1
+ }
+
+ if inData {
+ *cinData = 1
+ } else {
+ *cinData = 0
+ }
+ *clength = C.longlong(length)
+
+ return 0
+}
+
+//export streamSourceSkipCallback
+func streamSourceSkipCallback(stream C.virStreamPtr, length C.longlong, callbackID int) int {
+ callbackFunc := getCallbackId(callbackID)
+
+ callback, ok := callbackFunc.(StreamSourceSkipFunc)
+ if !ok {
+ panic("Incorrect stream sink skip func callback")
+ }
+
+ err := callback(&Stream{ptr: stream}, int64(length))
+ if err != nil {
+ return -1
+ }
+
+ return 0
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-stream.html#virStreamSendAll
+func (v *Stream) SendAll(handler StreamSourceFunc) error {
+
+ callbackID := registerCallbackId(handler)
+
+ var err C.virError
+ ret := C.virStreamSendAllWrapper(v.ptr, (C.int)(callbackID), &err)
+ freeCallbackId(callbackID)
+ if ret == -1 {
+ return makeError(&err)
+ }
+
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-stream.html#virStreamSparseSendAll
+func (v *Stream) SparseSendAll(handler StreamSourceFunc, holeHandler StreamSourceHoleFunc, skipHandler StreamSourceSkipFunc) error {
+ if C.LIBVIR_VERSION_NUMBER < 3004000 {
+ return makeNotImplementedError("virStreamSparseSendAll")
+ }
+
+ callbackID := registerCallbackId(handler)
+ holeCallbackID := registerCallbackId(holeHandler)
+ skipCallbackID := registerCallbackId(skipHandler)
+
+ var err C.virError
+ ret := C.virStreamSparseSendAllWrapper(v.ptr, (C.int)(callbackID), (C.int)(holeCallbackID), (C.int)(skipCallbackID), &err)
+ freeCallbackId(callbackID)
+ freeCallbackId(holeCallbackID)
+ freeCallbackId(skipCallbackID)
+ if ret == -1 {
+ return makeError(&err)
+ }
+
+ return nil
+}
+
+type StreamEventCallback func(*Stream, StreamEventType)
+
+// See also https://libvirt.org/html/libvirt-libvirt-stream.html#virStreamEventAddCallback
+func (v *Stream) EventAddCallback(events StreamEventType, callback StreamEventCallback) error {
+ callbackID := registerCallbackId(callback)
+
+ var err C.virError
+ ret := C.virStreamEventAddCallbackWrapper(v.ptr, (C.int)(events), (C.int)(callbackID), &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+
+ return nil
+}
+
+//export streamEventCallback
+func streamEventCallback(st C.virStreamPtr, events int, callbackID int) {
+ callbackFunc := getCallbackId(callbackID)
+
+ callback, ok := callbackFunc.(StreamEventCallback)
+ if !ok {
+ panic("Incorrect stream event func callback")
+ }
+
+ callback(&Stream{ptr: st}, StreamEventType(events))
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-stream.html#virStreamEventUpdateCallback
+func (v *Stream) EventUpdateCallback(events StreamEventType) error {
+ var err C.virError
+ ret := C.virStreamEventUpdateCallbackWrapper(v.ptr, (C.int)(events), &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+
+ return nil
+}
+
+// See also https://libvirt.org/html/libvirt-libvirt-stream.html#virStreamEventRemoveCallback
+func (v *Stream) EventRemoveCallback() error {
+ var err C.virError
+ ret := C.virStreamEventRemoveCallbackWrapper(v.ptr, &err)
+ if ret == -1 {
+ return makeError(&err)
+ }
+
+ return nil
+}
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/stream_compat.h b/src/dma/vendor/github.com/libvirt/libvirt-go/stream_compat.h
new file mode 100644
index 00000000..92befd58
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/stream_compat.h
@@ -0,0 +1,36 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+#ifndef LIBVIRT_GO_STREAM_COMPAT_H__
+#define LIBVIRT_GO_STREAM_COMPAT_H__
+
+/* 3.4.0 */
+
+#ifndef VIR_STREAM_RECV_STOP_AT_HOLE
+#define VIR_STREAM_RECV_STOP_AT_HOLE (1 << 0)
+#endif
+
+#endif /* LIBVIRT_GO_STREAM_COMPAT_H__ */
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/stream_wrapper.go b/src/dma/vendor/github.com/libvirt/libvirt-go/stream_wrapper.go
new file mode 100644
index 00000000..e563a742
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/stream_wrapper.go
@@ -0,0 +1,331 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+package libvirt
+
+/*
+#cgo pkg-config: libvirt
+#include <stdint.h>
+#include <stdlib.h>
+#include <assert.h>
+#include "stream_wrapper.h"
+
+int streamSourceCallback(virStreamPtr st, char *cdata, size_t nbytes, int callbackID);
+int streamSourceHoleCallback(virStreamPtr st, int *inData, long long *length, int callbackID);
+int streamSourceSkipCallback(virStreamPtr st, long long length, int callbackID);
+
+int streamSinkCallback(virStreamPtr st, const char *cdata, size_t nbytes, int callbackID);
+int streamSinkHoleCallback(virStreamPtr st, long long length, int callbackID);
+
+struct CallbackData {
+ int callbackID;
+ int holeCallbackID;
+ int skipCallbackID;
+};
+
+static int streamSourceCallbackHelper(virStreamPtr st, char *data, size_t nbytes, void *opaque)
+{
+ struct CallbackData *cbdata = opaque;
+
+ return streamSourceCallback(st, data, nbytes, cbdata->callbackID);
+}
+
+static int streamSourceHoleCallbackHelper(virStreamPtr st, int *inData, long long *length, void *opaque)
+{
+ struct CallbackData *cbdata = opaque;
+
+ return streamSourceHoleCallback(st, inData, length, cbdata->holeCallbackID);
+}
+
+static int streamSourceSkipCallbackHelper(virStreamPtr st, long long length, void *opaque)
+{
+ struct CallbackData *cbdata = opaque;
+
+ return streamSourceSkipCallback(st, length, cbdata->skipCallbackID);
+}
+
+static int streamSinkCallbackHelper(virStreamPtr st, const char *data, size_t nbytes, void *opaque)
+{
+ struct CallbackData *cbdata = opaque;
+
+ return streamSinkCallback(st, data, nbytes, cbdata->callbackID);
+}
+
+static int streamSinkHoleCallbackHelper(virStreamPtr st, long long length, void *opaque)
+{
+ struct CallbackData *cbdata = opaque;
+
+ return streamSinkHoleCallback(st, length, cbdata->holeCallbackID);
+}
+
+int
+virStreamAbortWrapper(virStreamPtr stream,
+ virErrorPtr err)
+{
+ int ret = virStreamAbort(stream);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+void
+streamEventCallback(virStreamPtr st, int events, int callbackID);
+
+static void
+streamEventCallbackHelper(virStreamPtr st, int events, void *opaque)
+{
+ streamEventCallback(st, events, (int)(intptr_t)opaque);
+}
+
+int
+virStreamEventAddCallbackWrapper(virStreamPtr stream,
+ int events,
+ int callbackID,
+ virErrorPtr err)
+{
+ int ret = virStreamEventAddCallback(stream, events, streamEventCallbackHelper, (void *)(intptr_t)callbackID, NULL);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virStreamEventRemoveCallbackWrapper(virStreamPtr stream,
+ virErrorPtr err)
+{
+ int ret = virStreamEventRemoveCallback(stream);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virStreamEventUpdateCallbackWrapper(virStreamPtr stream,
+ int events,
+ virErrorPtr err)
+{
+ int ret = virStreamEventUpdateCallback(stream, events);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virStreamFinishWrapper(virStreamPtr stream,
+ virErrorPtr err)
+{
+ int ret = virStreamFinish(stream);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virStreamFreeWrapper(virStreamPtr stream,
+ virErrorPtr err)
+{
+ int ret = virStreamFree(stream);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virStreamRecvWrapper(virStreamPtr stream,
+ char *data,
+ size_t nbytes,
+ virErrorPtr err)
+{
+ int ret = virStreamRecv(stream, data, nbytes);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virStreamRecvAllWrapper(virStreamPtr stream,
+ int callbackID,
+ virErrorPtr err)
+{
+ struct CallbackData cbdata = { .callbackID = callbackID };
+ int ret = virStreamRecvAll(stream, streamSinkCallbackHelper, &cbdata);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virStreamRecvFlagsWrapper(virStreamPtr stream,
+ char *data,
+ size_t nbytes,
+ unsigned int flags,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 3004000
+ assert(0); // Caller should have checked version
+#else
+ int ret = virStreamRecvFlags(stream, data, nbytes, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+int
+virStreamRecvHoleWrapper(virStreamPtr stream,
+ long long *length,
+ unsigned int flags,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 3004000
+ assert(0); // Caller should have checked version
+#else
+ int ret = virStreamRecvHole(stream, length, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+int
+virStreamRefWrapper(virStreamPtr stream,
+ virErrorPtr err)
+{
+ int ret = virStreamRef(stream);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virStreamSendWrapper(virStreamPtr stream,
+ const char *data,
+ size_t nbytes,
+ virErrorPtr err)
+{
+ int ret = virStreamSend(stream, data, nbytes);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virStreamSendAllWrapper(virStreamPtr stream,
+ int callbackID,
+ virErrorPtr err)
+{
+ struct CallbackData cbdata = { .callbackID = callbackID };
+ int ret = virStreamSendAll(stream, streamSourceCallbackHelper, &cbdata);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+}
+
+
+int
+virStreamSendHoleWrapper(virStreamPtr stream,
+ long long length,
+ unsigned int flags,
+ virErrorPtr err)
+{
+#if LIBVIR_VERSION_NUMBER < 3004000
+ assert(0); // Caller should have checked version
+#else
+ int ret = virStreamSendHole(stream, length, flags);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+int
+virStreamSparseRecvAllWrapper(virStreamPtr stream,
+ int callbackID,
+ int holeCallbackID,
+ virErrorPtr err)
+{
+ struct CallbackData cbdata = { .callbackID = callbackID, .holeCallbackID = holeCallbackID };
+#if LIBVIR_VERSION_NUMBER < 3004000
+ assert(0); // Caller should have checked version
+#else
+ int ret = virStreamSparseRecvAll(stream, streamSinkCallbackHelper, streamSinkHoleCallbackHelper, &cbdata);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+int
+virStreamSparseSendAllWrapper(virStreamPtr stream,
+ int callbackID,
+ int holeCallbackID,
+ int skipCallbackID,
+ virErrorPtr err)
+{
+ struct CallbackData cbdata = { .callbackID = callbackID, .holeCallbackID = holeCallbackID, .skipCallbackID = skipCallbackID };
+#if LIBVIR_VERSION_NUMBER < 3004000
+ assert(0); // Caller should have checked version
+#else
+ int ret = virStreamSparseSendAll(stream, streamSourceCallbackHelper, streamSourceHoleCallbackHelper, streamSourceSkipCallbackHelper, &cbdata);
+ if (ret < 0) {
+ virCopyLastError(err);
+ }
+ return ret;
+#endif
+}
+
+
+*/
+import "C"
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/stream_wrapper.h b/src/dma/vendor/github.com/libvirt/libvirt-go/stream_wrapper.h
new file mode 100644
index 00000000..b9c6e57c
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/stream_wrapper.h
@@ -0,0 +1,120 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+#ifndef LIBVIRT_GO_STREAM_WRAPPER_H__
+#define LIBVIRT_GO_STREAM_WRAPPER_H__
+
+#include <libvirt/libvirt.h>
+#include <libvirt/virterror.h>
+#include "stream_compat.h"
+
+int
+virStreamAbortWrapper(virStreamPtr stream,
+ virErrorPtr err);
+
+int
+virStreamEventAddCallbackWrapper(virStreamPtr st,
+ int events,
+ int callbackID,
+ virErrorPtr err);
+
+int
+virStreamEventRemoveCallbackWrapper(virStreamPtr stream,
+ virErrorPtr err);
+
+int
+virStreamEventUpdateCallbackWrapper(virStreamPtr stream,
+ int events,
+ virErrorPtr err);
+
+int
+virStreamFinishWrapper(virStreamPtr stream,
+ virErrorPtr err);
+
+int
+virStreamFreeWrapper(virStreamPtr stream,
+ virErrorPtr err);
+
+int
+virStreamRecvWrapper(virStreamPtr stream,
+ char *data,
+ size_t nbytes,
+ virErrorPtr err);
+
+int
+virStreamRecvAllWrapper(virStreamPtr st,
+ int callbackID,
+ virErrorPtr err);
+
+int
+virStreamRecvFlagsWrapper(virStreamPtr st,
+ char *data,
+ size_t nbytes,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virStreamRecvHoleWrapper(virStreamPtr,
+ long long *length,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virStreamRefWrapper(virStreamPtr stream,
+ virErrorPtr err);
+
+int
+virStreamSendWrapper(virStreamPtr stream,
+ const char *data,
+ size_t nbytes,
+ virErrorPtr err);
+
+int
+virStreamSendAllWrapper(virStreamPtr st,
+ int callbackID,
+ virErrorPtr err);
+
+int
+virStreamSendHoleWrapper(virStreamPtr st,
+ long long length,
+ unsigned int flags,
+ virErrorPtr err);
+
+int
+virStreamSparseRecvAllWrapper(virStreamPtr st,
+ int callbackID,
+ int holeCallbackID,
+ virErrorPtr err);
+
+int
+virStreamSparseSendAllWrapper(virStreamPtr st,
+ int callbackID,
+ int holeCallbackID,
+ int skipCallbackID,
+ virErrorPtr err);
+
+
+#endif /* LIBVIRT_GO_STREAM_WRAPPER_H__ */
diff --git a/src/dma/vendor/github.com/libvirt/libvirt-go/typedparams.go b/src/dma/vendor/github.com/libvirt/libvirt-go/typedparams.go
new file mode 100644
index 00000000..e8ceae07
--- /dev/null
+++ b/src/dma/vendor/github.com/libvirt/libvirt-go/typedparams.go
@@ -0,0 +1,262 @@
+/*
+ * This file is part of the libvirt-go project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * Copyright (c) 2013 Alex Zorin
+ * Copyright (C) 2016 Red Hat, Inc.
+ *
+ */
+
+package libvirt
+
+/*
+#cgo pkg-config: libvirt
+#include <libvirt/libvirt.h>
+#include <libvirt/virterror.h>
+#include <stdlib.h>
+#include <string.h>
+*/
+import "C"
+
+import (
+ "fmt"
+ "unsafe"
+)
+
+type typedParamsFieldInfo struct {
+ set *bool
+ i *int
+ ui *uint
+ l *int64
+ ul *uint64
+ b *bool
+ d *float64
+ s *string
+ sl *[]string
+}
+
+func typedParamsUnpackLen(cparams *C.virTypedParameter, nparams int, infomap map[string]typedParamsFieldInfo) (uint, error) {
+ count := uint(0)
+ for i := 0; i < nparams; i++ {
+ var cparam *C.virTypedParameter
+ cparam = (*C.virTypedParameter)(unsafe.Pointer(uintptr(unsafe.Pointer(cparams)) + unsafe.Sizeof(*cparam)*uintptr(i)))
+ name := C.GoString((*C.char)(unsafe.Pointer(&cparam.field)))
+ info, ok := infomap[name]
+ if !ok {
+ // Ignore unknown keys so that we don't break if
+ // run against a newer libvirt that returns more
+ // parameters than we currently have code to
+ // consume
+ continue
+ }
+ switch cparam._type {
+ case C.VIR_TYPED_PARAM_INT:
+ if info.i == nil {
+ return 0, fmt.Errorf("field %s expects an int", name)
+ }
+ *info.i = int(*(*C.int)(unsafe.Pointer(&cparam.value)))
+ *info.set = true
+ case C.VIR_TYPED_PARAM_UINT:
+ if info.ui == nil {
+ return 0, fmt.Errorf("field %s expects a uint", name)
+ }
+ *info.ui = uint(*(*C.uint)(unsafe.Pointer(&cparam.value)))
+ *info.set = true
+ case C.VIR_TYPED_PARAM_LLONG:
+ if info.l == nil {
+ return 0, fmt.Errorf("field %s expects an int64", name)
+ }
+ *info.l = int64(*(*C.longlong)(unsafe.Pointer(&cparam.value)))
+ *info.set = true
+ case C.VIR_TYPED_PARAM_ULLONG:
+ if info.ul == nil {
+ return 0, fmt.Errorf("field %s expects a uint64", name)
+ }
+ *info.ul = uint64(*(*C.ulonglong)(unsafe.Pointer(&cparam.value)))
+ *info.set = true
+ case C.VIR_TYPED_PARAM_DOUBLE:
+ if info.d == nil {
+ return 0, fmt.Errorf("field %s expects a float64", name)
+ }
+ *info.d = float64(*(*C.double)(unsafe.Pointer(&cparam.value)))
+ *info.set = true
+ case C.VIR_TYPED_PARAM_BOOLEAN:
+ if info.b == nil {
+ return 0, fmt.Errorf("field %s expects a bool", name)
+ }
+ *info.b = *(*C.char)(unsafe.Pointer(&cparam.value)) == 1
+ *info.set = true
+ case C.VIR_TYPED_PARAM_STRING:
+ if info.s != nil {
+ *info.s = C.GoString(*(**C.char)(unsafe.Pointer(&cparam.value)))
+ *info.set = true
+ } else if info.sl != nil {
+ *info.sl = append(*info.sl, C.GoString(*(**C.char)(unsafe.Pointer(&cparam.value))))
+ *info.set = true
+ } else {
+ return 0, fmt.Errorf("field %s expects a string/string list", name)
+ }
+ }
+ count++
+ }
+
+ return count, nil
+}
+
+func typedParamsUnpack(cparams []C.virTypedParameter, infomap map[string]typedParamsFieldInfo) (uint, error) {
+ return typedParamsUnpackLen(&cparams[0], len(cparams), infomap)
+}
+
+func typedParamsPackLen(cparams *C.virTypedParameter, nparams int, infomap map[string]typedParamsFieldInfo) error {
+ stringOffsets := make(map[string]uint)
+
+ for i := 0; i < nparams; i++ {
+ var cparam *C.virTypedParameter
+ cparam = (*C.virTypedParameter)(unsafe.Pointer(uintptr(unsafe.Pointer(cparams)) + unsafe.Sizeof(*cparam)*uintptr(i)))
+ name := C.GoString((*C.char)(unsafe.Pointer(&cparam.field)))
+ info, ok := infomap[name]
+ if !ok {
+ // Ignore unknown keys so that we don't break if
+ // run against a newer libvirt that returns more
+ // parameters than we currently have code to
+ // consume
+ continue
+ }
+ if !*info.set {
+ continue
+ }
+ switch cparam._type {
+ case C.VIR_TYPED_PARAM_INT:
+ if info.i == nil {
+ return fmt.Errorf("field %s expects an int", name)
+ }
+ *(*C.int)(unsafe.Pointer(&cparam.value)) = C.int(*info.i)
+ case C.VIR_TYPED_PARAM_UINT:
+ if info.ui == nil {
+ return fmt.Errorf("field %s expects a uint", name)
+ }
+ *(*C.uint)(unsafe.Pointer(&cparam.value)) = C.uint(*info.ui)
+ case C.VIR_TYPED_PARAM_LLONG:
+ if info.l == nil {
+ return fmt.Errorf("field %s expects an int64", name)
+ }
+ *(*C.longlong)(unsafe.Pointer(&cparam.value)) = C.longlong(*info.l)
+ case C.VIR_TYPED_PARAM_ULLONG:
+ if info.ul == nil {
+ return fmt.Errorf("field %s expects a uint64", name)
+ }
+ *(*C.ulonglong)(unsafe.Pointer(&cparam.value)) = C.ulonglong(*info.ul)
+ case C.VIR_TYPED_PARAM_DOUBLE:
+ if info.d == nil {
+ return fmt.Errorf("field %s expects a float64", name)
+ }
+ *(*C.double)(unsafe.Pointer(&cparam.value)) = C.double(*info.d)
+ case C.VIR_TYPED_PARAM_BOOLEAN:
+ if info.b == nil {
+ return fmt.Errorf("field %s expects a bool", name)
+ }
+ if *info.b {
+ *(*C.char)(unsafe.Pointer(&cparam.value)) = 1
+ } else {
+ *(*C.char)(unsafe.Pointer(&cparam.value)) = 0
+ }
+ case C.VIR_TYPED_PARAM_STRING:
+ if info.s != nil {
+ *(**C.char)(unsafe.Pointer(&cparam.value)) = C.CString(*info.s)
+ } else if info.sl != nil {
+ count := stringOffsets[name]
+ *(**C.char)(unsafe.Pointer(&cparam.value)) = C.CString((*info.sl)[count])
+ stringOffsets[name] = count + 1
+ } else {
+ return fmt.Errorf("field %s expects a string", name)
+ }
+ }
+ }
+
+ return nil
+}
+
+func typedParamsPack(cparams []C.virTypedParameter, infomap map[string]typedParamsFieldInfo) error {
+ return typedParamsPackLen(&cparams[0], len(cparams), infomap)
+}
+
+func typedParamsPackNew(infomap map[string]typedParamsFieldInfo) (*[]C.virTypedParameter, error) {
+ nparams := 0
+ for _, value := range infomap {
+ if !*value.set {
+ continue
+ }
+
+ if value.sl != nil {
+ nparams += len(*value.sl)
+ } else {
+ nparams++
+ }
+ }
+
+ cparams := make([]C.virTypedParameter, nparams)
+ nparams = 0
+ for key, value := range infomap {
+ if !*value.set {
+ continue
+ }
+
+ cfield := C.CString(key)
+ defer C.free(unsafe.Pointer(cfield))
+ clen := len(key) + 1
+ if clen > C.VIR_TYPED_PARAM_FIELD_LENGTH {
+ clen = C.VIR_TYPED_PARAM_FIELD_LENGTH
+ }
+ if value.sl != nil {
+ for i := 0; i < len(*value.sl); i++ {
+ cparam := &cparams[nparams]
+ cparam._type = C.VIR_TYPED_PARAM_STRING
+ C.memcpy(unsafe.Pointer(&cparam.field[0]), unsafe.Pointer(cfield), C.size_t(clen))
+ nparams++
+ }
+ } else {
+ cparam := &cparams[nparams]
+ if value.i != nil {
+ cparam._type = C.VIR_TYPED_PARAM_INT
+ } else if value.ui != nil {
+ cparam._type = C.VIR_TYPED_PARAM_UINT
+ } else if value.l != nil {
+ cparam._type = C.VIR_TYPED_PARAM_LLONG
+ } else if value.ul != nil {
+ cparam._type = C.VIR_TYPED_PARAM_ULLONG
+ } else if value.b != nil {
+ cparam._type = C.VIR_TYPED_PARAM_BOOLEAN
+ } else if value.d != nil {
+ cparam._type = C.VIR_TYPED_PARAM_DOUBLE
+ } else if value.s != nil {
+ cparam._type = C.VIR_TYPED_PARAM_STRING
+ }
+ C.memcpy(unsafe.Pointer(&cparam.field[0]), unsafe.Pointer(cfield), C.size_t(clen))
+ nparams++
+ }
+ }
+
+ err := typedParamsPack(cparams, infomap)
+ if err != nil {
+ C.virTypedParamsClear((*C.virTypedParameter)(unsafe.Pointer(&cparams[0])), C.int(nparams))
+ return nil, err
+ }
+ return &cparams, nil
+}
diff --git a/src/dma/vendor/github.com/mattn/go-colorable/.travis.yml b/src/dma/vendor/github.com/mattn/go-colorable/.travis.yml
new file mode 100644
index 00000000..98db8f06
--- /dev/null
+++ b/src/dma/vendor/github.com/mattn/go-colorable/.travis.yml
@@ -0,0 +1,9 @@
+language: go
+go:
+ - tip
+
+before_install:
+ - go get github.com/mattn/goveralls
+ - go get golang.org/x/tools/cmd/cover
+script:
+ - $HOME/gopath/bin/goveralls -repotoken xnXqRGwgW3SXIguzxf90ZSK1GPYZPaGrw
diff --git a/src/dma/vendor/github.com/mattn/go-colorable/LICENSE b/src/dma/vendor/github.com/mattn/go-colorable/LICENSE
new file mode 100644
index 00000000..91b5cef3
--- /dev/null
+++ b/src/dma/vendor/github.com/mattn/go-colorable/LICENSE
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) 2016 Yasuhiro Matsumoto
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/src/dma/vendor/github.com/mattn/go-colorable/README.md b/src/dma/vendor/github.com/mattn/go-colorable/README.md
new file mode 100644
index 00000000..56729a92
--- /dev/null
+++ b/src/dma/vendor/github.com/mattn/go-colorable/README.md
@@ -0,0 +1,48 @@
+# go-colorable
+
+[![Godoc Reference](https://godoc.org/github.com/mattn/go-colorable?status.svg)](http://godoc.org/github.com/mattn/go-colorable)
+[![Build Status](https://travis-ci.org/mattn/go-colorable.svg?branch=master)](https://travis-ci.org/mattn/go-colorable)
+[![Coverage Status](https://coveralls.io/repos/github/mattn/go-colorable/badge.svg?branch=master)](https://coveralls.io/github/mattn/go-colorable?branch=master)
+[![Go Report Card](https://goreportcard.com/badge/mattn/go-colorable)](https://goreportcard.com/report/mattn/go-colorable)
+
+Colorable writer for windows.
+
+For example, most of logger packages doesn't show colors on windows. (I know we can do it with ansicon. But I don't want.)
+This package is possible to handle escape sequence for ansi color on windows.
+
+## Too Bad!
+
+![](https://raw.githubusercontent.com/mattn/go-colorable/gh-pages/bad.png)
+
+
+## So Good!
+
+![](https://raw.githubusercontent.com/mattn/go-colorable/gh-pages/good.png)
+
+## Usage
+
+```go
+logrus.SetFormatter(&logrus.TextFormatter{ForceColors: true})
+logrus.SetOutput(colorable.NewColorableStdout())
+
+logrus.Info("succeeded")
+logrus.Warn("not correct")
+logrus.Error("something error")
+logrus.Fatal("panic")
+```
+
+You can compile above code on non-windows OSs.
+
+## Installation
+
+```
+$ go get github.com/mattn/go-colorable
+```
+
+# License
+
+MIT
+
+# Author
+
+Yasuhiro Matsumoto (a.k.a mattn)
diff --git a/src/dma/vendor/github.com/mattn/go-colorable/colorable_appengine.go b/src/dma/vendor/github.com/mattn/go-colorable/colorable_appengine.go
new file mode 100644
index 00000000..1f28d773
--- /dev/null
+++ b/src/dma/vendor/github.com/mattn/go-colorable/colorable_appengine.go
@@ -0,0 +1,29 @@
+// +build appengine
+
+package colorable
+
+import (
+ "io"
+ "os"
+
+ _ "github.com/mattn/go-isatty"
+)
+
+// NewColorable return new instance of Writer which handle escape sequence.
+func NewColorable(file *os.File) io.Writer {
+ if file == nil {
+ panic("nil passed instead of *os.File to NewColorable()")
+ }
+
+ return file
+}
+
+// NewColorableStdout return new instance of Writer which handle escape sequence for stdout.
+func NewColorableStdout() io.Writer {
+ return os.Stdout
+}
+
+// NewColorableStderr return new instance of Writer which handle escape sequence for stderr.
+func NewColorableStderr() io.Writer {
+ return os.Stderr
+}
diff --git a/src/dma/vendor/github.com/mattn/go-colorable/colorable_others.go b/src/dma/vendor/github.com/mattn/go-colorable/colorable_others.go
new file mode 100644
index 00000000..887f203d
--- /dev/null
+++ b/src/dma/vendor/github.com/mattn/go-colorable/colorable_others.go
@@ -0,0 +1,30 @@
+// +build !windows
+// +build !appengine
+
+package colorable
+
+import (
+ "io"
+ "os"
+
+ _ "github.com/mattn/go-isatty"
+)
+
+// NewColorable return new instance of Writer which handle escape sequence.
+func NewColorable(file *os.File) io.Writer {
+ if file == nil {
+ panic("nil passed instead of *os.File to NewColorable()")
+ }
+
+ return file
+}
+
+// NewColorableStdout return new instance of Writer which handle escape sequence for stdout.
+func NewColorableStdout() io.Writer {
+ return os.Stdout
+}
+
+// NewColorableStderr return new instance of Writer which handle escape sequence for stderr.
+func NewColorableStderr() io.Writer {
+ return os.Stderr
+}
diff --git a/src/dma/vendor/github.com/mattn/go-colorable/colorable_windows.go b/src/dma/vendor/github.com/mattn/go-colorable/colorable_windows.go
new file mode 100644
index 00000000..e17a5474
--- /dev/null
+++ b/src/dma/vendor/github.com/mattn/go-colorable/colorable_windows.go
@@ -0,0 +1,884 @@
+// +build windows
+// +build !appengine
+
+package colorable
+
+import (
+ "bytes"
+ "io"
+ "math"
+ "os"
+ "strconv"
+ "strings"
+ "syscall"
+ "unsafe"
+
+ "github.com/mattn/go-isatty"
+)
+
+const (
+ foregroundBlue = 0x1
+ foregroundGreen = 0x2
+ foregroundRed = 0x4
+ foregroundIntensity = 0x8
+ foregroundMask = (foregroundRed | foregroundBlue | foregroundGreen | foregroundIntensity)
+ backgroundBlue = 0x10
+ backgroundGreen = 0x20
+ backgroundRed = 0x40
+ backgroundIntensity = 0x80
+ backgroundMask = (backgroundRed | backgroundBlue | backgroundGreen | backgroundIntensity)
+)
+
+type wchar uint16
+type short int16
+type dword uint32
+type word uint16
+
+type coord struct {
+ x short
+ y short
+}
+
+type smallRect struct {
+ left short
+ top short
+ right short
+ bottom short
+}
+
+type consoleScreenBufferInfo struct {
+ size coord
+ cursorPosition coord
+ attributes word
+ window smallRect
+ maximumWindowSize coord
+}
+
+type consoleCursorInfo struct {
+ size dword
+ visible int32
+}
+
+var (
+ kernel32 = syscall.NewLazyDLL("kernel32.dll")
+ procGetConsoleScreenBufferInfo = kernel32.NewProc("GetConsoleScreenBufferInfo")
+ procSetConsoleTextAttribute = kernel32.NewProc("SetConsoleTextAttribute")
+ procSetConsoleCursorPosition = kernel32.NewProc("SetConsoleCursorPosition")
+ procFillConsoleOutputCharacter = kernel32.NewProc("FillConsoleOutputCharacterW")
+ procFillConsoleOutputAttribute = kernel32.NewProc("FillConsoleOutputAttribute")
+ procGetConsoleCursorInfo = kernel32.NewProc("GetConsoleCursorInfo")
+ procSetConsoleCursorInfo = kernel32.NewProc("SetConsoleCursorInfo")
+ procSetConsoleTitle = kernel32.NewProc("SetConsoleTitleW")
+)
+
+// Writer provide colorable Writer to the console
+type Writer struct {
+ out io.Writer
+ handle syscall.Handle
+ oldattr word
+ oldpos coord
+}
+
+// NewColorable return new instance of Writer which handle escape sequence from File.
+func NewColorable(file *os.File) io.Writer {
+ if file == nil {
+ panic("nil passed instead of *os.File to NewColorable()")
+ }
+
+ if isatty.IsTerminal(file.Fd()) {
+ var csbi consoleScreenBufferInfo
+ handle := syscall.Handle(file.Fd())
+ procGetConsoleScreenBufferInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&csbi)))
+ return &Writer{out: file, handle: handle, oldattr: csbi.attributes, oldpos: coord{0, 0}}
+ }
+ return file
+}
+
+// NewColorableStdout return new instance of Writer which handle escape sequence for stdout.
+func NewColorableStdout() io.Writer {
+ return NewColorable(os.Stdout)
+}
+
+// NewColorableStderr return new instance of Writer which handle escape sequence for stderr.
+func NewColorableStderr() io.Writer {
+ return NewColorable(os.Stderr)
+}
+
+var color256 = map[int]int{
+ 0: 0x000000,
+ 1: 0x800000,
+ 2: 0x008000,
+ 3: 0x808000,
+ 4: 0x000080,
+ 5: 0x800080,
+ 6: 0x008080,
+ 7: 0xc0c0c0,
+ 8: 0x808080,
+ 9: 0xff0000,
+ 10: 0x00ff00,
+ 11: 0xffff00,
+ 12: 0x0000ff,
+ 13: 0xff00ff,
+ 14: 0x00ffff,
+ 15: 0xffffff,
+ 16: 0x000000,
+ 17: 0x00005f,
+ 18: 0x000087,
+ 19: 0x0000af,
+ 20: 0x0000d7,
+ 21: 0x0000ff,
+ 22: 0x005f00,
+ 23: 0x005f5f,
+ 24: 0x005f87,
+ 25: 0x005faf,
+ 26: 0x005fd7,
+ 27: 0x005fff,
+ 28: 0x008700,
+ 29: 0x00875f,
+ 30: 0x008787,
+ 31: 0x0087af,
+ 32: 0x0087d7,
+ 33: 0x0087ff,
+ 34: 0x00af00,
+ 35: 0x00af5f,
+ 36: 0x00af87,
+ 37: 0x00afaf,
+ 38: 0x00afd7,
+ 39: 0x00afff,
+ 40: 0x00d700,
+ 41: 0x00d75f,
+ 42: 0x00d787,
+ 43: 0x00d7af,
+ 44: 0x00d7d7,
+ 45: 0x00d7ff,
+ 46: 0x00ff00,
+ 47: 0x00ff5f,
+ 48: 0x00ff87,
+ 49: 0x00ffaf,
+ 50: 0x00ffd7,
+ 51: 0x00ffff,
+ 52: 0x5f0000,
+ 53: 0x5f005f,
+ 54: 0x5f0087,
+ 55: 0x5f00af,
+ 56: 0x5f00d7,
+ 57: 0x5f00ff,
+ 58: 0x5f5f00,
+ 59: 0x5f5f5f,
+ 60: 0x5f5f87,
+ 61: 0x5f5faf,
+ 62: 0x5f5fd7,
+ 63: 0x5f5fff,
+ 64: 0x5f8700,
+ 65: 0x5f875f,
+ 66: 0x5f8787,
+ 67: 0x5f87af,
+ 68: 0x5f87d7,
+ 69: 0x5f87ff,
+ 70: 0x5faf00,
+ 71: 0x5faf5f,
+ 72: 0x5faf87,
+ 73: 0x5fafaf,
+ 74: 0x5fafd7,
+ 75: 0x5fafff,
+ 76: 0x5fd700,
+ 77: 0x5fd75f,
+ 78: 0x5fd787,
+ 79: 0x5fd7af,
+ 80: 0x5fd7d7,
+ 81: 0x5fd7ff,
+ 82: 0x5fff00,
+ 83: 0x5fff5f,
+ 84: 0x5fff87,
+ 85: 0x5fffaf,
+ 86: 0x5fffd7,
+ 87: 0x5fffff,
+ 88: 0x870000,
+ 89: 0x87005f,
+ 90: 0x870087,
+ 91: 0x8700af,
+ 92: 0x8700d7,
+ 93: 0x8700ff,
+ 94: 0x875f00,
+ 95: 0x875f5f,
+ 96: 0x875f87,
+ 97: 0x875faf,
+ 98: 0x875fd7,
+ 99: 0x875fff,
+ 100: 0x878700,
+ 101: 0x87875f,
+ 102: 0x878787,
+ 103: 0x8787af,
+ 104: 0x8787d7,
+ 105: 0x8787ff,
+ 106: 0x87af00,
+ 107: 0x87af5f,
+ 108: 0x87af87,
+ 109: 0x87afaf,
+ 110: 0x87afd7,
+ 111: 0x87afff,
+ 112: 0x87d700,
+ 113: 0x87d75f,
+ 114: 0x87d787,
+ 115: 0x87d7af,
+ 116: 0x87d7d7,
+ 117: 0x87d7ff,
+ 118: 0x87ff00,
+ 119: 0x87ff5f,
+ 120: 0x87ff87,
+ 121: 0x87ffaf,
+ 122: 0x87ffd7,
+ 123: 0x87ffff,
+ 124: 0xaf0000,
+ 125: 0xaf005f,
+ 126: 0xaf0087,
+ 127: 0xaf00af,
+ 128: 0xaf00d7,
+ 129: 0xaf00ff,
+ 130: 0xaf5f00,
+ 131: 0xaf5f5f,
+ 132: 0xaf5f87,
+ 133: 0xaf5faf,
+ 134: 0xaf5fd7,
+ 135: 0xaf5fff,
+ 136: 0xaf8700,
+ 137: 0xaf875f,
+ 138: 0xaf8787,
+ 139: 0xaf87af,
+ 140: 0xaf87d7,
+ 141: 0xaf87ff,
+ 142: 0xafaf00,
+ 143: 0xafaf5f,
+ 144: 0xafaf87,
+ 145: 0xafafaf,
+ 146: 0xafafd7,
+ 147: 0xafafff,
+ 148: 0xafd700,
+ 149: 0xafd75f,
+ 150: 0xafd787,
+ 151: 0xafd7af,
+ 152: 0xafd7d7,
+ 153: 0xafd7ff,
+ 154: 0xafff00,
+ 155: 0xafff5f,
+ 156: 0xafff87,
+ 157: 0xafffaf,
+ 158: 0xafffd7,
+ 159: 0xafffff,
+ 160: 0xd70000,
+ 161: 0xd7005f,
+ 162: 0xd70087,
+ 163: 0xd700af,
+ 164: 0xd700d7,
+ 165: 0xd700ff,
+ 166: 0xd75f00,
+ 167: 0xd75f5f,
+ 168: 0xd75f87,
+ 169: 0xd75faf,
+ 170: 0xd75fd7,
+ 171: 0xd75fff,
+ 172: 0xd78700,
+ 173: 0xd7875f,
+ 174: 0xd78787,
+ 175: 0xd787af,
+ 176: 0xd787d7,
+ 177: 0xd787ff,
+ 178: 0xd7af00,
+ 179: 0xd7af5f,
+ 180: 0xd7af87,
+ 181: 0xd7afaf,
+ 182: 0xd7afd7,
+ 183: 0xd7afff,
+ 184: 0xd7d700,
+ 185: 0xd7d75f,
+ 186: 0xd7d787,
+ 187: 0xd7d7af,
+ 188: 0xd7d7d7,
+ 189: 0xd7d7ff,
+ 190: 0xd7ff00,
+ 191: 0xd7ff5f,
+ 192: 0xd7ff87,
+ 193: 0xd7ffaf,
+ 194: 0xd7ffd7,
+ 195: 0xd7ffff,
+ 196: 0xff0000,
+ 197: 0xff005f,
+ 198: 0xff0087,
+ 199: 0xff00af,
+ 200: 0xff00d7,
+ 201: 0xff00ff,
+ 202: 0xff5f00,
+ 203: 0xff5f5f,
+ 204: 0xff5f87,
+ 205: 0xff5faf,
+ 206: 0xff5fd7,
+ 207: 0xff5fff,
+ 208: 0xff8700,
+ 209: 0xff875f,
+ 210: 0xff8787,
+ 211: 0xff87af,
+ 212: 0xff87d7,
+ 213: 0xff87ff,
+ 214: 0xffaf00,
+ 215: 0xffaf5f,
+ 216: 0xffaf87,
+ 217: 0xffafaf,
+ 218: 0xffafd7,
+ 219: 0xffafff,
+ 220: 0xffd700,
+ 221: 0xffd75f,
+ 222: 0xffd787,
+ 223: 0xffd7af,
+ 224: 0xffd7d7,
+ 225: 0xffd7ff,
+ 226: 0xffff00,
+ 227: 0xffff5f,
+ 228: 0xffff87,
+ 229: 0xffffaf,
+ 230: 0xffffd7,
+ 231: 0xffffff,
+ 232: 0x080808,
+ 233: 0x121212,
+ 234: 0x1c1c1c,
+ 235: 0x262626,
+ 236: 0x303030,
+ 237: 0x3a3a3a,
+ 238: 0x444444,
+ 239: 0x4e4e4e,
+ 240: 0x585858,
+ 241: 0x626262,
+ 242: 0x6c6c6c,
+ 243: 0x767676,
+ 244: 0x808080,
+ 245: 0x8a8a8a,
+ 246: 0x949494,
+ 247: 0x9e9e9e,
+ 248: 0xa8a8a8,
+ 249: 0xb2b2b2,
+ 250: 0xbcbcbc,
+ 251: 0xc6c6c6,
+ 252: 0xd0d0d0,
+ 253: 0xdadada,
+ 254: 0xe4e4e4,
+ 255: 0xeeeeee,
+}
+
+// `\033]0;TITLESTR\007`
+func doTitleSequence(er *bytes.Reader) error {
+ var c byte
+ var err error
+
+ c, err = er.ReadByte()
+ if err != nil {
+ return err
+ }
+ if c != '0' && c != '2' {
+ return nil
+ }
+ c, err = er.ReadByte()
+ if err != nil {
+ return err
+ }
+ if c != ';' {
+ return nil
+ }
+ title := make([]byte, 0, 80)
+ for {
+ c, err = er.ReadByte()
+ if err != nil {
+ return err
+ }
+ if c == 0x07 || c == '\n' {
+ break
+ }
+ title = append(title, c)
+ }
+ if len(title) > 0 {
+ title8, err := syscall.UTF16PtrFromString(string(title))
+ if err == nil {
+ procSetConsoleTitle.Call(uintptr(unsafe.Pointer(title8)))
+ }
+ }
+ return nil
+}
+
+// Write write data on console
+func (w *Writer) Write(data []byte) (n int, err error) {
+ var csbi consoleScreenBufferInfo
+ procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
+
+ er := bytes.NewReader(data)
+ var bw [1]byte
+loop:
+ for {
+ c1, err := er.ReadByte()
+ if err != nil {
+ break loop
+ }
+ if c1 != 0x1b {
+ bw[0] = c1
+ w.out.Write(bw[:])
+ continue
+ }
+ c2, err := er.ReadByte()
+ if err != nil {
+ break loop
+ }
+
+ if c2 == ']' {
+ if err := doTitleSequence(er); err != nil {
+ break loop
+ }
+ continue
+ }
+ if c2 != 0x5b {
+ continue
+ }
+
+ var buf bytes.Buffer
+ var m byte
+ for {
+ c, err := er.ReadByte()
+ if err != nil {
+ break loop
+ }
+ if ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || c == '@' {
+ m = c
+ break
+ }
+ buf.Write([]byte(string(c)))
+ }
+
+ switch m {
+ case 'A':
+ n, err = strconv.Atoi(buf.String())
+ if err != nil {
+ continue
+ }
+ procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
+ csbi.cursorPosition.y -= short(n)
+ procSetConsoleCursorPosition.Call(uintptr(w.handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition)))
+ case 'B':
+ n, err = strconv.Atoi(buf.String())
+ if err != nil {
+ continue
+ }
+ procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
+ csbi.cursorPosition.y += short(n)
+ procSetConsoleCursorPosition.Call(uintptr(w.handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition)))
+ case 'C':
+ n, err = strconv.Atoi(buf.String())
+ if err != nil {
+ continue
+ }
+ procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
+ csbi.cursorPosition.x += short(n)
+ procSetConsoleCursorPosition.Call(uintptr(w.handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition)))
+ case 'D':
+ n, err = strconv.Atoi(buf.String())
+ if err != nil {
+ continue
+ }
+ procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
+ csbi.cursorPosition.x -= short(n)
+ procSetConsoleCursorPosition.Call(uintptr(w.handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition)))
+ case 'E':
+ n, err = strconv.Atoi(buf.String())
+ if err != nil {
+ continue
+ }
+ procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
+ csbi.cursorPosition.x = 0
+ csbi.cursorPosition.y += short(n)
+ procSetConsoleCursorPosition.Call(uintptr(w.handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition)))
+ case 'F':
+ n, err = strconv.Atoi(buf.String())
+ if err != nil {
+ continue
+ }
+ procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
+ csbi.cursorPosition.x = 0
+ csbi.cursorPosition.y -= short(n)
+ procSetConsoleCursorPosition.Call(uintptr(w.handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition)))
+ case 'G':
+ n, err = strconv.Atoi(buf.String())
+ if err != nil {
+ continue
+ }
+ procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
+ csbi.cursorPosition.x = short(n - 1)
+ procSetConsoleCursorPosition.Call(uintptr(w.handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition)))
+ case 'H', 'f':
+ procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
+ if buf.Len() > 0 {
+ token := strings.Split(buf.String(), ";")
+ switch len(token) {
+ case 1:
+ n1, err := strconv.Atoi(token[0])
+ if err != nil {
+ continue
+ }
+ csbi.cursorPosition.y = short(n1 - 1)
+ case 2:
+ n1, err := strconv.Atoi(token[0])
+ if err != nil {
+ continue
+ }
+ n2, err := strconv.Atoi(token[1])
+ if err != nil {
+ continue
+ }
+ csbi.cursorPosition.x = short(n2 - 1)
+ csbi.cursorPosition.y = short(n1 - 1)
+ }
+ } else {
+ csbi.cursorPosition.y = 0
+ }
+ procSetConsoleCursorPosition.Call(uintptr(w.handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition)))
+ case 'J':
+ n := 0
+ if buf.Len() > 0 {
+ n, err = strconv.Atoi(buf.String())
+ if err != nil {
+ continue
+ }
+ }
+ var count, written dword
+ var cursor coord
+ procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
+ switch n {
+ case 0:
+ cursor = coord{x: csbi.cursorPosition.x, y: csbi.cursorPosition.y}
+ count = dword(csbi.size.x - csbi.cursorPosition.x + (csbi.size.y-csbi.cursorPosition.y)*csbi.size.x)
+ case 1:
+ cursor = coord{x: csbi.window.left, y: csbi.window.top}
+ count = dword(csbi.size.x - csbi.cursorPosition.x + (csbi.window.top-csbi.cursorPosition.y)*csbi.size.x)
+ case 2:
+ cursor = coord{x: csbi.window.left, y: csbi.window.top}
+ count = dword(csbi.size.x - csbi.cursorPosition.x + (csbi.size.y-csbi.cursorPosition.y)*csbi.size.x)
+ }
+ procFillConsoleOutputCharacter.Call(uintptr(w.handle), uintptr(' '), uintptr(count), *(*uintptr)(unsafe.Pointer(&cursor)), uintptr(unsafe.Pointer(&written)))
+ procFillConsoleOutputAttribute.Call(uintptr(w.handle), uintptr(csbi.attributes), uintptr(count), *(*uintptr)(unsafe.Pointer(&cursor)), uintptr(unsafe.Pointer(&written)))
+ case 'K':
+ n := 0
+ if buf.Len() > 0 {
+ n, err = strconv.Atoi(buf.String())
+ if err != nil {
+ continue
+ }
+ }
+ procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
+ var cursor coord
+ var count, written dword
+ switch n {
+ case 0:
+ cursor = coord{x: csbi.cursorPosition.x + 1, y: csbi.cursorPosition.y}
+ count = dword(csbi.size.x - csbi.cursorPosition.x - 1)
+ case 1:
+ cursor = coord{x: csbi.window.left, y: csbi.window.top + csbi.cursorPosition.y}
+ count = dword(csbi.size.x - csbi.cursorPosition.x)
+ case 2:
+ cursor = coord{x: csbi.window.left, y: csbi.window.top + csbi.cursorPosition.y}
+ count = dword(csbi.size.x)
+ }
+ procFillConsoleOutputCharacter.Call(uintptr(w.handle), uintptr(' '), uintptr(count), *(*uintptr)(unsafe.Pointer(&cursor)), uintptr(unsafe.Pointer(&written)))
+ procFillConsoleOutputAttribute.Call(uintptr(w.handle), uintptr(csbi.attributes), uintptr(count), *(*uintptr)(unsafe.Pointer(&cursor)), uintptr(unsafe.Pointer(&written)))
+ case 'm':
+ procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
+ attr := csbi.attributes
+ cs := buf.String()
+ if cs == "" {
+ procSetConsoleTextAttribute.Call(uintptr(w.handle), uintptr(w.oldattr))
+ continue
+ }
+ token := strings.Split(cs, ";")
+ for i := 0; i < len(token); i++ {
+ ns := token[i]
+ if n, err = strconv.Atoi(ns); err == nil {
+ switch {
+ case n == 0 || n == 100:
+ attr = w.oldattr
+ case 1 <= n && n <= 5:
+ attr |= foregroundIntensity
+ case n == 7:
+ attr = ((attr & foregroundMask) << 4) | ((attr & backgroundMask) >> 4)
+ case n == 22 || n == 25:
+ attr |= foregroundIntensity
+ case n == 27:
+ attr = ((attr & foregroundMask) << 4) | ((attr & backgroundMask) >> 4)
+ case 30 <= n && n <= 37:
+ attr &= backgroundMask
+ if (n-30)&1 != 0 {
+ attr |= foregroundRed
+ }
+ if (n-30)&2 != 0 {
+ attr |= foregroundGreen
+ }
+ if (n-30)&4 != 0 {
+ attr |= foregroundBlue
+ }
+ case n == 38: // set foreground color.
+ if i < len(token)-2 && (token[i+1] == "5" || token[i+1] == "05") {
+ if n256, err := strconv.Atoi(token[i+2]); err == nil {
+ if n256foreAttr == nil {
+ n256setup()
+ }
+ attr &= backgroundMask
+ attr |= n256foreAttr[n256]
+ i += 2
+ }
+ } else {
+ attr = attr & (w.oldattr & backgroundMask)
+ }
+ case n == 39: // reset foreground color.
+ attr &= backgroundMask
+ attr |= w.oldattr & foregroundMask
+ case 40 <= n && n <= 47:
+ attr &= foregroundMask
+ if (n-40)&1 != 0 {
+ attr |= backgroundRed
+ }
+ if (n-40)&2 != 0 {
+ attr |= backgroundGreen
+ }
+ if (n-40)&4 != 0 {
+ attr |= backgroundBlue
+ }
+ case n == 48: // set background color.
+ if i < len(token)-2 && token[i+1] == "5" {
+ if n256, err := strconv.Atoi(token[i+2]); err == nil {
+ if n256backAttr == nil {
+ n256setup()
+ }
+ attr &= foregroundMask
+ attr |= n256backAttr[n256]
+ i += 2
+ }
+ } else {
+ attr = attr & (w.oldattr & foregroundMask)
+ }
+ case n == 49: // reset foreground color.
+ attr &= foregroundMask
+ attr |= w.oldattr & backgroundMask
+ case 90 <= n && n <= 97:
+ attr = (attr & backgroundMask)
+ attr |= foregroundIntensity
+ if (n-90)&1 != 0 {
+ attr |= foregroundRed
+ }
+ if (n-90)&2 != 0 {
+ attr |= foregroundGreen
+ }
+ if (n-90)&4 != 0 {
+ attr |= foregroundBlue
+ }
+ case 100 <= n && n <= 107:
+ attr = (attr & foregroundMask)
+ attr |= backgroundIntensity
+ if (n-100)&1 != 0 {
+ attr |= backgroundRed
+ }
+ if (n-100)&2 != 0 {
+ attr |= backgroundGreen
+ }
+ if (n-100)&4 != 0 {
+ attr |= backgroundBlue
+ }
+ }
+ procSetConsoleTextAttribute.Call(uintptr(w.handle), uintptr(attr))
+ }
+ }
+ case 'h':
+ var ci consoleCursorInfo
+ cs := buf.String()
+ if cs == "5>" {
+ procGetConsoleCursorInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&ci)))
+ ci.visible = 0
+ procSetConsoleCursorInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&ci)))
+ } else if cs == "?25" {
+ procGetConsoleCursorInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&ci)))
+ ci.visible = 1
+ procSetConsoleCursorInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&ci)))
+ }
+ case 'l':
+ var ci consoleCursorInfo
+ cs := buf.String()
+ if cs == "5>" {
+ procGetConsoleCursorInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&ci)))
+ ci.visible = 1
+ procSetConsoleCursorInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&ci)))
+ } else if cs == "?25" {
+ procGetConsoleCursorInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&ci)))
+ ci.visible = 0
+ procSetConsoleCursorInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&ci)))
+ }
+ case 's':
+ procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
+ w.oldpos = csbi.cursorPosition
+ case 'u':
+ procSetConsoleCursorPosition.Call(uintptr(w.handle), *(*uintptr)(unsafe.Pointer(&w.oldpos)))
+ }
+ }
+
+ return len(data), nil
+}
+
+type consoleColor struct {
+ rgb int
+ red bool
+ green bool
+ blue bool
+ intensity bool
+}
+
+func (c consoleColor) foregroundAttr() (attr word) {
+ if c.red {
+ attr |= foregroundRed
+ }
+ if c.green {
+ attr |= foregroundGreen
+ }
+ if c.blue {
+ attr |= foregroundBlue
+ }
+ if c.intensity {
+ attr |= foregroundIntensity
+ }
+ return
+}
+
+func (c consoleColor) backgroundAttr() (attr word) {
+ if c.red {
+ attr |= backgroundRed
+ }
+ if c.green {
+ attr |= backgroundGreen
+ }
+ if c.blue {
+ attr |= backgroundBlue
+ }
+ if c.intensity {
+ attr |= backgroundIntensity
+ }
+ return
+}
+
+var color16 = []consoleColor{
+ {0x000000, false, false, false, false},
+ {0x000080, false, false, true, false},
+ {0x008000, false, true, false, false},
+ {0x008080, false, true, true, false},
+ {0x800000, true, false, false, false},
+ {0x800080, true, false, true, false},
+ {0x808000, true, true, false, false},
+ {0xc0c0c0, true, true, true, false},
+ {0x808080, false, false, false, true},
+ {0x0000ff, false, false, true, true},
+ {0x00ff00, false, true, false, true},
+ {0x00ffff, false, true, true, true},
+ {0xff0000, true, false, false, true},
+ {0xff00ff, true, false, true, true},
+ {0xffff00, true, true, false, true},
+ {0xffffff, true, true, true, true},
+}
+
+type hsv struct {
+ h, s, v float32
+}
+
+func (a hsv) dist(b hsv) float32 {
+ dh := a.h - b.h
+ switch {
+ case dh > 0.5:
+ dh = 1 - dh
+ case dh < -0.5:
+ dh = -1 - dh
+ }
+ ds := a.s - b.s
+ dv := a.v - b.v
+ return float32(math.Sqrt(float64(dh*dh + ds*ds + dv*dv)))
+}
+
+func toHSV(rgb int) hsv {
+ r, g, b := float32((rgb&0xFF0000)>>16)/256.0,
+ float32((rgb&0x00FF00)>>8)/256.0,
+ float32(rgb&0x0000FF)/256.0
+ min, max := minmax3f(r, g, b)
+ h := max - min
+ if h > 0 {
+ if max == r {
+ h = (g - b) / h
+ if h < 0 {
+ h += 6
+ }
+ } else if max == g {
+ h = 2 + (b-r)/h
+ } else {
+ h = 4 + (r-g)/h
+ }
+ }
+ h /= 6.0
+ s := max - min
+ if max != 0 {
+ s /= max
+ }
+ v := max
+ return hsv{h: h, s: s, v: v}
+}
+
+type hsvTable []hsv
+
+func toHSVTable(rgbTable []consoleColor) hsvTable {
+ t := make(hsvTable, len(rgbTable))
+ for i, c := range rgbTable {
+ t[i] = toHSV(c.rgb)
+ }
+ return t
+}
+
+func (t hsvTable) find(rgb int) consoleColor {
+ hsv := toHSV(rgb)
+ n := 7
+ l := float32(5.0)
+ for i, p := range t {
+ d := hsv.dist(p)
+ if d < l {
+ l, n = d, i
+ }
+ }
+ return color16[n]
+}
+
+func minmax3f(a, b, c float32) (min, max float32) {
+ if a < b {
+ if b < c {
+ return a, c
+ } else if a < c {
+ return a, b
+ } else {
+ return c, b
+ }
+ } else {
+ if a < c {
+ return b, c
+ } else if b < c {
+ return b, a
+ } else {
+ return c, a
+ }
+ }
+}
+
+var n256foreAttr []word
+var n256backAttr []word
+
+func n256setup() {
+ n256foreAttr = make([]word, 256)
+ n256backAttr = make([]word, 256)
+ t := toHSVTable(color16)
+ for i, rgb := range color256 {
+ c := t.find(rgb)
+ n256foreAttr[i] = c.foregroundAttr()
+ n256backAttr[i] = c.backgroundAttr()
+ }
+}
diff --git a/src/dma/vendor/github.com/mattn/go-colorable/noncolorable.go b/src/dma/vendor/github.com/mattn/go-colorable/noncolorable.go
new file mode 100644
index 00000000..9721e16f
--- /dev/null
+++ b/src/dma/vendor/github.com/mattn/go-colorable/noncolorable.go
@@ -0,0 +1,55 @@
+package colorable
+
+import (
+ "bytes"
+ "io"
+)
+
+// NonColorable hold writer but remove escape sequence.
+type NonColorable struct {
+ out io.Writer
+}
+
+// NewNonColorable return new instance of Writer which remove escape sequence from Writer.
+func NewNonColorable(w io.Writer) io.Writer {
+ return &NonColorable{out: w}
+}
+
+// Write write data on console
+func (w *NonColorable) Write(data []byte) (n int, err error) {
+ er := bytes.NewReader(data)
+ var bw [1]byte
+loop:
+ for {
+ c1, err := er.ReadByte()
+ if err != nil {
+ break loop
+ }
+ if c1 != 0x1b {
+ bw[0] = c1
+ w.out.Write(bw[:])
+ continue
+ }
+ c2, err := er.ReadByte()
+ if err != nil {
+ break loop
+ }
+ if c2 != 0x5b {
+ continue
+ }
+
+ var buf bytes.Buffer
+ for {
+ c, err := er.ReadByte()
+ if err != nil {
+ break loop
+ }
+ if ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || c == '@' {
+ break
+ }
+ buf.Write([]byte(string(c)))
+ }
+ }
+
+ return len(data), nil
+}
diff --git a/src/dma/vendor/github.com/mattn/go-isatty/.travis.yml b/src/dma/vendor/github.com/mattn/go-isatty/.travis.yml
new file mode 100644
index 00000000..b9f8b239
--- /dev/null
+++ b/src/dma/vendor/github.com/mattn/go-isatty/.travis.yml
@@ -0,0 +1,9 @@
+language: go
+go:
+ - tip
+
+before_install:
+ - go get github.com/mattn/goveralls
+ - go get golang.org/x/tools/cmd/cover
+script:
+ - $HOME/gopath/bin/goveralls -repotoken 3gHdORO5k5ziZcWMBxnd9LrMZaJs8m9x5
diff --git a/src/dma/vendor/github.com/mattn/go-isatty/LICENSE b/src/dma/vendor/github.com/mattn/go-isatty/LICENSE
new file mode 100644
index 00000000..65dc692b
--- /dev/null
+++ b/src/dma/vendor/github.com/mattn/go-isatty/LICENSE
@@ -0,0 +1,9 @@
+Copyright (c) Yasuhiro MATSUMOTO <mattn.jp@gmail.com>
+
+MIT License (Expat)
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/src/dma/vendor/github.com/mattn/go-isatty/README.md b/src/dma/vendor/github.com/mattn/go-isatty/README.md
new file mode 100644
index 00000000..1e69004b
--- /dev/null
+++ b/src/dma/vendor/github.com/mattn/go-isatty/README.md
@@ -0,0 +1,50 @@
+# go-isatty
+
+[![Godoc Reference](https://godoc.org/github.com/mattn/go-isatty?status.svg)](http://godoc.org/github.com/mattn/go-isatty)
+[![Build Status](https://travis-ci.org/mattn/go-isatty.svg?branch=master)](https://travis-ci.org/mattn/go-isatty)
+[![Coverage Status](https://coveralls.io/repos/github/mattn/go-isatty/badge.svg?branch=master)](https://coveralls.io/github/mattn/go-isatty?branch=master)
+[![Go Report Card](https://goreportcard.com/badge/mattn/go-isatty)](https://goreportcard.com/report/mattn/go-isatty)
+
+isatty for golang
+
+## Usage
+
+```go
+package main
+
+import (
+ "fmt"
+ "github.com/mattn/go-isatty"
+ "os"
+)
+
+func main() {
+ if isatty.IsTerminal(os.Stdout.Fd()) {
+ fmt.Println("Is Terminal")
+ } else if isatty.IsCygwinTerminal(os.Stdout.Fd()) {
+ fmt.Println("Is Cygwin/MSYS2 Terminal")
+ } else {
+ fmt.Println("Is Not Terminal")
+ }
+}
+```
+
+## Installation
+
+```
+$ go get github.com/mattn/go-isatty
+```
+
+## License
+
+MIT
+
+## Author
+
+Yasuhiro Matsumoto (a.k.a mattn)
+
+## Thanks
+
+* k-takata: base idea for IsCygwinTerminal
+
+ https://github.com/k-takata/go-iscygpty
diff --git a/src/dma/vendor/github.com/mattn/go-isatty/doc.go b/src/dma/vendor/github.com/mattn/go-isatty/doc.go
new file mode 100644
index 00000000..17d4f90e
--- /dev/null
+++ b/src/dma/vendor/github.com/mattn/go-isatty/doc.go
@@ -0,0 +1,2 @@
+// Package isatty implements interface to isatty
+package isatty
diff --git a/src/dma/vendor/github.com/mattn/go-isatty/isatty_appengine.go b/src/dma/vendor/github.com/mattn/go-isatty/isatty_appengine.go
new file mode 100644
index 00000000..9584a988
--- /dev/null
+++ b/src/dma/vendor/github.com/mattn/go-isatty/isatty_appengine.go
@@ -0,0 +1,15 @@
+// +build appengine
+
+package isatty
+
+// IsTerminal returns true if the file descriptor is terminal which
+// is always false on on appengine classic which is a sandboxed PaaS.
+func IsTerminal(fd uintptr) bool {
+ return false
+}
+
+// IsCygwinTerminal() return true if the file descriptor is a cygwin or msys2
+// terminal. This is also always false on this environment.
+func IsCygwinTerminal(fd uintptr) bool {
+ return false
+}
diff --git a/src/dma/vendor/github.com/mattn/go-isatty/isatty_bsd.go b/src/dma/vendor/github.com/mattn/go-isatty/isatty_bsd.go
new file mode 100644
index 00000000..42f2514d
--- /dev/null
+++ b/src/dma/vendor/github.com/mattn/go-isatty/isatty_bsd.go
@@ -0,0 +1,18 @@
+// +build darwin freebsd openbsd netbsd dragonfly
+// +build !appengine
+
+package isatty
+
+import (
+ "syscall"
+ "unsafe"
+)
+
+const ioctlReadTermios = syscall.TIOCGETA
+
+// IsTerminal return true if the file descriptor is terminal.
+func IsTerminal(fd uintptr) bool {
+ var termios syscall.Termios
+ _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, fd, ioctlReadTermios, uintptr(unsafe.Pointer(&termios)), 0, 0, 0)
+ return err == 0
+}
diff --git a/src/dma/vendor/github.com/mattn/go-isatty/isatty_linux.go b/src/dma/vendor/github.com/mattn/go-isatty/isatty_linux.go
new file mode 100644
index 00000000..7384cf99
--- /dev/null
+++ b/src/dma/vendor/github.com/mattn/go-isatty/isatty_linux.go
@@ -0,0 +1,18 @@
+// +build linux
+// +build !appengine,!ppc64,!ppc64le
+
+package isatty
+
+import (
+ "syscall"
+ "unsafe"
+)
+
+const ioctlReadTermios = syscall.TCGETS
+
+// IsTerminal return true if the file descriptor is terminal.
+func IsTerminal(fd uintptr) bool {
+ var termios syscall.Termios
+ _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, fd, ioctlReadTermios, uintptr(unsafe.Pointer(&termios)), 0, 0, 0)
+ return err == 0
+}
diff --git a/src/dma/vendor/github.com/mattn/go-isatty/isatty_linux_ppc64x.go b/src/dma/vendor/github.com/mattn/go-isatty/isatty_linux_ppc64x.go
new file mode 100644
index 00000000..44e5d213
--- /dev/null
+++ b/src/dma/vendor/github.com/mattn/go-isatty/isatty_linux_ppc64x.go
@@ -0,0 +1,19 @@
+// +build linux
+// +build ppc64 ppc64le
+
+package isatty
+
+import (
+ "unsafe"
+
+ syscall "golang.org/x/sys/unix"
+)
+
+const ioctlReadTermios = syscall.TCGETS
+
+// IsTerminal return true if the file descriptor is terminal.
+func IsTerminal(fd uintptr) bool {
+ var termios syscall.Termios
+ _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, fd, ioctlReadTermios, uintptr(unsafe.Pointer(&termios)), 0, 0, 0)
+ return err == 0
+}
diff --git a/src/dma/vendor/github.com/mattn/go-isatty/isatty_others.go b/src/dma/vendor/github.com/mattn/go-isatty/isatty_others.go
new file mode 100644
index 00000000..ff4de3d9
--- /dev/null
+++ b/src/dma/vendor/github.com/mattn/go-isatty/isatty_others.go
@@ -0,0 +1,10 @@
+// +build !windows
+// +build !appengine
+
+package isatty
+
+// IsCygwinTerminal() return true if the file descriptor is a cygwin or msys2
+// terminal. This is also always false on this environment.
+func IsCygwinTerminal(fd uintptr) bool {
+ return false
+}
diff --git a/src/dma/vendor/github.com/mattn/go-isatty/isatty_solaris.go b/src/dma/vendor/github.com/mattn/go-isatty/isatty_solaris.go
new file mode 100644
index 00000000..1f0c6bf5
--- /dev/null
+++ b/src/dma/vendor/github.com/mattn/go-isatty/isatty_solaris.go
@@ -0,0 +1,16 @@
+// +build solaris
+// +build !appengine
+
+package isatty
+
+import (
+ "golang.org/x/sys/unix"
+)
+
+// IsTerminal returns true if the given file descriptor is a terminal.
+// see: http://src.illumos.org/source/xref/illumos-gate/usr/src/lib/libbc/libc/gen/common/isatty.c
+func IsTerminal(fd uintptr) bool {
+ var termio unix.Termio
+ err := unix.IoctlSetTermio(int(fd), unix.TCGETA, &termio)
+ return err == nil
+}
diff --git a/src/dma/vendor/github.com/mattn/go-isatty/isatty_windows.go b/src/dma/vendor/github.com/mattn/go-isatty/isatty_windows.go
new file mode 100644
index 00000000..af51cbca
--- /dev/null
+++ b/src/dma/vendor/github.com/mattn/go-isatty/isatty_windows.go
@@ -0,0 +1,94 @@
+// +build windows
+// +build !appengine
+
+package isatty
+
+import (
+ "strings"
+ "syscall"
+ "unicode/utf16"
+ "unsafe"
+)
+
+const (
+ fileNameInfo uintptr = 2
+ fileTypePipe = 3
+)
+
+var (
+ kernel32 = syscall.NewLazyDLL("kernel32.dll")
+ procGetConsoleMode = kernel32.NewProc("GetConsoleMode")
+ procGetFileInformationByHandleEx = kernel32.NewProc("GetFileInformationByHandleEx")
+ procGetFileType = kernel32.NewProc("GetFileType")
+)
+
+func init() {
+ // Check if GetFileInformationByHandleEx is available.
+ if procGetFileInformationByHandleEx.Find() != nil {
+ procGetFileInformationByHandleEx = nil
+ }
+}
+
+// IsTerminal return true if the file descriptor is terminal.
+func IsTerminal(fd uintptr) bool {
+ var st uint32
+ r, _, e := syscall.Syscall(procGetConsoleMode.Addr(), 2, fd, uintptr(unsafe.Pointer(&st)), 0)
+ return r != 0 && e == 0
+}
+
+// Check pipe name is used for cygwin/msys2 pty.
+// Cygwin/MSYS2 PTY has a name like:
+// \{cygwin,msys}-XXXXXXXXXXXXXXXX-ptyN-{from,to}-master
+func isCygwinPipeName(name string) bool {
+ token := strings.Split(name, "-")
+ if len(token) < 5 {
+ return false
+ }
+
+ if token[0] != `\msys` && token[0] != `\cygwin` {
+ return false
+ }
+
+ if token[1] == "" {
+ return false
+ }
+
+ if !strings.HasPrefix(token[2], "pty") {
+ return false
+ }
+
+ if token[3] != `from` && token[3] != `to` {
+ return false
+ }
+
+ if token[4] != "master" {
+ return false
+ }
+
+ return true
+}
+
+// IsCygwinTerminal() return true if the file descriptor is a cygwin or msys2
+// terminal.
+func IsCygwinTerminal(fd uintptr) bool {
+ if procGetFileInformationByHandleEx == nil {
+ return false
+ }
+
+ // Cygwin/msys's pty is a pipe.
+ ft, _, e := syscall.Syscall(procGetFileType.Addr(), 1, fd, 0, 0)
+ if ft != fileTypePipe || e != 0 {
+ return false
+ }
+
+ var buf [2 + syscall.MAX_PATH]uint16
+ r, _, e := syscall.Syscall6(procGetFileInformationByHandleEx.Addr(),
+ 4, fd, fileNameInfo, uintptr(unsafe.Pointer(&buf)),
+ uintptr(len(buf)*2), 0, 0)
+ if r == 0 || e != 0 {
+ return false
+ }
+
+ l := *(*uint32)(unsafe.Pointer(&buf))
+ return isCygwinPipeName(string(utf16.Decode(buf[2 : 2+l/2])))
+}
diff --git a/src/dma/vendor/github.com/streadway/amqp/.gitignore b/src/dma/vendor/github.com/streadway/amqp/.gitignore
new file mode 100644
index 00000000..ba8a7056
--- /dev/null
+++ b/src/dma/vendor/github.com/streadway/amqp/.gitignore
@@ -0,0 +1,4 @@
+certs/*
+spec/spec
+examples/simple-consumer/simple-consumer
+examples/simple-producer/simple-producer
diff --git a/src/dma/vendor/github.com/streadway/amqp/.travis.yml b/src/dma/vendor/github.com/streadway/amqp/.travis.yml
new file mode 100644
index 00000000..7166964c
--- /dev/null
+++ b/src/dma/vendor/github.com/streadway/amqp/.travis.yml
@@ -0,0 +1,18 @@
+language: go
+
+go:
+ - 1.9.x
+ - 1.10.x
+
+services:
+ - rabbitmq
+
+env:
+ - AMQP_URL=amqp://guest:guest@127.0.0.1:5672/
+
+before_install:
+ - go get -v github.com/golang/lint/golint
+
+script:
+ - ./pre-commit
+ - go test -cpu=1,2 -v -tags integration ./...
diff --git a/src/dma/vendor/github.com/streadway/amqp/CONTRIBUTING.md b/src/dma/vendor/github.com/streadway/amqp/CONTRIBUTING.md
new file mode 100644
index 00000000..c87f3d7e
--- /dev/null
+++ b/src/dma/vendor/github.com/streadway/amqp/CONTRIBUTING.md
@@ -0,0 +1,35 @@
+## Prequisites
+
+1. Go: [https://golang.org/dl/](https://golang.org/dl/)
+1. Golint `go get -u -v github.com/golang/lint/golint`
+
+## Contributing
+
+The workflow is pretty standard:
+
+1. Fork github.com/streadway/amqp
+1. Add the pre-commit hook: `ln -s ../../pre-commit .git/hooks/pre-commit`
+1. Create your feature branch (`git checkout -b my-new-feature`)
+1. Run integration tests (see below)
+1. **Implement tests**
+1. Implement fixs
+1. Commit your changes (`git commit -am 'Add some feature'`)
+1. Push to a branch (`git push -u origin my-new-feature`)
+1. Submit a pull request
+
+## Running Tests
+
+The test suite assumes that:
+
+ * A RabbitMQ node is running on localhost with all defaults: [https://www.rabbitmq.com/download.html](https://www.rabbitmq.com/download.html)
+ * `AMQP_URL` is exported to `amqp://guest:guest@127.0.0.1:5672/`
+
+### Integration Tests
+
+After starting a local RabbitMQ, run integration tests with the following:
+
+ env AMQP_URL=amqp://guest:guest@127.0.0.1:5672/ go test -v -cpu 2 -tags integration -race
+
+All integration tests should use the `integrationConnection(...)` test
+helpers defined in `integration_test.go` to setup the integration environment
+and logging.
diff --git a/src/dma/vendor/github.com/streadway/amqp/LICENSE b/src/dma/vendor/github.com/streadway/amqp/LICENSE
new file mode 100644
index 00000000..243c0ce7
--- /dev/null
+++ b/src/dma/vendor/github.com/streadway/amqp/LICENSE
@@ -0,0 +1,23 @@
+Copyright (c) 2012, Sean Treadway, SoundCloud Ltd.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+Redistributions of source code must retain the above copyright notice, this
+list of conditions and the following disclaimer.
+
+Redistributions in binary form must reproduce the above copyright notice, this
+list of conditions and the following disclaimer in the documentation and/or
+other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/src/dma/vendor/github.com/streadway/amqp/README.md b/src/dma/vendor/github.com/streadway/amqp/README.md
new file mode 100644
index 00000000..099db276
--- /dev/null
+++ b/src/dma/vendor/github.com/streadway/amqp/README.md
@@ -0,0 +1,93 @@
+[![Build Status](https://api.travis-ci.org/streadway/amqp.svg)](http://travis-ci.org/streadway/amqp) [![GoDoc](https://godoc.org/github.com/streadway/amqp?status.svg)](http://godoc.org/github.com/streadway/amqp)
+
+# Go RabbitMQ Client Library
+
+This is an AMQP 0.9.1 client with RabbitMQ extensions in Go.
+
+## Project Maturity
+
+This project has been used in production systems for many years. It is reasonably mature
+and feature complete, and as of November 2016 has [a team of maintainers](https://github.com/streadway/amqp/issues/215).
+
+Future API changes are unlikely but possible. They will be discussed on [Github
+issues](https://github.com/streadway/amqp/issues) along with any bugs or
+enhancements.
+
+## Supported Go Versions
+
+This library supports two most recent Go release series, currently 1.8 and 1.9.
+
+
+## Supported RabbitMQ Versions
+
+This project supports RabbitMQ versions starting with `2.0` but primarily tested
+against reasonably recent `3.x` releases. Some features and behaviours may be
+server version-specific.
+
+## Goals
+
+Provide a functional interface that closely represents the AMQP 0.9.1 model
+targeted to RabbitMQ as a server. This includes the minimum necessary to
+interact the semantics of the protocol.
+
+## Non-goals
+
+Things not intended to be supported.
+
+ * Auto reconnect and re-synchronization of client and server topologies.
+ * Reconnection would require understanding the error paths when the
+ topology cannot be declared on reconnect. This would require a new set
+ of types and code paths that are best suited at the call-site of this
+ package. AMQP has a dynamic topology that needs all peers to agree. If
+ this doesn't happen, the behavior is undefined. Instead of producing a
+ possible interface with undefined behavior, this package is designed to
+ be simple for the caller to implement the necessary connection-time
+ topology declaration so that reconnection is trivial and encapsulated in
+ the caller's application code.
+ * AMQP Protocol negotiation for forward or backward compatibility.
+ * 0.9.1 is stable and widely deployed. Versions 0.10 and 1.0 are divergent
+ specifications that change the semantics and wire format of the protocol.
+ We will accept patches for other protocol support but have no plans for
+ implementation ourselves.
+ * Anything other than PLAIN and EXTERNAL authentication mechanisms.
+ * Keeping the mechanisms interface modular makes it possible to extend
+ outside of this package. If other mechanisms prove to be popular, then
+ we would accept patches to include them in this package.
+
+## Usage
+
+See the 'examples' subdirectory for simple producers and consumers executables.
+If you have a use-case in mind which isn't well-represented by the examples,
+please file an issue.
+
+## Documentation
+
+Use [Godoc documentation](http://godoc.org/github.com/streadway/amqp) for
+reference and usage.
+
+[RabbitMQ tutorials in
+Go](https://github.com/rabbitmq/rabbitmq-tutorials/tree/master/go) are also
+available.
+
+## Contributing
+
+Pull requests are very much welcomed. Create your pull request on a non-master
+branch, make sure a test or example is included that covers your change and
+your commits represent coherent changes that include a reason for the change.
+
+To run the integration tests, make sure you have RabbitMQ running on any host,
+export the environment variable `AMQP_URL=amqp://host/` and run `go test -tags
+integration`. TravisCI will also run the integration tests.
+
+Thanks to the [community of contributors](https://github.com/streadway/amqp/graphs/contributors).
+
+## External packages
+
+ * [Google App Engine Dialer support](https://github.com/soundtrackyourbrand/gaeamqp)
+ * [RabbitMQ examples in Go](https://github.com/rabbitmq/rabbitmq-tutorials/tree/master/go)
+
+## License
+
+BSD 2 clause - see LICENSE for more details.
+
+
diff --git a/src/dma/vendor/github.com/streadway/amqp/allocator.go b/src/dma/vendor/github.com/streadway/amqp/allocator.go
new file mode 100644
index 00000000..53620e7d
--- /dev/null
+++ b/src/dma/vendor/github.com/streadway/amqp/allocator.go
@@ -0,0 +1,106 @@
+package amqp
+
+import (
+ "bytes"
+ "fmt"
+ "math/big"
+)
+
+const (
+ free = 0
+ allocated = 1
+)
+
+// allocator maintains a bitset of allocated numbers.
+type allocator struct {
+ pool *big.Int
+ last int
+ low int
+ high int
+}
+
+// NewAllocator reserves and frees integers out of a range between low and
+// high.
+//
+// O(N) worst case space used, where N is maximum allocated, divided by
+// sizeof(big.Word)
+func newAllocator(low, high int) *allocator {
+ return &allocator{
+ pool: big.NewInt(0),
+ last: low,
+ low: low,
+ high: high,
+ }
+}
+
+// String returns a string describing the contents of the allocator like
+// "allocator[low..high] reserved..until"
+//
+// O(N) where N is high-low
+func (a allocator) String() string {
+ b := &bytes.Buffer{}
+ fmt.Fprintf(b, "allocator[%d..%d]", a.low, a.high)
+
+ for low := a.low; low <= a.high; low++ {
+ high := low
+ for a.reserved(high) && high <= a.high {
+ high++
+ }
+
+ if high > low+1 {
+ fmt.Fprintf(b, " %d..%d", low, high-1)
+ } else if high > low {
+ fmt.Fprintf(b, " %d", high-1)
+ }
+
+ low = high
+ }
+ return b.String()
+}
+
+// Next reserves and returns the next available number out of the range between
+// low and high. If no number is available, false is returned.
+//
+// O(N) worst case runtime where N is allocated, but usually O(1) due to a
+// rolling index into the oldest allocation.
+func (a *allocator) next() (int, bool) {
+ wrapped := a.last
+
+ // Find trailing bit
+ for ; a.last <= a.high; a.last++ {
+ if a.reserve(a.last) {
+ return a.last, true
+ }
+ }
+
+ // Find preceding free'd pool
+ a.last = a.low
+
+ for ; a.last < wrapped; a.last++ {
+ if a.reserve(a.last) {
+ return a.last, true
+ }
+ }
+
+ return 0, false
+}
+
+// reserve claims the bit if it is not already claimed, returning true if
+// successfully claimed.
+func (a *allocator) reserve(n int) bool {
+ if a.reserved(n) {
+ return false
+ }
+ a.pool.SetBit(a.pool, n-a.low, allocated)
+ return true
+}
+
+// reserved returns true if the integer has been allocated
+func (a *allocator) reserved(n int) bool {
+ return a.pool.Bit(n-a.low) == allocated
+}
+
+// release frees the use of the number for another allocation
+func (a *allocator) release(n int) {
+ a.pool.SetBit(a.pool, n-a.low, free)
+}
diff --git a/src/dma/vendor/github.com/streadway/amqp/auth.go b/src/dma/vendor/github.com/streadway/amqp/auth.go
new file mode 100644
index 00000000..ebc765b6
--- /dev/null
+++ b/src/dma/vendor/github.com/streadway/amqp/auth.go
@@ -0,0 +1,46 @@
+// Copyright (c) 2012, Sean Treadway, SoundCloud Ltd.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+// Source code and contact info at http://github.com/streadway/amqp
+
+package amqp
+
+import (
+ "fmt"
+)
+
+// Authentication interface provides a means for different SASL authentication
+// mechanisms to be used during connection tuning.
+type Authentication interface {
+ Mechanism() string
+ Response() string
+}
+
+// PlainAuth is a similar to Basic Auth in HTTP.
+type PlainAuth struct {
+ Username string
+ Password string
+}
+
+// Mechanism returns "PLAIN"
+func (auth *PlainAuth) Mechanism() string {
+ return "PLAIN"
+}
+
+// Response returns the null character delimited encoding for the SASL PLAIN Mechanism.
+func (auth *PlainAuth) Response() string {
+ return fmt.Sprintf("\000%s\000%s", auth.Username, auth.Password)
+}
+
+// Finds the first mechanism preferred by the client that the server supports.
+func pickSASLMechanism(client []Authentication, serverMechanisms []string) (auth Authentication, ok bool) {
+ for _, auth = range client {
+ for _, mech := range serverMechanisms {
+ if auth.Mechanism() == mech {
+ return auth, true
+ }
+ }
+ }
+
+ return
+}
diff --git a/src/dma/vendor/github.com/streadway/amqp/certs.sh b/src/dma/vendor/github.com/streadway/amqp/certs.sh
new file mode 100755
index 00000000..834f4224
--- /dev/null
+++ b/src/dma/vendor/github.com/streadway/amqp/certs.sh
@@ -0,0 +1,159 @@
+#!/bin/sh
+#
+# Creates the CA, server and client certs to be used by tls_test.go
+# http://www.rabbitmq.com/ssl.html
+#
+# Copy stdout into the const section of tls_test.go or use for RabbitMQ
+#
+root=$PWD/certs
+
+if [ -f $root/ca/serial ]; then
+ echo >&2 "Previous installation found"
+ echo >&2 "Remove $root/ca and rerun to overwrite"
+ exit 1
+fi
+
+mkdir -p $root/ca/private
+mkdir -p $root/ca/certs
+mkdir -p $root/server
+mkdir -p $root/client
+
+cd $root/ca
+
+chmod 700 private
+touch index.txt
+echo 'unique_subject = no' > index.txt.attr
+echo '01' > serial
+echo >openssl.cnf '
+[ ca ]
+default_ca = testca
+
+[ testca ]
+dir = .
+certificate = $dir/cacert.pem
+database = $dir/index.txt
+new_certs_dir = $dir/certs
+private_key = $dir/private/cakey.pem
+serial = $dir/serial
+
+default_crl_days = 7
+default_days = 3650
+default_md = sha1
+
+policy = testca_policy
+x509_extensions = certificate_extensions
+
+[ testca_policy ]
+commonName = supplied
+stateOrProvinceName = optional
+countryName = optional
+emailAddress = optional
+organizationName = optional
+organizationalUnitName = optional
+
+[ certificate_extensions ]
+basicConstraints = CA:false
+
+[ req ]
+default_bits = 2048
+default_keyfile = ./private/cakey.pem
+default_md = sha1
+prompt = yes
+distinguished_name = root_ca_distinguished_name
+x509_extensions = root_ca_extensions
+
+[ root_ca_distinguished_name ]
+commonName = hostname
+
+[ root_ca_extensions ]
+basicConstraints = CA:true
+keyUsage = keyCertSign, cRLSign
+
+[ client_ca_extensions ]
+basicConstraints = CA:false
+keyUsage = digitalSignature
+extendedKeyUsage = 1.3.6.1.5.5.7.3.2
+
+[ server_ca_extensions ]
+basicConstraints = CA:false
+keyUsage = keyEncipherment
+extendedKeyUsage = 1.3.6.1.5.5.7.3.1
+subjectAltName = @alt_names
+
+[ alt_names ]
+IP.1 = 127.0.0.1
+'
+
+openssl req \
+ -x509 \
+ -nodes \
+ -config openssl.cnf \
+ -newkey rsa:2048 \
+ -days 3650 \
+ -subj "/CN=MyTestCA/" \
+ -out cacert.pem \
+ -outform PEM
+
+openssl x509 \
+ -in cacert.pem \
+ -out cacert.cer \
+ -outform DER
+
+openssl genrsa -out $root/server/key.pem 2048
+openssl genrsa -out $root/client/key.pem 2048
+
+openssl req \
+ -new \
+ -nodes \
+ -config openssl.cnf \
+ -subj "/CN=127.0.0.1/O=server/" \
+ -key $root/server/key.pem \
+ -out $root/server/req.pem \
+ -outform PEM
+
+openssl req \
+ -new \
+ -nodes \
+ -config openssl.cnf \
+ -subj "/CN=127.0.0.1/O=client/" \
+ -key $root/client/key.pem \
+ -out $root/client/req.pem \
+ -outform PEM
+
+openssl ca \
+ -config openssl.cnf \
+ -in $root/server/req.pem \
+ -out $root/server/cert.pem \
+ -notext \
+ -batch \
+ -extensions server_ca_extensions
+
+openssl ca \
+ -config openssl.cnf \
+ -in $root/client/req.pem \
+ -out $root/client/cert.pem \
+ -notext \
+ -batch \
+ -extensions client_ca_extensions
+
+cat <<-END
+const caCert = \`
+`cat $root/ca/cacert.pem`
+\`
+
+const serverCert = \`
+`cat $root/server/cert.pem`
+\`
+
+const serverKey = \`
+`cat $root/server/key.pem`
+\`
+
+const clientCert = \`
+`cat $root/client/cert.pem`
+\`
+
+const clientKey = \`
+`cat $root/client/key.pem`
+\`
+END
diff --git a/src/dma/vendor/github.com/streadway/amqp/channel.go b/src/dma/vendor/github.com/streadway/amqp/channel.go
new file mode 100644
index 00000000..dd2552ca
--- /dev/null
+++ b/src/dma/vendor/github.com/streadway/amqp/channel.go
@@ -0,0 +1,1587 @@
+// Copyright (c) 2012, Sean Treadway, SoundCloud Ltd.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+// Source code and contact info at http://github.com/streadway/amqp
+
+package amqp
+
+import (
+ "reflect"
+ "sync"
+ "sync/atomic"
+)
+
+// 0 1 3 7 size+7 size+8
+// +------+---------+-------------+ +------------+ +-----------+
+// | type | channel | size | | payload | | frame-end |
+// +------+---------+-------------+ +------------+ +-----------+
+// octet short long size octets octet
+const frameHeaderSize = 1 + 2 + 4 + 1
+
+/*
+Channel represents an AMQP channel. Used as a context for valid message
+exchange. Errors on methods with this Channel as a receiver means this channel
+should be discarded and a new channel established.
+
+*/
+type Channel struct {
+ destructor sync.Once
+ m sync.Mutex // struct field mutex
+ confirmM sync.Mutex // publisher confirms state mutex
+ notifyM sync.RWMutex
+
+ connection *Connection
+
+ rpc chan message
+ consumers *consumers
+
+ id uint16
+
+ // closed is set to 1 when the channel has been closed - see Channel.send()
+ closed int32
+
+ // true when we will never notify again
+ noNotify bool
+
+ // Channel and Connection exceptions will be broadcast on these listeners.
+ closes []chan *Error
+
+ // Listeners for active=true flow control. When true is sent to a listener,
+ // publishing should pause until false is sent to listeners.
+ flows []chan bool
+
+ // Listeners for returned publishings for unroutable messages on mandatory
+ // publishings or undeliverable messages on immediate publishings.
+ returns []chan Return
+
+ // Listeners for when the server notifies the client that
+ // a consumer has been cancelled.
+ cancels []chan string
+
+ // Allocated when in confirm mode in order to track publish counter and order confirms
+ confirms *confirms
+ confirming bool
+
+ // Selects on any errors from shutdown during RPC
+ errors chan *Error
+
+ // State machine that manages frame order, must only be mutated by the connection
+ recv func(*Channel, frame) error
+
+ // Current state for frame re-assembly, only mutated from recv
+ message messageWithContent
+ header *headerFrame
+ body []byte
+}
+
+// Constructs a new channel with the given framing rules
+func newChannel(c *Connection, id uint16) *Channel {
+ return &Channel{
+ connection: c,
+ id: id,
+ rpc: make(chan message),
+ consumers: makeConsumers(),
+ confirms: newConfirms(),
+ recv: (*Channel).recvMethod,
+ errors: make(chan *Error, 1),
+ }
+}
+
+// shutdown is called by Connection after the channel has been removed from the
+// connection registry.
+func (ch *Channel) shutdown(e *Error) {
+ ch.destructor.Do(func() {
+ ch.m.Lock()
+ defer ch.m.Unlock()
+
+ // Grab an exclusive lock for the notify channels
+ ch.notifyM.Lock()
+ defer ch.notifyM.Unlock()
+
+ // Broadcast abnormal shutdown
+ if e != nil {
+ for _, c := range ch.closes {
+ c <- e
+ }
+ }
+
+ // Signal that from now on, Channel.send() should call
+ // Channel.sendClosed()
+ atomic.StoreInt32(&ch.closed, 1)
+
+ // Notify RPC if we're selecting
+ if e != nil {
+ ch.errors <- e
+ }
+
+ ch.consumers.close()
+
+ for _, c := range ch.closes {
+ close(c)
+ }
+
+ for _, c := range ch.flows {
+ close(c)
+ }
+
+ for _, c := range ch.returns {
+ close(c)
+ }
+
+ for _, c := range ch.cancels {
+ close(c)
+ }
+
+ // Set the slices to nil to prevent the dispatch() range from sending on
+ // the now closed channels after we release the notifyM mutex
+ ch.flows = nil
+ ch.closes = nil
+ ch.returns = nil
+ ch.cancels = nil
+
+ if ch.confirms != nil {
+ ch.confirms.Close()
+ }
+
+ close(ch.errors)
+ ch.noNotify = true
+ })
+}
+
+// send calls Channel.sendOpen() during normal operation.
+//
+// After the channel has been closed, send calls Channel.sendClosed(), ensuring
+// only 'channel.close' is sent to the server.
+func (ch *Channel) send(msg message) (err error) {
+ // If the channel is closed, use Channel.sendClosed()
+ if atomic.LoadInt32(&ch.closed) == 1 {
+ return ch.sendClosed(msg)
+ }
+
+ return ch.sendOpen(msg)
+}
+
+func (ch *Channel) open() error {
+ return ch.call(&channelOpen{}, &channelOpenOk{})
+}
+
+// Performs a request/response call for when the message is not NoWait and is
+// specified as Synchronous.
+func (ch *Channel) call(req message, res ...message) error {
+ if err := ch.send(req); err != nil {
+ return err
+ }
+
+ if req.wait() {
+ select {
+ case e, ok := <-ch.errors:
+ if ok {
+ return e
+ }
+ return ErrClosed
+
+ case msg := <-ch.rpc:
+ if msg != nil {
+ for _, try := range res {
+ if reflect.TypeOf(msg) == reflect.TypeOf(try) {
+ // *res = *msg
+ vres := reflect.ValueOf(try).Elem()
+ vmsg := reflect.ValueOf(msg).Elem()
+ vres.Set(vmsg)
+ return nil
+ }
+ }
+ return ErrCommandInvalid
+ }
+ // RPC channel has been closed without an error, likely due to a hard
+ // error on the Connection. This indicates we have already been
+ // shutdown and if were waiting, will have returned from the errors chan.
+ return ErrClosed
+ }
+ }
+
+ return nil
+}
+
+func (ch *Channel) sendClosed(msg message) (err error) {
+ // After a 'channel.close' is sent or received the only valid response is
+ // channel.close-ok
+ if _, ok := msg.(*channelCloseOk); ok {
+ return ch.connection.send(&methodFrame{
+ ChannelId: ch.id,
+ Method: msg,
+ })
+ }
+
+ return ErrClosed
+}
+
+func (ch *Channel) sendOpen(msg message) (err error) {
+ if content, ok := msg.(messageWithContent); ok {
+ props, body := content.getContent()
+ class, _ := content.id()
+
+ // catch client max frame size==0 and server max frame size==0
+ // set size to length of what we're trying to publish
+ var size int
+ if ch.connection.Config.FrameSize > 0 {
+ size = ch.connection.Config.FrameSize - frameHeaderSize
+ } else {
+ size = len(body)
+ }
+
+ if err = ch.connection.send(&methodFrame{
+ ChannelId: ch.id,
+ Method: content,
+ }); err != nil {
+ return
+ }
+
+ if err = ch.connection.send(&headerFrame{
+ ChannelId: ch.id,
+ ClassId: class,
+ Size: uint64(len(body)),
+ Properties: props,
+ }); err != nil {
+ return
+ }
+
+ // chunk body into size (max frame size - frame header size)
+ for i, j := 0, size; i < len(body); i, j = j, j+size {
+ if j > len(body) {
+ j = len(body)
+ }
+
+ if err = ch.connection.send(&bodyFrame{
+ ChannelId: ch.id,
+ Body: body[i:j],
+ }); err != nil {
+ return
+ }
+ }
+ } else {
+ err = ch.connection.send(&methodFrame{
+ ChannelId: ch.id,
+ Method: msg,
+ })
+ }
+
+ return
+}
+
+// Eventually called via the state machine from the connection's reader
+// goroutine, so assumes serialized access.
+func (ch *Channel) dispatch(msg message) {
+ switch m := msg.(type) {
+ case *channelClose:
+ // lock before sending connection.close-ok
+ // to avoid unexpected interleaving with basic.publish frames if
+ // publishing is happening concurrently
+ ch.m.Lock()
+ ch.send(&channelCloseOk{})
+ ch.m.Unlock()
+ ch.connection.closeChannel(ch, newError(m.ReplyCode, m.ReplyText))
+
+ case *channelFlow:
+ ch.notifyM.RLock()
+ for _, c := range ch.flows {
+ c <- m.Active
+ }
+ ch.notifyM.RUnlock()
+ ch.send(&channelFlowOk{Active: m.Active})
+
+ case *basicCancel:
+ ch.notifyM.RLock()
+ for _, c := range ch.cancels {
+ c <- m.ConsumerTag
+ }
+ ch.notifyM.RUnlock()
+ ch.consumers.cancel(m.ConsumerTag)
+
+ case *basicReturn:
+ ret := newReturn(*m)
+ ch.notifyM.RLock()
+ for _, c := range ch.returns {
+ c <- *ret
+ }
+ ch.notifyM.RUnlock()
+
+ case *basicAck:
+ if ch.confirming {
+ if m.Multiple {
+ ch.confirms.Multiple(Confirmation{m.DeliveryTag, true})
+ } else {
+ ch.confirms.One(Confirmation{m.DeliveryTag, true})
+ }
+ }
+
+ case *basicNack:
+ if ch.confirming {
+ if m.Multiple {
+ ch.confirms.Multiple(Confirmation{m.DeliveryTag, false})
+ } else {
+ ch.confirms.One(Confirmation{m.DeliveryTag, false})
+ }
+ }
+
+ case *basicDeliver:
+ ch.consumers.send(m.ConsumerTag, newDelivery(ch, m))
+ // TODO log failed consumer and close channel, this can happen when
+ // deliveries are in flight and a no-wait cancel has happened
+
+ default:
+ ch.rpc <- msg
+ }
+}
+
+func (ch *Channel) transition(f func(*Channel, frame) error) error {
+ ch.recv = f
+ return nil
+}
+
+func (ch *Channel) recvMethod(f frame) error {
+ switch frame := f.(type) {
+ case *methodFrame:
+ if msg, ok := frame.Method.(messageWithContent); ok {
+ ch.body = make([]byte, 0)
+ ch.message = msg
+ return ch.transition((*Channel).recvHeader)
+ }
+
+ ch.dispatch(frame.Method) // termination state
+ return ch.transition((*Channel).recvMethod)
+
+ case *headerFrame:
+ // drop
+ return ch.transition((*Channel).recvMethod)
+
+ case *bodyFrame:
+ // drop
+ return ch.transition((*Channel).recvMethod)
+ }
+
+ panic("unexpected frame type")
+}
+
+func (ch *Channel) recvHeader(f frame) error {
+ switch frame := f.(type) {
+ case *methodFrame:
+ // interrupt content and handle method
+ return ch.recvMethod(f)
+
+ case *headerFrame:
+ // start collecting if we expect body frames
+ ch.header = frame
+
+ if frame.Size == 0 {
+ ch.message.setContent(ch.header.Properties, ch.body)
+ ch.dispatch(ch.message) // termination state
+ return ch.transition((*Channel).recvMethod)
+ }
+ return ch.transition((*Channel).recvContent)
+
+ case *bodyFrame:
+ // drop and reset
+ return ch.transition((*Channel).recvMethod)
+ }
+
+ panic("unexpected frame type")
+}
+
+// state after method + header and before the length
+// defined by the header has been reached
+func (ch *Channel) recvContent(f frame) error {
+ switch frame := f.(type) {
+ case *methodFrame:
+ // interrupt content and handle method
+ return ch.recvMethod(f)
+
+ case *headerFrame:
+ // drop and reset
+ return ch.transition((*Channel).recvMethod)
+
+ case *bodyFrame:
+ ch.body = append(ch.body, frame.Body...)
+
+ if uint64(len(ch.body)) >= ch.header.Size {
+ ch.message.setContent(ch.header.Properties, ch.body)
+ ch.dispatch(ch.message) // termination state
+ return ch.transition((*Channel).recvMethod)
+ }
+
+ return ch.transition((*Channel).recvContent)
+ }
+
+ panic("unexpected frame type")
+}
+
+/*
+Close initiate a clean channel closure by sending a close message with the error
+code set to '200'.
+
+It is safe to call this method multiple times.
+
+*/
+func (ch *Channel) Close() error {
+ defer ch.connection.closeChannel(ch, nil)
+ return ch.call(
+ &channelClose{ReplyCode: replySuccess},
+ &channelCloseOk{},
+ )
+}
+
+/*
+NotifyClose registers a listener for when the server sends a channel or
+connection exception in the form of a Connection.Close or Channel.Close method.
+Connection exceptions will be broadcast to all open channels and all channels
+will be closed, where channel exceptions will only be broadcast to listeners to
+this channel.
+
+The chan provided will be closed when the Channel is closed and on a
+graceful close, no error will be sent.
+
+*/
+func (ch *Channel) NotifyClose(c chan *Error) chan *Error {
+ ch.notifyM.Lock()
+ defer ch.notifyM.Unlock()
+
+ if ch.noNotify {
+ close(c)
+ } else {
+ ch.closes = append(ch.closes, c)
+ }
+
+ return c
+}
+
+/*
+NotifyFlow registers a listener for basic.flow methods sent by the server.
+When `false` is sent on one of the listener channels, all publishers should
+pause until a `true` is sent.
+
+The server may ask the producer to pause or restart the flow of Publishings
+sent by on a channel. This is a simple flow-control mechanism that a server can
+use to avoid overflowing its queues or otherwise finding itself receiving more
+messages than it can process. Note that this method is not intended for window
+control. It does not affect contents returned by basic.get-ok methods.
+
+When a new channel is opened, it is active (flow is active). Some
+applications assume that channels are inactive until started. To emulate
+this behavior a client MAY open the channel, then pause it.
+
+Publishers should respond to a flow messages as rapidly as possible and the
+server may disconnect over producing channels that do not respect these
+messages.
+
+basic.flow-ok methods will always be returned to the server regardless of
+the number of listeners there are.
+
+To control the flow of deliveries from the server, use the Channel.Flow()
+method instead.
+
+Note: RabbitMQ will rather use TCP pushback on the network connection instead
+of sending basic.flow. This means that if a single channel is producing too
+much on the same connection, all channels using that connection will suffer,
+including acknowledgments from deliveries. Use different Connections if you
+desire to interleave consumers and producers in the same process to avoid your
+basic.ack messages from getting rate limited with your basic.publish messages.
+
+*/
+func (ch *Channel) NotifyFlow(c chan bool) chan bool {
+ ch.notifyM.Lock()
+ defer ch.notifyM.Unlock()
+
+ if ch.noNotify {
+ close(c)
+ } else {
+ ch.flows = append(ch.flows, c)
+ }
+
+ return c
+}
+
+/*
+NotifyReturn registers a listener for basic.return methods. These can be sent
+from the server when a publish is undeliverable either from the mandatory or
+immediate flags.
+
+A return struct has a copy of the Publishing along with some error
+information about why the publishing failed.
+
+*/
+func (ch *Channel) NotifyReturn(c chan Return) chan Return {
+ ch.notifyM.Lock()
+ defer ch.notifyM.Unlock()
+
+ if ch.noNotify {
+ close(c)
+ } else {
+ ch.returns = append(ch.returns, c)
+ }
+
+ return c
+}
+
+/*
+NotifyCancel registers a listener for basic.cancel methods. These can be sent
+from the server when a queue is deleted or when consuming from a mirrored queue
+where the master has just failed (and was moved to another node).
+
+The subscription tag is returned to the listener.
+
+*/
+func (ch *Channel) NotifyCancel(c chan string) chan string {
+ ch.notifyM.Lock()
+ defer ch.notifyM.Unlock()
+
+ if ch.noNotify {
+ close(c)
+ } else {
+ ch.cancels = append(ch.cancels, c)
+ }
+
+ return c
+}
+
+/*
+NotifyConfirm calls NotifyPublish and starts a goroutine sending
+ordered Ack and Nack DeliveryTag to the respective channels.
+
+For strict ordering, use NotifyPublish instead.
+*/
+func (ch *Channel) NotifyConfirm(ack, nack chan uint64) (chan uint64, chan uint64) {
+ confirms := ch.NotifyPublish(make(chan Confirmation, len(ack)+len(nack)))
+
+ go func() {
+ for c := range confirms {
+ if c.Ack {
+ ack <- c.DeliveryTag
+ } else {
+ nack <- c.DeliveryTag
+ }
+ }
+ close(ack)
+ if nack != ack {
+ close(nack)
+ }
+ }()
+
+ return ack, nack
+}
+
+/*
+NotifyPublish registers a listener for reliable publishing. Receives from this
+chan for every publish after Channel.Confirm will be in order starting with
+DeliveryTag 1.
+
+There will be one and only one Confirmation Publishing starting with the
+delivery tag of 1 and progressing sequentially until the total number of
+Publishings have been seen by the server.
+
+Acknowledgments will be received in the order of delivery from the
+NotifyPublish channels even if the server acknowledges them out of order.
+
+The listener chan will be closed when the Channel is closed.
+
+The capacity of the chan Confirmation must be at least as large as the
+number of outstanding publishings. Not having enough buffered chans will
+create a deadlock if you attempt to perform other operations on the Connection
+or Channel while confirms are in-flight.
+
+It's advisable to wait for all Confirmations to arrive before calling
+Channel.Close() or Connection.Close().
+
+*/
+func (ch *Channel) NotifyPublish(confirm chan Confirmation) chan Confirmation {
+ ch.notifyM.Lock()
+ defer ch.notifyM.Unlock()
+
+ if ch.noNotify {
+ close(confirm)
+ } else {
+ ch.confirms.Listen(confirm)
+ }
+
+ return confirm
+
+}
+
+/*
+Qos controls how many messages or how many bytes the server will try to keep on
+the network for consumers before receiving delivery acks. The intent of Qos is
+to make sure the network buffers stay full between the server and client.
+
+With a prefetch count greater than zero, the server will deliver that many
+messages to consumers before acknowledgments are received. The server ignores
+this option when consumers are started with noAck because no acknowledgments
+are expected or sent.
+
+With a prefetch size greater than zero, the server will try to keep at least
+that many bytes of deliveries flushed to the network before receiving
+acknowledgments from the consumers. This option is ignored when consumers are
+started with noAck.
+
+When global is true, these Qos settings apply to all existing and future
+consumers on all channels on the same connection. When false, the Channel.Qos
+settings will apply to all existing and future consumers on this channel.
+
+Please see the RabbitMQ Consumer Prefetch documentation for an explanation of
+how the global flag is implemented in RabbitMQ, as it differs from the
+AMQP 0.9.1 specification in that global Qos settings are limited in scope to
+channels, not connections (https://www.rabbitmq.com/consumer-prefetch.html).
+
+To get round-robin behavior between consumers consuming from the same queue on
+different connections, set the prefetch count to 1, and the next available
+message on the server will be delivered to the next available consumer.
+
+If your consumer work time is reasonably consistent and not much greater
+than two times your network round trip time, you will see significant
+throughput improvements starting with a prefetch count of 2 or slightly
+greater as described by benchmarks on RabbitMQ.
+
+http://www.rabbitmq.com/blog/2012/04/25/rabbitmq-performance-measurements-part-2/
+*/
+func (ch *Channel) Qos(prefetchCount, prefetchSize int, global bool) error {
+ return ch.call(
+ &basicQos{
+ PrefetchCount: uint16(prefetchCount),
+ PrefetchSize: uint32(prefetchSize),
+ Global: global,
+ },
+ &basicQosOk{},
+ )
+}
+
+/*
+Cancel stops deliveries to the consumer chan established in Channel.Consume and
+identified by consumer.
+
+Only use this method to cleanly stop receiving deliveries from the server and
+cleanly shut down the consumer chan identified by this tag. Using this method
+and waiting for remaining messages to flush from the consumer chan will ensure
+all messages received on the network will be delivered to the receiver of your
+consumer chan.
+
+Continue consuming from the chan Delivery provided by Channel.Consume until the
+chan closes.
+
+When noWait is true, do not wait for the server to acknowledge the cancel.
+Only use this when you are certain there are no deliveries in flight that
+require an acknowledgment, otherwise they will arrive and be dropped in the
+client without an ack, and will not be redelivered to other consumers.
+
+*/
+func (ch *Channel) Cancel(consumer string, noWait bool) error {
+ req := &basicCancel{
+ ConsumerTag: consumer,
+ NoWait: noWait,
+ }
+ res := &basicCancelOk{}
+
+ if err := ch.call(req, res); err != nil {
+ return err
+ }
+
+ if req.wait() {
+ ch.consumers.cancel(res.ConsumerTag)
+ } else {
+ // Potentially could drop deliveries in flight
+ ch.consumers.cancel(consumer)
+ }
+
+ return nil
+}
+
+/*
+QueueDeclare declares a queue to hold messages and deliver to consumers.
+Declaring creates a queue if it doesn't already exist, or ensures that an
+existing queue matches the same parameters.
+
+Every queue declared gets a default binding to the empty exchange "" which has
+the type "direct" with the routing key matching the queue's name. With this
+default binding, it is possible to publish messages that route directly to
+this queue by publishing to "" with the routing key of the queue name.
+
+ QueueDeclare("alerts", true, false, false, false, nil)
+ Publish("", "alerts", false, false, Publishing{Body: []byte("...")})
+
+ Delivery Exchange Key Queue
+ -----------------------------------------------
+ key: alerts -> "" -> alerts -> alerts
+
+The queue name may be empty, in which case the server will generate a unique name
+which will be returned in the Name field of Queue struct.
+
+Durable and Non-Auto-Deleted queues will survive server restarts and remain
+when there are no remaining consumers or bindings. Persistent publishings will
+be restored in this queue on server restart. These queues are only able to be
+bound to durable exchanges.
+
+Non-Durable and Auto-Deleted queues will not be redeclared on server restart
+and will be deleted by the server after a short time when the last consumer is
+canceled or the last consumer's channel is closed. Queues with this lifetime
+can also be deleted normally with QueueDelete. These durable queues can only
+be bound to non-durable exchanges.
+
+Non-Durable and Non-Auto-Deleted queues will remain declared as long as the
+server is running regardless of how many consumers. This lifetime is useful
+for temporary topologies that may have long delays between consumer activity.
+These queues can only be bound to non-durable exchanges.
+
+Durable and Auto-Deleted queues will be restored on server restart, but without
+active consumers will not survive and be removed. This Lifetime is unlikely
+to be useful.
+
+Exclusive queues are only accessible by the connection that declares them and
+will be deleted when the connection closes. Channels on other connections
+will receive an error when attempting to declare, bind, consume, purge or
+delete a queue with the same name.
+
+When noWait is true, the queue will assume to be declared on the server. A
+channel exception will arrive if the conditions are met for existing queues
+or attempting to modify an existing queue from a different connection.
+
+When the error return value is not nil, you can assume the queue could not be
+declared with these parameters, and the channel will be closed.
+
+*/
+func (ch *Channel) QueueDeclare(name string, durable, autoDelete, exclusive, noWait bool, args Table) (Queue, error) {
+ if err := args.Validate(); err != nil {
+ return Queue{}, err
+ }
+
+ req := &queueDeclare{
+ Queue: name,
+ Passive: false,
+ Durable: durable,
+ AutoDelete: autoDelete,
+ Exclusive: exclusive,
+ NoWait: noWait,
+ Arguments: args,
+ }
+ res := &queueDeclareOk{}
+
+ if err := ch.call(req, res); err != nil {
+ return Queue{}, err
+ }
+
+ if req.wait() {
+ return Queue{
+ Name: res.Queue,
+ Messages: int(res.MessageCount),
+ Consumers: int(res.ConsumerCount),
+ }, nil
+ }
+
+ return Queue{Name: name}, nil
+}
+
+/*
+
+QueueDeclarePassive is functionally and parametrically equivalent to
+QueueDeclare, except that it sets the "passive" attribute to true. A passive
+queue is assumed by RabbitMQ to already exist, and attempting to connect to a
+non-existent queue will cause RabbitMQ to throw an exception. This function
+can be used to test for the existence of a queue.
+
+*/
+func (ch *Channel) QueueDeclarePassive(name string, durable, autoDelete, exclusive, noWait bool, args Table) (Queue, error) {
+ if err := args.Validate(); err != nil {
+ return Queue{}, err
+ }
+
+ req := &queueDeclare{
+ Queue: name,
+ Passive: true,
+ Durable: durable,
+ AutoDelete: autoDelete,
+ Exclusive: exclusive,
+ NoWait: noWait,
+ Arguments: args,
+ }
+ res := &queueDeclareOk{}
+
+ if err := ch.call(req, res); err != nil {
+ return Queue{}, err
+ }
+
+ if req.wait() {
+ return Queue{
+ Name: res.Queue,
+ Messages: int(res.MessageCount),
+ Consumers: int(res.ConsumerCount),
+ }, nil
+ }
+
+ return Queue{Name: name}, nil
+}
+
+/*
+QueueInspect passively declares a queue by name to inspect the current message
+count and consumer count.
+
+Use this method to check how many messages ready for delivery reside in the queue,
+how many consumers are receiving deliveries, and whether a queue by this
+name already exists.
+
+If the queue by this name exists, use Channel.QueueDeclare check if it is
+declared with specific parameters.
+
+If a queue by this name does not exist, an error will be returned and the
+channel will be closed.
+
+*/
+func (ch *Channel) QueueInspect(name string) (Queue, error) {
+ req := &queueDeclare{
+ Queue: name,
+ Passive: true,
+ }
+ res := &queueDeclareOk{}
+
+ err := ch.call(req, res)
+
+ state := Queue{
+ Name: name,
+ Messages: int(res.MessageCount),
+ Consumers: int(res.ConsumerCount),
+ }
+
+ return state, err
+}
+
+/*
+QueueBind binds an exchange to a queue so that publishings to the exchange will
+be routed to the queue when the publishing routing key matches the binding
+routing key.
+
+ QueueBind("pagers", "alert", "log", false, nil)
+ QueueBind("emails", "info", "log", false, nil)
+
+ Delivery Exchange Key Queue
+ -----------------------------------------------
+ key: alert --> log ----> alert --> pagers
+ key: info ---> log ----> info ---> emails
+ key: debug --> log (none) (dropped)
+
+If a binding with the same key and arguments already exists between the
+exchange and queue, the attempt to rebind will be ignored and the existing
+binding will be retained.
+
+In the case that multiple bindings may cause the message to be routed to the
+same queue, the server will only route the publishing once. This is possible
+with topic exchanges.
+
+ QueueBind("pagers", "alert", "amq.topic", false, nil)
+ QueueBind("emails", "info", "amq.topic", false, nil)
+ QueueBind("emails", "#", "amq.topic", false, nil) // match everything
+
+ Delivery Exchange Key Queue
+ -----------------------------------------------
+ key: alert --> amq.topic ----> alert --> pagers
+ key: info ---> amq.topic ----> # ------> emails
+ \---> info ---/
+ key: debug --> amq.topic ----> # ------> emails
+
+It is only possible to bind a durable queue to a durable exchange regardless of
+whether the queue or exchange is auto-deleted. Bindings between durable queues
+and exchanges will also be restored on server restart.
+
+If the binding could not complete, an error will be returned and the channel
+will be closed.
+
+When noWait is true and the queue could not be bound, the channel will be
+closed with an error.
+
+*/
+func (ch *Channel) QueueBind(name, key, exchange string, noWait bool, args Table) error {
+ if err := args.Validate(); err != nil {
+ return err
+ }
+
+ return ch.call(
+ &queueBind{
+ Queue: name,
+ Exchange: exchange,
+ RoutingKey: key,
+ NoWait: noWait,
+ Arguments: args,
+ },
+ &queueBindOk{},
+ )
+}
+
+/*
+QueueUnbind removes a binding between an exchange and queue matching the key and
+arguments.
+
+It is possible to send and empty string for the exchange name which means to
+unbind the queue from the default exchange.
+
+*/
+func (ch *Channel) QueueUnbind(name, key, exchange string, args Table) error {
+ if err := args.Validate(); err != nil {
+ return err
+ }
+
+ return ch.call(
+ &queueUnbind{
+ Queue: name,
+ Exchange: exchange,
+ RoutingKey: key,
+ Arguments: args,
+ },
+ &queueUnbindOk{},
+ )
+}
+
+/*
+QueuePurge removes all messages from the named queue which are not waiting to
+be acknowledged. Messages that have been delivered but have not yet been
+acknowledged will not be removed.
+
+When successful, returns the number of messages purged.
+
+If noWait is true, do not wait for the server response and the number of
+messages purged will not be meaningful.
+*/
+func (ch *Channel) QueuePurge(name string, noWait bool) (int, error) {
+ req := &queuePurge{
+ Queue: name,
+ NoWait: noWait,
+ }
+ res := &queuePurgeOk{}
+
+ err := ch.call(req, res)
+
+ return int(res.MessageCount), err
+}
+
+/*
+QueueDelete removes the queue from the server including all bindings then
+purges the messages based on server configuration, returning the number of
+messages purged.
+
+When ifUnused is true, the queue will not be deleted if there are any
+consumers on the queue. If there are consumers, an error will be returned and
+the channel will be closed.
+
+When ifEmpty is true, the queue will not be deleted if there are any messages
+remaining on the queue. If there are messages, an error will be returned and
+the channel will be closed.
+
+When noWait is true, the queue will be deleted without waiting for a response
+from the server. The purged message count will not be meaningful. If the queue
+could not be deleted, a channel exception will be raised and the channel will
+be closed.
+
+*/
+func (ch *Channel) QueueDelete(name string, ifUnused, ifEmpty, noWait bool) (int, error) {
+ req := &queueDelete{
+ Queue: name,
+ IfUnused: ifUnused,
+ IfEmpty: ifEmpty,
+ NoWait: noWait,
+ }
+ res := &queueDeleteOk{}
+
+ err := ch.call(req, res)
+
+ return int(res.MessageCount), err
+}
+
+/*
+Consume immediately starts delivering queued messages.
+
+Begin receiving on the returned chan Delivery before any other operation on the
+Connection or Channel.
+
+Continues deliveries to the returned chan Delivery until Channel.Cancel,
+Connection.Close, Channel.Close, or an AMQP exception occurs. Consumers must
+range over the chan to ensure all deliveries are received. Unreceived
+deliveries will block all methods on the same connection.
+
+All deliveries in AMQP must be acknowledged. It is expected of the consumer to
+call Delivery.Ack after it has successfully processed the delivery. If the
+consumer is cancelled or the channel or connection is closed any unacknowledged
+deliveries will be requeued at the end of the same queue.
+
+The consumer is identified by a string that is unique and scoped for all
+consumers on this channel. If you wish to eventually cancel the consumer, use
+the same non-empty identifier in Channel.Cancel. An empty string will cause
+the library to generate a unique identity. The consumer identity will be
+included in every Delivery in the ConsumerTag field
+
+When autoAck (also known as noAck) is true, the server will acknowledge
+deliveries to this consumer prior to writing the delivery to the network. When
+autoAck is true, the consumer should not call Delivery.Ack. Automatically
+acknowledging deliveries means that some deliveries may get lost if the
+consumer is unable to process them after the server delivers them.
+See http://www.rabbitmq.com/confirms.html for more details.
+
+When exclusive is true, the server will ensure that this is the sole consumer
+from this queue. When exclusive is false, the server will fairly distribute
+deliveries across multiple consumers.
+
+The noLocal flag is not supported by RabbitMQ.
+
+It's advisable to use separate connections for
+Channel.Publish and Channel.Consume so not to have TCP pushback on publishing
+affect the ability to consume messages, so this parameter is here mostly for
+completeness.
+
+When noWait is true, do not wait for the server to confirm the request and
+immediately begin deliveries. If it is not possible to consume, a channel
+exception will be raised and the channel will be closed.
+
+Optional arguments can be provided that have specific semantics for the queue
+or server.
+
+Inflight messages, limited by Channel.Qos will be buffered until received from
+the returned chan.
+
+When the Channel or Connection is closed, all buffered and inflight messages will
+be dropped.
+
+When the consumer tag is cancelled, all inflight messages will be delivered until
+the returned chan is closed.
+
+*/
+func (ch *Channel) Consume(queue, consumer string, autoAck, exclusive, noLocal, noWait bool, args Table) (<-chan Delivery, error) {
+ // When we return from ch.call, there may be a delivery already for the
+ // consumer that hasn't been added to the consumer hash yet. Because of
+ // this, we never rely on the server picking a consumer tag for us.
+
+ if err := args.Validate(); err != nil {
+ return nil, err
+ }
+
+ if consumer == "" {
+ consumer = uniqueConsumerTag()
+ }
+
+ req := &basicConsume{
+ Queue: queue,
+ ConsumerTag: consumer,
+ NoLocal: noLocal,
+ NoAck: autoAck,
+ Exclusive: exclusive,
+ NoWait: noWait,
+ Arguments: args,
+ }
+ res := &basicConsumeOk{}
+
+ deliveries := make(chan Delivery)
+
+ ch.consumers.add(consumer, deliveries)
+
+ if err := ch.call(req, res); err != nil {
+ ch.consumers.cancel(consumer)
+ return nil, err
+ }
+
+ return (<-chan Delivery)(deliveries), nil
+}
+
+/*
+ExchangeDeclare declares an exchange on the server. If the exchange does not
+already exist, the server will create it. If the exchange exists, the server
+verifies that it is of the provided type, durability and auto-delete flags.
+
+Errors returned from this method will close the channel.
+
+Exchange names starting with "amq." are reserved for pre-declared and
+standardized exchanges. The client MAY declare an exchange starting with
+"amq." if the passive option is set, or the exchange already exists. Names can
+consist of a non-empty sequence of letters, digits, hyphen, underscore,
+period, or colon.
+
+Each exchange belongs to one of a set of exchange kinds/types implemented by
+the server. The exchange types define the functionality of the exchange - i.e.
+how messages are routed through it. Once an exchange is declared, its type
+cannot be changed. The common types are "direct", "fanout", "topic" and
+"headers".
+
+Durable and Non-Auto-Deleted exchanges will survive server restarts and remain
+declared when there are no remaining bindings. This is the best lifetime for
+long-lived exchange configurations like stable routes and default exchanges.
+
+Non-Durable and Auto-Deleted exchanges will be deleted when there are no
+remaining bindings and not restored on server restart. This lifetime is
+useful for temporary topologies that should not pollute the virtual host on
+failure or after the consumers have completed.
+
+Non-Durable and Non-Auto-deleted exchanges will remain as long as the server is
+running including when there are no remaining bindings. This is useful for
+temporary topologies that may have long delays between bindings.
+
+Durable and Auto-Deleted exchanges will survive server restarts and will be
+removed before and after server restarts when there are no remaining bindings.
+These exchanges are useful for robust temporary topologies or when you require
+binding durable queues to auto-deleted exchanges.
+
+Note: RabbitMQ declares the default exchange types like 'amq.fanout' as
+durable, so queues that bind to these pre-declared exchanges must also be
+durable.
+
+Exchanges declared as `internal` do not accept accept publishings. Internal
+exchanges are useful when you wish to implement inter-exchange topologies
+that should not be exposed to users of the broker.
+
+When noWait is true, declare without waiting for a confirmation from the server.
+The channel may be closed as a result of an error. Add a NotifyClose listener
+to respond to any exceptions.
+
+Optional amqp.Table of arguments that are specific to the server's implementation of
+the exchange can be sent for exchange types that require extra parameters.
+*/
+func (ch *Channel) ExchangeDeclare(name, kind string, durable, autoDelete, internal, noWait bool, args Table) error {
+ if err := args.Validate(); err != nil {
+ return err
+ }
+
+ return ch.call(
+ &exchangeDeclare{
+ Exchange: name,
+ Type: kind,
+ Passive: false,
+ Durable: durable,
+ AutoDelete: autoDelete,
+ Internal: internal,
+ NoWait: noWait,
+ Arguments: args,
+ },
+ &exchangeDeclareOk{},
+ )
+}
+
+/*
+
+ExchangeDeclarePassive is functionally and parametrically equivalent to
+ExchangeDeclare, except that it sets the "passive" attribute to true. A passive
+exchange is assumed by RabbitMQ to already exist, and attempting to connect to a
+non-existent exchange will cause RabbitMQ to throw an exception. This function
+can be used to detect the existence of an exchange.
+
+*/
+func (ch *Channel) ExchangeDeclarePassive(name, kind string, durable, autoDelete, internal, noWait bool, args Table) error {
+ if err := args.Validate(); err != nil {
+ return err
+ }
+
+ return ch.call(
+ &exchangeDeclare{
+ Exchange: name,
+ Type: kind,
+ Passive: true,
+ Durable: durable,
+ AutoDelete: autoDelete,
+ Internal: internal,
+ NoWait: noWait,
+ Arguments: args,
+ },
+ &exchangeDeclareOk{},
+ )
+}
+
+/*
+ExchangeDelete removes the named exchange from the server. When an exchange is
+deleted all queue bindings on the exchange are also deleted. If this exchange
+does not exist, the channel will be closed with an error.
+
+When ifUnused is true, the server will only delete the exchange if it has no queue
+bindings. If the exchange has queue bindings the server does not delete it
+but close the channel with an exception instead. Set this to true if you are
+not the sole owner of the exchange.
+
+When noWait is true, do not wait for a server confirmation that the exchange has
+been deleted. Failing to delete the channel could close the channel. Add a
+NotifyClose listener to respond to these channel exceptions.
+*/
+func (ch *Channel) ExchangeDelete(name string, ifUnused, noWait bool) error {
+ return ch.call(
+ &exchangeDelete{
+ Exchange: name,
+ IfUnused: ifUnused,
+ NoWait: noWait,
+ },
+ &exchangeDeleteOk{},
+ )
+}
+
+/*
+ExchangeBind binds an exchange to another exchange to create inter-exchange
+routing topologies on the server. This can decouple the private topology and
+routing exchanges from exchanges intended solely for publishing endpoints.
+
+Binding two exchanges with identical arguments will not create duplicate
+bindings.
+
+Binding one exchange to another with multiple bindings will only deliver a
+message once. For example if you bind your exchange to `amq.fanout` with two
+different binding keys, only a single message will be delivered to your
+exchange even though multiple bindings will match.
+
+Given a message delivered to the source exchange, the message will be forwarded
+to the destination exchange when the routing key is matched.
+
+ ExchangeBind("sell", "MSFT", "trade", false, nil)
+ ExchangeBind("buy", "AAPL", "trade", false, nil)
+
+ Delivery Source Key Destination
+ example exchange exchange
+ -----------------------------------------------
+ key: AAPL --> trade ----> MSFT sell
+ \---> AAPL --> buy
+
+When noWait is true, do not wait for the server to confirm the binding. If any
+error occurs the channel will be closed. Add a listener to NotifyClose to
+handle these errors.
+
+Optional arguments specific to the exchanges bound can also be specified.
+*/
+func (ch *Channel) ExchangeBind(destination, key, source string, noWait bool, args Table) error {
+ if err := args.Validate(); err != nil {
+ return err
+ }
+
+ return ch.call(
+ &exchangeBind{
+ Destination: destination,
+ Source: source,
+ RoutingKey: key,
+ NoWait: noWait,
+ Arguments: args,
+ },
+ &exchangeBindOk{},
+ )
+}
+
+/*
+ExchangeUnbind unbinds the destination exchange from the source exchange on the
+server by removing the routing key between them. This is the inverse of
+ExchangeBind. If the binding does not currently exist, an error will be
+returned.
+
+When noWait is true, do not wait for the server to confirm the deletion of the
+binding. If any error occurs the channel will be closed. Add a listener to
+NotifyClose to handle these errors.
+
+Optional arguments that are specific to the type of exchanges bound can also be
+provided. These must match the same arguments specified in ExchangeBind to
+identify the binding.
+*/
+func (ch *Channel) ExchangeUnbind(destination, key, source string, noWait bool, args Table) error {
+ if err := args.Validate(); err != nil {
+ return err
+ }
+
+ return ch.call(
+ &exchangeUnbind{
+ Destination: destination,
+ Source: source,
+ RoutingKey: key,
+ NoWait: noWait,
+ Arguments: args,
+ },
+ &exchangeUnbindOk{},
+ )
+}
+
+/*
+Publish sends a Publishing from the client to an exchange on the server.
+
+When you want a single message to be delivered to a single queue, you can
+publish to the default exchange with the routingKey of the queue name. This is
+because every declared queue gets an implicit route to the default exchange.
+
+Since publishings are asynchronous, any undeliverable message will get returned
+by the server. Add a listener with Channel.NotifyReturn to handle any
+undeliverable message when calling publish with either the mandatory or
+immediate parameters as true.
+
+Publishings can be undeliverable when the mandatory flag is true and no queue is
+bound that matches the routing key, or when the immediate flag is true and no
+consumer on the matched queue is ready to accept the delivery.
+
+This can return an error when the channel, connection or socket is closed. The
+error or lack of an error does not indicate whether the server has received this
+publishing.
+
+It is possible for publishing to not reach the broker if the underlying socket
+is shut down without pending publishing packets being flushed from the kernel
+buffers. The easy way of making it probable that all publishings reach the
+server is to always call Connection.Close before terminating your publishing
+application. The way to ensure that all publishings reach the server is to add
+a listener to Channel.NotifyPublish and put the channel in confirm mode with
+Channel.Confirm. Publishing delivery tags and their corresponding
+confirmations start at 1. Exit when all publishings are confirmed.
+
+When Publish does not return an error and the channel is in confirm mode, the
+internal counter for DeliveryTags with the first confirmation starts at 1.
+
+*/
+func (ch *Channel) Publish(exchange, key string, mandatory, immediate bool, msg Publishing) error {
+ if err := msg.Headers.Validate(); err != nil {
+ return err
+ }
+
+ ch.m.Lock()
+ defer ch.m.Unlock()
+
+ if err := ch.send(&basicPublish{
+ Exchange: exchange,
+ RoutingKey: key,
+ Mandatory: mandatory,
+ Immediate: immediate,
+ Body: msg.Body,
+ Properties: properties{
+ Headers: msg.Headers,
+ ContentType: msg.ContentType,
+ ContentEncoding: msg.ContentEncoding,
+ DeliveryMode: msg.DeliveryMode,
+ Priority: msg.Priority,
+ CorrelationId: msg.CorrelationId,
+ ReplyTo: msg.ReplyTo,
+ Expiration: msg.Expiration,
+ MessageId: msg.MessageId,
+ Timestamp: msg.Timestamp,
+ Type: msg.Type,
+ UserId: msg.UserId,
+ AppId: msg.AppId,
+ },
+ }); err != nil {
+ return err
+ }
+
+ if ch.confirming {
+ ch.confirms.Publish()
+ }
+
+ return nil
+}
+
+/*
+Get synchronously receives a single Delivery from the head of a queue from the
+server to the client. In almost all cases, using Channel.Consume will be
+preferred.
+
+If there was a delivery waiting on the queue and that delivery was received, the
+second return value will be true. If there was no delivery waiting or an error
+occurred, the ok bool will be false.
+
+All deliveries must be acknowledged including those from Channel.Get. Call
+Delivery.Ack on the returned delivery when you have fully processed this
+delivery.
+
+When autoAck is true, the server will automatically acknowledge this message so
+you don't have to. But if you are unable to fully process this message before
+the channel or connection is closed, the message will not get requeued.
+
+*/
+func (ch *Channel) Get(queue string, autoAck bool) (msg Delivery, ok bool, err error) {
+ req := &basicGet{Queue: queue, NoAck: autoAck}
+ res := &basicGetOk{}
+ empty := &basicGetEmpty{}
+
+ if err := ch.call(req, res, empty); err != nil {
+ return Delivery{}, false, err
+ }
+
+ if res.DeliveryTag > 0 {
+ return *(newDelivery(ch, res)), true, nil
+ }
+
+ return Delivery{}, false, nil
+}
+
+/*
+Tx puts the channel into transaction mode on the server. All publishings and
+acknowledgments following this method will be atomically committed or rolled
+back for a single queue. Call either Channel.TxCommit or Channel.TxRollback to
+leave a this transaction and immediately start a new transaction.
+
+The atomicity across multiple queues is not defined as queue declarations and
+bindings are not included in the transaction.
+
+The behavior of publishings that are delivered as mandatory or immediate while
+the channel is in a transaction is not defined.
+
+Once a channel has been put into transaction mode, it cannot be taken out of
+transaction mode. Use a different channel for non-transactional semantics.
+
+*/
+func (ch *Channel) Tx() error {
+ return ch.call(
+ &txSelect{},
+ &txSelectOk{},
+ )
+}
+
+/*
+TxCommit atomically commits all publishings and acknowledgments for a single
+queue and immediately start a new transaction.
+
+Calling this method without having called Channel.Tx is an error.
+
+*/
+func (ch *Channel) TxCommit() error {
+ return ch.call(
+ &txCommit{},
+ &txCommitOk{},
+ )
+}
+
+/*
+TxRollback atomically rolls back all publishings and acknowledgments for a
+single queue and immediately start a new transaction.
+
+Calling this method without having called Channel.Tx is an error.
+
+*/
+func (ch *Channel) TxRollback() error {
+ return ch.call(
+ &txRollback{},
+ &txRollbackOk{},
+ )
+}
+
+/*
+Flow pauses the delivery of messages to consumers on this channel. Channels
+are opened with flow control active, to open a channel with paused
+deliveries immediately call this method with `false` after calling
+Connection.Channel.
+
+When active is `false`, this method asks the server to temporarily pause deliveries
+until called again with active as `true`.
+
+Channel.Get methods will not be affected by flow control.
+
+This method is not intended to act as window control. Use Channel.Qos to limit
+the number of unacknowledged messages or bytes in flight instead.
+
+The server may also send us flow methods to throttle our publishings. A well
+behaving publishing client should add a listener with Channel.NotifyFlow and
+pause its publishings when `false` is sent on that channel.
+
+Note: RabbitMQ prefers to use TCP push back to control flow for all channels on
+a connection, so under high volume scenarios, it's wise to open separate
+Connections for publishings and deliveries.
+
+*/
+func (ch *Channel) Flow(active bool) error {
+ return ch.call(
+ &channelFlow{Active: active},
+ &channelFlowOk{},
+ )
+}
+
+/*
+Confirm puts this channel into confirm mode so that the client can ensure all
+publishings have successfully been received by the server. After entering this
+mode, the server will send a basic.ack or basic.nack message with the deliver
+tag set to a 1 based incremental index corresponding to every publishing
+received after the this method returns.
+
+Add a listener to Channel.NotifyPublish to respond to the Confirmations. If
+Channel.NotifyPublish is not called, the Confirmations will be silently
+ignored.
+
+The order of acknowledgments is not bound to the order of deliveries.
+
+Ack and Nack confirmations will arrive at some point in the future.
+
+Unroutable mandatory or immediate messages are acknowledged immediately after
+any Channel.NotifyReturn listeners have been notified. Other messages are
+acknowledged when all queues that should have the message routed to them have
+either received acknowledgment of delivery or have enqueued the message,
+persisting the message if necessary.
+
+When noWait is true, the client will not wait for a response. A channel
+exception could occur if the server does not support this method.
+
+*/
+func (ch *Channel) Confirm(noWait bool) error {
+ if err := ch.call(
+ &confirmSelect{Nowait: noWait},
+ &confirmSelectOk{},
+ ); err != nil {
+ return err
+ }
+
+ ch.confirmM.Lock()
+ ch.confirming = true
+ ch.confirmM.Unlock()
+
+ return nil
+}
+
+/*
+Recover redelivers all unacknowledged deliveries on this channel.
+
+When requeue is false, messages will be redelivered to the original consumer.
+
+When requeue is true, messages will be redelivered to any available consumer,
+potentially including the original.
+
+If the deliveries cannot be recovered, an error will be returned and the channel
+will be closed.
+
+Note: this method is not implemented on RabbitMQ, use Delivery.Nack instead
+*/
+func (ch *Channel) Recover(requeue bool) error {
+ return ch.call(
+ &basicRecover{Requeue: requeue},
+ &basicRecoverOk{},
+ )
+}
+
+/*
+Ack acknowledges a delivery by its delivery tag when having been consumed with
+Channel.Consume or Channel.Get.
+
+Ack acknowledges all message received prior to the delivery tag when multiple
+is true.
+
+See also Delivery.Ack
+*/
+func (ch *Channel) Ack(tag uint64, multiple bool) error {
+ ch.m.Lock()
+ defer ch.m.Unlock()
+
+ return ch.send(&basicAck{
+ DeliveryTag: tag,
+ Multiple: multiple,
+ })
+}
+
+/*
+Nack negatively acknowledges a delivery by its delivery tag. Prefer this
+method to notify the server that you were not able to process this delivery and
+it must be redelivered or dropped.
+
+See also Delivery.Nack
+*/
+func (ch *Channel) Nack(tag uint64, multiple bool, requeue bool) error {
+ ch.m.Lock()
+ defer ch.m.Unlock()
+
+ return ch.send(&basicNack{
+ DeliveryTag: tag,
+ Multiple: multiple,
+ Requeue: requeue,
+ })
+}
+
+/*
+Reject negatively acknowledges a delivery by its delivery tag. Prefer Nack
+over Reject when communicating with a RabbitMQ server because you can Nack
+multiple messages, reducing the amount of protocol messages to exchange.
+
+See also Delivery.Reject
+*/
+func (ch *Channel) Reject(tag uint64, requeue bool) error {
+ return ch.send(&basicReject{
+ DeliveryTag: tag,
+ Requeue: requeue,
+ })
+}
diff --git a/src/dma/vendor/github.com/streadway/amqp/confirms.go b/src/dma/vendor/github.com/streadway/amqp/confirms.go
new file mode 100644
index 00000000..06cbaa71
--- /dev/null
+++ b/src/dma/vendor/github.com/streadway/amqp/confirms.go
@@ -0,0 +1,94 @@
+package amqp
+
+import "sync"
+
+// confirms resequences and notifies one or multiple publisher confirmation listeners
+type confirms struct {
+ m sync.Mutex
+ listeners []chan Confirmation
+ sequencer map[uint64]Confirmation
+ published uint64
+ expecting uint64
+}
+
+// newConfirms allocates a confirms
+func newConfirms() *confirms {
+ return &confirms{
+ sequencer: map[uint64]Confirmation{},
+ published: 0,
+ expecting: 1,
+ }
+}
+
+func (c *confirms) Listen(l chan Confirmation) {
+ c.m.Lock()
+ defer c.m.Unlock()
+
+ c.listeners = append(c.listeners, l)
+}
+
+// publish increments the publishing counter
+func (c *confirms) Publish() uint64 {
+ c.m.Lock()
+ defer c.m.Unlock()
+
+ c.published++
+ return c.published
+}
+
+// confirm confirms one publishing, increments the expecting delivery tag, and
+// removes bookkeeping for that delivery tag.
+func (c *confirms) confirm(confirmation Confirmation) {
+ delete(c.sequencer, c.expecting)
+ c.expecting++
+ for _, l := range c.listeners {
+ l <- confirmation
+ }
+}
+
+// resequence confirms any out of order delivered confirmations
+func (c *confirms) resequence() {
+ for c.expecting <= c.published {
+ sequenced, found := c.sequencer[c.expecting]
+ if !found {
+ return
+ }
+ c.confirm(sequenced)
+ }
+}
+
+// one confirms one publishing and all following in the publishing sequence
+func (c *confirms) One(confirmed Confirmation) {
+ c.m.Lock()
+ defer c.m.Unlock()
+
+ if c.expecting == confirmed.DeliveryTag {
+ c.confirm(confirmed)
+ } else {
+ c.sequencer[confirmed.DeliveryTag] = confirmed
+ }
+ c.resequence()
+}
+
+// multiple confirms all publishings up until the delivery tag
+func (c *confirms) Multiple(confirmed Confirmation) {
+ c.m.Lock()
+ defer c.m.Unlock()
+
+ for c.expecting <= confirmed.DeliveryTag {
+ c.confirm(Confirmation{c.expecting, confirmed.Ack})
+ }
+ c.resequence()
+}
+
+// Close closes all listeners, discarding any out of sequence confirmations
+func (c *confirms) Close() error {
+ c.m.Lock()
+ defer c.m.Unlock()
+
+ for _, l := range c.listeners {
+ close(l)
+ }
+ c.listeners = nil
+ return nil
+}
diff --git a/src/dma/vendor/github.com/streadway/amqp/connection.go b/src/dma/vendor/github.com/streadway/amqp/connection.go
new file mode 100644
index 00000000..ca1372d0
--- /dev/null
+++ b/src/dma/vendor/github.com/streadway/amqp/connection.go
@@ -0,0 +1,842 @@
+// Copyright (c) 2012, Sean Treadway, SoundCloud Ltd.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+// Source code and contact info at http://github.com/streadway/amqp
+
+package amqp
+
+import (
+ "bufio"
+ "crypto/tls"
+ "io"
+ "net"
+ "reflect"
+ "strconv"
+ "strings"
+ "sync"
+ "sync/atomic"
+ "time"
+)
+
+const (
+ maxChannelMax = (2 << 15) - 1
+
+ defaultHeartbeat = 10 * time.Second
+ defaultConnectionTimeout = 30 * time.Second
+ defaultProduct = "https://github.com/streadway/amqp"
+ defaultVersion = "β"
+ // Safer default that makes channel leaks a lot easier to spot
+ // before they create operational headaches. See https://github.com/rabbitmq/rabbitmq-server/issues/1593.
+ defaultChannelMax = (2 << 10) - 1
+ defaultLocale = "en_US"
+)
+
+// Config is used in DialConfig and Open to specify the desired tuning
+// parameters used during a connection open handshake. The negotiated tuning
+// will be stored in the returned connection's Config field.
+type Config struct {
+ // The SASL mechanisms to try in the client request, and the successful
+ // mechanism used on the Connection object.
+ // If SASL is nil, PlainAuth from the URL is used.
+ SASL []Authentication
+
+ // Vhost specifies the namespace of permissions, exchanges, queues and
+ // bindings on the server. Dial sets this to the path parsed from the URL.
+ Vhost string
+
+ ChannelMax int // 0 max channels means 2^16 - 1
+ FrameSize int // 0 max bytes means unlimited
+ Heartbeat time.Duration // less than 1s uses the server's interval
+
+ // TLSClientConfig specifies the client configuration of the TLS connection
+ // when establishing a tls transport.
+ // If the URL uses an amqps scheme, then an empty tls.Config with the
+ // ServerName from the URL is used.
+ TLSClientConfig *tls.Config
+
+ // Properties is table of properties that the client advertises to the server.
+ // This is an optional setting - if the application does not set this,
+ // the underlying library will use a generic set of client properties.
+ Properties Table
+
+ // Connection locale that we expect to always be en_US
+ // Even though servers must return it as per the AMQP 0-9-1 spec,
+ // we are not aware of it being used other than to satisfy the spec requirements
+ Locale string
+
+ // Dial returns a net.Conn prepared for a TLS handshake with TSLClientConfig,
+ // then an AMQP connection handshake.
+ // If Dial is nil, net.DialTimeout with a 30s connection and 30s deadline is
+ // used during TLS and AMQP handshaking.
+ Dial func(network, addr string) (net.Conn, error)
+}
+
+// Connection manages the serialization and deserialization of frames from IO
+// and dispatches the frames to the appropriate channel. All RPC methods and
+// asynchronous Publishing, Delivery, Ack, Nack and Return messages are
+// multiplexed on this channel. There must always be active receivers for
+// every asynchronous message on this connection.
+type Connection struct {
+ destructor sync.Once // shutdown once
+ sendM sync.Mutex // conn writer mutex
+ m sync.Mutex // struct field mutex
+
+ conn io.ReadWriteCloser
+
+ rpc chan message
+ writer *writer
+ sends chan time.Time // timestamps of each frame sent
+ deadlines chan readDeadliner // heartbeater updates read deadlines
+
+ allocator *allocator // id generator valid after openTune
+ channels map[uint16]*Channel
+
+ noNotify bool // true when we will never notify again
+ closes []chan *Error
+ blocks []chan Blocking
+
+ errors chan *Error
+
+ Config Config // The negotiated Config after connection.open
+
+ Major int // Server's major version
+ Minor int // Server's minor version
+ Properties Table // Server properties
+ Locales []string // Server locales
+
+ closed int32 // Will be 1 if the connection is closed, 0 otherwise. Should only be accessed as atomic
+}
+
+type readDeadliner interface {
+ SetReadDeadline(time.Time) error
+}
+
+// defaultDial establishes a connection when config.Dial is not provided
+func defaultDial(network, addr string) (net.Conn, error) {
+ conn, err := net.DialTimeout(network, addr, defaultConnectionTimeout)
+ if err != nil {
+ return nil, err
+ }
+
+ // Heartbeating hasn't started yet, don't stall forever on a dead server.
+ // A deadline is set for TLS and AMQP handshaking. After AMQP is established,
+ // the deadline is cleared in openComplete.
+ if err := conn.SetDeadline(time.Now().Add(defaultConnectionTimeout)); err != nil {
+ return nil, err
+ }
+
+ return conn, nil
+}
+
+// Dial accepts a string in the AMQP URI format and returns a new Connection
+// over TCP using PlainAuth. Defaults to a server heartbeat interval of 10
+// seconds and sets the handshake deadline to 30 seconds. After handshake,
+// deadlines are cleared.
+//
+// Dial uses the zero value of tls.Config when it encounters an amqps://
+// scheme. It is equivalent to calling DialTLS(amqp, nil).
+func Dial(url string) (*Connection, error) {
+ return DialConfig(url, Config{
+ Heartbeat: defaultHeartbeat,
+ Locale: defaultLocale,
+ })
+}
+
+// DialTLS accepts a string in the AMQP URI format and returns a new Connection
+// over TCP using PlainAuth. Defaults to a server heartbeat interval of 10
+// seconds and sets the initial read deadline to 30 seconds.
+//
+// DialTLS uses the provided tls.Config when encountering an amqps:// scheme.
+func DialTLS(url string, amqps *tls.Config) (*Connection, error) {
+ return DialConfig(url, Config{
+ Heartbeat: defaultHeartbeat,
+ TLSClientConfig: amqps,
+ Locale: defaultLocale,
+ })
+}
+
+// DialConfig accepts a string in the AMQP URI format and a configuration for
+// the transport and connection setup, returning a new Connection. Defaults to
+// a server heartbeat interval of 10 seconds and sets the initial read deadline
+// to 30 seconds.
+func DialConfig(url string, config Config) (*Connection, error) {
+ var err error
+ var conn net.Conn
+
+ uri, err := ParseURI(url)
+ if err != nil {
+ return nil, err
+ }
+
+ if config.SASL == nil {
+ config.SASL = []Authentication{uri.PlainAuth()}
+ }
+
+ if config.Vhost == "" {
+ config.Vhost = uri.Vhost
+ }
+
+ addr := net.JoinHostPort(uri.Host, strconv.FormatInt(int64(uri.Port), 10))
+
+ dialer := config.Dial
+ if dialer == nil {
+ dialer = defaultDial
+ }
+
+ conn, err = dialer("tcp", addr)
+ if err != nil {
+ return nil, err
+ }
+
+ if uri.Scheme == "amqps" {
+ if config.TLSClientConfig == nil {
+ config.TLSClientConfig = new(tls.Config)
+ }
+
+ // If ServerName has not been specified in TLSClientConfig,
+ // set it to the URI host used for this connection.
+ if config.TLSClientConfig.ServerName == "" {
+ config.TLSClientConfig.ServerName = uri.Host
+ }
+
+ client := tls.Client(conn, config.TLSClientConfig)
+ if err := client.Handshake(); err != nil {
+ conn.Close()
+ return nil, err
+ }
+
+ conn = client
+ }
+
+ return Open(conn, config)
+}
+
+/*
+Open accepts an already established connection, or other io.ReadWriteCloser as
+a transport. Use this method if you have established a TLS connection or wish
+to use your own custom transport.
+
+*/
+func Open(conn io.ReadWriteCloser, config Config) (*Connection, error) {
+ c := &Connection{
+ conn: conn,
+ writer: &writer{bufio.NewWriter(conn)},
+ channels: make(map[uint16]*Channel),
+ rpc: make(chan message),
+ sends: make(chan time.Time),
+ errors: make(chan *Error, 1),
+ deadlines: make(chan readDeadliner, 1),
+ }
+ go c.reader(conn)
+ return c, c.open(config)
+}
+
+/*
+LocalAddr returns the local TCP peer address, or ":0" (the zero value of net.TCPAddr)
+as a fallback default value if the underlying transport does not support LocalAddr().
+*/
+func (c *Connection) LocalAddr() net.Addr {
+ if conn, ok := c.conn.(interface {
+ LocalAddr() net.Addr
+ }); ok {
+ return conn.LocalAddr()
+ }
+ return &net.TCPAddr{}
+}
+
+// ConnectionState returns basic TLS details of the underlying transport.
+// Returns a zero value when the underlying connection does not implement
+// ConnectionState() tls.ConnectionState.
+func (c *Connection) ConnectionState() tls.ConnectionState {
+ if conn, ok := c.conn.(interface {
+ ConnectionState() tls.ConnectionState
+ }); ok {
+ return conn.ConnectionState()
+ }
+ return tls.ConnectionState{}
+}
+
+/*
+NotifyClose registers a listener for close events either initiated by an error
+accompanying a connection.close method or by a normal shutdown.
+
+On normal shutdowns, the chan will be closed.
+
+To reconnect after a transport or protocol error, register a listener here and
+re-run your setup process.
+
+*/
+func (c *Connection) NotifyClose(receiver chan *Error) chan *Error {
+ c.m.Lock()
+ defer c.m.Unlock()
+
+ if c.noNotify {
+ close(receiver)
+ } else {
+ c.closes = append(c.closes, receiver)
+ }
+
+ return receiver
+}
+
+/*
+NotifyBlocked registers a listener for RabbitMQ specific TCP flow control
+method extensions connection.blocked and connection.unblocked. Flow control is
+active with a reason when Blocking.Blocked is true. When a Connection is
+blocked, all methods will block across all connections until server resources
+become free again.
+
+This optional extension is supported by the server when the
+"connection.blocked" server capability key is true.
+
+*/
+func (c *Connection) NotifyBlocked(receiver chan Blocking) chan Blocking {
+ c.m.Lock()
+ defer c.m.Unlock()
+
+ if c.noNotify {
+ close(receiver)
+ } else {
+ c.blocks = append(c.blocks, receiver)
+ }
+
+ return receiver
+}
+
+/*
+Close requests and waits for the response to close the AMQP connection.
+
+It's advisable to use this message when publishing to ensure all kernel buffers
+have been flushed on the server and client before exiting.
+
+An error indicates that server may not have received this request to close but
+the connection should be treated as closed regardless.
+
+After returning from this call, all resources associated with this connection,
+including the underlying io, Channels, Notify listeners and Channel consumers
+will also be closed.
+*/
+func (c *Connection) Close() error {
+ if c.isClosed() {
+ return ErrClosed
+ }
+
+ defer c.shutdown(nil)
+ return c.call(
+ &connectionClose{
+ ReplyCode: replySuccess,
+ ReplyText: "kthxbai",
+ },
+ &connectionCloseOk{},
+ )
+}
+
+func (c *Connection) closeWith(err *Error) error {
+ if c.isClosed() {
+ return ErrClosed
+ }
+
+ defer c.shutdown(err)
+ return c.call(
+ &connectionClose{
+ ReplyCode: uint16(err.Code),
+ ReplyText: err.Reason,
+ },
+ &connectionCloseOk{},
+ )
+}
+
+func (c *Connection) isClosed() bool {
+ return (atomic.LoadInt32(&c.closed) == 1)
+}
+
+func (c *Connection) send(f frame) error {
+ if c.isClosed() {
+ return ErrClosed
+ }
+
+ c.sendM.Lock()
+ err := c.writer.WriteFrame(f)
+ c.sendM.Unlock()
+
+ if err != nil {
+ // shutdown could be re-entrant from signaling notify chans
+ go c.shutdown(&Error{
+ Code: FrameError,
+ Reason: err.Error(),
+ })
+ } else {
+ // Broadcast we sent a frame, reducing heartbeats, only
+ // if there is something that can receive - like a non-reentrant
+ // call or if the heartbeater isn't running
+ select {
+ case c.sends <- time.Now():
+ default:
+ }
+ }
+
+ return err
+}
+
+func (c *Connection) shutdown(err *Error) {
+ atomic.StoreInt32(&c.closed, 1)
+
+ c.destructor.Do(func() {
+ c.m.Lock()
+ defer c.m.Unlock()
+
+ if err != nil {
+ for _, c := range c.closes {
+ c <- err
+ }
+ }
+
+ if err != nil {
+ c.errors <- err
+ }
+ // Shutdown handler goroutine can still receive the result.
+ close(c.errors)
+
+ for _, c := range c.closes {
+ close(c)
+ }
+
+ for _, c := range c.blocks {
+ close(c)
+ }
+
+ // Shutdown the channel, but do not use closeChannel() as it calls
+ // releaseChannel() which requires the connection lock.
+ //
+ // Ranging over c.channels and calling releaseChannel() that mutates
+ // c.channels is racy - see commit 6063341 for an example.
+ for _, ch := range c.channels {
+ ch.shutdown(err)
+ }
+
+ c.conn.Close()
+
+ c.channels = map[uint16]*Channel{}
+ c.allocator = newAllocator(1, c.Config.ChannelMax)
+ c.noNotify = true
+ })
+}
+
+// All methods sent to the connection channel should be synchronous so we
+// can handle them directly without a framing component
+func (c *Connection) demux(f frame) {
+ if f.channel() == 0 {
+ c.dispatch0(f)
+ } else {
+ c.dispatchN(f)
+ }
+}
+
+func (c *Connection) dispatch0(f frame) {
+ switch mf := f.(type) {
+ case *methodFrame:
+ switch m := mf.Method.(type) {
+ case *connectionClose:
+ // Send immediately as shutdown will close our side of the writer.
+ c.send(&methodFrame{
+ ChannelId: 0,
+ Method: &connectionCloseOk{},
+ })
+
+ c.shutdown(newError(m.ReplyCode, m.ReplyText))
+ case *connectionBlocked:
+ for _, c := range c.blocks {
+ c <- Blocking{Active: true, Reason: m.Reason}
+ }
+ case *connectionUnblocked:
+ for _, c := range c.blocks {
+ c <- Blocking{Active: false}
+ }
+ default:
+ c.rpc <- m
+ }
+ case *heartbeatFrame:
+ // kthx - all reads reset our deadline. so we can drop this
+ default:
+ // lolwat - channel0 only responds to methods and heartbeats
+ c.closeWith(ErrUnexpectedFrame)
+ }
+}
+
+func (c *Connection) dispatchN(f frame) {
+ c.m.Lock()
+ channel := c.channels[f.channel()]
+ c.m.Unlock()
+
+ if channel != nil {
+ channel.recv(channel, f)
+ } else {
+ c.dispatchClosed(f)
+ }
+}
+
+// section 2.3.7: "When a peer decides to close a channel or connection, it
+// sends a Close method. The receiving peer MUST respond to a Close with a
+// Close-Ok, and then both parties can close their channel or connection. Note
+// that if peers ignore Close, deadlock can happen when both peers send Close
+// at the same time."
+//
+// When we don't have a channel, so we must respond with close-ok on a close
+// method. This can happen between a channel exception on an asynchronous
+// method like basic.publish and a synchronous close with channel.close.
+// In that case, we'll get both a channel.close and channel.close-ok in any
+// order.
+func (c *Connection) dispatchClosed(f frame) {
+ // Only consider method frames, drop content/header frames
+ if mf, ok := f.(*methodFrame); ok {
+ switch mf.Method.(type) {
+ case *channelClose:
+ c.send(&methodFrame{
+ ChannelId: f.channel(),
+ Method: &channelCloseOk{},
+ })
+ case *channelCloseOk:
+ // we are already closed, so do nothing
+ default:
+ // unexpected method on closed channel
+ c.closeWith(ErrClosed)
+ }
+ }
+}
+
+// Reads each frame off the IO and hand off to the connection object that
+// will demux the streams and dispatch to one of the opened channels or
+// handle on channel 0 (the connection channel).
+func (c *Connection) reader(r io.Reader) {
+ buf := bufio.NewReader(r)
+ frames := &reader{buf}
+ conn, haveDeadliner := r.(readDeadliner)
+
+ for {
+ frame, err := frames.ReadFrame()
+
+ if err != nil {
+ c.shutdown(&Error{Code: FrameError, Reason: err.Error()})
+ return
+ }
+
+ c.demux(frame)
+
+ if haveDeadliner {
+ c.deadlines <- conn
+ }
+ }
+}
+
+// Ensures that at least one frame is being sent at the tuned interval with a
+// jitter tolerance of 1s
+func (c *Connection) heartbeater(interval time.Duration, done chan *Error) {
+ const maxServerHeartbeatsInFlight = 3
+
+ var sendTicks <-chan time.Time
+ if interval > 0 {
+ ticker := time.NewTicker(interval)
+ defer ticker.Stop()
+ sendTicks = ticker.C
+ }
+
+ lastSent := time.Now()
+
+ for {
+ select {
+ case at, stillSending := <-c.sends:
+ // When actively sending, depend on sent frames to reset server timer
+ if stillSending {
+ lastSent = at
+ } else {
+ return
+ }
+
+ case at := <-sendTicks:
+ // When idle, fill the space with a heartbeat frame
+ if at.Sub(lastSent) > interval-time.Second {
+ if err := c.send(&heartbeatFrame{}); err != nil {
+ // send heartbeats even after close/closeOk so we
+ // tick until the connection starts erroring
+ return
+ }
+ }
+
+ case conn := <-c.deadlines:
+ // When reading, reset our side of the deadline, if we've negotiated one with
+ // a deadline that covers at least 2 server heartbeats
+ if interval > 0 {
+ conn.SetReadDeadline(time.Now().Add(maxServerHeartbeatsInFlight * interval))
+ }
+
+ case <-done:
+ return
+ }
+ }
+}
+
+// Convenience method to inspect the Connection.Properties["capabilities"]
+// Table for server identified capabilities like "basic.ack" or
+// "confirm.select".
+func (c *Connection) isCapable(featureName string) bool {
+ capabilities, _ := c.Properties["capabilities"].(Table)
+ hasFeature, _ := capabilities[featureName].(bool)
+ return hasFeature
+}
+
+// allocateChannel records but does not open a new channel with a unique id.
+// This method is the initial part of the channel lifecycle and paired with
+// releaseChannel
+func (c *Connection) allocateChannel() (*Channel, error) {
+ c.m.Lock()
+ defer c.m.Unlock()
+
+ if c.isClosed() {
+ return nil, ErrClosed
+ }
+
+ id, ok := c.allocator.next()
+ if !ok {
+ return nil, ErrChannelMax
+ }
+
+ ch := newChannel(c, uint16(id))
+ c.channels[uint16(id)] = ch
+
+ return ch, nil
+}
+
+// releaseChannel removes a channel from the registry as the final part of the
+// channel lifecycle
+func (c *Connection) releaseChannel(id uint16) {
+ c.m.Lock()
+ defer c.m.Unlock()
+
+ delete(c.channels, id)
+ c.allocator.release(int(id))
+}
+
+// openChannel allocates and opens a channel, must be paired with closeChannel
+func (c *Connection) openChannel() (*Channel, error) {
+ ch, err := c.allocateChannel()
+ if err != nil {
+ return nil, err
+ }
+
+ if err := ch.open(); err != nil {
+ c.releaseChannel(ch.id)
+ return nil, err
+ }
+ return ch, nil
+}
+
+// closeChannel releases and initiates a shutdown of the channel. All channel
+// closures should be initiated here for proper channel lifecycle management on
+// this connection.
+func (c *Connection) closeChannel(ch *Channel, e *Error) {
+ ch.shutdown(e)
+ c.releaseChannel(ch.id)
+}
+
+/*
+Channel opens a unique, concurrent server channel to process the bulk of AMQP
+messages. Any error from methods on this receiver will render the receiver
+invalid and a new Channel should be opened.
+
+*/
+func (c *Connection) Channel() (*Channel, error) {
+ return c.openChannel()
+}
+
+func (c *Connection) call(req message, res ...message) error {
+ // Special case for when the protocol header frame is sent insted of a
+ // request method
+ if req != nil {
+ if err := c.send(&methodFrame{ChannelId: 0, Method: req}); err != nil {
+ return err
+ }
+ }
+
+ select {
+ case err, ok := <-c.errors:
+ if !ok {
+ return ErrClosed
+ }
+ return err
+
+ case msg := <-c.rpc:
+ // Try to match one of the result types
+ for _, try := range res {
+ if reflect.TypeOf(msg) == reflect.TypeOf(try) {
+ // *res = *msg
+ vres := reflect.ValueOf(try).Elem()
+ vmsg := reflect.ValueOf(msg).Elem()
+ vres.Set(vmsg)
+ return nil
+ }
+ }
+ return ErrCommandInvalid
+ }
+ // unreachable
+}
+
+// Connection = open-Connection *use-Connection close-Connection
+// open-Connection = C:protocol-header
+// S:START C:START-OK
+// *challenge
+// S:TUNE C:TUNE-OK
+// C:OPEN S:OPEN-OK
+// challenge = S:SECURE C:SECURE-OK
+// use-Connection = *channel
+// close-Connection = C:CLOSE S:CLOSE-OK
+// / S:CLOSE C:CLOSE-OK
+func (c *Connection) open(config Config) error {
+ if err := c.send(&protocolHeader{}); err != nil {
+ return err
+ }
+
+ return c.openStart(config)
+}
+
+func (c *Connection) openStart(config Config) error {
+ start := &connectionStart{}
+
+ if err := c.call(nil, start); err != nil {
+ return err
+ }
+
+ c.Major = int(start.VersionMajor)
+ c.Minor = int(start.VersionMinor)
+ c.Properties = Table(start.ServerProperties)
+ c.Locales = strings.Split(start.Locales, " ")
+
+ // eventually support challenge/response here by also responding to
+ // connectionSecure.
+ auth, ok := pickSASLMechanism(config.SASL, strings.Split(start.Mechanisms, " "))
+ if !ok {
+ return ErrSASL
+ }
+
+ // Save this mechanism off as the one we chose
+ c.Config.SASL = []Authentication{auth}
+
+ // Set the connection locale to client locale
+ c.Config.Locale = config.Locale
+
+ return c.openTune(config, auth)
+}
+
+func (c *Connection) openTune(config Config, auth Authentication) error {
+ if len(config.Properties) == 0 {
+ config.Properties = Table{
+ "product": defaultProduct,
+ "version": defaultVersion,
+ }
+ }
+
+ config.Properties["capabilities"] = Table{
+ "connection.blocked": true,
+ "consumer_cancel_notify": true,
+ }
+
+ ok := &connectionStartOk{
+ ClientProperties: config.Properties,
+ Mechanism: auth.Mechanism(),
+ Response: auth.Response(),
+ Locale: config.Locale,
+ }
+ tune := &connectionTune{}
+
+ if err := c.call(ok, tune); err != nil {
+ // per spec, a connection can only be closed when it has been opened
+ // so at this point, we know it's an auth error, but the socket
+ // was closed instead. Return a meaningful error.
+ return ErrCredentials
+ }
+
+ // When the server and client both use default 0, then the max channel is
+ // only limited by uint16.
+ c.Config.ChannelMax = pick(config.ChannelMax, int(tune.ChannelMax))
+ if c.Config.ChannelMax == 0 {
+ c.Config.ChannelMax = defaultChannelMax
+ }
+ c.Config.ChannelMax = min(c.Config.ChannelMax, maxChannelMax)
+
+ // Frame size includes headers and end byte (len(payload)+8), even if
+ // this is less than FrameMinSize, use what the server sends because the
+ // alternative is to stop the handshake here.
+ c.Config.FrameSize = pick(config.FrameSize, int(tune.FrameMax))
+
+ // Save this off for resetDeadline()
+ c.Config.Heartbeat = time.Second * time.Duration(pick(
+ int(config.Heartbeat/time.Second),
+ int(tune.Heartbeat)))
+
+ // "The client should start sending heartbeats after receiving a
+ // Connection.Tune method"
+ go c.heartbeater(c.Config.Heartbeat, c.NotifyClose(make(chan *Error, 1)))
+
+ if err := c.send(&methodFrame{
+ ChannelId: 0,
+ Method: &connectionTuneOk{
+ ChannelMax: uint16(c.Config.ChannelMax),
+ FrameMax: uint32(c.Config.FrameSize),
+ Heartbeat: uint16(c.Config.Heartbeat / time.Second),
+ },
+ }); err != nil {
+ return err
+ }
+
+ return c.openVhost(config)
+}
+
+func (c *Connection) openVhost(config Config) error {
+ req := &connectionOpen{VirtualHost: config.Vhost}
+ res := &connectionOpenOk{}
+
+ if err := c.call(req, res); err != nil {
+ // Cannot be closed yet, but we know it's a vhost problem
+ return ErrVhost
+ }
+
+ c.Config.Vhost = config.Vhost
+
+ return c.openComplete()
+}
+
+// openComplete performs any final Connection initialization dependent on the
+// connection handshake and clears any state needed for TLS and AMQP handshaking.
+func (c *Connection) openComplete() error {
+ // We clear the deadlines and let the heartbeater reset the read deadline if requested.
+ // RabbitMQ uses TCP flow control at this point for pushback so Writes can
+ // intentionally block.
+ if deadliner, ok := c.conn.(interface {
+ SetDeadline(time.Time) error
+ }); ok {
+ _ = deadliner.SetDeadline(time.Time{})
+ }
+
+ c.allocator = newAllocator(1, c.Config.ChannelMax)
+ return nil
+}
+
+func max(a, b int) int {
+ if a > b {
+ return a
+ }
+ return b
+}
+
+func min(a, b int) int {
+ if a < b {
+ return a
+ }
+ return b
+}
+
+func pick(client, server int) int {
+ if client == 0 || server == 0 {
+ return max(client, server)
+ }
+ return min(client, server)
+}
diff --git a/src/dma/vendor/github.com/streadway/amqp/consumers.go b/src/dma/vendor/github.com/streadway/amqp/consumers.go
new file mode 100644
index 00000000..887ac749
--- /dev/null
+++ b/src/dma/vendor/github.com/streadway/amqp/consumers.go
@@ -0,0 +1,142 @@
+// Copyright (c) 2012, Sean Treadway, SoundCloud Ltd.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+// Source code and contact info at http://github.com/streadway/amqp
+
+package amqp
+
+import (
+ "os"
+ "strconv"
+ "sync"
+ "sync/atomic"
+)
+
+var consumerSeq uint64
+
+const consumerTagLengthMax = 0xFF // see writeShortstr
+
+func uniqueConsumerTag() string {
+ return commandNameBasedUniqueConsumerTag(os.Args[0])
+}
+
+func commandNameBasedUniqueConsumerTag(commandName string) string {
+ tagPrefix := "ctag-"
+ tagInfix := commandName
+ tagSuffix := "-" + strconv.FormatUint(atomic.AddUint64(&consumerSeq, 1), 10)
+
+ if len(tagPrefix)+len(tagInfix)+len(tagSuffix) > consumerTagLengthMax {
+ tagInfix = "streadway/amqp"
+ }
+
+ return tagPrefix + tagInfix + tagSuffix
+}
+
+type consumerBuffers map[string]chan *Delivery
+
+// Concurrent type that manages the consumerTag ->
+// ingress consumerBuffer mapping
+type consumers struct {
+ sync.WaitGroup // one for buffer
+ closed chan struct{} // signal buffer
+
+ sync.Mutex // protects below
+ chans consumerBuffers
+}
+
+func makeConsumers() *consumers {
+ return &consumers{
+ closed: make(chan struct{}),
+ chans: make(consumerBuffers),
+ }
+}
+
+func (subs *consumers) buffer(in chan *Delivery, out chan Delivery) {
+ defer close(out)
+ defer subs.Done()
+
+ var inflight = in
+ var queue []*Delivery
+
+ for delivery := range in {
+ queue = append(queue, delivery)
+
+ for len(queue) > 0 {
+ select {
+ case <-subs.closed:
+ // closed before drained, drop in-flight
+ return
+
+ case delivery, consuming := <-inflight:
+ if consuming {
+ queue = append(queue, delivery)
+ } else {
+ inflight = nil
+ }
+
+ case out <- *queue[0]:
+ queue = queue[1:]
+ }
+ }
+ }
+}
+
+// On key conflict, close the previous channel.
+func (subs *consumers) add(tag string, consumer chan Delivery) {
+ subs.Lock()
+ defer subs.Unlock()
+
+ if prev, found := subs.chans[tag]; found {
+ close(prev)
+ }
+
+ in := make(chan *Delivery)
+ subs.chans[tag] = in
+
+ subs.Add(1)
+ go subs.buffer(in, consumer)
+}
+
+func (subs *consumers) cancel(tag string) (found bool) {
+ subs.Lock()
+ defer subs.Unlock()
+
+ ch, found := subs.chans[tag]
+
+ if found {
+ delete(subs.chans, tag)
+ close(ch)
+ }
+
+ return found
+}
+
+func (subs *consumers) close() {
+ subs.Lock()
+ defer subs.Unlock()
+
+ close(subs.closed)
+
+ for tag, ch := range subs.chans {
+ delete(subs.chans, tag)
+ close(ch)
+ }
+
+ subs.Wait()
+}
+
+// Sends a delivery to a the consumer identified by `tag`.
+// If unbuffered channels are used for Consume this method
+// could block all deliveries until the consumer
+// receives on the other end of the channel.
+func (subs *consumers) send(tag string, msg *Delivery) bool {
+ subs.Lock()
+ defer subs.Unlock()
+
+ buffer, found := subs.chans[tag]
+ if found {
+ buffer <- msg
+ }
+
+ return found
+}
diff --git a/src/dma/vendor/github.com/streadway/amqp/delivery.go b/src/dma/vendor/github.com/streadway/amqp/delivery.go
new file mode 100644
index 00000000..304c8346
--- /dev/null
+++ b/src/dma/vendor/github.com/streadway/amqp/delivery.go
@@ -0,0 +1,173 @@
+// Copyright (c) 2012, Sean Treadway, SoundCloud Ltd.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+// Source code and contact info at http://github.com/streadway/amqp
+
+package amqp
+
+import (
+ "errors"
+ "time"
+)
+
+var errDeliveryNotInitialized = errors.New("delivery not initialized")
+
+// Acknowledger notifies the server of successful or failed consumption of
+// delivieries via identifier found in the Delivery.DeliveryTag field.
+//
+// Applications can provide mock implementations in tests of Delivery handlers.
+type Acknowledger interface {
+ Ack(tag uint64, multiple bool) error
+ Nack(tag uint64, multiple bool, requeue bool) error
+ Reject(tag uint64, requeue bool) error
+}
+
+// Delivery captures the fields for a previously delivered message resident in
+// a queue to be delivered by the server to a consumer from Channel.Consume or
+// Channel.Get.
+type Delivery struct {
+ Acknowledger Acknowledger // the channel from which this delivery arrived
+
+ Headers Table // Application or header exchange table
+
+ // Properties
+ ContentType string // MIME content type
+ ContentEncoding string // MIME content encoding
+ DeliveryMode uint8 // queue implementation use - non-persistent (1) or persistent (2)
+ Priority uint8 // queue implementation use - 0 to 9
+ CorrelationId string // application use - correlation identifier
+ ReplyTo string // application use - address to reply to (ex: RPC)
+ Expiration string // implementation use - message expiration spec
+ MessageId string // application use - message identifier
+ Timestamp time.Time // application use - message timestamp
+ Type string // application use - message type name
+ UserId string // application use - creating user - should be authenticated user
+ AppId string // application use - creating application id
+
+ // Valid only with Channel.Consume
+ ConsumerTag string
+
+ // Valid only with Channel.Get
+ MessageCount uint32
+
+ DeliveryTag uint64
+ Redelivered bool
+ Exchange string // basic.publish exhange
+ RoutingKey string // basic.publish routing key
+
+ Body []byte
+}
+
+func newDelivery(channel *Channel, msg messageWithContent) *Delivery {
+ props, body := msg.getContent()
+
+ delivery := Delivery{
+ Acknowledger: channel,
+
+ Headers: props.Headers,
+ ContentType: props.ContentType,
+ ContentEncoding: props.ContentEncoding,
+ DeliveryMode: props.DeliveryMode,
+ Priority: props.Priority,
+ CorrelationId: props.CorrelationId,
+ ReplyTo: props.ReplyTo,
+ Expiration: props.Expiration,
+ MessageId: props.MessageId,
+ Timestamp: props.Timestamp,
+ Type: props.Type,
+ UserId: props.UserId,
+ AppId: props.AppId,
+
+ Body: body,
+ }
+
+ // Properties for the delivery types
+ switch m := msg.(type) {
+ case *basicDeliver:
+ delivery.ConsumerTag = m.ConsumerTag
+ delivery.DeliveryTag = m.DeliveryTag
+ delivery.Redelivered = m.Redelivered
+ delivery.Exchange = m.Exchange
+ delivery.RoutingKey = m.RoutingKey
+
+ case *basicGetOk:
+ delivery.MessageCount = m.MessageCount
+ delivery.DeliveryTag = m.DeliveryTag
+ delivery.Redelivered = m.Redelivered
+ delivery.Exchange = m.Exchange
+ delivery.RoutingKey = m.RoutingKey
+ }
+
+ return &delivery
+}
+
+/*
+Ack delegates an acknowledgement through the Acknowledger interface that the
+client or server has finished work on a delivery.
+
+All deliveries in AMQP must be acknowledged. If you called Channel.Consume
+with autoAck true then the server will be automatically ack each message and
+this method should not be called. Otherwise, you must call Delivery.Ack after
+you have successfully processed this delivery.
+
+When multiple is true, this delivery and all prior unacknowledged deliveries
+on the same channel will be acknowledged. This is useful for batch processing
+of deliveries.
+
+An error will indicate that the acknowledge could not be delivered to the
+channel it was sent from.
+
+Either Delivery.Ack, Delivery.Reject or Delivery.Nack must be called for every
+delivery that is not automatically acknowledged.
+*/
+func (d Delivery) Ack(multiple bool) error {
+ if d.Acknowledger == nil {
+ return errDeliveryNotInitialized
+ }
+ return d.Acknowledger.Ack(d.DeliveryTag, multiple)
+}
+
+/*
+Reject delegates a negatively acknowledgement through the Acknowledger interface.
+
+When requeue is true, queue this message to be delivered to a consumer on a
+different channel. When requeue is false or the server is unable to queue this
+message, it will be dropped.
+
+If you are batch processing deliveries, and your server supports it, prefer
+Delivery.Nack.
+
+Either Delivery.Ack, Delivery.Reject or Delivery.Nack must be called for every
+delivery that is not automatically acknowledged.
+*/
+func (d Delivery) Reject(requeue bool) error {
+ if d.Acknowledger == nil {
+ return errDeliveryNotInitialized
+ }
+ return d.Acknowledger.Reject(d.DeliveryTag, requeue)
+}
+
+/*
+Nack negatively acknowledge the delivery of message(s) identified by the
+delivery tag from either the client or server.
+
+When multiple is true, nack messages up to and including delivered messages up
+until the delivery tag delivered on the same channel.
+
+When requeue is true, request the server to deliver this message to a different
+consumer. If it is not possible or requeue is false, the message will be
+dropped or delivered to a server configured dead-letter queue.
+
+This method must not be used to select or requeue messages the client wishes
+not to handle, rather it is to inform the server that the client is incapable
+of handling this message at this time.
+
+Either Delivery.Ack, Delivery.Reject or Delivery.Nack must be called for every
+delivery that is not automatically acknowledged.
+*/
+func (d Delivery) Nack(multiple, requeue bool) error {
+ if d.Acknowledger == nil {
+ return errDeliveryNotInitialized
+ }
+ return d.Acknowledger.Nack(d.DeliveryTag, multiple, requeue)
+}
diff --git a/src/dma/vendor/github.com/streadway/amqp/doc.go b/src/dma/vendor/github.com/streadway/amqp/doc.go
new file mode 100644
index 00000000..76bf3e58
--- /dev/null
+++ b/src/dma/vendor/github.com/streadway/amqp/doc.go
@@ -0,0 +1,108 @@
+// Copyright (c) 2012, Sean Treadway, SoundCloud Ltd.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+// Source code and contact info at http://github.com/streadway/amqp
+
+/*
+Package amqp is an AMQP 0.9.1 client with RabbitMQ extensions
+
+Understand the AMQP 0.9.1 messaging model by reviewing these links first. Much
+of the terminology in this library directly relates to AMQP concepts.
+
+ Resources
+
+ http://www.rabbitmq.com/tutorials/amqp-concepts.html
+ http://www.rabbitmq.com/getstarted.html
+ http://www.rabbitmq.com/amqp-0-9-1-reference.html
+
+Design
+
+Most other broker clients publish to queues, but in AMQP, clients publish
+Exchanges instead. AMQP is programmable, meaning that both the producers and
+consumers agree on the configuration of the broker, instead requiring an
+operator or system configuration that declares the logical topology in the
+broker. The routing between producers and consumer queues is via Bindings.
+These bindings form the logical topology of the broker.
+
+In this library, a message sent from publisher is called a "Publishing" and a
+message received to a consumer is called a "Delivery". The fields of
+Publishings and Deliveries are close but not exact mappings to the underlying
+wire format to maintain stronger types. Many other libraries will combine
+message properties with message headers. In this library, the message well
+known properties are strongly typed fields on the Publishings and Deliveries,
+whereas the user defined headers are in the Headers field.
+
+The method naming closely matches the protocol's method name with positional
+parameters mapping to named protocol message fields. The motivation here is to
+present a comprehensive view over all possible interactions with the server.
+
+Generally, methods that map to protocol methods of the "basic" class will be
+elided in this interface, and "select" methods of various channel mode selectors
+will be elided for example Channel.Confirm and Channel.Tx.
+
+The library is intentionally designed to be synchronous, where responses for
+each protocol message are required to be received in an RPC manner. Some
+methods have a noWait parameter like Channel.QueueDeclare, and some methods are
+asynchronous like Channel.Publish. The error values should still be checked for
+these methods as they will indicate IO failures like when the underlying
+connection closes.
+
+Asynchronous Events
+
+Clients of this library may be interested in receiving some of the protocol
+messages other than Deliveries like basic.ack methods while a channel is in
+confirm mode.
+
+The Notify* methods with Connection and Channel receivers model the pattern of
+asynchronous events like closes due to exceptions, or messages that are sent out
+of band from an RPC call like basic.ack or basic.flow.
+
+Any asynchronous events, including Deliveries and Publishings must always have
+a receiver until the corresponding chans are closed. Without asynchronous
+receivers, the sychronous methods will block.
+
+Use Case
+
+It's important as a client to an AMQP topology to ensure the state of the
+broker matches your expectations. For both publish and consume use cases,
+make sure you declare the queues, exchanges and bindings you expect to exist
+prior to calling Channel.Publish or Channel.Consume.
+
+ // Connections start with amqp.Dial() typically from a command line argument
+ // or environment variable.
+ connection, err := amqp.Dial(os.Getenv("AMQP_URL"))
+
+ // To cleanly shutdown by flushing kernel buffers, make sure to close and
+ // wait for the response.
+ defer connection.Close()
+
+ // Most operations happen on a channel. If any error is returned on a
+ // channel, the channel will no longer be valid, throw it away and try with
+ // a different channel. If you use many channels, it's useful for the
+ // server to
+ channel, err := connection.Channel()
+
+ // Declare your topology here, if it doesn't exist, it will be created, if
+ // it existed already and is not what you expect, then that's considered an
+ // error.
+
+ // Use your connection on this topology with either Publish or Consume, or
+ // inspect your queues with QueueInspect. It's unwise to mix Publish and
+ // Consume to let TCP do its job well.
+
+SSL/TLS - Secure connections
+
+When Dial encounters an amqps:// scheme, it will use the zero value of a
+tls.Config. This will only perform server certificate and host verification.
+
+Use DialTLS when you wish to provide a client certificate (recommended),
+include a private certificate authority's certificate in the cert chain for
+server validity, or run insecure by not verifying the server certificate dial
+your own connection. DialTLS will use the provided tls.Config when it
+encounters an amqps:// scheme and will dial a plain connection when it
+encounters an amqp:// scheme.
+
+SSL/TLS in RabbitMQ is documented here: http://www.rabbitmq.com/ssl.html
+
+*/
+package amqp
diff --git a/src/dma/vendor/github.com/streadway/amqp/fuzz.go b/src/dma/vendor/github.com/streadway/amqp/fuzz.go
new file mode 100644
index 00000000..16e626ce
--- /dev/null
+++ b/src/dma/vendor/github.com/streadway/amqp/fuzz.go
@@ -0,0 +1,17 @@
+// +build gofuzz
+
+package amqp
+
+import "bytes"
+
+func Fuzz(data []byte) int {
+ r := reader{bytes.NewReader(data)}
+ frame, err := r.ReadFrame()
+ if err != nil {
+ if frame != nil {
+ panic("frame is not nil")
+ }
+ return 0
+ }
+ return 1
+}
diff --git a/src/dma/vendor/github.com/streadway/amqp/gen.sh b/src/dma/vendor/github.com/streadway/amqp/gen.sh
new file mode 100755
index 00000000..d46e19bd
--- /dev/null
+++ b/src/dma/vendor/github.com/streadway/amqp/gen.sh
@@ -0,0 +1,2 @@
+#!/bin/sh
+go run spec/gen.go < spec/amqp0-9-1.stripped.extended.xml | gofmt > spec091.go
diff --git a/src/dma/vendor/github.com/streadway/amqp/pre-commit b/src/dma/vendor/github.com/streadway/amqp/pre-commit
new file mode 100755
index 00000000..7607f467
--- /dev/null
+++ b/src/dma/vendor/github.com/streadway/amqp/pre-commit
@@ -0,0 +1,29 @@
+#!/bin/sh
+
+GOFMT_FILES=$(gofmt -l .)
+if [ -n "${GOFMT_FILES}" ]; then
+ printf >&2 'gofmt failed for the following files:\n%s\n\nplease run "gofmt -w ." on your changes before committing.\n' "${GOFMT_FILES}"
+ exit 1
+fi
+
+GOLINT_ERRORS=$(golint ./... | grep -v "Id should be")
+if [ -n "${GOLINT_ERRORS}" ]; then
+ printf >&2 'golint failed for the following reasons:\n%s\n\nplease run 'golint ./...' on your changes before committing.\n' "${GOLINT_ERRORS}"
+ exit 1
+fi
+
+GOVET_ERRORS=$(go tool vet *.go 2>&1)
+if [ -n "${GOVET_ERRORS}" ]; then
+ printf >&2 'go vet failed for the following reasons:\n%s\n\nplease run "go tool vet *.go" on your changes before committing.\n' "${GOVET_ERRORS}"
+ exit 1
+fi
+
+if [ -z "${NOTEST}" ]; then
+ printf >&2 'Running short tests...\n'
+ env AMQP_URL= go test -short -v | egrep 'PASS|ok'
+
+ if [ $? -ne 0 ]; then
+ printf >&2 'go test failed, please fix before committing.\n'
+ exit 1
+ fi
+fi
diff --git a/src/dma/vendor/github.com/streadway/amqp/read.go b/src/dma/vendor/github.com/streadway/amqp/read.go
new file mode 100644
index 00000000..3aa0b338
--- /dev/null
+++ b/src/dma/vendor/github.com/streadway/amqp/read.go
@@ -0,0 +1,456 @@
+// Copyright (c) 2012, Sean Treadway, SoundCloud Ltd.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+// Source code and contact info at http://github.com/streadway/amqp
+
+package amqp
+
+import (
+ "bytes"
+ "encoding/binary"
+ "errors"
+ "io"
+ "time"
+)
+
+/*
+Reads a frame from an input stream and returns an interface that can be cast into
+one of the following:
+
+ methodFrame
+ PropertiesFrame
+ bodyFrame
+ heartbeatFrame
+
+2.3.5 frame Details
+
+All frames consist of a header (7 octets), a payload of arbitrary size, and a
+'frame-end' octet that detects malformed frames:
+
+ 0 1 3 7 size+7 size+8
+ +------+---------+-------------+ +------------+ +-----------+
+ | type | channel | size | | payload | | frame-end |
+ +------+---------+-------------+ +------------+ +-----------+
+ octet short long size octets octet
+
+To read a frame, we:
+ 1. Read the header and check the frame type and channel.
+ 2. Depending on the frame type, we read the payload and process it.
+ 3. Read the frame end octet.
+
+In realistic implementations where performance is a concern, we would use
+“read-ahead buffering” or
+
+“gathering reads” to avoid doing three separate system calls to read a frame.
+*/
+func (r *reader) ReadFrame() (frame frame, err error) {
+ var scratch [7]byte
+
+ if _, err = io.ReadFull(r.r, scratch[:7]); err != nil {
+ return
+ }
+
+ typ := uint8(scratch[0])
+ channel := binary.BigEndian.Uint16(scratch[1:3])
+ size := binary.BigEndian.Uint32(scratch[3:7])
+
+ switch typ {
+ case frameMethod:
+ if frame, err = r.parseMethodFrame(channel, size); err != nil {
+ return
+ }
+
+ case frameHeader:
+ if frame, err = r.parseHeaderFrame(channel, size); err != nil {
+ return
+ }
+
+ case frameBody:
+ if frame, err = r.parseBodyFrame(channel, size); err != nil {
+ return nil, err
+ }
+
+ case frameHeartbeat:
+ if frame, err = r.parseHeartbeatFrame(channel, size); err != nil {
+ return
+ }
+
+ default:
+ return nil, ErrFrame
+ }
+
+ if _, err = io.ReadFull(r.r, scratch[:1]); err != nil {
+ return nil, err
+ }
+
+ if scratch[0] != frameEnd {
+ return nil, ErrFrame
+ }
+
+ return
+}
+
+func readShortstr(r io.Reader) (v string, err error) {
+ var length uint8
+ if err = binary.Read(r, binary.BigEndian, &length); err != nil {
+ return
+ }
+
+ bytes := make([]byte, length)
+ if _, err = io.ReadFull(r, bytes); err != nil {
+ return
+ }
+ return string(bytes), nil
+}
+
+func readLongstr(r io.Reader) (v string, err error) {
+ var length uint32
+ if err = binary.Read(r, binary.BigEndian, &length); err != nil {
+ return
+ }
+
+ // slices can't be longer than max int32 value
+ if length > (^uint32(0) >> 1) {
+ return
+ }
+
+ bytes := make([]byte, length)
+ if _, err = io.ReadFull(r, bytes); err != nil {
+ return
+ }
+ return string(bytes), nil
+}
+
+func readDecimal(r io.Reader) (v Decimal, err error) {
+ if err = binary.Read(r, binary.BigEndian, &v.Scale); err != nil {
+ return
+ }
+ if err = binary.Read(r, binary.BigEndian, &v.Value); err != nil {
+ return
+ }
+ return
+}
+
+func readFloat32(r io.Reader) (v float32, err error) {
+ if err = binary.Read(r, binary.BigEndian, &v); err != nil {
+ return
+ }
+ return
+}
+
+func readFloat64(r io.Reader) (v float64, err error) {
+ if err = binary.Read(r, binary.BigEndian, &v); err != nil {
+ return
+ }
+ return
+}
+
+func readTimestamp(r io.Reader) (v time.Time, err error) {
+ var sec int64
+ if err = binary.Read(r, binary.BigEndian, &sec); err != nil {
+ return
+ }
+ return time.Unix(sec, 0), nil
+}
+
+/*
+'A': []interface{}
+'D': Decimal
+'F': Table
+'I': int32
+'S': string
+'T': time.Time
+'V': nil
+'b': byte
+'d': float64
+'f': float32
+'l': int64
+'s': int16
+'t': bool
+'x': []byte
+*/
+func readField(r io.Reader) (v interface{}, err error) {
+ var typ byte
+ if err = binary.Read(r, binary.BigEndian, &typ); err != nil {
+ return
+ }
+
+ switch typ {
+ case 't':
+ var value uint8
+ if err = binary.Read(r, binary.BigEndian, &value); err != nil {
+ return
+ }
+ return (value != 0), nil
+
+ case 'b':
+ var value [1]byte
+ if _, err = io.ReadFull(r, value[0:1]); err != nil {
+ return
+ }
+ return value[0], nil
+
+ case 's':
+ var value int16
+ if err = binary.Read(r, binary.BigEndian, &value); err != nil {
+ return
+ }
+ return value, nil
+
+ case 'I':
+ var value int32
+ if err = binary.Read(r, binary.BigEndian, &value); err != nil {
+ return
+ }
+ return value, nil
+
+ case 'l':
+ var value int64
+ if err = binary.Read(r, binary.BigEndian, &value); err != nil {
+ return
+ }
+ return value, nil
+
+ case 'f':
+ var value float32
+ if err = binary.Read(r, binary.BigEndian, &value); err != nil {
+ return
+ }
+ return value, nil
+
+ case 'd':
+ var value float64
+ if err = binary.Read(r, binary.BigEndian, &value); err != nil {
+ return
+ }
+ return value, nil
+
+ case 'D':
+ return readDecimal(r)
+
+ case 'S':
+ return readLongstr(r)
+
+ case 'A':
+ return readArray(r)
+
+ case 'T':
+ return readTimestamp(r)
+
+ case 'F':
+ return readTable(r)
+
+ case 'x':
+ var len int32
+ if err = binary.Read(r, binary.BigEndian, &len); err != nil {
+ return nil, err
+ }
+
+ value := make([]byte, len)
+ if _, err = io.ReadFull(r, value); err != nil {
+ return nil, err
+ }
+ return value, err
+
+ case 'V':
+ return nil, nil
+ }
+
+ return nil, ErrSyntax
+}
+
+/*
+ Field tables are long strings that contain packed name-value pairs. The
+ name-value pairs are encoded as short string defining the name, and octet
+ defining the values type and then the value itself. The valid field types for
+ tables are an extension of the native integer, bit, string, and timestamp
+ types, and are shown in the grammar. Multi-octet integer fields are always
+ held in network byte order.
+*/
+func readTable(r io.Reader) (table Table, err error) {
+ var nested bytes.Buffer
+ var str string
+
+ if str, err = readLongstr(r); err != nil {
+ return
+ }
+
+ nested.Write([]byte(str))
+
+ table = make(Table)
+
+ for nested.Len() > 0 {
+ var key string
+ var value interface{}
+
+ if key, err = readShortstr(&nested); err != nil {
+ return
+ }
+
+ if value, err = readField(&nested); err != nil {
+ return
+ }
+
+ table[key] = value
+ }
+
+ return
+}
+
+func readArray(r io.Reader) ([]interface{}, error) {
+ var (
+ size uint32
+ err error
+ )
+
+ if err = binary.Read(r, binary.BigEndian, &size); err != nil {
+ return nil, err
+ }
+
+ var (
+ lim = &io.LimitedReader{R: r, N: int64(size)}
+ arr = []interface{}{}
+ field interface{}
+ )
+
+ for {
+ if field, err = readField(lim); err != nil {
+ if err == io.EOF {
+ break
+ }
+ return nil, err
+ }
+ arr = append(arr, field)
+ }
+
+ return arr, nil
+}
+
+// Checks if this bit mask matches the flags bitset
+func hasProperty(mask uint16, prop int) bool {
+ return int(mask)&prop > 0
+}
+
+func (r *reader) parseHeaderFrame(channel uint16, size uint32) (frame frame, err error) {
+ hf := &headerFrame{
+ ChannelId: channel,
+ }
+
+ if err = binary.Read(r.r, binary.BigEndian, &hf.ClassId); err != nil {
+ return
+ }
+
+ if err = binary.Read(r.r, binary.BigEndian, &hf.weight); err != nil {
+ return
+ }
+
+ if err = binary.Read(r.r, binary.BigEndian, &hf.Size); err != nil {
+ return
+ }
+
+ var flags uint16
+
+ if err = binary.Read(r.r, binary.BigEndian, &flags); err != nil {
+ return
+ }
+
+ if hasProperty(flags, flagContentType) {
+ if hf.Properties.ContentType, err = readShortstr(r.r); err != nil {
+ return
+ }
+ }
+ if hasProperty(flags, flagContentEncoding) {
+ if hf.Properties.ContentEncoding, err = readShortstr(r.r); err != nil {
+ return
+ }
+ }
+ if hasProperty(flags, flagHeaders) {
+ if hf.Properties.Headers, err = readTable(r.r); err != nil {
+ return
+ }
+ }
+ if hasProperty(flags, flagDeliveryMode) {
+ if err = binary.Read(r.r, binary.BigEndian, &hf.Properties.DeliveryMode); err != nil {
+ return
+ }
+ }
+ if hasProperty(flags, flagPriority) {
+ if err = binary.Read(r.r, binary.BigEndian, &hf.Properties.Priority); err != nil {
+ return
+ }
+ }
+ if hasProperty(flags, flagCorrelationId) {
+ if hf.Properties.CorrelationId, err = readShortstr(r.r); err != nil {
+ return
+ }
+ }
+ if hasProperty(flags, flagReplyTo) {
+ if hf.Properties.ReplyTo, err = readShortstr(r.r); err != nil {
+ return
+ }
+ }
+ if hasProperty(flags, flagExpiration) {
+ if hf.Properties.Expiration, err = readShortstr(r.r); err != nil {
+ return
+ }
+ }
+ if hasProperty(flags, flagMessageId) {
+ if hf.Properties.MessageId, err = readShortstr(r.r); err != nil {
+ return
+ }
+ }
+ if hasProperty(flags, flagTimestamp) {
+ if hf.Properties.Timestamp, err = readTimestamp(r.r); err != nil {
+ return
+ }
+ }
+ if hasProperty(flags, flagType) {
+ if hf.Properties.Type, err = readShortstr(r.r); err != nil {
+ return
+ }
+ }
+ if hasProperty(flags, flagUserId) {
+ if hf.Properties.UserId, err = readShortstr(r.r); err != nil {
+ return
+ }
+ }
+ if hasProperty(flags, flagAppId) {
+ if hf.Properties.AppId, err = readShortstr(r.r); err != nil {
+ return
+ }
+ }
+ if hasProperty(flags, flagReserved1) {
+ if hf.Properties.reserved1, err = readShortstr(r.r); err != nil {
+ return
+ }
+ }
+
+ return hf, nil
+}
+
+func (r *reader) parseBodyFrame(channel uint16, size uint32) (frame frame, err error) {
+ bf := &bodyFrame{
+ ChannelId: channel,
+ Body: make([]byte, size),
+ }
+
+ if _, err = io.ReadFull(r.r, bf.Body); err != nil {
+ return nil, err
+ }
+
+ return bf, nil
+}
+
+var errHeartbeatPayload = errors.New("Heartbeats should not have a payload")
+
+func (r *reader) parseHeartbeatFrame(channel uint16, size uint32) (frame frame, err error) {
+ hf := &heartbeatFrame{
+ ChannelId: channel,
+ }
+
+ if size > 0 {
+ return nil, errHeartbeatPayload
+ }
+
+ return hf, nil
+}
diff --git a/src/dma/vendor/github.com/streadway/amqp/return.go b/src/dma/vendor/github.com/streadway/amqp/return.go
new file mode 100644
index 00000000..10dcedb2
--- /dev/null
+++ b/src/dma/vendor/github.com/streadway/amqp/return.go
@@ -0,0 +1,64 @@
+// Copyright (c) 2012, Sean Treadway, SoundCloud Ltd.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+// Source code and contact info at http://github.com/streadway/amqp
+
+package amqp
+
+import (
+ "time"
+)
+
+// Return captures a flattened struct of fields returned by the server when a
+// Publishing is unable to be delivered either due to the `mandatory` flag set
+// and no route found, or `immediate` flag set and no free consumer.
+type Return struct {
+ ReplyCode uint16 // reason
+ ReplyText string // description
+ Exchange string // basic.publish exchange
+ RoutingKey string // basic.publish routing key
+
+ // Properties
+ ContentType string // MIME content type
+ ContentEncoding string // MIME content encoding
+ Headers Table // Application or header exchange table
+ DeliveryMode uint8 // queue implementation use - non-persistent (1) or persistent (2)
+ Priority uint8 // queue implementation use - 0 to 9
+ CorrelationId string // application use - correlation identifier
+ ReplyTo string // application use - address to to reply to (ex: RPC)
+ Expiration string // implementation use - message expiration spec
+ MessageId string // application use - message identifier
+ Timestamp time.Time // application use - message timestamp
+ Type string // application use - message type name
+ UserId string // application use - creating user id
+ AppId string // application use - creating application
+
+ Body []byte
+}
+
+func newReturn(msg basicReturn) *Return {
+ props, body := msg.getContent()
+
+ return &Return{
+ ReplyCode: msg.ReplyCode,
+ ReplyText: msg.ReplyText,
+ Exchange: msg.Exchange,
+ RoutingKey: msg.RoutingKey,
+
+ Headers: props.Headers,
+ ContentType: props.ContentType,
+ ContentEncoding: props.ContentEncoding,
+ DeliveryMode: props.DeliveryMode,
+ Priority: props.Priority,
+ CorrelationId: props.CorrelationId,
+ ReplyTo: props.ReplyTo,
+ Expiration: props.Expiration,
+ MessageId: props.MessageId,
+ Timestamp: props.Timestamp,
+ Type: props.Type,
+ UserId: props.UserId,
+ AppId: props.AppId,
+
+ Body: body,
+ }
+}
diff --git a/src/dma/vendor/github.com/streadway/amqp/spec091.go b/src/dma/vendor/github.com/streadway/amqp/spec091.go
new file mode 100644
index 00000000..cd53ebe7
--- /dev/null
+++ b/src/dma/vendor/github.com/streadway/amqp/spec091.go
@@ -0,0 +1,3306 @@
+// Copyright (c) 2012, Sean Treadway, SoundCloud Ltd.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+// Source code and contact info at http://github.com/streadway/amqp
+
+/* GENERATED FILE - DO NOT EDIT */
+/* Rebuild from the spec/gen.go tool */
+
+package amqp
+
+import (
+ "encoding/binary"
+ "fmt"
+ "io"
+)
+
+// Error codes that can be sent from the server during a connection or
+// channel exception or used by the client to indicate a class of error like
+// ErrCredentials. The text of the error is likely more interesting than
+// these constants.
+const (
+ frameMethod = 1
+ frameHeader = 2
+ frameBody = 3
+ frameHeartbeat = 8
+ frameMinSize = 4096
+ frameEnd = 206
+ replySuccess = 200
+ ContentTooLarge = 311
+ NoRoute = 312
+ NoConsumers = 313
+ ConnectionForced = 320
+ InvalidPath = 402
+ AccessRefused = 403
+ NotFound = 404
+ ResourceLocked = 405
+ PreconditionFailed = 406
+ FrameError = 501
+ SyntaxError = 502
+ CommandInvalid = 503
+ ChannelError = 504
+ UnexpectedFrame = 505
+ ResourceError = 506
+ NotAllowed = 530
+ NotImplemented = 540
+ InternalError = 541
+)
+
+func isSoftExceptionCode(code int) bool {
+ switch code {
+ case 311:
+ return true
+ case 312:
+ return true
+ case 313:
+ return true
+ case 403:
+ return true
+ case 404:
+ return true
+ case 405:
+ return true
+ case 406:
+ return true
+
+ }
+ return false
+}
+
+type connectionStart struct {
+ VersionMajor byte
+ VersionMinor byte
+ ServerProperties Table
+ Mechanisms string
+ Locales string
+}
+
+func (msg *connectionStart) id() (uint16, uint16) {
+ return 10, 10
+}
+
+func (msg *connectionStart) wait() bool {
+ return true
+}
+
+func (msg *connectionStart) write(w io.Writer) (err error) {
+
+ if err = binary.Write(w, binary.BigEndian, msg.VersionMajor); err != nil {
+ return
+ }
+ if err = binary.Write(w, binary.BigEndian, msg.VersionMinor); err != nil {
+ return
+ }
+
+ if err = writeTable(w, msg.ServerProperties); err != nil {
+ return
+ }
+
+ if err = writeLongstr(w, msg.Mechanisms); err != nil {
+ return
+ }
+ if err = writeLongstr(w, msg.Locales); err != nil {
+ return
+ }
+
+ return
+}
+
+func (msg *connectionStart) read(r io.Reader) (err error) {
+
+ if err = binary.Read(r, binary.BigEndian, &msg.VersionMajor); err != nil {
+ return
+ }
+ if err = binary.Read(r, binary.BigEndian, &msg.VersionMinor); err != nil {
+ return
+ }
+
+ if msg.ServerProperties, err = readTable(r); err != nil {
+ return
+ }
+
+ if msg.Mechanisms, err = readLongstr(r); err != nil {
+ return
+ }
+ if msg.Locales, err = readLongstr(r); err != nil {
+ return
+ }
+
+ return
+}
+
+type connectionStartOk struct {
+ ClientProperties Table
+ Mechanism string
+ Response string
+ Locale string
+}
+
+func (msg *connectionStartOk) id() (uint16, uint16) {
+ return 10, 11
+}
+
+func (msg *connectionStartOk) wait() bool {
+ return true
+}
+
+func (msg *connectionStartOk) write(w io.Writer) (err error) {
+
+ if err = writeTable(w, msg.ClientProperties); err != nil {
+ return
+ }
+
+ if err = writeShortstr(w, msg.Mechanism); err != nil {
+ return
+ }
+
+ if err = writeLongstr(w, msg.Response); err != nil {
+ return
+ }
+
+ if err = writeShortstr(w, msg.Locale); err != nil {
+ return
+ }
+
+ return
+}
+
+func (msg *connectionStartOk) read(r io.Reader) (err error) {
+
+ if msg.ClientProperties, err = readTable(r); err != nil {
+ return
+ }
+
+ if msg.Mechanism, err = readShortstr(r); err != nil {
+ return
+ }
+
+ if msg.Response, err = readLongstr(r); err != nil {
+ return
+ }
+
+ if msg.Locale, err = readShortstr(r); err != nil {
+ return
+ }
+
+ return
+}
+
+type connectionSecure struct {
+ Challenge string
+}
+
+func (msg *connectionSecure) id() (uint16, uint16) {
+ return 10, 20
+}
+
+func (msg *connectionSecure) wait() bool {
+ return true
+}
+
+func (msg *connectionSecure) write(w io.Writer) (err error) {
+
+ if err = writeLongstr(w, msg.Challenge); err != nil {
+ return
+ }
+
+ return
+}
+
+func (msg *connectionSecure) read(r io.Reader) (err error) {
+
+ if msg.Challenge, err = readLongstr(r); err != nil {
+ return
+ }
+
+ return
+}
+
+type connectionSecureOk struct {
+ Response string
+}
+
+func (msg *connectionSecureOk) id() (uint16, uint16) {
+ return 10, 21
+}
+
+func (msg *connectionSecureOk) wait() bool {
+ return true
+}
+
+func (msg *connectionSecureOk) write(w io.Writer) (err error) {
+
+ if err = writeLongstr(w, msg.Response); err != nil {
+ return
+ }
+
+ return
+}
+
+func (msg *connectionSecureOk) read(r io.Reader) (err error) {
+
+ if msg.Response, err = readLongstr(r); err != nil {
+ return
+ }
+
+ return
+}
+
+type connectionTune struct {
+ ChannelMax uint16
+ FrameMax uint32
+ Heartbeat uint16
+}
+
+func (msg *connectionTune) id() (uint16, uint16) {
+ return 10, 30
+}
+
+func (msg *connectionTune) wait() bool {
+ return true
+}
+
+func (msg *connectionTune) write(w io.Writer) (err error) {
+
+ if err = binary.Write(w, binary.BigEndian, msg.ChannelMax); err != nil {
+ return
+ }
+
+ if err = binary.Write(w, binary.BigEndian, msg.FrameMax); err != nil {
+ return
+ }
+
+ if err = binary.Write(w, binary.BigEndian, msg.Heartbeat); err != nil {
+ return
+ }
+
+ return
+}
+
+func (msg *connectionTune) read(r io.Reader) (err error) {
+
+ if err = binary.Read(r, binary.BigEndian, &msg.ChannelMax); err != nil {
+ return
+ }
+
+ if err = binary.Read(r, binary.BigEndian, &msg.FrameMax); err != nil {
+ return
+ }
+
+ if err = binary.Read(r, binary.BigEndian, &msg.Heartbeat); err != nil {
+ return
+ }
+
+ return
+}
+
+type connectionTuneOk struct {
+ ChannelMax uint16
+ FrameMax uint32
+ Heartbeat uint16
+}
+
+func (msg *connectionTuneOk) id() (uint16, uint16) {
+ return 10, 31
+}
+
+func (msg *connectionTuneOk) wait() bool {
+ return true
+}
+
+func (msg *connectionTuneOk) write(w io.Writer) (err error) {
+
+ if err = binary.Write(w, binary.BigEndian, msg.ChannelMax); err != nil {
+ return
+ }
+
+ if err = binary.Write(w, binary.BigEndian, msg.FrameMax); err != nil {
+ return
+ }
+
+ if err = binary.Write(w, binary.BigEndian, msg.Heartbeat); err != nil {
+ return
+ }
+
+ return
+}
+
+func (msg *connectionTuneOk) read(r io.Reader) (err error) {
+
+ if err = binary.Read(r, binary.BigEndian, &msg.ChannelMax); err != nil {
+ return
+ }
+
+ if err = binary.Read(r, binary.BigEndian, &msg.FrameMax); err != nil {
+ return
+ }
+
+ if err = binary.Read(r, binary.BigEndian, &msg.Heartbeat); err != nil {
+ return
+ }
+
+ return
+}
+
+type connectionOpen struct {
+ VirtualHost string
+ reserved1 string
+ reserved2 bool
+}
+
+func (msg *connectionOpen) id() (uint16, uint16) {
+ return 10, 40
+}
+
+func (msg *connectionOpen) wait() bool {
+ return true
+}
+
+func (msg *connectionOpen) write(w io.Writer) (err error) {
+ var bits byte
+
+ if err = writeShortstr(w, msg.VirtualHost); err != nil {
+ return
+ }
+ if err = writeShortstr(w, msg.reserved1); err != nil {
+ return
+ }
+
+ if msg.reserved2 {
+ bits |= 1 << 0
+ }
+
+ if err = binary.Write(w, binary.BigEndian, bits); err != nil {
+ return
+ }
+
+ return
+}
+
+func (msg *connectionOpen) read(r io.Reader) (err error) {
+ var bits byte
+
+ if msg.VirtualHost, err = readShortstr(r); err != nil {
+ return
+ }
+ if msg.reserved1, err = readShortstr(r); err != nil {
+ return
+ }
+
+ if err = binary.Read(r, binary.BigEndian, &bits); err != nil {
+ return
+ }
+ msg.reserved2 = (bits&(1<<0) > 0)
+
+ return
+}
+
+type connectionOpenOk struct {
+ reserved1 string
+}
+
+func (msg *connectionOpenOk) id() (uint16, uint16) {
+ return 10, 41
+}
+
+func (msg *connectionOpenOk) wait() bool {
+ return true
+}
+
+func (msg *connectionOpenOk) write(w io.Writer) (err error) {
+
+ if err = writeShortstr(w, msg.reserved1); err != nil {
+ return
+ }
+
+ return
+}
+
+func (msg *connectionOpenOk) read(r io.Reader) (err error) {
+
+ if msg.reserved1, err = readShortstr(r); err != nil {
+ return
+ }
+
+ return
+}
+
+type connectionClose struct {
+ ReplyCode uint16
+ ReplyText string
+ ClassId uint16
+ MethodId uint16
+}
+
+func (msg *connectionClose) id() (uint16, uint16) {
+ return 10, 50
+}
+
+func (msg *connectionClose) wait() bool {
+ return true
+}
+
+func (msg *connectionClose) write(w io.Writer) (err error) {
+
+ if err = binary.Write(w, binary.BigEndian, msg.ReplyCode); err != nil {
+ return
+ }
+
+ if err = writeShortstr(w, msg.ReplyText); err != nil {
+ return
+ }
+
+ if err = binary.Write(w, binary.BigEndian, msg.ClassId); err != nil {
+ return
+ }
+ if err = binary.Write(w, binary.BigEndian, msg.MethodId); err != nil {
+ return
+ }
+
+ return
+}
+
+func (msg *connectionClose) read(r io.Reader) (err error) {
+
+ if err = binary.Read(r, binary.BigEndian, &msg.ReplyCode); err != nil {
+ return
+ }
+
+ if msg.ReplyText, err = readShortstr(r); err != nil {
+ return
+ }
+
+ if err = binary.Read(r, binary.BigEndian, &msg.ClassId); err != nil {
+ return
+ }
+ if err = binary.Read(r, binary.BigEndian, &msg.MethodId); err != nil {
+ return
+ }
+
+ return
+}
+
+type connectionCloseOk struct {
+}
+
+func (msg *connectionCloseOk) id() (uint16, uint16) {
+ return 10, 51
+}
+
+func (msg *connectionCloseOk) wait() bool {
+ return true
+}
+
+func (msg *connectionCloseOk) write(w io.Writer) (err error) {
+
+ return
+}
+
+func (msg *connectionCloseOk) read(r io.Reader) (err error) {
+
+ return
+}
+
+type connectionBlocked struct {
+ Reason string
+}
+
+func (msg *connectionBlocked) id() (uint16, uint16) {
+ return 10, 60
+}
+
+func (msg *connectionBlocked) wait() bool {
+ return false
+}
+
+func (msg *connectionBlocked) write(w io.Writer) (err error) {
+
+ if err = writeShortstr(w, msg.Reason); err != nil {
+ return
+ }
+
+ return
+}
+
+func (msg *connectionBlocked) read(r io.Reader) (err error) {
+
+ if msg.Reason, err = readShortstr(r); err != nil {
+ return
+ }
+
+ return
+}
+
+type connectionUnblocked struct {
+}
+
+func (msg *connectionUnblocked) id() (uint16, uint16) {
+ return 10, 61
+}
+
+func (msg *connectionUnblocked) wait() bool {
+ return false
+}
+
+func (msg *connectionUnblocked) write(w io.Writer) (err error) {
+
+ return
+}
+
+func (msg *connectionUnblocked) read(r io.Reader) (err error) {
+
+ return
+}
+
+type channelOpen struct {
+ reserved1 string
+}
+
+func (msg *channelOpen) id() (uint16, uint16) {
+ return 20, 10
+}
+
+func (msg *channelOpen) wait() bool {
+ return true
+}
+
+func (msg *channelOpen) write(w io.Writer) (err error) {
+
+ if err = writeShortstr(w, msg.reserved1); err != nil {
+ return
+ }
+
+ return
+}
+
+func (msg *channelOpen) read(r io.Reader) (err error) {
+
+ if msg.reserved1, err = readShortstr(r); err != nil {
+ return
+ }
+
+ return
+}
+
+type channelOpenOk struct {
+ reserved1 string
+}
+
+func (msg *channelOpenOk) id() (uint16, uint16) {
+ return 20, 11
+}
+
+func (msg *channelOpenOk) wait() bool {
+ return true
+}
+
+func (msg *channelOpenOk) write(w io.Writer) (err error) {
+
+ if err = writeLongstr(w, msg.reserved1); err != nil {
+ return
+ }
+
+ return
+}
+
+func (msg *channelOpenOk) read(r io.Reader) (err error) {
+
+ if msg.reserved1, err = readLongstr(r); err != nil {
+ return
+ }
+
+ return
+}
+
+type channelFlow struct {
+ Active bool
+}
+
+func (msg *channelFlow) id() (uint16, uint16) {
+ return 20, 20
+}
+
+func (msg *channelFlow) wait() bool {
+ return true
+}
+
+func (msg *channelFlow) write(w io.Writer) (err error) {
+ var bits byte
+
+ if msg.Active {
+ bits |= 1 << 0
+ }
+
+ if err = binary.Write(w, binary.BigEndian, bits); err != nil {
+ return
+ }
+
+ return
+}
+
+func (msg *channelFlow) read(r io.Reader) (err error) {
+ var bits byte
+
+ if err = binary.Read(r, binary.BigEndian, &bits); err != nil {
+ return
+ }
+ msg.Active = (bits&(1<<0) > 0)
+
+ return
+}
+
+type channelFlowOk struct {
+ Active bool
+}
+
+func (msg *channelFlowOk) id() (uint16, uint16) {
+ return 20, 21
+}
+
+func (msg *channelFlowOk) wait() bool {
+ return false
+}
+
+func (msg *channelFlowOk) write(w io.Writer) (err error) {
+ var bits byte
+
+ if msg.Active {
+ bits |= 1 << 0
+ }
+
+ if err = binary.Write(w, binary.BigEndian, bits); err != nil {
+ return
+ }
+
+ return
+}
+
+func (msg *channelFlowOk) read(r io.Reader) (err error) {
+ var bits byte
+
+ if err = binary.Read(r, binary.BigEndian, &bits); err != nil {
+ return
+ }
+ msg.Active = (bits&(1<<0) > 0)
+
+ return
+}
+
+type channelClose struct {
+ ReplyCode uint16
+ ReplyText string
+ ClassId uint16
+ MethodId uint16
+}
+
+func (msg *channelClose) id() (uint16, uint16) {
+ return 20, 40
+}
+
+func (msg *channelClose) wait() bool {
+ return true
+}
+
+func (msg *channelClose) write(w io.Writer) (err error) {
+
+ if err = binary.Write(w, binary.BigEndian, msg.ReplyCode); err != nil {
+ return
+ }
+
+ if err = writeShortstr(w, msg.ReplyText); err != nil {
+ return
+ }
+
+ if err = binary.Write(w, binary.BigEndian, msg.ClassId); err != nil {
+ return
+ }
+ if err = binary.Write(w, binary.BigEndian, msg.MethodId); err != nil {
+ return
+ }
+
+ return
+}
+
+func (msg *channelClose) read(r io.Reader) (err error) {
+
+ if err = binary.Read(r, binary.BigEndian, &msg.ReplyCode); err != nil {
+ return
+ }
+
+ if msg.ReplyText, err = readShortstr(r); err != nil {
+ return
+ }
+
+ if err = binary.Read(r, binary.BigEndian, &msg.ClassId); err != nil {
+ return
+ }
+ if err = binary.Read(r, binary.BigEndian, &msg.MethodId); err != nil {
+ return
+ }
+
+ return
+}
+
+type channelCloseOk struct {
+}
+
+func (msg *channelCloseOk) id() (uint16, uint16) {
+ return 20, 41
+}
+
+func (msg *channelCloseOk) wait() bool {
+ return true
+}
+
+func (msg *channelCloseOk) write(w io.Writer) (err error) {
+
+ return
+}
+
+func (msg *channelCloseOk) read(r io.Reader) (err error) {
+
+ return
+}
+
+type exchangeDeclare struct {
+ reserved1 uint16
+ Exchange string
+ Type string
+ Passive bool
+ Durable bool
+ AutoDelete bool
+ Internal bool
+ NoWait bool
+ Arguments Table
+}
+
+func (msg *exchangeDeclare) id() (uint16, uint16) {
+ return 40, 10
+}
+
+func (msg *exchangeDeclare) wait() bool {
+ return true && !msg.NoWait
+}
+
+func (msg *exchangeDeclare) write(w io.Writer) (err error) {
+ var bits byte
+
+ if err = binary.Write(w, binary.BigEndian, msg.reserved1); err != nil {
+ return
+ }
+
+ if err = writeShortstr(w, msg.Exchange); err != nil {
+ return
+ }
+ if err = writeShortstr(w, msg.Type); err != nil {
+ return
+ }
+
+ if msg.Passive {
+ bits |= 1 << 0
+ }
+
+ if msg.Durable {
+ bits |= 1 << 1
+ }
+
+ if msg.AutoDelete {
+ bits |= 1 << 2
+ }
+
+ if msg.Internal {
+ bits |= 1 << 3
+ }
+
+ if msg.NoWait {
+ bits |= 1 << 4
+ }
+
+ if err = binary.Write(w, binary.BigEndian, bits); err != nil {
+ return
+ }
+
+ if err = writeTable(w, msg.Arguments); err != nil {
+ return
+ }
+
+ return
+}
+
+func (msg *exchangeDeclare) read(r io.Reader) (err error) {
+ var bits byte
+
+ if err = binary.Read(r, binary.BigEndian, &msg.reserved1); err != nil {
+ return
+ }
+
+ if msg.Exchange, err = readShortstr(r); err != nil {
+ return
+ }
+ if msg.Type, err = readShortstr(r); err != nil {
+ return
+ }
+
+ if err = binary.Read(r, binary.BigEndian, &bits); err != nil {
+ return
+ }
+ msg.Passive = (bits&(1<<0) > 0)
+ msg.Durable = (bits&(1<<1) > 0)
+ msg.AutoDelete = (bits&(1<<2) > 0)
+ msg.Internal = (bits&(1<<3) > 0)
+ msg.NoWait = (bits&(1<<4) > 0)
+
+ if msg.Arguments, err = readTable(r); err != nil {
+ return
+ }
+
+ return
+}
+
+type exchangeDeclareOk struct {
+}
+
+func (msg *exchangeDeclareOk) id() (uint16, uint16) {
+ return 40, 11
+}
+
+func (msg *exchangeDeclareOk) wait() bool {
+ return true
+}
+
+func (msg *exchangeDeclareOk) write(w io.Writer) (err error) {
+
+ return
+}
+
+func (msg *exchangeDeclareOk) read(r io.Reader) (err error) {
+
+ return
+}
+
+type exchangeDelete struct {
+ reserved1 uint16
+ Exchange string
+ IfUnused bool
+ NoWait bool
+}
+
+func (msg *exchangeDelete) id() (uint16, uint16) {
+ return 40, 20
+}
+
+func (msg *exchangeDelete) wait() bool {
+ return true && !msg.NoWait
+}
+
+func (msg *exchangeDelete) write(w io.Writer) (err error) {
+ var bits byte
+
+ if err = binary.Write(w, binary.BigEndian, msg.reserved1); err != nil {
+ return
+ }
+
+ if err = writeShortstr(w, msg.Exchange); err != nil {
+ return
+ }
+
+ if msg.IfUnused {
+ bits |= 1 << 0
+ }
+
+ if msg.NoWait {
+ bits |= 1 << 1
+ }
+
+ if err = binary.Write(w, binary.BigEndian, bits); err != nil {
+ return
+ }
+
+ return
+}
+
+func (msg *exchangeDelete) read(r io.Reader) (err error) {
+ var bits byte
+
+ if err = binary.Read(r, binary.BigEndian, &msg.reserved1); err != nil {
+ return
+ }
+
+ if msg.Exchange, err = readShortstr(r); err != nil {
+ return
+ }
+
+ if err = binary.Read(r, binary.BigEndian, &bits); err != nil {
+ return
+ }
+ msg.IfUnused = (bits&(1<<0) > 0)
+ msg.NoWait = (bits&(1<<1) > 0)
+
+ return
+}
+
+type exchangeDeleteOk struct {
+}
+
+func (msg *exchangeDeleteOk) id() (uint16, uint16) {
+ return 40, 21
+}
+
+func (msg *exchangeDeleteOk) wait() bool {
+ return true
+}
+
+func (msg *exchangeDeleteOk) write(w io.Writer) (err error) {
+
+ return
+}
+
+func (msg *exchangeDeleteOk) read(r io.Reader) (err error) {
+
+ return
+}
+
+type exchangeBind struct {
+ reserved1 uint16
+ Destination string
+ Source string
+ RoutingKey string
+ NoWait bool
+ Arguments Table
+}
+
+func (msg *exchangeBind) id() (uint16, uint16) {
+ return 40, 30
+}
+
+func (msg *exchangeBind) wait() bool {
+ return true && !msg.NoWait
+}
+
+func (msg *exchangeBind) write(w io.Writer) (err error) {
+ var bits byte
+
+ if err = binary.Write(w, binary.BigEndian, msg.reserved1); err != nil {
+ return
+ }
+
+ if err = writeShortstr(w, msg.Destination); err != nil {
+ return
+ }
+ if err = writeShortstr(w, msg.Source); err != nil {
+ return
+ }
+ if err = writeShortstr(w, msg.RoutingKey); err != nil {
+ return
+ }
+
+ if msg.NoWait {
+ bits |= 1 << 0
+ }
+
+ if err = binary.Write(w, binary.BigEndian, bits); err != nil {
+ return
+ }
+
+ if err = writeTable(w, msg.Arguments); err != nil {
+ return
+ }
+
+ return
+}
+
+func (msg *exchangeBind) read(r io.Reader) (err error) {
+ var bits byte
+
+ if err = binary.Read(r, binary.BigEndian, &msg.reserved1); err != nil {
+ return
+ }
+
+ if msg.Destination, err = readShortstr(r); err != nil {
+ return
+ }
+ if msg.Source, err = readShortstr(r); err != nil {
+ return
+ }
+ if msg.RoutingKey, err = readShortstr(r); err != nil {
+ return
+ }
+
+ if err = binary.Read(r, binary.BigEndian, &bits); err != nil {
+ return
+ }
+ msg.NoWait = (bits&(1<<0) > 0)
+
+ if msg.Arguments, err = readTable(r); err != nil {
+ return
+ }
+
+ return
+}
+
+type exchangeBindOk struct {
+}
+
+func (msg *exchangeBindOk) id() (uint16, uint16) {
+ return 40, 31
+}
+
+func (msg *exchangeBindOk) wait() bool {
+ return true
+}
+
+func (msg *exchangeBindOk) write(w io.Writer) (err error) {
+
+ return
+}
+
+func (msg *exchangeBindOk) read(r io.Reader) (err error) {
+
+ return
+}
+
+type exchangeUnbind struct {
+ reserved1 uint16
+ Destination string
+ Source string
+ RoutingKey string
+ NoWait bool
+ Arguments Table
+}
+
+func (msg *exchangeUnbind) id() (uint16, uint16) {
+ return 40, 40
+}
+
+func (msg *exchangeUnbind) wait() bool {
+ return true && !msg.NoWait
+}
+
+func (msg *exchangeUnbind) write(w io.Writer) (err error) {
+ var bits byte
+
+ if err = binary.Write(w, binary.BigEndian, msg.reserved1); err != nil {
+ return
+ }
+
+ if err = writeShortstr(w, msg.Destination); err != nil {
+ return
+ }
+ if err = writeShortstr(w, msg.Source); err != nil {
+ return
+ }
+ if err = writeShortstr(w, msg.RoutingKey); err != nil {
+ return
+ }
+
+ if msg.NoWait {
+ bits |= 1 << 0
+ }
+
+ if err = binary.Write(w, binary.BigEndian, bits); err != nil {
+ return
+ }
+
+ if err = writeTable(w, msg.Arguments); err != nil {
+ return
+ }
+
+ return
+}
+
+func (msg *exchangeUnbind) read(r io.Reader) (err error) {
+ var bits byte
+
+ if err = binary.Read(r, binary.BigEndian, &msg.reserved1); err != nil {
+ return
+ }
+
+ if msg.Destination, err = readShortstr(r); err != nil {
+ return
+ }
+ if msg.Source, err = readShortstr(r); err != nil {
+ return
+ }
+ if msg.RoutingKey, err = readShortstr(r); err != nil {
+ return
+ }
+
+ if err = binary.Read(r, binary.BigEndian, &bits); err != nil {
+ return
+ }
+ msg.NoWait = (bits&(1<<0) > 0)
+
+ if msg.Arguments, err = readTable(r); err != nil {
+ return
+ }
+
+ return
+}
+
+type exchangeUnbindOk struct {
+}
+
+func (msg *exchangeUnbindOk) id() (uint16, uint16) {
+ return 40, 51
+}
+
+func (msg *exchangeUnbindOk) wait() bool {
+ return true
+}
+
+func (msg *exchangeUnbindOk) write(w io.Writer) (err error) {
+
+ return
+}
+
+func (msg *exchangeUnbindOk) read(r io.Reader) (err error) {
+
+ return
+}
+
+type queueDeclare struct {
+ reserved1 uint16
+ Queue string
+ Passive bool
+ Durable bool
+ Exclusive bool
+ AutoDelete bool
+ NoWait bool
+ Arguments Table
+}
+
+func (msg *queueDeclare) id() (uint16, uint16) {
+ return 50, 10
+}
+
+func (msg *queueDeclare) wait() bool {
+ return true && !msg.NoWait
+}
+
+func (msg *queueDeclare) write(w io.Writer) (err error) {
+ var bits byte
+
+ if err = binary.Write(w, binary.BigEndian, msg.reserved1); err != nil {
+ return
+ }
+
+ if err = writeShortstr(w, msg.Queue); err != nil {
+ return
+ }
+
+ if msg.Passive {
+ bits |= 1 << 0
+ }
+
+ if msg.Durable {
+ bits |= 1 << 1
+ }
+
+ if msg.Exclusive {
+ bits |= 1 << 2
+ }
+
+ if msg.AutoDelete {
+ bits |= 1 << 3
+ }
+
+ if msg.NoWait {
+ bits |= 1 << 4
+ }
+
+ if err = binary.Write(w, binary.BigEndian, bits); err != nil {
+ return
+ }
+
+ if err = writeTable(w, msg.Arguments); err != nil {
+ return
+ }
+
+ return
+}
+
+func (msg *queueDeclare) read(r io.Reader) (err error) {
+ var bits byte
+
+ if err = binary.Read(r, binary.BigEndian, &msg.reserved1); err != nil {
+ return
+ }
+
+ if msg.Queue, err = readShortstr(r); err != nil {
+ return
+ }
+
+ if err = binary.Read(r, binary.BigEndian, &bits); err != nil {
+ return
+ }
+ msg.Passive = (bits&(1<<0) > 0)
+ msg.Durable = (bits&(1<<1) > 0)
+ msg.Exclusive = (bits&(1<<2) > 0)
+ msg.AutoDelete = (bits&(1<<3) > 0)
+ msg.NoWait = (bits&(1<<4) > 0)
+
+ if msg.Arguments, err = readTable(r); err != nil {
+ return
+ }
+
+ return
+}
+
+type queueDeclareOk struct {
+ Queue string
+ MessageCount uint32
+ ConsumerCount uint32
+}
+
+func (msg *queueDeclareOk) id() (uint16, uint16) {
+ return 50, 11
+}
+
+func (msg *queueDeclareOk) wait() bool {
+ return true
+}
+
+func (msg *queueDeclareOk) write(w io.Writer) (err error) {
+
+ if err = writeShortstr(w, msg.Queue); err != nil {
+ return
+ }
+
+ if err = binary.Write(w, binary.BigEndian, msg.MessageCount); err != nil {
+ return
+ }
+ if err = binary.Write(w, binary.BigEndian, msg.ConsumerCount); err != nil {
+ return
+ }
+
+ return
+}
+
+func (msg *queueDeclareOk) read(r io.Reader) (err error) {
+
+ if msg.Queue, err = readShortstr(r); err != nil {
+ return
+ }
+
+ if err = binary.Read(r, binary.BigEndian, &msg.MessageCount); err != nil {
+ return
+ }
+ if err = binary.Read(r, binary.BigEndian, &msg.ConsumerCount); err != nil {
+ return
+ }
+
+ return
+}
+
+type queueBind struct {
+ reserved1 uint16
+ Queue string
+ Exchange string
+ RoutingKey string
+ NoWait bool
+ Arguments Table
+}
+
+func (msg *queueBind) id() (uint16, uint16) {
+ return 50, 20
+}
+
+func (msg *queueBind) wait() bool {
+ return true && !msg.NoWait
+}
+
+func (msg *queueBind) write(w io.Writer) (err error) {
+ var bits byte
+
+ if err = binary.Write(w, binary.BigEndian, msg.reserved1); err != nil {
+ return
+ }
+
+ if err = writeShortstr(w, msg.Queue); err != nil {
+ return
+ }
+ if err = writeShortstr(w, msg.Exchange); err != nil {
+ return
+ }
+ if err = writeShortstr(w, msg.RoutingKey); err != nil {
+ return
+ }
+
+ if msg.NoWait {
+ bits |= 1 << 0
+ }
+
+ if err = binary.Write(w, binary.BigEndian, bits); err != nil {
+ return
+ }
+
+ if err = writeTable(w, msg.Arguments); err != nil {
+ return
+ }
+
+ return
+}
+
+func (msg *queueBind) read(r io.Reader) (err error) {
+ var bits byte
+
+ if err = binary.Read(r, binary.BigEndian, &msg.reserved1); err != nil {
+ return
+ }
+
+ if msg.Queue, err = readShortstr(r); err != nil {
+ return
+ }
+ if msg.Exchange, err = readShortstr(r); err != nil {
+ return
+ }
+ if msg.RoutingKey, err = readShortstr(r); err != nil {
+ return
+ }
+
+ if err = binary.Read(r, binary.BigEndian, &bits); err != nil {
+ return
+ }
+ msg.NoWait = (bits&(1<<0) > 0)
+
+ if msg.Arguments, err = readTable(r); err != nil {
+ return
+ }
+
+ return
+}
+
+type queueBindOk struct {
+}
+
+func (msg *queueBindOk) id() (uint16, uint16) {
+ return 50, 21
+}
+
+func (msg *queueBindOk) wait() bool {
+ return true
+}
+
+func (msg *queueBindOk) write(w io.Writer) (err error) {
+
+ return
+}
+
+func (msg *queueBindOk) read(r io.Reader) (err error) {
+
+ return
+}
+
+type queueUnbind struct {
+ reserved1 uint16
+ Queue string
+ Exchange string
+ RoutingKey string
+ Arguments Table
+}
+
+func (msg *queueUnbind) id() (uint16, uint16) {
+ return 50, 50
+}
+
+func (msg *queueUnbind) wait() bool {
+ return true
+}
+
+func (msg *queueUnbind) write(w io.Writer) (err error) {
+
+ if err = binary.Write(w, binary.BigEndian, msg.reserved1); err != nil {
+ return
+ }
+
+ if err = writeShortstr(w, msg.Queue); err != nil {
+ return
+ }
+ if err = writeShortstr(w, msg.Exchange); err != nil {
+ return
+ }
+ if err = writeShortstr(w, msg.RoutingKey); err != nil {
+ return
+ }
+
+ if err = writeTable(w, msg.Arguments); err != nil {
+ return
+ }
+
+ return
+}
+
+func (msg *queueUnbind) read(r io.Reader) (err error) {
+
+ if err = binary.Read(r, binary.BigEndian, &msg.reserved1); err != nil {
+ return
+ }
+
+ if msg.Queue, err = readShortstr(r); err != nil {
+ return
+ }
+ if msg.Exchange, err = readShortstr(r); err != nil {
+ return
+ }
+ if msg.RoutingKey, err = readShortstr(r); err != nil {
+ return
+ }
+
+ if msg.Arguments, err = readTable(r); err != nil {
+ return
+ }
+
+ return
+}
+
+type queueUnbindOk struct {
+}
+
+func (msg *queueUnbindOk) id() (uint16, uint16) {
+ return 50, 51
+}
+
+func (msg *queueUnbindOk) wait() bool {
+ return true
+}
+
+func (msg *queueUnbindOk) write(w io.Writer) (err error) {
+
+ return
+}
+
+func (msg *queueUnbindOk) read(r io.Reader) (err error) {
+
+ return
+}
+
+type queuePurge struct {
+ reserved1 uint16
+ Queue string
+ NoWait bool
+}
+
+func (msg *queuePurge) id() (uint16, uint16) {
+ return 50, 30
+}
+
+func (msg *queuePurge) wait() bool {
+ return true && !msg.NoWait
+}
+
+func (msg *queuePurge) write(w io.Writer) (err error) {
+ var bits byte
+
+ if err = binary.Write(w, binary.BigEndian, msg.reserved1); err != nil {
+ return
+ }
+
+ if err = writeShortstr(w, msg.Queue); err != nil {
+ return
+ }
+
+ if msg.NoWait {
+ bits |= 1 << 0
+ }
+
+ if err = binary.Write(w, binary.BigEndian, bits); err != nil {
+ return
+ }
+
+ return
+}
+
+func (msg *queuePurge) read(r io.Reader) (err error) {
+ var bits byte
+
+ if err = binary.Read(r, binary.BigEndian, &msg.reserved1); err != nil {
+ return
+ }
+
+ if msg.Queue, err = readShortstr(r); err != nil {
+ return
+ }
+
+ if err = binary.Read(r, binary.BigEndian, &bits); err != nil {
+ return
+ }
+ msg.NoWait = (bits&(1<<0) > 0)
+
+ return
+}
+
+type queuePurgeOk struct {
+ MessageCount uint32
+}
+
+func (msg *queuePurgeOk) id() (uint16, uint16) {
+ return 50, 31
+}
+
+func (msg *queuePurgeOk) wait() bool {
+ return true
+}
+
+func (msg *queuePurgeOk) write(w io.Writer) (err error) {
+
+ if err = binary.Write(w, binary.BigEndian, msg.MessageCount); err != nil {
+ return
+ }
+
+ return
+}
+
+func (msg *queuePurgeOk) read(r io.Reader) (err error) {
+
+ if err = binary.Read(r, binary.BigEndian, &msg.MessageCount); err != nil {
+ return
+ }
+
+ return
+}
+
+type queueDelete struct {
+ reserved1 uint16
+ Queue string
+ IfUnused bool
+ IfEmpty bool
+ NoWait bool
+}
+
+func (msg *queueDelete) id() (uint16, uint16) {
+ return 50, 40
+}
+
+func (msg *queueDelete) wait() bool {
+ return true && !msg.NoWait
+}
+
+func (msg *queueDelete) write(w io.Writer) (err error) {
+ var bits byte
+
+ if err = binary.Write(w, binary.BigEndian, msg.reserved1); err != nil {
+ return
+ }
+
+ if err = writeShortstr(w, msg.Queue); err != nil {
+ return
+ }
+
+ if msg.IfUnused {
+ bits |= 1 << 0
+ }
+
+ if msg.IfEmpty {
+ bits |= 1 << 1
+ }
+
+ if msg.NoWait {
+ bits |= 1 << 2
+ }
+
+ if err = binary.Write(w, binary.BigEndian, bits); err != nil {
+ return
+ }
+
+ return
+}
+
+func (msg *queueDelete) read(r io.Reader) (err error) {
+ var bits byte
+
+ if err = binary.Read(r, binary.BigEndian, &msg.reserved1); err != nil {
+ return
+ }
+
+ if msg.Queue, err = readShortstr(r); err != nil {
+ return
+ }
+
+ if err = binary.Read(r, binary.BigEndian, &bits); err != nil {
+ return
+ }
+ msg.IfUnused = (bits&(1<<0) > 0)
+ msg.IfEmpty = (bits&(1<<1) > 0)
+ msg.NoWait = (bits&(1<<2) > 0)
+
+ return
+}
+
+type queueDeleteOk struct {
+ MessageCount uint32
+}
+
+func (msg *queueDeleteOk) id() (uint16, uint16) {
+ return 50, 41
+}
+
+func (msg *queueDeleteOk) wait() bool {
+ return true
+}
+
+func (msg *queueDeleteOk) write(w io.Writer) (err error) {
+
+ if err = binary.Write(w, binary.BigEndian, msg.MessageCount); err != nil {
+ return
+ }
+
+ return
+}
+
+func (msg *queueDeleteOk) read(r io.Reader) (err error) {
+
+ if err = binary.Read(r, binary.BigEndian, &msg.MessageCount); err != nil {
+ return
+ }
+
+ return
+}
+
+type basicQos struct {
+ PrefetchSize uint32
+ PrefetchCount uint16
+ Global bool
+}
+
+func (msg *basicQos) id() (uint16, uint16) {
+ return 60, 10
+}
+
+func (msg *basicQos) wait() bool {
+ return true
+}
+
+func (msg *basicQos) write(w io.Writer) (err error) {
+ var bits byte
+
+ if err = binary.Write(w, binary.BigEndian, msg.PrefetchSize); err != nil {
+ return
+ }
+
+ if err = binary.Write(w, binary.BigEndian, msg.PrefetchCount); err != nil {
+ return
+ }
+
+ if msg.Global {
+ bits |= 1 << 0
+ }
+
+ if err = binary.Write(w, binary.BigEndian, bits); err != nil {
+ return
+ }
+
+ return
+}
+
+func (msg *basicQos) read(r io.Reader) (err error) {
+ var bits byte
+
+ if err = binary.Read(r, binary.BigEndian, &msg.PrefetchSize); err != nil {
+ return
+ }
+
+ if err = binary.Read(r, binary.BigEndian, &msg.PrefetchCount); err != nil {
+ return
+ }
+
+ if err = binary.Read(r, binary.BigEndian, &bits); err != nil {
+ return
+ }
+ msg.Global = (bits&(1<<0) > 0)
+
+ return
+}
+
+type basicQosOk struct {
+}
+
+func (msg *basicQosOk) id() (uint16, uint16) {
+ return 60, 11
+}
+
+func (msg *basicQosOk) wait() bool {
+ return true
+}
+
+func (msg *basicQosOk) write(w io.Writer) (err error) {
+
+ return
+}
+
+func (msg *basicQosOk) read(r io.Reader) (err error) {
+
+ return
+}
+
+type basicConsume struct {
+ reserved1 uint16
+ Queue string
+ ConsumerTag string
+ NoLocal bool
+ NoAck bool
+ Exclusive bool
+ NoWait bool
+ Arguments Table
+}
+
+func (msg *basicConsume) id() (uint16, uint16) {
+ return 60, 20
+}
+
+func (msg *basicConsume) wait() bool {
+ return true && !msg.NoWait
+}
+
+func (msg *basicConsume) write(w io.Writer) (err error) {
+ var bits byte
+
+ if err = binary.Write(w, binary.BigEndian, msg.reserved1); err != nil {
+ return
+ }
+
+ if err = writeShortstr(w, msg.Queue); err != nil {
+ return
+ }
+ if err = writeShortstr(w, msg.ConsumerTag); err != nil {
+ return
+ }
+
+ if msg.NoLocal {
+ bits |= 1 << 0
+ }
+
+ if msg.NoAck {
+ bits |= 1 << 1
+ }
+
+ if msg.Exclusive {
+ bits |= 1 << 2
+ }
+
+ if msg.NoWait {
+ bits |= 1 << 3
+ }
+
+ if err = binary.Write(w, binary.BigEndian, bits); err != nil {
+ return
+ }
+
+ if err = writeTable(w, msg.Arguments); err != nil {
+ return
+ }
+
+ return
+}
+
+func (msg *basicConsume) read(r io.Reader) (err error) {
+ var bits byte
+
+ if err = binary.Read(r, binary.BigEndian, &msg.reserved1); err != nil {
+ return
+ }
+
+ if msg.Queue, err = readShortstr(r); err != nil {
+ return
+ }
+ if msg.ConsumerTag, err = readShortstr(r); err != nil {
+ return
+ }
+
+ if err = binary.Read(r, binary.BigEndian, &bits); err != nil {
+ return
+ }
+ msg.NoLocal = (bits&(1<<0) > 0)
+ msg.NoAck = (bits&(1<<1) > 0)
+ msg.Exclusive = (bits&(1<<2) > 0)
+ msg.NoWait = (bits&(1<<3) > 0)
+
+ if msg.Arguments, err = readTable(r); err != nil {
+ return
+ }
+
+ return
+}
+
+type basicConsumeOk struct {
+ ConsumerTag string
+}
+
+func (msg *basicConsumeOk) id() (uint16, uint16) {
+ return 60, 21
+}
+
+func (msg *basicConsumeOk) wait() bool {
+ return true
+}
+
+func (msg *basicConsumeOk) write(w io.Writer) (err error) {
+
+ if err = writeShortstr(w, msg.ConsumerTag); err != nil {
+ return
+ }
+
+ return
+}
+
+func (msg *basicConsumeOk) read(r io.Reader) (err error) {
+
+ if msg.ConsumerTag, err = readShortstr(r); err != nil {
+ return
+ }
+
+ return
+}
+
+type basicCancel struct {
+ ConsumerTag string
+ NoWait bool
+}
+
+func (msg *basicCancel) id() (uint16, uint16) {
+ return 60, 30
+}
+
+func (msg *basicCancel) wait() bool {
+ return true && !msg.NoWait
+}
+
+func (msg *basicCancel) write(w io.Writer) (err error) {
+ var bits byte
+
+ if err = writeShortstr(w, msg.ConsumerTag); err != nil {
+ return
+ }
+
+ if msg.NoWait {
+ bits |= 1 << 0
+ }
+
+ if err = binary.Write(w, binary.BigEndian, bits); err != nil {
+ return
+ }
+
+ return
+}
+
+func (msg *basicCancel) read(r io.Reader) (err error) {
+ var bits byte
+
+ if msg.ConsumerTag, err = readShortstr(r); err != nil {
+ return
+ }
+
+ if err = binary.Read(r, binary.BigEndian, &bits); err != nil {
+ return
+ }
+ msg.NoWait = (bits&(1<<0) > 0)
+
+ return
+}
+
+type basicCancelOk struct {
+ ConsumerTag string
+}
+
+func (msg *basicCancelOk) id() (uint16, uint16) {
+ return 60, 31
+}
+
+func (msg *basicCancelOk) wait() bool {
+ return true
+}
+
+func (msg *basicCancelOk) write(w io.Writer) (err error) {
+
+ if err = writeShortstr(w, msg.ConsumerTag); err != nil {
+ return
+ }
+
+ return
+}
+
+func (msg *basicCancelOk) read(r io.Reader) (err error) {
+
+ if msg.ConsumerTag, err = readShortstr(r); err != nil {
+ return
+ }
+
+ return
+}
+
+type basicPublish struct {
+ reserved1 uint16
+ Exchange string
+ RoutingKey string
+ Mandatory bool
+ Immediate bool
+ Properties properties
+ Body []byte
+}
+
+func (msg *basicPublish) id() (uint16, uint16) {
+ return 60, 40
+}
+
+func (msg *basicPublish) wait() bool {
+ return false
+}
+
+func (msg *basicPublish) getContent() (properties, []byte) {
+ return msg.Properties, msg.Body
+}
+
+func (msg *basicPublish) setContent(props properties, body []byte) {
+ msg.Properties, msg.Body = props, body
+}
+
+func (msg *basicPublish) write(w io.Writer) (err error) {
+ var bits byte
+
+ if err = binary.Write(w, binary.BigEndian, msg.reserved1); err != nil {
+ return
+ }
+
+ if err = writeShortstr(w, msg.Exchange); err != nil {
+ return
+ }
+ if err = writeShortstr(w, msg.RoutingKey); err != nil {
+ return
+ }
+
+ if msg.Mandatory {
+ bits |= 1 << 0
+ }
+
+ if msg.Immediate {
+ bits |= 1 << 1
+ }
+
+ if err = binary.Write(w, binary.BigEndian, bits); err != nil {
+ return
+ }
+
+ return
+}
+
+func (msg *basicPublish) read(r io.Reader) (err error) {
+ var bits byte
+
+ if err = binary.Read(r, binary.BigEndian, &msg.reserved1); err != nil {
+ return
+ }
+
+ if msg.Exchange, err = readShortstr(r); err != nil {
+ return
+ }
+ if msg.RoutingKey, err = readShortstr(r); err != nil {
+ return
+ }
+
+ if err = binary.Read(r, binary.BigEndian, &bits); err != nil {
+ return
+ }
+ msg.Mandatory = (bits&(1<<0) > 0)
+ msg.Immediate = (bits&(1<<1) > 0)
+
+ return
+}
+
+type basicReturn struct {
+ ReplyCode uint16
+ ReplyText string
+ Exchange string
+ RoutingKey string
+ Properties properties
+ Body []byte
+}
+
+func (msg *basicReturn) id() (uint16, uint16) {
+ return 60, 50
+}
+
+func (msg *basicReturn) wait() bool {
+ return false
+}
+
+func (msg *basicReturn) getContent() (properties, []byte) {
+ return msg.Properties, msg.Body
+}
+
+func (msg *basicReturn) setContent(props properties, body []byte) {
+ msg.Properties, msg.Body = props, body
+}
+
+func (msg *basicReturn) write(w io.Writer) (err error) {
+
+ if err = binary.Write(w, binary.BigEndian, msg.ReplyCode); err != nil {
+ return
+ }
+
+ if err = writeShortstr(w, msg.ReplyText); err != nil {
+ return
+ }
+ if err = writeShortstr(w, msg.Exchange); err != nil {
+ return
+ }
+ if err = writeShortstr(w, msg.RoutingKey); err != nil {
+ return
+ }
+
+ return
+}
+
+func (msg *basicReturn) read(r io.Reader) (err error) {
+
+ if err = binary.Read(r, binary.BigEndian, &msg.ReplyCode); err != nil {
+ return
+ }
+
+ if msg.ReplyText, err = readShortstr(r); err != nil {
+ return
+ }
+ if msg.Exchange, err = readShortstr(r); err != nil {
+ return
+ }
+ if msg.RoutingKey, err = readShortstr(r); err != nil {
+ return
+ }
+
+ return
+}
+
+type basicDeliver struct {
+ ConsumerTag string
+ DeliveryTag uint64
+ Redelivered bool
+ Exchange string
+ RoutingKey string
+ Properties properties
+ Body []byte
+}
+
+func (msg *basicDeliver) id() (uint16, uint16) {
+ return 60, 60
+}
+
+func (msg *basicDeliver) wait() bool {
+ return false
+}
+
+func (msg *basicDeliver) getContent() (properties, []byte) {
+ return msg.Properties, msg.Body
+}
+
+func (msg *basicDeliver) setContent(props properties, body []byte) {
+ msg.Properties, msg.Body = props, body
+}
+
+func (msg *basicDeliver) write(w io.Writer) (err error) {
+ var bits byte
+
+ if err = writeShortstr(w, msg.ConsumerTag); err != nil {
+ return
+ }
+
+ if err = binary.Write(w, binary.BigEndian, msg.DeliveryTag); err != nil {
+ return
+ }
+
+ if msg.Redelivered {
+ bits |= 1 << 0
+ }
+
+ if err = binary.Write(w, binary.BigEndian, bits); err != nil {
+ return
+ }
+
+ if err = writeShortstr(w, msg.Exchange); err != nil {
+ return
+ }
+ if err = writeShortstr(w, msg.RoutingKey); err != nil {
+ return
+ }
+
+ return
+}
+
+func (msg *basicDeliver) read(r io.Reader) (err error) {
+ var bits byte
+
+ if msg.ConsumerTag, err = readShortstr(r); err != nil {
+ return
+ }
+
+ if err = binary.Read(r, binary.BigEndian, &msg.DeliveryTag); err != nil {
+ return
+ }
+
+ if err = binary.Read(r, binary.BigEndian, &bits); err != nil {
+ return
+ }
+ msg.Redelivered = (bits&(1<<0) > 0)
+
+ if msg.Exchange, err = readShortstr(r); err != nil {
+ return
+ }
+ if msg.RoutingKey, err = readShortstr(r); err != nil {
+ return
+ }
+
+ return
+}
+
+type basicGet struct {
+ reserved1 uint16
+ Queue string
+ NoAck bool
+}
+
+func (msg *basicGet) id() (uint16, uint16) {
+ return 60, 70
+}
+
+func (msg *basicGet) wait() bool {
+ return true
+}
+
+func (msg *basicGet) write(w io.Writer) (err error) {
+ var bits byte
+
+ if err = binary.Write(w, binary.BigEndian, msg.reserved1); err != nil {
+ return
+ }
+
+ if err = writeShortstr(w, msg.Queue); err != nil {
+ return
+ }
+
+ if msg.NoAck {
+ bits |= 1 << 0
+ }
+
+ if err = binary.Write(w, binary.BigEndian, bits); err != nil {
+ return
+ }
+
+ return
+}
+
+func (msg *basicGet) read(r io.Reader) (err error) {
+ var bits byte
+
+ if err = binary.Read(r, binary.BigEndian, &msg.reserved1); err != nil {
+ return
+ }
+
+ if msg.Queue, err = readShortstr(r); err != nil {
+ return
+ }
+
+ if err = binary.Read(r, binary.BigEndian, &bits); err != nil {
+ return
+ }
+ msg.NoAck = (bits&(1<<0) > 0)
+
+ return
+}
+
+type basicGetOk struct {
+ DeliveryTag uint64
+ Redelivered bool
+ Exchange string
+ RoutingKey string
+ MessageCount uint32
+ Properties properties
+ Body []byte
+}
+
+func (msg *basicGetOk) id() (uint16, uint16) {
+ return 60, 71
+}
+
+func (msg *basicGetOk) wait() bool {
+ return true
+}
+
+func (msg *basicGetOk) getContent() (properties, []byte) {
+ return msg.Properties, msg.Body
+}
+
+func (msg *basicGetOk) setContent(props properties, body []byte) {
+ msg.Properties, msg.Body = props, body
+}
+
+func (msg *basicGetOk) write(w io.Writer) (err error) {
+ var bits byte
+
+ if err = binary.Write(w, binary.BigEndian, msg.DeliveryTag); err != nil {
+ return
+ }
+
+ if msg.Redelivered {
+ bits |= 1 << 0
+ }
+
+ if err = binary.Write(w, binary.BigEndian, bits); err != nil {
+ return
+ }
+
+ if err = writeShortstr(w, msg.Exchange); err != nil {
+ return
+ }
+ if err = writeShortstr(w, msg.RoutingKey); err != nil {
+ return
+ }
+
+ if err = binary.Write(w, binary.BigEndian, msg.MessageCount); err != nil {
+ return
+ }
+
+ return
+}
+
+func (msg *basicGetOk) read(r io.Reader) (err error) {
+ var bits byte
+
+ if err = binary.Read(r, binary.BigEndian, &msg.DeliveryTag); err != nil {
+ return
+ }
+
+ if err = binary.Read(r, binary.BigEndian, &bits); err != nil {
+ return
+ }
+ msg.Redelivered = (bits&(1<<0) > 0)
+
+ if msg.Exchange, err = readShortstr(r); err != nil {
+ return
+ }
+ if msg.RoutingKey, err = readShortstr(r); err != nil {
+ return
+ }
+
+ if err = binary.Read(r, binary.BigEndian, &msg.MessageCount); err != nil {
+ return
+ }
+
+ return
+}
+
+type basicGetEmpty struct {
+ reserved1 string
+}
+
+func (msg *basicGetEmpty) id() (uint16, uint16) {
+ return 60, 72
+}
+
+func (msg *basicGetEmpty) wait() bool {
+ return true
+}
+
+func (msg *basicGetEmpty) write(w io.Writer) (err error) {
+
+ if err = writeShortstr(w, msg.reserved1); err != nil {
+ return
+ }
+
+ return
+}
+
+func (msg *basicGetEmpty) read(r io.Reader) (err error) {
+
+ if msg.reserved1, err = readShortstr(r); err != nil {
+ return
+ }
+
+ return
+}
+
+type basicAck struct {
+ DeliveryTag uint64
+ Multiple bool
+}
+
+func (msg *basicAck) id() (uint16, uint16) {
+ return 60, 80
+}
+
+func (msg *basicAck) wait() bool {
+ return false
+}
+
+func (msg *basicAck) write(w io.Writer) (err error) {
+ var bits byte
+
+ if err = binary.Write(w, binary.BigEndian, msg.DeliveryTag); err != nil {
+ return
+ }
+
+ if msg.Multiple {
+ bits |= 1 << 0
+ }
+
+ if err = binary.Write(w, binary.BigEndian, bits); err != nil {
+ return
+ }
+
+ return
+}
+
+func (msg *basicAck) read(r io.Reader) (err error) {
+ var bits byte
+
+ if err = binary.Read(r, binary.BigEndian, &msg.DeliveryTag); err != nil {
+ return
+ }
+
+ if err = binary.Read(r, binary.BigEndian, &bits); err != nil {
+ return
+ }
+ msg.Multiple = (bits&(1<<0) > 0)
+
+ return
+}
+
+type basicReject struct {
+ DeliveryTag uint64
+ Requeue bool
+}
+
+func (msg *basicReject) id() (uint16, uint16) {
+ return 60, 90
+}
+
+func (msg *basicReject) wait() bool {
+ return false
+}
+
+func (msg *basicReject) write(w io.Writer) (err error) {
+ var bits byte
+
+ if err = binary.Write(w, binary.BigEndian, msg.DeliveryTag); err != nil {
+ return
+ }
+
+ if msg.Requeue {
+ bits |= 1 << 0
+ }
+
+ if err = binary.Write(w, binary.BigEndian, bits); err != nil {
+ return
+ }
+
+ return
+}
+
+func (msg *basicReject) read(r io.Reader) (err error) {
+ var bits byte
+
+ if err = binary.Read(r, binary.BigEndian, &msg.DeliveryTag); err != nil {
+ return
+ }
+
+ if err = binary.Read(r, binary.BigEndian, &bits); err != nil {
+ return
+ }
+ msg.Requeue = (bits&(1<<0) > 0)
+
+ return
+}
+
+type basicRecoverAsync struct {
+ Requeue bool
+}
+
+func (msg *basicRecoverAsync) id() (uint16, uint16) {
+ return 60, 100
+}
+
+func (msg *basicRecoverAsync) wait() bool {
+ return false
+}
+
+func (msg *basicRecoverAsync) write(w io.Writer) (err error) {
+ var bits byte
+
+ if msg.Requeue {
+ bits |= 1 << 0
+ }
+
+ if err = binary.Write(w, binary.BigEndian, bits); err != nil {
+ return
+ }
+
+ return
+}
+
+func (msg *basicRecoverAsync) read(r io.Reader) (err error) {
+ var bits byte
+
+ if err = binary.Read(r, binary.BigEndian, &bits); err != nil {
+ return
+ }
+ msg.Requeue = (bits&(1<<0) > 0)
+
+ return
+}
+
+type basicRecover struct {
+ Requeue bool
+}
+
+func (msg *basicRecover) id() (uint16, uint16) {
+ return 60, 110
+}
+
+func (msg *basicRecover) wait() bool {
+ return true
+}
+
+func (msg *basicRecover) write(w io.Writer) (err error) {
+ var bits byte
+
+ if msg.Requeue {
+ bits |= 1 << 0
+ }
+
+ if err = binary.Write(w, binary.BigEndian, bits); err != nil {
+ return
+ }
+
+ return
+}
+
+func (msg *basicRecover) read(r io.Reader) (err error) {
+ var bits byte
+
+ if err = binary.Read(r, binary.BigEndian, &bits); err != nil {
+ return
+ }
+ msg.Requeue = (bits&(1<<0) > 0)
+
+ return
+}
+
+type basicRecoverOk struct {
+}
+
+func (msg *basicRecoverOk) id() (uint16, uint16) {
+ return 60, 111
+}
+
+func (msg *basicRecoverOk) wait() bool {
+ return true
+}
+
+func (msg *basicRecoverOk) write(w io.Writer) (err error) {
+
+ return
+}
+
+func (msg *basicRecoverOk) read(r io.Reader) (err error) {
+
+ return
+}
+
+type basicNack struct {
+ DeliveryTag uint64
+ Multiple bool
+ Requeue bool
+}
+
+func (msg *basicNack) id() (uint16, uint16) {
+ return 60, 120
+}
+
+func (msg *basicNack) wait() bool {
+ return false
+}
+
+func (msg *basicNack) write(w io.Writer) (err error) {
+ var bits byte
+
+ if err = binary.Write(w, binary.BigEndian, msg.DeliveryTag); err != nil {
+ return
+ }
+
+ if msg.Multiple {
+ bits |= 1 << 0
+ }
+
+ if msg.Requeue {
+ bits |= 1 << 1
+ }
+
+ if err = binary.Write(w, binary.BigEndian, bits); err != nil {
+ return
+ }
+
+ return
+}
+
+func (msg *basicNack) read(r io.Reader) (err error) {
+ var bits byte
+
+ if err = binary.Read(r, binary.BigEndian, &msg.DeliveryTag); err != nil {
+ return
+ }
+
+ if err = binary.Read(r, binary.BigEndian, &bits); err != nil {
+ return
+ }
+ msg.Multiple = (bits&(1<<0) > 0)
+ msg.Requeue = (bits&(1<<1) > 0)
+
+ return
+}
+
+type txSelect struct {
+}
+
+func (msg *txSelect) id() (uint16, uint16) {
+ return 90, 10
+}
+
+func (msg *txSelect) wait() bool {
+ return true
+}
+
+func (msg *txSelect) write(w io.Writer) (err error) {
+
+ return
+}
+
+func (msg *txSelect) read(r io.Reader) (err error) {
+
+ return
+}
+
+type txSelectOk struct {
+}
+
+func (msg *txSelectOk) id() (uint16, uint16) {
+ return 90, 11
+}
+
+func (msg *txSelectOk) wait() bool {
+ return true
+}
+
+func (msg *txSelectOk) write(w io.Writer) (err error) {
+
+ return
+}
+
+func (msg *txSelectOk) read(r io.Reader) (err error) {
+
+ return
+}
+
+type txCommit struct {
+}
+
+func (msg *txCommit) id() (uint16, uint16) {
+ return 90, 20
+}
+
+func (msg *txCommit) wait() bool {
+ return true
+}
+
+func (msg *txCommit) write(w io.Writer) (err error) {
+
+ return
+}
+
+func (msg *txCommit) read(r io.Reader) (err error) {
+
+ return
+}
+
+type txCommitOk struct {
+}
+
+func (msg *txCommitOk) id() (uint16, uint16) {
+ return 90, 21
+}
+
+func (msg *txCommitOk) wait() bool {
+ return true
+}
+
+func (msg *txCommitOk) write(w io.Writer) (err error) {
+
+ return
+}
+
+func (msg *txCommitOk) read(r io.Reader) (err error) {
+
+ return
+}
+
+type txRollback struct {
+}
+
+func (msg *txRollback) id() (uint16, uint16) {
+ return 90, 30
+}
+
+func (msg *txRollback) wait() bool {
+ return true
+}
+
+func (msg *txRollback) write(w io.Writer) (err error) {
+
+ return
+}
+
+func (msg *txRollback) read(r io.Reader) (err error) {
+
+ return
+}
+
+type txRollbackOk struct {
+}
+
+func (msg *txRollbackOk) id() (uint16, uint16) {
+ return 90, 31
+}
+
+func (msg *txRollbackOk) wait() bool {
+ return true
+}
+
+func (msg *txRollbackOk) write(w io.Writer) (err error) {
+
+ return
+}
+
+func (msg *txRollbackOk) read(r io.Reader) (err error) {
+
+ return
+}
+
+type confirmSelect struct {
+ Nowait bool
+}
+
+func (msg *confirmSelect) id() (uint16, uint16) {
+ return 85, 10
+}
+
+func (msg *confirmSelect) wait() bool {
+ return true
+}
+
+func (msg *confirmSelect) write(w io.Writer) (err error) {
+ var bits byte
+
+ if msg.Nowait {
+ bits |= 1 << 0
+ }
+
+ if err = binary.Write(w, binary.BigEndian, bits); err != nil {
+ return
+ }
+
+ return
+}
+
+func (msg *confirmSelect) read(r io.Reader) (err error) {
+ var bits byte
+
+ if err = binary.Read(r, binary.BigEndian, &bits); err != nil {
+ return
+ }
+ msg.Nowait = (bits&(1<<0) > 0)
+
+ return
+}
+
+type confirmSelectOk struct {
+}
+
+func (msg *confirmSelectOk) id() (uint16, uint16) {
+ return 85, 11
+}
+
+func (msg *confirmSelectOk) wait() bool {
+ return true
+}
+
+func (msg *confirmSelectOk) write(w io.Writer) (err error) {
+
+ return
+}
+
+func (msg *confirmSelectOk) read(r io.Reader) (err error) {
+
+ return
+}
+
+func (r *reader) parseMethodFrame(channel uint16, size uint32) (f frame, err error) {
+ mf := &methodFrame{
+ ChannelId: channel,
+ }
+
+ if err = binary.Read(r.r, binary.BigEndian, &mf.ClassId); err != nil {
+ return
+ }
+
+ if err = binary.Read(r.r, binary.BigEndian, &mf.MethodId); err != nil {
+ return
+ }
+
+ switch mf.ClassId {
+
+ case 10: // connection
+ switch mf.MethodId {
+
+ case 10: // connection start
+ //fmt.Println("NextMethod: class:10 method:10")
+ method := &connectionStart{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ case 11: // connection start-ok
+ //fmt.Println("NextMethod: class:10 method:11")
+ method := &connectionStartOk{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ case 20: // connection secure
+ //fmt.Println("NextMethod: class:10 method:20")
+ method := &connectionSecure{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ case 21: // connection secure-ok
+ //fmt.Println("NextMethod: class:10 method:21")
+ method := &connectionSecureOk{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ case 30: // connection tune
+ //fmt.Println("NextMethod: class:10 method:30")
+ method := &connectionTune{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ case 31: // connection tune-ok
+ //fmt.Println("NextMethod: class:10 method:31")
+ method := &connectionTuneOk{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ case 40: // connection open
+ //fmt.Println("NextMethod: class:10 method:40")
+ method := &connectionOpen{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ case 41: // connection open-ok
+ //fmt.Println("NextMethod: class:10 method:41")
+ method := &connectionOpenOk{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ case 50: // connection close
+ //fmt.Println("NextMethod: class:10 method:50")
+ method := &connectionClose{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ case 51: // connection close-ok
+ //fmt.Println("NextMethod: class:10 method:51")
+ method := &connectionCloseOk{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ case 60: // connection blocked
+ //fmt.Println("NextMethod: class:10 method:60")
+ method := &connectionBlocked{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ case 61: // connection unblocked
+ //fmt.Println("NextMethod: class:10 method:61")
+ method := &connectionUnblocked{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ default:
+ return nil, fmt.Errorf("Bad method frame, unknown method %d for class %d", mf.MethodId, mf.ClassId)
+ }
+
+ case 20: // channel
+ switch mf.MethodId {
+
+ case 10: // channel open
+ //fmt.Println("NextMethod: class:20 method:10")
+ method := &channelOpen{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ case 11: // channel open-ok
+ //fmt.Println("NextMethod: class:20 method:11")
+ method := &channelOpenOk{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ case 20: // channel flow
+ //fmt.Println("NextMethod: class:20 method:20")
+ method := &channelFlow{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ case 21: // channel flow-ok
+ //fmt.Println("NextMethod: class:20 method:21")
+ method := &channelFlowOk{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ case 40: // channel close
+ //fmt.Println("NextMethod: class:20 method:40")
+ method := &channelClose{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ case 41: // channel close-ok
+ //fmt.Println("NextMethod: class:20 method:41")
+ method := &channelCloseOk{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ default:
+ return nil, fmt.Errorf("Bad method frame, unknown method %d for class %d", mf.MethodId, mf.ClassId)
+ }
+
+ case 40: // exchange
+ switch mf.MethodId {
+
+ case 10: // exchange declare
+ //fmt.Println("NextMethod: class:40 method:10")
+ method := &exchangeDeclare{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ case 11: // exchange declare-ok
+ //fmt.Println("NextMethod: class:40 method:11")
+ method := &exchangeDeclareOk{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ case 20: // exchange delete
+ //fmt.Println("NextMethod: class:40 method:20")
+ method := &exchangeDelete{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ case 21: // exchange delete-ok
+ //fmt.Println("NextMethod: class:40 method:21")
+ method := &exchangeDeleteOk{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ case 30: // exchange bind
+ //fmt.Println("NextMethod: class:40 method:30")
+ method := &exchangeBind{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ case 31: // exchange bind-ok
+ //fmt.Println("NextMethod: class:40 method:31")
+ method := &exchangeBindOk{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ case 40: // exchange unbind
+ //fmt.Println("NextMethod: class:40 method:40")
+ method := &exchangeUnbind{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ case 51: // exchange unbind-ok
+ //fmt.Println("NextMethod: class:40 method:51")
+ method := &exchangeUnbindOk{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ default:
+ return nil, fmt.Errorf("Bad method frame, unknown method %d for class %d", mf.MethodId, mf.ClassId)
+ }
+
+ case 50: // queue
+ switch mf.MethodId {
+
+ case 10: // queue declare
+ //fmt.Println("NextMethod: class:50 method:10")
+ method := &queueDeclare{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ case 11: // queue declare-ok
+ //fmt.Println("NextMethod: class:50 method:11")
+ method := &queueDeclareOk{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ case 20: // queue bind
+ //fmt.Println("NextMethod: class:50 method:20")
+ method := &queueBind{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ case 21: // queue bind-ok
+ //fmt.Println("NextMethod: class:50 method:21")
+ method := &queueBindOk{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ case 50: // queue unbind
+ //fmt.Println("NextMethod: class:50 method:50")
+ method := &queueUnbind{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ case 51: // queue unbind-ok
+ //fmt.Println("NextMethod: class:50 method:51")
+ method := &queueUnbindOk{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ case 30: // queue purge
+ //fmt.Println("NextMethod: class:50 method:30")
+ method := &queuePurge{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ case 31: // queue purge-ok
+ //fmt.Println("NextMethod: class:50 method:31")
+ method := &queuePurgeOk{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ case 40: // queue delete
+ //fmt.Println("NextMethod: class:50 method:40")
+ method := &queueDelete{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ case 41: // queue delete-ok
+ //fmt.Println("NextMethod: class:50 method:41")
+ method := &queueDeleteOk{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ default:
+ return nil, fmt.Errorf("Bad method frame, unknown method %d for class %d", mf.MethodId, mf.ClassId)
+ }
+
+ case 60: // basic
+ switch mf.MethodId {
+
+ case 10: // basic qos
+ //fmt.Println("NextMethod: class:60 method:10")
+ method := &basicQos{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ case 11: // basic qos-ok
+ //fmt.Println("NextMethod: class:60 method:11")
+ method := &basicQosOk{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ case 20: // basic consume
+ //fmt.Println("NextMethod: class:60 method:20")
+ method := &basicConsume{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ case 21: // basic consume-ok
+ //fmt.Println("NextMethod: class:60 method:21")
+ method := &basicConsumeOk{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ case 30: // basic cancel
+ //fmt.Println("NextMethod: class:60 method:30")
+ method := &basicCancel{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ case 31: // basic cancel-ok
+ //fmt.Println("NextMethod: class:60 method:31")
+ method := &basicCancelOk{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ case 40: // basic publish
+ //fmt.Println("NextMethod: class:60 method:40")
+ method := &basicPublish{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ case 50: // basic return
+ //fmt.Println("NextMethod: class:60 method:50")
+ method := &basicReturn{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ case 60: // basic deliver
+ //fmt.Println("NextMethod: class:60 method:60")
+ method := &basicDeliver{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ case 70: // basic get
+ //fmt.Println("NextMethod: class:60 method:70")
+ method := &basicGet{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ case 71: // basic get-ok
+ //fmt.Println("NextMethod: class:60 method:71")
+ method := &basicGetOk{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ case 72: // basic get-empty
+ //fmt.Println("NextMethod: class:60 method:72")
+ method := &basicGetEmpty{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ case 80: // basic ack
+ //fmt.Println("NextMethod: class:60 method:80")
+ method := &basicAck{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ case 90: // basic reject
+ //fmt.Println("NextMethod: class:60 method:90")
+ method := &basicReject{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ case 100: // basic recover-async
+ //fmt.Println("NextMethod: class:60 method:100")
+ method := &basicRecoverAsync{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ case 110: // basic recover
+ //fmt.Println("NextMethod: class:60 method:110")
+ method := &basicRecover{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ case 111: // basic recover-ok
+ //fmt.Println("NextMethod: class:60 method:111")
+ method := &basicRecoverOk{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ case 120: // basic nack
+ //fmt.Println("NextMethod: class:60 method:120")
+ method := &basicNack{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ default:
+ return nil, fmt.Errorf("Bad method frame, unknown method %d for class %d", mf.MethodId, mf.ClassId)
+ }
+
+ case 90: // tx
+ switch mf.MethodId {
+
+ case 10: // tx select
+ //fmt.Println("NextMethod: class:90 method:10")
+ method := &txSelect{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ case 11: // tx select-ok
+ //fmt.Println("NextMethod: class:90 method:11")
+ method := &txSelectOk{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ case 20: // tx commit
+ //fmt.Println("NextMethod: class:90 method:20")
+ method := &txCommit{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ case 21: // tx commit-ok
+ //fmt.Println("NextMethod: class:90 method:21")
+ method := &txCommitOk{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ case 30: // tx rollback
+ //fmt.Println("NextMethod: class:90 method:30")
+ method := &txRollback{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ case 31: // tx rollback-ok
+ //fmt.Println("NextMethod: class:90 method:31")
+ method := &txRollbackOk{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ default:
+ return nil, fmt.Errorf("Bad method frame, unknown method %d for class %d", mf.MethodId, mf.ClassId)
+ }
+
+ case 85: // confirm
+ switch mf.MethodId {
+
+ case 10: // confirm select
+ //fmt.Println("NextMethod: class:85 method:10")
+ method := &confirmSelect{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ case 11: // confirm select-ok
+ //fmt.Println("NextMethod: class:85 method:11")
+ method := &confirmSelectOk{}
+ if err = method.read(r.r); err != nil {
+ return
+ }
+ mf.Method = method
+
+ default:
+ return nil, fmt.Errorf("Bad method frame, unknown method %d for class %d", mf.MethodId, mf.ClassId)
+ }
+
+ default:
+ return nil, fmt.Errorf("Bad method frame, unknown class %d", mf.ClassId)
+ }
+
+ return mf, nil
+}
diff --git a/src/dma/vendor/github.com/streadway/amqp/types.go b/src/dma/vendor/github.com/streadway/amqp/types.go
new file mode 100644
index 00000000..ff5ea3cb
--- /dev/null
+++ b/src/dma/vendor/github.com/streadway/amqp/types.go
@@ -0,0 +1,427 @@
+// Copyright (c) 2012, Sean Treadway, SoundCloud Ltd.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+// Source code and contact info at http://github.com/streadway/amqp
+
+package amqp
+
+import (
+ "fmt"
+ "io"
+ "time"
+)
+
+// Constants for standard AMQP 0-9-1 exchange types.
+const (
+ ExchangeDirect = "direct"
+ ExchangeFanout = "fanout"
+ ExchangeTopic = "topic"
+ ExchangeHeaders = "headers"
+)
+
+var (
+ // ErrClosed is returned when the channel or connection is not open
+ ErrClosed = &Error{Code: ChannelError, Reason: "channel/connection is not open"}
+
+ // ErrChannelMax is returned when Connection.Channel has been called enough
+ // times that all channel IDs have been exhausted in the client or the
+ // server.
+ ErrChannelMax = &Error{Code: ChannelError, Reason: "channel id space exhausted"}
+
+ // ErrSASL is returned from Dial when the authentication mechanism could not
+ // be negoated.
+ ErrSASL = &Error{Code: AccessRefused, Reason: "SASL could not negotiate a shared mechanism"}
+
+ // ErrCredentials is returned when the authenticated client is not authorized
+ // to any vhost.
+ ErrCredentials = &Error{Code: AccessRefused, Reason: "username or password not allowed"}
+
+ // ErrVhost is returned when the authenticated user is not permitted to
+ // access the requested Vhost.
+ ErrVhost = &Error{Code: AccessRefused, Reason: "no access to this vhost"}
+
+ // ErrSyntax is hard protocol error, indicating an unsupported protocol,
+ // implementation or encoding.
+ ErrSyntax = &Error{Code: SyntaxError, Reason: "invalid field or value inside of a frame"}
+
+ // ErrFrame is returned when the protocol frame cannot be read from the
+ // server, indicating an unsupported protocol or unsupported frame type.
+ ErrFrame = &Error{Code: FrameError, Reason: "frame could not be parsed"}
+
+ // ErrCommandInvalid is returned when the server sends an unexpected response
+ // to this requested message type. This indicates a bug in this client.
+ ErrCommandInvalid = &Error{Code: CommandInvalid, Reason: "unexpected command received"}
+
+ // ErrUnexpectedFrame is returned when something other than a method or
+ // heartbeat frame is delivered to the Connection, indicating a bug in the
+ // client.
+ ErrUnexpectedFrame = &Error{Code: UnexpectedFrame, Reason: "unexpected frame received"}
+
+ // ErrFieldType is returned when writing a message containing a Go type unsupported by AMQP.
+ ErrFieldType = &Error{Code: SyntaxError, Reason: "unsupported table field type"}
+)
+
+// Error captures the code and reason a channel or connection has been closed
+// by the server.
+type Error struct {
+ Code int // constant code from the specification
+ Reason string // description of the error
+ Server bool // true when initiated from the server, false when from this library
+ Recover bool // true when this error can be recovered by retrying later or with different parameters
+}
+
+func newError(code uint16, text string) *Error {
+ return &Error{
+ Code: int(code),
+ Reason: text,
+ Recover: isSoftExceptionCode(int(code)),
+ Server: true,
+ }
+}
+
+func (e Error) Error() string {
+ return fmt.Sprintf("Exception (%d) Reason: %q", e.Code, e.Reason)
+}
+
+// Used by header frames to capture routing and header information
+type properties struct {
+ ContentType string // MIME content type
+ ContentEncoding string // MIME content encoding
+ Headers Table // Application or header exchange table
+ DeliveryMode uint8 // queue implementation use - Transient (1) or Persistent (2)
+ Priority uint8 // queue implementation use - 0 to 9
+ CorrelationId string // application use - correlation identifier
+ ReplyTo string // application use - address to to reply to (ex: RPC)
+ Expiration string // implementation use - message expiration spec
+ MessageId string // application use - message identifier
+ Timestamp time.Time // application use - message timestamp
+ Type string // application use - message type name
+ UserId string // application use - creating user id
+ AppId string // application use - creating application
+ reserved1 string // was cluster-id - process for buffer consumption
+}
+
+// DeliveryMode. Transient means higher throughput but messages will not be
+// restored on broker restart. The delivery mode of publishings is unrelated
+// to the durability of the queues they reside on. Transient messages will
+// not be restored to durable queues, persistent messages will be restored to
+// durable queues and lost on non-durable queues during server restart.
+//
+// This remains typed as uint8 to match Publishing.DeliveryMode. Other
+// delivery modes specific to custom queue implementations are not enumerated
+// here.
+const (
+ Transient uint8 = 1
+ Persistent uint8 = 2
+)
+
+// The property flags are an array of bits that indicate the presence or
+// absence of each property value in sequence. The bits are ordered from most
+// high to low - bit 15 indicates the first property.
+const (
+ flagContentType = 0x8000
+ flagContentEncoding = 0x4000
+ flagHeaders = 0x2000
+ flagDeliveryMode = 0x1000
+ flagPriority = 0x0800
+ flagCorrelationId = 0x0400
+ flagReplyTo = 0x0200
+ flagExpiration = 0x0100
+ flagMessageId = 0x0080
+ flagTimestamp = 0x0040
+ flagType = 0x0020
+ flagUserId = 0x0010
+ flagAppId = 0x0008
+ flagReserved1 = 0x0004
+)
+
+// Queue captures the current server state of the queue on the server returned
+// from Channel.QueueDeclare or Channel.QueueInspect.
+type Queue struct {
+ Name string // server confirmed or generated name
+ Messages int // count of messages not awaiting acknowledgment
+ Consumers int // number of consumers receiving deliveries
+}
+
+// Publishing captures the client message sent to the server. The fields
+// outside of the Headers table included in this struct mirror the underlying
+// fields in the content frame. They use native types for convenience and
+// efficiency.
+type Publishing struct {
+ // Application or exchange specific fields,
+ // the headers exchange will inspect this field.
+ Headers Table
+
+ // Properties
+ ContentType string // MIME content type
+ ContentEncoding string // MIME content encoding
+ DeliveryMode uint8 // Transient (0 or 1) or Persistent (2)
+ Priority uint8 // 0 to 9
+ CorrelationId string // correlation identifier
+ ReplyTo string // address to to reply to (ex: RPC)
+ Expiration string // message expiration spec
+ MessageId string // message identifier
+ Timestamp time.Time // message timestamp
+ Type string // message type name
+ UserId string // creating user id - ex: "guest"
+ AppId string // creating application id
+
+ // The application specific payload of the message
+ Body []byte
+}
+
+// Blocking notifies the server's TCP flow control of the Connection. When a
+// server hits a memory or disk alarm it will block all connections until the
+// resources are reclaimed. Use NotifyBlock on the Connection to receive these
+// events.
+type Blocking struct {
+ Active bool // TCP pushback active/inactive on server
+ Reason string // Server reason for activation
+}
+
+// Confirmation notifies the acknowledgment or negative acknowledgement of a
+// publishing identified by its delivery tag. Use NotifyPublish on the Channel
+// to consume these events.
+type Confirmation struct {
+ DeliveryTag uint64 // A 1 based counter of publishings from when the channel was put in Confirm mode
+ Ack bool // True when the server successfully received the publishing
+}
+
+// Decimal matches the AMQP decimal type. Scale is the number of decimal
+// digits Scale == 2, Value == 12345, Decimal == 123.45
+type Decimal struct {
+ Scale uint8
+ Value int32
+}
+
+// Table stores user supplied fields of the following types:
+//
+// bool
+// byte
+// float32
+// float64
+// int16
+// int32
+// int64
+// nil
+// string
+// time.Time
+// amqp.Decimal
+// amqp.Table
+// []byte
+// []interface{} - containing above types
+//
+// Functions taking a table will immediately fail when the table contains a
+// value of an unsupported type.
+//
+// The caller must be specific in which precision of integer it wishes to
+// encode.
+//
+// Use a type assertion when reading values from a table for type conversion.
+//
+// RabbitMQ expects int32 for integer values.
+//
+type Table map[string]interface{}
+
+func validateField(f interface{}) error {
+ switch fv := f.(type) {
+ case nil, bool, byte, int16, int32, int64, float32, float64, string, []byte, Decimal, time.Time:
+ return nil
+
+ case []interface{}:
+ for _, v := range fv {
+ if err := validateField(v); err != nil {
+ return fmt.Errorf("in array %s", err)
+ }
+ }
+ return nil
+
+ case Table:
+ for k, v := range fv {
+ if err := validateField(v); err != nil {
+ return fmt.Errorf("table field %q %s", k, err)
+ }
+ }
+ return nil
+ }
+
+ return fmt.Errorf("value %t not supported", f)
+}
+
+// Validate returns and error if any Go types in the table are incompatible with AMQP types.
+func (t Table) Validate() error {
+ return validateField(t)
+}
+
+// Heap interface for maintaining delivery tags
+type tagSet []uint64
+
+func (set tagSet) Len() int { return len(set) }
+func (set tagSet) Less(i, j int) bool { return (set)[i] < (set)[j] }
+func (set tagSet) Swap(i, j int) { (set)[i], (set)[j] = (set)[j], (set)[i] }
+func (set *tagSet) Push(tag interface{}) { *set = append(*set, tag.(uint64)) }
+func (set *tagSet) Pop() interface{} {
+ val := (*set)[len(*set)-1]
+ *set = (*set)[:len(*set)-1]
+ return val
+}
+
+type message interface {
+ id() (uint16, uint16)
+ wait() bool
+ read(io.Reader) error
+ write(io.Writer) error
+}
+
+type messageWithContent interface {
+ message
+ getContent() (properties, []byte)
+ setContent(properties, []byte)
+}
+
+/*
+The base interface implemented as:
+
+2.3.5 frame Details
+
+All frames consist of a header (7 octets), a payload of arbitrary size, and a 'frame-end' octet that detects
+malformed frames:
+
+ 0 1 3 7 size+7 size+8
+ +------+---------+-------------+ +------------+ +-----------+
+ | type | channel | size | | payload | | frame-end |
+ +------+---------+-------------+ +------------+ +-----------+
+ octet short long size octets octet
+
+To read a frame, we:
+
+ 1. Read the header and check the frame type and channel.
+ 2. Depending on the frame type, we read the payload and process it.
+ 3. Read the frame end octet.
+
+In realistic implementations where performance is a concern, we would use
+“read-ahead buffering” or “gathering reads” to avoid doing three separate
+system calls to read a frame.
+
+*/
+type frame interface {
+ write(io.Writer) error
+ channel() uint16
+}
+
+type reader struct {
+ r io.Reader
+}
+
+type writer struct {
+ w io.Writer
+}
+
+// Implements the frame interface for Connection RPC
+type protocolHeader struct{}
+
+func (protocolHeader) write(w io.Writer) error {
+ _, err := w.Write([]byte{'A', 'M', 'Q', 'P', 0, 0, 9, 1})
+ return err
+}
+
+func (protocolHeader) channel() uint16 {
+ panic("only valid as initial handshake")
+}
+
+/*
+Method frames carry the high-level protocol commands (which we call "methods").
+One method frame carries one command. The method frame payload has this format:
+
+ 0 2 4
+ +----------+-----------+-------------- - -
+ | class-id | method-id | arguments...
+ +----------+-----------+-------------- - -
+ short short ...
+
+To process a method frame, we:
+ 1. Read the method frame payload.
+ 2. Unpack it into a structure. A given method always has the same structure,
+ so we can unpack the method rapidly. 3. Check that the method is allowed in
+ the current context.
+ 4. Check that the method arguments are valid.
+ 5. Execute the method.
+
+Method frame bodies are constructed as a list of AMQP data fields (bits,
+integers, strings and string tables). The marshalling code is trivially
+generated directly from the protocol specifications, and can be very rapid.
+*/
+type methodFrame struct {
+ ChannelId uint16
+ ClassId uint16
+ MethodId uint16
+ Method message
+}
+
+func (f *methodFrame) channel() uint16 { return f.ChannelId }
+
+/*
+Heartbeating is a technique designed to undo one of TCP/IP's features, namely
+its ability to recover from a broken physical connection by closing only after
+a quite long time-out. In some scenarios we need to know very rapidly if a
+peer is disconnected or not responding for other reasons (e.g. it is looping).
+Since heartbeating can be done at a low level, we implement this as a special
+type of frame that peers exchange at the transport level, rather than as a
+class method.
+*/
+type heartbeatFrame struct {
+ ChannelId uint16
+}
+
+func (f *heartbeatFrame) channel() uint16 { return f.ChannelId }
+
+/*
+Certain methods (such as Basic.Publish, Basic.Deliver, etc.) are formally
+defined as carrying content. When a peer sends such a method frame, it always
+follows it with a content header and zero or more content body frames.
+
+A content header frame has this format:
+
+ 0 2 4 12 14
+ +----------+--------+-----------+----------------+------------- - -
+ | class-id | weight | body size | property flags | property list...
+ +----------+--------+-----------+----------------+------------- - -
+ short short long long short remainder...
+
+We place content body in distinct frames (rather than including it in the
+method) so that AMQP may support "zero copy" techniques in which content is
+never marshalled or encoded. We place the content properties in their own
+frame so that recipients can selectively discard contents they do not want to
+process
+*/
+type headerFrame struct {
+ ChannelId uint16
+ ClassId uint16
+ weight uint16
+ Size uint64
+ Properties properties
+}
+
+func (f *headerFrame) channel() uint16 { return f.ChannelId }
+
+/*
+Content is the application data we carry from client-to-client via the AMQP
+server. Content is, roughly speaking, a set of properties plus a binary data
+part. The set of allowed properties are defined by the Basic class, and these
+form the "content header frame". The data can be any size, and MAY be broken
+into several (or many) chunks, each forming a "content body frame".
+
+Looking at the frames for a specific channel, as they pass on the wire, we
+might see something like this:
+
+ [method]
+ [method] [header] [body] [body]
+ [method]
+ ...
+*/
+type bodyFrame struct {
+ ChannelId uint16
+ Body []byte
+}
+
+func (f *bodyFrame) channel() uint16 { return f.ChannelId }
diff --git a/src/dma/vendor/github.com/streadway/amqp/uri.go b/src/dma/vendor/github.com/streadway/amqp/uri.go
new file mode 100644
index 00000000..35fefdc2
--- /dev/null
+++ b/src/dma/vendor/github.com/streadway/amqp/uri.go
@@ -0,0 +1,167 @@
+// Copyright (c) 2012, Sean Treadway, SoundCloud Ltd.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+// Source code and contact info at http://github.com/streadway/amqp
+
+package amqp
+
+import (
+ "errors"
+ "net"
+ "net/url"
+ "strconv"
+ "strings"
+)
+
+var errURIScheme = errors.New("AMQP scheme must be either 'amqp://' or 'amqps://'")
+var errURIWhitespace = errors.New("URI must not contain whitespace")
+
+var schemePorts = map[string]int{
+ "amqp": 5672,
+ "amqps": 5671,
+}
+
+var defaultURI = URI{
+ Scheme: "amqp",
+ Host: "localhost",
+ Port: 5672,
+ Username: "guest",
+ Password: "guest",
+ Vhost: "/",
+}
+
+// URI represents a parsed AMQP URI string.
+type URI struct {
+ Scheme string
+ Host string
+ Port int
+ Username string
+ Password string
+ Vhost string
+}
+
+// ParseURI attempts to parse the given AMQP URI according to the spec.
+// See http://www.rabbitmq.com/uri-spec.html.
+//
+// Default values for the fields are:
+//
+// Scheme: amqp
+// Host: localhost
+// Port: 5672
+// Username: guest
+// Password: guest
+// Vhost: /
+//
+func ParseURI(uri string) (URI, error) {
+ builder := defaultURI
+
+ if strings.Contains(uri, " ") == true {
+ return builder, errURIWhitespace
+ }
+
+ u, err := url.Parse(uri)
+ if err != nil {
+ return builder, err
+ }
+
+ defaultPort, okScheme := schemePorts[u.Scheme]
+
+ if okScheme {
+ builder.Scheme = u.Scheme
+ } else {
+ return builder, errURIScheme
+ }
+
+ host := u.Hostname()
+ port := u.Port()
+
+ if host != "" {
+ builder.Host = host
+ }
+
+ if port != "" {
+ port32, err := strconv.ParseInt(port, 10, 32)
+ if err != nil {
+ return builder, err
+ }
+ builder.Port = int(port32)
+ } else {
+ builder.Port = defaultPort
+ }
+
+ if u.User != nil {
+ builder.Username = u.User.Username()
+ if password, ok := u.User.Password(); ok {
+ builder.Password = password
+ }
+ }
+
+ if u.Path != "" {
+ if strings.HasPrefix(u.Path, "/") {
+ if u.Host == "" && strings.HasPrefix(u.Path, "///") {
+ // net/url doesn't handle local context authorities and leaves that up
+ // to the scheme handler. In our case, we translate amqp:/// into the
+ // default host and whatever the vhost should be
+ if len(u.Path) > 3 {
+ builder.Vhost = u.Path[3:]
+ }
+ } else if len(u.Path) > 1 {
+ builder.Vhost = u.Path[1:]
+ }
+ } else {
+ builder.Vhost = u.Path
+ }
+ }
+
+ return builder, nil
+}
+
+// PlainAuth returns a PlainAuth structure based on the parsed URI's
+// Username and Password fields.
+func (uri URI) PlainAuth() *PlainAuth {
+ return &PlainAuth{
+ Username: uri.Username,
+ Password: uri.Password,
+ }
+}
+
+func (uri URI) String() string {
+ authority, err := url.Parse("")
+ if err != nil {
+ return err.Error()
+ }
+
+ authority.Scheme = uri.Scheme
+
+ if uri.Username != defaultURI.Username || uri.Password != defaultURI.Password {
+ authority.User = url.User(uri.Username)
+
+ if uri.Password != defaultURI.Password {
+ authority.User = url.UserPassword(uri.Username, uri.Password)
+ }
+ }
+
+ authority.Host = net.JoinHostPort(uri.Host, strconv.Itoa(uri.Port))
+
+ if defaultPort, found := schemePorts[uri.Scheme]; !found || defaultPort != uri.Port {
+ authority.Host = net.JoinHostPort(uri.Host, strconv.Itoa(uri.Port))
+ } else {
+ // JoinHostPort() automatically add brackets to the host if it's
+ // an IPv6 address.
+ //
+ // If not port is specified, JoinHostPort() return an IP address in the
+ // form of "[::1]:", so we use TrimSuffix() to remove the extra ":".
+ authority.Host = strings.TrimSuffix(net.JoinHostPort(uri.Host, ""), ":")
+ }
+
+ if uri.Vhost != defaultURI.Vhost {
+ // Make sure net/url does not double escape, e.g.
+ // "%2F" does not become "%252F".
+ authority.Path = uri.Vhost
+ authority.RawPath = url.QueryEscape(uri.Vhost)
+ } else {
+ authority.Path = "/"
+ }
+
+ return authority.String()
+}
diff --git a/src/dma/vendor/github.com/streadway/amqp/write.go b/src/dma/vendor/github.com/streadway/amqp/write.go
new file mode 100644
index 00000000..58ed20d6
--- /dev/null
+++ b/src/dma/vendor/github.com/streadway/amqp/write.go
@@ -0,0 +1,411 @@
+// Copyright (c) 2012, Sean Treadway, SoundCloud Ltd.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+// Source code and contact info at http://github.com/streadway/amqp
+
+package amqp
+
+import (
+ "bufio"
+ "bytes"
+ "encoding/binary"
+ "errors"
+ "io"
+ "math"
+ "time"
+)
+
+func (w *writer) WriteFrame(frame frame) (err error) {
+ if err = frame.write(w.w); err != nil {
+ return
+ }
+
+ if buf, ok := w.w.(*bufio.Writer); ok {
+ err = buf.Flush()
+ }
+
+ return
+}
+
+func (f *methodFrame) write(w io.Writer) (err error) {
+ var payload bytes.Buffer
+
+ if f.Method == nil {
+ return errors.New("malformed frame: missing method")
+ }
+
+ class, method := f.Method.id()
+
+ if err = binary.Write(&payload, binary.BigEndian, class); err != nil {
+ return
+ }
+
+ if err = binary.Write(&payload, binary.BigEndian, method); err != nil {
+ return
+ }
+
+ if err = f.Method.write(&payload); err != nil {
+ return
+ }
+
+ return writeFrame(w, frameMethod, f.ChannelId, payload.Bytes())
+}
+
+// Heartbeat
+//
+// Payload is empty
+func (f *heartbeatFrame) write(w io.Writer) (err error) {
+ return writeFrame(w, frameHeartbeat, f.ChannelId, []byte{})
+}
+
+// CONTENT HEADER
+// 0 2 4 12 14
+// +----------+--------+-----------+----------------+------------- - -
+// | class-id | weight | body size | property flags | property list...
+// +----------+--------+-----------+----------------+------------- - -
+// short short long long short remainder...
+//
+func (f *headerFrame) write(w io.Writer) (err error) {
+ var payload bytes.Buffer
+ var zeroTime time.Time
+
+ if err = binary.Write(&payload, binary.BigEndian, f.ClassId); err != nil {
+ return
+ }
+
+ if err = binary.Write(&payload, binary.BigEndian, f.weight); err != nil {
+ return
+ }
+
+ if err = binary.Write(&payload, binary.BigEndian, f.Size); err != nil {
+ return
+ }
+
+ // First pass will build the mask to be serialized, second pass will serialize
+ // each of the fields that appear in the mask.
+
+ var mask uint16
+
+ if len(f.Properties.ContentType) > 0 {
+ mask = mask | flagContentType
+ }
+ if len(f.Properties.ContentEncoding) > 0 {
+ mask = mask | flagContentEncoding
+ }
+ if f.Properties.Headers != nil && len(f.Properties.Headers) > 0 {
+ mask = mask | flagHeaders
+ }
+ if f.Properties.DeliveryMode > 0 {
+ mask = mask | flagDeliveryMode
+ }
+ if f.Properties.Priority > 0 {
+ mask = mask | flagPriority
+ }
+ if len(f.Properties.CorrelationId) > 0 {
+ mask = mask | flagCorrelationId
+ }
+ if len(f.Properties.ReplyTo) > 0 {
+ mask = mask | flagReplyTo
+ }
+ if len(f.Properties.Expiration) > 0 {
+ mask = mask | flagExpiration
+ }
+ if len(f.Properties.MessageId) > 0 {
+ mask = mask | flagMessageId
+ }
+ if f.Properties.Timestamp != zeroTime {
+ mask = mask | flagTimestamp
+ }
+ if len(f.Properties.Type) > 0 {
+ mask = mask | flagType
+ }
+ if len(f.Properties.UserId) > 0 {
+ mask = mask | flagUserId
+ }
+ if len(f.Properties.AppId) > 0 {
+ mask = mask | flagAppId
+ }
+
+ if err = binary.Write(&payload, binary.BigEndian, mask); err != nil {
+ return
+ }
+
+ if hasProperty(mask, flagContentType) {
+ if err = writeShortstr(&payload, f.Properties.ContentType); err != nil {
+ return
+ }
+ }
+ if hasProperty(mask, flagContentEncoding) {
+ if err = writeShortstr(&payload, f.Properties.ContentEncoding); err != nil {
+ return
+ }
+ }
+ if hasProperty(mask, flagHeaders) {
+ if err = writeTable(&payload, f.Properties.Headers); err != nil {
+ return
+ }
+ }
+ if hasProperty(mask, flagDeliveryMode) {
+ if err = binary.Write(&payload, binary.BigEndian, f.Properties.DeliveryMode); err != nil {
+ return
+ }
+ }
+ if hasProperty(mask, flagPriority) {
+ if err = binary.Write(&payload, binary.BigEndian, f.Properties.Priority); err != nil {
+ return
+ }
+ }
+ if hasProperty(mask, flagCorrelationId) {
+ if err = writeShortstr(&payload, f.Properties.CorrelationId); err != nil {
+ return
+ }
+ }
+ if hasProperty(mask, flagReplyTo) {
+ if err = writeShortstr(&payload, f.Properties.ReplyTo); err != nil {
+ return
+ }
+ }
+ if hasProperty(mask, flagExpiration) {
+ if err = writeShortstr(&payload, f.Properties.Expiration); err != nil {
+ return
+ }
+ }
+ if hasProperty(mask, flagMessageId) {
+ if err = writeShortstr(&payload, f.Properties.MessageId); err != nil {
+ return
+ }
+ }
+ if hasProperty(mask, flagTimestamp) {
+ if err = binary.Write(&payload, binary.BigEndian, uint64(f.Properties.Timestamp.Unix())); err != nil {
+ return
+ }
+ }
+ if hasProperty(mask, flagType) {
+ if err = writeShortstr(&payload, f.Properties.Type); err != nil {
+ return
+ }
+ }
+ if hasProperty(mask, flagUserId) {
+ if err = writeShortstr(&payload, f.Properties.UserId); err != nil {
+ return
+ }
+ }
+ if hasProperty(mask, flagAppId) {
+ if err = writeShortstr(&payload, f.Properties.AppId); err != nil {
+ return
+ }
+ }
+
+ return writeFrame(w, frameHeader, f.ChannelId, payload.Bytes())
+}
+
+// Body
+//
+// Payload is one byterange from the full body who's size is declared in the
+// Header frame
+func (f *bodyFrame) write(w io.Writer) (err error) {
+ return writeFrame(w, frameBody, f.ChannelId, f.Body)
+}
+
+func writeFrame(w io.Writer, typ uint8, channel uint16, payload []byte) (err error) {
+ end := []byte{frameEnd}
+ size := uint(len(payload))
+
+ _, err = w.Write([]byte{
+ byte(typ),
+ byte((channel & 0xff00) >> 8),
+ byte((channel & 0x00ff) >> 0),
+ byte((size & 0xff000000) >> 24),
+ byte((size & 0x00ff0000) >> 16),
+ byte((size & 0x0000ff00) >> 8),
+ byte((size & 0x000000ff) >> 0),
+ })
+
+ if err != nil {
+ return
+ }
+
+ if _, err = w.Write(payload); err != nil {
+ return
+ }
+
+ if _, err = w.Write(end); err != nil {
+ return
+ }
+
+ return
+}
+
+func writeShortstr(w io.Writer, s string) (err error) {
+ b := []byte(s)
+
+ var length = uint8(len(b))
+
+ if err = binary.Write(w, binary.BigEndian, length); err != nil {
+ return
+ }
+
+ if _, err = w.Write(b[:length]); err != nil {
+ return
+ }
+
+ return
+}
+
+func writeLongstr(w io.Writer, s string) (err error) {
+ b := []byte(s)
+
+ var length = uint32(len(b))
+
+ if err = binary.Write(w, binary.BigEndian, length); err != nil {
+ return
+ }
+
+ if _, err = w.Write(b[:length]); err != nil {
+ return
+ }
+
+ return
+}
+
+/*
+'A': []interface{}
+'D': Decimal
+'F': Table
+'I': int32
+'S': string
+'T': time.Time
+'V': nil
+'b': byte
+'d': float64
+'f': float32
+'l': int64
+'s': int16
+'t': bool
+'x': []byte
+*/
+func writeField(w io.Writer, value interface{}) (err error) {
+ var buf [9]byte
+ var enc []byte
+
+ switch v := value.(type) {
+ case bool:
+ buf[0] = 't'
+ if v {
+ buf[1] = byte(1)
+ } else {
+ buf[1] = byte(0)
+ }
+ enc = buf[:2]
+
+ case byte:
+ buf[0] = 'b'
+ buf[1] = byte(v)
+ enc = buf[:2]
+
+ case int16:
+ buf[0] = 's'
+ binary.BigEndian.PutUint16(buf[1:3], uint16(v))
+ enc = buf[:3]
+
+ case int32:
+ buf[0] = 'I'
+ binary.BigEndian.PutUint32(buf[1:5], uint32(v))
+ enc = buf[:5]
+
+ case int64:
+ buf[0] = 'l'
+ binary.BigEndian.PutUint64(buf[1:9], uint64(v))
+ enc = buf[:9]
+
+ case float32:
+ buf[0] = 'f'
+ binary.BigEndian.PutUint32(buf[1:5], math.Float32bits(v))
+ enc = buf[:5]
+
+ case float64:
+ buf[0] = 'd'
+ binary.BigEndian.PutUint64(buf[1:9], math.Float64bits(v))
+ enc = buf[:9]
+
+ case Decimal:
+ buf[0] = 'D'
+ buf[1] = byte(v.Scale)
+ binary.BigEndian.PutUint32(buf[2:6], uint32(v.Value))
+ enc = buf[:6]
+
+ case string:
+ buf[0] = 'S'
+ binary.BigEndian.PutUint32(buf[1:5], uint32(len(v)))
+ enc = append(buf[:5], []byte(v)...)
+
+ case []interface{}: // field-array
+ buf[0] = 'A'
+
+ sec := new(bytes.Buffer)
+ for _, val := range v {
+ if err = writeField(sec, val); err != nil {
+ return
+ }
+ }
+
+ binary.BigEndian.PutUint32(buf[1:5], uint32(sec.Len()))
+ if _, err = w.Write(buf[:5]); err != nil {
+ return
+ }
+
+ if _, err = w.Write(sec.Bytes()); err != nil {
+ return
+ }
+
+ return
+
+ case time.Time:
+ buf[0] = 'T'
+ binary.BigEndian.PutUint64(buf[1:9], uint64(v.Unix()))
+ enc = buf[:9]
+
+ case Table:
+ if _, err = w.Write([]byte{'F'}); err != nil {
+ return
+ }
+ return writeTable(w, v)
+
+ case []byte:
+ buf[0] = 'x'
+ binary.BigEndian.PutUint32(buf[1:5], uint32(len(v)))
+ if _, err = w.Write(buf[0:5]); err != nil {
+ return
+ }
+ if _, err = w.Write(v); err != nil {
+ return
+ }
+ return
+
+ case nil:
+ buf[0] = 'V'
+ enc = buf[:1]
+
+ default:
+ return ErrFieldType
+ }
+
+ _, err = w.Write(enc)
+
+ return
+}
+
+func writeTable(w io.Writer, table Table) (err error) {
+ var buf bytes.Buffer
+
+ for key, val := range table {
+ if err = writeShortstr(&buf, key); err != nil {
+ return
+ }
+ if err = writeField(&buf, val); err != nil {
+ return
+ }
+ }
+
+ return writeLongstr(w, string(buf.Bytes()))
+}
diff --git a/src/dma/vendor/github.com/valyala/bytebufferpool/.travis.yml b/src/dma/vendor/github.com/valyala/bytebufferpool/.travis.yml
new file mode 100644
index 00000000..6a6ec2eb
--- /dev/null
+++ b/src/dma/vendor/github.com/valyala/bytebufferpool/.travis.yml
@@ -0,0 +1,15 @@
+language: go
+
+go:
+ - 1.6
+
+script:
+ # build test for supported platforms
+ - GOOS=linux go build
+ - GOOS=darwin go build
+ - GOOS=freebsd go build
+ - GOOS=windows go build
+ - GOARCH=386 go build
+
+ # run tests on a standard platform
+ - go test -v ./...
diff --git a/src/dma/vendor/github.com/valyala/bytebufferpool/LICENSE b/src/dma/vendor/github.com/valyala/bytebufferpool/LICENSE
new file mode 100644
index 00000000..f7c935c2
--- /dev/null
+++ b/src/dma/vendor/github.com/valyala/bytebufferpool/LICENSE
@@ -0,0 +1,22 @@
+The MIT License (MIT)
+
+Copyright (c) 2016 Aliaksandr Valialkin, VertaMedia
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+
diff --git a/src/dma/vendor/github.com/valyala/bytebufferpool/README.md b/src/dma/vendor/github.com/valyala/bytebufferpool/README.md
new file mode 100644
index 00000000..061357e8
--- /dev/null
+++ b/src/dma/vendor/github.com/valyala/bytebufferpool/README.md
@@ -0,0 +1,21 @@
+[![Build Status](https://travis-ci.org/valyala/bytebufferpool.svg)](https://travis-ci.org/valyala/bytebufferpool)
+[![GoDoc](https://godoc.org/github.com/valyala/bytebufferpool?status.svg)](http://godoc.org/github.com/valyala/bytebufferpool)
+[![Go Report](http://goreportcard.com/badge/valyala/bytebufferpool)](http://goreportcard.com/report/valyala/bytebufferpool)
+
+# bytebufferpool
+
+An implementation of a pool of byte buffers with anti-memory-waste protection.
+
+The pool may waste limited amount of memory due to fragmentation.
+This amount equals to the maximum total size of the byte buffers
+in concurrent use.
+
+# Benchmark results
+Currently bytebufferpool is fastest and most effective buffer pool written in Go.
+
+You can find results [here](https://omgnull.github.io/go-benchmark/buffer/).
+
+# bytebufferpool users
+
+* [fasthttp](https://github.com/valyala/fasthttp)
+* [quicktemplate](https://github.com/valyala/quicktemplate)
diff --git a/src/dma/vendor/github.com/valyala/bytebufferpool/bytebuffer.go b/src/dma/vendor/github.com/valyala/bytebufferpool/bytebuffer.go
new file mode 100644
index 00000000..07a055a2
--- /dev/null
+++ b/src/dma/vendor/github.com/valyala/bytebufferpool/bytebuffer.go
@@ -0,0 +1,111 @@
+package bytebufferpool
+
+import "io"
+
+// ByteBuffer provides byte buffer, which can be used for minimizing
+// memory allocations.
+//
+// ByteBuffer may be used with functions appending data to the given []byte
+// slice. See example code for details.
+//
+// Use Get for obtaining an empty byte buffer.
+type ByteBuffer struct {
+
+ // B is a byte buffer to use in append-like workloads.
+ // See example code for details.
+ B []byte
+}
+
+// Len returns the size of the byte buffer.
+func (b *ByteBuffer) Len() int {
+ return len(b.B)
+}
+
+// ReadFrom implements io.ReaderFrom.
+//
+// The function appends all the data read from r to b.
+func (b *ByteBuffer) ReadFrom(r io.Reader) (int64, error) {
+ p := b.B
+ nStart := int64(len(p))
+ nMax := int64(cap(p))
+ n := nStart
+ if nMax == 0 {
+ nMax = 64
+ p = make([]byte, nMax)
+ } else {
+ p = p[:nMax]
+ }
+ for {
+ if n == nMax {
+ nMax *= 2
+ bNew := make([]byte, nMax)
+ copy(bNew, p)
+ p = bNew
+ }
+ nn, err := r.Read(p[n:])
+ n += int64(nn)
+ if err != nil {
+ b.B = p[:n]
+ n -= nStart
+ if err == io.EOF {
+ return n, nil
+ }
+ return n, err
+ }
+ }
+}
+
+// WriteTo implements io.WriterTo.
+func (b *ByteBuffer) WriteTo(w io.Writer) (int64, error) {
+ n, err := w.Write(b.B)
+ return int64(n), err
+}
+
+// Bytes returns b.B, i.e. all the bytes accumulated in the buffer.
+//
+// The purpose of this function is bytes.Buffer compatibility.
+func (b *ByteBuffer) Bytes() []byte {
+ return b.B
+}
+
+// Write implements io.Writer - it appends p to ByteBuffer.B
+func (b *ByteBuffer) Write(p []byte) (int, error) {
+ b.B = append(b.B, p...)
+ return len(p), nil
+}
+
+// WriteByte appends the byte c to the buffer.
+//
+// The purpose of this function is bytes.Buffer compatibility.
+//
+// The function always returns nil.
+func (b *ByteBuffer) WriteByte(c byte) error {
+ b.B = append(b.B, c)
+ return nil
+}
+
+// WriteString appends s to ByteBuffer.B.
+func (b *ByteBuffer) WriteString(s string) (int, error) {
+ b.B = append(b.B, s...)
+ return len(s), nil
+}
+
+// Set sets ByteBuffer.B to p.
+func (b *ByteBuffer) Set(p []byte) {
+ b.B = append(b.B[:0], p...)
+}
+
+// SetString sets ByteBuffer.B to s.
+func (b *ByteBuffer) SetString(s string) {
+ b.B = append(b.B[:0], s...)
+}
+
+// String returns string representation of ByteBuffer.B.
+func (b *ByteBuffer) String() string {
+ return string(b.B)
+}
+
+// Reset makes ByteBuffer.B empty.
+func (b *ByteBuffer) Reset() {
+ b.B = b.B[:0]
+}
diff --git a/src/dma/vendor/github.com/valyala/bytebufferpool/doc.go b/src/dma/vendor/github.com/valyala/bytebufferpool/doc.go
new file mode 100644
index 00000000..e511b7c5
--- /dev/null
+++ b/src/dma/vendor/github.com/valyala/bytebufferpool/doc.go
@@ -0,0 +1,7 @@
+// Package bytebufferpool implements a pool of byte buffers
+// with anti-fragmentation protection.
+//
+// The pool may waste limited amount of memory due to fragmentation.
+// This amount equals to the maximum total size of the byte buffers
+// in concurrent use.
+package bytebufferpool
diff --git a/src/dma/vendor/github.com/valyala/bytebufferpool/pool.go b/src/dma/vendor/github.com/valyala/bytebufferpool/pool.go
new file mode 100644
index 00000000..8bb4134d
--- /dev/null
+++ b/src/dma/vendor/github.com/valyala/bytebufferpool/pool.go
@@ -0,0 +1,151 @@
+package bytebufferpool
+
+import (
+ "sort"
+ "sync"
+ "sync/atomic"
+)
+
+const (
+ minBitSize = 6 // 2**6=64 is a CPU cache line size
+ steps = 20
+
+ minSize = 1 << minBitSize
+ maxSize = 1 << (minBitSize + steps - 1)
+
+ calibrateCallsThreshold = 42000
+ maxPercentile = 0.95
+)
+
+// Pool represents byte buffer pool.
+//
+// Distinct pools may be used for distinct types of byte buffers.
+// Properly determined byte buffer types with their own pools may help reducing
+// memory waste.
+type Pool struct {
+ calls [steps]uint64
+ calibrating uint64
+
+ defaultSize uint64
+ maxSize uint64
+
+ pool sync.Pool
+}
+
+var defaultPool Pool
+
+// Get returns an empty byte buffer from the pool.
+//
+// Got byte buffer may be returned to the pool via Put call.
+// This reduces the number of memory allocations required for byte buffer
+// management.
+func Get() *ByteBuffer { return defaultPool.Get() }
+
+// Get returns new byte buffer with zero length.
+//
+// The byte buffer may be returned to the pool via Put after the use
+// in order to minimize GC overhead.
+func (p *Pool) Get() *ByteBuffer {
+ v := p.pool.Get()
+ if v != nil {
+ return v.(*ByteBuffer)
+ }
+ return &ByteBuffer{
+ B: make([]byte, 0, atomic.LoadUint64(&p.defaultSize)),
+ }
+}
+
+// Put returns byte buffer to the pool.
+//
+// ByteBuffer.B mustn't be touched after returning it to the pool.
+// Otherwise data races will occur.
+func Put(b *ByteBuffer) { defaultPool.Put(b) }
+
+// Put releases byte buffer obtained via Get to the pool.
+//
+// The buffer mustn't be accessed after returning to the pool.
+func (p *Pool) Put(b *ByteBuffer) {
+ idx := index(len(b.B))
+
+ if atomic.AddUint64(&p.calls[idx], 1) > calibrateCallsThreshold {
+ p.calibrate()
+ }
+
+ maxSize := int(atomic.LoadUint64(&p.maxSize))
+ if maxSize == 0 || cap(b.B) <= maxSize {
+ b.Reset()
+ p.pool.Put(b)
+ }
+}
+
+func (p *Pool) calibrate() {
+ if !atomic.CompareAndSwapUint64(&p.calibrating, 0, 1) {
+ return
+ }
+
+ a := make(callSizes, 0, steps)
+ var callsSum uint64
+ for i := uint64(0); i < steps; i++ {
+ calls := atomic.SwapUint64(&p.calls[i], 0)
+ callsSum += calls
+ a = append(a, callSize{
+ calls: calls,
+ size: minSize << i,
+ })
+ }
+ sort.Sort(a)
+
+ defaultSize := a[0].size
+ maxSize := defaultSize
+
+ maxSum := uint64(float64(callsSum) * maxPercentile)
+ callsSum = 0
+ for i := 0; i < steps; i++ {
+ if callsSum > maxSum {
+ break
+ }
+ callsSum += a[i].calls
+ size := a[i].size
+ if size > maxSize {
+ maxSize = size
+ }
+ }
+
+ atomic.StoreUint64(&p.defaultSize, defaultSize)
+ atomic.StoreUint64(&p.maxSize, maxSize)
+
+ atomic.StoreUint64(&p.calibrating, 0)
+}
+
+type callSize struct {
+ calls uint64
+ size uint64
+}
+
+type callSizes []callSize
+
+func (ci callSizes) Len() int {
+ return len(ci)
+}
+
+func (ci callSizes) Less(i, j int) bool {
+ return ci[i].calls > ci[j].calls
+}
+
+func (ci callSizes) Swap(i, j int) {
+ ci[i], ci[j] = ci[j], ci[i]
+}
+
+func index(n int) int {
+ n--
+ n >>= minBitSize
+ idx := 0
+ for n > 0 {
+ n >>= 1
+ idx++
+ }
+ if idx >= steps {
+ idx = steps - 1
+ }
+ return idx
+}
diff --git a/src/dma/vendor/github.com/valyala/fasttemplate/LICENSE b/src/dma/vendor/github.com/valyala/fasttemplate/LICENSE
new file mode 100644
index 00000000..7125a63c
--- /dev/null
+++ b/src/dma/vendor/github.com/valyala/fasttemplate/LICENSE
@@ -0,0 +1,22 @@
+The MIT License (MIT)
+
+Copyright (c) 2015 Aliaksandr Valialkin
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+
diff --git a/src/dma/vendor/github.com/valyala/fasttemplate/README.md b/src/dma/vendor/github.com/valyala/fasttemplate/README.md
new file mode 100644
index 00000000..3a4d56ce
--- /dev/null
+++ b/src/dma/vendor/github.com/valyala/fasttemplate/README.md
@@ -0,0 +1,85 @@
+fasttemplate
+============
+
+Simple and fast template engine for Go.
+
+Fasttemplate peforms only a single task - it substitutes template placeholders
+with user-defined values. At high speed :)
+
+Take a look at [quicktemplate](https://github.com/valyala/quicktemplate) if you need fast yet powerful html template engine.
+
+*Please note that fasttemplate doesn't do any escaping on template values
+unlike [html/template](http://golang.org/pkg/html/template/) do. So values
+must be properly escaped before passing them to fasttemplate.*
+
+Fasttemplate is faster than [text/template](http://golang.org/pkg/text/template/),
+[strings.Replace](http://golang.org/pkg/strings/#Replace),
+[strings.Replacer](http://golang.org/pkg/strings/#Replacer)
+and [fmt.Fprintf](https://golang.org/pkg/fmt/#Fprintf) on placeholders' substitution.
+
+Below are benchmark results comparing fasttemplate performance to text/template,
+strings.Replace, strings.Replacer and fmt.Fprintf:
+
+```
+$ go test -bench=. -benchmem
+PASS
+BenchmarkFmtFprintf-4 2000000 790 ns/op 0 B/op 0 allocs/op
+BenchmarkStringsReplace-4 500000 3474 ns/op 2112 B/op 14 allocs/op
+BenchmarkStringsReplacer-4 500000 2657 ns/op 2256 B/op 23 allocs/op
+BenchmarkTextTemplate-4 500000 3333 ns/op 336 B/op 19 allocs/op
+BenchmarkFastTemplateExecuteFunc-4 5000000 349 ns/op 0 B/op 0 allocs/op
+BenchmarkFastTemplateExecute-4 3000000 383 ns/op 0 B/op 0 allocs/op
+BenchmarkFastTemplateExecuteFuncString-4 3000000 549 ns/op 144 B/op 1 allocs/op
+BenchmarkFastTemplateExecuteString-4 3000000 572 ns/op 144 B/op 1 allocs/op
+BenchmarkFastTemplateExecuteTagFunc-4 2000000 743 ns/op 144 B/op 3 allocs/op
+```
+
+
+Docs
+====
+
+See http://godoc.org/github.com/valyala/fasttemplate .
+
+
+Usage
+=====
+
+```go
+ template := "http://{{host}}/?q={{query}}&foo={{bar}}{{bar}}"
+ t := fasttemplate.New(template, "{{", "}}")
+ s := t.ExecuteString(map[string]interface{}{
+ "host": "google.com",
+ "query": url.QueryEscape("hello=world"),
+ "bar": "foobar",
+ })
+ fmt.Printf("%s", s)
+
+ // Output:
+ // http://google.com/?q=hello%3Dworld&foo=foobarfoobar
+```
+
+
+Advanced usage
+==============
+
+```go
+ template := "Hello, [user]! You won [prize]!!! [foobar]"
+ t, err := fasttemplate.NewTemplate(template, "[", "]")
+ if err != nil {
+ log.Fatalf("unexpected error when parsing template: %s", err)
+ }
+ s := t.ExecuteFuncString(func(w io.Writer, tag string) (int, error) {
+ switch tag {
+ case "user":
+ return w.Write([]byte("John"))
+ case "prize":
+ return w.Write([]byte("$100500"))
+ default:
+ return w.Write([]byte(fmt.Sprintf("[unknown tag %q]", tag)))
+ }
+ })
+ fmt.Printf("%s", s)
+
+ // Output:
+ // Hello, John! You won $100500!!! [unknown tag "foobar"]
+```
diff --git a/src/dma/vendor/github.com/valyala/fasttemplate/template.go b/src/dma/vendor/github.com/valyala/fasttemplate/template.go
new file mode 100644
index 00000000..91209201
--- /dev/null
+++ b/src/dma/vendor/github.com/valyala/fasttemplate/template.go
@@ -0,0 +1,317 @@
+// Package fasttemplate implements simple and fast template library.
+//
+// Fasttemplate is faster than text/template, strings.Replace
+// and strings.Replacer.
+//
+// Fasttemplate ideally fits for fast and simple placeholders' substitutions.
+package fasttemplate
+
+import (
+ "bytes"
+ "fmt"
+ "github.com/valyala/bytebufferpool"
+ "io"
+)
+
+// ExecuteFunc calls f on each template tag (placeholder) occurrence.
+//
+// Returns the number of bytes written to w.
+//
+// This function is optimized for constantly changing templates.
+// Use Template.ExecuteFunc for frozen templates.
+func ExecuteFunc(template, startTag, endTag string, w io.Writer, f TagFunc) (int64, error) {
+ s := unsafeString2Bytes(template)
+ a := unsafeString2Bytes(startTag)
+ b := unsafeString2Bytes(endTag)
+
+ var nn int64
+ var ni int
+ var err error
+ for {
+ n := bytes.Index(s, a)
+ if n < 0 {
+ break
+ }
+ ni, err = w.Write(s[:n])
+ nn += int64(ni)
+ if err != nil {
+ return nn, err
+ }
+
+ s = s[n+len(a):]
+ n = bytes.Index(s, b)
+ if n < 0 {
+ // cannot find end tag - just write it to the output.
+ ni, _ = w.Write(a)
+ nn += int64(ni)
+ break
+ }
+
+ ni, err = f(w, unsafeBytes2String(s[:n]))
+ nn += int64(ni)
+ s = s[n+len(b):]
+ }
+ ni, err = w.Write(s)
+ nn += int64(ni)
+
+ return nn, err
+}
+
+// Execute substitutes template tags (placeholders) with the corresponding
+// values from the map m and writes the result to the given writer w.
+//
+// Substitution map m may contain values with the following types:
+// * []byte - the fastest value type
+// * string - convenient value type
+// * TagFunc - flexible value type
+//
+// Returns the number of bytes written to w.
+//
+// This function is optimized for constantly changing templates.
+// Use Template.Execute for frozen templates.
+func Execute(template, startTag, endTag string, w io.Writer, m map[string]interface{}) (int64, error) {
+ return ExecuteFunc(template, startTag, endTag, w, func(w io.Writer, tag string) (int, error) { return stdTagFunc(w, tag, m) })
+}
+
+// ExecuteFuncString calls f on each template tag (placeholder) occurrence
+// and substitutes it with the data written to TagFunc's w.
+//
+// Returns the resulting string.
+//
+// This function is optimized for constantly changing templates.
+// Use Template.ExecuteFuncString for frozen templates.
+func ExecuteFuncString(template, startTag, endTag string, f TagFunc) string {
+ tagsCount := bytes.Count(unsafeString2Bytes(template), unsafeString2Bytes(startTag))
+ if tagsCount == 0 {
+ return template
+ }
+
+ bb := byteBufferPool.Get()
+ if _, err := ExecuteFunc(template, startTag, endTag, bb, f); err != nil {
+ panic(fmt.Sprintf("unexpected error: %s", err))
+ }
+ s := string(bb.B)
+ bb.Reset()
+ byteBufferPool.Put(bb)
+ return s
+}
+
+var byteBufferPool bytebufferpool.Pool
+
+// ExecuteString substitutes template tags (placeholders) with the corresponding
+// values from the map m and returns the result.
+//
+// Substitution map m may contain values with the following types:
+// * []byte - the fastest value type
+// * string - convenient value type
+// * TagFunc - flexible value type
+//
+// This function is optimized for constantly changing templates.
+// Use Template.ExecuteString for frozen templates.
+func ExecuteString(template, startTag, endTag string, m map[string]interface{}) string {
+ return ExecuteFuncString(template, startTag, endTag, func(w io.Writer, tag string) (int, error) { return stdTagFunc(w, tag, m) })
+}
+
+// Template implements simple template engine, which can be used for fast
+// tags' (aka placeholders) substitution.
+type Template struct {
+ template string
+ startTag string
+ endTag string
+
+ texts [][]byte
+ tags []string
+ byteBufferPool bytebufferpool.Pool
+}
+
+// New parses the given template using the given startTag and endTag
+// as tag start and tag end.
+//
+// The returned template can be executed by concurrently running goroutines
+// using Execute* methods.
+//
+// New panics if the given template cannot be parsed. Use NewTemplate instead
+// if template may contain errors.
+func New(template, startTag, endTag string) *Template {
+ t, err := NewTemplate(template, startTag, endTag)
+ if err != nil {
+ panic(err)
+ }
+ return t
+}
+
+// NewTemplate parses the given template using the given startTag and endTag
+// as tag start and tag end.
+//
+// The returned template can be executed by concurrently running goroutines
+// using Execute* methods.
+func NewTemplate(template, startTag, endTag string) (*Template, error) {
+ var t Template
+ err := t.Reset(template, startTag, endTag)
+ if err != nil {
+ return nil, err
+ }
+ return &t, nil
+}
+
+// TagFunc can be used as a substitution value in the map passed to Execute*.
+// Execute* functions pass tag (placeholder) name in 'tag' argument.
+//
+// TagFunc must be safe to call from concurrently running goroutines.
+//
+// TagFunc must write contents to w and return the number of bytes written.
+type TagFunc func(w io.Writer, tag string) (int, error)
+
+// Reset resets the template t to new one defined by
+// template, startTag and endTag.
+//
+// Reset allows Template object re-use.
+//
+// Reset may be called only if no other goroutines call t methods at the moment.
+func (t *Template) Reset(template, startTag, endTag string) error {
+ // Keep these vars in t, so GC won't collect them and won't break
+ // vars derived via unsafe*
+ t.template = template
+ t.startTag = startTag
+ t.endTag = endTag
+ t.texts = t.texts[:0]
+ t.tags = t.tags[:0]
+
+ if len(startTag) == 0 {
+ panic("startTag cannot be empty")
+ }
+ if len(endTag) == 0 {
+ panic("endTag cannot be empty")
+ }
+
+ s := unsafeString2Bytes(template)
+ a := unsafeString2Bytes(startTag)
+ b := unsafeString2Bytes(endTag)
+
+ tagsCount := bytes.Count(s, a)
+ if tagsCount == 0 {
+ return nil
+ }
+
+ if tagsCount+1 > cap(t.texts) {
+ t.texts = make([][]byte, 0, tagsCount+1)
+ }
+ if tagsCount > cap(t.tags) {
+ t.tags = make([]string, 0, tagsCount)
+ }
+
+ for {
+ n := bytes.Index(s, a)
+ if n < 0 {
+ t.texts = append(t.texts, s)
+ break
+ }
+ t.texts = append(t.texts, s[:n])
+
+ s = s[n+len(a):]
+ n = bytes.Index(s, b)
+ if n < 0 {
+ return fmt.Errorf("Cannot find end tag=%q in the template=%q starting from %q", endTag, template, s)
+ }
+
+ t.tags = append(t.tags, unsafeBytes2String(s[:n]))
+ s = s[n+len(b):]
+ }
+
+ return nil
+}
+
+// ExecuteFunc calls f on each template tag (placeholder) occurrence.
+//
+// Returns the number of bytes written to w.
+//
+// This function is optimized for frozen templates.
+// Use ExecuteFunc for constantly changing templates.
+func (t *Template) ExecuteFunc(w io.Writer, f TagFunc) (int64, error) {
+ var nn int64
+
+ n := len(t.texts) - 1
+ if n == -1 {
+ ni, err := w.Write(unsafeString2Bytes(t.template))
+ return int64(ni), err
+ }
+
+ for i := 0; i < n; i++ {
+ ni, err := w.Write(t.texts[i])
+ nn += int64(ni)
+ if err != nil {
+ return nn, err
+ }
+
+ ni, err = f(w, t.tags[i])
+ nn += int64(ni)
+ if err != nil {
+ return nn, err
+ }
+ }
+ ni, err := w.Write(t.texts[n])
+ nn += int64(ni)
+ return nn, err
+}
+
+// Execute substitutes template tags (placeholders) with the corresponding
+// values from the map m and writes the result to the given writer w.
+//
+// Substitution map m may contain values with the following types:
+// * []byte - the fastest value type
+// * string - convenient value type
+// * TagFunc - flexible value type
+//
+// Returns the number of bytes written to w.
+func (t *Template) Execute(w io.Writer, m map[string]interface{}) (int64, error) {
+ return t.ExecuteFunc(w, func(w io.Writer, tag string) (int, error) { return stdTagFunc(w, tag, m) })
+}
+
+// ExecuteFuncString calls f on each template tag (placeholder) occurrence
+// and substitutes it with the data written to TagFunc's w.
+//
+// Returns the resulting string.
+//
+// This function is optimized for frozen templates.
+// Use ExecuteFuncString for constantly changing templates.
+func (t *Template) ExecuteFuncString(f TagFunc) string {
+ bb := t.byteBufferPool.Get()
+ if _, err := t.ExecuteFunc(bb, f); err != nil {
+ panic(fmt.Sprintf("unexpected error: %s", err))
+ }
+ s := string(bb.Bytes())
+ bb.Reset()
+ t.byteBufferPool.Put(bb)
+ return s
+}
+
+// ExecuteString substitutes template tags (placeholders) with the corresponding
+// values from the map m and returns the result.
+//
+// Substitution map m may contain values with the following types:
+// * []byte - the fastest value type
+// * string - convenient value type
+// * TagFunc - flexible value type
+//
+// This function is optimized for frozen templates.
+// Use ExecuteString for constantly changing templates.
+func (t *Template) ExecuteString(m map[string]interface{}) string {
+ return t.ExecuteFuncString(func(w io.Writer, tag string) (int, error) { return stdTagFunc(w, tag, m) })
+}
+
+func stdTagFunc(w io.Writer, tag string, m map[string]interface{}) (int, error) {
+ v := m[tag]
+ if v == nil {
+ return 0, nil
+ }
+ switch value := v.(type) {
+ case []byte:
+ return w.Write(value)
+ case string:
+ return w.Write([]byte(value))
+ case TagFunc:
+ return value(w, tag)
+ default:
+ panic(fmt.Sprintf("tag=%q contains unexpected value type=%#v. Expected []byte, string or TagFunc", tag, v))
+ }
+}
diff --git a/src/dma/vendor/github.com/valyala/fasttemplate/unsafe.go b/src/dma/vendor/github.com/valyala/fasttemplate/unsafe.go
new file mode 100644
index 00000000..0498248f
--- /dev/null
+++ b/src/dma/vendor/github.com/valyala/fasttemplate/unsafe.go
@@ -0,0 +1,22 @@
+// +build !appengine
+
+package fasttemplate
+
+import (
+ "reflect"
+ "unsafe"
+)
+
+func unsafeBytes2String(b []byte) string {
+ return *(*string)(unsafe.Pointer(&b))
+}
+
+func unsafeString2Bytes(s string) []byte {
+ sh := (*reflect.StringHeader)(unsafe.Pointer(&s))
+ bh := reflect.SliceHeader{
+ Data: sh.Data,
+ Len: sh.Len,
+ Cap: sh.Len,
+ }
+ return *(*[]byte)(unsafe.Pointer(&bh))
+}
diff --git a/src/dma/vendor/github.com/valyala/fasttemplate/unsafe_gae.go b/src/dma/vendor/github.com/valyala/fasttemplate/unsafe_gae.go
new file mode 100644
index 00000000..cc4ce151
--- /dev/null
+++ b/src/dma/vendor/github.com/valyala/fasttemplate/unsafe_gae.go
@@ -0,0 +1,11 @@
+// +build appengine
+
+package fasttemplate
+
+func unsafeBytes2String(b []byte) string {
+ return string(b)
+}
+
+func unsafeString2Bytes(s string) []byte {
+ return []byte(s)
+}
diff --git a/src/dma/vendor/golang.org/x/crypto/AUTHORS b/src/dma/vendor/golang.org/x/crypto/AUTHORS
new file mode 100644
index 00000000..2b00ddba
--- /dev/null
+++ b/src/dma/vendor/golang.org/x/crypto/AUTHORS
@@ -0,0 +1,3 @@
+# This source code refers to The Go Authors for copyright purposes.
+# The master list of authors is in the main Go distribution,
+# visible at https://tip.golang.org/AUTHORS.
diff --git a/src/dma/vendor/golang.org/x/crypto/CONTRIBUTORS b/src/dma/vendor/golang.org/x/crypto/CONTRIBUTORS
new file mode 100644
index 00000000..1fbd3e97
--- /dev/null
+++ b/src/dma/vendor/golang.org/x/crypto/CONTRIBUTORS
@@ -0,0 +1,3 @@
+# This source code was written by the Go contributors.
+# The master list of contributors is in the main Go distribution,
+# visible at https://tip.golang.org/CONTRIBUTORS.
diff --git a/src/dma/vendor/golang.org/x/crypto/LICENSE b/src/dma/vendor/golang.org/x/crypto/LICENSE
new file mode 100644
index 00000000..6a66aea5
--- /dev/null
+++ b/src/dma/vendor/golang.org/x/crypto/LICENSE
@@ -0,0 +1,27 @@
+Copyright (c) 2009 The Go Authors. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+ * Redistributions of source code must retain the above copyright
+notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above
+copyright notice, this list of conditions and the following disclaimer
+in the documentation and/or other materials provided with the
+distribution.
+ * Neither the name of Google Inc. nor the names of its
+contributors may be used to endorse or promote products derived from
+this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/src/dma/vendor/golang.org/x/crypto/PATENTS b/src/dma/vendor/golang.org/x/crypto/PATENTS
new file mode 100644
index 00000000..73309904
--- /dev/null
+++ b/src/dma/vendor/golang.org/x/crypto/PATENTS
@@ -0,0 +1,22 @@
+Additional IP Rights Grant (Patents)
+
+"This implementation" means the copyrightable works distributed by
+Google as part of the Go project.
+
+Google hereby grants to You a perpetual, worldwide, non-exclusive,
+no-charge, royalty-free, irrevocable (except as stated in this section)
+patent license to make, have made, use, offer to sell, sell, import,
+transfer and otherwise run, modify and propagate the contents of this
+implementation of Go, where such license applies only to those patent
+claims, both currently owned or controlled by Google and acquired in
+the future, licensable by Google that are necessarily infringed by this
+implementation of Go. This grant does not include claims that would be
+infringed only as a consequence of further modification of this
+implementation. If you or your agent or exclusive licensee institute or
+order or agree to the institution of patent litigation against any
+entity (including a cross-claim or counterclaim in a lawsuit) alleging
+that this implementation of Go or any code incorporated within this
+implementation of Go constitutes direct or contributory patent
+infringement, or inducement of patent infringement, then any patent
+rights granted to you under this License for this implementation of Go
+shall terminate as of the date such litigation is filed.
diff --git a/src/dma/vendor/golang.org/x/crypto/acme/acme.go b/src/dma/vendor/golang.org/x/crypto/acme/acme.go
new file mode 100644
index 00000000..7df64764
--- /dev/null
+++ b/src/dma/vendor/golang.org/x/crypto/acme/acme.go
@@ -0,0 +1,922 @@
+// Copyright 2015 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Package acme provides an implementation of the
+// Automatic Certificate Management Environment (ACME) spec.
+// See https://tools.ietf.org/html/draft-ietf-acme-acme-02 for details.
+//
+// Most common scenarios will want to use autocert subdirectory instead,
+// which provides automatic access to certificates from Let's Encrypt
+// and any other ACME-based CA.
+//
+// This package is a work in progress and makes no API stability promises.
+package acme
+
+import (
+ "context"
+ "crypto"
+ "crypto/ecdsa"
+ "crypto/elliptic"
+ "crypto/rand"
+ "crypto/sha256"
+ "crypto/tls"
+ "crypto/x509"
+ "crypto/x509/pkix"
+ "encoding/asn1"
+ "encoding/base64"
+ "encoding/hex"
+ "encoding/json"
+ "encoding/pem"
+ "errors"
+ "fmt"
+ "io"
+ "io/ioutil"
+ "math/big"
+ "net/http"
+ "strings"
+ "sync"
+ "time"
+)
+
+const (
+ // LetsEncryptURL is the Directory endpoint of Let's Encrypt CA.
+ LetsEncryptURL = "https://acme-v01.api.letsencrypt.org/directory"
+
+ // ALPNProto is the ALPN protocol name used by a CA server when validating
+ // tls-alpn-01 challenges.
+ //
+ // Package users must ensure their servers can negotiate the ACME ALPN in
+ // order for tls-alpn-01 challenge verifications to succeed.
+ // See the crypto/tls package's Config.NextProtos field.
+ ALPNProto = "acme-tls/1"
+)
+
+// idPeACMEIdentifierV1 is the OID for the ACME extension for the TLS-ALPN challenge.
+var idPeACMEIdentifierV1 = asn1.ObjectIdentifier{1, 3, 6, 1, 5, 5, 7, 1, 30, 1}
+
+const (
+ maxChainLen = 5 // max depth and breadth of a certificate chain
+ maxCertSize = 1 << 20 // max size of a certificate, in bytes
+
+ // Max number of collected nonces kept in memory.
+ // Expect usual peak of 1 or 2.
+ maxNonces = 100
+)
+
+// Client is an ACME client.
+// The only required field is Key. An example of creating a client with a new key
+// is as follows:
+//
+// key, err := rsa.GenerateKey(rand.Reader, 2048)
+// if err != nil {
+// log.Fatal(err)
+// }
+// client := &Client{Key: key}
+//
+type Client struct {
+ // Key is the account key used to register with a CA and sign requests.
+ // Key.Public() must return a *rsa.PublicKey or *ecdsa.PublicKey.
+ Key crypto.Signer
+
+ // HTTPClient optionally specifies an HTTP client to use
+ // instead of http.DefaultClient.
+ HTTPClient *http.Client
+
+ // DirectoryURL points to the CA directory endpoint.
+ // If empty, LetsEncryptURL is used.
+ // Mutating this value after a successful call of Client's Discover method
+ // will have no effect.
+ DirectoryURL string
+
+ // RetryBackoff computes the duration after which the nth retry of a failed request
+ // should occur. The value of n for the first call on failure is 1.
+ // The values of r and resp are the request and response of the last failed attempt.
+ // If the returned value is negative or zero, no more retries are done and an error
+ // is returned to the caller of the original method.
+ //
+ // Requests which result in a 4xx client error are not retried,
+ // except for 400 Bad Request due to "bad nonce" errors and 429 Too Many Requests.
+ //
+ // If RetryBackoff is nil, a truncated exponential backoff algorithm
+ // with the ceiling of 10 seconds is used, where each subsequent retry n
+ // is done after either ("Retry-After" + jitter) or (2^n seconds + jitter),
+ // preferring the former if "Retry-After" header is found in the resp.
+ // The jitter is a random value up to 1 second.
+ RetryBackoff func(n int, r *http.Request, resp *http.Response) time.Duration
+
+ dirMu sync.Mutex // guards writes to dir
+ dir *Directory // cached result of Client's Discover method
+
+ noncesMu sync.Mutex
+ nonces map[string]struct{} // nonces collected from previous responses
+}
+
+// Discover performs ACME server discovery using c.DirectoryURL.
+//
+// It caches successful result. So, subsequent calls will not result in
+// a network round-trip. This also means mutating c.DirectoryURL after successful call
+// of this method will have no effect.
+func (c *Client) Discover(ctx context.Context) (Directory, error) {
+ c.dirMu.Lock()
+ defer c.dirMu.Unlock()
+ if c.dir != nil {
+ return *c.dir, nil
+ }
+
+ dirURL := c.DirectoryURL
+ if dirURL == "" {
+ dirURL = LetsEncryptURL
+ }
+ res, err := c.get(ctx, dirURL, wantStatus(http.StatusOK))
+ if err != nil {
+ return Directory{}, err
+ }
+ defer res.Body.Close()
+ c.addNonce(res.Header)
+
+ var v struct {
+ Reg string `json:"new-reg"`
+ Authz string `json:"new-authz"`
+ Cert string `json:"new-cert"`
+ Revoke string `json:"revoke-cert"`
+ Meta struct {
+ Terms string `json:"terms-of-service"`
+ Website string `json:"website"`
+ CAA []string `json:"caa-identities"`
+ }
+ }
+ if err := json.NewDecoder(res.Body).Decode(&v); err != nil {
+ return Directory{}, err
+ }
+ c.dir = &Directory{
+ RegURL: v.Reg,
+ AuthzURL: v.Authz,
+ CertURL: v.Cert,
+ RevokeURL: v.Revoke,
+ Terms: v.Meta.Terms,
+ Website: v.Meta.Website,
+ CAA: v.Meta.CAA,
+ }
+ return *c.dir, nil
+}
+
+// CreateCert requests a new certificate using the Certificate Signing Request csr encoded in DER format.
+// The exp argument indicates the desired certificate validity duration. CA may issue a certificate
+// with a different duration.
+// If the bundle argument is true, the returned value will also contain the CA (issuer) certificate chain.
+//
+// In the case where CA server does not provide the issued certificate in the response,
+// CreateCert will poll certURL using c.FetchCert, which will result in additional round-trips.
+// In such a scenario, the caller can cancel the polling with ctx.
+//
+// CreateCert returns an error if the CA's response or chain was unreasonably large.
+// Callers are encouraged to parse the returned value to ensure the certificate is valid and has the expected features.
+func (c *Client) CreateCert(ctx context.Context, csr []byte, exp time.Duration, bundle bool) (der [][]byte, certURL string, err error) {
+ if _, err := c.Discover(ctx); err != nil {
+ return nil, "", err
+ }
+
+ req := struct {
+ Resource string `json:"resource"`
+ CSR string `json:"csr"`
+ NotBefore string `json:"notBefore,omitempty"`
+ NotAfter string `json:"notAfter,omitempty"`
+ }{
+ Resource: "new-cert",
+ CSR: base64.RawURLEncoding.EncodeToString(csr),
+ }
+ now := timeNow()
+ req.NotBefore = now.Format(time.RFC3339)
+ if exp > 0 {
+ req.NotAfter = now.Add(exp).Format(time.RFC3339)
+ }
+
+ res, err := c.post(ctx, c.Key, c.dir.CertURL, req, wantStatus(http.StatusCreated))
+ if err != nil {
+ return nil, "", err
+ }
+ defer res.Body.Close()
+
+ curl := res.Header.Get("Location") // cert permanent URL
+ if res.ContentLength == 0 {
+ // no cert in the body; poll until we get it
+ cert, err := c.FetchCert(ctx, curl, bundle)
+ return cert, curl, err
+ }
+ // slurp issued cert and CA chain, if requested
+ cert, err := c.responseCert(ctx, res, bundle)
+ return cert, curl, err
+}
+
+// FetchCert retrieves already issued certificate from the given url, in DER format.
+// It retries the request until the certificate is successfully retrieved,
+// context is cancelled by the caller or an error response is received.
+//
+// The returned value will also contain the CA (issuer) certificate if the bundle argument is true.
+//
+// FetchCert returns an error if the CA's response or chain was unreasonably large.
+// Callers are encouraged to parse the returned value to ensure the certificate is valid
+// and has expected features.
+func (c *Client) FetchCert(ctx context.Context, url string, bundle bool) ([][]byte, error) {
+ res, err := c.get(ctx, url, wantStatus(http.StatusOK))
+ if err != nil {
+ return nil, err
+ }
+ return c.responseCert(ctx, res, bundle)
+}
+
+// RevokeCert revokes a previously issued certificate cert, provided in DER format.
+//
+// The key argument, used to sign the request, must be authorized
+// to revoke the certificate. It's up to the CA to decide which keys are authorized.
+// For instance, the key pair of the certificate may be authorized.
+// If the key is nil, c.Key is used instead.
+func (c *Client) RevokeCert(ctx context.Context, key crypto.Signer, cert []byte, reason CRLReasonCode) error {
+ if _, err := c.Discover(ctx); err != nil {
+ return err
+ }
+
+ body := &struct {
+ Resource string `json:"resource"`
+ Cert string `json:"certificate"`
+ Reason int `json:"reason"`
+ }{
+ Resource: "revoke-cert",
+ Cert: base64.RawURLEncoding.EncodeToString(cert),
+ Reason: int(reason),
+ }
+ if key == nil {
+ key = c.Key
+ }
+ res, err := c.post(ctx, key, c.dir.RevokeURL, body, wantStatus(http.StatusOK))
+ if err != nil {
+ return err
+ }
+ defer res.Body.Close()
+ return nil
+}
+
+// AcceptTOS always returns true to indicate the acceptance of a CA's Terms of Service
+// during account registration. See Register method of Client for more details.
+func AcceptTOS(tosURL string) bool { return true }
+
+// Register creates a new account registration by following the "new-reg" flow.
+// It returns the registered account. The account is not modified.
+//
+// The registration may require the caller to agree to the CA's Terms of Service (TOS).
+// If so, and the account has not indicated the acceptance of the terms (see Account for details),
+// Register calls prompt with a TOS URL provided by the CA. Prompt should report
+// whether the caller agrees to the terms. To always accept the terms, the caller can use AcceptTOS.
+func (c *Client) Register(ctx context.Context, a *Account, prompt func(tosURL string) bool) (*Account, error) {
+ if _, err := c.Discover(ctx); err != nil {
+ return nil, err
+ }
+
+ var err error
+ if a, err = c.doReg(ctx, c.dir.RegURL, "new-reg", a); err != nil {
+ return nil, err
+ }
+ var accept bool
+ if a.CurrentTerms != "" && a.CurrentTerms != a.AgreedTerms {
+ accept = prompt(a.CurrentTerms)
+ }
+ if accept {
+ a.AgreedTerms = a.CurrentTerms
+ a, err = c.UpdateReg(ctx, a)
+ }
+ return a, err
+}
+
+// GetReg retrieves an existing registration.
+// The url argument is an Account URI.
+func (c *Client) GetReg(ctx context.Context, url string) (*Account, error) {
+ a, err := c.doReg(ctx, url, "reg", nil)
+ if err != nil {
+ return nil, err
+ }
+ a.URI = url
+ return a, nil
+}
+
+// UpdateReg updates an existing registration.
+// It returns an updated account copy. The provided account is not modified.
+func (c *Client) UpdateReg(ctx context.Context, a *Account) (*Account, error) {
+ uri := a.URI
+ a, err := c.doReg(ctx, uri, "reg", a)
+ if err != nil {
+ return nil, err
+ }
+ a.URI = uri
+ return a, nil
+}
+
+// Authorize performs the initial step in an authorization flow.
+// The caller will then need to choose from and perform a set of returned
+// challenges using c.Accept in order to successfully complete authorization.
+//
+// If an authorization has been previously granted, the CA may return
+// a valid authorization (Authorization.Status is StatusValid). If so, the caller
+// need not fulfill any challenge and can proceed to requesting a certificate.
+func (c *Client) Authorize(ctx context.Context, domain string) (*Authorization, error) {
+ if _, err := c.Discover(ctx); err != nil {
+ return nil, err
+ }
+
+ type authzID struct {
+ Type string `json:"type"`
+ Value string `json:"value"`
+ }
+ req := struct {
+ Resource string `json:"resource"`
+ Identifier authzID `json:"identifier"`
+ }{
+ Resource: "new-authz",
+ Identifier: authzID{Type: "dns", Value: domain},
+ }
+ res, err := c.post(ctx, c.Key, c.dir.AuthzURL, req, wantStatus(http.StatusCreated))
+ if err != nil {
+ return nil, err
+ }
+ defer res.Body.Close()
+
+ var v wireAuthz
+ if err := json.NewDecoder(res.Body).Decode(&v); err != nil {
+ return nil, fmt.Errorf("acme: invalid response: %v", err)
+ }
+ if v.Status != StatusPending && v.Status != StatusValid {
+ return nil, fmt.Errorf("acme: unexpected status: %s", v.Status)
+ }
+ return v.authorization(res.Header.Get("Location")), nil
+}
+
+// GetAuthorization retrieves an authorization identified by the given URL.
+//
+// If a caller needs to poll an authorization until its status is final,
+// see the WaitAuthorization method.
+func (c *Client) GetAuthorization(ctx context.Context, url string) (*Authorization, error) {
+ res, err := c.get(ctx, url, wantStatus(http.StatusOK, http.StatusAccepted))
+ if err != nil {
+ return nil, err
+ }
+ defer res.Body.Close()
+ var v wireAuthz
+ if err := json.NewDecoder(res.Body).Decode(&v); err != nil {
+ return nil, fmt.Errorf("acme: invalid response: %v", err)
+ }
+ return v.authorization(url), nil
+}
+
+// RevokeAuthorization relinquishes an existing authorization identified
+// by the given URL.
+// The url argument is an Authorization.URI value.
+//
+// If successful, the caller will be required to obtain a new authorization
+// using the Authorize method before being able to request a new certificate
+// for the domain associated with the authorization.
+//
+// It does not revoke existing certificates.
+func (c *Client) RevokeAuthorization(ctx context.Context, url string) error {
+ req := struct {
+ Resource string `json:"resource"`
+ Status string `json:"status"`
+ Delete bool `json:"delete"`
+ }{
+ Resource: "authz",
+ Status: "deactivated",
+ Delete: true,
+ }
+ res, err := c.post(ctx, c.Key, url, req, wantStatus(http.StatusOK))
+ if err != nil {
+ return err
+ }
+ defer res.Body.Close()
+ return nil
+}
+
+// WaitAuthorization polls an authorization at the given URL
+// until it is in one of the final states, StatusValid or StatusInvalid,
+// the ACME CA responded with a 4xx error code, or the context is done.
+//
+// It returns a non-nil Authorization only if its Status is StatusValid.
+// In all other cases WaitAuthorization returns an error.
+// If the Status is StatusInvalid, the returned error is of type *AuthorizationError.
+func (c *Client) WaitAuthorization(ctx context.Context, url string) (*Authorization, error) {
+ for {
+ res, err := c.get(ctx, url, wantStatus(http.StatusOK, http.StatusAccepted))
+ if err != nil {
+ return nil, err
+ }
+
+ var raw wireAuthz
+ err = json.NewDecoder(res.Body).Decode(&raw)
+ res.Body.Close()
+ switch {
+ case err != nil:
+ // Skip and retry.
+ case raw.Status == StatusValid:
+ return raw.authorization(url), nil
+ case raw.Status == StatusInvalid:
+ return nil, raw.error(url)
+ }
+
+ // Exponential backoff is implemented in c.get above.
+ // This is just to prevent continuously hitting the CA
+ // while waiting for a final authorization status.
+ d := retryAfter(res.Header.Get("Retry-After"))
+ if d == 0 {
+ // Given that the fastest challenges TLS-SNI and HTTP-01
+ // require a CA to make at least 1 network round trip
+ // and most likely persist a challenge state,
+ // this default delay seems reasonable.
+ d = time.Second
+ }
+ t := time.NewTimer(d)
+ select {
+ case <-ctx.Done():
+ t.Stop()
+ return nil, ctx.Err()
+ case <-t.C:
+ // Retry.
+ }
+ }
+}
+
+// GetChallenge retrieves the current status of an challenge.
+//
+// A client typically polls a challenge status using this method.
+func (c *Client) GetChallenge(ctx context.Context, url string) (*Challenge, error) {
+ res, err := c.get(ctx, url, wantStatus(http.StatusOK, http.StatusAccepted))
+ if err != nil {
+ return nil, err
+ }
+ defer res.Body.Close()
+ v := wireChallenge{URI: url}
+ if err := json.NewDecoder(res.Body).Decode(&v); err != nil {
+ return nil, fmt.Errorf("acme: invalid response: %v", err)
+ }
+ return v.challenge(), nil
+}
+
+// Accept informs the server that the client accepts one of its challenges
+// previously obtained with c.Authorize.
+//
+// The server will then perform the validation asynchronously.
+func (c *Client) Accept(ctx context.Context, chal *Challenge) (*Challenge, error) {
+ auth, err := keyAuth(c.Key.Public(), chal.Token)
+ if err != nil {
+ return nil, err
+ }
+
+ req := struct {
+ Resource string `json:"resource"`
+ Type string `json:"type"`
+ Auth string `json:"keyAuthorization"`
+ }{
+ Resource: "challenge",
+ Type: chal.Type,
+ Auth: auth,
+ }
+ res, err := c.post(ctx, c.Key, chal.URI, req, wantStatus(
+ http.StatusOK, // according to the spec
+ http.StatusAccepted, // Let's Encrypt: see https://goo.gl/WsJ7VT (acme-divergences.md)
+ ))
+ if err != nil {
+ return nil, err
+ }
+ defer res.Body.Close()
+
+ var v wireChallenge
+ if err := json.NewDecoder(res.Body).Decode(&v); err != nil {
+ return nil, fmt.Errorf("acme: invalid response: %v", err)
+ }
+ return v.challenge(), nil
+}
+
+// DNS01ChallengeRecord returns a DNS record value for a dns-01 challenge response.
+// A TXT record containing the returned value must be provisioned under
+// "_acme-challenge" name of the domain being validated.
+//
+// The token argument is a Challenge.Token value.
+func (c *Client) DNS01ChallengeRecord(token string) (string, error) {
+ ka, err := keyAuth(c.Key.Public(), token)
+ if err != nil {
+ return "", err
+ }
+ b := sha256.Sum256([]byte(ka))
+ return base64.RawURLEncoding.EncodeToString(b[:]), nil
+}
+
+// HTTP01ChallengeResponse returns the response for an http-01 challenge.
+// Servers should respond with the value to HTTP requests at the URL path
+// provided by HTTP01ChallengePath to validate the challenge and prove control
+// over a domain name.
+//
+// The token argument is a Challenge.Token value.
+func (c *Client) HTTP01ChallengeResponse(token string) (string, error) {
+ return keyAuth(c.Key.Public(), token)
+}
+
+// HTTP01ChallengePath returns the URL path at which the response for an http-01 challenge
+// should be provided by the servers.
+// The response value can be obtained with HTTP01ChallengeResponse.
+//
+// The token argument is a Challenge.Token value.
+func (c *Client) HTTP01ChallengePath(token string) string {
+ return "/.well-known/acme-challenge/" + token
+}
+
+// TLSSNI01ChallengeCert creates a certificate for TLS-SNI-01 challenge response.
+// Servers can present the certificate to validate the challenge and prove control
+// over a domain name.
+//
+// The implementation is incomplete in that the returned value is a single certificate,
+// computed only for Z0 of the key authorization. ACME CAs are expected to update
+// their implementations to use the newer version, TLS-SNI-02.
+// For more details on TLS-SNI-01 see https://tools.ietf.org/html/draft-ietf-acme-acme-01#section-7.3.
+//
+// The token argument is a Challenge.Token value.
+// If a WithKey option is provided, its private part signs the returned cert,
+// and the public part is used to specify the signee.
+// If no WithKey option is provided, a new ECDSA key is generated using P-256 curve.
+//
+// The returned certificate is valid for the next 24 hours and must be presented only when
+// the server name of the TLS ClientHello matches exactly the returned name value.
+func (c *Client) TLSSNI01ChallengeCert(token string, opt ...CertOption) (cert tls.Certificate, name string, err error) {
+ ka, err := keyAuth(c.Key.Public(), token)
+ if err != nil {
+ return tls.Certificate{}, "", err
+ }
+ b := sha256.Sum256([]byte(ka))
+ h := hex.EncodeToString(b[:])
+ name = fmt.Sprintf("%s.%s.acme.invalid", h[:32], h[32:])
+ cert, err = tlsChallengeCert([]string{name}, opt)
+ if err != nil {
+ return tls.Certificate{}, "", err
+ }
+ return cert, name, nil
+}
+
+// TLSSNI02ChallengeCert creates a certificate for TLS-SNI-02 challenge response.
+// Servers can present the certificate to validate the challenge and prove control
+// over a domain name. For more details on TLS-SNI-02 see
+// https://tools.ietf.org/html/draft-ietf-acme-acme-03#section-7.3.
+//
+// The token argument is a Challenge.Token value.
+// If a WithKey option is provided, its private part signs the returned cert,
+// and the public part is used to specify the signee.
+// If no WithKey option is provided, a new ECDSA key is generated using P-256 curve.
+//
+// The returned certificate is valid for the next 24 hours and must be presented only when
+// the server name in the TLS ClientHello matches exactly the returned name value.
+func (c *Client) TLSSNI02ChallengeCert(token string, opt ...CertOption) (cert tls.Certificate, name string, err error) {
+ b := sha256.Sum256([]byte(token))
+ h := hex.EncodeToString(b[:])
+ sanA := fmt.Sprintf("%s.%s.token.acme.invalid", h[:32], h[32:])
+
+ ka, err := keyAuth(c.Key.Public(), token)
+ if err != nil {
+ return tls.Certificate{}, "", err
+ }
+ b = sha256.Sum256([]byte(ka))
+ h = hex.EncodeToString(b[:])
+ sanB := fmt.Sprintf("%s.%s.ka.acme.invalid", h[:32], h[32:])
+
+ cert, err = tlsChallengeCert([]string{sanA, sanB}, opt)
+ if err != nil {
+ return tls.Certificate{}, "", err
+ }
+ return cert, sanA, nil
+}
+
+// TLSALPN01ChallengeCert creates a certificate for TLS-ALPN-01 challenge response.
+// Servers can present the certificate to validate the challenge and prove control
+// over a domain name. For more details on TLS-ALPN-01 see
+// https://tools.ietf.org/html/draft-shoemaker-acme-tls-alpn-00#section-3
+//
+// The token argument is a Challenge.Token value.
+// If a WithKey option is provided, its private part signs the returned cert,
+// and the public part is used to specify the signee.
+// If no WithKey option is provided, a new ECDSA key is generated using P-256 curve.
+//
+// The returned certificate is valid for the next 24 hours and must be presented only when
+// the server name in the TLS ClientHello matches the domain, and the special acme-tls/1 ALPN protocol
+// has been specified.
+func (c *Client) TLSALPN01ChallengeCert(token, domain string, opt ...CertOption) (cert tls.Certificate, err error) {
+ ka, err := keyAuth(c.Key.Public(), token)
+ if err != nil {
+ return tls.Certificate{}, err
+ }
+ shasum := sha256.Sum256([]byte(ka))
+ extValue, err := asn1.Marshal(shasum[:])
+ if err != nil {
+ return tls.Certificate{}, err
+ }
+ acmeExtension := pkix.Extension{
+ Id: idPeACMEIdentifierV1,
+ Critical: true,
+ Value: extValue,
+ }
+
+ tmpl := defaultTLSChallengeCertTemplate()
+
+ var newOpt []CertOption
+ for _, o := range opt {
+ switch o := o.(type) {
+ case *certOptTemplate:
+ t := *(*x509.Certificate)(o) // shallow copy is ok
+ tmpl = &t
+ default:
+ newOpt = append(newOpt, o)
+ }
+ }
+ tmpl.ExtraExtensions = append(tmpl.ExtraExtensions, acmeExtension)
+ newOpt = append(newOpt, WithTemplate(tmpl))
+ return tlsChallengeCert([]string{domain}, newOpt)
+}
+
+// doReg sends all types of registration requests.
+// The type of request is identified by typ argument, which is a "resource"
+// in the ACME spec terms.
+//
+// A non-nil acct argument indicates whether the intention is to mutate data
+// of the Account. Only Contact and Agreement of its fields are used
+// in such cases.
+func (c *Client) doReg(ctx context.Context, url string, typ string, acct *Account) (*Account, error) {
+ req := struct {
+ Resource string `json:"resource"`
+ Contact []string `json:"contact,omitempty"`
+ Agreement string `json:"agreement,omitempty"`
+ }{
+ Resource: typ,
+ }
+ if acct != nil {
+ req.Contact = acct.Contact
+ req.Agreement = acct.AgreedTerms
+ }
+ res, err := c.post(ctx, c.Key, url, req, wantStatus(
+ http.StatusOK, // updates and deletes
+ http.StatusCreated, // new account creation
+ http.StatusAccepted, // Let's Encrypt divergent implementation
+ ))
+ if err != nil {
+ return nil, err
+ }
+ defer res.Body.Close()
+
+ var v struct {
+ Contact []string
+ Agreement string
+ Authorizations string
+ Certificates string
+ }
+ if err := json.NewDecoder(res.Body).Decode(&v); err != nil {
+ return nil, fmt.Errorf("acme: invalid response: %v", err)
+ }
+ var tos string
+ if v := linkHeader(res.Header, "terms-of-service"); len(v) > 0 {
+ tos = v[0]
+ }
+ var authz string
+ if v := linkHeader(res.Header, "next"); len(v) > 0 {
+ authz = v[0]
+ }
+ return &Account{
+ URI: res.Header.Get("Location"),
+ Contact: v.Contact,
+ AgreedTerms: v.Agreement,
+ CurrentTerms: tos,
+ Authz: authz,
+ Authorizations: v.Authorizations,
+ Certificates: v.Certificates,
+ }, nil
+}
+
+// popNonce returns a nonce value previously stored with c.addNonce
+// or fetches a fresh one from the given URL.
+func (c *Client) popNonce(ctx context.Context, url string) (string, error) {
+ c.noncesMu.Lock()
+ defer c.noncesMu.Unlock()
+ if len(c.nonces) == 0 {
+ return c.fetchNonce(ctx, url)
+ }
+ var nonce string
+ for nonce = range c.nonces {
+ delete(c.nonces, nonce)
+ break
+ }
+ return nonce, nil
+}
+
+// clearNonces clears any stored nonces
+func (c *Client) clearNonces() {
+ c.noncesMu.Lock()
+ defer c.noncesMu.Unlock()
+ c.nonces = make(map[string]struct{})
+}
+
+// addNonce stores a nonce value found in h (if any) for future use.
+func (c *Client) addNonce(h http.Header) {
+ v := nonceFromHeader(h)
+ if v == "" {
+ return
+ }
+ c.noncesMu.Lock()
+ defer c.noncesMu.Unlock()
+ if len(c.nonces) >= maxNonces {
+ return
+ }
+ if c.nonces == nil {
+ c.nonces = make(map[string]struct{})
+ }
+ c.nonces[v] = struct{}{}
+}
+
+func (c *Client) fetchNonce(ctx context.Context, url string) (string, error) {
+ r, err := http.NewRequest("HEAD", url, nil)
+ if err != nil {
+ return "", err
+ }
+ resp, err := c.doNoRetry(ctx, r)
+ if err != nil {
+ return "", err
+ }
+ defer resp.Body.Close()
+ nonce := nonceFromHeader(resp.Header)
+ if nonce == "" {
+ if resp.StatusCode > 299 {
+ return "", responseError(resp)
+ }
+ return "", errors.New("acme: nonce not found")
+ }
+ return nonce, nil
+}
+
+func nonceFromHeader(h http.Header) string {
+ return h.Get("Replay-Nonce")
+}
+
+func (c *Client) responseCert(ctx context.Context, res *http.Response, bundle bool) ([][]byte, error) {
+ b, err := ioutil.ReadAll(io.LimitReader(res.Body, maxCertSize+1))
+ if err != nil {
+ return nil, fmt.Errorf("acme: response stream: %v", err)
+ }
+ if len(b) > maxCertSize {
+ return nil, errors.New("acme: certificate is too big")
+ }
+ cert := [][]byte{b}
+ if !bundle {
+ return cert, nil
+ }
+
+ // Append CA chain cert(s).
+ // At least one is required according to the spec:
+ // https://tools.ietf.org/html/draft-ietf-acme-acme-03#section-6.3.1
+ up := linkHeader(res.Header, "up")
+ if len(up) == 0 {
+ return nil, errors.New("acme: rel=up link not found")
+ }
+ if len(up) > maxChainLen {
+ return nil, errors.New("acme: rel=up link is too large")
+ }
+ for _, url := range up {
+ cc, err := c.chainCert(ctx, url, 0)
+ if err != nil {
+ return nil, err
+ }
+ cert = append(cert, cc...)
+ }
+ return cert, nil
+}
+
+// chainCert fetches CA certificate chain recursively by following "up" links.
+// Each recursive call increments the depth by 1, resulting in an error
+// if the recursion level reaches maxChainLen.
+//
+// First chainCert call starts with depth of 0.
+func (c *Client) chainCert(ctx context.Context, url string, depth int) ([][]byte, error) {
+ if depth >= maxChainLen {
+ return nil, errors.New("acme: certificate chain is too deep")
+ }
+
+ res, err := c.get(ctx, url, wantStatus(http.StatusOK))
+ if err != nil {
+ return nil, err
+ }
+ defer res.Body.Close()
+ b, err := ioutil.ReadAll(io.LimitReader(res.Body, maxCertSize+1))
+ if err != nil {
+ return nil, err
+ }
+ if len(b) > maxCertSize {
+ return nil, errors.New("acme: certificate is too big")
+ }
+ chain := [][]byte{b}
+
+ uplink := linkHeader(res.Header, "up")
+ if len(uplink) > maxChainLen {
+ return nil, errors.New("acme: certificate chain is too large")
+ }
+ for _, up := range uplink {
+ cc, err := c.chainCert(ctx, up, depth+1)
+ if err != nil {
+ return nil, err
+ }
+ chain = append(chain, cc...)
+ }
+
+ return chain, nil
+}
+
+// linkHeader returns URI-Reference values of all Link headers
+// with relation-type rel.
+// See https://tools.ietf.org/html/rfc5988#section-5 for details.
+func linkHeader(h http.Header, rel string) []string {
+ var links []string
+ for _, v := range h["Link"] {
+ parts := strings.Split(v, ";")
+ for _, p := range parts {
+ p = strings.TrimSpace(p)
+ if !strings.HasPrefix(p, "rel=") {
+ continue
+ }
+ if v := strings.Trim(p[4:], `"`); v == rel {
+ links = append(links, strings.Trim(parts[0], "<>"))
+ }
+ }
+ }
+ return links
+}
+
+// keyAuth generates a key authorization string for a given token.
+func keyAuth(pub crypto.PublicKey, token string) (string, error) {
+ th, err := JWKThumbprint(pub)
+ if err != nil {
+ return "", err
+ }
+ return fmt.Sprintf("%s.%s", token, th), nil
+}
+
+// defaultTLSChallengeCertTemplate is a template used to create challenge certs for TLS challenges.
+func defaultTLSChallengeCertTemplate() *x509.Certificate {
+ return &x509.Certificate{
+ SerialNumber: big.NewInt(1),
+ NotBefore: time.Now(),
+ NotAfter: time.Now().Add(24 * time.Hour),
+ BasicConstraintsValid: true,
+ KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature,
+ ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
+ }
+}
+
+// tlsChallengeCert creates a temporary certificate for TLS-SNI challenges
+// with the given SANs and auto-generated public/private key pair.
+// The Subject Common Name is set to the first SAN to aid debugging.
+// To create a cert with a custom key pair, specify WithKey option.
+func tlsChallengeCert(san []string, opt []CertOption) (tls.Certificate, error) {
+ var key crypto.Signer
+ tmpl := defaultTLSChallengeCertTemplate()
+ for _, o := range opt {
+ switch o := o.(type) {
+ case *certOptKey:
+ if key != nil {
+ return tls.Certificate{}, errors.New("acme: duplicate key option")
+ }
+ key = o.key
+ case *certOptTemplate:
+ t := *(*x509.Certificate)(o) // shallow copy is ok
+ tmpl = &t
+ default:
+ // package's fault, if we let this happen:
+ panic(fmt.Sprintf("unsupported option type %T", o))
+ }
+ }
+ if key == nil {
+ var err error
+ if key, err = ecdsa.GenerateKey(elliptic.P256(), rand.Reader); err != nil {
+ return tls.Certificate{}, err
+ }
+ }
+ tmpl.DNSNames = san
+ if len(san) > 0 {
+ tmpl.Subject.CommonName = san[0]
+ }
+
+ der, err := x509.CreateCertificate(rand.Reader, tmpl, tmpl, key.Public(), key)
+ if err != nil {
+ return tls.Certificate{}, err
+ }
+ return tls.Certificate{
+ Certificate: [][]byte{der},
+ PrivateKey: key,
+ }, nil
+}
+
+// encodePEM returns b encoded as PEM with block of type typ.
+func encodePEM(typ string, b []byte) []byte {
+ pb := &pem.Block{Type: typ, Bytes: b}
+ return pem.EncodeToMemory(pb)
+}
+
+// timeNow is useful for testing for fixed current time.
+var timeNow = time.Now
diff --git a/src/dma/vendor/golang.org/x/crypto/acme/autocert/autocert.go b/src/dma/vendor/golang.org/x/crypto/acme/autocert/autocert.go
new file mode 100644
index 00000000..4c2fc072
--- /dev/null
+++ b/src/dma/vendor/golang.org/x/crypto/acme/autocert/autocert.go
@@ -0,0 +1,1139 @@
+// Copyright 2016 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Package autocert provides automatic access to certificates from Let's Encrypt
+// and any other ACME-based CA.
+//
+// This package is a work in progress and makes no API stability promises.
+package autocert
+
+import (
+ "bytes"
+ "context"
+ "crypto"
+ "crypto/ecdsa"
+ "crypto/elliptic"
+ "crypto/rand"
+ "crypto/rsa"
+ "crypto/tls"
+ "crypto/x509"
+ "crypto/x509/pkix"
+ "encoding/pem"
+ "errors"
+ "fmt"
+ "io"
+ mathrand "math/rand"
+ "net"
+ "net/http"
+ "path"
+ "strings"
+ "sync"
+ "time"
+
+ "golang.org/x/crypto/acme"
+)
+
+// createCertRetryAfter is how much time to wait before removing a failed state
+// entry due to an unsuccessful createCert call.
+// This is a variable instead of a const for testing.
+// TODO: Consider making it configurable or an exp backoff?
+var createCertRetryAfter = time.Minute
+
+// pseudoRand is safe for concurrent use.
+var pseudoRand *lockedMathRand
+
+func init() {
+ src := mathrand.NewSource(time.Now().UnixNano())
+ pseudoRand = &lockedMathRand{rnd: mathrand.New(src)}
+}
+
+// AcceptTOS is a Manager.Prompt function that always returns true to
+// indicate acceptance of the CA's Terms of Service during account
+// registration.
+func AcceptTOS(tosURL string) bool { return true }
+
+// HostPolicy specifies which host names the Manager is allowed to respond to.
+// It returns a non-nil error if the host should be rejected.
+// The returned error is accessible via tls.Conn.Handshake and its callers.
+// See Manager's HostPolicy field and GetCertificate method docs for more details.
+type HostPolicy func(ctx context.Context, host string) error
+
+// HostWhitelist returns a policy where only the specified host names are allowed.
+// Only exact matches are currently supported. Subdomains, regexp or wildcard
+// will not match.
+func HostWhitelist(hosts ...string) HostPolicy {
+ whitelist := make(map[string]bool, len(hosts))
+ for _, h := range hosts {
+ whitelist[h] = true
+ }
+ return func(_ context.Context, host string) error {
+ if !whitelist[host] {
+ return errors.New("acme/autocert: host not configured")
+ }
+ return nil
+ }
+}
+
+// defaultHostPolicy is used when Manager.HostPolicy is not set.
+func defaultHostPolicy(context.Context, string) error {
+ return nil
+}
+
+// Manager is a stateful certificate manager built on top of acme.Client.
+// It obtains and refreshes certificates automatically using "tls-alpn-01",
+// "tls-sni-01", "tls-sni-02" and "http-01" challenge types,
+// as well as providing them to a TLS server via tls.Config.
+//
+// You must specify a cache implementation, such as DirCache,
+// to reuse obtained certificates across program restarts.
+// Otherwise your server is very likely to exceed the certificate
+// issuer's request rate limits.
+type Manager struct {
+ // Prompt specifies a callback function to conditionally accept a CA's Terms of Service (TOS).
+ // The registration may require the caller to agree to the CA's TOS.
+ // If so, Manager calls Prompt with a TOS URL provided by the CA. Prompt should report
+ // whether the caller agrees to the terms.
+ //
+ // To always accept the terms, the callers can use AcceptTOS.
+ Prompt func(tosURL string) bool
+
+ // Cache optionally stores and retrieves previously-obtained certificates
+ // and other state. If nil, certs will only be cached for the lifetime of
+ // the Manager. Multiple Managers can share the same Cache.
+ //
+ // Using a persistent Cache, such as DirCache, is strongly recommended.
+ Cache Cache
+
+ // HostPolicy controls which domains the Manager will attempt
+ // to retrieve new certificates for. It does not affect cached certs.
+ //
+ // If non-nil, HostPolicy is called before requesting a new cert.
+ // If nil, all hosts are currently allowed. This is not recommended,
+ // as it opens a potential attack where clients connect to a server
+ // by IP address and pretend to be asking for an incorrect host name.
+ // Manager will attempt to obtain a certificate for that host, incorrectly,
+ // eventually reaching the CA's rate limit for certificate requests
+ // and making it impossible to obtain actual certificates.
+ //
+ // See GetCertificate for more details.
+ HostPolicy HostPolicy
+
+ // RenewBefore optionally specifies how early certificates should
+ // be renewed before they expire.
+ //
+ // If zero, they're renewed 30 days before expiration.
+ RenewBefore time.Duration
+
+ // Client is used to perform low-level operations, such as account registration
+ // and requesting new certificates.
+ //
+ // If Client is nil, a zero-value acme.Client is used with acme.LetsEncryptURL
+ // as directory endpoint. If the Client.Key is nil, a new ECDSA P-256 key is
+ // generated and, if Cache is not nil, stored in cache.
+ //
+ // Mutating the field after the first call of GetCertificate method will have no effect.
+ Client *acme.Client
+
+ // Email optionally specifies a contact email address.
+ // This is used by CAs, such as Let's Encrypt, to notify about problems
+ // with issued certificates.
+ //
+ // If the Client's account key is already registered, Email is not used.
+ Email string
+
+ // ForceRSA used to make the Manager generate RSA certificates. It is now ignored.
+ //
+ // Deprecated: the Manager will request the correct type of certificate based
+ // on what each client supports.
+ ForceRSA bool
+
+ // ExtraExtensions are used when generating a new CSR (Certificate Request),
+ // thus allowing customization of the resulting certificate.
+ // For instance, TLS Feature Extension (RFC 7633) can be used
+ // to prevent an OCSP downgrade attack.
+ //
+ // The field value is passed to crypto/x509.CreateCertificateRequest
+ // in the template's ExtraExtensions field as is.
+ ExtraExtensions []pkix.Extension
+
+ clientMu sync.Mutex
+ client *acme.Client // initialized by acmeClient method
+
+ stateMu sync.Mutex
+ state map[certKey]*certState
+
+ // renewal tracks the set of domains currently running renewal timers.
+ renewalMu sync.Mutex
+ renewal map[certKey]*domainRenewal
+
+ // tokensMu guards the rest of the fields: tryHTTP01, certTokens and httpTokens.
+ tokensMu sync.RWMutex
+ // tryHTTP01 indicates whether the Manager should try "http-01" challenge type
+ // during the authorization flow.
+ tryHTTP01 bool
+ // httpTokens contains response body values for http-01 challenges
+ // and is keyed by the URL path at which a challenge response is expected
+ // to be provisioned.
+ // The entries are stored for the duration of the authorization flow.
+ httpTokens map[string][]byte
+ // certTokens contains temporary certificates for tls-sni and tls-alpn challenges
+ // and is keyed by token domain name, which matches server name of ClientHello.
+ // Keys always have ".acme.invalid" suffix for tls-sni. Otherwise, they are domain names
+ // for tls-alpn.
+ // The entries are stored for the duration of the authorization flow.
+ certTokens map[string]*tls.Certificate
+ // nowFunc, if not nil, returns the current time. This may be set for
+ // testing purposes.
+ nowFunc func() time.Time
+}
+
+// certKey is the key by which certificates are tracked in state, renewal and cache.
+type certKey struct {
+ domain string // without trailing dot
+ isRSA bool // RSA cert for legacy clients (as opposed to default ECDSA)
+ isToken bool // tls-based challenge token cert; key type is undefined regardless of isRSA
+}
+
+func (c certKey) String() string {
+ if c.isToken {
+ return c.domain + "+token"
+ }
+ if c.isRSA {
+ return c.domain + "+rsa"
+ }
+ return c.domain
+}
+
+// TLSConfig creates a new TLS config suitable for net/http.Server servers,
+// supporting HTTP/2 and the tls-alpn-01 ACME challenge type.
+func (m *Manager) TLSConfig() *tls.Config {
+ return &tls.Config{
+ GetCertificate: m.GetCertificate,
+ NextProtos: []string{
+ "h2", "http/1.1", // enable HTTP/2
+ acme.ALPNProto, // enable tls-alpn ACME challenges
+ },
+ }
+}
+
+// GetCertificate implements the tls.Config.GetCertificate hook.
+// It provides a TLS certificate for hello.ServerName host, including answering
+// tls-alpn-01 and *.acme.invalid (tls-sni-01 and tls-sni-02) challenges.
+// All other fields of hello are ignored.
+//
+// If m.HostPolicy is non-nil, GetCertificate calls the policy before requesting
+// a new cert. A non-nil error returned from m.HostPolicy halts TLS negotiation.
+// The error is propagated back to the caller of GetCertificate and is user-visible.
+// This does not affect cached certs. See HostPolicy field description for more details.
+//
+// If GetCertificate is used directly, instead of via Manager.TLSConfig, package users will
+// also have to add acme.ALPNProto to NextProtos for tls-alpn-01, or use HTTPHandler
+// for http-01. (The tls-sni-* challenges have been deprecated by popular ACME providers
+// due to security issues in the ecosystem.)
+func (m *Manager) GetCertificate(hello *tls.ClientHelloInfo) (*tls.Certificate, error) {
+ if m.Prompt == nil {
+ return nil, errors.New("acme/autocert: Manager.Prompt not set")
+ }
+
+ name := hello.ServerName
+ if name == "" {
+ return nil, errors.New("acme/autocert: missing server name")
+ }
+ if !strings.Contains(strings.Trim(name, "."), ".") {
+ return nil, errors.New("acme/autocert: server name component count invalid")
+ }
+ if strings.ContainsAny(name, `+/\`) {
+ return nil, errors.New("acme/autocert: server name contains invalid character")
+ }
+
+ // In the worst-case scenario, the timeout needs to account for caching, host policy,
+ // domain ownership verification and certificate issuance.
+ ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
+ defer cancel()
+
+ // Check whether this is a token cert requested for TLS-SNI or TLS-ALPN challenge.
+ if wantsTokenCert(hello) {
+ m.tokensMu.RLock()
+ defer m.tokensMu.RUnlock()
+ // It's ok to use the same token cert key for both tls-sni and tls-alpn
+ // because there's always at most 1 token cert per on-going domain authorization.
+ // See m.verify for details.
+ if cert := m.certTokens[name]; cert != nil {
+ return cert, nil
+ }
+ if cert, err := m.cacheGet(ctx, certKey{domain: name, isToken: true}); err == nil {
+ return cert, nil
+ }
+ // TODO: cache error results?
+ return nil, fmt.Errorf("acme/autocert: no token cert for %q", name)
+ }
+
+ // regular domain
+ ck := certKey{
+ domain: strings.TrimSuffix(name, "."), // golang.org/issue/18114
+ isRSA: !supportsECDSA(hello),
+ }
+ cert, err := m.cert(ctx, ck)
+ if err == nil {
+ return cert, nil
+ }
+ if err != ErrCacheMiss {
+ return nil, err
+ }
+
+ // first-time
+ if err := m.hostPolicy()(ctx, name); err != nil {
+ return nil, err
+ }
+ cert, err = m.createCert(ctx, ck)
+ if err != nil {
+ return nil, err
+ }
+ m.cachePut(ctx, ck, cert)
+ return cert, nil
+}
+
+// wantsTokenCert reports whether a TLS request with SNI is made by a CA server
+// for a challenge verification.
+func wantsTokenCert(hello *tls.ClientHelloInfo) bool {
+ // tls-alpn-01
+ if len(hello.SupportedProtos) == 1 && hello.SupportedProtos[0] == acme.ALPNProto {
+ return true
+ }
+ // tls-sni-xx
+ return strings.HasSuffix(hello.ServerName, ".acme.invalid")
+}
+
+func supportsECDSA(hello *tls.ClientHelloInfo) bool {
+ // The "signature_algorithms" extension, if present, limits the key exchange
+ // algorithms allowed by the cipher suites. See RFC 5246, section 7.4.1.4.1.
+ if hello.SignatureSchemes != nil {
+ ecdsaOK := false
+ schemeLoop:
+ for _, scheme := range hello.SignatureSchemes {
+ const tlsECDSAWithSHA1 tls.SignatureScheme = 0x0203 // constant added in Go 1.10
+ switch scheme {
+ case tlsECDSAWithSHA1, tls.ECDSAWithP256AndSHA256,
+ tls.ECDSAWithP384AndSHA384, tls.ECDSAWithP521AndSHA512:
+ ecdsaOK = true
+ break schemeLoop
+ }
+ }
+ if !ecdsaOK {
+ return false
+ }
+ }
+ if hello.SupportedCurves != nil {
+ ecdsaOK := false
+ for _, curve := range hello.SupportedCurves {
+ if curve == tls.CurveP256 {
+ ecdsaOK = true
+ break
+ }
+ }
+ if !ecdsaOK {
+ return false
+ }
+ }
+ for _, suite := range hello.CipherSuites {
+ switch suite {
+ case tls.TLS_ECDHE_ECDSA_WITH_RC4_128_SHA,
+ tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
+ tls.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA,
+ tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256,
+ tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
+ tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
+ tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305:
+ return true
+ }
+ }
+ return false
+}
+
+// HTTPHandler configures the Manager to provision ACME "http-01" challenge responses.
+// It returns an http.Handler that responds to the challenges and must be
+// running on port 80. If it receives a request that is not an ACME challenge,
+// it delegates the request to the optional fallback handler.
+//
+// If fallback is nil, the returned handler redirects all GET and HEAD requests
+// to the default TLS port 443 with 302 Found status code, preserving the original
+// request path and query. It responds with 400 Bad Request to all other HTTP methods.
+// The fallback is not protected by the optional HostPolicy.
+//
+// Because the fallback handler is run with unencrypted port 80 requests,
+// the fallback should not serve TLS-only requests.
+//
+// If HTTPHandler is never called, the Manager will only use the "tls-alpn-01"
+// challenge for domain verification.
+func (m *Manager) HTTPHandler(fallback http.Handler) http.Handler {
+ m.tokensMu.Lock()
+ defer m.tokensMu.Unlock()
+ m.tryHTTP01 = true
+
+ if fallback == nil {
+ fallback = http.HandlerFunc(handleHTTPRedirect)
+ }
+ return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ if !strings.HasPrefix(r.URL.Path, "/.well-known/acme-challenge/") {
+ fallback.ServeHTTP(w, r)
+ return
+ }
+ // A reasonable context timeout for cache and host policy only,
+ // because we don't wait for a new certificate issuance here.
+ ctx, cancel := context.WithTimeout(r.Context(), time.Minute)
+ defer cancel()
+ if err := m.hostPolicy()(ctx, r.Host); err != nil {
+ http.Error(w, err.Error(), http.StatusForbidden)
+ return
+ }
+ data, err := m.httpToken(ctx, r.URL.Path)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusNotFound)
+ return
+ }
+ w.Write(data)
+ })
+}
+
+func handleHTTPRedirect(w http.ResponseWriter, r *http.Request) {
+ if r.Method != "GET" && r.Method != "HEAD" {
+ http.Error(w, "Use HTTPS", http.StatusBadRequest)
+ return
+ }
+ target := "https://" + stripPort(r.Host) + r.URL.RequestURI()
+ http.Redirect(w, r, target, http.StatusFound)
+}
+
+func stripPort(hostport string) string {
+ host, _, err := net.SplitHostPort(hostport)
+ if err != nil {
+ return hostport
+ }
+ return net.JoinHostPort(host, "443")
+}
+
+// cert returns an existing certificate either from m.state or cache.
+// If a certificate is found in cache but not in m.state, the latter will be filled
+// with the cached value.
+func (m *Manager) cert(ctx context.Context, ck certKey) (*tls.Certificate, error) {
+ m.stateMu.Lock()
+ if s, ok := m.state[ck]; ok {
+ m.stateMu.Unlock()
+ s.RLock()
+ defer s.RUnlock()
+ return s.tlscert()
+ }
+ defer m.stateMu.Unlock()
+ cert, err := m.cacheGet(ctx, ck)
+ if err != nil {
+ return nil, err
+ }
+ signer, ok := cert.PrivateKey.(crypto.Signer)
+ if !ok {
+ return nil, errors.New("acme/autocert: private key cannot sign")
+ }
+ if m.state == nil {
+ m.state = make(map[certKey]*certState)
+ }
+ s := &certState{
+ key: signer,
+ cert: cert.Certificate,
+ leaf: cert.Leaf,
+ }
+ m.state[ck] = s
+ go m.renew(ck, s.key, s.leaf.NotAfter)
+ return cert, nil
+}
+
+// cacheGet always returns a valid certificate, or an error otherwise.
+// If a cached certificate exists but is not valid, ErrCacheMiss is returned.
+func (m *Manager) cacheGet(ctx context.Context, ck certKey) (*tls.Certificate, error) {
+ if m.Cache == nil {
+ return nil, ErrCacheMiss
+ }
+ data, err := m.Cache.Get(ctx, ck.String())
+ if err != nil {
+ return nil, err
+ }
+
+ // private
+ priv, pub := pem.Decode(data)
+ if priv == nil || !strings.Contains(priv.Type, "PRIVATE") {
+ return nil, ErrCacheMiss
+ }
+ privKey, err := parsePrivateKey(priv.Bytes)
+ if err != nil {
+ return nil, err
+ }
+
+ // public
+ var pubDER [][]byte
+ for len(pub) > 0 {
+ var b *pem.Block
+ b, pub = pem.Decode(pub)
+ if b == nil {
+ break
+ }
+ pubDER = append(pubDER, b.Bytes)
+ }
+ if len(pub) > 0 {
+ // Leftover content not consumed by pem.Decode. Corrupt. Ignore.
+ return nil, ErrCacheMiss
+ }
+
+ // verify and create TLS cert
+ leaf, err := validCert(ck, pubDER, privKey, m.now())
+ if err != nil {
+ return nil, ErrCacheMiss
+ }
+ tlscert := &tls.Certificate{
+ Certificate: pubDER,
+ PrivateKey: privKey,
+ Leaf: leaf,
+ }
+ return tlscert, nil
+}
+
+func (m *Manager) cachePut(ctx context.Context, ck certKey, tlscert *tls.Certificate) error {
+ if m.Cache == nil {
+ return nil
+ }
+
+ // contains PEM-encoded data
+ var buf bytes.Buffer
+
+ // private
+ switch key := tlscert.PrivateKey.(type) {
+ case *ecdsa.PrivateKey:
+ if err := encodeECDSAKey(&buf, key); err != nil {
+ return err
+ }
+ case *rsa.PrivateKey:
+ b := x509.MarshalPKCS1PrivateKey(key)
+ pb := &pem.Block{Type: "RSA PRIVATE KEY", Bytes: b}
+ if err := pem.Encode(&buf, pb); err != nil {
+ return err
+ }
+ default:
+ return errors.New("acme/autocert: unknown private key type")
+ }
+
+ // public
+ for _, b := range tlscert.Certificate {
+ pb := &pem.Block{Type: "CERTIFICATE", Bytes: b}
+ if err := pem.Encode(&buf, pb); err != nil {
+ return err
+ }
+ }
+
+ return m.Cache.Put(ctx, ck.String(), buf.Bytes())
+}
+
+func encodeECDSAKey(w io.Writer, key *ecdsa.PrivateKey) error {
+ b, err := x509.MarshalECPrivateKey(key)
+ if err != nil {
+ return err
+ }
+ pb := &pem.Block{Type: "EC PRIVATE KEY", Bytes: b}
+ return pem.Encode(w, pb)
+}
+
+// createCert starts the domain ownership verification and returns a certificate
+// for that domain upon success.
+//
+// If the domain is already being verified, it waits for the existing verification to complete.
+// Either way, createCert blocks for the duration of the whole process.
+func (m *Manager) createCert(ctx context.Context, ck certKey) (*tls.Certificate, error) {
+ // TODO: maybe rewrite this whole piece using sync.Once
+ state, err := m.certState(ck)
+ if err != nil {
+ return nil, err
+ }
+ // state may exist if another goroutine is already working on it
+ // in which case just wait for it to finish
+ if !state.locked {
+ state.RLock()
+ defer state.RUnlock()
+ return state.tlscert()
+ }
+
+ // We are the first; state is locked.
+ // Unblock the readers when domain ownership is verified
+ // and we got the cert or the process failed.
+ defer state.Unlock()
+ state.locked = false
+
+ der, leaf, err := m.authorizedCert(ctx, state.key, ck)
+ if err != nil {
+ // Remove the failed state after some time,
+ // making the manager call createCert again on the following TLS hello.
+ time.AfterFunc(createCertRetryAfter, func() {
+ defer testDidRemoveState(ck)
+ m.stateMu.Lock()
+ defer m.stateMu.Unlock()
+ // Verify the state hasn't changed and it's still invalid
+ // before deleting.
+ s, ok := m.state[ck]
+ if !ok {
+ return
+ }
+ if _, err := validCert(ck, s.cert, s.key, m.now()); err == nil {
+ return
+ }
+ delete(m.state, ck)
+ })
+ return nil, err
+ }
+ state.cert = der
+ state.leaf = leaf
+ go m.renew(ck, state.key, state.leaf.NotAfter)
+ return state.tlscert()
+}
+
+// certState returns a new or existing certState.
+// If a new certState is returned, state.exist is false and the state is locked.
+// The returned error is non-nil only in the case where a new state could not be created.
+func (m *Manager) certState(ck certKey) (*certState, error) {
+ m.stateMu.Lock()
+ defer m.stateMu.Unlock()
+ if m.state == nil {
+ m.state = make(map[certKey]*certState)
+ }
+ // existing state
+ if state, ok := m.state[ck]; ok {
+ return state, nil
+ }
+
+ // new locked state
+ var (
+ err error
+ key crypto.Signer
+ )
+ if ck.isRSA {
+ key, err = rsa.GenerateKey(rand.Reader, 2048)
+ } else {
+ key, err = ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
+ }
+ if err != nil {
+ return nil, err
+ }
+
+ state := &certState{
+ key: key,
+ locked: true,
+ }
+ state.Lock() // will be unlocked by m.certState caller
+ m.state[ck] = state
+ return state, nil
+}
+
+// authorizedCert starts the domain ownership verification process and requests a new cert upon success.
+// The key argument is the certificate private key.
+func (m *Manager) authorizedCert(ctx context.Context, key crypto.Signer, ck certKey) (der [][]byte, leaf *x509.Certificate, err error) {
+ client, err := m.acmeClient(ctx)
+ if err != nil {
+ return nil, nil, err
+ }
+
+ if err := m.verify(ctx, client, ck.domain); err != nil {
+ return nil, nil, err
+ }
+ csr, err := certRequest(key, ck.domain, m.ExtraExtensions)
+ if err != nil {
+ return nil, nil, err
+ }
+ der, _, err = client.CreateCert(ctx, csr, 0, true)
+ if err != nil {
+ return nil, nil, err
+ }
+ leaf, err = validCert(ck, der, key, m.now())
+ if err != nil {
+ return nil, nil, err
+ }
+ return der, leaf, nil
+}
+
+// revokePendingAuthz revokes all authorizations idenfied by the elements of uri slice.
+// It ignores revocation errors.
+func (m *Manager) revokePendingAuthz(ctx context.Context, uri []string) {
+ client, err := m.acmeClient(ctx)
+ if err != nil {
+ return
+ }
+ for _, u := range uri {
+ client.RevokeAuthorization(ctx, u)
+ }
+}
+
+// verify runs the identifier (domain) authorization flow
+// using each applicable ACME challenge type.
+func (m *Manager) verify(ctx context.Context, client *acme.Client, domain string) error {
+ // The list of challenge types we'll try to fulfill
+ // in this specific order.
+ challengeTypes := []string{"tls-alpn-01", "tls-sni-02", "tls-sni-01"}
+ m.tokensMu.RLock()
+ if m.tryHTTP01 {
+ challengeTypes = append(challengeTypes, "http-01")
+ }
+ m.tokensMu.RUnlock()
+
+ // Keep track of pending authzs and revoke the ones that did not validate.
+ pendingAuthzs := make(map[string]bool)
+ defer func() {
+ var uri []string
+ for k, pending := range pendingAuthzs {
+ if pending {
+ uri = append(uri, k)
+ }
+ }
+ if len(uri) > 0 {
+ // Use "detached" background context.
+ // The revocations need not happen in the current verification flow.
+ go m.revokePendingAuthz(context.Background(), uri)
+ }
+ }()
+
+ // errs accumulates challenge failure errors, printed if all fail
+ errs := make(map[*acme.Challenge]error)
+ var nextTyp int // challengeType index of the next challenge type to try
+ for {
+ // Start domain authorization and get the challenge.
+ authz, err := client.Authorize(ctx, domain)
+ if err != nil {
+ return err
+ }
+ // No point in accepting challenges if the authorization status
+ // is in a final state.
+ switch authz.Status {
+ case acme.StatusValid:
+ return nil // already authorized
+ case acme.StatusInvalid:
+ return fmt.Errorf("acme/autocert: invalid authorization %q", authz.URI)
+ }
+
+ pendingAuthzs[authz.URI] = true
+
+ // Pick the next preferred challenge.
+ var chal *acme.Challenge
+ for chal == nil && nextTyp < len(challengeTypes) {
+ chal = pickChallenge(challengeTypes[nextTyp], authz.Challenges)
+ nextTyp++
+ }
+ if chal == nil {
+ errorMsg := fmt.Sprintf("acme/autocert: unable to authorize %q", domain)
+ for chal, err := range errs {
+ errorMsg += fmt.Sprintf("; challenge %q failed with error: %v", chal.Type, err)
+ }
+ return errors.New(errorMsg)
+ }
+ cleanup, err := m.fulfill(ctx, client, chal, domain)
+ if err != nil {
+ errs[chal] = err
+ continue
+ }
+ defer cleanup()
+ if _, err := client.Accept(ctx, chal); err != nil {
+ errs[chal] = err
+ continue
+ }
+
+ // A challenge is fulfilled and accepted: wait for the CA to validate.
+ if _, err := client.WaitAuthorization(ctx, authz.URI); err != nil {
+ errs[chal] = err
+ continue
+ }
+ delete(pendingAuthzs, authz.URI)
+ return nil
+ }
+}
+
+// fulfill provisions a response to the challenge chal.
+// The cleanup is non-nil only if provisioning succeeded.
+func (m *Manager) fulfill(ctx context.Context, client *acme.Client, chal *acme.Challenge, domain string) (cleanup func(), err error) {
+ switch chal.Type {
+ case "tls-alpn-01":
+ cert, err := client.TLSALPN01ChallengeCert(chal.Token, domain)
+ if err != nil {
+ return nil, err
+ }
+ m.putCertToken(ctx, domain, &cert)
+ return func() { go m.deleteCertToken(domain) }, nil
+ case "tls-sni-01":
+ cert, name, err := client.TLSSNI01ChallengeCert(chal.Token)
+ if err != nil {
+ return nil, err
+ }
+ m.putCertToken(ctx, name, &cert)
+ return func() { go m.deleteCertToken(name) }, nil
+ case "tls-sni-02":
+ cert, name, err := client.TLSSNI02ChallengeCert(chal.Token)
+ if err != nil {
+ return nil, err
+ }
+ m.putCertToken(ctx, name, &cert)
+ return func() { go m.deleteCertToken(name) }, nil
+ case "http-01":
+ resp, err := client.HTTP01ChallengeResponse(chal.Token)
+ if err != nil {
+ return nil, err
+ }
+ p := client.HTTP01ChallengePath(chal.Token)
+ m.putHTTPToken(ctx, p, resp)
+ return func() { go m.deleteHTTPToken(p) }, nil
+ }
+ return nil, fmt.Errorf("acme/autocert: unknown challenge type %q", chal.Type)
+}
+
+func pickChallenge(typ string, chal []*acme.Challenge) *acme.Challenge {
+ for _, c := range chal {
+ if c.Type == typ {
+ return c
+ }
+ }
+ return nil
+}
+
+// putCertToken stores the token certificate with the specified name
+// in both m.certTokens map and m.Cache.
+func (m *Manager) putCertToken(ctx context.Context, name string, cert *tls.Certificate) {
+ m.tokensMu.Lock()
+ defer m.tokensMu.Unlock()
+ if m.certTokens == nil {
+ m.certTokens = make(map[string]*tls.Certificate)
+ }
+ m.certTokens[name] = cert
+ m.cachePut(ctx, certKey{domain: name, isToken: true}, cert)
+}
+
+// deleteCertToken removes the token certificate with the specified name
+// from both m.certTokens map and m.Cache.
+func (m *Manager) deleteCertToken(name string) {
+ m.tokensMu.Lock()
+ defer m.tokensMu.Unlock()
+ delete(m.certTokens, name)
+ if m.Cache != nil {
+ ck := certKey{domain: name, isToken: true}
+ m.Cache.Delete(context.Background(), ck.String())
+ }
+}
+
+// httpToken retrieves an existing http-01 token value from an in-memory map
+// or the optional cache.
+func (m *Manager) httpToken(ctx context.Context, tokenPath string) ([]byte, error) {
+ m.tokensMu.RLock()
+ defer m.tokensMu.RUnlock()
+ if v, ok := m.httpTokens[tokenPath]; ok {
+ return v, nil
+ }
+ if m.Cache == nil {
+ return nil, fmt.Errorf("acme/autocert: no token at %q", tokenPath)
+ }
+ return m.Cache.Get(ctx, httpTokenCacheKey(tokenPath))
+}
+
+// putHTTPToken stores an http-01 token value using tokenPath as key
+// in both in-memory map and the optional Cache.
+//
+// It ignores any error returned from Cache.Put.
+func (m *Manager) putHTTPToken(ctx context.Context, tokenPath, val string) {
+ m.tokensMu.Lock()
+ defer m.tokensMu.Unlock()
+ if m.httpTokens == nil {
+ m.httpTokens = make(map[string][]byte)
+ }
+ b := []byte(val)
+ m.httpTokens[tokenPath] = b
+ if m.Cache != nil {
+ m.Cache.Put(ctx, httpTokenCacheKey(tokenPath), b)
+ }
+}
+
+// deleteHTTPToken removes an http-01 token value from both in-memory map
+// and the optional Cache, ignoring any error returned from the latter.
+//
+// If m.Cache is non-nil, it blocks until Cache.Delete returns without a timeout.
+func (m *Manager) deleteHTTPToken(tokenPath string) {
+ m.tokensMu.Lock()
+ defer m.tokensMu.Unlock()
+ delete(m.httpTokens, tokenPath)
+ if m.Cache != nil {
+ m.Cache.Delete(context.Background(), httpTokenCacheKey(tokenPath))
+ }
+}
+
+// httpTokenCacheKey returns a key at which an http-01 token value may be stored
+// in the Manager's optional Cache.
+func httpTokenCacheKey(tokenPath string) string {
+ return path.Base(tokenPath) + "+http-01"
+}
+
+// renew starts a cert renewal timer loop, one per domain.
+//
+// The loop is scheduled in two cases:
+// - a cert was fetched from cache for the first time (wasn't in m.state)
+// - a new cert was created by m.createCert
+//
+// The key argument is a certificate private key.
+// The exp argument is the cert expiration time (NotAfter).
+func (m *Manager) renew(ck certKey, key crypto.Signer, exp time.Time) {
+ m.renewalMu.Lock()
+ defer m.renewalMu.Unlock()
+ if m.renewal[ck] != nil {
+ // another goroutine is already on it
+ return
+ }
+ if m.renewal == nil {
+ m.renewal = make(map[certKey]*domainRenewal)
+ }
+ dr := &domainRenewal{m: m, ck: ck, key: key}
+ m.renewal[ck] = dr
+ dr.start(exp)
+}
+
+// stopRenew stops all currently running cert renewal timers.
+// The timers are not restarted during the lifetime of the Manager.
+func (m *Manager) stopRenew() {
+ m.renewalMu.Lock()
+ defer m.renewalMu.Unlock()
+ for name, dr := range m.renewal {
+ delete(m.renewal, name)
+ dr.stop()
+ }
+}
+
+func (m *Manager) accountKey(ctx context.Context) (crypto.Signer, error) {
+ const keyName = "acme_account+key"
+
+ // Previous versions of autocert stored the value under a different key.
+ const legacyKeyName = "acme_account.key"
+
+ genKey := func() (*ecdsa.PrivateKey, error) {
+ return ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
+ }
+
+ if m.Cache == nil {
+ return genKey()
+ }
+
+ data, err := m.Cache.Get(ctx, keyName)
+ if err == ErrCacheMiss {
+ data, err = m.Cache.Get(ctx, legacyKeyName)
+ }
+ if err == ErrCacheMiss {
+ key, err := genKey()
+ if err != nil {
+ return nil, err
+ }
+ var buf bytes.Buffer
+ if err := encodeECDSAKey(&buf, key); err != nil {
+ return nil, err
+ }
+ if err := m.Cache.Put(ctx, keyName, buf.Bytes()); err != nil {
+ return nil, err
+ }
+ return key, nil
+ }
+ if err != nil {
+ return nil, err
+ }
+
+ priv, _ := pem.Decode(data)
+ if priv == nil || !strings.Contains(priv.Type, "PRIVATE") {
+ return nil, errors.New("acme/autocert: invalid account key found in cache")
+ }
+ return parsePrivateKey(priv.Bytes)
+}
+
+func (m *Manager) acmeClient(ctx context.Context) (*acme.Client, error) {
+ m.clientMu.Lock()
+ defer m.clientMu.Unlock()
+ if m.client != nil {
+ return m.client, nil
+ }
+
+ client := m.Client
+ if client == nil {
+ client = &acme.Client{DirectoryURL: acme.LetsEncryptURL}
+ }
+ if client.Key == nil {
+ var err error
+ client.Key, err = m.accountKey(ctx)
+ if err != nil {
+ return nil, err
+ }
+ }
+ var contact []string
+ if m.Email != "" {
+ contact = []string{"mailto:" + m.Email}
+ }
+ a := &acme.Account{Contact: contact}
+ _, err := client.Register(ctx, a, m.Prompt)
+ if ae, ok := err.(*acme.Error); err == nil || ok && ae.StatusCode == http.StatusConflict {
+ // conflict indicates the key is already registered
+ m.client = client
+ err = nil
+ }
+ return m.client, err
+}
+
+func (m *Manager) hostPolicy() HostPolicy {
+ if m.HostPolicy != nil {
+ return m.HostPolicy
+ }
+ return defaultHostPolicy
+}
+
+func (m *Manager) renewBefore() time.Duration {
+ if m.RenewBefore > renewJitter {
+ return m.RenewBefore
+ }
+ return 720 * time.Hour // 30 days
+}
+
+func (m *Manager) now() time.Time {
+ if m.nowFunc != nil {
+ return m.nowFunc()
+ }
+ return time.Now()
+}
+
+// certState is ready when its mutex is unlocked for reading.
+type certState struct {
+ sync.RWMutex
+ locked bool // locked for read/write
+ key crypto.Signer // private key for cert
+ cert [][]byte // DER encoding
+ leaf *x509.Certificate // parsed cert[0]; always non-nil if cert != nil
+}
+
+// tlscert creates a tls.Certificate from s.key and s.cert.
+// Callers should wrap it in s.RLock() and s.RUnlock().
+func (s *certState) tlscert() (*tls.Certificate, error) {
+ if s.key == nil {
+ return nil, errors.New("acme/autocert: missing signer")
+ }
+ if len(s.cert) == 0 {
+ return nil, errors.New("acme/autocert: missing certificate")
+ }
+ return &tls.Certificate{
+ PrivateKey: s.key,
+ Certificate: s.cert,
+ Leaf: s.leaf,
+ }, nil
+}
+
+// certRequest generates a CSR for the given common name cn and optional SANs.
+func certRequest(key crypto.Signer, cn string, ext []pkix.Extension, san ...string) ([]byte, error) {
+ req := &x509.CertificateRequest{
+ Subject: pkix.Name{CommonName: cn},
+ DNSNames: san,
+ ExtraExtensions: ext,
+ }
+ return x509.CreateCertificateRequest(rand.Reader, req, key)
+}
+
+// Attempt to parse the given private key DER block. OpenSSL 0.9.8 generates
+// PKCS#1 private keys by default, while OpenSSL 1.0.0 generates PKCS#8 keys.
+// OpenSSL ecparam generates SEC1 EC private keys for ECDSA. We try all three.
+//
+// Inspired by parsePrivateKey in crypto/tls/tls.go.
+func parsePrivateKey(der []byte) (crypto.Signer, error) {
+ if key, err := x509.ParsePKCS1PrivateKey(der); err == nil {
+ return key, nil
+ }
+ if key, err := x509.ParsePKCS8PrivateKey(der); err == nil {
+ switch key := key.(type) {
+ case *rsa.PrivateKey:
+ return key, nil
+ case *ecdsa.PrivateKey:
+ return key, nil
+ default:
+ return nil, errors.New("acme/autocert: unknown private key type in PKCS#8 wrapping")
+ }
+ }
+ if key, err := x509.ParseECPrivateKey(der); err == nil {
+ return key, nil
+ }
+
+ return nil, errors.New("acme/autocert: failed to parse private key")
+}
+
+// validCert parses a cert chain provided as der argument and verifies the leaf and der[0]
+// correspond to the private key, the domain and key type match, and expiration dates
+// are valid. It doesn't do any revocation checking.
+//
+// The returned value is the verified leaf cert.
+func validCert(ck certKey, der [][]byte, key crypto.Signer, now time.Time) (leaf *x509.Certificate, err error) {
+ // parse public part(s)
+ var n int
+ for _, b := range der {
+ n += len(b)
+ }
+ pub := make([]byte, n)
+ n = 0
+ for _, b := range der {
+ n += copy(pub[n:], b)
+ }
+ x509Cert, err := x509.ParseCertificates(pub)
+ if err != nil || len(x509Cert) == 0 {
+ return nil, errors.New("acme/autocert: no public key found")
+ }
+ // verify the leaf is not expired and matches the domain name
+ leaf = x509Cert[0]
+ if now.Before(leaf.NotBefore) {
+ return nil, errors.New("acme/autocert: certificate is not valid yet")
+ }
+ if now.After(leaf.NotAfter) {
+ return nil, errors.New("acme/autocert: expired certificate")
+ }
+ if err := leaf.VerifyHostname(ck.domain); err != nil {
+ return nil, err
+ }
+ // ensure the leaf corresponds to the private key and matches the certKey type
+ switch pub := leaf.PublicKey.(type) {
+ case *rsa.PublicKey:
+ prv, ok := key.(*rsa.PrivateKey)
+ if !ok {
+ return nil, errors.New("acme/autocert: private key type does not match public key type")
+ }
+ if pub.N.Cmp(prv.N) != 0 {
+ return nil, errors.New("acme/autocert: private key does not match public key")
+ }
+ if !ck.isRSA && !ck.isToken {
+ return nil, errors.New("acme/autocert: key type does not match expected value")
+ }
+ case *ecdsa.PublicKey:
+ prv, ok := key.(*ecdsa.PrivateKey)
+ if !ok {
+ return nil, errors.New("acme/autocert: private key type does not match public key type")
+ }
+ if pub.X.Cmp(prv.X) != 0 || pub.Y.Cmp(prv.Y) != 0 {
+ return nil, errors.New("acme/autocert: private key does not match public key")
+ }
+ if ck.isRSA && !ck.isToken {
+ return nil, errors.New("acme/autocert: key type does not match expected value")
+ }
+ default:
+ return nil, errors.New("acme/autocert: unknown public key algorithm")
+ }
+ return leaf, nil
+}
+
+type lockedMathRand struct {
+ sync.Mutex
+ rnd *mathrand.Rand
+}
+
+func (r *lockedMathRand) int63n(max int64) int64 {
+ r.Lock()
+ n := r.rnd.Int63n(max)
+ r.Unlock()
+ return n
+}
+
+// For easier testing.
+var (
+ // Called when a state is removed.
+ testDidRemoveState = func(certKey) {}
+)
diff --git a/src/dma/vendor/golang.org/x/crypto/acme/autocert/cache.go b/src/dma/vendor/golang.org/x/crypto/acme/autocert/cache.go
new file mode 100644
index 00000000..aa9aa845
--- /dev/null
+++ b/src/dma/vendor/golang.org/x/crypto/acme/autocert/cache.go
@@ -0,0 +1,130 @@
+// Copyright 2016 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package autocert
+
+import (
+ "context"
+ "errors"
+ "io/ioutil"
+ "os"
+ "path/filepath"
+)
+
+// ErrCacheMiss is returned when a certificate is not found in cache.
+var ErrCacheMiss = errors.New("acme/autocert: certificate cache miss")
+
+// Cache is used by Manager to store and retrieve previously obtained certificates
+// and other account data as opaque blobs.
+//
+// Cache implementations should not rely on the key naming pattern. Keys can
+// include any printable ASCII characters, except the following: \/:*?"<>|
+type Cache interface {
+ // Get returns a certificate data for the specified key.
+ // If there's no such key, Get returns ErrCacheMiss.
+ Get(ctx context.Context, key string) ([]byte, error)
+
+ // Put stores the data in the cache under the specified key.
+ // Underlying implementations may use any data storage format,
+ // as long as the reverse operation, Get, results in the original data.
+ Put(ctx context.Context, key string, data []byte) error
+
+ // Delete removes a certificate data from the cache under the specified key.
+ // If there's no such key in the cache, Delete returns nil.
+ Delete(ctx context.Context, key string) error
+}
+
+// DirCache implements Cache using a directory on the local filesystem.
+// If the directory does not exist, it will be created with 0700 permissions.
+type DirCache string
+
+// Get reads a certificate data from the specified file name.
+func (d DirCache) Get(ctx context.Context, name string) ([]byte, error) {
+ name = filepath.Join(string(d), name)
+ var (
+ data []byte
+ err error
+ done = make(chan struct{})
+ )
+ go func() {
+ data, err = ioutil.ReadFile(name)
+ close(done)
+ }()
+ select {
+ case <-ctx.Done():
+ return nil, ctx.Err()
+ case <-done:
+ }
+ if os.IsNotExist(err) {
+ return nil, ErrCacheMiss
+ }
+ return data, err
+}
+
+// Put writes the certificate data to the specified file name.
+// The file will be created with 0600 permissions.
+func (d DirCache) Put(ctx context.Context, name string, data []byte) error {
+ if err := os.MkdirAll(string(d), 0700); err != nil {
+ return err
+ }
+
+ done := make(chan struct{})
+ var err error
+ go func() {
+ defer close(done)
+ var tmp string
+ if tmp, err = d.writeTempFile(name, data); err != nil {
+ return
+ }
+ select {
+ case <-ctx.Done():
+ // Don't overwrite the file if the context was canceled.
+ default:
+ newName := filepath.Join(string(d), name)
+ err = os.Rename(tmp, newName)
+ }
+ }()
+ select {
+ case <-ctx.Done():
+ return ctx.Err()
+ case <-done:
+ }
+ return err
+}
+
+// Delete removes the specified file name.
+func (d DirCache) Delete(ctx context.Context, name string) error {
+ name = filepath.Join(string(d), name)
+ var (
+ err error
+ done = make(chan struct{})
+ )
+ go func() {
+ err = os.Remove(name)
+ close(done)
+ }()
+ select {
+ case <-ctx.Done():
+ return ctx.Err()
+ case <-done:
+ }
+ if err != nil && !os.IsNotExist(err) {
+ return err
+ }
+ return nil
+}
+
+// writeTempFile writes b to a temporary file, closes the file and returns its path.
+func (d DirCache) writeTempFile(prefix string, b []byte) (string, error) {
+ // TempFile uses 0600 permissions
+ f, err := ioutil.TempFile(string(d), prefix)
+ if err != nil {
+ return "", err
+ }
+ if _, err := f.Write(b); err != nil {
+ f.Close()
+ return "", err
+ }
+ return f.Name(), f.Close()
+}
diff --git a/src/dma/vendor/golang.org/x/crypto/acme/autocert/listener.go b/src/dma/vendor/golang.org/x/crypto/acme/autocert/listener.go
new file mode 100644
index 00000000..1e069818
--- /dev/null
+++ b/src/dma/vendor/golang.org/x/crypto/acme/autocert/listener.go
@@ -0,0 +1,157 @@
+// Copyright 2017 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package autocert
+
+import (
+ "crypto/tls"
+ "log"
+ "net"
+ "os"
+ "path/filepath"
+ "runtime"
+ "time"
+)
+
+// NewListener returns a net.Listener that listens on the standard TLS
+// port (443) on all interfaces and returns *tls.Conn connections with
+// LetsEncrypt certificates for the provided domain or domains.
+//
+// It enables one-line HTTPS servers:
+//
+// log.Fatal(http.Serve(autocert.NewListener("example.com"), handler))
+//
+// NewListener is a convenience function for a common configuration.
+// More complex or custom configurations can use the autocert.Manager
+// type instead.
+//
+// Use of this function implies acceptance of the LetsEncrypt Terms of
+// Service. If domains is not empty, the provided domains are passed
+// to HostWhitelist. If domains is empty, the listener will do
+// LetsEncrypt challenges for any requested domain, which is not
+// recommended.
+//
+// Certificates are cached in a "golang-autocert" directory under an
+// operating system-specific cache or temp directory. This may not
+// be suitable for servers spanning multiple machines.
+//
+// The returned listener uses a *tls.Config that enables HTTP/2, and
+// should only be used with servers that support HTTP/2.
+//
+// The returned Listener also enables TCP keep-alives on the accepted
+// connections. The returned *tls.Conn are returned before their TLS
+// handshake has completed.
+func NewListener(domains ...string) net.Listener {
+ m := &Manager{
+ Prompt: AcceptTOS,
+ }
+ if len(domains) > 0 {
+ m.HostPolicy = HostWhitelist(domains...)
+ }
+ dir := cacheDir()
+ if err := os.MkdirAll(dir, 0700); err != nil {
+ log.Printf("warning: autocert.NewListener not using a cache: %v", err)
+ } else {
+ m.Cache = DirCache(dir)
+ }
+ return m.Listener()
+}
+
+// Listener listens on the standard TLS port (443) on all interfaces
+// and returns a net.Listener returning *tls.Conn connections.
+//
+// The returned listener uses a *tls.Config that enables HTTP/2, and
+// should only be used with servers that support HTTP/2.
+//
+// The returned Listener also enables TCP keep-alives on the accepted
+// connections. The returned *tls.Conn are returned before their TLS
+// handshake has completed.
+//
+// Unlike NewListener, it is the caller's responsibility to initialize
+// the Manager m's Prompt, Cache, HostPolicy, and other desired options.
+func (m *Manager) Listener() net.Listener {
+ ln := &listener{
+ m: m,
+ conf: m.TLSConfig(),
+ }
+ ln.tcpListener, ln.tcpListenErr = net.Listen("tcp", ":443")
+ return ln
+}
+
+type listener struct {
+ m *Manager
+ conf *tls.Config
+
+ tcpListener net.Listener
+ tcpListenErr error
+}
+
+func (ln *listener) Accept() (net.Conn, error) {
+ if ln.tcpListenErr != nil {
+ return nil, ln.tcpListenErr
+ }
+ conn, err := ln.tcpListener.Accept()
+ if err != nil {
+ return nil, err
+ }
+ tcpConn := conn.(*net.TCPConn)
+
+ // Because Listener is a convenience function, help out with
+ // this too. This is not possible for the caller to set once
+ // we return a *tcp.Conn wrapping an inaccessible net.Conn.
+ // If callers don't want this, they can do things the manual
+ // way and tweak as needed. But this is what net/http does
+ // itself, so copy that. If net/http changes, we can change
+ // here too.
+ tcpConn.SetKeepAlive(true)
+ tcpConn.SetKeepAlivePeriod(3 * time.Minute)
+
+ return tls.Server(tcpConn, ln.conf), nil
+}
+
+func (ln *listener) Addr() net.Addr {
+ if ln.tcpListener != nil {
+ return ln.tcpListener.Addr()
+ }
+ // net.Listen failed. Return something non-nil in case callers
+ // call Addr before Accept:
+ return &net.TCPAddr{IP: net.IP{0, 0, 0, 0}, Port: 443}
+}
+
+func (ln *listener) Close() error {
+ if ln.tcpListenErr != nil {
+ return ln.tcpListenErr
+ }
+ return ln.tcpListener.Close()
+}
+
+func homeDir() string {
+ if runtime.GOOS == "windows" {
+ return os.Getenv("HOMEDRIVE") + os.Getenv("HOMEPATH")
+ }
+ if h := os.Getenv("HOME"); h != "" {
+ return h
+ }
+ return "/"
+}
+
+func cacheDir() string {
+ const base = "golang-autocert"
+ switch runtime.GOOS {
+ case "darwin":
+ return filepath.Join(homeDir(), "Library", "Caches", base)
+ case "windows":
+ for _, ev := range []string{"APPDATA", "CSIDL_APPDATA", "TEMP", "TMP"} {
+ if v := os.Getenv(ev); v != "" {
+ return filepath.Join(v, base)
+ }
+ }
+ // Worst case:
+ return filepath.Join(homeDir(), base)
+ }
+ if xdg := os.Getenv("XDG_CACHE_HOME"); xdg != "" {
+ return filepath.Join(xdg, base)
+ }
+ return filepath.Join(homeDir(), ".cache", base)
+}
diff --git a/src/dma/vendor/golang.org/x/crypto/acme/autocert/renewal.go b/src/dma/vendor/golang.org/x/crypto/acme/autocert/renewal.go
new file mode 100644
index 00000000..665f870d
--- /dev/null
+++ b/src/dma/vendor/golang.org/x/crypto/acme/autocert/renewal.go
@@ -0,0 +1,141 @@
+// Copyright 2016 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package autocert
+
+import (
+ "context"
+ "crypto"
+ "sync"
+ "time"
+)
+
+// renewJitter is the maximum deviation from Manager.RenewBefore.
+const renewJitter = time.Hour
+
+// domainRenewal tracks the state used by the periodic timers
+// renewing a single domain's cert.
+type domainRenewal struct {
+ m *Manager
+ ck certKey
+ key crypto.Signer
+
+ timerMu sync.Mutex
+ timer *time.Timer
+}
+
+// start starts a cert renewal timer at the time
+// defined by the certificate expiration time exp.
+//
+// If the timer is already started, calling start is a noop.
+func (dr *domainRenewal) start(exp time.Time) {
+ dr.timerMu.Lock()
+ defer dr.timerMu.Unlock()
+ if dr.timer != nil {
+ return
+ }
+ dr.timer = time.AfterFunc(dr.next(exp), dr.renew)
+}
+
+// stop stops the cert renewal timer.
+// If the timer is already stopped, calling stop is a noop.
+func (dr *domainRenewal) stop() {
+ dr.timerMu.Lock()
+ defer dr.timerMu.Unlock()
+ if dr.timer == nil {
+ return
+ }
+ dr.timer.Stop()
+ dr.timer = nil
+}
+
+// renew is called periodically by a timer.
+// The first renew call is kicked off by dr.start.
+func (dr *domainRenewal) renew() {
+ dr.timerMu.Lock()
+ defer dr.timerMu.Unlock()
+ if dr.timer == nil {
+ return
+ }
+
+ ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
+ defer cancel()
+ // TODO: rotate dr.key at some point?
+ next, err := dr.do(ctx)
+ if err != nil {
+ next = renewJitter / 2
+ next += time.Duration(pseudoRand.int63n(int64(next)))
+ }
+ dr.timer = time.AfterFunc(next, dr.renew)
+ testDidRenewLoop(next, err)
+}
+
+// updateState locks and replaces the relevant Manager.state item with the given
+// state. It additionally updates dr.key with the given state's key.
+func (dr *domainRenewal) updateState(state *certState) {
+ dr.m.stateMu.Lock()
+ defer dr.m.stateMu.Unlock()
+ dr.key = state.key
+ dr.m.state[dr.ck] = state
+}
+
+// do is similar to Manager.createCert but it doesn't lock a Manager.state item.
+// Instead, it requests a new certificate independently and, upon success,
+// replaces dr.m.state item with a new one and updates cache for the given domain.
+//
+// It may lock and update the Manager.state if the expiration date of the currently
+// cached cert is far enough in the future.
+//
+// The returned value is a time interval after which the renewal should occur again.
+func (dr *domainRenewal) do(ctx context.Context) (time.Duration, error) {
+ // a race is likely unavoidable in a distributed environment
+ // but we try nonetheless
+ if tlscert, err := dr.m.cacheGet(ctx, dr.ck); err == nil {
+ next := dr.next(tlscert.Leaf.NotAfter)
+ if next > dr.m.renewBefore()+renewJitter {
+ signer, ok := tlscert.PrivateKey.(crypto.Signer)
+ if ok {
+ state := &certState{
+ key: signer,
+ cert: tlscert.Certificate,
+ leaf: tlscert.Leaf,
+ }
+ dr.updateState(state)
+ return next, nil
+ }
+ }
+ }
+
+ der, leaf, err := dr.m.authorizedCert(ctx, dr.key, dr.ck)
+ if err != nil {
+ return 0, err
+ }
+ state := &certState{
+ key: dr.key,
+ cert: der,
+ leaf: leaf,
+ }
+ tlscert, err := state.tlscert()
+ if err != nil {
+ return 0, err
+ }
+ if err := dr.m.cachePut(ctx, dr.ck, tlscert); err != nil {
+ return 0, err
+ }
+ dr.updateState(state)
+ return dr.next(leaf.NotAfter), nil
+}
+
+func (dr *domainRenewal) next(expiry time.Time) time.Duration {
+ d := expiry.Sub(dr.m.now()) - dr.m.renewBefore()
+ // add a bit of randomness to renew deadline
+ n := pseudoRand.int63n(int64(renewJitter))
+ d -= time.Duration(n)
+ if d < 0 {
+ return 0
+ }
+ return d
+}
+
+var testDidRenewLoop = func(next time.Duration, err error) {}
diff --git a/src/dma/vendor/golang.org/x/crypto/acme/http.go b/src/dma/vendor/golang.org/x/crypto/acme/http.go
new file mode 100644
index 00000000..a43ce6a5
--- /dev/null
+++ b/src/dma/vendor/golang.org/x/crypto/acme/http.go
@@ -0,0 +1,281 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package acme
+
+import (
+ "bytes"
+ "context"
+ "crypto"
+ "crypto/rand"
+ "encoding/json"
+ "fmt"
+ "io/ioutil"
+ "math/big"
+ "net/http"
+ "strconv"
+ "strings"
+ "time"
+)
+
+// retryTimer encapsulates common logic for retrying unsuccessful requests.
+// It is not safe for concurrent use.
+type retryTimer struct {
+ // backoffFn provides backoff delay sequence for retries.
+ // See Client.RetryBackoff doc comment.
+ backoffFn func(n int, r *http.Request, res *http.Response) time.Duration
+ // n is the current retry attempt.
+ n int
+}
+
+func (t *retryTimer) inc() {
+ t.n++
+}
+
+// backoff pauses the current goroutine as described in Client.RetryBackoff.
+func (t *retryTimer) backoff(ctx context.Context, r *http.Request, res *http.Response) error {
+ d := t.backoffFn(t.n, r, res)
+ if d <= 0 {
+ return fmt.Errorf("acme: no more retries for %s; tried %d time(s)", r.URL, t.n)
+ }
+ wakeup := time.NewTimer(d)
+ defer wakeup.Stop()
+ select {
+ case <-ctx.Done():
+ return ctx.Err()
+ case <-wakeup.C:
+ return nil
+ }
+}
+
+func (c *Client) retryTimer() *retryTimer {
+ f := c.RetryBackoff
+ if f == nil {
+ f = defaultBackoff
+ }
+ return &retryTimer{backoffFn: f}
+}
+
+// defaultBackoff provides default Client.RetryBackoff implementation
+// using a truncated exponential backoff algorithm,
+// as described in Client.RetryBackoff.
+//
+// The n argument is always bounded between 1 and 30.
+// The returned value is always greater than 0.
+func defaultBackoff(n int, r *http.Request, res *http.Response) time.Duration {
+ const max = 10 * time.Second
+ var jitter time.Duration
+ if x, err := rand.Int(rand.Reader, big.NewInt(1000)); err == nil {
+ // Set the minimum to 1ms to avoid a case where
+ // an invalid Retry-After value is parsed into 0 below,
+ // resulting in the 0 returned value which would unintentionally
+ // stop the retries.
+ jitter = (1 + time.Duration(x.Int64())) * time.Millisecond
+ }
+ if v, ok := res.Header["Retry-After"]; ok {
+ return retryAfter(v[0]) + jitter
+ }
+
+ if n < 1 {
+ n = 1
+ }
+ if n > 30 {
+ n = 30
+ }
+ d := time.Duration(1<<uint(n-1))*time.Second + jitter
+ if d > max {
+ return max
+ }
+ return d
+}
+
+// retryAfter parses a Retry-After HTTP header value,
+// trying to convert v into an int (seconds) or use http.ParseTime otherwise.
+// It returns zero value if v cannot be parsed.
+func retryAfter(v string) time.Duration {
+ if i, err := strconv.Atoi(v); err == nil {
+ return time.Duration(i) * time.Second
+ }
+ t, err := http.ParseTime(v)
+ if err != nil {
+ return 0
+ }
+ return t.Sub(timeNow())
+}
+
+// resOkay is a function that reports whether the provided response is okay.
+// It is expected to keep the response body unread.
+type resOkay func(*http.Response) bool
+
+// wantStatus returns a function which reports whether the code
+// matches the status code of a response.
+func wantStatus(codes ...int) resOkay {
+ return func(res *http.Response) bool {
+ for _, code := range codes {
+ if code == res.StatusCode {
+ return true
+ }
+ }
+ return false
+ }
+}
+
+// get issues an unsigned GET request to the specified URL.
+// It returns a non-error value only when ok reports true.
+//
+// get retries unsuccessful attempts according to c.RetryBackoff
+// until the context is done or a non-retriable error is received.
+func (c *Client) get(ctx context.Context, url string, ok resOkay) (*http.Response, error) {
+ retry := c.retryTimer()
+ for {
+ req, err := http.NewRequest("GET", url, nil)
+ if err != nil {
+ return nil, err
+ }
+ res, err := c.doNoRetry(ctx, req)
+ switch {
+ case err != nil:
+ return nil, err
+ case ok(res):
+ return res, nil
+ case isRetriable(res.StatusCode):
+ retry.inc()
+ resErr := responseError(res)
+ res.Body.Close()
+ // Ignore the error value from retry.backoff
+ // and return the one from last retry, as received from the CA.
+ if retry.backoff(ctx, req, res) != nil {
+ return nil, resErr
+ }
+ default:
+ defer res.Body.Close()
+ return nil, responseError(res)
+ }
+ }
+}
+
+// post issues a signed POST request in JWS format using the provided key
+// to the specified URL.
+// It returns a non-error value only when ok reports true.
+//
+// post retries unsuccessful attempts according to c.RetryBackoff
+// until the context is done or a non-retriable error is received.
+// It uses postNoRetry to make individual requests.
+func (c *Client) post(ctx context.Context, key crypto.Signer, url string, body interface{}, ok resOkay) (*http.Response, error) {
+ retry := c.retryTimer()
+ for {
+ res, req, err := c.postNoRetry(ctx, key, url, body)
+ if err != nil {
+ return nil, err
+ }
+ if ok(res) {
+ return res, nil
+ }
+ resErr := responseError(res)
+ res.Body.Close()
+ switch {
+ // Check for bad nonce before isRetriable because it may have been returned
+ // with an unretriable response code such as 400 Bad Request.
+ case isBadNonce(resErr):
+ // Consider any previously stored nonce values to be invalid.
+ c.clearNonces()
+ case !isRetriable(res.StatusCode):
+ return nil, resErr
+ }
+ retry.inc()
+ // Ignore the error value from retry.backoff
+ // and return the one from last retry, as received from the CA.
+ if err := retry.backoff(ctx, req, res); err != nil {
+ return nil, resErr
+ }
+ }
+}
+
+// postNoRetry signs the body with the given key and POSTs it to the provided url.
+// The body argument must be JSON-serializable.
+// It is used by c.post to retry unsuccessful attempts.
+func (c *Client) postNoRetry(ctx context.Context, key crypto.Signer, url string, body interface{}) (*http.Response, *http.Request, error) {
+ nonce, err := c.popNonce(ctx, url)
+ if err != nil {
+ return nil, nil, err
+ }
+ b, err := jwsEncodeJSON(body, key, nonce)
+ if err != nil {
+ return nil, nil, err
+ }
+ req, err := http.NewRequest("POST", url, bytes.NewReader(b))
+ if err != nil {
+ return nil, nil, err
+ }
+ req.Header.Set("Content-Type", "application/jose+json")
+ res, err := c.doNoRetry(ctx, req)
+ if err != nil {
+ return nil, nil, err
+ }
+ c.addNonce(res.Header)
+ return res, req, nil
+}
+
+// doNoRetry issues a request req, replacing its context (if any) with ctx.
+func (c *Client) doNoRetry(ctx context.Context, req *http.Request) (*http.Response, error) {
+ res, err := c.httpClient().Do(req.WithContext(ctx))
+ if err != nil {
+ select {
+ case <-ctx.Done():
+ // Prefer the unadorned context error.
+ // (The acme package had tests assuming this, previously from ctxhttp's
+ // behavior, predating net/http supporting contexts natively)
+ // TODO(bradfitz): reconsider this in the future. But for now this
+ // requires no test updates.
+ return nil, ctx.Err()
+ default:
+ return nil, err
+ }
+ }
+ return res, nil
+}
+
+func (c *Client) httpClient() *http.Client {
+ if c.HTTPClient != nil {
+ return c.HTTPClient
+ }
+ return http.DefaultClient
+}
+
+// isBadNonce reports whether err is an ACME "badnonce" error.
+func isBadNonce(err error) bool {
+ // According to the spec badNonce is urn:ietf:params:acme:error:badNonce.
+ // However, ACME servers in the wild return their versions of the error.
+ // See https://tools.ietf.org/html/draft-ietf-acme-acme-02#section-5.4
+ // and https://github.com/letsencrypt/boulder/blob/0e07eacb/docs/acme-divergences.md#section-66.
+ ae, ok := err.(*Error)
+ return ok && strings.HasSuffix(strings.ToLower(ae.ProblemType), ":badnonce")
+}
+
+// isRetriable reports whether a request can be retried
+// based on the response status code.
+//
+// Note that a "bad nonce" error is returned with a non-retriable 400 Bad Request code.
+// Callers should parse the response and check with isBadNonce.
+func isRetriable(code int) bool {
+ return code <= 399 || code >= 500 || code == http.StatusTooManyRequests
+}
+
+// responseError creates an error of Error type from resp.
+func responseError(resp *http.Response) error {
+ // don't care if ReadAll returns an error:
+ // json.Unmarshal will fail in that case anyway
+ b, _ := ioutil.ReadAll(resp.Body)
+ e := &wireError{Status: resp.StatusCode}
+ if err := json.Unmarshal(b, e); err != nil {
+ // this is not a regular error response:
+ // populate detail with anything we received,
+ // e.Status will already contain HTTP response code value
+ e.Detail = string(b)
+ if e.Detail == "" {
+ e.Detail = resp.Status
+ }
+ }
+ return e.error(resp.Header)
+}
diff --git a/src/dma/vendor/golang.org/x/crypto/acme/jws.go b/src/dma/vendor/golang.org/x/crypto/acme/jws.go
new file mode 100644
index 00000000..6cbca25d
--- /dev/null
+++ b/src/dma/vendor/golang.org/x/crypto/acme/jws.go
@@ -0,0 +1,153 @@
+// Copyright 2015 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package acme
+
+import (
+ "crypto"
+ "crypto/ecdsa"
+ "crypto/rand"
+ "crypto/rsa"
+ "crypto/sha256"
+ _ "crypto/sha512" // need for EC keys
+ "encoding/base64"
+ "encoding/json"
+ "fmt"
+ "math/big"
+)
+
+// jwsEncodeJSON signs claimset using provided key and a nonce.
+// The result is serialized in JSON format.
+// See https://tools.ietf.org/html/rfc7515#section-7.
+func jwsEncodeJSON(claimset interface{}, key crypto.Signer, nonce string) ([]byte, error) {
+ jwk, err := jwkEncode(key.Public())
+ if err != nil {
+ return nil, err
+ }
+ alg, sha := jwsHasher(key)
+ if alg == "" || !sha.Available() {
+ return nil, ErrUnsupportedKey
+ }
+ phead := fmt.Sprintf(`{"alg":%q,"jwk":%s,"nonce":%q}`, alg, jwk, nonce)
+ phead = base64.RawURLEncoding.EncodeToString([]byte(phead))
+ cs, err := json.Marshal(claimset)
+ if err != nil {
+ return nil, err
+ }
+ payload := base64.RawURLEncoding.EncodeToString(cs)
+ hash := sha.New()
+ hash.Write([]byte(phead + "." + payload))
+ sig, err := jwsSign(key, sha, hash.Sum(nil))
+ if err != nil {
+ return nil, err
+ }
+
+ enc := struct {
+ Protected string `json:"protected"`
+ Payload string `json:"payload"`
+ Sig string `json:"signature"`
+ }{
+ Protected: phead,
+ Payload: payload,
+ Sig: base64.RawURLEncoding.EncodeToString(sig),
+ }
+ return json.Marshal(&enc)
+}
+
+// jwkEncode encodes public part of an RSA or ECDSA key into a JWK.
+// The result is also suitable for creating a JWK thumbprint.
+// https://tools.ietf.org/html/rfc7517
+func jwkEncode(pub crypto.PublicKey) (string, error) {
+ switch pub := pub.(type) {
+ case *rsa.PublicKey:
+ // https://tools.ietf.org/html/rfc7518#section-6.3.1
+ n := pub.N
+ e := big.NewInt(int64(pub.E))
+ // Field order is important.
+ // See https://tools.ietf.org/html/rfc7638#section-3.3 for details.
+ return fmt.Sprintf(`{"e":"%s","kty":"RSA","n":"%s"}`,
+ base64.RawURLEncoding.EncodeToString(e.Bytes()),
+ base64.RawURLEncoding.EncodeToString(n.Bytes()),
+ ), nil
+ case *ecdsa.PublicKey:
+ // https://tools.ietf.org/html/rfc7518#section-6.2.1
+ p := pub.Curve.Params()
+ n := p.BitSize / 8
+ if p.BitSize%8 != 0 {
+ n++
+ }
+ x := pub.X.Bytes()
+ if n > len(x) {
+ x = append(make([]byte, n-len(x)), x...)
+ }
+ y := pub.Y.Bytes()
+ if n > len(y) {
+ y = append(make([]byte, n-len(y)), y...)
+ }
+ // Field order is important.
+ // See https://tools.ietf.org/html/rfc7638#section-3.3 for details.
+ return fmt.Sprintf(`{"crv":"%s","kty":"EC","x":"%s","y":"%s"}`,
+ p.Name,
+ base64.RawURLEncoding.EncodeToString(x),
+ base64.RawURLEncoding.EncodeToString(y),
+ ), nil
+ }
+ return "", ErrUnsupportedKey
+}
+
+// jwsSign signs the digest using the given key.
+// It returns ErrUnsupportedKey if the key type is unknown.
+// The hash is used only for RSA keys.
+func jwsSign(key crypto.Signer, hash crypto.Hash, digest []byte) ([]byte, error) {
+ switch key := key.(type) {
+ case *rsa.PrivateKey:
+ return key.Sign(rand.Reader, digest, hash)
+ case *ecdsa.PrivateKey:
+ r, s, err := ecdsa.Sign(rand.Reader, key, digest)
+ if err != nil {
+ return nil, err
+ }
+ rb, sb := r.Bytes(), s.Bytes()
+ size := key.Params().BitSize / 8
+ if size%8 > 0 {
+ size++
+ }
+ sig := make([]byte, size*2)
+ copy(sig[size-len(rb):], rb)
+ copy(sig[size*2-len(sb):], sb)
+ return sig, nil
+ }
+ return nil, ErrUnsupportedKey
+}
+
+// jwsHasher indicates suitable JWS algorithm name and a hash function
+// to use for signing a digest with the provided key.
+// It returns ("", 0) if the key is not supported.
+func jwsHasher(key crypto.Signer) (string, crypto.Hash) {
+ switch key := key.(type) {
+ case *rsa.PrivateKey:
+ return "RS256", crypto.SHA256
+ case *ecdsa.PrivateKey:
+ switch key.Params().Name {
+ case "P-256":
+ return "ES256", crypto.SHA256
+ case "P-384":
+ return "ES384", crypto.SHA384
+ case "P-521":
+ return "ES512", crypto.SHA512
+ }
+ }
+ return "", 0
+}
+
+// JWKThumbprint creates a JWK thumbprint out of pub
+// as specified in https://tools.ietf.org/html/rfc7638.
+func JWKThumbprint(pub crypto.PublicKey) (string, error) {
+ jwk, err := jwkEncode(pub)
+ if err != nil {
+ return "", err
+ }
+ b := sha256.Sum256([]byte(jwk))
+ return base64.RawURLEncoding.EncodeToString(b[:]), nil
+}
diff --git a/src/dma/vendor/golang.org/x/crypto/acme/types.go b/src/dma/vendor/golang.org/x/crypto/acme/types.go
new file mode 100644
index 00000000..54792c06
--- /dev/null
+++ b/src/dma/vendor/golang.org/x/crypto/acme/types.go
@@ -0,0 +1,329 @@
+// Copyright 2016 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package acme
+
+import (
+ "crypto"
+ "crypto/x509"
+ "errors"
+ "fmt"
+ "net/http"
+ "strings"
+ "time"
+)
+
+// ACME server response statuses used to describe Authorization and Challenge states.
+const (
+ StatusUnknown = "unknown"
+ StatusPending = "pending"
+ StatusProcessing = "processing"
+ StatusValid = "valid"
+ StatusInvalid = "invalid"
+ StatusRevoked = "revoked"
+)
+
+// CRLReasonCode identifies the reason for a certificate revocation.
+type CRLReasonCode int
+
+// CRL reason codes as defined in RFC 5280.
+const (
+ CRLReasonUnspecified CRLReasonCode = 0
+ CRLReasonKeyCompromise CRLReasonCode = 1
+ CRLReasonCACompromise CRLReasonCode = 2
+ CRLReasonAffiliationChanged CRLReasonCode = 3
+ CRLReasonSuperseded CRLReasonCode = 4
+ CRLReasonCessationOfOperation CRLReasonCode = 5
+ CRLReasonCertificateHold CRLReasonCode = 6
+ CRLReasonRemoveFromCRL CRLReasonCode = 8
+ CRLReasonPrivilegeWithdrawn CRLReasonCode = 9
+ CRLReasonAACompromise CRLReasonCode = 10
+)
+
+// ErrUnsupportedKey is returned when an unsupported key type is encountered.
+var ErrUnsupportedKey = errors.New("acme: unknown key type; only RSA and ECDSA are supported")
+
+// Error is an ACME error, defined in Problem Details for HTTP APIs doc
+// http://tools.ietf.org/html/draft-ietf-appsawg-http-problem.
+type Error struct {
+ // StatusCode is The HTTP status code generated by the origin server.
+ StatusCode int
+ // ProblemType is a URI reference that identifies the problem type,
+ // typically in a "urn:acme:error:xxx" form.
+ ProblemType string
+ // Detail is a human-readable explanation specific to this occurrence of the problem.
+ Detail string
+ // Header is the original server error response headers.
+ // It may be nil.
+ Header http.Header
+}
+
+func (e *Error) Error() string {
+ return fmt.Sprintf("%d %s: %s", e.StatusCode, e.ProblemType, e.Detail)
+}
+
+// AuthorizationError indicates that an authorization for an identifier
+// did not succeed.
+// It contains all errors from Challenge items of the failed Authorization.
+type AuthorizationError struct {
+ // URI uniquely identifies the failed Authorization.
+ URI string
+
+ // Identifier is an AuthzID.Value of the failed Authorization.
+ Identifier string
+
+ // Errors is a collection of non-nil error values of Challenge items
+ // of the failed Authorization.
+ Errors []error
+}
+
+func (a *AuthorizationError) Error() string {
+ e := make([]string, len(a.Errors))
+ for i, err := range a.Errors {
+ e[i] = err.Error()
+ }
+ return fmt.Sprintf("acme: authorization error for %s: %s", a.Identifier, strings.Join(e, "; "))
+}
+
+// RateLimit reports whether err represents a rate limit error and
+// any Retry-After duration returned by the server.
+//
+// See the following for more details on rate limiting:
+// https://tools.ietf.org/html/draft-ietf-acme-acme-05#section-5.6
+func RateLimit(err error) (time.Duration, bool) {
+ e, ok := err.(*Error)
+ if !ok {
+ return 0, false
+ }
+ // Some CA implementations may return incorrect values.
+ // Use case-insensitive comparison.
+ if !strings.HasSuffix(strings.ToLower(e.ProblemType), ":ratelimited") {
+ return 0, false
+ }
+ if e.Header == nil {
+ return 0, true
+ }
+ return retryAfter(e.Header.Get("Retry-After")), true
+}
+
+// Account is a user account. It is associated with a private key.
+type Account struct {
+ // URI is the account unique ID, which is also a URL used to retrieve
+ // account data from the CA.
+ URI string
+
+ // Contact is a slice of contact info used during registration.
+ Contact []string
+
+ // The terms user has agreed to.
+ // A value not matching CurrentTerms indicates that the user hasn't agreed
+ // to the actual Terms of Service of the CA.
+ AgreedTerms string
+
+ // Actual terms of a CA.
+ CurrentTerms string
+
+ // Authz is the authorization URL used to initiate a new authz flow.
+ Authz string
+
+ // Authorizations is a URI from which a list of authorizations
+ // granted to this account can be fetched via a GET request.
+ Authorizations string
+
+ // Certificates is a URI from which a list of certificates
+ // issued for this account can be fetched via a GET request.
+ Certificates string
+}
+
+// Directory is ACME server discovery data.
+type Directory struct {
+ // RegURL is an account endpoint URL, allowing for creating new
+ // and modifying existing accounts.
+ RegURL string
+
+ // AuthzURL is used to initiate Identifier Authorization flow.
+ AuthzURL string
+
+ // CertURL is a new certificate issuance endpoint URL.
+ CertURL string
+
+ // RevokeURL is used to initiate a certificate revocation flow.
+ RevokeURL string
+
+ // Term is a URI identifying the current terms of service.
+ Terms string
+
+ // Website is an HTTP or HTTPS URL locating a website
+ // providing more information about the ACME server.
+ Website string
+
+ // CAA consists of lowercase hostname elements, which the ACME server
+ // recognises as referring to itself for the purposes of CAA record validation
+ // as defined in RFC6844.
+ CAA []string
+}
+
+// Challenge encodes a returned CA challenge.
+// Its Error field may be non-nil if the challenge is part of an Authorization
+// with StatusInvalid.
+type Challenge struct {
+ // Type is the challenge type, e.g. "http-01", "tls-sni-02", "dns-01".
+ Type string
+
+ // URI is where a challenge response can be posted to.
+ URI string
+
+ // Token is a random value that uniquely identifies the challenge.
+ Token string
+
+ // Status identifies the status of this challenge.
+ Status string
+
+ // Error indicates the reason for an authorization failure
+ // when this challenge was used.
+ // The type of a non-nil value is *Error.
+ Error error
+}
+
+// Authorization encodes an authorization response.
+type Authorization struct {
+ // URI uniquely identifies a authorization.
+ URI string
+
+ // Status identifies the status of an authorization.
+ Status string
+
+ // Identifier is what the account is authorized to represent.
+ Identifier AuthzID
+
+ // Challenges that the client needs to fulfill in order to prove possession
+ // of the identifier (for pending authorizations).
+ // For final authorizations, the challenges that were used.
+ Challenges []*Challenge
+
+ // A collection of sets of challenges, each of which would be sufficient
+ // to prove possession of the identifier.
+ // Clients must complete a set of challenges that covers at least one set.
+ // Challenges are identified by their indices in the challenges array.
+ // If this field is empty, the client needs to complete all challenges.
+ Combinations [][]int
+}
+
+// AuthzID is an identifier that an account is authorized to represent.
+type AuthzID struct {
+ Type string // The type of identifier, e.g. "dns".
+ Value string // The identifier itself, e.g. "example.org".
+}
+
+// wireAuthz is ACME JSON representation of Authorization objects.
+type wireAuthz struct {
+ Status string
+ Challenges []wireChallenge
+ Combinations [][]int
+ Identifier struct {
+ Type string
+ Value string
+ }
+}
+
+func (z *wireAuthz) authorization(uri string) *Authorization {
+ a := &Authorization{
+ URI: uri,
+ Status: z.Status,
+ Identifier: AuthzID{Type: z.Identifier.Type, Value: z.Identifier.Value},
+ Combinations: z.Combinations, // shallow copy
+ Challenges: make([]*Challenge, len(z.Challenges)),
+ }
+ for i, v := range z.Challenges {
+ a.Challenges[i] = v.challenge()
+ }
+ return a
+}
+
+func (z *wireAuthz) error(uri string) *AuthorizationError {
+ err := &AuthorizationError{
+ URI: uri,
+ Identifier: z.Identifier.Value,
+ }
+ for _, raw := range z.Challenges {
+ if raw.Error != nil {
+ err.Errors = append(err.Errors, raw.Error.error(nil))
+ }
+ }
+ return err
+}
+
+// wireChallenge is ACME JSON challenge representation.
+type wireChallenge struct {
+ URI string `json:"uri"`
+ Type string
+ Token string
+ Status string
+ Error *wireError
+}
+
+func (c *wireChallenge) challenge() *Challenge {
+ v := &Challenge{
+ URI: c.URI,
+ Type: c.Type,
+ Token: c.Token,
+ Status: c.Status,
+ }
+ if v.Status == "" {
+ v.Status = StatusPending
+ }
+ if c.Error != nil {
+ v.Error = c.Error.error(nil)
+ }
+ return v
+}
+
+// wireError is a subset of fields of the Problem Details object
+// as described in https://tools.ietf.org/html/rfc7807#section-3.1.
+type wireError struct {
+ Status int
+ Type string
+ Detail string
+}
+
+func (e *wireError) error(h http.Header) *Error {
+ return &Error{
+ StatusCode: e.Status,
+ ProblemType: e.Type,
+ Detail: e.Detail,
+ Header: h,
+ }
+}
+
+// CertOption is an optional argument type for the TLS ChallengeCert methods for
+// customizing a temporary certificate for TLS-based challenges.
+type CertOption interface {
+ privateCertOpt()
+}
+
+// WithKey creates an option holding a private/public key pair.
+// The private part signs a certificate, and the public part represents the signee.
+func WithKey(key crypto.Signer) CertOption {
+ return &certOptKey{key}
+}
+
+type certOptKey struct {
+ key crypto.Signer
+}
+
+func (*certOptKey) privateCertOpt() {}
+
+// WithTemplate creates an option for specifying a certificate template.
+// See x509.CreateCertificate for template usage details.
+//
+// In TLS ChallengeCert methods, the template is also used as parent,
+// resulting in a self-signed certificate.
+// The DNSNames field of t is always overwritten for tls-sni challenge certs.
+func WithTemplate(t *x509.Certificate) CertOption {
+ return (*certOptTemplate)(t)
+}
+
+type certOptTemplate x509.Certificate
+
+func (*certOptTemplate) privateCertOpt() {}