Annotation of embedaddon/strongswan/src/swanctl/commands/list_algs.c, revision 1.1
1.1 ! misho 1: /*
! 2: * Copyright (C) 2015 Tobias Brunner
! 3: * HSR Hochschule fuer Technik Rapperswil
! 4: *
! 5: * This program is free software; you can redistribute it and/or modify it
! 6: * under the terms of the GNU General Public License as published by the
! 7: * Free Software Foundation; either version 2 of the License, or (at your
! 8: * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
! 9: *
! 10: * This program is distributed in the hope that it will be useful, but
! 11: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
! 12: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
! 13: * for more details.
! 14: */
! 15:
! 16: #include "command.h"
! 17:
! 18: #include <errno.h>
! 19:
! 20: CALLBACK(algs, int,
! 21: void *null, vici_res_t *res, char *name, void *value, int len)
! 22: {
! 23: if (chunk_printable(chunk_create(value, len), NULL, ' '))
! 24: {
! 25: printf(" %s[%.*s]\n", name, len, value);
! 26: }
! 27: return 0;
! 28: }
! 29:
! 30: CALLBACK(types, int,
! 31: void *null, vici_res_t *res, char *name)
! 32: {
! 33: printf("%s:\n", name);
! 34: return vici_parse_cb(res, NULL, algs, NULL, NULL);
! 35: }
! 36:
! 37: static int algorithms(vici_conn_t *conn)
! 38: {
! 39: vici_req_t *req;
! 40: vici_res_t *res;
! 41: char *arg;
! 42: command_format_options_t format = COMMAND_FORMAT_NONE;
! 43: int ret;
! 44:
! 45: while (TRUE)
! 46: {
! 47: switch (command_getopt(&arg))
! 48: {
! 49: case 'h':
! 50: return command_usage(NULL);
! 51: case 'P':
! 52: format |= COMMAND_FORMAT_PRETTY;
! 53: /* fall through to raw */
! 54: case 'r':
! 55: format |= COMMAND_FORMAT_RAW;
! 56: continue;
! 57: case EOF:
! 58: break;
! 59: default:
! 60: return command_usage("invalid --list-algs option");
! 61: }
! 62: break;
! 63: }
! 64:
! 65: req = vici_begin("get-algorithms");
! 66: res = vici_submit(req, conn);
! 67: if (!res)
! 68: {
! 69: ret = errno;
! 70: fprintf(stderr, "get-algorithms request failed: %s\n", strerror(errno));
! 71: return ret;
! 72: }
! 73: if (format & COMMAND_FORMAT_RAW)
! 74: {
! 75: vici_dump(res, "get-algorithms reply", format & COMMAND_FORMAT_PRETTY,
! 76: stdout);
! 77: }
! 78: else
! 79: {
! 80: if (vici_parse_cb(res, types, NULL, NULL, NULL) != 0)
! 81: {
! 82: fprintf(stderr, "parsing get-algorithms reply failed: %s\n",
! 83: strerror(errno));
! 84: }
! 85: }
! 86: vici_free_res(res);
! 87: return 0;
! 88: }
! 89:
! 90: /**
! 91: * Register the command.
! 92: */
! 93: static void __attribute__ ((constructor))reg()
! 94: {
! 95: command_register((command_t) {
! 96: algorithms, 'g', "list-algs", "show loaded algorithms",
! 97: {"[--raw|--pretty]"},
! 98: {
! 99: {"help", 'h', 0, "show usage information"},
! 100: {"raw", 'r', 0, "dump raw response message"},
! 101: {"pretty", 'P', 0, "dump raw response message in pretty print"},
! 102: }
! 103: });
! 104: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>