# Email gateway - general kernel resources
-# $Id: default.res,v 1.19 1995/05/03 07:37:32 adam Exp $
+# $Id: default.res,v 1.20 1995/05/03 16:34:17 adam Exp $
#
# Important directories, programs, etc.
gw.reply.mta: /usr/lib/sendmail
ccl.command.info: info i
ccl.command.continue: continue
ccl.command.status: status
-ccl.command.cancel: cancel
+ccl.command.def: def
+ccl.command.account: account
ccl.token.and: and
ccl.token.or: or
ccl.token.not: not
* Europagate, 1995
*
* $Log: kernel.h,v $
- * Revision 1.16 1995/05/03 07:37:37 adam
+ * Revision 1.17 1995/05/03 16:34:18 adam
+ * CCL def command, i.e. user definitions - saved as resource files.
+ *
+ * Revision 1.16 1995/05/03 07:37:37 adam
* CCL commands stop/continue implemented. New functions gw_res_{int,bool}
* are used when possible.
*
const char *reply_fname;
int setno;
int next_position;
+ int userid;
#if USE_FML
Fml fml;
#endif
* Europagate, 1995
*
* $Log: main.c,v $
- * Revision 1.22 1995/05/03 07:37:39 adam
+ * Revision 1.23 1995/05/03 16:34:18 adam
+ * CCL def command, i.e. user definitions - saved as resource files.
+ *
+ * Revision 1.22 1995/05/03 07:37:39 adam
* CCL commands stop/continue implemented. New functions gw_res_{int,bool}
* are used when possible.
*
struct gw_kernel_info info;
-static void kernel_events (struct str_queue *queue, int userid)
+static void kernel_events (struct str_queue *queue)
{
char fifo_client_name[1024];
char fifo_server_name[1024];
timeout = gw_res_int (info.kernel_res, "gw.timeout", 600);
gw_log (GW_LOG_DEBUG, KERNEL_LOG, "event loop");
- sprintf (fifo_client_name, "fifo.c.%d", userid);
- sprintf (fifo_server_name, "fifo.s.%d", userid);
+ sprintf (fifo_client_name, "fifo.c.%d", info.userid);
+ sprintf (fifo_server_name, "fifo.s.%d", info.userid);
gip = gips_initialize (fifo_server_name);
gips_open (gip, fifo_client_name);
gw_log (GW_LOG_STAT, KERNEL_LOG, "Timeout after %d seconds",
timeout);
if (info.zass && persist_flag)
- save_p_state (userid);
+ save_p_state (info.userid);
break;
}
if (FD_ISSET (gip_fd, &set_r))
str_queue_enq (queue, line_buf);
urp_start (continuation, queue);
if (persist_flag && !continuation)
- load_p_state (userid);
+ load_p_state (info.userid);
r = urp_command (queue);
if (persist_flag && r == 1)
- del_p_state (userid);
+ del_p_state (info.userid);
urp_end ();
while (str_queue_deq (queue, 0, 0))
;
close (extra_fd);
gips_close (gip);
gips_destroy (gip);
+
unlink (fifo_client_name);
unlink (fifo_server_name);
}
int main (int argc, char **argv)
{
- int userid = -1;
struct str_queue *queue;
info.kernel_res = NULL;
info.databases = NULL;
info.database = NULL;
info.setno = -1;
+ info.userid = -1;
#if USE_FML
info.fml = NULL;
#endif
break;
case 'i':
if (argv[0][2])
- userid = atoi (argv[0]+2);
+ info.userid = atoi (argv[0]+2);
else if (argc > 0)
{
--argc;
- userid = atoi (*++argv);
+ info.userid = atoi (*++argv);
}
else
{
gw_log (GW_LOG_FATAL|GW_LOG_ERRNO, KERNEL_LOG, "str_queue_mk");
exit (1);
}
- if (userid != -1)
+ if (info.userid != -1)
{
read_kernel_res ();
- kernel_events (queue, userid);
+ kernel_events (queue);
}
else
{
gw_log (GW_LOG_DEBUG, KERNEL_LOG, "reading kernel resource, lang %s",
info.lang);
+ /* read default resources. These should exist */
if (gw_res_merge (info.kernel_res, info.default_res))
{
gw_log (GW_LOG_WARN, KERNEL_LOG, "Couldn't read resource file %s",
}
strcpy (path_prefix, gw_res_get (info.kernel_res, "gw.path", "."));
+ /* fetch target definitions (if defined at all) */
if (*info.target)
{
sprintf (resource_name, "gw.target.%s", info.target);
gw_res_merge (info.kernel_res, fname);
}
}
- if (info.lang)
+ /* fetch user definitions (if user-id is specified) */
+ if (info.userid >= 0)
+ {
+ sprintf (fname, "%s/user.%d.r", path_prefix, info.userid);
+ gw_res_merge (info.kernel_res, fname);
+ }
+ /* fetch language definitions (if specified at all) */
+ v = gw_res_get (info.kernel_res, "gw.language", info.lang);
+ if (v)
{
- sprintf (resource_name, "gw.lang.%s", info.lang);
+ sprintf (resource_name, "gw.lang.%s", v);
v = gw_res_get (info.kernel_res, resource_name, NULL);
if (v)
{
gw_res_merge (info.kernel_res, fname);
}
}
+ /* fetch overriding resources from file (if specified) */
if (info.override_res)
{
sprintf (fname, "%s/%s", path_prefix, info.override_res);
gw_res_merge (info.kernel_res, fname);
}
+
+ /* read bibset definition for ccl */
v = gw_res_get (info.kernel_res, "gw.bibset", NULL);
if (v)
{
fclose (bib_inf);
}
}
+
+ /* determine host name and port no */
sprintf (resource_name, "gw.target.%s", info.target);
if (*info.target && ! gw_res_get (info.kernel_res, resource_name, NULL))
{
- /* target is there, and there is no sub-resource for it... */
+ /* target is specified, and there is no sub-resource for it... */
const char *split;
if ((split = strchr (info.target, ':')))
}
}
else
- {
+ { /* resources gw.hostname and gw.portno will be used */
strncpy (info.hostname, gw_res_get (info.kernel_res,
"gw.hostname", "localhost"),
sizeof(info.hostname)-1);
info.port = gw_res_int (info.kernel_res, "gw.portno", 210);
strcpy (info.account, gw_res_get (info.kernel_res, "gw.account", ""));
}
+ /* set info.databases (all available databases for target) */
+ /* set info.database (first database for target) */
if (info.databases)
free (info.databases);
if (info.database)
for (cp = info.database; (cp = strchr (cp, ' ')); cp++)
*cp = ',';
}
+
+ /* the port no can be explicitly overridden by a command line option */
if (info.override_portno)
info.port = atoi (info.override_portno);
+
+ /* the hostname can be explicitly overridden by a command line option */
if (info.override_hostname)
strncpy (info.hostname, info.override_hostname,
sizeof(info.hostname)-1);
+
+ /* determine if more than one result-set names is supported */
if (gw_res_bool (info.kernel_res, "gw.result.set", 1))
info.setno = 0;
else
* Europagate, 1995
*
* $Log: persist.c,v $
- * Revision 1.6 1995/05/03 07:37:44 adam
+ * Revision 1.7 1995/05/03 16:34:19 adam
+ * CCL def command, i.e. user definitions - saved as resource files.
+ *
+ * Revision 1.6 1995/05/03 07:37:44 adam
* CCL commands stop/continue implemented. New functions gw_res_{int,bool}
* are used when possible.
*
int hits;
struct gw_user_set *set;
- sprintf (fname, "persist.%d", userid);
+ sprintf (fname, "user.%d.p", userid);
inf = fopen (fname, "r");
if (!inf)
FILE *of;
char fname[128];
- sprintf (fname, "persist.%d", userid);
+ sprintf (fname, "user.%d.p", userid);
of = fopen (fname, "w");
if (!of)
{
char fname[128];
- sprintf (fname, "persist.%d", userid);
+ sprintf (fname, "user.%d.p", userid);
unlink (fname);
}
* Europagate, 1995
*
* $Log: urp.c,v $
- * Revision 1.32 1995/05/03 07:37:46 adam
+ * Revision 1.33 1995/05/03 16:34:19 adam
+ * CCL def command, i.e. user definitions - saved as resource files.
+ *
+ * Revision 1.32 1995/05/03 07:37:46 adam
* CCL commands stop/continue implemented. New functions gw_res_{int,bool}
* are used when possible.
*
/*
Todo:
- stop/continue commands
info/status (other name?)
- per-user definitions
better persistence diagnostics
- show - position continuation
resource gw.path - use chdir call instead
Optional:
return 0;
}
-
-static struct command_word {
+struct command_word {
char *default_value;
char *resource_suffix;
-} command_tab [] =
-{
-{ "find", "find"},
-{ "show", "show"},
-{ "base", "base" },
-{ "help", "help" },
-{ "info", "info" },
-{ "continue", "continue" },
-{ "status", "status" },
-{ "stop", "stop" },
-{ "target", "target" },
-{ "cancel", "cancel" },
-{ "account", "account" },
-{ NULL, NULL }
};
static int command_search (struct command_word *tab, struct ccl_token *cmd,
return 0;
}
-struct command_word show_tab [] =
-{
-{ "f", "format"},
-{ "p", "position"},
-{ NULL, NULL }
-};
-
static void present (const char *set, int offset, int number,
struct ccl_token *format_token)
{
static int exec_show (struct ccl_token *list)
{
+ static struct command_word show_tab [] =
+ {
+ { "f", "format"},
+ { "p", "position"},
+ { NULL, NULL }
+ };
char tmp_str[20];
struct ccl_token *set_token = NULL;
struct ccl_token *format_token = NULL;
return 0;
}
+static int exec_def (struct ccl_token *list)
+{
+ const char *name = NULL;
+ char value[128];
+ char fname[256];
+ static struct command_word def_tab [] =
+ {
+ { "reset", "reset" },
+ { "f", "format"},
+ { "maxshow", "maxshow" },
+ { "defaultshow", "defaultshow" },
+ { "lang", "language" },
+ { NULL, NULL }
+ };
+
+ if (info.userid < 0)
+ return -1;
+ sprintf (fname, "%s/user.%d.r", gw_res_get (info.kernel_res,
+ "gw.path", "."),
+ info.userid);
+
+ if (list->kind == CCL_TOK_EOL)
+ {
+ fprintf (reply_fd, "format %s\n", gw_res_get
+ (info.kernel_res, "gw.display.format", ""));
+ fprintf (reply_fd, "maxshow %s\n", gw_res_get
+ (info.kernel_res, "gw.max.show", ""));
+ fprintf (reply_fd, "default-show %s\n", gw_res_get
+ (info.kernel_res, "gw.default.show", ""));
+ fprintf (reply_fd, "language %s\n", gw_res_get
+ (info.kernel_res, "gw.language", ""));
+ }
+ else
+ {
+ int setting_no = command_search (def_tab, list, "ccl.token.");
+
+ if (!setting_no)
+ {
+ fprintf (reply_fd, "Unknown setting in def\n");
+ return -1;
+ }
+ if (setting_no == 1)
+ {
+ unlink (fname);
+ read_kernel_res ();
+ return 0;
+ }
+ list = list->next;
+ if (list->kind == CCL_TOK_EOL)
+ {
+ fprintf (reply_fd, "Missing value\n");
+ return -1;
+ }
+ strncpy (value, list->name, 127);
+ value[(size_t) list->len] = '\0';
+ switch (setting_no)
+ {
+ case 2:
+ name = "gw.display.format";
+ break;
+ case 3:
+ name = "gw.max.show";
+ break;
+ case 4:
+ name = "gw.default.show";
+ break;
+ case 5:
+ name = "gw.language";
+ break;
+ default:
+ return 0;
+ }
+ gw_log (GW_LOG_DEBUG, KERNEL_LOG, "update file %s with %s=%s",
+ fname, name, value);
+ gw_res_put (info.kernel_res, "gw.username", info.from_str, fname);
+ gw_res_put (info.kernel_res, name, value, fname);
+ gw_res_commit (info.kernel_res, fname);
+ if (setting_no == 5)
+ read_kernel_res ();
+ }
+ return 0;
+}
+
+
/*
* exec_command: parse and execute ccl command in str.
* str: ccl command string
*/
static int exec_command (const char *str, int *stop_flag)
{
+ static struct command_word command_tab [] =
+ {
+ { "find", "find"},
+ { "show", "show"},
+ { "base", "base" },
+ { "help", "help" },
+ { "info", "info" },
+ { "continue", "continue" },
+ { "status", "status" },
+ { "stop", "stop" },
+ { "target", "target" },
+ { "def", "def" },
+ { "account", "account" },
+ { NULL, NULL }
+ };
+
struct ccl_token *cmd = ccl_tokenize (str);
int no;
if (cmd->kind != CCL_TOK_EOL &&
(no = command_search (command_tab, cmd, "ccl.command.")))
{
- if (!info.zass && no != 9 && no != 4 && no != 11 && no != 7)
- reopen_target ();
- fprintf (reply_fd, "\n> %s\n", str);
- if (!info.zass && (no == 1 || no == 2 || no == 3))
+ if (no == 1 || no == 2 || no == 3) /* find/show/base? */
{
- fprintf (reply_fd, "%s\n",
- gw_res_get (info.kernel_res, "gw.err.no.target",
- "No connection established - "
- "command ignored"));
- return 0;
+ if (!info.zass) /* open if not already opened */
+ reopen_target ();
+ fprintf (reply_fd, "\n> %s\n", str);
+ if (!info.zass) /* fail? */
+ {
+ fprintf (reply_fd, "%s\n",
+ gw_res_get (info.kernel_res, "gw.err.no.target",
+ "No connection established - "
+ "command ignored"));
+ return 0;
+ }
}
+ else
+ fprintf (reply_fd, "\n> %s\n", str);
#if 0
ccl_token_and = gw_res_get (info.kernel_res, "ccl.token.and", "and");
ccl_token_or = gw_res_get (info.kernel_res, "ccl.token.or", "or");
case 3:
return exec_base (cmd->next);
case 4:
+ fprintf (reply_fd, "\n> %s\n", str);
return exec_help (cmd->next);
case 6: /* continue */
*stop_flag = 2;
return 0;
case 9:
return exec_target (cmd->next);
+ case 10:
+ return exec_def (cmd->next);
case 11:
return exec_account (cmd->next);
default: