Repository navigation
Expand file tree
/
Copy pathcorDbSubscriptionQuery.c
More file actions
58 lines (47 loc) · 1.63 KB
/
Copy pathcorDbSubscriptionQuery.c
File metadata and controls
58 lines (47 loc) · 1.63 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
//
// FILE corDbSubscriptionQuery.c
//
// AUTHOR Ken Zangelin
//
// Copyright 2026 Seamware
// SPDX-License-Identifier: Apache-2.0
//
#include <stddef.h> // NULL
#include "corTree/CorNode.h" // CorNode
#include "corTree/corTreeClone.h" // corTreeClone
#include "corTree/corTreeBuilder.h" // corTreeArray, corTreeChildAdd
#include "corTree/corTreeLookup.h" // corTreeLookup
#include "corRest/CorRestState.h" // corRest
#include "db/DbDriver.h" // DB_OK, Tenant
#include "corDB/corDbStore.h" // corDbSubscriptions
#include "corDB/corDbSubscriptionQuery.h" // Own interface
// -----------------------------------------------------------------------------
//
// corDbSubscriptionQuery -
//
int corDbSubscriptionQuery(Tenant* tenantP, int limit, int offset, CorNode** arrayPP)
{
COR_DB_READ(tenantP);
CorNode* subscriptions = corDbSubscriptions(tenantP);
// Request-arena array (freed at request end / after cache-load), matching
// mongoc — a NULL (malloc) array would leak its container on every load.
CorNode* resultArray = corTreeArray(corRest.kallocP, NULL);
int ix = 0;
int added = 0;
for (CorNode* sP = subscriptions->value.head; sP != NULL; sP = sP->next)
{
if (ix < offset)
{
ix++;
continue;
}
if (limit > 0 && added >= limit)
break;
CorNode* cloneP = corTreeClone(corRest.kallocP, sP);
corTreeChildAdd(resultArray, cloneP);
added++;
ix++;
}
*arrayPP = resultArray;
return DB_OK;
}