134 Commits

Author SHA1 Message Date
5bb776c432 fix(server): check kill_recv in accept() loop to prevent hang on stop
If server_stop() is called before any client connects, the accept()
loop would spin forever since kill_recv was never checked, causing
pthread_join() to block indefinitely.

Add kill_recv check at the top of the accept() polling loop so the
thread can exit cleanly when server_stop() is called during the
pre-connection phase.
2026-03-12 11:51:56 +03:00
1c36292b1f fix(server): remove invalid recv() call on listen socket
The recv() drain loop on listen_socket was incorrect - listen sockets
don't have data to read. This caused Valgrind to report 'points to
unaddressable byte(s)' errors during functional tests.

Replaced magic number 2 with SHUT_RDWR for clarity.
2026-01-13 17:13:41 +03:00
79fe9dc2b3 fix: use valid buffer in recv() instead of NULL 2025-12-31 09:55:22 +03:00
0353d31355 Fix race condition in log_println (use-after-free)
The check for logready was done BEFORE acquiring the lock, causing a race
condition with log_close(). If log_close() runs between the check and
the lock acquisition, the log file would be closed but log_println would
still try to write to it (use-after-free).

Now the logready/logp check is inside the critical section.
2025-12-25 23:04:13 +03:00
afa4a3a4ea Fix GString memory leak in read_stream function
The 'stream' GString was not freed before returning from read_stream()
in two places:
1. When kill_recv is TRUE at the start of the loop
2. At the end of the function after the loop exits

Added g_string_free(stream, TRUE) before both return statements.
2025-12-25 22:47:10 +03:00
6579e9f565 Fix: Pass valid buffer to recv() instead of NULL
Valgrind reports:
  Syscall param socketcall.recvfrom(buf) points to unaddressable byte(s)
  at recv (recv.c:28)
  by xmppclient_end_session (xmppclient.c:57)
  Address 0x0 is not stack'd, malloc'd or (recently) free'd

The recv() call was passing NULL as buffer, which is invalid.
Now using a local char variable as discard buffer.
2025-12-25 20:42:32 +03:00
7a222fc446 fix: Free XMPPStanza objects in verify_any and verify_last
The XMPPStanza objects created by stanza_parse() in verify_any() and
verify_last() functions were never freed, causing memory leaks.

This fix adds stanza_free(stanza) calls before the return statements
to properly release the allocated stanza resources.
2025-12-24 16:52:40 +03:00
da7b32cbba fix: Resolve memory leak in verify_any and verify_last by destroying GTimer
The GTimer objects created in verify_any() and verify_last() functions
were never freed, causing memory leaks detected by Valgrind.

This fix adds g_timer_destroy(timer) calls after the while loops to
properly release the allocated timer resources.
2025-12-24 16:25:39 +03:00
6faee6177d Merge pull request 'fix: Resolve memory leak in stanza_parse by freeing parse state' (#2) from fix/memory-leak-stanza-parse into master
No functional changes to the parsing behavior
2025-12-24 12:38:15 +00:00
9a41c959ca fix: Resolve memory leak in stanza_parse by freeing parse state 2025-12-24 15:34:26 +03:00
00f47a1598 fix: Fix XMPP stream parsing and add stbbr_for_presence_to helper (#1)
This PR fixes critical issues with XMPP stream parsing and adds a new helper function for MUC testing.

## Changes

### 1. Fix XMPP stream parsing for multiple stanzas
The XML parser was not correctly handling multiple consecutive stanzas in the stream. Fixed depth tracking to properly detect stanza boundaries.

### 2. Fix XMPP stream parsing depth tracking
Added proper depth tracking for nested XML elements to correctly identify when a complete stanza has been received.

### 3. Remove debug logging that interfered with expect tests
Removed verbose debug output that was causing expect-based functional tests to fail due to unexpected output in the stream.

### 4. Add `stbbr_for_presence_to` for MUC join presence matching
New helper function that registers a canned response for presence stanzas based on the `to` attribute. This is essential for testing MUC (Multi-User Chat) join flows where the response must be triggered by presence to a specific room JID.

**API:**
```c
void stbbr_for_presence_to(const char *to, const char *response);

Reviewed-on: jabber.developer2/stabber#1
Co-authored-by: jabber.developer2 <jabber.developer2@jabber.space>
Co-committed-by: jabber.developer2 <jabber.developer2@jabber.space>
2025-12-15 08:45:38 +00:00
Michael Vetter
3e5c220071 Link with libmicrohttpd 2020-07-08 13:41:49 +02:00
Michael Vetter
81f38c6a33 Use pkgconfig for libmicrohttpd detection
See a3766c12585a1db989beacfdac7a0cc46685b59a for why the version bump.
2020-07-08 12:59:04 +02:00
Michael Vetter
f33c4b6ba9 Adapt libmicrohttpd types
Profanity Travis CI showed that stabber doesn't build anymore on Debian
Testing, Arch Linux and Fedora.

It appears all these systems have updated to libmicrohttpd 0.9.71
recently.

Earlier versions build fine.

See release announcement: https://lists.gnu.org/archive/html/libmicrohttpd/2020-06/msg00013.html

```
Furthermore, the release introduces an 'enum MHD_Result' instead of
for certain API misuse bugs by providing better types (not everything is
an 'int').  While this does NOT change the binary API, this change
_will_ cause compiler warnings for all legacy code -- until 'int' is
replaced with 'enum MHD_Result'.
```
2020-07-08 12:58:55 +02:00
James Booth
ed75087e44 Minor code style changes 2016-11-08 23:17:59 +00:00
James Booth
3c9df4390c Allow stubbing for bot get and set iq queries 2015-07-22 22:55:00 +01:00
James Booth
1040fb4fe1 Allow wildcards when waiting on stanza id 2015-07-15 00:23:16 +01:00
James Booth
8585c1af63 Added OSX for pthreads api, added curl example script 2015-07-14 23:32:59 +01:00
James Booth
68df7edd4e Added platform check to configure 2015-07-06 21:15:12 +01:00
James Booth
cd81c8783c Update README.md 2015-06-28 16:31:02 +01:00
James Booth
e7d256bf21 Update README.md 2015-06-14 01:55:41 +01:00
James Booth
23eb872a8d Updated README 2015-06-14 01:52:23 +01:00
James Booth
203e0642fa Merge remote-tracking branch 'origin/master' 2015-06-14 01:39:48 +01:00
James Booth
3733390d0f Added verify to http api 2015-06-14 01:39:21 +01:00
James Booth
121d288ba4 Update README.md 2015-06-09 00:18:33 +01:00
James Booth
2058d8e295 Update README.md 2015-06-08 22:33:58 +01:00
James Booth
6ae630ffa9 Update README.md 2015-06-08 22:32:39 +01:00
James Booth
abc49023e2 Update README.md 2015-06-08 22:29:41 +01:00
James Booth
210037747a Fixed README 2015-06-08 22:27:32 +01:00
James Booth
af8ff24364 Updated README 2015-06-08 22:26:57 +01:00
James Booth
987a7846e3 Added loglevel arg to C API 2015-06-08 22:24:40 +01:00
James Booth
954d3a2128 Moved logging, added log level paramater to standalone runner 2015-06-08 22:18:48 +01:00
James Booth
ad6728e74b Tidied logging, added debug 2015-06-08 21:26:44 +01:00
James Booth
d25f8c9acb Use log levels 2015-06-07 19:14:12 +01:00
James Booth
5dfe0a5786 Added log levels 2015-06-07 19:03:04 +01:00
James Booth
40a29755a6 Added thread names 2015-06-07 18:49:02 +01:00
James Booth
31506449bd Removed SO_REUSEPORT 2015-06-06 23:16:21 +01:00
James Booth
85f1f018fc Merge remote-tracking branch 'origin/master' 2015-06-06 23:06:46 +01:00
James Booth
b1a9f6470b Renamed parse_stanza -> stanza_parse 2015-06-06 23:06:00 +01:00
James Booth
2d83c6f732 Reuse stanza parsing code 2015-06-06 23:03:32 +01:00
James Booth
35babf392f Renamed stanza verification functions 2015-06-06 23:00:05 +01:00
James Booth
98b06b717c Moved stanza_free 2015-06-06 22:56:30 +01:00
James Booth
c521962dd1 Moved stanza_get_query_request 2015-06-06 22:53:33 +01:00
James Booth
7996baa832 Moved stanza_set_id 2015-06-06 22:50:44 +01:00
James Booth
95f594165e Moved stanza_get_id 2015-06-06 22:49:56 +01:00
James Booth
69afdf2cc5 Moved stanza_get_child_ny_name 2015-06-06 22:48:49 +01:00
James Booth
9fc69177da Moved stanza_get_child_by_ns 2015-06-06 22:47:55 +01:00
James Booth
df6556fe14 Moved stanza_add_child 2015-06-06 22:46:56 +01:00
James Booth
4d641963e4 Moved stanza_to_string 2015-06-06 22:44:53 +01:00
James Booth
c1910b052f Removed stanza show functions 2015-06-06 22:42:43 +01:00