libaacs | branch: master | npzacs <[email protected]> | Wed Nov  3 13:33:45 2010 
+0200| [ae43763e3168602a7becc7f537cc2beed23b3631] | committer: npzacs 

Moved _find_cfg_file() to keydbcfg.c

> http://git.videolan.org/gitweb.cgi/libaacs.git/?a=commit;h=ae43763e3168602a7becc7f537cc2beed23b3631
---

 src/Makefile.am     |    1 +
 src/file/keydbcfg.c |   65 +++++++++++++++++++++++++++++++++++++++++++++++++++
 src/file/keydbcfg.h |    5 ++++
 src/libaacs/aacs.c  |   30 +----------------------
 4 files changed, 72 insertions(+), 29 deletions(-)

diff --git a/src/Makefile.am b/src/Makefile.am
index 7cf7a12..e3de247 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -30,6 +30,7 @@ libaacs_la_SOURCES=libaacs/aacs.h \
        file/file.h \
        file/filesystem.h \
        file/file_posix.c \
+       file/keydbcfg.c \
        file/keydbcfg.h \
        file/keydbcfg-parser.y \
        file/keydbcfg-lexer.l \
diff --git a/src/file/keydbcfg.c b/src/file/keydbcfg.c
new file mode 100644
index 0000000..8289c74
--- /dev/null
+++ b/src/file/keydbcfg.c
@@ -0,0 +1,65 @@
+/*
+ * This file is part of libaacs
+ * Copyright (C) 2010  npzacs
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+#include "keydbcfg.h"
+
+#include "util/strutl.h"
+#include "util/logging.h"
+#include "util/macro.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+
+#define USER_CFG_DIR   "/.libaacs/"
+#define SYSTEM_CFG_DIR "/etc/libaacs/"
+
+#define CFG_FILE_NAME  "KEYDB.cfg"
+
+
+char *keydbcfg_find_config_file(void)
+{
+    static const char cfg_file_user[]   = USER_CFG_DIR   CFG_FILE_NAME;
+    static const char cfg_file_system[] = SYSTEM_CFG_DIR CFG_FILE_NAME;
+
+    const char *userhome = getenv("HOME");
+
+    char *cfg_file = str_printf("%s%s", userhome, cfg_file_user);
+
+    FILE *fp = fopen(cfg_file, "r");
+    if (!fp) {
+
+        cfg_file = (char*)realloc(cfg_file, sizeof(cfg_file_system));
+        strcpy(cfg_file, cfg_file_system);
+
+        fp = fopen(cfg_file, "r");
+        if (!fp) {
+            DEBUG(DBG_FILE, "No config file found!\n");
+            X_FREE(cfg_file);
+            return NULL;
+        }
+    }
+
+    fclose(fp);
+
+    DEBUG(DBG_FILE, "found config file: %s\n", cfg_file);
+    return cfg_file;
+}
+
diff --git a/src/file/keydbcfg.h b/src/file/keydbcfg.h
index cadb9b9..9c273f9 100644
--- a/src/file/keydbcfg.h
+++ b/src/file/keydbcfg.h
@@ -114,4 +114,9 @@ AACS_PRIVATE int keydbcfg_parse_config(config_file 
*cfgfile, const char *path);
 AACS_PRIVATE config_file *keydbcfg_new_config_file();
 AACS_PRIVATE int keydbcfg_config_file_close(config_file *cfgfile);
 
+/* */
+
+AACS_PRIVATE char *keydbcfg_find_config_file(void);
+
+
 #endif
diff --git a/src/libaacs/aacs.c b/src/libaacs/aacs.c
index 535bf90..f9a149d 100644
--- a/src/libaacs/aacs.c
+++ b/src/libaacs/aacs.c
@@ -544,34 +544,6 @@ static int _decrypt_unit(AACS *aacs, uint8_t *out_buf, 
const uint8_t *in_buf, ui
     return 0;
 }
 
-static char *_find_cfg_file(void)
-{
-    static const char cfg_file_user[]   = "/.libaacs/KEYDB.cfg";
-    static const char cfg_file_system[] = "/etc/libaacs/KEYDB.cfg";
-
-    const char *userhome = getenv("HOME");
-
-    char *cfg_file = str_printf("%s%s", userhome, cfg_file_user);
-
-    FILE *fp = fopen(cfg_file, "r");
-    if (!fp) {
-
-        cfg_file = (char*)realloc(cfg_file, sizeof(cfg_file_system));
-        strcpy(cfg_file, cfg_file_system);
-
-        fp = fopen(cfg_file, "r");
-        if (!fp) {
-            DEBUG(DBG_AACS, "No configfile found!\n");
-            X_FREE(cfg_file);
-            return NULL;
-        }
-    }
-
-    fclose(fp);
-
-    return cfg_file;
-}
-
 AACS *aacs_open(const char *path, const char *configfile_path)
 {
     DEBUG(DBG_AACS, "libaacs [%zd]\n", sizeof(AACS));
@@ -591,7 +563,7 @@ AACS *aacs_open(const char *path, const char 
*configfile_path)
         /* If no configfile path given, check for configfiles in user's home or
          * under /etc.
          */
-        cfgfile = _find_cfg_file();
+        cfgfile = keydbcfg_find_config_file();
         if (!cfgfile) {
             DEBUG(DBG_AACS, "No configfile found!\n");
             return NULL;

_______________________________________________
libaacs-devel mailing list
[email protected]
http://mailman.videolan.org/listinfo/libaacs-devel

Reply via email to