diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Exceptions.cc | 8 | ||||
-rw-r--r-- | lib/IRC.cc | 233 | ||||
-rw-r--r-- | lib/Makefile.am | 2 | ||||
-rw-r--r-- | lib/Socket.cc | 8 |
4 files changed, 245 insertions, 6 deletions
diff --git a/lib/Exceptions.cc b/lib/Exceptions.cc index b5a33bd..734e5e9 100644 --- a/lib/Exceptions.cc +++ b/lib/Exceptions.cc @@ -17,15 +17,15 @@ void * Base::malloc(ssize_t s) const { return xmalloc(s); } -/* + void * Base::operator new(size_t s) { return memset(xmalloc(s), 0, s); } -void * Base::operator new(size_t s, void * & p) { - return memset(p = xmalloc(s), 0, s); +void * Base::operator new(size_t s, void * p) { + memset(p, 0, s); + return p; } -*/ GeneralException::GeneralException(String emsg) : msg(strdup(emsg.to_charp())) { } GeneralException::GeneralException() : msg(0) { } diff --git a/lib/IRC.cc b/lib/IRC.cc new file mode 100644 index 0000000..8ba15cc --- /dev/null +++ b/lib/IRC.cc @@ -0,0 +1,233 @@ +#include "String.h" +#include "IRC.h" +#include "HttpServ.h" + +ircmsg_t ircmsgs[MSG_COUNT] = + +{ + { "RPL_WELCOME", RPL_WELCOME }, + { "RPL_YOURHOST", RPL_YOURHOST }, + { "RPL_CREATED", RPL_CREATED }, + { "RPL_MYINFO", RPL_MYINFO }, + { "RPL_BOUNCE", RPL_BOUNCE }, + { "RPL_TRACELINK", RPL_TRACELINK }, + { "RPL_TRACECONNECTING", RPL_TRACECONNECTING }, + { "RPL_TRACEHANDSHAKE", RPL_TRACEHANDSHAKE }, + { "RPL_TRACEUNKNOWN", RPL_TRACEUNKNOWN }, + { "RPL_TRACEOPERATOR", RPL_TRACEOPERATOR }, + { "RPL_TRACEUSER", RPL_TRACEUSER }, + { "RPL_TRACESERVER", RPL_TRACESERVER }, + { "RPL_TRACESERVICE", RPL_TRACESERVICE }, + { "RPL_TRACENEWTYPE", RPL_TRACENEWTYPE }, + { "RPL_TRACECLASS", RPL_TRACECLASS }, + { "RPL_TRACERECONNECT", RPL_TRACERECONNECT }, + { "RPL_STATSLINKINFO", RPL_STATSLINKINFO }, + { "RPL_STATSCOMMANDS", RPL_STATSCOMMANDS }, + { "RPL_STATSCLINE", RPL_STATSCLINE }, + { "RPL_STATSILINE", RPL_STATSILINE }, + { "RPL_STATSQLINE", RPL_STATSQLINE }, + { "RPL_ENDOFSTATS", RPL_ENDOFSTATS }, + { "RPL_UMODEIS", RPL_UMODEIS }, + { "RPL_SERVICEINFO", RPL_SERVICEINFO }, + { "RPL_SERVICE", RPL_SERVICE }, + { "RPL_SERVLIST", RPL_SERVLIST }, + { "RPL_SERVLISTEND", RPL_SERVLISTEND }, + { "RPL_STATSVLINE", RPL_STATSVLINE }, + { "RPL_STATSUPTIME", RPL_STATSUPTIME }, + { "RPL_STATSOLINE", RPL_STATSOLINE }, + { "RPL_STATSHLINE", RPL_STATSHLINE }, + { "RPL_STATSPING", RPL_STATSPING }, + { "RPL_STATSDLINE", RPL_STATSDLINE }, + { "RPL_LUSERCLIENT", RPL_LUSERCLIENT }, + { "RPL_LUSEROP", RPL_LUSEROP }, + { "RPL_LUSERUNKNOWN", RPL_LUSERUNKNOWN }, + { "RPL_LUSERCHANNELS", RPL_LUSERCHANNELS }, + { "RPL_LUSERME", RPL_LUSERME }, + { "RPL_ADMINME", RPL_ADMINME }, + { "RPL_ADMINLOC1", RPL_ADMINLOC1 }, + { "RPL_ADMINLOC2", RPL_ADMINLOC2 }, + { "RPL_ADMINEMAIL", RPL_ADMINEMAIL }, + { "RPL_TRACELOG", RPL_TRACELOG }, + { "RPL_TRACEEND", RPL_TRACEEND }, + { "RPL_TRYAGAIN", RPL_TRYAGAIN }, + { "RPL_NONE", RPL_NONE }, + { "RPL_AWAY", RPL_AWAY }, + { "RPL_USERHOST", RPL_USERHOST }, + { "RPL_ISON", RPL_ISON }, + { "RPL_UNAWAY", RPL_UNAWAY }, + { "RPL_NOWAWAY", RPL_NOWAWAY }, + { "RPL_WHOISUSER", RPL_WHOISUSER }, + { "RPL_WHOISSERVER", RPL_WHOISSERVER }, + { "RPL_WHOISOPERATOR", RPL_WHOISOPERATOR }, + { "RPL_WHOWASUSER", RPL_WHOWASUSER }, + { "RPL_ENDOFWHO", RPL_ENDOFWHO }, + { "RPL_WHOISIDLE", RPL_WHOISIDLE }, + { "RPL_ENDOFWHOIS", RPL_ENDOFWHOIS }, + { "RPL_WHOISCHANNELS", RPL_WHOISCHANNELS }, + { "RPL_LISTSTART", RPL_LISTSTART }, + { "RPL_LIST", RPL_LIST }, + { "RPL_LISTEND", RPL_LISTEND }, + { "RPL_CHANNELMODEIS", RPL_CHANNELMODEIS }, + { "RPL_UNIQOPIS", RPL_UNIQOPIS }, + { "RPL_NOTOPIC", RPL_NOTOPIC }, + { "RPL_TOPIC", RPL_TOPIC }, + { "RPL_INVITING", RPL_INVITING }, + { "RPL_SUMMONING", RPL_SUMMONING }, + { "RPL_INVITELIST", RPL_INVITELIST }, + { "RPL_ENDOFINVITELIST", RPL_ENDOFINVITELIST }, + { "RPL_EXCEPTLIST", RPL_EXCEPTLIST }, + { "RPL_ENDOFEXCEPTLIST", RPL_ENDOFEXCEPTLIST }, + { "RPL_VERSION", RPL_VERSION }, + { "RPL_WHOREPLY", RPL_WHOREPLY }, + { "RPL_NAMREPLY", RPL_NAMREPLY }, + { "RPL_KILLDONE", RPL_KILLDONE }, + { "RPL_CLOSEEND", RPL_CLOSEEND }, + { "RPL_LINKS", RPL_LINKS }, + { "RPL_ENDOFLINKS", RPL_ENDOFLINKS }, + { "RPL_ENDOFNAMES", RPL_ENDOFNAMES }, + { "RPL_BANLIST", RPL_BANLIST }, + { "RPL_ENDOFBANLIST", RPL_ENDOFBANLIST }, + { "RPL_ENDOFWHOWAS", RPL_ENDOFWHOWAS }, + { "RPL_INFO", RPL_INFO }, + { "RPL_MOTD", RPL_MOTD }, + { "RPL_ENDOFINFO", RPL_ENDOFINFO }, + { "RPL_MOTDSTART", RPL_MOTDSTART }, + { "RPL_ENDOFMOTD", RPL_ENDOFMOTD }, + { "RPL_YOUREOPER", RPL_YOUREOPER }, + { "RPL_REHASHING", RPL_REHASHING }, + { "RPL_YOURESERVICE", RPL_YOURESERVICE }, + { "RPL_MYPORTIS", RPL_MYPORTIS }, + { "RPL_TIME", RPL_TIME }, + { "RPL_USERSSTART", RPL_USERSSTART }, + { "RPL_USERS", RPL_USERS }, + { "RPL_ENDOFUSERS", RPL_ENDOFUSERS }, + { "RPL_NOUSERS", RPL_NOUSERS }, + { "ERR_NOSUCHNICK", ERR_NOSUCHNICK }, + { "ERR_NOSUCHSERVER", ERR_NOSUCHSERVER }, + { "ERR_NOSUCHCHANNEL", ERR_NOSUCHCHANNEL }, + { "ERR_CANNOTSENDTOCHAN", ERR_CANNOTSENDTOCHAN }, + { "ERR_TOOMANYCHANNELS", ERR_TOOMANYCHANNELS }, + { "ERR_WASNOSUCHNICK", ERR_WASNOSUCHNICK }, + { "ERR_TOOMANYTARGETS", ERR_TOOMANYTARGETS }, + { "ERR_NOSUCHSERVICE", ERR_NOSUCHSERVICE }, + { "ERR_NOORIGIN", ERR_NOORIGIN }, + { "ERR_NORECIPIENT", ERR_NORECIPIENT }, + { "ERR_NOTEXTTOSEND", ERR_NOTEXTTOSEND }, + { "ERR_NOTOPLEVEL", ERR_NOTOPLEVEL }, + { "ERR_WILDTOPLEVEL", ERR_WILDTOPLEVEL }, + { "ERR_BADMASK", ERR_BADMASK }, + { "ERR_UNKNOWNCOMMAND", ERR_UNKNOWNCOMMAND }, + { "ERR_NOMOTD", ERR_NOMOTD }, + { "ERR_NOADMININFO", ERR_NOADMININFO }, + { "ERR_FILEERROR", ERR_FILEERROR }, + { "ERR_NONICKNAMEGIVEN", ERR_NONICKNAMEGIVEN }, + { "ERR_ERRONEUSNICKNAME", ERR_ERRONEUSNICKNAME }, + { "ERR_NICKNAMEINUSE", ERR_NICKNAMEINUSE }, + { "ERR_NICKCOLLISION", ERR_NICKCOLLISION }, + { "ERR_UNAVAILRESOURCE", ERR_UNAVAILRESOURCE }, + { "ERR_USERNOTINCHANNEL", ERR_USERNOTINCHANNEL }, + { "ERR_NOTONCHANNEL", ERR_NOTONCHANNEL }, + { "ERR_USERONCHANNEL", ERR_USERONCHANNEL }, + { "ERR_NOLOGIN", ERR_NOLOGIN }, + { "ERR_SUMMONDISABLED", ERR_SUMMONDISABLED }, + { "ERR_USERSDISABLED", ERR_USERSDISABLED }, + { "ERR_NOTREGISTERED", ERR_NOTREGISTERED }, + { "ERR_NEEDMOREPARAMS", ERR_NEEDMOREPARAMS }, + { "ERR_ALREADYREGISTRED", ERR_ALREADYREGISTRED }, + { "ERR_NOPERMFORHOST", ERR_NOPERMFORHOST }, + { "ERR_PASSWDMISMATCH", ERR_PASSWDMISMATCH }, + { "ERR_YOUREBANNEDCREEP", ERR_YOUREBANNEDCREEP }, + { "ERR_YOUWILLBEBANNED", ERR_YOUWILLBEBANNED }, + { "ERR_KEYSET", ERR_KEYSET }, + { "ERR_CHANNELISFULL", ERR_CHANNELISFULL }, + { "ERR_UNKNOWNMODE", ERR_UNKNOWNMODE }, + { "ERR_INVITEONLYCHAN", ERR_INVITEONLYCHAN }, + { "ERR_BANNEDFROMCHAN", ERR_BANNEDFROMCHAN }, + { "ERR_BADCHANNELKEY", ERR_BADCHANNELKEY }, + { "ERR_BADCHANMASK", ERR_BADCHANMASK }, + { "ERR_NOCHANMODES", ERR_NOCHANMODES }, + { "ERR_BANLISTFULL", ERR_BANLISTFULL }, + { "ERR_NOPRIVILEGES", ERR_NOPRIVILEGES }, + { "ERR_CHANOPRIVSNEEDED", ERR_CHANOPRIVSNEEDED }, + { "ERR_CANTKILLSERVER", ERR_CANTKILLSERVER }, + { "ERR_RESTRICTED", ERR_RESTRICTED }, + { "ERR_UNIQOPPRIVSNEEDED", ERR_UNIQOPPRIVSNEEDED }, + { "ERR_NOOPERHOST", ERR_NOOPERHOST }, + { "ERR_NOSERVICEHOST", ERR_NOSERVICEHOST }, + { "ERR_UMODEUNKNOWNFLAG", ERR_UMODEUNKNOWNFLAG }, + { "ERR_USERSDONTMATCH", ERR_USERSDONTMATCH }, +}; + +Channel * Channel::start = NULL; + +Channel::Channel(const String & Name, const String & Key) : next(NULL), prev(NULL) { + next = start->next; + prev = start; + start = this; + if (next) next->prev = this; +} + +Channel::~Channel() { + if (next) next->prev = prev; + if (prev) prev->next = next; else start = next; +} + +ircmsg_t find_msg(int code) { + int i; + + ircmsg_t ret = {"", code}; + + for (i = 0; i < MSG_COUNT; i++) { + if (code == ircmsgs[i].code) return ircmsgs[i]; + } + + return ret; +} + +IRC::IRC(const String & nick_n, const String & server_n, const String & user_n, const String & name_n, int port_n) : + nick(nick_n), server(server_n), user(user_n), name(name_n), port(port_n), loginsequence(1) { +} + +IRC::~IRC() { +} + +bool IRC::Connect() { + return sock.Connect(server, port); +} + +int IRC::Parse(const String & line) { + if (!strcmp(line.to_charp(0, 3), "PING")) { + sock << "PONG" << line.to_charp(4) << endhl; + cerr << "PING/PONG" << line.to_charp(4) << endhl; + return 0; + } + + return 1; +} + +void IRC::MainLoop() { + String line; + int code, count = 0; + + while (true) { + switch (loginsequence) { + case 1: + cerr << "Trying the login sequence..." << endl; + sock << "NICK " << nick << endhl; + sock << "USER " << user << " 8 * :" << name << endhl; + sock << "JOIN #phear.org dede" << endhl; + loginsequence = 0; + } + sock >> line; + if ((code = Parse(line))) { +// sock << "PRIVMSG #phear.org : Unparsable: " << line << endhl; + cerr << "Unparsable: " << line << endl; + } + + if (count == 20) { + sock << "JOIN #phear.org dede" << endhl; + } + + count++; + } +} diff --git a/lib/Makefile.am b/lib/Makefile.am index 58cc6e7..edb449d 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -7,6 +7,6 @@ lib_LTLIBRARIES = libBaltisot.la libBaltisot_la_SOURCES = Exceptions.cc Handle.cc Output.cc String.cc\ Socket.cc Input.cc HttpServ.cc Variables.cc Action.cc Menu.cc Message.cc\ - Form.cc Confirm.cc Table.cc checkargs.c datecalc.c + Form.cc Confirm.cc Table.cc checkargs.c datecalc.c IRC.cc libBaltisot_la_LDFLAGS = -release $(Baltisot_VERSION_INFO) diff --git a/lib/Socket.cc b/lib/Socket.cc index 100d434..de6f42e 100644 --- a/lib/Socket.cc +++ b/lib/Socket.cc @@ -2,6 +2,7 @@ #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> +#include <errno.h> #include <string.h> #include <strings.h> #include <errno.h> @@ -104,6 +105,7 @@ bool Socket::Connect(String host, int port) { struct sockaddr_in remotesocketaddr; if (!listening && !connected) { + cerr << " - Resolving '" << host << "'..." << endl; if (!(remotehostent = gethostbyname(host.to_charp()))) { return false; } @@ -111,8 +113,12 @@ bool Socket::Connect(String host, int port) { remotesocketaddr.sin_family = AF_INET; remotesocketaddr.sin_port = htons(port); bcopy(remotehostent->h_addr, &remotesocketaddr.sin_addr, remotehostent->h_length); - if(connect(GetHandle(), (struct sockaddr *)&remotesocketaddr, sizeof(remotesocketaddr)) < 0) { + cerr << " - Connecting to port " << port << " ..." << endl; + if (!connect(GetHandle(), (struct sockaddr *)&remotesocketaddr, sizeof(remotesocketaddr))) { + cerr << " - Connected." << endl; connected = true; + } else { + cerr << " - Error connecting: " << strerror(errno) << endl; } } return connected; |