:
@ for i in $(SUBDIR) ; \
do \
- $(MAKE) DB=$(DB) -s -C $$i $@ ; \
+ $(MAKE) DB=$(DB) -C $$i $@ ; \
done
@ #ln -nsf rcvrpsql bin/receiver
@ #ln -nsf sndrpsql bin/sender
subrou.h \
unipos.h unipos.c
@ $(CC) \
+ $(CFLAGS) \
$(CPPFLAGS) \
-DDATABASE=1 \
-Dwith_postgres \
subrou.h \
unimar.h unimar.c
@ $(CC) \
+ $(CFLAGS) \
$(CPPFLAGS) \
-DDATABASE=2 \
-Dwith_mysql \
phase++;
}
return (SQLPTR *)sql;
+#undef OPEP
+}
+/*
+^L
+*/
+/********************************************************/
+/* */
+/* Procedure to return a unix time in acsii */
+/* format (data-base compatible). */
+/* */
+/********************************************************/
+PUBLIC const char *sql_fromunixtime(SQLPTR *sqlptr,time_t timestamp)
+
+{
+#define OPEP "devsql.c:sql_fromunixtime,"
+
+const char *unixdate;
+
+unixdate="";
+if (sqlptr!=(SQLPTR *)0) {
+ SQLTYP *sql;
+
+ sql=(SQLTYP *)sqlptr;
+ switch(sql->sqldb) {
+ case db_postgres :
+ unixdate=pos_fromunixtime(timestamp);
+ break;
+ case db_maria :
+ unixdate=mar_fromunixtime(timestamp);
+ break;
+ default :
+ (void) rou_alert(0,"%s Unexpected db type='%d' (BUG!?)",
+ OPEP,(int)sql->sqldb);
+ break;
+ }
+ }
+return unixdate;
+
+#undef OPEP
+}
+/*
+^L
+*/
+/********************************************************/
+/* */
+/* Procedure to return a unix time_t from an ASCII*/
+/* string (data-base compatible). */
+/* */
+/********************************************************/
+PUBLIC time_t sql_tounixtime(SQLPTR *sqlptr,char *date)
+
+{
+#define OPEP "devsql.c:sql_tounixtime,"
+
+time_t datetime;
+
+datetime=(time_t)0;
+if (sqlptr!=(SQLPTR *)0) {
+ SQLTYP *sql;
+
+ sql=(SQLTYP *)sqlptr;
+ switch(sql->sqldb) {
+ case db_postgres :
+ datetime=pos_tounixtime(date);
+ break;
+ case db_maria :
+ datetime=mar_tounixtime(date);
+ break;
+ default :
+ (void) rou_alert(0,"%s Unexpected db type='%d' (BUG!?)",
+ OPEP,(int)sql->sqldb);
+ break;
+ }
+ }
+return datetime;
+
#undef OPEP
}
/*
//procedure to close an previously opened SQL channel
extern SQLPTR *sql_closesql(SQLPTR *sqlptr);
+//converting a time to a database representation
+extern const char *sql_fromunixtime(SQLPTR *sqlptr,time_t timestamp);
+
+//converting a database time representation to unix time
+extern time_t sql_tounixtime(SQLPTR *sqlptr,char *date);
+
//procedure to LOCK access to a database table
-extern _Bool sql_lock(SQLPTR *sqlptr,char *tablename);
+extern _Bool sql_lock(SQLPTR *sqlPTR,char *tablename);
//procedure to UNLOCK access to a database table
extern _Bool sql_unlock(SQLPTR *sqlptr,_Bool commit);
{3,"lastupdate"},
{4,"links"},
{5,"credit"},
- {6,"status"},
+ {6,"listing"},
{0,(char *)0}
};
locsrv->credit=atoi(locval);
break;
case 6 : //scanning status
- locsrv->status=strdup(locval);
+ locsrv->listing=strdup(locval);
break;
default :
(void) rou_alert(0,"%s field <%d:%s> not implemented (Bug?)",
*/
/********************************************************/
/* */
+/* Procedure to return a unix time in acsii */
+/* format (data-base compatible). */
+/* */
+/********************************************************/
+PUBLIC const char *mar_fromunixtime(time_t timestamp)
+
+{
+#define TSTAMP "%Y-%m-%d %H:%M:%S"
+
+static char unixdate[50];
+
+(void) memset(unixdate,'\000',sizeof(unixdate));
+
+#ifdef DB_MYSQL
+/*Note:
+ *syntax MYSQL ("FROM_UNIXTIME(%ld)",timestamp)
+ */
+ {
+ struct tm *tminfo;
+
+ tminfo=localtime(×tamp);
+ (void) strftime(unixdate,sizeof(unixdate),TSTAMP,tminfo);
+ }
+#endif
+
+return unixdate;
+}
+/*
+\f
+*/
+/********************************************************/
+/* */
+/* Procedure to return a unix time_t from an ASCII*/
+/* string (data-base compatible). */
+/* */
+/********************************************************/
+PUBLIC time_t mar_tounixtime(char *date)
+
+{
+#define OPEP "unimar.c:mar_tounixtime,"
+
+time_t datetime;
+
+datetime=(time_t)0;
+#ifdef DB_MYSQL
+ {
+ static const char *stampeon="0000-00-00 00:00:00";
+
+ if ((date!=(char *)0)&&(strcmp(date,stampeon)!=0)) {
+ static const char *dbtounix="%Y-%m-%d %H:%M:%S";
+
+ char *ptr;
+ struct tm tm;
+
+ if ((ptr=strchr(date,'.'))!=(char *)0) {
+ *ptr='\000';
+ }
+ (void) memset(&tm,'\000',sizeof(struct tm));
+ tm.tm_isdst=-1;
+ if (strptime(date,dbtounix,&tm)!=(char *)0) {
+ datetime=mktime(&tm);
+ }
+ else {
+ (void) rou_alert(0," Unable to convert <%s> to time_t (Bug?)",OPEP,date);
+ }
+ }
+ }
+#endif
+
+return datetime;
+
+#undef OPEP
+}
+/*
+\f
+*/
+/********************************************************/
+/* */
/* procedure to lock access to a specific table */
/* within database. */
/* */
unlocked=true;
cmd="ROLLBACK";
- if (commit==true);
+ if (commit==true)
cmd="COMMIT";
if (mar_request(marptr,cmd)<0) {
unlocked=false;
//Procedure to detect and 'clean' any single quote within a string
extern char *mar_cleanquote(char *sequence);
+//converting a time to a database representation
+extern const char *mar_fromunixtime(time_t timestamp);
+
+//converting a database time representation to unix time
+extern time_t mar_tounixtime(char *date);
+
//locking database one table access
extern _Bool mar_lock(MARPTR *marptr,char *tablename);
*/
/********************************************************/
/* */
+/* Procedure to return a unix time in acsii */
+/* format (data-base compatible). */
+/* */
+/********************************************************/
+PUBLIC const char *pos_fromunixtime(time_t timestamp)
+
+{
+#define TSTAMP "%Y-%m-%d %H:%M:%S"
+
+static char unixdate[50];
+
+(void) memset(unixdate,'\000',sizeof(unixdate));
+
+#ifdef DB_POSTGRESQL
+ {
+ struct tm *tminfo;
+
+ tminfo=localtime(×tamp);
+ (void) strftime(unixdate,sizeof(unixdate),TSTAMP,tminfo);
+ }
+#endif
+
+return unixdate;
+}
+/*
+\f
+*/
+/********************************************************/
+/* */
+/* Procedure to return a unix time_t from an ASCII*/
+/* string (data-base compatible). */
+/* */
+/********************************************************/
+PUBLIC time_t pos_tounixtime(char *date)
+
+{
+#define OPEP "unipos.c:pos_tounixtime,"
+
+time_t datetime;
+
+datetime=(time_t)0;
+#ifdef DB_POSTGRESQL
+ {
+ if (date!=(char *)0) {
+ static const char *dbtounix="%Y-%m-%d %H:%M:%S";
+
+ char *ptr;
+ struct tm tm;
+
+ if ((ptr=strchr(date,'.'))!=(char *)0) {
+ *ptr='\000';
+ }
+ (void) memset(&tm,'\000',sizeof(struct tm));
+ tm.tm_isdst=-1;
+ if (strptime(date,dbtounix,&tm)!=(char *)0) {
+ datetime=mktime(&tm);
+ }
+ else {
+ (void) rou_alert(0," Unable to convert <%s> to time_t (Bug?)",OPEP,date);
+ }
+ }
+ }
+#endif
+
+return datetime;
+
+#undef OPEP
+}
+/*
+\f
+*/
+/********************************************************/
+/* */
/* procedure to lock access to a specific table */
/* within database. */
/* */
unlocked=true;
cmd="ROLLBACK";
- if (commit==true);
+ if (commit==true)
cmd="COMMIT";
if (pos_request(posptr,cmd)<0) {
unlocked=false;
//Procedure to detect and 'clean' any single quote within a string
extern char *pos_cleanquote(char *sequence);
+//converting a time to a database representation
+extern const char *pos_fromunixtime(time_t timestamp);
+
+//converting a database time representation to unix time
+extern time_t pos_tounixtime(char *date);
+
//locking database one table access
extern _Bool pos_lock(POSPTR *posptr,char *tablename);
{
if (smtpdata!=(SRVTYP *)0) {
- smtpdata->status=rou_freestr(smtpdata->status);
+ smtpdata->listing=rou_freestr(smtpdata->listing);
smtpdata->rmtip=rou_freestr(smtpdata->rmtip);
(void) free(smtpdata);
smtpdata=(SRVTYP *)0;
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
+ char *listing; //Remote listing explaination
}SRVTYP;
//procedure to free space used by an USRTYP
values ('user2@mardb.example.com','user2');
//List of remote IP status
-INSERT INTO remotes (remoteip,credit,status) \
- values ('127.127.0.25',10,'valide');
+INSERT INTO remotes (remoteip,credit,lastscan) \
+ values ('127.127.0.25',10,now());
//---------------------------------------------------------------
//selected IP from 'known' spammer
INSERT INTO remotes (remoteip) \
//defining table about remote server
CREATE TABLE remotes (
remoteip TEXTUNIQUE, //remote IP number
- lastscan DBTIMESTAMP //record laste update
- DFLT NOW(),
+ lastscan DBTIMESTAMP //record last update
+ DFLT NULL,
lastupdate DBTIMESTAMP //record creation
DFLT NOW(),
credit INTEGER //Remote IP current credit (-100..+100)
DFLT -100,
- status TEXT //'toscan','inscan','valide'
- DFLT 'toscan',
- listed TEXT //explaination obout black listing
+ listing TEXT //explaination obout black listing
DFLT NULL,
links INTEGER
DFLT 1 //how many time the remote connected
);
-CREATE INDEX remotes_ndx ON remotes (INS(status));
-INSERT INTO remotes (remoteip,credit,status) \
- values ('127.0.0.1',99,'valide');
+CREATE INDEX remotes_ndx ON remotes(lastscan);
+INSERT INTO remotes (remoteip,credit,lastscan) \
+ values ('127.0.0.1',99,now());
//--------------------------------------------------------------
//Defining TRIGGER fonctions according database type