Annotation of embedaddon/strongswan/src/swanctl/commands/reload_settings.c, revision 1.1

1.1     ! misho       1: /*
        !             2:  * Copyright (C) 2014 Martin Willi
        !             3:  * Copyright (C) 2014 revosec AG
        !             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: static int reload_settings(vici_conn_t *conn)
        !            21: {
        !            22:        vici_req_t *req;
        !            23:        vici_res_t *res;
        !            24:        char *arg;
        !            25:        int ret = 0;
        !            26:        command_format_options_t format = COMMAND_FORMAT_NONE;
        !            27: 
        !            28:        while (TRUE)
        !            29:        {
        !            30:                switch (command_getopt(&arg))
        !            31:                {
        !            32:                        case 'h':
        !            33:                                return command_usage(NULL);
        !            34:                        case 'P':
        !            35:                                format |= COMMAND_FORMAT_PRETTY;
        !            36:                                /* fall through to raw */
        !            37:                        case 'r':
        !            38:                                format |= COMMAND_FORMAT_RAW;
        !            39:                                continue;
        !            40:                        case EOF:
        !            41:                                break;
        !            42:                        default:
        !            43:                                return command_usage("invalid --reload-settings option");
        !            44:                }
        !            45:                break;
        !            46:        }
        !            47: 
        !            48:        req = vici_begin("reload-settings");
        !            49:        res = vici_submit(req, conn);
        !            50:        if (!res)
        !            51:        {
        !            52:                ret = errno;
        !            53:                fprintf(stderr, "reload-settings request failed: %s\n", strerror(errno));
        !            54:                return ret;
        !            55:        }
        !            56:        if (format & COMMAND_FORMAT_RAW)
        !            57:        {
        !            58:                vici_dump(res, "reload-settings reply",
        !            59:                                  format & COMMAND_FORMAT_PRETTY, stdout);
        !            60:        }
        !            61:        else
        !            62:        {
        !            63:                if (!streq(vici_find_str(res, "no", "success"), "yes"))
        !            64:                {
        !            65:                        fprintf(stderr, "reload-settings failed: %s\n",
        !            66:                                        vici_find_str(res, "", "errmsg"));
        !            67:                        ret = 1;
        !            68:                }
        !            69:        }
        !            70:        vici_free_res(res);
        !            71:        return ret;
        !            72: }
        !            73: 
        !            74: /**
        !            75:  * Register the command.
        !            76:  */
        !            77: static void __attribute__ ((constructor))reg()
        !            78: {
        !            79:        command_register((command_t) {
        !            80:                reload_settings, 'r', "reload-settings", "reload daemon strongswan.conf",
        !            81:                {"[--raw|--pretty]"},
        !            82:                {
        !            83:                        {"help",                'h', 0, "show usage information"},
        !            84:                        {"raw",                 'r', 0, "dump raw response message"},
        !            85:                        {"pretty",              'P', 0, "dump raw response message in pretty print"},
        !            86:                }
        !            87:        });
        !            88: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>