Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

util.h File Reference

Go to the source code of this file.

Functions

int mkpdir (const char *dirname, int mode)
const char * group2dir (const char *name)
int matchgroup (const char *pattern, const char *group)
int matchaddress (const char *pattern, const char *address)
const char * getfqdn (void)


Function Documentation

const char* getfqdn void   ) 
 

Author:
Thomas Gschwind Get the fqdn of the local host. The primary host name may be required for expansion of spool_directory and log_file_path, so make sure it is set asap. It is obtained from uname(), but if that yields an unqualified value, make a FQDN by using gethostbyname to canonize it. Some people like upper case letters in their host names, so we don't force the case.
Returns:
The FQDN

Definition at line 120 of file util.cc.

Referenced by Config::init(), main(), and NServer::NServer().

00121 {
00122         static char primary_hostname[MAXHOSTNAMELEN];
00123         struct utsname uts;
00124         struct hostent *host;
00125 
00126         if (uname(&uts) < 0)
00127                 return NULL;    // failed
00128         if (strchr(uts.nodename, '.') == NULL &&
00129             (host = gethostbyname(uts.nodename)) != NULL) {
00130                 strcpy(primary_hostname, (char *) host->h_name);
00131         } else {
00132                 strcpy(primary_hostname, uts.nodename);
00133         }
00134 
00135         return primary_hostname;
00136 }

const char* group2dir const char *  name  ) 
 

Definition at line 54 of file util.cc.

Referenced by NVNewsgroup::NVNewsgroup().

00055 {
00056         static char buf[MAXPATHLEN], *p;
00057         const char *q;
00058 
00059         p = buf;
00060         q = name;
00061         while (((*p) = ((*q != '.') ? *q : '/')) != '\0') {
00062                 p++;
00063                 q++;
00064         }
00065 
00066         return buf;
00067 }

int matchaddress const char *  pattern,
const char *  address
 

int matchgroup const char *  pattern,
const char *  group
 

Author:
Thomas Gschwind Checks whether a newsgroup matches a given list of patterns. The pattern-list is a comma separated list of newsgroup-patterns that may contain a wildcard (*) at the end and start with a ! to indicate that the newsgroup must not match a pattern. Eg: comp.*,!comp.os.win* matches all newsgroups starting with comp., except those starting with comp.os.win. This rule is especially designed for our special windows-friends ;)
Parameters:
pattern The pattern-list.
group The name of the newsgroup terminated by \0 or a whitespace.
Returns:
  • If the newsgroup is matched by a positive pattern, the number of matching characters plus one will be returned.
  • If the newsgroup is matched by a negative pattern (one that starts with !), minus the number of characters minus one will be returned.

Definition at line 69 of file util.cc.

Referenced by MPList::postserver(), NVActiveDB::read(), MPList::server(), and NVActiveDB::write().

00070 {
00071         char c;
00072         int j, clen, bmlen = 0, bmrej = 0;
00073         int rejrule = 0;
00074 
00075         j = 0;
00076         do {
00077                 clen = 0;
00078                 if (pattern[j] == '!') {
00079                         j++;
00080                         rejrule = 1;
00081                 } else {
00082                         rejrule = 0;
00083                 }
00084                 while ((c = pattern[j]) && c == group[clen]) {
00085                         clen++;
00086                         j++;
00087                 }
00088 
00089                 switch (c) {
00090                 case ',':
00091                 case '\0':
00092                         if (group[clen] != '\0' && !isspace(group[clen])) {
00093                                 clen = -2;
00094                         }
00095                         clen++;
00096                         break;
00097                 case '*':
00098                         clen++;
00099                         break;
00100                 default:
00101                         clen = -1;
00102                         break;
00103                 }
00104 
00105                 if (clen > bmlen) {
00106                         bmlen = clen;
00107                         bmrej = rejrule;
00108                 }
00109 
00110                 while (c && c != ',') {
00111                         j++;
00112                         c = pattern[j];
00113                 }
00114                 j++;
00115         } while (c);
00116 
00117         return bmrej ? -bmlen : bmlen;
00118 }

int mkpdir const char *  dirname,
int  mode
 

Definition at line 15 of file util.cc.

Referenced by ArtSpooler::ArtSpooler(), and NVNewsgroup::NVNewsgroup().

00016 {
00017         struct stat s;
00018         char buf[MAXPATHLEN];
00019         char *p;
00020         const char *q = dirname;
00021 
00022         if (stat(dirname, &s) < 0) {
00023                 if (errno != ENOENT)
00024                         return -1;
00025                 p = buf;
00026                 if (*q == '/')
00027                         *p++ = *q++;
00028                 while (*q) {
00029                         while (*q && *q != '/')
00030                                 *p++ = *q++;
00031                         *p = '\0';
00032                         if (stat(buf, &s) < 0) {
00033                                 if (errno != ENOENT)
00034                                         return -1;
00035                                 if (mkdir(buf, mode) < 0)
00036                                         return -1;
00037                         } else {
00038                                 if (!(S_ISDIR(s.st_mode))) {
00039                                         errno = ENOTDIR;
00040                                         return -1;
00041                                 }
00042                         }
00043                         while (*q == '/')
00044                                 *p++ = *q++;
00045                 }
00046         }
00047         if (!(S_ISDIR(s.st_mode))) {
00048                 errno = ENOTDIR;
00049                 return -1;
00050         }
00051         return 0;
00052 }


Generated on Fri Aug 20 10:58:09 2004 for NewsCache by doxygen 1.3.6-20040222