Prepare migration to binding 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
22 /*
23  * Function for registering the binding
24  *
25  * A binding V1 MUST have an exported function of name
26  *
27  *              afbBindingV1Register
28  *
29  * This function is called during loading of the binding. It
30  * receives an 'interface' that should be recorded for later access to
31  * functions provided by the framework.
32  *
33  * This function MUST return the address of a structure that describes
34  * the binding and its implemented verbs.
35  *
36  * In case of initialisation error, NULL must be returned.
37  *
38  * Be aware that the given 'interface' is not fully functionnal
39  * because no provision is given to the name and description
40  * of the binding. Check the function 'afbBindingV1ServiceInit'
41  * defined in the file <afb/afb-service-itf.h> because when
42  * the function 'afbBindingV1ServiceInit' is called, the 'interface'
43  * is fully functionnal.
44  */
45 extern const struct afb_binding *afbBindingV1Register (const struct afb_binding_interface *interface);
46
47 /*
48  * Enum for Session/Token/Assurance middleware.
49  * This enumeration is valid for bindings of type 1
50  */
51 enum afb_session_v1
52 {
53        AFB_SESSION_NONE = 0,   /* nothing required */
54        AFB_SESSION_CREATE = 1, /* Obsolete */
55        AFB_SESSION_CLOSE = 2,  /* After token authentification, closes the session at end */
56        AFB_SESSION_RENEW = 4,  /* After token authentification, refreshes the token at end */
57        AFB_SESSION_CHECK = 8,  /* Requires token authentification */
58
59        AFB_SESSION_LOA_GE = 16, /* check that the LOA is greater or equal to the given value */
60        AFB_SESSION_LOA_LE = 32, /* check that the LOA is lesser or equal to the given value */
61        AFB_SESSION_LOA_EQ = 48, /* check that the LOA is equal to the given value */
62
63        AFB_SESSION_LOA_SHIFT = 6, /* shift for LOA */
64        AFB_SESSION_LOA_MASK = 7,  /* mask for LOA */
65
66        AFB_SESSION_LOA_0 = 0,   /* value for LOA of 0 */
67        AFB_SESSION_LOA_1 = 64,  /* value for LOA of 1 */
68        AFB_SESSION_LOA_2 = 128, /* value for LOA of 2 */
69        AFB_SESSION_LOA_3 = 192, /* value for LOA of 3 */
70        AFB_SESSION_LOA_4 = 256, /* value for LOA of 4 */
71
72        AFB_SESSION_LOA_LE_0 = AFB_SESSION_LOA_LE | AFB_SESSION_LOA_0, /* check LOA <= 0 */
73        AFB_SESSION_LOA_LE_1 = AFB_SESSION_LOA_LE | AFB_SESSION_LOA_1, /* check LOA <= 1 */
74        AFB_SESSION_LOA_LE_2 = AFB_SESSION_LOA_LE | AFB_SESSION_LOA_2, /* check LOA <= 2 */
75        AFB_SESSION_LOA_LE_3 = AFB_SESSION_LOA_LE | AFB_SESSION_LOA_3, /* check LOA <= 3 */
76
77        AFB_SESSION_LOA_GE_0 = AFB_SESSION_LOA_GE | AFB_SESSION_LOA_0, /* check LOA >= 0 */
78        AFB_SESSION_LOA_GE_1 = AFB_SESSION_LOA_GE | AFB_SESSION_LOA_1, /* check LOA >= 1 */
79        AFB_SESSION_LOA_GE_2 = AFB_SESSION_LOA_GE | AFB_SESSION_LOA_2, /* check LOA >= 2 */
80        AFB_SESSION_LOA_GE_3 = AFB_SESSION_LOA_GE | AFB_SESSION_LOA_3, /* check LOA >= 3 */
81
82        AFB_SESSION_LOA_EQ_0 = AFB_SESSION_LOA_EQ | AFB_SESSION_LOA_0, /* check LOA == 0 */
83        AFB_SESSION_LOA_EQ_1 = AFB_SESSION_LOA_EQ | AFB_SESSION_LOA_1, /* check LOA == 1 */
84        AFB_SESSION_LOA_EQ_2 = AFB_SESSION_LOA_EQ | AFB_SESSION_LOA_2, /* check LOA == 2 */
85        AFB_SESSION_LOA_EQ_3 = AFB_SESSION_LOA_EQ | AFB_SESSION_LOA_3  /* check LOA == 3 */
86 };
87
88 /*
89  * Description of one verb of the API provided by the binding
90  * This enumeration is valid for bindings of type version 1
91  */
92 struct afb_verb_desc_v1
93 {
94        const char *name;                       /* name of the verb */
95        enum afb_session_v1 session;            /* authorisation and session requirements of the verb */
96        void (*callback)(struct afb_req req);   /* callback function implementing the verb */
97        const char *info;                       /* textual description of the verb */
98 };
99
100 /*
101  * Description of the bindings of type version 1
102  */
103 struct afb_binding_desc_v1
104 {
105        const char *info;                       /* textual information about the binding */
106        const char *prefix;                     /* required prefix name for the binding */
107        const struct afb_verb_desc_v1 *verbs;   /* array of descriptions of verbs terminated by a NULL name */
108 };
109