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, ¤t));
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: */
|