Permalink
Browse files

add ini file reading: read /etc/fastphoto/fastphoto.ini

git-svn-id: http://svn.kfish.org/fastphoto/trunk@164 9c49b5d1-7df3-0310-bce2-b7278e68f44c
  • Loading branch information...
1 parent 2f36faf commit ee58cc26812ffa589a30191963445f6cbfecb116 conrad committed Mar 1, 2006
Showing with 892 additions and 4 deletions.
  1. +3 −3 src/Makefile.am
  2. +1 −1 src/cache.c
  3. +3 −0 src/cgi.c
  4. +7 −0 src/fastphoto.h
  5. +52 −0 src/read_config.c
  6. +8 −0 src/read_config.h
  7. +708 −0 src/xini.c
  8. +110 −0 src/xini.h
View
@@ -9,12 +9,12 @@ TESTS_ENVIRONMENT = $(VALGRIND_ENVIRONMENT)
TESTS = httpdate_test cgi_test
-noinst_HEADERS = fastphoto.h alloc_snprintf.h cache.h cgi.h cmd.h header.h httpdate.h memory.h photo.h resize.h tests.h
+noinst_HEADERS = fastphoto.h alloc_snprintf.h cache.h cgi.h cmd.h read_config.h header.h httpdate.h memory.h photo.h resize.h tests.h xini.h
-fastphoto_SOURCES = main.c alloc_snprintf.c cache.c cgi.c cmd.c header.c httpdate.c memory.c photo.c resize.c
+fastphoto_SOURCES = main.c alloc_snprintf.c cache.c cgi.c cmd.c read_config.c header.c httpdate.c memory.c photo.c resize.c xini.c
fastphoto_LDADD = $(EPEG_LIBS)
httpdate_test_SOURCES = httpdate.c httpdate_test.c
-cgi_test_SOURCES = cgi_test.c cgi.c alloc_snprintf.c cache.c httpdate.c header.c photo.c resize.c memory.c
+cgi_test_SOURCES = cgi_test.c cgi.c alloc_snprintf.c cache.c read_config.c httpdate.c header.c photo.c resize.c memory.c xini.c
cgi_test_LDADD = $(EPEG_LIBS)
View
@@ -62,7 +62,7 @@ cache_check (fastphoto_t * params)
int
cache_init (fastphoto_t * params, char * path_info)
{
- char * cachedir = FASTPHOTO_DEFAULT_CACHEDIR;
+ char * cachedir = params->config.cachedir;
char * cachefile, * c;
int cached;
View
@@ -10,6 +10,7 @@
#include "httpdate.h"
#include "memory.h"
#include "photo.h"
+#include "read_config.h"
#include "resize.h"
static void
@@ -151,6 +152,8 @@ cgi_main (fastphoto_t * params)
header_content_type_jpeg ();
+ config_init (params);
+
parse_query (params, query_string);
if (params->x || params->y || params->scale || params->gray ||
View
@@ -9,15 +9,22 @@
#define FASTPHOTO_DEFAULT_CACHEDIR "/var/cache/fastphoto"
typedef struct fastphoto_s fastphoto_t;
+typedef struct config_s config_t;
typedef struct photo_s photo_t;
+struct config_s {
+ char * cachedir;
+};
+
struct photo_s {
char * name;
time_t mtime;
off_t size;
};
struct fastphoto_s {
+ config_t config;
+
photo_t in;
photo_t out;
View
@@ -0,0 +1,52 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include "fastphoto.h"
+#include "xini.h"
+
+static XiniStatus
+config_section (const char * name, void * user_data)
+{
+ return XINI_OK;
+}
+
+static XiniStatus
+config_assign (const char * name, const char * value, void * user_data)
+{
+ config_t * config = (config_t *) user_data;
+
+ fprintf (stderr, "CONFIG: %s = %s\n", name, value);
+
+ if (!strncmp (name, "cachedir", 8)) {
+ config->cachedir = strdup (value);
+ }
+
+ return XINI_OK;
+}
+
+static int
+config_read (config_t * config, const char * path)
+{
+ XiniStatus status;
+
+ fprintf (stderr, "CONFIG: Reading %s\n", path);
+
+ status = xini_read (path, config_section, config, config_assign, config);
+
+ fprintf (stderr, "CONFIG: status %d\n", status);
+
+ return (status == XINI_OK) ? 0 : -1;
+}
+
+int
+config_init (config_t * config)
+{
+ config->cachedir = FASTPHOTO_DEFAULT_CACHEDIR;
+
+ config_read (config, "/etc/fastphoto/fastphoto.ini");
+}
View
@@ -0,0 +1,8 @@
+#ifndef __CONFIG_H__
+#define __CONFIG_H__
+
+#include "fastphoto.h"
+
+int config_init (config_t * config);
+
+#endif /* __CONFIG_H__ */
Oops, something went wrong.

0 comments on commit ee58cc2

Please sign in to comment.