Tue Aug 18 00:42:33 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
[citadel.git] / citadel / netproc.c
index 974c44d8d7f943813bebaa64164929824e3740ec..f999e1c958f63320ee0727ab9ad066e48444b3de 100644 (file)
@@ -97,10 +97,10 @@ struct minfo {
        };
 
 
-void attach_to_server();
-void serv_read();
-void serv_write();
-void get_config();
+void attach_to_server(int argc, char **argv);
+void serv_read(char *buf, int bytes);
+void serv_write(char *buf, int nbytes);
+void get_config(void);
 
 struct filterlist *filter = NULL;
 char roomnames[MAXROOMS][20];
@@ -111,37 +111,13 @@ struct config config;
 extern char bbs_home_directory[];
 extern int home_specified;
 
-int struncmp(lstr,rstr,len)
-char lstr[],rstr[];
-int len; {
-       int pos = 0;
-       char lc,rc;
-       while (pos<len) {
-               lc=tolower(lstr[pos]);
-               rc=tolower(rstr[pos]);
-               if ((lc==0)&&(rc==0)) return(0);
-               if (lc<rc) return(-1);
-               if (lc>rc) return(1);
-               pos=pos+1;
-               }
-       return(0);
-       }
-
-/* redefine strucmp, just in case we're using an old version of citadel.h
- * that has it as a separate routine
- */
-#ifndef strucmp
-#undef strucmp
-#endif
-#define strucmp(lstr,rstr) struncmp(lstr,rstr,32767)
-
 
 #ifdef NO_STRERROR
 /*
  * replacement strerror() for systems that don't have it
  */
-char *strerror(e)
-int e; {
+char *strerror(int e)
+{
        static char buf[32];
 
        sprintf(buf,"errno = %d",e);
@@ -150,8 +126,8 @@ int e; {
 #endif
 
 
-void strip_trailing_whitespace(buf)
-char buf[]; {
+void strip_trailing_whitespace(char *buf)
+{
        while(isspace(buf[strlen(buf)-1]))
                buf[strlen(buf)-1]=0;
        }
@@ -161,7 +137,7 @@ char buf[]; {
  * for performance optimization, netproc loads the list of room names (and
  * their corresponding directory names, if applicable) into a table in memory.
  */
-int load_roomnames() {
+int load_roomnames(void) {
        FILE *fp;
        struct quickroom qbuf;
        int i;
@@ -186,7 +162,7 @@ int load_roomnames() {
  * as we learn more about the network from incoming messages, and write
  * the table back to disk when we're done.
  */
-int load_syslist() {
+int load_syslist(void) {
        FILE *fp;
        struct syslist *stemp;
        char insys = 0;
@@ -249,12 +225,12 @@ int load_syslist() {
 /* now we have to set up two "special" nodes on the list: one
  * for the local node, and one for an Internet gateway
  */
-void setup_special_nodes() {
+void setup_special_nodes(void) {
        struct syslist *stemp,*slocal;
 
        slocal = NULL;
        for (stemp=slist; stemp!=NULL; stemp=stemp->next) {
-               if (!strucmp(stemp->s_name,config.c_nodename)) slocal=stemp;
+               if (!strcasecmp(stemp->s_name,config.c_nodename)) slocal=stemp;
                }
        if (slocal==NULL) {
                slocal =(struct syslist *)malloc(sizeof(struct syslist));
@@ -270,7 +246,7 @@ void setup_special_nodes() {
 
        slocal = NULL;
        for (stemp=slist; stemp!=NULL; stemp=stemp->next) {
-               if (!strucmp(stemp->s_name,"internet")) slocal=stemp;
+               if (!strcasecmp(stemp->s_name,"internet")) slocal=stemp;
                }
        if (slocal==NULL) {
                slocal =(struct syslist *)malloc(sizeof(struct syslist));
@@ -290,7 +266,7 @@ void setup_special_nodes() {
 /*
  * here's the routine to write the table back to disk.
  */
-void rewrite_syslist() {
+void rewrite_syslist(void) {
        struct syslist *stemp;
        FILE *newfp;
        long now;
@@ -298,7 +274,7 @@ void rewrite_syslist() {
        time(&now);
        newfp=fopen("network/mail.sysinfo","w");
        for (stemp=slist; stemp!=NULL; stemp=stemp->next) {
-               if (!strucmp(stemp->s_name,config.c_nodename)) {
+               if (!strcasecmp(stemp->s_name,config.c_nodename)) {
                        time(&stemp->s_lastcontact);
                        strcpy(stemp->s_type,"bin");
                        strcpy(stemp->s_humannode,config.c_humannode);
@@ -335,8 +311,8 @@ void rewrite_syslist() {
 /* call this function with the node name of a system and it returns a pointer
  * to its syslist structure.
  */
-struct syslist *get_sys_ptr(sysname)
-char *sysname; {
+struct syslist *get_sys_ptr(char *sysname)
+{
        static char sysnambuf[16];
        static struct syslist *sysptrbuf = NULL;
        struct syslist *stemp;
@@ -359,7 +335,7 @@ char *sysname; {
 /*
  * make sure only one copy of netproc runs at a time, using lock files
  */
-int set_lockfile() {
+int set_lockfile(void) {
        FILE *lfp;
        int ok = 1;
        int onppid;
@@ -390,7 +366,7 @@ int set_lockfile() {
        return(0);
        }
 
-void remove_lockfile() {
+void remove_lockfile(void) {
        unlink(LOCKFILE);
        }
 
@@ -401,14 +377,14 @@ void remove_lockfile() {
  * The cleanup() routine makes a check to ensure it's not reentering, in
  * case the ipc module looped it somehow.
  */
-void nq_cleanup(e)
-int e; {
+void nq_cleanup(int e)
+{
        remove_lockfile();
        exit(e);
        }
 
-void cleanup(e)
-int e; {
+void cleanup(int e)
+{
        static int nested = 0;
 
        alarm(30);
@@ -422,15 +398,15 @@ int e; {
  * client-side IPC modules expect logoff() to be defined.  They call logoff()
  * when a problem connecting or staying connected to the server occurs.
  */
-void logoff(e)
-int e; {
+void logoff(int e)
+{
        cleanup(e);
        }
 
 /*
  * If there is a kill file in place, this function will process it.
  */
-void load_filterlist() {
+void load_filterlist(void) {
        FILE *fp;
        struct filterlist *fbuf;
        char sbuf[256];
@@ -467,34 +443,34 @@ void load_filterlist() {
        }
 
 /* returns 1 if user/message/room combination is in the kill file */
-int is_banned(k_person,k_room,k_system)
-char *k_person,*k_room,*k_system; {
+int is_banned(char *k_person, char *k_room, char *k_system)
+{
        struct filterlist *fptr;
 
        for (fptr=filter; fptr!=NULL; fptr=fptr->next) if (
-        ((!strucmp(fptr->f_person,k_person))||(!strcmp(fptr->f_person,"*")))
+        ((!strcasecmp(fptr->f_person,k_person))||(!strcmp(fptr->f_person,"*")))
        &&
-        ((!strucmp(fptr->f_room,k_room))||(!strcmp(fptr->f_room,"*")))
+        ((!strcasecmp(fptr->f_room,k_room))||(!strcmp(fptr->f_room,"*")))
        &&
-        ((!strucmp(fptr->f_system,k_system))||(!strcmp(fptr->f_system,"*")))
+        ((!strcasecmp(fptr->f_system,k_system))||(!strcmp(fptr->f_system,"*")))
        ) return(1);
 
        return(0);
        }
 
-int get_sysinfo_type(name)     /* determine routing from sysinfo file */
-char name[]; {
+int get_sysinfo_type(char *name)       /* determine routing from sysinfo file */
+             {
        struct syslist *stemp;
 GETSN: for (stemp=slist; stemp!=NULL; stemp=stemp->next) {
-           if (!strucmp(stemp->s_name,name)) {
-               if (!strucmp(stemp->s_type,"use")) {
+           if (!strcasecmp(stemp->s_name,name)) {
+               if (!strcasecmp(stemp->s_type,"use")) {
                        strcpy(name,stemp->s_nexthop);
                        goto GETSN;
                        }
-               if (!strucmp(stemp->s_type,"bin")) {
+               if (!strcasecmp(stemp->s_type,"bin")) {
                        return(M_BINARY);
                        }
-               if (!strucmp(stemp->s_type,"uum")) {
+               if (!strcasecmp(stemp->s_type,"uum")) {
                        return(M_INTERNET);
                        }
                }
@@ -504,9 +480,8 @@ GETSN:      for (stemp=slist; stemp!=NULL; stemp=stemp->next) {
        }
 
 
-void fpgetfield(fp,string)
-FILE *fp;
-char string[]; {
+void fpgetfield(FILE *fp, char *string)
+{
        int a,b;
 
        strcpy(string,"");
@@ -528,9 +503,8 @@ char string[]; {
  * Load all of the fields of a message, except the actual text, into a
  * table in memory (so we know how to process the message).
  */
-void msgfind(msgfile,buffer)
-char *msgfile;
-struct minfo *buffer; {
+void msgfind(char *msgfile, struct minfo *buffer)
+{
        int b,e,mtype,aflag;
        char bbb[1024];
        char userid[1024];
@@ -598,9 +572,9 @@ END:        if (buffer->I==0L) buffer->I=buffer->T;
        fclose(fp);
        }
 
-void ship_to(filenm,sysnm)     /* send spool file filenm to system sysnm */
-char *filenm;
-char *sysnm; {
+void ship_to(char *filenm, char *sysnm)        /* send spool file filenm to system sysnm */
+             
+             {
        char sysflnm[100];
        char commbuf1[100];
        char commbuf2[100];
@@ -622,8 +596,8 @@ char *sysnm; {
 /*
  * proc_file_transfer()  -  handle a simple file transfer packet
  */
-void proc_file_transfer(tname)
-char *tname; { /* name of temp file containing the whole message */
+void proc_file_transfer(char *tname)
+{      /* name of temp file containing the whole message */
        char buf[128];
        char dest_dir[32];
        FILE *tfp,*uud;
@@ -640,7 +614,7 @@ char *tname; {      /* name of temp file containing the whole message */
                if (a!='M') {
                        fpgetfield(tfp,buf);
                        if (a=='O') for (b=0; b<MAXROOMS; ++b) {
-                               if (!strucmp(buf,roomnames[b]))
+                               if (!strcasecmp(buf,roomnames[b]))
                                        strcpy(dest_dir,roomdirs[b]);
                                }
                        }
@@ -672,8 +646,8 @@ char *tname; {      /* name of temp file containing the whole message */
 
 
 /* send a bounce message */
-void bounce(bminfo)
-struct minfo *bminfo; {
+void bounce(struct minfo *bminfo)
+{
 
        FILE *bounce;
        char bfilename[64];
@@ -714,7 +688,7 @@ struct minfo *bminfo; {
 /*
  * process incoming files in ./network/spoolin
  */
-void inprocess() {
+void inprocess(void) {
        FILE *fp,*message,*testfp,*ls;
        static struct minfo minfo;
        struct recentmsg recentmsg;
@@ -813,7 +787,7 @@ NXMSG:      /* Seek to the beginning of the next message */
                printf("\n");
                }
        fflush(stdout);
-       if (!strucmp(minfo.D,FQDN)) strcpy(minfo.D,NODENAME);
+       if (!strcasecmp(minfo.D,FQDN)) strcpy(minfo.D,NODENAME);
 
        /* this routine updates our info on the system that sent the message */
        stemp = get_sys_ptr(minfo.N);
@@ -828,7 +802,7 @@ NXMSG:      /* Seek to the beginning of the next message */
                strcpy(slist->s_nexthop,minfo.nexthop);
                time(&slist->s_lastcontact);
                }
-       else if ((stemp == NULL) && (!strucmp(minfo.N,minfo.nexthop))) {
+       else if ((stemp == NULL) && (!strcasecmp(minfo.N,minfo.nexthop))) {
                /* add neighbor system to map */
                printf("Adding neighbor system <%s> to map\n", slist->s_name);
                sprintf(aaa,"%s/network/systems/%s",bbs_home_directory,minfo.N);
@@ -854,7 +828,7 @@ NXMSG:      /* Seek to the beginning of the next message */
                }
 
        /* route the message if necessary */
-       if ((strucmp(minfo.D,NODENAME))&&(minfo.D[0]!=0)) { 
+       if ((strcasecmp(minfo.D,NODENAME))&&(minfo.D[0]!=0)) { 
                a = get_sysinfo_type(minfo.D);
                printf("netproc: routing message to system <%s>\n",minfo.D);
                fflush(stdout);
@@ -880,14 +854,14 @@ NXMSG:    /* Seek to the beginning of the next message */
                }
 
        /* check to see if it's a file transfer */
-       else if (!struncmp(minfo.S,"FILE",4)) {
+       else if (!strncasecmp(minfo.S,"FILE",4)) {
                proc_file_transfer(tname);
                }
 
        /* otherwise process it as a normal message */
        else {
 
-               if (!strucmp(minfo.R, "postmaster")) {
+               if (!strcasecmp(minfo.R, "postmaster")) {
                        strcpy(minfo.R, "");
                        strcpy(minfo.C, "Aide");
                        }
@@ -970,9 +944,9 @@ ENDSTR:     fclose(fp);
     }
 
 
-int checkpath(path,sys)        /* Checks to see whether its ok to send */
-char path[];           /* Returns 1 for ok, send message       */
-char sys[]; {          /* Returns 0 if message already there   */
+int checkpath(char *path, char *sys)   /* Checks to see whether its ok to send */
+                       /* Returns 1 for ok, send message       */
+            {          /* Returns 0 if message already there   */
        int a;
        char sys2[512];
        strcpy(sys2,sys);
@@ -990,10 +964,8 @@ char sys[]; {              /* Returns 0 if message already there   */
 /*
  * implement split horizon algorithm
  */
-int ismsgok(mpos,mmfp,sysname)
-long mpos;
-FILE *mmfp;
-char *sysname; {
+int ismsgok(long int mpos, FILE *mmfp, char *sysname)
+{
        int a;
        int ok = 0;             /* fail safe - no path, don't send it */
        char fbuf[256];
@@ -1014,10 +986,10 @@ char *sysname; {
        return(ok);
        }
 
-int spool_out(cmlist,destfp,sysname)   /* spool list of messages to a file */
-struct msglist *cmlist;                        /* returns # of msgs spooled */
-FILE *destfp; 
-char *sysname;
+int spool_out(struct msglist *cmlist, FILE *destfp, char *sysname)     /* spool list of messages to a file */
+                                               /* returns # of msgs spooled */
+              
+              
 {
        struct msglist *cmptr;
        FILE *mmfp;
@@ -1038,7 +1010,7 @@ char *sysname;
        for (cmptr=cmlist; cmptr!=NULL; cmptr=cmptr->next) {
 
                /* make sure we're in the correct room... */
-               if (strucmp(curr_rm, cmptr->m_rmname)) {
+               if (strcasecmp(curr_rm, cmptr->m_rmname)) {
                        sprintf(buf, "GOTO %s", cmptr->m_rmname);
                        serv_puts(buf);
                        serv_gets(buf);
@@ -1101,8 +1073,8 @@ char *sysname;
        return(msgs_spooled);
        }
 
-void outprocess(sysname) /* send new room messages to sysname */
-char *sysname; {
+void outprocess(char *sysname) /* send new room messages to sysname */
+               {
        char sysflnm[64];
        char srmname[32];
        char shiptocmd[128];
@@ -1139,7 +1111,7 @@ char *sysname; {
                strip_trailing_whitespace(rmptr->rm_name);
                rmptr->rm_lastsent = atol(lbuf);
                if (crmlist==NULL) crmlist=rmptr;
-               else if (!strucmp(rmptr->rm_name,"control")) {
+               else if (!strcasecmp(rmptr->rm_name,"control")) {
                        /* control has to be first in room list */
                        rmptr->next = crmlist;
                        crmlist = rmptr;
@@ -1248,7 +1220,7 @@ char *sysname; {
 /*
  * Connect netproc to the Citadel server running on this computer.
  */
-void np_attach_to_server() {
+void np_attach_to_server(void) {
        char buf[256];
        char portname[8];
        char *args[] = { "netproc", "localhost", NULL, NULL } ;
@@ -1273,9 +1245,7 @@ void np_attach_to_server() {
 /*
  * main
  */
-void main(argc,argv)
-int argc;
-char *argv[];
+void main(int argc, char **argv)
 {
        char allst[32];
        FILE *allfp;