summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbill auger <mr.j.spam.me@gmail.com>2013-09-11 02:21:14 -0400
committerbill auger <mr.j.spam.me@gmail.com>2013-09-11 02:21:14 -0400
commitb107d6a1a737267623cf4a89b086525b7737ff6b (patch)
treee8d111c60c8e0d27540d1267a1ddfa5f7f24caae
parentb70b43e1fe21766ed37c743b27c765ac9e216948 (diff)
reimplement chat relay
-rw-r--r--CHANGELOG18
-rw-r--r--README.md18
-rw-r--r--bridgin.c249
-rw-r--r--bridgin.dbg.h14
-rw-r--r--bridgin.h76
5 files changed, 211 insertions, 164 deletions
diff --git a/CHANGELOG b/CHANGELOG
new file mode 100644
index 0000000..52aecbe
--- /dev/null
+++ b/CHANGELOG
@@ -0,0 +1,18 @@
+bridgin changelog
+
+
+2013-09-11 - v0.5pre
+ PENDING
+ reimplemented chat relay
+
+2013-09-08 - v0.5pre
+ b70b43e1fe
+ reimplemented add channel command and status reporting
+
+2013-09-08 - v0.5pre
+ 2babc935b0
+ implement admin command handling
+
+2013-09-07 - v0.5pre
+ 538eef5da2
+ initial commit with echo
diff --git a/README.md b/README.md
index 2c56780..d82c683 100644
--- a/README.md
+++ b/README.md
@@ -35,23 +35,25 @@ it is needed only to simplify building the bridgin plugin
now go make some C(__) and when the build has completed
copy the contents of this repo into ./libpurple/plugins
-cd into ./libpurple/plugins and run the install script
+cd into the plgins dir and run the install script
- chmod a+x ./install && ./install
+ cd ./libpurple/plugins
+ chmod a+x ./install
+ ./install
if your $HOME environment variable is properly set
the install script should reply with the following message
-and pidgin will launch automatically
+and pidgin will launch automatically upon successful installation
"compilation success - installing to YOUR_HOME_DIR/.purple/plugins/"
-check that the install location mentioned points to inside you home dir
-and that the plugin was installed properly
+the bridgin plugin should now be available to pidgin in Tools->Plugins
+if it is not then use this command to check that the plugin was installed
ls $HOME/.purple/plugins/bridgin.so
-if there is no output then you will need to manually copy the file 'bridgin.so'
-into YOUR_HOME_DIR/.purple/plugins/ or /usr/lib/purple-2/
+if there is no output then you will need to manually move the file 'bridgin.so'
+into YOUR_HOME_DIR/.purple/plugins/ or /usr/lib/purple-2/ then restart pidgin
if you are running without X or you do not want pidgin to launch automatically
use this comand to compile and install only
@@ -64,7 +66,7 @@ use this comand to compile only
make bridgin.so
-## window build instructions
+## build instructions for windows
follow [these instructions](https://test.developer.pidgin.im/wiki/BuildingWinPidgin) to build pidgin for windows
then copy the contents of this repo into PIDGIN_SRC_DIR\libpurple\plugins
cd into PIDGIN_SRC_DIR\libpurple\plugins then make and install with:
diff --git a/bridgin.c b/bridgin.c
index 3fb3e13..46fc73a 100644
--- a/bridgin.c
+++ b/bridgin.c
@@ -25,144 +25,147 @@ gboolean isBlank(const char* aCstring) { return (!aCstring || !*aCstring) ; }
Bridge* newBridge(char* bridgeName)
{
- Bridge* bridge ; Channel* channel ;
+ Bridge* aBridge ; Channel* aChannel ;
- bridge = (Bridge*) malloc(sizeof(Bridge)) ; if (!bridge) return NULL ;
- channel = (Channel*)malloc(sizeof(Channel)) ; if (!channel) return NULL ;
+ aBridge = (Bridge*) malloc(sizeof(Bridge)) ; if (!aBridge) return NULL ;
+ aChannel = (Channel*)malloc(sizeof(Channel)) ; if (!aChannel) return NULL ;
- bridge->name = bridgeName ;
- bridge->isEnabled = TRUE ;
- bridge->next = NULL ;
- bridge->sentinelChannel = channel ;
+ aBridge->name = bridgeName ;
+ aBridge->isEnabled = TRUE ;
+ aBridge->next = NULL ;
+ aBridge->sentinelChannel = aChannel ;
- channel->name = "sentinel" ;
- channel->protocol[0] = '\0' ;
- channel->account = NULL ;
- channel->username = "" ;
- channel->conv = NULL ;
- channel->isActive = FALSE ;
- channel->next = NULL ;
+ aChannel->name = "sentinel" ;
+ aChannel->protocol[0] = '\0' ;
+ aChannel->account = NULL ;
+ aChannel->username = "" ;
+ aChannel->conv = NULL ;
+ aChannel->isActive = FALSE ;
+ aChannel->next = NULL ;
- return bridge ;
+ return aBridge ;
}
-Channel* newChannel(PurpleConversation* conv)
+Channel* newChannel(PurpleConversation* aConv)
{
- Channel* channel ; PurpleAccount* account ;
+ Channel* aChannel ; PurpleAccount* anAccount ;
const char* protocol ; char* network ;
- channel = (Channel*)malloc(sizeof(Channel)) ; if (!channel) return NULL ;
+ aChannel = (Channel*)malloc(sizeof(Channel)) ; if (!aChannel) return NULL ;
// append network url to protocol
- account = getAccount(conv) ; protocol = getProtocol(account) ;
- if (!strcmp(protocol , IRC_PROTOCOL) && (network = strstr(getUsername(account) , "@")))
- snprintf(channel->protocol , PROTOCOL_BUFFER_SIZE , "%s%s" , protocol , network) ;
- else strncpy(channel->protocol , protocol , PROTOCOL_BUFFER_SIZE) ;
+ anAccount = getAccount(aConv) ; protocol = getProtocol(anAccount) ;
+ if (!strcmp(protocol , IRC_PROTOCOL) && (network = strstr(getUsername(anAccount) , "@")))
+ snprintf(aChannel->protocol , PROTOCOL_BUFFER_SIZE , "%s%s" , protocol , network) ;
+ else strncpy(aChannel->protocol , protocol , PROTOCOL_BUFFER_SIZE) ;
- channel->name = getChannelName(conv) ;
- channel->account = account ;
- channel->username = getNick(account) ;
- channel->conv = conv ;
- channel->isActive = TRUE ;
- channel->next = NULL ;
+ aChannel->name = getChannelName(aConv) ;
+ aChannel->account = anAccount ;
+ aChannel->username = getNick(anAccount) ;
+ aChannel->conv = aConv ;
+ aChannel->isActive = TRUE ;
+ aChannel->next = NULL ;
- return channel ;
+ return aChannel ;
}
-Bridge* getBridgeByChannel(PurpleConversation* conv)
+Bridge* getBridgeByChannel(PurpleConversation* aConv)
{
- Bridge* bridge ; Channel* channel ;
+ Bridge* aBridge ; Channel* aChannel ;
- bridge = SentinelBridge ;
- while (bridge->next)
+ aBridge = SentinelBridge ;
+ while (aBridge->next)
{
- channel = (bridge = bridge->next)->sentinelChannel ;
- while (channel->next)
- if ((channel = channel->next)->conv == conv)
+ aChannel = (aBridge = aBridge->next)->sentinelChannel ;
+ while (aChannel->next)
+ if ((aChannel = aChannel->next)->conv == aConv)
{
-DBGss("getBridgeByChannel() '" , getChannelName(conv) , "' found" , "") ;
+DBGss("getBridgeByChannel() '" , getChannelName(aConv) , "' found" , "") ;
- return bridge ;
+ return aBridge ;
}
}
-DBGss("getBridgeByChannel() '" , getChannelName(conv) , "' not found" , "") ;
+DBGss("getBridgeByChannel() '" , getChannelName(aConv) , "' not found" , "") ;
return SentinelBridge ;
}
Bridge* getBridgeByName(char* bridgeName)
{
- Bridge* bridge ;
+ Bridge* aBridge ;
- bridge = SentinelBridge ;
- while (bridge->next)
- if (!strcmp((bridge = bridge->next)->name , bridgeName))
+ aBridge = SentinelBridge ;
+ while (aBridge->next)
+ if (!strcmp((aBridge = aBridge->next)->name , bridgeName))
{
DBGss("getBridgeByName() '" , bridgeName , "' found" , "") ;
- return bridge ;
+ return aBridge ;
}
DBGss("getBridgeByName() '" , bridgeName , "' not found" , "") ;
return SentinelBridge ;
}
-const char* getChannelName(PurpleConversation* conv) { return purple_conversation_get_name(conv) ; }
+const char* getChannelName(PurpleConversation* aConv) { return purple_conversation_get_name(aConv) ; }
-const char* getProtocol(PurpleAccount *account) { return purple_account_get_protocol_name(account) ; }
+const char* getProtocol(PurpleAccount* anAccount) { return purple_account_get_protocol_name(anAccount) ; }
-PurpleAccount* getAccount(PurpleConversation* conv) { return purple_conversation_get_account(conv) ; }
+PurpleAccount* getAccount(PurpleConversation* aConv) { return purple_conversation_get_account(aConv) ; }
-const char* getUsername(PurpleAccount *account) { return purple_account_get_username(account) ; }
+const char* getUsername(PurpleAccount* anAccount) { return purple_account_get_username(anAccount) ; }
-const char* getNick(PurpleAccount *account) { return purple_account_get_name_for_display(account) ; }
+const char* getNick(PurpleAccount* anAccount) { return purple_account_get_name_for_display(anAccount) ; }
-void setChannel(char* bridgeName , PurpleConversation* conv)
+gboolean addChannel(char* bridgeName , PurpleConversation* aConv)
{
- Bridge* bridge ; Channel* channel ;
+ Bridge* aBridge ; Channel* aChannel ;
- if ((bridge = getBridgeByName(bridgeName)) == SentinelBridge)
+ if ((aBridge = getBridgeByName(bridgeName)) == SentinelBridge)
{
- while (bridge->next) bridge = bridge->next ;
- bridge->next = newBridge(bridgeName) ; if (!bridge->next) { alert(OOM_MSG) ; return ; }
-
- bridge = bridge->next ;
+ while (aBridge->next) aBridge = aBridge->next ;
+ aBridge->next = newBridge(bridgeName) ;
+ if (aBridge->next) aBridge = aBridge->next ; else { alert(OOM_MSG) ; return FALSE ; }
}
- channel = bridge->sentinelChannel ;
- while (channel->next) channel = channel->next ;
- channel->next = newChannel(conv) ; if (!channel->next) alert(OOM_MSG) ;
+ aChannel = aBridge->sentinelChannel ;
+ while (aChannel->next) aChannel = aChannel->next ;
+ aChannel->next = newChannel(aConv) ;
+ if (!aChannel->next) { alert(OOM_MSG) ; return FALSE ; }
+
+ storeSession() ; return TRUE ;
}
void storeSession() {} // TODO:
unsigned int getNBridges()
{
- Bridge* bridge ; unsigned int n ; bridge = SentinelBridge ; n = 0 ;
- while ((bridge = bridge->next)) ++n ;
+ Bridge* aBridge ; unsigned int n ; aBridge = SentinelBridge ; n = 0 ;
+ while ((aBridge = aBridge->next)) ++n ;
return n ;
}
-unsigned int getNChannels(Bridge* bridge)
+unsigned int getNChannels(Bridge* aBridge)
{
- Channel* channel ; unsigned int n ; channel = bridge->sentinelChannel ; n = 0 ;
- while ((channel = channel->next)) ++n ;
+ Channel* aChannel ; unsigned int n ; aChannel = aBridge->sentinelChannel ; n = 0 ;
+ while ((aChannel = aChannel->next)) ++n ;
return n ;
}
/* event handlers */
-void handlePluginInit(PurplePlugin* plugin) { SentinelBridge = newBridge("sentinel") ; }
+void handlePluginInit(PurplePlugin* plugin)
+ { ChatMutex = TRUE ; SentinelBridge = newBridge("sentinel") ; }
gboolean handlePluginLoaded(PurplePlugin* aPlugin)
{
ThisPlugin = aPlugin ;
- purple_signal_connect(purple_conversations_get_handle() , "received-im-msg" ,
- aPlugin , PURPLE_CALLBACK(handleIm) , NULL) ;
- purple_signal_connect(purple_conversations_get_handle() , "received-chat-msg" ,
+ purple_signal_connect(purple_conversations_get_handle() , RECEIVED_IM_SIGNAL ,
+ aPlugin , PURPLE_CALLBACK(handleChat) , NULL) ;
+ purple_signal_connect(purple_conversations_get_handle() , RECEIVED_CHAT_SIGNAL ,
aPlugin , PURPLE_CALLBACK(handleChat) , NULL) ;
- purple_signal_connect(purple_conversations_get_handle() , "deleting-conversation" ,
+ purple_signal_connect(purple_conversations_get_handle() , CHANNEL_CLOSING_SIGNAL ,
aPlugin , PURPLE_CALLBACK(handleChannelClosed) , NULL) ;
CommandIds[0] = registerCmd(ADD_CMD , UNARY_FMT , ADD_CB , ADDu_HELP) ;
@@ -189,52 +192,60 @@ gboolean handlePluginUnloaded(PurplePlugin* plugin)
return TRUE ;
}
-void handleIm(PurpleAccount* account , char* sender , char* buffer ,
- PurpleConversation* conv , PurpleMessageFlags flags , void* data)
+void handleChat(PurpleAccount* anAccount , char* sender , char* msg ,
+ PurpleConversation* aConv , PurpleMessageFlags flags , void* data)
{
-DBGchat("received-im-msg" , account , sender , conv , buffer , flags , data) ;
+ Bridge* aBridge ; unsigned int convType ; Channel* aChannel ;
-// purple_conv_chat_send(PURPLE_CONV_CHAT(conv) , formatMessage()) ;
-}
-
-void handleChat(PurpleAccount* account , char* sender , char* buffer ,
- PurpleConversation* conv , PurpleMessageFlags flags , void* data)
-{
-DBGchat("received-chat-msg" , account , sender , conv , buffer , flags , data) ;
+DBGchat(((purple_conversation_get_type(aConv) == PURPLE_CONV_TYPE_IM)? RECEIVED_IM_SIGNAL : RECEIVED_CHAT_SIGNAL) , anAccount , sender , aConv , msg , flags , data) ;
if (flags & PURPLE_MESSAGE_SEND) return ;
+ if ((aBridge = getBridgeByChannel(aConv)) == SentinelBridge) return ;
-// purple_conv_chat_send(PURPLE_CONV_CHAT(conv) , formatMessage()) ;
+ chatBufferFillSSSS("%s %s%s %s" , NICK_PREFIX , sender , NICK_POSTFIX , msg) ;
+ convType = purple_conversation_get_type(aConv) ;
+ aChannel = aBridge->sentinelChannel ;
+ while ((aChannel = aChannel->next)) if (aChannel->conv != aConv)
+ {
+ if (convType == PURPLE_CONV_TYPE_IM)
+ purple_conv_im_send(PURPLE_CONV_IM(aChannel->conv) , ChatBuffer) ;
+ else if (convType == PURPLE_CONV_TYPE_CHAT)
+ purple_conv_chat_send(PURPLE_CONV_CHAT(aChannel->conv) , ChatBuffer) ;
+ }
}
-void handleChannelClosed(PurpleConversation* conv , void* data)
+void handleChannelClosed(PurpleConversation* aConv , void* data)
{
-DBGchannelClosed(conv) ;
+DBGchannelClosed(aConv) ;
}
/* admin command handlers */
-PurpleCmdRet handleAddCmd(PurpleConversation* conv , const gchar* command ,
+PurpleCmdRet handleAddCmd(PurpleConversation* aConv , const gchar* command ,
gchar** args , gchar** error , void* data)
{
- char* bridgeName ; Bridge* thisBridge ;
+ char* bridgeName ; Bridge* thisBridge ; unsigned int convType ;
DBGcmd(command , args[0]) ;
+ convType = purple_conversation_get_type(aConv) ;
+ if (convType != PURPLE_CONV_TYPE_IM && convType != PURPLE_CONV_TYPE_CHAT)
+ return PURPLE_CMD_RET_OK ;
+
bridgeName = (isBlank(args[0]))? DEFAULT_BRIDGE_NAME : args[0] ;
- if ((thisBridge = getBridgeByChannel(conv)) != SentinelBridge)
+ if ((thisBridge = getBridgeByChannel(aConv)) != SentinelBridge)
{
- if (thisBridge == getBridgeByName(bridgeName)) addExistsResp(conv , bridgeName) ;
- else addConflictResp(conv) ;
+ if (thisBridge == getBridgeByName(bridgeName)) addExistsResp(aConv , bridgeName) ;
+ else addConflictResp(aConv) ;
}
- else { setChannel(bridgeName , conv) ; storeSession() ; addResp(conv , bridgeName) ; }
+ else if (addChannel(bridgeName , aConv)) addResp(aConv , bridgeName) ;
return PURPLE_CMD_RET_OK ;
}
-PurpleCmdRet handleRemoveCmd(PurpleConversation* conv , const gchar* command ,
+PurpleCmdRet handleRemoveCmd(PurpleConversation* aConv , const gchar* command ,
gchar** args , gchar** error , void* data)
{
DBGcmd(command , args[0]) ;
@@ -242,7 +253,7 @@ DBGcmd(command , args[0]) ;
return PURPLE_CMD_RET_OK ;
}
-PurpleCmdRet handleEnableCmd(PurpleConversation* conv , const gchar* command ,
+PurpleCmdRet handleEnableCmd(PurpleConversation* aConv , const gchar* command ,
gchar** args , gchar** error , void* data)
{
DBGcmd(command , args[0]) ;
@@ -250,7 +261,7 @@ DBGcmd(command , args[0]) ;
return PURPLE_CMD_RET_OK ;
}
-PurpleCmdRet handleEchoCmd(PurpleConversation* conv , const gchar* command ,
+PurpleCmdRet handleEchoCmd(PurpleConversation* aConv , const gchar* command ,
gchar** args , gchar** error , void* data)
{
DBGcmd(command , args[0]) ;
@@ -258,7 +269,7 @@ DBGcmd(command , args[0]) ;
return PURPLE_CMD_RET_OK ;
}
-PurpleCmdRet handleChatCmd(PurpleConversation* conv , const gchar* command ,
+PurpleCmdRet handleChatCmd(PurpleConversation* aConv , const gchar* command ,
gchar** args , gchar** error , void* data)
{
DBGcmd(command , args[0]) ;
@@ -266,7 +277,7 @@ DBGcmd(command , args[0]) ;
return PURPLE_CMD_RET_OK ;
}
-PurpleCmdRet handleBroadcastCmd(PurpleConversation* conv , const gchar* command ,
+PurpleCmdRet handleBroadcastCmd(PurpleConversation* aConv , const gchar* command ,
gchar** args , gchar** error , void* data)
{
DBGcmd(command , args[0]) ;
@@ -274,7 +285,7 @@ DBGcmd(command , args[0]) ;
return PURPLE_CMD_RET_OK ;
}
-PurpleCmdRet handleStatusCmd(PurpleConversation* conv , const gchar* command ,
+PurpleCmdRet handleStatusCmd(PurpleConversation* aConv , const gchar* command ,
gchar** args , gchar** error , void* data)
{
DBGcmd(command , args[0]) ;
@@ -282,7 +293,7 @@ DBGcmd(command , args[0]) ;
return PURPLE_CMD_RET_OK ;
}
-PurpleCmdRet handleHelpCmd(PurpleConversation* conv , const gchar* command ,
+PurpleCmdRet handleHelpCmd(PurpleConversation* aConv , const gchar* command ,
gchar** args , gchar** error , void* data)
{
DBGcmd(command , args[0]) ;
@@ -292,20 +303,22 @@ DBGcmd(command , args[0]) ;
/* admin command responses */
-void addResp(PurpleConversation* conv , char* bridgeName)
+void addResp(PurpleConversation* aConv , char* bridgeName)
{
chatBufferFillSS("%s '%s'" , CH_SET_MSG , bridgeName) ;
- chatBufferDump(conv) ; bridgeStatsMsg(conv , bridgeName) ;
+ chatBufferDump(aConv) ; bridgeStatsMsg(aConv , bridgeName) ;
}
-void addExistsResp(PurpleConversation* conv , char* bridgeName)
+void addExistsResp(PurpleConversation* aConv , char* bridgeName)
{
chatBufferFillSSS("%s %s '%s'" , THIS_CHANNEL_MSG , CHANNEL_EXISTS_MSG , bridgeName) ;
- chatBufferDump(conv) ;
+ chatBufferDump(aConv) ;
}
-void addConflictResp(PurpleConversation* conv)
- { chatBufferFillS("%s" , BRIDGE_CONFLICT_MSG) ; chatBufferDump(conv) ; }
+void addConflictResp(PurpleConversation* aConv)
+{
+ chatBufferFillS("%s" , BRIDGE_CONFLICT_MSG) ; chatBufferDump(aConv) ;
+}
/*
function removeResp($bridgeName)
{
@@ -370,47 +383,47 @@ function defaultResp()
return "$UNKNOWN_MSG '$TRIGGER_PREFIX$trigger'" ;
}
*/
-void bridgeStatsMsg(PurpleConversation* conv , char* bridgeName)
+void bridgeStatsMsg(PurpleConversation* aConv , char* bridgeName)
{
- Bridge* bridge ; Channel* channel ; unsigned int nChars ;
+ Bridge* aBridge ; Channel* aChannel ; unsigned int nChars ;
unsigned int nChannels ; char nchannels[5] ; char* activeMsg ;
DBG("bridgeStatsMsg()") ;
- if ((bridge = getBridgeByName(bridgeName)) == SentinelBridge)
+ if ((aBridge = getBridgeByName(bridgeName)) == SentinelBridge)
{
if (getNBridges()) chatBufferFillSS("\n%s '%s'" , NO_SUCH_BRIDGE_MSG , bridgeName) ;
else chatBufferFillS("\n%s" , NO_BRIDGES_MSG) ;
- chatBufferDump(conv) ; return ;
+ chatBufferDump(aConv) ; return ;
}
nChars = chatBufferFillSS("%s '%s' " , STATS_MSGa , bridgeName) ;
- nChannels = getNChannels(bridge) ;
+ nChannels = getNChannels(aBridge) ;
if (!nChannels) nChars += chatBufferCat(STATS_DELETED_MSG , nChars) ;
else
{
- if (bridge->isEnabled) nChars += chatBufferCat(STATS_ENABLED_MSG , nChars) ;
+ if (aBridge->isEnabled) nChars += chatBufferCat(STATS_ENABLED_MSG , nChars) ;
else nChars += chatBufferCat(STATS_DISABLED_MSG , nChars) ;
snprintf(nchannels , 5 , " %d " , nChannels) ; nChars += 4 ;
nChars += chatBufferCat(nchannels , nChars) ;
nChars += chatBufferCat(STATS_MSGb , nChars) ;
}
- channel = bridge->sentinelChannel ;
- while ((channel = channel->next))
+ aChannel = aBridge->sentinelChannel ;
+ while ((aChannel = aChannel->next))
{
- activeMsg = (channel->isActive)? CH_ACTIVE_MSG : CH_INACTIVE_MSG ;
+ activeMsg = (aChannel->isActive)? CH_ACTIVE_MSG : CH_INACTIVE_MSG ;
nChars += chatBufferCat("\n" , nChars) ;
nChars += chatBufferCat(activeMsg , nChars) ;
nChars += chatBufferCat("'" , nChars) ;
- nChars += chatBufferCat(channel->name , nChars) ;
+ nChars += chatBufferCat(aChannel->name , nChars) ;
nChars += chatBufferCat("' on '" , nChars) ;
- nChars += chatBufferCat(channel->protocol , nChars) ;
+ nChars += chatBufferCat(aChannel->protocol , nChars) ;
nChars += chatBufferCat("' as '" , nChars) ;
- nChars += chatBufferCat(channel->username , nChars) ;
+ nChars += chatBufferCat(aChannel->username , nChars) ;
nChars += chatBufferCat("'" , nChars) ;
}
- chatBufferDump(conv) ;
+ chatBufferDump(aConv) ;
}
/* chat buffer helpers */
@@ -425,6 +438,10 @@ unsigned int chatBufferFillSSS( const char* fmt , const char* s1 , const char*
const char* s3)
{ return snprintf(ChatBuffer , CHAT_BUFFER_SIZE , fmt , s1 , s2 , s3) ; }
+unsigned int chatBufferFillSSSS( const char* fmt , const char* s1 , const char* s2 ,
+ const char* s3 , const char* s4)
+ { return snprintf(ChatBuffer , CHAT_BUFFER_SIZE , fmt , s1 , s2 , s3 , s4) ; }
+
unsigned int chatBufferFillSSSDSD(const char* fmt , const char* s1 , const char* s2 ,
const char* s3 , int d1 , const char* s4 , int d2)
{ return snprintf(ChatBuffer , CHAT_BUFFER_SIZE , fmt , s1 , s2 , s3 , d1 , s4 , d2) ; }
@@ -435,9 +452,9 @@ unsigned int chatBufferCat( const char* msg , unsigned int nChars)
return nChars + strlen(msg) ;
}
-void chatBufferDump(PurpleConversation* conv)
+void chatBufferDump(PurpleConversation* aConv)
{
- purple_conversation_write(conv , BRIDGIN_NICK , ChatBuffer ,
+ purple_conversation_write(aConv , BRIDGIN_NICK , ChatBuffer ,
PURPLE_MESSAGE_SYSTEM , time(0)) ;
}
diff --git a/bridgin.dbg.h b/bridgin.dbg.h
index 6793c6b..b675c93 100644
--- a/bridgin.dbg.h
+++ b/bridgin.dbg.h
@@ -8,17 +8,17 @@ static void DBGs(const char* s1 , const char* s2) { if (isBlank(s1)) return ; pu
static void DBGd(const char* s1 , int d1) { if (isBlank(s1)) return ; purple_debug_misc(PLUGIN_NAME , "%s%d\n" , s1 , d1) ; }
-static void DBGsd(const char* s1 , const char* s2 , const char* s3 , int d1) { if (isBlank(s1)) return ; purple_debug_misc(PLUGIN_NAME , "%s%s%s%d\n" , s1 , s2 , s3 , d1) ; }
-
static void DBGss(const char* s1 , const char* s2 , const char* s3 , const char* s4) { if (isBlank(s1)) return ; purple_debug_misc(PLUGIN_NAME , "%s%s%s%s\n" , s1 , s2 , s3 , s4) ; }
+static void DBGsd(const char* s1 , const char* s2 , const char* s3 , int d1) { if (isBlank(s1)) return ; purple_debug_misc(PLUGIN_NAME , "%s%s%s%d\n" , s1 , s2 , s3 , d1) ; }
+
static void DBGsss(const char* s1 , const char* s2 , const char* s3 , const char* s4 , const char* s5 , const char* s6) { if (isBlank(s1)) return ; purple_debug_misc(PLUGIN_NAME , "%s%s%s%s%s%s\n" , s1 , s2 , s3 , s4 , s5 , s6) ; }
static void DBGsdd(const char* s1 , const char* s2 , const char* s3 , int d1 , const char* s4 , int d2) { if (isBlank(s1)) return ; purple_debug_misc(PLUGIN_NAME , "%s%s%s%d%s%d\n" , s1 , s2 , s3 , d1 , s4 , d2) ; }
static void DBGsssd(const char* s1 , const char* s2 , const char* s3 , const char* s4 , const char* s5 , const char* s6 , const char* s7 , int d1) { if (isBlank(s1)) return ; purple_debug_misc(PLUGIN_NAME , "%s%s%s%s%s%s%s%d\n" , s1 , s2 , s3 , s4 , s5 , s6 , s7 , d1) ; }
-static void DBGchat(char* convType , PurpleAccount* account , char* sender , PurpleConversation* conv , char* msg , PurpleMessageFlags flags , void* data)
+static void DBGchat(char* convType , PurpleAccount* anAccount , char* sender , PurpleConversation* aConv , char* msg , PurpleMessageFlags flags , void* data)
{
// call these from somewhere just to make the compiler stop barking when unused
DBG("") ; DBGs("" , "") ; DBGd("" , 0) ; DBGss("" , "" , "" , "") ; DBGsd("" , "" , "" , 0) ;
@@ -27,12 +27,12 @@ static void DBGchat(char* convType , PurpleAccount* account , char* sender , Pur
purple_debug_misc(PLUGIN_NAME ,
"%s from %s\n\taccount = %d\n\tsender = %s\n\tchannel = %s (%d)\n\tmessage = %s\n\tflags = %d\n\tdata = %d\n%s" ,
- convType , sender , (int)account , sender , ((conv != NULL) ? purple_conversation_get_name(conv) : "(null)") ,
- (int)conv , msg , flags , (int)data , ((flags & PURPLE_MESSAGE_SEND)? "loopback - dropping" : "")) ;
+ convType , sender , (int)anAccount , sender , ((aConv != NULL) ? purple_conversation_get_name(aConv) : "(null)") ,
+ (int)aConv , msg , flags , (int)data , ((flags & PURPLE_MESSAGE_SEND)? "loopback - dropping" : "")) ;
}
-static void DBGchannelClosed(PurpleConversation* conv)
- { purple_debug_misc(PLUGIN_NAME , "deleting-conversation (%s)\n" , purple_conversation_get_name(conv)) ; }
+static void DBGchannelClosed(PurpleConversation* aConv)
+ { purple_debug_misc(PLUGIN_NAME , "deleting-conversation (%s)\n" , purple_conversation_get_name(aConv)) ; }
static void DBGcmd(const char* command , char* args)
{ purple_debug_misc(PLUGIN_NAME , "HandleCmd '/%s' args = %s\n" , command , args) ; }
diff --git a/bridgin.h b/bridgin.h
index 9113f9b..5d952c7 100644
--- a/bridgin.h
+++ b/bridgin.h
@@ -6,7 +6,7 @@
#define PLUGIN_GUI_TYPE NULL
#define PLUGIN_ID "core-mr-jonze-bridgin"
#define PLUGIN_NAME "bridgin"
-#define PLUGIN_VERSION "0.5s"
+#define PLUGIN_VERSION "0.5pre"
#define PLUGIN_SHORT_DESC "short description"
#define PLUGIN_LONG_DESC "long description"
#define PLUGIN_AUTHOR "bill auger <mr.j.spam.me@gmail.com>"
@@ -17,6 +17,8 @@
// app constants
#define BRIDGIN_NICK "BRIDGIN"
#define DEFAULT_BRIDGE_NAME "default"
+#define NICK_PREFIX "(from" // dont use '<' some clients will supress it as html
+#define NICK_POSTFIX ")"
// admin commands
#define N_COMMANDS 13
@@ -74,6 +76,11 @@
#define PROTOCOL_BUFFER_SIZE 256
#define IRC_PROTOCOL "IRC"
+// purple constants
+#define RECEIVED_IM_SIGNAL "received-im-msg"
+#define RECEIVED_CHAT_SIGNAL "received-chat-msg"
+#define CHANNEL_CLOSING_SIGNAL "deleting-conversation"
+
#include <string.h>
@@ -104,75 +111,78 @@ typedef struct Bridge
struct Bridge* next ;
} Bridge ;
-static PurplePluginInfo PluginInfo ;
-static PurplePlugin* ThisPlugin ;
-static PurpleCmdId CommandIds[N_COMMANDS] ;
+static PurplePluginInfo PluginInfo ; // init pre main()
+static PurplePlugin* ThisPlugin ; // init on handlePluginLoaded()
+static PurpleCmdId CommandIds[N_COMMANDS] ; // init on handlePluginLoaded()
static char ChatBuffer[CHAT_BUFFER_SIZE] ;
-static Bridge* SentinelBridge ;
+static gboolean ChatMutex ; // init on handlePluginInit()
+static Bridge* SentinelBridge ; // init on handlePluginInit()
// helpers
PurpleCmdId registerCmd( const char* command , const char* format ,
- PurpleCmdRet (* callback)() , const char* help) ;
+ PurpleCmdRet (*callback)() , const char* help) ;
void alert( char* msg) ;
gboolean isBlank( const char* aCstring) ;
// model helpers
Bridge* newBridge( char* bridgeName) ;
-Channel* newChannel( PurpleConversation* conv) ;
-Bridge* getBridgeByChannel(PurpleConversation* conv) ;
+Channel* newChannel( PurpleConversation* aConv) ;
+Bridge* getBridgeByChannel(PurpleConversation* aConv) ;
Bridge* getBridgeByName( char* bridgeName) ;
-const char* getChannelName( PurpleConversation* conv) ;
-const char* getProtocol( PurpleAccount *account) ;
-PurpleAccount* getAccount( PurpleConversation* conv) ;
-const char* getUsername( PurpleAccount *account) ;
-const char* getNick( PurpleAccount *account) ;
-void setChannel( char* bridgeName , PurpleConversation* conv) ;
+const char* getChannelName( PurpleConversation* aConv) ;
+const char* getProtocol( PurpleAccount* anAccount) ;
+PurpleAccount* getAccount( PurpleConversation* aConv) ;
+const char* getUsername( PurpleAccount* anAccount) ;
+const char* getNick( PurpleAccount* anAccount) ;
+gboolean addChannel( char* bridgeName , PurpleConversation* aConv) ;
void storeSession( void) ;
unsigned int getNBridges( void) ;
-unsigned int getNChannels(Bridge* bridge) ;
+unsigned int getNChannels(Bridge* aBridge) ;
// event handlers
void handlePluginInit( PurplePlugin* plugin) ;
gboolean handlePluginLoaded( PurplePlugin* plugin) ;
gboolean handlePluginUnloaded(PurplePlugin* plugin) ;
-void handleIm( PurpleAccount* account , char* sender ,
- char* buffer , PurpleConversation* conv ,
+void handleIm( PurpleAccount* anAccount , char* sender ,
+ char* buffer , PurpleConversation* aConv ,
PurpleMessageFlags flags , void* data) ;
-void handleChat( PurpleAccount* account , char* sender ,
- char* buffer , PurpleConversation* conv ,
+void handleChat( PurpleAccount* anAccount , char* sender ,
+ char* buffer , PurpleConversation* aConv ,
PurpleMessageFlags flags , void* data) ;
-void handleChannelClosed( PurpleConversation* conv, void *data) ;
+void handleChannelClosed( PurpleConversation* aConv, void *data) ;
// admin command handlers */
-PurpleCmdRet handleAddCmd( PurpleConversation* conv , const gchar* cmd ,
+PurpleCmdRet handleAddCmd( PurpleConversation* aConv , const gchar* cmd ,
gchar** args , gchar** error , void* data) ;
-PurpleCmdRet handleRemoveCmd( PurpleConversation* conv , const gchar* cmd ,
+PurpleCmdRet handleRemoveCmd( PurpleConversation* aConv , const gchar* cmd ,
gchar** args , gchar** error , void* data) ;
-PurpleCmdRet handleEnableCmd( PurpleConversation* conv , const gchar* cmd ,
+PurpleCmdRet handleEnableCmd( PurpleConversation* aConv , const gchar* cmd ,
gchar** args , gchar** error , void* data) ;
-PurpleCmdRet handleEchoCmd( PurpleConversation* conv , const gchar* cmd ,
+PurpleCmdRet handleEchoCmd( PurpleConversation* aConv , const gchar* cmd ,
gchar** args , gchar** error , void* data) ;
-PurpleCmdRet handleChatCmd( PurpleConversation* conv , const gchar* cmd ,
+PurpleCmdRet handleChatCmd( PurpleConversation* aConv , const gchar* cmd ,
gchar** args , gchar** error , void* data) ;
-PurpleCmdRet handleBroadcastCmd(PurpleConversation* conv , const gchar* cmd ,
+PurpleCmdRet handleBroadcastCmd(PurpleConversation* aConv , const gchar* cmd ,
gchar** args , gchar** error , void* data) ;
-PurpleCmdRet handleStatusCmd( PurpleConversation* conv , const gchar* cmd ,
+PurpleCmdRet handleStatusCmd( PurpleConversation* aConv , const gchar* cmd ,
gchar** args , gchar** error , void* data) ;
-PurpleCmdRet handleHelpCmd( PurpleConversation* conv , const gchar* cmd ,
+PurpleCmdRet handleHelpCmd( PurpleConversation* aConv , const gchar* cmd ,
gchar** args , gchar** error , void* data) ;
// admin command responses
-void chatBufferDump( PurpleConversation* conv) ;
-void addResp( PurpleConversation* conv , char* bridgeName) ;
-void addExistsResp( PurpleConversation* conv , char* bridgeName) ;
-void addConflictResp(PurpleConversation* conv) ;
-void bridgeStatsMsg( PurpleConversation* conv , char* bridgeName) ;
+void chatBufferDump( PurpleConversation* aConv) ;
+void addResp( PurpleConversation* aConv , char* bridgeName) ;
+void addExistsResp( PurpleConversation* aConv , char* bridgeName) ;
+void addConflictResp(PurpleConversation* aConv) ;
+void bridgeStatsMsg( PurpleConversation* aConv , char* bridgeName) ;
// chat buffer helpers
unsigned int chatBufferFillS( const char* fmt , const char* s1) ;
unsigned int chatBufferFillSS( const char* fmt , const char* s1 , const char* s2) ;
unsigned int chatBufferFillSSS( const char* fmt , const char* s1 , const char* s2 ,
const char* s3) ;
+unsigned int chatBufferFillSSSS( const char* fmt , const char* s1 , const char* s2 ,
+ const char* s3 , const char* s4) ;
unsigned int chatBufferFillSSSDSD(const char* fmt , const char* s1 , const char* s2 ,
const char* s3 , int d1 , const char* s4 , int d2) ;
unsigned int chatBufferCat( const char* msg , unsigned int nChars) ;