2 * coded by Ketmar // Invisible Vector <ketmar@ketmar.no-ip.org>
3 * Understanding is not required. Only obedience.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3 of the License ONLY.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 // WARNING! this doesn't perform any sanity checks on "accounts.rc"!
18 module zsq_create_addrbook
is aliced
;
30 // ////////////////////////////////////////////////////////////////////////// //
31 void main (string
[] args
) {
32 ChiroTimerEnabled
= true;
33 chiroParseCommonCLIArgs(args
);
35 // here, i don't have any threads at all
36 if (sqlite3_config(SQLITE_CONFIG_SINGLETHREAD
) != SQLITE_OK
) throw new Exception("cannot switch SQLite to multi-threaded mode");
39 foreach (string s
; args
[1..$]) {
40 if (s
== "force") allowed
= true;
42 if (!allowed
) throw new Exception("use \"force\" to rebuild");
46 auto stInsAddress
= dbConf
.persistentStatement(`
47 INSERT INTO addressbook
48 ( nick, name, email, notes)
49 VALUES(:nick,:name,:email,:notes)
52 dbConf
.execute("BEGIN TRANSACTION;");
53 scope(failure
) dbConf
.execute("ROLLBACK TRANSACTION;");
55 foreach (string
[] argv
; loadRCFile("addressbook.rc")) {
56 if (argv
[0] != "addressbook_add") throw new Exception("expected \"addressbook_add\", but got \""~argv
[0]~"\"");
57 if (argv
.length
< 2) throw new Exception("\"addressbook_add\" don't have any arguments");
59 //uint accid = chiroGetAccountUid(dbConf, argv[1]);
60 //if (!accid) throw new Exception("account \""~argv[1]~"\" not found");
62 string nick
= argv
[1];
63 if (!isValidUTFNick(nick
)) throw new Exception("invalid addressbook nick \""~nick
~"\"");
69 for (usize aidx
= 2; aidx
< argv
.length
; ) {
70 string aname
= argv
[aidx
++];
73 if (name
!is null) throw new Exception("duplicate name in account \""~nick
~"\"");
77 if (email
!is null) throw new Exception("duplicate email in account \""~nick
~"\"");
79 if (!isGoodEmail(email
)) throw new Exception("invalid email in account \""~nick
~"\"");
82 if (notes
!is null) throw new Exception("duplicate notes in account \""~nick
~"\"");
84 if (!utf8Valid(notes
)) throw new Exception("invalid notes in account \""~nick
~"\"");
87 throw new Exception("unknown option \""~aname
~"\"");
91 if (email
.length
== 0) throw new Exception("missing email in account \""~nick
~"\"");
94 .bindConstText(":nick", nick
)
95 .bindConstText(":name", name
)
96 .bindConstText(":email", email
)
97 .bindConstText(":notes", notes
, allowNull
:true)
102 dbConf
.execute("COMMIT TRANSACTION;");
104 writeln(count
, " address book entries added.");
106 writeln("closing the db");