diff options
author | Kirill Volinsky <mataes2007@gmail.com> | 2015-05-16 17:34:54 +0000 |
---|---|---|
committer | Kirill Volinsky <mataes2007@gmail.com> | 2015-05-16 17:34:54 +0000 |
commit | b97306f8dc5e4f93bd3e6e5500a8b8338d6249a2 (patch) | |
tree | 2aadaa0640b4910b78b1e1e99718f220fbfa7622 /plugins/Ping/src | |
parent | 3dc4db00aa828d245e4f7a8a14233d624f3e2e7c (diff) |
cleanup
git-svn-id: http://svn.miranda-ng.org/main/trunk@13625 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Ping/src')
-rw-r--r-- | plugins/Ping/src/collection.h | 432 | ||||
-rw-r--r-- | plugins/Ping/src/common.h | 4 | ||||
-rw-r--r-- | plugins/Ping/src/icmp.cpp | 16 | ||||
-rw-r--r-- | plugins/Ping/src/icmp.h | 4 | ||||
-rw-r--r-- | plugins/Ping/src/log.cpp | 20 | ||||
-rw-r--r-- | plugins/Ping/src/options.cpp | 2 | ||||
-rw-r--r-- | plugins/Ping/src/options.h | 2 | ||||
-rw-r--r-- | plugins/Ping/src/ping.cpp | 30 | ||||
-rw-r--r-- | plugins/Ping/src/pinggraph.cpp | 355 | ||||
-rw-r--r-- | plugins/Ping/src/pinglist.cpp | 57 | ||||
-rw-r--r-- | plugins/Ping/src/pinglist.h | 2 | ||||
-rw-r--r-- | plugins/Ping/src/pingthread.cpp | 30 | ||||
-rw-r--r-- | plugins/Ping/src/rawping.cpp | 71 | ||||
-rw-r--r-- | plugins/Ping/src/rawping.h | 32 | ||||
-rw-r--r-- | plugins/Ping/src/utils.cpp | 142 | ||||
-rw-r--r-- | plugins/Ping/src/utils.h | 4 |
16 files changed, 626 insertions, 577 deletions
diff --git a/plugins/Ping/src/collection.h b/plugins/Ping/src/collection.h index 78fde37dfd..927d3db53d 100644 --- a/plugins/Ping/src/collection.h +++ b/plugins/Ping/src/collection.h @@ -2,56 +2,56 @@ template<class T> class Collection { protected:
unsigned long count;
public:
- Collection(): count(0) {}
+ Collection() : count(0) {}
virtual void clear() = 0;
virtual void add(const T &val) = 0;
virtual const bool remove(const T &val) = 0;
- const unsigned long size() const {return count;}
+ const unsigned long size() const { return count; }
};
template<class T> class Node {
public:
T val;
- Node(const T &v): val(v) {}
+ Node(const T &v) : val(v) {}
virtual ~Node() {}
};
-template<class T> class ListNode: public Node<T> {
+template<class T> class ListNode : public Node < T > {
public:
ListNode<T> *next, *prev;
- ListNode(const T &v): Node<T>(v), next(0), prev(0) {}
+ ListNode(const T &v) : Node<T>(v), next(0), prev(0) {}
virtual ~ListNode() {
- if(next) next->prev = prev;
- if(prev) prev->next = next;
+ if (next) next->prev = prev;
+ if (prev) prev->next = next;
}
};
-template<class T> class LinkedList: public Collection<T> {
+template<class T> class LinkedList : public Collection < T > {
protected:
ListNode<T> *head, *tail;
public:
class Iterator {
- friend class LinkedList<T>;
+ friend class LinkedList < T > ;
protected:
ListNode<T> *n;
- Iterator(ListNode<T> *start): n(start) {}
+ Iterator(ListNode<T> *start) : n(start) {}
public:
- Iterator(const Iterator &other): n(other.n) {}
+ Iterator(const Iterator &other) : n(other.n) {}
- virtual T &val() {return n->val;}
- virtual void next() {if(n) n = n->next;}
- virtual void prev() {if(n) n = n->prev;}
- virtual const bool has_val() {return (n ? true : false); }
+ virtual T &val() { return n->val; }
+ virtual void next() { if (n) n = n->next; }
+ virtual void prev() { if (n) n = n->prev; }
+ virtual const bool has_val() { return (n ? true : false); }
};
- LinkedList(): Collection<T>(), head(0), tail(0) {};
- LinkedList(const LinkedList<T> &other): Collection<T>(), head(0), tail(0) {
- for(Iterator i = other.begin(); i.has_val(); i.next())
+ LinkedList() : Collection<T>(), head(0), tail(0) {};
+ LinkedList(const LinkedList<T> &other) : Collection<T>(), head(0), tail(0) {
+ for (Iterator i = other.begin(); i.has_val(); i.next())
add(i.val());
}
virtual ~LinkedList() { clear(); }
@@ -59,7 +59,7 @@ public: LinkedList<T> &operator=(const LinkedList<T> &other)
{
clear();
- for(Iterator i = other.begin(); i.has_val(); i.next())
+ for (Iterator i = other.begin(); i.has_val(); i.next())
add(i.val());
return *this;
}
@@ -67,7 +67,7 @@ public: virtual void clear()
{
ListNode<T> *n;
- while(head) {
+ while (head) {
n = head;
head = head->next;
delete n;
@@ -76,37 +76,38 @@ public: Collection<T>::count = 0;
}
- virtual Iterator begin() const {return Iterator(head);}
+ virtual Iterator begin() const { return Iterator(head); }
virtual void add_front(T &val) {
ListNode<T> *n = new ListNode<T>(val);
n->next = head;
- if(head) head->prev = n;
+ if (head) head->prev = n;
head = n;
- if(!tail) tail = n;
+ if (!tail) tail = n;
Collection<T>::count++;
}
virtual void add(const T &val) {
ListNode<T> *n = new ListNode<T>(val);
n->prev = tail;
- if(tail) tail->next = n;
+ if (tail) tail->next = n;
tail = n;
- if(!head) head = n;
+ if (!head) head = n;
Collection<T>::count++;
}
virtual const bool remove(const T &val) {
ListNode<T> *n = head;
- while(n) {
- if(n->val == val) {
- if(n == head) head = head->next;
- if(n == tail) tail = tail->prev;
-
+ while (n) {
+ if (n->val == val) {
+ if (n == head) head = head->next;
+ if (n == tail) tail = tail->prev;
+
delete n;
Collection<T>::count--;
return true;
- } else
+ }
+ else
n = n->next;
}
@@ -115,10 +116,11 @@ public: virtual const bool contains(T &val) const {
ListNode<T> *n = head;
- while(n) {
- if(n->val == val) {
+ while (n) {
+ if (n->val == val) {
return true;
- } else
+ }
+ else
n = n->next;
}
@@ -137,22 +139,23 @@ public: }
virtual const bool pop(T &val) {
- if(!head) return false;
+ if (!head) return false;
ListNode<T> *n = head;
- if(head) {
+ if (head) {
head = head->next;
- if(n == tail) tail = 0;
+ if (n == tail) tail = 0;
val = n->val;
delete n;
Collection<T>::count--;
return true;
- } else
+ }
+ else
return false;
}
};
-template<class T> class DynamicArray: public Collection<T> {
+template<class T> class DynamicArray : public Collection < T > {
protected:
T *ar;
@@ -160,56 +163,57 @@ protected: public:
class Iterator {
- friend class DynamicArray<T>;
+ friend class DynamicArray < T > ;
protected:
T *ar;
unsigned long count;
unsigned long pos;
- Iterator(T *a, const int c, unsigned long p): ar(a), count(c), pos(p) {}
+ Iterator(T *a, const int c, unsigned long p) : ar(a), count(c), pos(p) {}
public:
- Iterator(const Iterator &other): ar(other.ar), count(other.count), pos(other.pos) {}
+ Iterator(const Iterator &other) : ar(other.ar), count(other.count), pos(other.pos) {}
- virtual T &val() {return ar[pos];}
- virtual void next() {pos++;}
- virtual void prev() {pos--;}
- virtual const bool has_val() {return pos < count; }
+ virtual T &val() { return ar[pos]; }
+ virtual void next() { pos++; }
+ virtual void prev() { pos--; }
+ virtual const bool has_val() { return pos < count; }
};
- DynamicArray(unsigned long init = 0, unsigned long inc = 1): Collection<T>(), ar(0), initial(init), limit(init), increment(inc) {
- if(limit) ar = (T *)malloc(limit * sizeof(T));
+ DynamicArray(unsigned long init = 0, unsigned long inc = 1) : Collection<T>(), ar(0), initial(init), limit(init), increment(inc) {
+ if (limit) ar = (T *)malloc(limit * sizeof(T));
}
- virtual ~DynamicArray() {if(ar) free(ar);}
+ virtual ~DynamicArray() { if (ar) free(ar); }
virtual void clear() {
Collection<T>::count = 0;
limit = initial;
- if(limit) ar = (T *)realloc(ar, limit * sizeof(T));
+ if (limit) ar = (T *)realloc(ar, limit * sizeof(T));
else {
free(ar);
ar = 0;
}
}
- virtual Iterator begin() const {return Iterator(ar, Collection<T>::count, 0);}
+ virtual Iterator begin() const { return Iterator(ar, Collection<T>::count, 0); }
virtual void add(const T &val) {
- if(Collection<T>::count == limit) {
+ if (Collection<T>::count == limit) {
limit += increment;
ar = (T *)realloc(ar, limit * sizeof(T));
ar[Collection<T>::count++] = val;
- } else
+ }
+ else
ar[Collection<T>::count++] = val;
}
virtual void add_all(DynamicArray<T> &other) {
- for(Iterator i = other.begin(); i != pl.end(); ++i) {
+ for (Iterator i = other.begin(); i != pl.end(); ++i) {
add(i.val());
}
}
virtual const bool remove(const T &val) {
- for(unsigned long i = 0; i < Collection<T>::count; i++) {
- if(ar[i] == val) {
+ for (unsigned long i = 0; i < Collection<T>::count; i++) {
+ if (ar[i] == val) {
memmove(ar + i, ar + i + 1, (Collection<T>::count - i) * sizeof(T));
Collection<T>::count--;
return true;
@@ -219,7 +223,7 @@ public: }
virtual const bool remove(const unsigned long index) {
- if(index >= Collection<T>::count) return false;
+ if (index >= Collection<T>::count) return false;
memmove(ar + index, ar + index + 1, (Collection<T>::count - index) * sizeof(T));
Collection<T>::count--;
@@ -227,16 +231,16 @@ public: }
virtual const bool insert(const T &val, const unsigned long index) {
- if(index > Collection<T>::count) return false;
+ if (index > Collection<T>::count) return false;
- if(Collection<T>::count == limit) {
+ if (Collection<T>::count == limit) {
limit += increment;
ar = (T *)realloc(ar, limit * sizeof(T));
}
- if(index < Collection<T>::count)
+ if (index < Collection<T>::count)
memmove(ar + index + 1, ar + index, (Collection<T>::count - index) * sizeof(T));
-
+
ar[index] = val;
Collection<T>::count++;
return true;
@@ -247,8 +251,8 @@ public: }
const bool index_of(const T &val, unsigned long &index) const {
- for(int i = 0; i < Collection<T>::count; i++) {
- if(ar[index] == val) {
+ for (int i = 0; i < Collection<T>::count; i++) {
+ if (ar[index] == val) {
index = i;
return true;
}
@@ -257,8 +261,8 @@ public: }
const int index_of(const T &val) const {
- for(int i = 0; i < Collection<T>::count; i++) {
- if(ar[i] == val) {
+ for (int i = 0; i < Collection<T>::count; i++) {
+ if (ar[i] == val) {
return i;
}
}
@@ -267,9 +271,9 @@ public: // stack functions
virtual const bool pop(T &val) {
- if(Collection<T>::count) {
- val = ar[Collection<T>::count -1];
- remove(Collection<T>::count -1);
+ if (Collection<T>::count) {
+ val = ar[Collection<T>::count - 1];
+ remove(Collection<T>::count - 1);
return true;
}
return false;
@@ -280,26 +284,28 @@ public: }
};
-template<class T> class SortedDynamicArray: public DynamicArray<T> {
+template<class T> class SortedDynamicArray : public DynamicArray < T > {
public:
- SortedDynamicArray(unsigned long init = 0, unsigned long inc = 1): DynamicArray<T>(init, inc) {}
+ SortedDynamicArray(unsigned long init = 0, unsigned long inc = 1) : DynamicArray<T>(init, inc) {}
virtual ~SortedDynamicArray() {}
const bool get_index(const T &val, unsigned long &index) {
- unsigned long low = 0;
- unsigned long high = Collection<T>::count-1;
-
- while( high < Collection<T>::count && low <= high )
- {
- unsigned long i = ( low+high )/2;
- if ( DynamicArray<T>::ar[i] == val )
- { index = i;
+ unsigned long low = 0;
+ unsigned long high = Collection<T>::count - 1;
+
+ while (high < Collection<T>::count && low <= high)
+ {
+ unsigned long i = (low + high) / 2;
+ if (DynamicArray<T>::ar[i] == val)
+ {
+ index = i;
return true;
- } else
+ }
+ else
if (DynamicArray<T>::ar[i] < val)
- low = i+1;
+ low = i + 1;
else
- high = i-1;
+ high = i - 1;
}
index = low;
@@ -313,47 +319,52 @@ public: }
};
-template<class T> class TreeNode: public Node<T> {
+template<class T> class TreeNode : public Node < T > {
public:
TreeNode<T> *parent, *left, *right;
- TreeNode(const T &v, TreeNode<T> *par): Node<T>(v), parent(par), left(0), right(0) {}
+ TreeNode(const T &v, TreeNode<T> *par) : Node<T>(v), parent(par), left(0), right(0) {}
virtual ~TreeNode() {
- if(parent) {
- if(parent->left == this) parent->left = 0;
- if(parent->right == this)parent->right = 0;
+ if (parent) {
+ if (parent->left == this) parent->left = 0;
+ if (parent->right == this)parent->right = 0;
}
}
};
-template<class T, class N = TreeNode<T> > class BinaryTree: public Collection<T> {
+template<class T, class N = TreeNode<T> > class BinaryTree : public Collection < T > {
protected:
N *root;
virtual void delete_node(N *n) {
- if(n->left && n->right) {
+ if (n->left && n->right) {
N *minmax = n->left;
- while(minmax->right) minmax = minmax->right;
+ while (minmax->right) minmax = minmax->right;
n->val = minmax->val;
delete_node(minmax);
return;
- } else if(n->right) {
- if(n->parent) {
- if(n->parent->left == n) n->parent->left = n->right;
+ }
+ else if (n->right) {
+ if (n->parent) {
+ if (n->parent->left == n) n->parent->left = n->right;
else n->parent->right = n->right;
- } else
+ }
+ else
root = n->right;
n->right->parent = n->parent;
- } else if(n->left) {
- if(n->parent) {
- if(n->parent->left == n) n->parent->left = n->left;
+ }
+ else if (n->left) {
+ if (n->parent) {
+ if (n->parent->left == n) n->parent->left = n->left;
else n->parent->right = n->left;
- } else
+ }
+ else
root = n->left;
n->left->parent = n->parent;
- } else {
- if(n == root) root = 0;
+ }
+ else {
+ if (n == root) root = 0;
}
delete n;
Collection<T>::count--;
@@ -361,21 +372,23 @@ protected: virtual void insert_node(N *n) {
N *current = root, *parent = 0;
- while(current) {
+ while (current) {
parent = current;
- if(n->val < current->val)
+ if (n->val < current->val)
current = current->left;
else
current = current->right;
}
- if(parent) {
- if(n->val < parent->val) {
+ if (parent) {
+ if (n->val < parent->val) {
parent->left = n;
- } else {
+ }
+ else {
parent->right = n;
}
- } else
+ }
+ else
root = n;
n->parent = parent;
@@ -384,7 +397,7 @@ protected: public:
class Iterator {
- friend class BinaryTree<T, N>;
+ friend class BinaryTree < T, N > ;
protected:
class EvalNode {
@@ -392,62 +405,62 @@ public: bool evaluate;
N *node;
- EvalNode(): evaluate(false), node(0) {}
- EvalNode(const bool eval, N *n): evaluate(eval), node(n) {}
- const bool operator==(const EvalNode &other) const {return node == other.node;}
- EvalNode &operator=(const EvalNode &other) {evaluate = other.evaluate; node = other.node; return *this;}
+ EvalNode() : evaluate(false), node(0) {}
+ EvalNode(const bool eval, N *n) : evaluate(eval), node(n) {}
+ const bool operator==(const EvalNode &other) const { return node == other.node; }
+ EvalNode &operator=(const EvalNode &other) { evaluate = other.evaluate; node = other.node; return *this; }
};
N *n;
LinkedList<EvalNode> stack;
-
- Iterator(N *start): n(0) {
- if(start) {
+
+ Iterator(N *start) : n(0) {
+ if (start) {
stack.push(EvalNode(true, start));
next();
}
}
public:
- Iterator(const Iterator &other):n(other.n), stack(other.stack) {}
+ Iterator(const Iterator &other) :n(other.n), stack(other.stack) {}
virtual ~Iterator() {}
- virtual T &val() {return n->val;}
+ virtual T &val() { return n->val; }
virtual void next() {
EvalNode en;
bool popped = false;
- while((popped = stack.pop(en)) && en.evaluate) {
- if(en.node->right) stack.push(EvalNode(true, en.node->right));
+ while ((popped = stack.pop(en)) && en.evaluate) {
+ if (en.node->right) stack.push(EvalNode(true, en.node->right));
stack.push(EvalNode(false, en.node));
- if(en.node->left) stack.push(EvalNode(true, en.node->left));
+ if (en.node->left) stack.push(EvalNode(true, en.node->left));
}
-
+
n = (popped ? en.node : 0);
}
- virtual const bool has_val() {return (n ? true : false);}
+ virtual const bool has_val() { return (n ? true : false); }
};
- BinaryTree(): Collection<T>(), root(0) {};
- BinaryTree(BinaryTree<T> &other): Collection<T>(), root(0) {
- for(Iterator i = other.begin(); i != pl.end(); ++i)
+ BinaryTree() : Collection<T>(), root(0) {};
+ BinaryTree(BinaryTree<T> &other) : Collection<T>(), root(0) {
+ for (Iterator i = other.begin(); i != pl.end(); ++i)
add(i.val());
}
- virtual ~BinaryTree() {clear();}
+ virtual ~BinaryTree() { clear(); }
BinaryTree &operator=(BinaryTree<T> &other) {
clear();
- for(Iterator i = other.begin(); i != pl.end(); ++i)
+ for (Iterator i = other.begin(); i != pl.end(); ++i)
add(i.val());
return *this;
}
virtual void clear() {
N *current = root, *parent = 0;
- while(current) {
- if(current->left) current = current->left;
- else if(current->right) current = current->right;
+ while (current) {
+ if (current->left) current = current->left;
+ else if (current->right) current = current->right;
else {
parent = current->parent;
delete current;
@@ -466,16 +479,16 @@ public: const bool remove(const T &val) {
N *current = root;
- while(current) {
- if(current->val == val)
+ while (current) {
+ if (current->val == val)
break;
- else if(val < current->val)
+ else if (val < current->val)
current = current->left;
- else
+ else
current = current->right;
}
- if(current) {
+ if (current) {
delete_node(current);
return true;
}
@@ -485,40 +498,40 @@ public: const bool contains(const T &val) const {
N *current = root;
- while(current) {
- if(current->val == val)
+ while (current) {
+ if (current->val == val)
break;
- else if(val < current->val)
+ else if (val < current->val)
current = current->left;
- else
+ else
current = current->right;
}
return current != 0;
}
- Iterator begin() const {return Iterator(root);}
+ Iterator begin() const { return Iterator(root); }
};
#define RED 1
#define BLACK 0
// thanks to wikipedia (http://en.wikipedia.org/wiki/Red_black_tree)
-template<class T> class ColouredTreeNode: public Node<T> {
+template<class T> class ColouredTreeNode : public Node < T > {
public:
ColouredTreeNode<T> *parent, *left, *right;
char color;
- ColouredTreeNode(const T &v, ColouredTreeNode<T> *par): Node<T>(v), parent(par), left(0), right(0), color(BLACK) {}
+ ColouredTreeNode(const T &v, ColouredTreeNode<T> *par) : Node<T>(v), parent(par), left(0), right(0), color(BLACK) {}
virtual ~ColouredTreeNode() {
- if(parent) {
- if(parent->left == this) parent->left = 0;
- if(parent->right == this)parent->right = 0;
+ if (parent) {
+ if (parent->left == this) parent->left = 0;
+ if (parent->right == this)parent->right = 0;
}
}
};
-template<class T, class N = ColouredTreeNode<T> > class RedBlackTree: public BinaryTree<T, N> {
+template<class T, class N = ColouredTreeNode<T> > class RedBlackTree : public BinaryTree < T, N > {
protected:
N *grandparent(N *n) {
if (n && n->parent)
@@ -527,21 +540,23 @@ protected: return NULL;
}
N *uncle(N *n) {
- if(grandparent(n)) {
+ if (grandparent(n)) {
if (n->parent == grandparent(n)->left)
return grandparent(n)->right;
else
return grandparent(n)->left;
- } else
+ }
+ else
return NULL;
}
N *sibling(N *n) {
- if(n->parent) {
+ if (n->parent) {
if (n == n->parent->left)
return n->parent->right;
else
return n->parent->left;
- } else
+ }
+ else
return NULL;
}
bool is_leaf(N *n) {
@@ -550,10 +565,11 @@ protected: void replace_node(N *o, N *n) {
n->parent = o->parent;
- if(n->parent) {
- if(n->parent->left == o) n->parent->left = n;
- else if(n->parent->right == o) n->parent->right = n;
- } else
+ if (n->parent) {
+ if (n->parent->left == o) n->parent->left = n;
+ else if (n->parent->right == o) n->parent->right = n;
+ }
+ else
BinaryTree<T, N>::root = n;
}
@@ -562,14 +578,15 @@ protected: N *q = n;
q->right = p->left;
- if(q->right) q->right->parent = q;
+ if (q->right) q->right->parent = q;
p->left = q;
p->parent = q->parent;
q->parent = p;
- if(p->parent) {
- if(p->parent->left == q) p->parent->left = p;
- else if(p->parent->right == q) p->parent->right = p;
- } else
+ if (p->parent) {
+ if (p->parent->left == q) p->parent->left = p;
+ else if (p->parent->right == q) p->parent->right = p;
+ }
+ else
BinaryTree<T, N>::root = p;
}
void rotate_right(N *n) {
@@ -577,14 +594,15 @@ protected: N *q = n;
q->left = p->right;
- if(q->left) q->left->parent = q;
+ if (q->left) q->left->parent = q;
p->right = q;
p->parent = q->parent;
q->parent = p;
- if(p->parent) {
- if(p->parent->left == q) p->parent->left = p;
- else if(p->parent->right == q) p->parent->right = p;
- } else
+ if (p->parent) {
+ if (p->parent->left == q) p->parent->left = p;
+ else if (p->parent->right == q) p->parent->right = p;
+ }
+ else
BinaryTree<T, N>::root = p;
}
@@ -606,14 +624,16 @@ protected: uncle(n)->color = BLACK;
grandparent(n)->color = RED;
insert_case1(grandparent(n));
- } else
+ }
+ else
insert_case4(n);
}
void insert_case4(N *n) {
if (n == n->parent->right && n->parent == grandparent(n)->left) {
rotate_left(n->parent);
n = n->left;
- } else if (n == n->parent->left && n->parent == grandparent(n)->right) {
+ }
+ else if (n == n->parent->left && n->parent == grandparent(n)->right) {
rotate_right(n->parent);
n = n->right;
}
@@ -624,7 +644,8 @@ protected: grandparent(n)->color = RED;
if (n == n->parent->left && n->parent == grandparent(n)->left) {
rotate_right(grandparent(n));
- } else {
+ }
+ else {
/* Here, n == n->parent->right && n->parent == grandparent(n)->right */
rotate_left(grandparent(n));
}
@@ -633,17 +654,18 @@ protected: void delete_case0(N *n) {
/* Precondition: n has at most one non-null child */
N *child = is_leaf(n->right) ? n->left : n->right;
- if(child) replace_node(n, child);
+ if (child) replace_node(n, child);
if (n->color == BLACK) {
- if(child) {
+ if (child) {
if (child->color == RED)
child->color = BLACK;
else
delete_case1(child);
- } else
+ }
+ else
delete_case1(n);
}
- if(BinaryTree<T, N>::root == n) BinaryTree<T, N>::root = 0;
+ if (BinaryTree<T, N>::root == n) BinaryTree<T, N>::root = 0;
delete n;
Collection<T>::count--;
}
@@ -673,7 +695,8 @@ protected: {
sibling(n)->color = RED;
delete_case1(n->parent);
- } else
+ }
+ else
delete_case4(n);
}
void delete_case4(N *n) {
@@ -685,24 +708,26 @@ protected: {
sibling(n)->color = RED;
n->parent->color = BLACK;
- } else
+ }
+ else
delete_case5(n);
}
void delete_case5(N *n) {
if (n == n->parent->left &&
- sibling(n) &&
+ sibling(n) &&
sibling(n)->color == BLACK &&
- sibling(n)->left &&
+ sibling(n)->left &&
sibling(n)->left->color == RED &&
(sibling(n)->right == 0 || sibling(n)->right->color == BLACK))
{
sibling(n)->color = RED;
sibling(n)->left->color = BLACK;
rotate_right(sibling(n));
- } else if (n == n->parent->right &&
- sibling(n) &&
+ }
+ else if (n == n->parent->right &&
+ sibling(n) &&
sibling(n)->color == BLACK &&
- sibling(n)->right &&
+ sibling(n)->right &&
sibling(n)->right->color == RED &&
(sibling(n)->left == 0 || sibling(n)->left->color == BLACK))
{
@@ -719,7 +744,8 @@ protected: /* Here, sibling(n)->right->color == RED */
sibling(n)->right->color = BLACK;
rotate_left(n->parent);
- } else {
+ }
+ else {
/* Here, sibling(n)->left->color == RED */
sibling(n)->left->color = BLACK;
rotate_right(n->parent);
@@ -728,7 +754,7 @@ protected: N *get_predecessor(N *n) {
N *minmax = n->left;
- while(minmax->right) minmax = minmax->right;
+ while (minmax->right) minmax = minmax->right;
return minmax;
}
@@ -740,16 +766,17 @@ protected: }
virtual void delete_node(N *n) {
- if(n->left && n->right) {
+ if (n->left && n->right) {
N *predecessor = get_predecessor(n);
n->val = predecessor->val;
delete_case0(predecessor);
- } else
+ }
+ else
delete_case0(n);
}
public:
- RedBlackTree(): BinaryTree< T, N >() {}
+ RedBlackTree() : BinaryTree< T, N >() {}
virtual ~RedBlackTree() {}
};
@@ -758,26 +785,26 @@ public: A first;
B second;
- Pair(const A &f): first(f) {}
- Pair(const A &f, const B &s): first(f), second(s) {}
- Pair(const Pair<A,B> &other): first(other.first), second(other.second) {}
+ Pair(const A &f) : first(f) {}
+ Pair(const A &f, const B &s) : first(f), second(s) {}
+ Pair(const Pair<A, B> &other) : first(other.first), second(other.second) {}
virtual ~Pair() {}
- const bool operator<(const Pair<A,B> &other) const {return first < other.first;}
- const bool operator==(const Pair<A,B> &other) const {return first == other.first;}
- Pair<A,B> &operator=(const Pair<A,B> &other) {first = other.first; second = other.second; return *this;}
+ const bool operator<(const Pair<A, B> &other) const { return first < other.first; }
+ const bool operator==(const Pair<A, B> &other) const { return first == other.first; }
+ Pair<A, B> &operator=(const Pair<A, B> &other) { first = other.first; second = other.second; return *this; }
};
//template<class A, class B, class N = TreeNode<Pair<A, B> > > class Map: public BinaryTree< Pair< A, B >, N > {
-template<class A, class B, class N = ColouredTreeNode<Pair<A, B> > > class Map: public RedBlackTree< Pair< A, B >, N > {
+template<class A, class B, class N = ColouredTreeNode<Pair<A, B> > > class Map : public RedBlackTree < Pair< A, B >, N > {
protected:
-
+
N *find(A &key) const {
N *n = RedBlackTree< Pair< A, B >, N >::root;
- while(n) {
- if(n->val.first == key)
+ while (n) {
+ if (n->val.first == key)
return n;
- else if(key < n->val.first)
+ else if (key < n->val.first)
n = n->left;
else
n = n->right;
@@ -787,25 +814,26 @@ protected: }
public:
//Map(): BinaryTree< Pair<A,B>, N >() {}
- Map(): RedBlackTree< Pair<A,B>, N >() {}
+ Map() : RedBlackTree< Pair<A, B>, N >() {}
virtual ~Map() {}
void put(A &key, B &value) {
- add(Pair<A,B>(key, value));
+ add(Pair<A, B>(key, value));
}
const bool get(A &key, B &val) const {
const N *n = find(key);
- if(n) {
+ if (n) {
val = n->val.second;
return true;
- } else
+ }
+ else
return false;
}
B &operator[](A &key) {
N *n = find(key);
- if(n)
+ if (n)
return n->val.second;
else {
Pair< A, B > p(key);
@@ -817,18 +845,20 @@ public: virtual const bool exists(A &key) const {
const N *n = find(key);
- if(n) {
+ if (n) {
return true;
- } else
+ }
+ else
return false;
}
virtual const bool remove(A &key) {
N *n = find(key);
- if(n) {
+ if (n) {
delete_node(n);
return true;
- } else
+ }
+ else
return false;
}
};
diff --git a/plugins/Ping/src/common.h b/plugins/Ping/src/common.h index 5242b5c848..69853c41bd 100644 --- a/plugins/Ping/src/common.h +++ b/plugins/Ping/src/common.h @@ -73,7 +73,7 @@ struct HistPair { short first;
time_t second;
- const bool operator==(const HistPair &other) const {return first == other.first && second == other.second;}
+ const bool operator==(const HistPair &other) const { return first == other.first && second == other.second; }
};
typedef LinkedList< HistPair > HistoryList;
@@ -125,7 +125,7 @@ extern PINGLIST list_items; extern HANDLE reload_event_handle;
extern mir_cs list_cs;
extern HANDLE mainThread;
-extern HANDLE hWakeEvent;
+extern HANDLE hWakeEvent;
extern mir_cs thread_finished_cs, list_changed_cs, data_list_cs;
extern PINGLIST data_list;
diff --git a/plugins/Ping/src/icmp.cpp b/plugins/Ping/src/icmp.cpp index dfa0c86578..84dd47d272 100644 --- a/plugins/Ping/src/icmp.cpp +++ b/plugins/Ping/src/icmp.cpp @@ -5,15 +5,15 @@ ICMP *ICMP::instance = 0; #define BUFFER_SIZE (16 * (sizeof(ICMP_ECHO_REPLY) + sizeof(data)))
-ICMP::ICMP():
- timeout(2000),
- functions_loaded(false)
+ICMP::ICMP() :
+timeout(2000),
+functions_loaded(false)
{
WSAData wsaData;
if (WSAStartup(MAKEWORD(1, 1), &wsaData) != 0) {
WSACleanup();
return;
- }
+ }
buff = new char[BUFFER_SIZE];
functions_loaded = true;
@@ -24,7 +24,7 @@ void ICMP::stop() }
ICMP::~ICMP() {
- if(hIP) stop();
+ if (hIP) stop();
WSACleanup();
delete[] buff;
}
@@ -53,7 +53,7 @@ bool ICMP::ping(char *host, ICMP_ECHO_REPLY &reply) ipoi.Flags = 0;
ipoi.OptionsSize = 0;
ipoi.OptionsData = 0;
-
+
reply.Status = 0;
hIP = IcmpCreateFile();
@@ -81,11 +81,11 @@ bool ICMP::ping(char *host, ICMP_ECHO_REPLY &reply) }
ICMP *ICMP::get_instance() {
- if(!instance)
+ if (!instance)
instance = new ICMP();
return instance;
}
void ICMP::cleanup() {
- if(instance) delete instance;
+ if (instance) delete instance;
}
\ No newline at end of file diff --git a/plugins/Ping/src/icmp.h b/plugins/Ping/src/icmp.h index 110f5b554c..d3b8e665a1 100644 --- a/plugins/Ping/src/icmp.h +++ b/plugins/Ping/src/icmp.h @@ -22,14 +22,14 @@ public: static void cleanup();
bool ping(char *host, ICMP_ECHO_REPLY &reply);
-
+
void set_timeout(unsigned int t) {
timeout = t;
}
void stop();
- unsigned int get_timeout() {return timeout;}
+ unsigned int get_timeout() { return timeout; }
};
#endif //_ICMP_H
diff --git a/plugins/Ping/src/log.cpp b/plugins/Ping/src/log.cpp index 65695872b9..cc9a166947 100644 --- a/plugins/Ping/src/log.cpp +++ b/plugins/Ping/src/log.cpp @@ -7,7 +7,7 @@ INT_PTR Log(WPARAM wParam, LPARAM) { //char TBcapt[255];
SYSTEMTIME systime;
-
+
GetLocalTime(&systime);
GetTimeFormat(LOCALE_USER_DEFAULT, 0, &systime, 0, tbuf, 512);
@@ -16,10 +16,11 @@ INT_PTR Log(WPARAM wParam, LPARAM) { TCHAR *line = (TCHAR *)wParam;
FILE *f = _tfopen(buf, _T("a+"));
- if(f) {
- if(options.log_csv) {
+ if (f) {
+ if (options.log_csv) {
_ftprintf(f, _T("%s, %s, %s\n"), dbuf, tbuf, line);
- } else {
+ }
+ else {
_ftprintf(f, _T("%s, %s: %s\n"), dbuf, tbuf, line);
}
fclose(f);
@@ -31,11 +32,12 @@ INT_PTR Log(WPARAM wParam, LPARAM) { INT_PTR GetLogFilename(WPARAM wParam, LPARAM lParam) {
DBVARIANT dbv;
TCHAR *filename = (TCHAR *)lParam;
- if(db_get_ts(0, PLUG, "LogFilename", &dbv)) {
+ if (db_get_ts(0, PLUG, "LogFilename", &dbv)) {
CallService(MS_DB_GETPROFILEPATHT, wParam, (LPARAM)filename);
- _tcsncat(filename, _T("\\ping_log.txt"),wParam);
- } else {
- _tcsncpy(filename, dbv.ptszVal, wParam);
+ mir_tstrncat(filename, _T("\\ping_log.txt"), _TRUNCATE);
+ }
+ else {
+ mir_tstrncpy(filename, dbv.ptszVal, wParam);
db_free(&dbv);
}
@@ -52,6 +54,6 @@ INT_PTR SetLogFilename(WPARAM, LPARAM lParam) { INT_PTR ViewLogData(WPARAM wParam, LPARAM) {
TCHAR buf[MAX_PATH];
CallService(PLUG "/GetLogFilename", (WPARAM)MAX_PATH, (LPARAM)buf);
- return (INT_PTR)ShellExecute((HWND)wParam, _T("edit"), buf, _T(""), _T(""), SW_SHOW);
+ return (INT_PTR)ShellExecute((HWND)wParam, _T("edit"), buf, _T(""), _T(""), SW_SHOW);
}
diff --git a/plugins/Ping/src/options.cpp b/plugins/Ping/src/options.cpp index b2f698a9cf..cab4183c93 100644 --- a/plugins/Ping/src/options.cpp +++ b/plugins/Ping/src/options.cpp @@ -241,7 +241,7 @@ INT_PTR CALLBACK DlgProcDestEdit(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l if (SendDlgItemMessage(hwndDlg, IDC_COMBO_DESTPROTO, CB_GETCURSEL, 0, 0) != -1)
{
GetDlgItemTextA(hwndDlg, IDC_COMBO_DESTPROTO, add_edit_addr.pszProto, SIZEOF(add_edit_addr.pszProto));
- if (!strcmp(add_edit_addr.pszProto, Translate("<none>")))
+ if (!mir_strcmp(add_edit_addr.pszProto, Translate("<none>")))
add_edit_addr.pszProto[0] = '\0';
else {
int sel = SendDlgItemMessage(hwndDlg, IDC_COMBO_DESTSTAT, CB_GETCURSEL, 0, 0);
diff --git a/plugins/Ping/src/options.h b/plugins/Ping/src/options.h index 8ea876a40f..9bbfca0ca7 100644 --- a/plugins/Ping/src/options.h +++ b/plugins/Ping/src/options.h @@ -3,7 +3,7 @@ INT_PTR CALLBACK DlgProcDestEdit(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
-int PingOptInit(WPARAM wParam,LPARAM lParam);
+int PingOptInit(WPARAM wParam, LPARAM lParam);
bool Edit(HWND hwnd, PINGADDRESS &addr);
diff --git a/plugins/Ping/src/ping.cpp b/plugins/Ping/src/ping.cpp index 9b07356ed1..a1654e9f1d 100644 --- a/plugins/Ping/src/ping.cpp +++ b/plugins/Ping/src/ping.cpp @@ -9,7 +9,7 @@ HANDLE hFillListEvent = 0; bool use_raw_ping = true;
// plugin stuff
-PLUGININFOEX pluginInfo={
+PLUGININFOEX pluginInfo = {
sizeof(PLUGININFOEX),
__PLUGIN_NAME,
PLUGIN_MAKE_VERSION(__MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM),
@@ -20,7 +20,7 @@ PLUGININFOEX pluginInfo={ __AUTHORWEB,
UNICODE_AWARE,
// {760EA901-C0C2-446C-8029-94C3BC47C45E}
- {0x760ea901, 0xc0c2, 0x446c, {0x80, 0x29, 0x94, 0xc3, 0xbc, 0x47, 0xc4, 0x5e}}
+ { 0x760ea901, 0xc0c2, 0x446c, { 0x80, 0x29, 0x94, 0xc3, 0xbc, 0x47, 0xc4, 0x5e } }
};
extern "C" BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
@@ -48,7 +48,7 @@ void CreatePluginServices() { CreateServiceFunction(PLUG "/SavePingList", SavePingList);
reload_event_handle = CreateHookableEvent(PLUG "/ListReload");
-
+
//log
CreateServiceFunction(PLUG "/Log", Log);
CreateServiceFunction(PLUG "/ViewLogData", ViewLogData);
@@ -71,7 +71,7 @@ int OnShutdown(WPARAM wParam, LPARAM lParam) { DeinitList();
- if(use_raw_ping)
+ if (use_raw_ping)
cleanup_raw_ping();
else
ICMP::cleanup();
@@ -80,7 +80,7 @@ int OnShutdown(WPARAM wParam, LPARAM lParam) { }
int OnModulesLoaded(WPARAM, LPARAM) {
- NETLIBUSER nl_user = {0};
+ NETLIBUSER nl_user = { 0 };
nl_user.cbSize = sizeof(nl_user);
nl_user.szSettingsModule = PLUG;
nl_user.flags = NUF_OUTGOING | NUF_HTTPCONNS | NUF_TCHAR;
@@ -99,8 +99,8 @@ int OnModulesLoaded(WPARAM, LPARAM) { hFillListEvent = HookEvent(PLUG "/ListReload", FillList);
- if(!db_get_b(0, PLUG, "PingPlugImport", 0)) {
- if(db_get_dw(0, "PingPlug", "NumEntries", 0)) {
+ if (!db_get_b(0, PLUG, "PingPlugImport", 0)) {
+ if (db_get_dw(0, "PingPlug", "NumEntries", 0)) {
import_ping_addresses();
db_set_b(0, PLUG, "PingPlugImport", 1);
}
@@ -112,7 +112,7 @@ int OnModulesLoaded(WPARAM, LPARAM) { graphs_init();
- if(options.logging) CallService(PLUG "/Log", (WPARAM)_T("start"), 0);
+ if (options.logging) CallService(PLUG "/Log", (WPARAM)_T("start"), 0);
return 0;
}
@@ -128,13 +128,13 @@ static IconItem iconList[] = extern "C" __declspec(dllexport) int Load(void)
{
//if(init_raw_ping()) {
- //MessageBox(0, Translate("Failed to initialize. Plugin disabled."), Translate("Ping Plugin"), MB_OK | MB_ICONERROR);
- //return 1;
- use_raw_ping = false;
+ //MessageBox(0, Translate("Failed to initialize. Plugin disabled."), Translate("Ping Plugin"), MB_OK | MB_ICONERROR);
+ //return 1;
+ use_raw_ping = false;
//}
db_set_b(0, PLUG, "UsingRawSockets", (BYTE)use_raw_ping);
- DuplicateHandle( GetCurrentProcess(), GetCurrentThread(), GetCurrentProcess(), &mainThread, THREAD_SET_CONTEXT, FALSE, 0 );
+ DuplicateHandle(GetCurrentProcess(), GetCurrentThread(), GetCurrentProcess(), &mainThread, THREAD_SET_CONTEXT, FALSE, 0);
hWakeEvent = CreateEvent(NULL, FALSE, FALSE, _T("Local\\ThreadWaitEvent"));
// create services before loading options - so we can have the 'getlogfilename' service!
@@ -147,7 +147,7 @@ extern "C" __declspec(dllexport) int Load(void) HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded);
- HookEvent(ME_OPT_INITIALISE, PingOptInit );
+ HookEvent(ME_OPT_INITIALISE, PingOptInit);
HookEvent(ME_SYSTEM_PRESHUTDOWN, OnShutdown);
@@ -162,9 +162,9 @@ extern "C" __declspec(dllexport) int Unload(void) {
SavePingList(0, 0);
- CloseHandle( mainThread );
+ CloseHandle(mainThread);
- if(options.logging) CallService(PLUG "/Log", (WPARAM)_T("stop"), 0);
+ if (options.logging) CallService(PLUG "/Log", (WPARAM)_T("stop"), 0);
return 0;
}
diff --git a/plugins/Ping/src/pinggraph.cpp b/plugins/Ping/src/pinggraph.cpp index 735d8a4bfa..64be901181 100644 --- a/plugins/Ping/src/pinggraph.cpp +++ b/plugins/Ping/src/pinggraph.cpp @@ -17,38 +17,38 @@ struct WindowData { LRESULT CALLBACK GraphWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
- switch(msg) {
+ switch (msg) {
case WM_REBUILDLIST:
- {
- WindowData *wd = (WindowData *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
-
- bool found = false;
- mir_cslock lck(data_list_cs);
- for(pinglist_it i = data_list.begin(); i != data_list.end(); ++i) {
- if(i->item_id == wd->item_id) {
- wd->list = history_map[wd->item_id];
- found = true;
- break;
- }
- }
-
- if(!found) {
- PostMessage(hwnd, WM_CLOSE, 0, 0);
- return TRUE;
+ {
+ WindowData *wd = (WindowData *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
+
+ bool found = false;
+ mir_cslock lck(data_list_cs);
+ for (pinglist_it i = data_list.begin(); i != data_list.end(); ++i) {
+ if (i->item_id == wd->item_id) {
+ wd->list = history_map[wd->item_id];
+ found = true;
+ break;
}
+ }
- InvalidateRect(hwnd, 0, FALSE);
+ if (!found) {
+ PostMessage(hwnd, WM_CLOSE, 0, 0);
+ return TRUE;
}
- return TRUE;
+
+ InvalidateRect(hwnd, 0, FALSE);
+ }
+ return TRUE;
case WM_SHOWWINDOW:
- if(wParam == TRUE && lParam == 0) {
+ if (wParam == TRUE && lParam == 0) {
WindowData *wd = (WindowData *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
- if(wd->hwnd_chk_grid == 0) {
+ if (wd->hwnd_chk_grid == 0) {
wd->hwnd_chk_grid = CreateWindow(_T("BUTTON"), TranslateT("Show grid lines"), WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX, 0, 0, 0, 0, hwnd, 0, hInst, 0);
SendMessage(wd->hwnd_chk_grid, BM_SETCHECK, wd->show_grid ? BST_CHECKED : BST_UNCHECKED, 0);
}
- if(wd->hwnd_chk_stat == 0) {
+ if (wd->hwnd_chk_stat == 0) {
wd->hwnd_chk_stat = CreateWindow(_T("BUTTON"), TranslateT("Show stats"), WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX, 0, 0, 0, 0, hwnd, 0, hInst, 0);
SendMessage(wd->hwnd_chk_stat, BM_SETCHECK, wd->show_stat ? BST_CHECKED : BST_UNCHECKED, 0);
}
@@ -63,189 +63,190 @@ LRESULT CALLBACK GraphWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPar }
break;
case WM_COMMAND:
- if(HIWORD(wParam) == BN_CLICKED) {
+ if (HIWORD(wParam) == BN_CLICKED) {
WindowData *wd = (WindowData *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
- if((HWND)lParam == wd->hwnd_chk_grid) {
+ if ((HWND)lParam == wd->hwnd_chk_grid) {
wd->show_grid = (SendMessage(wd->hwnd_chk_grid, BM_GETCHECK, 0, 0) == BST_CHECKED);
- } else if((HWND)lParam == wd->hwnd_chk_stat) {
+ }
+ else if ((HWND)lParam == wd->hwnd_chk_stat) {
wd->show_stat = (SendMessage(wd->hwnd_chk_stat, BM_GETCHECK, 0, 0) == BST_CHECKED);
}
InvalidateRect(hwnd, 0, TRUE);
}
return TRUE;
case WM_TIMER:
- {
- SendMessage(hwnd, WM_REBUILDLIST, 0, 0);
- }
- return TRUE;
+ {
+ SendMessage(hwnd, WM_REBUILDLIST, 0, 0);
+ }
+ return TRUE;
case WM_PAINT:
+ {
+ PAINTSTRUCT ps;
+ HDC hdc;
+ RECT r;
+ WindowData *wd = (WindowData *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
+ if (wd && (hdc = BeginPaint(hwnd, &ps)) != 0)
{
- PAINTSTRUCT ps;
- HDC hdc;
- RECT r;
- WindowData *wd = (WindowData *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
- if (wd && (hdc = BeginPaint(hwnd, &ps)) != 0)
- {
- GetClientRect(hwnd, &r);
- FillRect(hdc, &r, GetSysColorBrush(COLOR_WINDOW));
+ GetClientRect(hwnd, &r);
+ FillRect(hdc, &r, GetSysColorBrush(COLOR_WINDOW));
- short max_value = -1, min_value = (short)0x7FFF,
- graph_height = 0; // this is minimum graph height, in ms
+ short max_value = -1, min_value = (short)0x7FFF,
+ graph_height = 0; // this is minimum graph height, in ms
- double avg = 0;
- for(HistoryList::Iterator hli = wd->list.begin(); hli.has_val(); hli.next())
- {
- if (hli.val().first > max_value)
- max_value = hli.val().first;
- if (hli.val().first >= 0 && hli.val().first < min_value)
- min_value = hli.val().first;
- avg += hli.val().first;
- }
+ double avg = 0;
+ for (HistoryList::Iterator hli = wd->list.begin(); hli.has_val(); hli.next())
+ {
+ if (hli.val().first > max_value)
+ max_value = hli.val().first;
+ if (hli.val().first >= 0 && hli.val().first < min_value)
+ min_value = hli.val().first;
+ avg += hli.val().first;
+ }
- if (wd->list.size())
- avg /= wd->list.size();
+ if (wd->list.size())
+ avg /= wd->list.size();
- graph_height = (int)(max_value * 1.2f);
+ graph_height = (int)(max_value * 1.2f);
- if(graph_height < MIN_GRAPH_HEIGHT)
- graph_height = MIN_GRAPH_HEIGHT;
+ if (graph_height < MIN_GRAPH_HEIGHT)
+ graph_height = MIN_GRAPH_HEIGHT;
#ifdef max
- float unit_width = (r.right - r.left) / (float)max((int)wd->list.size(), MIN_BARS), // space for at least MIN_BARS bars
+ float unit_width = (r.right - r.left) / (float)max((int)wd->list.size(), MIN_BARS), // space for at least MIN_BARS bars
#else
- float unit_width = (r.right - r.left) / (float)std::max((int)wd->list.size(), MIN_BARS), // space for at least MIN_BARS bars
+ float unit_width = (r.right - r.left) / (float)std::max((int)wd->list.size(), MIN_BARS), // space for at least MIN_BARS bars
#endif
- unit_height = (r.bottom - r.top) / (float)graph_height;
+ unit_height = (r.bottom - r.top) / (float)graph_height;
- time_t last_time = 0, time, start_time = 0;
- if(wd->list.size())
- start_time = wd->list.begin().val().second;
+ time_t last_time = 0, time, start_time = 0;
+ if (wd->list.size())
+ start_time = wd->list.begin().val().second;
- RECT bar;
- bar.bottom = r.bottom;
- float x = r.right - (unit_width * wd->list.size() + 0.5f);
- bar.left = (int)(x + 0.5f);
- bar.right = (int)(x + unit_width + 0.5f);
+ RECT bar;
+ bar.bottom = r.bottom;
+ float x = r.right - (unit_width * wd->list.size() + 0.5f);
+ bar.left = (int)(x + 0.5f);
+ bar.right = (int)(x + unit_width + 0.5f);
- // set up pen for horiz (ping time) and vert (time covered by graph) lines
- HPEN hPenOld, hPen = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_3DDKSHADOW));
- hPenOld = (HPEN)SelectObject(hdc, hPen);
+ // set up pen for horiz (ping time) and vert (time covered by graph) lines
+ HPEN hPenOld, hPen = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_3DDKSHADOW));
+ hPenOld = (HPEN)SelectObject(hdc, hPen);
- for(HistoryList::Iterator hi = wd->list.begin(); hi.has_val(); hi.next())
+ for (HistoryList::Iterator hi = wd->list.begin(); hi.has_val(); hi.next())
+ {
+ if (hi.val().first != -1)
{
- if(hi.val().first != -1)
- {
- bar.top = bar.bottom - (int)(hi.val().first * unit_height + 0.5f);
- FillRect(hdc, &bar, GetSysColorBrush(COLOR_HOTLIGHT));
- }
+ bar.top = bar.bottom - (int)(hi.val().first * unit_height + 0.5f);
+ FillRect(hdc, &bar, GetSysColorBrush(COLOR_HOTLIGHT));
+ }
- time = hi.val().second - start_time;
+ time = hi.val().second - start_time;
- if(time / MARK_PERIOD != last_time / MARK_PERIOD)
- { // new minute
- MoveToEx(hdc, bar.left, r.bottom, 0);
- LineTo(hdc, bar.left, r.top);
- }
+ if (time / MARK_PERIOD != last_time / MARK_PERIOD)
+ { // new minute
+ MoveToEx(hdc, bar.left, r.bottom, 0);
+ LineTo(hdc, bar.left, r.top);
+ }
- last_time = time;
+ last_time = time;
- x += unit_width;
- bar.left = bar.right;
- bar.right = (int)(x + unit_width + 0.5f);
- }
+ x += unit_width;
+ bar.left = bar.right;
+ bar.right = (int)(x + unit_width + 0.5f);
+ }
- if(wd->show_grid)
+ if (wd->show_grid)
+ {
+ // draw horizontal lines to mark every 100ms
+ for (int li = 0; li < graph_height; li += MARK_TIME)
{
- // draw horizontal lines to mark every 100ms
- for(int li = 0; li < graph_height; li += MARK_TIME)
- {
- MoveToEx(hdc, r.left, r.bottom - (int)(li * unit_height + 0.5f), 0);
- LineTo(hdc, r.right, r.bottom - (int)(li * unit_height + 0.5f));
- }
+ MoveToEx(hdc, r.left, r.bottom - (int)(li * unit_height + 0.5f), 0);
+ LineTo(hdc, r.right, r.bottom - (int)(li * unit_height + 0.5f));
}
+ }
- HPEN hPen2 = CreatePen(PS_SOLID, 1, RGB(255, 0, 0));
- if(wd->show_stat)
+ HPEN hPen2 = CreatePen(PS_SOLID, 1, RGB(255, 0, 0));
+ if (wd->show_stat)
+ {
+ SelectObject(hdc, hPen2);
+ MoveToEx(hdc, r.left, r.bottom - (int)(avg * unit_height + 0.5f), 0);
+ LineTo(hdc, r.right, r.bottom - (int)(avg * unit_height + 0.5f));
+ if (max_value != avg)
{
- SelectObject(hdc, hPen2);
- MoveToEx(hdc, r.left, r.bottom - (int)(avg * unit_height + 0.5f), 0);
- LineTo(hdc, r.right, r.bottom - (int)(avg * unit_height + 0.5f));
- if (max_value != avg)
- {
- MoveToEx(hdc, r.left, r.bottom - (int)(max_value * unit_height + 0.5f), 0);
- LineTo(hdc, r.right, r.bottom - (int)(max_value * unit_height + 0.5f));
- MoveToEx(hdc, r.left, r.bottom - (int)(min_value * unit_height + 0.5f), 0);
- LineTo(hdc, r.right, r.bottom - (int)(min_value * unit_height + 0.5f));
- }
+ MoveToEx(hdc, r.left, r.bottom - (int)(max_value * unit_height + 0.5f), 0);
+ LineTo(hdc, r.right, r.bottom - (int)(max_value * unit_height + 0.5f));
+ MoveToEx(hdc, r.left, r.bottom - (int)(min_value * unit_height + 0.5f), 0);
+ LineTo(hdc, r.right, r.bottom - (int)(min_value * unit_height + 0.5f));
}
+ }
- // restore pen
- SelectObject(hdc, hPenOld);
- DeleteObject(hPen);
- DeleteObject(hPen2);
+ // restore pen
+ SelectObject(hdc, hPenOld);
+ DeleteObject(hPen);
+ DeleteObject(hPen2);
- SetBkMode(hdc, TRANSPARENT);
- SetTextColor(hdc, GetSysColor(COLOR_3DDKSHADOW));
- TCHAR buff[64];
- if(wd->show_grid)
- {
- mir_sntprintf(buff, SIZEOF(buff), TranslateT("%d ms"), MARK_TIME);
- TextOut(hdc, r.right - 100, r.bottom - (int)(unit_height * MARK_TIME + 0.5f), buff, (int)_tcslen(buff));
- }
+ SetBkMode(hdc, TRANSPARENT);
+ SetTextColor(hdc, GetSysColor(COLOR_3DDKSHADOW));
+ TCHAR buff[64];
+ if (wd->show_grid)
+ {
+ mir_sntprintf(buff, SIZEOF(buff), TranslateT("%d ms"), MARK_TIME);
+ TextOut(hdc, r.right - 100, r.bottom - (int)(unit_height * MARK_TIME + 0.5f), buff, (int)mir_tstrlen(buff));
+ }
- if (wd->show_stat)
- {
- SetTextColor(hdc, RGB(255, 0, 0));
- mir_sntprintf(buff, SIZEOF(buff), TranslateT("AVG %.1lf ms"), avg);
- TextOut(hdc, r.left + 10, r.bottom - (int)(avg * unit_height + 0.5f), buff, (int)_tcslen(buff));
- if (max_value != avg) {
- mir_sntprintf(buff, SIZEOF(buff), TranslateT("MAX %hd ms"), max_value);
- TextOut(hdc, r.left + 10, r.bottom - (int)(max_value * unit_height + 0.5f), buff, (int)_tcslen(buff));
- mir_sntprintf(buff, SIZEOF(buff), TranslateT("MIN %hd ms"), min_value);
- TextOut(hdc, r.left + 10, r.bottom - (int)(min_value * unit_height + 0.5f), buff, (int)_tcslen(buff));
- }
+ if (wd->show_stat)
+ {
+ SetTextColor(hdc, RGB(255, 0, 0));
+ mir_sntprintf(buff, SIZEOF(buff), TranslateT("AVG %.1lf ms"), avg);
+ TextOut(hdc, r.left + 10, r.bottom - (int)(avg * unit_height + 0.5f), buff, (int)mir_tstrlen(buff));
+ if (max_value != avg) {
+ mir_sntprintf(buff, SIZEOF(buff), TranslateT("MAX %hd ms"), max_value);
+ TextOut(hdc, r.left + 10, r.bottom - (int)(max_value * unit_height + 0.5f), buff, (int)mir_tstrlen(buff));
+ mir_sntprintf(buff, SIZEOF(buff), TranslateT("MIN %hd ms"), min_value);
+ TextOut(hdc, r.left + 10, r.bottom - (int)(min_value * unit_height + 0.5f), buff, (int)mir_tstrlen(buff));
}
-
- EndPaint(hwnd, &ps);
}
+
+ EndPaint(hwnd, &ps);
}
- return TRUE;
+ }
+ return TRUE;
case WM_ERASEBKGND:
return TRUE;
case WM_SIZE:
- {
- WindowData *wd = (WindowData *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
- RECT r;
- GetClientRect(hwnd, &r);
- if(wd->hwnd_chk_grid != 0) SetWindowPos(wd->hwnd_chk_grid, 0, r.right - 150, r.top + 10, 120, 20, SWP_NOZORDER | SWP_NOACTIVATE);
- if(wd->hwnd_chk_stat != 0) SetWindowPos(wd->hwnd_chk_stat, 0, r.right - 150, r.top + 30, 120, 20, SWP_NOZORDER | SWP_NOACTIVATE);
- }
- InvalidateRect(hwnd, 0, FALSE);
- break;
+ {
+ WindowData *wd = (WindowData *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
+ RECT r;
+ GetClientRect(hwnd, &r);
+ if (wd->hwnd_chk_grid != 0) SetWindowPos(wd->hwnd_chk_grid, 0, r.right - 150, r.top + 10, 120, 20, SWP_NOZORDER | SWP_NOACTIVATE);
+ if (wd->hwnd_chk_stat != 0) SetWindowPos(wd->hwnd_chk_stat, 0, r.right - 150, r.top + 30, 120, 20, SWP_NOZORDER | SWP_NOACTIVATE);
+ }
+ InvalidateRect(hwnd, 0, FALSE);
+ break;
case WM_CLOSE:
+ {
+ KillTimer(hwnd, ID_REPAINT_TIMER);
+ WindowData *wd = (WindowData *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
{
- KillTimer(hwnd, ID_REPAINT_TIMER);
- WindowData *wd = (WindowData *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
- {
- char buff[30];
- mir_snprintf(buff, SIZEOF(buff), "pinggraphwnd%d", wd->item_id);
- Utils_SaveWindowPosition(hwnd, 0, PLUG, buff);
- }
+ char buff[30];
+ mir_snprintf(buff, SIZEOF(buff), "pinggraphwnd%d", wd->item_id);
+ Utils_SaveWindowPosition(hwnd, 0, PLUG, buff);
}
- break;
+ }
+ break;
case WM_DESTROY:
+ {
+ WindowData *wd = (WindowData *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
{
- WindowData *wd = (WindowData *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
- {
- char buff[30];
- mir_snprintf(buff, SIZEOF(buff), "WindowHandle%d", wd->item_id);
- db_set_dw(0, PLUG, buff, 0);
- }
- delete wd;
+ char buff[30];
+ mir_snprintf(buff, SIZEOF(buff), "WindowHandle%d", wd->item_id);
+ db_set_dw(0, PLUG, buff, 0);
}
- // drop through
+ delete wd;
+ }
+ // drop through
};
return DefWindowProc(hwnd, msg, wParam, lParam);
@@ -255,36 +256,36 @@ INT_PTR ShowGraph(WPARAM wParam, LPARAM lParam) { char buff[30];
mir_snprintf(buff, SIZEOF(buff), "WindowHandle%d", (DWORD)wParam);
HWND hGraphWnd = (HWND)db_get_dw(0, PLUG, buff, 0);
- if(hGraphWnd) {
+ if (hGraphWnd) {
ShowWindow(hGraphWnd, SW_SHOW);
SetWindowPos(hGraphWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
return 0;
}
WNDCLASS wndclass;
- wndclass.style = 0;
- wndclass.lpfnWndProc = GraphWindowProc;
- wndclass.cbClsExtra = 0;
- wndclass.cbWndExtra = 0;
- wndclass.hInstance = hInst;
- wndclass.hIcon = hIconResponding;
- wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
- wndclass.hbrBackground = (HBRUSH)(COLOR_3DFACE+1);
- wndclass.lpszMenuName = NULL;
+ wndclass.style = 0;
+ wndclass.lpfnWndProc = GraphWindowProc;
+ wndclass.cbClsExtra = 0;
+ wndclass.cbWndExtra = 0;
+ wndclass.hInstance = hInst;
+ wndclass.hIcon = hIconResponding;
+ wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
+ wndclass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
+ wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = _T(PLUG) _T("GraphWindow");
RegisterClass(&wndclass);
TCHAR title[256];
- _tcsncpy(title, TranslateT("Ping Graph"), SIZEOF(title));
- if(lParam) {
- _tcsncat(title, _T(" - "), SIZEOF(title));
- _tcsncat(title, (TCHAR *)lParam, SIZEOF(title));
+ mir_tstrncpy(title, TranslateT("Ping Graph"), SIZEOF(title));
+ if (lParam) {
+ mir_tstrncat(title, _T(" - "), SIZEOF(title) - mir_tstrlen(title));
+ mir_tstrncat(title, (TCHAR *)lParam, SIZEOF(title) - mir_tstrlen(title));
}
HWND parent = 0;
hGraphWnd = CreateWindowEx(0, _T(PLUG) _T("GraphWindow"), title,
- (WS_THICKFRAME | WS_CAPTION | WS_SYSMENU | WS_CLIPCHILDREN) & ~CS_VREDRAW & ~CS_HREDRAW,
- 0,0,800,600,parent,NULL,hInst,NULL);
+ (WS_THICKFRAME | WS_CAPTION | WS_SYSMENU | WS_CLIPCHILDREN) & ~CS_VREDRAW & ~CS_HREDRAW,
+ 0, 0, 800, 600, parent, NULL, hInst, NULL);
WindowData *wd = new WindowData;
wd->item_id = (DWORD)wParam; // wParam is destination id
@@ -295,12 +296,12 @@ INT_PTR ShowGraph(WPARAM wParam, LPARAM lParam) { db_set_dw(0, PLUG, buff, (DWORD)hGraphWnd);
- SetWindowLongPtr(hGraphWnd, GWLP_USERDATA, (LONG_PTR)wd);
+ SetWindowLongPtr(hGraphWnd, GWLP_USERDATA, (LONG_PTR)wd);
mir_snprintf(buff, SIZEOF(buff), "pinggraphwnd%d", wd->item_id);
Utils_RestoreWindowPosition(hGraphWnd, 0, PLUG, buff);
- if(!IsWindowVisible(hGraphWnd))
+ if (!IsWindowVisible(hGraphWnd))
ShowWindow(hGraphWnd, SW_SHOW);
return 0;
@@ -312,14 +313,14 @@ void graphs_cleanup() { char buff[64];
HWND hwnd;
- for(int i = 0; i < list_size; i++) {
+ for (int i = 0; i < list_size; i++) {
mir_snprintf(buff, SIZEOF(buff), "WindowHandle%d", i);
- if(hwnd = (HWND)db_get_dw(0, PLUG, buff, 0)) {
+ if (hwnd = (HWND)db_get_dw(0, PLUG, buff, 0)) {
DestroyWindow(hwnd);
db_set_dw(0, PLUG, buff, 0);
mir_snprintf(buff, SIZEOF(buff), "WindowWasOpen%d", i);
db_set_b(0, PLUG, buff, 1);
- }
+ }
}
}
@@ -328,11 +329,11 @@ void graphs_init() { PINGLIST pl;
char buff[64];
CallService(PLUG "/GetPingList", 0, (LPARAM)&pl);
- for(pinglist_it i = pl.begin(); i != pl.end(); ++i) {
+ for (pinglist_it i = pl.begin(); i != pl.end(); ++i) {
mir_snprintf(buff, SIZEOF(buff), "WindowHandle%d", i->item_id); // clean up from possible crash
db_set_dw(0, PLUG, buff, 0);
mir_snprintf(buff, SIZEOF(buff), "WindowWasOpen%d", i->item_id); // restore windows that were open on shutdown
- if(db_get_b(0, PLUG, buff, 0)) {
+ if (db_get_b(0, PLUG, buff, 0)) {
db_set_b(0, PLUG, buff, 0);
ShowGraph((WPARAM)i->item_id, (LPARAM)i->pszLabel);
}
diff --git a/plugins/Ping/src/pinglist.cpp b/plugins/Ping/src/pinglist.cpp index 4b4a19363d..e3a0e7b6bb 100644 --- a/plugins/Ping/src/pinglist.cpp +++ b/plugins/Ping/src/pinglist.cpp @@ -33,13 +33,13 @@ const bool PINGADDRESS::operator<(const PINGADDRESS &b) const // lParam is address of pointer to a std::list<PINGADDRESS>
// copies data into this structure
-INT_PTR GetPingList(WPARAM,LPARAM lParam)
+INT_PTR GetPingList(WPARAM, LPARAM lParam)
{
PINGLIST *pa = (PINGLIST *)lParam;
mir_cslock lck(list_cs);
*pa = list_items;
-
+
return 0;
}
@@ -57,7 +57,7 @@ void write_ping_address(PINGADDRESS &i) char buff[16];
mir_snprintf(buff, SIZEOF(buff), "PING_DEST_%d", i.index);
- if(i.item_id == 0) {
+ if (i.item_id == 0) {
i.item_id = NextID++;
db_set_dw(0, PLUG, "NextID", NextID);
}
@@ -68,11 +68,11 @@ void write_ping_address(PINGADDRESS &i) db_set_w(0, buff, "Status", i.status);
db_set_dw(0, buff, "Port", i.port);
db_set_s(0, buff, "Proto", i.pszProto);
- if(_tcslen(i.pszCommand))
+ if (mir_tstrlen(i.pszCommand))
db_set_ts(0, buff, "Command", i.pszCommand);
else
db_unset(0, buff, "Command");
- if(_tcslen(i.pszParams))
+ if (mir_tstrlen(i.pszParams))
db_set_ts(0, buff, "CommandParams", i.pszParams);
else
db_unset(0, buff, "CommandParams");
@@ -85,7 +85,7 @@ void write_ping_address(PINGADDRESS &i) void write_ping_addresses()
{
int index = 0;
- for(pinglist_it i = list_items.begin(); i != list_items.end(); ++i, index++)
+ for (pinglist_it i = list_items.begin(); i != list_items.end(); ++i, index++)
{
i->index = index;
write_ping_address(*i);
@@ -98,11 +98,11 @@ void write_ping_addresses() do {
found = false;
mir_snprintf(buff, SIZEOF(buff), "PING_DEST_%d", index++);
- if(db_get_dw(0, buff, "Id", 0) != 0) {
+ if (db_get_dw(0, buff, "Id", 0) != 0) {
found = true;
db_set_dw(0, buff, "Id", 0);
}
- } while(found);
+ } while (found);
}
bool read_ping_address(PINGADDRESS &pa) {
@@ -112,38 +112,43 @@ bool read_ping_address(PINGADDRESS &pa) { mir_snprintf(buff, SIZEOF(buff), "PING_DEST_%d", index);
// return if not more contacts, or only deleted contacts remaining
- if((pa.item_id = db_get_dw(0, buff, "Id", 0)) == 0) return false;
+ if ((pa.item_id = db_get_dw(0, buff, "Id", 0)) == 0) return false;
DBVARIANT dbv;
- if(!db_get_ts(0, buff, "Address", &dbv)) {
- _tcsncpy(pa.pszName, dbv.ptszVal, MAX_PINGADDRESS_STRING_LENGTH);
+ if (!db_get_ts(0, buff, "Address", &dbv)) {
+ mir_tstrncpy(pa.pszName, dbv.ptszVal, SIZEOF(pa.pszName));
db_free(&dbv);
- } else return false;
+ }
+ else return false;
- if(!db_get_ts(0, buff, "Label", &dbv)) {
- _tcsncpy(pa.pszLabel, dbv.ptszVal, MAX_PINGADDRESS_STRING_LENGTH);
+ if (!db_get_ts(0, buff, "Label", &dbv)) {
+ mir_tstrncpy(pa.pszLabel, dbv.ptszVal, SIZEOF(pa.pszLabel));
db_free(&dbv);
- } else return false;
+ }
+ else return false;
pa.status = db_get_w(0, buff, "Status", PS_NOTRESPONDING);
- if(pa.status != PS_DISABLED) pa.status = PS_NOTRESPONDING;
+ if (pa.status != PS_DISABLED) pa.status = PS_NOTRESPONDING;
pa.port = (int)db_get_dw(0, buff, "Port", -1);
- if(!db_get_s(0, buff, "Proto", &dbv)) {
- strncpy(pa.pszProto, dbv.pszVal, MAX_PINGADDRESS_STRING_LENGTH);
+ if (!db_get_s(0, buff, "Proto", &dbv)) {
+ mir_strncpy(pa.pszProto, dbv.pszVal, SIZEOF(pa.pszProto));
db_free(&dbv);
- } else pa.pszProto[0] = '\0';
+ }
+ else pa.pszProto[0] = '\0';
- if(!db_get_ts(0, buff, "Command", &dbv)) {
- _tcsncpy(pa.pszCommand, dbv.ptszVal, MAX_PATH);
+ if (!db_get_ts(0, buff, "Command", &dbv)) {
+ mir_tstrncpy(pa.pszCommand, dbv.ptszVal, SIZEOF(pa.pszCommand));
db_free(&dbv);
- } else
+ }
+ else
pa.pszCommand[0] = '\0';
- if(!db_get_ts(0, buff, "CommandParams", &dbv)) {
- _tcsncpy(pa.pszParams, dbv.ptszVal, MAX_PATH);
+ if (!db_get_ts(0, buff, "CommandParams", &dbv)) {
+ mir_tstrncpy(pa.pszParams, dbv.ptszVal, SIZEOF(pa.pszParams));
db_free(&dbv);
- } else
+ }
+ else
pa.pszParams[0] = '\0';
pa.set_status = db_get_w(0, buff, "SetStatus", ID_STATUS_ONLINE);
@@ -155,7 +160,7 @@ bool read_ping_address(PINGADDRESS &pa) { pa.index = db_get_w(0, buff, "Index", 0);
pa.index = index;
- if(pa.item_id >= NextID) {
+ if (pa.item_id >= NextID) {
NextID = pa.item_id + 1;
db_set_dw(0, PLUG, "NextID", NextID);
}
diff --git a/plugins/Ping/src/pinglist.h b/plugins/Ping/src/pinglist.h index 4766c8e115..b01dcd4a17 100644 --- a/plugins/Ping/src/pinglist.h +++ b/plugins/Ping/src/pinglist.h @@ -2,7 +2,7 @@ #define _PINGLIST_H
INT_PTR LoadPingList(WPARAM wParam, LPARAM lParam);
-INT_PTR GetPingList(WPARAM wParam,LPARAM lParam);
+INT_PTR GetPingList(WPARAM wParam, LPARAM lParam);
INT_PTR SavePingList(WPARAM wParam, LPARAM lParam);
INT_PTR SetPingList(WPARAM wParam, LPARAM lParam); // use when you modified db yourself
INT_PTR SetAndSavePingList(WPARAM wParam, LPARAM lParam);
diff --git a/plugins/Ping/src/pingthread.cpp b/plugins/Ping/src/pingthread.cpp index 7c834c572a..050c81f587 100644 --- a/plugins/Ping/src/pingthread.cpp +++ b/plugins/Ping/src/pingthread.cpp @@ -52,7 +52,7 @@ void set_list_changed(bool f) { }
void SetProtoStatus(TCHAR *pszLabel, char *pszProto, int if_status, int new_status) {
- if (strcmp(pszProto, Translate("<all>")) == 0) {
+ if (mir_strcmp(pszProto, Translate("<all>")) == 0) {
int num_protocols;
PROTOACCOUNT **pppDesc;
@@ -115,9 +115,9 @@ void __cdecl sttCheckStatusThreadProc(void *vp) pa.item_id = i->item_id;
pa.miss_count = i->miss_count;
pa.port = i->port;
- _tcsncpy(pa.pszLabel, i->pszLabel, MAX_PINGADDRESS_STRING_LENGTH);
- _tcsncpy(pa.pszName, i->pszName, MAX_PINGADDRESS_STRING_LENGTH);
- strncpy(pa.pszProto, i->pszProto, MAX_PINGADDRESS_STRING_LENGTH);
+ mir_tstrncpy(pa.pszLabel, i->pszLabel, SIZEOF(pa.pszLabel));
+ mir_tstrncpy(pa.pszName, i->pszName, SIZEOF(pa.pszName));
+ mir_strncpy(pa.pszProto, i->pszProto, SIZEOF(pa.pszProto));
pa.set_status = i->set_status;
pa.status = i->status;
break;
@@ -1009,27 +1009,27 @@ void InitList() {
font_id.cbSize = sizeof(FontIDT);
- _tcsncpy(font_id.group, LPGENT("Ping"), SIZEOF(font_id.group));
- _tcsncpy(font_id.name, LPGENT("List"), SIZEOF(font_id.name));
- strncpy(font_id.dbSettingsGroup, "PING", sizeof(font_id.dbSettingsGroup));
- strncpy(font_id.prefix, "Font", sizeof(font_id.prefix));
- _tcsncpy(font_id.backgroundGroup, _T("Ping"), SIZEOF(font_id.backgroundGroup));
- _tcsncpy(font_id.backgroundName, _T("Background"), SIZEOF(font_id.backgroundName));
+ mir_tstrncpy(font_id.group, LPGENT("Ping"), SIZEOF(font_id.group));
+ mir_tstrncpy(font_id.name, LPGENT("List"), SIZEOF(font_id.name));
+ mir_strncpy(font_id.dbSettingsGroup, "PING", SIZEOF(font_id.dbSettingsGroup));
+ mir_strncpy(font_id.prefix, "Font", SIZEOF(font_id.prefix));
+ mir_tstrncpy(font_id.backgroundGroup, _T("Ping"), SIZEOF(font_id.backgroundGroup));
+ mir_tstrncpy(font_id.backgroundName, _T("Background"), SIZEOF(font_id.backgroundName));
font_id.order = 0;
font_id.flags = FIDF_DEFAULTVALID;
font_id.deffontsettings.charset = DEFAULT_CHARSET;
font_id.deffontsettings.size = -14;
font_id.deffontsettings.style = 0;
font_id.deffontsettings.colour = RGB(255, 255, 255);
- _tcsncpy(font_id.deffontsettings.szFace, _T("Tahoma"), SIZEOF(font_id.deffontsettings.szFace));
+ mir_tstrncpy(font_id.deffontsettings.szFace, _T("Tahoma"), SIZEOF(font_id.deffontsettings.szFace));
FontRegisterT(&font_id);
bk_col_id.cbSize = sizeof(ColourIDT);
- _tcsncpy(bk_col_id.group, _T("Ping"), SIZEOF(bk_col_id.group));
- _tcsncpy(bk_col_id.name, _T("Background"), SIZEOF(bk_col_id.name));
- strncpy(bk_col_id.dbSettingsGroup, "PING", sizeof(bk_col_id.dbSettingsGroup));
- strncpy(bk_col_id.setting, "BgColor", sizeof(bk_col_id.setting));
+ mir_tstrncpy(bk_col_id.group, _T("Ping"), SIZEOF(bk_col_id.group));
+ mir_tstrncpy(bk_col_id.name, _T("Background"), SIZEOF(bk_col_id.name));
+ mir_strncpy(bk_col_id.dbSettingsGroup, "PING", SIZEOF(bk_col_id.dbSettingsGroup));
+ mir_strncpy(bk_col_id.setting, "BgColor", SIZEOF(bk_col_id.setting));
bk_col_id.defcolour = RGB(0, 0, 0);
ColourRegisterT(&bk_col_id);
diff --git a/plugins/Ping/src/rawping.cpp b/plugins/Ping/src/rawping.cpp index f31868db5a..98cdace9bd 100644 --- a/plugins/Ping/src/rawping.cpp +++ b/plugins/Ping/src/rawping.cpp @@ -35,7 +35,7 @@ extern int init_raw_ping() return 1;
}
- if(sd != -1)
+ if (sd != -1)
closesocket(sd);
// Create the socket
@@ -51,7 +51,7 @@ extern int init_raw_ping() }
int our_recv_timeout = 100; // so we ca do multiple recv calls
- if(setsockopt(sd, SOL_SOCKET, SO_RCVTIMEO, (const char *)&our_recv_timeout, sizeof(int)) == SOCKET_ERROR) {
+ if (setsockopt(sd, SOL_SOCKET, SO_RCVTIMEO, (const char *)&our_recv_timeout, sizeof(int)) == SOCKET_ERROR) {
return 4;
}
@@ -61,7 +61,7 @@ extern int init_raw_ping() header->id = (USHORT)GetCurrentProcessId();
inited = true;
- if(raw_ping("127.0.0.1", 500) >= 0) {
+ if (raw_ping("127.0.0.1", 500) >= 0) {
return 0;
}
@@ -71,7 +71,7 @@ extern int init_raw_ping() extern int raw_ping(char *host, int timeout)
{
- if(!inited) return -1;
+ if (!inited) return -1;
// Initialize the destination host info block
sockaddr_in dest;
@@ -95,7 +95,7 @@ extern int raw_ping(char *host, int timeout) }
else {
// Not a recognized hostname either!
- if(options.logging) CallService(PLUG "/Log", (WPARAM)_T("rawping error: unrecognised host"), 0);
+ if (options.logging) CallService(PLUG "/Log", (WPARAM)_T("rawping error: unrecognised host"), 0);
return -1;
}
}
@@ -108,16 +108,17 @@ extern int raw_ping(char *host, int timeout) bool use_hi_res = false;
LARGE_INTEGER hr_freq, hr_send_time;
DWORD send_time;
- if(QueryPerformanceFrequency(&hr_freq)) {
+ if (QueryPerformanceFrequency(&hr_freq)) {
use_hi_res = true;
QueryPerformanceCounter(&hr_send_time);
- } else
+ }
+ else
send_time = GetTickCount();
// send packet
int bwrote = sendto(sd, (char*)packet, sizeof(ICMPHeader), 0, (sockaddr*)&dest, sizeof(dest));
if (bwrote == SOCKET_ERROR) {
- if(options.logging) CallService(PLUG "/Log", (WPARAM)_T("rawping error: unable to send"), 0);
+ if (options.logging) CallService(PLUG "/Log", (WPARAM)_T("rawping error: unable to send"), 0);
return -1;
}
@@ -128,86 +129,88 @@ extern int raw_ping(char *host, int timeout) ICMPHeader *reply;
DWORD start, current_time;
LARGE_INTEGER hr_start, hr_current_time, hr_timeout;
- if(use_hi_res) {
+ if (use_hi_res) {
hr_timeout.QuadPart = (timeout * hr_freq.QuadPart / 1000);
QueryPerformanceCounter(&hr_start);
hr_current_time = hr_start;
- } else {
+ }
+ else {
start = GetTickCount();
current_time = start;
}
- while(((use_hi_res && (hr_current_time.QuadPart < hr_start.QuadPart + hr_timeout.QuadPart))
- || (!use_hi_res && current_time < start + timeout)))
+ while (((use_hi_res && (hr_current_time.QuadPart < hr_start.QuadPart + hr_timeout.QuadPart))
+ || (!use_hi_res && current_time < start + timeout)))
{
int bread = recvfrom(sd, recv_buff, 1024, 0, (sockaddr*)&source, &fromlen);
- if(use_hi_res)
+ if (use_hi_res)
QueryPerformanceCounter(&hr_current_time);
else
current_time = GetTickCount();
if (bread == SOCKET_ERROR) {
- if(WSAGetLastError() != WSAETIMEDOUT) {
- if(options.logging)
+ if (WSAGetLastError() != WSAETIMEDOUT) {
+ if (options.logging)
CallService(PLUG "/Log", (WPARAM)_T("rawping error: socket error...cycling"), 0);
}
continue;
}
- if(reply_header->proto != ICMP_PROTO) {
- if(options.logging)
+ if (reply_header->proto != ICMP_PROTO) {
+ if (options.logging)
CallService(PLUG "/Log", (WPARAM)_T("rawping error: packet not ICMP...cycling"), 0);
continue;
}
- if(reply_header->tos != 0) {
- if(options.logging)
+ if (reply_header->tos != 0) {
+ if (options.logging)
CallService(PLUG "/Log", (WPARAM)_T("rawping error: TOS not 0...cycling"), 0);
continue;
}
- reply = (ICMPHeader *)(recv_buff + reply_header->h_len * 4);
- if((unsigned)bread < reply_header->h_len * 4 + sizeof(ICMPHeader)) {
- if(options.logging)
+ reply = (ICMPHeader *)(recv_buff + reply_header->h_len * 4);
+ if ((unsigned)bread < reply_header->h_len * 4 + sizeof(ICMPHeader)) {
+ if (options.logging)
CallService(PLUG "/Log", (WPARAM)_T("rawping error: short header"), 0);
continue;
}
- if(reply->id != (USHORT)GetCurrentProcessId()) {
- if(options.logging)
+ if (reply->id != (USHORT)GetCurrentProcessId()) {
+ if (options.logging)
CallService(PLUG "/Log", (WPARAM)_T("rawping error: wrong ID...cycling"), 0);
continue;
}
- if(reply->type != PT_ICMP_ECHO_REPLY && reply->type != PT_ICMP_SOURCE_QUENCH) {
- if(options.logging)
+ if (reply->type != PT_ICMP_ECHO_REPLY && reply->type != PT_ICMP_SOURCE_QUENCH) {
+ if (options.logging)
CallService(PLUG "/Log", (WPARAM)_T("rawping error: wrong type...cycling"), 0);
continue;
}
//if(reply->seq < seq_no) continue;
//if(reply->seq > seq_no) return -1;
- if(reply->seq != seq_no) {
- if(options.logging)
+ if (reply->seq != seq_no) {
+ if (options.logging)
CallService(PLUG "/Log", (WPARAM)_T("rawping error: wrong sequence number...cycling"), 0);
continue;
}
- if(reply->type == PT_ICMP_SOURCE_QUENCH) {
+ if (reply->type == PT_ICMP_SOURCE_QUENCH) {
char buff[1024];
mir_snprintf(buff, SIZEOF(buff), Translate("Host %s requests that you reduce the amount of traffic you are sending."), host);
MessageBoxA(0, buff, Translate(PLUG " Warning"), MB_OK | MB_ICONWARNING);
}
- if(use_hi_res) {
+ if (use_hi_res) {
LARGE_INTEGER ticks;
ticks.QuadPart = hr_current_time.QuadPart - hr_send_time.QuadPart;
- return (int)(ticks.QuadPart * 1000 / hr_freq.QuadPart);
- } else
+ return (int)(ticks.QuadPart * 1000 / hr_freq.QuadPart);
+ }
+ else
return current_time - send_time;
}
- if(options.logging)
+ if (options.logging)
CallService(PLUG "/Log", (WPARAM)_T("rawping error: timeout"), 0);
return -1;
@@ -215,7 +218,7 @@ extern int raw_ping(char *host, int timeout) extern int cleanup_raw_ping()
{
- if(inited) {
+ if (inited) {
closesocket(sd);
sd = -1;
WSACleanup();
diff --git a/plugins/Ping/src/rawping.h b/plugins/Ping/src/rawping.h index f5d9f877f5..59751d8c7a 100644 --- a/plugins/Ping/src/rawping.h +++ b/plugins/Ping/src/rawping.h @@ -20,26 +20,26 @@ // The IP header
struct IPHeader {
- BYTE h_len:4; // Length of the header in dwords
- BYTE version:4; // Version of IP
- BYTE tos; // Type of service
- USHORT total_len; // Length of the packet in dwords
- USHORT ident; // unique identifier
- USHORT flags; // Flags
- BYTE ttl; // Time to live
- BYTE proto; // Protocol number (TCP, UDP etc)
- USHORT checksum; // IP checksum
- ULONG source_ip;
- ULONG dest_ip;
+ BYTE h_len : 4; // Length of the header in dwords
+ BYTE version : 4; // Version of IP
+ BYTE tos; // Type of service
+ USHORT total_len; // Length of the packet in dwords
+ USHORT ident; // unique identifier
+ USHORT flags; // Flags
+ BYTE ttl; // Time to live
+ BYTE proto; // Protocol number (TCP, UDP etc)
+ USHORT checksum; // IP checksum
+ ULONG source_ip;
+ ULONG dest_ip;
};
// ICMP header
struct ICMPHeader {
- BYTE type; // ICMP packet type
- BYTE code; // Type sub code
- USHORT checksum;
- USHORT id;
- USHORT seq;
+ BYTE type; // ICMP packet type
+ BYTE code; // Type sub code
+ USHORT checksum;
+ USHORT id;
+ USHORT seq;
};
#pragma pack()
diff --git a/plugins/Ping/src/utils.cpp b/plugins/Ping/src/utils.cpp index 8e57dde2ff..84d86718b7 100644 --- a/plugins/Ping/src/utils.cpp +++ b/plugins/Ping/src/utils.cpp @@ -1,56 +1,57 @@ #include "common.h"
-LRESULT CALLBACK NullWindowProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
+LRESULT CALLBACK NullWindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
- switch( message ) {
- case WM_COMMAND: {
- PUDeletePopup( hWnd );
- break;
- }
+ switch (message) {
+ case WM_COMMAND: {
+ PUDeletePopup(hWnd);
+ break;
+ }
- case WM_CONTEXTMENU:
- PUDeletePopup( hWnd );
- break;
+ case WM_CONTEXTMENU:
+ PUDeletePopup(hWnd);
+ break;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
-void CALLBACK sttMainThreadCallback( ULONG_PTR dwParam )
+void CALLBACK sttMainThreadCallback(ULONG_PTR dwParam)
{
- POPUPDATAT* ppd = ( POPUPDATAT* )dwParam;
+ POPUPDATAT* ppd = (POPUPDATAT*)dwParam;
- if ( ServiceExists(MS_POPUP_ADDPOPUPT))
+ if (ServiceExists(MS_POPUP_ADDPOPUPT))
PUAddPopupT(ppd);
- free( ppd );
+ free(ppd);
}
-void __stdcall ShowPopup(TCHAR *line1,TCHAR *line2, int flags )
+void __stdcall ShowPopup(TCHAR *line1, TCHAR *line2, int flags)
{
- if(CallService(MS_SYSTEM_TERMINATED, 0, 0)) return;
+ if (CallService(MS_SYSTEM_TERMINATED, 0, 0)) return;
- if(ServiceExists(MS_POPUP_ADDPOPUPCLASS)) {
- ShowClassPopupT("pingpopups",line1,line2);
- } else if ( ServiceExists(MS_POPUP_ADDPOPUPT)) {
- POPUPDATAT *ppd = ( POPUPDATAT* )calloc( sizeof( POPUPDATAT ), 1 );
+ if (ServiceExists(MS_POPUP_ADDPOPUPCLASS)) {
+ ShowClassPopupT("pingpopups", line1, line2);
+ }
+ else if (ServiceExists(MS_POPUP_ADDPOPUPT)) {
+ POPUPDATAT *ppd = (POPUPDATAT*)calloc(sizeof(POPUPDATAT), 1);
ppd->lchContact = NULL;
ppd->lchIcon = (flags ? hIconResponding : hIconNotResponding);
- _tcsncpy( ppd->lptzContactName, line1, MAX_CONTACTNAME);
- _tcsncpy( ppd->lptzText, line2, MAX_SECONDLINE);
+ mir_tstrncpy(ppd->lptzContactName, line1, SIZEOF(ppd->lptzContactName));
+ mir_tstrncpy(ppd->lptzText, line2, SIZEOF(ppd->lptzText));
- ppd->colorBack = GetSysColor( COLOR_BTNFACE );
- ppd->colorText = GetSysColor( COLOR_WINDOWTEXT );
+ ppd->colorBack = GetSysColor(COLOR_BTNFACE);
+ ppd->colorText = GetSysColor(COLOR_WINDOWTEXT);
ppd->iSeconds = 10;
ppd->PluginWindowProc = NullWindowProc;
ppd->PluginData = NULL;
- QueueUserAPC(sttMainThreadCallback, mainThread, ( ULONG_PTR)ppd );
+ QueueUserAPC(sttMainThreadCallback, mainThread, (ULONG_PTR)ppd);
}
else{
- MessageBox( NULL, line2, _T(PLUG) _T(" Message"), MB_OK | MB_ICONINFORMATION );
+ MessageBox(NULL, line2, _T(PLUG) _T(" Message"), MB_OK | MB_ICONINFORMATION);
return;
}
}
@@ -60,31 +61,33 @@ void __stdcall ShowPopup(TCHAR *line1,TCHAR *line2, int flags ) // wParam is zero
// lParam is address of PINGADDRESS structure where ping result is placed (i.e. modifies 'responding'
// and 'round_trip_time')
-INT_PTR PluginPing(WPARAM,LPARAM lParam)
+INT_PTR PluginPing(WPARAM, LPARAM lParam)
{
PINGADDRESS *pa = (PINGADDRESS *)lParam;
- if(pa->port == -1) {
+ if (pa->port == -1) {
// ICMP echo
- if(use_raw_ping) {
+ if (use_raw_ping) {
pa->round_trip_time = raw_ping(_T2A(pa->pszName), options.ping_timeout * 1000);
pa->responding = (pa->round_trip_time != -1);
- } else {
-
+ }
+ else {
+
ICMP_ECHO_REPLY result;
pa->responding = ICMP::get_instance()->ping(_T2A(pa->pszName), result);
- if(pa->responding)
+ if (pa->responding)
pa->round_trip_time = (short)result.RoundTripTime;
else
pa->round_trip_time = -1;
}
- } else if(hNetlibUser) {
+ }
+ else if (hNetlibUser) {
// TCP connect
clock_t start_tcp = clock();
-
+
//GetLocalTime(&systime);
- NETLIBOPENCONNECTION conn = {0};
+ NETLIBOPENCONNECTION conn = { 0 };
conn.cbSize = sizeof(NETLIBOPENCONNECTION);
conn.szHost = mir_t2a(pa->pszName);
conn.wPort = pa->port;
@@ -94,8 +97,8 @@ INT_PTR PluginPing(WPARAM,LPARAM lParam) mir_free((void*)conn.szHost);
clock_t end_tcp = clock();
-
- if(s) {
+
+ if (s) {
LINGER l;
char buf[1024];
SOCKET socket = (SOCKET)CallService(MS_NETLIB_GETSOCKET, (WPARAM)s, (LPARAM)NLOCF_HTTP);
@@ -110,9 +113,9 @@ INT_PTR PluginPing(WPARAM,LPARAM lParam) unsigned long bytes_remaining;
ioctlsocket(socket, FIONBIO, &bytes_remaining);
- if(bytes_remaining > 0) {
+ if (bytes_remaining > 0) {
int retval, rx = 0;
- while((retval = Netlib_Recv(s, buf, 1024, 0)) != SOCKET_ERROR && (retval > 0) && rx < 2048) {
+ while ((retval = Netlib_Recv(s, buf, 1024, 0)) != SOCKET_ERROR && (retval > 0) && rx < 2048) {
rx += retval; // recv at most 2kb before closing connection
}
}
@@ -121,7 +124,8 @@ INT_PTR PluginPing(WPARAM,LPARAM lParam) pa->round_trip_time = (int)(((end_tcp - start_tcp) / (double)CLOCKS_PER_SEC) * 1000);
Netlib_CloseHandle(s);
- } else {
+ }
+ else {
pa->responding = false;
pa->round_trip_time = -1;
}
@@ -133,7 +137,7 @@ INT_PTR PluginPing(WPARAM,LPARAM lParam) INT_PTR PingDisableAll(WPARAM wParam, LPARAM lParam) {
PINGLIST pl;
CallService(PLUG "/GetPingList", 0, (LPARAM)&pl);
- for(pinglist_it i = pl.begin(); i != pl.end(); ++i) {
+ for (pinglist_it i = pl.begin(); i != pl.end(); ++i) {
i->status = PS_DISABLED;
i->miss_count = 0;
}
@@ -144,8 +148,8 @@ INT_PTR PingDisableAll(WPARAM wParam, LPARAM lParam) { INT_PTR PingEnableAll(WPARAM wParam, LPARAM lParam) {
PINGLIST pl;
CallService(PLUG "/GetPingList", 0, (LPARAM)&pl);
- for(pinglist_it i = pl.begin(); i != pl.end(); ++i) {
- if(i->status == PS_DISABLED) {
+ for (pinglist_it i = pl.begin(); i != pl.end(); ++i) {
+ if (i->status == PS_DISABLED) {
i->status = PS_NOTRESPONDING;
}
}
@@ -158,10 +162,10 @@ INT_PTR ToggleEnabled(WPARAM wParam, LPARAM lParam) { int retval = 0;
PINGLIST pl;
CallService(PLUG "/GetPingList", 0, (LPARAM)&pl);
- for(pinglist_it i = pl.begin(); i != pl.end(); ++i) {
- if(i->item_id == (DWORD)wParam) {
+ for (pinglist_it i = pl.begin(); i != pl.end(); ++i) {
+ if (i->item_id == (DWORD)wParam) {
- if(i->status == PS_DISABLED)
+ if (i->status == PS_DISABLED)
i->status = PS_NOTRESPONDING;
else {
i->status = PS_DISABLED;
@@ -179,13 +183,13 @@ INT_PTR EditContact(WPARAM wParam, LPARAM lParam) { HWND hwndList = (HWND)CallService(MS_CLUI_GETHWND, 0, 0);
CallService(PLUG "/GetPingList", 0, (LPARAM)&pl);
- for(pinglist_it i = pl.begin(); i != pl.end(); ++i) {
- if(i->item_id == (DWORD)wParam) {
+ for (pinglist_it i = pl.begin(); i != pl.end(); ++i) {
+ if (i->item_id == (DWORD)wParam) {
add_edit_addr = *i;
-
- if(DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG3), hwndList, DlgProcDestEdit) == IDOK) {
-
+
+ if (DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG3), hwndList, DlgProcDestEdit) == IDOK) {
+
*i = add_edit_addr;
CallService(PLUG "/SetAndSavePingList", (WPARAM)&pl, 0);
return 0;
@@ -198,11 +202,12 @@ INT_PTR EditContact(WPARAM wParam, LPARAM lParam) { INT_PTR DblClick(WPARAM wParam, LPARAM lParam) {
PINGLIST pl;
CallService(PLUG "/GetPingList", 0, (LPARAM)&pl);
- for(pinglist_it i = pl.begin(); i != pl.end(); ++i) {
- if(i->item_id == (DWORD)wParam) {
- if(_tcslen(i->pszCommand)) {
+ for (pinglist_it i = pl.begin(); i != pl.end(); ++i) {
+ if (i->item_id == (DWORD)wParam) {
+ if (mir_tstrlen(i->pszCommand)) {
ShellExecute(0, _T("open"), i->pszCommand, i->pszParams, 0, SW_SHOW);
- } else {
+ }
+ else {
return CallService(PLUG "/ToggleEnabled", wParam, 0);
}
}
@@ -215,31 +220,34 @@ void import_ping_address(int index, PINGADDRESS &pa) { DBVARIANT dbv;
char buf[256];
mir_snprintf(buf, SIZEOF(buf), "Address%d", index);
- if(!db_get_ts(0, "PingPlug", buf, &dbv)) {
- _tcsncpy(pa.pszName, dbv.ptszVal, MAX_PINGADDRESS_STRING_LENGTH);
+ if (!db_get_ts(0, "PingPlug", buf, &dbv)) {
+ mir_tstrncpy(pa.pszName, dbv.ptszVal, SIZEOF(pa.pszName));
db_free(&dbv);
- } else
- _tcsncpy(pa.pszName, TranslateT("Unknown Address"), MAX_PINGADDRESS_STRING_LENGTH);
+ }
+ else
+ mir_tstrncpy(pa.pszName, TranslateT("Unknown Address"), SIZEOF(pa.pszName));
mir_snprintf(buf, SIZEOF(buf), "Label%d", index);
- if(!db_get_ts(0, "PingPlug", buf, &dbv)) {
- _tcsncpy(pa.pszLabel, dbv.ptszVal, MAX_PINGADDRESS_STRING_LENGTH);
+ if (!db_get_ts(0, "PingPlug", buf, &dbv)) {
+ mir_tstrncpy(pa.pszLabel, dbv.ptszVal, SIZEOF(pa.pszLabel));
db_free(&dbv);
- } else
- _tcsncpy(pa.pszLabel, TranslateT("Unknown"), MAX_PINGADDRESS_STRING_LENGTH);
+ }
+ else
+ mir_tstrncpy(pa.pszLabel, TranslateT("Unknown"), SIZEOF(pa.pszLabel));
mir_snprintf(buf, SIZEOF(buf), "Port%d", index);
pa.port = (int)db_get_dw(0, "PingPlug", buf, -1);
mir_snprintf(buf, SIZEOF(buf), "Proto%d", index);
- if(!db_get_s(0, "PingPlug", buf, &dbv)) {
- strncpy(pa.pszProto, dbv.pszVal, MAX_PINGADDRESS_STRING_LENGTH);
+ if (!db_get_s(0, "PingPlug", buf, &dbv)) {
+ mir_strncpy(pa.pszProto, dbv.pszVal, SIZEOF(pa.pszProto));
db_free(&dbv);
mir_snprintf(buf, SIZEOF(buf), "Status%d", index);
pa.set_status = db_get_w(0, "PingPlug", buf, ID_STATUS_ONLINE);
mir_snprintf(buf, SIZEOF(buf), "Status2%d", index);
pa.get_status = db_get_w(0, "PingPlug", buf, ID_STATUS_OFFLINE);
- } else
+ }
+ else
pa.pszProto[0] = '\0';
@@ -252,7 +260,7 @@ void import_ping_address(int index, PINGADDRESS &pa) { pa.item_id = 0;
mir_snprintf(buf, SIZEOF(buf), "Enabled%d", index);
- if(db_get_b(0, "PingPlug", buf, 1) == 1)
+ if (db_get_b(0, "PingPlug", buf, 1) == 1)
pa.status = PS_NOTRESPONDING;
else
pa.status = PS_DISABLED;
@@ -266,7 +274,7 @@ void import_ping_addresses() mir_cslock lck(list_cs);
list_items.clear();
- for(int index = 0; index < count; index++)
+ for (int index = 0; index < count; index++)
{
import_ping_address(index, pa);
list_items.push_back(pa);
diff --git a/plugins/Ping/src/utils.h b/plugins/Ping/src/utils.h index d2c134026f..f3be0598b6 100644 --- a/plugins/Ping/src/utils.h +++ b/plugins/Ping/src/utils.h @@ -1,9 +1,9 @@ #ifndef _PING_UTILS
#define _PING_UTILS
-void __stdcall ShowPopup(TCHAR *line1, TCHAR *line2, int flags );
+void __stdcall ShowPopup(TCHAR *line1, TCHAR *line2, int flags);
-INT_PTR PluginPing(WPARAM wParam,LPARAM lParam);
+INT_PTR PluginPing(WPARAM wParam, LPARAM lParam);
INT_PTR PingDisableAll(WPARAM wParam, LPARAM lParam);
INT_PTR PingEnableAll(WPARAM wParam, LPARAM lParam);
|