home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: SysTools / SysTools.zip / pmcron03.zip / server.h < prev    next >
C/C++ Source or Header  |  1996-05-09  |  15KB  |  268 lines

  1. /* Copyright (c) 1995 Florian Große-Coosmann, RCS section at the eof */
  2. #ifndef SERVER_INCLUDED
  3. #define SERVER_INCLUDED
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <setjmp.h>
  7. #include <time.h>
  8. #include "common.h"
  9. #include "cron_id.h"
  10.  
  11. #define WAKEUP 3600                     /* awake every hour to compute the   */
  12.                                         /* next job time (value in seconds)  */
  13. #define MAX_CRONFILESIZE 0x20000        /* don't allow Crontab files larger  */
  14.                                         /* than this value, I think this is  */
  15.                                         /* enough :-)                        */
  16. #define MAX_IO 0x400                    /* pipe's communication size         */
  17. #define WINDOW_REFRESH  ((ULONG) 0xC302C302) /* magic number for WM_USER     */
  18.  
  19. /* cronmain.c */
  20. #define REWRITE_SCREEN        0x00000001ul
  21. #define REWRITE_FLAGS         0x00000002ul
  22. #define REWRITE_MAXIMUM       0x00000004ul
  23. #define REWRITE_CURRENT       0x00000008ul
  24. #define REWRITE_THRESHOLD     0x00000010ul
  25. #define REWRITE_OUTPUTPATH    0x00000020ul
  26. #define REWRITE_TCPIP_ALLOW   0x00000040ul
  27. #define REWRITE_CRONFILENAME  0x00000080ul
  28. #define REWRITE_LANGUAGE      0x00000100ul
  29. #define REWRITE_COLORS        0x00000200ul
  30. #define REWRITE_FONT          0x00000400ul
  31. #define REWRITE_DATE          0x00000800ul
  32.  
  33. #define PRG_OUTPUT_IS_NUL     0x00000001ul
  34. #define PRG_RUNATSTARTUP      0x00000002ul
  35. #define PRG_RUNATEXIT         0x00000004ul
  36. #define PRG_ALLOW_LAN         0x00000008ul
  37. #define PRG_ALLOW_TCPIP       0x00000010ul
  38. #define PRG_START_MINIMIZED   0x00000020ul
  39. #define PRG_START_MAXIMIZED   0x00000040ul
  40. #define PRG_ALLFLAGS          ((PRG_START_MAXIMIZED << 1) - 1)
  41.  
  42. #define ENGLISH                    0    /* 0 is the default value, don't chg.*/
  43. #define GERMAN                 10000
  44. #define FRENCH                 20000
  45. typedef struct {
  46.    USHORT   code;                       /* ENGLISH, GERMAN, etc              */
  47.    char    *LANG_descr;                 /* values codes from env-var LANG    */
  48.    char    *description;                /* full description                  */
  49. } LANGUAGE;
  50.  
  51. extern HAB   hab;                       /* these four values are for the     */
  52. extern HMQ   hmq;                       /* PM version only                   */
  53. extern HWND  hwndFrame;
  54. extern HWND  hwndClient;
  55.  
  56. extern char   CurrFilename[];           /* user modifiable values            */
  57. extern ULONG  ProgramFlags;
  58. extern RECTL  FrameRect,SaveFrameRect;
  59. extern ULONG  Threshold;
  60. extern UCHAR  MaxOutputs;
  61. extern UCHAR  CurrOutput;
  62. extern CHAR   Crontabs[];
  63. extern CHAR   TCPIP_Allow[];
  64. extern CHAR   OutputPath[CCHMAXPATH];
  65. extern USHORT Language;                 /* LANGUAGE.code                     */
  66. extern USHORT CurrentLanguage;
  67.                                         /* Language Specific Identifier:     */
  68. #define NLS(x) ((USHORT) ((USHORT) (x) + CurrentLanguage))
  69. #define NONLS(x) ((USHORT) ((USHORT) (x) % 10000))
  70.  
  71. extern LONG   Colors[4];                /* used colors, see following codes  */
  72. #define MYCLR_SYSFOREGROUND   0         /* foreground used by system         */
  73. #define MYCLR_FOREGROUND      1         /* currently used foreground         */
  74. #define MYCLR_SYSBACKGROUND   2         /* background used by system         */
  75. #define MYCLR_BACKGROUND      3         /* currently used background         */
  76. extern char Fontname[2 * FACESIZE + sizeof("10.")];   /* saveable font name  */
  77. extern ULONG LastDayStarted;            /* last day crond has run            */
  78.  
  79. extern const LANGUAGE Languages[];
  80. extern const unsigned LanguagesCount;   /* Number of Languages               */
  81.  
  82. extern int   GlobalStop;                /* flag: shall we stop the program?  */
  83. extern int   TCPIPAvail;                /* is TCP/IP available?              */
  84. extern int   RunningUnderPM;            /* the name of the flag says it      */
  85. extern ULONG ReWritePrfFlags;           /* flags what has changed            */
  86. extern CHAR  DefIOPath[CCHMAXPATH];     /* path of the program               */
  87. extern char  Delims[];                  /* path delimiter                    */
  88. extern FILE *out;                       /* current output file               */
  89. extern int   cronhandle;                /* the handle of the Crontabs file   */
  90. extern HEV   CronSem;                   /* event semaphore to show the       */
  91.                                         /* cron daemon that things have been */
  92.                                         /* changed                           */
  93.  
  94. #define printf()                        /* no printf's or puts's! they won't */
  95. #define puts()                          /* output anything, use Dprintf or   */
  96. #ifdef DEBUG                            /* Dputs instead                     */
  97. extern FILE *DebugFile;
  98. void Dputs(char *s);
  99. void Dprintf(char *fmt,...);
  100. #else
  101. #define Dputs(s)
  102. #define Dprintf(s)
  103. #endif
  104. extern void (*NewProgramStatus)(ULONG NewStatus);  /* show new program state */
  105. extern void (*NewStartTime)(time_t time); /* show next job start time        */
  106. extern void (*NewOutputFile)(void);     /* show the display output file      */
  107. extern void (*JobsModified)(void);      /* advise a changed job list         */
  108. extern void (*StopPM)(void);            /* stop PM window                    */
  109. extern void (*Error)(const char *s,HWND dummy); /* show error string         */
  110. extern void (*FatalError)(const char *s,HWND dummy);  /* show error and die  */
  111. extern void (*Stop)(int code);          /* signal handler                    */
  112. extern int SetJumpEnabled;              /* flag: can we use longjmp          */
  113. extern jmp_buf PrgEnd;                  /* jump if signaled                  */
  114.  
  115. void FullName(char *Filename);          /* make a fully qualified pathname   */
  116. void AppendPathComponent(char *path,const char *component);
  117. int CheckOutputPath(char *s);           /* is output path OK?                */
  118. int NextOutputFile(int Append);         /* use next output file              */
  119. int ReReadCrontabs(char *s);            /* (re)read the Crontabs file        */
  120. int ReWritePrf(void);                   /* rewrite changed profile data      */
  121. const char *Get(ULONG IDS);             /* get the requested string from     */
  122.                                         /* the resource appendix and buffer  */
  123. void GetTime(char *buf,size_t bufsize,time_t t);   /* return time t in buf   */
  124. const char *GetTimeString(void);        /* return locally buffered GetTime   */
  125.                                         /* with " : "                        */
  126. void BlockOutput(void);                 /* use the output file exclusively   */
  127. void UnBlockOutput(void);               /* release the output file           */
  128. void Message(const char *fmt,...);      /* print(f) to the output file       */
  129. const char *GetError(int errnocode);    /* return a description of the errno */
  130.                                         /* WITHOUT trailing newlines         */
  131. void Perror(const char *s);             /* perror to output                  */
  132. const char *ResolvOS2Err(ULONG msgno,const char *name,...); /* resolve the   */
  133.                                         /* OS/2-error msgno und return the   */
  134.                                         /* appropriate message string        */
  135. void ChildDies(int code);
  136.  
  137. /* cron_det.c */
  138. void DetachedNewProgramStatus(ULONG NewStatus); /* see NewProgramStatus      */
  139. void DetachedNewStartTime(time_t time); /* see NewStartTime                  */
  140. void DetachedNewOutputFile(void);       /* see NewOutputFile                 */
  141. void DetachedJobsModified(void);        /* see JobsModified                  */
  142. void DetachedStopPM(void);              /* see StopPM                        */
  143. void DetachedError(const char *s,HWND dummy);   /* see Error                 */
  144. void DetachedFatalError(const char *s,HWND dummy); /* see FatalError         */
  145. void DetachedStop(int code);            /* see Stop                          */
  146.  
  147. /* cron_pm.c */
  148. void PMError(const char *s,HWND owner); /* see Error                         */
  149. void PMFatalError(const char *s,HWND owner); /* see FatalError               */
  150. void WinError(HWND owner);              /* show GPI error                    */
  151. void FatalWinError(HWND owner);         /* show GPI error and die            */
  152. void SetPosOfWindow(HWND framewin);     /* save current window pos. and size */
  153. MRESULT EXPENTRY ClientWndProc(HWND hwnd,ULONG msg,MPARAM mp1,MPARAM mp2);
  154. void PMNewProgramStatus(ULONG NewStatus); /* see NewProgramStatus            */
  155. void PMNewStartTime(time_t time);       /* see NewStartTime                  */
  156. void PMNewOutputFile(void);             /* see NewOutputFile                 */
  157. void PMJobsModified(void);              /* see JobsModified                  */
  158. void PMStopPM(void);                    /* see StopPM                        */
  159. void PMStop(int code);                  /* see Stop                          */
  160.  
  161. /* server.c */
  162. extern char  PipeName[];                /* the name of the communication pipe*/
  163. extern int   pipehandle;                /* the handle of the pipe            */
  164. int IsPipeThere(void);                  /* check for existing pipe           */
  165. void WaitClientDisConnect(void);        /* wait for the client to release    */
  166.                                         /* the pipe                          */
  167. int ReadBlockedMsgPipe(volatile int *hf,char *buffer,size_t maxbuffer,
  168.                                                              size_t minbuffer);
  169. int ScanNumber(char *s,ULONG *num);     /* scan s for a number >= 0 into num */
  170. void ProcessRequest(volatile int *hf,char *name);  /* deal with pipe requests*/
  171.  
  172. /* tables.c */
  173. typedef struct _LIST_ENTRY {
  174.    struct _LIST_ENTRY  *next;
  175.    char                *s;              /* command line with time            */
  176.    const char          *StartCmd;       /* points to s after the time string */
  177.    time_t               NextStartTime;  /* -1 = not in the next 24 hours     */
  178.    unsigned long long   Minute;         /* bitsets                           */
  179.    unsigned             Hour;           /* bitsets                           */
  180.    unsigned             Day;            /* bitsets                           */
  181.    unsigned             Month;          /* bitsets                           */
  182.    unsigned             WeekDay;        /* bitsets                           */
  183.    unsigned             AtStartup:1;    /* job must run at start of cron     */
  184.    unsigned             AtExit:1;       /* job must run at exit of cron      */
  185.    unsigned             Once:1;         /* run only once, then delete job    */
  186.    unsigned             Deletable:1;    /* job is about to be deleted        */
  187.    unsigned             IsComment:1;    /* no job, the line is a comment     */
  188.    unsigned             Daily:1;        /* run job daily                     */
  189. } LIST_ENTRY;
  190.  
  191. extern HMTX ThreadSem;                  /* exclusive sem for accessing the   */
  192.                                         /* job table                         */
  193. extern time_t AutoDisConnect;           /* timeout for the pipe client       */
  194. extern time_t AutoCloseSocket;          /* timeout for the socket client     */
  195. extern LIST_ENTRY ListHead;             /* start the the current table       */
  196. extern ULONG EditEntryNumber;           /* No. of job which is edited or -1  */
  197.  
  198. void BlockProcess(void);                /* use the table exclusively         */
  199. void UnBlockProcess(void);              /* release the table                 */
  200. LIST_ENTRY *LookupEntryNum(ULONG num,int AllowComment);  /* look for the num */
  201.                                         /* entry in the table, comment lines */
  202.                                         /* may be counted/looked for, too.   */
  203.                                         /* 1 based!!!!                       */
  204. int DeleteListEntry(LIST_ENTRY *entry,LIST_ENTRY *head); /* delete the entry */
  205.                                         /* off the list head                 */
  206. #define CL_FILE   1                     /* create list to write Crontabs file*/
  207. #define CL_USER   2                     /* create list for the user          */
  208. #define CL_PM     3                     /* create list for PM                */
  209. char *CreateList(int flag);             /* create a very long string with    */
  210.                                         /* all table entries delimited by    */
  211.                                         /* CR/LF pairs either with numbers   */
  212.                                         /* and without comment lines of      */
  213.                                         /* without numbers but with comments */
  214.                                         /* see CL_??? for details            */
  215. int DeleteEntryNum(ULONG num,char *replybuf);   /* delete job num, copy a    */
  216.                                         /* message to replybuf if successful */
  217. int NewEntry(char *line,size_t size,char *replybuf);  /* insert a new job    */
  218.                                         /* from line (length size, need not  */
  219.                                         /* to be 0-term.), fill reply on succ*/
  220. const char *ParseLine(const char *buf,size_t bufsize,size_t *start,size_t *len);
  221.                                         /* return next line from a buffer    */
  222. int ReadInFile(int handle,LIST_ENTRY *head); /* read in the complete file    */
  223.                                         /* into head                         */
  224. void CronDaemon(void *dummy);           /* thread procedure                  */
  225.  
  226. /* process.c */
  227. void EndProcess(int pid,int reason,int rc);  /* show rc, copy temp. file     */
  228. void StartProcess(LIST_ENTRY *job);     /* start a new job                   */
  229. int ReapChildren(void);                 /* EndProcess for every stoped job   */
  230. void ShowStillRunnings(void);           /* show not deleted temp. files      */
  231.  
  232. /* tcpip.c */
  233. extern volatile int CommSock;           /* currenty opened socket to a client*/
  234. void CheckTCPIPAvail(void);             /* checks the availability of TCP/IP */
  235.                                         /* and opens the main socket         */
  236. int ReadAllow(char *s);                 /* (re)read the TCP/IP allow file    */
  237. void SocketThread(void *dummy);         /* deals with TCP/IP connections     */
  238.  
  239. #endif  /* SERVER_INCLUDED */
  240.  
  241. /* RCS depending informations
  242.  *
  243.  * $Id: server.h 1.5 1995/10/18 09:46:10 Florian Rel $
  244.  *
  245.  * $Name: Version121 $
  246.  *
  247.  * $Log: server.h $
  248.  * Revision 1.5  1995/10/18 09:46:10  Florian
  249.  * Font, colors and window state and current date variables added.
  250.  * Added support of the French language.
  251.  *
  252.  * Revision 1.4  1995/08/03 07:44:26  Florian
  253.  * NLS supported (English and German)
  254.  *
  255.  * Revision 1.3  1995/03/15 09:07:34  Florian
  256.  * Some minor bugs fixed.
  257.  * TCP/IP support added.
  258.  *
  259.  * Revision 1.2  1995/02/20 12:53:23  Florian
  260.  * All dialogs are placed into a notebook.
  261.  * Some bugs fixed.
  262.  *
  263.  * Revision 1.1  1995/02/03 10:42:49  Florian
  264.  * Initial revision
  265.  *
  266.  *
  267.  */
  268.