2
* Copyright (c) 2013, Joyent, Inc.
3
* See LICENSE file for copyright and license details.
22
typedef enum mdata_exit_codes {
33
print_response(mdata_response_t mdr, string_t *data)
35
const char *cstr = dynstr_cstr(data);
36
size_t len = dynstr_len(data);
40
fprintf(stdout, "%s", cstr);
41
if (len < 1 || cstr[len - 1] != '\n')
42
fprintf(stdout, "\n");
43
return (MDEC_SUCCESS);
45
fprintf(stderr, "No metadata for '%s'\n", keyname);
46
return (MDEC_NOTFOUND);
48
fprintf(stderr, "Error getting metadata for key '%s': %s\n",
51
case MDR_INVALID_COMMAND:
52
fprintf(stderr, "ERROR: host does not support GET\n");
55
ABORT("print_response: UNKNOWN RESPONSE\n");
61
main(int argc, char **argv)
69
errx(MDEC_USAGE_ERROR, "Usage: %s <keyname>", argv[0]);
72
if (proto_init(&mdp, &errmsg) != 0) {
73
fprintf(stderr, "ERROR: could not initialise protocol: %s\n",
78
keyname = strdup(argv[1]);
80
if (proto_execute(mdp, "GET", keyname, &mdr, &data) != 0) {
81
fprintf(stderr, "ERROR: could not execute GET\n");
85
return (print_response(mdr, data));