2be937135b054a61c34b8a0fd2a0c3c90f2e8679
[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 explicit 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: OBSOLETE SINCE FF (AGL6), PROVIDED FOR COMPATIBILITY 
160   Use the feature **urn:AGL:widget:required-binding** instead.
161   The binding is a local shared object.  
162   In that case, the name is the relative path of the
163   shared object to be loaded.
164
165 - auto:  
166   The framework set automatically the kind of
167   the connection to the API
168
169 - ws:  
170   The framework connect using internal websockets
171
172 - dbus:  
173   The framework connect using internal dbus
174
175 - cloud: [PROPOSAL - NOT IMPLEMENTED]  
176   The framework connect externally using websock.  
177   In that case, the name includes data to access the service.  
178   Example: `<param name="log:https://oic@agl.iot.bzh/cloud/log" value="cloud" />`
179
180 ### required-binding: feature name="urn:AGL:widget:required-binding"
181
182 List of the bindings required by the widget.
183
184 Note: Since AGL 6 (FF - Funky Flounder),
185 the binder implements bindings version 3 that allow the declaration
186 of 0, 1 or more APIs by one binding. In other words, the equivalency
187 one binding = one API is lost. At the same time the framework added
188 the ability to use bindings exported by other widgets.
189
190 Each required binding must be explicit using a `<param>` entry.
191
192 Example:
193
194 ```xml
195 <feature name="urn:AGL:widget:required-binding">
196   <param name="libexec/binding-gps.so" value="local" />
197   <param name="extra" value="extern" />
198 </feature>
199 ```
200
201 This will be *virtually* translated for mustaches to the JSON
202
203 ```json
204 "required-binding": [
205    { "name": "libexec/binding-gps.so", "value": "local" },
206    { "name": "extra", "value": "extern" }
207  ]
208 ```
209
210 #### required-binding: param name=[name or path]
211
212 The name or the path of the required BINDING.
213
214 The value describes how to connect to the required binding.
215 It is either:
216
217 - local:
218   The binding is a local shared object.  
219   In that case, the name is the relative path of the
220   shared object to be loaded.
221
222 - extern:
223   The binding is external. The name is the exported binding name.
224   See provided-binding.
225
226 ### provided-binding: feature name="urn:AGL:widget:provided-binding"
227
228 This feature allows to export a binding to other binders.
229 The bindings whose relative name is given as value is exported to
230 other binders under the given name.
231
232 Each provided binding must be explicit using a `<param>` entry.
233
234 Example:
235
236 ```xml
237 <feature name="urn:AGL:widget:provided-binding">
238   <param name="extra" value="export/binding-gps.so" />
239 </feature>
240 ```
241
242 This will be *virtually* translated for mustaches to the JSON
243
244 ```json
245 "provided-binding": [
246    { "name": "extra", "value": "export/binding-gps.so" }
247  ]
248 ```
249
250 #### provided-binding: param name=[exported name]
251
252 Exports a local binding to other applications.
253
254 The value must contain the path to the exported binding.
255
256 ### required-permission: feature name="urn:AGL:widget:required-permission"
257
258 List of the permissions required by the unit.
259
260 Each required permission must be explicit using a `<param>` entry.
261
262 Example:
263
264 ```xml
265   <feature name="urn:AGL:widget:required-permission">
266     <param name="#target" value="geoloc" />
267     <param name="urn:AGL:permission:real-time" value="required" />
268     <param name="urn:AGL:permission:syscall:*" value="required" />
269   </feature>
270 ```
271
272 This will be *virtually* translated for mustaches to the JSON
273
274 ```json
275 "required-permission":{
276   "urn:AGL:permission:real-time":{
277     "name":"urn:AGL:permission:real-time",
278     "value":"required"
279   },
280   "urn:AGL:permission:syscall:*":{
281     "name":"urn:AGL:permission:syscall:*",
282     "value":"required"
283   }
284 }
285 ```
286
287 #### required-permission: param name="#target"
288
289 OPTIONAL
290
291 Declares the name of the unit requiring the listed permissions.  
292 Only one instance of the param "#target" is allowed.  
293 When there is not instance of this param, it behave as if
294 the target main was specified.
295
296 #### required-permission: param name=[required permission name]
297
298 The value is either:
299
300 - required: the permission is mandatorily needed except if the feature
301   isn't required (required="false") and in that case it is optional.
302 - optional: the permission is optional
303
304 ### provided-unit: feature name="urn:AGL:widget:provided-unit"
305
306 This feature is made for declaring new units
307 for the widget.  
308 Using this feature, a software publisher
309 can provide more than one application in the same widget.
310
311 Example:
312
313 ```xml
314   <feature name="urn:AGL:widget:provided-unit">
315     <param name="#target" value="geoloc" />
316     <param name="description" value="binding of name geoloc" />
317     <param name="content.src" value="index.html" />
318     <param name="content.type" value="application/vnd.agl.service" />
319   </feature>
320 ```
321
322 This will be *virtually* translated for mustaches to the JSON
323
324 ```json
325     {
326       "#target":"geoloc",
327       "description":"binding of name geoloc",
328       "content":{
329         "src":"index.html",
330         "type":"application\/vnd.agl.service"
331       },
332       ...
333     }
334 ```
335
336 #### provided-unit: param name="#target"
337
338 REQUIRED
339
340 Declares the name of the unit. The default unit, the unit
341 of the main of the widget, has the name "main".  
342 The value given here must be unique within the widget file.  
343 It will be used in other places of the widget config.xml file to
344 designate the unit.
345
346 Only one instance of the param "#target" is allowed.  
347 The value can't be "main".
348
349 #### provided-unit: param name="content.type"
350
351 REQUIRED
352
353 The mimetype of the provided unit.
354
355 #### provided-unit: param name="content.src"
356
357 A path to the source
358
359 #### other parameters
360
361 The items that can be set for the main unit
362 can also be set using the params if needed.
363
364 - description
365 - name.content
366 - name.short
367 - ...
368
369 ### provided-api: feature name="urn:AGL:widget:provided-api"
370
371 Use this feature for exporting one or more API of a unit
372 to other widgets of the platform.
373
374 This feature is an important feature of the framework.
375
376 Example:
377
378 ```xml
379   <feature name="urn:AGL:widget:provided-api">
380     <param name="#target" value="geoloc" />
381     <param name="geoloc" value="auto" />
382     <param name="moonloc" value="auto" />
383   </feature>
384 ```
385
386 This will be *virtually* translated for mustaches to the JSON
387
388 ```json
389       "provided-api":[
390         {
391           "name":"geoloc",
392           "value":"auto"
393         },
394         {
395           "name":"moonloc",
396           "value":"auto"
397         }
398       ],
399 ```
400
401 #### provided-api: param name="#target"
402
403 OPTIONAL
404
405 Declares the name of the unit exporting the listed apis.  
406 Only one instance of the param "#target" is allowed.  
407 When there is not instance of this param, it behave as if
408 the target main was specified.
409
410 #### provided-api: param name=[name of exported api]
411
412 The name give the name of the api that is exported.
413
414 The value is one of the following values:
415
416 - ws:  
417   export the api using UNIX websocket
418
419 - dbus:  
420   export the API using dbus
421
422 - auto:  
423   export the api using the default method(s).
424
425 ### file-properties: feature name="urn:AGL:widget:file-properties"
426
427 Use this feature for setting properties to files of the widget.
428 At this time, this feature only allows to set executable flag
429 for making companion program executable explicitly.
430
431 Example:
432
433 ```xml
434   <feature name="urn:AGL:widget:file-properties">
435     <param name="flite" value="executable" />
436     <param name="jtalk" value="executable" />
437   </feature>
438 ```
439
440 #### file-properties: param name="path"
441
442 The name is the relative path of the file whose property
443 must be set.
444
445 The value must be "executable" to make the file executable.
446
447 ## Known content types
448
449 The configuration file ***/etc/afm/afm-unit.conf*** defines
450 how to create systemd units for widgets.
451
452 Known types for the type of content are:
453
454 - ***text/html***:  
455   HTML application,  
456   content.src designates the home page of the application
457
458 - ***application/vnd.agl.native***  
459   AGL compatible native,  
460   content.src designates the relative path of the binary.
461
462 - ***application/vnd.agl.service***:  
463   AGL service, content.src is not used.
464
465 - ***application/x-executable***:  
466   Native application,  
467   content.src designates the relative path of the binary.  
468   For such application, only security setup is made.
469
470 Adding more types is easy, it just need to edit the configuration
471 file ***afm-unit.conf***.
472
473 ### Older content type currently not supported at the moment
474
475 This types were defined previously when the framework was not
476 leveraging systemd.  
477 The transition to systemd let these types out at the moment.
478
479 - ***application/vnd.agl.url***
480 - ***text/vnd.qt.qml***, ***application/vnd.agl.qml***
481 - ***application/vnd.agl.qml.hybrid***
482 - ***application/vnd.agl.html.hybrid***
483
484 <!-- pagebreak -->
485
486 ## The configuration file afm-unit.conf
487
488 The integration of the framework with systemd
489 mainly consists of creating the systemd unit
490 files corresponding to the need and requirements
491 of the installed widgets.
492
493 This configuration file named `afm-unit.conf` installed
494 on the system with the path `/etc/afm/afm-unit.conf`
495 describes how to generate all units from the *config.xml*
496 configuration files of widgets.  
497 The description uses an extended version of the templating 
498 formalism of [mustache][] to describes all the units.
499
500 Let present how it works using the following diagram that
501 describes graphically the workflow of creating the unit
502 files for systemd `afm-unit.conf` from the configuration
503 file of the widget `config.xml`:
504
505 ![make-units](pictures/make-units.svg)
506
507 In a first step, and because [mustache][] is intended
508 to work on JSON representations, the configuration file is
509 translated to an internal JSON representation.  
510 This representation is shown along the examples of the documentation
511 of the config files of widgets.
512
513 In a second step, the mustache template `afm-unit.conf`
514 is instantiated using the C library [mustach][] that follows
515 the rules of [mustache][mustache] and with all its available
516 extensions:
517
518 - use of colon (:) for explicit substitution
519 - test of values with = or =!
520
521 In a third step, the result of instantiating `afm-unit.conf`
522 for the widget is split in units.  
523 To achieve that goal, the lines containing specific directives are searched.  
524 Any directive occupy one full line.  
525 The directives are:
526
527 - %nl
528   Produce an empty line at the end
529 - %begin systemd-unit
530 - %end systemd-unit
531   Delimit the produced unit, its begin and its end
532 - %systemd-unit user
533 - %systemd-unit system
534   Tells the kind of unit (user/system)
535 - %systemd-unit service NAME
536 - %systemd-unit socket NAME
537   Gives the name and type (service or socket) of the unit.  
538   The extension is automatically computed from the type
539   and must not be set in the name.
540 - %systemd-unit wanted-by NAME
541   Tells to install a link to the unit in the wants of NAME
542
543 Then the computed units are then written to the filesystem
544 and inserted in systemd.
545
546 The generated unit files will contain variables for internal
547 use of the framework.  
548 These variables are starting with `X-AFM-`.  
549 The variables starting with `X-AFM-` but not with `X-AFM--` are
550 the public variables.  
551 These variables will be returned by the
552 framework as the details of an application (see **afm-util detail ...**).
553
554 Variables starting with `X-AFM--` are private to the framework.  
555 By example, the variable  `X-AFM--http-port` is used to
556 record the allocated port for applications.
557
558 [mustach]:          https://gitlab.com/jobol/mustach                                "basic C implementation of mustache"
559 [mustache]:         http://mustache.github.io/mustache.5.html                       "mustache - Logic-less templates"
560 [widgets]:          http://www.w3.org/TR/widgets                                    "Packaged Web Apps"
561 [widgets-digsig]:   http://www.w3.org/TR/widgets-digsig                             "XML Digital Signatures for Widgets"
562 [libxml2]:          http://xmlsoft.org/html/index.html                              "libxml2"
563 [app-manifest]:     http://www.w3.org/TR/appmanifest                                "Web App Manifest"
564 [meta-intel]:       https://github.com/01org/meta-intel-iot-security                "A collection of layers providing security technologies"
565 [openssl]:          https://www.openssl.org                                         "OpenSSL"
566 [xmlsec]:           https://www.aleksey.com/xmlsec                                  "XMLSec"
567 [json-c]:           https://github.com/json-c/json-c                                "JSON-c"
568 [d-bus]:            http://www.freedesktop.org/wiki/Software/dbus                   "D-Bus"
569 [libzip]:           http://www.nih.at/libzip                                        "libzip"
570 [cmake]:            https://cmake.org                                               "CMake"
571 [security-manager]: https://wiki.tizen.org/wiki/Security/Tizen_3.X_Security_Manager "Security-Manager"
572 [tizen-security]:   https://wiki.tizen.org/wiki/Security                            "Tizen security home page"
573 [tizen-secu-3]:     https://wiki.tizen.org/wiki/Security/Tizen_3.X_Overview         "Tizen 3 security overview"
574 [semantic-version]: http://semver.org/                                              "Semantic versioning"