This commit is contained in:
Nishi 2026-04-12 23:06:29 +09:00
commit d2a3bcb744
Signed by: nishi
GPG key ID: 27EF69B208EB9343
32 changed files with 3298 additions and 0 deletions

15
include/ppr.h Normal file
View file

@ -0,0 +1,15 @@
#ifndef __PPR_H__
#define __PPR_H__
#include <ppr_base.h>
/* hash */
#include <ppr_sha256.h>
#include <ppr_md5.h>
#include <ppr_blake2s.h>
/* misc */
#include <ppr_url.h>
#include <ppr_wildcard.h>
#endif

230
include/ppr_base.h Normal file
View file

@ -0,0 +1,230 @@
#ifndef __PPR_BASE_H__
#define __PPR_BASE_H__
#include <ppr_machdep.h>
/* poll.c definitions */
#define PPR_POLLIN (1 << 0)
#define PPR_POLLPRI (1 << 1)
#define PPR_POLLOUT (1 << 2)
struct ppr_pollfd {
int fd;
short events;
short revents;
void* user;
};
/* file.c definitions */
typedef void PPR_FILE;
/* socket.c definitions */
enum ppr_socket_protocol {
PPR_PF_UNSPEC = 0,
PPR_PF_INET,
PPR_PF_INET6,
PPR_PF_UNIX
};
enum ppr_socket_address {
PPR_AF_UNSPEC = 0,
PPR_AF_INET,
PPR_AF_INET6,
PPR_AF_UNIX
};
enum ppr_socket_type {
PPR_SOCK_STREAM = 0,
PPR_SOCK_DGRAM
};
enum ppr_socket_ip_protocol {
PPR_IPPROTO_TCP = 1,
PPR_IPPROTO_UDP
};
struct ppr_sockaddr {
unsigned short sa_family;
char sa_data[14];
};
union ppr_in_addr_union {
ppr_uint8_t addr8[4];
ppr_uint16_t addr16[2];
ppr_uint32_t addr32[1];
};
struct ppr_in_addr {
union ppr_in_addr_union u;
};
struct ppr_sockaddr_in {
unsigned short sin_family;
ppr_uint16_t sin_port;
struct ppr_in_addr sin_addr;
};
union ppr_in6_addr_union {
ppr_uint8_t addr8[16];
ppr_uint16_t addr16[8];
ppr_uint32_t addr32[4];
};
struct ppr_in6_addr {
union ppr_in6_addr_union u;
};
struct ppr_sockaddr_in6 {
unsigned short sin6_family;
ppr_uint16_t sin6_port;
struct ppr_in6_addr sin6_addr;
};
struct ppr_sockaddr_storage {
unsigned short ss_family;
char ss_pad[128];
};
struct ppr_sockaddr_un {
unsigned short sun_family;
char sun_path[104];
};
/* stat.c definitions */
#define PPR_S_IFREG (1 << 0)
#define PPR_S_IFDIR (1 << 1)
#define PPR_S_ISREG(x) ((x) & PPR_S_IFREG)
#define PPR_S_ISDIR(x) ((x) & PPR_S_IFDIR)
struct ppr_stat {
ppr_size_t st_size;
ppr_time_t st_modtime;
int st_mode;
};
/* dirent.c definitions */
typedef void PPR_DIR;
struct ppr_dirent {
char d_name[512];
char d_fullname[1024];
struct ppr_stat d_stat;
};
/* time.c definitions */
struct ppr_tm {
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday;
int tm_yday;
int tm_isdst;
};
/* thread.c definitions */
#if defined(PPR_IS_NETWARE)
struct ppr_semaphore_usage {
long sem;
ppr_bool used;
};
#endif
/* core.c */
void ppr_init(void);
void ppr_uninit(void);
/* poll.c */
int ppr_poll(struct ppr_pollfd* fds, int nfds, int timeout);
/* file.c */
PPR_FILE* ppr_fopen(const char* path, const char* mode);
int ppr_fread(void* ptr, int size, int nmemb, PPR_FILE* stream);
int ppr_fwrite(const void* ptr, int size, int nmemb, PPR_FILE* stream);
void ppr_fclose(PPR_FILE* stream);
/* socket.c */
extern struct ppr_in_addr ppr_inaddr_any;
extern struct ppr_in6_addr ppr_in6addr_any;
void ppr_socket_init(void);
int ppr_socket(int domain, int type, int protocol);
int ppr_recv(int s, void* buf, int len, int flags);
int ppr_send(int s, const void* msg, int len, int flags);
int ppr_bind(int s, const struct ppr_sockaddr* name, int namelen);
int ppr_connect(int s, const struct ppr_sockaddr* name, int namelen);
int ppr_listen(int s, int backlog);
int ppr_accept(int s, struct ppr_sockaddr* addr, int* addrlen);
void ppr_socket_close(int d);
void ppr_socket_uninit(void);
ppr_bool ppr_socket_has_ipv6(void);
/* arpa.c */
ppr_uint16_t ppr_htons(ppr_uint16_t host16);
const char* ppr_inet_ntop(struct ppr_sockaddr* src, char* dst);
struct ppr_sockaddr* ppr_inet_addr(const char* addr, int* len);
/* string.c */
char* ppr_strdup(const char* str);
char* ppr_strvacat(const char* a, ...);
void ppr_strappend(char** dst, const char* src);
char* ppr_strsafehtml(const char* s);
/* dlfcn.c */
void* ppr_dlopen(const char* path);
void* ppr_dlsym(void* handle, const char* symbol);
int ppr_dlclose(void* handle);
/* unistd.c */
int ppr_gethostname(char* name, int namelen);
void ppr_msleep(int ms);
/* stat.c */
int ppr_stat(const char* path, struct ppr_stat* s);
/* thread.c */
#if defined(PPR_IS_NETWARE)
extern struct ppr_semaphore_usage ppr_semaphores[];
long ppr_thread_open_semaphore(long initial);
void ppr_thread_close_semaphore(long sem);
#endif
void* ppr_thread_create(void (*entry)(void* param), void* param);
void ppr_thread_join(void* handle);
void ppr_thread_destroy(void* handle);
void ppr_thread_init(void);
void ppr_thread_uninit(void);
/* mutex.c */
void* ppr_mutex_create(void);
void ppr_mutex_lock(void* handle);
void ppr_mutex_unlock(void* handle);
void ppr_mutex_destroy(void* handle);
/* process.c */
void* ppr_process_create(const char* exec, char** env);
void ppr_process_close(void* handle);
int ppr_process_write(void* handle, const void* data, int len);
int ppr_process_read(void* handle, void* data, int len);
void ppr_process_destroy(void* handle);
/* dirent.c */
PPR_DIR* ppr_opendir(const char* path);
struct ppr_dirent* ppr_readdir(PPR_DIR* handle);
void ppr_closedir(PPR_DIR* handle);
int ppr_scandir(const char* dirname, struct ppr_dirent*** namelist, int (*selectfn)(const struct ppr_dirent* d), int (*compar)(const struct ppr_dirent** d1, const struct ppr_dirent** d2));
int ppr_alphasort(const struct ppr_dirent** d1, const struct ppr_dirent** d2);
/* time.c */
extern void* ppr_gmtime_mutex;
extern void* ppr_localtime_mutex;
ppr_time_t ppr_time(void);
void ppr_gmtime(struct ppr_tm* tm, ppr_time_t t);
void ppr_localtime(struct ppr_tm* tm, ppr_time_t t);
#endif

78
include/ppr_blake2s.h Normal file
View file

@ -0,0 +1,78 @@
/*
BLAKE2 reference source code package - reference C implementations
Copyright 2012, Samuel Neves <sneves@dei.uc.pt>. You may use this under the
terms of the CC0, the OpenSSL Licence, or the Apache Public License 2.0, at
your option. The terms of these licenses can be found at:
- CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
- OpenSSL license : https://www.openssl.org/source/license.html
- Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0
More information about the BLAKE2 hash function can be found at
https://blake2.net.
*/
#ifndef PPR_BLAKE2S_H
#define PPR_BLAKE2S_H
#include <ppr_machdep.h>
enum ppr_blake2s_constant {
BLAKE2S_BLOCKBYTES = 64,
BLAKE2S_OUTBYTES = 32,
BLAKE2S_KEYBYTES = 32,
BLAKE2S_SALTBYTES = 8,
BLAKE2S_PERSONALBYTES = 8
};
typedef struct ppr_blake2s_state__ {
ppr_uint32_t h[8];
ppr_uint32_t t[2];
ppr_uint32_t f[2];
ppr_uint8_t buf[BLAKE2S_BLOCKBYTES];
ppr_size_t buflen;
ppr_size_t outlen;
ppr_uint8_t last_node;
} ppr_blake2s_state;
#ifdef PPR_HAS_PACK
#pragma pack(1)
#endif
struct ppr_blake2s_param__ {
ppr_uint8_t digest_length; /* 1 */
ppr_uint8_t key_length; /* 2 */
ppr_uint8_t fanout; /* 3 */
ppr_uint8_t depth; /* 4 */
ppr_uint32_t leaf_length; /* 8 */
ppr_uint32_t node_offset; /* 12 */
ppr_uint16_t xof_length; /* 14 */
ppr_uint8_t node_depth; /* 15 */
ppr_uint8_t inner_length; /* 16 */
/* ppr_uint8_t reserved[0]; */
ppr_uint8_t salt[BLAKE2S_SALTBYTES]; /* 24 */
ppr_uint8_t personal[BLAKE2S_PERSONALBYTES]; /* 32 */
};
#ifdef PPR_HAS_PACK
#pragma pack()
#endif
typedef struct ppr_blake2s_param__ ppr_blake2s_param;
#if 0
/* Padded structs result in a compile-time error */
enum {
BLAKE2_DUMMY_1 = 1/(int)(sizeof(ppr_blake2s_param) == BLAKE2S_OUTBYTES)
};
#endif
/* Streaming API */
int ppr_blake2s_init(ppr_blake2s_state* S, ppr_size_t outlen);
int ppr_blake2s_init_key(ppr_blake2s_state* S, ppr_size_t outlen, const void* key, ppr_size_t keylen);
int ppr_blake2s_init_param(ppr_blake2s_state* S, const ppr_blake2s_param* P);
int ppr_blake2s_update(ppr_blake2s_state* S, const void* in, ppr_size_t inlen);
int ppr_blake2s_final(ppr_blake2s_state* S, void* out, ppr_size_t outlen);
/* Simple API */
int ppr_blake2s(void* out, ppr_size_t outlen, const void* in, ppr_size_t inlen, const void* key, ppr_size_t keylen);
#endif

87
include/ppr_int.h Normal file
View file

@ -0,0 +1,87 @@
#ifndef __PPR_INT_H__
#define __PPR_INT_H__
/* generic section */
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <stdarg.h>
#include <time.h>
#if defined(PPR_IS_NETWARE)
#include <sys/stat.h>
#include <nwnamspc.h>
#include <nwadv.h>
#endif
#if defined(PPR_IS_UNIX)
#include <signal.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <dlfcn.h>
#endif
#if defined(PPR_IS_UNIX) || defined(PPR_IS_PSP) || defined(PPR_IS_PS2) || defined(PPR_IS_NETWARE)
#include <unistd.h>
#include <dirent.h>
#endif
/* thread section */
#if defined(PPR_IS_WIN32)
#if !defined(PPR_USE_CREATETHREAD)
#include <process.h>
#endif
#elif defined(PPR_IS_UNIX) || defined(PPR_IS_PSP) || defined(PPR_IS_PS2)
#include <pthread.h>
#define PPR_USE_PTHREAD
#elif defined(PPR_IS_NETWARE)
#include <nwthread.h>
#include <nwsemaph.h>
#endif
/* socket section */
#if defined(PPR_IS_WIN32)
#include <winsock2.h>
#include <ws2tcpip.h>
#include <ws2ipdef.h>
#ifndef IPPROTO_IPV6
#define IPPROTO_IPV6 41
#endif
#ifndef IPV6_V6ONLY
#define IPV6_V6ONLY 27
#endif
#else
#if defined(PPR_HAS_POLL)
#include <poll.h>
#else
#if !defined(PPR_IS_NETWARE)
#include <sys/select.h>
#endif
#endif
#include <sys/socket.h>
#include <sys/types.h>
#if defined(PPR_IS_NETWARE)
#include <sys/bsdskt.h>
#else
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#endif
#if defined(PPR_HAS_UNIX_SOCKET)
#include <sys/un.h>
#endif
#endif
/* windows.h wants to be the last one included */
#if defined(PPR_IS_WIN32)
#include <windows.h>
#endif
#endif

100
include/ppr_machdep.h Normal file
View file

@ -0,0 +1,100 @@
#ifndef __PPR_MACHDEP_H__
#define __PPR_MACHDEP_H__
#if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__linux__) || defined(__sun__)
#define PPR_IS_UNIX
#elif defined(_WIN32)
#define PPR_IS_WIN32
#elif defined(_PSP)
#define PPR_IS_PSP
#elif defined(_EE)
#define PPR_IS_PS2
#elif defined(__NETWARE__)
#define PPR_IS_NETWARE
#endif
/*** Platform differences */
#if defined(PPR_IS_WIN32) || defined(PPR_IS_NETWARE)
#define ppr_newline "\r\n"
#else
#define ppr_newline "\n"
#endif
#undef PPR_HAS_IPV6
#undef PPR_HAS_POLL
#undef PPR_HAS_FORK
#undef PPR_HAS_UNIX_SOCKET
#undef PPR_USE_SOCKLEN_T
/* Windows */
#if defined(PPR_IS_WIN32)
#define PPR_HAS_IPV6
#endif
/* PSP/PS2 */
#if defined(PPR_IS_PSP) || defined(PPR_IS_PS2)
#define PPR_USE_SOCKLEN_T
#endif
/* NetWare */
#if defined(PPR_IS_NETWARE)
/* Nothing */
#endif
/* BSD family */
#if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__linux__) || defined(__sun__)
#define PPR_HAS_IPV6
#define PPR_HAS_POLL
#define PPR_HAS_FORK
#define PPR_HAS_UNIX_SOCKET
#define PPR_USE_SOCKLEN_T
#endif
/*** Compiler differences ***/
#undef PPR_HAS_PACK
#if defined(__WATCOMC__) || defined(__GNUC__)
#define PPR_HAS_PACK
#endif
typedef unsigned char ppr_bool;
#define ppr_false 0
#define ppr_true 1
#if defined(_MSC_VER) || defined(__WATCOMC__)
typedef unsigned __int8 ppr_uint8_t;
typedef unsigned __int16 ppr_uint16_t;
typedef unsigned __int32 ppr_uint32_t;
typedef __int8 ppr_int8_t;
typedef __int16 ppr_int16_t;
typedef __int32 ppr_int32_t;
typedef __int64 ppr_size_t;
#elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) || defined(__clang__))
typedef unsigned char ppr_uint8_t;
typedef unsigned short ppr_uint16_t;
typedef unsigned int ppr_uint32_t;
typedef signed char ppr_int8_t;
typedef short ppr_int16_t;
typedef int ppr_int32_t;
typedef long long ppr_size_t;
#else
typedef unsigned char ppr_uint8_t;
typedef unsigned short ppr_uint16_t;
typedef unsigned int ppr_uint32_t;
typedef signed char ppr_int8_t;
typedef short ppr_int16_t;
typedef int ppr_int32_t;
typedef long ppr_size_t;
#endif
typedef ppr_size_t ppr_time_t;
#endif

43
include/ppr_md5.h Normal file
View file

@ -0,0 +1,43 @@
/*
**********************************************************************
** Copyright (C) 1990, RSA Data Security, Inc. All rights reserved. **
** **
** License to copy and use this software is granted provided that **
** it is identified as the "RSA Data Security, Inc. MD5 Message **
** Digest Algorithm" in all material mentioning or referencing this **
** software or this function. **
** **
** License is also granted to make and use derivative works **
** provided that such works are identified as "derived from the RSA **
** Data Security, Inc. MD5 Message Digest Algorithm" in all **
** material mentioning or referencing the derived work. **
** **
** RSA Data Security, Inc. makes no representations concerning **
** either the merchantability of this software or the suitability **
** of this software for any particular purpose. It is provided "as **
** is" without express or implied warranty of any kind. **
** **
** These notices must be retained in any copies of any part of this **
** documentation and/or software. **
**********************************************************************
*/
#ifndef __PPR_MD5_H__
#define __PPR_MD5_H__
#include <ppr_machdep.h>
typedef struct ppr_md5_context ppr_md5_context_t;
struct ppr_md5_context {
ppr_uint32_t i[2]; /* number of _bits_ handled mod 2^64 */
ppr_uint32_t buf[4]; /* scratch buffer */
unsigned char in[64]; /* input buffer */
unsigned char digest[16]; /* actual digest after MD5Final call */
};
void ppr_md5_init(ppr_md5_context_t* mdContext);
void ppr_md5_update(ppr_md5_context_t* mdContext, const void* inBuf, unsigned int inLen);
void ppr_md5_final(ppr_md5_context_t* mdContext);
#endif

8
include/ppr_sha256.h Normal file
View file

@ -0,0 +1,8 @@
#ifndef __PPR_SHA256_H__
#define __PPR_SHA256_H__
#include <ppr_machdep.h>
void ppr_sha256(void* output, const void* data, ppr_size_t len);
#endif

25
include/ppr_url.h Normal file
View file

@ -0,0 +1,25 @@
#ifndef __PPR_URL_H__
#define __PPR_URL_H__
#include <ppr_machdep.h>
typedef struct ppr_url ppr_url_t;
struct ppr_url {
char* scheme;
char* userinfo;
char* host;
int port;
char* path;
char* query;
char* fragment;
};
ppr_bool ppr_url_decode(char* out, const char* input, int len);
ppr_bool ppr_url_encode(char* out, const char* input, int len);
void ppr_url_init(ppr_url_t* url);
ppr_bool ppr_url_parse(ppr_url_t* url, const char* str);
void ppr_url_deinit(ppr_url_t* url);
#endif

8
include/ppr_wildcard.h Normal file
View file

@ -0,0 +1,8 @@
#ifndef __PPR_WILDCARD_H__
#define __PPR_WILDCARD_H__
#include <ppr_machdep.h>
ppr_bool ppr_wildcard(const char* wildcard, const char* target);
#endif