Repository navigation
Expand file tree
/
Copy pathcorDbSubscriptionCreate.c
More file actions
59 lines (48 loc) · 1.77 KB
/
Copy pathcorDbSubscriptionCreate.c
File metadata and controls
59 lines (48 loc) · 1.77 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
57
58
59
//
// FILE corDbSubscriptionCreate.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" // corDbSubscriptions
#include "corDB/corDbSubscriptionCreate.h" // Own interface
// -----------------------------------------------------------------------------
//
// corDbSubscriptionCreate -
//
int corDbSubscriptionCreate(Tenant* tenantP, const char* subId, CorNode* subP)
{
COR_DB_WRITE(tenantP);
CorNode* subscriptions = corDbSubscriptions(tenantP);
//
// Check for duplicate
//
for (CorNode* sP = subscriptions->value.head; sP != NULL; sP = sP->next)
{
CorNode* idP = corTreeLookup(sP, "id");
if (idP != NULL && idP->type == CorString && strcmp(idP->value.s, subId) == 0)
return DB_ALREADY_EXISTS;
}
//
// Deep-clone the subscription tree (using malloc, not a buffer allocator)
//
CorNode* cloneP = corTreeClone(NULL, subP);
if (cloneP == NULL)
{
COR_E("corDB: corTreeClone failed for subscription '%s'", subId);
return DB_ERR;
}
corTreeChildAdd(subscriptions, cloneP);
corDbPersistAppend(corDbLockedStore->persistP, CorDbLogSubPut, cloneP);
return DB_OK;
}