From ea50d49cb3d4fa35e2c71effa6dec29de70a7b7a Mon Sep 17 00:00:00 2001 From: Stefan Ritt Date: Tue, 7 Jan 2003 15:17:28 +0000 Subject: [PATCH] Improved performance, introduced resource and logbook dirs SVN revision: 313 --- elogd.c | 321 ++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 216 insertions(+), 105 deletions(-) diff --git a/elogd.c b/elogd.c index 1ebd55b7..5034b8fe 100755 --- a/elogd.c +++ b/elogd.c @@ -6,6 +6,9 @@ Contents: Web server program for Electronic Logbook ELOG $Log$ + Revision 2.119 2003/01/07 15:17:28 midas + Improved performance, introduced resource and logbook dirs + Revision 2.118 2003/01/07 08:29:44 midas Fixed bug with hierarchical logbooks @@ -546,8 +549,9 @@ int return_length; char host_name[256]; char referer[256]; char browser[256]; -char cfg_file[256]; -char cfg_dir[256]; +char config_file[256]; +char resource_dir[256]; +char logbook_dir[256]; char tcp_hostname[256]; int tcp_port = 80; @@ -666,7 +670,7 @@ typedef struct { char file_name[32]; time_t file_time; int offset; - BOOL thread_head; + int in_reply_to; } EL_INDEX; typedef struct { @@ -691,6 +695,7 @@ typedef struct { LOGBOOK *lbs; int index; char string[256]; + int in_reply_to; } MSG_LIST; LOGBOOK *lb_list = NULL; @@ -1112,17 +1117,18 @@ char list[1024][NAME_LENGTH]; if (verbose) puts(str); if (email_to) - { snprintf(str, sizeof(str) - 1, "To: %s\r\n", to); - send(s, str, strlen(str), 0); - if (verbose) puts(str); - } + else + snprintf(str, sizeof(str) - 1, "To: ELOG user\r\n"); + + send(s, str, strlen(str), 0); + if (verbose) puts(str); snprintf(str, sizeof(str) - 1, "From: %s\r\nSubject: %s\r\n", from, subject); send(s, str, strlen(str), 0); if (verbose) puts(str); - snprintf(str, sizeof(str) - 1, "From: %s\r\nSubject: %s\r\n", from, subject); + snprintf(str, sizeof(str) - 1, "Content-Type: text/plain\r\n"); send(s, str, strlen(str), 0); if (verbose) puts(str); @@ -1216,7 +1222,7 @@ int fh; /* read configuration file on init */ if (!cfgbuffer) { - fh = open(cfg_file, O_RDONLY | O_BINARY); + fh = open(config_file, O_RDONLY | O_BINARY); if (fh < 0) return 0; length = lseek(fh, 0, SEEK_END); @@ -1451,7 +1457,7 @@ static char old_language[256]; } else { - strlcpy(file_name, cfg_dir, sizeof(file_name)); + strlcpy(file_name, resource_dir, sizeof(file_name)); strlcat(file_name, "eloglang.", sizeof(file_name)); strlcat(file_name, language, sizeof(file_name)); @@ -1648,7 +1654,7 @@ int i; memset(file_name, 0, sizeof(file_name)); - strlcpy(file_name, cfg_dir, sizeof(file_name)); + strlcpy(file_name, resource_dir, sizeof(file_name)); strlcat(file_name, "themes", sizeof(file_name)); strlcat(file_name, DIR_SEPARATOR_STR, sizeof(file_name)); strlcat(file_name, tn, sizeof(file_name)); @@ -1909,7 +1915,7 @@ struct tm tms; if (equal_ustring(lb_list[i].data_dir, lbs->data_dir) && &lb_list[i] != lbs) { if (verbose) - printf(" Same index as logbook %s\n", lb_list[i].name); + printf("\n Same index as logbook %s\n", lb_list[i].name); lbs->el_index = lb_list[i].el_index; lbs->n_el_index = lb_list[i].n_el_index; @@ -2010,15 +2016,20 @@ struct tm tms; lbs->el_index[*lbs->n_el_index].message_id = atoi(p+8); lbs->el_index[*lbs->n_el_index].offset = (int) p - (int) buffer; - lbs->el_index[*lbs->n_el_index].thread_head = (in_reply_to[0] == 0); + lbs->el_index[*lbs->n_el_index].in_reply_to = atoi(in_reply_to); if (lbs->el_index[*lbs->n_el_index].message_id > 0) { if (verbose) + { + if (*lbs->n_el_index == 0) + printf("\n"); + printf(" ID %3d in %s, offset %5d, %s\n", lbs->el_index[*lbs->n_el_index].message_id, str, lbs->el_index[*lbs->n_el_index].offset, - lbs->el_index[*lbs->n_el_index].thread_head ? "thread head" : "reply"); + lbs->el_index[*lbs->n_el_index].in_reply_to ? "reply" : "thread head"); + } /* valid ID */ (*lbs->n_el_index)++; @@ -2104,14 +2115,28 @@ int i, j, n, status; strcpy(lb_list[n].name_enc, logbook); url_encode(lb_list[n].name_enc, sizeof(lb_list[n].name_enc)); - /* get data dir from configuration file */ - getcfg(logbook, "Data dir", str); - if (str[0] == DIR_SEPARATOR || str[1] == ':') - strlcpy(data_dir, str, sizeof(data_dir)); + /* get data dir from configuration file (old method) */ + if (getcfg(logbook, "Data dir", str)) + { + if (str[0] == DIR_SEPARATOR || str[1] == ':') + strlcpy(data_dir, str, sizeof(data_dir)); + else + { + strlcpy(data_dir, resource_dir, sizeof(data_dir)); + strlcat(data_dir, str, sizeof(data_dir)); + } + } else { - strlcpy(data_dir, cfg_dir, sizeof(data_dir)); - strlcat(data_dir, str, sizeof(data_dir)); + /* use logbook_dir + "Subdir" (new method) */ + strlcpy(data_dir, logbook_dir, sizeof(data_dir)); + if (data_dir[strlen(data_dir)-1] != DIR_SEPARATOR) + strlcat(data_dir, DIR_SEPARATOR_STR, sizeof(data_dir)); + + if (getcfg(logbook, "Subdir", str)) + strlcat(data_dir, str, sizeof(data_dir)); + else + strlcat(data_dir, logbook, sizeof(data_dir)); /* use logbook name as default */ } if (data_dir[strlen(data_dir)-1] != DIR_SEPARATOR) @@ -2140,8 +2165,10 @@ int i, j, n, status; strcpy(lb_list[n].data_dir, data_dir); lb_list[n].el_index = NULL; - printf("Indexing logbook \"%s\"...\n", logbook); + printf("Indexing logbook \"%s\" ... ", logbook); + fflush(stdout); status = el_build_index(&lb_list[n], FALSE); + printf("ok\n"); if (status == EL_EMPTY) printf("Found empty logbook \"%s\"\n", logbook); @@ -2190,7 +2217,7 @@ int i; if (head_only) { for (i=0 ; i<*lbs->n_el_index ; i++) - if (lbs->el_index[i].thread_head) + if (lbs->el_index[i].in_reply_to == 0) return lbs->el_index[i].message_id; return 0; @@ -2205,7 +2232,7 @@ int i; if (head_only) { for (i=*lbs->n_el_index-1 ; i>=0 ; i--) - if (lbs->el_index[i].thread_head) + if (lbs->el_index[i].in_reply_to == 0) return lbs->el_index[i].message_id; return 0; @@ -2230,7 +2257,7 @@ int i; if (head_only) { for (i++ ; i<*lbs->n_el_index ; i++) - if (lbs->el_index[i].thread_head) + if (lbs->el_index[i].in_reply_to == 0) return lbs->el_index[i].message_id; return 0; @@ -2254,7 +2281,7 @@ int i; if (head_only) { for (i-- ; i>=0 ; i--) - if (lbs->el_index[i].thread_head) + if (lbs->el_index[i].in_reply_to == 0) return lbs->el_index[i].message_id; return 0; @@ -2698,7 +2725,7 @@ BOOL bedit; strcpy(lbs->el_index[*lbs->n_el_index-1].file_name, file_name); lbs->el_index[*lbs->n_el_index-1].file_time = ltime; lbs->el_index[*lbs->n_el_index-1].offset = TELL(fh); - lbs->el_index[*lbs->n_el_index-1].thread_head = (in_reply_to[0] == 0); + lbs->el_index[*lbs->n_el_index-1].in_reply_to = atoi(in_reply_to); /* if index not ordered, sort it */ i = *lbs->n_el_index; @@ -4345,7 +4372,7 @@ int i, fh, wrong_pwd, size; strcpy(file_name, str); else { - strlcpy(file_name, cfg_dir, sizeof(file_name)); + strlcpy(file_name, resource_dir, sizeof(file_name)); strlcat(file_name, str, sizeof(file_name)); } @@ -5011,7 +5038,7 @@ time_t now; strcpy(file_name, str); else { - strlcpy(file_name, cfg_dir, sizeof(file_name)); + strlcpy(file_name, resource_dir, sizeof(file_name)); strlcat(file_name, str, sizeof(file_name)); } @@ -5410,10 +5437,10 @@ char *buffer; rsprintf("", gt("Categories bgcolor2")); - fh = open(cfg_file, O_RDONLY | O_BINARY); + fh = open(config_file, O_RDONLY | O_BINARY); if (fh < 0) { - rsprintf("Cannot read configuration file \"%s\"", cfg_file); + rsprintf("Cannot read configuration file \"%s\"", config_file); rsprintf("\n"); rsprintf("\r\n"); return; @@ -5467,10 +5494,10 @@ int save_admin_config() int fh, i; char str[80]; - fh = open(cfg_file, O_RDWR | O_BINARY | O_TRUNC, 644); + fh = open(config_file, O_RDWR | O_BINARY | O_TRUNC, 644); if (fh < 0) { - sprintf(str, loc("Cannot open file %s"), cfg_file); + sprintf(str, loc("Cannot open file %s"), config_file); strcat(str, ": "); strcat(str, strerror(errno)); show_error(str); @@ -5479,7 +5506,7 @@ char str[80]; i = write(fh, _mtext, strlen(_mtext)); if (i < (int)strlen(_mtext)) { - sprintf(str, loc("Cannot write to %s"), cfg_file); + sprintf(str, loc("Cannot write to %s"), config_file); strcat(str, ": "); strcat(str, strerror(errno)); show_error(str); @@ -5534,7 +5561,7 @@ int i, fh, size, self_register; strcpy(file_name, str); else { - strlcpy(file_name, cfg_dir, sizeof(file_name)); + strlcpy(file_name, resource_dir, sizeof(file_name)); strlcat(file_name, str, sizeof(file_name)); } @@ -5772,7 +5799,7 @@ int i, fh, size; strcpy(file_name, str); else { - strlcpy(file_name, cfg_dir, sizeof(file_name)); + strlcpy(file_name, resource_dir, sizeof(file_name)); strlcat(file_name, str, sizeof(file_name)); } @@ -7146,7 +7173,7 @@ char list[MAX_N_LIST][NAME_LENGTH]; void show_page_navigation(LOGBOOK *lbs, int n_msg, int page_n, int n_page, BOOL top, BOOL mode_commands, BOOL threaded) { -int i; +int i, num_pages, skip; char ref[256]; if (!page_n || n_msg <= n_page) @@ -7175,26 +7202,47 @@ char ref[256]; if (page_n && n_msg > n_page) { - for (i=0 ; i<(n_msg-1)/n_page+1 ; i++) + /* number of pages */ + num_pages = (n_msg-1)/n_page+1; + skip = FALSE; + + for (i=1 ; i<=num_pages ; i++) { - sprintf(ref, "page%d", i+1); + sprintf(ref, "page%d", i); build_ref(ref, sizeof(ref), "", ""); - if (i == (n_msg-1)/n_page) + if (i <= 3 || (i >= page_n - 1 && i <= page_n + 1) || i >= num_pages-2) { - if (page_n == i+1) - rsprintf("%d  ", i+1); - else - rsprintf("%d  \n", ref, i+1); + if (i > 1 && !skip) + rsprintf(", \n"); + + skip = FALSE; } else { - if (page_n == i+1) - rsprintf("%d, ", i+1); - else - rsprintf("%d, \n", ref, i+1); + if (!skip) + rsprintf(" ... "); + + skip = TRUE; } + + if (skip) + continue; + + if (page_n == i) + rsprintf("%d", i); + else + rsprintf("%d", ref, i); + + /* + if (i == num_pages ) + rsprintf("  \n"); + else + rsprintf(", "); + */ } + + rsprintf("  \n"); } if (page_n != -1 && n_page < n_msg && page_n * n_page < n_msg) @@ -7328,7 +7376,8 @@ void show_elog_submit_find(LOGBOOK *lbs, INT past_n, INT last_n, INT page_n) { int i, j, n, index, size, status, d1, m1, y1, d2, m2, y2, n_line; int current_year, current_month, current_day, printable, n_logbook, n_display, - reverse, n_attr_disp, n_msg, search_all, message_id, n_page, i_start, i_stop; + reverse, n_attr_disp, n_msg, search_all, message_id, n_page, i_start, i_stop, + in_reply_to_id; char date[80], attrib[MAX_N_ATTR][NAME_LENGTH], disp_attr[MAX_N_ATTR+4][NAME_LENGTH], list[10000], text[TEXT_SIZE], text1[TEXT_SIZE], text2[TEXT_SIZE], in_reply_to[80], reply_to[256], attachment[MAX_ATTACHMENTS][256], encoding[80]; @@ -7336,7 +7385,7 @@ char str[256], col[80], ref[256], img[80]; char mode[80]; char menu_str[1000], menu_item[MAX_N_LIST][NAME_LENGTH]; char *p , *pt, *pt1, *pt2; -BOOL show_attachments, threaded, mode_commands, expand; +BOOL show_attachments, threaded, mode_commands, expand, filtering; time_t ltime, ltime_start, ltime_end, now; struct tm tms, *ptms; MSG_LIST *msg_list; @@ -7677,10 +7726,27 @@ LOGBOOK *lbs_cur; /*---- filter message list ----*/ + filtering = FALSE; + for (i=0 ; in_attr ; i++) + { + /* check if attribute filter */ if (*getparam(attr_list[i])) break; + /* check if sort by attribute */ + if (equal_ustring(getparam("sort"), attr_list[i]) || + equal_ustring(getparam("rsort"), attr_list[i])) + break; + } + + /* turn on filtering if found */ + if (in_attr) + filtering = TRUE; + + if (*getparam("subtext")) + filtering = TRUE; + /* do filtering */ for (index=0 ; indexel_index[msg_list[index].index].message_id; + in_reply_to_id = msg_list[index].lbs->el_index[msg_list[index].index].in_reply_to; - status = el_retrieve(msg_list[index].lbs, message_id, - date, attr_list, attrib, lbs->n_attr, - text, &size, in_reply_to, reply_to, - attachment, - encoding); - if (status != EL_SUCCESS) - break; + if (filtering) + { + status = el_retrieve(msg_list[index].lbs, message_id, + date, attr_list, attrib, lbs->n_attr, + text, &size, in_reply_to, reply_to, + attachment, + encoding); + if (status != EL_SUCCESS) + break; + } for (i=0 ; in_attr ; i++) { @@ -7748,27 +7818,21 @@ LOGBOOK *lbs_cur; } /* in threaded mode, find message head */ - if (threaded && in_reply_to[0]) + if (threaded && in_reply_to_id) { do { - message_id = atoi(in_reply_to); - size = sizeof(text); - status = el_retrieve(msg_list[index].lbs, message_id, - date, attr_list, attrib, lbs->n_attr, - text, &size, in_reply_to, reply_to, - attachment, - encoding); - if (status != EL_SUCCESS) - break; + message_id = in_reply_to_id; - } while (in_reply_to[0]); + /* search index of message */ + for (i=0 ; i < *msg_list[index].lbs->n_el_index ; i++) + if (msg_list[index].lbs->el_index[i].message_id == message_id) + break; + + in_reply_to_id = msg_list[index].lbs->el_index[i].in_reply_to; + + } while (in_reply_to_id); - /* search index of message head */ - for (i=0 ; i < *msg_list[index].lbs->n_el_index ; i++) - if (msg_list[index].lbs->el_index[i].message_id == message_id) - break; - /* check if message head already in list */ for (j=0 ; j TCP/IP hostname\n"); printf(" -D become a daemon\n"); printf(" -c specify configuration file\n"); + printf(" -s specify resource directory (themes, icons, ...)\n"); + printf(" -d specify logbook root directory\n"); printf(" -v debugging output\n"); printf(" -r create/overwrite read password in config file\n"); printf(" -w create/overwrite write password in config file\n"); @@ -12261,26 +12362,36 @@ usage: return 0; } - /* extract directory from configuration file */ - if (cfg_file[0] && strchr(cfg_file, DIR_SEPARATOR)) + /* extract resource directory from configuration file if not given */ + if (config_file[0] && strchr(config_file, DIR_SEPARATOR) && !resource_dir[0]) { - strcpy(cfg_dir, cfg_file); - for (i=strlen(cfg_dir)-1 ; i>0 ; i--) + strcpy(resource_dir, config_file); + for (i=strlen(resource_dir)-1 ; i>0 ; i--) { - if (cfg_dir[i] == DIR_SEPARATOR) + if (resource_dir[i] == DIR_SEPARATOR) break; - cfg_dir[i] = 0; + resource_dir[i] = 0; } } - /* check for configuration file */ - fh = open(cfg_file, O_RDONLY | O_BINARY); - if (fh < 0) + /* do the same for the logbook dir */ + if (config_file[0] && strchr(config_file, DIR_SEPARATOR) && !logbook_dir[0]) { - printf("Configuration file \"%s\" not found.\n", cfg_file); - return 1; + strcpy(logbook_dir, config_file); + for (i=strlen(logbook_dir)-1 ; i>0 ; i--) + { + if (logbook_dir[i] == DIR_SEPARATOR) + break; + logbook_dir[i] = 0; + } + } + + if (verbose) + { + printf("Config file : %s\n", config_file); + printf("Resource dir : %s\n", resource_dir[0] ? resource_dir : "current dir"); + printf("Logbook dir : %s\n", logbook_dir[0] ? logbook_dir : "current dir"); } - close(fh); /* build logbook indices */ if (el_index_logbooks(FALSE) != EL_SUCCESS)