Commit graph

38 commits

Author SHA1 Message Date
Alexey Yerin cc83da4cd1 db: match placeholders with columns
Soju inserts 9 columns but only with 8 placeholders. This causes
channels not being saved properly and also logging errors like this:

    downstream ...: failed to create or update channel ...: 8 values for 9 columns
2021-04-27 09:22:44 +02:00
Simon Ser 424f676254 Store last internal msg ID in DB when detaching
References: https://todo.sr.ht/~emersion/soju/98
2021-04-13 18:15:30 +02:00
Simon Ser 1e4ff49472 Save delivery receipts in DB
This avoids loosing history on restart for clients that don't
support chathistory.

Closes: https://todo.sr.ht/~emersion/soju/80
2021-03-31 18:04:13 +02:00
Simon Ser d54c8c1122 Add Network.{URL,GetUsername,GetRealname}
Just a bunch of helpers that can be re-used.
2021-03-09 18:55:34 +01:00
delthas 939c087754 Introduce Channel.{RelayDetached,ReattachOn,DetachAfter,DetachOn}
This adds several fields to the channel database schema and struct.
These fields will be used to add support for customizable message
relaying through BouncerServ, auto-reattaching, auto-detaching.

- RelayDetached is a filter for which notices to relay through
  BouncerServ for detached channels.
- ReattachOn is a filter for which messages to trigger a channel
  reattach on.
- DetachAfter is the duration after which to automatically detach a
  channel if no matching messages are received.
- DetachOn is a filter for which messages will reset the auto-detach
  timer.
2020-12-14 20:54:02 +01:00
Simon Ser af1e578936
Switch to sql.NullString
Not really better than what we had before, however new contributors will
maybe be familiar with it.
2020-10-24 15:47:53 +02:00
Simon Ser fa16337d97
Switch DB API to user IDs
This commit changes the Network schema to use user IDs instead of
usernames. While at it, a new UNIQUE(user, name) constraint ensures
there is no conflict with custom network names.

Closes: https://todo.sr.ht/~emersion/soju/86
References: https://todo.sr.ht/~emersion/soju/29
2020-10-24 15:14:23 +02:00
Simon Ser b3e136e3b7
Add id column to User table
We used rowid before, but an explicit ID column is cleaner.
2020-10-24 14:52:55 +02:00
Hubert Hirtz 7310f67fc7
Make DB.DeleteChannel take the channel ID
... to allow the caller to correctly do any necessary casemapping.
2020-09-07 11:40:18 +02:00
Dan Shick 54efb1cab4
Fix store user query values 2020-08-18 00:26:59 +02:00
Simon Ser 0812c795f4
Add User.ID
For now it's just a new field that'll be useful to generate user ident
strings. It uses the SQLite implicit rowid column. In the future the DB
interface will need to be updated to use user IDs instead of usernames.
2020-08-11 10:26:42 +02:00
Simon Ser b71fcc2e00
Add DB.DeleteUser 2020-08-03 18:43:39 +02:00
Simon Ser 7ebe47ad4a
Fix deadlock in DB.Close
This method was calling itself, instead of the underlying SQLite
database's Close method.
2020-07-09 11:23:51 +02:00
delthas d1b4faa529 Add an admin flag to users
This is preparatory work for letting some users access admin-exclusive
service commands, such as creating new users.

This adds a boolean admin flag to the User schema. Old users will stay
non-admin after the DB migration.
2020-06-08 22:30:09 +02:00
Simon Ser 998546cdc3
Introduce User.Created
For Network and Channel, the database only needed to define one Store
operation to create/update a record. However since User is missing an ID
we couldn't have a single StoreUser function like other types. We had
CreateUser and UpdatePassword. As new User fields get added (e.g. the
upcoming Admin flag) this isn't sustainable.

We could have CreateUser and UpdateUser, but this wouldn't be consistent
with other types. Instead, introduce User.Created which indicates
whether the record is already stored in the DB. This can be used in a
new StoreUser function to decide whether we need to UPDATE or INSERT
without relying on SQL constraints and INSERT OR UPDATE.

The ListUsers and GetUser functions set User.Created to true.
2020-06-08 11:59:03 +02:00
fox.cpp 203dc3df6a
Implement upstream SASL EXTERNAL support
Closes: https://todo.sr.ht/~emersion/soju/47
2020-06-02 11:24:22 +02:00
Simon Ser d9186e994d
Add support for detached channels
Channels can now be detached by leaving them with the reason "detach",
and re-attached by joining them again. Upon detaching the channel is
no longer forwarded to downstream connections. Upon re-attaching the
history buffer is sent.
2020-05-01 15:18:14 +02:00
Simon Ser 276ce12e7c
Add network.channels, remove DB.GetChannel
Store the list of configured channels in the network data structure.
This removes the need for a database lookup and will be useful for
detached channels.
2020-04-23 16:36:20 +02:00
delthas 7f74055380 Add support for custom network on-connect commands
Some servers use custom IRC bots with custom commands for registering to
specific services after connection.

This adds support for setting custom raw IRC messages, that will be
sent after registering to a network.

It also adds support for a custom flag.Value type for string
slice flags (flags taking several string values).
2020-04-16 17:38:47 +02:00
Simon Ser 2194259124
Set up DB migration infrastructure
The database is now initialized automatically on first run. The schema
version is stored in SQLite's user_version special field. Migrations are
stored in an array and applied based on the schema version.
2020-04-10 22:45:02 +02:00
Thorben Günther 148bbc8102
Add ability to change password 2020-04-10 10:09:02 +02:00
Simon Ser 7c10535bfd
Fix SQL error logged on JOIN
Closes: https://todo.sr.ht/~emersion/soju/40
2020-04-01 17:34:22 +02:00
Simon Ser 96039320b6
Add "network delete" service command
And add all the infrastructure required to stop and delete networks.

References: https://todo.sr.ht/~emersion/soju/17
2020-04-01 15:40:20 +02:00
Simon Ser 2fff645129
Stop accessing user data in downstreamConn.authenticate
This becomes racy once user.Password is updated on-the-fly.
2020-03-27 22:38:38 +01:00
Simon Ser 04dd9d51f3
Correctly set Channel.ID in DB.StoreChannel 2020-03-25 14:23:41 +01:00
Simon Ser 02c3bdde20
Error out when storing unsupported SASL mechanism in DB 2020-03-25 14:15:25 +01:00
Simon Ser 33dacc4fb0
Add support for channel keys 2020-03-25 11:54:08 +01:00
delthas 1c41576988 schema: add Network.name 2020-03-19 00:06:48 +01:00
Simon Ser f3940117d1
Rename project to soju 2020-03-13 18:13:03 +01:00
Simon Ser 03d5600da6
Add support for SASL authentication
We now store SASL credentials in the database and automatically populate
them on NickServ REGISTER/IDENTIFY.

References: https://todo.sr.ht/~emersion/jounce/10
2020-03-13 15:12:44 +01:00
Simon Ser fee8fc79c6
Add support for upstream PASS command 2020-03-13 12:06:02 +01:00
Simon Ser 0ef08dfbb5
Store NICK changes in the DB 2020-03-12 19:17:06 +01:00
Simon Ser 0c4e9b539c
Update DB on JOIN and PART 2020-03-12 18:33:03 +01:00
Simon Ser f3656028f6
Add support for PASS to downstream 2020-03-11 19:09:32 +01:00
Simon Ser a572b24702
cmd/jouncectl: new command
Allows to create users.
2020-03-11 19:01:03 +01:00
Simon Ser 660e4c035d
Use a RWMutex for DB 2020-03-04 20:15:38 +01:00
Simon Ser 9db953c7e5
go fmt 2020-03-04 19:23:24 +01:00
Simon Ser 84fe3ae255
Add SQLite database
Closes: https://todo.sr.ht/~emersion/jounce/9
2020-03-04 18:22:58 +01:00