Changeset 595
- Timestamp:
- 1999-09-17T09:38:17+12:00 (25 years ago)
- Location:
- trunk/gsdl
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/lib/gsdlconf.h
r534 r595 77 77 78 78 79 // file locking 80 81 #if defined(__WIN32__) 82 #define MY_UNLOCK 0 83 #define MY_READLOCK 1 84 #define MY_WRITELOCK 2 85 int my_locking(int fd, int lmode, long lockoffset, long nbytes); 86 87 #define UNLOCK_FILE(fd) my_locking(fd, MY_UNLOCK, 0, 10) 88 #define READLOCK_FILE(fd) lock_val = my_locking(fd, MY_READLOCK, 0, 10) 89 #define WRITELOCK_FILE(fd) lock_val = my_locking(fd, MY_WRITELOCK, 0, 10) 90 91 #else 92 93 #if GSDL_USE_FLOCK 94 #include <sys/lock.h> 95 96 #ifndef LOCK_SH 97 #define LOCK_SH 1 79 98 #endif 99 100 #ifndef LOCK_EX 101 #define LOCK_EX 2 102 #endif 103 104 #ifndef LOCK_NB 105 #define LOCK_NB 4 106 #endif 107 108 #ifndef LOCK_UN 109 #define LOCK_UN 8 110 #endif 111 112 #define UNLOCK_FILE(fd) flock (fd, LOCK_UN) 113 #define READLOCK_FILE(fd) lock_val = flock (fd, LOCK_SH + LOCK_NB) 114 #define WRITELOCK_FILE(fd) lock_val = flock (fd, LOCK_EX + LOCK_NB) 115 116 #else 117 // use fcntl 118 #include <fcntl.h> 119 #define UNLOCK_FILE(fd) \ 120 { \ 121 struct flock flock; \ 122 flock.l_type = F_UNLCK; \ 123 flock.l_whence = SEEK_SET; \ 124 flock.l_start = flock.l_len = 0L; \ 125 fcntl (fd, F_SETLK, &flock); \ 126 } 127 #define READLOCK_FILE(fd) \ 128 { \ 129 struct flock flock; \ 130 flock.l_type = F_RDLCK; \ 131 flock.l_whence = SEEK_SET; \ 132 flock.l_start = flock.l_len = 0L; \ 133 lock_val = fcntl (fd, F_SETLK, &flock); \ 134 } 135 #define WRITELOCK_FILE(fd) \ 136 { \ 137 struct flock flock; \ 138 flock.l_type = F_WRLCK; \ 139 flock.l_whence = SEEK_SET; \ 140 flock.l_start = flock.l_len = 0L; \ 141 lock_val = fcntl (fd, F_SETLK, &flock); \ 142 } 143 144 #endif 145 #endif 146 147 #endif -
trunk/gsdl/src/recpt/receptionist.cpp
r533 r595 28 28 /* 29 29 $Log$ 30 Revision 1.31 1999/09/16 21:38:17 sjboddie 31 added some file locking stuff for logging. Windows still needs to 32 be done. 33 30 34 Revision 1.30 1999/09/07 04:56:58 sjboddie 31 35 added GPL notice … … 172 176 #include <assert.h> 173 177 #include <time.h> 178 #include <stdio.h> 174 179 #include <fstream.h> 175 180 … … 464 469 converthere++; 465 470 } 466 471 467 472 // set default converter if no good one has been defined 468 473 if (!defaultconvertname.empty()) { 469 474 cgiarginfo *ainfo = argsinfo.getarginfo ("w"); 470 if ((ainfo != NULL) && (converters.get_outconverter(ainfo->argdefault) == NULL)) { 471 ainfo->defaultstatus = cgiarginfo::good; 472 ainfo->argdefault = defaultconvertname; 473 } 474 } 475 475 if (ainfo->argdefault != "w") { 476 if ((ainfo != NULL) && (converters.get_outconverter(ainfo->argdefault) == NULL)) { 477 ainfo->defaultstatus = cgiarginfo::good; 478 ainfo->argdefault = defaultconvertname; 479 } 480 } 481 } 482 476 483 // init the actions 477 484 actionptrmap::iterator actionhere = actions.begin (); … … 617 624 bool receptionist::log_cgi_args (cgiargsclass &args, ostream &logout) { 618 625 619 utf8outconvertclass text_t2utf8;620 621 626 // see if we want to log the cgi arguments 622 627 if (!configinfo.logcgiargs) return true; … … 625 630 host = getenv("REMOTE_HOST"); 626 631 if (host == NULL) host = getenv ("REMOTE_ADDR"); 632 if (host == NULL) host = ""; 627 633 char *browser = getenv("HTTP_USER_AGENT"); 634 if (browser == NULL) browser = ""; 628 635 time_t ttime = time(NULL); 629 636 … … 642 649 text_t logfile = filename_cat (configinfo.gsdlhome, "etc"); 643 650 logfile = filename_cat (logfile, "usage.txt"); 644 char *lfile = logfile.getcstr(); 645 651 652 text_t logstr = host; 653 logstr += " ["; 654 logstr += ttime; 655 logstr += "] (" + argstr + ") \""; 656 logstr += browser; 657 logstr += "\"\n"; 658 659 return append_logstr (logfile, logstr, logout); 660 } 661 662 bool receptionist::append_logstr (const text_t &filename, const text_t &logstr, 663 ostream &logout) { 664 665 utf8outconvertclass text_t2utf8; 666 char *lfile = filename.getcstr(); 646 667 ofstream log (lfile, ios::app); 647 668 … … 650 671 delete lfile; 651 672 return false; 652 } 653 654 log << text_t2utf8 << host << " [" << ttime 655 << "] (" << argstr << ") \"" << browser << "\"\n"; 656 673 } 674 675 int fd = log.filedesc(); 676 // lock_val is set to 0 if file is locked successfully 677 int lock_val = 1; 678 WRITELOCK_FILE (fd); 679 if (lock_val == 0) { 680 log << text_t2utf8 << logstr; 681 UNLOCK_FILE (fd); 682 } else 683 logout << "Error: Couldn't lock file " << lfile << "\n"; 684 657 685 log.close(); 658 686 -
trunk/gsdl/src/recpt/receptionist.h
r533 r595 92 92 virtual void define_general_macros (cgiargsclass &args, recptproto *collectproto, 93 93 outconvertclass &outconvert, ostream &logout); 94 95 bool append_logstr (const text_t &filename, const text_t &logstr, 96 ostream &logout); 94 97 95 98 public:
Note:
See TracChangeset
for help on using the changeset viewer.