Browse code

detailed_ipv6_type mock working function created

Lucian Balaceanu authored on 22/08/2016 10:46:05
Showing 3 changed files
... ...
@@ -29,6 +29,7 @@
29 29
 #include <stdlib.h>
30 30
 #include <arpa/inet.h>
31 31
 #include <string.h>
32
+#include "../../str.h"
32 33
 
33 34
 static ip4_node IPv4ranges[IPv4RANGES_SIZE] = {
34 35
         { 0xffffffff,  "BROADCAST",  0xffffffff },  // 255.255.255.255/32
... ...
@@ -73,7 +74,7 @@ static  ip6_node IPv6ranges[IPv6RANGES_SIZE] = {
73 74
     //more to come here soon
74 75
 };
75 76
 
76
-
77
+/*
77 78
 int _compare_ips(str string_ip, char *res)
78 79
 {
79 80
   uint32_t in6_addr[4];
... ...
@@ -97,7 +98,7 @@ int _compare_ips(str string_ip, char *res)
97 98
 
98 99
   return 1;
99 100
 }
100
-
101
+*/
101 102
 char* ip6_iptype(str s, uint32_t *ip) {
102 103
     int i;
103 104
     for (i = 0; i < IPv6RANGES_SIZE; i++) {
... ...
@@ -133,7 +134,6 @@ void ipv4ranges_hton() {
133 134
     }
134 135
 }
135 136
 
136
-
137 137
 void ipv6ranges_hton() {
138 138
     int pos;
139 139
     uint32_t tmp;
... ...
@@ -27,8 +27,11 @@
27 27
 #ifndef _IPOPS_DETAILED_IP_TYPE_H
28 28
 #define _IPOPS_DETAILED_IP_TYPE_H
29 29
 
30
-#define IPv4RANGES_SIZE 15
31
-#define IPv6RANGES_SIZE 19
30
+#define IPv4RANGES_SIZE 16
31
+#define IPv6RANGES_SIZE 20
32
+
33
+#include <stdint.h>
34
+#include "../../str.h"
32 35
 
33 36
 typedef struct ip4_node {
34 37
     uint32_t value;
... ...
@@ -44,5 +47,6 @@ typedef struct ip6_node {
44 47
 
45 48
 void ipv6ranges_hton();
46 49
 void ipv4ranges_hton();
50
+char* ip6_iptype(str s, uint32_t *ip);
47 51
 
48 52
 #endif
... ...
@@ -50,10 +50,12 @@
50 50
 #include "../../mod_fix.h"
51 51
 #include "../../pvar.h"
52 52
 #include "../../resolve.h"
53
+#include "../../lvalue.h"
53 54
 #include "api.h"
54 55
 #include "ipops_pv.h"
55 56
 #include "ip_parser.h"
56 57
 #include "rfc1918_parser.h"
58
+#include "detailed_ip_type.h"
57 59
 
58 60
 MODULE_VERSION
59 61
 
... ...
@@ -78,21 +80,22 @@ int _ip_is_in_subnet(char *ip1, size_t len1, enum enum_ip_type ip1_type, char *i
78 80
 /*
79 81
  * Script functions
80 82
  */
81
-    t w_is_ip(struct sip_msg*, char*);
83
+static int w_is_ip(struct sip_msg*, char*);
82 84
 static int w_is_pure_ip(struct sip_msg*, char*);
83 85
 static int w_is_ipv4(struct sip_msg*, char*);
84 86
 static int w_is_ipv6(struct sip_msg*, char*);
85 87
 static int w_is_ipv6_reference(struct sip_msg*, char*);
86 88
 static int w_ip_type(struct sip_msg*, char*);
87
-static int w_detailed_ipv6_type(struct sip_msg*, char*);
89
+static int w_detailed_ipv6_type(struct sip_msg* _msg, char* _s,  char *res);
88 90
 static int w_compare_ips(struct sip_msg*, char*, char*);
89 91
 static int w_compare_pure_ips(struct sip_msg*, char*, char*);
90 92
 static int w_is_ip_rfc1918(struct sip_msg*, char*);
91 93
 static int w_ip_is_in_subnet(struct sip_msg*, char*, char*);
92 94
 static int w_dns_sys_match_ip(sip_msg_t*, char*, char*);
93 95
 static int w_dns_int_match_ip(sip_msg_t*, char*, char*);
94
-
96
+static int fixup_detailed_ipv6_type(void** param, int param_no);
95 97
 static int w_dns_query(struct sip_msg* msg, char* str1, char* str2);
98
+static int mod_init(void);
96 99
 
97 100
 static pv_export_t mod_pvs[] = {
98 101
 	{ {"dns", sizeof("dns")-1}, PVT_OTHER, pv_get_dns, 0,
... ...
@@ -117,7 +120,7 @@ static cmd_export_t cmds[] =
117 120
   REQUEST_ROUTE|FAILURE_ROUTE|ONREPLY_ROUTE|BRANCH_ROUTE|LOCAL_ROUTE },
118 121
   { "ip_type", (cmd_function)w_ip_type, 1, fixup_spve_null, 0,
119 122
   REQUEST_ROUTE|FAILURE_ROUTE|ONREPLY_ROUTE|BRANCH_ROUTE|LOCAL_ROUTE },
120
-  { "detailed_ipv6_type", (cmd_function)w_detailed_ipv6_type, 2, fixup_spve_null, 0,
123
+  { "detailed_ipv6_type", (cmd_function)w_detailed_ipv6_type, 2, fixup_detailed_ipv6_type, 0,
121 124
   REQUEST_ROUTE|FAILURE_ROUTE|ONREPLY_ROUTE|BRANCH_ROUTE|LOCAL_ROUTE },
122 125
   { "compare_ips", (cmd_function)w_compare_ips, 2, fixup_spve_spve, 0,
123 126
   REQUEST_ROUTE|FAILURE_ROUTE|ONREPLY_ROUTE|BRANCH_ROUTE|LOCAL_ROUTE },
... ...
@@ -170,8 +173,38 @@ static int mod_init(void) {
170 173
      * transform each ip to host order before comparing */
171 174
     ipv4ranges_hton();
172 175
     ipv6ranges_hton();
176
+    return 0;
177
+}
178
+
179
+
180
+/* Fixup functions */
173 181
 
182
+/*
183
+ * Fix detailed_ipv6_type param: result (writable pvar).
184
+ */
185
+static int fixup_detailed_ipv6_type(void** param, int param_no)
186
+{
187
+    if (param_no == 1) {
188
+        return fixup_spve_null(param, 1);
189
+    }
190
+
191
+    if (param_no == 2) {
192
+        if (fixup_pvar_null(param, 1) != 0) {
193
+            LM_ERR("failed to fixup result pvar\n");
194
+            return -1;
195
+        }
196
+        if (((pv_spec_t *) (*param))->setf == NULL) {
197
+            LM_ERR("result pvar is not writeble\n");
198
+            return -1;
199
+        }
200
+        return 0;
201
+    }
202
+
203
+    LM_ERR("invalid parameter number <%d>\n", param_no);
204
+    return -1;
174 205
 }
206
+
207
+
175 208
 /*
176 209
  * Module internal functions
177 210
  */
... ...
@@ -434,9 +467,11 @@ static int w_ip_type(struct sip_msg* _msg, char* _s)
434 467
 
435 468
 
436 469
 /*! \brief Return the IP type of the given argument (string or pv): 1 = IPv4, 2 = IPv6, 3 = IPv6 refenrece, -1 = invalid IP. */
437
-static int w_detailed_ipv6_type(struct sip_msg* _msg, char* _s,  char *res)
470
+static int w_detailed_ipv6_type(struct sip_msg* _msg, char* _s,  char *_dst)
438 471
 {
439 472
   str string;
473
+  pv_spec_t *dst;
474
+  pv_value_t val;
440 475
 
441 476
   if (_s == NULL) {
442 477
     LM_ERR("bad parameter\n");
... ...
@@ -449,13 +484,22 @@ static int w_detailed_ipv6_type(struct sip_msg* _msg, char* _s,  char *res)
449 484
     return -3;
450 485
   }
451 486
 
487
+  LM_ERR("!!!!!!! ip to change is %.*s\n", string.len, string.s);
452 488
   /* make IPv6 from reference */
453 489
   if (string.s[0] == '[') {
454 490
       string.s++;
455 491
       string.len -= 2;
456 492
   }
457
-
458
-  return ip6_iptype(string.s, string.len, res);
493
+  LM_ERR("!!!!!!! hi 1 \n");
494
+  //
495
+  val.rs.s = "Ana are";
496
+  val.rs.len = 7;
497
+  val.flags = PV_VAL_STR;
498
+  dst = (pv_spec_t *)_dst;
499
+  dst->setf(_msg, &dst->pvp, (int)EQ_T, &val);
500
+  LM_ERR("!!!!!!! hi 2 \n");
501
+  //return ip6_iptype(string.s, string.len);
502
+  return 1;
459 503
 }
460 504
 
461 505
 /*! \brief Return true if both IP's (string or pv) are equal. This function also allows comparing an IPv6 with an IPv6 reference. */