Code

Added missing includes identified by strict standard checks.
[libjunos.git] / src / junos.h
1 /*
2  * libJUNOS - src/junos.h
3  * Copyright (C) 2012 Sebastian 'tokkee' Harl <sh@tokkee.org>
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 COPYRIGHT HOLDERS AND CONTRIBUTORS
16  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
19  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
28 /*
29  * Base object used to manage the connection to a JUNOS device.
30  */
32 #ifndef JUNOS_H
33 #define JUNOS_H 1
35 #ifdef HAVE_CONFIG_H
36 #       include "config.h"
37 #endif
39 #include <stdio.h>
41 #include <libxml/tree.h>
43 #if defined(DEBUG) && (! defined(NDEBUG))
44 #       define dprintf(...) fprintf(stderr, "LIBJUNOS DEBUG: "__VA_ARGS__)
45 #else
46 #       define dprintf(...) /* noop */
47 #endif
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
53 /*
54  * data types
55  */
57 typedef struct junos junos_t;
59 /* method invocation */
61 enum {
62         JUNOS_NO_ARGS = 0,
63         JUNOS_ARG_TOGGLE,
64         JUNOS_ARG_TOGGLE_NO,
65         JUNOS_ARG_STRING,
66         JUNOS_ARG_INTEGER,
67         JUNOS_ARG_DOUBLE,
68         JUNOS_ARG_DOM,
69         JUNOS_ATTR_STRING,
70         JUNOS_ATTR_INTEGER,
71         JUNOS_ATTR_DOUBLE,
72 };
74 /* string buffer */
76 typedef struct junos_strbuf junos_strbuf_t;
78 /* netrc */
80 typedef struct {
81         char *machine;
82         char *login;
83         char *password;
84         /* we don't care for 'account' or 'macdef' */
85 } junos_netrc_entry_t;
87 typedef struct junos_netrc junos_netrc_t;
89 /* access types */
91 typedef struct junos_ssh_access junos_ssh_access_t;
93 /* error information */
95 enum {
96         JUNOS_OK = 0,
97         JUNOS_SYS_ERROR,
98         JUNOS_GAI_ERROR,
99         JUNOS_XML_ERROR,
100         JUNOS_ACCESS_ERROR
101 };
103 typedef struct {
104         int  type;
105         int  error;
106         char errmsg[1024];
107 } junos_error_t;
109 #define JUNOS_NO_ERROR { JUNOS_OK, 0, "" }
111 /*
112  * JUNOS object
113  */
115 int
116 junos_init(void);
118 junos_t *
119 junos_new(char *hostname, char *username, char *password);
121 char *
122 junos_get_hostname(junos_t *junos);
123 char *
124 junos_get_username(junos_t *junos);
125 char *
126 junos_get_password(junos_t *junos);
128 int
129 junos_connect(junos_t *junos);
131 xmlDocPtr
132 junos_invoke_method(junos_t *junos, const char *name, ...);
134 #define junos_simple_method(junos, name) \
135         junos_invoke_method((junos), (name), JUNOS_NO_ARGS)
137 int
138 junos_disconnect(junos_t *junos);
140 void
141 junos_free(junos_t *junos);
143 /*
144  * string buffer
145  */
147 junos_strbuf_t *
148 junos_strbuf_new(size_t size);
150 void
151 junos_strbuf_free(junos_strbuf_t *strbuf);
153 ssize_t
154 junos_strbuf_sprintf(junos_strbuf_t *strbuf, const char *fmt, ...);
156 ssize_t
157 junos_strbuf_vsprintf(junos_strbuf_t *strbuf, const char *fmt, va_list ap);
159 char *
160 junos_strbuf_string(junos_strbuf_t *strbuf);
162 size_t
163 junos_strbuf_len(junos_strbuf_t *strbuf);
165 /*
166  * netrc
167  */
169 junos_netrc_t *
170 junos_netrc_read(char *filename);
172 void
173 junos_netrc_free(junos_netrc_t *netrc);
175 const junos_netrc_entry_t *
176 junos_netrc_lookup(junos_netrc_t *netrc, char *hostname);
178 /*
179  * error handling
180  */
182 const char *
183 junos_get_errstr(junos_t *junos);
185 int
186 junos_set_error(junos_t *junos, int type, int error,
187                 char *msg_prefix, ...);
188 int
189 junos_set_verror(junos_t *junos, int type, int error,
190                 char *msg_prefix, va_list ap);
192 int
193 junos_set_ssh_error(junos_error_t *err, junos_ssh_access_t *ssh,
194                 char *msg_prefix, ...);
195 int
196 junos_set_ssh_verror(junos_error_t *err, junos_ssh_access_t *ssh,
197                 char *msg_prefix, va_list ap);
199 void
200 junos_clear_error(junos_t *junos);
202 /*
203  * SSH
204  */
206 junos_ssh_access_t *
207 junos_ssh_new(junos_t *junos);
209 int
210 junos_ssh_connect(junos_ssh_access_t *ssh);
212 ssize_t
213 junos_ssh_recv(junos_ssh_access_t *ssh, char *buf, size_t buf_len);
215 ssize_t
216 junos_ssh_send(junos_ssh_access_t *ssh, char *buf, size_t buf_len);
218 int
219 junos_ssh_disconnect(junos_ssh_access_t *ssh);
221 int
222 junos_ssh_free(junos_ssh_access_t *ssh);
224 #ifdef __cplusplus
225 } /* extern "C" */
226 #endif
228 #endif /* ! JUNOS_H */
230 /* vim: set tw=78 sw=4 ts=4 noexpandtab : */