Sorry folks,

Just noticed that the vpgsql.c's create index statement had extra brackets. Attached patch fixes the typos, removes extra brackets and adds valias and sql loggin support.



!DSPAM:4c1cdcfe32715874013085!
diff -urN vpopmail-5.4.30/vpgsql.c vpopmail-5.4.30-pgsqlfixed/vpgsql.c                                                  
--- vpopmail-5.4.30/vpgsql.c    2010-06-19 20:12:30.991542810 +0800                                                     
+++ vpopmail-5.4.30-pgsqlfixed/vpgsql.c 2010-06-19 21:59:41.951758993 +0800                                             
@@ -392,10 +392,10 @@                                                                                                   
 #endif                                                                                                                 
                                                                                                                        
 #ifdef ENABLE_SQL_LOGGING                                                                                              
-    qnprintf( sqlBufUpdate, SQL_BUF_SIZE,                                                                              
+    qnprintf( SqlBufUpdate, SQL_BUF_SIZE,                                                                              
        "delete from vlog where domain = '%s'", domain );                                                               
     pgres=PQexec(pgc, SqlBufUpdate);                                                                                   
-    if( !pgres || PGresultStatus(pgres)!=PGRES_COMMAND_OK) {                                                           
+    if( !pgres || PQresultStatus(pgres)!=PGRES_COMMAND_OK) {                                                           
       return(-1);                                                                                                      
     }                                                                                                                  
 #endif                                                                                                                 
@@ -445,11 +445,11 @@                                                                                                   
 #endif                                                                                                                 
                                                                                                                        
 #ifdef ENABLE_SQL_LOGGING                                                                                              
-    qnprintf( sqlBufUpdate, SQL_BUF_SIZE,                                                                              
+    qnprintf( SqlBufUpdate, SQL_BUF_SIZE,                                                                              
         "delete from vlog where domain = '%s' and user='%s'",                                                          
        domain, user );                                                                                                 
     pgres=PQexec(pgc, SqlBufUpdate);                                                                                   
-    if( !pgres || PGresultStatus(pgres)!=PGRES_COMMAND_OK) {                                                           
+    if( !pgres || PQresultStatus(pgres)!=PGRES_COMMAND_OK) {                                                           
       err = -1;                                                                                                        
     }                                                                                                                  
 #endif                                                                                                                 
@@ -1488,7 +1488,7 @@                                                                                                   
                                                                                                                        
   vauth_create_table ("valias", VALIAS_TABLE_LAYOUT, 1);                                                               
     snprintf( SqlBufCreate, SQL_BUF_SIZE,                                                                              
-       "create index valias_idx on valias ( %s )", VALIAS_INDEX_LAYOUT );                                              
+       "create index valias_idx on valias  %s ", VALIAS_INDEX_LAYOUT );                                                
                                                                                                                        
     pgres=PQexec( pgc, SqlBufCreate );                                                                                 
     if( !pgres || PQresultStatus(pgres)!=PGRES_COMMAND_OK ) {                                                          
@@ -1614,3 +1614,69 @@                                                                                                  
            return(strcmp(crypt(clear_pass,vpw->pw_passwd),vpw->pw_passwd));                                            
 }                                                                                                                      
                                                                                                                        
+char *valias_select_names( char *alias, char *domain )                                                                    
+{                                                                                                                         
+  PGresult *pgvalias;                                                                                                     
+  int err, verrori;                                                                                                       
+  unsigned ntuples, ctuple;                                                                                               
+  struct linklist *temp_entry = NULL;                                                                                     
+                                                                                                                          
+  /* remove old entries as necessary */                                                                                   
+  while (valias_current != NULL)                                                                                          
+   valias_current = linklist_del (valias_current);                                                                        
+                                                                                                                          
+  if ( (err=vauth_open(0)) != 0 ) {                                                                                       
+    verrori = err;                                                                                                        
+    return(NULL);                                                                                                         
+  }                                                                                                                       
+                                                                                                                          
+  qnprintf( SqlBufRead, SQL_BUF_SIZE,                                                                                     
+            "select distinct alias from valias where domain = '%s' order by alias",                                       
+            domain );                                                                                                     
+  if ( ! (pgvalias=PQexec(pgc, SqlBufRead))                                                                               
+       || PQresultStatus(pgvalias) != PGRES_TUPLES_OK ) {
+    if(pgvalias) PQclear(pgvalias);
+    vcreate_valias_table();
+    if ( ! (pgvalias=PQexec(pgc, SqlBufRead))
+         || PQresultStatus(pgvalias) != PGRES_TUPLES_OK ) {
+      fprintf(stderr,"vpgsql: sql error[j]: %s\n",
+              PQerrorMessage(pgc));
+          if (pgvalias) PQclear(pgvalias);
+      return(NULL);
+    }
+  }
+
+  ntuples = PQntuples (pgvalias);
+  for (ctuple = 0; ctuple < ntuples; ctuple++) {
+    temp_entry = linklist_add (temp_entry, PQgetvalue (pgvalias, ctuple, 1),
+PQgetvalue (pgvalias, ctuple, 0));
+    if (valias_current == NULL) valias_current = temp_entry;
+  }
+  PQclear (pgvalias);
+  pgvalias = NULL;
+
+  if (valias_current == NULL) return NULL; /* no results */
+  else {
+         strcpy (alias, valias_current->d2);
+         return(valias_current->data);
+  }
+}
+
+char *valias_select_names_next(char *alias)
+{
+  if (valias_current == NULL) return NULL;
+
+  valias_current = linklist_del (valias_current);
+
+  if (valias_current == NULL) return NULL;
+  else {
+         strcpy (alias, valias_current->d2);
+         return valias_current->data;
+  }
+}
+
+void valias_select_names_end() {
+
+//  not needed by pgsql
+
+}


!DSPAM:4c1cdcfe32715874013085!

Reply via email to