diff --git a/protocols/Makefile b/protocols/Makefile index db3d36e..3d22e7f 100644 --- a/protocols/Makefile +++ b/protocols/Makefile @@ -1,5 +1,8 @@ .DEFAULT_GOAL := default +irc: + $(MAKE) -f protocols/irc/Makefile + xmpp: $(MAKE) -f protocols/xmpp/Makefile diff --git a/protocols/irc/IrcMain.cpp b/protocols/irc/IrcMain.cpp new file mode 100644 index 0000000..056285c --- /dev/null +++ b/protocols/irc/IrcMain.cpp @@ -0,0 +1,52 @@ +/* + * Copyright 2021, Jaidyn Levesque + * All rights reserved. Distributed under the terms of the MIT license. + */ + +#include "IrcProtocol.h" + + +extern "C" _EXPORT ChatProtocol* protocol_at(int32 i); +extern "C" _EXPORT int32 protocol_count(); +extern "C" _EXPORT const char* signature(); +extern "C" _EXPORT const char* friendly_signature(); +extern "C" _EXPORT uint32 version(); + + +ChatProtocol* +protocol_at(int32 i) +{ + if (i == 0) + return (ChatProtocol*)new IrcProtocol(); + return NULL; +} + + +int32 +protocol_count() +{ + return 1; +} + + +const char* +signature() +{ + return "irc"; +} + + +const char* +friendly_signature() +{ + return "IRC"; +} + + +uint32 +version() +{ + return APP_VERSION_1_PRE_ALPHA_1; +} + + diff --git a/protocols/irc/IrcProtocol.cpp b/protocols/irc/IrcProtocol.cpp new file mode 100644 index 0000000..67d9605 --- /dev/null +++ b/protocols/irc/IrcProtocol.cpp @@ -0,0 +1,236 @@ +/* + * Copyright 2021, Jaidyn Levesque + * All rights reserved. Distributed under the terms of the MIT license. + */ + +#include "IrcProtocol.h" + +#include + + +status_t +connect_thread(void* data) +{ + BMessage* settings = (BMessage*)data; + if (!settings) + return B_ERROR; + + const char* nick = settings->FindString("nick"); + const char* ident = settings->FindString("ident"); + const char* real_name = settings->FindString("real_name"); + const char* server = settings->FindString("server"); + const char* password = settings->FindString("password"); + int32 port = settings->FindInt32("port"); + bool ssl = false; + + if (!nick || !ident || !server) + return B_ERROR; + + // libircclient wants a "#" in front of SSL addresses + BString joinServer; + if (ssl == true) + joinServer << "#"; + joinServer << server; + + settings->PrintToStream(); + + // Now create the session + irc_callbacks_t callbacks = get_callbacks(); + irc_session_t* session = irc_create_session(&callbacks); + + if (!session) + return B_ERROR; + + // Start connection + if (irc_connect(session, joinServer.String(), port, password, nick, ident, + real_name)) + { + printf("Could not connect: %s\n", irc_strerror (irc_errno(session))); + return B_ERROR; + } + + // Start network loop + if (irc_run(session)) { + printf("Could not connect or I/O error: %s\n", irc_strerror + (irc_errno(session))); + return B_ERROR; + } + return B_OK; +} + + +IrcProtocol::IrcProtocol() +{ +} + + +status_t +IrcProtocol::Init(ChatProtocolMessengerInterface* interface) +{ + fMessenger = interface; + return B_OK; +} + + +status_t +IrcProtocol::Shutdown() +{ + return B_OK; +} + + +status_t +IrcProtocol::Process(BMessage* msg) +{ + return B_OK; +} + + +status_t +IrcProtocol::UpdateSettings(BMessage* msg) +{ + fServerThread = spawn_thread(connect_thread, "connect_thread", + B_NORMAL_PRIORITY, (void*)msg); + + if (fServerThread < B_OK) + return B_ERROR; + + resume_thread(fServerThread); + return B_OK; +} + + +BMessage +IrcProtocol::SettingsTemplate(const char* name) +{ + size_t size; + BMessage temp; + const void* buff = fResources.LoadResource(B_MESSAGE_TYPE, name, &size); + + if (buff != NULL) + temp.Unflatten((const char*)buff); + return temp; +} + + +BObjectList +IrcProtocol::Commands() +{ + return BObjectList(); +} + + +BObjectList +IrcProtocol::UserPopUpItems() +{ + return BObjectList(); +} + + +BObjectList +IrcProtocol::ChatPopUpItems() +{ + return BObjectList(); +} + +BObjectList +IrcProtocol::MenuBarItems() +{ + return BObjectList(); +} + + +const char* +IrcProtocol::Signature() const +{ + return "irc"; +} + + +const char* +IrcProtocol::FriendlySignature() const +{ + return "IRC"; +} + + +BBitmap* +IrcProtocol::Icon() const +{ + return NULL; +} + + +void +IrcProtocol::SetAddOnPath(BPath path) +{ + fAddOnPath = path; + fResources.SetTo(path.Path()); +} + + +BPath +IrcProtocol::AddOnPath() +{ + return fAddOnPath; +} + + +const char* +IrcProtocol::GetName() +{ + return fName.String(); +} + + +void +IrcProtocol::SetName(const char* name) +{ + fName.SetTo(name); +} + + +uint32 +IrcProtocol::GetEncoding() +{ + return 0xffff; +} + + +ChatProtocolMessengerInterface* +IrcProtocol::MessengerInterface() const +{ + return fMessenger; +} + + +irc_callbacks_t +get_callbacks() +{ + irc_callbacks_t callbacks; + callbacks.event_connect = event_connect; + callbacks.event_numeric = event_numeric; + callbacks.event_join = event_join; + return callbacks; +} + + +void +event_connect(irc_session_t* session, const char* event, + const char* origin, const char** params, unsigned int count) +{ +} + + +void +event_numeric(irc_session_t* session, unsigned int blah, + const char* origin, const char** params, unsigned int count) +{ +} + + +void +event_join(irc_session_t* session, const char* event, const char* origin, + const char** params, unsigned int count) +{ +} diff --git a/protocols/irc/IrcProtocol.h b/protocols/irc/IrcProtocol.h new file mode 100644 index 0000000..d5a91b3 --- /dev/null +++ b/protocols/irc/IrcProtocol.h @@ -0,0 +1,79 @@ +/* + * Copyright 2021, Jaidyn Levesque + * All rights reserved. Distributed under the terms of the MIT license. + */ +#ifndef _IRC_PROTOCOL_H +#define _IRC_PROTOCOL_H + +#include +#include +#include + +#include +#include + +#include + + +status_t connect_thread(void* data); + + +class IrcProtocol : public ChatProtocol { +public: + IrcProtocol(); + + // ChatProtocol inheritance + virtual status_t Init(ChatProtocolMessengerInterface* interface); + virtual status_t Shutdown(); + + virtual status_t Process(BMessage* msg); + + virtual status_t UpdateSettings(BMessage* msg); + virtual BMessage SettingsTemplate(const char* name); + + virtual BObjectList Commands(); + virtual BObjectList UserPopUpItems(); + virtual BObjectList ChatPopUpItems(); + virtual BObjectList MenuBarItems(); + + virtual const char* Signature() const; + virtual const char* FriendlySignature() const; + + virtual BBitmap* Icon() const; + + virtual void SetAddOnPath(BPath path); + virtual BPath AddOnPath(); + + virtual const char* GetName(); + virtual void SetName(const char* name); + + virtual uint32 GetEncoding(); + + virtual ChatProtocolMessengerInterface* + MessengerInterface() const; + +private: + ChatProtocolMessengerInterface* fMessenger; + + thread_id fServerThread; + + BString fName; + BPath fAddOnPath; + BResources fResources; +}; + + +irc_callbacks_t get_callbacks(); + +void event_connect(irc_session_t* session, const char* event, + const char* origin, const char** params, + unsigned int count); + +void event_numeric(irc_session_t* session, unsigned int blah, + const char* origin, const char** params, unsigned int count); + +void event_join(irc_session_t* session, const char* event, + const char* origin, const char** params, unsigned int count); + + +#endif // _IRC_PROTOCOL_H diff --git a/protocols/irc/Makefile b/protocols/irc/Makefile new file mode 100644 index 0000000..0eaf478 --- /dev/null +++ b/protocols/irc/Makefile @@ -0,0 +1,138 @@ +## Haiku Generic Makefile v2.6 ## + +## Fill in this file to specify the project being created, and the referenced +## Makefile-Engine will do all of the hard work for you. This handles any +## architecture of Haiku. +## +## For more information, see: +## file:///system/develop/documentation/makefile-engine.html + +# The name of the binary. +NAME = protocols/irc + +# The type of binary, must be one of: +# APP: Application +# SHARED: Shared library or add-on +# STATIC: Static library archive +# DRIVER: Kernel driver +TYPE = SHARED + +# If you plan to use localization, specify the application's MIME signature. +APP_MIME_SIG = + +# The following lines tell Pe and Eddie where the SRCS, RDEFS, and RSRCS are +# so that Pe and Eddie can fill them in for you. +#%{ +# @src->@ + +# Specify the source files to use. Full paths or paths relative to the +# Makefile can be included. All files, regardless of directory, will have +# their object files created in the common object directory. Note that this +# means this Makefile will not work correctly if two source files with the +# same name (source.c or source.cpp) are included from different directories. +# Also note that spaces in folder names do not work well with this Makefile. +SRCS = \ + protocols/irc/IrcMain.cpp \ + protocols/irc/IrcProtocol.cpp \ + +# Specify the resource definition files to use. Full or relative paths can be +# used. +RDEFS = \ + protocols/irc/irc.rdef \ + protocols/irc/Templates.rdef \ + +# Specify the resource files to use. Full or relative paths can be used. +# Both RDEFS and RSRCS can be utilized in the same Makefile. +RSRCS = + +# End Pe/Eddie support. +# @<-src@ +#%} + +# Specify libraries to link against. +# There are two acceptable forms of library specifications: +# - if your library follows the naming pattern of libXXX.so or libXXX.a, +# you can simply specify XXX for the library. (e.g. the entry for +# "libtracker.so" would be "tracker") +# +# - for GCC-independent linking of standard C++ libraries, you can use +# $(STDCPPLIBS) instead of the raw "stdc++[.r4] [supc++]" library names. +# +# - if your library does not follow the standard library naming scheme, +# you need to specify the path to the library and it's name. +# (e.g. for mylib.a, specify "mylib.a" or "path/mylib.a") +LIBS = be crypto network support ssl ircclient z $(STDCPPLIBS) + + +# Specify additional paths to directories following the standard libXXX.so +# or libXXX.a naming scheme. You can specify full paths or paths relative +# to the Makefile. The paths included are not parsed recursively, so +# include all of the paths where libraries must be found. Directories where +# source files were specified are automatically included. +LIBPATHS = + +# Additional paths to look for system headers. These use the form +# "#include
". Directories that contain the files in SRCS are +# NOT auto-included here. +SYSTEM_INCLUDE_PATHS = application/ libs/ + +# Additional paths paths to look for local headers. These use the form +# #include "header". Directories that contain the files in SRCS are +# automatically included. +LOCAL_INCLUDE_PATHS = + +# Specify the level of optimization that you want. Specify either NONE (O0), +# SOME (O1), FULL (O3), or leave blank (for the default optimization level). +OPTIMIZE := + +# Specify the codes for languages you are going to support in this +# application. The default "en" one must be provided too. "make catkeys" +# will recreate only the "locales/en.catkeys" file. Use it as a template +# for creating catkeys for other languages. All localization files must be +# placed in the "locales" subdirectory. +LOCALES = + +# Specify all the preprocessor symbols to be defined. The symbols will not +# have their values set automatically; you must supply the value (if any) to +# use. For example, setting DEFINES to "DEBUG=1" will cause the compiler +# option "-DDEBUG=1" to be used. Setting DEFINES to "DEBUG" would pass +# "-DDEBUG" on the compiler's command line. +DEFINES = + +# Specify the warning level. Either NONE (suppress all warnings), +# ALL (enable all warnings), or leave blank (enable default warnings). +WARNINGS = + +# With image symbols, stack crawls in the debugger are meaningful. +# If set to "TRUE", symbols will be created. +SYMBOLS := + +# Includes debug information, which allows the binary to be debugged easily. +# If set to "TRUE", debug info will be created. +DEBUGGER := + +# Specify any additional compiler flags to be used. +COMPILER_FLAGS = + +# Specify any additional linker flags to be used. +LINKER_FLAGS = + +# Specify the version of this binary. Example: +# -app 3 4 0 d 0 -short 340 -long "340 "`echo -n -e '\302\251'`"1999 GNU GPL" +# This may also be specified in a resource. +APP_VERSION := + +# (Only used when "TYPE" is "DRIVER"). Specify the desired driver install +# location in the /dev hierarchy. Example: +# DRIVER_PATH = video/usb +# will instruct the "driverinstall" rule to place a symlink to your driver's +# binary in ~/add-ons/kernel/drivers/dev/video/usb, so that your driver will +# appear at /dev/video/usb when loaded. The default is "misc". +DRIVER_PATH = + +## Include the Makefile-Engine +DEVEL_DIRECTORY := /boot/system/develop/ +include $(DEVEL_DIRECTORY)/etc/makefile-engine + +include Makefile.common +include protocols/Makefile.common diff --git a/protocols/irc/Templates.rdef b/protocols/irc/Templates.rdef new file mode 100644 index 0000000..bda2e30 --- /dev/null +++ b/protocols/irc/Templates.rdef @@ -0,0 +1,69 @@ +// "account" settings template +resource(1000, "account") message('IMst') +{ + "setting" = message + { + "name" = "nick", + "description" = "Nickname:", + "default" = "Haikunaut", + "error" = "You need a default nickname― The Nameless are not welcome on IRC.", + int32 "type" = 'CSTR' + }, + "setting" = message + { + "name" = "ident", + "description" = "Ident:", + int32 "type" = 'CSTR' + }, + "setting" = message + { + "name" = "password", + "description" = "Password:", + int32 "type" = 'CSTR' + }, + "setting" = message + { + "name" = "real_name", + "description" = "Real Name:", + "default" = "Mx. Catbird", + int32 "type" = 'CSTR' + }, + "setting" = message + { + "name" = "server", + "description" = "Server:", + "default" = "127.0.0.1", + "error" = "Please enter a valid server address.", + int32 "type" = 'CSTR' + }, + "setting" = message + { + "name" = "port", + "description" = "Port:", + int32 "default" = 10025, + "error" = "Without a port, we don't know which door to knock on.\nIt's likely 10025/6667.", + int32 "type" = 'LONG' + } +}; + +resource(1001, "roster") message('IMst') +{ + "setting" = message + { + "name" = "user_id", + "description" = "Nickname:", + "error" = "You can't friend someone without a nick.", + int32 "type" = 'CSTR' + } +}; + +resource(1002, "room") message('IMst') +{ + "setting" = message + { + "name" = "room_id", + "description" = "Room:", + "error" = "You can't friend someone without a nick.", + int32 "type" = 'CSTR' + } +}; diff --git a/protocols/irc/irc.rdef b/protocols/irc/irc.rdef new file mode 100644 index 0000000..55581f8 --- /dev/null +++ b/protocols/irc/irc.rdef @@ -0,0 +1,13 @@ + +resource app_version { + major = 0, + middle = 0, + minor = 1, + + variety = B_APPV_ALPHA, + internal = 0, + + short_info = "IRC Protocol AddOn", + long_info = "©2021 Jaidyn Levesque" +}; +