|
|
1.1 ! root 1: /* semfile.c */ ! 2: ! 3: /* $Id: semfile.c,v 1.2 2006/09/02 01:59:26 deuce Exp $ */ ! 4: ! 5: /**************************************************************************** ! 6: * @format.tab-size 4 (Plain Text/Source Code File Header) * ! 7: * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * ! 8: * * ! 9: * Copyright 2006 Rob Swindell - http://www.synchro.net/copyright.html * ! 10: * * ! 11: * This program is free software; you can redistribute it and/or * ! 12: * modify it under the terms of the GNU General Public License * ! 13: * as published by the Free Software Foundation; either version 2 * ! 14: * of the License, or (at your option) any later version. * ! 15: * See the GNU General Public License for more details: gpl.txt or * ! 16: * http://www.fsf.org/copyleft/gpl.html * ! 17: * * ! 18: * Anonymous FTP access to the most recent released source is available at * ! 19: * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net * ! 20: * * ! 21: * Anonymous CVS access to the development source and modification history * ! 22: * is available at cvs.synchro.net:/cvsroot/sbbs, example: * ! 23: * cvs -d :pserver:[email protected]:/cvsroot/sbbs login * ! 24: * (just hit return, no password is necessary) * ! 25: * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src * ! 26: * * ! 27: * For Synchronet coding style and modification guidelines, see * ! 28: * http://www.synchro.net/source.html * ! 29: * * ! 30: * You are encouraged to submit any modifications (preferably in Unix diff * ! 31: * format) via e-mail to [email protected] * ! 32: * * ! 33: * Note: If this box doesn't appear square, then you need to fix your tabs. * ! 34: ****************************************************************************/ ! 35: ! 36: #include <string.h> ! 37: ! 38: #include "semfile.h" ! 39: #include "filewrap.h" ! 40: #include "dirwrap.h" ! 41: #include "genwrap.h" ! 42: ! 43: #if !defined(NO_SOCKET_SUPPORT) ! 44: #include "sockwrap.h" ! 45: #endif ! 46: ! 47: /****************************************************************************/ ! 48: /* This function compares a single semaphore file's */ ! 49: /* date/time stamp (if the file exists) against the passed time stamp (t) */ ! 50: /* updating the time stamp to the latest dated semaphore file and returning */ ! 51: /* TRUE if any where newer than the initial value. */ ! 52: /****************************************************************************/ ! 53: BOOL DLLCALL semfile_check(time_t* t, const char* fname) ! 54: { ! 55: time_t ft; ! 56: ! 57: if(*t==0) /* uninitialized */ ! 58: *t=time(NULL); ! 59: ! 60: if((ft=fdate(fname))==-1 || ft<=*t) ! 61: return(FALSE); ! 62: ! 63: *t=ft; ! 64: return(TRUE); ! 65: } ! 66: ! 67: /****************************************************************************/ ! 68: /* This function goes through a list of semaphore files, comparing the file */ ! 69: /* date/time stamp (if the file exists) against the passed time stamp (t) */ ! 70: /* updating the time stamp to the latest dated semaphore file and returning */ ! 71: /* a pointer to the filename if any where newer than the initial timestamp. */ ! 72: /****************************************************************************/ ! 73: char* DLLCALL semfile_list_check(time_t* t, str_list_t filelist) ! 74: { ! 75: char* signaled=NULL; ! 76: size_t i; ! 77: ! 78: for(i=0;filelist[i]!=NULL;i++) ! 79: if(semfile_check(t, filelist[i])) ! 80: signaled = filelist[i]; ! 81: ! 82: return(signaled); ! 83: } ! 84: ! 85: str_list_t DLLCALL semfile_list_init(const char* parent, ! 86: const char* action, const char* service) ! 87: { ! 88: char path[MAX_PATH+1]; ! 89: char hostname[128]; ! 90: char* p; ! 91: str_list_t list; ! 92: ! 93: if((list=strListInit())==NULL) ! 94: return(NULL); ! 95: SAFEPRINTF2(path,"%s%s",parent,action); ! 96: strListPush(&list,path); ! 97: SAFEPRINTF3(path,"%s%s.%s",parent,action,service); ! 98: strListPush(&list,path); ! 99: if(gethostname(hostname,sizeof(hostname))==0) { ! 100: SAFEPRINTF3(path,"%s%s.%s",parent,action,hostname); ! 101: strListPush(&list,path); ! 102: SAFEPRINTF4(path,"%s%s.%s.%s",parent,action,hostname,service); ! 103: strListPush(&list,path); ! 104: if((p=strchr(hostname,'.'))!=NULL) { ! 105: *p=0; ! 106: SAFEPRINTF3(path,"%s%s.%s",parent,action,hostname); ! 107: strListPush(&list,path); ! 108: SAFEPRINTF4(path,"%s%s.%s.%s",parent,action,hostname,service); ! 109: strListPush(&list,path); ! 110: } ! 111: } ! 112: ! 113: return(list); ! 114: } ! 115: ! 116: void DLLCALL semfile_list_add(str_list_t* filelist, const char* path) ! 117: { ! 118: strListPush(filelist, path); ! 119: } ! 120: ! 121: void DLLCALL semfile_list_free(str_list_t* filelist) ! 122: { ! 123: strListFree(filelist); ! 124: } ! 125: ! 126: BOOL DLLCALL semfile_signal(const char* fname, const char* text) ! 127: { ! 128: int file; ! 129: #if !defined(NO_SOCKET_SUPPORT) ! 130: char hostname[128]; ! 131: ! 132: if(text==NULL && gethostname(hostname,sizeof(hostname))==0) ! 133: text=hostname; ! 134: #endif ! 135: if((file=open(fname,O_CREAT|O_WRONLY))<0) /* use sopen instead? */ ! 136: return(FALSE); ! 137: if(text!=NULL) ! 138: write(file,text,strlen(text)); ! 139: /* use utime() for force the time-stamp to that of the local system? */ ! 140: close(file); ! 141: return(TRUE); ! 142: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.