From: Jean-Marc Pigeon (Delson) Date: Fri, 11 Jul 2025 15:37:23 +0000 (-0400) Subject: Able to read remotes table record X-Git-Tag: tag-0.14~132 X-Git-Url: https://jmp-git.ovh.safe.ca/?a=commitdiff_plain;h=b987c6dc1776851e417e72dee7db35958bab8dd2;p=jmp%2Fmailleur Able to read remotes table record --- diff --git a/lib/gessql.c b/lib/gessql.c index fb376fa..89624f6 100644 --- a/lib/gessql.c +++ b/lib/gessql.c @@ -190,7 +190,7 @@ while (proceed==true) { nbr=sql_getnbrtupple(sqlptr,rs); switch (nbr) { case 0 : //No user email found - phase=999; //this could append + phase=999; //User name not in database break; case 1 : //we have only one record, found user break; @@ -247,6 +247,120 @@ while (proceed==true) { *usr=locusr; return isok; +#undef OPEP +} +/* + +*/ +/********************************************************/ +/* */ +/* Procedure to select a user from emails tables */ +/* and return contents; */ +/* */ +/********************************************************/ +static _Bool select_remote(SQLPTR *sqlptr,char *rmtip,SRVTYP **srv) + +{ +#define OPEP "gessql.c:select_remote," + +static const char *sel="SELECT * FROM "RMTTBL" WHERE remoteip=%s"; + +//field available in table "emails" +static const FLDTYP usrfield[]={ + {1,"remoteip"}, + {2,"lastscan"}, + {3,"lastupdate"}, + {4,"links"}, + {5,"credit"}, + {6,"status"}, + {0,(char *)0} + }; + +_Bool isok; +SRVTYP *locsrv; +SQLRES *rs; +register int phase; +register _Bool proceed; + +isok=false; +locsrv=(SRVTYP *)0; +rs=(SQLRES *)0; +phase=0; +proceed=true; +while (proceed==true) { + switch (phase) { + case 0 : //checking parameters + if ((srv==(SRVTYP **)0)||(rmtip==(char *)0)||(strlen(rmtip)==0)) { + (void) rou_alert(0,"%s srv=<%p> or rmtip=<%s> sing (Bug?)",OPEP,srv,rmtip); + phase=999; + } + break; + case 1 : //Selecting user + if ((rs=sql_gettupple(sqlptr,sel,rmtip))==(SQLRES *)0) { + (void) rou_alert(0,"%s Unable to get data for user <%s> (Database?)", + OPEP,rmtip); + phase=999; //user not found within database + } + break; + case 2 : //do we have ONE user + int nbr; + + nbr=sql_getnbrtupple(sqlptr,rs); + switch (nbr) { + case 1 : //we have only one record, found remote + break; + case 0 : //no record found! + default : //such case should never ever happen + (void) rou_alert(0,"%s got '%d' users record %s (Database corrupted?)", + OPEP,nbr,"while only 1 is expected"); + phase=999; + break; + } + break; + case 3 : //user data extraction + isok=true; + locsrv=(SRVTYP *)calloc(1,sizeof(SRVTYP)); + for (int i=0;(usrfield[i].name!=(char *)0)&&(isok==true);i++) { + char *locval; + + if ((locval=sql_getvalue(sqlptr,rs,0,usrfield[i].name))==(char *)0) + continue; + switch (usrfield[i].num) { + case 1 : //user remoteip + locsrv->rmtip=strdup(locval); + break; + case 2 : //lastscan + break; + case 3 : //last update + break; + case 4 : //Number of links + locsrv->links=atoi(locval); + break; + case 5 : //remote server credibility + locsrv->credit=atoi(locval); + break; + case 6 : //scanning status + locsrv->status=strdup(locval); + break; + default : + (void) rou_alert(0,"%s field <%d:%s> not implemented (Bug?)", + OPEP,usrfield[i].num,usrfield[i].name); + locsrv=sql_freesrv(locsrv); + isok=false; + break; + } + } + break; + default : //SAFE Guard + rs=sql_droptupple(sqlptr,rs); + proceed=false; + break; + } + phase++; + } +*srv=locsrv; +return isok; + #undef OPEP } /* @@ -520,3 +634,66 @@ return done; #undef OPEP } +/* + +*/ +/********************************************************/ +/* */ +/* Procedure to retreive information about remote */ +/* server and get how reliable/trustable it is. */ +/* */ +/********************************************************/ +PUBLIC _Bool sql_mngremote(SQLPTR *sqlptr,SQLENUM action,char *key,SRVTYP **srv) + +{ +#define OPEP "gessql.c:sql_mnremote," + +_Bool isok; +char *gooddata; +int phase; +_Bool proceed; + +isok=false; +gooddata=(char *)0; +phase=0; +proceed=true; +while (proceed==true) { + switch (phase) { + case 0 : //checking SQL and user record + if (sqlptr==(SQLPTR *)0) { + (void) rou_alert(0,"%s SQL pointer is NULL (Bug?)",OPEP); + phase=999; + } + if (srv==(SRVTYP **)0) { + (void) rou_alert(0,"%s USER pointer is NULL (Bug?)",OPEP); + phase=999; + } + break; + case 1 : //do we have a good key + if ((gooddata=sql_gooddata(sqlptr,key))==(char *)0) { + (void) rou_alert(0,"%s %s table, key <%s> is empty (Bug?!)", + OPEP,EMLTBL,key); + phase=999; + } + break; + case 2 : //getting user information + switch (action) { + case sql_select : + isok=select_remote(sqlptr,gooddata,srv); + break; + default : + (void) rou_alert(0,"%s action='%d' not yet implemented!",OPEP,action); + } + gooddata=rou_freestr(gooddata); + break; + default : + proceed=false; + break; + } + phase++; + } +return isok; + +#undef OPEP +} + diff --git a/lib/gessql.h b/lib/gessql.h index 665d54a..7c85752 100644 --- a/lib/gessql.h +++ b/lib/gessql.h @@ -24,7 +24,9 @@ extern _Bool sql_mngusr(SQLPTR *sqlptr,SQLENUM action,char *key,USRTYP **usr); //procedure to manage information on email exchange session extern _Bool sql_mngses(SQLPTR *sqlptr,SQLENUM action,SESTYP **ses); -//Procedure to increment (or decrement) the remoteip -//connection number +//Procedure to increment (or decrement) the remoteip links number extern _Bool sql_newconnect(SQLPTR *sqlptr,char *rmtip,int delta); + +//procedure to extract the information about remotes server +extern _Bool sql_mngremote(SQLPTR *sqlptr,SQLENUM action,char *key,SRVTYP **srv); #endif diff --git a/lib/unisql.c b/lib/unisql.c index 52ec4fa..b3aba12 100644 --- a/lib/unisql.c +++ b/lib/unisql.c @@ -146,14 +146,14 @@ return ses; /* data record definition. */ /* */ /********************************************************/ -PUBLIC SMTTYP *sql_freesmtp(SMTTYP *smtpdata) +PUBLIC SRVTYP *sql_freesrv(SRVTYP *smtpdata) { -if (smtpdata!=(SMTTYP *)0) { +if (smtpdata!=(SRVTYP *)0) { smtpdata->status=rou_freestr(smtpdata->status); smtpdata->rmtip=rou_freestr(smtpdata->rmtip); (void) free(smtpdata); - smtpdata=(SMTTYP *)0; + smtpdata=(SRVTYP *)0; } return smtpdata; } diff --git a/lib/unisql.h b/lib/unisql.h index ae99323..8c30dcd 100644 --- a/lib/unisql.h +++ b/lib/unisql.h @@ -55,12 +55,13 @@ typedef struct { //Structure about remotes SMTP server typedef struct { - time_t lupdate; //last update time char *rmtip; //Remote IP number + time_t lastscan;//last scan time + time_t lupdate; //last update time int links; //Number of connection from this remote int credit; //Remote credit number char *status; //Remote record current status - }SMTTYP; + }SRVTYP; //procedure to free space used by an USRTYP extern USRTYP *sql_freeusr(USRTYP *usr); @@ -68,8 +69,8 @@ extern USRTYP *sql_freeusr(USRTYP *usr); //procedure to free memory used by a SESTYP extern SESTYP *sql_freeses(SESTYP *ses); -//procedure to free memory used by a SMTTYP -extern SMTTYP *sql_freesmtp(SMTTYP *smtpdata); +//procedure to free memory used by a remote server data +extern SRVTYP *sql_freesrv(SRVTYP *srvdata); //Procedure to check if string is properly coded according DB_LANG extern char *sql_checkencoding(char *strencoded);