leafnode  1.12.0
About: Leafnode is a store & forward NNTP proxy for small (dialup) sites.
  Fossies Dox: leafnode-1.12.0.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

activutil_resolve.c
Go to the documentation of this file.
1#include "leafnode.h"
2#include "activutil.h"
3#include "ln_log.h"
4#include "critmem.h"
5
6#include <string.h>
7#include <stdlib.h>
8#include <ctype.h>
9
10static void xfree(char *d)
11{
12 if (d)
13 free(d);
14}
15
16static void
18{
19 xfree(n->name);
20 xfree(n->desc);
21}
22
23/* count number of capital letters (isupper) in string */
24static unsigned long countcaps(const char *s)
25{
26 unsigned long i = 0;
27 while(*s)
28 {
29 if (isupper((unsigned char)*s))
30 i++;
31 s++;
32 }
33 return i;
34}
35
36/* check if d or s has less caps, and copy that part with less caps in
37 * its name into d, free the other struct's data
38 */
39static void picklesscaps(struct newsgroup *d, struct newsgroup *s)
40{
41 ln_log(LNLOG_SERR, LNLOG_CTOP, "Newsgroup name conflict: %s vs. %s",
42 d->name, s->name);
43 if (countcaps(s->name) < countcaps(d->name)) {
45 newsgroup_copy(d,s);
46 } else {
48 }
49 ln_log(LNLOG_SERR, LNLOG_CTOP, "Newsgroup name conflict, chose %s",
50 d->name);
51}
52
53void validateactive(void) {
54 unsigned long p1, p2;
55
56 for (p1 = p2 = 1 ; p1 < activesize; p1++) {
57 if (p1 > p2)
58 newsgroup_copy(&active[p2],&active[p1]);
59 if (0 == compactive(&active[p2-1], &active[p1])) {
60 /* duplicate newsgroup */
61 picklesscaps(&active[p2-1],&active[p1]);
62 } else {
63 p2++;
64 }
65 }
66
67 if (p2 < p1) {
68 activesize = p2;
69 active[p2].name = NULL; /* do NOT free this! it has been copied
70 already */
71 active = (struct newsgroup *)critrealloc((char *)active,
72 (1 + activesize)
73 * sizeof(struct newsgroup),
74 "reallocating active");
75 }
76}
int compactive(const void *a, const void *b)
Definition: activutil.c:62
void newsgroup_copy(struct newsgroup *d, const struct newsgroup *s)
Definition: activutil.c:52
size_t activesize
Definition: activutil.c:39
struct newsgroup * active
Definition: activutil.c:40
static unsigned long countcaps(const char *s)
static void xfree(char *d)
static void newsgroup_freedata(struct newsgroup *n)
void validateactive(void)
static void picklesscaps(struct newsgroup *d, struct newsgroup *s)
char * critrealloc(char *a, size_t size, const char *message)
Definition: critmem.c:79
void ln_log(int sev, int ctx, const char *format,...)
Definition: ln_log.c:103
#define LNLOG_SERR
Definition: ln_log.h:13
#define LNLOG_CTOP
Definition: ln_log.h:22
char * desc
Definition: leafnode.h:125
char * name
Definition: leafnode.h:124