summaryrefslogtreecommitdiff
path: root/plugins/TrafficCounter/vars.c
diff options
context:
space:
mode:
authorVlad Mironov <mironych@googlemail.com>2012-09-20 12:00:44 +0000
committerVlad Mironov <mironych@googlemail.com>2012-09-20 12:00:44 +0000
commit9bd135eb5be03099a8cfbc81ac9903a97044ae0f (patch)
tree49f85c07edf86610f3b7d0e152dfb4e97b9a11f4 /plugins/TrafficCounter/vars.c
parent4ac4df14e007a71bf195183a92113e29f984e31c (diff)
Добавлен TrafficCounter
git-svn-id: http://svn.miranda-ng.org/main/trunk@1607 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/TrafficCounter/vars.c')
-rw-r--r--plugins/TrafficCounter/vars.c185
1 files changed, 185 insertions, 0 deletions
diff --git a/plugins/TrafficCounter/vars.c b/plugins/TrafficCounter/vars.c
new file mode 100644
index 0000000000..bc2cda965f
--- /dev/null
+++ b/plugins/TrafficCounter/vars.c
@@ -0,0 +1,185 @@
+/*
+Traffic Counter plugin for Miranda IM
+Copyright 2007-2011 Mironych.
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+/* ======================================================================================
+Çäåñü ñîäåðæàòñÿ ôóíêöèè äëÿ ïîääåðæêè ïëàãèíà Variables
+Àâòîð: Mironych
+=======================================================================================*/
+
+#include "commonheaders.h"
+
+static TCHAR* GetTraffic(ARGUMENTSINFO *ai)
+{
+ DWORD tmp, tmpsn = 0, tmprn = 0, tmpst = 0, tmprt = 0;
+ BYTE ed;
+ WORD l;
+ TCHAR *res;
+
+ if (ai->argc != 5) return NULL;
+
+ if (!_tcscmp(ai->targv[1], _T("overall")))
+ {
+ tmpsn = OverallInfo.CurrentSentTraffic;
+ tmprn = OverallInfo.CurrentRecvTraffic;
+ tmpst = OverallInfo.TotalSentTraffic;
+ tmprt = OverallInfo.TotalRecvTraffic;
+ }
+ else
+ if (!_tcscmp(ai->targv[1], _T("summary")))
+ {
+ for (ed = 0; ed < NumberOfAccounts; ed++)
+ if (ProtoList[ed].Visible)
+ {
+ tmpsn += ProtoList[ed].CurrentSentTraffic;
+ tmprn += ProtoList[ed].CurrentRecvTraffic;
+ tmpst += ProtoList[ed].TotalSentTraffic;
+ tmprt += ProtoList[ed].TotalRecvTraffic;
+ }
+ }
+ else
+ { // Èùåì èíäåêñ ïðîòîêîëà, ïåðåäàííîãî ïåðâûì àðãóìåíòîì
+ for (tmp = ed = 0; ed < NumberOfAccounts; ed++)
+ {
+ TCHAR *buf;
+ if (!ProtoList[ed].name) continue;
+ buf = mir_a2t(ProtoList[ed].name);
+ if (!_tcscmp(buf, ai->targv[1]))
+ {
+ tmpsn = ProtoList[ed].CurrentSentTraffic;
+ tmprn = ProtoList[ed].CurrentRecvTraffic;
+ tmpst = ProtoList[ed].TotalSentTraffic;
+ tmprt = ProtoList[ed].TotalRecvTraffic;
+ tmp = 0xAA; // Ïðèçíàê òîãî, ÷òî ïðîòîêîë áûë íàéäåí
+ }
+ mir_free(buf);
+ }
+ if (tmp != 0xAA) return NULL;
+ }
+
+ if (!_tcscmp(ai->targv[2], _T("now")))
+ {
+ if (!_tcscmp(ai->targv[3], _T("sent"))) tmp = tmpsn;
+ else
+ if (!_tcscmp(ai->targv[3], _T("received"))) tmp = tmprn;
+ else
+ if (!_tcscmp(ai->targv[3], _T("both"))) tmp = tmprn + tmpsn;
+ else return NULL;
+ }
+ else
+ if (!_tcscmp(ai->targv[2], _T("total")))
+ {
+ if (!_tcscmp(ai->targv[3], _T("sent"))) tmp = tmpst;
+ else
+ if (!_tcscmp(ai->targv[3], _T("received"))) tmp = tmprt;
+ else
+ if (!_tcscmp(ai->targv[3], _T("both"))) tmp = tmprt + tmpst;
+ else return NULL;
+ }
+ else return NULL;
+
+ if (!_tcscmp(ai->targv[4], _T("b"))) ed = 0;
+ else
+ if (!_tcscmp(ai->targv[4], _T("k"))) ed = 1;
+ else
+ if (!_tcscmp(ai->targv[4], _T("m"))) ed = 2;
+ else
+ if (!_tcscmp(ai->targv[4], _T("d"))) ed = 3;
+ else return NULL;
+
+ // Ïîëó÷àåì ôîðìàòèðîâàííóþ ñòðîêó è âîçâðàùàåì óêàçàòåëü íà íå¸.
+ // Ñíà÷àëà óçíàåì ðàçìåð áóôåðà.
+ l = GetFormattedTraffic(tmp, ed, NULL, 0);
+ res = (TCHAR*)mir_alloc(l * sizeof(TCHAR));
+ if (!res) return NULL;
+ if (GetFormattedTraffic(tmp, ed, res, l))
+ return res;
+
+ return NULL;
+}
+
+static TCHAR* GetTime(ARGUMENTSINFO *ai)
+{
+ BYTE ed, flag;
+ TCHAR *res = NULL;
+ WORD l;
+ DWORD Duration;
+
+ if (ai->argc != 4) return NULL;
+
+ // Èùåì èíäåêñ ïðîòîêîëà, ïåðåäàííîãî ïåðâûì àðãóìåíòîì
+ for (flag = ed = 0; ed < NumberOfAccounts; ed++)
+ {
+ TCHAR *buf;
+ if (!ProtoList[ed].name) continue;
+ buf = mir_a2t(ProtoList[ed].name);
+ if (!_tcscmp(buf, ai->targv[1]))
+ {
+ flag = 0xAA;
+ if (!_tcscmp(ai->targv[2], _T("now")))
+ Duration = ProtoList[ed].Session.Timer;
+ else if (!_tcscmp(ai->targv[2], _T("total")))
+ Duration = ProtoList[ed].Total.Timer;
+ else flag = 0;
+ break;
+ }
+ mir_free(buf);
+ }
+ if ( (flag != 0xAA) && !_tcscmp(ai->targv[1], _T("summary")) )
+ {
+ flag = 0xAA;
+ if (!_tcscmp(ai->targv[2], _T("now")))
+ Duration = OverallInfo.Session.Timer;
+ else if (!_tcscmp(ai->targv[2], _T("total")))
+ Duration = OverallInfo.Total.Timer;
+ else flag = 0;
+ }
+
+ if (flag != 0xAA) return NULL;
+
+ // Ïîëó÷àåì ôîðìàòèðîâàííóþ ñòðîêó è âîçâðàùàåì óêàçàòåëü íà íå¸.
+ // Ñíà÷àëà óçíàåì ðàçìåð áóôåðà.
+ l = GetDurationFormatM(Duration, ai->targv[3], NULL, 0);
+ res = (TCHAR*)mir_alloc(l * sizeof(TCHAR));
+ if (!res) return NULL;
+ GetDurationFormatM(Duration, ai->targv[3], res, l);
+
+ return res;
+}
+
+void RegisterVariablesTokens(void)
+{
+ TOKENREGISTER trs;
+
+ if (!ServiceExists(MS_VARS_REGISTERTOKEN)) return;
+
+ ZeroMemory(&trs, sizeof(trs));
+ trs.cbSize = sizeof(TOKENREGISTER);
+
+ // Ôóíêöèÿ, âîçâðàùàþùàÿ òðàôèê
+ trs.tszTokenString = _T("tc_GetTraffic");
+ trs.parseFunctionT = GetTraffic;
+ trs.szHelpText = "Traffic counter\t(A,B,C,D)\tGet traffic counter value. A: <ProtocolName> OR overall OR summary; B: now OR total; C: sent OR received OR both; D: b - in bytes, k - in kilobytes, m - in megabytes, d - dynamic";
+ trs.flags = TRF_TCHAR | TRF_PARSEFUNC | TRF_FUNCTION | TRF_FREEMEM;
+ trs.memType = TR_MEM_MIRANDA;
+ CallService(MS_VARS_REGISTERTOKEN, 0, (LPARAM)&trs);
+ // Ôóíêöèÿ, âîçâðàùàþùàÿ âðåìÿ
+ trs.tszTokenString = _T("tc_GetTime");
+ trs.parseFunctionT = GetTime;
+ trs.szHelpText = "Traffic counter\t(A,B,C)\tGet time counter value. A: <ProtocolName> OR summary; B: now OR total; C: format";
+ CallService(MS_VARS_REGISTERTOKEN, 0, (LPARAM)&trs);
+}