summaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorkcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2007-12-12 09:42:23 +0800
committerkcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2007-12-12 09:42:23 +0800
commit9a12adf6d29cdefc98afe2566a9e5479489f111b (patch)
tree6e2b911398cb6dcb08b183ab645817e098182968 /util
parent3d16ea67c380607528e7c8df0b2cc5a2f2636b9f (diff)
downloadpttbbs-9a12adf6d29cdefc98afe2566a9e5479489f111b.tar
pttbbs-9a12adf6d29cdefc98afe2566a9e5479489f111b.tar.gz
pttbbs-9a12adf6d29cdefc98afe2566a9e5479489f111b.tar.bz2
pttbbs-9a12adf6d29cdefc98afe2566a9e5479489f111b.tar.lz
pttbbs-9a12adf6d29cdefc98afe2566a9e5479489f111b.tar.xz
pttbbs-9a12adf6d29cdefc98afe2566a9e5479489f111b.tar.zst
pttbbs-9a12adf6d29cdefc98afe2566a9e5479489f111b.zip
* extract common functions as library.
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@3673 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'util')
-rw-r--r--util/BM_money.c11
-rw-r--r--util/Makefile17
-rw-r--r--util/angel.c5
-rw-r--r--util/bbsmail.c34
-rw-r--r--util/birth.c10
-rw-r--r--util/deluserfile.c21
-rw-r--r--util/mailangel.c8
-rw-r--r--util/openticket.c11
-rw-r--r--util/outmail.c31
-rw-r--r--util/poststat.c38
-rw-r--r--util/reaper.c14
-rw-r--r--util/toplazyBBM.c15
-rw-r--r--util/toplazyBM.c15
-rw-r--r--util/topusr.c18
-rw-r--r--util/uhash_loader.c29
-rw-r--r--util/writemoney.c12
16 files changed, 21 insertions, 268 deletions
diff --git a/util/BM_money.c b/util/BM_money.c
index 1f5cc10f..b089fb0b 100644
--- a/util/BM_money.c
+++ b/util/BM_money.c
@@ -15,17 +15,6 @@ int c, n;
-int Link(const char *src, const char *dst) {
- char cmd[200];
-
- if (link(src, dst) == 0)
- return 0;
-
- sprintf(cmd, "/bin/cp -R %s %s", src, dst);
- return system(cmd);
-}
-
-
int main(int argc, char **argv)
{
FILE *fp = fopen(BBSHOME "/etc/topboardman", "r");
diff --git a/util/Makefile b/util/Makefile
index ca7b0fd0..48fadad8 100644
--- a/util/Makefile
+++ b/util/Makefile
@@ -10,7 +10,7 @@ BBSBASE= $(SRCROOT)/include/var.h
UTIL_OBJS= \
util_cache.o util_record.o util_passwd.o util_var.o \
util_stuff.o util_osdep.o util_args.o util_file.o \
- util_crypt.o util_calendar.o
+ util_crypt.o
MBBSD_OBJS= \
cache record passwd var \
@@ -27,11 +27,12 @@ CPROG_WITH_UTIL= \
reaper buildAnnounce inndBM mailangel \
outmail chkhbf merge_dir \
transman angel gamblegive wretch_man \
- chesscountry tunepasswd buildir xchatd
+ chesscountry tunepasswd buildir xchatd \
+ uhash_loader
# 下面這些程式, 會直接被 compile
CPROG_WITHOUT_UTIL= \
- uhash_loader showboard countalldice bbsrf \
+ showboard countalldice bbsrf \
initbbs userlist merge_board bbsmail
# 下面這些程式會被 install
@@ -43,6 +44,10 @@ PROGS= ${CPROG_WITH_UTIL} ${CPROG_WITHOUT_UTIL} \
dailybackup.pl tarqueue.pl waterball.pl filtermail.pl \
getbackup.pl udnnews.pl rebuildaloha.pl
+LIBS+= $(SRCROOT)/src/libbbsutil/libbbsutil.a \
+ $(SRCROOT)/src/libbbs/libbbs.a
+
+
all: ${CPROG_WITH_UTIL} ${CPROG_WITHOUT_UTIL} ${PROGS}
$(SRCROOT)/include/var.h: $(SRCROOT)/mbbsd/var.c
@@ -50,7 +55,7 @@ $(SRCROOT)/include/var.h: $(SRCROOT)/mbbsd/var.c
.for fn in ${CPROG_WITH_UTIL}
${fn}: ${BBSBASE} ${fn}.c ${UTIL_OBJS}
- $(CCACHE) ${CC} ${CFLAGS} ${LDFLAGS} -o ${fn} ${UTIL_OBJS} ${fn}.c
+ $(CCACHE) ${CC} ${CFLAGS} ${LDFLAGS} -o ${fn} ${UTIL_OBJS} ${fn}.c $(LIBS)
.endfor
.for fn in ${MBBSD_OBJS}
@@ -59,7 +64,7 @@ util_${fn}.o: ${BBSBASE} $(SRCROOT)/mbbsd/${fn}.c
.endfor
shmctl: ${BBSBASE} shmctl.c ${UTIL_OBJS}
- $(CCACHE) ${CXX} ${CFLAGS} ${LDFLAGS} -o shmctl ${UTIL_OBJS} shmctl.c
+ $(CCACHE) ${CXX} ${CFLAGS} ${LDFLAGS} -o shmctl ${UTIL_OBJS} shmctl.c $(LIBS)
#shmctl: ${BBSBASE} shmctl.c ${UTIL_OBJS}
# $(CCACHE) gcc -g -DBBSHOME='"/home/bbs"' -I$(SRCROOT)/include -D__OS_MAJOR_VERSION__="2" -D__OS_MINOR_VERSION__="6" -DPTTBBS_UTIL -O1 -o shmctl ${UTIL_OBJS} shmctl.c
#shmctl: ${BBSBASE} shmctl.cc ${UTIL_OBJS}
@@ -67,7 +72,7 @@ shmctl: ${BBSBASE} shmctl.c ${UTIL_OBJS}
bbsmail: ${BBSBASE} bbsmail.c $(SRCROOT)/innbbsd/str_decode.c $(UTIL_OBJS)
$(CCACHE) $(CC) $(CFLAGS) $(LDFLAGS) -o bbsmail -DUSE_ICONV \
- bbsmail.c $(SRCROOT)/innbbsd/str_decode.c $(UTIL_OBJS)
+ bbsmail.c $(SRCROOT)/innbbsd/str_decode.c $(UTIL_OBJS) $(LIBS)
install: $(PROGS)
install -d $(BBSHOME)/bin/
diff --git a/util/angel.c b/util/angel.c
index 4f7b0a0c..5acd400b 100644
--- a/util/angel.c
+++ b/util/angel.c
@@ -16,9 +16,6 @@ int nReport = 50;
int count;
char* mailto = "SYSOP";
-int ListCmp(const void * a, const void * b){
- return *(int*)b - *(int*)a;
-}
int RejCmp(const void * a, const void * b){
return strcasecmp(SHM->userid[*(int*)a - 1], SHM->userid[*(int*)b - 1]);
@@ -100,7 +97,7 @@ void readData(){
rej_list[k++] = i;
}
- qsort(list, count, sizeof(int[2]), ListCmp);
+ qsort(list, count, sizeof(int[2]), cmp_int_desc);
qsort(rej_list, double_rej, sizeof(int), RejCmp);
}
diff --git a/util/bbsmail.c b/util/bbsmail.c
index 4cc441f2..96f5b512 100644
--- a/util/bbsmail.c
+++ b/util/bbsmail.c
@@ -9,40 +9,6 @@ extern char *notitle[], *nofrom[], *nocont[];
#endif
-int
-strip_ansi(char *buf, const char *str, int mode)
-{
- register int ansi, count = 0;
-
- for (ansi = 0; *str /* && *str != '\n' */ ; str++) {
- if (*str == 27) {
- if (mode) {
- if (buf)
- *buf++ = *str;
- count++;
- }
- ansi = 1;
- } else if (ansi && strchr("[;1234567890mfHABCDnsuJKc=n", *str)) {
- if ((mode == NO_RELOAD && !strchr("c=n", *str)) ||
- (mode == ONLY_COLOR && strchr("[;1234567890m", *str))) {
- if (buf)
- *buf++ = *str;
- count++;
- }
- if (strchr("mHn ", *str))
- ansi = 0;
- } else {
- ansi = 0;
- if (buf)
- *buf++ = *str;
- count++;
- }
- }
- if (buf)
- *buf = '\0';
- return count;
-}
-
int mailalertuid(int tuid)
{
userinfo_t *uentp=NULL;
diff --git a/util/birth.c b/util/birth.c
index a3503390..436c37a6 100644
--- a/util/birth.c
+++ b/util/birth.c
@@ -24,16 +24,6 @@ int bad_user_id(const char *userid) {
return 0;
}
-int Link(const char *src, const char *dst) {
- char cmd[200];
-
- if (link(src, dst) == 0)
- return 0;
-
- sprintf(cmd, "/bin/cp -R %s %s", src, dst);
- return system(cmd);
-}
-
int main(argc, argv)
int argc;
char **argv;
diff --git a/util/deluserfile.c b/util/deluserfile.c
index aa5aaa74..f9f16f1f 100644
--- a/util/deluserfile.c
+++ b/util/deluserfile.c
@@ -7,25 +7,6 @@
#define DELZEROFILE
#define USERHOME BBSHOME "/home"
-int bad_user_id(const char *userid)
-{
- register char ch;
-
- if (strlen(userid) < 2)
- return 1;
-
- if (!isalpha(*userid))
- return 1;
-
- if (!strcasecmp(userid, "new"))
- return 1;
-
- while ((ch = *(++userid)))
- if (!isalnum(ch))
- return 1;
- return 0;
-}
-
void del_file(char *userid)
{
char buf[200], buf1[200];
@@ -123,7 +104,7 @@ int main(int argc, char **argv)
ptr = de->d_name;
/* 預防錯誤 */
- if (!bad_user_id(ptr))
+ if (is_validuserid(ptr))
{
if (!(count++ % 300))
printf(".\n");
diff --git a/util/mailangel.c b/util/mailangel.c
index 93d9524b..00906a4c 100644
--- a/util/mailangel.c
+++ b/util/mailangel.c
@@ -11,14 +11,6 @@ int count;
char *mailto = NULL;
char *mailfile = NULL;
-int ListCmp(const void * a, const void * b){
- return *(int*)b - *(int*)a;
-}
-
-int RejCmp(const void * a, const void * b){
- return strcasecmp(SHM->userid[*(int*)a - 1], SHM->userid[*(int*)b - 1]);
-}
-
void readData();
void sendResult();
void mailUser(char *userid);
diff --git a/util/openticket.c b/util/openticket.c
index db473fd2..a7a2fd5c 100644
--- a/util/openticket.c
+++ b/util/openticket.c
@@ -8,17 +8,6 @@ static char *betname[8] = {"Ptt", "Jaky", "Action", "Heat",
#define MAX_DES 7 /* 最大保留獎數 */
-int Link(const char *src, const char *dst)
-{
- char cmd[200];
-
- if (link(src, dst) == 0)
- return 0;
-
- sprintf(cmd, "/bin/cp -R %s %s", src, dst);
- return system(cmd);
-}
-
int main(int argc, char **argv)
{
int money, bet, n, total = 0, ticket[8] =
diff --git a/util/outmail.c b/util/outmail.c
index 5d5c9d37..eb674890 100644
--- a/util/outmail.c
+++ b/util/outmail.c
@@ -10,37 +10,6 @@ char *smtpname;
int smtpport;
char disclaimer[1024];
-/* qp_encode() modified from mutt-1.5.7/rfc2047.c q_encoder() */
-const char MimeSpecials[] = "@.,;:<>[]\\\"()?/= \t";
-char * qp_encode (char *s, size_t slen, const char *d, const char *tocode)
-{
- char hex[] = "0123456789ABCDEF";
- char *s0 = s;
-
- memcpy (s, "=?", 2), s += 2;
- memcpy (s, tocode, strlen (tocode)), s += strlen (tocode);
- memcpy (s, "?Q?", 3), s += 3;
- assert(s-s0+3<slen);
-
- while (*d != '\0' && s-s0+6<slen)
- {
- unsigned char c = *d++;
- if (c == ' ')
- *s++ = '_';
- else if (c >= 0x7f || c < 0x20 || c == '_' || strchr (MimeSpecials, c))
- {
- *s++ = '=';
- *s++ = hex[(c & 0xf0) >> 4];
- *s++ = hex[c & 0x0f];
- }
- else
- *s++ = c;
- }
- memcpy (s, "?=", 2), s += 2;
- *s='\0';
- return s0;
-}
-
int waitReply(int sock) {
char buf[256];
diff --git a/util/poststat.c b/util/poststat.c
index d18a3b70..8dfa6e5a 100644
--- a/util/poststat.c
+++ b/util/poststat.c
@@ -41,44 +41,6 @@ struct posttop
}
top[TOPCOUNT], *tp;
-/*
- woju
- Cross-fs rename()
- */
-
-int Rename(const char *src, const char *dst)
-{
-
- if (rename(src, dst) == 0)
- return 0;
-/*
- sprintf(cmd, "/bin/mv %s %s", src, dst);
- return system(cmd);
-*/
- return 0;
-}
-
-int
-ci_strcmp(s1, s2)
- register char *s1, *s2;
-{
- register int c1, c2, diff;
-
- do
- {
- c1 = *s1++;
- c2 = *s2++;
- if (c1 >= 'A' && c1 <= 'Z')
- c1 |= 32;
- if (c2 >= 'A' && c2 <= 'Z')
- c2 |= 32;
- if((diff = c1 - c2))
- return (diff);
- }
- while (c1);
- return 0;
-}
-
/* ---------------------------------- */
/* hash structure : array + link list */
diff --git a/util/reaper.c b/util/reaper.c
index 348224e9..d058cc55 100644
--- a/util/reaper.c
+++ b/util/reaper.c
@@ -4,24 +4,12 @@
time4_t now;
-int invalid(char *userid) {
- int i;
-
- if(!isalpha(userid[0]))
- return 1;
-
- for(i = 1; i < IDLEN && userid[i]; i++)
- if(!isalpha(userid[i]) && !isdigit(userid[i]))
- return 1;
- return 0;
-}
-
int check(int n, userec_t *u) {
time4_t d;
char buf[256];
if(u->userid[0] != '\0') {
- if(invalid(u->userid)) {
+ if(!is_validuserid(u->userid)) {
syslog(LOG_ERR, "bad userid(%d): %s", n, u->userid);
u->userid[0] = '\0';
} else {
diff --git a/util/toplazyBBM.c b/util/toplazyBBM.c
index 3b881c5f..38f4d55d 100644
--- a/util/toplazyBBM.c
+++ b/util/toplazyBBM.c
@@ -31,17 +31,6 @@ int bmlostdays_cmp(const void *va, const void *vb)
else return 1;
}
-
-int LINK(char* src, char* dst){
- char cmd[200];
- if(symlink(src,dst) == -1)
- {
- sprintf(cmd, "/bin/cp -R %s %s", src, dst);
- return system(cmd);
- }
- return 0;
-}
-
int main(int argc, char *argv[])
{
int bmid, i, j=0;
@@ -183,9 +172,9 @@ int main(int argc, char *argv[])
}
unlink(genbuf);
if(lostdays <= 30){
- LINK(OUTFILE, genbuf);
+ Link(OUTFILE, genbuf);
}else{
- LINK(FIREFILE, genbuf);
+ Link(FIREFILE, genbuf);
}
sprintf(genbuf, BBSHOME "/home/%c/%s/.DIR", lostbms[i].bmname[0], lostbms[i].bmname);
diff --git a/util/toplazyBM.c b/util/toplazyBM.c
index 4789557d..b9a66c26 100644
--- a/util/toplazyBM.c
+++ b/util/toplazyBM.c
@@ -30,17 +30,6 @@ int bmlostdays_cmp(const void *va, const void *vb)
else return 1;
}
-int LINK(char* src, char* dst)
-{
- char cmd[200];
- if(symlink(src,dst) == -1)
- {
- sprintf(cmd, "/bin/cp -R %s %s", src, dst);
- return system(cmd);
- }
- return 0;
-}
-
int main(int argc, char *argv[])
{
int bmid, i, j=0;
@@ -194,9 +183,9 @@ int main(int argc, char *argv[])
unlink(genbuf);
if (lostdays <= 90)
- LINK(OUTFILE, genbuf);
+ Link(OUTFILE, genbuf);
else
- LINK(FIREFILE, genbuf);
+ Link(FIREFILE, genbuf);
sprintf(genbuf, BBSHOME "/home/%c/%s/.DIR",
lostbms[i].bmname[0], lostbms[i].bmname);
diff --git a/util/topusr.c b/util/topusr.c
index d2679d39..58f3d86b 100644
--- a/util/topusr.c
+++ b/util/topusr.c
@@ -91,22 +91,6 @@ int
}
#endif /* HAVE_TIN */
-int
-bad_user_id(const char *userid)
-{
- register char ch;
- if (strlen(userid) < 2)
- return 1;
- if (not_alpha(*userid))
- return 1;
- while((ch = *(++userid)))
- {
- if (not_alnum(ch))
- return 1;
- }
- return 0;
-}
-
int main(int argc, char **argv)
{
int i, j;
@@ -137,7 +121,7 @@ int main(int argc, char **argv)
aman.userid[IDLEN]=0;
aman.nickname[22]=0;
if((aman.userlevel & PERM_NOTOP) || !aman.userid[0] ||
- bad_user_id(aman.userid) ||
+ !is_validuserid(aman.userid) ||
strchr(aman.userid, '.'))
{
continue;
diff --git a/util/uhash_loader.c b/util/uhash_loader.c
index fe90a545..8696b3c4 100644
--- a/util/uhash_loader.c
+++ b/util/uhash_loader.c
@@ -3,7 +3,6 @@
#include "bbs.h"
#include "fnv_hash.h"
-unsigned string_hash(unsigned char *s);
void userec_add_to_uhash(int n, userec_t *id, int onfly);
void fill_uhash(int onfly);
void load_uhash(void);
@@ -72,7 +71,7 @@ void checkhash(int h)
while(*p != -1)
{
if(*p <-1 || *p >= MAX_USERS) {*p=-1; return;}
- ch = string_hash( SHM->userid[*p])%(1<<HASH_BITS);
+ ch = StringHash( SHM->userid[*p])%(1<<HASH_BITS);
if(ch!=h)
{
printf("remove %d %d!=%d %d [%s] next:%d\n",
@@ -131,30 +130,6 @@ void fill_uhash(int onfly)
printf("total %d names %s.\n", usernumber, onfly ? "checked":"loaded");
}
-unsigned string_hash(unsigned char *s)
-{
- return fnv1a_32_strcase(s, FNV1_32_INIT);
-}
-
-// TODO share code with mbbsd/stuff.c
-int is_validuserid(const char *id)
-{
- int len, i;
- if(id==NULL)
- return 0;
- len = strlen(id);
-
- if (len < 2 || len>IDLEN)
- return 0;
-
- if (not_alpha(id[0]))
- return 0;
- for (i = 1; i < len; i++)
- if (not_alnum(id[i]))
- return 0;
- return 1;
-}
-
void userec_add_to_uhash(int n, userec_t *user, int onfly)
{
int *p, h, l=0;
@@ -170,7 +145,7 @@ void userec_add_to_uhash(int n, userec_t *user, int onfly)
return;
}
- h = string_hash(user->userid)%(1<<HASH_BITS);
+ h = StringHash(user->userid)%(1<<HASH_BITS);
p = &(SHM->hash_head[h]);
if(!onfly || SHM->userid[n][0] != user->userid[0] ||
diff --git a/util/writemoney.c b/util/writemoney.c
index 0db8d99d..4b70a22b 100644
--- a/util/writemoney.c
+++ b/util/writemoney.c
@@ -6,18 +6,6 @@
time4_t now;
extern SHM_t *SHM;
-int invalid(char *userid) {
- int i;
-
- if(!isalpha(userid[0]))
- return 1;
-
- for(i = 1; i < IDLEN && userid[i]; i++)
- if(!isalpha(userid[i]) && !isdigit(userid[i]))
- return 1;
- return 0;
-}
-
int main()
{
int num, pwdfd, money;