forked from telefonicaid/fiware-orion
-
Notifications
You must be signed in to change notification settings - Fork 40
/
orionldServiceInit.cpp
526 lines (457 loc) · 21 KB
/
orionldServiceInit.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
/*
*
* Copyright 2018 FIWARE Foundation e.V.
*
* This file is part of Orion-LD Context Broker.
*
* Orion-LD Context Broker is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* Orion-LD Context Broker is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
* General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Orion-LD Context Broker. If not, see http://www.gnu.org/licenses/.
*
* For those usages not covered by this license please contact with
* orionld at fiware dot org
*
* Author: Ken Zangelin
*/
#ifdef DEBUG
#include <sys/types.h> // DIR, dirent
#include <fcntl.h> // O_RDONLY
#include <dirent.h> // opendir(), readdir(), closedir()
#include <sys/stat.h> // statbuf
#include <unistd.h> // stat()
#endif
#include <microhttpd.h>
#include "logMsg/logMsg.h" // LM_*
#include "logMsg/traceLevels.h" // Lmt*
extern "C"
{
#include "kbase/kInit.h" // kInit
#include "kalloc/kaInit.h" // kaInit
#include "kalloc/kaBufferInit.h" // kaBufferInit
#include "kjson/kjBufferCreate.h" // kjBufferCreate
#include "kjson/kjParse.h" // kjParse
}
#include "orionld/common/orionldState.h" // orionldState
#include "orionld/common/urlCheck.h" // urlCheck
#include "orionld/context/orionldCoreContext.h" // orionldCoreContext, ORIONLD_CORE_CONTEXT_URL
#include "orionld/context/orionldContextInit.h" // orionldContextInit
#include "orionld/rest/OrionLdRestService.h" // OrionLdRestService, ORION_LD_SERVICE_PREFIX_LEN
#include "orionld/rest/temporaryErrorPayloads.h" // Temporary Error Payloads
#include "orionld/rest/uriParamName.h" // uriParamName
#include "orionld/serviceRoutines/orionldPostEntities.h" // orionldPostEntities
#include "orionld/serviceRoutines/orionldPostEntity.h" // orionldPostEntity
#include "orionld/serviceRoutines/orionldGetEntities.h" // orionldGetEntities
#include "orionld/serviceRoutines/orionldGetEntity.h" // orionldGetEntity
#include "orionld/serviceRoutines/orionldPatchEntity.h" // orionldPatchEntity
#include "orionld/serviceRoutines/orionldDeleteEntity.h" // orionldDeleteEntity
#include "orionld/serviceRoutines/orionldPatchAttribute.h" // orionldPatchAttribute
#include "orionld/serviceRoutines/orionldDeleteAttribute.h" // orionldDeleteAttribute
#include "orionld/serviceRoutines/orionldPostSubscriptions.h" // orionldPostSubscriptions
#include "orionld/serviceRoutines/orionldGetSubscriptions.h" // orionldGetSubscriptions
#include "orionld/serviceRoutines/orionldGetSubscription.h" // orionldGetSubscription
#include "orionld/serviceRoutines/orionldPostRegistrations.h" // orionldPostRegistrations
#include "orionld/serviceRoutines/orionldGetVersion.h" // orionldGetVersion
#include "orionld/serviceRoutines/orionldPostBatchDelete.h" // orionldPostBatchDelete
#include "orionld/serviceRoutines/orionldPostBatchCreate.h" // orionldPostBatchCreate
#include "orionld/serviceRoutines/orionldPostBatchUpsert.h" // orionldPostBatchUpsert
#include "orionld/serviceRoutines/orionldPostBatchUpdate.h" // orionldPostBatchUpdate
#include "orionld/serviceRoutines/orionldPostQuery.h" // orionldPostQuery
#include "orionld/serviceRoutines/orionldGetTenants.h" // orionldGetTenants
#include "orionld/serviceRoutines/orionldGetDbIndexes.h" // orionldGetDbIndexes
#include "orionld/serviceRoutines/orionldGetRegistrations.h" // orionldGetRegistrations
#include "orionld/serviceRoutines/orionldGetRegistration.h" // orionldGetRegistration
#include "orionld/serviceRoutines/orionldPatchRegistration.h" // orionldPatchRegistration
#include "orionld/serviceRoutines/orionldDeleteRegistration.h" // orionldDeleteRegistration
#include "orionld/serviceRoutines/orionldPatchSubscription.h" // orionldPatchSubscription
#include "orionld/serviceRoutines/orionldDeleteSubscription.h" // orionldDeleteSubscription
#include "orionld/serviceRoutines/orionldGetEntityTypes.h" // orionldGetEntityTypes
#include "orionld/troe/troePostEntities.h" // troePostEntities
#include "orionld/troe/troePostBatchDelete.h" // troePostBatchDelete
#include "orionld/troe/troeDeleteAttribute.h" // troeDeleteAttribute
#include "orionld/troe/troeDeleteEntity.h" // troeDeleteEntity
#include "orionld/troe/troePatchAttribute.h" // troePatchAttribute
#include "orionld/troe/troePatchEntity.h" // troePatchEntity
#include "orionld/troe/troePostBatchCreate.h" // troePostBatchCreate
#include "orionld/troe/troePostBatchUpsert.h" // troePostBatchUpsert
#include "orionld/troe/troePostBatchUpdate.h" // troePostBatchUpdate
#include "orionld/troe/troePostEntity.h" // troePostEntity
#include "orionld/mqtt/mqttConnectionInit.h" // mqttConnectionInit
#include "orionld/rest/orionldMhdConnection.h" // Own Interface
// -----------------------------------------------------------------------------
//
// libLogBuffer -
//
thread_local char libLogBuffer[1024 * 32];
// -----------------------------------------------------------------------------
//
// libLogFunction -
//
static void libLogFunction
(
int severity, // 1: Error, 2: Warning, 3: Info, 4: Verbose, 5: Trace
int level, // Trace level || Error code || Info Code
const char* fileName,
int lineNo,
const char* functionName,
const char* format,
...
)
{
va_list args;
/* "Parse" the variable arguments */
va_start(args, format);
/* Print message to variable */
vsnprintf(libLogBuffer, sizeof(libLogBuffer), format, args);
va_end(args);
// LM_K(("Got a lib log message, severity: %d: %s", severity, libLogBuffer));
if (severity == 1)
lmOut(libLogBuffer, 'E', fileName, lineNo, functionName, 0, NULL);
else if (severity == 2)
lmOut(libLogBuffer, 'W', fileName, lineNo, functionName, 0, NULL);
else if (severity == 3)
lmOut(libLogBuffer, 'I', fileName, lineNo, functionName, 0, NULL);
else if (severity == 4)
lmOut(libLogBuffer, 'V', fileName, lineNo, functionName, 0, NULL);
else if (severity == 5)
lmOut(libLogBuffer, 'T', fileName, lineNo, functionName, level + LmtKjlParse, NULL);
}
// -----------------------------------------------------------------------------
//
// orionldRestServiceV -
//
OrionLdRestServiceVector orionldRestServiceV[9];
// -----------------------------------------------------------------------------
//
// restServicePrepare -
//
static void restServicePrepare(OrionLdRestService* serviceP, OrionLdRestServiceSimplified* simpleServiceP)
{
// 1. Simply copy/reference the two fields of OrionLdRestServiceSimplified
serviceP->url = (char*) simpleServiceP->url;
serviceP->serviceRoutine = simpleServiceP->serviceRoutine;
// 2. Loop over the URL Path, count wildcards, charsBeforeFirstWildcard, etc
int ix = ORION_LD_SERVICE_PREFIX_LEN - 1;
char* wildCardStart = NULL;
char* wildCardEnd = NULL;
while (serviceP->url[++ix] != 0)
{
char c = serviceP->url[ix];
if (c == '*')
{
if (serviceP->wildcards == 0)
wildCardStart = &serviceP->url[ix + 1];
else if (serviceP->wildcards == 1)
wildCardEnd = &serviceP->url[ix];
LM_T(LmtUrlParse, ("Found a wildcard in index %d of '%s'", ix, serviceP->url));
serviceP->wildcards += 1;
continue;
}
if (serviceP->wildcards == 0)
{
++serviceP->charsBeforeFirstWildcard;
serviceP->charsBeforeFirstWildcardSum += c;
}
else if (serviceP->wildcards == 1)
{
++serviceP->charsBeforeSecondWildcard;
serviceP->charsBeforeSecondWildcardSum += c;
}
}
if (serviceP->wildcards != 0)
{
if (wildCardEnd == NULL) // If only one '*', make wildCardEnd point to end of URL
wildCardEnd = &serviceP->url[ix];
serviceP->matchForSecondWildcardLen = wildCardEnd - wildCardStart;
if (serviceP->matchForSecondWildcardLen < 0)
LM_X(1, ("Negative length of matchForSecondWildcard - not possible. SW bug"));
if (serviceP->matchForSecondWildcardLen > (int) sizeof(serviceP->matchForSecondWildcard))
LM_X(1, ("Too big matchForSecondWildcard - not possible. SW bug"));
if (serviceP->matchForSecondWildcardLen != 0)
{
strncpy(serviceP->matchForSecondWildcard, wildCardStart, wildCardEnd - wildCardStart);
LM_T(LmtUrlParse, ("matchForSecondWildcard: %s", serviceP->matchForSecondWildcard));
}
}
//
// Set options for the OrionLdRestService
//
// Most services needs the tenant to exist
//
// For POST /ngsi-ld/v1/entities:
// - The context may have to be saved in the context cache (if @context is non-string in payload)
// - Why? The broker needs to be able to serve it later
// - The Entity ID and type must be looked up and removed from the payload (pointers to the trees in orionldState
// - Why? The Entity ID is used when naming the context
// - The Entity Type is removed and saved to save time in the service routine (all on level 1 are attributes)
//
//
// Valid for almost ALL services - zeroed out by those services that do not support this feature
serviceP->options = ORIONLD_SERVICE_OPTION_MAKE_SURE_TENANT_EXISTS;
//
// URI parameters - set it to NONE - NO URI Parameter supported
// Later, each service is set to support whatever URI parameters the service supports
//
serviceP->uriParams = 0;
// But first, ALL services support 'prettyPrint' and 'spaces'
serviceP->uriParams |= ORIONLD_URIPARAM_PRETTYPRINT;
serviceP->uriParams |= ORIONLD_URIPARAM_SPACES;
if (serviceP->serviceRoutine == orionldPostEntities)
{
serviceP->options = 0; // Tenant will be created if necessary
serviceP->options = ORIONLD_SERVICE_OPTION_PREFETCH_ID_AND_TYPE;
serviceP->options |= ORIONLD_SERVICE_OPTION_CREATE_CONTEXT;
}
else if (serviceP->serviceRoutine == orionldGetEntities)
{
serviceP->uriParams |= ORIONLD_URIPARAM_OPTIONS;
serviceP->uriParams |= ORIONLD_URIPARAM_LIMIT;
serviceP->uriParams |= ORIONLD_URIPARAM_OFFSET;
serviceP->uriParams |= ORIONLD_URIPARAM_COUNT;
serviceP->uriParams |= ORIONLD_URIPARAM_IDLIST;
serviceP->uriParams |= ORIONLD_URIPARAM_TYPELIST;
serviceP->uriParams |= ORIONLD_URIPARAM_IDPATTERN;
serviceP->uriParams |= ORIONLD_URIPARAM_ATTRS;
serviceP->uriParams |= ORIONLD_URIPARAM_Q;
serviceP->uriParams |= ORIONLD_URIPARAM_CSF;
serviceP->uriParams |= ORIONLD_URIPARAM_GEOREL;
serviceP->uriParams |= ORIONLD_URIPARAM_GEOMETRY;
serviceP->uriParams |= ORIONLD_URIPARAM_COORDINATES;
serviceP->uriParams |= ORIONLD_URIPARAM_GEOPROPERTY;
serviceP->uriParams |= ORIONLD_URIPARAM_GEOMETRYPROPERTY;
}
else if (serviceP->serviceRoutine == orionldGetEntity)
{
serviceP->uriParams |= ORIONLD_URIPARAM_OPTIONS;
serviceP->uriParams |= ORIONLD_URIPARAM_ATTRS;
serviceP->uriParams |= ORIONLD_URIPARAM_GEOMETRYPROPERTY;
serviceP->options |= ORIONLD_SERVICE_OPTION_NO_V2_URI_PARAMS;
}
else if (serviceP->serviceRoutine == orionldDeleteEntity)
{
serviceP->options |= ORIONLD_SERVICE_OPTION_NO_V2_URI_PARAMS;
serviceP->options |= ORIONLD_SERVICE_OPTION_NO_CONTEXT_NEEDED;
}
else if (serviceP->serviceRoutine == orionldPostEntity)
{
serviceP->uriParams |= ORIONLD_URIPARAM_OPTIONS;
}
else if (serviceP->serviceRoutine == orionldPatchAttribute)
{
serviceP->options |= ORIONLD_SERVICE_OPTION_CLONE_PAYLOAD;
}
else if (serviceP->serviceRoutine == orionldDeleteAttribute)
{
serviceP->uriParams |= ORIONLD_URIPARAM_DATASETID;
serviceP->uriParams |= ORIONLD_URIPARAM_DELETEALL;
serviceP->options |= ORIONLD_SERVICE_OPTION_NO_V2_URI_PARAMS;
}
else if (serviceP->serviceRoutine == orionldPostRegistrations)
{
serviceP->options = 0; // Tenant will be created if necessary
serviceP->options |= ORIONLD_SERVICE_OPTION_PREFETCH_ID_AND_TYPE;
serviceP->options |= ORIONLD_SERVICE_OPTION_CREATE_CONTEXT;
}
else if (serviceP->serviceRoutine == orionldGetRegistrations)
{
serviceP->uriParams |= ORIONLD_URIPARAM_OPTIONS;
serviceP->uriParams |= ORIONLD_URIPARAM_LIMIT;
serviceP->uriParams |= ORIONLD_URIPARAM_OFFSET;
serviceP->uriParams |= ORIONLD_URIPARAM_COUNT;
serviceP->uriParams |= ORIONLD_URIPARAM_IDLIST;
serviceP->uriParams |= ORIONLD_URIPARAM_TYPELIST;
serviceP->uriParams |= ORIONLD_URIPARAM_IDPATTERN;
serviceP->uriParams |= ORIONLD_URIPARAM_ATTRS;
serviceP->uriParams |= ORIONLD_URIPARAM_Q;
serviceP->uriParams |= ORIONLD_URIPARAM_CSF;
serviceP->uriParams |= ORIONLD_URIPARAM_GEOREL;
serviceP->uriParams |= ORIONLD_URIPARAM_GEOMETRY;
serviceP->uriParams |= ORIONLD_URIPARAM_COORDINATES;
serviceP->uriParams |= ORIONLD_URIPARAM_GEOPROPERTY;
serviceP->uriParams |= ORIONLD_URIPARAM_TIMEPROPERTY;
serviceP->uriParams |= ORIONLD_URIPARAM_TIMEREL;
serviceP->uriParams |= ORIONLD_URIPARAM_TIMEAT;
serviceP->uriParams |= ORIONLD_URIPARAM_ENDTIMEAT;
}
else if (serviceP->serviceRoutine == orionldGetRegistration)
{
serviceP->uriParams |= ORIONLD_URIPARAM_OPTIONS;
}
else if (serviceP->serviceRoutine == orionldPatchRegistration)
{
serviceP->options |= ORIONLD_SERVICE_OPTION_NO_V2_URI_PARAMS;
}
else if (serviceP->serviceRoutine == orionldDeleteRegistration)
{
serviceP->options |= ORIONLD_SERVICE_OPTION_NO_V2_URI_PARAMS;
serviceP->options |= ORIONLD_SERVICE_OPTION_NO_CONTEXT_NEEDED;
}
else if (serviceP->serviceRoutine == orionldPostSubscriptions)
{
serviceP->options = 0; // Tenant will be created if necessary
serviceP->options |= ORIONLD_SERVICE_OPTION_PREFETCH_ID_AND_TYPE;
serviceP->options |= ORIONLD_SERVICE_OPTION_CREATE_CONTEXT;
}
else if (serviceP->serviceRoutine == orionldGetSubscriptions)
{
serviceP->options |= ORIONLD_SERVICE_OPTION_DONT_ADD_CONTEXT_TO_RESPONSE_PAYLOAD;
serviceP->uriParams |= ORIONLD_URIPARAM_OPTIONS;
serviceP->uriParams |= ORIONLD_URIPARAM_COUNT;
serviceP->uriParams |= ORIONLD_URIPARAM_LIMIT;
serviceP->uriParams |= ORIONLD_URIPARAM_OFFSET;
}
else if (serviceP->serviceRoutine == orionldGetSubscription)
{
serviceP->options |= ORIONLD_SERVICE_OPTION_DONT_ADD_CONTEXT_TO_RESPONSE_PAYLOAD;
serviceP->uriParams |= ORIONLD_URIPARAM_OPTIONS;
}
else if (serviceP->serviceRoutine == orionldPatchSubscription)
{
serviceP->options |= ORIONLD_SERVICE_OPTION_NO_V2_URI_PARAMS;
}
else if (serviceP->serviceRoutine == orionldDeleteSubscription)
{
serviceP->options |= ORIONLD_SERVICE_OPTION_NO_V2_URI_PARAMS;
serviceP->options |= ORIONLD_SERVICE_OPTION_NO_CONTEXT_NEEDED;
}
else if (serviceP->serviceRoutine == orionldPostBatchCreate)
{
serviceP->options = 0; // Tenant will be created if necessary
}
else if (serviceP->serviceRoutine == orionldPostBatchUpdate)
{
serviceP->uriParams |= ORIONLD_URIPARAM_OPTIONS;
}
else if (serviceP->serviceRoutine == orionldPostBatchUpsert)
{
serviceP->options = 0; // Tenant will be created if necessary
serviceP->uriParams |= ORIONLD_URIPARAM_OPTIONS;
}
else if (serviceP->serviceRoutine == orionldPostBatchDelete)
{
serviceP->options |= ORIONLD_SERVICE_OPTION_DONT_ADD_CONTEXT_TO_RESPONSE_PAYLOAD;
serviceP->options |= ORIONLD_SERVICE_OPTION_NO_CONTEXT_NEEDED;
}
else if (serviceP->serviceRoutine == orionldPostQuery)
{
serviceP->uriParams |= ORIONLD_URIPARAM_OPTIONS;
serviceP->uriParams |= ORIONLD_URIPARAM_COUNT;
serviceP->uriParams |= ORIONLD_URIPARAM_LIMIT;
serviceP->uriParams |= ORIONLD_URIPARAM_OFFSET;
}
else if (serviceP->serviceRoutine == orionldGetEntityTypes)
{
serviceP->uriParams |= ORIONLD_URIPARAM_DETAILS;
serviceP->options |= ORIONLD_SERVICE_OPTION_NO_V2_URI_PARAMS;
}
else if (serviceP->serviceRoutine == orionldGetVersion)
{
serviceP->options = 0; // Tenant is Ignored
serviceP->options = ORIONLD_SERVICE_OPTION_DONT_ADD_CONTEXT_TO_RESPONSE_PAYLOAD;
serviceP->options |= ORIONLD_SERVICE_OPTION_NO_V2_URI_PARAMS;
serviceP->options |= ORIONLD_SERVICE_OPTION_NO_CONTEXT_NEEDED;
}
else if (serviceP->serviceRoutine == orionldGetTenants)
{
serviceP->options = 0; // Tenant is Ignored
serviceP->options |= ORIONLD_SERVICE_OPTION_DONT_ADD_CONTEXT_TO_RESPONSE_PAYLOAD;
serviceP->options |= ORIONLD_SERVICE_OPTION_NO_V2_URI_PARAMS;
serviceP->options |= ORIONLD_SERVICE_OPTION_NO_CONTEXT_NEEDED;
}
else if (serviceP->serviceRoutine == orionldGetDbIndexes)
{
serviceP->options = 0; // Tenant is Ignored
serviceP->options |= ORIONLD_SERVICE_OPTION_DONT_ADD_CONTEXT_TO_RESPONSE_PAYLOAD;
serviceP->options |= ORIONLD_SERVICE_OPTION_NO_V2_URI_PARAMS;
serviceP->options |= ORIONLD_SERVICE_OPTION_NO_CONTEXT_NEEDED;
}
if (troe) // CLI Option to turn on Temporal Representation of Entities
{
if (serviceP->serviceRoutine == orionldPostEntities)
serviceP->troeRoutine = troePostEntities;
else if (serviceP->serviceRoutine == orionldPostBatchDelete)
serviceP->troeRoutine = troePostBatchDelete;
else if (serviceP->serviceRoutine == orionldPostEntity)
serviceP->troeRoutine = troePostEntity;
else if (serviceP->serviceRoutine == orionldDeleteAttribute)
serviceP->troeRoutine = troeDeleteAttribute;
else if (serviceP->serviceRoutine == orionldDeleteEntity)
serviceP->troeRoutine = troeDeleteEntity;
else if (serviceP->serviceRoutine == orionldPatchAttribute)
serviceP->troeRoutine = troePatchAttribute;
else if (serviceP->serviceRoutine == orionldPatchEntity)
serviceP->troeRoutine = troePatchEntity;
else if (serviceP->serviceRoutine == orionldPostBatchCreate)
serviceP->troeRoutine = troePostBatchCreate;
else if (serviceP->serviceRoutine == orionldPostBatchUpsert)
serviceP->troeRoutine = troePostBatchUpsert;
else if (serviceP->serviceRoutine == orionldPostBatchUpdate)
serviceP->troeRoutine = troePostBatchUpdate;
}
}
// -----------------------------------------------------------------------------
//
// orionldServiceInit -
//
// This function converts the OrionLdRestServiceSimplified vectors to OrionLdRestService vectors
//
void orionldServiceInit(OrionLdRestServiceSimplifiedVector* restServiceVV, int vecItems, char* cachedContextDir)
{
int svIx; // Service Vector Index
bzero(orionldRestServiceV, sizeof(orionldRestServiceV));
for (svIx = 0; svIx < vecItems; svIx++)
{
// svIx is really the Verb (GET=0, POST=2, up to NOVERB=9. See src/lib/rest/Verb.h)
LM_T(LmtUrlParse, ("svIx: %d", svIx));
if (restServiceVV[svIx].serviceV == NULL)
continue;
int services = restServiceVV[svIx].services;
orionldRestServiceV[svIx].serviceV = (OrionLdRestService*) calloc(sizeof(OrionLdRestService), services);
orionldRestServiceV[svIx].services = services;
int sIx; // Service Index inside Rest Service vector
for (sIx = 0; sIx < services; sIx++)
{
LM_T(LmtUrlParse, ("sIx: %d", sIx));
restServicePrepare(&orionldRestServiceV[svIx].serviceV[sIx], &restServiceVV[svIx].serviceV[sIx]);
}
}
//
// Initialize the KBASE library
// This call redirects all log messaghes from the K-libs to the brokers log file.
//
kInit(libLogFunction);
//
// Initialize the KALLOC library
//
kaInit(libLogFunction);
kaBufferInit(&kalloc, kallocBuffer, sizeof(kallocBuffer), 32 * 1024, NULL, "Global KAlloc buffer");
//
// Initialize the KJSON library
// This sets up the global kjson instance with preallocated kalloc buffer
//
kjsonP = kjBufferCreate(&kjson, &kalloc);
//
// Get the hostname - needed for contexts created by the broker
//
gethostname(orionldHostName, sizeof(orionldHostName));
orionldHostNameLen = strlen(orionldHostName);
orionldStateInit();
//
// Initialize the @context handling
//
OrionldProblemDetails pd;
if (orionldContextInit(&pd) == false)
LM_X(1, ("orionldContextInit failed: %s %s", pd.title, pd.detail));
//
// Initialize NQTT notifications
//
mqttConnectionInit();
}