diff --git a/.vscode/settings.json b/.vscode/settings.json index 047b616..4eed3f5 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,98 @@ { "python.linting.enabled": false, + "files.associations": { + "*.ejs": "html", + "*.inc": "cpp", + "internet": "cpp", + "socket": "cpp", + "functional": "c", + "cmath": "cpp", + "cstdlib": "cpp", + "hash_map": "cpp", + "cwchar": "cpp", + "cctype": "cpp", + "clocale": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwctype": "cpp", + "bitset": "cpp", + "deque": "cpp", + "forward_list": "cpp", + "list": "cpp", + "map": "cpp", + "set": "cpp", + "string": "cpp", + "unordered_map": "cpp", + "unordered_set": "cpp", + "vector": "cpp", + "algorithm": "cpp", + "array": "cpp", + "chrono": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "optional": "cpp", + "random": "cpp", + "ratio": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "atomic": "cpp", + "bit": "cpp", + "codecvt": "cpp", + "complex": "cpp", + "concepts": "cpp", + "condition_variable": "cpp", + "fstream": "cpp", + "iomanip": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "mutex": "cpp", + "numbers": "cpp", + "ostream": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "stop_token": "cpp", + "streambuf": "cpp", + "thread": "cpp", + "typeindex": "cpp", + "valarray": "cpp", + "variant": "cpp", + "cfenv": "cpp", + "cinttypes": "cpp", + "compare": "cpp", + "exception": "cpp", + "initializer_list": "cpp", + "new": "cpp", + "typeinfo": "cpp", + "*.tcc": "cpp", + "__bit_reference": "cpp", + "__bits": "cpp", + "__config": "cpp", + "__debug": "cpp", + "__errc": "cpp", + "__hash_table": "cpp", + "__locale": "cpp", + "__mutex_base": "cpp", + "__node_handle": "cpp", + "__nullptr": "cpp", + "__split_buffer": "cpp", + "__string": "cpp", + "__threading_support": "cpp", + "__tree": "cpp", + "__tuple": "cpp", + "ios": "cpp", + "locale": "cpp", + "queue": "cpp", + "stack": "cpp" + }, } \ No newline at end of file diff --git a/binding.gyp b/binding.gyp index 7f0a122..43cceec 100644 --- a/binding.gyp +++ b/binding.gyp @@ -22,10 +22,17 @@ ] }, { - "target_name": "file", + "target_name": "socket", 'cflags': [ '-Wall' ], "sources": [ - "clibs/chibrax/file.cc" + "clibs/chibrax/socket.cc" + ] + }, + { + "target_name": "ip", + 'cflags': [ '-Wall', '-Wextra' ], + "sources": [ + "clibs/chibrax/ip.cc" ] } ] diff --git a/clibs.sh b/clibs.sh index 79f6420..67b410d 100755 --- a/clibs.sh +++ b/clibs.sh @@ -10,7 +10,9 @@ echo " ioctl" cp build/Release/ioctl.node rootfs\ overrides/chibrax/ioctl.node echo " mount" cp build/Release/mount.node rootfs\ overrides/chibrax/mount.node -echo " file" -cp build/Release/file.node rootfs\ overrides/chibrax/file.node +echo " socket" +cp build/Release/socket.node rootfs\ overrides/chibrax/socket.node +echo " ip" +cp build/Release/ip.node rootfs\ overrides/chibrax/ip.node echo "done" \ No newline at end of file diff --git a/clibs/chibrax/file.cc b/clibs/chibrax/file.cc deleted file mode 100644 index 302447f..0000000 --- a/clibs/chibrax/file.cc +++ /dev/null @@ -1,49 +0,0 @@ -#include -#include -#include -#include -#include - -#define nodeparam v8::FunctionCallbackInfo - -namespace fileNode { - void nodeOpen(const nodeparam& args) { - v8::Isolate* isolate = args.GetIsolate(); - - if (args.Length() < 2 || !args[0]->IsString() || !args[1]->IsUint32() || ( args.Length() == 3 && !( args[2]->IsUndefined() || args[2]->IsUint32()))) { - isolate->ThrowException(v8::Exception::TypeError( - v8::String::NewFromUtf8(isolate, "Argument 1 must be a path, 2 must be a number").ToLocalChecked())); - return; - } - - v8::String::Utf8Value str(isolate, args[0]); - std::string path(*str); - int flags = args[1].As()->Value(); - - if(args.Length() == 3 && args[2]->IsUndefined()) { - mode_t mode = args[2].As()->Value(); - args.GetReturnValue().Set(open(path.c_str(), flags, mode)); - } else { - args.GetReturnValue().Set(open(path.c_str(), flags)); - } - } - - void nodeClose(const nodeparam& args) { - v8::Isolate* isolate = args.GetIsolate(); - - if (args.Length() < 1 || !args[0]->IsUint32()) { - isolate->ThrowException(v8::Exception::TypeError( - v8::String::NewFromUtf8(isolate, "Argument 1 must be a file descriptor (number)").ToLocalChecked())); - return; - } - - close(args[1].As()->Value()); - } - - void Initialize(v8::Local exports) { - NODE_SET_METHOD(exports, "open", nodeOpen); - NODE_SET_METHOD(exports, "close", nodeClose); - } - - NODE_MODULE(file_api, Initialize) -} diff --git a/clibs/chibrax/ioctl.cc b/clibs/chibrax/ioctl.cc index 4993ceb..2b77fc8 100644 --- a/clibs/chibrax/ioctl.cc +++ b/clibs/chibrax/ioctl.cc @@ -9,19 +9,13 @@ namespace ioctlNode { void nodeIoctl(const nodeparam& args) { v8::Isolate* isolate = args.GetIsolate(); - - - - if (args.Length() < 2 || !args[0]->IsString() || !args[1]->IsUint32()) { + if (args.Length() < 2 || !args[0]->IsUint32() || !args[1]->IsUint32()) { isolate->ThrowException(v8::Exception::TypeError( v8::String::NewFromUtf8(isolate, "Argument 1& 2 must be a number").ToLocalChecked())); return; } - v8::String::Utf8Value str(isolate, args[0]); - std::string cppStr(*str); - - int fd = open(cppStr.c_str(), 'r'); + u_int32_t fd = args[0].As()->Value(); unsigned long request = args[1].As()->Value(); int params[args.Length() - 2]; for(int i = 1 ; i < args.Length(); i++ ) { diff --git a/rootfs overrides/chibrax/cfiles.js b/rootfs overrides/chibrax/cfiles.js deleted file mode 100644 index bdb80bc..0000000 --- a/rootfs overrides/chibrax/cfiles.js +++ /dev/null @@ -1,15 +0,0 @@ -//@ts-check -/** - * @type {{ open: (path: string, flags: number, mode?: number) => number, close: (fd: number) => void }} - */ -//@ts-expect-error -const cfiles = require('./file.node') - -const modes = { - O_ACCMODE: 3, - O_RDONLY: 0, - O_WRONLY: 1, - O_RDWR: 2 -} - -module.exports = { ...cfiles, modes } \ No newline at end of file