summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbill auger <mr.j.spam.me@gmail.com>2013-09-25 03:51:56 -0400
committerbill auger <mr.j.spam.me@gmail.com>2013-09-25 03:51:56 -0400
commit7fcff3ee355086e881b98063193352eb2c75bea1 (patch)
treebc7baeab2abcfba580dbe0be2e621154625d2a3f
parent84279125be4e12b463f7b99124696efb8292ea90 (diff)
transpose model and state solely to purple prefs
-rw-r--r--CHANGELOG5
-rw-r--r--TODO18
-rw-r--r--bridgin.c638
-rw-r--r--bridgin.dbg.h67
-rw-r--r--bridgin.h110
-rwxr-xr-xinstall.sh (renamed from install)0
6 files changed, 280 insertions, 558 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 2acc3e0..1ae1bd5 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,11 @@
bridgin changelog
+2013-09-25 - v0.5
+ CURRENT
+ removed internal model mirror structs relying solely on purple prefs for state
+ this fixed issue #1
+
2013-09-23 - v0.5pre
897a50cdfa
reimplemented help command and refactored remaining MVC concerns
diff --git a/TODO b/TODO
new file mode 100644
index 0000000..f4da7ad
--- /dev/null
+++ b/TODO
@@ -0,0 +1,18 @@
+
+high-priority TODOs:
+ * ensure the ./install.sh script still works
+
+
+potential features:
+ * (in progress) GUI prefs though not particularly useful but perhaps just for fun
+ * proper handling of special forms - e.g. /me
+ * /?who command (for all users) to list users on other networks
+ * centralized server-side auth to manage/block multiple instances in same channels
+ * compile and/or package binaries and/or find a debian sponsor
+
+
+low-priority TODOs:
+ * refactor the inner activeChannelsIter loop in bridgeStatsMsg() into an array of char* outside the bridged channels loop
+ * refactor the inner loop of getBridgeName() into a findChannel() yield callback to g_find_custom on prefslist
+ * handle empty input strings avoiding responses such as "no such bridge ' '" either one by one
+ or refactor all command handlers into a dispatch function
diff --git a/bridgin.c b/bridgin.c
index 944056f..90f2117 100644
--- a/bridgin.c
+++ b/bridgin.c
@@ -2,6 +2,20 @@
#include "bridgin.dbg.h"
+/* globals */
+
+static char* Commands[N_UNIQ_CMDS] = COMMANDS ;
+static unsigned int NRelayChannels = 0 ;
+static PurplePluginInfo PluginInfo =
+{
+ PURPLE_PLUGIN_MAGIC , PURPLE_MAJOR_VERSION , PURPLE_MINOR_VERSION ,
+ PLUGIN_TYPE , PLUGIN_GUI_TYPE , 0 , NULL , PURPLE_PRIORITY_DEFAULT ,
+ PLUGIN_ID , PLUGIN_NAME , PLUGIN_VERSION , PLUGIN_SHORT_DESC , PLUGIN_LONG_DESC ,
+ PLUGIN_AUTHOR , PLUGIN_WEBSITE , PLUGIN_ONLOAD_CB , PLUGIN_ONUNLOAD_CB ,
+ NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL
+} ;
+
+
/* purple helpers */
PurpleCmdId registerCmd(const char* command , const char* format ,
@@ -10,64 +24,7 @@ PurpleCmdId registerCmd(const char* command , const char* format ,
return purple_cmd_register(command , format , PURPLE_CMD_P_DEFAULT ,
PURPLE_CMD_FLAG_IM | PURPLE_CMD_FLAG_CHAT , PLUGIN_ID , callback , help , NULL) ;
}
-/*
-gboolean restoreSession()
-{
- GList* prefsList ; GList* prefsIter ; const char* prefKey ; char* bridgeName ;
- GList* channelsList ; GList* channelsIter ;
-
- SentinelBridge = newBridge(SENTINEL_NAME , NULL , FALSE) ;
- if (!SentinelBridge) { alert(OOM_MSG) ; return FALSE ; }
-
- prefsList = purple_prefs_get_children_names(BASE_PREF_KEY) ;
- prefsIter = g_list_first(prefsList) ;
- while (prefsIter)
- {
-#ifdef DEBUG_VB
-if (purple_prefs_get_type((char*)prefsIter->data) == PURPLE_PREF_BOOLEAN)
- DBGsds("restoreSession() found bool prefKey='" , (char*)prefsIter->data , "' val='" , purple_prefs_get_bool((char*)prefsIter->data) , "'" , "") ;
-else if (purple_prefs_get_type((char*)prefsIter->data) == PURPLE_PREF_STRING)
- DBGsss("restoreSession() found string prefKey='" , (char*)prefsIter->data , "' val='" , purple_prefs_get_string((char*)prefsIter->data) , "'" , "") ;
-#endif
-
- prefKey = (char*)prefsIter->data ;
- if (purple_prefs_get_type(prefKey) == PURPLE_PREF_STRING_LIST &&
- (bridgeName = strrchr(prefKey , '/')) && ++bridgeName)
- {
-#ifdef DEBUG_VB
-DBGss("restoreSession() found stored bridgeName='" , bridgeName , "'" , "") ;
-#endif
-
- channelsList = purple_prefs_get_string_list(prefKey) ;
- channelsIter = g_list_first(channelsList) ;
- while (channelsIter)
- {
-#ifdef DEBUG_VB
-DBGss("restoreSession() found stored channelUid='" , (char*)channelsIter->data , "'" , "") ;
-#endif
-
- strcpy(ChannelUidBuffer , (char*)channelsIter->data) ;
- if (!createChannel(bridgeName , TRUE))
- {
- // malloc error - cleanup and bail
- g_list_free(channelsList) ; g_list_free(channelsIter) ;
- g_list_free(prefsList) ; g_list_free(prefsIter) ;
- alert(OOM_MSG) ; return FALSE ;
- }
-
- channelsIter = g_list_next(channelsIter) ;
- }
- g_list_free(channelsList) ; g_list_free(channelsIter) ;
- }
-
- prefsIter = g_list_next(prefsIter) ;
- }
- g_list_foreach(prefsList , (GFunc)g_free , NULL) ;
- g_list_free(prefsList) ; g_list_free(prefsIter) ;
- return TRUE ;
-}
-*/
void registerCommands()
{
CommandIds[0] = registerCmd(ADD_CMD , UNARY_FMT , ADD_CB , ADDu_HELP) ;
@@ -109,21 +66,7 @@ void unregisterCallbacks()
purple_signal_disconnect(purple_conversations_get_handle() , RECEIVING_CHAT_SIGNAL ,
ThisPlugin , PURPLE_CALLBACK(CHAT_RECV_CB)) ;
}
-/*
-void destroySession()
-{
- Bridge* aBridge ; Channel* aChannel ;
- aBridge = SentinelBridge ;
- while ((aBridge = aBridge->next))
- {
- aChannel = aBridge->sentinelChannel ;
- while ((aChannel = aChannel->next)) free(aChannel->prev) ;
- free(aChannel) ; free(aBridge->prev) ;
- }
- free(aBridge) ;
-}
-*/
const char* getChannelName(PurpleConversation* aConv)
{ return purple_conversation_get_name(aConv) ; }
@@ -139,25 +82,6 @@ const char* getUsername(PurpleAccount* anAccount)
const char* getNick(PurpleConversation* aConv)
{ return purple_account_get_name_for_display(getAccount(aConv)) ; }
-//unsigned int getNRelayChannels(Bridge* thisBridge , PurpleConversation* thisConv)
-void getNRelayChannels(char* thisBridgeName , PurpleConversation* thisConv)
-{
-// NOTE: inputConv will be excluded from the count - pass in NULL to include it
-
- GList* activeChannelsIter ; PurpleConversation* aConv ;
- char aBridgeName[SM_BUFFER_SIZE] ;
-
- activeChannelsIter = g_list_first(purple_get_conversations()) ; NRelayChannels = 0 ;
- while (activeChannelsIter)
- {
- aConv = (PurpleConversation*)activeChannelsIter->data ;
-// if (aConv != thisConv && getBridgeName(aConv) == thisBridge) ++nChannels ;
- getBridgeName(aConv , aBridgeName) ;
- if (aConv != thisConv && aBridgeName == thisBridgeName) ++NRelayChannels ;
- activeChannelsIter = g_list_next(activeChannelsIter) ;
- }
-}
-
/* model helpers */
@@ -179,116 +103,56 @@ void prepareChannelUid(PurpleConversation* aConv)
sprintf(ChannelUidBuffer , CHANNEL_UID_FMT , protocol , username , channelName) ;
}
-gint isThisChanne(gconstpointer a , gconstpointer b)
- { return strcmp((char*)a , (char*)b) ; }
-
-//Bridge* getBridgeName(PurpleConversation* aConv)
-void getBridgeName(PurpleConversation* aConv , char* thisBridgeNameBuffer)
-{
-/*
- Bridge* aBridge ; Channel* aChannel ;
+gint isMatch(gconstpointer a , gconstpointer b) { return strcmp((char*)a , (char*)b) ; }
-#ifdef DEBUG_VB
-prepareChannelUid(aConv) ; DBGss("getBridgeName() channel='" , ChannelUidBuffer , "'" , "") ;
-#endif
+void prefKey2Name(const char* prefKey , char* nameBuffer)
+ { snprintf(nameBuffer , SM_BUFFER_SIZE , "%s" , strrchr(prefKey , '/') + 1) ; }
- aBridge = SentinelBridge ; prepareChannelUid(aConv) ;
- while ((aBridge = aBridge->next))
- {
- aChannel = aBridge->sentinelChannel ;
- while ((aChannel = aChannel->next))
+void getBridgeName(PurpleConversation* aConv , char* bridgeNameBuffer)
{
-DBGsd("getBridgeName() aChannel->uid=" , aChannel->uid , " found=" , (!strcmp(aChannel->uid , ChannelUidBuffer))) ;
-
- if (!strcmp(aChannel->uid , ChannelUidBuffer))
- return aBridge ;
-}
- }
-
-#ifdef DEBUG_VB
-DBGss("getBridgeName() '" , ChannelUidBuffer , "' not found" , "") ;
-#endif
-
- return SentinelBridge ;
-*/
GList* prefsList ; GList* prefsIter ; char* prefKey ; GList* channelsList ;
- prepareChannelUid(aConv) ; thisBridgeNameBuffer[0] = '\0' ;
+ // search for this channelUid
+ prepareChannelUid(aConv) ; bridgeNameBuffer[0] = '\0' ;
prefsList = purple_prefs_get_children_names(BASE_PREF_KEY) ;
prefsIter = g_list_first(prefsList) ;
while (prefsIter)
{
-#ifdef DEBUG_VB
-if (purple_prefs_get_type((char*)prefsIter->data) == PURPLE_PREF_BOOLEAN)
+#if DEBUG_LOGIC
+if (purple_prefs_get_type((char*)prefsIter->data) == PURPLE_PREF_STRING_LIST)
+ DBGss("getBridgeName() found stored bridgeName='" , strrchr((char*)prefsIter->data , '/') + 1 , "'" , "") ;
+#endif
+#if DEBUG_VB
+else if (purple_prefs_get_type((char*)prefsIter->data) == PURPLE_PREF_BOOLEAN)
DBGsds("getBridgeName() found bool prefKey='" , (char*)prefsIter->data , "' val='" , purple_prefs_get_bool((char*)prefsIter->data) , "'" , "") ;
else if (purple_prefs_get_type((char*)prefsIter->data) == PURPLE_PREF_STRING)
DBGsss("getBridgeName() found string prefKey='" , (char*)prefsIter->data , "' val='" , purple_prefs_get_string((char*)prefsIter->data) , "'" , "") ;
-else if (purple_prefs_get_type((char*)prefsIter->data) == PURPLE_PREF_STRING_LIST)
- DBGss("getBridgeName() found stored bridgeName='" , (strrchr((char*)prefsIter->data , '/') + 1 ) , "'" , "") ;
#endif
prefKey = (char*)prefsIter->data ;
- if (isValidChannelsPref(prefKey))
- {
-#ifdef DEBUG_VB
-DBGs("getBridgeName() isValidChannelsPref() prefKey=" , prefKey) ;
-#endif
+ if (!isChannelsPref(prefKey)) { prefsIter = g_list_next(prefsIter) ; continue ; }
- channelsList = purple_prefs_get_string_list(prefKey) ;
- if (g_list_find_custom(channelsList , ChannelUidBuffer , (GCompareFunc)isThisChanne))
- {
-#ifdef DEBUG_VB
-DBGs("getBridgeName() found channel=" , ChannelUidBuffer) ;
-#endif
+ // set bridgeNameBuffer to channelUid if found
+ channelsList = purple_prefs_get_string_list(prefKey) ;
+ if (g_list_find_custom(channelsList , ChannelUidBuffer , (GCompareFunc)isMatch))
+ prefKey2Name(prefKey , bridgeNameBuffer) ;
- strncpy(thisBridgeNameBuffer , strrchr(prefKey , '/') + 1 , SM_BUFFER_SIZE) ;
- }
-#ifdef DEBUG_VB
-else DBGs("getBridgeName() not found channel=" , ChannelUidBuffer) ;
+#if DEBUG_LOGIC
+if (g_list_find_custom(channelsList , ChannelUidBuffer , (GCompareFunc)isMatch))
+ DBGsss("getBridgeName() found channel=" , ChannelUidBuffer , "' on bridgeName='" , bridgeNameBuffer , "'" , "") ;
#endif
- }
-#ifdef DEBUG_VB
-else DBGs("getBridgeName() not isValidChannelsPref() prefKey=" , prefKey) ;
+#if DEBUG_VB
+else DBGsss("getBridgeName() not found channel='" , ChannelUidBuffer , "' on bridgeName='" , bridgeNameBuffer , "'" , "") ;
#endif
prefsIter = g_list_next(prefsIter) ;
}
g_list_foreach(prefsList , (GFunc)g_free , NULL) ;
- g_list_free(prefsList) ; g_list_free(prefsIter) ;
-}
-
-/*
-Bridge* getBridgeByName(const char* bridgeName)
-{
-//return SentinelBridge ;
-
- Bridge* aBridge = SentinelBridge ; if (isBlank(bridgeName)) return SentinelBridge ;
-
- while ((aBridge = aBridge->next))
-{
-DBGssd("getBridgeByName() bridgeName=" , bridgeName , " aBridge->name=" , aBridge->name , " found=" , (!strcmp(aBridge->name , bridgeName))) ;
-
- if (!strcmp(aBridge->name , bridgeName))
- return aBridge ;
+ g_list_free(prefsIter) ; g_list_free(prefsList) ;
}
-#ifdef DEBUG_VB
-DBGsds("getBridgeByName() '" , bridgeName , "' not found - " , getNBridges() , " bridges exist" , "") ;
-#endif
- return SentinelBridge ;
-}
-*/
unsigned int getNBridges()
{
-/*
- Bridge* aBridge ; unsigned int n ;
-
- aBridge = SentinelBridge ; n = 0 ; while ((aBridge = aBridge->next)) ++n ;
-
-DBGd("getNBridges() nBridges=" , n) ;
-
- return n ;
-*/
GList* prefsList ; unsigned int nBridges ;
prefsList = purple_prefs_get_children_names(BASE_PREF_KEY) ;
@@ -299,32 +163,44 @@ DBGd("getNBridges() nBridges=" , n) ;
return nBridges ;
}
-// unsigned int getNChannels(Bridge* aBridge)
unsigned int getNChannels(const char* bridgePrefKey)
{
-/*
- Channel* aChannel ; unsigned int n ;
-
- aChannel = aBridge->sentinelChannel ; n = 0 ; while ((aChannel = aChannel->next)) ++n ;
-
-if (aBridge) DBGd("getNChannels() nChannels=" , n) ; else DBG("getNChannels() bridge nfg") ;
-
- return n ;
-*/
GList* channelsList ; unsigned int nChannels ;
channelsList = purple_prefs_get_string_list(bridgePrefKey) ;
nChannels = g_list_length(channelsList) ;
- g_list_free(channelsList) ;
return nChannels ;
}
-/*
-gboolean doesBridgeExist(Bridge* aBridge)
- { return (!!aBridge && aBridge != SentinelBridge) ; }
-*/
+
+void getNRelayChannels(char* bridgePrefKey , PurpleConversation* thisConv)
+{
+// NOTE: thisConv will be excluded from the count - pass in NULL to include it
+
+ GList* activeChannelsIter ; PurpleConversation* aConv ;
+ char thisBridgeName[SM_BUFFER_SIZE] ; char aBridgeName[SM_BUFFER_SIZE] ;
+
+ prefKey2Name(bridgePrefKey , thisBridgeName) ;
+ if (!isChannelsPref(bridgePrefKey)) return ;
+
+ activeChannelsIter = g_list_first(purple_get_conversations()) ;
+ while (activeChannelsIter)
+ {
+ aConv = (PurpleConversation*)activeChannelsIter->data ;
+ getBridgeName(aConv , aBridgeName) ;
+ if (aConv != thisConv && !strcmp(aBridgeName , thisBridgeName)) ++NRelayChannels ;
+ activeChannelsIter = g_list_next(activeChannelsIter) ;
+ }
+}
+
+gboolean isChannelsPref(const char* bridgePrefKey)
+{
+ return (purple_prefs_exists(bridgePrefKey) &&
+ purple_prefs_get_type(bridgePrefKey) == PURPLE_PREF_STRING_LIST) ;
+}
+
gboolean doesBridgeExist(const char* bridgeName)
- { prepareBridgeKeys(bridgeName) ; return purple_prefs_exists(BridgeKeyBuffer) ; }
+ { prepareBridgeKeys(bridgeName) ; return isChannelsPref(BridgeKeyBuffer) ; }
gboolean isBridgeEnabled(const char* bridgeName)
{
@@ -336,135 +212,55 @@ gboolean isBridgeEnabled(const char* bridgeName)
gboolean isChannelBridged(PurpleConversation* aConv)
{
char thisBridgeName[SM_BUFFER_SIZE] ; getBridgeName(aConv , thisBridgeName) ;
- return isBlank(thisBridgeName) ;
+ return !isBlank(thisBridgeName) ;
}
gboolean areReservedIds(char* bridgeName , char* channelUid , const char* channelName)
{
- return (!strcmp(bridgeName , SENTINEL_NAME) ||
- !strcmp(channelUid , SENTINEL_NAME) ||
- !strcmp(channelName , "NickServ") ||
+ return (!strcmp(bridgeName , "") || // TODO: better validations?
+ !strcmp(channelUid , "") ||
+ !strcmp(channelName , "NickServ") ||
!strcmp(channelName , "MemoServ")) ;
}
-gboolean isValidChannelsPref(const char* bridgePrefKey)
- { return (purple_prefs_get_type(bridgePrefKey) == PURPLE_PREF_STRING_LIST) ; }
-
-/*
-Bridge* newBridge(char* bridgeName , Bridge* prevBridge , gboolean isEnabled)
-{
- Bridge* newBridge ; Channel* newChannel ;
-
- newBridge = (Bridge*) malloc(sizeof(Bridge)) ; if (!newBridge) return NULL ;
- newChannel = (Channel*)malloc(sizeof(Channel)) ; if (!newChannel) return NULL ;
-
- strcpy(newBridge->name , bridgeName) ;
- newBridge->isEnabled = isEnabled ;
- newBridge->prev = prevBridge ;
- newBridge->next = NULL ;
- newBridge->sentinelChannel = newChannel ;
-
- strcpy(newChannel->uid , SENTINEL_NAME) ;
- newChannel->next = NULL ;
-
- return newBridge ;
-}
-
-Channel* newChannel(Channel* prevChannel)
-{
- Channel* newChannel ;
-
- newChannel = (Channel*)malloc(sizeof(Channel)) ; if (!newChannel) return NULL ;
-
- strcpy(newChannel->uid , ChannelUidBuffer) ;
- newChannel->prev = prevChannel ;
- newChannel->next = NULL ;
-
- return newChannel ;
-}
-*/
-//gboolean createChannel(char* bridgeName , gboolean isStored)
void createChannel(char* bridgeName)
{
-// Bridge* aBridge ; Channel* aChannel ;
-GList* channelsList = NULL ;
+ GList* channelsList = NULL ;
-#ifdef DEBUG_VB
+#if DEBUG_VB
DBGss("createChannel() bridgeName='" , bridgeName , "'" , "") ;
#endif
prepareBridgeKeys(bridgeName) ;
- // create bridge if necessary
-// if (!doesBridgeExist(aBridge = getBridgeByName(bridgeName)))
+ // add bridge to store if necessary
if (!doesBridgeExist(bridgeName))
{
-/*
- // restore stored state
- gboolean isEnabled = (!isStored || purple_prefs_get_bool(EnabledKeyBuffer)) ;
-
- // create new bridge struct
- while (aBridge->next) aBridge = aBridge->next ;
- aBridge->next = newBridge(bridgeName , aBridge , isEnabled) ;
- if (!(aBridge = aBridge->next)) return FALSE ;
-
- // store bridge
- if (!isStored)
- {
-*/
- purple_prefs_add_bool(EnabledKeyBuffer , TRUE) ;
- purple_prefs_add_string_list(BridgeKeyBuffer , channelsList) ;
+ purple_prefs_add_bool(EnabledKeyBuffer , TRUE) ;
+ purple_prefs_add_string_list(BridgeKeyBuffer , channelsList) ;
+#if DEBUG_LOGIC
DBGss("createChannel() added new bridgeKey='" , BridgeKeyBuffer , "'" , "") ;
-// }
-
-//DBGss("createChannel() added new bridge struct='" , BridgeKeyBuffer , "'" , "") ;
+#endif
}
-/*
- // create new channel struct
- aChannel = aBridge->sentinelChannel ;
- while (aChannel->next) aChannel = aChannel->next ;
- if (!(aChannel->next = newChannel(aChannel))) return FALSE ;
-
- // store new channel
- if (!isStored)
- {
-*/
- channelsList = purple_prefs_get_string_list(BridgeKeyBuffer) ;
- channelsList = g_list_prepend(channelsList , (gpointer)ChannelUidBuffer) ;
- purple_prefs_set_string_list(BridgeKeyBuffer , channelsList) ;
- g_list_free(channelsList) ;
-
-DBGss("createChannel() added new channelUid='" , ChannelUidBuffer , "'" , "") ;
-// }
-//DBGss("createChannel() added new Channel struct='" , strrchr(ChannelUidBuffer , ':') , "'" , "") ;
+ // add channel to store
+ channelsList = purple_prefs_get_string_list(BridgeKeyBuffer) ;
+ channelsList = g_list_prepend(channelsList , (gpointer)ChannelUidBuffer) ;
+ purple_prefs_set_string_list(BridgeKeyBuffer , channelsList) ;
-// return TRUE ;
+#if DEBUG_LOGIC
+DBGss("createChannel() added new channelUid='" , ChannelUidBuffer , "'" , "") ;
+#endif
}
-//static int DBGN = 0 ;
-//if (!DBGN) { ++DBGN ; //else return PURPLE_CMD_RET_OK ;
-//void destroyChannel(Bridge* aBridge , PurpleConversation* aConv)
+
void destroyChannel(PurpleConversation* aConv)
{
-// Channel* aChannel ; GList* channelsList = NULL ; GList* channelsIter = NULL ;
GList* channelsList = NULL ; GList* channelsIter = NULL ;
char thisBridgeName[SM_BUFFER_SIZE] ; getBridgeName(aConv , thisBridgeName) ;
-/*
- // destroy channel struct
- aChannel = aBridge->sentinelChannel ; prepareChannelUid(aConv) ;
- while ((aChannel = aChannel->next))
- if (!strcmp(aChannel->uid , ChannelUidBuffer))
- { aChannel->prev->next = aChannel->next ; free(aChannel) ; break ; }
// remove channel from store
- prepareBridgeKeys(aBridge->name) ;
-*/
prepareBridgeKeys(thisBridgeName) ; prepareChannelUid(aConv) ;
-
-DBGd("destroyChannel() nChannels IN=" , getNChannels(BridgeKeyBuffer)) ;
-DBGd("destroyChannel() nBridges IN=" , getNBridges()) ;
-
channelsList = purple_prefs_get_string_list(BridgeKeyBuffer) ;
channelsIter = g_list_first(channelsList) ;
while (channelsIter)
@@ -475,39 +271,33 @@ DBGd("destroyChannel() nBridges IN=" , getNBridges()) ;
}
else channelsIter = g_list_next(channelsIter) ;
purple_prefs_set_string_list(BridgeKeyBuffer , channelsList) ;
- g_list_free(channelsList) ; g_list_free(channelsIter) ;
+#if DEBUG_LOGIC
DBGssss("destroyChannel() removed channel='" , getChannelName(aConv) , "' from bridge='" , thisBridgeName , ((getNChannels(BridgeKeyBuffer))? "" : "' also removing bridge='") , ((getNChannels(BridgeKeyBuffer))? "" : thisBridgeName) , "'" , "") ;
-DBGd("destroyChannel() nChannels OUT=" , getNChannels(BridgeKeyBuffer)) ;
+#endif
- // destroy empty bridge struct and storage
-// if (!getNChannels(aBridge))
- if (!getNChannels(BridgeKeyBuffer))
- {
-// aBridge->prev->next = aBridge->next ; free(aBridge) ;
- purple_prefs_remove(BridgeKeyBuffer) ; purple_prefs_remove(EnabledKeyBuffer) ;
- }
+ if (getNChannels(BridgeKeyBuffer)) return ;
-DBGd("destroyChannel() nBridges OUT=" , getNBridges()) ;
+ // remove empty bridge from store
+ purple_prefs_remove(BridgeKeyBuffer) ; purple_prefs_remove(EnabledKeyBuffer) ;
}
-//void enableBridge(Bridge* aBridge , gboolean shouldEnable)
void enableBridge(char* bridgeName , gboolean shouldEnable)
{
-// if (aBridge->isEnabled == shouldEnable) return ;
-
-// aBridge->isEnabled = shouldEnable ;
-// prepareBridgeKeys(aBridge->name) ;
prepareBridgeKeys(bridgeName) ;
+ if (purple_prefs_get_bool(EnabledKeyBuffer) == shouldEnable) return ;
+
purple_prefs_set_bool(EnabledKeyBuffer , shouldEnable) ;
}
void enableBridgeEach(char* bridgePrefKey , gboolean* shouldEnable)
{
- if (isValidChannelsPref(bridgePrefKey))
- enableBridge(strrchr(bridgePrefKey , '/') + 1 , *shouldEnable) ;
+ char bridgeName[SM_BUFFER_SIZE] ; prefKey2Name(bridgePrefKey , bridgeName) ;
+
+ if (isChannelsPref(bridgePrefKey)) enableBridge(bridgeName , *shouldEnable) ;
}
+
/* event handlers */
void handlePluginInit(PurplePlugin* aPlugin)
@@ -515,47 +305,40 @@ void handlePluginInit(PurplePlugin* aPlugin)
gboolean handlePluginLoaded(PurplePlugin* aPlugin)
{
+#if DEBUG_EVS
DBG("handlePluginLoaded()") ;
+#endif
-// if (!restoreSession()) return FALSE ;
-
- registerCommands() ; registerCallbacks() ; chatBufferClear() ;
-
- return TRUE ;
+ registerCommands() ; registerCallbacks() ; chatBufferClear() ; return TRUE ;
}
gboolean handlePluginUnloaded(PurplePlugin* plugin)
{
+#if DEBUG_EVS
DBG("handlePluginUnloaded()") ;
+#endif
-// unregisterCommands() ; unregisterCallbacks() ; destroySession() ;
- unregisterCommands() ; unregisterCallbacks() ;
-
- return TRUE ;
+ unregisterCommands() ; unregisterCallbacks() ; return TRUE ;
}
gboolean handleChat(PurpleAccount* thisAccount , char** sender , char** msg ,
PurpleConversation* thisConv , PurpleMessageFlags* flags , void* data)
{
-// Bridge* thisBridge ;
-char thisBridgeName[SM_BUFFER_SIZE] ;
-
-#ifdef DEBUG_CHAT // NOTE: DBGchat() should mirror changes to logic here
-if (thisConv) DBGchat(thisAccount , *sender , thisConv , *msg , *flags) ;
-#endif
+ char thisBridgeName[SM_BUFFER_SIZE] ;
if (!thisConv) return TRUE ; // supress rogue msgs (autojoined server msgs maybe unbound)
-// thisBridge = getBridgeName(thisConv) ;
getBridgeName(thisConv , thisBridgeName) ;
- if (!isBridgeEnabled(thisBridgeName)) return FALSE ; // input channel bridge is disabled
- if (*flags & PURPLE_MESSAGE_SEND) return FALSE ; // never relay unprefixed local chat
- if (!(*flags & PURPLE_MESSAGE_RECV)) return FALSE ; // TODO: handle special message types
-// if (!doesBridgeExist(thisBridge)) return FALSE ; // input channel is unbridged
-// if (!thisBridge->isEnabled) return FALSE ; // input channel bridge is disabled
+
+#if DEBUG_CHAT // NOTE: DBGchat() should mirror changes to logic here
+DBGchat(thisAccount , *sender , thisConv , *msg , *flags , thisBridgeName) ;
+#endif
+
+ if (!isBridgeEnabled(thisBridgeName)) return FALSE ; // input channel bridge is disabled
+ if (*flags & PURPLE_MESSAGE_SEND) return FALSE ; // never relay unprefixed local chat
+ if (!(*flags & PURPLE_MESSAGE_RECV)) return FALSE ; // TODO: handle special message types
prepareRelayChat(NICK_PREFIX , *sender , *msg) ;
-// relayMessage(thisBridge , thisConv) ; chatBufferClear() ;
relayMessage(thisBridgeName , thisConv) ; chatBufferClear() ;
return FALSE ;
@@ -567,16 +350,15 @@ if (thisConv) DBGchat(thisAccount , *sender , thisConv , *msg , *flags) ;
PurpleCmdRet handleAddCmd(PurpleConversation* thisConv , const gchar* command ,
gchar** args , gchar** error , void* data)
{
-// char* bridgeName ; Bridge* thisBridge ;
char thisBridgeName[SM_BUFFER_SIZE] ; char* thatBridgeName ;
-DBGcmd(command , args[0]) ;
+#if DEBUG_EVS
+DBGcmd(command , *args) ;
+#endif
- thatBridgeName = (isBlank(args[0]))? DEFAULT_BRIDGE_NAME : args[0] ;
-// if (doesBridgeExist(thisBridge = getBridgeName(thisConv)))
+ thatBridgeName = (isBlank(*args))? DEFAULT_BRIDGE_NAME : *args ;
if (isChannelBridged(thisConv))
{
-// if (thisBridge != getBridgeByName(bridgeName)) addConflictResp(thisConv) ;
getBridgeName(thisConv , thisBridgeName) ;
if (strcmp(thisBridgeName , thatBridgeName)) addConflictResp(thisConv) ;
else addExistsResp(thisConv , thisBridgeName) ;
@@ -595,17 +377,12 @@ DBGcmd(command , args[0]) ;
PurpleCmdRet handleRemoveCmd(PurpleConversation* thisConv , const gchar* command ,
gchar** args , gchar** error , void* data)
{
-// Bridge* thisBridge ; char thisBridgeName[SM_BUFFER_SIZE] ;
char thisBridgeName[SM_BUFFER_SIZE] ; getBridgeName(thisConv , thisBridgeName) ;
-DBGcmd(command , args[0]) ;
-/*
- if (doesBridgeExist(thisBridge = getBridgeName(thisConv)))
- {
- strncpy(thisBridgeName , thisBridge->name , SM_BUFFER_SIZE) ;
- destroyChannel(thisBridge , thisConv) ; removeResp(thisConv , thisBridgeName) ;
- }
-*/
+#if DEBUG_EVS
+DBGcmd(command , *args) ;
+#endif
+
if (isBlank(thisBridgeName)) removeUnbridgedResp(thisConv) ;
else { destroyChannel(thisConv) ; removeResp(thisConv , thisBridgeName) ; }
@@ -615,23 +392,16 @@ DBGcmd(command , args[0]) ;
PurpleCmdRet handleEnableCmd(PurpleConversation* thisConv , const gchar* command ,
gchar** args , gchar** error , void* data)
{
-// gboolean shouldEnable ; char* bridgeName ; Bridge* aBridge ;
gboolean shouldEnable ; char* bridgeName ; GList* prefsList ;
-DBGcmd(command , args[0]) ;
+#if DEBUG_EVS
+DBGcmd(command , *args) ;
+#endif
- shouldEnable = !strcmp(command , ENABLE_CMD) ; bridgeName = args[0] ;
+ shouldEnable = !strcmp(command , ENABLE_CMD) ; bridgeName = *args ;
if (!getNBridges()) enableNoneResp(thisConv , "") ;
else if (isBlank(bridgeName))
{
-/*
- aBridge = SentinelBridge ; enableAllResp(thisConv , shouldEnable) ;
- while ((aBridge = aBridge->next))
- {
- enableBridge(aBridge , shouldEnable) ;
- enableResp(thisConv , aBridge->name , shouldEnable) ;
- }
-*/
enableAllResp(thisConv , shouldEnable) ;
prefsList = purple_prefs_get_children_names(BASE_PREF_KEY) ;
g_list_foreach(prefsList , (GFunc)enableBridgeEach , &shouldEnable) ;
@@ -639,13 +409,6 @@ DBGcmd(command , args[0]) ;
g_list_foreach(prefsList , (GFunc)g_free , NULL) ;
g_list_free(prefsList) ;
}
-/*
- else if (doesBridgeExist(aBridge = getBridgeByName(bridgeName)))
- {
- enableBridge(aBridge , shouldEnable) ;
- enableResp(thisConv , aBridge->name , shouldEnable) ;
- }
-*/
else if (doesBridgeExist(bridgeName))
{
enableBridge(bridgeName , shouldEnable) ;
@@ -659,7 +422,9 @@ DBGcmd(command , args[0]) ;
PurpleCmdRet handleEchoCmd(PurpleConversation* thisConv , const gchar* command ,
gchar** args , gchar** error , void* data)
{
-DBGcmd(command , args[0]) ;
+#if DEBUG_EVS
+DBGcmd(command , *args) ;
+#endif
adminEcho(thisConv , *args) ; return PURPLE_CMD_RET_OK ;
}
@@ -667,15 +432,14 @@ DBGcmd(command , args[0]) ;
PurpleCmdRet handleChatCmd(PurpleConversation* thisConv , const gchar* command ,
gchar** args , gchar** error , void* data)
{
-// Bridge* thisBridge ;
char thisBridgeName[SM_BUFFER_SIZE] ; getBridgeName(thisConv , thisBridgeName) ;
-DBGcmd(command , args[0]) ;
+#if DEBUG_EVS
+DBGcmd(command , *args) ;
+#endif
-// thisBridge = getBridgeName(thisConv) ;
-// if (doesBridgeExist(thisBridge)) adminChat(thisConv , *args , thisBridge) ;
if (isChannelBridged(thisConv)) adminChat(thisConv , *args , thisBridgeName) ;
- else channelStateMsg(thisConv) ;
+ else { channelStateMsg(thisConv) ; chatBufferDump(thisConv) ; }
return PURPLE_CMD_RET_OK ;
}
@@ -683,7 +447,9 @@ DBGcmd(command , args[0]) ;
PurpleCmdRet handleBroadcastCmd(PurpleConversation* thisConv , const gchar* command ,
gchar** args , gchar** error , void* data)
{
-DBGcmd(command , args[0]) ;
+#if DEBUG_EVS
+DBGcmd(command , *args) ;
+#endif
broadcastResp(thisConv) ; adminBroadcast(thisConv , *args) ; return PURPLE_CMD_RET_OK ;
}
@@ -691,15 +457,19 @@ DBGcmd(command , args[0]) ;
PurpleCmdRet handleStatusCmd(PurpleConversation* thisConv , const gchar* command ,
gchar** args , gchar** error , void* data)
{
-DBGcmd(command , args[0]) ;
+#if DEBUG_EVS
+DBGcmd(command , *args) ;
+#endif
- statusResp(thisConv , args[0]) ; return PURPLE_CMD_RET_OK ;
+ statusResp(thisConv , *args) ; return PURPLE_CMD_RET_OK ;
}
PurpleCmdRet handleHelpCmd(PurpleConversation* thisConv , const gchar* command ,
gchar** args , gchar** error , void* data)
{
-DBGcmd(command , args[0]) ;
+#if DEBUG_EVS
+DBGcmd(command , *args) ;
+#endif
helpResp(thisConv) ; return PURPLE_CMD_RET_OK ;
}
@@ -708,7 +478,7 @@ DBGcmd(command , args[0]) ;
void addResp(PurpleConversation* thisConv , char* thisBridgeName)
{
- chatBufferPutSS("%s '%s'\n\n" , CH_SET_MSG , thisBridgeName) ;
+ chatBufferPutSS("%s '%s'\n" , CH_SET_MSG , thisBridgeName) ;
bridgeStatsMsg(thisBridgeName) ; chatBufferDump(thisConv) ;
}
@@ -730,9 +500,8 @@ void addFailResp(PurpleConversation* thisConv)
void removeResp(PurpleConversation* thisConv , char* thisBridgeName)
{
chatBufferPutSS("%s '%s'" , CHANNEL_REMOVED_MSG , thisBridgeName) ;
-// if (doesBridgeExist(getBridgeByName(thisBridgeName)))
if (doesBridgeExist(thisBridgeName))
- { chatBufferCat("\n\n") ; bridgeStatsMsg(thisBridgeName) ; }
+ { chatBufferCat("\n") ; bridgeStatsMsg(thisBridgeName) ; }
else { chatBufferCatSSSS("\n'" , thisBridgeName , "' " , BRIDGE_REMOVED_MSG) ; }
chatBufferDump(thisConv) ;
}
@@ -758,8 +527,9 @@ void enableResp(PurpleConversation* thisConv , char* bridgeName , gboolean shoul
void enableRespEach(char* bridgePrefKey , PurpleConversation* thisConv)
{
- char* bridgeName = strrchr(bridgePrefKey , '/') + 1 ;
- if (isValidChannelsPref(bridgePrefKey))
+ char bridgeName[SM_BUFFER_SIZE] ; prefKey2Name(bridgePrefKey , bridgeName) ;
+
+ if (isChannelsPref(bridgePrefKey))
enableResp(thisConv , bridgeName , isBridgeEnabled(bridgeName)) ;
}
@@ -768,35 +538,26 @@ void adminEcho(PurpleConversation* thisConv , char* msg)
prepareRelayChat(NICK_PREFIX , getNick(thisConv) , msg) ; chatBufferDump(thisConv) ;
}
-// void adminChat(PurpleConversation* inputConv , char* msg , Bridge* aBridge)
void adminChat(PurpleConversation* thisConv , char* msg , char* thisBridgeName)
{
prepareRelayChat(NICK_PREFIX , getNick(thisConv) , msg) ;
-// relayMessage(aBridge , NULL) ; chatBufferClear() ;
- relayMessage(thisBridgeName , thisConv) ; chatBufferClear() ;
+ relayMessage(thisBridgeName , NULL) ; chatBufferClear() ;
}
void adminBroadcast(PurpleConversation* thisConv , char* msg)
{
-// Bridge* aBridge = SentinelBridge ;
GList* prefsList ;
prepareRelayChat(BCAST_PREFIX , getNick(thisConv) , msg) ;
-// while ((aBridge = aBridge->next)) relayMessage(aBridge , NULL) ; chatBufferClear() ;
prefsList = purple_prefs_get_children_names(BASE_PREF_KEY) ;
- g_list_foreach(prefsList , (GFunc)relayMessage , thisConv) ;
+ g_list_foreach(prefsList , (GFunc)relayMessageEach , NULL) ;
g_list_foreach(prefsList , (GFunc)g_free , NULL) ;
g_list_free(prefsList) ; chatBufferClear() ;
}
void broadcastResp(PurpleConversation* thisConv)
{
-// Bridge* aBridge ; unsigned int nChannels = 0 ;
-
-// aBridge = SentinelBridge ;
-// while ((aBridge = aBridge->next)) nChannels += getNRelayChannels(aBridge , NULL) ;
-
- GList* prefsList ;
+ GList* prefsList ; NRelayChannels = 0 ;
prefsList = purple_prefs_get_children_names(BASE_PREF_KEY) ;
g_list_foreach(prefsList , (GFunc)getNRelayChannels , NULL) ;
@@ -810,22 +571,17 @@ void broadcastResp(PurpleConversation* thisConv)
void statusResp(PurpleConversation* thisConv , char* bridgeName)
{
-// Bridge* aBridge ; unsigned int nBridges = getNBridges() ;
- unsigned int nBridges = getNBridges() ; GList* prefsList ;
+ unsigned int nBridges ; GList* prefsList ;
-#ifdef DEBUG_VB
-if (!nBridges) DBG("statusResp() no bridges") ; else if (isBlank(bridgeName)) DBG("statusResp() bridge unspecified - listing all") ; else DBGss("statusResp() bridgeName='" , bridgeName , "'" , "") ;
+#if DEBUG_VB
+if (!getNBridges()) DBG("statusResp() no bridges") ; else if (isBlank(bridgeName)) DBG("statusResp() bridge unspecified - listing all") ; else DBGss("statusResp() bridgeName='" , bridgeName , "'" , "") ;
#endif
-// aBridge = SentinelBridge ; nBridges = getNBridges() ;
nBridges = getNBridges() ;
-
chatBufferPutSDS("%s %d %s" , STATS_MSGa , nBridges , STATS_MSGb) ;
- if (nBridges) chatBufferCat("\n\n") ; else { chatBufferDump(thisConv) ; return ; }
+ if (nBridges) chatBufferCat("\n") ; else { chatBufferDump(thisConv) ; return ; }
- if (!isBlank(bridgeName)) bridgeStatsMsg(bridgeName) ;
-// else while ((aBridge = aBridge->next))
-// { bridgeStatsMsg(aBridge->name) ; chatBufferCat("\n\n") ; }
+ if (!isBlank(bridgeName)) { bridgeStatsMsg(bridgeName) ; chatBufferCat("\n") ; }
else
{
prefsList = purple_prefs_get_children_names(BASE_PREF_KEY) ;
@@ -856,51 +612,29 @@ void channelStateMsg(PurpleConversation* thisConv)
{
// NOTE: callers of channelStateMsg() should eventually call chatBufferDump()
-// Bridge* aBridge ;
-char thisBridgeName[SM_BUFFER_SIZE] ;
-
-#ifdef DEBUG_VB
-DBGss("channelStateMsg() channelName='" , getChannelName(thisConv) , "'" , "") ;
-#endif
+ char thisBridgeName[SM_BUFFER_SIZE] ;
chatBufferCatSS(THIS_CHANNEL_MSG , " ") ;
-// if (doesBridgeExist(aBridge = getBridgeName(thisConv)))
-// chatBufferCatSSSS(THIS_BRIDGE_MSG , " '" , aBridge->name , "'") ;
getBridgeName(thisConv , thisBridgeName) ;
if (isBlank(thisBridgeName)) chatBufferCat(UNBRIDGED_MSG) ;
else chatBufferCatSSSS(THIS_BRIDGE_MSG , " '" , thisBridgeName , "'") ;
}
-void bridgeStatsMsg(const char* bridgePrefKey) // bridgePrefKey or bridgeName
+void bridgeStatsMsg(const char* bridgeName)
{
// NOTE: callers of bridgeStatsMsg() should eventually call chatBufferDump()
-// Bridge* aBridge ; Channel* aChannel ; unsigned int nChannels ;
- const char* bridgeName ; unsigned int nChannels ;
+ unsigned int nChannels ;
GList* channelsList ; GList* channelsIter ; char* aChannelUid ;
GList* activeChannelsIter = NULL ; gboolean isActive = FALSE ;
char* activeMsg ; char* protocol ; char* username ; const char* channelName ;
char* network ; char nick[SM_BUFFER_SIZE] ;
- // ensure bridgePrefKey and bridgeName are properly set
-// TODO: most calls to this function will have BridgeKeyBuffer set properly
-// so we could work it so that bridgeName is passed in consistantly
-// parsing bridgeName in nextBridgeStatsMsg() and calling prepareBridgeKeys() elsewhere
-// then pass BridgeKeyBuffer to isValidChannelsPref() and purple_prefs_get_string_list()
- bridgeName = strrchr(bridgePrefKey , '/') ;
- if (bridgeName) ++bridgeName ; // called with bridgePrefKey (e.g. via g_list_foreach())
- else // called with bridgeName (e.g. via chat command)
- {
-DBG("bridgeStatsMsg() shouold not be here on forEach") ;
-
- bridgeName = bridgePrefKey ;
- prepareBridgeKeys(bridgeName) ; bridgePrefKey = BridgeKeyBuffer ;
- }
-
- // bail if we are called with an uninteresting key (e.g. via g_list_foreach())
- if (!isValidChannelsPref(bridgePrefKey)) return ;
+#if DEBUG_LOGIC
+DBGss("bridgeStatsMsg() bridgeName='" , bridgeName , "' " , ((doesBridgeExist(bridgeName))? "exists" : "not exists - bailing")) ;
+#endif
-// if (!doesBridgeExist(aBridge = getBridgeByName(bridgeName)))
+ // display non-existent bridge state
if (!doesBridgeExist(bridgeName))
{
if (!getNBridges()) chatBufferCatSS(NO_BRIDGES_MSG , "") ;
@@ -909,26 +643,24 @@ DBG("bridgeStatsMsg() shouold not be here on forEach") ;
}
else chatBufferCatSSSS(STATS_MSGc , " '" , bridgeName , "' - ") ;
-// nChannels = getNChannels(aBridge) ;
- nChannels = getNChannels(bridgePrefKey) ;
+ // display bridge state
+ prepareBridgeKeys(bridgeName) ;
+ nChannels = getNChannels(BridgeKeyBuffer) ;
if (!nChannels) chatBufferCat(STATS_DELETED_MSG) ;
else
{
-// if (aBridge->isEnabled) chatBufferCat(STATS_ENABLED_MSG) ;
if (isBridgeEnabled(bridgeName)) chatBufferCat(STATS_ENABLED_MSG) ;
else chatBufferCat(STATS_DISABLED_MSG) ;
channelUidBufferPutD("%d" , nChannels) ;
chatBufferCatSSSS(" - " , ChannelUidBuffer , " " , STATS_MSGd) ;
}
-/*
- aChannel = aBridge->sentinelChannel ;
- while ((aChannel = aChannel->next))
-*/
- channelsList = purple_prefs_get_string_list(bridgePrefKey) ;
+
+ // display channels
+ channelsList = purple_prefs_get_string_list(BridgeKeyBuffer) ;
channelsIter = g_list_first(channelsList) ;
while (channelsIter)
{
-#ifdef DEBUG_VB
+#if DEBUG_LOGIC
DBGss("bridgeStatsMsg() found stored channelUid='" , (char*)channelsIter->data , "'" , "") ;
#endif
@@ -938,7 +670,7 @@ DBGss("bridgeStatsMsg() found stored channelUid='" , (char*)channelsIter->data ,
activeChannelsIter = g_list_first(purple_get_conversations()) ;
while (activeChannelsIter)
{
-#ifdef DEBUG_VB
+#if DEBUG_VB
if (channelsIter == g_list_first(channelsList))
DBGss("bridgeStatsMsg() got active channelName='" , getChannelName((PurpleConversation*)activeChannelsIter->data) , "'" , "") ;
#endif
@@ -949,7 +681,7 @@ if (channelsIter == g_list_first(channelsList))
}
activeMsg = (isActive)? CH_ACTIVE_MSG : CH_INACTIVE_MSG ;
-#ifdef DEBUG_VB
+#if DEBUG_VB
DBGss("bridgeStatsMsg() aChannel='" , aChannelUid , "' " , activeMsg) ;
#endif
@@ -960,7 +692,7 @@ DBGss("bridgeStatsMsg() aChannel='" , aChannelUid , "' " , activeMsg) ;
!(channelName = strtok(NULL , UID_DELIMITER)))
continue ;
-#ifdef DEBUG_VB
+#if DEBUG_VB
DBGsssss("bridgeStatsMsg() parsed channelUid " , activeMsg , " protocol='" , protocol , "' username='" , username , "' channelName='" , channelName , "'" , "") ;
#endif
@@ -980,7 +712,11 @@ DBGsssss("bridgeStatsMsg() parsed channelUid " , activeMsg , " protocol='" , pro
}
void bridgeStatsMsgEach(const char* bridgePrefKey , void* unusedGListEachData)
- { bridgeStatsMsg(bridgePrefKey) ; chatBufferCat("\n") ; }
+{
+ char bridgeName[SM_BUFFER_SIZE] ; prefKey2Name(bridgePrefKey , bridgeName) ;
+
+ if (isChannelsPref(bridgePrefKey)) bridgeStatsMsg(bridgeName) ; chatBufferCat("\n") ;
+}
/* text buffer helpers */
@@ -1039,7 +775,7 @@ void prepareRelayChat(char* prefix , const char* sender , char* msg)
void chatBufferDump(PurpleConversation* thisConv)
{
-#ifdef DEBUG_CHAT
+#if DEBUG_CHAT
DBGs("chatBufferDump() ChatBuffer=\n" , ChatBuffer) ;
#endif
@@ -1048,7 +784,6 @@ DBGs("chatBufferDump() ChatBuffer=\n" , ChatBuffer) ;
chatBufferClear() ;
}
-//void relayMessage(Bridge* outputBridge , PurpleConversation* inputConv)
void relayMessage(char* thisBridgeName , PurpleConversation* thisConv)
{
// NOTE: thisConv will be excluded from the relay - pass in NULL to include it
@@ -1062,13 +797,12 @@ void relayMessage(char* thisBridgeName , PurpleConversation* thisConv)
aConv = (PurpleConversation*)activeChannelsIter->data ;
getBridgeName(aConv , aBridgeName) ;
-#ifdef DEBUG_VB
+#if DEBUG_VB
DBGss("relayMessage() got active channelName='" , getChannelName(aConv) ,
((aConv == thisConv)? " isThisChannel - skipping" :
((!strcmp(aBridgeName , thisBridgeName))? "' isThisBridge - relaying" : "' notThisBridge - skipping" )) , "") ;
#endif
-// if (aConv != inputConv && getBridgeName(aConv) == outputBridge)
if (aConv != thisConv && !strcmp(aBridgeName , thisBridgeName))
{
convType = purple_conversation_get_type(aConv) ;
@@ -1081,6 +815,13 @@ DBGss("relayMessage() got active channelName='" , getChannelName(aConv) ,
}
}
+void relayMessageEach(const char* bridgePrefKey , PurpleConversation* thisConv)
+{
+ char bridgeName[SM_BUFFER_SIZE] ; prefKey2Name(bridgePrefKey , bridgeName) ;
+
+ if (isChannelsPref(bridgePrefKey)) relayMessage(bridgeName , thisConv) ;
+}
+
void alert(char* msg)
{
purple_notify_message(ThisPlugin , PURPLE_NOTIFY_MSG_INFO , msg ,
@@ -1090,17 +831,4 @@ void alert(char* msg)
/* main */
-static PurplePluginInfo PluginInfo =
-{
- PURPLE_PLUGIN_MAGIC , PURPLE_MAJOR_VERSION , PURPLE_MINOR_VERSION ,
- PLUGIN_TYPE , PLUGIN_GUI_TYPE , 0 , NULL , PURPLE_PRIORITY_DEFAULT ,
- PLUGIN_ID , PLUGIN_NAME , PLUGIN_VERSION , PLUGIN_SHORT_DESC , PLUGIN_LONG_DESC ,
- PLUGIN_AUTHOR , PLUGIN_WEBSITE , PLUGIN_ONLOAD_CB , PLUGIN_ONUNLOAD_CB ,
- NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL
-} ;
-
-static char* Commands[N_UNIQ_CMDS] = COMMANDS ;
-static unsigned int NRelayChannels = 0 ;
-
-
PURPLE_INIT_PLUGIN(PLUGIN_NAME , handlePluginInit , PluginInfo)
diff --git a/bridgin.dbg.h b/bridgin.dbg.h
index 137be30..4524432 100644
--- a/bridgin.dbg.h
+++ b/bridgin.dbg.h
@@ -1,25 +1,28 @@
-#define DEBUG
-#define DEBUG_VB
-#define DEBUG_CHAT
+#define DEBUG 1
+#define DEBUG_EVS DEBUG && 1
+#define DEBUG_LOGIC DEBUG && 1
+#define DEBUG_CHAT DEBUG && 1
+#define DEBUG_VB DEBUG && 0
#include "debug.h"
-// arges for DBG*() functions are in pairs<string , var> (DBGd implies "n=" , n)
-static void DBG(const char* s1) { if (isBlank(s1)) return ; purple_debug_misc(PLUGIN_NAME , "%s\n" , s1) ; }
+// NOTE: DBG*() functions args are in pairs <string,var> - e.g. DBGd("n=" , 42) ;
+static void DBG(const char* s1) { if (isBlank(s1)) return ; purple_debug_misc(PLUGIN_NAME , "%s\n" , s1) ; }
+#if DEBUG_CHAT
static void DBGs(const char* s1 , const char* s2) { if (isBlank(s1)) return ; purple_debug_misc(PLUGIN_NAME , "%s%s\n" , s1 , s2) ; }
-
-static void DBGd(const char* s1 , int d1) { if (isBlank(s1)) return ; purple_debug_misc(PLUGIN_NAME , "%s%d\n" , s1 , d1) ; }
-
+#endif
+//static void DBGd(const char* s1 , int d1) { if (isBlank(s1)) return ; purple_debug_misc(PLUGIN_NAME , "%s%d\n" , s1 , d1) ; }
+#if DEBUG_LOGIC
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) ; }
-
+#endif
//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 DBGdd(const char* s1 , int d1 , const char* s2 , int d2) { if (isBlank(s1)) return ; purple_debug_misc(PLUGIN_NAME , "%s%d%s%d\n" , s1 , d1 , s2 , d2) ; }
-#ifdef DEBUG_VB
-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 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) ; }
+#if DEBUG_VB
static void DBGsds(const char* s1 , const char* s2 , const char* s3 , int d1 , const char* s4 , const char* s5) { if (isBlank(s1)) return ; purple_debug_misc(PLUGIN_NAME , "%s%s%s%d%s%s\n" , s1 , s2 , s3 , d1 , s4 , s5) ; }
#endif
//static void DBGssd(const char* s1 , const char* s2 , const char* s3 , const char* s4 , const char* s5 , int d1) { if (isBlank(s1)) return ; purple_debug_misc(PLUGIN_NAME , "%s%s%s%s%s%d\n" , s1 , s2 , s3 , s4 , s5 , d1) ; }
@@ -33,56 +36,60 @@ static void DBGssss(const char* s1 , const char* s2 , const char* s3 , const cha
//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 DBGsdsd(const char* s1 , const char* s2 , const char* s3 , int d1 , const char* s4 , const char* s5 , const char* s6 , int d2) { if (isBlank(s1)) return ; purple_debug_misc(PLUGIN_NAME , "%s%s%s%d%s%s%s%d\n" , s1 , s2 , s3 , d1 , s4 , s5 , s6 , d2) ; }
-
+#if DEBUG_VB
static void DBGsssss(const char* s1 , const char* s2 , const char* s3 , const char* s4 , const char* s5 , const char* s6 , const char* s7 , const char* s8 , const char* s9 , const char* s10) { if (isBlank(s1)) return ; purple_debug_misc(PLUGIN_NAME , "%s%s%s%s%s%s%s%s%s%s\n" , s1 , s2 , s3 , s4 , s5 , s6 , s7 , s8 , s9 , s10) ; }
+#endif
-
+#if DEBUG_EVS
static void DBGcmd(const char* command , char* args)
- { purple_debug_misc(PLUGIN_NAME , "HandleCmd '/%s' args = %s\n" , command , args) ; }
-
+ { purple_debug_misc(PLUGIN_NAME , "handle*Cmd() cmd='/%s' args='%s'\n" , command , args) ; }
+#endif
-static void DBGchat(PurpleAccount* thisAccount , char* sender ,
- PurpleConversation* thisConv , char* msg , PurpleMessageFlags flags)
+#if DEBUG_CHAT
+static void DBGchat(PurpleAccount* thisAccount , char* sender , PurpleConversation* thisConv ,
+ char* msg , PurpleMessageFlags flags , char* thisBridgeName)
{
char* convType = ((purple_conversation_get_type(thisConv) == PURPLE_CONV_TYPE_IM)?
RECEIVING_IM_SIGNAL : RECEIVING_CHAT_SIGNAL) ;
-// Bridge* thisBridge = getBridgeByChannel(thisConv) ;
const char* channelName = purple_conversation_get_name(thisConv) ;
gboolean isLocal = (flags & PURPLE_MESSAGE_SEND) ;
gboolean isRemote = (flags & PURPLE_MESSAGE_RECV) ;
-// gboolean isUnbridged = (thisBridge == SentinelBridge) ;
gboolean isBridged = isChannelBridged(thisConv) ;
-// char dbgBuffer[SM_BUFFER_SIZE] ; unsigned int nChannels ;
+ gboolean isEnabled = isBridgeEnabled(thisBridgeName) ;
char dbgBuffer[SM_BUFFER_SIZE] ;
- char thisBridgeName[SM_BUFFER_SIZE] ; getBridgeName(thisConv , thisBridgeName) ;
+ // server msgs
if (!strcmp(channelName , "NickServ") || !strcmp(channelName , "MemoServ"))
{
purple_debug_misc(PLUGIN_NAME , "%s from %s - dropping\n" , convType , channelName) ;
return ;
}
+ // relay echos
if (isLocal && !strcmp(msg , ChatBuffer))
{
- DBGss(convType , " relay on channel '" , channelName , "' - ignoring") ;
+ DBGss(convType , " relay echo on channel '" , channelName , "' - ignoring") ;
return ;
}
-// nChannels = getNRelayChannels(aBridge , thisConv) ;
- getNRelayChannels(thisBridgeName , thisConv) ;
+ // count channels
+ prepareBridgeKeys(thisBridgeName) ; NRelayChannels = 0 ;
+ getNRelayChannels(BridgeKeyBuffer , thisConv) ;
snprintf(dbgBuffer , SM_BUFFER_SIZE ,
"%d channels on bridge '%s'" , NRelayChannels , thisBridgeName) ;
- purple_debug_misc(PLUGIN_NAME ,
- "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%d%s%s%s\n" ,
+ // out
+ purple_debug_misc(PLUGIN_NAME , "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%d%s%s%s\n" ,
convType , ((isLocal)? " from admin " : " from user ") , sender ,
"\n\taccount = " , getProtocol(thisAccount) , " as " , getUsername(thisAccount) ,
"\n\tsender = " , sender ,
"\n\tchannel = " , ((!thisConv) ? "(null)" : channelName) ,
"\n\tmessage = " , msg ,
"\n\tflags = " , flags ,
- "\n" , ((isLocal)? "local message - dropping" :
- ((!isRemote)? "special message - dropping" :
- ((!isBridged)? "unbridged - dropping" : "relaying to "))) ,
- ((isRemote && isBridged)? dbgBuffer : "")) ;
+ "\n" , ((isLocal)? "local message - dropping" :
+ ((!isRemote)? "special message - dropping" :
+ ((!isBridged)? "unbridged - dropping" :
+ ((!isEnabled)? "bridge disabled - dropping" : "relaying to ")))) ,
+ ((!isRemote || !isBridged || !isEnabled)? "" : dbgBuffer)) ;
}
+#endif
diff --git a/bridgin.h b/bridgin.h
index 47de255..b5670ce 100644
--- a/bridgin.h
+++ b/bridgin.h
@@ -7,14 +7,15 @@
# define PURPLE_PLUGINS
#endif
+
// plugin constants
#define PLUGIN_TYPE PURPLE_PLUGIN_STANDARD
#define PLUGIN_GUI_TYPE NULL
#define PLUGIN_ID "core-mr-jonze-bridgin"
-#define PLUGIN_NAME "bridgin"
-#define PLUGIN_VERSION "0.5pre"
-#define PLUGIN_SHORT_DESC "short description"
-#define PLUGIN_LONG_DESC "long description"
+#define PLUGIN_NAME "Bridgin"
+#define PLUGIN_VERSION "0.5.0"
+#define PLUGIN_SHORT_DESC "Bridge multiple conversations"
+#define PLUGIN_LONG_DESC "Relays chat message from/to specified conversations.\n\tType /? into any conversation for available commands."
#define PLUGIN_AUTHOR "bill auger <mr.j.spam.me@gmail.com>"
#define PLUGIN_WEBSITE "https://github.com/bill-auger/bridgin"
#define PLUGIN_ONLOAD_CB handlePluginLoaded
@@ -24,10 +25,10 @@
// app constants
#define BRIDGIN_NICK "BRIDGIN"
#define DEFAULT_BRIDGE_NAME "default"
-#define CHAT_OUT_FMT "%s %s%s %s"
-#define NICK_PREFIX "(from" // dont use '<' - some clients will supress it as html
-#define NICK_POSTFIX ")"
-#define BCAST_PREFIX "(BROADCAST from"
+#define CHAT_OUT_FMT "%s%s%s%s" // prefix , sender , postfix , msg
+#define NICK_PREFIX "(from " // dont use '<' - some clients will supress it as html
+#define NICK_POSTFIX ") "
+#define BCAST_PREFIX "(BROADCAST from "
// purple constants
#define RECEIVING_IM_SIGNAL "receiving-im-msg"
@@ -37,12 +38,10 @@
// model constants
#define SM_BUFFER_SIZE 256
#define LG_BUFFER_SIZE 8192
+#define BASE_PREF_KEY "/plugins/core/"PLUGIN_NAME
#define BRIDGE_PREF_FMT "%s/%s"
#define ENABLED_PREF_FMT "%s%s"
-#define BASE_PREF_KEY "/plugins/core/"PLUGIN_NAME
-#define BASE_PREF_LABEL PLUGIN_NAME" preferences"
#define ENABLED_PREF_KEY "-enabled"
-#define SENTINEL_NAME "sentinel"
#define UID_DELIMITER "::"
#define CHANNEL_UID_FMT "%s"UID_DELIMITER"%s"UID_DELIMITER"%s"
@@ -124,35 +123,18 @@
//#include "signals.h"
#include "version.h"
-/*
-typedef struct Channel
-{
- char uid[SM_BUFFER_SIZE] ;
- struct Channel* prev ;
- struct Channel* next ;
-} Channel ;
-typedef struct Bridge
-{
- char name[SM_BUFFER_SIZE] ;
- gboolean isEnabled ;
- Channel* sentinelChannel ;
- struct Bridge* prev ;
- struct Bridge* next ;
-} Bridge ;
-*/
+/* global vars */
-// global vars
-static PurplePluginInfo PluginInfo ; // init pre main()
+static char* Commands[N_UNIQ_CMDS] ; // init global
+static unsigned int NRelayChannels ; // init global
+static PurplePluginInfo PluginInfo ; // init global
static PurplePlugin* ThisPlugin ; // init handlePluginLoaded()
static PurpleCmdId CommandIds[N_COMMANDS] ; // init handlePluginLoaded()
-static char* Commands[N_UNIQ_CMDS] ; // init pre main()
-//static Bridge* SentinelBridge ; // init handlePluginLoaded()
static char BridgeKeyBuffer[SM_BUFFER_SIZE] ; // volatile
static char EnabledKeyBuffer[SM_BUFFER_SIZE] ; // volatile
static char ChannelUidBuffer[SM_BUFFER_SIZE] ; // volatile
static char ChatBuffer[LG_BUFFER_SIZE] ; // volatile
-static unsigned int NRelayChannels ;// init pre main()
/* model-like functions */
@@ -160,49 +142,35 @@ static unsigned int NRelayChannels ;// init pre main()
// purple helpers
PurpleCmdId registerCmd( const char* command , const char* format ,
PurpleCmdRet (*callback)() , const char* help) ;
-//gboolean restoreSession( void) ;
void registerCommands( void) ;
void registerCallbacks( void) ;
void unregisterCommands( void) ;
void unregisterCallbacks(void) ;
-//void destroySession( void) ;
const char* getChannelName( PurpleConversation* aConv) ;
const char* getProtocol( PurpleAccount* anAccount) ;
PurpleAccount* getAccount( PurpleConversation* aConv) ;
const char* getUsername( PurpleAccount* anAccount) ;
const char* getNick( PurpleConversation* aConv) ;
-//unsigned int getNRelayChannels( Bridge* thisBridge , PurpleConversation* thisConv) ;
-void getNRelayChannels(char* bridgeName , PurpleConversation* inputConv) ;
// model helpers
-void prepareBridgeKeys( const char* bridgeName) ;
-void prepareChannelUid( PurpleConversation* aConv) ;
-gint isThisChanne(gconstpointer a , gconstpointer b) ;
-// Bridge* getBridgeByChannel(PurpleConversation* aConv) ;
-void getBridgeName(PurpleConversation* aConv , char* thisBridgeNameBuffer) ;
-//Bridge* getBridgeByName( const char* bridgeName) ;
-unsigned int getNBridges( void) ;
-// unsigned int getNChannels( Bridge* aBridge) ;
-unsigned int getNChannels(const char* bridgeName) ;
-//gboolean doesBridgeExist( Bridge* aBridge) ;
-gboolean doesBridgeExist(const char* bridgeName) ;
-gboolean isBridgeEnabled(const char* bridgeName) ;
-gboolean isChannelBridged(PurpleConversation* aConv) ;
-//gboolean isServerChannel( PurpleConversation* aConv) ;
-// gboolean areReservedIds( char* bridgeName , char* channelUid ,
-// PurpleConversation* aConv) ;
-gboolean areReservedIds(char* bridgeName , char* channelUid , const char* channelName) ;
-// Bridge* newBridge( char* bridgeName , Bridge* prevBridge ,
-// gboolean isEnabled) ;
-// Channel* newChannel( Channel* prevChannel) ;
-//gboolean createChannel( char* bridgeName , gboolean isStored) ;
-gboolean isValidChannelsPref(const char* bridgePrefKey) ;
-void createChannel(char* bridgeName) ;
-// void destroyChannel( Bridge* aBridge , PurpleConversation* aConv) ;
-void destroyChannel(PurpleConversation* aConv) ;
-// void enableBridge( Bridge* aBridge , gboolean isEnable) ;
-void enableBridge(char* bridgeName , gboolean shouldEnable) ;
-void enableBridgeEach(char* bridgePrefKey , gboolean* shouldEnable) ;
+void prepareBridgeKeys(const char* bridgeName) ;
+void prepareChannelUid(PurpleConversation* aConv) ;
+gint isMatch( gconstpointer a , gconstpointer b) ;
+void prefKey2Name( const char* prefKey , char* nameBuffer) ;
+void getBridgeName( PurpleConversation* aConv , char* thisBridgeNameBuffer) ;
+unsigned int getNBridges( void) ;
+unsigned int getNChannels( const char* bridgeName) ;
+void getNRelayChannels(char* bridgePrefKey , PurpleConversation* inputConv) ;
+gboolean doesBridgeExist( const char* bridgeName) ;
+gboolean isBridgeEnabled( const char* bridgeName) ;
+gboolean isChannelBridged( PurpleConversation* aConv) ;
+gboolean areReservedIds( char* bridgeName , char* channelUid ,
+ const char* channelName) ;
+gboolean isChannelsPref( const char* bridgePrefKey) ;
+void createChannel( char* bridgeName) ;
+void destroyChannel( PurpleConversation* aConv) ;
+void enableBridge( char* bridgeName , gboolean shouldEnable) ;
+void enableBridgeEach( char* bridgePrefKey , gboolean* shouldEnable) ;
/* controller-like functions */
@@ -237,8 +205,6 @@ PurpleCmdRet handleHelpCmd( PurpleConversation* aConv , const gchar* cmd ,
/* view-like functions */
// admin command responses
-// NOTE: callers of channelStateMsg() or bridgeStatsMsg()
-// should eventually call chatBufferDump() to flush to screen
void addResp( PurpleConversation* aConv , char* thisBridgeName) ;
void addExistsResp( PurpleConversation* aConv , char* thisBridgeName) ;
void addConflictResp( PurpleConversation* aConv) ;
@@ -250,18 +216,16 @@ void enableNoneResp( PurpleConversation* thisConv , char* bridgeName) ;
void enableAllResp( PurpleConversation* thisConv , gboolean shouldEnable) ;
void enableResp( PurpleConversation* thisConv , char* bridgeName ,
gboolean shouldEnable) ;
-void enableRespEach(char* bridgePrefKey , PurpleConversation* thisConv) ;
+void enableRespEach( char* bridgePrefKey , PurpleConversation* thisConv) ;
void adminEcho( PurpleConversation* thisConv , char* msg) ;
-// void adminChat( PurpleConversation* inputConv , char* msg ,
-// Bridge* aBridge) ;
-void adminChat(PurpleConversation* thisConv , char* msg , char* thisBridgeName) ;
+void adminChat( PurpleConversation* thisConv , char* msg , char* thisBridgeName) ;
void adminBroadcast( PurpleConversation* thisConv , char* msg) ;
void broadcastResp( PurpleConversation* thisConv) ;
void statusResp( PurpleConversation* aConv , char* bridgeName) ;
void helpResp( PurpleConversation* thisConv) ;
void channelStateMsg( PurpleConversation* aConv) ;
void bridgeStatsMsg( const char* bridgePrefKey) ;
-void bridgeStatsMsgEach(const char* bridgePrefKey , void* unusedGListEachData) ;
+void bridgeStatsMsgEach( const char* bridgePrefKey , void* unusedGListEachData) ;
// text buffer helpers
gboolean isBlank( const char* aCstring) ;
@@ -286,6 +250,6 @@ void chatBufferCatSSSSSS( const char* s1 , const char* s2 , const char* s3 ,
const char* s4 , const char* s5 , const char* s6) ;
void prepareRelayChat( char* prefix , const char* sender , char* msg) ;
void chatBufferDump( PurpleConversation* thisConv) ;
-// void relayMessage( Bridge* outputBridge , PurpleConversation* inputConv) ;
-void relayMessage(char* bridgeName , PurpleConversation* thisConv) ;
+void relayMessage( char* bridgeName , PurpleConversation* thisConv) ;
+void relayMessageEach( const char* bridgePrefKey , PurpleConversation* thisConv) ;
void alert( char* msg) ;
diff --git a/install b/install.sh
index 4362653..4362653 100755
--- a/install
+++ b/install.sh