| Code Coverage: vinyl-cache/include/vcli_serve.h |
| |
| 82217aa4fc7094b3610340078afaf78cd95a8ec9 |
| |
| 0 |
|
/*- |
| 1 |
|
* Copyright (c) 2006 Verdens Gang AS |
| 2 |
|
* Copyright (c) 2006-2011 Varnish Software AS |
| 3 |
|
* All rights reserved. |
| 4 |
|
* |
| 5 |
|
* Author: Poul-Henning Kamp <phk@phk.freebsd.dk> |
| 6 |
|
* |
| 7 |
|
* SPDX-License-Identifier: BSD-2-Clause |
| 8 |
|
* |
| 9 |
|
* Redistribution and use in source and binary forms, with or without |
| 10 |
|
* modification, are permitted provided that the following conditions |
| 11 |
|
* are met: |
| 12 |
|
* 1. Redistributions of source code must retain the above copyright |
| 13 |
|
* notice, this list of conditions and the following disclaimer. |
| 14 |
|
* 2. Redistributions in binary form must reproduce the above copyright |
| 15 |
|
* notice, this list of conditions and the following disclaimer in the |
| 16 |
|
* documentation and/or other materials provided with the distribution. |
| 17 |
|
* |
| 18 |
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
| 19 |
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 20 |
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 |
|
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE |
| 22 |
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 23 |
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 24 |
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 25 |
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 26 |
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 27 |
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 28 |
|
* SUCH DAMAGE. |
| 29 |
|
* |
| 30 |
|
* Vinyl process internal CLI stuff. |
| 31 |
|
* |
| 32 |
|
* XXX: at a latter date we may want to move some to cli.h/libvinylapi |
| 33 |
|
*/ |
| 34 |
|
|
| 35 |
|
#include "vcli.h" |
| 36 |
|
|
| 37 |
|
struct cli; /* NB: struct cli is opaque at this level. */ |
| 38 |
|
struct VCLS; |
| 39 |
|
|
| 40 |
|
typedef void cli_func_t(struct cli*, const char * const *av, void *priv); |
| 41 |
|
|
| 42 |
|
struct cli_cmd_desc { |
| 43 |
|
/* Must match CLI_CMD macro in include/tbl/cli_cmds.h */ |
| 44 |
|
const char *request; |
| 45 |
|
const char *syntax; |
| 46 |
|
const char *help; |
| 47 |
|
const char *doc; |
| 48 |
|
int minarg; |
| 49 |
|
int maxarg; |
| 50 |
|
}; |
| 51 |
|
|
| 52 |
|
#define CLI_CMD(U,l,s,h,d,m,M) extern const struct cli_cmd_desc CLICMD_##U[1]; |
| 53 |
|
#include "tbl/cli_cmds.h" |
| 54 |
|
|
| 55 |
|
/* A CLI command */ |
| 56 |
|
struct cli_proto { |
| 57 |
|
const struct cli_cmd_desc *desc; |
| 58 |
|
const char *flags; |
| 59 |
|
|
| 60 |
|
/* Dispatch information */ |
| 61 |
|
cli_func_t *func; |
| 62 |
|
cli_func_t *jsonfunc; |
| 63 |
|
void *priv; |
| 64 |
|
|
| 65 |
|
unsigned auth; |
| 66 |
|
VTAILQ_ENTRY(cli_proto) list; |
| 67 |
|
}; |
| 68 |
|
|
| 69 |
|
/* a CLI session */ |
| 70 |
|
struct cli { |
| 71 |
|
unsigned magic; |
| 72 |
3123 |
#define CLI_MAGIC 0x4038d570 |
| 73 |
|
void *priv; |
| 74 |
|
struct vsb *sb; |
| 75 |
|
enum VCLI_status_e result; |
| 76 |
|
struct vsb *cmd; |
| 77 |
|
unsigned auth; |
| 78 |
|
char challenge[34]; |
| 79 |
|
char *ident; |
| 80 |
|
struct VCLS *cls; |
| 81 |
|
volatile unsigned *limit; |
| 82 |
|
}; |
| 83 |
|
|
| 84 |
|
/* The implementation must provide these functions */ |
| 85 |
|
int VCLI_Overflow(struct cli *cli); |
| 86 |
|
void VCLI_Out(struct cli *cli, const char *fmt, ...) v_printflike_(2, 3); |
| 87 |
|
void VCLI_Quote(struct cli *cli, const char *str); |
| 88 |
|
void VCLI_JSON_str(struct cli *cli, const char *str); |
| 89 |
|
void VCLI_JSON_begin(struct cli *cli, unsigned ver, const char * const * av); |
| 90 |
|
void VCLI_JSON_end(struct cli *cli); |
| 91 |
|
void VCLI_SetResult(struct cli *cli, unsigned r); |
| 92 |
|
|
| 93 |
|
typedef int cls_cb_f(void *priv); |
| 94 |
|
typedef void cls_cbc_f(const struct cli*); |
| 95 |
|
struct VCLS *VCLS_New(struct VCLS *); |
| 96 |
|
void VCLS_SetHooks(struct VCLS *, cls_cbc_f *, cls_cbc_f *); |
| 97 |
|
void VCLS_SetLimit(struct VCLS *, volatile unsigned *); |
| 98 |
|
struct cli *VCLS_AddFd(struct VCLS *cs, int fdi, int fdo, cls_cb_f *closefunc, |
| 99 |
|
void *priv); |
| 100 |
|
void VCLS_AddFunc(struct VCLS *cs, unsigned auth, struct cli_proto *clp); |
| 101 |
|
int VCLS_Poll(struct VCLS *cs, const struct cli*, int timeout); |
| 102 |
|
void VCLS_Destroy(struct VCLS **); |
| 103 |
|
|
| 104 |
|
/* From libvinyl/cli.c */ |
| 105 |
|
cli_func_t VCLS_func_close; |
| 106 |
|
cli_func_t VCLS_func_help; |
| 107 |
|
cli_func_t VCLS_func_help_json; |
| 108 |
|
cli_func_t VCLS_func_ping; |
| 109 |
|
cli_func_t VCLS_func_ping_json; |
| 110 |
|
|
| 111 |
|
/* VTE integration */ |
| 112 |
|
int VCLI_VTE_format(void *priv, const char *fmt, ...) v_printflike_(2, 3); |