]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Adding getvers to subrou.c
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Mon, 8 Jul 2024 19:46:07 +0000 (15:46 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Mon, 8 Jul 2024 19:46:07 +0000 (15:46 -0400)
app/mailled.c
lib/subrou.c
lib/subrou.h

index 91af41f07da71fe614a245c60c04c15c76cf2ab1..7e0f573efef38ed27790570dd02690d59db066c0 100644 (file)
@@ -4,8 +4,10 @@
 /*     Main SMTP Daemon                                */
 /*                                                     */
 /********************************************************/
-#include       <stdbool.h>
 #include       <stdlib.h>
+#include       <stdio.h>
+
+#include       "subrou.h"
 
 /*
 \f
@@ -38,10 +40,13 @@ proceed=true;
 while (proceed==true) {
   switch (phase) {
     case 0      :       //initialising process
+      (void) rou_modesubrou(true);
       break;
     case 1      :       //checking parameters
+      (void) fprintf(stderr,"JMPDBG Vers='%s'\n",rou_getversion());
       break;
     default     :       //end of task
+      (void) rou_modesubrou(false);
       proceed=false;
       break;
     }
index c4b862b52615eaa271b435cad0b858fc1340f900..f337ed6be939a6a3195c1ad9b2ce128bddaded15 100644 (file)
 /*     Module for low level subroutine                 */
 /*                                                     */
 /********************************************************/
+#include        <stdio.h>
+#include        <stdlib.h>
+#include        <string.h>
+#include        <syslog.h>
 
 #include       "subrou.h"
 
 
 //version definition 
 #define VERSION "0.1"
-#define RELEASE "4"
+#define RELEASE "5"
+
+//Public variables
+PUBLIC  int debug=0;            //debug level
+
+PUBLIC  _Bool foreground=false; //process is always started in background mode
+PUBLIC  char *rootdir=(char *)0;//working directory (debugging)
+PUBLIC  char  *appname;         //application "official" name
+
+//static variables
+static  _Bool modopen;          //boolean module open/close
+
+//Time offset (for debug purpose only)
+static time_t off64_time=(time_t)0;
+static time_t off_date=(time_t)0;
+/*
+^L
+*/
+/********************************************************/
+/*                                                      */
+/*      Returne the version number and application      */
+/*      name.                                           */
+/*                                                      */
+/********************************************************/
+const char *rou_getversion()
+
+{
+return VERSION"."RELEASE;
+}
+/*
+\f
+*/
+/********************************************************/
+/*                                                     */
+/*     Subroutine to log event on syslog               */
+/*                                                     */
+/********************************************************/
+void rou_valert(const int dlevel,const char *fmt,va_list ap)
+
+#define        DEBMAX  80
+
+{
+if (debug>=dlevel)
+  {
+  char *ptr;
+  char strloc[10000];
+
+  (void) memset(strloc,'\000',sizeof(strloc));
+  (void) vsnprintf(strloc,sizeof(strloc)-1,fmt,ap);
+  ptr=strloc;
+  if (foreground==true)
+    (void) fprintf(stderr,"%s\n",strloc);
+  else {
+    while (strlen(ptr)>DEBMAX) {
+      char locline[DEBMAX+10];
+  
+      (void) strncpy(locline,ptr,DEBMAX);
+      locline[DEBMAX]='\000';
+      (void) syslog(LOG_INFO,"%s",locline);
+      ptr +=DEBMAX;
+      } 
+    (void) syslog(LOG_INFO,"%s",ptr);
+    }
+  }
+}
+/*
+\f
+*/
+/********************************************************/
+/*                                                     */
+/*     Subroutine to log event on syslog               */
+/*                                                     */
+/********************************************************/
+void rou_alert(const int dlevel,const char *fmt,...)
+
+{
+va_list args;
+
+va_start(args,fmt);
+(void) rou_valert(dlevel,fmt,args);
+va_end(args);
+}
+/*
+^L
+*/
+/********************************************************/
+/*                                                      */
+/*     Procedure to "open" usager to module.           */
+/*      homework purpose                                */
+/*      return zero if everything right                 */
+/*                                                      */
+/********************************************************/
+int rou_opensubrou()
+
+{
+int status;
+
+status=0;
+if (modopen==false) {
+  debug=0;
+  foreground=false;
+  off64_time=(time_t)0;
+  off_date=(time_t)0;
+  if (appname!=(char *)0)
+    (void) free(appname);
+  appname=strdup(APPNAME);
+  if (rootdir!=(char *)0) {
+    (void) free(rootdir);
+    status=-1;          //Rootdir should be found as NULL
+    }
+  rootdir=strdup("");
+  (void) openlog(APPNAME,LOG_PID,LOG_DAEMON);
+  (void) rou_alert(0,"Starting: %s-%s",APPNAME,rou_getversion());
+  modopen=true;
+  }
+return status;
+}
+/*
+^L
+*/
+/********************************************************/
+/*                                                      */
+/*     Procedure to "open/close" module and do         */
+/*      homework purpose                                */
+/*      return zero if everything right                 */
+/*                                                      */
+/********************************************************/
+int rou_modesubrou(_Bool mode)
+
+{
+#define OPEP    "subrou.c:rou_modesubrou"
+
+int status;
+
+status=0;
+if (mode!=modopen) {
+  switch ((int)mode) {
+    case true     :
+      debug=0;
+      foreground=false;
+      off64_time=(time_t)0;
+      off_date=(time_t)0;
+      if (appname!=(char *)0)
+        (void) free(appname);
+      appname=strdup(APPNAME);
+      if (rootdir!=(char *)0) {
+        (void) free(rootdir);
+        status=-1;          //Rootdir should be found as NULL
+        }
+      rootdir=strdup("");
+      (void) openlog(APPNAME,LOG_PID,LOG_DAEMON);
+      (void) rou_alert(0,"Starting: %s-%s",APPNAME,rou_getversion());
+      break;
+    case false    :
+      (void) rou_alert(0,"Exiting: %s-%s",APPNAME,rou_getversion());
+      (void) closelog();
+      if (appname!=(char *)0) {
+        (void) free(appname);
+        appname=(char *)0;
+        }
+      if (rootdir!=(char *)0) {
+        (void) free(rootdir);
+        rootdir=(char *)0;
+        }
+      break;
+    default       :
+      (void) fprintf(stderr,"Calling %s with wrong mode='%d' (Bug?!):",
+                            OPEP,(int)mode);
+      status=-1;
+      break;
+    }
+  modopen=mode;
+  }
+return status;
+#undef  OPEP
+}
index 8ab12158c39624497259703f9211cd5d0ee57cde..5444a60e461243a34613cedb875ac07d4dc257fe 100644 (file)
@@ -8,8 +8,34 @@
 #define SUBROU
 
 #include        <linux/types.h>
+#include        <stdbool.h>
 #include       <stdarg.h>
 
+
 #define APPNAME "mailled"        //application name
 
+//---   Variables defined within subrou.c       ---------
+extern int             debug;  //application debug mode
+extern _Bool       foreground;  //process is in foreground mode
+
+extern char          *rootdir;  //application root directory
+extern char          *appname;  //application "official" name
+
+//---   Routines implemented within subrou.c    ---------
+
+//to display message on console (verbose mode) or
+//via syslog (LOG_INFO) using variable argument list macros
+void rou_valert(const int dlevel,const char *fmt,va_list ap);
+
+//to display message on console (verbose mode) or
+//via syslog (LOG_DAEMON)
+extern void rou_alert(const int dlevel,const char *fmt,...);
+
+//return program version
+extern const char *rou_getversion();
+
+//homework to be done before starting/stoping module.
+extern int rou_modesubrou(_Bool mode);
+
+#define PUBLIC                  //to specify public variable
 #endif