Changeset 6521 for trunk/licq
- Timestamp:
- 09/13/08 22:59:51 (3 months ago)
- Location:
- trunk/licq
- Files:
-
- 3 modified
-
include/licq_onevent.h (modified) (2 diffs)
-
src/icqd.cpp (modified) (4 diffs)
-
src/onevent.cpp (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/licq/include/licq_onevent.h
r6347 r6521 3 3 4 4 #include <pthread.h> 5 #include <string> 5 6 6 7 class ICQUser; … … 26 27 ~COnEventManager(); 27 28 29 const std::string command() const { return myCommand; } 30 const std::string parameter(unsigned short event) const { return myParameters[event]; } 28 31 void Do(unsigned short m_nEvent, ICQUser *u); 29 void SetParameters(const char *, const char **);30 32 void SetCommandType(unsigned short _nCommandType); 33 void setCommand(const std::string& command); 34 void setParameter(unsigned short event, const std::string& parameter); 35 void setParameters(const std::string& command, const std::string parameters[]); 31 36 unsigned short CommandType(); 32 const char *Parameter(unsigned short n) { return m_aszParameters[n]; }33 const char *Command() { return m_szCommand; }34 37 void Lock() { pthread_mutex_lock(&mutex); } 35 38 void Unlock() { pthread_mutex_unlock(&mutex); } 36 39 protected: 37 40 unsigned short m_nCommandType; 38 char *m_szCommand;39 char *m_aszParameters[MAX_ON_EVENT];40 pthread_mutex_t mutex;41 std::string myCommand; 42 std::string myParameters[MAX_ON_EVENT]; 43 mutable pthread_mutex_t mutex; 41 44 }; 42 45 -
trunk/licq/src/icqd.cpp
r6500 r6521 287 287 288 288 // -----OnEvent configuration----- 289 char szOnEventCommand[MAX_FILENAME_LEN], *szOnParams[MAX_ON_EVENT];289 string onEventCommand, onEventParams[MAX_ON_EVENT]; 290 290 unsigned short nOnEventCmdType; 291 291 … … 294 294 licqConf.ReadBool("AlwaysOnlineNotify", m_bAlwaysOnlineNotify, false); 295 295 m_xOnEventManager.SetCommandType(nOnEventCmdType); 296 for (int i = 0; i < MAX_ON_EVENT; i++) {297 szOnParams[i] = new char[MAX_FILENAME_LEN];298 szOnParams[i][0] = '\0';299 }300 296 301 297 // Prepare default values for onEvent … … 324 320 strncat(DEF_MSGSENT, "sounds/icq/Message.wav", MAX_APPEND); 325 321 326 licqConf.ReadStr("Command", szOnEventCommand, "play"); 327 licqConf.ReadStr("Message", szOnParams[ON_EVENT_MSG], DEF_MESSAGE); 328 licqConf.ReadStr("Url", szOnParams[ON_EVENT_URL], DEF_URL); 329 licqConf.ReadStr("Chat", szOnParams[ON_EVENT_CHAT], DEF_CHAT); 330 licqConf.ReadStr("File", szOnParams[ON_EVENT_FILE], DEF_FILE); 331 licqConf.ReadStr("OnlineNotify", szOnParams[ON_EVENT_NOTIFY], DEF_NOTIFY); 332 licqConf.ReadStr("SysMsg", szOnParams[ON_EVENT_SYSMSG], DEF_SYSMSG); 333 licqConf.ReadStr("MsgSent", szOnParams[ON_EVENT_MSGSENT], DEF_MSGSENT); 334 m_xOnEventManager.SetParameters(szOnEventCommand, (const char **)szOnParams); 335 for (int i = 0; i < MAX_ON_EVENT; i++) 336 delete [] szOnParams[i]; 322 licqConf.readString("Command", onEventCommand, "play"); 323 licqConf.readString("Message", onEventParams[ON_EVENT_MSG], DEF_MESSAGE); 324 licqConf.readString("Url", onEventParams[ON_EVENT_URL], DEF_URL); 325 licqConf.readString("Chat", onEventParams[ON_EVENT_CHAT], DEF_CHAT); 326 licqConf.readString("File", onEventParams[ON_EVENT_FILE], DEF_FILE); 327 licqConf.readString("OnlineNotify", onEventParams[ON_EVENT_NOTIFY], DEF_NOTIFY); 328 licqConf.readString("SysMsg", onEventParams[ON_EVENT_SYSMSG], DEF_SYSMSG); 329 licqConf.readString("MsgSent", onEventParams[ON_EVENT_MSGSENT], DEF_MSGSENT); 330 m_xOnEventManager.setParameters(onEventCommand, onEventParams); 337 331 338 332 // Statistics … … 843 837 licqConf.WriteBool("AlwaysOnlineNotify", m_bAlwaysOnlineNotify); 844 838 oem->Lock(); 845 licqConf. WriteStr("Command", oem->Command());846 licqConf. WriteStr("Message", oem->Parameter(ON_EVENT_MSG));847 licqConf. WriteStr("Url", oem->Parameter(ON_EVENT_URL));848 licqConf. WriteStr("Chat",oem->Parameter(ON_EVENT_CHAT));849 licqConf. WriteStr("File",oem->Parameter(ON_EVENT_FILE));850 licqConf. WriteStr("OnlineNotify", oem->Parameter(ON_EVENT_NOTIFY));851 licqConf. WriteStr("SysMsg", oem->Parameter(ON_EVENT_SYSMSG));852 licqConf. WriteStr("MsgSent", oem->Parameter(ON_EVENT_MSGSENT));839 licqConf.writeString("Command", oem->command()); 840 licqConf.writeString("Message", oem->parameter(ON_EVENT_MSG)); 841 licqConf.writeString("Url", oem->parameter(ON_EVENT_URL)); 842 licqConf.writeString("Chat",oem->parameter(ON_EVENT_CHAT)); 843 licqConf.writeString("File",oem->parameter(ON_EVENT_FILE)); 844 licqConf.writeString("OnlineNotify", oem->parameter(ON_EVENT_NOTIFY)); 845 licqConf.writeString("SysMsg", oem->parameter(ON_EVENT_SYSMSG)); 846 licqConf.writeString("MsgSent", oem->parameter(ON_EVENT_MSGSENT)); 853 847 oem->Unlock(); 854 848 -
trunk/licq/src/onevent.cpp
r6467 r6521 18 18 #include "support.h" 19 19 20 using namespace std; 21 20 22 //=====COnEventManager========================================================== 21 23 22 24 COnEventManager::COnEventManager() 23 25 { 24 m_szCommand = NULL;25 for (unsigned short i = 0; i < MAX_ON_EVENT; i++)26 m_aszParameters[i] = NULL;27 26 pthread_mutex_init(&mutex, NULL); 28 27 } … … 30 29 COnEventManager::~COnEventManager() 31 30 { 32 if (m_szCommand)33 free(m_szCommand);34 35 for (unsigned short i = 0; i < MAX_ON_EVENT; i++)36 if (m_aszParameters[i])37 free(m_aszParameters[i]);38 31 } 39 32 … … 53 46 } 54 47 55 //-----COnEventManager::SetParameters------------------------------------------- 56 void COnEventManager::SetParameters(const char *_szCommand, const char **_aszParams) 48 void COnEventManager::setCommand(const string& command) 57 49 { 58 50 pthread_mutex_lock(&mutex); 59 SetString(&m_szCommand, _szCommand); 51 myCommand = command; 52 pthread_mutex_unlock(&mutex); 53 } 54 55 void COnEventManager::setParameter(unsigned short event, const string& parameter) 56 { 57 pthread_mutex_lock(&mutex); 58 myParameters[event] = parameter; 59 pthread_mutex_unlock(&mutex); 60 } 61 62 //-----COnEventManager::SetParameters------------------------------------------- 63 void COnEventManager::setParameters(const string& command, const string parameters[]) 64 { 65 pthread_mutex_lock(&mutex); 66 myCommand = command; 60 67 for (unsigned short i = 0; i < MAX_ON_EVENT; i++) 61 SetString(&m_aszParameters[i], _aszParams[i]);68 myParameters[i] = parameters[i]; 62 69 pthread_mutex_unlock(&mutex); 63 70 } … … 98 105 if (m_nCommandType == ON_EVENT_RUN) 99 106 { 100 char *szParam = m_aszParameters[_nEvent]; 101 char *szFullParam; 107 string param = myParameters[_nEvent]; 102 108 if (u != NULL) 103 szFullParam = u->usprintf(szParam, USPRINTF_LINEISCMD);104 else105 szFullParam = strdup(szParam);106 107 if (strlen(szFullParam))108 109 { 109 char szCmd[strlen(m_szCommand) + strlen(szFullParam) + 8];110 sprintf(szCmd, "%s %s &", m_szCommand, szFullParam);111 system(szCmd);110 char* szFullParam = u->usprintf(param.c_str(), USPRINTF_LINEISCMD); 111 param = szFullParam; 112 free(szFullParam); 112 113 } 113 114 if (szFullParam) 115 free(szFullParam); 114 string fullCmd = myCommand + " " + param + " &"; 115 system(fullCmd.c_str()); 116 116 } 117 117 pthread_mutex_unlock(&mutex);
