aboutsummaryrefslogtreecommitdiffstats
path: root/src/cyn.c
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2018-09-11 11:28:34 +0200
committerJose Bollo <jose.bollo@iot.bzh>2018-09-17 13:17:56 +0200
commit7ae3477d84ae13c5e9ef9bb1980a8f70f8b7e9bf (patch)
tree46c1ddda9a4dcc4782ceab8deb2f891ad3b0f2c8 /src/cyn.c
parent11654afcb5753a54a033db12e1ed4a19b3f7c86e (diff)
Make it work for AGL
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Diffstat (limited to 'src/cyn.c')
-rw-r--r--src/cyn.c94
1 files changed, 52 insertions, 42 deletions
diff --git a/src/cyn.c b/src/cyn.c
index 4eb6d9e..85deb4e 100644
--- a/src/cyn.c
+++ b/src/cyn.c
@@ -1,3 +1,20 @@
+/*
+ * Copyright (C) 2018 "IoT.bzh"
+ * Author José Bollo <jose.bollo@iot.bzh>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
#define _GNU_SOURCE
@@ -68,27 +85,15 @@ static
int
changed(
) {
- int rc = db_sync();
+ int rc;
struct callback *c;
+ rc = db_sync();
for (c = observers; c ; c = c->next)
c->callback(c->closure);
return rc;
}
-int
-cyn_init(
-) {
- /* TODO: paths? */
- int rc = db_open("/var/lib/cynara/cynara.names", "/var/lib/cynara/cynara.rules");
- if (rc == 0 && db_is_empty()) {
- /* TODO: init? */
- rc = db_set("System", "*", "*", "*", 1);
- db_sync();
- }
- return rc;
-}
-
/** enter critical recoverable section */
int
cyn_enter(
@@ -155,10 +160,17 @@ cyn_leave(
return -EPERM;
lock = &lock;
- if (commit)
- rc = queue_play() ?: changed();
- else
+ if (!commit)
rc = 0;
+ else {
+ rc = queue_play();
+ if (rc < 0)
+ db_recover();
+ else {
+ rc = db_backup();
+ changed();
+ }
+ }
queue_clear();
e = awaiters;
@@ -187,10 +199,9 @@ cyn_set(
const char *permission,
uint32_t value
) {
- if (lock && lock != &lock)
- return queue_set(client, session, user, permission, value);
-
- return db_set(client, session, user, permission, value) ?: changed();
+ if (!lock)
+ return -EPERM;
+ return queue_set(client, session, user, permission, value);
}
int
@@ -200,10 +211,27 @@ cyn_drop(
const char *user,
const char *permission
) {
- if (lock && lock != &lock)
- return queue_drop(client, session, user, permission);
+ if (!lock)
+ return -EPERM;
+ return queue_drop(client, session, user, permission);
+}
- return db_drop(client, session, user, permission) ?: changed();
+void
+cyn_list(
+ void *closure,
+ void (*callback)(
+ void *closure,
+ const char *client,
+ const char *session,
+ const char *user,
+ const char *permission,
+ uint32_t value),
+ const char *client,
+ const char *session,
+ const char *user,
+ const char *permission
+) {
+ db_for_all(closure, callback, client, session, user, permission);
}
int
@@ -224,24 +252,6 @@ cyn_test(
return rc;
}
-void
-cyn_list(
- void *closure,
- void (*callback)(
- void *closure,
- const char *client,
- const char *session,
- const char *user,
- const char *permission,
- uint32_t value),
- const char *client,
- const char *session,
- const char *user,
- const char *permission
-) {
- db_for_all(closure, callback, client, session, user, permission);
-}
-
int
cyn_check_async(
void (*check_cb)(void *closure, uint32_t value),