Zero-copy FTP/HTTP Daemon compatible with all POSIX systems
| 1 | /* |
| 2 | MIT License |
| 3 | |
| 4 | Copyright (c) 2026 Seregon |
| 5 | |
| 6 | Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | of this software and associated documentation files (the "Software"), to deal |
| 8 | in the Software without restriction, including without limitation the rights |
| 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | copies of the Software, and to permit persons to whom the Software is |
| 11 | furnished to do so, subject to the following conditions: |
| 12 | |
| 13 | The above copyright notice and this permission notice shall be included in all |
| 14 | copies or substantial portions of the Software. |
| 15 | |
| 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | SOFTWARE. |
| 23 | */ |
| 24 | |
| 25 | /** |
| 26 | * @file pal_notification.c |
| 27 | * @brief Platform Abstraction Layer - Notification Implementation (PS4/PS5) |
| 28 | * |
| 29 | * @author SeregonWar |
| 30 | * @version 1.0.0 |
| 31 | * @date 2026-02-13 |
| 32 | * |
| 33 | */ |
| 34 | #include "pal_notification.h" |
| 35 | |
| 36 | #if defined(PLATFORM_PS4) |
| 37 | |
| 38 | #include <stddef.h> |
| 39 | #include <stdint.h> |
| 40 | #include <stdio.h> |
| 41 | #include <string.h> |
| 42 | |
| 43 | typedef struct notify_request { |
| 44 | char padding[45]; |
| 45 | char message[3075]; |
| 46 | } notify_request_t; |
| 47 | |
| 48 | __attribute__((weak)) |
| 49 | int sceKernelSendNotificationRequest(int, notify_request_t *, size_t, int); |
| 50 | |
| 51 | static int g_notify_available = 0; |
| 52 | |
| 53 | int pal_notification_init(void) |
| 54 | { |
| 55 | if (sceKernelSendNotificationRequest == NULL) { |
| 56 | g_notify_available = 0; |
| 57 | return -1; |
| 58 | } |
| 59 | g_notify_available = 1; |
| 60 | return 0; |
| 61 | } |
| 62 | |
| 63 | void pal_notification_shutdown(void) |
| 64 | { |
| 65 | g_notify_available = 0; |
| 66 | } |
| 67 | |
| 68 | void pal_notification_send(const char *message) |
| 69 | { |
| 70 | if ((g_notify_available == 0) || (message == NULL)) { |
| 71 | return; |
| 72 | } |
| 73 | |
| 74 | notify_request_t req; |
| 75 | memset(&req, 0, sizeof(req)); |
| 76 | (void)snprintf(req.message, sizeof(req.message), "%s", message); |
| 77 | if (sceKernelSendNotificationRequest != NULL) { |
| 78 | (void)sceKernelSendNotificationRequest(0, &req, sizeof(req), 0); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | #elif defined(PLATFORM_PS5) |
| 83 | |
| 84 | #include <stddef.h> |
| 85 | #include <stdint.h> |
| 86 | #include <stdio.h> |
| 87 | #include <string.h> |
| 88 | |
| 89 | typedef struct notify_request { |
| 90 | char padding[45]; |
| 91 | char message[3075]; |
| 92 | } notify_request_t; |
| 93 | |
| 94 | __attribute__((weak)) |
| 95 | int sceKernelSendNotificationRequest(int, notify_request_t *, size_t, int); |
| 96 | |
| 97 | static int g_notify_available = 0; |
| 98 | |
| 99 | int pal_notification_init(void) |
| 100 | { |
| 101 | if (sceKernelSendNotificationRequest == NULL) { |
| 102 | g_notify_available = 0; |
| 103 | return -1; |
| 104 | } |
| 105 | g_notify_available = 1; |
| 106 | return 0; |
| 107 | } |
| 108 | |
| 109 | void pal_notification_shutdown(void) |
| 110 | { |
| 111 | g_notify_available = 0; |
| 112 | } |
| 113 | |
| 114 | void pal_notification_send(const char *message) |
| 115 | { |
| 116 | if ((g_notify_available == 0) || (message == NULL)) { |
| 117 | return; |
| 118 | } |
| 119 | |
| 120 | notify_request_t req; |
| 121 | memset(&req, 0, sizeof(req)); |
| 122 | (void)snprintf(req.message, sizeof(req.message), "%s", message); |
| 123 | if (sceKernelSendNotificationRequest != NULL) { |
| 124 | (void)sceKernelSendNotificationRequest(0, &req, sizeof(req), 0); |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | #else |
| 129 | |
| 130 | #include <stddef.h> |
| 131 | #include <syslog.h> |
| 132 | |
| 133 | static int g_syslog_open = 0; |
| 134 | |
| 135 | int pal_notification_init(void) |
| 136 | { |
| 137 | if (g_syslog_open == 0) { |
| 138 | openlog("zftpd", LOG_PID | LOG_CONS, LOG_DAEMON); |
| 139 | g_syslog_open = 1; |
| 140 | } |
| 141 | return 0; |
| 142 | } |
| 143 | |
| 144 | void pal_notification_shutdown(void) |
| 145 | { |
| 146 | if (g_syslog_open != 0) { |
| 147 | closelog(); |
| 148 | g_syslog_open = 0; |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | void pal_notification_send(const char *message) |
| 153 | { |
| 154 | if (message == NULL) { |
| 155 | return; |
| 156 | } |
| 157 | |
| 158 | if (g_syslog_open == 0) { |
| 159 | openlog("zftpd", LOG_PID | LOG_CONS, LOG_DAEMON); |
| 160 | g_syslog_open = 1; |
| 161 | } |
| 162 | |
| 163 | syslog(LOG_INFO, "%s", message); |
| 164 | } |
| 165 | |
| 166 | #endif |
| 167 |