From: <Jef...@us...> - 2007-07-25 22:14:50
|
Revision: 208 http://libirc.svn.sourceforge.net/libirc/?rev=208&view=rev Author: JeffM2501 Date: 2007-07-25 15:14:44 -0700 (Wed, 25 Jul 2007) Log Message: ----------- add an event at the end of the connection cycle ( end of MOTD ) eIRCConnectedEvent so that clients know when they can start joining channels and sending messages and stuff. Modified Paths: -------------- trunk/libirc/include/IRCEvents.h trunk/libirc/src/irClientEvents.cpp Modified: trunk/libirc/include/IRCEvents.h =================================================================== --- trunk/libirc/include/IRCEvents.h 2007-04-24 16:56:46 UTC (rev 207) +++ trunk/libirc/include/IRCEvents.h 2007-07-25 22:14:44 UTC (rev 208) @@ -29,6 +29,7 @@ eIRCNickNameChange, eIRCWelcomeEvent, eIRCEndMOTDEvent, + eIRCConnectedEvent, eIRCChannelJoinEvent, eIRCChannelPartEvent, eIRCChannelBanEvent, Modified: trunk/libirc/src/irClientEvents.cpp =================================================================== --- trunk/libirc/src/irClientEvents.cpp 2007-04-24 16:56:46 UTC (rev 207) +++ trunk/libirc/src/irClientEvents.cpp 2007-07-25 22:14:44 UTC (rev 208) @@ -52,6 +52,7 @@ trBaseEventInfo info; // no info callEventHandler(eIRCEndMOTDEvent,info); + callEventHandler(eIRCConnectedEvent,info); } void IRCClient::joinMessage ( BaseIRCCommandInfo &info ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Jef...@us...> - 2007-07-25 22:22:27
|
Revision: 209 http://libirc.svn.sourceforge.net/libirc/?rev=209&view=rev Author: JeffM2501 Date: 2007-07-25 15:22:25 -0700 (Wed, 25 Jul 2007) Log Message: ----------- it's IRCTextUtils not TextUtils. set it straight everywheres Modified Paths: -------------- trunk/libirc/include/Makefile.am trunk/libirc/src/Makefile.am trunk/libirc/vc7.1/libirc.vcproj trunk/libirc/vc8/libirc.vcproj Added Paths: ----------- trunk/libirc/src/IRCTextUtils.cxx Removed Paths: ------------- trunk/libirc/include/TCPConnection.h trunk/libirc/src/TextUtils.cxx Modified: trunk/libirc/include/Makefile.am =================================================================== --- trunk/libirc/include/Makefile.am 2007-07-25 22:14:44 UTC (rev 208) +++ trunk/libirc/include/Makefile.am 2007-07-25 22:22:25 UTC (rev 209) @@ -2,7 +2,7 @@ include_HEADERS = \ TCPConnection.h \ - TextUtils.h \ + IRCTextUtils.h \ Singleton.h \ IRCNumerics.h \ IRCEvents.h \ Deleted: trunk/libirc/include/TCPConnection.h =================================================================== --- trunk/libirc/include/TCPConnection.h 2007-07-25 22:14:44 UTC (rev 208) +++ trunk/libirc/include/TCPConnection.h 2007-07-25 22:22:25 UTC (rev 209) @@ -1,326 +0,0 @@ -/* libIRC -* Copyright (c) 2004 Christopher Sean Morrison -* -* This package is free software; you can redistribute it and/or -* modify it under the terms of the license found in the file -* named LICENSE that should have accompanied this file. -* -* THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR -* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED -* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. -*/ - -// TCP/IP connection class header - -#ifndef _TCP_CONNECTION_H_ -#define _TCP_CONNECTION_H_ - -#include <vector> -#include <string> -#include <map> - -#include "Singleton.h" -#include "net.h" - -// ------------------------TCP classes-------------------- -class TCPConnection; - -typedef enum -{ - eTCPNoError = 0, - eTCPNotInit, - eTCPTimeout, - eTCPBadAddress, - eTCPBadPort, - eTCPConnectionFailed, - eTCPSocketNFG, - eTCPInitFailed, - eTCPSelectFailed, - eTCPDataNFG, - eTCPUnknownError -}teTCPError; - -// Packet data class -// this class is realy just to hold data, and make sure it get deallocated. -class TCPPacket -{ -public: - TCPPacket(); - TCPPacket( const TCPPacket &p ); - TCPPacket( unsigned char* buf, unsigned int len ); - ~TCPPacket(); - - TCPPacket& operator = ( const TCPPacket &p ); - - void set ( unsigned char* buf, unsigned int len ); - unsigned char* get ( unsigned int &len ); - -protected: - unsigned char *data; - unsigned int size; -}; - -typedef std::vector<TCPPacket> tvPacketList; - -class TCPClientConnection; - -class TCPClientDataPendingListener -{ -public: - virtual ~TCPClientDataPendingListener(){return;}; - virtual void pending ( TCPClientConnection *connection, int count ) = 0; -}; - -typedef std::vector<TCPClientDataPendingListener*> tvClientDataPendingListenerList; - -// TCP/IP client connection to some host on some port -class TCPClientConnection -{ -public: - // connections - teTCPError connect ( std::string server, unsigned short port ); - teTCPError connect ( void ); - teTCPError disconnect( void ); - - // status - bool connected ( void ); - - // packet polling - bool packets ( void ); - tvPacketList& getPackets ( void ); - - // error handaling - teTCPError getLastError ( void ); - teTCPError setError ( teTCPError error ); - - // data read - // generaly only called by the parent - void readData ( void ); - - // data send - teTCPError sendData ( void *data, int len ); - teTCPError sendData ( const char *data, int len ); - teTCPError sendData ( std::string data ); - - // utils - void setReadChunkSize ( unsigned int size ); - unsigned int getReadChunkSize ( void ); - - // data pending listeners - // let the people register a callback class to be called when data is receved - void addListener ( TCPClientDataPendingListener* listener ); - void removeListener ( TCPClientDataPendingListener* listener ); - - TCPsocket socket; - -protected: - // who's your daddy - friend class TCPConnection; - - // only daddy should make us - TCPClientConnection(); - TCPClientConnection( std::string server, unsigned short port, TCPConnection *parentConnection ); - ~TCPClientConnection(); - - TCPConnection *parent; - tvPacketList packetList; - - teTCPError lastError; - IPaddress serverIP; - int readChunkSize; - - // listeners - tvClientDataPendingListenerList dataPendingList; - void callDataPendingListeners ( int count ); -}; - -// server connection classes -class TCPServerConnection; - -class TCPServerConnectedPeer -{ -public: - TCPServerConnectedPeer(); - ~TCPServerConnectedPeer(); - - // data pending - bool packets ( void ); - tvPacketList& getPackets ( void ); - unsigned int getPacketCount ( void ) {return (unsigned int)packetList.size();} - void flushPackets ( void ); - - //TCPServerConnectedPeer& operator = ( const TCPServerConnectedPeer &p ); - - // error handling - teTCPError getLastError ( void ); - teTCPError setError ( teTCPError error ); - - // called by the server class - void connect ( void* _socket ); - bool readData ( void ); - - // data send - teTCPError sendData ( void *data, int len ); - teTCPError sendData ( const char *data, int len ); - teTCPError sendData ( std::string data ); - - // client info - unsigned int getUID ( void ){ return UID; } - void* getParam ( void ) {return param;} - void setParam ( void * p ){ param = p;} - const std::string getHostMask ( void ); - bool getIP ( unsigned char ip[4] ); - -protected: - unsigned int UID; - - TCPsocket socket; - IPaddress address; - teTCPError lastError; - - tvPacketList packetList; - std::string host; - - void *param; -}; - -class TCPServerDataPendingListener -{ -public: - virtual ~TCPServerDataPendingListener(){return;}; - virtual bool connect ( TCPServerConnection *connection, TCPServerConnectedPeer *peer ) = 0; - virtual void pending ( TCPServerConnection *connection, TCPServerConnectedPeer *peer, unsigned int count ) = 0; - virtual void disconnect ( TCPServerConnection *connection, TCPServerConnectedPeer *peer, bool forced = false ){}; -}; - -typedef std::vector<TCPServerDataPendingListener*> tvServerDataPendingListenerList; - -typedef struct -{ - -}trServerConectedPeer; - -// TCP/IP server connection listening for some connections on some port -class TCPServerConnection -{ -public: - TCPServerConnection(); - TCPServerConnection( unsigned short port, unsigned int connections, TCPConnection *parentConnection ); - ~TCPServerConnection(); - - teTCPError listen ( unsigned short port, unsigned int connections ); - teTCPError disconnect( void ); - - // status - bool listening ( void ); - - // info - unsigned short getPort ( void ); - unsigned int getMaxConnections ( void ); - - // error handaling - teTCPError getLastError ( void ); - teTCPError setError ( teTCPError error ); - - // data pending listeners - // let the people register a callback class to be called when data is receved - void addListener ( TCPServerDataPendingListener* listener ); - void removeListener ( TCPServerDataPendingListener* listener ); - - std::vector<TCPServerConnectedPeer*> getPeers ( void ); - TCPServerConnectedPeer* getPeerFromUID ( unsigned int UID ); - - bool disconectPeer ( unsigned int UID ); - bool disconectPeer ( TCPServerConnectedPeer* peer ); - - // update the shizzle - bool update ( void ); - -protected: - // who's your daddy - friend class TCPConnection; - TCPConnection *parent; - - teTCPError lastError; - int maxUsers; - IPaddress serverIP; - TCPsocket socket; - int readChunkSize; - - net_SocketSet socketSet; - std::map<TCPsocket,TCPServerConnectedPeer> peers; - - // listeners - tvServerDataPendingListenerList dataPendingList; -}; - -// master TCP/IP connection manager -// takes care of loading and clearing out the TCP stack if it needs it -// gives out client and server connections -// handles the non blocking updates of connections. -class TCPConnection : public Singleton<TCPConnection> -{ -public: - // initalises the socket system, on windows inits WSA - // called automaticly by the constructor, but exposted - // in case the client needs to reinit the socket system - teTCPError init ( void ); - - // kills the socket system, closes all connections, - // and on windows cleans up the WSA system - void kill ( void ); - - // has all connections check for new data - teTCPError update ( void ); - void setUpdateTimeout ( int timeout ); - - // returns a new client conenction to the specified host and port - TCPClientConnection* newClientConnection ( std::string server, unsigned short port ); - - // returns a new server connection that will listen for the - // specified number of connections on the specfied port - TCPServerConnection* newServerConnection ( unsigned short port, int connections ); - - // disconnects and removes connections - void deleteClientConnection ( TCPClientConnection* connection ); - void deleteServerConnection ( TCPServerConnection* connection ); - - // returns the lost host - std::string getLocalHost ( void ); - -protected: - friend class Singleton<TCPConnection>; - - TCPConnection(); - ~TCPConnection(); - - friend class TCPClientConnection; - friend class TCPServerConnection; - - typedef std::vector<TCPClientConnection*> tvClientConnectionList; - tvClientConnectionList clientConnections; - - typedef std::vector<TCPServerConnection*> tvServerConnectionList; - tvServerConnectionList serverConnections; - - bool addClientSocket ( TCPClientConnection* client ); - - bool removeClientSocket ( TCPClientConnection* client ); - - typedef std::map<TCPsocket, TCPClientConnection* > tmClientSocketMap; - tmClientSocketMap clientSockets; - net_SocketSet clientSocketSet; - - bool initedSocketInterface; - int timeout; -}; - -#endif //_TCP_CONNECTION_H_ - -// Local Variables: *** -// mode: C++ *** -// tab-width: 8 *** -// c-basic-offset: 2 *** -// indent-tabs-mode: t *** -// End: *** -// ex: shiftwidth=2 tabstop=8 Copied: trunk/libirc/src/IRCTextUtils.cxx (from rev 207, trunk/libirc/src/TextUtils.cxx) =================================================================== --- trunk/libirc/src/IRCTextUtils.cxx (rev 0) +++ trunk/libirc/src/IRCTextUtils.cxx 2007-07-25 22:22:25 UTC (rev 209) @@ -0,0 +1,268 @@ +/* bzflag + * Copyright (c) 1993 - 2004 Tim Riker + * + * This package is free software; you can redistribute it and/or + * modify it under the terms of the license found in the file + * named COPYING that should have accompanied this file. + * + * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ + +// interface header +#include "IRCTextUtils.h" + +// system headers +#include <string> +#include <algorithm> +#include <sstream> +#include <stdarg.h> +#include <vector> + +namespace string_util +{ + std::string vformat(const char* fmt, va_list args) { + // FIXME -- should prevent buffer overflow in all cases + // not all platforms support vsnprintf so we'll use vsprintf and a + // big temporary buffer and hope for the best. + char buffer[8192]; + vsnprintf(buffer, 8192, fmt, args); + return std::string(buffer); + } + + + std::string format(const char* fmt, ...) { + va_list args; + va_start(args, fmt); + std::string result = vformat(fmt, args); + va_end(args); + return result; + } + + + std::string replace_all(const std::string& in, const std::string& replaceMe, const std::string& withMe) + { + std::string result; + std::string::size_type beginPos = 0; + std::string::size_type endPos = 0; + std::ostringstream tempStream; + + endPos = in.find(replaceMe); + if (endPos == std::string::npos) + return in; // can't find anything to replace + if (replaceMe.empty()) return in; // can't replace nothing with something -- can do reverse + + while (endPos != std::string::npos) { + // push the part up to + tempStream << in.substr(beginPos,endPos-beginPos); + tempStream << withMe; + beginPos = endPos + replaceMe.size(); + endPos = in.find(replaceMe,beginPos); + } + tempStream << in.substr(beginPos); + return tempStream.str(); + } + + + std::vector<std::string> tokenize(const std::string& in, const std::string &delims, const int maxTokens, const bool useQuotes){ + std::vector<std::string> tokens; + int numTokens = 0; + bool inQuote = false; + + std::ostringstream currentToken; + + std::string::size_type pos = in.find_first_not_of(delims); + int currentChar = (pos == std::string::npos) ? -1 : in[pos]; + bool enoughTokens = (maxTokens && (numTokens >= (maxTokens-1))); + + while (pos != std::string::npos && !enoughTokens) { + + // get next token + bool tokenDone = false; + bool foundSlash = false; + + currentChar = (pos < in.size()) ? in[pos] : -1; + while ((currentChar != -1) && !tokenDone){ + + tokenDone = false; + + if (delims.find(currentChar) != std::string::npos && !inQuote) { // currentChar is a delim + pos ++; + break; // breaks out of while look + } + + if (!useQuotes){ + currentToken << char(currentChar); + } else { + + switch (currentChar){ + case '\\' : // found a backslash + if (foundSlash){ + currentToken << char(currentChar); + foundSlash = false; + } else { + foundSlash = true; + } + break; + case '\"' : // found a quote + if (foundSlash){ // found \" + currentToken << char(currentChar); + foundSlash = false; + } else { // found unescaped " + if (inQuote){ // exiting a quote + // finish off current token + tokenDone = true; + inQuote = false; + //slurp off one additional delimeter if possible + if (pos+1 < in.size() && + delims.find(in[pos+1]) != std::string::npos) { + pos++; + } + + } else { // entering a quote + // finish off current token + tokenDone = true; + inQuote = true; + } + } + break; + default: + if (foundSlash){ // don't care about slashes except for above cases + currentToken << '\\'; + foundSlash = false; + } + currentToken << char(currentChar); + break; + } + } + + pos++; + currentChar = (pos < in.size()) ? in[pos] : -1; + } // end of getting a Token + + if (currentToken.str().size() > 0){ // if the token is something add to list + tokens.push_back(currentToken.str()); + currentToken.str(""); + numTokens ++; + } + + enoughTokens = (maxTokens && (numTokens >= (maxTokens-1))); + if (enoughTokens){ + break; + } else{ + pos = in.find_first_not_of(delims,pos); + } + + } // end of getting all tokens -- either EOL or max tokens reached + + if (enoughTokens && pos != std::string::npos) { + std::string lastToken = in.substr(pos); + if (lastToken.size() > 0) + tokens.push_back(lastToken); + } + + return tokens; + } + + int parseDuration(const std::string &duration) + { + int durationInt = 0; + int t = 0; + + int len = (int)duration.length(); + for(int i=0; i < len; i++) { + if (isdigit(duration[i])) { + t = t * 10 + (duration[i] - '0'); + } + else if(duration[i] == 'h' || duration[i] == 'H') { + durationInt += (t * 60); + t = 0; + } + else if(duration[i] == 'd' || duration[i] == 'D') { + durationInt += (t * 1440); + t = 0; + } + else if(duration[i] == 'w' || duration[i] == 'w') { + durationInt += (t * 10080); + t = 0; + } + } + durationInt += t; + return durationInt; + } + + std::string url_encode(const std::string &text) + { + char hex[5]; + std::string destination; + for (int i=0; i < (int) text.size(); i++) { + char c = text[i]; + if (isAlphanumeric(c)) { + destination+=c; + } else if (isWhitespace(c)) { + destination+='+'; + } else { + destination+='%'; + sprintf(hex, "%-2.2X", c); + destination.append(hex); + } + } + return destination; + } + + + std::string escape(const std::string &text, char escaper) + { + std::string destination; + for (int i = 0; i < (int) text.size(); i++) { + char c = text[i]; + if (!isAlphanumeric(c)) + destination += escaper; + destination += c; + } + return destination; + } + + std::string unescape(const std::string &text, char escaper) + { + const int len = (int) text.size(); + std::string destination; + for (int i = 0; i < len; i++) { + char c = text[i]; + if (c == escaper) { + if (i < len - 1) + destination += text[++i]; + else + // Should print an error + ; + } else { + destination += c; + } + } + return destination; + } + + int unescape_lookup(const std::string &text, char escaper, char sep) + { + int position = -1; + for (int i = 0; i < (int) text.size(); i++) { + char c = text[i]; + if (c == sep) { + position = i; + break; + } + if (c == escaper) + i++; + } + return position; + } +}; + +// Local Variables: *** +// mode: C++ *** +// tab-width: 8 *** +// c-basic-offset: 2 *** +// indent-tabs-mode: t *** +// End: *** +// ex: shiftwidth=2 tabstop=8 Modified: trunk/libirc/src/Makefile.am =================================================================== --- trunk/libirc/src/Makefile.am 2007-07-25 22:14:44 UTC (rev 208) +++ trunk/libirc/src/Makefile.am 2007-07-25 22:22:25 UTC (rev 209) @@ -4,7 +4,7 @@ libIRC_la_SOURCES = \ TCPConnection.cpp \ - TextUtils.cxx \ + IRCTextUtils.cxx \ ircCommands.cpp \ libIRC.cpp \ IRCClient.cpp \ Deleted: trunk/libirc/src/TextUtils.cxx =================================================================== --- trunk/libirc/src/TextUtils.cxx 2007-07-25 22:14:44 UTC (rev 208) +++ trunk/libirc/src/TextUtils.cxx 2007-07-25 22:22:25 UTC (rev 209) @@ -1,268 +0,0 @@ -/* bzflag - * Copyright (c) 1993 - 2004 Tim Riker - * - * This package is free software; you can redistribute it and/or - * modify it under the terms of the license found in the file - * named COPYING that should have accompanied this file. - * - * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED - * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. - */ - -// interface header -#include "IRCTextUtils.h" - -// system headers -#include <string> -#include <algorithm> -#include <sstream> -#include <stdarg.h> -#include <vector> - -namespace string_util -{ - std::string vformat(const char* fmt, va_list args) { - // FIXME -- should prevent buffer overflow in all cases - // not all platforms support vsnprintf so we'll use vsprintf and a - // big temporary buffer and hope for the best. - char buffer[8192]; - vsnprintf(buffer, 8192, fmt, args); - return std::string(buffer); - } - - - std::string format(const char* fmt, ...) { - va_list args; - va_start(args, fmt); - std::string result = vformat(fmt, args); - va_end(args); - return result; - } - - - std::string replace_all(const std::string& in, const std::string& replaceMe, const std::string& withMe) - { - std::string result; - std::string::size_type beginPos = 0; - std::string::size_type endPos = 0; - std::ostringstream tempStream; - - endPos = in.find(replaceMe); - if (endPos == std::string::npos) - return in; // can't find anything to replace - if (replaceMe.empty()) return in; // can't replace nothing with something -- can do reverse - - while (endPos != std::string::npos) { - // push the part up to - tempStream << in.substr(beginPos,endPos-beginPos); - tempStream << withMe; - beginPos = endPos + replaceMe.size(); - endPos = in.find(replaceMe,beginPos); - } - tempStream << in.substr(beginPos); - return tempStream.str(); - } - - - std::vector<std::string> tokenize(const std::string& in, const std::string &delims, const int maxTokens, const bool useQuotes){ - std::vector<std::string> tokens; - int numTokens = 0; - bool inQuote = false; - - std::ostringstream currentToken; - - std::string::size_type pos = in.find_first_not_of(delims); - int currentChar = (pos == std::string::npos) ? -1 : in[pos]; - bool enoughTokens = (maxTokens && (numTokens >= (maxTokens-1))); - - while (pos != std::string::npos && !enoughTokens) { - - // get next token - bool tokenDone = false; - bool foundSlash = false; - - currentChar = (pos < in.size()) ? in[pos] : -1; - while ((currentChar != -1) && !tokenDone){ - - tokenDone = false; - - if (delims.find(currentChar) != std::string::npos && !inQuote) { // currentChar is a delim - pos ++; - break; // breaks out of while look - } - - if (!useQuotes){ - currentToken << char(currentChar); - } else { - - switch (currentChar){ - case '\\' : // found a backslash - if (foundSlash){ - currentToken << char(currentChar); - foundSlash = false; - } else { - foundSlash = true; - } - break; - case '\"' : // found a quote - if (foundSlash){ // found \" - currentToken << char(currentChar); - foundSlash = false; - } else { // found unescaped " - if (inQuote){ // exiting a quote - // finish off current token - tokenDone = true; - inQuote = false; - //slurp off one additional delimeter if possible - if (pos+1 < in.size() && - delims.find(in[pos+1]) != std::string::npos) { - pos++; - } - - } else { // entering a quote - // finish off current token - tokenDone = true; - inQuote = true; - } - } - break; - default: - if (foundSlash){ // don't care about slashes except for above cases - currentToken << '\\'; - foundSlash = false; - } - currentToken << char(currentChar); - break; - } - } - - pos++; - currentChar = (pos < in.size()) ? in[pos] : -1; - } // end of getting a Token - - if (currentToken.str().size() > 0){ // if the token is something add to list - tokens.push_back(currentToken.str()); - currentToken.str(""); - numTokens ++; - } - - enoughTokens = (maxTokens && (numTokens >= (maxTokens-1))); - if (enoughTokens){ - break; - } else{ - pos = in.find_first_not_of(delims,pos); - } - - } // end of getting all tokens -- either EOL or max tokens reached - - if (enoughTokens && pos != std::string::npos) { - std::string lastToken = in.substr(pos); - if (lastToken.size() > 0) - tokens.push_back(lastToken); - } - - return tokens; - } - - int parseDuration(const std::string &duration) - { - int durationInt = 0; - int t = 0; - - int len = (int)duration.length(); - for(int i=0; i < len; i++) { - if (isdigit(duration[i])) { - t = t * 10 + (duration[i] - '0'); - } - else if(duration[i] == 'h' || duration[i] == 'H') { - durationInt += (t * 60); - t = 0; - } - else if(duration[i] == 'd' || duration[i] == 'D') { - durationInt += (t * 1440); - t = 0; - } - else if(duration[i] == 'w' || duration[i] == 'w') { - durationInt += (t * 10080); - t = 0; - } - } - durationInt += t; - return durationInt; - } - - std::string url_encode(const std::string &text) - { - char hex[5]; - std::string destination; - for (int i=0; i < (int) text.size(); i++) { - char c = text[i]; - if (isAlphanumeric(c)) { - destination+=c; - } else if (isWhitespace(c)) { - destination+='+'; - } else { - destination+='%'; - sprintf(hex, "%-2.2X", c); - destination.append(hex); - } - } - return destination; - } - - - std::string escape(const std::string &text, char escaper) - { - std::string destination; - for (int i = 0; i < (int) text.size(); i++) { - char c = text[i]; - if (!isAlphanumeric(c)) - destination += escaper; - destination += c; - } - return destination; - } - - std::string unescape(const std::string &text, char escaper) - { - const int len = (int) text.size(); - std::string destination; - for (int i = 0; i < len; i++) { - char c = text[i]; - if (c == escaper) { - if (i < len - 1) - destination += text[++i]; - else - // Should print an error - ; - } else { - destination += c; - } - } - return destination; - } - - int unescape_lookup(const std::string &text, char escaper, char sep) - { - int position = -1; - for (int i = 0; i < (int) text.size(); i++) { - char c = text[i]; - if (c == sep) { - position = i; - break; - } - if (c == escaper) - i++; - } - return position; - } -}; - -// Local Variables: *** -// mode: C++ *** -// tab-width: 8 *** -// c-basic-offset: 2 *** -// indent-tabs-mode: t *** -// End: *** -// ex: shiftwidth=2 tabstop=8 Modified: trunk/libirc/vc7.1/libirc.vcproj =================================================================== --- trunk/libirc/vc7.1/libirc.vcproj 2007-07-25 22:14:44 UTC (rev 208) +++ trunk/libirc/vc7.1/libirc.vcproj 2007-07-25 22:22:25 UTC (rev 209) @@ -149,7 +149,7 @@ Name="utils" Filter=""> <File - RelativePath="..\src\TextUtils.cxx"> + RelativePath="..\src\IRCTextUtils.cxx"> </File> </Filter> </Filter> Modified: trunk/libirc/vc8/libirc.vcproj =================================================================== --- trunk/libirc/vc8/libirc.vcproj 2007-07-25 22:14:44 UTC (rev 208) +++ trunk/libirc/vc8/libirc.vcproj 2007-07-25 22:22:25 UTC (rev 209) @@ -210,7 +210,7 @@ Name="utils" > <File - RelativePath="..\src\TextUtils.cxx" + RelativePath="..\src\IRCTextUtils.cxx" > </File> </Filter> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <br...@us...> - 2007-07-31 07:12:38
|
Revision: 216 http://libirc.svn.sourceforge.net/libirc/?rev=216&view=rev Author: brlcad Date: 2007-07-31 00:12:31 -0700 (Tue, 31 Jul 2007) Log Message: ----------- add a bunch of boilerplate m4 macros to simplify the configure logic a bit Added Paths: ----------- trunk/libirc/m4/ trunk/libirc/m4/args.m4 trunk/libirc/m4/cache.m4 trunk/libirc/m4/mkdirp.m4 trunk/libirc/m4/search.m4 trunk/libirc/m4/stage.m4 Added: trunk/libirc/m4/args.m4 =================================================================== --- trunk/libirc/m4/args.m4 (rev 0) +++ trunk/libirc/m4/args.m4 2007-07-31 07:12:31 UTC (rev 216) @@ -0,0 +1,239 @@ +# A R G S . M 4 +# BRL-CAD +# +# Copyright (c) 2005-2007 United States Government as represented by +# the U.S. Army Research Laboratory. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# +# 3. The name of the author may not be used to endorse or promote +# products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS +# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE +# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +### +# +# BC_ARG_ENABLE +# +# creates a configure --enable argument that simply sets a VARIABLE as +# to whether the feature is enabled or not. The arguments expected +# include the variable name, the --enable-FEATURE name, a help string, +# and a default value. provides bc_VARIABLE and bc_VARIABLE_default +# variables. +# +# +# BC_ARG_ALIAS +# +# creates an --enable alias. argument aliases do not show up in help, +# so the only expected arguments to the macro is the variable name, +# and the FEATURE alias name. +# +# +# BC_ARG_WITH +# +# creates a configure --with argument setting one FEATURE VARIABLE if +# the value was with or without (yes/no) and another FEATURE_val for +# the actual value. provides bc_VARIABLE and bc_VARIABLE_default +# variables. +# +# +# BC_ARG_WITH_ALIAS +# +# same as BC_ARG_ALIAS except that it sets the FEATURE_val VARIABLE +# too. BC_ARG_ALIAS will work as a simplified alternative if the +# FEATURE_val variable is not used (i.e. only a yes/no matters) +# +# +# BC_WITH_FLAG_ARGS +# +# provides convenience argument handlers for specifying CFLAGS, +# LDFLAGS, CPPFLAGS, and LIBS. more specifically, it adds +# --with-cflags, --with-cppflags, --with-ldflags, --with-libs. +# +### + +AC_DEFUN([BC_ARG_ENABLE], [ + +dnl XXX this was a failed attempt to get AC_ARG_ENABLE to grok an argument name +dnl ifelse([$1], [], [errprint([ERROR: missing first argument (the variable name) to BC_ARG_ENABLE])]) +dnl _bc_arg_name=ifelse([$2], [], [$1], [$2]) +dnl _bc_arg_help=ifelse([$4], [], +dnl [ifelse([$3], [], [enable $2], [$3])], +dnl [ifelse([$3], [], [enable $2 (default=$4)], [$3 (default=$4)] )] +dnl) + +# BC_ARG_ENABLE 1:[$1] 2:[$2] 3:[$3] 4:[$4] +bc_[$1]=[$4] +bc_[$1]_default=[$4] +bc_[$1]_set=no +AC_ARG_ENABLE([$2], AC_HELP_STRING([--enable-$2], [$3 (default=$4)]), + [ + bc_[$1]_set=yes + case "x$enableval" in + x[[yY]][[eE]][[sS]]) + bc_[$1]=yes + ;; + x[[nN]][[oO]]) + bc_[$1]=no + ;; + x) + bc_[$1]=yes + ;; + x*) + AC_MSG_NOTICE([*** WARNING *** WARNING *** WARNING *** WARNING *** WARNING ***]) + AC_MSG_NOTICE([Unexpected value of [$enableval] to --enable-[$2] (expecting yes/no)]) + bc_[$1]="$enableval" + ;; + esac + ] +) +]) + + +AC_DEFUN([BC_ARG_ALIAS], [ +# BC_ARG_ALIAS 1:[$1] 2:[$2] +AC_ARG_ENABLE([$2],, + [ + bc_[$1]_set=yes + case "x$enableval" in + x[[yY]][[eE]][[sS]]) + bc_[$1]=yes + ;; + x[[nN]][[oO]]) + bc_[$1]=no + ;; + x) + bc_[$1]=yes + ;; + x*) + bc_[$1]="$enableval" + ;; + esac + ] +) +]) + + +AC_DEFUN([BC_ARG_WITH], [ +# BC_ARG_WITH 1:[$1] 2:[$2] 3:[$3] 4:[$4] 5:[$5] +bc_[$1]=[$4] +bc_[$1]_val=[$5] +bc_[$1]_default=[$4] +bc_[$1]_set=no +AC_ARG_WITH([$2], AC_HELP_STRING([--with-$2], [$3]), + [ + bc_[$1]_set=yes + case "x$withval" in + x[[yY]][[eE]][[sS]]) + bc_[$1]=yes + bc_[$1]_val=yes + ;; + x[[nN]][[oO]]) + bc_[$1]=no + bc_[$1]_val=no + ;; + x) + bc_[$1]=yes + bc_[$1]_val="$withval" + ;; + x*) + bc_[$1]=yes + bc_[$1]_val="$withval" + ;; + esac + ] +) +]) + + +AC_DEFUN([BC_ARG_WITH_ALIAS], [ +# BC_ARG_WITH_ALIAS 1:[$1] 2:[$2] +AC_ARG_WITH([$2],, + [ + bc_[$1]_set=yes + case "x$withval" in + x[[yY]][[eE]][[sS]]) + bc_[$1]=yes + bc_[$1]_val=yes + ;; + x[[nN]][[oO]]) + bc_[$1]=no + bc_[$1]_val=no + ;; + x) + bc_[$1]=yes + bc_[$1]_val="$withval" + ;; + x*) + bc_[$1]=yes + bc_[$1]_val="$withval" + ;; + esac + ] +) +]) + + +AC_DEFUN([BC_WITH_FLAG_ARGS], [ +AC_ARG_WITH(cflags, AC_HELP_STRING(--with-cflags, + [Specify additional flags to pass to the C compiler]), + [ + if test "x$withval" != "xno" ; then + CFLAGS="$CFLAGS $withval" + fi + ] +) +AC_ARG_WITH(cppflags, AC_HELP_STRING(--with-cppflags, + [Specify additional flags to pass to C preprocessor]), + [ + if test "x$withval" != "xno"; then + CPPFLAGS="$CPPFLAGS $withval" + fi + ] +) +AC_ARG_WITH(ldflags, AC_HELP_STRING(--with-ldflags, + [Specify additional flags to pass to linker]), + [ + if test "x$withval" != "xno" ; then + LDFLAGS="$LDFLAGS $withval" + fi + ] +) +AC_ARG_WITH(libs, AC_HELP_STRING(--with-libs, + [Specify additional libraries to link against]), + [ + if test "x$withval" != "xno" ; then + LIBS="$LIBS $withval" + fi + ] +) +]) + +# Local Variables: +# mode: m4 +# tab-width: 8 +# standard-indent: 4 +# indent-tabs-mode: t +# End: +# ex: shiftwidth=4 tabstop=8 Added: trunk/libirc/m4/cache.m4 =================================================================== --- trunk/libirc/m4/cache.m4 (rev 0) +++ trunk/libirc/m4/cache.m4 2007-07-31 07:12:31 UTC (rev 216) @@ -0,0 +1,112 @@ +# C A C H E . M 4 +# BRL-CAD +# +# Copyright (c) 2005-2007 United States Government as represented by +# the U.S. Army Research Laboratory. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# +# 3. The name of the author may not be used to endorse or promote +# products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS +# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE +# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +### +# +# BC_CONFIG_CACHE +# +# automatically enable and load the configure cache file if available +# +### + +AC_DEFUN([BC_CONFIG_CACHE], [ +AC_MSG_CHECKING([whether a configure cache exists]) +if test "x$cache_file" = "x/dev/null" ; then + configure_cache=ifelse([$1], , [config.cache.${host_os}], [$1]) + CONFIG_CACHE="" + if test -f "$configure_cache"; then + if test "x`cat $configure_cache | grep ac_cv_env_CC_value`" != "xac_cv_env_CC_value=$CC" ; then + dnl if the compiler we're using now doesn't + dnl match the compiler used in the previous + dnl cached results, invalidate it. + AC_MSG_RESULT([found but compiler differs]) + rm -f "$configure_cache" + elif test "x`cat $configure_cache | grep ac_cv_env_CPPFLAGS_value`" != "xac_cv_env_CPPFLAGS_value=$CPPFLAGS" ; then + dnl if the preprocessor flags we're using now + dnl doesn't match the flags used in the + dnl previous cached results, invalidate it. + AC_MSG_RESULT([found but preprocessor flags differ]) + rm -f "$configure_cache" + else + dnl if the configure script has been modified + dnl since the last caching, assume it to be + dnl invalid. + last_modified="`ls -Lt $configure_cache configure`" + case "x$last_modified" in + xconfigure*) + AC_MSG_RESULT([found but out of date]) + rm -f $configure_cache + ;; + esac + fi + + dnl if the cache still exists, load it + if test -f "$configure_cache" ; then + dnl go ahead and load the cache + AC_MSG_RESULT([found $configure_cache]) + case $configure_cache in + [\\/]* | ?:[\\/]* ) + . $configure_cache + ;; + *) + . ./$configure_cache + ;; + esac + fi + else + AC_MSG_RESULT([not found]) + fi + + dnl if we are on sgi, bash may choke on bad sed syntax in the cache + if test "x$host_os" != "xirix6.5" ; then + AC_MSG_NOTICE([*** Automatically caching to $configure_cache ***]) + >$configure_cache + cache_file="$configure_cache" + CONFIG_CACHE="$cache_file" + else + AC_MSG_NOTICE([Automatic caching is unavailable on IRIX]) + fi + AC_SUBST(CONFIG_CACHE) +else + AC_MSG_RESULT($cache_file) +fi +]) + +# Local Variables: +# mode: m4 +# tab-width: 8 +# standard-indent: 4 +# indent-tabs-mode: t +# End: +# ex: shiftwidth=4 tabstop=8 Added: trunk/libirc/m4/mkdirp.m4 =================================================================== --- trunk/libirc/m4/mkdirp.m4 (rev 0) +++ trunk/libirc/m4/mkdirp.m4 2007-07-31 07:12:31 UTC (rev 216) @@ -0,0 +1,77 @@ +###################################################################### +# AM_PROG_MKDIR_P +# --------------- +# Check whether `mkdir -p' is supported, fallback to mkinstalldirs otherwise. + +# Copyright (C) 2003, 2004 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +# 02111-1307, USA. + +# Automake 1.8 used `mkdir -m 0755 -p --' to ensure that directories +# created by `make install' are always world readable, even if the +# installer happens to have an overly restrictive umask (e.g. 077). +# This was a mistake. There are at least two reasons why we must not +# use `-m 0755': +# - it causes special bits like SGID to be ignored, +# - it may be too restrictive (some setups expect 775 directories). +# +# Do not use -m 0755 and let people choose whatever they expect by +# setting umask. +# +# We cannot accept any implementation of `mkdir' that recognizes `-p'. +# Some implementations (such as Solaris 8's) are not thread-safe: if a +# parallel make tries to run `mkdir -p a/b' and `mkdir -p a/c' +# concurrently, both version can detect that a/ is missing, but only +# one can create it and the other will error out. Consequently we +# restrict ourselves to GNU make (using the --version option ensures +# this.) +AC_DEFUN([AM_PROG_MKDIR_P], +[if mkdir -p --version . >/dev/null 2>&1 && test ! -d ./--version; then + # We used to keeping the `.' as first argument, in order to + # allow $(mkdir_p) to be used without argument. As in + # $(mkdir_p) $(somedir) + # where $(somedir) is conditionally defined. However this is wrong + # for two reasons: + # 1. if the package is installed by a user who cannot write `.' + # make install will fail, + # 2. the above comment should most certainly read + # $(mkdir_p) $(DESTDIR)$(somedir) + # so it does not work when $(somedir) is undefined and + # $(DESTDIR) is not. + # To support the latter case, we have to write + # test -z "$(somedir)" || $(mkdir_p) $(DESTDIR)$(somedir), + # so the `.' trick is pointless. + mkdir_p='mkdir -p --' +else + # On NextStep and OpenStep, the `mkdir' command does not + # recognize any option. It will interpret all options as + # directories to create, and then abort because `.' already + # exists. + for d in ./-p ./--version; + do + test -d $d && rmdir $d + done + # $(mkinstalldirs) is defined by Automake if mkinstalldirs exists. + if test -f "$ac_aux_dir/mkinstalldirs"; then + mkdir_p='$(mkinstalldirs)' + else + mkdir_p='$(install_sh) -d' + fi +fi +AC_SUBST([mkdir_p]) +# automake 1.10+ seems to use uppercase instead +MKDIR_P="$mkdir_p" +AC_SUBST([MKDIR_P])]) Added: trunk/libirc/m4/search.m4 =================================================================== --- trunk/libirc/m4/search.m4 (rev 0) +++ trunk/libirc/m4/search.m4 2007-07-31 07:12:31 UTC (rev 216) @@ -0,0 +1,107 @@ +# S E A R C H . M 4 +# BRL-CAD +# +# Copyright (c) 2005-2007 United States Government as represented by +# the U.S. Army Research Laboratory. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# +# 3. The name of the author may not be used to endorse or promote +# products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS +# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE +# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +### +# +# BC_SEARCH_DIRECTORY +# +# designates a directory that should get searched for libraries, +# headers, and binaries. optional second argument is the directory +# group name. +# +### + +### +AC_DEFUN([BC_SEARCH_DIRECTORY], [ +search_dir="$1" +search_label="$2" +bc_dir_msg="" +if test "x$search_label" = "x" ; then + bc_dir_msg="for" +else + bc_dir_msg="for $search_label in" +fi + +AC_MSG_CHECKING([$bc_dir_msg $search_dir]) +if test -d "$search_dir" ; then + bc_found=0 + if test -d "${search_dir}/bin" ; then + if test "x$PATH" = "x" ; then + PATH="${search_dir}/bin" + else + PATH="${PATH}:${search_dir}/bin" + fi + bc_found=1 + fi + if test -d "${search_dir}/include" ; then + if test "x$CPPFLAGS" = "x" ; then + CPPFLAGS="-I${search_dir}/include" + else + CPPFLAGS="${CPPFLAGS} -I${search_dir}/include" + fi + bc_found=1 + fi + if test -d "${search_dir}/lib64" ; then + if test "x$LDFLAGS" = "x" ; then + LDFLAGS="-L${search_dir}/lib64" + else + LDFLAGS="${LDFLAGS} -L${search_dir}/lib64" + fi + bc_found=1 + fi + if test -d "${search_dir}/lib" ; then + if test "x$LDFLAGS" = "x" ; then + LDFLAGS="-L${search_dir}/lib" + else + LDFLAGS="${LDFLAGS} -L${search_dir}/lib" + fi + bc_found=1 + fi + if test "x$bc_found" = "x1" ; then + AC_MSG_RESULT([found]) + else + AC_MSG_RESULT([found, but empty]) + fi +else + AC_MSG_RESULT([not found]) +fi +]) + +# Local Variables: +# mode: m4 +# tab-width: 8 +# standard-indent: 4 +# indent-tabs-mode: t +# End: +# ex: shiftwidth=4 tabstop=8 Added: trunk/libirc/m4/stage.m4 =================================================================== --- trunk/libirc/m4/stage.m4 (rev 0) +++ trunk/libirc/m4/stage.m4 2007-07-31 07:12:31 UTC (rev 216) @@ -0,0 +1,91 @@ +# S T A G E . M 4 +# BRL-CAD +# +# Copyright (c) 2005-2007 United States Government as represented by +# the U.S. Army Research Laboratory. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# +# 3. The name of the author may not be used to endorse or promote +# products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS +# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE +# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +### +# +# BC_BOLD +# BC_UNBOLD +# +# sets and unsets the output to bold for emphasis +# +# +# BC_CONFIGURE_STAGE +# +# outputs status on the the specified configure stage being started. +# +### + +AC_DEFUN([BC_BOLD], [ +if test -t 1 ; then + if test -f "${srcdir}/sh/shtool" ; then + ${srcdir}/sh/shtool echo -n -e %B + elif test -f "${srcdir}/misc/shtool" ; then + ${srcdir}/misc/shtool echo -n -e %B + fi +fi +]) + + +AC_DEFUN([BC_UNBOLD], [ +if test -t 1 ; then + if test -f "${srcdir}/sh/shtool" ; then + ${srcdir}/sh/shtool echo -n -e %b + elif test -f "${srcdir}/misc/shtool" ; then + ${srcdir}/misc/shtool echo -n -e %b + fi +fi +]) + + +AC_DEFUN([BC_CONFIGURE_STAGE], [ + +_bc_stage="[$1]" +_bc_status="[$2]" +_bc_stage="`echo $_bc_stage | sed 's/\(.\)/\1 /g'`" + +BC_BOLD + +AC_MSG_CHECKING([... $_bc_stage]) +AC_MSG_RESULT([($_bc_status)]) + +BC_UNBOLD +]) + +# Local Variables: +# mode: m4 +# tab-width: 8 +# standard-indent: 4 +# indent-tabs-mode: t +# End: +# ex: shiftwidth=4 tabstop=8 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <br...@us...> - 2007-07-31 07:40:40
|
Revision: 221 http://libirc.svn.sourceforge.net/libirc/?rev=221&view=rev Author: brlcad Date: 2007-07-31 00:40:38 -0700 (Tue, 31 Jul 2007) Log Message: ----------- use BC_PATCH_LIBTOOL, add m4 to the build path Modified Paths: -------------- trunk/libirc/Makefile.am trunk/libirc/configure.ac Modified: trunk/libirc/Makefile.am =================================================================== --- trunk/libirc/Makefile.am 2007-07-31 07:37:16 UTC (rev 220) +++ trunk/libirc/Makefile.am 2007-07-31 07:40:38 UTC (rev 221) @@ -11,6 +11,7 @@ SUBDIRS = \ include \ + m4 \ misc \ src \ $(EXAMPLES) @@ -18,6 +19,7 @@ DIST_SUBDIRS = \ examples \ include \ + m4 \ misc \ src \ vc7.1 \ Modified: trunk/libirc/configure.ac =================================================================== --- trunk/libirc/configure.ac 2007-07-31 07:37:16 UTC (rev 220) +++ trunk/libirc/configure.ac 2007-07-31 07:40:38 UTC (rev 221) @@ -612,45 +612,16 @@ examples/stupidBot/Makefile examples/stupidBot/src/Makefile include/Makefile + m4/Makefile misc/Makefile src/Makefile ]) AC_OUTPUT +# patch libtool if it has the -all_load bug +BC_PATCH_LIBTOOL -################# -# patch libtool # -################# -case $host_os in - darwin*) - for script in $ac_top_builddir $ac_abs_builddir $ac_builddir . ; do - if test "x$script" = "x" ; then - libtoolscript="libtool" - else - libtoolscript="${script}/libtool" - fi - if test -f ${libtoolscript} ; then - if test -w ${libtoolscript} ; then - # remove any -all_load option. - # provokes libtool linker bug with noinst libraries. - sed 's/-all_load.*convenience//g' < $libtoolscript > ${libtoolscript}.sed - sed "s/temp_rpath=\$/temp_rpath=$TCL_PATH:$TK_PATH/g" < $libtoolscript.sed > ${libtoolscript}.sed2 - if test ! "x`cat ${libtoolscript}`" = "x`cat ${libtoolscript}.sed2`" ; then - AC_MSG_RESULT([Found -all_load in libtool script, removing]) - cp ${libtoolscript}.sed2 ${libtoolscript} - fi - rm -f ${libtoolscript}.sed - rm -f ${libtoolscript}.sed2 - else - AC_MSG_WARN([libtool script exists but is not writable so not attempting to edit]) - fi - fi - done - ;; -esac - - dnl dnl Expand the variables for summary reporting dnl This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <br...@us...> - 2007-07-31 07:49:19
|
Revision: 222 http://libirc.svn.sourceforge.net/libirc/?rev=222&view=rev Author: brlcad Date: 2007-07-31 00:49:17 -0700 (Tue, 31 Jul 2007) Log Message: ----------- import BC_SANITY_CHECK Modified Paths: -------------- trunk/libirc/configure.ac trunk/libirc/m4/Makefile.am Added Paths: ----------- trunk/libirc/m4/compiler.m4 Modified: trunk/libirc/configure.ac =================================================================== --- trunk/libirc/configure.ac 2007-07-31 07:40:38 UTC (rev 221) +++ trunk/libirc/configure.ac 2007-07-31 07:49:17 UTC (rev 222) @@ -554,18 +554,7 @@ AM_C_PROTOTYPES dnl Last step is to make sure that we can actually compile -AC_MSG_CHECKING(compiler and flags for sanity) -AC_TRY_RUN([ -#include <stdio.h> -int main(){exit(0);} - ], - [ AC_MSG_RESULT(yes) ], - [ - AC_MSG_RESULT(no) - AC_MSG_NOTICE([>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>]) - AC_MSG_ERROR([*** compiler cannot create working executables, check config.log ***]) - ] -) +BC_SANITY_CHECK dnl *************************** Modified: trunk/libirc/m4/Makefile.am =================================================================== --- trunk/libirc/m4/Makefile.am 2007-07-31 07:40:38 UTC (rev 221) +++ trunk/libirc/m4/Makefile.am 2007-07-31 07:49:17 UTC (rev 222) @@ -3,6 +3,7 @@ brlcad_m4 = \ args.m4 \ cache.m4 \ + compiler.m4 \ patch.m4 \ search.m4 \ stage.m4 Added: trunk/libirc/m4/compiler.m4 =================================================================== --- trunk/libirc/m4/compiler.m4 (rev 0) +++ trunk/libirc/m4/compiler.m4 2007-07-31 07:49:17 UTC (rev 222) @@ -0,0 +1,178 @@ +# C O M P I L E R . M 4 +# BRL-CAD +# +# Copyright (c) 2005-2007 United States Government as represented by +# the U.S. Army Research Laboratory. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# +# 3. The name of the author may not be used to endorse or promote +# products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS +# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE +# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +### +# +# BC_COMPILER_AND_LINKER_RECOGNIZES +# checks if the compiler will work with the specified flags +# +# BC_COMPILER_RECOGNIZES +# checks if the compiler will work with the specified cflags +# +# BC_LINKER_RECOGNIZES +# checks if the linker will work with the specified ldflags +# +# BC_PREPROCESSOR_RECOGNIZES +# checks if the preprocessor will work with the specified cppflags +# +# BC_SANITY_CHECK +# make sure the compiler actually builds executables that run +# +### + +AC_DEFUN([BC_COMPILER_AND_LINKER_RECOGNIZES], [ +__flag="$1" +bc_[$2]_works=yes +__keep="$3" +AC_MSG_CHECKING([if compiler and linker recognize $__flag]) +PRECFLAGS="$CFLAGS" +PRECXXFLAGS="$CXXFLAGS" +PRELDFLAGS="$LDFLAGS" +CFLAGS="$CFLAGS $__flag" +CXXFLAGS="$CXXFLAGS $__flag" +LDFLAGS="$LDFLAGS $__flag" +m4_pushdef([AC_TRY_EVAL], [_AC_EVAL_STDERR]($$[1])) +AC_TRY_COMPILE( [], [int i;], [if AC_TRY_COMMAND([grep "nrecognize" conftest.err >/dev/null 2>&1]) ; then bc_[$2]_works=no ; fi], [bc_[$2]_works=no]) +m4_popdef([AC_TRY_EVAL]) +rm -f conftest.err +AC_TRY_RUN( [ +#include <stdio.h> +int main(){exit(0);} +], [], [bc_[$2]_works=no]) +AC_MSG_RESULT($bc_[$2]_works) +if test "x$bc_[$2]_works" = "xno" -o "x$__keep" != "x" ; then + CFLAGS="$PRECFLAGS" + CXXFLAGS="$PRECXXFLAGS" + LDFLAGS="$PRELDFLAGS" +fi +]) + +AC_DEFUN([BC_COMPILER_AND_LINKER_RECOGNIZE], [ +BC_COMPILER_AND_LINKER_RECOGNIZES([$1], [$2], [$3]) +]) + + +AC_DEFUN([BC_COMPILER_RECOGNIZES], [ +__flag="$1" +AC_MSG_CHECKING([if compiler recognizes $__flag]) +bc_[$2]_works=yes +__keep="$3" +PRECFLAGS="$CFLAGS" +PRECXXFLAGS="$CXXFLAGS" +CFLAGS="$CFLAGS $__flag" +CXXFLAGS="$CXXFLAGS $__flag" +m4_pushdef([AC_TRY_EVAL], [_AC_EVAL_STDERR]($$[1])) +AC_TRY_COMPILE( [], [int i;], [if AC_TRY_COMMAND([grep "nrecognize" conftest.err >/dev/null 2>&1]) ; then bc_[$2]_works=no ; fi], [bc_[$2]_works=no]) +m4_popdef([AC_TRY_EVAL]) +rm -f conftest.err +AC_MSG_RESULT($bc_[$2]_works) +if test "x$bc_[$2]_works" = "xno" -o "x$__keep" != "x" ; then + CFLAGS="$PRECFLAGS" + CXXFLAGS="$PRECXXFLAGS" +fi +]) + +AC_DEFUN([BC_COMPILER_RECOGNIZE], [ +BC_COMPILER_RECOGNIZES([$1], [$2], [$3]) +]) + + +AC_DEFUN([BC_LINKER_RECOGNIZES], [ +__flag="$1" +AC_MSG_CHECKING([if linker recognizes $__flag]) +bc_[$2]_works=yes +__keep="$3" +PRELDFLAGS="$LDFLAGS" +LDFLAGS="$LDFLAGS $__flag" +m4_pushdef([AC_TRY_EVAL], [_AC_EVAL_STDERR]($$[1])) +AC_TRY_LINK( [], [int i;], [if AC_TRY_COMMAND([grep "nrecognize" conftest.err >/dev/null 2>&1]) ; then bc_[$2]_works=no ; fi], [bc_[$2]_works=no]) +m4_popdef([AC_TRY_EVAL]) +rm -f conftest.err +AC_MSG_RESULT($bc_[$2]_works) +if test "x$bc_[$2]_works" = "xno" -o "x$__keep" != "x" ; then + LDFLAGS="$PRELDFLAGS" +fi +]) + +AC_DEFUN([BC_LINKER_RECOGNIZE], [ +BC_LINKER_RECOGNIZES([$1], [$2], [$3]) +]) + + +AC_DEFUN([BC_PREPROCESSOR_RECOGNIZES], [ +__flag="$1" +AC_MSG_CHECKING([if preprocesser recognizes $__flag]) +bc_[$2]_works=yes +__keep="$3" +PRECPPFLAGS="$CPPFLAGS" +PRECXXCPPFLAGS="$CXXCPPFLAGS" +CPPFLAGS="$CPPFLAGS $__flag" +CXXCPPFLAGS="$CXXCPPFLAGS $__flag" +m4_pushdef([AC_TRY_EVAL], [_AC_EVAL_STDERR]($$[1])) +AC_TRY_COMPILE( [], [int i;], [if AC_TRY_COMMAND([grep "nrecognize" conftest.err >/dev/null 2>&1]) ; then bc_[$2]_works=no ; fi], [bc_[$2]_works=no]) +m4_popdef([AC_TRY_EVAL]) +rm -f conftest.err +AC_MSG_RESULT($bc_[$2]_works) +if test "x$bc_[$2]_works" = "xno" -o "x$__keep" = "x" ; then + CPPFLAGS="$PRECPPFLAGS" + CXXCPPFLAGS="$PRECXXCPPFLAGS" +fi +]) + +AC_DEFUN([BC_PREPROCESSOR_RECOGNIZE], [ +BC_PREPROCESSOR_RECOGNIZES([$1], [$2], [$3]) +]) + +AC_DEFUN([BC_SANITY_CHECK], [ +AC_MSG_CHECKING(compiler and flags for sanity) +AC_TRY_RUN([ +#include <stdio.h> +int main(){exit(0);} + ], + [ AC_MSG_RESULT(yes) ], + [ + AC_MSG_RESULT(no) + AC_MSG_NOTICE([}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}]) + AC_MSG_ERROR([*** compiler cannot create working executables, check config.log ***]) + ] +) +]) + +# Local Variables: +# mode: m4 +# tab-width: 8 +# standard-indent: 4 +# indent-tabs-mode: t +# End: +# ex: shiftwidth=4 tabstop=8 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <br...@us...> - 2007-07-31 08:17:11
|
Revision: 227 http://libirc.svn.sourceforge.net/libirc/?rev=227&view=rev Author: brlcad Date: 2007-07-31 01:17:09 -0700 (Tue, 31 Jul 2007) Log Message: ----------- propagate Makefile.defs throughout so that the recursive noprod rule works Modified Paths: -------------- trunk/libirc/Makefile.am trunk/libirc/configure.ac trunk/libirc/examples/Makefile.am trunk/libirc/examples/simpleIRCConnect/Makefile.am trunk/libirc/examples/simpleIRCConnect/src/Makefile.am trunk/libirc/examples/simpleTCPConnect/Makefile.am trunk/libirc/examples/simpleTCPConnect/src/Makefile.am trunk/libirc/examples/spamBot/Makefile.am trunk/libirc/examples/spamBot/src/Makefile.am trunk/libirc/examples/stupidBot/Makefile.am trunk/libirc/examples/stupidBot/src/Makefile.am trunk/libirc/examples/stupidServer/Makefile.am trunk/libirc/include/Makefile.am trunk/libirc/src/Makefile.am Modified: trunk/libirc/Makefile.am =================================================================== --- trunk/libirc/Makefile.am 2007-07-31 08:16:32 UTC (rev 226) +++ trunk/libirc/Makefile.am 2007-07-31 08:17:09 UTC (rev 227) @@ -39,16 +39,6 @@ configure.ac \ libtool -MAINTAINERCLEANFILES = \ - @CONFIG_CACHE@ \ - Makefile.in \ - aclocal.m4 \ - autom4te.cache \ - config.log \ - config.status \ - configure \ - libtool - examples: all-am cd examples && $(MAKE) $(AM_MAKEFLAGS) @@ -109,3 +99,15 @@ @ECHO@ "Run 'make test' to test the libIRC framework" ;\ fi @@ECHO@ + +MAINTAINERCLEANFILES = \ + @CONFIG_CACHE@ \ + Makefile.in \ + aclocal.m4 \ + autom4te.cache \ + config.log \ + config.status \ + configure \ + libtool + +include $(top_srcdir)/misc/Makefile.defs Modified: trunk/libirc/configure.ac =================================================================== --- trunk/libirc/configure.ac 2007-07-31 08:16:32 UTC (rev 226) +++ trunk/libirc/configure.ac 2007-07-31 08:17:09 UTC (rev 227) @@ -567,8 +567,12 @@ examples/simpleIRCConnect/src/Makefile examples/simpleTCPConnect/Makefile examples/simpleTCPConnect/src/Makefile + examples/spamBot/Makefile + examples/spamBot/src/Makefile examples/stupidBot/Makefile examples/stupidBot/src/Makefile + examples/stupidServer/Makefile + examples/stupidServer/src/Makefile include/Makefile m4/Makefile misc/Makefile Modified: trunk/libirc/examples/Makefile.am =================================================================== --- trunk/libirc/examples/Makefile.am 2007-07-31 08:16:32 UTC (rev 226) +++ trunk/libirc/examples/Makefile.am 2007-07-31 08:17:09 UTC (rev 227) @@ -3,7 +3,10 @@ SUBDIRS = \ simpleIRCConnect \ simpleTCPConnect \ - stupidBot \ + spamBot \ + stupidBot \ stupidServer MAINTAINERCLEANFILES = Makefile.in + +include $(top_srcdir)/misc/Makefile.defs Modified: trunk/libirc/examples/simpleIRCConnect/Makefile.am =================================================================== --- trunk/libirc/examples/simpleIRCConnect/Makefile.am 2007-07-31 08:16:32 UTC (rev 226) +++ trunk/libirc/examples/simpleIRCConnect/Makefile.am 2007-07-31 08:17:09 UTC (rev 227) @@ -11,3 +11,5 @@ EXTRA_DIST = readme.txt MAINTAINERCLEANFILES = Makefile.in + +include $(top_srcdir)/misc/Makefile.defs Modified: trunk/libirc/examples/simpleIRCConnect/src/Makefile.am =================================================================== --- trunk/libirc/examples/simpleIRCConnect/src/Makefile.am 2007-07-31 08:16:32 UTC (rev 226) +++ trunk/libirc/examples/simpleIRCConnect/src/Makefile.am 2007-07-31 08:17:09 UTC (rev 227) @@ -6,3 +6,5 @@ simpleIRCConnect_LDADD = $(top_builddir)/src/libIRC.la MAINTAINERCLEANFILES = Makefile.in + +include $(top_srcdir)/misc/Makefile.defs Modified: trunk/libirc/examples/simpleTCPConnect/Makefile.am =================================================================== --- trunk/libirc/examples/simpleTCPConnect/Makefile.am 2007-07-31 08:16:32 UTC (rev 226) +++ trunk/libirc/examples/simpleTCPConnect/Makefile.am 2007-07-31 08:17:09 UTC (rev 227) @@ -11,3 +11,5 @@ EXTRA_DIST = readme.txt MAINTAINERCLEANFILES = Makefile.in + +include $(top_srcdir)/misc/Makefile.defs Modified: trunk/libirc/examples/simpleTCPConnect/src/Makefile.am =================================================================== --- trunk/libirc/examples/simpleTCPConnect/src/Makefile.am 2007-07-31 08:16:32 UTC (rev 226) +++ trunk/libirc/examples/simpleTCPConnect/src/Makefile.am 2007-07-31 08:17:09 UTC (rev 227) @@ -6,3 +6,5 @@ simpleTCPConnect_LDADD = $(top_builddir)/src/libIRC.la MAINTAINERCLEANFILES = Makefile.in + +include $(top_srcdir)/misc/Makefile.defs Modified: trunk/libirc/examples/spamBot/Makefile.am =================================================================== --- trunk/libirc/examples/spamBot/Makefile.am 2007-07-31 08:16:32 UTC (rev 226) +++ trunk/libirc/examples/spamBot/Makefile.am 2007-07-31 08:17:09 UTC (rev 227) @@ -13,3 +13,5 @@ sample.cfg MAINTAINERCLEANFILES = Makefile.in + +include $(top_srcdir)/misc/Makefile.defs Modified: trunk/libirc/examples/spamBot/src/Makefile.am =================================================================== --- trunk/libirc/examples/spamBot/src/Makefile.am 2007-07-31 08:16:32 UTC (rev 226) +++ trunk/libirc/examples/spamBot/src/Makefile.am 2007-07-31 08:17:09 UTC (rev 227) @@ -6,3 +6,5 @@ spamBot_LDADD = $(top_builddir)/src/libIRC.la MAINTAINERCLEANFILES = Makefile.in + +include $(top_srcdir)/misc/Makefile.defs Modified: trunk/libirc/examples/stupidBot/Makefile.am =================================================================== --- trunk/libirc/examples/stupidBot/Makefile.am 2007-07-31 08:16:32 UTC (rev 226) +++ trunk/libirc/examples/stupidBot/Makefile.am 2007-07-31 08:17:09 UTC (rev 227) @@ -13,3 +13,5 @@ sample.cfg MAINTAINERCLEANFILES = Makefile.in + +include $(top_srcdir)/misc/Makefile.defs Modified: trunk/libirc/examples/stupidBot/src/Makefile.am =================================================================== --- trunk/libirc/examples/stupidBot/src/Makefile.am 2007-07-31 08:16:32 UTC (rev 226) +++ trunk/libirc/examples/stupidBot/src/Makefile.am 2007-07-31 08:17:09 UTC (rev 227) @@ -6,3 +6,5 @@ stupidBot_LDADD = $(top_builddir)/src/libIRC.la MAINTAINERCLEANFILES = Makefile.in + +include $(top_srcdir)/misc/Makefile.defs Modified: trunk/libirc/examples/stupidServer/Makefile.am =================================================================== --- trunk/libirc/examples/stupidServer/Makefile.am 2007-07-31 08:16:32 UTC (rev 226) +++ trunk/libirc/examples/stupidServer/Makefile.am 2007-07-31 08:17:09 UTC (rev 227) @@ -13,3 +13,5 @@ sample.cfg MAINTAINERCLEANFILES = Makefile.in + +include $(top_srcdir)/misc/Makefile.defs Modified: trunk/libirc/include/Makefile.am =================================================================== --- trunk/libirc/include/Makefile.am 2007-07-31 08:16:32 UTC (rev 226) +++ trunk/libirc/include/Makefile.am 2007-07-31 08:17:09 UTC (rev 227) @@ -24,3 +24,5 @@ # make sure that the build date/version is updated every time make is run all-local: @sh $(top_srcdir)/misc/vers.sh libirc_version "libIRC" > libirc_version.h + +include $(top_srcdir)/misc/Makefile.defs Modified: trunk/libirc/src/Makefile.am =================================================================== --- trunk/libirc/src/Makefile.am 2007-07-31 08:16:32 UTC (rev 226) +++ trunk/libirc/src/Makefile.am 2007-07-31 08:17:09 UTC (rev 227) @@ -14,3 +14,5 @@ ircBasicCommands.cpp MAINTAINERCLEANFILES = Makefile.in + +include $(top_srcdir)/misc/Makefile.defs This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <br...@us...> - 2007-07-31 08:37:52
|
Revision: 232 http://libirc.svn.sourceforge.net/libirc/?rev=232&view=rev Author: brlcad Date: 2007-07-31 01:37:50 -0700 (Tue, 31 Jul 2007) Log Message: ----------- s/loger/logger/, and fix scope on the default loggers so they don't run into each other in the library. libIRC is now compilation-functional again. Modified Paths: -------------- trunk/libirc/include/IRCClient.h trunk/libirc/include/IRCServer.h trunk/libirc/src/IRCClient.cpp trunk/libirc/src/IRCServer.cpp Modified: trunk/libirc/include/IRCClient.h =================================================================== --- trunk/libirc/include/IRCClient.h 2007-07-31 08:33:52 UTC (rev 231) +++ trunk/libirc/include/IRCClient.h 2007-07-31 08:37:50 UTC (rev 232) @@ -66,7 +66,7 @@ virtual ~IRCClient(); // logging - void setLogHandler ( IRCClientLogHandler * loger ); + void setLogHandler ( IRCClientLogHandler * logger ); virtual void setLogfile ( std::string file ); virtual std::string getLogfile ( void ); @@ -275,4 +275,4 @@ float minCycleTime; }; -#endif //_IRC_CLIENT_H_ \ No newline at end of file +#endif //_IRC_CLIENT_H_ Modified: trunk/libirc/include/IRCServer.h =================================================================== --- trunk/libirc/include/IRCServer.h 2007-07-31 08:33:52 UTC (rev 231) +++ trunk/libirc/include/IRCServer.h 2007-07-31 08:37:50 UTC (rev 232) @@ -66,7 +66,7 @@ virtual ~IRCServer(); // loging - void setLogHandler ( IRCServerLogHandler * loger ); + void setLogHandler ( IRCServerLogHandler * logger ); virtual void setLogfile ( std::string file ); virtual std::string getLogfile ( void ); @@ -128,4 +128,4 @@ std::vector<IRCServerConnectedClient>::iterator getClientItr ( IRCServerConnectedClient *client ); }; -#endif //_IRC_SERVER_H_ \ No newline at end of file +#endif //_IRC_SERVER_H_ Modified: trunk/libirc/src/IRCClient.cpp =================================================================== --- trunk/libirc/src/IRCClient.cpp 2007-07-31 08:33:52 UTC (rev 231) +++ trunk/libirc/src/IRCClient.cpp 2007-07-31 08:37:50 UTC (rev 232) @@ -47,7 +47,7 @@ } }; -DefaultIRCLogHandler defaultLoger; +static DefaultIRCLogHandler defaultLogger; // IRC class stuff @@ -63,7 +63,7 @@ debugLogLevel = 0; ircServerPort = _DEFAULT_IRC_PORT; ircConnectionState = eNotConnected; - logHandler = &defaultLoger; + logHandler = &defaultLogger; } // irc client @@ -275,12 +275,12 @@ return true; } -void IRCClient::setLogHandler ( IRCClientLogHandler * loger ) +void IRCClient::setLogHandler ( IRCClientLogHandler * logger ) { - if (!loger) - logHandler = &defaultLoger; + if (!logger) + logHandler = &defaultLogger; else - logHandler = loger; + logHandler = logger; } void IRCClient::log ( const char *text, int level ) Modified: trunk/libirc/src/IRCServer.cpp =================================================================== --- trunk/libirc/src/IRCServer.cpp 2007-07-31 08:33:52 UTC (rev 231) +++ trunk/libirc/src/IRCServer.cpp 2007-07-31 08:37:50 UTC (rev 232) @@ -47,7 +47,7 @@ } }; -DefaultServerIRCLogHandler defaultLoger; +static DefaultServerIRCLogHandler defaultLogger; IRCServerConnectedClient::IRCServerConnectedClient ( IRCServer *_server, TCPServerConnectedPeer* _peer ) @@ -91,7 +91,7 @@ tcpServer = NULL; debugLogLevel = 0; - logHandler = &defaultLoger; + logHandler = &defaultLogger; ircMessageTerminator = "\r\n"; ircCommandDelimator = " "; @@ -115,12 +115,12 @@ return clients.end(); } -void IRCServer::setLogHandler ( IRCServerLogHandler * loger ) +void IRCServer::setLogHandler ( IRCServerLogHandler * logger ) { - if (!loger) - logHandler = &defaultLoger; + if (!logger) + logHandler = &defaultLogger; else - logHandler = loger; + logHandler = logger; } void IRCServer::setLogfile ( std::string file ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <br...@us...> - 2007-07-31 09:07:23
|
Revision: 234 http://libirc.svn.sourceforge.net/libirc/?rev=234&view=rev Author: brlcad Date: 2007-07-31 02:07:21 -0700 (Tue, 31 Jul 2007) Log Message: ----------- ... and now libIRC even successfully passes a make distcheck again ... ship it! Modified Paths: -------------- trunk/libirc/Makefile.am trunk/libirc/examples/simpleIRCConnect/Makefile.am trunk/libirc/examples/simpleTCPConnect/Makefile.am trunk/libirc/examples/spamBot/Makefile.am trunk/libirc/examples/stupidBot/Makefile.am trunk/libirc/examples/stupidServer/Makefile.am trunk/libirc/include/Makefile.am trunk/libirc/m4/Makefile.am Modified: trunk/libirc/Makefile.am =================================================================== --- trunk/libirc/Makefile.am 2007-07-31 08:42:03 UTC (rev 233) +++ trunk/libirc/Makefile.am 2007-07-31 09:07:21 UTC (rev 234) @@ -21,9 +21,7 @@ include \ m4 \ misc \ - src \ - vc7.1 \ - vc8 + src EXTRA_DIST = \ AUTHORS \ @@ -33,11 +31,13 @@ HACKING \ INSTALL \ NEWS \ - ReadMe.txt \ + README \ TODO \ autogen.sh \ configure.ac \ - libtool + libtool \ + vc7.1 \ + vc8 examples: all-am cd examples && $(MAKE) $(AM_MAKEFLAGS) @@ -56,7 +56,6 @@ @@ECHO@ @@ECHO@ "libIRC @LIBIRC_VERSION@, Build @CONFIG_DATE@" @@ECHO@ - @@ECHO@ "$(MAKECMDGOALS) is goals" @if test "x$(MAKECMDGOALS)" = "xall-am" ; then \ @ECHO@ @ECHO_N@ "Elapsed compilation time: " ;\ sh $(top_srcdir)/misc/elapsed.sh `cat $(top_builddir)/include/libirc_version.h | grep Compilation` ;\ @@ -100,14 +99,16 @@ fi @@ECHO@ -MAINTAINERCLEANFILES = \ - @CONFIG_CACHE@ \ - Makefile.in \ +DISTCLEANFILES = \ + $(CONFIG_CACHE) \ aclocal.m4 \ - autom4te.cache \ config.log \ config.status \ configure \ - libtool + install.$(host_triplet).log \ + libtool \ + so_locations +MAINTAINERCLEANFILES = Makefile.in + include $(top_srcdir)/misc/Makefile.defs Modified: trunk/libirc/examples/simpleIRCConnect/Makefile.am =================================================================== --- trunk/libirc/examples/simpleIRCConnect/Makefile.am 2007-07-31 08:42:03 UTC (rev 233) +++ trunk/libirc/examples/simpleIRCConnect/Makefile.am 2007-07-31 09:07:21 UTC (rev 234) @@ -1,15 +1,12 @@ # $Id$ -SUBDIRS = \ - src +SUBDIRS = src -DIST_SUBDIRS = \ - src \ +EXTRA_DIST = \ + readme.txt \ vc7.1 \ vc8 -EXTRA_DIST = readme.txt - MAINTAINERCLEANFILES = Makefile.in include $(top_srcdir)/misc/Makefile.defs Modified: trunk/libirc/examples/simpleTCPConnect/Makefile.am =================================================================== --- trunk/libirc/examples/simpleTCPConnect/Makefile.am 2007-07-31 08:42:03 UTC (rev 233) +++ trunk/libirc/examples/simpleTCPConnect/Makefile.am 2007-07-31 09:07:21 UTC (rev 234) @@ -1,15 +1,12 @@ # $Id$ -SUBDIRS = \ - src +SUBDIRS = src -DIST_SUBDIRS = \ - src \ +EXTRA_DIST = \ + readme.txt \ vc7.1 \ vc8 -EXTRA_DIST = readme.txt - MAINTAINERCLEANFILES = Makefile.in include $(top_srcdir)/misc/Makefile.defs Modified: trunk/libirc/examples/spamBot/Makefile.am =================================================================== --- trunk/libirc/examples/spamBot/Makefile.am 2007-07-31 08:42:03 UTC (rev 233) +++ trunk/libirc/examples/spamBot/Makefile.am 2007-07-31 09:07:21 UTC (rev 234) @@ -1,17 +1,13 @@ # $Id$ -SUBDIRS = \ - src +SUBDIRS = src -DIST_SUBDIRS = \ - src \ +EXTRA_DIST = \ + readme.txt \ + sample.cfg \ vc7.1 \ vc8 -EXTRA_DIST = \ - readme.txt \ - sample.cfg - MAINTAINERCLEANFILES = Makefile.in include $(top_srcdir)/misc/Makefile.defs Modified: trunk/libirc/examples/stupidBot/Makefile.am =================================================================== --- trunk/libirc/examples/stupidBot/Makefile.am 2007-07-31 08:42:03 UTC (rev 233) +++ trunk/libirc/examples/stupidBot/Makefile.am 2007-07-31 09:07:21 UTC (rev 234) @@ -1,17 +1,13 @@ # $Id$ -SUBDIRS = \ - src +SUBDIRS = src -DIST_SUBDIRS = \ - src \ +EXTRA_DIST = \ + readme.txt \ + sample.cfg \ vc7.1 \ vc8 -EXTRA_DIST = \ - readme.txt \ - sample.cfg - MAINTAINERCLEANFILES = Makefile.in include $(top_srcdir)/misc/Makefile.defs Modified: trunk/libirc/examples/stupidServer/Makefile.am =================================================================== --- trunk/libirc/examples/stupidServer/Makefile.am 2007-07-31 08:42:03 UTC (rev 233) +++ trunk/libirc/examples/stupidServer/Makefile.am 2007-07-31 09:07:21 UTC (rev 234) @@ -1,17 +1,13 @@ # $Id$ -SUBDIRS = \ - src +SUBDIRS = src -DIST_SUBDIRS = \ - src \ +EXTRA_DIST = \ + readme.txt \ + sample.cfg \ vc7.1 \ vc8 -EXTRA_DIST = \ - readme.txt \ - sample.cfg - MAINTAINERCLEANFILES = Makefile.in include $(top_srcdir)/misc/Makefile.defs Modified: trunk/libirc/include/Makefile.am =================================================================== --- trunk/libirc/include/Makefile.am 2007-07-31 08:42:03 UTC (rev 233) +++ trunk/libirc/include/Makefile.am 2007-07-31 09:07:21 UTC (rev 234) @@ -1,21 +1,33 @@ # $Id$ include_HEADERS = \ - TCPConnection.h \ + IRCClient.h \ + IRCEvents.h \ + IRCNumerics.h \ + IRCServer.h \ IRCTextUtils.h \ + IRCUserManager.h \ Singleton.h \ - IRCNumerics.h \ - IRCEvents.h \ + TCPConnection.h \ ircCommands.h \ - libIRC.h + libIRC.h \ + net.h noinst_HEADERS = \ + config.h \ libirc_version.h EXTRA_DIST = \ config.h.in \ version +BUILT_SOURCES = \ + libirc_version.h \ + version + +DISTCLEANFILES = \ + $(BUILT_SOURCES) + MAINTAINERCLEANFILES = Makefile.in libirc_version.h: Modified: trunk/libirc/m4/Makefile.am =================================================================== --- trunk/libirc/m4/Makefile.am 2007-07-31 08:42:03 UTC (rev 233) +++ trunk/libirc/m4/Makefile.am 2007-07-31 09:07:21 UTC (rev 234) @@ -10,9 +10,7 @@ EXTRA_DIST = \ $(brlcad_m4) \ - mkdirp.m4 \ - python.m4 \ - sdl.m4 + mkdirp.m4 MAINTAINERCLEANFILES = Makefile.in This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <l4m...@us...> - 2007-08-12 06:20:16
|
Revision: 235 http://libirc.svn.sourceforge.net/libirc/?rev=235&view=rev Author: l4m3rthanyou Date: 2007-08-11 23:20:10 -0700 (Sat, 11 Aug 2007) Log Message: ----------- eUnknown -> eUnknownCommand. eUnknown clashes with cURL. Modified Paths: -------------- trunk/libirc/include/libIRC.h trunk/libirc/src/libIRC.cpp Modified: trunk/libirc/include/libIRC.h =================================================================== --- trunk/libirc/include/libIRC.h 2007-07-31 09:07:21 UTC (rev 234) +++ trunk/libirc/include/libIRC.h 2007-08-12 06:20:10 UTC (rev 235) @@ -47,7 +47,7 @@ // the types of command info structures typedef enum { - eUnknown = 0, + eUnknownCommand = 0, eIRCCommand, eCTCPCommand, eDDECommand Modified: trunk/libirc/src/libIRC.cpp =================================================================== --- trunk/libirc/src/libIRC.cpp 2007-07-31 09:07:21 UTC (rev 234) +++ trunk/libirc/src/libIRC.cpp 2007-08-12 06:20:10 UTC (rev 235) @@ -78,7 +78,7 @@ BaseIRCCommandInfo::BaseIRCCommandInfo() { - type = eUnknown; + type = eUnknownCommand; command = "NULL"; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mm...@us...> - 2007-10-05 10:12:58
|
Revision: 239 http://libirc.svn.sourceforge.net/libirc/?rev=239&view=rev Author: mm_202 Date: 2007-10-05 03:12:56 -0700 (Fri, 05 Oct 2007) Log Message: ----------- Some minor clean and typo fixes. Modified Paths: -------------- trunk/libirc/include/IRCClient.h trunk/libirc/include/IRCUserManager.h trunk/libirc/src/IRCClient.cpp trunk/libirc/src/IRCUserManager.cpp Modified: trunk/libirc/include/IRCClient.h =================================================================== --- trunk/libirc/include/IRCClient.h 2007-10-05 05:37:09 UTC (rev 238) +++ trunk/libirc/include/IRCClient.h 2007-10-05 10:12:56 UTC (rev 239) @@ -131,7 +131,7 @@ // IRC info operations virtual string_list listUsers ( std::string channel ); - virtual string_list listChanels ( void ); + virtual string_list listChannels ( void ); // NOTE: was this listChanels for a reason?? mm_202. virtual string_list listChanOps ( std::string channel ); virtual trIRCChannelPermisions getChanPerms ( std::string channel ); @@ -209,13 +209,13 @@ // networking TCPClientConnection *tcpClient; - TCPConnection &tcpConnection; + TCPConnection &tcpConnection; // irc data - std::string ircServerName; - std::string reportedServerHost; - unsigned short ircServerPort; - std::string lastRecevedData; + std::string ircServerName; + std::string reportedServerHost; + unsigned short ircServerPort; + std::string lastRecevedData; // IRC "constants" std::string ircMessageTerminator; @@ -233,7 +233,7 @@ teIRCConnectionState ircConnectionState; - bool registered; + bool registered; virtual teIRCConnectionState getConnectionState ( void ){return ircConnectionState;} virtual void setConnectionState ( teIRCConnectionState state ){ircConnectionState = state;} @@ -253,8 +253,8 @@ void registerDefaultCommandhandlers ( void ); // event handlers - tmIRCEventMap defaultEventHandlers; - tmIRCEventListMap userEventHandlers; + tmIRCEventMap defaultEventHandlers; + tmIRCEventListMap userEventHandlers; void addDefaultEventHandlers ( teIRCEventType eventType, IRCBasicEventCallback* handler ); void clearDefaultEventHandlers ( void ); @@ -262,17 +262,17 @@ // loging IRCClientLogHandler *logHandler; - std::string logfile; - int debugLogLevel; + std::string logfile; + int debugLogLevel; // info from the connection - std::string MOTD; - std::string requestedNick; - std::string nickname; + std::string MOTD; + std::string requestedNick; + std::string nickname; - IRCUserManager userManager; + IRCUserManager userManager; // flood protection - float minCycleTime; + float minCycleTime; }; #endif //_IRC_CLIENT_H_ Modified: trunk/libirc/include/IRCUserManager.h =================================================================== --- trunk/libirc/include/IRCUserManager.h 2007-10-05 05:37:09 UTC (rev 238) +++ trunk/libirc/include/IRCUserManager.h 2007-10-05 10:12:56 UTC (rev 239) @@ -52,44 +52,44 @@ typedef struct { std::string mode; - bool allowColors; - bool forwarded; - bool inviteOnly; - bool anyInvite; - bool juped; - int userLimit; - bool moderated; - bool externalMessages; - bool permanent; - bool regForVoice; - bool regOnly; - bool secret; - bool reducedModeraton; + bool allowColors; + bool forwarded; + bool inviteOnly; + bool anyInvite; + bool juped; + int userLimit; + bool moderated; + bool externalMessages; + bool permanent; + bool regForVoice; + bool regOnly; + bool secret; + bool reducedModeraton; }trIRCChannelPermisions; typedef struct { - int id; - std::string name; - trIRCChannelPermisions perms; + int id; + std::string name; + trIRCChannelPermisions perms; std::map<int,trIRCChannelUserPermisions>userPerms; - std::string lastMessage; - int lastMessageUser; - std::string topic; - std::vector<trIRCBanListItem> banList; + std::string lastMessage; + int lastMessageUser; + std::string topic; + std::vector<trIRCBanListItem> banList; }trIRCChannelRecord; typedef struct { - int id; - std::string nick; - std::string host; + int id; + std::string nick; + std::string host; - int lastMessageChannel; - std::string lastMessage; + int lastMessageChannel; + std::string lastMessage; - trIRCUserPermisions perms; - std::vector<int> channels; + trIRCUserPermisions perms; + std::vector<int> channels; }trIRCUserRecord; class IRCUserManager @@ -179,8 +179,8 @@ std::vector<trIRCBanListItem> getChannelBanList ( std::string &channel ); std::vector<int> listChannelUsers ( int id ); - std::vector<int> listChannelsUser ( std::string &name ); - std::vector<std::string> listChanneUserlNames ( int id ); + std::vector<int> listChannelUsers ( std::string &name ); + std::vector<std::string> listChannelUserNames ( int id ); std::vector<std::string> listChannelUserNames ( std::string &name ); std::vector<int> listChannels ( void ); @@ -252,9 +252,9 @@ std::map<std::string,int> userNameLookup; std::map<std::string,int> channelNameLookup; - bool autoPurgeOnLastPart; - int lastUserID; - int lastChannelID; + bool autoPurgeOnLastPart; + int lastUserID; + int lastChannelID; }; #endif//_IRC_USER_MANAGER_ \ No newline at end of file Modified: trunk/libirc/src/IRCClient.cpp =================================================================== --- trunk/libirc/src/IRCClient.cpp 2007-10-05 05:37:09 UTC (rev 238) +++ trunk/libirc/src/IRCClient.cpp 2007-10-05 10:12:56 UTC (rev 239) @@ -665,7 +665,7 @@ return userNames; } -string_list IRCClient::listChanels ( void ) +string_list IRCClient::listChannels ( void ) { return userManager.listChannelNames(); } Modified: trunk/libirc/src/IRCUserManager.cpp =================================================================== --- trunk/libirc/src/IRCUserManager.cpp 2007-10-05 05:37:09 UTC (rev 238) +++ trunk/libirc/src/IRCUserManager.cpp 2007-10-05 10:12:56 UTC (rev 239) @@ -457,7 +457,7 @@ return userList; } -std::vector<int> IRCUserManager::listChannelsUser ( std::string &name ) +std::vector<int> IRCUserManager::listChannelUsers ( std::string &name ) { trIRCChannelRecord &channel = getChannelInfo(name); @@ -469,7 +469,7 @@ return userList; } -std::vector<std::string> IRCUserManager::listChanneUserlNames ( int id ) +std::vector<std::string> IRCUserManager::listChannelUserNames ( int id ) { trIRCChannelRecord &channel = getChannelInfo(id); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Jef...@us...> - 2007-10-09 01:45:43
|
Revision: 240 http://libirc.svn.sourceforge.net/libirc/?rev=240&view=rev Author: JeffM2501 Date: 2007-10-08 18:45:37 -0700 (Mon, 08 Oct 2007) Log Message: ----------- add a client network handler so that the class can use external networking code. Modified Paths: -------------- trunk/libirc/include/IRCClient.h trunk/libirc/src/IRCClient.cpp Modified: trunk/libirc/include/IRCClient.h =================================================================== --- trunk/libirc/include/IRCClient.h 2007-10-05 10:12:56 UTC (rev 239) +++ trunk/libirc/include/IRCClient.h 2007-10-09 01:45:37 UTC (rev 240) @@ -19,14 +19,37 @@ #include "libIRC.h" #include "ircCommands.h" #include "IRCEvents.h" -#include "TCPConnection.h" #include "IRCUserManager.h" +#include "TCPConnection.h" + // global includes #include <string> #include <vector> #include <map> +// client network handler if they install one (TODO:: make a default one of these that runs our networking) + +class CIRCClientNetworkHandler +{ +public: + virtual ~CIRCClientNetworkHandler(){}; + + virtual bool connected ( void ) = 0; + virtual bool connect ( const char *server, int port ) = 0; + virtual void disconnect ( bool quit ) = 0; + + virtual void update ( void ){}; + // inbound pending data + virtual int pendingPackets ( void ) = 0; + virtual unsigned int getPacketSize ( int packet ) = 0; + virtual const char *getPacketData ( int packet ) = 0; + virtual void flushInboundPackets ( void ) = 0; + + // outbound pending data + virtual bool send ( const char *data, int len ) = 0; +}; + // need this later class IRCClient; @@ -62,7 +85,7 @@ class IRCClient : public TCPClientDataPendingListener, IRCBasicEventCallback { public: - IRCClient(); + IRCClient( CIRCClientNetworkHandler* h = NULL); virtual ~IRCClient(); // logging @@ -204,6 +227,9 @@ // used by the defalt event handlers bool process ( IRCClient &ircClient, teIRCEventType eventType, trBaseEventInfo &info ); + // external network access + void setNetworkHandler ( CIRCClientNetworkHandler * _netHandler ){netHandler = _netHandler;} + protected: friend class IRCClientCommandHandler; @@ -211,6 +237,9 @@ TCPClientConnection *tcpClient; TCPConnection &tcpConnection; + // external data handler + CIRCClientNetworkHandler *netHandler; + // irc data std::string ircServerName; std::string reportedServerHost; @@ -241,6 +270,8 @@ // receved data processing void processIRCLine ( std::string line ); + void addDataToLine ( std::string &line, unsigned int len, const char *data ); + // the command handlers typedef std::map<std::string, IRCClientCommandHandler*> tmCommandHandlerMap; typedef std::map<std::string, std::vector<IRCClientCommandHandler*> > tmUserCommandHandlersMap; Modified: trunk/libirc/src/IRCClient.cpp =================================================================== --- trunk/libirc/src/IRCClient.cpp 2007-10-05 10:12:56 UTC (rev 239) +++ trunk/libirc/src/IRCClient.cpp 2007-10-09 01:45:37 UTC (rev 240) @@ -19,210 +19,246 @@ #include "IRCTextUtils.h" #ifndef _WIN32 - #include <unistd.h> + #include <unistd.h> #else - #include <windows.h> - #include <time.h> - #include <stdio.h> + #include <windows.h> + #include <time.h> + #include <stdio.h> #endif class DefaultIRCLogHandler : public IRCClientLogHandler { public: - virtual ~DefaultIRCLogHandler(){return;} - virtual void log ( IRCClient &client, int level, std::string line ) - { - printf("log# %d:%s\n",level,line.c_str()); + virtual ~DefaultIRCLogHandler(){return;} + virtual void log ( IRCClient &client, int level, std::string line ) + { + printf("log# %d:%s\n",level,line.c_str()); - if (client.getLogfile().size()) - { - FILE *fp = fopen(client.getLogfile().c_str(),"at"); + if (client.getLogfile().size()) + { + FILE *fp = fopen(client.getLogfile().c_str(),"at"); - if (fp) - { - fprintf(fp,"log# %d:%s\n",level,line.c_str()); - fclose(fp); - } - } - } + if (fp) + { + fprintf(fp,"log# %d:%s\n",level,line.c_str()); + fclose(fp); + } + } + } }; -static DefaultIRCLogHandler defaultLogger; +static DefaultIRCLogHandler defaultLogger; // IRC class stuff -IRCClient::IRCClient() +IRCClient::IRCClient(CIRCClientNetworkHandler *h) :tcpConnection(TCPConnection::instance()) { - tcpClient = NULL; - registerDefaultCommandhandlers(); - init(); + netHandler = h; + tcpClient = NULL; + registerDefaultCommandhandlers(); + init(); - ircMessageTerminator = "\r\n"; - ircCommandDelimator = " "; - debugLogLevel = 0; - ircServerPort = _DEFAULT_IRC_PORT; - ircConnectionState = eNotConnected; - logHandler = &defaultLogger; + ircMessageTerminator = "\r\n"; + ircCommandDelimator = " "; + debugLogLevel = 0; + ircServerPort = _DEFAULT_IRC_PORT; + ircConnectionState = eNotConnected; + logHandler = &defaultLogger; } // irc client IRCClient::~IRCClient() { - disconnect("shutting down"); + disconnect("shutting down"); - if (tcpClient) - tcpConnection.deleteClientConnection(tcpClient); + if (tcpClient) + tcpConnection.deleteClientConnection(tcpClient); + else if ( netHandler ) + netHandler->disconnect(true); -// tcpConnection.kill(); +// tcpConnection.kill(); } // general connection methods bool IRCClient::init ( void ) { - minCycleTime = 0.1f; - registered = false; - nickname = ""; - // if any old conenctions are around, kill em - if (tcpClient) - tcpConnection.deleteClientConnection(tcpClient); + minCycleTime = 0.1f; + registered = false; + nickname = ""; + // if any old conenctions are around, kill em + if (netHandler) + netHandler->disconnect(false); + else if (tcpClient) + tcpConnection.deleteClientConnection(tcpClient); - tcpClient = NULL; + tcpClient = NULL; - // make sure the system we have is inited - //tcpConnection.init(); + // make sure the system we have is inited + //tcpConnection.init(); - // just get us a new empty connection - tcpClient = tcpConnection.newClientConnection("",0); - - if (tcpClient) - tcpClient->addListener(this); + // just get us a new empty connection + if (!netHandler) + tcpClient = tcpConnection.newClientConnection("",0); - return tcpClient != NULL; -} + if (tcpClient) + tcpClient->addListener(this); + return netHandler || (tcpClient != NULL); + } + bool IRCClient::connect ( std::string server, int port ) { - if (!tcpClient || !server.size()) - return false; + if (!netHandler && (!tcpClient || !server.size())) + return false; - reportedServerHost = ircServerName = server; - ircServerPort = _DEFAULT_IRC_PORT; - if ( port > 0 ) - ircServerPort = (unsigned short)port; + reportedServerHost = ircServerName = server; + ircServerPort = _DEFAULT_IRC_PORT; + if ( port > 0 ) + ircServerPort = (unsigned short)port; - teTCPError err = tcpClient->connect(server,ircServerPort); + teTCPError err; + if (netHandler) + err = netHandler->connect(server.c_str(),ircServerPort) ? eTCPNoError : eTCPConnectionFailed; + else + err = tcpClient->connect(server,ircServerPort); - ircConnectionState = err == eTCPNoError ? eTCPConenct : eNotConnected; + ircConnectionState = err == eTCPNoError ? eTCPConenct : eNotConnected; - return err == eTCPNoError; + return err == eTCPNoError; } bool IRCClient::disconnect ( std::string reason ) { - if (ircConnectionState >= eLoggedIn) - { - if (!reason.size()) - reason = "shuting down"; + if (ircConnectionState >= eLoggedIn) + { + if (!reason.size()) + reason = "shuting down"; - IRCCommandINfo info; - info.params.push_back(reason); + IRCCommandINfo info; + info.params.push_back(reason); - if (!sendIRCCommand(eCMD_QUIT,info)) - { - log("Disconnect Failed: QUIT command not sent",0); - return false; - } + if (!sendIRCCommand(eCMD_QUIT,info)) + { + log("Disconnect Failed: QUIT command not sent",0); + return false; + } - teTCPError err = tcpClient->disconnect(); + ircConnectionState = eNotConnected; + if (netHandler) + { + netHandler->disconnect(false); + return false; + } + else + return tcpClient->disconnect() == eTCPNoError; + } + return false; +} - ircConnectionState = eNotConnected; +void IRCClient::addDataToLine ( std::string &theLine, unsigned int len, const char *data ) +{ + unsigned int count = 0; - return err == eTCPNoError; - } - return false; + while (count < len) + { + if (data[count] == 13) + { + if (theLine.size()) + { + processIRCLine(theLine); + theLine = ""; + } + if (count != len-1) + count++; + } + else + { + if (data[count] != 10) + theLine += data[count]; + } + count++; + } } // update loop methods bool IRCClient::process ( void ) { - return tcpConnection.update()==eTCPNoError; + if (netHandler) + { + netHandler->update(); + + std::string theLine = lastRecevedData; + + int pendingCount = netHandler->pendingPackets(); + for ( int i = 0; i < pendingCount; i++ ) + { + addDataToLine(theLine,netHandler->getPacketSize(i),netHandler->getPacketData(i)); + // save off anything left + lastRecevedData = theLine; + } + netHandler->flushInboundPackets(); + } + else + return tcpConnection.update()==eTCPNoError; + + return true; } void IRCClient::pending ( TCPClientConnection *connection, int count ) { - // we got some data, do something with it - log("Data Pending notification",5); - // ok we have to parse this tuff into "lines" - std::string theLine = lastRecevedData; - tvPacketList &packets = connection->getPackets(); + // we got some data, do something with it + log("Data Pending notification",5); + // ok we have to parse this tuff into "lines" + std::string theLine = lastRecevedData; + tvPacketList &packets = connection->getPackets(); - while(packets.size()) - { - TCPPacket &packet = *(packets.begin()); + while(packets.size()) + { + TCPPacket &packet = *(packets.begin()); - unsigned int len; - char* data = (char*)packet.get(len); - unsigned int count = 0; + unsigned int len; + char* data = (char*)packet.get(len); + addDataToLine(theLine,len,data); - while (count < len) - { - if (data[count] == 13) - { - if (theLine.size()) - { - processIRCLine(theLine); - theLine = ""; - } - if (count != len-1) - count++; - } - else - { - if (data[count] != 10) - { - theLine += data[count]; - } - } - count++; - } - // save off anything left - lastRecevedData = theLine; + // save off anything left + lastRecevedData = theLine; - packets.erase(packets.begin()); - } + packets.erase(packets.begin()); + } } void IRCClient::processIRCLine ( std::string line ) { - // we have a single line of text, do something with it. - // see if it's a command, and or call any handlers that we have - // also check for error returns + // we have a single line of text, do something with it. + // see if it's a command, and or call any handlers that we have + // also check for error returns - // right now we don't know if it's an IRC or CTCP command so just go with the generic one - // let the command parse it out into paramaters and find the command - BaseIRCCommandInfo commandInfo; - commandInfo.parse(line); - std::string handler; + // right now we don't know if it's an IRC or CTCP command so just go with the generic one + // let the command parse it out into paramaters and find the command + BaseIRCCommandInfo commandInfo; + commandInfo.parse(line); + std::string handler; - if (!commandInfo.prefixed) - commandInfo.source = getServerHost(); + if (!commandInfo.prefixed) + commandInfo.source = getServerHost(); - // call the "ALL" handler special if there is one - handler = std::string("ALL"); - receveCommand(handler,commandInfo); + // call the "ALL" handler special if there is one + handler = std::string("ALL"); + receveCommand(handler,commandInfo); - if (atoi(commandInfo.command.c_str()) != 0) { - handler = std::string("NUMERIC"); - receveCommand(handler,commandInfo); - } + if (atoi(commandInfo.command.c_str()) != 0) + { + handler = std::string("NUMERIC"); + receveCommand(handler,commandInfo); + } - // notify any handlers for this specific command - receveCommand(commandInfo.command,commandInfo); + // notify any handlers for this specific command + receveCommand(commandInfo.command,commandInfo); } -bool IRCClient::sendIRCCommandToServer ( teIRCCommands command, std::string &data) +bool IRCClient::sendIRCCommandToServer ( teIRCCommands command, std::string &data) { std::string text = ircCommandParser.getCommandName(command) + ircCommandDelimator + data; return sendTextToServer(text); @@ -231,186 +267,192 @@ // utility methods bool IRCClient::sendTextToServer ( std::string &text ) { - if (!tcpClient || !tcpClient->connected()) - return false; + if (!text.size()) + return false; - std::string message = text; - if (text.size()) - { - message += ircMessageTerminator; - teTCPError error = tcpClient->sendData(message); - if (error == eTCPNoError) - log("Send Data:" + text,2); - else - { - switch (error) - { - case eTCPNotInit: - log("Send Data Error: TCP Not Initalised: data=" + text,0); - break; + std::string message = text + ircMessageTerminator; - case eTCPSocketNFG: - log("Send Data Error: Bad Socket: data=" + text,0); - break; + if (netHandler) + { + if ( !netHandler->connected() ) + return false; - case eTCPDataNFG: - log("Send Data Error: Bad Data",0); - break; + return netHandler->send(message.c_str(),(int)message.size()); + } - case eTCPConnectionFailed: - log("Send Data Error: TCP Connection failed",0); - break; + if (!tcpClient || !tcpClient->connected()) + return false; - default: - log("Send Data Error:Unknown Error",0); - } - return false; - } - } - else - return false; + teTCPError error = tcpClient->sendData(message); + if (error == eTCPNoError) + log("Send Data:" + text,2); + else + { + switch (error) + { + case eTCPNotInit: + log("Send Data Error: TCP Not Initalised: data=" + text,0); + break; - // prevent that thar flooding - IRCOSSleep(minCycleTime); - return true; + case eTCPSocketNFG: + log("Send Data Error: Bad Socket: data=" + text,0); + break; + + case eTCPDataNFG: + log("Send Data Error: Bad Data",0); + break; + + case eTCPConnectionFailed: + log("Send Data Error: TCP Connection failed",0); + break; + + default: + log("Send Data Error:Unknown Error",0); + } + return false; + } + + // prevent that thar flooding + IRCOSSleep(minCycleTime); + return true; } -void IRCClient::setLogHandler ( IRCClientLogHandler * logger ) +void IRCClient::setLogHandler ( IRCClientLogHandler * logger ) { - if (!logger) - logHandler = &defaultLogger; - else - logHandler = logger; + if (!logger) + logHandler = &defaultLogger; + else + logHandler = logger; } void IRCClient::log ( const char *text, int level ) { - log(std::string(text),level); + log(std::string(text),level); } void IRCClient::log ( std::string text, int level ) { - if (level <= debugLogLevel && logHandler) - logHandler->log(*this,level,text); + if (level <= debugLogLevel && logHandler) + logHandler->log(*this,level,text); } void IRCClient::setLogfile ( std::string file ) { - logfile = file; + logfile = file; } std::string IRCClient::getLogfile ( void ) { - return logfile; + return logfile; } void IRCClient::setDebugLevel ( int level ) { - debugLogLevel = level; + debugLogLevel = level; } int IRCClient::getDebugLevel ( void ) { - return debugLogLevel; + return debugLogLevel; } bool IRCClient::sendCommand ( std::string &commandName, BaseIRCCommandInfo &info ) { - tmUserCommandHandlersMap::iterator commandListItr = userCommandHandlers.find(commandName); + tmUserCommandHandlersMap::iterator commandListItr = userCommandHandlers.find(commandName); - bool callDefault = true; + bool callDefault = true; - if (commandListItr != userCommandHandlers.end() && commandListItr->second.size()) // do we have a custom command handler - { - // someone has to want us to call the defalt now - callDefault = false; - // is this right? - // should we do them all? or just the first one that "HANDLES" it? - std::vector<IRCClientCommandHandler*>::iterator itr = commandListItr->second.begin(); - while (itr != commandListItr->second.end()) - { - if ( (*itr)->send(*this,commandName,info)) - callDefault = true; - itr++; - } - return true; - } + if (commandListItr != userCommandHandlers.end() && commandListItr->second.size()) // do we have a custom command handler + { + // someone has to want us to call the defalt now + callDefault = false; + // is this right? + // should we do them all? or just the first one that "HANDLES" it? + std::vector<IRCClientCommandHandler*>::iterator itr = commandListItr->second.begin(); + while (itr != commandListItr->second.end()) + { + if ( (*itr)->send(*this,commandName,info)) + callDefault = true; + itr++; + } + return true; + } - if (callDefault) // check for the default - { - tmCommandHandlerMap::iterator itr = defaultCommandHandlers.find(commandName); - if (itr != defaultCommandHandlers.end()) - { - itr->second->send(*this,commandName,info); - return true; - } - } - return false; + if (callDefault) // check for the default + { + tmCommandHandlerMap::iterator itr = defaultCommandHandlers.find(commandName); + if (itr != defaultCommandHandlers.end()) + { + itr->second->send(*this,commandName,info); + return true; + } + } + return false; } -bool IRCClient::sendIRCCommand ( teIRCCommands command, IRCCommandINfo &info ) +bool IRCClient::sendIRCCommand ( teIRCCommands command, IRCCommandINfo &info ) { - info.type = eIRCCommand; - info.ircCommand = command; - info.command = ircCommandParser.getCommandName(command); - return sendCommand(info.command,info); + info.type = eIRCCommand; + info.ircCommand = command; + info.command = ircCommandParser.getCommandName(command); + return sendCommand(info.command,info); } -bool IRCClient::sendCTMPCommand ( teCTCPCommands command, CTCPCommandINfo &info ) +bool IRCClient::sendCTMPCommand ( teCTCPCommands command, CTCPCommandINfo &info ) { - info.type = eCTCPCommand; - info.ctcpCommand = command; - info.command = ctcpCommandParser.getCommandName(command); - return sendCommand(info.command,info); + info.type = eCTCPCommand; + info.ctcpCommand = command; + info.command = ctcpCommandParser.getCommandName(command); + return sendCommand(info.command,info); } bool IRCClient::receveCommand ( std::string &commandName, BaseIRCCommandInfo &info ) { - tmUserCommandHandlersMap::iterator commandListItr = userCommandHandlers.find(commandName); + tmUserCommandHandlersMap::iterator commandListItr = userCommandHandlers.find(commandName); - bool callDefault = true; + bool callDefault = true; - if (commandListItr != userCommandHandlers.end() && commandListItr->second.size()) // do we have a custom command handler - { - // someone has to want us to call the defalt now - callDefault = false; - // is this right? - // should we do them all? or just the first one that "HANDLES" it? - std::vector<IRCClientCommandHandler*>::iterator itr = commandListItr->second.begin(); - while (itr != commandListItr->second.end()) - { - if ( (*itr)->receve(*this,commandName,info)) - callDefault = true; - itr++; - } - if (!callDefault) - return true; - } + if (commandListItr != userCommandHandlers.end() && commandListItr->second.size()) // do we have a custom command handler + { + // someone has to want us to call the defalt now + callDefault = false; + // is this right? + // should we do them all? or just the first one that "HANDLES" it? + std::vector<IRCClientCommandHandler*>::iterator itr = commandListItr->second.begin(); + while (itr != commandListItr->second.end()) + { + if ( (*itr)->receve(*this,commandName,info)) + callDefault = true; + itr++; + } + if (!callDefault) + return true; + } - if (callDefault) // check for the default - { - tmCommandHandlerMap::iterator itr = defaultCommandHandlers.find(commandName); - if (itr != defaultCommandHandlers.end()) - { - itr->second->receve(*this,commandName,info); - return true; - } - } - return false; + if (callDefault) // check for the default + { + tmCommandHandlerMap::iterator itr = defaultCommandHandlers.find(commandName); + if (itr != defaultCommandHandlers.end()) + { + itr->second->receve(*this,commandName,info); + return true; + } + } + return false; } -bool IRCClient::receveIRCCommand ( teIRCCommands command, IRCCommandINfo &info ) +bool IRCClient::receveIRCCommand ( teIRCCommands command, IRCCommandINfo &info ) { - info.type = eIRCCommand; - info.ircCommand = command; - return receveCommand(info.command,info); + info.type = eIRCCommand; + info.ircCommand = command; + return receveCommand(info.command,info); } -bool IRCClient::receveCTMPCommand ( teCTCPCommands command, CTCPCommandINfo &info ) +bool IRCClient::receveCTMPCommand ( teCTCPCommands command, CTCPCommandINfo &info ) { - info.type = eCTCPCommand; - info.ctcpCommand = command; - return receveCommand(info.command,info); + info.type = eCTCPCommand; + info.ctcpCommand = command; + return receveCommand(info.command,info); } bool IRCClient::registerCommandHandler ( IRCClientCommandHandler *handler ) @@ -435,271 +477,271 @@ bool IRCClient::removeCommandHandler ( IRCClientCommandHandler *handler ) { - if (!handler) - return false; + if (!handler) + return false; - std::string command = handler->getCommandName(); + std::string command = handler->getCommandName(); - tmUserCommandHandlersMap::iterator commandListItr = userCommandHandlers.find(command); - if (commandListItr == userCommandHandlers.end()) - return false; - else - { - std::vector<IRCClientCommandHandler*>::iterator itr = commandListItr->second.begin(); - while ( itr != commandListItr->second.end()) - { - if (*itr == handler) - itr = commandListItr->second.erase(itr); - else - itr++; - } - } - return true; + tmUserCommandHandlersMap::iterator commandListItr = userCommandHandlers.find(command); + if (commandListItr == userCommandHandlers.end()) + return false; + else + { + std::vector<IRCClientCommandHandler*>::iterator itr = commandListItr->second.begin(); + while ( itr != commandListItr->second.end()) + { + if (*itr == handler) + itr = commandListItr->second.erase(itr); + else + itr++; + } + } + return true; } int IRCClient::listUserHandledCommands ( std::vector<std::string> &commandList ) { - commandList.clear(); + commandList.clear(); - tmUserCommandHandlersMap::iterator itr = userCommandHandlers.begin(); + tmUserCommandHandlersMap::iterator itr = userCommandHandlers.begin(); - while (itr != userCommandHandlers.end()) - { - commandList.push_back(itr->first); - itr++; - } - return (int)commandList.size(); + while (itr != userCommandHandlers.end()) + { + commandList.push_back(itr->first); + itr++; + } + return (int)commandList.size(); } int IRCClient::listDefaultHandledCommands ( std::vector<std::string> &commandList ) { - commandList.clear(); + commandList.clear(); - tmCommandHandlerMap::iterator itr = defaultCommandHandlers.begin(); + tmCommandHandlerMap::iterator itr = defaultCommandHandlers.begin(); - while (itr != defaultCommandHandlers.end()) - { - commandList.push_back(itr->first); - itr++; - } - return (int)commandList.size(); + while (itr != defaultCommandHandlers.end()) + { + commandList.push_back(itr->first); + itr++; + } + return (int)commandList.size(); } void IRCClient::addDefaultCommandhandlers ( IRCClientCommandHandler* handler ) { - defaultCommandHandlers[handler->getCommandName()] = handler; + defaultCommandHandlers[handler->getCommandName()] = handler; } void IRCClient::clearDefaultCommandhandlers ( void ) { - tmCommandHandlerMap::iterator itr = defaultCommandHandlers.begin(); + tmCommandHandlerMap::iterator itr = defaultCommandHandlers.begin(); - while (itr != defaultCommandHandlers.end()) - { - delete(itr->second); - itr++; - } - defaultCommandHandlers.clear(); + while (itr != defaultCommandHandlers.end()) + { + delete(itr->second); + itr++; + } + defaultCommandHandlers.clear(); } void IRCClient::registerDefaultCommandhandlers ( void ) { - registerDefaultEventHandlers(); + registerDefaultEventHandlers(); - userCommandHandlers.clear(); - clearDefaultCommandhandlers(); + userCommandHandlers.clear(); + clearDefaultCommandhandlers(); - // the "special" handlers - addDefaultCommandhandlers(new IRCALLCommand ); - addDefaultCommandhandlers(new IRCNumericCommand ); + // the "special" handlers + addDefaultCommandhandlers(new IRCALLCommand ); + addDefaultCommandhandlers(new IRCNumericCommand ); - // basic IRC commands - addDefaultCommandhandlers(new IRCNickCommand ); - addDefaultCommandhandlers(new IRCUserCommand ); - addDefaultCommandhandlers(new IRCPingCommand ); - addDefaultCommandhandlers(new IRCPongCommand ); - addDefaultCommandhandlers(new IRCNoticeCommand ); - addDefaultCommandhandlers(new IRCJoinCommand ); - addDefaultCommandhandlers(new IRCPartCommand ); - addDefaultCommandhandlers(new IRCQuitCommand ); - addDefaultCommandhandlers(new IRCModeCommand ); - addDefaultCommandhandlers(new IRCPrivMsgCommand ); - addDefaultCommandhandlers(new IRCKickCommand ); + // basic IRC commands + addDefaultCommandhandlers(new IRCNickCommand ); + addDefaultCommandhandlers(new IRCUserCommand ); + addDefaultCommandhandlers(new IRCPingCommand ); + addDefaultCommandhandlers(new IRCPongCommand ); + addDefaultCommandhandlers(new IRCNoticeCommand ); + addDefaultCommandhandlers(new IRCJoinCommand ); + addDefaultCommandhandlers(new IRCPartCommand ); + addDefaultCommandhandlers(new IRCQuitCommand ); + addDefaultCommandhandlers(new IRCModeCommand ); + addDefaultCommandhandlers(new IRCPrivMsgCommand ); + addDefaultCommandhandlers(new IRCKickCommand ); } // logical event handlers -//tmIRCEventMap defaultEventHandlers; -//tmIRCEventListMap userEventHandlers; +//tmIRCEventMap defaultEventHandlers; +//tmIRCEventListMap userEventHandlers; void IRCClient::addDefaultEventHandlers ( teIRCEventType eventType, IRCBasicEventCallback* handler ) { - if (handler) - defaultEventHandlers[eventType] = handler; + if (handler) + defaultEventHandlers[eventType] = handler; } void IRCClient::clearDefaultEventHandlers ( void ) { - tmIRCEventMap::iterator itr = defaultEventHandlers.begin(); + tmIRCEventMap::iterator itr = defaultEventHandlers.begin(); - while ( itr != defaultEventHandlers.end()) - { - if (itr->second && (itr->second != this) ) - delete(itr->second); - itr++; - } - defaultEventHandlers.clear(); + while ( itr != defaultEventHandlers.end()) + { + if (itr->second && (itr->second != this) ) + delete(itr->second); + itr++; + } + defaultEventHandlers.clear(); } void IRCClient::registerDefaultEventHandlers ( void ) { - userEventHandlers.clear(); - clearDefaultEventHandlers(); + userEventHandlers.clear(); + clearDefaultEventHandlers(); - addDefaultEventHandlers(eIRCNickNameError,this); + addDefaultEventHandlers(eIRCNickNameError,this); } bool IRCClient::registerEventHandler ( teIRCEventType eventType, IRCBasicEventCallback *handler ) { - if (!handler) - return false; + if (!handler) + return false; - tmIRCEventListMap::iterator eventListItr = userEventHandlers.find(eventType); - if (eventListItr == userEventHandlers.end()) - { - tvIRCEventList handlerList; - handlerList.push_back(handler); - userEventHandlers[eventType] = handlerList; - } - else - eventListItr->second.push_back(handler); + tmIRCEventListMap::iterator eventListItr = userEventHandlers.find(eventType); + if (eventListItr == userEventHandlers.end()) + { + tvIRCEventList handlerList; + handlerList.push_back(handler); + userEventHandlers[eventType] = handlerList; + } + else + eventListItr->second.push_back(handler); - return true; + return true; } bool IRCClient::removeEventHandler ( teIRCEventType eventType, IRCBasicEventCallback *handler ) { - if (!handler) - return false; + if (!handler) + return false; - tmIRCEventListMap::iterator eventListItr = userEventHandlers.find(eventType); - if (eventListItr == userEventHandlers.end()) - return false; - else - { - tvIRCEventList::iterator itr = eventListItr->second.begin(); - while ( itr != eventListItr->second.end()) - { - if ((*itr)== handler) - itr = eventListItr->second.erase(itr); - else - itr++; - } - } - return true; + tmIRCEventListMap::iterator eventListItr = userEventHandlers.find(eventType); + if (eventListItr == userEventHandlers.end()) + return false; + else + { + tvIRCEventList::iterator itr = eventListItr->second.begin(); + while ( itr != eventListItr->second.end()) + { + if ((*itr)== handler) + itr = eventListItr->second.erase(itr); + else + itr++; + } + } + return true; } void IRCClient::callEventHandler ( teIRCEventType eventType, trBaseEventInfo &info ) { - bool callDefault = true; + bool callDefault = true; - tmIRCEventListMap::iterator eventListItr = userEventHandlers.find(eventType); + tmIRCEventListMap::iterator eventListItr = userEventHandlers.find(eventType); - // make sure the event type is cool - info.eventType = eventType; + // make sure the event type is cool + info.eventType = eventType; - if (eventListItr != userEventHandlers.end() && eventListItr->second.size()) // do we have a custom command handler - { - // someone has to want us to call the defalt now - callDefault = false; - // is this right? - // should we do them all? or just the first one that "HANDLES" it? - tvIRCEventList::iterator itr = eventListItr->second.begin(); - while (itr != eventListItr->second.end()) - { - if ( (*itr)->process(*this,eventType,info)) - callDefault = true; - itr++; - } - if (!callDefault) - return; - } + if (eventListItr != userEventHandlers.end() && eventListItr->second.size()) // do we have a custom command handler + { + // someone has to want us to call the defalt now + callDefault = false; + // is this right? + // should we do them all? or just the first one that "HANDLES" it? + tvIRCEventList::iterator itr = eventListItr->second.begin(); + while (itr != eventListItr->second.end()) + { + if ( (*itr)->process(*this,eventType,info)) + callDefault = true; + itr++; + } + if (!callDefault) + return; + } - if (callDefault) // check for the default - { - tmIRCEventMap::iterator itr = defaultEventHandlers.find(eventType); - if (itr != defaultEventHandlers.end()) - { - itr->second->process(*this,eventType,info); - return; - } - } - return; + if (callDefault) // check for the default + { + tmIRCEventMap::iterator itr = defaultEventHandlers.find(eventType); + if (itr != defaultEventHandlers.end()) + { + itr->second->process(*this,eventType,info); + return; + } + } + return; } // info methods string_list IRCClient::listUsers ( std::string channel ) { - if (channel.size()) - return userManager.listChannelUserNames(channel); - - return userManager.listUserNames(); + if (channel.size()) + return userManager.listChannelUserNames(channel); + + return userManager.listUserNames(); } string_list IRCClient::listChanOps ( std::string channel ) { - string_list userNames; + string_list userNames; - int channelID = userManager.getChannelID(channel); - std::vector<int> userList = userManager.listChannelUsers(channelID); - std::vector<int>::iterator itr = userList.begin(); + int channelID = userManager.getChannelID(channel); + std::vector<int> userList = userManager.listChannelUsers(channelID); + std::vector<int>::iterator itr = userList.begin(); - while ( itr != userList.end() ) - { - if (userManager.userIsOp(*itr,channelID)) - userNames.push_back(userManager.getUserNick(*itr)); + while ( itr != userList.end() ) + { + if (userManager.userIsOp(*itr,channelID)) + userNames.push_back(userManager.getUserNick(*itr)); - itr++; - } - return userNames; + itr++; + } + return userNames; } string_list IRCClient::listChannels ( void ) { - return userManager.listChannelNames(); + return userManager.listChannelNames(); } trIRCChannelPermisions IRCClient::getChanPerms ( std::string channel ) { - return userManager.getChannelPerms(channel); + return userManager.getChannelPerms(channel); } // default event handling -bool IRCClient::process ( IRCClient &ircClient, teIRCEventType eventType, trBaseEventInfo &info ) +bool IRCClient::process ( IRCClient &ircClient, teIRCEventType eventType, trBaseEventInfo &info ) { - switch (eventType) - { - case eIRCNickNameError: - { - // atempt to keep adding crap to the nick till it goes - requestedNick += '_'; + switch (eventType) + { + case eIRCNickNameError: + { + // atempt to keep adding crap to the nick till it goes + requestedNick += '_'; - IRCCommandINfo info; - info.params.push_back(requestedNick); + IRCCommandINfo info; + info.params.push_back(requestedNick); - if (!sendIRCCommand(eCMD_NICK,info)) - { - log("Nick Error Resned Failed: NICK command not sent",0); - return false; - } - if (getConnectionState() < eSentNickAndUSer) - setConnectionState(eSentNickAndUSer); - } - break; - } - return true; + if (!sendIRCCommand(eCMD_NICK,info)) + { + log("Nick Error Resned Failed: NICK command not sent",0); + return false; + } + if (getConnectionState() < eSentNickAndUSer) + setConnectionState(eSentNickAndUSer); + } + break; + } + return true; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Jef...@us...> - 2007-10-09 16:21:36
|
Revision: 241 http://libirc.svn.sourceforge.net/libirc/?rev=241&view=rev Author: JeffM2501 Date: 2007-10-09 09:21:30 -0700 (Tue, 09 Oct 2007) Log Message: ----------- 2004 -> 2007 Modified Paths: -------------- trunk/libirc/include/IRCClient.h trunk/libirc/include/IRCEvents.h trunk/libirc/include/IRCNumerics.h trunk/libirc/include/IRCServer.h trunk/libirc/include/IRCUserManager.h trunk/libirc/include/TCPConnection.h trunk/libirc/include/ircCommands.h trunk/libirc/include/libIRC.h trunk/libirc/src/IRCClient.cpp trunk/libirc/src/IRCServer.cpp trunk/libirc/src/IRCUserManager.cpp trunk/libirc/src/TCPConnection.cpp trunk/libirc/src/irClientCommands.cpp trunk/libirc/src/irClientEvents.cpp trunk/libirc/src/ircBasicCommands.cpp trunk/libirc/src/ircBasicCommands.h trunk/libirc/src/ircCommands.cpp trunk/libirc/src/libIRC.cpp trunk/libirc/src/net.cpp Modified: trunk/libirc/include/IRCClient.h =================================================================== --- trunk/libirc/include/IRCClient.h 2007-10-09 01:45:37 UTC (rev 240) +++ trunk/libirc/include/IRCClient.h 2007-10-09 16:21:30 UTC (rev 241) @@ -1,5 +1,5 @@ /* libIRC -* Copyright (c) 2004 Christopher Sean Morrison +* Copyright (c) 2007 Christopher Sean Morrison * * This package is free software; you can redistribute it and/or * modify it under the terms of the license found in the file Modified: trunk/libirc/include/IRCEvents.h =================================================================== --- trunk/libirc/include/IRCEvents.h 2007-10-09 01:45:37 UTC (rev 240) +++ trunk/libirc/include/IRCEvents.h 2007-10-09 16:21:30 UTC (rev 241) @@ -1,5 +1,5 @@ /* libIRC -* Copyright (c) 2004 Christopher Sean Morrison +* Copyright (c) 2007 Christopher Sean Morrison * * This package is free software; you can redistribute it and/or * modify it under the terms of the license found in the file Modified: trunk/libirc/include/IRCNumerics.h =================================================================== --- trunk/libirc/include/IRCNumerics.h 2007-10-09 01:45:37 UTC (rev 240) +++ trunk/libirc/include/IRCNumerics.h 2007-10-09 16:21:30 UTC (rev 241) @@ -1,5 +1,5 @@ /* libIRC -* Copyright (c) 2004 Christopher Sean Morrison +* Copyright (c) 2007 Christopher Sean Morrison * * This package is free software; you can redistribute it and/or * modify it under the terms of the license found in the file Modified: trunk/libirc/include/IRCServer.h =================================================================== --- trunk/libirc/include/IRCServer.h 2007-10-09 01:45:37 UTC (rev 240) +++ trunk/libirc/include/IRCServer.h 2007-10-09 16:21:30 UTC (rev 241) @@ -1,5 +1,5 @@ /* libIRC -* Copyright (c) 2004 Christopher Sean Morrison +* Copyright (c) 2007 Christopher Sean Morrison * * This package is free software; you can redistribute it and/or * modify it under the terms of the license found in the file Modified: trunk/libirc/include/IRCUserManager.h =================================================================== --- trunk/libirc/include/IRCUserManager.h 2007-10-09 01:45:37 UTC (rev 240) +++ trunk/libirc/include/IRCUserManager.h 2007-10-09 16:21:30 UTC (rev 241) @@ -1,5 +1,5 @@ /* libIRC -* Copyright (c) 2004 Christopher Sean Morrison +* Copyright (c) 2007 Christopher Sean Morrison * * This package is free software; you can redistribute it and/or * modify it under the terms of the license found in the file Modified: trunk/libirc/include/TCPConnection.h =================================================================== --- trunk/libirc/include/TCPConnection.h 2007-10-09 01:45:37 UTC (rev 240) +++ trunk/libirc/include/TCPConnection.h 2007-10-09 16:21:30 UTC (rev 241) @@ -1,5 +1,5 @@ /* libIRC -* Copyright (c) 2004 Christopher Sean Morrison +* Copyright (c) 2007 Christopher Sean Morrison * * This package is free software; you can redistribute it and/or * modify it under the terms of the license found in the file Modified: trunk/libirc/include/ircCommands.h =================================================================== --- trunk/libirc/include/ircCommands.h 2007-10-09 01:45:37 UTC (rev 240) +++ trunk/libirc/include/ircCommands.h 2007-10-09 16:21:30 UTC (rev 241) @@ -1,5 +1,5 @@ /* libIRC -* Copyright (c) 2004 Christopher Sean Morrison +* Copyright (c) 2007 Christopher Sean Morrison * * This package is free software; you can redistribute it and/or * modify it under the terms of the license found in the file Modified: trunk/libirc/include/libIRC.h =================================================================== --- trunk/libirc/include/libIRC.h 2007-10-09 01:45:37 UTC (rev 240) +++ trunk/libirc/include/libIRC.h 2007-10-09 16:21:30 UTC (rev 241) @@ -1,5 +1,5 @@ /* libIRC - * Copyright (c) 2004 Christopher Sean Morrison + * Copyright (c) 2007 Christopher Sean Morrison * * This package is free software; you can redistribute it and/or * modify it under the terms of the license found in the file @@ -25,8 +25,8 @@ // IRC includes #include "ircCommands.h" #include "IRCEvents.h" +#include "IRCUserManager.h" #include "TCPConnection.h" -#include "IRCUserManager.h" #endif Modified: trunk/libirc/src/IRCClient.cpp =================================================================== --- trunk/libirc/src/IRCClient.cpp 2007-10-09 01:45:37 UTC (rev 240) +++ trunk/libirc/src/IRCClient.cpp 2007-10-09 16:21:30 UTC (rev 241) @@ -1,5 +1,5 @@ /* libIRC -* Copyright (c) 2004 Christopher Sean Morrison +* Copyright (c) 2007 Christopher Sean Morrison * * This package is free software; you can redistribute it and/or * modify it under the terms of the license found in the file Modified: trunk/libirc/src/IRCServer.cpp =================================================================== --- trunk/libirc/src/IRCServer.cpp 2007-10-09 01:45:37 UTC (rev 240) +++ trunk/libirc/src/IRCServer.cpp 2007-10-09 16:21:30 UTC (rev 241) @@ -1,5 +1,5 @@ /* libIRC -* Copyright (c) 2004 Christopher Sean Morrison +* Copyright (c) 2007 Christopher Sean Morrison * * This package is free software; you can redistribute it and/or * modify it under the terms of the license found in the file Modified: trunk/libirc/src/IRCUserManager.cpp =================================================================== --- trunk/libirc/src/IRCUserManager.cpp 2007-10-09 01:45:37 UTC (rev 240) +++ trunk/libirc/src/IRCUserManager.cpp 2007-10-09 16:21:30 UTC (rev 241) @@ -1,5 +1,5 @@ /* libIRC -* Copyright (c) 2004 Christopher Sean Morrison +* Copyright (c) 2007 Christopher Sean Morrison * * This package is free software; you can redistribute it and/or * modify it under the terms of the license found in the file Modified: trunk/libirc/src/TCPConnection.cpp =================================================================== --- trunk/libirc/src/TCPConnection.cpp 2007-10-09 01:45:37 UTC (rev 240) +++ trunk/libirc/src/TCPConnection.cpp 2007-10-09 16:21:30 UTC (rev 241) @@ -1,5 +1,5 @@ /* libIRC -* Copyright (c) 2004 Christopher Sean Morrison +* Copyright (c) 2007 Christopher Sean Morrison * * This package is free software; you can redistribute it and/or * modify it under the terms of the license found in the file Modified: trunk/libirc/src/irClientCommands.cpp =================================================================== --- trunk/libirc/src/irClientCommands.cpp 2007-10-09 01:45:37 UTC (rev 240) +++ trunk/libirc/src/irClientCommands.cpp 2007-10-09 16:21:30 UTC (rev 241) @@ -1,5 +1,5 @@ /* libIRC -* Copyright (c) 2004 Christopher Sean Morrison +* Copyright (c) 2007 Christopher Sean Morrison * * This package is free software; you can redistribute it and/or * modify it under the terms of the license found in the file Modified: trunk/libirc/src/irClientEvents.cpp =================================================================== --- trunk/libirc/src/irClientEvents.cpp 2007-10-09 01:45:37 UTC (rev 240) +++ trunk/libirc/src/irClientEvents.cpp 2007-10-09 16:21:30 UTC (rev 241) @@ -1,5 +1,5 @@ /* libIRC -* Copyright (c) 2004 Christopher Sean Morrison +* Copyright (c) 2007 Christopher Sean Morrison * * This package is free software; you can redistribute it and/or * modify it under the terms of the license found in the file Modified: trunk/libirc/src/ircBasicCommands.cpp =================================================================== --- trunk/libirc/src/ircBasicCommands.cpp 2007-10-09 01:45:37 UTC (rev 240) +++ trunk/libirc/src/ircBasicCommands.cpp 2007-10-09 16:21:30 UTC (rev 241) @@ -1,5 +1,5 @@ /* libIRC -* Copyright (c) 2004 Christopher Sean Morrison +* Copyright (c) 2007 Christopher Sean Morrison * * This package is free software; you can redistribute it and/or * modify it under the terms of the license found in the file Modified: trunk/libirc/src/ircBasicCommands.h =================================================================== --- trunk/libirc/src/ircBasicCommands.h 2007-10-09 01:45:37 UTC (rev 240) +++ trunk/libirc/src/ircBasicCommands.h 2007-10-09 16:21:30 UTC (rev 241) @@ -1,5 +1,5 @@ /* libIRC -* Copyright (c) 2004 Christopher Sean Morrison +* Copyright (c) 2007 Christopher Sean Morrison * * This package is free software; you can redistribute it and/or * modify it under the terms of the license found in the file Modified: trunk/libirc/src/ircCommands.cpp =================================================================== --- trunk/libirc/src/ircCommands.cpp 2007-10-09 01:45:37 UTC (rev 240) +++ trunk/libirc/src/ircCommands.cpp 2007-10-09 16:21:30 UTC (rev 241) @@ -1,5 +1,5 @@ /* libIRC -* Copyright (c) 2004 Christopher Sean Morrison +* Copyright (c) 2007 Christopher Sean Morrison * * This package is free software; you can redistribute it and/or * modify it under the terms of the license found in the file Modified: trunk/libirc/src/libIRC.cpp =================================================================== --- trunk/libirc/src/libIRC.cpp 2007-10-09 01:45:37 UTC (rev 240) +++ trunk/libirc/src/libIRC.cpp 2007-10-09 16:21:30 UTC (rev 241) @@ -1,5 +1,5 @@ /* libIRC -* Copyright (c) 2004 Christopher Sean Morrison +* Copyright (c) 2007 Christopher Sean Morrison * * This package is free software; you can redistribute it and/or * modify it under the terms of the license found in the file Modified: trunk/libirc/src/net.cpp =================================================================== --- trunk/libirc/src/net.cpp 2007-10-09 01:45:37 UTC (rev 240) +++ trunk/libirc/src/net.cpp 2007-10-09 16:21:30 UTC (rev 241) @@ -1,5 +1,5 @@ /* libIRC -* Copyright (c) 2004 Christopher Sean Morrison +* Copyright (c) 2007 Christopher Sean Morrison * * This package is free software; you can redistribute it and/or * modify it under the terms of the license found in the file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Jef...@us...> - 2007-10-09 17:20:07
|
Revision: 242 http://libirc.svn.sourceforge.net/libirc/?rev=242&view=rev Author: JeffM2501 Date: 2007-10-09 10:20:03 -0700 (Tue, 09 Oct 2007) Log Message: ----------- make server client records be virtual so derived classes can create their own. stub out virtual channel classes. free any user classes we make when we disconnect. disconnect on destruction clean up some searches and typedefs for ease of use. Modified Paths: -------------- trunk/libirc/include/IRCServer.h trunk/libirc/src/IRCServer.cpp Modified: trunk/libirc/include/IRCServer.h =================================================================== --- trunk/libirc/include/IRCServer.h 2007-10-09 16:21:30 UTC (rev 241) +++ trunk/libirc/include/IRCServer.h 2007-10-09 17:20:03 UTC (rev 242) @@ -44,21 +44,62 @@ { public: IRCServerConnectedClient ( IRCServer *_server, TCPServerConnectedPeer* _peer ); - ~IRCServerConnectedClient(); + virtual ~IRCServerConnectedClient(); unsigned int getClientID ( void ) { return clientID;} - bool sendText ( const std::string &text ); + virtual bool sendText ( const std::string &text ); + virtual bool sendText ( const char*text ); std::string lastData; std::string getHostMask ( void ); bool getIP ( unsigned char ip[4] ); + virtual bool joinChannel ( const char* channel ); + virtual bool partChannel ( const char* channel ); + protected: unsigned int clientID; + bool localUser; + + // local user connection TCPServerConnectedPeer *peer; IRCServer *server; + + // remote user connection + std::string remoteServer; + + std::vector<std::string> channels; }; +class IRCServerChannel +{ +public: + IRCServerChannel( const char * _name ); + virtual ~IRCServerChannel(); + + virtual void addMember ( IRCServerConnectedClient *member ); + virtual void removeMember ( IRCServerConnectedClient *member ); + + virtual bool sendText ( const std::string &text ); + virtual bool sendText ( const char*text ); + +protected: + std::string name; + class ChannelUserData + { + public: + virtual ~ChannelUserData(); + bool voice; + bool op; + }; + + virtual ChannelUserData* newUserData ( void ){ return new ChannelUserData;} + virtual void deleteUserData ( ChannelUserData *data ){ delete(data);} + + typedef std::map <IRCServerConnectedClient*, ChannelUserData*> MemberDataMap; + MemberDataMap members; +}; + class IRCServer : public TCPServerDataPendingListener { public: @@ -98,12 +139,23 @@ virtual void clientDisconnect ( IRCServerConnectedClient *client ); virtual void clientIRCCommand ( const std::string &command, IRCServerConnectedClient *client ); + IRCServerChannel *getChannel ( const char *name ); + IRCServerChannel *getChannel ( const std::string& name ); + protected: friend class IRCServerConnectedClient; + // overide thsese if you want to derive your own classes + virtual IRCServerChannel* newChannel ( const char * name ){ return new IRCServerChannel(name); } + virtual void deleteChannel ( IRCServerChannel *channel ){ delete(channel); } + + virtual IRCServerConnectedClient* newClient ( IRCServer *_server, TCPServerConnectedPeer* _peer ){ return new IRCServerConnectedClient(_server,_peer); } + virtual void deleteClient ( IRCServerConnectedClient *client ){ delete(client); } + + // common functions bool sendTextToPeer ( const std::string &text, TCPServerConnectedPeer *peer ); - void processIRCLine ( std::string line, IRCServerConnectedClient *client ); + virtual void processIRCLine ( std::string line, IRCServerConnectedClient *client ); // networking TCPServerConnection *tcpServer; @@ -123,9 +175,13 @@ float minCycleTime; // users - std::vector<IRCServerConnectedClient> clients; + typedef std::vector<IRCServerConnectedClient*> ClientList; + ClientList clients; - std::vector<IRCServerConnectedClient>::iterator getClientItr ( IRCServerConnectedClient *client ); + ClientList::iterator getClientItr ( IRCServerConnectedClient *client ); + + // channels + std::map<std::string, IRCServerChannel*> chanels; }; #endif //_IRC_SERVER_H_ Modified: trunk/libirc/src/IRCServer.cpp =================================================================== --- trunk/libirc/src/IRCServer.cpp 2007-10-09 16:21:30 UTC (rev 241) +++ trunk/libirc/src/IRCServer.cpp 2007-10-09 17:20:03 UTC (rev 242) @@ -17,44 +17,45 @@ #include "libIRC.h" #include "ircBasicCommands.h" #include "IRCTextUtils.h" +#include <algorithm> #ifndef _WIN32 - #include <unistd.h> + #include <unistd.h> #else - #include <windows.h> - #include <time.h> - #include <stdio.h> + #include <windows.h> + #include <time.h> + #include <stdio.h> #endif class DefaultServerIRCLogHandler : public IRCServerLogHandler { public: - virtual ~DefaultServerIRCLogHandler(){return;} - virtual void log ( IRCServer &client, int level, std::string line ) - { - printf("log# %d:%s\n",level,line.c_str()); + virtual ~DefaultServerIRCLogHandler(){return;} + virtual void log ( IRCServer &client, int level, std::string line ) + { + printf("log# %d:%s\n",level,line.c_str()); - if (client.getLogfile().size()) - { - FILE *fp = fopen(client.getLogfile().c_str(),"at"); + if (client.getLogfile().size()) + { + FILE *fp = fopen(client.getLogfile().c_str(),"at"); - if (fp) - { - fprintf(fp,"log# %d:%s\n",level,line.c_str()); - fclose(fp); - } - } - } + if (fp) + { + fprintf(fp,"log# %d:%s\n",level,line.c_str()); + fclose(fp); + } + } + } }; -static DefaultServerIRCLogHandler defaultLogger; +static DefaultServerIRCLogHandler defaultLogger; - +//------------------------------------IRCServerConnectedClient----------------------------------------- IRCServerConnectedClient::IRCServerConnectedClient ( IRCServer *_server, TCPServerConnectedPeer* _peer ) { - peer = _peer; - clientID = peer->getUID(); - server = _server; + peer = _peer; + clientID = peer->getUID(); + server = _server; } IRCServerConnectedClient::~IRCServerConnectedClient() @@ -63,134 +64,232 @@ bool IRCServerConnectedClient::sendText ( const std::string &text ) { - if (!server) - return false; + if (!server) + return false; - return server->sendTextToPeer(text,peer); + return server->sendTextToPeer(text,peer); } +bool IRCServerConnectedClient::sendText ( const char *text ) +{ + if (!server || !text) + return false; + + return server->sendTextToPeer(std::string(text),peer); +} + std::string IRCServerConnectedClient::getHostMask ( void ) { - if (!peer) - return std::string(); + if (!peer) + return std::string(); - return peer->getHostMask(); + return peer->getHostMask(); } bool IRCServerConnectedClient::getIP ( unsigned char ip[4] ) { - if (!peer) - return false; + if (!peer) + return false; - return peer->getIP(ip); + return peer->getIP(ip); } +bool IRCServerConnectedClient::joinChannel ( const char* channel ) +{ + if (!channel) + return false; + + std::string chanName = string_util::toupper(std::string(channel)); + + if (std::find(channels.begin(),channels.end(),chanName) != channels.end()) + return false; + + channels.push_back(chanName); + return true; +} + +bool IRCServerConnectedClient::partChannel ( const char* channel ) +{ + if (!channel) + return false; + + std::string chanName = string_util::toupper(std::string(channel)); + + std::vector<std::string>::iterator itr = std::find(channels.begin(),channels.end(),chanName); + if ( itr == channels.end()) + return false; + + channels.erase(itr); + return true; +} + +//---------------------------IRCServerChannel-------------------------------------- +IRCServerChannel::IRCServerChannel( const char * _name ) +{ + if (_name) + name = _name; + + name = string_util::toupper(name); +} + +IRCServerChannel::~IRCServerChannel() +{ + MemberDataMap::iterator itr = members.begin(); + while (itr != members.end()) + deleteUserData((itr++)->second); +} + +void IRCServerChannel::addMember ( IRCServerConnectedClient *member ) +{ + MemberDataMap::iterator itr = members.find(member); + if (itr != members.end()) + return; + + members[member] = newUserData(); +} + +void IRCServerChannel::removeMember ( IRCServerConnectedClient *member ) +{ + MemberDataMap::iterator itr = members.find(member); + if (itr == members.end()) + return; + + deleteUserData(itr->second); + members.erase(itr); +} + +bool IRCServerChannel::sendText ( const std::string &text ) +{ + if (!text.size()) + return false; + + // format the command here so it's FROM the channel + + + MemberDataMap::iterator itr = members.begin(); + while (itr != members.end()) + { + itr->first->sendText(text); + itr++; + } + return true; +} + +bool IRCServerChannel::sendText ( const char*text ) +{ + if (!text) + return false; + + return sendText(std::string(text)); +} + + +//---------------------------IRCServer-------------------------------------- IRCServer::IRCServer() :tcpConnection(TCPConnection::instance()) { - tcpServer = NULL; + tcpServer = NULL; - debugLogLevel = 0; - logHandler = &defaultLogger; + debugLogLevel = 0; + logHandler = &defaultLogger; - ircMessageTerminator = "\r\n"; - ircCommandDelimator = " "; + ircMessageTerminator = "\r\n"; + ircCommandDelimator = " "; - minCycleTime = 0.1f; + minCycleTime = 0.1f; } IRCServer::~IRCServer() { + disconnect(std::string("deconstruction")); } -std::vector<IRCServerConnectedClient>::iterator IRCServer::getClientItr ( IRCServerConnectedClient *client ) +IRCServer::ClientList::iterator IRCServer::getClientItr ( IRCServerConnectedClient *client ) { - std::vector<IRCServerConnectedClient>::iterator itr = clients.begin(); - while ( itr != clients.end() ) - { if ( &(*itr) == client ) - return itr; - itr++; - } - - return clients.end(); + return std::find(clients.begin(), clients.end(),client); } void IRCServer::setLogHandler ( IRCServerLogHandler * logger ) { - if (!logger) - logHandler = &defaultLogger; - else - logHandler = logger; + if (!logger) + logHandler = &defaultLogger; + else + logHandler = logger; } void IRCServer::setLogfile ( std::string file ) { - logfile = file; + logfile = file; } std::string IRCServer::getLogfile ( void ) { - return logfile; + return logfile; } void IRCServer::setDebugLevel ( int level ) { - debugLogLevel = level; + debugLogLevel = level; } int IRCServer::getDebugLevel ( void ) { - return debugLogLevel; + return debugLogLevel; } bool IRCServer::listen ( int maxConnections, int port ) { - if (tcpServer) - { - tcpServer->disconnect(); - tcpConnection.deleteServerConnection(tcpServer); - } + if (tcpServer) + { + tcpServer->disconnect(); + tcpConnection.deleteServerConnection(tcpServer); + } - if (maxConnections < 0) - maxConnections = 128; + if (maxConnections < 0) + maxConnections = 128; - ircServerPort = _DEFAULT_IRC_PORT; - if ( port > 0 ) - ircServerPort = (unsigned short)port; + ircServerPort = _DEFAULT_IRC_PORT; + if ( port > 0 ) + ircServerPort = (unsigned short)port; - tcpServer = tcpConnection.newServerConnection(ircServerPort,maxConnections); - tcpServer->addListener(this); + tcpServer = tcpConnection.newServerConnection(ircServerPort,maxConnections); + tcpServer->addListener(this); - return tcpServer->getLastError() == eTCPNoError; + return tcpServer->getLastError() == eTCPNoError; } bool IRCServer::disconnect ( std::string reason ) { - if (tcpServer) - { - tcpServer->disconnect(); - tcpConnection.deleteServerConnection(tcpServer); - tcpServer = NULL; - return true; - } + if (tcpServer) + { + tcpServer->disconnect(); + tcpConnection.deleteServerConnection(tcpServer); + tcpServer = NULL; - return false; + for (unsigned int i = 0; i < (unsigned int)clients.size(); i++ ) + deleteClient(clients[i]); + + clients.clear(); + return true; + } + + return false; } bool IRCServer::process ( void ) { - return tcpConnection.update() == eTCPNoError; + return tcpConnection.update() == eTCPNoError; } void IRCServer::log ( std::string text, int level ) { - if (level <= debugLogLevel && logHandler) - logHandler->log(*this,level,text); + if (level <= debugLogLevel && logHandler) + logHandler->log(*this,level,text); } void IRCServer::log ( const char *text, int level ) { - log(std::string(text),level); + log(std::string(text),level); } void IRCServer::processIRCLine ( std::string line, IRCServerConnectedClient *client ) @@ -200,117 +299,121 @@ bool IRCServer::sendTextToPeer ( const std::string &text, TCPServerConnectedPeer *peer ) { - if (!peer || !tcpServer->listening()) - return false; + if (!peer || !tcpServer->listening()) + return false; - std::string message = text; - if (text.size()) - { - message += ircMessageTerminator; - teTCPError error = peer->sendData(message); - if (error == eTCPNoError) - log("Send Data:" + text,2); - else - { - switch (error) - { - case eTCPNotInit: - log("Send Data Error: TCP Not Initalised: data=" + text,0); - break; + std::string message = text; + if (text.size()) + { + message += ircMessageTerminator; + teTCPError error = peer->sendData(message); + if (error == eTCPNoError) + log("Send Data:" + text,2); + else + { + switch (error) + { + case eTCPNotInit: + log("Send Data Error: TCP Not Initalised: data=" + text,0); + break; - case eTCPSocketNFG: - log("Send Data Error: Bad Socket: data=" + text,0); - break; + case eTCPSocketNFG: + log("Send Data Error: Bad Socket: data=" + text,0); + break; - case eTCPDataNFG: - log("Send Data Error: Bad Data",0); - break; + case eTCPDataNFG: + log("Send Data Error: Bad Data",0); + break; - case eTCPConnectionFailed: - log("Send Data Error: TCP Connection failed",0); - break; + case eTCPConnectionFailed: + log("Send Data Error: TCP Connection failed",0); + break; - default: - log("Send Data Error:Unknown Error",0); - } - return false; - } - } - else - return false; + default: + log("Send Data Error:Unknown Error",0); + } + return false; + } + } + else + return false; - // prevent that thar flooding - IRCOSSleep(minCycleTime); - return true; + // prevent that thar flooding + IRCOSSleep(minCycleTime); + return true; } bool IRCServer::connect ( TCPServerConnection *connection, TCPServerConnectedPeer *peer ) { - if (!connection || !peer) - return false; - unsigned char ip[4]; - peer->getIP(ip); + if (!connection || !peer) + return false; - if (!allowConnection(peer->getHostMask().c_str(),ip)) - return false; + unsigned char ip[4]; + peer->getIP(ip); - unsigned int index = (unsigned int )clients.size(); - IRCServerConnectedClient client(this,peer); + if (!allowConnection(peer->getHostMask().c_str(),ip)) + return false; - clients.push_back(client); - peer->setParam(&clients[index]); + unsigned int index = (unsigned int )clients.size(); + IRCServerConnectedClient* client = newClient(this,peer); - clientConnect(&clients[index]); + clients.push_back(client); + peer->setParam(clients[index]); - return true; + clientConnect(clients[index]); + + return true; } void IRCServer::pending ( TCPServerConnection *connection, TCPServerConnectedPeer *peer, unsigned int count ) { - IRCServerConnectedClient* client = (IRCServerConnectedClient*)peer->getParam(); - if (!client) // somehow out of band connection, screw it - return; + IRCServerConnectedClient* client = (IRCServerConnectedClient*)peer->getParam(); + if (!client) // somehow out of band connection, screw it + return; - tvPacketList &packets = peer->getPackets(); - std::string theLine = client->lastData; + tvPacketList &packets = peer->getPackets(); + std::string theLine = client->lastData; - for ( unsigned int p = 0; p < packets.size(); p++ ) - { - TCPPacket &packet = packets[p]; + for ( unsigned int p = 0; p < packets.size(); p++ ) + { + TCPPacket &packet = packets[p]; - unsigned int size; - unsigned char* data = packet.get(size); + unsigned int size; + unsigned char* data = packet.get(size); - for ( unsigned int i = 0; i < size; i++ ) - { - if ( data[i] != 13 ) - theLine += data[i]; - else - { - processIRCLine(theLine,client); - theLine = ""; - } - } - } + for ( unsigned int i = 0; i < size; i++ ) + { + if ( data[i] != 13 ) + theLine += data[i]; + else + { + processIRCLine(theLine,client); + theLine = ""; + } + } + } - client->lastData = theLine; - peer->flushPackets(); + client->lastData = theLine; + peer->flushPackets(); } void IRCServer::disconnect ( TCPServerConnection *connection, TCPServerConnectedPeer *peer, bool forced ) { - IRCServerConnectedClient* client = (IRCServerConnectedClient*)peer->getParam(); - if (!client) // somehow out of band connection, screw it - return; + IRCServerConnectedClient* client = (IRCServerConnectedClient*)peer->getParam(); + if (!client) // somehow out of band connection, screw it + return; - clientDisconnect(client); + clientDisconnect(client); - std::vector<IRCServerConnectedClient>::iterator clientItr = getClientItr(client); - if (clientItr != clients.end()) - clients.erase(clientItr); + ClientList::iterator clientItr = getClientItr(client); + if (clientItr != clients.end()) + clients.erase(clientItr); + + deleteClient(client); } // base IRC event handlers + void IRCServer::clientConnect ( IRCServerConnectedClient *client ) { } @@ -321,7 +424,7 @@ bool IRCServer::allowConnection ( const char* hostmask, unsigned char ip[4] ) { - return true; + return true; } void IRCServer::clientIRCCommand ( const std::string &command, IRCServerConnectedClient *client ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Jef...@us...> - 2007-10-09 20:31:30
|
Revision: 247 http://libirc.svn.sourceforge.net/libirc/?rev=247&view=rev Author: JeffM2501 Date: 2007-10-09 13:31:25 -0700 (Tue, 09 Oct 2007) Log Message: ----------- make event data structures all be called client data structures so they don't conflict with server event data. Modified Paths: -------------- trunk/libirc/include/IRCClient.h trunk/libirc/include/IRCEvents.h trunk/libirc/include/IRCServer.h trunk/libirc/include/libIRC.h trunk/libirc/src/IRCClient.cpp trunk/libirc/src/IRCServer.cpp trunk/libirc/src/irClientCommands.cpp trunk/libirc/src/irClientEvents.cpp trunk/libirc/src/ircBasicCommands.cpp Modified: trunk/libirc/include/IRCClient.h =================================================================== --- trunk/libirc/include/IRCClient.h 2007-10-09 18:48:16 UTC (rev 246) +++ trunk/libirc/include/IRCClient.h 2007-10-09 20:31:25 UTC (rev 247) @@ -174,11 +174,11 @@ // command sending and receving methods called by handlers virtual bool sendCommand ( std::string &commandName, BaseIRCCommandInfo &info ); - virtual bool sendIRCCommand ( teIRCCommands command, IRCCommandINfo &info ); + virtual bool sendIRCCommand ( teIRCCommands command, IRCCommandInfo &info ); virtual bool sendCTMPCommand ( teCTCPCommands command, CTCPCommandINfo &info ); virtual bool receveCommand ( std::string &commandName, BaseIRCCommandInfo &info ); - virtual bool receveIRCCommand ( teIRCCommands command, IRCCommandINfo &info ); + virtual bool receveIRCCommand ( teIRCCommands command, IRCCommandInfo &info ); virtual bool receveCTMPCommand ( teCTCPCommands command, CTCPCommandINfo &info ); // -------------------------------------------------------------------------------------- @@ -206,8 +206,8 @@ std::string getNick ( void ) {return nickname;} // used by the raw IRC command Handlers to update internal states and trigger events - void noticeMessage ( trMessageEventInfo &info ); - void welcomeMessage ( trMessageEventInfo &info ); + void noticeMessage ( trClientMessageEventInfo &info ); + void welcomeMessage ( trClientMessageEventInfo &info ); void beginMOTD ( void ){MOTD = "";} void addMOTD ( std::string line ) {MOTD += line + std::string("\n");} void endMOTD ( void ); Modified: trunk/libirc/include/IRCEvents.h =================================================================== --- trunk/libirc/include/IRCEvents.h 2007-10-09 18:48:16 UTC (rev 246) +++ trunk/libirc/include/IRCEvents.h 2007-10-09 20:31:25 UTC (rev 247) @@ -20,6 +20,7 @@ #include "IRCTextUtils.h" class IRCClient; +class IRCServerConnectedClient; typedef enum { @@ -55,55 +56,62 @@ teIRCEventType eventType; }trBaseEventInfo; +// basic structiure that all server events are based on +// events with no data use this +typedef struct trBaseServerEventInfo : public trBaseEventInfo +{ + IRCServerConnectedClient *client; +}trBaseServerEventInfo; + // nickname error type events, used for eIRCNickNameError -typedef struct trNickErrorEventInfo : public trBaseEventInfo +typedef struct trClientNickErrorEventInfo : public trBaseEventInfo { int error; std::string message; -}trNickErrorEventInfo; +}trClientNickErrorEventInfo; // join type evetns, used for eIRCChannelJoinEvent, eIRCUserJoinEvent -typedef struct trJoinEventInfo : public trBaseEventInfo +typedef struct trClientJoinEventInfo : public trBaseEventInfo { std::string channel; std::string user; -}trJoinEventInfo; +}trClientJoinEventInfo; // mode type evetns, used for eIRCUserModeSet,eIRCChannelModeSet,eIRCChannelUserModeSet -typedef struct trModeEventInfo : public trBaseEventInfo +typedef struct trClientModeEventInfo : public trBaseEventInfo { std::string target; std::string from; std::string mode; std::string message; -}trModeEventInfo; +}trClientModeEventInfo; // nick change type evetns, used for eIRCNickNameChange -typedef struct trNickChangeEventInfo : public trBaseEventInfo +typedef struct trClientNickChangeEventInfo : public trBaseEventInfo { std::string oldname; std::string newName; -}trNickChangeEventInfo; +}trClientNickChangeEventInfo; // part type evetns, used for eIRCChannelPartEvent, eIRCUserPartEvent, eIRCQuitEvetnt -typedef struct trPartEventInfo : public trBaseEventInfo +typedef struct trClientPartEventInfo : public trBaseEventInfo { std::string channel; std::string user; std::string reason; -}trPartEventInfo; +}trClientPartEventInfo; // kick and ban type events , used for eIRCChannelKickEvent,eIRCChannelBanEvent, eIRCUserPartEvent -typedef struct trKickBanEventInfo : public trBaseEventInfo +typedef struct trClientKickBanEventInfo : public trBaseEventInfo { std::string channel; std::string user; std::string reason; std::string kicker; -}trKickBanEventInfo; +}trClientKickBanEventInfo; // message events, used for eIRCChannelMessageEvent, eIRCPrivateMessageEvent, eIRCNoticeEvent, eIRCWelcomeEvent, eIRCTopicChangeEvent -typedef struct trMessageEventInfo : public trBaseEventInfo +typedef struct trClientMessageEventInfo : public trBaseEventInfo { std::string target; std::string source; @@ -112,7 +120,7 @@ std::vector<std::string> params; std::string getAsString ( int start = 0, int end = -1 ) {return string_util::getStringFromList(params," ",start,end);} -}trMessageEventInfo; +}trClientMessageEventInfo; class IRCBasicEventCallback { Modified: trunk/libirc/include/IRCServer.h =================================================================== --- trunk/libirc/include/IRCServer.h 2007-10-09 18:48:16 UTC (rev 246) +++ trunk/libirc/include/IRCServer.h 2007-10-09 20:31:25 UTC (rev 247) @@ -137,8 +137,9 @@ virtual bool allowConnection ( const char* hostmask, unsigned char ip[4] ); virtual void clientConnect ( IRCServerConnectedClient *client ); virtual void clientDisconnect ( IRCServerConnectedClient *client ); - virtual void clientIRCCommand ( const std::string &command, IRCServerConnectedClient *client ); + virtual void clientIRCCommand ( const BaseIRCCommandInfo &command, IRCServerConnectedClient *client ); + IRCServerChannel *getChannel ( const char *name ); IRCServerChannel *getChannel ( const std::string& name ); Modified: trunk/libirc/include/libIRC.h =================================================================== --- trunk/libirc/include/libIRC.h 2007-10-09 18:48:16 UTC (rev 246) +++ trunk/libirc/include/libIRC.h 2007-10-09 20:31:25 UTC (rev 247) @@ -21,6 +21,7 @@ #ifndef string_list typedef std::vector<std::string> string_list; +#endif // IRC includes #include "ircCommands.h" @@ -28,9 +29,6 @@ #include "IRCUserManager.h" #include "TCPConnection.h" -#endif - - #define _DEFAULT_IRC_PORT 6667 // simple OS indpendent sleep function @@ -74,7 +72,7 @@ }; // a normal Internet Relay Chat command -class IRCCommandINfo : public BaseIRCCommandInfo +class IRCCommandInfo : public BaseIRCCommandInfo { public: teIRCCommands ircCommand; Modified: trunk/libirc/src/IRCClient.cpp =================================================================== --- trunk/libirc/src/IRCClient.cpp 2007-10-09 18:48:16 UTC (rev 246) +++ trunk/libirc/src/IRCClient.cpp 2007-10-09 20:31:25 UTC (rev 247) @@ -135,7 +135,7 @@ if (!reason.size()) reason = "shuting down"; - IRCCommandINfo info; + IRCCommandInfo info; info.params.push_back(reason); if (!sendIRCCommand(eCMD_QUIT,info)) @@ -390,7 +390,7 @@ return false; } -bool IRCClient::sendIRCCommand ( teIRCCommands command, IRCCommandINfo &info ) +bool IRCClient::sendIRCCommand ( teIRCCommands command, IRCCommandInfo &info ) { info.type = eIRCCommand; info.ircCommand = command; @@ -441,7 +441,7 @@ return false; } -bool IRCClient::receveIRCCommand ( teIRCCommands command, IRCCommandINfo &info ) +bool IRCClient::receveIRCCommand ( teIRCCommands command, IRCCommandInfo &info ) { info.type = eIRCCommand; info.ircCommand = command; @@ -728,7 +728,7 @@ // atempt to keep adding crap to the nick till it goes requestedNick += '_'; - IRCCommandINfo info; + IRCCommandInfo info; info.params.push_back(requestedNick); if (!sendIRCCommand(eCMD_NICK,info)) Modified: trunk/libirc/src/IRCServer.cpp =================================================================== --- trunk/libirc/src/IRCServer.cpp 2007-10-09 18:48:16 UTC (rev 246) +++ trunk/libirc/src/IRCServer.cpp 2007-10-09 20:31:25 UTC (rev 247) @@ -297,7 +297,20 @@ void IRCServer::processIRCLine ( std::string line, IRCServerConnectedClient *client ) { + // we have a single line of text, do something with it. + // see if it's a command, and or call any handlers that we have + // also check for error returns + // right now we don't know if it's an IRC or CTCP command so just go with the generic one + // let the command parse it out into paramaters and find the command + BaseIRCCommandInfo commandInfo; + commandInfo.parse(line); + std::string handler; + + //if (!commandInfo.prefixed) + // commandInfo.source = getServerHost(); + + clientIRCCommand(commandInfo,client); } bool IRCServer::sendTextToPeer ( const std::string &text, TCPServerConnectedPeer *peer ) @@ -430,7 +443,7 @@ return true; } -void IRCServer::clientIRCCommand ( const std::string &command, IRCServerConnectedClient *client ) +void IRCServer::clientIRCCommand ( const BaseIRCCommandInfo &command, IRCServerConnectedClient *client ) { } Modified: trunk/libirc/src/irClientCommands.cpp =================================================================== --- trunk/libirc/src/irClientCommands.cpp 2007-10-09 18:48:16 UTC (rev 246) +++ trunk/libirc/src/irClientCommands.cpp 2007-10-09 20:31:25 UTC (rev 247) @@ -40,7 +40,7 @@ requestedNick = nick; - IRCCommandINfo info; + IRCCommandInfo info; info.params.push_back(nick); if (!sendIRCCommand(eCMD_NICK,info)) @@ -71,7 +71,7 @@ { requestedNick = nick; - IRCCommandINfo info; + IRCCommandInfo info; info.params.push_back(nick); if (!sendIRCCommand(eCMD_NICK,info)) @@ -89,7 +89,7 @@ if (getConnectionState() < eSentNickAndUSer) return false; - IRCCommandINfo info; + IRCCommandInfo info; info.target = channel; if (!sendIRCCommand(eCMD_JOIN,info)) { @@ -112,7 +112,7 @@ if (getConnectionState() < eSentNickAndUSer) return false; - IRCCommandINfo info; + IRCCommandInfo info; info.target = channel; info.params.push_back(reason); @@ -126,7 +126,7 @@ std::string nick = getNick(); userManager.userPartChannel(nick, channel); - trPartEventInfo eventInfo; + trClientPartEventInfo eventInfo; eventInfo.eventType = eIRCChannelPartEvent; eventInfo.reason = reason; @@ -163,7 +163,7 @@ std::string message = messageHeader+*itr+messageFooter; int len = (int)message.size(); - IRCCommandINfo commandInfo; + IRCCommandInfo commandInfo; commandInfo.target = target; commandInfo.params.clear(); commandInfo.params.push_back(message); @@ -175,24 +175,24 @@ bool IRCClient::sendCTCPRequest ( std::string target, teCTCPCommands command, std::string &data) { - std::string message = CMD_PRIVMSG; - message += " " + target + " :"; - message += CTCP_DELIMITER + ctcpCommandParser.getCommandName(command); - if (data != "") - message += " " + data; - message += CTCP_DELIMITER; - return sendTextToServer(message); + std::string message = CMD_PRIVMSG; + message += " " + target + " :"; + message += CTCP_DELIMITER + ctcpCommandParser.getCommandName(command); + if (data != "") + message += " " + data; + message += CTCP_DELIMITER; + return sendTextToServer(message); } bool IRCClient::sendCTCPReply ( std::string target, teCTCPCommands command, std::string &data) { - std::string message = CMD_NOTICE; - message += " " + target + " :"; - message += CTCP_DELIMITER + ctcpCommandParser.getCommandName(command); - if (data != "") - message += " " + data; - message += CTCP_DELIMITER; - return sendTextToServer(message); + std::string message = CMD_NOTICE; + message += " " + target + " :"; + message += CTCP_DELIMITER + ctcpCommandParser.getCommandName(command); + if (data != "") + message += " " + data; + message += CTCP_DELIMITER; + return sendTextToServer(message); } bool IRCClient::kick ( std::string user, std::string channel, std::string reason ) @@ -204,7 +204,7 @@ if (!userManager.userInChannel(user,channel)) return false; - IRCCommandINfo info; + IRCCommandInfo info; info.target = channel; info.params.push_back(user); info.params.push_back(reason); @@ -234,7 +234,7 @@ if (getConnectionState() < eSentNickAndUSer) return false; - IRCCommandINfo info; + IRCCommandInfo info; info.target = target; info.params.push_back(theMode); if (option.size()) Modified: trunk/libirc/src/irClientEvents.cpp =================================================================== --- trunk/libirc/src/irClientEvents.cpp 2007-10-09 18:48:16 UTC (rev 246) +++ trunk/libirc/src/irClientEvents.cpp 2007-10-09 20:31:25 UTC (rev 247) @@ -21,7 +21,7 @@ // event trigers from low level messages // this way the low level events don't need the logic for the high level events. -void IRCClient::noticeMessage ( trMessageEventInfo &info ) +void IRCClient::noticeMessage ( trClientMessageEventInfo &info ) { if (info.params[1] == "Looking") { @@ -32,7 +32,7 @@ } } -void IRCClient::welcomeMessage ( trMessageEventInfo &info ) +void IRCClient::welcomeMessage ( trClientMessageEventInfo &info ) { setNick(info.target); requestedNick = info.target; @@ -63,7 +63,7 @@ userManager.userJoinChannel(who,info.target); - trJoinEventInfo joinInfo; + trClientJoinEventInfo joinInfo; joinInfo.eventType = who == getNick() ? eIRCChannelJoinEvent : eIRCUserJoinEvent; joinInfo.channel = info.target; @@ -77,7 +77,7 @@ std::string who = goodies[0]; - trPartEventInfo partInfo; + trClientPartEventInfo partInfo; userManager.userPartChannel(who,info.target); if (who == getNick()) @@ -94,7 +94,7 @@ { userManager.modeReceved(channel,reportedServerHost,mode); - trModeEventInfo info; + trClientModeEventInfo info; info.eventType = eIRCChannelModeSet; info.target = channel; info.from = reportedServerHost; @@ -106,7 +106,7 @@ { userManager.topicReceved(channel,topic,true); - trMessageEventInfo info; + trClientMessageEventInfo info; info.eventType = eIRCTopicChangeEvent; info.target = channel; info.source = source; @@ -118,10 +118,10 @@ { std::string who = info.target; - trModeEventInfo modeInfo; + trClientModeEventInfo modeInfo; modeInfo.eventType = eIRCNULLEvent; - trKickBanEventInfo banInfo; + trClientKickBanEventInfo banInfo; banInfo.eventType = eIRCNULLEvent; modeInfo.target = who; @@ -196,7 +196,7 @@ void IRCClient::privMessage ( BaseIRCCommandInfo &info ) { - trMessageEventInfo msgInfo; + trClientMessageEventInfo msgInfo; msgInfo.source = info.source; msgInfo.target = info.target; msgInfo.message = info.getAsString(); @@ -220,7 +220,7 @@ void IRCClient::nickNameError ( int error, std::string message ) { - trNickErrorEventInfo info; + trClientNickErrorEventInfo info; info.error = error; if (getConnectionState() < eLoggedIn) @@ -239,7 +239,7 @@ userManager.nickChange(who,info.target); - trNickChangeEventInfo eventInfo; + trClientNickChangeEventInfo eventInfo; eventInfo.eventType = eIRCNickNameChange; eventInfo.oldname = who; eventInfo.newName = info.target; @@ -248,7 +248,7 @@ void IRCClient::kickCommand ( BaseIRCCommandInfo &info ) { - trKickBanEventInfo eventInfo; + trClientKickBanEventInfo eventInfo; eventInfo.eventType = eIRCUserKickedEvent; eventInfo.channel = info.target; @@ -269,7 +269,7 @@ std::string who = goodies[0]; - trPartEventInfo partInfo; + trClientPartEventInfo partInfo; userManager.userPartChannel(who,info.target); if (who == getNick()) Modified: trunk/libirc/src/ircBasicCommands.cpp =================================================================== --- trunk/libirc/src/ircBasicCommands.cpp 2007-10-09 18:48:16 UTC (rev 246) +++ trunk/libirc/src/ircBasicCommands.cpp 2007-10-09 20:31:25 UTC (rev 247) @@ -33,7 +33,7 @@ bool IRCNickCommand::send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) { - IRCCommandINfo &ircInfo = (IRCCommandINfo&)info; + IRCCommandInfo &ircInfo = (IRCCommandInfo&)info; std::string commandLine; @@ -58,7 +58,7 @@ bool IRCUserCommand::send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) { - IRCCommandINfo &ircInfo = (IRCCommandINfo&)info; + IRCCommandInfo &ircInfo = (IRCCommandInfo&)info; std::string commandLine; @@ -77,7 +77,7 @@ bool IRCPingCommand::receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) { - IRCCommandINfo ircInfo; + IRCCommandInfo ircInfo; ircInfo.command = eCMD_PONG; client.sendIRCCommand(eCMD_PONG,ircInfo); return true; @@ -85,7 +85,7 @@ bool IRCPingCommand::send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) { - IRCCommandINfo &ircInfo = (IRCCommandINfo&)info; + IRCCommandInfo &ircInfo = (IRCCommandInfo&)info; std::string commandLine; // PING @@ -107,7 +107,7 @@ bool IRCPongCommand::send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) { - IRCCommandINfo &ircInfo = (IRCCommandINfo&)info; + IRCCommandInfo &ircInfo = (IRCCommandInfo&)info; std::string commandLine; // PING @@ -123,7 +123,7 @@ bool IRCNoticeCommand::receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) { - trMessageEventInfo messageInfo; + trClientMessageEventInfo messageInfo; messageInfo.eventType = eIRCNoticeEvent; messageInfo.source = info.source; @@ -267,7 +267,7 @@ bool IRCPrivMsgCommand::send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) { - IRCCommandINfo &ircInfo = (IRCCommandINfo&)info; + IRCCommandInfo &ircInfo = (IRCCommandInfo&)info; std::string commandLine; ircInfo.target = @@ -292,7 +292,7 @@ bool IRCKickCommand::send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) { - IRCCommandINfo &ircInfo = (IRCCommandINfo&)info; + IRCCommandInfo &ircInfo = (IRCCommandInfo&)info; std::string commandLine; @@ -346,7 +346,7 @@ case RPL_WELCOME:// "Welcome to the Internet Relay Network <nick>!<user>@<host>" { - trMessageEventInfo messageInfo; + trClientMessageEventInfo messageInfo; messageInfo.eventType = eIRCNoticeEvent; messageInfo.target = info.target; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Jef...@us...> - 2007-10-09 20:44:17
|
Revision: 251 http://libirc.svn.sourceforge.net/libirc/?rev=251&view=rev Author: JeffM2501 Date: 2007-10-09 13:44:09 -0700 (Tue, 09 Oct 2007) Log Message: ----------- caps consistency Modified Paths: -------------- trunk/libirc/include/IRCClient.h trunk/libirc/src/IRCClient.cpp Modified: trunk/libirc/include/IRCClient.h =================================================================== --- trunk/libirc/include/IRCClient.h 2007-10-09 20:37:50 UTC (rev 250) +++ trunk/libirc/include/IRCClient.h 2007-10-09 20:44:09 UTC (rev 251) @@ -279,9 +279,9 @@ tmCommandHandlerMap defaultCommandHandlers; tmUserCommandHandlersMap userCommandHandlers; - void addDefaultCommandhandlers ( IRCClientCommandHandler* handler ); - void clearDefaultCommandhandlers ( void ); - void registerDefaultCommandhandlers ( void ); + void addDefaultCommandHandlers ( IRCClientCommandHandler* handler ); + void clearDefaultCommandHandlers ( void ); + void registerDefaultCommandHandlers ( void ); // event handlers tmIRCEventMap defaultEventHandlers; Modified: trunk/libirc/src/IRCClient.cpp =================================================================== --- trunk/libirc/src/IRCClient.cpp 2007-10-09 20:37:50 UTC (rev 250) +++ trunk/libirc/src/IRCClient.cpp 2007-10-09 20:44:09 UTC (rev 251) @@ -56,7 +56,7 @@ { netHandler = h; tcpClient = NULL; - registerDefaultCommandhandlers(); + registerDefaultCommandHandlers(); init(); ircMessageTerminator = "\r\n"; @@ -527,12 +527,12 @@ return (int)commandList.size(); } -void IRCClient::addDefaultCommandhandlers ( IRCClientCommandHandler* handler ) +void IRCClient::addDefaultCommandHandlers ( IRCClientCommandHandler* handler ) { defaultCommandHandlers[handler->getCommandName()] = handler; } -void IRCClient::clearDefaultCommandhandlers ( void ) +void IRCClient::clearDefaultCommandHandlers ( void ) { tmCommandHandlerMap::iterator itr = defaultCommandHandlers.begin(); @@ -544,29 +544,29 @@ defaultCommandHandlers.clear(); } -void IRCClient::registerDefaultCommandhandlers ( void ) +void IRCClient::registerDefaultCommandHandlers ( void ) { registerDefaultEventHandlers(); userCommandHandlers.clear(); - clearDefaultCommandhandlers(); + clearDefaultCommandHandlers(); // the "special" handlers - addDefaultCommandhandlers(new IRCALLCommand ); - addDefaultCommandhandlers(new IRCNumericCommand ); + addDefaultCommandHandlers(new IRCALLCommand ); + addDefaultCommandHandlers(new IRCNumericCommand ); // basic IRC commands - addDefaultCommandhandlers(new IRCNickCommand ); - addDefaultCommandhandlers(new IRCUserCommand ); - addDefaultCommandhandlers(new IRCPingCommand ); - addDefaultCommandhandlers(new IRCPongCommand ); - addDefaultCommandhandlers(new IRCNoticeCommand ); - addDefaultCommandhandlers(new IRCJoinCommand ); - addDefaultCommandhandlers(new IRCPartCommand ); - addDefaultCommandhandlers(new IRCQuitCommand ); - addDefaultCommandhandlers(new IRCModeCommand ); - addDefaultCommandhandlers(new IRCPrivMsgCommand ); - addDefaultCommandhandlers(new IRCKickCommand ); + addDefaultCommandHandlers(new IRCNickCommand ); + addDefaultCommandHandlers(new IRCUserCommand ); + addDefaultCommandHandlers(new IRCPingCommand ); + addDefaultCommandHandlers(new IRCPongCommand ); + addDefaultCommandHandlers(new IRCNoticeCommand ); + addDefaultCommandHandlers(new IRCJoinCommand ); + addDefaultCommandHandlers(new IRCPartCommand ); + addDefaultCommandHandlers(new IRCQuitCommand ); + addDefaultCommandHandlers(new IRCModeCommand ); + addDefaultCommandHandlers(new IRCPrivMsgCommand ); + addDefaultCommandHandlers(new IRCKickCommand ); } // logical event handlers This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Jef...@us...> - 2007-10-09 21:15:10
|
Revision: 252 http://libirc.svn.sourceforge.net/libirc/?rev=252&view=rev Author: JeffM2501 Date: 2007-10-09 14:15:06 -0700 (Tue, 09 Oct 2007) Log Message: ----------- rename all the client specific command handlers to say client, so we don't conflict with the server ones that will be happening soon. Modified Paths: -------------- trunk/libirc/include/IRCClient.h trunk/libirc/include/IRCEvents.h trunk/libirc/src/IRCClient.cpp trunk/libirc/src/irClientCommands.cpp trunk/libirc/src/irClientEvents.cpp trunk/libirc/src/ircBasicCommands.cpp trunk/libirc/src/ircBasicCommands.h Modified: trunk/libirc/include/IRCClient.h =================================================================== --- trunk/libirc/include/IRCClient.h 2007-10-09 20:44:09 UTC (rev 251) +++ trunk/libirc/include/IRCClient.h 2007-10-09 21:15:06 UTC (rev 252) @@ -169,6 +169,7 @@ //command handler methods... for lower level API virtual bool registerCommandHandler ( IRCClientCommandHandler *handler ); virtual bool removeCommandHandler ( IRCClientCommandHandler *handler ); + virtual int listUserHandledCommands ( std::vector<std::string> &commandList ); virtual int listDefaultHandledCommands ( std::vector<std::string> &commandList ); @@ -307,3 +308,11 @@ }; #endif //_IRC_CLIENT_H_ + +// Local Variables: *** +// mode:C++ *** +// tab-width: 8 *** +// c-basic-offset: 2 *** +// indent-tabs-mode: t *** +// End: *** +// ex: shiftwidth=2 tabstop=8 Modified: trunk/libirc/include/IRCEvents.h =================================================================== --- trunk/libirc/include/IRCEvents.h 2007-10-09 20:44:09 UTC (rev 251) +++ trunk/libirc/include/IRCEvents.h 2007-10-09 21:15:06 UTC (rev 252) @@ -134,3 +134,10 @@ typedef std::map<teIRCEventType,IRCBasicEventCallback*> tmIRCEventMap; #endif // __IRC_EVENTS_H__ +// Local Variables: *** +// mode: C++ *** +// tab-width: 8 *** +// c-basic-offset: 2 *** +// indent-tabs-mode: t *** +// End: *** +// ex: shiftwidth=2 tabstop=8 Modified: trunk/libirc/src/IRCClient.cpp =================================================================== --- trunk/libirc/src/IRCClient.cpp 2007-10-09 20:44:09 UTC (rev 251) +++ trunk/libirc/src/IRCClient.cpp 2007-10-09 21:15:06 UTC (rev 252) @@ -552,21 +552,21 @@ clearDefaultCommandHandlers(); // the "special" handlers - addDefaultCommandHandlers(new IRCALLCommand ); - addDefaultCommandHandlers(new IRCNumericCommand ); + addDefaultCommandHandlers(new IRCClientALLCommand ); + addDefaultCommandHandlers(new IRCClientNumericCommand ); // basic IRC commands - addDefaultCommandHandlers(new IRCNickCommand ); - addDefaultCommandHandlers(new IRCUserCommand ); - addDefaultCommandHandlers(new IRCPingCommand ); - addDefaultCommandHandlers(new IRCPongCommand ); - addDefaultCommandHandlers(new IRCNoticeCommand ); - addDefaultCommandHandlers(new IRCJoinCommand ); - addDefaultCommandHandlers(new IRCPartCommand ); - addDefaultCommandHandlers(new IRCQuitCommand ); - addDefaultCommandHandlers(new IRCModeCommand ); - addDefaultCommandHandlers(new IRCPrivMsgCommand ); - addDefaultCommandHandlers(new IRCKickCommand ); + addDefaultCommandHandlers(new IRCClientNickCommand ); + addDefaultCommandHandlers(new IRCClientUserCommand ); + addDefaultCommandHandlers(new IRCClientPingCommand ); + addDefaultCommandHandlers(new IRCClientPongCommand ); + addDefaultCommandHandlers(new IRCClientNoticeCommand ); + addDefaultCommandHandlers(new IRCClientJoinCommand ); + addDefaultCommandHandlers(new IRCClientPartCommand ); + addDefaultCommandHandlers(new IRCClientQuitCommand ); + addDefaultCommandHandlers(new IRCClientModeCommand ); + addDefaultCommandHandlers(new IRCClientPrivMsgCommand ); + addDefaultCommandHandlers(new IRCClientKickCommand ); } // logical event handlers Modified: trunk/libirc/src/irClientCommands.cpp =================================================================== --- trunk/libirc/src/irClientCommands.cpp 2007-10-09 20:44:09 UTC (rev 251) +++ trunk/libirc/src/irClientCommands.cpp 2007-10-09 21:15:06 UTC (rev 252) @@ -356,4 +356,11 @@ } +// Local Variables: *** +// mode: C++ *** +// tab-width: 8 *** +// c-basic-offset: 2 *** +// indent-tabs-mode: t *** +// End: *** +// ex: shiftwidth=2 tabstop=8 Modified: trunk/libirc/src/irClientEvents.cpp =================================================================== --- trunk/libirc/src/irClientEvents.cpp 2007-10-09 20:44:09 UTC (rev 251) +++ trunk/libirc/src/irClientEvents.cpp 2007-10-09 21:15:06 UTC (rev 252) @@ -284,3 +284,10 @@ +// Local Variables: *** +// mode: C++ *** +// tab-width: 8 *** +// c-basic-offset: 2 *** +// indent-tabs-mode: t *** +// End: *** +// ex: shiftwidth=2 tabstop=8 Modified: trunk/libirc/src/ircBasicCommands.cpp =================================================================== --- trunk/libirc/src/ircBasicCommands.cpp 2007-10-09 20:44:09 UTC (rev 251) +++ trunk/libirc/src/ircBasicCommands.cpp 2007-10-09 21:15:06 UTC (rev 252) @@ -20,18 +20,18 @@ // IRC "NICK" command -IRCNickCommand::IRCNickCommand() +IRCClientNickCommand::IRCClientNickCommand() { name = "NICK"; } -bool IRCNickCommand::receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) +bool IRCClientNickCommand::receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) { client.nickCommand(info); return true; } -bool IRCNickCommand::send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) +bool IRCClientNickCommand::send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) { IRCCommandInfo &ircInfo = (IRCCommandInfo&)info; @@ -46,17 +46,17 @@ // IRC "USER" command -IRCUserCommand::IRCUserCommand() +IRCClientUserCommand::IRCClientUserCommand() { name = "USER"; } -bool IRCUserCommand::receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) +bool IRCClientUserCommand::receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) { return true; } -bool IRCUserCommand::send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) +bool IRCClientUserCommand::send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) { IRCCommandInfo &ircInfo = (IRCCommandInfo&)info; @@ -70,12 +70,12 @@ } // IRC "PING" command -IRCPingCommand::IRCPingCommand() +IRCClientPingCommand::IRCClientPingCommand() { name = "PING"; } -bool IRCPingCommand::receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) +bool IRCClientPingCommand::receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) { IRCCommandInfo ircInfo; ircInfo.command = eCMD_PONG; @@ -83,7 +83,7 @@ return true; } -bool IRCPingCommand::send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) +bool IRCClientPingCommand::send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) { IRCCommandInfo &ircInfo = (IRCCommandInfo&)info; @@ -94,18 +94,18 @@ } // IRC "PONG" command -IRCPongCommand::IRCPongCommand() +IRCClientPongCommand::IRCClientPongCommand() { name = "PONG"; } -bool IRCPongCommand::receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) +bool IRCClientPongCommand::receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) { // we do nothing on a pong return true; } -bool IRCPongCommand::send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) +bool IRCClientPongCommand::send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) { IRCCommandInfo &ircInfo = (IRCCommandInfo&)info; @@ -116,12 +116,12 @@ } // IRC "NOTICE" command -IRCNoticeCommand::IRCNoticeCommand() +IRCClientNoticeCommand::IRCClientNoticeCommand() { name = "NOTICE"; } -bool IRCNoticeCommand::receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) +bool IRCClientNoticeCommand::receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) { trClientMessageEventInfo messageInfo; @@ -133,25 +133,25 @@ return true; } -bool IRCNoticeCommand::send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) +bool IRCClientNoticeCommand::send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) { // we do nothing on a pong return true; } // IRC "JOIN" command -IRCJoinCommand::IRCJoinCommand() +IRCClientJoinCommand::IRCClientJoinCommand() { name = "JOIN"; } -bool IRCJoinCommand::receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) +bool IRCClientJoinCommand::receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) { client.joinMessage(info); return true; } -bool IRCJoinCommand::send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) +bool IRCClientJoinCommand::send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) { std::string commandLine; @@ -177,18 +177,18 @@ } // IRC "PART" command -IRCPartCommand::IRCPartCommand() +IRCClientPartCommand::IRCClientPartCommand() { name = "PART"; } -bool IRCPartCommand::receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) +bool IRCClientPartCommand::receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) { client.partMessage(info); return true; } -bool IRCPartCommand::send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) +bool IRCClientPartCommand::send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) { std::string commandLine; @@ -201,18 +201,18 @@ // IRC "QUIT" command -IRCQuitCommand::IRCQuitCommand() +IRCClientQuitCommand::IRCClientQuitCommand() { name = "QUIT"; } -bool IRCQuitCommand::receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) +bool IRCClientQuitCommand::receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) { client.QuitMessage(info); return true; } -bool IRCQuitCommand::send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) +bool IRCClientQuitCommand::send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) { std::string commandLine; @@ -225,19 +225,19 @@ } // IRC "MODE" command -IRCModeCommand::IRCModeCommand() +IRCClientModeCommand::IRCClientModeCommand() { name = "MODE"; } -bool IRCModeCommand::receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) +bool IRCClientModeCommand::receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) { // we got a mode message, see what the deal is client.modeCommand(info); return true; } -bool IRCModeCommand::send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) +bool IRCClientModeCommand::send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) { // MODE TARGET modes std::string modeline = info.target; @@ -254,18 +254,18 @@ } // IRC "PRIVMSG" command -IRCPrivMsgCommand::IRCPrivMsgCommand() +IRCClientPrivMsgCommand::IRCClientPrivMsgCommand() { name = "PRIVMSG"; } -bool IRCPrivMsgCommand::receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) +bool IRCClientPrivMsgCommand::receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) { client.privMessage(info); return true; } -bool IRCPrivMsgCommand::send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) +bool IRCClientPrivMsgCommand::send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) { IRCCommandInfo &ircInfo = (IRCCommandInfo&)info; @@ -279,18 +279,18 @@ // IRC "KICK" command -IRCKickCommand::IRCKickCommand() +IRCClientKickCommand::IRCClientKickCommand() { name = "KICK"; } -bool IRCKickCommand::receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) +bool IRCClientKickCommand::receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) { client.kickCommand(info); return true; } -bool IRCKickCommand::send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) +bool IRCClientKickCommand::send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) { IRCCommandInfo &ircInfo = (IRCCommandInfo&)info; @@ -306,12 +306,12 @@ // special case commands // Generic handler for ALL -IRCALLCommand::IRCALLCommand() +IRCClientALLCommand::IRCClientALLCommand() { name = "ALL"; } -bool IRCALLCommand::receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) +bool IRCClientALLCommand::receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) { // just log it out client.log(string_util::format("ALL::command %s from %s for %s containing %s",info.command.c_str(),info.source.c_str(),info.target.c_str(),info.getAsString().c_str()),4); @@ -320,7 +320,7 @@ return true; } -bool IRCALLCommand::send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) +bool IRCClientALLCommand::send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) { // just log it out client.log(string_util::format("ALL::command %s: to server containing %s",command.c_str(),info.getAsString().c_str()),4); @@ -329,12 +329,12 @@ // numerics -IRCNumericCommand::IRCNumericCommand() +IRCClientNumericCommand::IRCClientNumericCommand() { name = "NUMERIC"; } -bool IRCNumericCommand::receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) +bool IRCClientNumericCommand::receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) { int numeric = atoi(info.command.c_str()); @@ -572,5 +572,12 @@ return true; } +// Local Variables: *** +// mode: C++ *** +// tab-width: 8 *** +// c-basic-offset: 2 *** +// indent-tabs-mode: t *** +// End: *** +// ex: shiftwidth=2 tabstop=8 Modified: trunk/libirc/src/ircBasicCommands.h =================================================================== --- trunk/libirc/src/ircBasicCommands.h 2007-10-09 20:44:09 UTC (rev 251) +++ trunk/libirc/src/ircBasicCommands.h 2007-10-09 21:15:06 UTC (rev 252) @@ -19,19 +19,19 @@ // special case commands // handles ALL posible messages, dosn't actualy DO anythign with them tho -class IRCALLCommand : public IRCClientCommandHandler +class IRCClientALLCommand : public IRCClientCommandHandler { public: - IRCALLCommand(); + IRCClientALLCommand(); virtual bool receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ); virtual bool send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ); }; // numerics, handles any IRC numeric return code -class IRCNumericCommand : public IRCClientCommandHandler +class IRCClientNumericCommand : public IRCClientCommandHandler { public: - IRCNumericCommand(); + IRCClientNumericCommand(); virtual bool receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ); }; @@ -39,115 +39,120 @@ // IRC "NICK" command // paramaters {NICKNAME} -class IRCNickCommand : public IRCClientCommandHandler +class IRCClientNickCommand : public IRCClientCommandHandler { public: - IRCNickCommand(); + IRCClientNickCommand(); virtual bool receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ); virtual bool send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ); }; // IRC "USER" command // paramaters {USERNAME, HOST, SERVER, REAL_NAME} -class IRCUserCommand : public IRCClientCommandHandler +class IRCClientUserCommand : public IRCClientCommandHandler { public: - IRCUserCommand(); + IRCClientUserCommand(); virtual bool receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ); virtual bool send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ); }; // IRC "PING" command // paramaters {} -class IRCPingCommand : public IRCClientCommandHandler +class IRCClientPingCommand : public IRCClientCommandHandler { public: - IRCPingCommand(); + IRCClientPingCommand(); virtual bool receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ); virtual bool send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ); }; // IRC "PONG" command // paramaters {} -class IRCPongCommand : public IRCClientCommandHandler +class IRCClientPongCommand : public IRCClientCommandHandler { public: - IRCPongCommand(); + IRCClientPongCommand(); virtual bool receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ); virtual bool send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ); }; // IRC "NOTICE" command // paramaters {} -class IRCNoticeCommand : public IRCClientCommandHandler +class IRCClientNoticeCommand : public IRCClientCommandHandler { public: - IRCNoticeCommand(); + IRCClientNoticeCommand(); virtual bool receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ); virtual bool send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ); }; // IRC "JOIN" command // paramaters {chanel1,chanel2......} -class IRCJoinCommand : public IRCClientCommandHandler +class IRCClientJoinCommand : public IRCClientCommandHandler { public: - IRCJoinCommand(); + IRCClientJoinCommand(); virtual bool receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ); virtual bool send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ); }; // IRC "PART" command // paramaters {channel reason} -class IRCPartCommand : public IRCClientCommandHandler +class IRCClientPartCommand : public IRCClientCommandHandler { public: - IRCPartCommand(); + IRCClientPartCommand(); virtual bool receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ); virtual bool send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ); }; // IRC "QUIT" command // paramaters {channel reason} -class IRCQuitCommand : public IRCClientCommandHandler +class IRCClientQuitCommand : public IRCClientCommandHandler { public: - IRCQuitCommand(); + IRCClientQuitCommand(); virtual bool receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ); virtual bool send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ); }; // IRC "MODE" command // paramaters {target,modes} -class IRCModeCommand : public IRCClientCommandHandler +class IRCClientModeCommand : public IRCClientCommandHandler { public: - IRCModeCommand(); + IRCClientModeCommand(); virtual bool receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ); virtual bool send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ); }; // IRC "PRIVMSG" command // paramaters -class IRCPrivMsgCommand : public IRCClientCommandHandler +class IRCClientPrivMsgCommand : public IRCClientCommandHandler { public: - IRCPrivMsgCommand(); + IRCClientPrivMsgCommand(); virtual bool receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ); virtual bool send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ); }; // IRC "KICK" command // paramaters {user,reason} -class IRCKickCommand : public IRCClientCommandHandler +class IRCClientKickCommand : public IRCClientCommandHandler { public: - IRCKickCommand(); + IRCClientKickCommand(); virtual bool receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ); virtual bool send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ); }; +#endif //_IRC_BASIC_COMMANDS_ - - -#endif //_IRC_BASIC_COMMANDS_ +// Local Variables: *** +// mode: C++ *** +// tab-width: 8 *** +// c-basic-offset: 2 *** +// indent-tabs-mode: t *** +// End: *** +// ex: shiftwidth=2 tabstop=8 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Jef...@us...> - 2007-10-09 21:15:32
|
Revision: 253 http://libirc.svn.sourceforge.net/libirc/?rev=253&view=rev Author: JeffM2501 Date: 2007-10-09 14:15:30 -0700 (Tue, 09 Oct 2007) Log Message: ----------- hook in some basic command handler callbacks Modified Paths: -------------- trunk/libirc/include/IRCServer.h trunk/libirc/src/IRCServer.cpp Modified: trunk/libirc/include/IRCServer.h =================================================================== --- trunk/libirc/include/IRCServer.h 2007-10-09 21:15:06 UTC (rev 252) +++ trunk/libirc/include/IRCServer.h 2007-10-09 21:15:30 UTC (rev 253) @@ -100,6 +100,29 @@ MemberDataMap members; }; +// base command handler for any command +class IRCServerCommandHandler +{ +public: + IRCServerCommandHandler(){return;} + virtual ~IRCServerCommandHandler(){return;} + + // called when the system wishes to know the name of this command + virtual std::string getCommandName ( void ){return name;} + + // the send and receve methods return true if the default handler is to be called + // it is recomended that the default ALWAYS be called, as it often sets internal data for other mesages + + // called when the client receves a command of this type + virtual bool receve ( IRCServer &server, IRCServerConnectedClient *client, std::string &command, BaseIRCCommandInfo &info ){return true;} + + // called when the user wishes to send a command of this type + virtual bool send ( IRCServer &server, IRCServerConnectedClient *client, std::string &command, BaseIRCCommandInfo &info ){return true;} + +protected: + std::string name; +}; + class IRCServer : public TCPServerDataPendingListener { public: @@ -184,6 +207,27 @@ // channels typedef std::map<std::string, IRCServerChannel*> ChannelMap; ChannelMap channels; + + // command handlers + + typedef std::map<std::string, IRCServerCommandHandler*> tmCommandHandlerMap; + typedef std::map<std::string, std::vector<IRCServerCommandHandler*> > tmCommandHandlerListMap; + + tmCommandHandlerMap defaultCommandHandlers; + tmCommandHandlerListMap userCommandHandlers; + + void addDefaultCommandHandlers ( IRCServerCommandHandler* handler ); + void clearDefaultCommandHandlers ( void ); + void registerDefaultCommandHandlers ( void ); + }; #endif //_IRC_SERVER_H_ + +// Local Variables: *** +// mode:C++ *** +// tab-width: 8 *** +// c-basic-offset: 2 *** +// indent-tabs-mode: t *** +// End: *** +// ex: shiftwidth=2 tabstop=8 \ No newline at end of file Modified: trunk/libirc/src/IRCServer.cpp =================================================================== --- trunk/libirc/src/IRCServer.cpp 2007-10-09 21:15:06 UTC (rev 252) +++ trunk/libirc/src/IRCServer.cpp 2007-10-09 21:15:30 UTC (rev 253) @@ -445,12 +445,31 @@ void IRCServer::clientIRCCommand ( const BaseIRCCommandInfo &command, IRCServerConnectedClient *client ) { +} +void IRCServer::addDefaultCommandHandlers ( IRCServerCommandHandler* handler ) +{ + defaultCommandHandlers[handler->getCommandName()] = handler; } +void IRCServer::clearDefaultCommandHandlers ( void ) +{ + tmCommandHandlerMap::iterator itr = defaultCommandHandlers.begin(); + while (itr != defaultCommandHandlers.end()) + { + delete(itr->second); + itr++; + } + defaultCommandHandlers.clear(); +} +void IRCServer::registerDefaultCommandHandlers ( void ) +{ +} + + // Local Variables: *** // mode:C++ *** // tab-width: 8 *** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Jef...@us...> - 2007-10-09 22:03:58
|
Revision: 254 http://libirc.svn.sourceforge.net/libirc/?rev=254&view=rev Author: JeffM2501 Date: 2007-10-09 15:03:54 -0700 (Tue, 09 Oct 2007) Log Message: ----------- keep the things that are const, const Modified Paths: -------------- trunk/libirc/include/IRCClient.h trunk/libirc/src/IRCClient.cpp trunk/libirc/src/ircBasicCommands.cpp trunk/libirc/src/ircBasicCommands.h Modified: trunk/libirc/include/IRCClient.h =================================================================== --- trunk/libirc/include/IRCClient.h 2007-10-09 21:15:30 UTC (rev 253) +++ trunk/libirc/include/IRCClient.h 2007-10-09 22:03:54 UTC (rev 254) @@ -67,10 +67,10 @@ // it is recomended that the default ALWAYS be called, as it often sets internal data for other mesages // called when the client receves a command of this type - virtual bool receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ){return true;} + virtual bool receve ( IRCClient &client, const std::string &command, BaseIRCCommandInfo &info ){return true;} // called when the user wishes to send a command of this type - virtual bool send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ){return true;} + virtual bool send ( IRCClient &client, const std::string &command, BaseIRCCommandInfo &info ){return true;} protected: std::string name; }; @@ -178,7 +178,7 @@ virtual bool sendIRCCommand ( teIRCCommands command, IRCCommandInfo &info ); virtual bool sendCTMPCommand ( teCTCPCommands command, CTCPCommandINfo &info ); - virtual bool receveCommand ( std::string &commandName, BaseIRCCommandInfo &info ); + virtual bool receveCommand ( const std::string &commandName, BaseIRCCommandInfo &info ); virtual bool receveIRCCommand ( teIRCCommands command, IRCCommandInfo &info ); virtual bool receveCTMPCommand ( teCTCPCommands command, CTCPCommandINfo &info ); Modified: trunk/libirc/src/IRCClient.cpp =================================================================== --- trunk/libirc/src/IRCClient.cpp 2007-10-09 21:15:30 UTC (rev 253) +++ trunk/libirc/src/IRCClient.cpp 2007-10-09 22:03:54 UTC (rev 254) @@ -245,14 +245,10 @@ commandInfo.source = getServerHost(); // call the "ALL" handler special if there is one - handler = std::string("ALL"); - receveCommand(handler,commandInfo); + receveCommand(std::string("ALL"),commandInfo); if (atoi(commandInfo.command.c_str()) != 0) - { - handler = std::string("NUMERIC"); - receveCommand(handler,commandInfo); - } + receveCommand(std::string("NUMERIC"),commandInfo); // notify any handlers for this specific command receveCommand(commandInfo.command,commandInfo); @@ -406,7 +402,7 @@ return sendCommand(info.command,info); } -bool IRCClient::receveCommand ( std::string &commandName, BaseIRCCommandInfo &info ) +bool IRCClient::receveCommand ( const std::string &commandName, BaseIRCCommandInfo &info ) { tmUserCommandHandlersMap::iterator commandListItr = userCommandHandlers.find(commandName); Modified: trunk/libirc/src/ircBasicCommands.cpp =================================================================== --- trunk/libirc/src/ircBasicCommands.cpp 2007-10-09 21:15:30 UTC (rev 253) +++ trunk/libirc/src/ircBasicCommands.cpp 2007-10-09 22:03:54 UTC (rev 254) @@ -25,13 +25,13 @@ name = "NICK"; } -bool IRCClientNickCommand::receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) +bool IRCClientNickCommand::receve ( IRCClient &client, const std::string &command, BaseIRCCommandInfo &info ) { client.nickCommand(info); return true; } -bool IRCClientNickCommand::send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) +bool IRCClientNickCommand::send ( IRCClient &client, const std::string &command, BaseIRCCommandInfo &info ) { IRCCommandInfo &ircInfo = (IRCCommandInfo&)info; @@ -51,12 +51,12 @@ name = "USER"; } -bool IRCClientUserCommand::receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) +bool IRCClientUserCommand::receve ( IRCClient &client, const std::string &command, BaseIRCCommandInfo &info ) { return true; } -bool IRCClientUserCommand::send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) +bool IRCClientUserCommand::send ( IRCClient &client, const std::string &command, BaseIRCCommandInfo &info ) { IRCCommandInfo &ircInfo = (IRCCommandInfo&)info; @@ -75,7 +75,7 @@ name = "PING"; } -bool IRCClientPingCommand::receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) +bool IRCClientPingCommand::receve ( IRCClient &client, const std::string &command, BaseIRCCommandInfo &info ) { IRCCommandInfo ircInfo; ircInfo.command = eCMD_PONG; @@ -83,7 +83,7 @@ return true; } -bool IRCClientPingCommand::send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) +bool IRCClientPingCommand::send ( IRCClient &client, const std::string &command, BaseIRCCommandInfo &info ) { IRCCommandInfo &ircInfo = (IRCCommandInfo&)info; @@ -99,13 +99,13 @@ name = "PONG"; } -bool IRCClientPongCommand::receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) +bool IRCClientPongCommand::receve ( IRCClient &client, const std::string &command, BaseIRCCommandInfo &info ) { // we do nothing on a pong return true; } -bool IRCClientPongCommand::send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) +bool IRCClientPongCommand::send ( IRCClient &client, const std::string &command, BaseIRCCommandInfo &info ) { IRCCommandInfo &ircInfo = (IRCCommandInfo&)info; @@ -121,7 +121,7 @@ name = "NOTICE"; } -bool IRCClientNoticeCommand::receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) +bool IRCClientNoticeCommand::receve ( IRCClient &client, const std::string &command, BaseIRCCommandInfo &info ) { trClientMessageEventInfo messageInfo; @@ -133,7 +133,7 @@ return true; } -bool IRCClientNoticeCommand::send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) +bool IRCClientNoticeCommand::send ( IRCClient &client, const std::string &command, BaseIRCCommandInfo &info ) { // we do nothing on a pong return true; @@ -145,13 +145,13 @@ name = "JOIN"; } -bool IRCClientJoinCommand::receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) +bool IRCClientJoinCommand::receve ( IRCClient &client, const std::string &command, BaseIRCCommandInfo &info ) { client.joinMessage(info); return true; } -bool IRCClientJoinCommand::send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) +bool IRCClientJoinCommand::send ( IRCClient &client, const std::string &command, BaseIRCCommandInfo &info ) { std::string commandLine; @@ -182,13 +182,13 @@ name = "PART"; } -bool IRCClientPartCommand::receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) +bool IRCClientPartCommand::receve ( IRCClient &client, const std::string &command, BaseIRCCommandInfo &info ) { client.partMessage(info); return true; } -bool IRCClientPartCommand::send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) +bool IRCClientPartCommand::send ( IRCClient &client, const std::string &command, BaseIRCCommandInfo &info ) { std::string commandLine; @@ -206,13 +206,13 @@ name = "QUIT"; } -bool IRCClientQuitCommand::receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) +bool IRCClientQuitCommand::receve ( IRCClient &client, const std::string &command, BaseIRCCommandInfo &info ) { client.QuitMessage(info); return true; } -bool IRCClientQuitCommand::send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) +bool IRCClientQuitCommand::send ( IRCClient &client, const std::string &command, BaseIRCCommandInfo &info ) { std::string commandLine; @@ -230,14 +230,14 @@ name = "MODE"; } -bool IRCClientModeCommand::receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) +bool IRCClientModeCommand::receve ( IRCClient &client, const std::string &command, BaseIRCCommandInfo &info ) { // we got a mode message, see what the deal is client.modeCommand(info); return true; } -bool IRCClientModeCommand::send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) +bool IRCClientModeCommand::send ( IRCClient &client, const std::string &command, BaseIRCCommandInfo &info ) { // MODE TARGET modes std::string modeline = info.target; @@ -259,13 +259,13 @@ name = "PRIVMSG"; } -bool IRCClientPrivMsgCommand::receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) +bool IRCClientPrivMsgCommand::receve ( IRCClient &client, const std::string &command, BaseIRCCommandInfo &info ) { client.privMessage(info); return true; } -bool IRCClientPrivMsgCommand::send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) +bool IRCClientPrivMsgCommand::send ( IRCClient &client, const std::string &command, BaseIRCCommandInfo &info ) { IRCCommandInfo &ircInfo = (IRCCommandInfo&)info; @@ -284,13 +284,13 @@ name = "KICK"; } -bool IRCClientKickCommand::receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) +bool IRCClientKickCommand::receve ( IRCClient &client, const std::string &command, BaseIRCCommandInfo &info ) { client.kickCommand(info); return true; } -bool IRCClientKickCommand::send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) +bool IRCClientKickCommand::send ( IRCClient &client, const std::string &command, BaseIRCCommandInfo &info ) { IRCCommandInfo &ircInfo = (IRCCommandInfo&)info; @@ -311,7 +311,7 @@ name = "ALL"; } -bool IRCClientALLCommand::receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) +bool IRCClientALLCommand::receve ( IRCClient &client, const std::string &command, BaseIRCCommandInfo &info ) { // just log it out client.log(string_util::format("ALL::command %s from %s for %s containing %s",info.command.c_str(),info.source.c_str(),info.target.c_str(),info.getAsString().c_str()),4); @@ -320,7 +320,7 @@ return true; } -bool IRCClientALLCommand::send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) +bool IRCClientALLCommand::send ( IRCClient &client, const std::string &command, BaseIRCCommandInfo &info ) { // just log it out client.log(string_util::format("ALL::command %s: to server containing %s",command.c_str(),info.getAsString().c_str()),4); @@ -334,7 +334,7 @@ name = "NUMERIC"; } -bool IRCClientNumericCommand::receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ) +bool IRCClientNumericCommand::receve ( IRCClient &client, const std::string &command, BaseIRCCommandInfo &info ) { int numeric = atoi(info.command.c_str()); Modified: trunk/libirc/src/ircBasicCommands.h =================================================================== --- trunk/libirc/src/ircBasicCommands.h 2007-10-09 21:15:30 UTC (rev 253) +++ trunk/libirc/src/ircBasicCommands.h 2007-10-09 22:03:54 UTC (rev 254) @@ -23,8 +23,8 @@ { public: IRCClientALLCommand(); - virtual bool receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ); - virtual bool send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ); + virtual bool receve ( IRCClient &client, const std::string &command, BaseIRCCommandInfo &info ); + virtual bool send ( IRCClient &client, const std::string &command, BaseIRCCommandInfo &info ); }; // numerics, handles any IRC numeric return code @@ -32,7 +32,7 @@ { public: IRCClientNumericCommand(); - virtual bool receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ); + virtual bool receve ( IRCClient &client, const std::string &command, BaseIRCCommandInfo &info ); }; // Text based IRC commands @@ -43,8 +43,8 @@ { public: IRCClientNickCommand(); - virtual bool receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ); - virtual bool send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ); + virtual bool receve ( IRCClient &client, const std::string &command, BaseIRCCommandInfo &info ); + virtual bool send ( IRCClient &client, const std::string &command, BaseIRCCommandInfo &info ); }; // IRC "USER" command @@ -53,8 +53,8 @@ { public: IRCClientUserCommand(); - virtual bool receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ); - virtual bool send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ); + virtual bool receve ( IRCClient &client, const std::string &command, BaseIRCCommandInfo &info ); + virtual bool send ( IRCClient &client, const std::string &command, BaseIRCCommandInfo &info ); }; // IRC "PING" command @@ -63,8 +63,8 @@ { public: IRCClientPingCommand(); - virtual bool receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ); - virtual bool send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ); + virtual bool receve ( IRCClient &client, const std::string &command, BaseIRCCommandInfo &info ); + virtual bool send ( IRCClient &client, const std::string &command, BaseIRCCommandInfo &info ); }; // IRC "PONG" command @@ -73,8 +73,8 @@ { public: IRCClientPongCommand(); - virtual bool receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ); - virtual bool send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ); + virtual bool receve ( IRCClient &client, const std::string &command, BaseIRCCommandInfo &info ); + virtual bool send ( IRCClient &client, const std::string &command, BaseIRCCommandInfo &info ); }; // IRC "NOTICE" command @@ -83,8 +83,8 @@ { public: IRCClientNoticeCommand(); - virtual bool receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ); - virtual bool send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ); + virtual bool receve ( IRCClient &client, const std::string &command, BaseIRCCommandInfo &info ); + virtual bool send ( IRCClient &client, const std::string &command, BaseIRCCommandInfo &info ); }; // IRC "JOIN" command @@ -93,8 +93,8 @@ { public: IRCClientJoinCommand(); - virtual bool receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ); - virtual bool send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ); + virtual bool receve ( IRCClient &client, const std::string &command, BaseIRCCommandInfo &info ); + virtual bool send ( IRCClient &client, const std::string &command, BaseIRCCommandInfo &info ); }; // IRC "PART" command @@ -103,8 +103,8 @@ { public: IRCClientPartCommand(); - virtual bool receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ); - virtual bool send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ); + virtual bool receve ( IRCClient &client, const std::string &command, BaseIRCCommandInfo &info ); + virtual bool send ( IRCClient &client, const std::string &command, BaseIRCCommandInfo &info ); }; // IRC "QUIT" command @@ -113,8 +113,8 @@ { public: IRCClientQuitCommand(); - virtual bool receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ); - virtual bool send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ); + virtual bool receve ( IRCClient &client, const std::string &command, BaseIRCCommandInfo &info ); + virtual bool send ( IRCClient &client, const std::string &command, BaseIRCCommandInfo &info ); }; // IRC "MODE" command @@ -123,8 +123,8 @@ { public: IRCClientModeCommand(); - virtual bool receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ); - virtual bool send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ); + virtual bool receve ( IRCClient &client, const std::string &command, BaseIRCCommandInfo &info ); + virtual bool send ( IRCClient &client, const std::string &command, BaseIRCCommandInfo &info ); }; // IRC "PRIVMSG" command @@ -133,8 +133,8 @@ { public: IRCClientPrivMsgCommand(); - virtual bool receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ); - virtual bool send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ); + virtual bool receve ( IRCClient &client, const std::string &command, BaseIRCCommandInfo &info ); + virtual bool send ( IRCClient &client, const std::string &command, BaseIRCCommandInfo &info ); }; // IRC "KICK" command @@ -143,8 +143,8 @@ { public: IRCClientKickCommand(); - virtual bool receve ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ); - virtual bool send ( IRCClient &client, std::string &command, BaseIRCCommandInfo &info ); + virtual bool receve ( IRCClient &client, const std::string &command, BaseIRCCommandInfo &info ); + virtual bool send ( IRCClient &client, const std::string &command, BaseIRCCommandInfo &info ); }; #endif //_IRC_BASIC_COMMANDS_ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Jef...@us...> - 2007-10-09 22:04:43
|
Revision: 255 http://libirc.svn.sourceforge.net/libirc/?rev=255&view=rev Author: JeffM2501 Date: 2007-10-09 15:04:39 -0700 (Tue, 09 Oct 2007) Log Message: ----------- call any registered command handlers when we get any IRC commands on the server Modified Paths: -------------- trunk/libirc/include/IRCServer.h trunk/libirc/src/IRCServer.cpp Modified: trunk/libirc/include/IRCServer.h =================================================================== --- trunk/libirc/include/IRCServer.h 2007-10-09 22:03:54 UTC (rev 254) +++ trunk/libirc/include/IRCServer.h 2007-10-09 22:04:39 UTC (rev 255) @@ -114,10 +114,10 @@ // it is recomended that the default ALWAYS be called, as it often sets internal data for other mesages // called when the client receves a command of this type - virtual bool receve ( IRCServer &server, IRCServerConnectedClient *client, std::string &command, BaseIRCCommandInfo &info ){return true;} + virtual bool receve ( IRCServer *server, IRCServerConnectedClient *client, const std::string &command, const BaseIRCCommandInfo &info ){return true;} // called when the user wishes to send a command of this type - virtual bool send ( IRCServer &server, IRCServerConnectedClient *client, std::string &command, BaseIRCCommandInfo &info ){return true;} + virtual bool send ( IRCServer *server, IRCServerConnectedClient *client, const std::string &command, const BaseIRCCommandInfo &info ){return true;} protected: std::string name; @@ -166,6 +166,9 @@ IRCServerChannel *getChannel ( const char *name ); IRCServerChannel *getChannel ( const std::string& name ); + // commands + virtual bool receveCommand ( const std::string &commandName, IRCServerConnectedClient *client, const BaseIRCCommandInfo &info ); + protected: friend class IRCServerConnectedClient; Modified: trunk/libirc/src/IRCServer.cpp =================================================================== --- trunk/libirc/src/IRCServer.cpp 2007-10-09 22:03:54 UTC (rev 254) +++ trunk/libirc/src/IRCServer.cpp 2007-10-09 22:04:39 UTC (rev 255) @@ -445,8 +445,37 @@ void IRCServer::clientIRCCommand ( const BaseIRCCommandInfo &command, IRCServerConnectedClient *client ) { + receveCommand(std::string("ALL"),client,command); + + if (atoi(command.command.c_str()) != 0) + receveCommand( std::string("NUMERIC"),client,command); + + // notify any handlers for this specific command + receveCommand(command.command,client,command); } +bool IRCServer::receveCommand ( const std::string &commandName, IRCServerConnectedClient *client, const BaseIRCCommandInfo &info ) +{ + tmCommandHandlerListMap::iterator itr = userCommandHandlers.find(commandName); + if ( itr != userCommandHandlers.end() ) + { + bool callDefault = false; + for ( unsigned int i = 0; i < (unsigned int) itr->second.size(); i++ ) + { + if ( itr->second[i]->receve(this,client,commandName,info)) + callDefault = true; + } + if (!callDefault) + return true; + } + + tmCommandHandlerMap::iterator defaultIter = defaultCommandHandlers.find(commandName); + if ( defaultIter != defaultCommandHandlers.end() && defaultIter->second ) + return defaultIter->second->receve(this,client,commandName,info); + + return false; +} + void IRCServer::addDefaultCommandHandlers ( IRCServerCommandHandler* handler ) { defaultCommandHandlers[handler->getCommandName()] = handler; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Jef...@us...> - 2007-10-09 22:18:08
|
Revision: 256 http://libirc.svn.sourceforge.net/libirc/?rev=256&view=rev Author: JeffM2501 Date: 2007-10-09 15:18:05 -0700 (Tue, 09 Oct 2007) Log Message: ----------- allow registration of command handlers Modified Paths: -------------- trunk/libirc/include/IRCServer.h trunk/libirc/src/IRCServer.cpp Modified: trunk/libirc/include/IRCServer.h =================================================================== --- trunk/libirc/include/IRCServer.h 2007-10-09 22:04:39 UTC (rev 255) +++ trunk/libirc/include/IRCServer.h 2007-10-09 22:18:05 UTC (rev 256) @@ -88,7 +88,7 @@ class ChannelUserData { public: - virtual ~ChannelUserData(); + virtual ~ChannelUserData(){}; bool voice; bool op; }; @@ -104,23 +104,23 @@ class IRCServerCommandHandler { public: - IRCServerCommandHandler(){return;} - virtual ~IRCServerCommandHandler(){return;} + IRCServerCommandHandler(){return;} + virtual ~IRCServerCommandHandler(){return;} - // called when the system wishes to know the name of this command - virtual std::string getCommandName ( void ){return name;} + // called when the system wishes to know the name of this command + virtual std::string getCommandName ( void ){return name;} - // the send and receve methods return true if the default handler is to be called - // it is recomended that the default ALWAYS be called, as it often sets internal data for other mesages + // the send and receve methods return true if the default handler is to be called + // it is recomended that the default ALWAYS be called, as it often sets internal data for other mesages - // called when the client receves a command of this type - virtual bool receve ( IRCServer *server, IRCServerConnectedClient *client, const std::string &command, const BaseIRCCommandInfo &info ){return true;} + // called when the client receves a command of this type + virtual bool receve ( IRCServer *server, IRCServerConnectedClient *client, const std::string &command, const BaseIRCCommandInfo &info ){return true;} - // called when the user wishes to send a command of this type - virtual bool send ( IRCServer *server, IRCServerConnectedClient *client, const std::string &command, const BaseIRCCommandInfo &info ){return true;} + // called when the user wishes to send a command of this type + virtual bool send ( IRCServer *server, IRCServerConnectedClient *client, const std::string &command, const BaseIRCCommandInfo &info ){return true;} protected: - std::string name; + std::string name; }; class IRCServer : public TCPServerDataPendingListener @@ -169,6 +169,13 @@ // commands virtual bool receveCommand ( const std::string &commandName, IRCServerConnectedClient *client, const BaseIRCCommandInfo &info ); + //command handler methods... for lower level API + virtual bool registerCommandHandler ( IRCServerCommandHandler *handler ); + virtual bool removeCommandHandler ( IRCServerCommandHandler *handler ); + + virtual int listUserHandledCommands ( std::vector<std::string> &commandList ); + virtual int listDefaultHandledCommands ( std::vector<std::string> &commandList ); + protected: friend class IRCServerConnectedClient; Modified: trunk/libirc/src/IRCServer.cpp =================================================================== --- trunk/libirc/src/IRCServer.cpp 2007-10-09 22:04:39 UTC (rev 255) +++ trunk/libirc/src/IRCServer.cpp 2007-10-09 22:18:05 UTC (rev 256) @@ -498,7 +498,79 @@ } +bool IRCServer::registerCommandHandler ( IRCServerCommandHandler *handler ) +{ + if (!handler) + return false; + std::string command = handler->getCommandName(); + + tmCommandHandlerListMap::iterator commandListItr = userCommandHandlers.find(command); + if (commandListItr == userCommandHandlers.end()) + { + std::vector<IRCServerCommandHandler*> handlerList; + handlerList.push_back(handler); + userCommandHandlers[command] = handlerList; + } + else + commandListItr->second.push_back(handler); + + return true; +} + +bool IRCServer::removeCommandHandler ( IRCServerCommandHandler *handler ) +{ + if (!handler) + return false; + + std::string command = handler->getCommandName(); + + tmCommandHandlerListMap::iterator commandListItr = userCommandHandlers.find(command); + if (commandListItr == userCommandHandlers.end()) + return false; + else + { + std::vector<IRCServerCommandHandler*>::iterator itr = commandListItr->second.begin(); + while ( itr != commandListItr->second.end()) + { + if (*itr == handler) + itr = commandListItr->second.erase(itr); + else + itr++; + } + } + return true; +} + +int IRCServer::listUserHandledCommands ( std::vector<std::string> &commandList ) +{ + commandList.clear(); + + tmCommandHandlerListMap::iterator itr = userCommandHandlers.begin(); + + while (itr != userCommandHandlers.end()) + { + commandList.push_back(itr->first); + itr++; + } + return (int)commandList.size(); +} + +int IRCServer::listDefaultHandledCommands ( std::vector<std::string> &commandList ) +{ + commandList.clear(); + + tmCommandHandlerMap::iterator itr = defaultCommandHandlers.begin(); + + while (itr != defaultCommandHandlers.end()) + { + commandList.push_back(itr->first); + itr++; + } + return (int)commandList.size(); +} + + // Local Variables: *** // mode:C++ *** // tab-width: 8 *** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Jef...@us...> - 2007-10-09 22:26:21
|
Revision: 257 http://libirc.svn.sourceforge.net/libirc/?rev=257&view=rev Author: JeffM2501 Date: 2007-10-09 15:26:19 -0700 (Tue, 09 Oct 2007) Log Message: ----------- client events for clients, server events for servers Modified Paths: -------------- trunk/libirc/include/IRCClient.h trunk/libirc/include/IRCEvents.h trunk/libirc/src/IRCClient.cpp Modified: trunk/libirc/include/IRCClient.h =================================================================== --- trunk/libirc/include/IRCClient.h 2007-10-09 22:18:05 UTC (rev 256) +++ trunk/libirc/include/IRCClient.h 2007-10-09 22:26:19 UTC (rev 257) @@ -82,7 +82,7 @@ virtual void log ( IRCClient &client, int level, std::string line ) = 0; }; -class IRCClient : public TCPClientDataPendingListener, IRCBasicEventCallback +class IRCClient : public TCPClientDataPendingListener, IRCClientEventCallback { public: IRCClient( CIRCClientNetworkHandler* h = NULL); @@ -162,8 +162,8 @@ IRCUserManager& getUserManager ( void ){return userManager;} //event handler methods.... for higher level API - virtual bool registerEventHandler ( teIRCEventType eventType, IRCBasicEventCallback *handler ); - virtual bool removeEventHandler ( teIRCEventType eventType, IRCBasicEventCallback *handler ); + virtual bool registerEventHandler ( teIRCEventType eventType, IRCClientEventCallback *handler ); + virtual bool removeEventHandler ( teIRCEventType eventType, IRCClientEventCallback *handler ); virtual void callEventHandler ( teIRCEventType eventType, trBaseEventInfo &info ); //command handler methods... for lower level API @@ -285,10 +285,10 @@ void registerDefaultCommandHandlers ( void ); // event handlers - tmIRCEventMap defaultEventHandlers; - tmIRCEventListMap userEventHandlers; + tmIRCClientEventMap defaultEventHandlers; + tmIRCClientEventListMap userEventHandlers; - void addDefaultEventHandlers ( teIRCEventType eventType, IRCBasicEventCallback* handler ); + void addDefaultEventHandlers ( teIRCEventType eventType, IRCClientEventCallback* handler ); void clearDefaultEventHandlers ( void ); void registerDefaultEventHandlers ( void ); Modified: trunk/libirc/include/IRCEvents.h =================================================================== --- trunk/libirc/include/IRCEvents.h 2007-10-09 22:18:05 UTC (rev 256) +++ trunk/libirc/include/IRCEvents.h 2007-10-09 22:26:19 UTC (rev 257) @@ -20,6 +20,7 @@ #include "IRCTextUtils.h" class IRCClient; +class IRCServer; class IRCServerConnectedClient; typedef enum @@ -122,17 +123,28 @@ std::string getAsString ( int start = 0, int end = -1 ) {return string_util::getStringFromList(params," ",start,end);} }trClientMessageEventInfo; -class IRCBasicEventCallback +class IRCClientEventCallback { public: - virtual ~IRCBasicEventCallback(){return;} + virtual ~IRCClientEventCallback(){return;} virtual bool process ( IRCClient &ircClient, teIRCEventType eventType, trBaseEventInfo &info ) = 0; }; -typedef std::vector<IRCBasicEventCallback*> tvIRCEventList; -typedef std::map<teIRCEventType,tvIRCEventList> tmIRCEventListMap; -typedef std::map<teIRCEventType,IRCBasicEventCallback*> tmIRCEventMap; +class IRCServerEventCallback +{ +public: + virtual ~IRCServerEventCallback(){return;} + virtual bool process ( IRCServer *ircServer, teIRCEventType eventType, trBaseServerEventInfo &info ) = 0; +}; +typedef std::vector<IRCClientEventCallback*> tvIRCClientEventList; +typedef std::map<teIRCEventType,tvIRCClientEventList> tmIRCClientEventListMap; +typedef std::map<teIRCEventType,IRCClientEventCallback*> tmIRCClientEventMap; + +typedef std::vector<IRCServerEventCallback*> tvIRCServerEventList; +typedef std::map<teIRCEventType,tvIRCServerEventList> tmIRCServerEventListMap; +typedef std::map<teIRCEventType,IRCServerEventCallback*> tmIRCServerEventMap; + #endif // __IRC_EVENTS_H__ // Local Variables: *** // mode: C++ *** Modified: trunk/libirc/src/IRCClient.cpp =================================================================== --- trunk/libirc/src/IRCClient.cpp 2007-10-09 22:18:05 UTC (rev 256) +++ trunk/libirc/src/IRCClient.cpp 2007-10-09 22:26:19 UTC (rev 257) @@ -570,7 +570,7 @@ //tmIRCEventMap defaultEventHandlers; //tmIRCEventListMap userEventHandlers; -void IRCClient::addDefaultEventHandlers ( teIRCEventType eventType, IRCBasicEventCallback* handler ) +void IRCClient::addDefaultEventHandlers ( teIRCEventType eventType, IRCClientEventCallback* handler ) { if (handler) defaultEventHandlers[eventType] = handler; @@ -578,7 +578,7 @@ void IRCClient::clearDefaultEventHandlers ( void ) { - tmIRCEventMap::iterator itr = defaultEventHandlers.begin(); + tmIRCClientEventMap::iterator itr = defaultEventHandlers.begin(); while ( itr != defaultEventHandlers.end()) { @@ -597,15 +597,15 @@ addDefaultEventHandlers(eIRCNickNameError,this); } -bool IRCClient::registerEventHandler ( teIRCEventType eventType, IRCBasicEventCallback *handler ) +bool IRCClient::registerEventHandler ( teIRCEventType eventType, IRCClientEventCallback *handler ) { if (!handler) return false; - tmIRCEventListMap::iterator eventListItr = userEventHandlers.find(eventType); + tmIRCClientEventListMap::iterator eventListItr = userEventHandlers.find(eventType); if (eventListItr == userEventHandlers.end()) { - tvIRCEventList handlerList; + tvIRCClientEventList handlerList; handlerList.push_back(handler); userEventHandlers[eventType] = handlerList; } @@ -615,17 +615,17 @@ return true; } -bool IRCClient::removeEventHandler ( teIRCEventType eventType, IRCBasicEventCallback *handler ) +bool IRCClient::removeEventHandler ( teIRCEventType eventType, IRCClientEventCallback *handler ) { if (!handler) return false; - tmIRCEventListMap::iterator eventListItr = userEventHandlers.find(eventType); + tmIRCClientEventListMap::iterator eventListItr = userEventHandlers.find(eventType); if (eventListItr == userEventHandlers.end()) return false; else { - tvIRCEventList::iterator itr = eventListItr->second.begin(); + tvIRCClientEventList::iterator itr = eventListItr->second.begin(); while ( itr != eventListItr->second.end()) { if ((*itr)== handler) @@ -641,7 +641,7 @@ { bool callDefault = true; - tmIRCEventListMap::iterator eventListItr = userEventHandlers.find(eventType); + tmIRCClientEventListMap::iterator eventListItr = userEventHandlers.find(eventType); // make sure the event type is cool info.eventType = eventType; @@ -652,7 +652,7 @@ callDefault = false; // is this right? // should we do them all? or just the first one that "HANDLES" it? - tvIRCEventList::iterator itr = eventListItr->second.begin(); + tvIRCClientEventList::iterator itr = eventListItr->second.begin(); while (itr != eventListItr->second.end()) { if ( (*itr)->process(*this,eventType,info)) @@ -665,7 +665,7 @@ if (callDefault) // check for the default { - tmIRCEventMap::iterator itr = defaultEventHandlers.find(eventType); + tmIRCClientEventMap::iterator itr = defaultEventHandlers.find(eventType); if (itr != defaultEventHandlers.end()) { itr->second->process(*this,eventType,info); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Jef...@us...> - 2007-10-09 23:30:17
|
Revision: 258 http://libirc.svn.sourceforge.net/libirc/?rev=258&view=rev Author: JeffM2501 Date: 2007-10-09 16:30:15 -0700 (Tue, 09 Oct 2007) Log Message: ----------- setup high level event system for server add connection event. Modified Paths: -------------- trunk/libirc/include/IRCEvents.h trunk/libirc/include/IRCServer.h trunk/libirc/src/IRCServer.cpp Modified: trunk/libirc/include/IRCEvents.h =================================================================== --- trunk/libirc/include/IRCEvents.h 2007-10-09 22:26:19 UTC (rev 257) +++ trunk/libirc/include/IRCEvents.h 2007-10-09 23:30:15 UTC (rev 258) @@ -61,7 +61,11 @@ // events with no data use this typedef struct trBaseServerEventInfo : public trBaseEventInfo { - IRCServerConnectedClient *client; + trBaseServerEventInfo(IRCServerConnectedClient*c) + { + client = c; + } + IRCServerConnectedClient *client; }trBaseServerEventInfo; // nickname error type events, used for eIRCNickNameError Modified: trunk/libirc/include/IRCServer.h =================================================================== --- trunk/libirc/include/IRCServer.h 2007-10-09 22:26:19 UTC (rev 257) +++ trunk/libirc/include/IRCServer.h 2007-10-09 23:30:15 UTC (rev 258) @@ -123,7 +123,7 @@ std::string name; }; -class IRCServer : public TCPServerDataPendingListener +class IRCServer : public TCPServerDataPendingListener, IRCServerEventCallback { public: IRCServer(); @@ -176,6 +176,17 @@ virtual int listUserHandledCommands ( std::vector<std::string> &commandList ); virtual int listDefaultHandledCommands ( std::vector<std::string> &commandList ); + //event handler methods.... for higher level API + virtual bool registerEventHandler ( teIRCEventType eventType, IRCServerEventCallback *handler ); + virtual bool removeEventHandler ( teIRCEventType eventType, IRCServerEventCallback *handler ); + virtual void callEventHandler ( teIRCEventType eventType, trBaseServerEventInfo &info ); + + // internal event callbacks + virtual bool process ( IRCServer *ircServer, teIRCEventType eventType, trBaseServerEventInfo &info ); + + // super high level common overides + virtual const char * getConnectionText ( IRCServerConnectedClient *client ){return NULL;} + protected: friend class IRCServerConnectedClient; @@ -230,6 +241,15 @@ void clearDefaultCommandHandlers ( void ); void registerDefaultCommandHandlers ( void ); + // event handlers + tmIRCServerEventMap defaultEventHandlers; + tmIRCServerEventListMap userEventHandlers; + + void addDefaultEventHandlers ( teIRCEventType eventType, IRCServerEventCallback* handler ); + void clearDefaultEventHandlers ( void ); + void registerDefaultEventHandlers ( void ); + + }; #endif //_IRC_SERVER_H_ Modified: trunk/libirc/src/IRCServer.cpp =================================================================== --- trunk/libirc/src/IRCServer.cpp 2007-10-09 22:26:19 UTC (rev 257) +++ trunk/libirc/src/IRCServer.cpp 2007-10-09 23:30:15 UTC (rev 258) @@ -400,11 +400,11 @@ for ( unsigned int i = 0; i < size; i++ ) { if ( data[i] != 13 ) - theLine += data[i]; + theLine += data[i]; else { - processIRCLine(theLine,client); - theLine = ""; + processIRCLine(theLine,client); + theLine = ""; } } } @@ -432,6 +432,8 @@ void IRCServer::clientConnect ( IRCServerConnectedClient *client ) { + trBaseServerEventInfo info(client); + callEventHandler(eIRCConnectedEvent,info); } void IRCServer::clientDisconnect ( IRCServerConnectedClient *client ) @@ -495,7 +497,7 @@ void IRCServer::registerDefaultCommandHandlers ( void ) { - + registerDefaultEventHandlers(); } bool IRCServer::registerCommandHandler ( IRCServerCommandHandler *handler ) @@ -570,7 +572,136 @@ return (int)commandList.size(); } +void IRCServer::addDefaultEventHandlers ( teIRCEventType eventType, IRCServerEventCallback* handler ) +{ + if (handler) + defaultEventHandlers[eventType] = handler; +} +void IRCServer::clearDefaultEventHandlers ( void ) +{ + tmIRCServerEventMap::iterator itr = defaultEventHandlers.begin(); + + while ( itr != defaultEventHandlers.end()) + { + if (itr->second && (itr->second != this) ) + delete(itr->second); + itr++; + } + defaultEventHandlers.clear(); +} + +void IRCServer::registerDefaultEventHandlers ( void ) +{ + userEventHandlers.clear(); + clearDefaultEventHandlers(); + + registerEventHandler(eIRCConnectedEvent,this); +} + +bool IRCServer::registerEventHandler ( teIRCEventType eventType, IRCServerEventCallback *handler ) +{ + if (!handler) + return false; + + tmIRCServerEventListMap::iterator eventListItr = userEventHandlers.find(eventType); + if (eventListItr == userEventHandlers.end()) + { + tvIRCServerEventList handlerList; + handlerList.push_back(handler); + userEventHandlers[eventType] = handlerList; + } + else + eventListItr->second.push_back(handler); + + return true; +} + +bool IRCServer::removeEventHandler ( teIRCEventType eventType, IRCServerEventCallback *handler ) +{ + if (!handler) + return false; + + tmIRCServerEventListMap::iterator eventListItr = userEventHandlers.find(eventType); + if (eventListItr == userEventHandlers.end()) + return false; + else + { + tvIRCServerEventList::iterator itr = eventListItr->second.begin(); + while ( itr != eventListItr->second.end()) + { + if ((*itr)== handler) + itr = eventListItr->second.erase(itr); + else + itr++; + } + } + return true; +} + +void IRCServer::callEventHandler ( teIRCEventType eventType, trBaseServerEventInfo &info ) +{ + bool callDefault = true; + + tmIRCServerEventListMap::iterator eventListItr = userEventHandlers.find(eventType); + + // make sure the event type is cool + info.eventType = eventType; + + if (eventListItr != userEventHandlers.end() && eventListItr->second.size()) // do we have a custom command handler + { + // someone has to want us to call the defalt now + callDefault = false; + // is this right? + // should we do them all? or just the first one that "HANDLES" it? + tvIRCServerEventList::iterator itr = eventListItr->second.begin(); + while (itr != eventListItr->second.end()) + { + if ( (*itr)->process(this,eventType,info)) + callDefault = true; + itr++; + } + if (!callDefault) + return; + } + + if (callDefault) // check for the default + { + tmIRCServerEventMap::iterator itr = defaultEventHandlers.find(eventType); + if (itr != defaultEventHandlers.end()) + { + itr->second->process(this,eventType,info); + return; + } + } + return; +} + +bool IRCServer::process ( IRCServer *ircServer, teIRCEventType eventType, trBaseServerEventInfo &info ) +{ + if (ircServer != this) + return false; + + switch(eventType) + { + case eIRCConnectedEvent: + { + char *text = getConnectionText(info.client); + if (!text) + return false; + + std::vector<std::string> lines = string_util::tokenize(std::string(text),std::string("\n")); + for (unsigned int i = 0; i < (unsigned int)lines.size(); i++) + { + // send out each line as it's own message + } + } + return true; + } + return false; +} + + // Local Variables: *** // mode:C++ *** // tab-width: 8 *** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Jef...@us...> - 2007-10-10 01:31:41
|
Revision: 260 http://libirc.svn.sourceforge.net/libirc/?rev=260&view=rev Author: JeffM2501 Date: 2007-10-09 18:31:38 -0700 (Tue, 09 Oct 2007) Log Message: ----------- get some command processing going Modified Paths: -------------- trunk/libirc/include/IRCServer.h trunk/libirc/src/IRCServer.cpp Modified: trunk/libirc/include/IRCServer.h =================================================================== --- trunk/libirc/include/IRCServer.h 2007-10-09 23:34:31 UTC (rev 259) +++ trunk/libirc/include/IRCServer.h 2007-10-10 01:31:38 UTC (rev 260) @@ -139,6 +139,8 @@ virtual int getDebugLevel ( void ); // general connection methods + virtual bool setHostName ( const char* host ); + virtual bool listen ( int maxConnections = 32, int port = -1 ); virtual bool disconnect ( std::string reason ); @@ -185,8 +187,19 @@ virtual bool process ( IRCServer *ircServer, teIRCEventType eventType, trBaseServerEventInfo &info ); // super high level common overides - virtual const char * getConnectionText ( IRCServerConnectedClient *client ){return NULL;} + typedef struct + { + std::string welome; + std::string host; + std::string created; + std::string info; + std::string bounce; + std::string motd; + }ConnectionText; + + virtual void getConnectionText ( IRCServerConnectedClient *client, ConnectionText &text ){return;} + protected: friend class IRCServerConnectedClient; @@ -203,10 +216,12 @@ virtual void processIRCLine ( std::string line, IRCServerConnectedClient *client ); // networking - TCPServerConnection *tcpServer; - TCPConnection &tcpConnection; - int ircServerPort; + TCPServerConnection *tcpServer; + TCPConnection &tcpConnection; + int ircServerPort; + std::string hostname; + // loging IRCServerLogHandler *logHandler; std::string logfile; @@ -249,7 +264,10 @@ void clearDefaultEventHandlers ( void ); void registerDefaultEventHandlers ( void ); + // utilities + void sendLinesOutToClient ( int numeric, IRCServerConnectedClient *client, const std::string &text ); + }; #endif //_IRC_SERVER_H_ Modified: trunk/libirc/src/IRCServer.cpp =================================================================== --- trunk/libirc/src/IRCServer.cpp 2007-10-09 23:34:31 UTC (rev 259) +++ trunk/libirc/src/IRCServer.cpp 2007-10-10 01:31:38 UTC (rev 260) @@ -686,22 +686,21 @@ { case eIRCConnectedEvent: { - const char *text = getConnectionText(info.client); - if (!text) - return false; - - std::vector<std::string> lines = string_util::tokenize(std::string(text),std::string("\n")); - for (unsigned int i = 0; i < (unsigned int)lines.size(); i++) - { - // send out each line as it's own message - } + ConnectionText record; + getConnectionText(info.client,record); } return true; } return false; } +void IRCServer::sendLinesOutToClient ( int numeric, IRCServerConnectedClient *client, const std::string &text ) +{ +} + + + // Local Variables: *** // mode:C++ *** // tab-width: 8 *** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mm...@us...> - 2007-10-10 05:38:50
|
Revision: 263 http://libirc.svn.sourceforge.net/libirc/?rev=263&view=rev Author: mm_202 Date: 2007-10-09 22:38:46 -0700 (Tue, 09 Oct 2007) Log Message: ----------- Commented out the area that is causing the segfaults. A dirty hack, but it'll be fixed later. Modified Paths: -------------- trunk/libirc/include/IRCUserManager.h trunk/libirc/src/IRCUserManager.cpp Modified: trunk/libirc/include/IRCUserManager.h =================================================================== --- trunk/libirc/include/IRCUserManager.h 2007-10-10 01:32:07 UTC (rev 262) +++ trunk/libirc/include/IRCUserManager.h 2007-10-10 05:38:46 UTC (rev 263) @@ -257,4 +257,4 @@ int lastChannelID; }; -#endif//_IRC_USER_MANAGER_ \ No newline at end of file +#endif//_IRC_USER_MANAGER_ Modified: trunk/libirc/src/IRCUserManager.cpp =================================================================== --- trunk/libirc/src/IRCUserManager.cpp 2007-10-10 01:32:07 UTC (rev 262) +++ trunk/libirc/src/IRCUserManager.cpp 2007-10-10 05:38:46 UTC (rev 263) @@ -582,16 +582,17 @@ { channelRecord.userPerms.erase(channelRecord.userPerms.find(userRecord.id)); - std::vector<int>::iterator itr = userRecord.channels.begin(); - while ( itr != userRecord.channels.end() ) - { - if ( *itr == channelRecord.id) - itr = userRecord.channels.erase(itr); - else - itr++; - } - if (autoPurgeOnLastPart && userRecord.channels.size() == 0) - removeUser(user); + // mm_202 - the problem area that causes the segfaults. + /*std::vector<int>::iterator itr = userRecord.channels.begin(); + while ( itr != userRecord.channels.end() ) + { + if ( *itr == channelRecord.id) + itr = userRecord.channels.erase(itr); + else + itr++; + }*/ + // if (autoPurgeOnLastPart && userRecord.channels.size() == 0) + // removeUser(user); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mm...@us...> - 2007-10-23 00:42:35
|
Revision: 293 http://libirc.svn.sourceforge.net/libirc/?rev=293&view=rev Author: mm_202 Date: 2007-10-22 17:42:33 -0700 (Mon, 22 Oct 2007) Log Message: ----------- Some minor typo fixes. Modified Paths: -------------- trunk/libirc/include/IRCClient.h trunk/libirc/src/irClientEvents.cpp Modified: trunk/libirc/include/IRCClient.h =================================================================== --- trunk/libirc/include/IRCClient.h 2007-10-16 21:22:43 UTC (rev 292) +++ trunk/libirc/include/IRCClient.h 2007-10-23 00:42:33 UTC (rev 293) @@ -130,7 +130,7 @@ virtual bool kick ( std::string user, std::string channel, std::string reason ); virtual bool mode ( std::string theMode, std::string target, std::string option ); - // user modes in chanel + // user modes in channel virtual bool ban ( std::string mask, std::string channel ); virtual bool unban ( std::string mask, std::string channel ); virtual bool voice ( std::string user, std::string channel ); Modified: trunk/libirc/src/irClientEvents.cpp =================================================================== --- trunk/libirc/src/irClientEvents.cpp 2007-10-16 21:22:43 UTC (rev 292) +++ trunk/libirc/src/irClientEvents.cpp 2007-10-23 00:42:33 UTC (rev 293) @@ -129,7 +129,7 @@ std::string mode = info.params[1]; - // figure out who the message is from, is it form a channel or from a dude + // figure out who the message is from, is it form a channel or from a user if (who[0] == '#' ) { if (string_util::charExists(mode,'b')) // it's a ban! @@ -156,7 +156,7 @@ modeInfo.from = info.source; modeInfo.mode = mode; - if (info.params.size() > 1) // if there is mor then one param then it's a mode change for a user + if (info.params.size() > 1) // if there is more than one param then it's a mode change for a user { modeInfo.eventType = eIRCChannelUserModeSet; modeInfo.message = info.getAsString(2); @@ -165,7 +165,7 @@ modeInfo.eventType = eIRCChannelModeSet; } } - else // it's amode for a user ( like US ) + else // it's a mode for a user (like us) { modeInfo.eventType = eIRCUserModeSet; modeInfo.mode = info.params[1]; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |