#====================================================
S:HELO example.com
R:250 mailleur.example.com, link (cleartext) ready,...
-S:MAIL FROM: <trouble@mailref1.example.com>
-R:250 2.1.3 trouble@mailref1.example.com sender ok
-S:RCPT TO: <user1@mailref1.example.com>
-R:250 2.6.4 Address accepted <user1@mailref1.example.com>
+C:ORGN: 185.242.226.23
+R:220 mailleur.example.com, ESMTP (cleartext) mailleur...
+C:WAIT 5 #wait 5 sec
S:QUIT
R:221 2.0.0 Bye, closing connection...
#-------------------------------------------------------------------------
{
#define OPEP "gessql.c:sql_newconnect,"
+static const char *sel="SELECT * FROM %s WHERE remoteip='%s' FOR UPDATE";
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')";
int connect;
+SQLRES *sqlres;
SRVTYP *srv;
int phase;
_Bool proceed;
}
break;
case 1 : //updating remotes record with links
- if (sql_request(sqlptr,upd,RMTTBL,delta,rmtip)==1)
- phase++; //Record is existing
+ if ((sqlres=sql_gettupple(sqlptr,sel,RMTTBL,rmtip))==(SQLRES *)0) {
+ (void) rou_alert(0,"%s Unable to get tupple for remote ip <%s> "
+ "in table <%s> (DB trouble?)",
+ OPEP,rmtip,RMTTBL);
+ phase=999; //no tupple information?
+ }
break;
- case 2 : //Let create a record
+ case 2 : //is record already existing
+ if (sql_getnbrtupple(sqlptr,sqlres)==1) {
+ phase++; //No need to create it
+ }
+ sqlres=sql_droptupple(sqlptr,sqlres);
+ break;
+ case 3 : //Let create a new unique 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);
+ (void) sql_unlock(sqlptr,true);
+ phase=999;
}
- else {
- 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);
- }
+ else
+ phase++; //record open
+ break;
+ case 4 : //lets update link
+ if (sql_request(sqlptr,upd,RMTTBL,delta,rmtip)!=1) {
+ (void) rou_alert(0,"%s Unable to update entry "
+ "for remote ip <%s> in table <%s> (DB trouble?)",
+ OPEP,rmtip,RMTTBL);
}
break;
- case 3 : //lets find the the number of connection
+ case 5 : //lets find the the number of connection
if (sql_mngremote(sqlptr,sql_select,rmtip,&srv)==false) {
(void) rou_alert(0,"%s Unable to get record "
"for remote ip <%s> in table <%s> (DB trouble?)",
srv=sql_freesrv(srv);
}
break;
- case 4 : //unlock database
+ case 6 : //unlock database
(void) sql_unlock(sqlptr,true);
break;
default : //SAFE Guard
switch (contact->privilege) {
case rel_authentic :
break;
- case rel_isrelay : //ne to force rel_plain
+ case rel_isrelay : //need to force rel_plain
contact->privilege=rel_plain;
//NO BREAK;
case rel_plain :
break;
case 4 : //let update links
if (sql_newconnect(contact->sqlptr,rmtip,1)!=1) {
+ static char *end;
+
+ end="You have another connection still in progress";
(void) rou_alert(0,"%s <%s> Too many '%d' links! (Testing?)",
OPEP,rmtip,sql_newconnect(contact->sqlptr,rmtip,0));
- phase=999;
+ (void) eml_transmit(contact,true,"%d contact denied <%s>",NOTNOW,end);
+ contact->termend=rou_freestr(contact->termend);
+ contact->termend=strdup(end);
+ contact->credit=-1; //small penalty
+ (void) sleep(1); //To avoid avalanche
+ (void) sql_newconnect(contact->sqlptr,rmtip,-1);
+ phase++; //connection rejected
}
break;
case 5 : //everything is now fine