1 /*
2  * Copyright (c) 2014 NLNet Labs
3  * Copyright (c) 2014 OpenDNSSEC AB (svb)
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
19  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
21  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
23  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
25  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  */
28 
29 #ifndef DAEMON_CLIENTPIPE_H
30 #define DAEMON_CLIENTPIPE_H
31 
32 #include "config.h"
33 #include <stdint.h>
34 
35 /* 1 on succes 0 on fail*/
36 int client_printf(int sockfd, const char * format, ...)
37 #ifdef HAVE___ATTRIBUTE__
38      __attribute__ ((format (printf, 2, 3)))
39 #endif
40      ;
41 
42 int client_printf_err(int sockfd, const char * format, ...)
43 #ifdef HAVE___ATTRIBUTE__
44      __attribute__ ((format (printf, 2, 3)))
45 #endif
46      ;
47 
48 
49 /**
50  * Client part of prompt handling
51  *
52  * Block on stdin and send to daemon
53  *
54  * \param sockfd, pipe to daemon.
55  * \return 1 success, 0 error
56  */
57 int client_handleprompt(int sockfd);
58 
59 enum msg_type {
60 	CLIENT_OPC_STDOUT = 0,
61 	CLIENT_OPC_STDERR,
62 	CLIENT_OPC_STDIN,
63 	CLIENT_OPC_PROMPT,
64 	CLIENT_OPC_EXIT
65 };
66 
67 /* 1 on succes, 0 on fail */
68 int client_exit(int sockfd, char exitcode);
69 int client_stdin(int sockfd, const char *cmd, uint16_t count);
70 int client_stdout(int sockfd, const char *cmd, uint16_t count);
71 int client_stderr(int sockfd, const char *cmd, uint16_t count);
72 
73 #endif /* DAEMON_CLIENTPIPE_H */
74