aboutsummaryrefslogtreecommitdiff
path: root/src/accfile.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/accfile.c')
-rw-r--r--src/accfile.c105
1 files changed, 105 insertions, 0 deletions
diff --git a/src/accfile.c b/src/accfile.c
new file mode 100644
index 0000000..3fe669d
--- /dev/null
+++ b/src/accfile.c
@@ -0,0 +1,105 @@
+/* This file is part of Eclat.
+ Copyright (C) 2012 Sergey Poznyakoff.
+
+ Eclat is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ Eclat is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Eclat. If not, see <http://www.gnu.org/licenses/>. */
+
+#include "eclat.h"
+
+char *access_file_name;
+
+static void
+skipline(FILE *fp)
+{
+ int c;
+
+ while ((c = getc(fp)) != EOF && c != '\n')
+ ;
+}
+
+int
+access_file_lookup(const char *id, char **access_key_ptr, char **secret_key_ptr)
+{
+ int rc;
+ int c;
+ FILE *fp;
+ size_t line = 0;
+ struct grecs_txtacc *acc;
+
+ if (!access_file_name)
+ return 1;
+ fp = fopen(access_file_name, "r");
+ if (!fp) {
+ err("cannot open \"%s\": %s",
+ access_file_name, strerror(errno));
+ return 1;
+ }
+
+ while ((c = getc(fp)) != EOF) {
+ line++;
+ while (c != EOF && (c == ' ' || c == '\t'))
+ c = getc(fp);
+ if (c == '\n')
+ continue;
+ if (c == '#') {
+ skipline(fp);
+ continue;
+ }
+ if (c == EOF)
+ break;
+ if (id) {
+ const char *p;
+
+ for (p = id; c != EOF && c != ':' && *p == c; p++)
+ c = getc(fp);
+ if (c == EOF)
+ break;
+ if (c == '\n')
+ continue;
+ if (c != ':') {
+ skipline(fp);
+ continue;
+ }
+ } else {
+ acc = grecs_txtacc_create();
+ while ((c = getc(fp)) != EOF && c != ':') {
+ if (c == '\n') {
+ err("%s:%u: incomplete line",
+ access_file_name, line);
+ break;
+ }
+ grecs_txtacc_grow_char(acc, c);
+ }
+ if (c == ':') {
+ grecs_txtacc_grow_char(acc, 0);
+ *access_key_ptr = grecs_txtacc_finish(acc, 1);
+ }
+ grecs_txtacc_free(acc);
+ }
+ break;
+ }
+
+ if (c == ':') {
+ acc = grecs_txtacc_create();
+ while ((c = getc(fp)) != EOF && c != '\n')
+ grecs_txtacc_grow_char(acc, c);
+ grecs_txtacc_grow_char(acc, 0);
+ *secret_key_ptr = grecs_txtacc_finish(acc, 1);
+ rc = 0;
+ } else
+ rc = 1;
+
+ fclose(fp);
+
+ return rc;
+}

Return to:

Send suggestions and report system problems to the System administrator.