a7f32dc12323535da3fa81fbb131d0539fd26116
[src/app-framework-main.git] / docs / 2.2-config.xml.md
1 # Configuration file - config.xml
2
3 The widgets are described by the W3C's technical recommendations
4 [Packaged Web Apps (Widgets)][widgets] and [XML Digital Signatures for Widgets][widgets-digsig]
5  that specifies the configuration file **config.xml**.
6
7 ## Overview
8
9 The file **config.xml** describes important data of the application
10 to the framework:
11
12 - the unique identifier of the application
13 - the name of the application
14 - the type of the application
15 - the icon of the application
16 - the permissions linked to the application
17 - the services and dependencies of the application
18
19 The file MUST be at the root of the widget and MUST be case sensitively name
20 ***config.xml***.
21
22 The file **config.xml** is a XML file described by the document
23 [widgets].
24
25 Here is the example of the config file for the QML application SmartHome.
26
27 ```xml
28 <?xml version="1.0" encoding="UTF-8"?>
29 <widget xmlns="http://www.w3.org/ns/widgets" id="smarthome" version="0.1">
30   <name>SmartHome</name>
31   <icon src="smarthome.png"/>
32   <content src="qml/smarthome/smarthome.qml" type="text/vnd.qt.qml"/>
33   <description>This is the Smarthome QML demo application. It shows some user interfaces for controlling an
34 automated house. The user interface is completely done with QML.</description>
35   <author>Qt team</author>
36   <license>GPL</license>
37 </widget>
38 ```
39
40 The most important items are:
41
42 - **<widget id="......"\>**: gives the id of the widget. It must be unique.
43
44 - **<widget version="......"\>**: gives the version of the widget
45
46 - **<icon src="..."\>**: gives a path to the icon of the application
47   (can be repeated with different sizes)
48
49 - **<content src="..." type="..."\>**: this indicates the entry point and its type.
50
51 ## Standard elements of "config.xml"
52
53 ### The element widget
54
55 #### the attribute id of widget
56
57 The attribute *id* is mandatory (for version 2.x, blowfish) and must be unique.
58
59 Values for *id* are any non empty string containing only latin letters,
60 arabic digits, and the three characters '.' (dot), '-' (dash) and
61 '\_' (underscore).
62
63 Authors can use a mnemonic id or can pick a unique id using
64 command **uuid** or **uuidgen**.
65
66 ### the attribute version of widget
67
68 The attribute *version* is mandatory (for version 2.x, blowfish).
69
70 Values for *version* are any non empty string containing only latin letters,
71 arabic digits, and the three characters '.' (dot), '-' (dash) and
72 '\_' (underscore).
73
74 Version values are dot separated fields MAJOR.MINOR.REVISION.  
75 Such version would preferably follow guidelines of
76 [semantic versioning][semantic-version].
77
78 ### The element content
79
80 The element *content* is mandatory (for version 2.x, blowfish) and must designate a file
81 (subject to localization) with its attribute *src*.
82
83 The content designed depends on its type. See below for the known types.
84
85 ### The element icon
86
87 The element *icon* is mandatory (for version 2.x, blowfish) and must
88 be unique. It must designate an image file with its attribute *src*.
89
90 ## AGL features
91
92 The AGL framework uses the feature tag for specifying security and binding
93 requirement of the widget.
94
95 Since the migration of the framework to leverage systemd power,
96 the features are of important use to:
97
98 - declare more than just an application
99 - declare the expected dependencies
100 - declare the expected permissions
101 - declare the exported apis
102
103 The specification of [widgets][widgets] is intended to describe
104 only one application.  
105 In the present case, we expect to describe more than just an application.  
106 For example, a publisher could provide a widget containing a service,
107 an application for tuning that service, an application that 
108 leverage the service.  
109 Here, the term of service means a background application that
110 runs without IHM and whose public api can be accessed by other
111 applications.
112
113 So the features are used to describe each of the possible
114 units of widgets.  
115 The "standard" unit in the meaning of [widgets][widgets] 
116 is called the "main" unit.
117
118 ### required-api: feature name="urn:AGL:widget:required-api"
119
120 List of the api required by the widget.
121
122 Each required api must be explicited using a `<param>` entry.
123
124 Example:
125
126 ```xml
127 <feature name="urn:AGL:widget:required-api">
128   <param name="#target" value="main" />>
129   <param name="gps" value="auto" />
130   <param name="afm-main" value="link" />
131 </feature>
132 ```
133
134 This will be *virtually* translated for mustaches to the JSON
135
136 ```json
137 "required-api": [
138    { "name": "gps", "value": "auto" },
139    { "name": "afm-main", "value": "link" }
140  ]
141 ```
142
143 #### required-api: param name="#target"
144
145 OPTIONAL
146
147 Declares the name of the unit requiring the listed apis.
148 Only one instance of the param "#target" is allowed.  
149 When there is not instance of this param, it behave as if
150 the target main was specified.
151
152 #### required-api: param name=[required api name]
153
154 The name is the name of the required API.
155
156 The value describes how to connect to the required api.  
157 It is either:
158
159 - local:  
160   The binding is a local shared object.  
161   In that case, the name is the relative path of the
162   shared object to be loaded.
163
164 - auto:  
165   The framework set automatically the kind of
166   the connection to the API
167
168 - ws:  
169   The framework connect using internal websockets
170
171 - dbus:  
172   The framework connect using internal dbus
173
174 - link:  
175  The framework connect in memory by dynamically linking
176
177 - cloud: [PROPOSAL - NOT IMPLEMENTED]  
178   The framework connect externally using websock.  
179   In that case, the name includes data to access the service.  
180   Example: `<param name="log:https://oic@agl.iot.bzh/cloud/log" value="cloud" />`
181
182 ### required-permission: feature name="urn:AGL:widget:required-permission"
183
184 List of the permissions required by the unit.
185
186 Each required permission must be explicited using a `<param>` entry.
187
188 Example:
189
190 ```xml
191   <feature name="urn:AGL:widget:required-permission">
192     <param name="#target" value="geoloc" />
193     <param name="urn:AGL:permission:real-time" value="required" />
194     <param name="urn:AGL:permission:syscall:*" value="required" />
195   </feature>
196 ```
197
198 This will be *virtually* translated for mustaches to the JSON
199
200 ```json
201 "required-permission":{
202   "urn:AGL:permission:real-time":{
203     "name":"urn:AGL:permission:real-time",
204     "value":"required"
205   },
206   "urn:AGL:permission:syscall:*":{
207     "name":"urn:AGL:permission:syscall:*",
208     "value":"required"
209   }
210 }
211 ```
212
213 #### required-permission: param name="#target"
214
215 OPTIONAL
216
217 Declares the name of the unit requiring the listed permissions.  
218 Only one instance of the param "#target" is allowed.  
219 When there is not instance of this param, it behave as if
220 the target main was specified.
221
222 #### required-permission: param name=[required permission name]
223
224 The value is either:
225
226 - required: the permission is mandatorily needed except if the feature
227   isn't required (required="false") and in that case it is optional.
228 - optional: the permission is optional
229
230 ### provided-unit: feature name="urn:AGL:widget:provided-unit"
231
232 This feature is made for declaring new units
233 for the widget.  
234 Using this feature, a software publisher
235 can provide more than one application in the same widget.
236
237 Example:
238
239 ```xml
240   <feature name="urn:AGL:widget:provided-unit">
241     <param name="#target" value="geoloc" />
242     <param name="description" value="binding of name geoloc" />
243     <param name="content.src" value="index.html" />
244     <param name="content.type" value="application/vnd.agl.service" />
245   </feature>
246 ```
247
248 This will be *virtually* translated for mustaches to the JSON
249
250 ```json
251     {
252       "#target":"geoloc",
253       "description":"binding of name geoloc",
254       "content":{
255         "src":"index.html",
256         "type":"application\/vnd.agl.service"
257       },
258       ...
259     }
260 ```
261
262 #### provided-unit: param name="#target"
263
264 REQUIRED
265
266 Declares the name of the unit. The default unit, the unit
267 of the main of the widget, has the name "main".  
268 The value given here must be unique within the widget file.  
269 It will be used in other places of the widget config.xml file to
270 designate the unit.
271
272 Only one instance of the param "#target" is allowed.  
273 The value can't be "main".
274
275 #### provided-unit: param name="content.type"
276
277 REQUIRED
278
279 The mimetype of the provided unit.
280
281 #### provided-unit: param name="content.src"
282
283 A path to the source
284
285 #### other parameters
286
287 The items that can be set for the main unit
288 can also be set using the params if needed.
289
290 - description
291 - name.content
292 - name.short
293 - ...
294
295 ### provided-api: feature name="urn:AGL:widget:provided-api"
296
297 Use this feature for exporting one or more API of a unit
298 to other widgets of the platform.
299
300 This feature is an important feature of the framework.
301
302 Example:
303
304 ```xml
305   <feature name="urn:AGL:widget:provided-api">
306     <param name="#target" value="geoloc" />
307     <param name="geoloc" value="auto" />
308     <param name="moonloc" value="auto" />
309   </feature>
310 ```
311
312 This will be *virtually* translated for mustaches to the JSON
313
314 ```json
315       "provided-api":[
316         {
317           "name":"geoloc",
318           "value":"auto"
319         },
320         {
321           "name":"moonloc",
322           "value":"auto"
323         }
324       ],
325 ```
326
327 #### provided-api: param name="#target"
328
329 OPTIONAL
330
331 Declares the name of the unit exporting the listed apis.  
332 Only one instance of the param "#target" is allowed.  
333 When there is not instance of this param, it behave as if
334 the target main was specified.
335
336 #### provided-api: param name=[name of exported api]
337
338 The name give the name of the api that is exported.
339
340 The value is one of the following values:
341
342 - ws:  
343   export the api using UNIX websocket
344
345 - dbus:  
346   export the API using dbus
347
348 - auto:  
349   export the api using the default method(s).
350
351 ### file-properties: feature name="urn:AGL:widget:file-properties"
352
353 Use this feature for setting properties to files of the widget.
354 At this time, this feature only allows to set executable flag
355 for making companion program executable explicitly.
356
357 Example:
358
359 ```xml
360   <feature name="urn:AGL:widget:file-properties">
361     <param name="flite" value="executable" />
362     <param name="jtalk" value="executable" />
363   </feature>
364 ```
365
366 #### file-properties: param name="path"
367
368 The name is the relative path of the file whose property
369 must be set.
370
371 The value must be "executable" to make the file executable.
372
373 ## Known content types
374
375 The configuration file ***/etc/afm/afm-unit.conf*** defines
376 how to create systemd units for widgets.
377
378 Known types for the type of content are:
379
380 - ***text/html***:  
381   HTML application,  
382   content.src designates the home page of the application
383
384 - ***application/vnd.agl.native***  
385   AGL compatible native,  
386   content.src designates the relative path of the binary.
387
388 - ***application/vnd.agl.service***:  
389   AGL service, content.src is not used.
390
391 - ***application/x-executable***:  
392   Native application,  
393   content.src designates the relative path of the binary.  
394   For such application, only security setup is made.
395
396 Adding more types is easy, it just need to edit the configuration
397 file ***afm-unit.conf***.
398
399 ### Older content type currently not supported at the moment
400
401 This types were defined previously when the framework was not
402 leveraging systemd.  
403 The transition to systemd let these types out at the moment.
404
405 - ***application/vnd.agl.url***
406 - ***text/vnd.qt.qml***, ***application/vnd.agl.qml***
407 - ***application/vnd.agl.qml.hybrid***
408 - ***application/vnd.agl.html.hybrid***
409
410 <!-- pagebreak -->
411
412 ## The configuration file afm-unit.conf
413
414 The integration of the framework with systemd
415 mainly consists of creating the systemd unit
416 files corresponding to the need and requirements
417 of the installed widgets.
418
419 This configuration file named `afm-unit.conf` installed
420 on the system with the path `/etc/afm/afm-unit.conf`
421 describes how to generate all units from the *config.xml*
422 configuration files of widgets.  
423 The description uses an extended version of the templating 
424 formalism of [mustache][] to describes all the units.
425
426 Let present how it works using the following diagram that
427 describes graphically the workflow of creating the unit
428 files for systemd `afm-unit.conf` from the configuration
429 file of the widget `config.xml`:
430
431 ![make-units](pictures/make-units.svg)
432
433 In a first step, and because [mustache][] is intended
434 to work on JSON representations, the configuration file is
435 translated to an internal JSON representation.  
436 This representation is shown along the examples of the documentation
437 of the config files of widgets.
438
439 In a second step, the mustache template `afm-unit.conf`
440 is instantiated using the C library [mustach][] that follows
441 the rules of [mustache][mustache] and with all its available
442 extensions:
443
444 - use of colon (:) for explicit substitution
445 - test of values with = or =!
446
447 In a third step, the result of instantiating `afm-unit.conf`
448 for the widget is split in units.  
449 To achieve that goal, the lines containing specific directives are searched.  
450 Any directive occupy one full line.  
451 The directives are:
452
453 - %nl
454   Produce an empty line at the end
455 - %begin systemd-unit
456 - %end systemd-unit
457   Delimit the produced unit, its begin and its end
458 - %systemd-unit user
459 - %systemd-unit system
460   Tells the kind of unit (user/system)
461 - %systemd-unit service NAME
462 - %systemd-unit socket NAME
463   Gives the name and type (service or socket) of the unit.  
464   The extension is automatically computed from the type
465   and must not be set in the name.
466 - %systemd-unit wanted-by NAME
467   Tells to install a link to the unit in the wants of NAME
468
469 Then the computed units are then written to the filesystem
470 and inserted in systemd.
471
472 The generated unit files will contain variables for internal
473 use of the framework.  
474 These variables are starting with `X-AFM-`.  
475 The variables starting with `X-AFM-` but not with `X-AFM--` are
476 the public variables.  
477 These variables will be returned by the
478 framework as the details of an application (see **afm-util detail ...**).
479
480 Variables starting with `X-AFM--` are private to the framework.  
481 By example, the variable  `X-AFM--http-port` is used to
482 record the allocated port for applications.
483
484 [mustach]:          https://gitlab.com/jobol/mustach                                "basic C implementation of mustache"
485 [mustache]:         http://mustache.github.io/mustache.5.html                       "mustache - Logic-less templates"
486 [widgets]:          http://www.w3.org/TR/widgets                                    "Packaged Web Apps"
487 [widgets-digsig]:   http://www.w3.org/TR/widgets-digsig                             "XML Digital Signatures for Widgets"
488 [libxml2]:          http://xmlsoft.org/html/index.html                              "libxml2"
489 [app-manifest]:     http://www.w3.org/TR/appmanifest                                "Web App Manifest"
490 [meta-intel]:       https://github.com/01org/meta-intel-iot-security                "A collection of layers providing security technologies"
491 [openssl]:          https://www.openssl.org                                         "OpenSSL"
492 [xmlsec]:           https://www.aleksey.com/xmlsec                                  "XMLSec"
493 [json-c]:           https://github.com/json-c/json-c                                "JSON-c"
494 [d-bus]:            http://www.freedesktop.org/wiki/Software/dbus                   "D-Bus"
495 [libzip]:           http://www.nih.at/libzip                                        "libzip"
496 [cmake]:            https://cmake.org                                               "CMake"
497 [security-manager]: https://wiki.tizen.org/wiki/Security/Tizen_3.X_Security_Manager "Security-Manager"
498 [tizen-security]:   https://wiki.tizen.org/wiki/Security                            "Tizen security home page"
499 [tizen-secu-3]:     https://wiki.tizen.org/wiki/Security/Tizen_3.X_Overview         "Tizen 3 security overview"
500 [semantic-version]: http://semver.org/                                              "Semantic versioning"