From: Gonzalo A. <ga...@us...> - 2006-09-12 15:23:36
|
Update of /cvsroot/mod-c/ehtml/src In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv19761/src Modified Files: DiskSessionDriver.cpp EHTMLApplication.cpp Session.cpp Request.cpp Log Message: * Removed spurius debugging messages. * Added a propper debugging framework. Index: DiskSessionDriver.cpp =================================================================== RCS file: /cvsroot/mod-c/ehtml/src/DiskSessionDriver.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** DiskSessionDriver.cpp 12 Sep 2006 00:25:19 -0000 1.2 --- DiskSessionDriver.cpp 12 Sep 2006 15:23:33 -0000 1.3 *************** *** 1,3 **** --- 1,4 ---- + #include <EHTMLApplication.h> #include <Session.h> #include <Common.h> *************** *** 116,122 **** string name = filename(id); string lname = locked_filename(id); - printf("name %s / %s\n", name.c_str(), lname.c_str()); if (rename(name.c_str(), lname.c_str())) { ! printf("Error: stale session (id=%s, rename error=%s)\n", id.hex().c_str(), strerror(errno)); return NULL; --- 117,122 ---- string name = filename(id); string lname = locked_filename(id); if (rename(name.c_str(), lname.c_str())) { ! Application()->Error("stale session (id=%s, rename error=%s)\n", id.hex().c_str(), strerror(errno)); return NULL; *************** *** 127,142 **** in >> *dev; } catch (const char*) { ! printf("Error: corrupt session state (id=%s)\n", id.hex().c_str()); delete dev; return NULL; } if (!in.eof()) { ! printf("Error: corrupt session state (%s)\n", id.hex().c_str()); delete dev; return NULL; } if (dev->Expired()) { ! printf("Error: expired session (id=%s, expires=%lu, now=%lu)\n", ! id.hex().c_str(), dev->Expires(), time(NULL)); unlink(lname.c_str()); delete dev; --- 127,144 ---- in >> *dev; } catch (const char*) { ! Application()->Error("corrupt session state (id=%s)\n", ! id.hex().c_str()); delete dev; return NULL; } if (!in.eof()) { ! Application()->Error("corrupt session state (id=%s)\n", ! id.hex().c_str()); delete dev; return NULL; } if (dev->Expired()) { ! Application()->Error("expired session (id=%s, expires=%lu, " ! "now=%lu)\n", id.hex().c_str(), dev->Expires(), time(NULL)); unlink(lname.c_str()); delete dev; *************** *** 171,175 **** string lname(locked_filename(s->ID())); int status = rename(lname.c_str(), name.c_str()); - printf("rename(%s,%s): %d\n", lname.c_str(), name.c_str(), status); return status ? false : true; } --- 173,176 ---- Index: Request.cpp =================================================================== RCS file: /cvsroot/mod-c/ehtml/src/Request.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Request.cpp 12 Sep 2006 00:29:01 -0000 1.7 --- Request.cpp 12 Sep 2006 15:23:33 -0000 1.8 *************** *** 117,120 **** --- 117,138 ---- } + void Request::Error(const char* fmt, ...) const { + if (Application == NULL) + return; + va_list l; + va_start(l, fmt); + Application->Error(fmt, l); + va_end(l); + } + + void Request::Debug(const char* fmt, ...) const { + if (Application == NULL) + return; + va_list l; + va_start(l, fmt); + Application->Debug(fmt, l); + va_end(l); + } + const string * Request::operator []( const string & Key ) const { *************** *** 130,140 **** const string* Request::GetCookie(const string& name) const { ! printf("Looking for %s\n", name.c_str()); string s = name + "="; for (HeaderEntryList::const_iterator i = HeaderCookies.begin(); i != HeaderCookies.end(); ++i) { ! printf("cmp %s =? %s\n", name.c_str(), (*i)->Value); if (!strncmp((*i)->Value, s.c_str(), s.length())) { ! printf("got it! (%s)\n", (*i)->Value + name.length()+1); cookies_returned.push_front(string((*i)->Value + name.length()+1)); return &*cookies_returned.begin(); --- 148,158 ---- const string* Request::GetCookie(const string& name) const { ! Debug("Looking for %s\n", name.c_str()); string s = name + "="; for (HeaderEntryList::const_iterator i = HeaderCookies.begin(); i != HeaderCookies.end(); ++i) { ! Debug("cmp %s =? %s\n", name.c_str(), (*i)->Value); if (!strncmp((*i)->Value, s.c_str(), s.length())) { ! Debug("got it! (%s)\n", (*i)->Value + name.length()+1); cookies_returned.push_front(string((*i)->Value + name.length()+1)); return &*cookies_returned.begin(); *************** *** 147,151 **** { const apr_array_header_t* arr = apr_table_elts( RequestContext->r->headers_in ); ! printf("%s:%d\n", __PRETTY_FUNCTION__, __LINE__); if ( arr->nelts > 0 ) { --- 165,169 ---- { const apr_array_header_t* arr = apr_table_elts( RequestContext->r->headers_in ); ! Debug("%s:%d\n", __PRETTY_FUNCTION__, __LINE__); if ( arr->nelts > 0 ) { *************** *** 161,165 **** if ( _key ) { ! printf("Parsing %s\n", _key); switch ( _key[0] ) { --- 179,183 ---- if ( _key ) { ! Debug("Parsing %s\n", _key); switch ( _key[0] ) { *************** *** 180,184 **** if ( strncmp( "kie", _tmp + 1, 3 ) == 0 ) // We have a cookie ! printf("Got cookie %s => %s\n", tmp->key, tmp->val); HeaderCookies.push_back( new HeaderEntry(tmp->key, tmp->val)); } --- 198,202 ---- if ( strncmp( "kie", _tmp + 1, 3 ) == 0 ) // We have a cookie ! Debug("Got cookie %s => %s\n", tmp->key, tmp->val); HeaderCookies.push_back( new HeaderEntry(tmp->key, tmp->val)); } Index: Session.cpp =================================================================== RCS file: /cvsroot/mod-c/ehtml/src/Session.cpp,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** Session.cpp 12 Sep 2006 00:26:09 -0000 1.13 --- Session.cpp 12 Sep 2006 15:23:33 -0000 1.14 *************** *** 173,177 **** int registerSessionDriver(const char* driver_name, const char* filename) { - fprintf(stderr, "registerSessionDriver(%s,%s)\n",driver_name, filename); void* dlh = dlopen(filename, RTLD_LAZY); if (dlh == NULL) --- 173,176 ---- *************** *** 193,197 **** int useSessionDriver(const char* name, const char* arg) { - fprintf(stderr,"useSessionDriver(%s,%s)\n",name,arg); SessionDriver* selected = SessionDriver::getByName(name); if (selected == NULL) { --- 192,195 ---- *************** *** 215,219 **** int registerSessionIDDriver(const char* driver_name, const char* filename) { - fprintf(stderr, "registerSessionIDDriver(%s,%s)\n",driver_name, filename); void* dlh = dlopen(filename, RTLD_LAZY); if (dlh == NULL) --- 213,216 ---- *************** *** 235,239 **** int useSessionIDDriver(const char* name, const char* arg) { - fprintf(stderr,"useSessionIDDriver(%s,%s)\n",name,arg); SessionIDDriver* selected = SessionIDDriver::getByName(name); if (selected == NULL) { --- 232,235 ---- *************** *** 270,274 **** return NULL; SessionID sid(hexdecode(*id)); - printf("got sessionid = %s\n", sid.hex().c_str()); return Get(sid); } --- 266,269 ---- *************** *** 302,306 **** istream& operator >> (istream& i, Session& s) { i >> *static_cast<Dictionary*>(&s); - printf("Expires=%s\n",s["$$__EXPIRES$$"].c_str()); s.Expires(xatoul(s["$$__EXPIRES$$"].c_str())); s.erase("$$__EXPIRES$$"); --- 297,300 ---- Index: EHTMLApplication.cpp =================================================================== RCS file: /cvsroot/mod-c/ehtml/src/EHTMLApplication.cpp,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** EHTMLApplication.cpp 8 Sep 2006 14:37:44 -0000 1.9 --- EHTMLApplication.cpp 12 Sep 2006 15:23:33 -0000 1.10 *************** *** 29,32 **** --- 29,34 ---- #include <iostream> + #include <http_log.h> + using namespace std; *************** *** 157,158 **** --- 159,204 ---- ShutSessionsDown(); } + + void EHTMLApplication::Error(const char* fmt, ...) const { + va_list l; + va_start (l, fmt); + Error(fmt, l); + va_end(l); + } + + void EHTMLApplication::Error(const char* fmt, va_list l) const { + Log(APLOG_ERR, fmt, l); + } + + void EHTMLApplication::Debug(const char* fmt, ...) const { + va_list l; + va_start (l, fmt); + Log(APLOG_DEBUG, fmt, l); + va_end(l); + } + + static const char* prefix(int level) { + switch (level) { + case APLOG_EMERG: return "EMERG"; + case APLOG_ALERT: return "ALERT"; + case APLOG_CRIT: return "CRIT"; + case APLOG_ERR: return "ERROR"; + case APLOG_WARNING: return "WARNING"; + case APLOG_NOTICE: return "NOTICE"; + case APLOG_INFO: return "INFO"; + case APLOG_DEBUG: return "DEBUG"; + + } + return "UNKNOWN"; + } + + void EHTMLApplication::Log(int level, const char* fmt, va_list l) const { + char* msg = (char*)malloc(512); + vsnprintf(msg, 511, fmt, l); + msg[511] = '\0'; + ap_log_error(APLOG_MARK, level, 0, + RequestContext->r->server, + "%s: %s", prefix(level), msg); + free(msg); + } + |