xref: /openbsd/usr.sbin/rpki-client/rrdp.h (revision 2bb4ff25)
1 /*	$OpenBSD: rrdp.h,v 1.9 2022/05/19 13:12:35 claudio Exp $ */
2 /*
3  * Copyright (c) 2020 Nils Fisher <nils_fisher@hotmail.com>
4  * Copyright (c) 2021 Claudio Jeker <claudio@openbsd.org>
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 #ifndef _RRDPH_
19 #define _RRDPH_
20 
21 #define RRDP_XMLNS	"http://www.ripe.net/rpki/rrdp"
22 #define MAX_VERSION 1
23 
24 /* save everyone doing this code over and over */
25 #define PARSE_FAIL(p, ...) do {		\
26 	XML_StopParser(p, XML_FALSE);	\
27 	warnx(__VA_ARGS__);		\
28 	return;				\
29 } while (0)
30 
31 enum rrdp_task {
32 	NOTIFICATION,
33 	SNAPSHOT,
34 	DELTA,
35 };
36 
37 struct rrdp;
38 
39 struct publish_xml {
40 	char			*uri;
41 	char			*data;
42 	char			 hash[SHA256_DIGEST_LENGTH];
43 	size_t			 data_length;
44 	enum publish_type	 type;
45 };
46 
47 /* rrdp generic */
48 char			*xstrdup(const char *);
49 void			 rrdp_publish_file(struct rrdp *, struct publish_xml *,
50 			    unsigned char *, size_t);
51 
52 /* rrdp util */
53 struct publish_xml	*new_publish_xml(enum publish_type, char *,
54 			    char *, size_t);
55 void			 free_publish_xml(struct publish_xml *);
56 int			 publish_add_content(struct publish_xml *,
57 			    const char *, int);
58 int			 publish_done(struct rrdp *, struct publish_xml *);
59 
60 /* notification */
61 struct notification_xml;
62 
63 struct notification_xml	*new_notification_xml(XML_Parser,
64 			    struct rrdp_session *, struct rrdp_session *,
65 			    const char *);
66 void			 free_notification_xml(struct notification_xml *);
67 enum rrdp_task		 notification_done(struct notification_xml *,
68 			    char *);
69 const char		*notification_get_next(struct notification_xml *,
70 			    char *, size_t, enum rrdp_task);
71 int			 notification_delta_done(struct notification_xml *);
72 void			 log_notification_xml(struct notification_xml *);
73 
74 /* snapshot */
75 struct snapshot_xml;
76 
77 struct snapshot_xml	*new_snapshot_xml(XML_Parser, struct rrdp_session *,
78 			    struct rrdp *);
79 void			 free_snapshot_xml(struct snapshot_xml *);
80 void			 log_snapshot_xml(struct snapshot_xml *);
81 
82 /* delta */
83 struct delta_xml;
84 
85 struct delta_xml	*new_delta_xml(XML_Parser, struct rrdp_session *,
86 			    struct rrdp *);
87 void			 free_delta_xml(struct delta_xml *);
88 void			 log_delta_xml(struct delta_xml *);
89 
90 #endif /* _RRDPH_ */
91