d35b7f4230981bb99e789b453400c949cbfa7b67
[src/app-framework-main.git] / src / wgtpkg.h
1 /*
2  Copyright 2015 IoT.bzh
3
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7
8      http://www.apache.org/licenses/LICENSE-2.0
9
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 */
16
17
18 #include <libxml/tree.h>
19 #include "config.h"
20
21 struct filedesc;
22
23 /**************************************************************/
24 /* from wgtpkg-base64 */
25
26 extern char *base64encw(const char *buffer, int length, int width);
27 extern char *base64enc(const char *buffer, int length);
28 extern int base64dec(const char *buffer, char **output);
29 extern int base64eq(const char *buf1, const char *buf2);
30
31 /**************************************************************/
32 /* from wgtpkg-certs */
33
34 extern void clear_certificates();
35 extern int add_certificate_b64(const char *b64);
36
37 /**************************************************************/
38 /* from wgtpkg-digsig */
39
40 /* verify the digital signature in file */
41 extern int verify_digsig(struct filedesc *fdesc);
42
43 /* create a digital signature */
44 extern int create_digsig(int index, const char *key, const char **certs);
45
46 /* check the signatures of the current directory */
47 extern int check_all_signatures();
48
49 /**************************************************************/
50 /* from wgtpkg-files */
51
52 enum entrytype {
53         type_unset = 0,
54         type_file = 1,
55         type_directory = 2
56 };
57
58 enum fileflag {
59         flag_referenced = 1,
60         flag_opened = 2,
61         flag_author_signature = 4,
62         flag_distributor_signature = 8,
63         flag_signature = 12
64 };
65
66 struct filedesc {
67         enum entrytype type;
68         unsigned int flags;
69         unsigned int signum;
70         unsigned int zindex;
71         char name[1];
72 };
73
74 extern void file_reset();
75 extern void file_clear_flags();
76 extern unsigned int file_count();
77 extern struct filedesc *file_of_index(unsigned int index);
78 extern struct filedesc *file_of_name(const char *name);
79 extern struct filedesc *file_add_directory(const char *name);
80 extern struct filedesc *file_add_file(const char *name);
81 extern int fill_files();
82
83 extern unsigned int signature_count();
84 extern struct filedesc *signature_of_index(unsigned int index);
85 extern struct filedesc *create_signature(unsigned int number);
86 extern struct filedesc *get_signature(unsigned int number);
87
88 extern int file_set_prop(struct filedesc *file, const char *name, const char *value);
89 extern const char *file_get_prop(struct filedesc *file, const char *name);
90
91 /**************************************************************/
92 /* from wgtpkg-verbose */
93 extern int verbosity;
94 #define warning(...) do{if(verbosity)syslog(LOG_WARNING,__VA_ARGS__);}while(0)
95 #define notice(...)  do{if(verbosity)syslog(LOG_NOTICE,__VA_ARGS__);}while(0)
96 #define info(...)    do{if(verbosity)syslog(LOG_INFO,__VA_ARGS__);}while(0)
97 #define debug(...)   do{if(verbosity>1)syslog(LOG_DEBUG,__VA_ARGS__);}while(0)
98 extern int verbose_scan_args(int argc, char **argv);
99
100 /**************************************************************/
101 /* from wgtpkg-workdir */
102
103 extern int enter_workdir(int clean);
104 extern void remove_workdir();
105 extern int make_workdir(int reuse);
106 extern int set_workdir(const char *name, int create);
107
108 /**************************************************************/
109 /* from wgtpkg-xmlsec */
110
111 extern int xmlsec_init();
112 extern void xmlsec_shutdown();
113 extern int xmlsec_verify(xmlNodePtr node);
114 extern xmlDocPtr xmlsec_create(int index, const char *key, const char **certs);
115
116 /**************************************************************/
117 /* from wgtpkg-zip */
118
119 /* read (extract) 'zipfile' in current directory */
120 extern int zread(const char *zipfile, unsigned long long maxsize);
121
122 /* write (pack) content of the current directory in 'zipfile' */
123 extern int zwrite(const char *zipfile);
124
125