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;
*usr=locusr;
return isok;
+#undef OPEP
+}
+/*
+\f
+*/
+/********************************************************/
+/* */
+/* 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
}
/*
#undef OPEP
}
+/*
+\f
+*/
+/********************************************************/
+/* */
+/* 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
+}
+
//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);
//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);