From a6a399c8e2cba4b6f7791beb94f750f4cf388a39 Mon Sep 17 00:00:00 2001 From: "Jean-Marc Pigeon (Delson)" Date: Tue, 17 Jun 2025 15:36:02 -0400 Subject: [PATCH] Working on the unipos and unimar library . --- Makefile | 2 +- app/Makefile | 3 ++- lib/Makefile | 54 ++++++++++++++++++++++++++++------------------------ lib/subrou.h | 4 ++++ lib/unimar.h | 1 + lib/unipos.c | 41 ++++++++++++++++++++++++++++----------- 6 files changed, 67 insertions(+), 38 deletions(-) diff --git a/Makefile b/Makefile index 2deec46..8327063 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ debug \ : @ for i in $(SUBDIR) ; \ do \ - $(MAKE) -s -C $$i $@ ; \ + $(MAKE) -C $$i $@ ; \ done clean : cleanrpm diff --git a/app/Makefile b/app/Makefile index 2c3f7a0..b22e21b 100644 --- a/app/Makefile +++ b/app/Makefile @@ -40,7 +40,7 @@ SRC= \ CC = gcc LD = gcc -g CFLAGS = -I ../lib -Wall $(OPTIME) -LIBMAIL = ../lib/libmail.a ../shared/libposql.so ../shared/libmasql.so +LIBMAIL = ../lib/libmail.a #LIBMAIL = ../lib/libmail.a LIBS = $(LIBMAIL) \ -luuid \ @@ -55,6 +55,7 @@ chkspf : toremake chkspf.o @ $(LD) $(LDFLAGS) -o ../bin/$@ $@.o $(LIBS) receiver: toremake receiver.o + @ echo JMPDBG DB=$(DB) @ $(LD) $(LDFLAGS) -o ../bin/$@ $@.o $(LIBS) feeder : toremake feeder.o diff --git a/lib/Makefile b/lib/Makefile index 7385ad1..560abf3 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -16,28 +16,27 @@ clean : - rm -fr ../shared/* *.so.* *.o *.a *.tar.gz #-------------------------------------------------------------------- -#database definition -shared : libposql libmasql - mv -f libposql.so.1.0 ../shared - ln -nsf libposql.so.1.0 ../shared/libposql.so.1 - ln -nsf libposql.so.1.0 ../shared/libposql.so - mv -f libmasql.so.1.0 ../shared - ln -nsf libmasql.so.1.0 ../shared/libmasql.so.1 - ln -nsf libmasql.so.1.0 ../shared/libmasql.so - -libposql: unipos.o - $(CC) -shared -Wl,-soname,$@.so.1 -o $@.so.1.0 unipos.o - -libmasql: unimar.o - $(CC) -shared -Wl,-soname,$@.so.1 -o $@.so.1.0 unimar.o - +#database definition USING SHARED (test a way to do it) +#shared : libposql libmasql +# mv -f libposql.so.1.0 ../shared +# ln -nsf libposql.so.1.0 ../shared/libposql.so.1 +# ln -nsf libposql.so.1.0 ../shared/libposql.so +# mv -f libmasql.so.1.0 ../shared +# ln -nsf libmasql.so.1.0 ../shared/libmasql.so.1 +# ln -nsf libmasql.so.1.0 ../shared/libmasql.so +# +#libposql: unipos.o +# $(CC) -shared -Wl,-soname,$@.so.1 -o $@.so.1.0 unipos.o +# +#libmasql: unimar.o +# $(CC) -shared -Wl,-soname,$@.so.1 -o $@.so.1.0 unimar.o + +#unipos.o: unipos.h +# $(CC) $(CFLAGS) -c -fPIC -o $@ unipos.c +# +#unimar.o: unimar.h +# $(CC) $(CFLAGS) -c -fPIC -o $@ unimar.c #-------------------------------------------------------------------- -unipos.o: unipos.h - $(CC) $(CFLAGS) -c -fPIC -o $@ unipos.c - -unimar.o: unimar.h - $(CC) $(CFLAGS) -c -fPIC -o $@ unimar.c - #-------------------------------------------------------------------- #Equivalences #-------------------------------------------------------------------- @@ -46,11 +45,11 @@ OBJS= \ lvleml.o \ gesspf.o gestcp.o geseml.o \ devlog.o devsoc.o devsql.o \ - unidns.o unieml.o \ - unipar.o uniprc.o unisig.o unitls.o \ + unidns.o unieml.o unimar.o unipar.o \ + unipos.o uniprc.o unisig.o unitls.o \ subafn.o subrou.o -objs : $(OBJS) shared +objs : $(OBJS) @ ar -cr $(LIBMAIL) $(OBJS) #-------------------------------------------------------------------- @@ -153,6 +152,9 @@ uniprc.h: \ unitls.h: \ subafn.h +unipos.o: unipos.c unipos.h + $(CC) $(CFLAGS) -c -o $@ unipos.c + #-------------------------------------------------------------------- toremake: Makefile @@ -163,10 +165,12 @@ toremake: Makefile .PHONY: clean #-------------------------------------------------------------------- #definitions +POSTGRESQL =1 +MYSQL =2 #-------------------------------------------------------------------- CC = gcc LD = gcc -CFLAGS = -Wall -D_GNU_SOURCE $(OPTIME) +CFLAGS = -Wall -D_GNU_SOURCE $(OPTIME) -DDATABASE=$(DB) LIBMAIL = libmail.a PAR = -j`/usr/bin/getconf _NPROCESSORS_ONLN` #-------------------------------------------------------------------- diff --git a/lib/subrou.h b/lib/subrou.h index 281dd30..9eb2f29 100644 --- a/lib/subrou.h +++ b/lib/subrou.h @@ -19,6 +19,10 @@ #define ITSOK 0 //to check errno against no error +//defining database #define +#define POSTGRESQL 1 +#define MYSQL 2 + typedef void (*genfree_t)(void *); typedef struct timespec TIMESPEC; diff --git a/lib/unimar.h b/lib/unimar.h index c8beb35..b353cf0 100644 --- a/lib/unimar.h +++ b/lib/unimar.h @@ -8,6 +8,7 @@ #ifndef UNIMAR #define UNIMAR + //reference to a SQL pointer reference typedef void MARPTR; diff --git a/lib/unipos.c b/lib/unipos.c index 2d4c022..7ad57fd 100644 --- a/lib/unipos.c +++ b/lib/unipos.c @@ -8,8 +8,14 @@ #include #include +#include "subrou.h" #include "unipos.h" +//checking if MYSQL database need to compiled +#if DATABASE==POSTGRESQL + #define DB_POSTGRESQL +#endif + /* */ @@ -23,20 +29,33 @@ POSPTR *pos_opensql(const char *host,const char *sqlport,const char *dbname) { #define OPEP "unipos.c:pos_opensql," +POSPTR *posptr; -char *z; //parameter null -PGconn *pf; +posptr=(POSPTR *)0; +#ifdef DB_POSTGRESQL + { + char *z; //parameter null + PGconn *pf; -z=(char *)0; -pf=PQsetdbLogin(host,sqlport,z,z,dbname,z,z); -// Check if the connection is successful -if (PQstatus(pf)!=CONNECTION_OK) { - (void) fprintf(stderr,"%s Connection to database '%s' failed, cause '%s'\n", - OPEP,dbname,PQerrorMessage(pf)); - (void) PQfinish(pf); - pf=(PGconn *)0; + POST DATABASE; + z=(char *)0; + pf=PQsetdbLogin(host,sqlport,z,z,dbname,z,z); + // Check if the connection is successful + if (PQstatus(pf)!=CONNECTION_OK) { + (void) fprintf(stderr,"%s Connection to database '%s' failed, cause '%s'\n", + OPEP,dbname,PQerrorMessage(pf)); + (void) PQfinish(pf); + pf=(PGconn *)0; + } + posptr=(POSPTR *)pf; } -return (POSPTR *)pf; +#else + { + OTHER DATABASE; + (void) rou_alert(0,"%s not compiled for postgresql",OPEP); + } +#endif +return (POSPTR *)posptr; #undef OPEP } /* -- 2.47.3