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("