Repository navigation
Expand file tree
/
Copy pathcorDbRegistrationCreate.c
More file actions
56 lines (44 loc) · 1.76 KB
/
Copy pathcorDbRegistrationCreate.c
File metadata and controls
56 lines (44 loc) · 1.76 KB
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
//
// FILE corDbRegistrationCreate.c
//
// AUTHOR Ken Zangelin
//
// Copyright 2026 Seamware
// SPDX-License-Identifier: Apache-2.0
//
#include <string.h> // strcmp
#include "corLog/corLog.h" // COR_E
#include "corTree/CorNode.h" // CorNode
#include "corTree/corTreeClone.h" // corTreeClone
#include "corTree/corTreeBuilder.h" // corTreeChildAdd
#include "corTree/corTreeLookup.h" // corTreeLookup
#include "db/DbDriver.h" // DB_OK, DB_ALREADY_EXISTS, DB_ERR, Tenant
#include "corDB/corDbPersist.h" // corDbPersistAppend
#include "corDB/corDbStore.h" // corDbRegistrations
#include "corDB/corDbRegistrationCreate.h" // Own interface
// -----------------------------------------------------------------------------
//
// corDbRegistrationCreate -
//
int corDbRegistrationCreate(Tenant* tenantP, const char* regId, CorNode* regP)
{
if (corDbStoreWriteRefused(tenantP) == true) // the broker is paused: nothing is touched
return DB_ERR;
COR_DB_WRITE(tenantP);
CorNode* registrations = corDbRegistrations(tenantP);
for (CorNode* rP = registrations->value.head; rP != NULL; rP = rP->next)
{
CorNode* idP = corTreeLookup(rP, "id");
if (idP != NULL && idP->type == CorString && strcmp(idP->value.s, regId) == 0)
return DB_ALREADY_EXISTS;
}
CorNode* cloneP = corTreeClone(NULL, regP);
if (cloneP == NULL)
{
COR_E("corDB: corTreeClone failed for registration '%s'", regId);
return DB_ERR;
}
corTreeChildAdd(registrations, cloneP);
corDbPersistAppend(corDbLockedStore->persistP, CorDbLogRegPut, cloneP);
return DB_OK;
}