Seregon/zftpd

Zero-copy FTP/HTTP Daemon compatible with all POSIX systems

C/11.0 KB/No license
src/pal_notification.c
zftpd / src / pal_notification.c
1/*
2MIT License
3 
4Copyright (c) 2026 Seregon
5 
6Permission is hereby granted, free of charge, to any person obtaining a copy
7of this software and associated documentation files (the "Software"), to deal
8in the Software without restriction, including without limitation the rights
9to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10copies of the Software, and to permit persons to whom the Software is
11furnished to do so, subject to the following conditions:
12 
13The above copyright notice and this permission notice shall be included in all
14copies or substantial portions of the Software.
15 
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22SOFTWARE.
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 
43typedef struct notify_request {
44 char padding[45];
45 char message[3075];
46} notify_request_t;
47 
48__attribute__((weak))
49int sceKernelSendNotificationRequest(int, notify_request_t *, size_t, int);
50 
51static int g_notify_available = 0;
52 
53int 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 
63void pal_notification_shutdown(void)
64{
65 g_notify_available = 0;
66}
67 
68void 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 
89typedef struct notify_request {
90 char padding[45];
91 char message[3075];
92} notify_request_t;
93 
94__attribute__((weak))
95int sceKernelSendNotificationRequest(int, notify_request_t *, size_t, int);
96 
97static int g_notify_available = 0;
98 
99int 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 
109void pal_notification_shutdown(void)
110{
111 g_notify_available = 0;
112}
113 
114void 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 
133static int g_syslog_open = 0;
134 
135int 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 
144void pal_notification_shutdown(void)
145{
146 if (g_syslog_open != 0) {
147 closelog();
148 g_syslog_open = 0;
149 }
150}
151 
152void 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