diff options
-rw-r--r-- | include/Exceptions.h | 4 | ||||
-rw-r--r-- | include/IRC.h | 201 | ||||
-rw-r--r-- | include/Makefile.am | 2 | ||||
-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 | ||||
-rw-r--r-- | src/Main.cc | 13 |
8 files changed, 462 insertions, 9 deletions
diff --git a/include/Exceptions.h b/include/Exceptions.h index 34c1155..6e8e1db 100644 --- a/include/Exceptions.h +++ b/include/Exceptions.h @@ -35,8 +35,8 @@ class Base { public: char * strdup(const char *) const; void * malloc(ssize_t) const; -/* void * operator new(size_t); - void * operator new(size_t, void *); */ + void * operator new(size_t); + void * operator new(size_t, void *); }; class GeneralException : public Base{ diff --git a/include/IRC.h b/include/IRC.h new file mode 100644 index 0000000..5f5a3f5 --- /dev/null +++ b/include/IRC.h @@ -0,0 +1,201 @@ +#ifndef __IRC_H__ +#define __IRC_H__ +#ifdef __cplusplus + +#include "Exceptions.h" +#include "Socket.h" + +#define RPL_WELCOME 1 +#define RPL_YOURHOST 2 +#define RPL_CREATED 3 +#define RPL_MYINFO 4 +#define RPL_BOUNCE 5 +#define RPL_TRACELINK 200 +#define RPL_TRACECONNECTING 201 +#define RPL_TRACEHANDSHAKE 202 +#define RPL_TRACEUNKNOWN 203 +#define RPL_TRACEOPERATOR 204 +#define RPL_TRACEUSER 205 +#define RPL_TRACESERVER 206 +#define RPL_TRACESERVICE 207 +#define RPL_TRACENEWTYPE 208 +#define RPL_TRACECLASS 209 +#define RPL_TRACERECONNECT 210 +#define RPL_STATSLINKINFO 211 +#define RPL_STATSCOMMANDS 212 +#define RPL_STATSCLINE 213 +#define RPL_STATSILINE 215 +#define RPL_STATSQLINE 217 +#define RPL_ENDOFSTATS 219 +#define RPL_UMODEIS 221 +#define RPL_SERVICEINFO 231 +#define RPL_SERVICE 233 +#define RPL_SERVLIST 234 +#define RPL_SERVLISTEND 235 +#define RPL_STATSVLINE 240 +#define RPL_STATSUPTIME 242 +#define RPL_STATSOLINE 243 +#define RPL_STATSHLINE 244 +#define RPL_STATSPING 246 +#define RPL_STATSDLINE 250 +#define RPL_LUSERCLIENT 251 +#define RPL_LUSEROP 252 +#define RPL_LUSERUNKNOWN 253 +#define RPL_LUSERCHANNELS 254 +#define RPL_LUSERME 255 +#define RPL_ADMINME 256 +#define RPL_ADMINLOC1 257 +#define RPL_ADMINLOC2 258 +#define RPL_ADMINEMAIL 259 +#define RPL_TRACELOG 261 +#define RPL_TRACEEND 262 +#define RPL_TRYAGAIN 263 +#define RPL_NONE 300 +#define RPL_AWAY 301 +#define RPL_USERHOST 302 +#define RPL_ISON 303 +#define RPL_UNAWAY 305 +#define RPL_NOWAWAY 306 +#define RPL_WHOISUSER 311 +#define RPL_WHOISSERVER 312 +#define RPL_WHOISOPERATOR 313 +#define RPL_WHOWASUSER 314 +#define RPL_ENDOFWHO 315 +#define RPL_WHOISIDLE 317 +#define RPL_ENDOFWHOIS 318 +#define RPL_WHOISCHANNELS 319 +#define RPL_LISTSTART 321 +#define RPL_LIST 322 +#define RPL_LISTEND 323 +#define RPL_CHANNELMODEIS 324 +#define RPL_UNIQOPIS 325 +#define RPL_NOTOPIC 331 +#define RPL_TOPIC 332 +#define RPL_INVITING 341 +#define RPL_SUMMONING 342 +#define RPL_INVITELIST 346 +#define RPL_ENDOFINVITELIST 347 +#define RPL_EXCEPTLIST 348 +#define RPL_ENDOFEXCEPTLIST 349 +#define RPL_VERSION 351 +#define RPL_WHOREPLY 352 +#define RPL_NAMREPLY 353 +#define RPL_KILLDONE 361 +#define RPL_CLOSEEND 363 +#define RPL_LINKS 364 +#define RPL_ENDOFLINKS 365 +#define RPL_ENDOFNAMES 366 +#define RPL_BANLIST 367 +#define RPL_ENDOFBANLIST 368 +#define RPL_ENDOFWHOWAS 369 +#define RPL_INFO 371 +#define RPL_MOTD 372 +#define RPL_ENDOFINFO 374 +#define RPL_MOTDSTART 375 +#define RPL_ENDOFMOTD 376 +#define RPL_YOUREOPER 381 +#define RPL_REHASHING 382 +#define RPL_YOURESERVICE 383 +#define RPL_MYPORTIS 384 +#define RPL_TIME 391 +#define RPL_USERSSTART 392 +#define RPL_USERS 393 +#define RPL_ENDOFUSERS 394 +#define RPL_NOUSERS 395 +#define ERR_NOSUCHNICK 401 +#define ERR_NOSUCHSERVER 402 +#define ERR_NOSUCHCHANNEL 403 +#define ERR_CANNOTSENDTOCHAN 404 +#define ERR_TOOMANYCHANNELS 405 +#define ERR_WASNOSUCHNICK 406 +#define ERR_TOOMANYTARGETS 407 +#define ERR_NOSUCHSERVICE 408 +#define ERR_NOORIGIN 409 +#define ERR_NORECIPIENT 411 +#define ERR_NOTEXTTOSEND 412 +#define ERR_NOTOPLEVEL 413 +#define ERR_WILDTOPLEVEL 414 +#define ERR_BADMASK 415 +#define ERR_UNKNOWNCOMMAND 421 +#define ERR_NOMOTD 422 +#define ERR_NOADMININFO 423 +#define ERR_FILEERROR 424 +#define ERR_NONICKNAMEGIVEN 431 +#define ERR_ERRONEUSNICKNAME 432 +#define ERR_NICKNAMEINUSE 433 +#define ERR_NICKCOLLISION 436 +#define ERR_UNAVAILRESOURCE 437 +#define ERR_USERNOTINCHANNEL 441 +#define ERR_NOTONCHANNEL 442 +#define ERR_USERONCHANNEL 443 +#define ERR_NOLOGIN 444 +#define ERR_SUMMONDISABLED 445 +#define ERR_USERSDISABLED 446 +#define ERR_NOTREGISTERED 451 +#define ERR_NEEDMOREPARAMS 461 +#define ERR_ALREADYREGISTRED 462 +#define ERR_NOPERMFORHOST 463 +#define ERR_PASSWDMISMATCH 464 +#define ERR_YOUREBANNEDCREEP 465 +#define ERR_YOUWILLBEBANNED 466 +#define ERR_KEYSET 467 +#define ERR_CHANNELISFULL 471 +#define ERR_UNKNOWNMODE 472 +#define ERR_INVITEONLYCHAN 473 +#define ERR_BANNEDFROMCHAN 474 +#define ERR_BADCHANNELKEY 475 +#define ERR_BADCHANMASK 476 +#define ERR_NOCHANMODES 477 +#define ERR_BANLISTFULL 478 +#define ERR_NOPRIVILEGES 481 +#define ERR_CHANOPRIVSNEEDED 482 +#define ERR_CANTKILLSERVER 483 +#define ERR_RESTRICTED 484 +#define ERR_UNIQOPPRIVSNEEDED 485 +#define ERR_NOOPERHOST 491 +#define ERR_NOSERVICEHOST 492 +#define ERR_UMODEUNKNOWNFLAG 501 +#define ERR_USERSDONTMATCH 502 + +typedef struct { + char * msg; + int code; +} ircmsg_t; + +#define MSG_COUNT 151 + +extern ircmsg_t ircmsgs[]; + +class Channel : public Base { + public: + Channel(const String &, const String & = ""); + ~Channel(); + protected: + Channel * GetNext(); + Channel * GetPrev(); + String GetName(); + String GetKey(); + private: + String Name, Key; + static Channel * start; + Channel * next, * prev; +}; + +class IRC : public Base { + public: + IRC(const String & = "Nick", const String & = "irc.openprojects.net", const String & = "guest_user", const String & = "Irc Name", int Port = 6667); + virtual ~IRC(); + bool Connect(); + void MainLoop(); + private: + int Parse(const String &); + String nick, server, user, name; + int port; + Socket sock; + int loginsequence; +}; + +#else +#error This only works with a C++ compiler +#endif +#endif diff --git a/include/Makefile.am b/include/Makefile.am index f58566a..ca7f866 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -1,2 +1,2 @@ -include_HEADERS = Exceptions.h Handle.h String.h Output.h Socket.h HttpServ.h Variables.h Menu.h Action.h Message.h Form.h Confirm.h Table.h +include_HEADERS = Exceptions.h Handle.h String.h Output.h Socket.h HttpServ.h Variables.h Menu.h Action.h Message.h Form.h Confirm.h Table.h IRC.h 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; diff --git a/src/Main.cc b/src/Main.cc index ffadd67..e874fcf 100644 --- a/src/Main.cc +++ b/src/Main.cc @@ -1,4 +1,5 @@ #include <unistd.h> +#include <list> #include "Action.h" #include "Handle.h" #include "HttpServ.h" @@ -10,6 +11,7 @@ #include "Form.h" #include "Confirm.h" #include "Table.h" +#include "IRC.h" class InPipe : public Handle { public: @@ -25,6 +27,10 @@ class InPipe : public Handle { int main(int argc, char ** argv) { int p[2], c; + list<String> testlist; + IRC ircclient("botalacon"); + + testlist.push_front("poide"); if (pipe(p)) { cerr << "Error creating pipe.\n"; @@ -55,6 +61,13 @@ int main(int argc, char ** argv) { } try { + cerr << "Connecting..." << endl; + if (ircclient.Connect()) { + cerr << "Doing main loop..." << endl; + ircclient.MainLoop(); + } else { + cerr << "Error connecting..." << endl; + } } catch (GeneralException e) { cerr << e.GetMsg() << endl; |