add ip2int and int2ip functions to be able to store on pg IPV4 ip addresses
[brisk.git] / web / Obj / brisk.phh
index 359cc5f..f221518 100644 (file)
@@ -345,6 +345,20 @@ $G_PG_cons_n = 345;
     /*     printf("\n"); */
     /* } */
 
+function ip2int($s)
+{
+    $v = ip2long($s);
+    if (PHP_INT_SIZE == 4)
+        return ($v);
+
+    return ( ($v & 0x80000000 ? 0xffffffff00000000 : 0x00) | $v );
+}
+
+function int2ip($i)
+{
+    return long2ip($i & 0xffffffff);
+}
+
 function nickserv_msg($dt, $msg) {
     return sprintf('chatt_sub("%s",[0x040003,"%s"],"%s");', $dt, NICKSERV, $msg);
 }
@@ -3301,7 +3315,7 @@ function validate_name($name)
 {
     $name_new = str_replace(' ', '_', mb_substr(trim($name),0,12, "UTF-8"));
 
-  for ($i = 0 ; $i < strlen($name_new) ; $i++) {
+  for ($i = 0 ; $i < mb_strlen($name_new) ; $i++) {
     $c = $name_new[$i];
     if (($c >= "a" && $c <= "z") || ($c >= "A" && $c <= "Z") || ($c >= "0" && $c <= "9"))
       return ($name_new);