### Install Examples Directory (CMake) Source: https://github.com/dieg0-a/posagentpro-src/blob/main/rapidjson/CMakeLists.txt Installs the 'example' directory to the documentation installation path, excluding intermediate build files. This makes the project's examples available for reference. ```cmake install(DIRECTORY example/ DESTINATION "${DOC_INSTALL_DIR}/examples" COMPONENT examples # Following patterns are for excluding the intermediate/object files # from an install of in-source CMake build. PATTERN "CMakeFiles" EXCLUDE PATTERN "Makefile" EXCLUDE PATTERN "cmake_install.cmake" EXCLUDE) ``` -------------------------------- ### Basic uWS C++ Application Example Source: https://github.com/dieg0-a/posagentpro-src/blob/main/uWebSockets/misc/READMORE.md A complete C++ example demonstrating how to create a uWS application, define a GET route for all paths, send a 'Hello World!' response, listen on port 9001, and run the event loop. It includes basic error handling for the listening process. ```c++ int main() { uWS::App().get("/*", [](auto *res, auto *req) { res->end("Hello World!"); }).listen(9001, [](auto *listenSocket) { if (listenSocket) { std::cout << "Listening for connections..." << std::endl; } }).run(); std::cout << "Shoot! We failed to listen and the App fell through, exiting now!" << std::endl; } ``` -------------------------------- ### Install Java Example File (CMake) Source: https://github.com/dieg0-a/posagentpro-src/blob/main/jpeg/libjpeg-turbo-main/CMakeLists.txt Installs the TJExample.java file to the documentation directory if the WITH_JAVA option is enabled. This allows users to access Java examples. ```cmake if(WITH_JAVA) install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/java/TJExample.java DESTINATION ${CMAKE_INSTALL_DOCDIR}) endif() ``` -------------------------------- ### TCP Echo Server Setup in C Source: https://github.com/dieg0-a/posagentpro-src/blob/main/uWebSockets/uSockets/libuv/docs/src/guide/networking.md Initializes a TCP server, binds it to a port, and starts listening for incoming connections. It uses uv_tcp_init, uv_tcp_bind, and uv_listen. The uv_ip4_addr utility converts IP and port to a sockaddr_in structure. ```c int main() { loop = uv_default_loop(); uv_tcp_t server; uv_tcp_init(loop, &server); uv_ip4_addr("0.0.0.0", DEFAULT_PORT, &addr); uv_tcp_bind(&server, (const struct sockaddr*)&addr, 0); int r = uv_listen((uv_stream_t*) &server, DEFAULT_BACKLOG, on_new_connection); if (r) { fprintf(stderr, "Listen error %s\n", uv_strerror(r)); return 1; } return uv_run(loop, UV_RUN_DEFAULT); } ``` -------------------------------- ### Build libuv from Source Source: https://github.com/dieg0-a/posagentpro-src/blob/main/uWebSockets/uSockets/libuv/docs/src/guide/introduction.md Instructions to build the libuv library from its source code. This involves running autogen.sh, configure, and make. No installation is required for building the examples. ```shell sh autogen.sh ./configure make ``` -------------------------------- ### Build Windows Installer (NMake) Source: https://github.com/dieg0-a/posagentpro-src/blob/main/jpeg/libjpeg-turbo-main/BUILDING.md Builds a Windows installer using NMake. Navigate to the build directory and execute 'nmake installer'. This requires the Nullsoft Install System (NSIS) to be installed and 'makensis.exe' to be in the PATH. ```shell cd {build_directory} nmake installer ``` -------------------------------- ### Build Windows Installer (MinGW) Source: https://github.com/dieg0-a/posagentpro-src/blob/main/jpeg/libjpeg-turbo-main/BUILDING.md Builds a Windows installer using MinGW. Navigate to the build directory and execute 'make installer'. This requires the Nullsoft Install System (NSIS) to be installed and 'makensis.exe' to be in the PATH. ```shell cd {build_directory} make installer ``` -------------------------------- ### JPEG Compression Setup with libjpeg-turbo (C) Source: https://github.com/dieg0-a/posagentpro-src/blob/main/libjpeg-turbo64/doc/example.txt This C code snippet demonstrates the initialization process for JPEG compression using the libjpeg library. It sets up the compression object, standard error handler, and prepares for data input. Dependencies include stdio.h, setjmp.h, and jpeglib.h. ```c #include #include "jpeglib.h" #include /* * IMAGE DATA FORMATS: * * The standard input image format is a rectangular array of pixels, with * each pixel having the same number of "component" values (color channels). * Each pixel row is an array of JSAMPLEs (which typically are unsigned chars). * If you are working with color data, then the color values for each pixel * must be adjacent in the row; for example, R,G,B,R,G,B,R,G,B,... for 24-bit * RGB color. * * For this example, we'll assume that this data structure matches the way * our application has stored the image in memory, so we can just pass a * pointer to our image buffer. In particular, let's say that the image is * RGB color and is described by: */ extern JSAMPLE *image_buffer; extern int image_height; extern int image_width; /* * Sample routine for JPEG compression. We assume that the target file name * and a compression quality factor are passed in. */ GLOBAL(void) write_JPEG_file(char *filename, int quality) { /* This struct contains the JPEG compression parameters and pointers to * working space (which is allocated as needed by the JPEG library). * It is possible to have several such structures, representing multiple * compression/decompression processes, in existence at once. We refer * to any one struct (and its associated working data) as a "JPEG object". */ struct jpeg_compress_struct cinfo; /* This struct represents a JPEG error handler. It is declared separately * because applications often want to supply a specialized error handler * (see the second half of this file for an example). But here we just * take the easy way out and use the standard error handler, which will * print a message on stderr and call exit() if compression fails. * Note that this struct must live as long as the main JPEG parameter * struct, to avoid dangling-pointer problems. */ struct jpeg_error_mgr jerr; /* More stuff */ FILE *outfile; JSAMPROW row_pointer[1]; int row_stride; /* Step 1: allocate and initialize JPEG compression object */ /* We have to set up the error handler first, in case the initialization * step fails. (Unlikely, but it could happen if you are out of memory.) * This routine fills in the contents of struct jerr, and returns jerr's * address which we place into the link field in cinfo. */ cinfo.err = jpeg_std_error(&jerr); /* Now we can initialize the JPEG compression object. */ jpeg_create_compress(&cinfo); ``` -------------------------------- ### CMake Project Configuration and Qt Setup Source: https://github.com/dieg0-a/posagentpro-src/blob/main/CMakeLists.txt Sets up the minimum CMake version, project name, languages (C++ and C), and configures Qt 6 or Qt 5 components like Widgets and PrintSupport. It also handles platform-specific Qt installation paths for Windows. ```cmake cmake_minimum_required(VERSION 3.5) project(posagent VERSION 0.1 LANGUAGES CXX C) if (WIN32) set (CMAKE_PREFIX_PATH "C:\\Qt\\6.5.2\\msvc2019_64") endif() set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED) find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets PrintSupport REQUIRED) ``` -------------------------------- ### Build Windows Installer (Visual Studio IDE) Source: https://github.com/dieg0-a/posagentpro-src/blob/main/jpeg/libjpeg-turbo-main/BUILDING.md Builds a Windows installer using the Visual Studio IDE. Open the solution and build the 'installer' target. The installer package will be located in the build directory or a subdirectory corresponding to the build configuration (e.g., Debug, Release). ```shell Build the "installer" target in Visual Studio IDE ``` -------------------------------- ### Add Examples Subdirectory (CMake) Source: https://github.com/dieg0-a/posagentpro-src/blob/main/rapidjson/CMakeLists.txt Conditionally adds the 'example' subdirectory to the build if the RAPIDJSON_BUILD_EXAMPLES option is enabled. This allows the project's examples to be compiled and potentially run as part of the build process. ```cmake if(RAPIDJSON_BUILD_EXAMPLES) add_subdirectory(example) endif() ``` -------------------------------- ### Include JPEG Library Headers (C) Source: https://github.com/dieg0-a/posagentpro-src/blob/main/libjpeg-turbo64/doc/libjpeg.txt To use the JPEG library, include the `jpeglib.h` header file. Ensure system headers like `` (for `FILE` and `size_t`) are included beforehand. For error codes, also include `jerror.h`. Install `jconfig.h` and `jmorecfg.h` along with these for a complete setup. ```c #include /* For FILE and size_t */ #include "jpeglib.h" #include "jerror.h" /* Optional, for error codes */ ``` -------------------------------- ### Install with Homebrew Source: https://github.com/dieg0-a/posagentpro-src/blob/main/uWebSockets/uSockets/libuv/README.md Installs the libuv library using the Homebrew package manager on macOS. This command installs the latest development version from the HEAD of the repository. ```bash brew install --HEAD libuv ``` -------------------------------- ### Example Usage: Hello World Server Source: https://github.com/dieg0-a/posagentpro-src/blob/main/uWebSockets/misc/READMORE.md A complete example demonstrating how to set up a simple 'Hello World' server, listen on port 9001, and run the event loop. ```APIDOC ## GET /* ### Description Handles incoming GET requests for any path and responds with 'Hello World!'. ### Method GET ### Endpoint `/*` ### Parameters #### Path Parameters - ***** (string) - Matches any path. ### Request Example ```http GET / HTTP/1.1 Host: localhost:9001 ``` ### Response #### Success Response (200) - **body** (string) - The response body, which is 'Hello World!'. #### Response Example ``` Hello World! ``` ## App.listen and App.run Combined Example ### Description This example shows a complete `main` function that initializes a uWebSockets.js application, defines a GET route, starts listening on port 9001, and runs the event loop. ### Method Initialization and Execution ### Endpoint Implicitly handled by `App.listen` and `App.run`. ### Request Example ```cpp int main() { uWS::App().get("/*", [](auto *res, auto *req) { res->end("Hello World!"); }).listen(9001, [](auto *listenSocket) { if (listenSocket) { std::cout << "Listening for connections..." << std::endl; } }).run(); std::cout << "Shoot! We failed to listen and the App fell through, exiting now!" << std::endl; } ``` ### Response #### Success Response (200) - **console output** (string) - "Listening for connections..." will be printed if the server starts successfully. #### Response Example ``` Listening for connections... ``` ### Notes If `listen` fails, `App.run` will return, and the message "Shoot! We failed to listen and the App fell through, exiting now!" will be printed. ``` -------------------------------- ### Install Project Documentation Files (CMake) Source: https://github.com/dieg0-a/posagentpro-src/blob/main/jpeg/libjpeg-turbo-main/CMakeLists.txt Installs various documentation and text files from the source directory to the installation's documentation directory. This includes README files, example files, and license information. ```cmake install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/README.ijg ${CMAKE_CURRENT_SOURCE_DIR}/README.md ${CMAKE_CURRENT_SOURCE_DIR}/example.txt ${CMAKE_CURRENT_SOURCE_DIR}/tjexample.c ${CMAKE_CURRENT_SOURCE_DIR}/libjpeg.txt ${CMAKE_CURRENT_SOURCE_DIR}/structure.txt ${CMAKE_CURRENT_SOURCE_DIR}/usage.txt ${CMAKE_CURRENT_SOURCE_DIR}/wizard.txt ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.md DESTINATION ${CMAKE_INSTALL_DOCDIR}) ``` -------------------------------- ### Sample Plugin Implementation (hello.c) Source: https://github.com/dieg0-a/posagentpro-src/blob/main/uWebSockets/uSockets/libuv/docs/src/guide/utilities.md This C file provides a simple example of a plugin. It includes the `plugin.h` header and defines an `initialize` function. This function calls `mfp_register` to register the plugin with the name "Hello World!". The application expects all plugins to export an `initialize` function. ```c #include "plugin.h" void initialize() { mfp_register("Hello World!"); } ``` -------------------------------- ### Create and Install cjpeg Fuzzer - CMake Source: https://github.com/dieg0-a/posagentpro-src/blob/main/jpeg/libjpeg-turbo-main/fuzz/CMakeLists.txt This CMake code defines the 'cjpeg_fuzzer' executable, linking it with the specified FUZZ_LIBRARY and jpeg-static. It then installs the fuzzer executable to the directory specified by FUZZ_BINDIR. ```cmake add_executable(cjpeg_fuzzer${FUZZER_SUFFIX} cjpeg.cc ../cdjpeg.c ../rdbmp.c ../rdgif.c ../rdppm.c ../rdswitch.c ../rdtarga.c) set_property(TARGET cjpeg_fuzzer${FUZZER_SUFFIX} PROPERTY COMPILE_FLAGS ${COMPILE_FLAGS}) target_link_libraries(cjpeg_fuzzer${FUZZER_SUFFIX} ${FUZZ_LIBRARY} jpeg-static) install(TARGETS cjpeg_fuzzer${FUZZER_SUFFIX} RUNTIME DESTINATION ${FUZZ_BINDIR}) ``` -------------------------------- ### Add Transform Fuzz Target - CMake Source: https://github.com/dieg0-a/posagentpro-src/blob/main/jpeg/libjpeg-turbo-main/fuzz/CMakeLists.txt This CMake command utilizes the 'add_fuzz_target' macro to create and install the 'transform' fuzz target using the 'transform.cc' source file. ```cmake add_fuzz_target(transform transform.cc) ``` -------------------------------- ### Add Compress Fuzz Target - CMake Source: https://github.com/dieg0-a/posagentpro-src/blob/main/jpeg/libjpeg-turbo-main/fuzz/CMakeLists.txt This CMake command utilizes the 'add_fuzz_target' macro to create and install the 'compress' fuzz target using the 'compress.cc' source file. ```cmake add_fuzz_target(compress compress.cc) ``` -------------------------------- ### Add Decompress YUV Fuzz Target - CMake Source: https://github.com/dieg0-a/posagentpro-src/blob/main/jpeg/libjpeg-turbo-main/fuzz/CMakeLists.txt This CMake command utilizes the 'add_fuzz_target' macro to create and install the 'decompress_yuv' fuzz target using the 'decompress_yuv.cc' source file. ```cmake add_fuzz_target(decompress_yuv decompress_yuv.cc) ``` -------------------------------- ### Initialize uvwget with libuv and libcurl Source: https://github.com/dieg0-a/posagentpro-src/blob/main/uWebSockets/uSockets/libuv/docs/src/guide/utilities.md Sets up the libuv event loop, initializes libcurl globally, and configures the multi-curl handle with socket and timer callbacks. It then adds provided URLs for download. ```c #include #include #include #include #include uv_loop_t *loop; CURLM *curl_handle; uv_timer_t timeout; int main(int argc, char **argv) { loop = uv_default_loop(); if (argc <= 1) return 0; if (curl_global_init(CURL_GLOBAL_ALL)) { fprintf(stderr, "Could not init cURL\n"); return 1; } uv_timer_init(loop, &timeout); curl_handle = curl_multi_init(); curl_multi_setopt(curl_handle, CURLMOPT_SOCKETFUNCTION, handle_socket); curl_multi_setopt(curl_handle, CURLMOPT_TIMERFUNCTION, start_timeout); while (argc-- > 1) { add_download(argv[argc], argc); } uv_run(loop, UV_RUN_DEFAULT); curl_multi_cleanup(curl_handle); return 0; } ``` -------------------------------- ### Add Compress YUV Fuzz Target - CMake Source: https://github.com/dieg0-a/posagentpro-src/blob/main/jpeg/libjpeg-turbo-main/fuzz/CMakeLists.txt This CMake command utilizes the 'add_fuzz_target' macro to create and install the 'compress_yuv' fuzz target using the 'compress_yuv.cc' source file. ```cmake add_fuzz_target(compress_yuv compress_yuv.cc) ``` -------------------------------- ### Hello World libuv Program in C Source: https://github.com/dieg0-a/posagentpro-src/blob/main/uWebSockets/uSockets/libuv/docs/src/guide/basics.md A basic 'Hello World' program using libuv. It initializes an event loop, prints a message, runs the loop (which exits immediately as there are no pending events), and then closes the loop. This demonstrates the minimal setup required for a libuv application. ```c #include #include #include int main() { uv_loop_t *loop = malloc(sizeof(uv_loop_t)); uv_loop_init(loop); printf("Now quitting.\n"); uv_run(loop, UV_RUN_DEFAULT); uv_loop_close(loop); free(loop); return 0; } ``` -------------------------------- ### Defining Routes with HTTP Methods Source: https://github.com/dieg0-a/posagentpro-src/blob/main/uWebSockets/misc/READMORE.md This section explains how to attach behavior to URL routes by pairing a lambda function with an HTTP method and a URL pattern. It covers common methods like GET and POST and provides an example. ```APIDOC ## GET /hello ### Description Handles GET requests to the /hello endpoint and responds with 'Hello World!'. ### Method GET ### Endpoint /hello ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **body** (string) - The response body, e.g., 'Hello World!'. #### Response Example ``` Hello World! ``` ``` -------------------------------- ### Building POS Agent Pro with CMake (Bash) Source: https://context7.com/dieg0-a/posagentpro-src/llms.txt Instructions for building the POS Agent Pro project using CMake on Linux and Windows. Requires Qt6, libjpeg-turbo, zlib, and OpenSSL. Specifies commands for creating build directories, configuring CMake, and compiling the project. ```bash # Linux build mkdir build && cd build cmake .. make # Required dependencies (Ubuntu/Debian) sudo apt install qt6-base-dev qt6-tools-dev libssl-dev libjpeg-turbo8-dev zlib1g-dev # Windows build (requires Qt 6.5.2 MSVC) mkdir build && cd build cmake -G "Visual Studio 17 2022" -A x64 .. cmake --build . --config Release ``` -------------------------------- ### Fuzz Target Creation Macro - CMake Source: https://github.com/dieg0-a/posagentpro-src/blob/main/jpeg/libjpeg-turbo-main/fuzz/CMakeLists.txt This CMake macro, 'add_fuzz_target', simplifies the creation of fuzz targets. It defines an executable for the given source file, links it with the FUZZ_LIBRARY and turbojpeg-static, and installs it to the FUZZ_BINDIR. ```cmake macro(add_fuzz_target target source_file) add_executable(${target}_fuzzer${FUZZER_SUFFIX} ${source_file}) target_link_libraries(${target}_fuzzer${FUZZER_SUFFIX} ${FUZZ_LIBRARY} turbojpeg-static) install(TARGETS ${target}_fuzzer${FUZZER_SUFFIX} RUNTIME DESTINATION ${FUZZ_BINDIR}) endmacro() ``` -------------------------------- ### Get Red Component Offset in Pixel Format (Java) Source: https://github.com/dieg0-a/posagentpro-src/blob/main/jpeg/libjpeg-turbo-main/java/doc/org/libjpegturbo/turbojpeg/TJ.html Retrieves the byte offset of the red component from the start of a pixel for a specified pixel format. This method aids in precise pixel data access. ```java static int getRedOffset(int pixelFormat) ``` -------------------------------- ### Main Application for Loading Plugins (main.c) Source: https://github.com/dieg0-a/posagentpro-src/blob/main/uWebSockets/uSockets/libuv/docs/src/guide/utilities.md This C program demonstrates how to load shared libraries as plugins using libuv. It iterates through command-line arguments, treating each as a plugin library path. For each library, it uses `uv_dlopen` to load it and `uv_dlsym` to find and execute an `initialize` function. Error handling for loading and symbol lookup is included. ```c #include "plugin.h" typedef void (*init_plugin_function)(); void mfp_register(const char *name) { fprintf(stderr, "Registered plugin \"%s\"\n", name); } int main(int argc, char **argv) { if (argc == 1) { fprintf(stderr, "Usage: %s [plugin1] [plugin2] ...\n", argv[0]); return 0; } uv_lib_t *lib = (uv_lib_t*) malloc(sizeof(uv_lib_t)); while (--argc) { fprintf(stderr, "Loading %s\n", argv[argc]); if (uv_dlopen(argv[argc], lib)) { fprintf(stderr, "Error: %s\n", uv_dlerror(lib)); continue; } init_plugin_function init_plugin; if (uv_dlsym(lib, "initialize", (void **) &init_plugin)) { fprintf(stderr, "dlsym error: %s\n", uv_dlerror(lib)); continue; } init_plugin(); } return 0; } ``` -------------------------------- ### Start JPEG Compression (C) Source: https://github.com/dieg0-a/posagentpro-src/blob/main/libjpeg-turbo64/doc/libjpeg.txt This C code shows how to initiate the compression process for a JPEG image. It mentions the possibility of passing FALSE to `jpeg_start_compress` to create abbreviated images, which can be useful when writing a series of images to a single file. ```c jpeg_start_compress(&cinfo); ``` -------------------------------- ### Get Alpha Component Offset in Pixel Format (Java) Source: https://github.com/dieg0-a/posagentpro-src/blob/main/jpeg/libjpeg-turbo-main/java/doc/org/libjpegturbo/turbojpeg/TJ.html Retrieves the byte offset of the alpha component from the start of a pixel for a given pixel format. This is useful for direct memory manipulation of pixel data. ```java static int getAlphaOffset(int pixelFormat) ``` -------------------------------- ### Get Green Component Offset in Pixel Format (Java) Source: https://github.com/dieg0-a/posagentpro-src/blob/main/jpeg/libjpeg-turbo-main/java/doc/org/libjpegturbo/turbojpeg/TJ.html Retrieves the byte offset of the green component from the start of a pixel for a given pixel format. This information is crucial for correctly accessing and manipulating color data. ```java static int getGreenOffset(int pixelFormat) ``` -------------------------------- ### Get Blue Component Offset in Pixel Format (Java) Source: https://github.com/dieg0-a/posagentpro-src/blob/main/jpeg/libjpeg-turbo-main/java/doc/org/libjpegturbo/turbojpeg/TJ.html Retrieves the byte offset of the blue component from the start of a pixel for a given pixel format. This method is essential for understanding the memory layout of pixel data. ```java static int getBlueOffset(int pixelFormat) ``` -------------------------------- ### Add libjpeg_turbo Fuzz Target - CMake Source: https://github.com/dieg0-a/posagentpro-src/blob/main/jpeg/libjpeg-turbo-main/fuzz/CMakeLists.txt This CMake command uses the 'add_fuzz_target' macro to create and install the 'libjpeg_turbo' fuzz target (replacing a previous decompress_fuzzer) using the 'decompress.cc' source file. This naming preserves corpora from Google's OSS-Fuzz. ```cmake # NOTE: This target is named libjpeg_turbo_fuzzer instead of decompress_fuzzer # in order to preserve the corpora from Google's OSS-Fuzz target for # libjpeg-turbo, which this target replaces. add_fuzz_target(libjpeg_turbo decompress.cc) ``` -------------------------------- ### Set up File System Event Watcher using libuv Source: https://github.com/dieg0-a/posagentpro-src/blob/main/uWebSockets/uSockets/libuv/docs/src/guide/filesystem.md Illustrates setting up file system event watchers using libuv's `uv_fs_event_init` and `uv_fs_event_start`. This function allows monitoring specific files or directories for changes and executing a callback when modifications occur. The example focuses on running a command when watched files change, with current limitations to OSX and Windows. ```c int main(int argc, char **argv) { if (argc <= 2) { fprintf(stderr, "Usage: %s [file2 ...]\n", argv[0]); return 1; } loop = uv_default_loop(); command = argv[1]; while (argc-- > 2) { fprintf(stderr, "Adding watch on %s\n", argv[argc]); uv_fs_event_t *fs_event_req = malloc(sizeof(uv_fs_event_t)); uv_fs_event_init(loop, fs_event_req); // The recursive flag watches subdirectories too. uv_fs_event_start(fs_event_req, run_command, argv[argc], UV_FS_EVENT_RECURSIVE); } return uv_run(loop, UV_RUN_DEFAULT); } ``` -------------------------------- ### Fuzz Target Directory and Library Configuration - CMake Source: https://github.com/dieg0-a/posagentpro-src/blob/main/jpeg/libjpeg-turbo-main/fuzz/CMakeLists.txt This CMake code configures the installation directory for fuzz targets and specifies the fuzzer library. It uses cache variables to allow user configuration and provides error messages if the required variables are not set. ```cmake set(FUZZ_BINDIR "" CACHE PATH "Directory into which fuzz targets should be installed") if(NOT FUZZ_BINDIR) message(FATAL_ERROR "FUZZ_BINDIR must be specified.") endif() message(STATUS "FUZZ_BINDIR = ${FUZZ_BINDIR}") set(FUZZ_LIBRARY "" CACHE STRING "Path to fuzzer library or flags necessary to link with it") if(NOT FUZZ_LIBRARY) message(FATAL_ERROR "FUZZ_LIBRARY must be specified.") endif() message(STATUS "FUZZ_LIBRARY = ${FUZZ_LIBRARY}") ``` -------------------------------- ### Listening on a Port Source: https://github.com/dieg0-a/posagentpro-src/blob/main/uWebSockets/misc/READMORE.md This section explains how to start listening for incoming connections on a specified port using the App.listen method. ```APIDOC ## POST /listen ### Description Starts listening for new connections on a specified port. ### Method POST ### Endpoint /listen ### Parameters #### Query Parameters - **port** (integer) - Required - The port number to listen on. #### Request Body This endpoint does not require a request body. ### Response #### Success Response (200) - **listenSocket** (object | null) - A handle to the listening socket, or null if an error occurred. #### Response Example ```json { "listenSocket": "" } ``` ### Notes Canceling listening is done with the `us_listen_socket_close` function. ``` -------------------------------- ### JPEG Compression Suspension Example Source: https://github.com/dieg0-a/posagentpro-src/blob/main/jpeg/libjpeg-turbo-main/libjpeg.txt Demonstrates how to implement compression suspension by returning FALSE from `empty_output_buffer`. This allows the application to regain control when the output buffer is full. This is typically implemented in C. ```c typedef struct { struct jpeg_destination_mgr pub; FILE * outfile; JOCTET buffer[BUF_SIZE]; } my_destination_mgr; METHODDEF(void) empty_output_buffer (j_compress_ptr cinfo) { my_destination_mgr *dest = (my_destination_mgr *) cinfo->dest; if (fwrite(dest->buffer, 1, BUF_SIZE, dest->outfile) != BUF_SIZE) { ERREXIT(cinfo, JERR_FILE_WRITE); } dest->pub.next_output_byte = dest->buffer; dest->pub.free_in_buffer = BUF_SIZE; return FALSE; } METHODDEF(void) init_destination (j_compress_ptr cinfo) { my_destination_mgr *dest = (my_destination_mgr *) cinfo->dest; dest->pub.next_output_byte = dest->buffer; dest->pub.free_in_buffer = BUF_SIZE; } METHODDEF(void) term_destination (j_compress_ptr cinfo) { my_destination_mgr *dest = (my_destination_mgr *) cinfo->dest; size_t datacount = BUF_SIZE - dest->pub.free_in_buffer; if (datacount > 0) { if (fwrite(dest->buffer, 1, datacount, dest->outfile) != datacount) { ERREXIT(cinfo, JERR_FILE_WRITE); } } (void) fflush(dest->outfile); } GLOBAL(void) jpeg_my_dest (j_compress_ptr cinfo, FILE * outfile) { my_destination_mgr *dest; if (cinfo->dest == NULL) { cinfo->dest = (struct jpeg_destination_mgr *) (*cinfo->mem->alloc) ((j_common_ptr) cinfo, sizeof(my_destination_mgr)); dest = (my_destination_mgr *) cinfo->dest; dest->init_destination = init_destination; dest->empty_output_buffer = empty_output_buffer; dest->term_destination = term_destination; } dest->outfile = outfile; } ``` -------------------------------- ### JPEG File Reading with Error Handling Setup (C) Source: https://github.com/dieg0-a/posagentpro-src/blob/main/jpeg/libjpeg-turbo-main/example.txt This C code snippet illustrates the setup for reading a JPEG file while incorporating the custom error handling mechanism. It initializes the JPEG decompression object, sets up the custom error handler, and establishes a `setjmp` context. If a JPEG error occurs, control is returned to the `setjmp` point, allowing for cleanup operations like closing the file and destroying the JPEG object before returning an error status. ```c METHODDEF(int) do_read_JPEG_file(struct jpeg_decompress_struct *cinfo, char *filename); GLOBAL(int) read_JPEG_file(char *filename) { struct jpeg_decompress_struct cinfo; return do_read_JPEG_file(&cinfo, filename); } METHODDEF(int) do_read_JPEG_file(struct jpeg_decompress_struct *cinfo, char *filename) { struct my_error_mgr jerr; FILE *infile; JSAMPARRAY buffer; int row_stride; if ((infile = fopen(filename, "rb")) == NULL) { fprintf(stderr, "can't open %s\n", filename); return 0; } cinfo->err = jpeg_std_error(&jerr.pub); jerr.pub.error_exit = my_error_exit; if (setjmp(jerr.setjmp_buffer)) { jpeg_destroy_decompress(cinfo); fclose(infile); return 0; } jpeg_create_decompress(cinfo); jpeg_stdio_src(cinfo, infile); (void)jpeg_read_header(cinfo, TRUE); return 1; } ``` -------------------------------- ### Spawn a Child Process using uv_spawn in C Source: https://github.com/dieg0-a/posagentpro-src/blob/main/uWebSockets/uSockets/libuv/docs/src/guide/processes.md Demonstrates how to spawn a child process (e.g., 'mkdir') using libuv's uv_spawn function. It configures process options, including arguments and an exit callback, and handles potential errors during spawning. The process ID is printed upon successful launch. ```c uv_loop_t *loop; uv_process_t child_req; uv_process_options_t options; int main() { loop = uv_default_loop(); char* args[3]; args[0] = "mkdir"; args[1] = "test-dir"; args[2] = NULL; options.exit_cb = on_exit; options.file = "mkdir"; options.args = args; int r; if ((r = uv_spawn(loop, &child_req, &options))) { fprintf(stderr, "%s\n", uv_strerror(r)); return 1; } else { fprintf(stderr, "Launched process with ID %d\n", child_req.pid); } return uv_run(loop, UV_RUN_DEFAULT); } ``` -------------------------------- ### zlib C Example: File Compression and Decompression Source: https://github.com/dieg0-a/posagentpro-src/blob/main/zlib/examples/zlib_how.html This C code snippet demonstrates the core functionality of zlib for compressing and decompressing data from files. It utilizes deflateInit, deflate, deflateEnd, inflateInit, inflate, and inflateEnd. The example addresses buffer management and error handling, crucial for robust zlib integration. ```c /* zpipe.c: example of proper use of zlib's inflate() and deflate() Not copyrighted -- provided to the public domain Version 1.4 11 December 2005 Mark Adler */ /* Version history: 1.0 30 Oct 2004 First version 1.1 8 Nov 2004 Add void casting for unused return values Use switch statement for inflate() return values 1.2 9 Nov 2004 Add assertions to document zlib guarantees 1.3 6 Apr 2005 Remove incorrect assertion in inf() 1.4 11 Dec 2005 Add hack to avoid MSDOS end-of-line conversions Avoid some compiler warnings for input and output buffers */ #include #include #include #include "zlib.h" #if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__) # include # include # define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY) #else # define SET_BINARY_MODE(file) /* */ #endif /* allocate a buffer for compression */ #define INBUFSIZE 16384 #define OUTBUFSIZE 16384 /* compression function */ int def(FILE *fin, FILE *fout, int level) { int ret, flush; unsigned have; z_stream strm; unsigned char in[INBUFSIZE]; unsigned char out[OUTBUFSIZE]; strm.zalloc = Z_NULL; strm.zfree = Z_NULL; strm.opaque = Z_NULL; if (deflateInit(&strm, level) != Z_OK) return Z_ERRNO; /* feed the data to zlib */ do { strm.avail_in = fread(in, 1, INBUFSIZE, fin); if (ferror(fin)) { (void)deflateEnd(&strm); return Z_ERRNO; } flush = feof(fin) ? Z_FINISH : Z_NO_FLUSH; strm.next_in = in; /* run deflate() on input until output buffer not full, or all input has been consumed and flushed. */ do { strm.avail_out = OUTBUFSIZE; strm.next_out = out; ret = deflate(&strm, flush); assert(ret != Z_STREAM_ERROR); have = OUTBUFSIZE - strm.avail_out; if (fwrite(out, 1, have, fout) != have || ferror(fout)) { (void)deflateEnd(&strm); return Z_ERRNO; } } while (strm.avail_out == 0); } while (flush != Z_FINISH); /* clean up and return */ (void)deflateEnd(&strm); return Z_OK; } /* decompress function */ int inf(FILE *fin, FILE *fout) { int ret; unsigned have; z_stream strm; unsigned char in[INBUFSIZE]; unsigned char out[OUTBUFSIZE]; /* window size actually depends on the maximum window size in the data */ /* given that the maximum window size is 32K, this is the maximum supported value */ strm.zalloc = Z_NULL; strm.zfree = Z_NULL; strm.opaque = Z_NULL; strm.avail_in = 0; strm.next_in = Z_NULL; if (inflateInit(&strm) != Z_OK) return Z_ERRNO; /* decompress until deflate stream ends or error */ do { strm.avail_in = fread(in, 1, INBUFSIZE, fin); if (ferror(fin)) { (void)inflateEnd(&strm); return Z_ERRNO; } if (strm.avail_in == 0) break; strm.next_in = in; /* run inflate() on input until output buffer not full, or all input has been consumed and decompressing to end. inflate() should be called until enough output has been generated */ do { strm.avail_out = OUTBUFSIZE; strm.next_out = out; ret = inflate(&strm, Z_NO_FLUSH); assert(ret != Z_STREAM_ERROR); /* state not clobbered */ switch (ret) { case Z_NEED_DICT: ret = Z_DATA_ERROR; case Z_DATA_ERROR: case Z_MEM_ERROR: (void)inflateEnd(&strm); return ret; } have = OUTBUFSIZE - strm.avail_out; if (fwrite(out, 1, have, fout) != have || ferror(fout)) { (void)inflateEnd(&strm); return Z_ERRNO; } } while (strm.avail_out == 0); } while (ret != Z_STREAM_END); /* clean up and return */ (void)inflateEnd(&strm); return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR; } /* main routine */ int main(int argc, char **argv) { FILE *fin; FILE *fout; int err; int level = Z_DEFAULT_COMPRESSION; /* turn on binary mode for stdin and stdout */ SET_BINARY_MODE(stdin); SET_BINARY_MODE(stdout); /* do compression and decompression */ if (argc != 3) { fputs("usage: zpipe -level " " \n", stderr); return 1; } if (strcmp(argv[1], "-level") == 0) { if (argc != 4) { fputs("usage: zpipe -level " " \n", stderr); return 1; } level = atoi(argv[2]); if (level < 0 || level > 9) { fputs("invalid compression level: ", stderr); fprintf(stderr, "%d\n", level); return 1; } fin = fopen(argv[3], "rb"); if (fin == NULL) { perror("fopen"); return 1; } fout = fopen(argv[4], "wb"); if (fout == NULL) { perror("fopen"); fclose(fin); return 1; } err = def(fin, fout, level); if (err != Z_OK) { fputs("zpipe: deflate failed with error code " , stderr); fprintf(stderr, "%d\n", err); fclose(fin); fclose(fout); return 1; } } else { fin = fopen(argv[1], "rb"); if (fin == NULL) { perror("fopen"); return 1; } fout = fopen(argv[2], "wb"); if (fout == NULL) { perror("fopen"); fclose(fin); return 1; } err = inf(fin, fout); if (err != Z_OK) { fputs("zpipe: inflate failed with error code " , stderr); fprintf(stderr, "%d\n", err); fclose(fin); fclose(fout); return 1; } } fclose(fin); fclose(fout); return 0; } ``` -------------------------------- ### Initialize Output Buffer for Deflate (C) Source: https://github.com/dieg0-a/posagentpro-src/blob/main/zlib/examples/zlib_how.html Sets the available output buffer size and the pointer to the output buffer for the zlib deflate function. This prepares the space where compressed data will be written. ```c strm.avail_out = CHUNK; strm.next_out = out; ``` -------------------------------- ### Initialize JPEG Compression Defaults (C) Source: https://github.com/dieg0-a/posagentpro-src/blob/main/libjpeg-turbo64/doc/libjpeg.txt Sets all JPEG compression parameters to reasonable defaults. It requires the input image's color space to be set in cinfo->in_color_space. This is a foundational step before setting other parameters. ```c void jpeg_set_defaults (j_compress_ptr cinfo); ``` -------------------------------- ### Install README File (CMake) Source: https://github.com/dieg0-a/posagentpro-src/blob/main/rapidjson/CMakeLists.txt Installs the 'readme.md' file to the documentation installation directory. This makes the project's main README accessible alongside the installed documentation. ```cmake install(FILES readme.md DESTINATION "${DOC_INSTALL_DIR}" COMPONENT doc) ```