#include <NVActiveDB.h>
Inheritance diagram for NVActiveDB:

Public Member Functions | |
| NVActiveDB () | |
| NVActiveDB (char *dbname) | |
| int | lock (int command, int block=Block) |
| int | get_lock (void) |
| void | open (const char *dbname) |
| int | is_open (void) |
| void | close (void) |
| void | setmtime (unsigned long tm, int force=0) |
| void | getmtime (unsigned long *tm) |
| void | clear (void) |
| int | is_empty (void) |
| void | add (GroupInfo &gi) |
| void | set (GroupInfo &gi, int flags=0) |
| int | get (const char *group, GroupInfo *gi) |
| int | hasgroup (const char *group) |
| void | read (std::istream &is, const char *filter, int flags=0) |
| void | write (std::ostream &os, nvtime_t ctime=0, int mode=m_active, const char *filter=NULL) |
| Iter< GroupInfo > | begin () |
| Iter< GroupInfo > | end () |
Protected Member Functions | |
| unsigned long | hash (const char *strg) |
| void | sset (GroupInfo &gi, int flags=0) |
Friends | |
| std::ostream & | operator<< (std::ostream &os, NVActiveDB &adb) |
Definition at line 41 of file NVActiveDB.h.
|
|
Definition at line 58 of file NVActiveDB.h.
00058 :NVHash() { 00059 } NVActiveDB(char *dbname):NVHash(dbname, NVActiveDB_HASHSIZE) { |
|
|
Definition at line 59 of file NVActiveDB.h.
00059 :NVHash(dbname, NVActiveDB_HASHSIZE) { 00060 } |
|
|
Adds the description of the newsgroup. If the newsgroup already exists in the active database, it adds a duplicate.
Implements ActiveDB. Definition at line 89 of file NVActiveDB.cc. References NVHash::add(), GroupInfo::getraw(), hash(), GroupInfo::name(), Logger::p(), slog, and VERB.
|
|
|
Implements ActiveDB. Definition at line 222 of file NVActiveDB.h.
00223 {
00224 return Iter < GroupInfo > (new NVActiveDB_Iter(this, true));
00225 }
|
|
|
Implements ActiveDB. Definition at line 86 of file NVActiveDB.h. References NVHash::clear(). Referenced by read().
00086 {
00087 NVHash::clear();
00088 }
|
|
|
Reimplemented from NVcontainer. Definition at line 75 of file NVActiveDB.h. References NVcontainer::close().
00075 {
00076 NVHash::close();
00077 }
|
|
|
Implements ActiveDB. Definition at line 227 of file NVActiveDB.h.
00228 {
00229 return Iter < GroupInfo > (new NVActiveDB_Iter(this, false));
00230 }
|
|
||||||||||||
|
Stores informations of the newsgroup group in gi.
Implements ActiveDB. Definition at line 98 of file NVActiveDB.cc. References hash(), lock(), NVlist::o2r(), GroupInfo::setraw(), slog, and VERB. Referenced by CServer::getgroup(), and CServer::groupinfo().
00099 {
00100 VERB(slog.
00101 p(Logger::Debug) << "NVActiveDB::get(" << group << ",&gi)\n");
00102 lock(ShrdLock);
00103 Record *head = o2r(hashtab[hash(group)]);
00104 Record *r = head;
00105
00106 while (r) {
00107 r = o2r(r->next);
00108
00109 // The first approach is the cleaner one since it uses
00110 // GroupInfo's setraw function. However, this involves
00111 // a copy operation
00112 // gi->setraw(r->datap(),r->szdata);
00113 // if(strcmp(gi->name(),group)==0) break;
00114
00115 // The second approach assumes that the GroupInfo
00116 // data is stored in the same layout in the file.
00117 // The last (sizeof(GroupInfo)-r->szdata) bytes don't
00118 // matter. These are junk anyways.
00119 if (strcmp(((GroupInfo *) r->datap())->name(), group) == 0) {
00120 gi->setraw(r->datap(), r->szdata);
00121 break;
00122 }
00123 if (r == head)
00124 r = NULL;
00125 }
00126 lock(UnLock);
00127
00128 if (!r)
00129 return -1;
00130 return 0;
00131 }
|
|
|
Reimplemented from NVcontainer. Definition at line 65 of file NVActiveDB.h. References NVcontainer::get_lock().
00065 {
00066 return NVHash::get_lock();
00067 }
|
|
|
Implements ActiveDB. Definition at line 82 of file NVActiveDB.h. References NVcontainer::getmtime(). Referenced by CServer::active_valid().
00082 {
00083 NVHash::getmtime(tm);
00084 }
|
|
|
Checks whether the group exists in the active database.
Implements ActiveDB. Definition at line 133 of file NVActiveDB.cc. References hash(), lock(), NVlist::o2r(), slog, and VERB.
00134 {
00135 VERB(slog.
00136 p(Logger::Info) << "NVActiveDB::hasgroup(" << group << ")\n");
00137 lock(ShrdLock);
00138 Record *head = o2r(hashtab[hash(group)]);
00139 Record *r = head;
00140
00141 while (r) {
00142 r = o2r(r->next);
00143
00144 // The first approach is the cleaner one since it uses
00145 // GroupInfo's setraw function. However, this involves
00146 // a copy operation
00147 // gi->setraw(r->datap(),r->szdata);
00148 // if(strcmp(gi->name(),group)==0) break;
00149
00150 // The second approach assumes that the GroupInfo
00151 // data is stored in the same layout in the file.
00152 // The last (sizeof(GroupInfo)-r->szdata) bytes don't
00153 // matter. These are junk anyways.
00154 if (strcmp(((GroupInfo *) r->datap())->name(), group) == 0) {
00155 break;
00156 }
00157 if (r == head)
00158 r = NULL;
00159 }
00160 lock(UnLock);
00161
00162 if (!r)
00163 return 0;
00164 return 1;
00165 }
|
|
|
Definition at line 18 of file NVActiveDB.cc. References NVActiveDB_HASHSIZE. Referenced by add(), get(), hasgroup(), and sset().
00019 {
00020 unsigned long h = 1;
00021 const char *p = strg;
00022 while (p[0]) {
00023 h = (h * (p[0]) + p[1]) % NVActiveDB_HASHSIZE;
00024 if (!p[1])
00025 break;
00026 p += 2;
00027 }
00028 return h;
00029 }
|
|
|
Implements ActiveDB. Definition at line 89 of file NVActiveDB.h. References NVHash::is_empty().
00089 {
00090 return NVHash::is_empty();
00091 }
|
|
|
Reimplemented from NVcontainer. Definition at line 72 of file NVActiveDB.h. References NVcontainer::is_open().
00072 {
00073 return NVHash::is_open();
00074 }
|
|
||||||||||||
|
Reimplemented from NVcontainer. Definition at line 62 of file NVActiveDB.h. References NVcontainer::lock(). Referenced by CServer::active(), get(), hasgroup(), read(), and set().
00062 {
00063 return NVHash::lock(command, block);
00064 }
|
|
|
Definition at line 69 of file NVActiveDB.h. References NVActiveDB_HASHSIZE, and NVHash::open().
00069 {
00070 NVHash::open(dbname, NVActiveDB_HASHSIZE);
00071 }
|
|
||||||||||||||||
|
Read active database records and store those matching the filter expression in the active database.
Implements ActiveDB. Definition at line 167 of file NVActiveDB.cc. References clear(), lock(), matchgroup(), nlreadline(), GroupInfo::set(), GroupInfo::setflag(), setmtime(), slog, sset(), and VERB.
00168 {
00169 VERB(slog.
00170 p(Logger::Debug) << "NVActiveDB::read(&is,*filter,flags)\n");
00171
00172 GroupInfo gd;
00173 string line;
00174 time_t now;
00175
00176 lock(NVcontainer::ExclLock);
00177 if (flags & F_CLEAR)
00178 clear();
00179 while (!is.eof()) {
00180 // Each line has the following form
00181 // GroupName Last First Flags
00182 nlreadline(is, line, 0);
00183 if (line == ".")
00184 break;
00185
00186 if (!filter || matchgroup(filter, line.c_str()) > 0) {
00187 // Add group
00188 gd.set(line.c_str());
00189 if (flags & F_STORE_READONLY)
00190 gd.setflag('n');
00191 sset(gd);
00192 }
00193 }
00194 time(&now);
00195 setmtime(now);
00196 lock(NVcontainer::UnLock);
00197 }
|
|
||||||||||||
|
Implements ActiveDB. Definition at line 99 of file NVActiveDB.h. References lock(), and sset().
|
|
||||||||||||
|
Implements ActiveDB. Definition at line 79 of file NVActiveDB.h. References NVcontainer::setmtime(). Referenced by CServer::invalidateActiveDB(), and read().
00079 {
00080 NVHash::setmtime(tm, force);
00081 }
|
|
||||||||||||
|
Set newsgroup information for group gi.name(). If the flag update_only is specified, it is regarded as error, if gi.name() does not already exist. Otherwise, it is added to the active database.
Definition at line 31 of file NVActiveDB.cc. References NVHash::add(), GroupInfo::getraw(), hash(), GroupInfo::name(), nvtime(), nvtime_t, NVlist::o2r(), GroupInfo::setctime(), slog, and VERB. Referenced by read(), and set().
00032 {
00033 // GroupInfo cg;
00034 const char *gidata;
00035 unsigned int gisz;
00036 Record *head = o2r(hashtab[hash(gi.name())]);
00037 Record *r = head;
00038
00039 while (r) {
00040 r = o2r(r->next);
00041
00042 // The first approach is the cleaner one since it uses
00043 // GroupInfo's setraw function. However, this involves
00044 // a copy operation
00045 // cg.setraw(r->datap(),r->szdata);
00046 // if(strcmp(gi.name(),cg.name())==0) {
00047 // gi.setctime(cg.ctime());
00048 // The second approach assumes that the GroupInfo
00049 // data is stored in the same layout in the file.
00050 // The last (sizeof(GroupInfo)-r->szdata) bytes don't
00051 // matter. These are junk anyways.
00052 if (strcmp(((GroupInfo *) r->datap())->name(), gi.name())
00053 == 0) {
00054 gi.setctime(((GroupInfo *) r->datap())->ctime());
00055 gi.getraw(&gidata, &gisz);
00056 if (gisz != r->szdata) {
00057 VERB(slog.
00058 p(Logger::
00059 Error) <<
00060 "NVActiveDB::set: Size of new record not equal original record size. Should have been impossible.\n");
00061 } else {
00062 memcpy(r->datap(), gidata, gisz);
00063 }
00064 break;
00065 }
00066 if (r == head)
00067 r = NULL;
00068 }
00069
00070 if (!r) {
00071 if (flags & update_only) {
00072 // Should we throw an exception here?!?
00073 VERB(slog.
00074 p(Logger::
00075 Error) <<
00076 "NVActiveDB::set: Cannot find requested record\n");
00077 } else {
00078 const char *buf;
00079 unsigned int bufsz;
00080 nvtime_t now;
00081 nvtime(&now);
00082 gi.setctime(now);
00083 gi.getraw(&buf, &bufsz);
00084 NVHash::add(hash(gi.name()), buf, bufsz);
00085 }
00086 }
00087 }
|
|
||||||||||||||||||||
|
Implements ActiveDB. Definition at line 199 of file NVActiveDB.cc. References GroupInfo::ctime(), NVHashIter::data(), ERROR_LOCATION, NVHashIter::first(), matchgroup(), GroupInfo::name(), NVHashIter::next(), nvtime_t, GroupInfo::setraw(), slog, NVHashIter::valid(), and VERB.
00201 {
00202 VERB(slog.
00203 p(Logger::Debug) << "NVActiveDB::write(&os,ctime,...)\n");
00204
00205 NVHashIter nvhi(*this);
00206 GroupInfo gd;
00207 const char *buf;
00208 unsigned int bufsz;
00209
00210 for (nvhi.first(); nvhi.valid(); nvhi.next()) {
00211 nvhi.data(&buf, &bufsz);
00212 gd.setraw(buf, bufsz);
00213 if (((!filter) ||
00214 ((matchgroup(filter, gd.name()) > 0))) &&
00215 ctime < gd.ctime()) {
00216 if (mode == m_active)
00217 os << gd << "\r\n";
00218 else
00219 os << gd.name() << " " << gd.
00220 ctime() << " news\r\n";
00221 if (!os.good()) {
00222 throw SystemError("Cannot write GroupList",
00223 errno, ERROR_LOCATION);
00224 }
00225 }
00226 } /* for */
00227 }
|
|
||||||||||||
|
Definition at line 134 of file NVActiveDB.h.
00135 {
00136 adb.write(os);
00137 return os;
00138 }
|
1.3.6-20040222