ctori NOW

This commit is contained in:
MallocNull 2020-04-12 15:53:32 -05:00
parent 597801265e
commit ed7894026c
17 changed files with 189 additions and 42 deletions

5
.gitignore vendored
View file

@ -1,3 +1,8 @@
## Ignore (cmake) build files
.idea/
build/
cmake-build-*/
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

30
CMakeLists.txt Normal file
View file

@ -0,0 +1,30 @@
cmake_minimum_required(VERSION 3.7)
project(kmj)
string(COMPARE EQUAL ${CMAKE_BUILD_TYPE} Debug _CMP)
if(_CMP)
set(CMAKE_VERBOSE_MAKEFILE ON)
add_definitions("-DKMJ_DEBUG")
endif()
file(GLOB_RECURSE komeiji_src
"src/*.c"
"src/*.h"
)
find_package(OpenSSL)
add_executable(komeiji ${komeiji_src})
target_include_directories(komeiji
PRIVATE ${PROJECT_SOURCE_DIR}/src
PRIVATE ${OPENSSL_INCLUDE_DIR})
target_link_libraries(komeiji ${OPENSSL_LIBRARIES})
install(TARGETS komeiji RUNTIME DESTINATION bin)
if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
target_link_libraries(komeiji wsock32 ws2_32)
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
target_link_libraries(komeiji dl pthread nsl resolv)
else()
target_link_libraries(komeiji dl pthread socket nsl resolv)
endif()

View file

@ -1,25 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29411.108
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Komeiji", "Komeiji\Komeiji.csproj", "{9D6BA160-CC0F-45AF-BA2B-338B8496A2A8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9D6BA160-CC0F-45AF-BA2B-338B8496A2A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9D6BA160-CC0F-45AF-BA2B-338B8496A2A8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9D6BA160-CC0F-45AF-BA2B-338B8496A2A8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9D6BA160-CC0F-45AF-BA2B-338B8496A2A8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {739F12F7-8FD0-4E63-A482-B7A5B5FDEB74}
EndGlobalSection
EndGlobal

View file

@ -1,8 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>
</Project>

View file

@ -1,9 +0,0 @@
using System;
namespace Komeiji {
class Program {
static void Main(string[] args) {
Console.WriteLine("Hello Hell!");
}
}
}

View file

@ -1 +1,3 @@
# komeiji
satori but without .net but with koishi

6
src/main.c Normal file
View file

@ -0,0 +1,6 @@
#include <stdio.h>
int main(int argc, char** argv) {
return 0;
}

1
src/sock/url.c Normal file
View file

@ -0,0 +1 @@
#include "url.h"

26
src/sock/url.h Normal file
View file

@ -0,0 +1,26 @@
#ifndef KMJ_URL_H
#define KMJ_URL_H
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#define KMJ_URL_PROTO_NA 0
#define KMJ_URL_PROTO_HTTP 1
#define KMJ_URL_PROTO_HTTPS 2
#define KMJ_URL_PROTO_WS 3
#define KMJ_URL_PROTO_WSS 4
typedef struct {
int proto;
char addr[256];
uint16_t port;
char path[2048];
char* query;
char* fragment;
} url_t;
url_t* url_parse(const char* url, url_t* out);
#endif

61
src/sock/wsock.h Normal file
View file

@ -0,0 +1,61 @@
#ifndef KMJ_WSOCK_H
#define KMJ_WSOCK_H
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#ifdef __MINGW32__
#undef _WIN32_WINNT
#define _WIN32_WINNT _WIN32_WINNT_WIN8
#endif
#include <winsock2.h>
#include <ws2tcpip.h>
#define __SOCK_T SOCKET
#define __ADDR_T SOCKADDR_IN
#else
#include <arpa/inet.h>
#include <errno.h>
#include <fcntl.h>
#include <netdb.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#define __SOCK_T int
#define __ADDR_T struct sockaddr_in
#endif
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
#define KMJ_SOCK_BUFLEN 2048
#define KMJ_SOCK_APPEND 1
#define KMJ_SOCK_APPEND_CLR 2
#define KMJ_SOCK_APPEND_IGN_PTR 4
#define KMJ_SOCK_BLOCK 8
typedef struct {
__SOCK_T sock;
__ADDR_T addr;
int addr_len;
int sock_open;
SSL* ssl;
char* append_ptr;
char* append_loc;
char buffer[KMJ_SOCK_BUFLEN];
} wsock_t;
wsock_t* wsock_create(const char* url);
void wsock_free(wsock_t*);
#endif

30
src/sock/wsock_all.c Normal file
View file

@ -0,0 +1,30 @@
#include "wsock.h"
struct {
SSL_CTX* client;
} _ssl_ctx;
int _ssl_init(void) {
static int is_ready = 0;
if(is_ready)
return 0;
SSL_load_error_strings();
OpenSSL_add_ssl_algorithms();
_ssl_ctx.client = SSL_CTX_new(SSLv23_client_method());
if(!_ssl_ctx.client)
return -1;
SSL_CTX_set_ecdh_auto(_ssl_ctx.client, 1);
is_ready = 1;
return 0;
}
#define KMJ_SOCK_PROTO_WS 0
#define KMJ_SOCK_PROTO_WSS 1
url_t* _ws_read_url(const char* url, url_t *out) {
}

6
src/sock/wsock_bsd.c Normal file
View file

@ -0,0 +1,6 @@
#include "wsock.h"
#include "wsock_all.c"
#ifndef _WIN32
#endif

8
src/sock/wsock_win.c Normal file
View file

@ -0,0 +1,8 @@
#include "wsock.h"
#include "wsock_all.c"
#ifdef _WIN32
// TODO: WIN32 CODE
#endif

2
src/utils/list.c Normal file
View file

@ -0,0 +1,2 @@
#include "list.h"

4
src/utils/list.h Normal file
View file

@ -0,0 +1,4 @@
#ifndef KMJ_LIST_H
#define KMJ_LIST_H
#endif

2
src/utils/string.c Normal file
View file

@ -0,0 +1,2 @@
#include "string.h"

6
src/utils/string.h Normal file
View file

@ -0,0 +1,6 @@
#ifndef KMJ_STRING_H
#define KMJ_STRING_H
#endif