diff options
-rw-r--r-- | cacheserver/Makefile | 11 | ||||
-rw-r--r-- | cacheserver/cacheserver.c | 23 | ||||
-rw-r--r-- | cacheserver/utmpserver.c | 58 | ||||
-rw-r--r-- | cacheserver/utmpsync.c | 33 | ||||
-rw-r--r-- | include/proto.h | 6 | ||||
-rw-r--r-- | mbbsd/stuff.c | 69 | ||||
-rw-r--r-- | mbbsd/talk.c | 12 |
7 files changed, 109 insertions, 103 deletions
diff --git a/cacheserver/Makefile b/cacheserver/Makefile index af95a2f0..2c4f46e5 100644 --- a/cacheserver/Makefile +++ b/cacheserver/Makefile @@ -1,21 +1,16 @@ # $Id$ .include "../pttbbs.mk" -AUTO_PROGRAMS= utmpserver -PROGRAMS= ${AUTO_PROGRAMS} utmpsync +PROGRAMS= utmpserver utmpsync all: ${PROGRAMS} #cacheserver: cacheserver.c # ${CC} ${CFLAGS} ${LDFLAGS} -o cacheserver cacheserver.c avltree.c -utmpsync: utmpsync.c - ${CC} ${CFLAGS} ${LDFLAGS} -DPTTBBS_UTIL -o utmpsync utmpsync.c \ - ../util/util_*.o - -.for fn in ${AUTO_PROGRAMS} +.for fn in ${PROGRAMS} ${fn}: ${fn}.c - ${CC} ${CFLAGS} ${LDFLAGS} -o ${fn} ${fn}.c + ${CC} ${CFLAGS} ${LDFLAGS} -DPTTBBS_UTIL -o ${fn} ${fn}.c ../util/util_*.o .endfor clean: diff --git a/cacheserver/cacheserver.c b/cacheserver/cacheserver.c index dd5cc57d..05b454c0 100644 --- a/cacheserver/cacheserver.c +++ b/cacheserver/cacheserver.c @@ -3,7 +3,6 @@ #include <avltree.h> #include <err.h> -int tobind(int); AVL_IX_DESC avl; typedef struct { @@ -105,25 +104,3 @@ int main(int argc, char **argv) service(sfd); return 0; } - -/* utils */ -int tobind(int port) -{ - int sockfd, val; - struct sockaddr_in servaddr; - - if( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0 ) - err(1, NULL); - setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, - (char *)&val, sizeof(val)); - bzero(&servaddr, sizeof(servaddr)); - servaddr.sin_family = AF_INET; - servaddr.sin_addr.s_addr = htonl(INADDR_ANY); - servaddr.sin_port = htons(port); - if( bind(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0 ) - err(1, NULL); - if( listen(sockfd, 5) < 0 ) - err(1, NULL); - - return sockfd; -} diff --git a/cacheserver/utmpserver.c b/cacheserver/utmpserver.c index 67989340..5826eb59 100644 --- a/cacheserver/utmpserver.c +++ b/cacheserver/utmpserver.c @@ -2,9 +2,6 @@ #include "bbs.h" #include <err.h> -int tobind(int); -int toread(int fd, void *buf, int len); - struct { int uid; short nFriends, nRejects; @@ -12,11 +9,18 @@ struct { int reject[MAX_REJECT]; } utmp[MAX_ACTIVE]; +inline void countarray(int *s, int max) +{ + int i; + for( i = 0 ; i < max && s[i] ; ++i ) + ; + return i; +} + int main(int argc, char **argv) { struct sockaddr_in clientaddr; - int ch, port = 5120, sfd, cfd, len, index, i; - //char buf[2048]; + int ch, port = 5120, sfd, cfd, len, index, i, uid; while( (ch = getopt(argc, argv, "p:h")) != -1 ) switch( ch ){ @@ -55,41 +59,17 @@ int main(int argc, char **argv) fprintf(stderr, "%d users synced\n", nSynced); continue; } - } - return 0; -} -/* utils */ -int tobind(int port) -{ - int sockfd, val; - struct sockaddr_in servaddr; - - if( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0 ) - err(1, NULL); - setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, - (char *)&val, sizeof(val)); - bzero(&servaddr, sizeof(servaddr)); - servaddr.sin_family = AF_INET; - servaddr.sin_addr.s_addr = htonl(INADDR_ANY); - servaddr.sin_port = htons(port); - if( bind(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0 ) - err(1, NULL); - if( listen(sockfd, 5) < 0 ) - err(1, NULL); - - return sockfd; -} + if( toread(cfd, &uid, sizeof(uid)) > 0 && + toread(cfd, utmp[index].friend, sizeof(utmp[index].friend)) > 0 && + toread(cfd, utmp[index].reject, sizeof(utmp[index].reject)) > 0 ){ + int nFriends = 0, frarray[MAX_FRIEND]; + utmp[index].uid = uid; + utmp[index].nFriends = countarray(utmp[index].friend, MAX_FRIEND); + utmp[index].nRejects = countarray(utmp[index].reject, MAX_REJECT); -int toread(int fd, void *buf, int len) -{ - int l; - for( l = 0 ; len > 0 ; ) - if( (l = read(fd, buf, len)) <= 0 ) - return -1; - else{ - buf += l; - len -= l; } - return l; + close(cfd); + } + return 0; } diff --git a/cacheserver/utmpsync.c b/cacheserver/utmpsync.c index a8d6731c..bebde137 100644 --- a/cacheserver/utmpsync.c +++ b/cacheserver/utmpsync.c @@ -25,36 +25,3 @@ int main(int argc, char **argv) } return 0; } - -/* utils */ -int towrite(int fd, void *buf, int len) -{ - int l; - for( l = 0 ; len > 0 ; ) - if( (l = write(fd, buf, len)) <= 0 ) - return -1; - else{ - buf += l; - len -= l; - } - return l; -} - -int toconnect(char *host, int port) -{ - int sock; - struct sockaddr_in serv_name; - if( (sock = socket(AF_INET, SOCK_STREAM, 0)) < 0 ){ - perror("socket"); - return -1; - } - - serv_name.sin_family = AF_INET; - serv_name.sin_addr.s_addr = inet_addr(host); - serv_name.sin_port = htons(port); - if( connect(sock, (struct sockaddr*)&serv_name, sizeof(serv_name)) < 0 ){ - close(sock); - return -1; - } - return sock; -} diff --git a/include/proto.h b/include/proto.h index 2828a196..f291f74d 100644 --- a/include/proto.h +++ b/include/proto.h @@ -523,6 +523,12 @@ int qsort_intcompar(const void *a, const void *b); void *MALLOC(int size); void FREE(void *ptr); #endif +#ifdef OUTTACACHE +int tobind(int port); +int toconnect(char *host, int port); +int toread(int fd, void *buf, int len); +int towrite(int fd, void *buf, int len); +#endif /* syspost */ int post_msg(char* bname, char* title, char *msg, char* author); diff --git a/mbbsd/stuff.c b/mbbsd/stuff.c index 767fdca1..008f18f9 100644 --- a/mbbsd/stuff.c +++ b/mbbsd/stuff.c @@ -694,3 +694,72 @@ int qsort_intcompar(const void *a, const void *b) { return *(int *)a - *(int *)b; } + +#ifdef OUTTACACHE +#include <err.h> +int tobind(int port) +{ + int sockfd, val; + struct sockaddr_in servaddr; + + if( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0 ) + err(1, NULL); + setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, + (char *)&val, sizeof(val)); + bzero(&servaddr, sizeof(servaddr)); + servaddr.sin_family = AF_INET; + servaddr.sin_addr.s_addr = htonl(INADDR_ANY); + servaddr.sin_port = htons(port); + if( bind(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0 ) + err(1, NULL); + if( listen(sockfd, 5) < 0 ) + err(1, NULL); + + return sockfd; +} + +int toconnect(char *host, int port) +{ + int sock; + struct sockaddr_in serv_name; + if( (sock = socket(AF_INET, SOCK_STREAM, 0)) < 0 ){ + perror("socket"); + return -1; + } + + serv_name.sin_family = AF_INET; + serv_name.sin_addr.s_addr = inet_addr(host); + serv_name.sin_port = htons(port); + if( connect(sock, (struct sockaddr*)&serv_name, sizeof(serv_name)) < 0 ){ + close(sock); + return -1; + } + return sock; +} + +int toread(int fd, void *buf, int len) +{ + int l; + for( l = 0 ; len > 0 ; ) + if( (l = read(fd, buf, len)) <= 0 ) + return -1; + else{ + buf += l; + len -= l; + } + return l; +} + +int towrite(int fd, void *buf, int len) +{ + int l; + for( l = 0 ; len > 0 ; ) + if( (l = write(fd, buf, len)) <= 0 ) + return -1; + else{ + buf += l; + len -= l; + } + return l; +} +#endif diff --git a/mbbsd/talk.c b/mbbsd/talk.c index c54291a2..b801357b 100644 --- a/mbbsd/talk.c +++ b/mbbsd/talk.c @@ -216,6 +216,18 @@ login_friend_online(void) userinfo_t *uentp; int i, stat, stat1; int offset = (int)(currutmp - &SHM->uinfo[0]); +#ifdef OUTTACACHE + int sfd; + + if( (sfd = toconnect(OUTTACACHEHOST, OUTTACACHEPOST)) > 0 ){ + if( towrite(sfd, &offset, sizeof(offset)) > 0 && + towrite(sfd, &currutmp->uid, sizeof(currutmp->uid)) > 0 && + towrite(sfd, currutmp->friend, sizeof(currutmp->friend)) > 0 && + towrite(sfd, currutmp->reject, sizeof(currutmp->reject)) > 0 ){ + } + close(sfd); + } +#endif for (i = 0; i < SHM->UTMPnumber && currutmp->friendtotal < MAX_FRIEND; i++) { uentp = (SHM->sorted[SHM->currsorted][0][i]); if (uentp && uentp->uid && (stat = set_friend_bit(currutmp, uentp))) { |