Diff for /parser3/src/classes/inet.C between versions 1.13 and 1.18

version 1.13, 2016/10/04 13:23:45 version 1.18, 2023/09/26 20:49:06
Line 1 Line 1
 /** @file  /** @file
         Parser: @b inet parser class.          Parser: @b inet parser class.
   
         Copyright (c) 2001-2015 Art. Lebedev Studio (http://www.artlebedev.com)          Copyright (c) 2001-2023 Art. Lebedev Studio (http://www.artlebedev.com)
         Author: Alexandr Petrosian <paf@design.ru>(http://paf.design.ru)          Authors: Konstantin Morshnev <moko@design.ru>, Alexandr Petrosian <paf@design.ru>
 */  */
   
 #include "pa_vmethod_frame.h"  #include "pa_vmethod_frame.h"
Line 31  static void _ntoa(Request& r, MethodPara Line 31  static void _ntoa(Request& r, MethodPara
         static const int ip_cstr_bufsize=3*4+3+1/*zero-teminator*/+1/*for faulty snprintfs*/;          static const int ip_cstr_bufsize=3*4+3+1/*zero-teminator*/+1/*for faulty snprintfs*/;
         char* ip_cstr=new(PointerFreeGC) char[ip_cstr_bufsize];          char* ip_cstr=new(PointerFreeGC) char[ip_cstr_bufsize];
         snprintf(ip_cstr, ip_cstr_bufsize, "%u.%u.%u.%u", (l>>24) & 0xFF, (l>>16) & 0xFF, (l>>8) & 0xFF, l & 0xFF);          snprintf(ip_cstr, ip_cstr_bufsize, "%u.%u.%u.%u", (l>>24) & 0xFF, (l>>16) & 0xFF, (l>>8) & 0xFF, l & 0xFF);
         r.write_no_lang(*new String(ip_cstr));          r.write(*new String(ip_cstr));
 }  }
   
 static void _aton(Request& r, MethodParams& params){  static void _aton(Request& r, MethodParams& params){
Line 74  static void _aton(Request& r, MethodPara Line 74  static void _aton(Request& r, MethodPara
                 throw Exception(PARSER_RUNTIME, 0, "Invalid IP address '%s' specified.", ip_cstr);                  throw Exception(PARSER_RUNTIME, 0, "Invalid IP address '%s' specified.", ip_cstr);
         } else {          } else {
                 result=(result << 8)+(ulong)byte_value;                  result=(result << 8)+(ulong)byte_value;
                 r.write_no_lang(*new VDouble(result));                  r.write(*new VDouble(result));
         }          }
 }  }
   
Line 97  static void _ip2name(Request& r, MethodP Line 97  static void _ip2name(Request& r, MethodP
         hints.ai_family=AF_INET;          hints.ai_family=AF_INET;
         hints.ai_socktype=SOCK_STREAM;          hints.ai_socktype=SOCK_STREAM;
         hints.ai_flags=AI_NUMERICHOST; // to disable DNS lookup          hints.ai_flags=AI_NUMERICHOST; // to disable DNS lookup
           
         if(params.count() == 2)          if(params.count() == 2)
                 if(HashStringValue* options=params.as_hash(1)){                  if(HashStringValue* options=params.as_hash(1)){
                         int valid_options=0;                          int valid_options=0;
Line 121  static void _ip2name(Request& r, MethodP Line 121  static void _ip2name(Request& r, MethodP
         freeaddrinfo(info);          freeaddrinfo(info);
   
         if(!error){          if(!error){
                 r.write_no_lang(*new String(pa_idna_decode(pa_strdup(hbuf), r.charsets.source()), String::L_TAINTED));                  r.write(*new String(pa_idna_decode(pa_strdup(hbuf), r.charsets.source()), String::L_TAINTED));
         } else if(error!=EAI_NONAME){          } else if(error!=EAI_NONAME){
                 throw Exception(PARSER_RUNTIME, 0, "Can't resolve IP address '%s': %s", ip_cstr, gai_strerror(error));                  throw Exception(PARSER_RUNTIME, 0, "Can't resolve IP address '%s': %s", ip_cstr, gai_strerror(error));
         }          }
 }  }
   
 static void _name2ip(Request& r, MethodParams& params){  static void _name2ip(Request& r, MethodParams& params){
         const String sname=params.as_string(0, PARAMETER_MUST_BE_STRING);          const String sname=params.as_string(0, PARAMETER_MUST_BE_STRING);
         if(sname.is_empty())          if(sname.is_empty())
Line 178  static void _name2ip(Request& r, MethodP Line 179  static void _name2ip(Request& r, MethodP
                         *row+=cur->ai_family == AF_INET ? &sv4 : cur->ai_family == AF_INET6 ? &sv6 : &sunknown;                          *row+=cur->ai_family == AF_INET ? &sv4 : cur->ai_family == AF_INET6 ? &sv6 : &sunknown;
                         *table+=row;                          *table+=row;
                 } else {                  } else {
                         r.write_no_lang(*saddr);                          r.write(*saddr);
                         break;                          break;
                 }                  }
         }          }
   
         if(table)          if(table)
                 r.write_no_lang(*new VTable(table));                  r.write(*new VTable(table));
   
         freeaddrinfo(info);          freeaddrinfo(info);
 }  }
   
   static void _hostname(Request& r, MethodParams& params){
           char buf[MAX_STRING];
   
           if(gethostname(buf, MAX_STRING))
                   throw Exception(PARSER_RUNTIME, 0, "Cant't get hostname");
   
           r.write(*new String(pa_strdup(buf), String::L_TAINTED));
   }
   
 // constructor  // constructor
 MInet::MInet(): Methoded("inet") {  MInet::MInet(): Methoded("inet") {
         add_native_method("ntoa", Method::CT_STATIC, _ntoa, 1, 1);          add_native_method("ntoa", Method::CT_STATIC, _ntoa, 1, 1);
Line 197  MInet::MInet(): Methoded("inet") { Line 207  MInet::MInet(): Methoded("inet") {
         add_native_method("ip2name", Method::CT_STATIC, _ip2name, 1, 2);          add_native_method("ip2name", Method::CT_STATIC, _ip2name, 1, 2);
         // ^inet:name2ip[name; $.ipv[4|6|any] $.table(true) ]          // ^inet:name2ip[name; $.ipv[4|6|any] $.table(true) ]
         add_native_method("name2ip", Method::CT_STATIC, _name2ip, 1, 2);          add_native_method("name2ip", Method::CT_STATIC, _name2ip, 1, 2);
           // ^inet:hostname[]
           add_native_method("hostname", Method::CT_STATIC, _hostname, 0, 0);
 }  }

Removed from v.1.13  
changed lines
  Added in v.1.18


E-mail: