]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Ready to to utf-8 coding test
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Sat, 28 Jun 2025 15:22:19 +0000 (11:22 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Sat, 28 Jun 2025 15:22:19 +0000 (11:22 -0400)
lib/devsql.c
lib/devsql.h
lib/unisql.c
lib/unisql.h

index 67f60f34406f9fc53d1d774fc9b82682a9856fce..177d14e976b2815d9099a0bf81d77728e771a055 100644 (file)
@@ -492,34 +492,58 @@ return (SQLPTR *)sql;
 /*      (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
 }
 /*
@@ -536,13 +560,15 @@ PUBLIC _Bool sql_mngusr(SQLPTR *sqlptr,SQLENUM action,char *email,USRTYP **usr)
 {
 #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) {
@@ -552,7 +578,7 @@ 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;
@@ -561,12 +587,13 @@ while (proceed==true) {
     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;
index 308df008393de7afecff62115c0f6dd1ab637525..1ae647f6d1a0a7c153d214f6cfa39afd504d1237 100644 (file)
@@ -19,9 +19,9 @@ extern SQLPTR *sql_opensql();
 //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);
index a4f72051e22c4be84803b1e283e32831d38bcf0f..184b34b44d58595951317675b91a8a0131903e57 100644 (file)
@@ -14,7 +14,7 @@
 #include       "subrou.h"
 #include       "unisql.h"
 
-#define DLANG   "UNICODE"
+#define DLANG   "UTF-8"
 
 /*
 \f
@@ -29,7 +29,7 @@
 static char *cnvconvert(char *lfrom,char *lto,char *encoded)
 
 {
-#define        OPEP    "rousql.c:cnvconvert,"
+#define        OPEP    "unisql.c:cnvconvert,"
 
 char *converted;
 char *marker;
@@ -141,34 +141,37 @@ return ses;
 /*     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;
@@ -176,6 +179,9 @@ while (proceed==true) {
     }
   phase++;
   }
+return converted;
+
+#undef  OPEP
 }
 /*
 \f
index 45fba33d4d0a65a52beca0fb700432cc9ba1f7cf..764a16f9c088619b50df1463bb845f7fa67e9f5b 100644 (file)
@@ -42,7 +42,7 @@ extern USRTYP *sql_freeusr(USRTYP *usr);
 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);