}SQLTYP;
//SQL database request
-#define EMAILS "emails" //emails tables
+#define EMAILS "emails" //emails tables
+#define SESSIONS "sessions" //session tabbles
-//field available in table "EMAILS"
+//field available in table "emails"
const char *usrfield[]={
"email",
"password",
(char *)0
};
+//field available in table "sessions"
+const char *sesfield[]={
+ "sessid",
+ "sessfrom",
+ "emailfrom",
+ "taille",
+ (char *)0
+ };
+
/*
\f
*/
*/
/********************************************************/
/* */
-/* Procedure to create a data request and submit it*/
-/* to the proper database daemon. */
+/* Procedure to create a data search request and */
+/* submit it to the to the proper database daemon. */
/* */
/********************************************************/
static SQLRES *gettupple(SQLTYP *sql,const char *fmt,...)
va_end(args);
return rs;
+#undef OPEP
+}
+/*
+\f
+*/
+/********************************************************/
+/* */
+/* Procedure to do some action to change database */
+/* contents. */
+/* */
+/********************************************************/
+static int sqlrequest(SQLTYP *sql,const char *fmt,...)
+
+{
+#define OPEP "devsql.c:sqlrequest,"
+
+int number;
+va_list args;
+char *cmd;
+
+number=-1;
+va_start(args,fmt);
+if ((rou_vasprintf(&cmd,fmt,args))>0) {
+ switch(sql->sqldb) {
+ case db_postgres :
+ number=pos_request(sql->db.psql,cmd);
+ break;
+ case db_maria :
+ number=mar_request(sql->db.msql,cmd);
+ break;
+ default :
+ (void) rou_alert(0,"%s Unexpected type='%d' (BUG!?)",
+ OPEP,(int)sql->sqldb);
+ break;
+ }
+ (void) free(cmd);
+ }
+va_end(args);
+return number;
+
#undef OPEP
}
/*
return usr;
#undef SELUSR
+#undef OPEP
+}
+/*
+\f
+*/
+/********************************************************/
+/* */
+/* Procedure to create a new session contents */
+/* */
+/********************************************************/
+static _Bool insert_ses(SQLTYP *sql,char *seskey,SESTYP **ses)
+
+{
+#define OPEP "devseql.c:insert_ses,"
+#define INSSES "INSERT INTO "SESSIONS" (sessid) VALUES(%s)"
+
+_Bool isok;
+
+isok=true;
+(void) rou_alert(0,"%s JMPDBG Insertin session <%s>",OPEP,seskey);
+isok=(sqlrequest(sql,INSSES,seskey)==1);
+return isok;
+
#undef OPEP
}
/*
phase=999;
}
if ((gooddata=sql_gooddata(sql,email))==(char *)0) {
- (void) rou_alert(0,"%s %s table, key <%s> not acceptable!",
+ (void) rou_alert(0,"%s %s table, key <%s> is empty (Bug?!)",
OPEP,EMAILS,email);
phase=999;
}
#undef OPEP
}
+/*
+\f
+*/
+/********************************************************/
+/* */
+/* Procedure to manage information about email */
+/* exchange session. */
+/* */
+/********************************************************/
+PUBLIC _Bool sql_mngses(SQLPTR *sqlptr,SQLENUM action,char *seskey,SESTYP **ses)
+
+{
+#define OPEP "devsql.c:sql_mngses,"
+
+_Bool isok;
+char *gooddata;
+SQLTYP *sql;
+int phase;
+_Bool proceed;
+
+isok=false;
+gooddata=(char *)0;
+sql=(SQLTYP *)sqlptr;
+phase=0;
+proceed=true;
+while (proceed==true) {
+ switch (phase) {
+ case 0 : //checking SQL
+ if (sql==(SQLTYP *)0) {
+ (void) rou_alert(0,"%s SQL pointer is NUll (Bug?)",OPEP);
+ phase=999;
+ }
+ if ((gooddata=sql_gooddata(sql,seskey))==(char *)0) {
+ (void) rou_alert(0,"%s %s table, key <%s> is empty (Bug?!)",
+ OPEP,SESSIONS,seskey);
+ phase=999;
+ }
+ break;
+ case 1 : //getting user information
+ switch (action) {
+ case sql_insert :
+ isok=insert_ses(sql,gooddata,ses);
+ 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
+}
//as key search by database
extern char *sql_gooddata(SQLPTR *sqlptr,char *key);
-//procedure to get information on exiting user
+//procedure to manage information on exiting user
extern _Bool sql_mngusr(SQLPTR *sqlptr,SQLENUM action,char *email,USRTYP **usr);
+//procedure to manage information on email exchange session
+extern _Bool sql_mngses(SQLPTR *sqlptr,SQLENUM action,char *seskey,SESTYP **ses);
+
#endif
{
if (contact!=(CONTYP *)0) {
+ char *newsid;
+
+ newsid=eml_getcursesid(contact->mainsesid,contact->numreset);
contact->session=sql_freeses(contact->session);
contact->session=(SESTYP *)calloc(1,sizeof(SESTYP));
- contact->session->sessid=eml_getcursesid(contact->mainsesid,contact->numreset);
+ contact->session->sessid=newsid;
+ (void) sql_mngses(contact->sqlptr,sql_insert,newsid,&(contact->session));
}
}
/*
#undef OPEP
}
+/*
+\f
+*/
+/********************************************************/
+/* */
+/* Procedure to request an action (insert,update */
+/* delete) to the database. */
+/* return the number of tupple affected by the */
+/* command. */
+/* */
+/********************************************************/
+PUBLIC int mar_request(MARPTR *marptr,char *command)
+
+{
+#define OPEP "unipos.c:pos_action,"
+
+int number;
+number=-1;
+#ifdef DB_MYSQL
+ {
+ register MYSQL *ms;
+
+ ms=(MYSQL *)marptr;
+ if (mysql_query(ms,command)==0)
+ number=mysql_affected_rows(ms);
+ else
+ (void) rou_alert(0,"%s pid='%05d' Unable to carry cmd=<%s>, error=<%s>",
+ OPEP,getpid(),command,mysql_error(ms));
+ }
+#endif
+return number;
+}
//procedure to return the number of entry within a result
extern int mar_nbrtupple(MARRES *marres);
+//procedure to submit an action (insert,update,delete)
+//to a MySAL database
+extern int mar_request(MARPTR *marptr,char *command);
+
#endif
*/
/********************************************************/
/* */
-/* Procedure to retunr the number of tupple related*/
+/* Procedure to return the number of tupple related*/
/* related to a previous search. */
/* */
/********************************************************/
#endif
return numrow;
}
+/*
+\f
+*/
+/********************************************************/
+/* */
+/* Procedure to request an action (insert,update */
+/* delete) to the database. */
+/* return the number of tupple affected by the */
+/* command. */
+/* */
+/********************************************************/
+PUBLIC int pos_request(POSPTR *posptr,char *command)
+
+{
+#define OPEP "unipos.c:pos_action,"
+
+int number;
+
+number=-1;
+#ifdef DB_POSTGRESQL
+ {
+ register PGconn *pf;
+ PGresult *pgstat;
+
+ pf=(PGconn *)posptr;
+ if ((pgstat=request((PGconn *)pf,command))!=(PGresult *)0) {
+ switch (PQresultStatus(pgstat)) {
+ case PGRES_COMMAND_OK :
+ number=atoi(PQcmdTuples(pgstat));
+ break;
+ default :
+ (void) rou_alert(0,"%s Command <%s> failed, (error=<%s> pgstatut='%d')",
+ OPEP,command,PQerrorMessage(pf),
+ PQresultStatus(pgstat));
+ break;
+ }
+ (void) PQclear(pgstat);
+ }
+ }
+#endif
+return number;
+
+#undef OPEP
+}
//procedure to extract specific field value within database
extern char *pos_getvalue(POSRES *rs,int tuple,const char *fieldname);
-//procedure to extract data from database
+//procedure to extract data from postgresql database
extern POSRES *pos_gettupple(POSPTR *posptr,char *command);
//procedure to return the number of entry within a result
extern int pos_nbrtupple(POSRES *posres);
+//procedure to submit an action (insert,update,delete)
+//to a postgresql database
+extern int pos_request(POSPTR *posptr,char *command);
+
#endif