From e731815ac52e7da6fe7d25d7c597017b3dcf0d32 Mon Sep 17 00:00:00 2001 From: Stefan Ritt Date: Sat, 13 Mar 2004 15:00:05 +0000 Subject: [PATCH] Implemented OR's of several conditions SVN revision: 826 --- doc/config.html | 23 +++++++ src/elogd.c | 167 +++++++++++++++++++++++++++++++----------------- 2 files changed, 132 insertions(+), 58 deletions(-) diff --git a/doc/config.html b/doc/config.html index d61bbfe4..51c6ff9a 100755 --- a/doc/config.html +++ b/doc/config.html @@ -1113,6 +1113,29 @@ message comment can be displayed to tell the user what to enter exactly in the message body for that attribute value.

+

Multiple conditions

+ +It is possible to define conditions in more than one options list. The only requiremnt +is that conditions are uniquie, meaning that a condition in one option list cannot +be used in another list. This can easily be avoided by using numbers for one condition +and letters for the other condition, like in the following example: +

+ +

+

+ +It is possible to specify an OR of several conditions like in the case {b,c}. This is +also possible over several conditions, like {1,a} would mean +"The PC has Linux or is in the Main Building". +


  Access control  

diff --git a/src/elogd.c b/src/elogd.c index 0a67e847..1679a29b 100755 --- a/src/elogd.c +++ b/src/elogd.c @@ -6,6 +6,9 @@ Contents: Web server program for Electronic Logbook ELOG $Log$ + Revision 1.292 2004/03/13 15:00:05 midas + Implemented OR's of several conditions + Revision 1.291 2004/03/11 11:42:09 midas Change POST action to './' for OS-X IE @@ -1982,14 +1985,58 @@ int is_logbook(char *logbook) /*-------------------------------------------------------------------*/ +char _condition[256]; + +void set_condition(char *c) +{ + strlcpy(_condition, c, sizeof(_condition)); +} + +/*-------------------------------------------------------------------*/ + +BOOL match_param(char *str, char *param) +{ + int ncl, npl, i, j; + char *p, pcond[256], clist[10][NAME_LENGTH], plist[10][NAME_LENGTH]; + + if (!_condition[0] || str[0] != '{') + return strieq(str, param); + + p = str; + if (strchr(p, '}')) + p = strchr(p, '}')+1; + while (*p == ' ') + p++; + + strlcpy(pcond, str, sizeof(pcond)); + if (strchr(pcond, '}')) + *strchr(pcond, '}') = 0; + if (strchr(pcond, '{')) + *strchr(pcond, '{') = ' '; + + npl = strbreak(pcond, plist, 10); + ncl = strbreak(_condition, clist, 10); + + for (i=0 ; i] */ { char *str, *p, *pstr; - int length; - int fh; + int length, status, fh; value[0] = 0; + status = 0; /* read configuration file on init */ if (!cfgbuffer) { @@ -2031,7 +2078,8 @@ int getcfg_simple(char *group, char *param, char *value) while (pstr > str && (*pstr == ' ' || *pstr == '=' || *pstr == '\t')) *pstr-- = 0; - if (strieq(str, param)) { + if (match_param(str, param)) { + status = strchr(str, '{') ? 2 : 1; if (*p == '=') { p++; while (*p == ' ' || *p == '\t') @@ -2050,7 +2098,7 @@ int getcfg_simple(char *group, char *param, char *value) strcpy(value, str); free(str); - return 1; + return status; } } @@ -2199,7 +2247,7 @@ int is_group(char *group) /*------------------------------------------------------------------*/ -int getcfg_cond(char *group, char *condition, char *param, char *value) +int getcfg_cond1(char *group, char *condition, char *param, char *value) { char str[256]; @@ -4939,7 +4987,7 @@ and trailing blanks */ /*------------------------------------------------------------------*/ -int scan_attributes(char *logbook, char *condition) +int scan_attributes(char *logbook) /* scan configuration file for attributes and fill attr_list, attr_options and attr_flags arrays */ { @@ -4947,7 +4995,7 @@ and attr_flags arrays */ tmp_list[MAX_N_ATTR][NAME_LENGTH]; int i, j, n, m; - if (getcfg_cond(logbook, condition, "Attributes", list)) { + if (getcfg(logbook, "Attributes", list)) { /* reset attribute flags */ memset(attr_flags, 0, sizeof(attr_flags)); @@ -4959,30 +5007,30 @@ and attr_flags arrays */ memset(attr_options, 0, sizeof(attr_options)); for (i = 0; i < n; i++) { sprintf(str, "Options %s", attr_list[i]); - if (getcfg_cond(logbook, condition, str, list)) + if (getcfg(logbook, str, list)) strbreak(list, attr_options[i], MAX_N_LIST); sprintf(str, "MOptions %s", attr_list[i]); - if (getcfg_cond(logbook, condition, str, list)) { + if (getcfg(logbook, str, list)) { strbreak(list, attr_options[i], MAX_N_LIST); attr_flags[i] |= AF_MULTI; } sprintf(str, "ROptions %s", attr_list[i]); - if (getcfg_cond(logbook, condition, str, list)) { + if (getcfg(logbook, str, list)) { strbreak(list, attr_options[i], MAX_N_LIST); attr_flags[i] |= AF_RADIO; } sprintf(str, "IOptions %s", attr_list[i]); - if (getcfg_cond(logbook, condition, str, list)) { + if (getcfg(logbook, str, list)) { strbreak(list, attr_options[i], MAX_N_LIST); attr_flags[i] |= AF_ICON; } } /* check if attribute required */ - getcfg_cond(logbook, condition, "Required Attributes", list); + getcfg(logbook, "Required Attributes", list); m = strbreak(list, tmp_list, MAX_N_ATTR); for (i = 0; i < m; i++) { for (j = 0; j < n; j++) @@ -4991,7 +5039,7 @@ and attr_flags arrays */ } /* check if locked attribute */ - getcfg_cond(logbook, condition, "Locked Attributes", list); + getcfg(logbook, "Locked Attributes", list); m = strbreak(list, tmp_list, MAX_N_ATTR); for (i = 0; i < m; i++) { for (j = 0; j < n; j++) @@ -5000,7 +5048,7 @@ and attr_flags arrays */ } /* check if fixed attribute for Edit */ - getcfg_cond(logbook, condition, "Fixed Attributes Edit", list); + getcfg(logbook, "Fixed Attributes Edit", list); m = strbreak(list, tmp_list, MAX_N_ATTR); for (i = 0; i < m; i++) { for (j = 0; j < n; j++) @@ -5009,7 +5057,7 @@ and attr_flags arrays */ } /* check if fixed attribute for Reply */ - getcfg_cond(logbook, condition, "Fixed Attributes Reply", list); + getcfg(logbook, "Fixed Attributes Reply", list); m = strbreak(list, tmp_list, MAX_N_ATTR); for (i = 0; i < m; i++) { for (j = 0; j < n; j++) @@ -5018,7 +5066,7 @@ and attr_flags arrays */ } /* check for extendable options */ - getcfg_cond(logbook, condition, "Extendable Options", list); + getcfg(logbook, "Extendable Options", list); m = strbreak(list, tmp_list, MAX_N_ATTR); for (i = 0; i < m; i++) { for (j = 0; j < n; j++) @@ -5029,7 +5077,7 @@ and attr_flags arrays */ for (i = 0; i < n; i++) { sprintf(str, "Type %s", attr_list[i]); - if (getcfg_cond(logbook, condition, str, type)) { + if (getcfg(logbook, str, type)) { if (strieq(type, "date")) attr_flags[i] |= AF_DATE; if (strieq(type, "numeric")) @@ -6352,6 +6400,12 @@ void show_edit_form(LOGBOOK * lbs, int message_id, BOOL breply, BOOL bedit, BOOL } } + set_condition(condition); + + /* rescan attributes if condition set */ + if (condition[0]) + scan_attributes(lbs->name); + /* check for maximum number of replies */ if (breply) { i = 0; @@ -6370,7 +6424,7 @@ void show_edit_form(LOGBOOK * lbs, int message_id, BOOL breply, BOOL bedit, BOOL } /* check for author */ - if (bedit && getcfg_cond(lbs->name, condition, "Restrict edit", str) + if (bedit && getcfg(lbs->name, "Restrict edit", str) && atoi(str) == 1) { if (!is_author(lbs, attrib, owner)) { sprintf(str, loc("Only user %s can edit this entry"), owner); @@ -6381,7 +6435,7 @@ void show_edit_form(LOGBOOK * lbs, int message_id, BOOL breply, BOOL bedit, BOOL } /* check for editing interval */ - if (bedit && getcfg_cond(lbs->name, condition, "Restrict edit time", str)) { + if (bedit && getcfg(lbs->name, "Restrict edit time", str)) { for (i = 0; i < *lbs->n_el_index; i++) if (lbs->el_index[i].message_id == message_id) break; @@ -6398,7 +6452,7 @@ void show_edit_form(LOGBOOK * lbs, int message_id, BOOL breply, BOOL bedit, BOOL /* remove attributes for replies */ if (breply) { - getcfg_cond(lbs->name, condition, "Remove on reply", str); + getcfg(lbs->name, "Remove on reply", str); n = strbreak(str, list, MAX_N_ATTR); for (i = 0; i < n; i++) for (j = 0; j < lbs->n_attr; j++) { @@ -6411,7 +6465,7 @@ void show_edit_form(LOGBOOK * lbs, int message_id, BOOL breply, BOOL bedit, BOOL if (breply) { for (index = 0; index < lbs->n_attr; index++) { sprintf(str, "Subst on reply %s", attr_list[index]); - if (getcfg_cond(lbs->name, condition, str, preset)) { + if (getcfg(lbs->name, str, preset)) { /* check if already second reply */ if (orig_tag[0] == 0) { i = build_subst_list(lbs, slist, svalue, attrib, TRUE); @@ -6429,7 +6483,7 @@ void show_edit_form(LOGBOOK * lbs, int message_id, BOOL breply, BOOL bedit, BOOL if (message_id && bedit && !breedit && !bupload) { for (index = 0; index < lbs->n_attr; index++) { sprintf(str, "Subst on edit %s", attr_list[index]); - if (getcfg_cond(lbs->name, condition, str, preset)) { + if (getcfg(lbs->name, str, preset)) { i = build_subst_list(lbs, slist, svalue, attrib, TRUE); sprintf(str, "%d", message_id); add_subst_list(slist, svalue, "message id", str, &i); @@ -6593,14 +6647,14 @@ void show_edit_form(LOGBOOK * lbs, int message_id, BOOL breply, BOOL bedit, BOOL time(&now); if (bedit) { - if (!getcfg_cond(lbs->name, condition, "Time format", format)) + if (!getcfg(lbs->name, "Time format", format)) strcpy(format, DEFAULT_TIME_FORMAT); ltime = date_to_ltime(date); pts = localtime(<ime); strftime(str, sizeof(str), format, pts); } else { - if (getcfg_cond(lbs->name, condition, "Time format", format)) + if (getcfg(lbs->name, "Time format", format)) strftime(str, sizeof(str), format, localtime(&now)); else strcpy(str, ctime(&now)); @@ -6613,10 +6667,6 @@ void show_edit_form(LOGBOOK * lbs, int message_id, BOOL breply, BOOL bedit, BOOL rsprintf("%s\n", str); rsprintf("\n", date); - /* rescan attributes if condition set */ - if (condition[0]) - scan_attributes(lbs->name, condition); - /* display attributes */ for (index = 0; index < lbs->n_attr; index++) { strcpy(class_name, "attribname"); @@ -6628,7 +6678,7 @@ void show_edit_form(LOGBOOK * lbs, int message_id, BOOL breply, BOOL bedit, BOOL btou(ua); sprintf(str, "Format %s", attr_list[index]); - if (getcfg_cond(lbs->name, condition, str, format)) { + if (getcfg(lbs->name, str, format)) { n = strbreak(format, fl, 8); if (n > 0) format_flags = atoi(fl[0]); @@ -6646,7 +6696,7 @@ void show_edit_form(LOGBOOK * lbs, int message_id, BOOL breply, BOOL bedit, BOOL /* check for preset string */ sprintf(str, "Preset %s", attr_list[index]); - if ((i = getcfg_cond(lbs->name, condition, str, preset)) > 0) { + if ((i = getcfg(lbs->name, str, preset)) > 0) { if (!bedit || (breedit && i == 2)) { /* subst on reedit only if preset is under condition */ @@ -6674,7 +6724,7 @@ void show_edit_form(LOGBOOK * lbs, int message_id, BOOL breply, BOOL bedit, BOOL /* show optional comment */ sprintf(str, "Comment %s", attr_list[index]); - if (getcfg_cond(lbs->name, condition, str, comment)) + if (getcfg(lbs->name, str, comment)) rsprintf("
%s\n", comment); rsprintf("\n"); @@ -6817,7 +6867,7 @@ void show_edit_form(LOGBOOK * lbs, int message_id, BOOL breply, BOOL bedit, BOOL ua, attr_options[index][i]); sprintf(str, "Icon comment %s", attr_options[index][i]); - getcfg_cond(lbs->name, condition, str, comment); + getcfg(lbs->name, str, comment); if (comment[0]) rsprintf("\"%s\"\n", @@ -6900,7 +6950,7 @@ void show_edit_form(LOGBOOK * lbs, int message_id, BOOL breply, BOOL bedit, BOOL /* set textarea width */ width = 76; - if (getcfg_cond(lbs->name, condition, "Message width", str)) + if (getcfg(lbs->name, "Message width", str)) width = atoi(str); /* increased width according to longest line */ @@ -6930,7 +6980,7 @@ void show_edit_form(LOGBOOK * lbs, int message_id, BOOL breply, BOOL bedit, BOOL /* set textarea height */ height = 20; - if (getcfg_cond(lbs->name, condition, "Message height", str)) + if (getcfg(lbs->name, "Message height", str)) height = atoi(str); rsprintf("\n"); @@ -6946,26 +6996,26 @@ void show_edit_form(LOGBOOK * lbs, int message_id, BOOL breply, BOOL bedit, BOOL if (bedit && message_id) rsprintf("\n", message_id); - if (getcfg_cond(lbs->name, condition, "Message comment", comment) + if (getcfg(lbs->name, "Message comment", comment) && !message_id) { rsputs(comment); rsputs("
\n"); } - if (!getcfg_cond(lbs->name, condition, "Show text", str) + if (!getcfg(lbs->name, "Show text", str) || atoi(str) == 1) { rsprintf("