Commit Graph
1001 Commits
Author SHA1 Message Date
andrey 64a9fc3dae more gtests and fix piauth 2026-09-24 11:49:36 +03:00
andrey 6bf50344fd fix: harden PIHTTPServerSessionAuth session table
- cleanupExpired() drops sessions expired by tokenTtl or sessionIdleTimeout and is
  called opportunistically on issuing a token, bounding the session table; it is
  protected and self-locking so subclasses can run it periodically
- issueToken() refuses a token already used by an active session instead of
  silently merging two sessions (login replies 500 on a generator collision)
- document that the token generator must be collision-resistant
- tests: SessionCleanupOnLogin, ManualCleanup, TokenCollisionRejected
2026-09-23 08:49:10 +03:00
andrey e1a24a98f7 fix: accept case-insensitive Basic scheme and guard HTTP test target
- parse the Basic auth-scheme case-insensitively (RFC 7235), matching Bearer
- register the http_server test only when pip_http_server and pip_http_client
  targets exist, so TESTS=ON without the HTTP modules does not fail to link
- add a Basic_LowercaseScheme test
2026-09-23 08:49:04 +03:00
andrey 994cf64838 feat: add optional sliding idle timeout to PIHTTPServerSessionAuth
The idle timeout is opt-in: when set with setSessionIdleTimeout(), a session
expires after that period without a successful request and every successful
request extends it. When unset (the default), sessions are not touched and keep
the previous behavior: the absolute tokenTtl applied to created, or living until
logout. Both deadlines can be combined and the earlier one wins.

- SessionRec: add last_used, drop the unused refresh_token field
- checkToken(): update last_used only while the idle timeout is enabled
- tests: IdleTimeout, IdleActivityExtendsSession, IdleDisabledKeepsSession,
  HasSessionIdleTimeout
2026-09-23 00:10:07 +03:00
andrey 2f63a49c69 refactor: make PIHTTPServerSessionAuth own sessions only, delegate credentials
The server no longer stores user accounts. PIHTTPServerMultiUser is renamed to
PIHTTPServerSessionAuth and keeps only the in-memory session table: credential
verification is delegated to the pure virtual checkCredentials(), implemented by
a client subclass that owns the user storage.

- remove UserRec, addUser/removeUser/userExists/userCount and the password
  check callback; add protected revokeToken()/revokeUserTokens() helpers
- add configurable login/logout route paths (default /api/login, /api/logout)
- call checkCredentials() without holding the internal lock and report 500 when
  the token generator yields no data
- rewrite tests around a client subclass with its own user table
2026-09-22 23:33:25 +03:00
andrey 78fbebe6b0 fix: accept case-insensitive Bearer scheme in HTTP server 2026-09-22 23:33:10 +03:00
andrey 1adb8b528e Merge branch 'master' into http_auth 2026-09-06 13:54:25 +03:00
andrey 9b459330df fixes 2026-09-06 13:52:47 +03:00
peri4 3da94abb2a PIInit refactoring, iteration 2
add to PISystemInfo processorsCount<P|E> fields, now counts only for Windows
Introspection public API works without PIP_HAS_THREADS
2026-09-06 10:41:53 +03:00
peri4 7051e138e9 PIInit refactoring, first iteration 2026-09-06 09:09:45 +03:00
peri4 4df907ef10 CMake - add all flags to pip_defs.h
Introspection - revert *_p files, because they are external API for introspection, not internal
2026-09-05 23:09:38 +03:00
andrey 1025b978aa Add HTTP Bearer auth server class with token validator 2026-09-05 23:01:14 +03:00
andrey 6327720e73 Add multi-user Basic auth support via AuthInfo 2026-09-05 22:51:50 +03:00
andrey 4e1ab26124 Add HTTP Basic Auth and protected server modules
- PIHTTPServerBasicAuth: parse Authorization: Basic header, validate credentials via callback
- PIHTTPServerProtected: wrap any handler with auth check (basic or custom token)
- Integration tests for both modules (12 test cases)
2026-09-05 21:59:42 +03:00
andrey 0572e38325 fix: register std::function<void()> typename so state machine compiles in NO-RTTI debug builds 2026-08-31 22:07:40 +03:00
andrey fa7ff781fe refactor: use targeted includes (pibase_macros.h, piliterals_string.h) and guard <string> by PIP_HAS_RTTI 2026-08-31 19:12:38 +03:00
andrey b6b7a27dcc cmake: make PIP_HAS_DYNLIB depend on PIP_HAS_FILESYSTEM, drop redundant guards in piplugin 2026-08-31 19:02:48 +03:00
andrey 2f840c74e5 refactor: remove unused PIBinaryStream operators for PIMQTT message types
The operator<< / operator>> templates for MessageConst / MessageMutable
added in 4d8b7430 have no users in the tree (libs, tests, utils, main).
Drop them along with the pibinarystream.h include they required; the
binary-stream fallback static_assert in pibinarystream.h already gives a
clear compile error if external code ever streams an MQTT message.
2026-08-31 18:56:29 +03:00
andrey d16f4bdaf7 feat: decouple PISerial from PIP_HAS_THREADS, gate termios/stty code by PIP_HAS_TTY
- CMake: drop PIP_HAS_SERIAL -> PIP_HAS_THREADS dependency and the forced
  PIP_HAS_SERIAL=OFF for PICO_BOARD, so serial can be built on Pico
- piserial.cpp: guard termios/stty code (tcgetattr/tcsetattr/tcflush/tcdrain,
  TIOCSBRK/TIOCCBRK, TIOCMBIS/TIOCMBIC/TIOCMGET, termios members, sys/ioctl.h
  and termios.h includes) with PIP_HAS_TTY; O_NOCTTY replaced by
  PISERIAL_NOCTTY (0 on no-TTY targets)
- add missing #ifndef fallbacks for B110..B115200 used by convertSpeed()
  when termios.h is absent
- guard thread-only PIIODevice API calls (isThreadedRead/stopThreadedRead)
  with PIP_HAS_THREADS in closeDevice/readDevice
- gate the availableDevicesInfo() test loop with PIP_HAS_FILESYSTEM||WINDOWS
  (device enumeration is a filesystem feature)
- AGENTS.md: note that clang-format-18 is applied automatically on file edits
2026-08-31 18:27:09 +03:00
andrey 8e9ba0298e fix: guard RTTI/threads/filesystem dependent code for arbitrary flag combinations 2026-08-31 17:10:38 +03:00
andrey 14355ede0f Merge remote-tracking branch 'origin/master' into pico_sdk
# Conflicts:
#	libs/main/io_devices/pidir.cpp
#	libs/main/io_devices/pifile.cpp
#	libs/main/thread/pithread.cpp
2026-08-31 13:24:55 +03:00
andrey 5209dd5fd4 use KiB literals for default packet sizes 2026-08-31 13:01:37 +03:00
andrey 446eea404f support building with musl libc (Alpine Linux)
- use LFS64 file/stat APIs only on glibc/Windows (absent in musl)
- use plain sched_priority outside glibc
- do not declare pow10(double) where the system provides C23 pow10() (musl)
- ICU is off by default: modern ICU (>= 75) needs C++17 for its headers,
  the project is built with C++11; enable explicitly with -DICU=ON
- fix latent crash: PIThread::setThreadName() read the thread handle from
  inside the new thread; the handle is not guaranteed to be visible before
  start (musl publishes it later), rename the calling thread via
  pthread_self() instead
2026-08-29 22:04:46 +00:00
andrey efede9e6bc small fix 2026-08-28 21:22:27 +03:00
andrey 4115d79e88 Merge branch 'master' into pico_sdk 2026-08-28 21:12:53 +03:00
andrey 37dbacc094 fix 2026-08-27 15:16:16 +03:00
andrey 74390a9678 fix: restore clang-format off guard and platform include order in piethernet.cpp 2026-08-27 12:29:35 +03:00
peri4 59c7e99e50 add PIIODevice::shutdown() 2026-08-26 11:38:30 +03:00
andrey c2e6a9927c refactor: merge adjacent same-condition preprocessor blocks
Merge consecutive #ifdef PIP_HAS_FILESYSTEM / PIP_INTROSPECTION / PIP_CAN
blocks that had no code between them into a single guarded block.
2026-08-25 17:21:01 +03:00
andrey 331ef49991 refactor: simplify redundant PIP_HAS_* preprocessor guards
- drop INTROSPECTION conjunctions (CMake dep table already forces THREADS+SOCKET)
- remove whole-file guards in client_server/process tests (CMake only compiles them when flags are ON)
- normalize single-flag '#if defined(PIP_HAS_X)' to '#ifdef PIP_HAS_X'
2026-08-25 16:57:20 +03:00
andrey 69b22bf95a feat: complete PIP_HAS_* feature guards in code and auto-generate flag summary
Guard PIConnection, thread primitives, PICodeParser and other feature
code behind PIP_HAS_THREADS/PIP_HAS_FILESYSTEM. In CMake generate the
feature flags summary from the single PIP_HAS_FLAGS list (used by the
add_definitions loop as well), default ICU to OFF and make introspection
also require PIP_HAS_SOCKET. Build system/thread test suites only when
the corresponding feature flags are enabled.
2026-08-25 11:14:25 +03:00
andrey 2605446573 refactor: rename __PIP_TYPENAME_DECLARE to PIP_REGISTER_TYPENAME, add PIP_DECLARE_TYPENAME macro
- Rename __PIP_TYPENAME_DECLARE to PIP_REGISTER_TYPENAME across all headers
- Add PIP_DECLARE_TYPENAME(name) macro for in-class type name declaration
- Replace all static const char * __pip_typename__() member functions with PIP_DECLARE_TYPENAME
2026-08-24 19:31:41 +03:00
andrey c1b8e97311 Merge branch 'master' into pico_sdk 2026-08-23 17:19:34 +03:00
andrey d323ebae88 fix: register type names inside feature guards and shrink embedded I/O buffers
- move __PIP_TYPENAME_DECLARE() calls inside PIP_HAS_* guards so -fno-rtti
  builds compile with arbitrary reduced flag combinations
- guard PISerial declaration by PIP_HAS_SERIAL like other feature-gated classes
- reduce threaded read buffers to 1 KiB on embedded targets (PIIODevice,
  PIPacketExtractor, PIEthernet)
2026-08-23 09:25:32 +03:00
andrey 86a1084ec1 feat: enforce no-RTTI type name registration with static_assert 2026-08-23 08:20:51 +03:00
andrey 8fc2be8dd9 fix: complete PIP_HAS_* flag matrix and restore ESP32/FreeRTOS support
- CMake: disable thread/socket-dependent modules (http_client, mqtt_client,
  client_server) and fftw when the required feature flags are off;
  client_server/cloud no longer tied to the crypt option
- host utils gated on filesystem and the modules they need
- Pico keeps the minimal set; generic FreeRTOS (ESP32) keeps filesystem,
  sockets and serial as in master, module set limited to crypt/compress/io_utils
- PICAN, PIBroadcast, PIPackedTCP vanish without socket+threads
- PISerial: restore PISERIAL_NO_PINS (auto-enabled on PIP_EMBEDDED)
- PIFile: FREERTOS uses fopen/stat (no fopen64 in ESP-IDF newlib)
- drop invalid PICout buffer guards, guard PIObject::deleteLater,
  remove (void)destroying hack, fake PIHIDevice non-Linux stub and the
  redundant PICO_SDK guard in code_model_generator
2026-08-22 19:23:22 +03:00
andrey f6075307b6 style: run clang-format over all files 2026-08-22 15:52:58 +03:00
andrey 8828aa3f81 fix: build PIP on Pico and arbitrary flag combinations
- guard console subsystem (PIScreen/PIScreenTile/tiles/PITerminal/
  PIKbdListener) by PIP_HAS_THREADS plus a TTY or Windows console
  (new PIP_HAS_TTY platform macro) - termios is not available on
  bare-metal newlib
- guard cloud subsystem (PICloudBase/Client/Server/TCP) by
  PIP_HAS_SOCKET and PIP_HAS_THREADS
- add PIP_BUILD_CONSOLE/PIP_BUILD_CLOUD to the auto-disable flag
  dependencies in CMake
- PIP_CAN (SocketCAN) is Linux-only, exclude other platforms
- on Pico keep sockets/MQTT off by default: pico-sdk lwip provides
  only a partial POSIX socket layer (no netinet/in.h, poll.h)
- PITranslator: inline no-op definitions when PIP_HAS_FILESYSTEM is
  off so the _tr literal links
- PIIODevice: guard read_func/write_func EVENT_HANDLERs (no-threads)
- piwaitevent_p.cpp: drop unused sys/ioctl.h include (missing on
  arm-none-eabi, broke Pico builds)
2026-08-22 15:49:05 +03:00
andrey 32066e3a8c fix: make PIP buildable for no-threads and no-filesystem flag combinations
Found while verifying -DPIP_HAS_THREADS=OFF / -DPIP_HAS_FILESYSTEM=OFF
smoke builds (pre-existing gaps of the branch):

- piinit.cpp: full implementation now requires PIP_HAS_THREADS as well
  (the PIInit class is declared in piinit.h only with threads; without
  threads PIInit is absent altogether, stub/absent branches unchanged)
- PIWaitEvent: drop the PIP_HAS_THREADS guard - it is a plain
  pipe/select/WaitForMultipleObjects wrapper with no thread usage
  (master had no guard), restores unistd.h include for PICAN etc.
- PIEthernet: guard server_thread_ member, server_func(), threaded
  listen/stop parts and writeThreaded() calls by PIP_HAS_THREADS
- PIPeer: guard class/impl by PIP_HAS_THREADS (uses PIThread/PITimer/
  PIDiagnostics), openDevice() /etc/pip.conf read by PIP_HAS_FILESYSTEM
- PIBinaryLog::restart(): guard threaded-read restart by PIP_HAS_THREADS
- PIIODevice::configure(config_file,...), PIConnection::configureFromConfig,
  PIConfig include resolution: guard path-based bodies by PIP_HAS_FILESYSTEM
- PISerial::availableDevicesInfo(): guard /dev and /proc/tty scan by
  PIP_HAS_FILESYSTEM
- PIHIDevice impl: requires filesystem (sysfs scan) in addition to threads
- PIPluginLoader::pluginsDirectories/findLibrary: guard PIFile/PIDir use
  by PIP_HAS_FILESYSTEM (fallback: empty list / path as-is)
2026-08-22 14:33:34 +03:00
andrey 5fd63cc7dc clean: remove dead feature-flag code
- pifile.cpp: drop '|| !defined(PIP_HAS_FILESYSTEM)' from the
  _fopen_call_ condition and the redundant inner
  '#ifdef PIP_HAS_FILESYSTEM' - the whole file is already inside
  PIP_HAS_FILESYSTEM
- remove PISERIAL_NO_PINS (piplatform.h, piserial.cpp): the whole
  piserial.cpp is inside PIP_HAS_SERIAL which is forced OFF for
  Pico/FREERTOS, so the macro could never be active where it mattered;
  keep the Windows/POSIX branches as-is
2026-08-22 14:08:41 +03:00
andrey b97f7feeb3 fix: guard PIConfig path-based API by PIP_HAS_FILESYSTEM
Declarations of PIConfig(PIString, DeviceMode), PIConfig(PIString,
PIStringList) and open(PIString, DeviceMode) now match their
filesystem-guarded definitions in piconfig.cpp (link error otherwise);
the path constructor definition is guarded as well since it calls the
guarded open(). String/device based overloads stay unguarded.
2026-08-22 14:07:12 +03:00
andrey 54de1da27b refactor: merge embedded CMake blocks, link unix libs by feature flags, guard grabber/pipeline headers
- merge the PICO_BOARD and PIP_FREERTOS blocks (90% duplicate) into one
  embedded block; Pico+PICO_FREERTOS now adds -DPIP_FREERTOS so
  pithread.cpp takes the FreeRTOS path instead of POSIX pthreads;
  restore set(ICU OFF)/set(LOCAL ON) for FreeRTOS/embedded targets
- auto-disable dependent flags when PIP_HAS_THREADS=OFF:
  PIP_HAS_PROCESS, PIP_HAS_SERIAL (PIProcess derives from PIThread,
  PISerial/PIIODevice use PIThread) and INTROSPECTION (walks threads)
- LIBS_MAIN: link dl only with PIP_HAS_DYNLIB, pthread/util/rt only with
  PIP_HAS_THREADS (rt was never linked on APPLE), socket on QNX_HOST only
  with PIP_HAS_SOCKET; WIN32 list untouched - arm-none-eabi has no
  libdl/libpthread/librt so Pico firmware links again
- collapse repeated 'NOT DEFINED PICO_SDK_PATH' utils checks into
  _PIP_HOST_TOOLS variable
- FindPIP.cmake: check PIP_FREERTOS instead of the never-set
  PIP_EMBEDDED CMake variable (as in master)
- drop unused set(PIP_MICRO ON) from esp-pip
- wrap PIGrabberBase/PIPipelineThread in #ifdef PIP_HAS_THREADS like
  pithread.h so 'pip.h' compiles in no-threads builds
2026-08-22 14:06:05 +03:00
andrey e0133e23ec fix: remove Android feature-flag overrides and protect code from arbitrary flag combos
- drop the ANDROID_PLATFORM block forcing PROCESS/DYNLIB/FFT off:
  Android has /proc and dlopen and these features worked there in master
- __sighandler__: wrap PIProcess::currentPID() by PIP_HAS_PROCESS (0
  fallback), the dumpApplicationToFile() call itself is already guarded
  by PIP_INTROSPECTION && PIP_HAS_FILESYSTEM
- PISystemMonitor: guard /proc-related members (proc_dir/file/filem) and
  code paths (startOnProcess, run() non-Windows part, gatherThread /proc
  reader) by PIP_HAS_PROCESS/PIP_HAS_FILESYSTEM so the file compiles for
  any flag combination, e.g. -DPIP_HAS_PROCESS=OFF -DPIP_HAS_FILESYSTEM=OFF
2026-08-22 14:00:17 +03:00
andrey 35d3136ffc fix: use PIP_HAS_RTTI in state machine formatHash and make no-RTTI builds work
- pistatemachine_base.h checked non-existent macros __GXX_RTTI__/__RTTI__,
  so on GCC/Clang desktop builds formatHash() always returned 0 and the
  guard signature check in testGuard() never fired (UB on incompatible
  signatures). Now the real PIP_HAS_RTTI (pibase_macros.h) is used.
- no-RTTI fallback: each Function<Args...> instantiation takes a unique
  hash from a process-wide counter (a per-instantiation counter would
  give every signature the same hash on first call).
- __pip_typename__ primary template: replace hard static_assert with a
  generic fallback; containers/stream operators instantiate it for
  arbitrary T in no-RTTI builds (Pico/arm-none-eabi has no RTTI), so the
  assert made any no-RTTI build impossible. Explicit
  __PIP_TYPENAME_DECLARE specializations still take precedence.
2026-08-22 13:56:27 +03:00
andrey b82ad8e6cd fix: remove non-inline __PIInit_Initializer__ definitions from piinit.h (ODR violation)
The stub member definitions lived in the header and were picked up by
every TU including piinit.h, causing multiple-definition link errors in
embedded (PIP_EMBEDDED) builds. Definitions now live only in piinit.cpp;
the stub implementation is compiled in the '#else' branch guarded by
PIP_HAS_THREADS (no-PIInit builds are unchanged).
2026-08-22 13:46:35 +03:00
andrey 858d205fd3 fix: guard PIObject dump diagnostics by PIP_INTROSPECTION and drop PIP_FORCE_NO_PIINTROSPECTION
- invert friend block in piobject.h (friends needed when introspection
  is enabled) and remove dead friend PIObjectManager
- guard PIObject::dump()/dumpApplication()/dumpApplicationToFile()
  declarations and definitions by PIP_INTROSPECTION
  (dumpApplicationToFile additionally requires PIP_HAS_FILESYSTEM)
- guard dumpApplicationToFile() call in __sighandler__ by
  PIP_INTROSPECTION && PIP_HAS_FILESYSTEM
- replace '#if defined(PIP_INTROSPECTION) && !defined(PIP_FORCE_NO_PIINTROSPECTION)'
  with plain '#ifdef PIP_INTROSPECTION' everywhere, remove PIP_FORCE_NO_PIINTROSPECTION
- fix broken PIINTROSPECTION_CONTAINER_ALLOC(T, (as - ...)) in
  pideque.h/pivector.h ('as' no longer exists, use new_rsize)
2026-08-22 13:44:58 +03:00
peri4 b1060fd572 PIEthernet fix: no more close outdated fd on disconnect (error at work with MHD) 2026-08-17 20:26:36 +03:00
andrey 75cfdd2e4c small fix 2026-08-12 18:54:25 +03:00
andrey a94d5d536b remove spaces 2026-08-12 18:23:48 +03:00
andrey 7af2b0bb07 remove some ifdefs 2026-08-12 15:12:36 +03:00