*/
/********************************************************/
/* */
+/* Procedure to get an exclusive access to a */
+/* specific database table. */
+/* */
+/********************************************************/
+PUBLIC int sql_lock(SQLPTR *sqlptr,char *tablename)
+
+{
+return 1;
+}
+/*
+\f
+*/
+/********************************************************/
+/* */
+/* Procedure to release an exclusive access to a */
+/* specific database table. */
+/* */
+/********************************************************/
+PUBLIC int sql_unlock(SQLPTR *sqlptr,_Bool commit)
+
+{
+return 1;
+}
+/*
+\f
+*/
+/********************************************************/
+/* */
/* Procedure to make sure a string to be use to */
/* access database is clean. */
/* (no character to be misunderstood by database) */
//procedure to close an previously opened SQL channel
extern SQLPTR *sql_closesql(SQLPTR *sqlptr);
+//procedure to LOCK access to a database table
+extern int sql_lock(SQLPTR *sqlptr,char *tablename);
+
+//procedure to UNLOCK access to a database table
+extern int sql_unlock(SQLPTR *sqlptr,_Bool commit);
+
//procedure to make sure a string is acceptable
//as key search by database
extern char *sql_gooddata(SQLPTR *sqlptr,char *key);
{
#define OPEP "gessql.c:sql_newconnect,"
-static const char *updfmt="UPDATE %s SET links=links+%d,lastupdate=now() WHERE remoteip='%s'";
+static const char *upd="UPDATE %s SET links=links+%d,lastupdate=now() WHERE remoteip='%s'";
+static const char *ins="INSERT INTO %s (remoteip) values('%s')";
_Bool done;
int phase;
while (proceed==true) {
switch (phase) {
case 0 : //updating remotes record with links
- if (sql_request(sqlptr,updfmt,RMTTBL,delta,rmtip)==1)
- phase=999;
+ if (sql_request(sqlptr,upd,RMTTBL,delta,rmtip)==1) {
+ phase=999; //done no probleme
+ }
+ break;
+ case 1 : //record does not exist
+ done=false;
+ if (sql_lock(sqlptr,RMTTBL)<0) {
+ (void) rou_alert(0,"%s Unable to dbd_lockhard %s table",OPEP,RMTTBL);
+ phase=999; //Unable to lock table
+ }
+ break;
+ case 2 : //was record created in the meantime?
+ done=true;
+ if (sql_request(sqlptr,upd,RMTTBL,delta,rmtip)==1) {
+ phase++; //yes, no need to create it again
+ }
+ break;
+ case 3 : //Let create a record
+ if (sql_request(sqlptr,ins,RMTTBL,rmtip)!=1) {
+ (void) rou_alert(0,"%s Unable to create entry "
+ "for remote ip <%s> in table <%s> (DB trouble?)",
+ OPEP,rmtip,RMTTBL);
+ done=false;
+ phase=999; //Unable to lock table
+ }
+ break;
+ case 4 : //unlock database
+ (void) sql_unlock(sqlptr,true);
break;
default : //SAFE Guard
proceed=false;
DFLT NOW(),
remoteip TEXTUNIQUE, //remote IP number
links INTEGER
- DFLT 0, //how many time the remote connected
+ DFLT 1, //how many time the remote connected
credit INTEGER //Remote IP current credit (-100..+100)
DFLT -100,
status TEXT //'toscan','inscan','valide'