[go: up one dir, main page]

File: confuga_file.c

package info (click to toggle)
cctools 9.9-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 44,624 kB
  • sloc: ansic: 192,539; python: 20,827; cpp: 20,199; sh: 11,719; perl: 4,106; xml: 3,688; makefile: 1,224
file content (77 lines) | stat: -rw-r--r-- 1,628 bytes parent folder | download | duplicates (3)
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
/*
Copyright (C) 2015- The University of Notre Dame
This software is distributed under the GNU General Public License.
See the file COPYING for details.
*/

#include "confuga_fs.h"

#include "catch.h"
#include "chirp_sqlite.h"
#include "debug.h"

#include <errno.h>
#include <stdlib.h>
#include <string.h>

int confugaF_extract (confuga *C, confuga_fid_t *fid, const char *str, const char **endptr)
{
	int rc;

	/* extract the File ID from interpolated serv_path */
	size_t k;
	for (k = 0; k < sizeof(fid->id); k += 1, str += 2) {
		char byte[3] = {str[0], str[1], '\0'};
		char *e;
		unsigned long value = strtoul(byte, &e, 16);
		if (e == &byte[2]) {
			fid->id[k] = value;
		} else {
			CATCH(EINVAL);
		}
	}

	if (endptr)
		*endptr = str;

	rc = 0;
	goto out;
out:
	return rc;
}

int confugaF_set (confuga *C, confuga_fid_t *fid, const void *id)
{
	memcpy(fid->id, id, confugaF_size(*fid));
	return 0;
}

CONFUGA_IAPI int confugaF_renew (confuga *C, confuga_fid_t fid)
{
	static const char SQL[] =
		"UPDATE Confuga.File"
		"	SET time_health = (strftime('%s', 'now'))"
		"	WHERE id = ?"
		";"
		;

	int rc;
	sqlite3 *db = C->db;
	sqlite3_stmt *stmt = NULL;
	const char *current = SQL;

	debug(D_DEBUG, "renewing File " CONFUGA_FID_DEBFMT, CONFUGA_FID_PRIARGS(fid));

	sqlcatch(sqlite3_prepare_v2(db, current, -1, &stmt, &current));
	sqlcatch(sqlite3_bind_blob(stmt, 1, confugaF_id(fid), confugaF_size(fid), SQLITE_STATIC));
	sqlcatchcode(sqlite3_step(stmt), SQLITE_DONE);
	sqlcatch(sqlite3_finalize(stmt); stmt = NULL);

	rc = 0;
	goto out;
out:
	sqlite3_finalize(stmt);
	return rc;
}

/* vim: set noexpandtab tabstop=4: */