Fix homescreen start on yocto/Zeus
[src/app-framework-main.git] / src / wgtpkg-info.c
1 /*
2  Copyright (C) 2015-2020 IoT.bzh
3
4  author: José Bollo <jose.bollo@iot.bzh>
5
6  Licensed under the Apache License, Version 2.0 (the "License");
7  you may not use this file except in compliance with the License.
8  You may obtain a copy of the License at
9
10      http://www.apache.org/licenses/LICENSE-2.0
11
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  See the License for the specific language governing permissions and
16  limitations under the License.
17 */
18
19 #include <stdlib.h>
20 #include <stdio.h>
21 #include <dirent.h>
22 #include <unistd.h>
23 #include <limits.h>
24 #include <errno.h>
25 #include <getopt.h>
26
27 #include <libxml/tree.h>
28
29 #include "verbose.h"
30 #include "wgtpkg-workdir.h"
31 #include "wgtpkg-files.h"
32 #include "wgtpkg-zip.h"
33 #include "wgtpkg-digsig.h"
34 #include "wgtpkg-xmlsec.h"
35 #include "wgt.h"
36 #include "wgt-info.h"
37
38 static const char appname[] = "wgtpkg-info";
39
40 static void show(const char *wgtfile);
41
42 static void version()
43 {
44         printf(
45                 "\n"
46                 "  %s  version="AFM_VERSION"\n"
47                 "\n"
48                 "  Copyright (C) 2015-2020 \"IoT.bzh\"\n"
49                 "  AFB comes with ABSOLUTELY NO WARRANTY.\n"
50                 "  Licence Apache 2\n"
51                 "\n",
52                 appname
53         );
54 }
55
56 static void usage()
57 {
58         printf(
59                 "usage: %s [-q] [-v] wgtfile...\n"
60                 "\n"
61                 "   -q            quiet\n"
62                 "   -v            verbose\n"
63                 "   -V            version\n"
64                 "\n",
65                 appname
66         );
67 }
68
69 static struct option options[] = {
70         { "help",        no_argument,       NULL, 'h' },
71         { "quiet",       no_argument,       NULL, 'q' },
72         { "verbose",     no_argument,       NULL, 'v' },
73         { "version",     no_argument,       NULL, 'V' },
74         { NULL, 0, NULL, 0 }
75 };
76
77 /* info the widgets of the list */
78 int main(int ac, char **av)
79 {
80         int i;
81         char *wpath;
82
83         LOGUSER(appname);
84
85         xmlsec_init();
86
87         for (;;) {
88                 i = getopt_long(ac, av, "hqvV", options, NULL);
89                 if (i < 0)
90                         break;
91                 switch (i) {
92                 case 'h':
93                         usage();
94                         return 0;
95                 case 'q':
96                         if (verbosity)
97                                 verbosity--;
98                         break;
99                 case 'v':
100                         verbosity++;
101                         break;
102                 case 'V':
103                         version();
104                         return 0;
105                 case ':':
106                         ERROR("missing argument value");
107                         return 1;
108                 default:
109                         ERROR("unrecognized option");
110                         return 1;
111                 }
112         }
113
114         /* canonic names for files */
115         av += optind;
116         for (i = 0 ; av[i] != NULL ; i++) {
117                 wpath = realpath(av[i], NULL);
118                 if (wpath == NULL) {
119                         ERROR("error while getting realpath of %dth widget: %s", i+1, av[i]);
120                         return 1;
121                 }
122                 av[i] = wpath;
123         }
124
125         /* info widgets */
126         for ( ; *av ; av++)
127                 show(*av);
128
129         return 0;
130 }
131
132 static int check_and_show()
133 {
134         struct wgt_info *ifo;
135
136         ifo = wgt_info_createat(workdirfd, NULL, 1, 1, 1);
137         if (!ifo)
138                 return -1;
139         wgt_info_dump(ifo, 1, "");
140         wgt_info_unref(ifo);
141         return 0;
142 }
143
144 /* install the widget of the file */
145 static void show(const char *wgtfile)
146 {
147         NOTICE("-- INFO for widget %s --", wgtfile);
148
149         /* workdir */
150         if (make_workdir("/tmp", "UNPACK", 0)) {
151                 ERROR("failed to create a working directory");
152                 return;
153         }
154
155         if (zread(wgtfile, 0))
156                 goto error2;
157
158         if (check_all_signatures(1)) /* info even on WGT without signature */
159                 goto error2;
160
161         check_and_show();
162
163 error2:
164         remove_workdir();
165         return;
166 }
167