1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-06-16 21:35:24 +00:00
Commit Graph

53 Commits

Author SHA1 Message Date
Steffen Jaeckel
9cf78e59d5 auto-format
Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
2022-02-01 15:01:28 +01:00
Juraj Mlich
c5b370bffc database.c: fix inserting messages to chat logs if archive_id is empty
The original intention of the code was that in case archive_id is not set, NULL should be inserted. What is
inserted however is an empty string. This causes the condition to not insert messages with non-unique
archive_id insert only one message in total and ignore all further ones (if NULL was there, the condition
would work properly). And this in turn causes chat history not work properly.

This commit makes the SQL condition work properly and therefore fixes chat history.

Fixes #1589.
2021-12-31 17:45:45 +01:00
Michael Vetter
f21595597f Format code correctly 2021-10-05 10:01:27 +02:00
CIacademic
e4d23d9364 Escape all parameters in SQL statements
Some more parameters might contain quotes, so escape all of them
with %q by using sqlite3_mprintf.
2021-06-11 14:16:43 +00:00
Michael Vetter
1ec606540e Get rid of asprintf and _GNU_SOURCE define
_GNU_SOURCE was even in some files where it was not needed at all
(http*).

Let's replace asprintf() with g_strdup_printf().
2021-03-30 17:38:13 +02:00
Michael Vetter
057c9ad776 Add config.h in files were it was missing
Related to https://github.com/profanity-im/profanity/issues/1512
2021-03-26 19:54:22 +01:00
Michael Vetter
901f9d3d8c database: make log_database_get_previous_chat safer 2021-03-25 16:46:18 +01:00
Michael Vetter
e93d4ff331 database: simplify _log_database_add_outgoing 2021-03-25 16:45:30 +01:00
Michael Vetter
c0e339130e database: simplify log_database_add_incoming 2021-03-25 16:44:36 +01:00
kaffeekanne
49dc9c5755 Calm OpenBSD syslog
On every write to `chatlog.db` syslog throws
```
profanity: vfprintf %s NULL in "INSERT INTO `ChatLogs` (`from_jid`,
`from_resource`, `to_jid`, `to_resource`, `message`, `timestamp`,
`stanza_id`, `archive_id`, `replace_id`, `type`, `encryption`) SELECT
'%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' WHERE
NOT EXISTS (SELECT 1 FROM `ChatLogs` WHERE `archive_id` = '%s')"
```
in `/var/log/messages`. Checking for `NULL` except in the fields the DB
is expected to throw errors for, satisfies OpenBSDs security measures
2021-02-15 15:58:35 +01:00
Philipp Klaus Krause
6a276e74e3 Since the string from strerror should never be modified, use const. 2020-10-14 09:52:26 +02:00
Michael Vetter
7f5169c2e9 Use g_date_time_format_iso8601()
This partly reverts d3a387a0ec.

For proanity 0.9.x we still wanted to support older glib versions so
that we can be packaged for various linux distros.

Now with 0.10 we want to move on.
2020-09-30 19:43:58 +02:00
Michael Vetter
c9b154b1a2 database: Only insert if there is no entry with same archive_id
archive_is is <stanza-id> or <result id=""> and should identify one
message stable and uniquely.

See XEP-0359: Unique and Stable Stanza IDs.

We need this for example for this situation:
* we go online with Profanity
* we fetch all messages since yesterday
* we add them to the db
* we go offline
* we go online with Profanity
* we fetch all messages since yesterday
* we only want to add the new ones

So far we don't ask MAM "give me all since last 'id'" but since a
certain date.

In case no archive_id will be set, it will be `(null)` and thus should
be inserted anyways because it won't find a value with (null) in that
row.

Because when adding we use `message->stanzaid ? message->stanzaid : "",`
so it will be empty in such a case.

Regards MAM: https://github.com/profanity-im/profanity/issues/660
Regards Stable IDs: https://github.com/profanity-im/profanity/issues/1207
2020-07-23 15:23:18 +02:00
Michael Vetter
a2726b6a7d Apply coding style 2020-07-07 14:18:57 +02:00
Michael Vetter
a4cadf78fa Revert "Apply coding style"
This reverts commit 9b55f2dec0.

Sorting the includes creates some problems.
2020-07-07 13:53:30 +02:00
Michael Vetter
9b55f2dec0 Apply coding style
Regards https://github.com/profanity-im/profanity/issues/1396
2020-07-07 09:43:28 +02:00
Michael Vetter
1224aa414e Use files_get_account_data_path instead of duplicate code
We often had a use case where we want the account specific data dir.
Let's create a function for this instead of doing it by hand each time.
2020-07-01 10:05:45 +02:00
DebXWoody
2c94ee5a88 Feature request - XEP-0373: OpenPGP for XMPP (OX)
Basic implementation of XEP-0373: OpenPGP for XMPP.
https://xmpp.org/extensions/xep-0373.html

Command /ox

Issue: #1331
2020-06-29 19:05:41 +02:00
Michael Vetter
d4692b1b2d Fix carbon logging
Regards https://github.com/profanity-im/profanity/issues/1342
2020-05-27 22:06:04 +02:00
Michael Vetter
b282965ede Escape message before adding to SQL backend 2020-04-18 10:01:40 +02:00
Michael Vetter
180ec2b474 Add to_jid field to ProfMessage struct
Is usefult in many cases if we want cleaner code.
Hope this edit didn't break anything though ;-)
2020-04-11 17:11:53 +02:00
Michael Vetter
b2eea969db Fix error in getting previous chatlog
Our search was too broad, and thus incorrect.

One of the various mistakes it can cause was
https://github.com/profanity-im/profanity/issues/1308

Fix https://github.com/profanity-im/profanity/issues/1308
2020-04-10 14:59:27 +02:00
Michael Vetter
f42f856d37 Retrieve message type from database
So we don't have to check for MUC another way.
2020-04-08 12:50:23 +02:00
Michael Vetter
d3a387a0ec Downgrade dependencies
Use g_date_time_format() instead of g_date_time_format_iso8601() to only
rely on glib 2.56.0 which is the latest version in Debian Buster
(current stable).

We also only use basic sqlite functions so 3.27.0 should be fine there
(also the one in Debian buster).

Thanks to @DebXWoody.
2020-04-07 11:10:41 +02:00
Michael Vetter
f5bdd67dec Add missing includes 2020-04-06 22:42:22 +02:00
Michael Vetter
fb4f82b82c db: actually display the last 10 entries in correct order 2020-04-06 19:44:03 +02:00
Michael Vetter
015c5d83d0 db: get last messages sorted by timestamp 2020-04-06 19:15:06 +02:00
Michael Vetter
3b2976c9cb db: Use type from message struct instead of having individual functions 2020-04-06 19:15:06 +02:00
Michael Vetter
5862e5b159 db: Fix memleaks 2020-04-06 16:09:38 +02:00
Michael Vetter
1afb708533 Add sql to error log
so we can more easily grep for it.
2020-04-06 15:55:22 +02:00
Michael Vetter
0942d98c61 Remove chat_log_get_previous()
We now dont get the log files from the text files via chat_log_get_previous() anymore.
We use the sql backend via log_database_get_previous_chat().

So far it just has the same behaviour like chat_log_get_previous(),
except that in _chatwin_history() we don't pass the sender to
win_print_history() which should be fixed in a commit soon.

And log_database_get_previous_chat() can later easily be expanded to fix
https://github.com/profanity-im/profanity/issues/205.
2020-04-06 14:42:52 +02:00
Michael Vetter
5d54bb228f Get regular chat history out of sql backend 2020-04-06 14:30:38 +02:00
Michael Vetter
20850eb4db db: log encryption type 2020-04-06 10:50:20 +02:00
Michael Vetter
9b1aac0481 db: log "to" resource 2020-04-06 10:50:20 +02:00
Michael Vetter
db502d7054 db: log "from" resource 2020-04-06 10:50:20 +02:00
Michael Vetter
a0a4fd0426 db: log all incoming and outgoing messages 2020-04-06 10:50:20 +02:00
Michael Vetter
def2123216 db: log outgoing message in one case
Not all cases covered yet.
2020-04-06 10:50:20 +02:00
Michael Vetter
628b86f57e db: add dedicated chat, muc, muc pm logging functions 2020-04-06 10:50:20 +02:00
Michael Vetter
af2630a289 db: insert message type 2020-04-06 10:50:20 +02:00
Michael Vetter
9278ba775b db: add more needed fields
DB fields should be complete now.
2020-04-06 10:50:20 +02:00
Michael Vetter
fe67102e71 db: make id autoincrement 2020-04-06 10:50:20 +02:00
Michael Vetter
c56443fea5 db: fix inserting null in database 2020-04-06 10:50:20 +02:00
Michael Vetter
dc0b7b5e91 db: log replace id 2020-04-06 10:50:20 +02:00
Michael Vetter
a5a53c52de db: use goto in error case 2020-04-06 10:50:20 +02:00
Michael Vetter
ac6a1222fc db: add db version
so we can later migrate.
2020-04-06 10:50:20 +02:00
Michael Vetter
4a7a0f3e76 db: move includes 2020-04-06 10:50:20 +02:00
Michael Vetter
1155963c6c db: guard against no DB
Maybe if we only use `/connect` we dont have ProfAccount. In that case
we won't log anything. Only if a account is used we log.

If this is the case or the init of the db didn't work we still want
profanity to run but wont log anything to the db.
2020-04-06 10:50:20 +02:00
Michael Vetter
11663625cc db: Have one database per account 2020-04-06 10:50:20 +02:00
Michael Vetter
5cc3b469a8 database: log stanza_id and whether it is a muc message 2020-04-06 10:50:20 +02:00
Michael Vetter
8045a32c4a database: log incoming messages
First trial. Not covering all cases yet.
2020-04-06 10:50:20 +02:00