1*cdf0e10cSrcweirpackage CallExternals; 2*cdf0e10cSrcweir 3*cdf0e10cSrcweir#************************************************************************* 4*cdf0e10cSrcweir# 5*cdf0e10cSrcweir# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6*cdf0e10cSrcweir# 7*cdf0e10cSrcweir# Copyright 2000, 2010 Oracle and/or its affiliates. 8*cdf0e10cSrcweir# 9*cdf0e10cSrcweir# OpenOffice.org - a multi-platform office productivity suite 10*cdf0e10cSrcweir# 11*cdf0e10cSrcweir# This file is part of OpenOffice.org. 12*cdf0e10cSrcweir# 13*cdf0e10cSrcweir# OpenOffice.org is free software: you can redistribute it and/or modify 14*cdf0e10cSrcweir# it under the terms of the GNU Lesser General Public License version 3 15*cdf0e10cSrcweir# only, as published by the Free Software Foundation. 16*cdf0e10cSrcweir# 17*cdf0e10cSrcweir# OpenOffice.org is distributed in the hope that it will be useful, 18*cdf0e10cSrcweir# but WITHOUT ANY WARRANTY; without even the implied warranty of 19*cdf0e10cSrcweir# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20*cdf0e10cSrcweir# GNU Lesser General Public License version 3 for more details 21*cdf0e10cSrcweir# (a copy is included in the LICENSE file that accompanied this code). 22*cdf0e10cSrcweir# 23*cdf0e10cSrcweir# You should have received a copy of the GNU Lesser General Public License 24*cdf0e10cSrcweir# version 3 along with OpenOffice.org. If not, see 25*cdf0e10cSrcweir# <http://www.openoffice.org/license.html> 26*cdf0e10cSrcweir# for a copy of the LGPLv3 License. 27*cdf0e10cSrcweir# 28*cdf0e10cSrcweir#************************************************************************* 29*cdf0e10cSrcweir 30*cdf0e10cSrcweiruse English; 31*cdf0e10cSrcweiruse warnings; 32*cdf0e10cSrcweiruse strict; 33*cdf0e10cSrcweiruse loghelper; 34*cdf0e10cSrcweir 35*cdf0e10cSrcweirBEGIN { 36*cdf0e10cSrcweir use Exporter (); 37*cdf0e10cSrcweir our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS); 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir $VERSION = 1.00; 40*cdf0e10cSrcweir # if using RCS/CVS, this may be preferred 41*cdf0e10cSrcweir $VERSION = do { my @r = (q$Revision: 1.29 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; # must be all one line, for MakeMaker 42*cdf0e10cSrcweir @ISA = qw(Exporter); 43*cdf0e10cSrcweir @EXPORT = qw(&callphp &getPHPExecutable &ExecSQL &callperl &getPerlExecutable &calljava &setJavaExecutable &getJavaExecutable &setToolsPath "e "eIfNeed &set_logfile &close_logfile ); 44*cdf0e10cSrcweir %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ], 45*cdf0e10cSrcweir # your exported package globals go here, 46*cdf0e10cSrcweir # as well as any optionally exported functions 47*cdf0e10cSrcweir @EXPORT_OK = ( ); # qw($Var1 %Hashit &func3); 48*cdf0e10cSrcweir} 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir# ------------------------------------------------------------------------------ 51*cdf0e10cSrcweir# small helper, which replaces the return code 52*cdf0e10cSrcweirsub errorAdaption($) 53*cdf0e10cSrcweir{ 54*cdf0e10cSrcweir my $error = shift; 55*cdf0e10cSrcweir if ($error != 0) 56*cdf0e10cSrcweir { 57*cdf0e10cSrcweir $error = $error / 256; 58*cdf0e10cSrcweir } 59*cdf0e10cSrcweir if ($error > 127) 60*cdf0e10cSrcweir { 61*cdf0e10cSrcweir $error = $error - 256; 62*cdf0e10cSrcweir } 63*cdf0e10cSrcweir return $error; 64*cdf0e10cSrcweir} 65*cdf0e10cSrcweir# ------------------------------------------------------------------------------ 66*cdf0e10cSrcweir# helper to call external php with popen 67*cdf0e10cSrcweirsub callphp($$$) 68*cdf0e10cSrcweir{ 69*cdf0e10cSrcweir local *IN_FILE; 70*cdf0e10cSrcweir my $phpexe = shift; 71*cdf0e10cSrcweir my $phpprogram = shift; 72*cdf0e10cSrcweir my $sParams = shift; 73*cdf0e10cSrcweir my $line; 74*cdf0e10cSrcweir my $error; 75*cdf0e10cSrcweir my @result; 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir # print "Will send: $phpexe $sParams\n"; 78*cdf0e10cSrcweir # log_print("CALLPHP: $phpexe $phpprogram $sParams\n"); 79*cdf0e10cSrcweir# if (open(IN_FILE, "$phpexe $sParams 2>&1 |")) 80*cdf0e10cSrcweir if (open(IN_FILE, "$phpexe $phpprogram $sParams |")) 81*cdf0e10cSrcweir { 82*cdf0e10cSrcweir while ($line = <IN_FILE>) 83*cdf0e10cSrcweir { 84*cdf0e10cSrcweir chomp($line); 85*cdf0e10cSrcweir # $line .= " "; 86*cdf0e10cSrcweir push(@result, $line); 87*cdf0e10cSrcweir # print "callphp output: $line\n"; 88*cdf0e10cSrcweir } 89*cdf0e10cSrcweir close(IN_FILE); 90*cdf0e10cSrcweir $error = errorAdaption($?); 91*cdf0e10cSrcweir } 92*cdf0e10cSrcweir else 93*cdf0e10cSrcweir { 94*cdf0e10cSrcweir print "callphp(): Can't popen '$phpexe' with parameter: '$sParams'\n"; 95*cdf0e10cSrcweir $error = 1; 96*cdf0e10cSrcweir } 97*cdf0e10cSrcweir return $error, @result; 98*cdf0e10cSrcweir} 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir# ------------------------------------------------------------------------------ 101*cdf0e10cSrcweirsub getPHPExecutable() 102*cdf0e10cSrcweir{ 103*cdf0e10cSrcweir my $phpexe; 104*cdf0e10cSrcweir if ($OSNAME eq "solaris") 105*cdf0e10cSrcweir { 106*cdf0e10cSrcweir $phpexe = "php5"; 107*cdf0e10cSrcweir } 108*cdf0e10cSrcweir elsif ($OSNAME eq "linux") 109*cdf0e10cSrcweir { 110*cdf0e10cSrcweir if ( -e "/usr/bin/php5") # Suse :-( 111*cdf0e10cSrcweir { 112*cdf0e10cSrcweir $phpexe = "php5"; 113*cdf0e10cSrcweir } 114*cdf0e10cSrcweir elsif ( -e "/usr/bin/php") # Gentoo 115*cdf0e10cSrcweir { 116*cdf0e10cSrcweir $phpexe = "php"; 117*cdf0e10cSrcweir } 118*cdf0e10cSrcweir else 119*cdf0e10cSrcweir { 120*cdf0e10cSrcweir print "getPHPExecutable(): no php exec found.\n"; 121*cdf0e10cSrcweir } 122*cdf0e10cSrcweir } 123*cdf0e10cSrcweir elsif ( $OSNAME eq "MSWin32" ) 124*cdf0e10cSrcweir { 125*cdf0e10cSrcweir $phpexe = "C:/programme/php/php.exe"; 126*cdf0e10cSrcweir # add second try (xampp) 127*cdf0e10cSrcweir if (! -e $phpexe) 128*cdf0e10cSrcweir { 129*cdf0e10cSrcweir $phpexe = "C:/xampp/php/php.exe"; 130*cdf0e10cSrcweir } 131*cdf0e10cSrcweir } 132*cdf0e10cSrcweir elsif ( $OSNAME eq "cygwin" ) 133*cdf0e10cSrcweir { 134*cdf0e10cSrcweir $phpexe = "/cygdrive/c/programme/php/php"; 135*cdf0e10cSrcweir } 136*cdf0e10cSrcweir else 137*cdf0e10cSrcweir { 138*cdf0e10cSrcweir print "getPHPExecutable(): unknown environment. ($OSNAME)\n"; 139*cdf0e10cSrcweir } 140*cdf0e10cSrcweir if (! $phpexe) 141*cdf0e10cSrcweir { 142*cdf0e10cSrcweir print "getPHPExecutable(): ERROR: php executable not found.\n"; 143*cdf0e10cSrcweir exit(1); 144*cdf0e10cSrcweir } 145*cdf0e10cSrcweir return $phpexe; 146*cdf0e10cSrcweir} 147*cdf0e10cSrcweir# ------------------------------------------------------------------------------ 148*cdf0e10cSrcweir# helper to call external java with popen 149*cdf0e10cSrcweirsub calljava($$$) 150*cdf0e10cSrcweir{ 151*cdf0e10cSrcweir local *IN_FILE; 152*cdf0e10cSrcweir my $javaexe = shift; 153*cdf0e10cSrcweir my $sParams = shift; 154*cdf0e10cSrcweir my $sDebug = shift; 155*cdf0e10cSrcweir my $line; 156*cdf0e10cSrcweir my $error = 1; 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir if (! $javaexe) 159*cdf0e10cSrcweir { 160*cdf0e10cSrcweir log_print("ERROR: javaexe not set.\n"); 161*cdf0e10cSrcweir return; 162*cdf0e10cSrcweir } 163*cdf0e10cSrcweir if (! $sDebug) 164*cdf0e10cSrcweir { 165*cdf0e10cSrcweir $sDebug = ""; 166*cdf0e10cSrcweir } 167*cdf0e10cSrcweir $javaexe = quoteIfNeed($javaexe); 168*cdf0e10cSrcweir log_print ("CALLJAVA: $javaexe $sDebug $sParams\n"); 169*cdf0e10cSrcweir if (open(IN_FILE, "$javaexe $sDebug $sParams 2>&1 |")) 170*cdf0e10cSrcweir { 171*cdf0e10cSrcweir while ($line = <IN_FILE>) 172*cdf0e10cSrcweir { 173*cdf0e10cSrcweir chomp($line); 174*cdf0e10cSrcweir log_print ("- $line\n"); 175*cdf0e10cSrcweir } 176*cdf0e10cSrcweir close(IN_FILE); 177*cdf0e10cSrcweir $error = errorAdaption($?); 178*cdf0e10cSrcweir } 179*cdf0e10cSrcweir else 180*cdf0e10cSrcweir { 181*cdf0e10cSrcweir log_print ("calljava(): Can't popen '$javaexe' with parameter '$sParams'\n"); 182*cdf0e10cSrcweir $error = 1; 183*cdf0e10cSrcweir } 184*cdf0e10cSrcweir return $error; 185*cdf0e10cSrcweir} 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir# ------------------------------------------------------------------------------ 188*cdf0e10cSrcweirsub getPerlExecutable() 189*cdf0e10cSrcweir{ 190*cdf0e10cSrcweir my $perlexe; 191*cdf0e10cSrcweir if ( $ENV{PERL} ) 192*cdf0e10cSrcweir { 193*cdf0e10cSrcweir $perlexe = $ENV{PERL}; 194*cdf0e10cSrcweir } 195*cdf0e10cSrcweir elsif ( $ENV{PERLEXE} ) 196*cdf0e10cSrcweir { 197*cdf0e10cSrcweir $perlexe = $ENV{PERLEXE}; 198*cdf0e10cSrcweir } 199*cdf0e10cSrcweir else 200*cdf0e10cSrcweir { 201*cdf0e10cSrcweir if ($OSNAME eq "MSWin32") 202*cdf0e10cSrcweir { 203*cdf0e10cSrcweir $perlexe="C:/xampp/perl/bin/perl.exe"; 204*cdf0e10cSrcweir if (! -e $perlexe) 205*cdf0e10cSrcweir { 206*cdf0e10cSrcweir $perlexe="r:/btw/perl/bin/perl"; 207*cdf0e10cSrcweir } 208*cdf0e10cSrcweir if (! -e $perlexe) 209*cdf0e10cSrcweir { 210*cdf0e10cSrcweir $perlexe="C:/Programme/Perl/bin/perl.exe"; 211*cdf0e10cSrcweir } 212*cdf0e10cSrcweir } 213*cdf0e10cSrcweir elsif ($OSNAME eq "cygwin") 214*cdf0e10cSrcweir { 215*cdf0e10cSrcweir $perlexe = "perl"; 216*cdf0e10cSrcweir } 217*cdf0e10cSrcweir elsif ($OSNAME eq "solaris") 218*cdf0e10cSrcweir { 219*cdf0e10cSrcweir $perlexe="/so/env/bt_solaris_intel/bin/perl"; 220*cdf0e10cSrcweir } 221*cdf0e10cSrcweir elsif ($OSNAME eq "linux") 222*cdf0e10cSrcweir { 223*cdf0e10cSrcweir $perlexe="/so/env/bt_linux_libc2.32/DEV300/bin/perl"; 224*cdf0e10cSrcweir } 225*cdf0e10cSrcweir else 226*cdf0e10cSrcweir { 227*cdf0e10cSrcweir log_print "WARNING: Use only the fallback of perl executable.\n"; 228*cdf0e10cSrcweir $perlexe = "perl"; # FALLBACK 229*cdf0e10cSrcweir } 230*cdf0e10cSrcweir } 231*cdf0e10cSrcweir if ( ! -e $perlexe) 232*cdf0e10cSrcweir { 233*cdf0e10cSrcweir log_print "getPerlExecutable(): There exist no perl executable.\n"; 234*cdf0e10cSrcweir exit(1); 235*cdf0e10cSrcweir } 236*cdf0e10cSrcweir return $perlexe; 237*cdf0e10cSrcweir} 238*cdf0e10cSrcweir# ------------------------------------------------------------------------------ 239*cdf0e10cSrcweir# helper to call external perl with popen 240*cdf0e10cSrcweirsub callperl($$$) 241*cdf0e10cSrcweir{ 242*cdf0e10cSrcweir local *IN_FILE; 243*cdf0e10cSrcweir my $perlexe = shift; 244*cdf0e10cSrcweir my $perlprogram = shift; 245*cdf0e10cSrcweir my $sParams = shift; 246*cdf0e10cSrcweir my $line; 247*cdf0e10cSrcweir my $error; 248*cdf0e10cSrcweir 249*cdf0e10cSrcweir log_print("CALLPERL: $perlexe $perlprogram $sParams\n"); 250*cdf0e10cSrcweir# if (open(IN_FILE, "$perlexe $sParams 2>&1 |")) 251*cdf0e10cSrcweir if (open(IN_FILE, "$perlexe $perlprogram $sParams |")) 252*cdf0e10cSrcweir { 253*cdf0e10cSrcweir while ($line = <IN_FILE>) 254*cdf0e10cSrcweir { 255*cdf0e10cSrcweir chomp($line); 256*cdf0e10cSrcweir log_print ("- $line\n"); 257*cdf0e10cSrcweir } 258*cdf0e10cSrcweir close(IN_FILE); 259*cdf0e10cSrcweir $error = errorAdaption($?); 260*cdf0e10cSrcweir } 261*cdf0e10cSrcweir else 262*cdf0e10cSrcweir { 263*cdf0e10cSrcweir log_print ("Can't popen '$perlexe' with parameter: '$sParams'\n"); 264*cdf0e10cSrcweir $error = 1; 265*cdf0e10cSrcweir } 266*cdf0e10cSrcweir return $error; 267*cdf0e10cSrcweir} 268*cdf0e10cSrcweir# ------------------------------------------------------------------------------ 269*cdf0e10cSrcweirour $sJavaExecutable; 270*cdf0e10cSrcweirsub setJavaExecutable($) 271*cdf0e10cSrcweir{ 272*cdf0e10cSrcweir $sJavaExecutable = shift; 273*cdf0e10cSrcweir} 274*cdf0e10cSrcweir 275*cdf0e10cSrcweir# sub getJava14() 276*cdf0e10cSrcweir# { 277*cdf0e10cSrcweir# my $sJava14; 278*cdf0e10cSrcweir# if ($OSNAME eq "MSWin32") 279*cdf0e10cSrcweir# { 280*cdf0e10cSrcweir# if ($sJavaExecutable) 281*cdf0e10cSrcweir# { 282*cdf0e10cSrcweir# $sJava14 = $sJavaExecutable; 283*cdf0e10cSrcweir# } 284*cdf0e10cSrcweir# else 285*cdf0e10cSrcweir# { 286*cdf0e10cSrcweir# # HARDCODE! 287*cdf0e10cSrcweir# $sJava14 = "C:\\Programme\\Java\\j2re1.4.2_10\\bin\\java.exe"; 288*cdf0e10cSrcweir# } 289*cdf0e10cSrcweir# } 290*cdf0e10cSrcweir# else 291*cdf0e10cSrcweir# { 292*cdf0e10cSrcweir# if ($sJavaExecutable) 293*cdf0e10cSrcweir# { 294*cdf0e10cSrcweir# $sJava14 = $sJavaExecutable; 295*cdf0e10cSrcweir# } 296*cdf0e10cSrcweir# else 297*cdf0e10cSrcweir# { 298*cdf0e10cSrcweir# # HARDCODE! 299*cdf0e10cSrcweir# $sJava14 = "/opt/java14/bin/java"; 300*cdf0e10cSrcweir# } 301*cdf0e10cSrcweir# } 302*cdf0e10cSrcweir# if ( ! -e $sJava14 ) 303*cdf0e10cSrcweir# { 304*cdf0e10cSrcweir# log_print ("Java14 not found. Is searched in '$sJava14'\n"); 305*cdf0e10cSrcweir# # exit(1); 306*cdf0e10cSrcweir# return ""; 307*cdf0e10cSrcweir# } 308*cdf0e10cSrcweir# return $sJava14; 309*cdf0e10cSrcweir# } 310*cdf0e10cSrcweir# ------------------------------------------------------------------------------ 311*cdf0e10cSrcweirsub getJava15() 312*cdf0e10cSrcweir{ 313*cdf0e10cSrcweir my $sJava15; 314*cdf0e10cSrcweir if ($sJavaExecutable) 315*cdf0e10cSrcweir { 316*cdf0e10cSrcweir $sJava15 = $sJavaExecutable; 317*cdf0e10cSrcweir } 318*cdf0e10cSrcweir else 319*cdf0e10cSrcweir { 320*cdf0e10cSrcweir if ($OSNAME eq "MSWin32") 321*cdf0e10cSrcweir { 322*cdf0e10cSrcweir # HARDCODE! 323*cdf0e10cSrcweir $sJava15 = "C:\\Programme\\Java\\jre1.5.0_22\\bin\\java.exe"; 324*cdf0e10cSrcweir if ( ! -e $sJava15) 325*cdf0e10cSrcweir { 326*cdf0e10cSrcweir $sJava15 = "C:\\Program Files\\Java\\jre6\\bin\\java.exe"; 327*cdf0e10cSrcweir } 328*cdf0e10cSrcweir if ( ! -e $sJava15) 329*cdf0e10cSrcweir { 330*cdf0e10cSrcweir $sJava15 = "C:\\Java\\jdk1.6\\bin\\java.exe"; 331*cdf0e10cSrcweir } 332*cdf0e10cSrcweir } 333*cdf0e10cSrcweir elsif ($OSNAME eq "cygwin") 334*cdf0e10cSrcweir { 335*cdf0e10cSrcweir $sJava15 = "java"; 336*cdf0e10cSrcweir } 337*cdf0e10cSrcweir else 338*cdf0e10cSrcweir { 339*cdf0e10cSrcweir # HARDCODE! 340*cdf0e10cSrcweir if ($OSNAME eq "solaris") 341*cdf0e10cSrcweir { 342*cdf0e10cSrcweir $sJava15 = "/usr/bin/java"; 343*cdf0e10cSrcweir } 344*cdf0e10cSrcweir else 345*cdf0e10cSrcweir { 346*cdf0e10cSrcweir $sJava15 = "/usr/bin/java"; 347*cdf0e10cSrcweir if ( ! -e $sJava15 ) 348*cdf0e10cSrcweir { 349*cdf0e10cSrcweir $sJava15 = "/opt/java15/bin/java"; 350*cdf0e10cSrcweir } 351*cdf0e10cSrcweir } 352*cdf0e10cSrcweir } 353*cdf0e10cSrcweir if ( ! -e $sJava15 ) 354*cdf0e10cSrcweir { 355*cdf0e10cSrcweir log_print ("Java15 not found. Is searched in '$sJava15'\n"); 356*cdf0e10cSrcweir # exit(1); 357*cdf0e10cSrcweir return ""; 358*cdf0e10cSrcweir } 359*cdf0e10cSrcweir } 360*cdf0e10cSrcweir return $sJava15; 361*cdf0e10cSrcweir} 362*cdf0e10cSrcweir# ------------------------------------------------------------------------------ 363*cdf0e10cSrcweirsub getJava16() 364*cdf0e10cSrcweir{ 365*cdf0e10cSrcweir my $sJava16; 366*cdf0e10cSrcweir if ($sJavaExecutable) 367*cdf0e10cSrcweir { 368*cdf0e10cSrcweir $sJava16 = $sJavaExecutable; 369*cdf0e10cSrcweir } 370*cdf0e10cSrcweir else 371*cdf0e10cSrcweir { 372*cdf0e10cSrcweir if ($OSNAME eq "MSWin32") 373*cdf0e10cSrcweir { 374*cdf0e10cSrcweir # HARDCODE! 375*cdf0e10cSrcweir $sJava16 = "C:\\Programme\\Java\\jre1.6.0_16\\bin\\java.exe"; 376*cdf0e10cSrcweir if ( ! -e $sJava16) 377*cdf0e10cSrcweir { 378*cdf0e10cSrcweir $sJava16 = "C:\\Program Files\\Java\\jre6\\bin\\java.exe"; 379*cdf0e10cSrcweir } 380*cdf0e10cSrcweir if ( ! -e $sJava16) 381*cdf0e10cSrcweir { 382*cdf0e10cSrcweir $sJava16 = "C:\\Java\\jdk1.6\\bin\\java.exe"; 383*cdf0e10cSrcweir } 384*cdf0e10cSrcweir # } 385*cdf0e10cSrcweir } 386*cdf0e10cSrcweir elsif ($OSNAME eq "cygwin") 387*cdf0e10cSrcweir { 388*cdf0e10cSrcweir # $sJava16 = "java"; 389*cdf0e10cSrcweir $sJava16 = "C:/Program Files/Java/jdk1.6.0_16/bin/java.exe"; 390*cdf0e10cSrcweir } 391*cdf0e10cSrcweir else 392*cdf0e10cSrcweir { 393*cdf0e10cSrcweir # HARDCODE! 394*cdf0e10cSrcweir if ($OSNAME eq "solaris") 395*cdf0e10cSrcweir { 396*cdf0e10cSrcweir $sJava16 = "/usr/bin/java"; 397*cdf0e10cSrcweir } 398*cdf0e10cSrcweir else 399*cdf0e10cSrcweir { 400*cdf0e10cSrcweir $sJava16 = "/usr/bin/java"; 401*cdf0e10cSrcweir if ( ! -e $sJava16 ) 402*cdf0e10cSrcweir { 403*cdf0e10cSrcweir $sJava16 = "/opt/java16/bin/java"; 404*cdf0e10cSrcweir } 405*cdf0e10cSrcweir } 406*cdf0e10cSrcweir } 407*cdf0e10cSrcweir if ( ! -e $sJava16 ) 408*cdf0e10cSrcweir { 409*cdf0e10cSrcweir log_print ("Java16 not found. Is searched in '$sJava16'\n"); 410*cdf0e10cSrcweir # exit(1); 411*cdf0e10cSrcweir return ""; 412*cdf0e10cSrcweir } 413*cdf0e10cSrcweir } 414*cdf0e10cSrcweir return $sJava16; 415*cdf0e10cSrcweir} 416*cdf0e10cSrcweir 417*cdf0e10cSrcweir# ------------------------------------------------------------------------------ 418*cdf0e10cSrcweirsub getJavaExecutable() 419*cdf0e10cSrcweir{ 420*cdf0e10cSrcweir return getJava16(); 421*cdf0e10cSrcweir} 422*cdf0e10cSrcweir 423*cdf0e10cSrcweir# ------------------------------------------------------------------------------ 424*cdf0e10cSrcweir# this function is a helper for parameters 425*cdf0e10cSrcweir# if quotes the whole string with 'STR' or "STR" and replace quotes in it's content for the right. 426*cdf0e10cSrcweirsub singleQuote($) 427*cdf0e10cSrcweir{ 428*cdf0e10cSrcweir my $sStr = shift; 429*cdf0e10cSrcweir if ( $OSNAME eq "MSWin32") 430*cdf0e10cSrcweir { 431*cdf0e10cSrcweir # we are MSWin32 (quote \" stronger) 432*cdf0e10cSrcweir # $sStr =~ s/\'/\"/g; 433*cdf0e10cSrcweir $sStr =~ s/\'/\\\"/g; 434*cdf0e10cSrcweir return "\"" . $sStr . "\""; 435*cdf0e10cSrcweir } 436*cdf0e10cSrcweir else 437*cdf0e10cSrcweir { 438*cdf0e10cSrcweir if (index($sStr, "'") >= 0) 439*cdf0e10cSrcweir { 440*cdf0e10cSrcweir # replace all single quotes ("'") by "\"" 441*cdf0e10cSrcweir $sStr =~ s/\'/\"/g; 442*cdf0e10cSrcweir } 443*cdf0e10cSrcweir } 444*cdf0e10cSrcweir return "'" . $sStr . "'"; 445*cdf0e10cSrcweir} 446*cdf0e10cSrcweir 447*cdf0e10cSrcweirsub quote($) 448*cdf0e10cSrcweir{ 449*cdf0e10cSrcweir my $sName = shift; 450*cdf0e10cSrcweir return "\"" . $sName . "\""; 451*cdf0e10cSrcweir} 452*cdf0e10cSrcweir 453*cdf0e10cSrcweirsub quoteIfNeed($) 454*cdf0e10cSrcweir{ 455*cdf0e10cSrcweir my $sName = shift; 456*cdf0e10cSrcweir if (-1 != index($sName, " ")) 457*cdf0e10cSrcweir { 458*cdf0e10cSrcweir return quote($sName); 459*cdf0e10cSrcweir } 460*cdf0e10cSrcweir return $sName; 461*cdf0e10cSrcweir} 462*cdf0e10cSrcweir 463*cdf0e10cSrcweir 464*cdf0e10cSrcweir# ------------------------------------------------------------------------------ 465*cdf0e10cSrcweirour $sToolsPath; 466*cdf0e10cSrcweirsub setToolsPath($) 467*cdf0e10cSrcweir{ 468*cdf0e10cSrcweir my $sNewPath = shift; 469*cdf0e10cSrcweir $sToolsPath = $sNewPath; 470*cdf0e10cSrcweir} 471*cdf0e10cSrcweir 472*cdf0e10cSrcweirsub ExecSQL($) 473*cdf0e10cSrcweir{ 474*cdf0e10cSrcweir my $sSQL = shift; 475*cdf0e10cSrcweir 476*cdf0e10cSrcweir my $error; 477*cdf0e10cSrcweir my @aResult; 478*cdf0e10cSrcweir my $sSQLDirect; 479*cdf0e10cSrcweir if ($sToolsPath) 480*cdf0e10cSrcweir { 481*cdf0e10cSrcweir $sSQLDirect = $sToolsPath; 482*cdf0e10cSrcweir $sSQLDirect .= "/"; 483*cdf0e10cSrcweir } 484*cdf0e10cSrcweir $sSQLDirect .= "sql_direct.php"; 485*cdf0e10cSrcweir 486*cdf0e10cSrcweir # select(undef, undef, undef, 0.060); 487*cdf0e10cSrcweir # log_print("ExecSQL: $sSQL\n"); 488*cdf0e10cSrcweir # sleep (1); 489*cdf0e10cSrcweir ($error, @aResult) = callphp(getPHPExecutable(), $sSQLDirect, singleQuote($sSQL)); 490*cdf0e10cSrcweir if ($error) 491*cdf0e10cSrcweir { 492*cdf0e10cSrcweir log_print ("ExecSQL: An Error occured.\n"); 493*cdf0e10cSrcweir log_print ("PHP: " . getPHPExecutable() . "\n"); 494*cdf0e10cSrcweir log_print ("SQL Statement: " . singleQuote($sSQL) . "\n"); 495*cdf0e10cSrcweir # exit(1); 496*cdf0e10cSrcweir } 497*cdf0e10cSrcweir # select(undef, undef, undef, 0.125); 498*cdf0e10cSrcweir # sleep (1); 499*cdf0e10cSrcweir return @aResult; 500*cdf0e10cSrcweir} 501*cdf0e10cSrcweir 502*cdf0e10cSrcweir# ------------------------------------------------------------------------------ 503*cdf0e10cSrcweir# helper to call external php with popen 504*cdf0e10cSrcweir# sub callexe($$$) 505*cdf0e10cSrcweir# { 506*cdf0e10cSrcweir# local *IN_FILE; 507*cdf0e10cSrcweir# my $exe = shift; 508*cdf0e10cSrcweir# my $program = shift; 509*cdf0e10cSrcweir# my $sParams = shift; 510*cdf0e10cSrcweir# my $line; 511*cdf0e10cSrcweir# my $error; 512*cdf0e10cSrcweir# my @result; 513*cdf0e10cSrcweir# 514*cdf0e10cSrcweir# $exe = quoteIfNeed($exe); 515*cdf0e10cSrcweir# $program = quoteIfNeed($program); 516*cdf0e10cSrcweir# 517*cdf0e10cSrcweir# # print "Will send: $exe $sParams\n"; 518*cdf0e10cSrcweir# # log_print("CALLEXE: $exe $program $sParams\n"); 519*cdf0e10cSrcweir# if (open(IN_FILE, "$exe $program $sParams |")) 520*cdf0e10cSrcweir# { 521*cdf0e10cSrcweir# while ($line = <IN_FILE>) 522*cdf0e10cSrcweir# { 523*cdf0e10cSrcweir# chomp($line); 524*cdf0e10cSrcweir# # $line .= " "; 525*cdf0e10cSrcweir# push(@result, $line); 526*cdf0e10cSrcweir# # print "callphp output: $line\n"; 527*cdf0e10cSrcweir# } 528*cdf0e10cSrcweir# close(IN_FILE); 529*cdf0e10cSrcweir# $error = errorAdaption($?); 530*cdf0e10cSrcweir# } 531*cdf0e10cSrcweir# else 532*cdf0e10cSrcweir# { 533*cdf0e10cSrcweir# print "Can't popen '$exe' with parameter: '$sParams'\n"; 534*cdf0e10cSrcweir# $error = 1; 535*cdf0e10cSrcweir# } 536*cdf0e10cSrcweir# return $error, @result; 537*cdf0e10cSrcweir# } 538*cdf0e10cSrcweir 539*cdf0e10cSrcweir1; 540