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