summaryrefslogtreecommitdiff
path: root/plugins/Variables/src/parse_inet.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2013-09-13 19:26:02 +0000
committerGeorge Hazan <george.hazan@gmail.com>2013-09-13 19:26:02 +0000
commiteacc63d1fe3c0a5f6b982575867258650f98119b (patch)
treeafe39a5e1764c13293cfd3e8a403a181ea8c3e1f /plugins/Variables/src/parse_inet.cpp
parent8aebeeca820d48c4a126bc7670b4a558d73ed881 (diff)
code cleaning
git-svn-id: http://svn.miranda-ng.org/main/trunk@6056 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Variables/src/parse_inet.cpp')
-rw-r--r--plugins/Variables/src/parse_inet.cpp77
1 files changed, 26 insertions, 51 deletions
diff --git a/plugins/Variables/src/parse_inet.cpp b/plugins/Variables/src/parse_inet.cpp
index 856af28d14..dfa92ba7f1 100644
--- a/plugins/Variables/src/parse_inet.cpp
+++ b/plugins/Variables/src/parse_inet.cpp
@@ -19,18 +19,15 @@
#include "variables.h"
-static TCHAR *parseUrlEnc(ARGUMENTSINFO *ai) {
- char hex[8];
-
- if (ai->argc != 2) {
+static TCHAR *parseUrlEnc(ARGUMENTSINFO *ai)
+{
+ if (ai->argc != 2)
return NULL;
- }
char *res = mir_t2a(ai->targv[1]);
-
- if (res == NULL) {
+ if (res == NULL)
return NULL;
- }
+
size_t cur = 0;
while (cur < strlen(res)) {
if (( (*(res+cur) >= '0') && (*(res+cur) <= '9')) || ( (*(res+cur) >= 'a') && (*(res+cur) <= 'z')) || ( (*(res+cur) >= 'A') && (*(res+cur) <= 'Z')) ) {
@@ -41,6 +38,7 @@ static TCHAR *parseUrlEnc(ARGUMENTSINFO *ai) {
if (res == NULL)
return NULL;
+ char hex[8];
MoveMemory(res+cur+3, res+cur+1, strlen(res+cur+1)+1);
mir_snprintf(hex, sizeof(hex), "%%%x", *(res+cur));
strncpy(res+cur, hex, strlen(hex));
@@ -48,27 +46,23 @@ static TCHAR *parseUrlEnc(ARGUMENTSINFO *ai) {
}
TCHAR *tres = mir_a2t(res);
-
mir_free(res);
-
return tres;
}
-static TCHAR *parseUrlDec(ARGUMENTSINFO *ai) {
- char hex[8];
-
- if (ai->argc != 2) {
+static TCHAR *parseUrlDec(ARGUMENTSINFO *ai)
+{
+ if (ai->argc != 2)
return NULL;
- }
char *res = mir_t2a(ai->targv[1]);
-
- if (res == NULL) {
+ if (res == NULL)
return NULL;
- }
+
unsigned int cur = 0;
while (cur < strlen(res)) {
if ((*(res+cur) == '%') && (strlen(res+cur) >= 3)) {
+ char hex[8];
memset(hex, '\0', sizeof(hex));
strncpy(hex, res+cur+1, 2);
*(res+cur) = (char)strtol(hex, NULL, 16);
@@ -76,57 +70,38 @@ static TCHAR *parseUrlDec(ARGUMENTSINFO *ai) {
}
cur++;
}
- res = ( char* )mir_realloc(res, strlen(res)+1);
+ res = ( char* )mir_realloc(res, strlen(res)+1);
TCHAR *tres = mir_a2t(res);
-
mir_free(res);
-
return tres;
}
-static TCHAR *parseNToA(ARGUMENTSINFO *ai) {
- struct in_addr in;
-
- if (ai->argc != 2) {
+static TCHAR *parseNToA(ARGUMENTSINFO *ai)
+{
+ if (ai->argc != 2)
return NULL;
- }
+ struct in_addr in;
in.s_addr = ttoi(ai->targv[1]);
- char *res = inet_ntoa(in);
- if (res != NULL) {
-
- return mir_a2t(res);
-
- }
-
- return NULL;
+ return mir_a2t( inet_ntoa(in));
}
-static TCHAR *parseHToA(ARGUMENTSINFO *ai) {
- struct in_addr in;
-
- if (ai->argc != 2) {
+static TCHAR *parseHToA(ARGUMENTSINFO *ai)
+{
+ if (ai->argc != 2)
return NULL;
- }
+ struct in_addr in;
in.s_addr = htonl(ttoi(ai->targv[1]));
- char *res = inet_ntoa(in);
- if (res != NULL) {
-
- return mir_a2t(res);
-
- }
-
- return NULL;
+ return mir_a2t( inet_ntoa(in));
}
-int registerInetTokens() {
-
+int registerInetTokens()
+{
registerIntToken(_T(URLENC), parseUrlEnc, TRF_FUNCTION, LPGEN("Internet Related")"\t(x)\t"LPGEN("converts each non-html character into hex format"));
registerIntToken(_T(URLDEC), parseUrlDec, TRF_FUNCTION, LPGEN("Internet Related")"\t(x)\t"LPGEN("converts each hex value into non-html character"));
registerIntToken(_T(NTOA), parseNToA, TRF_FUNCTION, LPGEN("Internet Related")"\t(x)\t"LPGEN("converts a 32-bit number to IPv4 dotted notation"));
registerIntToken(_T(HTOA), parseHToA, TRF_FUNCTION, LPGEN("Internet Related")"\t(x)\t"LPGEN("converts a 32-bit number (in host byte order) to IPv4 dotted notation"));
-
- return 0;
+ return 0;
}