[Uludag-commits] r16271 - in branches/comar-dbus: . etc/introspections include src tests tests/code tests/data tests/data/code

uludag-commits at pardus.org.tr uludag-commits at pardus.org.tr
9 Ara 2007 Paz 02:38:20 EET


Author: bahadir.kandemir
Date: Sun Dec  9 02:38:20 2007
New Revision: 16271

Added:
   branches/comar-dbus/etc/introspections/
   branches/comar-dbus/etc/introspections/Boot_Loader.xml
   branches/comar-dbus/etc/introspections/System_Package.xml
   branches/comar-dbus/include/data.h
   branches/comar-dbus/include/iksemel.h
   branches/comar-dbus/include/xml.h
   branches/comar-dbus/src/data.c
   branches/comar-dbus/src/iksemel.c
   branches/comar-dbus/src/xml.c
   branches/comar-dbus/tests/data/
   branches/comar-dbus/tests/data/code/
      - copied from r16270, branches/comar-dbus/tests/code/
Removed:
   branches/comar-dbus/tests/code/
Modified:
   branches/comar-dbus/CMakeLists.txt
   branches/comar-dbus/include/cfg.h
   branches/comar-dbus/include/csl.h
   branches/comar-dbus/include/log.h
   branches/comar-dbus/include/utility.h
   branches/comar-dbus/src/cfg.c
   branches/comar-dbus/src/csl.c
   branches/comar-dbus/src/dbus.c
   branches/comar-dbus/src/log.c
   branches/comar-dbus/src/main.c
   branches/comar-dbus/src/utility.c
   branches/comar-dbus/tests/run.sh
Log:
<SPOILER ALERT>
    This is a long long commit.
</SPOILER ALERT>


- Comar now provides object path and interface lists. It generates 
lists from application database (in data dir) and model 
introspections folder (in config dir).

- XML and database codes forwardported from Comar 1.*

- Comar uses new application database to check object path and 
interface format/existance

- Comar now has a new commandline argument for setting optional 
config dir.

- Boot.Loader and System.Package models ported (etc/)

- Better exception handling in CSL

- Minor changes in utility.c to suit new features.


TODO: Application/Model/Script register/remove methods



Modified: branches/comar-dbus/CMakeLists.txt
=================================================================
--- branches/comar-dbus/CMakeLists.txt	(original)
+++ branches/comar-dbus/CMakeLists.txt	Sun Dec  9 02:38:20 2007
@@ -12,12 +12,15 @@
                dbus-1
                gobject-2.0
                glib-2.0
-               polkit)
+               db)
 
 add_executable(comar-dbus src/main.c
                           src/cfg.c
                           src/csl.c
+                          src/data.c
                           src/dbus.c
+                          src/iksemel.c
                           src/log.c
                           src/process.c
-                          src/utility.c)
+                          src/utility.c
+                          src/xml.c)

Modified: branches/comar-dbus/include/cfg.h
=================================================================
--- branches/comar-dbus/include/cfg.h	(original)
+++ branches/comar-dbus/include/cfg.h	Sun Dec  9 02:38:20 2007
@@ -10,12 +10,13 @@
 #define VERSION "2.0"
 
 extern char *cfg_bus_name;
+extern char *cfg_config_dir;
 extern char *cfg_data_dir;
 extern int cfg_bus_type;
 extern int cfg_idle_shutdown;
 extern int cfg_log_console;
 extern int cfg_log_file;
 extern char *cfg_log_file_name;
-extern int cfg_log_level;
+extern int cfg_log_flags;
 
 void cfg_init(int argc, char *argv[]);

Modified: branches/comar-dbus/include/csl.h
=================================================================
--- branches/comar-dbus/include/csl.h	(original)
+++ branches/comar-dbus/include/csl.h	Sun Dec  9 02:38:20 2007
@@ -10,6 +10,6 @@
 #include <dbus/dbus.h>
 #include <Python.h>
 
-PyObject *py_call_method(const char *model, const char *app, const char *method, PyObject *args);
+int py_call_method(const char *app, const char *model, const char *method, PyObject *args, PyObject **result);
 PyObject *dbus_py_import(DBusMessage *msg);
-void dbus_py_export(DBusMessageIter *iter, PyObject *obj);
+int dbus_py_export(DBusMessageIter *iter, PyObject *obj);

Modified: branches/comar-dbus/include/log.h
=================================================================
--- branches/comar-dbus/include/log.h	(original)
+++ branches/comar-dbus/include/log.h	Sun Dec  9 02:38:20 2007
@@ -7,13 +7,10 @@
 ** option) any later version. Please read the COPYING file.
 */
 
-enum LOG {
-    LOG_CALL = 0,
-    LOG_PROC,
-    LOG_DBUS,
-    LOG_PERF,
-    LOG_FULL
-};
+#define LOG_DBUS 1
+#define LOG_PROC 2
+#define LOG_PERF 4
+#define LOG_FULL 0xffffffff
 
 void log_start(void);
 void log_error(const char *fmt, ...);

Modified: branches/comar-dbus/include/utility.h
=================================================================
--- branches/comar-dbus/include/utility.h	(original)
+++ branches/comar-dbus/include/utility.h	Sun Dec  9 02:38:20 2007
@@ -7,9 +7,14 @@
 ** option) any later version. Please read the COPYING file.
 */
 
+#include <sys/time.h>
+
 int check_file(const char *fname);
 unsigned char *load_file(const char *fname, int *sizeptr);
-int check_interface_format(const char *interface);
-int check_path_format(const char *path);
+int check_model_name(const char *model);
+int check_app_name(const char *app);
 char *get_script_path(const char *interface, const char *path);
+char *get_xml_path(const char *model);
 unsigned long time_diff(struct timeval *start, struct timeval *end);
+char *str_replace(const char *str, const char old, const char new);
+char *str_lshift(const char *str, int num);

Modified: branches/comar-dbus/src/cfg.c
=================================================================
--- branches/comar-dbus/src/cfg.c	(original)
+++ branches/comar-dbus/src/cfg.c	Sun Dec  9 02:38:20 2007
@@ -20,20 +20,20 @@
 
 // Global options
 char *cfg_bus_name = "tr.org.pardus.comar";
+char *cfg_config_dir = "/etc/comar";
 char *cfg_data_dir = "/var/db/comar";
 int cfg_bus_type = DBUS_BUS_SYSTEM;
 int cfg_idle_shutdown = 30;
 int cfg_log_console = 0;
 int cfg_log_file = 1;
 char *cfg_log_file_name = "/var/log/comar.log";
-int cfg_log_level = 0;
+int cfg_log_flags = 0;
 
 // Log flags
 static struct logflag_struct {
     const char *flag;
     int value;
 } logflags[] = {
-    { "call", LOG_CALL },
     { "proc", LOG_PROC },
     { "dbus", LOG_DBUS },
     { "perf", LOG_PERF },
@@ -44,6 +44,7 @@
 
 // Command line options
 static struct option longopts[] = {
+    { "configdir", required_argument, NULL, 'c' },
     { "datadir", required_argument, NULL, 'd' },
     { "debug", required_argument, NULL, 'g' },
     { "idle", required_argument, NULL, 'i' },
@@ -54,7 +55,7 @@
     { NULL, 0, NULL, 0 }
 };
 
-static char *shortopts = "d:g:i:pt:hv";
+static char *shortopts = "c:d:g:i:pt:hv";
 
 // Help message
 static void
@@ -63,17 +64,21 @@
     printf(
         _("Usage: comar [OPTIONS]\n"
         "Pardus configuration manager.\n"
-        " -d, --datadir [DIR] Data storage directory.\n"
-        "                     (default is %s)\n"
-        " -g, --debug [LEVEL] Set debug level.\n"
-        " -t, --type   [TYPE] DBus service type (system or session).\n"
-        "                     (default is system)\n"
-        " -i, --idle   [SECS] Shutdown after [SECS] seconds with no action.\n"
-        "                     (Only works with session type, default is %d)\n"
-        " -p, --print         Print debug messages to console.\n"
-        " -h, --help          Print this text and exit.\n"
-        " -v, --version       Print version and exit.\n"
+        " -c, --configdir [DIR] Configuration directory.\n"
+        "                       (default is %s)\n"
+        " -d, --datadir   [DIR] Data storage directory.\n"
+        "                       (default is %s)\n"
+        " -g, --debug    [FLAG] Set debug flag.\n"
+        "                       (Flags: dbus, proc, perf, full)\n"
+        " -t, --type     [TYPE] DBus service type (system or session).\n"
+        "                       (default is system)\n"
+        " -i, --idle     [SECS] Shutdown after [SECS] seconds with no action.\n"
+        "                       (Only works with session type, default is %d)\n"
+        " -p, --print           Print debug messages to console.\n"
+        " -h, --help            Print this text and exit.\n"
+        " -v, --version         Print version and exit.\n"
         "Report bugs to http://bugs.pardus.org.tr\n"),
+        cfg_config_dir,
         cfg_data_dir,
         cfg_idle_shutdown
     );
@@ -102,13 +107,16 @@
 
     while ((c = getopt_long(argc, argv, shortopts, longopts, &i)) != -1) {
         switch (c) {
+            case 'c':
+                cfg_config_dir = strdup(optarg);
+                break;
             case 'd':
                 cfg_data_dir = strdup(optarg);
                 break;
             case 'g':
                 for (j = 0; logflags[j].flag; ++j) {
                     if (strstr(optarg, logflags[j].flag))
-                        cfg_log_level = logflags[j].value;
+                        cfg_log_flags |= logflags[j].value;
                 }
                 break;
             case 'i':

Modified: branches/comar-dbus/src/csl.c
=================================================================
Suppressed!
	Too long (more than 250 lines) diff output suppressed...
Modified: branches/comar-dbus/src/dbus.c
=================================================================
Suppressed!
	Too long (more than 250 lines) diff output suppressed...
Modified: branches/comar-dbus/src/log.c
=================================================================
--- branches/comar-dbus/src/log.c	(original)
+++ branches/comar-dbus/src/log.c	Sun Dec  9 02:38:20 2007
@@ -55,6 +55,7 @@
 
     if (cfg_log_console) {
         pidstamp(stdout);
+        if (error) printf("Error: ");
         vprintf(fmt, ap);
     }
 
@@ -124,7 +125,7 @@
 {
     va_list ap;
 
-    if (cfg_log_level < subsys)
+    if ((cfg_log_flags & subsys) == 0)
         return;
 
     va_start(ap, fmt);

Modified: branches/comar-dbus/src/main.c
=================================================================
--- branches/comar-dbus/src/main.c	(original)
+++ branches/comar-dbus/src/main.c	Sun Dec  9 02:38:20 2007
@@ -12,6 +12,7 @@
 #include <dbus/dbus.h>
 
 #include "cfg.h"
+#include "data.h"
 #include "dbus.h"
 #include "i18n.h"
 #include "log.h"
@@ -39,7 +40,13 @@
         exit(1);
     }
 
-    // Initialize
+    // Initialize DB
+    if (db_init() != 0) {
+        puts(_("Database is corrupt."));
+        exit(1);
+    }
+
+    // Initialize main process
     proc_init(argc, argv, "Comar");
 
     // Start logging

Modified: branches/comar-dbus/src/utility.c
=================================================================
--- branches/comar-dbus/src/utility.c	(original)
+++ branches/comar-dbus/src/utility.c	Sun Dec  9 02:38:20 2007
@@ -18,7 +18,7 @@
 #include "utility.h"
 
 const char *valid_app_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-+";
-const char *valid_interface_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.";
+const char *valid_model_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.";
 const char *path_prefix = "/package/";
 
 int
@@ -72,16 +72,16 @@
 }
 
 int
-check_interface_format(const char *interface)
+check_model_name(const char *model)
 {
     int i;
 
-    if (interface == NULL) {
+    if (model == NULL) {
         return 0;
     }
 
-    for (i = 0; i < strlen(interface); i++) {
-        if (!in_str(interface[i], valid_interface_chars)) {
+    for (i = 0; i < strlen(model); i++) {
+        if (!in_str(model[i], valid_model_chars)) {
             return 0;
         }
     }
@@ -89,20 +89,16 @@
 }
 
 int
-check_path_format(const char *path)
+check_app_name(const char *app)
 {
     int i;
 
-    if (path == NULL) {
+    if (app == NULL) {
         return 0;
     }
 
-    if (strncmp(path, path_prefix, strlen(path_prefix))) {
-        return 0;
-    }
-
-    for (i = strlen(path_prefix); i < strlen(path); i++) {
-        if (!in_str(path[i], valid_app_chars)) {
+    for (i = 0; i < strlen(app); i++) {
+        if (!in_str(app[i], valid_app_chars)) {
             return 0;
         }
     }
@@ -114,46 +110,66 @@
 {
     char *new_str, *old_str, *t, *t2;
     int size;
-    old_str = strdup(str);
 
-    size = strlen(old_str) - num + 1;
+    size = strlen(str) - num + 1;
     new_str = malloc(size);
 
-    for (t = old_str + num, t2 = new_str; *t != '\0'; t++, t2++) {
+    for (t = (char *) str + num, t2 = new_str; *t != '\0'; t++, t2++) {
         *t2 = *t;
     }
     *t2 = '\0';
 
-    free(old_str);
+    return new_str;
+}
+
+char *
+str_replace(const char *str, const char old, const char new)
+{
+    char *new_str, *t, *t2;
+    int size;
+
+    new_str = strdup(str);
+
+    for (t = new_str; *t != '\0'; t++) {
+        if (*t == old) {
+            *t = new;
+        }
+    }
 
     return new_str;
 }
 
 char *
-get_script_path(const char *interface, const char *path)
+get_xml_path(const char *model)
 {
-    char *realpath, *model, *app, *t, *t2;
+    char *realpath, *model_escaped, *t, *t2;
     int size;
 
-    model = strdup(interface);
+    size = strlen(cfg_config_dir) + 1 + strlen("introspections") + 1 + strlen(model) + 5;
+    realpath = malloc(size);
+
+    model_escaped = (char *) str_replace(model, '.', '_');
+
+    // Generate script path
+    snprintf(realpath, size, "%s/introspections/%s.xml\0", cfg_config_dir, model_escaped);
+    free(model_escaped);
+    return realpath;
+}
 
-    // Get application name from object path
-    app = str_lshift(path, strlen(path_prefix));
+char *
+get_script_path(const char *app, const char *model)
+{
+    char *realpath, *model_escaped, *t, *t2;
+    int size;
 
-    size = strlen(cfg_data_dir) + 6 + strlen(model) + 1 + strlen(app) + 4;
+    size = strlen(cfg_data_dir) + 1 + strlen("code") + 1 + strlen(model) + 1 + strlen(app) + 4;
     realpath = malloc(size);
 
-    // Get model name from interface
-    for (t = model; *t != '\0'; t++) {
-        if (*t == '.') {
-            *t = '_';
-        }
-    }
+    model_escaped = (char *) str_replace(model, '.', '_');
 
     // Generate script path
-    snprintf(realpath, size, "%s/code/%s_%s.py", cfg_data_dir, model, app);
-    free(app);
-    free(model);
+    snprintf(realpath, size, "%s/code/%s_%s.py\0", cfg_data_dir, model_escaped, app);
+    free(model_escaped);
     return realpath;
 }
 

Modified: branches/comar-dbus/tests/run.sh
=================================================================
--- branches/comar-dbus/tests/run.sh	(original)
+++ branches/comar-dbus/tests/run.sh	Sun Dec  9 02:38:20 2007
@@ -1 +1 @@
-sudo ../comar-dbus --print --datadir=. --debug=all
+sudo ../comar-dbus --print --configdir=../etc --datadir=data --debug=all


Uludag-commits mesaj listesiyle ilgili daha fazla bilgi