Kaydet (Commit) fe8cbdf5 authored tarafından Gürer Özen's avatar Gürer Özen

model dosyası ve database dizini ayarlama opsiyonları.

model gerçekten dosyadan okunuyor artık.
i18n headerı.
üst a361d0b2
......@@ -13,7 +13,8 @@ OBJS = \
src/process.o \
src/csl.o \
src/data.o \
src/rpc_unix.o
src/rpc_unix.o \
src/iksemel.o
comar: $(OBJS)
$(CC) -o $@ $(OBJS) -ldb $(PYTHON_LIBS)
......
......@@ -10,6 +10,9 @@
#ifndef CFG_H
#define CFG_H 1
extern char *cfg_model_file;
extern char *cfg_data_dir;
void cfg_init(int argc, char *argv[]);
......
/*
** Copyright (c) 2005, TUBITAK/UEKAE
**
** This program 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 2 of the License, or (at your
** option) any later version. Please read the COPYING file.
*/
#ifndef I18N_H
#define I18N_H 1
#ifdef ENABLE_NLS
# include <locale.h>
# include <libintl.h>
# define _(String) gettext(String)
# ifdef gettext_noop
# define N_(String) gettext_noop(String)
# else
# define N_(String) (String)
# endif
#else
/* stubs that do something close enough */
# define textdomain(String)
# define bindtextdomain(Domain, Directory)
# define bind_textdomain_codeset(Domain, Codeset)
# define _(String) (String)
# define N_(String) (String)
# define gettext(String) (String)
# define dgettext(Domain,Message) (Message)
# define dcgettext(Domain,Message,Type) (Message)
#endif
#endif /* I18N_H */
This diff is collapsed.
<comar>
<model name='PARDUS'>
<group name='Net'>
<object name='NIC'>
<method name='up'/>
<method name='down'/>
</object>
</group>
</model>
</comar>
......@@ -12,27 +12,49 @@
#include <string.h>
#include <getopt.h>
/* possible options:
database dir, model file, daemon mode, log/debug output
*/
#include "i18n.h"
#include "cfg.h"
/* global option variables with defaults */
// FIXME: test only, proper defaults are given in comments
char *cfg_model_file = "model.xml"; // /etc/comar/system_model.xml
char *cfg_data_dir = "db"; // /var/lib/comar
static struct option longopts[] = {
{ "help", 0, 0, 'h' },
{ "version", 0, 0, 'v' },
{ 0, 0, 0, 0 }
{ "model", required_argument, NULL, 'm' },
{ "datadir", required_argument, NULL, 'd' },
{ "help", 0, NULL, 'h' },
{ "version", 0, NULL, 'v' },
{ NULL, 0, NULL, 0 }
};
static char *shortopts = "hv";
static char *shortopts = "m:d:hv";
static void
print_usage(void)
{
puts(
"Usage: comard [OPTIONS]\n"
_("Usage: comard [OPTIONS]\n"
"Pardus configuration manager.\n"
" -m, --model [FILE] Use the given xml model file.\n"
" -d, --datadir [DIR] Data storage directory.\n"
" -h, --help Print this text and exit.\n"
" -v, --version Print version and exit.\n"
"Report bugs to http://bugs.uludag.org.tr"
"Report bugs to http://bugs.uludag.org.tr")
);
}
static void
print_version(void)
{
printf(
_("COMARd %s\n"
"Copyright (c) 2005, TUBITAK/UEKAE\n"
"This program is free software; you can redistribute it and/or modify it\n"
"under the terms of the GNU General Public License as published by the\n"
"Free Software Foundation; either version 2 of the License, or (at your\n"
"option) any later version.\n"),
VERSION
);
}
......@@ -43,12 +65,20 @@ cfg_init(int argc, char *argv[])
while ((c = getopt_long(argc, argv, shortopts, longopts, &i)) != -1) {
switch (c) {
case 'm':
cfg_model_file = optarg;
break;
case 'd':
cfg_data_dir = optarg;
break;
case 'h':
print_usage();
exit(0);
case 'v':
puts("COMARd "VERSION);
print_version();
exit(0);
default:
exit(1);
}
}
}
......@@ -14,11 +14,9 @@
#include <stdlib.h>
#include <sys/stat.h>
#include "cfg.h"
#include "data.h"
// for testing without root, final place would probably be /var/lib/comar
#define COMAR_DATA_DIR "db"
static DB_ENV *my_env;
static int nr_open_dbs;
......@@ -27,9 +25,9 @@ db_init(void)
{
struct stat fs;
if (stat(COMAR_DATA_DIR, &fs) != 0) {
if (0 != mkdir(COMAR_DATA_DIR, S_IRWXU)) {
printf("Cannot create data dir '%s'\n", COMAR_DATA_DIR);
if (stat(cfg_data_dir, &fs) != 0) {
if (0 != mkdir(cfg_data_dir, S_IRWXU)) {
printf("Cannot create data dir '%s'\n", cfg_data_dir);
return -1;
}
} else {
......@@ -52,7 +50,7 @@ open_db(const char *name)
printf("Cannot create env, %s\n", db_strerror(e));
return NULL;
}
e = my_env->open(my_env, COMAR_DATA_DIR, DB_INIT_LOCK | DB_INIT_MPOOL
e = my_env->open(my_env, cfg_data_dir, DB_INIT_LOCK | DB_INIT_MPOOL
| DB_INIT_LOG | DB_INIT_TXN | DB_CREATE, 0);
if (e) {
printf("Cannot open env, %s\n", db_strerror(e));
......
This diff is collapsed.
......@@ -30,7 +30,7 @@ main(int argc, char *argv[])
if (db_init() != 0) return 1;
proc_init();
model_init();
if (model_init() != 0) return 1;
rpc = proc_fork(rpc_unix_start);
......
......@@ -7,13 +7,17 @@
** option) any later version. Please read the COPYING file.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "i18n.h"
#include "iksemel.h"
#include "cfg.h"
#include "model.h"
enum {
N_MODULE,
N_GROUP,
N_OBJECT,
N_METHOD
};
......@@ -81,18 +85,116 @@ add_node(int parent_no, const char *path, int type)
return n->no;
}
static char *
build_path(iks *g, iks *o, iks *m)
{
static char *ptr = NULL;
if (ptr) {
ptr += strlen(ptr) + 1;
} else {
ptr = paths;
}
if (m) {
sprintf(ptr, "%s.%s.%s",
iks_find_attrib(g, "name"),
iks_find_attrib(o, "name"),
iks_find_attrib(m, "name")
);
} else if (o) {
sprintf(ptr, "%s.%s",
iks_find_attrib(g, "name"),
iks_find_attrib(o, "name")
);
} else {
strcpy(ptr, iks_find_attrib(g, "name"));
}
return ptr;
}
int
model_init(void)
{
int no;
iks *doc, *model;
iks *grp, *obj, *met;
int count = 0;
size_t size = 0;
size_t grp_size, obj_size, met_size;
int grp_no, obj_no;
int e;
// parse model file
e = iks_load(cfg_model_file, &doc);
if (e) {
fprintf(stderr, "Cannot process model file '%s'\n", cfg_model_file);
return -1;
}
// FIXME: silly test case, replace with real loader
if (prepare_tables(4, 128)) return -1;
model = iks_find(doc, "model");
if (iks_strcmp(iks_name(doc), "comar") != 0 || model == NULL) {
fprintf(stderr, "Not a COMAR model file '%s'\n", cfg_model_file);
return -1;
}
// scan the model
for (grp = iks_first_tag(model); grp; grp = iks_next_tag(grp)) {
if (iks_strcmp(iks_name(grp), "group") == 0) {
grp_size = iks_strlen(iks_find_attrib(grp, "name"));
if (!grp_size) {
fprintf(stderr, "Broken COMAR model file '%s'\n", cfg_model_file);
return -1;
}
size += grp_size + 1;
++count;
for (obj = iks_first_tag(grp); obj; obj = iks_next_tag(obj)) {
if (iks_strcmp(iks_name(obj), "object") == 0) {
obj_size = iks_strlen(iks_find_attrib(obj, "name"));
if (!obj_size) {
fprintf(stderr, "Broken COMAR model file '%s'\n", cfg_model_file);
return -1;
}
size += grp_size + obj_size + 2;
++count;
for (met = iks_first_tag(obj); met; met = iks_next_tag(met)) {
if (iks_strcmp(iks_name(met), "method") == 0) {
met_size = iks_strlen(iks_find_attrib(met, "name"));
if (!met_size) {
fprintf(stderr, "Broken COMAR model file '%s'\n", cfg_model_file);
return -1;
}
size += grp_size + obj_size + met_size + 3;
++count;
}
}
}
}
}
}
// prepare data structures
if (prepare_tables(nr_nodes, size)) return -1;
// load the model
for (grp = iks_first_tag(model); grp; grp = iks_next_tag(grp)) {
if (iks_strcmp(iks_name(grp), "group") == 0) {
grp_no = add_node(-1, build_path(grp, NULL, NULL), N_GROUP);
for (obj = iks_first_tag(grp); obj; obj = iks_next_tag(obj)) {
if (iks_strcmp(iks_name(obj), "object") == 0) {
obj_no = add_node(grp_no, build_path(grp, obj, NULL), N_OBJECT);
for (met = iks_first_tag(obj); met; met = iks_next_tag(met)) {
if (iks_strcmp(iks_name(met), "method") == 0) {
add_node(obj_no, build_path(grp, obj, met), N_METHOD);
}
}
}
}
}
}
no = add_node(-1, "Net", N_MODULE);
no = add_node(no, "Net.NIC", N_OBJECT);
add_node(no, "Net.NIC.up", N_METHOD);
add_node(no, "Net.NIC.down", N_METHOD);
// no need to keep dom tree in memory
iks_delete(doc);
return 0;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment