5.7 KiB
5.7 KiB
CProof Project Structure (for skill context)
CProof is a terminal-based XMPP (chat) client written in C. It uses autotools for building and cmocka for unit testing. CProof is a fork of Profanity, renaming is WIP.
Build System
configure.ac/Makefile.am- Autotools build configurationautogen.sh- Script to generate configure scriptsconfigure-debug- Debug build helpertests/prof_cmocka.h- Test framework header (cmocka wrapper)
Source Directory (src/)
| Directory | Purpose |
|---|---|
src/ai/ |
AI client implementation (ai_client.c/h) - OpenAI/Perplexity provider support |
src/command/ |
Command handling (cmd_ac.c/h - autocomplete, cmd_defs.c/h - command definitions, cmd_funcs.c/h - command implementations) |
src/config/ |
Configuration management (accounts, preferences, themes, colors, CA certs, scripts) |
src/event/ |
Event handling (client events, server events, common) |
src/omemo/ |
OMEMO encryption (crypto, store) |
src/otr/ |
OTR encryption (otr.c/h, otrlib.c/h, otrlibv4.c) |
src/pgp/ |
PGP/OpenPGP integration (gpg.c/h, ox.c/h) |
src/plugins/ |
Plugin system (C API, Python API, autocompleters, callbacks, disco, settings, themes) |
src/tools/ |
Utility functions (autocomplete, parser, clipboard, editor, HTTP download/upload, bookmark ignore) |
src/ui/ |
User interface (buffers, windows, input, chat/muc/console windows, statusbar, tray, window management) |
src/xmpp/ |
XMPP protocol layer (connection, roster, muc, presence, message, stanza, vcard, session, JID, capabilities, OMEMO, Ox, blocking, bookmark, chat state, avatar) |
Key files at src/ root:
main.c- Entry pointprofanity.c- Application initialization/shutdowncommon.h- Common types/macros (includingauto_gcharfor memory management)database.c- Database layerchatlog.c- Chat log handlinglog.c- Logging
Tests Directory (tests/)
| Directory | Purpose |
|---|---|
tests/functionaltests/ |
Integration tests (requires running CProof instance) |
tests/unittests/ |
Unit tests (cmocka-based, run via make check) |
Unit test structure:
tests/unittests/unittests.c- Test runner (registers all tests)tests/unittests/test_*.c/h- Test files paired with headerstests/unittests/helpers.c/h- Test utilitiestests/unittests/<module>/stub_*.c- Stub implementations for dependencies
Stub directories:
unittests/ai/stub_ai_client.c- AI client stubsunittests/config/stub_accounts.c,stub_cafile.cunittests/database/stub_database.cunittests/log/stub_log.cunittests/omemo/stub_omemo.cunittests/otr/stub_otr.cunittests/pgp/stub_gpg.c,stub_ox.cunittests/tools/stub_*.cunittests/ui/stub_ai.c,stub_ui.c,stub_vcardwin.cunittests/xmpp/stub_*.c
Key Patterns
Memory Management:
- Uses
auto_gcharmacro (fromcommon.h) for automatic GString/GString cleanup g_free(),g_list_free_full(),g_hash_table_destroy()for manual cleanupFREE_SET_NULL()/GFREE_SET_NULL()macros
Autocomplete System:
Autocompletetype (GList-based) defined intools/autocomplete.h- Functions:
autocomplete_new(),autocomplete_add(),autocomplete_complete(),autocomplete_free() autocomplete_param_with_ac()- Complete using an Autocomplete objectautocomplete_param_with_func()- Complete using a callback function_autocomplete_param_common()- Internal helper
Command System:
- Commands defined in
cmd_defs.cwithCMD_MAINFUNC()andCMD_TAGS()macros - Autocomplete registered in
cmd_ac.cviag_hash_table_insert(ac_funcs, "/cmd", _cmd_autocomplete) parse_args()fromtools/parser.csplits input into args array
Testing Patterns:
- Use
will_return(func, value)before callingfunc()to mock return values - Use
expect_string()for struct field verification - Setup/teardown via
cmocka_unit_test_setup_teardown(test_func, setup, teardown), centralized in unittests.c - Mock
connection_get_status()withwill_return(connection_get_status, JABBER_CONNECTED)if connection is needed
Current Work Context
The /ai command autocomplete was recently added with:
ai_subcommands_ac- Top-level subcommands: set, remove, start, clear, correct, providersai_set_subcommands_ac- Set subcommands: provider, token, orgai_remove_subcommands_ac- Remove subcommands: providerai_providers_find()- Provider name autocomplete callback (stateless, no_last_provider_match)- Tests in
tests/unittests/test_ai_client.candtests/unittests/test_ai_client.h
Full List of auto_ Macros (Automatic Memory Management)
These macros use GCC's __cleanup__ attribute to automatically free/close resources when they go out of scope.
| Macro | Type | Cleanup Function | Description |
|---|---|---|---|
auto_gchar |
gchar* |
auto_free_gchar() |
Automatically frees a GLib character string |
auto_gcharv |
gchar** |
auto_free_gcharv() |
Automatically frees a GLib character string array (e.g., from g_strsplit) |
auto_char |
char* |
auto_free_char() |
Automatically frees a standard C string (from strdup) |
auto_guchar |
guchar* |
auto_free_guchar() |
Automatically frees a GLib unsigned char string (e.g., base64 decoded) |
auto_gfd |
gint* |
auto_close_gfd() |
Automatically closes a GFileDescriptor |
auto_FILE |
FILE* |
auto_close_FILE() |
Automatically closes a FILE stream |
auto_jid |
Jid* |
jid_auto_destroy() |
Automatically frees a Jid struct (defined only in src/xmpp/jid.h) |
Example usage:
auto_gchar gchar* myString = g_strdup("Hello, world!");
// myString is automatically freed when scope exits