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