/* (no character to be misunderstood by database) */
/* */
/********************************************************/
-PUBLIC char *sql_cleanstr(SQLPTR *sqlptr,char *str)
+PUBLIC char *sql_goodkey(SQLPTR *sqlptr,char *key)
{
-#define OPEP "devsql.c:sql_cleanstr,"
-char *cleanstr;
+#define OPEP "devsql.c:sql_goodkey,"
+
+char *goodkey;
+char *sqlkey;
SQLTYP *sql;
+int phase;
+_Bool proceed;
-cleanstr=(char *)0;
+goodkey=(char *)0;
+sqlkey=(char *)0;
sql=(SQLTYP *)sqlptr;
-if (str!=(char *)0) {
- (void) sql_checkencoding(str);
- switch(sql->sqldb) {
- case (db_postgres) :
- cleanstr=pos_cleanquote(str);
+phase=0;
+proceed=true;
+while (proceed==true) {
+ switch (phase) {
+ case 0 : //do we hav a goot data-base key
+ if ((key==(char *)0)||(strlen(key)==0)) {
+ (void) rou_alert(0,"%s dbkey is NULL or empty (Bug?)",OPEP);
+ phase=999; //trouble trouble
+ }
break;
- case (db_maria) :
- cleanstr=mar_cleanquote(str);
+ case 1 : //checking the key encoding
+ if ((sqlkey=sql_checkencoding(key))==(char *)0) {
+ (void) rou_alert(0,"%s dbkey <%s> encoding is wrong (config?)",OPEP,key);
+ phase=999; //trouble trouble
+ }
break;
- case (db_unknown) :
- default :
- (void) rou_alert(0,"%s Unknown SQL daemon (type='%d')",OPEP,sql->sqldb);
+ case 2 : //cleaning quote according daemon type
+ switch(sql->sqldb) {
+ case (db_postgres) :
+ goodkey=pos_cleanquote(sqlkey);
+ break;
+ case (db_maria) :
+ goodkey=mar_cleanquote(sqlkey);
+ break;
+ case (db_unknown) :
+ default :
+ (void) rou_alert(0,"%s Unknown SQL daemon (type='%d')",OPEP,sql->sqldb);
+ break;
+ }
+ sqlkey=rou_freestr(sqlkey);
+ break;
+ default : //SAFE Guard
+ proceed=false;
break;
}
+ phase++;
}
-else
- cleanstr=strdup("NULL");
-return cleanstr;
-
+return goodkey;
#undef OPEP
}
/*
{
#define OPEP "devsql.c:sql_mngusr,"
-SQLTYP *sql;
_Bool isok;
+char *goodkey;
+SQLTYP *sql;
int phase;
_Bool proceed;
-sql=(SQLTYP *)sqlptr;
isok=false;
+goodkey=(char *)0;
+sql=(SQLTYP *)sqlptr;
phase=0;
proceed=true;
while (proceed==true) {
(void) rou_alert(0,"%s SQL pointer is NUll (Bug?)",OPEP);
phase=999;
}
- if (sql_check_key(email)==false) {
+ if ((goodkey=sql_goodkey(sql,email))==(char *)0) {
(void) rou_alert(0,"%s %s table, key <%s> not acceptable!",
OPEP,EMAILS,email);
phase=999;
case 1 : //getting user information
switch (action) {
case sql_select :
- if ((*usr=select_user(sql,email))!=(USRTYP *)0)
+ if ((*usr=select_user(sql,goodkey))!=(USRTYP *)0)
isok=true;
break;
default :
(void) rou_alert(0,"%s action='%d' not yet implemented!",OPEP,action);
}
+ goodkey=rou_freestr(goodkey);
break;
default :
proceed=false;
//procedure to close an previously opened SQL channel
extern SQLPTR *sql_closesql(SQLPTR *sqlptr);
-//procedure to make sure a string with database
-//is clean
-extern char *sql_cleanstr(SQLPTR *sqlptr,char *str);
+//procedure to make sure a string is acceptable
+//as key search by database
+extern char *sql_goodkey(SQLPTR *sqlptr,char *key);
//procedure to get information on exiting user
extern _Bool sql_mngusr(SQLPTR *sqlptr,SQLENUM action,char *email,USRTYP **usr);
#include "subrou.h"
#include "unisql.h"
-#define DLANG "UNICODE"
+#define DLANG "UTF-8"
/*
\f
static char *cnvconvert(char *lfrom,char *lto,char *encoded)
{
-#define OPEP "rousql.c:cnvconvert,"
+#define OPEP "unisql.c:cnvconvert,"
char *converted;
char *marker;
/* dubious charactere with plain ASCII */
/* */
/************************************************/
-PUBLIC void sql_checkencoding(char *strencoded)
+PUBLIC char *sql_checkencoding(char *strencoded)
{
+#define OPEP "unisql.c:sql_checkencoding,"
+
+char *converted;
char *ptr;
int phase;
int proceed;
+converted=(char *)0;
ptr=(char *)0;
phase=0;
proceed=true;
while (proceed==true) {
switch (phase) {
- case 0 : /*autoconvert string */
+ case 0 : //set the destination convertion
if (((ptr=getenv("DB_LANG"))==(char *)0)||(strlen(ptr)==0))
ptr=DLANG;
- if ((ptr=cnvconvert(ptr,ptr,strencoded))!=(char *)0) {
- (void) free(ptr);
- phase=999; /*everything fine */
- }
break;
- case 1 : /*setting to plain ASCII*/
- if (strencoded!=(char *)0) { /*alway */
- while (*strencoded!='\000') {
- if (isascii(*strencoded)==0)
- *strencoded='_';
- strencoded++;
- }
- }
+ case 1 :
+ if ((converted=cnvconvert(DLANG,ptr,strencoded))!=(char *)0)
+ phase=999; //everything fine converting to DB_LANG
+ break;
+ case 2 : //converting in very plain ascii
+ if ((converted=cnvconvert(DLANG,ptr,strencoded))!=(char *)0)
+ phase=999; //simple char now
+ break;
+ case 3 : //conversion trouble
+ (void) rou_alert(0,"%s Wrong encoding for db access key <%s> (Config?)",
+ OPEP,strencoded);
break;
default : /*SAFE Guard */
proceed=false;
}
phase++;
}
+return converted;
+
+#undef OPEP
}
/*
\f
extern SESTYP *sql_freeses(SESTYP *ses);
//Procedure to check if string is properly coded according DB_LANG
-extern void sql_checkencoding(char *strencoded);
+extern char *sql_checkencoding(char *strencoded);
//Procedure to check if a SQL key is acceptable
extern _Bool sql_check_key(char *key);