Start to implement the bindings V2
[src/app-framework-binder.git] / include / afb / afb-binding-v1.h
1 /*
2  * Copyright (C) 2016, 2017 "IoT.bzh"
3  * Author: José Bollo <jose.bollo@iot.bzh>
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *   http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 #pragma once
19
20 struct afb_binding_interface;
21 struct json_object;
22 struct afb_service;
23
24 /*
25  * Function for registering the binding
26  *
27  * A binding V1 MUST have an exported function of name
28  *
29  *              afbBindingV1Register
30  *
31  * This function is called during loading of the binding. It
32  * receives an 'interface' that should be recorded for later access to
33  * functions provided by the framework.
34  *
35  * This function MUST return the address of a structure that describes
36  * the binding and its implemented verbs.
37  *
38  * In case of initialisation error, NULL must be returned.
39  *
40  * Be aware that the given 'interface' is not fully functionnal
41  * because no provision is given to the name and description
42  * of the binding. Check the function 'afbBindingV1ServiceInit'
43  * defined in the file <afb/afb-service-itf.h> because when
44  * the function 'afbBindingV1ServiceInit' is called, the 'interface'
45  * is fully functionnal.
46  */
47 extern const struct afb_binding *afbBindingV1Register (const struct afb_binding_interface *interface);
48
49 /*
50  * When a binding have an exported implementation of the
51  * function 'afbBindingV1ServiceInit', defined below,
52  * the framework calls it for initialising the service after
53  * registration of all bindings.
54  *
55  * The object 'service' should be recorded. It has functions that
56  * allows the binding to call features with its own personality.
57  *
58  * The function should return 0 in case of success or, else, should return
59  * a negative value.
60  */
61 extern int afbBindingV1ServiceInit(struct afb_service service);
62
63 /*
64  * When a binding have an implementation of the function 'afbBindingV1ServiceEvent',
65  * defined below, the framework calls that function for any broadcasted event or for
66  * events that the service subscribed to in its name.
67  *
68  * It receive the 'event' name and its related data in 'object' (be aware that 'object'
69  * might be NULL).
70  */
71 extern void afbBindingV1ServiceEvent(const char *event, struct json_object *object);
72
73
74 /*
75  * Enum for Session/Token/Assurance middleware.
76  * This enumeration is valid for bindings of type 1
77  */
78 enum afb_session_v1
79 {
80        AFB_SESSION_NONE = 0,   /* nothing required */
81        AFB_SESSION_CREATE = 1, /* Obsolete */
82        AFB_SESSION_CLOSE = 2,  /* After token authentification, closes the session at end */
83        AFB_SESSION_RENEW = 4,  /* After token authentification, refreshes the token at end */
84        AFB_SESSION_CHECK = 8,  /* Requires token authentification */
85
86        AFB_SESSION_LOA_GE = 16, /* check that the LOA is greater or equal to the given value */
87        AFB_SESSION_LOA_LE = 32, /* check that the LOA is lesser or equal to the given value */
88        AFB_SESSION_LOA_EQ = 48, /* check that the LOA is equal to the given value */
89
90        AFB_SESSION_LOA_SHIFT = 6, /* shift for LOA */
91        AFB_SESSION_LOA_MASK = 7,  /* mask for LOA */
92
93        AFB_SESSION_LOA_0 = 0,   /* value for LOA of 0 */
94        AFB_SESSION_LOA_1 = 64,  /* value for LOA of 1 */
95        AFB_SESSION_LOA_2 = 128, /* value for LOA of 2 */
96        AFB_SESSION_LOA_3 = 192, /* value for LOA of 3 */
97        AFB_SESSION_LOA_4 = 256, /* value for LOA of 4 */
98
99        AFB_SESSION_LOA_LE_0 = AFB_SESSION_LOA_LE | AFB_SESSION_LOA_0, /* check LOA <= 0 */
100        AFB_SESSION_LOA_LE_1 = AFB_SESSION_LOA_LE | AFB_SESSION_LOA_1, /* check LOA <= 1 */
101        AFB_SESSION_LOA_LE_2 = AFB_SESSION_LOA_LE | AFB_SESSION_LOA_2, /* check LOA <= 2 */
102        AFB_SESSION_LOA_LE_3 = AFB_SESSION_LOA_LE | AFB_SESSION_LOA_3, /* check LOA <= 3 */
103
104        AFB_SESSION_LOA_GE_0 = AFB_SESSION_LOA_GE | AFB_SESSION_LOA_0, /* check LOA >= 0 */
105        AFB_SESSION_LOA_GE_1 = AFB_SESSION_LOA_GE | AFB_SESSION_LOA_1, /* check LOA >= 1 */
106        AFB_SESSION_LOA_GE_2 = AFB_SESSION_LOA_GE | AFB_SESSION_LOA_2, /* check LOA >= 2 */
107        AFB_SESSION_LOA_GE_3 = AFB_SESSION_LOA_GE | AFB_SESSION_LOA_3, /* check LOA >= 3 */
108
109        AFB_SESSION_LOA_EQ_0 = AFB_SESSION_LOA_EQ | AFB_SESSION_LOA_0, /* check LOA == 0 */
110        AFB_SESSION_LOA_EQ_1 = AFB_SESSION_LOA_EQ | AFB_SESSION_LOA_1, /* check LOA == 1 */
111        AFB_SESSION_LOA_EQ_2 = AFB_SESSION_LOA_EQ | AFB_SESSION_LOA_2, /* check LOA == 2 */
112        AFB_SESSION_LOA_EQ_3 = AFB_SESSION_LOA_EQ | AFB_SESSION_LOA_3  /* check LOA == 3 */
113 };
114
115 /*
116  * Description of one verb of the API provided by the binding
117  * This enumeration is valid for bindings of type version 1
118  */
119 struct afb_verb_desc_v1
120 {
121        const char *name;                       /* name of the verb */
122        enum afb_session_v1 session;            /* authorisation and session requirements of the verb */
123        void (*callback)(struct afb_req req);   /* callback function implementing the verb */
124        const char *info;                       /* textual description of the verb */
125 };
126
127 /*
128  * Description of the bindings of type version 1
129  */
130 struct afb_binding_desc_v1
131 {
132        const char *info;                       /* textual information about the binding */
133        const char *prefix;                     /* required prefix name for the binding */
134        const struct afb_verb_desc_v1 *verbs;   /* array of descriptions of verbs terminated by a NULL name */
135 };
136
137 /*
138  * Definition of the type+versions of the binding.
139  * The definition uses hashes.
140  */
141 enum  afb_binding_type
142 {
143        AFB_BINDING_VERSION_1 = 123456789
144 };
145
146 /*
147  * Description of a binding
148  */
149 struct afb_binding
150 {
151        enum afb_binding_type type; /* type of the binding */
152        union {
153                struct afb_binding_desc_v1 v1;   /* description of the binding of type 1 */
154        };
155 };
156