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

5387 Commits

Author SHA1 Message Date
John Hernandez
1c02239ef6 Fix unintended exits on some commands
On some commands execution (like `/privacy logging X`
where X is any symbol/group of symbols)
FALSE is being returned.
Which main cycle understands as a signal to exit profanity.
The mistake is common since returns are often used by
developers to communicate success status.

First reported by @doctor in the Profanity MUC,
as exit on `/logging group color` command.
2023-11-11 13:58:47 +01:00
John Hernandez
1cf7973245 Minor config/conflists.c refactoring
Refactor functions `conf_string_list_add`, `conf_string_list_remove`:
simplify the logic, improve readability and avoid unnecessary allocations.
2023-11-11 08:41:00 +01:00
Michael Vetter
bba8278bb7 Fix passing of wrong parameter to cmd executable template function
`/executable vcard_photo test`

Printed
`Invalid usage, see '/help card_photo' for details.`

So it used the subcommand instead of the command and lost one of the
letters as well.

This mistake got introduced in 60c197487.
Where we added helper functions for the various `/executable` functions.

Discovered by @H3rnand3zzz with correct solution.

Fix https://github.com/profanity-im/profanity/issues/1921
2023-11-10 23:01:27 +01:00
Michael Vetter
74178806a8
Merge pull request #1919 from H3rnand3zzz/patch-1
Fix double free crash
2023-11-10 22:12:31 +01:00
John Hernandez
092b5530b2 Add emptiness check for /url save and /plugins install
Empty file is not a normal condition for file downloading,
thus user has to be notifed.

Related to https://github.com/profanity-im/profanity/issues/1901
2023-11-10 20:05:01 +01:00
John Hernandez
30fe5f0fb9 Allow redirects for '/plugins install <URL>
Fix https://github.com/profanity-im/profanity/issues/1901
Suggested by @jubalh
2023-11-10 20:04:04 +01:00
John Hernandez
76aee1625c
Fix double free crash
Double free was introduced earlier in a cleanup commit
865a056315

It was reported earlier by me and then by @jubalh https://github.com/profanity-im/profanity/issues/1901
2023-11-10 12:39:26 +01:00
John Hernandez
bc38ddf8fa Improve handling of NULL pointers in DB
Fix crash that occurs when message fetched from the database is NULL.

Introduced in this commit
89dc7a46f1

Previous fix attempt
6d17b4eeb5
2023-11-07 14:09:58 +01:00
Steffen Jaeckel
a99dda9a97 Handle potential NULL pointers in database
Follow-up of 89dc7a46f1 resp. #1902

Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
2023-11-07 11:27:17 +01:00
Michael Vetter
45fe1be58f
Merge pull request #1902 from H3rnand3zzz/feature/improved-history
Change DB structure
2023-11-06 22:41:36 +01:00
Steffen Jaeckel
4c26462827 Ensure instances of auto types are initialized
Follow-up of #1913

Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
2023-11-06 22:22:35 +01:00
John Hernandez
a671cff964 Improve XEP-0308 compliance
Disallow correcting historical MUC messages, as the XEP-308 requires.

Previous changes introduce problem with
"Illicit LMC attempt from conference@server/user for message from user"

During investigation it was revealed that XEP does not recommend support
of historical MUC messages correction.

```
When used in a Multi-User Chat (XEP-0045) context,
corrections must not be allowed (by the receiver)
for messages received before the sender joined the room -
particularly a full JID leaving the room
then rejoining and correcting a message SHOULD be disallowed,
as the entity behind the full JID in the MUC may have changed.
```
https://xmpp.org/extensions/xep-0308.html#rules

XEP details mentioned by @jubalh
Bug discovered and solution improved by  @jaeckel
2023-11-06 22:04:53 +01:00
Steffen Jaeckel
0449a42e5c Fix /omemo fingerprint crashing in a MUC
Reported by a user in the profanity MUC.

Fixup of e1d137f4e6 resp. #1863

Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
2023-11-06 19:29:25 +01:00
John Hernandez
89dc7a46f1 Improve Database: Replace Empty Strings with NULL Values
Enhance data consistency by updating the database to treat empty
strings as NULL values. This change simplifies queries and improves
overall database integrity.
2023-11-06 18:20:39 +01:00
John Hernandez
d89b5a04fa Change DB stucture, improve LMC behaviour
**Please, backup your DB before performing any testing.**

Introduce new DB structure and DB migration mechanism.
Index `timestamp`, `to_jid`, `from_jid` columns to improve performance.
Add trigger for `replaced_by_db_id` calculation by DB on message insert.

Now LMC messages are interconnected with original messages,
this way we have fast access to last (hence correct) applicable edits,
as well as reference to the original message from any edit (in case of chained edits).

Change the way LMC messages are being displayed. Now we check if we
can replace a message from current buffer. If we don't have a message in
the buffer, it might've been lost, but we can still display it as a
new message.

Further information available here:
https://github.com/profanity-im/profanity/pull/1893
https://github.com/profanity-im/profanity/issues/1899
https://github.com/profanity-im/profanity/pull/1902
2023-11-03 20:32:01 +01:00
John Hernandez
7af0e9b1e1 Show encryption for historical messages
Refactor getting char, introduce get_show_char() to follow DRY principle.

In theory, performance might be negatively affected after this change.

Ideally get_show_char should be optimized in the future.
2023-11-03 11:27:30 +01:00
John Hernandez
8e40ca1470 Add unicode support for correction char
Commit to allow unicode support in omemo/pgp/otr chars misses
adding support to set correction character.
1f8b1eb740

Further fixing commit also misses adding support to set the unicode character,
it only adds ability to display unicode correction character in the settings.
5cf6ee15cf6ee1bc6d0b99b01891bc455a657bf022a72b0
2023-11-03 09:21:00 +01:00
Steffen Jaeckel
1d41a328f1 Fix loading of encryption type
The column of the encryption type in the result is 4, not 3.

Fixup of 6375b2719f

Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
2023-10-30 16:06:37 +01:00
John Hernandez
88b4fdd50e Add database borders check
Stop fetching message from DB when profanity reached start or end of the history
with the user. This allows to save resources on page up/down
when ceiling or bottom accordingly are reached.
2023-10-29 13:34:01 +01:00
John Hernandez
ea39657b0a Reduce buffer size
Currently buffer is being redrawn on each DB fetch,
this causes a big waste of resources as on every page_up button click
we redraw 1200 messages (each message can be longer than 1 line),
commit will reduce buffer size to 200,
thus reducing amount of messages redrawn on each page up,
this is a temporary solution for a bigger problem.
2023-10-29 13:34:01 +01:00
John Hernandez
9ecade9919 Add params support for aliases
Before aliases used spaces in their name,
now the alias part is being read only before the first space,
thus allowing execution of complex command with aliases.

Example (with plugin):
`/alias add echo "/system exec echo"`
will allow execution of
`/echo test`
as opposed to prior state when the Profanity will
search for alias "echo tests" and output `Unknown command: /echo test`

Minor change: removed an example with invalid command (`/away`)
2023-10-20 10:42:37 +02:00
Michael Vetter
2ab9a306ab Fix /plugins reload error message
`/plugins reload non-existent-plugin` printed:
```
Failed to reload plugin: non-existent-plugin, `:^C
```

There were two mistakes:
error_message instead of error_message->str was passed to cons_show().

And in case of failing to unload the plugin due to not finding it in the
hash table it didn't print an error.

This bug was introduced in cc697de05.
2023-10-19 12:58:19 +02:00
Michael Vetter
3bd50fdd6a Unify error logging in database.c
Mentioned in review of:
https://github.com/profanity-im/profanity/pull/1898
2023-10-17 11:28:28 +02:00
John Hernandez
24d0030ecc Check sender for LMC messages
When we received a message correction via `XEP-0308: Last Message Correction`
we accepted the change without checking the sender
making it possible for anybody to replace the message if the ID was known.

This change has been proposed by @jubalh
https://github.com/profanity-im/profanity/pull/1893#issuecomment-1752434740
2023-10-17 11:11:10 +02:00
Michael Vetter
c68e10c2c4
Merge pull request #1896 from H3rnand3zzz/fix/reconnect-crash
Fix 2 crashes on reconnection
2023-10-16 08:41:54 +02:00
John Hernandez
3838e5a982 Fix crash on reconnection in the chat window
Profanity tries to access the nickname from the roster,
but roster is being cleaned already,
thus leading to use-after-free.

Fix #1894 https://github.com/profanity-im/profanity/issues/1894
2023-10-15 23:24:13 +02:00
John Hernandez
be42ffcee9 Fix crash on quick /reconnect now usage (double free)
Check connection state before reconnection.

Fix #1894 https://github.com/profanity-im/profanity/issues/1894
2023-10-15 23:23:01 +02:00
Michael Vetter
01f4732da3
Merge pull request #1897 from H3rnand3zzz/cleanup/typos
Fix typos, correct grammar
2023-10-15 01:04:36 +02:00
John Hernandez
3c8b4acac4 Fix typos, correct grammar 2023-10-14 18:07:52 +02:00
John Hernandez
403f924462 Add logging to DB message insertion
Add logging for cases when the message is not being inserted in the DB due to its ID.

Make diagnostic of unreliable message history much easier,
lay the groundwork for a fully reliable message history.

Further changes might include insertion of messages with non-unique stanza-id,
but as it's a big change with plentiful issues, decision was made
to further investigate potential causes of history unreliability.

For details see #1893 discussion
2023-10-14 13:29:17 +02:00
Michael Vetter
634cb586d9
Merge pull request #1892 from ike08/improvement/muc-title-behaviour
Improve MUC title behaviour for roster, statusbar, and titlebar
2023-10-09 09:47:03 +02:00
IsaacM88
23c6936398 Improve MUC title behaviour for roster, statusbar, and titlebar
## Abstract

Continuation of https://github.com/profanity-im/profanity/pull/1881

Give all MUC title commands a consistent command structure and appearance.

- `/roster room use name|jid` and `/roster room show|hide server` are now `/roster room title bookmark|jid|localpart|name`
- `/statusbar room room|jid` is now `/statusbar room title bookmark|jid|localpart|name`
- `/statusbar show|hide jid` and `/statusbar show|hide name` are now `/titlebar room title bookmark|jid|localpart|name`

Fix both bugs mentioned in https://github.com/profanity-im/profanity/pull/1881

### src/ui/mucwin.c:mucwin_generate_title

Called by each command to generate a properly formatted title. It checks for "name" first because "name" is the default preference for each command. The last if-statement sets the title to "localpart" for special cases when the title should be "localpart" instead of the user-defined preference.

## Testing

### Preparation

Remove preferences that will interfere with testing.

```
sed -i "/roster.rooms.title=/d" profrc
sed -i "/statusbar.room.title=/d" profrc
sed -i "/titlebar.muc.title=/d" profrc
sed -i "/roster.rooms.use.name=/d" profrc
sed -i "/roster.rooms.server=/d" profrc
sed -i "/statusbar.room=/d" profrc
sed -i "/titlebar.muc.title.jid=/d" profrc
sed -i "/titlebar.muc.title.name=/d" profrc
sed -i "/roster.rooms.by=/d" profrc
```

### Command Definitions

| Test | Window |
| :--- | :--- |
| `/help roster` | - /roster room title bookmark\|jid\|localpart\|name<br>- room title bookmark\|jid\|localpart\|name : Display the bookmark name, JID, JID localpart, or room name as the roster title for MUCs.<br>- *No /roster show\|hide server*<br>- *No /roster room use jid\|name* |
| `/help statusbar` | - /statusbar room title bookmark\|jid\|localpart\|name<br>- room title bookmark\|jid\|localpart\|name : Display the bookmark name, JID, JID localpart, or room name as the title for MUC tabs.<br>- *No /statusbar room jid\|room* |
| `/help titlebar` | - /titlebar room title bookmark\|jid\|localpart\|name<br>- room title bookmark\|jid\|localpart\|name : Display the bookmark name, JID, JID localpart, or room name as the MUC window title.<br>- *No /titlebar show\|hide jid\|name* |

### Autocomplete

| Test | Command line |
| :--- | :--- |
| `/roster room <TAB>` | Autocompletes `title` |
| `/roster room title <TAB>` | Autocompletes `bookmark\|jid\|localpart\|name` |
| `/statusbar room <TAB>` | Autocompletes `title` |
| `/statusbar room title <TAB>` | Autocompletes `bookmark\|jid\|localpart\|name` |
| `/titlebar room <TAB>` | Autocompletes `title` |
| `/titlebar room title <TAB>` | Autocompletes `bookmark\|jid\|localpart\|name` |
| `/roster room <TAB>` | Does not autocomplete `use`, `show`, or `hide` |
| `/roster room use <TAB>` | Does not autocomplete `name` |
| `/roster room show <TAB>` | Does not autocomplete `server` |
| `/roster room hide <TAB>` | Does not autocomplete `server` |
| `/statusbar room <TAB>` | Does not autocomplete `jid` or `room` |
| `/titlebar show <TAB>` | Does not autocomplete `jid` or `name` |
| `/titlebar hide <TAB>` | Does not autocomplete `jid` or `name` |

### Set Preferences

| Test | Window | profrc |
| :--- | :--- | :--- |
| `/roster room title bookmark` | Roster MUCs will display 'bookmark' as their title. | roster.rooms.title=bookmark |
| `/roster room title jid` | Roster MUCs will display 'jid' as their title. | roster.rooms.title=jid |
| `/roster room title localpart` | Roster MUCs will display 'localpart' as their title. | roster.rooms.title=localpart |
| `/roster room title name` | Roster MUCs will display 'name' as their title. | roster.rooms.title=name |
| `/roster room title invalid` | Invalid usage, see '/help roster' for details. | |
| `/statusbar room title bookmark` | Displaying 'bookmark' as the title for MUC tabs. | statusbar.room.title=bookmark |
| `/statusbar room title jid` | Displaying 'jid' as the title for MUC tabs. | statusbar.room.title=jid |
| `/statusbar room title localpart` | Displaying 'localpart' as the title for MUC tabs. | statusbar.room.title=localpart |
| `/statusbar room title name` | Displaying 'name' as the title for MUC tabs. | statusbar.room.title=name |
| `/statusbar room title invalid` | Invalid usage, see '/help statusbar' for details. |  |
| `/titlebar room title bookmark` | MUC windows will display 'bookmark' as the window title. | titlebar.muc.title=bookmark |
| `/titlebar room title jid` | MUC windows will display 'jid' as the window title. | titlebar.muc.title=jid |
| `/titlebar room title localpart` | MUC windows will display 'localpart' as the window title. | titlebar.muc.title=localpart |
| `/titlebar room title name` | MUC windows will display 'name' as the window title. | titlebar.muc.title=name |
| `/titlebar room title invalid` | Invalid usage, see '/help titlebar' for details. |  |
| `/roster room use jid` | Invalid usage, see '/help roster' for details. |  |
| `/roster room use name` | Invalid usage, see '/help roster' for details. |  |
| `/roster room show server` | Invalid usage, see '/help roster' for details. |  |
| `/roster room hide server` | Invalid usage, see '/help roster' for details. |  |
| `/statusbar room jid` | Invalid usage, see '/help statusbar' for details. |  |
| `/statusbar room room` | Invalid usage, see '/help statusbar' for details. |  |
| `/titlebar show jid` | Invalid usage, see '/help titlebar' for details. |  |
| `/titlebar hide jid` | Invalid usage, see '/help titlebar' for details. |  |
| `/titlebar show name` | Invalid usage, see '/help titlebar' for details. |  |
| `/titlebar hide name` | Invalid usage, see '/help titlebar' for details. |  |

### Display Set Preferences

| Test | Window |
| :--- | :--- |
| /prefs ui | - Roster rooms title (/roster) : name<br>- Room tab display (/statusbar) : name<br>- MUC window title (/titlebar) : name |

### Test MUC Window

#### Test: without *name* preference, without *room name* field

```
/join muc@dmn.im
/room config
/field1 ""
/form submit
/quit
```

| Test | Roster | Statusbar | Titlebar |
| :--- | :--- | :--- | :--- |
| `/join muc@dmn.im` | muc<span/>@dmn.im | muc<span/>@dmn.im | muc<span/>@dmn.im |
| `/room config` |  | muc<span/>@dmn.im conf | muc<span/>@dmn.im config |
| `/field2 edit` |  |  | muc<span/>@dmn.im config * |
| `/msg tst` | tst | muc<span/>@dmn.im/tst | muc<span/>@dmn.im/tst |
| `/roster room by service` | muc |  |  |

#### Test: with *name* preference, without *room name* field

```
/roster room title name
/statusbar room title name
/titlebar room title name
/save
/quit
```

| Test | Roster | Statusbar | Titlebar |
| :--- | :--- | :--- | :--- |
| `/join muc@dmn.im` | muc<span/>@dmn.im | muc<span/>@dmn.im | muc<span/>@dmn.im |
| `/room config` |  | muc<span/>@dmn.im conf | muc<span/>@dmn.im config |
| `/field2 edit` |  |  | muc<span/>@dmn.im config * |
| `/msg tst` | tst | muc<span/>@dmn.im/tst | muc<span/>@dmn.im/tst |
| `/roster room by service` | muc |  |  |

#### Test: without *name* preference, with *room name* field

```
sed -i "/roster.rooms.title=/d" profrc
sed -i "/statusbar.room.title=/d" profrc
sed -i "/titlebar.muc.title=/d" profrc
/join muc@dmn.im
/room config
/field1 "my_room"
/form submit
/quit
```

| Test | Roster | Statusbar | Titlebar |
| :--- | :--- | :--- | :--- |
| `/join muc@dmn.im` | my_room | my_room | my_room |
| `/room config` |  | my_room conf | my_room config |
| `/field2 edit` |  |  | my_room config * |
| `/msg tst` | tst | my_room/tst | my_room/tst |
| `/roster room by service` | my_room |  |  |

#### Test: with *name* preference, with *room name* field

```
/quit
/roster room title name
/statusbar room title name
/titlebar room title name
/save
/quit
```

| Test | Roster | Statusbar | Titlebar |
| :--- | :--- | :--- | :--- |
| `/join muc@dmn.im` | my_room | my_room | my_room |
| `/room config` |  | my_room conf | my_room config |
| `/field2 edit` |  |  | my_room config * |
| `/msg tst` | tst | my_room/tst | my_room/tst |
| `/roster room by service` | my_room |  |  |

#### Test: with *localpart* preference

```
/quit
/roster room title localpart
/statusbar room title localpart
/titlebar room title localpart
/save
/quit
```

| Test | Roster | Statusbar | Titlebar |
| :--- | :--- | :--- | :--- |
| `/join muc@dmn.im` | muc | muc | muc |
| `/room config` |  | muc conf | muc config |
| `/field2 edit` |  |  | muc config * |
| `/msg tst` | tst | muc/tst | muc/tst |
| `/roster room by service` | muc |  |  |

#### Test: with *bookmark* preference, without *bookmark name*

```
/quit
/roster room title bookmark
/statusbar room title bookmark
/titlebar room title bookmark
/save
/quit
/bookmark add muc@dmn.im
```

| Test | Roster | Statusbar | Titlebar |
| :--- | :--- | :--- | :--- |
| `/bookmark join muc@dmn.im` | muc<span/>@dmn.im | muc<span/>@dmn.im | muc<span/>@dmn.im |
| `/room config` |  | muc<span/>@dmn.im conf | muc<span/>@dmn.im config |
| `/field2 edit` |  |  | muc<span/>@dmn.im config * |
| `/msg tst` | tst | muc<span/>@dmn.im/tst | muc<span/>@dmn.im/tst |
| `/roster room by service` | muc |  |  |

#### Test: with *bookmark* preference, with *bookmark name*

```
/quit
/bookmark remove muc@dmn.im
/bookmark add muc@dmn.im name "my_bookmark"
```

| Test | Roster | Statusbar | Titlebar |
| :--- | :--- | :--- | :--- |
| `/bookmark join muc@dmn.im` | my_bookmark | my_bookmark | my_bookmark |
| `/room config` |  | my_bookmark conf | my_bookmark config |
| `/field2 edit` |  |  | my_bookmark config * |
| `/msg tst` | tst | my_bookmark/tst | my_bookmark/tst |
| `/roster room by service` | my_bookmark |  |  |

#### Test: with *jid* preference

```
/quit
/roster room title jid
/statusbar room title jid
/titlebar room title jid
/save
/quit
```

| Test | Roster | Statusbar | Titlebar |
| :--- | :--- | :--- | :--- |
| `/join muc@dmn.im` | muc<span/>@dmn.im | muc<span/>@dmn.im | muc<span/>@dmn.im |
| `/room config` |  | muc<span/>@dmn.im conf | muc<span/>@dmn.im config |
| `/field2 edit` |  |  | muc<span/>@dmn.im config * |
| `/msg tst` | tst | muc<span/>@dmn.im/tst | muc<span/>@dmn.im/tst |
| `/roster room by service` | muc |  |  |

### Test Contact Chat Window Title

#### Test: without contact nick

```
/roster add tst@dmn.im
```

| Test | Titlebar |
| :--- | :--- |
| `/msg tst@dmn.im` | tst<span/>@dmn.im |

#### Test: with contact nick

```
/roster add tst@dmn.im my_tst
```

| Test | Titlebar |
| :--- | :--- |
| `/msg my_tst` | my_tst <tst<span/>@ike.snikket.chat> |

### Test Preference Upgrade

#### Test /roster

| Test | profrc |
| :--- | :--- |
| `sed -i '/\[ui\]/a\roster.rooms.use.name=name' profrc` | Original key removed. |
| `sed -i '/\[ui\]/a\roster.rooms.use.name=' profrc` | Original key removed. |
| `sed -i '/\[ui\]/a\roster.rooms.server=' profrc` | Original key removed. |
| `sed -i '/\[ui\]/a\roster.rooms.use.name=jid' profrc` | Original key removed.<br>roster.rooms.title=jid |
| `sed -i '/\[ui\]/a\roster.rooms.use.name=jid' profrc`<br>`sed -i '/\[ui\]/a\roster.rooms.server=false' profrc` | Original keys removed.<br>roster.rooms.title=localpart |
| `sed -i '/\[ui\]/a\roster.rooms.use.name=jid' profrc`<br>`sed -i '/\[ui\]/a\roster.rooms.server=true' profrc` | Original keys removed.<br>roster.rooms.title=jid |
| `sed -i '/\[ui\]/a\roster.rooms.use.name=jid' profrc`<br>`sed -i '/\[ui\]/a\roster.rooms.server=' profrc` | Original keys removed.<br>roster.rooms.title=jid |
| `sed -i '/\[ui\]/a\statusbar.room=' profrc` | Original key removed. |
| `sed -i '/\[ui\]/a\statusbar.room=room' profrc` | Original key removed.<br>statusbar.room.title=localpart |
| `sed -i '/\[ui\]/a\statusbar.room=jid' profrc` | Original key removed.<br>statusbar.room.title=jid |
| `sed -i '/\[ui\]/a\titlebar.muc.title.jid=' profrc` | Original key removed. |
| `sed -i '/\[ui\]/a\titlebar.muc.title.name=' profrc` | Original key removed. |
| `sed -i '/\[ui\]/a\titlebar.muc.title.jid=true' profrc` | Original key removed. |
| `sed -i '/\[ui\]/a\titlebar.muc.title.name=true' profrc` | Original key removed. |
| `sed -i '/\[ui\]/a\titlebar.muc.title.jid=false' profrc` | Original key removed. |
| `sed -i '/\[ui\]/a\titlebar.muc.title.name=false' profrc` | Original key removed. |
| `sed -i '/\[ui\]/a\titlebar.muc.title.jid=true' profrc`<br>`sed -i '/\[ui\]/a\titlebar.muc.title.name=false' profrc` | Original key removed.<br>titlebar.muc.title=jid |
| `sed -i '/\[ui\]/a\titlebar.muc.title.jid=false' profrc`<br>`sed -i '/\[ui\]/a\titlebar.muc.title.name=true' profrc` | Original keys removed. |
| `sed -i '/\[ui\]/a\titlebar.muc.title.jid=true' profrc`<br>`sed -i '/\[ui\]/a\titlebar.muc.title.name=true' profrc` | Original keys removed. |

### Test Valgrind

No memory leaks detected relating to these changes.
2023-10-05 18:16:04 -06:00
Steffen Jaeckel
2b29d1baf3 Fix some glib nullptr-check warning messages
Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
2023-10-04 17:02:10 +02:00
Steffen Jaeckel
6f1ea087c8 Fix memleak.
In some cases it was possible that the `roster_pending_presence` list was
not free'd correctly.

Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
2023-10-04 17:02:10 +02:00
Steffen Jaeckel
e668c4f7df Extend autoping timer on each stanza we receive.
Sometimes the server is too busy sending other stanzas or our connection is
saturated because of something else, so the pong arrives too late.
Prevent the autoping disconnect event by extending the timeout
each time a stanza is received.

Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
2023-10-04 17:02:10 +02:00
Steffen Jaeckel
5b6b5130ae Fix OMEMO keyfile loading
We have to lazy load the keyfiles as they will maybe be written at one
point and should be initialized by that time.

Fixup of ca2df180d8

Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
2023-09-08 14:51:13 +02:00
Michael Vetter
394c935469
Merge pull request #1883 from profanity-im/fix/1877-url
Cut URLs before adding to automcomp at `>`
2023-09-05 10:44:00 +02:00
Michael Vetter
9f08cd44a6 Adjust regex to match URLs
First I tried with g_uri_parse() and g_uri_to_string() but then I
learned that GUri validation API is only for things that are part of a
proper URL.

Then used `g_utf8_strchr()` to cut the string at `>` since they are
sometimes enclosed in `<>`.

Thanks to @sjaeckel for providing a proper regex from
https://stackoverflow.com/questions/43588699/regex-for-matching-any-url-character

Fix https://github.com/profanity-im/profanity/issues/1877
2023-09-05 10:24:45 +02:00
Steffen Jaeckel
ca2df180d8 Introduce a shared implementation for keyfile loading
Instead of copy&pasting the same code over again, use a common
implementation.

Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
2023-09-04 09:59:09 +02:00
Steffen Jaeckel
b7f964fe64 Resolve symlinks recursively in get_file_or_linked()
Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
2023-09-04 09:59:09 +02:00
Steffen Jaeckel
d3b6ebb1d7 Less allocations in str_replace()
If `n` is the number of `substr` replace operations, the old
implementation did `n+1` allocations and always first copied start,
then replacement, then the remaining (unsearched) part of the original
string.

Now calculate the number of occurences of `substr` before allocating the
resulting string.
Change the algorithm to parse through the original string and only
copy the parts that must be kept into the resulting string plus the
replacements where they belong at.
Now we also only have to go through the original string twice plus we only
do a single allocation.

Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
2023-09-01 12:12:44 +02:00
Steffen Jaeckel
b36562c6b6 Introduce win_println_va()
Previously we printed a format string into a `GString` to then print that
result again into a `GString` and display that.
This patch removes one level of `GString` printing by forwarding the
`va_arg` to the newly added API `win_println_va()`.

Introducing `static win_println_va_internal()` also allowed refactoring
most of the `win_print*()` and `win_append*()` implementations and removing
all the redundant code.

Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
2023-09-01 12:12:44 +02:00
Steffen Jaeckel
e8348b8d17 Update preferences.h
* fix const correctness of `prefs_load()`
* remove some API's that don't exist anymore

Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
2023-08-31 23:14:02 +02:00
Steffen Jaeckel
1bb1f57128 No need to double check the window type
Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
2023-08-31 23:14:02 +02:00
Steffen Jaeckel
5657aac33d Fix some more char* -> gchar*.
Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
2023-08-31 23:14:02 +02:00
Michael Vetter
b88174709f Don't crash when using /plugins install disconnected
When we are not connected and run `/plugins install` we crash because we
get the account struct to check for the (xmpp) tls setting.
To apply that to the http (etc) connection to download the plugin from a
server.

This got introduced in 3a86b8c29 to fix #1624.

There are several ways to handle this (some described in 1880) in this
patch I took the route that it will use secure connection when we are
nto connected and will only check the tls.trust account setting if we
are connected.

Fix https://github.com/profanity-im/profanity/issues/1880
2023-08-28 07:55:29 +02:00
Michael Vetter
122434a276 ox: correctly recognize ox encrypted carbons
and dont display them as legacy pgp encrypted messages.
This was forgotten in 2c94ee5a8.

Fix https://github.com/profanity-im/profanity/issues/1875
2023-08-25 08:24:53 +02:00
Michael Vetter
492efc432c Display headline sender 2023-08-11 15:56:26 +02:00
Michael Vetter
a17544d962 Remove not needed check 2023-08-11 15:34:26 +02:00
Martin Dosch
2ed6211cc3 Don't use xscreensaver on wayland.
Fixes #1874.
2023-08-11 13:12:52 +02:00
Michael Vetter
191f571bcd Fix spaces in /privacy description 2023-08-04 08:39:20 +02:00
Michael Vetter
e853c121d9 Fix my email address
in all files
2023-07-31 16:51:58 +02:00
Michael Vetter
215e35b198 Fix my email address 2023-07-31 16:42:45 +02:00
Michael Vetter
3a9de7d21b fix: use correct format specifier in /privacy
Thanks to @H3rnand3zzz for noticing.
2023-07-27 15:13:44 +02:00
Michael Vetter
5fb3453808 Print actual client id in /privacy overview
Instead of just saying that we sent the "default".
2023-07-26 20:43:50 +02:00
Michael Vetter
22b1d14b67 Add helper function to create version string
And remove all the duplicate code.

Depending on the situation prof_get_version() will return:
* 0.13.1
* 0.13.1dev
* 0.13.1dev.master.69d8c1f9
2023-07-25 20:58:15 +02:00
Michael Vetter
13af6c96dc Link from /privacy to relevant /account settings
Related to https://github.com/profanity-im/profanity/issues/1836
2023-07-25 20:14:29 +02:00
Michael Vetter
f7cce4c5c1 Move /os into /privacy os
Related to https://github.com/profanity-im/profanity/issues/1836
2023-07-25 16:35:14 +02:00
Michael Vetter
feba4b8263 Add cons_privacy_setting() to print privacy setting infos 2023-07-24 18:25:34 +02:00
Michael Vetter
a963ff4d24 mam: check if we get 'first' stanza before usage
Fix https://github.com/profanity-im/profanity/issues/1868
2023-07-18 16:44:44 +02:00
John Hernandez
09f217d667 Improve documentation 2023-07-13 21:22:42 +02:00
John Hernandez
865a056315 Cleanup g_strfreev() to auto_gcharv
Include some additional minor cleanups
2023-07-13 17:05:07 +02:00
John Hernandez
029f1caa52 Cleanup jid_destroy to auto_jid
Remove unused variables
Apply minor cleanups
2023-07-13 17:05:07 +02:00
John Hernandez
8304ac86ff g_free() to auto_gfree, introduce auto_guchar
Fix 11 potential mem leaks in theme.c
2023-07-13 17:04:59 +02:00
John Hernandez
3a4cd7da48 Cleanup and mem leak fix
Improve usage of `gchar` and `char` by setting them correctly
Increase usage of `auto_gchar` and `auto_char`
Fix 2 mem leaks (rosterwin.c, avatar.c)
2023-07-12 17:43:33 +02:00
Michael Vetter
9451ea7c4c Mention DEV for doap in release guide 2023-07-12 14:09:55 +02:00
Michael Vetter
62e98dee74 Fix crash when using NetBSD curses implementation
Thanks to @alarixnia fot the patch and bugreport.

```
Forwarding a bug reported using the NetBSD bug tracker ("Profanity crashes at login"): http://gnats.netbsd.org/57050

The code in question here handles messages by people not in the user's contact list, and what is probably happening is that the XMPP server is sending such a message before profanity has set up its window layout.

Setting roster.unsubscribed=false indeed makes profanity start without crashing, and the attached patch bails out early in the problematic code path if layout->subwin is NULL (Adrian verified for me that either of the two makes profanity work for him again). But I am not familiar enough with the profanity code to say if this has any issues.

Profanity compiled with ncurses doesn't crash because ncurses's wattron() has a guard against the user passing null pointers, but the X/Open curses library standard doesn't have this guarantee and there's no guard in the NetBSD curses implementation.
```

Fix https://github.com/profanity-im/profanity/issues/1769
2023-07-12 13:58:03 +02:00
John Hernandez
00bea804e2 Improve documentation two functions
Namely `cmd_process_input()` and `files_get_data_path()`.

Edited by @jubalh.
2023-07-11 13:26:37 +02:00
John Hernandez
e1d137f4e6 Change char->free to auto_char char for autocleanup
Replace `gchar` and `g_free` to `auto_gchar`
Correct certain  `char` functions/variables to `gchar`

Related to #1819.

Edited by @jubalh.
2023-07-11 13:26:37 +02:00
John Hernandez
07fcaa7be3 Fix memory leak and cleanup 2023-07-03 16:06:27 +02:00
John Hernandez
4a70f5f513 Cleanup char* to auto_gchar gchar* for prefs_get_string
Necessity explained in #1819
2023-07-03 16:06:27 +02:00
John Hernandez
1c102fec27 Add /privacy logging command
Add ability to completely turn logs off,
Needed since `/logging` and `/history` didn't stop history logging
in the DB, only in files.
Command might break something on usage,
hence it was primarily introduced for privacy geeks.
Privacy command discussion #1836
2023-07-03 16:06:24 +02:00
Michael Vetter
f67d548ebf
Merge pull request #1850 from H3rnand3zzz/feature/pgp-improved
Extend `/pgp` command to make key exchange procedure easier
2023-07-03 14:18:35 +02:00
John Hernandez
7d6cbfdcd2 Refactor autocomplete
Use `_cmd_ac_complete_params` when fits, thus reducing plurality
2023-07-02 14:25:55 +02:00
John Hernandez
36784738fc Add optional pgp public key autoimport
Refactor `p_gpg_list_keys`
Add `/pgp autoimport` command,
it's not described in XEP-0027, but used in some clients,
such as PSI, Pidgin. It will autoimport keys received with
`/pgp sendpub`, in plain text as a message, or using features,
provided in other clients. It doesn't autoassign them, but shows
command to assign, letting user to decide.
Improve documentation for some preexisting functions
Add contact argument to `/pgp sendpub`
2023-07-02 14:25:55 +02:00
John Hernandez
349e4cb322 Refactor _cmd_set_boolean_preference function
Improve documentation
Update code formatting and indentation for better readability
Show state if no argument provided
Show if argument wasn't changed
Reduce amount of arguments
2023-07-02 14:25:55 +02:00
John Hernandez
a59623a007 Add /pgp sendpub command
Command allows to share your PGP pub key with ease,
it's not described in XEP-0027, but used in some clients,
such as PSI, Pidgin.
Fix typos
Minor improvements
2023-07-02 14:25:55 +02:00
Michael Vetter
6247c28e31
Merge pull request #1842 from H3rnand3zzz/feature/plugins-download
New Feature: Plugins Download
2023-06-06 18:35:18 +02:00
Steffen Jaeckel
88d383b052 Fix double-free of values.
The strings have to be dup'ed, otherwise we'll free them twice.

Fixes #1855

Introduced by b6bb50ceb2

Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
2023-06-04 13:39:03 +02:00
Michael Vetter
14a2dfc711 Expand /url description 2023-05-31 19:51:19 +02:00
Steffen Jaeckel
b6bb50ceb2 Fix use-after-free
introduced in 8d3c1f79ac

This fixes #1852

Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
2023-05-21 11:02:14 +02:00
Steffen Jaeckel
c0861eed49 Improve debug logging
Tell the user that a MAM request will be issued delayed instead of showing
a warning that MAM isn't supported by the server.

Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
2023-05-21 11:00:32 +02:00
Steffen Jaeckel
638b15c6d9 Fix memleak
introduced in 5d3c8ce7c1

Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
2023-05-21 10:59:13 +02:00
John Hernandez
95e06ad169 Add url support (downloading) to /plugins install
Additional changes include code refactoring.
2023-05-16 15:57:07 +02:00
Steffen Jaeckel
d8eea87f60 Fix -Werror=maybe-uninitialized
When compiling with `CFLAGS="-O2 -fexceptions -Wp,-D_FORTIFY_SOURCE=2"`, as
done per default when creating an AUR package e.g. via `makepkg`, this
error is produced.

Refactor `stanza_create_mam_iq()` in order to fix said warning-turned-into-
an-error.

Edit by jubalh:
I still think the error message is a false positive. But this commit improves the
code a lot.

Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
2023-05-12 08:39:29 +02:00
Steffen Jaeckel
197b839944 Remove VLA & calm Valgrind
`MB_CUR_MAX` looks like a macro, but it's a function call and therefore
creates a VLA. We don't want that.

Also this array being uninitialized created the following Valgrind error

```
==503529== Conditional jump or move depends on uninitialised value(s)
==503529==    at 0x619F15E: waddnstr (lib_addstr.c:67)
==503529==    by 0x1929B7: _inp_write (inputwin.c:353)
==503529==    by 0x1937D5: _inp_redisplay (inputwin.c:619)
==503529==    by 0x61511B1: rl_forced_update_display (display.c:2693)
==503529==    by 0x193F9D: _inp_rl_send_to_editor (inputwin.c:957)
==503529==    by 0x614642F: _rl_dispatch_subseq (readline.c:916)
==503529==    by 0x6146C85: _rl_dispatch_callback (readline.c:823)
==503529==    by 0x616739F: rl_callback_read_char (callback.c:241)
==503529==    by 0x1923DB: inp_readline (inputwin.c:188)
==503529==    by 0x149860: prof_run (profanity.c:117)
==503529==    by 0x2283E8: main (main.c:186)
==503529==  Uninitialised value was created by a stack allocation
==503529==    at 0x1928B1: _inp_write (inputwin.c:334)
```

Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
2023-05-12 08:39:23 +02:00
Steffen Jaeckel
12d76e4a21 Fix memleaks & more auto-free
`data_dir` would have been leaked if directory creation failed.

`editor_argv` was leaked at some point, no idea why.

```
==1244734== 118 (32 direct, 86 indirect) bytes in 1 blocks are definitely lost in loss record 6,299 of 7,824
==1244734==    at 0x4846CC3: realloc (vg_replace_malloc.c:1451)
==1244734==    by 0x5E85AD0: g_realloc (in /usr/lib/libglib-2.0.so.0.7600.1)
==1244734==    by 0x5E4A004: ??? (in /usr/lib/libglib-2.0.so.0.7600.1)
==1244734==    by 0x5E4A7B1: g_ptr_array_add (in /usr/lib/libglib-2.0.so.0.7600.1)
==1244734==    by 0x5EA4235: g_strsplit (in /usr/lib/libglib-2.0.so.0.7600.1)
==1244734==    by 0x1F143C: get_message_from_editor (editor.c:92)
==1244734==    by 0x193F6B: _inp_rl_send_to_editor (inputwin.c:950)
==1244734==    by 0x614642F: _rl_dispatch_subseq (readline.c:916)
==1244734==    by 0x6146C85: _rl_dispatch_callback (readline.c:823)
==1244734==    by 0x616739F: rl_callback_read_char (callback.c:241)
==1244734==    by 0x1923DB: inp_readline (inputwin.c:188)
==1244734==    by 0x149860: prof_run (profanity.c:117)
==1244734==    by 0x2283E8: main (main.c:186)
```

Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
2023-05-12 08:39:20 +02:00
Steffen Jaeckel
76a8de891e Improve const-correctness of API
Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
2023-05-12 08:39:19 +02:00
Steffen Jaeckel
860dd22bc5 Fix potential double-free
introduced in 8d3c1f79ac

Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
2023-05-12 08:39:16 +02:00
John Hernandez
9a68aab011 /url save and /url open refactoring
Additional changes: jid.c minor refactoring
2023-05-11 09:44:55 +02:00
Michael Vetter
ea35a4ceb0
Merge branch 'master' into cleanup/gchar-char 2023-05-11 08:45:46 +02:00
Michael Vetter
209a8f4bf5
Merge pull request #1847 from profanity-im/minor-improvements
Minor improvements
2023-05-11 08:43:37 +02:00
Steffen Jaeckel
8d3c1f79ac fix memory leaks
Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
2023-05-10 18:12:11 +02:00
Steffen Jaeckel
8cd53acfd7 fix /reconnect now
This fixes #1846
Issue introduced by a0aa26b6fa

Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
2023-05-10 18:12:11 +02:00
Steffen Jaeckel
08d68d329b more auto_char
Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
2023-05-10 18:08:09 +02:00
Steffen Jaeckel
7d9c3c1b32 fix "window NULL issue" (hopefully)
There were multiple reports where after a reconnect the window of the
MUC that was last opened, was empty.

`muc_join()` creates an instance of a MUC, `presence_join_room()` works
with this instance. Therefore the instance has to exist before working on
it.

I'm not sure if this really fixes the issue, but at least it didn't
happen anymore after I applied this modification.
I can't remember how I stumbled over this, either while looking at debug
logs or while looking at Valgrind output while a reconnect happened, but
something went wrong. Then I came to the conclusion that this may fix
the issue and for now it did ... maybe it comes back, then my RCA was
wrong.

Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
2023-05-10 17:51:52 +02:00
Michael Vetter
60c197487d Add helper function for individual cmd_executable_*() functions
Each of the cmd_executable_editor(), cmd_executable_urlopen() etc calls
this helper function since they were all doing the same just for
different configurations.
2023-05-10 09:41:59 +02:00
Michael Vetter
79efe56d64 Add autocompletion for /executable parameters
We autocompleted `/executable` to `avatar`, `vcard_photo`, `editor` etc.
But didn't autocomplete the next parameter. Namely `set` and `default`.
2023-05-10 09:34:52 +02:00
Michael Vetter
46c90bc681 Make it possible to reset editor to default
All the other commands (avatar, vcard_photo, urlsave, urlopen) have the
ability to reset to default already.
2023-05-10 09:34:52 +02:00
Michael Vetter
a7159c5954 Add vcard_photo to /executable autocompletion
Was forgotten in f934c5b59.
2023-05-10 09:34:52 +02:00