19 #include <ucommon/ucommon.h>
20 #include <ucommon/export.h>
28 using namespace UCOMMON_NAMESPACE;
31 bool Env::daemon_flag =
true;
32 bool Env::tool_flag =
false;
34 void Env::init(shell_t *args)
39 const char *rundir = strdup(str(env(
"APPDATA")) +
"/bayonne");
40 const char *prefix =
"C:\\Program Files\\bayonne";
41 const char *plugins =
"C:\\Program Files\\bayonne\\plugins";
43 set(
"config", _STR(str(prefix) +
"/bayonne.ini"));
44 set(
"configs", _STR(str(prefix) +
"\\config\\"));
45 set(
"services", _STR(str(prefix) +
"/services"));
46 set(
"controls", rundir);
47 set(
"control",
"\\\\.\\mailslot\\bayonne_ctrl");
48 set(
"snapshot", _STR(str(rundir) +
"/snapshot.log"));
49 set(
"boards", _STR(str(rundir) +
"/boards.log"));
50 set(
"spans", _STR(str(rundir) +
"/spans.log"));
51 set(
"logfiles", _STR(str(prefix) +
"/logs"));
52 set(
"logfile", _STR(str(prefix) +
"/logs/bayonne.log"));
53 set(
"calls", _STR(str(prefix) +
"/logs/bayonne.calls"));
54 set(
"stats", _STR(str(prefix) +
"/logs/bayonne.stats"));
55 set(
"scripts", _STR(str(prefix) +
"/scripts"));
56 set(
"appaudio", _STR(str(prefix) +
"/audio"));
57 set(
"sounds", _STR(str(prefix) +
"/sounds"));
58 set(
"definitions", _STR(str(prefix) +
"/scripts"));
59 set(
"shell",
"cmd.exe");
60 set(
"voices", _STR(str(prefix) +
"\\voices"));
61 set(
"temp",
"C:\\Program Files\\bayonne\\temp");
63 prefix =
"C:\\Program Files\\bayonne\\datafiles";
66 const char *prefix = DEFAULT_VARPATH
"/lib/bayonne";
67 const char *rundir = DEFAULT_VARPATH
"/run/bayonne";
68 const char *plugins = DEFAULT_LIBPATH
"/bayonne";
70 set(
"reply",
"/tmp/.bayonne.");
71 set(
"config", DEFAULT_CFGPATH
"/bayonne.conf");
72 set(
"configs", DEFAULT_CFGPATH
"/bayonne/");
73 set(
"services", DEFAULT_SCRPATH);
74 set(
"controls", DEFAULT_VARPATH
"/run/bayonne");
75 set(
"control", DEFAULT_VARPATH
"/run/bayonne/control");
76 set(
"snapshot", DEFAULT_VARPATH
"/run/bayonne/snapshot");
77 set(
"boards", DEFAULT_VARPATH
"/run/bayonne/boards");
78 set(
"spans", DEFAULT_VARPATH
"/run/bayonne/spans");
79 set(
"logfiles", DEFAULT_VARPATH
"/log");
80 set(
"logfile", DEFAULT_VARPATH
"/log/bayonne.log");
81 set(
"calls", DEFAULT_VARPATH
"/log/bayonne.calls");
82 set(
"stats", DEFAULT_VARPATH
"/log/bayonne.stats");
83 set(
"scripts", DEFAULT_VARPATH
"/lib/bayonne/scripts");
84 set(
"audio", DEFAULT_DATADIR
"/bayonne");
85 set(
"sounds", DEFAULT_DATADIR
"/sounds");
86 set(
"applications", DEFAULT_DATADIR
"/bayonne");
87 set(
"definitions", DEFAULT_DATADIR
"/bayonne");
88 set(
"shell",
"/bin/sh");
89 set(
"voices", DEFAULT_DATADIR
"/phrasebook");
90 set(
"temp", DEFAULT_VARPATH
"/tmp/bayonne");
94 const char *home_prefix = NULL;
95 struct passwd *pwd = getpwuid(getuid());
98 if(getuid() && pwd && pwd->pw_dir && *pwd->pw_dir ==
'/') {
99 if(!eq(pwd->pw_shell,
"/bin/false") && !eq(pwd->pw_dir,
"/var/", 5) && !eq(pwd->pw_dir,
"/srv/", 5)) {
104 prefix = strdup(pwd->pw_dir);
108 if(!daemon_flag && pwd)
109 home_prefix = strdup(str(pwd->pw_dir) +
"/.bayonne");
112 if(home_prefix && tool_flag && !fsys::isdir(home_prefix))
116 rundir = strdup(str(
"/tmp/bayonne-") + str(pwd->pw_name));
117 prefix = home_prefix;
119 set(
"config", _STR(str(pwd->pw_dir) +
"/.bayonnerc"));
120 set(
"configs", home_prefix);
121 set(
"scripts", home_prefix);
122 set(
"sysconfigs", _STR(str(DEFAULT_CFGPATH) +
"/bayonne"));
123 set(
"services", prefix);
124 set(
"controls", rundir);
125 set(
"control", _STR(str(rundir) +
"/control"));
126 set(
"snapshot", _STR(str(rundir) +
"/snapshot"));
127 set(
"boards", _STR(str(rundir) +
"/boards"));
128 set(
"spans", _STR(str(rundir) +
"/spans"));
129 set(
"logfiles", rundir);
130 set(
"logfile", _STR(str(rundir) +
"/logfile"));
131 set(
"calls", _STR(str(rundir) +
"/calls"));
132 set(
"stats", _STR(str(rundir) +
"/stats"));
133 set(
"prefix", prefix);
134 set(
"shell", pwd->pw_shell);
138 set(
"voice",
"default");
139 set(
"extension",
".au");
140 set(
"prefix", prefix);
141 set(
"rundir", rundir);
142 set(
"plugins", plugins);
145 void Env::tool(shell_t *args)
151 const char *Env::config(
const char *name)
154 const char *result = env(name);
158 const char *sysconfig = env(
"sysconfig");
160 string_t filename = str(env(
"configs")) + str(name);
162 if(sysconfig && !fsys::isfile(*filename))
163 filename = str(sysconfig) + str(name);
166 set(name, *filename);
170 const char *Env::path(pathinfo_t& pi,
const char *path,
char *buffer,
size_t size,
bool writeflag)
172 const char *ext = strrchr(path,
'/');
175 if(case_eq(path,
"file:", 5) || case_eq(path,
"tool:")) {
179 String::set(buffer, size, path + 5);
184 if(case_eq(path,
"out:", 4)) {
185 if(!tool_flag || !writeflag)
188 String::set(buffer, size, path + 4);
198 if(ext && strchr(path + 2,
':'))
202 if(!ext && strchr(path,
'.') && tool_flag && !strchr(path + 2,
':'))
206 ext = strchr(ext,
'.');
210 ext = env(
"extension");
212 if(*path !=
'/' && tool_flag)
213 snprintf(buffer, size,
"%s/%s%s",
214 env(
"prefix"), path, ext);
216 snprintf(buffer, size,
"%s%s", path, ext);
221 const char *voice = pi.voices;
223 voice = env(
"voice");
225 ext = strchr(path,
'.');
230 ext = env(
"extension");
233 if(case_eq(path,
"tmp:", 4) || case_eq(path,
"temp:", 5)) {
234 snprintf(buffer, size,
"%s/%s%s",
235 env(
"temp"), strchr(path,
':') + 1, ext);
240 if(case_eq(path,
"sound:", 6) || case_eq(path,
"sounds:", 7)) {
244 snprintf(buffer, size,
"%s/%s%s",
245 env(
"sounds"), strchr(path,
':') + 1, ext);
250 else if(case_eq(path,
"lib:", 4))
252 else if(strchr(path,
':'))
260 if(strchr(voice,
'/')) {
261 snprintf(buffer, size,
"%s/%s%s", voice, path, ext);
266 snprintf(buffer, size,
"%s%s%s/%s%s",
267 env(
"voices"), pi->path(), voice, path, ext);
#define BAYONNE_NAMESPACE
GNU Bayonne library namespace.