#--------------------------------------------------------------------
OBJS= \
modrec.o \
- unipar.o uniprc.o unisig.o \
+ unipar.o uniprc.o unisig.o unisoc.o \
subrou.o
objs : $(OBJS)
#Dependances
modrec.o: \
subrou.h \
+ uniprc.h \
+ unisig.h \
+ unisoc.h \
modrec.h modrec.c
unipar.o: \
subrou.h \
unisig.h unisig.c
+unisoc.o: \
+ subrou.h \
+ unisoc.h unisoc.c
+
subrou.o: \
subrou.h subrou.c
#--------------------------------------------------------------------
CC = gcc
LD = gcc
-CFLAGS = -Wall $(OPTIME)
+CFLAGS = -Wall -D_GNU_SOURCE $(OPTIME)
LIBAI = libAI
PAR = -j`/usr/bin/getconf _NPROCESSORS_ONLN`
#--------------------------------------------------------------------
/* */
/********************************************************/
#include <stdio.h>
+#include <string.h>
#include <unistd.h>
#include "subrou.h"
#include "uniprc.h"
#include "unisig.h"
+#include "unisoc.h"
#include "modrec.h"
static _Bool modopen; //boolean module open/close
PUBLIC void rec_handlesmtp()
{
+BINTYP binding;
int phase;
_Bool proceed;
+(void) memset(&binding,'\000',sizeof(BINTYP));
+binding.ip=strdup("127.0.0.25");
+binding.port=strdup("2525");
phase=0;
proceed=true;
while (proceed==true) {
case 0 : //looping forever email receiving processes
(void) prc_settitle("emlrec with pid='%06d'",getpid());
break;
- case 1 : //Terminating all remaining process
+ case 1 : //Opening a channel
+ if (soc_setbind(&binding)<0)
+ phase=999; //doc not open!
+ break;
+ case 2 : //Terminating all remaining process
(void) sleep(1);
if (hangup==false)
phase--; //looping forever
(void) rou_modesubrou(mode);
(void) prc_modeuniprc(mode);
(void) sig_modeunisig(mode);
+ (void) soc_modeunisoc(mode);
break;
case false :
+ (void) soc_modeunisoc(mode);
(void) sig_modeunisig(mode);
(void) prc_modeuniprc(mode);
(void) rou_modesubrou(mode);
/********************************************************/
/* */
/* Low level subroutine declaration */
-/* to hanle an argv list and extract */
+/* to handle an argv list and extract */
/* parameters. */
/* */
/********************************************************/
^L
*/
/********************************************************/
-/* */
/* */
/* Procedure to init the argument list */
/* */
/********************************************************/
/* */
/* Low level subroutine declaration */
-/* to hanle an argv list and extract */
+/* to handle an argv list and extract */
/* parameters. */
/* */
/********************************************************/
//allocated memory and parse an argment list
extern ARGTYP *par_getparams(int argc,char * const argv[],const char *optstring);
-//homework to be done before starting/stoping module.
+//homework to be done before starting/stopping module.
extern int par_modeunipar(_Bool mode);
#endif
--- /dev/null
+// vim: smarttab tabstop=8 shiftwidth=2 expandtab
+/********************************************************/
+/* */
+/* Low level subroutine declaration */
+/* to handle TCP socket. */
+/* */
+/********************************************************/
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netdb.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "subrou.h"
+#include "unisoc.h"
+
+//Need to have GNU_SOURCE define within CFLAGS
+#ifdef AI_ALL
+#define HINTFLG AI_ALL|AI_CANONNAME|AI_CANONIDN
+#else /*AI_ALL is not defined in linux <= rh9 */
+#define HINTFLG AI_CANONNAME
+#endif
+
+
+static _Bool modopen; //module open/close status
+/*
+^L
+*/
+/********************************************************/
+/* */
+/* Procedure to bind a sockt to a specific */
+/* IP/PORT. */
+/* */
+/********************************************************/
+static int bindhandle(struct addrinfo *ai,BINTYP *binding)
+
+{
+return -1;
+}
+/*
+^L
+*/
+/********************************************************/
+/* */
+/* Procedure to bind the socketc. */
+/* IP/PORT. */
+/* */
+/********************************************************/
+PUBLIC int soc_setbind(BINTYP *binding)
+
+{
+#define OPEP "unisoc.c:soc_setbind"
+
+
+int soc;
+struct addrinfo hints;
+struct addrinfo *tobind;
+int phase;
+_Bool proceed;
+
+soc=-1;
+(void) memset(&hints,'\000',sizeof(hints));
+hints.ai_family=PF_UNSPEC;
+hints.ai_flags=HINTFLG;
+hints.ai_socktype=SOCK_STREAM;
+tobind=(struct addrinfo *)0;
+phase=0;
+proceed=true;
+while (proceed==true) {
+ switch (phase) {
+ case 0 : //sanity check
+ if (binding==(BINTYP *)0) {
+ (void) rou_alert(0,"%s, socket binding reference is NULL (Bug!?)",OPEP);
+ phase=999; //no need to go further
+ }
+ break;
+ case 1 : //check if time to retry binding
+ if ((binding->lasttry+5)>time((time_t)0))
+ phase=999; //no need to go further
+ break;
+ case 2 : //to have the right address infp
+ int status;
+
+ binding->lasttry=time((time_t *)0);
+ if ((status=getaddrinfo(binding->ip,binding->port,&hints,&tobind))!=0) {
+ (void) rou_alert(0,"%s, Unable to find a address about "
+ "IP:port '%s:%s' (error='%s')",
+ binding->ip,binding->port,gai_strerror(status));
+ phase=999; //no need to go further
+ }
+ break;
+ case 3 : //binding socket
+ soc=bindhandle(tobind,binding);
+ break;
+ default : //SAFE Guard
+ proceed=false;
+ break;
+ }
+ phase++;
+ }
+return soc;
+#undef OPEP
+}
+/*
+^L
+*/
+/********************************************************/
+/* */
+/* Procedure to "open/close" module and do */
+/* homework purpose */
+/* return zero if everything right */
+/* */
+/********************************************************/
+int soc_modeunisoc(_Bool mode)
+
+{
+#define OPEP "unidoc.c:soc_modeunisoc"
+
+int status;
+
+status=0;
+if (mode!=modopen) {
+ (void) rou_modesubrou(mode);
+ switch ((int)mode) {
+ case true :
+ break;
+ case false :
+ break;
+ default :
+ (void) fprintf(stderr,"Calling %s with wrong mode='%d' (Bug?!):",
+ OPEP,(int)mode);
+ status=-1;
+ break;
+ }
+ modopen=mode;
+ }
+return status;
+#undef OPEP
+}
--- /dev/null
+// vim: smarttab tabstop=8 shiftwidth=2 expandtab
+/********************************************************/
+/* */
+/* Low level subroutine declaration */
+/* to handle tcp Socket. */
+/* */
+/********************************************************/
+#ifndef UNISOC
+#define UNISOC
+
+#include <stdbool.h>
+#include <time.h>
+
+typedef struct {
+ char *ip; //Binding IP //IPV4 or IPV6
+ char *port; //Binding Port
+ time_t lasttry; //successful binding last time
+ }BINTYP;
+
+//procedure to open a socketand retunr handle to socket
+extern int soc_setbind(BINTYP *binding);
+
+//homework to be done before starting/stopping module.
+extern int soc_modeunisoc(_Bool mode);
+
+#endif