1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
diff -urN -x .svn ../../vendor/vpopmail/vpgsql.c ./vpgsql.c
--- ../../vendor/vpopmail/vpgsql.c 2007-10-07 23:44:14.000000000 +0300
+++ vpgsql.c 2007-12-25 03:47:54.000000000 +0200
@@ -390,13 +390,15 @@
#endif
#ifdef ENABLE_SQL_LOGGING
- qnprintf( sqlBufUpdate, SQL_BUF_SIZE,
+#ifdef ENABLE_SQL_REMOVE_DELETED
+ 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
+#endif
return(0);
}
@@ -443,14 +445,16 @@
#endif
#ifdef ENABLE_SQL_LOGGING
- qnprintf( sqlBufUpdate, SQL_BUF_SIZE,
+#ifdef ENABLE_SQL_REMOVE_DELETED
+ 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
+#endif
return(err);
}
@@ -1553,6 +1557,80 @@
return valias_current->data;
}
}
+
+/************************************************************************
+ *
+ * valias_select_names
+ */
+
+char *valias_select_names( char *domain )
+{
+ PGresult *pgres;
+ int err;
+ 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 ) return(NULL);
+
+ qnprintf( SqlBufRead, SQL_BUF_SIZE,
+ "select distinct alias from valias where domain = '%s' order by alias", domain );
+
+ if ( ! (pgres=PQexec(pgc, SqlBufRead))
+ || PQresultStatus(pgres) != PGRES_TUPLES_OK ) {
+ if(pgres) PQclear(pgres);
+ vcreate_valias_table();
+ if ( ! (pgres=PQexec(pgc, SqlBufRead))
+ || PQresultStatus(pgres) != PGRES_TUPLES_OK ) {
+ fprintf(stderr,"vpgsql: sql error[o]: %s\n",
+ PQerrorMessage(pgc));
+ if (pgres) PQclear (pgres);
+ return(NULL);
+ }
+ }
+
+ ntuples = PQntuples (pgres);
+ for (ctuple = 0; ctuple < ntuples; ctuple++) {
+ temp_entry = linklist_add (temp_entry, PQgetvalue (pgres, ctuple, 0), "");
+ if (valias_current == NULL) valias_current = temp_entry;
+ }
+ PQclear (pgres);
+ pgres = NULL;
+
+ if (valias_current == NULL) return NULL; /* no results */
+ else return(valias_current->data);
+}
+
+/************************************************************************
+ *
+ * valias_select_names_next
+ */
+
+char *valias_select_names_next()
+{
+ if (valias_current == NULL) return NULL;
+ valias_current = linklist_del (valias_current);
+
+ if (valias_current == NULL) return NULL; /* no results */
+ else return(valias_current->data);
+}
+
+
+/************************************************************************
+ *
+ * valias_select_names_end
+ */
+
+void valias_select_names_end() {
+
+// not needed by pgsql
+
+}
+
#endif
#ifdef ENABLE_SQL_LOGGING
|