This is domessage.c in view mode; [Download] [Up]
/* domessage.c: * * this handles each incoming message * * (c) Copyright 1988, 1989, 1990 Jim Frost. All Rights Reserved. Please see * the accompanying file "Copyright" for more information. */ #include "Copyright" #include "config.h" #include "msend.h" #include "patchlevel" extern char *sys_errlist[]; extern int errno; extern short doroute, dobroadcast; /* in case we somehow get caught in an inconsistent state, we * kill ourselves after an arbitrary time. */ static void suicide() { error("child killed after lifetime expired"); die(1); } /* handle the incoming message */ void domessage(s) int s; { struct simsg si; struct rimsg ri; extern int errno; char localhost[MAXHOSTNAME+1]; char tmphost[MAXHOSTNAME+1]; struct hostent *hp; for (;;) { /* anything we say can and will be used against us in the court of * law, so it's a good idea to keep our mouth shut except with the * right people. In other words, nobody but root and the owner * should be able to see message files. */ umask(006); /* this is our guarantee that we won't have processes sitting in * funny states for very long. unfortunately it can also cause * valid connections to die if the user ignores them for long * enough, but we reset the timer every time there's a packet. */ alarm(LIFETIME); signal(SIGALRM,suicide); gethostname(tmphost,MAXHOSTNAME); if ((hp = gethostbyname(tmphost)) == NULL); (void) strncpy(localhost,hp->h_name,MAXHOSTNAME); /* hello? what do you want? */ recvmessage(s,&si); /* look to see if we are supposed to route this to somewhere. if so, * then do it. */ if (striphost(si.taddr,si.tohost) != NULL) { #ifdef ROUTE if(doroute) sendmessage(&si,&ri,si.mode); /* route the message and get reply */ /* routing is disabled so return an error message */ else { #endif ri.h.errno= RE_NOROUTE; sprintf(ri.msg,"%s: Message routing is disabled at this host",localhost); #ifdef ROUTE } #endif } else if (si.mode & SM_VERSION) { ri.h.errno= RE_OK; sprintf(ri.msg,"%s: msendd version %s patchlevel %s %s", localhost,VERSION,PATCHLEVEL,Copyright); } else if (si.msg[0] == '\0') { /* null messages are ignored */ ri.h.errno= RE_OK; ri.msg[0]= '\0'; } else if (si.mode & SM_BROADCAST) { #ifdef DBROADCAST /* broadcast to everyone in utmp */ if (dobroadcast) { broadcast(&si); ri.h.errno= RE_OK; ri.msg[0]= '\0'; } else { #endif ri.h.errno= RE_NOBROAD; sprintf(ri.msg,"%s: Broadcasting is disabled at this host",localhost); #ifdef DBROADCAST } #endif } else { /* write to a single user or tty */ switch (writeuser(&si)) { case RE_OK : ri.h.errno= RE_OK; ri.msg[0]= '\0'; break; case RE_NOMSGS : ri.h.errno= RE_NOMSGS; sprintf(ri.msg,"%s@%s: User's messages are off, try mail instead", si.taddr,localhost); break; case RE_NOTTHERE : ri.h.errno= RE_NOTTHERE; sprintf(ri.msg,"%s@%s: User not found",si.taddr,localhost); break; case RE_NOUSER : ri.h.errno= RE_NOUSER; sprintf(ri.msg,"%s@%s: No such user",si.taddr,localhost); break; case RE_SYSERR : ri.h.errno= RE_SYSERR; strcpy(ri.msg,sys_errlist[errno]); break; default : error("internal error (this cannot happen!)"); blderr(&ri,RE_INTERR,"Internal error in receiving daemon\n"); } } sendreply(s,&ri,si.mode); if ((si.mode & SM_CLOSE) || (ri.h.errno != RE_OK)) exit(0); } }
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.